@bosonprotocol/x402-evm 0.1.0-alpha-0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/adapters/viem-relayer.ts","../../../src/internal/web3lib-stub.ts"],"names":["InsufficientFundsError","ExecutionRevertedError","ContractFunctionRevertedError","RawContractError","BaseError"],"mappings":";;;;;AA6BO,IAAM,kBAAA,GAAN,cAAiC,KAAA,CAAM;AAAA,EAE5C,WAAA,CAAY,IAAA,EAA8B,OAAA,EAAiB,OAAA,EAA+B;AACxF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,oBAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AACF;AASA,IAAM,0BAAA,GAA6B,GAAA;AAqB5B,SAAS,6BAA6B,MAAA,EAY1B;AACjB,EAAA,MAAM,EAAE,YAAA,EAAc,YAAA,EAAc,OAAA,EAAQ,GAAI,MAAA;AAChD,EAAA,MAAM,gBAAA,GAAmB,OAAO,gBAAA,IAAoB,0BAAA;AACpD,EAAA,IAAI,YAAA,CAAa,KAAA,IAAS,YAAA,CAAa,KAAA,CAAM,OAAO,OAAA,EAAS;AAC3D,IAAA,MAAM,IAAI,kBAAA;AAAA,MACR,gBAAA;AAAA,MACA,CAAA,uBAAA,EAA0B,YAAA,CAAa,KAAA,CAAM,EAAE,qCAAqC,OAAO,CAAA,CAAA;AAAA,KAC7F;AAAA,EACF;AACA,EAAA,IAAI,YAAA,CAAa,KAAA,IAAS,YAAA,CAAa,KAAA,CAAM,OAAO,OAAA,EAAS;AAC3D,IAAA,MAAM,IAAI,kBAAA;AAAA,MACR,gBAAA;AAAA,MACA,CAAA,uBAAA,EAA0B,YAAA,CAAa,KAAA,CAAM,EAAE,qCAAqC,OAAO,CAAA,CAAA;AAAA,KAC7F;AAAA,EACF;AACA,EAAA,OAAO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,SAAA,EAAW,MAAM,CAAC,CAAA;AAAA,IACzD,uBAAuB,MAAM,OAAA,CAAQ,OAAO,WAAA,CAAY,SAAA,EAAW,uBAAuB,CAAC,CAAA;AAAA,IAC3F,kBAAkB,MAAM,OAAA,CAAQ,OAAO,WAAA,CAAY,SAAA,EAAW,kBAAkB,CAAC;AAAA,GACnF;AACF","file":"index.js","sourcesContent":["// Viem-backed `Web3LibAdapter` for relayer / facilitator-style flows where\n// a configured `WalletClient` submits transactions on a buyer's behalf.\n//\n// `@bosonprotocol/core-sdk`'s `MetaTxMixin.executeMetaTransaction(...)`\n// (the unified entrypoint that routes between\n// `executeMetaTransaction` and `executeMetaTransactionWithTokenTransferAuthorization`\n// based on whether `transferAuthorizations` is provided) drives every\n// on-chain side-effect through the SDK's `Web3LibAdapter`. This adapter\n// wraps a viem `WalletClient` (for writes) plus a `PublicClient`\n// (for reads / receipt polling) so the SDK can run end-to-end against\n// viem-configured transports.\n//\n// The sibling `client/src/internal/web3lib-adapter.ts` wraps a sign-only\n// `Signer` for the buyer path; this is the symmetric write-only variant\n// for the relayer path. Future work may consolidate them behind a\n// single factory.\n\nimport type { Web3LibAdapter } from \"@bosonprotocol/common\";\nimport {\n BaseError,\n ContractFunctionRevertedError,\n ExecutionRevertedError,\n InsufficientFundsError,\n RawContractError,\n type PublicClient,\n type WalletClient,\n} from \"viem\";\n\n/** Tagged error thrown by the adapter when `walletClient.sendTransaction` rejects. */\nexport class RelayerSubmitError extends Error {\n readonly code: RelayerSubmitErrorCode;\n constructor(code: RelayerSubmitErrorCode, message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"RelayerSubmitError\";\n this.code = code;\n }\n}\n\n/** Stable identifiers callers can map to their own error-code vocabulary. */\nexport type RelayerSubmitErrorCode =\n | \"INSUFFICIENT_FUNDS_FOR_GAS\"\n | \"ONCHAIN_REVERT\"\n | \"INTERNAL_ERROR\";\n\n/** Default deadline for `wait()` when the caller does not override. */\nconst DEFAULT_RECEIPT_TIMEOUT_MS = 60_000;\n\n/**\n * Build the `Web3LibAdapter` that `@bosonprotocol/core-sdk`'s `CoreSDK`\n * accepts for relayer-driven flows.\n *\n * - Writes flow through `walletClient.sendTransaction`; viem errors are\n * re-thrown as a tagged `RelayerSubmitError` so the caller can keep\n * precise classification (insufficient gas funds vs. on-chain revert\n * vs. transport failure).\n * - Reads (`call`, `getBalance`, `estimateGas`, `getTransactionReceipt`)\n * flow through `publicClient`.\n * - `send` rejects: the relayer never signs typed data through the\n * adapter (the buyer already signed off-chain).\n *\n * If either client carries a `chain` (viem populates it when the client\n * was built with an explicit chain) the factory cross-checks its id\n * against the supplied `chainId` and rejects mismatches up-front, so a\n * misconfigured pair fails loudly rather than silently targeting the\n * wrong network.\n */\nexport function walletClientToWeb3LibAdapter(params: {\n walletClient: WalletClient;\n publicClient: PublicClient;\n chainId: number;\n /**\n * Per-call timeout (ms) passed to `publicClient.waitForTransactionReceipt`\n * inside the adapter's `wait()` method, so callers that route through\n * core-sdk's `TransactionResponse.wait()` don't hang indefinitely on a\n * stalled RPC. Defaults to 60s. Direct callers that drive their own\n * receipt polling can ignore it.\n */\n receiptTimeoutMs?: number;\n}): Web3LibAdapter {\n const { walletClient, publicClient, chainId } = params;\n const receiptTimeoutMs = params.receiptTimeoutMs ?? DEFAULT_RECEIPT_TIMEOUT_MS;\n if (walletClient.chain && walletClient.chain.id !== chainId) {\n throw new RelayerSubmitError(\n \"INTERNAL_ERROR\",\n `walletClient.chain.id (${walletClient.chain.id}) does not match adapter chainId (${chainId})`,\n );\n }\n if (publicClient.chain && publicClient.chain.id !== chainId) {\n throw new RelayerSubmitError(\n \"INTERNAL_ERROR\",\n `publicClient.chain.id (${publicClient.chain.id}) does not match adapter chainId (${chainId})`,\n );\n }\n return {\n uuid: \"x402-evm:viem-relayer-adapter\",\n getSignerAddress: async () => {\n const account = walletClient.account;\n if (!account) {\n throw new RelayerSubmitError(\n \"INTERNAL_ERROR\",\n \"walletClient has no account; cannot resolve signer address\",\n );\n }\n return account.address;\n },\n isSignerContract: async () => false,\n getChainId: async () => chainId,\n getBalance: async (addressOrName) => {\n const balance = await publicClient.getBalance({ address: addressOrName as `0x${string}` });\n return balance;\n },\n estimateGas: async (req) => {\n const account = walletClient.account;\n const gas = await publicClient.estimateGas({\n account: account ?? undefined,\n to: req.to as `0x${string}` | undefined,\n data: req.data as `0x${string}` | undefined,\n value: req.value === undefined ? undefined : BigInt(req.value.toString()),\n });\n return gas;\n },\n sendTransaction: async (req) => {\n const account = walletClient.account;\n if (!account) {\n throw new RelayerSubmitError(\n \"INTERNAL_ERROR\",\n \"walletClient has no account; cannot send transaction\",\n );\n }\n let hash: `0x${string}`;\n try {\n hash = await walletClient.sendTransaction({\n account,\n chain: walletClient.chain ?? null,\n to: req.to as `0x${string}` | undefined,\n data: req.data as `0x${string}` | undefined,\n value: req.value === undefined ? 0n : BigInt(req.value.toString()),\n });\n } catch (e) {\n throw classifyViemSendError(e);\n }\n return {\n hash,\n wait: async (confirmations?: number) => {\n const receipt = await publicClient.waitForTransactionReceipt({\n hash,\n confirmations,\n timeout: receiptTimeoutMs,\n });\n return mapReceipt(receipt);\n },\n };\n },\n call: async (req) => {\n const result = await publicClient.call({\n to: req.to as `0x${string}` | undefined,\n data: req.data as `0x${string}` | undefined,\n });\n return result.data ?? \"0x\";\n },\n send: async (method) => {\n throw new RelayerSubmitError(\n \"INTERNAL_ERROR\",\n `x402-evm: relayer adapter does not support RPC method '${method}'; the relayer never signs typed data`,\n );\n },\n getTransactionReceipt: async (txHash) => {\n const receipt = await publicClient.getTransactionReceipt({ hash: txHash as `0x${string}` });\n return mapReceipt(receipt);\n },\n getCurrentTimeMs: async () => Date.now(),\n };\n}\n\n/**\n * Normalize a viem `TransactionReceipt` into the SDK's `TransactionReceipt`\n * shape from `@bosonprotocol/common`. viem's logs carry extra fields the\n * SDK doesn't reference; we strip them so the adapter returns exactly the\n * shape the contract is typed against (and keep both\n * `sendTransaction().wait()` and `getTransactionReceipt(...)` paths from\n * drifting).\n */\nfunction mapReceipt(receipt: Awaited<ReturnType<PublicClient[\"getTransactionReceipt\"]>>) {\n return {\n from: receipt.from,\n to: receipt.to ?? \"\",\n status: receipt.status === \"success\" ? 1 : 0,\n logs: receipt.logs.map((log) => ({ data: log.data, topics: [...log.topics] })),\n transactionHash: receipt.transactionHash,\n effectiveGasPrice: receipt.effectiveGasPrice,\n blockNumber: Number(receipt.blockNumber),\n gasUsed: receipt.gasUsed,\n };\n}\n\n/** Classify a viem error thrown by `walletClient.sendTransaction`. */\nexport function classifyViemSendError(e: unknown): RelayerSubmitError {\n const reason =\n e instanceof Error ? `sendTransaction failed: ${e.message}` : \"sendTransaction failed\";\n\n if (hasViemCause(e, InsufficientFundsError)) {\n return new RelayerSubmitError(\"INSUFFICIENT_FUNDS_FOR_GAS\", reason, { cause: e });\n }\n if (\n hasViemCause(e, ExecutionRevertedError) ||\n hasViemCause(e, ContractFunctionRevertedError) ||\n hasViemCause(e, RawContractError)\n ) {\n return new RelayerSubmitError(\"ONCHAIN_REVERT\", reason, { cause: e });\n }\n return new RelayerSubmitError(\"INTERNAL_ERROR\", reason, { cause: e });\n}\n\nfunction hasViemCause<T extends abstract new (...args: never[]) => Error>(\n e: unknown,\n ctor: T,\n): boolean {\n if (e instanceof ctor) return true;\n if (!(e instanceof BaseError)) return false;\n return e.walk((err) => err instanceof ctor) !== null;\n}\n","// Calldata-only `Web3LibAdapter` for the calldata-builder modules.\n//\n// Core-sdk's `signMetaTx` calls `web3Lib.getSignerAddress()` even in\n// `returnTypedDataToSign: true` mode to fill the message's `from` field.\n// We return a deterministic dummy address; the typed-data message is\n// discarded and only `{ functionName, functionSignature }` is consumed.\n//\n// All signing and transaction methods reject so the stub fails loudly if\n// it ever leaks into a path that needs more than typed-data construction.\n\nimport type { Web3LibAdapter } from \"@bosonprotocol/common\";\n\nconst DUMMY_SIGNER_ADDRESS = \"0x0000000000000000000000000000000000000001\";\n\nfunction unreachable(callerTag: string, method: string): Error {\n return new Error(\n `${callerTag}: stub Web3LibAdapter.${method}() should never be called. ` +\n \"If you see this, core-sdk changed its typed-data-only behavior.\",\n );\n}\n\nexport function createCalldataOnlyWeb3LibAdapter(callerTag: string): Web3LibAdapter {\n return {\n uuid: `${callerTag}:stub`,\n getSignerAddress: () => Promise.resolve(DUMMY_SIGNER_ADDRESS),\n isSignerContract: () => Promise.resolve(false),\n getChainId: () => Promise.reject(unreachable(callerTag, \"getChainId\")),\n getBalance: () => Promise.reject(unreachable(callerTag, \"getBalance\")),\n estimateGas: () => Promise.reject(unreachable(callerTag, \"estimateGas\")),\n sendTransaction: () => Promise.reject(unreachable(callerTag, \"sendTransaction\")),\n call: () => Promise.reject(unreachable(callerTag, \"call\")),\n send: () => Promise.reject(unreachable(callerTag, \"send\")),\n getTransactionReceipt: () => Promise.reject(unreachable(callerTag, \"getTransactionReceipt\")),\n getCurrentTimeMs: () => Promise.reject(unreachable(callerTag, \"getCurrentTimeMs\")),\n };\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { Hex, BosonMetaTx } from '@bosonprotocol/x402-core/schemes/escrow';
2
+
3
+ /** Encode a BosonMetaTx as the wire-format Hex for `signedPayload`. */
4
+ declare function encodeSignedPayload(metaTx: BosonMetaTx): Hex;
5
+ /** Decode the wire-format Hex back into a BosonMetaTx. */
6
+ declare function decodeSignedPayload(signedPayload: Hex): BosonMetaTx;
7
+
8
+ export { decodeSignedPayload, encodeSignedPayload };
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ var viem = require('viem');
4
+
5
+ // src/codec/signed-payload.ts
6
+ var SIGNED_PAYLOAD_ABI = [
7
+ { name: "from", type: "address" },
8
+ { name: "functionName", type: "string" },
9
+ { name: "functionSignature", type: "bytes" },
10
+ { name: "nonce", type: "uint256" },
11
+ { name: "v", type: "uint8" },
12
+ { name: "r", type: "bytes32" },
13
+ { name: "s", type: "bytes32" }
14
+ ];
15
+ function encodeSignedPayload(metaTx) {
16
+ return viem.encodeAbiParameters(SIGNED_PAYLOAD_ABI, [
17
+ metaTx.from,
18
+ metaTx.functionName,
19
+ metaTx.functionSignature,
20
+ BigInt(metaTx.nonce),
21
+ metaTx.sig.v,
22
+ metaTx.sig.r,
23
+ metaTx.sig.s
24
+ ]);
25
+ }
26
+ function decodeSignedPayload(signedPayload) {
27
+ const [from, functionName, functionSignature, nonce, v, r, s] = viem.decodeAbiParameters(
28
+ SIGNED_PAYLOAD_ABI,
29
+ signedPayload
30
+ );
31
+ return {
32
+ from,
33
+ functionName,
34
+ functionSignature,
35
+ nonce: nonce.toString(),
36
+ sig: { v: Number(v), r, s }
37
+ };
38
+ }
39
+
40
+ exports.decodeSignedPayload = decodeSignedPayload;
41
+ exports.encodeSignedPayload = encodeSignedPayload;
42
+ //# sourceMappingURL=index.js.map
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/codec/signed-payload.ts"],"names":["encodeAbiParameters","decodeAbiParameters"],"mappings":";;;;;AAaA,IAAM,kBAAA,GAA8C;AAAA,EAClD,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,SAAA,EAAU;AAAA,EAChC,EAAE,IAAA,EAAM,cAAA,EAAgB,IAAA,EAAM,QAAA,EAAS;AAAA,EACvC,EAAE,IAAA,EAAM,mBAAA,EAAqB,IAAA,EAAM,OAAA,EAAQ;AAAA,EAC3C,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,SAAA,EAAU;AAAA,EACjC,EAAE,IAAA,EAAM,GAAA,EAAK,IAAA,EAAM,OAAA,EAAQ;AAAA,EAC3B,EAAE,IAAA,EAAM,GAAA,EAAK,IAAA,EAAM,SAAA,EAAU;AAAA,EAC7B,EAAE,IAAA,EAAM,GAAA,EAAK,IAAA,EAAM,SAAA;AACrB,CAAA;AAGO,SAAS,oBAAoB,MAAA,EAA0B;AAC5D,EAAA,OAAOA,yBAAoB,kBAAA,EAAoB;AAAA,IAC7C,MAAA,CAAO,IAAA;AAAA,IACP,MAAA,CAAO,YAAA;AAAA,IACP,MAAA,CAAO,iBAAA;AAAA,IACP,MAAA,CAAO,OAAO,KAAK,CAAA;AAAA,IACnB,OAAO,GAAA,CAAI,CAAA;AAAA,IACX,OAAO,GAAA,CAAI,CAAA;AAAA,IACX,OAAO,GAAA,CAAI;AAAA,GACZ,CAAA;AACH;AAGO,SAAS,oBAAoB,aAAA,EAAiC;AACnE,EAAA,MAAM,CAAC,MAAM,YAAA,EAAc,iBAAA,EAAmB,OAAO,CAAA,EAAG,CAAA,EAAG,CAAC,CAAA,GAAIC,wBAAA;AAAA,IAC9D,kBAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,YAAA;AAAA,IACA,iBAAA;AAAA,IACA,KAAA,EAAO,MAAM,QAAA,EAAS;AAAA,IACtB,KAAK,EAAE,CAAA,EAAG,OAAO,CAAC,CAAA,EAAG,GAAG,CAAA;AAAE,GAC5B;AACF","file":"index.js","sourcesContent":["// Wire-format codec for the post-commit `signedPayload` Hex.\n//\n// The signed-payload Hex is the ABI-encoded tuple\n// (address from, string functionName, bytes functionSignature,\n// uint256 nonce, uint8 v, bytes32 r, bytes32 s)\n// — i.e. a serialised `BosonMetaTx` ready to be unpacked and wrapped in\n// `MetaTransactionsHandlerFacet.executeMetaTransaction(...)`. It lives\n// here so the buyer's client (encoding) and the facilitator (decoding)\n// share one definition and cannot drift.\n\nimport type { BosonMetaTx, Hex } from \"@bosonprotocol/x402-core/schemes/escrow\";\nimport { decodeAbiParameters, encodeAbiParameters, type AbiParameter } from \"viem\";\n\nconst SIGNED_PAYLOAD_ABI: readonly AbiParameter[] = [\n { name: \"from\", type: \"address\" },\n { name: \"functionName\", type: \"string\" },\n { name: \"functionSignature\", type: \"bytes\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"v\", type: \"uint8\" },\n { name: \"r\", type: \"bytes32\" },\n { name: \"s\", type: \"bytes32\" },\n] as const;\n\n/** Encode a BosonMetaTx as the wire-format Hex for `signedPayload`. */\nexport function encodeSignedPayload(metaTx: BosonMetaTx): Hex {\n return encodeAbiParameters(SIGNED_PAYLOAD_ABI, [\n metaTx.from as `0x${string}`,\n metaTx.functionName,\n metaTx.functionSignature as `0x${string}`,\n BigInt(metaTx.nonce),\n metaTx.sig.v,\n metaTx.sig.r as `0x${string}`,\n metaTx.sig.s as `0x${string}`,\n ]);\n}\n\n/** Decode the wire-format Hex back into a BosonMetaTx. */\nexport function decodeSignedPayload(signedPayload: Hex): BosonMetaTx {\n const [from, functionName, functionSignature, nonce, v, r, s] = decodeAbiParameters(\n SIGNED_PAYLOAD_ABI,\n signedPayload as `0x${string}`,\n ) as [`0x${string}`, string, `0x${string}`, bigint, number, `0x${string}`, `0x${string}`];\n return {\n from,\n functionName,\n functionSignature,\n nonce: nonce.toString(),\n sig: { v: Number(v), r, s },\n };\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export { BuildCreateOfferAndCommitCalldataArgs, BuildCreateOfferCommitAndRedeemCalldataArgs, InnerActionCalldata, TxRequest, buildCreateOfferAndCommitCalldata, buildCreateOfferCommitAndRedeemCalldata } from './actions/index.js';
2
+ export { decodeSignedPayload, encodeSignedPayload } from './codec/index.js';
3
+ export { RelayerSubmitError, RelayerSubmitErrorCode, classifyViemSendError, createCalldataOnlyWeb3LibAdapter, walletClientToWeb3LibAdapter } from './adapters/index.js';
4
+ import 'viem';
5
+ import '@bosonprotocol/common';
6
+ import '@bosonprotocol/x402-core/schemes/escrow';
@@ -0,0 +1,240 @@
1
+ 'use strict';
2
+
3
+ var coreSdk = require('@bosonprotocol/core-sdk');
4
+ var viem = require('viem');
5
+
6
+ // src/actions/create-offer-and-commit.ts
7
+
8
+ // src/internal/metatx-calldata-constants.ts
9
+ var DUMMY_CHAIN_ID = 1;
10
+ var DUMMY_METATX_HANDLER_ADDRESS = "0x0000000000000000000000000000000000000000";
11
+ var DUMMY_NONCE = "0";
12
+
13
+ // src/internal/web3lib-stub.ts
14
+ var DUMMY_SIGNER_ADDRESS = "0x0000000000000000000000000000000000000001";
15
+ function unreachable(callerTag, method) {
16
+ return new Error(
17
+ `${callerTag}: stub Web3LibAdapter.${method}() should never be called. If you see this, core-sdk changed its typed-data-only behavior.`
18
+ );
19
+ }
20
+ function createCalldataOnlyWeb3LibAdapter(callerTag) {
21
+ return {
22
+ uuid: `${callerTag}:stub`,
23
+ getSignerAddress: () => Promise.resolve(DUMMY_SIGNER_ADDRESS),
24
+ isSignerContract: () => Promise.resolve(false),
25
+ getChainId: () => Promise.reject(unreachable(callerTag, "getChainId")),
26
+ getBalance: () => Promise.reject(unreachable(callerTag, "getBalance")),
27
+ estimateGas: () => Promise.reject(unreachable(callerTag, "estimateGas")),
28
+ sendTransaction: () => Promise.reject(unreachable(callerTag, "sendTransaction")),
29
+ call: () => Promise.reject(unreachable(callerTag, "call")),
30
+ send: () => Promise.reject(unreachable(callerTag, "send")),
31
+ getTransactionReceipt: () => Promise.reject(unreachable(callerTag, "getTransactionReceipt")),
32
+ getCurrentTimeMs: () => Promise.reject(unreachable(callerTag, "getCurrentTimeMs"))
33
+ };
34
+ }
35
+
36
+ // src/actions/create-offer-and-commit.ts
37
+ var STUB_CALLER_TAG = "@bosonprotocol/x402-evm:create-offer-and-commit";
38
+ async function buildCreateOfferAndCommitCalldata(args) {
39
+ const result = await coreSdk.metaTx.handler.signMetaTxCreateOfferAndCommit({
40
+ web3Lib: createCalldataOnlyWeb3LibAdapter(STUB_CALLER_TAG),
41
+ metaTxHandlerAddress: DUMMY_METATX_HANDLER_ADDRESS,
42
+ chainId: DUMMY_CHAIN_ID,
43
+ nonce: DUMMY_NONCE,
44
+ createOfferAndCommitArgs: args.fullOffer,
45
+ returnTypedDataToSign: true
46
+ });
47
+ return {
48
+ functionName: result.functionName,
49
+ functionSignature: result.functionSignature
50
+ };
51
+ }
52
+ var STUB_CALLER_TAG2 = "@bosonprotocol/x402-evm:create-offer-commit-and-redeem";
53
+ async function buildCreateOfferCommitAndRedeemCalldata(args) {
54
+ const result = await coreSdk.metaTx.handler.signMetaTxCreateOfferCommitAndRedeem({
55
+ web3Lib: createCalldataOnlyWeb3LibAdapter(STUB_CALLER_TAG2),
56
+ metaTxHandlerAddress: DUMMY_METATX_HANDLER_ADDRESS,
57
+ chainId: DUMMY_CHAIN_ID,
58
+ nonce: DUMMY_NONCE,
59
+ createOfferAndCommitArgs: args.fullOffer,
60
+ returnTypedDataToSign: true
61
+ });
62
+ return {
63
+ functionName: result.functionName,
64
+ functionSignature: result.functionSignature
65
+ };
66
+ }
67
+ var SIGNED_PAYLOAD_ABI = [
68
+ { name: "from", type: "address" },
69
+ { name: "functionName", type: "string" },
70
+ { name: "functionSignature", type: "bytes" },
71
+ { name: "nonce", type: "uint256" },
72
+ { name: "v", type: "uint8" },
73
+ { name: "r", type: "bytes32" },
74
+ { name: "s", type: "bytes32" }
75
+ ];
76
+ function encodeSignedPayload(metaTx3) {
77
+ return viem.encodeAbiParameters(SIGNED_PAYLOAD_ABI, [
78
+ metaTx3.from,
79
+ metaTx3.functionName,
80
+ metaTx3.functionSignature,
81
+ BigInt(metaTx3.nonce),
82
+ metaTx3.sig.v,
83
+ metaTx3.sig.r,
84
+ metaTx3.sig.s
85
+ ]);
86
+ }
87
+ function decodeSignedPayload(signedPayload) {
88
+ const [from, functionName, functionSignature, nonce, v, r, s] = viem.decodeAbiParameters(
89
+ SIGNED_PAYLOAD_ABI,
90
+ signedPayload
91
+ );
92
+ return {
93
+ from,
94
+ functionName,
95
+ functionSignature,
96
+ nonce: nonce.toString(),
97
+ sig: { v: Number(v), r, s }
98
+ };
99
+ }
100
+ var RelayerSubmitError = class extends Error {
101
+ constructor(code, message, options) {
102
+ super(message, options);
103
+ this.name = "RelayerSubmitError";
104
+ this.code = code;
105
+ }
106
+ };
107
+ var DEFAULT_RECEIPT_TIMEOUT_MS = 6e4;
108
+ function walletClientToWeb3LibAdapter(params) {
109
+ const { walletClient, publicClient, chainId } = params;
110
+ const receiptTimeoutMs = params.receiptTimeoutMs ?? DEFAULT_RECEIPT_TIMEOUT_MS;
111
+ if (walletClient.chain && walletClient.chain.id !== chainId) {
112
+ throw new RelayerSubmitError(
113
+ "INTERNAL_ERROR",
114
+ `walletClient.chain.id (${walletClient.chain.id}) does not match adapter chainId (${chainId})`
115
+ );
116
+ }
117
+ if (publicClient.chain && publicClient.chain.id !== chainId) {
118
+ throw new RelayerSubmitError(
119
+ "INTERNAL_ERROR",
120
+ `publicClient.chain.id (${publicClient.chain.id}) does not match adapter chainId (${chainId})`
121
+ );
122
+ }
123
+ return {
124
+ uuid: "x402-evm:viem-relayer-adapter",
125
+ getSignerAddress: async () => {
126
+ const account = walletClient.account;
127
+ if (!account) {
128
+ throw new RelayerSubmitError(
129
+ "INTERNAL_ERROR",
130
+ "walletClient has no account; cannot resolve signer address"
131
+ );
132
+ }
133
+ return account.address;
134
+ },
135
+ isSignerContract: async () => false,
136
+ getChainId: async () => chainId,
137
+ getBalance: async (addressOrName) => {
138
+ const balance = await publicClient.getBalance({ address: addressOrName });
139
+ return balance;
140
+ },
141
+ estimateGas: async (req) => {
142
+ const account = walletClient.account;
143
+ const gas = await publicClient.estimateGas({
144
+ account: account ?? void 0,
145
+ to: req.to,
146
+ data: req.data,
147
+ value: req.value === void 0 ? void 0 : BigInt(req.value.toString())
148
+ });
149
+ return gas;
150
+ },
151
+ sendTransaction: async (req) => {
152
+ const account = walletClient.account;
153
+ if (!account) {
154
+ throw new RelayerSubmitError(
155
+ "INTERNAL_ERROR",
156
+ "walletClient has no account; cannot send transaction"
157
+ );
158
+ }
159
+ let hash;
160
+ try {
161
+ hash = await walletClient.sendTransaction({
162
+ account,
163
+ chain: walletClient.chain ?? null,
164
+ to: req.to,
165
+ data: req.data,
166
+ value: req.value === void 0 ? 0n : BigInt(req.value.toString())
167
+ });
168
+ } catch (e) {
169
+ throw classifyViemSendError(e);
170
+ }
171
+ return {
172
+ hash,
173
+ wait: async (confirmations) => {
174
+ const receipt = await publicClient.waitForTransactionReceipt({
175
+ hash,
176
+ confirmations,
177
+ timeout: receiptTimeoutMs
178
+ });
179
+ return mapReceipt(receipt);
180
+ }
181
+ };
182
+ },
183
+ call: async (req) => {
184
+ const result = await publicClient.call({
185
+ to: req.to,
186
+ data: req.data
187
+ });
188
+ return result.data ?? "0x";
189
+ },
190
+ send: async (method) => {
191
+ throw new RelayerSubmitError(
192
+ "INTERNAL_ERROR",
193
+ `x402-evm: relayer adapter does not support RPC method '${method}'; the relayer never signs typed data`
194
+ );
195
+ },
196
+ getTransactionReceipt: async (txHash) => {
197
+ const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
198
+ return mapReceipt(receipt);
199
+ },
200
+ getCurrentTimeMs: async () => Date.now()
201
+ };
202
+ }
203
+ function mapReceipt(receipt) {
204
+ return {
205
+ from: receipt.from,
206
+ to: receipt.to ?? "",
207
+ status: receipt.status === "success" ? 1 : 0,
208
+ logs: receipt.logs.map((log) => ({ data: log.data, topics: [...log.topics] })),
209
+ transactionHash: receipt.transactionHash,
210
+ effectiveGasPrice: receipt.effectiveGasPrice,
211
+ blockNumber: Number(receipt.blockNumber),
212
+ gasUsed: receipt.gasUsed
213
+ };
214
+ }
215
+ function classifyViemSendError(e) {
216
+ const reason = e instanceof Error ? `sendTransaction failed: ${e.message}` : "sendTransaction failed";
217
+ if (hasViemCause(e, viem.InsufficientFundsError)) {
218
+ return new RelayerSubmitError("INSUFFICIENT_FUNDS_FOR_GAS", reason, { cause: e });
219
+ }
220
+ if (hasViemCause(e, viem.ExecutionRevertedError) || hasViemCause(e, viem.ContractFunctionRevertedError) || hasViemCause(e, viem.RawContractError)) {
221
+ return new RelayerSubmitError("ONCHAIN_REVERT", reason, { cause: e });
222
+ }
223
+ return new RelayerSubmitError("INTERNAL_ERROR", reason, { cause: e });
224
+ }
225
+ function hasViemCause(e, ctor) {
226
+ if (e instanceof ctor) return true;
227
+ if (!(e instanceof viem.BaseError)) return false;
228
+ return e.walk((err) => err instanceof ctor) !== null;
229
+ }
230
+
231
+ exports.RelayerSubmitError = RelayerSubmitError;
232
+ exports.buildCreateOfferAndCommitCalldata = buildCreateOfferAndCommitCalldata;
233
+ exports.buildCreateOfferCommitAndRedeemCalldata = buildCreateOfferCommitAndRedeemCalldata;
234
+ exports.classifyViemSendError = classifyViemSendError;
235
+ exports.createCalldataOnlyWeb3LibAdapter = createCalldataOnlyWeb3LibAdapter;
236
+ exports.decodeSignedPayload = decodeSignedPayload;
237
+ exports.encodeSignedPayload = encodeSignedPayload;
238
+ exports.walletClientToWeb3LibAdapter = walletClientToWeb3LibAdapter;
239
+ //# sourceMappingURL=index.js.map
240
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/internal/metatx-calldata-constants.ts","../../src/internal/web3lib-stub.ts","../../src/actions/create-offer-and-commit.ts","../../src/actions/create-offer-commit-and-redeem.ts","../../src/codec/signed-payload.ts","../../src/adapters/viem-relayer.ts"],"names":["metaTx","STUB_CALLER_TAG","encodeAbiParameters","decodeAbiParameters","InsufficientFundsError","ExecutionRevertedError","ContractFunctionRevertedError","RawContractError","BaseError"],"mappings":";;;;;;;;AAUO,IAAM,cAAA,GAAiB,CAAA;AACvB,IAAM,4BAAA,GAA+B,4CAAA;AACrC,IAAM,WAAA,GAAc,GAAA;;;ACA3B,IAAM,oBAAA,GAAuB,4CAAA;AAE7B,SAAS,WAAA,CAAY,WAAmB,MAAA,EAAuB;AAC7D,EAAA,OAAO,IAAI,KAAA;AAAA,IACT,CAAA,EAAG,SAAS,CAAA,sBAAA,EAAyB,MAAM,CAAA,0FAAA;AAAA,GAE7C;AACF;AAEO,SAAS,iCAAiC,SAAA,EAAmC;AAClF,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,GAAG,SAAS,CAAA,KAAA,CAAA;AAAA,IAClB,gBAAA,EAAkB,MAAM,OAAA,CAAQ,OAAA,CAAQ,oBAAoB,CAAA;AAAA,IAC5D,gBAAA,EAAkB,MAAM,OAAA,CAAQ,OA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,CAAA,EAAGC,qBAAgB,CAAA,EAChC;AACA,IAAA,OAAO,IAAI,kBAAA,CAAmB,gBAAA,EAAkB,QAAQ,EAAE,KAAA,EAAO,GAAG,CAAA;AAAA,EACtE;AACA,EAAA,OAAO,IAAI,kBAAA,CAAmB,gBAAA,EAAkB,QAAQ,EAAE,KAAA,EAAO,GAAG,CAAA;AACtE;AAEA,SAAS,YAAA,CACP,GACA,IAAA,EACS;AACT,EAAA,IAAI,CAAA,YAAa,MAAM,OAAO,IAAA;AAC9B,EAAA,IAAI,EAAE,CAAA,YAAaC,cAAA,CAAA,EAAY,OAAO,KAAA;AACtC,EAAA,OAAO,EAAE,IAAA,CAAK,CAAC,GAAA,KAAQ,GAAA,YAAe,IAAI,CAAA,KAAM,IAAA;AAClD","file":"index.js","sourcesContent":["// Placeholder values for the meta-tx fields the SDK's `signMetaTx*` helpers\n// require but the calldata-builder modules don't care about.\n//\n// The builders delegate the `{ functionName, functionSignature }` pair to\n// `metaTx.handler.signMetaTx*({ returnTypedDataToSign: true })`. The SDK\n// requires `chainId`, `metaTxHandlerAddress`, and `nonce` to build the\n// meta-tx typed-data domain, but those affect only the typed-data portion\n// of the response; the selector literal and ABI-encoded calldata we read\n// back are independent of all three.\n\nexport const DUMMY_CHAIN_ID = 1;\nexport const DUMMY_METATX_HANDLER_ADDRESS = \"0x0000000000000000000000000000000000000000\";\nexport const DUMMY_NONCE = \"0\";\n","// Calldata-only `Web3LibAdapter` for the calldata-builder modules.\n//\n// Core-sdk's `signMetaTx` calls `web3Lib.getSignerAddress()` even in\n// `returnTypedDataToSign: true` mode to fill the message's `from` field.\n// We return a deterministic dummy address; the typed-data message is\n// discarded and only `{ functionName, functionSignature }` is consumed.\n//\n// All signing and transaction methods reject so the stub fails loudly if\n// it ever leaks into a path that needs more than typed-data construction.\n\nimport type { Web3LibAdapter } from \"@bosonprotocol/common\";\n\nconst DUMMY_SIGNER_ADDRESS = \"0x0000000000000000000000000000000000000001\";\n\nfunction unreachable(callerTag: string, method: string): Error {\n return new Error(\n `${callerTag}: stub Web3LibAdapter.${method}() should never be called. ` +\n \"If you see this, core-sdk changed its typed-data-only behavior.\",\n );\n}\n\nexport function createCalldataOnlyWeb3LibAdapter(callerTag: string): Web3LibAdapter {\n return {\n uuid: `${callerTag}:stub`,\n getSignerAddress: () => Promise.resolve(DUMMY_SIGNER_ADDRESS),\n isSignerContract: () => Promise.resolve(false),\n getChainId: () => Promise.reject(unreachable(callerTag, \"getChainId\")),\n getBalance: () => Promise.reject(unreachable(callerTag, \"getBalance\")),\n estimateGas: () => Promise.reject(unreachable(callerTag, \"estimateGas\")),\n sendTransaction: () => Promise.reject(unreachable(callerTag, \"sendTransaction\")),\n call: () => Promise.reject(unreachable(callerTag, \"call\")),\n send: () => Promise.reject(unreachable(callerTag, \"send\")),\n getTransactionReceipt: () => Promise.reject(unreachable(callerTag, \"getTransactionReceipt\")),\n getCurrentTimeMs: () => Promise.reject(unreachable(callerTag, \"getCurrentTimeMs\")),\n };\n}\n","// Calldata builder for `ExchangeCommitFacet.createOfferAndCommit` —\n// the \"deferred-redemption\" Boson action (Flow A in\n// docs/boson-impl-02-flows.md).\n//\n// Returns the `{ functionName, functionSignature }` pair the buyer's\n// meta-tx typed-data is built over — same pair the on-chain\n// `MetaTransactionsHandlerFacet` recovers signatures against.\n//\n// Implementation note: rather than hand-pin the `functionName` selector\n// string and call `exchanges.iface.encodeCreateOfferAndCommit` here\n// directly, we delegate the whole pair to\n// `@bosonprotocol/core-sdk`'s `metaTx.handler.signMetaTxCreateOfferAndCommit`\n// in `returnTypedDataToSign: true` mode. That's the same helper the\n// client uses to sign, so signing and verification source the\n// `functionName` literal + `functionSignature` bytes from one place.\n// If a future SDK release changes either, both paths track the change\n// automatically.\n\nimport type { FullOfferArgs } from \"@bosonprotocol/common\";\nimport { metaTx } from \"@bosonprotocol/core-sdk\";\nimport type { Hex } from \"viem\";\n\nimport {\n DUMMY_CHAIN_ID,\n DUMMY_METATX_HANDLER_ADDRESS,\n DUMMY_NONCE,\n} from \"../internal/metatx-calldata-constants.js\";\nimport { createCalldataOnlyWeb3LibAdapter } from \"../internal/web3lib-stub.js\";\nimport type { InnerActionCalldata } from \"../types.js\";\n\nexport interface BuildCreateOfferAndCommitCalldataArgs {\n /**\n * Full BPIP-10 offer payload, identical in shape to what core-sdk's\n * `exchanges.iface.encodeCreateOfferAndCommit` accepts. The seller's\n * `signature` field is embedded inside this struct and is verified\n * on-chain by `verifyOffer`.\n */\n fullOffer: FullOfferArgs;\n}\n\nconst STUB_CALLER_TAG = \"@bosonprotocol/x402-evm:create-offer-and-commit\";\n\n/**\n * Build the `{ functionName, functionSignature }` calldata pair for the\n * `createOfferAndCommit` inner action. The result feeds\n * `@bosonprotocol/x402-core/eip712`'s `metaTransactionTypedData`\n * builder to produce the EIP-712 typed-data the buyer signs.\n */\nexport async function buildCreateOfferAndCommitCalldata(\n args: BuildCreateOfferAndCommitCalldataArgs,\n): Promise<InnerActionCalldata> {\n const result = await metaTx.handler.signMetaTxCreateOfferAndCommit({\n web3Lib: createCalldataOnlyWeb3LibAdapter(STUB_CALLER_TAG),\n metaTxHandlerAddress: DUMMY_METATX_HANDLER_ADDRESS,\n chainId: DUMMY_CHAIN_ID,\n nonce: DUMMY_NONCE,\n createOfferAndCommitArgs: args.fullOffer,\n returnTypedDataToSign: true,\n });\n\n return {\n functionName: result.functionName,\n functionSignature: result.functionSignature as Hex,\n };\n}\n","// Calldata builder for `OrchestrationHandlerFacet2.createOfferCommitAndRedeem` —\n// the atomic \"create offer + commit + redeem\" Boson action (Flow B in\n// docs/boson-impl-02-flows.md).\n//\n// Same delegation pattern as `./create-offer-and-commit.ts`: rather than\n// hand-pin the `functionName` selector here, we route the whole\n// `{ functionName, functionSignature }` pair through\n// `@bosonprotocol/core-sdk`'s `metaTx.handler.signMetaTxCreateOfferCommitAndRedeem`\n// in `returnTypedDataToSign: true` mode. That's the same helper the\n// client uses to sign, so signing and verification share one source of\n// truth.\n//\n// Note: the function-argument arity differs from `createOfferAndCommit`\n// (this variant takes `(fullOfferStruct, address offerCreator, bytes\n// sellerSig, uint256 conditionalTokenId)` rather than the\n// deferred-redeem path's longer signature).\n\nimport type { FullOfferArgs } from \"@bosonprotocol/common\";\nimport { metaTx } from \"@bosonprotocol/core-sdk\";\nimport type { Hex } from \"viem\";\n\nimport {\n DUMMY_CHAIN_ID,\n DUMMY_METATX_HANDLER_ADDRESS,\n DUMMY_NONCE,\n} from \"../internal/metatx-calldata-constants.js\";\nimport { createCalldataOnlyWeb3LibAdapter } from \"../internal/web3lib-stub.js\";\nimport type { InnerActionCalldata } from \"../types.js\";\n\nexport interface BuildCreateOfferCommitAndRedeemCalldataArgs {\n /**\n * Full BPIP-10 offer payload, identical in shape to what core-sdk's\n * `orchestration.iface.encodeCreateOfferCommitAndRedeem` accepts. The\n * seller's `signature` field is embedded inside this struct and is\n * verified on-chain by `verifyOffer`.\n */\n fullOffer: FullOfferArgs;\n}\n\nconst STUB_CALLER_TAG = \"@bosonprotocol/x402-evm:create-offer-commit-and-redeem\";\n\n/**\n * Build the `{ functionName, functionSignature }` calldata pair for the\n * `createOfferCommitAndRedeem` inner action.\n */\nexport async function buildCreateOfferCommitAndRedeemCalldata(\n args: BuildCreateOfferCommitAndRedeemCalldataArgs,\n): Promise<InnerActionCalldata> {\n const result = await metaTx.handler.signMetaTxCreateOfferCommitAndRedeem({\n web3Lib: createCalldataOnlyWeb3LibAdapter(STUB_CALLER_TAG),\n metaTxHandlerAddress: DUMMY_METATX_HANDLER_ADDRESS,\n chainId: DUMMY_CHAIN_ID,\n nonce: DUMMY_NONCE,\n createOfferAndCommitArgs: args.fullOffer,\n returnTypedDataToSign: true,\n });\n\n return {\n functionName: result.functionName,\n functionSignature: result.functionSignature as Hex,\n };\n}\n","// Wire-format codec for the post-commit `signedPayload` Hex.\n//\n// The signed-payload Hex is the ABI-encoded tuple\n// (address from, string functionName, bytes functionSignature,\n// uint256 nonce, uint8 v, bytes32 r, bytes32 s)\n// — i.e. a serialised `BosonMetaTx` ready to be unpacked and wrapped in\n// `MetaTransactionsHandlerFacet.executeMetaTransaction(...)`. It lives\n// here so the buyer's client (encoding) and the facilitator (decoding)\n// share one definition and cannot drift.\n\nimport type { BosonMetaTx, Hex } from \"@bosonprotocol/x402-core/schemes/escrow\";\nimport { decodeAbiParameters, encodeAbiParameters, type AbiParameter } from \"viem\";\n\nconst SIGNED_PAYLOAD_ABI: readonly AbiParameter[] = [\n { name: \"from\", type: \"address\" },\n { name: \"functionName\", type: \"string\" },\n { name: \"functionSignature\", type: \"bytes\" },\n { name: \"nonce\", type: \"uint256\" },\n { name: \"v\", type: \"uint8\" },\n { name: \"r\", type: \"bytes32\" },\n { name: \"s\", type: \"bytes32\" },\n] as const;\n\n/** Encode a BosonMetaTx as the wire-format Hex for `signedPayload`. */\nexport function encodeSignedPayload(metaTx: BosonMetaTx): Hex {\n return encodeAbiParameters(SIGNED_PAYLOAD_ABI, [\n metaTx.from as `0x${string}`,\n metaTx.functionName,\n metaTx.functionSignature as `0x${string}`,\n BigInt(metaTx.nonce),\n metaTx.sig.v,\n metaTx.sig.r as `0x${string}`,\n metaTx.sig.s as `0x${string}`,\n ]);\n}\n\n/** Decode the wire-format Hex back into a BosonMetaTx. */\nexport function decodeSignedPayload(signedPayload: Hex): BosonMetaTx {\n const [from, functionName, functionSignature, nonce, v, r, s] = decodeAbiParameters(\n SIGNED_PAYLOAD_ABI,\n signedPayload as `0x${string}`,\n ) as [`0x${string}`, string, `0x${string}`, bigint, number, `0x${string}`, `0x${string}`];\n return {\n from,\n functionName,\n functionSignature,\n nonce: nonce.toString(),\n sig: { v: Number(v), r, s },\n };\n}\n","// Viem-backed `Web3LibAdapter` for relayer / facilitator-style flows where\n// a configured `WalletClient` submits transactions on a buyer's behalf.\n//\n// `@bosonprotocol/core-sdk`'s `MetaTxMixin.executeMetaTransaction(...)`\n// (the unified entrypoint that routes between\n// `executeMetaTransaction` and `executeMetaTransactionWithTokenTransferAuthorization`\n// based on whether `transferAuthorizations` is provided) drives every\n// on-chain side-effect through the SDK's `Web3LibAdapter`. This adapter\n// wraps a viem `WalletClient` (for writes) plus a `PublicClient`\n// (for reads / receipt polling) so the SDK can run end-to-end against\n// viem-configured transports.\n//\n// The sibling `client/src/internal/web3lib-adapter.ts` wraps a sign-only\n// `Signer` for the buyer path; this is the symmetric write-only variant\n// for the relayer path. Future work may consolidate them behind a\n// single factory.\n\nimport type { Web3LibAdapter } from \"@bosonprotocol/common\";\nimport {\n BaseError,\n ContractFunctionRevertedError,\n ExecutionRevertedError,\n InsufficientFundsError,\n RawContractError,\n type PublicClient,\n type WalletClient,\n} from \"viem\";\n\n/** Tagged error thrown by the adapter when `walletClient.sendTransaction` rejects. */\nexport class RelayerSubmitError extends Error {\n readonly code: RelayerSubmitErrorCode;\n constructor(code: RelayerSubmitErrorCode, message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = \"RelayerSubmitError\";\n this.code = code;\n }\n}\n\n/** Stable identifiers callers can map to their own error-code vocabulary. */\nexport type RelayerSubmitErrorCode =\n | \"INSUFFICIENT_FUNDS_FOR_GAS\"\n | \"ONCHAIN_REVERT\"\n | \"INTERNAL_ERROR\";\n\n/** Default deadline for `wait()` when the caller does not override. */\nconst DEFAULT_RECEIPT_TIMEOUT_MS = 60_000;\n\n/**\n * Build the `Web3LibAdapter` that `@bosonprotocol/core-sdk`'s `CoreSDK`\n * accepts for relayer-driven flows.\n *\n * - Writes flow through `walletClient.sendTransaction`; viem errors are\n * re-thrown as a tagged `RelayerSubmitError` so the caller can keep\n * precise classification (insufficient gas funds vs. on-chain revert\n * vs. transport failure).\n * - Reads (`call`, `getBalance`, `estimateGas`, `getTransactionReceipt`)\n * flow through `publicClient`.\n * - `send` rejects: the relayer never signs typed data through the\n * adapter (the buyer already signed off-chain).\n *\n * If either client carries a `chain` (viem populates it when the client\n * was built with an explicit chain) the factory cross-checks its id\n * against the supplied `chainId` and rejects mismatches up-front, so a\n * misconfigured pair fails loudly rather than silently targeting the\n * wrong network.\n */\nexport function walletClientToWeb3LibAdapter(params: {\n walletClient: WalletClient;\n publicClient: PublicClient;\n chainId: number;\n /**\n * Per-call timeout (ms) passed to `publicClient.waitForTransactionReceipt`\n * inside the adapter's `wait()` method, so callers that route through\n * core-sdk's `TransactionResponse.wait()` don't hang indefinitely on a\n * stalled RPC. Defaults to 60s. Direct callers that drive their own\n * receipt polling can ignore it.\n */\n receiptTimeoutMs?: number;\n}): Web3LibAdapter {\n const { walletClient, publicClient, chainId } = params;\n const receiptTimeoutMs = params.receiptTimeoutMs ?? DEFAULT_RECEIPT_TIMEOUT_MS;\n if (walletClient.chain && walletClient.chain.id !== chainId) {\n throw new RelayerSubmitError(\n \"INTERNAL_ERROR\",\n `walletClient.chain.id (${walletClient.chain.id}) does not match adapter chainId (${chainId})`,\n );\n }\n if (publicClient.chain && publicClient.chain.id !== chainId) {\n throw new RelayerSubmitError(\n \"INTERNAL_ERROR\",\n `publicClient.chain.id (${publicClient.chain.id}) does not match adapter chainId (${chainId})`,\n );\n }\n return {\n uuid: \"x402-evm:viem-relayer-adapter\",\n getSignerAddress: async () => {\n const account = walletClient.account;\n if (!account) {\n throw new RelayerSubmitError(\n \"INTERNAL_ERROR\",\n \"walletClient has no account; cannot resolve signer address\",\n );\n }\n return account.address;\n },\n isSignerContract: async () => false,\n getChainId: async () => chainId,\n getBalance: async (addressOrName) => {\n const balance = await publicClient.getBalance({ address: addressOrName as `0x${string}` });\n return balance;\n },\n estimateGas: async (req) => {\n const account = walletClient.account;\n const gas = await publicClient.estimateGas({\n account: account ?? undefined,\n to: req.to as `0x${string}` | undefined,\n data: req.data as `0x${string}` | undefined,\n value: req.value === undefined ? undefined : BigInt(req.value.toString()),\n });\n return gas;\n },\n sendTransaction: async (req) => {\n const account = walletClient.account;\n if (!account) {\n throw new RelayerSubmitError(\n \"INTERNAL_ERROR\",\n \"walletClient has no account; cannot send transaction\",\n );\n }\n let hash: `0x${string}`;\n try {\n hash = await walletClient.sendTransaction({\n account,\n chain: walletClient.chain ?? null,\n to: req.to as `0x${string}` | undefined,\n data: req.data as `0x${string}` | undefined,\n value: req.value === undefined ? 0n : BigInt(req.value.toString()),\n });\n } catch (e) {\n throw classifyViemSendError(e);\n }\n return {\n hash,\n wait: async (confirmations?: number) => {\n const receipt = await publicClient.waitForTransactionReceipt({\n hash,\n confirmations,\n timeout: receiptTimeoutMs,\n });\n return mapReceipt(receipt);\n },\n };\n },\n call: async (req) => {\n const result = await publicClient.call({\n to: req.to as `0x${string}` | undefined,\n data: req.data as `0x${string}` | undefined,\n });\n return result.data ?? \"0x\";\n },\n send: async (method) => {\n throw new RelayerSubmitError(\n \"INTERNAL_ERROR\",\n `x402-evm: relayer adapter does not support RPC method '${method}'; the relayer never signs typed data`,\n );\n },\n getTransactionReceipt: async (txHash) => {\n const receipt = await publicClient.getTransactionReceipt({ hash: txHash as `0x${string}` });\n return mapReceipt(receipt);\n },\n getCurrentTimeMs: async () => Date.now(),\n };\n}\n\n/**\n * Normalize a viem `TransactionReceipt` into the SDK's `TransactionReceipt`\n * shape from `@bosonprotocol/common`. viem's logs carry extra fields the\n * SDK doesn't reference; we strip them so the adapter returns exactly the\n * shape the contract is typed against (and keep both\n * `sendTransaction().wait()` and `getTransactionReceipt(...)` paths from\n * drifting).\n */\nfunction mapReceipt(receipt: Awaited<ReturnType<PublicClient[\"getTransactionReceipt\"]>>) {\n return {\n from: receipt.from,\n to: receipt.to ?? \"\",\n status: receipt.status === \"success\" ? 1 : 0,\n logs: receipt.logs.map((log) => ({ data: log.data, topics: [...log.topics] })),\n transactionHash: receipt.transactionHash,\n effectiveGasPrice: receipt.effectiveGasPrice,\n blockNumber: Number(receipt.blockNumber),\n gasUsed: receipt.gasUsed,\n };\n}\n\n/** Classify a viem error thrown by `walletClient.sendTransaction`. */\nexport function classifyViemSendError(e: unknown): RelayerSubmitError {\n const reason =\n e instanceof Error ? `sendTransaction failed: ${e.message}` : \"sendTransaction failed\";\n\n if (hasViemCause(e, InsufficientFundsError)) {\n return new RelayerSubmitError(\"INSUFFICIENT_FUNDS_FOR_GAS\", reason, { cause: e });\n }\n if (\n hasViemCause(e, ExecutionRevertedError) ||\n hasViemCause(e, ContractFunctionRevertedError) ||\n hasViemCause(e, RawContractError)\n ) {\n return new RelayerSubmitError(\"ONCHAIN_REVERT\", reason, { cause: e });\n }\n return new RelayerSubmitError(\"INTERNAL_ERROR\", reason, { cause: e });\n}\n\nfunction hasViemCause<T extends abstract new (...args: never[]) => Error>(\n e: unknown,\n ctor: T,\n): boolean {\n if (e instanceof ctor) return true;\n if (!(e instanceof BaseError)) return false;\n return e.walk((err) => err instanceof ctor) !== null;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,4 @@
1
+ export { buildCreateOfferAndCommitCalldata, buildCreateOfferCommitAndRedeemCalldata } from '../chunk-2PRTTZRV.js';
2
+ import '../chunk-YVUW4DX6.js';
3
+ //# sourceMappingURL=index.js.map
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,4 @@
1
+ export { RelayerSubmitError, classifyViemSendError, walletClientToWeb3LibAdapter } from '../chunk-W5YOMJCB.js';
2
+ export { createCalldataOnlyWeb3LibAdapter } from '../chunk-YVUW4DX6.js';
3
+ //# sourceMappingURL=index.js.map
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,43 @@
1
+ import { createCalldataOnlyWeb3LibAdapter } from './chunk-YVUW4DX6.js';
2
+ import { metaTx } from '@bosonprotocol/core-sdk';
3
+
4
+ // src/internal/metatx-calldata-constants.ts
5
+ var DUMMY_CHAIN_ID = 1;
6
+ var DUMMY_METATX_HANDLER_ADDRESS = "0x0000000000000000000000000000000000000000";
7
+ var DUMMY_NONCE = "0";
8
+
9
+ // src/actions/create-offer-and-commit.ts
10
+ var STUB_CALLER_TAG = "@bosonprotocol/x402-evm:create-offer-and-commit";
11
+ async function buildCreateOfferAndCommitCalldata(args) {
12
+ const result = await metaTx.handler.signMetaTxCreateOfferAndCommit({
13
+ web3Lib: createCalldataOnlyWeb3LibAdapter(STUB_CALLER_TAG),
14
+ metaTxHandlerAddress: DUMMY_METATX_HANDLER_ADDRESS,
15
+ chainId: DUMMY_CHAIN_ID,
16
+ nonce: DUMMY_NONCE,
17
+ createOfferAndCommitArgs: args.fullOffer,
18
+ returnTypedDataToSign: true
19
+ });
20
+ return {
21
+ functionName: result.functionName,
22
+ functionSignature: result.functionSignature
23
+ };
24
+ }
25
+ var STUB_CALLER_TAG2 = "@bosonprotocol/x402-evm:create-offer-commit-and-redeem";
26
+ async function buildCreateOfferCommitAndRedeemCalldata(args) {
27
+ const result = await metaTx.handler.signMetaTxCreateOfferCommitAndRedeem({
28
+ web3Lib: createCalldataOnlyWeb3LibAdapter(STUB_CALLER_TAG2),
29
+ metaTxHandlerAddress: DUMMY_METATX_HANDLER_ADDRESS,
30
+ chainId: DUMMY_CHAIN_ID,
31
+ nonce: DUMMY_NONCE,
32
+ createOfferAndCommitArgs: args.fullOffer,
33
+ returnTypedDataToSign: true
34
+ });
35
+ return {
36
+ functionName: result.functionName,
37
+ functionSignature: result.functionSignature
38
+ };
39
+ }
40
+
41
+ export { buildCreateOfferAndCommitCalldata, buildCreateOfferCommitAndRedeemCalldata };
42
+ //# sourceMappingURL=chunk-2PRTTZRV.js.map
43
+ //# sourceMappingURL=chunk-2PRTTZRV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/internal/metatx-calldata-constants.ts","../../src/actions/create-offer-and-commit.ts","../../src/actions/create-offer-commit-and-redeem.ts"],"names":["STUB_CALLER_TAG","metaTx"],"mappings":";;;;AAUO,IAAM,cAAA,GAAiB,CAAA;AACvB,IAAM,4BAAA,GAA+B,4CAAA;AACrC,IAAM,WAAA,GAAc,GAAA;;;AC4B3B,IAAM,eAAA,GAAkB,iDAAA;AAQxB,eAAsB,kCACpB,IAAA,EAC8B;AAC9B,EAAA,MAAM,MAAA,GAAS,MAAM,MAAA,CAAO,OAAA,CAAQ,8BAAA,CAA+B;AAAA,IACjE,OAAA,EAAS,iCAAiC,eAAe,CAAA;AAAA,IACzD,oBAAA,EAAsB,4BAAA;AAAA,IACtB,OAAA,EAAS,cAAA;AAAA,IACT,KAAA,EAAO,WAAA;AAAA,IACP,0BAA0B,IAAA,CAAK,SAAA;AAAA,IAC/B,qBAAA,EAAuB;AAAA,GACxB,CAAA;AAED,EAAA,OAAO;AAAA,IACL,cAAc,MAAA,CAAO,YAAA;AAAA,IACrB,mBAAmB,MAAA,CAAO;AAAA,GAC5B;AACF;ACzBA,IAAMA,gBAAAA,GAAkB,wDAAA;AAMxB,eAAsB,wCACpB,IAAA,EAC8B;AAC9B,EAAA,MAAM,MAAA,GAAS,MAAMC,MAAAA,CAAO,OAAA,CAAQ,oCAAA,CAAqC;AAAA,IACvE,OAAA,EAAS,iCAAiCD,gBAAe,CAAA;AAAA,IACzD,oBAAA,EAAsB,4BAAA;AAAA,IACtB,OAAA,EAAS,cAAA;AAAA,IACT,KAAA,EAAO,WAAA;AAAA,IACP,0BAA0B,IAAA,CAAK,SAAA;AAAA,IAC/B,qBAAA,EAAuB;AAAA,GACxB,CAAA;AAED,EAAA,OAAO;AAAA,IACL,cAAc,MAAA,CAAO,YAAA;AAAA,IACrB,mBAAmB,MAAA,CAAO;AAAA,GAC5B;AACF","file":"chunk-2PRTTZRV.js","sourcesContent":["// Placeholder values for the meta-tx fields the SDK's `signMetaTx*` helpers\n// require but the calldata-builder modules don't care about.\n//\n// The builders delegate the `{ functionName, functionSignature }` pair to\n// `metaTx.handler.signMetaTx*({ returnTypedDataToSign: true })`. The SDK\n// requires `chainId`, `metaTxHandlerAddress`, and `nonce` to build the\n// meta-tx typed-data domain, but those affect only the typed-data portion\n// of the response; the selector literal and ABI-encoded calldata we read\n// back are independent of all three.\n\nexport const DUMMY_CHAIN_ID = 1;\nexport const DUMMY_METATX_HANDLER_ADDRESS = \"0x0000000000000000000000000000000000000000\";\nexport const DUMMY_NONCE = \"0\";\n","// Calldata builder for `ExchangeCommitFacet.createOfferAndCommit` —\n// the \"deferred-redemption\" Boson action (Flow A in\n// docs/boson-impl-02-flows.md).\n//\n// Returns the `{ functionName, functionSignature }` pair the buyer's\n// meta-tx typed-data is built over — same pair the on-chain\n// `MetaTransactionsHandlerFacet` recovers signatures against.\n//\n// Implementation note: rather than hand-pin the `functionName` selector\n// string and call `exchanges.iface.encodeCreateOfferAndCommit` here\n// directly, we delegate the whole pair to\n// `@bosonprotocol/core-sdk`'s `metaTx.handler.signMetaTxCreateOfferAndCommit`\n// in `returnTypedDataToSign: true` mode. That's the same helper the\n// client uses to sign, so signing and verification source the\n// `functionName` literal + `functionSignature` bytes from one place.\n// If a future SDK release changes either, both paths track the change\n// automatically.\n\nimport type { FullOfferArgs } from \"@bosonprotocol/common\";\nimport { metaTx } from \"@bosonprotocol/core-sdk\";\nimport type { Hex } from \"viem\";\n\nimport {\n DUMMY_CHAIN_ID,\n DUMMY_METATX_HANDLER_ADDRESS,\n DUMMY_NONCE,\n} from \"../internal/metatx-calldata-constants.js\";\nimport { createCalldataOnlyWeb3LibAdapter } from \"../internal/web3lib-stub.js\";\nimport type { InnerActionCalldata } from \"../types.js\";\n\nexport interface BuildCreateOfferAndCommitCalldataArgs {\n /**\n * Full BPIP-10 offer payload, identical in shape to what core-sdk's\n * `exchanges.iface.encodeCreateOfferAndCommit` accepts. The seller's\n * `signature` field is embedded inside this struct and is verified\n * on-chain by `verifyOffer`.\n */\n fullOffer: FullOfferArgs;\n}\n\nconst STUB_CALLER_TAG = \"@bosonprotocol/x402-evm:create-offer-and-commit\";\n\n/**\n * Build the `{ functionName, functionSignature }` calldata pair for the\n * `createOfferAndCommit` inner action. The result feeds\n * `@bosonprotocol/x402-core/eip712`'s `metaTransactionTypedData`\n * builder to produce the EIP-712 typed-data the buyer signs.\n */\nexport async function buildCreateOfferAndCommitCalldata(\n args: BuildCreateOfferAndCommitCalldataArgs,\n): Promise<InnerActionCalldata> {\n const result = await metaTx.handler.signMetaTxCreateOfferAndCommit({\n web3Lib: createCalldataOnlyWeb3LibAdapter(STUB_CALLER_TAG),\n metaTxHandlerAddress: DUMMY_METATX_HANDLER_ADDRESS,\n chainId: DUMMY_CHAIN_ID,\n nonce: DUMMY_NONCE,\n createOfferAndCommitArgs: args.fullOffer,\n returnTypedDataToSign: true,\n });\n\n return {\n functionName: result.functionName,\n functionSignature: result.functionSignature as Hex,\n };\n}\n","// Calldata builder for `OrchestrationHandlerFacet2.createOfferCommitAndRedeem` —\n// the atomic \"create offer + commit + redeem\" Boson action (Flow B in\n// docs/boson-impl-02-flows.md).\n//\n// Same delegation pattern as `./create-offer-and-commit.ts`: rather than\n// hand-pin the `functionName` selector here, we route the whole\n// `{ functionName, functionSignature }` pair through\n// `@bosonprotocol/core-sdk`'s `metaTx.handler.signMetaTxCreateOfferCommitAndRedeem`\n// in `returnTypedDataToSign: true` mode. That's the same helper the\n// client uses to sign, so signing and verification share one source of\n// truth.\n//\n// Note: the function-argument arity differs from `createOfferAndCommit`\n// (this variant takes `(fullOfferStruct, address offerCreator, bytes\n// sellerSig, uint256 conditionalTokenId)` rather than the\n// deferred-redeem path's longer signature).\n\nimport type { FullOfferArgs } from \"@bosonprotocol/common\";\nimport { metaTx } from \"@bosonprotocol/core-sdk\";\nimport type { Hex } from \"viem\";\n\nimport {\n DUMMY_CHAIN_ID,\n DUMMY_METATX_HANDLER_ADDRESS,\n DUMMY_NONCE,\n} from \"../internal/metatx-calldata-constants.js\";\nimport { createCalldataOnlyWeb3LibAdapter } from \"../internal/web3lib-stub.js\";\nimport type { InnerActionCalldata } from \"../types.js\";\n\nexport interface BuildCreateOfferCommitAndRedeemCalldataArgs {\n /**\n * Full BPIP-10 offer payload, identical in shape to what core-sdk's\n * `orchestration.iface.encodeCreateOfferCommitAndRedeem` accepts. The\n * seller's `signature` field is embedded inside this struct and is\n * verified on-chain by `verifyOffer`.\n */\n fullOffer: FullOfferArgs;\n}\n\nconst STUB_CALLER_TAG = \"@bosonprotocol/x402-evm:create-offer-commit-and-redeem\";\n\n/**\n * Build the `{ functionName, functionSignature }` calldata pair for the\n * `createOfferCommitAndRedeem` inner action.\n */\nexport async function buildCreateOfferCommitAndRedeemCalldata(\n args: BuildCreateOfferCommitAndRedeemCalldataArgs,\n): Promise<InnerActionCalldata> {\n const result = await metaTx.handler.signMetaTxCreateOfferCommitAndRedeem({\n web3Lib: createCalldataOnlyWeb3LibAdapter(STUB_CALLER_TAG),\n metaTxHandlerAddress: DUMMY_METATX_HANDLER_ADDRESS,\n chainId: DUMMY_CHAIN_ID,\n nonce: DUMMY_NONCE,\n createOfferAndCommitArgs: args.fullOffer,\n returnTypedDataToSign: true,\n });\n\n return {\n functionName: result.functionName,\n functionSignature: result.functionSignature as Hex,\n };\n}\n"]}
@@ -0,0 +1,137 @@
1
+ import { BaseError, InsufficientFundsError, ExecutionRevertedError, ContractFunctionRevertedError, RawContractError } from 'viem';
2
+
3
+ // src/adapters/viem-relayer.ts
4
+ var RelayerSubmitError = class extends Error {
5
+ constructor(code, message, options) {
6
+ super(message, options);
7
+ this.name = "RelayerSubmitError";
8
+ this.code = code;
9
+ }
10
+ };
11
+ var DEFAULT_RECEIPT_TIMEOUT_MS = 6e4;
12
+ function walletClientToWeb3LibAdapter(params) {
13
+ const { walletClient, publicClient, chainId } = params;
14
+ const receiptTimeoutMs = params.receiptTimeoutMs ?? DEFAULT_RECEIPT_TIMEOUT_MS;
15
+ if (walletClient.chain && walletClient.chain.id !== chainId) {
16
+ throw new RelayerSubmitError(
17
+ "INTERNAL_ERROR",
18
+ `walletClient.chain.id (${walletClient.chain.id}) does not match adapter chainId (${chainId})`
19
+ );
20
+ }
21
+ if (publicClient.chain && publicClient.chain.id !== chainId) {
22
+ throw new RelayerSubmitError(
23
+ "INTERNAL_ERROR",
24
+ `publicClient.chain.id (${publicClient.chain.id}) does not match adapter chainId (${chainId})`
25
+ );
26
+ }
27
+ return {
28
+ uuid: "x402-evm:viem-relayer-adapter",
29
+ getSignerAddress: async () => {
30
+ const account = walletClient.account;
31
+ if (!account) {
32
+ throw new RelayerSubmitError(
33
+ "INTERNAL_ERROR",
34
+ "walletClient has no account; cannot resolve signer address"
35
+ );
36
+ }
37
+ return account.address;
38
+ },
39
+ isSignerContract: async () => false,
40
+ getChainId: async () => chainId,
41
+ getBalance: async (addressOrName) => {
42
+ const balance = await publicClient.getBalance({ address: addressOrName });
43
+ return balance;
44
+ },
45
+ estimateGas: async (req) => {
46
+ const account = walletClient.account;
47
+ const gas = await publicClient.estimateGas({
48
+ account: account ?? void 0,
49
+ to: req.to,
50
+ data: req.data,
51
+ value: req.value === void 0 ? void 0 : BigInt(req.value.toString())
52
+ });
53
+ return gas;
54
+ },
55
+ sendTransaction: async (req) => {
56
+ const account = walletClient.account;
57
+ if (!account) {
58
+ throw new RelayerSubmitError(
59
+ "INTERNAL_ERROR",
60
+ "walletClient has no account; cannot send transaction"
61
+ );
62
+ }
63
+ let hash;
64
+ try {
65
+ hash = await walletClient.sendTransaction({
66
+ account,
67
+ chain: walletClient.chain ?? null,
68
+ to: req.to,
69
+ data: req.data,
70
+ value: req.value === void 0 ? 0n : BigInt(req.value.toString())
71
+ });
72
+ } catch (e) {
73
+ throw classifyViemSendError(e);
74
+ }
75
+ return {
76
+ hash,
77
+ wait: async (confirmations) => {
78
+ const receipt = await publicClient.waitForTransactionReceipt({
79
+ hash,
80
+ confirmations,
81
+ timeout: receiptTimeoutMs
82
+ });
83
+ return mapReceipt(receipt);
84
+ }
85
+ };
86
+ },
87
+ call: async (req) => {
88
+ const result = await publicClient.call({
89
+ to: req.to,
90
+ data: req.data
91
+ });
92
+ return result.data ?? "0x";
93
+ },
94
+ send: async (method) => {
95
+ throw new RelayerSubmitError(
96
+ "INTERNAL_ERROR",
97
+ `x402-evm: relayer adapter does not support RPC method '${method}'; the relayer never signs typed data`
98
+ );
99
+ },
100
+ getTransactionReceipt: async (txHash) => {
101
+ const receipt = await publicClient.getTransactionReceipt({ hash: txHash });
102
+ return mapReceipt(receipt);
103
+ },
104
+ getCurrentTimeMs: async () => Date.now()
105
+ };
106
+ }
107
+ function mapReceipt(receipt) {
108
+ return {
109
+ from: receipt.from,
110
+ to: receipt.to ?? "",
111
+ status: receipt.status === "success" ? 1 : 0,
112
+ logs: receipt.logs.map((log) => ({ data: log.data, topics: [...log.topics] })),
113
+ transactionHash: receipt.transactionHash,
114
+ effectiveGasPrice: receipt.effectiveGasPrice,
115
+ blockNumber: Number(receipt.blockNumber),
116
+ gasUsed: receipt.gasUsed
117
+ };
118
+ }
119
+ function classifyViemSendError(e) {
120
+ const reason = e instanceof Error ? `sendTransaction failed: ${e.message}` : "sendTransaction failed";
121
+ if (hasViemCause(e, InsufficientFundsError)) {
122
+ return new RelayerSubmitError("INSUFFICIENT_FUNDS_FOR_GAS", reason, { cause: e });
123
+ }
124
+ if (hasViemCause(e, ExecutionRevertedError) || hasViemCause(e, ContractFunctionRevertedError) || hasViemCause(e, RawContractError)) {
125
+ return new RelayerSubmitError("ONCHAIN_REVERT", reason, { cause: e });
126
+ }
127
+ return new RelayerSubmitError("INTERNAL_ERROR", reason, { cause: e });
128
+ }
129
+ function hasViemCause(e, ctor) {
130
+ if (e instanceof ctor) return true;
131
+ if (!(e instanceof BaseError)) return false;
132
+ return e.walk((err) => err instanceof ctor) !== null;
133
+ }
134
+
135
+ export { RelayerSubmitError, classifyViemSendError, walletClientToWeb3LibAdapter };
136
+ //# sourceMappingURL=chunk-W5YOMJCB.js.map
137
+ //# sourceMappingURL=chunk-W5YOMJCB.js.map