Skip to content

Commit

Permalink
native: make test-only preimage check suck a bit less
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnerdhair committed Nov 9, 2021
1 parent a72bbcc commit 4c0bba0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/hdwallet-native/src/binance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe("NativeBinanceWallet", () => {
});

it("should only handle pubkeys returned from the BNB SDK if they are in amino format", async () => {
expect.assertions(6);
expect.assertions(5);
const original = bnbSdk.BncClient.prototype.transfer;
const mock = jest
.spyOn(bnbSdk.BncClient.prototype, "transfer")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class Node implements BIP32.Node, SecP256K1.ECDSARecoverableKey, SecP256K
readonly chainCode: Buffer & BIP32.ChainCode;
#publicKey: SecP256K1.CompressedPoint | undefined;

// When running tests, this will keep us aware of any codepaths that don't pass in the preimage
static requirePreimage = typeof expect === "function";

protected constructor(privateKey: Uint8Array, chainCode: Uint8Array) {
// We avoid handing the private key to any non-platform code -- including our type-checking machinery.
if (privateKey.length !== 32) throw new Error("bad private key length");
Expand Down Expand Up @@ -74,8 +77,7 @@ export class Node implements BIP32.Node, SecP256K1.ECDSARecoverableKey, SecP256K
counter === undefined || Uint32.assert(counter);
digestAlgorithm === null || Digest.AlgorithmName(32).assert(digestAlgorithm);

// When running tests, this will keep us aware of any codepaths that don't pass in the preimage
if (typeof expect === "function") expect(digestAlgorithm).not.toBeNull();
if (Node.requirePreimage && digestAlgorithm === null) throw TypeError("preimage required");

const msgOrDigest = digestAlgorithm === null ? checkType(ByteArray(32), msg) : Digest.Algorithms[digestAlgorithm](checkType(ByteArray(), msg));
const entropy = (counter === undefined ? undefined : Buffer.alloc(32));
Expand Down

0 comments on commit 4c0bba0

Please sign in to comment.