Skip to content

Commit e101c7b

Browse files
Merge pull request #7896 from BitGo/rel/latest-merge-conflict-3
2 parents 49bd3d6 + 79cda4e commit e101c7b

File tree

357 files changed

+4859
-3301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

357 files changed

+4859
-3301
lines changed

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ COPY --from=builder /tmp/bitgo/modules/sdk-opensslbytes /var/modules/sdk-openssl
4545
COPY --from=builder /tmp/bitgo/modules/secp256k1 /var/modules/secp256k1/
4646
COPY --from=builder /tmp/bitgo/modules/sjcl /var/modules/sjcl/
4747
COPY --from=builder /tmp/bitgo/modules/statics /var/modules/statics/
48-
COPY --from=builder /tmp/bitgo/modules/utxo-core /var/modules/utxo-core/
49-
COPY --from=builder /tmp/bitgo/modules/unspents /var/modules/unspents/
5048
COPY --from=builder /tmp/bitgo/modules/utxo-lib /var/modules/utxo-lib/
5149
COPY --from=builder /tmp/bitgo/modules/blake2b /var/modules/blake2b/
5250
COPY --from=builder /tmp/bitgo/modules/blake2b-wasm /var/modules/blake2b-wasm/
@@ -55,6 +53,8 @@ COPY --from=builder /tmp/bitgo/modules/abstract-utxo /var/modules/abstract-utxo/
5553
COPY --from=builder /tmp/bitgo/modules/blockapis /var/modules/blockapis/
5654
COPY --from=builder /tmp/bitgo/modules/sdk-api /var/modules/sdk-api/
5755
COPY --from=builder /tmp/bitgo/modules/sdk-hmac /var/modules/sdk-hmac/
56+
COPY --from=builder /tmp/bitgo/modules/unspents /var/modules/unspents/
57+
COPY --from=builder /tmp/bitgo/modules/utxo-core /var/modules/utxo-core/
5858
COPY --from=builder /tmp/bitgo/modules/utxo-ord /var/modules/utxo-ord/
5959
COPY --from=builder /tmp/bitgo/modules/account-lib /var/modules/account-lib/
6060
COPY --from=builder /tmp/bitgo/modules/sdk-coin-ada /var/modules/sdk-coin-ada/
@@ -143,8 +143,6 @@ cd /var/modules/sdk-opensslbytes && yarn link && \
143143
cd /var/modules/secp256k1 && yarn link && \
144144
cd /var/modules/sjcl && yarn link && \
145145
cd /var/modules/statics && yarn link && \
146-
cd /var/modules/utxo-core && yarn link && \
147-
cd /var/modules/unspents && yarn link && \
148146
cd /var/modules/utxo-lib && yarn link && \
149147
cd /var/modules/blake2b && yarn link && \
150148
cd /var/modules/blake2b-wasm && yarn link && \
@@ -153,6 +151,8 @@ cd /var/modules/abstract-utxo && yarn link && \
153151
cd /var/modules/blockapis && yarn link && \
154152
cd /var/modules/sdk-api && yarn link && \
155153
cd /var/modules/sdk-hmac && yarn link && \
154+
cd /var/modules/unspents && yarn link && \
155+
cd /var/modules/utxo-core && yarn link && \
156156
cd /var/modules/utxo-ord && yarn link && \
157157
cd /var/modules/account-lib && yarn link && \
158158
cd /var/modules/sdk-coin-ada && yarn link && \
@@ -244,8 +244,6 @@ RUN cd /var/bitgo-express && \
244244
yarn link @bitgo/secp256k1 && \
245245
yarn link @bitgo/sjcl && \
246246
yarn link @bitgo/statics && \
247-
yarn link @bitgo/utxo-core && \
248-
yarn link @bitgo/unspents && \
249247
yarn link @bitgo/utxo-lib && \
250248
yarn link @bitgo/blake2b && \
251249
yarn link @bitgo/blake2b-wasm && \
@@ -254,6 +252,8 @@ RUN cd /var/bitgo-express && \
254252
yarn link @bitgo/blockapis && \
255253
yarn link @bitgo/sdk-api && \
256254
yarn link @bitgo/sdk-hmac && \
255+
yarn link @bitgo/unspents && \
256+
yarn link @bitgo/utxo-core && \
257257
yarn link @bitgo/utxo-ord && \
258258
yarn link @bitgo/account-lib && \
259259
yarn link @bitgo/sdk-coin-ada && \

