Skip to content

Commit

Permalink
fix encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
netbonus committed Oct 16, 2024
1 parent bee0a26 commit 95ea0d9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
36 changes: 18 additions & 18 deletions src/__test__/e2e/wallet-jobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ describe('Test Wallet Jobs', () => {
expect(res.numOutputs).toEqual(jobData.numRequests);
// Ensure signatures validate against provided pubkey
const outputKey = res.outputs[0]?.pubkey;
const outputPubStr = outputKey.getPublic().encode('hex');
const outputPubStr = outputKey.getPublic().encode('hex', false);
expect(
outputKey.verify(jobData.sigReq[0].data, res.outputs[0].sig),
).toEqual(true);
Expand Down Expand Up @@ -513,7 +513,7 @@ describe('Test Wallet Jobs', () => {
expect(res.numOutputs).toEqual(jobData.numRequests);
// Ensure signatures validate against provided pubkey
const outputKey = res.outputs[0].pubkey;
const outputPubStr = outputKey.getPublic().encode('hex');
const outputPubStr = outputKey.getPublic().encode('hex', false);
expect(
outputKey.verify(jobData.sigReq[0].data, res.outputs[0].sig),
).toEqual(true);
Expand Down Expand Up @@ -691,7 +691,7 @@ describe('Test Wallet Jobs', () => {
);
});
let basePath = DEFAULT_SIGNER;
let parentPathStr = 'm/44\'/60\'/0\'/0';
let parentPathStr = "m/44'/60'/0'/0";

it('Should remove the current seed', async () => {
jobType = jobTypes.WALLET_JOB_DELETE_SEED;
Expand Down Expand Up @@ -759,27 +759,27 @@ describe('Test Wallet Jobs', () => {
});

// One leading privKey zero -> P(1/256)
it('Should test address m/44\'/60\'/0\'/0/396 (1 leading zero byte)', async () => {
it("Should test address m/44'/60'/0'/0/396 (1 leading zero byte)", async () => {
await runZerosTest(basePath, parentPathStr, 396, 1);
});
it('Should test address m/44\'/60\'/0\'/0/406 (1 leading zero byte)', async () => {
it("Should test address m/44'/60'/0'/0/406 (1 leading zero byte)", async () => {
await runZerosTest(basePath, parentPathStr, 406, 1);
});
it('Should test address m/44\'/60\'/0\'/0/668 (1 leading zero byte)', async () => {
it("Should test address m/44'/60'/0'/0/668 (1 leading zero byte)", async () => {
await runZerosTest(basePath, parentPathStr, 668, 1);
});

// Two leading privKey zeros -> P(1/65536)
it('Should test address m/44\'/60\'/0\'/0/71068 (2 leading zero bytes)', async () => {
it("Should test address m/44'/60'/0'/0/71068 (2 leading zero bytes)", async () => {
await runZerosTest(basePath, parentPathStr, 71068, 2);
});
it('Should test address m/44\'/60\'/0\'/0/82173 (2 leading zero bytes)', async () => {
it("Should test address m/44'/60'/0'/0/82173 (2 leading zero bytes)", async () => {
await runZerosTest(basePath, parentPathStr, 82173, 2);
});

// Three leading privKey zeros -> P(1/16777216)
// Unlikely any user ever runs into these but I wanted to derive the addrs for funsies
it('Should test address m/44\'/60\'/0\'/0/11981831 (3 leading zero bytes)', async () => {
it("Should test address m/44'/60'/0'/0/11981831 (3 leading zero bytes)", async () => {
await runZerosTest(basePath, parentPathStr, 11981831, 3);
});

Expand All @@ -790,42 +790,42 @@ describe('Test Wallet Jobs', () => {
// We want this leading-zero pubkey to be a parent derivation path to then
// test all further derivations
it('Should switch to testing public keys', async () => {
parentPathStr = 'm/44\'/60\'/0\'';
parentPathStr = "m/44'/60'/0'";
basePath[3] = 153;
basePath = basePath.slice(0, 4);
});

// There should be no problems with the parent path here because the result
// is the leading-zero pubkey directly. Since we do not do a further derivation
// with that leading-zero pubkey, there should never be any issues.
it('Should test address m/44\'/60\'/0\'/153', async () => {
it("Should test address m/44'/60'/0'/153", async () => {
await runZerosTest(basePath, parentPathStr, 153, 1, true);
});

it('Should prepare for one more derivation step', async () => {
parentPathStr = 'm/44\'/60\'/0\'/153';
parentPathStr = "m/44'/60'/0'/153";
basePath.push(0);
});

// Now we will derive one more step with the leading zero pubkey feeding
// into the derivation. This tests an edge case in firmware.
it('Should test address m/44\'/60\'/0\'/153/0', async () => {
it("Should test address m/44'/60'/0'/153/0", async () => {
await runZerosTest(basePath, parentPathStr, 0, 0);
});

it('Should test address m/44\'/60\'/0\'/153/1', async () => {
it("Should test address m/44'/60'/0'/153/1", async () => {
await runZerosTest(basePath, parentPathStr, 1, 0);
});

it('Should test address m/44\'/60\'/0\'/153/5', async () => {
it("Should test address m/44'/60'/0'/153/5", async () => {
await runZerosTest(basePath, parentPathStr, 5, 0);
});

it('Should test address m/44\'/60\'/0\'/153/10000', async () => {
it("Should test address m/44'/60'/0'/153/10000", async () => {
await runZerosTest(basePath, parentPathStr, 10000, 0);
});

it('Should test address m/44\'/60\'/0\'/153/9876543', async () => {
it("Should test address m/44'/60'/0'/153/9876543", async () => {
await runZerosTest(basePath, parentPathStr, 9876543, 0);
});
});
Expand Down Expand Up @@ -1028,7 +1028,7 @@ describe('Test Wallet Jobs', () => {
expect(res.numOutputs).to.equal(1);
const signerPubStr = res.outputs[0].pubkey
.getPublic()
.encode('hex')
.encode('hex', false)
.toString('hex');
// Make sure the exported signer matches expected
expect(signerPubStr).toEqualElseLog(refPubStr, 'Incorrect signer');
Expand Down
1 change: 0 additions & 1 deletion src/__test__/utils/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ export const getEtherscanKey = (): string => getEnv()['ETHERSCAN_KEY'] ?? '';
export const getEncPw = (): string => getEnv()['ENC_PW'] ?? null;

export const getPrng = (seed?: string) => {
// @ts-expect-error -- @types/seedrandom is inaccurate
return new seedrandom(seed ? seed : getSeed());
};
2 changes: 1 addition & 1 deletion src/__test__/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ export const validateDerivedPublicKeys = function (
// Otherwise this is a SECP256K1 pubkey
const priv = wallet.derivePath(getPathStr(path)).privateKey;
expect(pub.toString('hex')).toEqualElseLog(
secp256k1.keyFromPrivate(priv).getPublic().encode('hex'),
secp256k1.keyFromPrivate(priv).getPublic().encode('hex', false),
'Exported SECP256K1 pubkey incorrect',
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export class Client {
capabilities: this.activeWallets.external.capabilities,
},
},
ephemeralPub: this.ephemeralPub?.getPublic()?.encode('hex', true),
ephemeralPub: this.ephemeralPub?.getPublic()?.encode('hex', false),
fwVersion: this.fwVersion?.toString('hex'),
deviceId: this.deviceId,
name: this.name,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { KeyPair, ActiveWallets, FirmwareVersion } from '../types';
*/
export const getPubKeyBytes = (key: KeyPair, LE = false) => {
const k = key.getPublic();
const p = k.encode('hex', true);
const p = k.encode('hex', false);
const pb = Buffer.from(p, 'hex');
if (LE === true) {
// Need to flip X and Y components to little endian
Expand Down

0 comments on commit 95ea0d9

Please sign in to comment.