@@ -2,46 +2,54 @@ import * as assert from 'assert';
22
33import { parsePayGoAttestation } from '../../src/paygo' ;
44import { generatePayGoAttestationProof } from '../../src/testutil' ;
5+ import { NIL_UUID } from '../../src/paygo/attestation' ;
56
67const addressFromPubKeyBase58 = 'bitgoAddressToExtract' ;
78const bufferAddressPubKeyB58 = Buffer . from ( addressFromPubKeyBase58 ) ;
89
9- describe ( 'extractAddressBufferFromPayGoAttestationProof' , ( ) => {
10- it ( 'should extractAddressBufferFromPayGoAttestationProof properly' , ( ) => {
11- const paygoAttestationProof = generatePayGoAttestationProof (
12- '00000000-0000-0000-0000-000000000000' ,
13- bufferAddressPubKeyB58
14- ) ;
10+ describe ( 'parsePayGoAttestationProof with prefix' , ( ) => {
11+ it ( 'should extractAddressBufferFromPayGoAttestationProof properly' , function ( ) {
12+ const paygoAttestationProof = generatePayGoAttestationProof ( NIL_UUID , bufferAddressPubKeyB58 ) ;
1513 const { entropy, address, uuid } = parsePayGoAttestation ( paygoAttestationProof ) ;
16- assert . deepStrictEqual ( Buffer . compare ( address , bufferAddressPubKeyB58 ) , 0 ) ;
17- assert . deepStrictEqual ( uuid . toString ( ) , '00000000-0000-0000-0000-000000000000' ) ;
14+ assert . ok ( address . equals ( bufferAddressPubKeyB58 ) ) ;
15+ assert . deepStrictEqual ( uuid . toString ( ) , NIL_UUID ) ;
1816 assert . deepStrictEqual ( entropy . length , 64 ) ;
1917 } ) ;
2018
21- it ( 'should extract the paygo address paygo attestation proof given a non nilUUID' , ( ) => {
19+ it ( 'should extract the paygo address paygo attestation proof given a non nilUUID' , function ( ) {
2220 const paygoAttestationProof = generatePayGoAttestationProof (
2321 '12345678-1234-4567-6890-231928472123' ,
2422 bufferAddressPubKeyB58
2523 ) ;
2624 const { entropy, address, uuid } = parsePayGoAttestation ( paygoAttestationProof ) ;
27- assert . deepStrictEqual ( Buffer . compare ( address , bufferAddressPubKeyB58 ) , 0 ) ;
28- assert . deepStrictEqual ( uuid . toString ( ) , '12345678-1234-4567-6890-231928472123' ) ;
25+ assert . ok ( address . equals ( bufferAddressPubKeyB58 ) ) ;
26+ assert . deepStrictEqual ( uuid . toString ( 'utf-8' ) , '12345678-1234-4567-6890-231928472123' ) ;
2927 assert . deepStrictEqual ( entropy . length , 64 ) ;
3028 } ) ;
3129
32- it ( 'should not extract the correct address given a uuid of wrong format' , ( ) => {
30+ it ( 'should not extract the correct address given a uuid of wrong format' , function ( ) {
3331 const paygoAttestationProof = generatePayGoAttestationProof (
3432 '000000000000000-000000-0000000-000000-0000000000000000' ,
3533 bufferAddressPubKeyB58
3634 ) ;
3735 const { address } = parsePayGoAttestation ( paygoAttestationProof ) ;
38- assert . notDeepStrictEqual ( Buffer . compare ( address , bufferAddressPubKeyB58 ) , 0 ) ;
36+ assert . ok ( ! address . equals ( bufferAddressPubKeyB58 ) ) ;
3937 } ) ;
4038
41- it ( 'should throw an error if the paygo attestation proof is too short' , ( ) => {
39+ it ( 'should throw an error if the paygo attestation proof is too short' , function ( ) {
4240 assert . throws (
43- ( ) => parsePayGoAttestation ( Buffer . from ( 'shortproof-shrug' ) ) ,
41+ ( ) => parsePayGoAttestation ( Buffer . from ( 'shortproof-shrug' , 'utf-8' ) ) ,
4442 'PayGo attestation proof is too short to contain a valid address.'
4543 ) ;
4644 } ) ;
4745} ) ;
46+
47+ describe ( 'parsePayGoAttestation without prefix' , function ( ) {
48+ it ( 'should extract the parts of the proof without the prefix automatically' , function ( ) {
49+ const payGoAttestationProof = generatePayGoAttestationProof ( NIL_UUID , bufferAddressPubKeyB58 , false ) ;
50+ const { entropy, address, uuid } = parsePayGoAttestation ( payGoAttestationProof ) ;
51+ assert . ok ( address . equals ( bufferAddressPubKeyB58 ) ) ;
52+ assert . deepStrictEqual ( uuid . toString ( ) , NIL_UUID ) ;
53+ assert . deepStrictEqual ( entropy . length , 64 ) ;
54+ } ) ;
55+ } ) ;
0 commit comments