util-crypto: use the current @noble/hashes and @noble/curves APIs

The ranges ^1.3 resolve to @noble/curves 1.9 and @noble/hashes 1.8 for
everyone who installs this package, and those mark the calls used here
deprecated: the sha256/sha512/blake2b module paths, ProjectivePoint,
toRawBytes, px/py, Signature.fromCompact.

- hashes from @noble/hashes/sha2 and @noble/hashes/blake2
- secp256k1.Point with toBytes(true) for compression
- expand reads the affine x/y (toAffine) instead of the projective fields
- recover builds the signature with Signature.fromBytes(sig, 'compact') and
  returns toBytes() (compressed, as toRawBytes() did). Its method form of
  recoverPublicKey stays, with the reason on the line: the replacement is not
  in @noble/curves 1.9's types, and 2.x, which types it, is ESM-only.

The minimum versions rise with this (package.json, next commit).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Satoshi Qazi MuhammedandClaude Opus 5.5 authored and SatoshiQaziMuhammed committed 2026-10-07 19:21:45 +04:00
1 parent 6575789cfc
commit e9cccd2a04
7 files changed
+20 -17

No files matched your search

+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2025 @pezkuwi/util-crypto authors & contributors // Copyright 2017-2026 @pezkuwi/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { blake2b as blake2bJs } from '@noble/hashes/blake2b'; import { blake2b as blake2bJs } from '@noble/hashes/blake2';
import { hasBigInt, u8aToU8a } from '@pezkuwi/util'; import { hasBigInt, u8aToU8a } from '@pezkuwi/util';
import { blake2b, isReady } from '@pezkuwi/wasm-crypto'; import { blake2b, isReady } from '@pezkuwi/wasm-crypto';
+2 -3
View File
@@ -1,9 +1,8 @@
// Copyright 2017-2025 @pezkuwi/util-crypto authors & contributors // Copyright 2017-2026 @pezkuwi/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { hmac } from '@noble/hashes/hmac'; import { hmac } from '@noble/hashes/hmac';
import { sha256 } from '@noble/hashes/sha256'; import { sha256, sha512 } from '@noble/hashes/sha2';
import { sha512 } from '@noble/hashes/sha512';
import { hasBigInt, u8aToU8a } from '@pezkuwi/util'; import { hasBigInt, u8aToU8a } from '@pezkuwi/util';
import { hmacSha256, hmacSha512, isReady } from '@pezkuwi/wasm-crypto'; import { hmacSha256, hmacSha512, isReady } from '@pezkuwi/wasm-crypto';
+2 -2
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2025 @pezkuwi/util-crypto authors & contributors // Copyright 2017-2026 @pezkuwi/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { pbkdf2 as pbkdf2Js } from '@noble/hashes/pbkdf2'; import { pbkdf2 as pbkdf2Js } from '@noble/hashes/pbkdf2';
import { sha512 } from '@noble/hashes/sha512'; import { sha512 } from '@noble/hashes/sha2';
import { hasBigInt, u8aToU8a } from '@pezkuwi/util'; import { hasBigInt, u8aToU8a } from '@pezkuwi/util';
import { isReady, pbkdf2 } from '@pezkuwi/wasm-crypto'; import { isReady, pbkdf2 } from '@pezkuwi/wasm-crypto';
@@ -1,4 +1,4 @@
// Copyright 2017-2025 @pezkuwi/util-crypto authors & contributors // Copyright 2017-2026 @pezkuwi/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { secp256k1 } from '@noble/curves/secp256k1'; import { secp256k1 } from '@noble/curves/secp256k1';
@@ -17,5 +17,5 @@ export function secp256k1Compress (publicKey: Uint8Array, onlyJs?: boolean): Uin
return !hasBigInt || (!onlyJs && isReady()) return !hasBigInt || (!onlyJs && isReady())
? wasm(publicKey) ? wasm(publicKey)
: secp256k1.ProjectivePoint.fromHex(publicKey).toRawBytes(true); : secp256k1.Point.fromHex(publicKey).toBytes(true);
} }
+2 -2
View File
@@ -1,4 +1,4 @@
// Copyright 2017-2025 @pezkuwi/util-crypto authors & contributors // Copyright 2017-2026 @pezkuwi/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { secp256k1 } from '@noble/curves/secp256k1'; import { secp256k1 } from '@noble/curves/secp256k1';
@@ -21,7 +21,7 @@ export function secp256k1Expand (publicKey: Uint8Array, onlyJs?: boolean): Uint8
return wasm(publicKey).subarray(1); return wasm(publicKey).subarray(1);
} }
const { px, py } = secp256k1.ProjectivePoint.fromHex(publicKey); const { x: px, y: py } = secp256k1.Point.fromHex(publicKey).toAffine();
return u8aConcat( return u8aConcat(
bnToU8a(px, BN_BE_256_OPTS), bnToU8a(px, BN_BE_256_OPTS),
@@ -1,4 +1,4 @@
// Copyright 2017-2025 @pezkuwi/util-crypto authors & contributors // Copyright 2017-2026 @pezkuwi/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import type { HashType } from './types.js'; import type { HashType } from './types.js';
@@ -21,10 +21,15 @@ export function secp256k1Recover (msgHash: string | Uint8Array, signature: strin
const publicKey = !hasBigInt || (!onlyJs && isReady()) const publicKey = !hasBigInt || (!onlyJs && isReady())
? wasm(msg, sig, recovery) ? wasm(msg, sig, recovery)
: secp256k1.Signature : secp256k1.Signature
.fromCompact(sig) .fromBytes(sig, 'compact')
.addRecoveryBit(recovery) .addRecoveryBit(recovery)
// The replacement, secp256k1.recoverPublicKey(bytes, msg), exists at run
// time in @noble/curves 1.9 but not in its types (secp256k1 is still
// typed as the legacy CurveFn); 2.x has it typed but is ESM-only, which
// would break this package's CommonJS build. Kept until then.
// eslint-disable-next-line deprecation/deprecation
.recoverPublicKey(msg) .recoverPublicKey(msg)
.toRawBytes(); .toBytes();
if (!publicKey) { if (!publicKey) {
throw new Error('Unable to recover publicKey from signature'); throw new Error('Unable to recover publicKey from signature');
+2 -3
View File
@@ -1,8 +1,7 @@
// Copyright 2017-2025 @pezkuwi/util-crypto authors & contributors // Copyright 2017-2026 @pezkuwi/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
import { sha256 as sha256Js } from '@noble/hashes/sha256'; import { sha256 as sha256Js, sha512 as sha512Js } from '@noble/hashes/sha2';
import { sha512 as sha512Js } from '@noble/hashes/sha512';
import { sha256, sha512 } from '@pezkuwi/wasm-crypto'; import { sha256, sha512 } from '@pezkuwi/wasm-crypto';