-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathsep0005.js
37 lines (31 loc) · 1.14 KB
/
sep0005.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import assert from 'assert'
import has from 'lodash/has'
import StellarHDWallet from '../src/stellar-hd-wallet'
const assertKeypair = (actualKeypair, expectedPublicKey, expectedSecret) => {
assert.equal(actualKeypair.publicKey(), expectedPublicKey)
assert.equal(actualKeypair.secret(), expectedSecret)
}
const specTestCase = num => () => {
const testCase = require(`./data/sep0005-testcase-${num}.json`)
const wallet = has(testCase, 'passphrase')
? StellarHDWallet.fromMnemonic(testCase.seedWords, testCase.passphrase)
: StellarHDWallet.fromMnemonic(testCase.seedWords)
it('derives expected parent key', () => {
assert.equal(
wallet.derive(`m/44'/148'`).toString('hex'),
testCase.parentKey
)
})
it('derives expected child keys', () => {
testCase.keypairs.forEach(([publicKey, secret], index) =>
assertKeypair(wallet.getKeypair(index), publicKey, secret)
)
})
}
describe('SEP-0005', () => {
describe('Test Case 1', specTestCase(1))
describe('Test Case 2', specTestCase(2))
describe('Test Case 3', specTestCase(3))
describe('Test Case 4', specTestCase(4))
describe('Test Case 5', specTestCase(5))
})