vapi-network 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/SKILL.md +1 -1
- package/dist/cli.js +1466 -1205
- package/dist/cli.js.map +3 -3
- package/dist/index.js +1484 -1214
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6673,7 +6673,7 @@ function weierstrass(curveDef) {
|
|
|
6673
6673
|
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
6674
6674
|
if (["recovered", "canonical"].some((k) => k in opts))
|
|
6675
6675
|
throw new Error("sign() legacy options not supported");
|
|
6676
|
-
const { hash: hash5, randomBytes:
|
|
6676
|
+
const { hash: hash5, randomBytes: randomBytes18 } = CURVE;
|
|
6677
6677
|
let { lowS, prehash, extraEntropy: ent } = opts;
|
|
6678
6678
|
if (lowS == null)
|
|
6679
6679
|
lowS = true;
|
|
@@ -6685,7 +6685,7 @@ function weierstrass(curveDef) {
|
|
|
6685
6685
|
const d = normPrivateKeyToScalar(privateKey);
|
|
6686
6686
|
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
6687
6687
|
if (ent != null && ent !== false) {
|
|
6688
|
-
const e3 = ent === true ?
|
|
6688
|
+
const e3 = ent === true ? randomBytes18(Fp.BYTES) : ent;
|
|
6689
6689
|
seedArgs.push(ensureBytes("extraEntropy", e3));
|
|
6690
6690
|
}
|
|
6691
6691
|
const seed = concatBytes3(...seedArgs);
|
|
@@ -10118,8 +10118,8 @@ var init_call = __esm({
|
|
|
10118
10118
|
|
|
10119
10119
|
// ../cli/src/cli.ts
|
|
10120
10120
|
import { spawn as spawn5 } from "node:child_process";
|
|
10121
|
-
import { stat as
|
|
10122
|
-
import { join as
|
|
10121
|
+
import { stat as stat18 } from "node:fs/promises";
|
|
10122
|
+
import { join as join30 } from "node:path";
|
|
10123
10123
|
import { createInterface as createInterface3 } from "node:readline/promises";
|
|
10124
10124
|
|
|
10125
10125
|
// ../../node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/external.js
|
|
@@ -45227,9 +45227,9 @@ var X402Error = class extends Error {
|
|
|
45227
45227
|
function isValidPaymentId(value) {
|
|
45228
45228
|
return typeof value === "string" && PAYMENT_ID_PATTERN.test(value);
|
|
45229
45229
|
}
|
|
45230
|
-
function createPaymentId(
|
|
45230
|
+
function createPaymentId(randomBytes18 = fillRandomBytes) {
|
|
45231
45231
|
const bytes = new Uint8Array(16);
|
|
45232
|
-
|
|
45232
|
+
randomBytes18(bytes);
|
|
45233
45233
|
return `pay_${bytesToHex(bytes).slice(2)}`;
|
|
45234
45234
|
}
|
|
45235
45235
|
function buildPaymentExtensions(serverExtensions, options = {}) {
|
|
@@ -46620,8 +46620,8 @@ function conciseError(error61) {
|
|
|
46620
46620
|
}
|
|
46621
46621
|
|
|
46622
46622
|
// ../core/src/account-add.ts
|
|
46623
|
-
import { stat as
|
|
46624
|
-
import { join as
|
|
46623
|
+
import { stat as stat10 } from "node:fs/promises";
|
|
46624
|
+
import { join as join10 } from "node:path";
|
|
46625
46625
|
|
|
46626
46626
|
// ../core/src/agent-link.ts
|
|
46627
46627
|
import { createHash } from "node:crypto";
|
|
@@ -70033,20 +70033,20 @@ async function promptForSecret(prompt, noTerminalHint) {
|
|
|
70033
70033
|
}
|
|
70034
70034
|
|
|
70035
70035
|
// ../core/src/wallet-store.ts
|
|
70036
|
-
import { randomBytes as
|
|
70036
|
+
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
70037
70037
|
import {
|
|
70038
70038
|
chmod as chmod3,
|
|
70039
70039
|
lstat as lstat2,
|
|
70040
70040
|
mkdir as mkdir10,
|
|
70041
|
-
open as
|
|
70041
|
+
open as open8,
|
|
70042
70042
|
readdir as readdir3,
|
|
70043
|
-
readFile as
|
|
70043
|
+
readFile as readFile12,
|
|
70044
70044
|
rename as rename7,
|
|
70045
|
-
stat as
|
|
70045
|
+
stat as stat9,
|
|
70046
70046
|
unlink as unlink6,
|
|
70047
70047
|
writeFile as writeFile5
|
|
70048
70048
|
} from "node:fs/promises";
|
|
70049
|
-
import { dirname as dirname7, join as
|
|
70049
|
+
import { dirname as dirname7, join as join9 } from "node:path";
|
|
70050
70050
|
|
|
70051
70051
|
// ../core/src/account-movement-lock.ts
|
|
70052
70052
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
@@ -70164,497 +70164,16 @@ function isOpenMovementLeg(leg, journalEvidence) {
|
|
|
70164
70164
|
// ../core/src/secret-store.ts
|
|
70165
70165
|
import { spawn } from "node:child_process";
|
|
70166
70166
|
import { existsSync } from "node:fs";
|
|
70167
|
-
import { delimiter, isAbsolute, join as
|
|
70168
|
-
var SECRET_STORE_SERVICE = "vapi-network";
|
|
70169
|
-
var SECURITY_BINARY = "/usr/bin/security";
|
|
70170
|
-
var SECRET_TOOL_BINARY = "secret-tool";
|
|
70171
|
-
var WINDOWS_POWERSHELL_ARGS = ["-NoProfile", "-NonInteractive", "-Command", "-"];
|
|
70172
|
-
var SECURITY_ITEM_NOT_FOUND = 44;
|
|
70173
|
-
var WINDOWS_SECRET_SUCCESS = 0;
|
|
70174
|
-
var WINDOWS_SECRET_NOT_FOUND = 2;
|
|
70175
|
-
var UNSUPPORTED_PLATFORM = "No OS secret store on this platform yet; use VAPI_KEYSTORE_PASSWORD.";
|
|
70176
|
-
var SECRET_TOOL_MISSING = [
|
|
70177
|
-
"secret-tool is not installed, so the passphrase cannot be kept in the OS secret store.",
|
|
70178
|
-
"Install libsecret-tools (Debian, Ubuntu) or libsecret (Fedora, Arch), or use VAPI_KEYSTORE_PASSWORD."
|
|
70179
|
-
].join(" ");
|
|
70180
|
-
var POWERSHELL_MISSING = [
|
|
70181
|
-
"Windows PowerShell (powershell.exe) was not found, so the passphrase cannot be kept in the OS secret store.",
|
|
70182
|
-
"Use VAPI_KEYSTORE_PASSWORD."
|
|
70183
|
-
].join(" ");
|
|
70184
|
-
function secretStore(options = {}) {
|
|
70185
|
-
const platform2 = options.platform ?? process.platform;
|
|
70186
|
-
const run = options.run ?? (async (file2, args, input2) => await spawnRunner(platform2, file2, args, input2));
|
|
70187
|
-
const env = options.env ?? process.env;
|
|
70188
|
-
const installed = options.installed ?? ((file2) => binaryInstalled(file2, env));
|
|
70189
|
-
if (platform2 === "darwin") return keychainStore(platform2, run);
|
|
70190
|
-
if (platform2 === "win32") return windowsDataProtectionStore(platform2, run, env, installed);
|
|
70191
|
-
if (platform2 === "linux") return libsecretStore(platform2, run, installed);
|
|
70192
|
-
return unsupportedStore(platform2);
|
|
70193
|
-
}
|
|
70194
|
-
function memorySecretStore(initial = {}) {
|
|
70195
|
-
const entries = new Map(Object.entries(initial));
|
|
70196
|
-
return {
|
|
70197
|
-
available: true,
|
|
70198
|
-
platform: process.platform,
|
|
70199
|
-
description: "an in-memory store",
|
|
70200
|
-
async get(name) {
|
|
70201
|
-
return entries.get(name);
|
|
70202
|
-
},
|
|
70203
|
-
async has(name) {
|
|
70204
|
-
return entries.has(name);
|
|
70205
|
-
},
|
|
70206
|
-
async set(name, passphrase) {
|
|
70207
|
-
entries.set(name, passphrase);
|
|
70208
|
-
},
|
|
70209
|
-
async remove(name) {
|
|
70210
|
-
return entries.delete(name);
|
|
70211
|
-
},
|
|
70212
|
-
async list() {
|
|
70213
|
-
return [...entries.keys()].sort();
|
|
70214
|
-
}
|
|
70215
|
-
};
|
|
70216
|
-
}
|
|
70217
|
-
function keychainStore(platform2, run) {
|
|
70218
|
-
const find = async (account, withPassword) => await run(SECURITY_BINARY, [
|
|
70219
|
-
"find-generic-password",
|
|
70220
|
-
"-a",
|
|
70221
|
-
account,
|
|
70222
|
-
"-s",
|
|
70223
|
-
SECRET_STORE_SERVICE,
|
|
70224
|
-
...withPassword ? ["-w"] : []
|
|
70225
|
-
]);
|
|
70226
|
-
const read = async (account, what) => {
|
|
70227
|
-
const result = await find(account, true);
|
|
70228
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return void 0;
|
|
70229
|
-
requireSuccess(result, what);
|
|
70230
|
-
const value = withoutTrailingNewline(result.stdout);
|
|
70231
|
-
return value.length === 0 ? void 0 : value;
|
|
70232
|
-
};
|
|
70233
|
-
const write2 = async (account, value, what) => {
|
|
70234
|
-
const result = await run(
|
|
70235
|
-
SECURITY_BINARY,
|
|
70236
|
-
[
|
|
70237
|
-
"add-generic-password",
|
|
70238
|
-
"-a",
|
|
70239
|
-
account,
|
|
70240
|
-
"-s",
|
|
70241
|
-
SECRET_STORE_SERVICE,
|
|
70242
|
-
"-l",
|
|
70243
|
-
`${SECRET_STORE_SERVICE} ${account}`,
|
|
70244
|
-
"-U",
|
|
70245
|
-
"-w"
|
|
70246
|
-
],
|
|
70247
|
-
// `security` asks for the password and then for its confirmation.
|
|
70248
|
-
`${value}
|
|
70249
|
-
${value}
|
|
70250
|
-
`
|
|
70251
|
-
);
|
|
70252
|
-
requireSuccess(result, what);
|
|
70253
|
-
};
|
|
70254
|
-
const erase = async (account, what) => {
|
|
70255
|
-
const result = await run(SECURITY_BINARY, [
|
|
70256
|
-
"delete-generic-password",
|
|
70257
|
-
"-a",
|
|
70258
|
-
account,
|
|
70259
|
-
"-s",
|
|
70260
|
-
SECRET_STORE_SERVICE
|
|
70261
|
-
]);
|
|
70262
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70263
|
-
requireSuccess(result, what);
|
|
70264
|
-
return true;
|
|
70265
|
-
};
|
|
70266
|
-
const erasePartsAfter = async (account, keep, what) => {
|
|
70267
|
-
for (let part = keep + 1; part <= MAX_KEYCHAIN_PARTS; part += 1) {
|
|
70268
|
-
if (!await erase(keychainPart(account, part), what)) return;
|
|
70269
|
-
}
|
|
70270
|
-
};
|
|
70271
|
-
return {
|
|
70272
|
-
available: true,
|
|
70273
|
-
platform: platform2,
|
|
70274
|
-
description: "the macOS Keychain",
|
|
70275
|
-
async get(name) {
|
|
70276
|
-
const account = accountFor(name);
|
|
70277
|
-
const what = `read the passphrase of ${name} from the macOS Keychain`;
|
|
70278
|
-
const value = await read(account, what);
|
|
70279
|
-
const parts = value === void 0 ? void 0 : chunkedPartCount(value);
|
|
70280
|
-
if (value === void 0 || parts === void 0) return value;
|
|
70281
|
-
let joined = "";
|
|
70282
|
-
for (let part = 1; part <= parts; part += 1) {
|
|
70283
|
-
const chunk = await read(keychainPart(account, part), what);
|
|
70284
|
-
if (chunk === void 0) {
|
|
70285
|
-
throw new KeystoreError(
|
|
70286
|
-
`The stored secret ${name} is incomplete in the macOS Keychain. Store it again.`
|
|
70287
|
-
);
|
|
70288
|
-
}
|
|
70289
|
-
joined += chunk;
|
|
70290
|
-
}
|
|
70291
|
-
return joined;
|
|
70292
|
-
},
|
|
70293
|
-
async has(name) {
|
|
70294
|
-
const result = await find(accountFor(name), false);
|
|
70295
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70296
|
-
requireSuccess(result, `look up ${name} in the macOS Keychain`);
|
|
70297
|
-
return true;
|
|
70298
|
-
},
|
|
70299
|
-
async set(name, passphrase) {
|
|
70300
|
-
requirePassphrase(passphrase);
|
|
70301
|
-
const account = accountFor(name);
|
|
70302
|
-
const what = `store the passphrase of ${name} in the macOS Keychain`;
|
|
70303
|
-
if (passphrase.length <= KEYCHAIN_PROMPT_LIMIT) {
|
|
70304
|
-
await write2(account, passphrase, what);
|
|
70305
|
-
return;
|
|
70306
|
-
}
|
|
70307
|
-
const chunks = [];
|
|
70308
|
-
for (let index2 = 0; index2 < passphrase.length; index2 += KEYCHAIN_CHUNK) {
|
|
70309
|
-
chunks.push(passphrase.slice(index2, index2 + KEYCHAIN_CHUNK));
|
|
70310
|
-
}
|
|
70311
|
-
if (chunks.length > MAX_KEYCHAIN_PARTS) {
|
|
70312
|
-
throw new KeystoreError(`The secret ${name} is too long for the macOS Keychain.`);
|
|
70313
|
-
}
|
|
70314
|
-
for (const [index2, chunk] of chunks.entries()) {
|
|
70315
|
-
await write2(keychainPart(account, index2 + 1), chunk, what);
|
|
70316
|
-
}
|
|
70317
|
-
await erasePartsAfter(account, chunks.length, what);
|
|
70318
|
-
await write2(account, `${CHUNKED_MARKER}${chunks.length}`, what);
|
|
70319
|
-
},
|
|
70320
|
-
async remove(name) {
|
|
70321
|
-
const account = accountFor(name);
|
|
70322
|
-
const what = `remove the passphrase of ${name} from the macOS Keychain`;
|
|
70323
|
-
const found = await find(account, true);
|
|
70324
|
-
if (found.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70325
|
-
requireSuccess(found, what);
|
|
70326
|
-
if (chunkedPartCount(withoutTrailingNewline(found.stdout)) !== void 0) {
|
|
70327
|
-
await erasePartsAfter(account, 0, what);
|
|
70328
|
-
}
|
|
70329
|
-
return await erase(account, what);
|
|
70330
|
-
}
|
|
70331
|
-
};
|
|
70332
|
-
}
|
|
70333
|
-
var KEYCHAIN_PROMPT_LIMIT = 128;
|
|
70334
|
-
var KEYCHAIN_CHUNK = 120;
|
|
70335
|
-
var MAX_KEYCHAIN_PARTS = 32;
|
|
70336
|
-
var CHUNKED_MARKER = "vapi-chunked:v1:";
|
|
70337
|
-
function keychainPart(account, part) {
|
|
70338
|
-
return `${account}#${part}`;
|
|
70339
|
-
}
|
|
70340
|
-
function chunkedPartCount(value) {
|
|
70341
|
-
if (!value.startsWith(CHUNKED_MARKER)) return void 0;
|
|
70342
|
-
const parts = Number(value.slice(CHUNKED_MARKER.length));
|
|
70343
|
-
return Number.isInteger(parts) && parts > 0 && parts <= MAX_KEYCHAIN_PARTS ? parts : void 0;
|
|
70344
|
-
}
|
|
70345
|
-
function windowsSecretFileName(account) {
|
|
70346
|
-
let encoded = "";
|
|
70347
|
-
for (let index2 = 0; index2 < account.length; index2 += 1) {
|
|
70348
|
-
const character = account[index2];
|
|
70349
|
-
if (/^[a-z0-9._#-]$/u.test(character)) {
|
|
70350
|
-
encoded += character;
|
|
70351
|
-
continue;
|
|
70352
|
-
}
|
|
70353
|
-
encoded += `%${account.charCodeAt(index2).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
70354
|
-
}
|
|
70355
|
-
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu.test(encoded)) {
|
|
70356
|
-
encoded = `%${encoded.charCodeAt(0).toString(16).toUpperCase()}${encoded.slice(1)}`;
|
|
70357
|
-
}
|
|
70358
|
-
return `${encoded}.bin`;
|
|
70359
|
-
}
|
|
70360
|
-
function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
70361
|
-
const powershell = `${env.SystemRoot ?? "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
70362
|
-
const fileDetails = (name) => {
|
|
70363
|
-
const file2 = windowsSecretFileName(accountFor(name));
|
|
70364
|
-
return { file: file2, account: file2.slice(0, -".bin".length) };
|
|
70365
|
-
};
|
|
70366
|
-
const script = (file2, operations) => [
|
|
70367
|
-
"$ErrorActionPreference = 'Stop'",
|
|
70368
|
-
"try {",
|
|
70369
|
-
" Add-Type -AssemblyName System.Security",
|
|
70370
|
-
" $dir = Join-Path $env:LOCALAPPDATA 'vapi-network\\secrets'",
|
|
70371
|
-
` $path = Join-Path $dir '${file2}'`,
|
|
70372
|
-
...operations.map((operation) => ` ${operation}`),
|
|
70373
|
-
"} catch {",
|
|
70374
|
-
" [Console]::Error.WriteLine($_.Exception.Message)",
|
|
70375
|
-
" exit 1",
|
|
70376
|
-
"}"
|
|
70377
|
-
].join("\n");
|
|
70378
|
-
const execute = async (script2) => {
|
|
70379
|
-
const result = await run(powershell, WINDOWS_POWERSHELL_ARGS, `${script2}
|
|
70380
|
-
|
|
70381
|
-
`);
|
|
70382
|
-
requirePowerShell(result);
|
|
70383
|
-
return result;
|
|
70384
|
-
};
|
|
70385
|
-
return {
|
|
70386
|
-
available: installed(powershell),
|
|
70387
|
-
platform: platform2,
|
|
70388
|
-
description: "Windows Data Protection (DPAPI)",
|
|
70389
|
-
async get(name) {
|
|
70390
|
-
const { file: file2, account } = fileDetails(name);
|
|
70391
|
-
const result = await execute(
|
|
70392
|
-
script(file2, [
|
|
70393
|
-
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
70394
|
-
"$blob = [System.IO.File]::ReadAllBytes($path)",
|
|
70395
|
-
"$bytes = [System.Security.Cryptography.ProtectedData]::Unprotect($blob, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
70396
|
-
"[Console]::Out.Write([Convert]::ToBase64String($bytes))",
|
|
70397
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70398
|
-
])
|
|
70399
|
-
);
|
|
70400
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return void 0;
|
|
70401
|
-
requireSuccess(result, `read the passphrase of ${name} from Windows Data Protection`);
|
|
70402
|
-
const value = Buffer.from(result.stdout.trim(), "base64").toString("utf8");
|
|
70403
|
-
return value.length === 0 ? void 0 : value;
|
|
70404
|
-
},
|
|
70405
|
-
async has(name) {
|
|
70406
|
-
const { file: file2, account } = fileDetails(name);
|
|
70407
|
-
const result = await execute(
|
|
70408
|
-
script(file2, [
|
|
70409
|
-
`if (Test-Path -LiteralPath $path) { exit ${WINDOWS_SECRET_SUCCESS} }`,
|
|
70410
|
-
`[Console]::Error.WriteLine('No stored secret for ${account}.')`,
|
|
70411
|
-
`exit ${WINDOWS_SECRET_NOT_FOUND}`
|
|
70412
|
-
])
|
|
70413
|
-
);
|
|
70414
|
-
if (result.code === WINDOWS_SECRET_SUCCESS) return true;
|
|
70415
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
70416
|
-
requireSuccess(result, `look up ${name} in Windows Data Protection`);
|
|
70417
|
-
return false;
|
|
70418
|
-
},
|
|
70419
|
-
async set(name, passphrase) {
|
|
70420
|
-
requirePassphrase(passphrase);
|
|
70421
|
-
const { file: file2 } = fileDetails(name);
|
|
70422
|
-
const value = Buffer.from(passphrase, "utf8").toString("base64");
|
|
70423
|
-
const result = await execute(
|
|
70424
|
-
script(file2, [
|
|
70425
|
-
"[void][System.IO.Directory]::CreateDirectory($dir)",
|
|
70426
|
-
`$bytes = [Convert]::FromBase64String('${value}')`,
|
|
70427
|
-
"$blob = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
70428
|
-
"[System.IO.File]::WriteAllBytes($path, $blob)",
|
|
70429
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70430
|
-
])
|
|
70431
|
-
);
|
|
70432
|
-
requireSuccess(result, `store the passphrase of ${name} in Windows Data Protection`);
|
|
70433
|
-
},
|
|
70434
|
-
async remove(name) {
|
|
70435
|
-
const { file: file2, account } = fileDetails(name);
|
|
70436
|
-
const result = await execute(
|
|
70437
|
-
script(file2, [
|
|
70438
|
-
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
70439
|
-
"Remove-Item -LiteralPath $path -Force",
|
|
70440
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70441
|
-
])
|
|
70442
|
-
);
|
|
70443
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
70444
|
-
requireSuccess(result, `remove the passphrase of ${name} from Windows Data Protection`);
|
|
70445
|
-
return true;
|
|
70446
|
-
}
|
|
70447
|
-
};
|
|
70448
|
-
}
|
|
70449
|
-
function libsecretStore(platform2, run, installed) {
|
|
70450
|
-
const lookup2 = async (name) => {
|
|
70451
|
-
const result = await run(SECRET_TOOL_BINARY, [
|
|
70452
|
-
"lookup",
|
|
70453
|
-
"service",
|
|
70454
|
-
SECRET_STORE_SERVICE,
|
|
70455
|
-
"account",
|
|
70456
|
-
accountFor(name)
|
|
70457
|
-
]);
|
|
70458
|
-
requireBinary(result);
|
|
70459
|
-
const value = withoutTrailingNewline(result.stdout);
|
|
70460
|
-
if (result.code === 0) return value.length === 0 ? void 0 : value;
|
|
70461
|
-
if (result.stderr.trim().length === 0) return void 0;
|
|
70462
|
-
requireSuccess(result, `read the passphrase of ${name} from the secret service`);
|
|
70463
|
-
return void 0;
|
|
70464
|
-
};
|
|
70465
|
-
return {
|
|
70466
|
-
available: installed(SECRET_TOOL_BINARY),
|
|
70467
|
-
platform: platform2,
|
|
70468
|
-
description: "the libsecret keyring",
|
|
70469
|
-
get: lookup2,
|
|
70470
|
-
async has(name) {
|
|
70471
|
-
return await lookup2(name) !== void 0;
|
|
70472
|
-
},
|
|
70473
|
-
async set(name, passphrase) {
|
|
70474
|
-
requirePassphrase(passphrase);
|
|
70475
|
-
const account = accountFor(name);
|
|
70476
|
-
const result = await run(
|
|
70477
|
-
SECRET_TOOL_BINARY,
|
|
70478
|
-
[
|
|
70479
|
-
"store",
|
|
70480
|
-
`--label=${SECRET_STORE_SERVICE} ${account}`,
|
|
70481
|
-
"service",
|
|
70482
|
-
SECRET_STORE_SERVICE,
|
|
70483
|
-
"account",
|
|
70484
|
-
account
|
|
70485
|
-
],
|
|
70486
|
-
`${passphrase}
|
|
70487
|
-
`
|
|
70488
|
-
);
|
|
70489
|
-
requireBinary(result);
|
|
70490
|
-
requireSuccess(result, `store the passphrase of ${name} in the secret service`);
|
|
70491
|
-
},
|
|
70492
|
-
async remove(name) {
|
|
70493
|
-
const existed = await lookup2(name) !== void 0;
|
|
70494
|
-
const result = await run(SECRET_TOOL_BINARY, [
|
|
70495
|
-
"clear",
|
|
70496
|
-
"service",
|
|
70497
|
-
SECRET_STORE_SERVICE,
|
|
70498
|
-
"account",
|
|
70499
|
-
accountFor(name)
|
|
70500
|
-
]);
|
|
70501
|
-
requireBinary(result);
|
|
70502
|
-
requireSuccess(result, `remove the passphrase of ${name} from the secret service`);
|
|
70503
|
-
return existed;
|
|
70504
|
-
}
|
|
70505
|
-
};
|
|
70506
|
-
}
|
|
70507
|
-
function unsupportedStore(platform2) {
|
|
70508
|
-
const refuse = () => {
|
|
70509
|
-
throw new KeystoreError(UNSUPPORTED_PLATFORM);
|
|
70510
|
-
};
|
|
70511
|
-
return {
|
|
70512
|
-
available: false,
|
|
70513
|
-
platform: platform2,
|
|
70514
|
-
description: "no OS secret store",
|
|
70515
|
-
get: async () => refuse(),
|
|
70516
|
-
has: async () => refuse(),
|
|
70517
|
-
set: async () => refuse(),
|
|
70518
|
-
remove: async () => refuse()
|
|
70519
|
-
};
|
|
70520
|
-
}
|
|
70521
|
-
function accountFor(name) {
|
|
70522
|
-
const account = name.trim();
|
|
70523
|
-
if (account.length === 0) {
|
|
70524
|
-
throw new KeystoreError("A wallet name is needed to reach the OS secret store.");
|
|
70525
|
-
}
|
|
70526
|
-
return account;
|
|
70527
|
-
}
|
|
70528
|
-
function requirePassphrase(passphrase) {
|
|
70529
|
-
if (passphrase.length === 0) {
|
|
70530
|
-
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
70531
|
-
}
|
|
70532
|
-
}
|
|
70533
|
-
function requireBinary(result) {
|
|
70534
|
-
if (result.notFound === true) throw new KeystoreError(SECRET_TOOL_MISSING);
|
|
70535
|
-
}
|
|
70536
|
-
function requirePowerShell(result) {
|
|
70537
|
-
if (result.notFound === true) throw new KeystoreError(POWERSHELL_MISSING);
|
|
70538
|
-
}
|
|
70539
|
-
function binaryInstalled(file2, env) {
|
|
70540
|
-
if (isAbsolute(file2) || win32.isAbsolute(file2)) return existsSync(file2);
|
|
70541
|
-
return (env.PATH ?? "").split(delimiter).some((directory) => existsSync(join6(directory, file2)));
|
|
70542
|
-
}
|
|
70543
|
-
function requireSuccess(result, what) {
|
|
70544
|
-
if (result.code === 0) return;
|
|
70545
|
-
const detail = result.stderr.trim() || result.stdout.trim();
|
|
70546
|
-
throw new KeystoreError(
|
|
70547
|
-
`Could not ${what}${result.code === null ? "" : ` (exit ${result.code})`}.${detail.length === 0 ? "" : ` ${detail}`}`
|
|
70548
|
-
);
|
|
70549
|
-
}
|
|
70550
|
-
function withoutTrailingNewline(value) {
|
|
70551
|
-
return value.replace(/\r?\n$/u, "");
|
|
70552
|
-
}
|
|
70553
|
-
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve3) => {
|
|
70554
|
-
let stdout = "";
|
|
70555
|
-
let stderr2 = "";
|
|
70556
|
-
let settled = false;
|
|
70557
|
-
const finish = (outcome) => {
|
|
70558
|
-
if (settled) return;
|
|
70559
|
-
settled = true;
|
|
70560
|
-
resolve3(outcome);
|
|
70561
|
-
};
|
|
70562
|
-
const child = spawn(file2, [...args], {
|
|
70563
|
-
detached: platform2 !== "win32",
|
|
70564
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
70565
|
-
windowsHide: true
|
|
70566
|
-
});
|
|
70567
|
-
child.stdout?.setEncoding("utf8");
|
|
70568
|
-
child.stdout?.on("data", (chunk) => {
|
|
70569
|
-
stdout += chunk;
|
|
70570
|
-
});
|
|
70571
|
-
child.stderr?.setEncoding("utf8");
|
|
70572
|
-
child.stderr?.on("data", (chunk) => {
|
|
70573
|
-
stderr2 += chunk;
|
|
70574
|
-
});
|
|
70575
|
-
child.on("error", (error61) => {
|
|
70576
|
-
finish({
|
|
70577
|
-
code: null,
|
|
70578
|
-
stdout,
|
|
70579
|
-
stderr: stderr2,
|
|
70580
|
-
...error61.code === "ENOENT" ? { notFound: true } : {}
|
|
70581
|
-
});
|
|
70582
|
-
});
|
|
70583
|
-
child.on("close", (code) => finish({ code, stdout, stderr: stderr2 }));
|
|
70584
|
-
child.stdin?.on("error", () => void 0);
|
|
70585
|
-
child.stdin?.end(input2 ?? "");
|
|
70586
|
-
});
|
|
70587
|
-
|
|
70588
|
-
// ../core/src/passphrase.ts
|
|
70589
|
-
var PASSPHRASE_ENVIRONMENT_VARIABLE = "VAPI_KEYSTORE_PASSWORD";
|
|
70590
|
-
function noPassphraseHint(walletName) {
|
|
70591
|
-
return `Set ${PASSPHRASE_ENVIRONMENT_VARIABLE}, or store this wallet's passphrase once with vapi unlock --wallet ${walletName}.`;
|
|
70592
|
-
}
|
|
70593
|
-
function staleStoredPassphraseMessage(walletName, store) {
|
|
70594
|
-
return [
|
|
70595
|
-
`The passphrase stored in ${store.description} no longer opens wallet ${walletName}.`,
|
|
70596
|
-
`Store the current one with vapi unlock --wallet ${walletName}, or remove it with vapi lock --wallet ${walletName}.`
|
|
70597
|
-
].join(" ");
|
|
70598
|
-
}
|
|
70599
|
-
async function resolvePassphrase(walletName, options = {}) {
|
|
70600
|
-
const env = options.env ?? process.env;
|
|
70601
|
-
const fromEnvironment = env[PASSPHRASE_ENVIRONMENT_VARIABLE];
|
|
70602
|
-
if (fromEnvironment !== void 0) {
|
|
70603
|
-
if (fromEnvironment.length === 0) {
|
|
70604
|
-
throw new KeystoreError(`${PASSPHRASE_ENVIRONMENT_VARIABLE} cannot be empty.`);
|
|
70605
|
-
}
|
|
70606
|
-
return { passphrase: fromEnvironment, source: "environment" };
|
|
70607
|
-
}
|
|
70608
|
-
if (options.confirm !== true) {
|
|
70609
|
-
const stored = await readStored(options.store ?? secretStore(), walletName);
|
|
70610
|
-
if (stored !== void 0) return { passphrase: stored, source: "secret-store" };
|
|
70611
|
-
}
|
|
70612
|
-
const hint = noPassphraseHint(walletName);
|
|
70613
|
-
if (options.interactive === false) {
|
|
70614
|
-
throw new KeystoreError(
|
|
70615
|
-
`No interactive terminal is available for the keystore prompt. ${hint}`
|
|
70616
|
-
);
|
|
70617
|
-
}
|
|
70618
|
-
const prompt = options.prompt ?? promptForSecret;
|
|
70619
|
-
const first = await prompt(`Passphrase for ${walletName}: `, hint);
|
|
70620
|
-
if (first.length === 0) {
|
|
70621
|
-
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
70622
|
-
}
|
|
70623
|
-
if (options.confirm === true) {
|
|
70624
|
-
const second = await prompt("Confirm passphrase: ", hint);
|
|
70625
|
-
if (first !== second) throw new KeystoreError("Passphrases do not match.");
|
|
70626
|
-
}
|
|
70627
|
-
return { passphrase: first, source: "prompt" };
|
|
70628
|
-
}
|
|
70629
|
-
async function readStored(store, walletName) {
|
|
70630
|
-
if (!store.available) return void 0;
|
|
70631
|
-
try {
|
|
70632
|
-
return await store.get(walletName);
|
|
70633
|
-
} catch {
|
|
70634
|
-
return void 0;
|
|
70635
|
-
}
|
|
70636
|
-
}
|
|
70167
|
+
import { delimiter, isAbsolute, join as join7, win32 } from "node:path";
|
|
70637
70168
|
|
|
70638
|
-
// ../core/src/
|
|
70169
|
+
// ../core/src/file-secret-store.ts
|
|
70639
70170
|
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
70640
|
-
import {
|
|
70641
|
-
import { dirname as dirname5 } from "node:path";
|
|
70171
|
+
import { readFile as readFile8, stat as stat7 } from "node:fs/promises";
|
|
70642
70172
|
|
|
70643
|
-
// ../core/src/
|
|
70173
|
+
// ../core/src/vault.ts
|
|
70644
70174
|
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
70645
|
-
|
|
70646
|
-
|
|
70647
|
-
return typeof value === "string" && RUN_ID_PATTERN.test(value);
|
|
70648
|
-
}
|
|
70649
|
-
function createRunId(random = randomBytes5) {
|
|
70650
|
-
return `run_${Buffer.from(random(12)).toString("hex")}`;
|
|
70651
|
-
}
|
|
70652
|
-
var runRefSchema = external_exports.strictObject({
|
|
70653
|
-
id: external_exports.string().regex(RUN_ID_PATTERN),
|
|
70654
|
-
swarm: external_exports.string().optional(),
|
|
70655
|
-
member: external_exports.string().optional(),
|
|
70656
|
-
parentRunId: external_exports.string().optional()
|
|
70657
|
-
});
|
|
70175
|
+
import { mkdir as mkdir7, open as open5, readFile as readFile7, rename as rename4, rm, stat as stat6, unlink as unlink4, writeFile as writeFile3 } from "node:fs/promises";
|
|
70176
|
+
import { dirname as dirname5 } from "node:path";
|
|
70658
70177
|
|
|
70659
70178
|
// ../core/src/wallet-name.ts
|
|
70660
70179
|
var DEFAULT_WALLET_NAME = "main";
|
|
@@ -70667,260 +70186,7 @@ function isWalletName(value) {
|
|
|
70667
70186
|
return WALLET_NAME_PATTERN.test(value);
|
|
70668
70187
|
}
|
|
70669
70188
|
|
|
70670
|
-
// ../core/src/receipts.ts
|
|
70671
|
-
var receiptTestHooks;
|
|
70672
|
-
var RECEIPT_JOURNAL_BUSY_MESSAGE = "The receipt journal is busy. Wait for the other vapi command to finish, then retry.";
|
|
70673
|
-
async function withReceiptJournalLock(path, operation) {
|
|
70674
|
-
return await withFileLock(`${path}.lock`, operation, {
|
|
70675
|
-
lockedMessage: RECEIPT_JOURNAL_BUSY_MESSAGE
|
|
70676
|
-
});
|
|
70677
|
-
}
|
|
70678
|
-
var durationSchema = external_exports.number().nonnegative().finite();
|
|
70679
|
-
var receiptSchema = external_exports.strictObject({
|
|
70680
|
-
id: external_exports.string().min(1),
|
|
70681
|
-
timestamp: external_exports.iso.datetime(),
|
|
70682
|
-
run: runRefSchema.optional(),
|
|
70683
|
-
kind: external_exports.literal("transfer").optional(),
|
|
70684
|
-
wallet: walletNameSchema.optional(),
|
|
70685
|
-
resourceUrl: external_exports.url(),
|
|
70686
|
-
method: external_exports.string().min(1).optional(),
|
|
70687
|
-
source: external_exports.string().min(1).optional(),
|
|
70688
|
-
provenance: external_exports.array(
|
|
70689
|
-
external_exports.strictObject({
|
|
70690
|
-
source: external_exports.string().min(1),
|
|
70691
|
-
sourceUrl: external_exports.string().optional(),
|
|
70692
|
-
ref: external_exports.string().optional()
|
|
70693
|
-
})
|
|
70694
|
-
).optional(),
|
|
70695
|
-
quote: external_exports.strictObject({
|
|
70696
|
-
network: external_exports.string(),
|
|
70697
|
-
asset: external_exports.string().optional(),
|
|
70698
|
-
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
70699
|
-
payTo: external_exports.string().optional()
|
|
70700
|
-
}).optional(),
|
|
70701
|
-
payer: external_exports.string().optional(),
|
|
70702
|
-
paymentId: external_exports.string().regex(/^[A-Za-z0-9_-]{16,128}$/).optional(),
|
|
70703
|
-
authorization: external_exports.strictObject({
|
|
70704
|
-
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70705
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
70706
|
-
validBefore: external_exports.string().regex(/^\d+$/)
|
|
70707
|
-
}).optional(),
|
|
70708
|
-
transfer: external_exports.strictObject({
|
|
70709
|
-
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70710
|
-
toName: external_exports.string().min(1),
|
|
70711
|
-
toKind: external_exports.enum(["owner", "account"]),
|
|
70712
|
-
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
70713
|
-
network: external_exports.string().min(1),
|
|
70714
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
70715
|
-
status: external_exports.enum(["sent", "unknown", "failed"]),
|
|
70716
|
-
txHash: external_exports.string().regex(/^0x[0-9a-fA-F]+$/).nullable(),
|
|
70717
|
-
replayed: external_exports.boolean(),
|
|
70718
|
-
reservedOn: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
70719
|
-
request: external_exports.strictObject({
|
|
70720
|
-
authorization: external_exports.strictObject({
|
|
70721
|
-
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70722
|
-
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70723
|
-
value: external_exports.string().regex(/^\d+$/),
|
|
70724
|
-
validAfter: external_exports.string().regex(/^\d+$/),
|
|
70725
|
-
validBefore: external_exports.string().regex(/^\d+$/),
|
|
70726
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/)
|
|
70727
|
-
}),
|
|
70728
|
-
signature: external_exports.string().regex(/^0x[0-9a-fA-F]+$/)
|
|
70729
|
-
}).optional()
|
|
70730
|
-
}).optional(),
|
|
70731
|
-
settlement: external_exports.strictObject({
|
|
70732
|
-
outcome: external_exports.enum(["succeeded", "rejected", "unknown"]),
|
|
70733
|
-
transaction: external_exports.string().optional(),
|
|
70734
|
-
explorerUrl: external_exports.url().optional(),
|
|
70735
|
-
evidence: external_exports.unknown().optional()
|
|
70736
|
-
}).optional(),
|
|
70737
|
-
latencyMs: external_exports.number().nonnegative().finite().optional(),
|
|
70738
|
-
status: external_exports.number().int().min(100).max(599).optional(),
|
|
70739
|
-
error: external_exports.strictObject({ code: external_exports.string(), message: external_exports.string() }).optional(),
|
|
70740
|
-
phases: external_exports.strictObject({
|
|
70741
|
-
discoverMs: durationSchema.optional(),
|
|
70742
|
-
quoteMs: durationSchema.optional(),
|
|
70743
|
-
signMs: durationSchema.optional(),
|
|
70744
|
-
requestMs: durationSchema.optional(),
|
|
70745
|
-
settleMs: durationSchema.optional()
|
|
70746
|
-
}).optional(),
|
|
70747
|
-
listing: external_exports.strictObject({
|
|
70748
|
-
name: external_exports.string().min(1).optional(),
|
|
70749
|
-
providerHost: external_exports.string().min(1).optional(),
|
|
70750
|
-
source: external_exports.string().min(1)
|
|
70751
|
-
}).optional(),
|
|
70752
|
-
retry: external_exports.number().int().nonnegative().optional(),
|
|
70753
|
-
policy: external_exports.strictObject({
|
|
70754
|
-
maxPriceUsd: external_exports.string().regex(/^\d+(?:\.\d{1,6})?$/).optional(),
|
|
70755
|
-
capsApplied: external_exports.boolean()
|
|
70756
|
-
}).optional(),
|
|
70757
|
-
client: external_exports.strictObject({ name: external_exports.literal("vapi-network"), version: external_exports.string().min(1) }).optional(),
|
|
70758
|
-
outcome: external_exports.enum([
|
|
70759
|
-
"paid",
|
|
70760
|
-
"signed_in",
|
|
70761
|
-
"declined_policy",
|
|
70762
|
-
"failed_request",
|
|
70763
|
-
"settlement_rejected",
|
|
70764
|
-
"settlement_unknown"
|
|
70765
|
-
]).optional()
|
|
70766
|
-
});
|
|
70767
|
-
function parseReceipt(value) {
|
|
70768
|
-
const receipt = receiptSchema.parse(value);
|
|
70769
|
-
const transaction2 = receipt.settlement?.transaction;
|
|
70770
|
-
const network = receipt.quote?.network;
|
|
70771
|
-
const explorerUrl = transaction2 === void 0 || network === void 0 ? void 0 : explorerTransactionUrl(network, transaction2);
|
|
70772
|
-
if (explorerUrl === void 0 || receipt.settlement?.explorerUrl === explorerUrl) {
|
|
70773
|
-
return receipt;
|
|
70774
|
-
}
|
|
70775
|
-
return {
|
|
70776
|
-
...receipt,
|
|
70777
|
-
settlement: {
|
|
70778
|
-
outcome: receipt.settlement.outcome,
|
|
70779
|
-
...receipt.settlement.transaction ? { transaction: receipt.settlement.transaction } : {},
|
|
70780
|
-
explorerUrl,
|
|
70781
|
-
...receipt.settlement.evidence === void 0 ? {} : { evidence: receipt.settlement.evidence }
|
|
70782
|
-
}
|
|
70783
|
-
};
|
|
70784
|
-
}
|
|
70785
|
-
async function appendReceipt(receipt, path = getVapiPaths().receipts, options = {}) {
|
|
70786
|
-
const parsed = parseReceipt(
|
|
70787
|
-
receipt.wallet === void 0 && options.wallet !== void 0 ? { ...receipt, wallet: options.wallet } : receipt
|
|
70788
|
-
);
|
|
70789
|
-
await withReceiptJournalLock(path, async () => {
|
|
70790
|
-
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70791
|
-
const handle = await open5(path, "a", 384);
|
|
70792
|
-
try {
|
|
70793
|
-
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
70794
|
-
`, "utf8");
|
|
70795
|
-
} finally {
|
|
70796
|
-
await handle.close();
|
|
70797
|
-
}
|
|
70798
|
-
});
|
|
70799
|
-
return parsed;
|
|
70800
|
-
}
|
|
70801
|
-
async function readReceipts(path = getVapiPaths().receipts, options = {}) {
|
|
70802
|
-
let raw;
|
|
70803
|
-
try {
|
|
70804
|
-
raw = await readFile7(path, "utf8");
|
|
70805
|
-
} catch (error61) {
|
|
70806
|
-
if (isMissingFile(error61)) return [];
|
|
70807
|
-
throw error61;
|
|
70808
|
-
}
|
|
70809
|
-
const records = coalesceTransferReceiptRevisions(
|
|
70810
|
-
raw.split("\n").filter((line) => line.trim().length > 0).map((line, index2) => {
|
|
70811
|
-
try {
|
|
70812
|
-
return parseReceipt(JSON.parse(line));
|
|
70813
|
-
} catch (error61) {
|
|
70814
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70815
|
-
}
|
|
70816
|
-
})
|
|
70817
|
-
);
|
|
70818
|
-
const filtered = options.wallet === void 0 ? records : filterReceiptsByWallet(records, options.wallet);
|
|
70819
|
-
const limit = options.limit;
|
|
70820
|
-
if (limit === void 0) return filtered;
|
|
70821
|
-
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
70822
|
-
throw new Error("Receipt limit must be a non-negative integer.");
|
|
70823
|
-
return limit === 0 ? [] : filtered.slice(-limit);
|
|
70824
|
-
}
|
|
70825
|
-
function coalesceTransferReceiptRevisions(receipts) {
|
|
70826
|
-
const coalesced = [];
|
|
70827
|
-
const transferIndexes = /* @__PURE__ */ new Map();
|
|
70828
|
-
for (const receipt of receipts) {
|
|
70829
|
-
const existing = receipt.kind === "transfer" ? transferIndexes.get(receipt.id) : void 0;
|
|
70830
|
-
if (existing === void 0) {
|
|
70831
|
-
if (receipt.kind === "transfer") transferIndexes.set(receipt.id, coalesced.length);
|
|
70832
|
-
coalesced.push(receipt);
|
|
70833
|
-
} else {
|
|
70834
|
-
coalesced[existing] = receipt;
|
|
70835
|
-
}
|
|
70836
|
-
}
|
|
70837
|
-
return coalesced;
|
|
70838
|
-
}
|
|
70839
|
-
function receiptWallet(receipt) {
|
|
70840
|
-
return receipt.wallet ?? DEFAULT_WALLET_NAME;
|
|
70841
|
-
}
|
|
70842
|
-
function filterReceiptsByWallet(receipts, name) {
|
|
70843
|
-
return receipts.filter((receipt) => receiptWallet(receipt) === name);
|
|
70844
|
-
}
|
|
70845
|
-
async function renameReceiptWallet(from16, to, path = getVapiPaths().receipts) {
|
|
70846
|
-
return await withReceiptJournalLock(path, async () => {
|
|
70847
|
-
let raw;
|
|
70848
|
-
try {
|
|
70849
|
-
raw = await readFile7(path, "utf8");
|
|
70850
|
-
} catch (error61) {
|
|
70851
|
-
if (isMissingFile(error61)) return 0;
|
|
70852
|
-
throw error61;
|
|
70853
|
-
}
|
|
70854
|
-
let changed = 0;
|
|
70855
|
-
const lines = raw.split("\n").map((line, index2) => {
|
|
70856
|
-
if (line.trim().length === 0) return line;
|
|
70857
|
-
let parsed;
|
|
70858
|
-
try {
|
|
70859
|
-
parsed = JSON.parse(line);
|
|
70860
|
-
} catch (error61) {
|
|
70861
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70862
|
-
}
|
|
70863
|
-
const current = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "wallet") : void 0;
|
|
70864
|
-
if ((typeof current === "string" ? current : DEFAULT_WALLET_NAME) !== from16) return line;
|
|
70865
|
-
changed += 1;
|
|
70866
|
-
return JSON.stringify(parseReceipt({ ...parsed, wallet: to }));
|
|
70867
|
-
});
|
|
70868
|
-
if (changed === 0) return 0;
|
|
70869
|
-
await receiptTestHooks?.beforeRenameReplace?.(path);
|
|
70870
|
-
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70871
|
-
const temporaryPath = `${path}.${process.pid}.${randomBytes6(6).toString("hex")}.tmp`;
|
|
70872
|
-
await writeFile3(temporaryPath, lines.join("\n"), {
|
|
70873
|
-
encoding: "utf8",
|
|
70874
|
-
mode: 384,
|
|
70875
|
-
flag: "wx"
|
|
70876
|
-
});
|
|
70877
|
-
await rename4(temporaryPath, path);
|
|
70878
|
-
return changed;
|
|
70879
|
-
});
|
|
70880
|
-
}
|
|
70881
|
-
|
|
70882
|
-
// ../core/src/transfer-journal.ts
|
|
70883
|
-
import { readFile as readFile8 } from "node:fs/promises";
|
|
70884
|
-
async function readTransferJournal(home, from16, nonce) {
|
|
70885
|
-
let raw;
|
|
70886
|
-
try {
|
|
70887
|
-
raw = await readFile8(getVapiPaths(home).receipts, "utf8");
|
|
70888
|
-
} catch (error61) {
|
|
70889
|
-
if (isMissingFile(error61)) return { signed: false };
|
|
70890
|
-
throw error61;
|
|
70891
|
-
}
|
|
70892
|
-
let latest;
|
|
70893
|
-
let request;
|
|
70894
|
-
for (const [index2, line] of raw.split("\n").entries()) {
|
|
70895
|
-
if (!line.trim()) continue;
|
|
70896
|
-
let receipt;
|
|
70897
|
-
try {
|
|
70898
|
-
receipt = parseReceipt(JSON.parse(line));
|
|
70899
|
-
} catch (error61) {
|
|
70900
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70901
|
-
}
|
|
70902
|
-
if (receiptWallet(receipt) !== from16 || receipt.transfer?.nonce.toLowerCase() !== nonce.toLowerCase()) {
|
|
70903
|
-
continue;
|
|
70904
|
-
}
|
|
70905
|
-
latest = receipt;
|
|
70906
|
-
if (receipt.transfer.request !== void 0) request = receipt;
|
|
70907
|
-
}
|
|
70908
|
-
return {
|
|
70909
|
-
signed: latest !== void 0,
|
|
70910
|
-
...latest === void 0 ? {} : { latest },
|
|
70911
|
-
...request === void 0 ? {} : { request },
|
|
70912
|
-
...request?.transfer?.request?.authorization.validBefore === void 0 ? {} : { validBefore: request.transfer.request.authorization.validBefore },
|
|
70913
|
-
...(latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn) === void 0 ? {} : { reservedOn: latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn }
|
|
70914
|
-
};
|
|
70915
|
-
}
|
|
70916
|
-
|
|
70917
|
-
// ../core/src/vault-key.ts
|
|
70918
|
-
import { randomBytes as cryptoRandomBytes } from "node:crypto";
|
|
70919
|
-
|
|
70920
70189
|
// ../core/src/vault.ts
|
|
70921
|
-
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
70922
|
-
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";
|
|
70923
|
-
import { dirname as dirname6 } from "node:path";
|
|
70924
70190
|
var VaultError = class extends Error {
|
|
70925
70191
|
code;
|
|
70926
70192
|
constructor(code, message, options) {
|
|
@@ -71306,249 +70572,1227 @@ async function exportVaultAccountKey(args) {
|
|
|
71306
70572
|
if (privateKeyToAccount(privateKey).address.toLowerCase() !== account.address.toLowerCase()) {
|
|
71307
70573
|
throw new VaultError("corrupt", "A vault key does not match its stored address.");
|
|
71308
70574
|
}
|
|
71309
|
-
return privateKey;
|
|
71310
|
-
} catch (error61) {
|
|
71311
|
-
throw asVaultError(error61, "corrupt", "Unable to export the vault account key.");
|
|
70575
|
+
return privateKey;
|
|
70576
|
+
} catch (error61) {
|
|
70577
|
+
throw asVaultError(error61, "corrupt", "Unable to export the vault account key.");
|
|
70578
|
+
}
|
|
70579
|
+
}
|
|
70580
|
+
async function exportMemberKey(args) {
|
|
70581
|
+
return await exportVaultAccountKey(args);
|
|
70582
|
+
}
|
|
70583
|
+
function assertVaultKey(key2) {
|
|
70584
|
+
if (key2.byteLength !== 32) {
|
|
70585
|
+
throw new VaultError("bad_key", "A device vault key must contain exactly 32 bytes.");
|
|
70586
|
+
}
|
|
70587
|
+
}
|
|
70588
|
+
function assertAccountName(name) {
|
|
70589
|
+
const parsed = walletNameSchema.safeParse(name);
|
|
70590
|
+
if (!parsed.success) {
|
|
70591
|
+
throw new VaultError("name_taken", "The vault account name is not valid.", {
|
|
70592
|
+
cause: parsed.error
|
|
70593
|
+
});
|
|
70594
|
+
}
|
|
70595
|
+
}
|
|
70596
|
+
function assertAvailableName(file2, name) {
|
|
70597
|
+
assertAccountName(name);
|
|
70598
|
+
if (file2.accounts.some((account) => account.name === name)) {
|
|
70599
|
+
throw new VaultError("name_taken", "A vault account already has that name.");
|
|
70600
|
+
}
|
|
70601
|
+
}
|
|
70602
|
+
function nextDerivedIndex(file2) {
|
|
70603
|
+
let next = file2.nextDerivedIndex ?? 0;
|
|
70604
|
+
for (const account of file2.accounts) {
|
|
70605
|
+
if (account.kind === "derived") next = Math.max(next, account.index + 1);
|
|
70606
|
+
}
|
|
70607
|
+
return next;
|
|
70608
|
+
}
|
|
70609
|
+
function copyAccount(account) {
|
|
70610
|
+
if (account.kind === "derived") return { ...account };
|
|
70611
|
+
return {
|
|
70612
|
+
name: account.name,
|
|
70613
|
+
kind: account.kind,
|
|
70614
|
+
address: account.address,
|
|
70615
|
+
createdAt: account.createdAt
|
|
70616
|
+
};
|
|
70617
|
+
}
|
|
70618
|
+
function sealField(key2, plaintext) {
|
|
70619
|
+
const { nonce, ciphertext, tag } = encryptWithKey(key2, plaintext);
|
|
70620
|
+
return [nonce, ciphertext, tag].map((part) => part.toString("base64url")).join(".");
|
|
70621
|
+
}
|
|
70622
|
+
function openField(key2, value) {
|
|
70623
|
+
const [nonce = "", ciphertext = "", tag = ""] = value.split(".");
|
|
70624
|
+
return decryptWithKey(key2, {
|
|
70625
|
+
nonce: Buffer.from(nonce, "base64url"),
|
|
70626
|
+
ciphertext: Buffer.from(ciphertext, "base64url"),
|
|
70627
|
+
tag: Buffer.from(tag, "base64url")
|
|
70628
|
+
});
|
|
70629
|
+
}
|
|
70630
|
+
function decryptField(key2, value) {
|
|
70631
|
+
try {
|
|
70632
|
+
return openField(key2, value);
|
|
70633
|
+
} catch (error61) {
|
|
70634
|
+
throw new VaultError("bad_key", "Unable to decrypt the vault with this device key.", {
|
|
70635
|
+
cause: error61
|
|
70636
|
+
});
|
|
70637
|
+
}
|
|
70638
|
+
}
|
|
70639
|
+
function decryptPhraseForOpen(key2, phrase) {
|
|
70640
|
+
try {
|
|
70641
|
+
return openField(key2, phrase);
|
|
70642
|
+
} catch (error61) {
|
|
70643
|
+
throw new VaultError("bad_key", "Unable to decrypt the vault with this device key.", {
|
|
70644
|
+
cause: error61
|
|
70645
|
+
});
|
|
70646
|
+
}
|
|
70647
|
+
}
|
|
70648
|
+
function validateStoredImportedAccount(key2, account) {
|
|
70649
|
+
let plaintext;
|
|
70650
|
+
try {
|
|
70651
|
+
plaintext = decryptField(key2, account.key);
|
|
70652
|
+
if (plaintext.byteLength !== 32) {
|
|
70653
|
+
throw new VaultError("bad_key", "The stored imported key has the wrong length.");
|
|
70654
|
+
}
|
|
70655
|
+
let address4;
|
|
70656
|
+
try {
|
|
70657
|
+
address4 = privateKeyToAccount(`0x${plaintext.toString("hex")}`).address;
|
|
70658
|
+
} catch (error61) {
|
|
70659
|
+
throw new VaultError("bad_key", "The stored imported key is not valid.", {
|
|
70660
|
+
cause: error61
|
|
70661
|
+
});
|
|
70662
|
+
}
|
|
70663
|
+
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
70664
|
+
throw new VaultError("bad_key", "The stored imported key does not match its address.");
|
|
70665
|
+
}
|
|
70666
|
+
} finally {
|
|
70667
|
+
plaintext?.fill(0);
|
|
70668
|
+
}
|
|
70669
|
+
}
|
|
70670
|
+
function validateStoredDerivedAccount(key2, file2, account) {
|
|
70671
|
+
const plaintext = decryptField(key2, file2.phrase);
|
|
70672
|
+
let seed;
|
|
70673
|
+
try {
|
|
70674
|
+
seed = phraseToSeed(plaintext.toString("utf8"));
|
|
70675
|
+
const address4 = privateKeyToAccount(
|
|
70676
|
+
deriveEvmPrivateKey(seed, `m/44'/60'/0'/0/${account.index}`)
|
|
70677
|
+
).address;
|
|
70678
|
+
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
70679
|
+
throw new VaultError("bad_key", "The stored derived account does not match this vault.");
|
|
70680
|
+
}
|
|
70681
|
+
} finally {
|
|
70682
|
+
seed?.fill(0);
|
|
70683
|
+
plaintext.fill(0);
|
|
70684
|
+
}
|
|
70685
|
+
}
|
|
70686
|
+
function parseVaultFile(raw) {
|
|
70687
|
+
let value;
|
|
70688
|
+
try {
|
|
70689
|
+
value = JSON.parse(raw);
|
|
70690
|
+
} catch (error61) {
|
|
70691
|
+
throw new VaultError("corrupt", "The vault file is not valid JSON.", { cause: error61 });
|
|
70692
|
+
}
|
|
70693
|
+
const parsed = vaultFileSchema.safeParse(value);
|
|
70694
|
+
if (!parsed.success) {
|
|
70695
|
+
throw new VaultError("corrupt", "The vault file has an invalid structure.", {
|
|
70696
|
+
cause: parsed.error
|
|
70697
|
+
});
|
|
70698
|
+
}
|
|
70699
|
+
if (parsed.data.protected !== (parsed.data.wrappedKey !== void 0)) {
|
|
70700
|
+
throw new VaultError("corrupt", "The vault protection metadata is inconsistent.");
|
|
70701
|
+
}
|
|
70702
|
+
const names = /* @__PURE__ */ new Set();
|
|
70703
|
+
const indexes = /* @__PURE__ */ new Set();
|
|
70704
|
+
for (const account of parsed.data.accounts) {
|
|
70705
|
+
if (names.has(account.name)) {
|
|
70706
|
+
throw new VaultError("corrupt", "The vault file contains duplicate account names.");
|
|
70707
|
+
}
|
|
70708
|
+
names.add(account.name);
|
|
70709
|
+
if (account.kind === "derived") {
|
|
70710
|
+
if (indexes.has(account.index)) {
|
|
70711
|
+
throw new VaultError("corrupt", "The vault file contains duplicate derived indexes.");
|
|
70712
|
+
}
|
|
70713
|
+
indexes.add(account.index);
|
|
70714
|
+
}
|
|
70715
|
+
}
|
|
70716
|
+
return parsed.data;
|
|
70717
|
+
}
|
|
70718
|
+
async function readVaultFile(path, key2) {
|
|
70719
|
+
const file2 = await readVaultFileUnlocked(path);
|
|
70720
|
+
const plaintext = decryptPhraseForOpen(key2, file2.phrase);
|
|
70721
|
+
try {
|
|
70722
|
+
try {
|
|
70723
|
+
validateRecoveryPhrase(plaintext.toString("utf8"));
|
|
70724
|
+
} catch (error61) {
|
|
70725
|
+
throw new VaultError("corrupt", "The vault recovery phrase is not valid.", {
|
|
70726
|
+
cause: error61
|
|
70727
|
+
});
|
|
70728
|
+
}
|
|
70729
|
+
} finally {
|
|
70730
|
+
plaintext.fill(0);
|
|
70731
|
+
}
|
|
70732
|
+
return file2;
|
|
70733
|
+
}
|
|
70734
|
+
async function readVaultFileUnlocked(path) {
|
|
70735
|
+
let raw;
|
|
70736
|
+
try {
|
|
70737
|
+
raw = await readFile7(path, "utf8");
|
|
70738
|
+
} catch (error61) {
|
|
70739
|
+
if (isMissingFile2(error61)) {
|
|
70740
|
+
throw new VaultError("not_found", "No vault file was found at the requested path.", {
|
|
70741
|
+
cause: error61
|
|
70742
|
+
});
|
|
70743
|
+
}
|
|
70744
|
+
throw new VaultError("corrupt", "Unable to read the vault file.", { cause: error61 });
|
|
70745
|
+
}
|
|
70746
|
+
return parseVaultFile(raw);
|
|
70747
|
+
}
|
|
70748
|
+
async function refuseExistingVault(path) {
|
|
70749
|
+
try {
|
|
70750
|
+
await stat6(path);
|
|
70751
|
+
} catch (error61) {
|
|
70752
|
+
if (isMissingFile2(error61)) return;
|
|
70753
|
+
throw new VaultError("corrupt", "Unable to check whether the vault already exists.", {
|
|
70754
|
+
cause: error61
|
|
70755
|
+
});
|
|
70756
|
+
}
|
|
70757
|
+
throw new VaultError("corrupt", "A vault already exists at the requested path.");
|
|
70758
|
+
}
|
|
70759
|
+
async function writeVaultFile(path, file2) {
|
|
70760
|
+
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70761
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes5(6).toString("hex")}.tmp`;
|
|
70762
|
+
try {
|
|
70763
|
+
await writeFile3(temporaryPath, `${JSON.stringify(file2, null, 2)}
|
|
70764
|
+
`, {
|
|
70765
|
+
encoding: "utf8",
|
|
70766
|
+
mode: 384,
|
|
70767
|
+
flag: "wx"
|
|
70768
|
+
});
|
|
70769
|
+
await rename4(temporaryPath, path);
|
|
70770
|
+
} catch (error61) {
|
|
70771
|
+
await rm(temporaryPath, { force: true }).catch(() => void 0);
|
|
70772
|
+
throw error61;
|
|
70773
|
+
}
|
|
70774
|
+
}
|
|
70775
|
+
async function withVaultLock(path, operation) {
|
|
70776
|
+
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70777
|
+
const lockPath = `${path}.lock`;
|
|
70778
|
+
const deadline = Date.now() + VAULT_LOCK_TIMEOUT_MS;
|
|
70779
|
+
let handle;
|
|
70780
|
+
while (!handle) {
|
|
70781
|
+
try {
|
|
70782
|
+
handle = await open5(lockPath, "wx", 384);
|
|
70783
|
+
} catch (error61) {
|
|
70784
|
+
if (!isExistingFile(error61)) throw error61;
|
|
70785
|
+
await removeStaleVaultLock(lockPath);
|
|
70786
|
+
if (Date.now() >= deadline) {
|
|
70787
|
+
throw new VaultError("corrupt", "Timed out waiting for the vault lock.");
|
|
70788
|
+
}
|
|
70789
|
+
await new Promise((resolve3) => setTimeout(resolve3, 20));
|
|
70790
|
+
}
|
|
70791
|
+
}
|
|
70792
|
+
try {
|
|
70793
|
+
return await operation();
|
|
70794
|
+
} finally {
|
|
70795
|
+
await handle.close();
|
|
70796
|
+
await unlink4(lockPath).catch(() => void 0);
|
|
70797
|
+
}
|
|
70798
|
+
}
|
|
70799
|
+
async function removeStaleVaultLock(path) {
|
|
70800
|
+
try {
|
|
70801
|
+
const metadata = await stat6(path);
|
|
70802
|
+
if (Date.now() - metadata.mtimeMs > STALE_VAULT_LOCK_MS) await unlink4(path);
|
|
70803
|
+
} catch (error61) {
|
|
70804
|
+
if (!isMissingFile2(error61)) throw error61;
|
|
70805
|
+
}
|
|
70806
|
+
}
|
|
70807
|
+
function isMissingFile2(error61) {
|
|
70808
|
+
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "ENOENT";
|
|
70809
|
+
}
|
|
70810
|
+
function isExistingFile(error61) {
|
|
70811
|
+
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "EEXIST";
|
|
70812
|
+
}
|
|
70813
|
+
function asVaultError(error61, code, message) {
|
|
70814
|
+
return error61 instanceof VaultError ? error61 : new VaultError(code, message, { cause: error61 });
|
|
70815
|
+
}
|
|
70816
|
+
|
|
70817
|
+
// ../core/src/file-secret-store.ts
|
|
70818
|
+
var FILE_SECRET_STORE_PASSWORD_ENV = "VAPI_VAULT_PASSWORD";
|
|
70819
|
+
var FILE_SECRET_STORE_MIN_PASSWORD = 12;
|
|
70820
|
+
var CHECK_VALUE = "vapi-network file secret store";
|
|
70821
|
+
var sealedSchema = external_exports.object({ nonce: external_exports.string(), ciphertext: external_exports.string(), tag: external_exports.string() }).strict();
|
|
70822
|
+
var fileSchema = external_exports.object({
|
|
70823
|
+
v: external_exports.literal(1),
|
|
70824
|
+
salt: external_exports.string(),
|
|
70825
|
+
check: sealedSchema,
|
|
70826
|
+
entries: external_exports.record(external_exports.string(), sealedSchema)
|
|
70827
|
+
}).strict();
|
|
70828
|
+
async function createFileSecretStore(options) {
|
|
70829
|
+
const password = passwordFrom(options.env);
|
|
70830
|
+
if (password.length < FILE_SECRET_STORE_MIN_PASSWORD) {
|
|
70831
|
+
throw new KeystoreError(
|
|
70832
|
+
`${FILE_SECRET_STORE_PASSWORD_ENV} must be at least ${FILE_SECRET_STORE_MIN_PASSWORD} characters.`
|
|
70833
|
+
);
|
|
70834
|
+
}
|
|
70835
|
+
await withVaultLock(options.path, async () => {
|
|
70836
|
+
let exists = true;
|
|
70837
|
+
try {
|
|
70838
|
+
await stat7(options.path);
|
|
70839
|
+
} catch (error61) {
|
|
70840
|
+
if (!isMissingFile(error61)) throw error61;
|
|
70841
|
+
exists = false;
|
|
70842
|
+
}
|
|
70843
|
+
if (exists) {
|
|
70844
|
+
await withKey(options.path, options.env, async () => void 0);
|
|
70845
|
+
return;
|
|
70846
|
+
}
|
|
70847
|
+
const salt = randomBytes6(32);
|
|
70848
|
+
const key2 = await deriveScryptKey(password, salt);
|
|
70849
|
+
try {
|
|
70850
|
+
await writeJsonAtomic(
|
|
70851
|
+
options.path,
|
|
70852
|
+
{
|
|
70853
|
+
v: 1,
|
|
70854
|
+
salt: salt.toString("base64"),
|
|
70855
|
+
check: seal(key2, CHECK_VALUE),
|
|
70856
|
+
entries: {}
|
|
70857
|
+
},
|
|
70858
|
+
{ mode: 384 }
|
|
70859
|
+
);
|
|
70860
|
+
} finally {
|
|
70861
|
+
key2.fill(0);
|
|
70862
|
+
}
|
|
70863
|
+
});
|
|
70864
|
+
}
|
|
70865
|
+
function fileSecretStore(options) {
|
|
70866
|
+
const env = options.env ?? process.env;
|
|
70867
|
+
const write2 = async (change) => await withVaultLock(
|
|
70868
|
+
options.path,
|
|
70869
|
+
async () => await withKey(options.path, env, async (file2, key2) => {
|
|
70870
|
+
const changed = change(file2, key2);
|
|
70871
|
+
if (changed) await writeJsonAtomic(options.path, file2, { mode: 384 });
|
|
70872
|
+
return changed;
|
|
70873
|
+
})
|
|
70874
|
+
);
|
|
70875
|
+
const get = async (name) => await withKey(options.path, env, async (file2, key2) => {
|
|
70876
|
+
const sealed = Object.hasOwn(file2.entries, name) ? file2.entries[name] : void 0;
|
|
70877
|
+
return sealed === void 0 ? void 0 : open6(key2, sealed);
|
|
70878
|
+
});
|
|
70879
|
+
return {
|
|
70880
|
+
// A locked backend still exists; it must never enable a plaintext fallback.
|
|
70881
|
+
available: true,
|
|
70882
|
+
platform: process.platform,
|
|
70883
|
+
description: "the encrypted vAPI secrets file",
|
|
70884
|
+
get,
|
|
70885
|
+
async has(name) {
|
|
70886
|
+
return await get(name) !== void 0;
|
|
70887
|
+
},
|
|
70888
|
+
async set(name, value) {
|
|
70889
|
+
if (name === "__proto__") {
|
|
70890
|
+
throw new KeystoreError("The secret name is reserved in the encrypted vAPI secrets file.");
|
|
70891
|
+
}
|
|
70892
|
+
await write2((file2, key2) => {
|
|
70893
|
+
file2.entries[name] = seal(key2, value);
|
|
70894
|
+
return true;
|
|
70895
|
+
});
|
|
70896
|
+
},
|
|
70897
|
+
async remove(name) {
|
|
70898
|
+
return await write2((file2) => {
|
|
70899
|
+
if (!Object.hasOwn(file2.entries, name)) return false;
|
|
70900
|
+
delete file2.entries[name];
|
|
70901
|
+
return true;
|
|
70902
|
+
});
|
|
70903
|
+
}
|
|
70904
|
+
};
|
|
70905
|
+
}
|
|
70906
|
+
async function withKey(path, env, operation) {
|
|
70907
|
+
const file2 = await readStoredFile(path);
|
|
70908
|
+
const key2 = await deriveScryptKey(passwordFrom(env), Buffer.from(file2.salt, "base64"));
|
|
70909
|
+
try {
|
|
70910
|
+
if (open6(key2, file2.check) !== CHECK_VALUE) throw wrongPassword();
|
|
70911
|
+
return await operation(file2, key2);
|
|
70912
|
+
} finally {
|
|
70913
|
+
key2.fill(0);
|
|
70914
|
+
}
|
|
70915
|
+
}
|
|
70916
|
+
function passwordFrom(env) {
|
|
70917
|
+
const password = (env ?? process.env)[FILE_SECRET_STORE_PASSWORD_ENV];
|
|
70918
|
+
if (!password) {
|
|
70919
|
+
throw new KeystoreError(
|
|
70920
|
+
`This vault keeps its secrets in an encrypted file. Set ${FILE_SECRET_STORE_PASSWORD_ENV} to open it.`
|
|
70921
|
+
);
|
|
70922
|
+
}
|
|
70923
|
+
return password;
|
|
70924
|
+
}
|
|
70925
|
+
async function readStoredFile(path) {
|
|
70926
|
+
let raw;
|
|
70927
|
+
try {
|
|
70928
|
+
raw = await readFile8(path, "utf8");
|
|
70929
|
+
} catch (error61) {
|
|
70930
|
+
throw new KeystoreError("The vAPI secrets file is missing. Run vapi setup again.", {
|
|
70931
|
+
cause: error61
|
|
70932
|
+
});
|
|
70933
|
+
}
|
|
70934
|
+
let value;
|
|
70935
|
+
try {
|
|
70936
|
+
value = JSON.parse(raw);
|
|
70937
|
+
} catch {
|
|
70938
|
+
throw new KeystoreError("The vAPI secrets file is damaged.");
|
|
70939
|
+
}
|
|
70940
|
+
const parsed = fileSchema.safeParse(value);
|
|
70941
|
+
if (!parsed.success) throw new KeystoreError("The vAPI secrets file is damaged.");
|
|
70942
|
+
return parsed.data;
|
|
70943
|
+
}
|
|
70944
|
+
function seal(key2, value) {
|
|
70945
|
+
const { nonce, ciphertext, tag } = encryptWithKey(key2, Buffer.from(value, "utf8"));
|
|
70946
|
+
return {
|
|
70947
|
+
nonce: nonce.toString("base64"),
|
|
70948
|
+
ciphertext: ciphertext.toString("base64"),
|
|
70949
|
+
tag: tag.toString("base64")
|
|
70950
|
+
};
|
|
70951
|
+
}
|
|
70952
|
+
function open6(key2, sealed) {
|
|
70953
|
+
try {
|
|
70954
|
+
return decryptWithKey(key2, {
|
|
70955
|
+
nonce: Buffer.from(sealed.nonce, "base64"),
|
|
70956
|
+
ciphertext: Buffer.from(sealed.ciphertext, "base64"),
|
|
70957
|
+
tag: Buffer.from(sealed.tag, "base64")
|
|
70958
|
+
}).toString("utf8");
|
|
70959
|
+
} catch (error61) {
|
|
70960
|
+
throw wrongPassword(error61);
|
|
70961
|
+
}
|
|
70962
|
+
}
|
|
70963
|
+
function wrongPassword(cause) {
|
|
70964
|
+
return new KeystoreError(`Wrong ${FILE_SECRET_STORE_PASSWORD_ENV} for the vAPI secrets file.`, {
|
|
70965
|
+
cause
|
|
70966
|
+
});
|
|
70967
|
+
}
|
|
70968
|
+
|
|
70969
|
+
// ../core/src/secret-backend.ts
|
|
70970
|
+
import { readFileSync } from "node:fs";
|
|
70971
|
+
import { stat as stat8 } from "node:fs/promises";
|
|
70972
|
+
import { join as join6 } from "node:path";
|
|
70973
|
+
var PROBE_ACCOUNT = "setup-probe";
|
|
70974
|
+
var pinSchema = external_exports.object({ v: external_exports.literal(1), backend: external_exports.enum(["os", "file"]) }).strict();
|
|
70975
|
+
function secretBackendPath(home = getVapiPaths().directory) {
|
|
70976
|
+
return join6(home, "secret-store.json");
|
|
70977
|
+
}
|
|
70978
|
+
function secretsFilePath(home = getVapiPaths().directory) {
|
|
70979
|
+
return join6(home, "secrets.json");
|
|
70980
|
+
}
|
|
70981
|
+
function readSecretBackend(home = getVapiPaths().directory) {
|
|
70982
|
+
const path = secretBackendPath(home);
|
|
70983
|
+
try {
|
|
70984
|
+
const parsed = pinSchema.safeParse(JSON.parse(readFileSync(path, "utf8")));
|
|
70985
|
+
if (parsed.success) return parsed.data.backend;
|
|
70986
|
+
} catch (error61) {
|
|
70987
|
+
if (isMissingFile(error61)) return "os";
|
|
70988
|
+
}
|
|
70989
|
+
throw new KeystoreError(`The vAPI secret-store pin at ${path} is damaged.`);
|
|
70990
|
+
}
|
|
70991
|
+
async function chooseSecretBackend(options) {
|
|
70992
|
+
const env = options.env ?? process.env;
|
|
70993
|
+
const osWorks = options.os.platform !== "linux" || await osStoreWorks(options.os);
|
|
70994
|
+
const path = secretBackendPath(options.home);
|
|
70995
|
+
return await withVaultLock(path, async () => {
|
|
70996
|
+
if (await fileExists(path)) return readSecretBackend(options.home);
|
|
70997
|
+
if (await fileExists(join6(options.home, "vault.json"))) return "os";
|
|
70998
|
+
let backend;
|
|
70999
|
+
if (osWorks) {
|
|
71000
|
+
backend = "os";
|
|
71001
|
+
} else if (env[FILE_SECRET_STORE_PASSWORD_ENV]) {
|
|
71002
|
+
await createFileSecretStore({ path: secretsFilePath(options.home), env });
|
|
71003
|
+
backend = "file";
|
|
71004
|
+
} else {
|
|
71005
|
+
throw new KeystoreError(
|
|
71006
|
+
[
|
|
71007
|
+
`This machine has no working keyring (${options.os.description}).`,
|
|
71008
|
+
`Set ${FILE_SECRET_STORE_PASSWORD_ENV} (at least ${FILE_SECRET_STORE_MIN_PASSWORD} characters; in a GitHub Codespace add it as a Codespaces secret) and run vapi setup again,`,
|
|
71009
|
+
"or run vapi on your own computer, or connect Claude from https://api.vapinetwork.ai/connect."
|
|
71010
|
+
].join(" ")
|
|
71011
|
+
);
|
|
71012
|
+
}
|
|
71013
|
+
await writeJsonAtomic(path, { v: 1, backend }, { mode: 384 });
|
|
71014
|
+
return backend;
|
|
71015
|
+
});
|
|
71016
|
+
}
|
|
71017
|
+
async function fileExists(path) {
|
|
71018
|
+
try {
|
|
71019
|
+
await stat8(path);
|
|
71020
|
+
return true;
|
|
71021
|
+
} catch (error61) {
|
|
71022
|
+
if (isMissingFile(error61)) return false;
|
|
71023
|
+
throw error61;
|
|
71024
|
+
}
|
|
71025
|
+
}
|
|
71026
|
+
async function osStoreWorks(store) {
|
|
71027
|
+
if (!store.available) return false;
|
|
71028
|
+
try {
|
|
71029
|
+
try {
|
|
71030
|
+
await store.set(PROBE_ACCOUNT, "ok");
|
|
71031
|
+
return await store.get(PROBE_ACCOUNT) === "ok";
|
|
71032
|
+
} finally {
|
|
71033
|
+
await store.remove(PROBE_ACCOUNT);
|
|
71034
|
+
}
|
|
71035
|
+
} catch {
|
|
71036
|
+
return false;
|
|
71037
|
+
}
|
|
71038
|
+
}
|
|
71039
|
+
|
|
71040
|
+
// ../core/src/secret-store.ts
|
|
71041
|
+
var SECRET_STORE_SERVICE = "vapi-network";
|
|
71042
|
+
var SECURITY_BINARY = "/usr/bin/security";
|
|
71043
|
+
var SECRET_TOOL_BINARY = "secret-tool";
|
|
71044
|
+
var WINDOWS_POWERSHELL_ARGS = ["-NoProfile", "-NonInteractive", "-Command", "-"];
|
|
71045
|
+
var SECURITY_ITEM_NOT_FOUND = 44;
|
|
71046
|
+
var WINDOWS_SECRET_SUCCESS = 0;
|
|
71047
|
+
var WINDOWS_SECRET_NOT_FOUND = 2;
|
|
71048
|
+
var UNSUPPORTED_PLATFORM = "No OS secret store on this platform yet; use VAPI_KEYSTORE_PASSWORD.";
|
|
71049
|
+
var SECRET_TOOL_MISSING = [
|
|
71050
|
+
"secret-tool is not installed, so the passphrase cannot be kept in the OS secret store.",
|
|
71051
|
+
"Install libsecret-tools (Debian, Ubuntu) or libsecret (Fedora, Arch), or use VAPI_KEYSTORE_PASSWORD."
|
|
71052
|
+
].join(" ");
|
|
71053
|
+
var POWERSHELL_MISSING = [
|
|
71054
|
+
"Windows PowerShell (powershell.exe) was not found, so the passphrase cannot be kept in the OS secret store.",
|
|
71055
|
+
"Use VAPI_KEYSTORE_PASSWORD."
|
|
71056
|
+
].join(" ");
|
|
71057
|
+
function secretStore(options = {}) {
|
|
71058
|
+
const home = options.home ?? getVapiPaths().directory;
|
|
71059
|
+
if (readSecretBackend(home) === "file") {
|
|
71060
|
+
return fileSecretStore({ path: secretsFilePath(home), env: options.env ?? process.env });
|
|
71061
|
+
}
|
|
71062
|
+
return osSecretStore(options);
|
|
71063
|
+
}
|
|
71064
|
+
function osSecretStore(options = {}) {
|
|
71065
|
+
const platform2 = options.platform ?? process.platform;
|
|
71066
|
+
const run = options.run ?? (async (file2, args, input2) => await spawnRunner(platform2, file2, args, input2));
|
|
71067
|
+
const env = options.env ?? process.env;
|
|
71068
|
+
const installed = options.installed ?? ((file2) => binaryInstalled(file2, env));
|
|
71069
|
+
if (platform2 === "darwin") return keychainStore(platform2, run);
|
|
71070
|
+
if (platform2 === "win32") return windowsDataProtectionStore(platform2, run, env, installed);
|
|
71071
|
+
if (platform2 === "linux") return libsecretStore(platform2, run, installed);
|
|
71072
|
+
return unsupportedStore(platform2);
|
|
71073
|
+
}
|
|
71074
|
+
function memorySecretStore(initial = {}) {
|
|
71075
|
+
const entries = new Map(Object.entries(initial));
|
|
71076
|
+
return {
|
|
71077
|
+
available: true,
|
|
71078
|
+
platform: process.platform,
|
|
71079
|
+
description: "an in-memory store",
|
|
71080
|
+
async get(name) {
|
|
71081
|
+
return entries.get(name);
|
|
71082
|
+
},
|
|
71083
|
+
async has(name) {
|
|
71084
|
+
return entries.has(name);
|
|
71085
|
+
},
|
|
71086
|
+
async set(name, passphrase) {
|
|
71087
|
+
entries.set(name, passphrase);
|
|
71088
|
+
},
|
|
71089
|
+
async remove(name) {
|
|
71090
|
+
return entries.delete(name);
|
|
71091
|
+
},
|
|
71092
|
+
async list() {
|
|
71093
|
+
return [...entries.keys()].sort();
|
|
71094
|
+
}
|
|
71095
|
+
};
|
|
71096
|
+
}
|
|
71097
|
+
function keychainStore(platform2, run) {
|
|
71098
|
+
const find = async (account, withPassword) => await run(SECURITY_BINARY, [
|
|
71099
|
+
"find-generic-password",
|
|
71100
|
+
"-a",
|
|
71101
|
+
account,
|
|
71102
|
+
"-s",
|
|
71103
|
+
SECRET_STORE_SERVICE,
|
|
71104
|
+
...withPassword ? ["-w"] : []
|
|
71105
|
+
]);
|
|
71106
|
+
const read = async (account, what) => {
|
|
71107
|
+
const result = await find(account, true);
|
|
71108
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return void 0;
|
|
71109
|
+
requireSuccess(result, what);
|
|
71110
|
+
const value = withoutTrailingNewline(result.stdout);
|
|
71111
|
+
return value.length === 0 ? void 0 : value;
|
|
71112
|
+
};
|
|
71113
|
+
const write2 = async (account, value, what) => {
|
|
71114
|
+
const result = await run(
|
|
71115
|
+
SECURITY_BINARY,
|
|
71116
|
+
[
|
|
71117
|
+
"add-generic-password",
|
|
71118
|
+
"-a",
|
|
71119
|
+
account,
|
|
71120
|
+
"-s",
|
|
71121
|
+
SECRET_STORE_SERVICE,
|
|
71122
|
+
"-l",
|
|
71123
|
+
`${SECRET_STORE_SERVICE} ${account}`,
|
|
71124
|
+
"-U",
|
|
71125
|
+
"-w"
|
|
71126
|
+
],
|
|
71127
|
+
// `security` asks for the password and then for its confirmation.
|
|
71128
|
+
`${value}
|
|
71129
|
+
${value}
|
|
71130
|
+
`
|
|
71131
|
+
);
|
|
71132
|
+
requireSuccess(result, what);
|
|
71133
|
+
};
|
|
71134
|
+
const erase = async (account, what) => {
|
|
71135
|
+
const result = await run(SECURITY_BINARY, [
|
|
71136
|
+
"delete-generic-password",
|
|
71137
|
+
"-a",
|
|
71138
|
+
account,
|
|
71139
|
+
"-s",
|
|
71140
|
+
SECRET_STORE_SERVICE
|
|
71141
|
+
]);
|
|
71142
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71143
|
+
requireSuccess(result, what);
|
|
71144
|
+
return true;
|
|
71145
|
+
};
|
|
71146
|
+
const erasePartsAfter = async (account, keep, what) => {
|
|
71147
|
+
for (let part = keep + 1; part <= MAX_KEYCHAIN_PARTS; part += 1) {
|
|
71148
|
+
if (!await erase(keychainPart(account, part), what)) return;
|
|
71149
|
+
}
|
|
71150
|
+
};
|
|
71151
|
+
return {
|
|
71152
|
+
available: true,
|
|
71153
|
+
platform: platform2,
|
|
71154
|
+
description: "the macOS Keychain",
|
|
71155
|
+
async get(name) {
|
|
71156
|
+
const account = accountFor(name);
|
|
71157
|
+
const what = `read the passphrase of ${name} from the macOS Keychain`;
|
|
71158
|
+
const value = await read(account, what);
|
|
71159
|
+
const parts = value === void 0 ? void 0 : chunkedPartCount(value);
|
|
71160
|
+
if (value === void 0 || parts === void 0) return value;
|
|
71161
|
+
let joined = "";
|
|
71162
|
+
for (let part = 1; part <= parts; part += 1) {
|
|
71163
|
+
const chunk = await read(keychainPart(account, part), what);
|
|
71164
|
+
if (chunk === void 0) {
|
|
71165
|
+
throw new KeystoreError(
|
|
71166
|
+
`The stored secret ${name} is incomplete in the macOS Keychain. Store it again.`
|
|
71167
|
+
);
|
|
71168
|
+
}
|
|
71169
|
+
joined += chunk;
|
|
71170
|
+
}
|
|
71171
|
+
return joined;
|
|
71172
|
+
},
|
|
71173
|
+
async has(name) {
|
|
71174
|
+
const result = await find(accountFor(name), false);
|
|
71175
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71176
|
+
requireSuccess(result, `look up ${name} in the macOS Keychain`);
|
|
71177
|
+
return true;
|
|
71178
|
+
},
|
|
71179
|
+
async set(name, passphrase) {
|
|
71180
|
+
requirePassphrase(passphrase);
|
|
71181
|
+
const account = accountFor(name);
|
|
71182
|
+
const what = `store the passphrase of ${name} in the macOS Keychain`;
|
|
71183
|
+
if (passphrase.length <= KEYCHAIN_PROMPT_LIMIT) {
|
|
71184
|
+
await write2(account, passphrase, what);
|
|
71185
|
+
return;
|
|
71186
|
+
}
|
|
71187
|
+
const chunks = [];
|
|
71188
|
+
for (let index2 = 0; index2 < passphrase.length; index2 += KEYCHAIN_CHUNK) {
|
|
71189
|
+
chunks.push(passphrase.slice(index2, index2 + KEYCHAIN_CHUNK));
|
|
71190
|
+
}
|
|
71191
|
+
if (chunks.length > MAX_KEYCHAIN_PARTS) {
|
|
71192
|
+
throw new KeystoreError(`The secret ${name} is too long for the macOS Keychain.`);
|
|
71193
|
+
}
|
|
71194
|
+
for (const [index2, chunk] of chunks.entries()) {
|
|
71195
|
+
await write2(keychainPart(account, index2 + 1), chunk, what);
|
|
71196
|
+
}
|
|
71197
|
+
await erasePartsAfter(account, chunks.length, what);
|
|
71198
|
+
await write2(account, `${CHUNKED_MARKER}${chunks.length}`, what);
|
|
71199
|
+
},
|
|
71200
|
+
async remove(name) {
|
|
71201
|
+
const account = accountFor(name);
|
|
71202
|
+
const what = `remove the passphrase of ${name} from the macOS Keychain`;
|
|
71203
|
+
const found = await find(account, true);
|
|
71204
|
+
if (found.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71205
|
+
requireSuccess(found, what);
|
|
71206
|
+
if (chunkedPartCount(withoutTrailingNewline(found.stdout)) !== void 0) {
|
|
71207
|
+
await erasePartsAfter(account, 0, what);
|
|
71208
|
+
}
|
|
71209
|
+
return await erase(account, what);
|
|
71210
|
+
}
|
|
71211
|
+
};
|
|
71212
|
+
}
|
|
71213
|
+
var KEYCHAIN_PROMPT_LIMIT = 128;
|
|
71214
|
+
var KEYCHAIN_CHUNK = 120;
|
|
71215
|
+
var MAX_KEYCHAIN_PARTS = 32;
|
|
71216
|
+
var CHUNKED_MARKER = "vapi-chunked:v1:";
|
|
71217
|
+
function keychainPart(account, part) {
|
|
71218
|
+
return `${account}#${part}`;
|
|
71219
|
+
}
|
|
71220
|
+
function chunkedPartCount(value) {
|
|
71221
|
+
if (!value.startsWith(CHUNKED_MARKER)) return void 0;
|
|
71222
|
+
const parts = Number(value.slice(CHUNKED_MARKER.length));
|
|
71223
|
+
return Number.isInteger(parts) && parts > 0 && parts <= MAX_KEYCHAIN_PARTS ? parts : void 0;
|
|
71224
|
+
}
|
|
71225
|
+
function windowsSecretFileName(account) {
|
|
71226
|
+
let encoded = "";
|
|
71227
|
+
for (let index2 = 0; index2 < account.length; index2 += 1) {
|
|
71228
|
+
const character = account[index2];
|
|
71229
|
+
if (/^[a-z0-9._#-]$/u.test(character)) {
|
|
71230
|
+
encoded += character;
|
|
71231
|
+
continue;
|
|
71232
|
+
}
|
|
71233
|
+
encoded += `%${account.charCodeAt(index2).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
71234
|
+
}
|
|
71235
|
+
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu.test(encoded)) {
|
|
71236
|
+
encoded = `%${encoded.charCodeAt(0).toString(16).toUpperCase()}${encoded.slice(1)}`;
|
|
71237
|
+
}
|
|
71238
|
+
return `${encoded}.bin`;
|
|
71239
|
+
}
|
|
71240
|
+
function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
71241
|
+
const powershell = `${env.SystemRoot ?? "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
71242
|
+
const fileDetails = (name) => {
|
|
71243
|
+
const file2 = windowsSecretFileName(accountFor(name));
|
|
71244
|
+
return { file: file2, account: file2.slice(0, -".bin".length) };
|
|
71245
|
+
};
|
|
71246
|
+
const script = (file2, operations) => [
|
|
71247
|
+
"$ErrorActionPreference = 'Stop'",
|
|
71248
|
+
"try {",
|
|
71249
|
+
" Add-Type -AssemblyName System.Security",
|
|
71250
|
+
" $dir = Join-Path $env:LOCALAPPDATA 'vapi-network\\secrets'",
|
|
71251
|
+
` $path = Join-Path $dir '${file2}'`,
|
|
71252
|
+
...operations.map((operation) => ` ${operation}`),
|
|
71253
|
+
"} catch {",
|
|
71254
|
+
" [Console]::Error.WriteLine($_.Exception.Message)",
|
|
71255
|
+
" exit 1",
|
|
71256
|
+
"}"
|
|
71257
|
+
].join("\n");
|
|
71258
|
+
const execute = async (script2) => {
|
|
71259
|
+
const result = await run(powershell, WINDOWS_POWERSHELL_ARGS, `${script2}
|
|
71260
|
+
|
|
71261
|
+
`);
|
|
71262
|
+
requirePowerShell(result);
|
|
71263
|
+
return result;
|
|
71264
|
+
};
|
|
71265
|
+
return {
|
|
71266
|
+
available: installed(powershell),
|
|
71267
|
+
platform: platform2,
|
|
71268
|
+
description: "Windows Data Protection (DPAPI)",
|
|
71269
|
+
async get(name) {
|
|
71270
|
+
const { file: file2, account } = fileDetails(name);
|
|
71271
|
+
const result = await execute(
|
|
71272
|
+
script(file2, [
|
|
71273
|
+
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
71274
|
+
"$blob = [System.IO.File]::ReadAllBytes($path)",
|
|
71275
|
+
"$bytes = [System.Security.Cryptography.ProtectedData]::Unprotect($blob, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
71276
|
+
"[Console]::Out.Write([Convert]::ToBase64String($bytes))",
|
|
71277
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71278
|
+
])
|
|
71279
|
+
);
|
|
71280
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return void 0;
|
|
71281
|
+
requireSuccess(result, `read the passphrase of ${name} from Windows Data Protection`);
|
|
71282
|
+
const value = Buffer.from(result.stdout.trim(), "base64").toString("utf8");
|
|
71283
|
+
return value.length === 0 ? void 0 : value;
|
|
71284
|
+
},
|
|
71285
|
+
async has(name) {
|
|
71286
|
+
const { file: file2, account } = fileDetails(name);
|
|
71287
|
+
const result = await execute(
|
|
71288
|
+
script(file2, [
|
|
71289
|
+
`if (Test-Path -LiteralPath $path) { exit ${WINDOWS_SECRET_SUCCESS} }`,
|
|
71290
|
+
`[Console]::Error.WriteLine('No stored secret for ${account}.')`,
|
|
71291
|
+
`exit ${WINDOWS_SECRET_NOT_FOUND}`
|
|
71292
|
+
])
|
|
71293
|
+
);
|
|
71294
|
+
if (result.code === WINDOWS_SECRET_SUCCESS) return true;
|
|
71295
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
71296
|
+
requireSuccess(result, `look up ${name} in Windows Data Protection`);
|
|
71297
|
+
return false;
|
|
71298
|
+
},
|
|
71299
|
+
async set(name, passphrase) {
|
|
71300
|
+
requirePassphrase(passphrase);
|
|
71301
|
+
const { file: file2 } = fileDetails(name);
|
|
71302
|
+
const value = Buffer.from(passphrase, "utf8").toString("base64");
|
|
71303
|
+
const result = await execute(
|
|
71304
|
+
script(file2, [
|
|
71305
|
+
"[void][System.IO.Directory]::CreateDirectory($dir)",
|
|
71306
|
+
`$bytes = [Convert]::FromBase64String('${value}')`,
|
|
71307
|
+
"$blob = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
71308
|
+
"[System.IO.File]::WriteAllBytes($path, $blob)",
|
|
71309
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71310
|
+
])
|
|
71311
|
+
);
|
|
71312
|
+
requireSuccess(result, `store the passphrase of ${name} in Windows Data Protection`);
|
|
71313
|
+
},
|
|
71314
|
+
async remove(name) {
|
|
71315
|
+
const { file: file2, account } = fileDetails(name);
|
|
71316
|
+
const result = await execute(
|
|
71317
|
+
script(file2, [
|
|
71318
|
+
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
71319
|
+
"Remove-Item -LiteralPath $path -Force",
|
|
71320
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71321
|
+
])
|
|
71322
|
+
);
|
|
71323
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
71324
|
+
requireSuccess(result, `remove the passphrase of ${name} from Windows Data Protection`);
|
|
71325
|
+
return true;
|
|
71326
|
+
}
|
|
71327
|
+
};
|
|
71328
|
+
}
|
|
71329
|
+
function libsecretStore(platform2, run, installed) {
|
|
71330
|
+
const lookup2 = async (name) => {
|
|
71331
|
+
const result = await run(SECRET_TOOL_BINARY, [
|
|
71332
|
+
"lookup",
|
|
71333
|
+
"service",
|
|
71334
|
+
SECRET_STORE_SERVICE,
|
|
71335
|
+
"account",
|
|
71336
|
+
accountFor(name)
|
|
71337
|
+
]);
|
|
71338
|
+
requireBinary(result);
|
|
71339
|
+
const value = withoutTrailingNewline(result.stdout);
|
|
71340
|
+
if (result.code === 0) return value.length === 0 ? void 0 : value;
|
|
71341
|
+
if (result.stderr.trim().length === 0) return void 0;
|
|
71342
|
+
requireSuccess(result, `read the passphrase of ${name} from the secret service`);
|
|
71343
|
+
return void 0;
|
|
71344
|
+
};
|
|
71345
|
+
return {
|
|
71346
|
+
available: installed(SECRET_TOOL_BINARY),
|
|
71347
|
+
platform: platform2,
|
|
71348
|
+
description: "the libsecret keyring",
|
|
71349
|
+
get: lookup2,
|
|
71350
|
+
async has(name) {
|
|
71351
|
+
return await lookup2(name) !== void 0;
|
|
71352
|
+
},
|
|
71353
|
+
async set(name, passphrase) {
|
|
71354
|
+
requirePassphrase(passphrase);
|
|
71355
|
+
const account = accountFor(name);
|
|
71356
|
+
const result = await run(
|
|
71357
|
+
SECRET_TOOL_BINARY,
|
|
71358
|
+
[
|
|
71359
|
+
"store",
|
|
71360
|
+
`--label=${SECRET_STORE_SERVICE} ${account}`,
|
|
71361
|
+
"service",
|
|
71362
|
+
SECRET_STORE_SERVICE,
|
|
71363
|
+
"account",
|
|
71364
|
+
account
|
|
71365
|
+
],
|
|
71366
|
+
`${passphrase}
|
|
71367
|
+
`
|
|
71368
|
+
);
|
|
71369
|
+
requireBinary(result);
|
|
71370
|
+
requireSuccess(result, `store the passphrase of ${name} in the secret service`);
|
|
71371
|
+
},
|
|
71372
|
+
async remove(name) {
|
|
71373
|
+
const existed = await lookup2(name) !== void 0;
|
|
71374
|
+
const result = await run(SECRET_TOOL_BINARY, [
|
|
71375
|
+
"clear",
|
|
71376
|
+
"service",
|
|
71377
|
+
SECRET_STORE_SERVICE,
|
|
71378
|
+
"account",
|
|
71379
|
+
accountFor(name)
|
|
71380
|
+
]);
|
|
71381
|
+
requireBinary(result);
|
|
71382
|
+
requireSuccess(result, `remove the passphrase of ${name} from the secret service`);
|
|
71383
|
+
return existed;
|
|
71384
|
+
}
|
|
71385
|
+
};
|
|
71386
|
+
}
|
|
71387
|
+
function unsupportedStore(platform2) {
|
|
71388
|
+
const refuse = () => {
|
|
71389
|
+
throw new KeystoreError(UNSUPPORTED_PLATFORM);
|
|
71390
|
+
};
|
|
71391
|
+
return {
|
|
71392
|
+
available: false,
|
|
71393
|
+
platform: platform2,
|
|
71394
|
+
description: "no OS secret store",
|
|
71395
|
+
get: async () => refuse(),
|
|
71396
|
+
has: async () => refuse(),
|
|
71397
|
+
set: async () => refuse(),
|
|
71398
|
+
remove: async () => refuse()
|
|
71399
|
+
};
|
|
71400
|
+
}
|
|
71401
|
+
function accountFor(name) {
|
|
71402
|
+
const account = name.trim();
|
|
71403
|
+
if (account.length === 0) {
|
|
71404
|
+
throw new KeystoreError("A wallet name is needed to reach the OS secret store.");
|
|
71405
|
+
}
|
|
71406
|
+
return account;
|
|
71407
|
+
}
|
|
71408
|
+
function requirePassphrase(passphrase) {
|
|
71409
|
+
if (passphrase.length === 0) {
|
|
71410
|
+
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
71411
|
+
}
|
|
71412
|
+
}
|
|
71413
|
+
function requireBinary(result) {
|
|
71414
|
+
if (result.notFound === true) throw new KeystoreError(SECRET_TOOL_MISSING);
|
|
71415
|
+
}
|
|
71416
|
+
function requirePowerShell(result) {
|
|
71417
|
+
if (result.notFound === true) throw new KeystoreError(POWERSHELL_MISSING);
|
|
71418
|
+
}
|
|
71419
|
+
function binaryInstalled(file2, env) {
|
|
71420
|
+
if (isAbsolute(file2) || win32.isAbsolute(file2)) return existsSync(file2);
|
|
71421
|
+
return (env.PATH ?? "").split(delimiter).some((directory) => existsSync(join7(directory, file2)));
|
|
71422
|
+
}
|
|
71423
|
+
var SAFE_FAILURE_DETAILS = [
|
|
71424
|
+
"Cannot autolaunch D-Bus without X11 $DISPLAY",
|
|
71425
|
+
"Cannot autolaunch D-Bus",
|
|
71426
|
+
"The name org.freedesktop.secrets was not provided by any .service files",
|
|
71427
|
+
"Cannot create an item in a locked collection",
|
|
71428
|
+
"User interaction is not allowed.",
|
|
71429
|
+
"Access to the path is denied."
|
|
71430
|
+
];
|
|
71431
|
+
function requireSuccess(result, what) {
|
|
71432
|
+
if (result.code === 0) return;
|
|
71433
|
+
const detail = SAFE_FAILURE_DETAILS.find((reason) => result.stderr.includes(reason));
|
|
71434
|
+
throw new KeystoreError(
|
|
71435
|
+
`Could not ${what}${result.code === null ? "" : ` (exit ${result.code})`}.${detail === void 0 ? "" : ` ${detail}`}`
|
|
71436
|
+
);
|
|
71437
|
+
}
|
|
71438
|
+
function withoutTrailingNewline(value) {
|
|
71439
|
+
return value.replace(/\r?\n$/u, "");
|
|
71440
|
+
}
|
|
71441
|
+
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve3) => {
|
|
71442
|
+
let stdout = "";
|
|
71443
|
+
let stderr2 = "";
|
|
71444
|
+
let settled = false;
|
|
71445
|
+
const finish = (outcome) => {
|
|
71446
|
+
if (settled) return;
|
|
71447
|
+
settled = true;
|
|
71448
|
+
resolve3(outcome);
|
|
71449
|
+
};
|
|
71450
|
+
const child = spawn(file2, [...args], {
|
|
71451
|
+
detached: platform2 !== "win32",
|
|
71452
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
71453
|
+
windowsHide: true
|
|
71454
|
+
});
|
|
71455
|
+
child.stdout?.setEncoding("utf8");
|
|
71456
|
+
child.stdout?.on("data", (chunk) => {
|
|
71457
|
+
stdout += chunk;
|
|
71458
|
+
});
|
|
71459
|
+
child.stderr?.setEncoding("utf8");
|
|
71460
|
+
child.stderr?.on("data", (chunk) => {
|
|
71461
|
+
stderr2 += chunk;
|
|
71462
|
+
});
|
|
71463
|
+
child.on("error", (error61) => {
|
|
71464
|
+
finish({
|
|
71465
|
+
code: null,
|
|
71466
|
+
stdout,
|
|
71467
|
+
stderr: stderr2,
|
|
71468
|
+
...error61.code === "ENOENT" ? { notFound: true } : {}
|
|
71469
|
+
});
|
|
71470
|
+
});
|
|
71471
|
+
child.on("close", (code) => finish({ code, stdout, stderr: stderr2 }));
|
|
71472
|
+
child.stdin?.on("error", () => void 0);
|
|
71473
|
+
child.stdin?.end(input2 ?? "");
|
|
71474
|
+
});
|
|
71475
|
+
|
|
71476
|
+
// ../core/src/passphrase.ts
|
|
71477
|
+
var PASSPHRASE_ENVIRONMENT_VARIABLE = "VAPI_KEYSTORE_PASSWORD";
|
|
71478
|
+
function noPassphraseHint(walletName) {
|
|
71479
|
+
return `Set ${PASSPHRASE_ENVIRONMENT_VARIABLE}, or store this wallet's passphrase once with vapi unlock --wallet ${walletName}.`;
|
|
71480
|
+
}
|
|
71481
|
+
function staleStoredPassphraseMessage(walletName, store) {
|
|
71482
|
+
return [
|
|
71483
|
+
`The passphrase stored in ${store.description} no longer opens wallet ${walletName}.`,
|
|
71484
|
+
`Store the current one with vapi unlock --wallet ${walletName}, or remove it with vapi lock --wallet ${walletName}.`
|
|
71485
|
+
].join(" ");
|
|
71486
|
+
}
|
|
71487
|
+
async function resolvePassphrase(walletName, options = {}) {
|
|
71488
|
+
const env = options.env ?? process.env;
|
|
71489
|
+
const fromEnvironment = env[PASSPHRASE_ENVIRONMENT_VARIABLE];
|
|
71490
|
+
if (fromEnvironment !== void 0) {
|
|
71491
|
+
if (fromEnvironment.length === 0) {
|
|
71492
|
+
throw new KeystoreError(`${PASSPHRASE_ENVIRONMENT_VARIABLE} cannot be empty.`);
|
|
71493
|
+
}
|
|
71494
|
+
return { passphrase: fromEnvironment, source: "environment" };
|
|
71312
71495
|
}
|
|
71313
|
-
|
|
71314
|
-
|
|
71315
|
-
|
|
71316
|
-
}
|
|
71317
|
-
function assertVaultKey(key2) {
|
|
71318
|
-
if (key2.byteLength !== 32) {
|
|
71319
|
-
throw new VaultError("bad_key", "A device vault key must contain exactly 32 bytes.");
|
|
71496
|
+
if (options.confirm !== true) {
|
|
71497
|
+
const stored = await readStored(options.store ?? secretStore(), walletName);
|
|
71498
|
+
if (stored !== void 0) return { passphrase: stored, source: "secret-store" };
|
|
71320
71499
|
}
|
|
71321
|
-
|
|
71322
|
-
|
|
71323
|
-
|
|
71324
|
-
|
|
71325
|
-
|
|
71326
|
-
cause: parsed.error
|
|
71327
|
-
});
|
|
71500
|
+
const hint = noPassphraseHint(walletName);
|
|
71501
|
+
if (options.interactive === false) {
|
|
71502
|
+
throw new KeystoreError(
|
|
71503
|
+
`No interactive terminal is available for the keystore prompt. ${hint}`
|
|
71504
|
+
);
|
|
71328
71505
|
}
|
|
71329
|
-
|
|
71330
|
-
|
|
71331
|
-
|
|
71332
|
-
|
|
71333
|
-
|
|
71506
|
+
const prompt = options.prompt ?? promptForSecret;
|
|
71507
|
+
const first = await prompt(`Passphrase for ${walletName}: `, hint);
|
|
71508
|
+
if (first.length === 0) {
|
|
71509
|
+
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
71510
|
+
}
|
|
71511
|
+
if (options.confirm === true) {
|
|
71512
|
+
const second = await prompt("Confirm passphrase: ", hint);
|
|
71513
|
+
if (first !== second) throw new KeystoreError("Passphrases do not match.");
|
|
71334
71514
|
}
|
|
71515
|
+
return { passphrase: first, source: "prompt" };
|
|
71335
71516
|
}
|
|
71336
|
-
function
|
|
71337
|
-
|
|
71338
|
-
|
|
71339
|
-
|
|
71517
|
+
async function readStored(store, walletName) {
|
|
71518
|
+
if (!store.available) return void 0;
|
|
71519
|
+
try {
|
|
71520
|
+
return await store.get(walletName);
|
|
71521
|
+
} catch {
|
|
71522
|
+
return void 0;
|
|
71340
71523
|
}
|
|
71341
|
-
return next;
|
|
71342
71524
|
}
|
|
71343
|
-
|
|
71344
|
-
|
|
71345
|
-
|
|
71346
|
-
|
|
71347
|
-
|
|
71348
|
-
|
|
71349
|
-
|
|
71350
|
-
|
|
71525
|
+
|
|
71526
|
+
// ../core/src/receipts.ts
|
|
71527
|
+
import { randomBytes as randomBytes8 } from "node:crypto";
|
|
71528
|
+
import { mkdir as mkdir8, open as open7, readFile as readFile9, rename as rename5, writeFile as writeFile4 } from "node:fs/promises";
|
|
71529
|
+
import { dirname as dirname6 } from "node:path";
|
|
71530
|
+
|
|
71531
|
+
// ../core/src/agent-run.ts
|
|
71532
|
+
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
71533
|
+
var RUN_ID_PATTERN = /^run_[0-9a-f]{24}$/;
|
|
71534
|
+
function isRunId(value) {
|
|
71535
|
+
return typeof value === "string" && RUN_ID_PATTERN.test(value);
|
|
71351
71536
|
}
|
|
71352
|
-
function
|
|
71353
|
-
|
|
71354
|
-
return [nonce, ciphertext, tag].map((part) => part.toString("base64url")).join(".");
|
|
71537
|
+
function createRunId(random = randomBytes7) {
|
|
71538
|
+
return `run_${Buffer.from(random(12)).toString("hex")}`;
|
|
71355
71539
|
}
|
|
71356
|
-
|
|
71357
|
-
|
|
71358
|
-
|
|
71359
|
-
|
|
71360
|
-
|
|
71361
|
-
|
|
71540
|
+
var runRefSchema = external_exports.strictObject({
|
|
71541
|
+
id: external_exports.string().regex(RUN_ID_PATTERN),
|
|
71542
|
+
swarm: external_exports.string().optional(),
|
|
71543
|
+
member: external_exports.string().optional(),
|
|
71544
|
+
parentRunId: external_exports.string().optional()
|
|
71545
|
+
});
|
|
71546
|
+
|
|
71547
|
+
// ../core/src/receipts.ts
|
|
71548
|
+
var receiptTestHooks;
|
|
71549
|
+
var RECEIPT_JOURNAL_BUSY_MESSAGE = "The receipt journal is busy. Wait for the other vapi command to finish, then retry.";
|
|
71550
|
+
async function withReceiptJournalLock(path, operation) {
|
|
71551
|
+
return await withFileLock(`${path}.lock`, operation, {
|
|
71552
|
+
lockedMessage: RECEIPT_JOURNAL_BUSY_MESSAGE
|
|
71362
71553
|
});
|
|
71363
71554
|
}
|
|
71364
|
-
|
|
71365
|
-
|
|
71366
|
-
|
|
71367
|
-
|
|
71368
|
-
|
|
71369
|
-
|
|
71370
|
-
|
|
71371
|
-
|
|
71372
|
-
|
|
71373
|
-
|
|
71374
|
-
|
|
71375
|
-
|
|
71376
|
-
|
|
71377
|
-
|
|
71378
|
-
|
|
71379
|
-
})
|
|
71555
|
+
var durationSchema = external_exports.number().nonnegative().finite();
|
|
71556
|
+
var receiptSchema = external_exports.strictObject({
|
|
71557
|
+
id: external_exports.string().min(1),
|
|
71558
|
+
timestamp: external_exports.iso.datetime(),
|
|
71559
|
+
run: runRefSchema.optional(),
|
|
71560
|
+
kind: external_exports.literal("transfer").optional(),
|
|
71561
|
+
wallet: walletNameSchema.optional(),
|
|
71562
|
+
resourceUrl: external_exports.url(),
|
|
71563
|
+
method: external_exports.string().min(1).optional(),
|
|
71564
|
+
source: external_exports.string().min(1).optional(),
|
|
71565
|
+
provenance: external_exports.array(
|
|
71566
|
+
external_exports.strictObject({
|
|
71567
|
+
source: external_exports.string().min(1),
|
|
71568
|
+
sourceUrl: external_exports.string().optional(),
|
|
71569
|
+
ref: external_exports.string().optional()
|
|
71570
|
+
})
|
|
71571
|
+
).optional(),
|
|
71572
|
+
quote: external_exports.strictObject({
|
|
71573
|
+
network: external_exports.string(),
|
|
71574
|
+
asset: external_exports.string().optional(),
|
|
71575
|
+
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
71576
|
+
payTo: external_exports.string().optional()
|
|
71577
|
+
}).optional(),
|
|
71578
|
+
payer: external_exports.string().optional(),
|
|
71579
|
+
paymentId: external_exports.string().regex(/^[A-Za-z0-9_-]{16,128}$/).optional(),
|
|
71580
|
+
authorization: external_exports.strictObject({
|
|
71581
|
+
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71582
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
71583
|
+
validBefore: external_exports.string().regex(/^\d+$/)
|
|
71584
|
+
}).optional(),
|
|
71585
|
+
transfer: external_exports.strictObject({
|
|
71586
|
+
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71587
|
+
toName: external_exports.string().min(1),
|
|
71588
|
+
toKind: external_exports.enum(["owner", "account"]),
|
|
71589
|
+
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
71590
|
+
network: external_exports.string().min(1),
|
|
71591
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
71592
|
+
status: external_exports.enum(["sent", "unknown", "failed"]),
|
|
71593
|
+
txHash: external_exports.string().regex(/^0x[0-9a-fA-F]+$/).nullable(),
|
|
71594
|
+
replayed: external_exports.boolean(),
|
|
71595
|
+
reservedOn: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
71596
|
+
request: external_exports.strictObject({
|
|
71597
|
+
authorization: external_exports.strictObject({
|
|
71598
|
+
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71599
|
+
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71600
|
+
value: external_exports.string().regex(/^\d+$/),
|
|
71601
|
+
validAfter: external_exports.string().regex(/^\d+$/),
|
|
71602
|
+
validBefore: external_exports.string().regex(/^\d+$/),
|
|
71603
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/)
|
|
71604
|
+
}),
|
|
71605
|
+
signature: external_exports.string().regex(/^0x[0-9a-fA-F]+$/)
|
|
71606
|
+
}).optional()
|
|
71607
|
+
}).optional(),
|
|
71608
|
+
settlement: external_exports.strictObject({
|
|
71609
|
+
outcome: external_exports.enum(["succeeded", "rejected", "unknown"]),
|
|
71610
|
+
transaction: external_exports.string().optional(),
|
|
71611
|
+
explorerUrl: external_exports.url().optional(),
|
|
71612
|
+
evidence: external_exports.unknown().optional()
|
|
71613
|
+
}).optional(),
|
|
71614
|
+
latencyMs: external_exports.number().nonnegative().finite().optional(),
|
|
71615
|
+
status: external_exports.number().int().min(100).max(599).optional(),
|
|
71616
|
+
error: external_exports.strictObject({ code: external_exports.string(), message: external_exports.string() }).optional(),
|
|
71617
|
+
phases: external_exports.strictObject({
|
|
71618
|
+
discoverMs: durationSchema.optional(),
|
|
71619
|
+
quoteMs: durationSchema.optional(),
|
|
71620
|
+
signMs: durationSchema.optional(),
|
|
71621
|
+
requestMs: durationSchema.optional(),
|
|
71622
|
+
settleMs: durationSchema.optional()
|
|
71623
|
+
}).optional(),
|
|
71624
|
+
listing: external_exports.strictObject({
|
|
71625
|
+
name: external_exports.string().min(1).optional(),
|
|
71626
|
+
providerHost: external_exports.string().min(1).optional(),
|
|
71627
|
+
source: external_exports.string().min(1)
|
|
71628
|
+
}).optional(),
|
|
71629
|
+
retry: external_exports.number().int().nonnegative().optional(),
|
|
71630
|
+
policy: external_exports.strictObject({
|
|
71631
|
+
maxPriceUsd: external_exports.string().regex(/^\d+(?:\.\d{1,6})?$/).optional(),
|
|
71632
|
+
capsApplied: external_exports.boolean()
|
|
71633
|
+
}).optional(),
|
|
71634
|
+
client: external_exports.strictObject({ name: external_exports.literal("vapi-network"), version: external_exports.string().min(1) }).optional(),
|
|
71635
|
+
outcome: external_exports.enum([
|
|
71636
|
+
"paid",
|
|
71637
|
+
"signed_in",
|
|
71638
|
+
"declined_policy",
|
|
71639
|
+
"failed_request",
|
|
71640
|
+
"settlement_rejected",
|
|
71641
|
+
"settlement_unknown"
|
|
71642
|
+
]).optional()
|
|
71643
|
+
});
|
|
71644
|
+
function parseReceipt(value) {
|
|
71645
|
+
const receipt = receiptSchema.parse(value);
|
|
71646
|
+
const transaction2 = receipt.settlement?.transaction;
|
|
71647
|
+
const network = receipt.quote?.network;
|
|
71648
|
+
const explorerUrl = transaction2 === void 0 || network === void 0 ? void 0 : explorerTransactionUrl(network, transaction2);
|
|
71649
|
+
if (explorerUrl === void 0 || receipt.settlement?.explorerUrl === explorerUrl) {
|
|
71650
|
+
return receipt;
|
|
71380
71651
|
}
|
|
71381
|
-
|
|
71382
|
-
|
|
71383
|
-
|
|
71384
|
-
|
|
71385
|
-
|
|
71386
|
-
|
|
71387
|
-
|
|
71388
|
-
}
|
|
71389
|
-
let address4;
|
|
71390
|
-
try {
|
|
71391
|
-
address4 = privateKeyToAccount(`0x${plaintext.toString("hex")}`).address;
|
|
71392
|
-
} catch (error61) {
|
|
71393
|
-
throw new VaultError("bad_key", "The stored imported key is not valid.", {
|
|
71394
|
-
cause: error61
|
|
71395
|
-
});
|
|
71396
|
-
}
|
|
71397
|
-
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
71398
|
-
throw new VaultError("bad_key", "The stored imported key does not match its address.");
|
|
71652
|
+
return {
|
|
71653
|
+
...receipt,
|
|
71654
|
+
settlement: {
|
|
71655
|
+
outcome: receipt.settlement.outcome,
|
|
71656
|
+
...receipt.settlement.transaction ? { transaction: receipt.settlement.transaction } : {},
|
|
71657
|
+
explorerUrl,
|
|
71658
|
+
...receipt.settlement.evidence === void 0 ? {} : { evidence: receipt.settlement.evidence }
|
|
71399
71659
|
}
|
|
71400
|
-
}
|
|
71401
|
-
plaintext?.fill(0);
|
|
71402
|
-
}
|
|
71660
|
+
};
|
|
71403
71661
|
}
|
|
71404
|
-
function
|
|
71405
|
-
const
|
|
71406
|
-
|
|
71407
|
-
|
|
71408
|
-
|
|
71409
|
-
|
|
71410
|
-
|
|
71411
|
-
|
|
71412
|
-
|
|
71413
|
-
|
|
71662
|
+
async function appendReceipt(receipt, path = getVapiPaths().receipts, options = {}) {
|
|
71663
|
+
const parsed = parseReceipt(
|
|
71664
|
+
receipt.wallet === void 0 && options.wallet !== void 0 ? { ...receipt, wallet: options.wallet } : receipt
|
|
71665
|
+
);
|
|
71666
|
+
await withReceiptJournalLock(path, async () => {
|
|
71667
|
+
await mkdir8(dirname6(path), { recursive: true, mode: 448 });
|
|
71668
|
+
const handle = await open7(path, "a", 384);
|
|
71669
|
+
try {
|
|
71670
|
+
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
71671
|
+
`, "utf8");
|
|
71672
|
+
} finally {
|
|
71673
|
+
await handle.close();
|
|
71414
71674
|
}
|
|
71415
|
-
}
|
|
71416
|
-
|
|
71417
|
-
plaintext.fill(0);
|
|
71418
|
-
}
|
|
71675
|
+
});
|
|
71676
|
+
return parsed;
|
|
71419
71677
|
}
|
|
71420
|
-
function
|
|
71421
|
-
let
|
|
71678
|
+
async function readReceipts(path = getVapiPaths().receipts, options = {}) {
|
|
71679
|
+
let raw;
|
|
71422
71680
|
try {
|
|
71423
|
-
|
|
71681
|
+
raw = await readFile9(path, "utf8");
|
|
71424
71682
|
} catch (error61) {
|
|
71425
|
-
|
|
71426
|
-
|
|
71427
|
-
const parsed = vaultFileSchema.safeParse(value);
|
|
71428
|
-
if (!parsed.success) {
|
|
71429
|
-
throw new VaultError("corrupt", "The vault file has an invalid structure.", {
|
|
71430
|
-
cause: parsed.error
|
|
71431
|
-
});
|
|
71432
|
-
}
|
|
71433
|
-
if (parsed.data.protected !== (parsed.data.wrappedKey !== void 0)) {
|
|
71434
|
-
throw new VaultError("corrupt", "The vault protection metadata is inconsistent.");
|
|
71683
|
+
if (isMissingFile(error61)) return [];
|
|
71684
|
+
throw error61;
|
|
71435
71685
|
}
|
|
71436
|
-
const
|
|
71437
|
-
|
|
71438
|
-
|
|
71439
|
-
|
|
71440
|
-
|
|
71441
|
-
|
|
71442
|
-
names.add(account.name);
|
|
71443
|
-
if (account.kind === "derived") {
|
|
71444
|
-
if (indexes.has(account.index)) {
|
|
71445
|
-
throw new VaultError("corrupt", "The vault file contains duplicate derived indexes.");
|
|
71686
|
+
const records = coalesceTransferReceiptRevisions(
|
|
71687
|
+
raw.split("\n").filter((line) => line.trim().length > 0).map((line, index2) => {
|
|
71688
|
+
try {
|
|
71689
|
+
return parseReceipt(JSON.parse(line));
|
|
71690
|
+
} catch (error61) {
|
|
71691
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71446
71692
|
}
|
|
71447
|
-
|
|
71693
|
+
})
|
|
71694
|
+
);
|
|
71695
|
+
const filtered = options.wallet === void 0 ? records : filterReceiptsByWallet(records, options.wallet);
|
|
71696
|
+
const limit = options.limit;
|
|
71697
|
+
if (limit === void 0) return filtered;
|
|
71698
|
+
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
71699
|
+
throw new Error("Receipt limit must be a non-negative integer.");
|
|
71700
|
+
return limit === 0 ? [] : filtered.slice(-limit);
|
|
71701
|
+
}
|
|
71702
|
+
function coalesceTransferReceiptRevisions(receipts) {
|
|
71703
|
+
const coalesced = [];
|
|
71704
|
+
const transferIndexes = /* @__PURE__ */ new Map();
|
|
71705
|
+
for (const receipt of receipts) {
|
|
71706
|
+
const existing = receipt.kind === "transfer" ? transferIndexes.get(receipt.id) : void 0;
|
|
71707
|
+
if (existing === void 0) {
|
|
71708
|
+
if (receipt.kind === "transfer") transferIndexes.set(receipt.id, coalesced.length);
|
|
71709
|
+
coalesced.push(receipt);
|
|
71710
|
+
} else {
|
|
71711
|
+
coalesced[existing] = receipt;
|
|
71448
71712
|
}
|
|
71449
71713
|
}
|
|
71450
|
-
return
|
|
71714
|
+
return coalesced;
|
|
71451
71715
|
}
|
|
71452
|
-
|
|
71453
|
-
|
|
71454
|
-
|
|
71455
|
-
|
|
71716
|
+
function receiptWallet(receipt) {
|
|
71717
|
+
return receipt.wallet ?? DEFAULT_WALLET_NAME;
|
|
71718
|
+
}
|
|
71719
|
+
function filterReceiptsByWallet(receipts, name) {
|
|
71720
|
+
return receipts.filter((receipt) => receiptWallet(receipt) === name);
|
|
71721
|
+
}
|
|
71722
|
+
async function renameReceiptWallet(from16, to, path = getVapiPaths().receipts) {
|
|
71723
|
+
return await withReceiptJournalLock(path, async () => {
|
|
71724
|
+
let raw;
|
|
71456
71725
|
try {
|
|
71457
|
-
|
|
71726
|
+
raw = await readFile9(path, "utf8");
|
|
71458
71727
|
} catch (error61) {
|
|
71459
|
-
|
|
71460
|
-
|
|
71461
|
-
});
|
|
71462
|
-
}
|
|
71463
|
-
} finally {
|
|
71464
|
-
plaintext.fill(0);
|
|
71465
|
-
}
|
|
71466
|
-
return file2;
|
|
71467
|
-
}
|
|
71468
|
-
async function readVaultFileUnlocked(path) {
|
|
71469
|
-
let raw;
|
|
71470
|
-
try {
|
|
71471
|
-
raw = await readFile9(path, "utf8");
|
|
71472
|
-
} catch (error61) {
|
|
71473
|
-
if (isMissingFile2(error61)) {
|
|
71474
|
-
throw new VaultError("not_found", "No vault file was found at the requested path.", {
|
|
71475
|
-
cause: error61
|
|
71476
|
-
});
|
|
71728
|
+
if (isMissingFile(error61)) return 0;
|
|
71729
|
+
throw error61;
|
|
71477
71730
|
}
|
|
71478
|
-
|
|
71479
|
-
|
|
71480
|
-
|
|
71481
|
-
|
|
71482
|
-
|
|
71483
|
-
|
|
71484
|
-
|
|
71485
|
-
|
|
71486
|
-
|
|
71487
|
-
|
|
71488
|
-
|
|
71731
|
+
let changed = 0;
|
|
71732
|
+
const lines = raw.split("\n").map((line, index2) => {
|
|
71733
|
+
if (line.trim().length === 0) return line;
|
|
71734
|
+
let parsed;
|
|
71735
|
+
try {
|
|
71736
|
+
parsed = JSON.parse(line);
|
|
71737
|
+
} catch (error61) {
|
|
71738
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71739
|
+
}
|
|
71740
|
+
const current = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "wallet") : void 0;
|
|
71741
|
+
if ((typeof current === "string" ? current : DEFAULT_WALLET_NAME) !== from16) return line;
|
|
71742
|
+
changed += 1;
|
|
71743
|
+
return JSON.stringify(parseReceipt({ ...parsed, wallet: to }));
|
|
71489
71744
|
});
|
|
71490
|
-
|
|
71491
|
-
|
|
71492
|
-
}
|
|
71493
|
-
|
|
71494
|
-
|
|
71495
|
-
const temporaryPath = `${path}.${process.pid}.${randomBytes7(6).toString("hex")}.tmp`;
|
|
71496
|
-
try {
|
|
71497
|
-
await writeFile4(temporaryPath, `${JSON.stringify(file2, null, 2)}
|
|
71498
|
-
`, {
|
|
71745
|
+
if (changed === 0) return 0;
|
|
71746
|
+
await receiptTestHooks?.beforeRenameReplace?.(path);
|
|
71747
|
+
await mkdir8(dirname6(path), { recursive: true, mode: 448 });
|
|
71748
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes8(6).toString("hex")}.tmp`;
|
|
71749
|
+
await writeFile4(temporaryPath, lines.join("\n"), {
|
|
71499
71750
|
encoding: "utf8",
|
|
71500
71751
|
mode: 384,
|
|
71501
71752
|
flag: "wx"
|
|
71502
71753
|
});
|
|
71503
71754
|
await rename5(temporaryPath, path);
|
|
71755
|
+
return changed;
|
|
71756
|
+
});
|
|
71757
|
+
}
|
|
71758
|
+
|
|
71759
|
+
// ../core/src/transfer-journal.ts
|
|
71760
|
+
import { readFile as readFile10 } from "node:fs/promises";
|
|
71761
|
+
async function readTransferJournal(home, from16, nonce) {
|
|
71762
|
+
let raw;
|
|
71763
|
+
try {
|
|
71764
|
+
raw = await readFile10(getVapiPaths(home).receipts, "utf8");
|
|
71504
71765
|
} catch (error61) {
|
|
71505
|
-
|
|
71766
|
+
if (isMissingFile(error61)) return { signed: false };
|
|
71506
71767
|
throw error61;
|
|
71507
71768
|
}
|
|
71508
|
-
|
|
71509
|
-
|
|
71510
|
-
|
|
71511
|
-
|
|
71512
|
-
|
|
71513
|
-
let handle;
|
|
71514
|
-
while (!handle) {
|
|
71769
|
+
let latest;
|
|
71770
|
+
let request;
|
|
71771
|
+
for (const [index2, line] of raw.split("\n").entries()) {
|
|
71772
|
+
if (!line.trim()) continue;
|
|
71773
|
+
let receipt;
|
|
71515
71774
|
try {
|
|
71516
|
-
|
|
71775
|
+
receipt = parseReceipt(JSON.parse(line));
|
|
71517
71776
|
} catch (error61) {
|
|
71518
|
-
|
|
71519
|
-
await removeStaleVaultLock(lockPath);
|
|
71520
|
-
if (Date.now() >= deadline) {
|
|
71521
|
-
throw new VaultError("corrupt", "Timed out waiting for the vault lock.");
|
|
71522
|
-
}
|
|
71523
|
-
await new Promise((resolve3) => setTimeout(resolve3, 20));
|
|
71777
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71524
71778
|
}
|
|
71779
|
+
if (receiptWallet(receipt) !== from16 || receipt.transfer?.nonce.toLowerCase() !== nonce.toLowerCase()) {
|
|
71780
|
+
continue;
|
|
71781
|
+
}
|
|
71782
|
+
latest = receipt;
|
|
71783
|
+
if (receipt.transfer.request !== void 0) request = receipt;
|
|
71525
71784
|
}
|
|
71526
|
-
|
|
71527
|
-
|
|
71528
|
-
|
|
71529
|
-
|
|
71530
|
-
|
|
71531
|
-
|
|
71532
|
-
}
|
|
71533
|
-
async function removeStaleVaultLock(path) {
|
|
71534
|
-
try {
|
|
71535
|
-
const metadata = await stat6(path);
|
|
71536
|
-
if (Date.now() - metadata.mtimeMs > STALE_VAULT_LOCK_MS) await unlink4(path);
|
|
71537
|
-
} catch (error61) {
|
|
71538
|
-
if (!isMissingFile2(error61)) throw error61;
|
|
71539
|
-
}
|
|
71540
|
-
}
|
|
71541
|
-
function isMissingFile2(error61) {
|
|
71542
|
-
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "ENOENT";
|
|
71543
|
-
}
|
|
71544
|
-
function isExistingFile(error61) {
|
|
71545
|
-
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "EEXIST";
|
|
71546
|
-
}
|
|
71547
|
-
function asVaultError(error61, code, message) {
|
|
71548
|
-
return error61 instanceof VaultError ? error61 : new VaultError(code, message, { cause: error61 });
|
|
71785
|
+
return {
|
|
71786
|
+
signed: latest !== void 0,
|
|
71787
|
+
...latest === void 0 ? {} : { latest },
|
|
71788
|
+
...request === void 0 ? {} : { request },
|
|
71789
|
+
...request?.transfer?.request?.authorization.validBefore === void 0 ? {} : { validBefore: request.transfer.request.authorization.validBefore },
|
|
71790
|
+
...(latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn) === void 0 ? {} : { reservedOn: latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn }
|
|
71791
|
+
};
|
|
71549
71792
|
}
|
|
71550
71793
|
|
|
71551
71794
|
// ../core/src/vault-key.ts
|
|
71795
|
+
import { randomBytes as cryptoRandomBytes } from "node:crypto";
|
|
71552
71796
|
var VAULT_KEY_ACCOUNT = "vault-key";
|
|
71553
71797
|
var VAULT_SESSION_ACCOUNT = "vault-session";
|
|
71554
71798
|
var DEVICE_KEY_LENGTH = 32;
|
|
@@ -71570,7 +71814,7 @@ async function loadOrCreateDeviceKey(args) {
|
|
|
71570
71814
|
await args.secrets.set(VAULT_KEY_ACCOUNT, key2.toString("base64"));
|
|
71571
71815
|
return key2;
|
|
71572
71816
|
} catch (error61) {
|
|
71573
|
-
throw asVaultError2(error61,
|
|
71817
|
+
throw asVaultError2(error61, deviceKeyFailureMessage(error61, args.secrets.platform));
|
|
71574
71818
|
}
|
|
71575
71819
|
});
|
|
71576
71820
|
}
|
|
@@ -71776,8 +72020,8 @@ function passwordRequiredError() {
|
|
|
71776
72020
|
"A vault password is needed. Pass it or set VAPI_VAULT_PASSWORD."
|
|
71777
72021
|
);
|
|
71778
72022
|
}
|
|
71779
|
-
function randomKeyBytes(
|
|
71780
|
-
const key2 = Buffer.from((
|
|
72023
|
+
function randomKeyBytes(randomBytes18) {
|
|
72024
|
+
const key2 = Buffer.from((randomBytes18 ?? cryptoRandomBytes)(DEVICE_KEY_LENGTH));
|
|
71781
72025
|
if (key2.byteLength !== DEVICE_KEY_LENGTH) {
|
|
71782
72026
|
key2.fill(0);
|
|
71783
72027
|
throw new VaultError("corrupt", "A generated device vault key has the wrong length.");
|
|
@@ -71828,25 +72072,31 @@ function parseJson(value) {
|
|
|
71828
72072
|
function asVaultError2(error61, message) {
|
|
71829
72073
|
return error61 instanceof VaultError ? error61 : new VaultError("corrupt", message, { cause: error61 });
|
|
71830
72074
|
}
|
|
72075
|
+
var HEADLESS_LINUX_HINT = "A server, container or GitHub Codespace usually has no keyring. Set VAPI_VAULT_PASSWORD and run vapi setup again, or run vapi on your own computer.";
|
|
72076
|
+
function deviceKeyFailureMessage(error61, platform2) {
|
|
72077
|
+
if (!(error61 instanceof KeystoreError)) return "Unable to load or create the device vault key.";
|
|
72078
|
+
const detail = `Unable to load or create the device vault key: ${error61.message.replace(/\.$/u, "")}.`;
|
|
72079
|
+
return platform2 === "linux" ? `${detail} ${HEADLESS_LINUX_HINT}` : detail;
|
|
72080
|
+
}
|
|
71831
72081
|
|
|
71832
72082
|
// ../core/src/vault-migrate.ts
|
|
71833
72083
|
import {
|
|
71834
72084
|
chmod as chmod2,
|
|
71835
72085
|
lstat,
|
|
71836
72086
|
mkdir as mkdir9,
|
|
71837
|
-
readFile as
|
|
72087
|
+
readFile as readFile11,
|
|
71838
72088
|
readlink,
|
|
71839
72089
|
readdir as readdir2,
|
|
71840
72090
|
rename as rename6,
|
|
71841
72091
|
symlink,
|
|
71842
72092
|
unlink as unlink5
|
|
71843
72093
|
} from "node:fs/promises";
|
|
71844
|
-
import { join as
|
|
72094
|
+
import { join as join8, resolve } from "node:path";
|
|
71845
72095
|
var MIGRATED_DIRECTORY = "wallets.migrated";
|
|
71846
72096
|
async function legacyKeystoreNames(home) {
|
|
71847
72097
|
let entries;
|
|
71848
72098
|
try {
|
|
71849
|
-
entries = await readdir2(
|
|
72099
|
+
entries = await readdir2(join8(home, "wallets"), { withFileTypes: true });
|
|
71850
72100
|
} catch (error61) {
|
|
71851
72101
|
if (isMissingFile(error61)) return [];
|
|
71852
72102
|
throw error61;
|
|
@@ -71862,14 +72112,14 @@ async function migrateKeystores(args) {
|
|
|
71862
72112
|
);
|
|
71863
72113
|
const result = { imported: [], skipped: [] };
|
|
71864
72114
|
for (const name of names) {
|
|
71865
|
-
const source =
|
|
72115
|
+
const source = join8(args.home, "wallets", `${name}.json`);
|
|
71866
72116
|
if (args.vault.accounts().some((account) => account.name === name)) {
|
|
71867
72117
|
result.skipped.push({ name, reason: "name_taken" });
|
|
71868
72118
|
continue;
|
|
71869
72119
|
}
|
|
71870
72120
|
let parsed;
|
|
71871
72121
|
try {
|
|
71872
|
-
parsed = parseAnyKeystore(JSON.parse(await
|
|
72122
|
+
parsed = parseAnyKeystore(JSON.parse(await readFile11(source, "utf8")));
|
|
71873
72123
|
} catch {
|
|
71874
72124
|
result.skipped.push({ name, reason: "unreadable" });
|
|
71875
72125
|
continue;
|
|
@@ -71899,15 +72149,15 @@ async function migrateKeystores(args) {
|
|
|
71899
72149
|
if (imported.address.toLowerCase() !== parsed.address.toLowerCase()) {
|
|
71900
72150
|
throw new KeystoreError(`Migrated wallet ${name} does not match its stored address.`);
|
|
71901
72151
|
}
|
|
71902
|
-
const migratedDirectory =
|
|
71903
|
-
const destination =
|
|
72152
|
+
const migratedDirectory = join8(args.home, MIGRATED_DIRECTORY);
|
|
72153
|
+
const destination = join8(migratedDirectory, `${name}.json`);
|
|
71904
72154
|
await mkdir9(migratedDirectory, { recursive: true, mode: 448 });
|
|
71905
72155
|
await archiveExistingDestination(destination, migratedDirectory, name, now);
|
|
71906
72156
|
await rename6(source, destination);
|
|
71907
72157
|
await chmod2(destination, 384);
|
|
71908
72158
|
try {
|
|
71909
72159
|
await removeCompatibilityLink(args.home, source);
|
|
71910
|
-
await symlink(
|
|
72160
|
+
await symlink(join8("..", MIGRATED_DIRECTORY, `${name}.json`), source);
|
|
71911
72161
|
await audit({
|
|
71912
72162
|
event: "vault.migrate",
|
|
71913
72163
|
wallet: name,
|
|
@@ -71935,16 +72185,16 @@ async function migrateKeystores(args) {
|
|
|
71935
72185
|
async function archiveExistingDestination(destination, directory, name, now) {
|
|
71936
72186
|
if (!await pathExists2(destination)) return;
|
|
71937
72187
|
const timestamp = now().toISOString();
|
|
71938
|
-
let archive =
|
|
72188
|
+
let archive = join8(directory, `${name}.${timestamp}.json`);
|
|
71939
72189
|
let suffix = 1;
|
|
71940
72190
|
while (await pathExists2(archive)) {
|
|
71941
|
-
archive =
|
|
72191
|
+
archive = join8(directory, `${name}.${timestamp}.${suffix}.json`);
|
|
71942
72192
|
suffix += 1;
|
|
71943
72193
|
}
|
|
71944
72194
|
await rename6(destination, archive);
|
|
71945
72195
|
}
|
|
71946
72196
|
async function removeCompatibilityLink(home, migratedSource) {
|
|
71947
|
-
const compatibilityPath =
|
|
72197
|
+
const compatibilityPath = join8(home, "keystore.json");
|
|
71948
72198
|
let metadata;
|
|
71949
72199
|
try {
|
|
71950
72200
|
metadata = await lstat(compatibilityPath);
|
|
@@ -72018,7 +72268,7 @@ var WalletStore = class _WalletStore {
|
|
|
72018
72268
|
this.home = home;
|
|
72019
72269
|
this.options = options;
|
|
72020
72270
|
this.registry = registry2;
|
|
72021
|
-
this.secrets = options.secrets ?? secretStore();
|
|
72271
|
+
this.secrets = options.secrets ?? secretStore({ home });
|
|
72022
72272
|
this.environment = options.env ?? process.env;
|
|
72023
72273
|
this.passphraseResolver = options.resolvePassphrase ?? defaultPassphraseResolver(this.environment, this.secrets);
|
|
72024
72274
|
this.audit = options.audit ?? (async (record2) => await appendAudit(this.home, record2, { now: () => this.now() }));
|
|
@@ -72065,17 +72315,17 @@ var WalletStore = class _WalletStore {
|
|
|
72065
72315
|
return store;
|
|
72066
72316
|
}
|
|
72067
72317
|
get registryPath() {
|
|
72068
|
-
return
|
|
72318
|
+
return join9(this.home, REGISTRY_FILE);
|
|
72069
72319
|
}
|
|
72070
72320
|
get walletsDirectory() {
|
|
72071
|
-
return
|
|
72321
|
+
return join9(this.home, WALLETS_DIRECTORY);
|
|
72072
72322
|
}
|
|
72073
72323
|
get trashDirectory() {
|
|
72074
|
-
return
|
|
72324
|
+
return join9(this.walletsDirectory, TRASH_DIRECTORY);
|
|
72075
72325
|
}
|
|
72076
72326
|
/** The legacy 0.5 keystore path of a wallet, whether or not it exists. */
|
|
72077
72327
|
pathFor(name) {
|
|
72078
|
-
return
|
|
72328
|
+
return join9(this.walletsDirectory, `${assertWalletName(name)}.json`);
|
|
72079
72329
|
}
|
|
72080
72330
|
/** The names this machine knows, in registry order. */
|
|
72081
72331
|
names() {
|
|
@@ -72648,7 +72898,7 @@ var WalletStore = class _WalletStore {
|
|
|
72648
72898
|
}
|
|
72649
72899
|
const removedAt = this.now().toISOString();
|
|
72650
72900
|
await mkdir10(this.trashDirectory, { recursive: true, mode: 448 });
|
|
72651
|
-
const trashedPath =
|
|
72901
|
+
const trashedPath = join9(this.trashDirectory, `${wallet.name}-${removedAt}.json`);
|
|
72652
72902
|
const storedAccount = (await this.readVaultUnlocked())?.accounts.find(
|
|
72653
72903
|
(candidate) => candidate.name === wallet.name
|
|
72654
72904
|
);
|
|
@@ -72670,7 +72920,7 @@ var WalletStore = class _WalletStore {
|
|
|
72670
72920
|
this.balanceProbe = void 0;
|
|
72671
72921
|
}
|
|
72672
72922
|
if (await pathExists3(wallet.path)) {
|
|
72673
|
-
const legacyTrashedPath =
|
|
72923
|
+
const legacyTrashedPath = join9(
|
|
72674
72924
|
this.trashDirectory,
|
|
72675
72925
|
`${wallet.name}-${removedAt}.legacy.json`
|
|
72676
72926
|
);
|
|
@@ -72760,7 +73010,7 @@ var WalletStore = class _WalletStore {
|
|
|
72760
73010
|
if (!match) continue;
|
|
72761
73011
|
const [, name, removedAt] = match;
|
|
72762
73012
|
if (name === void 0 || removedAt === void 0 || !isWalletName(name)) continue;
|
|
72763
|
-
const path =
|
|
73013
|
+
const path = join9(this.trashDirectory, file2);
|
|
72764
73014
|
const entry = await readEntrySidecar(entrySidecarPath(path));
|
|
72765
73015
|
trashed.push({ name, removedAt, path, ...entry ? { entry } : {} });
|
|
72766
73016
|
}
|
|
@@ -72829,7 +73079,7 @@ var WalletStore = class _WalletStore {
|
|
|
72829
73079
|
return entry;
|
|
72830
73080
|
}
|
|
72831
73081
|
get vaultPath() {
|
|
72832
|
-
return
|
|
73082
|
+
return join9(this.home, VAULT_FILE);
|
|
72833
73083
|
}
|
|
72834
73084
|
async readVaultUnlocked() {
|
|
72835
73085
|
try {
|
|
@@ -72934,7 +73184,7 @@ var WalletStore = class _WalletStore {
|
|
|
72934
73184
|
async readRegistry() {
|
|
72935
73185
|
let raw;
|
|
72936
73186
|
try {
|
|
72937
|
-
raw = await
|
|
73187
|
+
raw = await readFile12(this.registryPath, "utf8");
|
|
72938
73188
|
} catch (error61) {
|
|
72939
73189
|
if (isMissingFile(error61)) return emptyRegistry();
|
|
72940
73190
|
throw error61;
|
|
@@ -72955,7 +73205,7 @@ var WalletStore = class _WalletStore {
|
|
|
72955
73205
|
}
|
|
72956
73206
|
};
|
|
72957
73207
|
async function swarmReferencingAccount(home, account) {
|
|
72958
|
-
const directory =
|
|
73208
|
+
const directory = join9(home, "swarms");
|
|
72959
73209
|
let files;
|
|
72960
73210
|
try {
|
|
72961
73211
|
files = await readdir3(directory);
|
|
@@ -72966,7 +73216,7 @@ async function swarmReferencingAccount(home, account) {
|
|
|
72966
73216
|
for (const file2 of files.filter((name) => name.endsWith(".json")).sort()) {
|
|
72967
73217
|
let value;
|
|
72968
73218
|
try {
|
|
72969
|
-
value = JSON.parse(await
|
|
73219
|
+
value = JSON.parse(await readFile12(join9(directory, file2), "utf8"));
|
|
72970
73220
|
} catch {
|
|
72971
73221
|
throw new KeystoreError(
|
|
72972
73222
|
`Cannot verify swarm references because ${file2} is invalid. Repair or remove that swarm file before renaming an account.`
|
|
@@ -72998,7 +73248,7 @@ async function swarmReferencingAccount(home, account) {
|
|
|
72998
73248
|
return void 0;
|
|
72999
73249
|
}
|
|
73000
73250
|
async function unfinishedMovementReferencingAccount(home, account) {
|
|
73001
|
-
const directory =
|
|
73251
|
+
const directory = join9(home, "movements");
|
|
73002
73252
|
let files;
|
|
73003
73253
|
try {
|
|
73004
73254
|
files = await readdir3(directory);
|
|
@@ -73009,7 +73259,7 @@ async function unfinishedMovementReferencingAccount(home, account) {
|
|
|
73009
73259
|
for (const file2 of files.filter((name) => name.endsWith(".json")).sort()) {
|
|
73010
73260
|
let value;
|
|
73011
73261
|
try {
|
|
73012
|
-
value = JSON.parse(await
|
|
73262
|
+
value = JSON.parse(await readFile12(join9(directory, file2), "utf8"));
|
|
73013
73263
|
} catch {
|
|
73014
73264
|
throw invalidMovementReferenceError(file2);
|
|
73015
73265
|
}
|
|
@@ -73030,11 +73280,11 @@ async function unfinishedMovementReferencingAccount(home, account) {
|
|
|
73030
73280
|
const restored = Reflect.get(leg, "restored");
|
|
73031
73281
|
const legFrom = Reflect.get(leg, "from") ?? movementFrom;
|
|
73032
73282
|
const journal = restored !== true && status === "failed" && retryable !== true && typeof nonce === "string" ? await readTransferJournal(home, legFrom, nonce) : void 0;
|
|
73033
|
-
const
|
|
73283
|
+
const open13 = isOpenMovementLeg(
|
|
73034
73284
|
{ status, retryable, nonce, restored },
|
|
73035
73285
|
journal?.signed === true ? "signed" : "unsigned"
|
|
73036
73286
|
);
|
|
73037
|
-
if (
|
|
73287
|
+
if (open13) movementOpen = true;
|
|
73038
73288
|
}
|
|
73039
73289
|
if (movementOpen && (movementFrom === account || legs.some(
|
|
73040
73290
|
(leg) => (Reflect.get(leg, "from") ?? movementFrom) === account || Reflect.get(leg, "to") === account
|
|
@@ -73070,7 +73320,7 @@ async function withAccountMutationLocks(home, accounts, command, operation) {
|
|
|
73070
73320
|
const [account, ...remaining2] = [...new Set(accounts)].sort();
|
|
73071
73321
|
if (account === void 0) return await operation();
|
|
73072
73322
|
return await withFileLock(
|
|
73073
|
-
|
|
73323
|
+
join9(home, `.account-${account}.lock`),
|
|
73074
73324
|
async () => await withAccountMutationLocks(home, remaining2, command, operation),
|
|
73075
73325
|
{
|
|
73076
73326
|
lockedMessage: `Account ${account} is busy with another account change. Wait for it to finish, then retry ${command}.`
|
|
@@ -73145,7 +73395,7 @@ function isLockedVaultError(error61) {
|
|
|
73145
73395
|
async function readTrashedVaultAccount(path) {
|
|
73146
73396
|
let parsed;
|
|
73147
73397
|
try {
|
|
73148
|
-
parsed = JSON.parse(await
|
|
73398
|
+
parsed = JSON.parse(await readFile12(path, "utf8"));
|
|
73149
73399
|
} catch {
|
|
73150
73400
|
return void 0;
|
|
73151
73401
|
}
|
|
@@ -73154,7 +73404,7 @@ async function readTrashedVaultAccount(path) {
|
|
|
73154
73404
|
}
|
|
73155
73405
|
async function readEntrySidecar(path) {
|
|
73156
73406
|
try {
|
|
73157
|
-
const parsed = walletEntrySchema.safeParse(JSON.parse(await
|
|
73407
|
+
const parsed = walletEntrySchema.safeParse(JSON.parse(await readFile12(path, "utf8")));
|
|
73158
73408
|
return parsed.success ? parsed.data : void 0;
|
|
73159
73409
|
} catch {
|
|
73160
73410
|
return void 0;
|
|
@@ -73163,7 +73413,7 @@ async function readEntrySidecar(path) {
|
|
|
73163
73413
|
async function readKeystoreSummary(path) {
|
|
73164
73414
|
let parsed;
|
|
73165
73415
|
try {
|
|
73166
|
-
parsed = JSON.parse(await
|
|
73416
|
+
parsed = JSON.parse(await readFile12(path, "utf8"));
|
|
73167
73417
|
} catch {
|
|
73168
73418
|
return {};
|
|
73169
73419
|
}
|
|
@@ -73181,7 +73431,7 @@ async function readKeystoreSummary(path) {
|
|
|
73181
73431
|
}
|
|
73182
73432
|
async function readConfiguredSpendCaps(configPath) {
|
|
73183
73433
|
try {
|
|
73184
|
-
const parsed = JSON.parse(await
|
|
73434
|
+
const parsed = JSON.parse(await readFile12(configPath, "utf8"));
|
|
73185
73435
|
const caps = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "spendCaps") : void 0;
|
|
73186
73436
|
const result = spendCapsSchema.safeParse(caps);
|
|
73187
73437
|
if (result.success) return result.data;
|
|
@@ -73273,7 +73523,7 @@ async function withRegistryLock(path, operation) {
|
|
|
73273
73523
|
let handle;
|
|
73274
73524
|
while (!handle) {
|
|
73275
73525
|
try {
|
|
73276
|
-
handle = await
|
|
73526
|
+
handle = await open8(lockPath, "wx", 384);
|
|
73277
73527
|
} catch (error61) {
|
|
73278
73528
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) throw error61;
|
|
73279
73529
|
await removeStaleRegistryLock(lockPath);
|
|
@@ -73292,7 +73542,7 @@ async function withRegistryLock(path, operation) {
|
|
|
73292
73542
|
}
|
|
73293
73543
|
async function removeStaleRegistryLock(path) {
|
|
73294
73544
|
try {
|
|
73295
|
-
const metadata = await
|
|
73545
|
+
const metadata = await stat9(path);
|
|
73296
73546
|
if (Date.now() - metadata.mtimeMs > 3e4) await unlink6(path);
|
|
73297
73547
|
} catch (error61) {
|
|
73298
73548
|
if (!isMissingFile(error61)) throw error61;
|
|
@@ -73300,7 +73550,7 @@ async function removeStaleRegistryLock(path) {
|
|
|
73300
73550
|
}
|
|
73301
73551
|
async function writeJsonFile(path, value) {
|
|
73302
73552
|
await mkdir10(dirname7(path), { recursive: true, mode: 448 });
|
|
73303
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
73553
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes9(6).toString("hex")}.tmp`;
|
|
73304
73554
|
await writeFile5(temporaryPath, `${JSON.stringify(value, null, 2)}
|
|
73305
73555
|
`, {
|
|
73306
73556
|
encoding: "utf8",
|
|
@@ -73338,7 +73588,7 @@ async function createAccount(args) {
|
|
|
73338
73588
|
created: false
|
|
73339
73589
|
};
|
|
73340
73590
|
}
|
|
73341
|
-
if (!await
|
|
73591
|
+
if (!await fileExists2(join10(args.store.home, "vault.json"))) {
|
|
73342
73592
|
throw new KeystoreError("No vault yet. Run vapi setup.");
|
|
73343
73593
|
}
|
|
73344
73594
|
const spendCaps = resolveNewAccountCaps(args.caps);
|
|
@@ -73605,9 +73855,9 @@ async function requireAddress(store, name) {
|
|
|
73605
73855
|
if (address4 === void 0) throw new KeystoreError(`No key for wallet ${name} in the vault.`);
|
|
73606
73856
|
return address4;
|
|
73607
73857
|
}
|
|
73608
|
-
async function
|
|
73858
|
+
async function fileExists2(path) {
|
|
73609
73859
|
try {
|
|
73610
|
-
await
|
|
73860
|
+
await stat10(path);
|
|
73611
73861
|
return true;
|
|
73612
73862
|
} catch (error61) {
|
|
73613
73863
|
if (isMissingFile(error61)) return false;
|
|
@@ -73669,9 +73919,9 @@ function secretsAllowed(env, streams) {
|
|
|
73669
73919
|
}
|
|
73670
73920
|
|
|
73671
73921
|
// ../core/src/agent-profile.ts
|
|
73672
|
-
import { randomBytes as
|
|
73673
|
-
import { mkdir as mkdir11, readFile as
|
|
73674
|
-
import { join as
|
|
73922
|
+
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
73923
|
+
import { mkdir as mkdir11, readFile as readFile13, readdir as readdir4, rename as rename8, unlink as unlink7, writeFile as writeFile6 } from "node:fs/promises";
|
|
73924
|
+
import { join as join11 } from "node:path";
|
|
73675
73925
|
var DEFAULT_AGENT_TOOLS = ["call.search", "call.inspect", "call.pay"];
|
|
73676
73926
|
var AGENT_GRANTS = ["read", "delegate", "allocate"];
|
|
73677
73927
|
var agentProfileShape = {
|
|
@@ -73701,7 +73951,7 @@ async function readAgentProfile(home, name, options = {}) {
|
|
|
73701
73951
|
const path = agentProfilePath(home, name);
|
|
73702
73952
|
let raw;
|
|
73703
73953
|
try {
|
|
73704
|
-
raw = await
|
|
73954
|
+
raw = await readFile13(path, "utf8");
|
|
73705
73955
|
} catch (error61) {
|
|
73706
73956
|
if (isMissingFile(error61)) {
|
|
73707
73957
|
throw new Error(`No agent named ${name}. Create it with vapi agent create ${name}.`);
|
|
@@ -73713,9 +73963,9 @@ async function readAgentProfile(home, name, options = {}) {
|
|
|
73713
73963
|
async function writeAgentProfile(home, profile, options = {}) {
|
|
73714
73964
|
const parsed = (options.schema ?? agentProfileSchema).parse(profile);
|
|
73715
73965
|
const directory = getVapiPaths(home).agentsDir;
|
|
73716
|
-
const path =
|
|
73966
|
+
const path = join11(directory, `${parsed.name}.json`);
|
|
73717
73967
|
await mkdir11(directory, { recursive: true, mode: 448 });
|
|
73718
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
73968
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes10(6).toString("hex")}.tmp`;
|
|
73719
73969
|
await writeFile6(temporaryPath, `${JSON.stringify(parsed, null, 2)}
|
|
73720
73970
|
`, {
|
|
73721
73971
|
encoding: "utf8",
|
|
@@ -73740,7 +73990,7 @@ async function listAgentProfiles(home, options = {}) {
|
|
|
73740
73990
|
try {
|
|
73741
73991
|
profiles.push(
|
|
73742
73992
|
(options.schema ?? agentProfileSchema).parse(
|
|
73743
|
-
JSON.parse(await
|
|
73993
|
+
JSON.parse(await readFile13(join11(directory, file2), "utf8"))
|
|
73744
73994
|
)
|
|
73745
73995
|
);
|
|
73746
73996
|
} catch {
|
|
@@ -73761,11 +74011,11 @@ async function removeAgentProfile(home, name) {
|
|
|
73761
74011
|
}
|
|
73762
74012
|
function agentProfilePath(home, name) {
|
|
73763
74013
|
const parsedName = walletNameSchema.parse(name);
|
|
73764
|
-
return
|
|
74014
|
+
return join11(getVapiPaths(home).agentsDir, `${parsedName}.json`);
|
|
73765
74015
|
}
|
|
73766
74016
|
|
|
73767
74017
|
// ../core/src/ceiling.ts
|
|
73768
|
-
import { randomBytes as
|
|
74018
|
+
import { randomBytes as randomBytes14 } from "node:crypto";
|
|
73769
74019
|
|
|
73770
74020
|
// ../core/src/authorization-state.ts
|
|
73771
74021
|
var EIP3009_AUTHORIZATION_STATE_ABI = [
|
|
@@ -73830,13 +74080,13 @@ function missingAuthorization(receipt) {
|
|
|
73830
74080
|
}
|
|
73831
74081
|
|
|
73832
74082
|
// ../core/src/movement.ts
|
|
73833
|
-
import { randomBytes as
|
|
73834
|
-
import { chmod as chmod4, mkdir as mkdir14, open as
|
|
73835
|
-
import { join as
|
|
74083
|
+
import { randomBytes as randomBytes13 } from "node:crypto";
|
|
74084
|
+
import { chmod as chmod4, mkdir as mkdir14, open as open11, readFile as readFile15, readdir as readdir5, rename as rename10, unlink as unlink10 } from "node:fs/promises";
|
|
74085
|
+
import { join as join12 } from "node:path";
|
|
73836
74086
|
|
|
73837
74087
|
// ../core/src/spend-policy.ts
|
|
73838
|
-
import { randomBytes as
|
|
73839
|
-
import { mkdir as mkdir12, open as
|
|
74088
|
+
import { randomBytes as randomBytes11 } from "node:crypto";
|
|
74089
|
+
import { mkdir as mkdir12, open as open9, readFile as readFile14, rename as rename9, stat as stat11, unlink as unlink8, writeFile as writeFile7 } from "node:fs/promises";
|
|
73840
74090
|
import { dirname as dirname8 } from "node:path";
|
|
73841
74091
|
var ledgerSchema = external_exports.object({
|
|
73842
74092
|
date: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
@@ -73907,7 +74157,7 @@ async function readSpendLedgerRows(path = getAgentCashPaths().ledger, now = /* @
|
|
|
73907
74157
|
async function readStoredSpendLedgerRows(path, now, allDays = false) {
|
|
73908
74158
|
let raw;
|
|
73909
74159
|
try {
|
|
73910
|
-
raw = await
|
|
74160
|
+
raw = await readFile14(path, "utf8");
|
|
73911
74161
|
} catch (error61) {
|
|
73912
74162
|
if (isMissingFile(error61)) return [];
|
|
73913
74163
|
throw error61;
|
|
@@ -74040,7 +74290,7 @@ async function reserveSpend(amountAtomic2, caps, options) {
|
|
|
74040
74290
|
{ amountAtomic: amountAtomic2, limitAtomic: perDayAtomic, spentAtomic: BigInt(spentAtomic), wallet }
|
|
74041
74291
|
);
|
|
74042
74292
|
}
|
|
74043
|
-
const reservationId = options?.reservationId ?? (options?.taskKey === void 0 ? void 0 :
|
|
74293
|
+
const reservationId = options?.reservationId ?? (options?.taskKey === void 0 ? void 0 : randomBytes11(16).toString("hex"));
|
|
74044
74294
|
const nextRow = {
|
|
74045
74295
|
date: utcDateKey(now),
|
|
74046
74296
|
spentAtomic: nextSpent.toString(),
|
|
@@ -74146,7 +74396,7 @@ async function writeLedgerAtomically(path, rows) {
|
|
|
74146
74396
|
...rows[0].reservations === void 0 ? {} : { reservations: rows[0].reservations }
|
|
74147
74397
|
} : { version: 1, rows };
|
|
74148
74398
|
await mkdir12(dirname8(path), { recursive: true, mode: 448 });
|
|
74149
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
74399
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes11(6).toString("hex")}.tmp`;
|
|
74150
74400
|
await writeFile7(temporaryPath, `${JSON.stringify(ledger, null, 2)}
|
|
74151
74401
|
`, {
|
|
74152
74402
|
encoding: "utf8",
|
|
@@ -74162,7 +74412,7 @@ async function withLedgerLock(path, operation) {
|
|
|
74162
74412
|
let handle;
|
|
74163
74413
|
while (!handle) {
|
|
74164
74414
|
try {
|
|
74165
|
-
handle = await
|
|
74415
|
+
handle = await open9(lockPath, "wx", 384);
|
|
74166
74416
|
} catch (error61) {
|
|
74167
74417
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) {
|
|
74168
74418
|
throw error61;
|
|
@@ -74183,7 +74433,7 @@ async function withLedgerLock(path, operation) {
|
|
|
74183
74433
|
}
|
|
74184
74434
|
async function removeStaleLock3(path) {
|
|
74185
74435
|
try {
|
|
74186
|
-
const metadata = await
|
|
74436
|
+
const metadata = await stat11(path);
|
|
74187
74437
|
if (Date.now() - metadata.mtimeMs > 3e4) {
|
|
74188
74438
|
await unlink8(path);
|
|
74189
74439
|
}
|
|
@@ -74195,8 +74445,8 @@ async function removeStaleLock3(path) {
|
|
|
74195
74445
|
}
|
|
74196
74446
|
|
|
74197
74447
|
// ../core/src/transfer.ts
|
|
74198
|
-
import { randomBytes as
|
|
74199
|
-
import { mkdir as mkdir13, open as
|
|
74448
|
+
import { randomBytes as randomBytes12, randomUUID } from "node:crypto";
|
|
74449
|
+
import { mkdir as mkdir13, open as open10, stat as stat12, unlink as unlink9 } from "node:fs/promises";
|
|
74200
74450
|
import { dirname as dirname9 } from "node:path";
|
|
74201
74451
|
|
|
74202
74452
|
// ../core/src/siblings.ts
|
|
@@ -74405,7 +74655,7 @@ async function transferBetweenAccounts(args) {
|
|
|
74405
74655
|
if (args.resume !== void 0) {
|
|
74406
74656
|
return await resumeTransfer(context, args.resume);
|
|
74407
74657
|
}
|
|
74408
|
-
const nonce = args.nonce ?? bytesToHex(
|
|
74658
|
+
const nonce = args.nonce ?? bytesToHex(randomBytes12(32));
|
|
74409
74659
|
if (!NONCE_PATTERN.test(nonce)) {
|
|
74410
74660
|
throw new TransferError(
|
|
74411
74661
|
"authorization_invalid",
|
|
@@ -74798,7 +75048,7 @@ async function withTransferLock(context, nonce, operation) {
|
|
|
74798
75048
|
let handle;
|
|
74799
75049
|
while (!handle) {
|
|
74800
75050
|
try {
|
|
74801
|
-
handle = await
|
|
75051
|
+
handle = await open10(lockPath, "wx", 384);
|
|
74802
75052
|
} catch (error61) {
|
|
74803
75053
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) throw error61;
|
|
74804
75054
|
await removeStaleTransferLock(lockPath, staleAfterMs);
|
|
@@ -74817,7 +75067,7 @@ async function withTransferLock(context, nonce, operation) {
|
|
|
74817
75067
|
}
|
|
74818
75068
|
async function removeStaleTransferLock(path, staleAfterMs) {
|
|
74819
75069
|
try {
|
|
74820
|
-
const metadata = await
|
|
75070
|
+
const metadata = await stat12(path);
|
|
74821
75071
|
if (Date.now() - metadata.mtimeMs > staleAfterMs) await unlink9(path);
|
|
74822
75072
|
} catch (error61) {
|
|
74823
75073
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "ENOENT")) throw error61;
|
|
@@ -75243,7 +75493,7 @@ async function listUnfinishedMovements(options) {
|
|
|
75243
75493
|
}
|
|
75244
75494
|
const summaries = [];
|
|
75245
75495
|
for (const name of names.filter((candidate) => candidate.endsWith(".json")).sort()) {
|
|
75246
|
-
const movement = parseMovement(JSON.parse(await
|
|
75496
|
+
const movement = parseMovement(JSON.parse(await readFile15(join12(directory, name), "utf8")));
|
|
75247
75497
|
if (options.from !== void 0 && !movement.legs.some((leg) => leg.from === options.from)) {
|
|
75248
75498
|
continue;
|
|
75249
75499
|
}
|
|
@@ -75274,7 +75524,7 @@ async function listUnfinishedMovementSnapshots(options) {
|
|
|
75274
75524
|
}
|
|
75275
75525
|
const snapshots = [];
|
|
75276
75526
|
for (const name of names.filter((candidate) => candidate.endsWith(".json")).sort()) {
|
|
75277
|
-
const movement = parseMovement(JSON.parse(await
|
|
75527
|
+
const movement = parseMovement(JSON.parse(await readFile15(join12(directory, name), "utf8")));
|
|
75278
75528
|
if (options.from !== void 0 && !movement.legs.some((leg) => leg.from === options.from)) {
|
|
75279
75529
|
continue;
|
|
75280
75530
|
}
|
|
@@ -75310,23 +75560,23 @@ async function movementHasOpenLeg(home, movement, from16) {
|
|
|
75310
75560
|
return false;
|
|
75311
75561
|
}
|
|
75312
75562
|
async function movementOpenEvidence(home, movement, from16) {
|
|
75313
|
-
let
|
|
75563
|
+
let open13 = false;
|
|
75314
75564
|
const signedFailedLegKeys = [];
|
|
75315
75565
|
for (const leg of movement.legs) {
|
|
75316
75566
|
if (from16 !== void 0 && leg.from !== from16) continue;
|
|
75317
|
-
if (isOpenMovementLeg(leg, "unsigned"))
|
|
75567
|
+
if (isOpenMovementLeg(leg, "unsigned")) open13 = true;
|
|
75318
75568
|
if (leg.status !== "failed") continue;
|
|
75319
75569
|
const journal = await readTransferJournal(home, leg.from, leg.nonce);
|
|
75320
75570
|
if (journal.signed) signedFailedLegKeys.push(movementTransferKey(leg.from, leg.nonce));
|
|
75321
|
-
if (isOpenMovementLeg(leg, journal.signed ? "signed" : "unsigned"))
|
|
75571
|
+
if (isOpenMovementLeg(leg, journal.signed ? "signed" : "unsigned")) open13 = true;
|
|
75322
75572
|
}
|
|
75323
|
-
return { open:
|
|
75573
|
+
return { open: open13, signedFailedLegKeys };
|
|
75324
75574
|
}
|
|
75325
75575
|
async function readMovement(home, id2) {
|
|
75326
75576
|
const safeId = parseMovementId(id2);
|
|
75327
75577
|
try {
|
|
75328
75578
|
return parseMovement(
|
|
75329
|
-
JSON.parse(await
|
|
75579
|
+
JSON.parse(await readFile15(join12(movementsDirectory(home), `${safeId}.json`), "utf8"))
|
|
75330
75580
|
);
|
|
75331
75581
|
} catch (error61) {
|
|
75332
75582
|
if (isMissingFile(error61)) {
|
|
@@ -76046,33 +76296,33 @@ function parseMovementId(value) {
|
|
|
76046
76296
|
return parsed.data;
|
|
76047
76297
|
}
|
|
76048
76298
|
function movementsDirectory(home) {
|
|
76049
|
-
return
|
|
76299
|
+
return join12(home, "movements");
|
|
76050
76300
|
}
|
|
76051
76301
|
function createMovementId() {
|
|
76052
|
-
return `mv_${
|
|
76302
|
+
return `mv_${randomBytes13(12).toString("hex")}`;
|
|
76053
76303
|
}
|
|
76054
76304
|
function createMovementNonce() {
|
|
76055
|
-
return bytesToHex(
|
|
76305
|
+
return bytesToHex(randomBytes13(32));
|
|
76056
76306
|
}
|
|
76057
76307
|
async function writeMovement(home, movement) {
|
|
76058
76308
|
const parsed = movementSchema.parse(movement);
|
|
76059
76309
|
const directory = movementsDirectory(home);
|
|
76060
76310
|
await mkdir14(directory, { recursive: true, mode: 448 });
|
|
76061
76311
|
await chmod4(directory, 448);
|
|
76062
|
-
const path =
|
|
76063
|
-
const temporary =
|
|
76312
|
+
const path = join12(directory, `${parsed.id}.json`);
|
|
76313
|
+
const temporary = join12(
|
|
76064
76314
|
directory,
|
|
76065
|
-
`.${parsed.id}.${process.pid}.${
|
|
76315
|
+
`.${parsed.id}.${process.pid}.${randomBytes13(6).toString("hex")}.tmp`
|
|
76066
76316
|
);
|
|
76067
76317
|
let handle;
|
|
76068
76318
|
try {
|
|
76069
|
-
handle = await
|
|
76319
|
+
handle = await open11(temporary, "wx", 384);
|
|
76070
76320
|
await handle.writeFile(serializeMovement(parsed), "utf8");
|
|
76071
76321
|
await handle.sync();
|
|
76072
76322
|
await handle.close();
|
|
76073
76323
|
handle = void 0;
|
|
76074
76324
|
await rename10(temporary, path);
|
|
76075
|
-
const directoryHandle = await
|
|
76325
|
+
const directoryHandle = await open11(directory, "r");
|
|
76076
76326
|
try {
|
|
76077
76327
|
await directoryHandle.sync();
|
|
76078
76328
|
} finally {
|
|
@@ -76292,7 +76542,7 @@ async function sweepAboveCeilingLocked(args) {
|
|
|
76292
76542
|
owner,
|
|
76293
76543
|
target,
|
|
76294
76544
|
amountAtomic: amountAtomic2.toString(),
|
|
76295
|
-
nonce: (args.randomNonce ?? (() => bytesToHex(
|
|
76545
|
+
nonce: (args.randomNonce ?? (() => bytesToHex(randomBytes14(32))))(),
|
|
76296
76546
|
createdAt: new Date(now()).toISOString(),
|
|
76297
76547
|
status: "planned"
|
|
76298
76548
|
};
|
|
@@ -77084,8 +77334,8 @@ function parseDecimal(value, scale) {
|
|
|
77084
77334
|
}
|
|
77085
77335
|
|
|
77086
77336
|
// ../core/src/swarm.ts
|
|
77087
|
-
import { readdir as readdir6, readFile as
|
|
77088
|
-
import { join as
|
|
77337
|
+
import { readdir as readdir6, readFile as readFile16, stat as stat13, unlink as unlink11 } from "node:fs/promises";
|
|
77338
|
+
import { join as join13 } from "node:path";
|
|
77089
77339
|
var SWARM_NAME_PATTERN = /^[a-z][a-z0-9-]{0,15}$/;
|
|
77090
77340
|
var SWARM_ROLE_PATTERN = /^[a-z][a-z0-9]{0,7}$/;
|
|
77091
77341
|
var DEFAULT_SWARM_MODEL = "venice/claude-sonnet-5";
|
|
@@ -77166,16 +77416,16 @@ var SwarmError = class extends Error {
|
|
|
77166
77416
|
code;
|
|
77167
77417
|
};
|
|
77168
77418
|
function swarmsDirectory(home) {
|
|
77169
|
-
return
|
|
77419
|
+
return join13(home, "swarms");
|
|
77170
77420
|
}
|
|
77171
77421
|
function swarmFilePath(home, name) {
|
|
77172
77422
|
assertName(name);
|
|
77173
|
-
return
|
|
77423
|
+
return join13(swarmsDirectory(home), `${name}.json`);
|
|
77174
77424
|
}
|
|
77175
77425
|
async function readSwarm(home, name) {
|
|
77176
77426
|
const path = swarmFilePath(home, name);
|
|
77177
77427
|
try {
|
|
77178
|
-
const swarm = parseSwarm(JSON.parse(await
|
|
77428
|
+
const swarm = parseSwarm(JSON.parse(await readFile16(path, "utf8")));
|
|
77179
77429
|
if (swarm.name !== name)
|
|
77180
77430
|
throw new SwarmError("invalid_swarm", "Swarm name does not match its file.");
|
|
77181
77431
|
return swarm;
|
|
@@ -77203,7 +77453,7 @@ async function writeSwarm(home, value) {
|
|
|
77203
77453
|
const bytes = `${JSON.stringify(swarm, null, 2)}
|
|
77204
77454
|
`;
|
|
77205
77455
|
try {
|
|
77206
|
-
if (await
|
|
77456
|
+
if (await readFile16(path, "utf8") === bytes) return;
|
|
77207
77457
|
} catch (error61) {
|
|
77208
77458
|
if (!isMissingFile(error61)) throw error61;
|
|
77209
77459
|
}
|
|
@@ -77218,7 +77468,7 @@ async function deleteSwarmFile(home, name) {
|
|
|
77218
77468
|
}
|
|
77219
77469
|
async function withSwarmLock(home, name, fn) {
|
|
77220
77470
|
assertName(name);
|
|
77221
|
-
const path =
|
|
77471
|
+
const path = join13(swarmsDirectory(home), `.${name}.lock`);
|
|
77222
77472
|
try {
|
|
77223
77473
|
return await withFileLock(path, fn, { lockedMessage: `Swarm ${name} is locked.` });
|
|
77224
77474
|
} catch (error61) {
|
|
@@ -77530,7 +77780,7 @@ async function swarmStatus(opts) {
|
|
|
77530
77780
|
);
|
|
77531
77781
|
let movementFiles;
|
|
77532
77782
|
try {
|
|
77533
|
-
movementFiles = await readdir6(
|
|
77783
|
+
movementFiles = await readdir6(join13(home, "movements"));
|
|
77534
77784
|
} catch (error61) {
|
|
77535
77785
|
if (!isMissingFile(error61)) throw error61;
|
|
77536
77786
|
movementFiles = [];
|
|
@@ -77587,11 +77837,11 @@ async function swarmStatus(opts) {
|
|
|
77587
77837
|
})
|
|
77588
77838
|
);
|
|
77589
77839
|
const accounts = new Set(swarmAccountNames(swarm));
|
|
77590
|
-
const
|
|
77840
|
+
const open13 = [];
|
|
77591
77841
|
for (const summary2 of await listUnfinishedMovements({ home })) {
|
|
77592
77842
|
const movement = await readMovement(home, summary2.id);
|
|
77593
77843
|
if (movement.treasury === swarm.treasury.account || movement.legs.some((leg) => accounts.has(leg.from) || accounts.has(leg.to))) {
|
|
77594
|
-
|
|
77844
|
+
open13.push(summary2);
|
|
77595
77845
|
}
|
|
77596
77846
|
}
|
|
77597
77847
|
return {
|
|
@@ -77600,7 +77850,7 @@ async function swarmStatus(opts) {
|
|
|
77600
77850
|
strategy: swarm.policy.strategy,
|
|
77601
77851
|
treasury,
|
|
77602
77852
|
members: members2,
|
|
77603
|
-
openMovements:
|
|
77853
|
+
openMovements: open13.sort(
|
|
77604
77854
|
(a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id)
|
|
77605
77855
|
)
|
|
77606
77856
|
};
|
|
@@ -77699,7 +77949,7 @@ async function assertNoConflicts(home, name, accounts) {
|
|
|
77699
77949
|
}
|
|
77700
77950
|
async function profileExists(home, account) {
|
|
77701
77951
|
try {
|
|
77702
|
-
await
|
|
77952
|
+
await stat13(join13(getVapiPaths(home).agentsDir, `${account}.json`));
|
|
77703
77953
|
return true;
|
|
77704
77954
|
} catch (error61) {
|
|
77705
77955
|
if (isMissingFile(error61)) return false;
|
|
@@ -77712,7 +77962,7 @@ async function refuseTreasuryProfile(home, account) {
|
|
|
77712
77962
|
}
|
|
77713
77963
|
|
|
77714
77964
|
// ../core/src/x402-pay.ts
|
|
77715
|
-
import { randomBytes as
|
|
77965
|
+
import { randomBytes as randomBytes15, randomUUID as randomUUID2 } from "node:crypto";
|
|
77716
77966
|
|
|
77717
77967
|
// ../core/src/run-budget.ts
|
|
77718
77968
|
var RunBudgetError = class extends Error {
|
|
@@ -77753,13 +78003,13 @@ function createRunBudget(args) {
|
|
|
77753
78003
|
// ../core/src/support-report.ts
|
|
77754
78004
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
77755
78005
|
import { arch, platform, release } from "node:os";
|
|
77756
|
-
import { join as
|
|
77757
|
-
var VAPI_CLIENT_VERSION = "0.
|
|
78006
|
+
import { join as join14 } from "node:path";
|
|
78007
|
+
var VAPI_CLIENT_VERSION = "0.13.0";
|
|
77758
78008
|
async function createSupportReport(options) {
|
|
77759
78009
|
const message = options.message.trim();
|
|
77760
78010
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
77761
78011
|
const paths = getVapiPaths();
|
|
77762
|
-
const reportsDirectory = options.reportsDirectory ??
|
|
78012
|
+
const reportsDirectory = options.reportsDirectory ?? join14(paths.directory, "reports");
|
|
77763
78013
|
const receipts = await readReceipts(options.receiptsPath ?? paths.receipts, { limit: 5 });
|
|
77764
78014
|
const system = options.systemInfo ?? defaultSystemInfo();
|
|
77765
78015
|
const report = {
|
|
@@ -77789,7 +78039,7 @@ async function createSupportReport(options) {
|
|
|
77789
78039
|
};
|
|
77790
78040
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
77791
78041
|
const timestamp = now.toISOString();
|
|
77792
|
-
const path =
|
|
78042
|
+
const path = join14(reportsDirectory, `${sanitizeTimestamp(timestamp)}.json`);
|
|
77793
78043
|
await mkdir15(reportsDirectory, { recursive: true, mode: 448 });
|
|
77794
78044
|
const serialized = `${JSON.stringify(report, null, 2)}
|
|
77795
78045
|
`;
|
|
@@ -77985,7 +78235,7 @@ async function completeX402Payment(args) {
|
|
|
77985
78235
|
throw walletCapError(error61, quote.amountAtomic, args);
|
|
77986
78236
|
}
|
|
77987
78237
|
} else {
|
|
77988
|
-
reservationId = args.paymentId ?? `x402_${
|
|
78238
|
+
reservationId = args.paymentId ?? `x402_${randomBytes15(12).toString("hex")}`;
|
|
77989
78239
|
let reservation;
|
|
77990
78240
|
try {
|
|
77991
78241
|
reservation = await reserveSpend(quote.amountAtomic, args.caps, {
|
|
@@ -79386,8 +79636,8 @@ function freezeScopeTerms(structuredInput, briefInput) {
|
|
|
79386
79636
|
}
|
|
79387
79637
|
|
|
79388
79638
|
// ../core/src/tasks/scope-bindings.ts
|
|
79389
|
-
import { readFile as
|
|
79390
|
-
import { join as
|
|
79639
|
+
import { readFile as readFile17 } from "node:fs/promises";
|
|
79640
|
+
import { join as join15 } from "node:path";
|
|
79391
79641
|
|
|
79392
79642
|
// ../core/src/tasks/chain-port.ts
|
|
79393
79643
|
var TasksChainError = class extends Error {
|
|
@@ -79962,7 +80212,7 @@ var messageSchema = external_exports.looseObject({
|
|
|
79962
80212
|
})
|
|
79963
80213
|
)
|
|
79964
80214
|
});
|
|
79965
|
-
var
|
|
80215
|
+
var fileSchema2 = external_exports.looseObject({
|
|
79966
80216
|
id: uuidSchema,
|
|
79967
80217
|
purpose: workFilePurposeSchema,
|
|
79968
80218
|
fileName: external_exports.string(),
|
|
@@ -80268,11 +80518,11 @@ var tasksResponseSchemas = {
|
|
|
80268
80518
|
observedAt: isoDateTimeSchema
|
|
80269
80519
|
}),
|
|
80270
80520
|
createUpload: external_exports.looseObject({
|
|
80271
|
-
file:
|
|
80521
|
+
file: fileSchema2.extend({ state: external_exports.literal("pending"), sha256: external_exports.null() }),
|
|
80272
80522
|
uploadUrl: external_exports.url()
|
|
80273
80523
|
}),
|
|
80274
80524
|
finalizeUpload: external_exports.looseObject({
|
|
80275
|
-
file:
|
|
80525
|
+
file: fileSchema2.extend({
|
|
80276
80526
|
state: external_exports.literal("ready"),
|
|
80277
80527
|
sha256: external_exports.string().regex(/^[0-9a-fA-F]{64}$/)
|
|
80278
80528
|
})
|
|
@@ -80880,10 +81130,10 @@ function key(identity) {
|
|
|
80880
81130
|
return `${identity.orderId}:${identity.trancheOrdinal}:${identity.scopeVersion}:${identity.termsHash.toLowerCase()}:${identity.self.toLowerCase()}`;
|
|
80881
81131
|
}
|
|
80882
81132
|
function createScopeBindings(home) {
|
|
80883
|
-
const path =
|
|
81133
|
+
const path = join15(home, "tasks", "scope-bindings.json");
|
|
80884
81134
|
async function read() {
|
|
80885
81135
|
try {
|
|
80886
|
-
return storeSchema.parse(JSON.parse(await
|
|
81136
|
+
return storeSchema.parse(JSON.parse(await readFile17(path, "utf8")));
|
|
80887
81137
|
} catch (error61) {
|
|
80888
81138
|
if (error61 instanceof Error && "code" in error61 && error61.code === "ENOENT")
|
|
80889
81139
|
return { version: 1, bindings: {} };
|
|
@@ -81564,7 +81814,7 @@ function createTasksChain(options) {
|
|
|
81564
81814
|
const { account, client, pending, rpcFor } = options;
|
|
81565
81815
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
81566
81816
|
const sleep = options.sleep ?? ((ms) => new Promise((resolve3) => setTimeout(resolve3, ms)));
|
|
81567
|
-
const
|
|
81817
|
+
const randomBytes18 = options.randomBytes ?? cryptoRandomBytes2;
|
|
81568
81818
|
const confirmations = options.confirmations ?? 2;
|
|
81569
81819
|
if (!Number.isSafeInteger(confirmations) || confirmations < 1)
|
|
81570
81820
|
throw new TasksChainError("Tasks confirmations must be a positive integer.", false, {
|
|
@@ -82173,7 +82423,7 @@ function createTasksChain(options) {
|
|
|
82173
82423
|
await verifyClone(rpcFor(ready.chainId), expected, true);
|
|
82174
82424
|
if (validBefore <= BigInt(Math.floor(now().getTime() / 1e3)))
|
|
82175
82425
|
throw new TasksValidationError("The task funding offer has expired.");
|
|
82176
|
-
const bytes =
|
|
82426
|
+
const bytes = randomBytes18(32);
|
|
82177
82427
|
if (bytes.length !== 32)
|
|
82178
82428
|
throw new TasksValidationError(
|
|
82179
82429
|
"Funding authorization randomness must contain 32 bytes."
|
|
@@ -82451,8 +82701,8 @@ function createTasksRpcFor(config2, options = {}) {
|
|
|
82451
82701
|
}
|
|
82452
82702
|
|
|
82453
82703
|
// ../core/src/tasks/pending-transactions.ts
|
|
82454
|
-
import { readFile as
|
|
82455
|
-
import { join as
|
|
82704
|
+
import { readFile as readFile18 } from "node:fs/promises";
|
|
82705
|
+
import { join as join16 } from "node:path";
|
|
82456
82706
|
var hex3 = external_exports.string().regex(/^0x(?:[0-9a-fA-F]{2})+$/).transform((v) => v);
|
|
82457
82707
|
var hash4 = external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/).transform((v) => v);
|
|
82458
82708
|
var step = external_exports.enum([
|
|
@@ -82534,11 +82784,11 @@ function validCheckpointStep(storedStep, response) {
|
|
|
82534
82784
|
}[response.operation.kind];
|
|
82535
82785
|
}
|
|
82536
82786
|
function createPendingTransactions(home) {
|
|
82537
|
-
const path =
|
|
82787
|
+
const path = join16(home, "tasks", "pending.json");
|
|
82538
82788
|
const lockPath = `${path}.lock`;
|
|
82539
82789
|
const read = async () => {
|
|
82540
82790
|
try {
|
|
82541
|
-
const state = stateSchema.parse(JSON.parse(await
|
|
82791
|
+
const state = stateSchema.parse(JSON.parse(await readFile18(path, "utf8")));
|
|
82542
82792
|
for (const [key2, value] of Object.entries(state.checkpoints)) {
|
|
82543
82793
|
const separator = key2.indexOf(":");
|
|
82544
82794
|
const operationId = key2.slice(0, separator);
|
|
@@ -82601,7 +82851,7 @@ function createPendingTransactions(home) {
|
|
|
82601
82851
|
},
|
|
82602
82852
|
withStepLock(operationId, step2, fn) {
|
|
82603
82853
|
return withFileLock(
|
|
82604
|
-
|
|
82854
|
+
join16(
|
|
82605
82855
|
home,
|
|
82606
82856
|
"tasks",
|
|
82607
82857
|
`step-${encodeURIComponent(operationId)}-${encodeURIComponent(step2)}.lock`
|
|
@@ -82613,13 +82863,13 @@ function createPendingTransactions(home) {
|
|
|
82613
82863
|
external_exports.number().int().positive().parse(chainId);
|
|
82614
82864
|
address3.parse(signer);
|
|
82615
82865
|
return withFileLock(
|
|
82616
|
-
|
|
82866
|
+
join16(home, "tasks", `signer-${chainId}-${signer.toLowerCase()}.lock`),
|
|
82617
82867
|
fn
|
|
82618
82868
|
);
|
|
82619
82869
|
},
|
|
82620
82870
|
withFundingLock(milestoneId, fn) {
|
|
82621
82871
|
milestoneKey(milestoneId);
|
|
82622
|
-
return withFileLock(
|
|
82872
|
+
return withFileLock(join16(home, "tasks", `fund-${milestoneId}.lock`), fn);
|
|
82623
82873
|
},
|
|
82624
82874
|
async nextNonce(chainId, signer) {
|
|
82625
82875
|
external_exports.number().int().positive().parse(chainId);
|
|
@@ -83445,7 +83695,7 @@ function policyAtomic(value) {
|
|
|
83445
83695
|
}
|
|
83446
83696
|
|
|
83447
83697
|
// ../core/src/tasks/operation-support.ts
|
|
83448
|
-
import { readFile as
|
|
83698
|
+
import { readFile as readFile19, stat as stat14 } from "node:fs/promises";
|
|
83449
83699
|
import { basename as basename3, extname } from "node:path";
|
|
83450
83700
|
var TaskOperationError = class extends Error {
|
|
83451
83701
|
constructor(code, message, manifestHash) {
|
|
@@ -83613,7 +83863,7 @@ function parseTaskDuration(text, now) {
|
|
|
83613
83863
|
async function readTaskFile(path) {
|
|
83614
83864
|
let details;
|
|
83615
83865
|
try {
|
|
83616
|
-
details = await
|
|
83866
|
+
details = await stat14(path);
|
|
83617
83867
|
} catch {
|
|
83618
83868
|
throw new TaskInputError(`Task file ${JSON.stringify(path)} could not be read.`);
|
|
83619
83869
|
}
|
|
@@ -83637,7 +83887,7 @@ async function readTaskFile(path) {
|
|
|
83637
83887
|
const contentType = types[extname(path).toLowerCase()];
|
|
83638
83888
|
if (!contentType)
|
|
83639
83889
|
throw new TaskInputError("Task files must be images, PDF, ZIP, text, Markdown, JSON or CSV.");
|
|
83640
|
-
const bytes = await
|
|
83890
|
+
const bytes = await readFile19(path);
|
|
83641
83891
|
if (bytes.length < TASK_LIMITS.uploadBytesMin || bytes.length > TASK_LIMITS.uploadBytesMax)
|
|
83642
83892
|
throw new TaskInputError("Task files must contain between 1 byte and 50 MiB.");
|
|
83643
83893
|
return {
|
|
@@ -84436,7 +84686,7 @@ async function resolveUnmatchedTaskOperation(context, input2) {
|
|
|
84436
84686
|
}
|
|
84437
84687
|
|
|
84438
84688
|
// ../core/src/searches.ts
|
|
84439
|
-
import { mkdir as mkdir16, open as
|
|
84689
|
+
import { mkdir as mkdir16, open as open12, readFile as readFile20 } from "node:fs/promises";
|
|
84440
84690
|
import { dirname as dirname10 } from "node:path";
|
|
84441
84691
|
var searchEventSchema = external_exports.strictObject({
|
|
84442
84692
|
timestamp: external_exports.iso.datetime(),
|
|
@@ -84458,7 +84708,7 @@ function parseSearchEvent(value) {
|
|
|
84458
84708
|
async function appendSearchEvent(event, path = getVapiPaths().searches) {
|
|
84459
84709
|
const parsed = parseSearchEvent(event);
|
|
84460
84710
|
await mkdir16(dirname10(path), { recursive: true, mode: 448 });
|
|
84461
|
-
const handle = await
|
|
84711
|
+
const handle = await open12(path, "a", 384);
|
|
84462
84712
|
try {
|
|
84463
84713
|
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
84464
84714
|
`, "utf8");
|
|
@@ -84470,7 +84720,7 @@ async function appendSearchEvent(event, path = getVapiPaths().searches) {
|
|
|
84470
84720
|
async function readSearchEvents(path = getVapiPaths().searches) {
|
|
84471
84721
|
let raw;
|
|
84472
84722
|
try {
|
|
84473
|
-
raw = await
|
|
84723
|
+
raw = await readFile20(path, "utf8");
|
|
84474
84724
|
} catch (error61) {
|
|
84475
84725
|
if (isMissingFile(error61)) return [];
|
|
84476
84726
|
throw error61;
|
|
@@ -85372,9 +85622,9 @@ function csvCell(value) {
|
|
|
85372
85622
|
}
|
|
85373
85623
|
|
|
85374
85624
|
// ../core/src/swarm-capital.ts
|
|
85375
|
-
import { createHash as createHash5, randomBytes as
|
|
85376
|
-
import { readFile as
|
|
85377
|
-
import { join as
|
|
85625
|
+
import { createHash as createHash5, randomBytes as randomBytes16 } from "node:crypto";
|
|
85626
|
+
import { readFile as readFile21, unlink as unlink12 } from "node:fs/promises";
|
|
85627
|
+
import { join as join17 } from "node:path";
|
|
85378
85628
|
var movementIdSchema3 = external_exports.string().regex(/^mv_[A-Za-z0-9_-]{8,128}$/u);
|
|
85379
85629
|
var amountSchema2 = external_exports.string().regex(/^\d+\.\d{2}$/u);
|
|
85380
85630
|
var requestIdSchema = external_exports.string().min(1).max(512);
|
|
@@ -86255,7 +86505,7 @@ async function readDelegationRecord(home, movementId) {
|
|
|
86255
86505
|
const safeId = runRecordMovementId(movementId);
|
|
86256
86506
|
try {
|
|
86257
86507
|
const record2 = delegationRecordSchema.parse(
|
|
86258
|
-
JSON.parse(await
|
|
86508
|
+
JSON.parse(await readFile21(delegationRecordPath(home, safeId), "utf8"))
|
|
86259
86509
|
);
|
|
86260
86510
|
if (record2.movementId !== safeId) {
|
|
86261
86511
|
throw new SwarmError(
|
|
@@ -86282,7 +86532,7 @@ async function readTreasuryRequestRecord(home, movementId) {
|
|
|
86282
86532
|
const safeId = runRecordMovementId(movementId);
|
|
86283
86533
|
try {
|
|
86284
86534
|
const record2 = treasuryRequestRecordSchema.parse(
|
|
86285
|
-
JSON.parse(await
|
|
86535
|
+
JSON.parse(await readFile21(treasuryRequestRecordPath(home, safeId), "utf8"))
|
|
86286
86536
|
);
|
|
86287
86537
|
if (record2.movementId !== safeId) {
|
|
86288
86538
|
throw new SwarmError(
|
|
@@ -86313,18 +86563,18 @@ function runRecordMovementId(value) {
|
|
|
86313
86563
|
return parsed.data;
|
|
86314
86564
|
}
|
|
86315
86565
|
function treasuryRequestRecordPath(home, movementId) {
|
|
86316
|
-
return
|
|
86566
|
+
return join17(home, "runs", "requests", `${movementId}.json`);
|
|
86317
86567
|
}
|
|
86318
86568
|
function delegationRecordPath(home, movementId) {
|
|
86319
|
-
return
|
|
86569
|
+
return join17(home, "runs", "delegations", `${movementId}.json`);
|
|
86320
86570
|
}
|
|
86321
86571
|
function legacyFundingProgressPath(home, name) {
|
|
86322
|
-
return
|
|
86572
|
+
return join17(home, "swarms", `.${name}.funding`);
|
|
86323
86573
|
}
|
|
86324
86574
|
async function readLegacyFundingProgress(home, name) {
|
|
86325
86575
|
try {
|
|
86326
86576
|
const progress = legacyFundingProgressSchema.parse(
|
|
86327
|
-
JSON.parse(await
|
|
86577
|
+
JSON.parse(await readFile21(legacyFundingProgressPath(home, name), "utf8"))
|
|
86328
86578
|
);
|
|
86329
86579
|
if (progress.name !== name) {
|
|
86330
86580
|
throw new SwarmError("invalid_swarm", `Invalid funding progress for swarm ${name}.`);
|
|
@@ -86553,7 +86803,7 @@ async function optionalMovement(home, id2) {
|
|
|
86553
86803
|
}
|
|
86554
86804
|
}
|
|
86555
86805
|
function nextMovementId(deps) {
|
|
86556
|
-
return movementIdSchema3.parse(deps.randomId?.() ?? `mv_${
|
|
86806
|
+
return movementIdSchema3.parse(deps.randomId?.() ?? `mv_${randomBytes16(12).toString("hex")}`);
|
|
86557
86807
|
}
|
|
86558
86808
|
async function executeRecordedMovement(id2, plan, deps, home, options = {}) {
|
|
86559
86809
|
try {
|
|
@@ -86969,7 +87219,7 @@ async function removeMemberLocked(home, swarm, account) {
|
|
|
86969
87219
|
}
|
|
86970
87220
|
|
|
86971
87221
|
// ../core/src/status.ts
|
|
86972
|
-
import { join as
|
|
87222
|
+
import { join as join18 } from "node:path";
|
|
86973
87223
|
var STATUS_TIMEOUT_MS = 2e3;
|
|
86974
87224
|
async function buildStatus(deps) {
|
|
86975
87225
|
const timers = deps.timers ?? { setTimeout, clearTimeout };
|
|
@@ -87025,7 +87275,7 @@ function formatUsdAmount(value) {
|
|
|
87025
87275
|
}
|
|
87026
87276
|
async function readVaultStatus(deps) {
|
|
87027
87277
|
const store = deps.secrets.description.replace(/^the /u, "");
|
|
87028
|
-
const path =
|
|
87278
|
+
const path = join18(deps.home, "vault.json");
|
|
87029
87279
|
let file2;
|
|
87030
87280
|
try {
|
|
87031
87281
|
file2 = await readVaultFileUnlocked(path);
|
|
@@ -87731,7 +87981,7 @@ function assertKeyMatchesAddress(bundle) {
|
|
|
87731
87981
|
}
|
|
87732
87982
|
|
|
87733
87983
|
// ../core/src/api-key.ts
|
|
87734
|
-
import { chmod as chmod5, mkdir as mkdir17, readFile as
|
|
87984
|
+
import { chmod as chmod5, mkdir as mkdir17, readFile as readFile22, rename as rename11, writeFile as writeFile9 } from "node:fs/promises";
|
|
87735
87985
|
import { dirname as dirname11 } from "node:path";
|
|
87736
87986
|
var API_KEY_PREFIX = "vapi_sk_";
|
|
87737
87987
|
var API_KEY_PATTERN = /^vapi_sk_[A-Za-z0-9_-]{16,128}$/;
|
|
@@ -87827,7 +88077,7 @@ async function readConfigApiKey(path) {
|
|
|
87827
88077
|
async function readConfigRecord(path) {
|
|
87828
88078
|
let raw;
|
|
87829
88079
|
try {
|
|
87830
|
-
raw = await
|
|
88080
|
+
raw = await readFile22(path, "utf8");
|
|
87831
88081
|
} catch (error61) {
|
|
87832
88082
|
if (isMissingFile(error61)) return void 0;
|
|
87833
88083
|
throw error61;
|
|
@@ -90497,8 +90747,8 @@ function exactPriceFact(value) {
|
|
|
90497
90747
|
}
|
|
90498
90748
|
|
|
90499
90749
|
// ../mcp/src/agent/runtime.ts
|
|
90500
|
-
import { mkdir as mkdir18, readFile as
|
|
90501
|
-
import { join as
|
|
90750
|
+
import { mkdir as mkdir18, readFile as readFile23, readdir as readdir7, rm as rm2 } from "node:fs/promises";
|
|
90751
|
+
import { join as join19 } from "node:path";
|
|
90502
90752
|
|
|
90503
90753
|
// ../mcp/src/agent/run.ts
|
|
90504
90754
|
var loopSearchResultSchema = external_exports.array(
|
|
@@ -91799,19 +92049,19 @@ var runRecordSchema = external_exports.strictObject({
|
|
|
91799
92049
|
detail: external_exports.string().optional()
|
|
91800
92050
|
});
|
|
91801
92051
|
function runsDirectory(home) {
|
|
91802
|
-
return
|
|
92052
|
+
return join19(home, "runs");
|
|
91803
92053
|
}
|
|
91804
92054
|
function runRecordPath(home, runId) {
|
|
91805
92055
|
assertRunId(runId);
|
|
91806
|
-
return
|
|
92056
|
+
return join19(runsDirectory(home), `${runId}.json`);
|
|
91807
92057
|
}
|
|
91808
92058
|
function runLogPath(home, runId) {
|
|
91809
92059
|
assertRunId(runId);
|
|
91810
|
-
return
|
|
92060
|
+
return join19(runsDirectory(home), `${runId}.log`);
|
|
91811
92061
|
}
|
|
91812
92062
|
function runResultPath(home, runId) {
|
|
91813
92063
|
assertRunId(runId);
|
|
91814
|
-
return
|
|
92064
|
+
return join19(runsDirectory(home), `${runId}.result.json`);
|
|
91815
92065
|
}
|
|
91816
92066
|
async function writeRunRecord(home, record2) {
|
|
91817
92067
|
const path = runRecordPath(home, record2.runId);
|
|
@@ -91822,7 +92072,7 @@ async function writeRunRecord(home, record2) {
|
|
|
91822
92072
|
async function readRunRecord(home, runId) {
|
|
91823
92073
|
const path = runRecordPath(home, runId);
|
|
91824
92074
|
try {
|
|
91825
|
-
return runRecordSchema.parse(JSON.parse(await
|
|
92075
|
+
return runRecordSchema.parse(JSON.parse(await readFile23(path, "utf8")));
|
|
91826
92076
|
} catch (error61) {
|
|
91827
92077
|
if (isMissingFile3(error61)) return void 0;
|
|
91828
92078
|
throw error61;
|
|
@@ -91842,7 +92092,7 @@ async function listRunRecords(home, filter = {}) {
|
|
|
91842
92092
|
if (match === null) continue;
|
|
91843
92093
|
try {
|
|
91844
92094
|
const record2 = runRecordSchema.parse(
|
|
91845
|
-
JSON.parse(await
|
|
92095
|
+
JSON.parse(await readFile23(join19(runsDirectory(home), file2), "utf8"))
|
|
91846
92096
|
);
|
|
91847
92097
|
if (record2.runId !== match[1]) continue;
|
|
91848
92098
|
if (filter.swarm !== void 0 && record2.member.swarm !== filter.swarm) continue;
|
|
@@ -92119,7 +92369,7 @@ async function stopRun(args) {
|
|
|
92119
92369
|
}
|
|
92120
92370
|
}
|
|
92121
92371
|
function memberRunLockPath(home, account) {
|
|
92122
|
-
return
|
|
92372
|
+
return join19(runsDirectory(home), `.member-${account}.lock`);
|
|
92123
92373
|
}
|
|
92124
92374
|
function summarizeRunRecord(record2) {
|
|
92125
92375
|
return {
|
|
@@ -95723,8 +95973,8 @@ function rgbToAnsi256(red, green, blue) {
|
|
|
95723
95973
|
}
|
|
95724
95974
|
|
|
95725
95975
|
// ../cli/src/accounts.ts
|
|
95726
|
-
import { readFile as
|
|
95727
|
-
import { join as
|
|
95976
|
+
import { readFile as readFile25, stat as stat16 } from "node:fs/promises";
|
|
95977
|
+
import { join as join22 } from "node:path";
|
|
95728
95978
|
|
|
95729
95979
|
// ../cli/src/dashboard.ts
|
|
95730
95980
|
import { resolve as resolve2 } from "node:path";
|
|
@@ -95735,7 +95985,12 @@ var PROBE_MODES = ["origin", "endpoint", "openapi"];
|
|
|
95735
95985
|
var PAYOUT_CHAIN_ID = "eip155:8453";
|
|
95736
95986
|
var PAYOUT_STATEMENT = "Confirm this wallet receives vAPI Call payouts";
|
|
95737
95987
|
var CLAIM_STATEMENT_PREFIX = "Claim the vAPI Call listings served from";
|
|
95738
|
-
|
|
95988
|
+
function apiKeyConsoleUrl(baseUrl) {
|
|
95989
|
+
const url2 = listingsUrl(baseUrl, "/connect");
|
|
95990
|
+
url2.search = "advanced=keys";
|
|
95991
|
+
url2.hash = "api-keys";
|
|
95992
|
+
return url2;
|
|
95993
|
+
}
|
|
95739
95994
|
var RegistryApiError = class extends Error {
|
|
95740
95995
|
constructor(status, message, body) {
|
|
95741
95996
|
super(message);
|
|
@@ -95895,7 +96150,7 @@ async function registryError(response, baseUrl) {
|
|
|
95895
96150
|
[
|
|
95896
96151
|
"The vAPI API key was rejected.",
|
|
95897
96152
|
detail,
|
|
95898
|
-
`Create a key in the console at ${
|
|
96153
|
+
`Create a key in the console at ${apiKeyConsoleUrl(baseUrl).href} and store it with vapi auth set-key.`
|
|
95899
96154
|
].filter(Boolean).join(" "),
|
|
95900
96155
|
body
|
|
95901
96156
|
);
|
|
@@ -96396,12 +96651,12 @@ function shellQuote2(value) {
|
|
|
96396
96651
|
}
|
|
96397
96652
|
|
|
96398
96653
|
// ../cli/src/status.ts
|
|
96399
|
-
import { stat as
|
|
96654
|
+
import { stat as stat15 } from "node:fs/promises";
|
|
96400
96655
|
import { homedir as homedir2 } from "node:os";
|
|
96401
96656
|
import { sep } from "node:path";
|
|
96402
96657
|
|
|
96403
96658
|
// ../core/src/cloud-backup.ts
|
|
96404
|
-
import { join as
|
|
96659
|
+
import { join as join21 } from "node:path";
|
|
96405
96660
|
|
|
96406
96661
|
// ../core/src/backup.ts
|
|
96407
96662
|
import {
|
|
@@ -96424,11 +96679,11 @@ import {
|
|
|
96424
96679
|
mkdir as mkdir19,
|
|
96425
96680
|
mkdtemp,
|
|
96426
96681
|
open as openFile,
|
|
96427
|
-
readFile as
|
|
96682
|
+
readFile as readFile24,
|
|
96428
96683
|
readdir as readdir8,
|
|
96429
96684
|
rm as rm3
|
|
96430
96685
|
} from "node:fs/promises";
|
|
96431
|
-
import { dirname as dirname12, join as
|
|
96686
|
+
import { dirname as dirname12, join as join20 } from "node:path";
|
|
96432
96687
|
var ERROR_MESSAGES = {
|
|
96433
96688
|
backup_too_large: "Backup envelope exceeds 65,536 bytes.",
|
|
96434
96689
|
backup_open_failed: "Unable to open backup.",
|
|
@@ -96711,8 +96966,8 @@ async function createBackup(options) {
|
|
|
96711
96966
|
assertDevice(options.device);
|
|
96712
96967
|
assertOwnerKey(options.ownerKey);
|
|
96713
96968
|
const createdAt = readCreatedAt(options.now ?? (() => /* @__PURE__ */ new Date()));
|
|
96714
|
-
const
|
|
96715
|
-
const nonce = readRandomBytes(
|
|
96969
|
+
const randomBytes18 = options.randomBytes ?? cryptoRandomBytes3;
|
|
96970
|
+
const nonce = readRandomBytes(randomBytes18, 12);
|
|
96716
96971
|
const salt = encodeBase64Url(options.ownerKey.salt);
|
|
96717
96972
|
const kdf = options.ownerKey.kdf === "hkdf-sha256" ? { name: "hkdf-sha256", salt } : { name: "scrypt", salt, N: SCRYPT_N2, r: SCRYPT_R2, p: SCRYPT_P2 };
|
|
96718
96973
|
const cipher = { name: CIPHER_NAME, nonce: encodeBase64Url(nonce) };
|
|
@@ -96906,7 +97161,7 @@ async function exportBackupSource(options) {
|
|
|
96906
97161
|
var BackupSnapshotChangedError = class extends Error {
|
|
96907
97162
|
};
|
|
96908
97163
|
async function exportBackupSourceAttempt(options, networks) {
|
|
96909
|
-
const path =
|
|
97164
|
+
const path = join20(options.store.home, "vault.json");
|
|
96910
97165
|
const { phrase, file: file2, accounts } = await withVaultLock(path, async () => {
|
|
96911
97166
|
const [phrase2, vault, file3] = await Promise.all([
|
|
96912
97167
|
exportVaultPhrase({ path, key: options.vaultKey }),
|
|
@@ -97042,16 +97297,16 @@ async function restoreBackupPlaintext(options) {
|
|
|
97042
97297
|
} catch {
|
|
97043
97298
|
throw new BackupError("backup_invalid_input");
|
|
97044
97299
|
}
|
|
97045
|
-
const vaultPath2 =
|
|
97046
|
-
const registryPath =
|
|
97300
|
+
const vaultPath2 = join20(options.home, "vault.json");
|
|
97301
|
+
const registryPath = join20(options.home, "wallets.json");
|
|
97047
97302
|
let stagingHome;
|
|
97048
97303
|
let beforePublishError;
|
|
97049
97304
|
let afterPublishError;
|
|
97050
97305
|
try {
|
|
97051
97306
|
await mkdir19(options.home, { recursive: true, mode: 448 });
|
|
97052
|
-
stagingHome = await mkdtemp(
|
|
97053
|
-
const stagedVaultPath =
|
|
97054
|
-
const stagedRegistryPath =
|
|
97307
|
+
stagingHome = await mkdtemp(join20(options.home, ".backup-restore-"));
|
|
97308
|
+
const stagedVaultPath = join20(stagingHome, "vault.json");
|
|
97309
|
+
const stagedRegistryPath = join20(stagingHome, "wallets.json");
|
|
97055
97310
|
await createVault({
|
|
97056
97311
|
path: stagedVaultPath,
|
|
97057
97312
|
key: options.vaultKey,
|
|
@@ -97110,7 +97365,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
97110
97365
|
protected: plaintext.protected,
|
|
97111
97366
|
networks: [...plaintext.registry.networks]
|
|
97112
97367
|
};
|
|
97113
|
-
const markerPath =
|
|
97368
|
+
const markerPath = join20(options.home, RESTORE_MARKER_FILE);
|
|
97114
97369
|
const fingerprint = restoreFingerprint(
|
|
97115
97370
|
plaintext,
|
|
97116
97371
|
stagedV2?.restoreDevice ?? options.device,
|
|
@@ -97321,13 +97576,13 @@ async function stageV2Restore(options) {
|
|
|
97321
97576
|
}
|
|
97322
97577
|
const agents = [];
|
|
97323
97578
|
for (const profile of validAgents) {
|
|
97324
|
-
const stagedPath =
|
|
97579
|
+
const stagedPath = join20(options.stagingHome, "agents", `${profile.name}.json`);
|
|
97325
97580
|
if (await stageRestoreBytes(stagedPath, prettyJson(profile))) {
|
|
97326
97581
|
agents.push({
|
|
97327
97582
|
kind: "agent",
|
|
97328
97583
|
name: profile.name,
|
|
97329
97584
|
stagedPath,
|
|
97330
|
-
targetPath:
|
|
97585
|
+
targetPath: join20(options.home, "agents", `${profile.name}.json`)
|
|
97331
97586
|
});
|
|
97332
97587
|
} else {
|
|
97333
97588
|
skipped2.push({ kind: "agent", name: profile.name, reason: "write_failed" });
|
|
@@ -97347,13 +97602,13 @@ async function stageV2Restore(options) {
|
|
|
97347
97602
|
if (restoreDevice !== void 0) {
|
|
97348
97603
|
for (const value of validSwarms) {
|
|
97349
97604
|
const swarm = swarmFileSchema.parse({ ...value, device: restoreDevice });
|
|
97350
|
-
const stagedPath =
|
|
97605
|
+
const stagedPath = join20(options.stagingHome, "swarms", `${swarm.name}.json`);
|
|
97351
97606
|
if (await stageRestoreBytes(stagedPath, prettyJson(swarm))) {
|
|
97352
97607
|
swarms.push({
|
|
97353
97608
|
kind: "swarm",
|
|
97354
97609
|
name: swarm.name,
|
|
97355
97610
|
stagedPath,
|
|
97356
|
-
targetPath:
|
|
97611
|
+
targetPath: join20(options.home, "swarms", `${swarm.name}.json`)
|
|
97357
97612
|
});
|
|
97358
97613
|
} else {
|
|
97359
97614
|
skipped2.push({ kind: "swarm", name: swarm.name, reason: "write_failed" });
|
|
@@ -97363,13 +97618,13 @@ async function stageV2Restore(options) {
|
|
|
97363
97618
|
const movements = [];
|
|
97364
97619
|
for (const movement of validMovements) {
|
|
97365
97620
|
const restored = reconcileRestoredMovement(movement, assumedReceiptKeys);
|
|
97366
|
-
const stagedPath =
|
|
97621
|
+
const stagedPath = join20(options.stagingHome, "movements", `${restored.id}.json`);
|
|
97367
97622
|
if (await stageRestoreBytes(stagedPath, serializeMovement(restored))) {
|
|
97368
97623
|
movements.push({
|
|
97369
97624
|
kind: "movement",
|
|
97370
97625
|
name: restored.id,
|
|
97371
97626
|
stagedPath,
|
|
97372
|
-
targetPath:
|
|
97627
|
+
targetPath: join20(options.home, "movements", `${restored.id}.json`),
|
|
97373
97628
|
movement: restored
|
|
97374
97629
|
});
|
|
97375
97630
|
} else {
|
|
@@ -97440,8 +97695,8 @@ async function publishRestoreFile(file2, staged) {
|
|
|
97440
97695
|
let identical = false;
|
|
97441
97696
|
try {
|
|
97442
97697
|
const [source, target] = await Promise.all([
|
|
97443
|
-
|
|
97444
|
-
|
|
97698
|
+
readFile24(file2.stagedPath),
|
|
97699
|
+
readFile24(file2.targetPath)
|
|
97445
97700
|
]);
|
|
97446
97701
|
identical = source.equals(target);
|
|
97447
97702
|
} catch {
|
|
@@ -97473,7 +97728,7 @@ async function publishRestoreReceiptsLocked(staged, targetPath) {
|
|
|
97473
97728
|
let existing = "";
|
|
97474
97729
|
let existingLines = /* @__PURE__ */ new Set();
|
|
97475
97730
|
try {
|
|
97476
|
-
await
|
|
97731
|
+
await readFile24(staged.receiptsPath, "utf8");
|
|
97477
97732
|
await mkdir19(dirname12(targetPath), { recursive: true, mode: 448 });
|
|
97478
97733
|
try {
|
|
97479
97734
|
const journal = await readRestoreReceiptJournal(targetPath);
|
|
@@ -97528,7 +97783,7 @@ async function reconcilePublishedMovements(staged, home, requireDurableSafety =
|
|
|
97528
97783
|
const unjournaledKeys = new Set([...signedKeys].filter((key2) => !journaledKeys.has(key2)));
|
|
97529
97784
|
let files;
|
|
97530
97785
|
try {
|
|
97531
|
-
files = await readdir8(
|
|
97786
|
+
files = await readdir8(join20(home, "movements"));
|
|
97532
97787
|
} catch (error61) {
|
|
97533
97788
|
if (isMissingFile4(error61)) return;
|
|
97534
97789
|
if (requireDurableSafety && unjournaledKeys.size > 0) throw error61;
|
|
@@ -97629,9 +97884,9 @@ function assertRelayKey(value) {
|
|
|
97629
97884
|
throw new BackupError("relay_invalid_key");
|
|
97630
97885
|
}
|
|
97631
97886
|
}
|
|
97632
|
-
function readRelayRandomBytes(
|
|
97887
|
+
function readRelayRandomBytes(randomBytes18, length) {
|
|
97633
97888
|
try {
|
|
97634
|
-
const value =
|
|
97889
|
+
const value = randomBytes18(length);
|
|
97635
97890
|
if (!(value instanceof Uint8Array) || value.byteLength !== length) throw new Error();
|
|
97636
97891
|
return Buffer.from(value);
|
|
97637
97892
|
} catch {
|
|
@@ -97749,7 +98004,7 @@ async function createRestoreMarker(vaultPath2, registryPath, fingerprint, vaultK
|
|
|
97749
98004
|
}
|
|
97750
98005
|
async function readRestoreMarker(path, fingerprint, vaultKey) {
|
|
97751
98006
|
try {
|
|
97752
|
-
const marker = restoreMarkerSchema.parse(JSON.parse(await
|
|
98007
|
+
const marker = restoreMarkerSchema.parse(JSON.parse(await readFile24(path, "utf8")));
|
|
97753
98008
|
const expectedMac = restoreMarkerMac(marker, vaultKey);
|
|
97754
98009
|
if (marker.fingerprint !== fingerprint || !timingSafeEqual(Buffer.from(marker.mac, "hex"), Buffer.from(expectedMac, "hex"))) {
|
|
97755
98010
|
throw new Error();
|
|
@@ -97766,7 +98021,7 @@ function restoreMarkerMac(marker, vaultKey) {
|
|
|
97766
98021
|
).digest("hex");
|
|
97767
98022
|
}
|
|
97768
98023
|
async function sha256File(path) {
|
|
97769
|
-
return createHash6("sha256").update(await
|
|
98024
|
+
return createHash6("sha256").update(await readFile24(path)).digest("hex");
|
|
97770
98025
|
}
|
|
97771
98026
|
async function notifyRestorePublish(hook, step2, rememberError) {
|
|
97772
98027
|
try {
|
|
@@ -98068,7 +98323,7 @@ function copyTransferReceipt(receipt) {
|
|
|
98068
98323
|
async function readReceiptJournal(path) {
|
|
98069
98324
|
let raw;
|
|
98070
98325
|
try {
|
|
98071
|
-
raw = await
|
|
98326
|
+
raw = await readFile24(path, "utf8");
|
|
98072
98327
|
} catch (error61) {
|
|
98073
98328
|
if (isMissingFile4(error61)) return [];
|
|
98074
98329
|
throw error61;
|
|
@@ -98078,7 +98333,7 @@ async function readReceiptJournal(path) {
|
|
|
98078
98333
|
async function readRestoreReceiptJournal(path) {
|
|
98079
98334
|
let raw;
|
|
98080
98335
|
try {
|
|
98081
|
-
raw = await
|
|
98336
|
+
raw = await readFile24(path, "utf8");
|
|
98082
98337
|
} catch (error61) {
|
|
98083
98338
|
if (isMissingFile4(error61)) return { raw: "", lines: /* @__PURE__ */ new Set(), signedKeys: /* @__PURE__ */ new Set() };
|
|
98084
98339
|
throw error61;
|
|
@@ -98197,8 +98452,8 @@ function assertOwnerKey(ownerKey) {
|
|
|
98197
98452
|
assertBytes(ownerKey.key, 32);
|
|
98198
98453
|
assertBytes(ownerKey.salt, 32);
|
|
98199
98454
|
}
|
|
98200
|
-
function readRandomBytes(
|
|
98201
|
-
const value =
|
|
98455
|
+
function readRandomBytes(randomBytes18, length) {
|
|
98456
|
+
const value = randomBytes18(length);
|
|
98202
98457
|
if (!(value instanceof Uint8Array) || value.byteLength !== length) {
|
|
98203
98458
|
throw new BackupError("backup_invalid_input");
|
|
98204
98459
|
}
|
|
@@ -98437,7 +98692,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
98437
98692
|
try {
|
|
98438
98693
|
let vaultFile;
|
|
98439
98694
|
try {
|
|
98440
|
-
vaultFile = await readVaultFileUnlocked(
|
|
98695
|
+
vaultFile = await readVaultFileUnlocked(join21(options.store.home, "vault.json"));
|
|
98441
98696
|
} catch (error61) {
|
|
98442
98697
|
if (error61 instanceof VaultError && error61.code === "not_found") {
|
|
98443
98698
|
return { status: "skipped", reason: "no_vault" };
|
|
@@ -98446,7 +98701,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
98446
98701
|
}
|
|
98447
98702
|
try {
|
|
98448
98703
|
vaultKey = vaultFile.protected ? await unlockProtectedVault({
|
|
98449
|
-
path:
|
|
98704
|
+
path: join21(options.store.home, "vault.json"),
|
|
98450
98705
|
secrets: options.secrets,
|
|
98451
98706
|
env: options.env,
|
|
98452
98707
|
...options.now === void 0 ? {} : { now: options.now }
|
|
@@ -99119,7 +99374,7 @@ async function readProcessStdin() {
|
|
|
99119
99374
|
}
|
|
99120
99375
|
|
|
99121
99376
|
// ../cli/src/version.ts
|
|
99122
|
-
var CLI_VERSION = "0.
|
|
99377
|
+
var CLI_VERSION = "0.13.0";
|
|
99123
99378
|
|
|
99124
99379
|
// ../cli/src/status.ts
|
|
99125
99380
|
async function statusCommand(argv, json2, io, dependencies) {
|
|
@@ -99286,7 +99541,7 @@ function withDeadlineSignal3(fetchImpl, deadline) {
|
|
|
99286
99541
|
}
|
|
99287
99542
|
async function statusConfig(path) {
|
|
99288
99543
|
try {
|
|
99289
|
-
await
|
|
99544
|
+
await stat15(path);
|
|
99290
99545
|
} catch (error61) {
|
|
99291
99546
|
if (isMissingFile(error61)) return getDefaultConfig(process.env);
|
|
99292
99547
|
throw error61;
|
|
@@ -99484,7 +99739,7 @@ async function siblingsFetchImpl(dependencies) {
|
|
|
99484
99739
|
const configPath = getVapiPaths().config;
|
|
99485
99740
|
let config2;
|
|
99486
99741
|
try {
|
|
99487
|
-
await
|
|
99742
|
+
await stat16(configPath);
|
|
99488
99743
|
config2 = await loadConfig(configPath, process.env);
|
|
99489
99744
|
} catch (error61) {
|
|
99490
99745
|
if (!isMissingFile(error61)) throw error61;
|
|
@@ -99573,7 +99828,7 @@ ${IMPORT_USAGE}`);
|
|
|
99573
99828
|
const passphrase = await secretPrompt(dependencies)(`Passphrase for ${keystorePath}: `);
|
|
99574
99829
|
privateKey = (await exportKeystoreKeys(passphrase, keystorePath)).evm.privateKey;
|
|
99575
99830
|
} else if (keyPath !== void 0) {
|
|
99576
|
-
privateKey = (await
|
|
99831
|
+
privateKey = (await readFile25(keyPath, "utf8")).trim();
|
|
99577
99832
|
} else {
|
|
99578
99833
|
privateKey = await secretPrompt(dependencies)("Private key: ");
|
|
99579
99834
|
}
|
|
@@ -99621,10 +99876,10 @@ async function accountsRenameCommand(argv, json2, io, dependencies) {
|
|
|
99621
99876
|
{
|
|
99622
99877
|
previous: from16,
|
|
99623
99878
|
...address4 === void 0 ? {} : { address: address4 },
|
|
99624
|
-
vault:
|
|
99879
|
+
vault: join22(store.home, "vault.json"),
|
|
99625
99880
|
message: `Wallet ${from16} is now ${renamed.name}.`
|
|
99626
99881
|
},
|
|
99627
|
-
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${
|
|
99882
|
+
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${join22(store.home, "vault.json")}`].join(
|
|
99628
99883
|
"\n"
|
|
99629
99884
|
)
|
|
99630
99885
|
);
|
|
@@ -99733,13 +99988,13 @@ async function accountsRestoreCommand(argv, json2, io, dependencies) {
|
|
|
99733
99988
|
{ name: restored.name, ...address4 === void 0 ? {} : { address: address4 } },
|
|
99734
99989
|
{
|
|
99735
99990
|
...address4 === void 0 ? {} : { address: address4 },
|
|
99736
|
-
vault:
|
|
99991
|
+
vault: join22(store.home, "vault.json"),
|
|
99737
99992
|
spendCaps: restored.entry.spendCaps,
|
|
99738
99993
|
message: `Wallet ${restored.name} restored to the device vault.`
|
|
99739
99994
|
},
|
|
99740
99995
|
[
|
|
99741
99996
|
`Wallet ${restored.name} restored to the device vault.`,
|
|
99742
|
-
`Vault: ${
|
|
99997
|
+
`Vault: ${join22(store.home, "vault.json")}`
|
|
99743
99998
|
].join("\n")
|
|
99744
99999
|
);
|
|
99745
100000
|
}
|
|
@@ -100069,7 +100324,7 @@ function formatNetworkAccounts(accounts) {
|
|
|
100069
100324
|
}
|
|
100070
100325
|
|
|
100071
100326
|
// ../cli/src/cloud-backup.ts
|
|
100072
|
-
import { join as
|
|
100327
|
+
import { join as join23 } from "node:path";
|
|
100073
100328
|
var CLOUD_BACKUP_USAGE = "Usage: vapi backup --cloud [off] [--json]";
|
|
100074
100329
|
var OWNER_RESTORE_USAGE = "Usage: vapi restore --from-owner [--owner <0x\u2026>] [--json]";
|
|
100075
100330
|
var OWNER_PATTERN2 = /^0x[0-9a-fA-F]{40}$/u;
|
|
@@ -100092,7 +100347,7 @@ async function cloudBackupCommand(argv, json2, io, dependencies) {
|
|
|
100092
100347
|
}
|
|
100093
100348
|
async function enrollCloudBackup(json2, io, dependencies) {
|
|
100094
100349
|
const paths = getVapiPaths();
|
|
100095
|
-
if (!await
|
|
100350
|
+
if (!await fileExists3(join23(paths.directory, "vault.json"))) {
|
|
100096
100351
|
throw new Error("No vault on this device. Run vapi setup first.");
|
|
100097
100352
|
}
|
|
100098
100353
|
const context = await cloudContext(io, dependencies);
|
|
@@ -100204,7 +100459,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
100204
100459
|
}
|
|
100205
100460
|
const expectedOwner = ownerValue?.toLowerCase();
|
|
100206
100461
|
const paths = getVapiPaths();
|
|
100207
|
-
if (await
|
|
100462
|
+
if (await fileExists3(join23(paths.directory, "vault.json")) && !await fileExists3(join23(paths.directory, ".backup-restore.json"))) {
|
|
100208
100463
|
throw new Error(
|
|
100209
100464
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
100210
100465
|
);
|
|
@@ -100260,7 +100515,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
100260
100515
|
env: getEnvironment(dependencies),
|
|
100261
100516
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
100262
100517
|
});
|
|
100263
|
-
if (!await
|
|
100518
|
+
if (!await fileExists3(paths.config)) {
|
|
100264
100519
|
const networks = restored.networks.length === 0 ? ["base"] : restored.networks;
|
|
100265
100520
|
await writeDefaultConfig(paths.config, getEnvironment(dependencies), { networks });
|
|
100266
100521
|
}
|
|
@@ -101301,20 +101556,20 @@ function shortExcerpt(value) {
|
|
|
101301
101556
|
}
|
|
101302
101557
|
|
|
101303
101558
|
// ../cli/src/agent.ts
|
|
101304
|
-
import { readFile as
|
|
101305
|
-
import { join as
|
|
101559
|
+
import { readFile as readFile27, stat as stat17 } from "node:fs/promises";
|
|
101560
|
+
import { join as join26 } from "node:path";
|
|
101306
101561
|
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
101307
101562
|
|
|
101308
101563
|
// ../cli/src/headless.ts
|
|
101309
101564
|
import { chmod as chmod7, mkdtemp as mkdtemp2, rm as rm4, writeFile as writeFile10 } from "node:fs/promises";
|
|
101310
101565
|
import { rmSync } from "node:fs";
|
|
101311
101566
|
import { tmpdir as osTmpdir } from "node:os";
|
|
101312
|
-
import { join as
|
|
101567
|
+
import { join as join24 } from "node:path";
|
|
101313
101568
|
var BUNDLE_VARIABLE_PATTERN = /^[A-Z_][A-Z0-9_]*$/u;
|
|
101314
101569
|
var REMOTE_BLOCKED_GRANTS2 = /* @__PURE__ */ new Set(["delegate", "allocate"]);
|
|
101315
101570
|
var agentProfileOptions = { schema: registeredAgentProfileSchema };
|
|
101316
101571
|
async function createHeadlessHome(bundle, options = {}) {
|
|
101317
|
-
const home = await mkdtemp2(
|
|
101572
|
+
const home = await mkdtemp2(join24(options.tmpdir ?? osTmpdir(), "vapi-headless-"));
|
|
101318
101573
|
const cleanup = async () => {
|
|
101319
101574
|
await rm4(home, { recursive: true, force: true });
|
|
101320
101575
|
};
|
|
@@ -101514,18 +101769,18 @@ import { readFile as nodeReadFile } from "node:fs/promises";
|
|
|
101514
101769
|
|
|
101515
101770
|
// ../cli/src/runtime-railway.ts
|
|
101516
101771
|
import { spawn as spawn2 } from "node:child_process";
|
|
101517
|
-
import { randomBytes as
|
|
101772
|
+
import { randomBytes as randomBytes17 } from "node:crypto";
|
|
101518
101773
|
import { closeSync, fsyncSync, mkdirSync, openSync, renameSync, rmSync as rmSync2, writeSync } from "node:fs";
|
|
101519
101774
|
import {
|
|
101520
101775
|
mkdtemp as nodeMkdtemp,
|
|
101521
101776
|
readdir as readdir9,
|
|
101522
|
-
readFile as
|
|
101777
|
+
readFile as readFile26,
|
|
101523
101778
|
rm as nodeRm,
|
|
101524
101779
|
stat as nodeStat,
|
|
101525
101780
|
writeFile as nodeWriteFile
|
|
101526
101781
|
} from "node:fs/promises";
|
|
101527
101782
|
import { tmpdir as osTmpdir2 } from "node:os";
|
|
101528
|
-
import { basename as basename4, dirname as dirname13, join as
|
|
101783
|
+
import { basename as basename4, dirname as dirname13, join as join25 } from "node:path";
|
|
101529
101784
|
var RAILWAY_CLI = {
|
|
101530
101785
|
binary: "railway",
|
|
101531
101786
|
create: (options) => [
|
|
@@ -101697,7 +101952,7 @@ async function assertRemoteSafeMember(args) {
|
|
|
101697
101952
|
}
|
|
101698
101953
|
function railwaySidecarPath(home, runId) {
|
|
101699
101954
|
if (!isRunId(runId)) throw new RuntimeError("invalid_run_id", `Invalid run id: ${runId}.`);
|
|
101700
|
-
return
|
|
101955
|
+
return join25(runsDirectory(home), `${runId}.railway.json`);
|
|
101701
101956
|
}
|
|
101702
101957
|
function createRailwayRuntime(options) {
|
|
101703
101958
|
const { home } = options;
|
|
@@ -102022,10 +102277,10 @@ function createRailwayRuntime(options) {
|
|
|
102022
102277
|
let createError;
|
|
102023
102278
|
let cleanupError;
|
|
102024
102279
|
try {
|
|
102025
|
-
directory = await fs.mkdtemp(
|
|
102280
|
+
directory = await fs.mkdtemp(join25(options.tmpdir ?? osTmpdir2(), "vapi-railway-"));
|
|
102026
102281
|
assertNotInterrupted();
|
|
102027
102282
|
await assertMode(fs, directory, 448, "env-file directory");
|
|
102028
|
-
envFile =
|
|
102283
|
+
envFile = join25(directory, "member.env");
|
|
102029
102284
|
await fs.writeFile(envFile, `${RAILWAY_CLI.bundleVariable}=${bundle}
|
|
102030
102285
|
`, {
|
|
102031
102286
|
encoding: "utf8",
|
|
@@ -102480,9 +102735,9 @@ async function writeSidecar(home, runId, sidecar) {
|
|
|
102480
102735
|
function writeSidecarSync(path, sidecar) {
|
|
102481
102736
|
const directory = dirname13(path);
|
|
102482
102737
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
102483
|
-
const temporary =
|
|
102738
|
+
const temporary = join25(
|
|
102484
102739
|
directory,
|
|
102485
|
-
`.${basename4(path)}.${process.pid}.${
|
|
102740
|
+
`.${basename4(path)}.${process.pid}.${randomBytes17(6).toString("hex")}.tmp`
|
|
102486
102741
|
);
|
|
102487
102742
|
try {
|
|
102488
102743
|
const descriptor2 = openSync(temporary, "wx", 384);
|
|
@@ -102520,7 +102775,7 @@ var LEGACY_SIDECAR_KEYS = ["checkpoint", "keepSandbox", "sandboxId", "v"];
|
|
|
102520
102775
|
async function readSidecar(home, runId) {
|
|
102521
102776
|
let parsed;
|
|
102522
102777
|
try {
|
|
102523
|
-
parsed = JSON.parse(await
|
|
102778
|
+
parsed = JSON.parse(await readFile26(railwaySidecarPath(home, runId), "utf8"));
|
|
102524
102779
|
} catch {
|
|
102525
102780
|
return void 0;
|
|
102526
102781
|
}
|
|
@@ -102578,7 +102833,7 @@ async function assertMode(fs, path, mode, what) {
|
|
|
102578
102833
|
}
|
|
102579
102834
|
}
|
|
102580
102835
|
async function deviceVaultKey(home, secrets, now) {
|
|
102581
|
-
const path =
|
|
102836
|
+
const path = join25(home, "vault.json");
|
|
102582
102837
|
const metadata = await readVaultFileUnlocked(path);
|
|
102583
102838
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
102584
102839
|
path,
|
|
@@ -102633,7 +102888,7 @@ function createLocalRuntime(options) {
|
|
|
102633
102888
|
const processCommand = options.processCommand ?? defaultProcessCommand;
|
|
102634
102889
|
const ownsProcess = (handle, pid) => processCommand(pid)?.includes(runResultPath(home, handle.runId)) === true;
|
|
102635
102890
|
const closeFd = options.closeFd ?? closeSync2;
|
|
102636
|
-
const
|
|
102891
|
+
const readFile33 = options.readFile ?? nodeReadFile;
|
|
102637
102892
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
102638
102893
|
const openLog = options.openLog ?? ((path) => {
|
|
102639
102894
|
mkdirSync2(runsDirectory(home), { recursive: true, mode: 448 });
|
|
@@ -102688,7 +102943,7 @@ function createLocalRuntime(options) {
|
|
|
102688
102943
|
return handle;
|
|
102689
102944
|
},
|
|
102690
102945
|
async status(handle) {
|
|
102691
|
-
const result = await readResultFile(
|
|
102946
|
+
const result = await readResultFile(readFile33, runResultPath(home, handle.runId));
|
|
102692
102947
|
if (result !== void 0) return result;
|
|
102693
102948
|
const pid = localPid(handle);
|
|
102694
102949
|
if (pid === void 0 || handle.kind !== "local") {
|
|
@@ -102791,10 +103046,10 @@ function childArguments(member, run) {
|
|
|
102791
103046
|
...run.drawUsd ? ["--draw", run.drawUsd] : []
|
|
102792
103047
|
];
|
|
102793
103048
|
}
|
|
102794
|
-
async function readResultFile(
|
|
103049
|
+
async function readResultFile(readFile33, path) {
|
|
102795
103050
|
let text;
|
|
102796
103051
|
try {
|
|
102797
|
-
text = await
|
|
103052
|
+
text = await readFile33(path, "utf8");
|
|
102798
103053
|
} catch (error61) {
|
|
102799
103054
|
if (hasCode3(error61, "ENOENT")) return void 0;
|
|
102800
103055
|
return { state: "failed", detail: "unreadable result file" };
|
|
@@ -102919,7 +103174,7 @@ async function createCommand(argv, json2, io, dependencies) {
|
|
|
102919
103174
|
if (await profileFileExists(paths.agentsDir, name)) {
|
|
102920
103175
|
throw new Error(`Agent ${name} already exists.`);
|
|
102921
103176
|
}
|
|
102922
|
-
const instructions = await
|
|
103177
|
+
const instructions = await readFile27(instructionsPath, "utf8");
|
|
102923
103178
|
if (instructions.length > 2e4) {
|
|
102924
103179
|
throw new UsageError("--instructions must contain at most 20000 characters.");
|
|
102925
103180
|
}
|
|
@@ -103505,7 +103760,7 @@ function explicitWallet(name) {
|
|
|
103505
103760
|
}
|
|
103506
103761
|
async function profileFileExists(directory, name) {
|
|
103507
103762
|
try {
|
|
103508
|
-
await
|
|
103763
|
+
await stat17(join26(directory, `${name}.json`));
|
|
103509
103764
|
return true;
|
|
103510
103765
|
} catch (error61) {
|
|
103511
103766
|
if (isMissingFile(error61)) return false;
|
|
@@ -103566,7 +103821,7 @@ function usd(value, minimumDecimals = 0) {
|
|
|
103566
103821
|
|
|
103567
103822
|
// ../cli/src/mcp-install.ts
|
|
103568
103823
|
import { spawn as spawn3 } from "node:child_process";
|
|
103569
|
-
import { mkdir as mkdir20, readFile as
|
|
103824
|
+
import { mkdir as mkdir20, readFile as readFile28, writeFile as writeFile11 } from "node:fs/promises";
|
|
103570
103825
|
import { homedir as systemHomedir } from "node:os";
|
|
103571
103826
|
import { dirname as dirname14, posix, win32 as win322 } from "node:path";
|
|
103572
103827
|
|
|
@@ -103946,7 +104201,7 @@ function isRecord12(value) {
|
|
|
103946
104201
|
}
|
|
103947
104202
|
async function readExistingFile(path) {
|
|
103948
104203
|
try {
|
|
103949
|
-
return await
|
|
104204
|
+
return await readFile28(path, "utf8");
|
|
103950
104205
|
} catch (error61) {
|
|
103951
104206
|
if (isMissingFile(error61)) return void 0;
|
|
103952
104207
|
throw error61;
|
|
@@ -103954,7 +104209,7 @@ async function readExistingFile(path) {
|
|
|
103954
104209
|
}
|
|
103955
104210
|
async function pathExists5(path) {
|
|
103956
104211
|
try {
|
|
103957
|
-
await
|
|
104212
|
+
await readFile28(path);
|
|
103958
104213
|
return true;
|
|
103959
104214
|
} catch (error61) {
|
|
103960
104215
|
if (isMissingFile(error61)) return false;
|
|
@@ -103964,15 +104219,15 @@ async function pathExists5(path) {
|
|
|
103964
104219
|
|
|
103965
104220
|
// ../cli/src/code.ts
|
|
103966
104221
|
import { constants as constants2 } from "node:fs";
|
|
103967
|
-
import { access, mkdir as mkdir21, readFile as
|
|
104222
|
+
import { access, mkdir as mkdir21, readFile as readFile29, realpath, unlink as unlink13, writeFile as writeFile12 } from "node:fs/promises";
|
|
103968
104223
|
import { homedir as homedir3 } from "node:os";
|
|
103969
|
-
import { basename as basename5, dirname as dirname15, join as
|
|
104224
|
+
import { basename as basename5, dirname as dirname15, join as join27, posix as posix2, win32 as win323 } from "node:path";
|
|
103970
104225
|
var VAPI_CODEX_PROVIDER = "vapi";
|
|
103971
104226
|
var VAPI_CODEX_PROFILE = "vapi";
|
|
103972
104227
|
var VAPI_CODEX_DEFAULT_MODEL = "venice/openai-gpt-61-sol";
|
|
103973
104228
|
var VAPI_ROUTER_KEY_ENV = "VAPI_ROUTER_KEY";
|
|
103974
104229
|
function codexConfigPath(env, home) {
|
|
103975
|
-
return
|
|
104230
|
+
return join27(env.CODEX_HOME || join27(home, ".codex"), "config.toml");
|
|
103976
104231
|
}
|
|
103977
104232
|
function hasVapiCodexProfile(contents) {
|
|
103978
104233
|
const roots = new Set(
|
|
@@ -104066,7 +104321,7 @@ function aliasContents(original, tools) {
|
|
|
104066
104321
|
}
|
|
104067
104322
|
async function readOptional(path) {
|
|
104068
104323
|
try {
|
|
104069
|
-
return await
|
|
104324
|
+
return await readFile29(path, "utf8");
|
|
104070
104325
|
} catch (error61) {
|
|
104071
104326
|
if (isMissingFile(error61)) return void 0;
|
|
104072
104327
|
throw error61;
|
|
@@ -104088,7 +104343,7 @@ async function codeCommand(argv, json2, io, dependencies) {
|
|
|
104088
104343
|
const env = getEnvironment(dependencies);
|
|
104089
104344
|
const home = dependencies.code?.homedir ?? homedir3();
|
|
104090
104345
|
const config2 = codexConfigPath(env, home);
|
|
104091
|
-
const rcPaths = [
|
|
104346
|
+
const rcPaths = [join27(home, ".zshrc"), join27(home, ".bashrc")];
|
|
104092
104347
|
if (command === "uninstall") {
|
|
104093
104348
|
const removed = [];
|
|
104094
104349
|
const previous = await readOptional(config2);
|
|
@@ -104212,7 +104467,7 @@ async function codeCommand(argv, json2, io, dependencies) {
|
|
|
104212
104467
|
|
|
104213
104468
|
// ../cli/src/code-launch.ts
|
|
104214
104469
|
import { spawn as spawn4 } from "node:child_process";
|
|
104215
|
-
import { readFile as
|
|
104470
|
+
import { readFile as readFile30 } from "node:fs/promises";
|
|
104216
104471
|
import { constants as constants3, homedir as homedir4 } from "node:os";
|
|
104217
104472
|
var CLAUDE_MODELS = {
|
|
104218
104473
|
sonnet: "venice/claude-sonnet-5-5",
|
|
@@ -104426,7 +104681,7 @@ function claudeModel(model) {
|
|
|
104426
104681
|
async function codexArgs(env, baseURL, model, dependencies) {
|
|
104427
104682
|
let contents = "";
|
|
104428
104683
|
try {
|
|
104429
|
-
contents = await
|
|
104684
|
+
contents = await readFile30(
|
|
104430
104685
|
codexConfigPath(env, dependencies.code?.homedir ?? homedir4()),
|
|
104431
104686
|
"utf8"
|
|
104432
104687
|
);
|
|
@@ -104601,7 +104856,7 @@ async function sendConfig(dependencies) {
|
|
|
104601
104856
|
|
|
104602
104857
|
// ../cli/src/setup.ts
|
|
104603
104858
|
import { rm as rm5 } from "node:fs/promises";
|
|
104604
|
-
import { join as
|
|
104859
|
+
import { join as join28 } from "node:path";
|
|
104605
104860
|
var SETUP_ARGUMENT_ERROR = `vapi setup accepts only --no-cloud-backup and --accounts <n> (1-${MAX_RESTORE_ACCOUNTS}); a recovery phrase is typed at the prompt, never passed on the command line.`;
|
|
104606
104861
|
var VAULT_CHOICE = "Create a new vault, or restore one from a recovery phrase? [new/restore] ";
|
|
104607
104862
|
async function setupCommand(argv, json2, io, dependencies) {
|
|
@@ -104620,18 +104875,24 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
104620
104875
|
const steps = [];
|
|
104621
104876
|
const humanIo = json2 ? stderrIo(io) : io;
|
|
104622
104877
|
const accountCount = parseAccountCount(parsed.one("--accounts"));
|
|
104623
|
-
if (!await
|
|
104878
|
+
if (!await fileExists3(paths.config)) {
|
|
104624
104879
|
await writeDefaultConfig(paths.config, process.env, { networks: ["base"] });
|
|
104625
104880
|
steps.push("config");
|
|
104626
104881
|
}
|
|
104627
104882
|
const config2 = await readConfig(paths.config, humanIo);
|
|
104883
|
+
if (!await fileExists3(join28(paths.directory, "vault.json"))) {
|
|
104884
|
+
const os = dependencies.secretBackendProbe ?? (dependencies.secretStore === void 0 ? osSecretStore() : void 0);
|
|
104885
|
+
if (os !== void 0) {
|
|
104886
|
+
await chooseSecretBackend({ home: paths.directory, os, env: getEnvironment(dependencies) });
|
|
104887
|
+
}
|
|
104888
|
+
}
|
|
104628
104889
|
let store = await openWalletStore(dependencies);
|
|
104629
104890
|
let vault = "existing";
|
|
104630
104891
|
let changedVault = false;
|
|
104631
104892
|
let changedAccount = false;
|
|
104632
104893
|
let changedLink = false;
|
|
104633
104894
|
let scannedAddresses;
|
|
104634
|
-
if (!await
|
|
104895
|
+
if (!await fileExists3(join28(paths.directory, "vault.json"))) {
|
|
104635
104896
|
const choice = await vaultChoice(dependencies);
|
|
104636
104897
|
if (choice === "restore") {
|
|
104637
104898
|
if (!isInteractive(dependencies)) {
|
|
@@ -104719,7 +104980,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
104719
104980
|
let scannedAddresses = 0;
|
|
104720
104981
|
try {
|
|
104721
104982
|
const restored = await restoreVault({
|
|
104722
|
-
path:
|
|
104983
|
+
path: join28(paths.directory, "vault.json"),
|
|
104723
104984
|
key: key2,
|
|
104724
104985
|
phrase: validatedPhrase,
|
|
104725
104986
|
probe: async (address4) => await readBalance3(address4) > 0n,
|
|
@@ -104730,7 +104991,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
104730
104991
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
104731
104992
|
});
|
|
104732
104993
|
names = restored.accounts().map((account) => account.name);
|
|
104733
|
-
await rm5(
|
|
104994
|
+
await rm5(join28(paths.directory, "wallets.json"), { force: true });
|
|
104734
104995
|
} finally {
|
|
104735
104996
|
key2.fill(0);
|
|
104736
104997
|
}
|
|
@@ -104848,7 +105109,7 @@ async function withRouterError2(operation) {
|
|
|
104848
105109
|
|
|
104849
105110
|
// ../cli/src/task.ts
|
|
104850
105111
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
104851
|
-
import { readFile as
|
|
105112
|
+
import { readFile as readFile31 } from "node:fs/promises";
|
|
104852
105113
|
var TASK_HELP = `Usage:
|
|
104853
105114
|
vapi task search [--open] [--min <usd>] [--tab trending|new|closing|paid] [--limit <n>] [--json]
|
|
104854
105115
|
vapi task show <id> [--account <name>] [--json]
|
|
@@ -105184,7 +105445,7 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
105184
105445
|
if (maxAwards !== void 0 && maxAwards > TASK_LIMITS.maxAwardsMax)
|
|
105185
105446
|
throw new UsageError("--max-awards must be between 1 and 50.");
|
|
105186
105447
|
if (parsed.one("--webhook") !== void 0) httpsUrl2(parsed.one("--webhook"), "--webhook");
|
|
105187
|
-
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await
|
|
105448
|
+
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await readFile31(briefPath, "utf8");
|
|
105188
105449
|
const input2 = {
|
|
105189
105450
|
title: title.trim(),
|
|
105190
105451
|
description: brief.trim(),
|
|
@@ -106862,7 +107123,7 @@ async function referencedSleep(milliseconds, signal) {
|
|
|
106862
107123
|
}
|
|
106863
107124
|
|
|
106864
107125
|
// ../cli/src/vault.ts
|
|
106865
|
-
import { join as
|
|
107126
|
+
import { join as join29 } from "node:path";
|
|
106866
107127
|
var VAULT_USAGE = "Usage: vapi vault protect|unprotect|lock|unlock|status [--json]";
|
|
106867
107128
|
var RESTORE_USAGE = "Usage: vapi restore [--accounts <n> | --from-owner [--owner <0x\u2026>]] [--json]";
|
|
106868
107129
|
var LEGACY_PASSWORD_NOTICE = "VAPI_KEYSTORE_PASSWORD is deprecated for vault passwords; use VAPI_VAULT_PASSWORD instead.";
|
|
@@ -106906,13 +107167,13 @@ async function restoreCommand(argv, json2, io, dependencies) {
|
|
|
106906
107167
|
}
|
|
106907
107168
|
const accountCount = parseRestoreAccountCount(parsed.one("--accounts"));
|
|
106908
107169
|
const paths = getVapiPaths();
|
|
106909
|
-
const path =
|
|
106910
|
-
if (await
|
|
107170
|
+
const path = join29(paths.directory, "vault.json");
|
|
107171
|
+
if (await fileExists3(path)) {
|
|
106911
107172
|
throw new Error(
|
|
106912
107173
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
106913
107174
|
);
|
|
106914
107175
|
}
|
|
106915
|
-
if (!await
|
|
107176
|
+
if (!await fileExists3(paths.config)) {
|
|
106916
107177
|
await writeDefaultConfig(paths.config, process.env, { networks: ["base"] });
|
|
106917
107178
|
}
|
|
106918
107179
|
const config2 = await readConfig(paths.config, json2 ? quietIo(io) : io);
|
|
@@ -107063,7 +107324,7 @@ function requireNoArguments(argv) {
|
|
|
107063
107324
|
parseArguments(argv, { valueOptions: /* @__PURE__ */ new Set(), maximumPositionals: 0 });
|
|
107064
107325
|
}
|
|
107065
107326
|
function vaultPath() {
|
|
107066
|
-
return
|
|
107327
|
+
return join29(getVapiPaths().directory, "vault.json");
|
|
107067
107328
|
}
|
|
107068
107329
|
function quietIo(io) {
|
|
107069
107330
|
return { stdout: () => void 0, stderr: io.stderr };
|
|
@@ -107514,7 +107775,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
107514
107775
|
break;
|
|
107515
107776
|
case "unlock":
|
|
107516
107777
|
io.stderr("vapi unlock is now vapi vault unlock; the old name works for one release.");
|
|
107517
|
-
if (await
|
|
107778
|
+
if (await fileExists3(join30(getVapiPaths().directory, "vault.json"))) {
|
|
107518
107779
|
parseArguments(args.slice(1), {
|
|
107519
107780
|
valueOptions: /* @__PURE__ */ new Set([WALLET_OPTION5]),
|
|
107520
107781
|
maximumPositionals: 0
|
|
@@ -107702,7 +107963,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
107702
107963
|
await recordAudit(dependencies, "wallet.create", { wallet: created.name });
|
|
107703
107964
|
const account = created.account;
|
|
107704
107965
|
if (!json2) await showRecoveryPhrase(created.recoveryPhrase, io, dependencies);
|
|
107705
|
-
if (!await
|
|
107966
|
+
if (!await fileExists3(paths.config)) {
|
|
107706
107967
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
107707
107968
|
} else {
|
|
107708
107969
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -107720,7 +107981,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
107720
107981
|
address: account.address,
|
|
107721
107982
|
accounts,
|
|
107722
107983
|
config: paths.config,
|
|
107723
|
-
vault:
|
|
107984
|
+
vault: join30(paths.directory, "vault.json"),
|
|
107724
107985
|
...configRewrites.length > 0 ? { configRewrites } : {},
|
|
107725
107986
|
custody: "self",
|
|
107726
107987
|
warning: CUSTODY_NOTICE,
|
|
@@ -107850,7 +108111,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
107850
108111
|
await recordAudit(dependencies, "wallet.create", { wallet: created.name });
|
|
107851
108112
|
const account = created.account;
|
|
107852
108113
|
if (!json2) await showRecoveryPhrase(created.recoveryPhrase, io, dependencies);
|
|
107853
|
-
if (!await
|
|
108114
|
+
if (!await fileExists3(paths.config)) {
|
|
107854
108115
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
107855
108116
|
} else {
|
|
107856
108117
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -107859,7 +108120,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
107859
108120
|
const result = {
|
|
107860
108121
|
address: account.address,
|
|
107861
108122
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
107862
|
-
vault:
|
|
108123
|
+
vault: join30(paths.directory, "vault.json"),
|
|
107863
108124
|
...label === void 0 ? {} : { label },
|
|
107864
108125
|
spendCaps: created.entry.spendCaps,
|
|
107865
108126
|
isDefault,
|
|
@@ -107899,7 +108160,7 @@ function formatCaps2(caps) {
|
|
|
107899
108160
|
function walletListResult(store, wallets, unlocked) {
|
|
107900
108161
|
return {
|
|
107901
108162
|
default: store.defaultName ?? null,
|
|
107902
|
-
vault:
|
|
108163
|
+
vault: join30(store.home, "vault.json"),
|
|
107903
108164
|
wallets: wallets.map((wallet) => ({
|
|
107904
108165
|
name: wallet.name,
|
|
107905
108166
|
...wallet.address === void 0 ? {} : { address: wallet.address },
|
|
@@ -108915,7 +109176,7 @@ function sameOrigin2(left, right) {
|
|
|
108915
109176
|
function noApiKeyMessage(baseUrl) {
|
|
108916
109177
|
return [
|
|
108917
109178
|
"No vAPI API key on this machine.",
|
|
108918
|
-
`Create one in the console at ${
|
|
109179
|
+
`Create one in the console at ${apiKeyConsoleUrl(baseUrl).href}, then store it with vapi auth set-key.`,
|
|
108919
109180
|
`In CI, set ${API_KEY_ENV} instead.`
|
|
108920
109181
|
].join("\n");
|
|
108921
109182
|
}
|
|
@@ -109172,7 +109433,7 @@ function formatClaimed(origin, claimed) {
|
|
|
109172
109433
|
}
|
|
109173
109434
|
var EXPORT_KEY_WARNING = "Anyone with this key can spend the wallet. Never paste it into a website or chat.";
|
|
109174
109435
|
async function deviceVaultKey2(store, dependencies) {
|
|
109175
|
-
const path =
|
|
109436
|
+
const path = join30(store.home, "vault.json");
|
|
109176
109437
|
const metadata = await readVaultFileUnlocked(path);
|
|
109177
109438
|
const secrets = getSecretStore(dependencies);
|
|
109178
109439
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
@@ -109265,7 +109526,7 @@ async function backupCommand(argv, json2, io, dependencies) {
|
|
|
109265
109526
|
const target = await targetWallet(parsed, dependencies);
|
|
109266
109527
|
const vaultAccount = await target.store.hasVaultAccount(target.name);
|
|
109267
109528
|
if (vaultAccount) {
|
|
109268
|
-
const vault = await readVaultFileUnlocked(
|
|
109529
|
+
const vault = await readVaultFileUnlocked(join30(target.store.home, "vault.json"));
|
|
109269
109530
|
if (vault.accounts.some((account) => account.name === target.name && account.kind === "imported")) {
|
|
109270
109531
|
throw new KeystoreError(
|
|
109271
109532
|
`Account ${target.name} was imported and is not recoverable from the vault phrase. Back it up with vapi export-key --account ${target.name}.`
|
|
@@ -109342,7 +109603,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109342
109603
|
const existed = store.has(name);
|
|
109343
109604
|
if (existed && !parsed.has("--replace")) {
|
|
109344
109605
|
const address4 = await store.readAddress(name);
|
|
109345
|
-
const location = await store.hasVaultAccount(name) ?
|
|
109606
|
+
const location = await store.hasVaultAccount(name) ? join30(store.home, "vault.json") : store.pathFor(name);
|
|
109346
109607
|
throw new Error(
|
|
109347
109608
|
[
|
|
109348
109609
|
`Wallet ${name} already exists at ${location}.`,
|
|
@@ -109370,7 +109631,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109370
109631
|
const imported = fromPhrase ? await store.create(name, "", { phrase: secret }) : await store.importKey(name, "", secret);
|
|
109371
109632
|
await recordAudit(dependencies, "wallet.import", { wallet: imported.name });
|
|
109372
109633
|
const account = imported.account;
|
|
109373
|
-
if (!await
|
|
109634
|
+
if (!await fileExists3(paths.config)) {
|
|
109374
109635
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
109375
109636
|
} else {
|
|
109376
109637
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -109378,7 +109639,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109378
109639
|
const result = {
|
|
109379
109640
|
address: account.address,
|
|
109380
109641
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
109381
|
-
vault:
|
|
109642
|
+
vault: join30(paths.directory, "vault.json"),
|
|
109382
109643
|
...previousKeystore ? { previousKeystore } : {},
|
|
109383
109644
|
message: "Wallet imported. Its encrypted key stays on this machine."
|
|
109384
109645
|
};
|
|
@@ -109986,9 +110247,9 @@ function isHttpUrl(value) {
|
|
|
109986
110247
|
return false;
|
|
109987
110248
|
}
|
|
109988
110249
|
}
|
|
109989
|
-
async function
|
|
110250
|
+
async function fileExists3(path) {
|
|
109990
110251
|
try {
|
|
109991
|
-
await
|
|
110252
|
+
await stat18(path);
|
|
109992
110253
|
return true;
|
|
109993
110254
|
} catch (error61) {
|
|
109994
110255
|
if (isMissingFile(error61)) return false;
|
|
@@ -110010,7 +110271,7 @@ function parseInitNetworks(value) {
|
|
|
110010
110271
|
|
|
110011
110272
|
// ../cli/src/update-check.ts
|
|
110012
110273
|
import { lookup } from "node:dns/promises";
|
|
110013
|
-
import { mkdir as mkdir22, readFile as
|
|
110274
|
+
import { mkdir as mkdir22, readFile as readFile32, writeFile as writeFile13 } from "node:fs/promises";
|
|
110014
110275
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
110015
110276
|
var CHECK_TIMEOUT_MS = 1500;
|
|
110016
110277
|
var LATEST_URL = "https://registry.npmjs.org/vapi-network/latest";
|
|
@@ -110054,7 +110315,7 @@ async function latestNotice(options, env, signal) {
|
|
|
110054
110315
|
const now = (options.nowMs ?? Date.now)();
|
|
110055
110316
|
let cached2;
|
|
110056
110317
|
try {
|
|
110057
|
-
const value = JSON.parse(await
|
|
110318
|
+
const value = JSON.parse(await readFile32(paths.updateCheck, "utf8"));
|
|
110058
110319
|
if (isRecord13(value) && typeof value.checkedAt === "number" && Number.isFinite(value.checkedAt) && typeof value.latest === "string" && parseVersion(value.latest)) {
|
|
110059
110320
|
cached2 = { checkedAt: value.checkedAt, latest: value.latest };
|
|
110060
110321
|
}
|