File tree Expand file tree Collapse file tree 4 files changed +19
-12
lines changed Expand file tree Collapse file tree 4 files changed +19
-12
lines changed Original file line number Diff line number Diff line change 1
- export class ErrorNoPayGoProof extends Error {
1
+ export class PayGoError extends Error {
2
+ constructor ( message : string ) {
3
+ super ( message ) ;
4
+ this . name = this . constructor . name ;
5
+ }
6
+ }
7
+
8
+ export class ErrorNoPayGoProof extends PayGoError {
2
9
constructor ( public outputIndex : number ) {
3
10
super ( `There is no paygo address proof encoded in the PSBT at output ${ outputIndex } .` ) ;
4
11
}
5
12
}
6
13
7
- export class ErrorMultiplePayGoProof extends Error {
14
+ export class ErrorMultiplePayGoProof extends PayGoError {
8
15
constructor ( ) {
9
16
super ( 'There are multiple paygo address proofs encoded in the PSBT. Something went wrong.' ) ;
10
17
}
11
18
}
12
19
13
- export class ErrorPayGoAddressProofFailedVerification extends Error {
20
+ export class ErrorPayGoAddressProofFailedVerification extends PayGoError {
14
21
constructor ( ) {
15
22
super ( 'Cannot verify the paygo address signature with the provided pubkey.' ) ;
16
23
}
17
24
}
18
25
19
- export class ErrorOutputIndexOutOfBounds extends Error {
26
+ export class ErrorOutputIndexOutOfBounds extends PayGoError {
20
27
constructor ( public outputIndex : number ) {
21
28
super ( `Output index ${ outputIndex } is out of bounds for PSBT outputs.` ) ;
22
29
}
23
30
}
24
31
25
- export class ErrorMultiplePayGoProofAtPsbtIndex extends Error {
32
+ export class ErrorMultiplePayGoProofAtPsbtIndex extends PayGoError {
26
33
constructor ( public outputIndex : number ) {
27
34
super ( `There are multiple PayGo addresses in the PSBT output ${ outputIndex } .` ) ;
28
35
}
Original file line number Diff line number Diff line change @@ -2,4 +2,4 @@ export * from './fixtures.utils';
2
2
export * from './key.utils' ;
3
3
export * from './toPlainObject.utils' ;
4
4
export * from './generatePayGoAttestationProof.utils' ;
5
- export * from './parseVaspProof ' ;
5
+ export * from './trimMessagePrefix ' ;
Original file line number Diff line number Diff line change @@ -2,14 +2,14 @@ import * as utxolib from '@bitgo/utxo-lib';
2
2
3
3
/** We receive a proof in the form:
4
4
* 0x18Bitcoin Signed Message:\n<varint_length><ENTROPY><ADDRESS><UUID>
5
- * and when verifying our message in our PayGo utils we want to only verify
6
- * the message portion of our proof. This helps to pare our proof in that format,
7
- * and returns a Buffer .
5
+ * and when verifying our message we want to exclude the 0x18Bitcoin Signed Message:\n<varint_length>
6
+ * of the proof so that we are left with the entropy address and uuid as our message.
7
+ * This is what we are going to be verifying .
8
8
*
9
9
* @param proof
10
10
* @returns
11
11
*/
12
- export function parseVaspProof ( proof : Buffer ) : Buffer {
12
+ export function trimMessagePrefix ( proof : Buffer ) : Buffer {
13
13
const prefix = '\u0018Bitcoin Signed Message:\n' ;
14
14
if ( proof . toString ( ) . startsWith ( prefix ) ) {
15
15
proof = proof . slice ( Buffer . from ( prefix ) . length ) ;
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import {
13
13
verifyPayGoAddressProof ,
14
14
} from '../../../src/paygo/psbt/payGoAddressProof' ;
15
15
import { generatePayGoAttestationProof } from '../../../src/testutil/generatePayGoAttestationProof.utils' ;
16
- import { parseVaspProof } from '../../../src/testutil/parseVaspProof ' ;
16
+ import { trimMessagePrefix } from '../../../src/testutil/trimMessagePrefix ' ;
17
17
import { signMessage } from '../../../src/bip32utils' ;
18
18
import { NIL_UUID } from '../../../src/paygo/attestation' ;
19
19
@@ -46,7 +46,7 @@ export const addressToVerify = utxolib.address.toBase58Check(
46
46
47
47
// this should be retuning a Buffer
48
48
export const addressProofBuffer = generatePayGoAttestationProof ( NIL_UUID , Buffer . from ( addressToVerify ) ) ;
49
- export const addressProofMsgBuffer = parseVaspProof ( addressProofBuffer ) ;
49
+ export const addressProofMsgBuffer = trimMessagePrefix ( addressProofBuffer ) ;
50
50
// We know that that the entropy is a set 64 bytes.
51
51
export const addressProofEntropy = addressProofMsgBuffer . subarray ( 0 , 65 ) ;
52
52
You can’t perform that action at this time.
0 commit comments