@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 +48 -1
- package/README.md +46 -6
- package/dist/index.cjs +146 -7
- package/dist/index.d.cts +68 -7
- package/dist/index.d.ts +68 -7
- package/dist/index.js +145 -8
- package/package.json +3 -2
- package/vectors/close-v1.json +633 -63
- package/vectors/revoke-allowance-v1.json +437 -0
package/dist/index.js
CHANGED
|
@@ -185,9 +185,10 @@ function tightenedOver(embeddedEntry, servedEntry) {
|
|
|
185
185
|
...servedEntry,
|
|
186
186
|
requiresMemo: embeddedEntry.requiresMemo || servedEntry.requiresMemo,
|
|
187
187
|
requiresMediator: embeddedEntry.requiresMediator || servedEntry.requiresMediator,
|
|
188
|
-
//
|
|
189
|
-
//
|
|
190
|
-
|
|
188
|
+
// Never taken from the served copy. A memo sent under the wrong type reaches the right
|
|
189
|
+
// address and is credited to nobody, so a served type that differs is recorded as a dispute
|
|
190
|
+
// (`mergeServedRegistry`) and the close is refused until the bundled copy is updated.
|
|
191
|
+
memoType: embeddedEntry.memoType
|
|
191
192
|
};
|
|
192
193
|
}
|
|
193
194
|
var MAX_EXTENSION_DAYS = 120;
|
|
@@ -207,8 +208,12 @@ function mergeServedRegistry(floor, body) {
|
|
|
207
208
|
}
|
|
208
209
|
const embeddedByAddress = new Map(floor.entries.map((e) => [e.address, e]));
|
|
209
210
|
const merged = new Map(embeddedByAddress);
|
|
211
|
+
const disputes = /* @__PURE__ */ new Set();
|
|
210
212
|
for (const servedEntry of served.entries.filter(isUsableEntry)) {
|
|
211
213
|
const embeddedEntry = embeddedByAddress.get(servedEntry.address);
|
|
214
|
+
if (embeddedEntry && embeddedEntry.memoType !== servedEntry.memoType) {
|
|
215
|
+
disputes.add(servedEntry.address);
|
|
216
|
+
}
|
|
212
217
|
merged.set(
|
|
213
218
|
servedEntry.address,
|
|
214
219
|
embeddedEntry ? tightenedOver(embeddedEntry, servedEntry) : servedEntry
|
|
@@ -217,7 +222,8 @@ function mergeServedRegistry(floor, body) {
|
|
|
217
222
|
return {
|
|
218
223
|
entries: [...merged.values()],
|
|
219
224
|
lastVerified: served.lastVerified,
|
|
220
|
-
validUntil: boundedValidUntil(floor.validUntil, served.validUntil)
|
|
225
|
+
validUntil: boundedValidUntil(floor.validUntil, served.validUntil),
|
|
226
|
+
memoTypeDisputes: [...disputes]
|
|
221
227
|
};
|
|
222
228
|
}
|
|
223
229
|
function isUsableAt(validUntil, now) {
|
|
@@ -251,6 +257,9 @@ function lookupExchange(address) {
|
|
|
251
257
|
function mediatorAllowedFor(address) {
|
|
252
258
|
return EMBEDDED.entries.find((e) => e.address === address)?.requiresMediator === true;
|
|
253
259
|
}
|
|
260
|
+
function memoTypeInDispute(address) {
|
|
261
|
+
return current.memoTypeDisputes?.includes(address) ?? false;
|
|
262
|
+
}
|
|
254
263
|
function collectAddress(address, into) {
|
|
255
264
|
switch (address.type) {
|
|
256
265
|
case "scAddressTypeAccount":
|
|
@@ -1446,7 +1455,7 @@ function depositAddressesOf(transfers, lookup) {
|
|
|
1446
1455
|
}
|
|
1447
1456
|
function registryView(served) {
|
|
1448
1457
|
if (served === void 0) {
|
|
1449
|
-
return { lookup: lookupExchange, usable: () => isRegistryUsable() };
|
|
1458
|
+
return { lookup: lookupExchange, usable: () => isRegistryUsable(), memoTypeInDispute };
|
|
1450
1459
|
}
|
|
1451
1460
|
const merged = mergeServedRegistry(bundledRegistry(), served);
|
|
1452
1461
|
if (merged === null) {
|
|
@@ -1456,11 +1465,30 @@ function registryView(served) {
|
|
|
1456
1465
|
);
|
|
1457
1466
|
}
|
|
1458
1467
|
const byAddress2 = new Map(merged.entries.map((e) => [e.address, e]));
|
|
1468
|
+
const disputes = new Set(merged.memoTypeDisputes);
|
|
1459
1469
|
return {
|
|
1460
1470
|
lookup: (address) => byAddress2.get(address) ?? null,
|
|
1461
|
-
usable: () => isUsableAt(merged.validUntil, /* @__PURE__ */ new Date())
|
|
1471
|
+
usable: () => isUsableAt(merged.validUntil, /* @__PURE__ */ new Date()),
|
|
1472
|
+
memoTypeInDispute: (address) => disputes.has(address)
|
|
1462
1473
|
};
|
|
1463
1474
|
}
|
|
1475
|
+
function listedMemoType(exchange, registry, expected) {
|
|
1476
|
+
if (registry.memoTypeInDispute(expected.destination)) {
|
|
1477
|
+
throw new VerificationError(
|
|
1478
|
+
"registry_memo_type_conflict",
|
|
1479
|
+
`The served exchange registry gives ${exchange.name} a different memo type than the bundled one, so the memo this close needs cannot be checked.`
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
const bundled = bundledRegistry().entries.some((e) => e.address === expected.destination);
|
|
1483
|
+
if (bundled) return exchange.memoType;
|
|
1484
|
+
if (expected.memo !== null && expected.memoType !== null && expected.memoType !== exchange.memoType) {
|
|
1485
|
+
throw new VerificationError(
|
|
1486
|
+
"registry_memo_type_unconfirmed",
|
|
1487
|
+
`The served exchange registry lists ${exchange.name} with ${MEMO_TYPE_WITH_ARTICLE[exchange.memoType]} memo, not the ${expected.memoType} memo you confirmed.`
|
|
1488
|
+
);
|
|
1489
|
+
}
|
|
1490
|
+
return expected.memoType;
|
|
1491
|
+
}
|
|
1464
1492
|
function verifyCloseTransaction(opts) {
|
|
1465
1493
|
const intent = intentFromXdr(opts.unsignedXdr, NETWORK_PASSPHRASES[opts.network]);
|
|
1466
1494
|
const registry = registryView(opts.servedRegistry);
|
|
@@ -1481,7 +1509,7 @@ function verifyCloseTransaction(opts) {
|
|
|
1481
1509
|
mediatorRequired: mediatorAllowedFor(opts.expected.destination),
|
|
1482
1510
|
directMergeRefused: exchange?.requiresMediator ?? false,
|
|
1483
1511
|
memoRequired: exchange?.requiresMemo ?? false,
|
|
1484
|
-
memoType: exchange
|
|
1512
|
+
memoType: exchange === null ? opts.expected.memoType : listedMemoType(exchange, registry, opts.expected),
|
|
1485
1513
|
nowSeconds: Math.floor(Date.now() / 1e3),
|
|
1486
1514
|
preAuthorized: opts.preAuthorized === true
|
|
1487
1515
|
});
|
|
@@ -2325,6 +2353,112 @@ function exitExpectations(accountState, network) {
|
|
|
2325
2353
|
};
|
|
2326
2354
|
}
|
|
2327
2355
|
|
|
2356
|
+
// ../../apps/web/lib/stellar/verify-revoke-allowance.ts
|
|
2357
|
+
var MAX_REVOKE_FEE_STROOPS = BigInt(1e7);
|
|
2358
|
+
var MAX_VALIDITY_SECONDS2 = BigInt(900);
|
|
2359
|
+
var RevokeAllowanceVerificationError = class extends Error {
|
|
2360
|
+
constructor(code, message) {
|
|
2361
|
+
super(message);
|
|
2362
|
+
this.name = "RevokeAllowanceVerificationError";
|
|
2363
|
+
this.code = code;
|
|
2364
|
+
}
|
|
2365
|
+
};
|
|
2366
|
+
function fail(code, message) {
|
|
2367
|
+
throw new RevokeAllowanceVerificationError(code, message);
|
|
2368
|
+
}
|
|
2369
|
+
function verifyRevokeAllowanceTransaction(xdr2, networkPassphrase, expected, nowSeconds = Math.floor(Date.now() / 1e3)) {
|
|
2370
|
+
const intent = intentFromXdr(xdr2, networkPassphrase);
|
|
2371
|
+
const maxTime = intent.maxTime ?? null;
|
|
2372
|
+
if (maxTime === null || !/^\d+$/.test(maxTime)) {
|
|
2373
|
+
fail(
|
|
2374
|
+
"revoke_expiry_missing",
|
|
2375
|
+
"This transaction never expires, so it could be submitted long after you approved it."
|
|
2376
|
+
);
|
|
2377
|
+
}
|
|
2378
|
+
if (BigInt(maxTime) > BigInt(Math.floor(nowSeconds)) + MAX_VALIDITY_SECONDS2) {
|
|
2379
|
+
fail(
|
|
2380
|
+
"revoke_expiry_too_far",
|
|
2381
|
+
"This transaction stays valid for far longer than a revocation needs."
|
|
2382
|
+
);
|
|
2383
|
+
}
|
|
2384
|
+
if (intent.source !== expected.owner) {
|
|
2385
|
+
fail(
|
|
2386
|
+
"revoke_transaction_source_mismatch",
|
|
2387
|
+
"This transaction is not sourced from the account being revoked for."
|
|
2388
|
+
);
|
|
2389
|
+
}
|
|
2390
|
+
if (intent.memo !== null) {
|
|
2391
|
+
fail("revoke_memo_present", "This transaction carries a memo, which a revocation never needs.");
|
|
2392
|
+
}
|
|
2393
|
+
if (BigInt(intent.fee) > MAX_REVOKE_FEE_STROOPS) {
|
|
2394
|
+
fail(
|
|
2395
|
+
"revoke_fee_above_cap",
|
|
2396
|
+
"This transaction's fee is higher than a revocation should ever need."
|
|
2397
|
+
);
|
|
2398
|
+
}
|
|
2399
|
+
if (intent.operations.length !== 1) {
|
|
2400
|
+
fail(
|
|
2401
|
+
"revoke_operation_count",
|
|
2402
|
+
`This transaction has ${intent.operations.length} operations; a revocation has exactly one.`
|
|
2403
|
+
);
|
|
2404
|
+
}
|
|
2405
|
+
const op = intent.operations[0];
|
|
2406
|
+
if (op.source !== expected.owner) {
|
|
2407
|
+
fail(
|
|
2408
|
+
"revoke_operation_source_mismatch",
|
|
2409
|
+
"The operation does not act as the account being revoked for."
|
|
2410
|
+
);
|
|
2411
|
+
}
|
|
2412
|
+
if (op.type !== "invoke_host_function") {
|
|
2413
|
+
fail("revoke_not_invocation", "This transaction does not invoke a contract.");
|
|
2414
|
+
}
|
|
2415
|
+
if (op.contract !== expected.token) {
|
|
2416
|
+
fail("revoke_token_mismatch", "This transaction does not touch the expected token contract.");
|
|
2417
|
+
}
|
|
2418
|
+
if (op.function !== "approve") {
|
|
2419
|
+
fail(
|
|
2420
|
+
"revoke_function_not_approve",
|
|
2421
|
+
"This transaction does not call approve, so it is not a revocation."
|
|
2422
|
+
);
|
|
2423
|
+
}
|
|
2424
|
+
if (op.args.length !== 4 || op.args[0] !== expected.owner || op.args[1] !== expected.spender || op.args[2] !== "0") {
|
|
2425
|
+
fail(
|
|
2426
|
+
"revoke_approve_args_mismatch",
|
|
2427
|
+
"This transaction does not revoke the expected spender's allowance on this token."
|
|
2428
|
+
);
|
|
2429
|
+
}
|
|
2430
|
+
if (op.authorizesBeyondSelf) {
|
|
2431
|
+
fail(
|
|
2432
|
+
"revoke_auth_beyond_self",
|
|
2433
|
+
"This transaction authorizes more than the account's own revocation."
|
|
2434
|
+
);
|
|
2435
|
+
}
|
|
2436
|
+
if (op.authDepth !== 0) {
|
|
2437
|
+
fail(
|
|
2438
|
+
"revoke_auth_nested",
|
|
2439
|
+
"This transaction authorizes a nested call, which a plain revocation never needs."
|
|
2440
|
+
);
|
|
2441
|
+
}
|
|
2442
|
+
if (op.unsupportedAddressCount > 0) {
|
|
2443
|
+
fail(
|
|
2444
|
+
"revoke_address_unsupported",
|
|
2445
|
+
"This transaction references an address form that cannot be verified."
|
|
2446
|
+
);
|
|
2447
|
+
}
|
|
2448
|
+
if (op.accountsReferenced.some((a) => a !== expected.owner && a !== expected.spender)) {
|
|
2449
|
+
fail(
|
|
2450
|
+
"revoke_foreign_account",
|
|
2451
|
+
"This transaction references an account other than the one being revoked for."
|
|
2452
|
+
);
|
|
2453
|
+
}
|
|
2454
|
+
if (op.contractsReferenced.some((c) => c !== expected.token && c !== expected.spender)) {
|
|
2455
|
+
fail(
|
|
2456
|
+
"revoke_foreign_contract",
|
|
2457
|
+
"This transaction references a contract other than the token or the spender."
|
|
2458
|
+
);
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2328
2462
|
// src/index.ts
|
|
2329
2463
|
function verifyCloseTransaction2(input) {
|
|
2330
2464
|
verifyCloseTransaction(input);
|
|
@@ -2335,5 +2469,8 @@ function exitExpectations2(accountState, network) {
|
|
|
2335
2469
|
function requiresMediator(address) {
|
|
2336
2470
|
return mediatorAllowedFor(address);
|
|
2337
2471
|
}
|
|
2472
|
+
function verifyRevokeAllowanceTransaction2(unsignedXdr, networkPassphrase, expected, nowSeconds) {
|
|
2473
|
+
verifyRevokeAllowanceTransaction(unsignedXdr, networkPassphrase, expected, nowSeconds);
|
|
2474
|
+
}
|
|
2338
2475
|
|
|
2339
|
-
export { VerificationError, exitExpectations2 as exitExpectations, requiresMediator, verifyCloseTransaction2 as verifyCloseTransaction };
|
|
2476
|
+
export { RevokeAllowanceVerificationError, VerificationError, exitExpectations2 as exitExpectations, requiresMediator, verifyCloseTransaction2 as verifyCloseTransaction, verifyRevokeAllowanceTransaction2 as verifyRevokeAllowanceTransaction };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumenwipe/verify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"default": "./dist/index.cjs"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
-
"./vectors/close-v1.json": "./vectors/close-v1.json"
|
|
21
|
+
"./vectors/close-v1.json": "./vectors/close-v1.json",
|
|
22
|
+
"./vectors/revoke-allowance-v1.json": "./vectors/revoke-allowance-v1.json"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"dist",
|