@lumenwipe/verify 0.7.0 → 0.9.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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Asset, TransactionBuilder, getLiquidityPoolId, Address, StrKey, scValToNative } from '@stellar/stellar-sdk';
1
+ import { Asset, TransactionBuilder, getLiquidityPoolId, Address, StrKey, Keypair, scValToNative } from '@stellar/stellar-sdk';
2
2
 
3
3
  // ../../apps/web/lib/stellar/verify.ts
4
4
 
@@ -185,6 +185,142 @@ var exchange_registry_default = {
185
185
  ]
186
186
  };
187
187
 
188
+ // ../../apps/api/src/config/exchange-registry.sig.json
189
+ var exchange_registry_sig_default = {
190
+ format: 1,
191
+ sequence: 1,
192
+ issuedAt: "2026-11-27",
193
+ signature: "nQ6wwF1KWDUlrOXa9eagarWoRz4DfOj57njy0uBBQpnvGUv+CjlW+PgNGLf3ZwqxKKh90/U2Gbqa1KbNqMl8AQ=="
194
+ };
195
+
196
+ // ../../apps/web/lib/exchange-registry/canonical.ts
197
+ function canonicalJson(value) {
198
+ if (typeof value === "string") return JSON.stringify(value);
199
+ if (typeof value === "boolean") return value ? "true" : "false";
200
+ if (typeof value === "number") {
201
+ if (!Number.isSafeInteger(value) || Object.is(value, -0)) {
202
+ throw new Error("A canonical payload holds only safe integers.");
203
+ }
204
+ return String(value);
205
+ }
206
+ if (Array.isArray(value)) return `[${Array.from(value, canonicalJson).join(",")}]`;
207
+ if (typeof value === "object" && value !== null) {
208
+ const proto = Object.getPrototypeOf(value);
209
+ if (proto !== Object.prototype && proto !== null) {
210
+ throw new Error("A canonical payload holds only plain objects.");
211
+ }
212
+ const record = value;
213
+ const members = Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(record[key])}`);
214
+ return `{${members.join(",")}}`;
215
+ }
216
+ throw new Error(
217
+ "A canonical payload holds only objects, arrays, strings, booleans and integers."
218
+ );
219
+ }
220
+
221
+ // ../../apps/web/lib/exchange-registry/signature.ts
222
+ var SIGNING_LABEL = "lumenwipe.exchange-registry.signature.v1";
223
+ var SIGNATURE_FORMAT = 1;
224
+ var REGISTRY_FIELDS = [
225
+ "version",
226
+ "lastVerified",
227
+ "validUntil",
228
+ "source",
229
+ "entries"
230
+ ];
231
+ var DAY_MS = 864e5;
232
+ var ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
233
+ var BASE64 = /^[A-Za-z0-9+/]{86}==$/;
234
+ function isDay(value) {
235
+ if (typeof value !== "string" || !ISO_DAY.test(value)) return false;
236
+ const ms = Date.parse(`${value}T00:00:00Z`);
237
+ return Number.isFinite(ms) && new Date(ms).toISOString().startsWith(value);
238
+ }
239
+ function parseSignature(raw) {
240
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return null;
241
+ const r = raw;
242
+ const keys = Object.keys(r).sort().join(",");
243
+ if (keys !== "format,issuedAt,sequence,signature") return null;
244
+ if (r.format !== SIGNATURE_FORMAT) return null;
245
+ if (typeof r.sequence !== "number" || !Number.isSafeInteger(r.sequence) || r.sequence < 1) {
246
+ return null;
247
+ }
248
+ if (!isDay(r.issuedAt)) return null;
249
+ if (typeof r.signature !== "string" || !BASE64.test(r.signature)) return null;
250
+ return {
251
+ format: SIGNATURE_FORMAT,
252
+ sequence: r.sequence,
253
+ issuedAt: r.issuedAt,
254
+ signature: r.signature
255
+ };
256
+ }
257
+ function registryProjection(body) {
258
+ if (typeof body !== "object" || body === null) return null;
259
+ const source = body;
260
+ const projection = {};
261
+ for (const field of REGISTRY_FIELDS) {
262
+ if (!(field in source)) return null;
263
+ projection[field] = source[field];
264
+ }
265
+ return projection;
266
+ }
267
+ function signingBytes(registry, meta) {
268
+ const projection = registryProjection(registry);
269
+ if (projection === null) return null;
270
+ try {
271
+ const text = canonicalJson({
272
+ format: SIGNATURE_FORMAT,
273
+ issuedAt: meta.issuedAt,
274
+ registry: projection,
275
+ sequence: meta.sequence
276
+ });
277
+ return new TextEncoder().encode(`${SIGNING_LABEL}
278
+ ${text}`);
279
+ } catch {
280
+ return null;
281
+ }
282
+ }
283
+ function decodeSignature(encoded) {
284
+ try {
285
+ const raw = atob(encoded);
286
+ const bytes = Uint8Array.from(raw, (c) => c.charCodeAt(0));
287
+ return bytes.length === 64 && btoa(raw) === encoded ? bytes : null;
288
+ } catch {
289
+ return null;
290
+ }
291
+ }
292
+ function verifiesUnderAny(keys, bytes, signature) {
293
+ return keys.some((key) => {
294
+ try {
295
+ return Keypair.fromPublicKey(key).verify(bytes, signature);
296
+ } catch {
297
+ return false;
298
+ }
299
+ });
300
+ }
301
+ function verifyRegistrySignature(body, envelope, context) {
302
+ const parsed = parseSignature(envelope);
303
+ const bytes = parsed === null ? null : signingBytes(body, parsed);
304
+ const signature = parsed === null ? null : decodeSignature(parsed.signature);
305
+ if (parsed === null || bytes === null || signature === null) {
306
+ return { ok: false, reason: "malformed" };
307
+ }
308
+ if (!verifiesUnderAny(context.keys, bytes, signature)) {
309
+ return { ok: false, reason: "bad-signature" };
310
+ }
311
+ if (parsed.sequence < context.bundledSequence) return { ok: false, reason: "stale-sequence" };
312
+ const { validUntil } = body;
313
+ const until = typeof validUntil === "string" ? validUntil : "";
314
+ if (!isDay(until) || Date.parse(`${until}T23:59:59Z`) < context.now.getTime()) {
315
+ return { ok: false, reason: "expired" };
316
+ }
317
+ const issued = Date.parse(`${parsed.issuedAt}T00:00:00Z`);
318
+ if (issued > context.now.getTime() + DAY_MS || parsed.issuedAt > until) {
319
+ return { ok: false, reason: "future-dated" };
320
+ }
321
+ return { ok: true, sequence: parsed.sequence };
322
+ }
323
+
188
324
  // ../../apps/web/lib/exchange-registry/merge.ts
189
325
  function appliesOn(entry, network) {
190
326
  return entry.network === void 0 || entry.network === network;
@@ -249,19 +385,54 @@ function mergeServedRegistry(floor, body) {
249
385
  memoTypeDisputes: [...disputes]
250
386
  };
251
387
  }
388
+ function resolveServedRegistry(floor, body, context) {
389
+ const merged = mergeServedRegistry(floor, body);
390
+ if (merged === null) return null;
391
+ const envelope = body.signature;
392
+ const verdict = verifyRegistrySignature(body, envelope, context);
393
+ if (!verdict.ok) return { ...merged, trust: "unsigned", sequence: null, mediatedAdditions: [] };
394
+ const bundled = new Set(floor.entries.map((e) => e.address));
395
+ return {
396
+ ...merged,
397
+ trust: "signed",
398
+ sequence: verdict.sequence,
399
+ mediatedAdditions: merged.entries.filter((e) => !bundled.has(e.address) && e.requiresMediator).map((e) => e.address)
400
+ };
401
+ }
402
+ function mediatedByAddition(registry, address, network) {
403
+ if (!registry.mediatedAdditions?.includes(address)) return false;
404
+ return registry.entries.some(
405
+ (e) => e.address === address && e.requiresMediator && appliesOn(e, network)
406
+ );
407
+ }
252
408
  function isUsableAt(validUntil, now) {
253
409
  const until = Date.parse(`${validUntil}T23:59:59Z`);
254
410
  return Number.isFinite(until) && now.getTime() <= until;
255
411
  }
256
412
 
413
+ // ../../apps/web/lib/exchange-registry/trust-roots.ts
414
+ var REGISTRY_SIGNING_KEYS = [
415
+ "GAKGKRCTIPJIFS4UAL6TZEXW3ZUUYBFBPBAVNG37NKILQQ5ZSW3VGDTK",
416
+ "GAOXVNB4UHWUOXDLSQXTPUJUZWRHKO35ZP5P5XZNPESMEIPUL3X66PDD"
417
+ ];
418
+
257
419
  // ../../apps/web/lib/exchange-registry/index.ts
420
+ var BUNDLED_SIGNATURE = parseSignature(exchange_registry_sig_default);
421
+ if (BUNDLED_SIGNATURE === null) {
422
+ throw new Error("The bundled exchange registry signature is malformed.");
423
+ }
258
424
  var EMBEDDED = {
259
425
  entries: bundledEntries(exchange_registry_default.entries),
260
426
  lastVerified: exchange_registry_default.lastVerified,
261
427
  validUntil: exchange_registry_default.validUntil,
262
- served: false
428
+ served: false,
429
+ trust: "bundled",
430
+ sequence: BUNDLED_SIGNATURE.sequence
263
431
  };
264
432
  var current = EMBEDDED;
433
+ function pinnedRegistryTrust() {
434
+ return { keys: REGISTRY_SIGNING_KEYS, bundledSequence: EMBEDDED.sequence };
435
+ }
265
436
  function bundledRegistry() {
266
437
  return EMBEDDED;
267
438
  }
@@ -278,7 +449,7 @@ function bundledExchange(address, network) {
278
449
  return EMBEDDED.entries.find((e) => e.address === address && appliesOn(e, network)) ?? null;
279
450
  }
280
451
  function mediatorAllowedFor(address, network) {
281
- return bundledExchange(address, network)?.requiresMediator === true;
452
+ return bundledExchange(address, network)?.requiresMediator === true || mediatedByAddition(current, address, network);
282
453
  }
283
454
  function memoTypeInDispute(address) {
284
455
  return current.memoTypeDisputes?.includes(address) ?? false;
@@ -958,11 +1129,22 @@ function readSwapArgs(fn, args) {
958
1129
  const min = integer(args[4]);
959
1130
  if (!CONTRACT_ID.test(token) || !CONTRACT_ID.test(assetOut)) return null;
960
1131
  if (amountIn === null || min === null) return null;
961
- if (args[6] !== "null") return null;
1132
+ if (args[6] !== "null" && !isZeroFeePartner(args[6] ?? "")) return null;
962
1133
  return { token, assetOut, amountIn, destination: args[0] ?? "", minAmountOut: min };
963
1134
  }
964
1135
  return null;
965
1136
  }
1137
+ function isZeroFeePartner(rendered) {
1138
+ let parsed;
1139
+ try {
1140
+ parsed = JSON.parse(rendered);
1141
+ } catch {
1142
+ return false;
1143
+ }
1144
+ if (typeof parsed !== "object" || parsed === null) return false;
1145
+ const { id } = parsed;
1146
+ return typeof id === "string" && rendered === JSON.stringify({ bps: 0, id });
1147
+ }
966
1148
  var XBULL_SWAP_FUNCTION = "strict_send";
967
1149
  function readXBullSwapArgs(args) {
968
1150
  if (args.length !== 6) return null;
@@ -1718,15 +1900,17 @@ function depositAddressesOf(transfers, lookup) {
1718
1900
  }
1719
1901
  return listed;
1720
1902
  }
1721
- function registryView(served, network) {
1903
+ function registryView(served, network, trust) {
1722
1904
  if (served === void 0) {
1723
1905
  return {
1724
1906
  lookup: (address) => lookupExchange(address, network),
1725
1907
  usable: () => isRegistryUsable(),
1726
- memoTypeInDispute
1908
+ memoTypeInDispute,
1909
+ mediatorAllowed: (address) => mediatorAllowedFor(address, network)
1727
1910
  };
1728
1911
  }
1729
- const merged = mergeServedRegistry(bundledRegistry(), served);
1912
+ const bundled = bundledRegistry();
1913
+ const merged = resolveServedRegistry(bundled, served, { ...trust, now: /* @__PURE__ */ new Date() });
1730
1914
  if (merged === null) {
1731
1915
  throw new VerificationError(
1732
1916
  "registry_snapshot_invalid",
@@ -1740,9 +1924,13 @@ function registryView(served, network) {
1740
1924
  return {
1741
1925
  lookup: (address) => byAddress2.get(address) ?? null,
1742
1926
  usable: () => isUsableAt(merged.validUntil, /* @__PURE__ */ new Date()),
1743
- memoTypeInDispute: (address) => disputes.has(address)
1927
+ memoTypeInDispute: (address) => disputes.has(address),
1928
+ mediatorAllowed: (address) => bundledExchange(address, network)?.requiresMediator === true || mediatedByAddition(merged, address, network)
1744
1929
  };
1745
1930
  }
1931
+ function mediatorAllowedUnder(destination, network, served) {
1932
+ return registryView(served, network, pinnedRegistryTrust()).mediatorAllowed(destination);
1933
+ }
1746
1934
  function listedMemoType(exchange, registry, network, expected) {
1747
1935
  if (registry.memoTypeInDispute(expected.destination)) {
1748
1936
  throw new VerificationError(
@@ -1760,8 +1948,11 @@ function listedMemoType(exchange, registry, network, expected) {
1760
1948
  return expected.memoType;
1761
1949
  }
1762
1950
  function verifyCloseTransaction(opts) {
1951
+ verifyCloseWith(opts, pinnedRegistryTrust());
1952
+ }
1953
+ function verifyCloseWith(opts, trust) {
1763
1954
  const intent = intentFromXdr(opts.unsignedXdr, NETWORK_PASSPHRASES[opts.network]);
1764
- const registry = registryView(opts.servedRegistry, opts.network);
1955
+ const registry = registryView(opts.servedRegistry, opts.network, trust);
1765
1956
  const exchange = registry.lookup(opts.expected.destination);
1766
1957
  if (exchange !== null && !registry.usable()) {
1767
1958
  throw new VerificationError(
@@ -1775,8 +1966,7 @@ function verifyCloseTransaction(opts) {
1775
1966
  [...Object.values(opts.expected.transfers), ...Object.values(opts.expected.tokenTransfers)],
1776
1967
  registry.lookup
1777
1968
  ),
1778
- // From the bundled copy alone, whatever was served: see `registryView`.
1779
- mediatorRequired: mediatorAllowedFor(opts.expected.destination, opts.network),
1969
+ mediatorRequired: registry.mediatorAllowed(opts.expected.destination),
1780
1970
  directMergeRefused: exchange?.requiresMediator ?? false,
1781
1971
  memoRequired: exchange?.requiresMemo ?? false,
1782
1972
  memoType: exchange === null ? opts.expected.memoType : listedMemoType(exchange, registry, opts.network, opts.expected),
@@ -2179,13 +2369,13 @@ var contract_registry_default = {
2179
2369
  protocol: "aquarius",
2180
2370
  kind: "router",
2181
2371
  address: "CBQDHNBFBZYE4MKPWBSJOPIYLW4SFSXAXUTSXJN76GNKYVYPCKWC6QUK",
2182
- wasmHash: "c99539b023df4a28d7857d33ca4c915c2e20fec04f12b125132b84fbdf94dad3",
2372
+ wasmHash: "2f8e7d7f237eca17e188c4e5d08b73b0065584b3d39f9e1d801993a8510a3107",
2183
2373
  version: "v1",
2184
- label: "Aquarius AMM router (mainnet, docs.aqua.network; stellar.expert: 'Aquarius Router') - enumerates the pools; never a call target of an exit; hash re-verified 2026-10-02 after an upstream upgrade (interface unchanged)",
2374
+ label: "Aquarius AMM router (mainnet, docs.aqua.network; stellar.expert: 'Aquarius Router') - enumerates the pools; never a call target of an exit; re-pinned 2026-11-25 after an upstream upgrade (every earlier function unchanged; swap_split, get_reward_token and get_reward_token_count added)",
2185
2375
  verifiedLive: true,
2186
- verifiedBy: "2026-11-06: readLiveWasmHash over RPC (mainnet.sorobanrpc.com) returned this hash, unchanged (#713); 2026-10-10: address matched against docs.aqua.network addresses-and-networks and live hash compared in the full registry re-verification (#581); 2026-11-17: live executable hash re-read over public RPC and matched (#1008)",
2376
+ verifiedBy: "2026-10-10 (#581): address matched against docs.aqua.network; 2026-11-25 (#1121): re-pinned after commit_upgrade tx 060f587341861b30d3c434b62d49d36ed006fe987b535a5771a3165d162ef7ae (ledger 65560332) and apply_upgrade tx 0169293062a1177282f3ddd8ea3ad7f8418bb3404b54a5b1bbe870c7ffaef3ae (ledger 65663788), each signed 2 of 3 by the router's Admin account; plain Wasm, version() 222; no public source, so trusted by spec and host-import diff and a live read of all 392 pools",
2187
2377
  source: "docs.aqua.network/developers/reference/addresses-and-networks; stellar.expert directory 'Aquarius Router'",
2188
- verifiedAt: "2026-11-17"
2378
+ verifiedAt: "2026-11-25"
2189
2379
  },
2190
2380
  {
2191
2381
  network: "mainnet",
@@ -2930,8 +3120,8 @@ function exitExpectations2(accountState, network) {
2930
3120
  function poolWithdrawalExpectations2(accountState) {
2931
3121
  return poolWithdrawalExpectations(accountState);
2932
3122
  }
2933
- function requiresMediator(address, network) {
2934
- return mediatorAllowedFor(address, network);
3123
+ function requiresMediator(address, network, servedRegistry) {
3124
+ return mediatorAllowedUnder(address, network, servedRegistry);
2935
3125
  }
2936
3126
  function verifyRevokeAllowanceTransaction2(unsignedXdr, networkPassphrase, expected, nowSeconds) {
2937
3127
  verifyRevokeAllowanceTransaction(unsignedXdr, networkPassphrase, expected, nowSeconds);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumenwipe/verify",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Reference verifier for LumenWipe close transactions, compiled from the web app's own trust anchor, with a conformance vector set.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -19,7 +19,8 @@
19
19
  }
20
20
  },
21
21
  "./vectors/close-v1.json": "./vectors/close-v1.json",
22
- "./vectors/revoke-allowance-v1.json": "./vectors/revoke-allowance-v1.json"
22
+ "./vectors/revoke-allowance-v1.json": "./vectors/revoke-allowance-v1.json",
23
+ "./vectors/registry-signing-v1.json": "./vectors/registry-signing-v1.json"
23
24
  },
24
25
  "files": [
25
26
  "dist",
@@ -57,6 +58,7 @@
57
58
  "type-check": "tsc --noEmit && tsc -p tests/tsconfig.json --noEmit",
58
59
  "lint": "eslint src scripts tests",
59
60
  "test": "bun run build:js && bun test tests",
61
+ "registry:check": "bun scripts/sign-registry.ts --check",
60
62
  "vectors": "bun scripts/generate-vectors.ts",
61
63
  "vectors:check": "bun scripts/generate-vectors.ts --check"
62
64
  },