@@ -8,6 +8,7 @@ import { checkForOutput } from 'bip174/src/lib/utils';
8
8
9
9
import {
10
10
addPayGoAddressProof ,
11
+ createPayGoAttestationBuffer ,
11
12
getPayGoAddressProofOutputIndex ,
12
13
psbtOutputIncludesPaygoAddressProof ,
13
14
verifyPayGoAddressProof ,
@@ -37,7 +38,7 @@ const attestationPubKey = dummyPub1.user.publicKey;
37
38
const attestationPrvKey = dummyPub1 . user . privateKey ! ;
38
39
39
40
// UUID structure
40
- const nilUUID = '00000000-0000-0000-0000-000000000000' ;
41
+ const nillUUID = '00000000-0000-0000-0000-000000000000' ;
41
42
42
43
// our xpub converted to base58 address
43
44
const addressToVerify = utxolib . address . toBase58Check (
@@ -47,7 +48,7 @@ const addressToVerify = utxolib.address.toBase58Check(
47
48
) ;
48
49
49
50
// this should be retuning a Buffer
50
- const addressProofBuffer = generatePayGoAttestationProof ( nilUUID , Buffer . from ( addressToVerify ) ) ;
51
+ const addressProofBuffer = generatePayGoAttestationProof ( nillUUID , Buffer . from ( addressToVerify ) ) ;
51
52
const addressProofMsgBuffer = parseVaspProof ( addressProofBuffer ) ;
52
53
// We know that that the entropy is a set 64 bytes.
53
54
const addressProofEntropy = addressProofMsgBuffer . subarray ( 0 , 65 ) ;
@@ -73,25 +74,12 @@ describe('addPaygoAddressProof and verifyPaygoAddressProof', () => {
73
74
} ) ;
74
75
}
75
76
76
- it ( 'should fail a proof verification with wrong UUID' , ( ) => {
77
- const outputIndex = 0 ;
78
- const psbt = getTestPsbt ( ) ;
79
- addPayGoAddressProof ( psbt , outputIndex , sig , addressProofEntropy ) ;
80
- const output = checkForOutput ( psbt . data . outputs , outputIndex ) ;
81
- const proofInPsbt = getPaygoProprietaryKey ( output . unknownKeyVals ! ) ;
82
- assert ( proofInPsbt . length === 1 ) ;
83
- assert . throws (
84
- ( ) => verifyPayGoAddressProof ( psbt , 0 , '00000000-0000-0000-0000-000000000001' , attestationPubKey ) ,
85
- ( e : any ) => e . message === 'Cannot verify the paygo address signature with the provided pubkey.'
86
- ) ;
87
- } ) ;
88
-
89
77
it ( 'should add and verify a valid paygo address proof on the PSBT' , ( ) => {
90
78
const psbt = getTestPsbt ( ) ;
91
79
psbt . addOutput ( { script : utxolib . address . toOutputScript ( addressToVerify , network ) , value : BigInt ( 10000 ) } ) ;
92
80
const outputIndex = psbt . data . outputs . length - 1 ;
93
81
addPayGoAddressProof ( psbt , outputIndex , sig , addressProofEntropy ) ;
94
- verifyPayGoAddressProof ( psbt , outputIndex , nilUUID , attestationPubKey ) ;
82
+ verifyPayGoAddressProof ( psbt , outputIndex , attestationPubKey ) ;
95
83
} ) ;
96
84
97
85
it ( 'should throw an error if there are multiple PayGo proprietary keys in the PSBT' , ( ) => {
@@ -104,7 +92,7 @@ describe('addPaygoAddressProof and verifyPaygoAddressProof', () => {
104
92
assert ( proofInPsbt . length !== 0 ) ;
105
93
assert ( proofInPsbt . length > 1 ) ;
106
94
assert . throws (
107
- ( ) => verifyPayGoAddressProof ( psbt , outputIndex , nilUUID , attestationPubKey ) ,
95
+ ( ) => verifyPayGoAddressProof ( psbt , outputIndex , attestationPubKey ) ,
108
96
( e : any ) => e . message === 'There are multiple paygo address proofs encoded in the PSBT. Something went wrong.'
109
97
) ;
110
98
} ) ;
@@ -114,7 +102,7 @@ describe('verifyPaygoAddressProof', () => {
114
102
it ( 'should throw an error if there is no PayGo address in PSBT' , ( ) => {
115
103
const psbt = getTestPsbt ( ) ;
116
104
assert . throws (
117
- ( ) => verifyPayGoAddressProof ( psbt , 0 , nilUUID , attestationPubKey ) ,
105
+ ( ) => verifyPayGoAddressProof ( psbt , 0 , attestationPubKey ) ,
118
106
( e : any ) => e . message === 'There is no paygo address proof encoded in the PSBT at output 0.'
119
107
) ;
120
108
} ) ;
@@ -146,3 +134,21 @@ describe('getPaygoAddressProofIndex', () => {
146
134
) ;
147
135
} ) ;
148
136
} ) ;
137
+
138
+ describe ( 'createPayGoAttestationBuffer' , ( ) => {
139
+ it ( 'should create a PayGo Attestation proof matching with original proof' , ( ) => {
140
+ const payGoAttestationProof = createPayGoAttestationBuffer ( addressToVerify , addressProofEntropy ) ;
141
+ assert . strictEqual ( payGoAttestationProof . toString ( ) , addressProofMsgBuffer . toString ( ) ) ;
142
+ assert ( Buffer . compare ( payGoAttestationProof , addressProofMsgBuffer ) === 0 ) ;
143
+ } ) ;
144
+
145
+ it ( 'should create a PayGo Attestation proof that does not match with different uuid' , ( ) => {
146
+ const addressProofBufferDiffUuid = generatePayGoAttestationProof (
147
+ '00000000-0000-0000-0000-000000000001' ,
148
+ Buffer . from ( addressToVerify )
149
+ ) ;
150
+ const payGoAttestationProof = createPayGoAttestationBuffer ( addressToVerify , addressProofEntropy ) ;
151
+ assert . notStrictEqual ( payGoAttestationProof . toString ( ) , addressProofBufferDiffUuid . toString ( ) ) ;
152
+ assert ( Buffer . compare ( payGoAttestationProof , addressProofBufferDiffUuid ) !== 0 ) ;
153
+ } ) ;
154
+ } ) ;
0 commit comments