From 603b7ae85c63de5fbcf80d8bd779e73a638fe93d Mon Sep 17 00:00:00 2001 From: Jackson Mills Date: Tue, 14 Sep 2021 09:55:12 -0700 Subject: [PATCH] Add Wallet.fromSecret(...) as an alias for Wallet.fromSeed(...) (#1618) * Add alias to fromSeed for fromSecret * Switch syntax to direct usage --- src/wallet/index.ts | 9 +++++++++ test/wallet/index.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/wallet/index.ts b/src/wallet/index.ts index e306a84a..32199a42 100644 --- a/src/wallet/index.ts +++ b/src/wallet/index.ts @@ -72,6 +72,15 @@ class Wallet { return Wallet.deriveWallet(seed, algorithm) } + /** + * Derives a wallet from a secret (AKA a seed) + * + * @param secret - A string used to generate a keypair (publicKey/privateKey) to derive a wallet. + * @param algorithm - The digital signature algorithm to generate an address fro. + * @returns A Wallet derived from a secret (AKA a seed). + */ + public static fromSecret = Wallet.fromSeed + /** * Derives a wallet from a mnemonic. * diff --git a/test/wallet/index.ts b/test/wallet/index.ts index 7f28e809..760f53a3 100644 --- a/test/wallet/index.ts +++ b/test/wallet/index.ts @@ -84,6 +84,37 @@ 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) + + assert.equal(wallet.publicKey, publicKey) + assert.equal(wallet.privateKey, privateKey) + }) + + it('derives a wallet using algorithm ecdsa-secp256k1', function () { + const algorithm = ECDSA.secp256k1 + const wallet = Wallet.fromSecret(seed, algorithm) + + assert.equal(wallet.publicKey, publicKey) + assert.equal(wallet.privateKey, privateKey) + }) + + it('derives a wallet using algorithm ed25519', function () { + const algorithm = ECDSA.ed25519 + const wallet = Wallet.fromSecret(seed, algorithm) + + assert.equal(wallet.publicKey, publicKey) + assert.equal(wallet.privateKey, privateKey) + }) + }) + describe('fromMnemonic', function () { const mnemonic = 'try milk link drift aware pass obtain again music stick pluck fold'