Détail du package

ox

wevm4.3mMIT0.8.3

Ethereum Standard Library

ethereum, standard, library, typescript

readme


<picture> <source media="(prefers-color-scheme: dark)" srcset="https://github.com/wevm/ox/blob/main/.github/ox-dark.svg"> ox logo </picture>

<picture> <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/ox?colorA=21262d&colorB=21262d&style=flat"> Version </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/l/ox?colorA=21262d&colorB=21262d&style=flat"> MIT License </picture> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/codecov/c/github/wevm/ox?colorA=21262d&colorB=21262d&style=flat"> Code coverage </picture>

Overview

Ox (⦻) is the foundation of robust Ethereum software written in TypeScript. It is an Ethereum Standard Library that provides a set of lightweight, performant, and type-safe TypeScript modules for Ethereum.

It offers core utilities & types for primitives such as: ABIs, Addresses, Blocks, Bytes, ECDSA, Hex, JSON-RPC, RLP, Signing & Signatures, Transaction Envelopes, and more.

As an unopinionated Standard Library, it is designed to be used by higher-level consumers (such as Viem, Tevm, or their alternatives) to provide their own opinionated interfaces, and/or when reaching for low-level primitives may be needed without buying into a Client Abstraction stack (Viem, Ethers, Web3.js, etc).

Documentation

Head to the documentation to read and learn more about Ox.

Example Usage

The example below demonstrates how to construct, sign, and broadcast a transaction envelope using Ox:

import { Provider, Secp256k1, TransactionEnvelopeEip1559, Value } from 'ox'

// 1. Construct a transaction envelope.
const envelope = TransactionEnvelopeEip1559.from({
  chainId: 1,
  gas: 21000n,
  nonce: 0n,
  maxFeePerGas: Value.fromGwei('10'),
  maxPriorityFeePerGas: Value.fromGwei('1'),
  to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
  value: Value.fromEther('1'),
})

// 2. Get the signing payload for the envelope.
const payload = TransactionEnvelopeEip1559.getSignPayload(envelope) 

// 3. Sign the payload with your private key using secp256k1.
const signature = Secp256k1.sign({ payload, privateKey: '0x...' })

// 4. Serialize the envelope with the signature.
const serialized = TransactionEnvelopeEip1559.serialize(envelope, { signature })

// 5. Broadcast the envelope to the network.
const provider = Provider.from(window.ethereum)
const hash = await provider.request({
  method: 'eth_sendRawTransaction',
  params: [serialized],
})

[!NOTE]
Ox's APIs are purposely stateless, unopinionated, and verbose. The example above can definitely be achieved in a few lines of code in a more concise manner, however, the goal is for higher-level abstractions (Viem, etc) built on top of Ox to handle this for you.

Community

Check out the following places for more Ox-related content:

Support

changelog

ox

0.8.3

Patch Changes

0.8.2

Patch Changes

  • 9fd0bf0 Thanks @jxom! - Added ECDH (Elliptic Curve Diffie-Hellman) shared secrets to P256, Secp256k1, and WebCryptoP256 modules. This enables secure key agreement between parties using elliptic curve cryptography for both secp256k1 and secp256r1 (P256) curves, with support for both @noble/curves (for P256 and Secp256k1) implementation and Web Crypto APIs (WebCryptoP256).

    • P256.getSharedSecret
    • Secp256k1.getSharedSecret
    • WebCryptoP256.getSharedSecret
  • 9fd0bf0 Thanks @jxom! - Added createKeyPair helper functions for Bls, P256, and Secp256k1 modules. These functions provide a convenient way to generate complete key pairs (private key + public key) in a single operation, simplifying key generation workflows and reducing the need for separate randomPrivateKey and getPublicKey calls.

  • 9fd0bf0 Thanks @jxom! - Added Ed25519 and X25519 modules. The Ed25519 module provides functionality for creating key pairs, signing messages, and verifying signatures using the Ed25519 signature scheme. The X25519 module enables Elliptic Curve Diffie-Hellman (ECDH) key agreement operations for secure shared secret derivation.

0.8.1

Patch Changes

  • 74e47c5 Thanks @jxom! - Added Keystore.toKey and Keystore.toKeyAsync to derive a key from a JSON Keystore using a password.

0.8.0

Minor Changes

  • 7fc1da0 Thanks @jxom! - Breaking(Keystore): Keystore derivation functions (e.g. Keystore.pbkdf2) now return a tuple of the key and derivation options, instead of an object with the key and options.

    import { Keystore } from 'ox'
    
    - const key = Keystore.pbkdf2({ password: 'testpassword' })
    + const [key, opts] = Keystore.pbkdf2({ password: 'testpassword' })
  • 7fc1da0 Thanks @jxom! - Breaking(Keystore): Keystore.decrypt function interface no longer requires an object as the second parameter, now it only requires the key itself.

    import { Keystore } from 'ox'
    
    const [key, opts] = Keystore.pbkdf2({ password: 'testpassword' })
    
    const encrypted = await Keystore.encrypt(secret, key, opts)
    
    + const decrypted = await Keystore.decrypt(encrypted, key)
  • 7fc1da0 Thanks @jxom! - Breaking(Keystore): Keystore.encrypt function interface has changed to require derivation options (opts).

    import { Keystore } from 'ox'
    
    const [key, opts] = Keystore.pbkdf2({ password: 'testpassword' })
    
    - const encrypted = await Keystore.encrypt(secret, key)
    + const encrypted = await Keystore.encrypt(secret, key, opts)

