Skip to content

Conversation

@nvjsr
Copy link
Contributor

@nvjsr nvjsr commented Sep 3, 2025

TICKET: COIN-5193

@nvjsr nvjsr force-pushed the COIN-5193-EVMkeyring branch 4 times, most recently from a15e458 to e9ef8af Compare September 3, 2025 13:50
@nvjsr nvjsr changed the title feat(EVM keyring): EVM wallet and address creation changes feat(sdk-core): EVM wallet and address creation changes Sep 3, 2025
@nvjsr nvjsr force-pushed the COIN-5193-EVMkeyring branch from e9ef8af to fa9cf7a Compare September 3, 2025 14:14
@nvjsr nvjsr marked this pull request as ready for review September 3, 2025 14:36
@nvjsr nvjsr requested review from a team as code owners September 3, 2025 14:36
@nvjsr nvjsr force-pushed the COIN-5193-EVMkeyring branch from fa9cf7a to 94ad1b1 Compare September 3, 2025 17:13
@nvjsr nvjsr force-pushed the COIN-5193-EVMkeyring branch from 94ad1b1 to 645eb31 Compare September 3, 2025 17:18
@nvjsr nvjsr changed the title feat(sdk-core): EVM wallet and address creation changes feat(sdk-core): EVM keyring wallet and address creation changes Sep 3, 2025
@nvjsr nvjsr merged commit bc6de97 into master Sep 3, 2025
11 checks passed
Comment on lines +1349 to +1353
} else if (!_.isUndefined(referenceCoin)) {
// referenceCoin cannot be used without referenceAddress
throw new Error('referenceAddress is required when using referenceCoin for EVM keyring');
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you instead do a if(_.isUndefined(referenceCoin) && !_.isUndefined(referenceAddress)) { throw error }
That's more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding changes in followup PR for same

}
}

// Validate EVM keyring params, referenceAddress is required and referenceCoin is optional for EVM keyring
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if referenceCoin by itself isn't valid, it should't be an independent option. Let's instead have referenceAddressEvmKeyRing and have the address and coin as nested fields.

Comment on lines +104 to +118
// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shoudn't be having a referenceId as a top level param that is EVM based only. Can we atleast name it evmKeyRingReferenceWalletId? Coin-specific logic shoudn't be leaking in generic add wallet methods, can we create a coin-specific util in eth-lib that can take care of this validation?

Copy link
Contributor

@pranavjain97 pranavjain97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we updated the express dev docs anywhere for the new fields added for wallet/address creation?

Comment on lines +341 to +370
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be an EVM lib util i.e something like createEvmKeyRingWallet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants