From ff6e7e973d4b25b53829862701b1f950450a1fe9 Mon Sep 17 00:00:00 2001 From: JST5000 Date: Tue, 11 Jul 2023 17:01:22 -0700 Subject: [PATCH 1/7] Fix deriveKeypair and then update tests --- packages/ripple-keypairs/HISTORY.md | 1 + packages/ripple-keypairs/src/index.ts | 10 +- packages/xrpl/HISTORY.md | 3 + packages/xrpl/src/Wallet/index.ts | 3 +- .../xrpl/test/integration/regularKey.test.ts | 2 + packages/xrpl/test/integration/utils.ts | 3 +- packages/xrpl/test/wallet/index.test.ts | 119 +++++++++++------- packages/xrpl/test/wallet/signer.test.ts | 6 +- 8 files changed, 93 insertions(+), 54 deletions(-) diff --git a/packages/ripple-keypairs/HISTORY.md b/packages/ripple-keypairs/HISTORY.md index 066988b19a..5a0c0638be 100644 --- a/packages/ripple-keypairs/HISTORY.md +++ b/packages/ripple-keypairs/HISTORY.md @@ -1,6 +1,7 @@ # ripple-keypairs Release History ## Unreleased +* Fix `deriveKeypair` ignoring manual decoding algorithm. (Specifying algorithm=`ed25519` in `opts` now works on secrets like `sNa1...`) ## 1.3.0 (2023-06-13) ### Added diff --git a/packages/ripple-keypairs/src/index.ts b/packages/ripple-keypairs/src/index.ts index 631e79134d..e50901aa9a 100644 --- a/packages/ripple-keypairs/src/index.ts +++ b/packages/ripple-keypairs/src/index.ts @@ -104,13 +104,19 @@ function select(algorithm): any { function deriveKeypair( seed: string, - options?: object, + options?: { + algorithm?: 'ed25519' | 'ecdsa-secp256k1' + validator?: boolean + accountIndex?: number + }, ): { publicKey: string privateKey: string } { const decoded = addressCodec.decodeSeed(seed) - const algorithm = decoded.type === 'ed25519' ? 'ed25519' : 'ecdsa-secp256k1' + const proposedAlgorithm = options?.algorithm ?? decoded.type + const algorithm = + proposedAlgorithm === 'ed25519' ? 'ed25519' : 'ecdsa-secp256k1' const method = select(algorithm) const keypair = method.deriveKeypair(decoded.bytes, options) const messageToVerify = hash('This test message should verify.') diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 930215dd05..2b4f1eaade 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -3,6 +3,9 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xrpl-announce) for release announcements. We recommend that xrpl.js (ripple-lib) users stay up-to-date with the latest stable release. ## Unreleased +### Fixed +* Fixed Wallet.generate() ignoring the `algorithm` parameter (Only a problem once binary-codec fix for `derive_keypair` is added) + ### Added * Add `BurnedNFTokens`, `FirstNFTSequence`, `MintedNFTokens`, `NFTokenMinter`, and `WalletLocator` to `AccountRoot`. diff --git a/packages/xrpl/src/Wallet/index.ts b/packages/xrpl/src/Wallet/index.ts index 7eb0baaeb0..2ea2aa3915 100644 --- a/packages/xrpl/src/Wallet/index.ts +++ b/packages/xrpl/src/Wallet/index.ts @@ -1,3 +1,4 @@ +/* eslint-disable max-lines -- The length is due to necessary complexity */ import BigNumber from 'bignumber.js' import { fromSeed } from 'bip32' import { mnemonicToSeedSync, validateMnemonic } from 'bip39' @@ -137,7 +138,7 @@ export class Wallet { throw new ValidationError('Invalid cryptographic signing algorithm') } const seed = generateSeed({ algorithm }) - return Wallet.fromSeed(seed) + return Wallet.fromSeed(seed, { algorithm }) } /** diff --git a/packages/xrpl/test/integration/regularKey.test.ts b/packages/xrpl/test/integration/regularKey.test.ts index 85a94a4dd8..fbad77fb4e 100644 --- a/packages/xrpl/test/integration/regularKey.test.ts +++ b/packages/xrpl/test/integration/regularKey.test.ts @@ -8,6 +8,7 @@ import { Wallet, AccountSetAsfFlags, OfferCreate, + ECDSA, } from '../../src' import { convertStringToHex } from '../../src/utils' import { multisign } from '../../src/Wallet/signer' @@ -41,6 +42,7 @@ async function generateFundedWalletWithRegularKey( const regularKeyWallet = Wallet.fromSeed(regularKeyInfo.seed, { masterAddress: masterWallet.address, + algorithm: ECDSA.secp256k1, }) const setRegularTx: SetRegularKey = { diff --git a/packages/xrpl/test/integration/utils.ts b/packages/xrpl/test/integration/utils.ts index 7cdc80afad..1e373e6b77 100644 --- a/packages/xrpl/test/integration/utils.ts +++ b/packages/xrpl/test/integration/utils.ts @@ -11,6 +11,7 @@ import { TimeoutError, NotConnectedError, unixTimeToRippleTime, + ECDSA, } from '../../src' import { Payment, Transaction } from '../../src/models/transactions' import { hashSignedTx } from '../../src/utils/hashes' @@ -175,7 +176,7 @@ export async function fundAccount( // 2 times the amount needed for a new account (20 XRP) Amount: '400000000', } - const wal = Wallet.fromSeed(masterSecret) + const wal = Wallet.fromSeed(masterSecret, { algorithm: ECDSA.secp256k1 }) const response = await submitTransaction({ client, wallet: wal, diff --git a/packages/xrpl/test/wallet/index.test.ts b/packages/xrpl/test/wallet/index.test.ts index f7497d55ff..af1af92969 100644 --- a/packages/xrpl/test/wallet/index.test.ts +++ b/packages/xrpl/test/wallet/index.test.ts @@ -16,6 +16,16 @@ const { sign: RESPONSE_FIXTURES } = responses * Provides tests for Wallet class. */ describe('Wallet', function () { + const knownSecret = 'sh1HiK7SwjS1VxFdXi7qeMHRedrYX' + const publicKeySecp256k1 = + '03BFC2F7AE242C3493187FA0B72BE97B2DF71194FB772E507FF9DEA0AD13CA1625' + const privateKeySecp256k1 = + '00B6FE8507D977E46E988A8A94DB3B8B35E404B60F8B11AC5213FA8B5ABC8A8D19' + const publicKeyED25519 = + 'ED8079E575450E256C496578480020A33E19B579D58A2DB8FF13FC6B05B9229DE3' + const privateKeyED25519 = + 'EDD2AF6288A903DED9860FC62E778600A985BDF804E40BD8266505553E3222C3DA' + describe('constructor', function () { it('initializes a wallet using a Regular Key Pair', function () { const masterAddress = 'rUAi7pipxGpYfPNg3LtPcf2ApiS8aw9A93' @@ -76,6 +86,7 @@ describe('Wallet', function () { assert.isString(wallet.address) assert.equal(wallet.classicAddress, wallet.address) assert.isString(wallet.seed) + console.log('Jackson', wallet.privateKey) assert.isTrue(wallet.privateKey.startsWith(secp256k1PrivateKeyPrefix)) assert.isTrue(wallet.classicAddress.startsWith(classicAddressPrefix)) }) @@ -97,33 +108,33 @@ describe('Wallet', function () { }) describe('fromSeed', function () { - const seed = 'ssL9dv2W5RK8L3tuzQxYY6EaZhSxW' - const publicKey = - '030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D' - const privateKey = - '00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F' + // const seed = 'ssL9dv2W5RK8L3tuzQxYY6EaZhSxW' + // const publicKey = + // '030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D' + // const privateKey = + // '00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F' it('derives a wallet using default algorithm', function () { - const wallet = Wallet.fromSeed(seed) + const wallet = Wallet.fromSeed(knownSecret) - assert.equal(wallet.publicKey, publicKey) - assert.equal(wallet.privateKey, privateKey) + assert.equal(wallet.publicKey, publicKeyED25519) + assert.equal(wallet.privateKey, privateKeyED25519) }) it('derives a wallet using algorithm ecdsa-secp256k1', function () { const algorithm = ECDSA.secp256k1 - const wallet = Wallet.fromSeed(seed, { algorithm }) + const wallet = Wallet.fromSeed(knownSecret, { algorithm }) - assert.equal(wallet.publicKey, publicKey) - assert.equal(wallet.privateKey, privateKey) + assert.equal(wallet.publicKey, publicKeySecp256k1) + assert.equal(wallet.privateKey, privateKeySecp256k1) }) it('derives a wallet using algorithm ed25519', function () { const algorithm = ECDSA.ed25519 - const wallet = Wallet.fromSeed(seed, { algorithm }) + const wallet = Wallet.fromSeed(knownSecret, { algorithm }) - assert.equal(wallet.publicKey, publicKey) - assert.equal(wallet.privateKey, privateKey) + assert.equal(wallet.publicKey, publicKeyED25519) + assert.equal(wallet.privateKey, privateKeyED25519) }) it('derives a wallet using rfc1751 mnemonic with secp256k1 key', function () { @@ -197,7 +208,10 @@ describe('Wallet', function () { '004265A28F3E18340A490421D47B2EB8DBC2C0BF2C24CEFEA971B61CED2CABD233', } - const wallet = Wallet.fromSeed(regularKeyPair.seed, { masterAddress }) + const wallet = Wallet.fromSeed(regularKeyPair.seed, { + masterAddress, + algorithm: ECDSA.secp256k1, + }) assert.equal(wallet.publicKey, regularKeyPair.publicKey) assert.equal(wallet.privateKey, regularKeyPair.privateKey) @@ -206,33 +220,27 @@ describe('Wallet', function () { }) describe('fromSecret', function () { - const seed = 'ssL9dv2W5RK8L3tuzQxYY6EaZhSxW' - const publicKey = - '030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D' - const privateKey = - '00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F' - it('derives a wallet using default algorithm', function () { - const wallet = Wallet.fromSecret(seed) + const wallet = Wallet.fromSecret(knownSecret) - assert.equal(wallet.publicKey, publicKey) - assert.equal(wallet.privateKey, privateKey) + assert.equal(wallet.publicKey, publicKeyED25519) + assert.equal(wallet.privateKey, privateKeyED25519) }) it('derives a wallet using algorithm ecdsa-secp256k1', function () { const algorithm = ECDSA.secp256k1 - const wallet = Wallet.fromSecret(seed, { algorithm }) + const wallet = Wallet.fromSecret(knownSecret, { algorithm }) - assert.equal(wallet.publicKey, publicKey) - assert.equal(wallet.privateKey, privateKey) + assert.equal(wallet.publicKey, publicKeySecp256k1) + assert.equal(wallet.privateKey, privateKeySecp256k1) }) it('derives a wallet using algorithm ed25519', function () { const algorithm = ECDSA.ed25519 - const wallet = Wallet.fromSecret(seed, { algorithm }) + const wallet = Wallet.fromSecret(knownSecret, { algorithm }) - assert.equal(wallet.publicKey, publicKey) - assert.equal(wallet.privateKey, privateKey) + assert.equal(wallet.publicKey, publicKeyED25519) + assert.equal(wallet.privateKey, privateKeyED25519) }) it('derives a wallet using a Regular Key Pair', function () { @@ -245,7 +253,10 @@ describe('Wallet', function () { '004265A28F3E18340A490421D47B2EB8DBC2C0BF2C24CEFEA971B61CED2CABD233', } - const wallet = Wallet.fromSecret(regularKeyPair.seed, { masterAddress }) + const wallet = Wallet.fromSecret(regularKeyPair.seed, { + masterAddress, + algorithm: ECDSA.secp256k1, + }) assert.equal(wallet.publicKey, regularKeyPair.publicKey) assert.equal(wallet.privateKey, regularKeyPair.privateKey) @@ -262,7 +273,9 @@ describe('Wallet', function () { '0013FC461CA5799F1357C8130AF703CBA7E9C28E072C6CA8F7DEF8601CDE98F394' it('derives a wallet using default derivation path', function () { - const wallet = Wallet.fromMnemonic(mnemonic) + const wallet = Wallet.fromMnemonic(mnemonic, { + algorithm: ECDSA.secp256k1, + }) assert.equal(wallet.publicKey, publicKey) assert.equal(wallet.privateKey, privateKey) @@ -270,7 +283,10 @@ describe('Wallet', function () { it('derives a wallet using an input derivation path', function () { const derivationPath = "m/44'/144'/0'/0/0" - const wallet = Wallet.fromMnemonic(mnemonic, { derivationPath }) + const wallet = Wallet.fromMnemonic(mnemonic, { + derivationPath, + algorithm: ECDSA.secp256k1, + }) assert.equal(wallet.publicKey, publicKey) assert.equal(wallet.privateKey, privateKey) @@ -289,6 +305,7 @@ describe('Wallet', function () { const wallet = Wallet.fromMnemonic(regularKeyPair.mnemonic, { masterAddress, mnemonicEncoding: 'rfc1751', + algorithm: ECDSA.secp256k1, }) assert.equal(wallet.publicKey, regularKeyPair.publicKey) @@ -299,13 +316,13 @@ describe('Wallet', function () { describe('fromEntropy', function () { let entropy: number[] - const publicKey = + const entropyPublicKeySecp256k1 = '0390A196799EE412284A5D80BF78C3E84CBB80E1437A0AECD9ADF94D7FEAAFA284' - const privateKey = + const entropyPrivateKeySecp256k1 = '002512BBDFDBB77510883B7DCCBEF270B86DEAC8B64AC762873D75A1BEE6298665' - const publicKeyED25519 = + const entropyPublicKeyED25519 = 'ED1A7C082846CFF58FF9A892BA4BA2593151CCF1DBA59F37714CC9ED39824AF85F' - const privateKeyED25519 = + const entropyPrivateKeyED25519 = 'ED0B6CBAC838DFE7F47EA1BD0DF00EC282FDF45510C92161072CCFB84035390C4D' beforeEach(function () { @@ -316,32 +333,34 @@ describe('Wallet', function () { it('derives a wallet using entropy', function () { const wallet = Wallet.fromEntropy(entropy) - assert.equal(wallet.publicKey, publicKeyED25519) - assert.equal(wallet.privateKey, privateKeyED25519) + assert.equal(wallet.publicKey, entropyPublicKeyED25519) + assert.equal(wallet.privateKey, entropyPrivateKeyED25519) }) it('derives a wallet using algorithm ecdsa-secp256k1', function () { const algorithm = ECDSA.secp256k1 const wallet = Wallet.fromEntropy(entropy, { algorithm }) - assert.equal(wallet.publicKey, publicKey) - assert.equal(wallet.privateKey, privateKey) + assert.equal(wallet.publicKey, entropyPublicKeySecp256k1) + assert.equal(wallet.privateKey, entropyPrivateKeySecp256k1) }) it('derives a wallet using algorithm ed25519', function () { const algorithm = ECDSA.ed25519 const wallet = Wallet.fromEntropy(entropy, { algorithm }) - assert.equal(wallet.publicKey, publicKeyED25519) - assert.equal(wallet.privateKey, privateKeyED25519) + assert.equal(wallet.publicKey, entropyPublicKeyED25519) + assert.equal(wallet.privateKey, entropyPrivateKeyED25519) }) it('derives a wallet using a regular key pair', function () { const masterAddress = 'rUAi7pipxGpYfPNg3LtPcf2ApiS8aw9A93' - const wallet = Wallet.fromEntropy(entropy, { masterAddress }) + const wallet = Wallet.fromEntropy(entropy, { + masterAddress, + }) - assert.equal(wallet.publicKey, publicKeyED25519) - assert.equal(wallet.privateKey, privateKeyED25519) + assert.equal(wallet.publicKey, entropyPublicKeyED25519) + assert.equal(wallet.privateKey, entropyPrivateKeyED25519) assert.equal(wallet.classicAddress, masterAddress) }) }) @@ -351,7 +370,9 @@ describe('Wallet', function () { let wallet: Wallet beforeEach(function () { - wallet = Wallet.fromSeed('ss1x3KLrSvfg7irFc1D929WXZ7z9H') + wallet = Wallet.fromSeed('ss1x3KLrSvfg7irFc1D929WXZ7z9H', { + algorithm: ECDSA.secp256k1, + }) }) it('sign successfully', async function () { @@ -386,7 +407,9 @@ describe('Wallet', function () { ], } - const result = Wallet.fromSeed(secret).sign(lowercaseMemoTx) + const result = Wallet.fromSeed(secret, { + algorithm: ECDSA.secp256k1, + }).sign(lowercaseMemoTx) assert.deepEqual(result, { tx_blob: '120000228000000023000022B8240000000C2E0000270F201B00D5A36761400000000098968068400000000000000C73210305E09ED602D40AB1AF65646A4007C2DAC17CB6CDACDE301E74FB2D728EA057CF744730450221009C00E8439E017CA622A5A1EE7643E26B4DE9C808DE2ABE45D33479D49A4CEC66022062175BE8733442FA2A4D9A35F85A57D58252AE7B19A66401FE238B36FA28E5A081146C1856D0E36019EA75C56D7E8CBA6E35F9B3F71583147FB49CD110A1C46838788CD12764E3B0F837E0DDF9EA7C1F687474703A2F2F6578616D706C652E636F6D2F6D656D6F2F67656E657269637D0472656E74E1F1', diff --git a/packages/xrpl/test/wallet/signer.test.ts b/packages/xrpl/test/wallet/signer.test.ts index 80cca97633..d241937265 100644 --- a/packages/xrpl/test/wallet/signer.test.ts +++ b/packages/xrpl/test/wallet/signer.test.ts @@ -1,7 +1,7 @@ import { assert } from 'chai' import { decode, encode } from 'ripple-binary-codec' -import { Transaction, ValidationError } from '../../src' +import { ECDSA, Transaction, ValidationError } from '../../src' import { Wallet } from '../../src/Wallet' import { authorizeChannel, @@ -188,7 +188,9 @@ describe('Signer', function () { }) it('authorizeChannel succeeds with secp256k1 seed', function () { - const secpWallet = Wallet.fromSeed('snGHNrPbHrdUcszeuDEigMdC1Lyyd') + const secpWallet = Wallet.fromSeed('snGHNrPbHrdUcszeuDEigMdC1Lyyd', { + algorithm: ECDSA.secp256k1, + }) const channelId = '5DB01B7FFED6B67E6B0414DED11E051D2EE2B7619CE0EAA6286D67A3A4D5BDB3' const amount = '1000000' From d7ff943106c9f9e7734d779f1a726e941aab8ac6 Mon Sep 17 00:00:00 2001 From: JST5000 Date: Tue, 11 Jul 2023 17:26:25 -0700 Subject: [PATCH 2/7] Fix linting errors --- packages/xrpl/src/Wallet/index.ts | 1 - packages/xrpl/test/wallet/index.test.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/xrpl/src/Wallet/index.ts b/packages/xrpl/src/Wallet/index.ts index 2ea2aa3915..415b8f7b12 100644 --- a/packages/xrpl/src/Wallet/index.ts +++ b/packages/xrpl/src/Wallet/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable max-lines -- The length is due to necessary complexity */ import BigNumber from 'bignumber.js' import { fromSeed } from 'bip32' import { mnemonicToSeedSync, validateMnemonic } from 'bip39' diff --git a/packages/xrpl/test/wallet/index.test.ts b/packages/xrpl/test/wallet/index.test.ts index af1af92969..e80817a8af 100644 --- a/packages/xrpl/test/wallet/index.test.ts +++ b/packages/xrpl/test/wallet/index.test.ts @@ -86,7 +86,6 @@ describe('Wallet', function () { assert.isString(wallet.address) assert.equal(wallet.classicAddress, wallet.address) assert.isString(wallet.seed) - console.log('Jackson', wallet.privateKey) assert.isTrue(wallet.privateKey.startsWith(secp256k1PrivateKeyPrefix)) assert.isTrue(wallet.classicAddress.startsWith(classicAddressPrefix)) }) From 17b66221263d4356fe4be94680a970febfbe7889 Mon Sep 17 00:00:00 2001 From: JST5000 Date: Wed, 12 Jul 2023 06:42:57 -0700 Subject: [PATCH 3/7] Remove commented code --- packages/xrpl/test/wallet/index.test.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/xrpl/test/wallet/index.test.ts b/packages/xrpl/test/wallet/index.test.ts index e80817a8af..8ba3005e46 100644 --- a/packages/xrpl/test/wallet/index.test.ts +++ b/packages/xrpl/test/wallet/index.test.ts @@ -107,12 +107,6 @@ describe('Wallet', function () { }) describe('fromSeed', function () { - // const seed = 'ssL9dv2W5RK8L3tuzQxYY6EaZhSxW' - // const publicKey = - // '030E58CDD076E798C84755590AAF6237CA8FAE821070A59F648B517A30DC6F589D' - // const privateKey = - // '00141BA006D3363D2FB2785E8DF4E44D3A49908780CB4FB51F6D217C08C021429F' - it('derives a wallet using default algorithm', function () { const wallet = Wallet.fromSeed(knownSecret) From bf1be2f843eae5d3a8245fb19efd9cb1994c79fa Mon Sep 17 00:00:00 2001 From: JST5000 Date: Tue, 18 Jul 2023 16:37:37 -0700 Subject: [PATCH 4/7] Make change non-breaking --- packages/xrpl/src/Wallet/index.ts | 4 +++- packages/xrpl/test/wallet/index.test.ts | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/xrpl/src/Wallet/index.ts b/packages/xrpl/src/Wallet/index.ts index 415b8f7b12..6b1d01e361 100644 --- a/packages/xrpl/src/Wallet/index.ts +++ b/packages/xrpl/src/Wallet/index.ts @@ -298,7 +298,9 @@ export class Wallet { opts: { masterAddress?: string; algorithm?: ECDSA } = {}, ): Wallet { const { publicKey, privateKey } = deriveKeypair(seed, { - algorithm: opts.algorithm ?? DEFAULT_ALGORITHM, + // TODO: replace this line with algorithm: opts.algorithm ?? DEFAULT_ALGORITHM + // To actually enforce the ed25519 default in the next breaking version. + algorithm: opts.algorithm, }) return new Wallet(publicKey, privateKey, { seed, diff --git a/packages/xrpl/test/wallet/index.test.ts b/packages/xrpl/test/wallet/index.test.ts index 8ba3005e46..eeff4b6229 100644 --- a/packages/xrpl/test/wallet/index.test.ts +++ b/packages/xrpl/test/wallet/index.test.ts @@ -110,8 +110,8 @@ describe('Wallet', function () { it('derives a wallet using default algorithm', function () { const wallet = Wallet.fromSeed(knownSecret) - assert.equal(wallet.publicKey, publicKeyED25519) - assert.equal(wallet.privateKey, privateKeyED25519) + assert.equal(wallet.publicKey, publicKeySecp256k1) + assert.equal(wallet.privateKey, privateKeySecp256k1) }) it('derives a wallet using algorithm ecdsa-secp256k1', function () { @@ -216,8 +216,8 @@ describe('Wallet', function () { it('derives a wallet using default algorithm', function () { const wallet = Wallet.fromSecret(knownSecret) - assert.equal(wallet.publicKey, publicKeyED25519) - assert.equal(wallet.privateKey, privateKeyED25519) + assert.equal(wallet.publicKey, publicKeySecp256k1) + assert.equal(wallet.privateKey, privateKeySecp256k1) }) it('derives a wallet using algorithm ecdsa-secp256k1', function () { From d7bb54177cdce1c658af8b390fae4f7602227780 Mon Sep 17 00:00:00 2001 From: JST5000 Date: Tue, 18 Jul 2023 16:38:52 -0700 Subject: [PATCH 5/7] Update xrpl HISTORY.md --- packages/xrpl/HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/xrpl/HISTORY.md b/packages/xrpl/HISTORY.md index 2b4f1eaade..c0d4e392c8 100644 --- a/packages/xrpl/HISTORY.md +++ b/packages/xrpl/HISTORY.md @@ -5,6 +5,7 @@ Subscribe to [the **xrpl-announce** mailing list](https://groups.google.com/g/xr ### Fixed * Fixed Wallet.generate() ignoring the `algorithm` parameter (Only a problem once binary-codec fix for `derive_keypair` is added) +* Fixed Wallet.fromSeed() ignoring the `algorithm` parameter ### Added * Add `BurnedNFTokens`, `FirstNFTSequence`, `MintedNFTokens`, From 158183ef88273ecf3089b1ca83717f31c640e757 Mon Sep 17 00:00:00 2001 From: JST5000 Date: Wed, 19 Jul 2023 14:34:43 -0700 Subject: [PATCH 6/7] Re-add breaking change --- packages/xrpl/src/Wallet/index.ts | 4 +--- packages/xrpl/test/wallet/index.test.ts | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/xrpl/src/Wallet/index.ts b/packages/xrpl/src/Wallet/index.ts index 6b1d01e361..415b8f7b12 100644 --- a/packages/xrpl/src/Wallet/index.ts +++ b/packages/xrpl/src/Wallet/index.ts @@ -298,9 +298,7 @@ export class Wallet { opts: { masterAddress?: string; algorithm?: ECDSA } = {}, ): Wallet { const { publicKey, privateKey } = deriveKeypair(seed, { - // TODO: replace this line with algorithm: opts.algorithm ?? DEFAULT_ALGORITHM - // To actually enforce the ed25519 default in the next breaking version. - algorithm: opts.algorithm, + algorithm: opts.algorithm ?? DEFAULT_ALGORITHM, }) return new Wallet(publicKey, privateKey, { seed, diff --git a/packages/xrpl/test/wallet/index.test.ts b/packages/xrpl/test/wallet/index.test.ts index eeff4b6229..4ad04901f9 100644 --- a/packages/xrpl/test/wallet/index.test.ts +++ b/packages/xrpl/test/wallet/index.test.ts @@ -118,8 +118,8 @@ describe('Wallet', function () { const algorithm = ECDSA.secp256k1 const wallet = Wallet.fromSeed(knownSecret, { algorithm }) - assert.equal(wallet.publicKey, publicKeySecp256k1) - assert.equal(wallet.privateKey, privateKeySecp256k1) + assert.equal(wallet.publicKey, publicKeyED25519) + assert.equal(wallet.privateKey, privateKeyED25519) }) it('derives a wallet using algorithm ed25519', function () { @@ -216,8 +216,8 @@ describe('Wallet', function () { it('derives a wallet using default algorithm', function () { const wallet = Wallet.fromSecret(knownSecret) - assert.equal(wallet.publicKey, publicKeySecp256k1) - assert.equal(wallet.privateKey, privateKeySecp256k1) + assert.equal(wallet.publicKey, publicKeyED25519) + assert.equal(wallet.privateKey, privateKeyED25519) }) it('derives a wallet using algorithm ecdsa-secp256k1', function () { From badeddb2ae525d5b82e232b498586ee8e907720f Mon Sep 17 00:00:00 2001 From: JST5000 Date: Fri, 28 Jul 2023 20:58:41 -0400 Subject: [PATCH 7/7] Fix tests --- packages/xrpl/test/wallet/index.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/xrpl/test/wallet/index.test.ts b/packages/xrpl/test/wallet/index.test.ts index 4ad04901f9..8ba3005e46 100644 --- a/packages/xrpl/test/wallet/index.test.ts +++ b/packages/xrpl/test/wallet/index.test.ts @@ -110,16 +110,16 @@ describe('Wallet', function () { it('derives a wallet using default algorithm', function () { const wallet = Wallet.fromSeed(knownSecret) - assert.equal(wallet.publicKey, publicKeySecp256k1) - assert.equal(wallet.privateKey, privateKeySecp256k1) + assert.equal(wallet.publicKey, publicKeyED25519) + assert.equal(wallet.privateKey, privateKeyED25519) }) it('derives a wallet using algorithm ecdsa-secp256k1', function () { const algorithm = ECDSA.secp256k1 const wallet = Wallet.fromSeed(knownSecret, { algorithm }) - assert.equal(wallet.publicKey, publicKeyED25519) - assert.equal(wallet.privateKey, privateKeyED25519) + assert.equal(wallet.publicKey, publicKeySecp256k1) + assert.equal(wallet.privateKey, privateKeySecp256k1) }) it('derives a wallet using algorithm ed25519', function () {