Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion modules/sdk-core/src/bitgo/baseCoin/iBaseCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ export interface SupplementGenerateWalletOptions {
type: 'hot' | 'cold' | 'custodial';
subType?: 'lightningCustody' | 'lightningSelfCustody' | 'onPrem';
coinSpecific?: { [coinName: string]: unknown };
referenceWalletId?: string;
}

export interface FeeEstimateOptions {
Expand Down
2 changes: 0 additions & 2 deletions modules/sdk-core/src/bitgo/wallet/iWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,6 @@ export interface CreateAddressOptions {
derivedAddress?: string;
index?: number;
onToken?: string;
referenceCoin?: string;
referenceAddress?: string;
}

export interface UpdateAddressOptions {
Expand Down
2 changes: 0 additions & 2 deletions modules/sdk-core/src/bitgo/wallet/iWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export interface GenerateWalletOptions {
commonKeychain?: string;
type?: 'hot' | 'cold' | 'custodial';
subType?: 'lightningCustody' | 'lightningSelfCustody';
referenceWalletId?: string;
}

export const GenerateLightningWalletOptionsCodec = t.strict(
Expand Down Expand Up @@ -171,7 +170,6 @@ export interface AddWalletOptions {
initializationTxs?: any;
disableTransactionNotifications?: boolean;
gasPrice?: number;
referenceWalletId?: string;
}

type KeySignatures = {
Expand Down
26 changes: 0 additions & 26 deletions modules/sdk-core/src/bitgo/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,8 +1251,6 @@ export class Wallet implements IWallet {
baseAddress,
allowSkipVerifyAddress = true,
onToken,
referenceCoin,
referenceAddress,
} = params;

if (!_.isUndefined(chain)) {
Expand Down Expand Up @@ -1327,30 +1325,6 @@ export class Wallet implements IWallet {
}
}

// Validate EVM keyring params, referenceAddress is required and referenceCoin is optional for EVM keyring
if (!_.isUndefined(referenceAddress)) {
if (!_.isString(referenceAddress)) {
throw new Error('referenceAddress has to be a string');
}
if (!this.baseCoin.isEVM()) {
throw new Error('referenceAddress is only supported for EVM chains');
}
if (!this.baseCoin.isValidAddress(referenceAddress)) {
throw new Error('referenceAddress must be a valid address');
}
addressParams.referenceAddress = referenceAddress;

if (!_.isUndefined(referenceCoin)) {
if (!_.isString(referenceCoin)) {
throw new Error('referenceCoin has to be a string');
}
addressParams.referenceCoin = referenceCoin;
}
} else if (!_.isUndefined(referenceCoin)) {
// referenceCoin cannot be used without referenceAddress
throw new Error('referenceAddress is required when using referenceCoin for EVM keyring');
}

// get keychains for address verification
const keychains = await Promise.all(this._wallet.keys.map((k) => this.baseCoin.keychains().get({ id: k, reqId })));
const rootAddress = _.get(this._wallet, 'receiveAddress.address');
Expand Down
69 changes: 3 additions & 66 deletions modules/sdk-core/src/bitgo/wallet/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,8 @@ export class Wallets implements IWallets {
throw new Error('missing required string parameter label');
}

// Validate referenceWalletId parameter
if (params.referenceWalletId) {
if (!_.isString(params.referenceWalletId)) {
throw new Error('invalid referenceWalletId argument, expecting string');
}
if (!this.baseCoin.isEVM()) {
throw new Error('referenceWalletId is only supported for EVM chains');
}
}

// For wallets with referenceWalletId, skip multisig validation as configuration is inherited
if (params.referenceWalletId) {
// Skip all multisig validation - configuration will be inherited from reference wallet
} else if (params.type !== 'custodial') {
// Standard validation for non-custodial wallets without referenceWalletId
// no need to pass keys for (single) custodial wallets
if (params.type !== 'custodial') {
if (Array.isArray(params.keys) === false || !_.isNumber(params.m) || !_.isNumber(params.n)) {
throw new Error('invalid argument');
}
Expand Down Expand Up @@ -285,10 +272,9 @@ export class Wallets implements IWallets {
throw new Error('missing required string parameter label');
}

const { type = 'hot', label, passphrase, enterprise, isDistributedCustody, referenceWalletId } = params;
const { type = 'hot', label, passphrase, enterprise, isDistributedCustody } = params;
const isTss = params.multisigType === 'tss' && this.baseCoin.supportsTss();
const canEncrypt = !!passphrase && typeof passphrase === 'string';
const isEVMWithReference = this.baseCoin.isEVM() && referenceWalletId;

const walletParams: SupplementGenerateWalletOptions = {
label: label,
Expand All @@ -298,11 +284,6 @@ export class Wallets implements IWallets {
type: !!params.userKey && params.multisigType !== 'onchain' ? 'cold' : type,
};

// Add referenceWalletId to walletParams if provided for EVM chains
if (isEVMWithReference) {
walletParams.referenceWalletId = referenceWalletId;
}

if (!_.isUndefined(params.passcodeEncryptionCode)) {
if (!_.isString(params.passcodeEncryptionCode)) {
throw new Error('passcodeEncryptionCode must be a string');
Expand All @@ -316,59 +297,15 @@ export class Wallets implements IWallets {
walletParams.enterprise = enterprise;
}

// Validate referenceWalletId for EVM keyring
if (!_.isUndefined(referenceWalletId)) {
if (!_.isString(referenceWalletId)) {
throw new Error('invalid referenceWalletId argument, expecting string');
}
if (!this.baseCoin.isEVM()) {
throw new Error('referenceWalletId is only supported for EVM chains');
}
}

// EVM TSS wallets must use wallet version 3, 5 and 6
// Skip this validation for EVM keyring wallets as they inherit version from reference wallet
if (
isTss &&
this.baseCoin.isEVM() &&
!referenceWalletId &&
!(params.walletVersion === 3 || params.walletVersion === 5 || params.walletVersion === 6)
) {
throw new Error('EVM TSS wallets are only supported for wallet version 3, 5 and 6');
}

// Handle EVM keyring wallet creation with referenceWalletId
if (isEVMWithReference) {
// For EVM keyring wallets, multisigType will be inferred from the reference wallet
// No need to explicitly validate TSS requirement here as it will be handled by bgms

// For EVM keyring wallets, we use the add method directly with referenceWalletId
// This bypasses the normal key generation process since keys are shared via keyring
const addWalletParams = {
label,
referenceWalletId,
};

const newWallet = await this.bitgo.post(this.baseCoin.url('/wallet/add')).send(addWalletParams).result();

// For EVM keyring wallets, we need to get the keychains from the reference wallet
const userKeychain = this.baseCoin.keychains().get({ id: newWallet.keys[KeyIndices.USER] });
const backupKeychain = this.baseCoin.keychains().get({ id: newWallet.keys[KeyIndices.BACKUP] });
const bitgoKeychain = this.baseCoin.keychains().get({ id: newWallet.keys[KeyIndices.BITGO] });

const [userKey, backupKey, bitgoKey] = await Promise.all([userKeychain, backupKeychain, bitgoKeychain]);

const result: WalletWithKeychains = {
wallet: new Wallet(this.bitgo, this.baseCoin, newWallet),
userKeychain: userKey,
backupKeychain: backupKey,
bitgoKeychain: bitgoKey,
responseType: 'WalletWithKeychains',
};

return result;
}

if (isTss) {
if (!this.baseCoin.supportsTss()) {
throw new Error(`coin ${this.baseCoin.getFamily()} does not support TSS at this time`);
Expand Down
Loading