felix-mcp 2.0.123 → 2.0.129
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 +26 -3
- package/dist/arc-hl-return-ports.js +15 -2
- package/dist/arc-hl-return.js +4 -2
- package/dist/arc-home.js +3 -10
- package/dist/arc-hypercore-funding.js +1076 -0
- package/dist/arc-hypercore-return.js +826 -0
- package/dist/arc-pm-return.js +28 -3
- package/dist/arc-safe-invalidation-hints.js +209 -0
- package/dist/arc-safe-invalidation.js +672 -0
- package/dist/arc-venue-app-policy.js +30 -0
- package/dist/funding.js +192 -25
- package/dist/getting-started-guide.js +12 -2
- package/dist/http-server.js +25 -8
- package/dist/index.js +821 -202
- package/dist/key-backup.js +15 -4
- package/dist/polymarket.js +5 -3
- package/dist/public-venue.js +35 -0
- package/dist/rpc-endpoints.js +133 -0
- package/dist/safe-migration.js +7 -3
- package/dist/safe-onboarding.js +58 -49
- package/dist/safe-policy.js +39 -28
- package/package.json +14 -2
- package/server.json +2 -2
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
// SAFE_NONCE_INVALIDATION_2026_09_28 (infra fix list A3a): the local driver
|
|
2
|
+
// for the engine's owner-signed Safe nonce invalidation
|
|
3
|
+
// (/v1/arc-home/safe-invalidations/*, engine services/arc_safe_invalidation*.py).
|
|
4
|
+
//
|
|
5
|
+
// Why it exists: every Arc home Safe payload Felix issues (an Arc withdrawal,
|
|
6
|
+
// a HyperCore funding, a Polymarket funding) permanently reserves the Safe's
|
|
7
|
+
// nonce. A payload that is issued but never executed (quote expiry during a
|
|
8
|
+
// deploy freeze, a declined signature, a crashed client) keeps that nonce
|
|
9
|
+
// reserved, and every later Felix Safe move refuses. The engine's only exit is
|
|
10
|
+
// this route: the OWNER signs a no-op SafeTx at the reserved nonce; once it
|
|
11
|
+
// executes, the original can never execute, the Safe is free again, and the
|
|
12
|
+
// engine closes the original journey on proof.
|
|
13
|
+
//
|
|
14
|
+
// What this client signs, and only after checking it itself:
|
|
15
|
+
// * the child typed data Felix hands out is rebuilt locally and must be the
|
|
16
|
+
// canonical Safe 1.3.0 SafeTx on chain 5042 for THIS account's verified
|
|
17
|
+
// Safe: CALL (operation 0) to the owner's own address, value 0, data 0x,
|
|
18
|
+
// zero gas/refund fields -- it moves nothing;
|
|
19
|
+
// * at the reserved nonce: the nonce must equal the original's nonce when
|
|
20
|
+
// this client can see it (the caller's expected_safe_nonce, or the Arc
|
|
21
|
+
// withdrawal's own SafeTx), and this client's own Arc quorum
|
|
22
|
+
// (FELIX_ARC_PROOF_RPC_URLS) must prove the Safe's CURRENT nonce is that
|
|
23
|
+
// nonce, with the Safe owned solely by this owner (verifySafeState);
|
|
24
|
+
// * it signs its OWN rebuilt typed data, journals the signature before the
|
|
25
|
+
// submit, submits once per invocation and never signs again.
|
|
26
|
+
// Completion: the engine's child proof, then this client's own quorum proof
|
|
27
|
+
// that exactly this no-op executed successfully, moved no USDC and spent the
|
|
28
|
+
// nonce (verifyNoopExecuted), then the engine's close-relay / close-withdrawal
|
|
29
|
+
// of the original. If the ORIGINAL executed instead, nothing is closed and the
|
|
30
|
+
// original is resumed with its own tool.
|
|
31
|
+
import { getAddress } from "viem";
|
|
32
|
+
import { ARC_MAINNET_CHAIN_ID, arcSafeTxHash, assertArcSafeTxShape } from "./arc-home.js";
|
|
33
|
+
import { INVALIDATION_EFFECT, SAFE_INVALIDATION_ROUTE_PREFIX, SAFE_INVALIDATION_TOOL, errorRecord, invalidationSuggestion, isInvalidationWriter, reasonOf, } from "./arc-safe-invalidation-hints.js";
|
|
34
|
+
export * from "./arc-safe-invalidation-hints.js";
|
|
35
|
+
// Checkpoint names never end in a money-movement suffix (":sent", ":submitted",
|
|
36
|
+
// ":submission-started", ...): the no-op moves no funds.
|
|
37
|
+
export const CP = {
|
|
38
|
+
scope: "sinv:scope",
|
|
39
|
+
prepared: "sinv:prepared",
|
|
40
|
+
signed: "sinv:signed",
|
|
41
|
+
offered: "sinv:offer",
|
|
42
|
+
executed: "sinv:executed",
|
|
43
|
+
completed: "sinv:completed",
|
|
44
|
+
};
|
|
45
|
+
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
46
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
47
|
+
const ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
48
|
+
const HASH = /^0x[0-9a-fA-F]{64}$/;
|
|
49
|
+
const SIGNATURE = /^0x[0-9a-fA-F]{130}$/;
|
|
50
|
+
const DEFAULT_MAX_POLLS = 40;
|
|
51
|
+
const MIN_POLL_MS = 2_000;
|
|
52
|
+
const MAX_POLL_MS = 20_000;
|
|
53
|
+
const TERMINAL_CHILD = new Set(["invalidated", "original_executed"]);
|
|
54
|
+
// Bounded passive discovery of this account's existing invalidations (GET list, 50 per page).
|
|
55
|
+
const MAX_CHILD_LIST_PAGES = 10;
|
|
56
|
+
function isRecord(value) {
|
|
57
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
58
|
+
}
|
|
59
|
+
export const SHIPPED_INVALIDATION_POLICY = Object.freeze({
|
|
60
|
+
verifySafeState: null,
|
|
61
|
+
verifyNoopExecuted: null,
|
|
62
|
+
});
|
|
63
|
+
export function invalidationPolicyGaps(policy) {
|
|
64
|
+
const gaps = [];
|
|
65
|
+
if (typeof policy?.verifySafeState !== "function")
|
|
66
|
+
gaps.push("safe_invalidation_safe_state_unverified");
|
|
67
|
+
if (typeof policy?.verifyNoopExecuted !== "function")
|
|
68
|
+
gaps.push("safe_invalidation_execution_unverified");
|
|
69
|
+
return gaps;
|
|
70
|
+
}
|
|
71
|
+
// ------------------------------------------------------------------ child checks
|
|
72
|
+
/** The no-op SafeTx this client would sign: built locally, never taken from the server. */
|
|
73
|
+
export function noopInvalidationTypedData(safe, owner, nonce) {
|
|
74
|
+
return {
|
|
75
|
+
domain: { chainId: ARC_MAINNET_CHAIN_ID, verifyingContract: getAddress(safe) },
|
|
76
|
+
types: {
|
|
77
|
+
EIP712Domain: [{ name: "chainId", type: "uint256" }, { name: "verifyingContract", type: "address" }],
|
|
78
|
+
SafeTx: [
|
|
79
|
+
{ name: "to", type: "address" }, { name: "value", type: "uint256" }, { name: "data", type: "bytes" },
|
|
80
|
+
{ name: "operation", type: "uint8" }, { name: "safeTxGas", type: "uint256" },
|
|
81
|
+
{ name: "baseGas", type: "uint256" }, { name: "gasPrice", type: "uint256" },
|
|
82
|
+
{ name: "gasToken", type: "address" }, { name: "refundReceiver", type: "address" },
|
|
83
|
+
{ name: "nonce", type: "uint256" },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
primaryType: "SafeTx",
|
|
87
|
+
message: {
|
|
88
|
+
to: getAddress(owner), value: "0", data: "0x", operation: 0, safeTxGas: "0", baseGas: "0",
|
|
89
|
+
gasPrice: "0", gasToken: ZERO_ADDRESS, refundReceiver: ZERO_ADDRESS, nonce: String(nonce),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export class SafeInvalidationHostileServer extends Error {
|
|
94
|
+
constructor(message) {
|
|
95
|
+
super(message);
|
|
96
|
+
this.name = "SafeInvalidationHostileServer";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function hostile(message) {
|
|
100
|
+
throw new SafeInvalidationHostileServer(message);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The server's child typed data -> the digest and nonce of the no-op this
|
|
104
|
+
* client rebuilt, or a refusal. Any field other than the fixed no-op refuses.
|
|
105
|
+
*/
|
|
106
|
+
export function verifyNoopChild(typedData, ctx) {
|
|
107
|
+
let shape;
|
|
108
|
+
try {
|
|
109
|
+
shape = assertArcSafeTxShape(typedData, { safe: ctx.safe, chainId: ARC_MAINNET_CHAIN_ID });
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
hostile(`the invalidation SafeTx is not canonical for this Safe: ${error.message}`);
|
|
113
|
+
}
|
|
114
|
+
if (shape.operation !== 0 || shape.to.toLowerCase() !== ctx.owner || String(shape.data).toLowerCase() !== "0x") {
|
|
115
|
+
hostile("the invalidation SafeTx is not a no-op call to this account's own owner");
|
|
116
|
+
}
|
|
117
|
+
if (ctx.nonce !== null && shape.nonce !== ctx.nonce) {
|
|
118
|
+
hostile("the invalidation SafeTx is not at the original operation's reserved nonce");
|
|
119
|
+
}
|
|
120
|
+
const rebuilt = noopInvalidationTypedData(ctx.safe, ctx.owner, shape.nonce);
|
|
121
|
+
const digest = arcSafeTxHash(rebuilt).toLowerCase();
|
|
122
|
+
if (arcSafeTxHash(typedData).toLowerCase() !== digest) {
|
|
123
|
+
hostile("the invalidation SafeTx digest is not the digest of the no-op this client rebuilt");
|
|
124
|
+
}
|
|
125
|
+
return { nonce: shape.nonce, safeTxHash: digest, typedData: rebuilt };
|
|
126
|
+
}
|
|
127
|
+
/** Every child view: this invalidation, a known phase, never a claim of moved funds. */
|
|
128
|
+
export function assertChildView(view, invalidationId) {
|
|
129
|
+
if (!isRecord(view))
|
|
130
|
+
hostile("the invalidation view is not an object");
|
|
131
|
+
const v = view;
|
|
132
|
+
const id = String(v.invalidation_id || "").toLowerCase();
|
|
133
|
+
if (!UUID.test(id) || (invalidationId !== null && id !== invalidationId))
|
|
134
|
+
hostile("the server answered for another invalidation");
|
|
135
|
+
if (!["prepared", "signed", "submitted_unknown", "reconciliation_required", "invalidated", "original_executed"]
|
|
136
|
+
.includes(String(v.phase))) {
|
|
137
|
+
hostile("the invalidation phase is unknown");
|
|
138
|
+
}
|
|
139
|
+
if (v.money_moved === true)
|
|
140
|
+
hostile("a no-op invalidation never moves funds");
|
|
141
|
+
return v;
|
|
142
|
+
}
|
|
143
|
+
const ORIGINAL_READ = {
|
|
144
|
+
withdrawal_source: (id) => `/v1/arc-home/operations/${id}`,
|
|
145
|
+
hypercore: (id) => `/v1/arc-home/hypercore-fundings/${id}`,
|
|
146
|
+
polygon: (id) => `/v1/arc-home/polygon-fundings/${id}`,
|
|
147
|
+
};
|
|
148
|
+
const ORIGINAL_TOOL = {
|
|
149
|
+
withdrawal_source: "arc_home_withdraw (or reconcile_arc_home_operation)",
|
|
150
|
+
hypercore: "fund_hypercore_from_arc",
|
|
151
|
+
polygon: "fund_polymarket_from_arc",
|
|
152
|
+
};
|
|
153
|
+
// Original phases in which its source calls are proven (or its journey is closed): nothing to invalidate.
|
|
154
|
+
const ORIGINAL_DONE = {
|
|
155
|
+
withdrawal_source: new Set(["executed", "completed", "gateway_funded", "burn_attested", "mint_submitted",
|
|
156
|
+
"attestation_expired"]),
|
|
157
|
+
hypercore: new Set(["completed", "refunded", "source_confirmed", "source_not_executed", "closed"]),
|
|
158
|
+
// 'closed': an operator closed a held funding whose source executed (engine A5 closure).
|
|
159
|
+
polygon: new Set(["credited", "refunded", "source_confirmed", "source_not_executed", "closed"]),
|
|
160
|
+
};
|
|
161
|
+
function httpStatus(response) {
|
|
162
|
+
const meta = isRecord(response._meta) ? response._meta : {};
|
|
163
|
+
const status = Number(meta.http_status);
|
|
164
|
+
return Number.isInteger(status) ? status : undefined;
|
|
165
|
+
}
|
|
166
|
+
function definitiveRefusal(response) {
|
|
167
|
+
const status = httpStatus(response);
|
|
168
|
+
return status !== undefined && [400, 401, 403, 404, 409, 422].includes(status);
|
|
169
|
+
}
|
|
170
|
+
function failed(response) {
|
|
171
|
+
const status = httpStatus(response);
|
|
172
|
+
return response.ok === false || (status !== undefined && status >= 400);
|
|
173
|
+
}
|
|
174
|
+
export async function driveSafeInvalidation(request, deps) {
|
|
175
|
+
const writer = request.original_writer;
|
|
176
|
+
const originalId = typeof request.original_operation_id === "string" ? request.original_operation_id.toLowerCase() : "";
|
|
177
|
+
const expectedNonce = request.expected_safe_nonce;
|
|
178
|
+
const requestedChildRaw = request.invalidation_id ?? null;
|
|
179
|
+
const requestedChild = typeof requestedChildRaw === "string" ? requestedChildRaw.toLowerCase() : null;
|
|
180
|
+
const result = (ok, status, fields) => {
|
|
181
|
+
const prepared = deps.getCheckpoint(CP.prepared);
|
|
182
|
+
return {
|
|
183
|
+
ok, status, tool: SAFE_INVALIDATION_TOOL, account_id: deps.accountId,
|
|
184
|
+
original_writer: writer, original_operation_id: originalId,
|
|
185
|
+
invalidation_id: prepared?.invalidation_id ?? null,
|
|
186
|
+
safe_nonce: prepared?.nonce ?? null,
|
|
187
|
+
noop_safe_tx_hash: prepared?.safe_tx_hash ?? null,
|
|
188
|
+
...(prepared?.existing === true ? { existing_invalidation_adopted: true } : {}),
|
|
189
|
+
effect: INVALIDATION_EFFECT,
|
|
190
|
+
...fields,
|
|
191
|
+
// The no-op moves no funds, whatever happened to the original.
|
|
192
|
+
money_moved: false, user_funds_moved: false,
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
const refuse = (code, message, extra = {}) => result(false, "refused", { error: { code, message }, signed: Boolean(deps.getCheckpoint(CP.signed)), ...extra });
|
|
196
|
+
const pending = (code, message, extra = {}) => result(false, "in_progress", { error: { code, message }, next_action: "resume_with_same_idempotency_key", ...extra });
|
|
197
|
+
// -------- request and policy: refuse before any request
|
|
198
|
+
if (!isInvalidationWriter(writer)) {
|
|
199
|
+
return refuse("safe_invalidation_writer_invalid", "original_writer must be withdrawal_source, hypercore or polygon.");
|
|
200
|
+
}
|
|
201
|
+
if (!UUID.test(originalId))
|
|
202
|
+
return refuse("safe_invalidation_operation_invalid", "original_operation_id must be a UUID.");
|
|
203
|
+
if (expectedNonce !== null && (!Number.isSafeInteger(expectedNonce) || expectedNonce < 0)) {
|
|
204
|
+
return refuse("safe_invalidation_nonce_invalid", "expected_safe_nonce must be a non-negative integer.");
|
|
205
|
+
}
|
|
206
|
+
if (requestedChildRaw !== null && (typeof requestedChildRaw !== "string" || !UUID.test(requestedChild))) {
|
|
207
|
+
return refuse("safe_invalidation_id_invalid", "invalidation_id must be a UUID.");
|
|
208
|
+
}
|
|
209
|
+
const accountId = typeof deps.accountId === "string" ? deps.accountId.toLowerCase() : "";
|
|
210
|
+
if (!UUID.test(accountId))
|
|
211
|
+
return refuse("child_account_required", "Select the account with use_child_account first.");
|
|
212
|
+
const owner = typeof deps.owner === "string" && ADDRESS.test(deps.owner) ? deps.owner.toLowerCase() : "";
|
|
213
|
+
if (!owner)
|
|
214
|
+
return refuse("client_signature_required", "A local owner key is required.");
|
|
215
|
+
const gaps = invalidationPolicyGaps(deps.policy);
|
|
216
|
+
if (gaps.length) {
|
|
217
|
+
return refuse("safe_invalidation_policy_unverified", "This client cannot independently prove the Safe's nonce or the invalidation's execution; "
|
|
218
|
+
+ "nothing was prepared or signed. Release the stuck Safe nonce in the Felix app (Wallet); "
|
|
219
|
+
+ "do not start a new transfer from this account meanwhile.", { policy_gaps: gaps });
|
|
220
|
+
}
|
|
221
|
+
const api = async (method, path, body, opts) => {
|
|
222
|
+
try {
|
|
223
|
+
const out = await deps.call(method, path, body, opts);
|
|
224
|
+
return isRecord(out) ? out : { ok: false, error: { code: "invalid_response", outcome_unknown: true } };
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
return { ok: false, error: { code: "transport_lost", outcome_unknown: true,
|
|
228
|
+
message: String(error?.message || error).slice(0, 200) } };
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const startedAt = deps.now();
|
|
232
|
+
const budget = deps.pollBudgetMs ?? 45_000;
|
|
233
|
+
const maxPolls = deps.maxPolls ?? DEFAULT_MAX_POLLS;
|
|
234
|
+
let polls = 0;
|
|
235
|
+
let delay = MIN_POLL_MS;
|
|
236
|
+
const pause = async () => { await deps.sleep(delay); delay = Math.min(MAX_POLL_MS, delay * 2); };
|
|
237
|
+
const outOfBudget = () => polls >= maxPolls || deps.now() - startedAt > budget;
|
|
238
|
+
try {
|
|
239
|
+
const safe = String(await deps.expectedSafe() || "").toLowerCase();
|
|
240
|
+
if (!ADDRESS.test(safe))
|
|
241
|
+
return refuse("safe_invalidation_safe_unverified", "The account's Arc home Safe is not verified for this owner.");
|
|
242
|
+
const scope = { account_id: accountId, owner, safe, original_writer: writer, original_operation_id: originalId,
|
|
243
|
+
expected_safe_nonce: expectedNonce, ...(requestedChild ? { invalidation_id: requestedChild } : {}) };
|
|
244
|
+
const savedScope = deps.getCheckpoint(CP.scope);
|
|
245
|
+
if (savedScope && JSON.stringify(savedScope) !== JSON.stringify(scope)) {
|
|
246
|
+
return refuse("safe_invalidation_scope_conflict", "This idempotency key belongs to a different invalidation.");
|
|
247
|
+
}
|
|
248
|
+
if (!savedScope)
|
|
249
|
+
deps.saveCheckpoint(CP.scope, scope);
|
|
250
|
+
const done = deps.getCheckpoint(CP.completed);
|
|
251
|
+
if (done && isRecord(done.result))
|
|
252
|
+
return done.result;
|
|
253
|
+
const withAccount = (body = {}) => ({ account_id: accountId, ...body });
|
|
254
|
+
// -------- the original: this account's, not already executed, and (when visible) its nonce
|
|
255
|
+
let originalNonce = expectedNonce;
|
|
256
|
+
if (!deps.getCheckpoint(CP.prepared)) {
|
|
257
|
+
const read = await api("GET", `${ORIGINAL_READ[writer](originalId)}?account_id=${encodeURIComponent(accountId)}`);
|
|
258
|
+
if (failed(read)) {
|
|
259
|
+
if (httpStatus(read) === 404) {
|
|
260
|
+
return refuse("safe_invalidation_original_not_found", "Felix has no such operation for this account; nothing was prepared or signed.");
|
|
261
|
+
}
|
|
262
|
+
if (definitiveRefusal(read)) {
|
|
263
|
+
return refuse(reasonOf(read) || "safe_invalidation_original_unreadable", "Felix would not read the original operation; nothing was prepared or signed.", { server_error: errorRecord(read) });
|
|
264
|
+
}
|
|
265
|
+
return pending("safe_invalidation_original_unavailable", "The original operation could not be read; nothing was signed.");
|
|
266
|
+
}
|
|
267
|
+
const phase = String(read.phase || "");
|
|
268
|
+
if (writer === "withdrawal_source") {
|
|
269
|
+
if (String(read.operation_id || "").toLowerCase() !== originalId)
|
|
270
|
+
hostile("the server answered for another operation");
|
|
271
|
+
if (read.kind !== "arc_same_chain") {
|
|
272
|
+
return refuse("safe_invalidation_writer_unsupported", "Only a same-chain Arc withdrawal can be invalidated this way; nothing was prepared or signed.");
|
|
273
|
+
}
|
|
274
|
+
const txs = Array.isArray(read.safe_transactions) ? read.safe_transactions : [];
|
|
275
|
+
const first = isRecord(txs[0]) ? txs[0] : null;
|
|
276
|
+
const typed = first && isRecord(first.typed_data) ? first.typed_data : null;
|
|
277
|
+
const domain = typed && isRecord(typed.domain) ? typed.domain : null;
|
|
278
|
+
const message = typed && isRecord(typed.message) ? typed.message : null;
|
|
279
|
+
if (txs.length !== 1 || !domain || !message || String(domain.verifyingContract || "").toLowerCase() !== safe
|
|
280
|
+
|| Number(domain.chainId) !== ARC_MAINNET_CHAIN_ID) {
|
|
281
|
+
hostile("the withdrawal's SafeTx is not for this account's Safe");
|
|
282
|
+
}
|
|
283
|
+
const nonce = Number(message.nonce);
|
|
284
|
+
if (!Number.isSafeInteger(nonce) || nonce < 0)
|
|
285
|
+
hostile("the withdrawal's SafeTx nonce is invalid");
|
|
286
|
+
if (originalNonce !== null && originalNonce !== nonce) {
|
|
287
|
+
return refuse("safe_invalidation_nonce_mismatch", "expected_safe_nonce is not the withdrawal's Safe nonce; nothing was signed.");
|
|
288
|
+
}
|
|
289
|
+
originalNonce = nonce;
|
|
290
|
+
if (typeof first.tx_hash === "string" && HASH.test(first.tx_hash)) {
|
|
291
|
+
return refuse("safe_invalidation_original_executed", "The withdrawal's Safe transaction executed; there is nothing to invalidate.", { original_phase: phase });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
if (String(read.id || "").toLowerCase() !== originalId)
|
|
296
|
+
hostile("the server answered for another funding");
|
|
297
|
+
if (String(read.safe || "").toLowerCase() !== safe || String(read.owner || "").toLowerCase() !== owner) {
|
|
298
|
+
hostile("the funding is not from this account's Safe and owner");
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const sourceProven = read.money_moved === true || isRecord(read.source) || isRecord(read.source_proof);
|
|
302
|
+
if (ORIGINAL_DONE[writer].has(phase) || sourceProven) {
|
|
303
|
+
return refuse("safe_invalidation_original_not_invalidatable", "The original operation's Safe transaction executed or its journey is closed; there is nothing to invalidate.", { original_phase: phase || null });
|
|
304
|
+
}
|
|
305
|
+
// -------- an existing child (SAFE_NONCE_HARDENING_2026_09_28, verifier MEDIUM): the
|
|
306
|
+
// engine keeps ONE invalidation per Safe nonce. When one already exists (its
|
|
307
|
+
// journal was lost, or it was started under another idempotency key) a new
|
|
308
|
+
// prepare is refused -- today a bare 503 -- so it is adopted and completed by
|
|
309
|
+
// id instead of looping on "retry with the same key".
|
|
310
|
+
const noopDigest = originalNonce !== null
|
|
311
|
+
? arcSafeTxHash(noopInvalidationTypedData(safe, owner, originalNonce)).toLowerCase() : null;
|
|
312
|
+
const childFacts = (view) => {
|
|
313
|
+
const evidence = isRecord(view.evidence) ? view.evidence : {};
|
|
314
|
+
const closure = isRecord(evidence.writer_closure) ? evidence.writer_closure : null;
|
|
315
|
+
const proof = isRecord(evidence.proof) ? evidence.proof : null;
|
|
316
|
+
const proofDigest = proof && HASH.test(String(proof.safe_tx_hash || "")) ? String(proof.safe_tx_hash).toLowerCase() : null;
|
|
317
|
+
let nonce = null;
|
|
318
|
+
if (view.phase === "prepared") {
|
|
319
|
+
try {
|
|
320
|
+
nonce = verifyNoopChild(view.typed_data, { safe, owner, nonce: null }).nonce;
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
nonce = null;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return { closure, proofDigest, nonce };
|
|
327
|
+
};
|
|
328
|
+
/** "match": provably THIS original's child; "other": provably not; "unknown": the view cannot tell. */
|
|
329
|
+
const bindChild = (view) => {
|
|
330
|
+
const { closure, proofDigest, nonce } = childFacts(view);
|
|
331
|
+
if (closure) {
|
|
332
|
+
return closure.writer === writer && String(closure.operation_id || "").toLowerCase() === originalId ? "match" : "other";
|
|
333
|
+
}
|
|
334
|
+
if (view.phase === "original_executed")
|
|
335
|
+
return "other";
|
|
336
|
+
if (view.phase === "prepared") {
|
|
337
|
+
if (nonce === null)
|
|
338
|
+
return "other";
|
|
339
|
+
if (originalNonce !== null)
|
|
340
|
+
return nonce === originalNonce ? "match" : "other";
|
|
341
|
+
return "unknown";
|
|
342
|
+
}
|
|
343
|
+
if (view.phase === "invalidated" && noopDigest !== null && proofDigest !== null) {
|
|
344
|
+
return proofDigest === noopDigest ? "match" : "other";
|
|
345
|
+
}
|
|
346
|
+
return "unknown";
|
|
347
|
+
};
|
|
348
|
+
const adoptChild = (view) => {
|
|
349
|
+
const id = String(view.invalidation_id).toLowerCase();
|
|
350
|
+
// A prepared child that is not the canonical no-op for this Safe is hostile, not "another operation's".
|
|
351
|
+
if (view.phase === "prepared" && childFacts(view).nonce === null)
|
|
352
|
+
verifyNoopChild(view.typed_data, { safe, owner, nonce: null });
|
|
353
|
+
if (bindChild(view) === "other") {
|
|
354
|
+
return refuse("safe_invalidation_child_for_another_operation", "That invalidation is not for this operation's reserved Safe nonce; nothing was signed.", { existing_invalidation: { invalidation_id: id, phase: view.phase } });
|
|
355
|
+
}
|
|
356
|
+
if (view.phase === "prepared") {
|
|
357
|
+
// Unsigned: verified exactly like a fresh child, then signed below after this
|
|
358
|
+
// client's own quorum proves the Safe's current nonce is the child's nonce.
|
|
359
|
+
const plan = verifyNoopChild(view.typed_data, { safe, owner, nonce: originalNonce });
|
|
360
|
+
deps.saveCheckpoint(CP.prepared, { invalidation_id: id, nonce: plan.nonce, safe_tx_hash: plan.safeTxHash,
|
|
361
|
+
typed_data: plan.typedData, existing: true });
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
// Signed elsewhere: followed and closed, never signed again.
|
|
365
|
+
deps.saveCheckpoint(CP.prepared, { invalidation_id: id, adopted: true, existing: true,
|
|
366
|
+
...(originalNonce !== null ? { nonce: originalNonce, safe_tx_hash: noopDigest } : {}) });
|
|
367
|
+
}
|
|
368
|
+
return null;
|
|
369
|
+
};
|
|
370
|
+
const adoptById = async (id) => {
|
|
371
|
+
const read = await api("GET", `${SAFE_INVALIDATION_ROUTE_PREFIX}/${id}?account_id=${encodeURIComponent(accountId)}`);
|
|
372
|
+
if (failed(read)) {
|
|
373
|
+
if (httpStatus(read) === 404) {
|
|
374
|
+
return refuse("safe_invalidation_child_not_found", "Felix has no such invalidation for this account; nothing was signed.");
|
|
375
|
+
}
|
|
376
|
+
if (definitiveRefusal(read)) {
|
|
377
|
+
return refuse(reasonOf(read) || "safe_invalidation_child_unreadable", "Felix would not read the invalidation; nothing was signed.", { server_error: errorRecord(read) });
|
|
378
|
+
}
|
|
379
|
+
return pending("safe_invalidation_child_unavailable", "The existing invalidation could not be read; nothing was signed.");
|
|
380
|
+
}
|
|
381
|
+
return adoptChild(assertChildView(read, id));
|
|
382
|
+
};
|
|
383
|
+
/** This account's invalidations that are not closed (bounded, passive), or null when unreadable. */
|
|
384
|
+
const openChildren = async () => {
|
|
385
|
+
const found = [];
|
|
386
|
+
let after = null;
|
|
387
|
+
for (let page = 0; page < MAX_CHILD_LIST_PAGES; page += 1) {
|
|
388
|
+
const listed = await api("GET", `${SAFE_INVALIDATION_ROUTE_PREFIX}?account_id=${encodeURIComponent(accountId)}`
|
|
389
|
+
+ `&limit=50${after ? `&after=${after}` : ""}`);
|
|
390
|
+
if (failed(listed) || !Array.isArray(listed.operations))
|
|
391
|
+
return null;
|
|
392
|
+
for (const view of listed.operations) {
|
|
393
|
+
const v = assertChildView(view, null);
|
|
394
|
+
if (v.original_journey_closed !== true || bindChild(v) === "match")
|
|
395
|
+
found.push(v);
|
|
396
|
+
}
|
|
397
|
+
const next = typeof listed.next_cursor === "string" ? listed.next_cursor.toLowerCase() : null;
|
|
398
|
+
if (!next)
|
|
399
|
+
return found;
|
|
400
|
+
if (!UUID.test(next) || next === after)
|
|
401
|
+
hostile("the invalidation list cursor is invalid");
|
|
402
|
+
after = next;
|
|
403
|
+
}
|
|
404
|
+
return found;
|
|
405
|
+
};
|
|
406
|
+
if (requestedChild) {
|
|
407
|
+
const adopted = await adoptById(requestedChild);
|
|
408
|
+
if (adopted)
|
|
409
|
+
return adopted;
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
// -------- prepare (idempotent by key): verify the child before journaling it
|
|
413
|
+
const response = await api("POST", `${SAFE_INVALIDATION_ROUTE_PREFIX}/prepare`, withAccount({ original_writer: writer, original_operation_id: originalId }), { idempotencyKey: deps.stageKey("safe-invalidation-prepare") });
|
|
414
|
+
if (failed(response)) {
|
|
415
|
+
// An engine that NAMES the existing child for this original: adopt exactly it.
|
|
416
|
+
const named = String(errorRecord(response).invalidation_id || "").toLowerCase();
|
|
417
|
+
if (UUID.test(named)) {
|
|
418
|
+
const adopted = await adoptById(named);
|
|
419
|
+
if (adopted)
|
|
420
|
+
return adopted;
|
|
421
|
+
}
|
|
422
|
+
else if (definitiveRefusal(response)) {
|
|
423
|
+
return refuse(reasonOf(response) || "safe_invalidation_prepare_refused", "Felix did not prepare the invalidation; nothing was signed.", { server_error: errorRecord(response) });
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
// A bare 5xx: either transient, or the one-child-per-nonce refusal. Look for the child.
|
|
427
|
+
const children = await openChildren();
|
|
428
|
+
const matches = (children ?? []).filter((v) => bindChild(v) === "match");
|
|
429
|
+
const unknown = (children ?? []).filter((v) => bindChild(v) === "unknown");
|
|
430
|
+
if (matches.length === 1) {
|
|
431
|
+
const adopted = adoptChild(matches[0]);
|
|
432
|
+
if (adopted)
|
|
433
|
+
return adopted;
|
|
434
|
+
}
|
|
435
|
+
else if (matches.length > 1 || unknown.length > 0) {
|
|
436
|
+
const listed = [...matches, ...unknown].map((v) => ({
|
|
437
|
+
invalidation_id: String(v.invalidation_id).toLowerCase(), phase: v.phase,
|
|
438
|
+
original_journey_closed: v.original_journey_closed === true,
|
|
439
|
+
...(childFacts(v).nonce !== null ? { safe_nonce: childFacts(v).nonce } : {}),
|
|
440
|
+
}));
|
|
441
|
+
const one = listed.length === 1 ? listed[0] : null;
|
|
442
|
+
return refuse("safe_invalidation_child_exists", one
|
|
443
|
+
? "Felix already holds an invalidation that is not complete, and it keeps one per Safe nonce, so a new "
|
|
444
|
+
+ "one cannot be prepared. Nothing was signed. Complete that invalidation: call invalidate_safe_nonce "
|
|
445
|
+
+ "with the same original_writer and original_operation_id plus invalidation_id, under a NEW "
|
|
446
|
+
+ "idempotency_key. It is bound to this operation before anything is signed."
|
|
447
|
+
: "Felix holds more than one incomplete invalidation for this account, and this client cannot tell "
|
|
448
|
+
+ "which one holds this operation's nonce. Nothing was signed. Contact support with these ids.", { next_action: one ? "complete_invalidation" : "contact_support", existing_invalidations: listed,
|
|
449
|
+
server_error: errorRecord(response),
|
|
450
|
+
...(one ? { safe_nonce_invalidation: invalidationSuggestion(writer, originalId, originalNonce, "Complete the invalidation Felix already holds for this Safe nonce.", one.invalidation_id) } : {}) });
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
return pending("safe_invalidation_prepare_unavailable", "Felix could not prepare the invalidation now (it refuses while the Safe's current nonce is not the "
|
|
454
|
+
+ "original's reserved nonce, or while Arc admission is paused). Nothing was signed; retry with the same key.", { server_error: errorRecord(response) });
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
const child = assertChildView(response, null);
|
|
460
|
+
const invalidationId = String(child.invalidation_id).toLowerCase();
|
|
461
|
+
if (child.phase === "prepared") {
|
|
462
|
+
const plan = verifyNoopChild(child.typed_data, { safe, owner, nonce: originalNonce });
|
|
463
|
+
deps.saveCheckpoint(CP.prepared, { invalidation_id: invalidationId, nonce: plan.nonce,
|
|
464
|
+
safe_tx_hash: plan.safeTxHash, typed_data: plan.typedData });
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
// Replayed after another client journal signed it: follow it, never sign again.
|
|
468
|
+
deps.saveCheckpoint(CP.prepared, { invalidation_id: invalidationId, adopted: true,
|
|
469
|
+
...(originalNonce !== null ? { nonce: originalNonce,
|
|
470
|
+
safe_tx_hash: arcSafeTxHash(noopInvalidationTypedData(safe, owner, originalNonce)).toLowerCase() } : {}) });
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
const prepared = deps.getCheckpoint(CP.prepared);
|
|
476
|
+
const invalidationId = String(prepared.invalidation_id);
|
|
477
|
+
const base = `${SAFE_INVALIDATION_ROUTE_PREFIX}/${invalidationId}`;
|
|
478
|
+
const knownNonce = typeof prepared.nonce === "number" ? prepared.nonce : null;
|
|
479
|
+
const knownDigest = typeof prepared.safe_tx_hash === "string" ? prepared.safe_tx_hash : null;
|
|
480
|
+
// -------- sign once: fresh read, own on-chain proof of the nonce, journal the bytes
|
|
481
|
+
if (!deps.getCheckpoint(CP.signed) && !prepared.adopted && !deps.getCheckpoint(CP.executed)) {
|
|
482
|
+
const read = await api("GET", `${base}?account_id=${encodeURIComponent(accountId)}`);
|
|
483
|
+
if (failed(read)) {
|
|
484
|
+
if (httpStatus(read) === 404)
|
|
485
|
+
hostile("the server lost the invalidation it prepared");
|
|
486
|
+
return pending("safe_invalidation_read_unavailable", "The invalidation could not be re-read; nothing was signed.");
|
|
487
|
+
}
|
|
488
|
+
const current = assertChildView(read, invalidationId);
|
|
489
|
+
if (current.phase === "prepared") {
|
|
490
|
+
const again = verifyNoopChild(current.typed_data, { safe, owner, nonce: knownNonce });
|
|
491
|
+
if (again.safeTxHash !== knownDigest)
|
|
492
|
+
hostile("the server changed the invalidation SafeTx");
|
|
493
|
+
let proven = false;
|
|
494
|
+
let proofCode = null;
|
|
495
|
+
try {
|
|
496
|
+
proven = (await deps.policy.verifySafeState(safe, Number(knownNonce))) === true;
|
|
497
|
+
}
|
|
498
|
+
catch (error) {
|
|
499
|
+
proven = false;
|
|
500
|
+
proofCode = typeof error?.code === "string" ? String(error.code) : null;
|
|
501
|
+
}
|
|
502
|
+
if (!proven) {
|
|
503
|
+
return refuse("safe_invalidation_safe_state_unverified", "This client could not prove on its own Arc quorum that the Safe is this owner's and that its current "
|
|
504
|
+
+ "nonce is the reserved nonce; nothing was signed.", { proof_error: proofCode });
|
|
505
|
+
}
|
|
506
|
+
const signature = await deps.signSafeTx(prepared.typed_data);
|
|
507
|
+
if (!SIGNATURE.test(signature))
|
|
508
|
+
return refuse("client_signing_failed", "The local signature is malformed; nothing was sent.");
|
|
509
|
+
deps.saveCheckpoint(CP.signed, { invalidation_id: invalidationId, safe_tx_hash: knownDigest,
|
|
510
|
+
signature: signature.toLowerCase(), signed_at_ms: deps.now() });
|
|
511
|
+
}
|
|
512
|
+
// A child already past "prepared" was signed elsewhere; it is only followed.
|
|
513
|
+
}
|
|
514
|
+
const signed = deps.getCheckpoint(CP.signed);
|
|
515
|
+
if (signed && (signed.invalidation_id !== invalidationId || signed.safe_tx_hash !== knownDigest)) {
|
|
516
|
+
hostile("the journaled signature is for another invalidation");
|
|
517
|
+
}
|
|
518
|
+
// -------- submit the SAME bytes at most once per invocation; reconcile to a proof
|
|
519
|
+
let offered = false;
|
|
520
|
+
let lastReason = null;
|
|
521
|
+
let executed = deps.getCheckpoint(CP.executed);
|
|
522
|
+
while (!executed) {
|
|
523
|
+
if (outOfBudget()) {
|
|
524
|
+
return pending("safe_invalidation_pending", "The invalidation has not executed yet; resume with the same key.", { signed: Boolean(signed), server_reason: lastReason });
|
|
525
|
+
}
|
|
526
|
+
polls += 1;
|
|
527
|
+
// Every second poll asks whether the ORIGINAL executed instead (a race the no-op then loses).
|
|
528
|
+
const probeOriginal = polls % 2 === 0;
|
|
529
|
+
const current = await api("POST", `${base}/reconcile`, withAccount(probeOriginal ? { original: true } : {}), { retryOnError: true });
|
|
530
|
+
if (failed(current)) {
|
|
531
|
+
if (httpStatus(current) === 404)
|
|
532
|
+
hostile("the server lost the invalidation");
|
|
533
|
+
await pause();
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
const view = assertChildView(current, invalidationId);
|
|
537
|
+
const phase = String(view.phase);
|
|
538
|
+
if (isRecord(view.evidence) && typeof view.evidence.reason === "string")
|
|
539
|
+
lastReason = view.evidence.reason;
|
|
540
|
+
if (phase === "prepared") {
|
|
541
|
+
if (signed && !offered) {
|
|
542
|
+
offered = true;
|
|
543
|
+
if (!deps.getCheckpoint(CP.offered))
|
|
544
|
+
deps.saveCheckpoint(CP.offered, { invalidation_id: invalidationId });
|
|
545
|
+
const submitted = await api("POST", `${base}/submit`, withAccount({ signature: String(signed.signature) }), { retryOnError: false });
|
|
546
|
+
if (failed(submitted) && definitiveRefusal(submitted)) {
|
|
547
|
+
return result(false, "submit_refused", {
|
|
548
|
+
signed: true, next_action: "resume_with_same_idempotency_key", server_error: errorRecord(submitted),
|
|
549
|
+
error: { code: reasonOf(submitted) || "safe_invalidation_submit_refused",
|
|
550
|
+
message: "Felix did not accept the signed invalidation now (for example while Arc admission is "
|
|
551
|
+
+ "paused). The signature is journaled; resume with the same key to offer the SAME bytes again." },
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
if (!signed) {
|
|
557
|
+
return pending("safe_invalidation_unsigned", "The invalidation is prepared but this client holds no signature for it.");
|
|
558
|
+
}
|
|
559
|
+
await pause();
|
|
560
|
+
continue;
|
|
561
|
+
}
|
|
562
|
+
if (phase === "original_executed") {
|
|
563
|
+
const final = result(false, "original_executed", {
|
|
564
|
+
signed: Boolean(signed), original_executed: true, original_journey_closed: false,
|
|
565
|
+
next_action: "resume_original_operation", resume_tool: ORIGINAL_TOOL[writer],
|
|
566
|
+
error: { code: "safe_invalidation_original_executed",
|
|
567
|
+
message: "The ORIGINAL Safe transaction executed at the reserved nonce before the no-op, so it was "
|
|
568
|
+
+ "not invalidated and nothing was closed. Resume the original operation with its own tool and "
|
|
569
|
+
+ "idempotency key; it settles from its own proof." },
|
|
570
|
+
});
|
|
571
|
+
deps.saveCheckpoint(CP.completed, { result: final });
|
|
572
|
+
return final;
|
|
573
|
+
}
|
|
574
|
+
if (phase === "invalidated") {
|
|
575
|
+
const evidence = isRecord(view.evidence) ? view.evidence : {};
|
|
576
|
+
const proof = isRecord(evidence.proof) ? evidence.proof : {};
|
|
577
|
+
const txHash = String(proof.tx_hash || "").toLowerCase();
|
|
578
|
+
const proofDigest = String(proof.safe_tx_hash || "").toLowerCase();
|
|
579
|
+
if (!HASH.test(txHash) || proof.state !== "verified" || proof.success !== true
|
|
580
|
+
|| (knownDigest !== null && proofDigest !== knownDigest)) {
|
|
581
|
+
hostile("the invalidation proof is not this client's no-op execution");
|
|
582
|
+
}
|
|
583
|
+
let verified = false;
|
|
584
|
+
if (knownDigest !== null && knownNonce !== null) {
|
|
585
|
+
try {
|
|
586
|
+
verified = (await deps.policy.verifyNoopExecuted({ safe, safeTxHash: knownDigest, signedNonce: knownNonce,
|
|
587
|
+
executionTx: txHash })) === true;
|
|
588
|
+
}
|
|
589
|
+
catch {
|
|
590
|
+
verified = false;
|
|
591
|
+
}
|
|
592
|
+
if (!verified) {
|
|
593
|
+
await pause();
|
|
594
|
+
continue;
|
|
595
|
+
} // no own proof yet: keep reconciling
|
|
596
|
+
}
|
|
597
|
+
executed = { invalidation_id: invalidationId, tx_hash: txHash, client_verified: verified };
|
|
598
|
+
deps.saveCheckpoint(CP.executed, executed);
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
await pause(); // signed / submitted_unknown / reconciliation_required (execution_proof_pending ...)
|
|
602
|
+
}
|
|
603
|
+
// -------- close the original on the proven execution (idempotent on Felix)
|
|
604
|
+
const txHash = String(executed.tx_hash);
|
|
605
|
+
const closePath = writer === "withdrawal_source" ? `${base}/close-withdrawal` : `${base}/close-relay`;
|
|
606
|
+
const closeBody = writer === "withdrawal_source"
|
|
607
|
+
? withAccount({ operation_id: originalId, transaction_hash: txHash, outcome: "invalidated" })
|
|
608
|
+
: withAccount({ writer, funding_id: originalId, transaction_hash: txHash, outcome: "invalidated" });
|
|
609
|
+
let attempted = false;
|
|
610
|
+
for (;;) {
|
|
611
|
+
// A proven execution always gets at least one close attempt in this call.
|
|
612
|
+
if (attempted && outOfBudget()) {
|
|
613
|
+
return result(false, "invalidated", {
|
|
614
|
+
signed: Boolean(signed), safe_nonce_released: true, original_journey_closed: false,
|
|
615
|
+
invalidation_tx_hash: txHash, client_verified: executed.client_verified === true,
|
|
616
|
+
next_action: "resume_with_same_idempotency_key",
|
|
617
|
+
error: { code: "safe_invalidation_close_pending",
|
|
618
|
+
message: "The no-op executed: the original can never execute and the Safe is free for new Felix "
|
|
619
|
+
+ "operations. Felix has not closed the original journey yet; resume with the same key." },
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
polls += 1;
|
|
623
|
+
attempted = true;
|
|
624
|
+
const closed = await api("POST", closePath, closeBody, { retryOnError: true });
|
|
625
|
+
if (failed(closed)) {
|
|
626
|
+
if (definitiveRefusal(closed)) {
|
|
627
|
+
return result(false, "invalidated", {
|
|
628
|
+
signed: Boolean(signed), safe_nonce_released: true, original_journey_closed: false,
|
|
629
|
+
invalidation_tx_hash: txHash, client_verified: executed.client_verified === true,
|
|
630
|
+
next_action: "contact_support", server_error: errorRecord(closed),
|
|
631
|
+
error: { code: reasonOf(closed) || "safe_invalidation_close_refused",
|
|
632
|
+
message: "The no-op executed (the Safe is free), but Felix refused to close the original journey. "
|
|
633
|
+
+ "Contact support with the invalidation id; do not sign anything else for it." },
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
await pause();
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
const view = assertChildView(closed, invalidationId);
|
|
640
|
+
const closure = isRecord(view.evidence) && isRecord(view.evidence.writer_closure)
|
|
641
|
+
? view.evidence.writer_closure : null;
|
|
642
|
+
if (view.original_journey_closed !== true || !closure || String(closure.operation_id || "").toLowerCase() !== originalId
|
|
643
|
+
|| closure.writer !== writer || closure.outcome !== "invalidated"
|
|
644
|
+
|| String(closure.tx_hash || "").toLowerCase() !== txHash) {
|
|
645
|
+
hostile("the closure is not this invalidation's closure of the original");
|
|
646
|
+
}
|
|
647
|
+
if (!TERMINAL_CHILD.has(String(view.phase)))
|
|
648
|
+
hostile("a closed invalidation is not terminal");
|
|
649
|
+
const final = result(true, "completed", {
|
|
650
|
+
signed: Boolean(signed), safe_nonce_released: true, original_journey_closed: true,
|
|
651
|
+
invalidation_tx_hash: txHash, client_verified: executed.client_verified === true,
|
|
652
|
+
closure, next_action: "none",
|
|
653
|
+
});
|
|
654
|
+
deps.saveCheckpoint(CP.completed, { result: final });
|
|
655
|
+
return final;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
catch (error) {
|
|
659
|
+
if (error instanceof SafeInvalidationHostileServer) {
|
|
660
|
+
return result(false, "reconciliation_required", {
|
|
661
|
+
signed: Boolean(deps.getCheckpoint(CP.signed)), reconciliation_required: true,
|
|
662
|
+
next_action: deps.getCheckpoint(CP.signed) ? "resume_with_same_idempotency_key" : "contact_support",
|
|
663
|
+
error: { code: "safe_invalidation_server_untrusted", message: error.message },
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
const message = String(error?.message || error).slice(0, 200);
|
|
667
|
+
if (deps.getCheckpoint(CP.signed)) {
|
|
668
|
+
return pending("safe_invalidation_client_failed_after_signing", message);
|
|
669
|
+
}
|
|
670
|
+
return refuse("safe_invalidation_client_failed", message);
|
|
671
|
+
}
|
|
672
|
+
}
|