Skip to content

Commit 46bcbb4

Browse files
authored
Merge pull request #5155 from BitGo/BTC-1632
fix: validate addresses created matches the requested format
2 parents 9d03546 + 01006ee commit 46bcbb4

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
AddressTypeChainMismatchError,
3030
BaseCoin,
3131
BitGoBase,
32+
CreateAddressFormat,
3233
decryptKeychainPrivateKey,
3334
ExtraPrebuildParamsOptions,
3435
HalfSignedUtxoTransaction,
@@ -251,6 +252,7 @@ export interface GenerateAddressOptions {
251252
}
252253

253254
export interface GenerateFixedScriptAddressOptions extends GenerateAddressOptions {
255+
format?: CreateAddressFormat;
254256
keychains: {
255257
pub: string;
256258
aspKeyId?: string;
@@ -1092,6 +1094,7 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
10921094
}
10931095

10941096
const expectedAddress = this.generateAddress({
1097+
format: params.format,
10951098
addressType: addressType as ScriptType2Of3,
10961099
keychains,
10971100
threshold: 2,
@@ -1220,7 +1223,7 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
12201223
);
12211224

12221225
return {
1223-
address,
1226+
address: this.canonicalAddress(address, params.format),
12241227
chain: derivationChain,
12251228
index: derivationIndex,
12261229
coin: this.getChain(),

modules/sdk-core/src/bitgo/baseCoin/iBaseCoin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { IPendingApprovals } from '../pendingApproval';
88
import { InitiateRecoveryOptions } from '../recovery';
99
import { EcdsaMPCv2Utils, EcdsaUtils } from '../utils/tss/ecdsa';
1010
import EddsaUtils, { PrebuildTransactionWithIntentOptions, TxRequest } from '../utils/tss/eddsa';
11-
import { CustomSigningFunction, IWallet, IWallets, Wallet, WalletData } from '../wallet';
11+
import { CreateAddressFormat, CustomSigningFunction, IWallet, IWallets, Wallet, WalletData } from '../wallet';
1212

1313
import { IWebhooks } from '../webhook/iWebhooks';
1414
import { TransactionType } from '../../account-lib';
@@ -105,6 +105,7 @@ export interface IBlsKeyPair extends KeyPair {
105105
}
106106

107107
export interface VerifyAddressOptions {
108+
format?: CreateAddressFormat;
108109
address: string;
109110
addressType?: string;
110111
keychains?: {

modules/sdk-core/src/bitgo/wallet/iWallet.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,16 @@ export interface ForwarderBalanceOptions {
437437
maximumBalance?: number;
438438
}
439439

440+
export type CreateAddressFormat = 'base58' | 'cashaddr';
441+
440442
export interface CreateAddressOptions {
441443
chain?: number;
442444
gasPrice?: number | string;
443445
count?: number;
444446
label?: string;
445447
lowPriority?: boolean;
446448
forwarderVersion?: number;
447-
format?: 'base58' | 'cashaddr';
449+
format?: CreateAddressFormat;
448450
baseAddress?: string;
449451
allowSkipVerifyAddress?: boolean;
450452
derivedAddress?: string;

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,7 @@ export class Wallet implements IWallet {
12671267

12681268
newAddress.keychains = keychains;
12691269
newAddress.baseAddress = baseAddress ?? _.get(this._wallet, 'coinSpecific.baseAddress');
1270+
newAddress.format = addressParams.format;
12701271

12711272
const verificationData: VerifyAddressOptions = _.merge({}, newAddress, { rootAddress });
12721273

0 commit comments

Comments
 (0)