Skip to content
Closed
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
5 changes: 4 additions & 1 deletion modules/sdk-core/src/bitgo/evm/evmUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface CreateEvmKeyRingWalletParams {
evmKeyRingReferenceWalletId: string;
bitgo: BitGoBase;
baseCoin: IBaseCoin;
/** Enterprise ID - required for cold/custodial wallets */
enterprise?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

why enterprise is needed for cold and custodial support ?

}

/**
Expand All @@ -39,11 +41,12 @@ export function validateEvmKeyRingWalletParams(params: any, baseCoin: IBaseCoin)
* @returns Promise<WalletWithKeychains> - The created wallet with its keychains
*/
export async function createEvmKeyRingWallet(params: CreateEvmKeyRingWalletParams): Promise<WalletWithKeychains> {
const { label, evmKeyRingReferenceWalletId, bitgo, baseCoin } = params;
const { label, evmKeyRingReferenceWalletId, bitgo, baseCoin, enterprise } = params;
// For EVM keyring wallets, this bypasses the normal key generation process since keys are shared via keyring
const addWalletParams = {
label,
evmKeyRingReferenceWalletId,
...(enterprise && { enterprise }),
};

const newWallet = await bitgo.post(baseCoin.url('/wallet/add')).send(addWalletParams).result();
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-core/src/bitgo/wallet/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export class Wallets implements IWallets {
evmKeyRingReferenceWalletId: evmKeyRingReferenceWalletId!,
bitgo: this.bitgo,
baseCoin: this.baseCoin,
enterprise,
});
}

Expand Down
158 changes: 158 additions & 0 deletions modules/sdk-core/test/unit/bitgo/wallet/walletsEvmKeyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,162 @@ describe('Wallets', function () {
}
});
});

describe('EVM Keyring - Cold/Custodial wallet support', function () {
beforeEach(function () {
mockBaseCoin.isEVM.returns(true);
mockBaseCoin.supportsTss.returns(true);
mockBaseCoin.getDefaultMultisigType.returns('tss');
});

it('should create cold EVM keyring wallet with enterprise (type inherited from reference)', async function () {
const mockWalletResponse = {
id: '597f1f77bcf86cd799439011',
keys: ['user-key', 'backup-key', 'bitgo-key'],
};

const sendStub = sinon.stub().returns({
result: sinon.stub().resolves(mockWalletResponse),
});

mockBitGo.post.returns({
send: sendStub,
} as any);

mockBaseCoin.keychains.returns({
get: sinon.stub().resolves({ id: 'keychain-id', pub: 'public-key' }),
} as any);

const result = await wallets.generateWallet({
label: 'Cold EVM Keyring Wallet',
evmKeyRingReferenceWalletId: '507f1f77bcf86cd799439011',
enterprise: 'test-enterprise-id',
});

result.should.have.property('wallet');

const sentParams = sendStub.firstCall.args[0];
sentParams.should.not.have.property('type');
sentParams.should.have.property('enterprise', 'test-enterprise-id');
sentParams.should.have.property('evmKeyRingReferenceWalletId', '507f1f77bcf86cd799439011');
});

it('should create custodial EVM keyring wallet with enterprise (type inherited from reference)', async function () {
const mockWalletResponse = {
id: '597f1f77bcf86cd799439012',
keys: ['user-key', 'backup-key', 'bitgo-key'],
};

const sendStub = sinon.stub().returns({
result: sinon.stub().resolves(mockWalletResponse),
});

mockBitGo.post.returns({
send: sendStub,
} as any);

mockBaseCoin.keychains.returns({
get: sinon.stub().resolves({ id: 'keychain-id', pub: 'public-key' }),
} as any);

const result = await wallets.generateWallet({
label: 'Custodial EVM Keyring Wallet',
evmKeyRingReferenceWalletId: '507f1f77bcf86cd799439011',
enterprise: 'test-enterprise-id',
});

result.should.have.property('wallet');

const sentParams = sendStub.firstCall.args[0];
sentParams.should.not.have.property('type');
sentParams.should.have.property('enterprise', 'test-enterprise-id');
sentParams.should.have.property('evmKeyRingReferenceWalletId', '507f1f77bcf86cd799439011');
});

it('should create EVM keyring wallet without type (inherits from reference wallet)', async function () {
const mockWalletResponse = {
id: '597f1f77bcf86cd799439013',
keys: ['user-key', 'backup-key', 'bitgo-key'],
};

const sendStub = sinon.stub().returns({
result: sinon.stub().resolves(mockWalletResponse),
});

mockBitGo.post.returns({
send: sendStub,
} as any);

mockBaseCoin.keychains.returns({
get: sinon.stub().resolves({ id: 'keychain-id', pub: 'public-key' }),
} as any);

const result = await wallets.generateWallet({
label: 'Hot EVM Keyring Wallet',
evmKeyRingReferenceWalletId: '507f1f77bcf86cd799439011',
});

result.should.have.property('wallet');

const sentParams = sendStub.firstCall.args[0];
sentParams.should.not.have.property('type');
sentParams.should.have.property('evmKeyRingReferenceWalletId', '507f1f77bcf86cd799439011');
});

it('should pass enterprise parameter for cold EVM keyring wallet via add method', async function () {
const mockWalletResponse = {
id: 'new-cold-wallet-id',
keys: ['user-key', 'backup-key', 'bitgo-key'],
};

const sendStub = sinon.stub().returns({
result: sinon.stub().resolves(mockWalletResponse),
});

mockBitGo.post.returns({
send: sendStub,
} as any);

const result = await wallets.add({
label: 'Cold EVM Keyring Child',
evmKeyRingReferenceWalletId: 'cold-parent-wallet-id',
enterprise: 'enterprise-123',
});

result.should.have.property('wallet');

const sentParams = sendStub.firstCall.args[0];
sentParams.should.not.have.property('type');
sentParams.should.have.property('enterprise', 'enterprise-123');
sentParams.should.have.property('evmKeyRingReferenceWalletId', 'cold-parent-wallet-id');
});

it('should pass enterprise parameter for custodial EVM keyring wallet via add method', async function () {
const mockWalletResponse = {
id: 'new-custodial-wallet-id',
keys: ['user-key', 'backup-key', 'bitgo-key'],
};

const sendStub = sinon.stub().returns({
result: sinon.stub().resolves(mockWalletResponse),
});

mockBitGo.post.returns({
send: sendStub,
} as any);

const result = await wallets.add({
label: 'Custodial EVM Keyring Child',
evmKeyRingReferenceWalletId: 'custodial-parent-wallet-id',
enterprise: 'enterprise-456',
});

result.should.have.property('wallet');

const sentParams = sendStub.firstCall.args[0];
sentParams.should.not.have.property('type');
sentParams.should.have.property('enterprise', 'enterprise-456');
sentParams.should.have.property('evmKeyRingReferenceWalletId', 'custodial-parent-wallet-id');
});
});
});