UNPKG

@owlprotocol/contracts-account-abstraction

Version:

ERC4337 Account Abstraction support for deploying relevant smart contracts and interacting with UserOps.

17 lines (16 loc) 543 B
import { bytesToHex, numberToHex, hexToBigInt, concat } from "viem"; import { getRandomValues } from "crypto"; function getERC4337Nonce(parameters) { if (!parameters) { const key = bytesToHex(getRandomValues(new Uint8Array(24))); const nonce = numberToHex(0, { size: 8 }); return hexToBigInt(concat([key, nonce])); } else { const key = numberToHex(parameters.key, { size: 24 }); const nonce = numberToHex(parameters.nonce, { size: 8 }); return hexToBigInt(concat([key, nonce])); } } export { getERC4337Nonce };