Skip to content

Commit

Permalink
Adds a couple tests to validate shorter HD paths
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-miller-0 committed May 3, 2021
1 parent 551aad9 commit aaf2d58
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions test/testWalletJobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('getAddresses', () => {
it('Should fetch with a shorter derivation path', async () => {
const req = {
currency: 'ETH',
startPath: [7842, helpers.ETH_COIN, 2532356, 0],
startPath: [7842, helpers.ETH_COIN, 2532356, 7],
n: 3,
skipCache: true,
}
Expand Down Expand Up @@ -322,6 +322,32 @@ describe('signTx', () => {
expect(outputPubStr).to.equal(derivedPubStr)
})

it('Should get GP_SUCCESS for signing out of shorter (but allowed) paths', async () => {
jobData.sigReq[0].signerPath = {
pathDepth: 3,
purpose: helpers.BTC_LEGACY_PURPOSE,
coin: helpers.ETH_COIN,
account: 1572,
change: 0, // Not used for pathDepth=3
addr: 0, // Not used for pathDepth=4
};
jobReq.payload = helpers.serializeJobData(jobType, activeWalletUID, jobData);
const _res = await runTestCase(helpers.gpErrors.GP_SUCCESS);
const res = helpers.deserializeSignTxJobResult(_res.result);
// Ensure correct number of outputs returned
expect(res.numOutputs).to.equal(jobData.numRequests);
// Ensure signatures validate against provided pubkey
const outputKey = res.outputs[0].pubkey;
const outputPubStr = helpers.getPubStr(outputKey);
expect(outputKey.verify(jobData.sigReq[0].data, res.outputs[0].sig)).to.equal(true);
// Ensure pubkey is correctly derived
const wallet = bip32.fromSeed(activeWalletSeed);
console.log('stringified path', helpers.stringifyPath(jobData.sigReq[0].signerPath))
const derivedKey = wallet.derivePath(helpers.stringifyPath(jobData.sigReq[0].signerPath));
const derivedPubStr = `04${ethutil.privateToPublic(derivedKey.privateKey).toString('hex')}`;
expect(outputPubStr).to.equal(derivedPubStr)
})

it('Should get GP_ENODEV for unknown (random) wallet', async () => {
const dummyWalletUID = crypto.randomBytes(32);
jobReq.payload = helpers.serializeJobData(jobType, dummyWalletUID, jobData);
Expand Down Expand Up @@ -832,4 +858,4 @@ describe('Wallet sync tests (starting with newly synced wallet)', () => {
helpers.validateBTCAddresses(res, jobData, activeWalletSeed, true);
});

})
})

0 comments on commit aaf2d58

Please sign in to comment.