Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
107 changes: 68 additions & 39 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/accounts/generatePrivateKey.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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())
}
5 changes: 3 additions & 2 deletions src/accounts/privateKeyToAccount.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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({
Expand Down
5 changes: 3 additions & 2 deletions src/accounts/utils/privateKeyToAddress.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
}
32 changes: 17 additions & 15 deletions src/accounts/utils/sign.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -30,18 +29,17 @@ export type SignReturnType<to extends To = 'object'> =

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
}

/**
Expand All @@ -57,21 +55,25 @@ export async function sign<to extends To = 'object'>({
privateKey,
to = 'object',
}: SignParameters<to>): Promise<SignReturnType<to>> {
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')
Expand Down
20 changes: 10 additions & 10 deletions src/accounts/wordlists.ts
Original file line number Diff line number Diff line change
@@ -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'
Loading
Loading