shinjuku-shielded 0.3.12 → 0.3.14
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/manifest.json +3 -3
- package/package.json +3 -3
- package/shinjuku-wallet.mjs +321 -296
package/manifest.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": "carbon-shielded-wallet/bundle-manifest/v1",
|
|
3
3
|
"file": "shinjuku-wallet.mjs",
|
|
4
|
-
"sha256": "
|
|
5
|
-
"bytes":
|
|
6
|
-
"sourceCommit": "
|
|
4
|
+
"sha256": "db079e3700b17388873252fb91358d1918801ff69d1ee26f4e3e9f21bccbab34",
|
|
5
|
+
"bytes": 11121670,
|
|
6
|
+
"sourceCommit": "181724d44e72d6b49f062fb641761811e66e23a6",
|
|
7
7
|
"sourceDirty": false,
|
|
8
8
|
"installRecordMatchesLockfile": true,
|
|
9
9
|
"releaseRule": "valid only when two fresh npm ci --ignore-scripts builds on different OSes give the same sha256; installRecordMatchesLockfile true means every entry npm installed equals its package-lock.json entry and every entry not marked optional, devOptional included, is installed: an optional entry (a package for another platform) may be absent",
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shinjuku-shielded",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"mcpName": "io.github.ShinjukuStaition/shinjuku-mcp",
|
|
5
5
|
"description": "Shinjuku Shielded, the private x402 facilitator on Solana: the self-custody wallet CLI and its MCP server. Shield, pay, and unshield USDC from any MCP agent, under caps you set.",
|
|
6
|
-
"shinjukuRelease": "
|
|
7
|
-
"shinjukuSha256": "
|
|
6
|
+
"shinjukuRelease": "db079e37",
|
|
7
|
+
"shinjukuSha256": "db079e3700b17388873252fb91358d1918801ff69d1ee26f4e3e9f21bccbab34",
|
|
8
8
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
9
9
|
"author": "Shinjuku Shielded",
|
|
10
10
|
"homepage": "https://github.com/ShinjukuStaition/shinjuku-mcp#readme",
|
package/shinjuku-wallet.mjs
CHANGED
|
@@ -91035,7 +91035,7 @@ async function payViaFloat({
|
|
|
91035
91035
|
if (response.ok && response.status !== 202) {
|
|
91036
91036
|
let settled;
|
|
91037
91037
|
try {
|
|
91038
|
-
const encoded = response.headers.get("PAYMENT-RESPONSE");
|
|
91038
|
+
const encoded = response.headers.get("PAYMENT-RESPONSE") ?? response.headers.get("X-PAYMENT-RESPONSE");
|
|
91039
91039
|
settled = encoded && encoded.length <= 128 * 1024 ? decodePaymentResponseHeader(encoded) : void 0;
|
|
91040
91040
|
} catch {
|
|
91041
91041
|
settled = void 0;
|
|
@@ -119055,13 +119055,13 @@ init_http();
|
|
|
119055
119055
|
import { createHash as createHash26 } from "node:crypto";
|
|
119056
119056
|
|
|
119057
119057
|
// wallet/src/pocket/auto.mjs
|
|
119058
|
-
var
|
|
119058
|
+
var import_web3125 = __toESM(require_index_cjs(), 1);
|
|
119059
119059
|
init_book();
|
|
119060
119060
|
init_fill();
|
|
119061
119061
|
|
|
119062
119062
|
// wallet/src/pocket/cli.mjs
|
|
119063
119063
|
init_fs();
|
|
119064
|
-
var
|
|
119064
|
+
var import_web3124 = __toESM(require_index_cjs(), 1);
|
|
119065
119065
|
init_store();
|
|
119066
119066
|
init_processLease();
|
|
119067
119067
|
init_chain2();
|
|
@@ -119197,7 +119197,259 @@ async function scanPockets({ store, connection, gap = 5, legacyPools = [] }) {
|
|
|
119197
119197
|
init_proxy();
|
|
119198
119198
|
init_rpcDefault();
|
|
119199
119199
|
init_secretFile();
|
|
119200
|
-
|
|
119200
|
+
|
|
119201
|
+
// wallet/src/move/migration.mjs
|
|
119202
|
+
init_fs();
|
|
119203
|
+
var import_web3123 = __toESM(require_index_cjs(), 1);
|
|
119204
|
+
init_shielded_wallet();
|
|
119205
|
+
init_store();
|
|
119206
|
+
import { join as join21 } from "node:path";
|
|
119207
|
+
init_proxy();
|
|
119208
|
+
var DECIMAL4 = /^(0|[1-9][0-9]{0,90})$/;
|
|
119209
|
+
var HEX644 = /^[0-9a-f]{64}$/;
|
|
119210
|
+
var PRIVATE_HOST2 = /^(localhost|127\.0\.0\.1|\[::1\]|10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|172\.(1[6-9]|2\d|3[01])\.\d+\.\d+)$/;
|
|
119211
|
+
var fail31 = (code, detail) => new Error(`${code}: ${detail}`);
|
|
119212
|
+
var releaseInvalid = (why) => fail31(
|
|
119213
|
+
"wallet_move_release_invalid",
|
|
119214
|
+
`the facilitator's release document names its pools in a shape this wallet does not accept (${why}); nothing was moved. Update the wallet (npx -y shinjuku-shielded@latest), then run shinjuku-wallet move again`
|
|
119215
|
+
);
|
|
119216
|
+
var isPubkey2 = (value) => {
|
|
119217
|
+
try {
|
|
119218
|
+
return typeof value === "string" && new import_web3123.PublicKey(value).toBase58() === value;
|
|
119219
|
+
} catch {
|
|
119220
|
+
return false;
|
|
119221
|
+
}
|
|
119222
|
+
};
|
|
119223
|
+
function poolOrigin(value, pool, facilitator) {
|
|
119224
|
+
let url;
|
|
119225
|
+
try {
|
|
119226
|
+
url = new URL(String(value));
|
|
119227
|
+
} catch {
|
|
119228
|
+
url = void 0;
|
|
119229
|
+
}
|
|
119230
|
+
if (!url || url.username || url.password || url.search || url.hash) throw releaseInvalid("a facilitatorOrigin is not a plain URL");
|
|
119231
|
+
if (!(url.protocol === "https:" || isOnionOrigin(url) || url.protocol === "http:" && PRIVATE_HOST2.test(url.hostname))) {
|
|
119232
|
+
throw releaseInvalid("a facilitatorOrigin is not https");
|
|
119233
|
+
}
|
|
119234
|
+
if (url.origin !== new URL(facilitator).origin) throw releaseInvalid("a facilitatorOrigin is on another host than the facilitator");
|
|
119235
|
+
const path = url.pathname.replace(/\/+$/, "");
|
|
119236
|
+
if (path !== "" && path !== `/pool/${pool.slice(0, 8)}`) throw releaseInvalid("a facilitatorOrigin path is not /pool/<first 8 characters of its pool>");
|
|
119237
|
+
return `${url.origin}${path}`;
|
|
119238
|
+
}
|
|
119239
|
+
function parseReleasePools(release, facilitator) {
|
|
119240
|
+
const raw = release?.pools;
|
|
119241
|
+
if (raw === void 0 || raw === null) {
|
|
119242
|
+
if (release?.migration) throw releaseInvalid("it announces a migration but names no pools");
|
|
119243
|
+
return Object.freeze({ pools: Object.freeze([]), migration: null });
|
|
119244
|
+
}
|
|
119245
|
+
if (!Array.isArray(raw) || raw.length > 16) throw releaseInvalid("pools is not a short list");
|
|
119246
|
+
const pools = raw.map((entry) => {
|
|
119247
|
+
if (!entry || typeof entry !== "object") throw releaseInvalid("a pool entry is not an object");
|
|
119248
|
+
if (!isPubkey2(entry.pool) || !isPubkey2(entry.programId)) throw releaseInvalid("a pool or programId is not a base58 address");
|
|
119249
|
+
if (!DECIMAL4.test(String(entry.poolDomain ?? ""))) throw releaseInvalid("a poolDomain is not a decimal number");
|
|
119250
|
+
if (entry.role !== "active" && entry.role !== "draining") throw releaseInvalid("a pool role is not active or draining");
|
|
119251
|
+
const tools = entry.proofTools;
|
|
119252
|
+
const proofTools = tools && HEX644.test(String(tools.sumsSha256)) && tools.dir === String(tools.sumsSha256).slice(0, 8) ? Object.freeze({ dir: tools.dir, sumsSha256: tools.sumsSha256 }) : void 0;
|
|
119253
|
+
return Object.freeze({
|
|
119254
|
+
pool: entry.pool,
|
|
119255
|
+
programId: entry.programId,
|
|
119256
|
+
poolDomain: String(entry.poolDomain),
|
|
119257
|
+
role: entry.role,
|
|
119258
|
+
facilitatorOrigin: poolOrigin(entry.facilitatorOrigin, entry.pool, facilitator),
|
|
119259
|
+
...proofTools ? { proofTools } : {}
|
|
119260
|
+
});
|
|
119261
|
+
});
|
|
119262
|
+
if (new Set(pools.map((entry) => entry.pool)).size !== pools.length) throw releaseInvalid("a pool is listed twice");
|
|
119263
|
+
const byPool = new Map(pools.map((entry) => [entry.pool, entry]));
|
|
119264
|
+
const announced = release.migration;
|
|
119265
|
+
if (announced === void 0 || announced === null) return Object.freeze({ pools: Object.freeze(pools), migration: null });
|
|
119266
|
+
if (typeof announced !== "object" || !Array.isArray(announced.from) || announced.from.length === 0) throw releaseInvalid("migration.from is not a list");
|
|
119267
|
+
const to = byPool.get(announced.to);
|
|
119268
|
+
if (!to || to.role !== "active") throw releaseInvalid("migration.to is not the active pool of the list");
|
|
119269
|
+
const from = announced.from.map((pool) => {
|
|
119270
|
+
const entry = byPool.get(pool);
|
|
119271
|
+
if (!entry || entry.role !== "draining") throw releaseInvalid("a migration.from pool is not a draining pool of the list");
|
|
119272
|
+
return entry;
|
|
119273
|
+
});
|
|
119274
|
+
return Object.freeze({ pools: Object.freeze(pools), migration: Object.freeze({ from: Object.freeze(from), to }) });
|
|
119275
|
+
}
|
|
119276
|
+
async function readReleasePools({ facilitator, fetchImpl = fetch }) {
|
|
119277
|
+
const release = await fetchRelease(facilitator, { fetchImpl });
|
|
119278
|
+
return Object.freeze({ release, ...parseReleasePools(release, facilitator) });
|
|
119279
|
+
}
|
|
119280
|
+
var knownPools = (config) => [config.pool, ...(config.previousPools ?? []).map((entry) => entry.pool)];
|
|
119281
|
+
function pendingMoves({ home, migration }) {
|
|
119282
|
+
if (!migration) return [];
|
|
119283
|
+
return migration.from.filter((entry) => existsSync(homeWalletPath(home, entry.pool))).map((from) => Object.freeze({ from, to: migration.to }));
|
|
119284
|
+
}
|
|
119285
|
+
function poolToolPaths(config, pool) {
|
|
119286
|
+
const entry = config.pool === pool ? config : (config.previousPools ?? []).find((item) => item.pool === pool);
|
|
119287
|
+
return entry ? {
|
|
119288
|
+
proofTools: entry.proofTools,
|
|
119289
|
+
exitProofTools: entry.exitProofTools,
|
|
119290
|
+
profile: entry.profile,
|
|
119291
|
+
program: entry.program,
|
|
119292
|
+
...entry.proofToolsRelease ? { proofToolsRelease: entry.proofToolsRelease } : {}
|
|
119293
|
+
} : void 0;
|
|
119294
|
+
}
|
|
119295
|
+
function parseMoveTrust(values) {
|
|
119296
|
+
return (values ?? []).map((value) => {
|
|
119297
|
+
const sums = String(value).trim().toLowerCase();
|
|
119298
|
+
if (!HEX644.test(sums)) {
|
|
119299
|
+
throw fail31("wallet_move_proof_tools_trust_invalid", "--trust-proof-tools must be the 64-hex SHA-256 of a proof-tool set's SHA256SUMS; nothing was moved");
|
|
119300
|
+
}
|
|
119301
|
+
return sums;
|
|
119302
|
+
});
|
|
119303
|
+
}
|
|
119304
|
+
var UNTRUSTED = /^(setup_proof_tools_pin_mismatch|setup_proof_tools_unpinned|wallet_channel_key_unset):/;
|
|
119305
|
+
async function poolProofTools({ home, config, entry, release, facilitator, trust = [], fetchImpl = fetch, publicKeyHex, deps = {} }) {
|
|
119306
|
+
const set = entry.proofTools;
|
|
119307
|
+
if (!set) return void 0;
|
|
119308
|
+
const recorded = poolToolPaths(config, entry.pool);
|
|
119309
|
+
if (recorded?.proofToolsRelease?.sumsSha256 === set.sumsSha256 && recorded.proofTools) return void 0;
|
|
119310
|
+
let trusted;
|
|
119311
|
+
if (trust.includes(set.sumsSha256)) {
|
|
119312
|
+
trusted = Object.freeze({ dir: set.dir, sumsSha256: set.sumsSha256, trusted: true });
|
|
119313
|
+
} else {
|
|
119314
|
+
let pin;
|
|
119315
|
+
try {
|
|
119316
|
+
pin = expectedProofTools(facilitator);
|
|
119317
|
+
} catch {
|
|
119318
|
+
pin = void 0;
|
|
119319
|
+
}
|
|
119320
|
+
const keyOption = publicKeyHex === void 0 ? {} : { publicKeyHex };
|
|
119321
|
+
try {
|
|
119322
|
+
trusted = await (deps.trustServedSet ?? trustServedSet)({
|
|
119323
|
+
home,
|
|
119324
|
+
facilitator,
|
|
119325
|
+
release: { ...release, pool: entry.pool, proofTools: set },
|
|
119326
|
+
expected: pin,
|
|
119327
|
+
fetchImpl,
|
|
119328
|
+
...keyOption
|
|
119329
|
+
});
|
|
119330
|
+
} catch (error) {
|
|
119331
|
+
if (!UNTRUSTED.test(String(error?.message))) throw error;
|
|
119332
|
+
throw fail31("wallet_move_proof_tools_untrusted", `the facilitator names proof-tool set ${set.dir} (SHA256SUMS ${set.sumsSha256}) for pool ${entry.pool}, and neither this wallet build's pin nor the signed release channel vouches for it; nothing was downloaded or moved. Update the wallet (npx -y shinjuku-shielded@latest), or (advanced) after you checked that set out of band run shinjuku-wallet move --trust-proof-tools ${set.sumsSha256} (repeat the flag once per set)`);
|
|
119333
|
+
}
|
|
119334
|
+
}
|
|
119335
|
+
const tools = await (deps.installProofTools ?? installProofTools)({ facilitator, toolsRoot: join21(home, "proof-tools"), expected: trusted, fetchImpl });
|
|
119336
|
+
return Object.freeze({
|
|
119337
|
+
dir: tools.dir,
|
|
119338
|
+
sumsSha256: tools.sumsSha256,
|
|
119339
|
+
proofTools: tools.proofTools,
|
|
119340
|
+
exitProofTools: tools.exitProofTools,
|
|
119341
|
+
profile: tools.profile,
|
|
119342
|
+
installed: tools.downloaded > 0
|
|
119343
|
+
});
|
|
119344
|
+
}
|
|
119345
|
+
function recordPoolTools({ home, config, pool, tools, program }) {
|
|
119346
|
+
const fresh = readSetupConfig(home) ?? config;
|
|
119347
|
+
const paths = {
|
|
119348
|
+
proofTools: tools.proofTools,
|
|
119349
|
+
exitProofTools: tools.exitProofTools,
|
|
119350
|
+
profile: tools.profile,
|
|
119351
|
+
proofToolsRelease: { dir: tools.dir, sumsSha256: tools.sumsSha256 }
|
|
119352
|
+
};
|
|
119353
|
+
let next;
|
|
119354
|
+
if (fresh.pool === pool) next = { ...fresh, ...paths };
|
|
119355
|
+
else if ((fresh.previousPools ?? []).some((entry) => entry.pool === pool)) {
|
|
119356
|
+
next = { ...fresh, previousPools: fresh.previousPools.map((entry) => entry.pool === pool ? { ...entry, ...paths } : entry) };
|
|
119357
|
+
} else if (program) {
|
|
119358
|
+
next = { ...fresh, previousPools: [...fresh.previousPools ?? [], { pool, program, ...paths }] };
|
|
119359
|
+
} else return fresh;
|
|
119360
|
+
writeSetupConfig(home, next);
|
|
119361
|
+
return next;
|
|
119362
|
+
}
|
|
119363
|
+
function ensureMoveTarget({ home, config, passphrase: passphrase2, from, to, release, targetTools, open: open3 = openWalletStore, create = createWalletStore }) {
|
|
119364
|
+
const { created, targetSeed } = ensureTargetWallet({ home, passphrase: passphrase2, fromPool: from.pool, toPool: to.pool, open: open3, create });
|
|
119365
|
+
let next = config;
|
|
119366
|
+
let configMoved = false;
|
|
119367
|
+
let setupNeeded = false;
|
|
119368
|
+
if (config.pool === from.pool) {
|
|
119369
|
+
const toolsFit = targetTools !== void 0 || config.program === to.programId && (!config.proofToolsRelease || !release?.proofTools || config.proofToolsRelease.sumsSha256 === release.proofTools.sumsSha256);
|
|
119370
|
+
if (toolsFit) {
|
|
119371
|
+
const own = targetTools === void 0 ? {} : {
|
|
119372
|
+
proofTools: targetTools.proofTools,
|
|
119373
|
+
exitProofTools: targetTools.exitProofTools,
|
|
119374
|
+
profile: targetTools.profile,
|
|
119375
|
+
proofToolsRelease: { dir: targetTools.dir, sumsSha256: targetTools.sumsSha256 }
|
|
119376
|
+
};
|
|
119377
|
+
next = { ...config, pool: to.pool, program: to.programId, ...own, previousPools: withPreviousPool(config) };
|
|
119378
|
+
writeSetupConfig(home, next);
|
|
119379
|
+
configMoved = true;
|
|
119380
|
+
} else {
|
|
119381
|
+
setupNeeded = true;
|
|
119382
|
+
}
|
|
119383
|
+
}
|
|
119384
|
+
return Object.freeze({ created, targetSeed, configMoved, setupNeeded, config: next });
|
|
119385
|
+
}
|
|
119386
|
+
function withPreviousPool(config) {
|
|
119387
|
+
const kept = (config.previousPools ?? []).filter((entry) => entry.pool !== config.pool);
|
|
119388
|
+
return [...kept, {
|
|
119389
|
+
pool: config.pool,
|
|
119390
|
+
program: config.program,
|
|
119391
|
+
...config.proofTools ? { proofTools: config.proofTools } : {},
|
|
119392
|
+
...config.exitProofTools ? { exitProofTools: config.exitProofTools } : {},
|
|
119393
|
+
...config.profile ? { profile: config.profile } : {},
|
|
119394
|
+
...config.proofToolsRelease ? { proofToolsRelease: config.proofToolsRelease } : {}
|
|
119395
|
+
}];
|
|
119396
|
+
}
|
|
119397
|
+
function homeSeedSourcePool({ home, passphrase: passphrase2, toPool, migration, open: open3 = openWalletStore }) {
|
|
119398
|
+
const named = (migration?.from ?? []).map((entry) => entry.pool);
|
|
119399
|
+
let others = [];
|
|
119400
|
+
try {
|
|
119401
|
+
others = readdirSync(home).filter((name) => isPubkey2(name)).sort();
|
|
119402
|
+
} catch {
|
|
119403
|
+
others = [];
|
|
119404
|
+
}
|
|
119405
|
+
for (const pool of [.../* @__PURE__ */ new Set([...named, ...others])]) {
|
|
119406
|
+
if (pool === toPool || !existsSync(homeWalletPath(home, pool))) continue;
|
|
119407
|
+
try {
|
|
119408
|
+
if (open3(homeWalletPath(home, pool), passphrase2).state.pool === pool) return pool;
|
|
119409
|
+
} catch {
|
|
119410
|
+
}
|
|
119411
|
+
}
|
|
119412
|
+
return void 0;
|
|
119413
|
+
}
|
|
119414
|
+
function ensureTargetWallet({ home, passphrase: passphrase2, fromPool, toPool, open: open3 = openWalletStore, create = createWalletStore }) {
|
|
119415
|
+
const from = { pool: fromPool };
|
|
119416
|
+
const to = { pool: toPool };
|
|
119417
|
+
const sourcePath = homeWalletPath(home, from.pool);
|
|
119418
|
+
const targetPath = homeWalletPath(home, to.pool);
|
|
119419
|
+
const source = open3(sourcePath, passphrase2);
|
|
119420
|
+
let created = false;
|
|
119421
|
+
if (existsSync(targetPath)) {
|
|
119422
|
+
let target;
|
|
119423
|
+
try {
|
|
119424
|
+
target = open3(targetPath, passphrase2);
|
|
119425
|
+
} catch {
|
|
119426
|
+
throw fail31("wallet_move_target_unreadable", `a wallet for the new pool ${to.pool} already exists in this home and does not open with this wallet's passphrase; nothing was moved. Move that folder aside (it is not this wallet), then run shinjuku-wallet move again`);
|
|
119427
|
+
}
|
|
119428
|
+
if (target.state.pool !== to.pool) {
|
|
119429
|
+
throw fail31("wallet_move_target_pool_mismatch", `the wallet file in the folder of the new pool ${to.pool} names another pool; nothing was moved. Move that folder aside, then run shinjuku-wallet move again: it makes the new pool's wallet from this wallet's seed`);
|
|
119430
|
+
}
|
|
119431
|
+
if (target.state.seedHex !== source.state.seedHex) return Object.freeze({ created, targetSeed: "other" });
|
|
119432
|
+
} else {
|
|
119433
|
+
const state = initialWalletState({
|
|
119434
|
+
pool: to.pool,
|
|
119435
|
+
network: source.state.network,
|
|
119436
|
+
asset: source.state.asset,
|
|
119437
|
+
decimals: source.state.decimals,
|
|
119438
|
+
binding: source.state.binding,
|
|
119439
|
+
config: { maxPaymentAtomic: source.state.config?.maxPaymentAtomic, maxCumulativeAtomic: source.state.config?.maxCumulativeAtomic },
|
|
119440
|
+
keys: { seedHex: source.state.seedHex, solanaSecretKey: source.state.solanaSecretKey }
|
|
119441
|
+
});
|
|
119442
|
+
const target = create(targetPath, passphrase2, state);
|
|
119443
|
+
if (target.state.seedHex !== source.state.seedHex || target.state.pool !== to.pool) {
|
|
119444
|
+
throw fail31("wallet_move_target_seed_mismatch", "the new pool's wallet did not read back with this wallet's seed; nothing was moved. Run shinjuku-wallet move again");
|
|
119445
|
+
}
|
|
119446
|
+
created = true;
|
|
119447
|
+
}
|
|
119448
|
+
return Object.freeze({ created, targetSeed: "same" });
|
|
119449
|
+
}
|
|
119450
|
+
|
|
119451
|
+
// wallet/src/pocket/cli.mjs
|
|
119452
|
+
var fail32 = (reason) => {
|
|
119201
119453
|
throw new Error(`p03_pocket_cli_${reason}`);
|
|
119202
119454
|
};
|
|
119203
119455
|
var FILL_REQUIRED = [
|
|
@@ -119222,21 +119474,21 @@ function parse3(command, args) {
|
|
|
119222
119474
|
const options = {};
|
|
119223
119475
|
for (let index = 0; index < args.length; index += 1) {
|
|
119224
119476
|
const key = args[index]?.startsWith("--") ? args[index].slice(2) : void 0;
|
|
119225
|
-
if (!key || options[key] !== void 0)
|
|
119477
|
+
if (!key || options[key] !== void 0) fail32("arguments_invalid");
|
|
119226
119478
|
if (spec.booleans.includes(key)) {
|
|
119227
119479
|
options[key] = true;
|
|
119228
119480
|
continue;
|
|
119229
119481
|
}
|
|
119230
|
-
if (![...spec.required, ...spec.optional].includes(key) || !args[index + 1] || args[index + 1].startsWith("--"))
|
|
119482
|
+
if (![...spec.required, ...spec.optional].includes(key) || !args[index + 1] || args[index + 1].startsWith("--")) fail32("arguments_invalid");
|
|
119231
119483
|
options[key] = args[index + 1];
|
|
119232
119484
|
index += 1;
|
|
119233
119485
|
}
|
|
119234
|
-
if (spec.required.some((key) => !options[key]))
|
|
119486
|
+
if (spec.required.some((key) => !options[key])) fail32("arguments_missing");
|
|
119235
119487
|
return options;
|
|
119236
119488
|
}
|
|
119237
119489
|
var count = (value, fallback) => {
|
|
119238
119490
|
if (value === void 0) return fallback;
|
|
119239
|
-
if (!/^[1-9][0-9]{0,2}$/.test(value))
|
|
119491
|
+
if (!/^[1-9][0-9]{0,2}$/.test(value)) fail32("count_invalid");
|
|
119240
119492
|
return Number(value);
|
|
119241
119493
|
};
|
|
119242
119494
|
var DEFAULT_DWELL_MINUTES = 1;
|
|
@@ -119279,9 +119531,9 @@ function ownTransactions(store) {
|
|
|
119279
119531
|
return own;
|
|
119280
119532
|
}
|
|
119281
119533
|
function poolKeys(store, programId) {
|
|
119282
|
-
const program = new
|
|
119283
|
-
const pool = new
|
|
119284
|
-
return { program: program.toBase58(), pool: pool.toBase58(), vault: vaultAddress2(program, pool, new
|
|
119534
|
+
const program = new import_web3124.PublicKey(programId);
|
|
119535
|
+
const pool = new import_web3124.PublicKey(store.state.pool);
|
|
119536
|
+
return { program: program.toBase58(), pool: pool.toBase58(), vault: vaultAddress2(program, pool, new import_web3124.PublicKey(store.state.asset)).toBase58() };
|
|
119285
119537
|
}
|
|
119286
119538
|
function poolEventKind(raw, { program, pool, vault }) {
|
|
119287
119539
|
if (!raw?.meta || raw.meta.err !== null) return void 0;
|
|
@@ -119334,7 +119586,7 @@ async function countOtherPoolEvents({ connection, keys: keys3, deposit, own, pag
|
|
|
119334
119586
|
}
|
|
119335
119587
|
async function vaultPage(connection, keys3) {
|
|
119336
119588
|
try {
|
|
119337
|
-
const page = await retryRpc2(() => connection.getSignaturesForAddress(new
|
|
119589
|
+
const page = await retryRpc2(() => connection.getSignaturesForAddress(new import_web3124.PublicKey(keys3.vault), { limit: DWELL_PAGE }, "finalized"));
|
|
119338
119590
|
return Array.isArray(page) ? page : void 0;
|
|
119339
119591
|
} catch {
|
|
119340
119592
|
return void 0;
|
|
@@ -119387,7 +119639,7 @@ function dwellGate({ store, connection, history = connection, programId, minutes
|
|
|
119387
119639
|
let anchored;
|
|
119388
119640
|
if (!deposit && store.state.restoredFromRecoveryText === true) {
|
|
119389
119641
|
anchored = await restoredDepositAnchor({ connection, keys: keys3 });
|
|
119390
|
-
if (!anchored)
|
|
119642
|
+
if (!anchored) fail32("dwell_unreadable");
|
|
119391
119643
|
deposit = anchored.deposit;
|
|
119392
119644
|
say2(`dwell: this wallet was rebuilt from the recovery text (restore) and holds no record of its own deposits, so the dwell counts from the pool's newest transaction that can be a deposit (slot ${deposit.slot}): your own newest deposit is no newer than that one`);
|
|
119393
119645
|
}
|
|
@@ -119430,7 +119682,7 @@ function dwellGate({ store, connection, history = connection, programId, minutes
|
|
|
119430
119682
|
} catch {
|
|
119431
119683
|
now = void 0;
|
|
119432
119684
|
}
|
|
119433
|
-
if (!Number.isSafeInteger(landedAt) || !Number.isSafeInteger(now))
|
|
119685
|
+
if (!Number.isSafeInteger(landedAt) || !Number.isSafeInteger(now)) fail32("dwell_unreadable");
|
|
119434
119686
|
const capAt = landedAt + minutes * 60;
|
|
119435
119687
|
if (now >= capAt) {
|
|
119436
119688
|
passed = true;
|
|
@@ -119470,9 +119722,9 @@ function facilitatorOrigin(value) {
|
|
|
119470
119722
|
try {
|
|
119471
119723
|
origin = new URL(value);
|
|
119472
119724
|
} catch {
|
|
119473
|
-
|
|
119725
|
+
fail32("facilitator_origin_invalid");
|
|
119474
119726
|
}
|
|
119475
|
-
if (origin.protocol !== "https:" && !isOnionOrigin(origin) || origin.pathname !== "/" || origin.search)
|
|
119727
|
+
if (origin.protocol !== "https:" && !isOnionOrigin(origin) || origin.pathname !== "/" || origin.search) fail32("facilitator_origin_invalid");
|
|
119476
119728
|
return origin.origin;
|
|
119477
119729
|
}
|
|
119478
119730
|
async function withWallet(options, run5) {
|
|
@@ -119482,7 +119734,7 @@ async function withWallet(options, run5) {
|
|
|
119482
119734
|
try {
|
|
119483
119735
|
release = await acquireWalletProcessLease(walletLockPath(walletPath2));
|
|
119484
119736
|
} catch {
|
|
119485
|
-
|
|
119737
|
+
fail32("wallet_locked");
|
|
119486
119738
|
}
|
|
119487
119739
|
try {
|
|
119488
119740
|
const store = openWalletStore(walletPath2, passphrase2);
|
|
@@ -119495,17 +119747,17 @@ async function reshieldPocket({ store, connection, options }) {
|
|
|
119495
119747
|
const origin = options.serviceBase ?? facilitatorOrigin(options.facilitator);
|
|
119496
119748
|
reconcileFills(store);
|
|
119497
119749
|
const accounts = pocketAccounts(store);
|
|
119498
|
-
if (options.pocket === void 0 === (options["pay-to"] === void 0))
|
|
119499
|
-
if (options.pocket !== void 0 && !/^(0|[1-9][0-9]{0,9})$/.test(options.pocket))
|
|
119750
|
+
if (options.pocket === void 0 === (options["pay-to"] === void 0)) fail32("reshield_needs_pocket_or_pay_to");
|
|
119751
|
+
if (options.pocket !== void 0 && !/^(0|[1-9][0-9]{0,9})$/.test(options.pocket)) fail32("reshield_pocket_invalid");
|
|
119500
119752
|
const chosen = options.pocket !== void 0 ? accounts.find((account2) => account2.index === Number(options.pocket)) : accounts.find((account2) => account2.payTo === options["pay-to"]);
|
|
119501
|
-
if (!chosen)
|
|
119502
|
-
if (chosen.status === "filling" || BigInt(chosen.reservedAtomic) > 0n)
|
|
119753
|
+
if (!chosen) fail32("reshield_pocket_unknown");
|
|
119754
|
+
if (chosen.status === "filling" || BigInt(chosen.reservedAtomic) > 0n) fail32("reshield_pocket_busy");
|
|
119503
119755
|
const prefix = `reshield-${chosen.index}-`;
|
|
119504
119756
|
const records = store.listWal().filter((name) => name.startsWith(`deposit-${prefix}`)).map((name) => store.readWal(name));
|
|
119505
119757
|
const open3 = records.find((record) => record && !["published", "foreign_funded", "reclaimed"].includes(record.state));
|
|
119506
119758
|
let held = 0n;
|
|
119507
119759
|
try {
|
|
119508
|
-
held = (await getAccount(connection, new
|
|
119760
|
+
held = (await getAccount(connection, new import_web3124.PublicKey(chosen.ata), "finalized", TOKEN_PROGRAM_ID)).amount;
|
|
119509
119761
|
} catch {
|
|
119510
119762
|
held = 0n;
|
|
119511
119763
|
}
|
|
@@ -119540,6 +119792,15 @@ async function reshieldPocket({ store, connection, options }) {
|
|
|
119540
119792
|
note: "the value is a new note of yours in the shielded pool: shinjuku-wallet balance --refresh shows it"
|
|
119541
119793
|
};
|
|
119542
119794
|
}
|
|
119795
|
+
function scanLegacyPools(env = process.env) {
|
|
119796
|
+
let config;
|
|
119797
|
+
try {
|
|
119798
|
+
config = readSetupConfig(setupHome(env));
|
|
119799
|
+
} catch {
|
|
119800
|
+
config = void 0;
|
|
119801
|
+
}
|
|
119802
|
+
return [.../* @__PURE__ */ new Set([...config ? knownPools(config) : [], ...Object.keys(RETIRED_POOLS)])];
|
|
119803
|
+
}
|
|
119543
119804
|
function pocketReport(store) {
|
|
119544
119805
|
const book = pocketBook(store);
|
|
119545
119806
|
return {
|
|
@@ -119553,7 +119814,7 @@ function pocketReport(store) {
|
|
|
119553
119814
|
}
|
|
119554
119815
|
async function main4(args = process.argv.slice(2), io = { out: (text3) => console.log(text3) }) {
|
|
119555
119816
|
const [command, ...rest] = args;
|
|
119556
|
-
if (!SPECS[command])
|
|
119817
|
+
if (!SPECS[command]) fail32("command_unknown");
|
|
119557
119818
|
const options = parse3(command, rest);
|
|
119558
119819
|
const historyUrl = historyRpcUrl(options["history-rpc"]);
|
|
119559
119820
|
await withWallet(options, async (store) => {
|
|
@@ -119581,14 +119842,14 @@ async function main4(args = process.argv.slice(2), io = { out: (text3) => consol
|
|
|
119581
119842
|
const offered = await fetchPocketFeePayer({ origin: origin2, network: store.state.network });
|
|
119582
119843
|
printFeePayer(await guardFeePayer(async () => recordFeePayer(store, offered, { replace: options["replace-fee-payer"] === true })), origin2);
|
|
119583
119844
|
} else if (options["replace-fee-payer"]) {
|
|
119584
|
-
|
|
119845
|
+
fail32("replace_fee_payer_needs_facilitator");
|
|
119585
119846
|
}
|
|
119586
|
-
const scanned = await scanPockets({ store, connection, gap: count(options.gap, 5) });
|
|
119847
|
+
const scanned = await scanPockets({ store, connection, gap: count(options.gap, 5), legacyPools: scanLegacyPools() });
|
|
119587
119848
|
io.out(JSON.stringify({ success: true, ...scanned, ...pocketReport(store) }, null, 2));
|
|
119588
119849
|
return;
|
|
119589
119850
|
}
|
|
119590
119851
|
const dwell2 = options["dwell-minutes"] === void 0 ? DEFAULT_DWELL_MINUTES : Number(options["dwell-minutes"]);
|
|
119591
|
-
if (!Number.isSafeInteger(dwell2) || dwell2 < 0 || dwell2 > 10080 || !/^[0-9]{1,5}$/.test(String(options["dwell-minutes"] ?? "0")))
|
|
119852
|
+
if (!Number.isSafeInteger(dwell2) || dwell2 < 0 || dwell2 > 10080 || !/^[0-9]{1,5}$/.test(String(options["dwell-minutes"] ?? "0"))) fail32("dwell_minutes_invalid");
|
|
119592
119853
|
const gate = {};
|
|
119593
119854
|
const dwellSource = resolveHistorySource(connectSplit(connection, historyUrl), store.state.pool);
|
|
119594
119855
|
const beforeNewFill = dwellGate({
|
|
@@ -119687,18 +119948,18 @@ function yieldIfAsked(shouldYield) {
|
|
|
119687
119948
|
}
|
|
119688
119949
|
if (asked) throw Object.assign(new Error(`${YIELD_CODE}: a payment waits for the wallet`), { readyAt: null });
|
|
119689
119950
|
}
|
|
119690
|
-
var
|
|
119951
|
+
var fail33 = (reason, extra = {}) => {
|
|
119691
119952
|
throw Object.assign(new Error(`p03_pocket_auto_${reason}`), extra);
|
|
119692
119953
|
};
|
|
119693
119954
|
var firstCode2 = (error) => String(error?.message ?? "").split(/[\s:;(]/, 1)[0];
|
|
119694
119955
|
var pendingFill3 = (entry) => entry.fills.find((fill) => fill.state === "started" || fill.state === "paid");
|
|
119695
119956
|
var fillIndex = (unshieldId) => Number(/^pocket-(\d+)-f\d+$/.exec(unshieldId ?? "")?.[1] ?? NaN);
|
|
119696
119957
|
function assertAutoPocketSize(sizeAtomic = AUTO_POCKET_SIZE_ATOMIC) {
|
|
119697
|
-
if (String(sizeAtomic) !== AUTO_POCKET_SIZE_ATOMIC)
|
|
119958
|
+
if (String(sizeAtomic) !== AUTO_POCKET_SIZE_ATOMIC) fail33("pocket_size_unproven");
|
|
119698
119959
|
return AUTO_POCKET_SIZE_ATOMIC;
|
|
119699
119960
|
}
|
|
119700
119961
|
function assertReadyTarget(readyTarget = DEFAULT_READY_POCKETS) {
|
|
119701
|
-
if (!Number.isSafeInteger(readyTarget) || readyTarget < 0 || readyTarget > MAX_READY_POCKETS)
|
|
119962
|
+
if (!Number.isSafeInteger(readyTarget) || readyTarget < 0 || readyTarget > MAX_READY_POCKETS) fail33("ready_pockets_invalid");
|
|
119702
119963
|
return readyTarget;
|
|
119703
119964
|
}
|
|
119704
119965
|
function pendingOf(store) {
|
|
@@ -119726,7 +119987,7 @@ function lastPaidAtMs(store, index) {
|
|
|
119726
119987
|
return last;
|
|
119727
119988
|
}
|
|
119728
119989
|
function idlePocketsDue(store, { now = Date.now(), idleDays = IDLE_RESHIELD_DAYS, floorAtomic = RESHIELD_FLOOR_ATOMIC } = {}) {
|
|
119729
|
-
if (!Number.isFinite(idleDays) || idleDays < 0)
|
|
119990
|
+
if (!Number.isFinite(idleDays) || idleDays < 0) fail33("idle_days_invalid");
|
|
119730
119991
|
const floor = BigInt(floorAtomic);
|
|
119731
119992
|
const due = [];
|
|
119732
119993
|
for (const account2 of pocketAccounts(store)) {
|
|
@@ -119895,20 +120156,20 @@ async function ensureReadyPockets({
|
|
|
119895
120156
|
}
|
|
119896
120157
|
function planPocketFill(store, { payTo, priceAtomic, sizeAtomic = AUTO_POCKET_SIZE_ATOMIC, maxFills = MAX_FILLS_PER_PAYMENT }) {
|
|
119897
120158
|
const size = BigInt(assertAutoPocketSize(sizeAtomic));
|
|
119898
|
-
if (!/^[1-9][0-9]*$/.test(String(priceAtomic ?? "")))
|
|
119899
|
-
if (!Number.isSafeInteger(maxFills) || maxFills < 1 || maxFills > MAX_FILLS_PER_PAYMENT)
|
|
120159
|
+
if (!/^[1-9][0-9]*$/.test(String(priceAtomic ?? ""))) fail33("price_invalid");
|
|
120160
|
+
if (!Number.isSafeInteger(maxFills) || maxFills < 1 || maxFills > MAX_FILLS_PER_PAYMENT) fail33("max_fills_invalid");
|
|
119900
120161
|
let key;
|
|
119901
120162
|
try {
|
|
119902
|
-
key = new
|
|
120163
|
+
key = new import_web3125.PublicKey(payTo).toBase58();
|
|
119903
120164
|
} catch {
|
|
119904
|
-
|
|
120165
|
+
fail33("pay_to_invalid");
|
|
119905
120166
|
}
|
|
119906
120167
|
const price = BigInt(priceAtomic);
|
|
119907
120168
|
const accounts = pocketAccounts(store);
|
|
119908
120169
|
const fillsFor = (available) => {
|
|
119909
120170
|
const short = price - available;
|
|
119910
120171
|
const fills = Number((short + size - 1n) / size);
|
|
119911
|
-
if (fills > maxFills)
|
|
120172
|
+
if (fills > maxFills) fail33("fill_count_over_cap", { fills, maxFills });
|
|
119912
120173
|
return fills;
|
|
119913
120174
|
};
|
|
119914
120175
|
const bound = accounts.find((account2) => account2.payTo === key && account2.status !== "flagged");
|
|
@@ -119919,7 +120180,7 @@ function planPocketFill(store, { payTo, priceAtomic, sizeAtomic = AUTO_POCKET_SI
|
|
|
119919
120180
|
if (available >= price) return { action: "resume", index: bound.index, fills: 0 };
|
|
119920
120181
|
return { action: "refill", index: bound.index, fills: fillsFor(available) };
|
|
119921
120182
|
}
|
|
119922
|
-
if (accounts.some((account2) => account2.payTo === key))
|
|
120183
|
+
if (accounts.some((account2) => account2.payTo === key)) fail33("pocket_for_pay_to_flagged");
|
|
119923
120184
|
const ready = accounts.filter((account2) => account2.status === "ready");
|
|
119924
120185
|
const covering = ready.find((account2) => BigInt(account2.availableAtomic) >= price);
|
|
119925
120186
|
if (covering) return { action: "pay", index: covering.index };
|
|
@@ -119992,7 +120253,7 @@ async function idlePocketReshield({
|
|
|
119992
120253
|
limit = 1,
|
|
119993
120254
|
reshield = reshieldPocket
|
|
119994
120255
|
}) {
|
|
119995
|
-
if (!options?.facilitator || !options["proof-tools"] || !options.program)
|
|
120256
|
+
if (!options?.facilitator || !options["proof-tools"] || !options.program) fail33("reshield_options_missing");
|
|
119996
120257
|
const due = idlePocketsDue(store, { now, idleDays, floorAtomic });
|
|
119997
120258
|
const reshielded = [];
|
|
119998
120259
|
const failed = [];
|
|
@@ -120016,7 +120277,7 @@ async function scanAfterRestore({ store, connection, origin, gap = 5, fetchImpl,
|
|
|
120016
120277
|
return { feePayer, ...await scan({ store, connection, gap }) };
|
|
120017
120278
|
}
|
|
120018
120279
|
function createPocketJobs({ underLease, now = Date.now, retryAfterMs: retryAfterMs2 = FILL_RETRY_AFTER_MS }) {
|
|
120019
|
-
if (typeof underLease !== "function")
|
|
120280
|
+
if (typeof underLease !== "function") fail33("lease_missing");
|
|
120020
120281
|
const jobs = /* @__PURE__ */ new Map();
|
|
120021
120282
|
const requests = /* @__PURE__ */ new Map();
|
|
120022
120283
|
let lastFailure;
|
|
@@ -120032,7 +120293,7 @@ function createPocketJobs({ underLease, now = Date.now, retryAfterMs: retryAfter
|
|
|
120032
120293
|
return {
|
|
120033
120294
|
bindRequest(requestId, fingerprint, key) {
|
|
120034
120295
|
const seen = requests.get(requestId);
|
|
120035
|
-
if (seen && (seen.fingerprint !== fingerprint || seen.key !== key))
|
|
120296
|
+
if (seen && (seen.fingerprint !== fingerprint || seen.key !== key)) fail33("request_id_reused");
|
|
120036
120297
|
requests.set(requestId, { fingerprint, key });
|
|
120037
120298
|
return key;
|
|
120038
120299
|
},
|
|
@@ -120660,256 +120921,6 @@ init_secretFile();
|
|
|
120660
120921
|
init_processLease();
|
|
120661
120922
|
init_store();
|
|
120662
120923
|
|
|
120663
|
-
// wallet/src/move/migration.mjs
|
|
120664
|
-
init_fs();
|
|
120665
|
-
var import_web3125 = __toESM(require_index_cjs(), 1);
|
|
120666
|
-
init_shielded_wallet();
|
|
120667
|
-
init_store();
|
|
120668
|
-
import { join as join21 } from "node:path";
|
|
120669
|
-
init_proxy();
|
|
120670
|
-
var DECIMAL4 = /^(0|[1-9][0-9]{0,90})$/;
|
|
120671
|
-
var HEX644 = /^[0-9a-f]{64}$/;
|
|
120672
|
-
var PRIVATE_HOST2 = /^(localhost|127\.0\.0\.1|\[::1\]|10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|172\.(1[6-9]|2\d|3[01])\.\d+\.\d+)$/;
|
|
120673
|
-
var fail33 = (code, detail) => new Error(`${code}: ${detail}`);
|
|
120674
|
-
var releaseInvalid = (why) => fail33(
|
|
120675
|
-
"wallet_move_release_invalid",
|
|
120676
|
-
`the facilitator's release document names its pools in a shape this wallet does not accept (${why}); nothing was moved. Update the wallet (npx -y shinjuku-shielded@latest), then run shinjuku-wallet move again`
|
|
120677
|
-
);
|
|
120678
|
-
var isPubkey2 = (value) => {
|
|
120679
|
-
try {
|
|
120680
|
-
return typeof value === "string" && new import_web3125.PublicKey(value).toBase58() === value;
|
|
120681
|
-
} catch {
|
|
120682
|
-
return false;
|
|
120683
|
-
}
|
|
120684
|
-
};
|
|
120685
|
-
function poolOrigin(value, pool, facilitator) {
|
|
120686
|
-
let url;
|
|
120687
|
-
try {
|
|
120688
|
-
url = new URL(String(value));
|
|
120689
|
-
} catch {
|
|
120690
|
-
url = void 0;
|
|
120691
|
-
}
|
|
120692
|
-
if (!url || url.username || url.password || url.search || url.hash) throw releaseInvalid("a facilitatorOrigin is not a plain URL");
|
|
120693
|
-
if (!(url.protocol === "https:" || isOnionOrigin(url) || url.protocol === "http:" && PRIVATE_HOST2.test(url.hostname))) {
|
|
120694
|
-
throw releaseInvalid("a facilitatorOrigin is not https");
|
|
120695
|
-
}
|
|
120696
|
-
if (url.origin !== new URL(facilitator).origin) throw releaseInvalid("a facilitatorOrigin is on another host than the facilitator");
|
|
120697
|
-
const path = url.pathname.replace(/\/+$/, "");
|
|
120698
|
-
if (path !== "" && path !== `/pool/${pool.slice(0, 8)}`) throw releaseInvalid("a facilitatorOrigin path is not /pool/<first 8 characters of its pool>");
|
|
120699
|
-
return `${url.origin}${path}`;
|
|
120700
|
-
}
|
|
120701
|
-
function parseReleasePools(release, facilitator) {
|
|
120702
|
-
const raw = release?.pools;
|
|
120703
|
-
if (raw === void 0 || raw === null) {
|
|
120704
|
-
if (release?.migration) throw releaseInvalid("it announces a migration but names no pools");
|
|
120705
|
-
return Object.freeze({ pools: Object.freeze([]), migration: null });
|
|
120706
|
-
}
|
|
120707
|
-
if (!Array.isArray(raw) || raw.length > 16) throw releaseInvalid("pools is not a short list");
|
|
120708
|
-
const pools = raw.map((entry) => {
|
|
120709
|
-
if (!entry || typeof entry !== "object") throw releaseInvalid("a pool entry is not an object");
|
|
120710
|
-
if (!isPubkey2(entry.pool) || !isPubkey2(entry.programId)) throw releaseInvalid("a pool or programId is not a base58 address");
|
|
120711
|
-
if (!DECIMAL4.test(String(entry.poolDomain ?? ""))) throw releaseInvalid("a poolDomain is not a decimal number");
|
|
120712
|
-
if (entry.role !== "active" && entry.role !== "draining") throw releaseInvalid("a pool role is not active or draining");
|
|
120713
|
-
const tools = entry.proofTools;
|
|
120714
|
-
const proofTools = tools && HEX644.test(String(tools.sumsSha256)) && tools.dir === String(tools.sumsSha256).slice(0, 8) ? Object.freeze({ dir: tools.dir, sumsSha256: tools.sumsSha256 }) : void 0;
|
|
120715
|
-
return Object.freeze({
|
|
120716
|
-
pool: entry.pool,
|
|
120717
|
-
programId: entry.programId,
|
|
120718
|
-
poolDomain: String(entry.poolDomain),
|
|
120719
|
-
role: entry.role,
|
|
120720
|
-
facilitatorOrigin: poolOrigin(entry.facilitatorOrigin, entry.pool, facilitator),
|
|
120721
|
-
...proofTools ? { proofTools } : {}
|
|
120722
|
-
});
|
|
120723
|
-
});
|
|
120724
|
-
if (new Set(pools.map((entry) => entry.pool)).size !== pools.length) throw releaseInvalid("a pool is listed twice");
|
|
120725
|
-
const byPool = new Map(pools.map((entry) => [entry.pool, entry]));
|
|
120726
|
-
const announced = release.migration;
|
|
120727
|
-
if (announced === void 0 || announced === null) return Object.freeze({ pools: Object.freeze(pools), migration: null });
|
|
120728
|
-
if (typeof announced !== "object" || !Array.isArray(announced.from) || announced.from.length === 0) throw releaseInvalid("migration.from is not a list");
|
|
120729
|
-
const to = byPool.get(announced.to);
|
|
120730
|
-
if (!to || to.role !== "active") throw releaseInvalid("migration.to is not the active pool of the list");
|
|
120731
|
-
const from = announced.from.map((pool) => {
|
|
120732
|
-
const entry = byPool.get(pool);
|
|
120733
|
-
if (!entry || entry.role !== "draining") throw releaseInvalid("a migration.from pool is not a draining pool of the list");
|
|
120734
|
-
return entry;
|
|
120735
|
-
});
|
|
120736
|
-
return Object.freeze({ pools: Object.freeze(pools), migration: Object.freeze({ from: Object.freeze(from), to }) });
|
|
120737
|
-
}
|
|
120738
|
-
async function readReleasePools({ facilitator, fetchImpl = fetch }) {
|
|
120739
|
-
const release = await fetchRelease(facilitator, { fetchImpl });
|
|
120740
|
-
return Object.freeze({ release, ...parseReleasePools(release, facilitator) });
|
|
120741
|
-
}
|
|
120742
|
-
var knownPools = (config) => [config.pool, ...(config.previousPools ?? []).map((entry) => entry.pool)];
|
|
120743
|
-
function pendingMoves({ home, migration }) {
|
|
120744
|
-
if (!migration) return [];
|
|
120745
|
-
return migration.from.filter((entry) => existsSync(homeWalletPath(home, entry.pool))).map((from) => Object.freeze({ from, to: migration.to }));
|
|
120746
|
-
}
|
|
120747
|
-
function poolToolPaths(config, pool) {
|
|
120748
|
-
const entry = config.pool === pool ? config : (config.previousPools ?? []).find((item) => item.pool === pool);
|
|
120749
|
-
return entry ? {
|
|
120750
|
-
proofTools: entry.proofTools,
|
|
120751
|
-
exitProofTools: entry.exitProofTools,
|
|
120752
|
-
profile: entry.profile,
|
|
120753
|
-
program: entry.program,
|
|
120754
|
-
...entry.proofToolsRelease ? { proofToolsRelease: entry.proofToolsRelease } : {}
|
|
120755
|
-
} : void 0;
|
|
120756
|
-
}
|
|
120757
|
-
function parseMoveTrust(values) {
|
|
120758
|
-
return (values ?? []).map((value) => {
|
|
120759
|
-
const sums = String(value).trim().toLowerCase();
|
|
120760
|
-
if (!HEX644.test(sums)) {
|
|
120761
|
-
throw fail33("wallet_move_proof_tools_trust_invalid", "--trust-proof-tools must be the 64-hex SHA-256 of a proof-tool set's SHA256SUMS; nothing was moved");
|
|
120762
|
-
}
|
|
120763
|
-
return sums;
|
|
120764
|
-
});
|
|
120765
|
-
}
|
|
120766
|
-
var UNTRUSTED = /^(setup_proof_tools_pin_mismatch|setup_proof_tools_unpinned|wallet_channel_key_unset):/;
|
|
120767
|
-
async function poolProofTools({ home, config, entry, release, facilitator, trust = [], fetchImpl = fetch, publicKeyHex, deps = {} }) {
|
|
120768
|
-
const set = entry.proofTools;
|
|
120769
|
-
if (!set) return void 0;
|
|
120770
|
-
const recorded = poolToolPaths(config, entry.pool);
|
|
120771
|
-
if (recorded?.proofToolsRelease?.sumsSha256 === set.sumsSha256 && recorded.proofTools) return void 0;
|
|
120772
|
-
let trusted;
|
|
120773
|
-
if (trust.includes(set.sumsSha256)) {
|
|
120774
|
-
trusted = Object.freeze({ dir: set.dir, sumsSha256: set.sumsSha256, trusted: true });
|
|
120775
|
-
} else {
|
|
120776
|
-
let pin;
|
|
120777
|
-
try {
|
|
120778
|
-
pin = expectedProofTools(facilitator);
|
|
120779
|
-
} catch {
|
|
120780
|
-
pin = void 0;
|
|
120781
|
-
}
|
|
120782
|
-
const keyOption = publicKeyHex === void 0 ? {} : { publicKeyHex };
|
|
120783
|
-
try {
|
|
120784
|
-
trusted = await (deps.trustServedSet ?? trustServedSet)({
|
|
120785
|
-
home,
|
|
120786
|
-
facilitator,
|
|
120787
|
-
release: { ...release, pool: entry.pool, proofTools: set },
|
|
120788
|
-
expected: pin,
|
|
120789
|
-
fetchImpl,
|
|
120790
|
-
...keyOption
|
|
120791
|
-
});
|
|
120792
|
-
} catch (error) {
|
|
120793
|
-
if (!UNTRUSTED.test(String(error?.message))) throw error;
|
|
120794
|
-
throw fail33("wallet_move_proof_tools_untrusted", `the facilitator names proof-tool set ${set.dir} (SHA256SUMS ${set.sumsSha256}) for pool ${entry.pool}, and neither this wallet build's pin nor the signed release channel vouches for it; nothing was downloaded or moved. Update the wallet (npx -y shinjuku-shielded@latest), or (advanced) after you checked that set out of band run shinjuku-wallet move --trust-proof-tools ${set.sumsSha256} (repeat the flag once per set)`);
|
|
120795
|
-
}
|
|
120796
|
-
}
|
|
120797
|
-
const tools = await (deps.installProofTools ?? installProofTools)({ facilitator, toolsRoot: join21(home, "proof-tools"), expected: trusted, fetchImpl });
|
|
120798
|
-
return Object.freeze({
|
|
120799
|
-
dir: tools.dir,
|
|
120800
|
-
sumsSha256: tools.sumsSha256,
|
|
120801
|
-
proofTools: tools.proofTools,
|
|
120802
|
-
exitProofTools: tools.exitProofTools,
|
|
120803
|
-
profile: tools.profile,
|
|
120804
|
-
installed: tools.downloaded > 0
|
|
120805
|
-
});
|
|
120806
|
-
}
|
|
120807
|
-
function recordPoolTools({ home, config, pool, tools, program }) {
|
|
120808
|
-
const fresh = readSetupConfig(home) ?? config;
|
|
120809
|
-
const paths = {
|
|
120810
|
-
proofTools: tools.proofTools,
|
|
120811
|
-
exitProofTools: tools.exitProofTools,
|
|
120812
|
-
profile: tools.profile,
|
|
120813
|
-
proofToolsRelease: { dir: tools.dir, sumsSha256: tools.sumsSha256 }
|
|
120814
|
-
};
|
|
120815
|
-
let next;
|
|
120816
|
-
if (fresh.pool === pool) next = { ...fresh, ...paths };
|
|
120817
|
-
else if ((fresh.previousPools ?? []).some((entry) => entry.pool === pool)) {
|
|
120818
|
-
next = { ...fresh, previousPools: fresh.previousPools.map((entry) => entry.pool === pool ? { ...entry, ...paths } : entry) };
|
|
120819
|
-
} else if (program) {
|
|
120820
|
-
next = { ...fresh, previousPools: [...fresh.previousPools ?? [], { pool, program, ...paths }] };
|
|
120821
|
-
} else return fresh;
|
|
120822
|
-
writeSetupConfig(home, next);
|
|
120823
|
-
return next;
|
|
120824
|
-
}
|
|
120825
|
-
function ensureMoveTarget({ home, config, passphrase: passphrase2, from, to, release, targetTools, open: open3 = openWalletStore, create = createWalletStore }) {
|
|
120826
|
-
const { created, targetSeed } = ensureTargetWallet({ home, passphrase: passphrase2, fromPool: from.pool, toPool: to.pool, open: open3, create });
|
|
120827
|
-
let next = config;
|
|
120828
|
-
let configMoved = false;
|
|
120829
|
-
let setupNeeded = false;
|
|
120830
|
-
if (config.pool === from.pool) {
|
|
120831
|
-
const toolsFit = targetTools !== void 0 || config.program === to.programId && (!config.proofToolsRelease || !release?.proofTools || config.proofToolsRelease.sumsSha256 === release.proofTools.sumsSha256);
|
|
120832
|
-
if (toolsFit) {
|
|
120833
|
-
const own = targetTools === void 0 ? {} : {
|
|
120834
|
-
proofTools: targetTools.proofTools,
|
|
120835
|
-
exitProofTools: targetTools.exitProofTools,
|
|
120836
|
-
profile: targetTools.profile,
|
|
120837
|
-
proofToolsRelease: { dir: targetTools.dir, sumsSha256: targetTools.sumsSha256 }
|
|
120838
|
-
};
|
|
120839
|
-
next = { ...config, pool: to.pool, program: to.programId, ...own, previousPools: withPreviousPool(config) };
|
|
120840
|
-
writeSetupConfig(home, next);
|
|
120841
|
-
configMoved = true;
|
|
120842
|
-
} else {
|
|
120843
|
-
setupNeeded = true;
|
|
120844
|
-
}
|
|
120845
|
-
}
|
|
120846
|
-
return Object.freeze({ created, targetSeed, configMoved, setupNeeded, config: next });
|
|
120847
|
-
}
|
|
120848
|
-
function withPreviousPool(config) {
|
|
120849
|
-
const kept = (config.previousPools ?? []).filter((entry) => entry.pool !== config.pool);
|
|
120850
|
-
return [...kept, {
|
|
120851
|
-
pool: config.pool,
|
|
120852
|
-
program: config.program,
|
|
120853
|
-
...config.proofTools ? { proofTools: config.proofTools } : {},
|
|
120854
|
-
...config.exitProofTools ? { exitProofTools: config.exitProofTools } : {},
|
|
120855
|
-
...config.profile ? { profile: config.profile } : {},
|
|
120856
|
-
...config.proofToolsRelease ? { proofToolsRelease: config.proofToolsRelease } : {}
|
|
120857
|
-
}];
|
|
120858
|
-
}
|
|
120859
|
-
function homeSeedSourcePool({ home, passphrase: passphrase2, toPool, migration, open: open3 = openWalletStore }) {
|
|
120860
|
-
const named = (migration?.from ?? []).map((entry) => entry.pool);
|
|
120861
|
-
let others = [];
|
|
120862
|
-
try {
|
|
120863
|
-
others = readdirSync(home).filter((name) => isPubkey2(name)).sort();
|
|
120864
|
-
} catch {
|
|
120865
|
-
others = [];
|
|
120866
|
-
}
|
|
120867
|
-
for (const pool of [.../* @__PURE__ */ new Set([...named, ...others])]) {
|
|
120868
|
-
if (pool === toPool || !existsSync(homeWalletPath(home, pool))) continue;
|
|
120869
|
-
try {
|
|
120870
|
-
if (open3(homeWalletPath(home, pool), passphrase2).state.pool === pool) return pool;
|
|
120871
|
-
} catch {
|
|
120872
|
-
}
|
|
120873
|
-
}
|
|
120874
|
-
return void 0;
|
|
120875
|
-
}
|
|
120876
|
-
function ensureTargetWallet({ home, passphrase: passphrase2, fromPool, toPool, open: open3 = openWalletStore, create = createWalletStore }) {
|
|
120877
|
-
const from = { pool: fromPool };
|
|
120878
|
-
const to = { pool: toPool };
|
|
120879
|
-
const sourcePath = homeWalletPath(home, from.pool);
|
|
120880
|
-
const targetPath = homeWalletPath(home, to.pool);
|
|
120881
|
-
const source = open3(sourcePath, passphrase2);
|
|
120882
|
-
let created = false;
|
|
120883
|
-
if (existsSync(targetPath)) {
|
|
120884
|
-
let target;
|
|
120885
|
-
try {
|
|
120886
|
-
target = open3(targetPath, passphrase2);
|
|
120887
|
-
} catch {
|
|
120888
|
-
throw fail33("wallet_move_target_unreadable", `a wallet for the new pool ${to.pool} already exists in this home and does not open with this wallet's passphrase; nothing was moved. Move that folder aside (it is not this wallet), then run shinjuku-wallet move again`);
|
|
120889
|
-
}
|
|
120890
|
-
if (target.state.pool !== to.pool) {
|
|
120891
|
-
throw fail33("wallet_move_target_pool_mismatch", `the wallet file in the folder of the new pool ${to.pool} names another pool; nothing was moved. Move that folder aside, then run shinjuku-wallet move again: it makes the new pool's wallet from this wallet's seed`);
|
|
120892
|
-
}
|
|
120893
|
-
if (target.state.seedHex !== source.state.seedHex) return Object.freeze({ created, targetSeed: "other" });
|
|
120894
|
-
} else {
|
|
120895
|
-
const state = initialWalletState({
|
|
120896
|
-
pool: to.pool,
|
|
120897
|
-
network: source.state.network,
|
|
120898
|
-
asset: source.state.asset,
|
|
120899
|
-
decimals: source.state.decimals,
|
|
120900
|
-
binding: source.state.binding,
|
|
120901
|
-
config: { maxPaymentAtomic: source.state.config?.maxPaymentAtomic, maxCumulativeAtomic: source.state.config?.maxCumulativeAtomic },
|
|
120902
|
-
keys: { seedHex: source.state.seedHex, solanaSecretKey: source.state.solanaSecretKey }
|
|
120903
|
-
});
|
|
120904
|
-
const target = create(targetPath, passphrase2, state);
|
|
120905
|
-
if (target.state.seedHex !== source.state.seedHex || target.state.pool !== to.pool) {
|
|
120906
|
-
throw fail33("wallet_move_target_seed_mismatch", "the new pool's wallet did not read back with this wallet's seed; nothing was moved. Run shinjuku-wallet move again");
|
|
120907
|
-
}
|
|
120908
|
-
created = true;
|
|
120909
|
-
}
|
|
120910
|
-
return Object.freeze({ created, targetSeed: "same" });
|
|
120911
|
-
}
|
|
120912
|
-
|
|
120913
120924
|
// wallet/src/move/job.mjs
|
|
120914
120925
|
init_fs();
|
|
120915
120926
|
var import_web3126 = __toESM(require_index_cjs(), 1);
|
|
@@ -125176,9 +125187,10 @@ function createWalletTools({
|
|
|
125176
125187
|
...amounts,
|
|
125177
125188
|
replayed: receipt.replayed === true,
|
|
125178
125189
|
receiptFinality: receipt.receiptFinality ?? null,
|
|
125179
|
-
|
|
125190
|
+
// Leg 1 (this wallet's private payment to Shinjuku, a pool transaction): the seller may return no settle signature.
|
|
125191
|
+
...floatPaid ? { via: "shinjuku", shinjukuTransaction: typeof float.floatSettleTransaction === "string" ? float.floatSettleTransaction : null } : {},
|
|
125180
125192
|
...one ? { balanceAtomic: one.balanceAtomic, balance: one.balance, breakdown: one.breakdown } : {},
|
|
125181
|
-
next: receipt.replayed === true ? "this request id was already paid: the stored receipt came back and nothing new was paid" : floatPaid ? "paid through Shinjuku (privately: the chain shows Shinjuku paying the seller, not this wallet); tell the user the price (priceAtomic), the fee (feeAtomic), the total (amountAtomic), and the transaction. wallet_balance shows the new balance" : "paid; tell the user what was paid (amountAtomic, transaction). wallet_receipts lists this payment, wallet_balance shows the new balance"
|
|
125193
|
+
next: receipt.replayed === true ? "this request id was already paid: the stored receipt came back and nothing new was paid" : floatPaid ? "paid through Shinjuku (privately: the chain shows Shinjuku paying the seller, not this wallet); tell the user the price (priceAtomic), the fee (feeAtomic), the total (amountAtomic), and the transaction (the seller's settle transaction; null when the seller returned none) or shinjukuTransaction (this wallet's private payment to Shinjuku). wallet_balance shows the new balance" : "paid; tell the user what was paid (amountAtomic, transaction). wallet_receipts lists this payment, wallet_balance shows the new balance"
|
|
125182
125194
|
}
|
|
125183
125195
|
}));
|
|
125184
125196
|
}
|
|
@@ -132976,7 +132988,7 @@ var COMMANDS = [
|
|
|
132976
132988
|
"The provers are Linux programs. Linux: ready. Windows: the wallet runs them through WSL; setup checks that wsl.exe runs (wsl --install -d Ubuntu otherwise). macOS: not supported; setup says so and creates nothing.",
|
|
132977
132989
|
"Run it again at any time: it never changes an existing wallet, keeps the recorded caps unless you pass new ones, checks every proof-tool file again, downloads what is missing or newer, and rewrites config.json.",
|
|
132978
132990
|
"Then mcp needs no flags: npx -y shinjuku-shielded mcp reads config.json (a flag on the command line still wins). Before setup, mcp in a terminal offers to run setup; started by an agent host, it serves shinjuku_setup, which runs this same setup after you confirm in the host.",
|
|
132979
|
-
"A command that takes --pool (balance, recover, deposit, add-funds, and others) takes it, and the passphrase of this home's wallet, from config.json when you leave them out: shinjuku-wallet balance needs no flags. A flag or SHIELDED_WALLET_PASSPHRASE still wins; init and restore never use config.json, and move reads it itself."
|
|
132991
|
+
"A command that takes --pool (balance, recover, deposit, add-funds, and others) takes it, and the passphrase of this home's wallet, from config.json when you leave them out: shinjuku-wallet balance needs no flags. A pocket command (pocket list, scan, reshield, release, fill) takes this home's --wallet and passphrase file the same way, and --program, --proof-tools, --facilitator when it needs them. A flag or SHIELDED_WALLET_PASSPHRASE still wins; init and restore never use config.json, and move reads it itself."
|
|
132980
132992
|
],
|
|
132981
132993
|
next: `start it from your agent host with npx -y shinjuku-shielded mcp (or ${CLI2} mcp), then ask your agent "what is my balance"`,
|
|
132982
132994
|
run: (args, values, deps, io) => deps.setupMain(values, { ...deps, io })
|
|
@@ -133657,17 +133669,30 @@ function configDefaults(command, args, deps) {
|
|
|
133657
133669
|
const passphraseFileSpec = command.flags.find((spec) => spec.name === "--passphrase-file");
|
|
133658
133670
|
const envPassphrase = Boolean(deps.env[PASSPHRASE_ENV2]);
|
|
133659
133671
|
const wantPool = has2("--pool") && !given.has("--pool") && !given.has("--wallet");
|
|
133672
|
+
const wantWallet = !has2("--pool") && has2("--wallet") && !given.has("--wallet");
|
|
133660
133673
|
const wantFile = Boolean(passphraseFileSpec) && !given.has("--passphrase-file") && (passphraseFileSpec.required || !envPassphrase);
|
|
133661
133674
|
const wantEnv = !passphraseFileSpec && command.env.includes(PASSPHRASE_ENV2) && !envPassphrase;
|
|
133662
|
-
if (!wantPool && !wantFile && !wantEnv) return unchanged;
|
|
133675
|
+
if (!wantPool && !wantWallet && !wantFile && !wantEnv) return unchanged;
|
|
133663
133676
|
const home = setupHome(deps.env);
|
|
133664
133677
|
const config = setupConfigOf(home);
|
|
133665
133678
|
if (!config) return unchanged;
|
|
133666
|
-
const added = wantPool ? ["--pool", config.pool] : [];
|
|
133679
|
+
const added = wantPool ? ["--pool", config.pool] : wantWallet ? ["--wallet", homeWalletPath(home, config.pool)] : [];
|
|
133680
|
+
const fromConfig = [
|
|
133681
|
+
["--program", config.program],
|
|
133682
|
+
["--proof-tools", config.proofTools],
|
|
133683
|
+
["--facilitator", config.memoService],
|
|
133684
|
+
["--service", config.memoService]
|
|
133685
|
+
];
|
|
133686
|
+
if (wantPool || wantWallet || given.has("--wallet") || given.get("--pool") === config.pool) {
|
|
133687
|
+
for (const [name, value] of fromConfig) {
|
|
133688
|
+
if (typeof value === "string" && command.flags.some((spec) => spec.name === name && spec.required) && !given.has(name)) added.push(name, value);
|
|
133689
|
+
}
|
|
133690
|
+
}
|
|
133667
133691
|
const pool = wantPool ? config.pool : given.get("--pool");
|
|
133668
133692
|
const homePools = [config.pool, ...(config.previousPools ?? []).map((entry) => entry.pool)];
|
|
133669
|
-
const ownWallet = given.has("--wallet") ? homePools.some((entry) => resolve35(given.get("--wallet")) === resolve35(homeWalletPath(home, entry))) : homePools.includes(pool);
|
|
133670
|
-
if (!ownWallet
|
|
133693
|
+
const ownWallet = wantWallet || (given.has("--wallet") ? homePools.some((entry) => resolve35(given.get("--wallet")) === resolve35(homeWalletPath(home, entry))) : homePools.includes(pool));
|
|
133694
|
+
if (!ownWallet) return unchanged;
|
|
133695
|
+
if (!wantFile && !wantEnv) return { args: [...args, ...added], passphrase: void 0 };
|
|
133671
133696
|
const where = `config.json (${join34(home, "config.json")})`;
|
|
133672
133697
|
if (wantFile) {
|
|
133673
133698
|
if (!config.passphraseFile) {
|