@lumenwipe/verify 0.1.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -7,6 +7,51 @@ release is cut.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0] - 2026-11-10
11
+
12
+ ### Added
13
+
14
+ - `verifyRevokeAllowanceTransaction(unsignedXdr, networkPassphrase, expected, nowSeconds?)`,
15
+ compiled from the web's allowance-revocation trust anchor, with the documented input type
16
+ `RevokeAllowanceExpectation` (`owner`, `token`, `spender`).
17
+ - `RevokeAllowanceVerificationError`, whose `name` is `"RevokeAllowanceVerificationError"` and
18
+ whose `code` is one stable `RevokeAllowanceVerificationErrorCode` per refusal reason. Branch on
19
+ the code: the message is English wording and may change. An envelope that cannot be decoded is
20
+ refused with `VerificationError` and its existing code.
21
+ - `vectors/revoke-allowance-v1.json`, exported as `@lumenwipe/verify/vectors/revoke-allowance-v1.json`:
22
+ two accepted revocations (a contract and an account spender) and a rejected mutation for every
23
+ refusal code, plus one envelope the decoder refuses.
24
+
25
+ The bundled exchange and contract registries are unchanged.
26
+
27
+ ## [0.2.0] - 2026-11-08
28
+
29
+ ### Added
30
+
31
+ - Three vectors in `vectors/close-v1.json` for a multisig close's first transaction, signer
32
+ normalization with no merge: `multisig-normalization-first`, accepted, and its rejected
33
+ mutations `normalization-first-threshold-raised` and `normalization-first-signer-added`.
34
+ - Two `VerificationErrorCode` values: `registry_memo_type_conflict` and
35
+ `registry_memo_type_unconfirmed`.
36
+ - Vectors for a snapshot that changes a memo type: `exchange-close-with-numeric-text-memo`,
37
+ accepted, its rejected mutations `snapshot-changes-exchange-memo-type` and
38
+ `snapshot-disputes-exchange-memo-type`, and
39
+ `snapshot-memo-type-other-than-confirmed`, a rejected mutation of
40
+ `close-to-exchange-listed-by-snapshot`.
41
+
42
+ ### Changed
43
+
44
+ - A served registry snapshot no longer decides a memo type. A bundled exchange the snapshot
45
+ lists with a different `memoType` is refused with `registry_memo_type_conflict`, where the
46
+ snapshot's type used to be adopted. For an address only the snapshot lists, the type the user
47
+ confirmed is checked, and a snapshot type that differs from it is refused with
48
+ `registry_memo_type_unconfirmed`, where it used to replace the confirmed type. A memo with
49
+ no readable confirmed type to such an address is refused with `memo_type_unreadable`, where
50
+ the snapshot's type used to be filled in.
51
+ - The vector `close-to-exchange-listed-by-snapshot` now confirms an id memo, the snapshot's
52
+ type, instead of text, and the description of its mutation `memo-type-other-than-snapshot`
53
+ says so. Its code and message are unchanged.
54
+
10
55
  ## [0.1.0] - 2026-11-08
11
56
 
12
57
  ### Added
@@ -34,5 +79,7 @@ release is cut.
34
79
  is optional, and a rejection may mutate the snapshot instead of, or with, the transaction.
35
80
  - The package ships its `LICENSE` and this `CHANGELOG.md`.
36
81
 
37
- [Unreleased]: https://github.com/LumenWipe/lumenwipe/compare/verify-v0.1.0...HEAD
82
+ [Unreleased]: https://github.com/LumenWipe/lumenwipe/compare/verify-v0.3.0...HEAD
83
+ [0.3.0]: https://github.com/LumenWipe/lumenwipe/compare/verify-v0.2.0...verify-v0.3.0
84
+ [0.2.0]: https://github.com/LumenWipe/lumenwipe/compare/verify-v0.1.0...verify-v0.2.0
38
85
  [0.1.0]: https://github.com/LumenWipe/lumenwipe/tree/verify-v0.1.0
package/README.md CHANGED
@@ -10,6 +10,11 @@ It is not a port. The bundle is compiled from the web's own
10
10
  conformance vector set (`vectors/close-v1.json`) runs against this package and against the web
11
11
  verifier in CI.
12
12
 
