-
Notifications
You must be signed in to change notification settings - Fork 300
feat(sdk-core): EVM keyring wallet and address creation changes #6872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a15e458 to
e9ef8af
Compare
e9ef8af to
fa9cf7a
Compare
fa9cf7a to
94ad1b1
Compare
94ad1b1 to
645eb31
Compare
| } else if (!_.isUndefined(referenceCoin)) { | ||
| // referenceCoin cannot be used without referenceAddress | ||
| throw new Error('referenceAddress is required when using referenceCoin for EVM keyring'); | ||
| } | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
| // 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this 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?
| 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; | ||
| } |
There was a problem hiding this comment.
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.
TICKET: COIN-5193