@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"],"names":[],"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;AAAA,IACL,IAAA,EAAM,+BAAA;AAAA,IACN,kBAAkB,YAAY;AAC5B,MAAA,MAAM,UAAU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EAAA,IAAI,CAAA,YAAa,MAAM,OAAO,IAAA;AAC9B,EAAA,IAAI,EAAE,CAAA,YAAa,SAAA,CAAA,EAAY,OAAO,KAAA;AACtC,EAAA,OAAO,EAAE,IAAA,CAAK,CAAC,GAAA,KAAQ,GAAA,YAAe,IAAI,CAAA,KAAM,IAAA;AAClD","file":"chunk-W5YOMJCB.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"]}
@@ -0,0 +1,40 @@
1
+ import { encodeAbiParameters, decodeAbiParameters } from 'viem';
2
+
3
+ // src/codec/signed-payload.ts
4
+ var SIGNED_PAYLOAD_ABI = [
5
+ { name: "from", type: "address" },
6
+ { name: "functionName", type: "string" },
7
+ { name: "functionSignature", type: "bytes" },
8
+ { name: "nonce", type: "uint256" },
9
+ { name: "v", type: "uint8" },
10
+ { name: "r", type: "bytes32" },
11
+ { name: "s", type: "bytes32" }
12
+ ];
13
+ function encodeSignedPayload(metaTx) {
14
+ return encodeAbiParameters(SIGNED_PAYLOAD_ABI, [
15
+ metaTx.from,
16
+ metaTx.functionName,
17
+ metaTx.functionSignature,
18
+ BigInt(metaTx.nonce),
19
+ metaTx.sig.v,
20
+ metaTx.sig.r,
21
+ metaTx.sig.s
22
+ ]);
23
+ }
24
+ function decodeSignedPayload(signedPayload) {
25
+ const [from, functionName, functionSignature, nonce, v, r, s] = decodeAbiParameters(
26
+ SIGNED_PAYLOAD_ABI,
27
+ signedPayload
28
+ );
29
+ return {
30
+ from,
31
+ functionName,
32
+ functionSignature,
33
+ nonce: nonce.toString(),
34
+ sig: { v: Number(v), r, s }
35
+ };
36
+ }
37
+
38
+ export { decodeSignedPayload, encodeSignedPayload };
39
+ //# sourceMappingURL=chunk-YQO6KFMJ.js.map
40
+ //# sourceMappingURL=chunk-YQO6KFMJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/codec/signed-payload.ts"],"names":[],"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,OAAO,oBAAoB,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,GAAI,mBAAA;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":"chunk-YQO6KFMJ.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,26 @@
1
+ // src/internal/web3lib-stub.ts
2
+ var DUMMY_SIGNER_ADDRESS = "0x0000000000000000000000000000000000000001";
3
+ function unreachable(callerTag, method) {
4
+ return new Error(
5
+ `${callerTag}: stub Web3LibAdapter.${method}() should never be called. If you see this, core-sdk changed its typed-data-only behavior.`
6
+ );
7
+ }
8
+ function createCalldataOnlyWeb3LibAdapter(callerTag) {
9
+ return {
10
+ uuid: `${callerTag}:stub`,
11
+ getSignerAddress: () => Promise.resolve(DUMMY_SIGNER_ADDRESS),
12
+ isSignerContract: () => Promise.resolve(false),
13
+ getChainId: () => Promise.reject(unreachable(callerTag, "getChainId")),
14
+ getBalance: () => Promise.reject(unreachable(callerTag, "getBalance")),
15
+ estimateGas: () => Promise.reject(unreachable(callerTag, "estimateGas")),
16
+ sendTransaction: () => Promise.reject(unreachable(callerTag, "sendTransaction")),
17
+ call: () => Promise.reject(unreachable(callerTag, "call")),
18
+ send: () => Promise.reject(unreachable(callerTag, "send")),
19
+ getTransactionReceipt: () => Promise.reject(unreachable(callerTag, "getTransactionReceipt")),
20
+ getCurrentTimeMs: () => Promise.reject(unreachable(callerTag, "getCurrentTimeMs"))
21
+ };
22
+ }
23
+
24
+ export { createCalldataOnlyWeb3LibAdapter };
25
+ //# sourceMappingURL=chunk-YVUW4DX6.js.map
26
+ //# sourceMappingURL=chunk-YVUW4DX6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/internal/web3lib-stub.ts"],"names":[],"mappings":";AAYA,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,OAAA,CAAQ,KAAK,CAAA;AAAA,IAC7C,YAAY,MAAM,OAAA,CAAQ,OAAO,WAAA,CAAY,SAAA,EAAW,YAAY,CAAC,CAAA;AAAA,IACrE,YAAY,MAAM,OAAA,CAAQ,OAAO,WAAA,CAAY,SAAA,EAAW,YAAY,CAAC,CAAA;AAAA,IACrE,aAAa,MAAM,OAAA,CAAQ,OAAO,WAAA,CAAY,SAAA,EAAW,aAAa,CAAC,CAAA;AAAA,IACvE,iBAAiB,MAAM,OAAA,CAAQ,OAAO,WAAA,CAAY,SAAA,EAAW,iBAAiB,CAAC,CAAA;AAAA,IAC/E,MAAM,MAAM,OAAA,CAAQ,OAAO,WAAA,CAAY,SAAA,EAAW,MAAM,CAAC,CAAA;AAAA,IACzD,MAAM,MAAM,OAAA,CAAQ,OAAO,WAAA,CAAY,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":"chunk-YVUW4DX6.js","sourcesContent":["// 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,3 @@
1
+ export { decodeSignedPayload, encodeSignedPayload } from '../chunk-YQO6KFMJ.js';
2
+ //# sourceMappingURL=index.js.map
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,6 @@
1
+ export { buildCreateOfferAndCommitCalldata, buildCreateOfferCommitAndRedeemCalldata } from './chunk-2PRTTZRV.js';
2
+ export { RelayerSubmitError, classifyViemSendError, walletClientToWeb3LibAdapter } from './chunk-W5YOMJCB.js';
3
+ export { createCalldataOnlyWeb3LibAdapter } from './chunk-YVUW4DX6.js';
4
+ export { decodeSignedPayload, encodeSignedPayload } from './chunk-YQO6KFMJ.js';
5
+ //# sourceMappingURL=index.js.map
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@bosonprotocol/x402-evm",
3
+ "version": "0.1.0-alpha-0",
4
+ "license": "Apache-2.0",
5
+ "description": "Boson Protocol EVM calldata + adapter glue for the x402 escrow scheme — inner-action ABI encoding for the commit step and viem ↔ Web3LibAdapter bridges. Wraps @bosonprotocol/core-sdk for everything else.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/bosonprotocol/x402B.git",
9
+ "directory": "typescript/packages/evm"
10
+ },
11
+ "homepage": "https://github.com/bosonprotocol/x402B/tree/main/typescript/packages/evm",
12
+ "bugs": {
13
+ "url": "https://github.com/bosonprotocol/x402B/issues"
14
+ },
15
+ "keywords": [
16
+ "x402",
17
+ "boson-protocol",
18
+ "escrow",
19
+ "evm",
20
+ "meta-transaction",
21
+ "calldata"
22
+ ],
23
+ "main": "./dist/cjs/index.js",
24
+ "module": "./dist/esm/index.js",
25
+ "types": "./dist/cjs/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/cjs/index.d.ts",
29
+ "import": "./dist/esm/index.js",
30
+ "require": "./dist/cjs/index.js"
31
+ },
32
+ "./actions": {
33
+ "types": "./dist/cjs/actions/index.d.ts",
34
+ "import": "./dist/esm/actions/index.js",
35
+ "require": "./dist/cjs/actions/index.js"
36
+ },
37
+ "./codec": {
38
+ "types": "./dist/cjs/codec/index.d.ts",
39
+ "import": "./dist/esm/codec/index.js",
40
+ "require": "./dist/cjs/codec/index.js"
41
+ },
42
+ "./adapters": {
43
+ "types": "./dist/cjs/adapters/index.d.ts",
44
+ "import": "./dist/esm/adapters/index.js",
45
+ "require": "./dist/cjs/adapters/index.js"
46
+ }
47
+ },
48
+ "files": [
49
+ "dist",
50
+ "README.md",
51
+ "LICENSE"
52
+ ],
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "dependencies": {
57
+ "@bosonprotocol/common": "1.33.0-alpha.7",
58
+ "@bosonprotocol/core-sdk": "1.48.0-alpha.6",
59
+ "viem": "^2.39.3",
60
+ "@bosonprotocol/x402-core": "^0.1.0-alpha-0"
61
+ },
62
+ "devDependencies": {
63
+ "@types/node": "^20.17.10",
64
+ "tsup": "^8.3.5",
65
+ "typescript": "^5.7.2",
66
+ "vitest": "^2.1.8"
67
+ },
68
+ "scripts": {
69
+ "build": "tsup && node scripts/postbuild.mjs",
70
+ "test": "vitest run",
71
+ "lint": "eslint src test --max-warnings 0",
72
+ "clean": "rm -rf dist .turbo"
73
+ }
74
+ }