13
+ It also ships the web's trust anchor for an allowance revocation,
14
+ `verifyRevokeAllowanceTransaction`, compiled from
15
+ [`verify-revoke-allowance.ts`](https://github.com/LumenWipe/lumenwipe/blob/main/apps/web/lib/stellar/verify-revoke-allowance.ts)
16
+ with its own vector set (`vectors/revoke-allowance-v1.json`).
17
+
13
18
  ## Install
14
19
 
15
20
  ```bash
@@ -92,8 +97,7 @@ because it can only make verification stricter:
92
97
  - A bundled exchange is never removed, and its memo requirement and its refusal of a direct
93
98
  merge are never turned off.
94
99
  - An address the snapshot adds is checked as an exchange: a direct merge into it is refused if it
95
- needs the intermediary, a memo is required if it needs one (in the snapshot's memo type), and a
96
- transfer to it is refused.
100
+ needs the intermediary, a memo is required if it needs one, and a transfer to it is refused.
97
101
  - It never enables the mediated hand-off: that stays limited to the exchanges bundled here
98
102
  (`requiresMediator`, which takes no snapshot). An address only the snapshot lists as needing the
99
103
  intermediary refuses both a direct merge and the hand-off until you upgrade. Accepting the
@@ -104,10 +108,13 @@ because it can only make verification stricter:
104
108
  `entries` list, or no `lastVerified` or `validUntil` string) is refused with
105
109
  `registry_snapshot_invalid` rather than ignored.
106
110
 
107
- Two fields are taken from it rather than tightened, as in the web app: an entry's `memoType`
108
- (exchanges do move from text to id memos) and its `name`, used only in refusal messages. A
109
- wrong memo type can leave a deposit uncredited; it cannot send funds anywhere the user did not
110
- choose.
111
+ - It never decides a memo type, because a memo sent under the wrong type reaches the exchange
112
+ and is credited to nobody. A bundled exchange it lists with a different `memoType` refuses the
113
+ close with `registry_memo_type_conflict` until you upgrade. For an address only the snapshot
114
+ lists, the type the user confirmed is the one checked, and a snapshot type that differs from
115
+ it refuses the close with `registry_memo_type_unconfirmed`.
116
+
117
+ An entry's `name` is taken from it, as in the web app, and used only in refusal messages.
111
118
 
112
119
  Without a snapshot:
113
120
 
@@ -119,6 +126,34 @@ Without a snapshot:
119
126
  `verifyCloseTransaction` also reads the system clock for the transaction's expiry: a transaction
120
127
  valid for more than 900 seconds from now is refused.
121
128
 
129
+ ## Revoking an allowance
130
+
131
+ `verifyRevokeAllowanceTransaction` checks an API-built revocation before the signature: exactly
132
+ one `approve(owner, spender, 0, expiration)` on the token, sourced from the owner, with no memo,
133
+ a fee of at most 10,000,000 stroops, valid for at most 900 seconds, authorized only by the
134
+ owner's own source account and naming no other account or contract. Pass the allowance your
135
+ screen showed, never values read from the transaction:
136
+
137
+ ```ts
138
+ import {
139
+ RevokeAllowanceVerificationError,
140
+ verifyRevokeAllowanceTransaction,
141
+ } from "@lumenwipe/verify";
142
+ import { Networks } from "@stellar/stellar-sdk";
143
+
144
+ try {
145
+ verifyRevokeAllowanceTransaction(unsignedXdr, Networks.PUBLIC, { owner, token, spender });
146
+ } catch (error) {
147
+ if (error instanceof RevokeAllowanceVerificationError) console.error(error.code);
148
+ throw error;
149
+ }
150
+ ```
151
+
152
+ It throws `RevokeAllowanceVerificationError` with a stable `code`
153
+ (`RevokeAllowanceVerificationErrorCode`), or `VerificationError` when the envelope cannot be
154
+ decoded at all. The optional fourth argument is the current Unix time in seconds; it defaults to
155
+ the system clock.
156
+
122
157
  ## Conformance vectors
123
158
 
124
159
  `vectors/close-v1.json` (schema 1) lists accepted and rejected transactions with the full
@@ -131,6 +166,11 @@ this one:
131
166
  import vectors from "@lumenwipe/verify/vectors/close-v1.json" with { type: "json" };
132
167
  ```
133
168
 
169
+ `vectors/revoke-allowance-v1.json` (schema 1) does the same for
170
+ `verifyRevokeAllowanceTransaction`: each vector gives the envelope, the network passphrase, the
171
+ expectation and `nowSeconds` to pass as the fourth argument, and for a rejection the error
172
+ `class`, `code` and exact `message`.
173
+
134
174
  ## License
135
175
 
136
176
  Apache-2.0
package/dist/index.cjs CHANGED
@@ -187,9 +187,10 @@ function tightenedOver(embeddedEntry, servedEntry) {
187
187
  ...servedEntry,
188
188
  requiresMemo: embeddedEntry.requiresMemo || servedEntry.requiresMemo,
189
189
  requiresMediator: embeddedEntry.requiresMediator || servedEntry.requiresMediator,
190
- // A memo type may be corrected (text -> id is a real, common change) but only while the
191
- // requirement itself stands; it cannot be used to smuggle in "no memo".
192
- memoType: servedEntry.memoType
190
+ // Never taken from the served copy. A memo sent under the wrong type reaches the right
191
+ // address and is credited to nobody, so a served type that differs is recorded as a dispute
192
+ // (`mergeServedRegistry`) and the close is refused until the bundled copy is updated.
193
+ memoType: embeddedEntry.memoType
193
194
  };
194
195
  }
195
196
  var MAX_EXTENSION_DAYS = 120;
@@ -209,8 +210,12 @@ function mergeServedRegistry(floor, body) {
209
210
  }
210
211
  const embeddedByAddress = new Map(floor.entries.map((e) => [e.address, e]));
211
212
  const merged = new Map(embeddedByAddress);
