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