@@ -8,17 +8,17 @@ import { checkForOutput } from 'bip174/src/lib/utils';
8
8
9
9
import {
10
10
addPayGoAddressProof ,
11
- createPayGoAttestationBuffer ,
12
11
getPayGoAddressProofOutputIndex ,
13
12
psbtOutputIncludesPaygoAddressProof ,
14
13
verifyPayGoAddressProof ,
15
- } from '../../../src/paygo/psbt/PayGoUtils ' ;
14
+ } from '../../../src/paygo/psbt/payGoAddressProof ' ;
16
15
import { generatePayGoAttestationProof } from '../../../src/testutil/generatePayGoAttestationProof.utils' ;
17
16
import { parseVaspProof } from '../../../src/testutil/parseVaspProof' ;
18
17
import { signMessage } from '../../../src/bip32utils' ;
18
+ import { NIL_UUID } from '../../../src/paygo/attestation' ;
19
19
20
20
// To construct our PSBTs
21
- const network = utxolib . networks . bitcoin ;
21
+ export const network = utxolib . networks . bitcoin ;
22
22
const keys = [ 1 , 2 , 3 ] . map ( ( v ) => utxolib . bip32 . fromSeed ( Buffer . alloc ( 16 , `test/2/${ v } ` ) , network ) ) ;
23
23
const rootWalletKeys = new utxolib . bitgo . RootWalletKeys ( [ keys [ 0 ] , keys [ 1 ] , keys [ 2 ] ] ) ;
24
24
@@ -34,34 +34,31 @@ const psbtOutputs = utxolib.testutil.outputScriptTypes.map((scriptType) => ({
34
34
35
35
// wallet pub and priv key for tbtc
36
36
const 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 ! ;
42
39
43
40
// our xpub converted to base58 address
44
- const addressToVerify = utxolib . address . toBase58Check (
41
+ export const addressToVerify = utxolib . address . toBase58Check (
45
42
utxolib . crypto . hash160 ( Buffer . from ( dummyPub1 . backup . publicKey ) ) ,
46
43
utxolib . networks . bitcoin . pubKeyHash ,
47
44
utxolib . networks . bitcoin
48
45
) ;
49
46
50
47
// 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 ) ;
53
50
// 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 ) ;
55
52
56
53
// signature with the given msg addressProofBuffer
57
- const sig = signMessage ( addressProofMsgBuffer . toString ( ) , attestationPrvKey ! , network ) ;
54
+ export const sig = signMessage ( addressProofMsgBuffer . toString ( ) , attestationPrvKey ! , network ) ;
58
55
59
56
function getTestPsbt ( ) {
60
57
return utxolib . testutil . constructPsbt ( psbtInputs , psbtOutputs , network , rootWalletKeys , 'unsigned' ) ;
61
58
}
62
59
63
60
describe ( 'addPaygoAddressProof and verifyPaygoAddressProof' , ( ) => {
64
- function getPaygoProprietaryKey ( proprietaryKeyVals : KeyValue [ ] ) {
61
+ function getPayGoProprietaryKey ( proprietaryKeyVals : KeyValue [ ] ) {
65
62
return proprietaryKeyVals
66
63
. map ( ( { key, value } ) => {
67
64
return { key : decodeProprietaryKey ( key ) , value } ;
@@ -88,7 +85,7 @@ describe('addPaygoAddressProof and verifyPaygoAddressProof', () => {
88
85
addPayGoAddressProof ( psbt , outputIndex , sig , addressProofEntropy ) ;
89
86
addPayGoAddressProof ( psbt , outputIndex , Buffer . from ( 'signature2' ) , crypto . randomBytes ( 64 ) ) ;
90
87
const output = checkForOutput ( psbt . data . outputs , outputIndex ) ;
91
- const proofInPsbt = getPaygoProprietaryKey ( output . unknownKeyVals ! ) ;
88
+ const proofInPsbt = getPayGoProprietaryKey ( output . unknownKeyVals ! ) ;
92
89
assert ( proofInPsbt . length !== 0 ) ;
93
90
assert ( proofInPsbt . length > 1 ) ;
94
91
assert . throws (
@@ -134,21 +131,3 @@ describe('getPaygoAddressProofIndex', () => {
134
131
) ;
135
132
} ) ;
136
133
} ) ;
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