From a4dc28ea80056b78be0c50fe3f04a00574f12a67 Mon Sep 17 00:00:00 2001 From: Alejandro Busse Date: Mon, 19 Feb 2024 19:53:15 -0300 Subject: [PATCH] feat(sdk-core): implement root key creation for eddsa multisig implemented root key creation for eddsa multisig, deprecated ed25519 Key deriver WP-1401 TICKET: WP-1401 --- .../bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts | 2 +- modules/sdk-core/src/bitgo/baseCoin/baseCoin.ts | 13 +++++++++++-- modules/sdk-core/src/bitgo/baseCoin/iBaseCoin.ts | 1 + modules/sdk-core/src/bitgo/keychain/iKeychains.ts | 2 +- modules/sdk-core/src/bitgo/keychain/keychains.ts | 10 ++++++++-- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts b/modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts index 42cfc5b726..c03a238e6f 100644 --- a/modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts +++ b/modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts @@ -994,7 +994,7 @@ describe('TSS Ecdsa Utils:', async function () { }); // Seems to be flaky on CI, failed here: https://github.com/BitGo/BitGoJS/actions/runs/5902489990/job/16010623888?pr=3822 - it.skip('createOfflineMuDeltaShare should succeed', async function () { + xit('createOfflineMuDeltaShare should succeed', async function () { const mockPassword = 'password'; const alphaLength = 1536; const deltaLength = 64; diff --git a/modules/sdk-core/src/bitgo/baseCoin/baseCoin.ts b/modules/sdk-core/src/bitgo/baseCoin/baseCoin.ts index 3ad0ba52dc..0411a7ca75 100644 --- a/modules/sdk-core/src/bitgo/baseCoin/baseCoin.ts +++ b/modules/sdk-core/src/bitgo/baseCoin/baseCoin.ts @@ -429,11 +429,20 @@ export abstract class BaseCoin implements IBaseCoin { /** * Generate a key pair on the curve used by the coin - * - * @param seed + * @param {Buffer} seed - seed to use for key pair generation + * @returns {KeyPair} the generated key pair */ abstract generateKeyPair(seed?: Buffer): KeyPair; + /** + * Generate a root key pair on the curve used by the coin + * @param {Buffer} seed - seed to use for key pair generation + * @returns {KeyPair} the generated key pair + */ + generateRootKeyPair(seed?: Buffer): KeyPair { + throw new NotImplementedError('generateRootKeyPair is not supported for this coin'); + } + /** * Return boolean indicating whether input is valid public key for the coin. * diff --git a/modules/sdk-core/src/bitgo/baseCoin/iBaseCoin.ts b/modules/sdk-core/src/bitgo/baseCoin/iBaseCoin.ts index bb1eac3df7..3b8306a2fd 100644 --- a/modules/sdk-core/src/bitgo/baseCoin/iBaseCoin.ts +++ b/modules/sdk-core/src/bitgo/baseCoin/iBaseCoin.ts @@ -503,6 +503,7 @@ export interface IBaseCoin { initiateRecovery(params: InitiateRecoveryOptions): never; parseTransaction(params: ParseTransactionOptions): Promise; generateKeyPair(seed?: Buffer): KeyPair; + generateRootKeyPair(seed?: Buffer): KeyPair; isValidPub(pub: string): boolean; isValidMofNSetup(params: ValidMofNOptions): boolean; isValidAddress(address: string): boolean; diff --git a/modules/sdk-core/src/bitgo/keychain/iKeychains.ts b/modules/sdk-core/src/bitgo/keychain/iKeychains.ts index bf2b5894bd..77752ac30f 100644 --- a/modules/sdk-core/src/bitgo/keychain/iKeychains.ts +++ b/modules/sdk-core/src/bitgo/keychain/iKeychains.ts @@ -174,7 +174,7 @@ export interface IKeychains { list(params?: ListKeychainOptions): Promise; updatePassword(params: UpdatePasswordOptions): Promise; updateSingleKeychainPassword(params?: UpdateSingleKeychainPasswordOptions): Keychain; - create(params?: { seed?: Buffer }): KeyPair; + create(params?: { seed?: Buffer; isRootKey?: boolean }): KeyPair; add(params?: AddKeychainOptions): Promise; createBitGo(params?: CreateBitGoOptions): Promise; createBackup(params?: CreateBackupOptions): Promise; diff --git a/modules/sdk-core/src/bitgo/keychain/keychains.ts b/modules/sdk-core/src/bitgo/keychain/keychains.ts index 8efaf76fa1..bac469afe2 100644 --- a/modules/sdk-core/src/bitgo/keychain/keychains.ts +++ b/modules/sdk-core/src/bitgo/keychain/keychains.ts @@ -172,9 +172,15 @@ export class Keychains implements IKeychains { /** * Create a public/private key pair - * @param params.seed + * @param params - optional params + * @param params.seed optional - seed to use for keypair generation + * @param params.isRootKey optional - whether the resulting keypair should be a root key + * @returns {KeyPair} - the generated keypair */ - create(params: { seed?: Buffer } = {}): KeyPair { + create(params: { seed?: Buffer; isRootKey?: boolean } = {}): KeyPair { + if (params?.isRootKey) { + return this.baseCoin.generateRootKeyPair(params.seed); + } return this.baseCoin.generateKeyPair(params.seed); }