@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
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { IntentsConnectApiError, IntentsConnectError } from '@/errors';
|
|
2
|
+
import type { Execution, Intermediary, SubmitStatus } from '@/types/execution';
|
|
3
|
+
import type { DeleteSignatureEnvelope } from '@/types/signing';
|
|
4
|
+
import type {
|
|
5
|
+
CreateExecutionBody,
|
|
6
|
+
CreateStepsExecutionBody,
|
|
7
|
+
IntentsConnectApi,
|
|
8
|
+
ListExecutionsQuery,
|
|
9
|
+
RecordDepositBody,
|
|
10
|
+
SubmitSignatureBody,
|
|
11
|
+
SupportedTokensFlow,
|
|
12
|
+
SupportedTokensResult,
|
|
13
|
+
} from '@/api/types';
|
|
14
|
+
|
|
15
|
+
export type FetchLike = (
|
|
16
|
+
input: string,
|
|
17
|
+
init?: {
|
|
18
|
+
method?: string;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
body?: string;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
},
|
|
23
|
+
) => Promise<{
|
|
24
|
+
ok: boolean;
|
|
25
|
+
status: number;
|
|
26
|
+
text: () => Promise<string>;
|
|
27
|
+
}>;
|
|
28
|
+
|
|
29
|
+
export type IntentsConnectApiOptions = {
|
|
30
|
+
baseUrl: string;
|
|
31
|
+
/**
|
|
32
|
+
* Sent as `x-api-key` on create calls.
|
|
33
|
+
*
|
|
34
|
+
* Prefer `apiKeyProxyUrl` in a browser: the key prices per-key fees
|
|
35
|
+
* server-side and should not ship in client code.
|
|
36
|
+
*/
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Base URL of your own server that injects `x-api-key` and forwards to the
|
|
40
|
+
* Intents Connect API. When set, create calls go here instead of `baseUrl`.
|
|
41
|
+
*/
|
|
42
|
+
apiKeyProxyUrl?: string;
|
|
43
|
+
/** Defaults to global `fetch`. */
|
|
44
|
+
fetch?: FetchLike;
|
|
45
|
+
/** Milliseconds. Defaults to 30_000. */
|
|
46
|
+
timeout?: number;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const DEFAULT_TIMEOUT = 30_000;
|
|
50
|
+
|
|
51
|
+
/** Responses are wrapped as `{ result: … }`; tolerate a bare body too. */
|
|
52
|
+
const unwrap = <T>(payload: unknown): T => {
|
|
53
|
+
if (payload && typeof payload === 'object' && 'result' in payload) {
|
|
54
|
+
return (payload as { result: T }).result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return payload as T;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const BODY_SNIPPET_LENGTH = 200;
|
|
61
|
+
|
|
62
|
+
const errorMessage = (
|
|
63
|
+
payload: unknown,
|
|
64
|
+
status: number,
|
|
65
|
+
raw: string,
|
|
66
|
+
): string => {
|
|
67
|
+
if (payload && typeof payload === 'object' && 'error' in payload) {
|
|
68
|
+
const { error } = payload as { error: unknown };
|
|
69
|
+
|
|
70
|
+
if (typeof error === 'string') {
|
|
71
|
+
return error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// A non-JSON body is usually a proxy or CDN error page rather than the API.
|
|
76
|
+
// Including a snippet is the difference between a debuggable failure and an
|
|
77
|
+
// opaque status code.
|
|
78
|
+
const snippet = raw.trim().slice(0, BODY_SNIPPET_LENGTH);
|
|
79
|
+
|
|
80
|
+
return snippet
|
|
81
|
+
? `Intents Connect API responded ${status}: ${snippet}`
|
|
82
|
+
: `Intents Connect API responded ${status}`;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const createIntentsConnectApi = (
|
|
86
|
+
options: IntentsConnectApiOptions,
|
|
87
|
+
): IntentsConnectApi => {
|
|
88
|
+
const {
|
|
89
|
+
baseUrl,
|
|
90
|
+
apiKey,
|
|
91
|
+
apiKeyProxyUrl,
|
|
92
|
+
fetch: fetchImpl,
|
|
93
|
+
timeout = DEFAULT_TIMEOUT,
|
|
94
|
+
} = options;
|
|
95
|
+
|
|
96
|
+
const doFetch: FetchLike =
|
|
97
|
+
fetchImpl ?? ((input, init) => globalThis.fetch(input, init));
|
|
98
|
+
|
|
99
|
+
const request = async <T>(args: {
|
|
100
|
+
path: string;
|
|
101
|
+
method?: 'GET' | 'POST' | 'DELETE';
|
|
102
|
+
query?: Record<string, string | undefined>;
|
|
103
|
+
body?: unknown;
|
|
104
|
+
withApiKey?: boolean;
|
|
105
|
+
}): Promise<T> => {
|
|
106
|
+
const { path, method = 'GET', query, body, withApiKey = false } = args;
|
|
107
|
+
|
|
108
|
+
const origin = withApiKey && apiKeyProxyUrl ? apiKeyProxyUrl : baseUrl;
|
|
109
|
+
const url = new URL(path, origin.endsWith('/') ? origin : `${origin}/`);
|
|
110
|
+
|
|
111
|
+
Object.entries(query ?? {}).forEach(([key, value]) => {
|
|
112
|
+
if (value !== undefined && value !== '') {
|
|
113
|
+
url.searchParams.set(key, value);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const headers: Record<string, string> = {
|
|
118
|
+
'Content-Type': 'application/json',
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// Only create calls are priced per key. Sending it elsewhere is harmless
|
|
122
|
+
// but misleading, so it is scoped deliberately.
|
|
123
|
+
if (withApiKey && apiKey && !apiKeyProxyUrl) {
|
|
124
|
+
headers['x-api-key'] = apiKey;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const controller = new AbortController();
|
|
128
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
129
|
+
|
|
130
|
+
let response: Awaited<ReturnType<FetchLike>>;
|
|
131
|
+
let raw: string;
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
response = await doFetch(url.toString(), {
|
|
135
|
+
method,
|
|
136
|
+
headers,
|
|
137
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
138
|
+
signal: controller.signal,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Inside the try, and before the timer is cleared: `doFetch` resolves as
|
|
142
|
+
// soon as headers arrive, so reading the body here is what keeps a server
|
|
143
|
+
// that sends headers then stalls from hanging the call forever.
|
|
144
|
+
raw = await response.text();
|
|
145
|
+
} catch (error) {
|
|
146
|
+
if (controller.signal.aborted) {
|
|
147
|
+
throw new IntentsConnectError(
|
|
148
|
+
`request to ${path} timed out after ${timeout}ms`,
|
|
149
|
+
{ cause: error },
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
throw error;
|
|
154
|
+
} finally {
|
|
155
|
+
clearTimeout(timer);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Parsed defensively and AFTER the status check below can see it: an error
|
|
159
|
+
// response is frequently not JSON at all (an HTML 502 from a proxy), and
|
|
160
|
+
// throwing SyntaxError here would hide the status code and make
|
|
161
|
+
// `isExecutionInFlight` unreachable.
|
|
162
|
+
let payload: unknown;
|
|
163
|
+
let parsed = true;
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
payload = raw ? JSON.parse(raw) : undefined;
|
|
167
|
+
} catch {
|
|
168
|
+
payload = undefined;
|
|
169
|
+
parsed = false;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!response.ok) {
|
|
173
|
+
throw new IntentsConnectApiError(
|
|
174
|
+
errorMessage(payload, response.status, raw),
|
|
175
|
+
response.status,
|
|
176
|
+
parsed ? payload : raw,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (!parsed) {
|
|
181
|
+
throw new IntentsConnectError(
|
|
182
|
+
`Intents Connect API returned a non-JSON body for ${path}: ${raw
|
|
183
|
+
.trim()
|
|
184
|
+
.slice(0, BODY_SNIPPET_LENGTH)}`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return unwrap<T>(payload);
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const encode = (value: string) => encodeURIComponent(value);
|
|
192
|
+
|
|
193
|
+
return {
|
|
194
|
+
getIntermediary: (wallet, opts) =>
|
|
195
|
+
request<Intermediary>({
|
|
196
|
+
path: `api/v1/executions/${encode(wallet)}/intermediary`,
|
|
197
|
+
query: { publicKey: opts?.publicKey },
|
|
198
|
+
}),
|
|
199
|
+
|
|
200
|
+
createExecution: (wallet: string, body: CreateExecutionBody) =>
|
|
201
|
+
request<Execution>({
|
|
202
|
+
path: `api/v1/executions/${encode(wallet)}`,
|
|
203
|
+
method: 'POST',
|
|
204
|
+
body,
|
|
205
|
+
withApiKey: true,
|
|
206
|
+
}),
|
|
207
|
+
|
|
208
|
+
createStepsExecution: (wallet: string, body: CreateStepsExecutionBody) =>
|
|
209
|
+
request<Execution>({
|
|
210
|
+
path: `api/v1/executions/${encode(wallet)}/steps`,
|
|
211
|
+
method: 'POST',
|
|
212
|
+
body,
|
|
213
|
+
withApiKey: true,
|
|
214
|
+
}),
|
|
215
|
+
|
|
216
|
+
listSupportedTokens: (flow?: SupportedTokensFlow) =>
|
|
217
|
+
request<SupportedTokensResult>({
|
|
218
|
+
path: 'api/v1/supported_tokens',
|
|
219
|
+
query: { flow },
|
|
220
|
+
}),
|
|
221
|
+
|
|
222
|
+
submitSignature: (wallet: string, body: SubmitSignatureBody) =>
|
|
223
|
+
request<{ status: SubmitStatus }>({
|
|
224
|
+
path: `api/v1/executions/${encode(wallet)}/submit`,
|
|
225
|
+
method: 'POST',
|
|
226
|
+
body,
|
|
227
|
+
}),
|
|
228
|
+
|
|
229
|
+
recordDeposit: async (body: RecordDepositBody) => {
|
|
230
|
+
await request<unknown>({
|
|
231
|
+
path: 'api/v1/executions/deposit/submit',
|
|
232
|
+
method: 'POST',
|
|
233
|
+
body,
|
|
234
|
+
});
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
listExecutions: async (wallet: string, query?: ListExecutionsQuery) => {
|
|
238
|
+
const result = await request<Execution[] | Execution>({
|
|
239
|
+
path: `api/v1/executions/${encode(wallet)}`,
|
|
240
|
+
query: {
|
|
241
|
+
id: query?.id,
|
|
242
|
+
status: Array.isArray(query?.status)
|
|
243
|
+
? query.status.join(',')
|
|
244
|
+
: (query?.status as string | undefined),
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
return Array.isArray(result) ? result : [result].filter(Boolean);
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
deleteExecution: async (
|
|
252
|
+
wallet: string,
|
|
253
|
+
executionId: string,
|
|
254
|
+
signature: DeleteSignatureEnvelope,
|
|
255
|
+
) => {
|
|
256
|
+
await request<unknown>({
|
|
257
|
+
path: `api/v1/executions/${encode(wallet)}/${encode(executionId)}`,
|
|
258
|
+
method: 'DELETE',
|
|
259
|
+
body: signature,
|
|
260
|
+
});
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time conformance between our hand-written domain types and the
|
|
3
|
+
* generated OpenAPI document.
|
|
4
|
+
*
|
|
5
|
+
* ## Why this file exists rather than using the generated types directly
|
|
6
|
+
*
|
|
7
|
+
* Not one of the 26 schemas in the document declares a `required` list, so every
|
|
8
|
+
* generated field is optional. Exposing them as this package's API would make
|
|
9
|
+
* `execution.id`, `quote.depositAddress` and `details.payload` all
|
|
10
|
+
* `T | undefined`, which erases exactly the invariants the guards and the runner
|
|
11
|
+
* exist to enforce — every call site would grow a null check that says nothing.
|
|
12
|
+
*
|
|
13
|
+
* So the generated types are treated as a **checked contract** instead. The
|
|
14
|
+
* assertions below fail `yarn typecheck` when the wire shape drifts. Workflow:
|
|
15
|
+
*
|
|
16
|
+
* 1. `yarn generate:api`
|
|
17
|
+
* 2. `yarn typecheck`
|
|
18
|
+
* 3. a failure here means the API changed and our logic needs a decision —
|
|
19
|
+
* not that this file needs relaxing.
|
|
20
|
+
*
|
|
21
|
+
* Every check is written so the compiler error NAMES what drifted, e.g.
|
|
22
|
+
* `Type '"OPERATION_REFUNDED"' does not satisfy the constraint 'never'` rather
|
|
23
|
+
* than a bare `false is not true`.
|
|
24
|
+
*
|
|
25
|
+
* This file has no runtime values and is excluded from the build.
|
|
26
|
+
*/
|
|
27
|
+
import type {
|
|
28
|
+
Execution,
|
|
29
|
+
ExecutionDetails,
|
|
30
|
+
ExecutionQuote,
|
|
31
|
+
ExecutionStatus,
|
|
32
|
+
ExecutionType,
|
|
33
|
+
Intermediary,
|
|
34
|
+
Step,
|
|
35
|
+
SwapType,
|
|
36
|
+
} from '@/types/execution';
|
|
37
|
+
import type {
|
|
38
|
+
DeleteSignatureEnvelope,
|
|
39
|
+
SigningPayload,
|
|
40
|
+
SigningStandard,
|
|
41
|
+
TonConnectEnvelope,
|
|
42
|
+
} from '@/types/signing';
|
|
43
|
+
import type { CreateExecutionBody, SubmitSignatureBody } from '@/api/types';
|
|
44
|
+
import type { components } from '@/api/generated/openapi';
|
|
45
|
+
|
|
46
|
+
type Schemas = components['schemas'];
|
|
47
|
+
|
|
48
|
+
/* ── Assertion helpers ─────────────────────────────────────────────────────── */
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Compiles only when `T` is `never`. Anything left over is printed in the error,
|
|
52
|
+
* which is what makes these failures self-describing.
|
|
53
|
+
*/
|
|
54
|
+
type AssertNone<T extends never> = T;
|
|
55
|
+
|
|
56
|
+
/** Members of `From` that `To` does not cover. */
|
|
57
|
+
type UncoveredMembers<From, To> = Exclude<From, To>;
|
|
58
|
+
|
|
59
|
+
/** Keys of `From` that `To` does not declare. */
|
|
60
|
+
type MissingKeys<From, To> = Exclude<keyof From, keyof To>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Keys present on both sides whose value type in `From` is not assignable to the
|
|
64
|
+
* same key in `To`. Optionality is stripped, because the document marks
|
|
65
|
+
* everything optional and that alone is not drift.
|
|
66
|
+
*/
|
|
67
|
+
type IncompatibleKeys<From, To> = {
|
|
68
|
+
[K in keyof From & keyof To]-?: [NonNullable<From[K]>] extends [
|
|
69
|
+
NonNullable<To[K]>,
|
|
70
|
+
]
|
|
71
|
+
? never
|
|
72
|
+
: K;
|
|
73
|
+
}[keyof From & keyof To];
|
|
74
|
+
|
|
75
|
+
type SpecExecution = Schemas['controllers.executionDoc'];
|
|
76
|
+
type SpecQuote = Schemas['controllers.executionQuoteDoc'];
|
|
77
|
+
type SpecDetails = Schemas['controllers.executionDetailsDoc'];
|
|
78
|
+
type SpecPayload = Schemas['controllers.signingPayloadDoc'];
|
|
79
|
+
type SpecIntermediary = Schemas['controllers.intermediaryResult'];
|
|
80
|
+
type SpecStep = Schemas['controllers.executionStepEVMDoc'];
|
|
81
|
+
type SpecCreateBody = Schemas['controllers.createExecutionRequestDoc'];
|
|
82
|
+
type SpecSubmitBody = Schemas['controllers.submitSignatureRequestDoc'];
|
|
83
|
+
type SpecDeleteBody = Schemas['controllers.deleteExecutionRequestDoc'];
|
|
84
|
+
type SpecTonConnect = Schemas['controllers.tonConnectEnvelopeDoc'];
|
|
85
|
+
|
|
86
|
+
/* ── Enums ──────────────────────────────────────────────────────────────────
|
|
87
|
+
* Checked in both directions. A value added server-side is the most dangerous
|
|
88
|
+
* drift there is: the polling loop would treat an unknown status as "keep
|
|
89
|
+
* waiting", and a new signing standard would reach a wallet that cannot produce
|
|
90
|
+
* it. A value removed means we carry a branch that can never fire. */
|
|
91
|
+
|
|
92
|
+
export type NoNewStatuses = AssertNone<
|
|
93
|
+
UncoveredMembers<NonNullable<SpecExecution['status']>, ExecutionStatus>
|
|
94
|
+
>;
|
|
95
|
+
export type NoStaleStatuses = AssertNone<
|
|
96
|
+
UncoveredMembers<ExecutionStatus, NonNullable<SpecExecution['status']>>
|
|
97
|
+
>;
|
|
98
|
+
|
|
99
|
+
export type NoNewSigningStandards = AssertNone<
|
|
100
|
+
UncoveredMembers<NonNullable<SpecPayload['standard']>, SigningStandard>
|
|
101
|
+
>;
|
|
102
|
+
export type NoStaleSigningStandards = AssertNone<
|
|
103
|
+
UncoveredMembers<SigningStandard, NonNullable<SpecPayload['standard']>>
|
|
104
|
+
>;
|
|
105
|
+
|
|
106
|
+
export type NoNewSwapTypes = AssertNone<
|
|
107
|
+
UncoveredMembers<NonNullable<SpecQuote['swapType']>, SwapType>
|
|
108
|
+
>;
|
|
109
|
+
export type NoStaleSwapTypes = AssertNone<
|
|
110
|
+
UncoveredMembers<SwapType, NonNullable<SpecQuote['swapType']>>
|
|
111
|
+
>;
|
|
112
|
+
|
|
113
|
+
export type NoNewExecutionTypes = AssertNone<
|
|
114
|
+
UncoveredMembers<NonNullable<SpecExecution['type']>, ExecutionType>
|
|
115
|
+
>;
|
|
116
|
+
|
|
117
|
+
export type NoNewOriginTypes = AssertNone<
|
|
118
|
+
UncoveredMembers<
|
|
119
|
+
NonNullable<SpecIntermediary['originType']>,
|
|
120
|
+
Intermediary['originType']
|
|
121
|
+
>
|
|
122
|
+
>;
|
|
123
|
+
|
|
124
|
+
/* ── Response shapes ────────────────────────────────────────────────────────
|
|
125
|
+
* `Execution['transaction']` is excluded on purpose: the API returns it (both
|
|
126
|
+
* the widget and last-mile read `transaction.evmTxHash`) but the document does
|
|
127
|
+
* not declare it, so requiring it here would fail against a correct spec.
|
|
128
|
+
*
|
|
129
|
+
* Nested objects are compared through their own checks rather than structurally,
|
|
130
|
+
* so a failure points at the specific schema that moved. */
|
|
131
|
+
|
|
132
|
+
export type ExecutionFieldsExist = AssertNone<
|
|
133
|
+
MissingKeys<Omit<Execution, 'transaction'>, SpecExecution>
|
|
134
|
+
>;
|
|
135
|
+
export type ExecutionFieldsFit = AssertNone<
|
|
136
|
+
IncompatibleKeys<
|
|
137
|
+
SpecExecution,
|
|
138
|
+
Omit<Execution, 'quote' | 'details' | 'steps' | 'transaction'>
|
|
139
|
+
>
|
|
140
|
+
>;
|
|
141
|
+
|
|
142
|
+
export type QuoteFieldsExist = AssertNone<
|
|
143
|
+
MissingKeys<ExecutionQuote, SpecQuote>
|
|
144
|
+
>;
|
|
145
|
+
export type QuoteFieldsFit = AssertNone<
|
|
146
|
+
IncompatibleKeys<
|
|
147
|
+
SpecQuote,
|
|
148
|
+
// `depositMemo` is `string | null` for us and `string` on the wire: the key
|
|
149
|
+
// is absent in JSON, which the client normalises to null.
|
|
150
|
+
Omit<ExecutionQuote, 'depositMemo'>
|
|
151
|
+
>
|
|
152
|
+
>;
|
|
153
|
+
|
|
154
|
+
export type DetailsFieldsExist = AssertNone<
|
|
155
|
+
MissingKeys<ExecutionDetails, SpecDetails>
|
|
156
|
+
>;
|
|
157
|
+
export type DetailsFieldsFit = AssertNone<
|
|
158
|
+
IncompatibleKeys<SpecDetails, Omit<ExecutionDetails, 'payload'>>
|
|
159
|
+
>;
|
|
160
|
+
|
|
161
|
+
export type PayloadFieldsExist = AssertNone<
|
|
162
|
+
MissingKeys<SigningPayload, SpecPayload>
|
|
163
|
+
>;
|
|
164
|
+
export type PayloadFieldsFit = AssertNone<
|
|
165
|
+
IncompatibleKeys<SpecPayload, SigningPayload>
|
|
166
|
+
>;
|
|
167
|
+
|
|
168
|
+
export type IntermediaryFieldsExist = AssertNone<
|
|
169
|
+
MissingKeys<Intermediary, SpecIntermediary>
|
|
170
|
+
>;
|
|
171
|
+
export type IntermediaryFieldsFit = AssertNone<
|
|
172
|
+
IncompatibleKeys<SpecIntermediary, Intermediary>
|
|
173
|
+
>;
|
|
174
|
+
|
|
175
|
+
/* ── Request shapes ─────────────────────────────────────────────────────────
|
|
176
|
+
* Reversed: what we send has to be acceptable to the API, so our field types
|
|
177
|
+
* must fit the wire's. Catches a field we send being renamed or retyped. */
|
|
178
|
+
|
|
179
|
+
export type CreateBodyFieldsAccepted = AssertNone<
|
|
180
|
+
// `steps` is checked below; see the parameters deviation.
|
|
181
|
+
IncompatibleKeys<Omit<CreateExecutionBody, 'steps'>, SpecCreateBody>
|
|
182
|
+
>;
|
|
183
|
+
export type CreateBodyHasNoUnknownFields = AssertNone<
|
|
184
|
+
MissingKeys<Omit<CreateExecutionBody, 'steps'>, SpecCreateBody>
|
|
185
|
+
>;
|
|
186
|
+
|
|
187
|
+
export type SubmitBodyFieldsAccepted = AssertNone<
|
|
188
|
+
IncompatibleKeys<SubmitSignatureBody, SpecSubmitBody>
|
|
189
|
+
>;
|
|
190
|
+
export type SubmitBodyHasNoUnknownFields = AssertNone<
|
|
191
|
+
MissingKeys<SubmitSignatureBody, SpecSubmitBody>
|
|
192
|
+
>;
|
|
193
|
+
|
|
194
|
+
export type DeleteBodyFieldsAccepted = AssertNone<
|
|
195
|
+
IncompatibleKeys<DeleteSignatureEnvelope, SpecDeleteBody>
|
|
196
|
+
>;
|
|
197
|
+
|
|
198
|
+
export type TonConnectFieldsAccepted = AssertNone<
|
|
199
|
+
IncompatibleKeys<TonConnectEnvelope, SpecTonConnect>
|
|
200
|
+
>;
|
|
201
|
+
|
|
202
|
+
/* ── Steps ──────────────────────────────────────────────────────────────────
|
|
203
|
+
* The five-key whitelist `stepShapeIsLegal` rejects unknown keys against, so
|
|
204
|
+
* the key set is pinned in both directions: a new wire field would otherwise be
|
|
205
|
+
* rejected client-side before the API ever saw it. */
|
|
206
|
+
|
|
207
|
+
export type StepFieldsExist = AssertNone<MissingKeys<Step, SpecStep>>;
|
|
208
|
+
export type StepHasNoUnmodelledFields = AssertNone<MissingKeys<SpecStep, Step>>;
|
|
209
|
+
export type StepFieldsFit = AssertNone<
|
|
210
|
+
IncompatibleKeys<SpecStep, Omit<Step, 'parameters' | 'metadata'>>
|
|
211
|
+
>;
|
|
212
|
+
|
|
213
|
+
/* ── Known deviation: `executionStepEVMDoc.parameters` ──────────────────────
|
|
214
|
+
*
|
|
215
|
+
* The document declares it as `array` of `object`, which generates
|
|
216
|
+
* `Record<string, never>[]` — an uninhabited element type nothing can satisfy.
|
|
217
|
+
* Step parameters are ABI-encoded scalars and tuples (`["0xPool", "94275"]`),
|
|
218
|
+
* never plain objects, as every worked example in the developer guides shows.
|
|
219
|
+
*
|
|
220
|
+
* So this is a spec defect, not a mismatch on our side, and `Step['parameters']`
|
|
221
|
+
* stays `string[]`. The assertion pins the deviation rather than hiding it: it
|
|
222
|
+
* holds while the document is still wrong and starts failing once `parameters`
|
|
223
|
+
* is corrected — at which point delete this block and drop `parameters` from the
|
|
224
|
+
* `StepFieldsFit` exclusion above.
|
|
225
|
+
*/
|
|
226
|
+
export type StepParametersStillDeviates = AssertNone<
|
|
227
|
+
UncoveredMembers<
|
|
228
|
+
NonNullable<SpecStep['parameters']> extends Record<string, never>[]
|
|
229
|
+
? never
|
|
230
|
+
: 'spec parameters schema was fixed — re-enable the StepFieldsFit check',
|
|
231
|
+
never
|
|
232
|
+
>
|
|
233
|
+
>;
|