mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-29 08:35:49 +00:00
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:
committed by
Mayukha Vadari
parent
fcc8977623
commit
603b7ae85c
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user