modules/abstract-lightning/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
]
4040
},
4141
"dependencies": {
42-
"@bitgo/public-types": "5.43.1",
42+
"@bitgo/public-types": "5.63.0",
4343
"@bitgo/sdk-core": "^36.26.0",
4444
"@bitgo/statics": "^58.20.0",
4545
"@bitgo/utxo-lib": "^11.19.0",

modules/abstract-utxo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"@bitgo/utxo-core": "^1.29.0",
6969
"@bitgo/utxo-lib": "^11.19.0",
7070
"@bitgo/utxo-ord": "^1.22.21",
71-
"@bitgo/wasm-utxo": "1.19.0",
71+
"@bitgo/wasm-utxo": "^1.22.0",
7272
"@types/lodash": "^4.14.121",
7373
"@types/superagent": "4.1.15",
7474
"bignumber.js": "^9.0.2",

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { randomBytes } from 'crypto';
44
import _ from 'lodash';
55
import * as utxolib from '@bitgo/utxo-lib';
66
import { bip32 } from '@bitgo/secp256k1';
7-
import { bitgo, getMainnet, isMainnet, isTestnet } from '@bitgo/utxo-lib';
7+
import { bitgo, getMainnet, isMainnet } from '@bitgo/utxo-lib';
88
import {
99
AddressCoinSpecific,
1010
BaseCoin,
@@ -76,7 +76,14 @@ import {
7676
ErrorImplicitExternalOutputs,
7777
} from './transaction/descriptor/verifyTransaction';
7878
import { assertDescriptorWalletAddress, getDescriptorMapFromWallet, isDescriptorWallet } from './descriptor';
79-
import { getChainFromNetwork, getFamilyFromNetwork, getFullNameFromNetwork } from './names';
79+
import {
80+
getFullNameFromCoinName,
81+
getMainnetCoinName,
82+
getNetworkFromCoinName,
83+
isTestnetCoin,
84+
UtxoCoinName,
85+
UtxoCoinNameMainnet,
86+
} from './names';
8087
import { assertFixedScriptWalletAddress } from './address/fixedScript';
8188
import { isSdkBackend, ParsedTransaction, SdkBackend } from './transaction/types';
8289
import { decodePsbtWith, encodeTransaction, stringToBufferTryFormats } from './transaction/decode';
@@ -369,42 +376,40 @@ export abstract class AbstractUtxoCoin
369376
extends BaseCoin
370377
implements Musig2Participant<utxolib.bitgo.UtxoPsbt>, Musig2Participant<fixedScriptWallet.BitGoPsbt>
371378
{
379+
abstract name: UtxoCoinName;
380+
372381
public altScriptHash?: number;
373382
public supportAltScriptDestination?: boolean;
374383
public defaultSdkBackend: SdkBackend = 'utxolib';
375384
public readonly amountType: 'number' | 'bigint';
376-
private readonly _network: utxolib.Network;
377385

378-
protected constructor(bitgo: BitGoBase, network: utxolib.Network, amountType: 'number' | 'bigint' = 'number') {
386+
protected constructor(bitgo: BitGoBase, amountType: 'number' | 'bigint' = 'number') {
379387
super(bitgo);
380-
if (!utxolib.isValidNetwork(network)) {
381-
throw new Error(
382-
'invalid network: please make sure to use the same version of ' +
383-
'@bitgo/utxo-lib as this library when initializing an instance of this class'
384-
);
385-
}
386388
this.amountType = amountType;
387-
this._network = network;
388389
}
389390

390-
get network() {
391-
return this._network;
391+
/**
392+
* @deprecated - will be removed when we drop support for utxolib
393+
* Use `name` property instead.
394+
*/
395+
get network(): utxolib.Network {
396+
return getNetworkFromCoinName(this.name);
392397
}
393398

394-
getChain() {
395-
return getChainFromNetwork(this.network);
399+
getChain(): UtxoCoinName {
400+
return this.name;
396401
}
397402

398-
getFamily() {
399-
return getFamilyFromNetwork(this.network);
403+
getFamily(): UtxoCoinNameMainnet {
404+
return getMainnetCoinName(this.name);
400405
}
401406

402-
getFullName() {
403-
return getFullNameFromNetwork(this.network);
407+
getFullName(): string {
408+
return getFullNameFromCoinName(this.name);
404409
}
405410

406411
/** Indicates whether the coin supports a block target */
407-
supportsBlockTarget() {
412+
supportsBlockTarget(): boolean {
408413
// FIXME: the SDK does not seem to use this anywhere so it is unclear what the purpose of this method is
409414
switch (getMainnet(this.network)) {
410415
case utxolib.networks.bitcoin:
@@ -428,7 +433,7 @@ export abstract class AbstractUtxoCoin
428433
* Returns the factor between the base unit and its smallest subdivison
429434
* @return {number}
430435
*/
431-
getBaseFactor() {
436+
getBaseFactor(): number {
432437
return 1e8;
433438
}
434439

@@ -466,7 +471,7 @@ export abstract class AbstractUtxoCoin
466471
* @param {String} pub the pub to be checked
467472
* @returns {Boolean} is it valid?
468473
*/
469-
isValidPub(pub: string) {
474+
isValidPub(pub: string): boolean {
470475
try {
471476
return bip32.fromBase58(pub).isNeutered();
472477
} catch (e) {
@@ -545,7 +550,7 @@ export abstract class AbstractUtxoCoin
545550
}
546551

547552
if (utxolib.bitgo.isPsbt(input)) {
548-
return decodePsbtWith(input, this.network, decodeWith);
553+
return decodePsbtWith(input, this.name, decodeWith);
549554
} else {
550555
if (decodeWith !== 'utxolib') {
551556
console.error('received decodeWith hint %s, ignoring for legacy transaction', decodeWith);
@@ -687,7 +692,7 @@ export abstract class AbstractUtxoCoin
687692
throw new Error('keychains must be a triple');
688693
}
689694
assertDescriptorWalletAddress(
690-
this.network,
695+
this.name,
691696
params,
692697
getDescriptorMapFromWallet(wallet, toBip32Triple(keychains), getPolicyForEnv(this.bitgo.env))
693698
);
@@ -704,7 +709,7 @@ export abstract class AbstractUtxoCoin
704709
throw new Error('missing required param keychains');
705710
}
706711

707-
assertFixedScriptWalletAddress(this.network, {
712+
assertFixedScriptWalletAddress(this.name, {
708713
address,
709714
keychains,
710715
format: params.format ?? 'base58',
@@ -762,9 +767,9 @@ export abstract class AbstractUtxoCoin
762767
.send({ psbt: buffer.toString('hex') })
763768
.result();
764769
if (psbt instanceof utxolib.bitgo.UtxoPsbt) {
765-
return decodePsbtWith(response.psbt, this.network, 'utxolib') as T;
770+
return decodePsbtWith(response.psbt, this.name, 'utxolib') as T;
766771
} else {
767-
return decodePsbtWith(response.psbt, this.network, 'wasm-utxo') as T;
772+
return decodePsbtWith(response.psbt, this.name, 'wasm-utxo') as T;
768773
}
769774
}
770775

@@ -861,7 +866,7 @@ export abstract class AbstractUtxoCoin
861866
* @returns {boolean}
862867
*/
863868
isBitGoTaintedUnspent<TNumber extends number | bigint>(unspent: Unspent<TNumber>): boolean {
864-
return isReplayProtectionUnspent<TNumber>(unspent, this.network);
869+
return isReplayProtectionUnspent(unspent, this.name);
865870
}
866871

867872
/**
@@ -872,7 +877,7 @@ export abstract class AbstractUtxoCoin
872877
override async explainTransaction<TNumber extends number | bigint = number>(
873878
params: ExplainTransactionOptions<TNumber>
874879
): Promise<TransactionExplanation> {
875-
return explainTx(this.decodeTransactionFromPrebuild(params), params, this.network);
880+
return explainTx(this.decodeTransactionFromPrebuild(params), params, this.name);
876881
}
877882

878883
/**
@@ -967,14 +972,14 @@ export abstract class AbstractUtxoCoin
967972
getDefaultTxFormat(wallet: Wallet, requestedFormat?: TxFormat): TxFormat | undefined {
968973
// If format is explicitly requested, use it
969974
if (requestedFormat !== undefined) {
970-
if (isTestnet(this.network) && requestedFormat === 'legacy') {
975+
if (isTestnetCoin(this.name) && requestedFormat === 'legacy') {
971976
throw new ErrorDeprecatedTxFormat(requestedFormat);
972977
}
973978

974979
return requestedFormat;
975980
}
976981

977-
if (isTestnet(this.network)) {
982+
if (isTestnetCoin(this.name)) {
978983
return 'psbt-lite';
979984
}
980985

@@ -1056,7 +1061,15 @@ export abstract class AbstractUtxoCoin
10561061
}
10571062

10581063
/** @inheritDoc */
1059-
auditDecryptedKey({ multiSigType, publicKey, prv }) {
1064+
auditDecryptedKey({
1065+
multiSigType,
1066+
publicKey,
1067+
prv,
1068+
}: {
1069+
multiSigType: MultisigType;
1070+
publicKey: string;
1071+
prv: string;
1072+
}): void {
10601073
if (multiSigType === 'tss') {
10611074
throw new Error('tss auditing is not supported for this coin');
10621075
}

modules/abstract-utxo/src/address/fixedScript.ts

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import {
1212
isTriple,
1313
Triple,
1414
} from '@bitgo/sdk-core';
15-
import * as utxolib from '@bitgo/utxo-lib';
1615
import { bitgo } from '@bitgo/utxo-lib';
17-
import { bip32 } from '@bitgo/secp256k1';
1816
import * as wasmUtxo from '@bitgo/wasm-utxo';
1917

18+
import { getNetworkFromCoinName, UtxoCoinName } from '../names';
19+
2020
type ScriptType2Of3 = bitgo.outputScripts.ScriptType2Of3;
2121

2222
export interface FixedScriptAddressCoinSpecific {
@@ -38,44 +38,23 @@ interface GenerateFixedScriptAddressOptions extends GenerateAddressOptions {
3838
keychains: { pub: string }[];
3939
}
4040

41-
function canonicalAddress(network: utxolib.Network, address: string, format?: CreateAddressFormat): string {
42-
if (format === 'cashaddr') {
43-
const script = utxolib.addressFormat.toOutputScriptTryFormats(address, network);
44-
return utxolib.addressFormat.fromOutputScriptWithFormat(script, format, network);
45-
}
46-
// Default to canonical format (base58 for most coins)
47-
return utxolib.addressFormat.toCanonicalFormat(address, network);
48-
}
49-
50-
function supportsAddressType(network: utxolib.Network, addressType: ScriptType2Of3): boolean {
51-
return utxolib.bitgo.outputScripts.isSupportedScriptType(network, addressType);
41+
function supportsAddressType(coinName: UtxoCoinName, addressType: ScriptType2Of3): boolean {
42+
const network = getNetworkFromCoinName(coinName);
43+
return bitgo.outputScripts.isSupportedScriptType(network, addressType);
5244
}
5345

5446
export function generateAddressWithChainAndIndex(
55-
network: utxolib.Network,
47+
coinName: UtxoCoinName,
5648
keychains: bitgo.RootWalletKeys | Triple<string>,
5749
chain: bitgo.ChainCode,
5850
index: number,
5951
format: CreateAddressFormat | undefined
6052
): string {
61-
if (utxolib.isTestnet(network)) {
62-
// Convert CreateAddressFormat to AddressFormat for wasm-utxo
63-
// 'base58' -> 'default', 'cashaddr' -> 'cashaddr'
64-
const wasmFormat = format === 'base58' ? 'default' : format;
65-
return wasmUtxo.fixedScriptWallet.address(keychains, chain, index, network, wasmFormat);
66-
}
67-
68-
if (!(keychains instanceof bitgo.RootWalletKeys)) {
69-
const hdNodes = keychains.map((pub) => bip32.fromBase58(pub));
70-
keychains = new bitgo.RootWalletKeys(hdNodes as Triple<utxolib.BIP32Interface>);
71-
}
72-
73-
const addressType = bitgo.scriptTypeForChain(chain);
74-
75-
const derivedKeys = keychains.deriveForChainAndIndex(chain, index).publicKeys;
76-
const { scriptPubKey: outputScript } = utxolib.bitgo.outputScripts.createOutputScript2of3(derivedKeys, addressType);
77-
const address = utxolib.address.fromOutputScript(outputScript, network);
78-
return canonicalAddress(network, address, format);
53+
// Convert CreateAddressFormat to AddressFormat for wasm-utxo
54+
// 'base58' -> 'default', 'cashaddr' -> 'cashaddr'
55+
const wasmFormat = format === 'base58' ? 'default' : format;
56+
const network = getNetworkFromCoinName(coinName);
57+
return wasmUtxo.fixedScriptWallet.address(keychains, chain, index, network, wasmFormat);
7958
}
8059

8160
/**
@@ -90,7 +69,7 @@ export function generateAddressWithChainAndIndex(
9069
* @param params.bech32 {boolean} Deprecated
9170
* @returns {string} The generated address
9271
*/
93-
export function generateAddress(network: utxolib.Network, params: GenerateFixedScriptAddressOptions): string {
72+
export function generateAddress(coinName: UtxoCoinName, params: GenerateFixedScriptAddressOptions): string {
9473
let derivationIndex = 0;
9574
if (_.isInteger(params.index) && (params.index as number) > 0) {
9675
derivationIndex = params.index as number;
@@ -118,11 +97,11 @@ export function generateAddress(network: utxolib.Network, params: GenerateFixedS
11897

11998
const addressType = params.addressType || convertFlagsToAddressType();
12099

121-
if (addressType !== utxolib.bitgo.scriptTypeForChain(derivationChain)) {
100+
if (addressType !== bitgo.scriptTypeForChain(derivationChain)) {
122101
throw new AddressTypeChainMismatchError(addressType, derivationChain);
123102
}
124103

125-
if (!supportsAddressType(network, addressType)) {
104+
if (!supportsAddressType(coinName, addressType)) {
126105
switch (addressType) {
127106
case 'p2sh':
128107
throw new Error(`internal error: p2sh should always be supported`);
@@ -144,7 +123,7 @@ export function generateAddress(network: utxolib.Network, params: GenerateFixedS
144123
}
145124

146125
return generateAddressWithChainAndIndex(
147-
network,
126+
coinName,
148127
keychains.map((k) => k.pub) as Triple<string>,
149128
derivationChain,
150129
derivationIndex,
@@ -157,7 +136,7 @@ type Keychain = {
157136
};
158137

159138
export function assertFixedScriptWalletAddress(
160-
network: utxolib.Network,
139+
coinName: UtxoCoinName,
161140
{
162141
chain,
163142
index,
@@ -184,7 +163,7 @@ export function assertFixedScriptWalletAddress(
184163
throw new Error('missing required param keychains');
185164
}
186165

187-
const expectedAddress = generateAddress(network, {
166+
const expectedAddress = generateAddress(coinName, {
188167
format,
189168
addressType: addressType as ScriptType2Of3,
190169
keychains,

0 commit comments

Comments
 (0)