@@ -4,24 +4,30 @@ import { KeyValue } from 'bip174/src/lib/interfaces';
4
4
import { checkForOutput } from 'bip174/src/lib/utils' ;
5
5
6
6
import { bip32 , networks , testutil } from '../../../src'
7
- import { addPaygoAddressProof , verifyPaygoAddressProof , getPaygoAddressProofIndex , psbtIncludesPaygoAddressProof } from "../../../src/bitgo/psbt/paygoAddressProof" ;
8
- import { inputScriptTypes , outputScriptTypes } from '../../../src/testutil' ;
7
+ import { addPaygoAddressProof , verifyPaygoAddressProof , getPaygoAddressProofOutputIndex , psbtOutputIncludesPaygoAddressProof } from "../../../src/bitgo/psbt/paygoAddressProof" ;
8
+ import { generatePayGoAttestationProof , inputScriptTypes , outputScriptTypes } from '../../../src/testutil' ;
9
9
import { ProprietaryKeySubtype , PSBT_PROPRIETARY_IDENTIFIER , RootWalletKeys } from '../../../src/bitgo' ;
10
10
11
11
12
12
const network = networks . bitcoin ;
13
13
const keys = [ 1 , 2 , 3 ] . map ( ( v ) => bip32 . fromSeed ( Buffer . alloc ( 16 , `test/2/${ v } ` ) , network ) )
14
14
const rootWalletKeys = new RootWalletKeys ( [ keys [ 0 ] , keys [ 1 ] , keys [ 2 ] ] )
15
- const dummyKey1 = rootWalletKeys . deriveForChainAndIndex ( 50 , 200 ) ;
15
+ // const dummyKey1 = rootWalletKeys.deriveForChainAndIndex(50, 200);
16
16
const dummyKey2 = rootWalletKeys . deriveForChainAndIndex ( 60 , 201 ) ;
17
- const dumm1yXPubs = dummyKey1 . publicKeys ;
18
- const dummy1PubKey = dummyKey1 . user . publicKey ;
19
17
20
18
const psbtInputs = inputScriptTypes . map ( ( scriptType ) => ( { scriptType, value : BigInt ( 1000 ) } ) )
21
19
const psbtOutputs = outputScriptTypes . map ( ( scriptType ) => ( { scriptType, value : BigInt ( 900 ) } ) )
22
- const sig = dummyKey1 . user . privateKey ! ;
20
+ // const dummy1PubKey = dummyKey1.user.publicKey;
21
+ // This generatePayGoAttestationProof function should be returning the bitcoin signed message
23
22
const sig2 = dummyKey2 . user . privateKey ! ;
24
23
24
+ // wallet pub and priv key for tbtc
25
+ const attestationPubKey = "xpub661MyMwAqRbcFU2Qx7pvGmmiQpVj8NcR7dSVpgqNChMkQyobpVWWERcrTb47WicmXwkhAY2VrC3hb29s18FDQWJf5pLm3saN6uLXAXpw1GV" ;
26
+ const attestationPrvKey = "red" ;
27
+ const nilUUID = '00000000-0000-0000-0000-000000000000' ;
28
+ const addressProofBuffer = generatePayGoAttestationProof ( Buffer . from ( attestationPrvKey ) , nilUUID , Buffer . from ( address ) )
29
+
30
+
25
31
function getTestPsbt ( ) {
26
32
return testutil . constructPsbt (
27
33
psbtInputs , psbtOutputs , network , rootWalletKeys , 'unsigned'
@@ -33,14 +39,14 @@ describe('addPaygoAddressProof and verifyPaygoAddressProof', () => {
33
39
return proprietaryKeyVals . map ( ( { key, value} ) => {
34
40
return { key : decodeProprietaryKey ( key ) , value } ;
35
41
} ) . filter ( ( keyValue ) => {
36
- return keyValue . key . identifier === PSBT_PROPRIETARY_IDENTIFIER && keyValue . key . subtype === ProprietaryKeySubtype . PAYGO_ADDRESS_PROOF
42
+ return keyValue . key . identifier === PSBT_PROPRIETARY_IDENTIFIER && keyValue . key . subtype === ProprietaryKeySubtype . PAYGO_ADDRESS_ATTESTATION_PROOF
37
43
} ) ;
38
44
}
39
45
40
46
it ( "should fail a proof verification if the proof isn't valid" , ( ) => {
41
47
const outputIndex = 0 ;
42
48
const psbt = getTestPsbt ( ) ;
43
- addPaygoAddressProof ( psbt , outputIndex , Buffer . from ( sig ) , dummy1PubKey ) ;
49
+ addPaygoAddressProof ( psbt , outputIndex , Buffer . from ( addressProofBuffer ) , Buffer . from ( attestationPubKey ) ) ;
44
50
const output = checkForOutput ( psbt . data . outputs , outputIndex ) ;
45
51
const proofInPsbt = getPaygoProprietaryKey ( output . unknownKeyVals ! ) ;
46
52
assert ( proofInPsbt . length === 1 )
@@ -50,45 +56,45 @@ describe('addPaygoAddressProof and verifyPaygoAddressProof', () => {
50
56
it ( "should add and verify a valid paygo address proof on the PSBT" , ( ) => {
51
57
const outputIndex = 0 ;
52
58
const psbt = getTestPsbt ( ) ;
53
- addPaygoAddressProof ( psbt , outputIndex , Buffer . from ( sig ) , dummy1PubKey ) ;
59
+ addPaygoAddressProof ( psbt , outputIndex , Buffer . from ( addressProofBuffer ) , Buffer . from ( attestationPubKey ) ) ;
54
60
// should verify function return a boolean? that way we can assert
55
61
// if this is verified, throws an error otherwise or false + error msg as an object
56
- verifyPaygoAddressProof ( psbt , outputIndex , dummy1PubKey ) ;
62
+ verifyPaygoAddressProof ( psbt , outputIndex , Buffer . from ( attestationPubKey ) ) ;
57
63
} ) ;
58
64
59
65
it ( "should throw an error if there are multiple PayGo proprietary keys in the PSBT" , ( ) => {
60
66
const outputIndex = 0 ;
61
67
const psbt = getTestPsbt ( ) ;
62
- addPaygoAddressProof ( psbt , outputIndex , Buffer . from ( sig ) , dummy1PubKey ) ;
63
- addPaygoAddressProof ( psbt , outputIndex , Buffer . from ( sig2 ) , dummy1PubKey ) ;
68
+ addPaygoAddressProof ( psbt , outputIndex , Buffer . from ( addressProofBuffer ) , Buffer . from ( attestationPubKey ) ) ;
69
+ addPaygoAddressProof ( psbt , outputIndex , Buffer . from ( sig2 ) , Buffer . from ( attestationPubKey ) ) ;
64
70
const output = checkForOutput ( psbt . data . outputs , outputIndex ) ;
65
71
const proofInPsbt = getPaygoProprietaryKey ( output . unknownKeyVals ! ) ;
66
72
assert ( proofInPsbt . length !== 0 )
67
73
assert ( proofInPsbt . length <= 1 )
68
- assert . throws ( ( ) => verifyPaygoAddressProof ( psbt , outputIndex , dummy1PubKey ) , ( e : any ) => e . message === 'There are multiple paygo address proofs encoded in the PSBT. Something went wrong.' ) ;
74
+ assert . throws ( ( ) => verifyPaygoAddressProof ( psbt , outputIndex , Buffer . from ( attestationPubKey ) ) , ( e : any ) => e . message === 'There are multiple paygo address proofs encoded in the PSBT. Something went wrong.' ) ;
69
75
} ) ;
70
76
} ) ;
71
77
72
78
73
79
describe ( 'verifyPaygoAddressProof' , ( ) => {
74
80
it ( 'should throw an error if there is no PayGo address in PSBT' , ( ) => {
75
81
const psbt = getTestPsbt ( ) ;
76
- assert . throws ( ( ) => verifyPaygoAddressProof ( psbt , 0 , dummy1PubKey ) , ( e : any ) => e . message === 'here is no paygo address proof encoded in the PSBT.' ) ;
82
+ assert . throws ( ( ) => verifyPaygoAddressProof ( psbt , 0 , Buffer . from ( attestationPubKey ) ) , ( e : any ) => e . message === 'here is no paygo address proof encoded in the PSBT.' ) ;
77
83
} ) ;
78
84
} ) ;
79
85
80
86
describe ( 'getPaygoAddressProofIndex' , ( ) => {
81
87
it ( 'should get PayGo address proof index from PSBT if there is one' , ( ) => {
82
88
const psbt = getTestPsbt ( ) ;
83
89
const outputIndex = 0 ;
84
- addPaygoAddressProof ( psbt , outputIndex , Buffer . from ( sig ) , dummy1PubKey ) ;
85
- assert ( psbtIncludesPaygoAddressProof ( psbt ) ) ;
86
- assert ( getPaygoAddressProofIndex ( psbt ) === 1 )
90
+ addPaygoAddressProof ( psbt , outputIndex , Buffer . from ( addressProofBuffer ) , Buffer . from ( attestationPubKey ) ) ;
91
+ assert ( psbtOutputIncludesPaygoAddressProof ( psbt ) ) ;
92
+ assert ( getPaygoAddressProofOutputIndex ( psbt ) === 0 )
87
93
} ) ;
88
94
89
95
it ( "should return undefined if there is no PayGo address proof in PSBT" , ( ) => {
90
96
const psbt = getTestPsbt ( ) ;
91
- assert ( getPaygoAddressProofIndex ( psbt ) === undefined )
92
- assert ( ! psbtIncludesPaygoAddressProof ( psbt ) )
97
+ assert ( getPaygoAddressProofOutputIndex ( psbt ) === undefined )
98
+ assert ( ! psbtOutputIncludesPaygoAddressProof ( psbt ) )
93
99
} ) ;
94
100
} ) ;
0 commit comments