Skip to content

Commit fca30ba

Browse files
committed
feat: use noble/curves ver 2
1 parent 9786e97 commit fca30ba

File tree

8 files changed

+32
-28
lines changed

8 files changed

+32
-28
lines changed

package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@
6161
"npm": ">=10.x"
6262
},
6363
"dependencies": {
64-
"@noble/curves": "^1.8.0"
64+
"@noble/curves": "^2.0.1"
6565
}
6666
}

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { concatBytes } from "@noble/curves/abstract/utils";
2-
import { secp256k1 } from "@noble/curves/secp256k1";
1+
import { concatBytes } from "@noble/curves/utils.js";
2+
import { secp256k1 } from "@noble/curves/secp256k1.js";
33

44
// eslint-disable-next-line @typescript-eslint/no-explicit-any, n/no-unsupported-features/node-builtins
55
const browserCrypto = globalThis.crypto || (globalThis as any).msCrypto || {};
@@ -179,8 +179,8 @@ export const sign = async function (privateKey: Uint8Array, msg: Uint8Array): Pr
179179
assert(isValidPrivateKey(privateKey), "Bad private key");
180180
assert(msg.length > 0, "Message should not be empty");
181181
assert(msg.length <= 32, "Message is too long");
182-
const sig = secp256k1.sign(msg, privateKey, { prehash: false });
183-
return sig.toDERRawBytes();
182+
const sig = secp256k1.sign(msg, privateKey, { prehash: false, format: "der" });
183+
return sig;
184184
};
185185

186186
export const verify = async function (publicKey: Uint8Array, msg: Uint8Array, sig: Uint8Array): Promise<null> {
@@ -193,7 +193,7 @@ export const verify = async function (publicKey: Uint8Array, msg: Uint8Array, si
193193
}
194194
assert(msg.length > 0, "Message should not be empty");
195195
assert(msg.length <= 32, "Message is too long");
196-
if (secp256k1.verify(sig, msg, publicKey, { prehash: false })) return null;
196+
if (secp256k1.verify(sig, msg, publicKey, { prehash: false, format: "der" })) return null;
197197
throw new Error("Bad signature");
198198
};
199199

test/derive.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable import/no-extraneous-dependencies */
2-
import { concatBytes, equalBytes } from "@noble/curves/abstract/utils";
2+
import { concatBytes, equalBytes } from "@noble/curves/utils.js";
33
import { beforeAll, beforeEach, describe, expect, it } from "vitest";
44

55
import * as ec from "../src/index";

test/encrypt_decrypt.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/* eslint-disable import/no-extraneous-dependencies */
2-
import { bytesToUtf8, concatBytes, equalBytes, hexToBytes } from "@noble/curves/abstract/utils";
2+
import { concatBytes, equalBytes, hexToBytes } from "@noble/curves/utils.js";
33
import { beforeEach, describe, expect, it } from "vitest";
44

55
import * as eccrypto from "../src/index";
66

7+
const bytesToUtf8 = (bytes: Uint8Array): string => {
8+
return new TextDecoder().decode(bytes);
9+
};
10+
711
describe("Functions: encrypt & decrypt", () => {
812
let ephemPublicKey: Uint8Array;
913
let encOpts: { ephemPrivateKey: Uint8Array; iv: Uint8Array };

test/getPublic.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable import/no-extraneous-dependencies */
2-
import { bytesToHex, hexToBytes } from "@noble/curves/abstract/utils";
2+
import { bytesToHex, hexToBytes } from "@noble/curves/utils.js";
33
import { beforeEach, describe, expect, it } from "vitest";
44

55
import * as ec from "../src/index";

test/getPublicCompressed.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable import/no-extraneous-dependencies */
2-
import { bytesToHex, hexToBytes } from "@noble/curves/abstract/utils";
2+
import { bytesToHex, hexToBytes } from "@noble/curves/utils.js";
33
import { beforeEach, describe, expect, it } from "vitest";
44

55
import * as ec from "../src/index";

test/sign_verify.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable import/no-extraneous-dependencies */
2-
import { bytesToHex, concatBytes, hexToBytes } from "@noble/curves/abstract/utils";
2+
import { bytesToHex, concatBytes, hexToBytes } from "@noble/curves/utils.js";
33
import { beforeEach, describe, expect, it } from "vitest";
44

55
import * as ec from "../src/index";

0 commit comments

Comments
 (0)