Skip to content

Commit 33b17e1

Browse files
committed
use Buffer.compare instead bufferEqual
1 parent c0270e0 commit 33b17e1

File tree

4 files changed

+13
-55
lines changed

4 files changed

+13
-55
lines changed

package-lock.json

-38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@
4545
"@toruslabs/eslint-config-node": "^4.0.4",
4646
"@toruslabs/eslint-config-typescript": "^4.0.4",
4747
"@toruslabs/torus-scripts": "^7.0.4",
48-
"@types/buffer-equal": "^1.0.2",
4948
"@types/elliptic": "^6.4.18",
5049
"@vitest/browser": "^3.0.7",
5150
"@vitest/coverage-istanbul": "^3.0.7",
5251
"browserify": "^17.0.1",
53-
"buffer-equal": "^1.0.1",
5452
"eslint": "^9.21.0",
5553
"playwright": "^1.50.1",
5654
"typescript": "^5.7.3",

test/derive.spec.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable import/no-extraneous-dependencies */
2-
import bufferEqual from "buffer-equal";
32
import { beforeAll, beforeEach, describe, expect, it } from "vitest";
43

54
import * as eccrypto from "../src/index";
@@ -99,23 +98,23 @@ describe("Functions: derive & derivePadded", () => {
9998
});
10099

101100
it("should be equal: derive(privateKeyA, publicKeyB) == derive(privateKeyB, publicKeyA)", async () => {
102-
expect(bufferEqual(deriveBA, deriveAB)).toBe(true);
101+
expect(Buffer.compare(deriveBA, deriveAB)).toBe(0);
103102
});
104103

105104
it("should be equal: derive(privateKeyA, publicKeyB) == derivePadded(privateKeyA, publicKeyB)", async () => {
106-
expect(bufferEqual(deriveAB, derivePaddedAB)).toBe(true);
105+
expect(Buffer.compare(deriveAB, derivePaddedAB)).toBe(0);
107106
});
108107

109108
it("should be equal: derivePadded(privateKeyA, publicKeyB) == derivePadded(privateKeyB, publicKeyA)", async () => {
110-
expect(bufferEqual(derivePaddedBA, derivePaddedAB)).toBe(true);
109+
expect(Buffer.compare(derivePaddedBA, derivePaddedAB)).toBe(0);
111110
});
112111

113112
it("should be equal: derive(privateKeyA, compressedPublicKeyB) == derive(privateKeyB, compressedPublicKeyA)", async () => {
114-
expect(bufferEqual(deriveABUseCompressed, deriveBAUseCompressed)).toBe(true);
113+
expect(Buffer.compare(deriveABUseCompressed, deriveBAUseCompressed)).toBe(0);
115114
});
116115

117116
it("should be equal: derive(privateKeyA, compressedPublicKeyB) == derivePadded(privateKeyA, compressedPublicKeyB)", async () => {
118-
expect(bufferEqual(deriveABUseCompressed, derivePaddedAB)).toBe(true);
117+
expect(Buffer.compare(deriveABUseCompressed, derivePaddedAB)).toBe(0);
119118
});
120119
});
121120
});

test/encrypt&decrypt.spec.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable import/no-extraneous-dependencies */
2-
import bufferEqual from "buffer-equal";
32
import { beforeEach, describe, expect, it } from "vitest";
43

54
import * as eccrypto from "../src/index";
@@ -39,18 +38,18 @@ describe("Functions: encrypt & decrypt", () => {
3938

4039
it("should encrypt message when provided encryption options", async () => {
4140
const enc = await eccrypto.encrypt(publicKey, Buffer.from("test"), encOpts);
42-
expect(bufferEqual(enc.iv, iv)).toBe(true);
43-
expect(bufferEqual(enc.ephemPublicKey, ephemPublicKey)).toBe(true);
44-
expect(bufferEqual(enc.ciphertext, ciphertext)).toBe(true);
45-
expect(bufferEqual(enc.mac, mac)).toBe(true);
41+
expect(Buffer.compare(enc.iv, iv)).toBe(0);
42+
expect(Buffer.compare(enc.ephemPublicKey, ephemPublicKey)).toBe(0);
43+
expect(Buffer.compare(enc.ciphertext, ciphertext)).toBe(0);
44+
expect(Buffer.compare(enc.mac, mac)).toBe(0);
4645
});
4746

4847
it("should encrypt with compressed public key", async () => {
4948
const enc = await eccrypto.encrypt(publicKeyCompressed, Buffer.from("test"), encOpts);
50-
expect(bufferEqual(enc.iv, iv)).toBe(true);
51-
expect(bufferEqual(enc.ephemPublicKey, ephemPublicKey)).toBe(true);
52-
expect(bufferEqual(enc.ciphertext, ciphertext)).toBe(true);
53-
expect(bufferEqual(enc.mac, mac)).toBe(true);
49+
expect(Buffer.compare(enc.iv, iv)).toBe(0);
50+
expect(Buffer.compare(enc.ephemPublicKey, ephemPublicKey)).toBe(0);
51+
expect(Buffer.compare(enc.ciphertext, ciphertext)).toBe(0);
52+
expect(Buffer.compare(enc.mac, mac)).toBe(0);
5453
});
5554

5655
it("should throw 'Bad public key' on bad publicKey when encrypting", async () => {

0 commit comments

Comments
 (0)