File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
packages/wasm-miniscript/test Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 11import * as utxolib from "@bitgo/utxo-lib" ;
22import { Descriptor , Psbt } from "../js" ;
33
4- export function toWrappedPsbt ( psbt : utxolib . bitgo . UtxoPsbt | Buffer | Uint8Array ) {
5- if ( psbt instanceof utxolib . bitgo . UtxoPsbt ) {
4+ function toAddress ( descriptor : Descriptor , network : utxolib . Network ) {
5+ utxolib . address . fromOutputScript ( Buffer . from ( descriptor . scriptPubkey ( ) ) , network ) ;
6+ }
7+
8+ export function toWrappedPsbt ( psbt : utxolib . bitgo . UtxoPsbt | utxolib . Psbt | Buffer | Uint8Array ) {
9+ if ( psbt instanceof utxolib . bitgo . UtxoPsbt || psbt instanceof utxolib . Psbt ) {
610 psbt = psbt . toBuffer ( ) ;
711 }
812 if ( psbt instanceof Buffer || psbt instanceof Uint8Array ) {
@@ -24,11 +28,20 @@ export function toUtxoPsbt(psbt: Psbt | Buffer | Uint8Array) {
2428}
2529
2630export function updateInputWithDescriptor (
27- psbt : utxolib . bitgo . UtxoPsbt ,
31+ psbt : utxolib . Psbt ,
2832 inputIndex : number ,
2933 descriptor : Descriptor ,
3034) {
3135 const wrappedPsbt = toWrappedPsbt ( psbt ) ;
3236 wrappedPsbt . updateInputWithDescriptor ( inputIndex , descriptor ) ;
3337 psbt . data . inputs [ inputIndex ] = toUtxoPsbt ( wrappedPsbt ) . data . inputs [ inputIndex ] ;
3438}
39+
40+ export function finalizePsbt ( psbt : utxolib . Psbt ) {
41+ const wrappedPsbt = toWrappedPsbt ( psbt ) ;
42+ wrappedPsbt . finalize ( ) ;
43+ const unwrappedPsbt = toUtxoPsbt ( wrappedPsbt ) ;
44+ for ( let i = 0 ; i < psbt . data . inputs . length ; i ++ ) {
45+ psbt . data . inputs [ i ] = unwrappedPsbt . data . inputs [ i ] ;
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments