Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/wasm-utxo/js/fixedScriptWallet/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ const chainCodeSet = new Set<number>(chainCodes);
const chainToMeta = new Map<ChainCode, { scope: Scope; scriptType: OutputScriptType }>();
const scriptTypeToChain = new Map<OutputScriptType, { internal: ChainCode; external: ChainCode }>();

// Initialize from WASM (called once at load time)
function assertChainCode(n: number): ChainCode {
/**
* Assert that a number is a valid chain code.
* @throws Error if the number is not a valid chain code
*/
export function assertChainCode(n: number): ChainCode {
if (!chainCodeSet.has(n)) {
throw new Error(`Invalid chain code from WASM: ${n}`);
throw new Error(`Invalid chain code: ${n}`);
}
return n as ChainCode;
}
Expand Down
30 changes: 28 additions & 2 deletions packages/wasm-utxo/js/fixedScriptWallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWall
export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
export { outputScript, address } from "./address.js";
export { Dimensions } from "./Dimensions.js";
export { type OutputScriptType, type InputScriptType, type ScriptType } from "./scriptType.js";
export { ChainCode, chainCodes, type Scope } from "./chains.js";
export {
outputScriptTypes,
inputScriptTypes,
type OutputScriptType,
type InputScriptType,
type ScriptType,
} from "./scriptType.js";
export { ChainCode, chainCodes, assertChainCode, type Scope } from "./chains.js";

// Bitcoin-like PSBT (for all non-Zcash networks)
export {
Expand Down Expand Up @@ -61,3 +67,23 @@ import type { ScriptType } from "./scriptType.js";
export function supportsScriptType(coin: CoinName, scriptType: ScriptType): boolean {
return FixedScriptWalletNamespace.supports_script_type(coin, scriptType);
}

/**
* Create an OP_RETURN output script with optional data
*
* @param data - Optional data bytes to include in the OP_RETURN script
* @returns The OP_RETURN script as a Uint8Array
*
* @example
* ```typescript
* // Empty OP_RETURN
* const script = createOpReturnScript();
*
* // OP_RETURN with data
* const data = new Uint8Array([1, 2, 3, 4]);
* const script = createOpReturnScript(data);
* ```
*/
export function createOpReturnScript(data?: Uint8Array): Uint8Array {
return FixedScriptWalletNamespace.create_op_return_script(data);
}
49 changes: 31 additions & 18 deletions packages/wasm-utxo/js/fixedScriptWallet/scriptType.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
/**
* Fixed-script wallet output script types (2-of-3 multisig)
* All output script types for fixed-script wallets (2-of-3 multisig)
*
* This type represents the abstract script type, independent of chain (external/internal).
* This represents the abstract script type, independent of chain (external/internal).
* Use this for checking network support or when you need the script type without derivation info.
*/
export type OutputScriptType =
| "p2sh"
| "p2shP2wsh"
| "p2wsh"
| "p2tr" // alias for p2trLegacy
| "p2trLegacy"
| "p2trMusig2";
export const outputScriptTypes = [
"p2sh",
"p2shP2wsh",
"p2wsh",
"p2trLegacy",
"p2trMusig2",
] as const;

/**
* Input script types for fixed-script wallets
* Output script type for fixed-script wallets
*
* Note: "p2tr" is an alias for "p2trLegacy" for backward compatibility.
*/
export type OutputScriptType = (typeof outputScriptTypes)[number] | "p2tr";

/**
* All input script types for fixed-script wallets
*
* These are more specific than output types and include single-sig and taproot variants.
*/
export type InputScriptType =
| "p2shP2pk"
| "p2sh"
| "p2shP2wsh"
| "p2wsh"
| "p2trLegacy"
| "p2trMusig2ScriptPath"
| "p2trMusig2KeyPath";
export const inputScriptTypes = [
"p2shP2pk",
"p2sh",
"p2shP2wsh",
"p2wsh",
"p2trLegacy",
"p2trMusig2ScriptPath",
"p2trMusig2KeyPath",
] as const;

/**
* Input script type for fixed-script wallets
*/
export type InputScriptType = (typeof inputScriptTypes)[number];

/**
* Union of all script types that can be checked for network support
Expand Down
Loading