@aurora-is-near/intents-connect 7.20.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 +176 -0
- package/dist/api/createIntentsConnectApi.d.ts +31 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/types.d.ts +93 -0
- package/dist/chains.d.ts +27 -0
- package/dist/chunks/recovery-BBQaAcqE.js +1034 -0
- package/dist/chunks/recovery-BBQaAcqE.js.map +1 -0
- package/dist/errors.d.ts +94 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +197 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +7 -0
- package/dist/machine/context.d.ts +39 -0
- package/dist/machine/guards/checks/amountMustExceedFee.d.ts +2 -0
- package/dist/machine/guards/checks/destinationTokenIsTouched.d.ts +12 -0
- package/dist/machine/guards/checks/feeMustBeEstimated.d.ts +9 -0
- package/dist/machine/guards/checks/memoPresentForStellar.d.ts +6 -0
- package/dist/machine/guards/checks/mustBeSignedBeforeDeposit.d.ts +8 -0
- package/dist/machine/guards/checks/mustHaveSigningPayload.d.ts +7 -0
- package/dist/machine/guards/checks/noExecutionInFlight.d.ts +7 -0
- package/dist/machine/guards/checks/originNetworkMatches.d.ts +5 -0
- package/dist/machine/guards/checks/publicKeyMatchesStandard.d.ts +7 -0
- package/dist/machine/guards/checks/quoteMustNotHaveMoved.d.ts +8 -0
- package/dist/machine/guards/checks/recipientOnlyOnOutOperation.d.ts +11 -0
- package/dist/machine/guards/checks/round1MustBeStepless.d.ts +8 -0
- package/dist/machine/guards/checks/stepShapeIsLegal.d.ts +7 -0
- package/dist/machine/guards/checks/stepsRequiredForRealCreate.d.ts +6 -0
- package/dist/machine/guards/checks/strategiesAreExclusive.d.ts +17 -0
- package/dist/machine/guards/index.d.ts +19 -0
- package/dist/machine/index.d.ts +4 -0
- package/dist/machine/machine.d.ts +50 -0
- package/dist/machine/phases.d.ts +48 -0
- package/dist/react/IntentsConnectProvider.d.ts +12 -0
- package/dist/react/context.d.ts +12 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +149 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useExecution.d.ts +42 -0
- package/dist/recovery.d.ts +27 -0
- package/dist/runner/createExecutionRunner.d.ts +2 -0
- package/dist/runner/index.d.ts +2 -0
- package/dist/runner/types.d.ts +146 -0
- package/dist/signers/index.d.ts +2 -0
- package/dist/signers/intentsConnect.d.ts +43 -0
- package/dist/signers/standards/encoding.d.ts +15 -0
- package/dist/signers/standards/erc191.d.ts +18 -0
- package/dist/signers/standards/index.d.ts +12 -0
- package/dist/signers/standards/nep413.d.ts +22 -0
- package/dist/signers/standards/rawEd25519.d.ts +20 -0
- package/dist/signers/standards/sep53.d.ts +22 -0
- package/dist/types/execution.d.ts +133 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/providers.d.ts +63 -0
- package/dist/types/recipe.d.ts +38 -0
- package/dist/types/signing.d.ts +70 -0
- package/dist/types/transfer.d.ts +60 -0
- package/dist/types/wallet.d.ts +53 -0
- package/package.json +54 -0
- package/react/package.json +8 -0
- package/src/api/createIntentsConnectApi.test.ts +146 -0
- package/src/api/createIntentsConnectApi.ts +263 -0
- package/src/api/generated/conformance.ts +233 -0
- package/src/api/generated/openapi.ts +995 -0
- package/src/api/index.ts +17 -0
- package/src/api/types.ts +138 -0
- package/src/chains.ts +103 -0
- package/src/errors.ts +234 -0
- package/src/index.ts +73 -0
- package/src/logger.ts +21 -0
- package/src/machine/context.ts +56 -0
- package/src/machine/guards/checks/amountMustExceedFee.ts +14 -0
- package/src/machine/guards/checks/destinationTokenIsTouched.ts +31 -0
- package/src/machine/guards/checks/feeMustBeEstimated.ts +22 -0
- package/src/machine/guards/checks/memoPresentForStellar.ts +20 -0
- package/src/machine/guards/checks/mustBeSignedBeforeDeposit.ts +17 -0
- package/src/machine/guards/checks/mustHaveSigningPayload.ts +19 -0
- package/src/machine/guards/checks/noExecutionInFlight.ts +19 -0
- package/src/machine/guards/checks/originNetworkMatches.ts +23 -0
- package/src/machine/guards/checks/publicKeyMatchesStandard.ts +28 -0
- package/src/machine/guards/checks/quoteMustNotHaveMoved.ts +20 -0
- package/src/machine/guards/checks/recipientOnlyOnOutOperation.ts +23 -0
- package/src/machine/guards/checks/round1MustBeStepless.ts +17 -0
- package/src/machine/guards/checks/stepShapeIsLegal.ts +79 -0
- package/src/machine/guards/checks/stepsRequiredForRealCreate.ts +12 -0
- package/src/machine/guards/checks/strategiesAreExclusive.ts +35 -0
- package/src/machine/guards/guards.test.ts +317 -0
- package/src/machine/guards/index.ts +22 -0
- package/src/machine/index.ts +15 -0
- package/src/machine/machine.test.ts +131 -0
- package/src/machine/machine.ts +113 -0
- package/src/machine/phases.ts +81 -0
- package/src/react/IntentsConnectProvider.tsx +61 -0
- package/src/react/context.ts +34 -0
- package/src/react/index.ts +14 -0
- package/src/react/useExecution.test.tsx +281 -0
- package/src/react/useExecution.ts +246 -0
- package/src/recovery.test.ts +44 -0
- package/src/recovery.ts +45 -0
- package/src/runner/createExecutionRunner.test.ts +1388 -0
- package/src/runner/createExecutionRunner.ts +1156 -0
- package/src/runner/index.ts +9 -0
- package/src/runner/types.ts +148 -0
- package/src/signers/index.ts +7 -0
- package/src/signers/intentsConnect.ts +210 -0
- package/src/signers/signers.test.ts +415 -0
- package/src/signers/standards/encoding.ts +89 -0
- package/src/signers/standards/erc191.ts +61 -0
- package/src/signers/standards/index.ts +20 -0
- package/src/signers/standards/nep413.ts +84 -0
- package/src/signers/standards/rawEd25519.ts +46 -0
- package/src/signers/standards/sep53.ts +74 -0
- package/src/tests/setup.ts +4 -0
- package/src/types/execution.ts +177 -0
- package/src/types/index.ts +6 -0
- package/src/types/providers.ts +71 -0
- package/src/types/recipe.ts +41 -0
- package/src/types/signing.ts +99 -0
- package/src/types/transfer.ts +90 -0
- package/src/types/wallet.ts +60 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { I as x, a as v, b as N, d as O, f as C, m as M, c as R, e as $, n as D, o as B, p as K, q as L, r as U, g as F, s as H, h as j, i as G, j as k, k as q, l as J, t as Y, u as z, v as V, w as X, x as W, y as Q, z as Z, A as ee, B as te, C as se, D as ae, E as re, F as oe } from "./chunks/recovery-BBQaAcqE.js";
|
|
2
|
+
import { a7 as he, W as Te, a9 as ge, Q as ye, O as fe, X as Ae, Y as Ie, Z as xe, a3 as Pe, a5 as _e, a4 as be, P as we, _ as ve, a6 as Ne, a8 as Oe, T as Ce, a2 as Me, H as Re, G as $e, J as De, a0 as Be, V as Ke, $ as Le, R as Ue, S as Fe, aa as He, K as je, L as Ge, a1 as ke, U as qe, M as Je, N as Ye } from "./chunks/recovery-BBQaAcqE.js";
|
|
3
|
+
const pe = (s) => {
|
|
4
|
+
const a = s.amountAtomic ?? s.amount;
|
|
5
|
+
if (a === void 0 || a === "")
|
|
6
|
+
throw new Error("No amount to transfer: set amountAtomic");
|
|
7
|
+
const o = BigInt(a);
|
|
8
|
+
if (o <= 0n)
|
|
9
|
+
throw new Error(`Transfer amount must be positive, got ${a}`);
|
|
10
|
+
return o;
|
|
11
|
+
}, ne = 3e4, ie = (s) => s && typeof s == "object" && "result" in s ? s.result : s, P = 200, ce = (s, a, o) => {
|
|
12
|
+
if (s && typeof s == "object" && "error" in s) {
|
|
13
|
+
const { error: l } = s;
|
|
14
|
+
if (typeof l == "string")
|
|
15
|
+
return l;
|
|
16
|
+
}
|
|
17
|
+
const c = o.trim().slice(0, P);
|
|
18
|
+
return c ? `Intents Connect API responded ${a}: ${c}` : `Intents Connect API responded ${a}`;
|
|
19
|
+
}, de = (s) => {
|
|
20
|
+
const {
|
|
21
|
+
baseUrl: a,
|
|
22
|
+
apiKey: o,
|
|
23
|
+
apiKeyProxyUrl: c,
|
|
24
|
+
fetch: l,
|
|
25
|
+
timeout: g = ne
|
|
26
|
+
} = s, _ = l ?? ((e, t) => globalThis.fetch(e, t)), r = async (e) => {
|
|
27
|
+
const { path: t, method: i = "GET", query: b, body: y, withApiKey: f = !1 } = e, m = f && c ? c : a, A = new URL(t, m.endsWith("/") ? m : `${m}/`);
|
|
28
|
+
Object.entries(b ?? {}).forEach(([S, T]) => {
|
|
29
|
+
T !== void 0 && T !== "" && A.searchParams.set(S, T);
|
|
30
|
+
});
|
|
31
|
+
const I = {
|
|
32
|
+
"Content-Type": "application/json"
|
|
33
|
+
};
|
|
34
|
+
f && o && !c && (I["x-api-key"] = o);
|
|
35
|
+
const E = new AbortController(), w = setTimeout(() => E.abort(), g);
|
|
36
|
+
let p, u;
|
|
37
|
+
try {
|
|
38
|
+
p = await _(A.toString(), {
|
|
39
|
+
method: i,
|
|
40
|
+
headers: I,
|
|
41
|
+
body: y === void 0 ? void 0 : JSON.stringify(y),
|
|
42
|
+
signal: E.signal
|
|
43
|
+
}), u = await p.text();
|
|
44
|
+
} catch (S) {
|
|
45
|
+
throw E.signal.aborted ? new x(
|
|
46
|
+
`request to ${t} timed out after ${g}ms`,
|
|
47
|
+
{ cause: S }
|
|
48
|
+
) : S;
|
|
49
|
+
} finally {
|
|
50
|
+
clearTimeout(w);
|
|
51
|
+
}
|
|
52
|
+
let d, h = !0;
|
|
53
|
+
try {
|
|
54
|
+
d = u ? JSON.parse(u) : void 0;
|
|
55
|
+
} catch {
|
|
56
|
+
d = void 0, h = !1;
|
|
57
|
+
}
|
|
58
|
+
if (!p.ok)
|
|
59
|
+
throw new v(
|
|
60
|
+
ce(d, p.status, u),
|
|
61
|
+
p.status,
|
|
62
|
+
h ? d : u
|
|
63
|
+
);
|
|
64
|
+
if (!h)
|
|
65
|
+
throw new x(
|
|
66
|
+
`Intents Connect API returned a non-JSON body for ${t}: ${u.trim().slice(0, P)}`
|
|
67
|
+
);
|
|
68
|
+
return ie(d);
|
|
69
|
+
}, n = (e) => encodeURIComponent(e);
|
|
70
|
+
return {
|
|
71
|
+
getIntermediary: (e, t) => r({
|
|
72
|
+
path: `api/v1/executions/${n(e)}/intermediary`,
|
|
73
|
+
query: { publicKey: t?.publicKey }
|
|
74
|
+
}),
|
|
75
|
+
createExecution: (e, t) => r({
|
|
76
|
+
path: `api/v1/executions/${n(e)}`,
|
|
77
|
+
method: "POST",
|
|
78
|
+
body: t,
|
|
79
|
+
withApiKey: !0
|
|
80
|
+
}),
|
|
81
|
+
createStepsExecution: (e, t) => r({
|
|
82
|
+
path: `api/v1/executions/${n(e)}/steps`,
|
|
83
|
+
method: "POST",
|
|
84
|
+
body: t,
|
|
85
|
+
withApiKey: !0
|
|
86
|
+
}),
|
|
87
|
+
listSupportedTokens: (e) => r({
|
|
88
|
+
path: "api/v1/supported_tokens",
|
|
89
|
+
query: { flow: e }
|
|
90
|
+
}),
|
|
91
|
+
submitSignature: (e, t) => r({
|
|
92
|
+
path: `api/v1/executions/${n(e)}/submit`,
|
|
93
|
+
method: "POST",
|
|
94
|
+
body: t
|
|
95
|
+
}),
|
|
96
|
+
recordDeposit: async (e) => {
|
|
97
|
+
await r({
|
|
98
|
+
path: "api/v1/executions/deposit/submit",
|
|
99
|
+
method: "POST",
|
|
100
|
+
body: e
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
listExecutions: async (e, t) => {
|
|
104
|
+
const i = await r({
|
|
105
|
+
path: `api/v1/executions/${n(e)}`,
|
|
106
|
+
query: {
|
|
107
|
+
id: t?.id,
|
|
108
|
+
status: Array.isArray(t?.status) ? t.status.join(",") : t?.status
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return Array.isArray(i) ? i : [i].filter(Boolean);
|
|
112
|
+
},
|
|
113
|
+
deleteExecution: async (e, t, i) => {
|
|
114
|
+
await r({
|
|
115
|
+
path: `api/v1/executions/${n(e)}/${n(t)}`,
|
|
116
|
+
method: "DELETE",
|
|
117
|
+
body: i
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}, le = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
122
|
+
__proto__: null,
|
|
123
|
+
amountMustExceedFee: N,
|
|
124
|
+
destinationTokenIsTouched: O,
|
|
125
|
+
feeMustBeEstimated: C,
|
|
126
|
+
memoPresentForStellar: M,
|
|
127
|
+
mustBeSignedBeforeDeposit: R,
|
|
128
|
+
mustHaveSigningPayload: $,
|
|
129
|
+
noExecutionInFlight: D,
|
|
130
|
+
originNetworkMatches: B,
|
|
131
|
+
publicKeyMatchesStandard: K,
|
|
132
|
+
quoteMustNotHaveMoved: L,
|
|
133
|
+
recipientOnlyOnOutOperation: U,
|
|
134
|
+
round1MustBeStepless: F,
|
|
135
|
+
stepShapeIsLegal: H,
|
|
136
|
+
stepsRequiredForRealCreate: j,
|
|
137
|
+
stepsUsePlaceholder: G,
|
|
138
|
+
strategiesAreExclusive: k
|
|
139
|
+
}, Symbol.toStringTag, { value: "Module" })), Se = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
140
|
+
__proto__: null,
|
|
141
|
+
assertEd25519SignatureLength: q,
|
|
142
|
+
ed25519PublicKeyFromBase58: J,
|
|
143
|
+
ed25519PublicKeyFromBytes: Y,
|
|
144
|
+
ed25519Signature: z,
|
|
145
|
+
encodePublicKey: V,
|
|
146
|
+
fromBase64: X,
|
|
147
|
+
fromHex: W,
|
|
148
|
+
normaliseRecoveryByte: Q,
|
|
149
|
+
secp256k1Signature: Z,
|
|
150
|
+
signErc191: ee,
|
|
151
|
+
signNep413: te,
|
|
152
|
+
signRawEd25519: se,
|
|
153
|
+
signSep53: ae,
|
|
154
|
+
toBase58: re,
|
|
155
|
+
toBase64: oe
|
|
156
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
157
|
+
export {
|
|
158
|
+
he as BACKEND_PLACEHOLDERS,
|
|
159
|
+
Te as DepositTransferError,
|
|
160
|
+
ge as ED25519_STANDARDS,
|
|
161
|
+
ye as EVM_CHAINS,
|
|
162
|
+
fe as EVM_CHAIN_IDS,
|
|
163
|
+
Ae as ExecutionCancelledError,
|
|
164
|
+
Ie as ExecutionPollTimeoutError,
|
|
165
|
+
xe as GuardError,
|
|
166
|
+
Pe as IN_FLIGHT_STATUSES,
|
|
167
|
+
v as IntentsConnectApiError,
|
|
168
|
+
x as IntentsConnectError,
|
|
169
|
+
_e as MAX_FUNCTION_SIGNATURE_BYTES,
|
|
170
|
+
be as MAX_STEPS,
|
|
171
|
+
we as PHASE_TRANSITIONS,
|
|
172
|
+
ve as RunnerDisposedError,
|
|
173
|
+
Ne as STEP_KEYS,
|
|
174
|
+
Oe as SUPPORTED_SIGNING_STANDARDS,
|
|
175
|
+
Ce as TERMINAL_PHASES,
|
|
176
|
+
Me as TERMINAL_STATUSES,
|
|
177
|
+
Re as createExecutionMachine,
|
|
178
|
+
$e as createExecutionRunner,
|
|
179
|
+
De as createInitialContext,
|
|
180
|
+
de as createIntentsConnectApi,
|
|
181
|
+
Be as defaultLogger,
|
|
182
|
+
Ke as deriveExecutionRecovery,
|
|
183
|
+
Le as failGuard,
|
|
184
|
+
Ue as getChainFamily,
|
|
185
|
+
le as guards,
|
|
186
|
+
Fe as isEvmChain,
|
|
187
|
+
He as isSupportedSigningStandard,
|
|
188
|
+
je as isTerminalPhase,
|
|
189
|
+
Ge as moveTo,
|
|
190
|
+
ke as noopLogger,
|
|
191
|
+
qe as parseOriginAsset,
|
|
192
|
+
pe as resolveTransferAmount,
|
|
193
|
+
Je as signIntentsConnectPayload,
|
|
194
|
+
Ye as signIntentsConnectText,
|
|
195
|
+
Se as standards
|
|
196
|
+
};
|
|
197
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/types/transfer.ts","../src/api/createIntentsConnectApi.ts"],"sourcesContent":["import type { Chain } from '@/types/execution';\n\n/**\n * Deposit-transfer contract.\n *\n * A deliberate SUPERSET of `packages/intents-swap-widget/src/types/transfer.ts`:\n * the widget-specific fields are kept optional so `intents-swap-widget-evm` can\n * later delegate here instead of maintaining a fork of `makeTransfer` (notably\n * `makeVirtualChainTransfer`). Add fields; never remove them.\n */\nexport type MakeTransferArgs = {\n /**\n * ATOMIC amount, despite the name — a widget-compatibility alias where the\n * field already held an atomic value. Never pass a human-readable/decimal\n * string here. Ignored when `amountAtomic` is set; prefer `amountAtomic`.\n */\n amount?: string;\n /** Exact atomic amount. Preferred — avoids re-deriving from a display string. */\n amountAtomic?: string;\n decimals: number;\n /** Recipient — the 1Click deposit address for an Intents Connect deposit. */\n address: string;\n /** Absent means the chain's native gas asset. */\n tokenAddress?: string;\n chain: Chain;\n evmChainId?: number | null;\n isNativeEvmTokenTransfer?: boolean;\n /** Memo / destination tag. Required for Stellar. */\n memo?: string;\n\n // --- Widget-compatibility fields. Unused by Intents Connect deposits, kept\n // --- so the widget's callers remain expressible against this contract.\n sourceAssetId?: string;\n targetAssetId?: string;\n};\n\nexport type TransferResult = {\n hash: string;\n transactionLink?: string;\n};\n\n/**\n * Structurally compatible with the widget's network plugins, so a consumer who\n * already has `evm` / `sol` / `stellar` from the `intents-swap-widget-*`\n * packages can pass them straight in.\n */\nexport type MakeTransfer<TOptions = unknown> = (\n args: MakeTransferArgs,\n options: TOptions,\n) => Promise<Pick<TransferResult, 'hash'>>;\n\nexport type TransferPlugin<TOptions = unknown> = {\n makeTransfer: MakeTransfer<TOptions>;\n};\n\n/** Keyed the same way as the widget's `Plugins`. */\nexport type TransferPlugins = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n evm?: TransferPlugin<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n sol?: TransferPlugin<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stellar?: TransferPlugin<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n near?: TransferPlugin<any>;\n};\n\n/**\n * Resolves the atomic amount a transfer should move.\n *\n * `amountAtomic` is preferred and is what the runner always sets — it comes\n * straight from the quote, so it cannot drift from what the bridge expects.\n * `amount` is accepted for widget-plugin compatibility, where the field already\n * held an atomic value despite its name.\n */\nexport const resolveTransferAmount = (args: MakeTransferArgs): bigint => {\n const raw = args.amountAtomic ?? args.amount;\n\n if (raw === undefined || raw === '') {\n throw new Error('No amount to transfer: set amountAtomic');\n }\n\n const atomic = BigInt(raw);\n\n if (atomic <= 0n) {\n throw new Error(`Transfer amount must be positive, got ${raw}`);\n }\n\n return atomic;\n};\n","import { IntentsConnectApiError, IntentsConnectError } from '@/errors';\nimport type { Execution, Intermediary, SubmitStatus } from '@/types/execution';\nimport type { DeleteSignatureEnvelope } from '@/types/signing';\nimport type {\n CreateExecutionBody,\n CreateStepsExecutionBody,\n IntentsConnectApi,\n ListExecutionsQuery,\n RecordDepositBody,\n SubmitSignatureBody,\n SupportedTokensFlow,\n SupportedTokensResult,\n} from '@/api/types';\n\nexport type FetchLike = (\n input: string,\n init?: {\n method?: string;\n headers?: Record<string, string>;\n body?: string;\n signal?: AbortSignal;\n },\n) => Promise<{\n ok: boolean;\n status: number;\n text: () => Promise<string>;\n}>;\n\nexport type IntentsConnectApiOptions = {\n baseUrl: string;\n /**\n * Sent as `x-api-key` on create calls.\n *\n * Prefer `apiKeyProxyUrl` in a browser: the key prices per-key fees\n * server-side and should not ship in client code.\n */\n apiKey?: string;\n /**\n * Base URL of your own server that injects `x-api-key` and forwards to the\n * Intents Connect API. When set, create calls go here instead of `baseUrl`.\n */\n apiKeyProxyUrl?: string;\n /** Defaults to global `fetch`. */\n fetch?: FetchLike;\n /** Milliseconds. Defaults to 30_000. */\n timeout?: number;\n};\n\nconst DEFAULT_TIMEOUT = 30_000;\n\n/** Responses are wrapped as `{ result: … }`; tolerate a bare body too. */\nconst unwrap = <T>(payload: unknown): T => {\n if (payload && typeof payload === 'object' && 'result' in payload) {\n return (payload as { result: T }).result;\n }\n\n return payload as T;\n};\n\nconst BODY_SNIPPET_LENGTH = 200;\n\nconst errorMessage = (\n payload: unknown,\n status: number,\n raw: string,\n): string => {\n if (payload && typeof payload === 'object' && 'error' in payload) {\n const { error } = payload as { error: unknown };\n\n if (typeof error === 'string') {\n return error;\n }\n }\n\n // A non-JSON body is usually a proxy or CDN error page rather than the API.\n // Including a snippet is the difference between a debuggable failure and an\n // opaque status code.\n const snippet = raw.trim().slice(0, BODY_SNIPPET_LENGTH);\n\n return snippet\n ? `Intents Connect API responded ${status}: ${snippet}`\n : `Intents Connect API responded ${status}`;\n};\n\nexport const createIntentsConnectApi = (\n options: IntentsConnectApiOptions,\n): IntentsConnectApi => {\n const {\n baseUrl,\n apiKey,\n apiKeyProxyUrl,\n fetch: fetchImpl,\n timeout = DEFAULT_TIMEOUT,\n } = options;\n\n const doFetch: FetchLike =\n fetchImpl ?? ((input, init) => globalThis.fetch(input, init));\n\n const request = async <T>(args: {\n path: string;\n method?: 'GET' | 'POST' | 'DELETE';\n query?: Record<string, string | undefined>;\n body?: unknown;\n withApiKey?: boolean;\n }): Promise<T> => {\n const { path, method = 'GET', query, body, withApiKey = false } = args;\n\n const origin = withApiKey && apiKeyProxyUrl ? apiKeyProxyUrl : baseUrl;\n const url = new URL(path, origin.endsWith('/') ? origin : `${origin}/`);\n\n Object.entries(query ?? {}).forEach(([key, value]) => {\n if (value !== undefined && value !== '') {\n url.searchParams.set(key, value);\n }\n });\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Only create calls are priced per key. Sending it elsewhere is harmless\n // but misleading, so it is scoped deliberately.\n if (withApiKey && apiKey && !apiKeyProxyUrl) {\n headers['x-api-key'] = apiKey;\n }\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeout);\n\n let response: Awaited<ReturnType<FetchLike>>;\n let raw: string;\n\n try {\n response = await doFetch(url.toString(), {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: controller.signal,\n });\n\n // Inside the try, and before the timer is cleared: `doFetch` resolves as\n // soon as headers arrive, so reading the body here is what keeps a server\n // that sends headers then stalls from hanging the call forever.\n raw = await response.text();\n } catch (error) {\n if (controller.signal.aborted) {\n throw new IntentsConnectError(\n `request to ${path} timed out after ${timeout}ms`,\n { cause: error },\n );\n }\n\n throw error;\n } finally {\n clearTimeout(timer);\n }\n\n // Parsed defensively and AFTER the status check below can see it: an error\n // response is frequently not JSON at all (an HTML 502 from a proxy), and\n // throwing SyntaxError here would hide the status code and make\n // `isExecutionInFlight` unreachable.\n let payload: unknown;\n let parsed = true;\n\n try {\n payload = raw ? JSON.parse(raw) : undefined;\n } catch {\n payload = undefined;\n parsed = false;\n }\n\n if (!response.ok) {\n throw new IntentsConnectApiError(\n errorMessage(payload, response.status, raw),\n response.status,\n parsed ? payload : raw,\n );\n }\n\n if (!parsed) {\n throw new IntentsConnectError(\n `Intents Connect API returned a non-JSON body for ${path}: ${raw\n .trim()\n .slice(0, BODY_SNIPPET_LENGTH)}`,\n );\n }\n\n return unwrap<T>(payload);\n };\n\n const encode = (value: string) => encodeURIComponent(value);\n\n return {\n getIntermediary: (wallet, opts) =>\n request<Intermediary>({\n path: `api/v1/executions/${encode(wallet)}/intermediary`,\n query: { publicKey: opts?.publicKey },\n }),\n\n createExecution: (wallet: string, body: CreateExecutionBody) =>\n request<Execution>({\n path: `api/v1/executions/${encode(wallet)}`,\n method: 'POST',\n body,\n withApiKey: true,\n }),\n\n createStepsExecution: (wallet: string, body: CreateStepsExecutionBody) =>\n request<Execution>({\n path: `api/v1/executions/${encode(wallet)}/steps`,\n method: 'POST',\n body,\n withApiKey: true,\n }),\n\n listSupportedTokens: (flow?: SupportedTokensFlow) =>\n request<SupportedTokensResult>({\n path: 'api/v1/supported_tokens',\n query: { flow },\n }),\n\n submitSignature: (wallet: string, body: SubmitSignatureBody) =>\n request<{ status: SubmitStatus }>({\n path: `api/v1/executions/${encode(wallet)}/submit`,\n method: 'POST',\n body,\n }),\n\n recordDeposit: async (body: RecordDepositBody) => {\n await request<unknown>({\n path: 'api/v1/executions/deposit/submit',\n method: 'POST',\n body,\n });\n },\n\n listExecutions: async (wallet: string, query?: ListExecutionsQuery) => {\n const result = await request<Execution[] | Execution>({\n path: `api/v1/executions/${encode(wallet)}`,\n query: {\n id: query?.id,\n status: Array.isArray(query?.status)\n ? query.status.join(',')\n : (query?.status as string | undefined),\n },\n });\n\n return Array.isArray(result) ? result : [result].filter(Boolean);\n },\n\n deleteExecution: async (\n wallet: string,\n executionId: string,\n signature: DeleteSignatureEnvelope,\n ) => {\n await request<unknown>({\n path: `api/v1/executions/${encode(wallet)}/${encode(executionId)}`,\n method: 'DELETE',\n body: signature,\n });\n },\n };\n};\n"],"names":["resolveTransferAmount","args","raw","atomic","DEFAULT_TIMEOUT","unwrap","payload","BODY_SNIPPET_LENGTH","errorMessage","status","error","snippet","createIntentsConnectApi","options","baseUrl","apiKey","apiKeyProxyUrl","fetchImpl","timeout","doFetch","input","init","request","path","method","query","body","withApiKey","origin","url","key","value","headers","controller","timer","response","IntentsConnectError","parsed","IntentsConnectApiError","encode","wallet","opts","flow","result","executionId","signature"],"mappings":"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"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type Logger = {
|
|
2
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
3
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
4
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const defaultLogger: Logger;
|
|
7
|
+
export declare const noopLogger: Logger;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Execution, ExecutionStatus, Intermediary } from '../types/execution';
|
|
2
|
+
import { Phase } from './phases';
|
|
3
|
+
/**
|
|
4
|
+
* Declared as a type alias rather than an interface so it keeps an implicit
|
|
5
|
+
* index signature — some store helpers constrain context to
|
|
6
|
+
* `Record<string, unknown>`, which interfaces do not satisfy.
|
|
7
|
+
*/
|
|
8
|
+
export type Context = {
|
|
9
|
+
phase: Phase;
|
|
10
|
+
intermediary?: Intermediary;
|
|
11
|
+
executionId?: string;
|
|
12
|
+
execution?: Execution;
|
|
13
|
+
status?: ExecutionStatus;
|
|
14
|
+
/** Present once a fee has been measured (threeRound) or reported. */
|
|
15
|
+
networkFee?: string;
|
|
16
|
+
/** The amount the steps may spend, post-fee. */
|
|
17
|
+
spendable?: string;
|
|
18
|
+
/** threeRound only: the amount actually baked into the created steps. */
|
|
19
|
+
bakedAmount?: string;
|
|
20
|
+
/** Only ever set after the signature is submitted. */
|
|
21
|
+
depositAddress?: string;
|
|
22
|
+
depositMemo?: string | null;
|
|
23
|
+
/** ISO — the deposit-address validity deadline. */
|
|
24
|
+
deadline?: string;
|
|
25
|
+
depositTxHash?: string;
|
|
26
|
+
hasSubmittedSignature: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* A `delete_execution` signature / request is in flight.
|
|
29
|
+
*
|
|
30
|
+
* Deliberately NOT a phase: `cancel()` can be invoked from almost any point
|
|
31
|
+
* in the lifecycle — including terminal phases, where a transition would be
|
|
32
|
+
* refused — so cancelling is orthogonal to where the execution itself got
|
|
33
|
+
* to. A UI needs it to say "sign to cancel" rather than mislabelling the
|
|
34
|
+
* prompt with the phase it interrupted (e.g. "Awaiting signature").
|
|
35
|
+
*/
|
|
36
|
+
isCancelling: boolean;
|
|
37
|
+
error?: Error;
|
|
38
|
+
};
|
|
39
|
+
export declare const createInitialContext: () => Context;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Step } from '../../../types/execution';
|
|
2
|
+
/**
|
|
3
|
+
* At least one step must call the destination token contract.
|
|
4
|
+
*
|
|
5
|
+
* The network fee is collected in the destination token via a fee-transfer step
|
|
6
|
+
* the backend appends, so a step set that never engages that token is rejected.
|
|
7
|
+
* Native destinations are exempt — the fee is taken in native value.
|
|
8
|
+
*
|
|
9
|
+
* When the real steps genuinely never touch the payout token, satisfy this by
|
|
10
|
+
* appending a zero-value transfer of it to the intermediary.
|
|
11
|
+
*/
|
|
12
|
+
export declare const destinationTokenIsTouched: (steps: Step[], destinationTokenAddress?: string) => void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Execution } from '../../../types/execution';
|
|
2
|
+
/**
|
|
3
|
+
* An absent `details.networkFee` means gas estimation failed, so nothing was
|
|
4
|
+
* carved and the response amounts are still GROSS. Copying them forward bakes
|
|
5
|
+
* an amount the batch cannot cover once the fee step is appended.
|
|
6
|
+
*
|
|
7
|
+
* The correct response is to retry the round, never to proceed.
|
|
8
|
+
*/
|
|
9
|
+
export declare const feeMustBeEstimated: (execution: Execution) => string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stellar 1Click uses a SHARED deposit address, so the per-quote memo is the
|
|
3
|
+
* only thing attributing incoming funds to this execution. It must appear on
|
|
4
|
+
* the payment AND on `deposit/submit` — omitting it on either loses the deposit.
|
|
5
|
+
*/
|
|
6
|
+
export declare const memoPresentForStellar: (originChain: string, memo?: string | null) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signing happens BEFORE the deposit: the service holds a pre-signed batch and
|
|
3
|
+
* fires it the moment the bridge settles.
|
|
4
|
+
*
|
|
5
|
+
* So a deposit address must never reach the user — as a QR code or otherwise —
|
|
6
|
+
* until the signature is submitted, or funds can arrive with no batch to fire.
|
|
7
|
+
*/
|
|
8
|
+
export declare const mustBeSignedBeforeDeposit: (hasSubmittedSignature: boolean) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Execution } from '../../../types/execution';
|
|
2
|
+
import { SigningPayload, SigningStandard } from '../../../types/signing';
|
|
3
|
+
/** A created execution without a signing payload cannot be progressed. */
|
|
4
|
+
export declare const mustHaveSigningPayload: (execution: Execution) => {
|
|
5
|
+
payload: SigningPayload;
|
|
6
|
+
standard: SigningStandard;
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Execution } from '../../../types/execution';
|
|
2
|
+
/**
|
|
3
|
+
* A `dry: false` create takes an in-flight lock per (intermediary, chain); a
|
|
4
|
+
* second one answers 409. Checking first turns that into an actionable error
|
|
5
|
+
* naming the execution to wait for or cancel.
|
|
6
|
+
*/
|
|
7
|
+
export declare const noExecutionInFlight: (openExecutions: Execution[]) => void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EVM origins only: the wallet must be on the origin chain before it can send
|
|
3
|
+
* the deposit. Skipped when the connector exposes no chain id.
|
|
4
|
+
*/
|
|
5
|
+
export declare const originNetworkMatches: (getChainId: (() => Promise<number>) | undefined, expectedChainId: number | null | undefined) => Promise<void>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SigningStandard } from '../../../types/signing';
|
|
2
|
+
/**
|
|
3
|
+
* ed25519 cannot recover a public key from a signature, so the verifier needs
|
|
4
|
+
* one. secp256k1 can (`ecrecover`), so sending one is rejected. Enforcing the
|
|
5
|
+
* asymmetry here turns a confusing 400 into a local error.
|
|
6
|
+
*/
|
|
7
|
+
export declare const publicKeyMatchesStandard: (standard: SigningStandard, publicKey?: string) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Three-round flow only: the quote can move between the measuring round and the
|
|
3
|
+
* create. If the service now guarantees LESS than the amount baked into the
|
|
4
|
+
* steps, the batch cannot cover `spend + fee` and must not be signed.
|
|
5
|
+
*
|
|
6
|
+
* A higher guarantee is fine — the surplus simply stays at the intermediary.
|
|
7
|
+
*/
|
|
8
|
+
export declare const quoteMustNotHaveMoved: (bakedAmount: string, returnedMinAmountOut: string) => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FlowShape } from '../../../types/execution';
|
|
2
|
+
/**
|
|
3
|
+
* `quote.recipient` is out-operation only. On a bridge-in the recipient is
|
|
4
|
+
* always the intermediary, and sending one is a 400.
|
|
5
|
+
*
|
|
6
|
+
* v1 implements `bridge-in` only, so any recipient is rejected. The `flow`
|
|
7
|
+
* argument is threaded through now so that adding `out-operation` to
|
|
8
|
+
* `FlowShape` turns this into a real branch rather than a signature change at
|
|
9
|
+
* every call site.
|
|
10
|
+
*/
|
|
11
|
+
export declare const recipientOnlyOnOutOperation: (flow: FlowShape, recipient?: string) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Step } from '../../../types/execution';
|
|
2
|
+
/**
|
|
3
|
+
* Round 1 of the three-round flow must send no steps.
|
|
4
|
+
*
|
|
5
|
+
* Gas estimation only runs when `steps` is non-empty, so an empty array is what
|
|
6
|
+
* yields a quote with no fee deducted. It must therefore also be `dry: true`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const round1MustBeStepless: (steps: Step[]) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ExecutionType, Step } from '../../../types/execution';
|
|
2
|
+
/**
|
|
3
|
+
* Steps accept only the five documented keys. An unknown key, a differently
|
|
4
|
+
* cased spelling, or a duplicate is a 400 — so it is worth catching locally
|
|
5
|
+
* where the message can name the offending step.
|
|
6
|
+
*/
|
|
7
|
+
export declare const stepShapeIsLegal: (steps: Step[], type: ExecutionType) => void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Step } from '../../../types/execution';
|
|
2
|
+
/**
|
|
3
|
+
* A `dry: false` create with an empty steps array is rejected with
|
|
4
|
+
* `400 steps are required for non-dry executions`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const stepsRequiredForRealCreate: (steps: Step[], dry: boolean) => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FeeStrategy, Step } from '../../../types/execution';
|
|
2
|
+
/** True when the steps embed the `{MIN_AMOUNT_OUT}` placeholder. */
|
|
3
|
+
export declare const stepsUsePlaceholder: (steps: Step[]) => boolean;
|
|
4
|
+
/**
|
|
5
|
+
* `{MIN_AMOUNT_OUT}` exists to collapse the three-round protocol into one call,
|
|
6
|
+
* so the two strategies are alternatives. A `threeRound` flow computes literal
|
|
7
|
+
* amounts, and leaking the placeholder into one of its steps would leave two
|
|
8
|
+
* steps operating on different amounts.
|
|
9
|
+
*
|
|
10
|
+
* The converse is deliberately NOT asserted. Under the placeholder strategy the
|
|
11
|
+
* runner passes `{MIN_AMOUNT_OUT}` as `ctx.amount`, so the placeholder appears
|
|
12
|
+
* exactly when the recipe interpolates the amount. A recipe that legitimately
|
|
13
|
+
* never does — a bare `claim()`, or steps with intentionally fixed amounts — is
|
|
14
|
+
* valid, and rejecting it here would block it for no reason. The runner logs a
|
|
15
|
+
* warning via `stepsUsePlaceholder` instead.
|
|
16
|
+
*/
|
|
17
|
+
export declare const strategiesAreExclusive: (strategy: FeeStrategy, steps: Step[]) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every precondition the Intents Connect protocol imposes, named after what it
|
|
3
|
+
* prevents. Each throws a `GuardError` carrying a `GuardCode`.
|
|
4
|
+
*/
|
|
5
|
+
export { amountMustExceedFee } from './checks/amountMustExceedFee';
|
|
6
|
+
export { destinationTokenIsTouched } from './checks/destinationTokenIsTouched';
|
|
7
|
+
export { feeMustBeEstimated } from './checks/feeMustBeEstimated';
|
|
8
|
+
export { memoPresentForStellar } from './checks/memoPresentForStellar';
|
|
9
|
+
export { mustBeSignedBeforeDeposit } from './checks/mustBeSignedBeforeDeposit';
|
|
10
|
+
export { mustHaveSigningPayload } from './checks/mustHaveSigningPayload';
|
|
11
|
+
export { noExecutionInFlight } from './checks/noExecutionInFlight';
|
|
12
|
+
export { originNetworkMatches } from './checks/originNetworkMatches';
|
|
13
|
+
export { publicKeyMatchesStandard } from './checks/publicKeyMatchesStandard';
|
|
14
|
+
export { quoteMustNotHaveMoved } from './checks/quoteMustNotHaveMoved';
|
|
15
|
+
export { recipientOnlyOnOutOperation } from './checks/recipientOnlyOnOutOperation';
|
|
16
|
+
export { round1MustBeStepless } from './checks/round1MustBeStepless';
|
|
17
|
+
export { stepShapeIsLegal } from './checks/stepShapeIsLegal';
|
|
18
|
+
export { stepsRequiredForRealCreate } from './checks/stepsRequiredForRealCreate';
|
|
19
|
+
export { stepsUsePlaceholder, strategiesAreExclusive, } from './checks/strategiesAreExclusive';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createExecutionMachine, moveTo, type ExecutionMachine, type ExecutionMachineStore, type MoveToOptions, } from './machine';
|
|
2
|
+
export { createInitialContext, type Context } from './context';
|
|
3
|
+
export { PHASE_TRANSITIONS, TERMINAL_PHASES, isTerminalPhase, type Phase, } from './phases';
|
|
4
|
+
export * as guards from './guards';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Logger } from '../logger';
|
|
2
|
+
import { Context } from './context';
|
|
3
|
+
import { Phase } from './phases';
|
|
4
|
+
/** The valtio store a framework binding subscribes to. */
|
|
5
|
+
export type ExecutionMachineStore = {
|
|
6
|
+
state: Phase;
|
|
7
|
+
context: Context;
|
|
8
|
+
};
|
|
9
|
+
export type ExecutionMachine = {
|
|
10
|
+
readonly current: Phase;
|
|
11
|
+
readonly context: Context;
|
|
12
|
+
getStore: () => ExecutionMachineStore;
|
|
13
|
+
canMoveTo: (phase: Phase) => boolean;
|
|
14
|
+
/** Refuses an illegal transition; check `current` to see whether it moved. */
|
|
15
|
+
moveTo: (phase: Phase) => ExecutionMachine;
|
|
16
|
+
/**
|
|
17
|
+
* Returns to `idle` with a fresh context. Deliberately bypasses the
|
|
18
|
+
* transition table: it is how a runner is made reusable after a terminal
|
|
19
|
+
* phase, which by design has no outgoing edges.
|
|
20
|
+
*/
|
|
21
|
+
reset: () => void;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A FACTORY, deliberately — unlike the widget, which exports a module-level
|
|
25
|
+
* singleton machine.
|
|
26
|
+
*
|
|
27
|
+
* Two reasons: several executions may be in flight in one app (deposit while a
|
|
28
|
+
* previous one settles), and a module-level valtio store leaks state across
|
|
29
|
+
* requests under SSR.
|
|
30
|
+
*
|
|
31
|
+
* Built on `valtio/vanilla` rather than `valtio-fsm`. `valtio-fsm` imports
|
|
32
|
+
* valtio's ROOT entry, which re-exports `valtio/react` and therefore requires
|
|
33
|
+
* `react` to be installed — so importing this "headless" package in Node or a
|
|
34
|
+
* worker failed with ERR_MODULE_NOT_FOUND. `valtio/vanilla` pulls only
|
|
35
|
+
* `proxy-compare`. Only five members of `valtio-fsm` were ever used, so the
|
|
36
|
+
* transitions table below replaces it outright.
|
|
37
|
+
*/
|
|
38
|
+
export declare const createExecutionMachine: () => ExecutionMachine;
|
|
39
|
+
export type MoveToOptions = {
|
|
40
|
+
logger?: Logger;
|
|
41
|
+
onMoved?: (phase: Phase) => void;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Guarded transition. Mirrors `moveTo` in the widget's machine: an illegal
|
|
45
|
+
* transition is refused and logged rather than throwing, so a stray event
|
|
46
|
+
* cannot corrupt a live execution.
|
|
47
|
+
*
|
|
48
|
+
* Returns whether the move happened.
|
|
49
|
+
*/
|
|
50
|
+
export declare const moveTo: (machine: ExecutionMachine, phase: Phase, { logger, onMoved }?: MoveToOptions) => boolean;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side phases — what a UI renders.
|
|
3
|
+
*
|
|
4
|
+
* Distinct from `ExecutionStatus`, which is the server's view and only exists
|
|
5
|
+
* from `creating` onward.
|
|
6
|
+
*/
|
|
7
|
+
export type Phase = 'idle'
|
|
8
|
+
/** GET /intermediary — deterministic, cached per wallet. */
|
|
9
|
+
| 'resolving-identity'
|
|
10
|
+
/** Build steps and size the amount against the fee (0 or 2 dry rounds). */
|
|
11
|
+
| 'planning'
|
|
12
|
+
/** POST create, dry: false. */
|
|
13
|
+
| 'creating'
|
|
14
|
+
/** Waiting on the wallet prompt. */
|
|
15
|
+
| 'awaiting-signature'
|
|
16
|
+
/** POST /submit. */
|
|
17
|
+
| 'submitting'
|
|
18
|
+
/** User sends funds — wallet transfer or QR / exchange. */
|
|
19
|
+
| 'awaiting-deposit'
|
|
20
|
+
/** Polling to a terminal status. */
|
|
21
|
+
| 'settling' | 'success' | 'failed' | 'expired' | 'cancelled';
|
|
22
|
+
/**
|
|
23
|
+
* Legal transitions.
|
|
24
|
+
*
|
|
25
|
+
* Two entries carry non-obvious behaviour:
|
|
26
|
+
*
|
|
27
|
+
* - `submitting` FORKS. v1 is bridge-in so it always needs a deposit, but the
|
|
28
|
+
* direct edge to `settling` is modelled now because out-operations answer
|
|
29
|
+
* `SIGNING` from /submit and skip the deposit phase entirely.
|
|
30
|
+
* - `expired` re-enters `settling`. `EXPIRED` looks terminal but is not: a
|
|
31
|
+
* deposit that settles late revives an execution straight to
|
|
32
|
+
* `OPERATION_PROCESSING`.
|
|
33
|
+
* - `idle` may go directly to `awaiting-signature`, `awaiting-deposit` or
|
|
34
|
+
* `settling`. Those are `resume()` re-entry points: identity and planning
|
|
35
|
+
* already happened in an earlier session, so replaying them would emit events
|
|
36
|
+
* for work this runner never did. Which one it enters depends on how far the
|
|
37
|
+
* execution actually got.
|
|
38
|
+
* - `idle` may also go to `failed`, because `run()` and `resume()` can both fail
|
|
39
|
+
* on their very first call (an unknown execution id, a disconnected wallet)
|
|
40
|
+
* and must still record the error rather than silently staying idle.
|
|
41
|
+
* - EVERY non-terminal phase may go to `cancelled`. `cancel()` is the user's
|
|
42
|
+
* escape hatch from a stuck execution and can be invoked at any point after
|
|
43
|
+
* an execution id exists — refusing the transition from any live phase would
|
|
44
|
+
* leave the machine claiming an execution that was already deleted.
|
|
45
|
+
*/
|
|
46
|
+
export declare const PHASE_TRANSITIONS: Readonly<Record<Phase, readonly Phase[]>>;
|
|
47
|
+
export declare const TERMINAL_PHASES: readonly Phase[];
|
|
48
|
+
export declare const isTerminalPhase: (phase: Phase) => boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { IntentsConnectContextValue } from './context';
|
|
3
|
+
export type IntentsConnectProviderProps = IntentsConnectContextValue & {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Supplies the API client and connected wallet to `useExecution`.
|
|
8
|
+
*
|
|
9
|
+
* Deliberately holds no execution state of its own: a runner is created per
|
|
10
|
+
* `useExecution` call so two concurrent executions never share a machine.
|
|
11
|
+
*/
|
|
12
|
+
export declare const IntentsConnectProvider: ({ children, ...value }: IntentsConnectProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ExecutionRunnerOptions, IntentsConnectApi, WalletConnector } from '../index';
|
|
2
|
+
/** Everything a `useExecution` call needs that is not per-execution. */
|
|
3
|
+
export type IntentsConnectContextValue = Omit<ExecutionRunnerOptions, 'api' | 'wallet' | 'onEvent'> & {
|
|
4
|
+
api: IntentsConnectApi;
|
|
5
|
+
/**
|
|
6
|
+
* The connected wallet. `null` while disconnected — `useExecution` surfaces a
|
|
7
|
+
* `WALLET_NOT_CONNECTED` guard rather than throwing at render time.
|
|
8
|
+
*/
|
|
9
|
+
wallet: WalletConnector | null;
|
|
10
|
+
};
|
|
11
|
+
export declare const IntentsConnectContext: import('react').Context<IntentsConnectContextValue | null>;
|
|
12
|
+
export declare const useIntentsConnect: () => IntentsConnectContextValue;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { IntentsConnectProvider, type IntentsConnectProviderProps, } from './IntentsConnectProvider';
|
|
2
|
+
export { IntentsConnectContext, useIntentsConnect, type IntentsConnectContextValue, } from './context';
|
|
3
|
+
export { useExecution, type UseExecutionOptions, type UseExecutionResult, } from './useExecution';
|