@@ -70,12 +70,17 @@ export type AddInputOptions = {
7070 prevTx ?: Uint8Array ;
7171} ;
7272
73- export type AddOutputOptions = {
74- /** Output script (scriptPubKey) */
75- script : Uint8Array ;
76- /** Value in satoshis */
77- value : bigint ;
78- } ;
73+ export type AddOutputOptions =
74+ | {
75+ script : Uint8Array ;
76+ /** Value in satoshis */
77+ value : bigint ;
78+ }
79+ | {
80+ address : string ;
81+ /** Value in satoshis */
82+ value : bigint ;
83+ } ;
7984
8085/** Key identifier for signing ("user", "backup", or "bitgo") */
8186export type SignerKey = "user" | "backup" | "bitgo" ;
@@ -196,19 +201,70 @@ export class BitGoPsbt {
196201 /**
197202 * Add an output to the PSBT
198203 *
199- * @param options - Output options (script, value)
204+ * @param script - The output script (scriptPubKey)
205+ * @param value - Value in satoshis
206+ * @returns The index of the newly added output
207+ *
208+ * @example
209+ * ```typescript
210+ * const outputIndex = psbt.addOutput(outputScript, 50000n);
211+ * ```
212+ */
213+ addOutput ( script : Uint8Array , value : bigint ) : number ;
214+ /**
215+ * Add an output to the PSBT by address
216+ *
217+ * @param address - The destination address
218+ * @param value - Value in satoshis
219+ * @returns The index of the newly added output
220+ *
221+ * @example
222+ * ```typescript
223+ * const outputIndex = psbt.addOutput("bc1q...", 50000n);
224+ * ```
225+ */
226+ addOutput ( address : string , value : bigint ) : number ;
227+ /**
228+ * Add an output to the PSBT
229+ *
230+ * @param options - Output options (script or address, and value)
200231 * @returns The index of the newly added output
201232 *
202233 * @example
203234 * ```typescript
235+ * // Using script
204236 * const outputIndex = psbt.addOutput({
205237 * script: outputScript,
206238 * value: 50000n,
207239 * });
240+ *
241+ * // Using address
242+ * const outputIndex = psbt.addOutput({
243+ * address: "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",
244+ * value: 50000n,
245+ * });
208246 * ```
209247 */
210- addOutput ( options : AddOutputOptions ) : number {
211- return this . _wasm . add_output ( options . script , options . value ) ;
248+ addOutput ( options : AddOutputOptions ) : number ;
249+ addOutput ( scriptOrOptions : Uint8Array | string | AddOutputOptions , value ?: bigint ) : number {
250+ if ( scriptOrOptions instanceof Uint8Array || typeof scriptOrOptions === "string" ) {
251+ if ( value === undefined ) {
252+ throw new Error ( "Value is required when passing a script or address" ) ;
253+ }
254+ if ( scriptOrOptions instanceof Uint8Array ) {
255+ return this . _wasm . add_output ( scriptOrOptions , value ) ;
256+ }
257+ return this . _wasm . add_output_with_address ( scriptOrOptions , value ) ;
258+ }
259+
260+ const options = scriptOrOptions ;
261+ if ( "script" in options ) {
262+ return this . _wasm . add_output ( options . script , options . value ) ;
263+ }
264+ if ( "address" in options ) {
265+ return this . _wasm . add_output_with_address ( options . address , options . value ) ;
266+ }
267+ throw new Error ( "Invalid output options" ) ;
212268 }
213269
214270 /**
0 commit comments