@bitgo/wasm-utxo 1.19.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,10 +57,13 @@ export type AddInputOptions = {
57
57
  prevTx?: Uint8Array;
58
58
  };
59
59
  export type AddOutputOptions = {
60
- /** Output script (scriptPubKey) */
61
60
  script: Uint8Array;
62
61
  /** Value in satoshis */
63
62
  value: bigint;
63
+ } | {
64
+ address: string;
65
+ /** Value in satoshis */
66
+ value: bigint;
64
67
  };
65
68
  /** Key identifier for signing ("user", "backup", or "bitgo") */
66
69
  export type SignerKey = "user" | "backup" | "bitgo";
@@ -146,15 +149,48 @@ export declare class BitGoPsbt {
146
149
  /**
147
150
  * Add an output to the PSBT
148
151
  *
149
- * @param options - Output options (script, value)
152
+ * @param script - The output script (scriptPubKey)
153
+ * @param value - Value in satoshis
154
+ * @returns The index of the newly added output
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const outputIndex = psbt.addOutput(outputScript, 50000n);
159
+ * ```
160
+ */
161
+ addOutput(script: Uint8Array, value: bigint): number;
162
+ /**
163
+ * Add an output to the PSBT by address
164
+ *
165
+ * @param address - The destination address
166
+ * @param value - Value in satoshis
167
+ * @returns The index of the newly added output
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const outputIndex = psbt.addOutput("bc1q...", 50000n);
172
+ * ```
173
+ */
174
+ addOutput(address: string, value: bigint): number;
175
+ /**
176
+ * Add an output to the PSBT
177
+ *
178
+ * @param options - Output options (script or address, and value)
150
179
  * @returns The index of the newly added output
151
180
  *
152
181
  * @example
153
182
  * ```typescript
183
+ * // Using script
154
184
  * const outputIndex = psbt.addOutput({
155
185
  * script: outputScript,
156
186
  * value: 50000n,
157
187
  * });
188
+ *
189
+ * // Using address
190
+ * const outputIndex = psbt.addOutput({
191
+ * address: "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
192
+ * value: 50000n,
193
+ * });
158
194
  * ```
159
195
  */
160
196
  addOutput(options: AddOutputOptions): number;
@@ -77,22 +77,24 @@ class BitGoPsbt {
77
77
  addInput(options, script) {
78
78
  return this._wasm.add_input(options.txid, options.vout, options.value, script, options.sequence, options.prevTx);
79
79
  }
80
- /**
81
- * Add an output to the PSBT
82
- *
83
- * @param options - Output options (script, value)
84
- * @returns The index of the newly added output
85
- *
86
- * @example
87
- * ```typescript
88
- * const outputIndex = psbt.addOutput({
89
- * script: outputScript,
90
- * value: 50000n,
91
- * });
92
- * ```
93
- */
94
- addOutput(options) {
95
- return this._wasm.add_output(options.script, options.value);
80
+ addOutput(scriptOrOptions, value) {
81
+ if (scriptOrOptions instanceof Uint8Array || typeof scriptOrOptions === "string") {
82
+ if (value === undefined) {
83
+ throw new Error("Value is required when passing a script or address");
84
+ }
85
+ if (scriptOrOptions instanceof Uint8Array) {
86
+ return this._wasm.add_output(scriptOrOptions, value);
87
+ }
88
+ return this._wasm.add_output_with_address(scriptOrOptions, value);
89
+ }
90
+ const options = scriptOrOptions;
91
+ if ("script" in options) {
92
+ return this._wasm.add_output(options.script, options.value);
93
+ }
94
+ if ("address" in options) {
95
+ return this._wasm.add_output_with_address(options.address, options.value);
96
+ }
97
+ throw new Error("Invalid output options");
96
98
  }
97
99
  /**
98
100
  * Add a wallet input with full PSBT metadata
@@ -225,6 +225,17 @@ export class BitGoPsbt {
225
225
  * generated for security. Custom session_id is only allowed on testnets for testing purposes.
226
226
  */
227
227
  generate_musig2_nonces(xpriv: WasmBIP32, session_id_bytes?: Uint8Array | null): void;
228
+ /**
229
+ * Add an output to the PSBT by address
230
+ *
231
+ * # Arguments
232
+ * * `address` - The destination address
233
+ * * `value` - The value in satoshis
234
+ *
235
+ * # Returns
236
+ * The index of the newly added output
237
+ */
238
+ add_output_with_address(address: string, value: bigint): number;
228
239
  /**
229
240
  * Verify if a valid signature exists for a given ECPair key at the specified input index
230
241
  *
@@ -800,6 +800,36 @@ class BitGoPsbt {
800
800
  wasm.__wbindgen_add_to_stack_pointer(16);
801
801
  }
802
802
  }
803
+ /**
804
+ * Add an output to the PSBT by address
805
+ *
806
+ * # Arguments
807
+ * * `address` - The destination address
808
+ * * `value` - The value in satoshis
809
+ *
810
+ * # Returns
811
+ * The index of the newly added output
812
+ * @param {string} address
813
+ * @param {bigint} value
814
+ * @returns {number}
815
+ */
816
+ add_output_with_address(address, value) {
817
+ try {
818
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
819
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_export, wasm.__wbindgen_export2);
820
+ const len0 = WASM_VECTOR_LEN;
821
+ wasm.bitgopsbt_add_output_with_address(retptr, this.__wbg_ptr, ptr0, len0, value);
822
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
823
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
824
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
825
+ if (r2) {
826
+ throw takeObject(r1);
827
+ }
828
+ return r0 >>> 0;
829
+ } finally {
830
+ wasm.__wbindgen_add_to_stack_pointer(16);
831
+ }
832
+ }
803
833
  /**
804
834
  * Verify if a valid signature exists for a given ECPair key at the specified input index
805
835
  *
Binary file
@@ -57,6 +57,7 @@ export const addressnamespace_from_output_script_with_coin: (a: number, b: numbe
57
57
  export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
58
58
  export const bitgopsbt_add_input: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number, j: number, k: number) => void;
59
59
  export const bitgopsbt_add_output: (a: number, b: number, c: number, d: number, e: bigint) => void;
60
+ export const bitgopsbt_add_output_with_address: (a: number, b: number, c: number, d: number, e: bigint) => void;
60
61
  export const bitgopsbt_add_paygo_attestation: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
61
62
  export const bitgopsbt_add_replay_protection_input: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number) => void;
62
63
  export const bitgopsbt_add_wallet_input: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number) => void;
@@ -57,10 +57,13 @@ export type AddInputOptions = {
57
57
  prevTx?: Uint8Array;
58
58
  };
59
59
  export type AddOutputOptions = {
60
- /** Output script (scriptPubKey) */
61
60
  script: Uint8Array;
62
61
  /** Value in satoshis */
63
62
  value: bigint;
63
+ } | {
64
+ address: string;
65
+ /** Value in satoshis */
66
+ value: bigint;
64
67
  };
65
68
  /** Key identifier for signing ("user", "backup", or "bitgo") */
66
69
  export type SignerKey = "user" | "backup" | "bitgo";
@@ -146,15 +149,48 @@ export declare class BitGoPsbt {
146
149
  /**
147
150
  * Add an output to the PSBT
148
151
  *
149
- * @param options - Output options (script, value)
152
+ * @param script - The output script (scriptPubKey)
153
+ * @param value - Value in satoshis
154
+ * @returns The index of the newly added output
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const outputIndex = psbt.addOutput(outputScript, 50000n);
159
+ * ```
160
+ */
161
+ addOutput(script: Uint8Array, value: bigint): number;
162
+ /**
163
+ * Add an output to the PSBT by address
164
+ *
165
+ * @param address - The destination address
166
+ * @param value - Value in satoshis
167
+ * @returns The index of the newly added output
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const outputIndex = psbt.addOutput("bc1q...", 50000n);
172
+ * ```
173
+ */
174
+ addOutput(address: string, value: bigint): number;
175
+ /**
176
+ * Add an output to the PSBT
177
+ *
178
+ * @param options - Output options (script or address, and value)
150
179
  * @returns The index of the newly added output
151
180
  *
152
181
  * @example
153
182
  * ```typescript
183
+ * // Using script
154
184
  * const outputIndex = psbt.addOutput({
155
185
  * script: outputScript,
156
186
  * value: 50000n,
157
187
  * });
188
+ *
189
+ * // Using address
190
+ * const outputIndex = psbt.addOutput({
191
+ * address: "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
192
+ * value: 50000n,
193
+ * });
158
194
  * ```
159
195
  */
160
196
  addOutput(options: AddOutputOptions): number;
@@ -74,22 +74,24 @@ export class BitGoPsbt {
74
74
  addInput(options, script) {
75
75
  return this._wasm.add_input(options.txid, options.vout, options.value, script, options.sequence, options.prevTx);
76
76
  }
77
- /**
78
- * Add an output to the PSBT
79
- *
80
- * @param options - Output options (script, value)
81
- * @returns The index of the newly added output
82
- *
83
- * @example
84
- * ```typescript
85
- * const outputIndex = psbt.addOutput({
86
- * script: outputScript,
87
- * value: 50000n,
88
- * });
89
- * ```
90
- */
91
- addOutput(options) {
92
- return this._wasm.add_output(options.script, options.value);
77
+ addOutput(scriptOrOptions, value) {
78
+ if (scriptOrOptions instanceof Uint8Array || typeof scriptOrOptions === "string") {
79
+ if (value === undefined) {
80
+ throw new Error("Value is required when passing a script or address");
81
+ }
82
+ if (scriptOrOptions instanceof Uint8Array) {
83
+ return this._wasm.add_output(scriptOrOptions, value);
84
+ }
85
+ return this._wasm.add_output_with_address(scriptOrOptions, value);
86
+ }
87
+ const options = scriptOrOptions;
88
+ if ("script" in options) {
89
+ return this._wasm.add_output(options.script, options.value);
90
+ }
91
+ if ("address" in options) {
92
+ return this._wasm.add_output_with_address(options.address, options.value);
93
+ }
94
+ throw new Error("Invalid output options");
93
95
  }
94
96
  /**
95
97
  * Add a wallet input with full PSBT metadata
@@ -225,6 +225,17 @@ export class BitGoPsbt {
225
225
  * generated for security. Custom session_id is only allowed on testnets for testing purposes.
226
226
  */
227
227
  generate_musig2_nonces(xpriv: WasmBIP32, session_id_bytes?: Uint8Array | null): void;
228
+ /**
229
+ * Add an output to the PSBT by address
230
+ *
231
+ * # Arguments
232
+ * * `address` - The destination address
233
+ * * `value` - The value in satoshis
234
+ *
235
+ * # Returns
236
+ * The index of the newly added output
237
+ */
238
+ add_output_with_address(address: string, value: bigint): number;
228
239
  /**
229
240
  * Verify if a valid signature exists for a given ECPair key at the specified input index
230
241
  *
@@ -808,6 +808,36 @@ export class BitGoPsbt {
808
808
  wasm.__wbindgen_add_to_stack_pointer(16);
809
809
  }
810
810
  }
811
+ /**
812
+ * Add an output to the PSBT by address
813
+ *
814
+ * # Arguments
815
+ * * `address` - The destination address
816
+ * * `value` - The value in satoshis
817
+ *
818
+ * # Returns
819
+ * The index of the newly added output
820
+ * @param {string} address
821
+ * @param {bigint} value
822
+ * @returns {number}
823
+ */
824
+ add_output_with_address(address, value) {
825
+ try {
826
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
827
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_export, wasm.__wbindgen_export2);
828
+ const len0 = WASM_VECTOR_LEN;
829
+ wasm.bitgopsbt_add_output_with_address(retptr, this.__wbg_ptr, ptr0, len0, value);
830
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
831
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
832
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
833
+ if (r2) {
834
+ throw takeObject(r1);
835
+ }
836
+ return r0 >>> 0;
837
+ } finally {
838
+ wasm.__wbindgen_add_to_stack_pointer(16);
839
+ }
840
+ }
811
841
  /**
812
842
  * Verify if a valid signature exists for a given ECPair key at the specified input index
813
843
  *
Binary file
@@ -57,6 +57,7 @@ export const addressnamespace_from_output_script_with_coin: (a: number, b: numbe
57
57
  export const addressnamespace_to_output_script_with_coin: (a: number, b: number, c: number, d: number, e: number) => void;
58
58
  export const bitgopsbt_add_input: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number, j: number, k: number) => void;
59
59
  export const bitgopsbt_add_output: (a: number, b: number, c: number, d: number, e: bigint) => void;
60
+ export const bitgopsbt_add_output_with_address: (a: number, b: number, c: number, d: number, e: bigint) => void;
60
61
  export const bitgopsbt_add_paygo_attestation: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
61
62
  export const bitgopsbt_add_replay_protection_input: (a: number, b: number, c: number, d: number, e: number, f: number, g: bigint, h: number) => void;
62
63
  export const bitgopsbt_add_wallet_input: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitgo/wasm-utxo",
3
3
  "description": "WebAssembly wrapper for rust-bitcoin (beta)",
4
- "version": "1.19.0",
4
+ "version": "1.20.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",