@@ -2,7 +2,7 @@ import assert from 'assert';
22
33import * as utxolib from '@bitgo/utxo-lib' ;
44
5- import { getBip322ProofMessageAtIndex } from '../../src/bip322' ;
5+ import { getBip322ProofMessageAtIndex , isBip322ProofCheck } from '../../src/bip322' ;
66
77import { BIP322_FIXTURE_HELLO_WORLD_TOSIGN_PSBT } from './bip322.utils' ;
88
@@ -35,4 +35,50 @@ describe('BIP322 Proof utils', function () {
3535 assert . ok ( messageBuffer , 'Message buffer should not be undefined' ) ;
3636 assert . deepStrictEqual ( messageBuffer . toString ( 'utf-8' ) , 'Hello World' , 'Message does not match expected value' ) ;
3737 } ) ;
38+
39+ describe ( 'isBip322ProofCheck' , function ( ) {
40+ it ( 'should work for PSBTs' , function ( ) {
41+ const psbt = utxolib . bitgo . createPsbtFromBuffer (
42+ BIP322_FIXTURE_HELLO_WORLD_TOSIGN_PSBT . toBuffer ( ) ,
43+ utxolib . networks . bitcoin
44+ ) ;
45+ assert . ok ( isBip322ProofCheck ( psbt ) , 'Expected PSBT to be a valid BIP322 proof' ) ;
46+ assert . deepEqual (
47+ isBip322ProofCheck (
48+ utxolib . testutil . constructPsbt (
49+ [ { scriptType : 'taprootKeyPathSpend' , value : BigInt ( 1000 ) } ] ,
50+ [ { scriptType : 'p2sh' , value : BigInt ( 900 ) } ] ,
51+ utxolib . networks . bitcoin ,
52+ utxolib . testutil . getDefaultWalletKeys ( ) ,
53+ 'unsigned'
54+ )
55+ ) ,
56+ false
57+ ) ;
58+ } ) ;
59+
60+ it ( 'should work for Transactions' , function ( ) {
61+ const psbt = utxolib . bitgo . createPsbtFromBuffer (
62+ BIP322_FIXTURE_HELLO_WORLD_TOSIGN_PSBT . toBuffer ( ) ,
63+ utxolib . networks . bitcoin
64+ ) ;
65+ // Cannot extract the transaction because it has no signatures
66+ const tx = psbt . getUnsignedTx ( ) ;
67+ assert . ok ( isBip322ProofCheck ( tx ) , 'Expected Transaction to be a valid BIP322 proof' ) ;
68+ assert . deepEqual (
69+ isBip322ProofCheck (
70+ utxolib . testutil
71+ . constructPsbt (
72+ [ { scriptType : 'taprootKeyPathSpend' , value : BigInt ( 1000 ) } ] ,
73+ [ { scriptType : 'p2sh' , value : BigInt ( 900 ) } ] ,
74+ utxolib . networks . bitcoin ,
75+ utxolib . testutil . getDefaultWalletKeys ( ) ,
76+ 'unsigned'
77+ )
78+ . getUnsignedTx ( )
79+ ) ,
80+ false
81+ ) ;
82+ } ) ;
83+ } ) ;
3884} ) ;
0 commit comments