@bosonprotocol/x402-client 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 +22 -0
- package/dist/cjs/index.d.ts +240 -0
- package/dist/cjs/index.js +923 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/token-auth/index.d.ts +35 -0
- package/dist/cjs/token-auth/index.js +265 -0
- package/dist/cjs/token-auth/index.js.map +1 -0
- package/dist/cjs/types-DLOroMb1.d.ts +104 -0
- package/dist/esm/chunk-JTTWAQGC.js +359 -0
- package/dist/esm/chunk-JTTWAQGC.js.map +1 -0
- package/dist/esm/index.js +557 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/token-auth/index.js +3 -0
- package/dist/esm/token-auth/index.js.map +1 -0
- package/package.json +64 -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,22 @@
|
|
|
1
|
+
# @bosonprotocol/x402-client
|
|
2
|
+
|
|
3
|
+
Framework-agnostic buyer-side SDK 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 package intercepts a `402 Payment Required` carrying `scheme: "escrow"`, signs the buyer's Boson protocol meta-transaction + token-transfer authorization, and produces the `X-PAYMENT` header so the request can be re-issued.
|
|
6
|
+
|
|
7
|
+
Adapters for specific HTTP clients will be published as sibling packages — e.g. `@bosonprotocol/x402-client-fetch` for native `fetch`.
|
|
8
|
+
|
|
9
|
+
## Status
|
|
10
|
+
|
|
11
|
+
Pre-release skeleton. The public API surface lands incrementally; the package currently exports types, errors, the client factory, and pure-function utilities (action picker, fulfillment resolver).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @bosonprotocol/x402-client
|
|
17
|
+
# or: npm install @bosonprotocol/x402-client
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## License
|
|
21
|
+
|
|
22
|
+
[Apache-2.0](./LICENSE)
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { P as Policy, X as X402bClientConfig, E as ExchangeSummary, S as Signer } from './types-DLOroMb1.js';
|
|
2
|
+
export { F as FulfillmentConfig, R as RedeemMode, T as TokenDomainResolver } from './types-DLOroMb1.js';
|
|
3
|
+
import { EscrowPaymentRequirements, BosonCommitActionId, BosonMetaTx, Hex as Hex$1 } from '@bosonprotocol/x402-core/schemes/escrow';
|
|
4
|
+
import { ActionId } from '@bosonprotocol/x402-core/state-machine';
|
|
5
|
+
import { Address, Hex } from 'viem';
|
|
6
|
+
import '@bosonprotocol/x402-core/eip712/token-auth';
|
|
7
|
+
|
|
8
|
+
declare class UnsupportedSchemeError extends Error {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
declare class UnsupportedTokenAuthError extends Error {
|
|
12
|
+
constructor(message: string);
|
|
13
|
+
}
|
|
14
|
+
declare class NoCompatibleActionError extends Error {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
declare class FulfillmentValidationError extends Error {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
declare class MaxAmountExceededError extends Error {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the Boson commit-time action the client will sign. Throws
|
|
26
|
+
* `NoCompatibleActionError` when the server hasn't advertised any action
|
|
27
|
+
* compatible with the requested policy.
|
|
28
|
+
*/
|
|
29
|
+
declare function pickAction(requirements: EscrowPaymentRequirements, policy?: Policy): BosonCommitActionId;
|
|
30
|
+
|
|
31
|
+
interface ResolvedFulfillment {
|
|
32
|
+
option: string;
|
|
33
|
+
/**
|
|
34
|
+
* Buyer-supplied delivery data, validated locally against the option's
|
|
35
|
+
* JSON Schema. The payload assembler decides whether to include this
|
|
36
|
+
* field in the commit-time payload (Flow B yes, Flow A no).
|
|
37
|
+
*/
|
|
38
|
+
data: Record<string, unknown> | null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns the resolved `{ option, data }` pair the assembler will attach
|
|
42
|
+
* to the commit-time fulfillment slot (Flow B) or carry forward for the
|
|
43
|
+
* redeem-time POST body (Flow A). Throws when the requirements demand a
|
|
44
|
+
* fulfillment but the client config doesn't supply one, when the option
|
|
45
|
+
* id isn't advertised by the server, or when the buyer data doesn't
|
|
46
|
+
* validate against the option's schema.
|
|
47
|
+
*/
|
|
48
|
+
declare function resolveFulfillment(requirements: EscrowPaymentRequirements, config: Pick<X402bClientConfig, "fulfillment">): ResolvedFulfillment | undefined;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Parse a CAIP-2 EVM network identifier (e.g. `"eip155:8453"`) into its
|
|
52
|
+
* numeric chain id. Throws if the network is not a well-formed `eip155:<N>`.
|
|
53
|
+
*/
|
|
54
|
+
declare function parseChainId(network: string): number;
|
|
55
|
+
|
|
56
|
+
/** Read a header value from anything that exposes `.get(name)`. */
|
|
57
|
+
interface HeaderLike {
|
|
58
|
+
get(name: string): string | null;
|
|
59
|
+
}
|
|
60
|
+
interface ResponseLike {
|
|
61
|
+
headers: HeaderLike;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Decode the `X-PAYMENT-RESPONSE` header on a Response-like object. Returns
|
|
65
|
+
* `undefined` when the header isn't set; throws on a malformed payload.
|
|
66
|
+
*/
|
|
67
|
+
declare function parsePaymentResponse(response: ResponseLike): ExchangeSummary | undefined;
|
|
68
|
+
|
|
69
|
+
type BigNumberish$1 = string | number | bigint;
|
|
70
|
+
/**
|
|
71
|
+
* Buyer-invokable post-commit action ids — derived from `ActionId` in
|
|
72
|
+
* `@bosonprotocol/x402-core/state-machine` (the single source of truth)
|
|
73
|
+
* by excluding:
|
|
74
|
+
*
|
|
75
|
+
* - the commit-time ids, which the buyer signs via `handle402`;
|
|
76
|
+
* - `boson-revokeVoucher`, which is seller-only;
|
|
77
|
+
* - entity-keyed actions (`boson-withdrawFunds`), which are signed via
|
|
78
|
+
* `client.signWithdrawFunds` / `client.signWithdrawAllAvailableFunds`
|
|
79
|
+
* because they take an `entityId` + token list rather than an
|
|
80
|
+
* `exchangeId`.
|
|
81
|
+
*/
|
|
82
|
+
type BuyerPostCommitActionId = Exclude<ActionId, "boson-createOfferAndCommit" | "boson-createOfferCommitAndRedeem" | "boson-revokeVoucher" | "boson-withdrawFunds">;
|
|
83
|
+
/** Caller-supplied arguments for `client.signAction`. */
|
|
84
|
+
type SignActionArgs = SimplePostCommitArgs | ResolveDisputeArgs;
|
|
85
|
+
interface BaseArgs {
|
|
86
|
+
exchangeId: BigNumberish$1;
|
|
87
|
+
/** CAIP-2 network identifier (e.g. `"eip155:8453"`). */
|
|
88
|
+
network: string;
|
|
89
|
+
/** Boson Diamond address (the `escrowAddress` from the prior 402). */
|
|
90
|
+
escrowAddress: Address;
|
|
91
|
+
}
|
|
92
|
+
interface SimplePostCommitArgs extends BaseArgs {
|
|
93
|
+
actionId: Exclude<BuyerPostCommitActionId, "boson-resolveDispute">;
|
|
94
|
+
}
|
|
95
|
+
interface ResolveDisputeArgs extends BaseArgs {
|
|
96
|
+
actionId: "boson-resolveDispute";
|
|
97
|
+
/** Buyer share of the disputed amount, in the units the protocol expects (basis points). */
|
|
98
|
+
buyerPercent: BigNumberish$1;
|
|
99
|
+
/** Counterparty (seller) signature over the proposal. Hex string or `{r, s, v}`. */
|
|
100
|
+
counterpartySig: Hex | {
|
|
101
|
+
r: Hex;
|
|
102
|
+
s: Hex;
|
|
103
|
+
v: number;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Wire-format result of `signPostCommitAction`: the signed `BosonMetaTx`
|
|
108
|
+
* envelope plus its ABI-encoded `signedPayload` Hex. Pick the one that
|
|
109
|
+
* matches the channel — the server/facilitator HTTP routes consume
|
|
110
|
+
* `signedPayload`; direct on-chain or MCP submissions use `metaTx`.
|
|
111
|
+
*/
|
|
112
|
+
interface SignedPostCommitAction {
|
|
113
|
+
metaTx: BosonMetaTx;
|
|
114
|
+
/**
|
|
115
|
+
* ABI-encoded `BosonMetaTx` ready to drop into a server / facilitator
|
|
116
|
+
* route's `signedPayload` field. The hex is JSON-serialisable; we type
|
|
117
|
+
* it as the loose wire `Hex` (string) rather than viem's strict
|
|
118
|
+
* `\`0x\${string}\`` so the codec's output matches the schemes module's
|
|
119
|
+
* own `Hex` alias.
|
|
120
|
+
*/
|
|
121
|
+
signedPayload: Hex$1;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type BigNumberish = string | number | bigint;
|
|
125
|
+
/**
|
|
126
|
+
* Resolution targets accepted by the "withdraw all" helper. Either
|
|
127
|
+
* pass the raw `entityId` (numeric Boson account id) or an EVM
|
|
128
|
+
* `address` with an optional `role` discriminator for the case where
|
|
129
|
+
* the address maps to both a seller and a buyer entity.
|
|
130
|
+
*/
|
|
131
|
+
type WithdrawEntitySelector = {
|
|
132
|
+
entityId: BigNumberish;
|
|
133
|
+
} | {
|
|
134
|
+
address: Address;
|
|
135
|
+
role?: "buyer" | "seller";
|
|
136
|
+
};
|
|
137
|
+
/** Arguments accepted by `signWithdrawFunds` (caller-resolved entity + token list). */
|
|
138
|
+
interface SignWithdrawFundsArgs {
|
|
139
|
+
entityId: BigNumberish;
|
|
140
|
+
/** CAIP-2 network identifier (e.g. `"eip155:8453"`). */
|
|
141
|
+
network: string;
|
|
142
|
+
/** Boson Diamond address (the `escrowAddress` from the prior 402). */
|
|
143
|
+
escrowAddress: Address;
|
|
144
|
+
/** Token addresses to withdraw — must align by index with `tokenAmounts`. */
|
|
145
|
+
tokenList: readonly Address[];
|
|
146
|
+
/** Amounts to withdraw — must align by index with `tokenList`. */
|
|
147
|
+
tokenAmounts: readonly BigNumberish[];
|
|
148
|
+
}
|
|
149
|
+
/** Arguments accepted by `signWithdrawAllAvailableFunds` — entity + network only. */
|
|
150
|
+
type SignWithdrawAllAvailableFundsArgs = WithdrawEntitySelector & {
|
|
151
|
+
/** CAIP-2 network identifier (e.g. `"eip155:8453"`). */
|
|
152
|
+
network: string;
|
|
153
|
+
/** Boson Diamond address. */
|
|
154
|
+
escrowAddress: Address;
|
|
155
|
+
};
|
|
156
|
+
/** Wire-format result identical in shape to `SignedPostCommitAction`. */
|
|
157
|
+
interface SignedWithdrawFunds {
|
|
158
|
+
metaTx: BosonMetaTx;
|
|
159
|
+
signedPayload: Hex$1;
|
|
160
|
+
/** Resolved `entityId` (echoed back for caller convenience when looked up by address). */
|
|
161
|
+
entityId: string;
|
|
162
|
+
/** Tokens included in the signature, in calldata order. */
|
|
163
|
+
tokenList: readonly Address[];
|
|
164
|
+
/** Amounts included in the signature, in calldata order. */
|
|
165
|
+
tokenAmounts: readonly string[];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
interface X402bClient {
|
|
169
|
+
/**
|
|
170
|
+
* Consume a parsed escrow PaymentRequirements and return the base64
|
|
171
|
+
* value to set as the `X-PAYMENT` header on the retry.
|
|
172
|
+
*/
|
|
173
|
+
handle402(requirements: unknown): Promise<string>;
|
|
174
|
+
/**
|
|
175
|
+
* Sign a Boson protocol meta-transaction for a buyer-driven post-commit
|
|
176
|
+
* action (redeem, cancel, complete, dispute family). Returns both the
|
|
177
|
+
* wire-format `BosonMetaTx` envelope and the ABI-encoded `signedPayload`
|
|
178
|
+
* Hex — pick the shape that matches the chosen channel. Server /
|
|
179
|
+
* facilitator HTTP routes consume `signedPayload` directly (e.g. as
|
|
180
|
+
* the `signedPayload` field on the JSON POST body to the endpoint the
|
|
181
|
+
* prior response advertised under `actions.next[].endpoints.server`);
|
|
182
|
+
* on-chain and MCP channels use the `metaTx` object.
|
|
183
|
+
*
|
|
184
|
+
* Note: `boson-escalateDispute` signs only the meta-tx. If the dispute
|
|
185
|
+
* resolver requires an escalation deposit, the resolver/server returns
|
|
186
|
+
* its own 402 with an `escrow` `PaymentRequirements` and the buyer pairs
|
|
187
|
+
* this meta-tx with a token-auth payload — the deposit wrapper is out
|
|
188
|
+
* of MVP.
|
|
189
|
+
*/
|
|
190
|
+
signAction(args: SignActionArgs): Promise<SignedPostCommitAction>;
|
|
191
|
+
/**
|
|
192
|
+
* Sign a `withdrawFunds(entityId, tokenList, tokenAmounts)` meta-tx.
|
|
193
|
+
* Caller-resolved entity + tokens snapshot — see
|
|
194
|
+
* `signWithdrawAllAvailableFunds` for the read-from-subgraph "withdraw
|
|
195
|
+
* everything" sugar.
|
|
196
|
+
*/
|
|
197
|
+
signWithdrawFunds(args: SignWithdrawFundsArgs): Promise<SignedWithdrawFunds>;
|
|
198
|
+
/**
|
|
199
|
+
* Read available funds for the given entity from the subgraph and
|
|
200
|
+
* sign a meta-tx withdrawing the entire current balance set. Accepts
|
|
201
|
+
* either an `entityId` directly or an `address` (with optional
|
|
202
|
+
* `role` for ambiguous wallets).
|
|
203
|
+
*/
|
|
204
|
+
signWithdrawAllAvailableFunds(args: SignWithdrawAllAvailableFundsArgs): Promise<SignedWithdrawFunds>;
|
|
205
|
+
/**
|
|
206
|
+
* Best-effort decode of `X-PAYMENT-RESPONSE` after a successful retry.
|
|
207
|
+
* Returns `undefined` when the header isn't present.
|
|
208
|
+
*/
|
|
209
|
+
parsePaymentResponse(response: {
|
|
210
|
+
headers: {
|
|
211
|
+
get(name: string): string | null;
|
|
212
|
+
};
|
|
213
|
+
}): ExchangeSummary | undefined;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Build a stateless client bound to a buyer signer + policy. The
|
|
217
|
+
* underlying `CoreSDK` is built lazily per `(chainId, escrowAddress)` and
|
|
218
|
+
* cached across calls — both `handle402` and `signAction` reuse it.
|
|
219
|
+
*/
|
|
220
|
+
declare function createX402bClient(config: X402bClientConfig): X402bClient;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Structural subset of `@bosonprotocol/common`'s `Web3LibAdapter` that
|
|
224
|
+
* {@link signerFromEthersAdapter} actually exercises. An `EthersAdapter`
|
|
225
|
+
* from `@bosonprotocol/ethers-sdk` (or any future concrete adapter)
|
|
226
|
+
* satisfies this shape without an explicit cast.
|
|
227
|
+
*/
|
|
228
|
+
interface Web3LibAdapterLike {
|
|
229
|
+
getSignerAddress(): Promise<string>;
|
|
230
|
+
send(method: string, params: readonly unknown[]): Promise<unknown>;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Wrap a Boson `Web3LibAdapter`-shaped object as an x402-client
|
|
234
|
+
* {@link Signer}. `signTypedData` builds the standard
|
|
235
|
+
* `eth_signTypedData_v4` JSON payload (including a derived
|
|
236
|
+
* `EIP712Domain` type list) and routes it through `adapter.send`.
|
|
237
|
+
*/
|
|
238
|
+
declare function signerFromEthersAdapter(adapter: Web3LibAdapterLike): Signer;
|
|
239
|
+
|
|
240
|
+
export { ExchangeSummary, FulfillmentValidationError, MaxAmountExceededError, NoCompatibleActionError, Policy, type ResolveDisputeArgs, type ResolvedFulfillment, type SignActionArgs, type SignWithdrawAllAvailableFundsArgs, type SignWithdrawFundsArgs, type SignedPostCommitAction, type SignedWithdrawFunds, Signer, type SimplePostCommitArgs, UnsupportedSchemeError, UnsupportedTokenAuthError, type Web3LibAdapterLike, type WithdrawEntitySelector, type X402bClient, X402bClientConfig, createX402bClient, parseChainId, parsePaymentResponse, pickAction, resolveFulfillment, signerFromEthersAdapter };
|