From 34d8fb050db3d18024b7e25a8a5a9084580a059d Mon Sep 17 00:00:00 2001 From: Alejandro Busse Date: Mon, 19 Feb 2024 20:09:32 -0300 Subject: [PATCH 1/3] fix(sdk-core): deprecate derivedHardened for eddsa KeyPair deprecated derivedHardened for eddsa KeyPair WP-1465 TICKET: WP-1465 --- modules/sdk-core/src/account-lib/baseCoin/ed25519KeyPair.ts | 1 + modules/sdk-core/src/account-lib/util/ed25519KeyDeriver.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/modules/sdk-core/src/account-lib/baseCoin/ed25519KeyPair.ts b/modules/sdk-core/src/account-lib/baseCoin/ed25519KeyPair.ts index a62b397be0..0391ef86e0 100644 --- a/modules/sdk-core/src/account-lib/baseCoin/ed25519KeyPair.ts +++ b/modules/sdk-core/src/account-lib/baseCoin/ed25519KeyPair.ts @@ -128,6 +128,7 @@ export abstract class Ed25519KeyPair implements BaseKeyPair { * as the seed. * * @param path derivation path + * @deprecated */ deriveHardened(path: string): DefaultKeys { if (!this.keyPair?.prv) { diff --git a/modules/sdk-core/src/account-lib/util/ed25519KeyDeriver.ts b/modules/sdk-core/src/account-lib/util/ed25519KeyDeriver.ts index acd98bf763..7ce712897b 100644 --- a/modules/sdk-core/src/account-lib/util/ed25519KeyDeriver.ts +++ b/modules/sdk-core/src/account-lib/util/ed25519KeyDeriver.ts @@ -14,6 +14,8 @@ export interface HdKeypair { * * https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md * https://github.com/satoshilabs/slips/blob/master/slip-0010.md + * + * @deprecated */ export class Ed25519KeyDeriver { /** From 7e99480f2e5041b7c787ec7a4b07b21b813183a8 Mon Sep 17 00:00:00 2001 From: Alejandro Busse Date: Mon, 19 Feb 2024 20:10:32 -0300 Subject: [PATCH 2/3] fix(sdk-coin-dot): deprecate derivedHardened for DOT deprecated derivedHardened for DOT keypair WP-1465 TICKET: WP-1465 --- modules/sdk-coin-dot/test/unit/keypair.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/modules/sdk-coin-dot/test/unit/keypair.ts b/modules/sdk-coin-dot/test/unit/keypair.ts index 3620661cd0..e783dceab0 100644 --- a/modules/sdk-coin-dot/test/unit/keypair.ts +++ b/modules/sdk-coin-dot/test/unit/keypair.ts @@ -42,23 +42,6 @@ describe('Dot KeyPair', () => { const keyPair = new KeyPair({ pub: bs58Account.publicKey }); should.equal(keyPair.getKeys().pub, publicKeyHexString); }); - - it('should be able to derive keypair with hardened derivation', () => { - // using ed25519 (polkadot.js uses sr25519) - const keyPair = new KeyPair({ - prv: account1.secretKey, - }); - const derivationIndex = 0; - const derived = keyPair.deriveHardened(`m/0'/0'/0'/${derivationIndex}'`); - const derivedKeyPair = new KeyPair({ - prv: derived.prv || '', - }); - should.exists(derivedKeyPair.getAddress(DotAddressFormat.substrate)); - should.exists(derivedKeyPair.getKeys().prv); - should.exists(derivedKeyPair.getKeys().pub); - should.equal(derivedKeyPair.getKeys().prv?.length, 64); - should.equal(derivedKeyPair.getKeys().pub?.length, 64); - }); }); describe('KeyPair validation', () => { From d3cb90057924e874b2319abe962d00daaf06f2a4 Mon Sep 17 00:00:00 2001 From: Alejandro Busse Date: Mon, 19 Feb 2024 20:11:11 -0300 Subject: [PATCH 3/3] fix(sdk-coin-sol): deprecate deriveHardened for SOL deprecated deriveHardened for SOL keypair WP-1465 TICKET: WP-1465 --- modules/sdk-coin-sol/test/unit/keyPair.ts | 32 +---------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/modules/sdk-coin-sol/test/unit/keyPair.ts b/modules/sdk-coin-sol/test/unit/keyPair.ts index 612814db6c..5d3330c786 100644 --- a/modules/sdk-coin-sol/test/unit/keyPair.ts +++ b/modules/sdk-coin-sol/test/unit/keyPair.ts @@ -2,7 +2,7 @@ import assert from 'assert'; import { KeyPair } from '../../src'; import should from 'should'; import * as testData from '../resources/sol'; -import { isValidPublicKey, isValidAddress, isValidPrivateKey } from '../../src/lib/utils'; +import { isValidPublicKey, isValidAddress } from '../../src/lib/utils'; describe('Sol KeyPair', function () { const defaultSeed = { seed: testData.accountWithSeed.seed }; @@ -158,34 +158,4 @@ describe('Sol KeyPair', function () { keyPair.verifySignature(message, signature).should.equal(false); }); }); - - describe('deriveHardened', () => { - it('should derive child key pairs', () => { - const rootKeyPair = new KeyPair(); - for (let i = 0; i < 50; i++) { - const path = `m/0'/0'/0'/${i}'`; - const derived = new KeyPair(rootKeyPair.deriveHardened(path)); - - isValidPublicKey(derived.getKeys().pub).should.be.true(); - isValidAddress(derived.getAddress()).should.be.true(); - - const derivedPrv = derived.getKeys().prv; - should.exist(derivedPrv); - isValidPrivateKey(derivedPrv as string | Uint8Array).should.be.true(); - - const rederived = new KeyPair(rootKeyPair.deriveHardened(path)); - rederived.getKeys().should.deepEqual(derived.getKeys()); - } - }); - - it('should not be able to derive without private key', () => { - const rootKeyPair = new KeyPair({ pub: testData.accountWithSeed.publicKey }); - assert.throws(() => rootKeyPair.deriveHardened("m/0'/0'/0'/0'"), /need private key to derive hardened keypair/); - }); - - it('should throw error for non-hardened path', () => { - const rootKeyPair = new KeyPair(); - assert.throws(() => rootKeyPair.deriveHardened('m/0/0/0/0'), /Invalid derivation path/); - }); - }); });