@lumenwipe/verify 0.2.0 → 0.4.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 +43 -1
- package/README.md +52 -5
- package/dist/index.cjs +165 -28
- package/dist/index.d.cts +72 -5
- package/dist/index.d.ts +72 -5
- package/dist/index.js +164 -29
- package/package.json +3 -2
- package/vectors/close-v1.json +373 -0
- package/vectors/revoke-allowance-v1.json +437 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,46 @@ release is cut.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.0] - 2026-11-10
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **Breaking:** `requiresMediator(address)` is now `requiresMediator(address, network)`. The
|
|
15
|
+
network is required: a call without it is a type error, and the answer is for that network
|
|
16
|
+
only. Pass the network the close runs on, the same value you pass `verifyCloseTransaction`.
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- An exchange registry entry may carry `network: "testnet"` (`ExchangeRegistryEntry.network`).
|
|
21
|
+
Such an entry applies on testnet only. On mainnet its address is not listed: `requiresMediator`
|
|
22
|
+
answers false, and `verifyCloseTransaction` checks a close to it as a close to a plain wallet,
|
|
23
|
+
so the mediated hand-off to it is refused. A served snapshot cannot change the network a
|
|
24
|
+
bundled entry applies on, and an entry it adds with any other `network` value is dropped.
|
|
25
|
+
- The bundled exchange registry gains one testnet-only entry, "LumenWipe testnet exchange"
|
|
26
|
+
(`GB4VXLVR2DDIJUPVVY74QVPEIHINBMMXO6WUY67JUEYO42LQSDS5IMKW`), which needs the intermediary and
|
|
27
|
+
an id memo. The mainnet entries are unchanged.
|
|
28
|
+
- Three vectors in `vectors/close-v1.json`: `testnet-stand-in-close-through-intermediary`,
|
|
29
|
+
accepted on testnet; `testnet-stand-in-is-a-wallet-on-mainnet`, accepted on mainnet; and its
|
|
30
|
+
rejected mutation `testnet-stand-in-through-intermediary-on-mainnet`. These are the first
|
|
31
|
+
vectors whose `input.network` is `mainnet`.
|
|
32
|
+
|
|
33
|
+
## [0.3.0] - 2026-11-10
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- `verifyRevokeAllowanceTransaction(unsignedXdr, networkPassphrase, expected, nowSeconds?)`,
|
|
38
|
+
compiled from the web's allowance-revocation trust anchor, with the documented input type
|
|
39
|
+
`RevokeAllowanceExpectation` (`owner`, `token`, `spender`).
|
|
40
|
+
- `RevokeAllowanceVerificationError`, whose `name` is `"RevokeAllowanceVerificationError"` and
|
|
41
|
+
whose `code` is one stable `RevokeAllowanceVerificationErrorCode` per refusal reason. Branch on
|
|
42
|
+
the code: the message is English wording and may change. An envelope that cannot be decoded is
|
|
43
|
+
refused with `VerificationError` and its existing code.
|
|
44
|
+
- `vectors/revoke-allowance-v1.json`, exported as `@lumenwipe/verify/vectors/revoke-allowance-v1.json`:
|
|
45
|
+
two accepted revocations (a contract and an account spender) and a rejected mutation for every
|
|
46
|
+
refusal code, plus one envelope the decoder refuses.
|
|
47
|
+
|
|
48
|
+
The bundled exchange and contract registries are unchanged.
|
|
49
|
+
|
|
10
50
|
## [0.2.0] - 2026-11-08
|
|
11
51
|
|
|
12
52
|
### Added
|
|
@@ -62,6 +102,8 @@ release is cut.
|
|
|
62
102
|
is optional, and a rejection may mutate the snapshot instead of, or with, the transaction.
|
|
63
103
|
- The package ships its `LICENSE` and this `CHANGELOG.md`.
|
|
64
104
|
|
|
65
|
-
[Unreleased]: https://github.com/LumenWipe/lumenwipe/compare/verify-v0.
|
|
105
|
+
[Unreleased]: https://github.com/LumenWipe/lumenwipe/compare/verify-v0.4.0...HEAD
|
|
106
|
+
[0.4.0]: https://github.com/LumenWipe/lumenwipe/compare/verify-v0.3.0...verify-v0.4.0
|
|
107
|
+
[0.3.0]: https://github.com/LumenWipe/lumenwipe/compare/verify-v0.2.0...verify-v0.3.0
|
|
66
108
|
[0.2.0]: https://github.com/LumenWipe/lumenwipe/compare/verify-v0.1.0...verify-v0.2.0
|
|
67
109
|
[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
|
|
@@ -71,10 +76,16 @@ whether the merge must go through the shared intermediary are not inputs. The ve
|
|
|
71
76
|
them from the exchange registry bundled in this package, tightened by `servedRegistry` when you
|
|
72
77
|
pass one.
|
|
73
78
|
|
|
74
|
-
`requiresMediator(address)` exposes that same decision. An exchange close is one
|
|
75
|
-
holding the merge into the intermediary and the intermediary's forward, which the API
|
|
76
|
-
(`mediatorSign`). Decide whether to ask for that co-signature with
|
|
77
|
-
on the address the user typed
|
|
79
|
+
`requiresMediator(address, network)` exposes that same decision. An exchange close is one
|
|
80
|
+
transaction holding the merge into the intermediary and the intermediary's forward, which the API
|
|
81
|
+
co-signs (`mediatorSign`). Decide whether to ask for that co-signature with
|
|
82
|
+
`requiresMediator(destination, network)` on the address the user typed and the network the close
|
|
83
|
+
runs on, never from the API's response.
|
|
84
|
+
|
|
85
|
+
A registry entry may carry `"network": "testnet"`. Such an entry applies on testnet only: on
|
|
86
|
+
mainnet its address is not listed, so `requiresMediator` answers false there and the verifier
|
|
87
|
+
checks a close to it as a close to a plain wallet. An entry without the field applies on every
|
|
88
|
+
network.
|
|
78
89
|
|
|
79
90
|
## The bundled registries
|
|
80
91
|
|
|
@@ -98,8 +109,11 @@ because it can only make verification stricter:
|
|
|
98
109
|
intermediary refuses both a direct merge and the hand-off until you upgrade. Accepting the
|
|
99
110
|
hand-off on served data would let the API, which also builds the transaction and reports the
|
|
100
111
|
balance the forward is checked against, choose which closes go through an intermediary.
|
|
112
|
+
- It never changes the network a bundled exchange applies on: a testnet-only entry stays
|
|
113
|
+
unlisted on mainnet, and an entry listed on every network stays listed on both. An address it
|
|
114
|
+
adds with `"network": "testnet"` applies on testnet only.
|
|
101
115
|
- Its `validUntil` may move the bundled expiry later, by at most 120 days, and never earlier.
|
|
102
|
-
- An entry that is not well formed is dropped. A snapshot that is not a registry at all (no
|
|
116
|
+
- An entry that is not well formed (a `network` other than `"testnet"` included) is dropped. A snapshot that is not a registry at all (no
|
|
103
117
|
`entries` list, or no `lastVerified` or `validUntil` string) is refused with
|
|
104
118
|
`registry_snapshot_invalid` rather than ignored.
|
|
105
119
|
|
|
@@ -121,6 +135,34 @@ Without a snapshot:
|
|
|
121
135
|
`verifyCloseTransaction` also reads the system clock for the transaction's expiry: a transaction
|
|
122
136
|
valid for more than 900 seconds from now is refused.
|
|
123
137
|
|
|
138
|
+
## Revoking an allowance
|
|
139
|
+
|
|
140
|
+
`verifyRevokeAllowanceTransaction` checks an API-built revocation before the signature: exactly
|
|
141
|
+
one `approve(owner, spender, 0, expiration)` on the token, sourced from the owner, with no memo,
|
|
142
|
+
a fee of at most 10,000,000 stroops, valid for at most 900 seconds, authorized only by the
|
|
143
|
+
owner's own source account and naming no other account or contract. Pass the allowance your
|
|
144
|
+
screen showed, never values read from the transaction:
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import {
|
|
148
|
+
RevokeAllowanceVerificationError,
|
|
149
|
+
verifyRevokeAllowanceTransaction,
|
|
150
|
+
} from "@lumenwipe/verify";
|
|
151
|
+
import { Networks } from "@stellar/stellar-sdk";
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
verifyRevokeAllowanceTransaction(unsignedXdr, Networks.PUBLIC, { owner, token, spender });
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error instanceof RevokeAllowanceVerificationError) console.error(error.code);
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
It throws `RevokeAllowanceVerificationError` with a stable `code`
|
|
162
|
+
(`RevokeAllowanceVerificationErrorCode`), or `VerificationError` when the envelope cannot be
|
|
163
|
+
decoded at all. The optional fourth argument is the current Unix time in seconds; it defaults to
|
|
164
|
+
the system clock.
|
|
165
|
+
|
|
124
166
|
## Conformance vectors
|
|
125
167
|
|
|
126
168
|
`vectors/close-v1.json` (schema 1) lists accepted and rejected transactions with the full
|
|
@@ -133,6 +175,11 @@ this one:
|
|
|
133
175
|
import vectors from "@lumenwipe/verify/vectors/close-v1.json" with { type: "json" };
|
|
134
176
|
```
|
|
135
177
|
|
|
178
|
+
`vectors/revoke-allowance-v1.json` (schema 1) does the same for
|
|
179
|
+
`verifyRevokeAllowanceTransaction`: each vector gives the envelope, the network passphrase, the
|
|
180
|
+
expectation and `nowSeconds` to pass as the fourth argument, and for a rejection the error
|
|
181
|
+
`class`, `code` and exact `message`.
|
|
182
|
+
|
|
136
183
|
## License
|
|
137
184
|
|
|
138
185
|
Apache-2.0
|
package/dist/index.cjs
CHANGED
|
@@ -172,18 +172,36 @@ var exchange_registry_default = {
|
|
|
172
172
|
requiresMediator: true,
|
|
173
173
|
requiresMemo: true,
|
|
174
174
|
memoType: "text"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
address: "GB4VXLVR2DDIJUPVVY74QVPEIHINBMMXO6WUY67JUEYO42LQSDS5IMKW",
|
|
178
|
+
name: "LumenWipe testnet exchange",
|
|
179
|
+
domain: "lumenwipe.com",
|
|
180
|
+
requiresMediator: true,
|
|
181
|
+
requiresMemo: true,
|
|
182
|
+
memoType: "id",
|
|
183
|
+
network: "testnet"
|
|
175
184
|
}
|
|
176
185
|
]
|
|
177
186
|
};
|
|
178
187
|
|
|
179
188
|
// ../../apps/web/lib/exchange-registry/merge.ts
|
|
189
|
+
function appliesOn(entry, network) {
|
|
190
|
+
return entry.network === void 0 || entry.network === network;
|
|
191
|
+
}
|
|
180
192
|
function isUsableEntry(e) {
|
|
181
193
|
if (typeof e !== "object" || e === null) return false;
|
|
182
194
|
const r = e;
|
|
183
|
-
return typeof r.address === "string" && r.address.startsWith("G") && r.address.length === 56 && typeof r.name === "string" && typeof r.requiresMediator === "boolean" && typeof r.requiresMemo === "boolean" && (r.memoType === "text" || r.memoType === "id" || r.memoType === "hash");
|
|
195
|
+
return typeof r.address === "string" && r.address.startsWith("G") && r.address.length === 56 && typeof r.name === "string" && typeof r.requiresMediator === "boolean" && typeof r.requiresMemo === "boolean" && (r.memoType === "text" || r.memoType === "id" || r.memoType === "hash") && (!("network" in r) || r.network === "testnet");
|
|
196
|
+
}
|
|
197
|
+
function bundledEntries(raw) {
|
|
198
|
+
if (!Array.isArray(raw)) throw new Error("The bundled exchange registry has no entries list.");
|
|
199
|
+
const bad = raw.findIndex((e) => !isUsableEntry(e));
|
|
200
|
+
if (bad !== -1) throw new Error(`The bundled exchange registry entry ${bad} is malformed.`);
|
|
201
|
+
return raw;
|
|
184
202
|
}
|
|
185
203
|
function tightenedOver(embeddedEntry, servedEntry) {
|
|
186
|
-
|
|
204
|
+
const tightened = {
|
|
187
205
|
...servedEntry,
|
|
188
206
|
requiresMemo: embeddedEntry.requiresMemo || servedEntry.requiresMemo,
|
|
189
207
|
requiresMediator: embeddedEntry.requiresMediator || servedEntry.requiresMediator,
|
|
@@ -192,6 +210,9 @@ function tightenedOver(embeddedEntry, servedEntry) {
|
|
|
192
210
|
// (`mergeServedRegistry`) and the close is refused until the bundled copy is updated.
|
|
193
211
|
memoType: embeddedEntry.memoType
|
|
194
212
|
};
|
|
213
|
+
if (embeddedEntry.network === void 0) delete tightened.network;
|
|
214
|
+
else tightened.network = embeddedEntry.network;
|
|
215
|
+
return tightened;
|
|
195
216
|
}
|
|
196
217
|
var MAX_EXTENSION_DAYS = 120;
|
|
197
218
|
function boundedValidUntil(embeddedUntil, servedUntil) {
|
|
@@ -234,15 +255,12 @@ function isUsableAt(validUntil, now) {
|
|
|
234
255
|
}
|
|
235
256
|
|
|
236
257
|
// ../../apps/web/lib/exchange-registry/index.ts
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
var EMBEDDED = snapshotFrom(exchange_registry_default, false);
|
|
258
|
+
var EMBEDDED = {
|
|
259
|
+
entries: bundledEntries(exchange_registry_default.entries),
|
|
260
|
+
lastVerified: exchange_registry_default.lastVerified,
|
|
261
|
+
validUntil: exchange_registry_default.validUntil,
|
|
262
|
+
served: false
|
|
263
|
+
};
|
|
246
264
|
var current = EMBEDDED;
|
|
247
265
|
function bundledRegistry() {
|
|
248
266
|
return EMBEDDED;
|
|
@@ -250,14 +268,17 @@ function bundledRegistry() {
|
|
|
250
268
|
function isRegistryUsable(now = /* @__PURE__ */ new Date()) {
|
|
251
269
|
return isUsableAt(current.validUntil, now);
|
|
252
270
|
}
|
|
253
|
-
function byAddress() {
|
|
254
|
-
return new Map(current.entries.map((e) => [e.address, e]));
|
|
271
|
+
function byAddress(network) {
|
|
272
|
+
return new Map(current.entries.filter((e) => appliesOn(e, network)).map((e) => [e.address, e]));
|
|
255
273
|
}
|
|
256
|
-
function lookupExchange(address) {
|
|
257
|
-
return byAddress().get(address) ?? null;
|
|
274
|
+
function lookupExchange(address, network) {
|
|
275
|
+
return byAddress(network).get(address) ?? null;
|
|
258
276
|
}
|
|
259
|
-
function
|
|
260
|
-
return EMBEDDED.entries.find((e) => e.address === address)
|
|
277
|
+
function bundledExchange(address, network) {
|
|
278
|
+
return EMBEDDED.entries.find((e) => e.address === address && appliesOn(e, network)) ?? null;
|
|
279
|
+
}
|
|
280
|
+
function mediatorAllowedFor(address, network) {
|
|
281
|
+
return bundledExchange(address, network)?.requiresMediator === true;
|
|
261
282
|
}
|
|
262
283
|
function memoTypeInDispute(address) {
|
|
263
284
|
return current.memoTypeDisputes?.includes(address) ?? false;
|
|
@@ -1455,9 +1476,13 @@ function depositAddressesOf(transfers, lookup) {
|
|
|
1455
1476
|
}
|
|
1456
1477
|
return listed;
|
|
1457
1478
|
}
|
|
1458
|
-
function registryView(served) {
|
|
1479
|
+
function registryView(served, network) {
|
|
1459
1480
|
if (served === void 0) {
|
|
1460
|
-
return {
|
|
1481
|
+
return {
|
|
1482
|
+
lookup: (address) => lookupExchange(address, network),
|
|
1483
|
+
usable: () => isRegistryUsable(),
|
|
1484
|
+
memoTypeInDispute
|
|
1485
|
+
};
|
|
1461
1486
|
}
|
|
1462
1487
|
const merged = mergeServedRegistry(bundledRegistry(), served);
|
|
1463
1488
|
if (merged === null) {
|
|
@@ -1466,7 +1491,9 @@ function registryView(served) {
|
|
|
1466
1491
|
"The exchange registry passed to the verifier is not a registry (it needs an entries list, lastVerified and validUntil), so this close cannot be checked against it."
|
|
1467
1492
|
);
|
|
1468
1493
|
}
|
|
1469
|
-
const byAddress2 = new Map(
|
|
1494
|
+
const byAddress2 = new Map(
|
|
1495
|
+
merged.entries.filter((e) => appliesOn(e, network)).map((e) => [e.address, e])
|
|
1496
|
+
);
|
|
1470
1497
|
const disputes = new Set(merged.memoTypeDisputes);
|
|
1471
1498
|
return {
|
|
1472
1499
|
lookup: (address) => byAddress2.get(address) ?? null,
|
|
@@ -1474,15 +1501,14 @@ function registryView(served) {
|
|
|
1474
1501
|
memoTypeInDispute: (address) => disputes.has(address)
|
|
1475
1502
|
};
|
|
1476
1503
|
}
|
|
1477
|
-
function listedMemoType(exchange, registry, expected) {
|
|
1504
|
+
function listedMemoType(exchange, registry, network, expected) {
|
|
1478
1505
|
if (registry.memoTypeInDispute(expected.destination)) {
|
|
1479
1506
|
throw new VerificationError(
|
|
1480
1507
|
"registry_memo_type_conflict",
|
|
1481
1508
|
`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
1509
|
);
|
|
1483
1510
|
}
|
|
1484
|
-
|
|
1485
|
-
if (bundled) return exchange.memoType;
|
|
1511
|
+
if (bundledExchange(expected.destination, network) !== null) return exchange.memoType;
|
|
1486
1512
|
if (expected.memo !== null && expected.memoType !== null && expected.memoType !== exchange.memoType) {
|
|
1487
1513
|
throw new VerificationError(
|
|
1488
1514
|
"registry_memo_type_unconfirmed",
|
|
@@ -1493,7 +1519,7 @@ function listedMemoType(exchange, registry, expected) {
|
|
|
1493
1519
|
}
|
|
1494
1520
|
function verifyCloseTransaction(opts) {
|
|
1495
1521
|
const intent = intentFromXdr(opts.unsignedXdr, NETWORK_PASSPHRASES[opts.network]);
|
|
1496
|
-
const registry = registryView(opts.servedRegistry);
|
|
1522
|
+
const registry = registryView(opts.servedRegistry, opts.network);
|
|
1497
1523
|
const exchange = registry.lookup(opts.expected.destination);
|
|
1498
1524
|
if (exchange !== null && !registry.usable()) {
|
|
1499
1525
|
throw new VerificationError(
|
|
@@ -1508,10 +1534,10 @@ function verifyCloseTransaction(opts) {
|
|
|
1508
1534
|
registry.lookup
|
|
1509
1535
|
),
|
|
1510
1536
|
// From the bundled copy alone, whatever was served: see `registryView`.
|
|
1511
|
-
mediatorRequired: mediatorAllowedFor(opts.expected.destination),
|
|
1537
|
+
mediatorRequired: mediatorAllowedFor(opts.expected.destination, opts.network),
|
|
1512
1538
|
directMergeRefused: exchange?.requiresMediator ?? false,
|
|
1513
1539
|
memoRequired: exchange?.requiresMemo ?? false,
|
|
1514
|
-
memoType: exchange === null ? opts.expected.memoType : listedMemoType(exchange, registry, opts.expected),
|
|
1540
|
+
memoType: exchange === null ? opts.expected.memoType : listedMemoType(exchange, registry, opts.network, opts.expected),
|
|
1515
1541
|
nowSeconds: Math.floor(Date.now() / 1e3),
|
|
1516
1542
|
preAuthorized: opts.preAuthorized === true
|
|
1517
1543
|
});
|
|
@@ -2355,6 +2381,112 @@ function exitExpectations(accountState, network) {
|
|
|
2355
2381
|
};
|
|
2356
2382
|
}
|
|
2357
2383
|
|
|
2384
|
+
// ../../apps/web/lib/stellar/verify-revoke-allowance.ts
|
|
2385
|
+
var MAX_REVOKE_FEE_STROOPS = BigInt(1e7);
|
|
2386
|
+
var MAX_VALIDITY_SECONDS2 = BigInt(900);
|
|
2387
|
+
var RevokeAllowanceVerificationError = class extends Error {
|
|
2388
|
+
constructor(code, message) {
|
|
2389
|
+
super(message);
|
|
2390
|
+
this.name = "RevokeAllowanceVerificationError";
|
|
2391
|
+
this.code = code;
|
|
2392
|
+
}
|
|
2393
|
+
};
|
|
2394
|
+
function fail(code, message) {
|
|
2395
|
+
throw new RevokeAllowanceVerificationError(code, message);
|
|
2396
|
+
}
|
|
2397
|
+
function verifyRevokeAllowanceTransaction(xdr2, networkPassphrase, expected, nowSeconds = Math.floor(Date.now() / 1e3)) {
|
|
2398
|
+
const intent = intentFromXdr(xdr2, networkPassphrase);
|
|
2399
|
+
const maxTime = intent.maxTime ?? null;
|
|
2400
|
+
if (maxTime === null || !/^\d+$/.test(maxTime)) {
|
|
2401
|
+
fail(
|
|
2402
|
+
"revoke_expiry_missing",
|
|
2403
|
+
"This transaction never expires, so it could be submitted long after you approved it."
|
|
2404
|
+
);
|
|
2405
|
+
}
|
|
2406
|
+
if (BigInt(maxTime) > BigInt(Math.floor(nowSeconds)) + MAX_VALIDITY_SECONDS2) {
|
|
2407
|
+
fail(
|
|
2408
|
+
"revoke_expiry_too_far",
|
|
2409
|
+
"This transaction stays valid for far longer than a revocation needs."
|
|
2410
|
+
);
|
|
2411
|
+
}
|
|
2412
|
+
if (intent.source !== expected.owner) {
|
|
2413
|
+
fail(
|
|
2414
|
+
"revoke_transaction_source_mismatch",
|
|
2415
|
+
"This transaction is not sourced from the account being revoked for."
|
|
2416
|
+
);
|
|
2417
|
+
}
|
|
2418
|
+
if (intent.memo !== null) {
|
|
2419
|
+
fail("revoke_memo_present", "This transaction carries a memo, which a revocation never needs.");
|
|
2420
|
+
}
|
|
2421
|
+
if (BigInt(intent.fee) > MAX_REVOKE_FEE_STROOPS) {
|
|
2422
|
+
fail(
|
|
2423
|
+
"revoke_fee_above_cap",
|
|
2424
|
+
"This transaction's fee is higher than a revocation should ever need."
|
|
2425
|
+
);
|
|
2426
|
+
}
|
|
2427
|
+
if (intent.operations.length !== 1) {
|
|
2428
|
+
fail(
|
|
2429
|
+
"revoke_operation_count",
|
|
2430
|
+
`This transaction has ${intent.operations.length} operations; a revocation has exactly one.`
|
|
2431
|
+
);
|
|
2432
|
+
}
|
|
2433
|
+
const op = intent.operations[0];
|
|
2434
|
+
if (op.source !== expected.owner) {
|
|
2435
|
+
fail(
|
|
2436
|
+
"revoke_operation_source_mismatch",
|
|
2437
|
+
"The operation does not act as the account being revoked for."
|
|
2438
|
+
);
|
|
2439
|
+
}
|
|
2440
|
+
if (op.type !== "invoke_host_function") {
|
|
2441
|
+
fail("revoke_not_invocation", "This transaction does not invoke a contract.");
|
|
2442
|
+
}
|
|
2443
|
+
if (op.contract !== expected.token) {
|
|
2444
|
+
fail("revoke_token_mismatch", "This transaction does not touch the expected token contract.");
|
|
2445
|
+
}
|
|
2446
|
+
if (op.function !== "approve") {
|
|
2447
|
+
fail(
|
|
2448
|
+
"revoke_function_not_approve",
|
|
2449
|
+
"This transaction does not call approve, so it is not a revocation."
|
|
2450
|
+
);
|
|
2451
|
+
}
|
|
2452
|
+
if (op.args.length !== 4 || op.args[0] !== expected.owner || op.args[1] !== expected.spender || op.args[2] !== "0") {
|
|
2453
|
+
fail(
|
|
2454
|
+
"revoke_approve_args_mismatch",
|
|
2455
|
+
"This transaction does not revoke the expected spender's allowance on this token."
|
|
2456
|
+
);
|
|
2457
|
+
}
|
|
2458
|
+
if (op.authorizesBeyondSelf) {
|
|
2459
|
+
fail(
|
|
2460
|
+
"revoke_auth_beyond_self",
|
|
2461
|
+
"This transaction authorizes more than the account's own revocation."
|
|
2462
|
+
);
|
|
2463
|
+
}
|
|
2464
|
+
if (op.authDepth !== 0) {
|
|
2465
|
+
fail(
|
|
2466
|
+
"revoke_auth_nested",
|
|
2467
|
+
"This transaction authorizes a nested call, which a plain revocation never needs."
|
|
2468
|
+
);
|
|
2469
|
+
}
|
|
2470
|
+
if (op.unsupportedAddressCount > 0) {
|
|
2471
|
+
fail(
|
|
2472
|
+
"revoke_address_unsupported",
|
|
2473
|
+
"This transaction references an address form that cannot be verified."
|
|
2474
|
+
);
|
|
2475
|
+
}
|
|
2476
|
+
if (op.accountsReferenced.some((a) => a !== expected.owner && a !== expected.spender)) {
|
|
2477
|
+
fail(
|
|
2478
|
+
"revoke_foreign_account",
|
|
2479
|
+
"This transaction references an account other than the one being revoked for."
|
|
2480
|
+
);
|
|
2481
|
+
}
|
|
2482
|
+
if (op.contractsReferenced.some((c) => c !== expected.token && c !== expected.spender)) {
|
|
2483
|
+
fail(
|
|
2484
|
+
"revoke_foreign_contract",
|
|
2485
|
+
"This transaction references a contract other than the token or the spender."
|
|
2486
|
+
);
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
|
|
2358
2490
|
// src/index.ts
|
|
2359
2491
|
function verifyCloseTransaction2(input) {
|
|
2360
2492
|
verifyCloseTransaction(input);
|
|
@@ -2362,11 +2494,16 @@ function verifyCloseTransaction2(input) {
|
|
|
2362
2494
|
function exitExpectations2(accountState, network) {
|
|
2363
2495
|
return exitExpectations(accountState, network);
|
|
2364
2496
|
}
|
|
2365
|
-
function requiresMediator(address) {
|
|
2366
|
-
return mediatorAllowedFor(address);
|
|
2497
|
+
function requiresMediator(address, network) {
|
|
2498
|
+
return mediatorAllowedFor(address, network);
|
|
2499
|
+
}
|
|
2500
|
+
function verifyRevokeAllowanceTransaction2(unsignedXdr, networkPassphrase, expected, nowSeconds) {
|
|
2501
|
+
verifyRevokeAllowanceTransaction(unsignedXdr, networkPassphrase, expected, nowSeconds);
|
|
2367
2502
|
}
|
|
2368
2503
|
|
|
2504
|
+
exports.RevokeAllowanceVerificationError = RevokeAllowanceVerificationError;
|
|
2369
2505
|
exports.VerificationError = VerificationError;
|
|
2370
2506
|
exports.exitExpectations = exitExpectations2;
|
|
2371
2507
|
exports.requiresMediator = requiresMediator;
|
|
2372
2508
|
exports.verifyCloseTransaction = verifyCloseTransaction2;
|
|
2509
|
+
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
|
|
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
|
*
|
|
@@ -324,6 +325,8 @@ export declare interface ExchangeRegistryEntry {
|
|
|
324
325
|
requiresMemo: boolean;
|
|
325
326
|
/** The required memo type, if `requiresMemo` is true. */
|
|
326
327
|
memoType: "text" | "id" | "hash";
|
|
328
|
+
/** Present only on an entry scoped to testnet. Absent means the entry applies on every network. */
|
|
329
|
+
network?: "testnet";
|
|
327
330
|
}
|
|
328
331
|
|
|
329
332
|
/**
|
|
@@ -411,6 +414,9 @@ declare interface PhoenixStakePosition extends DefiPositionBase {
|
|
|
411
414
|
stakedAmount: string;
|
|
412
415
|
/** Unix seconds; unbonding requires the original stake's timestamp (architecture.md §9.6). */
|
|
413
416
|
stakedAtEpoch: string;
|
|
417
|
+
/** The pool's LP share token (`CONFIG.share_token`): unbonding returns the shares to it, and the
|
|
418
|
+
* withdrawal that follows transfers them back to the pool. Read from the pool. */
|
|
419
|
+
shareToken?: string;
|
|
414
420
|
}
|
|
415
421
|
|
|
416
422
|
declare interface PlanBlocker {
|
|
@@ -426,13 +432,48 @@ declare interface PoolShareEntry {
|
|
|
426
432
|
}
|
|
427
433
|
|
|
428
434
|
/**
|
|
429
|
-
* Whether a close to `address` goes through the shared intermediary: true only for
|
|
430
|
-
* the registry bundled in this package lists as unable to receive
|
|
431
|
-
*
|
|
435
|
+
* Whether a close to `address` on `network` goes through the shared intermediary: true only for
|
|
436
|
+
* an exchange the registry bundled in this package lists, on that network, as unable to receive
|
|
437
|
+
* an account merge. An entry scoped to testnet never answers true on mainnet. The same rule
|
|
438
|
+
* `verifyCloseTransaction` applies, so an integrator decides from it, never from the API's
|
|
432
439
|
* response, whether a transaction needs the intermediary's co-signature. A served snapshot never
|
|
433
440
|
* changes this answer, so it takes none.
|
|
434
441
|
*/
|
|
435
|
-
export declare function requiresMediator(address: string): boolean;
|
|
442
|
+
export declare function requiresMediator(address: string, network: Network): boolean;
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Every reason the revocation anchor refuses a transaction, one stable code each, in the order the
|
|
446
|
+
* checks run. The code is the contract an integrator branches on; the message is the current
|
|
447
|
+
* English wording and may change. Each code carries a `revoke_` prefix so it never shares a value
|
|
448
|
+
* with a close `VerificationErrorCode`.
|
|
449
|
+
*/
|
|
450
|
+
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"];
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* What the screen showed the user before they approved an allowance revocation: the allowance
|
|
454
|
+
* the revocation must zero, and nothing else. Every value is one the integrator already displayed,
|
|
455
|
+
* never one read from the transaction under verification.
|
|
456
|
+
*/
|
|
457
|
+
export declare interface RevokeAllowanceExpectation {
|
|
458
|
+
/** The account whose allowance is revoked. The transaction and its one operation must be
|
|
459
|
+
* sourced from it, and it is the only account the call may authorize. */
|
|
460
|
+
owner: string;
|
|
461
|
+
/** The token contract (`C...`) `approve` is called on. */
|
|
462
|
+
token: string;
|
|
463
|
+
/** The spender whose allowance goes to zero: a contract (`C...`) or, less often, an account
|
|
464
|
+
* (`G...`). */
|
|
465
|
+
spender: string;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/** Thrown when a server-built allowance revocation fails verification. Never sign past this. */
|
|
469
|
+
export declare class RevokeAllowanceVerificationError extends Error {
|
|
470
|
+
/** Why the transaction was refused. Stable across releases, unlike the message. */
|
|
471
|
+
readonly code: RevokeAllowanceVerificationErrorCode;
|
|
472
|
+
constructor(code: RevokeAllowanceVerificationErrorCode, message: string);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/** The reason a {@link RevokeAllowanceVerificationError} was thrown. */
|
|
476
|
+
export declare type RevokeAllowanceVerificationErrorCode = (typeof REVOKE_ALLOWANCE_VERIFICATION_ERROR_CODES)[number];
|
|
436
477
|
|
|
437
478
|
/**
|
|
438
479
|
* A served exchange registry: the body of `GET /v1/config/exchange-registry` (the SDK's
|
|
@@ -448,6 +489,9 @@ export declare function requiresMediator(address: string): boolean;
|
|
|
448
489
|
* - It never enables the mediated hand-off. That stays limited to the exchanges the bundled
|
|
449
490
|
* registry lists ({@link requiresMediator}), so an address only the snapshot lists as needing
|
|
450
491
|
* the intermediary refuses both shapes until this package is updated.
|
|
492
|
+
* - It never changes the network a bundled exchange applies on: a testnet-only entry stays
|
|
493
|
+
* unlisted on mainnet, and an entry listed on every network stays listed on both. An entry it
|
|
494
|
+
* adds with `network: "testnet"` applies on testnet only; any other `network` value drops it.
|
|
451
495
|
* - Its `validUntil` may move the bundled expiry later, by at most 120 days, never earlier.
|
|
452
496
|
* - It never decides a memo type. A different type for a bundled exchange is refused with
|
|
453
497
|
* `registry_memo_type_conflict`, and a type for an address it adds that differs from the one
|
|
@@ -651,4 +695,27 @@ export declare interface VerifyCloseInput {
|
|
|
651
695
|
*/
|
|
652
696
|
export declare function verifyCloseTransaction(input: VerifyCloseInput): void;
|
|
653
697
|
|
|
698
|
+
/**
|
|
699
|
+
* Decodes an API-built, unsigned allowance revocation and asserts it is exactly
|
|
700
|
+
* `approve(owner, spender, 0, expiration)` on `token`: one operation, sourced from `owner`, no
|
|
701
|
+
* memo, a fee of at most 10,000,000 stroops, valid for at most 900 seconds after `nowSeconds`,
|
|
702
|
+
* authorized only by the owner's own source account with no nested call, and naming no other
|
|
703
|
+
* account or contract. Returns only when the transaction may be signed.
|
|
704
|
+
*
|
|
705
|
+
* What it guarantees is that the signed transaction does what the screen said, so an API cannot
|
|
706
|
+
* swap the token or the spender between what was shown and what is signed. It does not judge
|
|
707
|
+
* whether the shown allowance is worth revoking.
|
|
708
|
+
*
|
|
709
|
+
* Throws {@link RevokeAllowanceVerificationError} with a stable `code` on any mismatch, or
|
|
710
|
+
* {@link VerificationError} when the envelope cannot be decoded at all (for example a text memo
|
|
711
|
+
* that is not valid UTF-8). Synchronous and offline: it reads no network and no page state, and
|
|
712
|
+
* keeps no state between calls. Run it once per transaction, immediately before the signature.
|
|
713
|
+
*
|
|
714
|
+
* @param unsignedXdr - The unsigned transaction envelope as returned by the API, base64.
|
|
715
|
+
* @param networkPassphrase - The passphrase of the network the revocation runs on.
|
|
716
|
+
* @param expected - The allowance the screen showed.
|
|
717
|
+
* @param nowSeconds - The current Unix time in seconds; defaults to the system clock.
|
|
718
|
+
*/
|
|
719
|
+
export declare function verifyRevokeAllowanceTransaction(unsignedXdr: string, networkPassphrase: string, expected: RevokeAllowanceExpectation, nowSeconds?: number): void;
|
|
720
|
+
|
|
654
721
|
export { }
|