0.7.2

Patch Changes

0.7.1

Patch Changes

0.7.0

Minor Changes

  • 09f72cb Thanks @jxom! - Updated EIP-5792 APIs to the latest spec on RpcSchema.

Patch Changes

0.6.12

Patch Changes

0.6.11

Patch Changes

  • ba67f11 Thanks @jxom! - Enhanced handling of arbitrary Provider errors.

0.6.10

Patch Changes

  • #65 33712a5 Thanks @thomas779! - Added support for multiple credentialIds in WebAuthnP256.

  • 10e6449 Thanks @jxom! - Added case to fall back to cause.details for BaseError details.

0.6.9

Patch Changes

  • 6480607 Thanks @jxom! - Fixed AbiEvent.encode for zeroish arguments.

0.6.8

Patch Changes

0.6.7

Patch Changes

  • 076c6a2 Thanks @jxom! - Removed redundant pure annotation.

0.6.6

Patch Changes

0.6.5

Patch Changes

  • 0b5182f Thanks @jxom! - Fixed build process for typedef generation.

0.6.4

Patch Changes

  • 74ceae4 Thanks @jxom! - Fixed Provider.parseError behavior.

0.6.3

Patch Changes

  • ddaed51 Thanks @jxom! - Fixed parsing of Provider RPC errors.

0.6.2

Patch Changes

  • e541cec Thanks @jxom! - Modified fallback RPC Errors to RpcResponse.InternalError.

0.6.1

Patch Changes

  • 5d007ae Thanks @jxom! - Added RpcResponse.parseErrorObject and Provider.parseErrorObject.

0.6.0

Minor Changes

  • 94ec558 Thanks @jxom! - Added BlockOverrides & StateOverrides modules.

  • 94ec558 Thanks @jxom! - Added eth_simulateV1 to eth_ RPC schema.

0.5.0

Minor Changes

0.4.4

Patch Changes

  • #45 48b896f Thanks @deodad! - Ensured addresses are checksummed when creating SIWE messages

0.4.3

Patch Changes

  • c09d165 Thanks @jxom! - Added checksumAddress as an option to AbiParameters.{encode|decode}.

0.4.2

Patch Changes

  • #40 47e306d Thanks @jxom! - ox/erc6492: Added universal signature verification exports.

0.4.1

Patch Changes

0.4.0

Minor Changes

  • #35 4680b06 Thanks @gregfromstl! - Updated Signature.toHex to serialize the last byte as v instead of yParity for widened compatibility.

Patch Changes

  • 15f9863 Thanks @jxom! - Added assertion for ABI-encoding integer ranges.

  • 2e0d4af Thanks @jxom! - Added support for block identifiers.

0.3.1

Patch Changes

  • e4104cd Thanks @jxom! - Added extraEntropy option to Secp256k1.sign & P256.sign.

0.3.0

Minor Changes

  • 9ad0d2c Thanks @jxom! - Added extra entropy to signature generation.

0.2.2

Patch Changes

  • 4f40358 Thanks @jxom! - Tweaked RpcResponse and Provider errors to have optional parameters.

0.2.1

Patch Changes

  • 6e4b635 Thanks @jxom! - Derive EIP-712 Domain type if not provided in TypedData.serialize.

0.2.0

Minor Changes

  • 2f0fc9b Thanks @jxom! - Breaking: Removed .parseError property on functions. Use the .ErrorType property instead. Example

Patch Changes

  • af01579 Thanks @jxom! - Assert that EIP-712 domains are valid.

0.1.8

Patch Changes

  • #25 5da9efb Thanks @tmm! - Shimmed WebAuthnP256.createCredential for 1Password Firefox Add-on.

0.1.7

Patch Changes

0.1.6

Patch Changes

0.1.5

Patch Changes

  • 644b96a Thanks @jxom! - Added additional guard for result in Provider.from.

0.1.4

Patch Changes

  • 777fe42 Thanks @jxom! - Tweaked trimLeft to remove all leading zeros.

0.1.3

Patch Changes

  • 868d431 Thanks @jxom! - Added handling for odd-length hex values.

0.1.2

Patch Changes

0.1.1

Patch Changes

  • b7de4f2 Thanks @jxom! - Fixed RpcSchema inference on params.

0.1.0

Minor Changes