vapi-network 0.12.1 → 0.13.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/README.md +17 -1
- package/SKILL.md +1 -1
- package/dist/cli.js +1447 -1205
- package/dist/cli.js.map +3 -3
- package/dist/index.js +1470 -1219
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6673,7 +6673,7 @@ function weierstrass(curveDef) {
|
|
|
6673
6673
|
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
6674
6674
|
if (["recovered", "canonical"].some((k) => k in opts))
|
|
6675
6675
|
throw new Error("sign() legacy options not supported");
|
|
6676
|
-
const { hash: hash5, randomBytes:
|
|
6676
|
+
const { hash: hash5, randomBytes: randomBytes18 } = CURVE;
|
|
6677
6677
|
let { lowS, prehash, extraEntropy: ent } = opts;
|
|
6678
6678
|
if (lowS == null)
|
|
6679
6679
|
lowS = true;
|
|
@@ -6685,7 +6685,7 @@ function weierstrass(curveDef) {
|
|
|
6685
6685
|
const d = normPrivateKeyToScalar(privateKey);
|
|
6686
6686
|
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
6687
6687
|
if (ent != null && ent !== false) {
|
|
6688
|
-
const e3 = ent === true ?
|
|
6688
|
+
const e3 = ent === true ? randomBytes18(Fp.BYTES) : ent;
|
|
6689
6689
|
seedArgs.push(ensureBytes("extraEntropy", e3));
|
|
6690
6690
|
}
|
|
6691
6691
|
const seed = concatBytes3(...seedArgs);
|
|
@@ -10118,8 +10118,8 @@ var init_call = __esm({
|
|
|
10118
10118
|
|
|
10119
10119
|
// ../cli/src/cli.ts
|
|
10120
10120
|
import { spawn as spawn5 } from "node:child_process";
|
|
10121
|
-
import { stat as
|
|
10122
|
-
import { join as
|
|
10121
|
+
import { stat as stat18 } from "node:fs/promises";
|
|
10122
|
+
import { join as join30 } from "node:path";
|
|
10123
10123
|
import { createInterface as createInterface3 } from "node:readline/promises";
|
|
10124
10124
|
|
|
10125
10125
|
// ../../node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/external.js
|
|
@@ -45227,9 +45227,9 @@ var X402Error = class extends Error {
|
|
|
45227
45227
|
function isValidPaymentId(value) {
|
|
45228
45228
|
return typeof value === "string" && PAYMENT_ID_PATTERN.test(value);
|
|
45229
45229
|
}
|
|
45230
|
-
function createPaymentId(
|
|
45230
|
+
function createPaymentId(randomBytes18 = fillRandomBytes) {
|
|
45231
45231
|
const bytes = new Uint8Array(16);
|
|
45232
|
-
|
|
45232
|
+
randomBytes18(bytes);
|
|
45233
45233
|
return `pay_${bytesToHex(bytes).slice(2)}`;
|
|
45234
45234
|
}
|
|
45235
45235
|
function buildPaymentExtensions(serverExtensions, options = {}) {
|
|
@@ -46620,8 +46620,8 @@ function conciseError(error61) {
|
|
|
46620
46620
|
}
|
|
46621
46621
|
|
|
46622
46622
|
// ../core/src/account-add.ts
|
|
46623
|
-
import { stat as
|
|
46624
|
-
import { join as
|
|
46623
|
+
import { stat as stat10 } from "node:fs/promises";
|
|
46624
|
+
import { join as join10 } from "node:path";
|
|
46625
46625
|
|
|
46626
46626
|
// ../core/src/agent-link.ts
|
|
46627
46627
|
import { createHash } from "node:crypto";
|
|
@@ -70033,20 +70033,20 @@ async function promptForSecret(prompt, noTerminalHint) {
|
|
|
70033
70033
|
}
|
|
70034
70034
|
|
|
70035
70035
|
// ../core/src/wallet-store.ts
|
|
70036
|
-
import { randomBytes as
|
|
70036
|
+
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
70037
70037
|
import {
|
|
70038
70038
|
chmod as chmod3,
|
|
70039
70039
|
lstat as lstat2,
|
|
70040
70040
|
mkdir as mkdir10,
|
|
70041
|
-
open as
|
|
70041
|
+
open as open8,
|
|
70042
70042
|
readdir as readdir3,
|
|
70043
|
-
readFile as
|
|
70043
|
+
readFile as readFile12,
|
|
70044
70044
|
rename as rename7,
|
|
70045
|
-
stat as
|
|
70045
|
+
stat as stat9,
|
|
70046
70046
|
unlink as unlink6,
|
|
70047
70047
|
writeFile as writeFile5
|
|
70048
70048
|
} from "node:fs/promises";
|
|
70049
|
-
import { dirname as dirname7, join as
|
|
70049
|
+
import { dirname as dirname7, join as join9 } from "node:path";
|
|
70050
70050
|
|
|
70051
70051
|
// ../core/src/account-movement-lock.ts
|
|
70052
70052
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
@@ -70164,505 +70164,16 @@ function isOpenMovementLeg(leg, journalEvidence) {
|
|
|
70164
70164
|
// ../core/src/secret-store.ts
|
|
70165
70165
|
import { spawn } from "node:child_process";
|
|
70166
70166
|
import { existsSync } from "node:fs";
|
|
70167
|
-
import { delimiter, isAbsolute, join as
|
|
70168
|
-
var SECRET_STORE_SERVICE = "vapi-network";
|
|
70169
|
-
var SECURITY_BINARY = "/usr/bin/security";
|
|
70170
|
-
var SECRET_TOOL_BINARY = "secret-tool";
|
|
70171
|
-
var WINDOWS_POWERSHELL_ARGS = ["-NoProfile", "-NonInteractive", "-Command", "-"];
|
|
70172
|
-
var SECURITY_ITEM_NOT_FOUND = 44;
|
|
70173
|
-
var WINDOWS_SECRET_SUCCESS = 0;
|
|
70174
|
-
var WINDOWS_SECRET_NOT_FOUND = 2;
|
|
70175
|
-
var UNSUPPORTED_PLATFORM = "No OS secret store on this platform yet; use VAPI_KEYSTORE_PASSWORD.";
|
|
70176
|
-
var SECRET_TOOL_MISSING = [
|
|
70177
|
-
"secret-tool is not installed, so the passphrase cannot be kept in the OS secret store.",
|
|
70178
|
-
"Install libsecret-tools (Debian, Ubuntu) or libsecret (Fedora, Arch), or use VAPI_KEYSTORE_PASSWORD."
|
|
70179
|
-
].join(" ");
|
|
70180
|
-
var POWERSHELL_MISSING = [
|
|
70181
|
-
"Windows PowerShell (powershell.exe) was not found, so the passphrase cannot be kept in the OS secret store.",
|
|
70182
|
-
"Use VAPI_KEYSTORE_PASSWORD."
|
|
70183
|
-
].join(" ");
|
|
70184
|
-
function secretStore(options = {}) {
|
|
70185
|
-
const platform2 = options.platform ?? process.platform;
|
|
70186
|
-
const run = options.run ?? (async (file2, args, input2) => await spawnRunner(platform2, file2, args, input2));
|
|
70187
|
-
const env = options.env ?? process.env;
|
|
70188
|
-
const installed = options.installed ?? ((file2) => binaryInstalled(file2, env));
|
|
70189
|
-
if (platform2 === "darwin") return keychainStore(platform2, run);
|
|
70190
|
-
if (platform2 === "win32") return windowsDataProtectionStore(platform2, run, env, installed);
|
|
70191
|
-
if (platform2 === "linux") return libsecretStore(platform2, run, installed);
|
|
70192
|
-
return unsupportedStore(platform2);
|
|
70193
|
-
}
|
|
70194
|
-
function memorySecretStore(initial = {}) {
|
|
70195
|
-
const entries = new Map(Object.entries(initial));
|
|
70196
|
-
return {
|
|
70197
|
-
available: true,
|
|
70198
|
-
platform: process.platform,
|
|
70199
|
-
description: "an in-memory store",
|
|
70200
|
-
async get(name) {
|
|
70201
|
-
return entries.get(name);
|
|
70202
|
-
},
|
|
70203
|
-
async has(name) {
|
|
70204
|
-
return entries.has(name);
|
|
70205
|
-
},
|
|
70206
|
-
async set(name, passphrase) {
|
|
70207
|
-
entries.set(name, passphrase);
|
|
70208
|
-
},
|
|
70209
|
-
async remove(name) {
|
|
70210
|
-
return entries.delete(name);
|
|
70211
|
-
},
|
|
70212
|
-
async list() {
|
|
70213
|
-
return [...entries.keys()].sort();
|
|
70214
|
-
}
|
|
70215
|
-
};
|
|
70216
|
-
}
|
|
70217
|
-
function keychainStore(platform2, run) {
|
|
70218
|
-
const find = async (account, withPassword) => await run(SECURITY_BINARY, [
|
|
70219
|
-
"find-generic-password",
|
|
70220
|
-
"-a",
|
|
70221
|
-
account,
|
|
70222
|
-
"-s",
|
|
70223
|
-
SECRET_STORE_SERVICE,
|
|
70224
|
-
...withPassword ? ["-w"] : []
|
|
70225
|
-
]);
|
|
70226
|
-
const read = async (account, what) => {
|
|
70227
|
-
const result = await find(account, true);
|
|
70228
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return void 0;
|
|
70229
|
-
requireSuccess(result, what);
|
|
70230
|
-
const value = withoutTrailingNewline(result.stdout);
|
|
70231
|
-
return value.length === 0 ? void 0 : value;
|
|
70232
|
-
};
|
|
70233
|
-
const write2 = async (account, value, what) => {
|
|
70234
|
-
const result = await run(
|
|
70235
|
-
SECURITY_BINARY,
|
|
70236
|
-
[
|
|
70237
|
-
"add-generic-password",
|
|
70238
|
-
"-a",
|
|
70239
|
-
account,
|
|
70240
|
-
"-s",
|
|
70241
|
-
SECRET_STORE_SERVICE,
|
|
70242
|
-
"-l",
|
|
70243
|
-
`${SECRET_STORE_SERVICE} ${account}`,
|
|
70244
|
-
"-U",
|
|
70245
|
-
"-w"
|
|
70246
|
-
],
|
|
70247
|
-
// `security` asks for the password and then for its confirmation.
|
|
70248
|
-
`${value}
|
|
70249
|
-
${value}
|
|
70250
|
-
`
|
|
70251
|
-
);
|
|
70252
|
-
requireSuccess(result, what);
|
|
70253
|
-
};
|
|
70254
|
-
const erase = async (account, what) => {
|
|
70255
|
-
const result = await run(SECURITY_BINARY, [
|
|
70256
|
-
"delete-generic-password",
|
|
70257
|
-
"-a",
|
|
70258
|
-
account,
|
|
70259
|
-
"-s",
|
|
70260
|
-
SECRET_STORE_SERVICE
|
|
70261
|
-
]);
|
|
70262
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70263
|
-
requireSuccess(result, what);
|
|
70264
|
-
return true;
|
|
70265
|
-
};
|
|
70266
|
-
const erasePartsAfter = async (account, keep, what) => {
|
|
70267
|
-
for (let part = keep + 1; part <= MAX_KEYCHAIN_PARTS; part += 1) {
|
|
70268
|
-
if (!await erase(keychainPart(account, part), what)) return;
|
|
70269
|
-
}
|
|
70270
|
-
};
|
|
70271
|
-
return {
|
|
70272
|
-
available: true,
|
|
70273
|
-
platform: platform2,
|
|
70274
|
-
description: "the macOS Keychain",
|
|
70275
|
-
async get(name) {
|
|
70276
|
-
const account = accountFor(name);
|
|
70277
|
-
const what = `read the passphrase of ${name} from the macOS Keychain`;
|
|
70278
|
-
const value = await read(account, what);
|
|
70279
|
-
const parts = value === void 0 ? void 0 : chunkedPartCount(value);
|
|
70280
|
-
if (value === void 0 || parts === void 0) return value;
|
|
70281
|
-
let joined = "";
|
|
70282
|
-
for (let part = 1; part <= parts; part += 1) {
|
|
70283
|
-
const chunk = await read(keychainPart(account, part), what);
|
|
70284
|
-
if (chunk === void 0) {
|
|
70285
|
-
throw new KeystoreError(
|
|
70286
|
-
`The stored secret ${name} is incomplete in the macOS Keychain. Store it again.`
|
|
70287
|
-
);
|
|
70288
|
-
}
|
|
70289
|
-
joined += chunk;
|
|
70290
|
-
}
|
|
70291
|
-
return joined;
|
|
70292
|
-
},
|
|
70293
|
-
async has(name) {
|
|
70294
|
-
const result = await find(accountFor(name), false);
|
|
70295
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70296
|
-
requireSuccess(result, `look up ${name} in the macOS Keychain`);
|
|
70297
|
-
return true;
|
|
70298
|
-
},
|
|
70299
|
-
async set(name, passphrase) {
|
|
70300
|
-
requirePassphrase(passphrase);
|
|
70301
|
-
const account = accountFor(name);
|
|
70302
|
-
const what = `store the passphrase of ${name} in the macOS Keychain`;
|
|
70303
|
-
if (passphrase.length <= KEYCHAIN_PROMPT_LIMIT) {
|
|
70304
|
-
await write2(account, passphrase, what);
|
|
70305
|
-
return;
|
|
70306
|
-
}
|
|
70307
|
-
const chunks = [];
|
|
70308
|
-
for (let index2 = 0; index2 < passphrase.length; index2 += KEYCHAIN_CHUNK) {
|
|
70309
|
-
chunks.push(passphrase.slice(index2, index2 + KEYCHAIN_CHUNK));
|
|
70310
|
-
}
|
|
70311
|
-
if (chunks.length > MAX_KEYCHAIN_PARTS) {
|
|
70312
|
-
throw new KeystoreError(`The secret ${name} is too long for the macOS Keychain.`);
|
|
70313
|
-
}
|
|
70314
|
-
for (const [index2, chunk] of chunks.entries()) {
|
|
70315
|
-
await write2(keychainPart(account, index2 + 1), chunk, what);
|
|
70316
|
-
}
|
|
70317
|
-
await erasePartsAfter(account, chunks.length, what);
|
|
70318
|
-
await write2(account, `${CHUNKED_MARKER}${chunks.length}`, what);
|
|
70319
|
-
},
|
|
70320
|
-
async remove(name) {
|
|
70321
|
-
const account = accountFor(name);
|
|
70322
|
-
const what = `remove the passphrase of ${name} from the macOS Keychain`;
|
|
70323
|
-
const found = await find(account, true);
|
|
70324
|
-
if (found.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70325
|
-
requireSuccess(found, what);
|
|
70326
|
-
if (chunkedPartCount(withoutTrailingNewline(found.stdout)) !== void 0) {
|
|
70327
|
-
await erasePartsAfter(account, 0, what);
|
|
70328
|
-
}
|
|
70329
|
-
return await erase(account, what);
|
|
70330
|
-
}
|
|
70331
|
-
};
|
|
70332
|
-
}
|
|
70333
|
-
var KEYCHAIN_PROMPT_LIMIT = 128;
|
|
70334
|
-
var KEYCHAIN_CHUNK = 120;
|
|
70335
|
-
var MAX_KEYCHAIN_PARTS = 32;
|
|
70336
|
-
var CHUNKED_MARKER = "vapi-chunked:v1:";
|
|
70337
|
-
function keychainPart(account, part) {
|
|
70338
|
-
return `${account}#${part}`;
|
|
70339
|
-
}
|
|
70340
|
-
function chunkedPartCount(value) {
|
|
70341
|
-
if (!value.startsWith(CHUNKED_MARKER)) return void 0;
|
|
70342
|
-
const parts = Number(value.slice(CHUNKED_MARKER.length));
|
|
70343
|
-
return Number.isInteger(parts) && parts > 0 && parts <= MAX_KEYCHAIN_PARTS ? parts : void 0;
|
|
70344
|
-
}
|
|
70345
|
-
function windowsSecretFileName(account) {
|
|
70346
|
-
let encoded = "";
|
|
70347
|
-
for (let index2 = 0; index2 < account.length; index2 += 1) {
|
|
70348
|
-
const character = account[index2];
|
|
70349
|
-
if (/^[a-z0-9._#-]$/u.test(character)) {
|
|
70350
|
-
encoded += character;
|
|
70351
|
-
continue;
|
|
70352
|
-
}
|
|
70353
|
-
encoded += `%${account.charCodeAt(index2).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
70354
|
-
}
|
|
70355
|
-
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu.test(encoded)) {
|
|
70356
|
-
encoded = `%${encoded.charCodeAt(0).toString(16).toUpperCase()}${encoded.slice(1)}`;
|
|
70357
|
-
}
|
|
70358
|
-
return `${encoded}.bin`;
|
|
70359
|
-
}
|
|
70360
|
-
function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
70361
|
-
const powershell = `${env.SystemRoot ?? "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
70362
|
-
const fileDetails = (name) => {
|
|
70363
|
-
const file2 = windowsSecretFileName(accountFor(name));
|
|
70364
|
-
return { file: file2, account: file2.slice(0, -".bin".length) };
|
|
70365
|
-
};
|
|
70366
|
-
const script = (file2, operations) => [
|
|
70367
|
-
"$ErrorActionPreference = 'Stop'",
|
|
70368
|
-
"try {",
|
|
70369
|
-
" Add-Type -AssemblyName System.Security",
|
|
70370
|
-
" $dir = Join-Path $env:LOCALAPPDATA 'vapi-network\\secrets'",
|
|
70371
|
-
` $path = Join-Path $dir '${file2}'`,
|
|
70372
|
-
...operations.map((operation) => ` ${operation}`),
|
|
70373
|
-
"} catch {",
|
|
70374
|
-
" [Console]::Error.WriteLine($_.Exception.Message)",
|
|
70375
|
-
" exit 1",
|
|
70376
|
-
"}"
|
|
70377
|
-
].join("\n");
|
|
70378
|
-
const execute = async (script2) => {
|
|
70379
|
-
const result = await run(powershell, WINDOWS_POWERSHELL_ARGS, `${script2}
|
|
70380
|
-
|
|
70381
|
-
`);
|
|
70382
|
-
requirePowerShell(result);
|
|
70383
|
-
return result;
|
|
70384
|
-
};
|
|
70385
|
-
return {
|
|
70386
|
-
available: installed(powershell),
|
|
70387
|
-
platform: platform2,
|
|
70388
|
-
description: "Windows Data Protection (DPAPI)",
|
|
70389
|
-
async get(name) {
|
|
70390
|
-
const { file: file2, account } = fileDetails(name);
|
|
70391
|
-
const result = await execute(
|
|
70392
|
-
script(file2, [
|
|
70393
|
-
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
70394
|
-
"$blob = [System.IO.File]::ReadAllBytes($path)",
|
|
70395
|
-
"$bytes = [System.Security.Cryptography.ProtectedData]::Unprotect($blob, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
70396
|
-
"[Console]::Out.Write([Convert]::ToBase64String($bytes))",
|
|
70397
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70398
|
-
])
|
|
70399
|
-
);
|
|
70400
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return void 0;
|
|
70401
|
-
requireSuccess(result, `read the passphrase of ${name} from Windows Data Protection`);
|
|
70402
|
-
const value = Buffer.from(result.stdout.trim(), "base64").toString("utf8");
|
|
70403
|
-
return value.length === 0 ? void 0 : value;
|
|
70404
|
-
},
|
|
70405
|
-
async has(name) {
|
|
70406
|
-
const { file: file2, account } = fileDetails(name);
|
|
70407
|
-
const result = await execute(
|
|
70408
|
-
script(file2, [
|
|
70409
|
-
`if (Test-Path -LiteralPath $path) { exit ${WINDOWS_SECRET_SUCCESS} }`,
|
|
70410
|
-
`[Console]::Error.WriteLine('No stored secret for ${account}.')`,
|
|
70411
|
-
`exit ${WINDOWS_SECRET_NOT_FOUND}`
|
|
70412
|
-
])
|
|
70413
|
-
);
|
|
70414
|
-
if (result.code === WINDOWS_SECRET_SUCCESS) return true;
|
|
70415
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
70416
|
-
requireSuccess(result, `look up ${name} in Windows Data Protection`);
|
|
70417
|
-
return false;
|
|
70418
|
-
},
|
|
70419
|
-
async set(name, passphrase) {
|
|
70420
|
-
requirePassphrase(passphrase);
|
|
70421
|
-
const { file: file2 } = fileDetails(name);
|
|
70422
|
-
const value = Buffer.from(passphrase, "utf8").toString("base64");
|
|
70423
|
-
const result = await execute(
|
|
70424
|
-
script(file2, [
|
|
70425
|
-
"[void][System.IO.Directory]::CreateDirectory($dir)",
|
|
70426
|
-
`$bytes = [Convert]::FromBase64String('${value}')`,
|
|
70427
|
-
"$blob = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
70428
|
-
"[System.IO.File]::WriteAllBytes($path, $blob)",
|
|
70429
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70430
|
-
])
|
|
70431
|
-
);
|
|
70432
|
-
requireSuccess(result, `store the passphrase of ${name} in Windows Data Protection`);
|
|
70433
|
-
},
|
|
70434
|
-
async remove(name) {
|
|
70435
|
-
const { file: file2, account } = fileDetails(name);
|
|
70436
|
-
const result = await execute(
|
|
70437
|
-
script(file2, [
|
|
70438
|
-
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
70439
|
-
"Remove-Item -LiteralPath $path -Force",
|
|
70440
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70441
|
-
])
|
|
70442
|
-
);
|
|
70443
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
70444
|
-
requireSuccess(result, `remove the passphrase of ${name} from Windows Data Protection`);
|
|
70445
|
-
return true;
|
|
70446
|
-
}
|
|
70447
|
-
};
|
|
70448
|
-
}
|
|
70449
|
-
function libsecretStore(platform2, run, installed) {
|
|
70450
|
-
const lookup2 = async (name) => {
|
|
70451
|
-
const result = await run(SECRET_TOOL_BINARY, [
|
|
70452
|
-
"lookup",
|
|
70453
|
-
"service",
|
|
70454
|
-
SECRET_STORE_SERVICE,
|
|
70455
|
-
"account",
|
|
70456
|
-
accountFor(name)
|
|
70457
|
-
]);
|
|
70458
|
-
requireBinary(result);
|
|
70459
|
-
const value = withoutTrailingNewline(result.stdout);
|
|
70460
|
-
if (result.code === 0) return value.length === 0 ? void 0 : value;
|
|
70461
|
-
if (result.stderr.trim().length === 0) return void 0;
|
|
70462
|
-
requireSuccess(result, `read the passphrase of ${name} from the secret service`);
|
|
70463
|
-
return void 0;
|
|
70464
|
-
};
|
|
70465
|
-
return {
|
|
70466
|
-
available: installed(SECRET_TOOL_BINARY),
|
|
70467
|
-
platform: platform2,
|
|
70468
|
-
description: "the libsecret keyring",
|
|
70469
|
-
get: lookup2,
|
|
70470
|
-
async has(name) {
|
|
70471
|
-
return await lookup2(name) !== void 0;
|
|
70472
|
-
},
|
|
70473
|
-
async set(name, passphrase) {
|
|
70474
|
-
requirePassphrase(passphrase);
|
|
70475
|
-
const account = accountFor(name);
|
|
70476
|
-
const result = await run(
|
|
70477
|
-
SECRET_TOOL_BINARY,
|
|
70478
|
-
[
|
|
70479
|
-
"store",
|
|
70480
|
-
`--label=${SECRET_STORE_SERVICE} ${account}`,
|
|
70481
|
-
"service",
|
|
70482
|
-
SECRET_STORE_SERVICE,
|
|
70483
|
-
"account",
|
|
70484
|
-
account
|
|
70485
|
-
],
|
|
70486
|
-
`${passphrase}
|
|
70487
|
-
`
|
|
70488
|
-
);
|
|
70489
|
-
requireBinary(result);
|
|
70490
|
-
requireSuccess(result, `store the passphrase of ${name} in the secret service`);
|
|
70491
|
-
},
|
|
70492
|
-
async remove(name) {
|
|
70493
|
-
const existed = await lookup2(name) !== void 0;
|
|
70494
|
-
const result = await run(SECRET_TOOL_BINARY, [
|
|
70495
|
-
"clear",
|
|
70496
|
-
"service",
|
|
70497
|
-
SECRET_STORE_SERVICE,
|
|
70498
|
-
"account",
|
|
70499
|
-
accountFor(name)
|
|
70500
|
-
]);
|
|
70501
|
-
requireBinary(result);
|
|
70502
|
-
requireSuccess(result, `remove the passphrase of ${name} from the secret service`);
|
|
70503
|
-
return existed;
|
|
70504
|
-
}
|
|
70505
|
-
};
|
|
70506
|
-
}
|
|
70507
|
-
function unsupportedStore(platform2) {
|
|
70508
|
-
const refuse = () => {
|
|
70509
|
-
throw new KeystoreError(UNSUPPORTED_PLATFORM);
|
|
70510
|
-
};
|
|
70511
|
-
return {
|
|
70512
|
-
available: false,
|
|
70513
|
-
platform: platform2,
|
|
70514
|
-
description: "no OS secret store",
|
|
70515
|
-
get: async () => refuse(),
|
|
70516
|
-
has: async () => refuse(),
|
|
70517
|
-
set: async () => refuse(),
|
|
70518
|
-
remove: async () => refuse()
|
|
70519
|
-
};
|
|
70520
|
-
}
|
|
70521
|
-
function accountFor(name) {
|
|
70522
|
-
const account = name.trim();
|
|
70523
|
-
if (account.length === 0) {
|
|
70524
|
-
throw new KeystoreError("A wallet name is needed to reach the OS secret store.");
|
|
70525
|
-
}
|
|
70526
|
-
return account;
|
|
70527
|
-
}
|
|
70528
|
-
function requirePassphrase(passphrase) {
|
|
70529
|
-
if (passphrase.length === 0) {
|
|
70530
|
-
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
70531
|
-
}
|
|
70532
|
-
}
|
|
70533
|
-
function requireBinary(result) {
|
|
70534
|
-
if (result.notFound === true) throw new KeystoreError(SECRET_TOOL_MISSING);
|
|
70535
|
-
}
|
|
70536
|
-
function requirePowerShell(result) {
|
|
70537
|
-
if (result.notFound === true) throw new KeystoreError(POWERSHELL_MISSING);
|
|
70538
|
-
}
|
|
70539
|
-
function binaryInstalled(file2, env) {
|
|
70540
|
-
if (isAbsolute(file2) || win32.isAbsolute(file2)) return existsSync(file2);
|
|
70541
|
-
return (env.PATH ?? "").split(delimiter).some((directory) => existsSync(join6(directory, file2)));
|
|
70542
|
-
}
|
|
70543
|
-
var SAFE_FAILURE_DETAILS = [
|
|
70544
|
-
"Cannot autolaunch D-Bus without X11 $DISPLAY",
|
|
70545
|
-
"Cannot autolaunch D-Bus",
|
|
70546
|
-
"The name org.freedesktop.secrets was not provided by any .service files",
|
|
70547
|
-
"Cannot create an item in a locked collection",
|
|
70548
|
-
"User interaction is not allowed.",
|
|
70549
|
-
"Access to the path is denied."
|
|
70550
|
-
];
|
|
70551
|
-
function requireSuccess(result, what) {
|
|
70552
|
-
if (result.code === 0) return;
|
|
70553
|
-
const detail = SAFE_FAILURE_DETAILS.find((reason) => result.stderr.includes(reason));
|
|
70554
|
-
throw new KeystoreError(
|
|
70555
|
-
`Could not ${what}${result.code === null ? "" : ` (exit ${result.code})`}.${detail === void 0 ? "" : ` ${detail}`}`
|
|
70556
|
-
);
|
|
70557
|
-
}
|
|
70558
|
-
function withoutTrailingNewline(value) {
|
|
70559
|
-
return value.replace(/\r?\n$/u, "");
|
|
70560
|
-
}
|
|
70561
|
-
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve3) => {
|
|
70562
|
-
let stdout = "";
|
|
70563
|
-
let stderr2 = "";
|
|
70564
|
-
let settled = false;
|
|
70565
|
-
const finish = (outcome) => {
|
|
70566
|
-
if (settled) return;
|
|
70567
|
-
settled = true;
|
|
70568
|
-
resolve3(outcome);
|
|
70569
|
-
};
|
|
70570
|
-
const child = spawn(file2, [...args], {
|
|
70571
|
-
detached: platform2 !== "win32",
|
|
70572
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
70573
|
-
windowsHide: true
|
|
70574
|
-
});
|
|
70575
|
-
child.stdout?.setEncoding("utf8");
|
|
70576
|
-
child.stdout?.on("data", (chunk) => {
|
|
70577
|
-
stdout += chunk;
|
|
70578
|
-
});
|
|
70579
|
-
child.stderr?.setEncoding("utf8");
|
|
70580
|
-
child.stderr?.on("data", (chunk) => {
|
|
70581
|
-
stderr2 += chunk;
|
|
70582
|
-
});
|
|
70583
|
-
child.on("error", (error61) => {
|
|
70584
|
-
finish({
|
|
70585
|
-
code: null,
|
|
70586
|
-
stdout,
|
|
70587
|
-
stderr: stderr2,
|
|
70588
|
-
...error61.code === "ENOENT" ? { notFound: true } : {}
|
|
70589
|
-
});
|
|
70590
|
-
});
|
|
70591
|
-
child.on("close", (code) => finish({ code, stdout, stderr: stderr2 }));
|
|
70592
|
-
child.stdin?.on("error", () => void 0);
|
|
70593
|
-
child.stdin?.end(input2 ?? "");
|
|
70594
|
-
});
|
|
70595
|
-
|
|
70596
|
-
// ../core/src/passphrase.ts
|
|
70597
|
-
var PASSPHRASE_ENVIRONMENT_VARIABLE = "VAPI_KEYSTORE_PASSWORD";
|
|
70598
|
-
function noPassphraseHint(walletName) {
|
|
70599
|
-
return `Set ${PASSPHRASE_ENVIRONMENT_VARIABLE}, or store this wallet's passphrase once with vapi unlock --wallet ${walletName}.`;
|
|
70600
|
-
}
|
|
70601
|
-
function staleStoredPassphraseMessage(walletName, store) {
|
|
70602
|
-
return [
|
|
70603
|
-
`The passphrase stored in ${store.description} no longer opens wallet ${walletName}.`,
|
|
70604
|
-
`Store the current one with vapi unlock --wallet ${walletName}, or remove it with vapi lock --wallet ${walletName}.`
|
|
70605
|
-
].join(" ");
|
|
70606
|
-
}
|
|
70607
|
-
async function resolvePassphrase(walletName, options = {}) {
|
|
70608
|
-
const env = options.env ?? process.env;
|
|
70609
|
-
const fromEnvironment = env[PASSPHRASE_ENVIRONMENT_VARIABLE];
|
|
70610
|
-
if (fromEnvironment !== void 0) {
|
|
70611
|
-
if (fromEnvironment.length === 0) {
|
|
70612
|
-
throw new KeystoreError(`${PASSPHRASE_ENVIRONMENT_VARIABLE} cannot be empty.`);
|
|
70613
|
-
}
|
|
70614
|
-
return { passphrase: fromEnvironment, source: "environment" };
|
|
70615
|
-
}
|
|
70616
|
-
if (options.confirm !== true) {
|
|
70617
|
-
const stored = await readStored(options.store ?? secretStore(), walletName);
|
|
70618
|
-
if (stored !== void 0) return { passphrase: stored, source: "secret-store" };
|
|
70619
|
-
}
|
|
70620
|
-
const hint = noPassphraseHint(walletName);
|
|
70621
|
-
if (options.interactive === false) {
|
|
70622
|
-
throw new KeystoreError(
|
|
70623
|
-
`No interactive terminal is available for the keystore prompt. ${hint}`
|
|
70624
|
-
);
|
|
70625
|
-
}
|
|
70626
|
-
const prompt = options.prompt ?? promptForSecret;
|
|
70627
|
-
const first = await prompt(`Passphrase for ${walletName}: `, hint);
|
|
70628
|
-
if (first.length === 0) {
|
|
70629
|
-
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
70630
|
-
}
|
|
70631
|
-
if (options.confirm === true) {
|
|
70632
|
-
const second = await prompt("Confirm passphrase: ", hint);
|
|
70633
|
-
if (first !== second) throw new KeystoreError("Passphrases do not match.");
|
|
70634
|
-
}
|
|
70635
|
-
return { passphrase: first, source: "prompt" };
|
|
70636
|
-
}
|
|
70637
|
-
async function readStored(store, walletName) {
|
|
70638
|
-
if (!store.available) return void 0;
|
|
70639
|
-
try {
|
|
70640
|
-
return await store.get(walletName);
|
|
70641
|
-
} catch {
|
|
70642
|
-
return void 0;
|
|
70643
|
-
}
|
|
70644
|
-
}
|
|
70167
|
+
import { delimiter, isAbsolute, join as join7, win32 } from "node:path";
|
|
70645
70168
|
|
|
70646
|
-
// ../core/src/
|
|
70169
|
+
// ../core/src/file-secret-store.ts
|
|
70647
70170
|
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
70648
|
-
import {
|
|
70649
|
-
import { dirname as dirname5 } from "node:path";
|
|
70171
|
+
import { readFile as readFile8, stat as stat7 } from "node:fs/promises";
|
|
70650
70172
|
|
|
70651
|
-
// ../core/src/
|
|
70173
|
+
// ../core/src/vault.ts
|
|
70652
70174
|
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
70653
|
-
|
|
70654
|
-
|
|
70655
|
-
return typeof value === "string" && RUN_ID_PATTERN.test(value);
|
|
70656
|
-
}
|
|
70657
|
-
function createRunId(random = randomBytes5) {
|
|
70658
|
-
return `run_${Buffer.from(random(12)).toString("hex")}`;
|
|
70659
|
-
}
|
|
70660
|
-
var runRefSchema = external_exports.strictObject({
|
|
70661
|
-
id: external_exports.string().regex(RUN_ID_PATTERN),
|
|
70662
|
-
swarm: external_exports.string().optional(),
|
|
70663
|
-
member: external_exports.string().optional(),
|
|
70664
|
-
parentRunId: external_exports.string().optional()
|
|
70665
|
-
});
|
|
70175
|
+
import { mkdir as mkdir7, open as open5, readFile as readFile7, rename as rename4, rm, stat as stat6, unlink as unlink4, writeFile as writeFile3 } from "node:fs/promises";
|
|
70176
|
+
import { dirname as dirname5 } from "node:path";
|
|
70666
70177
|
|
|
70667
70178
|
// ../core/src/wallet-name.ts
|
|
70668
70179
|
var DEFAULT_WALLET_NAME = "main";
|
|
@@ -70675,260 +70186,7 @@ function isWalletName(value) {
|
|
|
70675
70186
|
return WALLET_NAME_PATTERN.test(value);
|
|
70676
70187
|
}
|
|
70677
70188
|
|
|
70678
|
-
// ../core/src/receipts.ts
|
|
70679
|
-
var receiptTestHooks;
|
|
70680
|
-
var RECEIPT_JOURNAL_BUSY_MESSAGE = "The receipt journal is busy. Wait for the other vapi command to finish, then retry.";
|
|
70681
|
-
async function withReceiptJournalLock(path, operation) {
|
|
70682
|
-
return await withFileLock(`${path}.lock`, operation, {
|
|
70683
|
-
lockedMessage: RECEIPT_JOURNAL_BUSY_MESSAGE
|
|
70684
|
-
});
|
|
70685
|
-
}
|
|
70686
|
-
var durationSchema = external_exports.number().nonnegative().finite();
|
|
70687
|
-
var receiptSchema = external_exports.strictObject({
|
|
70688
|
-
id: external_exports.string().min(1),
|
|
70689
|
-
timestamp: external_exports.iso.datetime(),
|
|
70690
|
-
run: runRefSchema.optional(),
|
|
70691
|
-
kind: external_exports.literal("transfer").optional(),
|
|
70692
|
-
wallet: walletNameSchema.optional(),
|
|
70693
|
-
resourceUrl: external_exports.url(),
|
|
70694
|
-
method: external_exports.string().min(1).optional(),
|
|
70695
|
-
source: external_exports.string().min(1).optional(),
|
|
70696
|
-
provenance: external_exports.array(
|
|
70697
|
-
external_exports.strictObject({
|
|
70698
|
-
source: external_exports.string().min(1),
|
|
70699
|
-
sourceUrl: external_exports.string().optional(),
|
|
70700
|
-
ref: external_exports.string().optional()
|
|
70701
|
-
})
|
|
70702
|
-
).optional(),
|
|
70703
|
-
quote: external_exports.strictObject({
|
|
70704
|
-
network: external_exports.string(),
|
|
70705
|
-
asset: external_exports.string().optional(),
|
|
70706
|
-
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
70707
|
-
payTo: external_exports.string().optional()
|
|
70708
|
-
}).optional(),
|
|
70709
|
-
payer: external_exports.string().optional(),
|
|
70710
|
-
paymentId: external_exports.string().regex(/^[A-Za-z0-9_-]{16,128}$/).optional(),
|
|
70711
|
-
authorization: external_exports.strictObject({
|
|
70712
|
-
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70713
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
70714
|
-
validBefore: external_exports.string().regex(/^\d+$/)
|
|
70715
|
-
}).optional(),
|
|
70716
|
-
transfer: external_exports.strictObject({
|
|
70717
|
-
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70718
|
-
toName: external_exports.string().min(1),
|
|
70719
|
-
toKind: external_exports.enum(["owner", "account"]),
|
|
70720
|
-
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
70721
|
-
network: external_exports.string().min(1),
|
|
70722
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
70723
|
-
status: external_exports.enum(["sent", "unknown", "failed"]),
|
|
70724
|
-
txHash: external_exports.string().regex(/^0x[0-9a-fA-F]+$/).nullable(),
|
|
70725
|
-
replayed: external_exports.boolean(),
|
|
70726
|
-
reservedOn: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
70727
|
-
request: external_exports.strictObject({
|
|
70728
|
-
authorization: external_exports.strictObject({
|
|
70729
|
-
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70730
|
-
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70731
|
-
value: external_exports.string().regex(/^\d+$/),
|
|
70732
|
-
validAfter: external_exports.string().regex(/^\d+$/),
|
|
70733
|
-
validBefore: external_exports.string().regex(/^\d+$/),
|
|
70734
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/)
|
|
70735
|
-
}),
|
|
70736
|
-
signature: external_exports.string().regex(/^0x[0-9a-fA-F]+$/)
|
|
70737
|
-
}).optional()
|
|
70738
|
-
}).optional(),
|
|
70739
|
-
settlement: external_exports.strictObject({
|
|
70740
|
-
outcome: external_exports.enum(["succeeded", "rejected", "unknown"]),
|
|
70741
|
-
transaction: external_exports.string().optional(),
|
|
70742
|
-
explorerUrl: external_exports.url().optional(),
|
|
70743
|
-
evidence: external_exports.unknown().optional()
|
|
70744
|
-
}).optional(),
|
|
70745
|
-
latencyMs: external_exports.number().nonnegative().finite().optional(),
|
|
70746
|
-
status: external_exports.number().int().min(100).max(599).optional(),
|
|
70747
|
-
error: external_exports.strictObject({ code: external_exports.string(), message: external_exports.string() }).optional(),
|
|
70748
|
-
phases: external_exports.strictObject({
|
|
70749
|
-
discoverMs: durationSchema.optional(),
|
|
70750
|
-
quoteMs: durationSchema.optional(),
|
|
70751
|
-
signMs: durationSchema.optional(),
|
|
70752
|
-
requestMs: durationSchema.optional(),
|
|
70753
|
-
settleMs: durationSchema.optional()
|
|
70754
|
-
}).optional(),
|
|
70755
|
-
listing: external_exports.strictObject({
|
|
70756
|
-
name: external_exports.string().min(1).optional(),
|
|
70757
|
-
providerHost: external_exports.string().min(1).optional(),
|
|
70758
|
-
source: external_exports.string().min(1)
|
|
70759
|
-
}).optional(),
|
|
70760
|
-
retry: external_exports.number().int().nonnegative().optional(),
|
|
70761
|
-
policy: external_exports.strictObject({
|
|
70762
|
-
maxPriceUsd: external_exports.string().regex(/^\d+(?:\.\d{1,6})?$/).optional(),
|
|
70763
|
-
capsApplied: external_exports.boolean()
|
|
70764
|
-
}).optional(),
|
|
70765
|
-
client: external_exports.strictObject({ name: external_exports.literal("vapi-network"), version: external_exports.string().min(1) }).optional(),
|
|
70766
|
-
outcome: external_exports.enum([
|
|
70767
|
-
"paid",
|
|
70768
|
-
"signed_in",
|
|
70769
|
-
"declined_policy",
|
|
70770
|
-
"failed_request",
|
|
70771
|
-
"settlement_rejected",
|
|
70772
|
-
"settlement_unknown"
|
|
70773
|
-
]).optional()
|
|
70774
|
-
});
|
|
70775
|
-
function parseReceipt(value) {
|
|
70776
|
-
const receipt = receiptSchema.parse(value);
|
|
70777
|
-
const transaction2 = receipt.settlement?.transaction;
|
|
70778
|
-
const network = receipt.quote?.network;
|
|
70779
|
-
const explorerUrl = transaction2 === void 0 || network === void 0 ? void 0 : explorerTransactionUrl(network, transaction2);
|
|
70780
|
-
if (explorerUrl === void 0 || receipt.settlement?.explorerUrl === explorerUrl) {
|
|
70781
|
-
return receipt;
|
|
70782
|
-
}
|
|
70783
|
-
return {
|
|
70784
|
-
...receipt,
|
|
70785
|
-
settlement: {
|
|
70786
|
-
outcome: receipt.settlement.outcome,
|
|
70787
|
-
...receipt.settlement.transaction ? { transaction: receipt.settlement.transaction } : {},
|
|
70788
|
-
explorerUrl,
|
|
70789
|
-
...receipt.settlement.evidence === void 0 ? {} : { evidence: receipt.settlement.evidence }
|
|
70790
|
-
}
|
|
70791
|
-
};
|
|
70792
|
-
}
|
|
70793
|
-
async function appendReceipt(receipt, path = getVapiPaths().receipts, options = {}) {
|
|
70794
|
-
const parsed = parseReceipt(
|
|
70795
|
-
receipt.wallet === void 0 && options.wallet !== void 0 ? { ...receipt, wallet: options.wallet } : receipt
|
|
70796
|
-
);
|
|
70797
|
-
await withReceiptJournalLock(path, async () => {
|
|
70798
|
-
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70799
|
-
const handle = await open5(path, "a", 384);
|
|
70800
|
-
try {
|
|
70801
|
-
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
70802
|
-
`, "utf8");
|
|
70803
|
-
} finally {
|
|
70804
|
-
await handle.close();
|
|
70805
|
-
}
|
|
70806
|
-
});
|
|
70807
|
-
return parsed;
|
|
70808
|
-
}
|
|
70809
|
-
async function readReceipts(path = getVapiPaths().receipts, options = {}) {
|
|
70810
|
-
let raw;
|
|
70811
|
-
try {
|
|
70812
|
-
raw = await readFile7(path, "utf8");
|
|
70813
|
-
} catch (error61) {
|
|
70814
|
-
if (isMissingFile(error61)) return [];
|
|
70815
|
-
throw error61;
|
|
70816
|
-
}
|
|
70817
|
-
const records = coalesceTransferReceiptRevisions(
|
|
70818
|
-
raw.split("\n").filter((line) => line.trim().length > 0).map((line, index2) => {
|
|
70819
|
-
try {
|
|
70820
|
-
return parseReceipt(JSON.parse(line));
|
|
70821
|
-
} catch (error61) {
|
|
70822
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70823
|
-
}
|
|
70824
|
-
})
|
|
70825
|
-
);
|
|
70826
|
-
const filtered = options.wallet === void 0 ? records : filterReceiptsByWallet(records, options.wallet);
|
|
70827
|
-
const limit = options.limit;
|
|
70828
|
-
if (limit === void 0) return filtered;
|
|
70829
|
-
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
70830
|
-
throw new Error("Receipt limit must be a non-negative integer.");
|
|
70831
|
-
return limit === 0 ? [] : filtered.slice(-limit);
|
|
70832
|
-
}
|
|
70833
|
-
function coalesceTransferReceiptRevisions(receipts) {
|
|
70834
|
-
const coalesced = [];
|
|
70835
|
-
const transferIndexes = /* @__PURE__ */ new Map();
|
|
70836
|
-
for (const receipt of receipts) {
|
|
70837
|
-
const existing = receipt.kind === "transfer" ? transferIndexes.get(receipt.id) : void 0;
|
|
70838
|
-
if (existing === void 0) {
|
|
70839
|
-
if (receipt.kind === "transfer") transferIndexes.set(receipt.id, coalesced.length);
|
|
70840
|
-
coalesced.push(receipt);
|
|
70841
|
-
} else {
|
|
70842
|
-
coalesced[existing] = receipt;
|
|
70843
|
-
}
|
|
70844
|
-
}
|
|
70845
|
-
return coalesced;
|
|
70846
|
-
}
|
|
70847
|
-
function receiptWallet(receipt) {
|
|
70848
|
-
return receipt.wallet ?? DEFAULT_WALLET_NAME;
|
|
70849
|
-
}
|
|
70850
|
-
function filterReceiptsByWallet(receipts, name) {
|
|
70851
|
-
return receipts.filter((receipt) => receiptWallet(receipt) === name);
|
|
70852
|
-
}
|
|
70853
|
-
async function renameReceiptWallet(from16, to, path = getVapiPaths().receipts) {
|
|
70854
|
-
return await withReceiptJournalLock(path, async () => {
|
|
70855
|
-
let raw;
|
|
70856
|
-
try {
|
|
70857
|
-
raw = await readFile7(path, "utf8");
|
|
70858
|
-
} catch (error61) {
|
|
70859
|
-
if (isMissingFile(error61)) return 0;
|
|
70860
|
-
throw error61;
|
|
70861
|
-
}
|
|
70862
|
-
let changed = 0;
|
|
70863
|
-
const lines = raw.split("\n").map((line, index2) => {
|
|
70864
|
-
if (line.trim().length === 0) return line;
|
|
70865
|
-
let parsed;
|
|
70866
|
-
try {
|
|
70867
|
-
parsed = JSON.parse(line);
|
|
70868
|
-
} catch (error61) {
|
|
70869
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70870
|
-
}
|
|
70871
|
-
const current = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "wallet") : void 0;
|
|
70872
|
-
if ((typeof current === "string" ? current : DEFAULT_WALLET_NAME) !== from16) return line;
|
|
70873
|
-
changed += 1;
|
|
70874
|
-
return JSON.stringify(parseReceipt({ ...parsed, wallet: to }));
|
|
70875
|
-
});
|
|
70876
|
-
if (changed === 0) return 0;
|
|
70877
|
-
await receiptTestHooks?.beforeRenameReplace?.(path);
|
|
70878
|
-
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70879
|
-
const temporaryPath = `${path}.${process.pid}.${randomBytes6(6).toString("hex")}.tmp`;
|
|
70880
|
-
await writeFile3(temporaryPath, lines.join("\n"), {
|
|
70881
|
-
encoding: "utf8",
|
|
70882
|
-
mode: 384,
|
|
70883
|
-
flag: "wx"
|
|
70884
|
-
});
|
|
70885
|
-
await rename4(temporaryPath, path);
|
|
70886
|
-
return changed;
|
|
70887
|
-
});
|
|
70888
|
-
}
|
|
70889
|
-
|
|
70890
|
-
// ../core/src/transfer-journal.ts
|
|
70891
|
-
import { readFile as readFile8 } from "node:fs/promises";
|
|
70892
|
-
async function readTransferJournal(home, from16, nonce) {
|
|
70893
|
-
let raw;
|
|
70894
|
-
try {
|
|
70895
|
-
raw = await readFile8(getVapiPaths(home).receipts, "utf8");
|
|
70896
|
-
} catch (error61) {
|
|
70897
|
-
if (isMissingFile(error61)) return { signed: false };
|
|
70898
|
-
throw error61;
|
|
70899
|
-
}
|
|
70900
|
-
let latest;
|
|
70901
|
-
let request;
|
|
70902
|
-
for (const [index2, line] of raw.split("\n").entries()) {
|
|
70903
|
-
if (!line.trim()) continue;
|
|
70904
|
-
let receipt;
|
|
70905
|
-
try {
|
|
70906
|
-
receipt = parseReceipt(JSON.parse(line));
|
|
70907
|
-
} catch (error61) {
|
|
70908
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70909
|
-
}
|
|
70910
|
-
if (receiptWallet(receipt) !== from16 || receipt.transfer?.nonce.toLowerCase() !== nonce.toLowerCase()) {
|
|
70911
|
-
continue;
|
|
70912
|
-
}
|
|
70913
|
-
latest = receipt;
|
|
70914
|
-
if (receipt.transfer.request !== void 0) request = receipt;
|
|
70915
|
-
}
|
|
70916
|
-
return {
|
|
70917
|
-
signed: latest !== void 0,
|
|
70918
|
-
...latest === void 0 ? {} : { latest },
|
|
70919
|
-
...request === void 0 ? {} : { request },
|
|
70920
|
-
...request?.transfer?.request?.authorization.validBefore === void 0 ? {} : { validBefore: request.transfer.request.authorization.validBefore },
|
|
70921
|
-
...(latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn) === void 0 ? {} : { reservedOn: latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn }
|
|
70922
|
-
};
|
|
70923
|
-
}
|
|
70924
|
-
|
|
70925
|
-
// ../core/src/vault-key.ts
|
|
70926
|
-
import { randomBytes as cryptoRandomBytes } from "node:crypto";
|
|
70927
|
-
|
|
70928
70189
|
// ../core/src/vault.ts
|
|
70929
|
-
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
70930
|
-
import { mkdir as mkdir8, open as open6, readFile as readFile9, rename as rename5, rm, stat as stat6, unlink as unlink4, writeFile as writeFile4 } from "node:fs/promises";
|
|
70931
|
-
import { dirname as dirname6 } from "node:path";
|
|
70932
70190
|
var VaultError = class extends Error {
|
|
70933
70191
|
code;
|
|
70934
70192
|
constructor(code, message, options) {
|
|
@@ -71319,244 +70577,1222 @@ async function exportVaultAccountKey(args) {
|
|
|
71319
70577
|
throw asVaultError(error61, "corrupt", "Unable to export the vault account key.");
|
|
71320
70578
|
}
|
|
71321
70579
|
}
|
|
71322
|
-
async function exportMemberKey(args) {
|
|
71323
|
-
return await exportVaultAccountKey(args);
|
|
70580
|
+
async function exportMemberKey(args) {
|
|
70581
|
+
return await exportVaultAccountKey(args);
|
|
70582
|
+
}
|
|
70583
|
+
function assertVaultKey(key2) {
|
|
70584
|
+
if (key2.byteLength !== 32) {
|
|
70585
|
+
throw new VaultError("bad_key", "A device vault key must contain exactly 32 bytes.");
|
|
70586
|
+
}
|
|
70587
|
+
}
|
|
70588
|
+
function assertAccountName(name) {
|
|
70589
|
+
const parsed = walletNameSchema.safeParse(name);
|
|
70590
|
+
if (!parsed.success) {
|
|
70591
|
+
throw new VaultError("name_taken", "The vault account name is not valid.", {
|
|
70592
|
+
cause: parsed.error
|
|
70593
|
+
});
|
|
70594
|
+
}
|
|
70595
|
+
}
|
|
70596
|
+
function assertAvailableName(file2, name) {
|
|
70597
|
+
assertAccountName(name);
|
|
70598
|
+
if (file2.accounts.some((account) => account.name === name)) {
|
|
70599
|
+
throw new VaultError("name_taken", "A vault account already has that name.");
|
|
70600
|
+
}
|
|
70601
|
+
}
|
|
70602
|
+
function nextDerivedIndex(file2) {
|
|
70603
|
+
let next = file2.nextDerivedIndex ?? 0;
|
|
70604
|
+
for (const account of file2.accounts) {
|
|
70605
|
+
if (account.kind === "derived") next = Math.max(next, account.index + 1);
|
|
70606
|
+
}
|
|
70607
|
+
return next;
|
|
70608
|
+
}
|
|
70609
|
+
function copyAccount(account) {
|
|
70610
|
+
if (account.kind === "derived") return { ...account };
|
|
70611
|
+
return {
|
|
70612
|
+
name: account.name,
|
|
70613
|
+
kind: account.kind,
|
|
70614
|
+
address: account.address,
|
|
70615
|
+
createdAt: account.createdAt
|
|
70616
|
+
};
|
|
70617
|
+
}
|
|
70618
|
+
function sealField(key2, plaintext) {
|
|
70619
|
+
const { nonce, ciphertext, tag } = encryptWithKey(key2, plaintext);
|
|
70620
|
+
return [nonce, ciphertext, tag].map((part) => part.toString("base64url")).join(".");
|
|
70621
|
+
}
|
|
70622
|
+
function openField(key2, value) {
|
|
70623
|
+
const [nonce = "", ciphertext = "", tag = ""] = value.split(".");
|
|
70624
|
+
return decryptWithKey(key2, {
|
|
70625
|
+
nonce: Buffer.from(nonce, "base64url"),
|
|
70626
|
+
ciphertext: Buffer.from(ciphertext, "base64url"),
|
|
70627
|
+
tag: Buffer.from(tag, "base64url")
|
|
70628
|
+
});
|
|
70629
|
+
}
|
|
70630
|
+
function decryptField(key2, value) {
|
|
70631
|
+
try {
|
|
70632
|
+
return openField(key2, value);
|
|
70633
|
+
} catch (error61) {
|
|
70634
|
+
throw new VaultError("bad_key", "Unable to decrypt the vault with this device key.", {
|
|
70635
|
+
cause: error61
|
|
70636
|
+
});
|
|
70637
|
+
}
|
|
70638
|
+
}
|
|
70639
|
+
function decryptPhraseForOpen(key2, phrase) {
|
|
70640
|
+
try {
|
|
70641
|
+
return openField(key2, phrase);
|
|
70642
|
+
} catch (error61) {
|
|
70643
|
+
throw new VaultError("bad_key", "Unable to decrypt the vault with this device key.", {
|
|
70644
|
+
cause: error61
|
|
70645
|
+
});
|
|
70646
|
+
}
|
|
70647
|
+
}
|
|
70648
|
+
function validateStoredImportedAccount(key2, account) {
|
|
70649
|
+
let plaintext;
|
|
70650
|
+
try {
|
|
70651
|
+
plaintext = decryptField(key2, account.key);
|
|
70652
|
+
if (plaintext.byteLength !== 32) {
|
|
70653
|
+
throw new VaultError("bad_key", "The stored imported key has the wrong length.");
|
|
70654
|
+
}
|
|
70655
|
+
let address4;
|
|
70656
|
+
try {
|
|
70657
|
+
address4 = privateKeyToAccount(`0x${plaintext.toString("hex")}`).address;
|
|
70658
|
+
} catch (error61) {
|
|
70659
|
+
throw new VaultError("bad_key", "The stored imported key is not valid.", {
|
|
70660
|
+
cause: error61
|
|
70661
|
+
});
|
|
70662
|
+
}
|
|
70663
|
+
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
70664
|
+
throw new VaultError("bad_key", "The stored imported key does not match its address.");
|
|
70665
|
+
}
|
|
70666
|
+
} finally {
|
|
70667
|
+
plaintext?.fill(0);
|
|
70668
|
+
}
|
|
70669
|
+
}
|
|
70670
|
+
function validateStoredDerivedAccount(key2, file2, account) {
|
|
70671
|
+
const plaintext = decryptField(key2, file2.phrase);
|
|
70672
|
+
let seed;
|
|
70673
|
+
try {
|
|
70674
|
+
seed = phraseToSeed(plaintext.toString("utf8"));
|
|
70675
|
+
const address4 = privateKeyToAccount(
|
|
70676
|
+
deriveEvmPrivateKey(seed, `m/44'/60'/0'/0/${account.index}`)
|
|
70677
|
+
).address;
|
|
70678
|
+
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
70679
|
+
throw new VaultError("bad_key", "The stored derived account does not match this vault.");
|
|
70680
|
+
}
|
|
70681
|
+
} finally {
|
|
70682
|
+
seed?.fill(0);
|
|
70683
|
+
plaintext.fill(0);
|
|
70684
|
+
}
|
|
70685
|
+
}
|
|
70686
|
+
function parseVaultFile(raw) {
|
|
70687
|
+
let value;
|
|
70688
|
+
try {
|
|
70689
|
+
value = JSON.parse(raw);
|
|
70690
|
+
} catch (error61) {
|
|
70691
|
+
throw new VaultError("corrupt", "The vault file is not valid JSON.", { cause: error61 });
|
|
70692
|
+
}
|
|
70693
|
+
const parsed = vaultFileSchema.safeParse(value);
|
|
70694
|
+
if (!parsed.success) {
|
|
70695
|
+
throw new VaultError("corrupt", "The vault file has an invalid structure.", {
|
|
70696
|
+
cause: parsed.error
|
|
70697
|
+
});
|
|
70698
|
+
}
|
|
70699
|
+
if (parsed.data.protected !== (parsed.data.wrappedKey !== void 0)) {
|
|
70700
|
+
throw new VaultError("corrupt", "The vault protection metadata is inconsistent.");
|
|
70701
|
+
}
|
|
70702
|
+
const names = /* @__PURE__ */ new Set();
|
|
70703
|
+
const indexes = /* @__PURE__ */ new Set();
|
|
70704
|
+
for (const account of parsed.data.accounts) {
|
|
70705
|
+
if (names.has(account.name)) {
|
|
70706
|
+
throw new VaultError("corrupt", "The vault file contains duplicate account names.");
|
|
70707
|
+
}
|
|
70708
|
+
names.add(account.name);
|
|
70709
|
+
if (account.kind === "derived") {
|
|
70710
|
+
if (indexes.has(account.index)) {
|
|
70711
|
+
throw new VaultError("corrupt", "The vault file contains duplicate derived indexes.");
|
|
70712
|
+
}
|
|
70713
|
+
indexes.add(account.index);
|
|
70714
|
+
}
|
|
70715
|
+
}
|
|
70716
|
+
return parsed.data;
|
|
70717
|
+
}
|
|
70718
|
+
async function readVaultFile(path, key2) {
|
|
70719
|
+
const file2 = await readVaultFileUnlocked(path);
|
|
70720
|
+
const plaintext = decryptPhraseForOpen(key2, file2.phrase);
|
|
70721
|
+
try {
|
|
70722
|
+
try {
|
|
70723
|
+
validateRecoveryPhrase(plaintext.toString("utf8"));
|
|
70724
|
+
} catch (error61) {
|
|
70725
|
+
throw new VaultError("corrupt", "The vault recovery phrase is not valid.", {
|
|
70726
|
+
cause: error61
|
|
70727
|
+
});
|
|
70728
|
+
}
|
|
70729
|
+
} finally {
|
|
70730
|
+
plaintext.fill(0);
|
|
70731
|
+
}
|
|
70732
|
+
return file2;
|
|
70733
|
+
}
|
|
70734
|
+
async function readVaultFileUnlocked(path) {
|
|
70735
|
+
let raw;
|
|
70736
|
+
try {
|
|
70737
|
+
raw = await readFile7(path, "utf8");
|
|
70738
|
+
} catch (error61) {
|
|
70739
|
+
if (isMissingFile2(error61)) {
|
|
70740
|
+
throw new VaultError("not_found", "No vault file was found at the requested path.", {
|
|
70741
|
+
cause: error61
|
|
70742
|
+
});
|
|
70743
|
+
}
|
|
70744
|
+
throw new VaultError("corrupt", "Unable to read the vault file.", { cause: error61 });
|
|
70745
|
+
}
|
|
70746
|
+
return parseVaultFile(raw);
|
|
70747
|
+
}
|
|
70748
|
+
async function refuseExistingVault(path) {
|
|
70749
|
+
try {
|
|
70750
|
+
await stat6(path);
|
|
70751
|
+
} catch (error61) {
|
|
70752
|
+
if (isMissingFile2(error61)) return;
|
|
70753
|
+
throw new VaultError("corrupt", "Unable to check whether the vault already exists.", {
|
|
70754
|
+
cause: error61
|
|
70755
|
+
});
|
|
70756
|
+
}
|
|
70757
|
+
throw new VaultError("corrupt", "A vault already exists at the requested path.");
|
|
70758
|
+
}
|
|
70759
|
+
async function writeVaultFile(path, file2) {
|
|
70760
|
+
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70761
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes5(6).toString("hex")}.tmp`;
|
|
70762
|
+
try {
|
|
70763
|
+
await writeFile3(temporaryPath, `${JSON.stringify(file2, null, 2)}
|
|
70764
|
+
`, {
|
|
70765
|
+
encoding: "utf8",
|
|
70766
|
+
mode: 384,
|
|
70767
|
+
flag: "wx"
|
|
70768
|
+
});
|
|
70769
|
+
await rename4(temporaryPath, path);
|
|
70770
|
+
} catch (error61) {
|
|
70771
|
+
await rm(temporaryPath, { force: true }).catch(() => void 0);
|
|
70772
|
+
throw error61;
|
|
70773
|
+
}
|
|
70774
|
+
}
|
|
70775
|
+
async function withVaultLock(path, operation) {
|
|
70776
|
+
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70777
|
+
const lockPath = `${path}.lock`;
|
|
70778
|
+
const deadline = Date.now() + VAULT_LOCK_TIMEOUT_MS;
|
|
70779
|
+
let handle;
|
|
70780
|
+
while (!handle) {
|
|
70781
|
+
try {
|
|
70782
|
+
handle = await open5(lockPath, "wx", 384);
|
|
70783
|
+
} catch (error61) {
|
|
70784
|
+
if (!isExistingFile(error61)) throw error61;
|
|
70785
|
+
await removeStaleVaultLock(lockPath);
|
|
70786
|
+
if (Date.now() >= deadline) {
|
|
70787
|
+
throw new VaultError("corrupt", "Timed out waiting for the vault lock.");
|
|
70788
|
+
}
|
|
70789
|
+
await new Promise((resolve3) => setTimeout(resolve3, 20));
|
|
70790
|
+
}
|
|
70791
|
+
}
|
|
70792
|
+
try {
|
|
70793
|
+
return await operation();
|
|
70794
|
+
} finally {
|
|
70795
|
+
await handle.close();
|
|
70796
|
+
await unlink4(lockPath).catch(() => void 0);
|
|
70797
|
+
}
|
|
70798
|
+
}
|
|
70799
|
+
async function removeStaleVaultLock(path) {
|
|
70800
|
+
try {
|
|
70801
|
+
const metadata = await stat6(path);
|
|
70802
|
+
if (Date.now() - metadata.mtimeMs > STALE_VAULT_LOCK_MS) await unlink4(path);
|
|
70803
|
+
} catch (error61) {
|
|
70804
|
+
if (!isMissingFile2(error61)) throw error61;
|
|
70805
|
+
}
|
|
70806
|
+
}
|
|
70807
|
+
function isMissingFile2(error61) {
|
|
70808
|
+
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "ENOENT";
|
|
70809
|
+
}
|
|
70810
|
+
function isExistingFile(error61) {
|
|
70811
|
+
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "EEXIST";
|
|
70812
|
+
}
|
|
70813
|
+
function asVaultError(error61, code, message) {
|
|
70814
|
+
return error61 instanceof VaultError ? error61 : new VaultError(code, message, { cause: error61 });
|
|
70815
|
+
}
|
|
70816
|
+
|
|
70817
|
+
// ../core/src/file-secret-store.ts
|
|
70818
|
+
var FILE_SECRET_STORE_PASSWORD_ENV = "VAPI_VAULT_PASSWORD";
|
|
70819
|
+
var FILE_SECRET_STORE_MIN_PASSWORD = 12;
|
|
70820
|
+
var CHECK_VALUE = "vapi-network file secret store";
|
|
70821
|
+
var sealedSchema = external_exports.object({ nonce: external_exports.string(), ciphertext: external_exports.string(), tag: external_exports.string() }).strict();
|
|
70822
|
+
var fileSchema = external_exports.object({
|
|
70823
|
+
v: external_exports.literal(1),
|
|
70824
|
+
salt: external_exports.string(),
|
|
70825
|
+
check: sealedSchema,
|
|
70826
|
+
entries: external_exports.record(external_exports.string(), sealedSchema)
|
|
70827
|
+
}).strict();
|
|
70828
|
+
async function createFileSecretStore(options) {
|
|
70829
|
+
const password = passwordFrom(options.env);
|
|
70830
|
+
if (password.length < FILE_SECRET_STORE_MIN_PASSWORD) {
|
|
70831
|
+
throw new KeystoreError(
|
|
70832
|
+
`${FILE_SECRET_STORE_PASSWORD_ENV} must be at least ${FILE_SECRET_STORE_MIN_PASSWORD} characters.`
|
|
70833
|
+
);
|
|
70834
|
+
}
|
|
70835
|
+
await withVaultLock(options.path, async () => {
|
|
70836
|
+
let exists = true;
|
|
70837
|
+
try {
|
|
70838
|
+
await stat7(options.path);
|
|
70839
|
+
} catch (error61) {
|
|
70840
|
+
if (!isMissingFile(error61)) throw error61;
|
|
70841
|
+
exists = false;
|
|
70842
|
+
}
|
|
70843
|
+
if (exists) {
|
|
70844
|
+
await withKey(options.path, options.env, async () => void 0);
|
|
70845
|
+
return;
|
|
70846
|
+
}
|
|
70847
|
+
const salt = randomBytes6(32);
|
|
70848
|
+
const key2 = await deriveScryptKey(password, salt);
|
|
70849
|
+
try {
|
|
70850
|
+
await writeJsonAtomic(
|
|
70851
|
+
options.path,
|
|
70852
|
+
{
|
|
70853
|
+
v: 1,
|
|
70854
|
+
salt: salt.toString("base64"),
|
|
70855
|
+
check: seal(key2, CHECK_VALUE),
|
|
70856
|
+
entries: {}
|
|
70857
|
+
},
|
|
70858
|
+
{ mode: 384 }
|
|
70859
|
+
);
|
|
70860
|
+
} finally {
|
|
70861
|
+
key2.fill(0);
|
|
70862
|
+
}
|
|
70863
|
+
});
|
|
70864
|
+
}
|
|
70865
|
+
function fileSecretStore(options) {
|
|
70866
|
+
const env = options.env ?? process.env;
|
|
70867
|
+
const write2 = async (change) => await withVaultLock(
|
|
70868
|
+
options.path,
|
|
70869
|
+
async () => await withKey(options.path, env, async (file2, key2) => {
|
|
70870
|
+
const changed = change(file2, key2);
|
|
70871
|
+
if (changed) await writeJsonAtomic(options.path, file2, { mode: 384 });
|
|
70872
|
+
return changed;
|
|
70873
|
+
})
|
|
70874
|
+
);
|
|
70875
|
+
const get = async (name) => await withKey(options.path, env, async (file2, key2) => {
|
|
70876
|
+
const sealed = Object.hasOwn(file2.entries, name) ? file2.entries[name] : void 0;
|
|
70877
|
+
return sealed === void 0 ? void 0 : open6(key2, sealed);
|
|
70878
|
+
});
|
|
70879
|
+
return {
|
|
70880
|
+
// A locked backend still exists; it must never enable a plaintext fallback.
|
|
70881
|
+
available: true,
|
|
70882
|
+
platform: process.platform,
|
|
70883
|
+
description: "the encrypted vAPI secrets file",
|
|
70884
|
+
get,
|
|
70885
|
+
async has(name) {
|
|
70886
|
+
return await get(name) !== void 0;
|
|
70887
|
+
},
|
|
70888
|
+
async set(name, value) {
|
|
70889
|
+
if (name === "__proto__") {
|
|
70890
|
+
throw new KeystoreError("The secret name is reserved in the encrypted vAPI secrets file.");
|
|
70891
|
+
}
|
|
70892
|
+
await write2((file2, key2) => {
|
|
70893
|
+
file2.entries[name] = seal(key2, value);
|
|
70894
|
+
return true;
|
|
70895
|
+
});
|
|
70896
|
+
},
|
|
70897
|
+
async remove(name) {
|
|
70898
|
+
return await write2((file2) => {
|
|
70899
|
+
if (!Object.hasOwn(file2.entries, name)) return false;
|
|
70900
|
+
delete file2.entries[name];
|
|
70901
|
+
return true;
|
|
70902
|
+
});
|
|
70903
|
+
}
|
|
70904
|
+
};
|
|
70905
|
+
}
|
|
70906
|
+
async function withKey(path, env, operation) {
|
|
70907
|
+
const file2 = await readStoredFile(path);
|
|
70908
|
+
const key2 = await deriveScryptKey(passwordFrom(env), Buffer.from(file2.salt, "base64"));
|
|
70909
|
+
try {
|
|
70910
|
+
if (open6(key2, file2.check) !== CHECK_VALUE) throw wrongPassword();
|
|
70911
|
+
return await operation(file2, key2);
|
|
70912
|
+
} finally {
|
|
70913
|
+
key2.fill(0);
|
|
70914
|
+
}
|
|
70915
|
+
}
|
|
70916
|
+
function passwordFrom(env) {
|
|
70917
|
+
const password = (env ?? process.env)[FILE_SECRET_STORE_PASSWORD_ENV];
|
|
70918
|
+
if (!password) {
|
|
70919
|
+
throw new KeystoreError(
|
|
70920
|
+
`This vault keeps its secrets in an encrypted file. Set ${FILE_SECRET_STORE_PASSWORD_ENV} to open it.`
|
|
70921
|
+
);
|
|
70922
|
+
}
|
|
70923
|
+
return password;
|
|
70924
|
+
}
|
|
70925
|
+
async function readStoredFile(path) {
|
|
70926
|
+
let raw;
|
|
70927
|
+
try {
|
|
70928
|
+
raw = await readFile8(path, "utf8");
|
|
70929
|
+
} catch (error61) {
|
|
70930
|
+
throw new KeystoreError("The vAPI secrets file is missing. Run vapi setup again.", {
|
|
70931
|
+
cause: error61
|
|
70932
|
+
});
|
|
70933
|
+
}
|
|
70934
|
+
let value;
|
|
70935
|
+
try {
|
|
70936
|
+
value = JSON.parse(raw);
|
|
70937
|
+
} catch {
|
|
70938
|
+
throw new KeystoreError("The vAPI secrets file is damaged.");
|
|
70939
|
+
}
|
|
70940
|
+
const parsed = fileSchema.safeParse(value);
|
|
70941
|
+
if (!parsed.success) throw new KeystoreError("The vAPI secrets file is damaged.");
|
|
70942
|
+
return parsed.data;
|
|
70943
|
+
}
|
|
70944
|
+
function seal(key2, value) {
|
|
70945
|
+
const { nonce, ciphertext, tag } = encryptWithKey(key2, Buffer.from(value, "utf8"));
|
|
70946
|
+
return {
|
|
70947
|
+
nonce: nonce.toString("base64"),
|
|
70948
|
+
ciphertext: ciphertext.toString("base64"),
|
|
70949
|
+
tag: tag.toString("base64")
|
|
70950
|
+
};
|
|
70951
|
+
}
|
|
70952
|
+
function open6(key2, sealed) {
|
|
70953
|
+
try {
|
|
70954
|
+
return decryptWithKey(key2, {
|
|
70955
|
+
nonce: Buffer.from(sealed.nonce, "base64"),
|
|
70956
|
+
ciphertext: Buffer.from(sealed.ciphertext, "base64"),
|
|
70957
|
+
tag: Buffer.from(sealed.tag, "base64")
|
|
70958
|
+
}).toString("utf8");
|
|
70959
|
+
} catch (error61) {
|
|
70960
|
+
throw wrongPassword(error61);
|
|
70961
|
+
}
|
|
70962
|
+
}
|
|
70963
|
+
function wrongPassword(cause) {
|
|
70964
|
+
return new KeystoreError(`Wrong ${FILE_SECRET_STORE_PASSWORD_ENV} for the vAPI secrets file.`, {
|
|
70965
|
+
cause
|
|
70966
|
+
});
|
|
70967
|
+
}
|
|
70968
|
+
|
|
70969
|
+
// ../core/src/secret-backend.ts
|
|
70970
|
+
import { readFileSync } from "node:fs";
|
|
70971
|
+
import { stat as stat8 } from "node:fs/promises";
|
|
70972
|
+
import { join as join6 } from "node:path";
|
|
70973
|
+
var PROBE_ACCOUNT = "setup-probe";
|
|
70974
|
+
var pinSchema = external_exports.object({ v: external_exports.literal(1), backend: external_exports.enum(["os", "file"]) }).strict();
|
|
70975
|
+
function secretBackendPath(home = getVapiPaths().directory) {
|
|
70976
|
+
return join6(home, "secret-store.json");
|
|
70977
|
+
}
|
|
70978
|
+
function secretsFilePath(home = getVapiPaths().directory) {
|
|
70979
|
+
return join6(home, "secrets.json");
|
|
70980
|
+
}
|
|
70981
|
+
function readSecretBackend(home = getVapiPaths().directory) {
|
|
70982
|
+
const path = secretBackendPath(home);
|
|
70983
|
+
try {
|
|
70984
|
+
const parsed = pinSchema.safeParse(JSON.parse(readFileSync(path, "utf8")));
|
|
70985
|
+
if (parsed.success) return parsed.data.backend;
|
|
70986
|
+
} catch (error61) {
|
|
70987
|
+
if (isMissingFile(error61)) return "os";
|
|
70988
|
+
}
|
|
70989
|
+
throw new KeystoreError(`The vAPI secret-store pin at ${path} is damaged.`);
|
|
70990
|
+
}
|
|
70991
|
+
async function chooseSecretBackend(options) {
|
|
70992
|
+
const env = options.env ?? process.env;
|
|
70993
|
+
const osWorks = options.os.platform !== "linux" || await osStoreWorks(options.os);
|
|
70994
|
+
const path = secretBackendPath(options.home);
|
|
70995
|
+
return await withVaultLock(path, async () => {
|
|
70996
|
+
if (await fileExists(path)) return readSecretBackend(options.home);
|
|
70997
|
+
if (await fileExists(join6(options.home, "vault.json"))) return "os";
|
|
70998
|
+
let backend;
|
|
70999
|
+
if (osWorks) {
|
|
71000
|
+
backend = "os";
|
|
71001
|
+
} else if (env[FILE_SECRET_STORE_PASSWORD_ENV]) {
|
|
71002
|
+
await createFileSecretStore({ path: secretsFilePath(options.home), env });
|
|
71003
|
+
backend = "file";
|
|
71004
|
+
} else {
|
|
71005
|
+
throw new KeystoreError(
|
|
71006
|
+
[
|
|
71007
|
+
`This machine has no working keyring (${options.os.description}).`,
|
|
71008
|
+
`Set ${FILE_SECRET_STORE_PASSWORD_ENV} (at least ${FILE_SECRET_STORE_MIN_PASSWORD} characters; in a GitHub Codespace add it as a Codespaces secret) and run vapi setup again,`,
|
|
71009
|
+
"or run vapi on your own computer, or connect Claude from https://api.vapinetwork.ai/connect."
|
|
71010
|
+
].join(" ")
|
|
71011
|
+
);
|
|
71012
|
+
}
|
|
71013
|
+
await writeJsonAtomic(path, { v: 1, backend }, { mode: 384 });
|
|
71014
|
+
return backend;
|
|
71015
|
+
});
|
|
71016
|
+
}
|
|
71017
|
+
async function fileExists(path) {
|
|
71018
|
+
try {
|
|
71019
|
+
await stat8(path);
|
|
71020
|
+
return true;
|
|
71021
|
+
} catch (error61) {
|
|
71022
|
+
if (isMissingFile(error61)) return false;
|
|
71023
|
+
throw error61;
|
|
71024
|
+
}
|
|
71025
|
+
}
|
|
71026
|
+
async function osStoreWorks(store) {
|
|
71027
|
+
if (!store.available) return false;
|
|
71028
|
+
try {
|
|
71029
|
+
try {
|
|
71030
|
+
await store.set(PROBE_ACCOUNT, "ok");
|
|
71031
|
+
return await store.get(PROBE_ACCOUNT) === "ok";
|
|
71032
|
+
} finally {
|
|
71033
|
+
await store.remove(PROBE_ACCOUNT);
|
|
71034
|
+
}
|
|
71035
|
+
} catch {
|
|
71036
|
+
return false;
|
|
71037
|
+
}
|
|
71038
|
+
}
|
|
71039
|
+
|
|
71040
|
+
// ../core/src/secret-store.ts
|
|
71041
|
+
var SECRET_STORE_SERVICE = "vapi-network";
|
|
71042
|
+
var SECURITY_BINARY = "/usr/bin/security";
|
|
71043
|
+
var SECRET_TOOL_BINARY = "secret-tool";
|
|
71044
|
+
var WINDOWS_POWERSHELL_ARGS = ["-NoProfile", "-NonInteractive", "-Command", "-"];
|
|
71045
|
+
var SECURITY_ITEM_NOT_FOUND = 44;
|
|
71046
|
+
var WINDOWS_SECRET_SUCCESS = 0;
|
|
71047
|
+
var WINDOWS_SECRET_NOT_FOUND = 2;
|
|
71048
|
+
var UNSUPPORTED_PLATFORM = "No OS secret store on this platform yet; use VAPI_KEYSTORE_PASSWORD.";
|
|
71049
|
+
var SECRET_TOOL_MISSING = [
|
|
71050
|
+
"secret-tool is not installed, so the passphrase cannot be kept in the OS secret store.",
|
|
71051
|
+
"Install libsecret-tools (Debian, Ubuntu) or libsecret (Fedora, Arch), or use VAPI_KEYSTORE_PASSWORD."
|
|
71052
|
+
].join(" ");
|
|
71053
|
+
var POWERSHELL_MISSING = [
|
|
71054
|
+
"Windows PowerShell (powershell.exe) was not found, so the passphrase cannot be kept in the OS secret store.",
|
|
71055
|
+
"Use VAPI_KEYSTORE_PASSWORD."
|
|
71056
|
+
].join(" ");
|
|
71057
|
+
function secretStore(options = {}) {
|
|
71058
|
+
const home = options.home ?? getVapiPaths().directory;
|
|
71059
|
+
if (readSecretBackend(home) === "file") {
|
|
71060
|
+
return fileSecretStore({ path: secretsFilePath(home), env: options.env ?? process.env });
|
|
71061
|
+
}
|
|
71062
|
+
return osSecretStore(options);
|
|
71063
|
+
}
|
|
71064
|
+
function osSecretStore(options = {}) {
|
|
71065
|
+
const platform2 = options.platform ?? process.platform;
|
|
71066
|
+
const run = options.run ?? (async (file2, args, input2) => await spawnRunner(platform2, file2, args, input2));
|
|
71067
|
+
const env = options.env ?? process.env;
|
|
71068
|
+
const installed = options.installed ?? ((file2) => binaryInstalled(file2, env));
|
|
71069
|
+
if (platform2 === "darwin") return keychainStore(platform2, run);
|
|
71070
|
+
if (platform2 === "win32") return windowsDataProtectionStore(platform2, run, env, installed);
|
|
71071
|
+
if (platform2 === "linux") return libsecretStore(platform2, run, installed);
|
|
71072
|
+
return unsupportedStore(platform2);
|
|
71073
|
+
}
|
|
71074
|
+
function memorySecretStore(initial = {}) {
|
|
71075
|
+
const entries = new Map(Object.entries(initial));
|
|
71076
|
+
return {
|
|
71077
|
+
available: true,
|
|
71078
|
+
platform: process.platform,
|
|
71079
|
+
description: "an in-memory store",
|
|
71080
|
+
async get(name) {
|
|
71081
|
+
return entries.get(name);
|
|
71082
|
+
},
|
|
71083
|
+
async has(name) {
|
|
71084
|
+
return entries.has(name);
|
|
71085
|
+
},
|
|
71086
|
+
async set(name, passphrase) {
|
|
71087
|
+
entries.set(name, passphrase);
|
|
71088
|
+
},
|
|
71089
|
+
async remove(name) {
|
|
71090
|
+
return entries.delete(name);
|
|
71091
|
+
},
|
|
71092
|
+
async list() {
|
|
71093
|
+
return [...entries.keys()].sort();
|
|
71094
|
+
}
|
|
71095
|
+
};
|
|
71096
|
+
}
|
|
71097
|
+
function keychainStore(platform2, run) {
|
|
71098
|
+
const find = async (account, withPassword) => await run(SECURITY_BINARY, [
|
|
71099
|
+
"find-generic-password",
|
|
71100
|
+
"-a",
|
|
71101
|
+
account,
|
|
71102
|
+
"-s",
|
|
71103
|
+
SECRET_STORE_SERVICE,
|
|
71104
|
+
...withPassword ? ["-w"] : []
|
|
71105
|
+
]);
|
|
71106
|
+
const read = async (account, what) => {
|
|
71107
|
+
const result = await find(account, true);
|
|
71108
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return void 0;
|
|
71109
|
+
requireSuccess(result, what);
|
|
71110
|
+
const value = withoutTrailingNewline(result.stdout);
|
|
71111
|
+
return value.length === 0 ? void 0 : value;
|
|
71112
|
+
};
|
|
71113
|
+
const write2 = async (account, value, what) => {
|
|
71114
|
+
const result = await run(
|
|
71115
|
+
SECURITY_BINARY,
|
|
71116
|
+
[
|
|
71117
|
+
"add-generic-password",
|
|
71118
|
+
"-a",
|
|
71119
|
+
account,
|
|
71120
|
+
"-s",
|
|
71121
|
+
SECRET_STORE_SERVICE,
|
|
71122
|
+
"-l",
|
|
71123
|
+
`${SECRET_STORE_SERVICE} ${account}`,
|
|
71124
|
+
"-U",
|
|
71125
|
+
"-w"
|
|
71126
|
+
],
|
|
71127
|
+
// `security` asks for the password and then for its confirmation.
|
|
71128
|
+
`${value}
|
|
71129
|
+
${value}
|
|
71130
|
+
`
|
|
71131
|
+
);
|
|
71132
|
+
requireSuccess(result, what);
|
|
71133
|
+
};
|
|
71134
|
+
const erase = async (account, what) => {
|
|
71135
|
+
const result = await run(SECURITY_BINARY, [
|
|
71136
|
+
"delete-generic-password",
|
|
71137
|
+
"-a",
|
|
71138
|
+
account,
|
|
71139
|
+
"-s",
|
|
71140
|
+
SECRET_STORE_SERVICE
|
|
71141
|
+
]);
|
|
71142
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71143
|
+
requireSuccess(result, what);
|
|
71144
|
+
return true;
|
|
71145
|
+
};
|
|
71146
|
+
const erasePartsAfter = async (account, keep, what) => {
|
|
71147
|
+
for (let part = keep + 1; part <= MAX_KEYCHAIN_PARTS; part += 1) {
|
|
71148
|
+
if (!await erase(keychainPart(account, part), what)) return;
|
|
71149
|
+
}
|
|
71150
|
+
};
|
|
71151
|
+
return {
|
|
71152
|
+
available: true,
|
|
71153
|
+
platform: platform2,
|
|
71154
|
+
description: "the macOS Keychain",
|
|
71155
|
+
async get(name) {
|
|
71156
|
+
const account = accountFor(name);
|
|
71157
|
+
const what = `read the passphrase of ${name} from the macOS Keychain`;
|
|
71158
|
+
const value = await read(account, what);
|
|
71159
|
+
const parts = value === void 0 ? void 0 : chunkedPartCount(value);
|
|
71160
|
+
if (value === void 0 || parts === void 0) return value;
|
|
71161
|
+
let joined = "";
|
|
71162
|
+
for (let part = 1; part <= parts; part += 1) {
|
|
71163
|
+
const chunk = await read(keychainPart(account, part), what);
|
|
71164
|
+
if (chunk === void 0) {
|
|
71165
|
+
throw new KeystoreError(
|
|
71166
|
+
`The stored secret ${name} is incomplete in the macOS Keychain. Store it again.`
|
|
71167
|
+
);
|
|
71168
|
+
}
|
|
71169
|
+
joined += chunk;
|
|
71170
|
+
}
|
|
71171
|
+
return joined;
|
|
71172
|
+
},
|
|
71173
|
+
async has(name) {
|
|
71174
|
+
const result = await find(accountFor(name), false);
|
|
71175
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71176
|
+
requireSuccess(result, `look up ${name} in the macOS Keychain`);
|
|
71177
|
+
return true;
|
|
71178
|
+
},
|
|
71179
|
+
async set(name, passphrase) {
|
|
71180
|
+
requirePassphrase(passphrase);
|
|
71181
|
+
const account = accountFor(name);
|
|
71182
|
+
const what = `store the passphrase of ${name} in the macOS Keychain`;
|
|
71183
|
+
if (passphrase.length <= KEYCHAIN_PROMPT_LIMIT) {
|
|
71184
|
+
await write2(account, passphrase, what);
|
|
71185
|
+
return;
|
|
71186
|
+
}
|
|
71187
|
+
const chunks = [];
|
|
71188
|
+
for (let index2 = 0; index2 < passphrase.length; index2 += KEYCHAIN_CHUNK) {
|
|
71189
|
+
chunks.push(passphrase.slice(index2, index2 + KEYCHAIN_CHUNK));
|
|
71190
|
+
}
|
|
71191
|
+
if (chunks.length > MAX_KEYCHAIN_PARTS) {
|
|
71192
|
+
throw new KeystoreError(`The secret ${name} is too long for the macOS Keychain.`);
|
|
71193
|
+
}
|
|
71194
|
+
for (const [index2, chunk] of chunks.entries()) {
|
|
71195
|
+
await write2(keychainPart(account, index2 + 1), chunk, what);
|
|
71196
|
+
}
|
|
71197
|
+
await erasePartsAfter(account, chunks.length, what);
|
|
71198
|
+
await write2(account, `${CHUNKED_MARKER}${chunks.length}`, what);
|
|
71199
|
+
},
|
|
71200
|
+
async remove(name) {
|
|
71201
|
+
const account = accountFor(name);
|
|
71202
|
+
const what = `remove the passphrase of ${name} from the macOS Keychain`;
|
|
71203
|
+
const found = await find(account, true);
|
|
71204
|
+
if (found.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71205
|
+
requireSuccess(found, what);
|
|
71206
|
+
if (chunkedPartCount(withoutTrailingNewline(found.stdout)) !== void 0) {
|
|
71207
|
+
await erasePartsAfter(account, 0, what);
|
|
71208
|
+
}
|
|
71209
|
+
return await erase(account, what);
|
|
71210
|
+
}
|
|
71211
|
+
};
|
|
71212
|
+
}
|
|
71213
|
+
var KEYCHAIN_PROMPT_LIMIT = 128;
|
|
71214
|
+
var KEYCHAIN_CHUNK = 120;
|
|
71215
|
+
var MAX_KEYCHAIN_PARTS = 32;
|
|
71216
|
+
var CHUNKED_MARKER = "vapi-chunked:v1:";
|
|
71217
|
+
function keychainPart(account, part) {
|
|
71218
|
+
return `${account}#${part}`;
|
|
71219
|
+
}
|
|
71220
|
+
function chunkedPartCount(value) {
|
|
71221
|
+
if (!value.startsWith(CHUNKED_MARKER)) return void 0;
|
|
71222
|
+
const parts = Number(value.slice(CHUNKED_MARKER.length));
|
|
71223
|
+
return Number.isInteger(parts) && parts > 0 && parts <= MAX_KEYCHAIN_PARTS ? parts : void 0;
|
|
71224
|
+
}
|
|
71225
|
+
function windowsSecretFileName(account) {
|
|
71226
|
+
let encoded = "";
|
|
71227
|
+
for (let index2 = 0; index2 < account.length; index2 += 1) {
|
|
71228
|
+
const character = account[index2];
|
|
71229
|
+
if (/^[a-z0-9._#-]$/u.test(character)) {
|
|
71230
|
+
encoded += character;
|
|
71231
|
+
continue;
|
|
71232
|
+
}
|
|
71233
|
+
encoded += `%${account.charCodeAt(index2).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
71234
|
+
}
|
|
71235
|
+
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu.test(encoded)) {
|
|
71236
|
+
encoded = `%${encoded.charCodeAt(0).toString(16).toUpperCase()}${encoded.slice(1)}`;
|
|
71237
|
+
}
|
|
71238
|
+
return `${encoded}.bin`;
|
|
71239
|
+
}
|
|
71240
|
+
function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
71241
|
+
const powershell = `${env.SystemRoot ?? "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
71242
|
+
const fileDetails = (name) => {
|
|
71243
|
+
const file2 = windowsSecretFileName(accountFor(name));
|
|
71244
|
+
return { file: file2, account: file2.slice(0, -".bin".length) };
|
|
71245
|
+
};
|
|
71246
|
+
const script = (file2, operations) => [
|
|
71247
|
+
"$ErrorActionPreference = 'Stop'",
|
|
71248
|
+
"try {",
|
|
71249
|
+
" Add-Type -AssemblyName System.Security",
|
|
71250
|
+
" $dir = Join-Path $env:LOCALAPPDATA 'vapi-network\\secrets'",
|
|
71251
|
+
` $path = Join-Path $dir '${file2}'`,
|
|
71252
|
+
...operations.map((operation) => ` ${operation}`),
|
|
71253
|
+
"} catch {",
|
|
71254
|
+
" [Console]::Error.WriteLine($_.Exception.Message)",
|
|
71255
|
+
" exit 1",
|
|
71256
|
+
"}"
|
|
71257
|
+
].join("\n");
|
|
71258
|
+
const execute = async (script2) => {
|
|
71259
|
+
const result = await run(powershell, WINDOWS_POWERSHELL_ARGS, `${script2}
|
|
71260
|
+
|
|
71261
|
+
`);
|
|
71262
|
+
requirePowerShell(result);
|
|
71263
|
+
return result;
|
|
71264
|
+
};
|
|
71265
|
+
return {
|
|
71266
|
+
available: installed(powershell),
|
|
71267
|
+
platform: platform2,
|
|
71268
|
+
description: "Windows Data Protection (DPAPI)",
|
|
71269
|
+
async get(name) {
|
|
71270
|
+
const { file: file2, account } = fileDetails(name);
|
|
71271
|
+
const result = await execute(
|
|
71272
|
+
script(file2, [
|
|
71273
|
+
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
71274
|
+
"$blob = [System.IO.File]::ReadAllBytes($path)",
|
|
71275
|
+
"$bytes = [System.Security.Cryptography.ProtectedData]::Unprotect($blob, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
71276
|
+
"[Console]::Out.Write([Convert]::ToBase64String($bytes))",
|
|
71277
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71278
|
+
])
|
|
71279
|
+
);
|
|
71280
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return void 0;
|
|
71281
|
+
requireSuccess(result, `read the passphrase of ${name} from Windows Data Protection`);
|
|
71282
|
+
const value = Buffer.from(result.stdout.trim(), "base64").toString("utf8");
|
|
71283
|
+
return value.length === 0 ? void 0 : value;
|
|
71284
|
+
},
|
|
71285
|
+
async has(name) {
|
|
71286
|
+
const { file: file2, account } = fileDetails(name);
|
|
71287
|
+
const result = await execute(
|
|
71288
|
+
script(file2, [
|
|
71289
|
+
`if (Test-Path -LiteralPath $path) { exit ${WINDOWS_SECRET_SUCCESS} }`,
|
|
71290
|
+
`[Console]::Error.WriteLine('No stored secret for ${account}.')`,
|
|
71291
|
+
`exit ${WINDOWS_SECRET_NOT_FOUND}`
|
|
71292
|
+
])
|
|
71293
|
+
);
|
|
71294
|
+
if (result.code === WINDOWS_SECRET_SUCCESS) return true;
|
|
71295
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
71296
|
+
requireSuccess(result, `look up ${name} in Windows Data Protection`);
|
|
71297
|
+
return false;
|
|
71298
|
+
},
|
|
71299
|
+
async set(name, passphrase) {
|
|
71300
|
+
requirePassphrase(passphrase);
|
|
71301
|
+
const { file: file2 } = fileDetails(name);
|
|
71302
|
+
const value = Buffer.from(passphrase, "utf8").toString("base64");
|
|
71303
|
+
const result = await execute(
|
|
71304
|
+
script(file2, [
|
|
71305
|
+
"[void][System.IO.Directory]::CreateDirectory($dir)",
|
|
71306
|
+
`$bytes = [Convert]::FromBase64String('${value}')`,
|
|
71307
|
+
"$blob = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
71308
|
+
"[System.IO.File]::WriteAllBytes($path, $blob)",
|
|
71309
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71310
|
+
])
|
|
71311
|
+
);
|
|
71312
|
+
requireSuccess(result, `store the passphrase of ${name} in Windows Data Protection`);
|
|
71313
|
+
},
|
|
71314
|
+
async remove(name) {
|
|
71315
|
+
const { file: file2, account } = fileDetails(name);
|
|
71316
|
+
const result = await execute(
|
|
71317
|
+
script(file2, [
|
|
71318
|
+
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
71319
|
+
"Remove-Item -LiteralPath $path -Force",
|
|
71320
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71321
|
+
])
|
|
71322
|
+
);
|
|
71323
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
71324
|
+
requireSuccess(result, `remove the passphrase of ${name} from Windows Data Protection`);
|
|
71325
|
+
return true;
|
|
71326
|
+
}
|
|
71327
|
+
};
|
|
71328
|
+
}
|
|
71329
|
+
function libsecretStore(platform2, run, installed) {
|
|
71330
|
+
const lookup2 = async (name) => {
|
|
71331
|
+
const result = await run(SECRET_TOOL_BINARY, [
|
|
71332
|
+
"lookup",
|
|
71333
|
+
"service",
|
|
71334
|
+
SECRET_STORE_SERVICE,
|
|
71335
|
+
"account",
|
|
71336
|
+
accountFor(name)
|
|
71337
|
+
]);
|
|
71338
|
+
requireBinary(result);
|
|
71339
|
+
const value = withoutTrailingNewline(result.stdout);
|
|
71340
|
+
if (result.code === 0) return value.length === 0 ? void 0 : value;
|
|
71341
|
+
if (result.stderr.trim().length === 0) return void 0;
|
|
71342
|
+
requireSuccess(result, `read the passphrase of ${name} from the secret service`);
|
|
71343
|
+
return void 0;
|
|
71344
|
+
};
|
|
71345
|
+
return {
|
|
71346
|
+
available: installed(SECRET_TOOL_BINARY),
|
|
71347
|
+
platform: platform2,
|
|
71348
|
+
description: "the libsecret keyring",
|
|
71349
|
+
get: lookup2,
|
|
71350
|
+
async has(name) {
|
|
71351
|
+
return await lookup2(name) !== void 0;
|
|
71352
|
+
},
|
|
71353
|
+
async set(name, passphrase) {
|
|
71354
|
+
requirePassphrase(passphrase);
|
|
71355
|
+
const account = accountFor(name);
|
|
71356
|
+
const result = await run(
|
|
71357
|
+
SECRET_TOOL_BINARY,
|
|
71358
|
+
[
|
|
71359
|
+
"store",
|
|
71360
|
+
`--label=${SECRET_STORE_SERVICE} ${account}`,
|
|
71361
|
+
"service",
|
|
71362
|
+
SECRET_STORE_SERVICE,
|
|
71363
|
+
"account",
|
|
71364
|
+
account
|
|
71365
|
+
],
|
|
71366
|
+
`${passphrase}
|
|
71367
|
+
`
|
|
71368
|
+
);
|
|
71369
|
+
requireBinary(result);
|
|
71370
|
+
requireSuccess(result, `store the passphrase of ${name} in the secret service`);
|
|
71371
|
+
},
|
|
71372
|
+
async remove(name) {
|
|
71373
|
+
const existed = await lookup2(name) !== void 0;
|
|
71374
|
+
const result = await run(SECRET_TOOL_BINARY, [
|
|
71375
|
+
"clear",
|
|
71376
|
+
"service",
|
|
71377
|
+
SECRET_STORE_SERVICE,
|
|
71378
|
+
"account",
|
|
71379
|
+
accountFor(name)
|
|
71380
|
+
]);
|
|
71381
|
+
requireBinary(result);
|
|
71382
|
+
requireSuccess(result, `remove the passphrase of ${name} from the secret service`);
|
|
71383
|
+
return existed;
|
|
71384
|
+
}
|
|
71385
|
+
};
|
|
71386
|
+
}
|
|
71387
|
+
function unsupportedStore(platform2) {
|
|
71388
|
+
const refuse = () => {
|
|
71389
|
+
throw new KeystoreError(UNSUPPORTED_PLATFORM);
|
|
71390
|
+
};
|
|
71391
|
+
return {
|
|
71392
|
+
available: false,
|
|
71393
|
+
platform: platform2,
|
|
71394
|
+
description: "no OS secret store",
|
|
71395
|
+
get: async () => refuse(),
|
|
71396
|
+
has: async () => refuse(),
|
|
71397
|
+
set: async () => refuse(),
|
|
71398
|
+
remove: async () => refuse()
|
|
71399
|
+
};
|
|
71400
|
+
}
|
|
71401
|
+
function accountFor(name) {
|
|
71402
|
+
const account = name.trim();
|
|
71403
|
+
if (account.length === 0) {
|
|
71404
|
+
throw new KeystoreError("A wallet name is needed to reach the OS secret store.");
|
|
71405
|
+
}
|
|
71406
|
+
return account;
|
|
71407
|
+
}
|
|
71408
|
+
function requirePassphrase(passphrase) {
|
|
71409
|
+
if (passphrase.length === 0) {
|
|
71410
|
+
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
71411
|
+
}
|
|
71412
|
+
}
|
|
71413
|
+
function requireBinary(result) {
|
|
71414
|
+
if (result.notFound === true) throw new KeystoreError(SECRET_TOOL_MISSING);
|
|
71415
|
+
}
|
|
71416
|
+
function requirePowerShell(result) {
|
|
71417
|
+
if (result.notFound === true) throw new KeystoreError(POWERSHELL_MISSING);
|
|
71418
|
+
}
|
|
71419
|
+
function binaryInstalled(file2, env) {
|
|
71420
|
+
if (isAbsolute(file2) || win32.isAbsolute(file2)) return existsSync(file2);
|
|
71421
|
+
return (env.PATH ?? "").split(delimiter).some((directory) => existsSync(join7(directory, file2)));
|
|
71422
|
+
}
|
|
71423
|
+
var SAFE_FAILURE_DETAILS = [
|
|
71424
|
+
"Cannot autolaunch D-Bus without X11 $DISPLAY",
|
|
71425
|
+
"Cannot autolaunch D-Bus",
|
|
71426
|
+
"The name org.freedesktop.secrets was not provided by any .service files",
|
|
71427
|
+
"Cannot create an item in a locked collection",
|
|
71428
|
+
"User interaction is not allowed.",
|
|
71429
|
+
"Access to the path is denied."
|
|
71430
|
+
];
|
|
71431
|
+
function requireSuccess(result, what) {
|
|
71432
|
+
if (result.code === 0) return;
|
|
71433
|
+
const detail = SAFE_FAILURE_DETAILS.find((reason) => result.stderr.includes(reason));
|
|
71434
|
+
throw new KeystoreError(
|
|
71435
|
+
`Could not ${what}${result.code === null ? "" : ` (exit ${result.code})`}.${detail === void 0 ? "" : ` ${detail}`}`
|
|
71436
|
+
);
|
|
71437
|
+
}
|
|
71438
|
+
function withoutTrailingNewline(value) {
|
|
71439
|
+
return value.replace(/\r?\n$/u, "");
|
|
71440
|
+
}
|
|
71441
|
+
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve3) => {
|
|
71442
|
+
let stdout = "";
|
|
71443
|
+
let stderr2 = "";
|
|
71444
|
+
let settled = false;
|
|
71445
|
+
const finish = (outcome) => {
|
|
71446
|
+
if (settled) return;
|
|
71447
|
+
settled = true;
|
|
71448
|
+
resolve3(outcome);
|
|
71449
|
+
};
|
|
71450
|
+
const child = spawn(file2, [...args], {
|
|
71451
|
+
detached: platform2 !== "win32",
|
|
71452
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
71453
|
+
windowsHide: true
|
|
71454
|
+
});
|
|
71455
|
+
child.stdout?.setEncoding("utf8");
|
|
71456
|
+
child.stdout?.on("data", (chunk) => {
|
|
71457
|
+
stdout += chunk;
|
|
71458
|
+
});
|
|
71459
|
+
child.stderr?.setEncoding("utf8");
|
|
71460
|
+
child.stderr?.on("data", (chunk) => {
|
|
71461
|
+
stderr2 += chunk;
|
|
71462
|
+
});
|
|
71463
|
+
child.on("error", (error61) => {
|
|
71464
|
+
finish({
|
|
71465
|
+
code: null,
|
|
71466
|
+
stdout,
|
|
71467
|
+
stderr: stderr2,
|
|
71468
|
+
...error61.code === "ENOENT" ? { notFound: true } : {}
|
|
71469
|
+
});
|
|
71470
|
+
});
|
|
71471
|
+
child.on("close", (code) => finish({ code, stdout, stderr: stderr2 }));
|
|
71472
|
+
child.stdin?.on("error", () => void 0);
|
|
71473
|
+
child.stdin?.end(input2 ?? "");
|
|
71474
|
+
});
|
|
71475
|
+
|
|
71476
|
+
// ../core/src/passphrase.ts
|
|
71477
|
+
var PASSPHRASE_ENVIRONMENT_VARIABLE = "VAPI_KEYSTORE_PASSWORD";
|
|
71478
|
+
function noPassphraseHint(walletName) {
|
|
71479
|
+
return `Set ${PASSPHRASE_ENVIRONMENT_VARIABLE}, or store this wallet's passphrase once with vapi unlock --wallet ${walletName}.`;
|
|
71480
|
+
}
|
|
71481
|
+
function staleStoredPassphraseMessage(walletName, store) {
|
|
71482
|
+
return [
|
|
71483
|
+
`The passphrase stored in ${store.description} no longer opens wallet ${walletName}.`,
|
|
71484
|
+
`Store the current one with vapi unlock --wallet ${walletName}, or remove it with vapi lock --wallet ${walletName}.`
|
|
71485
|
+
].join(" ");
|
|
71324
71486
|
}
|
|
71325
|
-
function
|
|
71326
|
-
|
|
71327
|
-
|
|
71487
|
+
async function resolvePassphrase(walletName, options = {}) {
|
|
71488
|
+
const env = options.env ?? process.env;
|
|
71489
|
+
const fromEnvironment = env[PASSPHRASE_ENVIRONMENT_VARIABLE];
|
|
71490
|
+
if (fromEnvironment !== void 0) {
|
|
71491
|
+
if (fromEnvironment.length === 0) {
|
|
71492
|
+
throw new KeystoreError(`${PASSPHRASE_ENVIRONMENT_VARIABLE} cannot be empty.`);
|
|
71493
|
+
}
|
|
71494
|
+
return { passphrase: fromEnvironment, source: "environment" };
|
|
71328
71495
|
}
|
|
71329
|
-
|
|
71330
|
-
|
|
71331
|
-
|
|
71332
|
-
if (!parsed.success) {
|
|
71333
|
-
throw new VaultError("name_taken", "The vault account name is not valid.", {
|
|
71334
|
-
cause: parsed.error
|
|
71335
|
-
});
|
|
71496
|
+
if (options.confirm !== true) {
|
|
71497
|
+
const stored = await readStored(options.store ?? secretStore(), walletName);
|
|
71498
|
+
if (stored !== void 0) return { passphrase: stored, source: "secret-store" };
|
|
71336
71499
|
}
|
|
71337
|
-
|
|
71338
|
-
|
|
71339
|
-
|
|
71340
|
-
|
|
71341
|
-
|
|
71500
|
+
const hint = noPassphraseHint(walletName);
|
|
71501
|
+
if (options.interactive === false) {
|
|
71502
|
+
throw new KeystoreError(
|
|
71503
|
+
`No interactive terminal is available for the keystore prompt. ${hint}`
|
|
71504
|
+
);
|
|
71505
|
+
}
|
|
71506
|
+
const prompt = options.prompt ?? promptForSecret;
|
|
71507
|
+
const first = await prompt(`Passphrase for ${walletName}: `, hint);
|
|
71508
|
+
if (first.length === 0) {
|
|
71509
|
+
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
71510
|
+
}
|
|
71511
|
+
if (options.confirm === true) {
|
|
71512
|
+
const second = await prompt("Confirm passphrase: ", hint);
|
|
71513
|
+
if (first !== second) throw new KeystoreError("Passphrases do not match.");
|
|
71342
71514
|
}
|
|
71515
|
+
return { passphrase: first, source: "prompt" };
|
|
71343
71516
|
}
|
|
71344
|
-
function
|
|
71345
|
-
|
|
71346
|
-
|
|
71347
|
-
|
|
71517
|
+
async function readStored(store, walletName) {
|
|
71518
|
+
if (!store.available) return void 0;
|
|
71519
|
+
try {
|
|
71520
|
+
return await store.get(walletName);
|
|
71521
|
+
} catch {
|
|
71522
|
+
return void 0;
|
|
71348
71523
|
}
|
|
71349
|
-
return next;
|
|
71350
71524
|
}
|
|
71351
|
-
|
|
71352
|
-
|
|
71353
|
-
|
|
71354
|
-
|
|
71355
|
-
|
|
71356
|
-
|
|
71357
|
-
|
|
71358
|
-
|
|
71525
|
+
|
|
71526
|
+
// ../core/src/receipts.ts
|
|
71527
|
+
import { randomBytes as randomBytes8 } from "node:crypto";
|
|
71528
|
+
import { mkdir as mkdir8, open as open7, readFile as readFile9, rename as rename5, writeFile as writeFile4 } from "node:fs/promises";
|
|
71529
|
+
import { dirname as dirname6 } from "node:path";
|
|
71530
|
+
|
|
71531
|
+
// ../core/src/agent-run.ts
|
|
71532
|
+
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
71533
|
+
var RUN_ID_PATTERN = /^run_[0-9a-f]{24}$/;
|
|
71534
|
+
function isRunId(value) {
|
|
71535
|
+
return typeof value === "string" && RUN_ID_PATTERN.test(value);
|
|
71359
71536
|
}
|
|
71360
|
-
function
|
|
71361
|
-
|
|
71362
|
-
return [nonce, ciphertext, tag].map((part) => part.toString("base64url")).join(".");
|
|
71537
|
+
function createRunId(random = randomBytes7) {
|
|
71538
|
+
return `run_${Buffer.from(random(12)).toString("hex")}`;
|
|
71363
71539
|
}
|
|
71364
|
-
|
|
71365
|
-
|
|
71366
|
-
|
|
71367
|
-
|
|
71368
|
-
|
|
71369
|
-
|
|
71540
|
+
var runRefSchema = external_exports.strictObject({
|
|
71541
|
+
id: external_exports.string().regex(RUN_ID_PATTERN),
|
|
71542
|
+
swarm: external_exports.string().optional(),
|
|
71543
|
+
member: external_exports.string().optional(),
|
|
71544
|
+
parentRunId: external_exports.string().optional()
|
|
71545
|
+
});
|
|
71546
|
+
|
|
71547
|
+
// ../core/src/receipts.ts
|
|
71548
|
+
var receiptTestHooks;
|
|
71549
|
+
var RECEIPT_JOURNAL_BUSY_MESSAGE = "The receipt journal is busy. Wait for the other vapi command to finish, then retry.";
|
|
71550
|
+
async function withReceiptJournalLock(path, operation) {
|
|
71551
|
+
return await withFileLock(`${path}.lock`, operation, {
|
|
71552
|
+
lockedMessage: RECEIPT_JOURNAL_BUSY_MESSAGE
|
|
71370
71553
|
});
|
|
71371
71554
|
}
|
|
71372
|
-
|
|
71373
|
-
|
|
71374
|
-
|
|
71375
|
-
|
|
71376
|
-
|
|
71377
|
-
|
|
71378
|
-
|
|
71379
|
-
|
|
71380
|
-
|
|
71381
|
-
|
|
71382
|
-
|
|
71383
|
-
|
|
71384
|
-
|
|
71385
|
-
|
|
71386
|
-
|
|
71387
|
-
})
|
|
71555
|
+
var durationSchema = external_exports.number().nonnegative().finite();
|
|
71556
|
+
var receiptSchema = external_exports.strictObject({
|
|
71557
|
+
id: external_exports.string().min(1),
|
|
71558
|
+
timestamp: external_exports.iso.datetime(),
|
|
71559
|
+
run: runRefSchema.optional(),
|
|
71560
|
+
kind: external_exports.literal("transfer").optional(),
|
|
71561
|
+
wallet: walletNameSchema.optional(),
|
|
71562
|
+
resourceUrl: external_exports.url(),
|
|
71563
|
+
method: external_exports.string().min(1).optional(),
|
|
71564
|
+
source: external_exports.string().min(1).optional(),
|
|
71565
|
+
provenance: external_exports.array(
|
|
71566
|
+
external_exports.strictObject({
|
|
71567
|
+
source: external_exports.string().min(1),
|
|
71568
|
+
sourceUrl: external_exports.string().optional(),
|
|
71569
|
+
ref: external_exports.string().optional()
|
|
71570
|
+
})
|
|
71571
|
+
).optional(),
|
|
71572
|
+
quote: external_exports.strictObject({
|
|
71573
|
+
network: external_exports.string(),
|
|
71574
|
+
asset: external_exports.string().optional(),
|
|
71575
|
+
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
71576
|
+
payTo: external_exports.string().optional()
|
|
71577
|
+
}).optional(),
|
|
71578
|
+
payer: external_exports.string().optional(),
|
|
71579
|
+
paymentId: external_exports.string().regex(/^[A-Za-z0-9_-]{16,128}$/).optional(),
|
|
71580
|
+
authorization: external_exports.strictObject({
|
|
71581
|
+
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71582
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
71583
|
+
validBefore: external_exports.string().regex(/^\d+$/)
|
|
71584
|
+
}).optional(),
|
|
71585
|
+
transfer: external_exports.strictObject({
|
|
71586
|
+
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71587
|
+
toName: external_exports.string().min(1),
|
|
71588
|
+
toKind: external_exports.enum(["owner", "account"]),
|
|
71589
|
+
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
71590
|
+
network: external_exports.string().min(1),
|
|
71591
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
71592
|
+
status: external_exports.enum(["sent", "unknown", "failed"]),
|
|
71593
|
+
txHash: external_exports.string().regex(/^0x[0-9a-fA-F]+$/).nullable(),
|
|
71594
|
+
replayed: external_exports.boolean(),
|
|
71595
|
+
reservedOn: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
71596
|
+
request: external_exports.strictObject({
|
|
71597
|
+
authorization: external_exports.strictObject({
|
|
71598
|
+
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71599
|
+
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71600
|
+
value: external_exports.string().regex(/^\d+$/),
|
|
71601
|
+
validAfter: external_exports.string().regex(/^\d+$/),
|
|
71602
|
+
validBefore: external_exports.string().regex(/^\d+$/),
|
|
71603
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/)
|
|
71604
|
+
}),
|
|
71605
|
+
signature: external_exports.string().regex(/^0x[0-9a-fA-F]+$/)
|
|
71606
|
+
}).optional()
|
|
71607
|
+
}).optional(),
|
|
71608
|
+
settlement: external_exports.strictObject({
|
|
71609
|
+
outcome: external_exports.enum(["succeeded", "rejected", "unknown"]),
|
|
71610
|
+
transaction: external_exports.string().optional(),
|
|
71611
|
+
explorerUrl: external_exports.url().optional(),
|
|
71612
|
+
evidence: external_exports.unknown().optional()
|
|
71613
|
+
}).optional(),
|
|
71614
|
+
latencyMs: external_exports.number().nonnegative().finite().optional(),
|
|
71615
|
+
status: external_exports.number().int().min(100).max(599).optional(),
|
|
71616
|
+
error: external_exports.strictObject({ code: external_exports.string(), message: external_exports.string() }).optional(),
|
|
71617
|
+
phases: external_exports.strictObject({
|
|
71618
|
+
discoverMs: durationSchema.optional(),
|
|
71619
|
+
quoteMs: durationSchema.optional(),
|
|
71620
|
+
signMs: durationSchema.optional(),
|
|
71621
|
+
requestMs: durationSchema.optional(),
|
|
71622
|
+
settleMs: durationSchema.optional()
|
|
71623
|
+
}).optional(),
|
|
71624
|
+
listing: external_exports.strictObject({
|
|
71625
|
+
name: external_exports.string().min(1).optional(),
|
|
71626
|
+
providerHost: external_exports.string().min(1).optional(),
|
|
71627
|
+
source: external_exports.string().min(1)
|
|
71628
|
+
}).optional(),
|
|
71629
|
+
retry: external_exports.number().int().nonnegative().optional(),
|
|
71630
|
+
policy: external_exports.strictObject({
|
|
71631
|
+
maxPriceUsd: external_exports.string().regex(/^\d+(?:\.\d{1,6})?$/).optional(),
|
|
71632
|
+
capsApplied: external_exports.boolean()
|
|
71633
|
+
}).optional(),
|
|
71634
|
+
client: external_exports.strictObject({ name: external_exports.literal("vapi-network"), version: external_exports.string().min(1) }).optional(),
|
|
71635
|
+
outcome: external_exports.enum([
|
|
71636
|
+
"paid",
|
|
71637
|
+
"signed_in",
|
|
71638
|
+
"declined_policy",
|
|
71639
|
+
"failed_request",
|
|
71640
|
+
"settlement_rejected",
|
|
71641
|
+
"settlement_unknown"
|
|
71642
|
+
]).optional()
|
|
71643
|
+
});
|
|
71644
|
+
function parseReceipt(value) {
|
|
71645
|
+
const receipt = receiptSchema.parse(value);
|
|
71646
|
+
const transaction2 = receipt.settlement?.transaction;
|
|
71647
|
+
const network = receipt.quote?.network;
|
|
71648
|
+
const explorerUrl = transaction2 === void 0 || network === void 0 ? void 0 : explorerTransactionUrl(network, transaction2);
|
|
71649
|
+
if (explorerUrl === void 0 || receipt.settlement?.explorerUrl === explorerUrl) {
|
|
71650
|
+
return receipt;
|
|
71388
71651
|
}
|
|
71389
|
-
|
|
71390
|
-
|
|
71391
|
-
|
|
71392
|
-
|
|
71393
|
-
|
|
71394
|
-
|
|
71395
|
-
|
|
71396
|
-
}
|
|
71397
|
-
let address4;
|
|
71398
|
-
try {
|
|
71399
|
-
address4 = privateKeyToAccount(`0x${plaintext.toString("hex")}`).address;
|
|
71400
|
-
} catch (error61) {
|
|
71401
|
-
throw new VaultError("bad_key", "The stored imported key is not valid.", {
|
|
71402
|
-
cause: error61
|
|
71403
|
-
});
|
|
71404
|
-
}
|
|
71405
|
-
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
71406
|
-
throw new VaultError("bad_key", "The stored imported key does not match its address.");
|
|
71652
|
+
return {
|
|
71653
|
+
...receipt,
|
|
71654
|
+
settlement: {
|
|
71655
|
+
outcome: receipt.settlement.outcome,
|
|
71656
|
+
...receipt.settlement.transaction ? { transaction: receipt.settlement.transaction } : {},
|
|
71657
|
+
explorerUrl,
|
|
71658
|
+
...receipt.settlement.evidence === void 0 ? {} : { evidence: receipt.settlement.evidence }
|
|
71407
71659
|
}
|
|
71408
|
-
}
|
|
71409
|
-
plaintext?.fill(0);
|
|
71410
|
-
}
|
|
71660
|
+
};
|
|
71411
71661
|
}
|
|
71412
|
-
function
|
|
71413
|
-
const
|
|
71414
|
-
|
|
71415
|
-
|
|
71416
|
-
|
|
71417
|
-
|
|
71418
|
-
|
|
71419
|
-
|
|
71420
|
-
|
|
71421
|
-
|
|
71662
|
+
async function appendReceipt(receipt, path = getVapiPaths().receipts, options = {}) {
|
|
71663
|
+
const parsed = parseReceipt(
|
|
71664
|
+
receipt.wallet === void 0 && options.wallet !== void 0 ? { ...receipt, wallet: options.wallet } : receipt
|
|
71665
|
+
);
|
|
71666
|
+
await withReceiptJournalLock(path, async () => {
|
|
71667
|
+
await mkdir8(dirname6(path), { recursive: true, mode: 448 });
|
|
71668
|
+
const handle = await open7(path, "a", 384);
|
|
71669
|
+
try {
|
|
71670
|
+
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
71671
|
+
`, "utf8");
|
|
71672
|
+
} finally {
|
|
71673
|
+
await handle.close();
|
|
71422
71674
|
}
|
|
71423
|
-
}
|
|
71424
|
-
|
|
71425
|
-
plaintext.fill(0);
|
|
71426
|
-
}
|
|
71675
|
+
});
|
|
71676
|
+
return parsed;
|
|
71427
71677
|
}
|
|
71428
|
-
function
|
|
71429
|
-
let
|
|
71678
|
+
async function readReceipts(path = getVapiPaths().receipts, options = {}) {
|
|
71679
|
+
let raw;
|
|
71430
71680
|
try {
|
|
71431
|
-
|
|
71681
|
+
raw = await readFile9(path, "utf8");
|
|
71432
71682
|
} catch (error61) {
|
|
71433
|
-
|
|
71434
|
-
|
|
71435
|
-
const parsed = vaultFileSchema.safeParse(value);
|
|
71436
|
-
if (!parsed.success) {
|
|
71437
|
-
throw new VaultError("corrupt", "The vault file has an invalid structure.", {
|
|
71438
|
-
cause: parsed.error
|
|
71439
|
-
});
|
|
71440
|
-
}
|
|
71441
|
-
if (parsed.data.protected !== (parsed.data.wrappedKey !== void 0)) {
|
|
71442
|
-
throw new VaultError("corrupt", "The vault protection metadata is inconsistent.");
|
|
71683
|
+
if (isMissingFile(error61)) return [];
|
|
71684
|
+
throw error61;
|
|
71443
71685
|
}
|
|
71444
|
-
const
|
|
71445
|
-
|
|
71446
|
-
|
|
71447
|
-
|
|
71448
|
-
|
|
71449
|
-
|
|
71450
|
-
names.add(account.name);
|
|
71451
|
-
if (account.kind === "derived") {
|
|
71452
|
-
if (indexes.has(account.index)) {
|
|
71453
|
-
throw new VaultError("corrupt", "The vault file contains duplicate derived indexes.");
|
|
71686
|
+
const records = coalesceTransferReceiptRevisions(
|
|
71687
|
+
raw.split("\n").filter((line) => line.trim().length > 0).map((line, index2) => {
|
|
71688
|
+
try {
|
|
71689
|
+
return parseReceipt(JSON.parse(line));
|
|
71690
|
+
} catch (error61) {
|
|
71691
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71454
71692
|
}
|
|
71455
|
-
|
|
71693
|
+
})
|
|
71694
|
+
);
|
|
71695
|
+
const filtered = options.wallet === void 0 ? records : filterReceiptsByWallet(records, options.wallet);
|
|
71696
|
+
const limit = options.limit;
|
|
71697
|
+
if (limit === void 0) return filtered;
|
|
71698
|
+
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
71699
|
+
throw new Error("Receipt limit must be a non-negative integer.");
|
|
71700
|
+
return limit === 0 ? [] : filtered.slice(-limit);
|
|
71701
|
+
}
|
|
71702
|
+
function coalesceTransferReceiptRevisions(receipts) {
|
|
71703
|
+
const coalesced = [];
|
|
71704
|
+
const transferIndexes = /* @__PURE__ */ new Map();
|
|
71705
|
+
for (const receipt of receipts) {
|
|
71706
|
+
const existing = receipt.kind === "transfer" ? transferIndexes.get(receipt.id) : void 0;
|
|
71707
|
+
if (existing === void 0) {
|
|
71708
|
+
if (receipt.kind === "transfer") transferIndexes.set(receipt.id, coalesced.length);
|
|
71709
|
+
coalesced.push(receipt);
|
|
71710
|
+
} else {
|
|
71711
|
+
coalesced[existing] = receipt;
|
|
71456
71712
|
}
|
|
71457
71713
|
}
|
|
71458
|
-
return
|
|
71714
|
+
return coalesced;
|
|
71459
71715
|
}
|
|
71460
|
-
|
|
71461
|
-
|
|
71462
|
-
|
|
71463
|
-
|
|
71716
|
+
function receiptWallet(receipt) {
|
|
71717
|
+
return receipt.wallet ?? DEFAULT_WALLET_NAME;
|
|
71718
|
+
}
|
|
71719
|
+
function filterReceiptsByWallet(receipts, name) {
|
|
71720
|
+
return receipts.filter((receipt) => receiptWallet(receipt) === name);
|
|
71721
|
+
}
|
|
71722
|
+
async function renameReceiptWallet(from16, to, path = getVapiPaths().receipts) {
|
|
71723
|
+
return await withReceiptJournalLock(path, async () => {
|
|
71724
|
+
let raw;
|
|
71464
71725
|
try {
|
|
71465
|
-
|
|
71726
|
+
raw = await readFile9(path, "utf8");
|
|
71466
71727
|
} catch (error61) {
|
|
71467
|
-
|
|
71468
|
-
|
|
71469
|
-
});
|
|
71470
|
-
}
|
|
71471
|
-
} finally {
|
|
71472
|
-
plaintext.fill(0);
|
|
71473
|
-
}
|
|
71474
|
-
return file2;
|
|
71475
|
-
}
|
|
71476
|
-
async function readVaultFileUnlocked(path) {
|
|
71477
|
-
let raw;
|
|
71478
|
-
try {
|
|
71479
|
-
raw = await readFile9(path, "utf8");
|
|
71480
|
-
} catch (error61) {
|
|
71481
|
-
if (isMissingFile2(error61)) {
|
|
71482
|
-
throw new VaultError("not_found", "No vault file was found at the requested path.", {
|
|
71483
|
-
cause: error61
|
|
71484
|
-
});
|
|
71728
|
+
if (isMissingFile(error61)) return 0;
|
|
71729
|
+
throw error61;
|
|
71485
71730
|
}
|
|
71486
|
-
|
|
71487
|
-
|
|
71488
|
-
|
|
71489
|
-
|
|
71490
|
-
|
|
71491
|
-
|
|
71492
|
-
|
|
71493
|
-
|
|
71494
|
-
|
|
71495
|
-
|
|
71496
|
-
|
|
71731
|
+
let changed = 0;
|
|
71732
|
+
const lines = raw.split("\n").map((line, index2) => {
|
|
71733
|
+
if (line.trim().length === 0) return line;
|
|
71734
|
+
let parsed;
|
|
71735
|
+
try {
|
|
71736
|
+
parsed = JSON.parse(line);
|
|
71737
|
+
} catch (error61) {
|
|
71738
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71739
|
+
}
|
|
71740
|
+
const current = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "wallet") : void 0;
|
|
71741
|
+
if ((typeof current === "string" ? current : DEFAULT_WALLET_NAME) !== from16) return line;
|
|
71742
|
+
changed += 1;
|
|
71743
|
+
return JSON.stringify(parseReceipt({ ...parsed, wallet: to }));
|
|
71497
71744
|
});
|
|
71498
|
-
|
|
71499
|
-
|
|
71500
|
-
}
|
|
71501
|
-
|
|
71502
|
-
|
|
71503
|
-
const temporaryPath = `${path}.${process.pid}.${randomBytes7(6).toString("hex")}.tmp`;
|
|
71504
|
-
try {
|
|
71505
|
-
await writeFile4(temporaryPath, `${JSON.stringify(file2, null, 2)}
|
|
71506
|
-
`, {
|
|
71745
|
+
if (changed === 0) return 0;
|
|
71746
|
+
await receiptTestHooks?.beforeRenameReplace?.(path);
|
|
71747
|
+
await mkdir8(dirname6(path), { recursive: true, mode: 448 });
|
|
71748
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes8(6).toString("hex")}.tmp`;
|
|
71749
|
+
await writeFile4(temporaryPath, lines.join("\n"), {
|
|
71507
71750
|
encoding: "utf8",
|
|
71508
71751
|
mode: 384,
|
|
71509
71752
|
flag: "wx"
|
|
71510
71753
|
});
|
|
71511
71754
|
await rename5(temporaryPath, path);
|
|
71755
|
+
return changed;
|
|
71756
|
+
});
|
|
71757
|
+
}
|
|
71758
|
+
|
|
71759
|
+
// ../core/src/transfer-journal.ts
|
|
71760
|
+
import { readFile as readFile10 } from "node:fs/promises";
|
|
71761
|
+
async function readTransferJournal(home, from16, nonce) {
|
|
71762
|
+
let raw;
|
|
71763
|
+
try {
|
|
71764
|
+
raw = await readFile10(getVapiPaths(home).receipts, "utf8");
|
|
71512
71765
|
} catch (error61) {
|
|
71513
|
-
|
|
71766
|
+
if (isMissingFile(error61)) return { signed: false };
|
|
71514
71767
|
throw error61;
|
|
71515
71768
|
}
|
|
71516
|
-
|
|
71517
|
-
|
|
71518
|
-
|
|
71519
|
-
|
|
71520
|
-
|
|
71521
|
-
let handle;
|
|
71522
|
-
while (!handle) {
|
|
71769
|
+
let latest;
|
|
71770
|
+
let request;
|
|
71771
|
+
for (const [index2, line] of raw.split("\n").entries()) {
|
|
71772
|
+
if (!line.trim()) continue;
|
|
71773
|
+
let receipt;
|
|
71523
71774
|
try {
|
|
71524
|
-
|
|
71775
|
+
receipt = parseReceipt(JSON.parse(line));
|
|
71525
71776
|
} catch (error61) {
|
|
71526
|
-
|
|
71527
|
-
await removeStaleVaultLock(lockPath);
|
|
71528
|
-
if (Date.now() >= deadline) {
|
|
71529
|
-
throw new VaultError("corrupt", "Timed out waiting for the vault lock.");
|
|
71530
|
-
}
|
|
71531
|
-
await new Promise((resolve3) => setTimeout(resolve3, 20));
|
|
71777
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71532
71778
|
}
|
|
71779
|
+
if (receiptWallet(receipt) !== from16 || receipt.transfer?.nonce.toLowerCase() !== nonce.toLowerCase()) {
|
|
71780
|
+
continue;
|
|
71781
|
+
}
|
|
71782
|
+
latest = receipt;
|
|
71783
|
+
if (receipt.transfer.request !== void 0) request = receipt;
|
|
71533
71784
|
}
|
|
71534
|
-
|
|
71535
|
-
|
|
71536
|
-
|
|
71537
|
-
|
|
71538
|
-
|
|
71539
|
-
|
|
71540
|
-
}
|
|
71541
|
-
async function removeStaleVaultLock(path) {
|
|
71542
|
-
try {
|
|
71543
|
-
const metadata = await stat6(path);
|
|
71544
|
-
if (Date.now() - metadata.mtimeMs > STALE_VAULT_LOCK_MS) await unlink4(path);
|
|
71545
|
-
} catch (error61) {
|
|
71546
|
-
if (!isMissingFile2(error61)) throw error61;
|
|
71547
|
-
}
|
|
71548
|
-
}
|
|
71549
|
-
function isMissingFile2(error61) {
|
|
71550
|
-
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "ENOENT";
|
|
71551
|
-
}
|
|
71552
|
-
function isExistingFile(error61) {
|
|
71553
|
-
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "EEXIST";
|
|
71554
|
-
}
|
|
71555
|
-
function asVaultError(error61, code, message) {
|
|
71556
|
-
return error61 instanceof VaultError ? error61 : new VaultError(code, message, { cause: error61 });
|
|
71785
|
+
return {
|
|
71786
|
+
signed: latest !== void 0,
|
|
71787
|
+
...latest === void 0 ? {} : { latest },
|
|
71788
|
+
...request === void 0 ? {} : { request },
|
|
71789
|
+
...request?.transfer?.request?.authorization.validBefore === void 0 ? {} : { validBefore: request.transfer.request.authorization.validBefore },
|
|
71790
|
+
...(latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn) === void 0 ? {} : { reservedOn: latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn }
|
|
71791
|
+
};
|
|
71557
71792
|
}
|
|
71558
71793
|
|
|
71559
71794
|
// ../core/src/vault-key.ts
|
|
71795
|
+
import { randomBytes as cryptoRandomBytes } from "node:crypto";
|
|
71560
71796
|
var VAULT_KEY_ACCOUNT = "vault-key";
|
|
71561
71797
|
var VAULT_SESSION_ACCOUNT = "vault-session";
|
|
71562
71798
|
var DEVICE_KEY_LENGTH = 32;
|
|
@@ -71784,8 +72020,8 @@ function passwordRequiredError() {
|
|
|
71784
72020
|
"A vault password is needed. Pass it or set VAPI_VAULT_PASSWORD."
|
|
71785
72021
|
);
|
|
71786
72022
|
}
|
|
71787
|
-
function randomKeyBytes(
|
|
71788
|
-
const key2 = Buffer.from((
|
|
72023
|
+
function randomKeyBytes(randomBytes18) {
|
|
72024
|
+
const key2 = Buffer.from((randomBytes18 ?? cryptoRandomBytes)(DEVICE_KEY_LENGTH));
|
|
71789
72025
|
if (key2.byteLength !== DEVICE_KEY_LENGTH) {
|
|
71790
72026
|
key2.fill(0);
|
|
71791
72027
|
throw new VaultError("corrupt", "A generated device vault key has the wrong length.");
|
|
@@ -71836,7 +72072,7 @@ function parseJson(value) {
|
|
|
71836
72072
|
function asVaultError2(error61, message) {
|
|
71837
72073
|
return error61 instanceof VaultError ? error61 : new VaultError("corrupt", message, { cause: error61 });
|
|
71838
72074
|
}
|
|
71839
|
-
var HEADLESS_LINUX_HINT = "A server, container or GitHub Codespace usually has no keyring.
|
|
72075
|
+
var HEADLESS_LINUX_HINT = "A server, container or GitHub Codespace usually has no keyring. Set VAPI_VAULT_PASSWORD and run vapi setup again, or run vapi on your own computer.";
|
|
71840
72076
|
function deviceKeyFailureMessage(error61, platform2) {
|
|
71841
72077
|
if (!(error61 instanceof KeystoreError)) return "Unable to load or create the device vault key.";
|
|
71842
72078
|
const detail = `Unable to load or create the device vault key: ${error61.message.replace(/\.$/u, "")}.`;
|
|
@@ -71848,19 +72084,19 @@ import {
|
|
|
71848
72084
|
chmod as chmod2,
|
|
71849
72085
|
lstat,
|
|
71850
72086
|
mkdir as mkdir9,
|
|
71851
|
-
readFile as
|
|
72087
|
+
readFile as readFile11,
|
|
71852
72088
|
readlink,
|
|
71853
72089
|
readdir as readdir2,
|
|
71854
72090
|
rename as rename6,
|
|
71855
72091
|
symlink,
|
|
71856
72092
|
unlink as unlink5
|
|
71857
72093
|
} from "node:fs/promises";
|
|
71858
|
-
import { join as
|
|
72094
|
+
import { join as join8, resolve } from "node:path";
|
|
71859
72095
|
var MIGRATED_DIRECTORY = "wallets.migrated";
|
|
71860
72096
|
async function legacyKeystoreNames(home) {
|
|
71861
72097
|
let entries;
|
|
71862
72098
|
try {
|
|
71863
|
-
entries = await readdir2(
|
|
72099
|
+
entries = await readdir2(join8(home, "wallets"), { withFileTypes: true });
|
|
71864
72100
|
} catch (error61) {
|
|
71865
72101
|
if (isMissingFile(error61)) return [];
|
|
71866
72102
|
throw error61;
|
|
@@ -71876,14 +72112,14 @@ async function migrateKeystores(args) {
|
|
|
71876
72112
|
);
|
|
71877
72113
|
const result = { imported: [], skipped: [] };
|
|
71878
72114
|
for (const name of names) {
|
|
71879
|
-
const source =
|
|
72115
|
+
const source = join8(args.home, "wallets", `${name}.json`);
|
|
71880
72116
|
if (args.vault.accounts().some((account) => account.name === name)) {
|
|
71881
72117
|
result.skipped.push({ name, reason: "name_taken" });
|
|
71882
72118
|
continue;
|
|
71883
72119
|
}
|
|
71884
72120
|
let parsed;
|
|
71885
72121
|
try {
|
|
71886
|
-
parsed = parseAnyKeystore(JSON.parse(await
|
|
72122
|
+
parsed = parseAnyKeystore(JSON.parse(await readFile11(source, "utf8")));
|
|
71887
72123
|
} catch {
|
|
71888
72124
|
result.skipped.push({ name, reason: "unreadable" });
|
|
71889
72125
|
continue;
|
|
@@ -71913,15 +72149,15 @@ async function migrateKeystores(args) {
|
|
|
71913
72149
|
if (imported.address.toLowerCase() !== parsed.address.toLowerCase()) {
|
|
71914
72150
|
throw new KeystoreError(`Migrated wallet ${name} does not match its stored address.`);
|
|
71915
72151
|
}
|
|
71916
|
-
const migratedDirectory =
|
|
71917
|
-
const destination =
|
|
72152
|
+
const migratedDirectory = join8(args.home, MIGRATED_DIRECTORY);
|
|
72153
|
+
const destination = join8(migratedDirectory, `${name}.json`);
|
|
71918
72154
|
await mkdir9(migratedDirectory, { recursive: true, mode: 448 });
|
|
71919
72155
|
await archiveExistingDestination(destination, migratedDirectory, name, now);
|
|
71920
72156
|
await rename6(source, destination);
|
|
71921
72157
|
await chmod2(destination, 384);
|
|
71922
72158
|
try {
|
|
71923
72159
|
await removeCompatibilityLink(args.home, source);
|
|
71924
|
-
await symlink(
|
|
72160
|
+
await symlink(join8("..", MIGRATED_DIRECTORY, `${name}.json`), source);
|
|
71925
72161
|
await audit({
|
|
71926
72162
|
event: "vault.migrate",
|
|
71927
72163
|
wallet: name,
|
|
@@ -71949,16 +72185,16 @@ async function migrateKeystores(args) {
|
|
|
71949
72185
|
async function archiveExistingDestination(destination, directory, name, now) {
|
|
71950
72186
|
if (!await pathExists2(destination)) return;
|
|
71951
72187
|
const timestamp = now().toISOString();
|
|
71952
|
-
let archive =
|
|
72188
|
+
let archive = join8(directory, `${name}.${timestamp}.json`);
|
|
71953
72189
|
let suffix = 1;
|
|
71954
72190
|
while (await pathExists2(archive)) {
|
|
71955
|
-
archive =
|
|
72191
|
+
archive = join8(directory, `${name}.${timestamp}.${suffix}.json`);
|
|
71956
72192
|
suffix += 1;
|
|
71957
72193
|
}
|
|
71958
72194
|
await rename6(destination, archive);
|
|
71959
72195
|
}
|
|
71960
72196
|
async function removeCompatibilityLink(home, migratedSource) {
|
|
71961
|
-
const compatibilityPath =
|
|
72197
|
+
const compatibilityPath = join8(home, "keystore.json");
|
|
71962
72198
|
let metadata;
|
|
71963
72199
|
try {
|
|
71964
72200
|
metadata = await lstat(compatibilityPath);
|
|
@@ -72032,7 +72268,7 @@ var WalletStore = class _WalletStore {
|
|
|
72032
72268
|
this.home = home;
|
|
72033
72269
|
this.options = options;
|
|
72034
72270
|
this.registry = registry2;
|
|
72035
|
-
this.secrets = options.secrets ?? secretStore();
|
|
72271
|
+
this.secrets = options.secrets ?? secretStore({ home });
|
|
72036
72272
|
this.environment = options.env ?? process.env;
|
|
72037
72273
|
this.passphraseResolver = options.resolvePassphrase ?? defaultPassphraseResolver(this.environment, this.secrets);
|
|
72038
72274
|
this.audit = options.audit ?? (async (record2) => await appendAudit(this.home, record2, { now: () => this.now() }));
|
|
@@ -72079,17 +72315,17 @@ var WalletStore = class _WalletStore {
|
|
|
72079
72315
|
return store;
|
|
72080
72316
|
}
|
|
72081
72317
|
get registryPath() {
|
|
72082
|
-
return
|
|
72318
|
+
return join9(this.home, REGISTRY_FILE);
|
|
72083
72319
|
}
|
|
72084
72320
|
get walletsDirectory() {
|
|
72085
|
-
return
|
|
72321
|
+
return join9(this.home, WALLETS_DIRECTORY);
|
|
72086
72322
|
}
|
|
72087
72323
|
get trashDirectory() {
|
|
72088
|
-
return
|
|
72324
|
+
return join9(this.walletsDirectory, TRASH_DIRECTORY);
|
|
72089
72325
|
}
|
|
72090
72326
|
/** The legacy 0.5 keystore path of a wallet, whether or not it exists. */
|
|
72091
72327
|
pathFor(name) {
|
|
72092
|
-
return
|
|
72328
|
+
return join9(this.walletsDirectory, `${assertWalletName(name)}.json`);
|
|
72093
72329
|
}
|
|
72094
72330
|
/** The names this machine knows, in registry order. */
|
|
72095
72331
|
names() {
|
|
@@ -72662,7 +72898,7 @@ var WalletStore = class _WalletStore {
|
|
|
72662
72898
|
}
|
|
72663
72899
|
const removedAt = this.now().toISOString();
|
|
72664
72900
|
await mkdir10(this.trashDirectory, { recursive: true, mode: 448 });
|
|
72665
|
-
const trashedPath =
|
|
72901
|
+
const trashedPath = join9(this.trashDirectory, `${wallet.name}-${removedAt}.json`);
|
|
72666
72902
|
const storedAccount = (await this.readVaultUnlocked())?.accounts.find(
|
|
72667
72903
|
(candidate) => candidate.name === wallet.name
|
|
72668
72904
|
);
|
|
@@ -72684,7 +72920,7 @@ var WalletStore = class _WalletStore {
|
|
|
72684
72920
|
this.balanceProbe = void 0;
|
|
72685
72921
|
}
|
|
72686
72922
|
if (await pathExists3(wallet.path)) {
|
|
72687
|
-
const legacyTrashedPath =
|
|
72923
|
+
const legacyTrashedPath = join9(
|
|
72688
72924
|
this.trashDirectory,
|
|
72689
72925
|
`${wallet.name}-${removedAt}.legacy.json`
|
|
72690
72926
|
);
|
|
@@ -72774,7 +73010,7 @@ var WalletStore = class _WalletStore {
|
|
|
72774
73010
|
if (!match) continue;
|
|
72775
73011
|
const [, name, removedAt] = match;
|
|
72776
73012
|
if (name === void 0 || removedAt === void 0 || !isWalletName(name)) continue;
|
|
72777
|
-
const path =
|
|
73013
|
+
const path = join9(this.trashDirectory, file2);
|
|
72778
73014
|
const entry = await readEntrySidecar(entrySidecarPath(path));
|
|
72779
73015
|
trashed.push({ name, removedAt, path, ...entry ? { entry } : {} });
|
|
72780
73016
|
}
|
|
@@ -72843,7 +73079,7 @@ var WalletStore = class _WalletStore {
|
|
|
72843
73079
|
return entry;
|
|
72844
73080
|
}
|
|
72845
73081
|
get vaultPath() {
|
|
72846
|
-
return
|
|
73082
|
+
return join9(this.home, VAULT_FILE);
|
|
72847
73083
|
}
|
|
72848
73084
|
async readVaultUnlocked() {
|
|
72849
73085
|
try {
|
|
@@ -72948,7 +73184,7 @@ var WalletStore = class _WalletStore {
|
|
|
72948
73184
|
async readRegistry() {
|
|
72949
73185
|
let raw;
|
|
72950
73186
|
try {
|
|
72951
|
-
raw = await
|
|
73187
|
+
raw = await readFile12(this.registryPath, "utf8");
|
|
72952
73188
|
} catch (error61) {
|
|
72953
73189
|
if (isMissingFile(error61)) return emptyRegistry();
|
|
72954
73190
|
throw error61;
|
|
@@ -72969,7 +73205,7 @@ var WalletStore = class _WalletStore {
|
|
|
72969
73205
|
}
|
|
72970
73206
|
};
|
|
72971
73207
|
async function swarmReferencingAccount(home, account) {
|
|
72972
|
-
const directory =
|
|
73208
|
+
const directory = join9(home, "swarms");
|
|
72973
73209
|
let files;
|
|
72974
73210
|
try {
|
|
72975
73211
|
files = await readdir3(directory);
|
|
@@ -72980,7 +73216,7 @@ async function swarmReferencingAccount(home, account) {
|
|
|
72980
73216
|
for (const file2 of files.filter((name) => name.endsWith(".json")).sort()) {
|
|
72981
73217
|
let value;
|
|
72982
73218
|
try {
|
|
72983
|
-
value = JSON.parse(await
|
|
73219
|
+
value = JSON.parse(await readFile12(join9(directory, file2), "utf8"));
|
|
72984
73220
|
} catch {
|
|
72985
73221
|
throw new KeystoreError(
|
|
72986
73222
|
`Cannot verify swarm references because ${file2} is invalid. Repair or remove that swarm file before renaming an account.`
|
|
@@ -73012,7 +73248,7 @@ async function swarmReferencingAccount(home, account) {
|
|
|
73012
73248
|
return void 0;
|
|
73013
73249
|
}
|
|
73014
73250
|
async function unfinishedMovementReferencingAccount(home, account) {
|
|
73015
|
-
const directory =
|
|
73251
|
+
const directory = join9(home, "movements");
|
|
73016
73252
|
let files;
|
|
73017
73253
|
try {
|
|
73018
73254
|
files = await readdir3(directory);
|
|
@@ -73023,7 +73259,7 @@ async function unfinishedMovementReferencingAccount(home, account) {
|
|
|
73023
73259
|
for (const file2 of files.filter((name) => name.endsWith(".json")).sort()) {
|
|
73024
73260
|
let value;
|
|
73025
73261
|
try {
|
|
73026
|
-
value = JSON.parse(await
|
|
73262
|
+
value = JSON.parse(await readFile12(join9(directory, file2), "utf8"));
|
|
73027
73263
|
} catch {
|
|
73028
73264
|
throw invalidMovementReferenceError(file2);
|
|
73029
73265
|
}
|
|
@@ -73044,11 +73280,11 @@ async function unfinishedMovementReferencingAccount(home, account) {
|
|
|
73044
73280
|
const restored = Reflect.get(leg, "restored");
|
|
73045
73281
|
const legFrom = Reflect.get(leg, "from") ?? movementFrom;
|
|
73046
73282
|
const journal = restored !== true && status === "failed" && retryable !== true && typeof nonce === "string" ? await readTransferJournal(home, legFrom, nonce) : void 0;
|
|
73047
|
-
const
|
|
73283
|
+
const open13 = isOpenMovementLeg(
|
|
73048
73284
|
{ status, retryable, nonce, restored },
|
|
73049
73285
|
journal?.signed === true ? "signed" : "unsigned"
|
|
73050
73286
|
);
|
|
73051
|
-
if (
|
|
73287
|
+
if (open13) movementOpen = true;
|
|
73052
73288
|
}
|
|
73053
73289
|
if (movementOpen && (movementFrom === account || legs.some(
|
|
73054
73290
|
(leg) => (Reflect.get(leg, "from") ?? movementFrom) === account || Reflect.get(leg, "to") === account
|
|
@@ -73084,7 +73320,7 @@ async function withAccountMutationLocks(home, accounts, command, operation) {
|
|
|
73084
73320
|
const [account, ...remaining2] = [...new Set(accounts)].sort();
|
|
73085
73321
|
if (account === void 0) return await operation();
|
|
73086
73322
|
return await withFileLock(
|
|
73087
|
-
|
|
73323
|
+
join9(home, `.account-${account}.lock`),
|
|
73088
73324
|
async () => await withAccountMutationLocks(home, remaining2, command, operation),
|
|
73089
73325
|
{
|
|
73090
73326
|
lockedMessage: `Account ${account} is busy with another account change. Wait for it to finish, then retry ${command}.`
|
|
@@ -73159,7 +73395,7 @@ function isLockedVaultError(error61) {
|
|
|
73159
73395
|
async function readTrashedVaultAccount(path) {
|
|
73160
73396
|
let parsed;
|
|
73161
73397
|
try {
|
|
73162
|
-
parsed = JSON.parse(await
|
|
73398
|
+
parsed = JSON.parse(await readFile12(path, "utf8"));
|
|
73163
73399
|
} catch {
|
|
73164
73400
|
return void 0;
|
|
73165
73401
|
}
|
|
@@ -73168,7 +73404,7 @@ async function readTrashedVaultAccount(path) {
|
|
|
73168
73404
|
}
|
|
73169
73405
|
async function readEntrySidecar(path) {
|
|
73170
73406
|
try {
|
|
73171
|
-
const parsed = walletEntrySchema.safeParse(JSON.parse(await
|
|
73407
|
+
const parsed = walletEntrySchema.safeParse(JSON.parse(await readFile12(path, "utf8")));
|
|
73172
73408
|
return parsed.success ? parsed.data : void 0;
|
|
73173
73409
|
} catch {
|
|
73174
73410
|
return void 0;
|
|
@@ -73177,7 +73413,7 @@ async function readEntrySidecar(path) {
|
|
|
73177
73413
|
async function readKeystoreSummary(path) {
|
|
73178
73414
|
let parsed;
|
|
73179
73415
|
try {
|
|
73180
|
-
parsed = JSON.parse(await
|
|
73416
|
+
parsed = JSON.parse(await readFile12(path, "utf8"));
|
|
73181
73417
|
} catch {
|
|
73182
73418
|
return {};
|
|
73183
73419
|
}
|
|
@@ -73195,7 +73431,7 @@ async function readKeystoreSummary(path) {
|
|
|
73195
73431
|
}
|
|
73196
73432
|
async function readConfiguredSpendCaps(configPath) {
|
|
73197
73433
|
try {
|
|
73198
|
-
const parsed = JSON.parse(await
|
|
73434
|
+
const parsed = JSON.parse(await readFile12(configPath, "utf8"));
|
|
73199
73435
|
const caps = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "spendCaps") : void 0;
|
|
73200
73436
|
const result = spendCapsSchema.safeParse(caps);
|
|
73201
73437
|
if (result.success) return result.data;
|
|
@@ -73287,7 +73523,7 @@ async function withRegistryLock(path, operation) {
|
|
|
73287
73523
|
let handle;
|
|
73288
73524
|
while (!handle) {
|
|
73289
73525
|
try {
|
|
73290
|
-
handle = await
|
|
73526
|
+
handle = await open8(lockPath, "wx", 384);
|
|
73291
73527
|
} catch (error61) {
|
|
73292
73528
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) throw error61;
|
|
73293
73529
|
await removeStaleRegistryLock(lockPath);
|
|
@@ -73306,7 +73542,7 @@ async function withRegistryLock(path, operation) {
|
|
|
73306
73542
|
}
|
|
73307
73543
|
async function removeStaleRegistryLock(path) {
|
|
73308
73544
|
try {
|
|
73309
|
-
const metadata = await
|
|
73545
|
+
const metadata = await stat9(path);
|
|
73310
73546
|
if (Date.now() - metadata.mtimeMs > 3e4) await unlink6(path);
|
|
73311
73547
|
} catch (error61) {
|
|
73312
73548
|
if (!isMissingFile(error61)) throw error61;
|
|
@@ -73314,7 +73550,7 @@ async function removeStaleRegistryLock(path) {
|
|
|
73314
73550
|
}
|
|
73315
73551
|
async function writeJsonFile(path, value) {
|
|
73316
73552
|
await mkdir10(dirname7(path), { recursive: true, mode: 448 });
|
|
73317
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
73553
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes9(6).toString("hex")}.tmp`;
|
|
73318
73554
|
await writeFile5(temporaryPath, `${JSON.stringify(value, null, 2)}
|
|
73319
73555
|
`, {
|
|
73320
73556
|
encoding: "utf8",
|
|
@@ -73352,7 +73588,7 @@ async function createAccount(args) {
|
|
|
73352
73588
|
created: false
|
|
73353
73589
|
};
|
|
73354
73590
|
}
|
|
73355
|
-
if (!await
|
|
73591
|
+
if (!await fileExists2(join10(args.store.home, "vault.json"))) {
|
|
73356
73592
|
throw new KeystoreError("No vault yet. Run vapi setup.");
|
|
73357
73593
|
}
|
|
73358
73594
|
const spendCaps = resolveNewAccountCaps(args.caps);
|
|
@@ -73619,9 +73855,9 @@ async function requireAddress(store, name) {
|
|
|
73619
73855
|
if (address4 === void 0) throw new KeystoreError(`No key for wallet ${name} in the vault.`);
|
|
73620
73856
|
return address4;
|
|
73621
73857
|
}
|
|
73622
|
-
async function
|
|
73858
|
+
async function fileExists2(path) {
|
|
73623
73859
|
try {
|
|
73624
|
-
await
|
|
73860
|
+
await stat10(path);
|
|
73625
73861
|
return true;
|
|
73626
73862
|
} catch (error61) {
|
|
73627
73863
|
if (isMissingFile(error61)) return false;
|
|
@@ -73683,9 +73919,9 @@ function secretsAllowed(env, streams) {
|
|
|
73683
73919
|
}
|
|
73684
73920
|
|
|
73685
73921
|
// ../core/src/agent-profile.ts
|
|
73686
|
-
import { randomBytes as
|
|
73687
|
-
import { mkdir as mkdir11, readFile as
|
|
73688
|
-
import { join as
|
|
73922
|
+
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
73923
|
+
import { mkdir as mkdir11, readFile as readFile13, readdir as readdir4, rename as rename8, unlink as unlink7, writeFile as writeFile6 } from "node:fs/promises";
|
|
73924
|
+
import { join as join11 } from "node:path";
|
|
73689
73925
|
var DEFAULT_AGENT_TOOLS = ["call.search", "call.inspect", "call.pay"];
|
|
73690
73926
|
var AGENT_GRANTS = ["read", "delegate", "allocate"];
|
|
73691
73927
|
var agentProfileShape = {
|
|
@@ -73715,7 +73951,7 @@ async function readAgentProfile(home, name, options = {}) {
|
|
|
73715
73951
|
const path = agentProfilePath(home, name);
|
|
73716
73952
|
let raw;
|
|
73717
73953
|
try {
|
|
73718
|
-
raw = await
|
|
73954
|
+
raw = await readFile13(path, "utf8");
|
|
73719
73955
|
} catch (error61) {
|
|
73720
73956
|
if (isMissingFile(error61)) {
|
|
73721
73957
|
throw new Error(`No agent named ${name}. Create it with vapi agent create ${name}.`);
|
|
@@ -73727,9 +73963,9 @@ async function readAgentProfile(home, name, options = {}) {
|
|
|
73727
73963
|
async function writeAgentProfile(home, profile, options = {}) {
|
|
73728
73964
|
const parsed = (options.schema ?? agentProfileSchema).parse(profile);
|
|
73729
73965
|
const directory = getVapiPaths(home).agentsDir;
|
|
73730
|
-
const path =
|
|
73966
|
+
const path = join11(directory, `${parsed.name}.json`);
|
|
73731
73967
|
await mkdir11(directory, { recursive: true, mode: 448 });
|
|
73732
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
73968
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes10(6).toString("hex")}.tmp`;
|
|
73733
73969
|
await writeFile6(temporaryPath, `${JSON.stringify(parsed, null, 2)}
|
|
73734
73970
|
`, {
|
|
73735
73971
|
encoding: "utf8",
|
|
@@ -73754,7 +73990,7 @@ async function listAgentProfiles(home, options = {}) {
|
|
|
73754
73990
|
try {
|
|
73755
73991
|
profiles.push(
|
|
73756
73992
|
(options.schema ?? agentProfileSchema).parse(
|
|
73757
|
-
JSON.parse(await
|
|
73993
|
+
JSON.parse(await readFile13(join11(directory, file2), "utf8"))
|
|
73758
73994
|
)
|
|
73759
73995
|
);
|
|
73760
73996
|
} catch {
|
|
@@ -73775,11 +74011,11 @@ async function removeAgentProfile(home, name) {
|
|
|
73775
74011
|
}
|
|
73776
74012
|
function agentProfilePath(home, name) {
|
|
73777
74013
|
const parsedName = walletNameSchema.parse(name);
|
|
73778
|
-
return
|
|
74014
|
+
return join11(getVapiPaths(home).agentsDir, `${parsedName}.json`);
|
|
73779
74015
|
}
|
|
73780
74016
|
|
|
73781
74017
|
// ../core/src/ceiling.ts
|
|
73782
|
-
import { randomBytes as
|
|
74018
|
+
import { randomBytes as randomBytes14 } from "node:crypto";
|
|
73783
74019
|
|
|
73784
74020
|
// ../core/src/authorization-state.ts
|
|
73785
74021
|
var EIP3009_AUTHORIZATION_STATE_ABI = [
|
|
@@ -73844,13 +74080,13 @@ function missingAuthorization(receipt) {
|
|
|
73844
74080
|
}
|
|
73845
74081
|
|
|
73846
74082
|
// ../core/src/movement.ts
|
|
73847
|
-
import { randomBytes as
|
|
73848
|
-
import { chmod as chmod4, mkdir as mkdir14, open as
|
|
73849
|
-
import { join as
|
|
74083
|
+
import { randomBytes as randomBytes13 } from "node:crypto";
|
|
74084
|
+
import { chmod as chmod4, mkdir as mkdir14, open as open11, readFile as readFile15, readdir as readdir5, rename as rename10, unlink as unlink10 } from "node:fs/promises";
|
|
74085
|
+
import { join as join12 } from "node:path";
|
|
73850
74086
|
|
|
73851
74087
|
// ../core/src/spend-policy.ts
|
|
73852
|
-
import { randomBytes as
|
|
73853
|
-
import { mkdir as mkdir12, open as
|
|
74088
|
+
import { randomBytes as randomBytes11 } from "node:crypto";
|
|
74089
|
+
import { mkdir as mkdir12, open as open9, readFile as readFile14, rename as rename9, stat as stat11, unlink as unlink8, writeFile as writeFile7 } from "node:fs/promises";
|
|
73854
74090
|
import { dirname as dirname8 } from "node:path";
|
|
73855
74091
|
var ledgerSchema = external_exports.object({
|
|
73856
74092
|
date: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
@@ -73921,7 +74157,7 @@ async function readSpendLedgerRows(path = getAgentCashPaths().ledger, now = /* @
|
|
|
73921
74157
|
async function readStoredSpendLedgerRows(path, now, allDays = false) {
|
|
73922
74158
|
let raw;
|
|
73923
74159
|
try {
|
|
73924
|
-
raw = await
|
|
74160
|
+
raw = await readFile14(path, "utf8");
|
|
73925
74161
|
} catch (error61) {
|
|
73926
74162
|
if (isMissingFile(error61)) return [];
|
|
73927
74163
|
throw error61;
|
|
@@ -74054,7 +74290,7 @@ async function reserveSpend(amountAtomic2, caps, options) {
|
|
|
74054
74290
|
{ amountAtomic: amountAtomic2, limitAtomic: perDayAtomic, spentAtomic: BigInt(spentAtomic), wallet }
|
|
74055
74291
|
);
|
|
74056
74292
|
}
|
|
74057
|
-
const reservationId = options?.reservationId ?? (options?.taskKey === void 0 ? void 0 :
|
|
74293
|
+
const reservationId = options?.reservationId ?? (options?.taskKey === void 0 ? void 0 : randomBytes11(16).toString("hex"));
|
|
74058
74294
|
const nextRow = {
|
|
74059
74295
|
date: utcDateKey(now),
|
|
74060
74296
|
spentAtomic: nextSpent.toString(),
|
|
@@ -74160,7 +74396,7 @@ async function writeLedgerAtomically(path, rows) {
|
|
|
74160
74396
|
...rows[0].reservations === void 0 ? {} : { reservations: rows[0].reservations }
|
|
74161
74397
|
} : { version: 1, rows };
|
|
74162
74398
|
await mkdir12(dirname8(path), { recursive: true, mode: 448 });
|
|
74163
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
74399
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes11(6).toString("hex")}.tmp`;
|
|
74164
74400
|
await writeFile7(temporaryPath, `${JSON.stringify(ledger, null, 2)}
|
|
74165
74401
|
`, {
|
|
74166
74402
|
encoding: "utf8",
|
|
@@ -74176,7 +74412,7 @@ async function withLedgerLock(path, operation) {
|
|
|
74176
74412
|
let handle;
|
|
74177
74413
|
while (!handle) {
|
|
74178
74414
|
try {
|
|
74179
|
-
handle = await
|
|
74415
|
+
handle = await open9(lockPath, "wx", 384);
|
|
74180
74416
|
} catch (error61) {
|
|
74181
74417
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) {
|
|
74182
74418
|
throw error61;
|
|
@@ -74197,7 +74433,7 @@ async function withLedgerLock(path, operation) {
|
|
|
74197
74433
|
}
|
|
74198
74434
|
async function removeStaleLock3(path) {
|
|
74199
74435
|
try {
|
|
74200
|
-
const metadata = await
|
|
74436
|
+
const metadata = await stat11(path);
|
|
74201
74437
|
if (Date.now() - metadata.mtimeMs > 3e4) {
|
|
74202
74438
|
await unlink8(path);
|
|
74203
74439
|
}
|
|
@@ -74209,8 +74445,8 @@ async function removeStaleLock3(path) {
|
|
|
74209
74445
|
}
|
|
74210
74446
|
|
|
74211
74447
|
// ../core/src/transfer.ts
|
|
74212
|
-
import { randomBytes as
|
|
74213
|
-
import { mkdir as mkdir13, open as
|
|
74448
|
+
import { randomBytes as randomBytes12, randomUUID } from "node:crypto";
|
|
74449
|
+
import { mkdir as mkdir13, open as open10, stat as stat12, unlink as unlink9 } from "node:fs/promises";
|
|
74214
74450
|
import { dirname as dirname9 } from "node:path";
|
|
74215
74451
|
|
|
74216
74452
|
// ../core/src/siblings.ts
|
|
@@ -74419,7 +74655,7 @@ async function transferBetweenAccounts(args) {
|
|
|
74419
74655
|
if (args.resume !== void 0) {
|
|
74420
74656
|
return await resumeTransfer(context, args.resume);
|
|
74421
74657
|
}
|
|
74422
|
-
const nonce = args.nonce ?? bytesToHex(
|
|
74658
|
+
const nonce = args.nonce ?? bytesToHex(randomBytes12(32));
|
|
74423
74659
|
if (!NONCE_PATTERN.test(nonce)) {
|
|
74424
74660
|
throw new TransferError(
|
|
74425
74661
|
"authorization_invalid",
|
|
@@ -74812,7 +75048,7 @@ async function withTransferLock(context, nonce, operation) {
|
|
|
74812
75048
|
let handle;
|
|
74813
75049
|
while (!handle) {
|
|
74814
75050
|
try {
|
|
74815
|
-
handle = await
|
|
75051
|
+
handle = await open10(lockPath, "wx", 384);
|
|
74816
75052
|
} catch (error61) {
|
|
74817
75053
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) throw error61;
|
|
74818
75054
|
await removeStaleTransferLock(lockPath, staleAfterMs);
|
|
@@ -74831,7 +75067,7 @@ async function withTransferLock(context, nonce, operation) {
|
|
|
74831
75067
|
}
|
|
74832
75068
|
async function removeStaleTransferLock(path, staleAfterMs) {
|
|
74833
75069
|
try {
|
|
74834
|
-
const metadata = await
|
|
75070
|
+
const metadata = await stat12(path);
|
|
74835
75071
|
if (Date.now() - metadata.mtimeMs > staleAfterMs) await unlink9(path);
|
|
74836
75072
|
} catch (error61) {
|
|
74837
75073
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "ENOENT")) throw error61;
|
|
@@ -75257,7 +75493,7 @@ async function listUnfinishedMovements(options) {
|
|
|
75257
75493
|
}
|
|
75258
75494
|
const summaries = [];
|
|
75259
75495
|
for (const name of names.filter((candidate) => candidate.endsWith(".json")).sort()) {
|
|
75260
|
-
const movement = parseMovement(JSON.parse(await
|
|
75496
|
+
const movement = parseMovement(JSON.parse(await readFile15(join12(directory, name), "utf8")));
|
|
75261
75497
|
if (options.from !== void 0 && !movement.legs.some((leg) => leg.from === options.from)) {
|
|
75262
75498
|
continue;
|
|
75263
75499
|
}
|
|
@@ -75288,7 +75524,7 @@ async function listUnfinishedMovementSnapshots(options) {
|
|
|
75288
75524
|
}
|
|
75289
75525
|
const snapshots = [];
|
|
75290
75526
|
for (const name of names.filter((candidate) => candidate.endsWith(".json")).sort()) {
|
|
75291
|
-
const movement = parseMovement(JSON.parse(await
|
|
75527
|
+
const movement = parseMovement(JSON.parse(await readFile15(join12(directory, name), "utf8")));
|
|
75292
75528
|
if (options.from !== void 0 && !movement.legs.some((leg) => leg.from === options.from)) {
|
|
75293
75529
|
continue;
|
|
75294
75530
|
}
|
|
@@ -75324,23 +75560,23 @@ async function movementHasOpenLeg(home, movement, from16) {
|
|
|
75324
75560
|
return false;
|
|
75325
75561
|
}
|
|
75326
75562
|
async function movementOpenEvidence(home, movement, from16) {
|
|
75327
|
-
let
|
|
75563
|
+
let open13 = false;
|
|
75328
75564
|
const signedFailedLegKeys = [];
|
|
75329
75565
|
for (const leg of movement.legs) {
|
|
75330
75566
|
if (from16 !== void 0 && leg.from !== from16) continue;
|
|
75331
|
-
if (isOpenMovementLeg(leg, "unsigned"))
|
|
75567
|
+
if (isOpenMovementLeg(leg, "unsigned")) open13 = true;
|
|
75332
75568
|
if (leg.status !== "failed") continue;
|
|
75333
75569
|
const journal = await readTransferJournal(home, leg.from, leg.nonce);
|
|
75334
75570
|
if (journal.signed) signedFailedLegKeys.push(movementTransferKey(leg.from, leg.nonce));
|
|
75335
|
-
if (isOpenMovementLeg(leg, journal.signed ? "signed" : "unsigned"))
|
|
75571
|
+
if (isOpenMovementLeg(leg, journal.signed ? "signed" : "unsigned")) open13 = true;
|
|
75336
75572
|
}
|
|
75337
|
-
return { open:
|
|
75573
|
+
return { open: open13, signedFailedLegKeys };
|
|
75338
75574
|
}
|
|
75339
75575
|
async function readMovement(home, id2) {
|
|
75340
75576
|
const safeId = parseMovementId(id2);
|
|
75341
75577
|
try {
|
|
75342
75578
|
return parseMovement(
|
|
75343
|
-
JSON.parse(await
|
|
75579
|
+
JSON.parse(await readFile15(join12(movementsDirectory(home), `${safeId}.json`), "utf8"))
|
|
75344
75580
|
);
|
|
75345
75581
|
} catch (error61) {
|
|
75346
75582
|
if (isMissingFile(error61)) {
|
|
@@ -76060,33 +76296,33 @@ function parseMovementId(value) {
|
|
|
76060
76296
|
return parsed.data;
|
|
76061
76297
|
}
|
|
76062
76298
|
function movementsDirectory(home) {
|
|
76063
|
-
return
|
|
76299
|
+
return join12(home, "movements");
|
|
76064
76300
|
}
|
|
76065
76301
|
function createMovementId() {
|
|
76066
|
-
return `mv_${
|
|
76302
|
+
return `mv_${randomBytes13(12).toString("hex")}`;
|
|
76067
76303
|
}
|
|
76068
76304
|
function createMovementNonce() {
|
|
76069
|
-
return bytesToHex(
|
|
76305
|
+
return bytesToHex(randomBytes13(32));
|
|
76070
76306
|
}
|
|
76071
76307
|
async function writeMovement(home, movement) {
|
|
76072
76308
|
const parsed = movementSchema.parse(movement);
|
|
76073
76309
|
const directory = movementsDirectory(home);
|
|
76074
76310
|
await mkdir14(directory, { recursive: true, mode: 448 });
|
|
76075
76311
|
await chmod4(directory, 448);
|
|
76076
|
-
const path =
|
|
76077
|
-
const temporary =
|
|
76312
|
+
const path = join12(directory, `${parsed.id}.json`);
|
|
76313
|
+
const temporary = join12(
|
|
76078
76314
|
directory,
|
|
76079
|
-
`.${parsed.id}.${process.pid}.${
|
|
76315
|
+
`.${parsed.id}.${process.pid}.${randomBytes13(6).toString("hex")}.tmp`
|
|
76080
76316
|
);
|
|
76081
76317
|
let handle;
|
|
76082
76318
|
try {
|
|
76083
|
-
handle = await
|
|
76319
|
+
handle = await open11(temporary, "wx", 384);
|
|
76084
76320
|
await handle.writeFile(serializeMovement(parsed), "utf8");
|
|
76085
76321
|
await handle.sync();
|
|
76086
76322
|
await handle.close();
|
|
76087
76323
|
handle = void 0;
|
|
76088
76324
|
await rename10(temporary, path);
|
|
76089
|
-
const directoryHandle = await
|
|
76325
|
+
const directoryHandle = await open11(directory, "r");
|
|
76090
76326
|
try {
|
|
76091
76327
|
await directoryHandle.sync();
|
|
76092
76328
|
} finally {
|
|
@@ -76306,7 +76542,7 @@ async function sweepAboveCeilingLocked(args) {
|
|
|
76306
76542
|
owner,
|
|
76307
76543
|
target,
|
|
76308
76544
|
amountAtomic: amountAtomic2.toString(),
|
|
76309
|
-
nonce: (args.randomNonce ?? (() => bytesToHex(
|
|
76545
|
+
nonce: (args.randomNonce ?? (() => bytesToHex(randomBytes14(32))))(),
|
|
76310
76546
|
createdAt: new Date(now()).toISOString(),
|
|
76311
76547
|
status: "planned"
|
|
76312
76548
|
};
|
|
@@ -77098,8 +77334,8 @@ function parseDecimal(value, scale) {
|
|
|
77098
77334
|
}
|
|
77099
77335
|
|
|
77100
77336
|
// ../core/src/swarm.ts
|
|
77101
|
-
import { readdir as readdir6, readFile as
|
|
77102
|
-
import { join as
|
|
77337
|
+
import { readdir as readdir6, readFile as readFile16, stat as stat13, unlink as unlink11 } from "node:fs/promises";
|
|
77338
|
+
import { join as join13 } from "node:path";
|
|
77103
77339
|
var SWARM_NAME_PATTERN = /^[a-z][a-z0-9-]{0,15}$/;
|
|
77104
77340
|
var SWARM_ROLE_PATTERN = /^[a-z][a-z0-9]{0,7}$/;
|
|
77105
77341
|
var DEFAULT_SWARM_MODEL = "venice/claude-sonnet-5";
|
|
@@ -77180,16 +77416,16 @@ var SwarmError = class extends Error {
|
|
|
77180
77416
|
code;
|
|
77181
77417
|
};
|
|
77182
77418
|
function swarmsDirectory(home) {
|
|
77183
|
-
return
|
|
77419
|
+
return join13(home, "swarms");
|
|
77184
77420
|
}
|
|
77185
77421
|
function swarmFilePath(home, name) {
|
|
77186
77422
|
assertName(name);
|
|
77187
|
-
return
|
|
77423
|
+
return join13(swarmsDirectory(home), `${name}.json`);
|
|
77188
77424
|
}
|
|
77189
77425
|
async function readSwarm(home, name) {
|
|
77190
77426
|
const path = swarmFilePath(home, name);
|
|
77191
77427
|
try {
|
|
77192
|
-
const swarm = parseSwarm(JSON.parse(await
|
|
77428
|
+
const swarm = parseSwarm(JSON.parse(await readFile16(path, "utf8")));
|
|
77193
77429
|
if (swarm.name !== name)
|
|
77194
77430
|
throw new SwarmError("invalid_swarm", "Swarm name does not match its file.");
|
|
77195
77431
|
return swarm;
|
|
@@ -77217,7 +77453,7 @@ async function writeSwarm(home, value) {
|
|
|
77217
77453
|
const bytes = `${JSON.stringify(swarm, null, 2)}
|
|
77218
77454
|
`;
|
|
77219
77455
|
try {
|
|
77220
|
-
if (await
|
|
77456
|
+
if (await readFile16(path, "utf8") === bytes) return;
|
|
77221
77457
|
} catch (error61) {
|
|
77222
77458
|
if (!isMissingFile(error61)) throw error61;
|
|
77223
77459
|
}
|
|
@@ -77232,7 +77468,7 @@ async function deleteSwarmFile(home, name) {
|
|
|
77232
77468
|
}
|
|
77233
77469
|
async function withSwarmLock(home, name, fn) {
|
|
77234
77470
|
assertName(name);
|
|
77235
|
-
const path =
|
|
77471
|
+
const path = join13(swarmsDirectory(home), `.${name}.lock`);
|
|
77236
77472
|
try {
|
|
77237
77473
|
return await withFileLock(path, fn, { lockedMessage: `Swarm ${name} is locked.` });
|
|
77238
77474
|
} catch (error61) {
|
|
@@ -77544,7 +77780,7 @@ async function swarmStatus(opts) {
|
|
|
77544
77780
|
);
|
|
77545
77781
|
let movementFiles;
|
|
77546
77782
|
try {
|
|
77547
|
-
movementFiles = await readdir6(
|
|
77783
|
+
movementFiles = await readdir6(join13(home, "movements"));
|
|
77548
77784
|
} catch (error61) {
|
|
77549
77785
|
if (!isMissingFile(error61)) throw error61;
|
|
77550
77786
|
movementFiles = [];
|
|
@@ -77601,11 +77837,11 @@ async function swarmStatus(opts) {
|
|
|
77601
77837
|
})
|
|
77602
77838
|
);
|
|
77603
77839
|
const accounts = new Set(swarmAccountNames(swarm));
|
|
77604
|
-
const
|
|
77840
|
+
const open13 = [];
|
|
77605
77841
|
for (const summary2 of await listUnfinishedMovements({ home })) {
|
|
77606
77842
|
const movement = await readMovement(home, summary2.id);
|
|
77607
77843
|
if (movement.treasury === swarm.treasury.account || movement.legs.some((leg) => accounts.has(leg.from) || accounts.has(leg.to))) {
|
|
77608
|
-
|
|
77844
|
+
open13.push(summary2);
|
|
77609
77845
|
}
|
|
77610
77846
|
}
|
|
77611
77847
|
return {
|
|
@@ -77614,7 +77850,7 @@ async function swarmStatus(opts) {
|
|
|
77614
77850
|
strategy: swarm.policy.strategy,
|
|
77615
77851
|
treasury,
|
|
77616
77852
|
members: members2,
|
|
77617
|
-
openMovements:
|
|
77853
|
+
openMovements: open13.sort(
|
|
77618
77854
|
(a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id)
|
|
77619
77855
|
)
|
|
77620
77856
|
};
|
|
@@ -77713,7 +77949,7 @@ async function assertNoConflicts(home, name, accounts) {
|
|
|
77713
77949
|
}
|
|
77714
77950
|
async function profileExists(home, account) {
|
|
77715
77951
|
try {
|
|
77716
|
-
await
|
|
77952
|
+
await stat13(join13(getVapiPaths(home).agentsDir, `${account}.json`));
|
|
77717
77953
|
return true;
|
|
77718
77954
|
} catch (error61) {
|
|
77719
77955
|
if (isMissingFile(error61)) return false;
|
|
@@ -77726,7 +77962,7 @@ async function refuseTreasuryProfile(home, account) {
|
|
|
77726
77962
|
}
|
|
77727
77963
|
|
|
77728
77964
|
// ../core/src/x402-pay.ts
|
|
77729
|
-
import { randomBytes as
|
|
77965
|
+
import { randomBytes as randomBytes15, randomUUID as randomUUID2 } from "node:crypto";
|
|
77730
77966
|
|
|
77731
77967
|
// ../core/src/run-budget.ts
|
|
77732
77968
|
var RunBudgetError = class extends Error {
|
|
@@ -77767,13 +78003,13 @@ function createRunBudget(args) {
|
|
|
77767
78003
|
// ../core/src/support-report.ts
|
|
77768
78004
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
77769
78005
|
import { arch, platform, release } from "node:os";
|
|
77770
|
-
import { join as
|
|
77771
|
-
var VAPI_CLIENT_VERSION = "0.
|
|
78006
|
+
import { join as join14 } from "node:path";
|
|
78007
|
+
var VAPI_CLIENT_VERSION = "0.13.0";
|
|
77772
78008
|
async function createSupportReport(options) {
|
|
77773
78009
|
const message = options.message.trim();
|
|
77774
78010
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
77775
78011
|
const paths = getVapiPaths();
|
|
77776
|
-
const reportsDirectory = options.reportsDirectory ??
|
|
78012
|
+
const reportsDirectory = options.reportsDirectory ?? join14(paths.directory, "reports");
|
|
77777
78013
|
const receipts = await readReceipts(options.receiptsPath ?? paths.receipts, { limit: 5 });
|
|
77778
78014
|
const system = options.systemInfo ?? defaultSystemInfo();
|
|
77779
78015
|
const report = {
|
|
@@ -77803,7 +78039,7 @@ async function createSupportReport(options) {
|
|
|
77803
78039
|
};
|
|
77804
78040
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
77805
78041
|
const timestamp = now.toISOString();
|
|
77806
|
-
const path =
|
|
78042
|
+
const path = join14(reportsDirectory, `${sanitizeTimestamp(timestamp)}.json`);
|
|
77807
78043
|
await mkdir15(reportsDirectory, { recursive: true, mode: 448 });
|
|
77808
78044
|
const serialized = `${JSON.stringify(report, null, 2)}
|
|
77809
78045
|
`;
|
|
@@ -77999,7 +78235,7 @@ async function completeX402Payment(args) {
|
|
|
77999
78235
|
throw walletCapError(error61, quote.amountAtomic, args);
|
|
78000
78236
|
}
|
|
78001
78237
|
} else {
|
|
78002
|
-
reservationId = args.paymentId ?? `x402_${
|
|
78238
|
+
reservationId = args.paymentId ?? `x402_${randomBytes15(12).toString("hex")}`;
|
|
78003
78239
|
let reservation;
|
|
78004
78240
|
try {
|
|
78005
78241
|
reservation = await reserveSpend(quote.amountAtomic, args.caps, {
|
|
@@ -79400,8 +79636,8 @@ function freezeScopeTerms(structuredInput, briefInput) {
|
|
|
79400
79636
|
}
|
|
79401
79637
|
|
|
79402
79638
|
// ../core/src/tasks/scope-bindings.ts
|
|
79403
|
-
import { readFile as
|
|
79404
|
-
import { join as
|
|
79639
|
+
import { readFile as readFile17 } from "node:fs/promises";
|
|
79640
|
+
import { join as join15 } from "node:path";
|
|
79405
79641
|
|
|
79406
79642
|
// ../core/src/tasks/chain-port.ts
|
|
79407
79643
|
var TasksChainError = class extends Error {
|
|
@@ -79976,7 +80212,7 @@ var messageSchema = external_exports.looseObject({
|
|
|
79976
80212
|
})
|
|
79977
80213
|
)
|
|
79978
80214
|
});
|
|
79979
|
-
var
|
|
80215
|
+
var fileSchema2 = external_exports.looseObject({
|
|
79980
80216
|
id: uuidSchema,
|
|
79981
80217
|
purpose: workFilePurposeSchema,
|
|
79982
80218
|
fileName: external_exports.string(),
|
|
@@ -80282,11 +80518,11 @@ var tasksResponseSchemas = {
|
|
|
80282
80518
|
observedAt: isoDateTimeSchema
|
|
80283
80519
|
}),
|
|
80284
80520
|
createUpload: external_exports.looseObject({
|
|
80285
|
-
file:
|
|
80521
|
+
file: fileSchema2.extend({ state: external_exports.literal("pending"), sha256: external_exports.null() }),
|
|
80286
80522
|
uploadUrl: external_exports.url()
|
|
80287
80523
|
}),
|
|
80288
80524
|
finalizeUpload: external_exports.looseObject({
|
|
80289
|
-
file:
|
|
80525
|
+
file: fileSchema2.extend({
|
|
80290
80526
|
state: external_exports.literal("ready"),
|
|
80291
80527
|
sha256: external_exports.string().regex(/^[0-9a-fA-F]{64}$/)
|
|
80292
80528
|
})
|
|
@@ -80894,10 +81130,10 @@ function key(identity) {
|
|
|
80894
81130
|
return `${identity.orderId}:${identity.trancheOrdinal}:${identity.scopeVersion}:${identity.termsHash.toLowerCase()}:${identity.self.toLowerCase()}`;
|
|
80895
81131
|
}
|
|
80896
81132
|
function createScopeBindings(home) {
|
|
80897
|
-
const path =
|
|
81133
|
+
const path = join15(home, "tasks", "scope-bindings.json");
|
|
80898
81134
|
async function read() {
|
|
80899
81135
|
try {
|
|
80900
|
-
return storeSchema.parse(JSON.parse(await
|
|
81136
|
+
return storeSchema.parse(JSON.parse(await readFile17(path, "utf8")));
|
|
80901
81137
|
} catch (error61) {
|
|
80902
81138
|
if (error61 instanceof Error && "code" in error61 && error61.code === "ENOENT")
|
|
80903
81139
|
return { version: 1, bindings: {} };
|
|
@@ -81578,7 +81814,7 @@ function createTasksChain(options) {
|
|
|
81578
81814
|
const { account, client, pending, rpcFor } = options;
|
|
81579
81815
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
81580
81816
|
const sleep = options.sleep ?? ((ms) => new Promise((resolve3) => setTimeout(resolve3, ms)));
|
|
81581
|
-
const
|
|
81817
|
+
const randomBytes18 = options.randomBytes ?? cryptoRandomBytes2;
|
|
81582
81818
|
const confirmations = options.confirmations ?? 2;
|
|
81583
81819
|
if (!Number.isSafeInteger(confirmations) || confirmations < 1)
|
|
81584
81820
|
throw new TasksChainError("Tasks confirmations must be a positive integer.", false, {
|
|
@@ -82187,7 +82423,7 @@ function createTasksChain(options) {
|
|
|
82187
82423
|
await verifyClone(rpcFor(ready.chainId), expected, true);
|
|
82188
82424
|
if (validBefore <= BigInt(Math.floor(now().getTime() / 1e3)))
|
|
82189
82425
|
throw new TasksValidationError("The task funding offer has expired.");
|
|
82190
|
-
const bytes =
|
|
82426
|
+
const bytes = randomBytes18(32);
|
|
82191
82427
|
if (bytes.length !== 32)
|
|
82192
82428
|
throw new TasksValidationError(
|
|
82193
82429
|
"Funding authorization randomness must contain 32 bytes."
|
|
@@ -82465,8 +82701,8 @@ function createTasksRpcFor(config2, options = {}) {
|
|
|
82465
82701
|
}
|
|
82466
82702
|
|
|
82467
82703
|
// ../core/src/tasks/pending-transactions.ts
|
|
82468
|
-
import { readFile as
|
|
82469
|
-
import { join as
|
|
82704
|
+
import { readFile as readFile18 } from "node:fs/promises";
|
|
82705
|
+
import { join as join16 } from "node:path";
|
|
82470
82706
|
var hex3 = external_exports.string().regex(/^0x(?:[0-9a-fA-F]{2})+$/).transform((v) => v);
|
|
82471
82707
|
var hash4 = external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/).transform((v) => v);
|
|
82472
82708
|
var step = external_exports.enum([
|
|
@@ -82548,11 +82784,11 @@ function validCheckpointStep(storedStep, response) {
|
|
|
82548
82784
|
}[response.operation.kind];
|
|
82549
82785
|
}
|
|
82550
82786
|
function createPendingTransactions(home) {
|
|
82551
|
-
const path =
|
|
82787
|
+
const path = join16(home, "tasks", "pending.json");
|
|
82552
82788
|
const lockPath = `${path}.lock`;
|
|
82553
82789
|
const read = async () => {
|
|
82554
82790
|
try {
|
|
82555
|
-
const state = stateSchema.parse(JSON.parse(await
|
|
82791
|
+
const state = stateSchema.parse(JSON.parse(await readFile18(path, "utf8")));
|
|
82556
82792
|
for (const [key2, value] of Object.entries(state.checkpoints)) {
|
|
82557
82793
|
const separator = key2.indexOf(":");
|
|
82558
82794
|
const operationId = key2.slice(0, separator);
|
|
@@ -82615,7 +82851,7 @@ function createPendingTransactions(home) {
|
|
|
82615
82851
|
},
|
|
82616
82852
|
withStepLock(operationId, step2, fn) {
|
|
82617
82853
|
return withFileLock(
|
|
82618
|
-
|
|
82854
|
+
join16(
|
|
82619
82855
|
home,
|
|
82620
82856
|
"tasks",
|
|
82621
82857
|
`step-${encodeURIComponent(operationId)}-${encodeURIComponent(step2)}.lock`
|
|
@@ -82627,13 +82863,13 @@ function createPendingTransactions(home) {
|
|
|
82627
82863
|
external_exports.number().int().positive().parse(chainId);
|
|
82628
82864
|
address3.parse(signer);
|
|
82629
82865
|
return withFileLock(
|
|
82630
|
-
|
|
82866
|
+
join16(home, "tasks", `signer-${chainId}-${signer.toLowerCase()}.lock`),
|
|
82631
82867
|
fn
|
|
82632
82868
|
);
|
|
82633
82869
|
},
|
|
82634
82870
|
withFundingLock(milestoneId, fn) {
|
|
82635
82871
|
milestoneKey(milestoneId);
|
|
82636
|
-
return withFileLock(
|
|
82872
|
+
return withFileLock(join16(home, "tasks", `fund-${milestoneId}.lock`), fn);
|
|
82637
82873
|
},
|
|
82638
82874
|
async nextNonce(chainId, signer) {
|
|
82639
82875
|
external_exports.number().int().positive().parse(chainId);
|
|
@@ -83459,7 +83695,7 @@ function policyAtomic(value) {
|
|
|
83459
83695
|
}
|
|
83460
83696
|
|
|
83461
83697
|
// ../core/src/tasks/operation-support.ts
|
|
83462
|
-
import { readFile as
|
|
83698
|
+
import { readFile as readFile19, stat as stat14 } from "node:fs/promises";
|
|
83463
83699
|
import { basename as basename3, extname } from "node:path";
|
|
83464
83700
|
var TaskOperationError = class extends Error {
|
|
83465
83701
|
constructor(code, message, manifestHash) {
|
|
@@ -83627,7 +83863,7 @@ function parseTaskDuration(text, now) {
|
|
|
83627
83863
|
async function readTaskFile(path) {
|
|
83628
83864
|
let details;
|
|
83629
83865
|
try {
|
|
83630
|
-
details = await
|
|
83866
|
+
details = await stat14(path);
|
|
83631
83867
|
} catch {
|
|
83632
83868
|
throw new TaskInputError(`Task file ${JSON.stringify(path)} could not be read.`);
|
|
83633
83869
|
}
|
|
@@ -83651,7 +83887,7 @@ async function readTaskFile(path) {
|
|
|
83651
83887
|
const contentType = types[extname(path).toLowerCase()];
|
|
83652
83888
|
if (!contentType)
|
|
83653
83889
|
throw new TaskInputError("Task files must be images, PDF, ZIP, text, Markdown, JSON or CSV.");
|
|
83654
|
-
const bytes = await
|
|
83890
|
+
const bytes = await readFile19(path);
|
|
83655
83891
|
if (bytes.length < TASK_LIMITS.uploadBytesMin || bytes.length > TASK_LIMITS.uploadBytesMax)
|
|
83656
83892
|
throw new TaskInputError("Task files must contain between 1 byte and 50 MiB.");
|
|
83657
83893
|
return {
|
|
@@ -84450,7 +84686,7 @@ async function resolveUnmatchedTaskOperation(context, input2) {
|
|
|
84450
84686
|
}
|
|
84451
84687
|
|
|
84452
84688
|
// ../core/src/searches.ts
|
|
84453
|
-
import { mkdir as mkdir16, open as
|
|
84689
|
+
import { mkdir as mkdir16, open as open12, readFile as readFile20 } from "node:fs/promises";
|
|
84454
84690
|
import { dirname as dirname10 } from "node:path";
|
|
84455
84691
|
var searchEventSchema = external_exports.strictObject({
|
|
84456
84692
|
timestamp: external_exports.iso.datetime(),
|
|
@@ -84472,7 +84708,7 @@ function parseSearchEvent(value) {
|
|
|
84472
84708
|
async function appendSearchEvent(event, path = getVapiPaths().searches) {
|
|
84473
84709
|
const parsed = parseSearchEvent(event);
|
|
84474
84710
|
await mkdir16(dirname10(path), { recursive: true, mode: 448 });
|
|
84475
|
-
const handle = await
|
|
84711
|
+
const handle = await open12(path, "a", 384);
|
|
84476
84712
|
try {
|
|
84477
84713
|
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
84478
84714
|
`, "utf8");
|
|
@@ -84484,7 +84720,7 @@ async function appendSearchEvent(event, path = getVapiPaths().searches) {
|
|
|
84484
84720
|
async function readSearchEvents(path = getVapiPaths().searches) {
|
|
84485
84721
|
let raw;
|
|
84486
84722
|
try {
|
|
84487
|
-
raw = await
|
|
84723
|
+
raw = await readFile20(path, "utf8");
|
|
84488
84724
|
} catch (error61) {
|
|
84489
84725
|
if (isMissingFile(error61)) return [];
|
|
84490
84726
|
throw error61;
|
|
@@ -85386,9 +85622,9 @@ function csvCell(value) {
|
|
|
85386
85622
|
}
|
|
85387
85623
|
|
|
85388
85624
|
// ../core/src/swarm-capital.ts
|
|
85389
|
-
import { createHash as createHash5, randomBytes as
|
|
85390
|
-
import { readFile as
|
|
85391
|
-
import { join as
|
|
85625
|
+
import { createHash as createHash5, randomBytes as randomBytes16 } from "node:crypto";
|
|
85626
|
+
import { readFile as readFile21, unlink as unlink12 } from "node:fs/promises";
|
|
85627
|
+
import { join as join17 } from "node:path";
|
|
85392
85628
|
var movementIdSchema3 = external_exports.string().regex(/^mv_[A-Za-z0-9_-]{8,128}$/u);
|
|
85393
85629
|
var amountSchema2 = external_exports.string().regex(/^\d+\.\d{2}$/u);
|
|
85394
85630
|
var requestIdSchema = external_exports.string().min(1).max(512);
|
|
@@ -86269,7 +86505,7 @@ async function readDelegationRecord(home, movementId) {
|
|
|
86269
86505
|
const safeId = runRecordMovementId(movementId);
|
|
86270
86506
|
try {
|
|
86271
86507
|
const record2 = delegationRecordSchema.parse(
|
|
86272
|
-
JSON.parse(await
|
|
86508
|
+
JSON.parse(await readFile21(delegationRecordPath(home, safeId), "utf8"))
|
|
86273
86509
|
);
|
|
86274
86510
|
if (record2.movementId !== safeId) {
|
|
86275
86511
|
throw new SwarmError(
|
|
@@ -86296,7 +86532,7 @@ async function readTreasuryRequestRecord(home, movementId) {
|
|
|
86296
86532
|
const safeId = runRecordMovementId(movementId);
|
|
86297
86533
|
try {
|
|
86298
86534
|
const record2 = treasuryRequestRecordSchema.parse(
|
|
86299
|
-
JSON.parse(await
|
|
86535
|
+
JSON.parse(await readFile21(treasuryRequestRecordPath(home, safeId), "utf8"))
|
|
86300
86536
|
);
|
|
86301
86537
|
if (record2.movementId !== safeId) {
|
|
86302
86538
|
throw new SwarmError(
|
|
@@ -86327,18 +86563,18 @@ function runRecordMovementId(value) {
|
|
|
86327
86563
|
return parsed.data;
|
|
86328
86564
|
}
|
|
86329
86565
|
function treasuryRequestRecordPath(home, movementId) {
|
|
86330
|
-
return
|
|
86566
|
+
return join17(home, "runs", "requests", `${movementId}.json`);
|
|
86331
86567
|
}
|
|
86332
86568
|
function delegationRecordPath(home, movementId) {
|
|
86333
|
-
return
|
|
86569
|
+
return join17(home, "runs", "delegations", `${movementId}.json`);
|
|
86334
86570
|
}
|
|
86335
86571
|
function legacyFundingProgressPath(home, name) {
|
|
86336
|
-
return
|
|
86572
|
+
return join17(home, "swarms", `.${name}.funding`);
|
|
86337
86573
|
}
|
|
86338
86574
|
async function readLegacyFundingProgress(home, name) {
|
|
86339
86575
|
try {
|
|
86340
86576
|
const progress = legacyFundingProgressSchema.parse(
|
|
86341
|
-
JSON.parse(await
|
|
86577
|
+
JSON.parse(await readFile21(legacyFundingProgressPath(home, name), "utf8"))
|
|
86342
86578
|
);
|
|
86343
86579
|
if (progress.name !== name) {
|
|
86344
86580
|
throw new SwarmError("invalid_swarm", `Invalid funding progress for swarm ${name}.`);
|
|
@@ -86567,7 +86803,7 @@ async function optionalMovement(home, id2) {
|
|
|
86567
86803
|
}
|
|
86568
86804
|
}
|
|
86569
86805
|
function nextMovementId(deps) {
|
|
86570
|
-
return movementIdSchema3.parse(deps.randomId?.() ?? `mv_${
|
|
86806
|
+
return movementIdSchema3.parse(deps.randomId?.() ?? `mv_${randomBytes16(12).toString("hex")}`);
|
|
86571
86807
|
}
|
|
86572
86808
|
async function executeRecordedMovement(id2, plan, deps, home, options = {}) {
|
|
86573
86809
|
try {
|
|
@@ -86983,7 +87219,7 @@ async function removeMemberLocked(home, swarm, account) {
|
|
|
86983
87219
|
}
|
|
86984
87220
|
|
|
86985
87221
|
// ../core/src/status.ts
|
|
86986
|
-
import { join as
|
|
87222
|
+
import { join as join18 } from "node:path";
|
|
86987
87223
|
var STATUS_TIMEOUT_MS = 2e3;
|
|
86988
87224
|
async function buildStatus(deps) {
|
|
86989
87225
|
const timers = deps.timers ?? { setTimeout, clearTimeout };
|
|
@@ -87039,7 +87275,7 @@ function formatUsdAmount(value) {
|
|
|
87039
87275
|
}
|
|
87040
87276
|
async function readVaultStatus(deps) {
|
|
87041
87277
|
const store = deps.secrets.description.replace(/^the /u, "");
|
|
87042
|
-
const path =
|
|
87278
|
+
const path = join18(deps.home, "vault.json");
|
|
87043
87279
|
let file2;
|
|
87044
87280
|
try {
|
|
87045
87281
|
file2 = await readVaultFileUnlocked(path);
|
|
@@ -87745,7 +87981,7 @@ function assertKeyMatchesAddress(bundle) {
|
|
|
87745
87981
|
}
|
|
87746
87982
|
|
|
87747
87983
|
// ../core/src/api-key.ts
|
|
87748
|
-
import { chmod as chmod5, mkdir as mkdir17, readFile as
|
|
87984
|
+
import { chmod as chmod5, mkdir as mkdir17, readFile as readFile22, rename as rename11, writeFile as writeFile9 } from "node:fs/promises";
|
|
87749
87985
|
import { dirname as dirname11 } from "node:path";
|
|
87750
87986
|
var API_KEY_PREFIX = "vapi_sk_";
|
|
87751
87987
|
var API_KEY_PATTERN = /^vapi_sk_[A-Za-z0-9_-]{16,128}$/;
|
|
@@ -87841,7 +88077,7 @@ async function readConfigApiKey(path) {
|
|
|
87841
88077
|
async function readConfigRecord(path) {
|
|
87842
88078
|
let raw;
|
|
87843
88079
|
try {
|
|
87844
|
-
raw = await
|
|
88080
|
+
raw = await readFile22(path, "utf8");
|
|
87845
88081
|
} catch (error61) {
|
|
87846
88082
|
if (isMissingFile(error61)) return void 0;
|
|
87847
88083
|
throw error61;
|
|
@@ -90511,8 +90747,8 @@ function exactPriceFact(value) {
|
|
|
90511
90747
|
}
|
|
90512
90748
|
|
|
90513
90749
|
// ../mcp/src/agent/runtime.ts
|
|
90514
|
-
import { mkdir as mkdir18, readFile as
|
|
90515
|
-
import { join as
|
|
90750
|
+
import { mkdir as mkdir18, readFile as readFile23, readdir as readdir7, rm as rm2 } from "node:fs/promises";
|
|
90751
|
+
import { join as join19 } from "node:path";
|
|
90516
90752
|
|
|
90517
90753
|
// ../mcp/src/agent/run.ts
|
|
90518
90754
|
var loopSearchResultSchema = external_exports.array(
|
|
@@ -91813,19 +92049,19 @@ var runRecordSchema = external_exports.strictObject({
|
|
|
91813
92049
|
detail: external_exports.string().optional()
|
|
91814
92050
|
});
|
|
91815
92051
|
function runsDirectory(home) {
|
|
91816
|
-
return
|
|
92052
|
+
return join19(home, "runs");
|
|
91817
92053
|
}
|
|
91818
92054
|
function runRecordPath(home, runId) {
|
|
91819
92055
|
assertRunId(runId);
|
|
91820
|
-
return
|
|
92056
|
+
return join19(runsDirectory(home), `${runId}.json`);
|
|
91821
92057
|
}
|
|
91822
92058
|
function runLogPath(home, runId) {
|
|
91823
92059
|
assertRunId(runId);
|
|
91824
|
-
return
|
|
92060
|
+
return join19(runsDirectory(home), `${runId}.log`);
|
|
91825
92061
|
}
|
|
91826
92062
|
function runResultPath(home, runId) {
|
|
91827
92063
|
assertRunId(runId);
|
|
91828
|
-
return
|
|
92064
|
+
return join19(runsDirectory(home), `${runId}.result.json`);
|
|
91829
92065
|
}
|
|
91830
92066
|
async function writeRunRecord(home, record2) {
|
|
91831
92067
|
const path = runRecordPath(home, record2.runId);
|
|
@@ -91836,7 +92072,7 @@ async function writeRunRecord(home, record2) {
|
|
|
91836
92072
|
async function readRunRecord(home, runId) {
|
|
91837
92073
|
const path = runRecordPath(home, runId);
|
|
91838
92074
|
try {
|
|
91839
|
-
return runRecordSchema.parse(JSON.parse(await
|
|
92075
|
+
return runRecordSchema.parse(JSON.parse(await readFile23(path, "utf8")));
|
|
91840
92076
|
} catch (error61) {
|
|
91841
92077
|
if (isMissingFile3(error61)) return void 0;
|
|
91842
92078
|
throw error61;
|
|
@@ -91856,7 +92092,7 @@ async function listRunRecords(home, filter = {}) {
|
|
|
91856
92092
|
if (match === null) continue;
|
|
91857
92093
|
try {
|
|
91858
92094
|
const record2 = runRecordSchema.parse(
|
|
91859
|
-
JSON.parse(await
|
|
92095
|
+
JSON.parse(await readFile23(join19(runsDirectory(home), file2), "utf8"))
|
|
91860
92096
|
);
|
|
91861
92097
|
if (record2.runId !== match[1]) continue;
|
|
91862
92098
|
if (filter.swarm !== void 0 && record2.member.swarm !== filter.swarm) continue;
|
|
@@ -92133,7 +92369,7 @@ async function stopRun(args) {
|
|
|
92133
92369
|
}
|
|
92134
92370
|
}
|
|
92135
92371
|
function memberRunLockPath(home, account) {
|
|
92136
|
-
return
|
|
92372
|
+
return join19(runsDirectory(home), `.member-${account}.lock`);
|
|
92137
92373
|
}
|
|
92138
92374
|
function summarizeRunRecord(record2) {
|
|
92139
92375
|
return {
|
|
@@ -95737,8 +95973,8 @@ function rgbToAnsi256(red, green, blue) {
|
|
|
95737
95973
|
}
|
|
95738
95974
|
|
|
95739
95975
|
// ../cli/src/accounts.ts
|
|
95740
|
-
import { readFile as
|
|
95741
|
-
import { join as
|
|
95976
|
+
import { readFile as readFile25, stat as stat16 } from "node:fs/promises";
|
|
95977
|
+
import { join as join22 } from "node:path";
|
|
95742
95978
|
|
|
95743
95979
|
// ../cli/src/dashboard.ts
|
|
95744
95980
|
import { resolve as resolve2 } from "node:path";
|
|
@@ -96415,12 +96651,12 @@ function shellQuote2(value) {
|
|
|
96415
96651
|
}
|
|
96416
96652
|
|
|
96417
96653
|
// ../cli/src/status.ts
|
|
96418
|
-
import { stat as
|
|
96654
|
+
import { stat as stat15 } from "node:fs/promises";
|
|
96419
96655
|
import { homedir as homedir2 } from "node:os";
|
|
96420
96656
|
import { sep } from "node:path";
|
|
96421
96657
|
|
|
96422
96658
|
// ../core/src/cloud-backup.ts
|
|
96423
|
-
import { join as
|
|
96659
|
+
import { join as join21 } from "node:path";
|
|
96424
96660
|
|
|
96425
96661
|
// ../core/src/backup.ts
|
|
96426
96662
|
import {
|
|
@@ -96443,11 +96679,11 @@ import {
|
|
|
96443
96679
|
mkdir as mkdir19,
|
|
96444
96680
|
mkdtemp,
|
|
96445
96681
|
open as openFile,
|
|
96446
|
-
readFile as
|
|
96682
|
+
readFile as readFile24,
|
|
96447
96683
|
readdir as readdir8,
|
|
96448
96684
|
rm as rm3
|
|
96449
96685
|
} from "node:fs/promises";
|
|
96450
|
-
import { dirname as dirname12, join as
|
|
96686
|
+
import { dirname as dirname12, join as join20 } from "node:path";
|
|
96451
96687
|
var ERROR_MESSAGES = {
|
|
96452
96688
|
backup_too_large: "Backup envelope exceeds 65,536 bytes.",
|
|
96453
96689
|
backup_open_failed: "Unable to open backup.",
|
|
@@ -96730,8 +96966,8 @@ async function createBackup(options) {
|
|
|
96730
96966
|
assertDevice(options.device);
|
|
96731
96967
|
assertOwnerKey(options.ownerKey);
|
|
96732
96968
|
const createdAt = readCreatedAt(options.now ?? (() => /* @__PURE__ */ new Date()));
|
|
96733
|
-
const
|
|
96734
|
-
const nonce = readRandomBytes(
|
|
96969
|
+
const randomBytes18 = options.randomBytes ?? cryptoRandomBytes3;
|
|
96970
|
+
const nonce = readRandomBytes(randomBytes18, 12);
|
|
96735
96971
|
const salt = encodeBase64Url(options.ownerKey.salt);
|
|
96736
96972
|
const kdf = options.ownerKey.kdf === "hkdf-sha256" ? { name: "hkdf-sha256", salt } : { name: "scrypt", salt, N: SCRYPT_N2, r: SCRYPT_R2, p: SCRYPT_P2 };
|
|
96737
96973
|
const cipher = { name: CIPHER_NAME, nonce: encodeBase64Url(nonce) };
|
|
@@ -96925,7 +97161,7 @@ async function exportBackupSource(options) {
|
|
|
96925
97161
|
var BackupSnapshotChangedError = class extends Error {
|
|
96926
97162
|
};
|
|
96927
97163
|
async function exportBackupSourceAttempt(options, networks) {
|
|
96928
|
-
const path =
|
|
97164
|
+
const path = join20(options.store.home, "vault.json");
|
|
96929
97165
|
const { phrase, file: file2, accounts } = await withVaultLock(path, async () => {
|
|
96930
97166
|
const [phrase2, vault, file3] = await Promise.all([
|
|
96931
97167
|
exportVaultPhrase({ path, key: options.vaultKey }),
|
|
@@ -97061,16 +97297,16 @@ async function restoreBackupPlaintext(options) {
|
|
|
97061
97297
|
} catch {
|
|
97062
97298
|
throw new BackupError("backup_invalid_input");
|
|
97063
97299
|
}
|
|
97064
|
-
const vaultPath2 =
|
|
97065
|
-
const registryPath =
|
|
97300
|
+
const vaultPath2 = join20(options.home, "vault.json");
|
|
97301
|
+
const registryPath = join20(options.home, "wallets.json");
|
|
97066
97302
|
let stagingHome;
|
|
97067
97303
|
let beforePublishError;
|
|
97068
97304
|
let afterPublishError;
|
|
97069
97305
|
try {
|
|
97070
97306
|
await mkdir19(options.home, { recursive: true, mode: 448 });
|
|
97071
|
-
stagingHome = await mkdtemp(
|
|
97072
|
-
const stagedVaultPath =
|
|
97073
|
-
const stagedRegistryPath =
|
|
97307
|
+
stagingHome = await mkdtemp(join20(options.home, ".backup-restore-"));
|
|
97308
|
+
const stagedVaultPath = join20(stagingHome, "vault.json");
|
|
97309
|
+
const stagedRegistryPath = join20(stagingHome, "wallets.json");
|
|
97074
97310
|
await createVault({
|
|
97075
97311
|
path: stagedVaultPath,
|
|
97076
97312
|
key: options.vaultKey,
|
|
@@ -97129,7 +97365,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
97129
97365
|
protected: plaintext.protected,
|
|
97130
97366
|
networks: [...plaintext.registry.networks]
|
|
97131
97367
|
};
|
|
97132
|
-
const markerPath =
|
|
97368
|
+
const markerPath = join20(options.home, RESTORE_MARKER_FILE);
|
|
97133
97369
|
const fingerprint = restoreFingerprint(
|
|
97134
97370
|
plaintext,
|
|
97135
97371
|
stagedV2?.restoreDevice ?? options.device,
|
|
@@ -97340,13 +97576,13 @@ async function stageV2Restore(options) {
|
|
|
97340
97576
|
}
|
|
97341
97577
|
const agents = [];
|
|
97342
97578
|
for (const profile of validAgents) {
|
|
97343
|
-
const stagedPath =
|
|
97579
|
+
const stagedPath = join20(options.stagingHome, "agents", `${profile.name}.json`);
|
|
97344
97580
|
if (await stageRestoreBytes(stagedPath, prettyJson(profile))) {
|
|
97345
97581
|
agents.push({
|
|
97346
97582
|
kind: "agent",
|
|
97347
97583
|
name: profile.name,
|
|
97348
97584
|
stagedPath,
|
|
97349
|
-
targetPath:
|
|
97585
|
+
targetPath: join20(options.home, "agents", `${profile.name}.json`)
|
|
97350
97586
|
});
|
|
97351
97587
|
} else {
|
|
97352
97588
|
skipped2.push({ kind: "agent", name: profile.name, reason: "write_failed" });
|
|
@@ -97366,13 +97602,13 @@ async function stageV2Restore(options) {
|
|
|
97366
97602
|
if (restoreDevice !== void 0) {
|
|
97367
97603
|
for (const value of validSwarms) {
|
|
97368
97604
|
const swarm = swarmFileSchema.parse({ ...value, device: restoreDevice });
|
|
97369
|
-
const stagedPath =
|
|
97605
|
+
const stagedPath = join20(options.stagingHome, "swarms", `${swarm.name}.json`);
|
|
97370
97606
|
if (await stageRestoreBytes(stagedPath, prettyJson(swarm))) {
|
|
97371
97607
|
swarms.push({
|
|
97372
97608
|
kind: "swarm",
|
|
97373
97609
|
name: swarm.name,
|
|
97374
97610
|
stagedPath,
|
|
97375
|
-
targetPath:
|
|
97611
|
+
targetPath: join20(options.home, "swarms", `${swarm.name}.json`)
|
|
97376
97612
|
});
|
|
97377
97613
|
} else {
|
|
97378
97614
|
skipped2.push({ kind: "swarm", name: swarm.name, reason: "write_failed" });
|
|
@@ -97382,13 +97618,13 @@ async function stageV2Restore(options) {
|
|
|
97382
97618
|
const movements = [];
|
|
97383
97619
|
for (const movement of validMovements) {
|
|
97384
97620
|
const restored = reconcileRestoredMovement(movement, assumedReceiptKeys);
|
|
97385
|
-
const stagedPath =
|
|
97621
|
+
const stagedPath = join20(options.stagingHome, "movements", `${restored.id}.json`);
|
|
97386
97622
|
if (await stageRestoreBytes(stagedPath, serializeMovement(restored))) {
|
|
97387
97623
|
movements.push({
|
|
97388
97624
|
kind: "movement",
|
|
97389
97625
|
name: restored.id,
|
|
97390
97626
|
stagedPath,
|
|
97391
|
-
targetPath:
|
|
97627
|
+
targetPath: join20(options.home, "movements", `${restored.id}.json`),
|
|
97392
97628
|
movement: restored
|
|
97393
97629
|
});
|
|
97394
97630
|
} else {
|
|
@@ -97459,8 +97695,8 @@ async function publishRestoreFile(file2, staged) {
|
|
|
97459
97695
|
let identical = false;
|
|
97460
97696
|
try {
|
|
97461
97697
|
const [source, target] = await Promise.all([
|
|
97462
|
-
|
|
97463
|
-
|
|
97698
|
+
readFile24(file2.stagedPath),
|
|
97699
|
+
readFile24(file2.targetPath)
|
|
97464
97700
|
]);
|
|
97465
97701
|
identical = source.equals(target);
|
|
97466
97702
|
} catch {
|
|
@@ -97492,7 +97728,7 @@ async function publishRestoreReceiptsLocked(staged, targetPath) {
|
|
|
97492
97728
|
let existing = "";
|
|
97493
97729
|
let existingLines = /* @__PURE__ */ new Set();
|
|
97494
97730
|
try {
|
|
97495
|
-
await
|
|
97731
|
+
await readFile24(staged.receiptsPath, "utf8");
|
|
97496
97732
|
await mkdir19(dirname12(targetPath), { recursive: true, mode: 448 });
|
|
97497
97733
|
try {
|
|
97498
97734
|
const journal = await readRestoreReceiptJournal(targetPath);
|
|
@@ -97547,7 +97783,7 @@ async function reconcilePublishedMovements(staged, home, requireDurableSafety =
|
|
|
97547
97783
|
const unjournaledKeys = new Set([...signedKeys].filter((key2) => !journaledKeys.has(key2)));
|
|
97548
97784
|
let files;
|
|
97549
97785
|
try {
|
|
97550
|
-
files = await readdir8(
|
|
97786
|
+
files = await readdir8(join20(home, "movements"));
|
|
97551
97787
|
} catch (error61) {
|
|
97552
97788
|
if (isMissingFile4(error61)) return;
|
|
97553
97789
|
if (requireDurableSafety && unjournaledKeys.size > 0) throw error61;
|
|
@@ -97648,9 +97884,9 @@ function assertRelayKey(value) {
|
|
|
97648
97884
|
throw new BackupError("relay_invalid_key");
|
|
97649
97885
|
}
|
|
97650
97886
|
}
|
|
97651
|
-
function readRelayRandomBytes(
|
|
97887
|
+
function readRelayRandomBytes(randomBytes18, length) {
|
|
97652
97888
|
try {
|
|
97653
|
-
const value =
|
|
97889
|
+
const value = randomBytes18(length);
|
|
97654
97890
|
if (!(value instanceof Uint8Array) || value.byteLength !== length) throw new Error();
|
|
97655
97891
|
return Buffer.from(value);
|
|
97656
97892
|
} catch {
|
|
@@ -97768,7 +98004,7 @@ async function createRestoreMarker(vaultPath2, registryPath, fingerprint, vaultK
|
|
|
97768
98004
|
}
|
|
97769
98005
|
async function readRestoreMarker(path, fingerprint, vaultKey) {
|
|
97770
98006
|
try {
|
|
97771
|
-
const marker = restoreMarkerSchema.parse(JSON.parse(await
|
|
98007
|
+
const marker = restoreMarkerSchema.parse(JSON.parse(await readFile24(path, "utf8")));
|
|
97772
98008
|
const expectedMac = restoreMarkerMac(marker, vaultKey);
|
|
97773
98009
|
if (marker.fingerprint !== fingerprint || !timingSafeEqual(Buffer.from(marker.mac, "hex"), Buffer.from(expectedMac, "hex"))) {
|
|
97774
98010
|
throw new Error();
|
|
@@ -97785,7 +98021,7 @@ function restoreMarkerMac(marker, vaultKey) {
|
|
|
97785
98021
|
).digest("hex");
|
|
97786
98022
|
}
|
|
97787
98023
|
async function sha256File(path) {
|
|
97788
|
-
return createHash6("sha256").update(await
|
|
98024
|
+
return createHash6("sha256").update(await readFile24(path)).digest("hex");
|
|
97789
98025
|
}
|
|
97790
98026
|
async function notifyRestorePublish(hook, step2, rememberError) {
|
|
97791
98027
|
try {
|
|
@@ -98087,7 +98323,7 @@ function copyTransferReceipt(receipt) {
|
|
|
98087
98323
|
async function readReceiptJournal(path) {
|
|
98088
98324
|
let raw;
|
|
98089
98325
|
try {
|
|
98090
|
-
raw = await
|
|
98326
|
+
raw = await readFile24(path, "utf8");
|
|
98091
98327
|
} catch (error61) {
|
|
98092
98328
|
if (isMissingFile4(error61)) return [];
|
|
98093
98329
|
throw error61;
|
|
@@ -98097,7 +98333,7 @@ async function readReceiptJournal(path) {
|
|
|
98097
98333
|
async function readRestoreReceiptJournal(path) {
|
|
98098
98334
|
let raw;
|
|
98099
98335
|
try {
|
|
98100
|
-
raw = await
|
|
98336
|
+
raw = await readFile24(path, "utf8");
|
|
98101
98337
|
} catch (error61) {
|
|
98102
98338
|
if (isMissingFile4(error61)) return { raw: "", lines: /* @__PURE__ */ new Set(), signedKeys: /* @__PURE__ */ new Set() };
|
|
98103
98339
|
throw error61;
|
|
@@ -98216,8 +98452,8 @@ function assertOwnerKey(ownerKey) {
|
|
|
98216
98452
|
assertBytes(ownerKey.key, 32);
|
|
98217
98453
|
assertBytes(ownerKey.salt, 32);
|
|
98218
98454
|
}
|
|
98219
|
-
function readRandomBytes(
|
|
98220
|
-
const value =
|
|
98455
|
+
function readRandomBytes(randomBytes18, length) {
|
|
98456
|
+
const value = randomBytes18(length);
|
|
98221
98457
|
if (!(value instanceof Uint8Array) || value.byteLength !== length) {
|
|
98222
98458
|
throw new BackupError("backup_invalid_input");
|
|
98223
98459
|
}
|
|
@@ -98456,7 +98692,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
98456
98692
|
try {
|
|
98457
98693
|
let vaultFile;
|
|
98458
98694
|
try {
|
|
98459
|
-
vaultFile = await readVaultFileUnlocked(
|
|
98695
|
+
vaultFile = await readVaultFileUnlocked(join21(options.store.home, "vault.json"));
|
|
98460
98696
|
} catch (error61) {
|
|
98461
98697
|
if (error61 instanceof VaultError && error61.code === "not_found") {
|
|
98462
98698
|
return { status: "skipped", reason: "no_vault" };
|
|
@@ -98465,7 +98701,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
98465
98701
|
}
|
|
98466
98702
|
try {
|
|
98467
98703
|
vaultKey = vaultFile.protected ? await unlockProtectedVault({
|
|
98468
|
-
path:
|
|
98704
|
+
path: join21(options.store.home, "vault.json"),
|
|
98469
98705
|
secrets: options.secrets,
|
|
98470
98706
|
env: options.env,
|
|
98471
98707
|
...options.now === void 0 ? {} : { now: options.now }
|
|
@@ -99138,7 +99374,7 @@ async function readProcessStdin() {
|
|
|
99138
99374
|
}
|
|
99139
99375
|
|
|
99140
99376
|
// ../cli/src/version.ts
|
|
99141
|
-
var CLI_VERSION = "0.
|
|
99377
|
+
var CLI_VERSION = "0.13.0";
|
|
99142
99378
|
|
|
99143
99379
|
// ../cli/src/status.ts
|
|
99144
99380
|
async function statusCommand(argv, json2, io, dependencies) {
|
|
@@ -99305,7 +99541,7 @@ function withDeadlineSignal3(fetchImpl, deadline) {
|
|
|
99305
99541
|
}
|
|
99306
99542
|
async function statusConfig(path) {
|
|
99307
99543
|
try {
|
|
99308
|
-
await
|
|
99544
|
+
await stat15(path);
|
|
99309
99545
|
} catch (error61) {
|
|
99310
99546
|
if (isMissingFile(error61)) return getDefaultConfig(process.env);
|
|
99311
99547
|
throw error61;
|
|
@@ -99503,7 +99739,7 @@ async function siblingsFetchImpl(dependencies) {
|
|
|
99503
99739
|
const configPath = getVapiPaths().config;
|
|
99504
99740
|
let config2;
|
|
99505
99741
|
try {
|
|
99506
|
-
await
|
|
99742
|
+
await stat16(configPath);
|
|
99507
99743
|
config2 = await loadConfig(configPath, process.env);
|
|
99508
99744
|
} catch (error61) {
|
|
99509
99745
|
if (!isMissingFile(error61)) throw error61;
|
|
@@ -99592,7 +99828,7 @@ ${IMPORT_USAGE}`);
|
|
|
99592
99828
|
const passphrase = await secretPrompt(dependencies)(`Passphrase for ${keystorePath}: `);
|
|
99593
99829
|
privateKey = (await exportKeystoreKeys(passphrase, keystorePath)).evm.privateKey;
|
|
99594
99830
|
} else if (keyPath !== void 0) {
|
|
99595
|
-
privateKey = (await
|
|
99831
|
+
privateKey = (await readFile25(keyPath, "utf8")).trim();
|
|
99596
99832
|
} else {
|
|
99597
99833
|
privateKey = await secretPrompt(dependencies)("Private key: ");
|
|
99598
99834
|
}
|
|
@@ -99640,10 +99876,10 @@ async function accountsRenameCommand(argv, json2, io, dependencies) {
|
|
|
99640
99876
|
{
|
|
99641
99877
|
previous: from16,
|
|
99642
99878
|
...address4 === void 0 ? {} : { address: address4 },
|
|
99643
|
-
vault:
|
|
99879
|
+
vault: join22(store.home, "vault.json"),
|
|
99644
99880
|
message: `Wallet ${from16} is now ${renamed.name}.`
|
|
99645
99881
|
},
|
|
99646
|
-
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${
|
|
99882
|
+
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${join22(store.home, "vault.json")}`].join(
|
|
99647
99883
|
"\n"
|
|
99648
99884
|
)
|
|
99649
99885
|
);
|
|
@@ -99752,13 +99988,13 @@ async function accountsRestoreCommand(argv, json2, io, dependencies) {
|
|
|
99752
99988
|
{ name: restored.name, ...address4 === void 0 ? {} : { address: address4 } },
|
|
99753
99989
|
{
|
|
99754
99990
|
...address4 === void 0 ? {} : { address: address4 },
|
|
99755
|
-
vault:
|
|
99991
|
+
vault: join22(store.home, "vault.json"),
|
|
99756
99992
|
spendCaps: restored.entry.spendCaps,
|
|
99757
99993
|
message: `Wallet ${restored.name} restored to the device vault.`
|
|
99758
99994
|
},
|
|
99759
99995
|
[
|
|
99760
99996
|
`Wallet ${restored.name} restored to the device vault.`,
|
|
99761
|
-
`Vault: ${
|
|
99997
|
+
`Vault: ${join22(store.home, "vault.json")}`
|
|
99762
99998
|
].join("\n")
|
|
99763
99999
|
);
|
|
99764
100000
|
}
|
|
@@ -100088,7 +100324,7 @@ function formatNetworkAccounts(accounts) {
|
|
|
100088
100324
|
}
|
|
100089
100325
|
|
|
100090
100326
|
// ../cli/src/cloud-backup.ts
|
|
100091
|
-
import { join as
|
|
100327
|
+
import { join as join23 } from "node:path";
|
|
100092
100328
|
var CLOUD_BACKUP_USAGE = "Usage: vapi backup --cloud [off] [--json]";
|
|
100093
100329
|
var OWNER_RESTORE_USAGE = "Usage: vapi restore --from-owner [--owner <0x\u2026>] [--json]";
|
|
100094
100330
|
var OWNER_PATTERN2 = /^0x[0-9a-fA-F]{40}$/u;
|
|
@@ -100111,7 +100347,7 @@ async function cloudBackupCommand(argv, json2, io, dependencies) {
|
|
|
100111
100347
|
}
|
|
100112
100348
|
async function enrollCloudBackup(json2, io, dependencies) {
|
|
100113
100349
|
const paths = getVapiPaths();
|
|
100114
|
-
if (!await
|
|
100350
|
+
if (!await fileExists3(join23(paths.directory, "vault.json"))) {
|
|
100115
100351
|
throw new Error("No vault on this device. Run vapi setup first.");
|
|
100116
100352
|
}
|
|
100117
100353
|
const context = await cloudContext(io, dependencies);
|
|
@@ -100223,7 +100459,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
100223
100459
|
}
|
|
100224
100460
|
const expectedOwner = ownerValue?.toLowerCase();
|
|
100225
100461
|
const paths = getVapiPaths();
|
|
100226
|
-
if (await
|
|
100462
|
+
if (await fileExists3(join23(paths.directory, "vault.json")) && !await fileExists3(join23(paths.directory, ".backup-restore.json"))) {
|
|
100227
100463
|
throw new Error(
|
|
100228
100464
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
100229
100465
|
);
|
|
@@ -100279,7 +100515,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
100279
100515
|
env: getEnvironment(dependencies),
|
|
100280
100516
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
100281
100517
|
});
|
|
100282
|
-
if (!await
|
|
100518
|
+
if (!await fileExists3(paths.config)) {
|
|
100283
100519
|
const networks = restored.networks.length === 0 ? ["base"] : restored.networks;
|
|
100284
100520
|
await writeDefaultConfig(paths.config, getEnvironment(dependencies), { networks });
|
|
100285
100521
|
}
|
|
@@ -101320,20 +101556,20 @@ function shortExcerpt(value) {
|
|
|
101320
101556
|
}
|
|
101321
101557
|
|
|
101322
101558
|
// ../cli/src/agent.ts
|
|
101323
|
-
import { readFile as
|
|
101324
|
-
import { join as
|
|
101559
|
+
import { readFile as readFile27, stat as stat17 } from "node:fs/promises";
|
|
101560
|
+
import { join as join26 } from "node:path";
|
|
101325
101561
|
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
101326
101562
|
|
|
101327
101563
|
// ../cli/src/headless.ts
|
|
101328
101564
|
import { chmod as chmod7, mkdtemp as mkdtemp2, rm as rm4, writeFile as writeFile10 } from "node:fs/promises";
|
|
101329
101565
|
import { rmSync } from "node:fs";
|
|
101330
101566
|
import { tmpdir as osTmpdir } from "node:os";
|
|
101331
|
-
import { join as
|
|
101567
|
+
import { join as join24 } from "node:path";
|
|
101332
101568
|
var BUNDLE_VARIABLE_PATTERN = /^[A-Z_][A-Z0-9_]*$/u;
|
|
101333
101569
|
var REMOTE_BLOCKED_GRANTS2 = /* @__PURE__ */ new Set(["delegate", "allocate"]);
|
|
101334
101570
|
var agentProfileOptions = { schema: registeredAgentProfileSchema };
|
|
101335
101571
|
async function createHeadlessHome(bundle, options = {}) {
|
|
101336
|
-
const home = await mkdtemp2(
|
|
101572
|
+
const home = await mkdtemp2(join24(options.tmpdir ?? osTmpdir(), "vapi-headless-"));
|
|
101337
101573
|
const cleanup = async () => {
|
|
101338
101574
|
await rm4(home, { recursive: true, force: true });
|
|
101339
101575
|
};
|
|
@@ -101533,18 +101769,18 @@ import { readFile as nodeReadFile } from "node:fs/promises";
|
|
|
101533
101769
|
|
|
101534
101770
|
// ../cli/src/runtime-railway.ts
|
|
101535
101771
|
import { spawn as spawn2 } from "node:child_process";
|
|
101536
|
-
import { randomBytes as
|
|
101772
|
+
import { randomBytes as randomBytes17 } from "node:crypto";
|
|
101537
101773
|
import { closeSync, fsyncSync, mkdirSync, openSync, renameSync, rmSync as rmSync2, writeSync } from "node:fs";
|
|
101538
101774
|
import {
|
|
101539
101775
|
mkdtemp as nodeMkdtemp,
|
|
101540
101776
|
readdir as readdir9,
|
|
101541
|
-
readFile as
|
|
101777
|
+
readFile as readFile26,
|
|
101542
101778
|
rm as nodeRm,
|
|
101543
101779
|
stat as nodeStat,
|
|
101544
101780
|
writeFile as nodeWriteFile
|
|
101545
101781
|
} from "node:fs/promises";
|
|
101546
101782
|
import { tmpdir as osTmpdir2 } from "node:os";
|
|
101547
|
-
import { basename as basename4, dirname as dirname13, join as
|
|
101783
|
+
import { basename as basename4, dirname as dirname13, join as join25 } from "node:path";
|
|
101548
101784
|
var RAILWAY_CLI = {
|
|
101549
101785
|
binary: "railway",
|
|
101550
101786
|
create: (options) => [
|
|
@@ -101716,7 +101952,7 @@ async function assertRemoteSafeMember(args) {
|
|
|
101716
101952
|
}
|
|
101717
101953
|
function railwaySidecarPath(home, runId) {
|
|
101718
101954
|
if (!isRunId(runId)) throw new RuntimeError("invalid_run_id", `Invalid run id: ${runId}.`);
|
|
101719
|
-
return
|
|
101955
|
+
return join25(runsDirectory(home), `${runId}.railway.json`);
|
|
101720
101956
|
}
|
|
101721
101957
|
function createRailwayRuntime(options) {
|
|
101722
101958
|
const { home } = options;
|
|
@@ -102041,10 +102277,10 @@ function createRailwayRuntime(options) {
|
|
|
102041
102277
|
let createError;
|
|
102042
102278
|
let cleanupError;
|
|
102043
102279
|
try {
|
|
102044
|
-
directory = await fs.mkdtemp(
|
|
102280
|
+
directory = await fs.mkdtemp(join25(options.tmpdir ?? osTmpdir2(), "vapi-railway-"));
|
|
102045
102281
|
assertNotInterrupted();
|
|
102046
102282
|
await assertMode(fs, directory, 448, "env-file directory");
|
|
102047
|
-
envFile =
|
|
102283
|
+
envFile = join25(directory, "member.env");
|
|
102048
102284
|
await fs.writeFile(envFile, `${RAILWAY_CLI.bundleVariable}=${bundle}
|
|
102049
102285
|
`, {
|
|
102050
102286
|
encoding: "utf8",
|
|
@@ -102499,9 +102735,9 @@ async function writeSidecar(home, runId, sidecar) {
|
|
|
102499
102735
|
function writeSidecarSync(path, sidecar) {
|
|
102500
102736
|
const directory = dirname13(path);
|
|
102501
102737
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
102502
|
-
const temporary =
|
|
102738
|
+
const temporary = join25(
|
|
102503
102739
|
directory,
|
|
102504
|
-
`.${basename4(path)}.${process.pid}.${
|
|
102740
|
+
`.${basename4(path)}.${process.pid}.${randomBytes17(6).toString("hex")}.tmp`
|
|
102505
102741
|
);
|
|
102506
102742
|
try {
|
|
102507
102743
|
const descriptor2 = openSync(temporary, "wx", 384);
|
|
@@ -102539,7 +102775,7 @@ var LEGACY_SIDECAR_KEYS = ["checkpoint", "keepSandbox", "sandboxId", "v"];
|
|
|
102539
102775
|
async function readSidecar(home, runId) {
|
|
102540
102776
|
let parsed;
|
|
102541
102777
|
try {
|
|
102542
|
-
parsed = JSON.parse(await
|
|
102778
|
+
parsed = JSON.parse(await readFile26(railwaySidecarPath(home, runId), "utf8"));
|
|
102543
102779
|
} catch {
|
|
102544
102780
|
return void 0;
|
|
102545
102781
|
}
|
|
@@ -102597,7 +102833,7 @@ async function assertMode(fs, path, mode, what) {
|
|
|
102597
102833
|
}
|
|
102598
102834
|
}
|
|
102599
102835
|
async function deviceVaultKey(home, secrets, now) {
|
|
102600
|
-
const path =
|
|
102836
|
+
const path = join25(home, "vault.json");
|
|
102601
102837
|
const metadata = await readVaultFileUnlocked(path);
|
|
102602
102838
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
102603
102839
|
path,
|
|
@@ -102652,7 +102888,7 @@ function createLocalRuntime(options) {
|
|
|
102652
102888
|
const processCommand = options.processCommand ?? defaultProcessCommand;
|
|
102653
102889
|
const ownsProcess = (handle, pid) => processCommand(pid)?.includes(runResultPath(home, handle.runId)) === true;
|
|
102654
102890
|
const closeFd = options.closeFd ?? closeSync2;
|
|
102655
|
-
const
|
|
102891
|
+
const readFile33 = options.readFile ?? nodeReadFile;
|
|
102656
102892
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
102657
102893
|
const openLog = options.openLog ?? ((path) => {
|
|
102658
102894
|
mkdirSync2(runsDirectory(home), { recursive: true, mode: 448 });
|
|
@@ -102707,7 +102943,7 @@ function createLocalRuntime(options) {
|
|
|
102707
102943
|
return handle;
|
|
102708
102944
|
},
|
|
102709
102945
|
async status(handle) {
|
|
102710
|
-
const result = await readResultFile(
|
|
102946
|
+
const result = await readResultFile(readFile33, runResultPath(home, handle.runId));
|
|
102711
102947
|
if (result !== void 0) return result;
|
|
102712
102948
|
const pid = localPid(handle);
|
|
102713
102949
|
if (pid === void 0 || handle.kind !== "local") {
|
|
@@ -102810,10 +103046,10 @@ function childArguments(member, run) {
|
|
|
102810
103046
|
...run.drawUsd ? ["--draw", run.drawUsd] : []
|
|
102811
103047
|
];
|
|
102812
103048
|
}
|
|
102813
|
-
async function readResultFile(
|
|
103049
|
+
async function readResultFile(readFile33, path) {
|
|
102814
103050
|
let text;
|
|
102815
103051
|
try {
|
|
102816
|
-
text = await
|
|
103052
|
+
text = await readFile33(path, "utf8");
|
|
102817
103053
|
} catch (error61) {
|
|
102818
103054
|
if (hasCode3(error61, "ENOENT")) return void 0;
|
|
102819
103055
|
return { state: "failed", detail: "unreadable result file" };
|
|
@@ -102938,7 +103174,7 @@ async function createCommand(argv, json2, io, dependencies) {
|
|
|
102938
103174
|
if (await profileFileExists(paths.agentsDir, name)) {
|
|
102939
103175
|
throw new Error(`Agent ${name} already exists.`);
|
|
102940
103176
|
}
|
|
102941
|
-
const instructions = await
|
|
103177
|
+
const instructions = await readFile27(instructionsPath, "utf8");
|
|
102942
103178
|
if (instructions.length > 2e4) {
|
|
102943
103179
|
throw new UsageError("--instructions must contain at most 20000 characters.");
|
|
102944
103180
|
}
|
|
@@ -103524,7 +103760,7 @@ function explicitWallet(name) {
|
|
|
103524
103760
|
}
|
|
103525
103761
|
async function profileFileExists(directory, name) {
|
|
103526
103762
|
try {
|
|
103527
|
-
await
|
|
103763
|
+
await stat17(join26(directory, `${name}.json`));
|
|
103528
103764
|
return true;
|
|
103529
103765
|
} catch (error61) {
|
|
103530
103766
|
if (isMissingFile(error61)) return false;
|
|
@@ -103585,7 +103821,7 @@ function usd(value, minimumDecimals = 0) {
|
|
|
103585
103821
|
|
|
103586
103822
|
// ../cli/src/mcp-install.ts
|
|
103587
103823
|
import { spawn as spawn3 } from "node:child_process";
|
|
103588
|
-
import { mkdir as mkdir20, readFile as
|
|
103824
|
+
import { mkdir as mkdir20, readFile as readFile28, writeFile as writeFile11 } from "node:fs/promises";
|
|
103589
103825
|
import { homedir as systemHomedir } from "node:os";
|
|
103590
103826
|
import { dirname as dirname14, posix, win32 as win322 } from "node:path";
|
|
103591
103827
|
|
|
@@ -103965,7 +104201,7 @@ function isRecord12(value) {
|
|
|
103965
104201
|
}
|
|
103966
104202
|
async function readExistingFile(path) {
|
|
103967
104203
|
try {
|
|
103968
|
-
return await
|
|
104204
|
+
return await readFile28(path, "utf8");
|
|
103969
104205
|
} catch (error61) {
|
|
103970
104206
|
if (isMissingFile(error61)) return void 0;
|
|
103971
104207
|
throw error61;
|
|
@@ -103973,7 +104209,7 @@ async function readExistingFile(path) {
|
|
|
103973
104209
|
}
|
|
103974
104210
|
async function pathExists5(path) {
|
|
103975
104211
|
try {
|
|
103976
|
-
await
|
|
104212
|
+
await readFile28(path);
|
|
103977
104213
|
return true;
|
|
103978
104214
|
} catch (error61) {
|
|
103979
104215
|
if (isMissingFile(error61)) return false;
|
|
@@ -103983,15 +104219,15 @@ async function pathExists5(path) {
|
|
|
103983
104219
|
|
|
103984
104220
|
// ../cli/src/code.ts
|
|
103985
104221
|
import { constants as constants2 } from "node:fs";
|
|
103986
|
-
import { access, mkdir as mkdir21, readFile as
|
|
104222
|
+
import { access, mkdir as mkdir21, readFile as readFile29, realpath, unlink as unlink13, writeFile as writeFile12 } from "node:fs/promises";
|
|
103987
104223
|
import { homedir as homedir3 } from "node:os";
|
|
103988
|
-
import { basename as basename5, dirname as dirname15, join as
|
|
104224
|
+
import { basename as basename5, dirname as dirname15, join as join27, posix as posix2, win32 as win323 } from "node:path";
|
|
103989
104225
|
var VAPI_CODEX_PROVIDER = "vapi";
|
|
103990
104226
|
var VAPI_CODEX_PROFILE = "vapi";
|
|
103991
104227
|
var VAPI_CODEX_DEFAULT_MODEL = "venice/openai-gpt-61-sol";
|
|
103992
104228
|
var VAPI_ROUTER_KEY_ENV = "VAPI_ROUTER_KEY";
|
|
103993
104229
|
function codexConfigPath(env, home) {
|
|
103994
|
-
return
|
|
104230
|
+
return join27(env.CODEX_HOME || join27(home, ".codex"), "config.toml");
|
|
103995
104231
|
}
|
|
103996
104232
|
function hasVapiCodexProfile(contents) {
|
|
103997
104233
|
const roots = new Set(
|
|
@@ -104085,7 +104321,7 @@ function aliasContents(original, tools) {
|
|
|
104085
104321
|
}
|
|
104086
104322
|
async function readOptional(path) {
|
|
104087
104323
|
try {
|
|
104088
|
-
return await
|
|
104324
|
+
return await readFile29(path, "utf8");
|
|
104089
104325
|
} catch (error61) {
|
|
104090
104326
|
if (isMissingFile(error61)) return void 0;
|
|
104091
104327
|
throw error61;
|
|
@@ -104107,7 +104343,7 @@ async function codeCommand(argv, json2, io, dependencies) {
|
|
|
104107
104343
|
const env = getEnvironment(dependencies);
|
|
104108
104344
|
const home = dependencies.code?.homedir ?? homedir3();
|
|
104109
104345
|
const config2 = codexConfigPath(env, home);
|
|
104110
|
-
const rcPaths = [
|
|
104346
|
+
const rcPaths = [join27(home, ".zshrc"), join27(home, ".bashrc")];
|
|
104111
104347
|
if (command === "uninstall") {
|
|
104112
104348
|
const removed = [];
|
|
104113
104349
|
const previous = await readOptional(config2);
|
|
@@ -104231,7 +104467,7 @@ async function codeCommand(argv, json2, io, dependencies) {
|
|
|
104231
104467
|
|
|
104232
104468
|
// ../cli/src/code-launch.ts
|
|
104233
104469
|
import { spawn as spawn4 } from "node:child_process";
|
|
104234
|
-
import { readFile as
|
|
104470
|
+
import { readFile as readFile30 } from "node:fs/promises";
|
|
104235
104471
|
import { constants as constants3, homedir as homedir4 } from "node:os";
|
|
104236
104472
|
var CLAUDE_MODELS = {
|
|
104237
104473
|
sonnet: "venice/claude-sonnet-5-5",
|
|
@@ -104445,7 +104681,7 @@ function claudeModel(model) {
|
|
|
104445
104681
|
async function codexArgs(env, baseURL, model, dependencies) {
|
|
104446
104682
|
let contents = "";
|
|
104447
104683
|
try {
|
|
104448
|
-
contents = await
|
|
104684
|
+
contents = await readFile30(
|
|
104449
104685
|
codexConfigPath(env, dependencies.code?.homedir ?? homedir4()),
|
|
104450
104686
|
"utf8"
|
|
104451
104687
|
);
|
|
@@ -104620,7 +104856,7 @@ async function sendConfig(dependencies) {
|
|
|
104620
104856
|
|
|
104621
104857
|
// ../cli/src/setup.ts
|
|
104622
104858
|
import { rm as rm5 } from "node:fs/promises";
|
|
104623
|
-
import { join as
|
|
104859
|
+
import { join as join28 } from "node:path";
|
|
104624
104860
|
var SETUP_ARGUMENT_ERROR = `vapi setup accepts only --no-cloud-backup and --accounts <n> (1-${MAX_RESTORE_ACCOUNTS}); a recovery phrase is typed at the prompt, never passed on the command line.`;
|
|
104625
104861
|
var VAULT_CHOICE = "Create a new vault, or restore one from a recovery phrase? [new/restore] ";
|
|
104626
104862
|
async function setupCommand(argv, json2, io, dependencies) {
|
|
@@ -104639,18 +104875,24 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
104639
104875
|
const steps = [];
|
|
104640
104876
|
const humanIo = json2 ? stderrIo(io) : io;
|
|
104641
104877
|
const accountCount = parseAccountCount(parsed.one("--accounts"));
|
|
104642
|
-
if (!await
|
|
104878
|
+
if (!await fileExists3(paths.config)) {
|
|
104643
104879
|
await writeDefaultConfig(paths.config, process.env, { networks: ["base"] });
|
|
104644
104880
|
steps.push("config");
|
|
104645
104881
|
}
|
|
104646
104882
|
const config2 = await readConfig(paths.config, humanIo);
|
|
104883
|
+
if (!await fileExists3(join28(paths.directory, "vault.json"))) {
|
|
104884
|
+
const os = dependencies.secretBackendProbe ?? (dependencies.secretStore === void 0 ? osSecretStore() : void 0);
|
|
104885
|
+
if (os !== void 0) {
|
|
104886
|
+
await chooseSecretBackend({ home: paths.directory, os, env: getEnvironment(dependencies) });
|
|
104887
|
+
}
|
|
104888
|
+
}
|
|
104647
104889
|
let store = await openWalletStore(dependencies);
|
|
104648
104890
|
let vault = "existing";
|
|
104649
104891
|
let changedVault = false;
|
|
104650
104892
|
let changedAccount = false;
|
|
104651
104893
|
let changedLink = false;
|
|
104652
104894
|
let scannedAddresses;
|
|
104653
|
-
if (!await
|
|
104895
|
+
if (!await fileExists3(join28(paths.directory, "vault.json"))) {
|
|
104654
104896
|
const choice = await vaultChoice(dependencies);
|
|
104655
104897
|
if (choice === "restore") {
|
|
104656
104898
|
if (!isInteractive(dependencies)) {
|
|
@@ -104738,7 +104980,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
104738
104980
|
let scannedAddresses = 0;
|
|
104739
104981
|
try {
|
|
104740
104982
|
const restored = await restoreVault({
|
|
104741
|
-
path:
|
|
104983
|
+
path: join28(paths.directory, "vault.json"),
|
|
104742
104984
|
key: key2,
|
|
104743
104985
|
phrase: validatedPhrase,
|
|
104744
104986
|
probe: async (address4) => await readBalance3(address4) > 0n,
|
|
@@ -104749,7 +104991,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
104749
104991
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
104750
104992
|
});
|
|
104751
104993
|
names = restored.accounts().map((account) => account.name);
|
|
104752
|
-
await rm5(
|
|
104994
|
+
await rm5(join28(paths.directory, "wallets.json"), { force: true });
|
|
104753
104995
|
} finally {
|
|
104754
104996
|
key2.fill(0);
|
|
104755
104997
|
}
|
|
@@ -104867,7 +105109,7 @@ async function withRouterError2(operation) {
|
|
|
104867
105109
|
|
|
104868
105110
|
// ../cli/src/task.ts
|
|
104869
105111
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
104870
|
-
import { readFile as
|
|
105112
|
+
import { readFile as readFile31 } from "node:fs/promises";
|
|
104871
105113
|
var TASK_HELP = `Usage:
|
|
104872
105114
|
vapi task search [--open] [--min <usd>] [--tab trending|new|closing|paid] [--limit <n>] [--json]
|
|
104873
105115
|
vapi task show <id> [--account <name>] [--json]
|
|
@@ -105203,7 +105445,7 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
105203
105445
|
if (maxAwards !== void 0 && maxAwards > TASK_LIMITS.maxAwardsMax)
|
|
105204
105446
|
throw new UsageError("--max-awards must be between 1 and 50.");
|
|
105205
105447
|
if (parsed.one("--webhook") !== void 0) httpsUrl2(parsed.one("--webhook"), "--webhook");
|
|
105206
|
-
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await
|
|
105448
|
+
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await readFile31(briefPath, "utf8");
|
|
105207
105449
|
const input2 = {
|
|
105208
105450
|
title: title.trim(),
|
|
105209
105451
|
description: brief.trim(),
|
|
@@ -106881,7 +107123,7 @@ async function referencedSleep(milliseconds, signal) {
|
|
|
106881
107123
|
}
|
|
106882
107124
|
|
|
106883
107125
|
// ../cli/src/vault.ts
|
|
106884
|
-
import { join as
|
|
107126
|
+
import { join as join29 } from "node:path";
|
|
106885
107127
|
var VAULT_USAGE = "Usage: vapi vault protect|unprotect|lock|unlock|status [--json]";
|
|
106886
107128
|
var RESTORE_USAGE = "Usage: vapi restore [--accounts <n> | --from-owner [--owner <0x\u2026>]] [--json]";
|
|
106887
107129
|
var LEGACY_PASSWORD_NOTICE = "VAPI_KEYSTORE_PASSWORD is deprecated for vault passwords; use VAPI_VAULT_PASSWORD instead.";
|
|
@@ -106925,13 +107167,13 @@ async function restoreCommand(argv, json2, io, dependencies) {
|
|
|
106925
107167
|
}
|
|
106926
107168
|
const accountCount = parseRestoreAccountCount(parsed.one("--accounts"));
|
|
106927
107169
|
const paths = getVapiPaths();
|
|
106928
|
-
const path =
|
|
106929
|
-
if (await
|
|
107170
|
+
const path = join29(paths.directory, "vault.json");
|
|
107171
|
+
if (await fileExists3(path)) {
|
|
106930
107172
|
throw new Error(
|
|
106931
107173
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
106932
107174
|
);
|
|
106933
107175
|
}
|
|
106934
|
-
if (!await
|
|
107176
|
+
if (!await fileExists3(paths.config)) {
|
|
106935
107177
|
await writeDefaultConfig(paths.config, process.env, { networks: ["base"] });
|
|
106936
107178
|
}
|
|
106937
107179
|
const config2 = await readConfig(paths.config, json2 ? quietIo(io) : io);
|
|
@@ -107082,7 +107324,7 @@ function requireNoArguments(argv) {
|
|
|
107082
107324
|
parseArguments(argv, { valueOptions: /* @__PURE__ */ new Set(), maximumPositionals: 0 });
|
|
107083
107325
|
}
|
|
107084
107326
|
function vaultPath() {
|
|
107085
|
-
return
|
|
107327
|
+
return join29(getVapiPaths().directory, "vault.json");
|
|
107086
107328
|
}
|
|
107087
107329
|
function quietIo(io) {
|
|
107088
107330
|
return { stdout: () => void 0, stderr: io.stderr };
|
|
@@ -107533,7 +107775,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
107533
107775
|
break;
|
|
107534
107776
|
case "unlock":
|
|
107535
107777
|
io.stderr("vapi unlock is now vapi vault unlock; the old name works for one release.");
|
|
107536
|
-
if (await
|
|
107778
|
+
if (await fileExists3(join30(getVapiPaths().directory, "vault.json"))) {
|
|
107537
107779
|
parseArguments(args.slice(1), {
|
|
107538
107780
|
valueOptions: /* @__PURE__ */ new Set([WALLET_OPTION5]),
|
|
107539
107781
|
maximumPositionals: 0
|
|
@@ -107721,7 +107963,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
107721
107963
|
await recordAudit(dependencies, "wallet.create", { wallet: created.name });
|
|
107722
107964
|
const account = created.account;
|
|
107723
107965
|
if (!json2) await showRecoveryPhrase(created.recoveryPhrase, io, dependencies);
|
|
107724
|
-
if (!await
|
|
107966
|
+
if (!await fileExists3(paths.config)) {
|
|
107725
107967
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
107726
107968
|
} else {
|
|
107727
107969
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -107739,7 +107981,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
107739
107981
|
address: account.address,
|
|
107740
107982
|
accounts,
|
|
107741
107983
|
config: paths.config,
|
|
107742
|
-
vault:
|
|
107984
|
+
vault: join30(paths.directory, "vault.json"),
|
|
107743
107985
|
...configRewrites.length > 0 ? { configRewrites } : {},
|
|
107744
107986
|
custody: "self",
|
|
107745
107987
|
warning: CUSTODY_NOTICE,
|
|
@@ -107869,7 +108111,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
107869
108111
|
await recordAudit(dependencies, "wallet.create", { wallet: created.name });
|
|
107870
108112
|
const account = created.account;
|
|
107871
108113
|
if (!json2) await showRecoveryPhrase(created.recoveryPhrase, io, dependencies);
|
|
107872
|
-
if (!await
|
|
108114
|
+
if (!await fileExists3(paths.config)) {
|
|
107873
108115
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
107874
108116
|
} else {
|
|
107875
108117
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -107878,7 +108120,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
107878
108120
|
const result = {
|
|
107879
108121
|
address: account.address,
|
|
107880
108122
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
107881
|
-
vault:
|
|
108123
|
+
vault: join30(paths.directory, "vault.json"),
|
|
107882
108124
|
...label === void 0 ? {} : { label },
|
|
107883
108125
|
spendCaps: created.entry.spendCaps,
|
|
107884
108126
|
isDefault,
|
|
@@ -107918,7 +108160,7 @@ function formatCaps2(caps) {
|
|
|
107918
108160
|
function walletListResult(store, wallets, unlocked) {
|
|
107919
108161
|
return {
|
|
107920
108162
|
default: store.defaultName ?? null,
|
|
107921
|
-
vault:
|
|
108163
|
+
vault: join30(store.home, "vault.json"),
|
|
107922
108164
|
wallets: wallets.map((wallet) => ({
|
|
107923
108165
|
name: wallet.name,
|
|
107924
108166
|
...wallet.address === void 0 ? {} : { address: wallet.address },
|
|
@@ -109191,7 +109433,7 @@ function formatClaimed(origin, claimed) {
|
|
|
109191
109433
|
}
|
|
109192
109434
|
var EXPORT_KEY_WARNING = "Anyone with this key can spend the wallet. Never paste it into a website or chat.";
|
|
109193
109435
|
async function deviceVaultKey2(store, dependencies) {
|
|
109194
|
-
const path =
|
|
109436
|
+
const path = join30(store.home, "vault.json");
|
|
109195
109437
|
const metadata = await readVaultFileUnlocked(path);
|
|
109196
109438
|
const secrets = getSecretStore(dependencies);
|
|
109197
109439
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
@@ -109284,7 +109526,7 @@ async function backupCommand(argv, json2, io, dependencies) {
|
|
|
109284
109526
|
const target = await targetWallet(parsed, dependencies);
|
|
109285
109527
|
const vaultAccount = await target.store.hasVaultAccount(target.name);
|
|
109286
109528
|
if (vaultAccount) {
|
|
109287
|
-
const vault = await readVaultFileUnlocked(
|
|
109529
|
+
const vault = await readVaultFileUnlocked(join30(target.store.home, "vault.json"));
|
|
109288
109530
|
if (vault.accounts.some((account) => account.name === target.name && account.kind === "imported")) {
|
|
109289
109531
|
throw new KeystoreError(
|
|
109290
109532
|
`Account ${target.name} was imported and is not recoverable from the vault phrase. Back it up with vapi export-key --account ${target.name}.`
|
|
@@ -109361,7 +109603,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109361
109603
|
const existed = store.has(name);
|
|
109362
109604
|
if (existed && !parsed.has("--replace")) {
|
|
109363
109605
|
const address4 = await store.readAddress(name);
|
|
109364
|
-
const location = await store.hasVaultAccount(name) ?
|
|
109606
|
+
const location = await store.hasVaultAccount(name) ? join30(store.home, "vault.json") : store.pathFor(name);
|
|
109365
109607
|
throw new Error(
|
|
109366
109608
|
[
|
|
109367
109609
|
`Wallet ${name} already exists at ${location}.`,
|
|
@@ -109389,7 +109631,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109389
109631
|
const imported = fromPhrase ? await store.create(name, "", { phrase: secret }) : await store.importKey(name, "", secret);
|
|
109390
109632
|
await recordAudit(dependencies, "wallet.import", { wallet: imported.name });
|
|
109391
109633
|
const account = imported.account;
|
|
109392
|
-
if (!await
|
|
109634
|
+
if (!await fileExists3(paths.config)) {
|
|
109393
109635
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
109394
109636
|
} else {
|
|
109395
109637
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -109397,7 +109639,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109397
109639
|
const result = {
|
|
109398
109640
|
address: account.address,
|
|
109399
109641
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
109400
|
-
vault:
|
|
109642
|
+
vault: join30(paths.directory, "vault.json"),
|
|
109401
109643
|
...previousKeystore ? { previousKeystore } : {},
|
|
109402
109644
|
message: "Wallet imported. Its encrypted key stays on this machine."
|
|
109403
109645
|
};
|
|
@@ -110005,9 +110247,9 @@ function isHttpUrl(value) {
|
|
|
110005
110247
|
return false;
|
|
110006
110248
|
}
|
|
110007
110249
|
}
|
|
110008
|
-
async function
|
|
110250
|
+
async function fileExists3(path) {
|
|
110009
110251
|
try {
|
|
110010
|
-
await
|
|
110252
|
+
await stat18(path);
|
|
110011
110253
|
return true;
|
|
110012
110254
|
} catch (error61) {
|
|
110013
110255
|
if (isMissingFile(error61)) return false;
|
|
@@ -110029,7 +110271,7 @@ function parseInitNetworks(value) {
|
|
|
110029
110271
|
|
|
110030
110272
|
// ../cli/src/update-check.ts
|
|
110031
110273
|
import { lookup } from "node:dns/promises";
|
|
110032
|
-
import { mkdir as mkdir22, readFile as
|
|
110274
|
+
import { mkdir as mkdir22, readFile as readFile32, writeFile as writeFile13 } from "node:fs/promises";
|
|
110033
110275
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
110034
110276
|
var CHECK_TIMEOUT_MS = 1500;
|
|
110035
110277
|
var LATEST_URL = "https://registry.npmjs.org/vapi-network/latest";
|
|
@@ -110073,7 +110315,7 @@ async function latestNotice(options, env, signal) {
|
|
|
110073
110315
|
const now = (options.nowMs ?? Date.now)();
|
|
110074
110316
|
let cached2;
|
|
110075
110317
|
try {
|
|
110076
|
-
const value = JSON.parse(await
|
|
110318
|
+
const value = JSON.parse(await readFile32(paths.updateCheck, "utf8"));
|
|
110077
110319
|
if (isRecord13(value) && typeof value.checkedAt === "number" && Number.isFinite(value.checkedAt) && typeof value.latest === "string" && parseVersion(value.latest)) {
|
|
110078
110320
|
cached2 = { checkedAt: value.checkedAt, latest: value.latest };
|
|
110079
110321
|
}
|