From b0f9b6fd63db11c78f738cf98838815775f33d5e Mon Sep 17 00:00:00 2001 From: Alejandro Busse Date: Mon, 19 Feb 2024 20:05:30 -0300 Subject: [PATCH] fix(sdk-coin-xlm): deprecate eddsa key deriver for xlm deprecated eddsa key deriver for xlm WP-1401 TICKET: WP-1401 --- modules/sdk-coin-xlm/package.json | 1 - modules/sdk-coin-xlm/src/xlm.ts | 37 +++++---------------------- modules/sdk-coin-xlm/test/unit/xlm.ts | 20 ++++++--------- 3 files changed, 14 insertions(+), 44 deletions(-) diff --git a/modules/sdk-coin-xlm/package.json b/modules/sdk-coin-xlm/package.json index 07766ac2e1..83e8b968d9 100644 --- a/modules/sdk-coin-xlm/package.json +++ b/modules/sdk-coin-xlm/package.json @@ -42,7 +42,6 @@ "dependencies": { "@bitgo/sdk-core": "^25.1.0", "@bitgo/statics": "^46.1.0", - "@bitgo/utxo-lib": "^9.34.0", "bignumber.js": "^9.1.1", "lodash": "^4.17.14", "stellar-sdk": "^10.0.1", diff --git a/modules/sdk-coin-xlm/src/xlm.ts b/modules/sdk-coin-xlm/src/xlm.ts index b2271a1d07..7124bfee55 100644 --- a/modules/sdk-coin-xlm/src/xlm.ts +++ b/modules/sdk-coin-xlm/src/xlm.ts @@ -1,6 +1,5 @@ import assert from 'assert'; import * as _ from 'lodash'; -import * as utxolib from '@bitgo/utxo-lib'; import * as querystring from 'querystring'; import * as url from 'url'; import * as request from 'superagent'; @@ -12,7 +11,6 @@ import { BitGoBase, checkKrsProvider, common, - Ed25519KeyDeriver, ExtraPrebuildParamsOptions, InvalidAddressError, InvalidMemoIdError, @@ -33,6 +31,7 @@ import { VerifyAddressOptions as BaseVerifyAddressOptions, VerifyTransactionOptions as BaseVerifyTransactionOptions, Wallet, + NotSupported, } from '@bitgo/sdk-core'; import { toBitgoRequest } from '@bitgo/sdk-api'; import { getStellarKeys } from './getStellarKeys'; @@ -209,12 +208,8 @@ export class Xlm extends BaseCoin { return 'https://horizon.stellar.org'; } - /** - * Generate a new key pair on the ed25519 curve - * @param seed - * @returns generated pub and prv - */ - generateKeyPair(seed: Buffer): KeyPair { + /** inheritdoc */ + generateKeyPair(seed?: Buffer): KeyPair { const pair = seed ? stellar.Keypair.fromRawEd25519Seed(seed) : stellar.Keypair.random(); return { pub: pair.publicKey(), @@ -1112,29 +1107,9 @@ export class Xlm extends BaseCoin { return true; } - /** - * Derive a hardened child public key from a master key seed using an additional seed for randomness. - * - * Due to technical differences between keypairs on the ed25519 curve and the secp256k1 curve, - * only hardened private key derivation is supported. - * - * @param key seed for the master key. Note: Not the public key or encoded private key. This is the raw seed. - * @param entropySeed random seed which is hashed to generate the derivation path - */ - deriveKeyWithSeed({ key, seed }: { key: string; seed: string }): { derivationPath: string; key: string } { - const derivationPathInput = utxolib.crypto.hash256(Buffer.from(seed, 'utf8')).toString('hex'); - const derivationPathParts = [ - 999999, - parseInt(derivationPathInput.slice(0, 7), 16), - parseInt(derivationPathInput.slice(7, 14), 16), - ]; - const derivationPath = 'm/' + derivationPathParts.map((part) => `${part}'`).join('/'); - const derivedKey = Ed25519KeyDeriver.derivePath(derivationPath, key).key; - const keypair = stellar.Keypair.fromRawEd25519Seed(derivedKey); - return { - key: keypair.publicKey(), - derivationPath, - }; + /** inheritdoc */ + deriveKeyWithSeed(): { derivationPath: string; key: string } { + throw new NotSupported('method deriveKeyWithSeed not supported for eddsa curve'); } /** diff --git a/modules/sdk-coin-xlm/test/unit/xlm.ts b/modules/sdk-coin-xlm/test/unit/xlm.ts index 436eabda56..00f2710946 100644 --- a/modules/sdk-coin-xlm/test/unit/xlm.ts +++ b/modules/sdk-coin-xlm/test/unit/xlm.ts @@ -282,6 +282,14 @@ describe('XLM:', function () { walletParams.rootPrivateKey.should.equal(rootPrivateKey); }); + describe('deriveKeyWithSeed', function () { + it('should derive key with seed', function () { + (() => { + basecoin.deriveKeyWithSeed('test'); + }).should.throw('method deriveKeyWithSeed not supported for eddsa curve'); + }); + }); + describe('Transaction Verification', function () { let basecoin; let wallet; @@ -891,18 +899,6 @@ describe('XLM:', function () { stellar.StrKey.encodeEd25519SecretSeed(seed).should.equal(secret); }); - it('should deterministically derive a child key from master seed and entropy seed', () => { - const seed = Buffer.alloc(32).fill(0).toString('hex'); - const masterSeed = '0x01020304050607080910111213141516171819202122232425262728293031'; - - const derivedKey = basecoin.deriveKeyWithSeed({ key: masterSeed, seed }); - - derivedKey.should.have.properties({ - key: 'GCJR3ORBWOKGFA3FTGYDDQVFEEMCYXFHY6KAUOTU4MQMFHK4LLSWWGLW', - derivationPath: "m/999999'/230673453'/206129755'", - }); - }); - it('should validate pub key', () => { const { pub } = basecoin.keychains().create(); basecoin.isValidPub(pub).should.equal(true);