From 584aa268327dc29ccc9e86dcb1f41f673bf2db86 Mon Sep 17 00:00:00 2001 From: tony Date: Mon, 10 Apr 2023 11:28:30 +0800 Subject: [PATCH 1/3] ci: update node versions --- .github/workflows/test.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 157bd84..23d0cc4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,8 +12,7 @@ jobs: name: Node ${{ matrix.node }} strategy: matrix: - os: [ubuntu-latest] - node: [8, 10, 12, 14] + node: [14,16,18] steps: - uses: actions/checkout@v2 From 885fdc02c16abe38b083c685691ea998743e772c Mon Sep 17 00:00:00 2001 From: tony Date: Wed, 17 May 2023 16:16:34 +0800 Subject: [PATCH 2/3] hdnode: allow custom path --- src/hdnode.ts | 4 ++-- tests/crypto.test.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/hdnode.ts b/src/hdnode.ts index a64987d..9a63db6 100644 --- a/src/hdnode.ts +++ b/src/hdnode.ts @@ -22,10 +22,10 @@ export interface HDNode { export namespace HDNode { /** create node from mnemonic words */ - export function fromMnemonic(words: string[]) { + export function fromMnemonic(words: string[], path=VET_DERIVATION_PATH) { // normalize words to lowercase const joinedWords = words.join(' ').toLowerCase() - const node = HD.fromMnemonic(joinedWords).derivePath(VET_DERIVATION_PATH) + const node = HD.fromMnemonic(joinedWords).derivePath(path) return createHDNode(node) } diff --git a/tests/crypto.test.ts b/tests/crypto.test.ts index b03b977..265ee2e 100644 --- a/tests/crypto.test.ts +++ b/tests/crypto.test.ts @@ -172,4 +172,23 @@ describe('mnemonic', () => { const node2 = HDNode.fromMnemonic(words.map(w => w.toUpperCase())) expect(node.address === node2.address) }) + + it('hdNode custom path', () => { + const eth_path = `m/44'/60'/0'/0` + const node = HDNode.fromMnemonic(words, eth_path) + // test case generated via https://iancoleman.io/bip39/ + const addresses = [ + '4473c83a6a9661ab9cdb6b07749998ad9e77a580', + '858531457566df8b60cf1355b54e48e04e36be33', + '40b5aa8b54aafaf6323b58ce5737ce320d92cf99', + '988f3af24dca0a3080f9ab5a1f57d706c6b8f011', + 'ffb0e35ba82856f8f5b7a57104c38a73f3ceff03' + ] + for (let i = 0; i < 5; i++) { + const child = node.derive(i) + expect(address.fromPublicKey(child.publicKey).slice(2)).equal(addresses[i]) + expect(child.address).equal('0x' + addresses[i]) + expect(secp256k1.derivePublicKey(child.privateKey!).toString('hex')).equal(child.publicKey.toString('hex')) + } + }) }) From fec11ad7f2537f5222c8b98684ffa6356d07b4e1 Mon Sep 17 00:00:00 2001 From: tony Date: Wed, 17 May 2023 16:21:14 +0800 Subject: [PATCH 3/3] ci: update action syntax --- .github/workflows/test.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 23d0cc4..1523d44 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,19 +15,12 @@ jobs: node: [14,16,18] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} - - - name: Cache Node.js modules - uses: actions/cache@v2 - with: - path: ~/.npm - key: ${{ runner.OS }}-node-${{matrix.node}}-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.OS }}-node- + cache: 'npm' - name: Install Dependencies run: npm ci