@playmos/sdk 0.1.6 → 0.3.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/README.md +146 -0
- package/dist/errors-BVESr920.d.cts +552 -0
- package/dist/errors-BVESr920.d.ts +552 -0
- package/dist/index.cjs +682 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +335 -17
- package/dist/index.d.ts +335 -17
- package/dist/index.js +674 -19
- package/dist/index.js.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/package.json +3 -3
- package/dist/errors-B-85VYMv.d.cts +0 -224
- package/dist/errors-B-85VYMv.d.ts +0 -224
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as Network, P as PlaymosConfig, W as WebhookEvent, a as
|
|
2
|
-
export {
|
|
1
|
+
import { N as Network, P as PlaymosConfig, W as WebhookEvent, R as RoundOpenInput, a as RoundState, b as RoundSettleInput, S as SettleRoundResult, A as AgentWallet, c as AgentFundResult, T as TransferResult, E as EscrowHoldInput, d as EscrowHoldResult, e as EscrowResolveResult, M as MarketplaceListInput, L as Listing, f as MarketplaceSaleResult, g as MarketplaceGetResult, h as PayInput, i as Payment, j as EnterRoundInput, k as TransferReconcile, l as WaitOptions, m as TransferInput, n as TransferConfirmOptions, V as VerifyResult } from './errors-BVESr920.js';
|
|
2
|
+
export { o as AgentEconomyConfig, p as ApiError, q as AuthError, C as ConfigError, r as ContractConfig, s as Eip1193Provider, G as GasConfig, t as GasMode, I as InsufficientGasError, u as InvalidAmountError, v as ListingStatus, w as MarketplaceItem, x as MarketplaceSale, y as MissingFieldError, z as PaymentFailedError, B as PaymentStatus, D as PayoutRule, F as PlaymosError, H as PlaymosErrorCode, J as RetryOptions, K as RoundStatus, O as WalletConfig, Q as WalletConnectionError, U as WalletConnector, X as WebhookEventType } from './errors-BVESr920.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Environment resolution + the canonical address book.
|
|
@@ -36,11 +36,18 @@ declare class Playmos {
|
|
|
36
36
|
readonly config: PlaymosConfig;
|
|
37
37
|
readonly env: ResolvedEnv;
|
|
38
38
|
private readonly http;
|
|
39
|
+
/**
|
|
40
|
+
* Webhook helpers. Signature verification is **server-only** (Node `crypto`) and
|
|
41
|
+
* lives on `@playmos/sdk/server` so browser bundlers never see `node:crypto` (#9).
|
|
42
|
+
*
|
|
43
|
+
* import { verifyWebhook } from "@playmos/sdk/server";
|
|
44
|
+
* const event = verifyWebhook(rawBody, req.headers["x-playmos-signature"], secret);
|
|
45
|
+
*/
|
|
39
46
|
readonly webhooks: {
|
|
40
47
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
48
|
+
* @deprecated Use `import { verifyWebhook } from "@playmos/sdk/server"` instead.
|
|
49
|
+
* Throws if called — kept as a discoverable pointer so call sites fail loudly
|
|
50
|
+
* with a fix instruction rather than a silent missing method.
|
|
44
51
|
*/
|
|
45
52
|
verify: (_rawBody: string | Buffer, _signatureHeader: string | string[] | undefined, _secret: string) => WebhookEvent;
|
|
46
53
|
};
|
|
@@ -54,25 +61,105 @@ declare class Playmos {
|
|
|
54
61
|
url: string;
|
|
55
62
|
}>;
|
|
56
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* Skill/contest **round lifecycle** (issue #13) — closes the enterRound loop.
|
|
66
|
+
*
|
|
67
|
+
* Scores never leave the studio. Flow:
|
|
68
|
+
* rounds.open → players enterRound → studio scores → rounds.lock →
|
|
69
|
+
* rounds.settle({ ranking }) → contract pays winners.
|
|
70
|
+
*
|
|
71
|
+
* Operator txs are signed by the Playmos service (OPERATOR_ROLE key).
|
|
72
|
+
*/
|
|
73
|
+
readonly rounds: {
|
|
74
|
+
open: (input: RoundOpenInput) => Promise<RoundState>;
|
|
75
|
+
lock: (input: {
|
|
76
|
+
roundId: string;
|
|
77
|
+
gameId?: string;
|
|
78
|
+
}) => Promise<RoundState>;
|
|
79
|
+
settle: (input: RoundSettleInput) => Promise<SettleRoundResult>;
|
|
80
|
+
get: (input: {
|
|
81
|
+
roundId: string;
|
|
82
|
+
}) => Promise<RoundState>;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* `agents` — assign wallets to the NPCs YOUR game already owns, so they can transact USDC in your economy.
|
|
86
|
+
* The game creates the NPCs; the SDK only creates the WALLET for a game-supplied id. Engine-agnostic
|
|
87
|
+
* (Unity/Unreal/Godot/web all call the same REST). Requires a secret test key (`sk_test_`) on the sandbox.
|
|
88
|
+
*/
|
|
57
89
|
readonly agents: {
|
|
58
|
-
/** Assign
|
|
90
|
+
/** Assign (or return) the wallet for a game NPC id. Idempotent — safe to call wherever your NPCs spawn. */
|
|
59
91
|
createWallet: (input: {
|
|
60
92
|
agentId: string;
|
|
61
|
-
}) => Promise<
|
|
93
|
+
}) => Promise<AgentWallet>;
|
|
94
|
+
/** Resolve one NPC's wallet by your id. */
|
|
95
|
+
wallet: (agentId: string) => Promise<AgentWallet>;
|
|
96
|
+
/** List the NPC wallets you've assigned in this studio. */
|
|
97
|
+
list: () => Promise<AgentWallet[]>;
|
|
98
|
+
/** Sandbox faucet: fund an NPC with USDC from your treasury (per-NPC lifetime cap). */
|
|
99
|
+
fund: (input: {
|
|
62
100
|
agentId: string;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}>;
|
|
66
|
-
/**
|
|
101
|
+
amount: string;
|
|
102
|
+
idempotencyKey?: string;
|
|
103
|
+
}) => Promise<AgentFundResult>;
|
|
104
|
+
/** NPC→NPC (or →player) USDC transfer, by id. A thin alias of `playmos.transfer` (which is canonical). */
|
|
67
105
|
pay: (input: {
|
|
68
106
|
from: string;
|
|
69
107
|
to: string;
|
|
70
108
|
amount: string;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
109
|
+
feeBps?: number;
|
|
110
|
+
feeSink?: `0x${string}`;
|
|
111
|
+
}) => Promise<TransferResult>;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* `escrow` — the fair-exchange primitive (Phase 2): lock the payer's USDC on-chain the instant a deal
|
|
115
|
+
* opens (`hold`), then move it exactly once — `release` (→ payee, fee skimmed) XOR `refund` (→ payer,
|
|
116
|
+
* 100%). The contract holds the funds trustlessly; YOUR game decides the rule (who resolves, and when).
|
|
117
|
+
* A `deadline` auto-refund guarantees funds never get stuck. Pass the `hold` result's `id` to the rest.
|
|
118
|
+
*/
|
|
119
|
+
readonly escrow: {
|
|
120
|
+
/** Open a deal: lock `amount` of the payer's USDC into the on-chain escrow. Retries are idempotent.
|
|
121
|
+
* `async` so client-side validation surfaces as a rejected promise, not a synchronous throw. */
|
|
122
|
+
hold: (input: EscrowHoldInput) => Promise<EscrowHoldResult>;
|
|
123
|
+
/** Release a held deal to the payee (fee skimmed). `escrowId` is the `hold` result's `id`. */
|
|
124
|
+
release: (input: {
|
|
125
|
+
escrowId: string;
|
|
126
|
+
}) => Promise<EscrowResolveResult>;
|
|
127
|
+
/** Refund a held deal to the payer (100%, untaxed). `escrowId` is the `hold` result's `id`. */
|
|
128
|
+
refund: (input: {
|
|
129
|
+
escrowId: string;
|
|
130
|
+
}) => Promise<EscrowResolveResult>;
|
|
131
|
+
/** Verify a deal's on-chain state (reconciles a `settling` hold wedged by a crash). */
|
|
132
|
+
get: (escrowId: string) => Promise<EscrowResolveResult>;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* `marketplace` — list an item, and the seller is paid ONLY when it's bought (Phase 3a, off-chain items).
|
|
136
|
+
* Built on `escrow`: `buy` locks the buyer's USDC on-chain, `confirm` (after your game server delivers the
|
|
137
|
+
* item) pays the seller, and a no-delivery/timeout `refund`s the buyer. `deliver: true` on `buy` collapses
|
|
138
|
+
* lock+pay into one call when your server delivers synchronously. On-chain items are Phase 3b.
|
|
139
|
+
*/
|
|
140
|
+
readonly marketplace: {
|
|
141
|
+
/** List an off-chain item for sale. No money moves. Idempotent on `idempotencyKey`. */
|
|
142
|
+
list: (input: MarketplaceListInput) => Promise<Listing>;
|
|
143
|
+
/** Buy a listing: lock the buyer's USDC in escrow. Pass `deliver: true` to also pay the seller in one call. */
|
|
144
|
+
buy: (input: {
|
|
145
|
+
listingId: string;
|
|
146
|
+
buyer?: `0x${string}`;
|
|
147
|
+
deliver?: boolean;
|
|
148
|
+
}) => Promise<MarketplaceSaleResult>;
|
|
149
|
+
/** Confirm delivery → the seller is paid (release), fee skimmed. */
|
|
150
|
+
confirm: (input: {
|
|
151
|
+
listingId: string;
|
|
152
|
+
}) => Promise<MarketplaceSaleResult>;
|
|
153
|
+
/** Refund the buyer 100% (seller couldn't deliver / dispute / timeout). */
|
|
154
|
+
refund: (input: {
|
|
155
|
+
listingId: string;
|
|
156
|
+
}) => Promise<MarketplaceSaleResult>;
|
|
157
|
+
/** Delist an unsold listing (pure DB, no tx). */
|
|
158
|
+
cancel: (input: {
|
|
159
|
+
listingId: string;
|
|
160
|
+
}) => Promise<Listing>;
|
|
161
|
+
/** Fetch a listing + its on-chain-verified sale status. */
|
|
162
|
+
get: (listingId: string) => Promise<MarketplaceGetResult>;
|
|
76
163
|
};
|
|
77
164
|
constructor(config: PlaymosConfig);
|
|
78
165
|
/** Connect the player's wallet and return their address. */
|
|
@@ -107,6 +194,44 @@ declare class Playmos {
|
|
|
107
194
|
pay(input: PayInput): Promise<Payment>;
|
|
108
195
|
/** Playmos-owned skill-game entry (10%, 60/30/10 prize pool). Closes #343. */
|
|
109
196
|
enterRound(input: EnterRoundInput): Promise<Payment>;
|
|
197
|
+
/**
|
|
198
|
+
* `transfers` — read-back / confirmation for a prior `transfer()` (issues #27, #47).
|
|
199
|
+
* `get` reconciles once against chain truth; `wait` polls it to a terminal state
|
|
200
|
+
* for you (no hand-rolled loop). Both cover the gasless agent path.
|
|
201
|
+
*/
|
|
202
|
+
readonly transfers: {
|
|
203
|
+
/** One-shot reconcile of a transfer against chain truth. */
|
|
204
|
+
get: (transferId: string) => Promise<TransferReconcile>;
|
|
205
|
+
/**
|
|
206
|
+
* Block until a transfer reaches a terminal state — `settled` or `failed` —
|
|
207
|
+
* instead of hand-rolling a poll loop (#47). Polls `transfers.get(id)` every
|
|
208
|
+
* `intervalMs` (default 1000) until terminal, then RESOLVES with the final
|
|
209
|
+
* reconcile. Throws a typed `ApiError` (`detail.timeout`) if neither
|
|
210
|
+
* `timeoutMs` (default 30000) nor `maxAttempts` (default 40) is reached first.
|
|
211
|
+
*
|
|
212
|
+
* A `failed` transfer is a legitimate outcome, so it RESOLVES (status
|
|
213
|
+
* "failed") — inspect `result.status`; it does not throw.
|
|
214
|
+
*/
|
|
215
|
+
wait: (transferId: string, opts?: WaitOptions) => Promise<TransferReconcile>;
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* `transfer` — the value-movement base primitive (Phase 1a): move USDC from one wallet to another,
|
|
219
|
+
* with a per-call fee. The GAME LOGIC is the authority — you already decided the move is valid — so
|
|
220
|
+
* this is a direct, unconditional push (use `escrow`/`marketplace` when a trust boundary needs fair
|
|
221
|
+
* exchange). The service settles it through the protocol-agnostic settlement core (idempotent,
|
|
222
|
+
* reserve-before-broadcast) and the on-chain PlaymosTransfer / PlaymosTransferAuth contracts.
|
|
223
|
+
*
|
|
224
|
+
* Fee is per-call: `feeBps` 0–10000 (+ `feeSink`). `feeBps: 0` is an untaxed reward/faucet transfer.
|
|
225
|
+
* Retries are safe: pass the same `idempotencyKey` and a re-call NEVER broadcasts a second tx —
|
|
226
|
+
* it returns the cached result (`idempotentReplay: true`).
|
|
227
|
+
*
|
|
228
|
+
* Confirmation: treat `status === "settled" && txHash` as final. If `settling`, either call
|
|
229
|
+
* `playmos.transfers.wait(id)`, or pass `{ confirm: true }` here to block until terminal in one
|
|
230
|
+
* call (#47). BaseScan: `https://sepolia.basescan.org/tx/<txHash>`.
|
|
231
|
+
*
|
|
232
|
+
* NPC `from` requires `sk_test_` and settles gaslessly (NPC signs; service relays).
|
|
233
|
+
*/
|
|
234
|
+
transfer(input: TransferInput, opts?: TransferConfirmOptions): Promise<TransferResult>;
|
|
110
235
|
/** Verify a payment by the service's on-chain read (spec §6.1). Idempotent. */
|
|
111
236
|
verify(paymentId: string): Promise<VerifyResult>;
|
|
112
237
|
/**
|
|
@@ -133,6 +258,37 @@ declare function previewIapSplit(amount: string): {
|
|
|
133
258
|
fee: string;
|
|
134
259
|
net: string;
|
|
135
260
|
};
|
|
261
|
+
/**
|
|
262
|
+
* Local preview of a `transfer` fee split without any network — handy for UIs and quotes. Mirrors the
|
|
263
|
+
* on-chain floor math: `fee = floor(amount * feeBps / 10000)`, `net = amount − fee` (dust → payee).
|
|
264
|
+
*/
|
|
265
|
+
declare function previewTransferSplit(amount: string, feeBps: number): {
|
|
266
|
+
amount: string;
|
|
267
|
+
fee: string;
|
|
268
|
+
net: string;
|
|
269
|
+
feeBps: number;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Local preview of what an escrow `release` would pay out, without any network. Mirrors the on-chain
|
|
273
|
+
* floor math: `fee = floor(amount * feeBps / 10000)`, `net = amount − fee` (dust → payee). A `refund`
|
|
274
|
+
* returns the full `amount` with no fee, so it needs no preview.
|
|
275
|
+
*/
|
|
276
|
+
declare function previewEscrowFee(amount: string, feeBps: number): {
|
|
277
|
+
amount: string;
|
|
278
|
+
fee: string;
|
|
279
|
+
net: string;
|
|
280
|
+
feeBps: number;
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Local preview of a marketplace sale's payout, without any network. Mirrors the on-chain floor math
|
|
284
|
+
* (`fee = floor(price * feeBps / 10000)`, `net = price − fee`, dust → seller). A no-sale/refund pays 0.
|
|
285
|
+
*/
|
|
286
|
+
declare function previewMarketplaceSplit(price: string, feeBps: number): {
|
|
287
|
+
price: string;
|
|
288
|
+
fee: string;
|
|
289
|
+
net: string;
|
|
290
|
+
feeBps: number;
|
|
291
|
+
};
|
|
136
292
|
/** Local preview of the 60/30/10 entry split without any network. */
|
|
137
293
|
declare function previewPoolSplit(amount: string): {
|
|
138
294
|
amount: string;
|
|
@@ -141,6 +297,40 @@ declare function previewPoolSplit(amount: string): {
|
|
|
141
297
|
rake: string;
|
|
142
298
|
};
|
|
143
299
|
|
|
300
|
+
/**
|
|
301
|
+
* payout.ts — pure payout math for skill/contest settlement (issue #13).
|
|
302
|
+
*
|
|
303
|
+
* Scores NEVER enter this module. The studio ranks wallets (best-first) from its
|
|
304
|
+
* own leaderboard; we only turn that ranking + a payout rule into integer USDC
|
|
305
|
+
* base-unit amounts that sum EXACTLY to the payable pool.
|
|
306
|
+
*
|
|
307
|
+
* No network, no chain — fully unit-testable.
|
|
308
|
+
*/
|
|
309
|
+
type PayoutRule = {
|
|
310
|
+
kind: "winner-take-all";
|
|
311
|
+
} | {
|
|
312
|
+
kind: "top-n";
|
|
313
|
+
splitsBps: number[];
|
|
314
|
+
} | {
|
|
315
|
+
kind: "custom";
|
|
316
|
+
amounts: string[];
|
|
317
|
+
};
|
|
318
|
+
declare class PayoutError extends Error {
|
|
319
|
+
code: "payout_invalid";
|
|
320
|
+
constructor(message: string);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Apply the studio's payout rule to a payable pool and ranking (best-first).
|
|
324
|
+
*
|
|
325
|
+
* - Integer math only (bigint micro-USDC).
|
|
326
|
+
* - Sum of amounts == pool exactly; any remainder from floor division goes to rank 1.
|
|
327
|
+
* - Rejects empty ranking, bad splits, more winners than ranking, zero pool.
|
|
328
|
+
*/
|
|
329
|
+
declare function computePayout(pool: bigint, ranking: `0x${string}`[], rule: PayoutRule): {
|
|
330
|
+
wallet: `0x${string}`;
|
|
331
|
+
amount: bigint;
|
|
332
|
+
}[];
|
|
333
|
+
|
|
144
334
|
/**
|
|
145
335
|
* Money math — exact, integer-only, in USDC micro-units (6 decimals).
|
|
146
336
|
*
|
|
@@ -196,4 +386,132 @@ declare function ulid(seedTime?: number): string;
|
|
|
196
386
|
/** `${prefix}_${ulid()}` — e.g. `pay_01J…`, `entry_01J…`, `idem_01J…`. */
|
|
197
387
|
declare function prefixedId(prefix: string): string;
|
|
198
388
|
|
|
199
|
-
|
|
389
|
+
/**
|
|
390
|
+
* settlement.ts — the x402-ready settlement CORE contract (Phase 0).
|
|
391
|
+
*
|
|
392
|
+
* Two shared shapes every value-movement primitive (`transfer`, `escrow`,
|
|
393
|
+
* `marketplace`) AND the future x402 adapter build on. The whole point of
|
|
394
|
+
* naming them now is that x402 later becomes a thin HTTP-402 adapter with zero
|
|
395
|
+
* rework — see `docs/design/transfer-escrow-marketplace-spec.md` §"Architecture:
|
|
396
|
+
* x402-ready by design".
|
|
397
|
+
*
|
|
398
|
+
* PaymentRequirement — WHAT must be paid. A plain, JSON-safe object. A direct
|
|
399
|
+
* SDK call creates one and satisfies it immediately; an x402 "402 Payment
|
|
400
|
+
* Required" challenge is literally this object serialized onto the wire. So
|
|
401
|
+
* it is designed to round-trip to/from an HTTP 402 body with zero loss —
|
|
402
|
+
* `parsePaymentRequirement(serializePaymentRequirement(req))` is `req`.
|
|
403
|
+
*
|
|
404
|
+
* Authorization — HOW a settlement is authorized. A discriminated union so the
|
|
405
|
+
* settlement core never bakes in "direct SDK signature": today a
|
|
406
|
+
* `wallet-signature` (implemented), tomorrow an `x402-payload` (declared,
|
|
407
|
+
* not settled yet). This union is the seam that keeps x402 out of the core.
|
|
408
|
+
*
|
|
409
|
+
* Nothing here touches the network or the chain — these are the shared data
|
|
410
|
+
* shapes the SDK produces and the service's protocol-agnostic settlement core
|
|
411
|
+
* consumes.
|
|
412
|
+
*/
|
|
413
|
+
|
|
414
|
+
/** The only settlement asset in V1. Named so an x402 challenge carries it verbatim. */
|
|
415
|
+
type SettlementAsset = "USDC";
|
|
416
|
+
/**
|
|
417
|
+
* The shared payment contract — WHAT must be paid, independent of HOW it was
|
|
418
|
+
* requested (direct SDK call today, x402 challenge tomorrow).
|
|
419
|
+
*
|
|
420
|
+
* Every field is a JSON primitive so the object is byte-stable across an HTTP
|
|
421
|
+
* 402 body: mint it once, and both the direct path and the x402 path settle the
|
|
422
|
+
* exact same requirement, idempotent on `id`.
|
|
423
|
+
*/
|
|
424
|
+
interface PaymentRequirement {
|
|
425
|
+
/** The anchor id (`preq_<ulid>`). Settlement idempotency key + x402 challenge id. */
|
|
426
|
+
id: string;
|
|
427
|
+
/** The recipient wallet (the payee). Checksummed or lowercase 0x-address. */
|
|
428
|
+
payTo: `0x${string}`;
|
|
429
|
+
/** USD decimal string ("5.00") — same money convention as `pay()`/`enterRound()`. */
|
|
430
|
+
amount: string;
|
|
431
|
+
/** Only USDC in V1. */
|
|
432
|
+
asset: SettlementAsset;
|
|
433
|
+
/** Which chain settles this requirement. */
|
|
434
|
+
network: Network;
|
|
435
|
+
/** Optional free-form terms/memo, echoed on the receipt and in the 402 body. */
|
|
436
|
+
terms?: string;
|
|
437
|
+
/** ISO-8601 expiry. A challenge/authorization presented after this is rejected. */
|
|
438
|
+
expiresAt: string;
|
|
439
|
+
}
|
|
440
|
+
interface CreatePaymentRequirementInput {
|
|
441
|
+
/** Recipient wallet. */
|
|
442
|
+
payTo: `0x${string}`;
|
|
443
|
+
/** USD decimal string ("5.00"). */
|
|
444
|
+
amount: string;
|
|
445
|
+
/** Settlement chain. */
|
|
446
|
+
network: Network;
|
|
447
|
+
/** Defaults to "USDC". */
|
|
448
|
+
asset?: SettlementAsset;
|
|
449
|
+
/** Optional terms/memo. */
|
|
450
|
+
terms?: string;
|
|
451
|
+
/** Absolute ISO expiry. Overrides `expiresInMs`. Defaults to now + 15 min. */
|
|
452
|
+
expiresAt?: string;
|
|
453
|
+
/** Relative TTL from now, in ms. Ignored if `expiresAt` is set. */
|
|
454
|
+
expiresInMs?: number;
|
|
455
|
+
/** Supply for a deterministic id (e.g. to reuse an upstream id); else a `preq_<ulid>` is minted. */
|
|
456
|
+
id?: string;
|
|
457
|
+
/** Injectable clock for deterministic tests. */
|
|
458
|
+
now?: () => Date;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Build a validated {@link PaymentRequirement}. This is the single producer the
|
|
462
|
+
* direct primitives (`transfer`/`escrow`/`marketplace`) and — later — the x402
|
|
463
|
+
* adapter both call, so every requirement on the wire is shaped identically.
|
|
464
|
+
* Pure: no network, no chain, no id collisions (monotonic ULID).
|
|
465
|
+
*/
|
|
466
|
+
declare function createPaymentRequirement(input: CreatePaymentRequirementInput): PaymentRequirement;
|
|
467
|
+
/**
|
|
468
|
+
* Serialize a requirement to a plain, JSON-safe object — the exact body an x402
|
|
469
|
+
* "402 Payment Required" response carries. Undefined optionals are omitted so
|
|
470
|
+
* the shape is stable across `JSON.stringify` → `JSON.parse` → re-parse.
|
|
471
|
+
*/
|
|
472
|
+
declare function serializePaymentRequirement(req: PaymentRequirement): Record<string, unknown>;
|
|
473
|
+
/**
|
|
474
|
+
* Parse + validate an untrusted object (an HTTP 402 body, a queue message, a
|
|
475
|
+
* direct call) back into a {@link PaymentRequirement}. This is the exact decoder
|
|
476
|
+
* the x402 adapter reuses — it must reject anything malformed with a typed error.
|
|
477
|
+
*/
|
|
478
|
+
declare function parsePaymentRequirement(input: unknown): PaymentRequirement;
|
|
479
|
+
/**
|
|
480
|
+
* A settlement authorized by a wallet — the ONLY variant implemented in Phase 0.
|
|
481
|
+
* Covers both signer models the primitives support:
|
|
482
|
+
* - server-held NPC/agent wallets (the service signs) and
|
|
483
|
+
* - player Base Accounts (the client signs) —
|
|
484
|
+
* carrying either the settlement `txHash` the client already broadcast, or a
|
|
485
|
+
* `signature` + `payload` (e.g. EIP-3009 / EIP-5792 batch params) the service
|
|
486
|
+
* submits. Phase 0 only READS `txHash`; the signed-submit path lands in Phase 1.
|
|
487
|
+
*/
|
|
488
|
+
interface WalletSignatureAuthorization {
|
|
489
|
+
kind: "wallet-signature";
|
|
490
|
+
/** The wallet that authorized the move (payer / signer). */
|
|
491
|
+
from: `0x${string}`;
|
|
492
|
+
/** A settlement tx the client already broadcast (client-signed path). */
|
|
493
|
+
txHash?: `0x${string}`;
|
|
494
|
+
/** An off-chain signature the service submits on the payer's behalf. */
|
|
495
|
+
signature?: `0x${string}`;
|
|
496
|
+
/** Opaque protocol-specific authorization data (EIP-5792 calls, EIP-3009, …). */
|
|
497
|
+
payload?: Record<string, unknown>;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* A settlement authorized by an x402 payment payload (the `X-PAYMENT` header).
|
|
501
|
+
* DECLARED for the Phase 4 HTTP-402 adapter so the core's type surface is final
|
|
502
|
+
* now — but NOT settled in Phase 0: `settle()` throws a clear "not implemented
|
|
503
|
+
* yet" for this variant. This is the seam that keeps x402 out of the core.
|
|
504
|
+
*/
|
|
505
|
+
interface X402PayloadAuthorization {
|
|
506
|
+
kind: "x402-payload";
|
|
507
|
+
/** The raw, opaque x402 payment payload decoded from the request. */
|
|
508
|
+
payload: Record<string, unknown>;
|
|
509
|
+
}
|
|
510
|
+
/** How a settlement is authorized — protocol-agnostic by construction. */
|
|
511
|
+
type Authorization = WalletSignatureAuthorization | X402PayloadAuthorization;
|
|
512
|
+
/** Narrow to the implemented wallet-signature variant. */
|
|
513
|
+
declare function isWalletSignatureAuthorization(auth: Authorization): auth is WalletSignatureAuthorization;
|
|
514
|
+
/** Narrow to the declared-but-unimplemented x402 variant. */
|
|
515
|
+
declare function isX402PayloadAuthorization(auth: Authorization): auth is X402PayloadAuthorization;
|
|
516
|
+
|
|
517
|
+
export { AgentFundResult, AgentWallet, type Authorization, CHAIN_ID, type CreatePaymentRequirementInput, DEFAULT_API_BASE_URL, EnterRoundInput, EscrowHoldInput, EscrowHoldResult, EscrowResolveResult, Listing, MICRO_PER_USDC, MarketplaceGetResult, MarketplaceListInput, MarketplaceSaleResult, Network, PayInput, Payment, type PaymentRequirement, PayoutError, type PayoutRule as PayoutRuleCompute, Playmos, PlaymosConfig, RoundOpenInput, RoundSettleInput, RoundState, SettleRoundResult, type SettlementAsset, TransferConfirmOptions, TransferInput, TransferReconcile, TransferResult, USDC_ADDRESS, USDC_DECIMALS, VerifyResult, WaitOptions, type WalletSignatureAuthorization, WebhookEvent, type X402PayloadAuthorization, computeIapSplit, computePayout, computePoolSplit, createPaymentRequirement, formatMicroToUsd, isWalletSignatureAuthorization, isX402PayloadAuthorization, parsePaymentRequirement, parseUsdToMicro, prefixedId, previewEscrowFee, previewIapSplit, previewMarketplaceSplit, previewPoolSplit, previewTransferSplit, serializePaymentRequirement, ulid };
|