@@ -8,17 +8,17 @@ import { checkForOutput } from 'bip174/src/lib/utils';
88
99import {
1010 addPayGoAddressProof ,
11- createPayGoAttestationBuffer ,
1211 getPayGoAddressProofOutputIndex ,
1312 psbtOutputIncludesPaygoAddressProof ,
1413 verifyPayGoAddressProof ,
15- } from '../../../src/paygo/psbt/PayGoUtils ' ;
14+ } from '../../../src/paygo/psbt/payGoAddressProof ' ;
1615import { generatePayGoAttestationProof } from '../../../src/testutil/generatePayGoAttestationProof.utils' ;
1716import { parseVaspProof } from '../../../src/testutil/parseVaspProof' ;
1817import { signMessage } from '../../../src/bip32utils' ;
18+ import { NIL_UUID } from '../../../src/paygo/attestation' ;
1919
2020// To construct our PSBTs
21- const network = utxolib . networks . bitcoin ;
21+ export const network = utxolib . networks . bitcoin ;
2222const keys = [ 1 , 2 , 3 ] . map ( ( v ) => utxolib . bip32 . fromSeed ( Buffer . alloc ( 16 , `test/2/${ v } ` ) , network ) ) ;
2323const rootWalletKeys = new utxolib . bitgo . RootWalletKeys ( [ keys [ 0 ] , keys [ 1 ] , keys [ 2 ] ] ) ;
2424
@@ -34,34 +34,31 @@ const psbtOutputs = utxolib.testutil.outputScriptTypes.map((scriptType) => ({
3434
3535// wallet pub and priv key for tbtc
3636const dummyPub1 = rootWalletKeys . deriveForChainAndIndex ( 50 , 200 ) ;
37- const attestationPubKey = dummyPub1 . user . publicKey ;
38- const attestationPrvKey = dummyPub1 . user . privateKey ! ;
39-
40- // UUID structure
41- const nillUUID = '00000000-0000-0000-0000-000000000000' ;
37+ export const attestationPubKey = dummyPub1 . user . publicKey ;
38+ export const attestationPrvKey = dummyPub1 . user . privateKey ! ;
4239
4340// our xpub converted to base58 address
44- const addressToVerify = utxolib . address . toBase58Check (
41+ export const addressToVerify = utxolib . address . toBase58Check (
4542 utxolib . crypto . hash160 ( Buffer . from ( dummyPub1 . backup . publicKey ) ) ,
4643 utxolib . networks . bitcoin . pubKeyHash ,
4744 utxolib . networks . bitcoin
4845) ;
4946
5047// this should be retuning a Buffer
51- const addressProofBuffer = generatePayGoAttestationProof ( nillUUID , Buffer . from ( addressToVerify ) ) ;
52- const addressProofMsgBuffer = parseVaspProof ( addressProofBuffer ) ;
48+ export const addressProofBuffer = generatePayGoAttestationProof ( NIL_UUID , Buffer . from ( addressToVerify ) ) ;
49+ export const addressProofMsgBuffer = parseVaspProof ( addressProofBuffer ) ;
5350// We know that that the entropy is a set 64 bytes.
54- const addressProofEntropy = addressProofMsgBuffer . subarray ( 0 , 65 ) ;
51+ export const addressProofEntropy = addressProofMsgBuffer . subarray ( 0 , 65 ) ;
5552
5653// signature with the given msg addressProofBuffer
57- const sig = signMessage ( addressProofMsgBuffer . toString ( ) , attestationPrvKey ! , network ) ;
54+ export const sig = signMessage ( addressProofMsgBuffer . toString ( ) , attestationPrvKey ! , network ) ;
5855
5956function getTestPsbt ( ) {
6057 return utxolib . testutil . constructPsbt ( psbtInputs , psbtOutputs , network , rootWalletKeys , 'unsigned' ) ;
6158}
6259
6360describe ( 'addPaygoAddressProof and verifyPaygoAddressProof' , ( ) => {
64- function getPaygoProprietaryKey ( proprietaryKeyVals : KeyValue [ ] ) {
61+ function getPayGoProprietaryKey ( proprietaryKeyVals : KeyValue [ ] ) {
6562 return proprietaryKeyVals
6663 . map ( ( { key, value } ) => {
6764 return { key : decodeProprietaryKey ( key ) , value } ;
@@ -88,7 +85,7 @@ describe('addPaygoAddressProof and verifyPaygoAddressProof', () => {
8885 addPayGoAddressProof ( psbt , outputIndex , sig , addressProofEntropy ) ;
8986 addPayGoAddressProof ( psbt , outputIndex , Buffer . from ( 'signature2' ) , crypto . randomBytes ( 64 ) ) ;
9087 const output = checkForOutput ( psbt . data . outputs , outputIndex ) ;
91- const proofInPsbt = getPaygoProprietaryKey ( output . unknownKeyVals ! ) ;
88+ const proofInPsbt = getPayGoProprietaryKey ( output . unknownKeyVals ! ) ;
9289 assert ( proofInPsbt . length !== 0 ) ;
9390 assert ( proofInPsbt . length > 1 ) ;
9491 assert . throws (
@@ -134,21 +131,3 @@ describe('getPaygoAddressProofIndex', () => {
134131 ) ;
135132 } ) ;
136133} ) ;
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