@moonbeam-foundation/sdk 0.12.0 → 0.13.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.
Files changed (155) hide show
  1. package/README.md +79 -18
  2. package/bin/moonbeam.mjs +4 -1
  3. package/dist/actors/track-record.d.ts +1 -1
  4. package/dist/actors/track-record.js +1 -1
  5. package/dist/arbitration/index.d.ts +10 -4
  6. package/dist/arbitration/index.d.ts.map +1 -1
  7. package/dist/arbitration/index.js +14 -2
  8. package/dist/arbitration/index.js.map +1 -1
  9. package/dist/assurance/assurance-shared.d.ts +85 -132
  10. package/dist/assurance/assurance-shared.js +46 -90
  11. package/dist/core/keyed.d.ts +17 -0
  12. package/dist/core/keyed.d.ts.map +1 -0
  13. package/dist/core/keyed.js +36 -0
  14. package/dist/core/keyed.js.map +1 -0
  15. package/dist/cover/index.d.ts +3 -3
  16. package/dist/cover/index.d.ts.map +1 -1
  17. package/dist/cover/index.js +2 -1
  18. package/dist/cover/index.js.map +1 -1
  19. package/dist/devnet/index.d.ts +3 -3
  20. package/dist/devnet/index.d.ts.map +1 -1
  21. package/dist/devnet/index.js +7 -6
  22. package/dist/devnet/index.js.map +1 -1
  23. package/dist/devnet/profile.d.ts +1 -1
  24. package/dist/devnet/profile.d.ts.map +1 -1
  25. package/dist/devnet/profile.js +3 -2
  26. package/dist/devnet/profile.js.map +1 -1
  27. package/dist/economy/index.d.ts +264 -0
  28. package/dist/economy/index.d.ts.map +1 -0
  29. package/dist/economy/index.js +376 -0
  30. package/dist/economy/index.js.map +1 -0
  31. package/dist/erc8183/index.d.ts +1 -1
  32. package/dist/errors/index.d.ts +5 -5
  33. package/dist/errors/index.d.ts.map +1 -1
  34. package/dist/errors/index.js +3 -3
  35. package/dist/jobs/index.d.ts +4 -4
  36. package/dist/jobs/index.d.ts.map +1 -1
  37. package/dist/jobs/index.js +3 -2
  38. package/dist/jobs/index.js.map +1 -1
  39. package/dist/market/cohorts.d.ts +112 -0
  40. package/dist/market/cohorts.d.ts.map +1 -0
  41. package/dist/market/cohorts.js +72 -0
  42. package/dist/market/cohorts.js.map +1 -0
  43. package/dist/market/http.d.ts.map +1 -1
  44. package/dist/market/http.js +2 -1
  45. package/dist/market/http.js.map +1 -1
  46. package/dist/market/index.d.ts +27 -17
  47. package/dist/market/index.d.ts.map +1 -1
  48. package/dist/market/index.js +16 -9
  49. package/dist/market/index.js.map +1 -1
  50. package/dist/market/journey.d.ts +7 -7
  51. package/dist/market/journey.d.ts.map +1 -1
  52. package/dist/market/journey.js +10 -9
  53. package/dist/market/journey.js.map +1 -1
  54. package/dist/market/listed.d.ts +228 -0
  55. package/dist/market/listed.d.ts.map +1 -0
  56. package/dist/market/listed.js +169 -0
  57. package/dist/market/listed.js.map +1 -0
  58. package/dist/market/reads.d.ts +124 -0
  59. package/dist/market/reads.d.ts.map +1 -0
  60. package/dist/market/reads.js +99 -0
  61. package/dist/market/reads.js.map +1 -0
  62. package/dist/market/sale-stops.d.ts +2 -2
  63. package/dist/market/sale-stops.d.ts.map +1 -1
  64. package/dist/market/states-data.d.ts +491 -0
  65. package/dist/market/states-data.d.ts.map +1 -0
  66. package/dist/market/states-data.js +4 -0
  67. package/dist/market/states-data.js.map +1 -0
  68. package/dist/market/states.d.ts +40 -0
  69. package/dist/market/states.d.ts.map +1 -0
  70. package/dist/market/states.js +36 -0
  71. package/dist/market/states.js.map +1 -0
  72. package/dist/market/venues-data.d.ts.map +1 -1
  73. package/dist/market/venues-data.js +808 -40
  74. package/dist/market/venues-data.js.map +1 -1
  75. package/dist/market/venues.d.ts +50 -5
  76. package/dist/market/venues.d.ts.map +1 -1
  77. package/dist/market/venues.js +23 -7
  78. package/dist/market/venues.js.map +1 -1
  79. package/dist/onboard/index.d.ts +215 -33
  80. package/dist/onboard/index.d.ts.map +1 -1
  81. package/dist/onboard/index.js +344 -34
  82. package/dist/onboard/index.js.map +1 -1
  83. package/dist/onboard/send.d.ts +43 -0
  84. package/dist/onboard/send.d.ts.map +1 -0
  85. package/dist/onboard/send.js +65 -0
  86. package/dist/onboard/send.js.map +1 -0
  87. package/dist/playground/cases.d.ts +72 -0
  88. package/dist/playground/cases.d.ts.map +1 -0
  89. package/dist/playground/cases.js +115 -0
  90. package/dist/playground/cases.js.map +1 -0
  91. package/dist/playground/doc.d.ts +2 -0
  92. package/dist/playground/doc.d.ts.map +1 -0
  93. package/dist/playground/doc.js +52 -0
  94. package/dist/playground/doc.js.map +1 -0
  95. package/dist/playground/index.d.ts +172 -0
  96. package/dist/playground/index.d.ts.map +1 -0
  97. package/dist/playground/index.js +246 -0
  98. package/dist/playground/index.js.map +1 -0
  99. package/dist/playground/nets.d.ts +79 -0
  100. package/dist/playground/nets.d.ts.map +1 -0
  101. package/dist/playground/nets.js +147 -0
  102. package/dist/playground/nets.js.map +1 -0
  103. package/dist/playground/ports.d.ts +93 -0
  104. package/dist/playground/ports.d.ts.map +1 -0
  105. package/dist/playground/ports.js +72 -0
  106. package/dist/playground/ports.js.map +1 -0
  107. package/dist/playground/stream.d.ts +106 -0
  108. package/dist/playground/stream.d.ts.map +1 -0
  109. package/dist/playground/stream.js +269 -0
  110. package/dist/playground/stream.js.map +1 -0
  111. package/dist/pools/index.d.ts +18 -7
  112. package/dist/pools/index.d.ts.map +1 -1
  113. package/dist/pools/index.js +31 -9
  114. package/dist/pools/index.js.map +1 -1
  115. package/dist/proof/index.d.ts +5 -5
  116. package/dist/proof/index.d.ts.map +1 -1
  117. package/dist/proof/index.js +3 -2
  118. package/dist/proof/index.js.map +1 -1
  119. package/dist/resale/index.d.ts +13 -13
  120. package/dist/resale/index.d.ts.map +1 -1
  121. package/dist/resale/index.js +20 -19
  122. package/dist/resale/index.js.map +1 -1
  123. package/dist/resale/payment-scheme.d.mts +2 -5
  124. package/dist/resale/payment-scheme.mjs +16 -116
  125. package/dist/resale/payment-scheme.pin.json +1 -2
  126. package/dist/resale/settle-rule.d.ts +3 -3
  127. package/dist/resale/settle-rule.d.ts.map +1 -1
  128. package/dist/resale/settle-rule.js +3 -3
  129. package/dist/resale/settle-rule.js.map +1 -1
  130. package/dist/rpc/index.js +1 -1
  131. package/dist/workflows/index.js +1 -1
  132. package/dist/workflows/steps.d.ts +4 -4
  133. package/dist/workflows/steps.d.ts.map +1 -1
  134. package/dist/workflows/steps.js +4 -4
  135. package/dist/workflows/steps.js.map +1 -1
  136. package/dist/workflows/types.d.ts +1 -1
  137. package/dist/x402/index.d.ts +2 -2
  138. package/dist/x402/index.d.ts.map +1 -1
  139. package/dist/x402/index.js +5 -4
  140. package/dist/x402/index.js.map +1 -1
  141. package/docs/PATHS.md +96 -0
  142. package/docs/REFERENCE.md +52 -19
  143. package/docs/VENUES.md +85 -36
  144. package/docs/WORKFLOWS.md +3 -3
  145. package/docs/io-coverage.md +206 -0
  146. package/docs/playground.md +220 -0
  147. package/examples/24-resell-on-base.mjs +1 -1
  148. package/examples/50-x402-pay-a-wall.mjs +1 -1
  149. package/examples/51-read-a-proof.mjs +2 -2
  150. package/examples/README.md +1 -1
  151. package/examples/data/cross-list.recorded.json +1 -1
  152. package/examples/data/x402-wall-402.json +6 -6
  153. package/package.json +28 -4
  154. package/dist/assurance/assurance-shared.d.ts.map +0 -1
  155. package/dist/assurance/assurance-shared.js.map +0 -1
