FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

13
node_modules/ox/_esm/core/Abi.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import * as abitype from 'abitype';
import * as internal from './internal/abi.js';
/** @internal */
export function format(abi) {
return abitype.formatAbi(abi);
}
/** @internal */
export function from(abi) {
if (internal.isSignatures(abi))
return abitype.parseAbi(abi);
return abi;
}
//# sourceMappingURL=Abi.js.map

1
node_modules/ox/_esm/core/Abi.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Abi.js","sourceRoot":"","sources":["../../core/Abi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAElC,OAAO,KAAK,QAAQ,MAAM,mBAAmB,CAAA;AA2C7C,gBAAgB;AAChB,MAAM,UAAU,MAAM,CAAC,GAA6B;IAClD,OAAO,OAAO,CAAC,SAAS,CAAC,GAAG,CAAU,CAAA;AACxC,CAAC;AA8FD,gBAAgB;AAChB,MAAM,UAAU,IAAI,CAAC,GAA4B;IAC/C,IAAI,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC;QAAE,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC5D,OAAO,GAAG,CAAA;AACZ,CAAC"}

87
node_modules/ox/_esm/core/AbiConstructor.js generated vendored Normal file
View File

@@ -0,0 +1,87 @@
import * as abitype from 'abitype';
import * as AbiItem from './AbiItem.js';
import * as AbiParameters from './AbiParameters.js';
import * as Hex from './Hex.js';
/** @internal */
export function decode(abiConstructor, options) {
const { bytecode } = options;
if (abiConstructor.inputs.length === 0)
return undefined;
const data = options.data.replace(bytecode, '0x');
return AbiParameters.decode(abiConstructor.inputs, data);
}
/**
* ABI-encodes the provided constructor input (`inputs`).
*
* @example
* ```ts twoslash
* import { AbiConstructor } from 'ox'
*
* const constructor = AbiConstructor.from('constructor(address, uint256)')
*
* const data = AbiConstructor.encode(constructor, {
* bytecode: '0x...',
* args: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 123n],
* })
* ```
*
* @example
* ### End-to-end
*
* Below is an end-to-end example of using `AbiConstructor.encode` to encode the constructor of a contract and deploy it.
*
* ```ts twoslash
* import 'ox/window'
* import { AbiConstructor, Hex } from 'ox'
*
* // 1. Instantiate the ABI Constructor.
* const constructor = AbiConstructor.from(
* 'constructor(address owner, uint256 amount)',
* )
*
* // 2. Encode the ABI Constructor.
* const data = AbiConstructor.encode(constructor, {
* bytecode: '0x...',
* args: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 123n],
* })
*
* // 3. Deploy the contract.
* const hash = await window.ethereum!.request({
* method: 'eth_sendTransaction',
* params: [{ data }],
* })
* ```
*
* :::note
*
* For simplicity, the above example uses `window.ethereum.request`, but you can use any
* type of JSON-RPC interface.
*
* :::
*
* @param abiConstructor - The ABI Constructor to encode.
* @param options - Encoding options.
* @returns The encoded constructor.
*/
export function encode(abiConstructor, options) {
const { bytecode, args } = options;
return Hex.concat(bytecode, abiConstructor.inputs?.length && args?.length
? AbiParameters.encode(abiConstructor.inputs, args)
: '0x');
}
/** @internal */
export function format(abiConstructor) {
return abitype.formatAbiItem(abiConstructor);
}
/** @internal */
export function from(abiConstructor) {
return AbiItem.from(abiConstructor);
}
/** @internal */
export function fromAbi(abi) {
const item = abi.find((item) => item.type === 'constructor');
if (!item)
throw new AbiItem.NotFoundError({ name: 'constructor' });
return item;
}
//# sourceMappingURL=AbiConstructor.js.map

1
node_modules/ox/_esm/core/AbiConstructor.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"AbiConstructor.js","sourceRoot":"","s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AAA;AACvD,CAAC;AAgDD,gBAAgB;AAChB,MAAM,UAAU,OAAO,CAAC,GAAiC;IACvD,MAAM,IAAI,GAAI,GAAe,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,CAAA;IACzE,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAA;IACnE,OAAO,IAAI,CAAA;AACb,CAAC"}

350
node_modules/ox/_esm/core/AbiError.js generated vendored Normal file
View File

@@ -0,0 +1,350 @@
import * as abitype from 'abitype';
import * as AbiItem from './AbiItem.js';
import * as AbiParameters from './AbiParameters.js';
import * as Hex from './Hex.js';
/** @internal */
export function decode(abiError, data, options = {}) {
if (Hex.size(data) < 4)
throw new AbiItem.InvalidSelectorSizeError({ data });
if (abiError.inputs.length === 0)
return undefined;
const values = AbiParameters.decode(abiError.inputs, Hex.slice(data, 4), options);
if (values && Object.keys(values).length === 1) {
if (Array.isArray(values))
return values[0];
return Object.values(values)[0];
}
return values;
}
/**
* ABI-encodes the provided error input (`inputs`), prefixed with the 4 byte error selector.
*
* @example
* ```ts twoslash
* import { AbiError } from 'ox'
*
* const error = AbiError.from(
* 'error InvalidSignature(uint r, uint s, uint8 yParity)'
* )
*
* const data = AbiError.encode( // [!code focus]
* error, // [!code focus]
* [1n, 2n, 0] // [!code focus]
* ) // [!code focus]
* // @log: '0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000010f2c'
* ```
*
* @example
* You can extract an ABI Error from a JSON ABI with {@link ox#AbiError.(fromAbi:function)}:
*
* ```ts twoslash
* // @noErrors
* import { Abi, AbiError } from 'ox'
*
* const abi = Abi.from([ // [!code hl]
* // ... // [!code hl]
* { // [!code hl]
* name: 'InvalidSignature', // [!code hl]
* type: 'error', // [!code hl]
* inputs: [ // [!code hl]
* { name: 'r', type: 'uint256' }, // [!code hl]
* { name: 's', type: 'uint256' }, // [!code hl]
* { name: 'yParity', type: 'uint8' }, // [!code hl]
* ], // [!code hl]
* }, // [!code hl]
* // ... // [!code hl]
* ]) // [!code hl]
* const error = AbiError.fromAbi(abi, 'InvalidSignature') // [!code hl]
*
* const data = AbiError.encode(
* error,
* ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
* )
* // @log: '0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000010f2c'
* ```
*
* @param abiError - ABI Error to encode
* @param args - Error arguments
* @returns ABI-encoded error name and arguments
*/
export function encode(abiError, ...args) {
const selector = getSelector(abiError);
const data = args.length > 0
? AbiParameters.encode(abiError.inputs, args[0])
: undefined;
return data ? Hex.concat(selector, data) : selector;
}
/**
* Formats an {@link ox#AbiError.AbiError} into a **Human Readable ABI Error**.
*
* @example
* ```ts twoslash
* import { AbiError } from 'ox'
*
* const formatted = AbiError.format({
* type: 'error',
* name: 'Example',
* inputs: [
* {
* name: 'spender',
* type: 'address',
* },
* {
* name: 'amount',
* type: 'uint256',
* },
* ],
* })
*
* formatted
* // ^?
*
*
* ```
*
* @param abiError - The ABI Error to format.
* @returns The formatted ABI Error.
*/
export function format(abiError) {
return abitype.formatAbiItem(abiError);
}
/**
* Parses an arbitrary **JSON ABI Error** or **Human Readable ABI Error** into a typed {@link ox#AbiError.AbiError}.
*
* @example
* ### JSON ABIs
*
* ```ts twoslash
* import { AbiError } from 'ox'
*
* const badSignatureVError = AbiError.from({
* inputs: [{ name: 'v', type: 'uint8' }],
* name: 'BadSignatureV',
* type: 'error',
* })
*
* badSignatureVError
* //^?
*
*
*
*
*
*
*
*
*
*
*
*
* ```
*
* @example
* ### Human Readable ABIs
*
* A Human Readable ABI can be parsed into a typed ABI object:
*
* ```ts twoslash
* import { AbiError } from 'ox'
*
* const badSignatureVError = AbiError.from(
* 'error BadSignatureV(uint8 v)' // [!code hl]
* )
*
* badSignatureVError
* //^?
*
*
*
*
*
*
*
*
*
*
*
*
*
* ```
*
* @example
* It is possible to specify `struct`s along with your definitions:
*
* ```ts twoslash
* import { AbiError } from 'ox'
*
* const badSignatureVError = AbiError.from([
* 'struct Signature { uint8 v; }', // [!code hl]
* 'error BadSignatureV(Signature signature)',
* ])
*
* badSignatureVError
* //^?
*
*
*
*
*
*
*
*
*
*
*
*
* ```
*
*
*
* @param abiError - The ABI Error to parse.
* @returns Typed ABI Error.
*/
export function from(abiError, options = {}) {
return AbiItem.from(abiError, options);
}
/**
* Extracts an {@link ox#AbiError.AbiError} from an {@link ox#Abi.Abi} given a name and optional arguments.
*
* @example
* ### Extracting by Name
*
* ABI Errors can be extracted by their name using the `name` option:
*
* ```ts twoslash
* import { Abi, AbiError } from 'ox'
*
* const abi = Abi.from([
* 'function foo()',
* 'error BadSignatureV(uint8 v)',
* 'function bar(string a) returns (uint256 x)',
* ])
*
* const item = AbiError.fromAbi(abi, 'BadSignatureV') // [!code focus]
* // ^?
*
*
*
*
*
*
* ```
*
* @example
* ### Extracting by Selector
*
* ABI Errors can be extract by their selector when {@link ox#Hex.Hex} is provided to `name`.
*
* ```ts twoslash
* import { Abi, AbiError } from 'ox'
*
* const abi = Abi.from([
* 'function foo()',
* 'error BadSignatureV(uint8 v)',
* 'function bar(string a) returns (uint256 x)',
* ])
* const item = AbiError.fromAbi(abi, '0x095ea7b3') // [!code focus]
* // ^?
*
*
*
*
*
*
*
*
*
* ```
*
* :::note
*
* Extracting via a hex selector is useful when extracting an ABI Error from JSON-RPC error data.
*
* :::
*
* @param abi - The ABI to extract from.
* @param name - The name (or selector) of the ABI item to extract.
* @param options - Extraction options.
* @returns The ABI item.
*/
export function fromAbi(abi, name, options) {
if (name === 'Error')
return solidityError;
if (name === 'Panic')
return solidityPanic;
if (Hex.validate(name, { strict: false })) {
const selector = Hex.slice(name, 0, 4);
if (selector === solidityErrorSelector)
return solidityError;
if (selector === solidityPanicSelector)
return solidityPanic;
}
const item = AbiItem.fromAbi(abi, name, options);
if (item.type !== 'error')
throw new AbiItem.NotFoundError({ name, type: 'error' });
return item;
}
/**
* Computes the [4-byte selector](https://solidity-by-example.org/function-selector/) for an {@link ox#AbiError.AbiError}.
*
* @example
* ```ts twoslash
* import { AbiError } from 'ox'
*
* const selector = AbiError.getSelector('error BadSignatureV(uint8 v)')
* // @log: '0x6352211e'
* ```
*
* @example
* ```ts twoslash
* import { AbiError } from 'ox'
*
* const selector = AbiError.getSelector({
* inputs: [{ name: 'v', type: 'uint8' }],
* name: 'BadSignatureV',
* type: 'error'
* })
* // @log: '0x6352211e'
* ```
*
* @param abiItem - The ABI item to compute the selector for.
* @returns The first 4 bytes of the {@link ox#Hash.(keccak256:function)} hash of the error signature.
*/
export function getSelector(abiItem) {
return AbiItem.getSelector(abiItem);
}
// https://docs.soliditylang.org/en/v0.8.16/control-structures.html#panic-via-assert-and-error-via-require
export const panicReasons = {
1: 'An `assert` condition failed.',
17: 'Arithmetic operation resulted in underflow or overflow.',
18: 'Division or modulo by zero (e.g. `5 / 0` or `23 % 0`).',
33: 'Attempted to convert to an invalid type.',
34: 'Attempted to access a storage byte array that is incorrectly encoded.',
49: 'Performed `.pop()` on an empty array',
50: 'Array index is out of bounds.',
65: 'Allocated too much memory or created an array which is too large.',
81: 'Attempted to call a zero-initialized variable of internal function type.',
};
export const solidityError = /*#__PURE__*/ from({
inputs: [
{
name: 'message',
type: 'string',
},
],
name: 'Error',
type: 'error',
});
export const solidityErrorSelector = '0x08c379a0';
export const solidityPanic = /*#__PURE__*/ from({
inputs: [
{
name: 'reason',
type: 'uint8',
},
],
name: 'Panic',
type: 'error',
});
export const solidityPanicSelector = '0x4e487b71';
//# sourceMappingURL=AbiError.js.map

1
node_modules/ox/_esm/core/AbiError.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"AbiError.js","sourceRoot":"","sources":["../../core/AbiError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO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AAC,CAAA;IACvD,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO;QACvB,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;IAC1D,OAAO,IAAa,CAAA;AACtB,CAAC;AA2BD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,WAAW,CAAC,OAA0B;IACpD,OAAO,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;AACrC,CAAC;AAMD,0GAA0G;AAC1G,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,CAAC,EAAE,+BAA+B;IAClC,EAAE,EAAE,yDAAyD;IAC7D,EAAE,EAAE,wDAAwD;IAC5D,EAAE,EAAE,0CAA0C;IAC9C,EAAE,EAAE,uEAAuE;IAC3E,EAAE,EAAE,sCAAsC;IAC1C,EAAE,EAAE,+BAA+B;IACnC,EAAE,EAAE,mEAAmE;IACvE,EAAE,EAAE,0EAA0E;CACrD,CAAA;AAE3B,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC,IAAI,CAAC;IAC9C,MAAM,EAAE;QACN;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,QAAQ;SACf;KACF;IACD,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,OAAO;CACd,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAA;AAEjD,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAC,IAAI,CAAC;IAC9C,MAAM,EAAE;QACN;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;SACd;KACF;IACD,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,OAAO;CACd,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAA"}

1020
node_modules/ox/_esm/core/AbiEvent.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

1
node_modules/ox/_esm/core/AbiEvent.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

535
node_modules/ox/_esm/core/AbiFunction.js generated vendored Normal file
View File

@@ -0,0 +1,535 @@
import * as abitype from 'abitype';
import * as AbiItem from './AbiItem.js';
import * as AbiParameters from './AbiParameters.js';
import * as Hex from './Hex.js';
/**
* ABI-decodes function arguments according to the ABI Item's input types (`inputs`).
*
* @example
* ```ts twoslash
* import { AbiFunction } from 'ox'
*
* const approve = AbiFunction.from('function approve(address, uint256)')
*
* const data = AbiFunction.encodeData(
* approve,
* ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
* )
* // '0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000010f2c'
*
* const input = AbiFunction.decodeData(approve, data) // [!code focus]
* // @log: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
* ```
*
* @param abiFunction - The ABI Item to decode.
* @param data - The data to decode.
*/
export function decodeData(abiFunction, data) {
const { overloads } = abiFunction;
if (Hex.size(data) < 4)
throw new AbiItem.InvalidSelectorSizeError({ data });
if (abiFunction.inputs.length === 0)
return undefined;
const item = overloads
? fromAbi([abiFunction, ...overloads], data)
: abiFunction;
if (Hex.size(data) <= 4)
return undefined;
return AbiParameters.decode(item.inputs, Hex.slice(data, 4));
}
/**
* ABI-decodes a function's result according to the ABI Item's output types (`outputs`).
*
* :::tip
*
* This function is typically used to decode contract function return values (e.g. the response of an `eth_call` or the `input` property of a Transaction).
*
* See the [End-to-end Example](#end-to-end).
*
* :::
*
* @example
* ```ts twoslash
* import { AbiFunction } from 'ox'
*
* const data = '0x000000000000000000000000000000000000000000000000000000000000002a'
*
* const totalSupply = AbiFunction.from('function totalSupply() returns (uint256)')
*
* const output = AbiFunction.decodeResult(totalSupply, data)
* // @log: 42n
* ```
*
* @example
* You can extract an ABI Function from a JSON ABI with {@link ox#AbiFunction.(fromAbi:function)}:
*
* ```ts twoslash
* // @noErrors
* import { Abi, AbiFunction } from 'ox'
*
* const data = '0x000000000000000000000000000000000000000000000000000000000000002a'
*
* const erc20Abi = Abi.from([...]) // [!code hl]
* const totalSupply = AbiFunction.fromAbi(erc20Abi, 'totalSupply') // [!code hl]
*
* const output = AbiFunction.decodeResult(totalSupply, data)
* // @log: 42n
* ```
*
* @example
* ### End-to-end
*
* Below is an end-to-end example of using `AbiFunction.decodeResult` to decode the result of a `balanceOf` contract call on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
*
* ```ts twoslash
* import 'ox/window'
* import { Abi, AbiFunction } from 'ox'
*
* // 1. Extract the Function from the Contract's ABI.
* const abi = Abi.from([
* // ...
* {
* name: 'balanceOf',
* type: 'function',
* inputs: [{ name: 'account', type: 'address' }],
* outputs: [{ name: 'balance', type: 'uint256' }],
* stateMutability: 'view',
* },
* // ...
* ])
* const balanceOf = AbiFunction.fromAbi(abi, 'balanceOf')
*
* // 2. Encode the Function Input.
* const data = AbiFunction.encodeData(
* balanceOf,
* ['0xd2135CfB216b74109775236E36d4b433F1DF507B']
* )
*
* // 3. Perform the Contract Call.
* const response = await window.ethereum!.request({
* method: 'eth_call',
* params: [
* {
* data,
* to: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
* },
* ],
* })
*
* // 4. Decode the Function Output. // [!code focus]
* const balance = AbiFunction.decodeResult(balanceOf, response) // [!code focus]
* // @log: 42n
* ```
*
* :::note
*
* For simplicity, the above example uses `window.ethereum.request`, but you can use any
* type of JSON-RPC interface.
*
* :::
*
* @param abiFunction - ABI Function to decode
* @param data - ABI-encoded function output
* @param options - Decoding options
* @returns Decoded function output
*/
export function decodeResult(abiFunction, data, options = {}) {
const values = AbiParameters.decode(abiFunction.outputs, data, options);
if (values && Object.keys(values).length === 0)
return undefined;
if (values && Object.keys(values).length === 1) {
if (Array.isArray(values))
return values[0];
return Object.values(values)[0];
}
return values;
}
/**
* ABI-encodes function arguments (`inputs`), prefixed with the 4 byte function selector.
*
* :::tip
*
* This function is typically used to encode a contract function and its arguments for contract calls (e.g. `data` parameter of an `eth_call` or `eth_sendTransaction`).
*
* See the [End-to-end Example](#end-to-end).
*
* :::
*
* @example
* ```ts twoslash
* import { AbiFunction } from 'ox'
*
* const approve = AbiFunction.from('function approve(address, uint256)')
*
* const data = AbiFunction.encodeData( // [!code focus]
* approve, // [!code focus]
* ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n] // [!code focus]
* ) // [!code focus]
* // @log: '0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000010f2c'
* ```
*
* @example
* You can extract an ABI Function from a JSON ABI with {@link ox#AbiFunction.(fromAbi:function)}:
*
* ```ts twoslash
* // @noErrors
* import { Abi, AbiFunction } from 'ox'
*
* const erc20Abi = Abi.from([...]) // [!code hl]
* const approve = AbiFunction.fromAbi(erc20Abi, 'approve') // [!code hl]
*
* const data = AbiFunction.encodeData(
* approve,
* ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
* )
* // @log: '0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000010f2c'
* ```
*
* @example
* ### End-to-end
*
* Below is an end-to-end example of using `AbiFunction.encodeData` to encode the input of a `balanceOf` contract call on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
*
* ```ts twoslash
* import 'ox/window'
* import { Abi, AbiFunction } from 'ox'
*
* // 1. Extract the Function from the Contract's ABI.
* const abi = Abi.from([
* // ...
* {
* name: 'balanceOf',
* type: 'function',
* inputs: [{ name: 'account', type: 'address' }],
* outputs: [{ name: 'balance', type: 'uint256' }],
* stateMutability: 'view',
* },
* // ...
* ])
* const balanceOf = AbiFunction.fromAbi(abi, 'balanceOf')
*
* // 2. Encode the Function Input. // [!code focus]
* const data = AbiFunction.encodeData( // [!code focus]
* balanceOf, // [!code focus]
* ['0xd2135CfB216b74109775236E36d4b433F1DF507B'] // [!code focus]
* ) // [!code focus]
*
* // 3. Perform the Contract Call.
* const response = await window.ethereum!.request({
* method: 'eth_call',
* params: [
* {
* data,
* to: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
* },
* ],
* })
*
* // 4. Decode the Function Output.
* const balance = AbiFunction.decodeResult(balanceOf, response)
* ```
*
* :::note
*
* For simplicity, the above example uses `window.ethereum.request`, but you can use any
* type of JSON-RPC interface.
*
* :::
*
* @param abiFunction - ABI Function to encode
* @param args - Function arguments
* @returns ABI-encoded function name and arguments
*/
export function encodeData(abiFunction, ...args) {
const { overloads } = abiFunction;
const item = overloads
? fromAbi([abiFunction, ...overloads], abiFunction.name, {
args: args[0],
})
: abiFunction;
const selector = getSelector(item);
const data = args.length > 0
? AbiParameters.encode(item.inputs, args[0])
: undefined;
return data ? Hex.concat(selector, data) : selector;
}
/**
* ABI-encodes a function's result (`outputs`).
*
* @example
* ```ts twoslash
* import { AbiFunction } from 'ox'
*
* const totalSupply = AbiFunction.from('function totalSupply() returns (uint256)')
* const output = AbiFunction.decodeResult(totalSupply, '0x000000000000000000000000000000000000000000000000000000000000002a')
* // 42n
*
* const data = AbiFunction.encodeResult(totalSupply, 42n) // [!code focus]
* // @log: '0x000000000000000000000000000000000000000000000000000000000000002a'
* ```
*
* @param abiFunction - The ABI item to encode the function output for.
* @param output - The function output to encode.
* @param options - Encoding options.
* @returns The encoded function output.
*/
export function encodeResult(abiFunction, output, options = {}) {
const { as = 'Array' } = options;
const values = (() => {
if (abiFunction.outputs.length === 1)
return [output];
if (Array.isArray(output))
return output;
if (as === 'Object')
return Object.values(output);
return [output];
})();
return AbiParameters.encode(abiFunction.outputs, values);
}
/**
* Formats an {@link ox#AbiFunction.AbiFunction} into a **Human Readable ABI Function**.
*
* @example
* ```ts twoslash
* import { AbiFunction } from 'ox'
*
* const formatted = AbiFunction.format({
* type: 'function',
* name: 'approve',
* stateMutability: 'nonpayable',
* inputs: [
* {
* name: 'spender',
* type: 'address',
* },
* {
* name: 'amount',
* type: 'uint256',
* },
* ],
* outputs: [{ type: 'bool' }],
* })
*
* formatted
* // ^?
*
*
* ```
*
* @param abiFunction - The ABI Function to format.
* @returns The formatted ABI Function.
*/
export function format(abiFunction) {
return abitype.formatAbiItem(abiFunction);
}
/**
* Parses an arbitrary **JSON ABI Function** or **Human Readable ABI Function** into a typed {@link ox#AbiFunction.AbiFunction}.
*
* @example
* ### JSON ABIs
*
* ```ts twoslash
* import { AbiFunction } from 'ox'
*
* const approve = AbiFunction.from({
* type: 'function',
* name: 'approve',
* stateMutability: 'nonpayable',
* inputs: [
* {
* name: 'spender',
* type: 'address',
* },
* {
* name: 'amount',
* type: 'uint256',
* },
* ],
* outputs: [{ type: 'bool' }],
* })
*
* approve
* //^?
*
*
*
*
*
*
*
*
*
*
*
*
* ```
*
* @example
* ### Human Readable ABIs
*
* A Human Readable ABI can be parsed into a typed ABI object:
*
* ```ts twoslash
* import { AbiFunction } from 'ox'
*
* const approve = AbiFunction.from(
* 'function approve(address spender, uint256 amount) returns (bool)' // [!code hl]
* )
*
* approve
* //^?
*
*
*
*
*
*
*
*
*
*
*
*
*
* ```
*
* @example
* It is possible to specify `struct`s along with your definitions:
*
* ```ts twoslash
* import { AbiFunction } from 'ox'
*
* const approve = AbiFunction.from([
* 'struct Foo { address spender; uint256 amount; }', // [!code hl]
* 'function approve(Foo foo) returns (bool)',
* ])
*
* approve
* //^?
*
*
*
*
*
*
*
*
*
*
*
*
* ```
*
*
*
* @param abiFunction - The ABI Function to parse.
* @returns Typed ABI Function.
*/
export function from(abiFunction, options = {}) {
return AbiItem.from(abiFunction, options);
}
/**
* Extracts an {@link ox#AbiFunction.AbiFunction} from an {@link ox#Abi.Abi} given a name and optional arguments.
*
* @example
* ### Extracting by Name
*
* ABI Functions can be extracted by their name using the `name` option:
*
* ```ts twoslash
* import { Abi, AbiFunction } from 'ox'
*
* const abi = Abi.from([
* 'function foo()',
* 'event Transfer(address owner, address to, uint256 tokenId)',
* 'function bar(string a) returns (uint256 x)',
* ])
*
* const item = AbiFunction.fromAbi(abi, 'foo') // [!code focus]
* // ^?
*
*
*
*
*
*
* ```
*
* @example
* ### Extracting by Selector
*
* ABI Functions can be extract by their selector when {@link ox#Hex.Hex} is provided to `name`.
*
* ```ts twoslash
* import { Abi, AbiFunction } from 'ox'
*
* const abi = Abi.from([
* 'function foo()',
* 'event Transfer(address owner, address to, uint256 tokenId)',
* 'function bar(string a) returns (uint256 x)',
* ])
* const item = AbiFunction.fromAbi(abi, '0x095ea7b3') // [!code focus]
* // ^?
*
*
*
*
*
*
*
*
*
* ```
*
* :::note
*
* Extracting via a hex selector is useful when extracting an ABI Function from an `eth_call` RPC response or
* from a Transaction `input`.
*
* :::
*
* @param abi - The ABI to extract from.
* @param name - The name (or selector) of the ABI item to extract.
* @param options - Extraction options.
* @returns The ABI item.
*/
export function fromAbi(abi, name, options) {
const item = AbiItem.fromAbi(abi, name, options);
if (item.type !== 'function')
throw new AbiItem.NotFoundError({ name, type: 'function' });
return item;
}
/**
* Computes the [4-byte selector](https://solidity-by-example.org/function-selector/) for an {@link ox#AbiFunction.AbiFunction}.
*
* Useful for computing function selectors for calldata.
*
* @example
* ```ts twoslash
* import { AbiFunction } from 'ox'
*
* const selector = AbiFunction.getSelector('function ownerOf(uint256 tokenId)')
* // @log: '0x6352211e'
* ```
*
* @example
* ```ts twoslash
* import { AbiFunction } from 'ox'
*
* const selector = AbiFunction.getSelector({
* inputs: [{ type: 'uint256' }],
* name: 'ownerOf',
* outputs: [],
* stateMutability: 'view',
* type: 'function'
* })
* // @log: '0x6352211e'
* ```
*
* @param abiItem - The ABI item to compute the selector for.
* @returns The first 4 bytes of the {@link ox#Hash.(keccak256:function)} hash of the function signature.
*/
export function getSelector(abiItem) {
return AbiItem.getSelector(abiItem);
}
//# sourceMappingURL=AbiFunction.js.map

1
node_modules/ox/_esm/core/AbiFunction.js.map generated vendored Normal file
View File

@@ -0,0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GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,OAAc,CAAC,CAAA;IACvD,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU;QAC1B,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAA;IAC7D,OAAO,IAAa,CAAA;AACtB,CAAC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,WAAW,CAAC,OAA6B;IACvD,OAAO,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;AACrC,CAAC"}

558
node_modules/ox/_esm/core/AbiItem.js generated vendored Normal file
View File

@@ -0,0 +1,558 @@
import * as abitype from 'abitype';
import * as Errors from './Errors.js';
import * as Hash from './Hash.js';
import * as Hex from './Hex.js';
import * as internal from './internal/abiItem.js';
/**
* Formats an {@link ox#AbiItem.AbiItem} into a **Human Readable ABI Item**.
*
* @example
* ```ts twoslash
* import { AbiItem } from 'ox'
*
* const formatted = AbiItem.format({
* type: 'function',
* name: 'approve',
* stateMutability: 'nonpayable',
* inputs: [
* {
* name: 'spender',
* type: 'address',
* },
* {
* name: 'amount',
* type: 'uint256',
* },
* ],
* outputs: [{ type: 'bool' }],
* })
*
* formatted
* // ^?
*
*
* ```
*
* @param abiItem - The ABI Item to format.
* @returns The formatted ABI Item .
*/
export function format(abiItem) {
return abitype.formatAbiItem(abiItem);
}
/**
* Parses an arbitrary **JSON ABI Item** or **Human Readable ABI Item** into a typed {@link ox#AbiItem.AbiItem}.
*
* @example
* ### JSON ABIs
*
* ```ts twoslash
* import { AbiItem } from 'ox'
*
* const abiItem = AbiItem.from({
* type: 'function',
* name: 'approve',
* stateMutability: 'nonpayable',
* inputs: [
* {
* name: 'spender',
* type: 'address',
* },
* {
* name: 'amount',
* type: 'uint256',
* },
* ],
* outputs: [{ type: 'bool' }],
* })
*
* abiItem
* //^?
*
*
*
*
*
*
*
*
*
*
*
*
* ```
*
* @example
* ### Human Readable ABIs
*
* A Human Readable ABI can be parsed into a typed ABI object:
*
* ```ts twoslash
* import { AbiItem } from 'ox'
*
* const abiItem = AbiItem.from(
* 'function approve(address spender, uint256 amount) returns (bool)' // [!code hl]
* )
*
* abiItem
* //^?
*
*
*
*
*
*
*
*
*
*
*
*
*
* ```
*
* @example
* It is possible to specify `struct`s along with your definitions:
*
* ```ts twoslash
* import { AbiItem } from 'ox'
*
* const abiItem = AbiItem.from([
* 'struct Foo { address spender; uint256 amount; }', // [!code hl]
* 'function approve(Foo foo) returns (bool)',
* ])
*
* abiItem
* //^?
*
*
*
*
*
*
*
*
*
*
*
*
* ```
*
*
*
* @param abiItem - The ABI Item to parse.
* @returns The typed ABI Item.
*/
export function from(abiItem, options = {}) {
const { prepare = true } = options;
const item = (() => {
if (Array.isArray(abiItem))
return abitype.parseAbiItem(abiItem);
if (typeof abiItem === 'string')
return abitype.parseAbiItem(abiItem);
return abiItem;
})();
return {
...item,
...(prepare ? { hash: getSignatureHash(item) } : {}),
};
}
/**
* Extracts an {@link ox#AbiItem.AbiItem} from an {@link ox#Abi.Abi} given a name and optional arguments.
*
* @example
* ABI Items can be extracted by their name using the `name` option:
*
* ```ts twoslash
* import { Abi, AbiItem } from 'ox'
*
* const abi = Abi.from([
* 'function foo()',
* 'event Transfer(address owner, address to, uint256 tokenId)',
* 'function bar(string a) returns (uint256 x)',
* ])
*
* const item = AbiItem.fromAbi(abi, 'Transfer') // [!code focus]
* // ^?
*
*
*
*
*
*
* ```
*
* @example
* ### Extracting by Selector
*
* ABI Items can be extract by their selector when {@link ox#Hex.Hex} is provided to `name`.
*
* ```ts twoslash
* import { Abi, AbiItem } from 'ox'
*
* const abi = Abi.from([
* 'function foo()',
* 'event Transfer(address owner, address to, uint256 tokenId)',
* 'function bar(string a) returns (uint256 x)',
* ])
* const item = AbiItem.fromAbi(abi, '0x095ea7b3') // [!code focus]
* // ^?
*
*
*
*
*
*
*
*
*
*
*
*
*
* ```
*
* :::note
*
* Extracting via a hex selector is useful when extracting an ABI Item from an `eth_call` RPC response,
* a Transaction `input`, or from Event Log `topics`.
*
* :::
*
* @param abi - The ABI to extract from.
* @param name - The name (or selector) of the ABI item to extract.
* @param options - Extraction options.
* @returns The ABI item.
*/
export function fromAbi(abi, name, options) {
const { args = [], prepare = true } = (options ??
{});
const isSelector = Hex.validate(name, { strict: false });
const abiItems = abi.filter((abiItem) => {
if (isSelector) {
if (abiItem.type === 'function' || abiItem.type === 'error')
return getSelector(abiItem) === Hex.slice(name, 0, 4);
if (abiItem.type === 'event')
return getSignatureHash(abiItem) === name;
return false;
}
return 'name' in abiItem && abiItem.name === name;
});
if (abiItems.length === 0)
throw new NotFoundError({ name: name });
if (abiItems.length === 1)
return {
...abiItems[0],
...(prepare ? { hash: getSignatureHash(abiItems[0]) } : {}),
};
let matchedAbiItem = undefined;
for (const abiItem of abiItems) {
if (!('inputs' in abiItem))
continue;
if (!args || args.length === 0) {
if (!abiItem.inputs || abiItem.inputs.length === 0)
return {
...abiItem,
...(prepare ? { hash: getSignatureHash(abiItem) } : {}),
};
continue;
}
if (!abiItem.inputs)
continue;
if (abiItem.inputs.length === 0)
continue;
if (abiItem.inputs.length !== args.length)
continue;
const matched = args.every((arg, index) => {
const abiParameter = 'inputs' in abiItem && abiItem.inputs[index];
if (!abiParameter)
return false;
return internal.isArgOfType(arg, abiParameter);
});
if (matched) {
// Check for ambiguity against already matched parameters (e.g. `address` vs `bytes20`).
if (matchedAbiItem &&
'inputs' in matchedAbiItem &&
matchedAbiItem.inputs) {
const ambiguousTypes = internal.getAmbiguousTypes(abiItem.inputs, matchedAbiItem.inputs, args);
if (ambiguousTypes)
throw new AmbiguityError({
abiItem,
type: ambiguousTypes[0],
}, {
abiItem: matchedAbiItem,
type: ambiguousTypes[1],
});
}
matchedAbiItem = abiItem;
}
}
const abiItem = (() => {
if (matchedAbiItem)
return matchedAbiItem;
const [abiItem, ...overloads] = abiItems;
return { ...abiItem, overloads };
})();
if (!abiItem)
throw new NotFoundError({ name: name });
return {
...abiItem,
...(prepare ? { hash: getSignatureHash(abiItem) } : {}),
};
}
/**
* Computes the [4-byte selector](https://solidity-by-example.org/function-selector/) for an {@link ox#AbiItem.AbiItem}.
*
* Useful for computing function selectors for calldata.
*
* @example
* ```ts twoslash
* import { AbiItem } from 'ox'
*
* const selector = AbiItem.getSelector('function ownerOf(uint256 tokenId)')
* // @log: '0x6352211e'
* ```
*
* @example
* ```ts twoslash
* import { AbiItem } from 'ox'
*
* const selector = AbiItem.getSelector({
* inputs: [{ type: 'uint256' }],
* name: 'ownerOf',
* outputs: [],
* stateMutability: 'view',
* type: 'function'
* })
* // @log: '0x6352211e'
* ```
*
* @param abiItem - The ABI item to compute the selector for. Can be a signature or an ABI item for an error, event, function, etc.
* @returns The first 4 bytes of the {@link ox#Hash.(keccak256:function)} hash of the function signature.
*/
export function getSelector(abiItem) {
return Hex.slice(getSignatureHash(abiItem), 0, 4);
}
/**
* Computes the stringified signature for a given {@link ox#AbiItem.AbiItem}.
*
* @example
* ```ts twoslash
* import { AbiItem } from 'ox'
*
* const signature = AbiItem.getSignature('function ownerOf(uint256 tokenId)')
* // @log: 'ownerOf(uint256)'
* ```
*
* @example
* ```ts twoslash
* import { AbiItem } from 'ox'
*
* const signature = AbiItem.getSignature({
* name: 'ownerOf',
* type: 'function',
* inputs: [{ name: 'tokenId', type: 'uint256' }],
* outputs: [],
* stateMutability: 'view',
* })
* // @log: 'ownerOf(uint256)'
* ```
*
* @param abiItem - The ABI Item to compute the signature for.
* @returns The stringified signature of the ABI Item.
*/
export function getSignature(abiItem) {
const signature = (() => {
if (typeof abiItem === 'string')
return abiItem;
return abitype.formatAbiItem(abiItem);
})();
return internal.normalizeSignature(signature);
}
/**
* Computes the signature hash for an {@link ox#AbiItem.AbiItem}.
*
* Useful for computing Event Topic values.
*
* @example
* ```ts twoslash
* import { AbiItem } from 'ox'
*
* const hash = AbiItem.getSignatureHash('event Transfer(address indexed from, address indexed to, uint256 amount)')
* // @log: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
* ```
*
* @example
* ```ts twoslash
* import { AbiItem } from 'ox'
*
* const hash = AbiItem.getSignatureHash({
* name: 'Transfer',
* type: 'event',
* inputs: [
* { name: 'from', type: 'address', indexed: true },
* { name: 'to', type: 'address', indexed: true },
* { name: 'amount', type: 'uint256', indexed: false },
* ],
* })
* // @log: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
* ```
*
* @param abiItem - The ABI Item to compute the signature hash for.
* @returns The {@link ox#Hash.(keccak256:function)} hash of the ABI item's signature.
*/
export function getSignatureHash(abiItem) {
if (typeof abiItem !== 'string' && 'hash' in abiItem && abiItem.hash)
return abiItem.hash;
return Hash.keccak256(Hex.fromString(getSignature(abiItem)));
}
/**
* Throws when ambiguous types are found on overloaded ABI items.
*
* @example
* ```ts twoslash
* import { Abi, AbiFunction } from 'ox'
*
* const foo = Abi.from(['function foo(address)', 'function foo(bytes20)'])
* AbiFunction.fromAbi(foo, 'foo', {
* args: ['0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'],
* })
* // @error: AbiItem.AmbiguityError: Found ambiguous types in overloaded ABI Items.
* // @error: `bytes20` in `foo(bytes20)`, and
* // @error: `address` in `foo(address)`
* // @error: These types encode differently and cannot be distinguished at runtime.
* // @error: Remove one of the ambiguous items in the ABI.
* ```
*
* ### Solution
*
* Remove one of the ambiguous types from the ABI.
*
* ```ts twoslash
* import { Abi, AbiFunction } from 'ox'
*
* const foo = Abi.from([
* 'function foo(address)',
* 'function foo(bytes20)' // [!code --]
* ])
* AbiFunction.fromAbi(foo, 'foo', {
* args: ['0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'],
* })
* // @error: AbiItem.AmbiguityError: Found ambiguous types in overloaded ABI Items.
* // @error: `bytes20` in `foo(bytes20)`, and
* // @error: `address` in `foo(address)`
* // @error: These types encode differently and cannot be distinguished at runtime.
* // @error: Remove one of the ambiguous items in the ABI.
* ```
*/
export class AmbiguityError extends Errors.BaseError {
constructor(x, y) {
super('Found ambiguous types in overloaded ABI Items.', {
metaMessages: [
// TODO: abitype to add support for signature-formatted ABI items.
`\`${x.type}\` in \`${internal.normalizeSignature(abitype.formatAbiItem(x.abiItem))}\`, and`,
`\`${y.type}\` in \`${internal.normalizeSignature(abitype.formatAbiItem(y.abiItem))}\``,
'',
'These types encode differently and cannot be distinguished at runtime.',
'Remove one of the ambiguous items in the ABI.',
],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'AbiItem.AmbiguityError'
});
}
}
/**
* Throws when an ABI item is not found in the ABI.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Abi, AbiFunction } from 'ox'
*
* const foo = Abi.from([
* 'function foo(address)',
* 'function bar(uint)'
* ])
* AbiFunction.fromAbi(foo, 'baz')
* // @error: AbiItem.NotFoundError: ABI function with name "baz" not found.
* ```
*
* ### Solution
*
* Ensure the ABI item exists on the ABI.
*
* ```ts twoslash
* // @noErrors
* import { Abi, AbiFunction } from 'ox'
*
* const foo = Abi.from([
* 'function foo(address)',
* 'function bar(uint)',
* 'function baz(bool)' // [!code ++]
* ])
* AbiFunction.fromAbi(foo, 'baz')
* ```
*/
export class NotFoundError extends Errors.BaseError {
constructor({ name, data, type = 'item', }) {
const selector = (() => {
if (name)
return ` with name "${name}"`;
if (data)
return ` with data "${data}"`;
return '';
})();
super(`ABI ${type}${selector} not found.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'AbiItem.NotFoundError'
});
}
}
/**
* Throws when the selector size is invalid.
*
* @example
* ```ts twoslash
* import { Abi, AbiFunction } from 'ox'
*
* const foo = Abi.from([
* 'function foo(address)',
* 'function bar(uint)'
* ])
* AbiFunction.fromAbi(foo, '0xaaa')
* // @error: AbiItem.InvalidSelectorSizeError: Selector size is invalid. Expected 4 bytes. Received 2 bytes ("0xaaa").
* ```
*
* ### Solution
*
* Ensure the selector size is 4 bytes.
*
* ```ts twoslash
* // @noErrors
* import { Abi, AbiFunction } from 'ox'
*
* const foo = Abi.from([
* 'function foo(address)',
* 'function bar(uint)'
* ])
* AbiFunction.fromAbi(foo, '0x7af82b1a')
* ```
*/
export class InvalidSelectorSizeError extends Errors.BaseError {
constructor({ data }) {
super(`Selector size is invalid. Expected 4 bytes. Received ${Hex.size(data)} bytes ("${data}").`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'AbiItem.InvalidSelectorSizeError'
});
}
}
//# sourceMappingURL=AbiItem.js.map

1
node_modules/ox/_esm/core/AbiItem.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

532
node_modules/ox/_esm/core/AbiParameters.js generated vendored Normal file
View File

@@ -0,0 +1,532 @@
import * as abitype from 'abitype';
import * as Address from './Address.js';
import * as Bytes from './Bytes.js';
import * as Errors from './Errors.js';
import * as Hex from './Hex.js';
import * as Solidity from './Solidity.js';
import * as internal from './internal/abiParameters.js';
import * as Cursor from './internal/cursor.js';
// eslint-disable-next-line jsdoc/require-jsdoc
export function decode(parameters, data, options = {}) {
const { as = 'Array', checksumAddress = false } = options;
const bytes = typeof data === 'string' ? Bytes.fromHex(data) : data;
const cursor = Cursor.create(bytes);
if (Bytes.size(bytes) === 0 && parameters.length > 0)
throw new ZeroDataError();
if (Bytes.size(bytes) && Bytes.size(bytes) < 32)
throw new DataSizeTooSmallError({
data: typeof data === 'string' ? data : Hex.fromBytes(data),
parameters: parameters,
size: Bytes.size(bytes),
});
let consumed = 0;
const values = as === 'Array' ? [] : {};
for (let i = 0; i < parameters.length; ++i) {
const param = parameters[i];
cursor.setPosition(consumed);
const [data, consumed_] = internal.decodeParameter(cursor, param, {
checksumAddress,
staticPosition: 0,
});
consumed += consumed_;
if (as === 'Array')
values.push(data);
else
values[param.name ?? i] = data;
}
return values;
}
/**
* Encodes primitive values into ABI encoded data as per the [Application Binary Interface (ABI) Specification](https://docs.soliditylang.org/en/latest/abi-spec).
*
* @example
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* const data = AbiParameters.encode(
* AbiParameters.from(['string', 'uint', 'bool']),
* ['wagmi', 420n, true],
* )
* ```
*
* @example
* ### JSON Parameters
*
* Specify **JSON ABI** Parameters as schema:
*
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* const data = AbiParameters.encode(
* [
* { type: 'string', name: 'name' },
* { type: 'uint', name: 'age' },
* { type: 'bool', name: 'isOwner' },
* ],
* ['wagmi', 420n, true],
* )
* ```
*
* @param parameters - The set of ABI parameters to encode, in the shape of the `inputs` or `outputs` attribute of an ABI Item. These parameters must include valid [ABI types](https://docs.soliditylang.org/en/latest/types.html).
* @param values - The set of primitive values that correspond to the ABI types defined in `parameters`.
* @returns ABI encoded data.
*/
export function encode(parameters, values, options) {
const { checksumAddress = false } = options ?? {};
if (parameters.length !== values.length)
throw new LengthMismatchError({
expectedLength: parameters.length,
givenLength: values.length,
});
// Prepare the parameters to determine dynamic types to encode.
const preparedParameters = internal.prepareParameters({
checksumAddress,
parameters: parameters,
values: values,
});
const data = internal.encode(preparedParameters);
if (data.length === 0)
return '0x';
return data;
}
/**
* Encodes an array of primitive values to a [packed ABI encoding](https://docs.soliditylang.org/en/latest/abi-spec.html#non-standard-packed-mode).
*
* @example
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* const encoded = AbiParameters.encodePacked(
* ['address', 'string'],
* ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 'hello world'],
* )
* // @log: '0xd8da6bf26964af9d7eed9e03e53415d37aa9604568656c6c6f20776f726c64'
* ```
*
* @param types - Set of ABI types to pack encode.
* @param values - The set of primitive values that correspond to the ABI types defined in `types`.
* @returns The encoded packed data.
*/
export function encodePacked(types, values) {
if (types.length !== values.length)
throw new LengthMismatchError({
expectedLength: types.length,
givenLength: values.length,
});
const data = [];
for (let i = 0; i < types.length; i++) {
const type = types[i];
const value = values[i];
data.push(encodePacked.encode(type, value));
}
return Hex.concat(...data);
}
(function (encodePacked) {
// eslint-disable-next-line jsdoc/require-jsdoc
function encode(type, value, isArray = false) {
if (type === 'address') {
const address = value;
Address.assert(address);
return Hex.padLeft(address.toLowerCase(), isArray ? 32 : 0);
}
if (type === 'string')
return Hex.fromString(value);
if (type === 'bytes')
return value;
if (type === 'bool')
return Hex.padLeft(Hex.fromBoolean(value), isArray ? 32 : 1);
const intMatch = type.match(Solidity.integerRegex);
if (intMatch) {
const [_type, baseType, bits = '256'] = intMatch;
const size = Number.parseInt(bits) / 8;
return Hex.fromNumber(value, {
size: isArray ? 32 : size,
signed: baseType === 'int',
});
}
const bytesMatch = type.match(Solidity.bytesRegex);
if (bytesMatch) {
const [_type, size] = bytesMatch;
if (Number.parseInt(size) !== (value.length - 2) / 2)
throw new BytesSizeMismatchError({
expectedSize: Number.parseInt(size),
value: value,
});
return Hex.padRight(value, isArray ? 32 : 0);
}
const arrayMatch = type.match(Solidity.arrayRegex);
if (arrayMatch && Array.isArray(value)) {
const [_type, childType] = arrayMatch;
const data = [];
for (let i = 0; i < value.length; i++) {
data.push(encode(childType, value[i], true));
}
if (data.length === 0)
return '0x';
return Hex.concat(...data);
}
throw new InvalidTypeError(type);
}
encodePacked.encode = encode;
})(encodePacked || (encodePacked = {}));
/**
* Formats {@link ox#AbiParameters.AbiParameters} into **Human Readable ABI Parameters**.
*
* @example
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* const formatted = AbiParameters.format([
* {
* name: 'spender',
* type: 'address',
* },
* {
* name: 'amount',
* type: 'uint256',
* },
* ])
*
* formatted
* // ^?
*
*
* ```
*
* @param parameters - The ABI Parameters to format.
* @returns The formatted ABI Parameters .
*/
export function format(parameters) {
return abitype.formatAbiParameters(parameters);
}
/**
* Parses arbitrary **JSON ABI Parameters** or **Human Readable ABI Parameters** into typed {@link ox#AbiParameters.AbiParameters}.
*
* @example
* ### JSON Parameters
*
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* const parameters = AbiParameters.from([
* {
* name: 'spender',
* type: 'address',
* },
* {
* name: 'amount',
* type: 'uint256',
* },
* ])
*
* parameters
* //^?
*
*
*
*
*
*
*
* ```
*
* @example
* ### Human Readable Parameters
*
* Human Readable ABI Parameters can be parsed into a typed {@link ox#AbiParameters.AbiParameters}:
*
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* const parameters = AbiParameters.from('address spender, uint256 amount')
*
* parameters
* //^?
*
*
*
*
*
*
*
* ```
*
* @example
* It is possible to specify `struct`s along with your definitions:
*
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* const parameters = AbiParameters.from([
* 'struct Foo { address spender; uint256 amount; }', // [!code hl]
* 'Foo foo, address bar',
* ])
*
* parameters
* //^?
*
*
*
*
*
*
*
*
*
*
*
*
* ```
*
*
*
* @param parameters - The ABI Parameters to parse.
* @returns The typed ABI Parameters.
*/
export function from(parameters) {
if (Array.isArray(parameters) && typeof parameters[0] === 'string')
return abitype.parseAbiParameters(parameters);
if (typeof parameters === 'string')
return abitype.parseAbiParameters(parameters);
return parameters;
}
/**
* Throws when the data size is too small for the given parameters.
*
* @example
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* AbiParameters.decode([{ type: 'uint256' }], '0x010f')
* // ↑ ❌ 2 bytes
* // @error: AbiParameters.DataSizeTooSmallError: Data size of 2 bytes is too small for given parameters.
* // @error: Params: (uint256)
* // @error: Data: 0x010f (2 bytes)
* ```
*
* ### Solution
*
* Pass a valid data size.
*
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* AbiParameters.decode([{ type: 'uint256' }], '0x00000000000000000000000000000000000000000000000000000000000010f')
* // ↑ ✅ 32 bytes
* ```
*/
export class DataSizeTooSmallError extends Errors.BaseError {
constructor({ data, parameters, size, }) {
super(`Data size of ${size} bytes is too small for given parameters.`, {
metaMessages: [
`Params: (${abitype.formatAbiParameters(parameters)})`,
`Data: ${data} (${size} bytes)`,
],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'AbiParameters.DataSizeTooSmallError'
});
}
}
/**
* Throws when zero data is provided, but data is expected.
*
* @example
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* AbiParameters.decode([{ type: 'uint256' }], '0x')
* // ↑ ❌ zero data
* // @error: AbiParameters.DataSizeTooSmallError: Data size of 2 bytes is too small for given parameters.
* // @error: Params: (uint256)
* // @error: Data: 0x010f (2 bytes)
* ```
*
* ### Solution
*
* Pass valid data.
*
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* AbiParameters.decode([{ type: 'uint256' }], '0x00000000000000000000000000000000000000000000000000000000000010f')
* // ↑ ✅ 32 bytes
* ```
*/
export class ZeroDataError extends Errors.BaseError {
constructor() {
super('Cannot decode zero data ("0x") with ABI parameters.');
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'AbiParameters.ZeroDataError'
});
}
}
/**
* The length of the array value does not match the length specified in the corresponding ABI parameter.
*
* ### Example
*
* ```ts twoslash
* // @noErrors
* import { AbiParameters } from 'ox'
* // ---cut---
* AbiParameters.encode(AbiParameters.from('uint256[3]'), [[69n, 420n]])
* // ↑ expected: 3 ↑ ❌ length: 2
* // @error: AbiParameters.ArrayLengthMismatchError: ABI encoding array length mismatch
* // @error: for type `uint256[3]`. Expected: `3`. Given: `2`.
* ```
*
* ### Solution
*
* Pass an array of the correct length.
*
* ```ts twoslash
* import { AbiParameters } from 'ox'
* // ---cut---
* AbiParameters.encode(AbiParameters.from(['uint256[3]']), [[69n, 420n, 69n]])
* // ↑ ✅ length: 3
* ```
*/
export class ArrayLengthMismatchError extends Errors.BaseError {
constructor({ expectedLength, givenLength, type, }) {
super(`Array length mismatch for type \`${type}\`. Expected: \`${expectedLength}\`. Given: \`${givenLength}\`.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'AbiParameters.ArrayLengthMismatchError'
});
}
}
/**
* The size of the bytes value does not match the size specified in the corresponding ABI parameter.
*
* ### Example
*
* ```ts twoslash
* // @noErrors
* import { AbiParameters } from 'ox'
* // ---cut---
* AbiParameters.encode(AbiParameters.from('bytes8'), [['0xdeadbeefdeadbeefdeadbeef']])
* // ↑ expected: 8 bytes ↑ ❌ size: 12 bytes
* // @error: BytesSizeMismatchError: Size of bytes "0xdeadbeefdeadbeefdeadbeef"
* // @error: (bytes12) does not match expected size (bytes8).
* ```
*
* ### Solution
*
* Pass a bytes value of the correct size.
*
* ```ts twoslash
* import { AbiParameters } from 'ox'
* // ---cut---
* AbiParameters.encode(AbiParameters.from(['bytes8']), ['0xdeadbeefdeadbeef'])
* // ↑ ✅ size: 8 bytes
* ```
*/
export class BytesSizeMismatchError extends Errors.BaseError {
constructor({ expectedSize, value, }) {
super(`Size of bytes "${value}" (bytes${Hex.size(value)}) does not match expected size (bytes${expectedSize}).`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'AbiParameters.BytesSizeMismatchError'
});
}
}
/**
* The length of the values to encode does not match the length of the ABI parameters.
*
* ### Example
*
* ```ts twoslash
* // @noErrors
* import { AbiParameters } from 'ox'
* // ---cut---
* AbiParameters.encode(AbiParameters.from(['string', 'uint256']), ['hello'])
* // @error: LengthMismatchError: ABI encoding params/values length mismatch.
* // @error: Expected length (params): 2
* // @error: Given length (values): 1
* ```
*
* ### Solution
*
* Pass the correct number of values to encode.
*
* ### Solution
*
* Pass a [valid ABI type](https://docs.soliditylang.org/en/develop/abi-spec.html#types).
*/
export class LengthMismatchError extends Errors.BaseError {
constructor({ expectedLength, givenLength, }) {
super([
'ABI encoding parameters/values length mismatch.',
`Expected length (parameters): ${expectedLength}`,
`Given length (values): ${givenLength}`,
].join('\n'));
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'AbiParameters.LengthMismatchError'
});
}
}
/**
* The value provided is not a valid array as specified in the corresponding ABI parameter.
*
* ### Example
*
* ```ts twoslash
* // @noErrors
* import { AbiParameters } from 'ox'
* // ---cut---
* AbiParameters.encode(AbiParameters.from(['uint256[3]']), [69])
* ```
*
* ### Solution
*
* Pass an array value.
*/
export class InvalidArrayError extends Errors.BaseError {
constructor(value) {
super(`Value \`${value}\` is not a valid array.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'AbiParameters.InvalidArrayError'
});
}
}
/**
* Throws when the ABI parameter type is invalid.
*
* @example
* ```ts twoslash
* import { AbiParameters } from 'ox'
*
* AbiParameters.decode([{ type: 'lol' }], '0x00000000000000000000000000000000000000000000000000000000000010f')
* // ↑ ❌ invalid type
* // @error: AbiParameters.InvalidTypeError: Type `lol` is not a valid ABI Type.
* ```
*/
export class InvalidTypeError extends Errors.BaseError {
constructor(type) {
super(`Type \`${type}\` is not a valid ABI Type.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'AbiParameters.InvalidTypeError'
});
}
}
//# sourceMappingURL=AbiParameters.js.map

1
node_modules/ox/_esm/core/AbiParameters.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

105
node_modules/ox/_esm/core/AccessList.js generated vendored Normal file
View File

@@ -0,0 +1,105 @@
import * as Address from './Address.js';
import * as Errors from './Errors.js';
import * as Hash from './Hash.js';
import * as Hex from './Hex.js';
/**
* Converts a list of Access List tuples into a object-formatted list.
*
* @example
* ```ts twoslash
* import { AccessList } from 'ox'
*
* const accessList = AccessList.fromTupleList([
* [
* '0x0000000000000000000000000000000000000000',
* [
* '0x0000000000000000000000000000000000000000000000000000000000000001',
* '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe',
* ],
* ],
* ])
* // @log: [
* // @log: {
* // @log: address: '0x0000000000000000000000000000000000000000',
* // @log: storageKeys: [
* // @log: '0x0000000000000000000000000000000000000000000000000000000000000001',
* // @log: '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe',
* // @log: ],
* // @log: },
* // @log: ]
* ```
*
* @param accessList - List of tuples.
* @returns Access list.
*/
export function fromTupleList(accessList) {
const list = [];
for (let i = 0; i < accessList.length; i++) {
const [address, storageKeys] = accessList[i];
if (address)
Address.assert(address, { strict: false });
list.push({
address: address,
storageKeys: storageKeys.map((key) => Hash.validate(key) ? key : Hex.trimLeft(key)),
});
}
return list;
}
/**
* Converts a structured Access List into a list of tuples.
*
* @example
* ```ts twoslash
* import { AccessList } from 'ox'
*
* const accessList = AccessList.toTupleList([
* {
* address: '0x0000000000000000000000000000000000000000',
* storageKeys: [
* '0x0000000000000000000000000000000000000000000000000000000000000001',
* '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe'],
* },
* ])
* // @log: [
* // @log: [
* // @log: '0x0000000000000000000000000000000000000000',
* // @log: [
* // @log: '0x0000000000000000000000000000000000000000000000000000000000000001',
* // @log: '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe',
* // @log: ],
* // @log: ],
* // @log: ]
* ```
*
* @param accessList - Access list.
* @returns List of tuples.
*/
export function toTupleList(accessList) {
if (!accessList || accessList.length === 0)
return [];
const tuple = [];
for (const { address, storageKeys } of accessList) {
for (let j = 0; j < storageKeys.length; j++)
if (Hex.size(storageKeys[j]) !== 32)
throw new InvalidStorageKeySizeError({
storageKey: storageKeys[j],
});
if (address)
Address.assert(address, { strict: false });
tuple.push([address, storageKeys]);
}
return tuple;
}
/** Thrown when the size of a storage key is invalid. */
export class InvalidStorageKeySizeError extends Errors.BaseError {
constructor({ storageKey }) {
super(`Size for storage key "${storageKey}" is invalid. Expected 32 bytes. Got ${Hex.size(storageKey)} bytes.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'AccessList.InvalidStorageKeySizeError'
});
}
}
//# sourceMappingURL=AccessList.js.map

1
node_modules/ox/_esm/core/AccessList.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"AccessList.js","sourceRoot":"","sources":["../../core/AccessList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO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E;YACzC,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,KAAK,EAAE;gBAClC,MAAM,IAAI,0BAA0B,CAAC;oBACnC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAE;iBAC5B,CAAC,CAAA;QAEN,IAAI,OAAO;YAAE,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;QAEvD,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAA;IACpC,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAED,wDAAwD;AACxD,MAAM,OAAO,0BAA2B,SAAQ,MAAM,CAAC,SAAS;IAE9D,YAAY,EAAE,UAAU,EAA2B;QACjD,KAAK,CACH,yBAAyB,UAAU,wCAAwC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CACzG,CAAA;QAJe;;;;mBAAO,uCAAuC;WAAA;IAKhE,CAAC;CACF"}

2
node_modules/ox/_esm/core/AccountProof.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=AccountProof.js.map

1
node_modules/ox/_esm/core/AccountProof.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"AccountProof.js","sourceRoot":"","sources":["../../core/AccountProof.ts"],"names":[],"mappings":""}

255
node_modules/ox/_esm/core/Address.js generated vendored Normal file
View File

@@ -0,0 +1,255 @@
import * as Bytes from './Bytes.js';
import * as Caches from './Caches.js';
import * as Errors from './Errors.js';
import * as Hash from './Hash.js';
import * as PublicKey from './PublicKey.js';
const addressRegex = /*#__PURE__*/ /^0x[a-fA-F0-9]{40}$/;
/**
* Asserts that the given value is a valid {@link ox#Address.Address}.
*
* @example
* ```ts twoslash
* import { Address } from 'ox'
*
* Address.assert('0xA0Cf798816D4b9b9866b5330EEa46a18382f251e')
* ```
*
* @example
* ```ts twoslash
* import { Address } from 'ox'
*
* Address.assert('0xdeadbeef')
* // @error: InvalidAddressError: Address "0xdeadbeef" is invalid.
* ```
*
* @param value - Value to assert if it is a valid address.
* @param options - Assertion options.
*/
export function assert(value, options = {}) {
const { strict = true } = options;
if (!addressRegex.test(value))
throw new InvalidAddressError({
address: value,
cause: new InvalidInputError(),
});
if (strict) {
if (value.toLowerCase() === value)
return;
if (checksum(value) !== value)
throw new InvalidAddressError({
address: value,
cause: new InvalidChecksumError(),
});
}
}
/**
* Computes the checksum address for the given {@link ox#Address.Address}.
*
* @example
* ```ts twoslash
* import { Address } from 'ox'
*
* Address.checksum('0xa0cf798816d4b9b9866b5330eea46a18382f251e')
* // @log: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'
* ```
*
* @param address - The address to compute the checksum for.
* @returns The checksummed address.
*/
export function checksum(address) {
if (Caches.checksum.has(address))
return Caches.checksum.get(address);
assert(address, { strict: false });
const hexAddress = address.substring(2).toLowerCase();
const hash = Hash.keccak256(Bytes.fromString(hexAddress), { as: 'Bytes' });
const characters = hexAddress.split('');
for (let i = 0; i < 40; i += 2) {
if (hash[i >> 1] >> 4 >= 8 && characters[i]) {
characters[i] = characters[i].toUpperCase();
}
if ((hash[i >> 1] & 0x0f) >= 8 && characters[i + 1]) {
characters[i + 1] = characters[i + 1].toUpperCase();
}
}
const result = `0x${characters.join('')}`;
Caches.checksum.set(address, result);
return result;
}
/**
* Converts a stringified address to a typed (checksummed) {@link ox#Address.Address}.
*
* @example
* ```ts twoslash
* import { Address } from 'ox'
*
* Address.from('0xa0cf798816d4b9b9866b5330eea46a18382f251e')
* // @log: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'
* ```
*
* @example
* ```ts twoslash
* import { Address } from 'ox'
*
* Address.from('0xa0cf798816d4b9b9866b5330eea46a18382f251e', {
* checksum: false
* })
* // @log: '0xa0cf798816d4b9b9866b5330eea46a18382f251e'
* ```
*
* @example
* ```ts twoslash
* import { Address } from 'ox'
*
* Address.from('hello')
* // @error: InvalidAddressError: Address "0xa" is invalid.
* ```
*
* @param address - An address string to convert to a typed Address.
* @param options - Conversion options.
* @returns The typed Address.
*/
export function from(address, options = {}) {
const { checksum: checksumVal = false } = options;
assert(address);
if (checksumVal)
return checksum(address);
return address;
}
/**
* Converts an ECDSA public key to an {@link ox#Address.Address}.
*
* @example
* ```ts twoslash
* import { Address, PublicKey } from 'ox'
*
* const publicKey = PublicKey.from(
* '0x048318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5',
* )
* const address = Address.fromPublicKey(publicKey)
* // @log: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
* ```
*
* @param publicKey - The ECDSA public key to convert to an {@link ox#Address.Address}.
* @param options - Conversion options.
* @returns The {@link ox#Address.Address} corresponding to the public key.
*/
export function fromPublicKey(publicKey, options = {}) {
const address = Hash.keccak256(`0x${PublicKey.toHex(publicKey).slice(4)}`).substring(26);
return from(`0x${address}`, options);
}
/**
* Checks if two {@link ox#Address.Address} are equal.
*
* @example
* ```ts twoslash
* import { Address } from 'ox'
*
* Address.isEqual(
* '0xa0cf798816d4b9b9866b5330eea46a18382f251e',
* '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'
* )
* // @log: true
* ```
*
* @example
* ```ts twoslash
* import { Address } from 'ox'
*
* Address.isEqual(
* '0xa0cf798816d4b9b9866b5330eea46a18382f251e',
* '0xA0Cf798816D4b9b9866b5330EEa46a18382f251f'
* )
* // @log: false
* ```
*
* @param addressA - The first address to compare.
* @param addressB - The second address to compare.
* @returns Whether the addresses are equal.
*/
export function isEqual(addressA, addressB) {
assert(addressA, { strict: false });
assert(addressB, { strict: false });
return addressA.toLowerCase() === addressB.toLowerCase();
}
/**
* Checks if the given address is a valid {@link ox#Address.Address}.
*
* @example
* ```ts twoslash
* import { Address } from 'ox'
*
* Address.validate('0xA0Cf798816D4b9b9866b5330EEa46a18382f251e')
* // @log: true
* ```
*
* @example
* ```ts twoslash
* import { Address } from 'ox'
*
* Address.validate('0xdeadbeef')
* // @log: false
* ```
*
* @param address - Value to check if it is a valid address.
* @param options - Check options.
* @returns Whether the address is a valid address.
*/
export function validate(address, options = {}) {
const { strict = true } = options ?? {};
try {
assert(address, { strict });
return true;
}
catch {
return false;
}
}
/**
* Thrown when an address is invalid.
*
* @example
* ```ts twoslash
* import { Address } from 'ox'
*
* Address.from('0x123')
* // @error: Address.InvalidAddressError: Address `0x123` is invalid.
* ```
*/
export class InvalidAddressError extends Errors.BaseError {
constructor({ address, cause }) {
super(`Address "${address}" is invalid.`, {
cause,
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Address.InvalidAddressError'
});
}
}
/** Thrown when an address is not a 20 byte (40 hexadecimal character) value. */
export class InvalidInputError extends Errors.BaseError {
constructor() {
super('Address is not a 20 byte (40 hexadecimal character) value.');
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Address.InvalidInputError'
});
}
}
/** Thrown when an address does not match its checksum counterpart. */
export class InvalidChecksumError extends Errors.BaseError {
constructor() {
super('Address does not match its checksum counterpart.');
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Address.InvalidChecksumError'
});
}
}
//# sourceMappingURL=Address.js.map

1
node_modules/ox/_esm/core/Address.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Address.js","sourceRoot":"","sources":["../../core/Address.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C,MAAM,YAAY,GAAG,aAAa,CAAC,qBAAqB,CAAA;AAKxD;;;;;;;;;;;;;;;;;;;;GAo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DAAkD,CAAC,CAAA;QAHzC;;;;mBAAO,8BAA8B;WAAA;IAIvD,CAAC;CACF"}

112
node_modules/ox/_esm/core/AesGcm.js generated vendored Normal file
View File

@@ -0,0 +1,112 @@
import * as Bytes from './Bytes.js';
import * as Hex from './Hex.js';
export const ivLength = 16;
/**
* Decrypts encrypted data using AES-GCM.
*
* @example
* ```ts twoslash
* import { AesGcm, Hex } from 'ox'
*
* const key = await AesGcm.getKey({ password: 'qwerty' })
* const secret = Hex.fromString('i am a secret message')
*
* const encrypted = await AesGcm.encrypt(secret, key)
*
* const decrypted = await AesGcm.decrypt(encrypted, key) // [!code focus]
* // @log: Hex.fromString('i am a secret message')
* ```
*
* @param value - The data to encrypt.
* @param key - The `CryptoKey` to use for encryption.
* @param options - Decryption options.
* @returns The decrypted data.
*/
export async function decrypt(value, key, options = {}) {
const { as = typeof value === 'string' ? 'Hex' : 'Bytes' } = options;
const encrypted = Bytes.from(value);
const iv = encrypted.slice(0, ivLength);
const data = encrypted.slice(ivLength);
const decrypted = await globalThis.crypto.subtle.decrypt({
name: 'AES-GCM',
iv,
}, key, Bytes.from(data));
const result = new Uint8Array(decrypted);
if (as === 'Bytes')
return result;
return Hex.from(result);
}
/**
* Encrypts data using AES-GCM.
*
* @example
* ```ts twoslash
* import { AesGcm, Hex } from 'ox'
*
* const key = await AesGcm.getKey({ password: 'qwerty' })
* const secret = Hex.fromString('i am a secret message')
*
* const encrypted = await AesGcm.encrypt(secret, key) // [!code focus]
* // @log: '0x5e257b25bcf53d5431e54e5a68ca0138306d31bb6154f35a97bb8ea18111e7d82bcf619d3c76c4650688bc5310eed80b8fc86d1e3e'
* ```
*
* @param value - The data to encrypt.
* @param key - The `CryptoKey` to use for encryption.
* @param options - Encryption options.
* @returns The encrypted data.
*/
export async function encrypt(value, key, options = {}) {
const { as = typeof value === 'string' ? 'Hex' : 'Bytes' } = options;
const iv = Bytes.random(ivLength);
const encrypted = await globalThis.crypto.subtle.encrypt({
name: 'AES-GCM',
iv,
}, key, Bytes.from(value));
const result = Bytes.concat(iv, new Uint8Array(encrypted));
if (as === 'Bytes')
return result;
return Hex.from(result);
}
/**
* Derives an AES-GCM key from a password using PBKDF2.
*
* @example
* ```ts twoslash
* import { AesGcm } from 'ox'
*
* const key = await AesGcm.getKey({ password: 'qwerty' })
* // @log: CryptoKey {}
* ```
*
* @param options - Options for key derivation.
* @returns The derived key.
*/
export async function getKey(options) {
const { iterations = 900_000, password, salt = randomSalt(32) } = options;
const baseKey = await globalThis.crypto.subtle.importKey('raw', Bytes.fromString(password), { name: 'PBKDF2' }, false, ['deriveBits', 'deriveKey']);
const key = await globalThis.crypto.subtle.deriveKey({
name: 'PBKDF2',
salt,
iterations,
hash: 'SHA-256',
}, baseKey, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
return key;
}
/**
* Generates a random salt of the specified size.
*
* @example
* ```ts twoslash
* import { AesGcm } from 'ox'
*
* const salt = AesGcm.randomSalt()
* // @log: Uint8Array [123, 79, 183, 167, 163, 136, 136, 16, 168, 126, 13, 165, 170, 166, 136, 136, 16, 168, 126, 13, 165, 170, 166, 136, 136, 16, 168, 126, 13, 165, 170, 166]
* ```
*
* @param size - The size of the salt to generate. Defaults to `32`.
* @returns A random salt of the specified size.
*/
export function randomSalt(size = 32) {
return Bytes.random(size);
}
//# sourceMappingURL=AesGcm.js.map

1
node_modules/ox/_esm/core/AesGcm.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"AesGcm.js","sourceRoot":"","sources":["../../core/AesGcm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAE/B,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAA;AAE1B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAM3B,KAAoC,EACpC,GAAc,EACd,UAA+B,EAAE;IAE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AAC,EAAE,EAAE,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC,CAAA;IAC1D,IAAI,EAAE,KAAK,OAAO;QAAE,OAAO,MAAe,CAAA;IAC1C,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,CAAU,CAAA;AAClC,CAAC;AAoBD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAuB;IAClD,MAAM,EAAE,UAAU,GAAG,OAAO,EAAE,QAAQ,EAAE,IAAI,GAAG,UAAU,CAAC,EAAE,CAAC,EAAE,GAAG,OAAO,CAAA;IACzE,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CACtD,KAAK,EACL,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,EAC1B,EAAE,IAAI,EAAE,QAAQ,EAAE,EAClB,KAAK,EACL,CAAC,YAAY,EAAE,WAAW,CAAC,CAC5B,CAAA;IACD,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAClD;QACE,IAAI,EAAE,QAAQ;QACd,IAAI;QACJ,UAAU;QACV,IAAI,EAAE,SAAS;KAChB,EACD,OAAO,EACP,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,EAChC,KAAK,EACL,CAAC,SAAS,EAAE,SAAS,CAAC,CACvB,CAAA;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAeD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CAAC,IAAI,GAAG,EAAE;IAClC,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAC3B,CAAC"}

408
node_modules/ox/_esm/core/Authorization.js generated vendored Normal file
View File

@@ -0,0 +1,408 @@
import * as Hash from './Hash.js';
import * as Hex from './Hex.js';
import * as Rlp from './Rlp.js';
import * as Signature from './Signature.js';
/**
* Converts an [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) Authorization object into a typed {@link ox#Authorization.Authorization}.
*
* @example
* An Authorization can be instantiated from an [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) Authorization tuple in object format.
*
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorization = Authorization.from({
* address: '0x1234567890abcdef1234567890abcdef12345678',
* chainId: 1,
* nonce: 69n,
* })
* ```
*
* @example
* ### Attaching Signatures
*
* A {@link ox#Signature.Signature} can be attached with the `signature` option. The example below demonstrates signing
* an Authorization with {@link ox#Secp256k1.(sign:function)}.
*
* ```ts twoslash
* import { Authorization, Secp256k1 } from 'ox'
*
* const authorization = Authorization.from({
* address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
* chainId: 1,
* nonce: 40n,
* })
*
* const signature = Secp256k1.sign({
* payload: Authorization.getSignPayload(authorization),
* privateKey: '0x...',
* })
*
* const authorization_signed = Authorization.from(authorization, { signature }) // [!code focus]
* ```
*
* @param authorization - An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) Authorization tuple in object format.
* @param options - Authorization options.
* @returns The {@link ox#Authorization.Authorization}.
*/
export function from(authorization, options = {}) {
if (typeof authorization.chainId === 'string')
return fromRpc(authorization);
return { ...authorization, ...options.signature };
}
/**
* Converts an {@link ox#Authorization.Rpc} to an {@link ox#Authorization.Authorization}.
*
* @example
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorization = Authorization.fromRpc({
* address: '0x0000000000000000000000000000000000000000',
* chainId: '0x1',
* nonce: '0x1',
* r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
* s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
* yParity: '0x0',
* })
* ```
*
* @param authorization - The RPC-formatted Authorization.
* @returns A signed {@link ox#Authorization.Authorization}.
*/
export function fromRpc(authorization) {
const { address, chainId, nonce } = authorization;
const signature = Signature.extract(authorization);
return {
address,
chainId: Number(chainId),
nonce: BigInt(nonce),
...signature,
};
}
/**
* Converts an {@link ox#Authorization.ListRpc} to an {@link ox#Authorization.List}.
*
* @example
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorizationList = Authorization.fromRpcList([{
* address: '0x0000000000000000000000000000000000000000',
* chainId: '0x1',
* nonce: '0x1',
* r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
* s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
* yParity: '0x0',
* }])
* ```
*
* @param authorizationList - The RPC-formatted Authorization list.
* @returns A signed {@link ox#Authorization.List}.
*/
export function fromRpcList(authorizationList) {
return authorizationList.map(fromRpc);
}
/**
* Converts an {@link ox#Authorization.Tuple} to an {@link ox#Authorization.Authorization}.
*
* @example
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorization = Authorization.fromTuple([
* '0x1',
* '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
* '0x3'
* ])
* // @log: {
* // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
* // @log: chainId: 1,
* // @log: nonce: 3n
* // @log: }
* ```
*
* @example
* It is also possible to append a Signature tuple to the end of an Authorization tuple.
*
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorization = Authorization.fromTuple([
* '0x1',
* '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
* '0x3',
* '0x1',
* '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
* '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
* ])
* // @log: {
* // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
* // @log: chainId: 1,
* // @log: nonce: 3n
* // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'),
* // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'),
* // @log: yParity: 0,
* // @log: }
* ```
*
* @param tuple - The [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) Authorization tuple.
* @returns The {@link ox#Authorization.Authorization}.
*/
export function fromTuple(tuple) {
const [chainId, address, nonce, yParity, r, s] = tuple;
const signature = yParity && r && s ? Signature.fromTuple([yParity, r, s]) : undefined;
return from({
address,
chainId: Number(chainId),
nonce: BigInt(nonce),
...signature,
});
}
/**
* Converts an {@link ox#Authorization.TupleList} to an {@link ox#Authorization.List}.
*
* @example
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorizationList = Authorization.fromTupleList([
* ['0x1', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x3'],
* ['0x3', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x14'],
* ])
* // @log: [
* // @log: {
* // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
* // @log: chainId: 1,
* // @log: nonce: 3n,
* // @log: },
* // @log: {
* // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
* // @log: chainId: 3,
* // @log: nonce: 20n,
* // @log: },
* // @log: ]
* ```
*
* @example
* It is also possible to append a Signature tuple to the end of an Authorization tuple.
*
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorizationList = Authorization.fromTupleList([
* ['0x1', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x3', '0x1', '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90', '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'],
* ['0x3', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x14', '0x1', '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90', '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'],
* ])
* // @log: [
* // @log: {
* // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
* // @log: chainId: 1,
* // @log: nonce: 3n,
* // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'),
* // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'),
* // @log: yParity: 0,
* // @log: },
* // @log: {
* // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
* // @log: chainId: 3,
* // @log: nonce: 20n,
* // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'),
* // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'),
* // @log: yParity: 0,
* // @log: },
* // @log: ]
* ```
*
* @param tupleList - The [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) Authorization tuple list.
* @returns An {@link ox#Authorization.List}.
*/
export function fromTupleList(tupleList) {
const list = [];
for (const tuple of tupleList)
list.push(fromTuple(tuple));
return list;
}
/**
* Computes the sign payload for an {@link ox#Authorization.Authorization} in [EIP-7702 format](https://eips.ethereum.org/EIPS/eip-7702): `keccak256('0x05' || rlp([chain_id, address, nonce]))`.
*
* @example
* The example below demonstrates computing the sign payload for an {@link ox#Authorization.Authorization}. This payload
* can then be passed to signing functions like {@link ox#Secp256k1.(sign:function)}.
*
* ```ts twoslash
* import { Authorization, Secp256k1 } from 'ox'
*
* const authorization = Authorization.from({
* address: '0x1234567890abcdef1234567890abcdef12345678',
* chainId: 1,
* nonce: 69n,
* })
*
* const payload = Authorization.getSignPayload(authorization) // [!code focus]
*
* const signature = Secp256k1.sign({
* payload,
* privateKey: '0x...',
* })
* ```
*
* @param authorization - The {@link ox#Authorization.Authorization}.
* @returns The sign payload.
*/
export function getSignPayload(authorization) {
return hash(authorization);
}
/**
* Computes the hash for an {@link ox#Authorization.Authorization} in [EIP-7702 format](https://eips.ethereum.org/EIPS/eip-7702): `keccak256('0x05' || rlp([chain_id, address, nonce]))`.
*
* @example
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorization = Authorization.from({
* address: '0x1234567890abcdef1234567890abcdef12345678',
* chainId: 1,
* nonce: 69n,
* })
*
* const hash = Authorization.hash(authorization) // [!code focus]
* ```
*
* @param authorization - The {@link ox#Authorization.Authorization}.
* @returns The hash.
*/
export function hash(authorization) {
return Hash.keccak256(Hex.concat('0x05', Rlp.fromHex(toTuple(authorization))));
}
/**
* Converts an {@link ox#Authorization.Authorization} to an {@link ox#Authorization.Rpc}.
*
* @example
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorization = Authorization.toRpc({
* address: '0x0000000000000000000000000000000000000000',
* chainId: 1,
* nonce: 1n,
* r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n,
* s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n,
* yParity: 0,
* })
* ```
*
* @param authorization - An Authorization.
* @returns An RPC-formatted Authorization.
*/
export function toRpc(authorization) {
const { address, chainId, nonce, ...signature } = authorization;
return {
address,
chainId: Hex.fromNumber(chainId),
nonce: Hex.fromNumber(nonce),
...Signature.toRpc(signature),
};
}
/**
* Converts an {@link ox#Authorization.List} to an {@link ox#Authorization.ListRpc}.
*
* @example
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorization = Authorization.toRpcList([{
* address: '0x0000000000000000000000000000000000000000',
* chainId: 1,
* nonce: 1n,
* r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n,
* s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n,
* yParity: 0,
* }])
* ```
*
* @param authorizationList - An Authorization List.
* @returns An RPC-formatted Authorization List.
*/
export function toRpcList(authorizationList) {
return authorizationList.map(toRpc);
}
/**
* Converts an {@link ox#Authorization.Authorization} to an {@link ox#Authorization.Tuple}.
*
* @example
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorization = Authorization.from({
* address: '0x1234567890abcdef1234567890abcdef12345678',
* chainId: 1,
* nonce: 69n,
* })
*
* const tuple = Authorization.toTuple(authorization) // [!code focus]
* // @log: [
* // @log: address: '0x1234567890abcdef1234567890abcdef12345678',
* // @log: chainId: 1,
* // @log: nonce: 69n,
* // @log: ]
* ```
*
* @param authorization - The {@link ox#Authorization.Authorization}.
* @returns An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) Authorization tuple.
*/
export function toTuple(authorization) {
const { address, chainId, nonce } = authorization;
const signature = Signature.extract(authorization);
return [
chainId ? Hex.fromNumber(chainId) : '0x',
address,
nonce ? Hex.fromNumber(nonce) : '0x',
...(signature ? Signature.toTuple(signature) : []),
];
}
/**
* Converts an {@link ox#Authorization.List} to an {@link ox#Authorization.TupleList}.
*
* @example
* ```ts twoslash
* import { Authorization } from 'ox'
*
* const authorization_1 = Authorization.from({
* address: '0x1234567890abcdef1234567890abcdef12345678',
* chainId: 1,
* nonce: 69n,
* })
* const authorization_2 = Authorization.from({
* address: '0x1234567890abcdef1234567890abcdef12345678',
* chainId: 3,
* nonce: 20n,
* })
*
* const tuple = Authorization.toTupleList([authorization_1, authorization_2]) // [!code focus]
* // @log: [
* // @log: [
* // @log: address: '0x1234567890abcdef1234567890abcdef12345678',
* // @log: chainId: 1,
* // @log: nonce: 69n,
* // @log: ],
* // @log: [
* // @log: address: '0x1234567890abcdef1234567890abcdef12345678',
* // @log: chainId: 3,
* // @log: nonce: 20n,
* // @log: ],
* // @log: ]
* ```
*
* @param list - An {@link ox#Authorization.List}.
* @returns An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) Authorization tuple list.
*/
export function toTupleList(list) {
if (!list || list.length === 0)
return [];
const tupleList = [];
for (const authorization of list)
tupleList.push(toTuple(authorization));
return tupleList;
}
//# sourceMappingURL=Authorization.js.map

1
node_modules/ox/_esm/core/Authorization.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Authorization.js","sourceRoot":"","sources":["../../core/Authorization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,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9B,CAAA;AACH,CAAC;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,SAAS,CAAC,iBAA6B;IACrD,OAAO,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AACrC,CAAC;AAMD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,OAAO,CACrB,aAA4B;IAE5B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,aAAa,CAAA;IACjD,MAAM,SAAS,GAAG,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;IAClD,OAAO;QACL,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI;QACxC,OAAO;QACP,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI;QACpC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1C,CAAA;AACZ,CAAC;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,UAAU,WAAW,CAIzB,IAAuB;IACvB,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IAEzC,MAAM,SAAS,GAAuB,EAAE,CAAA;IACxC,KAAK,MAAM,aAAa,IAAI,IAAI;QAAE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAA;IAExE,OAAO,SAAkB,CAAA;AAC3B,CAAC"}

124
node_modules/ox/_esm/core/Base58.js generated vendored Normal file
View File

@@ -0,0 +1,124 @@
import * as Bytes from './Bytes.js';
import * as Hex from './Hex.js';
import * as internal from './internal/base58.js';
/**
* Encodes a {@link ox#Bytes.Bytes} to a Base58-encoded string.
*
* @example
* ```ts twoslash
* import { Base58, Bytes } from 'ox'
*
* const value = Base58.fromBytes(Bytes.fromString('Hello World!'))
* // @log: '2NEpo7TZRRrLZSi2U'
* ```
*
* @param value - The byte array to encode.
* @returns The Base58 encoded string.
*/
export function fromBytes(value) {
return internal.from(value);
}
/**
* Encodes a {@link ox#Hex.Hex} to a Base58-encoded string.
*
* @example
* ```ts twoslash
* import { Base58, Hex } from 'ox'
*
* const value = Base58.fromHex(Hex.fromString('Hello World!'))
* // @log: '2NEpo7TZRRrLZSi2U'
* ```
*
* @param value - The byte array to encode.
* @returns The Base58 encoded string.
*/
export function fromHex(value) {
return internal.from(value);
}
/**
* Encodes a string to a Base58-encoded string.
*
* @example
* ```ts twoslash
* import { Base58 } from 'ox'
*
* const value = Base58.fromString('Hello World!')
* // @log: '2NEpo7TZRRrLZSi2U'
* ```
*
* @param value - The string to encode.
* @returns The Base58 encoded string.
*/
export function fromString(value) {
return internal.from(Bytes.fromString(value));
}
/**
* Decodes a Base58-encoded string to a {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Base58 } from 'ox'
*
* const value = Base58.toBytes('2NEpo7TZRRrLZSi2U')
* // @log: Uint8Array [ 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33 ]
* ```
*
* @param value - The Base58 encoded string.
* @returns The decoded byte array.
*/
export function toBytes(value) {
return Bytes.fromHex(toHex(value));
}
/**
* Decodes a Base58-encoded string to {@link ox#Hex.Hex}.
*
* @example
* ```ts twoslash
* import { Base58 } from 'ox'
*
* const value = Base58.toHex('2NEpo7TZRRrLZSi2U')
* // @log: '0x48656c6c6f20576f726c6421'
* ```
*
* @param value - The Base58 encoded string.
* @returns The decoded hex string.
*/
export function toHex(value) {
let integer = BigInt(0);
let pad = 0;
let checkPad = true;
for (let i = 0; i < value.length; i++) {
const char = value[i];
// check for leading 1s
if (checkPad && char === '1')
pad++;
else
checkPad = false;
// check for invalid characters
if (typeof internal.alphabetToInteger[char] !== 'bigint')
throw new Error('invalid base58 character: ' + char);
integer = integer * 58n;
integer = integer + internal.alphabetToInteger[char];
}
if (!pad)
return `0x${integer.toString(16)}`;
return `0x${'0'.repeat(pad * 2)}${integer.toString(16)}`;
}
/**
* Decodes a Base58-encoded string to a string.
*
* @example
* ```ts twoslash
* import { Base58 } from 'ox'
*
* const value = Base58.toString('2NEpo7TZRRrLZSi2U')
* // @log: 'Hello World!'
* ```
*
* @param value - The Base58 encoded string.
* @returns The decoded string.
*/
export function toString(value) {
return Hex.toString(toHex(value));
}
//# sourceMappingURL=Base58.js.map

1
node_modules/ox/_esm/core/Base58.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Base58.js","sourceRoot":"","sources":["../../core/Base58.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAEhD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CAAC,KAAkB;IAC1C,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC7B,CAAC;AAMD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC7B,CAAC;AAMD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;AAC/C,CAAC;AAMD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa;IACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;AACpC,CAAC;AAMD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,IAAI,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;IACvB,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,IAAI,QAAQ,GAAG,IAAI,CAAA;IAEnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAE,CAAA;QAEtB,uBAAuB;QACvB,IAAI,QAAQ,IAAI,IAAI,KAAK,GAAG;YAAE,GAAG,EAAE,CAAA;;YAC9B,QAAQ,GAAG,KAAK,CAAA;QAErB,+BAA+B;QAC/B,IAAI,OAAO,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,QAAQ;YACtD,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,IAAI,CAAC,CAAA;QAEtD,OAAO,GAAG,OAAO,GAAG,GAAG,CAAA;QACvB,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC,iBAAiB,CAAC,IAAI,CAAE,CAAA;IACvD,CAAC;IAED,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAa,CAAA;IACvD,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAa,CAAA;AACrE,CAAC;AAMD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAA;AACnC,CAAC"}

218
node_modules/ox/_esm/core/Base64.js generated vendored Normal file
View File

@@ -0,0 +1,218 @@
import * as Bytes from './Bytes.js';
import * as Hex from './Hex.js';
const encoder = /*#__PURE__*/ new TextEncoder();
const decoder = /*#__PURE__*/ new TextDecoder();
const integerToCharacter = /*#__PURE__*/ Object.fromEntries(Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/').map((a, i) => [i, a.charCodeAt(0)]));
const characterToInteger = /*#__PURE__*/ {
...Object.fromEntries(Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/').map((a, i) => [a.charCodeAt(0), i])),
['='.charCodeAt(0)]: 0,
['-'.charCodeAt(0)]: 62,
['_'.charCodeAt(0)]: 63,
};
/**
* Encodes a {@link ox#Bytes.Bytes} to a Base64-encoded string (with optional padding and/or URL-safe characters).
*
* @example
* ```ts twoslash
* import { Base64, Bytes } from 'ox'
*
* const value = Base64.fromBytes(Bytes.fromString('hello world'))
* // @log: 'aGVsbG8gd29ybGQ='
* ```
*
* @example
* ### No Padding
*
* Turn off [padding of encoded data](https://datatracker.ietf.org/doc/html/rfc4648#section-3.2) with the `pad` option:
*
* ```ts twoslash
* import { Base64, Bytes } from 'ox'
*
* const value = Base64.fromBytes(Bytes.fromString('hello world'), { pad: false })
* // @log: 'aGVsbG8gd29ybGQ'
* ```
*
* ### URL-safe Encoding
*
* Turn on [URL-safe encoding](https://datatracker.ietf.org/doc/html/rfc4648#section-5) (Base64 URL) with the `url` option:
*
* ```ts twoslash
* import { Base64, Bytes } from 'ox'
*
* const value = Base64.fromBytes(Bytes.fromString('hello wod'), { url: true })
* // @log: 'aGVsbG8gd29_77-9ZA=='
* ```
*
* @param value - The byte array to encode.
* @param options - Encoding options.
* @returns The Base64 encoded string.
*/
export function fromBytes(value, options = {}) {
const { pad = true, url = false } = options;
const encoded = new Uint8Array(Math.ceil(value.length / 3) * 4);
for (let i = 0, j = 0; j < value.length; i += 4, j += 3) {
const y = (value[j] << 16) + (value[j + 1] << 8) + (value[j + 2] | 0);
encoded[i] = integerToCharacter[y >> 18];
encoded[i + 1] = integerToCharacter[(y >> 12) & 0x3f];
encoded[i + 2] = integerToCharacter[(y >> 6) & 0x3f];
encoded[i + 3] = integerToCharacter[y & 0x3f];
}
const k = value.length % 3;
const end = Math.floor(value.length / 3) * 4 + (k && k + 1);
let base64 = decoder.decode(new Uint8Array(encoded.buffer, 0, end));
if (pad && k === 1)
base64 += '==';
if (pad && k === 2)
base64 += '=';
if (url)
base64 = base64.replaceAll('+', '-').replaceAll('/', '_');
return base64;
}
/**
* Encodes a {@link ox#Hex.Hex} to a Base64-encoded string (with optional padding and/or URL-safe characters).
*
* @example
* ```ts twoslash
* import { Base64, Hex } from 'ox'
*
* const value = Base64.fromHex(Hex.fromString('hello world'))
* // @log: 'aGVsbG8gd29ybGQ='
* ```
*
* @example
* ### No Padding
*
* Turn off [padding of encoded data](https://datatracker.ietf.org/doc/html/rfc4648#section-3.2) with the `pad` option:
*
* ```ts twoslash
* import { Base64, Hex } from 'ox'
*
* const value = Base64.fromHex(Hex.fromString('hello world'), { pad: false })
* // @log: 'aGVsbG8gd29ybGQ'
* ```
*
* ### URL-safe Encoding
*
* Turn on [URL-safe encoding](https://datatracker.ietf.org/doc/html/rfc4648#section-5) (Base64 URL) with the `url` option:
*
* ```ts twoslash
* import { Base64, Hex } from 'ox'
*
* const value = Base64.fromHex(Hex.fromString('hello wod'), { url: true })
* // @log: 'aGVsbG8gd29_77-9ZA=='
* ```
*
* @param value - The hex value to encode.
* @param options - Encoding options.
* @returns The Base64 encoded string.
*/
export function fromHex(value, options = {}) {
return fromBytes(Bytes.fromHex(value), options);
}
/**
* Encodes a string to a Base64-encoded string (with optional padding and/or URL-safe characters).
*
* @example
* ```ts twoslash
* import { Base64 } from 'ox'
*
* const value = Base64.fromString('hello world')
* // @log: 'aGVsbG8gd29ybGQ='
* ```
*
* @example
* ### No Padding
*
* Turn off [padding of encoded data](https://datatracker.ietf.org/doc/html/rfc4648#section-3.2) with the `pad` option:
*
* ```ts twoslash
* import { Base64 } from 'ox'
*
* const value = Base64.fromString('hello world', { pad: false })
* // @log: 'aGVsbG8gd29ybGQ'
* ```
*
* ### URL-safe Encoding
*
* Turn on [URL-safe encoding](https://datatracker.ietf.org/doc/html/rfc4648#section-5) (Base64 URL) with the `url` option:
*
* ```ts twoslash
* import { Base64 } from 'ox'
*
* const value = Base64.fromString('hello wod', { url: true })
* // @log: 'aGVsbG8gd29_77-9ZA=='
* ```
*
* @param value - The string to encode.
* @param options - Encoding options.
* @returns The Base64 encoded string.
*/
export function fromString(value, options = {}) {
return fromBytes(Bytes.fromString(value), options);
}
/**
* Decodes a Base64-encoded string (with optional padding and/or URL-safe characters) to {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Base64, Bytes } from 'ox'
*
* const value = Base64.toBytes('aGVsbG8gd29ybGQ=')
* // @log: Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])
* ```
*
* @param value - The string, hex value, or byte array to encode.
* @returns The Base64 decoded {@link ox#Bytes.Bytes}.
*/
export function toBytes(value) {
const base64 = value.replace(/=+$/, '');
const size = base64.length;
const decoded = new Uint8Array(size + 3);
encoder.encodeInto(base64 + '===', decoded);
for (let i = 0, j = 0; i < base64.length; i += 4, j += 3) {
const x = (characterToInteger[decoded[i]] << 18) +
(characterToInteger[decoded[i + 1]] << 12) +
(characterToInteger[decoded[i + 2]] << 6) +
characterToInteger[decoded[i + 3]];
decoded[j] = x >> 16;
decoded[j + 1] = (x >> 8) & 0xff;
decoded[j + 2] = x & 0xff;
}
const decodedSize = (size >> 2) * 3 + (size % 4 && (size % 4) - 1);
return new Uint8Array(decoded.buffer, 0, decodedSize);
}
/**
* Decodes a Base64-encoded string (with optional padding and/or URL-safe characters) to {@link ox#Hex.Hex}.
*
* @example
* ```ts twoslash
* import { Base64, Hex } from 'ox'
*
* const value = Base64.toHex('aGVsbG8gd29ybGQ=')
* // @log: 0x68656c6c6f20776f726c64
* ```
*
* @param value - The string, hex value, or byte array to encode.
* @returns The Base64 decoded {@link ox#Hex.Hex}.
*/
export function toHex(value) {
return Hex.fromBytes(toBytes(value));
}
/**
* Decodes a Base64-encoded string (with optional padding and/or URL-safe characters) to a string.
*
* @example
* ```ts twoslash
* import { Base64 } from 'ox'
*
* const value = Base64.toString('aGVsbG8gd29ybGQ=')
* // @log: 'hello world'
* ```
*
* @param value - The string, hex value, or byte array to encode.
* @returns The Base64 decoded string.
*/
export function toString(value) {
return Bytes.toString(toBytes(value));
}
//# sourceMappingURL=Base64.js.map

1
node_modules/ox/_esm/core/Base64.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Base64.js","sourceRoot":"","sources":["../../core/Base64.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAE/B,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,WAAW,EAAE,CAAA;AAC/C,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,WAAW,EAAE,CAAA;AAE/C,MAAM,kBAAkB,GAAG,aAAa,CAAC,MAAM,CAAC,WAAW,CACzD,KAAK,CAAC,IAAI,CACR,kEAAkE,CACnE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CACtC,CAAA;AAED,MAAM,kBAAkB,GAAG,aAAa,CAAC;IACvC,GAAG,MAAM,CAAC,WAAW,CACnB,KAAK,CAAC,IAAI,CACR,kEAAkE,CACnE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CACtC;IACD,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;IACvB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAA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,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;AACvC,CAAC"}

196
node_modules/ox/_esm/core/BinaryStateTree.js generated vendored Normal file
View File

@@ -0,0 +1,196 @@
import { blake3 } from '@noble/hashes/blake3';
import * as Bytes from './Bytes.js';
/**
* Creates a new Binary State Tree instance.
*
* @example
* ```ts twoslash
* import { BinaryStateTree } from 'ox'
*
* const tree = BinaryStateTree.create()
* ```
*
* @returns A Binary State Tree.
*/
export function create() {
return {
root: emptyNode(),
};
}
/**
* Inserts a key-value pair into the Binary State Tree.
*
* @example
* ```ts twoslash
* import { BinaryStateTree, Bytes } from 'ox'
*
* const tree = BinaryStateTree.create()
*
* BinaryStateTree.insert( // [!code focus]
* tree, // [!code focus]
* Bytes.fromHex('0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54'), // [!code focus]
* Bytes.fromHex('0xd4fd4e189132273036449fc9e11198c739161b4c0116a9a2dccdfa1c492006f1') // [!code focus]
* ) // [!code focus]
* ```
*
* @param tree - Binary State Tree instance.
* @param key - Key to insert.
* @param value - Value to insert.
*/
export function insert(tree, key, value) {
const stem = Bytes.slice(key, 0, 31);
const subIndex = Bytes.slice(key, 31)[0];
if (tree.root.type === 'empty') {
tree.root = stemNode(stem);
tree.root.values[subIndex] = value;
return;
}
function inner(node_, stem, subIndex, value, depth) {
let node = node_;
if (node.type === 'empty') {
node = stemNode(stem);
node.values[subIndex] = value;
return node;
}
const stemBits = bytesToBits(stem);
if (node.type === 'stem') {
if (Bytes.isEqual(node.stem, stem)) {
node.values[subIndex] = value;
return node;
}
const existingStemBits = bytesToBits(node.stem);
return splitLeaf(node, stemBits, existingStemBits, subIndex, value, depth);
}
if (node.type === 'internal') {
const bit = stemBits[depth];
if (bit === 0) {
node.left = inner(node.left, stem, subIndex, value, depth + 1);
}
else {
node.right = inner(node.right, stem, subIndex, value, depth + 1);
}
return node;
}
return emptyNode();
}
tree.root = inner(tree.root, stem, subIndex, value, 0);
}
/**
* Merkelizes a Binary State Tree.
*
* @example
* ```ts twoslash
* import { BinaryStateTree, Bytes } from 'ox'
*
* const tree = BinaryStateTree.create()
*
* BinaryStateTree.insert(
* tree,
* Bytes.fromHex('0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54'),
* Bytes.fromHex('0xd4fd4e189132273036449fc9e11198c739161b4c0116a9a2dccdfa1c492006f1')
* )
*
* const hash = BinaryStateTree.merkelize(tree) // [!code focus]
* ```
*
* @param tree - Binary State Tree instance.
* @returns Merkle hash.
*/
export function merkelize(tree) {
function inner(node) {
if (node.type === 'empty')
return new Uint8Array(32).fill(0);
if (node.type === 'internal') {
const hash_left = inner(node.left);
const hash_right = inner(node.right);
return hash(Bytes.concat(hash_left, hash_right));
}
let level = node.values.map(hash);
while (level.length > 1) {
const level_ = [];
for (let i = 0; i < level.length; i += 2)
level_.push(hash(Bytes.concat(level[i], level[i + 1])));
level = level_;
}
return hash(Bytes.concat(node.stem, new Uint8Array(1).fill(0), level[0]));
}
return inner(tree.root);
}
/** @internal */
function splitLeaf(leaf, stemBits, existingStemBits, subIndex, value, depth) {
if (stemBits[depth] === existingStemBits[depth]) {
const internal = internalNode();
const bit = stemBits[depth];
if (bit === 0) {
internal.left = splitLeaf(leaf, stemBits, existingStemBits, subIndex, value, depth + 1);
}
else {
internal.right = splitLeaf(leaf, stemBits, existingStemBits, subIndex, value, depth + 1);
}
return internal;
}
const internal = internalNode();
const bit = stemBits[depth];
const stem = bitsToBytes(stemBits);
if (bit === 0) {
internal.left = stemNode(stem);
internal.left.values[subIndex] = value;
internal.right = leaf;
}
else {
internal.right = stemNode(stem);
internal.right.values[subIndex] = value;
internal.left = leaf;
}
return internal;
}
/** @internal */
function emptyNode() {
return {
type: 'empty',
};
}
/** @internal */
function internalNode() {
return {
left: emptyNode(),
right: emptyNode(),
type: 'internal',
};
}
/** @internal */
function stemNode(stem) {
return {
stem,
values: Array.from({ length: 256 }, () => undefined),
type: 'stem',
};
}
/** @internal */
function bytesToBits(bytes) {
const bits = [];
for (const byte of bytes)
for (let i = 0; i < 8; i++)
bits.push((byte >> (7 - i)) & 1);
return bits;
}
/** @internal */
function bitsToBytes(bits) {
const byte_data = new Uint8Array(bits.length / 8);
for (let i = 0; i < bits.length; i += 8) {
let byte = 0;
for (let j = 0; j < 8; j++)
byte |= bits[i + j] << (7 - j);
byte_data[i / 8] = byte;
}
return byte_data;
}
/** @internal */
function hash(bytes) {
if (!bytes)
return new Uint8Array(32).fill(0);
if (!bytes.some((byte) => byte !== 0))
return new Uint8Array(32).fill(0);
return blake3(bytes);
}
//# sourceMappingURL=BinaryStateTree.js.map

1
node_modules/ox/_esm/core/BinaryStateTree.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

596
node_modules/ox/_esm/core/Blobs.js generated vendored Normal file
View File

@@ -0,0 +1,596 @@
import * as Bytes from './Bytes.js';
import * as Errors from './Errors.js';
import * as Hash from './Hash.js';
import * as Hex from './Hex.js';
import * as Kzg from './Kzg.js';
import * as Cursor from './internal/cursor.js';
/** Blob limit per transaction. */
const blobsPerTransaction = 6;
/** The number of bytes in a BLS scalar field element. */
export const bytesPerFieldElement = 32;
/** The number of field elements in a blob. */
export const fieldElementsPerBlob = 4096;
/** The number of bytes in a blob. */
export const bytesPerBlob = bytesPerFieldElement * fieldElementsPerBlob;
/** Blob bytes limit per transaction. */
export const maxBytesPerTransaction = bytesPerBlob * blobsPerTransaction -
// terminator byte (0x80).
1 -
// zero byte (0x00) appended to each field element.
1 * fieldElementsPerBlob * blobsPerTransaction;
/**
* Transform a list of Commitments to Blob Versioned Hashes.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'viem'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const commitments = Blobs.toCommitments(blobs, { kzg })
* const versionedHashes = Blobs.commitmentsToVersionedHashes(commitments) // [!code focus]
* // @log: ['0x...', '0x...']
* ```
*
* @example
* ### Configuring Return Type
*
* It is possible to configure the return type for the Versioned Hashes with the `as` option.
*
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'viem'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const commitments = Blobs.toCommitments(blobs, { kzg })
* const versionedHashes = Blobs.commitmentsToVersionedHashes(commitments, {
* as: 'Bytes', // [!code focus]
* })
* // @log: [Uint8Array [ ... ], Uint8Array [ ... ]]
* ```
*
* @example
* ### Versioning Hashes
*
* It is possible to configure the version for the Versioned Hashes with the `version` option.
*
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'viem'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const commitments = Blobs.toCommitments(blobs, { kzg })
* const versionedHashes = Blobs.commitmentsToVersionedHashes(commitments, {
* version: 2, // [!code focus]
* })
* ```
*
* @param commitments - A list of commitments.
* @param options - Options.
* @returns A list of Blob Versioned Hashes.
*/
export function commitmentsToVersionedHashes(commitments, options = {}) {
const { version } = options;
const as = options.as ?? (typeof commitments[0] === 'string' ? 'Hex' : 'Bytes');
const hashes = [];
for (const commitment of commitments) {
hashes.push(commitmentToVersionedHash(commitment, {
as,
version,
}));
}
return hashes;
}
/**
* Transform a Commitment to its Blob Versioned Hash.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'ox'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const [commitment] = Blobs.toCommitments(blobs, { kzg })
* const versionedHash = Blobs.commitmentToVersionedHash(commitment) // [!code focus]
* ```
*
* @example
* ### Configuring Return Type
*
* It is possible to configure the return type for the Versioned Hash with the `as` option.
*
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'viem'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const [commitment] = Blobs.toCommitments(blobs, { kzg })
* const versionedHashes = Blobs.commitmentToVersionedHash(commitment, {
* as: 'Bytes', // [!code focus]
* })
* // @log: [Uint8Array [ ... ], Uint8Array [ ... ]]
* ```
*
* @example
* ### Versioning Hashes
*
* It is possible to configure the version for the Versioned Hash with the `version` option.
*
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'viem'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const [commitment] = Blobs.toCommitments(blobs, { kzg })
* const versionedHashes = Blobs.commitmentToVersionedHash(commitment, {
* version: 2, // [!code focus]
* })
* ```
*
* @param commitment - The commitment.
* @param options - Options.
* @returns The Blob Versioned Hash.
*/
export function commitmentToVersionedHash(commitment, options = {}) {
const { version = 1 } = options;
const as = options.as ?? (typeof commitment === 'string' ? 'Hex' : 'Bytes');
const versionedHash = Hash.sha256(commitment, { as: 'Bytes' });
versionedHash.set([version], 0);
return (as === 'Bytes' ? versionedHash : Hex.fromBytes(versionedHash));
}
/**
* Transforms arbitrary data to {@link ox#Blobs.Blobs}.
*
* @example
* ```ts twoslash
* import { Blobs } from 'ox'
*
* const blobs = Blobs.from('0xdeadbeef')
* ```
*
* @example
* ### Creating Blobs from a String
*
* An example of creating Blobs from a string using {@link ox#Hex.(from:function)}:
*
* ```ts twoslash
* import { Blobs, Hex } from 'ox'
*
* const blobs = Blobs.from(Hex.fromString('Hello world!'))
* ```
*
* @example
* ### Configuring Return Type
*
* It is possible to configure the return type for the Blobs with the `as` option.
*
* ```ts twoslash
* import { Blobs } from 'ox'
*
* const blobs = Blobs.from('0xdeadbeef', { as: 'Bytes' })
* // ^?
*
*
* ```
*
* @param data - The data to convert to {@link ox#Blobs.Blobs}.
* @param options - Options.
* @returns The {@link ox#Blobs.Blobs}.
*/
export function from(data, options = {}) {
const as = options.as ?? (typeof data === 'string' ? 'Hex' : 'Bytes');
const data_ = (typeof data === 'string' ? Bytes.fromHex(data) : data);
const size_ = Bytes.size(data_);
if (!size_)
throw new EmptyBlobError();
if (size_ > maxBytesPerTransaction)
throw new BlobSizeTooLargeError({
maxSize: maxBytesPerTransaction,
size: size_,
});
const blobs = [];
let active = true;
let position = 0;
while (active) {
const blob = Cursor.create(new Uint8Array(bytesPerBlob));
let size = 0;
while (size < fieldElementsPerBlob) {
const bytes = data_.slice(position, position + (bytesPerFieldElement - 1));
// Push a zero byte so the field element doesn't overflow the BLS modulus.
blob.pushByte(0x00);
// Push the current segment of data bytes.
blob.pushBytes(bytes);
// If we detect that the current segment of data bytes is less than 31 bytes,
// we can stop processing and push a terminator byte to indicate the end of the blob.
if (bytes.length < 31) {
blob.pushByte(0x80);
active = false;
break;
}
size++;
position += 31;
}
blobs.push(blob);
}
return (as === 'Bytes'
? blobs.map((x) => x.bytes)
: blobs.map((x) => Hex.fromBytes(x.bytes)));
}
/**
* Transforms a list of {@link ox#Blobs.BlobSidecars} to their Blob Versioned Hashes.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'ox'
*
* const blobs = Blobs.from('0xdeadbeef')
* const sidecars = Blobs.toSidecars(blobs, { kzg })
* const versionedHashes = Blobs.sidecarsToVersionedHashes(sidecars) // [!code focus]
* ```
*
* @example
* ### Configuring Return Type
*
* It is possible to configure the return type for the Versioned Hashes with the `as` option.
*
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'viem'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const sidecars = Blobs.toSidecars(blobs, { kzg })
* const versionedHashes = Blobs.sidecarsToVersionedHashes(sidecars, {
* as: 'Bytes', // [!code focus]
* })
* // @log: [Uint8Array [ ... ], Uint8Array [ ... ]]
* ```
*
* @example
* ### Versioning Hashes
*
* It is possible to configure the version for the Versioned Hashes with the `version` option.
*
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'viem'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const sidecars = Blobs.toSidecars(blobs, { kzg })
* const versionedHashes = Blobs.sidecarsToVersionedHashes(sidecars, {
* version: 2, // [!code focus]
* })
* ```
*
* @param sidecars - The {@link ox#Blobs.BlobSidecars} to transform to Blob Versioned Hashes.
* @param options - Options.
* @returns The versioned hashes.
*/
export function sidecarsToVersionedHashes(sidecars, options = {}) {
const { version } = options;
const as = options.as ?? (typeof sidecars[0].blob === 'string' ? 'Hex' : 'Bytes');
const hashes = [];
for (const { commitment } of sidecars) {
hashes.push(commitmentToVersionedHash(commitment, {
as,
version,
}));
}
return hashes;
}
/**
* Transforms Ox-shaped {@link ox#Blobs.Blobs} into the originating data.
*
* @example
* ```ts twoslash
* import { Blobs, Hex } from 'ox'
*
* const blobs = Blobs.from('0xdeadbeef')
* const data = Blobs.to(blobs) // [!code focus]
* // @log: '0xdeadbeef'
* ```
*
* @example
* ### Configuring Return Type
*
* It is possible to configure the return type with second argument.
*
* ```ts twoslash
* import { Blobs } from 'ox'
*
* const blobs = Blobs.from('0xdeadbeef')
* const data = Blobs.to(blobs, 'Bytes')
* // @log: Uint8Array [ 13, 174, 190, 239 ]
* ```
*
* @param blobs - The {@link ox#Blobs.Blobs} to transform.
* @param to - The type to transform to.
* @returns The originating data.
*/
export function to(blobs, to) {
const to_ = to ?? (typeof blobs[0] === 'string' ? 'Hex' : 'Bytes');
const blobs_ = (typeof blobs[0] === 'string'
? blobs.map((x) => Bytes.fromHex(x))
: blobs);
const length = blobs_.reduce((length, blob) => length + blob.length, 0);
const data = Cursor.create(new Uint8Array(length));
let active = true;
for (const blob of blobs_) {
const cursor = Cursor.create(blob);
while (active && cursor.position < blob.length) {
// First byte will be a zero 0x00 byte we can skip.
cursor.incrementPosition(1);
let consume = 31;
if (blob.length - cursor.position < 31)
consume = blob.length - cursor.position;
for (const _ in Array.from({ length: consume })) {
const byte = cursor.readByte();
const isTerminator = byte === 0x80 && !cursor.inspectBytes(cursor.remaining).includes(0x80);
if (isTerminator) {
active = false;
break;
}
data.pushByte(byte);
}
}
}
const trimmedData = data.bytes.slice(0, data.position);
return (to_ === 'Hex' ? Hex.fromBytes(trimmedData) : trimmedData);
}
/**
* Transforms Ox-shaped {@link ox#Blobs.Blobs} into the originating data.
*
* @example
* ```ts twoslash
* import { Blobs, Hex } from 'ox'
*
* const blobs = Blobs.from('0xdeadbeef')
* const data = Blobs.toHex(blobs) // [!code focus]
* // @log: '0xdeadbeef'
* ```
*/
export function toHex(blobs) {
return to(blobs, 'Hex');
}
/**
* Transforms Ox-shaped {@link ox#Blobs.Blobs} into the originating data.
*
* @example
* ```ts
* import { Blobs, Hex } from 'ox'
*
* const blobs = Blobs.from('0xdeadbeef')
* const data = Blobs.toBytes(blobs) // [!code focus]
* // @log: Uint8Array [ 13, 174, 190, 239 ]
* ```
*/
export function toBytes(blobs) {
return to(blobs, 'Bytes');
}
/**
* Compute commitments from a list of {@link ox#Blobs.Blobs}.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'ox'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const commitments = Blobs.toCommitments(blobs, { kzg }) // [!code focus]
* ```
*
* @example
* ### Configuring Return Type
*
* It is possible to configure the return type with the `as` option.
*
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'ox'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const commitments = Blobs.toCommitments(blobs, {
* as: 'Bytes', // [!code focus]
* kzg,
* })
* // @log: [Uint8Array [ ... ], Uint8Array [ ... ]]
* ```
*
* @param blobs - The {@link ox#Blobs.Blobs} to transform to commitments.
* @param options - Options.
* @returns The commitments.
*/
export function toCommitments(blobs, options) {
const { kzg } = options;
const as = options.as ?? (typeof blobs[0] === 'string' ? 'Hex' : 'Bytes');
const blobs_ = (typeof blobs[0] === 'string'
? blobs.map((x) => Bytes.fromHex(x))
: blobs);
const commitments = [];
for (const blob of blobs_)
commitments.push(Uint8Array.from(kzg.blobToKzgCommitment(blob)));
return (as === 'Bytes' ? commitments : commitments.map((x) => Hex.fromBytes(x)));
}
/**
* Compute the proofs for a list of {@link ox#Blobs.Blobs} and their commitments.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'viem'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const commitments = Blobs.toCommitments(blobs, { kzg })
* const proofs = Blobs.toProofs(blobs, { commitments, kzg }) // [!code focus]
* ```
*
* @param blobs - The {@link ox#Blobs.Blobs} to compute proofs for.
* @param options - Options.
* @returns The Blob proofs.
*/
export function toProofs(blobs, options) {
const { kzg } = options;
const as = options.as ?? (typeof blobs[0] === 'string' ? 'Hex' : 'Bytes');
const blobs_ = (typeof blobs[0] === 'string'
? blobs.map((x) => Bytes.fromHex(x))
: blobs);
const commitments = (typeof options.commitments[0] === 'string'
? options.commitments.map((x) => Bytes.fromHex(x))
: options.commitments);
const proofs = [];
for (let i = 0; i < blobs_.length; i++) {
const blob = blobs_[i];
const commitment = commitments[i];
proofs.push(Uint8Array.from(kzg.computeBlobKzgProof(blob, commitment)));
}
return (as === 'Bytes' ? proofs : proofs.map((x) => Hex.fromBytes(x)));
}
/**
* Transforms {@link ox#Blobs.Blobs} into a {@link ox#Blobs.BlobSidecars} array.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'ox'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const sidecars = Blobs.toSidecars(blobs, { kzg }) // [!code focus]
* ```
*
* @example
* You can also provide your own commitments and proofs if you do not want `toSidecars`
* to compute them.
*
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'ox'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const commitments = Blobs.toCommitments(blobs, { kzg })
* const proofs = Blobs.toProofs(blobs, { commitments, kzg })
*
* const sidecars = Blobs.toSidecars(blobs, { commitments, kzg, proofs }) // [!code focus]
* ```
*
* @param blobs - The {@link ox#Blobs.Blobs} to transform into {@link ox#Blobs.BlobSidecars}.
* @param options - Options.
* @returns The {@link ox#Blobs.BlobSidecars}.
*/
export function toSidecars(blobs, options) {
const { kzg } = options;
const commitments = options.commitments ?? toCommitments(blobs, { kzg: kzg });
const proofs = options.proofs ??
toProofs(blobs, { commitments: commitments, kzg: kzg });
const sidecars = [];
for (let i = 0; i < blobs.length; i++)
sidecars.push({
blob: blobs[i],
commitment: commitments[i],
proof: proofs[i],
});
return sidecars;
}
/**
* Compute Blob Versioned Hashes from a list of {@link ox#Blobs.Blobs}.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Blobs } from 'ox'
* import { kzg } from './kzg'
*
* const blobs = Blobs.from('0xdeadbeef')
* const versionedHashes = Blobs.toVersionedHashes(blobs, { kzg }) // [!code focus]
* ```
*
* @param blobs - The {@link ox#Blobs.Blobs} to transform into Blob Versioned Hashes.
* @param options - Options.
* @returns The Blob Versioned Hashes.
*/
export function toVersionedHashes(blobs, options) {
const commitments = toCommitments(blobs, options);
return commitmentsToVersionedHashes(commitments, options);
}
/** Thrown when the blob size is too large. */
export class BlobSizeTooLargeError extends Errors.BaseError {
constructor({ maxSize, size }) {
super('Blob size is too large.', {
metaMessages: [`Max: ${maxSize} bytes`, `Given: ${size} bytes`],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Blobs.BlobSizeTooLargeError'
});
}
}
/** Thrown when the blob is empty. */
export class EmptyBlobError extends Errors.BaseError {
constructor() {
super('Blob data must not be empty.');
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Blobs.EmptyBlobError'
});
}
}
/** Thrown when the blob versioned hashes are empty. */
export class EmptyBlobVersionedHashesError extends Errors.BaseError {
constructor() {
super('Blob versioned hashes must not be empty.');
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Blobs.EmptyBlobVersionedHashesError'
});
}
}
/** Thrown when the blob versioned hash size is invalid. */
export class InvalidVersionedHashSizeError extends Errors.BaseError {
constructor({ hash, size, }) {
super(`Versioned hash "${hash}" size is invalid.`, {
metaMessages: ['Expected: 32', `Received: ${size}`],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Blobs.InvalidVersionedHashSizeError'
});
}
}
/** Thrown when the blob versioned hash version is invalid. */
export class InvalidVersionedHashVersionError extends Errors.BaseError {
constructor({ hash, version, }) {
super(`Versioned hash "${hash}" version is invalid.`, {
metaMessages: [
`Expected: ${Kzg.versionedHashVersion}`,
`Received: ${version}`,
],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Blobs.InvalidVersionedHashVersionError'
});
}
}
//# sourceMappingURL=Blobs.js.map

1
node_modules/ox/_esm/core/Blobs.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

171
node_modules/ox/_esm/core/Block.js generated vendored Normal file
View File

@@ -0,0 +1,171 @@
import * as Hex from './Hex.js';
import * as Transaction from './Transaction.js';
import * as Withdrawal from './Withdrawal.js';
/**
* Converts a {@link ox#Block.Block} to an {@link ox#Block.Rpc}.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Block } from 'ox'
*
* const block = Block.toRpc({
* // ...
* hash: '0xebc3644804e4040c0a74c5a5bbbc6b46a71a5d4010fe0c92ebb2fdf4a43ea5dd',
* number: 19868020n,
* size: 520n
* timestamp: 1662222222n,
* // ...
* })
* // @log: {
* // @log: // ...
* // @log: hash: '0xebc3644804e4040c0a74c5a5bbbc6b46a71a5d4010fe0c92ebb2fdf4a43ea5dd',
* // @log: number: '0xec6fc6',
* // @log: size: '0x208',
* // @log: timestamp: '0x63198f6f',
* // @log: // ...
* // @log: }
* ```
*
* @param block - The Block to convert.
* @returns An RPC Block.
*/
export function toRpc(block, _options = {}) {
const transactions = block.transactions.map((transaction) => {
if (typeof transaction === 'string')
return transaction;
return Transaction.toRpc(transaction);
});
return {
baseFeePerGas: typeof block.baseFeePerGas === 'bigint'
? Hex.fromNumber(block.baseFeePerGas)
: undefined,
blobGasUsed: typeof block.blobGasUsed === 'bigint'
? Hex.fromNumber(block.blobGasUsed)
: undefined,
excessBlobGas: typeof block.excessBlobGas === 'bigint'
? Hex.fromNumber(block.excessBlobGas)
: undefined,
extraData: block.extraData,
difficulty: typeof block.difficulty === 'bigint'
? Hex.fromNumber(block.difficulty)
: undefined,
gasLimit: Hex.fromNumber(block.gasLimit),
gasUsed: Hex.fromNumber(block.gasUsed),
hash: block.hash,
logsBloom: block.logsBloom,
miner: block.miner,
mixHash: block.mixHash,
nonce: block.nonce,
number: (typeof block.number === 'bigint'
? Hex.fromNumber(block.number)
: null),
parentBeaconBlockRoot: block.parentBeaconBlockRoot,
parentHash: block.parentHash,
receiptsRoot: block.receiptsRoot,
sealFields: block.sealFields,
sha3Uncles: block.sha3Uncles,
size: Hex.fromNumber(block.size),
stateRoot: block.stateRoot,
timestamp: Hex.fromNumber(block.timestamp),
totalDifficulty: typeof block.totalDifficulty === 'bigint'
? Hex.fromNumber(block.totalDifficulty)
: undefined,
transactions,
transactionsRoot: block.transactionsRoot,
uncles: block.uncles,
withdrawals: block.withdrawals?.map(Withdrawal.toRpc),
withdrawalsRoot: block.withdrawalsRoot,
};
}
/**
* Converts a {@link ox#Block.Rpc} to an {@link ox#Block.Block}.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Block } from 'ox'
*
* const block = Block.fromRpc({
* // ...
* hash: '0xebc3644804e4040c0a74c5a5bbbc6b46a71a5d4010fe0c92ebb2fdf4a43ea5dd',
* number: '0xec6fc6',
* size: '0x208',
* timestamp: '0x63198f6f',
* // ...
* })
* // @log: {
* // @log: // ...
* // @log: hash: '0xebc3644804e4040c0a74c5a5bbbc6b46a71a5d4010fe0c92ebb2fdf4a43ea5dd',
* // @log: number: 19868020n,
* // @log: size: 520n,
* // @log: timestamp: 1662222222n,
* // @log: // ...
* // @log: }
* ```
*
* @example
* ### End-to-end
*
* Below is an end-to-end example of using `Block.fromRpc` to fetch a block from the network and convert it to an {@link ox#Block.Block}.
*
* ```ts twoslash
* import 'ox/window'
* import { Block } from 'ox'
*
* const block = await window.ethereum!
* .request({
* method: 'eth_getBlockByNumber',
* params: ['latest', false],
* })
* .then(Block.fromRpc) // [!code hl]
* // @log: {
* // @log: // ...
* // @log: hash: '0xebc3644804e4040c0a74c5a5bbbc6b46a71a5d4010fe0c92ebb2fdf4a43ea5dd',
* // @log: number: 19868020n,
* // @log: size: 520n,
* // @log: timestamp: 1662222222n,
* // @log: // ...
* // @log: }
* ```
*
* :::note
*
* For simplicity, the above example uses `window.ethereum.request`, but you can use any
* type of JSON-RPC interface.
*
* :::
*
* @param block - The RPC block to convert.
* @returns An instantiated {@link ox#Block.Block}.
*/
export function fromRpc(block, _options = {}) {
if (!block)
return null;
const transactions = block.transactions.map((transaction) => {
if (typeof transaction === 'string')
return transaction;
return Transaction.fromRpc(transaction);
});
return {
...block,
baseFeePerGas: block.baseFeePerGas
? BigInt(block.baseFeePerGas)
: undefined,
blobGasUsed: block.blobGasUsed ? BigInt(block.blobGasUsed) : undefined,
difficulty: block.difficulty ? BigInt(block.difficulty) : undefined,
excessBlobGas: block.excessBlobGas
? BigInt(block.excessBlobGas)
: undefined,
gasLimit: BigInt(block.gasLimit ?? 0n),
gasUsed: BigInt(block.gasUsed ?? 0n),
number: block.number ? BigInt(block.number) : null,
size: BigInt(block.size ?? 0n),
stateRoot: block.stateRoot,
timestamp: BigInt(block.timestamp ?? 0n),
totalDifficulty: BigInt(block.totalDifficulty ?? 0n),
transactions,
withdrawals: block.withdrawals?.map(Withdrawal.fromRpc),
};
}
//# sourceMappingURL=Block.js.map

1
node_modules/ox/_esm/core/Block.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Block.js","sourceRoot":"","sources":["../../core/Block.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AAgH7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,KAAK,CAInB,KAA2C,EAC3C,WAAyD,EAAE;IAE3D,MAAM,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG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K,CAAC,aAAa;YAChC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC;YAC7B,CAAC,CAAC,SAAS;QACb,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;QACtE,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS;QACnE,aAAa,EAAE,KAAK,CAAC,aAAa;YAChC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC;YAC7B,CAAC,CAAC,SAAS;QACb,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;QACtC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;QACpC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI;QAClD,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC;QACxC,eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,eAAe,IAAI,EAAE,CAAC;QACpD,YAAY;QACZ,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC;KACtC,CAAA;AACrB,CAAC"}

117
node_modules/ox/_esm/core/BlockOverrides.js generated vendored Normal file
View File

@@ -0,0 +1,117 @@
import * as Hex from './Hex.js';
import * as Withdrawal from './Withdrawal.js';
/**
* Converts an {@link ox#BlockOverrides.Rpc} to an {@link ox#BlockOverrides.BlockOverrides}.
*
* @example
* ```ts twoslash
* import { BlockOverrides } from 'ox'
*
* const blockOverrides = BlockOverrides.fromRpc({
* baseFeePerGas: '0x1',
* blobBaseFee: '0x2',
* feeRecipient: '0x0000000000000000000000000000000000000000',
* gasLimit: '0x4',
* number: '0x5',
* prevRandao: '0x6',
* time: '0x1234567890',
* withdrawals: [
* {
* address: '0x0000000000000000000000000000000000000000',
* amount: '0x1',
* index: '0x0',
* validatorIndex: '0x1',
* },
* ],
* })
* ```
*
* @param rpcBlockOverrides - The RPC block overrides to convert.
* @returns An instantiated {@link ox#BlockOverrides.BlockOverrides}.
*/
export function fromRpc(rpcBlockOverrides) {
return {
...(rpcBlockOverrides.baseFeePerGas && {
baseFeePerGas: BigInt(rpcBlockOverrides.baseFeePerGas),
}),
...(rpcBlockOverrides.blobBaseFee && {
blobBaseFee: BigInt(rpcBlockOverrides.blobBaseFee),
}),
...(rpcBlockOverrides.feeRecipient && {
feeRecipient: rpcBlockOverrides.feeRecipient,
}),
...(rpcBlockOverrides.gasLimit && {
gasLimit: BigInt(rpcBlockOverrides.gasLimit),
}),
...(rpcBlockOverrides.number && {
number: BigInt(rpcBlockOverrides.number),
}),
...(rpcBlockOverrides.prevRandao && {
prevRandao: BigInt(rpcBlockOverrides.prevRandao),
}),
...(rpcBlockOverrides.time && {
time: BigInt(rpcBlockOverrides.time),
}),
...(rpcBlockOverrides.withdrawals && {
withdrawals: rpcBlockOverrides.withdrawals.map(Withdrawal.fromRpc),
}),
};
}
/**
* Converts an {@link ox#BlockOverrides.BlockOverrides} to an {@link ox#BlockOverrides.Rpc}.
*
* @example
* ```ts twoslash
* import { BlockOverrides } from 'ox'
*
* const blockOverrides = BlockOverrides.toRpc({
* baseFeePerGas: 1n,
* blobBaseFee: 2n,
* feeRecipient: '0x0000000000000000000000000000000000000000',
* gasLimit: 4n,
* number: 5n,
* prevRandao: 6n,
* time: 78187493520n,
* withdrawals: [
* {
* address: '0x0000000000000000000000000000000000000000',
* amount: 1n,
* index: 0,
* validatorIndex: 1,
* },
* ],
* })
* ```
*
* @param blockOverrides - The block overrides to convert.
* @returns An instantiated {@link ox#BlockOverrides.Rpc}.
*/
export function toRpc(blockOverrides) {
return {
...(typeof blockOverrides.baseFeePerGas === 'bigint' && {
baseFeePerGas: Hex.fromNumber(blockOverrides.baseFeePerGas),
}),
...(typeof blockOverrides.blobBaseFee === 'bigint' && {
blobBaseFee: Hex.fromNumber(blockOverrides.blobBaseFee),
}),
...(typeof blockOverrides.feeRecipient === 'string' && {
feeRecipient: blockOverrides.feeRecipient,
}),
...(typeof blockOverrides.gasLimit === 'bigint' && {
gasLimit: Hex.fromNumber(blockOverrides.gasLimit),
}),
...(typeof blockOverrides.number === 'bigint' && {
number: Hex.fromNumber(blockOverrides.number),
}),
...(typeof blockOverrides.prevRandao === 'bigint' && {
prevRandao: Hex.fromNumber(blockOverrides.prevRandao),
}),
...(typeof blockOverrides.time === 'bigint' && {
time: Hex.fromNumber(blockOverrides.time),
}),
...(blockOverrides.withdrawals && {
withdrawals: blockOverrides.withdrawals.map(Withdrawal.toRpc),
}),
};
}
//# sourceMappingURL=BlockOverrides.js.map

1
node_modules/ox/_esm/core/BlockOverrides.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"BlockOverrides.js","sourceRoot":"","sources":["../../core/BlockOverrides.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAA;AA6B7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,OAAO,CAAC,iBAAsB;IAC5C,OAAO;QACL,GAAG,CAAC,iBAAiB,CAAC,aAAa,IAAI;YACrC,aAAa,EAAE,MAAM,CAAC,iBAAiB,CAAC,aAAa,CAAC;SACvD,CAAC;QACF,GAAG,CAAC,iBAAiB,CAAC,WAAW,IAAI;YACnC,WAAW,EAAE,MAAM,CAAC,iBAAiB,CAAC,WAAW,CAAC;SACnD,CAAC;QACF,GA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Q,IAAI;YACjD,QAAQ,EAAE,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,QAAQ,CAAC;SAClD,CAAC;QACF,GAAG,CAAC,OAAO,cAAc,CAAC,MAAM,KAAK,QAAQ,IAAI;YAC/C,MAAM,EAAE,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC;SAC9C,CAAC;QACF,GAAG,CAAC,OAAO,cAAc,CAAC,UAAU,KAAK,QAAQ,IAAI;YACnD,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC;SACtD,CAAC;QACF,GAAG,CAAC,OAAO,cAAc,CAAC,IAAI,KAAK,QAAQ,IAAI;YAC7C,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC;SAC1C,CAAC;QACF,GAAG,CAAC,cAAc,CAAC,WAAW,IAAI;YAChC,WAAW,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC;SAC9D,CAAC;KACH,CAAA;AACH,CAAC"}

52
node_modules/ox/_esm/core/Bloom.js generated vendored Normal file
View File

@@ -0,0 +1,52 @@
import * as Bytes from './Bytes.js';
import * as Hash from './Hash.js';
import * as Hex from './Hex.js';
/**
* Checks if an input is matched in the bloom filter.
*
* @example
* ```ts twoslash
* import { Bloom } from 'ox'
*
* Bloom.contains(
* '0x00000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002020000000000000000000000000000000000000000000008000000001000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
* '0xef2d6d194084c2de36e0dabfce45d046b37d1106',
* )
* // @log: true
* ```
*
* @param bloom - Bloom filter value.
* @param input - Input to check.
* @returns Whether the input is matched in the bloom filter.
*/
export function contains(bloom, input) {
const filter = Bytes.fromHex(bloom);
const hash = Hash.keccak256(input, { as: 'Bytes' });
for (const i of [0, 2, 4]) {
const bit = (hash[i + 1] + (hash[i] << 8)) & 0x7ff;
if ((filter[256 - 1 - Math.floor(bit / 8)] & (1 << (bit % 8))) === 0)
return false;
}
return true;
}
/**
* Checks if a string is a valid bloom filter value.
*
* @example
* ```ts twoslash
* import { Bloom } from 'ox'
*
* Bloom.validate('0x')
* // @log: false
*
* Bloom.validate('0x00000000000000000000008000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000044000200000000000000000002000000000000000000000040000000000000000000000000000020000000000000000000800000000000800000000000800000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000808002000000000400000000000000000000000060000000000000000000000000000000000000000000000100000000000002000000')
* // @log: true
* ```
*
* @param value - Value to check.
* @returns Whether the value is a valid bloom filter.
*/
export function validate(value) {
return Hex.validate(value) && Hex.size(value) === 256;
}
//# sourceMappingURL=Bloom.js.map

1
node_modules/ox/_esm/core/Bloom.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Bloom.js","sourceRoot":"","sources":["../../core/Bloom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAE/B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAc,EACd,KAA4B;IAE5B,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACnC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IAEnD,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAE,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;QACpD,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YACnE,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AASD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAA;AACvD,CAAC"}

133
node_modules/ox/_esm/core/Bls.js generated vendored Normal file
View File

@@ -0,0 +1,133 @@
import { bls12_381 as bls } from '@noble/curves/bls12-381';
import * as Bytes from './Bytes.js';
import * as Hex from './Hex.js';
/** Re-export of noble/curves BLS12-381 utilities. */
export const noble = bls;
// eslint-disable-next-line jsdoc/require-jsdoc
export function aggregate(points) {
const group = typeof points[0]?.x === 'bigint' ? bls.G1 : bls.G2;
const point = points.reduce((acc, point) => acc.add(new group.ProjectivePoint(point.x, point.y, point.z)), group.ProjectivePoint.ZERO);
return {
x: point.px,
y: point.py,
z: point.pz,
};
}
// eslint-disable-next-line jsdoc/require-jsdoc
export function getPublicKey(options) {
const { privateKey, size = 'short-key:long-sig' } = options;
const group = size === 'short-key:long-sig' ? bls.G1 : bls.G2;
const { px, py, pz } = group.ProjectivePoint.fromPrivateKey(Hex.from(privateKey).slice(2));
return { x: px, y: py, z: pz };
}
/**
* Generates a random BLS12-381 private key.
*
* @example
* ```ts twoslash
* import { Bls } from 'ox'
*
* const privateKey = Bls.randomPrivateKey()
* ```
*
* @param options - The options to generate the private key.
* @returns The generated private key.
*/
export function randomPrivateKey(options = {}) {
const { as = 'Hex' } = options;
const bytes = bls.utils.randomPrivateKey();
if (as === 'Hex')
return Hex.fromBytes(bytes);
return bytes;
}
// eslint-disable-next-line jsdoc/require-jsdoc
export function sign(options) {
const { payload, privateKey, suite, size = 'short-key:long-sig' } = options;
const payloadGroup = size === 'short-key:long-sig' ? bls.G2 : bls.G1;
const payloadPoint = payloadGroup.hashToCurve(Bytes.from(payload), suite ? { DST: Bytes.fromString(suite) } : undefined);
const privateKeyGroup = size === 'short-key:long-sig' ? bls.G1 : bls.G2;
const signature = payloadPoint.multiply(privateKeyGroup.normPrivateKeyToScalar(privateKey.slice(2)));
return {
x: signature.px,
y: signature.py,
z: signature.pz,
};
}
/**
* Verifies a payload was signed by the provided public key(s).
*
* @example
*
* ```ts twoslash
* import { Bls, Hex } from 'ox'
*
* const payload = Hex.random(32)
* const privateKey = Bls.randomPrivateKey()
*
* const publicKey = Bls.getPublicKey({ privateKey })
* const signature = Bls.sign({ payload, privateKey })
*
* const verified = Bls.verify({ // [!code focus]
* payload, // [!code focus]
* publicKey, // [!code focus]
* signature, // [!code focus]
* }) // [!code focus]
* ```
*
* @example
* ### Verify Aggregated Signatures
*
* We can also pass a public key and signature that was aggregated with {@link ox#Bls.(aggregate:function)} to `Bls.verify`.
*
* ```ts twoslash
* import { Bls, Hex } from 'ox'
*
* const payload = Hex.random(32)
* const privateKeys = Array.from({ length: 100 }, () => Bls.randomPrivateKey())
*
* const publicKeys = privateKeys.map((privateKey) =>
* Bls.getPublicKey({ privateKey }),
* )
* const signatures = privateKeys.map((privateKey) =>
* Bls.sign({ payload, privateKey }),
* )
*
* const publicKey = Bls.aggregate(publicKeys) // [!code focus]
* const signature = Bls.aggregate(signatures) // [!code focus]
*
* const valid = Bls.verify({ payload, publicKey, signature }) // [!code focus]
* ```
*
* @param options - Verification options.
* @returns Whether the payload was signed by the provided public key.
*/
export function verify(options) {
const { payload, suite } = options;
const publicKey = options.publicKey;
const signature = options.signature;
const isShortSig = typeof signature.x === 'bigint';
const group = isShortSig ? bls.G1 : bls.G2;
const payloadPoint = group.hashToCurve(Bytes.from(payload), suite ? { DST: Bytes.fromString(suite) } : undefined);
const shortSigPairing = () => bls.pairingBatch([
{
g1: payloadPoint,
g2: new bls.G2.ProjectivePoint(publicKey.x, publicKey.y, publicKey.z),
},
{
g1: new bls.G1.ProjectivePoint(signature.x, signature.y, signature.z),
g2: bls.G2.ProjectivePoint.BASE.negate(),
},
]);
const longSigPairing = () => bls.pairingBatch([
{
g1: new bls.G1.ProjectivePoint(publicKey.x, publicKey.y, publicKey.z).negate(),
g2: payloadPoint,
},
{
g1: bls.G1.ProjectivePoint.BASE,
g2: new bls.G2.ProjectivePoint(signature.x, signature.y, signature.z),
},
]);
return bls.fields.Fp12.eql(isShortSig ? shortSigPairing() : longSigPairing(), bls.fields.Fp12.ONE);
}
//# sourceMappingURL=Bls.js.map

1
node_modules/ox/_esm/core/Bls.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Bls.js","sourceRoot":"","sources":["../../core/Bls.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,IAAI,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAG1D,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAK/B,qDAAqD;AACrD,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,CAAA;AAuCxB,+CAA+C;AAC/C,MAAM,UAAU,SAAS,CACvB,MAAoC;IAEpC,MAAM,KAAK,GAAG,OAAO,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAA;IAChE,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CACzB,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CACb,GAAG,CAAC,GAAG,CAAC,IA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AU,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,cAAc,EAAE,EACjD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CACpB,CAAA;AACH,CAAC"}

51
node_modules/ox/_esm/core/BlsPoint.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
import { bls12_381 as bls } from '@noble/curves/bls12-381';
import * as Hex from './Hex.js';
/**
* Converts a BLS point to {@link ox#Bytes.Bytes}.
*
* @example
* ### Public Key to Bytes
* ```ts twoslash
* import { Bls, BlsPoint } from 'ox'
*
* const publicKey = Bls.getPublicKey({ privateKey: '0x...' })
* const publicKeyBytes = BlsPoint.toBytes(publicKey)
* // @log: Uint8Array [172, 175, 255, ...]
* ```
*
* @example
* ### Signature to Bytes
* ```ts twoslash
* import { Bls, BlsPoint } from 'ox'
*
* const signature = Bls.sign({ payload: '0x...', privateKey: '0x...' })
* const signatureBytes = BlsPoint.toBytes(signature)
* // @log: Uint8Array [172, 175, 255, ...]
* ```
*
* @param point - The BLS point to convert.
* @returns The bytes representation of the BLS point.
*/
export function toBytes(point) {
const group = typeof point.z === 'bigint' ? bls.G1 : bls.G2;
return new group.ProjectivePoint(point.x, point.y, point.z).toRawBytes();
}
// eslint-disable-next-line jsdoc/require-jsdoc
export function toHex(point) {
return Hex.fromBytes(toBytes(point));
}
// eslint-disable-next-line jsdoc/require-jsdoc
export function fromBytes(bytes) {
const group = bytes.length === 48 ? bls.G1 : bls.G2;
const point = group.ProjectivePoint.fromHex(bytes);
return {
x: point.px,
y: point.py,
z: point.pz,
};
}
// eslint-disable-next-line jsdoc/require-jsdoc
export function fromHex(hex, group) {
return fromBytes(Hex.toBytes(hex), group);
}
//# sourceMappingURL=BlsPoint.js.map

1
node_modules/ox/_esm/core/BlsPoint.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"BlsPoint.js","sourceRoot":"","sources":["../../core/BlsPoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAA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from '@noble/curves/abstract/utils';
import * as Errors from './Errors.js';
import * as Hex from './Hex.js';
import * as Json from './Json.js';
import * as internal from './internal/bytes.js';
import * as internal_hex from './internal/hex.js';
const decoder = /*#__PURE__*/ new TextDecoder();
const encoder = /*#__PURE__*/ new TextEncoder();
/**
* Asserts if the given value is {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.assert('abc')
* // @error: Bytes.InvalidBytesTypeError:
* // @error: Value `"abc"` of type `string` is an invalid Bytes value.
* // @error: Bytes values must be of type `Uint8Array`.
* ```
*
* @param value - Value to assert.
*/
export function assert(value) {
if (value instanceof Uint8Array)
return;
if (!value)
throw new InvalidBytesTypeError(value);
if (typeof value !== 'object')
throw new InvalidBytesTypeError(value);
if (!('BYTES_PER_ELEMENT' in value))
throw new InvalidBytesTypeError(value);
if (value.BYTES_PER_ELEMENT !== 1 || value.constructor.name !== 'Uint8Array')
throw new InvalidBytesTypeError(value);
}
/**
* Concatenates two or more {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const bytes = Bytes.concat(
* Bytes.from([1]),
* Bytes.from([69]),
* Bytes.from([420, 69]),
* )
* // @log: Uint8Array [ 1, 69, 420, 69 ]
* ```
*
* @param values - Values to concatenate.
* @returns Concatenated {@link ox#Bytes.Bytes}.
*/
export function concat(...values) {
let length = 0;
for (const arr of values) {
length += arr.length;
}
const result = new Uint8Array(length);
for (let i = 0, index = 0; i < values.length; i++) {
const arr = values[i];
result.set(arr, index);
index += arr.length;
}
return result;
}
/**
* Instantiates a {@link ox#Bytes.Bytes} value from a `Uint8Array`, a hex string, or an array of unsigned 8-bit integers.
*
* :::tip
*
* To instantiate from a **Boolean**, **String**, or **Number**, use one of the following:
*
* - `Bytes.fromBoolean`
*
* - `Bytes.fromString`
*
* - `Bytes.fromNumber`
*
* :::
*
* @example
* ```ts twoslash
* // @noErrors
* import { Bytes } from 'ox'
*
* const data = Bytes.from([255, 124, 5, 4])
* // @log: Uint8Array([255, 124, 5, 4])
*
* const data = Bytes.from('0xdeadbeef')
* // @log: Uint8Array([222, 173, 190, 239])
* ```
*
* @param value - Value to convert.
* @returns A {@link ox#Bytes.Bytes} instance.
*/
export function from(value) {
if (value instanceof Uint8Array)
return value;
if (typeof value === 'string')
return fromHex(value);
return fromArray(value);
}
/**
* Converts an array of unsigned 8-bit integers into {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const data = Bytes.fromArray([255, 124, 5, 4])
* // @log: Uint8Array([255, 124, 5, 4])
* ```
*
* @param value - Value to convert.
* @returns A {@link ox#Bytes.Bytes} instance.
*/
export function fromArray(value) {
return value instanceof Uint8Array ? value : new Uint8Array(value);
}
/**
* Encodes a boolean value into {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const data = Bytes.fromBoolean(true)
* // @log: Uint8Array([1])
* ```
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const data = Bytes.fromBoolean(true, { size: 32 })
* // @log: Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
* ```
*
* @param value - Boolean value to encode.
* @param options - Encoding options.
* @returns Encoded {@link ox#Bytes.Bytes}.
*/
export function fromBoolean(value, options = {}) {
const { size } = options;
const bytes = new Uint8Array(1);
bytes[0] = Number(value);
if (typeof size === 'number') {
internal.assertSize(bytes, size);
return padLeft(bytes, size);
}
return bytes;
}
/**
* Encodes a {@link ox#Hex.Hex} value into {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const data = Bytes.fromHex('0x48656c6c6f20776f726c6421')
* // @log: Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33])
* ```
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const data = Bytes.fromHex('0x48656c6c6f20776f726c6421', { size: 32 })
* // @log: Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
* ```
*
* @param value - {@link ox#Hex.Hex} value to encode.
* @param options - Encoding options.
* @returns Encoded {@link ox#Bytes.Bytes}.
*/
export function fromHex(value, options = {}) {
const { size } = options;
let hex = value;
if (size) {
internal_hex.assertSize(value, size);
hex = Hex.padRight(value, size);
}
let hexString = hex.slice(2);
if (hexString.length % 2)
hexString = `0${hexString}`;
const length = hexString.length / 2;
const bytes = new Uint8Array(length);
for (let index = 0, j = 0; index < length; index++) {
const nibbleLeft = internal.charCodeToBase16(hexString.charCodeAt(j++));
const nibbleRight = internal.charCodeToBase16(hexString.charCodeAt(j++));
if (nibbleLeft === undefined || nibbleRight === undefined) {
throw new Errors.BaseError(`Invalid byte sequence ("${hexString[j - 2]}${hexString[j - 1]}" in "${hexString}").`);
}
bytes[index] = nibbleLeft * 16 + nibbleRight;
}
return bytes;
}
/**
* Encodes a number value into {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const data = Bytes.fromNumber(420)
* // @log: Uint8Array([1, 164])
* ```
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const data = Bytes.fromNumber(420, { size: 4 })
* // @log: Uint8Array([0, 0, 1, 164])
* ```
*
* @param value - Number value to encode.
* @param options - Encoding options.
* @returns Encoded {@link ox#Bytes.Bytes}.
*/
export function fromNumber(value, options) {
const hex = Hex.fromNumber(value, options);
return fromHex(hex);
}
/**
* Encodes a string into {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const data = Bytes.fromString('Hello world!')
* // @log: Uint8Array([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33])
* ```
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const data = Bytes.fromString('Hello world!', { size: 32 })
* // @log: Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
* ```
*
* @param value - String to encode.
* @param options - Encoding options.
* @returns Encoded {@link ox#Bytes.Bytes}.
*/
export function fromString(value, options = {}) {
const { size } = options;
const bytes = encoder.encode(value);
if (typeof size === 'number') {
internal.assertSize(bytes, size);
return padRight(bytes, size);
}
return bytes;
}
/**
* Checks if two {@link ox#Bytes.Bytes} values are equal.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.isEqual(Bytes.from([1]), Bytes.from([1]))
* // @log: true
*
* Bytes.isEqual(Bytes.from([1]), Bytes.from([2]))
* // @log: false
* ```
*
* @param bytesA - First {@link ox#Bytes.Bytes} value.
* @param bytesB - Second {@link ox#Bytes.Bytes} value.
* @returns `true` if the two values are equal, otherwise `false`.
*/
export function isEqual(bytesA, bytesB) {
return equalBytes(bytesA, bytesB);
}
/**
* Pads a {@link ox#Bytes.Bytes} value to the left with zero bytes until it reaches the given `size` (default: 32 bytes).
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.padLeft(Bytes.from([1]), 4)
* // @log: Uint8Array([0, 0, 0, 1])
* ```
*
* @param value - {@link ox#Bytes.Bytes} value to pad.
* @param size - Size to pad the {@link ox#Bytes.Bytes} value to.
* @returns Padded {@link ox#Bytes.Bytes} value.
*/
export function padLeft(value, size) {
return internal.pad(value, { dir: 'left', size });
}
/**
* Pads a {@link ox#Bytes.Bytes} value to the right with zero bytes until it reaches the given `size` (default: 32 bytes).
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.padRight(Bytes.from([1]), 4)
* // @log: Uint8Array([1, 0, 0, 0])
* ```
*
* @param value - {@link ox#Bytes.Bytes} value to pad.
* @param size - Size to pad the {@link ox#Bytes.Bytes} value to.
* @returns Padded {@link ox#Bytes.Bytes} value.
*/
export function padRight(value, size) {
return internal.pad(value, { dir: 'right', size });
}
/**
* Generates random {@link ox#Bytes.Bytes} of the specified length.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const bytes = Bytes.random(32)
* // @log: Uint8Array([... x32])
* ```
*
* @param length - Length of the random {@link ox#Bytes.Bytes} to generate.
* @returns Random {@link ox#Bytes.Bytes} of the specified length.
*/
export function random(length) {
return crypto.getRandomValues(new Uint8Array(length));
}
/**
* Retrieves the size of a {@link ox#Bytes.Bytes} value.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.size(Bytes.from([1, 2, 3, 4]))
* // @log: 4
* ```
*
* @param value - {@link ox#Bytes.Bytes} value.
* @returns Size of the {@link ox#Bytes.Bytes} value.
*/
export function size(value) {
return value.length;
}
/**
* Returns a section of a {@link ox#Bytes.Bytes} value given a start/end bytes offset.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.slice(
* Bytes.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
* 1,
* 4,
* )
* // @log: Uint8Array([2, 3, 4])
* ```
*
* @param value - The {@link ox#Bytes.Bytes} value.
* @param start - Start offset.
* @param end - End offset.
* @param options - Slice options.
* @returns Sliced {@link ox#Bytes.Bytes} value.
*/
export function slice(value, start, end, options = {}) {
const { strict } = options;
internal.assertStartOffset(value, start);
const value_ = value.slice(start, end);
if (strict)
internal.assertEndOffset(value_, start, end);
return value_;
}
/**
* Decodes a {@link ox#Bytes.Bytes} into a bigint.
*
* @example
* ```ts
* import { Bytes } from 'ox'
*
* Bytes.toBigInt(Bytes.from([1, 164]))
* // @log: 420n
* ```
*
* @param bytes - The {@link ox#Bytes.Bytes} to decode.
* @param options - Decoding options.
* @returns Decoded bigint.
*/
export function toBigInt(bytes, options = {}) {
const { size } = options;
if (typeof size !== 'undefined')
internal.assertSize(bytes, size);
const hex = Hex.fromBytes(bytes, options);
return Hex.toBigInt(hex, options);
}
/**
* Decodes a {@link ox#Bytes.Bytes} into a boolean.
*
* @example
* ```ts
* import { Bytes } from 'ox'
*
* Bytes.toBoolean(Bytes.from([1]))
* // @log: true
* ```
*
* @param bytes - The {@link ox#Bytes.Bytes} to decode.
* @param options - Decoding options.
* @returns Decoded boolean.
*/
export function toBoolean(bytes, options = {}) {
const { size } = options;
let bytes_ = bytes;
if (typeof size !== 'undefined') {
internal.assertSize(bytes_, size);
bytes_ = trimLeft(bytes_);
}
if (bytes_.length > 1 || bytes_[0] > 1)
throw new InvalidBytesBooleanError(bytes_);
return Boolean(bytes_[0]);
}
/**
* Encodes a {@link ox#Bytes.Bytes} value into a {@link ox#Hex.Hex} value.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.toHex(Bytes.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]))
* // '0x48656c6c6f20576f726c6421'
* ```
*
* @param value - The {@link ox#Bytes.Bytes} to decode.
* @param options - Options.
* @returns Decoded {@link ox#Hex.Hex} value.
*/
export function toHex(value, options = {}) {
return Hex.fromBytes(value, options);
}
/**
* Decodes a {@link ox#Bytes.Bytes} into a number.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.toNumber(Bytes.from([1, 164]))
* // @log: 420
* ```
*/
export function toNumber(bytes, options = {}) {
const { size } = options;
if (typeof size !== 'undefined')
internal.assertSize(bytes, size);
const hex = Hex.fromBytes(bytes, options);
return Hex.toNumber(hex, options);
}
/**
* Decodes a {@link ox#Bytes.Bytes} into a string.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* const data = Bytes.toString(Bytes.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]))
* // @log: 'Hello world'
* ```
*
* @param bytes - The {@link ox#Bytes.Bytes} to decode.
* @param options - Options.
* @returns Decoded string.
*/
export function toString(bytes, options = {}) {
const { size } = options;
let bytes_ = bytes;
if (typeof size !== 'undefined') {
internal.assertSize(bytes_, size);
bytes_ = trimRight(bytes_);
}
return decoder.decode(bytes_);
}
/**
* Trims leading zeros from a {@link ox#Bytes.Bytes} value.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.trimLeft(Bytes.from([0, 0, 0, 0, 1, 2, 3]))
* // @log: Uint8Array([1, 2, 3])
* ```
*
* @param value - {@link ox#Bytes.Bytes} value.
* @returns Trimmed {@link ox#Bytes.Bytes} value.
*/
export function trimLeft(value) {
return internal.trim(value, { dir: 'left' });
}
/**
* Trims trailing zeros from a {@link ox#Bytes.Bytes} value.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.trimRight(Bytes.from([1, 2, 3, 0, 0, 0, 0]))
* // @log: Uint8Array([1, 2, 3])
* ```
*
* @param value - {@link ox#Bytes.Bytes} value.
* @returns Trimmed {@link ox#Bytes.Bytes} value.
*/
export function trimRight(value) {
return internal.trim(value, { dir: 'right' });
}
/**
* Checks if the given value is {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.validate('0x')
* // @log: false
*
* Bytes.validate(Bytes.from([1, 2, 3]))
* // @log: true
* ```
*
* @param value - Value to check.
* @returns `true` if the value is {@link ox#Bytes.Bytes}, otherwise `false`.
*/
export function validate(value) {
try {
assert(value);
return true;
}
catch {
return false;
}
}
/**
* Thrown when the bytes value cannot be represented as a boolean.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.toBoolean(Bytes.from([5]))
* // @error: Bytes.InvalidBytesBooleanError: Bytes value `[5]` is not a valid boolean.
* // @error: The bytes array must contain a single byte of either a `0` or `1` value.
* ```
*/
export class InvalidBytesBooleanError extends Errors.BaseError {
constructor(bytes) {
super(`Bytes value \`${bytes}\` is not a valid boolean.`, {
metaMessages: [
'The bytes array must contain a single byte of either a `0` or `1` value.',
],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Bytes.InvalidBytesBooleanError'
});
}
}
/**
* Thrown when a value cannot be converted to bytes.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Bytes } from 'ox'
*
* Bytes.from('foo')
* // @error: Bytes.InvalidBytesTypeError: Value `foo` of type `string` is an invalid Bytes value.
* ```
*/
export class InvalidBytesTypeError extends Errors.BaseError {
constructor(value) {
super(`Value \`${typeof value === 'object' ? Json.stringify(value) : value}\` of type \`${typeof value}\` is an invalid Bytes value.`, {
metaMessages: ['Bytes values must be of type `Bytes`.'],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Bytes.InvalidBytesTypeError'
});
}
}
/**
* Thrown when a size exceeds the maximum allowed size.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.fromString('Hello World!', { size: 8 })
* // @error: Bytes.SizeOverflowError: Size cannot exceed `8` bytes. Given size: `12` bytes.
* ```
*/
export class SizeOverflowError extends Errors.BaseError {
constructor({ givenSize, maxSize }) {
super(`Size cannot exceed \`${maxSize}\` bytes. Given size: \`${givenSize}\` bytes.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Bytes.SizeOverflowError'
});
}
}
/**
* Thrown when a slice offset is out-of-bounds.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.slice(Bytes.from([1, 2, 3]), 4)
* // @error: Bytes.SliceOffsetOutOfBoundsError: Slice starting at offset `4` is out-of-bounds (size: `3`).
* ```
*/
export class SliceOffsetOutOfBoundsError extends Errors.BaseError {
constructor({ offset, position, size, }) {
super(`Slice ${position === 'start' ? 'starting' : 'ending'} at offset \`${offset}\` is out-of-bounds (size: \`${size}\`).`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Bytes.SliceOffsetOutOfBoundsError'
});
}
}
/**
* Thrown when a the padding size exceeds the maximum allowed size.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.padLeft(Bytes.fromString('Hello World!'), 8)
* // @error: [Bytes.SizeExceedsPaddingSizeError: Bytes size (`12`) exceeds padding size (`8`).
* ```
*/
export class SizeExceedsPaddingSizeError extends Errors.BaseError {
constructor({ size, targetSize, type, }) {
super(`${type.charAt(0).toUpperCase()}${type
.slice(1)
.toLowerCase()} size (\`${size}\`) exceeds padding size (\`${targetSize}\`).`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Bytes.SizeExceedsPaddingSizeError'
});
}
}
//# sourceMappingURL=Bytes.js.map

1
node_modules/ox/_esm/core/Bytes.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

19
node_modules/ox/_esm/core/Caches.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
import { LruMap } from './internal/lru.js';
const caches = {
checksum: /*#__PURE__*/ new LruMap(8192),
};
export const checksum = caches.checksum;
/**
* Clears all global caches.
*
* @example
* ```ts
* import { Caches } from 'ox'
* Caches.clear()
* ```
*/
export function clear() {
for (const cache of Object.values(caches))
cache.clear();
}
//# sourceMappingURL=Caches.js.map

1
node_modules/ox/_esm/core/Caches.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Caches.js","sourceRoot":"","sources":["../../core/Caches.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,MAAM,MAAM,GAAG;IACb,QAAQ,EAAE,aAAa,CAAC,IAAI,MAAM,CAAkB,IAAI,CAAC;CAC1D,CAAA;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;AAEvC;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK;IACnB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;QAAE,KAAK,CAAC,KAAK,EAAE,CAAA;AAC1D,CAAC"}

101
node_modules/ox/_esm/core/ContractAddress.js generated vendored Normal file
View File

@@ -0,0 +1,101 @@
import * as Address from './Address.js';
import * as Bytes from './Bytes.js';
import * as Hash from './Hash.js';
import * as Hex from './Hex.js';
import * as Rlp from './Rlp.js';
/**
* Computes Contract Address generated by the [CREATE](https://ethereum.stackexchange.com/questions/68943/create-opcode-what-does-it-really-do/68945#68945) or [CREATE2](https://eips.ethereum.org/EIPS/eip-1014) opcode.
*
* @example
* ### CREATE
*
* Computes via the [CREATE](https://ethereum.stackexchange.com/questions/68943/create-opcode-what-does-it-really-do/68945#68945) opcode. Shorthand for {@link ox#ContractAddress.(fromCreate:function)}.
*
* ```ts twoslash
* import { ContractAddress } from 'ox'
* ContractAddress.from({
* from: '0x1a1e021a302c237453d3d45c7b82b19ceeb7e2e6',
* nonce: 0n,
* })
* // @log: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
* ```
*
* @example
* ### CREATE2
*
* Computes via the [CREATE2](https://eips.ethereum.org/EIPS/eip-1014) opcode. Shorthand for {@link ox#ContractAddress.(fromCreate2:function)}.
*
* ```ts twoslash
* import { ContractAddress, Hex } from 'ox'
* ContractAddress.from({
* from: '0x1a1e021a302c237453d3d45c7b82b19ceeb7e2e6',
* bytecode: '0x6394198df16000526103ff60206004601c335afa6040516060f3',
* salt: Hex.fromString('hello world'),
* })
* // @log: '0x59fbB593ABe27Cb193b6ee5C5DC7bbde312290aB'
* ```
*
* @param options - Options.
* @returns Contract Address.
*/
export function from(options) {
if (options.salt)
return fromCreate2(options);
return fromCreate(options);
}
/**
* Computes contract address via [CREATE](https://ethereum.stackexchange.com/questions/68943/create-opcode-what-does-it-really-do/68945#68945) opcode.
*
* @example
* ```ts twoslash
* import { ContractAddress } from 'ox'
*
* ContractAddress.fromCreate({
* from: '0x1a1e021a302c237453d3d45c7b82b19ceeb7e2e6',
* nonce: 0n,
* })
* // @log: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
* ```
*
* @param options - Options for retrieving address.
* @returns Contract Address.
*/
export function fromCreate(options) {
const from = Bytes.fromHex(Address.from(options.from));
let nonce = Bytes.fromNumber(options.nonce);
if (nonce[0] === 0)
nonce = new Uint8Array([]);
return Address.from(`0x${Hash.keccak256(Rlp.fromBytes([from, nonce], { as: 'Hex' })).slice(26)}`);
}
/**
* Computes contract address via [CREATE2](https://eips.ethereum.org/EIPS/eip-1014) opcode.
*
* @example
* ```ts twoslash
* import { ContractAddress, Hex } from 'ox'
*
* ContractAddress.fromCreate2({
* from: '0x1a1e021a302c237453d3d45c7b82b19ceeb7e2e6',
* bytecode: '0x6394198df16000526103ff60206004601c335afa6040516060f3',
* salt: Hex.fromString('hello world'),
* })
* // @log: '0x59fbB593ABe27Cb193b6ee5C5DC7bbde312290aB'
* ```
*
* @param options - Options for retrieving address.
* @returns Contract Address.
*/
export function fromCreate2(options) {
const from = Bytes.fromHex(Address.from(options.from));
const salt = Bytes.padLeft(Bytes.validate(options.salt) ? options.salt : Bytes.fromHex(options.salt), 32);
const bytecodeHash = (() => {
if ('bytecodeHash' in options) {
if (Bytes.validate(options.bytecodeHash))
return options.bytecodeHash;
return Bytes.fromHex(options.bytecodeHash);
}
return Hash.keccak256(options.bytecode, { as: 'Bytes' });
})();
return Address.from(Hex.slice(Hash.keccak256(Bytes.concat(Bytes.fromHex('0xff'), from, salt, bytecodeHash), { as: 'Hex' }), 12));
}
//# sourceMappingURL=ContractAddress.js.map

1
node_modules/ox/_esm/core/ContractAddress.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"ContractAddress.js","sourceRoot":"","sources":["../../core/ContractAddress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAG/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,IAAI,CAAC,OAAqB;IACxC,IAAI,OAAO,C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YAAY,CAAC;gBAAE,OAAO,OAAO,CAAC,YAAY,CAAA;YACrE,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;QAC5C,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IAC1D,CAAC,CAAC,EAAE,CAAA;IAEJ,OAAO,OAAO,CAAC,IAAI,CACjB,GAAG,CAAC,KAAK,CACP,IAAI,CAAC,SAAS,CACZ,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,EAC7D,EAAE,EAAE,EAAE,KAAK,EAAE,CACd,EACD,EAAE,CACH,CACF,CAAA;AACH,CAAC"}

75
node_modules/ox/_esm/core/Ens.js generated vendored Normal file
View File

@@ -0,0 +1,75 @@
import { ens_normalize } from '@adraffy/ens-normalize';
import * as Bytes from './Bytes.js';
import * as Hash from './Hash.js';
import * as Hex from './Hex.js';
import * as internal from './internal/ens.js';
/**
* Hashes ENS label.
*
* Since ENS labels prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS labels](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `labelhash`. You can use the built-in {@link ox#Ens.(normalize:function)} function for this.
*
* @example
* ```ts twoslash
* import { Ens } from 'ox'
* Ens.labelhash('eth')
* '0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0'
* ```
*
* @param label - ENS label.
* @returns ENS labelhash.
*/
export function labelhash(label) {
const result = new Uint8Array(32).fill(0);
if (!label)
return Hex.fromBytes(result);
return (internal.unwrapLabelhash(label) || Hash.keccak256(Hex.fromString(label)));
}
/**
* Hashes ENS name.
*
* Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `namehash`. You can use the built-in {@link ox#Ens.(normalize:function)} function for this.
*
* @example
* ```ts twoslash
* import { Ens } from 'ox'
* Ens.namehash('wevm.eth')
* // @log: '0xf246651c1b9a6b141d19c2604e9a58f567973833990f830d882534a747801359'
* ```
*
* @param name - ENS name.
* @returns ENS namehash.
*/
export function namehash(name) {
let result = new Uint8Array(32).fill(0);
if (!name)
return Hex.fromBytes(result);
const labels = name.split('.');
// Iterate in reverse order building up hash
for (let i = labels.length - 1; i >= 0; i -= 1) {
const hashFromEncodedLabel = internal.unwrapLabelhash(labels[i]);
const hashed = hashFromEncodedLabel
? Bytes.fromHex(hashFromEncodedLabel)
: Hash.keccak256(Bytes.fromString(labels[i]), { as: 'Bytes' });
result = Hash.keccak256(Bytes.concat(result, hashed), { as: 'Bytes' });
}
return Hex.fromBytes(result);
}
/**
* Normalizes ENS name according to [ENSIP-15](https://github.com/ensdomains/docs/blob/9edf9443de4333a0ea7ec658a870672d5d180d53/ens-improvement-proposals/ensip-15-normalization-standard.md).
*
* For more info see [ENS documentation](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) on name processing.
*
* @example
* ```ts twoslash
* import { Ens } from 'ox'
* Ens.normalize('wevm.eth')
* // @log: 'wevm.eth'
* ```
*
* @param name - ENS name.
* @returns Normalized ENS name.
*/
export function normalize(name) {
return ens_normalize(name);
}
//# sourceMappingURL=Ens.js.map

1
node_modules/ox/_esm/core/Ens.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Ens.js","sourceRoot":"","sources":["../../core/Ens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,GAAG,MAAM,UAAU,C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C,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IACxE,CAAC;IAED,OAAO,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;AAC9B,CAAC;AAaD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC"}

105
node_modules/ox/_esm/core/Errors.js generated vendored Normal file
View File

@@ -0,0 +1,105 @@
import { getVersion } from './internal/errors.js';
/**
* Base error class inherited by all errors thrown by ox.
*
* @example
* ```ts
* import { Errors } from 'ox'
* throw new Errors.BaseError('An error occurred')
* ```
*/
export class BaseError extends Error {
constructor(shortMessage, options = {}) {
const details = (() => {
if (options.cause instanceof BaseError) {
if (options.cause.details)
return options.cause.details;
if (options.cause.shortMessage)
return options.cause.shortMessage;
}
if (options.cause?.message)
return options.cause.message;
return options.details;
})();
const docsPath = (() => {
if (options.cause instanceof BaseError)
return options.cause.docsPath || options.docsPath;
return options.docsPath;
})();
const docsBaseUrl = 'https://oxlib.sh';
const docs = `${docsBaseUrl}${docsPath ?? ''}`;
const message = [
shortMessage || 'An error occurred.',
...(options.metaMessages ? ['', ...options.metaMessages] : []),
...(details || docsPath
? [
'',
details ? `Details: ${details}` : undefined,
docsPath ? `See: ${docs}` : undefined,
]
: []),
]
.filter((x) => typeof x === 'string')
.join('\n');
super(message, options.cause ? { cause: options.cause } : undefined);
Object.defineProperty(this, "details", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "docs", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "docsPath", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "shortMessage", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "cause", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'BaseError'
});
Object.defineProperty(this, "version", {
enumerable: true,
configurable: true,
writable: true,
value: `ox@${getVersion()}`
});
this.cause = options.cause;
this.details = details;
this.docs = docs;
this.docsPath = docsPath;
this.shortMessage = shortMessage;
}
walk(fn) {
return walk(this, fn);
}
}
/** @internal */
function walk(err, fn) {
if (fn?.(err))
return err;
if (err && typeof err === 'object' && 'cause' in err && err.cause)
return walk(err.cause, fn);
return fn ? null : err;
}
//# sourceMappingURL=Errors.js.map

1
node_modules/ox/_esm/core/Errors.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Errors.js","sourceRoot":"","sources":["../../core/Errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAMjD;;;;;;;;GAQG;AACH,MAAM,OAAO,SAEX,SAAQ,KAAK;IAWb,YAAY,YAAoB,EAAE,UAAoC,EAAE;QACtE,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE;YACpB,IAAI,OAAO,CAAC,KAAK,YAAY,SAAS,EAAE,CAAC;gBACvC,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO;oBAAE,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAA;gBACvD,IAAI,OAAO,CAAC,KAAK,CAAC,YAAY;oBAAE,OAAO,OAAO,CAAC,KAAK,CAAC,YAAY,CAAA;YACnE,CAAC;YACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO;gBAAE,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAA;YACxD,OAAO,OAAO,CAAC,OAAQ,CAAA;QACzB,CAAC,CAAC,EAAE,CAAA;QACJ,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE;YACrB,IAAI,OAAO,CAAC,KAAK,YAAY,SAAS;gBACpC,OAAO,OAAO,CAAC,KAAK,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAA;YACn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QACxB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAID,IAAI,CAAC,EAAQ;QACX,OAAO,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IACvB,CAAC;CACF;AAWD,gBAAgB;AAChB,SAAS,IAAI,CACX,GAAY,EACZ,EAA4C;IAE5C,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAA;IACzB,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK;QAC/D,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IAC5B,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAA;AACxB,CAAC"}

2
node_modules/ox/_esm/core/Fee.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=Fee.js.map

1
node_modules/ox/_esm/core/Fee.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Fee.js","sourceRoot":"","sources":["../../core/Fee.ts"],"names":[],"mappings":""}

94
node_modules/ox/_esm/core/Filter.js generated vendored Normal file
View File

@@ -0,0 +1,94 @@
import * as Hex from './Hex.js';
/**
* Converts a {@link ox#Filter.Rpc} to an {@link ox#Filter.Filter}.
*
* @example
* ```ts twoslash
* import { Filter } from 'ox'
*
* const filter = Filter.fromRpc({
* address: '0xd3cda913deb6f67967b99d671a681250403edf27',
* fromBlock: 'latest',
* toBlock: '0x010f2c',
* topics: [
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
* null,
* '0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1',
* ],
* })
* // @log: {
* // @log: address: '0xd3cda913deb6f67967b99d671a681250403edf27',
* // @log: fromBlock: 'latest',
* // @log: toBlock: 69420n,
* // @log: topics: [
* // @log: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
* // @log: null,
* // @log: '0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1',
* // @log: ],
* // @log: }
* ```
*
* @param filter - The RPC filter to convert.
* @returns An instantiated {@link ox#Filter.Filter}.
*/
export function fromRpc(filter) {
const { fromBlock, toBlock } = filter;
return {
...filter,
...(fromBlock && {
fromBlock: Hex.validate(fromBlock, { strict: false })
? BigInt(fromBlock)
: fromBlock,
}),
...(toBlock && {
toBlock: Hex.validate(toBlock, { strict: false })
? BigInt(toBlock)
: toBlock,
}),
};
}
/**
* Converts a {@link ox#Filter.Filter} to a {@link ox#Filter.Rpc}.
*
* @example
* ```ts twoslash
* import { AbiEvent, Filter } from 'ox'
*
* const transfer = AbiEvent.from('event Transfer(address indexed, address indexed, uint256)')
* const { topics } = AbiEvent.encode(transfer)
*
* const filter = Filter.toRpc({
* address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
* topics,
* })
* // @log: {
* // @log: address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
* // @log: topics: [
* // @log: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
* // @log: ],
* // @log: }
* ```
*
* @param filter - The filter to convert.
* @returns An RPC filter.
*/
export function toRpc(filter) {
const { address, topics, fromBlock, toBlock } = filter;
return {
...(address && { address }),
...(topics && { topics }),
...(typeof fromBlock !== 'undefined'
? {
fromBlock: typeof fromBlock === 'bigint'
? Hex.fromNumber(fromBlock)
: fromBlock,
}
: {}),
...(typeof toBlock !== 'undefined'
? {
toBlock: typeof toBlock === 'bigint' ? Hex.fromNumber(toBlock) : toBlock,
}
: {}),
};
}
//# sourceMappingURL=Filter.js.map

1
node_modules/ox/_esm/core/Filter.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Filter.js","sourceRoot":"","sources":["../../core/Filter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK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AC,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO;aAClE;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAA;AACH,CAAC"}

118
node_modules/ox/_esm/core/Hash.js generated vendored Normal file
View File

@@ -0,0 +1,118 @@
import { ripemd160 as noble_ripemd160 } from '@noble/hashes/ripemd160';
import { keccak_256 as noble_keccak256 } from '@noble/hashes/sha3';
import { sha256 as noble_sha256 } from '@noble/hashes/sha256';
import * as Bytes from './Bytes.js';
import * as Hex from './Hex.js';
/**
* Calculates the [Keccak256](https://en.wikipedia.org/wiki/SHA-3) hash of a {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value.
*
* This function is a re-export of `keccak_256` from [`@noble/hashes`](https://github.com/paulmillr/noble-hashes), an audited & minimal JS hashing library.
*
* @example
* ```ts twoslash
* import { Hash } from 'ox'
*
* Hash.keccak256('0xdeadbeef')
* // @log: '0xd4fd4e189132273036449fc9e11198c739161b4c0116a9a2dccdfa1c492006f1'
* ```
*
* @example
* ### Calculate Hash of a String
*
* ```ts twoslash
* import { Hash, Hex } from 'ox'
*
* Hash.keccak256(Hex.fromString('hello world'))
* // @log: '0x3ea2f1d0abf3fc66cf29eebb70cbd4e7fe762ef8a09bcc06c8edf641230afec0'
* ```
*
* @example
* ### Configure Return Type
*
* ```ts twoslash
* import { Hash } from 'ox'
*
* Hash.keccak256('0xdeadbeef', { as: 'Bytes' })
* // @log: Uint8Array [...]
* ```
*
* @param value - {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value.
* @param options - Options.
* @returns Keccak256 hash.
*/
export function keccak256(value, options = {}) {
const { as = typeof value === 'string' ? 'Hex' : 'Bytes' } = options;
const bytes = noble_keccak256(Bytes.from(value));
if (as === 'Bytes')
return bytes;
return Hex.fromBytes(bytes);
}
/**
* Calculates the [Ripemd160](https://en.wikipedia.org/wiki/RIPEMD) hash of a {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value.
*
* This function is a re-export of `ripemd160` from [`@noble/hashes`](https://github.com/paulmillr/noble-hashes), an audited & minimal JS hashing library.
*
* @example
* ```ts twoslash
* import { Hash } from 'ox'
*
* Hash.ripemd160('0xdeadbeef')
* // '0x226821c2f5423e11fe9af68bd285c249db2e4b5a'
* ```
*
* @param value - {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value.
* @param options - Options.
* @returns Ripemd160 hash.
*/
export function ripemd160(value, options = {}) {
const { as = typeof value === 'string' ? 'Hex' : 'Bytes' } = options;
const bytes = noble_ripemd160(Bytes.from(value));
if (as === 'Bytes')
return bytes;
return Hex.fromBytes(bytes);
}
/**
* Calculates the [Sha256](https://en.wikipedia.org/wiki/SHA-256) hash of a {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value.
*
* This function is a re-export of `sha256` from [`@noble/hashes`](https://github.com/paulmillr/noble-hashes), an audited & minimal JS hashing library.
*
* @example
* ```ts twoslash
* import { Hash } from 'ox'
*
* Hash.sha256('0xdeadbeef')
* // '0x5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953'
* ```
*
* @param value - {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value.
* @param options - Options.
* @returns Sha256 hash.
*/
export function sha256(value, options = {}) {
const { as = typeof value === 'string' ? 'Hex' : 'Bytes' } = options;
const bytes = noble_sha256(Bytes.from(value));
if (as === 'Bytes')
return bytes;
return Hex.fromBytes(bytes);
}
/**
* Checks if a string is a valid hash value.
*
* @example
* ```ts twoslash
* import { Hash } from 'ox'
*
* Hash.validate('0x')
* // @log: false
*
* Hash.validate('0x3ea2f1d0abf3fc66cf29eebb70cbd4e7fe762ef8a09bcc06c8edf641230afec0')
* // @log: true
* ```
*
* @param value - Value to check.
* @returns Whether the value is a valid hash.
*/
export function validate(value) {
return Hex.validate(value) && Hex.size(value) === 32;
}
//# sourceMappingURL=Hash.js.map

1
node_modules/ox/_esm/core/Hash.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{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gBG;AACH,MAAM,UAAU,MAAM,CAMpB,KAAoC,EACpC,UAA8B,EAAE;IAEhC,MAAM,EAAE,EAAE,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,OAAO,CAAA;IACpE,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;IAC7C,IAAI,EAAE,KAAK,OAAO;QAAE,OAAO,KAAc,CAAA;IACzC,OAAO,GAAG,CAAC,SAAS,CAAC,KAAK,CAAU,CAAA;AACtC,CAAC;AAkBD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;AACtD,CAAC"}

96
node_modules/ox/_esm/core/HdKey.js generated vendored Normal file
View File

@@ -0,0 +1,96 @@
import { HDKey } from '@scure/bip32';
import * as Bytes from './Bytes.js';
import * as internal from './internal/hdKey.js';
/**
* Creates a HD Key from an extended private key.
*
* @example
* ```ts twoslash
* import { HdKey } from 'ox'
*
* const hdKey = HdKey.fromExtendedKey('...')
*
* console.log(hdKey.privateKey)
* // @log: '0x...'
* ```
*
* @param extendedKey - The extended private key.
* @returns The HD Key.
*/
export function fromExtendedKey(extendedKey) {
const key = HDKey.fromExtendedKey(extendedKey);
return internal.fromScure(key);
}
/**
* Creates a HD Key from a JSON object containing an extended private key (`xpriv`).
*
* @example
* ```ts twoslash
* import { HdKey } from 'ox'
*
* const hdKey = HdKey.fromJson({ xpriv: '...' })
*
* console.log(hdKey.privateKey)
* // @log: '0x...'
* ```
*
* @param json - The JSON object containing an extended private key (`xpriv`).
* @returns The HD Key.
*/
export function fromJson(json) {
return internal.fromScure(HDKey.fromJSON(json));
}
/**
* Creates a HD Key from a master seed.
*
* @example
* ```ts twoslash
* import { HdKey, Mnemonic } from 'ox'
*
* const seed = Mnemonic.toSeed('test test test test test test test test test test test junk')
* const hdKey = HdKey.fromSeed(seed)
* ```
*
* @example
* ### Path Derivation
*
* You can derive a HD Key at a specific path using `derive`.
*
* ```ts twoslash
* import { HdKey, Mnemonic } from 'ox'
*
* const mnemonic = Mnemonic.toSeed('test test test test test test test test test test test junk')
* const hdKey = HdKey.fromSeed(mnemonic).derive(HdKey.path())
*
* console.log(hdKey.privateKey)
* // @log: '0x...'
* ```
*
* @param seed - The master seed to create the HD Key from.
* @param options - Creation options.
* @returns The HD Key.
*/
export function fromSeed(seed, options = {}) {
const { versions } = options;
const key = HDKey.fromMasterSeed(Bytes.from(seed), versions);
return internal.fromScure(key);
}
/**
* Creates an Ethereum-based BIP-44 HD path.
*
* @example
* ```ts twoslash
* import { HdKey } from 'ox'
*
* const path = HdKey.path({ account: 1, index: 2 })
* // @log: "m/44'/60'/1'/0/2"
* ```
*
* @param options - Path options.
* @returns The path.
*/
export function path(options = {}) {
const { account = 0, change = 0, index = 0 } = options;
return `m/44'/60'/${account}'/${change}/${index}`;
}
//# sourceMappingURL=HdKey.js.map

1
node_modules/ox/_esm/core/HdKey.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"HdKey.js","sourceRoot":"","sources":["../../core/HdKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAiB,MAAM,cAAc,CAAA;AACnD,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAInC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAe/C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,eAAe,CAAC,WAAmB;IACjD,MAAM,GAAG,GAAG,KAAK,CAAC,eAAe,CAAC,WAAW,CAAC,CAAA;IAC9C,OAAO,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;AAChC,CAAC;AAMD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAuB;IAC9C,OAAO,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;AACjD,CAAC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,QAAQ,CACtB,IAA2B,EAC3B,UAA4B,EAAE;IAE9B,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAC5B,MAAM,GAAG,GAAG,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,CAAA;IAC5D,OAAO,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;AAChC,CAAC;AAcD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,IAAI,CAAC,UAAwB,EAAE;IAC7C,MAAM,EAAE,OAAO,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,OAAO,CAAA;IACtD,OAAO,aAAa,OAAO,KAAK,MAAM,IAAI,KAAK,EAAE,CAAA;AACnD,CAAC"}

716
node_modules/ox/_esm/core/Hex.js generated vendored Normal file
View File

@@ -0,0 +1,716 @@
import { equalBytes } from '@noble/curves/abstract/utils';
import * as Bytes from './Bytes.js';
import * as Errors from './Errors.js';
import * as Json from './Json.js';
import * as internal_bytes from './internal/bytes.js';
import * as internal from './internal/hex.js';
const encoder = /*#__PURE__*/ new TextEncoder();
const hexes = /*#__PURE__*/ Array.from({ length: 256 }, (_v, i) => i.toString(16).padStart(2, '0'));
/**
* Asserts if the given value is {@link ox#Hex.Hex}.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.assert('abc')
* // @error: InvalidHexValueTypeError:
* // @error: Value `"abc"` of type `string` is an invalid hex type.
* // @error: Hex types must be represented as `"0x\${string}"`.
* ```
*
* @param value - The value to assert.
* @param options - Options.
*/
export function assert(value, options = {}) {
const { strict = false } = options;
if (!value)
throw new InvalidHexTypeError(value);
if (typeof value !== 'string')
throw new InvalidHexTypeError(value);
if (strict) {
if (!/^0x[0-9a-fA-F]*$/.test(value))
throw new InvalidHexValueError(value);
}
if (!value.startsWith('0x'))
throw new InvalidHexValueError(value);
}
/**
* Concatenates two or more {@link ox#Hex.Hex}.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.concat('0x123', '0x456')
* // @log: '0x123456'
* ```
*
* @param values - The {@link ox#Hex.Hex} values to concatenate.
* @returns The concatenated {@link ox#Hex.Hex} value.
*/
export function concat(...values) {
return `0x${values.reduce((acc, x) => acc + x.replace('0x', ''), '')}`;
}
/**
* Instantiates a {@link ox#Hex.Hex} value from a hex string or {@link ox#Bytes.Bytes} value.
*
* :::tip
*
* To instantiate from a **Boolean**, **String**, or **Number**, use one of the following:
*
* - `Hex.fromBoolean`
*
* - `Hex.fromString`
*
* - `Hex.fromNumber`
*
* :::
*
* @example
* ```ts twoslash
* import { Bytes, Hex } from 'ox'
*
* Hex.from('0x48656c6c6f20576f726c6421')
* // @log: '0x48656c6c6f20576f726c6421'
*
* Hex.from(Bytes.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]))
* // @log: '0x48656c6c6f20576f726c6421'
* ```
*
* @param value - The {@link ox#Bytes.Bytes} value to encode.
* @returns The encoded {@link ox#Hex.Hex} value.
*/
export function from(value) {
if (value instanceof Uint8Array)
return fromBytes(value);
if (Array.isArray(value))
return fromBytes(new Uint8Array(value));
return value;
}
/**
* Encodes a boolean into a {@link ox#Hex.Hex} value.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.fromBoolean(true)
* // @log: '0x1'
*
* Hex.fromBoolean(false)
* // @log: '0x0'
*
* Hex.fromBoolean(true, { size: 32 })
* // @log: '0x0000000000000000000000000000000000000000000000000000000000000001'
* ```
*
* @param value - The boolean value to encode.
* @param options - Options.
* @returns The encoded {@link ox#Hex.Hex} value.
*/
export function fromBoolean(value, options = {}) {
const hex = `0x${Number(value)}`;
if (typeof options.size === 'number') {
internal.assertSize(hex, options.size);
return padLeft(hex, options.size);
}
return hex;
}
/**
* Encodes a {@link ox#Bytes.Bytes} value into a {@link ox#Hex.Hex} value.
*
* @example
* ```ts twoslash
* import { Bytes, Hex } from 'ox'
*
* Hex.fromBytes(Bytes.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]))
* // @log: '0x48656c6c6f20576f726c6421'
* ```
*
* @param value - The {@link ox#Bytes.Bytes} value to encode.
* @param options - Options.
* @returns The encoded {@link ox#Hex.Hex} value.
*/
export function fromBytes(value, options = {}) {
let string = '';
for (let i = 0; i < value.length; i++)
string += hexes[value[i]];
const hex = `0x${string}`;
if (typeof options.size === 'number') {
internal.assertSize(hex, options.size);
return padRight(hex, options.size);
}
return hex;
}
/**
* Encodes a number or bigint into a {@link ox#Hex.Hex} value.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.fromNumber(420)
* // @log: '0x1a4'
*
* Hex.fromNumber(420, { size: 32 })
* // @log: '0x00000000000000000000000000000000000000000000000000000000000001a4'
* ```
*
* @param value - The number or bigint value to encode.
* @param options - Options.
* @returns The encoded {@link ox#Hex.Hex} value.
*/
export function fromNumber(value, options = {}) {
const { signed, size } = options;
const value_ = BigInt(value);
let maxValue;
if (size) {
if (signed)
maxValue = (1n << (BigInt(size) * 8n - 1n)) - 1n;
else
maxValue = 2n ** (BigInt(size) * 8n) - 1n;
}
else if (typeof value === 'number') {
maxValue = BigInt(Number.MAX_SAFE_INTEGER);
}
const minValue = typeof maxValue === 'bigint' && signed ? -maxValue - 1n : 0;
if ((maxValue && value_ > maxValue) || value_ < minValue) {
const suffix = typeof value === 'bigint' ? 'n' : '';
throw new IntegerOutOfRangeError({
max: maxValue ? `${maxValue}${suffix}` : undefined,
min: `${minValue}${suffix}`,
signed,
size,
value: `${value}${suffix}`,
});
}
const stringValue = (signed && value_ < 0 ? (1n << BigInt(size * 8)) + BigInt(value_) : value_).toString(16);
const hex = `0x${stringValue}`;
if (size)
return padLeft(hex, size);
return hex;
}
/**
* Encodes a string into a {@link ox#Hex.Hex} value.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
* Hex.fromString('Hello World!')
* // '0x48656c6c6f20576f726c6421'
*
* Hex.fromString('Hello World!', { size: 32 })
* // '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000'
* ```
*
* @param value - The string value to encode.
* @param options - Options.
* @returns The encoded {@link ox#Hex.Hex} value.
*/
export function fromString(value, options = {}) {
return fromBytes(encoder.encode(value), options);
}
/**
* Checks if two {@link ox#Hex.Hex} values are equal.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.isEqual('0xdeadbeef', '0xdeadbeef')
* // @log: true
*
* Hex.isEqual('0xda', '0xba')
* // @log: false
* ```
*
* @param hexA - The first {@link ox#Hex.Hex} value.
* @param hexB - The second {@link ox#Hex.Hex} value.
* @returns `true` if the two {@link ox#Hex.Hex} values are equal, `false` otherwise.
*/
export function isEqual(hexA, hexB) {
return equalBytes(Bytes.fromHex(hexA), Bytes.fromHex(hexB));
}
/**
* Pads a {@link ox#Hex.Hex} value to the left with zero bytes until it reaches the given `size` (default: 32 bytes).
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.padLeft('0x1234', 4)
* // @log: '0x00001234'
* ```
*
* @param value - The {@link ox#Hex.Hex} value to pad.
* @param size - The size (in bytes) of the output hex value.
* @returns The padded {@link ox#Hex.Hex} value.
*/
export function padLeft(value, size) {
return internal.pad(value, { dir: 'left', size });
}
/**
* Pads a {@link ox#Hex.Hex} value to the right with zero bytes until it reaches the given `size` (default: 32 bytes).
*
* @example
* ```ts
* import { Hex } from 'ox'
*
* Hex.padRight('0x1234', 4)
* // @log: '0x12340000'
* ```
*
* @param value - The {@link ox#Hex.Hex} value to pad.
* @param size - The size (in bytes) of the output hex value.
* @returns The padded {@link ox#Hex.Hex} value.
*/
export function padRight(value, size) {
return internal.pad(value, { dir: 'right', size });
}
/**
* Generates a random {@link ox#Hex.Hex} value of the specified length.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* const hex = Hex.random(32)
* // @log: '0x...'
* ```
*
* @returns Random {@link ox#Hex.Hex} value.
*/
export function random(length) {
return fromBytes(Bytes.random(length));
}
/**
* Returns a section of a {@link ox#Bytes.Bytes} value given a start/end bytes offset.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.slice('0x0123456789', 1, 4)
* // @log: '0x234567'
* ```
*
* @param value - The {@link ox#Hex.Hex} value to slice.
* @param start - The start offset (in bytes).
* @param end - The end offset (in bytes).
* @param options - Options.
* @returns The sliced {@link ox#Hex.Hex} value.
*/
export function slice(value, start, end, options = {}) {
const { strict } = options;
internal.assertStartOffset(value, start);
const value_ = `0x${value
.replace('0x', '')
.slice((start ?? 0) * 2, (end ?? value.length) * 2)}`;
if (strict)
internal.assertEndOffset(value_, start, end);
return value_;
}
/**
* Retrieves the size of a {@link ox#Hex.Hex} value (in bytes).
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.size('0xdeadbeef')
* // @log: 4
* ```
*
* @param value - The {@link ox#Hex.Hex} value to get the size of.
* @returns The size of the {@link ox#Hex.Hex} value (in bytes).
*/
export function size(value) {
return Math.ceil((value.length - 2) / 2);
}
/**
* Trims leading zeros from a {@link ox#Hex.Hex} value.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.trimLeft('0x00000000deadbeef')
* // @log: '0xdeadbeef'
* ```
*
* @param value - The {@link ox#Hex.Hex} value to trim.
* @returns The trimmed {@link ox#Hex.Hex} value.
*/
export function trimLeft(value) {
return internal.trim(value, { dir: 'left' });
}
/**
* Trims trailing zeros from a {@link ox#Hex.Hex} value.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.trimRight('0xdeadbeef00000000')
* // @log: '0xdeadbeef'
* ```
*
* @param value - The {@link ox#Hex.Hex} value to trim.
* @returns The trimmed {@link ox#Hex.Hex} value.
*/
export function trimRight(value) {
return internal.trim(value, { dir: 'right' });
}
/**
* Decodes a {@link ox#Hex.Hex} value into a BigInt.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.toBigInt('0x1a4')
* // @log: 420n
*
* Hex.toBigInt('0x00000000000000000000000000000000000000000000000000000000000001a4', { size: 32 })
* // @log: 420n
* ```
*
* @param hex - The {@link ox#Hex.Hex} value to decode.
* @param options - Options.
* @returns The decoded BigInt.
*/
export function toBigInt(hex, options = {}) {
const { signed } = options;
if (options.size)
internal.assertSize(hex, options.size);
const value = BigInt(hex);
if (!signed)
return value;
const size = (hex.length - 2) / 2;
const max_unsigned = (1n << (BigInt(size) * 8n)) - 1n;
const max_signed = max_unsigned >> 1n;
if (value <= max_signed)
return value;
return value - max_unsigned - 1n;
}
/**
* Decodes a {@link ox#Hex.Hex} value into a boolean.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.toBoolean('0x01')
* // @log: true
*
* Hex.toBoolean('0x0000000000000000000000000000000000000000000000000000000000000001', { size: 32 })
* // @log: true
* ```
*
* @param hex - The {@link ox#Hex.Hex} value to decode.
* @param options - Options.
* @returns The decoded boolean.
*/
export function toBoolean(hex, options = {}) {
if (options.size)
internal.assertSize(hex, options.size);
const hex_ = trimLeft(hex);
if (hex_ === '0x')
return false;
if (hex_ === '0x1')
return true;
throw new InvalidHexBooleanError(hex);
}
/**
* Decodes a {@link ox#Hex.Hex} value into a {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* const data = Hex.toBytes('0x48656c6c6f20776f726c6421')
* // @log: Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33])
* ```
*
* @param hex - The {@link ox#Hex.Hex} value to decode.
* @param options - Options.
* @returns The decoded {@link ox#Bytes.Bytes}.
*/
export function toBytes(hex, options = {}) {
return Bytes.fromHex(hex, options);
}
/**
* Decodes a {@link ox#Hex.Hex} value into a number.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.toNumber('0x1a4')
* // @log: 420
*
* Hex.toNumber('0x00000000000000000000000000000000000000000000000000000000000001a4', { size: 32 })
* // @log: 420
* ```
*
* @param hex - The {@link ox#Hex.Hex} value to decode.
* @param options - Options.
* @returns The decoded number.
*/
export function toNumber(hex, options = {}) {
const { signed, size } = options;
if (!signed && !size)
return Number(hex);
return Number(toBigInt(hex, options));
}
/**
* Decodes a {@link ox#Hex.Hex} value into a string.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.toString('0x48656c6c6f20576f726c6421')
* // @log: 'Hello world!'
*
* Hex.toString('0x48656c6c6f20576f726c64210000000000000000000000000000000000000000', {
* size: 32,
* })
* // @log: 'Hello world'
* ```
*
* @param hex - The {@link ox#Hex.Hex} value to decode.
* @param options - Options.
* @returns The decoded string.
*/
export function toString(hex, options = {}) {
const { size } = options;
let bytes = Bytes.fromHex(hex);
if (size) {
internal_bytes.assertSize(bytes, size);
bytes = Bytes.trimRight(bytes);
}
return new TextDecoder().decode(bytes);
}
/**
* Checks if the given value is {@link ox#Hex.Hex}.
*
* @example
* ```ts twoslash
* import { Bytes, Hex } from 'ox'
*
* Hex.validate('0xdeadbeef')
* // @log: true
*
* Hex.validate(Bytes.from([1, 2, 3]))
* // @log: false
* ```
*
* @param value - The value to check.
* @param options - Options.
* @returns `true` if the value is a {@link ox#Hex.Hex}, `false` otherwise.
*/
export function validate(value, options = {}) {
const { strict = false } = options;
try {
assert(value, { strict });
return true;
}
catch {
return false;
}
}
/**
* Thrown when the provided integer is out of range, and cannot be represented as a hex value.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.fromNumber(420182738912731283712937129)
* // @error: Hex.IntegerOutOfRangeError: Number \`4.2018273891273126e+26\` is not in safe unsigned integer range (`0` to `9007199254740991`)
* ```
*/
export class IntegerOutOfRangeError extends Errors.BaseError {
constructor({ max, min, signed, size, value, }) {
super(`Number \`${value}\` is not in safe${size ? ` ${size * 8}-bit` : ''}${signed ? ' signed' : ' unsigned'} integer range ${max ? `(\`${min}\` to \`${max}\`)` : `(above \`${min}\`)`}`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Hex.IntegerOutOfRangeError'
});
}
}
/**
* Thrown when the provided hex value cannot be represented as a boolean.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.toBoolean('0xa')
* // @error: Hex.InvalidHexBooleanError: Hex value `"0xa"` is not a valid boolean.
* // @error: The hex value must be `"0x0"` (false) or `"0x1"` (true).
* ```
*/
export class InvalidHexBooleanError extends Errors.BaseError {
constructor(hex) {
super(`Hex value \`"${hex}"\` is not a valid boolean.`, {
metaMessages: [
'The hex value must be `"0x0"` (false) or `"0x1"` (true).',
],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Hex.InvalidHexBooleanError'
});
}
}
/**
* Thrown when the provided value is not a valid hex type.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.assert(1)
* // @error: Hex.InvalidHexTypeError: Value `1` of type `number` is an invalid hex type.
* ```
*/
export class InvalidHexTypeError extends Errors.BaseError {
constructor(value) {
super(`Value \`${typeof value === 'object' ? Json.stringify(value) : value}\` of type \`${typeof value}\` is an invalid hex type.`, {
metaMessages: ['Hex types must be represented as `"0x${string}"`.'],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Hex.InvalidHexTypeError'
});
}
}
/**
* Thrown when the provided hex value is invalid.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.assert('0x0123456789abcdefg')
* // @error: Hex.InvalidHexValueError: Value `0x0123456789abcdefg` is an invalid hex value.
* // @error: Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).
* ```
*/
export class InvalidHexValueError extends Errors.BaseError {
constructor(value) {
super(`Value \`${value}\` is an invalid hex value.`, {
metaMessages: [
'Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).',
],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Hex.InvalidHexValueError'
});
}
}
/**
* Thrown when the provided hex value is an odd length.
*
* @example
* ```ts twoslash
* import { Bytes } from 'ox'
*
* Bytes.fromHex('0xabcde')
* // @error: Hex.InvalidLengthError: Hex value `"0xabcde"` is an odd length (5 nibbles).
* ```
*/
export class InvalidLengthError extends Errors.BaseError {
constructor(value) {
super(`Hex value \`"${value}"\` is an odd length (${value.length - 2} nibbles).`, {
metaMessages: ['It must be an even length.'],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Hex.InvalidLengthError'
});
}
}
/**
* Thrown when the size of the value exceeds the expected max size.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.fromString('Hello World!', { size: 8 })
* // @error: Hex.SizeOverflowError: Size cannot exceed `8` bytes. Given size: `12` bytes.
* ```
*/
export class SizeOverflowError extends Errors.BaseError {
constructor({ givenSize, maxSize }) {
super(`Size cannot exceed \`${maxSize}\` bytes. Given size: \`${givenSize}\` bytes.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Hex.SizeOverflowError'
});
}
}
/**
* Thrown when the slice offset exceeds the bounds of the value.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.slice('0x0123456789', 6)
* // @error: Hex.SliceOffsetOutOfBoundsError: Slice starting at offset `6` is out-of-bounds (size: `5`).
* ```
*/
export class SliceOffsetOutOfBoundsError extends Errors.BaseError {
constructor({ offset, position, size, }) {
super(`Slice ${position === 'start' ? 'starting' : 'ending'} at offset \`${offset}\` is out-of-bounds (size: \`${size}\`).`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Hex.SliceOffsetOutOfBoundsError'
});
}
}
/**
* Thrown when the size of the value exceeds the pad size.
*
* @example
* ```ts twoslash
* import { Hex } from 'ox'
*
* Hex.padLeft('0x1a4e12a45a21323123aaa87a897a897a898a6567a578a867a98778a667a85a875a87a6a787a65a675a6a9', 32)
* // @error: Hex.SizeExceedsPaddingSizeError: Hex size (`43`) exceeds padding size (`32`).
* ```
*/
export class SizeExceedsPaddingSizeError extends Errors.BaseError {
constructor({ size, targetSize, type, }) {
super(`${type.charAt(0).toUpperCase()}${type
.slice(1)
.toLowerCase()} size (\`${size}\`) exceeds padding size (\`${targetSize}\`).`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Hex.SizeExceedsPaddingSizeError'
});
}
}
//# sourceMappingURL=Hex.js.map

1
node_modules/ox/_esm/core/Hex.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

56
node_modules/ox/_esm/core/Json.js generated vendored Normal file
View File

@@ -0,0 +1,56 @@
const bigIntSuffix = '#__bigint';
/**
* Parses a JSON string, with support for `bigint`.
*
* @example
* ```ts twoslash
* import { Json } from 'ox'
*
* const json = Json.parse('{"foo":"bar","baz":"69420694206942069420694206942069420694206942069420#__bigint"}')
* // @log: {
* // @log: foo: 'bar',
* // @log: baz: 69420694206942069420694206942069420694206942069420n
* // @log: }
* ```
*
* @param string - The value to parse.
* @param reviver - A function that transforms the results.
* @returns The parsed value.
*/
export function parse(string, reviver) {
return JSON.parse(string, (key, value_) => {
const value = value_;
if (typeof value === 'string' && value.endsWith(bigIntSuffix))
return BigInt(value.slice(0, -bigIntSuffix.length));
return typeof reviver === 'function' ? reviver(key, value) : value;
});
}
/**
* Stringifies a value to its JSON representation, with support for `bigint`.
*
* @example
* ```ts twoslash
* import { Json } from 'ox'
*
* const json = Json.stringify({
* foo: 'bar',
* baz: 69420694206942069420694206942069420694206942069420n,
* })
* // @log: '{"foo":"bar","baz":"69420694206942069420694206942069420694206942069420#__bigint"}'
* ```
*
* @param value - The value to stringify.
* @param replacer - A function that transforms the results. It is passed the key and value of the property, and must return the value to be used in the JSON string. If this function returns `undefined`, the property is not included in the resulting JSON string.
* @param space - A string or number that determines the indentation of the JSON string. If it is a number, it indicates the number of spaces to use as indentation; if it is a string (e.g. `'\t'`), it uses the string as the indentation character.
* @returns The JSON string.
*/
export function stringify(value, replacer, space) {
return JSON.stringify(value, (key, value) => {
if (typeof replacer === 'function')
return replacer(key, value);
if (typeof value === 'bigint')
return value.toString() + bigIntSuffix;
return value;
}, space);
}
//# sourceMappingURL=Json.js.map

1
node_modules/ox/_esm/core/Json.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Json.js","sourceRoot":"","sources":["../../core/Json.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG,WAAW,CAAA;AAEhC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,KAAK,CACnB,MAAc,EACd,OAAmE;IAEnE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;QACxC,MAAM,KAAK,GAAG,MAAM,CAAA;QACpB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC;YAC3D,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAA;QACrD,OAAO,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;IACpE,CAAC,CAAC,CAAA;AACJ,CAAC;AAMD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,SAAS,CACvB,KAAU,EACV,QAA2E,EAC3E,KAAmC;IAEnC,OAAO,IAAI,CAAC,SAAS,CACnB,KAAK,EACL,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACb,IAAI,OAAO,QAAQ,KAAK,UAAU;YAAE,OAAO,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QAC/D,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC,QAAQ,EAAE,GAAG,YAAY,CAAA;QACrE,OAAO,KAAK,CAAA;IACd,CAAC,EACD,KAAK,CACN,CAAA;AACH,CAAC"}

28
node_modules/ox/_esm/core/Kzg.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
/** @see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4844.md#parameters */
export const versionedHashVersion = 1;
/**
* Defines a KZG interface.
*
* @example
* ```ts twoslash
* // @noErrors
* import * as cKzg from 'c-kzg'
* import { Kzg } from 'ox'
* import { Paths } from 'ox/trusted-setups'
*
* cKzg.loadTrustedSetup(Paths.mainnet)
*
* const kzg = Kzg.from(cKzg)
* ```
*
* @param value - The KZG object to convert.
* @returns The KZG interface object.
*/
export function from(value) {
const { blobToKzgCommitment, computeBlobKzgProof } = value;
return {
blobToKzgCommitment,
computeBlobKzgProof,
};
}
//# sourceMappingURL=Kzg.js.map

1
node_modules/ox/_esm/core/Kzg.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Kzg.js","sourceRoot":"","sources":["../../core/Kzg.ts"],"names":[],"mappings":"AAGA,oFAAoF;AACpF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA;AAerC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,IAAI,CAAC,KAAU;IAC7B,MAAM,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,GAAG,KAAK,CAAA;IAC1D,OAAO;QACL,mBAAmB;QACnB,mBAAmB;KACpB,CAAA;AACH,CAAC"}

175
node_modules/ox/_esm/core/Log.js generated vendored Normal file
View File

@@ -0,0 +1,175 @@
import * as Hex from './Hex.js';
/**
* Converts a {@link ox#Log.Rpc} to an {@link ox#Log.Log}.
*
* @example
* ```ts twoslash
* import { Log } from 'ox'
*
* const log = Log.fromRpc({
* address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
* topics: [
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
* '0x0000000000000000000000000000000000000000000000000000000000000000',
* '0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1',
* '0x000000000000000000000000000000000000000000000000000000000000025b',
* ],
* data: '0x',
* blockHash:
* '0xabe69134e80a12f6a93d0aa18215b5b86c2fb338bae911790ca374a8716e01a4',
* blockNumber: '0x12d846c',
* transactionHash:
* '0xcfa52db0bc2cb5bdcb2c5bd8816df7a2f018a0e3964ab1ef4d794cf327966e93',
* transactionIndex: '0x91',
* logIndex: '0x10f',
* removed: false,
* })
* // @log: {
* // @log: address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
* // @log: blockHash: '0xabe69134e80a12f6a93d0aa18215b5b86c2fb338bae911790ca374a8716e01a4',
* // @log: blockNumber: 19760236n,
* // @log: data: '0x',
* // @log: logIndex: 271,
* // @log: removed: false,
* // @log: topics: [
* // @log: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
* // @log: "0x0000000000000000000000000000000000000000000000000000000000000000",
* // @log: "0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1",
* // @log: "0x000000000000000000000000000000000000000000000000000000000000025b",
* // @log: transactionHash:
* // @log: '0xcfa52db0bc2cb5bdcb2c5bd8816df7a2f018a0e3964ab1ef4d794cf327966e93',
* // @log: transactionIndex: 145,
* // @log: }
* ```
*
* @example
* ### End-to-end
*
* Below is an example of how to use `Log.fromRpc` to instantiate a {@link ox#Log.Log} from an RPC log.
*
* ```ts twoslash
* import 'ox/window'
* import { AbiEvent, Hex, Log } from 'ox'
*
* const transfer = AbiEvent.from(
* 'event Transfer(address indexed from, address indexed to, uint256 indexed value)',
* )
*
* const { topics } = AbiEvent.encode(transfer)
*
* const logs = await window.ethereum!.request({
* method: 'eth_getLogs',
* params: [
* {
* address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
* fromBlock: Hex.fromNumber(19760235n),
* toBlock: Hex.fromNumber(19760240n),
* topics,
* },
* ],
* })
*
* const log = Log.fromRpc(logs[0]) // [!code focus]
* // @log: {
* // @log: address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
* // @log: blockHash: '0xabe69134e80a12f6a93d0aa18215b5b86c2fb338bae911790ca374a8716e01a4',
* // @log: blockNumber: 19760236n,
* // @log: data: '0x',
* // @log: logIndex: 271,
* // @log: removed: false,
* // @log: topics: [
* // @log: "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
* // @log: "0x0000000000000000000000000000000000000000000000000000000000000000",
* // @log: "0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1",
* // @log: "0x000000000000000000000000000000000000000000000000000000000000025b",
* // @log: transactionHash:
* // @log: '0xcfa52db0bc2cb5bdcb2c5bd8816df7a2f018a0e3964ab1ef4d794cf327966e93',
* // @log: transactionIndex: 145,
* // @log: }
* ```
*
* :::note
*
* For simplicity, the above example uses `window.ethereum.request`, but you can use any
* type of JSON-RPC interface.
*
* :::
*
* @param log - The RPC log to convert.
* @returns An instantiated {@link ox#Log.Log}.
*/
export function fromRpc(log, _options = {}) {
return {
...log,
blockNumber: log.blockNumber ? BigInt(log.blockNumber) : null,
logIndex: log.logIndex ? Number(log.logIndex) : null,
transactionIndex: log.transactionIndex
? Number(log.transactionIndex)
: null,
};
}
/**
* Converts a {@link ox#Log.Log} to a {@link ox#Log.Rpc}.
*
* @example
* ```ts twoslash
* import { Log } from 'ox'
*
* const log = Log.toRpc({
* address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
* blockHash:
* '0xabe69134e80a12f6a93d0aa18215b5b86c2fb338bae911790ca374a8716e01a4',
* blockNumber: 19760236n,
* data: '0x',
* logIndex: 271,
* removed: false,
* topics: [
* '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
* '0x0000000000000000000000000000000000000000000000000000000000000000',
* '0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1',
* '0x000000000000000000000000000000000000000000000000000000000000025b',
* ],
* transactionHash:
* '0xcfa52db0bc2cb5bdcb2c5bd8816df7a2f018a0e3964ab1ef4d794cf327966e93',
* transactionIndex: 145,
* })
* // @log: {
* // @log: address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
* // @log: blockHash: '0xabe69134e80a12f6a93d0aa18215b5b86c2fb338bae911790ca374a8716e01a4',
* // @log: blockNumber: '0x012d846c',
* // @log: data: '0x',
* // @log: logIndex: '0x010f',
* // @log: removed: false,
* // @log: topics: [
* // @log: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
* // @log: '0x0000000000000000000000000000000000000000000000000000000000000000',
* // @log: '0x0000000000000000000000000c04d9e9278ec5e4d424476d3ebec70cb5d648d1',
* // @log: '0x000000000000000000000000000000000000000000000000000000000000025b',
* // @log: ],
* // @log: transactionHash:
* // @log: '0xcfa52db0bc2cb5bdcb2c5bd8816df7a2f018a0e3964ab1ef4d794cf327966e93',
* // @log: transactionIndex: '0x91',
* // @log: }
* ```
*
* @param log - The log to convert.
* @returns An RPC log.
*/
export function toRpc(log, _options = {}) {
return {
address: log.address,
blockHash: log.blockHash,
blockNumber: typeof log.blockNumber === 'bigint'
? Hex.fromNumber(log.blockNumber)
: null,
data: log.data,
logIndex: typeof log.logIndex === 'number' ? Hex.fromNumber(log.logIndex) : null,
topics: log.topics,
transactionHash: log.transactionHash,
transactionIndex: typeof log.transactionIndex === 'number'
? Hex.fromNumber(log.transactionIndex)
: null,
removed: log.removed,
};
}
//# sourceMappingURL=Log.js.map

1
node_modules/ox/_esm/core/Log.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Log.js","sourceRoot":"","sources":["../../core/Log.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAoC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC,UAAU,CAAC,GAAG,CAAC,gBAAgB,CAAC;YACtC,CAAC,CAAC,IAAI;QACV,OAAO,EAAE,GAAG,CAAC,OAAO;KACL,CAAA;AACnB,CAAC"}

139
node_modules/ox/_esm/core/Mnemonic.js generated vendored Normal file
View File

@@ -0,0 +1,139 @@
import { generateMnemonic, mnemonicToSeedSync, validateMnemonic, } from '@scure/bip39';
import * as Bytes from './Bytes.js';
import * as HdKey from './HdKey.js';
export { path } from './HdKey.js';
export { english, czech, french, italian, japanese, korean, portuguese, simplifiedChinese, spanish, traditionalChinese, } from './internal/mnemonic/wordlists.js';
/**
* Generates a random mnemonic.
*
* @example
* ```ts twoslash
* import { Mnemonic } from 'ox'
*
* const mnemonic = Mnemonic.random(Mnemonic.english)
* // @log: 'buyer zoo end danger ice capable shrug naive twist relief mass bonus'
* ```
*
* @param wordlist - The wordlist to use.
* @param options - Generation options.
* @returns The mnemonic.
*/
export function random(wordlist, options = {}) {
const { strength = 128 } = options;
return generateMnemonic(wordlist, strength);
}
/**
* Converts a mnemonic to a HD Key.
*
* @example
* ```ts twoslash
* import { Mnemonic } from 'ox'
*
* const mnemonic = Mnemonic.random(Mnemonic.english)
* const hdKey = Mnemonic.toHdKey(mnemonic)
* ```
*
* @example
* ### Path Derivation
*
* You can derive a HD Key at a specific path using `derive`:
*
* ```ts twoslash
* import { Mnemonic } from 'ox'
*
* const mnemonic = Mnemonic.random(Mnemonic.english)
* const hdKey = Mnemonic.toHdKey(mnemonic).derive(Mnemonic.path({ index: 1 }))
* ```
*
* @param mnemonic - The mnemonic to convert.
* @param options - Conversion options.
* @returns The HD Key.
*/
export function toHdKey(mnemonic, options = {}) {
const { passphrase } = options;
const seed = toSeed(mnemonic, { passphrase });
return HdKey.fromSeed(seed);
}
/**
* Converts a mnemonic to a private key.
*
* @example
* ```ts twoslash
* import { Mnemonic } from 'ox'
*
* const mnemonic = Mnemonic.random(Mnemonic.english)
* const privateKey = Mnemonic.toPrivateKey(mnemonic)
* // @log: '0x...'
* ```
*
* @example
* ### Paths
*
* You can derive a private key at a specific path using the `path` option.
*
* ```ts twoslash
* import { Mnemonic } from 'ox'
*
* const mnemonic = Mnemonic.random(Mnemonic.english)
* const privateKey = Mnemonic.toPrivateKey(mnemonic, {
* path: Mnemonic.path({ index: 1 }) // 'm/44'/60'/0'/0/1' // [!code focus]
* })
* // @log: '0x...'
* ```
*
* @param mnemonic - The mnemonic to convert.
* @param options - Conversion options.
* @returns The private key.
*/
export function toPrivateKey(mnemonic, options = {}) {
const { path = HdKey.path(), passphrase } = options;
const hdKey = toHdKey(mnemonic, { passphrase }).derive(path);
if (options.as === 'Bytes')
return Bytes.from(hdKey.privateKey);
return hdKey.privateKey;
}
/**
* Converts a mnemonic to a master seed.
*
* @example
* ```ts twoslash
* import { Mnemonic } from 'ox'
*
* const mnemonic = Mnemonic.random(Mnemonic.english)
* const seed = Mnemonic.toSeed(mnemonic)
* // @log: Uint8Array [...64 bytes]
* ```
*
* @param mnemonic - The mnemonic to convert.
* @param options - Conversion options.
* @returns The master seed.
*/
export function toSeed(mnemonic, options = {}) {
const { passphrase } = options;
const seed = mnemonicToSeedSync(mnemonic, passphrase);
if (options.as === 'Hex')
return Bytes.toHex(seed);
return seed;
}
/**
* Checks if a mnemonic is valid, given a wordlist.
*
* @example
* ```ts twoslash
* import { Mnemonic } from 'ox'
*
* const mnemonic = Mnemonic.validate(
* 'buyer zoo end danger ice capable shrug naive twist relief mass bonus',
* Mnemonic.english
* )
* // @log: true
* ```
*
* @param mnemonic - The mnemonic to validate.
* @param wordlist - The wordlist to use.
* @returns Whether the mnemonic is valid.
*/
export function validate(mnemonic, wordlist) {
return validateMnemonic(mnemonic, wordlist);
}
//# sourceMappingURL=Mnemonic.js.map

1
node_modules/ox/_esm/core/Mnemonic.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Mnemonic.js","sourceRoot":"","sources":["../../core/Mnemonic.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gB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,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAU,CAAA;IACxE,OAAO,KAAK,CAAC,UAAmB,CAAA;AAClC,CAAC;AAmBD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,MAAM,CACpB,QAAgB,EAChB,UAA8B,EAAE;IAEhC,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAA;IAC9B,MAAM,IAAI,GAAG,kBAAkB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;IACrD,IAAI,OAAO,CAAC,EAAE,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAU,CAAA;IAC3D,OAAO,IAAa,CAAA;AACtB,CAAC;AAiBD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAgB,EAAE,QAAkB;IAC3D,OAAO,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;AAC7C,CAAC"}

131
node_modules/ox/_esm/core/P256.js generated vendored Normal file
View File

@@ -0,0 +1,131 @@
import { secp256r1 } from '@noble/curves/p256';
import * as Bytes from './Bytes.js';
import * as Hex from './Hex.js';
import * as PublicKey from './PublicKey.js';
import * as Entropy from './internal/entropy.js';
/** Re-export of noble/curves P256 utilities. */
export const noble = secp256r1;
/**
* Computes the P256 ECDSA public key from a provided private key.
*
* @example
* ```ts twoslash
* import { P256 } from 'ox'
*
* const publicKey = P256.getPublicKey({ privateKey: '0x...' })
* ```
*
* @param options - The options to compute the public key.
* @returns The computed public key.
*/
export function getPublicKey(options) {
const { privateKey } = options;
const point = secp256r1.ProjectivePoint.fromPrivateKey(typeof privateKey === 'string'
? privateKey.slice(2)
: Hex.fromBytes(privateKey).slice(2));
return PublicKey.from(point);
}
/**
* Generates a random P256 ECDSA private key.
*
* @example
* ```ts twoslash
* import { P256 } from 'ox'
*
* const privateKey = P256.randomPrivateKey()
* ```
*
* @param options - The options to generate the private key.
* @returns The generated private key.
*/
export function randomPrivateKey(options = {}) {
const { as = 'Hex' } = options;
const bytes = secp256r1.utils.randomPrivateKey();
if (as === 'Hex')
return Hex.fromBytes(bytes);
return bytes;
}
/**
* Recovers the signing public key from the signed payload and signature.
*
* @example
* ```ts twoslash
* import { P256 } from 'ox'
*
* const signature = P256.sign({ payload: '0xdeadbeef', privateKey: '0x...' })
*
* const publicKey = P256.recoverPublicKey({ // [!code focus]
* payload: '0xdeadbeef', // [!code focus]
* signature, // [!code focus]
* }) // [!code focus]
* ```
*
* @param options - The recovery options.
* @returns The recovered public key.
*/
export function recoverPublicKey(options) {
const { payload, signature } = options;
const { r, s, yParity } = signature;
const signature_ = new secp256r1.Signature(BigInt(r), BigInt(s)).addRecoveryBit(yParity);
const payload_ = payload instanceof Uint8Array ? Hex.fromBytes(payload) : payload;
const point = signature_.recoverPublicKey(payload_.substring(2));
return PublicKey.from(point);
}
/**
* Signs the payload with the provided private key and returns a P256 signature.
*
* @example
* ```ts twoslash
* import { P256 } from 'ox'
*
* const signature = P256.sign({ // [!code focus]
* payload: '0xdeadbeef', // [!code focus]
* privateKey: '0x...' // [!code focus]
* }) // [!code focus]
* ```
*
* @param options - The signing options.
* @returns The ECDSA {@link ox#Signature.Signature}.
*/
export function sign(options) {
const { extraEntropy = Entropy.extraEntropy, hash, payload, privateKey, } = options;
const { r, s, recovery } = secp256r1.sign(payload instanceof Uint8Array ? payload : Bytes.fromHex(payload), privateKey instanceof Uint8Array ? privateKey : Bytes.fromHex(privateKey), {
extraEntropy: typeof extraEntropy === 'boolean'
? extraEntropy
: Hex.from(extraEntropy).slice(2),
lowS: true,
...(hash ? { prehash: true } : {}),
});
return {
r,
s,
yParity: recovery,
};
}
/**
* Verifies a payload was signed by the provided public key.
*
* @example
*
* ```ts twoslash
* import { P256 } from 'ox'
*
* const privateKey = P256.randomPrivateKey()
* const publicKey = P256.getPublicKey({ privateKey })
* const signature = P256.sign({ payload: '0xdeadbeef', privateKey })
*
* const verified = P256.verify({ // [!code focus]
* publicKey, // [!code focus]
* payload: '0xdeadbeef', // [!code focus]
* signature, // [!code focus]
* }) // [!code focus]
* ```
*
* @param options - The verification options.
* @returns Whether the payload was signed by the provided public key.
*/
export function verify(options) {
const { hash, payload, publicKey, signature } = options;
return secp256r1.verify(signature, payload instanceof Uint8Array ? payload : Bytes.fromHex(payload), PublicKey.toHex(publicKey).substring(2), ...(hash ? [{ prehash: true, lowS: true }] : []));
}
//# sourceMappingURL=P256.js.map

1
node_modules/ox/_esm/core/P256.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"P256.js","sourceRoot":"","sources":["../../core/P256.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAA;AAEhD,gDAAgD;AAChD,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAA;AAE9B;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,OAA6B;IAE7B,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAA;IAC9B,MAAM,KAAK,GAAG,SAAS,CAAC,eAAe,CAAC,cAAc,CACpD,OAAO,UAAU,KAAK,QAAQ;QAC5B,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QACrB,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CACvC,CAAA;IACD,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC;AAaD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAAwC,EAAE;IAE1C,MAAM,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,OAAO,C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,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EACzE;QACE,YAAY,EACV,OAAO,YAAY,KAAK,SAAS;YAC/B,CAAC,CAAC,YAAY;YACd,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QACrC,IAAI,EAAE,IAAI;QACV,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACnC,CACF,CAAA;IACD,OAAO;QACL,CAAC;QACD,CAAC;QACD,OAAO,EAAE,QAAQ;KAClB,CAAA;AACH,CAAC;AA0BD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,MAAM,CAAC,OAAuB;IAC5C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IACvD,OAAO,SAAS,CAAC,MAAM,CACrB,SAAS,EACT,OAAO,YAAY,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAChE,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACvC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CACjD,CAAA;AACH,CAAC"}

42
node_modules/ox/_esm/core/PersonalMessage.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
import * as Hash from './Hash.js';
import * as Hex from './Hex.js';
/**
* Encodes a personal sign message in [ERC-191 format](https://eips.ethereum.org/EIPS/eip-191#version-0x45-e): `0x19 ‖ "Ethereum Signed Message:\n" + message.length ‖ message`.
*
* @example
* ```ts twoslash
* import { Hex, PersonalMessage } from 'ox'
*
* const data = PersonalMessage.encode(Hex.fromString('hello world'))
* // @log: '0x19457468657265756d205369676e6564204d6573736167653a0a313168656c6c6f20776f726c64'
* // @log: (0x19 ‖ 'Ethereum Signed Message:\n11' ‖ 'hello world')
* ```
*
* @param data - The data to encode.
* @returns The encoded personal sign message.
*/
export function encode(data) {
const message = Hex.from(data);
return Hex.concat(
// Personal Sign Format: `0x19 ‖ "Ethereum Signed Message:\n" ‖ message.length ‖ message`
'0x19', Hex.fromString('Ethereum Signed Message:\n' + Hex.size(message)), message);
}
/**
* Gets the payload to use for signing an [ERC-191 formatted](https://eips.ethereum.org/EIPS/eip-191#version-0x45-e) personal message.
*
* @example
* ```ts twoslash
* import { Hex, PersonalMessage, Secp256k1 } from 'ox'
*
* const payload = PersonalMessage.getSignPayload(Hex.fromString('hello world')) // [!code focus]
*
* const signature = Secp256k1.sign({ payload, privateKey: '0x...' })
* ```
*
* @param data - The data to get the sign payload for.
* @returns The payload to use for signing.
*/
export function getSignPayload(data) {
return Hash.keccak256(encode(data));
}
//# sourceMappingURL=PersonalMessage.js.map

1
node_modules/ox/_esm/core/PersonalMessage.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"PersonalMessage.js","sourceRoot":"","sources":["../../core/PersonalMessage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAE/B;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,MAAM,CAAC,IAA2B;IAChD,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC9B,OAAO,GAAG,CAAC,MAAM;IACf,yFAAyF;IACzF,MAAM,EACN,GAAG,CAAC,UAAU,CAAC,4BAA4B,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAChE,OAAO,CACR,CAAA;AACH,CAAC;AAUD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAC,IAA2B;IACxD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;AACrC,CAAC"}

281
node_modules/ox/_esm/core/Provider.js generated vendored Normal file
View File

@@ -0,0 +1,281 @@
import { EventEmitter } from 'eventemitter3';
import * as Errors from './Errors.js';
import * as RpcResponse from './RpcResponse.js';
export class ProviderRpcError extends Error {
constructor(code, message) {
super(message);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'ProviderRpcError'
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "details", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.code = code;
this.details = message;
}
}
/** The user rejected the request. */
export class UserRejectedRequestError extends ProviderRpcError {
constructor({ message = 'The user rejected the request.', } = {}) {
super(4001, message);
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: 4001
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Provider.UserRejectedRequestError'
});
}
}
Object.defineProperty(UserRejectedRequestError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: 4001
});
/** The requested method and/or account has not been authorized by the user. */
export class UnauthorizedError extends ProviderRpcError {
constructor({ message = 'The requested method and/or account has not been authorized by the user.', } = {}) {
super(4100, message);
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: 4100
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Provider.UnauthorizedError'
});
}
}
Object.defineProperty(UnauthorizedError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: 4100
});
/** The provider does not support the requested method. */
export class UnsupportedMethodError extends ProviderRpcError {
constructor({ message = 'The provider does not support the requested method.', } = {}) {
super(4200, message);
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: 4200
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Provider.UnsupportedMethodError'
});
}
}
Object.defineProperty(UnsupportedMethodError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: 4200
});
/** The provider is disconnected from all chains. */
export class DisconnectedError extends ProviderRpcError {
constructor({ message = 'The provider is disconnected from all chains.', } = {}) {
super(4900, message);
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: 4900
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Provider.DisconnectedError'
});
}
}
Object.defineProperty(DisconnectedError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: 4900
});
/** The provider is not connected to the requested chain. */
export class ChainDisconnectedError extends ProviderRpcError {
constructor({ message = 'The provider is not connected to the requested chain.', } = {}) {
super(4901, message);
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: 4901
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Provider.ChainDisconnectedError'
});
}
}
Object.defineProperty(ChainDisconnectedError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: 4901
});
/**
* Creates an EIP-1193 flavored event emitter to be injected onto a Provider.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Provider, RpcRequest, RpcResponse } from 'ox' // [!code focus]
*
* // 1. Instantiate a Provider Emitter. // [!code focus]
* const emitter = Provider.createEmitter() // [!code focus]
*
* const store = RpcRequest.createStore()
*
* const provider = Provider.from({
* // 2. Pass the Emitter to the Provider. // [!code focus]
* ...emitter, // [!code focus]
* async request(args) {
* return await fetch('https://1.rpc.thirdweb.com', {
* body: JSON.stringify(store.prepare(args)),
* method: 'POST',
* headers: {
* 'Content-Type': 'application/json',
* },
* })
* .then((res) => res.json())
* .then(RpcResponse.parse)
* },
* })
*
* // 3. Emit Provider Events. // [!code focus]
* emitter.emit('accountsChanged', ['0x...']) // [!code focus]
* ```
*
* @returns An event emitter.
*/
export function createEmitter() {
const emitter = new EventEmitter();
return {
get eventNames() {
return emitter.eventNames.bind(emitter);
},
get listenerCount() {
return emitter.listenerCount.bind(emitter);
},
get listeners() {
return emitter.listeners.bind(emitter);
},
addListener: emitter.addListener.bind(emitter),
emit: emitter.emit.bind(emitter),
off: emitter.off.bind(emitter),
on: emitter.on.bind(emitter),
once: emitter.once.bind(emitter),
removeAllListeners: emitter.removeAllListeners.bind(emitter),
removeListener: emitter.removeListener.bind(emitter),
};
}
// eslint-disable-next-line jsdoc/require-jsdoc
export function from(provider, options = {}) {
const { includeEvents = true } = options;
if (!provider)
throw new IsUndefinedError();
return {
...(includeEvents
? {
on: provider.on?.bind(provider),
removeListener: provider.removeListener?.bind(provider),
}
: {}),
async request(args) {
try {
const result = await provider.request(args);
if (result &&
typeof result === 'object' &&
'jsonrpc' in result)
return RpcResponse.parse(result);
return result;
}
catch (error) {
throw parseError(error);
}
},
};
}
/**
* Parses an error object into an error instance.
*
* @example
* ```ts twoslash
* import { Provider } from 'ox'
*
* const error = Provider.parseError({ code: 4200, message: 'foo' })
*
* error
* // ^?
*
* ```
*
* @param errorObject - The error object to parse.
* @returns An error instance.
*/
export function parseError(errorObject) {
const errorObject_ = errorObject;
const error = RpcResponse.parseError(errorObject_);
if (error instanceof RpcResponse.InternalError) {
if (!error.data)
return error;
const { code } = error.data;
if (code === DisconnectedError.code)
return new DisconnectedError(errorObject_);
if (code === ChainDisconnectedError.code)
return new ChainDisconnectedError(errorObject_);
if (code === UserRejectedRequestError.code)
return new UserRejectedRequestError(errorObject_);
if (code === UnauthorizedError.code)
return new UnauthorizedError(errorObject_);
if (code === UnsupportedMethodError.code)
return new UnsupportedMethodError(errorObject_);
}
return error;
}
/** Thrown when the provider is undefined. */
export class IsUndefinedError extends Errors.BaseError {
constructor() {
super('`provider` is undefined.');
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Provider.IsUndefinedError'
});
}
}
//# sourceMappingURL=Provider.js.map

1
node_modules/ox/_esm/core/Provider.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{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C,YAAY,CAAC,CAAA;IAClD,IAAI,KAAK,YAAY,WAAW,CAAC,aAAa,EAAE,CAAC;QAC/C,IAAI,CAAC,KAAK,CAAC,IAAI;YAAE,OAAO,KAAc,CAAA;QAEtC,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,IAA+B,CAAA;QACtD,IAAI,IAAI,KAAK,iBAAiB,CAAC,IAAI;YACjC,OAAO,IAAI,iBAAiB,CAAC,YAAY,CAAU,CAAA;QACrD,IAAI,IAAI,KAAK,sBAAsB,CAAC,IAAI;YACtC,OAAO,IAAI,sBAAsB,CAAC,YAAY,CAAU,CAAA;QAC1D,IAAI,IAAI,KAAK,wBAAwB,CAAC,IAAI;YACxC,OAAO,IAAI,wBAAwB,CAAC,YAAY,CAAU,CAAA;QAC5D,IAAI,IAAI,KAAK,iBAAiB,CAAC,IAAI;YACjC,OAAO,IAAI,iBAAiB,CAAC,YAAY,CAAU,CAAA;QACrD,IAAI,IAAI,KAAK,sBAAsB,CAAC,IAAI;YACtC,OAAO,IAAI,sBAAsB,CAAC,YAAY,CAAU,CAAA;IAC5D,CAAC;IACD,OAAO,KAAc,CAAA;AACvB,CAAC;AA4CD,6CAA6C;AAC7C,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,SAAS;IAGpD;QACE,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAHjB;;;;mBAAO,2BAA2B;WAAA;IAIpD,CAAC;CACF"}

377
node_modules/ox/_esm/core/PublicKey.js generated vendored Normal file
View File

@@ -0,0 +1,377 @@
import * as Bytes from './Bytes.js';
import * as Errors from './Errors.js';
import * as Hex from './Hex.js';
import * as Json from './Json.js';
/**
* Asserts that a {@link ox#PublicKey.PublicKey} is valid.
*
* @example
* ```ts twoslash
* import { PublicKey } from 'ox'
*
* PublicKey.assert({
* prefix: 4,
* y: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* })
* // @error: PublicKey.InvalidError: Value \`{"y":"1"}\` is not a valid public key.
* // @error: Public key must contain:
* // @error: - an `x` and `prefix` value (compressed)
* // @error: - an `x`, `y`, and `prefix` value (uncompressed)
* ```
*
* @param publicKey - The public key object to assert.
*/
export function assert(publicKey, options = {}) {
const { compressed } = options;
const { prefix, x, y } = publicKey;
// Uncompressed
if (compressed === false ||
(typeof x === 'bigint' && typeof y === 'bigint')) {
if (prefix !== 4)
throw new InvalidPrefixError({
prefix,
cause: new InvalidUncompressedPrefixError(),
});
return;
}
// Compressed
if (compressed === true ||
(typeof x === 'bigint' && typeof y === 'undefined')) {
if (prefix !== 3 && prefix !== 2)
throw new InvalidPrefixError({
prefix,
cause: new InvalidCompressedPrefixError(),
});
return;
}
// Unknown/invalid
throw new InvalidError({ publicKey });
}
/**
* Compresses a {@link ox#PublicKey.PublicKey}.
*
* @example
* ```ts twoslash
* import { PublicKey } from 'ox'
*
* const publicKey = PublicKey.from({
* prefix: 4,
* x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
* y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
* })
*
* const compressed = PublicKey.compress(publicKey) // [!code focus]
* // @log: {
* // @log: prefix: 3,
* // @log: x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
* // @log: }
* ```
*
* @param publicKey - The public key to compress.
* @returns The compressed public key.
*/
export function compress(publicKey) {
const { x, y } = publicKey;
return {
prefix: y % 2n === 0n ? 2 : 3,
x,
};
}
/**
* Instantiates a typed {@link ox#PublicKey.PublicKey} object from a {@link ox#PublicKey.PublicKey}, {@link ox#Bytes.Bytes}, or {@link ox#Hex.Hex}.
*
* @example
* ```ts twoslash
* import { PublicKey } from 'ox'
*
* const publicKey = PublicKey.from({
* prefix: 4,
* x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
* y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
* })
* // @log: {
* // @log: prefix: 4,
* // @log: x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
* // @log: y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
* // @log: }
* ```
*
* @example
* ### From Serialized
*
* ```ts twoslash
* import { PublicKey } from 'ox'
*
* const publicKey = PublicKey.from('0x048318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5')
* // @log: {
* // @log: prefix: 4,
* // @log: x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
* // @log: y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
* // @log: }
* ```
*
* @param value - The public key value to instantiate.
* @returns The instantiated {@link ox#PublicKey.PublicKey}.
*/
export function from(value) {
const publicKey = (() => {
if (Hex.validate(value))
return fromHex(value);
if (Bytes.validate(value))
return fromBytes(value);
const { prefix, x, y } = value;
if (typeof x === 'bigint' && typeof y === 'bigint')
return { prefix: prefix ?? 0x04, x, y };
return { prefix, x };
})();
assert(publicKey);
return publicKey;
}
/**
* Deserializes a {@link ox#PublicKey.PublicKey} from a {@link ox#Bytes.Bytes} value.
*
* @example
* ```ts twoslash
* // @noErrors
* import { PublicKey } from 'ox'
*
* const publicKey = PublicKey.fromBytes(new Uint8Array([128, 3, 131, ...]))
* // @log: {
* // @log: prefix: 4,
* // @log: x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
* // @log: y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
* // @log: }
* ```
*
* @param publicKey - The serialized public key.
* @returns The deserialized public key.
*/
export function fromBytes(publicKey) {
return fromHex(Hex.fromBytes(publicKey));
}
/**
* Deserializes a {@link ox#PublicKey.PublicKey} from a {@link ox#Hex.Hex} value.
*
* @example
* ```ts twoslash
* import { PublicKey } from 'ox'
*
* const publicKey = PublicKey.fromHex('0x8318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5')
* // @log: {
* // @log: prefix: 4,
* // @log: x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
* // @log: y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
* // @log: }
* ```
*
* @example
* ### Deserializing a Compressed Public Key
*
* ```ts twoslash
* import { PublicKey } from 'ox'
*
* const publicKey = PublicKey.fromHex('0x038318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed75')
* // @log: {
* // @log: prefix: 3,
* // @log: x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
* // @log: }
* ```
*
* @param publicKey - The serialized public key.
* @returns The deserialized public key.
*/
export function fromHex(publicKey) {
if (publicKey.length !== 132 &&
publicKey.length !== 130 &&
publicKey.length !== 68)
throw new InvalidSerializedSizeError({ publicKey });
if (publicKey.length === 130) {
const x = BigInt(Hex.slice(publicKey, 0, 32));
const y = BigInt(Hex.slice(publicKey, 32, 64));
return {
prefix: 4,
x,
y,
};
}
if (publicKey.length === 132) {
const prefix = Number(Hex.slice(publicKey, 0, 1));
const x = BigInt(Hex.slice(publicKey, 1, 33));
const y = BigInt(Hex.slice(publicKey, 33, 65));
return {
prefix,
x,
y,
};
}
const prefix = Number(Hex.slice(publicKey, 0, 1));
const x = BigInt(Hex.slice(publicKey, 1, 33));
return {
prefix,
x,
};
}
/**
* Serializes a {@link ox#PublicKey.PublicKey} to {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { PublicKey } from 'ox'
*
* const publicKey = PublicKey.from({
* prefix: 4,
* x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
* y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
* })
*
* const bytes = PublicKey.toBytes(publicKey) // [!code focus]
* // @log: Uint8Array [128, 3, 131, ...]
* ```
*
* @param publicKey - The public key to serialize.
* @returns The serialized public key.
*/
export function toBytes(publicKey, options = {}) {
return Bytes.fromHex(toHex(publicKey, options));
}
/**
* Serializes a {@link ox#PublicKey.PublicKey} to {@link ox#Hex.Hex}.
*
* @example
* ```ts twoslash
* import { PublicKey } from 'ox'
*
* const publicKey = PublicKey.from({
* prefix: 4,
* x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
* y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
* })
*
* const hex = PublicKey.toHex(publicKey) // [!code focus]
* // @log: '0x048318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5'
* ```
*
* @param publicKey - The public key to serialize.
* @returns The serialized public key.
*/
export function toHex(publicKey, options = {}) {
assert(publicKey);
const { prefix, x, y } = publicKey;
const { includePrefix = true } = options;
const publicKey_ = Hex.concat(includePrefix ? Hex.fromNumber(prefix, { size: 1 }) : '0x', Hex.fromNumber(x, { size: 32 }),
// If the public key is not compressed, add the y coordinate.
typeof y === 'bigint' ? Hex.fromNumber(y, { size: 32 }) : '0x');
return publicKey_;
}
/**
* Validates a {@link ox#PublicKey.PublicKey}. Returns `true` if valid, `false` otherwise.
*
* @example
* ```ts twoslash
* import { PublicKey } from 'ox'
*
* const valid = PublicKey.validate({
* prefix: 4,
* y: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* })
* // @log: false
* ```
*
* @param publicKey - The public key object to assert.
*/
export function validate(publicKey, options = {}) {
try {
assert(publicKey, options);
return true;
}
catch (error) {
return false;
}
}
/**
* Thrown when a public key is invalid.
*
* @example
* ```ts twoslash
* import { PublicKey } from 'ox'
*
* PublicKey.assert({ y: 1n })
* // @error: PublicKey.InvalidError: Value `{"y":1n}` is not a valid public key.
* // @error: Public key must contain:
* // @error: - an `x` and `prefix` value (compressed)
* // @error: - an `x`, `y`, and `prefix` value (uncompressed)
* ```
*/
export class InvalidError extends Errors.BaseError {
constructor({ publicKey }) {
super(`Value \`${Json.stringify(publicKey)}\` is not a valid public key.`, {
metaMessages: [
'Public key must contain:',
'- an `x` and `prefix` value (compressed)',
'- an `x`, `y`, and `prefix` value (uncompressed)',
],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'PublicKey.InvalidError'
});
}
}
/** Thrown when a public key has an invalid prefix. */
export class InvalidPrefixError extends Errors.BaseError {
constructor({ prefix, cause }) {
super(`Prefix "${prefix}" is invalid.`, {
cause,
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'PublicKey.InvalidPrefixError'
});
}
}
/** Thrown when the public key has an invalid prefix for a compressed public key. */
export class InvalidCompressedPrefixError extends Errors.BaseError {
constructor() {
super('Prefix must be 2 or 3 for compressed public keys.');
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'PublicKey.InvalidCompressedPrefixError'
});
}
}
/** Thrown when the public key has an invalid prefix for an uncompressed public key. */
export class InvalidUncompressedPrefixError extends Errors.BaseError {
constructor() {
super('Prefix must be 4 for uncompressed public keys.');
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'PublicKey.InvalidUncompressedPrefixError'
});
}
}
/** Thrown when the public key has an invalid serialized size. */
export class InvalidSerializedSizeError extends Errors.BaseError {
constructor({ publicKey }) {
super(`Value \`${publicKey}\` is an invalid public key size.`, {
metaMessages: [
'Expected: 33 bytes (compressed + prefix), 64 bytes (uncompressed) or 65 bytes (uncompressed + prefix).',
`Received ${Hex.size(Hex.from(publicKey))} bytes.`,
],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'PublicKey.InvalidSerializedSizeError'
});
}
}
//# sourceMappingURL=PublicKey.js.map

1
node_modules/ox/_esm/core/PublicKey.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

249
node_modules/ox/_esm/core/Rlp.js generated vendored Normal file
View File

@@ -0,0 +1,249 @@
import * as Bytes from './Bytes.js';
import * as Errors from './Errors.js';
import * as Hex from './Hex.js';
import * as Cursor from './internal/cursor.js';
/**
* Decodes a Recursive-Length Prefix (RLP) value into a {@link ox#Bytes.Bytes} value.
*
* @example
* ```ts twoslash
* import { Rlp } from 'ox'
* Rlp.toBytes('0x8b68656c6c6f20776f726c64')
* // Uint8Array([139, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])
* ```
*
* @param value - The value to decode.
* @returns The decoded {@link ox#Bytes.Bytes} value.
*/
export function toBytes(value) {
return to(value, 'Bytes');
}
/**
* Decodes a Recursive-Length Prefix (RLP) value into a {@link ox#Hex.Hex} value.
*
* @example
* ```ts twoslash
* import { Rlp } from 'ox'
* Rlp.toHex('0x8b68656c6c6f20776f726c64')
* // 0x68656c6c6f20776f726c64
* ```
*
* @param value - The value to decode.
* @returns The decoded {@link ox#Hex.Hex} value.
*/
export function toHex(value) {
return to(value, 'Hex');
}
/////////////////////////////////////////////////////////////////////////////////
// Internal
/////////////////////////////////////////////////////////////////////////////////
/** @internal */
export function to(value, to) {
const to_ = to ?? (typeof value === 'string' ? 'Hex' : 'Bytes');
const bytes = (() => {
if (typeof value === 'string') {
if (value.length > 3 && value.length % 2 !== 0)
throw new Hex.InvalidLengthError(value);
return Bytes.fromHex(value);
}
return value;
})();
const cursor = Cursor.create(bytes, {
recursiveReadLimit: Number.POSITIVE_INFINITY,
});
const result = decodeRlpCursor(cursor, to_);
return result;
}
/** @internal */
/** @internal */
export function decodeRlpCursor(cursor, to = 'Hex') {
if (cursor.bytes.length === 0)
return (to === 'Hex' ? Hex.fromBytes(cursor.bytes) : cursor.bytes);
const prefix = cursor.readByte();
if (prefix < 0x80)
cursor.decrementPosition(1);
// bytes
if (prefix < 0xc0) {
const length = readLength(cursor, prefix, 0x80);
const bytes = cursor.readBytes(length);
return (to === 'Hex' ? Hex.fromBytes(bytes) : bytes);
}
// list
const length = readLength(cursor, prefix, 0xc0);
return readList(cursor, length, to);
}
/** @internal */
export function readLength(cursor, prefix, offset) {
if (offset === 0x80 && prefix < 0x80)
return 1;
if (prefix <= offset + 55)
return prefix - offset;
if (prefix === offset + 55 + 1)
return cursor.readUint8();
if (prefix === offset + 55 + 2)
return cursor.readUint16();
if (prefix === offset + 55 + 3)
return cursor.readUint24();
if (prefix === offset + 55 + 4)
return cursor.readUint32();
throw new Errors.BaseError('Invalid RLP prefix');
}
/** @internal */
export function readList(cursor, length, to) {
const position = cursor.position;
const value = [];
while (cursor.position - position < length)
value.push(decodeRlpCursor(cursor, to));
return value;
}
/**
* Encodes a {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value into a Recursive-Length Prefix (RLP) value.
*
* @example
* ```ts twoslash
* import { Bytes, Rlp } from 'ox'
*
* Rlp.from('0x68656c6c6f20776f726c64', { as: 'Hex' })
* // @log: 0x8b68656c6c6f20776f726c64
*
* Rlp.from(Bytes.from([139, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]), { as: 'Bytes' })
* // @log: Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])
* ```
*
* @param value - The {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value to encode.
* @param options - Options.
* @returns The RLP value.
*/
export function from(value, options) {
const { as } = options;
const encodable = getEncodable(value);
const cursor = Cursor.create(new Uint8Array(encodable.length));
encodable.encode(cursor);
if (as === 'Hex')
return Hex.fromBytes(cursor.bytes);
return cursor.bytes;
}
/**
* Encodes a {@link ox#Bytes.Bytes} value into a Recursive-Length Prefix (RLP) value.
*
* @example
* ```ts twoslash
* import { Bytes, Rlp } from 'ox'
*
* Rlp.fromBytes(Bytes.from([139, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]))
* // @log: Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])
* ```
*
* @param bytes - The {@link ox#Bytes.Bytes} value to encode.
* @param options - Options.
* @returns The RLP value.
*/
export function fromBytes(bytes, options = {}) {
const { as = 'Bytes' } = options;
return from(bytes, { as });
}
/**
* Encodes a {@link ox#Hex.Hex} value into a Recursive-Length Prefix (RLP) value.
*
* @example
* ```ts twoslash
* import { Rlp } from 'ox'
*
* Rlp.fromHex('0x68656c6c6f20776f726c64')
* // @log: 0x8b68656c6c6f20776f726c64
* ```
*
* @param hex - The {@link ox#Hex.Hex} value to encode.
* @param options - Options.
* @returns The RLP value.
*/
export function fromHex(hex, options = {}) {
const { as = 'Hex' } = options;
return from(hex, { as });
}
/////////////////////////////////////////////////////////////////////////////////
// Internal
/////////////////////////////////////////////////////////////////////////////////
function getEncodable(bytes) {
if (Array.isArray(bytes))
return getEncodableList(bytes.map((x) => getEncodable(x)));
return getEncodableBytes(bytes);
}
function getEncodableList(list) {
const bodyLength = list.reduce((acc, x) => acc + x.length, 0);
const sizeOfBodyLength = getSizeOfLength(bodyLength);
const length = (() => {
if (bodyLength <= 55)
return 1 + bodyLength;
return 1 + sizeOfBodyLength + bodyLength;
})();
return {
length,
encode(cursor) {
if (bodyLength <= 55) {
cursor.pushByte(0xc0 + bodyLength);
}
else {
cursor.pushByte(0xc0 + 55 + sizeOfBodyLength);
if (sizeOfBodyLength === 1)
cursor.pushUint8(bodyLength);
else if (sizeOfBodyLength === 2)
cursor.pushUint16(bodyLength);
else if (sizeOfBodyLength === 3)
cursor.pushUint24(bodyLength);
else
cursor.pushUint32(bodyLength);
}
for (const { encode } of list) {
encode(cursor);
}
},
};
}
function getEncodableBytes(bytesOrHex) {
const bytes = typeof bytesOrHex === 'string' ? Bytes.fromHex(bytesOrHex) : bytesOrHex;
const sizeOfBytesLength = getSizeOfLength(bytes.length);
const length = (() => {
if (bytes.length === 1 && bytes[0] < 0x80)
return 1;
if (bytes.length <= 55)
return 1 + bytes.length;
return 1 + sizeOfBytesLength + bytes.length;
})();
return {
length,
encode(cursor) {
if (bytes.length === 1 && bytes[0] < 0x80) {
cursor.pushBytes(bytes);
}
else if (bytes.length <= 55) {
cursor.pushByte(0x80 + bytes.length);
cursor.pushBytes(bytes);
}
else {
cursor.pushByte(0x80 + 55 + sizeOfBytesLength);
if (sizeOfBytesLength === 1)
cursor.pushUint8(bytes.length);
else if (sizeOfBytesLength === 2)
cursor.pushUint16(bytes.length);
else if (sizeOfBytesLength === 3)
cursor.pushUint24(bytes.length);
else
cursor.pushUint32(bytes.length);
cursor.pushBytes(bytes);
}
},
};
}
function getSizeOfLength(length) {
if (length < 2 ** 8)
return 1;
if (length < 2 ** 16)
return 2;
if (length < 2 ** 24)
return 3;
if (length < 2 ** 32)
return 4;
throw new Errors.BaseError('Length is too large.');
}
//# sourceMappingURL=Rlp.js.map

1
node_modules/ox/_esm/core/Rlp.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

125
node_modules/ox/_esm/core/RpcRequest.js generated vendored Normal file
View File

@@ -0,0 +1,125 @@
/**
* Creates a JSON-RPC request store to build requests with an incrementing `id`.
*
* Returns a type-safe `prepare` function to build a JSON-RPC request object as per the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification#request_object).
*
* @example
* ```ts twoslash
* import { RpcRequest } from 'ox'
*
* const store = RpcRequest.createStore()
*
* const request_1 = store.prepare({
* method: 'eth_blockNumber',
* })
* // @log: { id: 0, jsonrpc: '2.0', method: 'eth_blockNumber' }
*
* const request_2 = store.prepare({
* method: 'eth_call',
* params: [
* {
* to: '0x0000000000000000000000000000000000000000',
* data: '0xdeadbeef',
* },
* ],
* })
* // @log: { id: 1, jsonrpc: '2.0', method: 'eth_call', params: [{ to: '0x0000000000000000000000000000000000000000', data: '0xdeadbeef' }] }
* ```
*
* @example
* ### Type-safe Custom Schemas
*
* It is possible to define your own type-safe schema by using the {@link ox#RpcSchema.From} type.
*
* ```ts twoslash
* import { RpcSchema, RpcRequest } from 'ox'
*
* type Schema = RpcSchema.From<{ // [!code focus]
* Request: { // [!code focus]
* method: 'eth_foobar' // [!code focus]
* params: [number] // [!code focus]
* } // [!code focus]
* ReturnType: string // [!code focus]
* } | { // [!code focus]
* Request: { // [!code focus]
* method: 'eth_foobaz' // [!code focus]
* params: [string] // [!code focus]
* } // [!code focus]
* ReturnType: string // [!code focus]
* }> // [!code focus]
*
* const store = RpcRequest.createStore<Schema>() // [!code focus]
*
* const request = store.prepare({
* method: 'eth_foobar', // [!code focus]
* // ^?
* params: [42],
* })
* ```
*
* @param options - Request store options.
* @returns The request store
*/
export function createStore(options = {}) {
let id = options.id ?? 0;
return {
prepare(options) {
return from({
id: id++,
...options,
});
},
get id() {
return id;
},
};
}
/**
* A type-safe interface to build a JSON-RPC request object as per the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification#request_object).
*
* :::warning
*
* You will likely want to use {@link ox#RpcRequest.(createStore:function)} instead as it will also manage `id`s and uses this function internally.
*
* :::
*
* @example
* ```ts twoslash
* import { RpcRequest, RpcResponse } from 'ox'
*
* // 1. Build a request object.
* const request = RpcRequest.from({ // [!code focus]
* id: 0, // [!code focus]
* method: 'eth_estimateGas', // [!code focus]
* params: [ // [!code focus]
* { // [!code focus]
* from: '0xd2135CfB216b74109775236E36d4b433F1DF507B', // [!code focus]
* to: '0x0D44f617435088c947F00B31160f64b074e412B4', // [!code focus]
* value: '0x69420', // [!code focus]
* }, // [!code focus]
* ], // [!code focus]
* }) // [!code focus]
*
* // 2. Send the JSON-RPC request via HTTP.
* const gas = await fetch('https://1.rpc.thirdweb.com', {
* body: JSON.stringify(request),
* headers: {
* 'Content-Type': 'application/json',
* },
* method: 'POST',
* })
* .then((response) => response.json())
* // 3. Parse the JSON-RPC response into a type-safe result.
* .then((response) => RpcResponse.parse(response, { request }))
* ```
*
* @param options - JSON-RPC request options.
* @returns The fully-formed JSON-RPC request object.
*/
export function from(options) {
return {
...options,
jsonrpc: '2.0',
};
}
//# sourceMappingURL=RpcRequest.js.map

1
node_modules/ox/_esm/core/RpcRequest.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"RpcRequest.js","sourceRoot":"","sources":["../../core/RpcRequest.ts"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAM,UAAU,WAAW,CAEzB,UAA+B,EAAE;IACjC,IAAI,EAAE,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,CAAA;IACxB,OAAO;QACL,OAAO,CAAC,OAAO;YACb,OAAO,IAAI,CAAC;gBACV,EAAE,EAAE,EAAE,EAAE;gBACR,GAAG,OAAO;aACF,CAAU,CAAA;QACtB,CAAC;QACD,IAAI,EAAE;YACJ,OAAO,EAAE,CAAA;QACX,CAAC;KACF,CAAA;AACH,CAAC;AAcD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,UAAU,IAAI,CAClB,OAAiC;IAEjC,OAAO;QACL,GAAG,OAAO;QACV,OAAO,EAAE,KAAK;KACN,CAAA;AACZ,CAAC"}

522
node_modules/ox/_esm/core/RpcResponse.js generated vendored Normal file
View File

@@ -0,0 +1,522 @@
// eslint-disable-next-line jsdoc/require-jsdoc
export function from(response, options = {}) {
const { request } = options;
return {
...response,
id: response.id ?? request?.id,
jsonrpc: response.jsonrpc ?? request.jsonrpc,
};
}
/**
* A type-safe interface to parse a JSON-RPC response object as per the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification#response_object), and extract the result.
*
* @example
* ```ts twoslash
* import { RpcRequest, RpcResponse } from 'ox'
*
* // 1. Create a request store.
* const store = RpcRequest.createStore()
*
* // 2. Get a request object.
* const request = store.prepare({
* method: 'eth_getBlockByNumber',
* params: ['0x1', false],
* })
*
* // 3. Send the JSON-RPC request via HTTP.
* const block = await fetch('https://1.rpc.thirdweb.com', {
* body: JSON.stringify(request),
* headers: {
* 'Content-Type': 'application/json',
* },
* method: 'POST',
* })
* .then((response) => response.json())
* // 4. Parse the JSON-RPC response into a type-safe result. // [!code focus]
* .then((response) => RpcResponse.parse(response, { request })) // [!code focus]
*
* block // [!code focus]
* // ^?
*
*
*
*
*
*
*
*
*
*
*
* ```
*
* :::tip
*
* If you don't need the return type, you can omit the options entirely.
*
* ```ts twoslash
* // @noErrors
* import { RpcResponse } from 'ox'
*
* const block = await fetch('https://1.rpc.thirdweb.com', {})
* .then((response) => response.json())
* .then((response) => RpcResponse.parse(response, { request })) // [!code --]
* .then(RpcResponse.parse) // [!code ++]
* ```
* :::
*
* @example
* ### Raw Mode
*
* If `raw` is `true`, the response will be returned as an object with `result` and `error` properties instead of returning the `result` directly and throwing errors.
*
* ```ts twoslash
* import { RpcRequest, RpcResponse } from 'ox'
*
* const store = RpcRequest.createStore()
*
* const request = store.prepare({
* method: 'eth_blockNumber',
* })
*
* const response = RpcResponse.parse({}, {
* request,
* raw: true, // [!code hl]
* })
*
* response.result
* // ^?
*
*
* response.error
* // ^?
*
*
* ```
*
* @param response - Opaque JSON-RPC response object.
* @param options - Parsing options.
* @returns Typed JSON-RPC result, or response object (if `raw` is `true`).
*/
export function parse(response, options = {}) {
const { raw = false } = options;
const response_ = response;
if (raw)
return response;
if (response_.error)
throw parseError(response_.error);
return response_.result;
}
/**
* Parses a JSON-RPC error object into an error instance.
*
* @example
* ```ts twoslash
* import { RpcResponse } from 'ox'
*
* const error = RpcResponse.parseError({ code: -32000, message: 'unsupported method' })
*
* error
* // ^?
*
* ```
*
* @param errorObject - JSON-RPC error object.
* @returns Error instance.
*/
export function parseError(errorObject) {
const errorObject_ = errorObject;
const { code } = errorObject_;
if (code === InternalError.code)
return new InternalError(errorObject_);
if (code === InvalidInputError.code)
return new InvalidInputError(errorObject_);
if (code === InvalidParamsError.code)
return new InvalidParamsError(errorObject_);
if (code === InvalidRequestError.code)
return new InvalidRequestError(errorObject_);
if (code === LimitExceededError.code)
return new LimitExceededError(errorObject_);
if (code === MethodNotFoundError.code)
return new MethodNotFoundError(errorObject_);
if (code === MethodNotSupportedError.code)
return new MethodNotSupportedError(errorObject_);
if (code === ParseError.code)
return new ParseError(errorObject_);
if (code === ResourceNotFoundError.code)
return new ResourceNotFoundError(errorObject_);
if (code === ResourceUnavailableError.code)
return new ResourceUnavailableError(errorObject_);
if (code === TransactionRejectedError.code)
return new TransactionRejectedError(errorObject_);
if (code === VersionNotSupportedError.code)
return new VersionNotSupportedError(errorObject_);
return new InternalError({
data: errorObject_,
message: errorObject_.message,
});
}
/** Thrown when a JSON-RPC error has occurred. */
export class BaseError extends Error {
constructor(errorObject) {
const { code, message, data } = errorObject;
super(message);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.BaseError'
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "data", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.code = code;
this.data = data;
}
}
/** Thrown when the input to a JSON-RPC method is invalid. */
export class InvalidInputError extends BaseError {
constructor(parameters = {}) {
super({
code: InvalidInputError.code,
data: parameters.data,
message: parameters.message ?? 'Missing or invalid parameters.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32000
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.InvalidInputError'
});
}
}
Object.defineProperty(InvalidInputError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32000
});
/** Thrown when a JSON-RPC resource is not found. */
export class ResourceNotFoundError extends BaseError {
constructor(parameters = {}) {
super({
code: ResourceNotFoundError.code,
data: parameters.data,
message: parameters.message ?? 'Requested resource not found.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32001
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.ResourceNotFoundError'
});
}
}
Object.defineProperty(ResourceNotFoundError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32001
});
/** Thrown when a JSON-RPC resource is unavailable. */
export class ResourceUnavailableError extends BaseError {
constructor(parameters = {}) {
super({
code: ResourceUnavailableError.code,
data: parameters.data,
message: parameters.message ?? 'Requested resource not available.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32002
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.ResourceUnavailableError'
});
}
}
Object.defineProperty(ResourceUnavailableError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32002
});
/** Thrown when a JSON-RPC transaction is rejected. */
export class TransactionRejectedError extends BaseError {
constructor(parameters = {}) {
super({
code: TransactionRejectedError.code,
data: parameters.data,
message: parameters.message ?? 'Transaction creation failed.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32003
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.TransactionRejectedError'
});
}
}
Object.defineProperty(TransactionRejectedError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32003
});
/** Thrown when a JSON-RPC method is not supported. */
export class MethodNotSupportedError extends BaseError {
constructor(parameters = {}) {
super({
code: MethodNotSupportedError.code,
data: parameters.data,
message: parameters.message ?? 'Method is not implemented.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32004
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.MethodNotSupportedError'
});
}
}
Object.defineProperty(MethodNotSupportedError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32004
});
/** Thrown when a rate-limit is exceeded. */
export class LimitExceededError extends BaseError {
constructor(parameters = {}) {
super({
code: LimitExceededError.code,
data: parameters.data,
message: parameters.message ?? 'Rate limit exceeded.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32005
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.LimitExceededError'
});
}
}
Object.defineProperty(LimitExceededError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32005
});
/** Thrown when a JSON-RPC version is not supported. */
export class VersionNotSupportedError extends BaseError {
constructor(parameters = {}) {
super({
code: VersionNotSupportedError.code,
data: parameters.data,
message: parameters.message ?? 'JSON-RPC version not supported.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32006
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.VersionNotSupportedError'
});
}
}
Object.defineProperty(VersionNotSupportedError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32006
});
/** Thrown when a JSON-RPC request is invalid. */
export class InvalidRequestError extends BaseError {
constructor(parameters = {}) {
super({
code: InvalidRequestError.code,
data: parameters.data,
message: parameters.message ?? 'Input is not a valid JSON-RPC request.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32600
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.InvalidRequestError'
});
}
}
Object.defineProperty(InvalidRequestError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32600
});
/** Thrown when a JSON-RPC method is not found. */
export class MethodNotFoundError extends BaseError {
constructor(parameters = {}) {
super({
code: MethodNotFoundError.code,
data: parameters.data,
message: parameters.message ?? 'Method does not exist.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32601
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.MethodNotFoundError'
});
}
}
Object.defineProperty(MethodNotFoundError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32601
});
/** Thrown when the parameters to a JSON-RPC method are invalid. */
export class InvalidParamsError extends BaseError {
constructor(parameters = {}) {
super({
code: InvalidParamsError.code,
data: parameters.data,
message: parameters.message ?? 'Invalid method parameters.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32602
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.InvalidParamsError'
});
}
}
Object.defineProperty(InvalidParamsError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32602
});
/** Thrown when an internal JSON-RPC error has occurred. */
export class InternalError extends BaseError {
constructor(parameters = {}) {
super({
code: InternalError.code,
data: parameters.data,
message: parameters.message ?? 'Internal JSON-RPC error.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32603
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.InternalError'
});
}
}
Object.defineProperty(InternalError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32603
});
/** Thrown when a JSON-RPC response is invalid. */
export class ParseError extends BaseError {
constructor(parameters = {}) {
super({
code: ParseError.code,
data: parameters.data,
message: parameters.message ?? 'Failed to parse JSON-RPC response.',
});
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32700
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcResponse.ParseError'
});
}
}
Object.defineProperty(ParseError, "code", {
enumerable: true,
configurable: true,
writable: true,
value: -32700
});
//# sourceMappingURL=RpcResponse.js.map

1
node_modules/ox/_esm/core/RpcResponse.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

46
node_modules/ox/_esm/core/RpcSchema.js generated vendored Normal file
View File

@@ -0,0 +1,46 @@
/**
* Instantiates a statically typed Schema. This is a runtime-noop function, and is purposed
* to be used as a type-level tag to be used with {@link ox#Provider.(from:function)} or
* {@link ox#RpcTransport.(fromHttp:function)}.
*
* @example
* ### Using with `Provider.from`
*
* ```ts twoslash
* // @noErrors
* import 'ox/window'
* import { Provider, RpcSchema } from 'ox'
*
* const schema = RpcSchema.from<
* | RpcSchema.Default
* | {
* Request: {
* method: 'abe_foo',
* params: [id: number],
* }
* ReturnType: string
* }
* | {
* Request: {
* method: 'abe_bar',
* params: [id: string],
* }
* ReturnType: string
* }
* >()
*
* const provider = Provider.from(window.ethereum, { schema })
*
* const blockNumber = await provider.request({ method: 'e' })
* // ^|
*
*
*
*
*
* ```
*/
export function from() {
return null;
}
//# sourceMappingURL=RpcSchema.js.map

1
node_modules/ox/_esm/core/RpcSchema.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"RpcSchema.js","sourceRoot":"","sources":["../../core/RpcSchema.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,UAAU,IAAI;IAClB,OAAO,IAAa,CAAA;AACtB,CAAC"}

107
node_modules/ox/_esm/core/RpcTransport.js generated vendored Normal file
View File

@@ -0,0 +1,107 @@
import * as Errors from './Errors.js';
import { getUrl } from './internal/errors.js';
import * as promise from './internal/promise.js';
import * as internal from './internal/rpcTransport.js';
/**
* Creates a HTTP JSON-RPC Transport from a URL.
*
* @example
* ```ts twoslash
* import { RpcTransport } from 'ox'
*
* const transport = RpcTransport.fromHttp('https://1.rpc.thirdweb.com')
*
* const blockNumber = await transport.request({ method: 'eth_blockNumber' })
* // @log: '0x1a2b3c'
* ```
*
* @param url - URL to perform the JSON-RPC requests to.
* @param options - Transport options.
* @returns HTTP JSON-RPC Transport.
*/
export function fromHttp(url, options = {}) {
return internal.create({
async request(body_, options_) {
const { fetchFn = options.fetchFn ?? fetch, fetchOptions: fetchOptions_ = options.fetchOptions, timeout = options.timeout ?? 10_000, } = options_;
const body = JSON.stringify(body_);
const fetchOptions = typeof fetchOptions_ === 'function'
? await fetchOptions_(body_)
: fetchOptions_;
const response = await promise.withTimeout(({ signal }) => {
const init = {
...fetchOptions,
body,
headers: {
'Content-Type': 'application/json',
...fetchOptions?.headers,
},
method: fetchOptions?.method ?? 'POST',
signal: fetchOptions?.signal ?? (timeout > 0 ? signal : null),
};
const request = new Request(url, init);
return fetchFn(request);
}, {
timeout,
signal: true,
});
const data = await (async () => {
if (response.headers.get('Content-Type')?.startsWith('application/json'))
return response.json();
return response.text().then((data) => {
try {
return JSON.parse(data || '{}');
}
catch (err) {
if (response.ok)
throw new MalformedResponseError({
response: data,
});
return { error: data };
}
});
})();
if (!response.ok)
throw new HttpError({
body,
details: JSON.stringify(data.error) ?? response.statusText,
response,
url,
});
return data;
},
}, { raw: options.raw });
}
/** Thrown when a HTTP request fails. */
export class HttpError extends Errors.BaseError {
constructor({ body, details, response, url, }) {
super('HTTP request failed.', {
details,
metaMessages: [
`Status: ${response.status}`,
`URL: ${getUrl(url)}`,
body ? `Body: ${JSON.stringify(body)}` : undefined,
],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcTransport.HttpError'
});
}
}
/** Thrown when a HTTP response is malformed. */
export class MalformedResponseError extends Errors.BaseError {
constructor({ response }) {
super('HTTP Response could not be parsed as JSON.', {
metaMessages: [`Response: ${response}`],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'RpcTransport.MalformedResponseError'
});
}
}
//# sourceMappingURL=RpcTransport.js.map

1
node_modules/ox/_esm/core/RpcTransport.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"RpcTransport.js","sourceRoot":"","sources":["../../core/RpcTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAGrC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAC7C,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAA;AAEhD,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAA;AAsDtD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,QAAQ,CAGtB,GAAW,EAAE,UAAyC,EAAE;IACxD,OAAO,QAAQ,CAAC,MAAM,CACpB;QACE,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ;YAC3B,MAAM,EACJ,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,KAAK,EAClC,YAAY,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,EAClD,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,MAAM,GACpC,GAAG,QAAQ,CAAA;YAEZ,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;YAElC,MAAM,YAAY,GAChB,OAAO,aAAa,KAAK,UAAU;gBACjC,CAAC,CAAC,MAAM,aAAa,CAAC,KAAK,CAAC;gBAC5B,CAAC,CAAC,aAAa,CAAA;YAEnB,MAAM,QAAQ,GAAG,M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AAC,EAAE;gBACd,MAAM,IAAI,SAAS,CAAC;oBAClB,IAAI;oBACJ,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,UAAU;oBAC1D,QAAQ;oBACR,GAAG;iBACJ,CAAC,CAAA;YAEJ,OAAO,IAAa,CAAA;QACtB,CAAC;KACF,EACD,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CACrB,CAAA;AACH,CAAC;AAcD,wCAAwC;AACxC,MAAM,OAAO,SAAU,SAAQ,MAAM,CAAC,SAAS;IAG7C,YAAY,EACV,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,GAAG,GACiE;QACpE,KAAK,CAAC,sBAAsB,EAAE;YAC5B,OAAO;YACP,YAAY,EAAE;gBACZ,WAAW,QAAQ,CAAC,MAAM,EAAE;gBAC5B,QAAQ,MAAM,CAAC,GAAG,CAAC,EAAE;gBACrB,IAAI,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;aACnD;SACF,CAAC,CAAA;QAfc;;;;mBAAO,wBAAwB;WAAA;IAgBjD,CAAC;CACF;AAED,gDAAgD;AAChD,MAAM,OAAO,sBAAuB,SAAQ,MAAM,CAAC,SAAS;IAG1D,YAAY,EAAE,QAAQ,EAAwB;QAC5C,KAAK,CAAC,4CAA4C,EAAE;YAClD,YAAY,EAAE,CAAC,aAAa,QAAQ,EAAE,CAAC;SACxC,CAAC,CAAA;QALc;;;;mBAAO,qCAAqC;WAAA;IAM9D,CAAC;CACF"}

168
node_modules/ox/_esm/core/Secp256k1.js generated vendored Normal file
View File

@@ -0,0 +1,168 @@
import { secp256k1 } from '@noble/curves/secp256k1';
import * as Address from './Address.js';
import * as Bytes from './Bytes.js';
import * as Hex from './Hex.js';
import * as PublicKey from './PublicKey.js';
import * as Entropy from './internal/entropy.js';
/** Re-export of noble/curves secp256k1 utilities. */
export const noble = secp256k1;
/**
* Computes the secp256k1 ECDSA public key from a provided private key.
*
* @example
* ```ts twoslash
* import { Secp256k1 } from 'ox'
*
* const publicKey = Secp256k1.getPublicKey({ privateKey: '0x...' })
* ```
*
* @param options - The options to compute the public key.
* @returns The computed public key.
*/
export function getPublicKey(options) {
const { privateKey } = options;
const point = secp256k1.ProjectivePoint.fromPrivateKey(Hex.from(privateKey).slice(2));
return PublicKey.from(point);
}
/**
* Generates a random ECDSA private key on the secp256k1 curve.
*
* @example
* ```ts twoslash
* import { Secp256k1 } from 'ox'
*
* const privateKey = Secp256k1.randomPrivateKey()
* ```
*
* @param options - The options to generate the private key.
* @returns The generated private key.
*/
export function randomPrivateKey(options = {}) {
const { as = 'Hex' } = options;
const bytes = secp256k1.utils.randomPrivateKey();
if (as === 'Hex')
return Hex.fromBytes(bytes);
return bytes;
}
/**
* Recovers the signing address from the signed payload and signature.
*
* @example
* ```ts twoslash
* import { Secp256k1 } from 'ox'
*
* const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey: '0x...' })
*
* const address = Secp256k1.recoverAddress({ // [!code focus]
* payload: '0xdeadbeef', // [!code focus]
* signature, // [!code focus]
* }) // [!code focus]
* ```
*
* @param options - The recovery options.
* @returns The recovered address.
*/
export function recoverAddress(options) {
return Address.fromPublicKey(recoverPublicKey(options));
}
/**
* Recovers the signing public key from the signed payload and signature.
*
* @example
* ```ts twoslash
* import { Secp256k1 } from 'ox'
*
* const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey: '0x...' })
*
* const publicKey = Secp256k1.recoverPublicKey({ // [!code focus]
* payload: '0xdeadbeef', // [!code focus]
* signature, // [!code focus]
* }) // [!code focus]
* ```
*
* @param options - The recovery options.
* @returns The recovered public key.
*/
export function recoverPublicKey(options) {
const { payload, signature } = options;
const { r, s, yParity } = signature;
const signature_ = new secp256k1.Signature(BigInt(r), BigInt(s)).addRecoveryBit(yParity);
const point = signature_.recoverPublicKey(Hex.from(payload).substring(2));
return PublicKey.from(point);
}
/**
* Signs the payload with the provided private key.
*
* @example
* ```ts twoslash
* import { Secp256k1 } from 'ox'
*
* const signature = Secp256k1.sign({ // [!code focus]
* payload: '0xdeadbeef', // [!code focus]
* privateKey: '0x...' // [!code focus]
* }) // [!code focus]
* ```
*
* @param options - The signing options.
* @returns The ECDSA {@link ox#Signature.Signature}.
*/
export function sign(options) {
const { extraEntropy = Entropy.extraEntropy, hash, payload, privateKey, } = options;
const { r, s, recovery } = secp256k1.sign(Bytes.from(payload), Bytes.from(privateKey), {
extraEntropy: typeof extraEntropy === 'boolean'
? extraEntropy
: Hex.from(extraEntropy).slice(2),
lowS: true,
...(hash ? { prehash: true } : {}),
});
return {
r,
s,
yParity: recovery,
};
}
/**
* Verifies a payload was signed by the provided address.
*
* @example
* ### Verify with Ethereum Address
*
* ```ts twoslash
* import { Secp256k1 } from 'ox'
*
* const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey: '0x...' })
*
* const verified = Secp256k1.verify({ // [!code focus]
* address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', // [!code focus]
* payload: '0xdeadbeef', // [!code focus]
* signature, // [!code focus]
* }) // [!code focus]
* ```
*
* @example
* ### Verify with Public Key
*
* ```ts twoslash
* import { Secp256k1 } from 'ox'
*
* const privateKey = '0x...'
* const publicKey = Secp256k1.getPublicKey({ privateKey })
* const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey })
*
* const verified = Secp256k1.verify({ // [!code focus]
* publicKey, // [!code focus]
* payload: '0xdeadbeef', // [!code focus]
* signature, // [!code focus]
* }) // [!code focus]
* ```
*
* @param options - The verification options.
* @returns Whether the payload was signed by the provided address.
*/
export function verify(options) {
const { address, hash, payload, publicKey, signature } = options;
if (address)
return Address.isEqual(address, recoverAddress({ payload, signature }));
return secp256k1.verify(signature, Bytes.from(payload), PublicKey.toBytes(publicKey), ...(hash ? [{ prehash: true, lowS: true }] : []));
}
//# sourceMappingURL=Secp256k1.js.map

1
node_modules/ox/_esm/core/Secp256k1.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Secp256k1.js","sourceRoot":"","sources":["../../core/Secp256k1.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAE3C,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAA;AAGhD,qDAAqD;AACrD,MAAM,CAAC,MAAM,KAAK,GAAG,SAAS,CAAA;AAE9B;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,OAA6B;IAE7B,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAA;IAC9B,MAAM,KAAK,GAAG,SAAS,CAAC,eAAe,CAAC,cAAc,CACpD,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAC9B,CAAA;IACD,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC;AAgBD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAAwC,EAAE;IAE1C,MAAM,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,OAAO,CAAA;IAC9B,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAA;IAChD,IAAI,EAAE,KAAK,KAAK;QAAE,OAAO,GAAG,CAAC,SAAS,CAAC,KAAK,CAAU,CAAA;IACtD,OAAO,KAAc,CAAA;AACvB,CAAC;AAkBD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,cAAc,CAC5B,OAA+B;IAE/B,OAAO,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,OAAO,CAAC,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CAAC;QACD,OAAO,EAAE,QAAQ;KAClB,CAAA;AACH,CAAC;AA0BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,UAAU,MAAM,CAAC,OAAuB;IAC5C,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IAChE,IAAI,OAAO;QACT,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAA;IACzE,OAAO,SAAS,CAAC,MAAM,CACrB,SAAS,EACT,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,EACnB,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,EAC5B,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CACjD,CAAA;AACH,CAAC"}

647
node_modules/ox/_esm/core/Signature.js generated vendored Normal file
View File

@@ -0,0 +1,647 @@
import { secp256k1 } from '@noble/curves/secp256k1';
import * as Bytes from './Bytes.js';
import * as Errors from './Errors.js';
import * as Hex from './Hex.js';
import * as Json from './Json.js';
import * as Solidity from './Solidity.js';
/**
* Asserts that a Signature is valid.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* Signature.assert({
* r: -49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* yParity: 1,
* })
* // @error: InvalidSignatureRError:
* // @error: Value `-549...n` is an invalid r value.
* // @error: r must be a positive integer less than 2^256.
* ```
*
* @param signature - The signature object to assert.
*/
export function assert(signature, options = {}) {
const { recovered } = options;
if (typeof signature.r === 'undefined')
throw new MissingPropertiesError({ signature });
if (typeof signature.s === 'undefined')
throw new MissingPropertiesError({ signature });
if (recovered && typeof signature.yParity === 'undefined')
throw new MissingPropertiesError({ signature });
if (signature.r < 0n || signature.r > Solidity.maxUint256)
throw new InvalidRError({ value: signature.r });
if (signature.s < 0n || signature.s > Solidity.maxUint256)
throw new InvalidSError({ value: signature.s });
if (typeof signature.yParity === 'number' &&
signature.yParity !== 0 &&
signature.yParity !== 1)
throw new InvalidYParityError({ value: signature.yParity });
}
/**
* Deserializes a {@link ox#Bytes.Bytes} signature into a structured {@link ox#Signature.Signature}.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Signature } from 'ox'
*
* Signature.fromBytes(new Uint8Array([128, 3, 131, ...]))
* // @log: { r: 5231...n, s: 3522...n, yParity: 0 }
* ```
*
* @param signature - The serialized signature.
* @returns The deserialized {@link ox#Signature.Signature}.
*/
export function fromBytes(signature) {
return fromHex(Hex.fromBytes(signature));
}
/**
* Deserializes a {@link ox#Hex.Hex} signature into a structured {@link ox#Signature.Signature}.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* Signature.fromHex('0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c')
* // @log: { r: 5231...n, s: 3522...n, yParity: 0 }
* ```
*
* @param serialized - The serialized signature.
* @returns The deserialized {@link ox#Signature.Signature}.
*/
export function fromHex(signature) {
if (signature.length !== 130 && signature.length !== 132)
throw new InvalidSerializedSizeError({ signature });
const r = BigInt(Hex.slice(signature, 0, 32));
const s = BigInt(Hex.slice(signature, 32, 64));
const yParity = (() => {
const yParity = Number(`0x${signature.slice(130)}`);
if (Number.isNaN(yParity))
return undefined;
try {
return vToYParity(yParity);
}
catch {
throw new InvalidYParityError({ value: yParity });
}
})();
if (typeof yParity === 'undefined')
return {
r,
s,
};
return {
r,
s,
yParity,
};
}
/**
* Extracts a {@link ox#Signature.Signature} from an arbitrary object that may include signature properties.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Signature } from 'ox'
*
* Signature.extract({
* baz: 'barry',
* foo: 'bar',
* r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* yParity: 1,
* zebra: 'stripes',
* })
* // @log: {
* // @log: r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* // @log: s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* // @log: yParity: 1
* // @log: }
* ```
*
* @param value - The arbitrary object to extract the signature from.
* @returns The extracted {@link ox#Signature.Signature}.
*/
export function extract(value) {
if (typeof value.r === 'undefined')
return undefined;
if (typeof value.s === 'undefined')
return undefined;
return from(value);
}
/**
* Instantiates a typed {@link ox#Signature.Signature} object from a {@link ox#Signature.Signature}, {@link ox#Signature.Legacy}, {@link ox#Bytes.Bytes}, or {@link ox#Hex.Hex}.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* Signature.from({
* r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* yParity: 1,
* })
* // @log: {
* // @log: r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* // @log: s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* // @log: yParity: 1
* // @log: }
* ```
*
* @example
* ### From Serialized
*
* ```ts twoslash
* import { Signature } from 'ox'
*
* Signature.from('0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db801')
* // @log: {
* // @log: r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* // @log: s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* // @log: yParity: 1,
* // @log: }
* ```
*
* @example
* ### From Legacy
*
* ```ts twoslash
* import { Signature } from 'ox'
*
* Signature.from({
* r: 47323457007453657207889730243826965761922296599680473886588287015755652701072n,
* s: 57228803202727131502949358313456071280488184270258293674242124340113824882788n,
* v: 27,
* })
* // @log: {
* // @log: r: 47323457007453657207889730243826965761922296599680473886588287015755652701072n,
* // @log: s: 57228803202727131502949358313456071280488184270258293674242124340113824882788n,
* // @log: yParity: 0
* // @log: }
* ```
*
* @param signature - The signature value to instantiate.
* @returns The instantiated {@link ox#Signature.Signature}.
*/
export function from(signature) {
const signature_ = (() => {
if (typeof signature === 'string')
return fromHex(signature);
if (signature instanceof Uint8Array)
return fromBytes(signature);
if (typeof signature.r === 'string')
return fromRpc(signature);
if (signature.v)
return fromLegacy(signature);
return {
r: signature.r,
s: signature.s,
...(typeof signature.yParity !== 'undefined'
? { yParity: signature.yParity }
: {}),
};
})();
assert(signature_);
return signature_;
}
/**
* Converts a DER-encoded signature to a {@link ox#Signature.Signature}.
*
* @example
* ```ts twoslash
* // @noErrors
* import { Signature } from 'ox'
*
* const signature = Signature.fromDerBytes(new Uint8Array([132, 51, 23, ...]))
* // @log: {
* // @log: r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* // @log: s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* // @log: }
* ```
*
* @param signature - The DER-encoded signature to convert.
* @returns The {@link ox#Signature.Signature}.
*/
export function fromDerBytes(signature) {
return fromDerHex(Hex.fromBytes(signature));
}
/**
* Converts a DER-encoded signature to a {@link ox#Signature.Signature}.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const signature = Signature.fromDerHex('0x304402206e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf02204a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8')
* // @log: {
* // @log: r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* // @log: s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* // @log: }
* ```
*
* @param signature - The DER-encoded signature to convert.
* @returns The {@link ox#Signature.Signature}.
*/
export function fromDerHex(signature) {
const { r, s } = secp256k1.Signature.fromDER(Hex.from(signature).slice(2));
return { r, s };
}
/**
* Converts a {@link ox#Signature.Legacy} into a {@link ox#Signature.Signature}.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const legacy = Signature.fromLegacy({ r: 1n, s: 2n, v: 28 })
* // @log: { r: 1n, s: 2n, yParity: 1 }
* ```
*
* @param signature - The {@link ox#Signature.Legacy} to convert.
* @returns The converted {@link ox#Signature.Signature}.
*/
export function fromLegacy(signature) {
return {
r: signature.r,
s: signature.s,
yParity: vToYParity(signature.v),
};
}
/**
* Converts a {@link ox#Signature.Rpc} into a {@link ox#Signature.Signature}.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const signature = Signature.fromRpc({
* r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
* s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
* yParity: '0x0',
* })
* ```
*
* @param signature - The {@link ox#Signature.Rpc} to convert.
* @returns The converted {@link ox#Signature.Signature}.
*/
export function fromRpc(signature) {
const yParity = (() => {
const v = signature.v ? Number(signature.v) : undefined;
let yParity = signature.yParity ? Number(signature.yParity) : undefined;
if (typeof v === 'number' && typeof yParity !== 'number')
yParity = vToYParity(v);
if (typeof yParity !== 'number')
throw new InvalidYParityError({ value: signature.yParity });
return yParity;
})();
return {
r: BigInt(signature.r),
s: BigInt(signature.s),
yParity,
};
}
/**
* Converts a {@link ox#Signature.Tuple} to a {@link ox#Signature.Signature}.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const signature = Signature.fromTuple(['0x01', '0x7b', '0x1c8'])
* // @log: {
* // @log: r: 123n,
* // @log: s: 456n,
* // @log: yParity: 1,
* // @log: }
* ```
*
* @param tuple - The {@link ox#Signature.Tuple} to convert.
* @returns The {@link ox#Signature.Signature}.
*/
export function fromTuple(tuple) {
const [yParity, r, s] = tuple;
return from({
r: r === '0x' ? 0n : BigInt(r),
s: s === '0x' ? 0n : BigInt(s),
yParity: yParity === '0x' ? 0 : Number(yParity),
});
}
/**
* Serializes a {@link ox#Signature.Signature} to {@link ox#Bytes.Bytes}.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const signature = Signature.toBytes({
* r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* yParity: 1
* })
* // @log: Uint8Array [102, 16, 10, ...]
* ```
*
* @param signature - The signature to serialize.
* @returns The serialized signature.
*/
export function toBytes(signature) {
return Bytes.fromHex(toHex(signature));
}
/**
* Serializes a {@link ox#Signature.Signature} to {@link ox#Hex.Hex}.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const signature = Signature.toHex({
* r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* yParity: 1
* })
* // @log: '0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c'
* ```
*
* @param signature - The signature to serialize.
* @returns The serialized signature.
*/
export function toHex(signature) {
assert(signature);
const r = signature.r;
const s = signature.s;
const signature_ = Hex.concat(Hex.fromNumber(r, { size: 32 }), Hex.fromNumber(s, { size: 32 }),
// If the signature is recovered, add the recovery byte to the signature.
typeof signature.yParity === 'number'
? Hex.fromNumber(yParityToV(signature.yParity), { size: 1 })
: '0x');
return signature_;
}
/**
* Converts a {@link ox#Signature.Signature} to DER-encoded format.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const signature = Signature.from({
* r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* })
*
* const signature_der = Signature.toDerBytes(signature)
* // @log: Uint8Array [132, 51, 23, ...]
* ```
*
* @param signature - The signature to convert.
* @returns The DER-encoded signature.
*/
export function toDerBytes(signature) {
const sig = new secp256k1.Signature(signature.r, signature.s);
return sig.toDERRawBytes();
}
/**
* Converts a {@link ox#Signature.Signature} to DER-encoded format.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const signature = Signature.from({
* r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* })
*
* const signature_der = Signature.toDerHex(signature)
* // @log: '0x304402206e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf02204a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8'
* ```
*
* @param signature - The signature to convert.
* @returns The DER-encoded signature.
*/
export function toDerHex(signature) {
const sig = new secp256k1.Signature(signature.r, signature.s);
return `0x${sig.toDERHex()}`;
}
/**
* Converts a {@link ox#Signature.Signature} into a {@link ox#Signature.Legacy}.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const legacy = Signature.toLegacy({ r: 1n, s: 2n, yParity: 1 })
* // @log: { r: 1n, s: 2n, v: 28 }
* ```
*
* @param signature - The {@link ox#Signature.Signature} to convert.
* @returns The converted {@link ox#Signature.Legacy}.
*/
export function toLegacy(signature) {
return {
r: signature.r,
s: signature.s,
v: yParityToV(signature.yParity),
};
}
/**
* Converts a {@link ox#Signature.Signature} into a {@link ox#Signature.Rpc}.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const signature = Signature.toRpc({
* r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* yParity: 1
* })
* ```
*
* @param signature - The {@link ox#Signature.Signature} to convert.
* @returns The converted {@link ox#Signature.Rpc}.
*/
export function toRpc(signature) {
const { r, s, yParity } = signature;
return {
r: Hex.fromNumber(r, { size: 32 }),
s: Hex.fromNumber(s, { size: 32 }),
yParity: yParity === 0 ? '0x0' : '0x1',
};
}
/**
* Converts a {@link ox#Signature.Signature} to a serialized {@link ox#Signature.Tuple} to be used for signatures in Transaction Envelopes, EIP-7702 Authorization Lists, etc.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const signatureTuple = Signature.toTuple({
* r: 123n,
* s: 456n,
* yParity: 1,
* })
* // @log: [yParity: '0x01', r: '0x7b', s: '0x1c8']
* ```
*
* @param signature - The {@link ox#Signature.Signature} to convert.
* @returns The {@link ox#Signature.Tuple}.
*/
export function toTuple(signature) {
const { r, s, yParity } = signature;
return [
yParity ? '0x01' : '0x',
r === 0n ? '0x' : Hex.trimLeft(Hex.fromNumber(r)),
s === 0n ? '0x' : Hex.trimLeft(Hex.fromNumber(s)),
];
}
/**
* Validates a Signature. Returns `true` if the signature is valid, `false` otherwise.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const valid = Signature.validate({
* r: -49782753348462494199823712700004552394425719014458918871452329774910450607807n,
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
* yParity: 1,
* })
* // @log: false
* ```
*
* @param signature - The signature object to assert.
*/
export function validate(signature, options = {}) {
try {
assert(signature, options);
return true;
}
catch {
return false;
}
}
/**
* Converts a ECDSA `v` value to a `yParity` value.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const yParity = Signature.vToYParity(28)
* // @log: 1
* ```
*
* @param v - The ECDSA `v` value to convert.
* @returns The `yParity` value.
*/
export function vToYParity(v) {
if (v === 0 || v === 27)
return 0;
if (v === 1 || v === 28)
return 1;
if (v >= 35)
return v % 2 === 0 ? 1 : 0;
throw new InvalidVError({ value: v });
}
/**
* Converts a ECDSA `v` value to a `yParity` value.
*
* @example
* ```ts twoslash
* import { Signature } from 'ox'
*
* const v = Signature.yParityToV(1)
* // @log: 28
* ```
*
* @param yParity - The ECDSA `yParity` value to convert.
* @returns The `v` value.
*/
export function yParityToV(yParity) {
if (yParity === 0)
return 27;
if (yParity === 1)
return 28;
throw new InvalidYParityError({ value: yParity });
}
/** Thrown when the serialized signature is of an invalid size. */
export class InvalidSerializedSizeError extends Errors.BaseError {
constructor({ signature }) {
super(`Value \`${signature}\` is an invalid signature size.`, {
metaMessages: [
'Expected: 64 bytes or 65 bytes.',
`Received ${Hex.size(Hex.from(signature))} bytes.`,
],
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Signature.InvalidSerializedSizeError'
});
}
}
/** Thrown when the signature is missing either an `r`, `s`, or `yParity` property. */
export class MissingPropertiesError extends Errors.BaseError {
constructor({ signature }) {
super(`Signature \`${Json.stringify(signature)}\` is missing either an \`r\`, \`s\`, or \`yParity\` property.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Signature.MissingPropertiesError'
});
}
}
/** Thrown when the signature has an invalid `r` value. */
export class InvalidRError extends Errors.BaseError {
constructor({ value }) {
super(`Value \`${value}\` is an invalid r value. r must be a positive integer less than 2^256.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Signature.InvalidRError'
});
}
}
/** Thrown when the signature has an invalid `s` value. */
export class InvalidSError extends Errors.BaseError {
constructor({ value }) {
super(`Value \`${value}\` is an invalid s value. s must be a positive integer less than 2^256.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Signature.InvalidSError'
});
}
}
/** Thrown when the signature has an invalid `yParity` value. */
export class InvalidYParityError extends Errors.BaseError {
constructor({ value }) {
super(`Value \`${value}\` is an invalid y-parity value. Y-parity must be 0 or 1.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Signature.InvalidYParityError'
});
}
}
/** Thrown when the signature has an invalid `v` value. */
export class InvalidVError extends Errors.BaseError {
constructor({ value }) {
super(`Value \`${value}\` is an invalid v value. v must be 27, 28 or >=35.`);
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Signature.InvalidVError'
});
}
}
//# sourceMappingURL=Signature.js.map

1
node_modules/ox/_esm/core/Signature.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

371
node_modules/ox/_esm/core/Siwe.js generated vendored Normal file
View File

@@ -0,0 +1,371 @@
import * as Address from './Address.js';
import * as Errors from './Errors.js';
import { uid } from './internal/uid.js';
export const domainRegex = /^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}(:[0-9]{1,5})?$/;
export const ipRegex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:[0-9]{1,5})?$/;
export const localhostRegex = /^localhost(:[0-9]{1,5})?$/;
export const nonceRegex = /^[a-zA-Z0-9]{8,}$/;
export const schemeRegex = /^([a-zA-Z][a-zA-Z0-9+-.]*)$/;
// https://regexr.com/80gdj
export const prefixRegex = /^(?:(?<scheme>[a-zA-Z][a-zA-Z0-9+-.]*):\/\/)?(?<domain>[a-zA-Z0-9+-.]*(?::[0-9]{1,5})?) (?:wants you to sign in with your Ethereum account:\n)(?<address>0x[a-fA-F0-9]{40})\n\n(?:(?<statement>.*)\n\n)?/;
// https://regexr.com/80gf9
export const suffixRegex = /(?:URI: (?<uri>.+))\n(?:Version: (?<version>.+))\n(?:Chain ID: (?<chainId>\d+))\n(?:Nonce: (?<nonce>[a-zA-Z0-9]+))\n(?:Issued At: (?<issuedAt>.+))(?:\nExpiration Time: (?<expirationTime>.+))?(?:\nNot Before: (?<notBefore>.+))?(?:\nRequest ID: (?<requestId>.+))?/;
/**
* Creates [EIP-4361](https://eips.ethereum.org/EIPS/eip-4361) formatted message.
*
* @example
* ```ts twoslash
* import { Siwe } from 'ox'
*
* Siwe.createMessage({
* address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* chainId: 1,
* domain: 'example.com',
* nonce: 'foobarbaz',
* uri: 'https://example.com/path',
* version: '1',
* })
* // @log: "example.com wants you to sign in with your Ethereum account:
* // @log: 0xA0Cf798816D4b9b9866b5330EEa46a18382f251e
* // @log:
* // @log:
* // @log: URI: https://example.com/path
* // @log: Version: 1
* // @log: Chain ID: 1
* // @log: Nonce: foobarbaz
* // @log: Issued At: 2023-02-01T00:00:00.000Z"
* ```
*
* @param value - Values to use when creating EIP-4361 formatted message.
* @returns EIP-4361 formatted message.
*/
export function createMessage(value) {
const { chainId, domain, expirationTime, issuedAt = new Date(), nonce, notBefore, requestId, resources, scheme, uri, version, } = value;
// Validate fields
{
// Required fields
if (chainId !== Math.floor(chainId))
throw new InvalidMessageFieldError({
field: 'chainId',
metaMessages: [
'- Chain ID must be a EIP-155 chain ID.',
'- See https://eips.ethereum.org/EIPS/eip-155',
'',
`Provided value: ${chainId}`,
],
});
if (!(domainRegex.test(domain) ||
ipRegex.test(domain) ||
localhostRegex.test(domain)))
throw new InvalidMessageFieldError({
field: 'domain',
metaMessages: [
'- Domain must be an RFC 3986 authority.',
'- See https://www.rfc-editor.org/rfc/rfc3986',
'',
`Provided value: ${domain}`,
],
});
if (!nonceRegex.test(nonce))
throw new InvalidMessageFieldError({
field: 'nonce',
metaMessages: [
'- Nonce must be at least 8 characters.',
'- Nonce must be alphanumeric.',
'',
`Provided value: ${nonce}`,
],
});
if (!isUri(uri))
throw new InvalidMessageFieldError({
field: 'uri',
metaMessages: [
'- URI must be a RFC 3986 URI referring to the resource that is the subject of the signing.',
'- See https://www.rfc-editor.org/rfc/rfc3986',
'',
`Provided value: ${uri}`,
],
});
if (version !== '1')
throw new InvalidMessageFieldError({
field: 'version',
metaMessages: [
"- Version must be '1'.",
'',
`Provided value: ${version}`,
],
});
// Optional fields
if (scheme && !schemeRegex.test(scheme))
throw new InvalidMessageFieldError({
field: 'scheme',
metaMessages: [
'- Scheme must be an RFC 3986 URI scheme.',
'- See https://www.rfc-editor.org/rfc/rfc3986#section-3.1',
'',
`Provided value: ${scheme}`,
],
});
const statement = value.statement;
if (statement?.includes('\n'))
throw new InvalidMessageFieldError({
field: 'statement',
metaMessages: [
"- Statement must not include '\\n'.",
'',
`Provided value: ${statement}`,
],
});
}
// Construct message
const address = Address.from(value.address, { checksum: true });
const origin = (() => {
if (scheme)
return `${scheme}://${domain}`;
return domain;
})();
const statement = (() => {
if (!value.statement)
return '';
return `${value.statement}\n`;
})();
const prefix = `${origin} wants you to sign in with your Ethereum account:\n${address}\n\n${statement}`;
let suffix = `URI: ${uri}\nVersion: ${version}\nChain ID: ${chainId}\nNonce: ${nonce}\nIssued At: ${issuedAt.toISOString()}`;
if (expirationTime)
suffix += `\nExpiration Time: ${expirationTime.toISOString()}`;
if (notBefore)
suffix += `\nNot Before: ${notBefore.toISOString()}`;
if (requestId)
suffix += `\nRequest ID: ${requestId}`;
if (resources) {
let content = '\nResources:';
for (const resource of resources) {
if (!isUri(resource))
throw new InvalidMessageFieldError({
field: 'resources',
metaMessages: [
'- Every resource must be a RFC 3986 URI.',
'- See https://www.rfc-editor.org/rfc/rfc3986',
'',
`Provided value: ${resource}`,
],
});
content += `\n- ${resource}`;
}
suffix += content;
}
return `${prefix}\n${suffix}`;
}
/**
* Generates random [EIP-4361](https://eips.ethereum.org/EIPS/eip-4361) nonce.
*
* @example
* ```ts twoslash
* import { Siwe } from 'ox'
*
* Siwe.generateNonce()
* // @log: '65ed4681d4efe0270b923ff5f4b097b1c95974dc33aeebecd5724c42fd86dfd25dc70b27ef836b2aa22e68f19ebcccc1'
* ```
*
* @returns Random nonce.
*/
export function generateNonce() {
return uid(96);
}
/**
* Check if the given URI is a valid [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986) URI.
*
* @example
* ```ts twoslash
* import { Siwe } from 'ox'
*
* Siwe.isUri('https://example.com/foo')
* // @log: true
* ```
*
* @param value - Value to check.
* @returns `false` if invalid, otherwise the valid URI.
*/
// based on https://github.com/ogt/valid-url
export function isUri(value) {
// check for illegal characters
if (/[^a-z0-9\:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=\.\-\_\~\%]/i.test(value))
return false;
// check for hex escapes that aren't complete
if (/%[^0-9a-f]/i.test(value))
return false;
if (/%[0-9a-f](:?[^0-9a-f]|$)/i.test(value))
return false;
// from RFC 3986
const splitted = splitUri(value);
const scheme = splitted[1];
const authority = splitted[2];
const path = splitted[3];
const query = splitted[4];
const fragment = splitted[5];
// scheme and path are required, though the path can be empty
if (!(scheme?.length && path && path.length >= 0))
return false;
// if authority is present, the path must be empty or begin with a /
if (authority?.length) {
if (!(path.length === 0 || /^\//.test(path)))
return false;
}
else {
// if authority is not present, the path must not start with //
if (/^\/\//.test(path))
return false;
}
// scheme must begin with a letter, then consist of letters, digits, +, ., or -
if (!/^[a-z][a-z0-9\+\-\.]*$/.test(scheme.toLowerCase()))
return false;
let out = '';
// re-assemble the URL per section 5.3 in RFC 3986
out += `${scheme}:`;
if (authority?.length)
out += `//${authority}`;
out += path;
if (query?.length)
out += `?${query}`;
if (fragment?.length)
out += `#${fragment}`;
return out;
}
function splitUri(value) {
return value.match(/(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/);
}
/**
* [EIP-4361](https://eips.ethereum.org/EIPS/eip-4361) formatted message into message fields object.
*
* @example
* ```ts twoslash
* import { Siwe } from 'ox'
*
* Siwe.parseMessage(`example.com wants you to sign in with your Ethereum account:
* 0xA0Cf798816D4b9b9866b5330EEa46a18382f251e
*
* I accept the ExampleOrg Terms of Service: https://example.com/tos
*
* URI: https://example.com/path
* Version: 1
* Chain ID: 1
* Nonce: foobarbaz
* Issued At: 2023-02-01T00:00:00.000Z`)
* // @log: {
* // @log: address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* // @log: chainId: 1,
* // @log: domain: 'example.com',
* // @log: issuedAt: '2023-02-01T00:00:00.000Z',
* // @log: nonce: 'foobarbaz',
* // @log: statement: 'I accept the ExampleOrg Terms of Service: https://example.com/tos',
* // @log: uri: 'https://example.com/path',
* // @log: version: '1',
* // @log: }
* ```
*
* @param message - [EIP-4361](https://eips.ethereum.org/EIPS/eip-4361) formatted message.
* @returns Message fields object.
*/
export function parseMessage(message) {
const { scheme, statement, ...prefix } = (message.match(prefixRegex)
?.groups ?? {});
const { chainId, expirationTime, issuedAt, notBefore, requestId, ...suffix } = (message.match(suffixRegex)?.groups ?? {});
const resources = message.split('Resources:')[1]?.split('\n- ').slice(1);
return {
...prefix,
...suffix,
...(chainId ? { chainId: Number(chainId) } : {}),
...(expirationTime ? { expirationTime: new Date(expirationTime) } : {}),
...(issuedAt ? { issuedAt: new Date(issuedAt) } : {}),
...(notBefore ? { notBefore: new Date(notBefore) } : {}),
...(requestId ? { requestId } : {}),
...(resources ? { resources } : {}),
...(scheme ? { scheme } : {}),
...(statement ? { statement } : {}),
};
}
/**
* Validates [EIP-4361](https://eips.ethereum.org/EIPS/eip-4361) message.
*
* @example
* ```ts twoslash
* import { Siwe } from 'ox'
*
* Siwe.validateMessage({
* address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* domain: 'example.com',
* message: {
* address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* chainId: 1,
* domain: 'example.com',
* nonce: 'foobarbaz',
* uri: 'https://example.com/path',
* version: '1',
* },
* nonce: 'foobarbaz',
* })
* // @log: true
* ```
*
* @param value - Values to use when validating EIP-4361 formatted message.
* @returns Whether the message is valid.
*/
export function validateMessage(value) {
const { address, domain, message, nonce, scheme, time = new Date() } = value;
if (domain && message.domain !== domain)
return false;
if (nonce && message.nonce !== nonce)
return false;
if (scheme && message.scheme !== scheme)
return false;
if (message.expirationTime && time >= message.expirationTime)
return false;
if (message.notBefore && time < message.notBefore)
return false;
try {
if (!message.address)
return false;
if (address && !Address.isEqual(message.address, address))
return false;
}
catch {
return false;
}
return true;
}
/**
* Thrown when a field in a SIWE Message is invalid.
*
* @example
* ```ts twoslash
* import { Siwe } from 'ox'
*
* Siwe.createMessage({
* address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* chainId: 1.1,
* domain: 'example.com',
* nonce: 'foobarbaz',
* uri: 'https://example.com/path',
* version: '1',
* })
* // @error: Siwe.InvalidMessageFieldError: Invalid Sign-In with Ethereum message field "chainId".
* // @error: - Chain ID must be a EIP-155 chain ID.
* // @error: - See https://eips.ethereum.org/EIPS/eip-155
* // @error: Provided value: 1.1
* ```
*/
export class InvalidMessageFieldError extends Errors.BaseError {
constructor(parameters) {
const { field, metaMessages } = parameters;
super(`Invalid Sign-In with Ethereum message field "${field}".`, {
metaMessages,
});
Object.defineProperty(this, "name", {
enumerable: true,
configurable: true,
writable: true,
value: 'Siwe.InvalidMessageFieldError'
});
}
}
//# sourceMappingURL=Siwe.js.map

1
node_modules/ox/_esm/core/Siwe.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

104
node_modules/ox/_esm/core/Solidity.js generated vendored Normal file
View File

@@ -0,0 +1,104 @@
export const arrayRegex = /^(.*)\[([0-9]*)\]$/;
// `bytes<M>`: binary type of `M` bytes, `0 < M <= 32`
// https://regexr.com/6va55
export const bytesRegex = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/;
// `(u)int<M>`: (un)signed integer type of `M` bits, `0 < M <= 256`, `M % 8 == 0`
// https://regexr.com/6v8hp
export const integerRegex = /^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;
export const maxInt8 = 2n ** (8n - 1n) - 1n;
export const maxInt16 = 2n ** (16n - 1n) - 1n;
export const maxInt24 = 2n ** (24n - 1n) - 1n;
export const maxInt32 = 2n ** (32n - 1n) - 1n;
export const maxInt40 = 2n ** (40n - 1n) - 1n;
export const maxInt48 = 2n ** (48n - 1n) - 1n;
export const maxInt56 = 2n ** (56n - 1n) - 1n;
export const maxInt64 = 2n ** (64n - 1n) - 1n;
export const maxInt72 = 2n ** (72n - 1n) - 1n;
export const maxInt80 = 2n ** (80n - 1n) - 1n;
export const maxInt88 = 2n ** (88n - 1n) - 1n;
export const maxInt96 = 2n ** (96n - 1n) - 1n;
export const maxInt104 = 2n ** (104n - 1n) - 1n;
export const maxInt112 = 2n ** (112n - 1n) - 1n;
export const maxInt120 = 2n ** (120n - 1n) - 1n;
export const maxInt128 = 2n ** (128n - 1n) - 1n;
export const maxInt136 = 2n ** (136n - 1n) - 1n;
export const maxInt144 = 2n ** (144n - 1n) - 1n;
export const maxInt152 = 2n ** (152n - 1n) - 1n;
export const maxInt160 = 2n ** (160n - 1n) - 1n;
export const maxInt168 = 2n ** (168n - 1n) - 1n;
export const maxInt176 = 2n ** (176n - 1n) - 1n;
export const maxInt184 = 2n ** (184n - 1n) - 1n;
export const maxInt192 = 2n ** (192n - 1n) - 1n;
export const maxInt200 = 2n ** (200n - 1n) - 1n;
export const maxInt208 = 2n ** (208n - 1n) - 1n;
export const maxInt216 = 2n ** (216n - 1n) - 1n;
export const maxInt224 = 2n ** (224n - 1n) - 1n;
export const maxInt232 = 2n ** (232n - 1n) - 1n;
export const maxInt240 = 2n ** (240n - 1n) - 1n;
export const maxInt248 = 2n ** (248n - 1n) - 1n;
export const maxInt256 = 2n ** (256n - 1n) - 1n;
export const minInt8 = -(2n ** (8n - 1n));
export const minInt16 = -(2n ** (16n - 1n));
export const minInt24 = -(2n ** (24n - 1n));
export const minInt32 = -(2n ** (32n - 1n));
export const minInt40 = -(2n ** (40n - 1n));
export const minInt48 = -(2n ** (48n - 1n));
export const minInt56 = -(2n ** (56n - 1n));
export const minInt64 = -(2n ** (64n - 1n));
export const minInt72 = -(2n ** (72n - 1n));
export const minInt80 = -(2n ** (80n - 1n));
export const minInt88 = -(2n ** (88n - 1n));
export const minInt96 = -(2n ** (96n - 1n));
export const minInt104 = -(2n ** (104n - 1n));
export const minInt112 = -(2n ** (112n - 1n));
export const minInt120 = -(2n ** (120n - 1n));
export const minInt128 = -(2n ** (128n - 1n));
export const minInt136 = -(2n ** (136n - 1n));
export const minInt144 = -(2n ** (144n - 1n));
export const minInt152 = -(2n ** (152n - 1n));
export const minInt160 = -(2n ** (160n - 1n));
export const minInt168 = -(2n ** (168n - 1n));
export const minInt176 = -(2n ** (176n - 1n));
export const minInt184 = -(2n ** (184n - 1n));
export const minInt192 = -(2n ** (192n - 1n));
export const minInt200 = -(2n ** (200n - 1n));
export const minInt208 = -(2n ** (208n - 1n));
export const minInt216 = -(2n ** (216n - 1n));
export const minInt224 = -(2n ** (224n - 1n));
export const minInt232 = -(2n ** (232n - 1n));
export const minInt240 = -(2n ** (240n - 1n));
export const minInt248 = -(2n ** (248n - 1n));
export const minInt256 = -(2n ** (256n - 1n));
export const maxUint8 = 2n ** 8n - 1n;
export const maxUint16 = 2n ** 16n - 1n;
export const maxUint24 = 2n ** 24n - 1n;
export const maxUint32 = 2n ** 32n - 1n;
export const maxUint40 = 2n ** 40n - 1n;
export const maxUint48 = 2n ** 48n - 1n;
export const maxUint56 = 2n ** 56n - 1n;
export const maxUint64 = 2n ** 64n - 1n;
export const maxUint72 = 2n ** 72n - 1n;
export const maxUint80 = 2n ** 80n - 1n;
export const maxUint88 = 2n ** 88n - 1n;
export const maxUint96 = 2n ** 96n - 1n;
export const maxUint104 = 2n ** 104n - 1n;
export const maxUint112 = 2n ** 112n - 1n;
export const maxUint120 = 2n ** 120n - 1n;
export const maxUint128 = 2n ** 128n - 1n;
export const maxUint136 = 2n ** 136n - 1n;
export const maxUint144 = 2n ** 144n - 1n;
export const maxUint152 = 2n ** 152n - 1n;
export const maxUint160 = 2n ** 160n - 1n;
export const maxUint168 = 2n ** 168n - 1n;
export const maxUint176 = 2n ** 176n - 1n;
export const maxUint184 = 2n ** 184n - 1n;
export const maxUint192 = 2n ** 192n - 1n;
export const maxUint200 = 2n ** 200n - 1n;
export const maxUint208 = 2n ** 208n - 1n;
export const maxUint216 = 2n ** 216n - 1n;
export const maxUint224 = 2n ** 224n - 1n;
export const maxUint232 = 2n ** 232n - 1n;
export const maxUint240 = 2n ** 240n - 1n;
export const maxUint248 = 2n ** 248n - 1n;
export const maxUint256 = 2n ** 256n - 1n;
//# sourceMappingURL=Solidity.js.map

1
node_modules/ox/_esm/core/Solidity.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

78
node_modules/ox/_esm/core/StateOverrides.js generated vendored Normal file
View File

@@ -0,0 +1,78 @@
import * as Hex from './Hex.js';
/**
* Converts an {@link ox#StateOverrides.Rpc} to an {@link ox#StateOverrides.StateOverrides}.
*
* @example
* ```ts twoslash
* import { StateOverrides } from 'ox'
*
* const stateOverrides = StateOverrides.fromRpc({
* '0x0000000000000000000000000000000000000000': {
* balance: '0x1',
* },
* })
* ```
*
* @param rpcStateOverrides - The RPC state overrides to convert.
* @returns An instantiated {@link ox#StateOverrides.StateOverrides}.
*/
export function fromRpc(rpcStateOverrides) {
const stateOverrides = {};
for (const [address, accountOverridesRpc] of Object.entries(rpcStateOverrides)) {
const accountOverrides = {};
if (accountOverridesRpc.balance)
accountOverrides.balance = BigInt(accountOverridesRpc.balance);
if (accountOverridesRpc.code)
accountOverrides.code = accountOverridesRpc.code;
if (accountOverridesRpc.movePrecompileToAddress)
accountOverrides.movePrecompileToAddress =
accountOverridesRpc.movePrecompileToAddress;
if (accountOverridesRpc.nonce)
accountOverrides.nonce = BigInt(accountOverridesRpc.nonce);
if (accountOverridesRpc.state)
accountOverrides.state = accountOverridesRpc.state;
if (accountOverridesRpc.stateDiff)
accountOverrides.stateDiff = accountOverridesRpc.stateDiff;
stateOverrides[address] = accountOverrides;
}
return stateOverrides;
}
/**
* Converts an {@link ox#StateOverrides.StateOverrides} to an {@link ox#StateOverrides.Rpc}.
*
* @example
* ```ts twoslash
* import { StateOverrides } from 'ox'
*
* const stateOverrides = StateOverrides.toRpc({
* '0x0000000000000000000000000000000000000000': {
* balance: 1n,
* },
* })
* ```
*
* @param stateOverrides - The state overrides to convert.
* @returns An instantiated {@link ox#StateOverrides.Rpc}.
*/
export function toRpc(stateOverrides) {
const rpcStateOverrides = {};
for (const [address, accountOverrides] of Object.entries(stateOverrides)) {
const accountOverridesRpc = {};
if (typeof accountOverrides.balance === 'bigint')
accountOverridesRpc.balance = Hex.fromNumber(accountOverrides.balance);
if (accountOverrides.code)
accountOverridesRpc.code = accountOverrides.code;
if (accountOverrides.movePrecompileToAddress)
accountOverridesRpc.movePrecompileToAddress =
accountOverrides.movePrecompileToAddress;
if (typeof accountOverrides.nonce === 'bigint')
accountOverridesRpc.nonce = Hex.fromNumber(accountOverrides.nonce);
if (accountOverrides.state)
accountOverridesRpc.state = accountOverrides.state;
if (accountOverrides.stateDiff)
accountOverridesRpc.stateDiff = accountOverrides.stateDiff;
rpcStateOverrides[address] = accountOverridesRpc;
}
return rpcStateOverrides;
}
//# sourceMappingURL=StateOverrides.js.map

1
node_modules/ox/_esm/core/StateOverrides.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"StateOverrides.js","sourceRoot":"","sources":["../../core/StateOverrides.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAoD/B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,OAAO,CAAC,iBAAsB;IAC5C,MAAM,cAAc,GAAmB,EAAE,CAAA;IACzC,KAAK,MAAM,CAAC,OAAO,EAAE,mBAAmB,CAAC,IAAI,MAAM,CAAC,OAAO,CACzD,iBAAiB,CAClB,EAAE,CAAC;QACF,MAAM,gBAAgB,GAAqB,EAAE,CAAA;QAC7C,IAAI,mBAAmB,CAAC,OAAO;YAC7B,gBAAgB,CAAC,OAAO,GAAG,MAAM,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAA;QAChE,IAAI,mBAAmB,CAAC,IAAI;YAC1B,gBAAgB,CAAC,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAA;QAClD,IAAI,mBAAmB,CAAC,uBAAuB;YAC7C,gBAAgB,CAAC,uBAAuB;gBACtC,mBAAmB,CAAC,uBAAuB,CAAA;QAC/C,IAAI,mBAAmB,CAAC,KAAK;YAC3B,gBAAgB,CAAC,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAA;QAC5D,IAAI,mBAAmB,CAAC,KAAK;YAC3B,gBAA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iBAAiB,CAAA;AAC1B,CAAC"}

170
node_modules/ox/_esm/core/Transaction.js generated vendored Normal file
View File

@@ -0,0 +1,170 @@
import * as Authorization from './Authorization.js';
import * as Hex from './Hex.js';
import * as Signature from './Signature.js';
/** Type to RPC Type mapping. */
export const toRpcType = {
legacy: '0x0',
eip2930: '0x1',
eip1559: '0x2',
eip4844: '0x3',
eip7702: '0x4',
};
/** RPC Type to Type mapping. */
export const fromRpcType = {
'0x0': 'legacy',
'0x1': 'eip2930',
'0x2': 'eip1559',
'0x3': 'eip4844',
'0x4': 'eip7702',
};
/**
* Converts an {@link ox#Transaction.Rpc} to an {@link ox#Transaction.Transaction}.
*
* @example
* ```ts twoslash
* import { Transaction } from 'ox'
*
* const transaction = Transaction.fromRpc({
* hash: '0x353fdfc38a2f26115daadee9f5b8392ce62b84f410957967e2ed56b35338cdd0',
* nonce: '0x357',
* blockHash:
* '0xc350d807505fb835650f0013632c5515592987ba169bbc6626d9fc54d91f0f0b',
* blockNumber: '0x12f296f',
* transactionIndex: '0x2',
* from: '0x814e5e0e31016b9a7f138c76b7e7b2bb5c1ab6a6',
* to: '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad',
* value: '0x9b6e64a8ec60000',
* gas: '0x43f5d',
* maxFeePerGas: '0x2ca6ae494',
* maxPriorityFeePerGas: '0x41cc3c0',
* input:
* '0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000006643504700000000000000000000000000000000000000000000000000000000000000040b080604000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000009b6e64a8ec600000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000009b6e64a8ec60000000000000000000000000000000000000000000000000000019124bb5ae978c000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000c56c7a0eaa804f854b536a5f3d5f49d2ec4b12b80000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c56c7a0eaa804f854b536a5f3d5f49d2ec4b12b8000000000000000000000000000000fee13a103a10d593b9ae06b3e05f2e7e1c00000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c56c7a0eaa804f854b536a5f3d5f49d2ec4b12b800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000190240001b9872b',
* r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
* s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
* yParity: '0x0',
* chainId: '0x1',
* accessList: [],
* type: '0x2',
* })
* ```
*
* @param transaction - The RPC transaction to convert.
* @returns An instantiated {@link ox#Transaction.Transaction}.
*/
export function fromRpc(transaction, _options = {}) {
if (!transaction)
return null;
const signature = Signature.extract(transaction);
const transaction_ = {
...transaction,
...signature,
};
transaction_.blockNumber = transaction.blockNumber
? BigInt(transaction.blockNumber)
: null;
transaction_.data = transaction.input;
transaction_.gas = BigInt(transaction.gas ?? 0n);
transaction_.nonce = BigInt(transaction.nonce ?? 0n);
transaction_.transactionIndex = transaction.transactionIndex
? Number(transaction.transactionIndex)
: null;
transaction_.value = BigInt(transaction.value ?? 0n);
if (transaction.authorizationList)
transaction_.authorizationList = Authorization.fromRpcList(transaction.authorizationList);
if (transaction.chainId)
transaction_.chainId = Number(transaction.chainId);
if (transaction.gasPrice)
transaction_.gasPrice = BigInt(transaction.gasPrice);
if (transaction.maxFeePerBlobGas)
transaction_.maxFeePerBlobGas = BigInt(transaction.maxFeePerBlobGas);
if (transaction.maxFeePerGas)
transaction_.maxFeePerGas = BigInt(transaction.maxFeePerGas);
if (transaction.maxPriorityFeePerGas)
transaction_.maxPriorityFeePerGas = BigInt(transaction.maxPriorityFeePerGas);
if (transaction.type)
transaction_.type =
fromRpcType[transaction.type] ?? transaction.type;
if (signature)
transaction_.v = Signature.yParityToV(signature.yParity);
return transaction_;
}
/**
* Converts an {@link ox#Transaction.Transaction} to an {@link ox#Transaction.Rpc}.
*
* @example
* ```ts twoslash
* import { Transaction } from 'ox'
*
* const transaction = Transaction.toRpc({
* accessList: [],
* blockHash:
* '0xc350d807505fb835650f0013632c5515592987ba169bbc6626d9fc54d91f0f0b',
* blockNumber: 19868015n,
* chainId: 1,
* from: '0x814e5e0e31016b9a7f138c76b7e7b2bb5c1ab6a6',
* gas: 278365n,
* hash: '0x353fdfc38a2f26115daadee9f5b8392ce62b84f410957967e2ed56b35338cdd0',
* input:
* '0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000006643504700000000000000000000000000000000000000000000000000000000000000040b080604000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000009b6e64a8ec600000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000009b6e64a8ec60000000000000000000000000000000000000000000000000000019124bb5ae978c000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000c56c7a0eaa804f854b536a5f3d5f49d2ec4b12b80000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c56c7a0eaa804f854b536a5f3d5f49d2ec4b12b8000000000000000000000000000000fee13a103a10d593b9ae06b3e05f2e7e1c00000000000000000000000000000000000000000000000000000000000000190000000000000000000000000000000000000000000000000000000000000060000000000000000000000000c56c7a0eaa804f854b536a5f3d5f49d2ec4b12b800000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000190240001b9872b',
* maxFeePerGas: 11985937556n,
* maxPriorityFeePerGas: 68993984n,
* nonce: 855n,
* r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n,
* s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n,
* to: '0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad',
* transactionIndex: 2,
* type: 'eip1559',
* v: 27,
* value: 700000000000000000n,
* yParity: 0,
* })
* ```
*
* @param transaction - The transaction to convert.
* @returns An RPC-formatted transaction.
*/
export function toRpc(transaction, _options) {
const rpc = {};
rpc.blockHash = transaction.blockHash;
rpc.blockNumber =
typeof transaction.blockNumber === 'bigint'
? Hex.fromNumber(transaction.blockNumber)
: null;
rpc.from = transaction.from;
rpc.gas = Hex.fromNumber(transaction.gas ?? 0n);
rpc.hash = transaction.hash;
rpc.input = transaction.input;
rpc.nonce = Hex.fromNumber(transaction.nonce ?? 0n);
rpc.to = transaction.to;
rpc.transactionIndex = transaction.transactionIndex
? Hex.fromNumber(transaction.transactionIndex)
: null;
rpc.type = toRpcType[transaction.type] ?? transaction.type;
rpc.value = Hex.fromNumber(transaction.value ?? 0n);
if (transaction.accessList)
rpc.accessList = transaction.accessList;
if (transaction.authorizationList)
rpc.authorizationList = Authorization.toRpcList(transaction.authorizationList);
if (transaction.blobVersionedHashes)
rpc.blobVersionedHashes = transaction.blobVersionedHashes;
if (transaction.chainId)
rpc.chainId = Hex.fromNumber(transaction.chainId);
if (typeof transaction.gasPrice === 'bigint')
rpc.gasPrice = Hex.fromNumber(transaction.gasPrice);
if (typeof transaction.maxFeePerBlobGas === 'bigint')
rpc.maxFeePerBlobGas = Hex.fromNumber(transaction.maxFeePerBlobGas);
if (typeof transaction.maxFeePerGas === 'bigint')
rpc.maxFeePerGas = Hex.fromNumber(transaction.maxFeePerGas);
if (typeof transaction.maxPriorityFeePerGas === 'bigint')
rpc.maxPriorityFeePerGas = Hex.fromNumber(transaction.maxPriorityFeePerGas);
if (typeof transaction.r === 'bigint')
rpc.r = Hex.fromNumber(transaction.r, { size: 32 });
if (typeof transaction.s === 'bigint')
rpc.s = Hex.fromNumber(transaction.s, { size: 32 });
if (typeof transaction.v === 'number')
rpc.v = Hex.fromNumber(transaction.v, { size: 1 });
if (typeof transaction.yParity === 'number')
rpc.yParity = transaction.yParity === 0 ? '0x0' : '0x1';
return rpc;
}
//# sourceMappingURL=Transaction.js.map

1
node_modules/ox/_esm/core/Transaction.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../core/Transaction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AA6M3C,gCAAgC;AAChC,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,KAAK;CACN,CAAA;AAOV,gCAAgC;AAChC,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,SAAS;CACR,CAAA;AAQV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,OAAO,CAIrB,WAA8C,EAC9C,WAAqC,EAAE;IAEvC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