Skip to content

Commit 26d42d4

Browse files
chore(abstract-utxo): function to get pub key
TICKET: BTC-2118
1 parent 9e14f14 commit 26d42d4

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

modules/abstract-utxo/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@bitgo/blockapis": "^1.10.19",
4646
"@bitgo/sdk-api": "^1.64.4",
4747
"@bitgo/sdk-core": "^35.6.0",
48+
"@bitgo/statics": "^55.0.0",
4849
"@bitgo/unspents": "^0.48.4",
4950
"@bitgo/utxo-core": "^1.12.0",
5051
"@bitgo/utxo-lib": "^11.6.2",

modules/abstract-utxo/src/transaction/fixedScript/explainTransaction.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as utxocore from '@bitgo/utxo-core';
55

66
import { Output, TransactionExplanation, FixedScriptWalletOutput } from '../../abstractUtxoCoin';
77
import { toExtendedAddressFormat } from '../recipient';
8-
import { Networks } from '../../../../statics/src/networks';
8+
import { getPayGoVerificationPubkey } from '../getPayGoVerificationPubkey';
99

1010
export type ChangeAddressInfo = { address: string; chain: number; index: number };
1111

@@ -198,31 +198,33 @@ export function explainPsbt<TNumber extends number | bigint, Tx extends bitgo.Ut
198198
* Extract PayGo address proof information from the PSBT if present
199199
* @returns Information about the PayGo proof, including the output index and address
200200
*/
201-
function getPayGoVerificationInfo():
202-
| { outputIndex: number | undefined; verificationPubkey: string | undefined }
203-
| undefined {
201+
function getPayGoVerificationInfo(): { outputIndex: number; verificationPubkey: string } | undefined {
204202
let outputIndex: number | undefined = undefined;
205203
let address: string | undefined = undefined;
206-
const verificationPubkey = Networks.test.bitcoin.paygoAddressAttestationPubkey;
207204
// Check if this PSBT has any PayGo address proofs
208205
if (!utxocore.paygo.psbtOutputIncludesPaygoAddressProof(psbt)) {
209206
return undefined;
210207
}
211208

209+
// This pulls the pubkey depending on given network
210+
const verificationPubkey = getPayGoVerificationPubkey(network);
211+
212212
// find which output index that contains the PayGo proof
213213
outputIndex = utxocore.paygo.getPayGoAddressProofOutputIndex(psbt);
214-
if (outputIndex !== undefined) {
215-
const output = txOutputs[outputIndex];
216-
address = utxolib.address.fromOutputScript(output.script, network);
217-
if (!address) {
218-
return undefined;
219-
}
214+
if (!outputIndex || !verificationPubkey) {
215+
return undefined;
220216
}
217+
const output = txOutputs[outputIndex];
218+
address = utxolib.address.fromOutputScript(output.script, network);
219+
if (!address) {
220+
return undefined;
221+
}
222+
221223
return { outputIndex, verificationPubkey };
222224
}
223225

224226
const payGoVerificationInfo = getPayGoVerificationInfo();
225-
if (payGoVerificationInfo && payGoVerificationInfo.outputIndex && payGoVerificationInfo.verificationPubkey) {
227+
if (payGoVerificationInfo) {
226228
utxocore.paygo.verifyPayGoAddressProof(
227229
psbt,
228230
payGoVerificationInfo.outputIndex,

modules/abstract-utxo/src/transaction/fixedScript/verifyTransaction.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import _ from 'lodash';
33
import BigNumber from 'bignumber.js';
44
import { BitGoBase } from '@bitgo/sdk-core';
55
import * as utxolib from '@bitgo/utxo-lib';
6-
import * as utxocore from '@bitgo/utxo-core';
76

87
import { AbstractUtxoCoin, Output, ParsedTransaction, VerifyTransactionOptions } from '../../abstractUtxoCoin';
98
import { verifyCustomChangeKeySignatures, verifyKeySignature, verifyUserPublicKey } from '../../verifyKey';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as utxolib from '@bitgo/utxo-lib';
2+
import { Networks } from '@bitgo/statics';
3+
4+
/**
5+
* We want to return the verification pubkey from our statics that has our
6+
* verification pubkey.
7+
* @param network
8+
* @returns
9+
*/
10+
export function getPayGoVerificationPubkey(network: utxolib.Network): string | undefined {
11+
const networkName = utxolib.getNetworkName(network);
12+
switch (networkName) {
13+
case 'testnet':
14+
return Networks.test.bitcoin.paygoAddressAttestationPubkey;
15+
default:
16+
return undefined;
17+
}
18+
}

0 commit comments

Comments
 (0)