@playmos/sdk 0.1.4 → 0.1.6
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 +86 -0
- package/dist/chunk-B7SHFZYY.js +62 -0
- package/dist/chunk-B7SHFZYY.js.map +1 -0
- package/dist/errors-B-85VYMv.d.cts +224 -0
- package/dist/errors-B-85VYMv.d.ts +224 -0
- package/dist/index.cjs +11 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -248
- package/dist/index.d.ts +9 -248
- package/dist/index.js +14 -103
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +63 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +26 -0
- package/dist/server.d.ts +26 -0
- package/dist/server.js +47 -0
- package/dist/server.js.map +1 -0
- package/package.json +6 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,178 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* The old vendored surface advertised four wallet connectors that silently
|
|
5
|
-
* returned {connected:false} and config fields the code never read. Here the
|
|
6
|
-
* types expose exactly what V1 does: two connectors, the fields `pay()` /
|
|
7
|
-
* `enterRound()` actually use, and no more.
|
|
8
|
-
*/
|
|
9
|
-
type Network = "base" | "base-sepolia";
|
|
10
|
-
/** Only the connectors that are actually implemented. */
|
|
11
|
-
type WalletConnector = "base-account" | "injected";
|
|
12
|
-
type GasMode = "sponsored" | "player";
|
|
13
|
-
type PaymentStatus = "created" | "pending" | "confirmed" | "failed";
|
|
14
|
-
/** Minimal EIP-1193 provider shape (what the wallet must expose). */
|
|
15
|
-
interface Eip1193Provider {
|
|
16
|
-
request(args: {
|
|
17
|
-
method: string;
|
|
18
|
-
params?: unknown[] | object;
|
|
19
|
-
}): Promise<unknown>;
|
|
20
|
-
}
|
|
21
|
-
interface GasConfig {
|
|
22
|
-
mode?: GasMode;
|
|
23
|
-
/** CDP paymaster URL — required only for `mode: "sponsored"`. */
|
|
24
|
-
paymasterUrl?: string;
|
|
25
|
-
}
|
|
26
|
-
interface WalletConfig {
|
|
27
|
-
connector?: WalletConnector;
|
|
28
|
-
/**
|
|
29
|
-
* Pre-built EIP-1193 provider. If omitted, `injected` uses globalThis.ethereum
|
|
30
|
-
* and `base-account` expects a provider supplied by the Base Account SDK host.
|
|
31
|
-
*/
|
|
32
|
-
provider?: Eip1193Provider;
|
|
33
|
-
}
|
|
34
|
-
/** Per-game contract addresses. On testnet these come from the service intent,
|
|
35
|
-
* but a studio may pin them explicitly (matches the dogfood adapter). */
|
|
36
|
-
interface ContractConfig {
|
|
37
|
-
usdc?: `0x${string}`;
|
|
38
|
-
playmosPay?: `0x${string}`;
|
|
39
|
-
prizePool?: `0x${string}`;
|
|
40
|
-
}
|
|
41
|
-
interface AgentEconomyConfig {
|
|
42
|
-
enabled?: boolean;
|
|
43
|
-
/** Tax skimmed to Playmos on each agent↔agent transfer. 100 = 1% (default). */
|
|
44
|
-
taxBps?: number;
|
|
45
|
-
}
|
|
46
|
-
interface PlaymosConfig {
|
|
47
|
-
/** pk_test_* (sandbox / Base Sepolia) or pk_live_* (production / Base mainnet).
|
|
48
|
-
* The key prefix selects the environment. */
|
|
49
|
-
apiKey: string;
|
|
50
|
-
/** Override the network derived from the key. Explicit value wins. */
|
|
51
|
-
network?: Network;
|
|
52
|
-
wallet?: WalletConfig;
|
|
53
|
-
gas?: GasConfig;
|
|
54
|
-
agentEconomy?: AgentEconomyConfig;
|
|
55
|
-
contracts?: ContractConfig;
|
|
56
|
-
/** Escape hatch; defaults to the right env's base URL. */
|
|
57
|
-
apiBaseUrl?: string;
|
|
58
|
-
/**
|
|
59
|
-
* Explicit, clearly-labeled offline unit-test helper — instant, deterministic,
|
|
60
|
-
* NO network, NO chain. Never the default, never conflated with sandbox. Note:
|
|
61
|
-
* even mock results use the REAL status union (never a synthetic "mocked").
|
|
62
|
-
*/
|
|
63
|
-
mock?: boolean;
|
|
64
|
-
}
|
|
65
|
-
interface PayInput {
|
|
66
|
-
/** USD decimal string ("4.99"). Rejected: ≤ 0, non-numeric, > 2 dp. */
|
|
67
|
-
amount: string;
|
|
68
|
-
/** Your product id, echoed on the receipt + webhook. */
|
|
69
|
-
sku: string;
|
|
70
|
-
/** Your opaque user id. */
|
|
71
|
-
playerId: string;
|
|
72
|
-
/**
|
|
73
|
-
* The game this IAP belongs to. Optional: when your API key maps to exactly
|
|
74
|
-
* one game the service resolves it for you (the quickstart). Supply it
|
|
75
|
-
* explicitly when your key spans multiple games.
|
|
76
|
-
*/
|
|
77
|
-
gameId?: string;
|
|
78
|
-
/** The studio wallet that receives the 99%. Falls back to the service default. */
|
|
79
|
-
studio?: `0x${string}`;
|
|
80
|
-
/** Supply your own to make retries safe; omit and the SDK generates a ULID. */
|
|
81
|
-
idempotencyKey?: string;
|
|
82
|
-
metadata?: Record<string, string>;
|
|
83
|
-
}
|
|
84
|
-
interface EnterRoundInput {
|
|
85
|
-
/** The game — selects its prize-pool contract. */
|
|
86
|
-
gameId: string;
|
|
87
|
-
/** The round being entered. */
|
|
88
|
-
roundId: string;
|
|
89
|
-
/** USD entry — grows this round's pool. */
|
|
90
|
-
amount: string;
|
|
91
|
-
playerId: string;
|
|
92
|
-
idempotencyKey?: string;
|
|
93
|
-
metadata?: Record<string, string>;
|
|
94
|
-
/**
|
|
95
|
-
* Advanced (games that manage their own on-chain rounds, e.g. the Playmos
|
|
96
|
-
* game-hub kit): the EXACT on-chain round key to enter — overrides the default
|
|
97
|
-
* `${gameId}:${roundId}` derivation. Set it to the value your game's server
|
|
98
|
-
* verifies `hasEntered` against (e.g. "bjtest:T1").
|
|
99
|
-
*/
|
|
100
|
-
roundKey?: string;
|
|
101
|
-
/**
|
|
102
|
-
* Advanced: the EXACT on-chain identity for this paid attempt (e.g.
|
|
103
|
-
* "0xWallet#nonce"). Overrides the server-generated identity so the on-chain
|
|
104
|
-
* entry and your server's `hasEntered` check line up. One entry per identity.
|
|
105
|
-
*/
|
|
106
|
-
identity?: string;
|
|
107
|
-
}
|
|
108
|
-
interface Payment {
|
|
109
|
-
/** `pay_…` (IAP) or `entry_…` (prize-pool) — ULID, server-issued, unique. */
|
|
110
|
-
id: string;
|
|
111
|
-
status: PaymentStatus;
|
|
112
|
-
/** "iap" (1% external) or "entry" (60/30/10 prize-pool). */
|
|
113
|
-
kind: "iap" | "entry";
|
|
114
|
-
amount: string;
|
|
115
|
-
fee: string;
|
|
116
|
-
net: string;
|
|
117
|
-
/** Present for prize-pool entries: the 60/30/10 breakdown in USD. */
|
|
118
|
-
split?: {
|
|
119
|
-
pool: string;
|
|
120
|
-
seed: string;
|
|
121
|
-
rake: string;
|
|
122
|
-
};
|
|
123
|
-
sku?: string;
|
|
124
|
-
roundId?: string;
|
|
125
|
-
gameId?: string;
|
|
126
|
-
playerId: string;
|
|
127
|
-
txHash?: `0x${string}`;
|
|
128
|
-
chain: Network;
|
|
129
|
-
createdAt: string;
|
|
130
|
-
metadata?: Record<string, string>;
|
|
131
|
-
/**
|
|
132
|
-
* The on-chain identity used for a prize-pool entry (echo of
|
|
133
|
-
* `EnterRoundInput.identity` or the SDK-derived value) — reconcile against your
|
|
134
|
-
* server's `hasEntered`.
|
|
135
|
-
*/
|
|
136
|
-
identity?: string;
|
|
137
|
-
/** True only when produced by the labeled `mock: true` helper. */
|
|
138
|
-
mock?: boolean;
|
|
139
|
-
}
|
|
140
|
-
/** What `verify()` resolves to (server reads the chain). */
|
|
141
|
-
interface VerifyResult {
|
|
142
|
-
id: string;
|
|
143
|
-
status: PaymentStatus;
|
|
144
|
-
amount: string;
|
|
145
|
-
fee: string;
|
|
146
|
-
net: string;
|
|
147
|
-
txHash?: `0x${string}`;
|
|
148
|
-
playerId: string;
|
|
149
|
-
sku?: string;
|
|
150
|
-
roundId?: string;
|
|
151
|
-
chain: Network;
|
|
152
|
-
/** How the service derived this status: an on-chain read, the honest cache, or
|
|
153
|
-
* degraded (chain reads not configured). Lets the SDK stop polling when the
|
|
154
|
-
* service can never confirm on-chain. */
|
|
155
|
-
verifiedVia?: "chain" | "cache" | "degraded";
|
|
156
|
-
chainReads?: "enabled" | "degraded";
|
|
157
|
-
}
|
|
158
|
-
type WebhookEventType = "payment.confirmed" | "payment.failed" | "payout.settled" | "refund.processed";
|
|
159
|
-
interface WebhookEvent {
|
|
160
|
-
id: string;
|
|
161
|
-
type: WebhookEventType;
|
|
162
|
-
createdAt: string;
|
|
163
|
-
data: {
|
|
164
|
-
id: string;
|
|
165
|
-
status: PaymentStatus;
|
|
166
|
-
amount: string;
|
|
167
|
-
fee: string;
|
|
168
|
-
net: string;
|
|
169
|
-
playerId: string;
|
|
170
|
-
sku?: string;
|
|
171
|
-
txHash?: `0x${string}`;
|
|
172
|
-
chain: Network;
|
|
173
|
-
metadata?: Record<string, string>;
|
|
174
|
-
};
|
|
175
|
-
}
|
|
1
|
+
import { N as Network, P as PlaymosConfig, W as WebhookEvent, a as PayInput, b as Payment, E as EnterRoundInput, V as VerifyResult } from './errors-B-85VYMv.cjs';
|
|
2
|
+
export { A as AgentEconomyConfig, c as ApiError, d as AuthError, C as ConfigError, e as ContractConfig, f as Eip1193Provider, G as GasConfig, g as GasMode, I as InsufficientGasError, h as InvalidAmountError, M as MissingFieldError, i as PaymentFailedError, j as PaymentStatus, k as PlaymosError, l as PlaymosErrorCode, m as WalletConfig, n as WalletConnectionError, o as WalletConnector, p as WebhookEventType } from './errors-B-85VYMv.cjs';
|
|
176
3
|
|
|
177
4
|
/**
|
|
178
5
|
* Environment resolution + the canonical address book.
|
|
@@ -210,8 +37,12 @@ declare class Playmos {
|
|
|
210
37
|
readonly env: ResolvedEnv;
|
|
211
38
|
private readonly http;
|
|
212
39
|
readonly webhooks: {
|
|
213
|
-
/**
|
|
214
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Webhook verification is server-only (it uses node:crypto) and no longer
|
|
42
|
+
* ships in the browser entry (issue #9). On a backend, import it directly:
|
|
43
|
+
* import { verifyWebhook } from "@playmos/sdk/server";
|
|
44
|
+
*/
|
|
45
|
+
verify: (_rawBody: string | Buffer, _signatureHeader: string | string[] | undefined, _secret: string) => WebhookEvent;
|
|
215
46
|
};
|
|
216
47
|
readonly payouts: {
|
|
217
48
|
/** Choose how the studio is paid: "usdc" (default) or "fiat" (Bridge). */
|
|
@@ -310,76 +141,6 @@ declare function previewPoolSplit(amount: string): {
|
|
|
310
141
|
rake: string;
|
|
311
142
|
};
|
|
312
143
|
|
|
313
|
-
/**
|
|
314
|
-
* Typed, actionable errors — the Stripe bar (spec §11).
|
|
315
|
-
*
|
|
316
|
-
* Every error carries a stable machine-readable `code` and is thrown at the
|
|
317
|
-
* EARLIEST possible layer: input errors fire client-side before any network or
|
|
318
|
-
* chain call, so a studio never pays gas to discover a typo.
|
|
319
|
-
*/
|
|
320
|
-
type PlaymosErrorCode = "invalid_amount" | "missing_field" | "insufficient_gas" | "wallet_connection" | "payment_failed" | "auth" | "api_error" | "config";
|
|
321
|
-
declare class PlaymosError extends Error {
|
|
322
|
-
readonly code: PlaymosErrorCode;
|
|
323
|
-
/** Optional machine context (e.g. the offending field, the http status). */
|
|
324
|
-
readonly detail?: Record<string, unknown>;
|
|
325
|
-
constructor(code: PlaymosErrorCode, message: string, detail?: Record<string, unknown>);
|
|
326
|
-
}
|
|
327
|
-
/** amount ≤ 0, non-numeric, empty, or more than 2 decimal places. */
|
|
328
|
-
declare class InvalidAmountError extends PlaymosError {
|
|
329
|
-
constructor(amount: unknown);
|
|
330
|
-
}
|
|
331
|
-
/** A required field (sku, playerId, gameId, roundId, agentId…) was empty. */
|
|
332
|
-
declare class MissingFieldError extends PlaymosError {
|
|
333
|
-
constructor(field: string);
|
|
334
|
-
}
|
|
335
|
-
/** gas mode "player" and the player's ETH is too low to cover gas (pre-check, §7). */
|
|
336
|
-
declare class InsufficientGasError extends PlaymosError {
|
|
337
|
-
constructor(detail?: Record<string, unknown>);
|
|
338
|
-
}
|
|
339
|
-
/** The player closed or failed the wallet sheet, or no provider is available. */
|
|
340
|
-
declare class WalletConnectionError extends PlaymosError {
|
|
341
|
-
constructor(message?: string, detail?: Record<string, unknown>);
|
|
342
|
-
}
|
|
343
|
-
/** The on-chain settlement reverted, was cancelled, or timed out. */
|
|
344
|
-
declare class PaymentFailedError extends PlaymosError {
|
|
345
|
-
constructor(message?: string, detail?: Record<string, unknown>);
|
|
346
|
-
}
|
|
347
|
-
/** Bad, missing, or wrong-environment API key (e.g. a pk_test_ key on a live route). */
|
|
348
|
-
declare class AuthError extends PlaymosError {
|
|
349
|
-
constructor(message?: string, detail?: Record<string, unknown>);
|
|
350
|
-
}
|
|
351
|
-
/** The Playmos service returned a non-2xx we don't have a more specific error for. */
|
|
352
|
-
declare class ApiError extends PlaymosError {
|
|
353
|
-
constructor(message: string, detail?: Record<string, unknown>);
|
|
354
|
-
}
|
|
355
|
-
/** SDK misconfiguration (e.g. a missing contract address for on-chain mode). */
|
|
356
|
-
declare class ConfigError extends PlaymosError {
|
|
357
|
-
constructor(message: string, detail?: Record<string, unknown>);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Webhook signature verification (spec §6.2) — server-side only.
|
|
362
|
-
*
|
|
363
|
-
* Signature scheme (mirrors the Playmos service byte-for-byte):
|
|
364
|
-
* header `X-Playmos-Signature: t=<unixSeconds>,v1=<hex>`
|
|
365
|
-
* where <hex> = HMAC_SHA256(secret, `${t}.${rawBody}`)
|
|
366
|
-
*
|
|
367
|
-
* Verify BEFORE trusting an event. Uses node:crypto (constant-time compare) and
|
|
368
|
-
* rejects stale timestamps to blunt replay. Throws on any mismatch.
|
|
369
|
-
*/
|
|
370
|
-
|
|
371
|
-
declare class WebhookSignatureError extends PlaymosError {
|
|
372
|
-
constructor(message: string);
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Verify a webhook and return the parsed event. `rawBody` MUST be the exact raw
|
|
376
|
-
* request bytes (use express.raw / fastify rawBody) — a re-serialized JSON body
|
|
377
|
-
* will not match the signature.
|
|
378
|
-
*/
|
|
379
|
-
declare function verifyWebhook(rawBody: string | Buffer, signatureHeader: string | string[] | undefined, secret: string, opts?: {
|
|
380
|
-
toleranceSeconds?: number;
|
|
381
|
-
}): WebhookEvent;
|
|
382
|
-
|
|
383
144
|
/**
|
|
384
145
|
* Money math — exact, integer-only, in USDC micro-units (6 decimals).
|
|
385
146
|
*
|
|
@@ -435,4 +196,4 @@ declare function ulid(seedTime?: number): string;
|
|
|
435
196
|
/** `${prefix}_${ulid()}` — e.g. `pay_01J…`, `entry_01J…`, `idem_01J…`. */
|
|
436
197
|
declare function prefixedId(prefix: string): string;
|
|
437
198
|
|
|
438
|
-
export {
|
|
199
|
+
export { CHAIN_ID, DEFAULT_API_BASE_URL, EnterRoundInput, MICRO_PER_USDC, Network, PayInput, Payment, Playmos, PlaymosConfig, USDC_ADDRESS, USDC_DECIMALS, VerifyResult, WebhookEvent, computeIapSplit, computePoolSplit, formatMicroToUsd, parseUsdToMicro, prefixedId, previewIapSplit, previewPoolSplit, ulid };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,178 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* The old vendored surface advertised four wallet connectors that silently
|
|
5
|
-
* returned {connected:false} and config fields the code never read. Here the
|
|
6
|
-
* types expose exactly what V1 does: two connectors, the fields `pay()` /
|
|
7
|
-
* `enterRound()` actually use, and no more.
|
|
8
|
-
*/
|
|
9
|
-
type Network = "base" | "base-sepolia";
|
|
10
|
-
/** Only the connectors that are actually implemented. */
|
|
11
|
-
type WalletConnector = "base-account" | "injected";
|
|
12
|
-
type GasMode = "sponsored" | "player";
|
|
13
|
-
type PaymentStatus = "created" | "pending" | "confirmed" | "failed";
|
|
14
|
-
/** Minimal EIP-1193 provider shape (what the wallet must expose). */
|
|
15
|
-
interface Eip1193Provider {
|
|
16
|
-
request(args: {
|
|
17
|
-
method: string;
|
|
18
|
-
params?: unknown[] | object;
|
|
19
|
-
}): Promise<unknown>;
|
|
20
|
-
}
|
|
21
|
-
interface GasConfig {
|
|
22
|
-
mode?: GasMode;
|
|
23
|
-
/** CDP paymaster URL — required only for `mode: "sponsored"`. */
|
|
24
|
-
paymasterUrl?: string;
|
|
25
|
-
}
|
|
26
|
-
interface WalletConfig {
|
|
27
|
-
connector?: WalletConnector;
|
|
28
|
-
/**
|
|
29
|
-
* Pre-built EIP-1193 provider. If omitted, `injected` uses globalThis.ethereum
|
|
30
|
-
* and `base-account` expects a provider supplied by the Base Account SDK host.
|
|
31
|
-
*/
|
|
32
|
-
provider?: Eip1193Provider;
|
|
33
|
-
}
|
|
34
|
-
/** Per-game contract addresses. On testnet these come from the service intent,
|
|
35
|
-
* but a studio may pin them explicitly (matches the dogfood adapter). */
|
|
36
|
-
interface ContractConfig {
|
|
37
|
-
usdc?: `0x${string}`;
|
|
38
|
-
playmosPay?: `0x${string}`;
|
|
39
|
-
prizePool?: `0x${string}`;
|
|
40
|
-
}
|
|
41
|
-
interface AgentEconomyConfig {
|
|
42
|
-
enabled?: boolean;
|
|
43
|
-
/** Tax skimmed to Playmos on each agent↔agent transfer. 100 = 1% (default). */
|
|
44
|
-
taxBps?: number;
|
|
45
|
-
}
|
|
46
|
-
interface PlaymosConfig {
|
|
47
|
-
/** pk_test_* (sandbox / Base Sepolia) or pk_live_* (production / Base mainnet).
|
|
48
|
-
* The key prefix selects the environment. */
|
|
49
|
-
apiKey: string;
|
|
50
|
-
/** Override the network derived from the key. Explicit value wins. */
|
|
51
|
-
network?: Network;
|
|
52
|
-
wallet?: WalletConfig;
|
|
53
|
-
gas?: GasConfig;
|
|
54
|
-
agentEconomy?: AgentEconomyConfig;
|
|
55
|
-
contracts?: ContractConfig;
|
|
56
|
-
/** Escape hatch; defaults to the right env's base URL. */
|
|
57
|
-
apiBaseUrl?: string;
|
|
58
|
-
/**
|
|
59
|
-
* Explicit, clearly-labeled offline unit-test helper — instant, deterministic,
|
|
60
|
-
* NO network, NO chain. Never the default, never conflated with sandbox. Note:
|
|
61
|
-
* even mock results use the REAL status union (never a synthetic "mocked").
|
|
62
|
-
*/
|
|
63
|
-
mock?: boolean;
|
|
64
|
-
}
|
|
65
|
-
interface PayInput {
|
|
66
|
-
/** USD decimal string ("4.99"). Rejected: ≤ 0, non-numeric, > 2 dp. */
|
|
67
|
-
amount: string;
|
|
68
|
-
/** Your product id, echoed on the receipt + webhook. */
|
|
69
|
-
sku: string;
|
|
70
|
-
/** Your opaque user id. */
|
|
71
|
-
playerId: string;
|
|
72
|
-
/**
|
|
73
|
-
* The game this IAP belongs to. Optional: when your API key maps to exactly
|
|
74
|
-
* one game the service resolves it for you (the quickstart). Supply it
|
|
75
|
-
* explicitly when your key spans multiple games.
|
|
76
|
-
*/
|
|
77
|
-
gameId?: string;
|
|
78
|
-
/** The studio wallet that receives the 99%. Falls back to the service default. */
|
|
79
|
-
studio?: `0x${string}`;
|
|
80
|
-
/** Supply your own to make retries safe; omit and the SDK generates a ULID. */
|
|
81
|
-
idempotencyKey?: string;
|
|
82
|
-
metadata?: Record<string, string>;
|
|
83
|
-
}
|
|
84
|
-
interface EnterRoundInput {
|
|
85
|
-
/** The game — selects its prize-pool contract. */
|
|
86
|
-
gameId: string;
|
|
87
|
-
/** The round being entered. */
|
|
88
|
-
roundId: string;
|
|
89
|
-
/** USD entry — grows this round's pool. */
|
|
90
|
-
amount: string;
|
|
91
|
-
playerId: string;
|
|
92
|
-
idempotencyKey?: string;
|
|
93
|
-
metadata?: Record<string, string>;
|
|
94
|
-
/**
|
|
95
|
-
* Advanced (games that manage their own on-chain rounds, e.g. the Playmos
|
|
96
|
-
* game-hub kit): the EXACT on-chain round key to enter — overrides the default
|
|
97
|
-
* `${gameId}:${roundId}` derivation. Set it to the value your game's server
|
|
98
|
-
* verifies `hasEntered` against (e.g. "bjtest:T1").
|
|
99
|
-
*/
|
|
100
|
-
roundKey?: string;
|
|
101
|
-
/**
|
|
102
|
-
* Advanced: the EXACT on-chain identity for this paid attempt (e.g.
|
|
103
|
-
* "0xWallet#nonce"). Overrides the server-generated identity so the on-chain
|
|
104
|
-
* entry and your server's `hasEntered` check line up. One entry per identity.
|
|
105
|
-
*/
|
|
106
|
-
identity?: string;
|
|
107
|
-
}
|
|
108
|
-
interface Payment {
|
|
109
|
-
/** `pay_…` (IAP) or `entry_…` (prize-pool) — ULID, server-issued, unique. */
|
|
110
|
-
id: string;
|
|
111
|
-
status: PaymentStatus;
|
|
112
|
-
/** "iap" (1% external) or "entry" (60/30/10 prize-pool). */
|
|
113
|
-
kind: "iap" | "entry";
|
|
114
|
-
amount: string;
|
|
115
|
-
fee: string;
|
|
116
|
-
net: string;
|
|
117
|
-
/** Present for prize-pool entries: the 60/30/10 breakdown in USD. */
|
|
118
|
-
split?: {
|
|
119
|
-
pool: string;
|
|
120
|
-
seed: string;
|
|
121
|
-
rake: string;
|
|
122
|
-
};
|
|
123
|
-
sku?: string;
|
|
124
|
-
roundId?: string;
|
|
125
|
-
gameId?: string;
|
|
126
|
-
playerId: string;
|
|
127
|
-
txHash?: `0x${string}`;
|
|
128
|
-
chain: Network;
|
|
129
|
-
createdAt: string;
|
|
130
|
-
metadata?: Record<string, string>;
|
|
131
|
-
/**
|
|
132
|
-
* The on-chain identity used for a prize-pool entry (echo of
|
|
133
|
-
* `EnterRoundInput.identity` or the SDK-derived value) — reconcile against your
|
|
134
|
-
* server's `hasEntered`.
|
|
135
|
-
*/
|
|
136
|
-
identity?: string;
|
|
137
|
-
/** True only when produced by the labeled `mock: true` helper. */
|
|
138
|
-
mock?: boolean;
|
|
139
|
-
}
|
|
140
|
-
/** What `verify()` resolves to (server reads the chain). */
|
|
141
|
-
interface VerifyResult {
|
|
142
|
-
id: string;
|
|
143
|
-
status: PaymentStatus;
|
|
144
|
-
amount: string;
|
|
145
|
-
fee: string;
|
|
146
|
-
net: string;
|
|
147
|
-
txHash?: `0x${string}`;
|
|
148
|
-
playerId: string;
|
|
149
|
-
sku?: string;
|
|
150
|
-
roundId?: string;
|
|
151
|
-
chain: Network;
|
|
152
|
-
/** How the service derived this status: an on-chain read, the honest cache, or
|
|
153
|
-
* degraded (chain reads not configured). Lets the SDK stop polling when the
|
|
154
|
-
* service can never confirm on-chain. */
|
|
155
|
-
verifiedVia?: "chain" | "cache" | "degraded";
|
|
156
|
-
chainReads?: "enabled" | "degraded";
|
|
157
|
-
}
|
|
158
|
-
type WebhookEventType = "payment.confirmed" | "payment.failed" | "payout.settled" | "refund.processed";
|
|
159
|
-
interface WebhookEvent {
|
|
160
|
-
id: string;
|
|
161
|
-
type: WebhookEventType;
|
|
162
|
-
createdAt: string;
|
|
163
|
-
data: {
|
|
164
|
-
id: string;
|
|
165
|
-
status: PaymentStatus;
|
|
166
|
-
amount: string;
|
|
167
|
-
fee: string;
|
|
168
|
-
net: string;
|
|
169
|
-
playerId: string;
|
|
170
|
-
sku?: string;
|
|
171
|
-
txHash?: `0x${string}`;
|
|
172
|
-
chain: Network;
|
|
173
|
-
metadata?: Record<string, string>;
|
|
174
|
-
};
|
|
175
|
-
}
|
|
1
|
+
import { N as Network, P as PlaymosConfig, W as WebhookEvent, a as PayInput, b as Payment, E as EnterRoundInput, V as VerifyResult } from './errors-B-85VYMv.js';
|
|
2
|
+
export { A as AgentEconomyConfig, c as ApiError, d as AuthError, C as ConfigError, e as ContractConfig, f as Eip1193Provider, G as GasConfig, g as GasMode, I as InsufficientGasError, h as InvalidAmountError, M as MissingFieldError, i as PaymentFailedError, j as PaymentStatus, k as PlaymosError, l as PlaymosErrorCode, m as WalletConfig, n as WalletConnectionError, o as WalletConnector, p as WebhookEventType } from './errors-B-85VYMv.js';
|
|
176
3
|
|
|
177
4
|
/**
|
|
178
5
|
* Environment resolution + the canonical address book.
|
|
@@ -210,8 +37,12 @@ declare class Playmos {
|
|
|
210
37
|
readonly env: ResolvedEnv;
|
|
211
38
|
private readonly http;
|
|
212
39
|
readonly webhooks: {
|
|
213
|
-
/**
|
|
214
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Webhook verification is server-only (it uses node:crypto) and no longer
|
|
42
|
+
* ships in the browser entry (issue #9). On a backend, import it directly:
|
|
43
|
+
* import { verifyWebhook } from "@playmos/sdk/server";
|
|
44
|
+
*/
|
|
45
|
+
verify: (_rawBody: string | Buffer, _signatureHeader: string | string[] | undefined, _secret: string) => WebhookEvent;
|
|
215
46
|
};
|
|
216
47
|
readonly payouts: {
|
|
217
48
|
/** Choose how the studio is paid: "usdc" (default) or "fiat" (Bridge). */
|
|
@@ -310,76 +141,6 @@ declare function previewPoolSplit(amount: string): {
|
|
|
310
141
|
rake: string;
|
|
311
142
|
};
|
|
312
143
|
|
|
313
|
-
/**
|
|
314
|
-
* Typed, actionable errors — the Stripe bar (spec §11).
|
|
315
|
-
*
|
|
316
|
-
* Every error carries a stable machine-readable `code` and is thrown at the
|
|
317
|
-
* EARLIEST possible layer: input errors fire client-side before any network or
|
|
318
|
-
* chain call, so a studio never pays gas to discover a typo.
|
|
319
|
-
*/
|
|
320
|
-
type PlaymosErrorCode = "invalid_amount" | "missing_field" | "insufficient_gas" | "wallet_connection" | "payment_failed" | "auth" | "api_error" | "config";
|
|
321
|
-
declare class PlaymosError extends Error {
|
|
322
|
-
readonly code: PlaymosErrorCode;
|
|
323
|
-
/** Optional machine context (e.g. the offending field, the http status). */
|
|
324
|
-
readonly detail?: Record<string, unknown>;
|
|
325
|
-
constructor(code: PlaymosErrorCode, message: string, detail?: Record<string, unknown>);
|
|
326
|
-
}
|
|
327
|
-
/** amount ≤ 0, non-numeric, empty, or more than 2 decimal places. */
|
|
328
|
-
declare class InvalidAmountError extends PlaymosError {
|
|
329
|
-
constructor(amount: unknown);
|
|
330
|
-
}
|
|
331
|
-
/** A required field (sku, playerId, gameId, roundId, agentId…) was empty. */
|
|
332
|
-
declare class MissingFieldError extends PlaymosError {
|
|
333
|
-
constructor(field: string);
|
|
334
|
-
}
|
|
335
|
-
/** gas mode "player" and the player's ETH is too low to cover gas (pre-check, §7). */
|
|
336
|
-
declare class InsufficientGasError extends PlaymosError {
|
|
337
|
-
constructor(detail?: Record<string, unknown>);
|
|
338
|
-
}
|
|
339
|
-
/** The player closed or failed the wallet sheet, or no provider is available. */
|
|
340
|
-
declare class WalletConnectionError extends PlaymosError {
|
|
341
|
-
constructor(message?: string, detail?: Record<string, unknown>);
|
|
342
|
-
}
|
|
343
|
-
/** The on-chain settlement reverted, was cancelled, or timed out. */
|
|
344
|
-
declare class PaymentFailedError extends PlaymosError {
|
|
345
|
-
constructor(message?: string, detail?: Record<string, unknown>);
|
|
346
|
-
}
|
|
347
|
-
/** Bad, missing, or wrong-environment API key (e.g. a pk_test_ key on a live route). */
|
|
348
|
-
declare class AuthError extends PlaymosError {
|
|
349
|
-
constructor(message?: string, detail?: Record<string, unknown>);
|
|
350
|
-
}
|
|
351
|
-
/** The Playmos service returned a non-2xx we don't have a more specific error for. */
|
|
352
|
-
declare class ApiError extends PlaymosError {
|
|
353
|
-
constructor(message: string, detail?: Record<string, unknown>);
|
|
354
|
-
}
|
|
355
|
-
/** SDK misconfiguration (e.g. a missing contract address for on-chain mode). */
|
|
356
|
-
declare class ConfigError extends PlaymosError {
|
|
357
|
-
constructor(message: string, detail?: Record<string, unknown>);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Webhook signature verification (spec §6.2) — server-side only.
|
|
362
|
-
*
|
|
363
|
-
* Signature scheme (mirrors the Playmos service byte-for-byte):
|
|
364
|
-
* header `X-Playmos-Signature: t=<unixSeconds>,v1=<hex>`
|
|
365
|
-
* where <hex> = HMAC_SHA256(secret, `${t}.${rawBody}`)
|
|
366
|
-
*
|
|
367
|
-
* Verify BEFORE trusting an event. Uses node:crypto (constant-time compare) and
|
|
368
|
-
* rejects stale timestamps to blunt replay. Throws on any mismatch.
|
|
369
|
-
*/
|
|
370
|
-
|
|
371
|
-
declare class WebhookSignatureError extends PlaymosError {
|
|
372
|
-
constructor(message: string);
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Verify a webhook and return the parsed event. `rawBody` MUST be the exact raw
|
|
376
|
-
* request bytes (use express.raw / fastify rawBody) — a re-serialized JSON body
|
|
377
|
-
* will not match the signature.
|
|
378
|
-
*/
|
|
379
|
-
declare function verifyWebhook(rawBody: string | Buffer, signatureHeader: string | string[] | undefined, secret: string, opts?: {
|
|
380
|
-
toleranceSeconds?: number;
|
|
381
|
-
}): WebhookEvent;
|
|
382
|
-
|
|
383
144
|
/**
|
|
384
145
|
* Money math — exact, integer-only, in USDC micro-units (6 decimals).
|
|
385
146
|
*
|
|
@@ -435,4 +196,4 @@ declare function ulid(seedTime?: number): string;
|
|
|
435
196
|
/** `${prefix}_${ulid()}` — e.g. `pay_01J…`, `entry_01J…`, `idem_01J…`. */
|
|
436
197
|
declare function prefixedId(prefix: string): string;
|
|
437
198
|
|
|
438
|
-
export {
|
|
199
|
+
export { CHAIN_ID, DEFAULT_API_BASE_URL, EnterRoundInput, MICRO_PER_USDC, Network, PayInput, Payment, Playmos, PlaymosConfig, USDC_ADDRESS, USDC_DECIMALS, VerifyResult, WebhookEvent, computeIapSplit, computePoolSplit, formatMicroToUsd, parseUsdToMicro, prefixedId, previewIapSplit, previewPoolSplit, ulid };
|