x402-proxy 0.10.7 → 0.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -1
- package/README.md +7 -1
- package/dist/Credential-COZQnr1-.js +2055 -0
- package/dist/Mcp-CrCEqLqO.js +10 -0
- package/dist/Sse-ChldYgU7.js +9742 -0
- package/dist/Sse-kCB38G56.js +16482 -0
- package/dist/accounts-DsuvWwph.js +232 -0
- package/dist/accounts-DzvAlQRn.js +5 -0
- package/dist/accounts-IG-Cmrwy.js +229 -0
- package/dist/api-CUzmQvTQ.js +2802 -0
- package/dist/auth-DTzQmnZ_.js +1196 -0
- package/dist/bin/cli.js +585 -242
- package/dist/ccip-Bx-zoUCJ.js +240 -0
- package/dist/ccip-C2k1DD1T.js +153 -0
- package/dist/ccip-C6CQOJYv.js +152 -0
- package/dist/ccip-RZzsZ5Mv.js +156 -0
- package/dist/chain-CafcHffR.js +1997 -0
- package/dist/chain-DwfP5RGZ.js +1968 -0
- package/dist/chunk-DBEY4PJZ.js +16 -0
- package/dist/chunk-DjEMn6fM.js +36 -0
- package/dist/client-Blw2V7LF.js +657 -0
- package/dist/client-C37gWJOZ.js +102 -0
- package/dist/client-CEc4NYAA.js +6388 -0
- package/dist/client-CVDTUY0l.js +5152 -0
- package/dist/config-BUQsit4s.js +3 -0
- package/dist/config-DR1Fs_wL.js +6600 -0
- package/dist/{config-D9wIR3xc.js → config-rvKA3SYT.js} +10 -5
- package/dist/decodeFunctionData-DuFcwhC_.js +4510 -0
- package/dist/decodeFunctionData-JPOUdvil.js +4394 -0
- package/dist/derive-DNUl8LU9.js +9109 -0
- package/dist/dist-C2YO6HSQ.js +6581 -0
- package/dist/dist-DM5_F3r5.js +4 -0
- package/dist/dist-DxJCYyL5.js +1388 -0
- package/dist/hashTypedData-BHmP9dBd.js +859 -0
- package/dist/hashTypedData-CtEdfx4y.js +846 -0
- package/dist/helpers-CuUSw-tH.js +7125 -0
- package/dist/hmac-59IlS_by.js +648 -0
- package/dist/http-BAtucMbS.js +2060 -0
- package/dist/index.d.ts +1903 -9
- package/dist/index.js +18006 -50
- package/dist/index.node-CxkL0OFh.js +3592 -0
- package/dist/index.node-DvmeuZBj.js +3 -0
- package/dist/isAddressEqual-BLrd1Hg1.js +9 -0
- package/dist/isAddressEqual-DsAqfQOD.js +10 -0
- package/dist/localBatchGatewayRequest-C-RPJyDO.js +6260 -0
- package/dist/localBatchGatewayRequest-DOdQ9bR7.js +93 -0
- package/dist/localBatchGatewayRequest-DQkbZaSy.js +6261 -0
- package/dist/parseUnits-CApwcKSD.js +49 -0
- package/dist/parseUnits-cMO2udMe.js +48 -0
- package/dist/schemas-BxMFYNbH.js +1270 -0
- package/dist/secp256k1-BZpiyffY.js +2525 -0
- package/dist/secp256k1-BjenrLl5.js +1877 -0
- package/dist/secp256k1-CLPUX17u.js +3 -0
- package/dist/sendRawTransactionSync-DvSkhZtW.js +3612 -0
- package/dist/server-CSq0IuUq.js +565 -0
- package/dist/setup-BY4J49Lv.js +1110 -0
- package/dist/setup-wMOAgrsN.js +3 -0
- package/dist/sha256-FAs0qeni.js +17 -0
- package/dist/sha3-CYkWM8Xa.js +195 -0
- package/dist/sha3-DbMJRJ3C.js +194 -0
- package/dist/sse-B4LLqBQm.js +408 -0
- package/dist/status-Bu23RjW6.js +3 -0
- package/dist/{status-DihAcUSC.js → status-X21VnGUO.js} +16 -15
- package/dist/stdio-BADqxZdZ.js +85 -0
- package/dist/streamableHttp-BHkJypcI.js +358 -0
- package/dist/tempo-3nttrxgQ.js +17 -0
- package/dist/tempo-DER0P-ul.js +18 -0
- package/dist/types-BEKUz-Mf.js +1240 -0
- package/dist/types-DatK5vR5.js +3 -0
- package/dist/utils-BYjkXZDF.js +444 -0
- package/dist/utils-SeGHMW9O.js +445 -0
- package/dist/wallet-DKVlrR1S.js +3 -0
- package/dist/wallet-DSyht15_.js +17759 -0
- package/package.json +18 -71
- package/dist/config-B_upkJeK.js +0 -66
- package/dist/config-Be35NM5s.js +0 -3
- package/dist/config-J1m-CWXT.js +0 -27
- package/dist/derive-CL6e8K0Z.js +0 -81
- package/dist/openclaw/plugin.d.ts +0 -15
- package/dist/openclaw/plugin.js +0 -2067
- package/dist/openclaw.plugin.json +0 -93
- package/dist/setup-CNyMLnM-.js +0 -197
- package/dist/setup-DTIxPe58.js +0 -3
- package/dist/status-DZlJ4pS7.js +0 -3
- package/dist/wallet-B0S-rma9.js +0 -544
- package/dist/wallet-DBrVZJqe.js +0 -3
- package/openclaw.plugin.json +0 -93
- package/skills/SKILL.md +0 -183
- package/skills/references/library.md +0 -85
- package/skills/references/openclaw-plugin.md +0 -145
|
@@ -0,0 +1,3612 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { $ as stringify, $t as parseAbiParameter, A as padRight, Bt as ContractFunctionExecutionError, C as concat, D as fromNumber, E as fromBytes$2, G as size$1, H as fromHex$3, Ht as ContractFunctionZeroDataError, J as toBoolean, Jt as encodeFunctionData, K as slice$1, Lt as RpcRequestError, M as size, N as slice, O as fromString$1, Q as validate$3, Qt as parseStructs, R as trimLeft$1, T as fromBoolean, U as fromString, Ut as RawContractError, V as from$5, Vt as ContractFunctionRevertedError, X as toString, Y as toNumber, Z as trimLeft, an as modifiers, at as formatTransactionRequest, b as IntegerOutOfRangeError, ct as getNodeError, et as BaseError, ht as InvalidInputRpcError, in as isStructSignature, k as padLeft, mt as InternalRpcError, n as call, nn as InvalidAbiParametersError, nt as assertRequest, ot as defineFormatter, q as toBigInt, rt as serializeStateOverride, sn as formatAbiParameters, st as extract$1, tn as splitParameters, tt as decodeFunctionResult, w as from$6, x as InvalidLengthError, z as validate$2 } from "./decodeFunctionData-DuFcwhC_.js";
|
|
3
|
+
import { A as formatGwei, D as TransactionReceiptRevertedError, F as parseAccount, J as LruMap$1, Mt as BaseError$1, Nt as size$2, Pt as isHex, at as hexToBigInt, gt as AbiDecodingZeroDataError, j as formatEther, k as prettyPrint, rt as toHex$3, st as hexToNumber, tt as numberToHex, v as UnknownNodeError, w as TransactionExecutionError } from "./chain-CafcHffR.js";
|
|
4
|
+
import { t as keccak_256 } from "./sha3-CYkWM8Xa.js";
|
|
5
|
+
import { d as getTransactionType, f as toBlobSidecars, g as hashAuthorization, h as blobsToCommitments, m as blobsToProofs, p as commitmentsToVersionedHashes, v as publicKeyToAddress } from "./hashTypedData-CtEdfx4y.js";
|
|
6
|
+
import { t as sha256$1 } from "./sha256-FAs0qeni.js";
|
|
7
|
+
import { t as secp256k1 } from "./secp256k1-BjenrLl5.js";
|
|
8
|
+
//#region node_modules/.pnpm/abitype@1.2.3_typescript@5.9.3_zod@4.3.6/node_modules/abitype/dist/esm/human-readable/parseAbiParameters.js
|
|
9
|
+
/**
|
|
10
|
+
* Parses human-readable ABI parameters into {@link AbiParameter}s
|
|
11
|
+
*
|
|
12
|
+
* @param params - Human-readable ABI parameters
|
|
13
|
+
* @returns Parsed {@link AbiParameter}s
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const abiParameters = parseAbiParameters('address from, address to, uint256 amount')
|
|
17
|
+
* // ^? const abiParameters: [{ type: "address"; name: "from"; }, { type: "address";...
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const abiParameters = parseAbiParameters([
|
|
21
|
+
* // ^? const abiParameters: [{ type: "tuple"; components: [{ type: "string"; name:...
|
|
22
|
+
* 'Baz bar',
|
|
23
|
+
* 'struct Baz { string name; }',
|
|
24
|
+
* ])
|
|
25
|
+
*/
|
|
26
|
+
function parseAbiParameters(params) {
|
|
27
|
+
const abiParameters = [];
|
|
28
|
+
if (typeof params === "string") {
|
|
29
|
+
const parameters = splitParameters(params);
|
|
30
|
+
const length = parameters.length;
|
|
31
|
+
for (let i = 0; i < length; i++) abiParameters.push(parseAbiParameter(parameters[i], { modifiers }));
|
|
32
|
+
} else {
|
|
33
|
+
const structs = parseStructs(params);
|
|
34
|
+
const length = params.length;
|
|
35
|
+
for (let i = 0; i < length; i++) {
|
|
36
|
+
const signature = params[i];
|
|
37
|
+
if (isStructSignature(signature)) continue;
|
|
38
|
+
const parameters = splitParameters(signature);
|
|
39
|
+
const length = parameters.length;
|
|
40
|
+
for (let k = 0; k < length; k++) abiParameters.push(parseAbiParameter(parameters[k], {
|
|
41
|
+
modifiers,
|
|
42
|
+
structs
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (abiParameters.length === 0) throw new InvalidAbiParametersError({ params });
|
|
47
|
+
return abiParameters;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/utils/getAction.js
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves and returns an action from the client (if exists), and falls
|
|
53
|
+
* back to the tree-shakable action.
|
|
54
|
+
*
|
|
55
|
+
* Useful for extracting overridden actions from a client (ie. if a consumer
|
|
56
|
+
* wants to override the `sendTransaction` implementation).
|
|
57
|
+
*/
|
|
58
|
+
function getAction(client, actionFn, name) {
|
|
59
|
+
const action_implicit = client[actionFn.name];
|
|
60
|
+
if (typeof action_implicit === "function") return action_implicit;
|
|
61
|
+
const action_explicit = client[name];
|
|
62
|
+
if (typeof action_explicit === "function") return action_explicit;
|
|
63
|
+
return (params) => actionFn(client, params);
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/utils/errors/getContractError.js
|
|
67
|
+
const EXECUTION_REVERTED_ERROR_CODE = 3;
|
|
68
|
+
function getContractError(err, { abi, address, args, docsPath, functionName, sender }) {
|
|
69
|
+
const error = err instanceof RawContractError ? err : err instanceof BaseError$1 ? err.walk((err) => "data" in err) || err.walk() : {};
|
|
70
|
+
const { code, data, details, message, shortMessage } = error;
|
|
71
|
+
return new ContractFunctionExecutionError((() => {
|
|
72
|
+
if (err instanceof AbiDecodingZeroDataError) return new ContractFunctionZeroDataError({
|
|
73
|
+
functionName,
|
|
74
|
+
cause: err
|
|
75
|
+
});
|
|
76
|
+
if ([EXECUTION_REVERTED_ERROR_CODE, InternalRpcError.code].includes(code) && (data || details || message || shortMessage) || code === InvalidInputRpcError.code && details === "execution reverted" && data) return new ContractFunctionRevertedError({
|
|
77
|
+
abi,
|
|
78
|
+
data: typeof data === "object" ? data.data : data,
|
|
79
|
+
functionName,
|
|
80
|
+
message: error instanceof RpcRequestError ? details : shortMessage ?? message,
|
|
81
|
+
cause: err
|
|
82
|
+
});
|
|
83
|
+
return err;
|
|
84
|
+
})(), {
|
|
85
|
+
abi,
|
|
86
|
+
args,
|
|
87
|
+
contractAddress: address,
|
|
88
|
+
docsPath,
|
|
89
|
+
functionName,
|
|
90
|
+
sender
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/utils/signature/recoverPublicKey.js
|
|
95
|
+
async function recoverPublicKey$1({ hash, signature }) {
|
|
96
|
+
const hashHex = isHex(hash) ? hash : toHex$3(hash);
|
|
97
|
+
const { secp256k1 } = await import("./secp256k1-CLPUX17u.js");
|
|
98
|
+
return `0x${(() => {
|
|
99
|
+
if (typeof signature === "object" && "r" in signature && "s" in signature) {
|
|
100
|
+
const { r, s, v, yParity } = signature;
|
|
101
|
+
const recoveryBit = toRecoveryBit(Number(yParity ?? v));
|
|
102
|
+
return new secp256k1.Signature(hexToBigInt(r), hexToBigInt(s)).addRecoveryBit(recoveryBit);
|
|
103
|
+
}
|
|
104
|
+
const signatureHex = isHex(signature) ? signature : toHex$3(signature);
|
|
105
|
+
if (size$2(signatureHex) !== 65) throw new Error("invalid signature length");
|
|
106
|
+
const recoveryBit = toRecoveryBit(hexToNumber(`0x${signatureHex.slice(130)}`));
|
|
107
|
+
return secp256k1.Signature.fromCompact(signatureHex.substring(2, 130)).addRecoveryBit(recoveryBit);
|
|
108
|
+
})().recoverPublicKey(hashHex.substring(2)).toHex(false)}`;
|
|
109
|
+
}
|
|
110
|
+
function toRecoveryBit(yParityOrV) {
|
|
111
|
+
if (yParityOrV === 0 || yParityOrV === 1) return yParityOrV;
|
|
112
|
+
if (yParityOrV === 27) return 0;
|
|
113
|
+
if (yParityOrV === 28) return 1;
|
|
114
|
+
throw new Error("Invalid yParityOrV value");
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/utils/signature/recoverAddress.js
|
|
118
|
+
async function recoverAddress$1({ hash, signature }) {
|
|
119
|
+
return publicKeyToAddress(await recoverPublicKey$1({
|
|
120
|
+
hash,
|
|
121
|
+
signature
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/utils/authorization/recoverAuthorizationAddress.js
|
|
126
|
+
async function recoverAuthorizationAddress(parameters) {
|
|
127
|
+
const { authorization, signature } = parameters;
|
|
128
|
+
return recoverAddress$1({
|
|
129
|
+
hash: hashAuthorization(authorization),
|
|
130
|
+
signature: signature ?? authorization
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/errors/estimateGas.js
|
|
135
|
+
var EstimateGasExecutionError = class extends BaseError$1 {
|
|
136
|
+
constructor(cause, { account, docsPath, chain, data, gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas, nonce, to, value }) {
|
|
137
|
+
const prettyArgs = prettyPrint({
|
|
138
|
+
from: account?.address,
|
|
139
|
+
to,
|
|
140
|
+
value: typeof value !== "undefined" && `${formatEther(value)} ${chain?.nativeCurrency?.symbol || "ETH"}`,
|
|
141
|
+
data,
|
|
142
|
+
gas,
|
|
143
|
+
gasPrice: typeof gasPrice !== "undefined" && `${formatGwei(gasPrice)} gwei`,
|
|
144
|
+
maxFeePerGas: typeof maxFeePerGas !== "undefined" && `${formatGwei(maxFeePerGas)} gwei`,
|
|
145
|
+
maxPriorityFeePerGas: typeof maxPriorityFeePerGas !== "undefined" && `${formatGwei(maxPriorityFeePerGas)} gwei`,
|
|
146
|
+
nonce
|
|
147
|
+
});
|
|
148
|
+
super(cause.shortMessage, {
|
|
149
|
+
cause,
|
|
150
|
+
docsPath,
|
|
151
|
+
metaMessages: [
|
|
152
|
+
...cause.metaMessages ? [...cause.metaMessages, " "] : [],
|
|
153
|
+
"Estimate Gas Arguments:",
|
|
154
|
+
prettyArgs
|
|
155
|
+
].filter(Boolean),
|
|
156
|
+
name: "EstimateGasExecutionError"
|
|
157
|
+
});
|
|
158
|
+
Object.defineProperty(this, "cause", {
|
|
159
|
+
enumerable: true,
|
|
160
|
+
configurable: true,
|
|
161
|
+
writable: true,
|
|
162
|
+
value: void 0
|
|
163
|
+
});
|
|
164
|
+
this.cause = cause;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/utils/errors/getEstimateGasError.js
|
|
169
|
+
function getEstimateGasError(err, { docsPath, ...args }) {
|
|
170
|
+
return new EstimateGasExecutionError((() => {
|
|
171
|
+
const cause = getNodeError(err, args);
|
|
172
|
+
if (cause instanceof UnknownNodeError) return err;
|
|
173
|
+
return cause;
|
|
174
|
+
})(), {
|
|
175
|
+
docsPath,
|
|
176
|
+
...args
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/errors/fee.js
|
|
181
|
+
var BaseFeeScalarError = class extends BaseError$1 {
|
|
182
|
+
constructor() {
|
|
183
|
+
super("`baseFeeMultiplier` must be greater than 1.", { name: "BaseFeeScalarError" });
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var Eip1559FeesNotSupportedError = class extends BaseError$1 {
|
|
187
|
+
constructor() {
|
|
188
|
+
super("Chain does not support EIP-1559 fees.", { name: "Eip1559FeesNotSupportedError" });
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var MaxFeePerGasTooLowError = class extends BaseError$1 {
|
|
192
|
+
constructor({ maxPriorityFeePerGas }) {
|
|
193
|
+
super(`\`maxFeePerGas\` cannot be less than the \`maxPriorityFeePerGas\` (${formatGwei(maxPriorityFeePerGas)} gwei).`, { name: "MaxFeePerGasTooLowError" });
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/errors/block.js
|
|
198
|
+
var BlockNotFoundError = class extends BaseError$1 {
|
|
199
|
+
constructor({ blockHash, blockNumber }) {
|
|
200
|
+
let identifier = "Block";
|
|
201
|
+
if (blockHash) identifier = `Block at hash "${blockHash}"`;
|
|
202
|
+
if (blockNumber) identifier = `Block at number "${blockNumber}"`;
|
|
203
|
+
super(`${identifier} could not be found.`, { name: "BlockNotFoundError" });
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/utils/formatters/transaction.js
|
|
208
|
+
const transactionType = {
|
|
209
|
+
"0x0": "legacy",
|
|
210
|
+
"0x1": "eip2930",
|
|
211
|
+
"0x2": "eip1559",
|
|
212
|
+
"0x3": "eip4844",
|
|
213
|
+
"0x4": "eip7702"
|
|
214
|
+
};
|
|
215
|
+
function formatTransaction(transaction, _) {
|
|
216
|
+
const transaction_ = {
|
|
217
|
+
...transaction,
|
|
218
|
+
blockHash: transaction.blockHash ? transaction.blockHash : null,
|
|
219
|
+
blockNumber: transaction.blockNumber ? BigInt(transaction.blockNumber) : null,
|
|
220
|
+
chainId: transaction.chainId ? hexToNumber(transaction.chainId) : void 0,
|
|
221
|
+
gas: transaction.gas ? BigInt(transaction.gas) : void 0,
|
|
222
|
+
gasPrice: transaction.gasPrice ? BigInt(transaction.gasPrice) : void 0,
|
|
223
|
+
maxFeePerBlobGas: transaction.maxFeePerBlobGas ? BigInt(transaction.maxFeePerBlobGas) : void 0,
|
|
224
|
+
maxFeePerGas: transaction.maxFeePerGas ? BigInt(transaction.maxFeePerGas) : void 0,
|
|
225
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas ? BigInt(transaction.maxPriorityFeePerGas) : void 0,
|
|
226
|
+
nonce: transaction.nonce ? hexToNumber(transaction.nonce) : void 0,
|
|
227
|
+
to: transaction.to ? transaction.to : null,
|
|
228
|
+
transactionIndex: transaction.transactionIndex ? Number(transaction.transactionIndex) : null,
|
|
229
|
+
type: transaction.type ? transactionType[transaction.type] : void 0,
|
|
230
|
+
typeHex: transaction.type ? transaction.type : void 0,
|
|
231
|
+
value: transaction.value ? BigInt(transaction.value) : void 0,
|
|
232
|
+
v: transaction.v ? BigInt(transaction.v) : void 0
|
|
233
|
+
};
|
|
234
|
+
if (transaction.authorizationList) transaction_.authorizationList = formatAuthorizationList(transaction.authorizationList);
|
|
235
|
+
transaction_.yParity = (() => {
|
|
236
|
+
if (transaction.yParity) return Number(transaction.yParity);
|
|
237
|
+
if (typeof transaction_.v === "bigint") {
|
|
238
|
+
if (transaction_.v === 0n || transaction_.v === 27n) return 0;
|
|
239
|
+
if (transaction_.v === 1n || transaction_.v === 28n) return 1;
|
|
240
|
+
if (transaction_.v >= 35n) return transaction_.v % 2n === 0n ? 1 : 0;
|
|
241
|
+
}
|
|
242
|
+
})();
|
|
243
|
+
if (transaction_.type === "legacy") {
|
|
244
|
+
delete transaction_.accessList;
|
|
245
|
+
delete transaction_.maxFeePerBlobGas;
|
|
246
|
+
delete transaction_.maxFeePerGas;
|
|
247
|
+
delete transaction_.maxPriorityFeePerGas;
|
|
248
|
+
delete transaction_.yParity;
|
|
249
|
+
}
|
|
250
|
+
if (transaction_.type === "eip2930") {
|
|
251
|
+
delete transaction_.maxFeePerBlobGas;
|
|
252
|
+
delete transaction_.maxFeePerGas;
|
|
253
|
+
delete transaction_.maxPriorityFeePerGas;
|
|
254
|
+
}
|
|
255
|
+
if (transaction_.type === "eip1559") delete transaction_.maxFeePerBlobGas;
|
|
256
|
+
return transaction_;
|
|
257
|
+
}
|
|
258
|
+
const defineTransaction = /* @__PURE__ */ defineFormatter("transaction", formatTransaction);
|
|
259
|
+
function formatAuthorizationList(authorizationList) {
|
|
260
|
+
return authorizationList.map((authorization) => ({
|
|
261
|
+
address: authorization.address,
|
|
262
|
+
chainId: Number(authorization.chainId),
|
|
263
|
+
nonce: Number(authorization.nonce),
|
|
264
|
+
r: authorization.r,
|
|
265
|
+
s: authorization.s,
|
|
266
|
+
yParity: Number(authorization.yParity)
|
|
267
|
+
}));
|
|
268
|
+
}
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/utils/formatters/block.js
|
|
271
|
+
function formatBlock(block, _) {
|
|
272
|
+
const transactions = (block.transactions ?? []).map((transaction) => {
|
|
273
|
+
if (typeof transaction === "string") return transaction;
|
|
274
|
+
return formatTransaction(transaction);
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
...block,
|
|
278
|
+
baseFeePerGas: block.baseFeePerGas ? BigInt(block.baseFeePerGas) : null,
|
|
279
|
+
blobGasUsed: block.blobGasUsed ? BigInt(block.blobGasUsed) : void 0,
|
|
280
|
+
difficulty: block.difficulty ? BigInt(block.difficulty) : void 0,
|
|
281
|
+
excessBlobGas: block.excessBlobGas ? BigInt(block.excessBlobGas) : void 0,
|
|
282
|
+
gasLimit: block.gasLimit ? BigInt(block.gasLimit) : void 0,
|
|
283
|
+
gasUsed: block.gasUsed ? BigInt(block.gasUsed) : void 0,
|
|
284
|
+
hash: block.hash ? block.hash : null,
|
|
285
|
+
logsBloom: block.logsBloom ? block.logsBloom : null,
|
|
286
|
+
nonce: block.nonce ? block.nonce : null,
|
|
287
|
+
number: block.number ? BigInt(block.number) : null,
|
|
288
|
+
size: block.size ? BigInt(block.size) : void 0,
|
|
289
|
+
timestamp: block.timestamp ? BigInt(block.timestamp) : void 0,
|
|
290
|
+
transactions,
|
|
291
|
+
totalDifficulty: block.totalDifficulty ? BigInt(block.totalDifficulty) : null
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
const defineBlock = /* @__PURE__ */ defineFormatter("block", formatBlock);
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/public/getBlock.js
|
|
297
|
+
/**
|
|
298
|
+
* Returns information about a block at a block number, hash, or tag.
|
|
299
|
+
*
|
|
300
|
+
* - Docs: https://viem.sh/docs/actions/public/getBlock
|
|
301
|
+
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks_fetching-blocks
|
|
302
|
+
* - JSON-RPC Methods:
|
|
303
|
+
* - Calls [`eth_getBlockByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber) for `blockNumber` & `blockTag`.
|
|
304
|
+
* - Calls [`eth_getBlockByHash`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbyhash) for `blockHash`.
|
|
305
|
+
*
|
|
306
|
+
* @param client - Client to use
|
|
307
|
+
* @param parameters - {@link GetBlockParameters}
|
|
308
|
+
* @returns Information about the block. {@link GetBlockReturnType}
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* import { createPublicClient, http } from 'viem'
|
|
312
|
+
* import { mainnet } from 'viem/chains'
|
|
313
|
+
* import { getBlock } from 'viem/public'
|
|
314
|
+
*
|
|
315
|
+
* const client = createPublicClient({
|
|
316
|
+
* chain: mainnet,
|
|
317
|
+
* transport: http(),
|
|
318
|
+
* })
|
|
319
|
+
* const block = await getBlock(client)
|
|
320
|
+
*/
|
|
321
|
+
async function getBlock(client, { blockHash, blockNumber, blockTag = client.experimental_blockTag ?? "latest", includeTransactions: includeTransactions_ } = {}) {
|
|
322
|
+
const includeTransactions = includeTransactions_ ?? false;
|
|
323
|
+
const blockNumberHex = blockNumber !== void 0 ? numberToHex(blockNumber) : void 0;
|
|
324
|
+
let block = null;
|
|
325
|
+
if (blockHash) block = await client.request({
|
|
326
|
+
method: "eth_getBlockByHash",
|
|
327
|
+
params: [blockHash, includeTransactions]
|
|
328
|
+
}, { dedupe: true });
|
|
329
|
+
else block = await client.request({
|
|
330
|
+
method: "eth_getBlockByNumber",
|
|
331
|
+
params: [blockNumberHex || blockTag, includeTransactions]
|
|
332
|
+
}, { dedupe: Boolean(blockNumberHex) });
|
|
333
|
+
if (!block) throw new BlockNotFoundError({
|
|
334
|
+
blockHash,
|
|
335
|
+
blockNumber
|
|
336
|
+
});
|
|
337
|
+
return (client.chain?.formatters?.block?.format || formatBlock)(block, "getBlock");
|
|
338
|
+
}
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/public/getGasPrice.js
|
|
341
|
+
/**
|
|
342
|
+
* Returns the current price of gas (in wei).
|
|
343
|
+
*
|
|
344
|
+
* - Docs: https://viem.sh/docs/actions/public/getGasPrice
|
|
345
|
+
* - JSON-RPC Methods: [`eth_gasPrice`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gasprice)
|
|
346
|
+
*
|
|
347
|
+
* @param client - Client to use
|
|
348
|
+
* @returns The gas price (in wei). {@link GetGasPriceReturnType}
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* import { createPublicClient, http } from 'viem'
|
|
352
|
+
* import { mainnet } from 'viem/chains'
|
|
353
|
+
* import { getGasPrice } from 'viem/public'
|
|
354
|
+
*
|
|
355
|
+
* const client = createPublicClient({
|
|
356
|
+
* chain: mainnet,
|
|
357
|
+
* transport: http(),
|
|
358
|
+
* })
|
|
359
|
+
* const gasPrice = await getGasPrice(client)
|
|
360
|
+
*/
|
|
361
|
+
async function getGasPrice(client) {
|
|
362
|
+
const gasPrice = await client.request({ method: "eth_gasPrice" });
|
|
363
|
+
return BigInt(gasPrice);
|
|
364
|
+
}
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/public/estimateMaxPriorityFeePerGas.js
|
|
367
|
+
/**
|
|
368
|
+
* Returns an estimate for the max priority fee per gas (in wei) for a
|
|
369
|
+
* transaction to be likely included in the next block.
|
|
370
|
+
* Defaults to [`chain.fees.defaultPriorityFee`](/docs/clients/chains#fees-defaultpriorityfee) if set.
|
|
371
|
+
*
|
|
372
|
+
* - Docs: https://viem.sh/docs/actions/public/estimateMaxPriorityFeePerGas
|
|
373
|
+
*
|
|
374
|
+
* @param client - Client to use
|
|
375
|
+
* @returns An estimate (in wei) for the max priority fee per gas. {@link EstimateMaxPriorityFeePerGasReturnType}
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* import { createPublicClient, http } from 'viem'
|
|
379
|
+
* import { mainnet } from 'viem/chains'
|
|
380
|
+
* import { estimateMaxPriorityFeePerGas } from 'viem/actions'
|
|
381
|
+
*
|
|
382
|
+
* const client = createPublicClient({
|
|
383
|
+
* chain: mainnet,
|
|
384
|
+
* transport: http(),
|
|
385
|
+
* })
|
|
386
|
+
* const maxPriorityFeePerGas = await estimateMaxPriorityFeePerGas(client)
|
|
387
|
+
* // 10000000n
|
|
388
|
+
*/
|
|
389
|
+
async function estimateMaxPriorityFeePerGas(client, args) {
|
|
390
|
+
return internal_estimateMaxPriorityFeePerGas(client, args);
|
|
391
|
+
}
|
|
392
|
+
async function internal_estimateMaxPriorityFeePerGas(client, args) {
|
|
393
|
+
const { block: block_, chain = client.chain, request } = args || {};
|
|
394
|
+
try {
|
|
395
|
+
const maxPriorityFeePerGas = chain?.fees?.maxPriorityFeePerGas ?? chain?.fees?.defaultPriorityFee;
|
|
396
|
+
if (typeof maxPriorityFeePerGas === "function") {
|
|
397
|
+
const maxPriorityFeePerGas_ = await maxPriorityFeePerGas({
|
|
398
|
+
block: block_ || await getAction(client, getBlock, "getBlock")({}),
|
|
399
|
+
client,
|
|
400
|
+
request
|
|
401
|
+
});
|
|
402
|
+
if (maxPriorityFeePerGas_ === null) throw new Error();
|
|
403
|
+
return maxPriorityFeePerGas_;
|
|
404
|
+
}
|
|
405
|
+
if (typeof maxPriorityFeePerGas !== "undefined") return maxPriorityFeePerGas;
|
|
406
|
+
return hexToBigInt(await client.request({ method: "eth_maxPriorityFeePerGas" }));
|
|
407
|
+
} catch {
|
|
408
|
+
const [block, gasPrice] = await Promise.all([block_ ? Promise.resolve(block_) : getAction(client, getBlock, "getBlock")({}), getAction(client, getGasPrice, "getGasPrice")({})]);
|
|
409
|
+
if (typeof block.baseFeePerGas !== "bigint") throw new Eip1559FeesNotSupportedError();
|
|
410
|
+
const maxPriorityFeePerGas = gasPrice - block.baseFeePerGas;
|
|
411
|
+
if (maxPriorityFeePerGas < 0n) return 0n;
|
|
412
|
+
return maxPriorityFeePerGas;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/public/estimateFeesPerGas.js
|
|
417
|
+
/**
|
|
418
|
+
* Returns an estimate for the fees per gas (in wei) for a
|
|
419
|
+
* transaction to be likely included in the next block.
|
|
420
|
+
* Defaults to [`chain.fees.estimateFeesPerGas`](/docs/clients/chains#fees-estimatefeespergas) if set.
|
|
421
|
+
*
|
|
422
|
+
* - Docs: https://viem.sh/docs/actions/public/estimateFeesPerGas
|
|
423
|
+
*
|
|
424
|
+
* @param client - Client to use
|
|
425
|
+
* @param parameters - {@link EstimateFeesPerGasParameters}
|
|
426
|
+
* @returns An estimate (in wei) for the fees per gas. {@link EstimateFeesPerGasReturnType}
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* import { createPublicClient, http } from 'viem'
|
|
430
|
+
* import { mainnet } from 'viem/chains'
|
|
431
|
+
* import { estimateFeesPerGas } from 'viem/actions'
|
|
432
|
+
*
|
|
433
|
+
* const client = createPublicClient({
|
|
434
|
+
* chain: mainnet,
|
|
435
|
+
* transport: http(),
|
|
436
|
+
* })
|
|
437
|
+
* const maxPriorityFeePerGas = await estimateFeesPerGas(client)
|
|
438
|
+
* // { maxFeePerGas: ..., maxPriorityFeePerGas: ... }
|
|
439
|
+
*/
|
|
440
|
+
async function estimateFeesPerGas(client, args) {
|
|
441
|
+
return internal_estimateFeesPerGas(client, args);
|
|
442
|
+
}
|
|
443
|
+
async function internal_estimateFeesPerGas(client, args) {
|
|
444
|
+
const { block: block_, chain = client.chain, request, type = "eip1559" } = args || {};
|
|
445
|
+
const baseFeeMultiplier = await (async () => {
|
|
446
|
+
if (typeof chain?.fees?.baseFeeMultiplier === "function") return chain.fees.baseFeeMultiplier({
|
|
447
|
+
block: block_,
|
|
448
|
+
client,
|
|
449
|
+
request
|
|
450
|
+
});
|
|
451
|
+
return chain?.fees?.baseFeeMultiplier ?? 1.2;
|
|
452
|
+
})();
|
|
453
|
+
if (baseFeeMultiplier < 1) throw new BaseFeeScalarError();
|
|
454
|
+
const denominator = 10 ** (baseFeeMultiplier.toString().split(".")[1]?.length ?? 0);
|
|
455
|
+
const multiply = (base) => base * BigInt(Math.ceil(baseFeeMultiplier * denominator)) / BigInt(denominator);
|
|
456
|
+
const block = block_ ? block_ : await getAction(client, getBlock, "getBlock")({});
|
|
457
|
+
if (typeof chain?.fees?.estimateFeesPerGas === "function") {
|
|
458
|
+
const fees = await chain.fees.estimateFeesPerGas({
|
|
459
|
+
block: block_,
|
|
460
|
+
client,
|
|
461
|
+
multiply,
|
|
462
|
+
request,
|
|
463
|
+
type
|
|
464
|
+
});
|
|
465
|
+
if (fees !== null) return fees;
|
|
466
|
+
}
|
|
467
|
+
if (type === "eip1559") {
|
|
468
|
+
if (typeof block.baseFeePerGas !== "bigint") throw new Eip1559FeesNotSupportedError();
|
|
469
|
+
const maxPriorityFeePerGas = typeof request?.maxPriorityFeePerGas === "bigint" ? request.maxPriorityFeePerGas : await internal_estimateMaxPriorityFeePerGas(client, {
|
|
470
|
+
block,
|
|
471
|
+
chain,
|
|
472
|
+
request
|
|
473
|
+
});
|
|
474
|
+
const baseFeePerGas = multiply(block.baseFeePerGas);
|
|
475
|
+
return {
|
|
476
|
+
maxFeePerGas: request?.maxFeePerGas ?? baseFeePerGas + maxPriorityFeePerGas,
|
|
477
|
+
maxPriorityFeePerGas
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
return { gasPrice: request?.gasPrice ?? multiply(await getAction(client, getGasPrice, "getGasPrice")({})) };
|
|
481
|
+
}
|
|
482
|
+
//#endregion
|
|
483
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/public/getTransactionCount.js
|
|
484
|
+
/**
|
|
485
|
+
* Returns the number of [Transactions](https://viem.sh/docs/glossary/terms#transaction) an Account has sent.
|
|
486
|
+
*
|
|
487
|
+
* - Docs: https://viem.sh/docs/actions/public/getTransactionCount
|
|
488
|
+
* - JSON-RPC Methods: [`eth_getTransactionCount`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactioncount)
|
|
489
|
+
*
|
|
490
|
+
* @param client - Client to use
|
|
491
|
+
* @param parameters - {@link GetTransactionCountParameters}
|
|
492
|
+
* @returns The number of transactions an account has sent. {@link GetTransactionCountReturnType}
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* import { createPublicClient, http } from 'viem'
|
|
496
|
+
* import { mainnet } from 'viem/chains'
|
|
497
|
+
* import { getTransactionCount } from 'viem/public'
|
|
498
|
+
*
|
|
499
|
+
* const client = createPublicClient({
|
|
500
|
+
* chain: mainnet,
|
|
501
|
+
* transport: http(),
|
|
502
|
+
* })
|
|
503
|
+
* const transactionCount = await getTransactionCount(client, {
|
|
504
|
+
* address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
|
505
|
+
* })
|
|
506
|
+
*/
|
|
507
|
+
async function getTransactionCount(client, { address, blockTag = "latest", blockNumber }) {
|
|
508
|
+
return hexToNumber(await client.request({
|
|
509
|
+
method: "eth_getTransactionCount",
|
|
510
|
+
params: [address, typeof blockNumber === "bigint" ? numberToHex(blockNumber) : blockTag]
|
|
511
|
+
}, { dedupe: Boolean(blockNumber) }));
|
|
512
|
+
}
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/utils/errors/getTransactionError.js
|
|
515
|
+
function getTransactionError(err, { docsPath, ...args }) {
|
|
516
|
+
return new TransactionExecutionError((() => {
|
|
517
|
+
const cause = getNodeError(err, args);
|
|
518
|
+
if (cause instanceof UnknownNodeError) return err;
|
|
519
|
+
return cause;
|
|
520
|
+
})(), {
|
|
521
|
+
docsPath,
|
|
522
|
+
...args
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/public/getChainId.js
|
|
527
|
+
/**
|
|
528
|
+
* Returns the chain ID associated with the current network.
|
|
529
|
+
*
|
|
530
|
+
* - Docs: https://viem.sh/docs/actions/public/getChainId
|
|
531
|
+
* - JSON-RPC Methods: [`eth_chainId`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_chainid)
|
|
532
|
+
*
|
|
533
|
+
* @param client - Client to use
|
|
534
|
+
* @returns The current chain ID. {@link GetChainIdReturnType}
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* import { createPublicClient, http } from 'viem'
|
|
538
|
+
* import { mainnet } from 'viem/chains'
|
|
539
|
+
* import { getChainId } from 'viem/public'
|
|
540
|
+
*
|
|
541
|
+
* const client = createPublicClient({
|
|
542
|
+
* chain: mainnet,
|
|
543
|
+
* transport: http(),
|
|
544
|
+
* })
|
|
545
|
+
* const chainId = await getChainId(client)
|
|
546
|
+
* // 1
|
|
547
|
+
*/
|
|
548
|
+
async function getChainId(client) {
|
|
549
|
+
return hexToNumber(await client.request({ method: "eth_chainId" }, { dedupe: true }));
|
|
550
|
+
}
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/public/fillTransaction.js
|
|
553
|
+
/**
|
|
554
|
+
* Fills a transaction request with the necessary fields to be signed over.
|
|
555
|
+
*
|
|
556
|
+
* - Docs: https://viem.sh/docs/actions/public/fillTransaction
|
|
557
|
+
*
|
|
558
|
+
* @param client - Client to use
|
|
559
|
+
* @param parameters - {@link FillTransactionParameters}
|
|
560
|
+
* @returns The filled transaction. {@link FillTransactionReturnType}
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* import { createPublicClient, http } from 'viem'
|
|
564
|
+
* import { mainnet } from 'viem/chains'
|
|
565
|
+
* import { fillTransaction } from 'viem/public'
|
|
566
|
+
*
|
|
567
|
+
* const client = createPublicClient({
|
|
568
|
+
* chain: mainnet,
|
|
569
|
+
* transport: http(),
|
|
570
|
+
* })
|
|
571
|
+
* const result = await fillTransaction(client, {
|
|
572
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
|
573
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
|
574
|
+
* value: parseEther('1'),
|
|
575
|
+
* })
|
|
576
|
+
*/
|
|
577
|
+
async function fillTransaction(client, parameters) {
|
|
578
|
+
const { account = client.account, accessList, authorizationList, chain = client.chain, blobVersionedHashes, blobs, data, gas, gasPrice, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, nonce: nonce_, nonceManager, to, type, value, ...rest } = parameters;
|
|
579
|
+
const nonce = await (async () => {
|
|
580
|
+
if (!account) return nonce_;
|
|
581
|
+
if (!nonceManager) return nonce_;
|
|
582
|
+
if (typeof nonce_ !== "undefined") return nonce_;
|
|
583
|
+
const account_ = parseAccount(account);
|
|
584
|
+
const chainId = chain ? chain.id : await getAction(client, getChainId, "getChainId")({});
|
|
585
|
+
return await nonceManager.consume({
|
|
586
|
+
address: account_.address,
|
|
587
|
+
chainId,
|
|
588
|
+
client
|
|
589
|
+
});
|
|
590
|
+
})();
|
|
591
|
+
assertRequest(parameters);
|
|
592
|
+
const chainFormat = chain?.formatters?.transactionRequest?.format;
|
|
593
|
+
const request = (chainFormat || formatTransactionRequest)({
|
|
594
|
+
...extract$1(rest, { format: chainFormat }),
|
|
595
|
+
account: account ? parseAccount(account) : void 0,
|
|
596
|
+
accessList,
|
|
597
|
+
authorizationList,
|
|
598
|
+
blobs,
|
|
599
|
+
blobVersionedHashes,
|
|
600
|
+
data,
|
|
601
|
+
gas,
|
|
602
|
+
gasPrice,
|
|
603
|
+
maxFeePerBlobGas,
|
|
604
|
+
maxFeePerGas,
|
|
605
|
+
maxPriorityFeePerGas,
|
|
606
|
+
nonce,
|
|
607
|
+
to,
|
|
608
|
+
type,
|
|
609
|
+
value
|
|
610
|
+
}, "fillTransaction");
|
|
611
|
+
try {
|
|
612
|
+
const response = await client.request({
|
|
613
|
+
method: "eth_fillTransaction",
|
|
614
|
+
params: [request]
|
|
615
|
+
});
|
|
616
|
+
const transaction = (chain?.formatters?.transaction?.format || formatTransaction)(response.tx);
|
|
617
|
+
delete transaction.blockHash;
|
|
618
|
+
delete transaction.blockNumber;
|
|
619
|
+
delete transaction.r;
|
|
620
|
+
delete transaction.s;
|
|
621
|
+
delete transaction.transactionIndex;
|
|
622
|
+
delete transaction.v;
|
|
623
|
+
delete transaction.yParity;
|
|
624
|
+
transaction.data = transaction.input;
|
|
625
|
+
if (transaction.gas) transaction.gas = parameters.gas ?? transaction.gas;
|
|
626
|
+
if (transaction.gasPrice) transaction.gasPrice = parameters.gasPrice ?? transaction.gasPrice;
|
|
627
|
+
if (transaction.maxFeePerBlobGas) transaction.maxFeePerBlobGas = parameters.maxFeePerBlobGas ?? transaction.maxFeePerBlobGas;
|
|
628
|
+
if (transaction.maxFeePerGas) transaction.maxFeePerGas = parameters.maxFeePerGas ?? transaction.maxFeePerGas;
|
|
629
|
+
if (transaction.maxPriorityFeePerGas) transaction.maxPriorityFeePerGas = parameters.maxPriorityFeePerGas ?? transaction.maxPriorityFeePerGas;
|
|
630
|
+
if (transaction.nonce) transaction.nonce = parameters.nonce ?? transaction.nonce;
|
|
631
|
+
const feeMultiplier = await (async () => {
|
|
632
|
+
if (typeof chain?.fees?.baseFeeMultiplier === "function") {
|
|
633
|
+
const block = await getAction(client, getBlock, "getBlock")({});
|
|
634
|
+
return chain.fees.baseFeeMultiplier({
|
|
635
|
+
block,
|
|
636
|
+
client,
|
|
637
|
+
request: parameters
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
return chain?.fees?.baseFeeMultiplier ?? 1.2;
|
|
641
|
+
})();
|
|
642
|
+
if (feeMultiplier < 1) throw new BaseFeeScalarError();
|
|
643
|
+
const denominator = 10 ** (feeMultiplier.toString().split(".")[1]?.length ?? 0);
|
|
644
|
+
const multiplyFee = (base) => base * BigInt(Math.ceil(feeMultiplier * denominator)) / BigInt(denominator);
|
|
645
|
+
if (transaction.maxFeePerGas && !parameters.maxFeePerGas) transaction.maxFeePerGas = multiplyFee(transaction.maxFeePerGas);
|
|
646
|
+
if (transaction.gasPrice && !parameters.gasPrice) transaction.gasPrice = multiplyFee(transaction.gasPrice);
|
|
647
|
+
return {
|
|
648
|
+
raw: response.raw,
|
|
649
|
+
transaction: {
|
|
650
|
+
from: request.from,
|
|
651
|
+
...transaction
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
} catch (err) {
|
|
655
|
+
throw getTransactionError(err, {
|
|
656
|
+
...parameters,
|
|
657
|
+
chain: client.chain
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
//#endregion
|
|
662
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/wallet/prepareTransactionRequest.js
|
|
663
|
+
const defaultParameters = [
|
|
664
|
+
"blobVersionedHashes",
|
|
665
|
+
"chainId",
|
|
666
|
+
"fees",
|
|
667
|
+
"gas",
|
|
668
|
+
"nonce",
|
|
669
|
+
"type"
|
|
670
|
+
];
|
|
671
|
+
/** @internal */
|
|
672
|
+
const eip1559NetworkCache = /* @__PURE__ */ new Map();
|
|
673
|
+
/** @internal */
|
|
674
|
+
const supportsFillTransaction = /* @__PURE__ */ new LruMap$1(128);
|
|
675
|
+
/**
|
|
676
|
+
* Prepares a transaction request for signing.
|
|
677
|
+
*
|
|
678
|
+
* - Docs: https://viem.sh/docs/actions/wallet/prepareTransactionRequest
|
|
679
|
+
*
|
|
680
|
+
* @param args - {@link PrepareTransactionRequestParameters}
|
|
681
|
+
* @returns The transaction request. {@link PrepareTransactionRequestReturnType}
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* import { createWalletClient, custom } from 'viem'
|
|
685
|
+
* import { mainnet } from 'viem/chains'
|
|
686
|
+
* import { prepareTransactionRequest } from 'viem/actions'
|
|
687
|
+
*
|
|
688
|
+
* const client = createWalletClient({
|
|
689
|
+
* chain: mainnet,
|
|
690
|
+
* transport: custom(window.ethereum),
|
|
691
|
+
* })
|
|
692
|
+
* const request = await prepareTransactionRequest(client, {
|
|
693
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
|
694
|
+
* to: '0x0000000000000000000000000000000000000000',
|
|
695
|
+
* value: 1n,
|
|
696
|
+
* })
|
|
697
|
+
*
|
|
698
|
+
* @example
|
|
699
|
+
* // Account Hoisting
|
|
700
|
+
* import { createWalletClient, http } from 'viem'
|
|
701
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
702
|
+
* import { mainnet } from 'viem/chains'
|
|
703
|
+
* import { prepareTransactionRequest } from 'viem/actions'
|
|
704
|
+
*
|
|
705
|
+
* const client = createWalletClient({
|
|
706
|
+
* account: privateKeyToAccount('0x…'),
|
|
707
|
+
* chain: mainnet,
|
|
708
|
+
* transport: custom(window.ethereum),
|
|
709
|
+
* })
|
|
710
|
+
* const request = await prepareTransactionRequest(client, {
|
|
711
|
+
* to: '0x0000000000000000000000000000000000000000',
|
|
712
|
+
* value: 1n,
|
|
713
|
+
* })
|
|
714
|
+
*/
|
|
715
|
+
async function prepareTransactionRequest(client, args) {
|
|
716
|
+
let request = args;
|
|
717
|
+
request.account ??= client.account;
|
|
718
|
+
request.parameters ??= defaultParameters;
|
|
719
|
+
const { account: account_, chain = client.chain, nonceManager, parameters } = request;
|
|
720
|
+
const prepareTransactionRequest = (() => {
|
|
721
|
+
if (typeof chain?.prepareTransactionRequest === "function") return {
|
|
722
|
+
fn: chain.prepareTransactionRequest,
|
|
723
|
+
runAt: ["beforeFillTransaction"]
|
|
724
|
+
};
|
|
725
|
+
if (Array.isArray(chain?.prepareTransactionRequest)) return {
|
|
726
|
+
fn: chain.prepareTransactionRequest[0],
|
|
727
|
+
runAt: chain.prepareTransactionRequest[1].runAt
|
|
728
|
+
};
|
|
729
|
+
})();
|
|
730
|
+
let chainId;
|
|
731
|
+
async function getChainId$1() {
|
|
732
|
+
if (chainId) return chainId;
|
|
733
|
+
if (typeof request.chainId !== "undefined") return request.chainId;
|
|
734
|
+
if (chain) return chain.id;
|
|
735
|
+
chainId = await getAction(client, getChainId, "getChainId")({});
|
|
736
|
+
return chainId;
|
|
737
|
+
}
|
|
738
|
+
const account = account_ ? parseAccount(account_) : account_;
|
|
739
|
+
let nonce = request.nonce;
|
|
740
|
+
if (parameters.includes("nonce") && typeof nonce === "undefined" && account && nonceManager) {
|
|
741
|
+
const chainId = await getChainId$1();
|
|
742
|
+
nonce = await nonceManager.consume({
|
|
743
|
+
address: account.address,
|
|
744
|
+
chainId,
|
|
745
|
+
client
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
if (prepareTransactionRequest?.fn && prepareTransactionRequest.runAt?.includes("beforeFillTransaction")) {
|
|
749
|
+
request = await prepareTransactionRequest.fn({
|
|
750
|
+
...request,
|
|
751
|
+
chain
|
|
752
|
+
}, { phase: "beforeFillTransaction" });
|
|
753
|
+
nonce ??= request.nonce;
|
|
754
|
+
}
|
|
755
|
+
const fillResult = (() => {
|
|
756
|
+
if ((parameters.includes("blobVersionedHashes") || parameters.includes("sidecars")) && request.kzg && request.blobs) return false;
|
|
757
|
+
if (supportsFillTransaction.get(client.uid) === false) return false;
|
|
758
|
+
if (!["fees", "gas"].some((parameter) => parameters.includes(parameter))) return false;
|
|
759
|
+
if (parameters.includes("chainId") && typeof request.chainId !== "number") return true;
|
|
760
|
+
if (parameters.includes("nonce") && typeof nonce !== "number") return true;
|
|
761
|
+
if (parameters.includes("fees") && typeof request.gasPrice !== "bigint" && (typeof request.maxFeePerGas !== "bigint" || typeof request.maxPriorityFeePerGas !== "bigint")) return true;
|
|
762
|
+
if (parameters.includes("gas") && typeof request.gas !== "bigint") return true;
|
|
763
|
+
return false;
|
|
764
|
+
})() ? await getAction(client, fillTransaction, "fillTransaction")({
|
|
765
|
+
...request,
|
|
766
|
+
nonce
|
|
767
|
+
}).then((result) => {
|
|
768
|
+
const { chainId, from, gas, gasPrice, nonce, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, type, ...rest } = result.transaction;
|
|
769
|
+
supportsFillTransaction.set(client.uid, true);
|
|
770
|
+
return {
|
|
771
|
+
...request,
|
|
772
|
+
...from ? { from } : {},
|
|
773
|
+
...type && !request.type ? { type } : {},
|
|
774
|
+
...typeof chainId !== "undefined" ? { chainId } : {},
|
|
775
|
+
...typeof gas !== "undefined" ? { gas } : {},
|
|
776
|
+
...typeof gasPrice !== "undefined" ? { gasPrice } : {},
|
|
777
|
+
...typeof nonce !== "undefined" ? { nonce } : {},
|
|
778
|
+
...typeof maxFeePerBlobGas !== "undefined" && request.type !== "legacy" && request.type !== "eip2930" ? { maxFeePerBlobGas } : {},
|
|
779
|
+
...typeof maxFeePerGas !== "undefined" && request.type !== "legacy" && request.type !== "eip2930" ? { maxFeePerGas } : {},
|
|
780
|
+
...typeof maxPriorityFeePerGas !== "undefined" && request.type !== "legacy" && request.type !== "eip2930" ? { maxPriorityFeePerGas } : {},
|
|
781
|
+
..."nonceKey" in rest && typeof rest.nonceKey !== "undefined" ? { nonceKey: rest.nonceKey } : {}
|
|
782
|
+
};
|
|
783
|
+
}).catch((e) => {
|
|
784
|
+
const error = e;
|
|
785
|
+
if (error.name !== "TransactionExecutionError") return request;
|
|
786
|
+
if (error.walk?.((e) => {
|
|
787
|
+
const error = e;
|
|
788
|
+
return error.name === "MethodNotFoundRpcError" || error.name === "MethodNotSupportedRpcError" || error.message?.includes("eth_fillTransaction is not available");
|
|
789
|
+
})) supportsFillTransaction.set(client.uid, false);
|
|
790
|
+
return request;
|
|
791
|
+
}) : request;
|
|
792
|
+
nonce ??= fillResult.nonce;
|
|
793
|
+
request = {
|
|
794
|
+
...fillResult,
|
|
795
|
+
...account ? { from: account?.address } : {},
|
|
796
|
+
...nonce ? { nonce } : {}
|
|
797
|
+
};
|
|
798
|
+
const { blobs, gas, kzg, type } = request;
|
|
799
|
+
if (prepareTransactionRequest?.fn && prepareTransactionRequest.runAt?.includes("beforeFillParameters")) request = await prepareTransactionRequest.fn({
|
|
800
|
+
...request,
|
|
801
|
+
chain
|
|
802
|
+
}, { phase: "beforeFillParameters" });
|
|
803
|
+
let block;
|
|
804
|
+
async function getBlock$1() {
|
|
805
|
+
if (block) return block;
|
|
806
|
+
block = await getAction(client, getBlock, "getBlock")({ blockTag: "latest" });
|
|
807
|
+
return block;
|
|
808
|
+
}
|
|
809
|
+
if (parameters.includes("nonce") && typeof nonce === "undefined" && account && !nonceManager) request.nonce = await getAction(client, getTransactionCount, "getTransactionCount")({
|
|
810
|
+
address: account.address,
|
|
811
|
+
blockTag: "pending"
|
|
812
|
+
});
|
|
813
|
+
if ((parameters.includes("blobVersionedHashes") || parameters.includes("sidecars")) && blobs && kzg) {
|
|
814
|
+
const commitments = blobsToCommitments({
|
|
815
|
+
blobs,
|
|
816
|
+
kzg
|
|
817
|
+
});
|
|
818
|
+
if (parameters.includes("blobVersionedHashes")) {
|
|
819
|
+
const versionedHashes = commitmentsToVersionedHashes({
|
|
820
|
+
commitments,
|
|
821
|
+
to: "hex"
|
|
822
|
+
});
|
|
823
|
+
request.blobVersionedHashes = versionedHashes;
|
|
824
|
+
}
|
|
825
|
+
if (parameters.includes("sidecars")) {
|
|
826
|
+
const sidecars = toBlobSidecars({
|
|
827
|
+
blobs,
|
|
828
|
+
commitments,
|
|
829
|
+
proofs: blobsToProofs({
|
|
830
|
+
blobs,
|
|
831
|
+
commitments,
|
|
832
|
+
kzg
|
|
833
|
+
}),
|
|
834
|
+
to: "hex"
|
|
835
|
+
});
|
|
836
|
+
request.sidecars = sidecars;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (parameters.includes("chainId")) request.chainId = await getChainId$1();
|
|
840
|
+
if ((parameters.includes("fees") || parameters.includes("type")) && typeof type === "undefined") try {
|
|
841
|
+
request.type = getTransactionType(request);
|
|
842
|
+
} catch {
|
|
843
|
+
let isEip1559Network = eip1559NetworkCache.get(client.uid);
|
|
844
|
+
if (typeof isEip1559Network === "undefined") {
|
|
845
|
+
isEip1559Network = typeof (await getBlock$1())?.baseFeePerGas === "bigint";
|
|
846
|
+
eip1559NetworkCache.set(client.uid, isEip1559Network);
|
|
847
|
+
}
|
|
848
|
+
request.type = isEip1559Network ? "eip1559" : "legacy";
|
|
849
|
+
}
|
|
850
|
+
if (parameters.includes("fees")) if (request.type !== "legacy" && request.type !== "eip2930") {
|
|
851
|
+
if (typeof request.maxFeePerGas === "undefined" || typeof request.maxPriorityFeePerGas === "undefined") {
|
|
852
|
+
const { maxFeePerGas, maxPriorityFeePerGas } = await internal_estimateFeesPerGas(client, {
|
|
853
|
+
block: await getBlock$1(),
|
|
854
|
+
chain,
|
|
855
|
+
request
|
|
856
|
+
});
|
|
857
|
+
if (typeof request.maxPriorityFeePerGas === "undefined" && request.maxFeePerGas && request.maxFeePerGas < maxPriorityFeePerGas) throw new MaxFeePerGasTooLowError({ maxPriorityFeePerGas });
|
|
858
|
+
request.maxPriorityFeePerGas = maxPriorityFeePerGas;
|
|
859
|
+
request.maxFeePerGas = maxFeePerGas;
|
|
860
|
+
}
|
|
861
|
+
} else {
|
|
862
|
+
if (typeof request.maxFeePerGas !== "undefined" || typeof request.maxPriorityFeePerGas !== "undefined") throw new Eip1559FeesNotSupportedError();
|
|
863
|
+
if (typeof request.gasPrice === "undefined") {
|
|
864
|
+
const { gasPrice: gasPrice_ } = await internal_estimateFeesPerGas(client, {
|
|
865
|
+
block: await getBlock$1(),
|
|
866
|
+
chain,
|
|
867
|
+
request,
|
|
868
|
+
type: "legacy"
|
|
869
|
+
});
|
|
870
|
+
request.gasPrice = gasPrice_;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
if (parameters.includes("gas") && typeof gas === "undefined") request.gas = await getAction(client, estimateGas, "estimateGas")({
|
|
874
|
+
...request,
|
|
875
|
+
account,
|
|
876
|
+
prepare: account?.type === "local" ? [] : ["blobVersionedHashes"]
|
|
877
|
+
});
|
|
878
|
+
if (prepareTransactionRequest?.fn && prepareTransactionRequest.runAt?.includes("afterFillParameters")) request = await prepareTransactionRequest.fn({
|
|
879
|
+
...request,
|
|
880
|
+
chain
|
|
881
|
+
}, { phase: "afterFillParameters" });
|
|
882
|
+
assertRequest(request);
|
|
883
|
+
delete request.parameters;
|
|
884
|
+
return request;
|
|
885
|
+
}
|
|
886
|
+
//#endregion
|
|
887
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/public/estimateGas.js
|
|
888
|
+
/**
|
|
889
|
+
* Estimates the gas necessary to complete a transaction without submitting it to the network.
|
|
890
|
+
*
|
|
891
|
+
* - Docs: https://viem.sh/docs/actions/public/estimateGas
|
|
892
|
+
* - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
|
|
893
|
+
*
|
|
894
|
+
* @param client - Client to use
|
|
895
|
+
* @param parameters - {@link EstimateGasParameters}
|
|
896
|
+
* @returns The gas estimate (in gas units). {@link EstimateGasReturnType}
|
|
897
|
+
*
|
|
898
|
+
* @example
|
|
899
|
+
* import { createPublicClient, http, parseEther } from 'viem'
|
|
900
|
+
* import { mainnet } from 'viem/chains'
|
|
901
|
+
* import { estimateGas } from 'viem/public'
|
|
902
|
+
*
|
|
903
|
+
* const client = createPublicClient({
|
|
904
|
+
* chain: mainnet,
|
|
905
|
+
* transport: http(),
|
|
906
|
+
* })
|
|
907
|
+
* const gasEstimate = await estimateGas(client, {
|
|
908
|
+
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
|
909
|
+
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
|
910
|
+
* value: parseEther('1'),
|
|
911
|
+
* })
|
|
912
|
+
*/
|
|
913
|
+
async function estimateGas(client, args) {
|
|
914
|
+
const { account: account_ = client.account, prepare = true } = args;
|
|
915
|
+
const account = account_ ? parseAccount(account_) : void 0;
|
|
916
|
+
const parameters = (() => {
|
|
917
|
+
if (Array.isArray(prepare)) return prepare;
|
|
918
|
+
if (account?.type !== "local") return ["blobVersionedHashes"];
|
|
919
|
+
})();
|
|
920
|
+
try {
|
|
921
|
+
const to = await (async () => {
|
|
922
|
+
if (args.to) return args.to;
|
|
923
|
+
if (args.authorizationList && args.authorizationList.length > 0) return await recoverAuthorizationAddress({ authorization: args.authorizationList[0] }).catch(() => {
|
|
924
|
+
throw new BaseError$1("`to` is required. Could not infer from `authorizationList`");
|
|
925
|
+
});
|
|
926
|
+
})();
|
|
927
|
+
const { accessList, authorizationList, blobs, blobVersionedHashes, blockNumber, blockTag, data, gas, gasPrice, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, nonce, value, stateOverride, ...rest } = prepare ? await prepareTransactionRequest(client, {
|
|
928
|
+
...args,
|
|
929
|
+
parameters,
|
|
930
|
+
to
|
|
931
|
+
}) : args;
|
|
932
|
+
if (gas && args.gas !== gas) return gas;
|
|
933
|
+
const block = (typeof blockNumber === "bigint" ? numberToHex(blockNumber) : void 0) || blockTag;
|
|
934
|
+
const rpcStateOverride = serializeStateOverride(stateOverride);
|
|
935
|
+
assertRequest(args);
|
|
936
|
+
const chainFormat = client.chain?.formatters?.transactionRequest?.format;
|
|
937
|
+
const request = (chainFormat || formatTransactionRequest)({
|
|
938
|
+
...extract$1(rest, { format: chainFormat }),
|
|
939
|
+
account,
|
|
940
|
+
accessList,
|
|
941
|
+
authorizationList,
|
|
942
|
+
blobs,
|
|
943
|
+
blobVersionedHashes,
|
|
944
|
+
data,
|
|
945
|
+
gasPrice,
|
|
946
|
+
maxFeePerBlobGas,
|
|
947
|
+
maxFeePerGas,
|
|
948
|
+
maxPriorityFeePerGas,
|
|
949
|
+
nonce,
|
|
950
|
+
to,
|
|
951
|
+
value
|
|
952
|
+
}, "estimateGas");
|
|
953
|
+
return BigInt(await client.request({
|
|
954
|
+
method: "eth_estimateGas",
|
|
955
|
+
params: rpcStateOverride ? [
|
|
956
|
+
request,
|
|
957
|
+
block ?? client.experimental_blockTag ?? "latest",
|
|
958
|
+
rpcStateOverride
|
|
959
|
+
] : block ? [request, block] : [request]
|
|
960
|
+
}));
|
|
961
|
+
} catch (err) {
|
|
962
|
+
throw getEstimateGasError(err, {
|
|
963
|
+
...args,
|
|
964
|
+
account,
|
|
965
|
+
chain: client.chain
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
//#endregion
|
|
970
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/utils/formatters/log.js
|
|
971
|
+
function formatLog(log, { args, eventName } = {}) {
|
|
972
|
+
return {
|
|
973
|
+
...log,
|
|
974
|
+
blockHash: log.blockHash ? log.blockHash : null,
|
|
975
|
+
blockNumber: log.blockNumber ? BigInt(log.blockNumber) : null,
|
|
976
|
+
blockTimestamp: log.blockTimestamp ? BigInt(log.blockTimestamp) : log.blockTimestamp === null ? null : void 0,
|
|
977
|
+
logIndex: log.logIndex ? Number(log.logIndex) : null,
|
|
978
|
+
transactionHash: log.transactionHash ? log.transactionHash : null,
|
|
979
|
+
transactionIndex: log.transactionIndex ? Number(log.transactionIndex) : null,
|
|
980
|
+
...eventName ? {
|
|
981
|
+
args,
|
|
982
|
+
eventName
|
|
983
|
+
} : {}
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
//#endregion
|
|
987
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/public/readContract.js
|
|
988
|
+
/**
|
|
989
|
+
* Calls a read-only function on a contract, and returns the response.
|
|
990
|
+
*
|
|
991
|
+
* - Docs: https://viem.sh/docs/contract/readContract
|
|
992
|
+
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/contracts_reading-contracts
|
|
993
|
+
*
|
|
994
|
+
* A "read-only" function (constant function) on a Solidity contract is denoted by a `view` or `pure` keyword. They can only read the state of the contract, and cannot make any changes to it. Since read-only methods do not change the state of the contract, they do not require any gas to be executed, and can be called by any user without the need to pay for gas.
|
|
995
|
+
*
|
|
996
|
+
* Internally, uses a [Public Client](https://viem.sh/docs/clients/public) to call the [`call` action](https://viem.sh/docs/actions/public/call) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData).
|
|
997
|
+
*
|
|
998
|
+
* @param client - Client to use
|
|
999
|
+
* @param parameters - {@link ReadContractParameters}
|
|
1000
|
+
* @returns The response from the contract. Type is inferred. {@link ReadContractReturnType}
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* import { createPublicClient, http, parseAbi } from 'viem'
|
|
1004
|
+
* import { mainnet } from 'viem/chains'
|
|
1005
|
+
* import { readContract } from 'viem/contract'
|
|
1006
|
+
*
|
|
1007
|
+
* const client = createPublicClient({
|
|
1008
|
+
* chain: mainnet,
|
|
1009
|
+
* transport: http(),
|
|
1010
|
+
* })
|
|
1011
|
+
* const result = await readContract(client, {
|
|
1012
|
+
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
|
|
1013
|
+
* abi: parseAbi(['function balanceOf(address) view returns (uint256)']),
|
|
1014
|
+
* functionName: 'balanceOf',
|
|
1015
|
+
* args: ['0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'],
|
|
1016
|
+
* })
|
|
1017
|
+
* // 424122n
|
|
1018
|
+
*/
|
|
1019
|
+
async function readContract(client, parameters) {
|
|
1020
|
+
const { abi, address, args, functionName, ...rest } = parameters;
|
|
1021
|
+
const calldata = encodeFunctionData({
|
|
1022
|
+
abi,
|
|
1023
|
+
args,
|
|
1024
|
+
functionName
|
|
1025
|
+
});
|
|
1026
|
+
try {
|
|
1027
|
+
const { data } = await getAction(client, call, "call")({
|
|
1028
|
+
...rest,
|
|
1029
|
+
data: calldata,
|
|
1030
|
+
to: address
|
|
1031
|
+
});
|
|
1032
|
+
return decodeFunctionResult({
|
|
1033
|
+
abi,
|
|
1034
|
+
args,
|
|
1035
|
+
functionName,
|
|
1036
|
+
data: data || "0x"
|
|
1037
|
+
});
|
|
1038
|
+
} catch (error) {
|
|
1039
|
+
throw getContractError(error, {
|
|
1040
|
+
abi,
|
|
1041
|
+
address,
|
|
1042
|
+
args,
|
|
1043
|
+
docsPath: "/docs/contract/readContract",
|
|
1044
|
+
functionName
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
//#endregion
|
|
1049
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/wallet/sendRawTransaction.js
|
|
1050
|
+
/**
|
|
1051
|
+
* Sends a **signed** transaction to the network
|
|
1052
|
+
*
|
|
1053
|
+
* - Docs: https://viem.sh/docs/actions/wallet/sendRawTransaction
|
|
1054
|
+
* - JSON-RPC Method: [`eth_sendRawTransaction`](https://ethereum.github.io/execution-apis/api-documentation/)
|
|
1055
|
+
*
|
|
1056
|
+
* @param client - Client to use
|
|
1057
|
+
* @param parameters - {@link SendRawTransactionParameters}
|
|
1058
|
+
* @returns The transaction hash. {@link SendRawTransactionReturnType}
|
|
1059
|
+
*
|
|
1060
|
+
* @example
|
|
1061
|
+
* import { createWalletClient, custom } from 'viem'
|
|
1062
|
+
* import { mainnet } from 'viem/chains'
|
|
1063
|
+
* import { sendRawTransaction } from 'viem/wallet'
|
|
1064
|
+
*
|
|
1065
|
+
* const client = createWalletClient({
|
|
1066
|
+
* chain: mainnet,
|
|
1067
|
+
* transport: custom(window.ethereum),
|
|
1068
|
+
* })
|
|
1069
|
+
*
|
|
1070
|
+
* const hash = await sendRawTransaction(client, {
|
|
1071
|
+
* serializedTransaction: '0x02f850018203118080825208808080c080a04012522854168b27e5dc3d5839bab5e6b39e1a0ffd343901ce1622e3d64b48f1a04e00902ae0502c4728cbf12156290df99c3ed7de85b1dbfe20b5c36931733a33'
|
|
1072
|
+
* })
|
|
1073
|
+
*/
|
|
1074
|
+
async function sendRawTransaction(client, { serializedTransaction }) {
|
|
1075
|
+
return client.request({
|
|
1076
|
+
method: "eth_sendRawTransaction",
|
|
1077
|
+
params: [serializedTransaction]
|
|
1078
|
+
}, { retryCount: 0 });
|
|
1079
|
+
}
|
|
1080
|
+
//#endregion
|
|
1081
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/utils/formatters/transactionReceipt.js
|
|
1082
|
+
const receiptStatuses = {
|
|
1083
|
+
"0x0": "reverted",
|
|
1084
|
+
"0x1": "success"
|
|
1085
|
+
};
|
|
1086
|
+
function formatTransactionReceipt(transactionReceipt, _) {
|
|
1087
|
+
const receipt = {
|
|
1088
|
+
...transactionReceipt,
|
|
1089
|
+
blockNumber: transactionReceipt.blockNumber ? BigInt(transactionReceipt.blockNumber) : null,
|
|
1090
|
+
contractAddress: transactionReceipt.contractAddress ? transactionReceipt.contractAddress : null,
|
|
1091
|
+
cumulativeGasUsed: transactionReceipt.cumulativeGasUsed ? BigInt(transactionReceipt.cumulativeGasUsed) : null,
|
|
1092
|
+
effectiveGasPrice: transactionReceipt.effectiveGasPrice ? BigInt(transactionReceipt.effectiveGasPrice) : null,
|
|
1093
|
+
gasUsed: transactionReceipt.gasUsed ? BigInt(transactionReceipt.gasUsed) : null,
|
|
1094
|
+
logs: transactionReceipt.logs ? transactionReceipt.logs.map((log) => formatLog(log)) : null,
|
|
1095
|
+
to: transactionReceipt.to ? transactionReceipt.to : null,
|
|
1096
|
+
transactionIndex: transactionReceipt.transactionIndex ? hexToNumber(transactionReceipt.transactionIndex) : null,
|
|
1097
|
+
status: transactionReceipt.status ? receiptStatuses[transactionReceipt.status] : null,
|
|
1098
|
+
type: transactionReceipt.type ? transactionType[transactionReceipt.type] || transactionReceipt.type : null
|
|
1099
|
+
};
|
|
1100
|
+
if (transactionReceipt.blobGasPrice) receipt.blobGasPrice = BigInt(transactionReceipt.blobGasPrice);
|
|
1101
|
+
if (transactionReceipt.blobGasUsed) receipt.blobGasUsed = BigInt(transactionReceipt.blobGasUsed);
|
|
1102
|
+
return receipt;
|
|
1103
|
+
}
|
|
1104
|
+
const defineTransactionReceipt = /* @__PURE__ */ defineFormatter("transactionReceipt", formatTransactionReceipt);
|
|
1105
|
+
//#endregion
|
|
1106
|
+
//#region node_modules/.pnpm/ox@0.14.7_typescript@5.9.3_zod@4.3.6/node_modules/ox/_esm/core/internal/lru.js
|
|
1107
|
+
/**
|
|
1108
|
+
* @internal
|
|
1109
|
+
*
|
|
1110
|
+
* Map with a LRU (Least recently used) policy.
|
|
1111
|
+
* @see https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
|
|
1112
|
+
*/
|
|
1113
|
+
var LruMap = class extends Map {
|
|
1114
|
+
constructor(size) {
|
|
1115
|
+
super();
|
|
1116
|
+
Object.defineProperty(this, "maxSize", {
|
|
1117
|
+
enumerable: true,
|
|
1118
|
+
configurable: true,
|
|
1119
|
+
writable: true,
|
|
1120
|
+
value: void 0
|
|
1121
|
+
});
|
|
1122
|
+
this.maxSize = size;
|
|
1123
|
+
}
|
|
1124
|
+
get(key) {
|
|
1125
|
+
const value = super.get(key);
|
|
1126
|
+
if (super.has(key) && value !== void 0) {
|
|
1127
|
+
this.delete(key);
|
|
1128
|
+
super.set(key, value);
|
|
1129
|
+
}
|
|
1130
|
+
return value;
|
|
1131
|
+
}
|
|
1132
|
+
set(key, value) {
|
|
1133
|
+
super.set(key, value);
|
|
1134
|
+
if (this.maxSize && this.size > this.maxSize) {
|
|
1135
|
+
const firstKey = this.keys().next().value;
|
|
1136
|
+
if (firstKey) this.delete(firstKey);
|
|
1137
|
+
}
|
|
1138
|
+
return this;
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
const checksum$1 = { checksum: /* @__PURE__ */ new LruMap(8192) }.checksum;
|
|
1142
|
+
//#endregion
|
|
1143
|
+
//#region node_modules/.pnpm/ox@0.14.7_typescript@5.9.3_zod@4.3.6/node_modules/ox/_esm/core/Hash.js
|
|
1144
|
+
/**
|
|
1145
|
+
* Calculates the [Keccak256](https://en.wikipedia.org/wiki/SHA-3) hash of a {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value.
|
|
1146
|
+
*
|
|
1147
|
+
* This function is a re-export of `keccak_256` from [`@noble/hashes`](https://github.com/paulmillr/noble-hashes), an audited & minimal JS hashing library.
|
|
1148
|
+
*
|
|
1149
|
+
* @example
|
|
1150
|
+
* ```ts twoslash
|
|
1151
|
+
* import { Hash } from 'ox'
|
|
1152
|
+
*
|
|
1153
|
+
* Hash.keccak256('0xdeadbeef')
|
|
1154
|
+
* // @log: '0xd4fd4e189132273036449fc9e11198c739161b4c0116a9a2dccdfa1c492006f1'
|
|
1155
|
+
* ```
|
|
1156
|
+
*
|
|
1157
|
+
* @example
|
|
1158
|
+
* ### Calculate Hash of a String
|
|
1159
|
+
*
|
|
1160
|
+
* ```ts twoslash
|
|
1161
|
+
* import { Hash, Hex } from 'ox'
|
|
1162
|
+
*
|
|
1163
|
+
* Hash.keccak256(Hex.fromString('hello world'))
|
|
1164
|
+
* // @log: '0x3ea2f1d0abf3fc66cf29eebb70cbd4e7fe762ef8a09bcc06c8edf641230afec0'
|
|
1165
|
+
* ```
|
|
1166
|
+
*
|
|
1167
|
+
* @example
|
|
1168
|
+
* ### Configure Return Type
|
|
1169
|
+
*
|
|
1170
|
+
* ```ts twoslash
|
|
1171
|
+
* import { Hash } from 'ox'
|
|
1172
|
+
*
|
|
1173
|
+
* Hash.keccak256('0xdeadbeef', { as: 'Bytes' })
|
|
1174
|
+
* // @log: Uint8Array [...]
|
|
1175
|
+
* ```
|
|
1176
|
+
*
|
|
1177
|
+
* @param value - {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value.
|
|
1178
|
+
* @param options - Options.
|
|
1179
|
+
* @returns Keccak256 hash.
|
|
1180
|
+
*/
|
|
1181
|
+
function keccak256(value, options = {}) {
|
|
1182
|
+
const { as = typeof value === "string" ? "Hex" : "Bytes" } = options;
|
|
1183
|
+
const bytes = keccak_256(from$5(value));
|
|
1184
|
+
if (as === "Bytes") return bytes;
|
|
1185
|
+
return fromBytes$2(bytes);
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Calculates the [Sha256](https://en.wikipedia.org/wiki/SHA-256) hash of a {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value.
|
|
1189
|
+
*
|
|
1190
|
+
* This function is a re-export of `sha256` from [`@noble/hashes`](https://github.com/paulmillr/noble-hashes), an audited & minimal JS hashing library.
|
|
1191
|
+
*
|
|
1192
|
+
* @example
|
|
1193
|
+
* ```ts twoslash
|
|
1194
|
+
* import { Hash } from 'ox'
|
|
1195
|
+
*
|
|
1196
|
+
* Hash.sha256('0xdeadbeef')
|
|
1197
|
+
* // '0x5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953'
|
|
1198
|
+
* ```
|
|
1199
|
+
*
|
|
1200
|
+
* @param value - {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value.
|
|
1201
|
+
* @param options - Options.
|
|
1202
|
+
* @returns Sha256 hash.
|
|
1203
|
+
*/
|
|
1204
|
+
function sha256(value, options = {}) {
|
|
1205
|
+
const { as = typeof value === "string" ? "Hex" : "Bytes" } = options;
|
|
1206
|
+
const bytes = sha256$1(from$5(value));
|
|
1207
|
+
if (as === "Bytes") return bytes;
|
|
1208
|
+
return fromBytes$2(bytes);
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Checks if a string is a valid hash value.
|
|
1212
|
+
*
|
|
1213
|
+
* @example
|
|
1214
|
+
* ```ts twoslash
|
|
1215
|
+
* import { Hash } from 'ox'
|
|
1216
|
+
*
|
|
1217
|
+
* Hash.validate('0x')
|
|
1218
|
+
* // @log: false
|
|
1219
|
+
*
|
|
1220
|
+
* Hash.validate('0x3ea2f1d0abf3fc66cf29eebb70cbd4e7fe762ef8a09bcc06c8edf641230afec0')
|
|
1221
|
+
* // @log: true
|
|
1222
|
+
* ```
|
|
1223
|
+
*
|
|
1224
|
+
* @param value - Value to check.
|
|
1225
|
+
* @returns Whether the value is a valid hash.
|
|
1226
|
+
*/
|
|
1227
|
+
function validate$1(value) {
|
|
1228
|
+
return validate$2(value) && size(value) === 32;
|
|
1229
|
+
}
|
|
1230
|
+
//#endregion
|
|
1231
|
+
//#region node_modules/.pnpm/ox@0.14.7_typescript@5.9.3_zod@4.3.6/node_modules/ox/_esm/core/PublicKey.js
|
|
1232
|
+
/**
|
|
1233
|
+
* Asserts that a {@link ox#PublicKey.PublicKey} is valid.
|
|
1234
|
+
*
|
|
1235
|
+
* @example
|
|
1236
|
+
* ```ts twoslash
|
|
1237
|
+
* import { PublicKey } from 'ox'
|
|
1238
|
+
*
|
|
1239
|
+
* PublicKey.assert({
|
|
1240
|
+
* prefix: 4,
|
|
1241
|
+
* y: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
|
|
1242
|
+
* })
|
|
1243
|
+
* // @error: PublicKey.InvalidError: Value \`{"y":"1"}\` is not a valid public key.
|
|
1244
|
+
* // @error: Public key must contain:
|
|
1245
|
+
* // @error: - an `x` and `prefix` value (compressed)
|
|
1246
|
+
* // @error: - an `x`, `y`, and `prefix` value (uncompressed)
|
|
1247
|
+
* ```
|
|
1248
|
+
*
|
|
1249
|
+
* @param publicKey - The public key object to assert.
|
|
1250
|
+
*/
|
|
1251
|
+
function assert$2(publicKey, options = {}) {
|
|
1252
|
+
const { compressed } = options;
|
|
1253
|
+
const { prefix, x, y } = publicKey;
|
|
1254
|
+
if (compressed === false || typeof x === "bigint" && typeof y === "bigint") {
|
|
1255
|
+
if (prefix !== 4) throw new InvalidPrefixError({
|
|
1256
|
+
prefix,
|
|
1257
|
+
cause: new InvalidUncompressedPrefixError()
|
|
1258
|
+
});
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
if (compressed === true || typeof x === "bigint" && typeof y === "undefined") {
|
|
1262
|
+
if (prefix !== 3 && prefix !== 2) throw new InvalidPrefixError({
|
|
1263
|
+
prefix,
|
|
1264
|
+
cause: new InvalidCompressedPrefixError()
|
|
1265
|
+
});
|
|
1266
|
+
return;
|
|
1267
|
+
}
|
|
1268
|
+
throw new InvalidError({ publicKey });
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Instantiates a typed {@link ox#PublicKey.PublicKey} object from a {@link ox#PublicKey.PublicKey}, {@link ox#Bytes.Bytes}, or {@link ox#Hex.Hex}.
|
|
1272
|
+
*
|
|
1273
|
+
* @example
|
|
1274
|
+
* ```ts twoslash
|
|
1275
|
+
* import { PublicKey } from 'ox'
|
|
1276
|
+
*
|
|
1277
|
+
* const publicKey = PublicKey.from({
|
|
1278
|
+
* prefix: 4,
|
|
1279
|
+
* x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
|
|
1280
|
+
* y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
|
|
1281
|
+
* })
|
|
1282
|
+
* // @log: {
|
|
1283
|
+
* // @log: prefix: 4,
|
|
1284
|
+
* // @log: x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
|
|
1285
|
+
* // @log: y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
|
|
1286
|
+
* // @log: }
|
|
1287
|
+
* ```
|
|
1288
|
+
*
|
|
1289
|
+
* @example
|
|
1290
|
+
* ### From Serialized
|
|
1291
|
+
*
|
|
1292
|
+
* ```ts twoslash
|
|
1293
|
+
* import { PublicKey } from 'ox'
|
|
1294
|
+
*
|
|
1295
|
+
* const publicKey = PublicKey.from('0x048318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5')
|
|
1296
|
+
* // @log: {
|
|
1297
|
+
* // @log: prefix: 4,
|
|
1298
|
+
* // @log: x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
|
|
1299
|
+
* // @log: y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
|
|
1300
|
+
* // @log: }
|
|
1301
|
+
* ```
|
|
1302
|
+
*
|
|
1303
|
+
* @param value - The public key value to instantiate.
|
|
1304
|
+
* @returns The instantiated {@link ox#PublicKey.PublicKey}.
|
|
1305
|
+
*/
|
|
1306
|
+
function from$4(value) {
|
|
1307
|
+
const publicKey = (() => {
|
|
1308
|
+
if (validate$2(value)) return fromHex$2(value);
|
|
1309
|
+
if (validate$3(value)) return fromBytes$1(value);
|
|
1310
|
+
const { prefix, x, y } = value;
|
|
1311
|
+
if (typeof x === "bigint" && typeof y === "bigint") return {
|
|
1312
|
+
prefix: prefix ?? 4,
|
|
1313
|
+
x,
|
|
1314
|
+
y
|
|
1315
|
+
};
|
|
1316
|
+
return {
|
|
1317
|
+
prefix,
|
|
1318
|
+
x
|
|
1319
|
+
};
|
|
1320
|
+
})();
|
|
1321
|
+
assert$2(publicKey);
|
|
1322
|
+
return publicKey;
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Deserializes a {@link ox#PublicKey.PublicKey} from a {@link ox#Bytes.Bytes} value.
|
|
1326
|
+
*
|
|
1327
|
+
* @example
|
|
1328
|
+
* ```ts twoslash
|
|
1329
|
+
* // @noErrors
|
|
1330
|
+
* import { PublicKey } from 'ox'
|
|
1331
|
+
*
|
|
1332
|
+
* const publicKey = PublicKey.fromBytes(new Uint8Array([128, 3, 131, ...]))
|
|
1333
|
+
* // @log: {
|
|
1334
|
+
* // @log: prefix: 4,
|
|
1335
|
+
* // @log: x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
|
|
1336
|
+
* // @log: y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
|
|
1337
|
+
* // @log: }
|
|
1338
|
+
* ```
|
|
1339
|
+
*
|
|
1340
|
+
* @param publicKey - The serialized public key.
|
|
1341
|
+
* @returns The deserialized public key.
|
|
1342
|
+
*/
|
|
1343
|
+
function fromBytes$1(publicKey) {
|
|
1344
|
+
return fromHex$2(fromBytes$2(publicKey));
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Deserializes a {@link ox#PublicKey.PublicKey} from a {@link ox#Hex.Hex} value.
|
|
1348
|
+
*
|
|
1349
|
+
* @example
|
|
1350
|
+
* ```ts twoslash
|
|
1351
|
+
* import { PublicKey } from 'ox'
|
|
1352
|
+
*
|
|
1353
|
+
* const publicKey = PublicKey.fromHex('0x8318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5')
|
|
1354
|
+
* // @log: {
|
|
1355
|
+
* // @log: prefix: 4,
|
|
1356
|
+
* // @log: x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
|
|
1357
|
+
* // @log: y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
|
|
1358
|
+
* // @log: }
|
|
1359
|
+
* ```
|
|
1360
|
+
*
|
|
1361
|
+
* @example
|
|
1362
|
+
* ### Deserializing a Compressed Public Key
|
|
1363
|
+
*
|
|
1364
|
+
* ```ts twoslash
|
|
1365
|
+
* import { PublicKey } from 'ox'
|
|
1366
|
+
*
|
|
1367
|
+
* const publicKey = PublicKey.fromHex('0x038318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed75')
|
|
1368
|
+
* // @log: {
|
|
1369
|
+
* // @log: prefix: 3,
|
|
1370
|
+
* // @log: x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
|
|
1371
|
+
* // @log: }
|
|
1372
|
+
* ```
|
|
1373
|
+
*
|
|
1374
|
+
* @param publicKey - The serialized public key.
|
|
1375
|
+
* @returns The deserialized public key.
|
|
1376
|
+
*/
|
|
1377
|
+
function fromHex$2(publicKey) {
|
|
1378
|
+
if (publicKey.length !== 132 && publicKey.length !== 130 && publicKey.length !== 68) throw new InvalidSerializedSizeError$1({ publicKey });
|
|
1379
|
+
if (publicKey.length === 130) return {
|
|
1380
|
+
prefix: 4,
|
|
1381
|
+
x: BigInt(slice(publicKey, 0, 32)),
|
|
1382
|
+
y: BigInt(slice(publicKey, 32, 64))
|
|
1383
|
+
};
|
|
1384
|
+
if (publicKey.length === 132) return {
|
|
1385
|
+
prefix: Number(slice(publicKey, 0, 1)),
|
|
1386
|
+
x: BigInt(slice(publicKey, 1, 33)),
|
|
1387
|
+
y: BigInt(slice(publicKey, 33, 65))
|
|
1388
|
+
};
|
|
1389
|
+
return {
|
|
1390
|
+
prefix: Number(slice(publicKey, 0, 1)),
|
|
1391
|
+
x: BigInt(slice(publicKey, 1, 33))
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Serializes a {@link ox#PublicKey.PublicKey} to {@link ox#Bytes.Bytes}.
|
|
1396
|
+
*
|
|
1397
|
+
* @example
|
|
1398
|
+
* ```ts twoslash
|
|
1399
|
+
* import { PublicKey } from 'ox'
|
|
1400
|
+
*
|
|
1401
|
+
* const publicKey = PublicKey.from({
|
|
1402
|
+
* prefix: 4,
|
|
1403
|
+
* x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
|
|
1404
|
+
* y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
|
|
1405
|
+
* })
|
|
1406
|
+
*
|
|
1407
|
+
* const bytes = PublicKey.toBytes(publicKey) // [!code focus]
|
|
1408
|
+
* // @log: Uint8Array [128, 3, 131, ...]
|
|
1409
|
+
* ```
|
|
1410
|
+
*
|
|
1411
|
+
* @param publicKey - The public key to serialize.
|
|
1412
|
+
* @returns The serialized public key.
|
|
1413
|
+
*/
|
|
1414
|
+
function toBytes(publicKey, options = {}) {
|
|
1415
|
+
return fromHex$3(toHex$2(publicKey, options));
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Serializes a {@link ox#PublicKey.PublicKey} to {@link ox#Hex.Hex}.
|
|
1419
|
+
*
|
|
1420
|
+
* @example
|
|
1421
|
+
* ```ts twoslash
|
|
1422
|
+
* import { PublicKey } from 'ox'
|
|
1423
|
+
*
|
|
1424
|
+
* const publicKey = PublicKey.from({
|
|
1425
|
+
* prefix: 4,
|
|
1426
|
+
* x: 59295962801117472859457908919941473389380284132224861839820747729565200149877n,
|
|
1427
|
+
* y: 24099691209996290925259367678540227198235484593389470330605641003500238088869n,
|
|
1428
|
+
* })
|
|
1429
|
+
*
|
|
1430
|
+
* const hex = PublicKey.toHex(publicKey) // [!code focus]
|
|
1431
|
+
* // @log: '0x048318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5'
|
|
1432
|
+
* ```
|
|
1433
|
+
*
|
|
1434
|
+
* @param publicKey - The public key to serialize.
|
|
1435
|
+
* @returns The serialized public key.
|
|
1436
|
+
*/
|
|
1437
|
+
function toHex$2(publicKey, options = {}) {
|
|
1438
|
+
assert$2(publicKey);
|
|
1439
|
+
const { prefix, x, y } = publicKey;
|
|
1440
|
+
const { includePrefix = true } = options;
|
|
1441
|
+
return concat(includePrefix ? fromNumber(prefix, { size: 1 }) : "0x", fromNumber(x, { size: 32 }), typeof y === "bigint" ? fromNumber(y, { size: 32 }) : "0x");
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Thrown when a public key is invalid.
|
|
1445
|
+
*
|
|
1446
|
+
* @example
|
|
1447
|
+
* ```ts twoslash
|
|
1448
|
+
* import { PublicKey } from 'ox'
|
|
1449
|
+
*
|
|
1450
|
+
* PublicKey.assert({ y: 1n })
|
|
1451
|
+
* // @error: PublicKey.InvalidError: Value `{"y":1n}` is not a valid public key.
|
|
1452
|
+
* // @error: Public key must contain:
|
|
1453
|
+
* // @error: - an `x` and `prefix` value (compressed)
|
|
1454
|
+
* // @error: - an `x`, `y`, and `prefix` value (uncompressed)
|
|
1455
|
+
* ```
|
|
1456
|
+
*/
|
|
1457
|
+
var InvalidError = class extends BaseError {
|
|
1458
|
+
constructor({ publicKey }) {
|
|
1459
|
+
super(`Value \`${stringify(publicKey)}\` is not a valid public key.`, { metaMessages: [
|
|
1460
|
+
"Public key must contain:",
|
|
1461
|
+
"- an `x` and `prefix` value (compressed)",
|
|
1462
|
+
"- an `x`, `y`, and `prefix` value (uncompressed)"
|
|
1463
|
+
] });
|
|
1464
|
+
Object.defineProperty(this, "name", {
|
|
1465
|
+
enumerable: true,
|
|
1466
|
+
configurable: true,
|
|
1467
|
+
writable: true,
|
|
1468
|
+
value: "PublicKey.InvalidError"
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
/** Thrown when a public key has an invalid prefix. */
|
|
1473
|
+
var InvalidPrefixError = class extends BaseError {
|
|
1474
|
+
constructor({ prefix, cause }) {
|
|
1475
|
+
super(`Prefix "${prefix}" is invalid.`, { cause });
|
|
1476
|
+
Object.defineProperty(this, "name", {
|
|
1477
|
+
enumerable: true,
|
|
1478
|
+
configurable: true,
|
|
1479
|
+
writable: true,
|
|
1480
|
+
value: "PublicKey.InvalidPrefixError"
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
/** Thrown when the public key has an invalid prefix for a compressed public key. */
|
|
1485
|
+
var InvalidCompressedPrefixError = class extends BaseError {
|
|
1486
|
+
constructor() {
|
|
1487
|
+
super("Prefix must be 2 or 3 for compressed public keys.");
|
|
1488
|
+
Object.defineProperty(this, "name", {
|
|
1489
|
+
enumerable: true,
|
|
1490
|
+
configurable: true,
|
|
1491
|
+
writable: true,
|
|
1492
|
+
value: "PublicKey.InvalidCompressedPrefixError"
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
/** Thrown when the public key has an invalid prefix for an uncompressed public key. */
|
|
1497
|
+
var InvalidUncompressedPrefixError = class extends BaseError {
|
|
1498
|
+
constructor() {
|
|
1499
|
+
super("Prefix must be 4 for uncompressed public keys.");
|
|
1500
|
+
Object.defineProperty(this, "name", {
|
|
1501
|
+
enumerable: true,
|
|
1502
|
+
configurable: true,
|
|
1503
|
+
writable: true,
|
|
1504
|
+
value: "PublicKey.InvalidUncompressedPrefixError"
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
};
|
|
1508
|
+
/** Thrown when the public key has an invalid serialized size. */
|
|
1509
|
+
var InvalidSerializedSizeError$1 = class extends BaseError {
|
|
1510
|
+
constructor({ publicKey }) {
|
|
1511
|
+
super(`Value \`${publicKey}\` is an invalid public key size.`, { metaMessages: ["Expected: 33 bytes (compressed + prefix), 64 bytes (uncompressed) or 65 bytes (uncompressed + prefix).", `Received ${size(from$6(publicKey))} bytes.`] });
|
|
1512
|
+
Object.defineProperty(this, "name", {
|
|
1513
|
+
enumerable: true,
|
|
1514
|
+
configurable: true,
|
|
1515
|
+
writable: true,
|
|
1516
|
+
value: "PublicKey.InvalidSerializedSizeError"
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
};
|
|
1520
|
+
//#endregion
|
|
1521
|
+
//#region node_modules/.pnpm/ox@0.14.7_typescript@5.9.3_zod@4.3.6/node_modules/ox/_esm/core/Address.js
|
|
1522
|
+
const addressRegex = /^0x[a-fA-F0-9]{40}$/;
|
|
1523
|
+
/**
|
|
1524
|
+
* Asserts that the given value is a valid {@link ox#Address.Address}.
|
|
1525
|
+
*
|
|
1526
|
+
* @example
|
|
1527
|
+
* ```ts twoslash
|
|
1528
|
+
* import { Address } from 'ox'
|
|
1529
|
+
*
|
|
1530
|
+
* Address.assert('0xA0Cf798816D4b9b9866b5330EEa46a18382f251e')
|
|
1531
|
+
* ```
|
|
1532
|
+
*
|
|
1533
|
+
* @example
|
|
1534
|
+
* ```ts twoslash
|
|
1535
|
+
* import { Address } from 'ox'
|
|
1536
|
+
*
|
|
1537
|
+
* Address.assert('0xdeadbeef')
|
|
1538
|
+
* // @error: InvalidAddressError: Address "0xdeadbeef" is invalid.
|
|
1539
|
+
* ```
|
|
1540
|
+
*
|
|
1541
|
+
* @param value - Value to assert if it is a valid address.
|
|
1542
|
+
* @param options - Assertion options.
|
|
1543
|
+
*/
|
|
1544
|
+
function assert$1(value, options = {}) {
|
|
1545
|
+
const { strict = true } = options;
|
|
1546
|
+
if (!addressRegex.test(value)) throw new InvalidAddressError({
|
|
1547
|
+
address: value,
|
|
1548
|
+
cause: new InvalidInputError()
|
|
1549
|
+
});
|
|
1550
|
+
if (strict) {
|
|
1551
|
+
if (value.toLowerCase() === value) return;
|
|
1552
|
+
if (checksum(value) !== value) throw new InvalidAddressError({
|
|
1553
|
+
address: value,
|
|
1554
|
+
cause: new InvalidChecksumError()
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
/**
|
|
1559
|
+
* Computes the checksum address for the given {@link ox#Address.Address}.
|
|
1560
|
+
*
|
|
1561
|
+
* @example
|
|
1562
|
+
* ```ts twoslash
|
|
1563
|
+
* import { Address } from 'ox'
|
|
1564
|
+
*
|
|
1565
|
+
* Address.checksum('0xa0cf798816d4b9b9866b5330eea46a18382f251e')
|
|
1566
|
+
* // @log: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'
|
|
1567
|
+
* ```
|
|
1568
|
+
*
|
|
1569
|
+
* @param address - The address to compute the checksum for.
|
|
1570
|
+
* @returns The checksummed address.
|
|
1571
|
+
*/
|
|
1572
|
+
function checksum(address) {
|
|
1573
|
+
if (checksum$1.has(address)) return checksum$1.get(address);
|
|
1574
|
+
assert$1(address, { strict: false });
|
|
1575
|
+
const hexAddress = address.substring(2).toLowerCase();
|
|
1576
|
+
const hash = keccak256(fromString(hexAddress), { as: "Bytes" });
|
|
1577
|
+
const characters = hexAddress.split("");
|
|
1578
|
+
for (let i = 0; i < 40; i += 2) {
|
|
1579
|
+
if (hash[i >> 1] >> 4 >= 8 && characters[i]) characters[i] = characters[i].toUpperCase();
|
|
1580
|
+
if ((hash[i >> 1] & 15) >= 8 && characters[i + 1]) characters[i + 1] = characters[i + 1].toUpperCase();
|
|
1581
|
+
}
|
|
1582
|
+
const result = `0x${characters.join("")}`;
|
|
1583
|
+
checksum$1.set(address, result);
|
|
1584
|
+
return result;
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Converts a stringified address to a typed (optionally checksummed) {@link ox#Address.Address}.
|
|
1588
|
+
*
|
|
1589
|
+
* @example
|
|
1590
|
+
* ```ts twoslash
|
|
1591
|
+
* import { Address } from 'ox'
|
|
1592
|
+
*
|
|
1593
|
+
* Address.from('0xa0cf798816d4b9b9866b5330eea46a18382f251e')
|
|
1594
|
+
* // @log: '0xa0cf798816d4b9b9866b5330eea46a18382f251e'
|
|
1595
|
+
* ```
|
|
1596
|
+
*
|
|
1597
|
+
* @example
|
|
1598
|
+
* ```ts twoslash
|
|
1599
|
+
* import { Address } from 'ox'
|
|
1600
|
+
*
|
|
1601
|
+
* Address.from('0xa0cf798816d4b9b9866b5330eea46a18382f251e', {
|
|
1602
|
+
* checksum: true
|
|
1603
|
+
* })
|
|
1604
|
+
* // @log: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'
|
|
1605
|
+
* ```
|
|
1606
|
+
*
|
|
1607
|
+
* @example
|
|
1608
|
+
* ```ts twoslash
|
|
1609
|
+
* import { Address } from 'ox'
|
|
1610
|
+
*
|
|
1611
|
+
* Address.from('hello')
|
|
1612
|
+
* // @error: InvalidAddressError: Address "0xa" is invalid.
|
|
1613
|
+
* ```
|
|
1614
|
+
*
|
|
1615
|
+
* @param address - An address string to convert to a typed Address.
|
|
1616
|
+
* @param options - Conversion options.
|
|
1617
|
+
* @returns The typed Address.
|
|
1618
|
+
*/
|
|
1619
|
+
function from$3(address, options = {}) {
|
|
1620
|
+
const { checksum: checksumVal = false } = options;
|
|
1621
|
+
assert$1(address);
|
|
1622
|
+
if (checksumVal) return checksum(address);
|
|
1623
|
+
return address;
|
|
1624
|
+
}
|
|
1625
|
+
/**
|
|
1626
|
+
* Converts an ECDSA public key to an {@link ox#Address.Address}.
|
|
1627
|
+
*
|
|
1628
|
+
* @example
|
|
1629
|
+
* ```ts twoslash
|
|
1630
|
+
* import { Address, PublicKey } from 'ox'
|
|
1631
|
+
*
|
|
1632
|
+
* const publicKey = PublicKey.from(
|
|
1633
|
+
* '0x048318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5',
|
|
1634
|
+
* )
|
|
1635
|
+
* const address = Address.fromPublicKey(publicKey)
|
|
1636
|
+
* // @log: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
|
|
1637
|
+
* ```
|
|
1638
|
+
*
|
|
1639
|
+
* @param publicKey - The ECDSA public key to convert to an {@link ox#Address.Address}.
|
|
1640
|
+
* @param options - Conversion options.
|
|
1641
|
+
* @returns The {@link ox#Address.Address} corresponding to the public key.
|
|
1642
|
+
*/
|
|
1643
|
+
function fromPublicKey(publicKey, options = {}) {
|
|
1644
|
+
return from$3(`0x${keccak256(`0x${toHex$2(publicKey).slice(4)}`).substring(26)}`, options);
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Checks if two {@link ox#Address.Address} are equal.
|
|
1648
|
+
*
|
|
1649
|
+
* @example
|
|
1650
|
+
* ```ts twoslash
|
|
1651
|
+
* import { Address } from 'ox'
|
|
1652
|
+
*
|
|
1653
|
+
* Address.isEqual(
|
|
1654
|
+
* '0xa0cf798816d4b9b9866b5330eea46a18382f251e',
|
|
1655
|
+
* '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'
|
|
1656
|
+
* )
|
|
1657
|
+
* // @log: true
|
|
1658
|
+
* ```
|
|
1659
|
+
*
|
|
1660
|
+
* @example
|
|
1661
|
+
* ```ts twoslash
|
|
1662
|
+
* import { Address } from 'ox'
|
|
1663
|
+
*
|
|
1664
|
+
* Address.isEqual(
|
|
1665
|
+
* '0xa0cf798816d4b9b9866b5330eea46a18382f251e',
|
|
1666
|
+
* '0xA0Cf798816D4b9b9866b5330EEa46a18382f251f'
|
|
1667
|
+
* )
|
|
1668
|
+
* // @log: false
|
|
1669
|
+
* ```
|
|
1670
|
+
*
|
|
1671
|
+
* @param addressA - The first address to compare.
|
|
1672
|
+
* @param addressB - The second address to compare.
|
|
1673
|
+
* @returns Whether the addresses are equal.
|
|
1674
|
+
*/
|
|
1675
|
+
function isEqual(addressA, addressB) {
|
|
1676
|
+
assert$1(addressA, { strict: false });
|
|
1677
|
+
assert$1(addressB, { strict: false });
|
|
1678
|
+
return addressA.toLowerCase() === addressB.toLowerCase();
|
|
1679
|
+
}
|
|
1680
|
+
/**
|
|
1681
|
+
* Checks if the given address is a valid {@link ox#Address.Address}.
|
|
1682
|
+
*
|
|
1683
|
+
* @example
|
|
1684
|
+
* ```ts twoslash
|
|
1685
|
+
* import { Address } from 'ox'
|
|
1686
|
+
*
|
|
1687
|
+
* Address.validate('0xA0Cf798816D4b9b9866b5330EEa46a18382f251e')
|
|
1688
|
+
* // @log: true
|
|
1689
|
+
* ```
|
|
1690
|
+
*
|
|
1691
|
+
* @example
|
|
1692
|
+
* ```ts twoslash
|
|
1693
|
+
* import { Address } from 'ox'
|
|
1694
|
+
*
|
|
1695
|
+
* Address.validate('0xdeadbeef')
|
|
1696
|
+
* // @log: false
|
|
1697
|
+
* ```
|
|
1698
|
+
*
|
|
1699
|
+
* @param address - Value to check if it is a valid address.
|
|
1700
|
+
* @param options - Check options.
|
|
1701
|
+
* @returns Whether the address is a valid address.
|
|
1702
|
+
*/
|
|
1703
|
+
function validate(address, options = {}) {
|
|
1704
|
+
const { strict = true } = options ?? {};
|
|
1705
|
+
try {
|
|
1706
|
+
assert$1(address, { strict });
|
|
1707
|
+
return true;
|
|
1708
|
+
} catch {
|
|
1709
|
+
return false;
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
/**
|
|
1713
|
+
* Thrown when an address is invalid.
|
|
1714
|
+
*
|
|
1715
|
+
* @example
|
|
1716
|
+
* ```ts twoslash
|
|
1717
|
+
* import { Address } from 'ox'
|
|
1718
|
+
*
|
|
1719
|
+
* Address.from('0x123')
|
|
1720
|
+
* // @error: Address.InvalidAddressError: Address `0x123` is invalid.
|
|
1721
|
+
* ```
|
|
1722
|
+
*/
|
|
1723
|
+
var InvalidAddressError = class extends BaseError {
|
|
1724
|
+
constructor({ address, cause }) {
|
|
1725
|
+
super(`Address "${address}" is invalid.`, { cause });
|
|
1726
|
+
Object.defineProperty(this, "name", {
|
|
1727
|
+
enumerable: true,
|
|
1728
|
+
configurable: true,
|
|
1729
|
+
writable: true,
|
|
1730
|
+
value: "Address.InvalidAddressError"
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
};
|
|
1734
|
+
/** Thrown when an address is not a 20 byte (40 hexadecimal character) value. */
|
|
1735
|
+
var InvalidInputError = class extends BaseError {
|
|
1736
|
+
constructor() {
|
|
1737
|
+
super("Address is not a 20 byte (40 hexadecimal character) value.");
|
|
1738
|
+
Object.defineProperty(this, "name", {
|
|
1739
|
+
enumerable: true,
|
|
1740
|
+
configurable: true,
|
|
1741
|
+
writable: true,
|
|
1742
|
+
value: "Address.InvalidInputError"
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
/** Thrown when an address does not match its checksum counterpart. */
|
|
1747
|
+
var InvalidChecksumError = class extends BaseError {
|
|
1748
|
+
constructor() {
|
|
1749
|
+
super("Address does not match its checksum counterpart.");
|
|
1750
|
+
Object.defineProperty(this, "name", {
|
|
1751
|
+
enumerable: true,
|
|
1752
|
+
configurable: true,
|
|
1753
|
+
writable: true,
|
|
1754
|
+
value: "Address.InvalidChecksumError"
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
};
|
|
1758
|
+
//#endregion
|
|
1759
|
+
//#region node_modules/.pnpm/ox@0.14.7_typescript@5.9.3_zod@4.3.6/node_modules/ox/_esm/core/Solidity.js
|
|
1760
|
+
const arrayRegex = /^(.*)\[([0-9]*)\]$/;
|
|
1761
|
+
const bytesRegex = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/;
|
|
1762
|
+
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)?$/;
|
|
1763
|
+
2n ** (8n - 1n) - 1n;
|
|
1764
|
+
2n ** (16n - 1n) - 1n;
|
|
1765
|
+
2n ** (24n - 1n) - 1n;
|
|
1766
|
+
2n ** (32n - 1n) - 1n;
|
|
1767
|
+
2n ** (40n - 1n) - 1n;
|
|
1768
|
+
2n ** (48n - 1n) - 1n;
|
|
1769
|
+
2n ** (56n - 1n) - 1n;
|
|
1770
|
+
2n ** (64n - 1n) - 1n;
|
|
1771
|
+
2n ** (72n - 1n) - 1n;
|
|
1772
|
+
2n ** (80n - 1n) - 1n;
|
|
1773
|
+
2n ** (88n - 1n) - 1n;
|
|
1774
|
+
2n ** (96n - 1n) - 1n;
|
|
1775
|
+
2n ** (104n - 1n) - 1n;
|
|
1776
|
+
2n ** (112n - 1n) - 1n;
|
|
1777
|
+
2n ** (120n - 1n) - 1n;
|
|
1778
|
+
2n ** (128n - 1n) - 1n;
|
|
1779
|
+
2n ** (136n - 1n) - 1n;
|
|
1780
|
+
2n ** (144n - 1n) - 1n;
|
|
1781
|
+
2n ** (152n - 1n) - 1n;
|
|
1782
|
+
2n ** (160n - 1n) - 1n;
|
|
1783
|
+
2n ** (168n - 1n) - 1n;
|
|
1784
|
+
2n ** (176n - 1n) - 1n;
|
|
1785
|
+
2n ** (184n - 1n) - 1n;
|
|
1786
|
+
2n ** (192n - 1n) - 1n;
|
|
1787
|
+
2n ** (200n - 1n) - 1n;
|
|
1788
|
+
2n ** (208n - 1n) - 1n;
|
|
1789
|
+
2n ** (216n - 1n) - 1n;
|
|
1790
|
+
2n ** (224n - 1n) - 1n;
|
|
1791
|
+
2n ** (232n - 1n) - 1n;
|
|
1792
|
+
2n ** (240n - 1n) - 1n;
|
|
1793
|
+
2n ** (248n - 1n) - 1n;
|
|
1794
|
+
2n ** (256n - 1n) - 1n;
|
|
1795
|
+
-(2n ** (8n - 1n));
|
|
1796
|
+
-(2n ** (16n - 1n));
|
|
1797
|
+
-(2n ** (24n - 1n));
|
|
1798
|
+
-(2n ** (32n - 1n));
|
|
1799
|
+
-(2n ** (40n - 1n));
|
|
1800
|
+
-(2n ** (48n - 1n));
|
|
1801
|
+
-(2n ** (56n - 1n));
|
|
1802
|
+
-(2n ** (64n - 1n));
|
|
1803
|
+
-(2n ** (72n - 1n));
|
|
1804
|
+
-(2n ** (80n - 1n));
|
|
1805
|
+
-(2n ** (88n - 1n));
|
|
1806
|
+
-(2n ** (96n - 1n));
|
|
1807
|
+
-(2n ** (104n - 1n));
|
|
1808
|
+
-(2n ** (112n - 1n));
|
|
1809
|
+
-(2n ** (120n - 1n));
|
|
1810
|
+
-(2n ** (128n - 1n));
|
|
1811
|
+
-(2n ** (136n - 1n));
|
|
1812
|
+
-(2n ** (144n - 1n));
|
|
1813
|
+
-(2n ** (152n - 1n));
|
|
1814
|
+
-(2n ** (160n - 1n));
|
|
1815
|
+
-(2n ** (168n - 1n));
|
|
1816
|
+
-(2n ** (176n - 1n));
|
|
1817
|
+
-(2n ** (184n - 1n));
|
|
1818
|
+
-(2n ** (192n - 1n));
|
|
1819
|
+
-(2n ** (200n - 1n));
|
|
1820
|
+
-(2n ** (208n - 1n));
|
|
1821
|
+
-(2n ** (216n - 1n));
|
|
1822
|
+
-(2n ** (224n - 1n));
|
|
1823
|
+
-(2n ** (232n - 1n));
|
|
1824
|
+
-(2n ** (240n - 1n));
|
|
1825
|
+
-(2n ** (248n - 1n));
|
|
1826
|
+
-(2n ** (256n - 1n));
|
|
1827
|
+
const maxUint256 = 2n ** 256n - 1n;
|
|
1828
|
+
//#endregion
|
|
1829
|
+
//#region node_modules/.pnpm/ox@0.14.7_typescript@5.9.3_zod@4.3.6/node_modules/ox/_esm/core/internal/abiParameters.js
|
|
1830
|
+
/** @internal */
|
|
1831
|
+
function decodeParameter(cursor, param, options) {
|
|
1832
|
+
const { checksumAddress, staticPosition } = options;
|
|
1833
|
+
const arrayComponents = getArrayComponents(param.type);
|
|
1834
|
+
if (arrayComponents) {
|
|
1835
|
+
const [length, type] = arrayComponents;
|
|
1836
|
+
return decodeArray(cursor, {
|
|
1837
|
+
...param,
|
|
1838
|
+
type
|
|
1839
|
+
}, {
|
|
1840
|
+
checksumAddress,
|
|
1841
|
+
length,
|
|
1842
|
+
staticPosition
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
if (param.type === "tuple") return decodeTuple(cursor, param, {
|
|
1846
|
+
checksumAddress,
|
|
1847
|
+
staticPosition
|
|
1848
|
+
});
|
|
1849
|
+
if (param.type === "address") return decodeAddress(cursor, { checksum: checksumAddress });
|
|
1850
|
+
if (param.type === "bool") return decodeBool(cursor);
|
|
1851
|
+
if (param.type.startsWith("bytes")) return decodeBytes(cursor, param, { staticPosition });
|
|
1852
|
+
if (param.type.startsWith("uint") || param.type.startsWith("int")) return decodeNumber(cursor, param);
|
|
1853
|
+
if (param.type === "string") return decodeString(cursor, { staticPosition });
|
|
1854
|
+
throw new InvalidTypeError(param.type);
|
|
1855
|
+
}
|
|
1856
|
+
const sizeOfLength = 32;
|
|
1857
|
+
const sizeOfOffset = 32;
|
|
1858
|
+
/** @internal */
|
|
1859
|
+
function decodeAddress(cursor, options = {}) {
|
|
1860
|
+
const { checksum: checksum$2 = false } = options;
|
|
1861
|
+
const value = cursor.readBytes(32);
|
|
1862
|
+
const wrap = (address) => checksum$2 ? checksum(address) : address;
|
|
1863
|
+
return [wrap(fromBytes$2(slice$1(value, -20))), 32];
|
|
1864
|
+
}
|
|
1865
|
+
/** @internal */
|
|
1866
|
+
function decodeArray(cursor, param, options) {
|
|
1867
|
+
const { checksumAddress, length, staticPosition } = options;
|
|
1868
|
+
if (!length) {
|
|
1869
|
+
const start = staticPosition + toNumber(cursor.readBytes(sizeOfOffset));
|
|
1870
|
+
const startOfData = start + sizeOfLength;
|
|
1871
|
+
cursor.setPosition(start);
|
|
1872
|
+
const length = toNumber(cursor.readBytes(sizeOfLength));
|
|
1873
|
+
const dynamicChild = hasDynamicChild(param);
|
|
1874
|
+
let consumed = 0;
|
|
1875
|
+
const value = [];
|
|
1876
|
+
for (let i = 0; i < length; ++i) {
|
|
1877
|
+
cursor.setPosition(startOfData + (dynamicChild ? i * 32 : consumed));
|
|
1878
|
+
const [data, consumed_] = decodeParameter(cursor, param, {
|
|
1879
|
+
checksumAddress,
|
|
1880
|
+
staticPosition: startOfData
|
|
1881
|
+
});
|
|
1882
|
+
consumed += consumed_;
|
|
1883
|
+
value.push(data);
|
|
1884
|
+
}
|
|
1885
|
+
cursor.setPosition(staticPosition + 32);
|
|
1886
|
+
return [value, 32];
|
|
1887
|
+
}
|
|
1888
|
+
if (hasDynamicChild(param)) {
|
|
1889
|
+
const start = staticPosition + toNumber(cursor.readBytes(sizeOfOffset));
|
|
1890
|
+
const value = [];
|
|
1891
|
+
for (let i = 0; i < length; ++i) {
|
|
1892
|
+
cursor.setPosition(start + i * 32);
|
|
1893
|
+
const [data] = decodeParameter(cursor, param, {
|
|
1894
|
+
checksumAddress,
|
|
1895
|
+
staticPosition: start
|
|
1896
|
+
});
|
|
1897
|
+
value.push(data);
|
|
1898
|
+
}
|
|
1899
|
+
cursor.setPosition(staticPosition + 32);
|
|
1900
|
+
return [value, 32];
|
|
1901
|
+
}
|
|
1902
|
+
let consumed = 0;
|
|
1903
|
+
const value = [];
|
|
1904
|
+
for (let i = 0; i < length; ++i) {
|
|
1905
|
+
const [data, consumed_] = decodeParameter(cursor, param, {
|
|
1906
|
+
checksumAddress,
|
|
1907
|
+
staticPosition: staticPosition + consumed
|
|
1908
|
+
});
|
|
1909
|
+
consumed += consumed_;
|
|
1910
|
+
value.push(data);
|
|
1911
|
+
}
|
|
1912
|
+
return [value, consumed];
|
|
1913
|
+
}
|
|
1914
|
+
/** @internal */
|
|
1915
|
+
function decodeBool(cursor) {
|
|
1916
|
+
return [toBoolean(cursor.readBytes(32), { size: 32 }), 32];
|
|
1917
|
+
}
|
|
1918
|
+
/** @internal */
|
|
1919
|
+
function decodeBytes(cursor, param, { staticPosition }) {
|
|
1920
|
+
const [_, size] = param.type.split("bytes");
|
|
1921
|
+
if (!size) {
|
|
1922
|
+
const offset = toNumber(cursor.readBytes(32));
|
|
1923
|
+
cursor.setPosition(staticPosition + offset);
|
|
1924
|
+
const length = toNumber(cursor.readBytes(32));
|
|
1925
|
+
if (length === 0) {
|
|
1926
|
+
cursor.setPosition(staticPosition + 32);
|
|
1927
|
+
return ["0x", 32];
|
|
1928
|
+
}
|
|
1929
|
+
const data = cursor.readBytes(length);
|
|
1930
|
+
cursor.setPosition(staticPosition + 32);
|
|
1931
|
+
return [fromBytes$2(data), 32];
|
|
1932
|
+
}
|
|
1933
|
+
return [fromBytes$2(cursor.readBytes(Number.parseInt(size, 10), 32)), 32];
|
|
1934
|
+
}
|
|
1935
|
+
/** @internal */
|
|
1936
|
+
function decodeNumber(cursor, param) {
|
|
1937
|
+
const signed = param.type.startsWith("int");
|
|
1938
|
+
const size = Number.parseInt(param.type.split("int")[1] || "256", 10);
|
|
1939
|
+
const value = cursor.readBytes(32);
|
|
1940
|
+
return [size > 48 ? toBigInt(value, { signed }) : toNumber(value, { signed }), 32];
|
|
1941
|
+
}
|
|
1942
|
+
/** @internal */
|
|
1943
|
+
function decodeTuple(cursor, param, options) {
|
|
1944
|
+
const { checksumAddress, staticPosition } = options;
|
|
1945
|
+
const hasUnnamedChild = param.components.length === 0 || param.components.some(({ name }) => !name);
|
|
1946
|
+
const value = hasUnnamedChild ? [] : {};
|
|
1947
|
+
let consumed = 0;
|
|
1948
|
+
if (hasDynamicChild(param)) {
|
|
1949
|
+
const start = staticPosition + toNumber(cursor.readBytes(sizeOfOffset));
|
|
1950
|
+
for (let i = 0; i < param.components.length; ++i) {
|
|
1951
|
+
const component = param.components[i];
|
|
1952
|
+
cursor.setPosition(start + consumed);
|
|
1953
|
+
const [data, consumed_] = decodeParameter(cursor, component, {
|
|
1954
|
+
checksumAddress,
|
|
1955
|
+
staticPosition: start
|
|
1956
|
+
});
|
|
1957
|
+
consumed += consumed_;
|
|
1958
|
+
value[hasUnnamedChild ? i : component?.name] = data;
|
|
1959
|
+
}
|
|
1960
|
+
cursor.setPosition(staticPosition + 32);
|
|
1961
|
+
return [value, 32];
|
|
1962
|
+
}
|
|
1963
|
+
for (let i = 0; i < param.components.length; ++i) {
|
|
1964
|
+
const component = param.components[i];
|
|
1965
|
+
const [data, consumed_] = decodeParameter(cursor, component, {
|
|
1966
|
+
checksumAddress,
|
|
1967
|
+
staticPosition
|
|
1968
|
+
});
|
|
1969
|
+
value[hasUnnamedChild ? i : component?.name] = data;
|
|
1970
|
+
consumed += consumed_;
|
|
1971
|
+
}
|
|
1972
|
+
return [value, consumed];
|
|
1973
|
+
}
|
|
1974
|
+
/** @internal */
|
|
1975
|
+
function decodeString(cursor, { staticPosition }) {
|
|
1976
|
+
const start = staticPosition + toNumber(cursor.readBytes(32));
|
|
1977
|
+
cursor.setPosition(start);
|
|
1978
|
+
const length = toNumber(cursor.readBytes(32));
|
|
1979
|
+
if (length === 0) {
|
|
1980
|
+
cursor.setPosition(staticPosition + 32);
|
|
1981
|
+
return ["", 32];
|
|
1982
|
+
}
|
|
1983
|
+
const value = toString(trimLeft(cursor.readBytes(length, 32)));
|
|
1984
|
+
cursor.setPosition(staticPosition + 32);
|
|
1985
|
+
return [value, 32];
|
|
1986
|
+
}
|
|
1987
|
+
/** @internal */
|
|
1988
|
+
function prepareParameters({ checksumAddress, parameters, values }) {
|
|
1989
|
+
const preparedParameters = [];
|
|
1990
|
+
for (let i = 0; i < parameters.length; i++) preparedParameters.push(prepareParameter({
|
|
1991
|
+
checksumAddress,
|
|
1992
|
+
parameter: parameters[i],
|
|
1993
|
+
value: values[i]
|
|
1994
|
+
}));
|
|
1995
|
+
return preparedParameters;
|
|
1996
|
+
}
|
|
1997
|
+
/** @internal */
|
|
1998
|
+
function prepareParameter({ checksumAddress = false, parameter: parameter_, value }) {
|
|
1999
|
+
const parameter = parameter_;
|
|
2000
|
+
const arrayComponents = getArrayComponents(parameter.type);
|
|
2001
|
+
if (arrayComponents) {
|
|
2002
|
+
const [length, type] = arrayComponents;
|
|
2003
|
+
return encodeArray(value, {
|
|
2004
|
+
checksumAddress,
|
|
2005
|
+
length,
|
|
2006
|
+
parameter: {
|
|
2007
|
+
...parameter,
|
|
2008
|
+
type
|
|
2009
|
+
}
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
if (parameter.type === "tuple") return encodeTuple(value, {
|
|
2013
|
+
checksumAddress,
|
|
2014
|
+
parameter
|
|
2015
|
+
});
|
|
2016
|
+
if (parameter.type === "address") return encodeAddress(value, { checksum: checksumAddress });
|
|
2017
|
+
if (parameter.type === "bool") return encodeBoolean(value);
|
|
2018
|
+
if (parameter.type.startsWith("uint") || parameter.type.startsWith("int")) {
|
|
2019
|
+
const signed = parameter.type.startsWith("int");
|
|
2020
|
+
const [, , size = "256"] = integerRegex.exec(parameter.type) ?? [];
|
|
2021
|
+
return encodeNumber(value, {
|
|
2022
|
+
signed,
|
|
2023
|
+
size: Number(size)
|
|
2024
|
+
});
|
|
2025
|
+
}
|
|
2026
|
+
if (parameter.type.startsWith("bytes")) return encodeBytes(value, { type: parameter.type });
|
|
2027
|
+
if (parameter.type === "string") return encodeString(value);
|
|
2028
|
+
throw new InvalidTypeError(parameter.type);
|
|
2029
|
+
}
|
|
2030
|
+
/** @internal */
|
|
2031
|
+
function encode$1(preparedParameters) {
|
|
2032
|
+
let staticSize = 0;
|
|
2033
|
+
for (let i = 0; i < preparedParameters.length; i++) {
|
|
2034
|
+
const { dynamic, encoded } = preparedParameters[i];
|
|
2035
|
+
if (dynamic) staticSize += 32;
|
|
2036
|
+
else staticSize += size(encoded);
|
|
2037
|
+
}
|
|
2038
|
+
const staticParameters = [];
|
|
2039
|
+
const dynamicParameters = [];
|
|
2040
|
+
let dynamicSize = 0;
|
|
2041
|
+
for (let i = 0; i < preparedParameters.length; i++) {
|
|
2042
|
+
const { dynamic, encoded } = preparedParameters[i];
|
|
2043
|
+
if (dynamic) {
|
|
2044
|
+
staticParameters.push(fromNumber(staticSize + dynamicSize, { size: 32 }));
|
|
2045
|
+
dynamicParameters.push(encoded);
|
|
2046
|
+
dynamicSize += size(encoded);
|
|
2047
|
+
} else staticParameters.push(encoded);
|
|
2048
|
+
}
|
|
2049
|
+
return concat(...staticParameters, ...dynamicParameters);
|
|
2050
|
+
}
|
|
2051
|
+
/** @internal */
|
|
2052
|
+
function encodeAddress(value, options) {
|
|
2053
|
+
const { checksum = false } = options;
|
|
2054
|
+
assert$1(value, { strict: checksum });
|
|
2055
|
+
return {
|
|
2056
|
+
dynamic: false,
|
|
2057
|
+
encoded: padLeft(value.toLowerCase())
|
|
2058
|
+
};
|
|
2059
|
+
}
|
|
2060
|
+
/** @internal */
|
|
2061
|
+
function encodeArray(value, options) {
|
|
2062
|
+
const { checksumAddress, length, parameter } = options;
|
|
2063
|
+
const dynamic = length === null;
|
|
2064
|
+
if (!Array.isArray(value)) throw new InvalidArrayError(value);
|
|
2065
|
+
if (!dynamic && value.length !== length) throw new ArrayLengthMismatchError({
|
|
2066
|
+
expectedLength: length,
|
|
2067
|
+
givenLength: value.length,
|
|
2068
|
+
type: `${parameter.type}[${length}]`
|
|
2069
|
+
});
|
|
2070
|
+
let dynamicChild = false;
|
|
2071
|
+
const preparedParameters = [];
|
|
2072
|
+
for (let i = 0; i < value.length; i++) {
|
|
2073
|
+
const preparedParam = prepareParameter({
|
|
2074
|
+
checksumAddress,
|
|
2075
|
+
parameter,
|
|
2076
|
+
value: value[i]
|
|
2077
|
+
});
|
|
2078
|
+
if (preparedParam.dynamic) dynamicChild = true;
|
|
2079
|
+
preparedParameters.push(preparedParam);
|
|
2080
|
+
}
|
|
2081
|
+
if (dynamic || dynamicChild) {
|
|
2082
|
+
const data = encode$1(preparedParameters);
|
|
2083
|
+
if (dynamic) {
|
|
2084
|
+
const length = fromNumber(preparedParameters.length, { size: 32 });
|
|
2085
|
+
return {
|
|
2086
|
+
dynamic: true,
|
|
2087
|
+
encoded: preparedParameters.length > 0 ? concat(length, data) : length
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
if (dynamicChild) return {
|
|
2091
|
+
dynamic: true,
|
|
2092
|
+
encoded: data
|
|
2093
|
+
};
|
|
2094
|
+
}
|
|
2095
|
+
return {
|
|
2096
|
+
dynamic: false,
|
|
2097
|
+
encoded: concat(...preparedParameters.map(({ encoded }) => encoded))
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
/** @internal */
|
|
2101
|
+
function encodeBytes(value, { type }) {
|
|
2102
|
+
const [, parametersize] = type.split("bytes");
|
|
2103
|
+
const bytesSize = size(value);
|
|
2104
|
+
if (!parametersize) {
|
|
2105
|
+
let value_ = value;
|
|
2106
|
+
if (bytesSize % 32 !== 0) value_ = padRight(value_, Math.ceil((value.length - 2) / 2 / 32) * 32);
|
|
2107
|
+
return {
|
|
2108
|
+
dynamic: true,
|
|
2109
|
+
encoded: concat(padLeft(fromNumber(bytesSize, { size: 32 })), value_)
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
if (bytesSize !== Number.parseInt(parametersize, 10)) throw new BytesSizeMismatchError({
|
|
2113
|
+
expectedSize: Number.parseInt(parametersize, 10),
|
|
2114
|
+
value
|
|
2115
|
+
});
|
|
2116
|
+
return {
|
|
2117
|
+
dynamic: false,
|
|
2118
|
+
encoded: padRight(value)
|
|
2119
|
+
};
|
|
2120
|
+
}
|
|
2121
|
+
/** @internal */
|
|
2122
|
+
function encodeBoolean(value) {
|
|
2123
|
+
if (typeof value !== "boolean") throw new BaseError(`Invalid boolean value: "${value}" (type: ${typeof value}). Expected: \`true\` or \`false\`.`);
|
|
2124
|
+
return {
|
|
2125
|
+
dynamic: false,
|
|
2126
|
+
encoded: padLeft(fromBoolean(value))
|
|
2127
|
+
};
|
|
2128
|
+
}
|
|
2129
|
+
/** @internal */
|
|
2130
|
+
function encodeNumber(value, { signed, size }) {
|
|
2131
|
+
if (typeof size === "number") {
|
|
2132
|
+
const max = 2n ** (BigInt(size) - (signed ? 1n : 0n)) - 1n;
|
|
2133
|
+
const min = signed ? -max - 1n : 0n;
|
|
2134
|
+
if (value > max || value < min) throw new IntegerOutOfRangeError({
|
|
2135
|
+
max: max.toString(),
|
|
2136
|
+
min: min.toString(),
|
|
2137
|
+
signed,
|
|
2138
|
+
size: size / 8,
|
|
2139
|
+
value: value.toString()
|
|
2140
|
+
});
|
|
2141
|
+
}
|
|
2142
|
+
return {
|
|
2143
|
+
dynamic: false,
|
|
2144
|
+
encoded: fromNumber(value, {
|
|
2145
|
+
size: 32,
|
|
2146
|
+
signed
|
|
2147
|
+
})
|
|
2148
|
+
};
|
|
2149
|
+
}
|
|
2150
|
+
/** @internal */
|
|
2151
|
+
function encodeString(value) {
|
|
2152
|
+
const hexValue = fromString$1(value);
|
|
2153
|
+
const partsLength = Math.ceil(size(hexValue) / 32);
|
|
2154
|
+
const parts = [];
|
|
2155
|
+
for (let i = 0; i < partsLength; i++) parts.push(padRight(slice(hexValue, i * 32, (i + 1) * 32)));
|
|
2156
|
+
return {
|
|
2157
|
+
dynamic: true,
|
|
2158
|
+
encoded: concat(padRight(fromNumber(size(hexValue), { size: 32 })), ...parts)
|
|
2159
|
+
};
|
|
2160
|
+
}
|
|
2161
|
+
/** @internal */
|
|
2162
|
+
function encodeTuple(value, options) {
|
|
2163
|
+
const { checksumAddress, parameter } = options;
|
|
2164
|
+
let dynamic = false;
|
|
2165
|
+
const preparedParameters = [];
|
|
2166
|
+
for (let i = 0; i < parameter.components.length; i++) {
|
|
2167
|
+
const param_ = parameter.components[i];
|
|
2168
|
+
const preparedParam = prepareParameter({
|
|
2169
|
+
checksumAddress,
|
|
2170
|
+
parameter: param_,
|
|
2171
|
+
value: value[Array.isArray(value) ? i : param_.name]
|
|
2172
|
+
});
|
|
2173
|
+
preparedParameters.push(preparedParam);
|
|
2174
|
+
if (preparedParam.dynamic) dynamic = true;
|
|
2175
|
+
}
|
|
2176
|
+
return {
|
|
2177
|
+
dynamic,
|
|
2178
|
+
encoded: dynamic ? encode$1(preparedParameters) : concat(...preparedParameters.map(({ encoded }) => encoded))
|
|
2179
|
+
};
|
|
2180
|
+
}
|
|
2181
|
+
/** @internal */
|
|
2182
|
+
function getArrayComponents(type) {
|
|
2183
|
+
const matches = type.match(/^(.*)\[(\d+)?\]$/);
|
|
2184
|
+
return matches ? [matches[2] ? Number(matches[2]) : null, matches[1]] : void 0;
|
|
2185
|
+
}
|
|
2186
|
+
/** @internal */
|
|
2187
|
+
function hasDynamicChild(param) {
|
|
2188
|
+
const { type } = param;
|
|
2189
|
+
if (type === "string") return true;
|
|
2190
|
+
if (type === "bytes") return true;
|
|
2191
|
+
if (type.endsWith("[]")) return true;
|
|
2192
|
+
if (type === "tuple") return param.components?.some(hasDynamicChild);
|
|
2193
|
+
const arrayComponents = getArrayComponents(param.type);
|
|
2194
|
+
if (arrayComponents && hasDynamicChild({
|
|
2195
|
+
...param,
|
|
2196
|
+
type: arrayComponents[1]
|
|
2197
|
+
})) return true;
|
|
2198
|
+
return false;
|
|
2199
|
+
}
|
|
2200
|
+
//#endregion
|
|
2201
|
+
//#region node_modules/.pnpm/ox@0.14.7_typescript@5.9.3_zod@4.3.6/node_modules/ox/_esm/core/internal/cursor.js
|
|
2202
|
+
const staticCursor = {
|
|
2203
|
+
bytes: new Uint8Array(),
|
|
2204
|
+
dataView: /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(0)),
|
|
2205
|
+
position: 0,
|
|
2206
|
+
positionReadCount: /* @__PURE__ */ new Map(),
|
|
2207
|
+
recursiveReadCount: 0,
|
|
2208
|
+
recursiveReadLimit: Number.POSITIVE_INFINITY,
|
|
2209
|
+
assertReadLimit() {
|
|
2210
|
+
if (this.recursiveReadCount >= this.recursiveReadLimit) throw new RecursiveReadLimitExceededError({
|
|
2211
|
+
count: this.recursiveReadCount + 1,
|
|
2212
|
+
limit: this.recursiveReadLimit
|
|
2213
|
+
});
|
|
2214
|
+
},
|
|
2215
|
+
assertPosition(position) {
|
|
2216
|
+
if (position < 0 || position > this.bytes.length - 1) throw new PositionOutOfBoundsError({
|
|
2217
|
+
length: this.bytes.length,
|
|
2218
|
+
position
|
|
2219
|
+
});
|
|
2220
|
+
},
|
|
2221
|
+
decrementPosition(offset) {
|
|
2222
|
+
if (offset < 0) throw new NegativeOffsetError({ offset });
|
|
2223
|
+
const position = this.position - offset;
|
|
2224
|
+
this.assertPosition(position);
|
|
2225
|
+
this.position = position;
|
|
2226
|
+
},
|
|
2227
|
+
getReadCount(position) {
|
|
2228
|
+
return this.positionReadCount.get(position || this.position) || 0;
|
|
2229
|
+
},
|
|
2230
|
+
incrementPosition(offset) {
|
|
2231
|
+
if (offset < 0) throw new NegativeOffsetError({ offset });
|
|
2232
|
+
const position = this.position + offset;
|
|
2233
|
+
this.assertPosition(position);
|
|
2234
|
+
this.position = position;
|
|
2235
|
+
},
|
|
2236
|
+
inspectByte(position_) {
|
|
2237
|
+
const position = position_ ?? this.position;
|
|
2238
|
+
this.assertPosition(position);
|
|
2239
|
+
return this.bytes[position];
|
|
2240
|
+
},
|
|
2241
|
+
inspectBytes(length, position_) {
|
|
2242
|
+
const position = position_ ?? this.position;
|
|
2243
|
+
this.assertPosition(position + length - 1);
|
|
2244
|
+
return this.bytes.subarray(position, position + length);
|
|
2245
|
+
},
|
|
2246
|
+
inspectUint8(position_) {
|
|
2247
|
+
const position = position_ ?? this.position;
|
|
2248
|
+
this.assertPosition(position);
|
|
2249
|
+
return this.bytes[position];
|
|
2250
|
+
},
|
|
2251
|
+
inspectUint16(position_) {
|
|
2252
|
+
const position = position_ ?? this.position;
|
|
2253
|
+
this.assertPosition(position + 1);
|
|
2254
|
+
return this.dataView.getUint16(position);
|
|
2255
|
+
},
|
|
2256
|
+
inspectUint24(position_) {
|
|
2257
|
+
const position = position_ ?? this.position;
|
|
2258
|
+
this.assertPosition(position + 2);
|
|
2259
|
+
return (this.dataView.getUint16(position) << 8) + this.dataView.getUint8(position + 2);
|
|
2260
|
+
},
|
|
2261
|
+
inspectUint32(position_) {
|
|
2262
|
+
const position = position_ ?? this.position;
|
|
2263
|
+
this.assertPosition(position + 3);
|
|
2264
|
+
return this.dataView.getUint32(position);
|
|
2265
|
+
},
|
|
2266
|
+
pushByte(byte) {
|
|
2267
|
+
this.assertPosition(this.position);
|
|
2268
|
+
this.bytes[this.position] = byte;
|
|
2269
|
+
this.position++;
|
|
2270
|
+
},
|
|
2271
|
+
pushBytes(bytes) {
|
|
2272
|
+
this.assertPosition(this.position + bytes.length - 1);
|
|
2273
|
+
this.bytes.set(bytes, this.position);
|
|
2274
|
+
this.position += bytes.length;
|
|
2275
|
+
},
|
|
2276
|
+
pushUint8(value) {
|
|
2277
|
+
this.assertPosition(this.position);
|
|
2278
|
+
this.bytes[this.position] = value;
|
|
2279
|
+
this.position++;
|
|
2280
|
+
},
|
|
2281
|
+
pushUint16(value) {
|
|
2282
|
+
this.assertPosition(this.position + 1);
|
|
2283
|
+
this.dataView.setUint16(this.position, value);
|
|
2284
|
+
this.position += 2;
|
|
2285
|
+
},
|
|
2286
|
+
pushUint24(value) {
|
|
2287
|
+
this.assertPosition(this.position + 2);
|
|
2288
|
+
this.dataView.setUint16(this.position, value >> 8);
|
|
2289
|
+
this.dataView.setUint8(this.position + 2, value & 255);
|
|
2290
|
+
this.position += 3;
|
|
2291
|
+
},
|
|
2292
|
+
pushUint32(value) {
|
|
2293
|
+
this.assertPosition(this.position + 3);
|
|
2294
|
+
this.dataView.setUint32(this.position, value);
|
|
2295
|
+
this.position += 4;
|
|
2296
|
+
},
|
|
2297
|
+
readByte() {
|
|
2298
|
+
this.assertReadLimit();
|
|
2299
|
+
this._touch();
|
|
2300
|
+
const value = this.inspectByte();
|
|
2301
|
+
this.position++;
|
|
2302
|
+
return value;
|
|
2303
|
+
},
|
|
2304
|
+
readBytes(length, size) {
|
|
2305
|
+
this.assertReadLimit();
|
|
2306
|
+
this._touch();
|
|
2307
|
+
const value = this.inspectBytes(length);
|
|
2308
|
+
this.position += size ?? length;
|
|
2309
|
+
return value;
|
|
2310
|
+
},
|
|
2311
|
+
readUint8() {
|
|
2312
|
+
this.assertReadLimit();
|
|
2313
|
+
this._touch();
|
|
2314
|
+
const value = this.inspectUint8();
|
|
2315
|
+
this.position += 1;
|
|
2316
|
+
return value;
|
|
2317
|
+
},
|
|
2318
|
+
readUint16() {
|
|
2319
|
+
this.assertReadLimit();
|
|
2320
|
+
this._touch();
|
|
2321
|
+
const value = this.inspectUint16();
|
|
2322
|
+
this.position += 2;
|
|
2323
|
+
return value;
|
|
2324
|
+
},
|
|
2325
|
+
readUint24() {
|
|
2326
|
+
this.assertReadLimit();
|
|
2327
|
+
this._touch();
|
|
2328
|
+
const value = this.inspectUint24();
|
|
2329
|
+
this.position += 3;
|
|
2330
|
+
return value;
|
|
2331
|
+
},
|
|
2332
|
+
readUint32() {
|
|
2333
|
+
this.assertReadLimit();
|
|
2334
|
+
this._touch();
|
|
2335
|
+
const value = this.inspectUint32();
|
|
2336
|
+
this.position += 4;
|
|
2337
|
+
return value;
|
|
2338
|
+
},
|
|
2339
|
+
get remaining() {
|
|
2340
|
+
return this.bytes.length - this.position;
|
|
2341
|
+
},
|
|
2342
|
+
setPosition(position) {
|
|
2343
|
+
const oldPosition = this.position;
|
|
2344
|
+
this.assertPosition(position);
|
|
2345
|
+
this.position = position;
|
|
2346
|
+
return () => this.position = oldPosition;
|
|
2347
|
+
},
|
|
2348
|
+
_touch() {
|
|
2349
|
+
if (this.recursiveReadLimit === Number.POSITIVE_INFINITY) return;
|
|
2350
|
+
const count = this.getReadCount();
|
|
2351
|
+
this.positionReadCount.set(this.position, count + 1);
|
|
2352
|
+
if (count > 0) this.recursiveReadCount++;
|
|
2353
|
+
}
|
|
2354
|
+
};
|
|
2355
|
+
/** @internal */
|
|
2356
|
+
function create(bytes, { recursiveReadLimit = 8192 } = {}) {
|
|
2357
|
+
const cursor = Object.create(staticCursor);
|
|
2358
|
+
cursor.bytes = bytes;
|
|
2359
|
+
cursor.dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
2360
|
+
cursor.positionReadCount = /* @__PURE__ */ new Map();
|
|
2361
|
+
cursor.recursiveReadLimit = recursiveReadLimit;
|
|
2362
|
+
return cursor;
|
|
2363
|
+
}
|
|
2364
|
+
/** @internal */
|
|
2365
|
+
var NegativeOffsetError = class extends BaseError {
|
|
2366
|
+
constructor({ offset }) {
|
|
2367
|
+
super(`Offset \`${offset}\` cannot be negative.`);
|
|
2368
|
+
Object.defineProperty(this, "name", {
|
|
2369
|
+
enumerable: true,
|
|
2370
|
+
configurable: true,
|
|
2371
|
+
writable: true,
|
|
2372
|
+
value: "Cursor.NegativeOffsetError"
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2375
|
+
};
|
|
2376
|
+
/** @internal */
|
|
2377
|
+
var PositionOutOfBoundsError = class extends BaseError {
|
|
2378
|
+
constructor({ length, position }) {
|
|
2379
|
+
super(`Position \`${position}\` is out of bounds (\`0 < position < ${length}\`).`);
|
|
2380
|
+
Object.defineProperty(this, "name", {
|
|
2381
|
+
enumerable: true,
|
|
2382
|
+
configurable: true,
|
|
2383
|
+
writable: true,
|
|
2384
|
+
value: "Cursor.PositionOutOfBoundsError"
|
|
2385
|
+
});
|
|
2386
|
+
}
|
|
2387
|
+
};
|
|
2388
|
+
/** @internal */
|
|
2389
|
+
var RecursiveReadLimitExceededError = class extends BaseError {
|
|
2390
|
+
constructor({ count, limit }) {
|
|
2391
|
+
super(`Recursive read limit of \`${limit}\` exceeded (recursive read count: \`${count}\`).`);
|
|
2392
|
+
Object.defineProperty(this, "name", {
|
|
2393
|
+
enumerable: true,
|
|
2394
|
+
configurable: true,
|
|
2395
|
+
writable: true,
|
|
2396
|
+
value: "Cursor.RecursiveReadLimitExceededError"
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
};
|
|
2400
|
+
//#endregion
|
|
2401
|
+
//#region node_modules/.pnpm/ox@0.14.7_typescript@5.9.3_zod@4.3.6/node_modules/ox/_esm/core/AbiParameters.js
|
|
2402
|
+
function decode(parameters, data, options = {}) {
|
|
2403
|
+
const { as = "Array", checksumAddress = false } = options;
|
|
2404
|
+
const bytes = typeof data === "string" ? fromHex$3(data) : data;
|
|
2405
|
+
const cursor = create(bytes);
|
|
2406
|
+
if (size$1(bytes) === 0 && parameters.length > 0) throw new ZeroDataError();
|
|
2407
|
+
if (size$1(bytes) && size$1(bytes) < 32) throw new DataSizeTooSmallError({
|
|
2408
|
+
data: typeof data === "string" ? data : fromBytes$2(data),
|
|
2409
|
+
parameters,
|
|
2410
|
+
size: size$1(bytes)
|
|
2411
|
+
});
|
|
2412
|
+
let consumed = 0;
|
|
2413
|
+
const values = as === "Array" ? [] : {};
|
|
2414
|
+
for (let i = 0; i < parameters.length; ++i) {
|
|
2415
|
+
const param = parameters[i];
|
|
2416
|
+
cursor.setPosition(consumed);
|
|
2417
|
+
const [data, consumed_] = decodeParameter(cursor, param, {
|
|
2418
|
+
checksumAddress,
|
|
2419
|
+
staticPosition: 0
|
|
2420
|
+
});
|
|
2421
|
+
consumed += consumed_;
|
|
2422
|
+
if (as === "Array") values.push(data);
|
|
2423
|
+
else values[param.name ?? i] = data;
|
|
2424
|
+
}
|
|
2425
|
+
return values;
|
|
2426
|
+
}
|
|
2427
|
+
/**
|
|
2428
|
+
* Encodes primitive values into ABI encoded data as per the [Application Binary Interface (ABI) Specification](https://docs.soliditylang.org/en/latest/abi-spec).
|
|
2429
|
+
*
|
|
2430
|
+
* @example
|
|
2431
|
+
* ```ts twoslash
|
|
2432
|
+
* import { AbiParameters } from 'ox'
|
|
2433
|
+
*
|
|
2434
|
+
* const data = AbiParameters.encode(
|
|
2435
|
+
* AbiParameters.from(['string', 'uint', 'bool']),
|
|
2436
|
+
* ['wagmi', 420n, true],
|
|
2437
|
+
* )
|
|
2438
|
+
* ```
|
|
2439
|
+
*
|
|
2440
|
+
* @example
|
|
2441
|
+
* ### JSON Parameters
|
|
2442
|
+
*
|
|
2443
|
+
* Specify **JSON ABI** Parameters as schema:
|
|
2444
|
+
*
|
|
2445
|
+
* ```ts twoslash
|
|
2446
|
+
* import { AbiParameters } from 'ox'
|
|
2447
|
+
*
|
|
2448
|
+
* const data = AbiParameters.encode(
|
|
2449
|
+
* [
|
|
2450
|
+
* { type: 'string', name: 'name' },
|
|
2451
|
+
* { type: 'uint', name: 'age' },
|
|
2452
|
+
* { type: 'bool', name: 'isOwner' },
|
|
2453
|
+
* ],
|
|
2454
|
+
* ['wagmi', 420n, true],
|
|
2455
|
+
* )
|
|
2456
|
+
* ```
|
|
2457
|
+
*
|
|
2458
|
+
* @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).
|
|
2459
|
+
* @param values - The set of primitive values that correspond to the ABI types defined in `parameters`.
|
|
2460
|
+
* @returns ABI encoded data.
|
|
2461
|
+
*/
|
|
2462
|
+
function encode(parameters, values, options) {
|
|
2463
|
+
const { checksumAddress = false } = options ?? {};
|
|
2464
|
+
if (parameters.length !== values.length) throw new LengthMismatchError({
|
|
2465
|
+
expectedLength: parameters.length,
|
|
2466
|
+
givenLength: values.length
|
|
2467
|
+
});
|
|
2468
|
+
const data = encode$1(prepareParameters({
|
|
2469
|
+
checksumAddress,
|
|
2470
|
+
parameters,
|
|
2471
|
+
values
|
|
2472
|
+
}));
|
|
2473
|
+
if (data.length === 0) return "0x";
|
|
2474
|
+
return data;
|
|
2475
|
+
}
|
|
2476
|
+
/**
|
|
2477
|
+
* Encodes an array of primitive values to a [packed ABI encoding](https://docs.soliditylang.org/en/latest/abi-spec.html#non-standard-packed-mode).
|
|
2478
|
+
*
|
|
2479
|
+
* @example
|
|
2480
|
+
* ```ts twoslash
|
|
2481
|
+
* import { AbiParameters } from 'ox'
|
|
2482
|
+
*
|
|
2483
|
+
* const encoded = AbiParameters.encodePacked(
|
|
2484
|
+
* ['address', 'string'],
|
|
2485
|
+
* ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 'hello world'],
|
|
2486
|
+
* )
|
|
2487
|
+
* // @log: '0xd8da6bf26964af9d7eed9e03e53415d37aa9604568656c6c6f20776f726c64'
|
|
2488
|
+
* ```
|
|
2489
|
+
*
|
|
2490
|
+
* @param types - Set of ABI types to pack encode.
|
|
2491
|
+
* @param values - The set of primitive values that correspond to the ABI types defined in `types`.
|
|
2492
|
+
* @returns The encoded packed data.
|
|
2493
|
+
*/
|
|
2494
|
+
function encodePacked(types, values) {
|
|
2495
|
+
if (types.length !== values.length) throw new LengthMismatchError({
|
|
2496
|
+
expectedLength: types.length,
|
|
2497
|
+
givenLength: values.length
|
|
2498
|
+
});
|
|
2499
|
+
const data = [];
|
|
2500
|
+
for (let i = 0; i < types.length; i++) {
|
|
2501
|
+
const type = types[i];
|
|
2502
|
+
const value = values[i];
|
|
2503
|
+
data.push(encodePacked.encode(type, value));
|
|
2504
|
+
}
|
|
2505
|
+
return concat(...data);
|
|
2506
|
+
}
|
|
2507
|
+
(function(encodePacked) {
|
|
2508
|
+
function encode(type, value, isArray = false) {
|
|
2509
|
+
if (type === "address") {
|
|
2510
|
+
const address = value;
|
|
2511
|
+
assert$1(address);
|
|
2512
|
+
return padLeft(address.toLowerCase(), isArray ? 32 : 0);
|
|
2513
|
+
}
|
|
2514
|
+
if (type === "string") return fromString$1(value);
|
|
2515
|
+
if (type === "bytes") return value;
|
|
2516
|
+
if (type === "bool") return padLeft(fromBoolean(value), isArray ? 32 : 1);
|
|
2517
|
+
const intMatch = type.match(integerRegex);
|
|
2518
|
+
if (intMatch) {
|
|
2519
|
+
const [_type, baseType, bits = "256"] = intMatch;
|
|
2520
|
+
const size = Number.parseInt(bits, 10) / 8;
|
|
2521
|
+
return fromNumber(value, {
|
|
2522
|
+
size: isArray ? 32 : size,
|
|
2523
|
+
signed: baseType === "int"
|
|
2524
|
+
});
|
|
2525
|
+
}
|
|
2526
|
+
const bytesMatch = type.match(bytesRegex);
|
|
2527
|
+
if (bytesMatch) {
|
|
2528
|
+
const [_type, size] = bytesMatch;
|
|
2529
|
+
if (Number.parseInt(size, 10) !== (value.length - 2) / 2) throw new BytesSizeMismatchError({
|
|
2530
|
+
expectedSize: Number.parseInt(size, 10),
|
|
2531
|
+
value
|
|
2532
|
+
});
|
|
2533
|
+
return padRight(value, isArray ? 32 : 0);
|
|
2534
|
+
}
|
|
2535
|
+
const arrayMatch = type.match(arrayRegex);
|
|
2536
|
+
if (arrayMatch && Array.isArray(value)) {
|
|
2537
|
+
const [_type, childType] = arrayMatch;
|
|
2538
|
+
const data = [];
|
|
2539
|
+
for (let i = 0; i < value.length; i++) data.push(encode(childType, value[i], true));
|
|
2540
|
+
if (data.length === 0) return "0x";
|
|
2541
|
+
return concat(...data);
|
|
2542
|
+
}
|
|
2543
|
+
throw new InvalidTypeError(type);
|
|
2544
|
+
}
|
|
2545
|
+
encodePacked.encode = encode;
|
|
2546
|
+
})(encodePacked || (encodePacked = {}));
|
|
2547
|
+
/**
|
|
2548
|
+
* Parses arbitrary **JSON ABI Parameters** or **Human Readable ABI Parameters** into typed {@link ox#AbiParameters.AbiParameters}.
|
|
2549
|
+
*
|
|
2550
|
+
* @example
|
|
2551
|
+
* ### JSON Parameters
|
|
2552
|
+
*
|
|
2553
|
+
* ```ts twoslash
|
|
2554
|
+
* import { AbiParameters } from 'ox'
|
|
2555
|
+
*
|
|
2556
|
+
* const parameters = AbiParameters.from([
|
|
2557
|
+
* {
|
|
2558
|
+
* name: 'spender',
|
|
2559
|
+
* type: 'address',
|
|
2560
|
+
* },
|
|
2561
|
+
* {
|
|
2562
|
+
* name: 'amount',
|
|
2563
|
+
* type: 'uint256',
|
|
2564
|
+
* },
|
|
2565
|
+
* ])
|
|
2566
|
+
*
|
|
2567
|
+
* parameters
|
|
2568
|
+
* //^?
|
|
2569
|
+
*
|
|
2570
|
+
*
|
|
2571
|
+
*
|
|
2572
|
+
*
|
|
2573
|
+
*
|
|
2574
|
+
*
|
|
2575
|
+
*
|
|
2576
|
+
* ```
|
|
2577
|
+
*
|
|
2578
|
+
* @example
|
|
2579
|
+
* ### Human Readable Parameters
|
|
2580
|
+
*
|
|
2581
|
+
* Human Readable ABI Parameters can be parsed into a typed {@link ox#AbiParameters.AbiParameters}:
|
|
2582
|
+
*
|
|
2583
|
+
* ```ts twoslash
|
|
2584
|
+
* import { AbiParameters } from 'ox'
|
|
2585
|
+
*
|
|
2586
|
+
* const parameters = AbiParameters.from('address spender, uint256 amount')
|
|
2587
|
+
*
|
|
2588
|
+
* parameters
|
|
2589
|
+
* //^?
|
|
2590
|
+
*
|
|
2591
|
+
*
|
|
2592
|
+
*
|
|
2593
|
+
*
|
|
2594
|
+
*
|
|
2595
|
+
*
|
|
2596
|
+
*
|
|
2597
|
+
* ```
|
|
2598
|
+
*
|
|
2599
|
+
* @example
|
|
2600
|
+
* It is possible to specify `struct`s along with your definitions:
|
|
2601
|
+
*
|
|
2602
|
+
* ```ts twoslash
|
|
2603
|
+
* import { AbiParameters } from 'ox'
|
|
2604
|
+
*
|
|
2605
|
+
* const parameters = AbiParameters.from([
|
|
2606
|
+
* 'struct Foo { address spender; uint256 amount; }', // [!code hl]
|
|
2607
|
+
* 'Foo foo, address bar',
|
|
2608
|
+
* ])
|
|
2609
|
+
*
|
|
2610
|
+
* parameters
|
|
2611
|
+
* //^?
|
|
2612
|
+
*
|
|
2613
|
+
*
|
|
2614
|
+
*
|
|
2615
|
+
*
|
|
2616
|
+
*
|
|
2617
|
+
*
|
|
2618
|
+
*
|
|
2619
|
+
*
|
|
2620
|
+
*
|
|
2621
|
+
*
|
|
2622
|
+
*
|
|
2623
|
+
*
|
|
2624
|
+
* ```
|
|
2625
|
+
*
|
|
2626
|
+
*
|
|
2627
|
+
*
|
|
2628
|
+
* @param parameters - The ABI Parameters to parse.
|
|
2629
|
+
* @returns The typed ABI Parameters.
|
|
2630
|
+
*/
|
|
2631
|
+
function from$2(parameters) {
|
|
2632
|
+
if (Array.isArray(parameters) && typeof parameters[0] === "string") return parseAbiParameters(parameters);
|
|
2633
|
+
if (typeof parameters === "string") return parseAbiParameters(parameters);
|
|
2634
|
+
return parameters;
|
|
2635
|
+
}
|
|
2636
|
+
/**
|
|
2637
|
+
* Throws when the data size is too small for the given parameters.
|
|
2638
|
+
*
|
|
2639
|
+
* @example
|
|
2640
|
+
* ```ts twoslash
|
|
2641
|
+
* import { AbiParameters } from 'ox'
|
|
2642
|
+
*
|
|
2643
|
+
* AbiParameters.decode([{ type: 'uint256' }], '0x010f')
|
|
2644
|
+
* // ↑ ❌ 2 bytes
|
|
2645
|
+
* // @error: AbiParameters.DataSizeTooSmallError: Data size of 2 bytes is too small for given parameters.
|
|
2646
|
+
* // @error: Params: (uint256)
|
|
2647
|
+
* // @error: Data: 0x010f (2 bytes)
|
|
2648
|
+
* ```
|
|
2649
|
+
*
|
|
2650
|
+
* ### Solution
|
|
2651
|
+
*
|
|
2652
|
+
* Pass a valid data size.
|
|
2653
|
+
*
|
|
2654
|
+
* ```ts twoslash
|
|
2655
|
+
* import { AbiParameters } from 'ox'
|
|
2656
|
+
*
|
|
2657
|
+
* AbiParameters.decode([{ type: 'uint256' }], '0x00000000000000000000000000000000000000000000000000000000000010f')
|
|
2658
|
+
* // ↑ ✅ 32 bytes
|
|
2659
|
+
* ```
|
|
2660
|
+
*/
|
|
2661
|
+
var DataSizeTooSmallError = class extends BaseError {
|
|
2662
|
+
constructor({ data, parameters, size }) {
|
|
2663
|
+
super(`Data size of ${size} bytes is too small for given parameters.`, { metaMessages: [`Params: (${formatAbiParameters(parameters)})`, `Data: ${data} (${size} bytes)`] });
|
|
2664
|
+
Object.defineProperty(this, "name", {
|
|
2665
|
+
enumerable: true,
|
|
2666
|
+
configurable: true,
|
|
2667
|
+
writable: true,
|
|
2668
|
+
value: "AbiParameters.DataSizeTooSmallError"
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
};
|
|
2672
|
+
/**
|
|
2673
|
+
* Throws when zero data is provided, but data is expected.
|
|
2674
|
+
*
|
|
2675
|
+
* @example
|
|
2676
|
+
* ```ts twoslash
|
|
2677
|
+
* import { AbiParameters } from 'ox'
|
|
2678
|
+
*
|
|
2679
|
+
* AbiParameters.decode([{ type: 'uint256' }], '0x')
|
|
2680
|
+
* // ↑ ❌ zero data
|
|
2681
|
+
* // @error: AbiParameters.DataSizeTooSmallError: Data size of 2 bytes is too small for given parameters.
|
|
2682
|
+
* // @error: Params: (uint256)
|
|
2683
|
+
* // @error: Data: 0x010f (2 bytes)
|
|
2684
|
+
* ```
|
|
2685
|
+
*
|
|
2686
|
+
* ### Solution
|
|
2687
|
+
*
|
|
2688
|
+
* Pass valid data.
|
|
2689
|
+
*
|
|
2690
|
+
* ```ts twoslash
|
|
2691
|
+
* import { AbiParameters } from 'ox'
|
|
2692
|
+
*
|
|
2693
|
+
* AbiParameters.decode([{ type: 'uint256' }], '0x00000000000000000000000000000000000000000000000000000000000010f')
|
|
2694
|
+
* // ↑ ✅ 32 bytes
|
|
2695
|
+
* ```
|
|
2696
|
+
*/
|
|
2697
|
+
var ZeroDataError = class extends BaseError {
|
|
2698
|
+
constructor() {
|
|
2699
|
+
super("Cannot decode zero data (\"0x\") with ABI parameters.");
|
|
2700
|
+
Object.defineProperty(this, "name", {
|
|
2701
|
+
enumerable: true,
|
|
2702
|
+
configurable: true,
|
|
2703
|
+
writable: true,
|
|
2704
|
+
value: "AbiParameters.ZeroDataError"
|
|
2705
|
+
});
|
|
2706
|
+
}
|
|
2707
|
+
};
|
|
2708
|
+
/**
|
|
2709
|
+
* The length of the array value does not match the length specified in the corresponding ABI parameter.
|
|
2710
|
+
*
|
|
2711
|
+
* ### Example
|
|
2712
|
+
*
|
|
2713
|
+
* ```ts twoslash
|
|
2714
|
+
* // @noErrors
|
|
2715
|
+
* import { AbiParameters } from 'ox'
|
|
2716
|
+
* // ---cut---
|
|
2717
|
+
* AbiParameters.encode(AbiParameters.from('uint256[3]'), [[69n, 420n]])
|
|
2718
|
+
* // ↑ expected: 3 ↑ ❌ length: 2
|
|
2719
|
+
* // @error: AbiParameters.ArrayLengthMismatchError: ABI encoding array length mismatch
|
|
2720
|
+
* // @error: for type `uint256[3]`. Expected: `3`. Given: `2`.
|
|
2721
|
+
* ```
|
|
2722
|
+
*
|
|
2723
|
+
* ### Solution
|
|
2724
|
+
*
|
|
2725
|
+
* Pass an array of the correct length.
|
|
2726
|
+
*
|
|
2727
|
+
* ```ts twoslash
|
|
2728
|
+
* import { AbiParameters } from 'ox'
|
|
2729
|
+
* // ---cut---
|
|
2730
|
+
* AbiParameters.encode(AbiParameters.from(['uint256[3]']), [[69n, 420n, 69n]])
|
|
2731
|
+
* // ↑ ✅ length: 3
|
|
2732
|
+
* ```
|
|
2733
|
+
*/
|
|
2734
|
+
var ArrayLengthMismatchError = class extends BaseError {
|
|
2735
|
+
constructor({ expectedLength, givenLength, type }) {
|
|
2736
|
+
super(`Array length mismatch for type \`${type}\`. Expected: \`${expectedLength}\`. Given: \`${givenLength}\`.`);
|
|
2737
|
+
Object.defineProperty(this, "name", {
|
|
2738
|
+
enumerable: true,
|
|
2739
|
+
configurable: true,
|
|
2740
|
+
writable: true,
|
|
2741
|
+
value: "AbiParameters.ArrayLengthMismatchError"
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
};
|
|
2745
|
+
/**
|
|
2746
|
+
* The size of the bytes value does not match the size specified in the corresponding ABI parameter.
|
|
2747
|
+
*
|
|
2748
|
+
* ### Example
|
|
2749
|
+
*
|
|
2750
|
+
* ```ts twoslash
|
|
2751
|
+
* // @noErrors
|
|
2752
|
+
* import { AbiParameters } from 'ox'
|
|
2753
|
+
* // ---cut---
|
|
2754
|
+
* AbiParameters.encode(AbiParameters.from('bytes8'), [['0xdeadbeefdeadbeefdeadbeef']])
|
|
2755
|
+
* // ↑ expected: 8 bytes ↑ ❌ size: 12 bytes
|
|
2756
|
+
* // @error: BytesSizeMismatchError: Size of bytes "0xdeadbeefdeadbeefdeadbeef"
|
|
2757
|
+
* // @error: (bytes12) does not match expected size (bytes8).
|
|
2758
|
+
* ```
|
|
2759
|
+
*
|
|
2760
|
+
* ### Solution
|
|
2761
|
+
*
|
|
2762
|
+
* Pass a bytes value of the correct size.
|
|
2763
|
+
*
|
|
2764
|
+
* ```ts twoslash
|
|
2765
|
+
* import { AbiParameters } from 'ox'
|
|
2766
|
+
* // ---cut---
|
|
2767
|
+
* AbiParameters.encode(AbiParameters.from(['bytes8']), ['0xdeadbeefdeadbeef'])
|
|
2768
|
+
* // ↑ ✅ size: 8 bytes
|
|
2769
|
+
* ```
|
|
2770
|
+
*/
|
|
2771
|
+
var BytesSizeMismatchError = class extends BaseError {
|
|
2772
|
+
constructor({ expectedSize, value }) {
|
|
2773
|
+
super(`Size of bytes "${value}" (bytes${size(value)}) does not match expected size (bytes${expectedSize}).`);
|
|
2774
|
+
Object.defineProperty(this, "name", {
|
|
2775
|
+
enumerable: true,
|
|
2776
|
+
configurable: true,
|
|
2777
|
+
writable: true,
|
|
2778
|
+
value: "AbiParameters.BytesSizeMismatchError"
|
|
2779
|
+
});
|
|
2780
|
+
}
|
|
2781
|
+
};
|
|
2782
|
+
/**
|
|
2783
|
+
* The length of the values to encode does not match the length of the ABI parameters.
|
|
2784
|
+
*
|
|
2785
|
+
* ### Example
|
|
2786
|
+
*
|
|
2787
|
+
* ```ts twoslash
|
|
2788
|
+
* // @noErrors
|
|
2789
|
+
* import { AbiParameters } from 'ox'
|
|
2790
|
+
* // ---cut---
|
|
2791
|
+
* AbiParameters.encode(AbiParameters.from(['string', 'uint256']), ['hello'])
|
|
2792
|
+
* // @error: LengthMismatchError: ABI encoding params/values length mismatch.
|
|
2793
|
+
* // @error: Expected length (params): 2
|
|
2794
|
+
* // @error: Given length (values): 1
|
|
2795
|
+
* ```
|
|
2796
|
+
*
|
|
2797
|
+
* ### Solution
|
|
2798
|
+
*
|
|
2799
|
+
* Pass the correct number of values to encode.
|
|
2800
|
+
*
|
|
2801
|
+
* ### Solution
|
|
2802
|
+
*
|
|
2803
|
+
* Pass a [valid ABI type](https://docs.soliditylang.org/en/develop/abi-spec.html#types).
|
|
2804
|
+
*/
|
|
2805
|
+
var LengthMismatchError = class extends BaseError {
|
|
2806
|
+
constructor({ expectedLength, givenLength }) {
|
|
2807
|
+
super([
|
|
2808
|
+
"ABI encoding parameters/values length mismatch.",
|
|
2809
|
+
`Expected length (parameters): ${expectedLength}`,
|
|
2810
|
+
`Given length (values): ${givenLength}`
|
|
2811
|
+
].join("\n"));
|
|
2812
|
+
Object.defineProperty(this, "name", {
|
|
2813
|
+
enumerable: true,
|
|
2814
|
+
configurable: true,
|
|
2815
|
+
writable: true,
|
|
2816
|
+
value: "AbiParameters.LengthMismatchError"
|
|
2817
|
+
});
|
|
2818
|
+
}
|
|
2819
|
+
};
|
|
2820
|
+
/**
|
|
2821
|
+
* The value provided is not a valid array as specified in the corresponding ABI parameter.
|
|
2822
|
+
*
|
|
2823
|
+
* ### Example
|
|
2824
|
+
*
|
|
2825
|
+
* ```ts twoslash
|
|
2826
|
+
* // @noErrors
|
|
2827
|
+
* import { AbiParameters } from 'ox'
|
|
2828
|
+
* // ---cut---
|
|
2829
|
+
* AbiParameters.encode(AbiParameters.from(['uint256[3]']), [69])
|
|
2830
|
+
* ```
|
|
2831
|
+
*
|
|
2832
|
+
* ### Solution
|
|
2833
|
+
*
|
|
2834
|
+
* Pass an array value.
|
|
2835
|
+
*/
|
|
2836
|
+
var InvalidArrayError = class extends BaseError {
|
|
2837
|
+
constructor(value) {
|
|
2838
|
+
super(`Value \`${value}\` is not a valid array.`);
|
|
2839
|
+
Object.defineProperty(this, "name", {
|
|
2840
|
+
enumerable: true,
|
|
2841
|
+
configurable: true,
|
|
2842
|
+
writable: true,
|
|
2843
|
+
value: "AbiParameters.InvalidArrayError"
|
|
2844
|
+
});
|
|
2845
|
+
}
|
|
2846
|
+
};
|
|
2847
|
+
/**
|
|
2848
|
+
* Throws when the ABI parameter type is invalid.
|
|
2849
|
+
*
|
|
2850
|
+
* @example
|
|
2851
|
+
* ```ts twoslash
|
|
2852
|
+
* import { AbiParameters } from 'ox'
|
|
2853
|
+
*
|
|
2854
|
+
* AbiParameters.decode([{ type: 'lol' }], '0x00000000000000000000000000000000000000000000000000000000000010f')
|
|
2855
|
+
* // ↑ ❌ invalid type
|
|
2856
|
+
* // @error: AbiParameters.InvalidTypeError: Type `lol` is not a valid ABI Type.
|
|
2857
|
+
* ```
|
|
2858
|
+
*/
|
|
2859
|
+
var InvalidTypeError = class extends BaseError {
|
|
2860
|
+
constructor(type) {
|
|
2861
|
+
super(`Type \`${type}\` is not a valid ABI Type.`);
|
|
2862
|
+
Object.defineProperty(this, "name", {
|
|
2863
|
+
enumerable: true,
|
|
2864
|
+
configurable: true,
|
|
2865
|
+
writable: true,
|
|
2866
|
+
value: "AbiParameters.InvalidTypeError"
|
|
2867
|
+
});
|
|
2868
|
+
}
|
|
2869
|
+
};
|
|
2870
|
+
//#endregion
|
|
2871
|
+
//#region node_modules/.pnpm/ox@0.14.7_typescript@5.9.3_zod@4.3.6/node_modules/ox/_esm/core/Rlp.js
|
|
2872
|
+
/**
|
|
2873
|
+
* Decodes a Recursive-Length Prefix (RLP) value into a {@link ox#Hex.Hex} value.
|
|
2874
|
+
*
|
|
2875
|
+
* @example
|
|
2876
|
+
* ```ts twoslash
|
|
2877
|
+
* import { Rlp } from 'ox'
|
|
2878
|
+
* Rlp.toHex('0x8b68656c6c6f20776f726c64')
|
|
2879
|
+
* // 0x68656c6c6f20776f726c64
|
|
2880
|
+
* ```
|
|
2881
|
+
*
|
|
2882
|
+
* @param value - The value to decode.
|
|
2883
|
+
* @returns The decoded {@link ox#Hex.Hex} value.
|
|
2884
|
+
*/
|
|
2885
|
+
function toHex$1(value) {
|
|
2886
|
+
return to(value, "Hex");
|
|
2887
|
+
}
|
|
2888
|
+
/** @internal */
|
|
2889
|
+
function to(value, to) {
|
|
2890
|
+
const to_ = to ?? (typeof value === "string" ? "Hex" : "Bytes");
|
|
2891
|
+
return decodeRlpCursor(create((() => {
|
|
2892
|
+
if (typeof value === "string") {
|
|
2893
|
+
if (value.length > 3 && value.length % 2 !== 0) throw new InvalidLengthError(value);
|
|
2894
|
+
return fromHex$3(value);
|
|
2895
|
+
}
|
|
2896
|
+
return value;
|
|
2897
|
+
})(), { recursiveReadLimit: Number.POSITIVE_INFINITY }), to_);
|
|
2898
|
+
}
|
|
2899
|
+
/** @internal */
|
|
2900
|
+
/** @internal */
|
|
2901
|
+
function decodeRlpCursor(cursor, to = "Hex") {
|
|
2902
|
+
if (cursor.bytes.length === 0) return to === "Hex" ? fromBytes$2(cursor.bytes) : cursor.bytes;
|
|
2903
|
+
const prefix = cursor.readByte();
|
|
2904
|
+
if (prefix < 128) cursor.decrementPosition(1);
|
|
2905
|
+
if (prefix < 192) {
|
|
2906
|
+
const length = readLength(cursor, prefix, 128);
|
|
2907
|
+
const bytes = cursor.readBytes(length);
|
|
2908
|
+
return to === "Hex" ? fromBytes$2(bytes) : bytes;
|
|
2909
|
+
}
|
|
2910
|
+
return readList(cursor, readLength(cursor, prefix, 192), to);
|
|
2911
|
+
}
|
|
2912
|
+
/** @internal */
|
|
2913
|
+
function readLength(cursor, prefix, offset) {
|
|
2914
|
+
if (offset === 128 && prefix < 128) return 1;
|
|
2915
|
+
if (prefix <= offset + 55) return prefix - offset;
|
|
2916
|
+
if (prefix === offset + 55 + 1) return cursor.readUint8();
|
|
2917
|
+
if (prefix === offset + 55 + 2) return cursor.readUint16();
|
|
2918
|
+
if (prefix === offset + 55 + 3) return cursor.readUint24();
|
|
2919
|
+
if (prefix === offset + 55 + 4) return cursor.readUint32();
|
|
2920
|
+
throw new BaseError("Invalid RLP prefix");
|
|
2921
|
+
}
|
|
2922
|
+
/** @internal */
|
|
2923
|
+
function readList(cursor, length, to) {
|
|
2924
|
+
const position = cursor.position;
|
|
2925
|
+
const value = [];
|
|
2926
|
+
while (cursor.position - position < length) value.push(decodeRlpCursor(cursor, to));
|
|
2927
|
+
return value;
|
|
2928
|
+
}
|
|
2929
|
+
/**
|
|
2930
|
+
* Encodes a {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value into a Recursive-Length Prefix (RLP) value.
|
|
2931
|
+
*
|
|
2932
|
+
* @example
|
|
2933
|
+
* ```ts twoslash
|
|
2934
|
+
* import { Bytes, Rlp } from 'ox'
|
|
2935
|
+
*
|
|
2936
|
+
* Rlp.from('0x68656c6c6f20776f726c64', { as: 'Hex' })
|
|
2937
|
+
* // @log: 0x8b68656c6c6f20776f726c64
|
|
2938
|
+
*
|
|
2939
|
+
* Rlp.from(Bytes.from([139, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]), { as: 'Bytes' })
|
|
2940
|
+
* // @log: Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])
|
|
2941
|
+
* ```
|
|
2942
|
+
*
|
|
2943
|
+
* @param value - The {@link ox#Bytes.Bytes} or {@link ox#Hex.Hex} value to encode.
|
|
2944
|
+
* @param options - Options.
|
|
2945
|
+
* @returns The RLP value.
|
|
2946
|
+
*/
|
|
2947
|
+
function from$1(value, options) {
|
|
2948
|
+
const { as } = options;
|
|
2949
|
+
const encodable = getEncodable(value);
|
|
2950
|
+
const cursor = create(new Uint8Array(encodable.length));
|
|
2951
|
+
encodable.encode(cursor);
|
|
2952
|
+
if (as === "Hex") return fromBytes$2(cursor.bytes);
|
|
2953
|
+
return cursor.bytes;
|
|
2954
|
+
}
|
|
2955
|
+
/**
|
|
2956
|
+
* Encodes a {@link ox#Hex.Hex} value into a Recursive-Length Prefix (RLP) value.
|
|
2957
|
+
*
|
|
2958
|
+
* @example
|
|
2959
|
+
* ```ts twoslash
|
|
2960
|
+
* import { Rlp } from 'ox'
|
|
2961
|
+
*
|
|
2962
|
+
* Rlp.fromHex('0x68656c6c6f20776f726c64')
|
|
2963
|
+
* // @log: 0x8b68656c6c6f20776f726c64
|
|
2964
|
+
* ```
|
|
2965
|
+
*
|
|
2966
|
+
* @param hex - The {@link ox#Hex.Hex} value to encode.
|
|
2967
|
+
* @param options - Options.
|
|
2968
|
+
* @returns The RLP value.
|
|
2969
|
+
*/
|
|
2970
|
+
function fromHex$1(hex, options = {}) {
|
|
2971
|
+
const { as = "Hex" } = options;
|
|
2972
|
+
return from$1(hex, { as });
|
|
2973
|
+
}
|
|
2974
|
+
function getEncodable(bytes) {
|
|
2975
|
+
if (Array.isArray(bytes)) return getEncodableList(bytes.map((x) => getEncodable(x)));
|
|
2976
|
+
return getEncodableBytes(bytes);
|
|
2977
|
+
}
|
|
2978
|
+
function getEncodableList(list) {
|
|
2979
|
+
const bodyLength = list.reduce((acc, x) => acc + x.length, 0);
|
|
2980
|
+
const sizeOfBodyLength = getSizeOfLength(bodyLength);
|
|
2981
|
+
return {
|
|
2982
|
+
length: (() => {
|
|
2983
|
+
if (bodyLength <= 55) return 1 + bodyLength;
|
|
2984
|
+
return 1 + sizeOfBodyLength + bodyLength;
|
|
2985
|
+
})(),
|
|
2986
|
+
encode(cursor) {
|
|
2987
|
+
if (bodyLength <= 55) cursor.pushByte(192 + bodyLength);
|
|
2988
|
+
else {
|
|
2989
|
+
cursor.pushByte(247 + sizeOfBodyLength);
|
|
2990
|
+
if (sizeOfBodyLength === 1) cursor.pushUint8(bodyLength);
|
|
2991
|
+
else if (sizeOfBodyLength === 2) cursor.pushUint16(bodyLength);
|
|
2992
|
+
else if (sizeOfBodyLength === 3) cursor.pushUint24(bodyLength);
|
|
2993
|
+
else cursor.pushUint32(bodyLength);
|
|
2994
|
+
}
|
|
2995
|
+
for (const { encode } of list) encode(cursor);
|
|
2996
|
+
}
|
|
2997
|
+
};
|
|
2998
|
+
}
|
|
2999
|
+
function getEncodableBytes(bytesOrHex) {
|
|
3000
|
+
const bytes = typeof bytesOrHex === "string" ? fromHex$3(bytesOrHex) : bytesOrHex;
|
|
3001
|
+
const sizeOfBytesLength = getSizeOfLength(bytes.length);
|
|
3002
|
+
return {
|
|
3003
|
+
length: (() => {
|
|
3004
|
+
if (bytes.length === 1 && bytes[0] < 128) return 1;
|
|
3005
|
+
if (bytes.length <= 55) return 1 + bytes.length;
|
|
3006
|
+
return 1 + sizeOfBytesLength + bytes.length;
|
|
3007
|
+
})(),
|
|
3008
|
+
encode(cursor) {
|
|
3009
|
+
if (bytes.length === 1 && bytes[0] < 128) cursor.pushBytes(bytes);
|
|
3010
|
+
else if (bytes.length <= 55) {
|
|
3011
|
+
cursor.pushByte(128 + bytes.length);
|
|
3012
|
+
cursor.pushBytes(bytes);
|
|
3013
|
+
} else {
|
|
3014
|
+
cursor.pushByte(183 + sizeOfBytesLength);
|
|
3015
|
+
if (sizeOfBytesLength === 1) cursor.pushUint8(bytes.length);
|
|
3016
|
+
else if (sizeOfBytesLength === 2) cursor.pushUint16(bytes.length);
|
|
3017
|
+
else if (sizeOfBytesLength === 3) cursor.pushUint24(bytes.length);
|
|
3018
|
+
else cursor.pushUint32(bytes.length);
|
|
3019
|
+
cursor.pushBytes(bytes);
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
};
|
|
3023
|
+
}
|
|
3024
|
+
function getSizeOfLength(length) {
|
|
3025
|
+
if (length <= 255) return 1;
|
|
3026
|
+
if (length <= 65535) return 2;
|
|
3027
|
+
if (length <= 16777215) return 3;
|
|
3028
|
+
if (length <= 4294967295) return 4;
|
|
3029
|
+
throw new BaseError("Length is too large.");
|
|
3030
|
+
}
|
|
3031
|
+
//#endregion
|
|
3032
|
+
//#region node_modules/.pnpm/ox@0.14.7_typescript@5.9.3_zod@4.3.6/node_modules/ox/_esm/core/Signature.js
|
|
3033
|
+
/**
|
|
3034
|
+
* Asserts that a Signature is valid.
|
|
3035
|
+
*
|
|
3036
|
+
* @example
|
|
3037
|
+
* ```ts twoslash
|
|
3038
|
+
* import { Signature } from 'ox'
|
|
3039
|
+
*
|
|
3040
|
+
* Signature.assert({
|
|
3041
|
+
* r: -49782753348462494199823712700004552394425719014458918871452329774910450607807n,
|
|
3042
|
+
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
|
|
3043
|
+
* yParity: 1,
|
|
3044
|
+
* })
|
|
3045
|
+
* // @error: InvalidSignatureRError:
|
|
3046
|
+
* // @error: Value `-549...n` is an invalid r value.
|
|
3047
|
+
* // @error: r must be a positive integer less than 2^256.
|
|
3048
|
+
* ```
|
|
3049
|
+
*
|
|
3050
|
+
* @param signature - The signature object to assert.
|
|
3051
|
+
*/
|
|
3052
|
+
function assert(signature, options = {}) {
|
|
3053
|
+
const { recovered } = options;
|
|
3054
|
+
if (typeof signature.r === "undefined") throw new MissingPropertiesError({ signature });
|
|
3055
|
+
if (typeof signature.s === "undefined") throw new MissingPropertiesError({ signature });
|
|
3056
|
+
if (recovered && typeof signature.yParity === "undefined") throw new MissingPropertiesError({ signature });
|
|
3057
|
+
if (signature.r < 0n || signature.r > maxUint256) throw new InvalidRError({ value: signature.r });
|
|
3058
|
+
if (signature.s < 0n || signature.s > maxUint256) throw new InvalidSError({ value: signature.s });
|
|
3059
|
+
if (typeof signature.yParity === "number" && signature.yParity !== 0 && signature.yParity !== 1) throw new InvalidYParityError({ value: signature.yParity });
|
|
3060
|
+
}
|
|
3061
|
+
/**
|
|
3062
|
+
* Deserializes a {@link ox#Bytes.Bytes} signature into a structured {@link ox#Signature.Signature}.
|
|
3063
|
+
*
|
|
3064
|
+
* @example
|
|
3065
|
+
* ```ts twoslash
|
|
3066
|
+
* // @noErrors
|
|
3067
|
+
* import { Signature } from 'ox'
|
|
3068
|
+
*
|
|
3069
|
+
* Signature.fromBytes(new Uint8Array([128, 3, 131, ...]))
|
|
3070
|
+
* // @log: { r: 5231...n, s: 3522...n, yParity: 0 }
|
|
3071
|
+
* ```
|
|
3072
|
+
*
|
|
3073
|
+
* @param signature - The serialized signature.
|
|
3074
|
+
* @returns The deserialized {@link ox#Signature.Signature}.
|
|
3075
|
+
*/
|
|
3076
|
+
function fromBytes(signature) {
|
|
3077
|
+
return fromHex(fromBytes$2(signature));
|
|
3078
|
+
}
|
|
3079
|
+
/**
|
|
3080
|
+
* Deserializes a {@link ox#Hex.Hex} signature into a structured {@link ox#Signature.Signature}.
|
|
3081
|
+
*
|
|
3082
|
+
* @example
|
|
3083
|
+
* ```ts twoslash
|
|
3084
|
+
* import { Signature } from 'ox'
|
|
3085
|
+
*
|
|
3086
|
+
* Signature.fromHex('0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c')
|
|
3087
|
+
* // @log: { r: 5231...n, s: 3522...n, yParity: 0 }
|
|
3088
|
+
* ```
|
|
3089
|
+
*
|
|
3090
|
+
* @param serialized - The serialized signature.
|
|
3091
|
+
* @returns The deserialized {@link ox#Signature.Signature}.
|
|
3092
|
+
*/
|
|
3093
|
+
function fromHex(signature) {
|
|
3094
|
+
if (signature.length !== 130 && signature.length !== 132) throw new InvalidSerializedSizeError({ signature });
|
|
3095
|
+
const r = BigInt(slice(signature, 0, 32));
|
|
3096
|
+
const s = BigInt(slice(signature, 32, 64));
|
|
3097
|
+
const yParity = (() => {
|
|
3098
|
+
const yParity = Number(`0x${signature.slice(130)}`);
|
|
3099
|
+
if (Number.isNaN(yParity)) return void 0;
|
|
3100
|
+
try {
|
|
3101
|
+
return vToYParity(yParity);
|
|
3102
|
+
} catch {
|
|
3103
|
+
throw new InvalidYParityError({ value: yParity });
|
|
3104
|
+
}
|
|
3105
|
+
})();
|
|
3106
|
+
if (typeof yParity === "undefined") return {
|
|
3107
|
+
r,
|
|
3108
|
+
s
|
|
3109
|
+
};
|
|
3110
|
+
return {
|
|
3111
|
+
r,
|
|
3112
|
+
s,
|
|
3113
|
+
yParity
|
|
3114
|
+
};
|
|
3115
|
+
}
|
|
3116
|
+
/**
|
|
3117
|
+
* Extracts a {@link ox#Signature.Signature} from an arbitrary object that may include signature properties.
|
|
3118
|
+
*
|
|
3119
|
+
* @example
|
|
3120
|
+
* ```ts twoslash
|
|
3121
|
+
* // @noErrors
|
|
3122
|
+
* import { Signature } from 'ox'
|
|
3123
|
+
*
|
|
3124
|
+
* Signature.extract({
|
|
3125
|
+
* baz: 'barry',
|
|
3126
|
+
* foo: 'bar',
|
|
3127
|
+
* r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
|
|
3128
|
+
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
|
|
3129
|
+
* yParity: 1,
|
|
3130
|
+
* zebra: 'stripes',
|
|
3131
|
+
* })
|
|
3132
|
+
* // @log: {
|
|
3133
|
+
* // @log: r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
|
|
3134
|
+
* // @log: s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
|
|
3135
|
+
* // @log: yParity: 1
|
|
3136
|
+
* // @log: }
|
|
3137
|
+
* ```
|
|
3138
|
+
*
|
|
3139
|
+
* @param value - The arbitrary object to extract the signature from.
|
|
3140
|
+
* @returns The extracted {@link ox#Signature.Signature}.
|
|
3141
|
+
*/
|
|
3142
|
+
function extract(value) {
|
|
3143
|
+
if (typeof value.r === "undefined") return void 0;
|
|
3144
|
+
if (typeof value.s === "undefined") return void 0;
|
|
3145
|
+
return from(value);
|
|
3146
|
+
}
|
|
3147
|
+
/**
|
|
3148
|
+
* 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}.
|
|
3149
|
+
*
|
|
3150
|
+
* @example
|
|
3151
|
+
* ```ts twoslash
|
|
3152
|
+
* import { Signature } from 'ox'
|
|
3153
|
+
*
|
|
3154
|
+
* Signature.from({
|
|
3155
|
+
* r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
|
|
3156
|
+
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
|
|
3157
|
+
* yParity: 1,
|
|
3158
|
+
* })
|
|
3159
|
+
* // @log: {
|
|
3160
|
+
* // @log: r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
|
|
3161
|
+
* // @log: s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
|
|
3162
|
+
* // @log: yParity: 1
|
|
3163
|
+
* // @log: }
|
|
3164
|
+
* ```
|
|
3165
|
+
*
|
|
3166
|
+
* @example
|
|
3167
|
+
* ### From Serialized
|
|
3168
|
+
*
|
|
3169
|
+
* ```ts twoslash
|
|
3170
|
+
* import { Signature } from 'ox'
|
|
3171
|
+
*
|
|
3172
|
+
* Signature.from('0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db801')
|
|
3173
|
+
* // @log: {
|
|
3174
|
+
* // @log: r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
|
|
3175
|
+
* // @log: s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
|
|
3176
|
+
* // @log: yParity: 1,
|
|
3177
|
+
* // @log: }
|
|
3178
|
+
* ```
|
|
3179
|
+
*
|
|
3180
|
+
* @example
|
|
3181
|
+
* ### From Legacy
|
|
3182
|
+
*
|
|
3183
|
+
* ```ts twoslash
|
|
3184
|
+
* import { Signature } from 'ox'
|
|
3185
|
+
*
|
|
3186
|
+
* Signature.from({
|
|
3187
|
+
* r: 47323457007453657207889730243826965761922296599680473886588287015755652701072n,
|
|
3188
|
+
* s: 57228803202727131502949358313456071280488184270258293674242124340113824882788n,
|
|
3189
|
+
* v: 27,
|
|
3190
|
+
* })
|
|
3191
|
+
* // @log: {
|
|
3192
|
+
* // @log: r: 47323457007453657207889730243826965761922296599680473886588287015755652701072n,
|
|
3193
|
+
* // @log: s: 57228803202727131502949358313456071280488184270258293674242124340113824882788n,
|
|
3194
|
+
* // @log: yParity: 0
|
|
3195
|
+
* // @log: }
|
|
3196
|
+
* ```
|
|
3197
|
+
*
|
|
3198
|
+
* @param signature - The signature value to instantiate.
|
|
3199
|
+
* @returns The instantiated {@link ox#Signature.Signature}.
|
|
3200
|
+
*/
|
|
3201
|
+
function from(signature) {
|
|
3202
|
+
const signature_ = (() => {
|
|
3203
|
+
if (typeof signature === "string") return fromHex(signature);
|
|
3204
|
+
if (signature instanceof Uint8Array) return fromBytes(signature);
|
|
3205
|
+
if (typeof signature.r === "string") return fromRpc(signature);
|
|
3206
|
+
if (signature.v) return fromLegacy(signature);
|
|
3207
|
+
return {
|
|
3208
|
+
r: signature.r,
|
|
3209
|
+
s: signature.s,
|
|
3210
|
+
...typeof signature.yParity !== "undefined" ? { yParity: signature.yParity } : {}
|
|
3211
|
+
};
|
|
3212
|
+
})();
|
|
3213
|
+
assert(signature_);
|
|
3214
|
+
return signature_;
|
|
3215
|
+
}
|
|
3216
|
+
/**
|
|
3217
|
+
* Converts a {@link ox#Signature.Legacy} into a {@link ox#Signature.Signature}.
|
|
3218
|
+
*
|
|
3219
|
+
* @example
|
|
3220
|
+
* ```ts twoslash
|
|
3221
|
+
* import { Signature } from 'ox'
|
|
3222
|
+
*
|
|
3223
|
+
* const legacy = Signature.fromLegacy({ r: 1n, s: 2n, v: 28 })
|
|
3224
|
+
* // @log: { r: 1n, s: 2n, yParity: 1 }
|
|
3225
|
+
* ```
|
|
3226
|
+
*
|
|
3227
|
+
* @param signature - The {@link ox#Signature.Legacy} to convert.
|
|
3228
|
+
* @returns The converted {@link ox#Signature.Signature}.
|
|
3229
|
+
*/
|
|
3230
|
+
function fromLegacy(signature) {
|
|
3231
|
+
return {
|
|
3232
|
+
r: signature.r,
|
|
3233
|
+
s: signature.s,
|
|
3234
|
+
yParity: vToYParity(signature.v)
|
|
3235
|
+
};
|
|
3236
|
+
}
|
|
3237
|
+
/**
|
|
3238
|
+
* Converts a {@link ox#Signature.Rpc} into a {@link ox#Signature.Signature}.
|
|
3239
|
+
*
|
|
3240
|
+
* @example
|
|
3241
|
+
* ```ts twoslash
|
|
3242
|
+
* import { Signature } from 'ox'
|
|
3243
|
+
*
|
|
3244
|
+
* const signature = Signature.fromRpc({
|
|
3245
|
+
* r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
|
|
3246
|
+
* s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
|
|
3247
|
+
* yParity: '0x0',
|
|
3248
|
+
* })
|
|
3249
|
+
* ```
|
|
3250
|
+
*
|
|
3251
|
+
* @param signature - The {@link ox#Signature.Rpc} to convert.
|
|
3252
|
+
* @returns The converted {@link ox#Signature.Signature}.
|
|
3253
|
+
*/
|
|
3254
|
+
function fromRpc(signature) {
|
|
3255
|
+
const yParity = (() => {
|
|
3256
|
+
const v = signature.v ? Number(signature.v) : void 0;
|
|
3257
|
+
let yParity = signature.yParity ? Number(signature.yParity) : void 0;
|
|
3258
|
+
if (typeof v === "number" && typeof yParity !== "number") yParity = vToYParity(v);
|
|
3259
|
+
if (typeof yParity !== "number") throw new InvalidYParityError({ value: signature.yParity });
|
|
3260
|
+
return yParity;
|
|
3261
|
+
})();
|
|
3262
|
+
return {
|
|
3263
|
+
r: BigInt(signature.r),
|
|
3264
|
+
s: BigInt(signature.s),
|
|
3265
|
+
yParity
|
|
3266
|
+
};
|
|
3267
|
+
}
|
|
3268
|
+
/**
|
|
3269
|
+
* Converts a {@link ox#Signature.Tuple} to a {@link ox#Signature.Signature}.
|
|
3270
|
+
*
|
|
3271
|
+
* @example
|
|
3272
|
+
* ```ts twoslash
|
|
3273
|
+
* import { Signature } from 'ox'
|
|
3274
|
+
*
|
|
3275
|
+
* const signature = Signature.fromTuple(['0x01', '0x7b', '0x1c8'])
|
|
3276
|
+
* // @log: {
|
|
3277
|
+
* // @log: r: 123n,
|
|
3278
|
+
* // @log: s: 456n,
|
|
3279
|
+
* // @log: yParity: 1,
|
|
3280
|
+
* // @log: }
|
|
3281
|
+
* ```
|
|
3282
|
+
*
|
|
3283
|
+
* @param tuple - The {@link ox#Signature.Tuple} to convert.
|
|
3284
|
+
* @returns The {@link ox#Signature.Signature}.
|
|
3285
|
+
*/
|
|
3286
|
+
function fromTuple(tuple) {
|
|
3287
|
+
const [yParity, r, s] = tuple;
|
|
3288
|
+
return from({
|
|
3289
|
+
r: r === "0x" ? 0n : BigInt(r),
|
|
3290
|
+
s: s === "0x" ? 0n : BigInt(s),
|
|
3291
|
+
yParity: yParity === "0x" ? 0 : Number(yParity)
|
|
3292
|
+
});
|
|
3293
|
+
}
|
|
3294
|
+
/**
|
|
3295
|
+
* Serializes a {@link ox#Signature.Signature} to {@link ox#Hex.Hex}.
|
|
3296
|
+
*
|
|
3297
|
+
* @example
|
|
3298
|
+
* ```ts twoslash
|
|
3299
|
+
* import { Signature } from 'ox'
|
|
3300
|
+
*
|
|
3301
|
+
* const signature = Signature.toHex({
|
|
3302
|
+
* r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
|
|
3303
|
+
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
|
|
3304
|
+
* yParity: 1
|
|
3305
|
+
* })
|
|
3306
|
+
* // @log: '0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c'
|
|
3307
|
+
* ```
|
|
3308
|
+
*
|
|
3309
|
+
* @param signature - The signature to serialize.
|
|
3310
|
+
* @returns The serialized signature.
|
|
3311
|
+
*/
|
|
3312
|
+
function toHex(signature) {
|
|
3313
|
+
assert(signature);
|
|
3314
|
+
const r = signature.r;
|
|
3315
|
+
const s = signature.s;
|
|
3316
|
+
return concat(fromNumber(r, { size: 32 }), fromNumber(s, { size: 32 }), typeof signature.yParity === "number" ? fromNumber(yParityToV(signature.yParity), { size: 1 }) : "0x");
|
|
3317
|
+
}
|
|
3318
|
+
/**
|
|
3319
|
+
* Converts a {@link ox#Signature.Signature} into a {@link ox#Signature.Rpc}.
|
|
3320
|
+
*
|
|
3321
|
+
* @example
|
|
3322
|
+
* ```ts twoslash
|
|
3323
|
+
* import { Signature } from 'ox'
|
|
3324
|
+
*
|
|
3325
|
+
* const signature = Signature.toRpc({
|
|
3326
|
+
* r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
|
|
3327
|
+
* s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
|
|
3328
|
+
* yParity: 1
|
|
3329
|
+
* })
|
|
3330
|
+
* ```
|
|
3331
|
+
*
|
|
3332
|
+
* @param signature - The {@link ox#Signature.Signature} to convert.
|
|
3333
|
+
* @returns The converted {@link ox#Signature.Rpc}.
|
|
3334
|
+
*/
|
|
3335
|
+
function toRpc(signature) {
|
|
3336
|
+
const { r, s, yParity } = signature;
|
|
3337
|
+
return {
|
|
3338
|
+
r: fromNumber(r, { size: 32 }),
|
|
3339
|
+
s: fromNumber(s, { size: 32 }),
|
|
3340
|
+
yParity: yParity === 0 ? "0x0" : "0x1"
|
|
3341
|
+
};
|
|
3342
|
+
}
|
|
3343
|
+
/**
|
|
3344
|
+
* 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.
|
|
3345
|
+
*
|
|
3346
|
+
* @example
|
|
3347
|
+
* ```ts twoslash
|
|
3348
|
+
* import { Signature } from 'ox'
|
|
3349
|
+
*
|
|
3350
|
+
* const signatureTuple = Signature.toTuple({
|
|
3351
|
+
* r: 123n,
|
|
3352
|
+
* s: 456n,
|
|
3353
|
+
* yParity: 1,
|
|
3354
|
+
* })
|
|
3355
|
+
* // @log: [yParity: '0x01', r: '0x7b', s: '0x1c8']
|
|
3356
|
+
* ```
|
|
3357
|
+
*
|
|
3358
|
+
* @param signature - The {@link ox#Signature.Signature} to convert.
|
|
3359
|
+
* @returns The {@link ox#Signature.Tuple}.
|
|
3360
|
+
*/
|
|
3361
|
+
function toTuple(signature) {
|
|
3362
|
+
const { r, s, yParity } = signature;
|
|
3363
|
+
return [
|
|
3364
|
+
yParity ? "0x01" : "0x",
|
|
3365
|
+
r === 0n ? "0x" : trimLeft$1(fromNumber(r)),
|
|
3366
|
+
s === 0n ? "0x" : trimLeft$1(fromNumber(s))
|
|
3367
|
+
];
|
|
3368
|
+
}
|
|
3369
|
+
/**
|
|
3370
|
+
* Converts a ECDSA `v` value to a `yParity` value.
|
|
3371
|
+
*
|
|
3372
|
+
* @example
|
|
3373
|
+
* ```ts twoslash
|
|
3374
|
+
* import { Signature } from 'ox'
|
|
3375
|
+
*
|
|
3376
|
+
* const yParity = Signature.vToYParity(28)
|
|
3377
|
+
* // @log: 1
|
|
3378
|
+
* ```
|
|
3379
|
+
*
|
|
3380
|
+
* @param v - The ECDSA `v` value to convert.
|
|
3381
|
+
* @returns The `yParity` value.
|
|
3382
|
+
*/
|
|
3383
|
+
function vToYParity(v) {
|
|
3384
|
+
if (v === 0 || v === 27) return 0;
|
|
3385
|
+
if (v === 1 || v === 28) return 1;
|
|
3386
|
+
if (v >= 35) return v % 2 === 0 ? 1 : 0;
|
|
3387
|
+
throw new InvalidVError({ value: v });
|
|
3388
|
+
}
|
|
3389
|
+
/**
|
|
3390
|
+
* Converts a ECDSA `v` value to a `yParity` value.
|
|
3391
|
+
*
|
|
3392
|
+
* @example
|
|
3393
|
+
* ```ts twoslash
|
|
3394
|
+
* import { Signature } from 'ox'
|
|
3395
|
+
*
|
|
3396
|
+
* const v = Signature.yParityToV(1)
|
|
3397
|
+
* // @log: 28
|
|
3398
|
+
* ```
|
|
3399
|
+
*
|
|
3400
|
+
* @param yParity - The ECDSA `yParity` value to convert.
|
|
3401
|
+
* @returns The `v` value.
|
|
3402
|
+
*/
|
|
3403
|
+
function yParityToV(yParity) {
|
|
3404
|
+
if (yParity === 0) return 27;
|
|
3405
|
+
if (yParity === 1) return 28;
|
|
3406
|
+
throw new InvalidYParityError({ value: yParity });
|
|
3407
|
+
}
|
|
3408
|
+
/** Thrown when the serialized signature is of an invalid size. */
|
|
3409
|
+
var InvalidSerializedSizeError = class extends BaseError {
|
|
3410
|
+
constructor({ signature }) {
|
|
3411
|
+
super(`Value \`${signature}\` is an invalid signature size.`, { metaMessages: ["Expected: 64 bytes or 65 bytes.", `Received ${size(from$6(signature))} bytes.`] });
|
|
3412
|
+
Object.defineProperty(this, "name", {
|
|
3413
|
+
enumerable: true,
|
|
3414
|
+
configurable: true,
|
|
3415
|
+
writable: true,
|
|
3416
|
+
value: "Signature.InvalidSerializedSizeError"
|
|
3417
|
+
});
|
|
3418
|
+
}
|
|
3419
|
+
};
|
|
3420
|
+
/** Thrown when the signature is missing either an `r`, `s`, or `yParity` property. */
|
|
3421
|
+
var MissingPropertiesError = class extends BaseError {
|
|
3422
|
+
constructor({ signature }) {
|
|
3423
|
+
super(`Signature \`${stringify(signature)}\` is missing either an \`r\`, \`s\`, or \`yParity\` property.`);
|
|
3424
|
+
Object.defineProperty(this, "name", {
|
|
3425
|
+
enumerable: true,
|
|
3426
|
+
configurable: true,
|
|
3427
|
+
writable: true,
|
|
3428
|
+
value: "Signature.MissingPropertiesError"
|
|
3429
|
+
});
|
|
3430
|
+
}
|
|
3431
|
+
};
|
|
3432
|
+
/** Thrown when the signature has an invalid `r` value. */
|
|
3433
|
+
var InvalidRError = class extends BaseError {
|
|
3434
|
+
constructor({ value }) {
|
|
3435
|
+
super(`Value \`${value}\` is an invalid r value. r must be a positive integer less than 2^256.`);
|
|
3436
|
+
Object.defineProperty(this, "name", {
|
|
3437
|
+
enumerable: true,
|
|
3438
|
+
configurable: true,
|
|
3439
|
+
writable: true,
|
|
3440
|
+
value: "Signature.InvalidRError"
|
|
3441
|
+
});
|
|
3442
|
+
}
|
|
3443
|
+
};
|
|
3444
|
+
/** Thrown when the signature has an invalid `s` value. */
|
|
3445
|
+
var InvalidSError = class extends BaseError {
|
|
3446
|
+
constructor({ value }) {
|
|
3447
|
+
super(`Value \`${value}\` is an invalid s value. s must be a positive integer less than 2^256.`);
|
|
3448
|
+
Object.defineProperty(this, "name", {
|
|
3449
|
+
enumerable: true,
|
|
3450
|
+
configurable: true,
|
|
3451
|
+
writable: true,
|
|
3452
|
+
value: "Signature.InvalidSError"
|
|
3453
|
+
});
|
|
3454
|
+
}
|
|
3455
|
+
};
|
|
3456
|
+
/** Thrown when the signature has an invalid `yParity` value. */
|
|
3457
|
+
var InvalidYParityError = class extends BaseError {
|
|
3458
|
+
constructor({ value }) {
|
|
3459
|
+
super(`Value \`${value}\` is an invalid y-parity value. Y-parity must be 0 or 1.`);
|
|
3460
|
+
Object.defineProperty(this, "name", {
|
|
3461
|
+
enumerable: true,
|
|
3462
|
+
configurable: true,
|
|
3463
|
+
writable: true,
|
|
3464
|
+
value: "Signature.InvalidYParityError"
|
|
3465
|
+
});
|
|
3466
|
+
}
|
|
3467
|
+
};
|
|
3468
|
+
/** Thrown when the signature has an invalid `v` value. */
|
|
3469
|
+
var InvalidVError = class extends BaseError {
|
|
3470
|
+
constructor({ value }) {
|
|
3471
|
+
super(`Value \`${value}\` is an invalid v value. v must be 27, 28 or >=35.`);
|
|
3472
|
+
Object.defineProperty(this, "name", {
|
|
3473
|
+
enumerable: true,
|
|
3474
|
+
configurable: true,
|
|
3475
|
+
writable: true,
|
|
3476
|
+
value: "Signature.InvalidVError"
|
|
3477
|
+
});
|
|
3478
|
+
}
|
|
3479
|
+
};
|
|
3480
|
+
//#endregion
|
|
3481
|
+
//#region node_modules/.pnpm/ox@0.14.7_typescript@5.9.3_zod@4.3.6/node_modules/ox/_esm/core/Secp256k1.js
|
|
3482
|
+
/**
|
|
3483
|
+
* Recovers the signing address from the signed payload and signature.
|
|
3484
|
+
*
|
|
3485
|
+
* @example
|
|
3486
|
+
* ```ts twoslash
|
|
3487
|
+
* import { Secp256k1 } from 'ox'
|
|
3488
|
+
*
|
|
3489
|
+
* const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey: '0x...' })
|
|
3490
|
+
*
|
|
3491
|
+
* const address = Secp256k1.recoverAddress({ // [!code focus]
|
|
3492
|
+
* payload: '0xdeadbeef', // [!code focus]
|
|
3493
|
+
* signature, // [!code focus]
|
|
3494
|
+
* }) // [!code focus]
|
|
3495
|
+
* ```
|
|
3496
|
+
*
|
|
3497
|
+
* @param options - The recovery options.
|
|
3498
|
+
* @returns The recovered address.
|
|
3499
|
+
*/
|
|
3500
|
+
function recoverAddress(options) {
|
|
3501
|
+
return fromPublicKey(recoverPublicKey(options));
|
|
3502
|
+
}
|
|
3503
|
+
/**
|
|
3504
|
+
* Recovers the signing public key from the signed payload and signature.
|
|
3505
|
+
*
|
|
3506
|
+
* @example
|
|
3507
|
+
* ```ts twoslash
|
|
3508
|
+
* import { Secp256k1 } from 'ox'
|
|
3509
|
+
*
|
|
3510
|
+
* const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey: '0x...' })
|
|
3511
|
+
*
|
|
3512
|
+
* const publicKey = Secp256k1.recoverPublicKey({ // [!code focus]
|
|
3513
|
+
* payload: '0xdeadbeef', // [!code focus]
|
|
3514
|
+
* signature, // [!code focus]
|
|
3515
|
+
* }) // [!code focus]
|
|
3516
|
+
* ```
|
|
3517
|
+
*
|
|
3518
|
+
* @param options - The recovery options.
|
|
3519
|
+
* @returns The recovered public key.
|
|
3520
|
+
*/
|
|
3521
|
+
function recoverPublicKey(options) {
|
|
3522
|
+
const { payload, signature } = options;
|
|
3523
|
+
const { r, s, yParity } = signature;
|
|
3524
|
+
return from$4(new secp256k1.Signature(BigInt(r), BigInt(s)).addRecoveryBit(yParity).recoverPublicKey(from$6(payload).substring(2)));
|
|
3525
|
+
}
|
|
3526
|
+
/**
|
|
3527
|
+
* Verifies a payload was signed by the provided address.
|
|
3528
|
+
*
|
|
3529
|
+
* @example
|
|
3530
|
+
* ### Verify with Ethereum Address
|
|
3531
|
+
*
|
|
3532
|
+
* ```ts twoslash
|
|
3533
|
+
* import { Secp256k1 } from 'ox'
|
|
3534
|
+
*
|
|
3535
|
+
* const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey: '0x...' })
|
|
3536
|
+
*
|
|
3537
|
+
* const verified = Secp256k1.verify({ // [!code focus]
|
|
3538
|
+
* address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', // [!code focus]
|
|
3539
|
+
* payload: '0xdeadbeef', // [!code focus]
|
|
3540
|
+
* signature, // [!code focus]
|
|
3541
|
+
* }) // [!code focus]
|
|
3542
|
+
* ```
|
|
3543
|
+
*
|
|
3544
|
+
* @example
|
|
3545
|
+
* ### Verify with Public Key
|
|
3546
|
+
*
|
|
3547
|
+
* ```ts twoslash
|
|
3548
|
+
* import { Secp256k1 } from 'ox'
|
|
3549
|
+
*
|
|
3550
|
+
* const privateKey = '0x...'
|
|
3551
|
+
* const publicKey = Secp256k1.getPublicKey({ privateKey })
|
|
3552
|
+
* const signature = Secp256k1.sign({ payload: '0xdeadbeef', privateKey })
|
|
3553
|
+
*
|
|
3554
|
+
* const verified = Secp256k1.verify({ // [!code focus]
|
|
3555
|
+
* publicKey, // [!code focus]
|
|
3556
|
+
* payload: '0xdeadbeef', // [!code focus]
|
|
3557
|
+
* signature, // [!code focus]
|
|
3558
|
+
* }) // [!code focus]
|
|
3559
|
+
* ```
|
|
3560
|
+
*
|
|
3561
|
+
* @param options - The verification options.
|
|
3562
|
+
* @returns Whether the payload was signed by the provided address.
|
|
3563
|
+
*/
|
|
3564
|
+
function verify(options) {
|
|
3565
|
+
const { address, hash, payload, publicKey, signature } = options;
|
|
3566
|
+
if (address) return isEqual(address, recoverAddress({
|
|
3567
|
+
payload,
|
|
3568
|
+
signature
|
|
3569
|
+
}));
|
|
3570
|
+
return secp256k1.verify(signature, from$5(payload), toBytes(publicKey), ...hash ? [{
|
|
3571
|
+
prehash: true,
|
|
3572
|
+
lowS: true
|
|
3573
|
+
}] : []);
|
|
3574
|
+
}
|
|
3575
|
+
//#endregion
|
|
3576
|
+
//#region node_modules/.pnpm/viem@2.47.6_typescript@5.9.3_zod@4.3.6/node_modules/viem/_esm/actions/wallet/sendRawTransactionSync.js
|
|
3577
|
+
/**
|
|
3578
|
+
* Sends a **signed** transaction to the network synchronously,
|
|
3579
|
+
* and waits for the transaction to be included in a block.
|
|
3580
|
+
*
|
|
3581
|
+
* - Docs: https://viem.sh/docs/actions/wallet/sendRawTransactionSync
|
|
3582
|
+
* - JSON-RPC Method: [`eth_sendRawTransactionSync`](https://eips.ethereum.org/EIPS/eip-7966)
|
|
3583
|
+
*
|
|
3584
|
+
* @param client - Client to use
|
|
3585
|
+
* @param parameters - {@link SendRawTransactionParameters}
|
|
3586
|
+
* @returns The transaction receipt. {@link SendRawTransactionSyncReturnType}
|
|
3587
|
+
*
|
|
3588
|
+
* @example
|
|
3589
|
+
* import { createWalletClient, custom } from 'viem'
|
|
3590
|
+
* import { mainnet } from 'viem/chains'
|
|
3591
|
+
* import { sendRawTransactionSync } from 'viem/wallet'
|
|
3592
|
+
*
|
|
3593
|
+
* const client = createWalletClient({
|
|
3594
|
+
* chain: mainnet,
|
|
3595
|
+
* transport: custom(window.ethereum),
|
|
3596
|
+
* })
|
|
3597
|
+
*
|
|
3598
|
+
* const receipt = await sendRawTransactionSync(client, {
|
|
3599
|
+
* serializedTransaction: '0x02f850018203118080825208808080c080a04012522854168b27e5dc3d5839bab5e6b39e1a0ffd343901ce1622e3d64b48f1a04e00902ae0502c4728cbf12156290df99c3ed7de85b1dbfe20b5c36931733a33'
|
|
3600
|
+
* })
|
|
3601
|
+
*/
|
|
3602
|
+
async function sendRawTransactionSync(client, { serializedTransaction, throwOnReceiptRevert, timeout }) {
|
|
3603
|
+
const receipt = await client.request({
|
|
3604
|
+
method: "eth_sendRawTransactionSync",
|
|
3605
|
+
params: timeout ? [serializedTransaction, timeout] : [serializedTransaction]
|
|
3606
|
+
}, { retryCount: 0 });
|
|
3607
|
+
const formatted = (client.chain?.formatters?.transactionReceipt?.format || formatTransactionReceipt)(receipt);
|
|
3608
|
+
if (formatted.status === "reverted" && throwOnReceiptRevert) throw new TransactionReceiptRevertedError({ receipt: formatted });
|
|
3609
|
+
return formatted;
|
|
3610
|
+
}
|
|
3611
|
+
//#endregion
|
|
3612
|
+
export { recoverAuthorizationAddress as $, validate$1 as A, fillTransaction as B, fromPublicKey as C, toHex$2 as D, toBytes as E, readContract as F, estimateMaxPriorityFeePerGas as G, getTransactionError as H, formatLog as I, defineBlock as J, getGasPrice as K, estimateGas as L, formatTransactionReceipt as M, receiptStatuses as N, keccak256 as O, sendRawTransaction as P, BlockNotFoundError as Q, defaultParameters as R, checksum as S, validate as T, getTransactionCount as U, getChainId as V, estimateFeesPerGas as W, defineTransaction as X, formatBlock as Y, formatTransaction as Z, decode as _, assert as a, create as b, fromHex as c, toHex as d, recoverAddress$1 as et, toRpc as f, toHex$1 as g, fromHex$1 as h, verify as i, defineTransactionReceipt as j, sha256 as k, fromRpc as l, yParityToV as m, recoverAddress as n, getAction as nt, extract as o, toTuple as p, getBlock as q, recoverPublicKey as r, parseAbiParameters as rt, from as s, sendRawTransactionSync as t, getContractError as tt, fromTuple as u, encode as v, isEqual as w, assert$1 as x, from$2 as y, prepareTransactionRequest as z };
|