Add Wallet.fromSecret(...) as an alias for Wallet.fromSeed(...) (#1618)

* Add alias to fromSeed for fromSecret

* Switch syntax to direct usage
This commit is contained in:
Jackson Mills
2021-09-14 09:55:12 -07:00
committed by Mayukha Vadari
parent fcc8977623
commit 603b7ae85c
2 changed files with 40 additions and 0 deletions

View File

@@ -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.
*

View File

@@ -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'