@bosonprotocol/x402-core 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.
- package/LICENSE +201 -0
- package/README.md +26 -0
- package/dist/cjs/eip712/index.d.ts +142 -0
- package/dist/cjs/eip712/index.js +224 -0
- package/dist/cjs/eip712/index.js.map +1 -0
- package/dist/cjs/eip712/token-auth/index.d.ts +259 -0
- package/dist/cjs/eip712/token-auth/index.js +221 -0
- package/dist/cjs/eip712/token-auth/index.js.map +1 -0
- package/dist/cjs/index.d.ts +15 -0
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/schemes/escrow/index.d.ts +1262 -0
- package/dist/cjs/schemes/escrow/index.js +228 -0
- package/dist/cjs/schemes/escrow/index.js.map +1 -0
- package/dist/cjs/state-machine/index.d.ts +86 -0
- package/dist/cjs/state-machine/index.js +146 -0
- package/dist/cjs/state-machine/index.js.map +1 -0
- package/dist/cjs/states-Q2FJASHh.d.ts +38 -0
- package/dist/esm/chunk-7IY3WEFZ.js +10 -0
- package/dist/esm/chunk-7IY3WEFZ.js.map +1 -0
- package/dist/esm/eip712/index.js +213 -0
- package/dist/esm/eip712/index.js.map +1 -0
- package/dist/esm/eip712/token-auth/index.js +189 -0
- package/dist/esm/eip712/token-auth/index.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/schemes/escrow/index.js +202 -0
- package/dist/esm/schemes/escrow/index.js.map +1 -0
- package/dist/esm/state-machine/index.js +127 -0
- package/dist/esm/state-machine/index.js.map +1 -0
- package/dist/schemas/next_actions.schema.json +87 -0
- package/dist/schemas/payment_payload.schema.json +156 -0
- package/dist/schemas/payment_requirements.schema.json +135 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Boson Protocol
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @bosonprotocol/x402-core
|
|
2
|
+
|
|
3
|
+
`escrow`-scheme primitives for [x402B](https://github.com/bosonprotocol/x402B) — Boson Protocol's implementation of the [`x402-escrow-schema`](https://github.com/bosonprotocol/x402-escrow-schema).
|
|
4
|
+
|
|
5
|
+
This is the leaf package that every other `@bosonprotocol/x402-*` package depends on. It will provide:
|
|
6
|
+
|
|
7
|
+
- JSON schemas + TypeScript types + zod validators for the `escrow` scheme wire format
|
|
8
|
+
- EIP-712 builders for the Boson `FullOffer`, the protocol meta-transaction envelope, and the four BPIP-12 token-authorization strategies (ERC-3009 `ReceiveWithAuthorization`, EIP-2612 `Permit`, Uniswap Permit2, plain approve)
|
|
9
|
+
- Exchange state machine model (states + legal transitions + `boson-*` action ids)
|
|
10
|
+
|
|
11
|
+
The escrow scheme is intended as a drop-in addition to existing x402 servers and clients — types here extend the base `PaymentRequirements` / `PaymentPayload` from [`@x402/core`](https://www.npmjs.com/package/@x402/core).
|
|
12
|
+
|
|
13
|
+
## Status
|
|
14
|
+
|
|
15
|
+
Pre-release skeleton. The public API surface lands incrementally; the package currently exports nothing.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @bosonprotocol/x402-core
|
|
21
|
+
# or: npm install @bosonprotocol/x402-core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
[Apache-2.0](./LICENSE)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Address, Hex } from 'viem';
|
|
2
|
+
import { FullOfferArgs } from '@bosonprotocol/common';
|
|
3
|
+
|
|
4
|
+
/** Unsigned FullOffer payload — same shape core-sdk accepts. */
|
|
5
|
+
type UnsignedFullOffer = Omit<FullOfferArgs, "signature">;
|
|
6
|
+
/** A single EIP-712 type field — a `{ name, type }` pair. */
|
|
7
|
+
type TypedDataField = {
|
|
8
|
+
name: string;
|
|
9
|
+
type: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* EIP-712 typed-data ready for any viem signer. Uses a deliberately-loose
|
|
13
|
+
* `types` shape (not viem's `TypedData`) because Boson's `EIP712Domain`
|
|
14
|
+
* field set is non-standard and viem's strict union rejects it; consumers
|
|
15
|
+
* pass this shape directly to `hashTypedData` / `signTypedData` /
|
|
16
|
+
* `recoverTypedDataAddress`, which accept it structurally.
|
|
17
|
+
*/
|
|
18
|
+
interface FullOfferTypedData {
|
|
19
|
+
domain: Record<string, unknown>;
|
|
20
|
+
types: Record<string, readonly TypedDataField[]>;
|
|
21
|
+
primaryType: "FullOffer";
|
|
22
|
+
message: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
interface FullOfferArgsForBuilder {
|
|
25
|
+
fullOffer: UnsignedFullOffer;
|
|
26
|
+
/** Address of the Boson escrow contract — the EIP-712 verifyingContract. */
|
|
27
|
+
verifyingContract: Address;
|
|
28
|
+
chainId: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Build EIP-712 typed-data for a FullOffer that the seller will sign.
|
|
32
|
+
* Delegates the struct definition to `@bosonprotocol/core-sdk` so we stay in
|
|
33
|
+
* lock-step with whatever shape the deployed protocol's `verifyOffer`
|
|
34
|
+
* accepts.
|
|
35
|
+
*/
|
|
36
|
+
declare function fullOfferTypedData({ fullOffer, verifyingContract, chainId, }: FullOfferArgsForBuilder): Promise<FullOfferTypedData>;
|
|
37
|
+
/** EIP-712 digest for a FullOffer — what the seller signs. */
|
|
38
|
+
declare function hashFullOffer(args: FullOfferArgsForBuilder): Promise<Hex>;
|
|
39
|
+
/** Recover the seller address from a FullOffer signature. */
|
|
40
|
+
declare function recoverFullOfferSigner(args: FullOfferArgsForBuilder & {
|
|
41
|
+
signature: Hex;
|
|
42
|
+
}): Promise<Address>;
|
|
43
|
+
|
|
44
|
+
declare const META_TRANSACTION_PRIMARY_TYPE: "MetaTransaction";
|
|
45
|
+
/** Strongly-typed message body — what the buyer signs. */
|
|
46
|
+
interface MetaTransactionMessage {
|
|
47
|
+
/** `MetaTransactionsHandlerFacet.usedNonce[from][nonce]` replay-protection slot. */
|
|
48
|
+
nonce: bigint;
|
|
49
|
+
/** Buyer EOA. Must match the signature recovery on-chain. */
|
|
50
|
+
from: Address;
|
|
51
|
+
/** Address of the Boson escrow contract the call targets. */
|
|
52
|
+
contractAddress: Address;
|
|
53
|
+
/**
|
|
54
|
+
* Solidity function-name+selector string, e.g.
|
|
55
|
+
* `"createOfferCommitAndRedeem(BosonTypes.FullOffer,address,bytes,uint256)"`.
|
|
56
|
+
*/
|
|
57
|
+
functionName: string;
|
|
58
|
+
/** ABI-encoded function-call data. */
|
|
59
|
+
functionSignature: Hex;
|
|
60
|
+
}
|
|
61
|
+
interface MetaTransactionTypedData {
|
|
62
|
+
domain: Record<string, unknown>;
|
|
63
|
+
types: Record<string, readonly TypedDataField[]>;
|
|
64
|
+
primaryType: typeof META_TRANSACTION_PRIMARY_TYPE;
|
|
65
|
+
message: Record<string, unknown>;
|
|
66
|
+
}
|
|
67
|
+
interface MetaTransactionArgs {
|
|
68
|
+
chainId: number;
|
|
69
|
+
/** Address of the Boson escrow contract — the EIP-712 verifyingContract. */
|
|
70
|
+
verifyingContract: Address;
|
|
71
|
+
message: MetaTransactionMessage;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Build the EIP-712 typed-data for a Boson meta-transaction.
|
|
75
|
+
*
|
|
76
|
+
* Pass the result to:
|
|
77
|
+
* - `account.signTypedData(typedData)` (a viem `LocalAccount` / HD account);
|
|
78
|
+
* - `walletClient.signTypedData({ account, ...typedData })` (a viem
|
|
79
|
+
* `WalletClient` for browser-wallet / RPC signers).
|
|
80
|
+
*
|
|
81
|
+
* Use {@link recoverMetaTransactionSigner} to verify a signature.
|
|
82
|
+
*/
|
|
83
|
+
declare function metaTransactionTypedData({ message, chainId, verifyingContract, }: MetaTransactionArgs): Promise<MetaTransactionTypedData>;
|
|
84
|
+
/** EIP-712 digest for the meta-tx — what gets signed. */
|
|
85
|
+
declare function hashMetaTransaction(args: MetaTransactionArgs): Promise<Hex>;
|
|
86
|
+
/** Recover the signer address from a meta-tx signature. */
|
|
87
|
+
declare function recoverMetaTransactionSigner(args: MetaTransactionArgs & {
|
|
88
|
+
signature: Hex;
|
|
89
|
+
}): Promise<Address>;
|
|
90
|
+
/** Loose typed-data shape — covers the action-specific variants below. */
|
|
91
|
+
interface ActionMetaTransactionTypedData {
|
|
92
|
+
domain: Record<string, unknown>;
|
|
93
|
+
types: Record<string, readonly TypedDataField[]>;
|
|
94
|
+
primaryType: string;
|
|
95
|
+
message: Record<string, unknown>;
|
|
96
|
+
}
|
|
97
|
+
interface BaseActionArgs {
|
|
98
|
+
chainId: number;
|
|
99
|
+
/** Address of the Boson escrow contract — the EIP-712 verifyingContract. */
|
|
100
|
+
verifyingContract: Address;
|
|
101
|
+
/** Boson `MetaTransactionsHandlerFacet.usedNonce[from][nonce]` replay-protection slot. */
|
|
102
|
+
nonce: bigint;
|
|
103
|
+
/** Buyer / signer EOA — populates the typed-data `message.from`. */
|
|
104
|
+
from: Address;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Build the EIP-712 typed-data for an EXCHANGE-keyed post-commit meta-tx
|
|
108
|
+
* (`redeemVoucher`, `cancelVoucher`, `completeExchange`,
|
|
109
|
+
* `raiseDispute`, `retractDispute`, `escalateDispute`). All six share
|
|
110
|
+
* the `MetaTxExchange` primary type and `exchangeDetails: {exchangeId}`
|
|
111
|
+
* sub-struct; the only difference between them is `message.functionName`.
|
|
112
|
+
*/
|
|
113
|
+
declare function metaTransactionExchangeTypedData(args: BaseActionArgs & {
|
|
114
|
+
/** Boson function signature, e.g. `"redeemVoucher(uint256)"`. */
|
|
115
|
+
functionName: string;
|
|
116
|
+
/** Exchange the action targets. */
|
|
117
|
+
exchangeId: bigint;
|
|
118
|
+
}): Promise<ActionMetaTransactionTypedData>;
|
|
119
|
+
/**
|
|
120
|
+
* Build the EIP-712 typed-data for `resolveDispute` — `MetaTxDisputeResolution`
|
|
121
|
+
* primary type with a nested `disputeResolutionDetails` struct carrying
|
|
122
|
+
* the exchange id, the buyer's percent split, and the counterparty's
|
|
123
|
+
* signature.
|
|
124
|
+
*/
|
|
125
|
+
declare function metaTransactionDisputeResolutionTypedData(args: BaseActionArgs & {
|
|
126
|
+
exchangeId: bigint;
|
|
127
|
+
buyerPercentBasisPoints: bigint;
|
|
128
|
+
/** Counterparty's signature over the resolution proposal — packed `r||s||v` hex. */
|
|
129
|
+
counterpartySig: Hex;
|
|
130
|
+
}): Promise<ActionMetaTransactionTypedData>;
|
|
131
|
+
/**
|
|
132
|
+
* Build the EIP-712 typed-data for `withdrawFunds` — `MetaTxFund` primary
|
|
133
|
+
* type with a nested `fundDetails` struct carrying the entity id, the
|
|
134
|
+
* token-address list, and the per-token amounts.
|
|
135
|
+
*/
|
|
136
|
+
declare function metaTransactionFundTypedData(args: BaseActionArgs & {
|
|
137
|
+
entityId: bigint;
|
|
138
|
+
tokenList: readonly Address[];
|
|
139
|
+
tokenAmounts: readonly bigint[];
|
|
140
|
+
}): Promise<ActionMetaTransactionTypedData>;
|
|
141
|
+
|
|
142
|
+
export { type ActionMetaTransactionTypedData, type FullOfferArgsForBuilder, type FullOfferTypedData, META_TRANSACTION_PRIMARY_TYPE, type MetaTransactionArgs, type MetaTransactionMessage, type MetaTransactionTypedData, type TypedDataField, type UnsignedFullOffer, fullOfferTypedData, hashFullOffer, hashMetaTransaction, metaTransactionDisputeResolutionTypedData, metaTransactionExchangeTypedData, metaTransactionFundTypedData, metaTransactionTypedData, recoverFullOfferSigner, recoverMetaTransactionSigner };
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var coreSdk = require('@bosonprotocol/core-sdk');
|
|
4
|
+
var viem = require('viem');
|
|
5
|
+
|
|
6
|
+
// src/eip712/meta-transaction.ts
|
|
7
|
+
|
|
8
|
+
// src/internal/web3lib-stub.ts
|
|
9
|
+
function unreachable(callerTag, method) {
|
|
10
|
+
return new Error(
|
|
11
|
+
`${callerTag}: stub Web3LibAdapter.${method}() should never be called. If you see this, either core-sdk changed its behaviour or the stub leaked into a non-signing-only path \u2014 file a bug.`
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
function createThrowingWeb3LibAdapter(callerTag) {
|
|
15
|
+
return {
|
|
16
|
+
uuid: `${callerTag}:stub`,
|
|
17
|
+
getSignerAddress: () => Promise.reject(unreachable(callerTag, "getSignerAddress")),
|
|
18
|
+
isSignerContract: () => Promise.reject(unreachable(callerTag, "isSignerContract")),
|
|
19
|
+
getChainId: () => Promise.reject(unreachable(callerTag, "getChainId")),
|
|
20
|
+
getBalance: () => Promise.reject(unreachable(callerTag, "getBalance")),
|
|
21
|
+
estimateGas: () => Promise.reject(unreachable(callerTag, "estimateGas")),
|
|
22
|
+
sendTransaction: () => Promise.reject(unreachable(callerTag, "sendTransaction")),
|
|
23
|
+
call: () => Promise.reject(unreachable(callerTag, "call")),
|
|
24
|
+
send: () => Promise.reject(unreachable(callerTag, "send")),
|
|
25
|
+
getTransactionReceipt: () => Promise.reject(unreachable(callerTag, "getTransactionReceipt")),
|
|
26
|
+
getCurrentTimeMs: () => Promise.reject(unreachable(callerTag, "getCurrentTimeMs"))
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function createTypedDataInterceptAdapter(args) {
|
|
30
|
+
const dummy = args.dummySignature ?? DEFAULT_DUMMY_SIGNATURE_65;
|
|
31
|
+
let captured;
|
|
32
|
+
const adapter = {
|
|
33
|
+
uuid: `${args.callerTag}:typed-data-intercept`,
|
|
34
|
+
getSignerAddress: () => Promise.resolve(args.signerAddress),
|
|
35
|
+
isSignerContract: () => Promise.resolve(false),
|
|
36
|
+
getChainId: () => Promise.resolve(args.chainId),
|
|
37
|
+
send: async (method, params) => {
|
|
38
|
+
if (method !== "eth_signTypedData_v4") {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`${args.callerTag}: unexpected RPC method during typed-data capture: ${method}`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
const json = params[1];
|
|
44
|
+
if (typeof json !== "string") {
|
|
45
|
+
throw new Error(`${args.callerTag}: eth_signTypedData_v4 payload is not a JSON string`);
|
|
46
|
+
}
|
|
47
|
+
captured = args.parse(json);
|
|
48
|
+
return dummy;
|
|
49
|
+
},
|
|
50
|
+
getBalance: () => Promise.reject(unreachable(args.callerTag, "getBalance")),
|
|
51
|
+
estimateGas: () => Promise.reject(unreachable(args.callerTag, "estimateGas")),
|
|
52
|
+
sendTransaction: () => Promise.reject(unreachable(args.callerTag, "sendTransaction")),
|
|
53
|
+
call: () => Promise.reject(unreachable(args.callerTag, "call")),
|
|
54
|
+
getTransactionReceipt: () => Promise.reject(unreachable(args.callerTag, "getTransactionReceipt")),
|
|
55
|
+
getCurrentTimeMs: () => Promise.reject(unreachable(args.callerTag, "getCurrentTimeMs"))
|
|
56
|
+
};
|
|
57
|
+
return { adapter, read: () => captured };
|
|
58
|
+
}
|
|
59
|
+
var DEFAULT_DUMMY_SIGNATURE_65 = `0x${"11".repeat(32)}${"22".repeat(32)}1b`;
|
|
60
|
+
|
|
61
|
+
// src/eip712/meta-transaction.ts
|
|
62
|
+
var META_TRANSACTION_PRIMARY_TYPE = "MetaTransaction";
|
|
63
|
+
var STUB_CALLER_TAG = "@bosonprotocol/x402-core:meta-transaction";
|
|
64
|
+
async function metaTransactionTypedData({
|
|
65
|
+
message,
|
|
66
|
+
chainId,
|
|
67
|
+
verifyingContract
|
|
68
|
+
}) {
|
|
69
|
+
const intercept = createTypedDataInterceptAdapter({
|
|
70
|
+
callerTag: STUB_CALLER_TAG,
|
|
71
|
+
// signMetaTx puts the signer's address into the `from` field of the
|
|
72
|
+
// typed-data message — we want it to match the caller-supplied `from`.
|
|
73
|
+
signerAddress: message.from,
|
|
74
|
+
chainId,
|
|
75
|
+
parse: (json) => JSON.parse(json)
|
|
76
|
+
});
|
|
77
|
+
await coreSdk.metaTx.handler.signMetaTx({
|
|
78
|
+
web3Lib: intercept.adapter,
|
|
79
|
+
nonce: message.nonce.toString(),
|
|
80
|
+
metaTxHandlerAddress: verifyingContract,
|
|
81
|
+
chainId,
|
|
82
|
+
functionName: message.functionName,
|
|
83
|
+
functionSignature: message.functionSignature
|
|
84
|
+
});
|
|
85
|
+
const captured = intercept.read();
|
|
86
|
+
if (!captured) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
"@bosonprotocol/x402-core:meta-transaction: signMetaTx did not invoke eth_signTypedData_v4 \u2014 core-sdk internals may have changed"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return captured;
|
|
92
|
+
}
|
|
93
|
+
async function hashMetaTransaction(args) {
|
|
94
|
+
const td = await metaTransactionTypedData(args);
|
|
95
|
+
return viem.hashTypedData(td);
|
|
96
|
+
}
|
|
97
|
+
async function recoverMetaTransactionSigner(args) {
|
|
98
|
+
const { signature, ...rest } = args;
|
|
99
|
+
const td = await metaTransactionTypedData(rest);
|
|
100
|
+
return viem.recoverTypedDataAddress({
|
|
101
|
+
domain: td.domain,
|
|
102
|
+
types: td.types,
|
|
103
|
+
primaryType: td.primaryType,
|
|
104
|
+
message: td.message,
|
|
105
|
+
signature
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
async function metaTransactionExchangeTypedData(args) {
|
|
109
|
+
return callCoreSdkForTypedData(
|
|
110
|
+
args.from,
|
|
111
|
+
args.chainId,
|
|
112
|
+
async (web3Lib) => coreSdk.metaTx.handler.signMetaTxRedeemVoucher({
|
|
113
|
+
web3Lib,
|
|
114
|
+
nonce: args.nonce.toString(),
|
|
115
|
+
metaTxHandlerAddress: args.verifyingContract,
|
|
116
|
+
chainId: args.chainId,
|
|
117
|
+
exchangeId: args.exchangeId.toString(),
|
|
118
|
+
returnTypedDataToSign: true
|
|
119
|
+
})
|
|
120
|
+
).then((td) => withOverriddenFunctionName(td, args.functionName));
|
|
121
|
+
}
|
|
122
|
+
async function metaTransactionDisputeResolutionTypedData(args) {
|
|
123
|
+
return callCoreSdkForTypedData(
|
|
124
|
+
args.from,
|
|
125
|
+
args.chainId,
|
|
126
|
+
async (web3Lib) => coreSdk.metaTx.handler.signMetaTxResolveDispute({
|
|
127
|
+
web3Lib,
|
|
128
|
+
nonce: args.nonce.toString(),
|
|
129
|
+
metaTxHandlerAddress: args.verifyingContract,
|
|
130
|
+
chainId: args.chainId,
|
|
131
|
+
exchangeId: args.exchangeId.toString(),
|
|
132
|
+
buyerPercent: args.buyerPercentBasisPoints.toString(),
|
|
133
|
+
counterpartySig: args.counterpartySig,
|
|
134
|
+
returnTypedDataToSign: true
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
async function metaTransactionFundTypedData(args) {
|
|
139
|
+
return callCoreSdkForTypedData(
|
|
140
|
+
args.from,
|
|
141
|
+
args.chainId,
|
|
142
|
+
async (web3Lib) => coreSdk.metaTx.handler.signMetaTxWithdrawFunds({
|
|
143
|
+
web3Lib,
|
|
144
|
+
nonce: args.nonce.toString(),
|
|
145
|
+
metaTxHandlerAddress: args.verifyingContract,
|
|
146
|
+
chainId: args.chainId,
|
|
147
|
+
entityId: args.entityId.toString(),
|
|
148
|
+
tokenList: args.tokenList,
|
|
149
|
+
tokenAmounts: args.tokenAmounts.map((amount) => amount.toString()),
|
|
150
|
+
returnTypedDataToSign: true
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
async function callCoreSdkForTypedData(from, chainId, invoke) {
|
|
155
|
+
const intercept = createTypedDataInterceptAdapter({
|
|
156
|
+
callerTag: STUB_CALLER_TAG,
|
|
157
|
+
signerAddress: from,
|
|
158
|
+
chainId,
|
|
159
|
+
// `parse` is wired up but never called — `returnTypedDataToSign: true`
|
|
160
|
+
// short-circuits in core-sdk before `eth_signTypedData_v4` would fire.
|
|
161
|
+
parse: (json) => JSON.parse(json)
|
|
162
|
+
});
|
|
163
|
+
const result = await invoke(intercept.adapter);
|
|
164
|
+
return {
|
|
165
|
+
domain: result.domain,
|
|
166
|
+
types: result.types,
|
|
167
|
+
primaryType: result.primaryType,
|
|
168
|
+
message: result.message
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function withOverriddenFunctionName(td, functionName) {
|
|
172
|
+
return {
|
|
173
|
+
...td,
|
|
174
|
+
message: { ...td.message, functionName }
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
var STUB_CALLER_TAG2 = "@bosonprotocol/x402-core:full-offer";
|
|
178
|
+
async function fullOfferTypedData({
|
|
179
|
+
fullOffer,
|
|
180
|
+
verifyingContract,
|
|
181
|
+
chainId
|
|
182
|
+
}) {
|
|
183
|
+
const sd = await coreSdk.exchanges.handler.signFullOffer({
|
|
184
|
+
fullOfferArgsUnsigned: fullOffer,
|
|
185
|
+
contractAddress: verifyingContract,
|
|
186
|
+
chainId,
|
|
187
|
+
web3Lib: createThrowingWeb3LibAdapter(STUB_CALLER_TAG2),
|
|
188
|
+
returnTypedDataToSign: true
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
domain: sd.domain,
|
|
192
|
+
types: sd.types,
|
|
193
|
+
primaryType: "FullOffer",
|
|
194
|
+
message: sd.message
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
async function hashFullOffer(args) {
|
|
198
|
+
const td = await fullOfferTypedData(args);
|
|
199
|
+
return viem.hashTypedData(td);
|
|
200
|
+
}
|
|
201
|
+
async function recoverFullOfferSigner(args) {
|
|
202
|
+
const { signature, ...rest } = args;
|
|
203
|
+
const td = await fullOfferTypedData(rest);
|
|
204
|
+
return viem.recoverTypedDataAddress({
|
|
205
|
+
domain: td.domain,
|
|
206
|
+
types: td.types,
|
|
207
|
+
primaryType: td.primaryType,
|
|
208
|
+
message: td.message,
|
|
209
|
+
signature
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
exports.META_TRANSACTION_PRIMARY_TYPE = META_TRANSACTION_PRIMARY_TYPE;
|
|
214
|
+
exports.fullOfferTypedData = fullOfferTypedData;
|
|
215
|
+
exports.hashFullOffer = hashFullOffer;
|
|
216
|
+
exports.hashMetaTransaction = hashMetaTransaction;
|
|
217
|
+
exports.metaTransactionDisputeResolutionTypedData = metaTransactionDisputeResolutionTypedData;
|
|
218
|
+
exports.metaTransactionExchangeTypedData = metaTransactionExchangeTypedData;
|
|
219
|
+
exports.metaTransactionFundTypedData = metaTransactionFundTypedData;
|
|
220
|
+
exports.metaTransactionTypedData = metaTransactionTypedData;
|
|
221
|
+
exports.recoverFullOfferSigner = recoverFullOfferSigner;
|
|
222
|
+
exports.recoverMetaTransactionSigner = recoverMetaTransactionSigner;
|
|
223
|
+
//# sourceMappingURL=index.js.map
|
|
224
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/internal/web3lib-stub.ts","../../../src/eip712/meta-transaction.ts","../../../src/eip712/full-offer.ts"],"names":["metaTx","hashTypedData","recoverTypedDataAddress","STUB_CALLER_TAG","exchanges"],"mappings":";;;;;;;;AA6BO,SAAS,WAAA,CAAY,WAAmB,MAAA,EAAuB;AACpE,EAAA,OAAO,IAAI,KAAA;AAAA,IACT,CAAA,EAAG,SAAS,CAAA,sBAAA,EAAyB,MAAM,CAAA,oJAAA;AAAA,GAG7C;AACF;AAOO,SAAS,6BAA6B,SAAA,EAAmC;AAC9E,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,GAAG,SAAS,CA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AAA,IACX,OAAO,EAAA,CAAG,KAAA;AAAA,IACV,aAAa,EAAA,CAAG,WAAA;AAAA,IAChB,SAAS,EAAA,CAAG,OAAA;AAAA,IACZ;AAAA,GAC2D,CAAA;AAC/D","file":"index.js","sourcesContent":["// Shared stub `Web3LibAdapter` factories.\n//\n// `@bosonprotocol/core-sdk`'s signing helpers all take a `Web3LibAdapter`\n// even when no signing actually happens — e.g. `signFullOffer({\n// returnTypedDataToSign: true })` and `signMetaTx` are typed-data-only paths\n// where the adapter is structural baggage. We pass a stub adapter whose\n// methods throw if invoked, so that any future leak into a non-signing-only\n// path is loud rather than silent.\n//\n// Two flavours live here:\n//\n// - {@link createThrowingWeb3LibAdapter} — every method rejects. Used by\n// `eip712/full-offer.ts` (which truly invokes nothing).\n// - {@link createTypedDataInterceptAdapter} — captures the structured\n// data passed to `eth_signTypedData_v4` and otherwise rejects. Used by\n// `eip712/meta-transaction.ts` to extract the typed-data core-sdk\n// would otherwise ship straight to a wallet.\n//\n// This module is internal — not part of the package's public `exports`\n// map. Consumers stay on the public typed-data builders; the stubs are\n// kept here so the same loud-error idiom is shared in one place.\n//\n// {@link unreachable} is exported for callers (e.g. the intercept adapter)\n// that need to compose a custom adapter and want the same error wording.\n\nimport type { Web3LibAdapter } from \"@bosonprotocol/common\";\nimport type { Hex } from \"viem\";\n\n/** Error builder for stub methods that should never be invoked. */\nexport function unreachable(callerTag: string, method: string): Error {\n return new Error(\n `${callerTag}: stub Web3LibAdapter.${method}() should never be called. ` +\n `If you see this, either core-sdk changed its behaviour or the stub leaked ` +\n `into a non-signing-only path — file a bug.`,\n );\n}\n\n/**\n * Build a `Web3LibAdapter` whose every method rejects with {@link unreachable}.\n * `callerTag` is interpolated into the error message so the offending stub\n * site is greppable from production logs.\n */\nexport function createThrowingWeb3LibAdapter(callerTag: string): Web3LibAdapter {\n return {\n uuid: `${callerTag}:stub`,\n getSignerAddress: () => Promise.reject(unreachable(callerTag, \"getSignerAddress\")),\n isSignerContract: () => Promise.reject(unreachable(callerTag, \"isSignerContract\")),\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\n/** Bag returned by {@link createTypedDataInterceptAdapter}. */\nexport interface TypedDataIntercept<T> {\n adapter: Web3LibAdapter;\n /** Whatever the intercept captured, or `undefined` if `send` never fired. */\n read(): T | undefined;\n}\n\n/**\n * Build a `Web3LibAdapter` that captures the second argument to\n * `send(\"eth_signTypedData_v4\", [from, json])` (a JSON-encoded typed-data\n * object), parses it through `parse`, and stores the result for later\n * retrieval. `getSignerAddress`, `isSignerContract`, and `getChainId` are\n * answered locally so core-sdk's signing helpers don't blow up; every\n * other method rejects with {@link unreachable}.\n *\n * The 65-byte `dummySignature` returned from `send` is unused downstream —\n * core-sdk's `getSignatureParameters` only slices it without validation.\n */\nexport function createTypedDataInterceptAdapter<T>(args: {\n callerTag: string;\n signerAddress: `0x${string}`;\n chainId: number;\n parse: (jsonPayload: string) => T;\n dummySignature?: Hex;\n}): TypedDataIntercept<T> {\n const dummy = args.dummySignature ?? DEFAULT_DUMMY_SIGNATURE_65;\n let captured: T | undefined;\n\n const adapter: Web3LibAdapter = {\n uuid: `${args.callerTag}:typed-data-intercept`,\n getSignerAddress: () => Promise.resolve(args.signerAddress),\n isSignerContract: () => Promise.resolve(false),\n getChainId: () => Promise.resolve(args.chainId),\n send: async (method, params) => {\n if (method !== \"eth_signTypedData_v4\") {\n throw new Error(\n `${args.callerTag}: unexpected RPC method during typed-data capture: ${method}`,\n );\n }\n const json = (params as unknown[])[1];\n if (typeof json !== \"string\") {\n throw new Error(`${args.callerTag}: eth_signTypedData_v4 payload is not a JSON string`);\n }\n captured = args.parse(json);\n return dummy;\n },\n getBalance: () => Promise.reject(unreachable(args.callerTag, \"getBalance\")),\n estimateGas: () => Promise.reject(unreachable(args.callerTag, \"estimateGas\")),\n sendTransaction: () => Promise.reject(unreachable(args.callerTag, \"sendTransaction\")),\n call: () => Promise.reject(unreachable(args.callerTag, \"call\")),\n getTransactionReceipt: () =>\n Promise.reject(unreachable(args.callerTag, \"getTransactionReceipt\")),\n getCurrentTimeMs: () => Promise.reject(unreachable(args.callerTag, \"getCurrentTimeMs\")),\n };\n\n return { adapter, read: () => captured };\n}\n\n// Any 65-byte hex; the value is irrelevant — core-sdk's\n// `getSignatureParameters` only slices it without validation.\nconst DEFAULT_DUMMY_SIGNATURE_65: Hex = `0x${\"11\".repeat(32)}${\"22\".repeat(32)}1b`;\n","// EIP-712 typed-data builder for the Boson Protocol meta-transaction envelope.\n//\n// The MetaTransaction struct shape and the salt-flavor EIP-712 domain are\n// fully owned by `@bosonprotocol/core-sdk`'s\n// `metaTx.handler.signMetaTx`. Rather than re-declaring them here (and risking\n// drift), we route the signing call through a stub `Web3LibAdapter` that\n// intercepts `eth_signTypedData_v4` to capture the structured data, then\n// returns a dummy 65-byte signature so signMetaTx can finish without errors.\n// The intercept adapter is built by the shared\n// `createTypedDataInterceptAdapter` factory from `internal/web3lib-stub.ts`,\n// so the same loud-error semantics apply to any future helper that needs\n// to extract typed-data out of core-sdk.\n//\n// The captured object is exactly what the deployed protocol's\n// `MetaTransactionsHandlerFacet` recovers signatures against.\n//\n// The same typed-data is consumed by both:\n//\n// 1. `MetaTransactionsHandlerFacet.executeMetaTransaction(...)` — the\n// existing Boson entrypoint, already supported by `@bosonprotocol/core-sdk`.\n// Used when no token-transfer authorization payloads need to be queued\n// (e.g. `tokenAuthStrategy: \"none\"` flows where the buyer has\n// pre-approved the escrow contract).\n//\n// 2. `MetaTransactionsHandlerFacet.executeMetaTransactionWithTokenTransferAuthorization(...)`\n// — the BPIP-12 entrypoint. Used when ERC-3009 / EIP-2612 / Permit2\n// payloads are queued alongside the meta-tx.\n//\n// The buyer signs once. Choice of on-chain entrypoint is the relayer's, and\n// happens at calldata-build time downstream (in `@bosonprotocol/x402-evm`).\n\nimport { metaTx } from \"@bosonprotocol/core-sdk\";\nimport { hashTypedData, recoverTypedDataAddress, type Address, type Hex } from \"viem\";\n\nimport { createTypedDataInterceptAdapter } from \"../internal/web3lib-stub.js\";\nimport type { TypedDataField } from \"./full-offer.js\";\n\nexport const META_TRANSACTION_PRIMARY_TYPE = \"MetaTransaction\" as const;\n\n/** Strongly-typed message body — what the buyer signs. */\nexport interface MetaTransactionMessage {\n /** `MetaTransactionsHandlerFacet.usedNonce[from][nonce]` replay-protection slot. */\n nonce: bigint;\n /** Buyer EOA. Must match the signature recovery on-chain. */\n from: Address;\n /** Address of the Boson escrow contract the call targets. */\n contractAddress: Address;\n /**\n * Solidity function-name+selector string, e.g.\n * `\"createOfferCommitAndRedeem(BosonTypes.FullOffer,address,bytes,uint256)\"`.\n */\n functionName: string;\n /** ABI-encoded function-call data. */\n functionSignature: Hex;\n}\n\nexport interface MetaTransactionTypedData {\n domain: Record<string, unknown>;\n types: Record<string, readonly TypedDataField[]>;\n primaryType: typeof META_TRANSACTION_PRIMARY_TYPE;\n message: Record<string, unknown>;\n}\n\nexport interface MetaTransactionArgs {\n chainId: number;\n /** Address of the Boson escrow contract — the EIP-712 verifyingContract. */\n verifyingContract: Address;\n message: MetaTransactionMessage;\n}\n\nconst STUB_CALLER_TAG = \"@bosonprotocol/x402-core:meta-transaction\";\n\n/**\n * Build the EIP-712 typed-data for a Boson meta-transaction.\n *\n * Pass the result to:\n * - `account.signTypedData(typedData)` (a viem `LocalAccount` / HD account);\n * - `walletClient.signTypedData({ account, ...typedData })` (a viem\n * `WalletClient` for browser-wallet / RPC signers).\n *\n * Use {@link recoverMetaTransactionSigner} to verify a signature.\n */\nexport async function metaTransactionTypedData({\n message,\n chainId,\n verifyingContract,\n}: MetaTransactionArgs): Promise<MetaTransactionTypedData> {\n const intercept = createTypedDataInterceptAdapter<MetaTransactionTypedData>({\n callerTag: STUB_CALLER_TAG,\n // signMetaTx puts the signer's address into the `from` field of the\n // typed-data message — we want it to match the caller-supplied `from`.\n signerAddress: message.from,\n chainId,\n parse: (json) => JSON.parse(json) as MetaTransactionTypedData,\n });\n\n await metaTx.handler.signMetaTx({\n web3Lib: intercept.adapter,\n nonce: message.nonce.toString(),\n metaTxHandlerAddress: verifyingContract,\n chainId,\n functionName: message.functionName,\n functionSignature: message.functionSignature,\n });\n\n const captured = intercept.read();\n if (!captured) {\n throw new Error(\n \"@bosonprotocol/x402-core:meta-transaction: signMetaTx did not invoke eth_signTypedData_v4 — \" +\n \"core-sdk internals may have changed\",\n );\n }\n return captured;\n}\n\n/** EIP-712 digest for the meta-tx — what gets signed. */\nexport async function hashMetaTransaction(args: MetaTransactionArgs): Promise<Hex> {\n const td = await metaTransactionTypedData(args);\n return hashTypedData(td as Parameters<typeof hashTypedData>[0]);\n}\n\n/** Recover the signer address from a meta-tx signature. */\nexport async function recoverMetaTransactionSigner(\n args: MetaTransactionArgs & { signature: Hex },\n): Promise<Address> {\n const { signature, ...rest } = args;\n const td = await metaTransactionTypedData(rest);\n return recoverTypedDataAddress({\n domain: td.domain,\n types: td.types,\n primaryType: td.primaryType,\n message: td.message,\n signature,\n } as unknown as Parameters<typeof recoverTypedDataAddress>[0]);\n}\n\n// ===========================================================================\n// Action-specific MetaTx variants.\n//\n// core-sdk's `metaTx.handler.signMetaTx*` methods use different EIP-712\n// primary types for different action families. The recovery side MUST\n// reconstruct the same typed-data structure or `ecrecover` yields a\n// garbage address. The basic `MetaTransaction` type (handled by\n// `metaTransactionTypedData` above) only covers the commit-time actions\n// and `revokeVoucher`; the three builders below cover the rest. Each\n// routes through the corresponding core-sdk `signMetaTx*({…,\n// returnTypedDataToSign: true})` so the typed-data shape stays in\n// lock-step with the deployed protocol — no manual re-derivation of\n// types, domain, or message structure on our side.\n// ===========================================================================\n\n/** Loose typed-data shape — covers the action-specific variants below. */\nexport interface ActionMetaTransactionTypedData {\n domain: Record<string, unknown>;\n types: Record<string, readonly TypedDataField[]>;\n primaryType: string;\n message: Record<string, unknown>;\n}\n\ninterface BaseActionArgs {\n chainId: number;\n /** Address of the Boson escrow contract — the EIP-712 verifyingContract. */\n verifyingContract: Address;\n /** Boson `MetaTransactionsHandlerFacet.usedNonce[from][nonce]` replay-protection slot. */\n nonce: bigint;\n /** Buyer / signer EOA — populates the typed-data `message.from`. */\n from: Address;\n}\n\n/**\n * Build the EIP-712 typed-data for an EXCHANGE-keyed post-commit meta-tx\n * (`redeemVoucher`, `cancelVoucher`, `completeExchange`,\n * `raiseDispute`, `retractDispute`, `escalateDispute`). All six share\n * the `MetaTxExchange` primary type and `exchangeDetails: {exchangeId}`\n * sub-struct; the only difference between them is `message.functionName`.\n */\nexport async function metaTransactionExchangeTypedData(\n args: BaseActionArgs & {\n /** Boson function signature, e.g. `\"redeemVoucher(uint256)\"`. */\n functionName: string;\n /** Exchange the action targets. */\n exchangeId: bigint;\n },\n): Promise<ActionMetaTransactionTypedData> {\n return callCoreSdkForTypedData(args.from, args.chainId, async (web3Lib) =>\n metaTx.handler.signMetaTxRedeemVoucher({\n web3Lib,\n nonce: args.nonce.toString(),\n metaTxHandlerAddress: args.verifyingContract,\n chainId: args.chainId,\n exchangeId: args.exchangeId.toString(),\n returnTypedDataToSign: true,\n }),\n ).then((td) => withOverriddenFunctionName(td, args.functionName));\n}\n\n/**\n * Build the EIP-712 typed-data for `resolveDispute` — `MetaTxDisputeResolution`\n * primary type with a nested `disputeResolutionDetails` struct carrying\n * the exchange id, the buyer's percent split, and the counterparty's\n * signature.\n */\nexport async function metaTransactionDisputeResolutionTypedData(\n args: BaseActionArgs & {\n exchangeId: bigint;\n buyerPercentBasisPoints: bigint;\n /** Counterparty's signature over the resolution proposal — packed `r||s||v` hex. */\n counterpartySig: Hex;\n },\n): Promise<ActionMetaTransactionTypedData> {\n return callCoreSdkForTypedData(args.from, args.chainId, async (web3Lib) =>\n metaTx.handler.signMetaTxResolveDispute({\n web3Lib,\n nonce: args.nonce.toString(),\n metaTxHandlerAddress: args.verifyingContract,\n chainId: args.chainId,\n exchangeId: args.exchangeId.toString(),\n buyerPercent: args.buyerPercentBasisPoints.toString(),\n counterpartySig: args.counterpartySig,\n returnTypedDataToSign: true,\n }),\n );\n}\n\n/**\n * Build the EIP-712 typed-data for `withdrawFunds` — `MetaTxFund` primary\n * type with a nested `fundDetails` struct carrying the entity id, the\n * token-address list, and the per-token amounts.\n */\nexport async function metaTransactionFundTypedData(\n args: BaseActionArgs & {\n entityId: bigint;\n tokenList: readonly Address[];\n tokenAmounts: readonly bigint[];\n },\n): Promise<ActionMetaTransactionTypedData> {\n return callCoreSdkForTypedData(args.from, args.chainId, async (web3Lib) =>\n metaTx.handler.signMetaTxWithdrawFunds({\n web3Lib,\n nonce: args.nonce.toString(),\n metaTxHandlerAddress: args.verifyingContract,\n chainId: args.chainId,\n entityId: args.entityId.toString(),\n tokenList: args.tokenList as string[],\n tokenAmounts: args.tokenAmounts.map((amount) => amount.toString()),\n returnTypedDataToSign: true,\n }),\n );\n}\n\n/**\n * Drive a core-sdk `signMetaTx*({…, returnTypedDataToSign: true})` and\n * strip the convenience fields (`functionName`, `functionSignature`)\n * the SDK appends — only the EIP-712 typed-data shape is needed for\n * recovery.\n *\n * core-sdk's `returnTypedDataToSign: true` path short-circuits before\n * `eth_signTypedData_v4` is invoked, so we only need a `Web3LibAdapter`\n * that can answer `getSignerAddress()` and `getChainId()`. Any other\n * method invocation indicates core-sdk's internals changed and surfaces\n * loudly through {@link createTypedDataInterceptAdapter}'s stubs.\n */\nasync function callCoreSdkForTypedData(\n from: Address,\n chainId: number,\n invoke: (web3Lib: Parameters<typeof metaTx.handler.signMetaTx>[0][\"web3Lib\"]) => Promise<{\n domain: Record<string, unknown>;\n types: Record<string, readonly TypedDataField[]>;\n primaryType: string;\n message: Record<string, unknown>;\n }>,\n): Promise<ActionMetaTransactionTypedData> {\n const intercept = createTypedDataInterceptAdapter<ActionMetaTransactionTypedData>({\n callerTag: STUB_CALLER_TAG,\n signerAddress: from,\n chainId,\n // `parse` is wired up but never called — `returnTypedDataToSign: true`\n // short-circuits in core-sdk before `eth_signTypedData_v4` would fire.\n parse: (json) => JSON.parse(json) as ActionMetaTransactionTypedData,\n });\n const result = await invoke(intercept.adapter);\n return {\n domain: result.domain,\n types: result.types,\n primaryType: result.primaryType,\n message: result.message,\n };\n}\n\n/**\n * Substitute the typed-data's `message.functionName` for the action's\n * specific value. `metaTransactionExchangeTypedData` routes every\n * exchange-keyed action through `signMetaTxRedeemVoucher` (the six\n * methods produce identical types/domain/primaryType, differing only in\n * the hard-coded `functionName`); this override restores the correct\n * value so the recovered EIP-712 hash matches whatever the signer\n * actually signed.\n */\nfunction withOverriddenFunctionName(\n td: ActionMetaTransactionTypedData,\n functionName: string,\n): ActionMetaTransactionTypedData {\n return {\n ...td,\n message: { ...td.message, functionName },\n };\n}\n","// EIP-712 typed-data builder for the BPIP-10 FullOffer signed by the seller.\n//\n// FullOffer's nested struct shape (Offer / OfferDates / OfferDurations /\n// DRParameters / Condition / RoyaltyInfo) is large and protocol-internal — it\n// can change as the contracts evolve. Rather than hand-mirroring it here,\n// this module wraps `@bosonprotocol/core-sdk`'s\n// `exchanges.handler.signFullOffer({..., returnTypedDataToSign: true})` and\n// re-exposes the typed-data through a viem-friendly hash + recover API.\n//\n// In `returnTypedDataToSign: true` mode, core-sdk's `prepareDataSignatureParameters`\n// returns the StructuredData immediately and never invokes any method on\n// `web3Lib`. We therefore pass the shared throwing stub from\n// `internal/web3lib-stub.ts` — any future use of web3Lib is loud rather than\n// silent.\n//\n// The result hashes against the same Boson EIP-712 domain that\n// `verifyOffer` uses on-chain (salt-based, \"Boson Protocol\" name) — the\n// shape comes straight from core-sdk so we don't redefine it here.\n\nimport { exchanges } from \"@bosonprotocol/core-sdk\";\nimport type { FullOfferArgs } from \"@bosonprotocol/common\";\nimport { hashTypedData, recoverTypedDataAddress, type Address, type Hex } from \"viem\";\n\nimport { createThrowingWeb3LibAdapter } from \"../internal/web3lib-stub.js\";\n\n/** Unsigned FullOffer payload — same shape core-sdk accepts. */\nexport type UnsignedFullOffer = Omit<FullOfferArgs, \"signature\">;\n\n/** A single EIP-712 type field — a `{ name, type }` pair. */\nexport type TypedDataField = { name: string; type: string };\n\n/**\n * EIP-712 typed-data ready for any viem signer. Uses a deliberately-loose\n * `types` shape (not viem's `TypedData`) because Boson's `EIP712Domain`\n * field set is non-standard and viem's strict union rejects it; consumers\n * pass this shape directly to `hashTypedData` / `signTypedData` /\n * `recoverTypedDataAddress`, which accept it structurally.\n */\nexport interface FullOfferTypedData {\n domain: Record<string, unknown>;\n types: Record<string, readonly TypedDataField[]>;\n primaryType: \"FullOffer\";\n message: Record<string, unknown>;\n}\n\nexport interface FullOfferArgsForBuilder {\n fullOffer: UnsignedFullOffer;\n /** Address of the Boson escrow contract — the EIP-712 verifyingContract. */\n verifyingContract: Address;\n chainId: number;\n}\n\nconst STUB_CALLER_TAG = \"@bosonprotocol/x402-core:full-offer\";\n\n/**\n * Build EIP-712 typed-data for a FullOffer that the seller will sign.\n * Delegates the struct definition to `@bosonprotocol/core-sdk` so we stay in\n * lock-step with whatever shape the deployed protocol's `verifyOffer`\n * accepts.\n */\nexport async function fullOfferTypedData({\n fullOffer,\n verifyingContract,\n chainId,\n}: FullOfferArgsForBuilder): Promise<FullOfferTypedData> {\n const sd = await exchanges.handler.signFullOffer({\n fullOfferArgsUnsigned: fullOffer,\n contractAddress: verifyingContract,\n chainId,\n web3Lib: createThrowingWeb3LibAdapter(STUB_CALLER_TAG),\n returnTypedDataToSign: true,\n });\n\n return {\n domain: sd.domain as unknown as Record<string, unknown>,\n types: sd.types as unknown as Record<string, readonly TypedDataField[]>,\n primaryType: \"FullOffer\",\n message: sd.message,\n };\n}\n\n/** EIP-712 digest for a FullOffer — what the seller signs. */\nexport async function hashFullOffer(args: FullOfferArgsForBuilder): Promise<Hex> {\n const td = await fullOfferTypedData(args);\n return hashTypedData(td as Parameters<typeof hashTypedData>[0]);\n}\n\n/** Recover the seller address from a FullOffer signature. */\nexport async function recoverFullOfferSigner(\n args: FullOfferArgsForBuilder & { signature: Hex },\n): Promise<Address> {\n const { signature, ...rest } = args;\n const td = await fullOfferTypedData(rest);\n return recoverTypedDataAddress({\n domain: td.domain,\n types: td.types,\n primaryType: td.primaryType,\n message: td.message,\n signature,\n } as unknown as Parameters<typeof recoverTypedDataAddress>[0]);\n}\n"]}
|