mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-01 17:45:49 +00:00
[Feature] Generate Wallet from secret numbers (#1799)
* add the possibility to create a wallet from Secret Numbers * Move it off the Wallet class
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import { assert } from 'chai'
|
||||
import { decode } from 'ripple-binary-codec'
|
||||
|
||||
import { NFTokenMint, Payment, Transaction } from '../../src'
|
||||
import {
|
||||
NFTokenMint,
|
||||
Payment,
|
||||
Transaction,
|
||||
walletFromSecretNumbers,
|
||||
} from '../../src'
|
||||
import ECDSA from '../../src/ECDSA'
|
||||
import { Wallet } from '../../src/Wallet'
|
||||
import requests from '../fixtures/requests'
|
||||
@@ -297,6 +302,86 @@ describe('Wallet', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('fromSecretNumbers', function () {
|
||||
const secretNumbersString =
|
||||
'399150 474506 009147 088773 432160 282843 253738 605430'
|
||||
const secretNumbersArray = [
|
||||
'399150',
|
||||
'474506',
|
||||
'009147',
|
||||
'088773',
|
||||
'432160',
|
||||
'282843',
|
||||
'253738',
|
||||
'605430',
|
||||
]
|
||||
|
||||
const publicKey =
|
||||
'03BFC2F7AE242C3493187FA0B72BE97B2DF71194FB772E507FF9DEA0AD13CA1625'
|
||||
const privateKey =
|
||||
'00B6FE8507D977E46E988A8A94DB3B8B35E404B60F8B11AC5213FA8B5ABC8A8D19'
|
||||
// TODO: Uncomment when the `deriveKeypair` fix is merged so `deriveSecretNumbers` with ed25519 works.
|
||||
// const publicKeyED25519 =
|
||||
// 'ED8079E575450E256C496578480020A33E19B579D58A2DB8FF13FC6B05B9229DE3'
|
||||
// const privateKeyED25519 =
|
||||
// 'EDD2AF6288A903DED9860FC62E778600A985BDF804E40BD8266505553E3222C3DA'
|
||||
|
||||
it('derives a wallet using default algorithm', function () {
|
||||
const wallet = walletFromSecretNumbers(secretNumbersString)
|
||||
|
||||
assert.equal(wallet.publicKey, publicKey)
|
||||
assert.equal(wallet.privateKey, privateKey)
|
||||
})
|
||||
|
||||
it('derives a wallet from secret numbers as an array using default algorithm', function () {
|
||||
const wallet = walletFromSecretNumbers(secretNumbersArray)
|
||||
|
||||
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 = walletFromSecretNumbers(secretNumbersString, {
|
||||
algorithm,
|
||||
})
|
||||
|
||||
assert.equal(wallet.publicKey, publicKey)
|
||||
assert.equal(wallet.privateKey, privateKey)
|
||||
})
|
||||
|
||||
// TODO: Uncomment this test when the `deriveKeypair` fix is merged
|
||||
// it('derives a wallet using algorithm ed25519', function () {
|
||||
// const algorithm = ECDSA.ed25519
|
||||
// const wallet = Wallet.fromSecretNumbers(secretNumbersString, {
|
||||
// algorithm,
|
||||
// })
|
||||
|
||||
// assert.equal(wallet.publicKey, publicKeyED25519)
|
||||
// assert.equal(wallet.privateKey, privateKeyED25519)
|
||||
// })
|
||||
|
||||
it('derives a wallet using a Regular Key Pair', function () {
|
||||
const masterAddress = 'rUAi7pipxGpYfPNg3LtPcf2ApiS8aw9A93'
|
||||
const regularKeyPair = {
|
||||
secretNumbers:
|
||||
'399150 474506 009147 088773 432160 282843 253738 605430',
|
||||
publicKey:
|
||||
'03BFC2F7AE242C3493187FA0B72BE97B2DF71194FB772E507FF9DEA0AD13CA1625',
|
||||
privateKey:
|
||||
'00B6FE8507D977E46E988A8A94DB3B8B35E404B60F8B11AC5213FA8B5ABC8A8D19',
|
||||
}
|
||||
|
||||
const wallet = walletFromSecretNumbers(regularKeyPair.secretNumbers, {
|
||||
masterAddress,
|
||||
})
|
||||
|
||||
assert.equal(wallet.publicKey, regularKeyPair.publicKey)
|
||||
assert.equal(wallet.privateKey, regularKeyPair.privateKey)
|
||||
assert.equal(wallet.classicAddress, masterAddress)
|
||||
})
|
||||
})
|
||||
|
||||
describe('fromEntropy', function () {
|
||||
let entropy: number[]
|
||||
const publicKey =
|
||||
|
||||
Reference in New Issue
Block a user