Skip to content

Commit a722209

Browse files
authored
Merge pull request #5695 from BitGo/WP-3785-multisigtype-is-require
fix(sdk-core): multisig type should not be a required type
2 parents c5f1072 + e2727df commit a722209

File tree

42 files changed

+530
-15
lines changed

Some content is hidden

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

42 files changed

+530
-15
lines changed

modules/abstract-cosmos/src/cosmosCoin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
InvalidMemoIdError,
1010
KeyPair,
1111
MPCAlgorithm,
12+
MultisigType,
13+
multisigTypes,
1214
ParsedTransaction,
1315
ParseTransactionOptions,
1416
SignedTransaction,
@@ -105,6 +107,11 @@ export class CosmosCoin extends BaseCoin {
105107
return true;
106108
}
107109

110+
/** inherited doc */
111+
getDefaultMultisigType(): MultisigType {
112+
return multisigTypes.tss;
113+
}
114+
108115
/** @inheritDoc **/
109116
getMPCAlgorithm(): MPCAlgorithm {
110117
return 'ecdsa';

modules/abstract-substrate/src/abstractSubstrateCoin.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
MPCTx,
1414
MPCTxs,
1515
MPCUnsignedTx,
16+
MultisigType,
17+
multisigTypes,
1618
ParsedTransaction,
1719
ParseTransactionOptions,
1820
RecoveryTxRequest,
@@ -78,6 +80,11 @@ export class SubstrateCoin extends BaseCoin {
7880
return true;
7981
}
8082

83+
/** inherited doc */
84+
getDefaultMultisigType(): MultisigType {
85+
return multisigTypes.tss;
86+
}
87+
8188
/** @inheritDoc **/
8289
getMPCAlgorithm(): MPCAlgorithm {
8390
return 'eddsa';

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
IWallet,
2222
KeychainsTriplet,
2323
KeyIndices,
24+
MultisigType,
25+
multisigTypes,
2426
P2shP2wshUnsupportedError,
2527
P2trMusig2UnsupportedError,
2628
P2trUnsupportedError,
@@ -693,6 +695,16 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
693695
return utxolib.bitgo.outputScripts.isSupportedScriptType(this.network, addressType);
694696
}
695697

698+
/** {@inheritDoc } **/
699+
supportsMultisig(): boolean {
700+
return true;
701+
}
702+
703+
/** inherited doc */
704+
getDefaultMultisigType(): MultisigType {
705+
return multisigTypes.onchain;
706+
}
707+
696708
/**
697709
* @param chain
698710
* @return true iff coin supports spending from chain

modules/bitgo/test/v2/unit/wallets.ts

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
BulkWalletShareOptions,
2626
KeychainWithEncryptedPrv,
2727
WalletWithKeychains,
28+
multisigTypes,
2829
} from '@bitgo/sdk-core';
2930
import { BitGo } from '../../../src';
3031
import { afterEach } from 'mocha';
@@ -184,6 +185,7 @@ describe('V2 Wallets:', function () {
184185
});
185186

186187
describe('Generate wallet:', function () {
188+
const sandbox = sinon.createSandbox();
187189
it('should validate parameters', async function () {
188190
let params = {};
189191
await wallets.generateWallet(params).should.be.rejectedWith('Missing parameter: label');
@@ -475,6 +477,42 @@ describe('V2 Wallets:', function () {
475477
params.passphrase
476478
);
477479
});
480+
481+
it('should generate hot onchain wallet without passing multisig type', async () => {
482+
const params: GenerateWalletOptions = {
483+
label: 'test wallet',
484+
passphrase: 'multisig password',
485+
enterprise: 'enterprise',
486+
passcodeEncryptionCode: 'originalPasscodeEncryptionCode',
487+
};
488+
489+
const walletNock = nock(bgUrl)
490+
.post('/api/v2/tbtc/wallet/add', function (body) {
491+
body.type.should.equal('hot');
492+
return true;
493+
})
494+
.reply(200);
495+
496+
nock(bgUrl)
497+
.post('/api/v2/tbtc/key', _.matches({ source: 'bitgo' }))
498+
.reply(200, { pub: 'bitgoPub' });
499+
nock(bgUrl).post('/api/v2/tbtc/key', _.matches({})).reply(200);
500+
nock(bgUrl)
501+
.post('/api/v2/tbtc/key', _.matches({ source: 'backup' }))
502+
.reply(200, { pub: 'backupPub' });
503+
504+
const generateWalletSpy = sandbox.spy(wallets, 'generateWallet');
505+
const response = await wallets.generateWallet(params);
506+
walletNock.isDone().should.be.true();
507+
sinon.assert.calledOnce(generateWalletSpy);
508+
assert.equal(generateWalletSpy.firstCall?.args[0]?.multisigType, multisigTypes.onchain);
509+
assert.ok(response.encryptedWalletPassphrase);
510+
assert.ok(response.wallet);
511+
assert.equal(
512+
bitgo.decrypt({ input: response.encryptedWalletPassphrase, password: params.passcodeEncryptionCode }),
513+
params.passphrase
514+
);
515+
});
478516
});
479517

480518
describe('Generate TSS wallet:', function () {
@@ -552,6 +590,58 @@ describe('V2 Wallets:', function () {
552590
);
553591
});
554592

593+
it('should create a new TSS wallet without passing multisig type', async function () {
594+
const stubbedKeychainsTriplet: KeychainsTriplet = {
595+
userKeychain: {
596+
id: '1',
597+
pub: 'userPub',
598+
type: 'independent',
599+
source: 'user',
600+
},
601+
backupKeychain: {
602+
id: '2',
603+
pub: 'userPub',
604+
type: 'independent',
605+
source: 'backup',
606+
},
607+
bitgoKeychain: {
608+
id: '3',
609+
pub: 'userPub',
610+
type: 'independent',
611+
source: 'bitgo',
612+
},
613+
};
614+
sandbox.stub(TssUtils.prototype, 'createKeychains').resolves(stubbedKeychainsTriplet);
615+
616+
const walletNock = nock('https://bitgo.fakeurl')
617+
.post('/api/v2/tsol/wallet/add', function (body) {
618+
body.multisigType.should.equal(multisigTypes.tss);
619+
return true;
620+
})
621+
.reply(200);
622+
623+
const wallets = new Wallets(bitgo, tsol);
624+
625+
const params = {
626+
label: 'tss wallet',
627+
passphrase: 'tss password',
628+
enterprise: 'enterprise',
629+
passcodeEncryptionCode: 'originalPasscodeEncryptionCode',
630+
};
631+
632+
const generateWalletSpy = sandbox.spy(wallets, 'generateWallet');
633+
const response = await wallets.generateWallet(params);
634+
walletNock.isDone().should.be.true();
635+
sinon.assert.calledOnce(generateWalletSpy);
636+
assert.equal(generateWalletSpy.firstCall?.args[0]?.multisigType, multisigTypes.tss);
637+
assert.ok(response.encryptedWalletPassphrase);
638+
assert.ok(response.wallet);
639+
assert.equal(
640+
bitgo.decrypt({ input: response.encryptedWalletPassphrase, password: params.passcodeEncryptionCode }),
641+
params.passphrase
642+
);
643+
});
644+
555645
it('should create a new TSS wallet without providing passcodeEncryptionCode', async function () {
556646
const stubbedKeychainsTriplet: KeychainsTriplet = {
557647
userKeychain: {
@@ -961,6 +1051,62 @@ describe('V2 Wallets:', function () {
9611051
);
9621052
});
9631053

1054+
it(`should create a new ${coin} TSS MPCv2 hot wallet without passing multisig type`, async function () {
1055+
const testCoin = bitgo.coin(coin);
1056+
const stubbedKeychainsTriplet: KeychainsTriplet = {
1057+
userKeychain: {
1058+
id: '1',
1059+
commonKeychain: 'userPub',
1060+
type: 'tss',
1061+
source: 'user',
1062+
},
1063+
backupKeychain: {
1064+
id: '2',
1065+
commonKeychain: 'userPub',
1066+
type: 'tss',
1067+
source: 'backup',
1068+
},
1069+
bitgoKeychain: {
1070+
id: '3',
1071+
commonKeychain: 'userPub',
1072+
type: 'tss',
1073+
source: 'bitgo',
1074+
},
1075+
};
1076+
const stubCreateKeychains = sandbox
1077+
.stub(ECDSAUtils.EcdsaMPCv2Utils.prototype, 'createKeychains')
1078+
.resolves(stubbedKeychainsTriplet);
1079+
1080+
const walletNock = nock('https://bitgo.fakeurl')
1081+
.post(`/api/v2/${coin}/wallet/add`, function (body) {
1082+
body.multisigType.should.equal(multisigTypes.tss);
1083+
return true;
1084+
})
1085+
.reply(200);
1086+
1087+
const wallets = new Wallets(bitgo, testCoin);
1088+
1089+
const params = {
1090+
label: 'tss wallet',
1091+
passphrase: 'tss password',
1092+
enterprise: 'enterprise',
1093+
passcodeEncryptionCode: 'originalPasscodeEncryptionCode',
1094+
walletVersion: 3,
1095+
};
1096+
1097+
const response = await wallets.generateWallet(params);
1098+
1099+
walletNock.isDone().should.be.true();
1100+
stubCreateKeychains.calledOnce.should.be.true();
1101+
1102+
assert.ok(response.encryptedWalletPassphrase);
1103+
assert.ok(response.wallet);
1104+
assert.equal(
1105+
bitgo.decrypt({ input: response.encryptedWalletPassphrase, password: params.passcodeEncryptionCode }),
1106+
params.passphrase
1107+
);
1108+
});
1109+
9641110
it(`should create a new ${coin} TSS MPCv2 cold wallet`, async function () {
9651111
const testCoin = bitgo.coin(coin);
9661112
const bitgoKeyId = 'key123';

modules/sdk-coin-ada/src/ada.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import {
2929
MPCTxs,
3030
PopulatedIntent,
3131
PrebuildTransactionWithIntentOptions,
32+
MultisigType,
33+
multisigTypes,
3234
} from '@bitgo/sdk-core';
3335
import { KeyPair as AdaKeyPair, Transaction, TransactionBuilderFactory, Utils } from './lib';
3436
import { BaseCoin as StaticsBaseCoin, CoinFamily, coins } from '@bitgo/statics';
@@ -602,6 +604,11 @@ export class Ada extends BaseCoin {
602604
return true;
603605
}
604606

607+
/** inherited doc */
608+
getDefaultMultisigType(): MultisigType {
609+
return multisigTypes.tss;
610+
}
611+
605612
/** inherited doc */
606613
getMPCAlgorithm(): MPCAlgorithm {
607614
return 'eddsa';

modules/sdk-coin-algo/src/algo.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import {
2727
VerifyAddressOptions,
2828
VerifyTransactionOptions,
2929
NotSupported,
30+
MultisigType,
31+
multisigTypes,
3032
} from '@bitgo/sdk-core';
3133
import stellar from 'stellar-sdk';
3234
import BigNumber from 'bignumber.js';
@@ -592,6 +594,16 @@ export class Algo extends BaseCoin {
592594
return false;
593595
}
594596

597+
/** {@inheritDoc } **/
598+
supportsMultisig(): boolean {
599+
return true;
600+
}
601+
602+
/** inherited doc */
603+
getDefaultMultisigType(): MultisigType {
604+
return multisigTypes.onchain;
605+
}
606+
595607
/**
596608
* Gets config for how token enablements work for this coin
597609
* @returns

modules/sdk-coin-apt/src/apt.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
InvalidAddressError,
66
KeyPair,
77
MPCAlgorithm,
8+
MultisigType,
9+
multisigTypes,
810
ParsedTransaction,
911
ParseTransactionOptions,
1012
SignedTransaction,
@@ -64,6 +66,11 @@ export class Apt extends BaseCoin {
6466
return true;
6567
}
6668

69+
/** inherited doc */
70+
getDefaultMultisigType(): MultisigType {
71+
return multisigTypes.tss;
72+
}
73+
6774
getMPCAlgorithm(): MPCAlgorithm {
6875
return 'eddsa';
6976
}

modules/sdk-coin-arbeth/src/arbeth.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @prettier
33
*/
4-
import { BaseCoin, BitGoBase, common } from '@bitgo/sdk-core';
4+
import { BaseCoin, BitGoBase, common, MultisigType, multisigTypes } from '@bitgo/sdk-core';
55
import { BaseCoin as StaticsBaseCoin, coins, ethGasConfigs } from '@bitgo/statics';
66
import {
77
AbstractEthLikeNewCoins,
@@ -51,4 +51,14 @@ export class Arbeth extends AbstractEthLikeNewCoins {
5151
}
5252
return userGasLimit;
5353
}
54+
55+
/** {@inheritDoc } **/
56+
supportsMultisig(): boolean {
57+
return true;
58+
}
59+
60+
/** inherited doc */
61+
getDefaultMultisigType(): MultisigType {
62+
return multisigTypes.onchain;
63+
}
5464
}

modules/sdk-coin-avaxc/src/avaxc.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import {
2525
InvalidAddressError,
2626
IWallet,
2727
KeyPair,
28+
MultisigType,
29+
multisigTypes,
2830
ParsedTransaction,
2931
ParseTransactionOptions,
3032
Recipient,
@@ -133,6 +135,16 @@ export class AvaxC extends AbstractEthLikeNewCoins {
133135
return false;
134136
}
135137

138+
/** {@inheritDoc } **/
139+
supportsMultisig(): boolean {
140+
return true;
141+
}
142+
143+
/** inherited doc */
144+
getDefaultMultisigType(): MultisigType {
145+
return multisigTypes.onchain;
146+
}
147+
136148
generateKeyPair(seed?: Buffer): KeyPair {
137149
const avaxKeyPair = seed ? new AvaxcKeyPair({ seed }) : new AvaxcKeyPair();
138150
const extendedKeys = avaxKeyPair.getExtendedKeys();

modules/sdk-coin-avaxp/src/avaxp.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
UnexpectedAddressError,
1515
ITransactionRecipient,
1616
ParsedTransaction,
17+
MultisigType,
18+
multisigTypes,
1719
} from '@bitgo/sdk-core';
1820
import * as AvaxpLib from './lib';
1921
import {
@@ -58,6 +60,16 @@ export class AvaxP extends BaseCoin {
5860
return Math.pow(10, this._staticsCoin.decimalPlaces);
5961
}
6062

63+
/** {@inheritDoc } **/
64+
supportsMultisig(): boolean {
65+
return true;
66+
}
67+
68+
/** inherited doc */
69+
getDefaultMultisigType(): MultisigType {
70+
return multisigTypes.onchain;
71+
}
72+
6173
/**
6274
* Check if staking txn is valid, based on expected tx params.
6375
*

0 commit comments

Comments
 (0)