@bosonprotocol/x402-client 0.1.0 → 0.1.1-alpha-1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bosonprotocol/x402-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-alpha-1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Boson Protocol x402 buyer-side SDK — framework-agnostic client that intercepts 402 escrow-scheme responses and produces the X-PAYMENT header.",
|
|
6
6
|
"repository": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"@bosonprotocol/core-sdk": "1.48.0-alpha.6",
|
|
46
46
|
"ajv": "^8.17.1",
|
|
47
47
|
"viem": "^2.39.3",
|
|
48
|
-
"@bosonprotocol/x402-core": "^0.1.
|
|
49
|
-
"@bosonprotocol/x402-evm": "^0.1.
|
|
48
|
+
"@bosonprotocol/x402-core": "^0.1.1-alpha-1",
|
|
49
|
+
"@bosonprotocol/x402-evm": "^0.1.1-alpha-1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/node": "^20.17.10",
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { ClientState } from '@bosonprotocol/x402-core/state-machine';
|
|
2
|
-
import { TokenEip712Domain } from '@bosonprotocol/x402-core/eip712/token-auth';
|
|
3
|
-
import { Address, TypedDataDomain, TypedDataParameter, Hex, PublicClient } from 'viem';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Decision the buyer's policy makes about the on-chain redemption phase, **independent
|
|
7
|
-
* of when the resource is delivered off-chain**.
|
|
8
|
-
*
|
|
9
|
-
* - `"auto"` — default. Prefers the deferred `boson-createOfferAndCommit`
|
|
10
|
-
* path when advertised; falls back to atomic commit+redeem.
|
|
11
|
-
* - `"commit-only"` — explicitly want the deferred path; buyer (or another agent)
|
|
12
|
-
* will redeem later.
|
|
13
|
-
* - `"commit-and-redeem"` — explicitly want atomic on-chain commit+redeem;
|
|
14
|
-
* requires the server to advertise
|
|
15
|
-
* `boson-createOfferCommitAndRedeem` on the server channel,
|
|
16
|
-
* otherwise throws `NoCompatibleActionError`.
|
|
17
|
-
*/
|
|
18
|
-
type RedeemMode = "auto" | "commit-only" | "commit-and-redeem";
|
|
19
|
-
interface Policy {
|
|
20
|
-
redeemMode?: RedeemMode;
|
|
21
|
-
/** Atomic-units cap. If set, the client rejects requirements whose `amount` exceeds it. */
|
|
22
|
-
maxAmount?: string;
|
|
23
|
-
}
|
|
24
|
-
interface FulfillmentConfig {
|
|
25
|
-
/** `id` of the option the buyer wants from `requirements.fulfillment.options[]`. */
|
|
26
|
-
option: string;
|
|
27
|
-
/** Buyer-supplied data; validated against the chosen option's JSON Schema. */
|
|
28
|
-
data: Record<string, unknown>;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Resolves the EIP-712 domain a given ERC-20 publishes for ERC-3009 /
|
|
32
|
-
* EIP-2612 signatures. Callers usually provide a small in-memory lookup
|
|
33
|
-
* table keyed by `(chainId, asset)`. Permit2 does not use the token's
|
|
34
|
-
* EIP-712 domain and can be signed without this resolver.
|
|
35
|
-
*/
|
|
36
|
-
type TokenDomainResolver = (asset: Address, chainId: number) => Promise<TokenEip712Domain> | TokenEip712Domain;
|
|
37
|
-
/**
|
|
38
|
-
* Minimal wallet abstraction the client signs through. Matches the shape of
|
|
39
|
-
* viem's `Account.signTypedData` so a viem `LocalAccount` can be passed
|
|
40
|
-
* directly (its `signTypedData` and `address` already line up); a viem
|
|
41
|
-
* `WalletClient`-bound account or an external signer needs a 4-line
|
|
42
|
-
* inline wrapper of the same shape.
|
|
43
|
-
*/
|
|
44
|
-
interface Signer {
|
|
45
|
-
getAddress(): Promise<Address>;
|
|
46
|
-
signTypedData(args: {
|
|
47
|
-
domain: TypedDataDomain;
|
|
48
|
-
types: Record<string, readonly TypedDataParameter[]>;
|
|
49
|
-
primaryType: string;
|
|
50
|
-
message: Record<string, unknown>;
|
|
51
|
-
}): Promise<Hex>;
|
|
52
|
-
}
|
|
53
|
-
interface X402bClientConfig {
|
|
54
|
-
signer: Signer;
|
|
55
|
-
/**
|
|
56
|
-
* Per-chain Boson subgraph URLs. `CoreSDK`'s base constructor requires one;
|
|
57
|
-
* for signing-only flows the URL may not actually be queried, but it must
|
|
58
|
-
* be present. Keyed by EIP-155 chain id (e.g. `8453` for Base mainnet).
|
|
59
|
-
*/
|
|
60
|
-
subgraphUrls?: Record<number, string>;
|
|
61
|
-
/**
|
|
62
|
-
* Per-chain viem `PublicClient`s. Required for the EIP-2612 Permit
|
|
63
|
-
* token-auth strategy, which fetches the token's `nonces(owner)` before
|
|
64
|
-
* signing. If the buyer signs only on chains with no Permit support, this
|
|
65
|
-
* may be omitted; attempting to sign a Permit payload without a configured
|
|
66
|
-
* PublicClient throws a clear error. Keyed by EIP-155 chain id.
|
|
67
|
-
*/
|
|
68
|
-
publicClients?: Record<number, PublicClient>;
|
|
69
|
-
tokenDomainResolver?: TokenDomainResolver;
|
|
70
|
-
policy?: Policy;
|
|
71
|
-
/** Default fulfillment selection. Required when `requirements.fulfillment.required` is true. */
|
|
72
|
-
fulfillment?: FulfillmentConfig;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Whatever the server returns in `X-PAYMENT-RESPONSE` (if anything) after a
|
|
76
|
-
* successful settle. Permissive — the server-side contract for this header
|
|
77
|
-
* isn't pinned yet; the client surfaces the raw payload and best-effort
|
|
78
|
-
* lifts `exchangeId` / `state` from common property paths.
|
|
79
|
-
*/
|
|
80
|
-
interface ExchangeSummary {
|
|
81
|
-
raw?: unknown;
|
|
82
|
-
exchangeId?: string;
|
|
83
|
-
state?: ClientState;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export type { ExchangeSummary as E, FulfillmentConfig as F, Policy as P, RedeemMode as R, Signer as S, TokenDomainResolver as T, X402bClientConfig as X };
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { ClientState } from '@bosonprotocol/x402-core/state-machine';
|
|
2
|
-
import { TokenEip712Domain } from '@bosonprotocol/x402-core/eip712/token-auth';
|
|
3
|
-
import { Address, TypedDataDomain, TypedDataParameter, Hex, PublicClient } from 'viem';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Decision the buyer's policy makes about the on-chain redemption phase, **independent
|
|
7
|
-
* of when the resource is delivered off-chain**.
|
|
8
|
-
*
|
|
9
|
-
* - `"auto"` — default. Prefers the deferred `boson-createOfferAndCommit`
|
|
10
|
-
* path when advertised; falls back to atomic commit+redeem.
|
|
11
|
-
* - `"commit-only"` — explicitly want the deferred path; buyer (or another agent)
|
|
12
|
-
* will redeem later.
|
|
13
|
-
* - `"commit-and-redeem"` — explicitly want atomic on-chain commit+redeem;
|
|
14
|
-
* requires the server to advertise
|
|
15
|
-
* `boson-createOfferCommitAndRedeem` on the server channel,
|
|
16
|
-
* otherwise throws `NoCompatibleActionError`.
|
|
17
|
-
*/
|
|
18
|
-
type RedeemMode = "auto" | "commit-only" | "commit-and-redeem";
|
|
19
|
-
interface Policy {
|
|
20
|
-
redeemMode?: RedeemMode;
|
|
21
|
-
/** Atomic-units cap. If set, the client rejects requirements whose `amount` exceeds it. */
|
|
22
|
-
maxAmount?: string;
|
|
23
|
-
}
|
|
24
|
-
interface FulfillmentConfig {
|
|
25
|
-
/** `id` of the option the buyer wants from `requirements.fulfillment.options[]`. */
|
|
26
|
-
option: string;
|
|
27
|
-
/**
|
|
28
|
-
* Buyer-supplied data; validated against the chosen option's JSON Schema.
|
|
29
|
-
* Use `null` for schemaless options such as `inline`.
|
|
30
|
-
*/
|
|
31
|
-
data: Record<string, unknown> | null;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Resolves the EIP-712 domain a given ERC-20 publishes for ERC-3009 /
|
|
35
|
-
* EIP-2612 signatures. Callers usually provide a small in-memory lookup
|
|
36
|
-
* table keyed by `(chainId, asset)`. Permit2 does not use the token's
|
|
37
|
-
* EIP-712 domain and can be signed without this resolver.
|
|
38
|
-
*/
|
|
39
|
-
type TokenDomainResolver = (asset: Address, chainId: number) => Promise<TokenEip712Domain> | TokenEip712Domain;
|
|
40
|
-
/**
|
|
41
|
-
* Minimal wallet abstraction the client signs through. Matches the shape of
|
|
42
|
-
* viem's `Account.signTypedData` so a viem `LocalAccount` can be passed
|
|
43
|
-
* directly (its `signTypedData` and `address` already line up); a viem
|
|
44
|
-
* `WalletClient`-bound account or an external signer needs a 4-line
|
|
45
|
-
* inline wrapper of the same shape.
|
|
46
|
-
*/
|
|
47
|
-
interface Signer {
|
|
48
|
-
getAddress(): Promise<Address>;
|
|
49
|
-
signTypedData(args: {
|
|
50
|
-
domain: TypedDataDomain;
|
|
51
|
-
types: Record<string, readonly TypedDataParameter[]>;
|
|
52
|
-
primaryType: string;
|
|
53
|
-
message: Record<string, unknown>;
|
|
54
|
-
}): Promise<Hex>;
|
|
55
|
-
}
|
|
56
|
-
interface X402bClientConfig {
|
|
57
|
-
signer: Signer;
|
|
58
|
-
/**
|
|
59
|
-
* Per-chain Boson subgraph URLs. `CoreSDK`'s base constructor requires one;
|
|
60
|
-
* for signing-only flows the URL may not actually be queried, but it must
|
|
61
|
-
* be present. Keyed by EIP-155 chain id (e.g. `8453` for Base mainnet).
|
|
62
|
-
*/
|
|
63
|
-
subgraphUrls?: Record<number, string>;
|
|
64
|
-
/**
|
|
65
|
-
* Per-chain viem `PublicClient`s. Required for the EIP-2612 Permit
|
|
66
|
-
* token-auth strategy, which fetches the token's `nonces(owner)` before
|
|
67
|
-
* signing. If the buyer signs only on chains with no Permit support, this
|
|
68
|
-
* may be omitted; attempting to sign a Permit payload without a configured
|
|
69
|
-
* PublicClient throws a clear error. Keyed by EIP-155 chain id.
|
|
70
|
-
*/
|
|
71
|
-
publicClients?: Record<number, PublicClient>;
|
|
72
|
-
tokenDomainResolver?: TokenDomainResolver;
|
|
73
|
-
policy?: Policy;
|
|
74
|
-
/** Default fulfillment selection. Required when `requirements.fulfillment.required` is true. */
|
|
75
|
-
fulfillment?: FulfillmentConfig;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Whatever the server returns in `X-PAYMENT-RESPONSE` (if anything) after a
|
|
79
|
-
* successful settle. Permissive — the server-side contract for this header
|
|
80
|
-
* isn't pinned yet; the client surfaces the raw payload and best-effort
|
|
81
|
-
* lifts `exchangeId` / `state` from common property paths.
|
|
82
|
-
*/
|
|
83
|
-
interface ExchangeSummary {
|
|
84
|
-
raw?: unknown;
|
|
85
|
-
exchangeId?: string;
|
|
86
|
-
state?: ClientState;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export type { ExchangeSummary as E, FulfillmentConfig as F, Policy as P, RedeemMode as R, Signer as S, TokenDomainResolver as T, X402bClientConfig as X };
|