Skip to content

Commit

Permalink
Merge pull request #3984 from BitGo/BTC-396-add-distributed-custody-w…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkaplanbitgo authored Oct 14, 2023
2 parents 5dcd46e + e53c9a4 commit 51e3451
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions modules/sdk-core/src/bitgo/wallet/iWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ export interface CrossChainUTXO {
}

export type WalletType = 'backing' | 'cold' | 'custodial' | 'custodialPaired' | 'hot' | 'trading';
export type SubWalletType = 'distributedCustody';

export interface WalletData {
id: string;
Expand Down Expand Up @@ -559,6 +560,7 @@ export interface WalletData {
};
multisigType: 'onchain' | 'tss';
type?: WalletType;
subType?: SubWalletType;
tokens?: Record<string, any>[];
}

Expand Down
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/wallet/iWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface GenerateWalletOptions {
coldDerivationSeed?: string;
rootPrivateKey?: string;
multisigType?: 'onchain' | 'tss' | 'blsdkg';
isDistributedCustody?: boolean;
}

export interface GetWalletByAddressOptions {
Expand Down
20 changes: 19 additions & 1 deletion modules/sdk-core/src/bitgo/wallet/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ export class Wallets implements IWallets {
* @param params.disableKRSEmail
* @param params.walletVersion
* @param params.multisigType optional multisig type, 'onchain' or 'tss' or 'blsdkg'; if absent, we will defer to the coin's default type
* @param params.isDistributedCustody optional parameter for creating bitgo key. This is only necessary if you want to create
* a distributed custody wallet. If provided, you must have the enterprise license and pass in
* `params.enterprise` into `generateWallet` as well.
* @returns {*}
*/
async generateWallet(params: GenerateWalletOptions = {}): Promise<WalletWithKeychains> {
Expand Down Expand Up @@ -254,6 +257,19 @@ export class Wallets implements IWallets {
return this.generateMpcWallet({ multisigType: 'blsdkg', label, passphrase });
}

// Handle distributed custody
if (params.isDistributedCustody) {
if (!params.enterprise) {
throw new Error('must provide enterprise when creating distributed custody wallet');
}
if (params.multisigType !== 'onchain') {
throw new Error('distributed custody wallets must be onchain');
}
if (!walletParams.isCold) {
throw new Error('distributed custody wallets must be cold');
}
}

const hasBackupXpub = !!params.backupXpub;
const hasBackupXpubProvider = !!params.backupXpubProvider;
if (hasBackupXpub && hasBackupXpubProvider) {
Expand Down Expand Up @@ -392,7 +408,9 @@ export class Wallets implements IWallets {
const { userKeychain, backupKeychain, bitgoKeychain }: KeychainsTriplet = await promiseProps({
userKeychain: userKeychainPromise(),
backupKeychain: backupKeychainPromise(),
bitgoKeychain: this.baseCoin.keychains().createBitGo({ enterprise: params.enterprise, reqId }),
bitgoKeychain: this.baseCoin
.keychains()
.createBitGo({ enterprise: params.enterprise, reqId, isDistributedCustody: params.isDistributedCustody }),
});

walletParams.keys = [userKeychain.id, backupKeychain.id, bitgoKeychain.id];
Expand Down

0 comments on commit 51e3451

Please sign in to comment.