213
+ const disputes = /* @__PURE__ */ new Set();
212
214
  for (const servedEntry of served.entries.filter(isUsableEntry)) {
213
215
  const embeddedEntry = embeddedByAddress.get(servedEntry.address);
216
+ if (embeddedEntry && embeddedEntry.memoType !== servedEntry.memoType) {
217
+ disputes.add(servedEntry.address);
218
+ }
214
219
  merged.set(
215
220
  servedEntry.address,
216
221
  embeddedEntry ? tightenedOver(embeddedEntry, servedEntry) : servedEntry
@@ -219,7 +224,8 @@ function mergeServedRegistry(floor, body) {
219
224
  return {
220
225
  entries: [...merged.values()],
221
226
  lastVerified: served.lastVerified,
222
- validUntil: boundedValidUntil(floor.validUntil, served.validUntil)
227
+ validUntil: boundedValidUntil(floor.validUntil, served.validUntil),
228
+ memoTypeDisputes: [...disputes]
223
229
  };
224
230
  }
225
231
  function isUsableAt(validUntil, now) {
@@ -253,6 +259,9 @@ function lookupExchange(address) {
253
259
  function mediatorAllowedFor(address) {
254
260
  return EMBEDDED.entries.find((e) => e.address === address)?.requiresMediator === true;
255
261
  }
262
+ function memoTypeInDispute(address) {
263
+ return current.memoTypeDisputes?.includes(address) ?? false;
264
+ }
256
265
  function collectAddress(address, into) {
257
266
  switch (address.type) {
258
267
  case "scAddressTypeAccount":
@@ -1448,7 +1457,7 @@ function depositAddressesOf(transfers, lookup) {
1448
1457
  }
1449
1458
  function registryView(served) {
1450
1459
  if (served === void 0) {
1451
- return { lookup: lookupExchange, usable: () => isRegistryUsable() };
1460
+ return { lookup: lookupExchange, usable: () => isRegistryUsable(), memoTypeInDispute };
1452
1461
  }
1453
1462
  const merged = mergeServedRegistry(bundledRegistry(), served);
1454
1463
  if (merged === null) {
@@ -1458,11 +1467,30 @@ function registryView(served) {
1458
1467
  );
1459
1468
  }
1460
1469
  const byAddress2 = new Map(merged.entries.map((e) => [e.address, e]));
1470
+ const disputes = new Set(merged.memoTypeDisputes);
1461
1471
  return {
1462
1472
  lookup: (address) => byAddress2.get(address) ?? null,
1463
- usable: () => isUsableAt(merged.validUntil, /* @__PURE__ */ new Date())
1473
+ usable: () => isUsableAt(merged.validUntil, /* @__PURE__ */ new Date()),
1474
+ memoTypeInDispute: (address) => disputes.has(address)
1464
1475
  };
1465
1476
  }
1477
+ function listedMemoType(exchange, registry, expected) {
1478
+ if (registry.memoTypeInDispute(expected.destination)) {
1479
+ throw new VerificationError(
1480
+ "registry_memo_type_conflict",
1481
+ `The served exchange registry gives ${exchange.name} a different memo type than the bundled one, so the memo this close needs cannot be checked.`
1482
+ );
1483
+ }
1484
+ const bundled = bundledRegistry().entries.some((e) => e.address === expected.destination);
1485
+ if (bundled) return exchange.memoType;
1486
+ if (expected.memo !== null && expected.memoType !== null && expected.memoType !== exchange.memoType) {
1487
+ throw new VerificationError(
1488
+ "registry_memo_type_unconfirmed",
1489
+ `The served exchange registry lists ${exchange.name} with ${MEMO_TYPE_WITH_ARTICLE[exchange.memoType]} memo, not the ${expected.memoType} memo you confirmed.`
1490
+ );
1491
+ }
1492
+ return expected.memoType;
1493
+ }
1466
1494
  function verifyCloseTransaction(opts) {
1467
1495
  const intent = intentFromXdr(opts.unsignedXdr, NETWORK_PASSPHRASES[opts.network]);
1468
1496
  const registry = registryView(opts.servedRegistry);
@@ -1483,7 +1511,7 @@ function verifyCloseTransaction(opts) {
1483
1511
  mediatorRequired: mediatorAllowedFor(opts.expected.destination),
1484
1512
  directMergeRefused: exchange?.requiresMediator ?? false,
1485
1513
  memoRequired: exchange?.requiresMemo ?? false,
1486
- memoType: exchange?.memoType ?? opts.expected.memoType,
1514
+ memoType: exchange === null ? opts.expected.memoType : listedMemoType(exchange, registry, opts.expected),
1487
1515
  nowSeconds: Math.floor(Date.now() / 1e3),
1488
1516
  preAuthorized: opts.preAuthorized === true
1489
1517
  });
@@ -2327,6 +2355,112 @@ function exitExpectations(accountState, network) {
2327
2355
  };
2328
2356
  }
2329
2357
 
2358
+ // ../../apps/web/lib/stellar/verify-revoke-allowance.ts
2359
+ var MAX_REVOKE_FEE_STROOPS = BigInt(1e7);
2360
+ var MAX_VALIDITY_SECONDS2 = BigInt(900);
2361
+ var RevokeAllowanceVerificationError = class extends Error {
2362
+ constructor(code, message) {
2363
+ super(message);
2364
+ this.name = "RevokeAllowanceVerificationError";
2365
+ this.code = code;
2366
+ }
2367
+ };
2368
+ function fail(code, message) {
2369
+ throw new RevokeAllowanceVerificationError(code, message);
2370
+ }
2371
+ function verifyRevokeAllowanceTransaction(xdr2, networkPassphrase, expected, nowSeconds = Math.floor(Date.now() / 1e3)) {
2372
+ const intent = intentFromXdr(xdr2, networkPassphrase);
2373
+ const maxTime = intent.maxTime ?? null;
2374
+ if (maxTime === null || !/^\d+$/.test(maxTime)) {
2375
+ fail(
2376
+ "revoke_expiry_missing",
2377
+ "This transaction never expires, so it could be submitted long after you approved it."
2378
+ );
2379
+ }
2380
+ if (BigInt(maxTime) > BigInt(Math.floor(nowSeconds)) + MAX_VALIDITY_SECONDS2) {
2381
+ fail(
2382
+ "revoke_expiry_too_far",
2383
+ "This transaction stays valid for far longer than a revocation needs."
2384
+ );
2385
+ }
2386
+ if (intent.source !== expected.owner) {
2387
+ fail(
2388
+ "revoke_transaction_source_mismatch",
2389
+ "This transaction is not sourced from the account being revoked for."
2390
+ );
2391
+ }
2392
+ if (intent.memo !== null) {
2393
+ fail("revoke_memo_present", "This transaction carries a memo, which a revocation never needs.");
2394
+ }
2395
+ if (BigInt(intent.fee) > MAX_REVOKE_FEE_STROOPS) {
2396
+ fail(
2397
+ "revoke_fee_above_cap",
2398
+ "This transaction's fee is higher than a revocation should ever need."
2399
+ );
2400
+ }
2401
+ if (intent.operations.length !== 1) {
2402
+ fail(
2403
+ "revoke_operation_count",
2404
+ `This transaction has ${intent.operations.length} operations; a revocation has exactly one.`
2405
+ );
2406
+ }
2407
+ const op = intent.operations[0];
2408
+ if (op.source !== expected.owner) {
2409
+ fail(
2410
+ "revoke_operation_source_mismatch",
2411
+ "The operation does not act as the account being revoked for."
2412
+ );
2413
+ }
2414
+ if (op.type !== "invoke_host_function") {
2415
+ fail("revoke_not_invocation", "This transaction does not invoke a contract.");
2416
+ }
2417
+ if (op.contract !== expected.token) {
2418
+ fail("revoke_token_mismatch", "This transaction does not touch the expected token contract.");
2419
+ }
2420
+ if (op.function !== "approve") {
2421
+ fail(
2422
+ "revoke_function_not_approve",
2423
+ "This transaction does not call approve, so it is not a revocation."
2424
+ );
2425
+ }
2426
+ if (op.args.length !== 4 || op.args[0] !== expected.owner || op.args[1] !== expected.spender || op.args[2] !== "0") {
2427
+ fail(
2428
+ "revoke_approve_args_mismatch",
2429
+ "This transaction does not revoke the expected spender's allowance on this token."
2430
+ );
2431
+ }
2432
+ if (op.authorizesBeyondSelf) {
2433
+ fail(
2434
+ "revoke_auth_beyond_self",
2435
+ "This transaction authorizes more than the account's own revocation."
2436
+ );
2437
+ }
2438
+ if (op.authDepth !== 0) {
2439
+ fail(
2440
+ "revoke_auth_nested",
2441
+ "This transaction authorizes a nested call, which a plain revocation never needs."
2442
+ );
2443
+ }
2444
+ if (op.unsupportedAddressCount > 0) {
2445
+ fail(
2446
+ "revoke_address_unsupported",
2447
+ "This transaction references an address form that cannot be verified."
2448
+ );
2449
+ }
2450
+ if (op.accountsReferenced.some((a) => a !== expected.owner && a !== expected.spender)) {
2451
+ fail(
2452
+ "revoke_foreign_account",
2453
+ "This transaction references an account other than the one being revoked for."
2454
+ );
2455
+ }
2456
+ if (op.contractsReferenced.some((c) => c !== expected.token && c !== expected.spender)) {
2457
+ fail(
2458
+ "revoke_foreign_contract",
2459
+ "This transaction references a contract other than the token or the spender."
2460
+ );
2461
+ }
2462
+ }
2463
+
2330
2464
  // src/index.ts
2331
2465
  function verifyCloseTransaction2(input) {
2332
2466
  verifyCloseTransaction(input);
@@ -2337,8 +2471,13 @@ function exitExpectations2(accountState, network) {
2337
2471
  function requiresMediator(address) {
2338
2472
  return mediatorAllowedFor(address);
2339
2473
  }
2474
+ function verifyRevokeAllowanceTransaction2(unsignedXdr, networkPassphrase, expected, nowSeconds) {
2475
+ verifyRevokeAllowanceTransaction(unsignedXdr, networkPassphrase, expected, nowSeconds);
2476
+ }
2340
2477
 
2478
+ exports.RevokeAllowanceVerificationError = RevokeAllowanceVerificationError;
2341
2479
  exports.VerificationError = VerificationError;
2342
2480
  exports.exitExpectations = exitExpectations2;
2343
2481
  exports.requiresMediator = requiresMediator;
2344
2482
  exports.verifyCloseTransaction = verifyCloseTransaction2;
2483
+ exports.verifyRevokeAllowanceTransaction = verifyRevokeAllowanceTransaction2;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * `@lumenwipe/verify`: the verifier the LumenWipe web app runs before every signature, compiled
3
- * from the web's own modules rather than copied. There is one implementation; this file only
3
+ * from the web's own modules rather than copied, together with the web's trust anchor for an
4
+ * allowance revocation. There is one implementation; this file only
4
5
  * gives it explicit, documented types. `tests/types.test.ts` pins every type below to the web
5
6
  * signature in both directions, so a change on either side fails the build.
6
7
  *
@@ -182,8 +183,9 @@ export declare interface CloseExpectationInput extends ExitExpectations {
182
183
  nativeBalance: string;
183
184
  /** The memo the user confirmed, or null. */
184
185
  memo: string | null;
185
- /** The type the user confirmed for `memo`, or null with no memo. A listed exchange's registry
186
- * type replaces it. */
186
+ /** The type the user confirmed for `memo`, or null with no memo. The bundled registry's type
187
+ * replaces it for an exchange the bundle lists; a served registry's type that differs from it
188
+ * is refused (`registry_memo_type_unconfirmed`), never adopted. */
187
189
  memoType: "text" | "id" | "hash" | null;
188
190
  /** Canonical `CODE:ISSUER` of each trustline a claimable balance claim may add and remove. */
189
191
  claimTrustlineAssets: string[];
@@ -433,6 +435,40 @@ declare interface PoolShareEntry {
433
435
  */
434
436
  export declare function requiresMediator(address: string): boolean;
435
437
 
438
+ /**
439
+ * Every reason the revocation anchor refuses a transaction, one stable code each, in the order the
440
+ * checks run. The code is the contract an integrator branches on; the message is the current
441
+ * English wording and may change. Each code carries a `revoke_` prefix so it never shares a value
442
+ * with a close `VerificationErrorCode`.
443
+ */
444
+ declare const REVOKE_ALLOWANCE_VERIFICATION_ERROR_CODES: readonly ["revoke_expiry_missing", "revoke_expiry_too_far", "revoke_transaction_source_mismatch", "revoke_memo_present", "revoke_fee_above_cap", "revoke_operation_count", "revoke_operation_source_mismatch", "revoke_not_invocation", "revoke_token_mismatch", "revoke_function_not_approve", "revoke_approve_args_mismatch", "revoke_auth_beyond_self", "revoke_auth_nested", "revoke_address_unsupported", "revoke_foreign_account", "revoke_foreign_contract"];
445
+
446
+ /**
447
+ * What the screen showed the user before they approved an allowance revocation: the allowance
448
+ * the revocation must zero, and nothing else. Every value is one the integrator already displayed,
449
+ * never one read from the transaction under verification.
450
+ */
451
+ export declare interface RevokeAllowanceExpectation {
452
+ /** The account whose allowance is revoked. The transaction and its one operation must be
453
+ * sourced from it, and it is the only account the call may authorize. */
454
+ owner: string;
455
+ /** The token contract (`C...`) `approve` is called on. */
456
+ token: string;
457
+ /** The spender whose allowance goes to zero: a contract (`C...`) or, less often, an account
458
+ * (`G...`). */
459
+ spender: string;
460
+ }
461
+
462
+ /** Thrown when a server-built allowance revocation fails verification. Never sign past this. */
463
+ export declare class RevokeAllowanceVerificationError extends Error {
464
+ /** Why the transaction was refused. Stable across releases, unlike the message. */
465
+ readonly code: RevokeAllowanceVerificationErrorCode;
466
+ constructor(code: RevokeAllowanceVerificationErrorCode, message: string);
467
+ }
468
+
469
+ /** The reason a {@link RevokeAllowanceVerificationError} was thrown. */
470
+ export declare type RevokeAllowanceVerificationErrorCode = (typeof REVOKE_ALLOWANCE_VERIFICATION_ERROR_CODES)[number];
471
+
436
472
  /**
437
473
  * A served exchange registry: the body of `GET /v1/config/exchange-registry` (the SDK's
438
474
  * `client.getExchangeRegistry()`), passed as is. Only these three fields are read.
@@ -448,10 +484,12 @@ export declare function requiresMediator(address: string): boolean;
448
484
  * registry lists ({@link requiresMediator}), so an address only the snapshot lists as needing
449
485
  * the intermediary refuses both shapes until this package is updated.
450
486
  * - Its `validUntil` may move the bundled expiry later, by at most 120 days, never earlier.
487
+ * - It never decides a memo type. A different type for a bundled exchange is refused with
488
+ * `registry_memo_type_conflict`, and a type for an address it adds that differs from the one
489
+ * the user confirmed is refused with `registry_memo_type_unconfirmed`. A memo sent under the
490
+ * wrong type reaches the exchange and is credited to nobody.
451
491
  *
452
- * Two fields are taken from it rather than tightened: an entry's `memoType` (exchanges do change
453
- * text to id) and `name` (only used in refusal messages). A wrong memo type can make a deposit
454
- * uncreditable, but it cannot change where funds go.
492
+ * An entry's `name` is taken from it, and only used in refusal messages.
455
493
  */
456
494
  export declare interface ServedRegistry {
457
495
  /** The listed exchanges. An entry that is not well formed is dropped. */
@@ -606,7 +644,7 @@ declare interface UnrecognizedDefiPosition {
606
644
  * that applies to several operation kinds (the fee cap, the operation source) shares one code,
607
645
  * since the kind is visible in the transaction itself.
608
646
  */
609
- declare const VERIFICATION_ERROR_CODES: readonly ["registry_expired", "registry_snapshot_invalid", "transaction_source_mismatch", "expiry_missing", "expiry_too_far", "fee_unreadable", "fee_above_cap", "operation_unknown", "operation_source_mismatch", "merge_multiple", "merge_direct_refused", "merge_destination_mismatch", "mediator_handoff_shape", "mediator_forward_source_mismatch", "mediator_forward_destination_mismatch", "mediator_forward_not_native", "mediator_forward_short", "transfer_not_chosen", "transfer_destination_mismatch", "transfer_to_deposit_address", "transfer_duplicate", "transfer_amount_short", "token_transfer_function_invalid", "token_transfer_from_mismatch", "token_transfer_foreign_contract", "conversion_recipient_mismatch", "conversion_not_to_xlm", "conversion_min_out_missing", "conversion_asset_not_chosen", "conversion_duplicate", "conversion_min_out_below_floor", "conversion_amount_short", "swap_quote_missing", "swap_args_unreadable", "swap_referral_recipient", "swap_route_asset_unknown", "swap_auth_unexpected_call", "swap_auth_exceeds_amount", "trustline_not_removal", "data_entry_not_removal", "offer_not_cancellation", "signer_added", "signer_unknown", "master_weight_changed", "thresholds_raised", "account_settings_changed", "invocation_not_alone", "invocation_auth_beyond_self", "invocation_address_unsupported", "invocation_foreign_account", "exit_contract_not_position", "exit_expectation_inconsistent", "exit_function_not_allowed", "exit_foreign_contract", "exit_argument_party_mismatch", "exit_request_not_allowed", "exit_unverified_spend", "exit_spend_not_repay", "exit_liquidity_auth_invalid", "exit_auth_foreign_contract", "exit_token_function_not_allowed", "exit_token_argument_count", "exit_token_recipient_mismatch", "memo_unexpected", "memo_type_unreadable", "memo_missing", "memo_value_mismatch", "memo_type_mismatch", "memo_required", "memo_invalid_text"];
647
+ declare const VERIFICATION_ERROR_CODES: readonly ["registry_expired", "registry_snapshot_invalid", "registry_memo_type_conflict", "registry_memo_type_unconfirmed", "transaction_source_mismatch", "expiry_missing", "expiry_too_far", "fee_unreadable", "fee_above_cap", "operation_unknown", "operation_source_mismatch", "merge_multiple", "merge_direct_refused", "merge_destination_mismatch", "mediator_handoff_shape", "mediator_forward_source_mismatch", "mediator_forward_destination_mismatch", "mediator_forward_not_native", "mediator_forward_short", "transfer_not_chosen", "transfer_destination_mismatch", "transfer_to_deposit_address", "transfer_duplicate", "transfer_amount_short", "token_transfer_function_invalid", "token_transfer_from_mismatch", "token_transfer_foreign_contract", "conversion_recipient_mismatch", "conversion_not_to_xlm", "conversion_min_out_missing", "conversion_asset_not_chosen", "conversion_duplicate", "conversion_min_out_below_floor", "conversion_amount_short", "swap_quote_missing", "swap_args_unreadable", "swap_referral_recipient", "swap_route_asset_unknown", "swap_auth_unexpected_call", "swap_auth_exceeds_amount", "trustline_not_removal", "data_entry_not_removal", "offer_not_cancellation", "signer_added", "signer_unknown", "master_weight_changed", "thresholds_raised", "account_settings_changed", "invocation_not_alone", "invocation_auth_beyond_self", "invocation_address_unsupported", "invocation_foreign_account", "exit_contract_not_position", "exit_expectation_inconsistent", "exit_function_not_allowed", "exit_foreign_contract", "exit_argument_party_mismatch", "exit_request_not_allowed", "exit_unverified_spend", "exit_spend_not_repay", "exit_liquidity_auth_invalid", "exit_auth_foreign_contract", "exit_token_function_not_allowed", "exit_token_argument_count", "exit_token_recipient_mismatch", "memo_unexpected", "memo_type_unreadable", "memo_missing", "memo_value_mismatch", "memo_type_mismatch", "memo_required", "memo_invalid_text"];
610
648
 
611
649
  /** Thrown when a server-built close transaction fails verification. Never sign past this. */
612
650
  export declare class VerificationError extends Error {
@@ -648,4 +686,27 @@ export declare interface VerifyCloseInput {
648
686
  */
649
687
  export declare function verifyCloseTransaction(input: VerifyCloseInput): void;
650
688
 
689
+ /**
690
+ * Decodes an API-built, unsigned allowance revocation and asserts it is exactly
691
+ * `approve(owner, spender, 0, expiration)` on `token`: one operation, sourced from `owner`, no
692
+ * memo, a fee of at most 10,000,000 stroops, valid for at most 900 seconds after `nowSeconds`,
693
+ * authorized only by the owner's own source account with no nested call, and naming no other
694
+ * account or contract. Returns only when the transaction may be signed.
695
+ *
696
+ * What it guarantees is that the signed transaction does what the screen said, so an API cannot
697
+ * swap the token or the spender between what was shown and what is signed. It does not judge
698
+ * whether the shown allowance is worth revoking.
699
+ *
700
+ * Throws {@link RevokeAllowanceVerificationError} with a stable `code` on any mismatch, or
701
+ * {@link VerificationError} when the envelope cannot be decoded at all (for example a text memo
702
+ * that is not valid UTF-8). Synchronous and offline: it reads no network and no page state, and
703
+ * keeps no state between calls. Run it once per transaction, immediately before the signature.
704
+ *
705
+ * @param unsignedXdr - The unsigned transaction envelope as returned by the API, base64.
706
+ * @param networkPassphrase - The passphrase of the network the revocation runs on.
707
+ * @param expected - The allowance the screen showed.
708
+ * @param nowSeconds - The current Unix time in seconds; defaults to the system clock.
709
+ */
710
+ export declare function verifyRevokeAllowanceTransaction(unsignedXdr: string, networkPassphrase: string, expected: RevokeAllowanceExpectation, nowSeconds?: number): void;
711
+
651
712
  export { }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * `@lumenwipe/verify`: the verifier the LumenWipe web app runs before every signature, compiled
3
- * from the web's own modules rather than copied. There is one implementation; this file only
3
+ * from the web's own modules rather than copied, together with the web's trust anchor for an
4
+ * allowance revocation. There is one implementation; this file only
4
5
  * gives it explicit, documented types. `tests/types.test.ts` pins every type below to the web
5
6
  * signature in both directions, so a change on either side fails the build.
6
7
  *
@@ -182,8 +183,9 @@ export declare interface CloseExpectationInput extends ExitExpectations {
182
183
  nativeBalance: string;
183
184
  /** The memo the user confirmed, or null. */
184
185
  memo: string | null;
185
- /** The type the user confirmed for `memo`, or null with no memo. A listed exchange's registry
186
- * type replaces it. */
186
+ /** The type the user confirmed for `memo`, or null with no memo. The bundled registry's type
187
+ * replaces it for an exchange the bundle lists; a served registry's type that differs from it
188
+ * is refused (`registry_memo_type_unconfirmed`), never adopted. */
187
189
  memoType: "text" | "id" | "hash" | null;
188
190
  /** Canonical `CODE:ISSUER` of each trustline a claimable balance claim may add and remove. */
189
191
  claimTrustlineAssets: string[];
@@ -433,6 +435,40 @@ declare interface PoolShareEntry {
433
435
  */
434
436
  export declare function requiresMediator(address: string): boolean;
435
437
 
438
+ /**
439
+ * Every reason the revocation anchor refuses a transaction, one stable code each, in the order the
440
+ * checks run. The code is the contract an integrator branches on; the message is the current
441
+ * English wording and may change. Each code carries a `revoke_` prefix so it never shares a value
442
+ * with a close `VerificationErrorCode`.
443
+ */
444
+ declare const REVOKE_ALLOWANCE_VERIFICATION_ERROR_CODES: readonly ["revoke_expiry_missing", "revoke_expiry_too_far", "revoke_transaction_source_mismatch", "revoke_memo_present", "revoke_fee_above_cap", "revoke_operation_count", "revoke_operation_source_mismatch", "revoke_not_invocation", "revoke_token_mismatch", "revoke_function_not_approve", "revoke_approve_args_mismatch", "revoke_auth_beyond_self", "revoke_auth_nested", "revoke_address_unsupported", "revoke_foreign_account", "revoke_foreign_contract"];
445
+
446
+ /**
447
+ * What the screen showed the user before they approved an allowance revocation: the allowance
448
+ * the revocation must zero, and nothing else. Every value is one the integrator already displayed,
449
+ * never one read from the transaction under verification.
450
+ */
451
+ export declare interface RevokeAllowanceExpectation {
452
+ /** The account whose allowance is revoked. The transaction and its one operation must be
453
+ * sourced from it, and it is the only account the call may authorize. */
454
+ owner: string;
455
+ /** The token contract (`C...`) `approve` is called on. */
456
+ token: string;
457
+ /** The spender whose allowance goes to zero: a contract (`C...`) or, less often, an account
458
+ * (`G...`). */
459
+ spender: string;
460
+ }
461
+
462
+ /** Thrown when a server-built allowance revocation fails verification. Never sign past this. */
463
+ export declare class RevokeAllowanceVerificationError extends Error {
464
+ /** Why the transaction was refused. Stable across releases, unlike the message. */
465
+ readonly code: RevokeAllowanceVerificationErrorCode;
466
+ constructor(code: RevokeAllowanceVerificationErrorCode, message: string);
467
+ }
468
+
469
+ /** The reason a {@link RevokeAllowanceVerificationError} was thrown. */
470
+ export declare type RevokeAllowanceVerificationErrorCode = (typeof REVOKE_ALLOWANCE_VERIFICATION_ERROR_CODES)[number];
471
+
436
472
  /**
437
473
  * A served exchange registry: the body of `GET /v1/config/exchange-registry` (the SDK's
438
474
  * `client.getExchangeRegistry()`), passed as is. Only these three fields are read.
@@ -448,10 +484,12 @@ export declare function requiresMediator(address: string): boolean;
448
484
  * registry lists ({@link requiresMediator}), so an address only the snapshot lists as needing
449
485
  * the intermediary refuses both shapes until this package is updated.
450
486
  * - Its `validUntil` may move the bundled expiry later, by at most 120 days, never earlier.
487
+ * - It never decides a memo type. A different type for a bundled exchange is refused with
488
+ * `registry_memo_type_conflict`, and a type for an address it adds that differs from the one
489
+ * the user confirmed is refused with `registry_memo_type_unconfirmed`. A memo sent under the
490
+ * wrong type reaches the exchange and is credited to nobody.
451
491
  *
452
- * Two fields are taken from it rather than tightened: an entry's `memoType` (exchanges do change
453
- * text to id) and `name` (only used in refusal messages). A wrong memo type can make a deposit
454
- * uncreditable, but it cannot change where funds go.
492
+ * An entry's `name` is taken from it, and only used in refusal messages.
455
493
  */
456
494
  export declare interface ServedRegistry {
457
495
  /** The listed exchanges. An entry that is not well formed is dropped. */
@@ -606,7 +644,7 @@ declare interface UnrecognizedDefiPosition {
606
644
  * that applies to several operation kinds (the fee cap, the operation source) shares one code,
607
645
  * since the kind is visible in the transaction itself.
608
646
  */
609
- declare const VERIFICATION_ERROR_CODES: readonly ["registry_expired", "registry_snapshot_invalid", "transaction_source_mismatch", "expiry_missing", "expiry_too_far", "fee_unreadable", "fee_above_cap", "operation_unknown", "operation_source_mismatch", "merge_multiple", "merge_direct_refused", "merge_destination_mismatch", "mediator_handoff_shape", "mediator_forward_source_mismatch", "mediator_forward_destination_mismatch", "mediator_forward_not_native", "mediator_forward_short", "transfer_not_chosen", "transfer_destination_mismatch", "transfer_to_deposit_address", "transfer_duplicate", "transfer_amount_short", "token_transfer_function_invalid", "token_transfer_from_mismatch", "token_transfer_foreign_contract", "conversion_recipient_mismatch", "conversion_not_to_xlm", "conversion_min_out_missing", "conversion_asset_not_chosen", "conversion_duplicate", "conversion_min_out_below_floor", "conversion_amount_short", "swap_quote_missing", "swap_args_unreadable", "swap_referral_recipient", "swap_route_asset_unknown", "swap_auth_unexpected_call", "swap_auth_exceeds_amount", "trustline_not_removal", "data_entry_not_removal", "offer_not_cancellation", "signer_added", "signer_unknown", "master_weight_changed", "thresholds_raised", "account_settings_changed", "invocation_not_alone", "invocation_auth_beyond_self", "invocation_address_unsupported", "invocation_foreign_account", "exit_contract_not_position", "exit_expectation_inconsistent", "exit_function_not_allowed", "exit_foreign_contract", "exit_argument_party_mismatch", "exit_request_not_allowed", "exit_unverified_spend", "exit_spend_not_repay", "exit_liquidity_auth_invalid", "exit_auth_foreign_contract", "exit_token_function_not_allowed", "exit_token_argument_count", "exit_token_recipient_mismatch", "memo_unexpected", "memo_type_unreadable", "memo_missing", "memo_value_mismatch", "memo_type_mismatch", "memo_required", "memo_invalid_text"];
647
+ declare const VERIFICATION_ERROR_CODES: readonly ["registry_expired", "registry_snapshot_invalid", "registry_memo_type_conflict", "registry_memo_type_unconfirmed", "transaction_source_mismatch", "expiry_missing", "expiry_too_far", "fee_unreadable", "fee_above_cap", "operation_unknown", "operation_source_mismatch", "merge_multiple", "merge_direct_refused", "merge_destination_mismatch", "mediator_handoff_shape", "mediator_forward_source_mismatch", "mediator_forward_destination_mismatch", "mediator_forward_not_native", "mediator_forward_short", "transfer_not_chosen", "transfer_destination_mismatch", "transfer_to_deposit_address", "transfer_duplicate", "transfer_amount_short", "token_transfer_function_invalid", "token_transfer_from_mismatch", "token_transfer_foreign_contract", "conversion_recipient_mismatch", "conversion_not_to_xlm", "conversion_min_out_missing", "conversion_asset_not_chosen", "conversion_duplicate", "conversion_min_out_below_floor", "conversion_amount_short", "swap_quote_missing", "swap_args_unreadable", "swap_referral_recipient", "swap_route_asset_unknown", "swap_auth_unexpected_call", "swap_auth_exceeds_amount", "trustline_not_removal", "data_entry_not_removal", "offer_not_cancellation", "signer_added", "signer_unknown", "master_weight_changed", "thresholds_raised", "account_settings_changed", "invocation_not_alone", "invocation_auth_beyond_self", "invocation_address_unsupported", "invocation_foreign_account", "exit_contract_not_position", "exit_expectation_inconsistent", "exit_function_not_allowed", "exit_foreign_contract", "exit_argument_party_mismatch", "exit_request_not_allowed", "exit_unverified_spend", "exit_spend_not_repay", "exit_liquidity_auth_invalid", "exit_auth_foreign_contract", "exit_token_function_not_allowed", "exit_token_argument_count", "exit_token_recipient_mismatch", "memo_unexpected", "memo_type_unreadable", "memo_missing", "memo_value_mismatch", "memo_type_mismatch", "memo_required", "memo_invalid_text"];
610
648
 
611
649
  /** Thrown when a server-built close transaction fails verification. Never sign past this. */
612
650
  export declare class VerificationError extends Error {
@@ -648,4 +686,27 @@ export declare interface VerifyCloseInput {
648
686
  */
649
687
  export declare function verifyCloseTransaction(input: VerifyCloseInput): void;
650
688
 
689
+ /**
690
+ * Decodes an API-built, unsigned allowance revocation and asserts it is exactly
691
+ * `approve(owner, spender, 0, expiration)` on `token`: one operation, sourced from `owner`, no
692
+ * memo, a fee of at most 10,000,000 stroops, valid for at most 900 seconds after `nowSeconds`,
693
+ * authorized only by the owner's own source account with no nested call, and naming no other
694
+ * account or contract. Returns only when the transaction may be signed.
695
+ *
696
+ * What it guarantees is that the signed transaction does what the screen said, so an API cannot
697
+ * swap the token or the spender between what was shown and what is signed. It does not judge
698
+ * whether the shown allowance is worth revoking.
699
+ *
700
+ * Throws {@link RevokeAllowanceVerificationError} with a stable `code` on any mismatch, or
701
+ * {@link VerificationError} when the envelope cannot be decoded at all (for example a text memo
702
+ * that is not valid UTF-8). Synchronous and offline: it reads no network and no page state, and
703
+ * keeps no state between calls. Run it once per transaction, immediately before the signature.
704
+ *
705
+ * @param unsignedXdr - The unsigned transaction envelope as returned by the API, base64.
706
+ * @param networkPassphrase - The passphrase of the network the revocation runs on.
707
+ * @param expected - The allowance the screen showed.
708
+ * @param nowSeconds - The current Unix time in seconds; defaults to the system clock.
709
+ */
710
+ export declare function verifyRevokeAllowanceTransaction(unsignedXdr: string, networkPassphrase: string, expected: RevokeAllowanceExpectation, nowSeconds?: number): void;
711
+
651
712
  export { }