Skip to content

Commit 4ac3f8a

Browse files
feat: upgrade @noble/curves and @noble/hashes to v2
- @noble/curves ^1.8.1 → ^2.0.1, @noble/hashes ^1.7.1 → ^2.0.1 - Migrate import paths to .js suffixed subpaths (sha2.js, utils.js, secp256k1.js) - API: ProjectivePoint → Point, CURVE.n → Point.Fn.ORDER, randomPrivateKey → randomSecretKey, toRawBytes → toBytes
1 parent a0c2586 commit 4ac3f8a

4 files changed

Lines changed: 27 additions & 23 deletions

File tree

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"url": "https://github.com/forgesworn/range-proof.git"
3737
},
3838
"dependencies": {
39-
"@noble/curves": "^1.8.1",
40-
"@noble/hashes": "^1.7.1"
39+
"@noble/curves": "^2.0.1",
40+
"@noble/hashes": "^2.0.1"
4141
},
4242
"devDependencies": {
4343
"@semantic-release/changelog": "^6.0.3",

src/range-proof.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Pedersen Commitments + Range Proofs on secp256k1
22
// Proves "value is in [min, max]" without revealing the exact value.
33

4-
import { hexToBytes, utf8ToBytes } from '@noble/hashes/utils';
4+
import { hexToBytes, utf8ToBytes } from '@noble/hashes/utils.js';
55
import {
66
Point,
77
type ProjectivePoint,
@@ -18,7 +18,7 @@ import {
1818
import { ValidationError, CryptoError } from './errors.js';
1919

2020
function pointToBytes(p: ProjectivePoint): Uint8Array {
21-
return p.toRawBytes(true);
21+
return p.toBytes();
2222
}
2323

2424
const DOMAIN_BIT_PROOF = 'pedersen-bit-proof-v1';

src/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Shared secp256k1 utilities for range-proof.ts.
22

3-
import { secp256k1 } from '@noble/curves/secp256k1';
4-
import { sha256 } from '@noble/hashes/sha256';
5-
import { bytesToHex, hexToBytes, utf8ToBytes, concatBytes } from '@noble/hashes/utils';
3+
import { secp256k1 } from '@noble/curves/secp256k1.js';
4+
import { sha256 } from '@noble/hashes/sha2.js';
5+
import { bytesToHex, hexToBytes, utf8ToBytes, concatBytes } from '@noble/hashes/utils.js';
66
import { ValidationError, CryptoError } from './errors.js';
77

8-
export const Point = secp256k1.ProjectivePoint;
9-
export const N = secp256k1.CURVE.n;
8+
export const Point = secp256k1.Point;
9+
export const N = secp256k1.Point.Fn.ORDER;
1010
export type ProjectivePoint = typeof Point.BASE;
1111

1212
/** Constant-time comparison of two equal-length Uint8Arrays.
@@ -31,7 +31,7 @@ export function mod(a: bigint, m: bigint = N): bigint {
3131
export function randomScalar(): bigint {
3232
let s: bigint;
3333
do {
34-
const bytes = secp256k1.utils.randomPrivateKey();
34+
const bytes = secp256k1.utils.randomSecretKey();
3535
s = mod(BigInt('0x' + bytesToHex(bytes)));
3636
} while (s === 0n);
3737
return s;

0 commit comments

Comments
 (0)