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 {
29 constructor ( public outputIndex : number ) {
310 super ( `There is no paygo address proof encoded in the PSBT at output ${ outputIndex } .` ) ;
411 }
512}
613
7- export class ErrorMultiplePayGoProof extends Error {
14+ export class ErrorMultiplePayGoProof extends PayGoError {
815 constructor ( ) {
916 super ( 'There are multiple paygo address proofs encoded in the PSBT. Something went wrong.' ) ;
1017 }
1118}
1219
13- export class ErrorPayGoAddressProofFailedVerification extends Error {
20+ export class ErrorPayGoAddressProofFailedVerification extends PayGoError {
1421 constructor ( ) {
1522 super ( 'Cannot verify the paygo address signature with the provided pubkey.' ) ;
1623 }
1724}
1825
19- export class ErrorOutputIndexOutOfBounds extends Error {
26+ export class ErrorOutputIndexOutOfBounds extends PayGoError {
2027 constructor ( public outputIndex : number ) {
2128 super ( `Output index ${ outputIndex } is out of bounds for PSBT outputs.` ) ;
2229 }
2330}
2431
25- export class ErrorMultiplePayGoProofAtPsbtIndex extends Error {
32+ export class ErrorMultiplePayGoProofAtPsbtIndex extends PayGoError {
2633 constructor ( public outputIndex : number ) {
2734 super ( `There are multiple PayGo addresses in the PSBT output ${ outputIndex } .` ) ;
2835 }
Original file line number Diff line number Diff line change @@ -2,4 +2,4 @@ export * from './fixtures.utils';
22export * from './key.utils' ;
33export * from './toPlainObject.utils' ;
44export * 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';
22
33/** We receive a proof in the form:
44 * 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 .
88 *
99 * @param proof
1010 * @returns
1111 */
12- export function parseVaspProof ( proof : Buffer ) : Buffer {
12+ export function trimMessagePrefix ( proof : Buffer ) : Buffer {
1313 const prefix = '\u0018Bitcoin Signed Message:\n' ;
1414 if ( proof . toString ( ) . startsWith ( prefix ) ) {
1515 proof = proof . slice ( Buffer . from ( prefix ) . length ) ;
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import {
1313 verifyPayGoAddressProof ,
1414} from '../../../src/paygo/psbt/payGoAddressProof' ;
1515import { generatePayGoAttestationProof } from '../../../src/testutil/generatePayGoAttestationProof.utils' ;
16- import { parseVaspProof } from '../../../src/testutil/parseVaspProof ' ;
16+ import { trimMessagePrefix } from '../../../src/testutil/trimMessagePrefix ' ;
1717import { signMessage } from '../../../src/bip32utils' ;
1818import { NIL_UUID } from '../../../src/paygo/attestation' ;
1919
@@ -46,7 +46,7 @@ export const addressToVerify = utxolib.address.toBase58Check(
4646
4747// this should be retuning a Buffer
4848export const addressProofBuffer = generatePayGoAttestationProof ( NIL_UUID , Buffer . from ( addressToVerify ) ) ;
49- export const addressProofMsgBuffer = parseVaspProof ( addressProofBuffer ) ;
49+ export const addressProofMsgBuffer = trimMessagePrefix ( addressProofBuffer ) ;
5050// We know that that the entropy is a set 64 bytes.
5151export const addressProofEntropy = addressProofMsgBuffer . subarray ( 0 , 65 ) ;
5252
You can’t perform that action at this time.
0 commit comments