diff --git a/package.json b/package.json index 7be9b6aea2..3aeecbb52d 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "@changesets/changelog-github": "^0.4.8", "@changesets/cli": "^2.29.7", "@ethereumjs/rlp": "^5.0.2", - "@paulmillr/trusted-setups": "^0.1.2", + "@paulmillr/trusted-setups": "^0.3.0", "@pimlico/alto": "0.0.18", "@remix-run/node-fetch-server": "^0.12.0", "@size-limit/preset-big-lib": "^11.2.0", @@ -62,7 +62,7 @@ "bun": "^1.2.22", "ethers": "^6.15.0", "knip": "^5.64.0", - "micro-eth-signer": "^0.14.0", + "micro-eth-signer": "^0.18.1", "ox": "0.14.20", "permissionless": "^0.2.57", "prool": "~0.2.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f43ddf57c6..e3a8303bbe 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -107,8 +107,8 @@ importers: specifier: ^5.0.2 version: 5.0.2 '@paulmillr/trusted-setups': - specifier: ^0.1.2 - version: 0.1.2 + specifier: ^0.3.0 + version: 0.3.0 '@pimlico/alto': specifier: 0.0.18 version: 0.0.18(typescript@5.9.3) @@ -137,8 +137,8 @@ importers: specifier: ^5.64.0 version: 5.64.0(@types/node@24.5.2)(typescript@5.9.3) micro-eth-signer: - specifier: ^0.14.0 - version: 0.14.0 + specifier: ^0.18.1 + version: 0.18.1 ox: specifier: 0.14.20 version: 0.14.20(typescript@5.9.3)(zod@4.3.6) @@ -632,17 +632,17 @@ importers: src: dependencies: '@noble/curves': - specifier: 1.9.1 - version: 1.9.1 + specifier: 2.2.0 + version: 2.2.0 '@noble/hashes': - specifier: 1.8.0 - version: 1.8.0 + specifier: 2.2.0 + version: 2.2.0 '@scure/bip32': - specifier: 1.7.0 - version: 1.7.0 + specifier: 2.2.0 + version: 2.2.0 '@scure/bip39': - specifier: 1.6.0 - version: 1.6.0 + specifier: 2.2.0 + version: 2.2.0 abitype: specifier: 1.2.3 version: 1.2.3(typescript@5.9.3)(zod@4.3.6) @@ -1721,26 +1721,26 @@ packages: '@noble/curves@1.2.0': resolution: {integrity: sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==} - '@noble/curves@1.8.2': - resolution: {integrity: sha512-vnI7V6lFNe0tLAuJMu+2sX+FcL14TaCWy1qiczg1VwRmPrpQCdq5ESXQMqUc2tluRNf6irBXrWbl1mGN8uaU/g==} - engines: {node: ^14.21.3 || >=16} - '@noble/curves@1.9.1': resolution: {integrity: sha512-k11yZxZg+t+gWvBbIswW0yoJlu8cHOC7dhunwOzoWH/mXGBiYyR4YY6hAEK/3EUs4UpB8la1RfdRpeGsFHkWsA==} engines: {node: ^14.21.3 || >=16} + '@noble/curves@2.2.0': + resolution: {integrity: sha512-T/BoHgFXirb0ENSPBquzX0rcjXeM6Lo892a2jlYJkqk83LqZx0l1Of7DzlKJ6jkpvMrkHSnAcgb5JegL8SeIkQ==} + engines: {node: '>= 20.19.0'} + '@noble/hashes@1.3.2': resolution: {integrity: sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==} engines: {node: '>= 16'} - '@noble/hashes@1.7.2': - resolution: {integrity: sha512-biZ0NUSxyjLLqo6KxEJ1b+C2NAx0wtDoFvCaXHGgUkeHzf3Xc1xKumFKREuT7f7DARNZ/slvYUwFG6B0f2b6hQ==} - engines: {node: ^14.21.3 || >=16} - '@noble/hashes@1.8.0': resolution: {integrity: sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==} engines: {node: ^14.21.3 || >=16} + '@noble/hashes@2.2.0': + resolution: {integrity: sha512-IYqDGiTXab6FniAgnSdZwgWbomxpy9FtYvLKs7wCUs2a8RkITG+DFGO1DM9cr+E3/RgADRpFjrKVaJ1z6sjtEg==} + engines: {node: '>= 20.19.0'} + '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -2106,8 +2106,8 @@ packages: cpu: [x64] os: [win32] - '@paulmillr/trusted-setups@0.1.2': - resolution: {integrity: sha512-NKpT0G4Blj+Vp9lbfczb7iPJm3B4njpzX8NXiQs8G51N4CLndCvLqEvksFlTJbNLwl3iwsGZHSvJRdfhfOHLwQ==} + '@paulmillr/trusted-setups@0.3.0': + resolution: {integrity: sha512-j752FHV8nYS8xG7msHj0kkakeeh/gUgcJM48i0sDihMcbHK1bmP2ZeObqyausF1NhfkDYkx5t30yKAuLQIWXog==} '@pimlico/alto@0.0.18': resolution: {integrity: sha512-JIDEEYgdnkT7+wdxk0OBLSVwhm2CaLSbCw4474C9ZFmBggKBOByzaYCeIAJPb+Tag3WVBDXrXb2lYi2aRT9phQ==} @@ -2341,12 +2341,24 @@ packages: '@scure/base@1.2.5': resolution: {integrity: sha512-9rE6EOVeIQzt5TSu4v+K523F8u6DhBsoZWPGKlnCshhlDhy0kJzUX4V+tr2dWmzF1GdekvThABoEQBGBQI7xZw==} + '@scure/base@2.0.0': + resolution: {integrity: sha512-3E1kpuZginKkek01ovG8krQ0Z44E3DHPjc5S2rjJw9lZn3KSQOs8S7wqikF/AH7iRanHypj85uGyxk0XAyC37w==} + + '@scure/base@2.2.0': + resolution: {integrity: sha512-b8XEupJibegiXV+tDUseI8oLQc8ei3d/4Jkb2RpbHh3MfE054ov3uIz2dhFkB3FI8iwYkEh0gGCApkrYggkPNg==} + '@scure/bip32@1.7.0': resolution: {integrity: sha512-E4FFX/N3f4B80AKWp5dP6ow+flD1LQZo/w8UnLGYZO674jS6YnYeepycOOksv+vLPSpgN35wgKgy+ybfTb2SMw==} + '@scure/bip32@2.2.0': + resolution: {integrity: sha512-zFr7t2F+a9+5tB7QbarF2HQNYrgjCNaoLAupZdKkrFMYMozJf5zqH2WJCQibMzm1qQ0QogrxVGO3qXfQDYMaQg==} + '@scure/bip39@1.6.0': resolution: {integrity: sha512-+lF0BbLiJNwVlev4eKelw1WWLaiKXw7sSl8T6FvBlWkdX+94aGJ4o8XjUdlyhTCjd8c+B3KT3JfS8P0bLRNU6A==} + '@scure/bip39@2.2.0': + resolution: {integrity: sha512-T/Bj/YvYMNkIPq6EENO6/rcs2e7qTNuyoUXf0KBFDmp0ZDu0H2X4Lq6yC3i0c8PcWkov5EbW+yQZZbdMmk154A==} + '@sec-ant/readable-stream@0.4.1': resolution: {integrity: sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==} @@ -4612,11 +4624,13 @@ packages: resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==} engines: {node: '>= 8'} - micro-eth-signer@0.14.0: - resolution: {integrity: sha512-5PLLzHiVYPWClEvZIXXFu5yutzpadb73rnQCpUqIHu3No3coFuWQNfE5tkBQJ7djuLYl6aRLaS0MgWJYGoqiBw==} + micro-eth-signer@0.18.1: + resolution: {integrity: sha512-vXKhCZxrytpl+dXR9JeaE41ZVFndi7wCKc1Jd22smOMAeDErvRcXaTxhYUf1yQxis4n2kIdv/pH7iuf+5/cj+Q==} + engines: {node: '>= 20.19.0'} - micro-packed@0.7.2: - resolution: {integrity: sha512-HJ/u8+tMzgrJVAl6P/4l8KGjJSA3SCZaRb1m4wpbovNScCSmVOGUYbkkcoPPcknCHWPpRAdjy+yqXqyQWf+k8g==} + micro-packed@0.8.0: + resolution: {integrity: sha512-AKb8znIvg9sooythbXzyFeChEY0SkW0C6iXECpy/ls0e5BtwXO45J9wD9SLzBztnS4XmF/5kwZknsq+jyynd/A==} + engines: {node: '>= 20.19.0'} micromark-core-commonmark@2.0.2: resolution: {integrity: sha512-FKjQKbxd1cibWMM1P9N+H8TwlgGgSkWZMmfuVucLCHaYqeSvJ0hFeHsIa65pA2nYbes0f8LDHPMrd9X7Ujxg9w==} @@ -7597,20 +7611,20 @@ snapshots: dependencies: '@noble/hashes': 1.3.2 - '@noble/curves@1.8.2': - dependencies: - '@noble/hashes': 1.7.2 - '@noble/curves@1.9.1': dependencies: '@noble/hashes': 1.8.0 - '@noble/hashes@1.3.2': {} + '@noble/curves@2.2.0': + dependencies: + '@noble/hashes': 2.2.0 - '@noble/hashes@1.7.2': {} + '@noble/hashes@1.3.2': {} '@noble/hashes@1.8.0': {} + '@noble/hashes@2.2.0': {} + '@nodelib/fs.scandir@2.1.5': dependencies: '@nodelib/fs.stat': 2.0.5 @@ -7966,7 +7980,7 @@ snapshots: '@oxc-resolver/binding-win32-x64-msvc@11.8.3': optional: true - '@paulmillr/trusted-setups@0.1.2': {} + '@paulmillr/trusted-setups@0.3.0': {} '@pimlico/alto@0.0.18(typescript@5.9.3)': dependencies: @@ -8180,17 +8194,32 @@ snapshots: '@scure/base@1.2.5': {} + '@scure/base@2.0.0': {} + + '@scure/base@2.2.0': {} + '@scure/bip32@1.7.0': dependencies: '@noble/curves': 1.9.1 '@noble/hashes': 1.8.0 '@scure/base': 1.2.5 + '@scure/bip32@2.2.0': + dependencies: + '@noble/curves': 2.2.0 + '@noble/hashes': 2.2.0 + '@scure/base': 2.2.0 + '@scure/bip39@1.6.0': dependencies: '@noble/hashes': 1.8.0 '@scure/base': 1.2.5 + '@scure/bip39@2.2.0': + dependencies: + '@noble/hashes': 2.2.0 + '@scure/base': 2.2.0 + '@sec-ant/readable-stream@0.4.1': {} '@sentry-internal/tracing@7.119.2': @@ -10784,15 +10813,15 @@ snapshots: merge2@1.4.1: {} - micro-eth-signer@0.14.0: + micro-eth-signer@0.18.1: dependencies: - '@noble/curves': 1.8.2 - '@noble/hashes': 1.7.2 - micro-packed: 0.7.2 + '@noble/curves': 2.2.0 + '@noble/hashes': 2.2.0 + micro-packed: 0.8.0 - micro-packed@0.7.2: + micro-packed@0.8.0: dependencies: - '@scure/base': 1.2.5 + '@scure/base': 2.0.0 micromark-core-commonmark@2.0.2: dependencies: diff --git a/src/accounts/generatePrivateKey.ts b/src/accounts/generatePrivateKey.ts index f920e242b6..2ce5179ad7 100644 --- a/src/accounts/generatePrivateKey.ts +++ b/src/accounts/generatePrivateKey.ts @@ -1,4 +1,4 @@ -import { secp256k1 } from '@noble/curves/secp256k1' +import { secp256k1 } from '@noble/curves/secp256k1.js' import type { ErrorType } from '../errors/utils.js' import type { Hex } from '../types/misc.js' @@ -12,5 +12,5 @@ export type GeneratePrivateKeyErrorType = ToHexErrorType | ErrorType * @returns A randomly generated private key. */ export function generatePrivateKey(): Hex { - return toHex(secp256k1.utils.randomPrivateKey()) + return toHex(secp256k1.utils.randomSecretKey()) } diff --git a/src/accounts/privateKeyToAccount.ts b/src/accounts/privateKeyToAccount.ts index 479c228591..28a587aec5 100644 --- a/src/accounts/privateKeyToAccount.ts +++ b/src/accounts/privateKeyToAccount.ts @@ -1,6 +1,7 @@ -import { secp256k1 } from '@noble/curves/secp256k1' +import { secp256k1 } from '@noble/curves/secp256k1.js' import type { ErrorType } from '../errors/utils.js' import type { Hex } from '../types/misc.js' +import { hexToBytes } from '../utils/encoding/toBytes.js' import { type ToHexErrorType, toHex } from '../utils/encoding/toHex.js' import type { NonceManager } from '../utils/nonceManager.js' import { type ToAccountErrorType, toAccount } from './toAccount.js' @@ -45,7 +46,7 @@ export function privateKeyToAccount( options: PrivateKeyToAccountOptions = {}, ): PrivateKeyAccount { const { nonceManager } = options - const publicKey = toHex(secp256k1.getPublicKey(privateKey.slice(2), false)) + const publicKey = toHex(secp256k1.getPublicKey(hexToBytes(privateKey), false)) const address = publicKeyToAddress(publicKey) const account = toAccount({ diff --git a/src/accounts/utils/privateKeyToAddress.ts b/src/accounts/utils/privateKeyToAddress.ts index d98ef0faac..7a8806da4d 100644 --- a/src/accounts/utils/privateKeyToAddress.ts +++ b/src/accounts/utils/privateKeyToAddress.ts @@ -1,8 +1,9 @@ -import { secp256k1 } from '@noble/curves/secp256k1' +import { secp256k1 } from '@noble/curves/secp256k1.js' import type { Address } from 'abitype' import type { ErrorType } from '../../errors/utils.js' import type { Hex } from '../../types/misc.js' +import { hexToBytes } from '../../utils/encoding/toBytes.js' import { type BytesToHexErrorType, bytesToHex, @@ -26,7 +27,7 @@ export type PrivateKeyToAddressErrorType = */ export function privateKeyToAddress(privateKey: Hex): Address { const publicKey = bytesToHex( - secp256k1.getPublicKey(privateKey.slice(2), false), + secp256k1.getPublicKey(hexToBytes(privateKey), false), ) return publicKeyToAddress(publicKey) } diff --git a/src/accounts/utils/sign.ts b/src/accounts/utils/sign.ts index 2db237513e..b1592b5129 100644 --- a/src/accounts/utils/sign.ts +++ b/src/accounts/utils/sign.ts @@ -1,10 +1,9 @@ // TODO(v3): Convert to sync. -import { secp256k1 } from '@noble/curves/secp256k1' +import { secp256k1 } from '@noble/curves/secp256k1.js' import type { ErrorType } from '../../errors/utils.js' import type { ByteArray, Hex, Signature } from '../../types/misc.js' -import { type IsHexErrorType, isHex } from '../../utils/data/isHex.js' import { type HexToBytesErrorType, hexToBytes, @@ -30,18 +29,17 @@ export type SignReturnType = export type SignErrorType = | HexToBytesErrorType - | IsHexErrorType | NumberToHexErrorType | ErrorType -let extraEntropy: Hex | boolean = false +let extraEntropy: Uint8Array | boolean = false /** * Sets extra entropy for signing functions. */ export function setSignEntropy(entropy: true | Hex) { if (!entropy) throw new Error('must be a `true` or a hex value.') - extraEntropy = entropy + extraEntropy = typeof entropy === 'string' ? hexToBytes(entropy) : entropy } /** @@ -57,21 +55,25 @@ export async function sign({ privateKey, to = 'object', }: SignParameters): Promise> { - const { r, s, recovery } = secp256k1.sign( - hash.slice(2), - privateKey.slice(2), + const signatureBytes = secp256k1.sign( + hexToBytes(hash), + hexToBytes(privateKey), { + prehash: false, lowS: true, - extraEntropy: isHex(extraEntropy, { strict: false }) - ? hexToBytes(extraEntropy) - : extraEntropy, + extraEntropy, + format: 'recovered', }, ) + const nobleSignature = secp256k1.Signature.fromBytes( + signatureBytes, + 'recovered', + ) const signature = { - r: numberToHex(r, { size: 32 }), - s: numberToHex(s, { size: 32 }), - v: recovery ? 28n : 27n, - yParity: recovery, + r: numberToHex(nobleSignature.r, { size: 32 }), + s: numberToHex(nobleSignature.s, { size: 32 }), + v: nobleSignature.recovery ? 28n : 27n, + yParity: nobleSignature.recovery, } return (() => { if (to === 'bytes' || to === 'hex') diff --git a/src/accounts/wordlists.ts b/src/accounts/wordlists.ts index b0e484257d..438f011a95 100644 --- a/src/accounts/wordlists.ts +++ b/src/accounts/wordlists.ts @@ -1,11 +1,11 @@ // biome-ignore lint/performance/noBarrelFile: _ -export { wordlist as czech } from '@scure/bip39/wordlists/czech' -export { wordlist as english } from '@scure/bip39/wordlists/english' -export { wordlist as french } from '@scure/bip39/wordlists/french' -export { wordlist as italian } from '@scure/bip39/wordlists/italian' -export { wordlist as japanese } from '@scure/bip39/wordlists/japanese' -export { wordlist as korean } from '@scure/bip39/wordlists/korean' -export { wordlist as portuguese } from '@scure/bip39/wordlists/portuguese' -export { wordlist as simplifiedChinese } from '@scure/bip39/wordlists/simplified-chinese' -export { wordlist as spanish } from '@scure/bip39/wordlists/spanish' -export { wordlist as traditionalChinese } from '@scure/bip39/wordlists/traditional-chinese' +export { wordlist as czech } from '@scure/bip39/wordlists/czech.js' +export { wordlist as english } from '@scure/bip39/wordlists/english.js' +export { wordlist as french } from '@scure/bip39/wordlists/french.js' +export { wordlist as italian } from '@scure/bip39/wordlists/italian.js' +export { wordlist as japanese } from '@scure/bip39/wordlists/japanese.js' +export { wordlist as korean } from '@scure/bip39/wordlists/korean.js' +export { wordlist as portuguese } from '@scure/bip39/wordlists/portuguese.js' +export { wordlist as simplifiedChinese } from '@scure/bip39/wordlists/simplified-chinese.js' +export { wordlist as spanish } from '@scure/bip39/wordlists/spanish.js' +export { wordlist as traditionalChinese } from '@scure/bip39/wordlists/traditional-chinese.js' diff --git a/src/package.json b/src/package.json index 1e0b8166d5..6e7ba250b0 100644 --- a/src/package.json +++ b/src/package.json @@ -217,10 +217,10 @@ } }, "dependencies": { - "@noble/curves": "1.9.1", - "@noble/hashes": "1.8.0", - "@scure/bip32": "1.7.0", - "@scure/bip39": "1.6.0", + "@noble/curves": "2.2.0", + "@noble/hashes": "2.2.0", + "@scure/bip32": "2.2.0", + "@scure/bip39": "2.2.0", "abitype": "1.2.3", "isows": "1.0.7", "ox": "0.14.20", diff --git a/src/utils/hash/keccak256.ts b/src/utils/hash/keccak256.ts index abdb5733b3..e0fd4a08e5 100644 --- a/src/utils/hash/keccak256.ts +++ b/src/utils/hash/keccak256.ts @@ -1,4 +1,4 @@ -import { keccak_256 } from '@noble/hashes/sha3' +import { keccak_256 } from '@noble/hashes/sha3.js' import type { ErrorType } from '../../errors/utils.js' import type { ByteArray, Hex } from '../../types/misc.js' diff --git a/src/utils/hash/ripemd160.ts b/src/utils/hash/ripemd160.ts index 2bd482a08b..184bb8f375 100644 --- a/src/utils/hash/ripemd160.ts +++ b/src/utils/hash/ripemd160.ts @@ -1,4 +1,4 @@ -import { ripemd160 as noble_ripemd160 } from '@noble/hashes/ripemd160' +import { ripemd160 as noble_ripemd160 } from '@noble/hashes/legacy.js' import type { ErrorType } from '../../errors/utils.js' import type { ByteArray, Hex } from '../../types/misc.js' diff --git a/src/utils/hash/sha256.ts b/src/utils/hash/sha256.ts index cb63873066..be1d40c29b 100644 --- a/src/utils/hash/sha256.ts +++ b/src/utils/hash/sha256.ts @@ -1,4 +1,4 @@ -import { sha256 as noble_sha256 } from '@noble/hashes/sha256' +import { sha256 as noble_sha256 } from '@noble/hashes/sha2.js' import type { ErrorType } from '../../errors/utils.js' import type { ByteArray, Hex } from '../../types/misc.js' diff --git a/src/utils/signature/parseCompactSignature.ts b/src/utils/signature/parseCompactSignature.ts index 9cdc583440..a1cc305893 100644 --- a/src/utils/signature/parseCompactSignature.ts +++ b/src/utils/signature/parseCompactSignature.ts @@ -1,4 +1,4 @@ -import { secp256k1 } from '@noble/curves/secp256k1' +import { secp256k1 } from '@noble/curves/secp256k1.js' import type { ErrorType } from '../../errors/utils.js' import type { CompactSignature, Hex } from '../../types/misc.js' @@ -17,7 +17,10 @@ export type ParseCompactSignatureErrorType = NumberToHexErrorType | ErrorType * // { r: '0x...', yParityAndS: '0x...' } */ export function parseCompactSignature(signatureHex: Hex): CompactSignature { - const { r, s } = secp256k1.Signature.fromCompact(signatureHex.slice(2, 130)) + const { r, s } = secp256k1.Signature.fromHex( + signatureHex.slice(2, 130), + 'compact', + ) return { r: numberToHex(r, { size: 32 }), yParityAndS: numberToHex(s, { size: 32 }), diff --git a/src/utils/signature/parseSignature.ts b/src/utils/signature/parseSignature.ts index e342065aed..e9d9a9a37e 100644 --- a/src/utils/signature/parseSignature.ts +++ b/src/utils/signature/parseSignature.ts @@ -1,4 +1,4 @@ -import { secp256k1 } from '@noble/curves/secp256k1' +import { secp256k1 } from '@noble/curves/secp256k1.js' import type { ErrorType } from '../../errors/utils.js' import type { Hex, Signature } from '../../types/misc.js' @@ -20,7 +20,10 @@ export type ParseSignatureErrorType = NumberToHexErrorType | ErrorType * // { r: '0x...', s: '0x...', v: 28n } */ export function parseSignature(signatureHex: Hex) { - const { r, s } = secp256k1.Signature.fromCompact(signatureHex.slice(2, 130)) + const { r, s } = secp256k1.Signature.fromHex( + signatureHex.slice(2, 130), + 'compact', + ) const yParityOrV = Number(`0x${signatureHex.slice(130)}`) const [v, yParity] = (() => { if (yParityOrV === 0 || yParityOrV === 1) return [undefined, yParityOrV] diff --git a/src/utils/signature/recoverPublicKey.ts b/src/utils/signature/recoverPublicKey.ts index 36e4dba144..0b66bd4b18 100644 --- a/src/utils/signature/recoverPublicKey.ts +++ b/src/utils/signature/recoverPublicKey.ts @@ -7,6 +7,7 @@ import { hexToBigInt, hexToNumber, } from '../encoding/fromHex.js' +import { hexToBytes } from '../encoding/toBytes.js' import { toHex } from '../encoding/toHex.js' export type RecoverPublicKeyParameters = { @@ -27,17 +28,16 @@ export async function recoverPublicKey({ }: RecoverPublicKeyParameters): Promise { const hashHex = isHex(hash) ? hash : toHex(hash) - const { secp256k1 } = await import('@noble/curves/secp256k1') + const { secp256k1 } = await import('@noble/curves/secp256k1.js') const signature_ = (() => { // typeof signature: `Signature` if (typeof signature === 'object' && 'r' in signature && 's' in signature) { const { r, s, v, yParity } = signature const yParityOrV = Number(yParity ?? v)! const recoveryBit = toRecoveryBit(yParityOrV) - return new secp256k1.Signature( - hexToBigInt(r), - hexToBigInt(s), - ).addRecoveryBit(recoveryBit) + return new secp256k1.Signature(hexToBigInt(r), hexToBigInt(s)) + .addRecoveryBit(recoveryBit) + .toBytes('recovered') } // typeof signature: `Hex | ByteArray` @@ -45,14 +45,19 @@ export async function recoverPublicKey({ if (size(signatureHex) !== 65) throw new Error('invalid signature length') const yParityOrV = hexToNumber(`0x${signatureHex.slice(130)}`) const recoveryBit = toRecoveryBit(yParityOrV) - return secp256k1.Signature.fromCompact( + return secp256k1.Signature.fromHex( signatureHex.substring(2, 130), - ).addRecoveryBit(recoveryBit) + 'compact', + ) + .addRecoveryBit(recoveryBit) + .toBytes('recovered') })() - const publicKey = signature_ - .recoverPublicKey(hashHex.substring(2)) - .toHex(false) + const publicKey = secp256k1.Point.fromBytes( + secp256k1.recoverPublicKey(signature_, hexToBytes(hashHex), { + prehash: false, + }), + ).toHex(false) return `0x${publicKey}` } diff --git a/src/utils/signature/serializeCompactSignature.ts b/src/utils/signature/serializeCompactSignature.ts index 12c9a03c9b..a57fef25b8 100644 --- a/src/utils/signature/serializeCompactSignature.ts +++ b/src/utils/signature/serializeCompactSignature.ts @@ -1,4 +1,4 @@ -import { secp256k1 } from '@noble/curves/secp256k1' +import { secp256k1 } from '@noble/curves/secp256k1.js' import type { ErrorType } from '../../errors/utils.js' import type { CompactSignature, Hex } from '../../types/misc.js' import { type HexToBigIntErrorType, hexToBigInt } from '../encoding/fromHex.js' @@ -27,5 +27,5 @@ export function serializeCompactSignature({ return `0x${new secp256k1.Signature( hexToBigInt(r), hexToBigInt(yParityAndS), - ).toCompactHex()}` + ).toHex('compact')}` } diff --git a/src/utils/signature/serializeSignature.ts b/src/utils/signature/serializeSignature.ts index e090c6aea9..773abeaa1a 100644 --- a/src/utils/signature/serializeSignature.ts +++ b/src/utils/signature/serializeSignature.ts @@ -1,4 +1,4 @@ -import { secp256k1 } from '@noble/curves/secp256k1' +import { secp256k1 } from '@noble/curves/secp256k1.js' import type { ErrorType } from '../../errors/utils.js' import type { ByteArray, Hex, Signature } from '../../types/misc.js' @@ -50,7 +50,7 @@ export function serializeSignature({ const signature = `0x${new secp256k1.Signature( hexToBigInt(r), hexToBigInt(s), - ).toCompactHex()}${yParity_ === 0 ? '1b' : '1c'}` as const + ).toHex('compact')}${yParity_ === 0 ? '1b' : '1c'}` as const if (to === 'hex') return signature as SerializeSignatureReturnType return hexToBytes(signature) as SerializeSignatureReturnType diff --git a/test/src/kzg.ts b/test/src/kzg.ts index 5744a6d68e..1bc7f942a7 100644 --- a/test/src/kzg.ts +++ b/test/src/kzg.ts @@ -1,7 +1,8 @@ import { readFileSync } from 'node:fs' import { resolve } from 'node:path' -import { trustedSetup as fastSetup } from '@paulmillr/trusted-setups/fast.js' -import { KZG } from 'micro-eth-signer/kzg' +import { trustedSetup as fastSetup } from '@paulmillr/trusted-setups/fast-kzg.js' +// micro-eth-signer 0.18 moved KZG under its advanced export. +import { KZG } from 'micro-eth-signer/advanced/kzg.js' import { bytesToHex, defineKzg, hexToBytes } from '../../src/index.js' const k = new KZG(fastSetup)