@@ -0,0 +1,147 @@
1
+ /**
2
+ * The one switch of the playground: the devnet (chain 36927) and Base (chain 8453), side by side in one frozen table (`NETS`).
3
+ *
4
+ * A cover case is one plan with the same steps on both networks (./cases). What differs per network is only what this table
5
+ * holds: the chain id, the token, the windows, and who signs each role. The table holds no address: the contracts a plan calls
6
+ * come in a `Placement` the caller passes (`checkPlacement`), checksummed, for the network's own chain.
7
+ *
8
+ * Signer refs name WHO signs, never a key:
9
+ * wallet:test a devnet-only wallet the playground makes for one run (never a managed key)
10
+ * wallet:user the user's own wallet, on Base
11
+ * coord:<p> a sign request on the coord pipe for purpose <p> (Moonbeam signs it there; the SDK never holds the key)
12
+ * null no purpose exists for the role on this network yet: every case that needs it is refused (`gapsOf`)
13
+ */
14
+ import { ECONOMY_ROLES } from '../economy/index.js';
15
+ import { keccak256 } from '../onboard/index.js';
16
+ import { CASE_IDS, CASES, rolesOf, stepsOf } from './cases.js';
17
+ export const NET_IDS = Object.freeze(['devnet', 'base']);
18
+ export const SIGNER_ROLES = Object.freeze([...ECONOMY_ROLES, 'payout']);
19
+ const deepFreeze = (o) => {
20
+ for (const v of Object.values(o))
21
+ if (v && typeof v === 'object' && !Object.isFrozen(v))
22
+ deepFreeze(v);
23
+ return Object.freeze(o);
24
+ };
25
+ /** The one switch. */
26
+ export const NETS = deepFreeze({
27
+ devnet: {
28
+ id: 'devnet', name: 'Moonbeam devnet', chainId: 36927,
29
+ token: { symbol: 'dUSDC', decimals: 6 },
30
+ windows: { reviewS: 60, disputeS: 60, arbitrationS: 120 },
31
+ signers: {
32
+ buyer: 'wallet:test', seller: 'wallet:test', backer: 'wallet:test',
33
+ evaluator: 'coord:devnet.evaluate', arbitrator: 'coord:devnet.arbitrate', keeper: 'coord:devnet.keeper', payout: 'coord:devnet.payout',
34
+ },
35
+ },
36
+ base: {
37
+ id: 'base', name: 'Base', chainId: 8453,
38
+ token: { symbol: 'USDC', decimals: 6 },
39
+ windows: { reviewS: null, disputeS: null, arbitrationS: null },
40
+ signers: {
41
+ buyer: 'wallet:user', seller: 'wallet:user', backer: 'wallet:user',
42
+ // no coord sign purpose exists for these two on Base yet: the table says so, and every case needing them is refused
43
+ evaluator: null, arbitrator: null,
44
+ keeper: 'coord:keeper.end', payout: 'coord:payout.seller',
45
+ },
46
+ },
47
+ });
48
+ export function netOf(net) {
49
+ if (typeof net !== 'string')
50
+ return net;
51
+ const n = NETS[net];
52
+ if (!n)
53
+ throw new RangeError(`not a net: ${String(net)} (one of ${NET_IDS.join(', ')})`);
54
+ return n;
55
+ }
56
+ /** The roles a net has no signer for, and the built cases each one blocks. */
57
+ export function gapsOf(net, signers = netOf(net).signers) {
58
+ const gaps = [];
59
+ for (const role of SIGNER_ROLES) {
60
+ if (signers[role] !== null)
61
+ continue;
62
+ const blocks = [];
63
+ for (const id of CASE_IDS) {
64
+ const c = CASES[id];
65
+ if (c.status !== 'planned')
66
+ continue;
67
+ if (c.vias) {
68
+ for (const via of c.vias)
69
+ if (rolesOf(id, via).includes(role))
70
+ blocks.push({ case: id, via });
71
+ }
72
+ else if (rolesOf(id).includes(role))
73
+ blocks.push({ case: id });
74
+ }
75
+ gaps.push({ role, blocks });
76
+ }
77
+ return gaps;
78
+ }
79
+ export class PlacementError extends TypeError {
80
+ name = 'PlacementError';
81
+ }
82
+ const HEX40 = /^0x[0-9a-fA-F]{40}$/;
83
+ /** The EIP-55 checksummed spelling of an address. */
84
+ export function toChecksum(a) {
85
+ if (!HEX40.test(a))
86
+ throw new PlacementError(`not an address: ${String(a)}`);
87
+ const lower = a.slice(2).toLowerCase();
88
+ const h = keccak256(new TextEncoder().encode(lower));
89
+ let out = '0x';
90
+ for (let i = 0; i < 40; i++) {
91
+ const nibble = (h[i >> 1] >> (i % 2 === 0 ? 4 : 0)) & 0xf;
92
+ out += nibble >= 8 ? lower[i].toUpperCase() : lower[i];
93
+ }
94
+ return out;
95
+ }
96
+ /** True for an address written in its EIP-55 checksummed form (an all-lowercase or all-uppercase spelling is refused). */
97
+ export function isChecksumAddress(v) {
98
+ return typeof v === 'string' && HEX40.test(v) && toChecksum(v) === v;
99
+ }
100
+ const ZERO = '0x0000000000000000000000000000000000000000';
101
+ const PLACED = ['hook', 'token', 'judgeAdapter', 'pool', 'vault'];
102
+ /** Check a placement for a net: its chain is the net's, every address is checksummed and none is zero. Returns it frozen. */
103
+ export function checkPlacement(net, p) {
104
+ const n = netOf(net);
105
+ if (!p || typeof p !== 'object')
106
+ throw new PlacementError('a placement is required: { chainId, hook, token, judgeAdapter, pool, vault }');
107
+ if (p.chainId !== n.chainId)
108
+ throw new PlacementError(`refused: the placement is for chain ${String(p.chainId)}, but ${n.id} is chain ${n.chainId}`);
109
+ for (const k of PLACED) {
110
+ if (!isChecksumAddress(p[k]))
111
+ throw new PlacementError(`placement.${k} is not a checksummed address: ${String(p[k])}`);
112
+ if (p[k] === ZERO)
113
+ throw new PlacementError(`placement.${k} is the zero address`);
114
+ }
115
+ if (p.arbiter !== undefined && p.arbiter !== null && !isChecksumAddress(p.arbiter))
116
+ throw new PlacementError(`placement.arbiter is not a checksummed address: ${String(p.arbiter)}`);
117
+ for (const [k, v] of Object.entries(p.windows ?? {}))
118
+ if (!Number.isInteger(v) || v <= 0)
119
+ throw new PlacementError(`placement.windows.${k} must be whole seconds above 0`);
120
+ return Object.freeze({ ...p, ...(p.windows ? { windows: Object.freeze({ ...p.windows }) } : {}) });
121
+ }
122
+ /** The windows a plan on this net waits on: the table's, or (where it has none) the placement's, read from the hook. */
123
+ export function windowsOf(net, p) {
124
+ const n = netOf(net);
125
+ const out = {};
126
+ for (const k of ['reviewS', 'disputeS', 'arbitrationS']) {
127
+ const fromTable = n.windows[k], fromHook = p.windows?.[k];
128
+ if (fromTable !== null && fromHook !== undefined && fromHook !== fromTable)
129
+ throw new PlacementError(`placement.windows.${k} is ${fromHook}, but ${n.id} fixes it at ${fromTable}`);
130
+ const v = fromTable ?? fromHook;
131
+ if (v === undefined)
132
+ throw new PlacementError(`${n.id} reads ${k} from the hook: pass it in placement.windows`);
133
+ out[k] = v;
134
+ }
135
+ return out;
136
+ }
137
+ /** How a case stands on a net: planned, refused (a role with no signer), or not built. Without a via, `rejected` is refused
138
+ * when any of its vias is. */
139
+ export function statusOn(net, caseId, via) {
140
+ const def = CASES[caseId];
141
+ if (def.status === 'not_built')
142
+ return 'not_built';
143
+ const n = netOf(net);
144
+ const vias = def.vias ? (via ? [via] : def.vias) : [undefined];
145
+ return vias.some((v) => stepsOf(caseId, v).some((s) => n.signers[s.role] === null)) ? 'refused' : 'planned';
146
+ }
147
+ //# sourceMappingURL=nets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nets.js","sourceRoot":"","sources":["../../src/playground/nets.ts"],"names":[],"mappings":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,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9G,CAAC"}
@@ -0,0 +1,93 @@
1
+ import type { Hex } from '../onboard/index.js';
2
+ import type { LightId, Wait } from './cases.js';
3
+ import type { Plan, PlanStep, Parties } from './index.js';
4
+ /** An acknowledgement on the coord pipe: of a sign request (`signed`), or of a stage the sale run reached. `tx`: the
5
+ * transaction the stage rests on (for `paid`, the transfer to the seller). */
6
+ export interface Ack {
7
+ id: string;
8
+ stage: LightId | 'signed';
9
+ tx?: Hex;
10
+ }
11
+ /** One event a transaction emitted. */
12
+ export interface ChainEvent {
13
+ name: string;
14
+ args?: Readonly<Record<string, unknown>>;
15
+ }
16
+ /** What a step waits for: a window after the previous transaction, or a point in chain time (the deadline). */
17
+ export interface WaitFor {
18
+ window: Wait;
19
+ seconds?: number;
20
+ at?: number;
21
+ after: Hex | null;
22
+ }
23
+ export interface WalletPort {
24
+ /** the run's parties: on the devnet, wallets made for this run only */
25
+ parties?(): Promise<Parties>;
26
+ sign(step: PlanStep): Promise<{
27
+ tx: Hex | null;
28
+ }>;
29
+ }
30
+ /**
31
+ * How the coord stream answered one sign request. Absent means `signed` when a transaction came back (the fakes leave it out).
32
+ * signed the purpose is armed and released a signature; `tx` is the transaction that went out
33
+ * shadow the purpose is in shadow: the signer answers what it WOULD sign (`would`) and signs nothing, so no transaction
34
+ * refused the purpose or a rule refused it (`reason` carries the signer's code and words)
35
+ * not_routable no route to the signer for this request on this port (`reason` says what is missing)
36
+ * no_answer the request went out and no result came back within the port's reads
37
+ */
38
+ export type SignStatus = 'signed' | 'shadow' | 'refused' | 'not_routable' | 'no_answer';
39
+ export interface SignAnswer {
40
+ tx: Hex | null;
41
+ ack: Ack | null;
42
+ status?: SignStatus;
43
+ reason?: string;
44
+ would?: unknown;
45
+ }
46
+ export interface StreamPort {
47
+ sign(step: PlanStep): Promise<SignAnswer>;
48
+ settle(plan: Plan, steps: readonly RunStepResult[]): Promise<{
49
+ acks: readonly Ack[];
50
+ } | null>;
51
+ }
52
+ export interface ChainPort {
53
+ event(tx: Hex): Promise<readonly ChainEvent[]>;
54
+ waitUntil(w: WaitFor): Promise<void>;
55
+ }
56
+ export interface Ports {
57
+ wallet: WalletPort;
58
+ stream: StreamPort;
59
+ chain: ChainPort;
60
+ }
61
+ /** A step as it ran. */
62
+ export interface RunStepResult extends PlanStep {
63
+ tx: Hex | null;
64
+ ack: Ack | null;
65
+ events: readonly ChainEvent[];
66
+ ok: boolean;
67
+ /** a Moonbeam step's answer on the stream when it was not a plain signature; `skipped`: a user step not sent after a step that
68
+ * only would sign (its chain state never came to be) */
69
+ sign?: {
70
+ status: SignStatus | 'skipped';
71
+ reason?: string;
72
+ would?: unknown;
73
+ };
74
+ }
75
+ export interface FakeOptions {
76
+ /** stages the fake sale run does not ack */
77
+ withhold?: readonly LightId[];
78
+ /** a step fn the fake signers return no transaction for */
79
+ noTxFor?: string;
80
+ /** the run's parties (default: three made-up addresses) */
81
+ parties?: Parties;
82
+ }
83
+ export interface FakePorts extends Ports {
84
+ /** every port call, in order */
85
+ log: string[];
86
+ /** the fake chain's clock, advanced by waitUntil only */
87
+ clock: {
88
+ now: number;
89
+ };
90
+ }
91
+ /** In-memory ports: each signed step gets a transaction whose events are the ones the plan expects of it. */
92
+ export declare function fakePorts(o?: FakeOptions): FakePorts;
93
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/playground/ports.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAW,GAAG,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1D;+EAC+E;AAC/E,MAAM,WAAW,GAAG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ground run goes through, and in-memory fakes of them (`fakePorts`). No live port ships here: a run on a
3
+ * network needs the coord pipe's sign purposes of that network armed first.
4
+ *
5
+ * wallet signs the `wallet:*` steps (the buyer's, the seller's, the backer's) and names the run's parties
6
+ * stream the coord pipe: `sign(step)` is a sign request for a `coord:*` step, answered with { tx, ack };
7
+ * `settle(plan, steps)` hands the run to the sale run, which acks each stage it reached
8
+ * chain `event(tx)` reads a transaction's events; `waitUntil(window)` resolves once chain time passed it (never a sleep)
9
+ */
10
+ import { keccakHex } from '../onboard/index.js';
11
+ const FAKE_PARTIES = Object.freeze({
12
+ buyer: '0x00000000000000000000000000000000000000B1',
13
+ seller: '0x00000000000000000000000000000000000000b2',
14
+ backer: '0x00000000000000000000000000000000000000B3',
15
+ });
16
+ /** In-memory ports: each signed step gets a transaction whose events are the ones the plan expects of it. */
17
+ export function fakePorts(o = {}) {
18
+ const log = [];
19
+ const clock = { now: 1_800_000_000 };
20
+ const byTx = new Map();
21
+ let n = 0;
22
+ const txOf = (step) => {
23
+ if (o.noTxFor !== undefined && step.fn === o.noTxFor)
24
+ return null;
25
+ const tx = keccakHex(new TextEncoder().encode(`fake-tx:${++n}:${step.fn}`));
26
+ byTx.set(tx, step);
27
+ return tx;
28
+ };
29
+ const parties = o.parties ?? FAKE_PARTIES;
30
+ return {
31
+ log, clock,
32
+ wallet: {
33
+ parties: async () => { log.push('wallet.parties'); return parties; },
34
+ sign: async (step) => { log.push(`wallet.sign ${step.fn}`); return { tx: txOf(step) }; },
35
+ },
36
+ stream: {
37
+ sign: async (step) => {
38
+ log.push(`stream.sign ${step.fn} ${step.signer}`);
39
+ const tx = txOf(step);
40
+ return { tx, ack: tx ? { id: `ack:${n}`, stage: 'signed' } : null };
41
+ },
42
+ settle: async (plan, steps) => {
43
+ log.push('stream.settle');
44
+ const ending = steps.find((s) => s.ends && s.tx);
45
+ const acks = [];
46
+ for (const l of plan.lights) {
47
+ if (!l.expected || o.withhold?.includes(l.light))
48
+ continue;
49
+ acks.push({ id: `ack:${l.light}`, stage: l.light, ...(l.light === 'paid' && ending?.tx ? { tx: ending.tx } : {}) });
50
+ }
51
+ return { acks };
52
+ },
53
+ },
54
+ chain: {
55
+ event: async (tx) => {
56
+ log.push('chain.event');
57
+ const step = byTx.get(tx);
58
+ if (!step)
59
+ return [];
60
+ const ev = step.expects.events.map((name) => ({ name, ...(name === 'JobOpened' && step.expects.opens ? { args: { seller: step.expects.opens.seller } } : {}) }));
61
+ for (const t of step.expects.transfers ?? [])
62
+ ev.push({ name: 'Transfer', args: { to: t.to, value: t.units } });
63
+ return ev;
64
+ },
65
+ waitUntil: async (w) => {
66
+ log.push(`chain.waitUntil ${w.window}`);
67
+ clock.now = w.at !== undefined ? Math.max(clock.now, w.at + 1) : clock.now + (w.seconds ?? 0) + 1;
68
+ },
69
+ },
70
+ };
71
+ }
72
+ //# sourceMappingURL=ports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.js","sourceRoot":"","sources":["../../src/playground/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAgEhD,MAAM,YAAY,GAAY,MAAM,CAAC,MAAM,CAAC;IAC1C,KAAK,EAAE,4CAAuD;IAC9D,MAAM,EAAE,4CAAuD;IAC/D,MAAM,EAAE,4CAAuD;CAChE,CAAC,CAAC;AAEH,6GAA6G;AAC7G,MAAM,UAAU,SAAS,CAAC,CAAC,GAAgB,EAAE;IAC3C,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAiB,CAAC;IACtC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,MAAM,IAAI,GAAG,CAAC,IAAc,EAAc,EAAE;QAC1C,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS,IAAI,IAAI,CAAC,EAAE,KAAK,CAAC,CA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EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC/K,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE;oBAAE,EAAE,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBAChH,OAAO,EAAE,CAAC;YACZ,CAAC;YACD,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;gBACrB,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;gBACxC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACpG,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,106 @@
1
+ import type { Hex, OnboardTransport } from '../onboard/index.js';
2
+ import type { PlanStep } from './index.js';
3
+ import type { ChainPort, StreamPort } from './ports.js';
4
+ /** The devnet and Base chain ids a playground runs on. */
5
+ export declare const STREAM_CHAINS: Readonly<{
6
+ readonly devnet: 36927;
7
+ readonly base: 8453;
8
+ }>;
9
+ export declare const PIPE_ENVELOPE_SCHEMA = "taifoon.pipe.envelope.v1";
10
+ export declare const SIGN_REQUEST_SCHEMA = "taifoon.sign.request.v1";
11
+ export declare const SIGN_RESULT_SCHEMA = "taifoon.sign.result.v1";
12
+ /** the signer's own inbox: a request goes `to: { agent: SIGNER_INBOX }` (sign.cue deploy.inbox) */
13
+ export declare const SIGNER_INBOX = "coord-sign";
14
+ /** A refusal that stops the run: a 401 (a key is needed), 402 (payment is needed) or 429 (rate limited). Never retried. */
15
+ export declare class StreamRefused extends Error {
16
+ readonly status: 401 | 402 | 429;
17
+ readonly route: string;
18
+ readonly body: unknown;
19
+ name: string;
20
+ constructor(status: 401 | 402 | 429, route: string, body: unknown);
21
+ }
22
+ /** The purpose a `coord:<purpose>` signer names, or null for any other signer. */
23
+ export declare const purposeOf: (signer: string) => string | null;
24
+ /**
25
+ * Why a purpose may not sign on a chain, or null when it may. A `devnet.*` purpose signs on the devnet (36927) only; every other
26
+ * purpose never signs there. A test ref (`coord:test.*`) is never a purpose of the signer; a chain other than the two is refused.
27
+ */
28
+ export declare function purposeNetRefusal(purpose: string, chainId: number): string | null;
29
+ /** A purpose as the signer's status read names it (GET /v1/sign/status → purposes[]). */
30
+ export interface SignerPurpose {
31
+ id: string;
32
+ mode: string;
33
+ key: string;
34
+ vault: string;
35
+ }
36
+ /** The request a requester signs: coord lang/cue/sign.cue `sign.request.fields`. */
37
+ export interface SignRequestBody {
38
+ schema: typeof SIGN_REQUEST_SCHEMA;
39
+ purpose: string;
40
+ requester: string;
41
+ vault: string;
42
+ key: string;
43
+ /** the purpose's arguments: the call the plan built (the signer rebuilds what it signs from its register and these) */
44
+ request: {
45
+ chain: number;
46
+ to: string;
47
+ fn: string;
48
+ data: string;
49
+ value: string;
50
+ };
51
+ evidence: null;
52
+ nonce: string;
53
+ at: string;
54
+ ttl_s: number;
55
+ }
56
+ /** The text a request key signs: the request schema, a newline, the exact payload. */
57
+ export declare const signedText: (payload: string) => string;
58
+ /** One sign request as a pipe envelope (coord lang/cue/api-bodies.cue PipeEnvelope; sign.cue `sign.request`). Pure. */
59
+ export declare function signEnvelope(body: SignRequestBody, sig: string, createdAt: string): Record<string, unknown>;
60
+ /** The terms of one sale's unsigned plan (POST /v1/settle: kind, chainId, buyer, seller, price, evidence, ref, deadline). */
61
+ export interface SaleTerms {
62
+ chainId: number;
63
+ buyer: string;
64
+ seller: string;
65
+ price: bigint;
66
+ evidence: Hex;
67
+ refId: string;
68
+ deadline?: number;
69
+ /** settle through Moonbeam's own judge adapter (the planner's `via: "us"`) */
70
+ viaUs?: boolean;
71
+ }
72
+ /** The body of POST /v1/settle. Pure. */
73
+ export declare function settleBody(t: SaleTerms): Record<string, unknown>;
74
+ export interface CoordStreamOptions {
75
+ /** the requester id the signer's register names; never a key */
76
+ requester: string;
77
+ /** the chain the chain reads go to (default: the devnet) */
78
+ chainId?: number;
79
+ /** the requester's Ed25519 signature (base64) over `signedText(payload)`, made wherever the request key lives. Without it, no sign
80
+ * request can be sent and every one answers not_routable */
81
+ seal?: (text: string) => Promise<string>;
82
+ /** sends a released signature to the chain and returns its tx hash. Without it, a released signature has no transaction */
83
+ send?: (a: {
84
+ signature: string;
85
+ step: PlanStep;
86
+ }) => Promise<Hex>;
87
+ /** inbox long-polls per request (each up to 25 s on the server, never a sleep here); default 3 */
88
+ polls?: number;
89
+ /** clock and nonce (tests) */
90
+ now?: () => number;
91
+ nonce?: () => string;
92
+ }
93
+ export interface CoordStream extends StreamPort {
94
+ readonly requester: string;
95
+ /** the chain port's read: events only for a transaction coord proves; `waitUntil` needs a chain clock this port does not read */
96
+ readonly chain: ChainPort;
97
+ /** the unsigned plan of a sale (POST /v1/settle) */
98
+ planSale(t: SaleTerms): Promise<{
99
+ ok: boolean;
100
+ status: number;
101
+ body: unknown;
102
+ }>;
103
+ }
104
+ /** The coord stream port over a transport (see the module's header). */
105
+ export declare function coordStream(t: OnboardTransport, o: CoordStreamOptions): CoordStream;
106
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/playground/stream.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAQ,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD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