Skip to content

Commit d717184

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): move generateAddress to a separate file
Move the generateAddress function to its own module and update imports across the codebase to maintain functionality. Issue: BTC-2652 Co-authored-by: llm-git <[email protected]>
1 parent 4cf86ea commit d717184

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

modules/abstract-utxo/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './abstractUtxoCoin';
2+
export * from './address';
23
export * from './config';
34
export * from './recovery';
45
export * from './replayProtection';

modules/abstract-utxo/test/unit/abstractUtxoCoin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import should = require('should');
33
import * as sinon from 'sinon';
44
import { Wallet, UnexpectedAddressError, VerificationOptions, Triple } from '@bitgo/sdk-core';
55

6-
import { UtxoWallet, Output, TransactionExplanation, TransactionParams } from '../../src';
6+
import { UtxoWallet, Output, TransactionExplanation, TransactionParams, generateAddress } from '../../src';
77

88
import { bip322Fixtures } from './fixtures/bip322/fixtures';
99
import { psbtTxHex } from './fixtures/psbtHexProof';
@@ -151,7 +151,7 @@ describe('Abstract UTXO Coin:', () => {
151151
threshold: 2,
152152
};
153153

154-
const { address: changeAddress, coinSpecific } = coin.generateAddress(addressData);
154+
const { address: changeAddress, coinSpecific } = generateAddress(coin.network, coin.getChain(), addressData);
155155

156156
const changeWalletId = 'changeWalletId';
157157
const stubData = {

modules/abstract-utxo/test/unit/address.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as assert from 'assert';
44
import * as utxolib from '@bitgo/utxo-lib';
55
const { chainCodes } = utxolib.bitgo;
66

7-
import { AbstractUtxoCoin, GenerateFixedScriptAddressOptions } from '../../src';
7+
import { AbstractUtxoCoin, GenerateFixedScriptAddressOptions, generateAddress } from '../../src';
88

99
import { utxoCoins, keychains as keychainsBip32, getFixture, shouldEqualJSON } from './util';
1010

@@ -82,7 +82,7 @@ function run(coin: AbstractUtxoCoin) {
8282
const addresses = getParameters().map((p) => {
8383
const label = { chain: p.chain === undefined ? 'default' : p.chain };
8484
try {
85-
return [label, coin.generateAddress(p)];
85+
return [label, generateAddress(coin.network, coin.getChain(), p)];
8686
} catch (e) {
8787
return [label, { error: e.message }];
8888
}
@@ -94,11 +94,11 @@ function run(coin: AbstractUtxoCoin) {
9494
it('validates and verifies generated addresses', function () {
9595
getParameters().forEach((p) => {
9696
if (p.chain && !coin.supportsAddressChain(p.chain)) {
97-
assert.throws(() => coin.generateAddress(p));
97+
assert.throws(() => generateAddress(coin.network, coin.getChain(), p));
9898
return;
9999
}
100100

101-
const a = coin.generateAddress(p);
101+
const a = generateAddress(coin.network, coin.getChain(), p);
102102
coin.isValidAddress(a.address).should.eql(true);
103103
if (a.address !== a.address.toUpperCase()) {
104104
coin.isValidAddress(a.address.toUpperCase()).should.eql(false);
@@ -110,7 +110,7 @@ function run(coin: AbstractUtxoCoin) {
110110
it('defaults to canonical address', function () {
111111
getParameters().forEach((p) => {
112112
if (!p.chain || coin.supportsAddressChain(p.chain)) {
113-
const address = coin.generateAddress(p).address;
113+
const address = generateAddress(coin.network, coin.getChain(), p).address;
114114
coin.canonicalAddress(address).should.eql(address);
115115
}
116116
});
@@ -122,8 +122,8 @@ function run(coin: AbstractUtxoCoin) {
122122
if (p.chain && (!coin.supportsAddressChain(p.chain) || !otherCoin.supportsAddressChain(p.chain))) {
123123
return;
124124
}
125-
const address = coin.generateAddress(p);
126-
const otherAddress = otherCoin.generateAddress(p);
125+
const address = generateAddress(coin.network, coin.getChain(), p);
126+
const otherAddress = generateAddress(otherCoin.network, otherCoin.getChain(), p);
127127
(address.address === otherAddress.address).should.eql(isCompatibleAddress(coin, otherCoin));
128128
coin.isValidAddress(otherAddress.address).should.eql(isCompatibleAddress(coin, otherCoin));
129129
});

modules/abstract-utxo/test/unit/recovery/crossChainRecovery.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
CrossChainRecoveryUnsigned,
1414
getWallet,
1515
supportedCrossChainRecoveries,
16+
generateAddress,
1617
} from '../../../src';
1718
import {
1819
getFixture,
@@ -100,10 +101,13 @@ function run<TNumber extends number | bigint = number>(sourceCoin: AbstractUtxoC
100101
const recoveryWalletId = '5abacebe28d72fbd07e0b8cbba0ff39e';
101102
// the address the accidental deposit went to, in both sourceCoin and addressCoin formats
102103
const [depositAddressSourceCoin, depositAddressRecoveryCoin] = [sourceCoin, recoveryCoin].map((coin) =>
103-
coin.generateAddress({ keychains: keychainsBase58, index: 0 })
104+
generateAddress(coin.network, coin.getChain(), { keychains: keychainsBase58, index: 0 })
104105
);
105106
// the address where we want to recover our funds to
106-
const recoveryAddress = sourceCoin.generateAddress({ keychains: keychainsBase58, index: 1 }).address;
107+
const recoveryAddress = generateAddress(sourceCoin.network, sourceCoin.getChain(), {
108+
keychains: keychainsBase58,
109+
index: 1,
110+
}).address;
107111
const nocks: nock.Scope[] = [];
108112

109113
let depositTx: utxolib.bitgo.UtxoTransaction<TNumber>;

modules/abstract-utxo/test/unit/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
WalletSignTransactionOptions,
1414
} from '@bitgo/sdk-core';
1515

16-
import { AbstractUtxoCoin, getReplayProtectionAddresses } from '../../src';
16+
import { AbstractUtxoCoin, getReplayProtectionAddresses, generateAddress } from '../../src';
1717

1818
import {
1919
utxoCoins,
@@ -311,7 +311,7 @@ function run<TNumber extends number | bigint = number>(
311311
}
312312

313313
function getOutputAddress(rootWalletKeys: utxolib.bitgo.RootWalletKeys): string {
314-
return coin.generateAddress({
314+
return generateAddress(coin.network, coin.getChain(), {
315315
keychains: rootWalletKeys.triple.map((k) => ({ pub: k.neutered().toBase58() })),
316316
}).address;
317317
}

0 commit comments

Comments
 (0)