@vapi-network/cli 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/dist/cli.d.ts +2 -0
- package/dist/cli.js +1467 -1206
- package/dist/cli.js.map +3 -3
- package/dist/index.js +1466 -1205
- package/dist/index.js.map +3 -3
- package/dist/publish-client.d.ts +2 -2
- package/dist/version.d.ts +1 -1
- 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,7 +10118,7 @@ var init_call = __esm({
|
|
|
10118
10118
|
|
|
10119
10119
|
// src/update-check.ts
|
|
10120
10120
|
import { lookup } from "node:dns/promises";
|
|
10121
|
-
import { mkdir as mkdir22, readFile as
|
|
10121
|
+
import { mkdir as mkdir22, readFile as readFile32, writeFile as writeFile13 } from "node:fs/promises";
|
|
10122
10122
|
|
|
10123
10123
|
// ../../node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/external.js
|
|
10124
10124
|
var external_exports = {};
|
|
@@ -45225,9 +45225,9 @@ var X402Error = class extends Error {
|
|
|
45225
45225
|
function isValidPaymentId(value) {
|
|
45226
45226
|
return typeof value === "string" && PAYMENT_ID_PATTERN.test(value);
|
|
45227
45227
|
}
|
|
45228
|
-
function createPaymentId(
|
|
45228
|
+
function createPaymentId(randomBytes18 = fillRandomBytes) {
|
|
45229
45229
|
const bytes = new Uint8Array(16);
|
|
45230
|
-
|
|
45230
|
+
randomBytes18(bytes);
|
|
45231
45231
|
return `pay_${bytesToHex(bytes).slice(2)}`;
|
|
45232
45232
|
}
|
|
45233
45233
|
function buildPaymentExtensions(serverExtensions, options = {}) {
|
|
@@ -46618,8 +46618,8 @@ function conciseError(error61) {
|
|
|
46618
46618
|
}
|
|
46619
46619
|
|
|
46620
46620
|
// ../core/src/account-add.ts
|
|
46621
|
-
import { stat as
|
|
46622
|
-
import { join as
|
|
46621
|
+
import { stat as stat10 } from "node:fs/promises";
|
|
46622
|
+
import { join as join10 } from "node:path";
|
|
46623
46623
|
|
|
46624
46624
|
// ../core/src/agent-link.ts
|
|
46625
46625
|
import { createHash } from "node:crypto";
|
|
@@ -70031,20 +70031,20 @@ async function promptForSecret(prompt, noTerminalHint) {
|
|
|
70031
70031
|
}
|
|
70032
70032
|
|
|
70033
70033
|
// ../core/src/wallet-store.ts
|
|
70034
|
-
import { randomBytes as
|
|
70034
|
+
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
70035
70035
|
import {
|
|
70036
70036
|
chmod as chmod3,
|
|
70037
70037
|
lstat as lstat2,
|
|
70038
70038
|
mkdir as mkdir10,
|
|
70039
|
-
open as
|
|
70039
|
+
open as open8,
|
|
70040
70040
|
readdir as readdir3,
|
|
70041
|
-
readFile as
|
|
70041
|
+
readFile as readFile12,
|
|
70042
70042
|
rename as rename7,
|
|
70043
|
-
stat as
|
|
70043
|
+
stat as stat9,
|
|
70044
70044
|
unlink as unlink6,
|
|
70045
70045
|
writeFile as writeFile5
|
|
70046
70046
|
} from "node:fs/promises";
|
|
70047
|
-
import { dirname as dirname7, join as
|
|
70047
|
+
import { dirname as dirname7, join as join9 } from "node:path";
|
|
70048
70048
|
|
|
70049
70049
|
// ../core/src/account-movement-lock.ts
|
|
70050
70050
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
@@ -70162,497 +70162,16 @@ function isOpenMovementLeg(leg, journalEvidence) {
|
|
|
70162
70162
|
// ../core/src/secret-store.ts
|
|
70163
70163
|
import { spawn } from "node:child_process";
|
|
70164
70164
|
import { existsSync } from "node:fs";
|
|
70165
|
-
import { delimiter, isAbsolute, join as
|
|
70166
|
-
var SECRET_STORE_SERVICE = "vapi-network";
|
|
70167
|
-
var SECURITY_BINARY = "/usr/bin/security";
|
|
70168
|
-
var SECRET_TOOL_BINARY = "secret-tool";
|
|
70169
|
-
var WINDOWS_POWERSHELL_ARGS = ["-NoProfile", "-NonInteractive", "-Command", "-"];
|
|
70170
|
-
var SECURITY_ITEM_NOT_FOUND = 44;
|
|
70171
|
-
var WINDOWS_SECRET_SUCCESS = 0;
|
|
70172
|
-
var WINDOWS_SECRET_NOT_FOUND = 2;
|
|
70173
|
-
var UNSUPPORTED_PLATFORM = "No OS secret store on this platform yet; use VAPI_KEYSTORE_PASSWORD.";
|
|
70174
|
-
var SECRET_TOOL_MISSING = [
|
|
70175
|
-
"secret-tool is not installed, so the passphrase cannot be kept in the OS secret store.",
|
|
70176
|
-
"Install libsecret-tools (Debian, Ubuntu) or libsecret (Fedora, Arch), or use VAPI_KEYSTORE_PASSWORD."
|
|
70177
|
-
].join(" ");
|
|
70178
|
-
var POWERSHELL_MISSING = [
|
|
70179
|
-
"Windows PowerShell (powershell.exe) was not found, so the passphrase cannot be kept in the OS secret store.",
|
|
70180
|
-
"Use VAPI_KEYSTORE_PASSWORD."
|
|
70181
|
-
].join(" ");
|
|
70182
|
-
function secretStore(options = {}) {
|
|
70183
|
-
const platform2 = options.platform ?? process.platform;
|
|
70184
|
-
const run = options.run ?? (async (file2, args, input2) => await spawnRunner(platform2, file2, args, input2));
|
|
70185
|
-
const env = options.env ?? process.env;
|
|
70186
|
-
const installed = options.installed ?? ((file2) => binaryInstalled(file2, env));
|
|
70187
|
-
if (platform2 === "darwin") return keychainStore(platform2, run);
|
|
70188
|
-
if (platform2 === "win32") return windowsDataProtectionStore(platform2, run, env, installed);
|
|
70189
|
-
if (platform2 === "linux") return libsecretStore(platform2, run, installed);
|
|
70190
|
-
return unsupportedStore(platform2);
|
|
70191
|
-
}
|
|
70192
|
-
function memorySecretStore(initial = {}) {
|
|
70193
|
-
const entries = new Map(Object.entries(initial));
|
|
70194
|
-
return {
|
|
70195
|
-
available: true,
|
|
70196
|
-
platform: process.platform,
|
|
70197
|
-
description: "an in-memory store",
|
|
70198
|
-
async get(name) {
|
|
70199
|
-
return entries.get(name);
|
|
70200
|
-
},
|
|
70201
|
-
async has(name) {
|
|
70202
|
-
return entries.has(name);
|
|
70203
|
-
},
|
|
70204
|
-
async set(name, passphrase) {
|
|
70205
|
-
entries.set(name, passphrase);
|
|
70206
|
-
},
|
|
70207
|
-
async remove(name) {
|
|
70208
|
-
return entries.delete(name);
|
|
70209
|
-
},
|
|
70210
|
-
async list() {
|
|
70211
|
-
return [...entries.keys()].sort();
|
|
70212
|
-
}
|
|
70213
|
-
};
|
|
70214
|
-
}
|
|
70215
|
-
function keychainStore(platform2, run) {
|
|
70216
|
-
const find = async (account, withPassword) => await run(SECURITY_BINARY, [
|
|
70217
|
-
"find-generic-password",
|
|
70218
|
-
"-a",
|
|
70219
|
-
account,
|
|
70220
|
-
"-s",
|
|
70221
|
-
SECRET_STORE_SERVICE,
|
|
70222
|
-
...withPassword ? ["-w"] : []
|
|
70223
|
-
]);
|
|
70224
|
-
const read = async (account, what) => {
|
|
70225
|
-
const result = await find(account, true);
|
|
70226
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return void 0;
|
|
70227
|
-
requireSuccess(result, what);
|
|
70228
|
-
const value = withoutTrailingNewline(result.stdout);
|
|
70229
|
-
return value.length === 0 ? void 0 : value;
|
|
70230
|
-
};
|
|
70231
|
-
const write2 = async (account, value, what) => {
|
|
70232
|
-
const result = await run(
|
|
70233
|
-
SECURITY_BINARY,
|
|
70234
|
-
[
|
|
70235
|
-
"add-generic-password",
|
|
70236
|
-
"-a",
|
|
70237
|
-
account,
|
|
70238
|
-
"-s",
|
|
70239
|
-
SECRET_STORE_SERVICE,
|
|
70240
|
-
"-l",
|
|
70241
|
-
`${SECRET_STORE_SERVICE} ${account}`,
|
|
70242
|
-
"-U",
|
|
70243
|
-
"-w"
|
|
70244
|
-
],
|
|
70245
|
-
// `security` asks for the password and then for its confirmation.
|
|
70246
|
-
`${value}
|
|
70247
|
-
${value}
|
|
70248
|
-
`
|
|
70249
|
-
);
|
|
70250
|
-
requireSuccess(result, what);
|
|
70251
|
-
};
|
|
70252
|
-
const erase = async (account, what) => {
|
|
70253
|
-
const result = await run(SECURITY_BINARY, [
|
|
70254
|
-
"delete-generic-password",
|
|
70255
|
-
"-a",
|
|
70256
|
-
account,
|
|
70257
|
-
"-s",
|
|
70258
|
-
SECRET_STORE_SERVICE
|
|
70259
|
-
]);
|
|
70260
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70261
|
-
requireSuccess(result, what);
|
|
70262
|
-
return true;
|
|
70263
|
-
};
|
|
70264
|
-
const erasePartsAfter = async (account, keep, what) => {
|
|
70265
|
-
for (let part = keep + 1; part <= MAX_KEYCHAIN_PARTS; part += 1) {
|
|
70266
|
-
if (!await erase(keychainPart(account, part), what)) return;
|
|
70267
|
-
}
|
|
70268
|
-
};
|
|
70269
|
-
return {
|
|
70270
|
-
available: true,
|
|
70271
|
-
platform: platform2,
|
|
70272
|
-
description: "the macOS Keychain",
|
|
70273
|
-
async get(name) {
|
|
70274
|
-
const account = accountFor(name);
|
|
70275
|
-
const what = `read the passphrase of ${name} from the macOS Keychain`;
|
|
70276
|
-
const value = await read(account, what);
|
|
70277
|
-
const parts = value === void 0 ? void 0 : chunkedPartCount(value);
|
|
70278
|
-
if (value === void 0 || parts === void 0) return value;
|
|
70279
|
-
let joined = "";
|
|
70280
|
-
for (let part = 1; part <= parts; part += 1) {
|
|
70281
|
-
const chunk = await read(keychainPart(account, part), what);
|
|
70282
|
-
if (chunk === void 0) {
|
|
70283
|
-
throw new KeystoreError(
|
|
70284
|
-
`The stored secret ${name} is incomplete in the macOS Keychain. Store it again.`
|
|
70285
|
-
);
|
|
70286
|
-
}
|
|
70287
|
-
joined += chunk;
|
|
70288
|
-
}
|
|
70289
|
-
return joined;
|
|
70290
|
-
},
|
|
70291
|
-
async has(name) {
|
|
70292
|
-
const result = await find(accountFor(name), false);
|
|
70293
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70294
|
-
requireSuccess(result, `look up ${name} in the macOS Keychain`);
|
|
70295
|
-
return true;
|
|
70296
|
-
},
|
|
70297
|
-
async set(name, passphrase) {
|
|
70298
|
-
requirePassphrase(passphrase);
|
|
70299
|
-
const account = accountFor(name);
|
|
70300
|
-
const what = `store the passphrase of ${name} in the macOS Keychain`;
|
|
70301
|
-
if (passphrase.length <= KEYCHAIN_PROMPT_LIMIT) {
|
|
70302
|
-
await write2(account, passphrase, what);
|
|
70303
|
-
return;
|
|
70304
|
-
}
|
|
70305
|
-
const chunks = [];
|
|
70306
|
-
for (let index2 = 0; index2 < passphrase.length; index2 += KEYCHAIN_CHUNK) {
|
|
70307
|
-
chunks.push(passphrase.slice(index2, index2 + KEYCHAIN_CHUNK));
|
|
70308
|
-
}
|
|
70309
|
-
if (chunks.length > MAX_KEYCHAIN_PARTS) {
|
|
70310
|
-
throw new KeystoreError(`The secret ${name} is too long for the macOS Keychain.`);
|
|
70311
|
-
}
|
|
70312
|
-
for (const [index2, chunk] of chunks.entries()) {
|
|
70313
|
-
await write2(keychainPart(account, index2 + 1), chunk, what);
|
|
70314
|
-
}
|
|
70315
|
-
await erasePartsAfter(account, chunks.length, what);
|
|
70316
|
-
await write2(account, `${CHUNKED_MARKER}${chunks.length}`, what);
|
|
70317
|
-
},
|
|
70318
|
-
async remove(name) {
|
|
70319
|
-
const account = accountFor(name);
|
|
70320
|
-
const what = `remove the passphrase of ${name} from the macOS Keychain`;
|
|
70321
|
-
const found = await find(account, true);
|
|
70322
|
-
if (found.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70323
|
-
requireSuccess(found, what);
|
|
70324
|
-
if (chunkedPartCount(withoutTrailingNewline(found.stdout)) !== void 0) {
|
|
70325
|
-
await erasePartsAfter(account, 0, what);
|
|
70326
|
-
}
|
|
70327
|
-
return await erase(account, what);
|
|
70328
|
-
}
|
|
70329
|
-
};
|
|
70330
|
-
}
|
|
70331
|
-
var KEYCHAIN_PROMPT_LIMIT = 128;
|
|
70332
|
-
var KEYCHAIN_CHUNK = 120;
|
|
70333
|
-
var MAX_KEYCHAIN_PARTS = 32;
|
|
70334
|
-
var CHUNKED_MARKER = "vapi-chunked:v1:";
|
|
70335
|
-
function keychainPart(account, part) {
|
|
70336
|
-
return `${account}#${part}`;
|
|
70337
|
-
}
|
|
70338
|
-
function chunkedPartCount(value) {
|
|
70339
|
-
if (!value.startsWith(CHUNKED_MARKER)) return void 0;
|
|
70340
|
-
const parts = Number(value.slice(CHUNKED_MARKER.length));
|
|
70341
|
-
return Number.isInteger(parts) && parts > 0 && parts <= MAX_KEYCHAIN_PARTS ? parts : void 0;
|
|
70342
|
-
}
|
|
70343
|
-
function windowsSecretFileName(account) {
|
|
70344
|
-
let encoded = "";
|
|
70345
|
-
for (let index2 = 0; index2 < account.length; index2 += 1) {
|
|
70346
|
-
const character = account[index2];
|
|
70347
|
-
if (/^[a-z0-9._#-]$/u.test(character)) {
|
|
70348
|
-
encoded += character;
|
|
70349
|
-
continue;
|
|
70350
|
-
}
|
|
70351
|
-
encoded += `%${account.charCodeAt(index2).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
70352
|
-
}
|
|
70353
|
-
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu.test(encoded)) {
|
|
70354
|
-
encoded = `%${encoded.charCodeAt(0).toString(16).toUpperCase()}${encoded.slice(1)}`;
|
|
70355
|
-
}
|
|
70356
|
-
return `${encoded}.bin`;
|
|
70357
|
-
}
|
|
70358
|
-
function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
70359
|
-
const powershell = `${env.SystemRoot ?? "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
70360
|
-
const fileDetails = (name) => {
|
|
70361
|
-
const file2 = windowsSecretFileName(accountFor(name));
|
|
70362
|
-
return { file: file2, account: file2.slice(0, -".bin".length) };
|
|
70363
|
-
};
|
|
70364
|
-
const script = (file2, operations) => [
|
|
70365
|
-
"$ErrorActionPreference = 'Stop'",
|
|
70366
|
-
"try {",
|
|
70367
|
-
" Add-Type -AssemblyName System.Security",
|
|
70368
|
-
" $dir = Join-Path $env:LOCALAPPDATA 'vapi-network\\secrets'",
|
|
70369
|
-
` $path = Join-Path $dir '${file2}'`,
|
|
70370
|
-
...operations.map((operation) => ` ${operation}`),
|
|
70371
|
-
"} catch {",
|
|
70372
|
-
" [Console]::Error.WriteLine($_.Exception.Message)",
|
|
70373
|
-
" exit 1",
|
|
70374
|
-
"}"
|
|
70375
|
-
].join("\n");
|
|
70376
|
-
const execute = async (script2) => {
|
|
70377
|
-
const result = await run(powershell, WINDOWS_POWERSHELL_ARGS, `${script2}
|
|
70378
|
-
|
|
70379
|
-
`);
|
|
70380
|
-
requirePowerShell(result);
|
|
70381
|
-
return result;
|
|
70382
|
-
};
|
|
70383
|
-
return {
|
|
70384
|
-
available: installed(powershell),
|
|
70385
|
-
platform: platform2,
|
|
70386
|
-
description: "Windows Data Protection (DPAPI)",
|
|
70387
|
-
async get(name) {
|
|
70388
|
-
const { file: file2, account } = fileDetails(name);
|
|
70389
|
-
const result = await execute(
|
|
70390
|
-
script(file2, [
|
|
70391
|
-
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
70392
|
-
"$blob = [System.IO.File]::ReadAllBytes($path)",
|
|
70393
|
-
"$bytes = [System.Security.Cryptography.ProtectedData]::Unprotect($blob, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
70394
|
-
"[Console]::Out.Write([Convert]::ToBase64String($bytes))",
|
|
70395
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70396
|
-
])
|
|
70397
|
-
);
|
|
70398
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return void 0;
|
|
70399
|
-
requireSuccess(result, `read the passphrase of ${name} from Windows Data Protection`);
|
|
70400
|
-
const value = Buffer.from(result.stdout.trim(), "base64").toString("utf8");
|
|
70401
|
-
return value.length === 0 ? void 0 : value;
|
|
70402
|
-
},
|
|
70403
|
-
async has(name) {
|
|
70404
|
-
const { file: file2, account } = fileDetails(name);
|
|
70405
|
-
const result = await execute(
|
|
70406
|
-
script(file2, [
|
|
70407
|
-
`if (Test-Path -LiteralPath $path) { exit ${WINDOWS_SECRET_SUCCESS} }`,
|
|
70408
|
-
`[Console]::Error.WriteLine('No stored secret for ${account}.')`,
|
|
70409
|
-
`exit ${WINDOWS_SECRET_NOT_FOUND}`
|
|
70410
|
-
])
|
|
70411
|
-
);
|
|
70412
|
-
if (result.code === WINDOWS_SECRET_SUCCESS) return true;
|
|
70413
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
70414
|
-
requireSuccess(result, `look up ${name} in Windows Data Protection`);
|
|
70415
|
-
return false;
|
|
70416
|
-
},
|
|
70417
|
-
async set(name, passphrase) {
|
|
70418
|
-
requirePassphrase(passphrase);
|
|
70419
|
-
const { file: file2 } = fileDetails(name);
|
|
70420
|
-
const value = Buffer.from(passphrase, "utf8").toString("base64");
|
|
70421
|
-
const result = await execute(
|
|
70422
|
-
script(file2, [
|
|
70423
|
-
"[void][System.IO.Directory]::CreateDirectory($dir)",
|
|
70424
|
-
`$bytes = [Convert]::FromBase64String('${value}')`,
|
|
70425
|
-
"$blob = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
70426
|
-
"[System.IO.File]::WriteAllBytes($path, $blob)",
|
|
70427
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70428
|
-
])
|
|
70429
|
-
);
|
|
70430
|
-
requireSuccess(result, `store the passphrase of ${name} in Windows Data Protection`);
|
|
70431
|
-
},
|
|
70432
|
-
async remove(name) {
|
|
70433
|
-
const { file: file2, account } = fileDetails(name);
|
|
70434
|
-
const result = await execute(
|
|
70435
|
-
script(file2, [
|
|
70436
|
-
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
70437
|
-
"Remove-Item -LiteralPath $path -Force",
|
|
70438
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70439
|
-
])
|
|
70440
|
-
);
|
|
70441
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
70442
|
-
requireSuccess(result, `remove the passphrase of ${name} from Windows Data Protection`);
|
|
70443
|
-
return true;
|
|
70444
|
-
}
|
|
70445
|
-
};
|
|
70446
|
-
}
|
|
70447
|
-
function libsecretStore(platform2, run, installed) {
|
|
70448
|
-
const lookup2 = async (name) => {
|
|
70449
|
-
const result = await run(SECRET_TOOL_BINARY, [
|
|
70450
|
-
"lookup",
|
|
70451
|
-
"service",
|
|
70452
|
-
SECRET_STORE_SERVICE,
|
|
70453
|
-
"account",
|
|
70454
|
-
accountFor(name)
|
|
70455
|
-
]);
|
|
70456
|
-
requireBinary(result);
|
|
70457
|
-
const value = withoutTrailingNewline(result.stdout);
|
|
70458
|
-
if (result.code === 0) return value.length === 0 ? void 0 : value;
|
|
70459
|
-
if (result.stderr.trim().length === 0) return void 0;
|
|
70460
|
-
requireSuccess(result, `read the passphrase of ${name} from the secret service`);
|
|
70461
|
-
return void 0;
|
|
70462
|
-
};
|
|
70463
|
-
return {
|
|
70464
|
-
available: installed(SECRET_TOOL_BINARY),
|
|
70465
|
-
platform: platform2,
|
|
70466
|
-
description: "the libsecret keyring",
|
|
70467
|
-
get: lookup2,
|
|
70468
|
-
async has(name) {
|
|
70469
|
-
return await lookup2(name) !== void 0;
|
|
70470
|
-
},
|
|
70471
|
-
async set(name, passphrase) {
|
|
70472
|
-
requirePassphrase(passphrase);
|
|
70473
|
-
const account = accountFor(name);
|
|
70474
|
-
const result = await run(
|
|
70475
|
-
SECRET_TOOL_BINARY,
|
|
70476
|
-
[
|
|
70477
|
-
"store",
|
|
70478
|
-
`--label=${SECRET_STORE_SERVICE} ${account}`,
|
|
70479
|
-
"service",
|
|
70480
|
-
SECRET_STORE_SERVICE,
|
|
70481
|
-
"account",
|
|
70482
|
-
account
|
|
70483
|
-
],
|
|
70484
|
-
`${passphrase}
|
|
70485
|
-
`
|
|
70486
|
-
);
|
|
70487
|
-
requireBinary(result);
|
|
70488
|
-
requireSuccess(result, `store the passphrase of ${name} in the secret service`);
|
|
70489
|
-
},
|
|
70490
|
-
async remove(name) {
|
|
70491
|
-
const existed = await lookup2(name) !== void 0;
|
|
70492
|
-
const result = await run(SECRET_TOOL_BINARY, [
|
|
70493
|
-
"clear",
|
|
70494
|
-
"service",
|
|
70495
|
-
SECRET_STORE_SERVICE,
|
|
70496
|
-
"account",
|
|
70497
|
-
accountFor(name)
|
|
70498
|
-
]);
|
|
70499
|
-
requireBinary(result);
|
|
70500
|
-
requireSuccess(result, `remove the passphrase of ${name} from the secret service`);
|
|
70501
|
-
return existed;
|
|
70502
|
-
}
|
|
70503
|
-
};
|
|
70504
|
-
}
|
|
70505
|
-
function unsupportedStore(platform2) {
|
|
70506
|
-
const refuse = () => {
|
|
70507
|
-
throw new KeystoreError(UNSUPPORTED_PLATFORM);
|
|
70508
|
-
};
|
|
70509
|
-
return {
|
|
70510
|
-
available: false,
|
|
70511
|
-
platform: platform2,
|
|
70512
|
-
description: "no OS secret store",
|
|
70513
|
-
get: async () => refuse(),
|
|
70514
|
-
has: async () => refuse(),
|
|
70515
|
-
set: async () => refuse(),
|
|
70516
|
-
remove: async () => refuse()
|
|
70517
|
-
};
|
|
70518
|
-
}
|
|
70519
|
-
function accountFor(name) {
|
|
70520
|
-
const account = name.trim();
|
|
70521
|
-
if (account.length === 0) {
|
|
70522
|
-
throw new KeystoreError("A wallet name is needed to reach the OS secret store.");
|
|
70523
|
-
}
|
|
70524
|
-
return account;
|
|
70525
|
-
}
|
|
70526
|
-
function requirePassphrase(passphrase) {
|
|
70527
|
-
if (passphrase.length === 0) {
|
|
70528
|
-
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
70529
|
-
}
|
|
70530
|
-
}
|
|
70531
|
-
function requireBinary(result) {
|
|
70532
|
-
if (result.notFound === true) throw new KeystoreError(SECRET_TOOL_MISSING);
|
|
70533
|
-
}
|
|
70534
|
-
function requirePowerShell(result) {
|
|
70535
|
-
if (result.notFound === true) throw new KeystoreError(POWERSHELL_MISSING);
|
|
70536
|
-
}
|
|
70537
|
-
function binaryInstalled(file2, env) {
|
|
70538
|
-
if (isAbsolute(file2) || win32.isAbsolute(file2)) return existsSync(file2);
|
|
70539
|
-
return (env.PATH ?? "").split(delimiter).some((directory) => existsSync(join6(directory, file2)));
|
|
70540
|
-
}
|
|
70541
|
-
function requireSuccess(result, what) {
|
|
70542
|
-
if (result.code === 0) return;
|
|
70543
|
-
const detail = result.stderr.trim() || result.stdout.trim();
|
|
70544
|
-
throw new KeystoreError(
|
|
70545
|
-
`Could not ${what}${result.code === null ? "" : ` (exit ${result.code})`}.${detail.length === 0 ? "" : ` ${detail}`}`
|
|
70546
|
-
);
|
|
70547
|
-
}
|
|
70548
|
-
function withoutTrailingNewline(value) {
|
|
70549
|
-
return value.replace(/\r?\n$/u, "");
|
|
70550
|
-
}
|
|
70551
|
-
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve3) => {
|
|
70552
|
-
let stdout = "";
|
|
70553
|
-
let stderr2 = "";
|
|
70554
|
-
let settled = false;
|
|
70555
|
-
const finish = (outcome) => {
|
|
70556
|
-
if (settled) return;
|
|
70557
|
-
settled = true;
|
|
70558
|
-
resolve3(outcome);
|
|
70559
|
-
};
|
|
70560
|
-
const child = spawn(file2, [...args], {
|
|
70561
|
-
detached: platform2 !== "win32",
|
|
70562
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
70563
|
-
windowsHide: true
|
|
70564
|
-
});
|
|
70565
|
-
child.stdout?.setEncoding("utf8");
|
|
70566
|
-
child.stdout?.on("data", (chunk) => {
|
|
70567
|
-
stdout += chunk;
|
|
70568
|
-
});
|
|
70569
|
-
child.stderr?.setEncoding("utf8");
|
|
70570
|
-
child.stderr?.on("data", (chunk) => {
|
|
70571
|
-
stderr2 += chunk;
|
|
70572
|
-
});
|
|
70573
|
-
child.on("error", (error61) => {
|
|
70574
|
-
finish({
|
|
70575
|
-
code: null,
|
|
70576
|
-
stdout,
|
|
70577
|
-
stderr: stderr2,
|
|
70578
|
-
...error61.code === "ENOENT" ? { notFound: true } : {}
|
|
70579
|
-
});
|
|
70580
|
-
});
|
|
70581
|
-
child.on("close", (code) => finish({ code, stdout, stderr: stderr2 }));
|
|
70582
|
-
child.stdin?.on("error", () => void 0);
|
|
70583
|
-
child.stdin?.end(input2 ?? "");
|
|
70584
|
-
});
|
|
70585
|
-
|
|
70586
|
-
// ../core/src/passphrase.ts
|
|
70587
|
-
var PASSPHRASE_ENVIRONMENT_VARIABLE = "VAPI_KEYSTORE_PASSWORD";
|
|
70588
|
-
function noPassphraseHint(walletName) {
|
|
70589
|
-
return `Set ${PASSPHRASE_ENVIRONMENT_VARIABLE}, or store this wallet's passphrase once with vapi unlock --wallet ${walletName}.`;
|
|
70590
|
-
}
|
|
70591
|
-
function staleStoredPassphraseMessage(walletName, store) {
|
|
70592
|
-
return [
|
|
70593
|
-
`The passphrase stored in ${store.description} no longer opens wallet ${walletName}.`,
|
|
70594
|
-
`Store the current one with vapi unlock --wallet ${walletName}, or remove it with vapi lock --wallet ${walletName}.`
|
|
70595
|
-
].join(" ");
|
|
70596
|
-
}
|
|
70597
|
-
async function resolvePassphrase(walletName, options = {}) {
|
|
70598
|
-
const env = options.env ?? process.env;
|
|
70599
|
-
const fromEnvironment = env[PASSPHRASE_ENVIRONMENT_VARIABLE];
|
|
70600
|
-
if (fromEnvironment !== void 0) {
|
|
70601
|
-
if (fromEnvironment.length === 0) {
|
|
70602
|
-
throw new KeystoreError(`${PASSPHRASE_ENVIRONMENT_VARIABLE} cannot be empty.`);
|
|
70603
|
-
}
|
|
70604
|
-
return { passphrase: fromEnvironment, source: "environment" };
|
|
70605
|
-
}
|
|
70606
|
-
if (options.confirm !== true) {
|
|
70607
|
-
const stored = await readStored(options.store ?? secretStore(), walletName);
|
|
70608
|
-
if (stored !== void 0) return { passphrase: stored, source: "secret-store" };
|
|
70609
|
-
}
|
|
70610
|
-
const hint = noPassphraseHint(walletName);
|
|
70611
|
-
if (options.interactive === false) {
|
|
70612
|
-
throw new KeystoreError(
|
|
70613
|
-
`No interactive terminal is available for the keystore prompt. ${hint}`
|
|
70614
|
-
);
|
|
70615
|
-
}
|
|
70616
|
-
const prompt = options.prompt ?? promptForSecret;
|
|
70617
|
-
const first = await prompt(`Passphrase for ${walletName}: `, hint);
|
|
70618
|
-
if (first.length === 0) {
|
|
70619
|
-
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
70620
|
-
}
|
|
70621
|
-
if (options.confirm === true) {
|
|
70622
|
-
const second = await prompt("Confirm passphrase: ", hint);
|
|
70623
|
-
if (first !== second) throw new KeystoreError("Passphrases do not match.");
|
|
70624
|
-
}
|
|
70625
|
-
return { passphrase: first, source: "prompt" };
|
|
70626
|
-
}
|
|
70627
|
-
async function readStored(store, walletName) {
|
|
70628
|
-
if (!store.available) return void 0;
|
|
70629
|
-
try {
|
|
70630
|
-
return await store.get(walletName);
|
|
70631
|
-
} catch {
|
|
70632
|
-
return void 0;
|
|
70633
|
-
}
|
|
70634
|
-
}
|
|
70165
|
+
import { delimiter, isAbsolute, join as join7, win32 } from "node:path";
|
|
70635
70166
|
|
|
70636
|
-
// ../core/src/
|
|
70167
|
+
// ../core/src/file-secret-store.ts
|
|
70637
70168
|
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
70638
|
-
import {
|
|
70639
|
-
import { dirname as dirname5 } from "node:path";
|
|
70169
|
+
import { readFile as readFile8, stat as stat7 } from "node:fs/promises";
|
|
70640
70170
|
|
|
70641
|
-
// ../core/src/
|
|
70171
|
+
// ../core/src/vault.ts
|
|
70642
70172
|
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
70643
|
-
|
|
70644
|
-
|
|
70645
|
-
return typeof value === "string" && RUN_ID_PATTERN.test(value);
|
|
70646
|
-
}
|
|
70647
|
-
function createRunId(random = randomBytes5) {
|
|
70648
|
-
return `run_${Buffer.from(random(12)).toString("hex")}`;
|
|
70649
|
-
}
|
|
70650
|
-
var runRefSchema = external_exports.strictObject({
|
|
70651
|
-
id: external_exports.string().regex(RUN_ID_PATTERN),
|
|
70652
|
-
swarm: external_exports.string().optional(),
|
|
70653
|
-
member: external_exports.string().optional(),
|
|
70654
|
-
parentRunId: external_exports.string().optional()
|
|
70655
|
-
});
|
|
70173
|
+
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";
|
|
70174
|
+
import { dirname as dirname5 } from "node:path";
|
|
70656
70175
|
|
|
70657
70176
|
// ../core/src/wallet-name.ts
|
|
70658
70177
|
var DEFAULT_WALLET_NAME = "main";
|
|
@@ -70665,260 +70184,7 @@ function isWalletName(value) {
|
|
|
70665
70184
|
return WALLET_NAME_PATTERN.test(value);
|
|
70666
70185
|
}
|
|
70667
70186
|
|
|
70668
|
-
// ../core/src/receipts.ts
|
|
70669
|
-
var receiptTestHooks;
|
|
70670
|
-
var RECEIPT_JOURNAL_BUSY_MESSAGE = "The receipt journal is busy. Wait for the other vapi command to finish, then retry.";
|
|
70671
|
-
async function withReceiptJournalLock(path, operation) {
|
|
70672
|
-
return await withFileLock(`${path}.lock`, operation, {
|
|
70673
|
-
lockedMessage: RECEIPT_JOURNAL_BUSY_MESSAGE
|
|
70674
|
-
});
|
|
70675
|
-
}
|
|
70676
|
-
var durationSchema = external_exports.number().nonnegative().finite();
|
|
70677
|
-
var receiptSchema = external_exports.strictObject({
|
|
70678
|
-
id: external_exports.string().min(1),
|
|
70679
|
-
timestamp: external_exports.iso.datetime(),
|
|
70680
|
-
run: runRefSchema.optional(),
|
|
70681
|
-
kind: external_exports.literal("transfer").optional(),
|
|
70682
|
-
wallet: walletNameSchema.optional(),
|
|
70683
|
-
resourceUrl: external_exports.url(),
|
|
70684
|
-
method: external_exports.string().min(1).optional(),
|
|
70685
|
-
source: external_exports.string().min(1).optional(),
|
|
70686
|
-
provenance: external_exports.array(
|
|
70687
|
-
external_exports.strictObject({
|
|
70688
|
-
source: external_exports.string().min(1),
|
|
70689
|
-
sourceUrl: external_exports.string().optional(),
|
|
70690
|
-
ref: external_exports.string().optional()
|
|
70691
|
-
})
|
|
70692
|
-
).optional(),
|
|
70693
|
-
quote: external_exports.strictObject({
|
|
70694
|
-
network: external_exports.string(),
|
|
70695
|
-
asset: external_exports.string().optional(),
|
|
70696
|
-
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
70697
|
-
payTo: external_exports.string().optional()
|
|
70698
|
-
}).optional(),
|
|
70699
|
-
payer: external_exports.string().optional(),
|
|
70700
|
-
paymentId: external_exports.string().regex(/^[A-Za-z0-9_-]{16,128}$/).optional(),
|
|
70701
|
-
authorization: external_exports.strictObject({
|
|
70702
|
-
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70703
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
70704
|
-
validBefore: external_exports.string().regex(/^\d+$/)
|
|
70705
|
-
}).optional(),
|
|
70706
|
-
transfer: external_exports.strictObject({
|
|
70707
|
-
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70708
|
-
toName: external_exports.string().min(1),
|
|
70709
|
-
toKind: external_exports.enum(["owner", "account"]),
|
|
70710
|
-
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
70711
|
-
network: external_exports.string().min(1),
|
|
70712
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
70713
|
-
status: external_exports.enum(["sent", "unknown", "failed"]),
|
|
70714
|
-
txHash: external_exports.string().regex(/^0x[0-9a-fA-F]+$/).nullable(),
|
|
70715
|
-
replayed: external_exports.boolean(),
|
|
70716
|
-
reservedOn: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
70717
|
-
request: external_exports.strictObject({
|
|
70718
|
-
authorization: external_exports.strictObject({
|
|
70719
|
-
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70720
|
-
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70721
|
-
value: external_exports.string().regex(/^\d+$/),
|
|
70722
|
-
validAfter: external_exports.string().regex(/^\d+$/),
|
|
70723
|
-
validBefore: external_exports.string().regex(/^\d+$/),
|
|
70724
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/)
|
|
70725
|
-
}),
|
|
70726
|
-
signature: external_exports.string().regex(/^0x[0-9a-fA-F]+$/)
|
|
70727
|
-
}).optional()
|
|
70728
|
-
}).optional(),
|
|
70729
|
-
settlement: external_exports.strictObject({
|
|
70730
|
-
outcome: external_exports.enum(["succeeded", "rejected", "unknown"]),
|
|
70731
|
-
transaction: external_exports.string().optional(),
|
|
70732
|
-
explorerUrl: external_exports.url().optional(),
|
|
70733
|
-
evidence: external_exports.unknown().optional()
|
|
70734
|
-
}).optional(),
|
|
70735
|
-
latencyMs: external_exports.number().nonnegative().finite().optional(),
|
|
70736
|
-
status: external_exports.number().int().min(100).max(599).optional(),
|
|
70737
|
-
error: external_exports.strictObject({ code: external_exports.string(), message: external_exports.string() }).optional(),
|
|
70738
|
-
phases: external_exports.strictObject({
|
|
70739
|
-
discoverMs: durationSchema.optional(),
|
|
70740
|
-
quoteMs: durationSchema.optional(),
|
|
70741
|
-
signMs: durationSchema.optional(),
|
|
70742
|
-
requestMs: durationSchema.optional(),
|
|
70743
|
-
settleMs: durationSchema.optional()
|
|
70744
|
-
}).optional(),
|
|
70745
|
-
listing: external_exports.strictObject({
|
|
70746
|
-
name: external_exports.string().min(1).optional(),
|
|
70747
|
-
providerHost: external_exports.string().min(1).optional(),
|
|
70748
|
-
source: external_exports.string().min(1)
|
|
70749
|
-
}).optional(),
|
|
70750
|
-
retry: external_exports.number().int().nonnegative().optional(),
|
|
70751
|
-
policy: external_exports.strictObject({
|
|
70752
|
-
maxPriceUsd: external_exports.string().regex(/^\d+(?:\.\d{1,6})?$/).optional(),
|
|
70753
|
-
capsApplied: external_exports.boolean()
|
|
70754
|
-
}).optional(),
|
|
70755
|
-
client: external_exports.strictObject({ name: external_exports.literal("vapi-network"), version: external_exports.string().min(1) }).optional(),
|
|
70756
|
-
outcome: external_exports.enum([
|
|
70757
|
-
"paid",
|
|
70758
|
-
"signed_in",
|
|
70759
|
-
"declined_policy",
|
|
70760
|
-
"failed_request",
|
|
70761
|
-
"settlement_rejected",
|
|
70762
|
-
"settlement_unknown"
|
|
70763
|
-
]).optional()
|
|
70764
|
-
});
|
|
70765
|
-
function parseReceipt(value) {
|
|
70766
|
-
const receipt = receiptSchema.parse(value);
|
|
70767
|
-
const transaction2 = receipt.settlement?.transaction;
|
|
70768
|
-
const network = receipt.quote?.network;
|
|
70769
|
-
const explorerUrl = transaction2 === void 0 || network === void 0 ? void 0 : explorerTransactionUrl(network, transaction2);
|
|
70770
|
-
if (explorerUrl === void 0 || receipt.settlement?.explorerUrl === explorerUrl) {
|
|
70771
|
-
return receipt;
|
|
70772
|
-
}
|
|
70773
|
-
return {
|
|
70774
|
-
...receipt,
|
|
70775
|
-
settlement: {
|
|
70776
|
-
outcome: receipt.settlement.outcome,
|
|
70777
|
-
...receipt.settlement.transaction ? { transaction: receipt.settlement.transaction } : {},
|
|
70778
|
-
explorerUrl,
|
|
70779
|
-
...receipt.settlement.evidence === void 0 ? {} : { evidence: receipt.settlement.evidence }
|
|
70780
|
-
}
|
|
70781
|
-
};
|
|
70782
|
-
}
|
|
70783
|
-
async function appendReceipt(receipt, path = getVapiPaths().receipts, options = {}) {
|
|
70784
|
-
const parsed = parseReceipt(
|
|
70785
|
-
receipt.wallet === void 0 && options.wallet !== void 0 ? { ...receipt, wallet: options.wallet } : receipt
|
|
70786
|
-
);
|
|
70787
|
-
await withReceiptJournalLock(path, async () => {
|
|
70788
|
-
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70789
|
-
const handle = await open5(path, "a", 384);
|
|
70790
|
-
try {
|
|
70791
|
-
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
70792
|
-
`, "utf8");
|
|
70793
|
-
} finally {
|
|
70794
|
-
await handle.close();
|
|
70795
|
-
}
|
|
70796
|
-
});
|
|
70797
|
-
return parsed;
|
|
70798
|
-
}
|
|
70799
|
-
async function readReceipts(path = getVapiPaths().receipts, options = {}) {
|
|
70800
|
-
let raw;
|
|
70801
|
-
try {
|
|
70802
|
-
raw = await readFile7(path, "utf8");
|
|
70803
|
-
} catch (error61) {
|
|
70804
|
-
if (isMissingFile(error61)) return [];
|
|
70805
|
-
throw error61;
|
|
70806
|
-
}
|
|
70807
|
-
const records = coalesceTransferReceiptRevisions(
|
|
70808
|
-
raw.split("\n").filter((line) => line.trim().length > 0).map((line, index2) => {
|
|
70809
|
-
try {
|
|
70810
|
-
return parseReceipt(JSON.parse(line));
|
|
70811
|
-
} catch (error61) {
|
|
70812
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70813
|
-
}
|
|
70814
|
-
})
|
|
70815
|
-
);
|
|
70816
|
-
const filtered = options.wallet === void 0 ? records : filterReceiptsByWallet(records, options.wallet);
|
|
70817
|
-
const limit = options.limit;
|
|
70818
|
-
if (limit === void 0) return filtered;
|
|
70819
|
-
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
70820
|
-
throw new Error("Receipt limit must be a non-negative integer.");
|
|
70821
|
-
return limit === 0 ? [] : filtered.slice(-limit);
|
|
70822
|
-
}
|
|
70823
|
-
function coalesceTransferReceiptRevisions(receipts) {
|
|
70824
|
-
const coalesced = [];
|
|
70825
|
-
const transferIndexes = /* @__PURE__ */ new Map();
|
|
70826
|
-
for (const receipt of receipts) {
|
|
70827
|
-
const existing = receipt.kind === "transfer" ? transferIndexes.get(receipt.id) : void 0;
|
|
70828
|
-
if (existing === void 0) {
|
|
70829
|
-
if (receipt.kind === "transfer") transferIndexes.set(receipt.id, coalesced.length);
|
|
70830
|
-
coalesced.push(receipt);
|
|
70831
|
-
} else {
|
|
70832
|
-
coalesced[existing] = receipt;
|
|
70833
|
-
}
|
|
70834
|
-
}
|
|
70835
|
-
return coalesced;
|
|
70836
|
-
}
|
|
70837
|
-
function receiptWallet(receipt) {
|
|
70838
|
-
return receipt.wallet ?? DEFAULT_WALLET_NAME;
|
|
70839
|
-
}
|
|
70840
|
-
function filterReceiptsByWallet(receipts, name) {
|
|
70841
|
-
return receipts.filter((receipt) => receiptWallet(receipt) === name);
|
|
70842
|
-
}
|
|
70843
|
-
async function renameReceiptWallet(from16, to, path = getVapiPaths().receipts) {
|
|
70844
|
-
return await withReceiptJournalLock(path, async () => {
|
|
70845
|
-
let raw;
|
|
70846
|
-
try {
|
|
70847
|
-
raw = await readFile7(path, "utf8");
|
|
70848
|
-
} catch (error61) {
|
|
70849
|
-
if (isMissingFile(error61)) return 0;
|
|
70850
|
-
throw error61;
|
|
70851
|
-
}
|
|
70852
|
-
let changed = 0;
|
|
70853
|
-
const lines = raw.split("\n").map((line, index2) => {
|
|
70854
|
-
if (line.trim().length === 0) return line;
|
|
70855
|
-
let parsed;
|
|
70856
|
-
try {
|
|
70857
|
-
parsed = JSON.parse(line);
|
|
70858
|
-
} catch (error61) {
|
|
70859
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70860
|
-
}
|
|
70861
|
-
const current = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "wallet") : void 0;
|
|
70862
|
-
if ((typeof current === "string" ? current : DEFAULT_WALLET_NAME) !== from16) return line;
|
|
70863
|
-
changed += 1;
|
|
70864
|
-
return JSON.stringify(parseReceipt({ ...parsed, wallet: to }));
|
|
70865
|
-
});
|
|
70866
|
-
if (changed === 0) return 0;
|
|
70867
|
-
await receiptTestHooks?.beforeRenameReplace?.(path);
|
|
70868
|
-
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70869
|
-
const temporaryPath = `${path}.${process.pid}.${randomBytes6(6).toString("hex")}.tmp`;
|
|
70870
|
-
await writeFile3(temporaryPath, lines.join("\n"), {
|
|
70871
|
-
encoding: "utf8",
|
|
70872
|
-
mode: 384,
|
|
70873
|
-
flag: "wx"
|
|
70874
|
-
});
|
|
70875
|
-
await rename4(temporaryPath, path);
|
|
70876
|
-
return changed;
|
|
70877
|
-
});
|
|
70878
|
-
}
|
|
70879
|
-
|
|
70880
|
-
// ../core/src/transfer-journal.ts
|
|
70881
|
-
import { readFile as readFile8 } from "node:fs/promises";
|
|
70882
|
-
async function readTransferJournal(home, from16, nonce) {
|
|
70883
|
-
let raw;
|
|
70884
|
-
try {
|
|
70885
|
-
raw = await readFile8(getVapiPaths(home).receipts, "utf8");
|
|
70886
|
-
} catch (error61) {
|
|
70887
|
-
if (isMissingFile(error61)) return { signed: false };
|
|
70888
|
-
throw error61;
|
|
70889
|
-
}
|
|
70890
|
-
let latest;
|
|
70891
|
-
let request;
|
|
70892
|
-
for (const [index2, line] of raw.split("\n").entries()) {
|
|
70893
|
-
if (!line.trim()) continue;
|
|
70894
|
-
let receipt;
|
|
70895
|
-
try {
|
|
70896
|
-
receipt = parseReceipt(JSON.parse(line));
|
|
70897
|
-
} catch (error61) {
|
|
70898
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70899
|
-
}
|
|
70900
|
-
if (receiptWallet(receipt) !== from16 || receipt.transfer?.nonce.toLowerCase() !== nonce.toLowerCase()) {
|
|
70901
|
-
continue;
|
|
70902
|
-
}
|
|
70903
|
-
latest = receipt;
|
|
70904
|
-
if (receipt.transfer.request !== void 0) request = receipt;
|
|
70905
|
-
}
|
|
70906
|
-
return {
|
|
70907
|
-
signed: latest !== void 0,
|
|
70908
|
-
...latest === void 0 ? {} : { latest },
|
|
70909
|
-
...request === void 0 ? {} : { request },
|
|
70910
|
-
...request?.transfer?.request?.authorization.validBefore === void 0 ? {} : { validBefore: request.transfer.request.authorization.validBefore },
|
|
70911
|
-
...(latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn) === void 0 ? {} : { reservedOn: latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn }
|
|
70912
|
-
};
|
|
70913
|
-
}
|
|
70914
|
-
|
|
70915
|
-
// ../core/src/vault-key.ts
|
|
70916
|
-
import { randomBytes as cryptoRandomBytes } from "node:crypto";
|
|
70917
|
-
|
|
70918
70187
|
// ../core/src/vault.ts
|
|
70919
|
-
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
70920
|
-
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";
|
|
70921
|
-
import { dirname as dirname6 } from "node:path";
|
|
70922
70188
|
var VaultError = class extends Error {
|
|
70923
70189
|
code;
|
|
70924
70190
|
constructor(code, message, options) {
|
|
@@ -71304,249 +70570,1227 @@ async function exportVaultAccountKey(args) {
|
|
|
71304
70570
|
if (privateKeyToAccount(privateKey).address.toLowerCase() !== account.address.toLowerCase()) {
|
|
71305
70571
|
throw new VaultError("corrupt", "A vault key does not match its stored address.");
|
|
71306
70572
|
}
|
|
71307
|
-
return privateKey;
|
|
71308
|
-
} catch (error61) {
|
|
71309
|
-
throw asVaultError(error61, "corrupt", "Unable to export the vault account key.");
|
|
70573
|
+
return privateKey;
|
|
70574
|
+
} catch (error61) {
|
|
70575
|
+
throw asVaultError(error61, "corrupt", "Unable to export the vault account key.");
|
|
70576
|
+
}
|
|
70577
|
+
}
|
|
70578
|
+
async function exportMemberKey(args) {
|
|
70579
|
+
return await exportVaultAccountKey(args);
|
|
70580
|
+
}
|
|
70581
|
+
function assertVaultKey(key2) {
|
|
70582
|
+
if (key2.byteLength !== 32) {
|
|
70583
|
+
throw new VaultError("bad_key", "A device vault key must contain exactly 32 bytes.");
|
|
70584
|
+
}
|
|
70585
|
+
}
|
|
70586
|
+
function assertAccountName(name) {
|
|
70587
|
+
const parsed = walletNameSchema.safeParse(name);
|
|
70588
|
+
if (!parsed.success) {
|
|
70589
|
+
throw new VaultError("name_taken", "The vault account name is not valid.", {
|
|
70590
|
+
cause: parsed.error
|
|
70591
|
+
});
|
|
70592
|
+
}
|
|
70593
|
+
}
|
|
70594
|
+
function assertAvailableName(file2, name) {
|
|
70595
|
+
assertAccountName(name);
|
|
70596
|
+
if (file2.accounts.some((account) => account.name === name)) {
|
|
70597
|
+
throw new VaultError("name_taken", "A vault account already has that name.");
|
|
70598
|
+
}
|
|
70599
|
+
}
|
|
70600
|
+
function nextDerivedIndex(file2) {
|
|
70601
|
+
let next = file2.nextDerivedIndex ?? 0;
|
|
70602
|
+
for (const account of file2.accounts) {
|
|
70603
|
+
if (account.kind === "derived") next = Math.max(next, account.index + 1);
|
|
70604
|
+
}
|
|
70605
|
+
return next;
|
|
70606
|
+
}
|
|
70607
|
+
function copyAccount(account) {
|
|
70608
|
+
if (account.kind === "derived") return { ...account };
|
|
70609
|
+
return {
|
|
70610
|
+
name: account.name,
|
|
70611
|
+
kind: account.kind,
|
|
70612
|
+
address: account.address,
|
|
70613
|
+
createdAt: account.createdAt
|
|
70614
|
+
};
|
|
70615
|
+
}
|
|
70616
|
+
function sealField(key2, plaintext) {
|
|
70617
|
+
const { nonce, ciphertext, tag } = encryptWithKey(key2, plaintext);
|
|
70618
|
+
return [nonce, ciphertext, tag].map((part) => part.toString("base64url")).join(".");
|
|
70619
|
+
}
|
|
70620
|
+
function openField(key2, value) {
|
|
70621
|
+
const [nonce = "", ciphertext = "", tag = ""] = value.split(".");
|
|
70622
|
+
return decryptWithKey(key2, {
|
|
70623
|
+
nonce: Buffer.from(nonce, "base64url"),
|
|
70624
|
+
ciphertext: Buffer.from(ciphertext, "base64url"),
|
|
70625
|
+
tag: Buffer.from(tag, "base64url")
|
|
70626
|
+
});
|
|
70627
|
+
}
|
|
70628
|
+
function decryptField(key2, value) {
|
|
70629
|
+
try {
|
|
70630
|
+
return openField(key2, value);
|
|
70631
|
+
} catch (error61) {
|
|
70632
|
+
throw new VaultError("bad_key", "Unable to decrypt the vault with this device key.", {
|
|
70633
|
+
cause: error61
|
|
70634
|
+
});
|
|
70635
|
+
}
|
|
70636
|
+
}
|
|
70637
|
+
function decryptPhraseForOpen(key2, phrase) {
|
|
70638
|
+
try {
|
|
70639
|
+
return openField(key2, phrase);
|
|
70640
|
+
} catch (error61) {
|
|
70641
|
+
throw new VaultError("bad_key", "Unable to decrypt the vault with this device key.", {
|
|
70642
|
+
cause: error61
|
|
70643
|
+
});
|
|
70644
|
+
}
|
|
70645
|
+
}
|
|
70646
|
+
function validateStoredImportedAccount(key2, account) {
|
|
70647
|
+
let plaintext;
|
|
70648
|
+
try {
|
|
70649
|
+
plaintext = decryptField(key2, account.key);
|
|
70650
|
+
if (plaintext.byteLength !== 32) {
|
|
70651
|
+
throw new VaultError("bad_key", "The stored imported key has the wrong length.");
|
|
70652
|
+
}
|
|
70653
|
+
let address4;
|
|
70654
|
+
try {
|
|
70655
|
+
address4 = privateKeyToAccount(`0x${plaintext.toString("hex")}`).address;
|
|
70656
|
+
} catch (error61) {
|
|
70657
|
+
throw new VaultError("bad_key", "The stored imported key is not valid.", {
|
|
70658
|
+
cause: error61
|
|
70659
|
+
});
|
|
70660
|
+
}
|
|
70661
|
+
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
70662
|
+
throw new VaultError("bad_key", "The stored imported key does not match its address.");
|
|
70663
|
+
}
|
|
70664
|
+
} finally {
|
|
70665
|
+
plaintext?.fill(0);
|
|
70666
|
+
}
|
|
70667
|
+
}
|
|
70668
|
+
function validateStoredDerivedAccount(key2, file2, account) {
|
|
70669
|
+
const plaintext = decryptField(key2, file2.phrase);
|
|
70670
|
+
let seed;
|
|
70671
|
+
try {
|
|
70672
|
+
seed = phraseToSeed(plaintext.toString("utf8"));
|
|
70673
|
+
const address4 = privateKeyToAccount(
|
|
70674
|
+
deriveEvmPrivateKey(seed, `m/44'/60'/0'/0/${account.index}`)
|
|
70675
|
+
).address;
|
|
70676
|
+
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
70677
|
+
throw new VaultError("bad_key", "The stored derived account does not match this vault.");
|
|
70678
|
+
}
|
|
70679
|
+
} finally {
|
|
70680
|
+
seed?.fill(0);
|
|
70681
|
+
plaintext.fill(0);
|
|
70682
|
+
}
|
|
70683
|
+
}
|
|
70684
|
+
function parseVaultFile(raw) {
|
|
70685
|
+
let value;
|
|
70686
|
+
try {
|
|
70687
|
+
value = JSON.parse(raw);
|
|
70688
|
+
} catch (error61) {
|
|
70689
|
+
throw new VaultError("corrupt", "The vault file is not valid JSON.", { cause: error61 });
|
|
70690
|
+
}
|
|
70691
|
+
const parsed = vaultFileSchema.safeParse(value);
|
|
70692
|
+
if (!parsed.success) {
|
|
70693
|
+
throw new VaultError("corrupt", "The vault file has an invalid structure.", {
|
|
70694
|
+
cause: parsed.error
|
|
70695
|
+
});
|
|
70696
|
+
}
|
|
70697
|
+
if (parsed.data.protected !== (parsed.data.wrappedKey !== void 0)) {
|
|
70698
|
+
throw new VaultError("corrupt", "The vault protection metadata is inconsistent.");
|
|
70699
|
+
}
|
|
70700
|
+
const names = /* @__PURE__ */ new Set();
|
|
70701
|
+
const indexes = /* @__PURE__ */ new Set();
|
|
70702
|
+
for (const account of parsed.data.accounts) {
|
|
70703
|
+
if (names.has(account.name)) {
|
|
70704
|
+
throw new VaultError("corrupt", "The vault file contains duplicate account names.");
|
|
70705
|
+
}
|
|
70706
|
+
names.add(account.name);
|
|
70707
|
+
if (account.kind === "derived") {
|
|
70708
|
+
if (indexes.has(account.index)) {
|
|
70709
|
+
throw new VaultError("corrupt", "The vault file contains duplicate derived indexes.");
|
|
70710
|
+
}
|
|
70711
|
+
indexes.add(account.index);
|
|
70712
|
+
}
|
|
70713
|
+
}
|
|
70714
|
+
return parsed.data;
|
|
70715
|
+
}
|
|
70716
|
+
async function readVaultFile(path, key2) {
|
|
70717
|
+
const file2 = await readVaultFileUnlocked(path);
|
|
70718
|
+
const plaintext = decryptPhraseForOpen(key2, file2.phrase);
|
|
70719
|
+
try {
|
|
70720
|
+
try {
|
|
70721
|
+
validateRecoveryPhrase(plaintext.toString("utf8"));
|
|
70722
|
+
} catch (error61) {
|
|
70723
|
+
throw new VaultError("corrupt", "The vault recovery phrase is not valid.", {
|
|
70724
|
+
cause: error61
|
|
70725
|
+
});
|
|
70726
|
+
}
|
|
70727
|
+
} finally {
|
|
70728
|
+
plaintext.fill(0);
|
|
70729
|
+
}
|
|
70730
|
+
return file2;
|
|
70731
|
+
}
|
|
70732
|
+
async function readVaultFileUnlocked(path) {
|
|
70733
|
+
let raw;
|
|
70734
|
+
try {
|
|
70735
|
+
raw = await readFile7(path, "utf8");
|
|
70736
|
+
} catch (error61) {
|
|
70737
|
+
if (isMissingFile2(error61)) {
|
|
70738
|
+
throw new VaultError("not_found", "No vault file was found at the requested path.", {
|
|
70739
|
+
cause: error61
|
|
70740
|
+
});
|
|
70741
|
+
}
|
|
70742
|
+
throw new VaultError("corrupt", "Unable to read the vault file.", { cause: error61 });
|
|
70743
|
+
}
|
|
70744
|
+
return parseVaultFile(raw);
|
|
70745
|
+
}
|
|
70746
|
+
async function refuseExistingVault(path) {
|
|
70747
|
+
try {
|
|
70748
|
+
await stat6(path);
|
|
70749
|
+
} catch (error61) {
|
|
70750
|
+
if (isMissingFile2(error61)) return;
|
|
70751
|
+
throw new VaultError("corrupt", "Unable to check whether the vault already exists.", {
|
|
70752
|
+
cause: error61
|
|
70753
|
+
});
|
|
70754
|
+
}
|
|
70755
|
+
throw new VaultError("corrupt", "A vault already exists at the requested path.");
|
|
70756
|
+
}
|
|
70757
|
+
async function writeVaultFile(path, file2) {
|
|
70758
|
+
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70759
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes5(6).toString("hex")}.tmp`;
|
|
70760
|
+
try {
|
|
70761
|
+
await writeFile3(temporaryPath, `${JSON.stringify(file2, null, 2)}
|
|
70762
|
+
`, {
|
|
70763
|
+
encoding: "utf8",
|
|
70764
|
+
mode: 384,
|
|
70765
|
+
flag: "wx"
|
|
70766
|
+
});
|
|
70767
|
+
await rename4(temporaryPath, path);
|
|
70768
|
+
} catch (error61) {
|
|
70769
|
+
await rm(temporaryPath, { force: true }).catch(() => void 0);
|
|
70770
|
+
throw error61;
|
|
70771
|
+
}
|
|
70772
|
+
}
|
|
70773
|
+
async function withVaultLock(path, operation) {
|
|
70774
|
+
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70775
|
+
const lockPath = `${path}.lock`;
|
|
70776
|
+
const deadline = Date.now() + VAULT_LOCK_TIMEOUT_MS;
|
|
70777
|
+
let handle;
|
|
70778
|
+
while (!handle) {
|
|
70779
|
+
try {
|
|
70780
|
+
handle = await open5(lockPath, "wx", 384);
|
|
70781
|
+
} catch (error61) {
|
|
70782
|
+
if (!isExistingFile(error61)) throw error61;
|
|
70783
|
+
await removeStaleVaultLock(lockPath);
|
|
70784
|
+
if (Date.now() >= deadline) {
|
|
70785
|
+
throw new VaultError("corrupt", "Timed out waiting for the vault lock.");
|
|
70786
|
+
}
|
|
70787
|
+
await new Promise((resolve3) => setTimeout(resolve3, 20));
|
|
70788
|
+
}
|
|
70789
|
+
}
|
|
70790
|
+
try {
|
|
70791
|
+
return await operation();
|
|
70792
|
+
} finally {
|
|
70793
|
+
await handle.close();
|
|
70794
|
+
await unlink4(lockPath).catch(() => void 0);
|
|
70795
|
+
}
|
|
70796
|
+
}
|
|
70797
|
+
async function removeStaleVaultLock(path) {
|
|
70798
|
+
try {
|
|
70799
|
+
const metadata = await stat6(path);
|
|
70800
|
+
if (Date.now() - metadata.mtimeMs > STALE_VAULT_LOCK_MS) await unlink4(path);
|
|
70801
|
+
} catch (error61) {
|
|
70802
|
+
if (!isMissingFile2(error61)) throw error61;
|
|
70803
|
+
}
|
|
70804
|
+
}
|
|
70805
|
+
function isMissingFile2(error61) {
|
|
70806
|
+
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "ENOENT";
|
|
70807
|
+
}
|
|
70808
|
+
function isExistingFile(error61) {
|
|
70809
|
+
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "EEXIST";
|
|
70810
|
+
}
|
|
70811
|
+
function asVaultError(error61, code, message) {
|
|
70812
|
+
return error61 instanceof VaultError ? error61 : new VaultError(code, message, { cause: error61 });
|
|
70813
|
+
}
|
|
70814
|
+
|
|
70815
|
+
// ../core/src/file-secret-store.ts
|
|
70816
|
+
var FILE_SECRET_STORE_PASSWORD_ENV = "VAPI_VAULT_PASSWORD";
|
|
70817
|
+
var FILE_SECRET_STORE_MIN_PASSWORD = 12;
|
|
70818
|
+
var CHECK_VALUE = "vapi-network file secret store";
|
|
70819
|
+
var sealedSchema = external_exports.object({ nonce: external_exports.string(), ciphertext: external_exports.string(), tag: external_exports.string() }).strict();
|
|
70820
|
+
var fileSchema = external_exports.object({
|
|
70821
|
+
v: external_exports.literal(1),
|
|
70822
|
+
salt: external_exports.string(),
|
|
70823
|
+
check: sealedSchema,
|
|
70824
|
+
entries: external_exports.record(external_exports.string(), sealedSchema)
|
|
70825
|
+
}).strict();
|
|
70826
|
+
async function createFileSecretStore(options) {
|
|
70827
|
+
const password = passwordFrom(options.env);
|
|
70828
|
+
if (password.length < FILE_SECRET_STORE_MIN_PASSWORD) {
|
|
70829
|
+
throw new KeystoreError(
|
|
70830
|
+
`${FILE_SECRET_STORE_PASSWORD_ENV} must be at least ${FILE_SECRET_STORE_MIN_PASSWORD} characters.`
|
|
70831
|
+
);
|
|
70832
|
+
}
|
|
70833
|
+
await withVaultLock(options.path, async () => {
|
|
70834
|
+
let exists = true;
|
|
70835
|
+
try {
|
|
70836
|
+
await stat7(options.path);
|
|
70837
|
+
} catch (error61) {
|
|
70838
|
+
if (!isMissingFile(error61)) throw error61;
|
|
70839
|
+
exists = false;
|
|
70840
|
+
}
|
|
70841
|
+
if (exists) {
|
|
70842
|
+
await withKey(options.path, options.env, async () => void 0);
|
|
70843
|
+
return;
|
|
70844
|
+
}
|
|
70845
|
+
const salt = randomBytes6(32);
|
|
70846
|
+
const key2 = await deriveScryptKey(password, salt);
|
|
70847
|
+
try {
|
|
70848
|
+
await writeJsonAtomic(
|
|
70849
|
+
options.path,
|
|
70850
|
+
{
|
|
70851
|
+
v: 1,
|
|
70852
|
+
salt: salt.toString("base64"),
|
|
70853
|
+
check: seal(key2, CHECK_VALUE),
|
|
70854
|
+
entries: {}
|
|
70855
|
+
},
|
|
70856
|
+
{ mode: 384 }
|
|
70857
|
+
);
|
|
70858
|
+
} finally {
|
|
70859
|
+
key2.fill(0);
|
|
70860
|
+
}
|
|
70861
|
+
});
|
|
70862
|
+
}
|
|
70863
|
+
function fileSecretStore(options) {
|
|
70864
|
+
const env = options.env ?? process.env;
|
|
70865
|
+
const write2 = async (change) => await withVaultLock(
|
|
70866
|
+
options.path,
|
|
70867
|
+
async () => await withKey(options.path, env, async (file2, key2) => {
|
|
70868
|
+
const changed = change(file2, key2);
|
|
70869
|
+
if (changed) await writeJsonAtomic(options.path, file2, { mode: 384 });
|
|
70870
|
+
return changed;
|
|
70871
|
+
})
|
|
70872
|
+
);
|
|
70873
|
+
const get = async (name) => await withKey(options.path, env, async (file2, key2) => {
|
|
70874
|
+
const sealed = Object.hasOwn(file2.entries, name) ? file2.entries[name] : void 0;
|
|
70875
|
+
return sealed === void 0 ? void 0 : open6(key2, sealed);
|
|
70876
|
+
});
|
|
70877
|
+
return {
|
|
70878
|
+
// A locked backend still exists; it must never enable a plaintext fallback.
|
|
70879
|
+
available: true,
|
|
70880
|
+
platform: process.platform,
|
|
70881
|
+
description: "the encrypted vAPI secrets file",
|
|
70882
|
+
get,
|
|
70883
|
+
async has(name) {
|
|
70884
|
+
return await get(name) !== void 0;
|
|
70885
|
+
},
|
|
70886
|
+
async set(name, value) {
|
|
70887
|
+
if (name === "__proto__") {
|
|
70888
|
+
throw new KeystoreError("The secret name is reserved in the encrypted vAPI secrets file.");
|
|
70889
|
+
}
|
|
70890
|
+
await write2((file2, key2) => {
|
|
70891
|
+
file2.entries[name] = seal(key2, value);
|
|
70892
|
+
return true;
|
|
70893
|
+
});
|
|
70894
|
+
},
|
|
70895
|
+
async remove(name) {
|
|
70896
|
+
return await write2((file2) => {
|
|
70897
|
+
if (!Object.hasOwn(file2.entries, name)) return false;
|
|
70898
|
+
delete file2.entries[name];
|
|
70899
|
+
return true;
|
|
70900
|
+
});
|
|
70901
|
+
}
|
|
70902
|
+
};
|
|
70903
|
+
}
|
|
70904
|
+
async function withKey(path, env, operation) {
|
|
70905
|
+
const file2 = await readStoredFile(path);
|
|
70906
|
+
const key2 = await deriveScryptKey(passwordFrom(env), Buffer.from(file2.salt, "base64"));
|
|
70907
|
+
try {
|
|
70908
|
+
if (open6(key2, file2.check) !== CHECK_VALUE) throw wrongPassword();
|
|
70909
|
+
return await operation(file2, key2);
|
|
70910
|
+
} finally {
|
|
70911
|
+
key2.fill(0);
|
|
70912
|
+
}
|
|
70913
|
+
}
|
|
70914
|
+
function passwordFrom(env) {
|
|
70915
|
+
const password = (env ?? process.env)[FILE_SECRET_STORE_PASSWORD_ENV];
|
|
70916
|
+
if (!password) {
|
|
70917
|
+
throw new KeystoreError(
|
|
70918
|
+
`This vault keeps its secrets in an encrypted file. Set ${FILE_SECRET_STORE_PASSWORD_ENV} to open it.`
|
|
70919
|
+
);
|
|
70920
|
+
}
|
|
70921
|
+
return password;
|
|
70922
|
+
}
|
|
70923
|
+
async function readStoredFile(path) {
|
|
70924
|
+
let raw;
|
|
70925
|
+
try {
|
|
70926
|
+
raw = await readFile8(path, "utf8");
|
|
70927
|
+
} catch (error61) {
|
|
70928
|
+
throw new KeystoreError("The vAPI secrets file is missing. Run vapi setup again.", {
|
|
70929
|
+
cause: error61
|
|
70930
|
+
});
|
|
70931
|
+
}
|
|
70932
|
+
let value;
|
|
70933
|
+
try {
|
|
70934
|
+
value = JSON.parse(raw);
|
|
70935
|
+
} catch {
|
|
70936
|
+
throw new KeystoreError("The vAPI secrets file is damaged.");
|
|
70937
|
+
}
|
|
70938
|
+
const parsed = fileSchema.safeParse(value);
|
|
70939
|
+
if (!parsed.success) throw new KeystoreError("The vAPI secrets file is damaged.");
|
|
70940
|
+
return parsed.data;
|
|
70941
|
+
}
|
|
70942
|
+
function seal(key2, value) {
|
|
70943
|
+
const { nonce, ciphertext, tag } = encryptWithKey(key2, Buffer.from(value, "utf8"));
|
|
70944
|
+
return {
|
|
70945
|
+
nonce: nonce.toString("base64"),
|
|
70946
|
+
ciphertext: ciphertext.toString("base64"),
|
|
70947
|
+
tag: tag.toString("base64")
|
|
70948
|
+
};
|
|
70949
|
+
}
|
|
70950
|
+
function open6(key2, sealed) {
|
|
70951
|
+
try {
|
|
70952
|
+
return decryptWithKey(key2, {
|
|
70953
|
+
nonce: Buffer.from(sealed.nonce, "base64"),
|
|
70954
|
+
ciphertext: Buffer.from(sealed.ciphertext, "base64"),
|
|
70955
|
+
tag: Buffer.from(sealed.tag, "base64")
|
|
70956
|
+
}).toString("utf8");
|
|
70957
|
+
} catch (error61) {
|
|
70958
|
+
throw wrongPassword(error61);
|
|
70959
|
+
}
|
|
70960
|
+
}
|
|
70961
|
+
function wrongPassword(cause) {
|
|
70962
|
+
return new KeystoreError(`Wrong ${FILE_SECRET_STORE_PASSWORD_ENV} for the vAPI secrets file.`, {
|
|
70963
|
+
cause
|
|
70964
|
+
});
|
|
70965
|
+
}
|
|
70966
|
+
|
|
70967
|
+
// ../core/src/secret-backend.ts
|
|
70968
|
+
import { readFileSync } from "node:fs";
|
|
70969
|
+
import { stat as stat8 } from "node:fs/promises";
|
|
70970
|
+
import { join as join6 } from "node:path";
|
|
70971
|
+
var PROBE_ACCOUNT = "setup-probe";
|
|
70972
|
+
var pinSchema = external_exports.object({ v: external_exports.literal(1), backend: external_exports.enum(["os", "file"]) }).strict();
|
|
70973
|
+
function secretBackendPath(home = getVapiPaths().directory) {
|
|
70974
|
+
return join6(home, "secret-store.json");
|
|
70975
|
+
}
|
|
70976
|
+
function secretsFilePath(home = getVapiPaths().directory) {
|
|
70977
|
+
return join6(home, "secrets.json");
|
|
70978
|
+
}
|
|
70979
|
+
function readSecretBackend(home = getVapiPaths().directory) {
|
|
70980
|
+
const path = secretBackendPath(home);
|
|
70981
|
+
try {
|
|
70982
|
+
const parsed = pinSchema.safeParse(JSON.parse(readFileSync(path, "utf8")));
|
|
70983
|
+
if (parsed.success) return parsed.data.backend;
|
|
70984
|
+
} catch (error61) {
|
|
70985
|
+
if (isMissingFile(error61)) return "os";
|
|
70986
|
+
}
|
|
70987
|
+
throw new KeystoreError(`The vAPI secret-store pin at ${path} is damaged.`);
|
|
70988
|
+
}
|
|
70989
|
+
async function chooseSecretBackend(options) {
|
|
70990
|
+
const env = options.env ?? process.env;
|
|
70991
|
+
const osWorks = options.os.platform !== "linux" || await osStoreWorks(options.os);
|
|
70992
|
+
const path = secretBackendPath(options.home);
|
|
70993
|
+
return await withVaultLock(path, async () => {
|
|
70994
|
+
if (await fileExists(path)) return readSecretBackend(options.home);
|
|
70995
|
+
if (await fileExists(join6(options.home, "vault.json"))) return "os";
|
|
70996
|
+
let backend;
|
|
70997
|
+
if (osWorks) {
|
|
70998
|
+
backend = "os";
|
|
70999
|
+
} else if (env[FILE_SECRET_STORE_PASSWORD_ENV]) {
|
|
71000
|
+
await createFileSecretStore({ path: secretsFilePath(options.home), env });
|
|
71001
|
+
backend = "file";
|
|
71002
|
+
} else {
|
|
71003
|
+
throw new KeystoreError(
|
|
71004
|
+
[
|
|
71005
|
+
`This machine has no working keyring (${options.os.description}).`,
|
|
71006
|
+
`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,`,
|
|
71007
|
+
"or run vapi on your own computer, or connect Claude from https://api.vapinetwork.ai/connect."
|
|
71008
|
+
].join(" ")
|
|
71009
|
+
);
|
|
71010
|
+
}
|
|
71011
|
+
await writeJsonAtomic(path, { v: 1, backend }, { mode: 384 });
|
|
71012
|
+
return backend;
|
|
71013
|
+
});
|
|
71014
|
+
}
|
|
71015
|
+
async function fileExists(path) {
|
|
71016
|
+
try {
|
|
71017
|
+
await stat8(path);
|
|
71018
|
+
return true;
|
|
71019
|
+
} catch (error61) {
|
|
71020
|
+
if (isMissingFile(error61)) return false;
|
|
71021
|
+
throw error61;
|
|
71022
|
+
}
|
|
71023
|
+
}
|
|
71024
|
+
async function osStoreWorks(store) {
|
|
71025
|
+
if (!store.available) return false;
|
|
71026
|
+
try {
|
|
71027
|
+
try {
|
|
71028
|
+
await store.set(PROBE_ACCOUNT, "ok");
|
|
71029
|
+
return await store.get(PROBE_ACCOUNT) === "ok";
|
|
71030
|
+
} finally {
|
|
71031
|
+
await store.remove(PROBE_ACCOUNT);
|
|
71032
|
+
}
|
|
71033
|
+
} catch {
|
|
71034
|
+
return false;
|
|
71035
|
+
}
|
|
71036
|
+
}
|
|
71037
|
+
|
|
71038
|
+
// ../core/src/secret-store.ts
|
|
71039
|
+
var SECRET_STORE_SERVICE = "vapi-network";
|
|
71040
|
+
var SECURITY_BINARY = "/usr/bin/security";
|
|
71041
|
+
var SECRET_TOOL_BINARY = "secret-tool";
|
|
71042
|
+
var WINDOWS_POWERSHELL_ARGS = ["-NoProfile", "-NonInteractive", "-Command", "-"];
|
|
71043
|
+
var SECURITY_ITEM_NOT_FOUND = 44;
|
|
71044
|
+
var WINDOWS_SECRET_SUCCESS = 0;
|
|
71045
|
+
var WINDOWS_SECRET_NOT_FOUND = 2;
|
|
71046
|
+
var UNSUPPORTED_PLATFORM = "No OS secret store on this platform yet; use VAPI_KEYSTORE_PASSWORD.";
|
|
71047
|
+
var SECRET_TOOL_MISSING = [
|
|
71048
|
+
"secret-tool is not installed, so the passphrase cannot be kept in the OS secret store.",
|
|
71049
|
+
"Install libsecret-tools (Debian, Ubuntu) or libsecret (Fedora, Arch), or use VAPI_KEYSTORE_PASSWORD."
|
|
71050
|
+
].join(" ");
|
|
71051
|
+
var POWERSHELL_MISSING = [
|
|
71052
|
+
"Windows PowerShell (powershell.exe) was not found, so the passphrase cannot be kept in the OS secret store.",
|
|
71053
|
+
"Use VAPI_KEYSTORE_PASSWORD."
|
|
71054
|
+
].join(" ");
|
|
71055
|
+
function secretStore(options = {}) {
|
|
71056
|
+
const home = options.home ?? getVapiPaths().directory;
|
|
71057
|
+
if (readSecretBackend(home) === "file") {
|
|
71058
|
+
return fileSecretStore({ path: secretsFilePath(home), env: options.env ?? process.env });
|
|
71059
|
+
}
|
|
71060
|
+
return osSecretStore(options);
|
|
71061
|
+
}
|
|
71062
|
+
function osSecretStore(options = {}) {
|
|
71063
|
+
const platform2 = options.platform ?? process.platform;
|
|
71064
|
+
const run = options.run ?? (async (file2, args, input2) => await spawnRunner(platform2, file2, args, input2));
|
|
71065
|
+
const env = options.env ?? process.env;
|
|
71066
|
+
const installed = options.installed ?? ((file2) => binaryInstalled(file2, env));
|
|
71067
|
+
if (platform2 === "darwin") return keychainStore(platform2, run);
|
|
71068
|
+
if (platform2 === "win32") return windowsDataProtectionStore(platform2, run, env, installed);
|
|
71069
|
+
if (platform2 === "linux") return libsecretStore(platform2, run, installed);
|
|
71070
|
+
return unsupportedStore(platform2);
|
|
71071
|
+
}
|
|
71072
|
+
function memorySecretStore(initial = {}) {
|
|
71073
|
+
const entries = new Map(Object.entries(initial));
|
|
71074
|
+
return {
|
|
71075
|
+
available: true,
|
|
71076
|
+
platform: process.platform,
|
|
71077
|
+
description: "an in-memory store",
|
|
71078
|
+
async get(name) {
|
|
71079
|
+
return entries.get(name);
|
|
71080
|
+
},
|
|
71081
|
+
async has(name) {
|
|
71082
|
+
return entries.has(name);
|
|
71083
|
+
},
|
|
71084
|
+
async set(name, passphrase) {
|
|
71085
|
+
entries.set(name, passphrase);
|
|
71086
|
+
},
|
|
71087
|
+
async remove(name) {
|
|
71088
|
+
return entries.delete(name);
|
|
71089
|
+
},
|
|
71090
|
+
async list() {
|
|
71091
|
+
return [...entries.keys()].sort();
|
|
71092
|
+
}
|
|
71093
|
+
};
|
|
71094
|
+
}
|
|
71095
|
+
function keychainStore(platform2, run) {
|
|
71096
|
+
const find = async (account, withPassword) => await run(SECURITY_BINARY, [
|
|
71097
|
+
"find-generic-password",
|
|
71098
|
+
"-a",
|
|
71099
|
+
account,
|
|
71100
|
+
"-s",
|
|
71101
|
+
SECRET_STORE_SERVICE,
|
|
71102
|
+
...withPassword ? ["-w"] : []
|
|
71103
|
+
]);
|
|
71104
|
+
const read = async (account, what) => {
|
|
71105
|
+
const result = await find(account, true);
|
|
71106
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return void 0;
|
|
71107
|
+
requireSuccess(result, what);
|
|
71108
|
+
const value = withoutTrailingNewline(result.stdout);
|
|
71109
|
+
return value.length === 0 ? void 0 : value;
|
|
71110
|
+
};
|
|
71111
|
+
const write2 = async (account, value, what) => {
|
|
71112
|
+
const result = await run(
|
|
71113
|
+
SECURITY_BINARY,
|
|
71114
|
+
[
|
|
71115
|
+
"add-generic-password",
|
|
71116
|
+
"-a",
|
|
71117
|
+
account,
|
|
71118
|
+
"-s",
|
|
71119
|
+
SECRET_STORE_SERVICE,
|
|
71120
|
+
"-l",
|
|
71121
|
+
`${SECRET_STORE_SERVICE} ${account}`,
|
|
71122
|
+
"-U",
|
|
71123
|
+
"-w"
|
|
71124
|
+
],
|
|
71125
|
+
// `security` asks for the password and then for its confirmation.
|
|
71126
|
+
`${value}
|
|
71127
|
+
${value}
|
|
71128
|
+
`
|
|
71129
|
+
);
|
|
71130
|
+
requireSuccess(result, what);
|
|
71131
|
+
};
|
|
71132
|
+
const erase = async (account, what) => {
|
|
71133
|
+
const result = await run(SECURITY_BINARY, [
|
|
71134
|
+
"delete-generic-password",
|
|
71135
|
+
"-a",
|
|
71136
|
+
account,
|
|
71137
|
+
"-s",
|
|
71138
|
+
SECRET_STORE_SERVICE
|
|
71139
|
+
]);
|
|
71140
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71141
|
+
requireSuccess(result, what);
|
|
71142
|
+
return true;
|
|
71143
|
+
};
|
|
71144
|
+
const erasePartsAfter = async (account, keep, what) => {
|
|
71145
|
+
for (let part = keep + 1; part <= MAX_KEYCHAIN_PARTS; part += 1) {
|
|
71146
|
+
if (!await erase(keychainPart(account, part), what)) return;
|
|
71147
|
+
}
|
|
71148
|
+
};
|
|
71149
|
+
return {
|
|
71150
|
+
available: true,
|
|
71151
|
+
platform: platform2,
|
|
71152
|
+
description: "the macOS Keychain",
|
|
71153
|
+
async get(name) {
|
|
71154
|
+
const account = accountFor(name);
|
|
71155
|
+
const what = `read the passphrase of ${name} from the macOS Keychain`;
|
|
71156
|
+
const value = await read(account, what);
|
|
71157
|
+
const parts = value === void 0 ? void 0 : chunkedPartCount(value);
|
|
71158
|
+
if (value === void 0 || parts === void 0) return value;
|
|
71159
|
+
let joined = "";
|
|
71160
|
+
for (let part = 1; part <= parts; part += 1) {
|
|
71161
|
+
const chunk = await read(keychainPart(account, part), what);
|
|
71162
|
+
if (chunk === void 0) {
|
|
71163
|
+
throw new KeystoreError(
|
|
71164
|
+
`The stored secret ${name} is incomplete in the macOS Keychain. Store it again.`
|
|
71165
|
+
);
|
|
71166
|
+
}
|
|
71167
|
+
joined += chunk;
|
|
71168
|
+
}
|
|
71169
|
+
return joined;
|
|
71170
|
+
},
|
|
71171
|
+
async has(name) {
|
|
71172
|
+
const result = await find(accountFor(name), false);
|
|
71173
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71174
|
+
requireSuccess(result, `look up ${name} in the macOS Keychain`);
|
|
71175
|
+
return true;
|
|
71176
|
+
},
|
|
71177
|
+
async set(name, passphrase) {
|
|
71178
|
+
requirePassphrase(passphrase);
|
|
71179
|
+
const account = accountFor(name);
|
|
71180
|
+
const what = `store the passphrase of ${name} in the macOS Keychain`;
|
|
71181
|
+
if (passphrase.length <= KEYCHAIN_PROMPT_LIMIT) {
|
|
71182
|
+
await write2(account, passphrase, what);
|
|
71183
|
+
return;
|
|
71184
|
+
}
|
|
71185
|
+
const chunks = [];
|
|
71186
|
+
for (let index2 = 0; index2 < passphrase.length; index2 += KEYCHAIN_CHUNK) {
|
|
71187
|
+
chunks.push(passphrase.slice(index2, index2 + KEYCHAIN_CHUNK));
|
|
71188
|
+
}
|
|
71189
|
+
if (chunks.length > MAX_KEYCHAIN_PARTS) {
|
|
71190
|
+
throw new KeystoreError(`The secret ${name} is too long for the macOS Keychain.`);
|
|
71191
|
+
}
|
|
71192
|
+
for (const [index2, chunk] of chunks.entries()) {
|
|
71193
|
+
await write2(keychainPart(account, index2 + 1), chunk, what);
|
|
71194
|
+
}
|
|
71195
|
+
await erasePartsAfter(account, chunks.length, what);
|
|
71196
|
+
await write2(account, `${CHUNKED_MARKER}${chunks.length}`, what);
|
|
71197
|
+
},
|
|
71198
|
+
async remove(name) {
|
|
71199
|
+
const account = accountFor(name);
|
|
71200
|
+
const what = `remove the passphrase of ${name} from the macOS Keychain`;
|
|
71201
|
+
const found = await find(account, true);
|
|
71202
|
+
if (found.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71203
|
+
requireSuccess(found, what);
|
|
71204
|
+
if (chunkedPartCount(withoutTrailingNewline(found.stdout)) !== void 0) {
|
|
71205
|
+
await erasePartsAfter(account, 0, what);
|
|
71206
|
+
}
|
|
71207
|
+
return await erase(account, what);
|
|
71208
|
+
}
|
|
71209
|
+
};
|
|
71210
|
+
}
|
|
71211
|
+
var KEYCHAIN_PROMPT_LIMIT = 128;
|
|
71212
|
+
var KEYCHAIN_CHUNK = 120;
|
|
71213
|
+
var MAX_KEYCHAIN_PARTS = 32;
|
|
71214
|
+
var CHUNKED_MARKER = "vapi-chunked:v1:";
|
|
71215
|
+
function keychainPart(account, part) {
|
|
71216
|
+
return `${account}#${part}`;
|
|
71217
|
+
}
|
|
71218
|
+
function chunkedPartCount(value) {
|
|
71219
|
+
if (!value.startsWith(CHUNKED_MARKER)) return void 0;
|
|
71220
|
+
const parts = Number(value.slice(CHUNKED_MARKER.length));
|
|
71221
|
+
return Number.isInteger(parts) && parts > 0 && parts <= MAX_KEYCHAIN_PARTS ? parts : void 0;
|
|
71222
|
+
}
|
|
71223
|
+
function windowsSecretFileName(account) {
|
|
71224
|
+
let encoded = "";
|
|
71225
|
+
for (let index2 = 0; index2 < account.length; index2 += 1) {
|
|
71226
|
+
const character = account[index2];
|
|
71227
|
+
if (/^[a-z0-9._#-]$/u.test(character)) {
|
|
71228
|
+
encoded += character;
|
|
71229
|
+
continue;
|
|
71230
|
+
}
|
|
71231
|
+
encoded += `%${account.charCodeAt(index2).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
71232
|
+
}
|
|
71233
|
+
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu.test(encoded)) {
|
|
71234
|
+
encoded = `%${encoded.charCodeAt(0).toString(16).toUpperCase()}${encoded.slice(1)}`;
|
|
71235
|
+
}
|
|
71236
|
+
return `${encoded}.bin`;
|
|
71237
|
+
}
|
|
71238
|
+
function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
71239
|
+
const powershell = `${env.SystemRoot ?? "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
71240
|
+
const fileDetails = (name) => {
|
|
71241
|
+
const file2 = windowsSecretFileName(accountFor(name));
|
|
71242
|
+
return { file: file2, account: file2.slice(0, -".bin".length) };
|
|
71243
|
+
};
|
|
71244
|
+
const script = (file2, operations) => [
|
|
71245
|
+
"$ErrorActionPreference = 'Stop'",
|
|
71246
|
+
"try {",
|
|
71247
|
+
" Add-Type -AssemblyName System.Security",
|
|
71248
|
+
" $dir = Join-Path $env:LOCALAPPDATA 'vapi-network\\secrets'",
|
|
71249
|
+
` $path = Join-Path $dir '${file2}'`,
|
|
71250
|
+
...operations.map((operation) => ` ${operation}`),
|
|
71251
|
+
"} catch {",
|
|
71252
|
+
" [Console]::Error.WriteLine($_.Exception.Message)",
|
|
71253
|
+
" exit 1",
|
|
71254
|
+
"}"
|
|
71255
|
+
].join("\n");
|
|
71256
|
+
const execute = async (script2) => {
|
|
71257
|
+
const result = await run(powershell, WINDOWS_POWERSHELL_ARGS, `${script2}
|
|
71258
|
+
|
|
71259
|
+
`);
|
|
71260
|
+
requirePowerShell(result);
|
|
71261
|
+
return result;
|
|
71262
|
+
};
|
|
71263
|
+
return {
|
|
71264
|
+
available: installed(powershell),
|
|
71265
|
+
platform: platform2,
|
|
71266
|
+
description: "Windows Data Protection (DPAPI)",
|
|
71267
|
+
async get(name) {
|
|
71268
|
+
const { file: file2, account } = fileDetails(name);
|
|
71269
|
+
const result = await execute(
|
|
71270
|
+
script(file2, [
|
|
71271
|
+
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
71272
|
+
"$blob = [System.IO.File]::ReadAllBytes($path)",
|
|
71273
|
+
"$bytes = [System.Security.Cryptography.ProtectedData]::Unprotect($blob, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
71274
|
+
"[Console]::Out.Write([Convert]::ToBase64String($bytes))",
|
|
71275
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71276
|
+
])
|
|
71277
|
+
);
|
|
71278
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return void 0;
|
|
71279
|
+
requireSuccess(result, `read the passphrase of ${name} from Windows Data Protection`);
|
|
71280
|
+
const value = Buffer.from(result.stdout.trim(), "base64").toString("utf8");
|
|
71281
|
+
return value.length === 0 ? void 0 : value;
|
|
71282
|
+
},
|
|
71283
|
+
async has(name) {
|
|
71284
|
+
const { file: file2, account } = fileDetails(name);
|
|
71285
|
+
const result = await execute(
|
|
71286
|
+
script(file2, [
|
|
71287
|
+
`if (Test-Path -LiteralPath $path) { exit ${WINDOWS_SECRET_SUCCESS} }`,
|
|
71288
|
+
`[Console]::Error.WriteLine('No stored secret for ${account}.')`,
|
|
71289
|
+
`exit ${WINDOWS_SECRET_NOT_FOUND}`
|
|
71290
|
+
])
|
|
71291
|
+
);
|
|
71292
|
+
if (result.code === WINDOWS_SECRET_SUCCESS) return true;
|
|
71293
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
71294
|
+
requireSuccess(result, `look up ${name} in Windows Data Protection`);
|
|
71295
|
+
return false;
|
|
71296
|
+
},
|
|
71297
|
+
async set(name, passphrase) {
|
|
71298
|
+
requirePassphrase(passphrase);
|
|
71299
|
+
const { file: file2 } = fileDetails(name);
|
|
71300
|
+
const value = Buffer.from(passphrase, "utf8").toString("base64");
|
|
71301
|
+
const result = await execute(
|
|
71302
|
+
script(file2, [
|
|
71303
|
+
"[void][System.IO.Directory]::CreateDirectory($dir)",
|
|
71304
|
+
`$bytes = [Convert]::FromBase64String('${value}')`,
|
|
71305
|
+
"$blob = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
71306
|
+
"[System.IO.File]::WriteAllBytes($path, $blob)",
|
|
71307
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71308
|
+
])
|
|
71309
|
+
);
|
|
71310
|
+
requireSuccess(result, `store the passphrase of ${name} in Windows Data Protection`);
|
|
71311
|
+
},
|
|
71312
|
+
async remove(name) {
|
|
71313
|
+
const { file: file2, account } = fileDetails(name);
|
|
71314
|
+
const result = await execute(
|
|
71315
|
+
script(file2, [
|
|
71316
|
+
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
71317
|
+
"Remove-Item -LiteralPath $path -Force",
|
|
71318
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71319
|
+
])
|
|
71320
|
+
);
|
|
71321
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
71322
|
+
requireSuccess(result, `remove the passphrase of ${name} from Windows Data Protection`);
|
|
71323
|
+
return true;
|
|
71324
|
+
}
|
|
71325
|
+
};
|
|
71326
|
+
}
|
|
71327
|
+
function libsecretStore(platform2, run, installed) {
|
|
71328
|
+
const lookup2 = async (name) => {
|
|
71329
|
+
const result = await run(SECRET_TOOL_BINARY, [
|
|
71330
|
+
"lookup",
|
|
71331
|
+
"service",
|
|
71332
|
+
SECRET_STORE_SERVICE,
|
|
71333
|
+
"account",
|
|
71334
|
+
accountFor(name)
|
|
71335
|
+
]);
|
|
71336
|
+
requireBinary(result);
|
|
71337
|
+
const value = withoutTrailingNewline(result.stdout);
|
|
71338
|
+
if (result.code === 0) return value.length === 0 ? void 0 : value;
|
|
71339
|
+
if (result.stderr.trim().length === 0) return void 0;
|
|
71340
|
+
requireSuccess(result, `read the passphrase of ${name} from the secret service`);
|
|
71341
|
+
return void 0;
|
|
71342
|
+
};
|
|
71343
|
+
return {
|
|
71344
|
+
available: installed(SECRET_TOOL_BINARY),
|
|
71345
|
+
platform: platform2,
|
|
71346
|
+
description: "the libsecret keyring",
|
|
71347
|
+
get: lookup2,
|
|
71348
|
+
async has(name) {
|
|
71349
|
+
return await lookup2(name) !== void 0;
|
|
71350
|
+
},
|
|
71351
|
+
async set(name, passphrase) {
|
|
71352
|
+
requirePassphrase(passphrase);
|
|
71353
|
+
const account = accountFor(name);
|
|
71354
|
+
const result = await run(
|
|
71355
|
+
SECRET_TOOL_BINARY,
|
|
71356
|
+
[
|
|
71357
|
+
"store",
|
|
71358
|
+
`--label=${SECRET_STORE_SERVICE} ${account}`,
|
|
71359
|
+
"service",
|
|
71360
|
+
SECRET_STORE_SERVICE,
|
|
71361
|
+
"account",
|
|
71362
|
+
account
|
|
71363
|
+
],
|
|
71364
|
+
`${passphrase}
|
|
71365
|
+
`
|
|
71366
|
+
);
|
|
71367
|
+
requireBinary(result);
|
|
71368
|
+
requireSuccess(result, `store the passphrase of ${name} in the secret service`);
|
|
71369
|
+
},
|
|
71370
|
+
async remove(name) {
|
|
71371
|
+
const existed = await lookup2(name) !== void 0;
|
|
71372
|
+
const result = await run(SECRET_TOOL_BINARY, [
|
|
71373
|
+
"clear",
|
|
71374
|
+
"service",
|
|
71375
|
+
SECRET_STORE_SERVICE,
|
|
71376
|
+
"account",
|
|
71377
|
+
accountFor(name)
|
|
71378
|
+
]);
|
|
71379
|
+
requireBinary(result);
|
|
71380
|
+
requireSuccess(result, `remove the passphrase of ${name} from the secret service`);
|
|
71381
|
+
return existed;
|
|
71382
|
+
}
|
|
71383
|
+
};
|
|
71384
|
+
}
|
|
71385
|
+
function unsupportedStore(platform2) {
|
|
71386
|
+
const refuse = () => {
|
|
71387
|
+
throw new KeystoreError(UNSUPPORTED_PLATFORM);
|
|
71388
|
+
};
|
|
71389
|
+
return {
|
|
71390
|
+
available: false,
|
|
71391
|
+
platform: platform2,
|
|
71392
|
+
description: "no OS secret store",
|
|
71393
|
+
get: async () => refuse(),
|
|
71394
|
+
has: async () => refuse(),
|
|
71395
|
+
set: async () => refuse(),
|
|
71396
|
+
remove: async () => refuse()
|
|
71397
|
+
};
|
|
71398
|
+
}
|
|
71399
|
+
function accountFor(name) {
|
|
71400
|
+
const account = name.trim();
|
|
71401
|
+
if (account.length === 0) {
|
|
71402
|
+
throw new KeystoreError("A wallet name is needed to reach the OS secret store.");
|
|
71403
|
+
}
|
|
71404
|
+
return account;
|
|
71405
|
+
}
|
|
71406
|
+
function requirePassphrase(passphrase) {
|
|
71407
|
+
if (passphrase.length === 0) {
|
|
71408
|
+
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
71409
|
+
}
|
|
71410
|
+
}
|
|
71411
|
+
function requireBinary(result) {
|
|
71412
|
+
if (result.notFound === true) throw new KeystoreError(SECRET_TOOL_MISSING);
|
|
71413
|
+
}
|
|
71414
|
+
function requirePowerShell(result) {
|
|
71415
|
+
if (result.notFound === true) throw new KeystoreError(POWERSHELL_MISSING);
|
|
71416
|
+
}
|
|
71417
|
+
function binaryInstalled(file2, env) {
|
|
71418
|
+
if (isAbsolute(file2) || win32.isAbsolute(file2)) return existsSync(file2);
|
|
71419
|
+
return (env.PATH ?? "").split(delimiter).some((directory) => existsSync(join7(directory, file2)));
|
|
71420
|
+
}
|
|
71421
|
+
var SAFE_FAILURE_DETAILS = [
|
|
71422
|
+
"Cannot autolaunch D-Bus without X11 $DISPLAY",
|
|
71423
|
+
"Cannot autolaunch D-Bus",
|
|
71424
|
+
"The name org.freedesktop.secrets was not provided by any .service files",
|
|
71425
|
+
"Cannot create an item in a locked collection",
|
|
71426
|
+
"User interaction is not allowed.",
|
|
71427
|
+
"Access to the path is denied."
|
|
71428
|
+
];
|
|
71429
|
+
function requireSuccess(result, what) {
|
|
71430
|
+
if (result.code === 0) return;
|
|
71431
|
+
const detail = SAFE_FAILURE_DETAILS.find((reason) => result.stderr.includes(reason));
|
|
71432
|
+
throw new KeystoreError(
|
|
71433
|
+
`Could not ${what}${result.code === null ? "" : ` (exit ${result.code})`}.${detail === void 0 ? "" : ` ${detail}`}`
|
|
71434
|
+
);
|
|
71435
|
+
}
|
|
71436
|
+
function withoutTrailingNewline(value) {
|
|
71437
|
+
return value.replace(/\r?\n$/u, "");
|
|
71438
|
+
}
|
|
71439
|
+
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve3) => {
|
|
71440
|
+
let stdout = "";
|
|
71441
|
+
let stderr2 = "";
|
|
71442
|
+
let settled = false;
|
|
71443
|
+
const finish = (outcome) => {
|
|
71444
|
+
if (settled) return;
|
|
71445
|
+
settled = true;
|
|
71446
|
+
resolve3(outcome);
|
|
71447
|
+
};
|
|
71448
|
+
const child = spawn(file2, [...args], {
|
|
71449
|
+
detached: platform2 !== "win32",
|
|
71450
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
71451
|
+
windowsHide: true
|
|
71452
|
+
});
|
|
71453
|
+
child.stdout?.setEncoding("utf8");
|
|
71454
|
+
child.stdout?.on("data", (chunk) => {
|
|
71455
|
+
stdout += chunk;
|
|
71456
|
+
});
|
|
71457
|
+
child.stderr?.setEncoding("utf8");
|
|
71458
|
+
child.stderr?.on("data", (chunk) => {
|
|
71459
|
+
stderr2 += chunk;
|
|
71460
|
+
});
|
|
71461
|
+
child.on("error", (error61) => {
|
|
71462
|
+
finish({
|
|
71463
|
+
code: null,
|
|
71464
|
+
stdout,
|
|
71465
|
+
stderr: stderr2,
|
|
71466
|
+
...error61.code === "ENOENT" ? { notFound: true } : {}
|
|
71467
|
+
});
|
|
71468
|
+
});
|
|
71469
|
+
child.on("close", (code) => finish({ code, stdout, stderr: stderr2 }));
|
|
71470
|
+
child.stdin?.on("error", () => void 0);
|
|
71471
|
+
child.stdin?.end(input2 ?? "");
|
|
71472
|
+
});
|
|
71473
|
+
|
|
71474
|
+
// ../core/src/passphrase.ts
|
|
71475
|
+
var PASSPHRASE_ENVIRONMENT_VARIABLE = "VAPI_KEYSTORE_PASSWORD";
|
|
71476
|
+
function noPassphraseHint(walletName) {
|
|
71477
|
+
return `Set ${PASSPHRASE_ENVIRONMENT_VARIABLE}, or store this wallet's passphrase once with vapi unlock --wallet ${walletName}.`;
|
|
71478
|
+
}
|
|
71479
|
+
function staleStoredPassphraseMessage(walletName, store) {
|
|
71480
|
+
return [
|
|
71481
|
+
`The passphrase stored in ${store.description} no longer opens wallet ${walletName}.`,
|
|
71482
|
+
`Store the current one with vapi unlock --wallet ${walletName}, or remove it with vapi lock --wallet ${walletName}.`
|
|
71483
|
+
].join(" ");
|
|
71484
|
+
}
|
|
71485
|
+
async function resolvePassphrase(walletName, options = {}) {
|
|
71486
|
+
const env = options.env ?? process.env;
|
|
71487
|
+
const fromEnvironment = env[PASSPHRASE_ENVIRONMENT_VARIABLE];
|
|
71488
|
+
if (fromEnvironment !== void 0) {
|
|
71489
|
+
if (fromEnvironment.length === 0) {
|
|
71490
|
+
throw new KeystoreError(`${PASSPHRASE_ENVIRONMENT_VARIABLE} cannot be empty.`);
|
|
71491
|
+
}
|
|
71492
|
+
return { passphrase: fromEnvironment, source: "environment" };
|
|
71310
71493
|
}
|
|
71311
|
-
|
|
71312
|
-
|
|
71313
|
-
|
|
71314
|
-
}
|
|
71315
|
-
function assertVaultKey(key2) {
|
|
71316
|
-
if (key2.byteLength !== 32) {
|
|
71317
|
-
throw new VaultError("bad_key", "A device vault key must contain exactly 32 bytes.");
|
|
71494
|
+
if (options.confirm !== true) {
|
|
71495
|
+
const stored = await readStored(options.store ?? secretStore(), walletName);
|
|
71496
|
+
if (stored !== void 0) return { passphrase: stored, source: "secret-store" };
|
|
71318
71497
|
}
|
|
71319
|
-
|
|
71320
|
-
|
|
71321
|
-
|
|
71322
|
-
|
|
71323
|
-
|
|
71324
|
-
cause: parsed.error
|
|
71325
|
-
});
|
|
71498
|
+
const hint = noPassphraseHint(walletName);
|
|
71499
|
+
if (options.interactive === false) {
|
|
71500
|
+
throw new KeystoreError(
|
|
71501
|
+
`No interactive terminal is available for the keystore prompt. ${hint}`
|
|
71502
|
+
);
|
|
71326
71503
|
}
|
|
71327
|
-
|
|
71328
|
-
|
|
71329
|
-
|
|
71330
|
-
|
|
71331
|
-
|
|
71504
|
+
const prompt = options.prompt ?? promptForSecret;
|
|
71505
|
+
const first = await prompt(`Passphrase for ${walletName}: `, hint);
|
|
71506
|
+
if (first.length === 0) {
|
|
71507
|
+
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
71508
|
+
}
|
|
71509
|
+
if (options.confirm === true) {
|
|
71510
|
+
const second = await prompt("Confirm passphrase: ", hint);
|
|
71511
|
+
if (first !== second) throw new KeystoreError("Passphrases do not match.");
|
|
71332
71512
|
}
|
|
71513
|
+
return { passphrase: first, source: "prompt" };
|
|
71333
71514
|
}
|
|
71334
|
-
function
|
|
71335
|
-
|
|
71336
|
-
|
|
71337
|
-
|
|
71515
|
+
async function readStored(store, walletName) {
|
|
71516
|
+
if (!store.available) return void 0;
|
|
71517
|
+
try {
|
|
71518
|
+
return await store.get(walletName);
|
|
71519
|
+
} catch {
|
|
71520
|
+
return void 0;
|
|
71338
71521
|
}
|
|
71339
|
-
return next;
|
|
71340
71522
|
}
|
|
71341
|
-
|
|
71342
|
-
|
|
71343
|
-
|
|
71344
|
-
|
|
71345
|
-
|
|
71346
|
-
|
|
71347
|
-
|
|
71348
|
-
|
|
71523
|
+
|
|
71524
|
+
// ../core/src/receipts.ts
|
|
71525
|
+
import { randomBytes as randomBytes8 } from "node:crypto";
|
|
71526
|
+
import { mkdir as mkdir8, open as open7, readFile as readFile9, rename as rename5, writeFile as writeFile4 } from "node:fs/promises";
|
|
71527
|
+
import { dirname as dirname6 } from "node:path";
|
|
71528
|
+
|
|
71529
|
+
// ../core/src/agent-run.ts
|
|
71530
|
+
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
71531
|
+
var RUN_ID_PATTERN = /^run_[0-9a-f]{24}$/;
|
|
71532
|
+
function isRunId(value) {
|
|
71533
|
+
return typeof value === "string" && RUN_ID_PATTERN.test(value);
|
|
71349
71534
|
}
|
|
71350
|
-
function
|
|
71351
|
-
|
|
71352
|
-
return [nonce, ciphertext, tag].map((part) => part.toString("base64url")).join(".");
|
|
71535
|
+
function createRunId(random = randomBytes7) {
|
|
71536
|
+
return `run_${Buffer.from(random(12)).toString("hex")}`;
|
|
71353
71537
|
}
|
|
71354
|
-
|
|
71355
|
-
|
|
71356
|
-
|
|
71357
|
-
|
|
71358
|
-
|
|
71359
|
-
|
|
71538
|
+
var runRefSchema = external_exports.strictObject({
|
|
71539
|
+
id: external_exports.string().regex(RUN_ID_PATTERN),
|
|
71540
|
+
swarm: external_exports.string().optional(),
|
|
71541
|
+
member: external_exports.string().optional(),
|
|
71542
|
+
parentRunId: external_exports.string().optional()
|
|
71543
|
+
});
|
|
71544
|
+
|
|
71545
|
+
// ../core/src/receipts.ts
|
|
71546
|
+
var receiptTestHooks;
|
|
71547
|
+
var RECEIPT_JOURNAL_BUSY_MESSAGE = "The receipt journal is busy. Wait for the other vapi command to finish, then retry.";
|
|
71548
|
+
async function withReceiptJournalLock(path, operation) {
|
|
71549
|
+
return await withFileLock(`${path}.lock`, operation, {
|
|
71550
|
+
lockedMessage: RECEIPT_JOURNAL_BUSY_MESSAGE
|
|
71360
71551
|
});
|
|
71361
71552
|
}
|
|
71362
|
-
|
|
71363
|
-
|
|
71364
|
-
|
|
71365
|
-
|
|
71366
|
-
|
|
71367
|
-
|
|
71368
|
-
|
|
71369
|
-
|
|
71370
|
-
|
|
71371
|
-
|
|
71372
|
-
|
|
71373
|
-
|
|
71374
|
-
|
|
71375
|
-
|
|
71376
|
-
|
|
71377
|
-
})
|
|
71553
|
+
var durationSchema = external_exports.number().nonnegative().finite();
|
|
71554
|
+
var receiptSchema = external_exports.strictObject({
|
|
71555
|
+
id: external_exports.string().min(1),
|
|
71556
|
+
timestamp: external_exports.iso.datetime(),
|
|
71557
|
+
run: runRefSchema.optional(),
|
|
71558
|
+
kind: external_exports.literal("transfer").optional(),
|
|
71559
|
+
wallet: walletNameSchema.optional(),
|
|
71560
|
+
resourceUrl: external_exports.url(),
|
|
71561
|
+
method: external_exports.string().min(1).optional(),
|
|
71562
|
+
source: external_exports.string().min(1).optional(),
|
|
71563
|
+
provenance: external_exports.array(
|
|
71564
|
+
external_exports.strictObject({
|
|
71565
|
+
source: external_exports.string().min(1),
|
|
71566
|
+
sourceUrl: external_exports.string().optional(),
|
|
71567
|
+
ref: external_exports.string().optional()
|
|
71568
|
+
})
|
|
71569
|
+
).optional(),
|
|
71570
|
+
quote: external_exports.strictObject({
|
|
71571
|
+
network: external_exports.string(),
|
|
71572
|
+
asset: external_exports.string().optional(),
|
|
71573
|
+
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
71574
|
+
payTo: external_exports.string().optional()
|
|
71575
|
+
}).optional(),
|
|
71576
|
+
payer: external_exports.string().optional(),
|
|
71577
|
+
paymentId: external_exports.string().regex(/^[A-Za-z0-9_-]{16,128}$/).optional(),
|
|
71578
|
+
authorization: external_exports.strictObject({
|
|
71579
|
+
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71580
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
71581
|
+
validBefore: external_exports.string().regex(/^\d+$/)
|
|
71582
|
+
}).optional(),
|
|
71583
|
+
transfer: external_exports.strictObject({
|
|
71584
|
+
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71585
|
+
toName: external_exports.string().min(1),
|
|
71586
|
+
toKind: external_exports.enum(["owner", "account"]),
|
|
71587
|
+
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
71588
|
+
network: external_exports.string().min(1),
|
|
71589
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
71590
|
+
status: external_exports.enum(["sent", "unknown", "failed"]),
|
|
71591
|
+
txHash: external_exports.string().regex(/^0x[0-9a-fA-F]+$/).nullable(),
|
|
71592
|
+
replayed: external_exports.boolean(),
|
|
71593
|
+
reservedOn: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
71594
|
+
request: external_exports.strictObject({
|
|
71595
|
+
authorization: external_exports.strictObject({
|
|
71596
|
+
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71597
|
+
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71598
|
+
value: external_exports.string().regex(/^\d+$/),
|
|
71599
|
+
validAfter: external_exports.string().regex(/^\d+$/),
|
|
71600
|
+
validBefore: external_exports.string().regex(/^\d+$/),
|
|
71601
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/)
|
|
71602
|
+
}),
|
|
71603
|
+
signature: external_exports.string().regex(/^0x[0-9a-fA-F]+$/)
|
|
71604
|
+
}).optional()
|
|
71605
|
+
}).optional(),
|
|
71606
|
+
settlement: external_exports.strictObject({
|
|
71607
|
+
outcome: external_exports.enum(["succeeded", "rejected", "unknown"]),
|
|
71608
|
+
transaction: external_exports.string().optional(),
|
|
71609
|
+
explorerUrl: external_exports.url().optional(),
|
|
71610
|
+
evidence: external_exports.unknown().optional()
|
|
71611
|
+
}).optional(),
|
|
71612
|
+
latencyMs: external_exports.number().nonnegative().finite().optional(),
|
|
71613
|
+
status: external_exports.number().int().min(100).max(599).optional(),
|
|
71614
|
+
error: external_exports.strictObject({ code: external_exports.string(), message: external_exports.string() }).optional(),
|
|
71615
|
+
phases: external_exports.strictObject({
|
|
71616
|
+
discoverMs: durationSchema.optional(),
|
|
71617
|
+
quoteMs: durationSchema.optional(),
|
|
71618
|
+
signMs: durationSchema.optional(),
|
|
71619
|
+
requestMs: durationSchema.optional(),
|
|
71620
|
+
settleMs: durationSchema.optional()
|
|
71621
|
+
}).optional(),
|
|
71622
|
+
listing: external_exports.strictObject({
|
|
71623
|
+
name: external_exports.string().min(1).optional(),
|
|
71624
|
+
providerHost: external_exports.string().min(1).optional(),
|
|
71625
|
+
source: external_exports.string().min(1)
|
|
71626
|
+
}).optional(),
|
|
71627
|
+
retry: external_exports.number().int().nonnegative().optional(),
|
|
71628
|
+
policy: external_exports.strictObject({
|
|
71629
|
+
maxPriceUsd: external_exports.string().regex(/^\d+(?:\.\d{1,6})?$/).optional(),
|
|
71630
|
+
capsApplied: external_exports.boolean()
|
|
71631
|
+
}).optional(),
|
|
71632
|
+
client: external_exports.strictObject({ name: external_exports.literal("vapi-network"), version: external_exports.string().min(1) }).optional(),
|
|
71633
|
+
outcome: external_exports.enum([
|
|
71634
|
+
"paid",
|
|
71635
|
+
"signed_in",
|
|
71636
|
+
"declined_policy",
|
|
71637
|
+
"failed_request",
|
|
71638
|
+
"settlement_rejected",
|
|
71639
|
+
"settlement_unknown"
|
|
71640
|
+
]).optional()
|
|
71641
|
+
});
|
|
71642
|
+
function parseReceipt(value) {
|
|
71643
|
+
const receipt = receiptSchema.parse(value);
|
|
71644
|
+
const transaction2 = receipt.settlement?.transaction;
|
|
71645
|
+
const network = receipt.quote?.network;
|
|
71646
|
+
const explorerUrl = transaction2 === void 0 || network === void 0 ? void 0 : explorerTransactionUrl(network, transaction2);
|
|
71647
|
+
if (explorerUrl === void 0 || receipt.settlement?.explorerUrl === explorerUrl) {
|
|
71648
|
+
return receipt;
|
|
71378
71649
|
}
|
|
71379
|
-
|
|
71380
|
-
|
|
71381
|
-
|
|
71382
|
-
|
|
71383
|
-
|
|
71384
|
-
|
|
71385
|
-
|
|
71386
|
-
}
|
|
71387
|
-
let address4;
|
|
71388
|
-
try {
|
|
71389
|
-
address4 = privateKeyToAccount(`0x${plaintext.toString("hex")}`).address;
|
|
71390
|
-
} catch (error61) {
|
|
71391
|
-
throw new VaultError("bad_key", "The stored imported key is not valid.", {
|
|
71392
|
-
cause: error61
|
|
71393
|
-
});
|
|
71394
|
-
}
|
|
71395
|
-
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
71396
|
-
throw new VaultError("bad_key", "The stored imported key does not match its address.");
|
|
71650
|
+
return {
|
|
71651
|
+
...receipt,
|
|
71652
|
+
settlement: {
|
|
71653
|
+
outcome: receipt.settlement.outcome,
|
|
71654
|
+
...receipt.settlement.transaction ? { transaction: receipt.settlement.transaction } : {},
|
|
71655
|
+
explorerUrl,
|
|
71656
|
+
...receipt.settlement.evidence === void 0 ? {} : { evidence: receipt.settlement.evidence }
|
|
71397
71657
|
}
|
|
71398
|
-
}
|
|
71399
|
-
plaintext?.fill(0);
|
|
71400
|
-
}
|
|
71658
|
+
};
|
|
71401
71659
|
}
|
|
71402
|
-
function
|
|
71403
|
-
const
|
|
71404
|
-
|
|
71405
|
-
|
|
71406
|
-
|
|
71407
|
-
|
|
71408
|
-
|
|
71409
|
-
|
|
71410
|
-
|
|
71411
|
-
|
|
71660
|
+
async function appendReceipt(receipt, path = getVapiPaths().receipts, options = {}) {
|
|
71661
|
+
const parsed = parseReceipt(
|
|
71662
|
+
receipt.wallet === void 0 && options.wallet !== void 0 ? { ...receipt, wallet: options.wallet } : receipt
|
|
71663
|
+
);
|
|
71664
|
+
await withReceiptJournalLock(path, async () => {
|
|
71665
|
+
await mkdir8(dirname6(path), { recursive: true, mode: 448 });
|
|
71666
|
+
const handle = await open7(path, "a", 384);
|
|
71667
|
+
try {
|
|
71668
|
+
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
71669
|
+
`, "utf8");
|
|
71670
|
+
} finally {
|
|
71671
|
+
await handle.close();
|
|
71412
71672
|
}
|
|
71413
|
-
}
|
|
71414
|
-
|
|
71415
|
-
plaintext.fill(0);
|
|
71416
|
-
}
|
|
71673
|
+
});
|
|
71674
|
+
return parsed;
|
|
71417
71675
|
}
|
|
71418
|
-
function
|
|
71419
|
-
let
|
|
71676
|
+
async function readReceipts(path = getVapiPaths().receipts, options = {}) {
|
|
71677
|
+
let raw;
|
|
71420
71678
|
try {
|
|
71421
|
-
|
|
71679
|
+
raw = await readFile9(path, "utf8");
|
|
71422
71680
|
} catch (error61) {
|
|
71423
|
-
|
|
71424
|
-
|
|
71425
|
-
const parsed = vaultFileSchema.safeParse(value);
|
|
71426
|
-
if (!parsed.success) {
|
|
71427
|
-
throw new VaultError("corrupt", "The vault file has an invalid structure.", {
|
|
71428
|
-
cause: parsed.error
|
|
71429
|
-
});
|
|
71430
|
-
}
|
|
71431
|
-
if (parsed.data.protected !== (parsed.data.wrappedKey !== void 0)) {
|
|
71432
|
-
throw new VaultError("corrupt", "The vault protection metadata is inconsistent.");
|
|
71681
|
+
if (isMissingFile(error61)) return [];
|
|
71682
|
+
throw error61;
|
|
71433
71683
|
}
|
|
71434
|
-
const
|
|
71435
|
-
|
|
71436
|
-
|
|
71437
|
-
|
|
71438
|
-
|
|
71439
|
-
|
|
71440
|
-
names.add(account.name);
|
|
71441
|
-
if (account.kind === "derived") {
|
|
71442
|
-
if (indexes.has(account.index)) {
|
|
71443
|
-
throw new VaultError("corrupt", "The vault file contains duplicate derived indexes.");
|
|
71684
|
+
const records = coalesceTransferReceiptRevisions(
|
|
71685
|
+
raw.split("\n").filter((line) => line.trim().length > 0).map((line, index2) => {
|
|
71686
|
+
try {
|
|
71687
|
+
return parseReceipt(JSON.parse(line));
|
|
71688
|
+
} catch (error61) {
|
|
71689
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71444
71690
|
}
|
|
71445
|
-
|
|
71691
|
+
})
|
|
71692
|
+
);
|
|
71693
|
+
const filtered = options.wallet === void 0 ? records : filterReceiptsByWallet(records, options.wallet);
|
|
71694
|
+
const limit = options.limit;
|
|
71695
|
+
if (limit === void 0) return filtered;
|
|
71696
|
+
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
71697
|
+
throw new Error("Receipt limit must be a non-negative integer.");
|
|
71698
|
+
return limit === 0 ? [] : filtered.slice(-limit);
|
|
71699
|
+
}
|
|
71700
|
+
function coalesceTransferReceiptRevisions(receipts) {
|
|
71701
|
+
const coalesced = [];
|
|
71702
|
+
const transferIndexes = /* @__PURE__ */ new Map();
|
|
71703
|
+
for (const receipt of receipts) {
|
|
71704
|
+
const existing = receipt.kind === "transfer" ? transferIndexes.get(receipt.id) : void 0;
|
|
71705
|
+
if (existing === void 0) {
|
|
71706
|
+
if (receipt.kind === "transfer") transferIndexes.set(receipt.id, coalesced.length);
|
|
71707
|
+
coalesced.push(receipt);
|
|
71708
|
+
} else {
|
|
71709
|
+
coalesced[existing] = receipt;
|
|
71446
71710
|
}
|
|
71447
71711
|
}
|
|
71448
|
-
return
|
|
71712
|
+
return coalesced;
|
|
71449
71713
|
}
|
|
71450
|
-
|
|
71451
|
-
|
|
71452
|
-
|
|
71453
|
-
|
|
71714
|
+
function receiptWallet(receipt) {
|
|
71715
|
+
return receipt.wallet ?? DEFAULT_WALLET_NAME;
|
|
71716
|
+
}
|
|
71717
|
+
function filterReceiptsByWallet(receipts, name) {
|
|
71718
|
+
return receipts.filter((receipt) => receiptWallet(receipt) === name);
|
|
71719
|
+
}
|
|
71720
|
+
async function renameReceiptWallet(from16, to, path = getVapiPaths().receipts) {
|
|
71721
|
+
return await withReceiptJournalLock(path, async () => {
|
|
71722
|
+
let raw;
|
|
71454
71723
|
try {
|
|
71455
|
-
|
|
71724
|
+
raw = await readFile9(path, "utf8");
|
|
71456
71725
|
} catch (error61) {
|
|
71457
|
-
|
|
71458
|
-
|
|
71459
|
-
});
|
|
71460
|
-
}
|
|
71461
|
-
} finally {
|
|
71462
|
-
plaintext.fill(0);
|
|
71463
|
-
}
|
|
71464
|
-
return file2;
|
|
71465
|
-
}
|
|
71466
|
-
async function readVaultFileUnlocked(path) {
|
|
71467
|
-
let raw;
|
|
71468
|
-
try {
|
|
71469
|
-
raw = await readFile9(path, "utf8");
|
|
71470
|
-
} catch (error61) {
|
|
71471
|
-
if (isMissingFile2(error61)) {
|
|
71472
|
-
throw new VaultError("not_found", "No vault file was found at the requested path.", {
|
|
71473
|
-
cause: error61
|
|
71474
|
-
});
|
|
71726
|
+
if (isMissingFile(error61)) return 0;
|
|
71727
|
+
throw error61;
|
|
71475
71728
|
}
|
|
71476
|
-
|
|
71477
|
-
|
|
71478
|
-
|
|
71479
|
-
|
|
71480
|
-
|
|
71481
|
-
|
|
71482
|
-
|
|
71483
|
-
|
|
71484
|
-
|
|
71485
|
-
|
|
71486
|
-
|
|
71729
|
+
let changed = 0;
|
|
71730
|
+
const lines = raw.split("\n").map((line, index2) => {
|
|
71731
|
+
if (line.trim().length === 0) return line;
|
|
71732
|
+
let parsed;
|
|
71733
|
+
try {
|
|
71734
|
+
parsed = JSON.parse(line);
|
|
71735
|
+
} catch (error61) {
|
|
71736
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71737
|
+
}
|
|
71738
|
+
const current = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "wallet") : void 0;
|
|
71739
|
+
if ((typeof current === "string" ? current : DEFAULT_WALLET_NAME) !== from16) return line;
|
|
71740
|
+
changed += 1;
|
|
71741
|
+
return JSON.stringify(parseReceipt({ ...parsed, wallet: to }));
|
|
71487
71742
|
});
|
|
71488
|
-
|
|
71489
|
-
|
|
71490
|
-
}
|
|
71491
|
-
|
|
71492
|
-
|
|
71493
|
-
const temporaryPath = `${path}.${process.pid}.${randomBytes7(6).toString("hex")}.tmp`;
|
|
71494
|
-
try {
|
|
71495
|
-
await writeFile4(temporaryPath, `${JSON.stringify(file2, null, 2)}
|
|
71496
|
-
`, {
|
|
71743
|
+
if (changed === 0) return 0;
|
|
71744
|
+
await receiptTestHooks?.beforeRenameReplace?.(path);
|
|
71745
|
+
await mkdir8(dirname6(path), { recursive: true, mode: 448 });
|
|
71746
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes8(6).toString("hex")}.tmp`;
|
|
71747
|
+
await writeFile4(temporaryPath, lines.join("\n"), {
|
|
71497
71748
|
encoding: "utf8",
|
|
71498
71749
|
mode: 384,
|
|
71499
71750
|
flag: "wx"
|
|
71500
71751
|
});
|
|
71501
71752
|
await rename5(temporaryPath, path);
|
|
71753
|
+
return changed;
|
|
71754
|
+
});
|
|
71755
|
+
}
|
|
71756
|
+
|
|
71757
|
+
// ../core/src/transfer-journal.ts
|
|
71758
|
+
import { readFile as readFile10 } from "node:fs/promises";
|
|
71759
|
+
async function readTransferJournal(home, from16, nonce) {
|
|
71760
|
+
let raw;
|
|
71761
|
+
try {
|
|
71762
|
+
raw = await readFile10(getVapiPaths(home).receipts, "utf8");
|
|
71502
71763
|
} catch (error61) {
|
|
71503
|
-
|
|
71764
|
+
if (isMissingFile(error61)) return { signed: false };
|
|
71504
71765
|
throw error61;
|
|
71505
71766
|
}
|
|
71506
|
-
|
|
71507
|
-
|
|
71508
|
-
|
|
71509
|
-
|
|
71510
|
-
|
|
71511
|
-
let handle;
|
|
71512
|
-
while (!handle) {
|
|
71767
|
+
let latest;
|
|
71768
|
+
let request;
|
|
71769
|
+
for (const [index2, line] of raw.split("\n").entries()) {
|
|
71770
|
+
if (!line.trim()) continue;
|
|
71771
|
+
let receipt;
|
|
71513
71772
|
try {
|
|
71514
|
-
|
|
71773
|
+
receipt = parseReceipt(JSON.parse(line));
|
|
71515
71774
|
} catch (error61) {
|
|
71516
|
-
|
|
71517
|
-
await removeStaleVaultLock(lockPath);
|
|
71518
|
-
if (Date.now() >= deadline) {
|
|
71519
|
-
throw new VaultError("corrupt", "Timed out waiting for the vault lock.");
|
|
71520
|
-
}
|
|
71521
|
-
await new Promise((resolve3) => setTimeout(resolve3, 20));
|
|
71775
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71522
71776
|
}
|
|
71777
|
+
if (receiptWallet(receipt) !== from16 || receipt.transfer?.nonce.toLowerCase() !== nonce.toLowerCase()) {
|
|
71778
|
+
continue;
|
|
71779
|
+
}
|
|
71780
|
+
latest = receipt;
|
|
71781
|
+
if (receipt.transfer.request !== void 0) request = receipt;
|
|
71523
71782
|
}
|
|
71524
|
-
|
|
71525
|
-
|
|
71526
|
-
|
|
71527
|
-
|
|
71528
|
-
|
|
71529
|
-
|
|
71530
|
-
}
|
|
71531
|
-
async function removeStaleVaultLock(path) {
|
|
71532
|
-
try {
|
|
71533
|
-
const metadata = await stat6(path);
|
|
71534
|
-
if (Date.now() - metadata.mtimeMs > STALE_VAULT_LOCK_MS) await unlink4(path);
|
|
71535
|
-
} catch (error61) {
|
|
71536
|
-
if (!isMissingFile2(error61)) throw error61;
|
|
71537
|
-
}
|
|
71538
|
-
}
|
|
71539
|
-
function isMissingFile2(error61) {
|
|
71540
|
-
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "ENOENT";
|
|
71541
|
-
}
|
|
71542
|
-
function isExistingFile(error61) {
|
|
71543
|
-
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "EEXIST";
|
|
71544
|
-
}
|
|
71545
|
-
function asVaultError(error61, code, message) {
|
|
71546
|
-
return error61 instanceof VaultError ? error61 : new VaultError(code, message, { cause: error61 });
|
|
71783
|
+
return {
|
|
71784
|
+
signed: latest !== void 0,
|
|
71785
|
+
...latest === void 0 ? {} : { latest },
|
|
71786
|
+
...request === void 0 ? {} : { request },
|
|
71787
|
+
...request?.transfer?.request?.authorization.validBefore === void 0 ? {} : { validBefore: request.transfer.request.authorization.validBefore },
|
|
71788
|
+
...(latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn) === void 0 ? {} : { reservedOn: latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn }
|
|
71789
|
+
};
|
|
71547
71790
|
}
|
|
71548
71791
|
|
|
71549
71792
|
// ../core/src/vault-key.ts
|
|
71793
|
+
import { randomBytes as cryptoRandomBytes } from "node:crypto";
|
|
71550
71794
|
var VAULT_KEY_ACCOUNT = "vault-key";
|
|
71551
71795
|
var VAULT_SESSION_ACCOUNT = "vault-session";
|
|
71552
71796
|
var DEVICE_KEY_LENGTH = 32;
|
|
@@ -71568,7 +71812,7 @@ async function loadOrCreateDeviceKey(args) {
|
|
|
71568
71812
|
await args.secrets.set(VAULT_KEY_ACCOUNT, key2.toString("base64"));
|
|
71569
71813
|
return key2;
|
|
71570
71814
|
} catch (error61) {
|
|
71571
|
-
throw asVaultError2(error61,
|
|
71815
|
+
throw asVaultError2(error61, deviceKeyFailureMessage(error61, args.secrets.platform));
|
|
71572
71816
|
}
|
|
71573
71817
|
});
|
|
71574
71818
|
}
|
|
@@ -71774,8 +72018,8 @@ function passwordRequiredError() {
|
|
|
71774
72018
|
"A vault password is needed. Pass it or set VAPI_VAULT_PASSWORD."
|
|
71775
72019
|
);
|
|
71776
72020
|
}
|
|
71777
|
-
function randomKeyBytes(
|
|
71778
|
-
const key2 = Buffer.from((
|
|
72021
|
+
function randomKeyBytes(randomBytes18) {
|
|
72022
|
+
const key2 = Buffer.from((randomBytes18 ?? cryptoRandomBytes)(DEVICE_KEY_LENGTH));
|
|
71779
72023
|
if (key2.byteLength !== DEVICE_KEY_LENGTH) {
|
|
71780
72024
|
key2.fill(0);
|
|
71781
72025
|
throw new VaultError("corrupt", "A generated device vault key has the wrong length.");
|
|
@@ -71826,25 +72070,31 @@ function parseJson(value) {
|
|
|
71826
72070
|
function asVaultError2(error61, message) {
|
|
71827
72071
|
return error61 instanceof VaultError ? error61 : new VaultError("corrupt", message, { cause: error61 });
|
|
71828
72072
|
}
|
|
72073
|
+
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.";
|
|
72074
|
+
function deviceKeyFailureMessage(error61, platform2) {
|
|
72075
|
+
if (!(error61 instanceof KeystoreError)) return "Unable to load or create the device vault key.";
|
|
72076
|
+
const detail = `Unable to load or create the device vault key: ${error61.message.replace(/\.$/u, "")}.`;
|
|
72077
|
+
return platform2 === "linux" ? `${detail} ${HEADLESS_LINUX_HINT}` : detail;
|
|
72078
|
+
}
|
|
71829
72079
|
|
|
71830
72080
|
// ../core/src/vault-migrate.ts
|
|
71831
72081
|
import {
|
|
71832
72082
|
chmod as chmod2,
|
|
71833
72083
|
lstat,
|
|
71834
72084
|
mkdir as mkdir9,
|
|
71835
|
-
readFile as
|
|
72085
|
+
readFile as readFile11,
|
|
71836
72086
|
readlink,
|
|
71837
72087
|
readdir as readdir2,
|
|
71838
72088
|
rename as rename6,
|
|
71839
72089
|
symlink,
|
|
71840
72090
|
unlink as unlink5
|
|
71841
72091
|
} from "node:fs/promises";
|
|
71842
|
-
import { join as
|
|
72092
|
+
import { join as join8, resolve } from "node:path";
|
|
71843
72093
|
var MIGRATED_DIRECTORY = "wallets.migrated";
|
|
71844
72094
|
async function legacyKeystoreNames(home) {
|
|
71845
72095
|
let entries;
|
|
71846
72096
|
try {
|
|
71847
|
-
entries = await readdir2(
|
|
72097
|
+
entries = await readdir2(join8(home, "wallets"), { withFileTypes: true });
|
|
71848
72098
|
} catch (error61) {
|
|
71849
72099
|
if (isMissingFile(error61)) return [];
|
|
71850
72100
|
throw error61;
|
|
@@ -71860,14 +72110,14 @@ async function migrateKeystores(args) {
|
|
|
71860
72110
|
);
|
|
71861
72111
|
const result = { imported: [], skipped: [] };
|
|
71862
72112
|
for (const name of names) {
|
|
71863
|
-
const source =
|
|
72113
|
+
const source = join8(args.home, "wallets", `${name}.json`);
|
|
71864
72114
|
if (args.vault.accounts().some((account) => account.name === name)) {
|
|
71865
72115
|
result.skipped.push({ name, reason: "name_taken" });
|
|
71866
72116
|
continue;
|
|
71867
72117
|
}
|
|
71868
72118
|
let parsed;
|
|
71869
72119
|
try {
|
|
71870
|
-
parsed = parseAnyKeystore(JSON.parse(await
|
|
72120
|
+
parsed = parseAnyKeystore(JSON.parse(await readFile11(source, "utf8")));
|
|
71871
72121
|
} catch {
|
|
71872
72122
|
result.skipped.push({ name, reason: "unreadable" });
|
|
71873
72123
|
continue;
|
|
@@ -71897,15 +72147,15 @@ async function migrateKeystores(args) {
|
|
|
71897
72147
|
if (imported.address.toLowerCase() !== parsed.address.toLowerCase()) {
|
|
71898
72148
|
throw new KeystoreError(`Migrated wallet ${name} does not match its stored address.`);
|
|
71899
72149
|
}
|
|
71900
|
-
const migratedDirectory =
|
|
71901
|
-
const destination =
|
|
72150
|
+
const migratedDirectory = join8(args.home, MIGRATED_DIRECTORY);
|
|
72151
|
+
const destination = join8(migratedDirectory, `${name}.json`);
|
|
71902
72152
|
await mkdir9(migratedDirectory, { recursive: true, mode: 448 });
|
|
71903
72153
|
await archiveExistingDestination(destination, migratedDirectory, name, now);
|
|
71904
72154
|
await rename6(source, destination);
|
|
71905
72155
|
await chmod2(destination, 384);
|
|
71906
72156
|
try {
|
|
71907
72157
|
await removeCompatibilityLink(args.home, source);
|
|
71908
|
-
await symlink(
|
|
72158
|
+
await symlink(join8("..", MIGRATED_DIRECTORY, `${name}.json`), source);
|
|
71909
72159
|
await audit({
|
|
71910
72160
|
event: "vault.migrate",
|
|
71911
72161
|
wallet: name,
|
|
@@ -71933,16 +72183,16 @@ async function migrateKeystores(args) {
|
|
|
71933
72183
|
async function archiveExistingDestination(destination, directory, name, now) {
|
|
71934
72184
|
if (!await pathExists2(destination)) return;
|
|
71935
72185
|
const timestamp = now().toISOString();
|
|
71936
|
-
let archive =
|
|
72186
|
+
let archive = join8(directory, `${name}.${timestamp}.json`);
|
|
71937
72187
|
let suffix = 1;
|
|
71938
72188
|
while (await pathExists2(archive)) {
|
|
71939
|
-
archive =
|
|
72189
|
+
archive = join8(directory, `${name}.${timestamp}.${suffix}.json`);
|
|
71940
72190
|
suffix += 1;
|
|
71941
72191
|
}
|
|
71942
72192
|
await rename6(destination, archive);
|
|
71943
72193
|
}
|
|
71944
72194
|
async function removeCompatibilityLink(home, migratedSource) {
|
|
71945
|
-
const compatibilityPath =
|
|
72195
|
+
const compatibilityPath = join8(home, "keystore.json");
|
|
71946
72196
|
let metadata;
|
|
71947
72197
|
try {
|
|
71948
72198
|
metadata = await lstat(compatibilityPath);
|
|
@@ -72016,7 +72266,7 @@ var WalletStore = class _WalletStore {
|
|
|
72016
72266
|
this.home = home;
|
|
72017
72267
|
this.options = options;
|
|
72018
72268
|
this.registry = registry2;
|
|
72019
|
-
this.secrets = options.secrets ?? secretStore();
|
|
72269
|
+
this.secrets = options.secrets ?? secretStore({ home });
|
|
72020
72270
|
this.environment = options.env ?? process.env;
|
|
72021
72271
|
this.passphraseResolver = options.resolvePassphrase ?? defaultPassphraseResolver(this.environment, this.secrets);
|
|
72022
72272
|
this.audit = options.audit ?? (async (record2) => await appendAudit(this.home, record2, { now: () => this.now() }));
|
|
@@ -72063,17 +72313,17 @@ var WalletStore = class _WalletStore {
|
|
|
72063
72313
|
return store;
|
|
72064
72314
|
}
|
|
72065
72315
|
get registryPath() {
|
|
72066
|
-
return
|
|
72316
|
+
return join9(this.home, REGISTRY_FILE);
|
|
72067
72317
|
}
|
|
72068
72318
|
get walletsDirectory() {
|
|
72069
|
-
return
|
|
72319
|
+
return join9(this.home, WALLETS_DIRECTORY);
|
|
72070
72320
|
}
|
|
72071
72321
|
get trashDirectory() {
|
|
72072
|
-
return
|
|
72322
|
+
return join9(this.walletsDirectory, TRASH_DIRECTORY);
|
|
72073
72323
|
}
|
|
72074
72324
|
/** The legacy 0.5 keystore path of a wallet, whether or not it exists. */
|
|
72075
72325
|
pathFor(name) {
|
|
72076
|
-
return
|
|
72326
|
+
return join9(this.walletsDirectory, `${assertWalletName(name)}.json`);
|
|
72077
72327
|
}
|
|
72078
72328
|
/** The names this machine knows, in registry order. */
|
|
72079
72329
|
names() {
|
|
@@ -72646,7 +72896,7 @@ var WalletStore = class _WalletStore {
|
|
|
72646
72896
|
}
|
|
72647
72897
|
const removedAt = this.now().toISOString();
|
|
72648
72898
|
await mkdir10(this.trashDirectory, { recursive: true, mode: 448 });
|
|
72649
|
-
const trashedPath =
|
|
72899
|
+
const trashedPath = join9(this.trashDirectory, `${wallet.name}-${removedAt}.json`);
|
|
72650
72900
|
const storedAccount = (await this.readVaultUnlocked())?.accounts.find(
|
|
72651
72901
|
(candidate) => candidate.name === wallet.name
|
|
72652
72902
|
);
|
|
@@ -72668,7 +72918,7 @@ var WalletStore = class _WalletStore {
|
|
|
72668
72918
|
this.balanceProbe = void 0;
|
|
72669
72919
|
}
|
|
72670
72920
|
if (await pathExists3(wallet.path)) {
|
|
72671
|
-
const legacyTrashedPath =
|
|
72921
|
+
const legacyTrashedPath = join9(
|
|
72672
72922
|
this.trashDirectory,
|
|
72673
72923
|
`${wallet.name}-${removedAt}.legacy.json`
|
|
72674
72924
|
);
|
|
@@ -72758,7 +73008,7 @@ var WalletStore = class _WalletStore {
|
|
|
72758
73008
|
if (!match) continue;
|
|
72759
73009
|
const [, name, removedAt] = match;
|
|
72760
73010
|
if (name === void 0 || removedAt === void 0 || !isWalletName(name)) continue;
|
|
72761
|
-
const path =
|
|
73011
|
+
const path = join9(this.trashDirectory, file2);
|
|
72762
73012
|
const entry = await readEntrySidecar(entrySidecarPath(path));
|
|
72763
73013
|
trashed.push({ name, removedAt, path, ...entry ? { entry } : {} });
|
|
72764
73014
|
}
|
|
@@ -72827,7 +73077,7 @@ var WalletStore = class _WalletStore {
|
|
|
72827
73077
|
return entry;
|
|
72828
73078
|
}
|
|
72829
73079
|
get vaultPath() {
|
|
72830
|
-
return
|
|
73080
|
+
return join9(this.home, VAULT_FILE);
|
|
72831
73081
|
}
|
|
72832
73082
|
async readVaultUnlocked() {
|
|
72833
73083
|
try {
|
|
@@ -72932,7 +73182,7 @@ var WalletStore = class _WalletStore {
|
|
|
72932
73182
|
async readRegistry() {
|
|
72933
73183
|
let raw;
|
|
72934
73184
|
try {
|
|
72935
|
-
raw = await
|
|
73185
|
+
raw = await readFile12(this.registryPath, "utf8");
|
|
72936
73186
|
} catch (error61) {
|
|
72937
73187
|
if (isMissingFile(error61)) return emptyRegistry();
|
|
72938
73188
|
throw error61;
|
|
@@ -72953,7 +73203,7 @@ var WalletStore = class _WalletStore {
|
|
|
72953
73203
|
}
|
|
72954
73204
|
};
|
|
72955
73205
|
async function swarmReferencingAccount(home, account) {
|
|
72956
|
-
const directory =
|
|
73206
|
+
const directory = join9(home, "swarms");
|
|
72957
73207
|
let files;
|
|
72958
73208
|
try {
|
|
72959
73209
|
files = await readdir3(directory);
|
|
@@ -72964,7 +73214,7 @@ async function swarmReferencingAccount(home, account) {
|
|
|
72964
73214
|
for (const file2 of files.filter((name) => name.endsWith(".json")).sort()) {
|
|
72965
73215
|
let value;
|
|
72966
73216
|
try {
|
|
72967
|
-
value = JSON.parse(await
|
|
73217
|
+
value = JSON.parse(await readFile12(join9(directory, file2), "utf8"));
|
|
72968
73218
|
} catch {
|
|
72969
73219
|
throw new KeystoreError(
|
|
72970
73220
|
`Cannot verify swarm references because ${file2} is invalid. Repair or remove that swarm file before renaming an account.`
|
|
@@ -72996,7 +73246,7 @@ async function swarmReferencingAccount(home, account) {
|
|
|
72996
73246
|
return void 0;
|
|
72997
73247
|
}
|
|
72998
73248
|
async function unfinishedMovementReferencingAccount(home, account) {
|
|
72999
|
-
const directory =
|
|
73249
|
+
const directory = join9(home, "movements");
|
|
73000
73250
|
let files;
|
|
73001
73251
|
try {
|
|
73002
73252
|
files = await readdir3(directory);
|
|
@@ -73007,7 +73257,7 @@ async function unfinishedMovementReferencingAccount(home, account) {
|
|
|
73007
73257
|
for (const file2 of files.filter((name) => name.endsWith(".json")).sort()) {
|
|
73008
73258
|
let value;
|
|
73009
73259
|
try {
|
|
73010
|
-
value = JSON.parse(await
|
|
73260
|
+
value = JSON.parse(await readFile12(join9(directory, file2), "utf8"));
|
|
73011
73261
|
} catch {
|
|
73012
73262
|
throw invalidMovementReferenceError(file2);
|
|
73013
73263
|
}
|
|
@@ -73028,11 +73278,11 @@ async function unfinishedMovementReferencingAccount(home, account) {
|
|
|
73028
73278
|
const restored = Reflect.get(leg, "restored");
|
|
73029
73279
|
const legFrom = Reflect.get(leg, "from") ?? movementFrom;
|
|
73030
73280
|
const journal = restored !== true && status === "failed" && retryable !== true && typeof nonce === "string" ? await readTransferJournal(home, legFrom, nonce) : void 0;
|
|
73031
|
-
const
|
|
73281
|
+
const open13 = isOpenMovementLeg(
|
|
73032
73282
|
{ status, retryable, nonce, restored },
|
|
73033
73283
|
journal?.signed === true ? "signed" : "unsigned"
|
|
73034
73284
|
);
|
|
73035
|
-
if (
|
|
73285
|
+
if (open13) movementOpen = true;
|
|
73036
73286
|
}
|
|
73037
73287
|
if (movementOpen && (movementFrom === account || legs.some(
|
|
73038
73288
|
(leg) => (Reflect.get(leg, "from") ?? movementFrom) === account || Reflect.get(leg, "to") === account
|
|
@@ -73068,7 +73318,7 @@ async function withAccountMutationLocks(home, accounts, command, operation) {
|
|
|
73068
73318
|
const [account, ...remaining2] = [...new Set(accounts)].sort();
|
|
73069
73319
|
if (account === void 0) return await operation();
|
|
73070
73320
|
return await withFileLock(
|
|
73071
|
-
|
|
73321
|
+
join9(home, `.account-${account}.lock`),
|
|
73072
73322
|
async () => await withAccountMutationLocks(home, remaining2, command, operation),
|
|
73073
73323
|
{
|
|
73074
73324
|
lockedMessage: `Account ${account} is busy with another account change. Wait for it to finish, then retry ${command}.`
|
|
@@ -73143,7 +73393,7 @@ function isLockedVaultError(error61) {
|
|
|
73143
73393
|
async function readTrashedVaultAccount(path) {
|
|
73144
73394
|
let parsed;
|
|
73145
73395
|
try {
|
|
73146
|
-
parsed = JSON.parse(await
|
|
73396
|
+
parsed = JSON.parse(await readFile12(path, "utf8"));
|
|
73147
73397
|
} catch {
|
|
73148
73398
|
return void 0;
|
|
73149
73399
|
}
|
|
@@ -73152,7 +73402,7 @@ async function readTrashedVaultAccount(path) {
|
|
|
73152
73402
|
}
|
|
73153
73403
|
async function readEntrySidecar(path) {
|
|
73154
73404
|
try {
|
|
73155
|
-
const parsed = walletEntrySchema.safeParse(JSON.parse(await
|
|
73405
|
+
const parsed = walletEntrySchema.safeParse(JSON.parse(await readFile12(path, "utf8")));
|
|
73156
73406
|
return parsed.success ? parsed.data : void 0;
|
|
73157
73407
|
} catch {
|
|
73158
73408
|
return void 0;
|
|
@@ -73161,7 +73411,7 @@ async function readEntrySidecar(path) {
|
|
|
73161
73411
|
async function readKeystoreSummary(path) {
|
|
73162
73412
|
let parsed;
|
|
73163
73413
|
try {
|
|
73164
|
-
parsed = JSON.parse(await
|
|
73414
|
+
parsed = JSON.parse(await readFile12(path, "utf8"));
|
|
73165
73415
|
} catch {
|
|
73166
73416
|
return {};
|
|
73167
73417
|
}
|
|
@@ -73179,7 +73429,7 @@ async function readKeystoreSummary(path) {
|
|
|
73179
73429
|
}
|
|
73180
73430
|
async function readConfiguredSpendCaps(configPath) {
|
|
73181
73431
|
try {
|
|
73182
|
-
const parsed = JSON.parse(await
|
|
73432
|
+
const parsed = JSON.parse(await readFile12(configPath, "utf8"));
|
|
73183
73433
|
const caps = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "spendCaps") : void 0;
|
|
73184
73434
|
const result = spendCapsSchema.safeParse(caps);
|
|
73185
73435
|
if (result.success) return result.data;
|
|
@@ -73271,7 +73521,7 @@ async function withRegistryLock(path, operation) {
|
|
|
73271
73521
|
let handle;
|
|
73272
73522
|
while (!handle) {
|
|
73273
73523
|
try {
|
|
73274
|
-
handle = await
|
|
73524
|
+
handle = await open8(lockPath, "wx", 384);
|
|
73275
73525
|
} catch (error61) {
|
|
73276
73526
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) throw error61;
|
|
73277
73527
|
await removeStaleRegistryLock(lockPath);
|
|
@@ -73290,7 +73540,7 @@ async function withRegistryLock(path, operation) {
|
|
|
73290
73540
|
}
|
|
73291
73541
|
async function removeStaleRegistryLock(path) {
|
|
73292
73542
|
try {
|
|
73293
|
-
const metadata = await
|
|
73543
|
+
const metadata = await stat9(path);
|
|
73294
73544
|
if (Date.now() - metadata.mtimeMs > 3e4) await unlink6(path);
|
|
73295
73545
|
} catch (error61) {
|
|
73296
73546
|
if (!isMissingFile(error61)) throw error61;
|
|
@@ -73298,7 +73548,7 @@ async function removeStaleRegistryLock(path) {
|
|
|
73298
73548
|
}
|
|
73299
73549
|
async function writeJsonFile(path, value) {
|
|
73300
73550
|
await mkdir10(dirname7(path), { recursive: true, mode: 448 });
|
|
73301
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
73551
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes9(6).toString("hex")}.tmp`;
|
|
73302
73552
|
await writeFile5(temporaryPath, `${JSON.stringify(value, null, 2)}
|
|
73303
73553
|
`, {
|
|
73304
73554
|
encoding: "utf8",
|
|
@@ -73336,7 +73586,7 @@ async function createAccount(args) {
|
|
|
73336
73586
|
created: false
|
|
73337
73587
|
};
|
|
73338
73588
|
}
|
|
73339
|
-
if (!await
|
|
73589
|
+
if (!await fileExists2(join10(args.store.home, "vault.json"))) {
|
|
73340
73590
|
throw new KeystoreError("No vault yet. Run vapi setup.");
|
|
73341
73591
|
}
|
|
73342
73592
|
const spendCaps = resolveNewAccountCaps(args.caps);
|
|
@@ -73603,9 +73853,9 @@ async function requireAddress(store, name) {
|
|
|
73603
73853
|
if (address4 === void 0) throw new KeystoreError(`No key for wallet ${name} in the vault.`);
|
|
73604
73854
|
return address4;
|
|
73605
73855
|
}
|
|
73606
|
-
async function
|
|
73856
|
+
async function fileExists2(path) {
|
|
73607
73857
|
try {
|
|
73608
|
-
await
|
|
73858
|
+
await stat10(path);
|
|
73609
73859
|
return true;
|
|
73610
73860
|
} catch (error61) {
|
|
73611
73861
|
if (isMissingFile(error61)) return false;
|
|
@@ -73667,9 +73917,9 @@ function secretsAllowed(env, streams) {
|
|
|
73667
73917
|
}
|
|
73668
73918
|
|
|
73669
73919
|
// ../core/src/agent-profile.ts
|
|
73670
|
-
import { randomBytes as
|
|
73671
|
-
import { mkdir as mkdir11, readFile as
|
|
73672
|
-
import { join as
|
|
73920
|
+
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
73921
|
+
import { mkdir as mkdir11, readFile as readFile13, readdir as readdir4, rename as rename8, unlink as unlink7, writeFile as writeFile6 } from "node:fs/promises";
|
|
73922
|
+
import { join as join11 } from "node:path";
|
|
73673
73923
|
var DEFAULT_AGENT_TOOLS = ["call.search", "call.inspect", "call.pay"];
|
|
73674
73924
|
var AGENT_GRANTS = ["read", "delegate", "allocate"];
|
|
73675
73925
|
var agentProfileShape = {
|
|
@@ -73699,7 +73949,7 @@ async function readAgentProfile(home, name, options = {}) {
|
|
|
73699
73949
|
const path = agentProfilePath(home, name);
|
|
73700
73950
|
let raw;
|
|
73701
73951
|
try {
|
|
73702
|
-
raw = await
|
|
73952
|
+
raw = await readFile13(path, "utf8");
|
|
73703
73953
|
} catch (error61) {
|
|
73704
73954
|
if (isMissingFile(error61)) {
|
|
73705
73955
|
throw new Error(`No agent named ${name}. Create it with vapi agent create ${name}.`);
|
|
@@ -73711,9 +73961,9 @@ async function readAgentProfile(home, name, options = {}) {
|
|
|
73711
73961
|
async function writeAgentProfile(home, profile, options = {}) {
|
|
73712
73962
|
const parsed = (options.schema ?? agentProfileSchema).parse(profile);
|
|
73713
73963
|
const directory = getVapiPaths(home).agentsDir;
|
|
73714
|
-
const path =
|
|
73964
|
+
const path = join11(directory, `${parsed.name}.json`);
|
|
73715
73965
|
await mkdir11(directory, { recursive: true, mode: 448 });
|
|
73716
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
73966
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes10(6).toString("hex")}.tmp`;
|
|
73717
73967
|
await writeFile6(temporaryPath, `${JSON.stringify(parsed, null, 2)}
|
|
73718
73968
|
`, {
|
|
73719
73969
|
encoding: "utf8",
|
|
@@ -73738,7 +73988,7 @@ async function listAgentProfiles(home, options = {}) {
|
|
|
73738
73988
|
try {
|
|
73739
73989
|
profiles.push(
|
|
73740
73990
|
(options.schema ?? agentProfileSchema).parse(
|
|
73741
|
-
JSON.parse(await
|
|
73991
|
+
JSON.parse(await readFile13(join11(directory, file2), "utf8"))
|
|
73742
73992
|
)
|
|
73743
73993
|
);
|
|
73744
73994
|
} catch {
|
|
@@ -73759,11 +74009,11 @@ async function removeAgentProfile(home, name) {
|
|
|
73759
74009
|
}
|
|
73760
74010
|
function agentProfilePath(home, name) {
|
|
73761
74011
|
const parsedName = walletNameSchema.parse(name);
|
|
73762
|
-
return
|
|
74012
|
+
return join11(getVapiPaths(home).agentsDir, `${parsedName}.json`);
|
|
73763
74013
|
}
|
|
73764
74014
|
|
|
73765
74015
|
// ../core/src/ceiling.ts
|
|
73766
|
-
import { randomBytes as
|
|
74016
|
+
import { randomBytes as randomBytes14 } from "node:crypto";
|
|
73767
74017
|
|
|
73768
74018
|
// ../core/src/authorization-state.ts
|
|
73769
74019
|
var EIP3009_AUTHORIZATION_STATE_ABI = [
|
|
@@ -73828,13 +74078,13 @@ function missingAuthorization(receipt) {
|
|
|
73828
74078
|
}
|
|
73829
74079
|
|
|
73830
74080
|
// ../core/src/movement.ts
|
|
73831
|
-
import { randomBytes as
|
|
73832
|
-
import { chmod as chmod4, mkdir as mkdir14, open as
|
|
73833
|
-
import { join as
|
|
74081
|
+
import { randomBytes as randomBytes13 } from "node:crypto";
|
|
74082
|
+
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";
|
|
74083
|
+
import { join as join12 } from "node:path";
|
|
73834
74084
|
|
|
73835
74085
|
// ../core/src/spend-policy.ts
|
|
73836
|
-
import { randomBytes as
|
|
73837
|
-
import { mkdir as mkdir12, open as
|
|
74086
|
+
import { randomBytes as randomBytes11 } from "node:crypto";
|
|
74087
|
+
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";
|
|
73838
74088
|
import { dirname as dirname8 } from "node:path";
|
|
73839
74089
|
var ledgerSchema = external_exports.object({
|
|
73840
74090
|
date: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
@@ -73905,7 +74155,7 @@ async function readSpendLedgerRows(path = getAgentCashPaths().ledger, now = /* @
|
|
|
73905
74155
|
async function readStoredSpendLedgerRows(path, now, allDays = false) {
|
|
73906
74156
|
let raw;
|
|
73907
74157
|
try {
|
|
73908
|
-
raw = await
|
|
74158
|
+
raw = await readFile14(path, "utf8");
|
|
73909
74159
|
} catch (error61) {
|
|
73910
74160
|
if (isMissingFile(error61)) return [];
|
|
73911
74161
|
throw error61;
|
|
@@ -74038,7 +74288,7 @@ async function reserveSpend(amountAtomic2, caps, options) {
|
|
|
74038
74288
|
{ amountAtomic: amountAtomic2, limitAtomic: perDayAtomic, spentAtomic: BigInt(spentAtomic), wallet }
|
|
74039
74289
|
);
|
|
74040
74290
|
}
|
|
74041
|
-
const reservationId = options?.reservationId ?? (options?.taskKey === void 0 ? void 0 :
|
|
74291
|
+
const reservationId = options?.reservationId ?? (options?.taskKey === void 0 ? void 0 : randomBytes11(16).toString("hex"));
|
|
74042
74292
|
const nextRow = {
|
|
74043
74293
|
date: utcDateKey(now),
|
|
74044
74294
|
spentAtomic: nextSpent.toString(),
|
|
@@ -74144,7 +74394,7 @@ async function writeLedgerAtomically(path, rows) {
|
|
|
74144
74394
|
...rows[0].reservations === void 0 ? {} : { reservations: rows[0].reservations }
|
|
74145
74395
|
} : { version: 1, rows };
|
|
74146
74396
|
await mkdir12(dirname8(path), { recursive: true, mode: 448 });
|
|
74147
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
74397
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes11(6).toString("hex")}.tmp`;
|
|
74148
74398
|
await writeFile7(temporaryPath, `${JSON.stringify(ledger, null, 2)}
|
|
74149
74399
|
`, {
|
|
74150
74400
|
encoding: "utf8",
|
|
@@ -74160,7 +74410,7 @@ async function withLedgerLock(path, operation) {
|
|
|
74160
74410
|
let handle;
|
|
74161
74411
|
while (!handle) {
|
|
74162
74412
|
try {
|
|
74163
|
-
handle = await
|
|
74413
|
+
handle = await open9(lockPath, "wx", 384);
|
|
74164
74414
|
} catch (error61) {
|
|
74165
74415
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) {
|
|
74166
74416
|
throw error61;
|
|
@@ -74181,7 +74431,7 @@ async function withLedgerLock(path, operation) {
|
|
|
74181
74431
|
}
|
|
74182
74432
|
async function removeStaleLock3(path) {
|
|
74183
74433
|
try {
|
|
74184
|
-
const metadata = await
|
|
74434
|
+
const metadata = await stat11(path);
|
|
74185
74435
|
if (Date.now() - metadata.mtimeMs > 3e4) {
|
|
74186
74436
|
await unlink8(path);
|
|
74187
74437
|
}
|
|
@@ -74193,8 +74443,8 @@ async function removeStaleLock3(path) {
|
|
|
74193
74443
|
}
|
|
74194
74444
|
|
|
74195
74445
|
// ../core/src/transfer.ts
|
|
74196
|
-
import { randomBytes as
|
|
74197
|
-
import { mkdir as mkdir13, open as
|
|
74446
|
+
import { randomBytes as randomBytes12, randomUUID } from "node:crypto";
|
|
74447
|
+
import { mkdir as mkdir13, open as open10, stat as stat12, unlink as unlink9 } from "node:fs/promises";
|
|
74198
74448
|
import { dirname as dirname9 } from "node:path";
|
|
74199
74449
|
|
|
74200
74450
|
// ../core/src/siblings.ts
|
|
@@ -74403,7 +74653,7 @@ async function transferBetweenAccounts(args) {
|
|
|
74403
74653
|
if (args.resume !== void 0) {
|
|
74404
74654
|
return await resumeTransfer(context, args.resume);
|
|
74405
74655
|
}
|
|
74406
|
-
const nonce = args.nonce ?? bytesToHex(
|
|
74656
|
+
const nonce = args.nonce ?? bytesToHex(randomBytes12(32));
|
|
74407
74657
|
if (!NONCE_PATTERN.test(nonce)) {
|
|
74408
74658
|
throw new TransferError(
|
|
74409
74659
|
"authorization_invalid",
|
|
@@ -74796,7 +75046,7 @@ async function withTransferLock(context, nonce, operation) {
|
|
|
74796
75046
|
let handle;
|
|
74797
75047
|
while (!handle) {
|
|
74798
75048
|
try {
|
|
74799
|
-
handle = await
|
|
75049
|
+
handle = await open10(lockPath, "wx", 384);
|
|
74800
75050
|
} catch (error61) {
|
|
74801
75051
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) throw error61;
|
|
74802
75052
|
await removeStaleTransferLock(lockPath, staleAfterMs);
|
|
@@ -74815,7 +75065,7 @@ async function withTransferLock(context, nonce, operation) {
|
|
|
74815
75065
|
}
|
|
74816
75066
|
async function removeStaleTransferLock(path, staleAfterMs) {
|
|
74817
75067
|
try {
|
|
74818
|
-
const metadata = await
|
|
75068
|
+
const metadata = await stat12(path);
|
|
74819
75069
|
if (Date.now() - metadata.mtimeMs > staleAfterMs) await unlink9(path);
|
|
74820
75070
|
} catch (error61) {
|
|
74821
75071
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "ENOENT")) throw error61;
|
|
@@ -75241,7 +75491,7 @@ async function listUnfinishedMovements(options) {
|
|
|
75241
75491
|
}
|
|
75242
75492
|
const summaries = [];
|
|
75243
75493
|
for (const name of names.filter((candidate) => candidate.endsWith(".json")).sort()) {
|
|
75244
|
-
const movement = parseMovement(JSON.parse(await
|
|
75494
|
+
const movement = parseMovement(JSON.parse(await readFile15(join12(directory, name), "utf8")));
|
|
75245
75495
|
if (options.from !== void 0 && !movement.legs.some((leg) => leg.from === options.from)) {
|
|
75246
75496
|
continue;
|
|
75247
75497
|
}
|
|
@@ -75272,7 +75522,7 @@ async function listUnfinishedMovementSnapshots(options) {
|
|
|
75272
75522
|
}
|
|
75273
75523
|
const snapshots = [];
|
|
75274
75524
|
for (const name of names.filter((candidate) => candidate.endsWith(".json")).sort()) {
|
|
75275
|
-
const movement = parseMovement(JSON.parse(await
|
|
75525
|
+
const movement = parseMovement(JSON.parse(await readFile15(join12(directory, name), "utf8")));
|
|
75276
75526
|
if (options.from !== void 0 && !movement.legs.some((leg) => leg.from === options.from)) {
|
|
75277
75527
|
continue;
|
|
75278
75528
|
}
|
|
@@ -75308,23 +75558,23 @@ async function movementHasOpenLeg(home, movement, from16) {
|
|
|
75308
75558
|
return false;
|
|
75309
75559
|
}
|
|
75310
75560
|
async function movementOpenEvidence(home, movement, from16) {
|
|
75311
|
-
let
|
|
75561
|
+
let open13 = false;
|
|
75312
75562
|
const signedFailedLegKeys = [];
|
|
75313
75563
|
for (const leg of movement.legs) {
|
|
75314
75564
|
if (from16 !== void 0 && leg.from !== from16) continue;
|
|
75315
|
-
if (isOpenMovementLeg(leg, "unsigned"))
|
|
75565
|
+
if (isOpenMovementLeg(leg, "unsigned")) open13 = true;
|
|
75316
75566
|
if (leg.status !== "failed") continue;
|
|
75317
75567
|
const journal = await readTransferJournal(home, leg.from, leg.nonce);
|
|
75318
75568
|
if (journal.signed) signedFailedLegKeys.push(movementTransferKey(leg.from, leg.nonce));
|
|
75319
|
-
if (isOpenMovementLeg(leg, journal.signed ? "signed" : "unsigned"))
|
|
75569
|
+
if (isOpenMovementLeg(leg, journal.signed ? "signed" : "unsigned")) open13 = true;
|
|
75320
75570
|
}
|
|
75321
|
-
return { open:
|
|
75571
|
+
return { open: open13, signedFailedLegKeys };
|
|
75322
75572
|
}
|
|
75323
75573
|
async function readMovement(home, id2) {
|
|
75324
75574
|
const safeId = parseMovementId(id2);
|
|
75325
75575
|
try {
|
|
75326
75576
|
return parseMovement(
|
|
75327
|
-
JSON.parse(await
|
|
75577
|
+
JSON.parse(await readFile15(join12(movementsDirectory(home), `${safeId}.json`), "utf8"))
|
|
75328
75578
|
);
|
|
75329
75579
|
} catch (error61) {
|
|
75330
75580
|
if (isMissingFile(error61)) {
|
|
@@ -76044,33 +76294,33 @@ function parseMovementId(value) {
|
|
|
76044
76294
|
return parsed.data;
|
|
76045
76295
|
}
|
|
76046
76296
|
function movementsDirectory(home) {
|
|
76047
|
-
return
|
|
76297
|
+
return join12(home, "movements");
|
|
76048
76298
|
}
|
|
76049
76299
|
function createMovementId() {
|
|
76050
|
-
return `mv_${
|
|
76300
|
+
return `mv_${randomBytes13(12).toString("hex")}`;
|
|
76051
76301
|
}
|
|
76052
76302
|
function createMovementNonce() {
|
|
76053
|
-
return bytesToHex(
|
|
76303
|
+
return bytesToHex(randomBytes13(32));
|
|
76054
76304
|
}
|
|
76055
76305
|
async function writeMovement(home, movement) {
|
|
76056
76306
|
const parsed = movementSchema.parse(movement);
|
|
76057
76307
|
const directory = movementsDirectory(home);
|
|
76058
76308
|
await mkdir14(directory, { recursive: true, mode: 448 });
|
|
76059
76309
|
await chmod4(directory, 448);
|
|
76060
|
-
const path =
|
|
76061
|
-
const temporary =
|
|
76310
|
+
const path = join12(directory, `${parsed.id}.json`);
|
|
76311
|
+
const temporary = join12(
|
|
76062
76312
|
directory,
|
|
76063
|
-
`.${parsed.id}.${process.pid}.${
|
|
76313
|
+
`.${parsed.id}.${process.pid}.${randomBytes13(6).toString("hex")}.tmp`
|
|
76064
76314
|
);
|
|
76065
76315
|
let handle;
|
|
76066
76316
|
try {
|
|
76067
|
-
handle = await
|
|
76317
|
+
handle = await open11(temporary, "wx", 384);
|
|
76068
76318
|
await handle.writeFile(serializeMovement(parsed), "utf8");
|
|
76069
76319
|
await handle.sync();
|
|
76070
76320
|
await handle.close();
|
|
76071
76321
|
handle = void 0;
|
|
76072
76322
|
await rename10(temporary, path);
|
|
76073
|
-
const directoryHandle = await
|
|
76323
|
+
const directoryHandle = await open11(directory, "r");
|
|
76074
76324
|
try {
|
|
76075
76325
|
await directoryHandle.sync();
|
|
76076
76326
|
} finally {
|
|
@@ -76290,7 +76540,7 @@ async function sweepAboveCeilingLocked(args) {
|
|
|
76290
76540
|
owner,
|
|
76291
76541
|
target,
|
|
76292
76542
|
amountAtomic: amountAtomic2.toString(),
|
|
76293
|
-
nonce: (args.randomNonce ?? (() => bytesToHex(
|
|
76543
|
+
nonce: (args.randomNonce ?? (() => bytesToHex(randomBytes14(32))))(),
|
|
76294
76544
|
createdAt: new Date(now()).toISOString(),
|
|
76295
76545
|
status: "planned"
|
|
76296
76546
|
};
|
|
@@ -77082,8 +77332,8 @@ function parseDecimal(value, scale) {
|
|
|
77082
77332
|
}
|
|
77083
77333
|
|
|
77084
77334
|
// ../core/src/swarm.ts
|
|
77085
|
-
import { readdir as readdir6, readFile as
|
|
77086
|
-
import { join as
|
|
77335
|
+
import { readdir as readdir6, readFile as readFile16, stat as stat13, unlink as unlink11 } from "node:fs/promises";
|
|
77336
|
+
import { join as join13 } from "node:path";
|
|
77087
77337
|
var SWARM_NAME_PATTERN = /^[a-z][a-z0-9-]{0,15}$/;
|
|
77088
77338
|
var SWARM_ROLE_PATTERN = /^[a-z][a-z0-9]{0,7}$/;
|
|
77089
77339
|
var DEFAULT_SWARM_MODEL = "venice/claude-sonnet-5";
|
|
@@ -77164,16 +77414,16 @@ var SwarmError = class extends Error {
|
|
|
77164
77414
|
code;
|
|
77165
77415
|
};
|
|
77166
77416
|
function swarmsDirectory(home) {
|
|
77167
|
-
return
|
|
77417
|
+
return join13(home, "swarms");
|
|
77168
77418
|
}
|
|
77169
77419
|
function swarmFilePath(home, name) {
|
|
77170
77420
|
assertName(name);
|
|
77171
|
-
return
|
|
77421
|
+
return join13(swarmsDirectory(home), `${name}.json`);
|
|
77172
77422
|
}
|
|
77173
77423
|
async function readSwarm(home, name) {
|
|
77174
77424
|
const path = swarmFilePath(home, name);
|
|
77175
77425
|
try {
|
|
77176
|
-
const swarm = parseSwarm(JSON.parse(await
|
|
77426
|
+
const swarm = parseSwarm(JSON.parse(await readFile16(path, "utf8")));
|
|
77177
77427
|
if (swarm.name !== name)
|
|
77178
77428
|
throw new SwarmError("invalid_swarm", "Swarm name does not match its file.");
|
|
77179
77429
|
return swarm;
|
|
@@ -77201,7 +77451,7 @@ async function writeSwarm(home, value) {
|
|
|
77201
77451
|
const bytes = `${JSON.stringify(swarm, null, 2)}
|
|
77202
77452
|
`;
|
|
77203
77453
|
try {
|
|
77204
|
-
if (await
|
|
77454
|
+
if (await readFile16(path, "utf8") === bytes) return;
|
|
77205
77455
|
} catch (error61) {
|
|
77206
77456
|
if (!isMissingFile(error61)) throw error61;
|
|
77207
77457
|
}
|
|
@@ -77216,7 +77466,7 @@ async function deleteSwarmFile(home, name) {
|
|
|
77216
77466
|
}
|
|
77217
77467
|
async function withSwarmLock(home, name, fn) {
|
|
77218
77468
|
assertName(name);
|
|
77219
|
-
const path =
|
|
77469
|
+
const path = join13(swarmsDirectory(home), `.${name}.lock`);
|
|
77220
77470
|
try {
|
|
77221
77471
|
return await withFileLock(path, fn, { lockedMessage: `Swarm ${name} is locked.` });
|
|
77222
77472
|
} catch (error61) {
|
|
@@ -77528,7 +77778,7 @@ async function swarmStatus(opts) {
|
|
|
77528
77778
|
);
|
|
77529
77779
|
let movementFiles;
|
|
77530
77780
|
try {
|
|
77531
|
-
movementFiles = await readdir6(
|
|
77781
|
+
movementFiles = await readdir6(join13(home, "movements"));
|
|
77532
77782
|
} catch (error61) {
|
|
77533
77783
|
if (!isMissingFile(error61)) throw error61;
|
|
77534
77784
|
movementFiles = [];
|
|
@@ -77585,11 +77835,11 @@ async function swarmStatus(opts) {
|
|
|
77585
77835
|
})
|
|
77586
77836
|
);
|
|
77587
77837
|
const accounts = new Set(swarmAccountNames(swarm));
|
|
77588
|
-
const
|
|
77838
|
+
const open13 = [];
|
|
77589
77839
|
for (const summary2 of await listUnfinishedMovements({ home })) {
|
|
77590
77840
|
const movement = await readMovement(home, summary2.id);
|
|
77591
77841
|
if (movement.treasury === swarm.treasury.account || movement.legs.some((leg) => accounts.has(leg.from) || accounts.has(leg.to))) {
|
|
77592
|
-
|
|
77842
|
+
open13.push(summary2);
|
|
77593
77843
|
}
|
|
77594
77844
|
}
|
|
77595
77845
|
return {
|
|
@@ -77598,7 +77848,7 @@ async function swarmStatus(opts) {
|
|
|
77598
77848
|
strategy: swarm.policy.strategy,
|
|
77599
77849
|
treasury,
|
|
77600
77850
|
members: members2,
|
|
77601
|
-
openMovements:
|
|
77851
|
+
openMovements: open13.sort(
|
|
77602
77852
|
(a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id)
|
|
77603
77853
|
)
|
|
77604
77854
|
};
|
|
@@ -77697,7 +77947,7 @@ async function assertNoConflicts(home, name, accounts) {
|
|
|
77697
77947
|
}
|
|
77698
77948
|
async function profileExists(home, account) {
|
|
77699
77949
|
try {
|
|
77700
|
-
await
|
|
77950
|
+
await stat13(join13(getVapiPaths(home).agentsDir, `${account}.json`));
|
|
77701
77951
|
return true;
|
|
77702
77952
|
} catch (error61) {
|
|
77703
77953
|
if (isMissingFile(error61)) return false;
|
|
@@ -77710,7 +77960,7 @@ async function refuseTreasuryProfile(home, account) {
|
|
|
77710
77960
|
}
|
|
77711
77961
|
|
|
77712
77962
|
// ../core/src/x402-pay.ts
|
|
77713
|
-
import { randomBytes as
|
|
77963
|
+
import { randomBytes as randomBytes15, randomUUID as randomUUID2 } from "node:crypto";
|
|
77714
77964
|
|
|
77715
77965
|
// ../core/src/run-budget.ts
|
|
77716
77966
|
var RunBudgetError = class extends Error {
|
|
@@ -77751,13 +78001,13 @@ function createRunBudget(args) {
|
|
|
77751
78001
|
// ../core/src/support-report.ts
|
|
77752
78002
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
77753
78003
|
import { arch, platform, release } from "node:os";
|
|
77754
|
-
import { join as
|
|
77755
|
-
var VAPI_CLIENT_VERSION = "0.
|
|
78004
|
+
import { join as join14 } from "node:path";
|
|
78005
|
+
var VAPI_CLIENT_VERSION = "0.13.0";
|
|
77756
78006
|
async function createSupportReport(options) {
|
|
77757
78007
|
const message = options.message.trim();
|
|
77758
78008
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
77759
78009
|
const paths = getVapiPaths();
|
|
77760
|
-
const reportsDirectory = options.reportsDirectory ??
|
|
78010
|
+
const reportsDirectory = options.reportsDirectory ?? join14(paths.directory, "reports");
|
|
77761
78011
|
const receipts = await readReceipts(options.receiptsPath ?? paths.receipts, { limit: 5 });
|
|
77762
78012
|
const system = options.systemInfo ?? defaultSystemInfo();
|
|
77763
78013
|
const report = {
|
|
@@ -77787,7 +78037,7 @@ async function createSupportReport(options) {
|
|
|
77787
78037
|
};
|
|
77788
78038
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
77789
78039
|
const timestamp = now.toISOString();
|
|
77790
|
-
const path =
|
|
78040
|
+
const path = join14(reportsDirectory, `${sanitizeTimestamp(timestamp)}.json`);
|
|
77791
78041
|
await mkdir15(reportsDirectory, { recursive: true, mode: 448 });
|
|
77792
78042
|
const serialized = `${JSON.stringify(report, null, 2)}
|
|
77793
78043
|
`;
|
|
@@ -77983,7 +78233,7 @@ async function completeX402Payment(args) {
|
|
|
77983
78233
|
throw walletCapError(error61, quote.amountAtomic, args);
|
|
77984
78234
|
}
|
|
77985
78235
|
} else {
|
|
77986
|
-
reservationId = args.paymentId ?? `x402_${
|
|
78236
|
+
reservationId = args.paymentId ?? `x402_${randomBytes15(12).toString("hex")}`;
|
|
77987
78237
|
let reservation;
|
|
77988
78238
|
try {
|
|
77989
78239
|
reservation = await reserveSpend(quote.amountAtomic, args.caps, {
|
|
@@ -79384,8 +79634,8 @@ function freezeScopeTerms(structuredInput, briefInput) {
|
|
|
79384
79634
|
}
|
|
79385
79635
|
|
|
79386
79636
|
// ../core/src/tasks/scope-bindings.ts
|
|
79387
|
-
import { readFile as
|
|
79388
|
-
import { join as
|
|
79637
|
+
import { readFile as readFile17 } from "node:fs/promises";
|
|
79638
|
+
import { join as join15 } from "node:path";
|
|
79389
79639
|
|
|
79390
79640
|
// ../core/src/tasks/chain-port.ts
|
|
79391
79641
|
var TasksChainError = class extends Error {
|
|
@@ -79960,7 +80210,7 @@ var messageSchema = external_exports.looseObject({
|
|
|
79960
80210
|
})
|
|
79961
80211
|
)
|
|
79962
80212
|
});
|
|
79963
|
-
var
|
|
80213
|
+
var fileSchema2 = external_exports.looseObject({
|
|
79964
80214
|
id: uuidSchema,
|
|
79965
80215
|
purpose: workFilePurposeSchema,
|
|
79966
80216
|
fileName: external_exports.string(),
|
|
@@ -80266,11 +80516,11 @@ var tasksResponseSchemas = {
|
|
|
80266
80516
|
observedAt: isoDateTimeSchema
|
|
80267
80517
|
}),
|
|
80268
80518
|
createUpload: external_exports.looseObject({
|
|
80269
|
-
file:
|
|
80519
|
+
file: fileSchema2.extend({ state: external_exports.literal("pending"), sha256: external_exports.null() }),
|
|
80270
80520
|
uploadUrl: external_exports.url()
|
|
80271
80521
|
}),
|
|
80272
80522
|
finalizeUpload: external_exports.looseObject({
|
|
80273
|
-
file:
|
|
80523
|
+
file: fileSchema2.extend({
|
|
80274
80524
|
state: external_exports.literal("ready"),
|
|
80275
80525
|
sha256: external_exports.string().regex(/^[0-9a-fA-F]{64}$/)
|
|
80276
80526
|
})
|
|
@@ -80878,10 +81128,10 @@ function key(identity) {
|
|
|
80878
81128
|
return `${identity.orderId}:${identity.trancheOrdinal}:${identity.scopeVersion}:${identity.termsHash.toLowerCase()}:${identity.self.toLowerCase()}`;
|
|
80879
81129
|
}
|
|
80880
81130
|
function createScopeBindings(home) {
|
|
80881
|
-
const path =
|
|
81131
|
+
const path = join15(home, "tasks", "scope-bindings.json");
|
|
80882
81132
|
async function read() {
|
|
80883
81133
|
try {
|
|
80884
|
-
return storeSchema.parse(JSON.parse(await
|
|
81134
|
+
return storeSchema.parse(JSON.parse(await readFile17(path, "utf8")));
|
|
80885
81135
|
} catch (error61) {
|
|
80886
81136
|
if (error61 instanceof Error && "code" in error61 && error61.code === "ENOENT")
|
|
80887
81137
|
return { version: 1, bindings: {} };
|
|
@@ -81562,7 +81812,7 @@ function createTasksChain(options) {
|
|
|
81562
81812
|
const { account, client, pending, rpcFor } = options;
|
|
81563
81813
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
81564
81814
|
const sleep = options.sleep ?? ((ms) => new Promise((resolve3) => setTimeout(resolve3, ms)));
|
|
81565
|
-
const
|
|
81815
|
+
const randomBytes18 = options.randomBytes ?? cryptoRandomBytes2;
|
|
81566
81816
|
const confirmations = options.confirmations ?? 2;
|
|
81567
81817
|
if (!Number.isSafeInteger(confirmations) || confirmations < 1)
|
|
81568
81818
|
throw new TasksChainError("Tasks confirmations must be a positive integer.", false, {
|
|
@@ -82171,7 +82421,7 @@ function createTasksChain(options) {
|
|
|
82171
82421
|
await verifyClone(rpcFor(ready.chainId), expected, true);
|
|
82172
82422
|
if (validBefore <= BigInt(Math.floor(now().getTime() / 1e3)))
|
|
82173
82423
|
throw new TasksValidationError("The task funding offer has expired.");
|
|
82174
|
-
const bytes =
|
|
82424
|
+
const bytes = randomBytes18(32);
|
|
82175
82425
|
if (bytes.length !== 32)
|
|
82176
82426
|
throw new TasksValidationError(
|
|
82177
82427
|
"Funding authorization randomness must contain 32 bytes."
|
|
@@ -82449,8 +82699,8 @@ function createTasksRpcFor(config2, options = {}) {
|
|
|
82449
82699
|
}
|
|
82450
82700
|
|
|
82451
82701
|
// ../core/src/tasks/pending-transactions.ts
|
|
82452
|
-
import { readFile as
|
|
82453
|
-
import { join as
|
|
82702
|
+
import { readFile as readFile18 } from "node:fs/promises";
|
|
82703
|
+
import { join as join16 } from "node:path";
|
|
82454
82704
|
var hex3 = external_exports.string().regex(/^0x(?:[0-9a-fA-F]{2})+$/).transform((v) => v);
|
|
82455
82705
|
var hash4 = external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/).transform((v) => v);
|
|
82456
82706
|
var step = external_exports.enum([
|
|
@@ -82532,11 +82782,11 @@ function validCheckpointStep(storedStep, response) {
|
|
|
82532
82782
|
}[response.operation.kind];
|
|
82533
82783
|
}
|
|
82534
82784
|
function createPendingTransactions(home) {
|
|
82535
|
-
const path =
|
|
82785
|
+
const path = join16(home, "tasks", "pending.json");
|
|
82536
82786
|
const lockPath = `${path}.lock`;
|
|
82537
82787
|
const read = async () => {
|
|
82538
82788
|
try {
|
|
82539
|
-
const state = stateSchema.parse(JSON.parse(await
|
|
82789
|
+
const state = stateSchema.parse(JSON.parse(await readFile18(path, "utf8")));
|
|
82540
82790
|
for (const [key2, value] of Object.entries(state.checkpoints)) {
|
|
82541
82791
|
const separator = key2.indexOf(":");
|
|
82542
82792
|
const operationId = key2.slice(0, separator);
|
|
@@ -82599,7 +82849,7 @@ function createPendingTransactions(home) {
|
|
|
82599
82849
|
},
|
|
82600
82850
|
withStepLock(operationId, step2, fn) {
|
|
82601
82851
|
return withFileLock(
|
|
82602
|
-
|
|
82852
|
+
join16(
|
|
82603
82853
|
home,
|
|
82604
82854
|
"tasks",
|
|
82605
82855
|
`step-${encodeURIComponent(operationId)}-${encodeURIComponent(step2)}.lock`
|
|
@@ -82611,13 +82861,13 @@ function createPendingTransactions(home) {
|
|
|
82611
82861
|
external_exports.number().int().positive().parse(chainId);
|
|
82612
82862
|
address3.parse(signer);
|
|
82613
82863
|
return withFileLock(
|
|
82614
|
-
|
|
82864
|
+
join16(home, "tasks", `signer-${chainId}-${signer.toLowerCase()}.lock`),
|
|
82615
82865
|
fn
|
|
82616
82866
|
);
|
|
82617
82867
|
},
|
|
82618
82868
|
withFundingLock(milestoneId, fn) {
|
|
82619
82869
|
milestoneKey(milestoneId);
|
|
82620
|
-
return withFileLock(
|
|
82870
|
+
return withFileLock(join16(home, "tasks", `fund-${milestoneId}.lock`), fn);
|
|
82621
82871
|
},
|
|
82622
82872
|
async nextNonce(chainId, signer) {
|
|
82623
82873
|
external_exports.number().int().positive().parse(chainId);
|
|
@@ -83443,7 +83693,7 @@ function policyAtomic(value) {
|
|
|
83443
83693
|
}
|
|
83444
83694
|
|
|
83445
83695
|
// ../core/src/tasks/operation-support.ts
|
|
83446
|
-
import { readFile as
|
|
83696
|
+
import { readFile as readFile19, stat as stat14 } from "node:fs/promises";
|
|
83447
83697
|
import { basename as basename3, extname } from "node:path";
|
|
83448
83698
|
var TaskOperationError = class extends Error {
|
|
83449
83699
|
constructor(code, message, manifestHash) {
|
|
@@ -83611,7 +83861,7 @@ function parseTaskDuration(text, now) {
|
|
|
83611
83861
|
async function readTaskFile(path) {
|
|
83612
83862
|
let details;
|
|
83613
83863
|
try {
|
|
83614
|
-
details = await
|
|
83864
|
+
details = await stat14(path);
|
|
83615
83865
|
} catch {
|
|
83616
83866
|
throw new TaskInputError(`Task file ${JSON.stringify(path)} could not be read.`);
|
|
83617
83867
|
}
|
|
@@ -83635,7 +83885,7 @@ async function readTaskFile(path) {
|
|
|
83635
83885
|
const contentType = types[extname(path).toLowerCase()];
|
|
83636
83886
|
if (!contentType)
|
|
83637
83887
|
throw new TaskInputError("Task files must be images, PDF, ZIP, text, Markdown, JSON or CSV.");
|
|
83638
|
-
const bytes = await
|
|
83888
|
+
const bytes = await readFile19(path);
|
|
83639
83889
|
if (bytes.length < TASK_LIMITS.uploadBytesMin || bytes.length > TASK_LIMITS.uploadBytesMax)
|
|
83640
83890
|
throw new TaskInputError("Task files must contain between 1 byte and 50 MiB.");
|
|
83641
83891
|
return {
|
|
@@ -84434,7 +84684,7 @@ async function resolveUnmatchedTaskOperation(context, input2) {
|
|
|
84434
84684
|
}
|
|
84435
84685
|
|
|
84436
84686
|
// ../core/src/searches.ts
|
|
84437
|
-
import { mkdir as mkdir16, open as
|
|
84687
|
+
import { mkdir as mkdir16, open as open12, readFile as readFile20 } from "node:fs/promises";
|
|
84438
84688
|
import { dirname as dirname10 } from "node:path";
|
|
84439
84689
|
var searchEventSchema = external_exports.strictObject({
|
|
84440
84690
|
timestamp: external_exports.iso.datetime(),
|
|
@@ -84456,7 +84706,7 @@ function parseSearchEvent(value) {
|
|
|
84456
84706
|
async function appendSearchEvent(event, path = getVapiPaths().searches) {
|
|
84457
84707
|
const parsed = parseSearchEvent(event);
|
|
84458
84708
|
await mkdir16(dirname10(path), { recursive: true, mode: 448 });
|
|
84459
|
-
const handle = await
|
|
84709
|
+
const handle = await open12(path, "a", 384);
|
|
84460
84710
|
try {
|
|
84461
84711
|
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
84462
84712
|
`, "utf8");
|
|
@@ -84468,7 +84718,7 @@ async function appendSearchEvent(event, path = getVapiPaths().searches) {
|
|
|
84468
84718
|
async function readSearchEvents(path = getVapiPaths().searches) {
|
|
84469
84719
|
let raw;
|
|
84470
84720
|
try {
|
|
84471
|
-
raw = await
|
|
84721
|
+
raw = await readFile20(path, "utf8");
|
|
84472
84722
|
} catch (error61) {
|
|
84473
84723
|
if (isMissingFile(error61)) return [];
|
|
84474
84724
|
throw error61;
|
|
@@ -85370,9 +85620,9 @@ function csvCell(value) {
|
|
|
85370
85620
|
}
|
|
85371
85621
|
|
|
85372
85622
|
// ../core/src/swarm-capital.ts
|
|
85373
|
-
import { createHash as createHash5, randomBytes as
|
|
85374
|
-
import { readFile as
|
|
85375
|
-
import { join as
|
|
85623
|
+
import { createHash as createHash5, randomBytes as randomBytes16 } from "node:crypto";
|
|
85624
|
+
import { readFile as readFile21, unlink as unlink12 } from "node:fs/promises";
|
|
85625
|
+
import { join as join17 } from "node:path";
|
|
85376
85626
|
var movementIdSchema3 = external_exports.string().regex(/^mv_[A-Za-z0-9_-]{8,128}$/u);
|
|
85377
85627
|
var amountSchema2 = external_exports.string().regex(/^\d+\.\d{2}$/u);
|
|
85378
85628
|
var requestIdSchema = external_exports.string().min(1).max(512);
|
|
@@ -86253,7 +86503,7 @@ async function readDelegationRecord(home, movementId) {
|
|
|
86253
86503
|
const safeId = runRecordMovementId(movementId);
|
|
86254
86504
|
try {
|
|
86255
86505
|
const record2 = delegationRecordSchema.parse(
|
|
86256
|
-
JSON.parse(await
|
|
86506
|
+
JSON.parse(await readFile21(delegationRecordPath(home, safeId), "utf8"))
|
|
86257
86507
|
);
|
|
86258
86508
|
if (record2.movementId !== safeId) {
|
|
86259
86509
|
throw new SwarmError(
|
|
@@ -86280,7 +86530,7 @@ async function readTreasuryRequestRecord(home, movementId) {
|
|
|
86280
86530
|
const safeId = runRecordMovementId(movementId);
|
|
86281
86531
|
try {
|
|
86282
86532
|
const record2 = treasuryRequestRecordSchema.parse(
|
|
86283
|
-
JSON.parse(await
|
|
86533
|
+
JSON.parse(await readFile21(treasuryRequestRecordPath(home, safeId), "utf8"))
|
|
86284
86534
|
);
|
|
86285
86535
|
if (record2.movementId !== safeId) {
|
|
86286
86536
|
throw new SwarmError(
|
|
@@ -86311,18 +86561,18 @@ function runRecordMovementId(value) {
|
|
|
86311
86561
|
return parsed.data;
|
|
86312
86562
|
}
|
|
86313
86563
|
function treasuryRequestRecordPath(home, movementId) {
|
|
86314
|
-
return
|
|
86564
|
+
return join17(home, "runs", "requests", `${movementId}.json`);
|
|
86315
86565
|
}
|
|
86316
86566
|
function delegationRecordPath(home, movementId) {
|
|
86317
|
-
return
|
|
86567
|
+
return join17(home, "runs", "delegations", `${movementId}.json`);
|
|
86318
86568
|
}
|
|
86319
86569
|
function legacyFundingProgressPath(home, name) {
|
|
86320
|
-
return
|
|
86570
|
+
return join17(home, "swarms", `.${name}.funding`);
|
|
86321
86571
|
}
|
|
86322
86572
|
async function readLegacyFundingProgress(home, name) {
|
|
86323
86573
|
try {
|
|
86324
86574
|
const progress = legacyFundingProgressSchema.parse(
|
|
86325
|
-
JSON.parse(await
|
|
86575
|
+
JSON.parse(await readFile21(legacyFundingProgressPath(home, name), "utf8"))
|
|
86326
86576
|
);
|
|
86327
86577
|
if (progress.name !== name) {
|
|
86328
86578
|
throw new SwarmError("invalid_swarm", `Invalid funding progress for swarm ${name}.`);
|
|
@@ -86551,7 +86801,7 @@ async function optionalMovement(home, id2) {
|
|
|
86551
86801
|
}
|
|
86552
86802
|
}
|
|
86553
86803
|
function nextMovementId(deps) {
|
|
86554
|
-
return movementIdSchema3.parse(deps.randomId?.() ?? `mv_${
|
|
86804
|
+
return movementIdSchema3.parse(deps.randomId?.() ?? `mv_${randomBytes16(12).toString("hex")}`);
|
|
86555
86805
|
}
|
|
86556
86806
|
async function executeRecordedMovement(id2, plan, deps, home, options = {}) {
|
|
86557
86807
|
try {
|
|
@@ -86967,7 +87217,7 @@ async function removeMemberLocked(home, swarm, account) {
|
|
|
86967
87217
|
}
|
|
86968
87218
|
|
|
86969
87219
|
// ../core/src/status.ts
|
|
86970
|
-
import { join as
|
|
87220
|
+
import { join as join18 } from "node:path";
|
|
86971
87221
|
var STATUS_TIMEOUT_MS = 2e3;
|
|
86972
87222
|
async function buildStatus(deps) {
|
|
86973
87223
|
const timers = deps.timers ?? { setTimeout, clearTimeout };
|
|
@@ -87023,7 +87273,7 @@ function formatUsdAmount(value) {
|
|
|
87023
87273
|
}
|
|
87024
87274
|
async function readVaultStatus(deps) {
|
|
87025
87275
|
const store = deps.secrets.description.replace(/^the /u, "");
|
|
87026
|
-
const path =
|
|
87276
|
+
const path = join18(deps.home, "vault.json");
|
|
87027
87277
|
let file2;
|
|
87028
87278
|
try {
|
|
87029
87279
|
file2 = await readVaultFileUnlocked(path);
|
|
@@ -87457,8 +87707,8 @@ function isRecord4(value) {
|
|
|
87457
87707
|
|
|
87458
87708
|
// src/cli.ts
|
|
87459
87709
|
import { spawn as spawn5 } from "node:child_process";
|
|
87460
|
-
import { stat as
|
|
87461
|
-
import { join as
|
|
87710
|
+
import { stat as stat18 } from "node:fs/promises";
|
|
87711
|
+
import { join as join30 } from "node:path";
|
|
87462
87712
|
import { createInterface as createInterface3 } from "node:readline/promises";
|
|
87463
87713
|
|
|
87464
87714
|
// ../core/src/member-bundle.ts
|
|
@@ -87735,7 +87985,7 @@ function assertKeyMatchesAddress(bundle) {
|
|
|
87735
87985
|
}
|
|
87736
87986
|
|
|
87737
87987
|
// ../core/src/api-key.ts
|
|
87738
|
-
import { chmod as chmod5, mkdir as mkdir17, readFile as
|
|
87988
|
+
import { chmod as chmod5, mkdir as mkdir17, readFile as readFile22, rename as rename11, writeFile as writeFile9 } from "node:fs/promises";
|
|
87739
87989
|
import { dirname as dirname11 } from "node:path";
|
|
87740
87990
|
var API_KEY_PREFIX = "vapi_sk_";
|
|
87741
87991
|
var API_KEY_PATTERN = /^vapi_sk_[A-Za-z0-9_-]{16,128}$/;
|
|
@@ -87831,7 +88081,7 @@ async function readConfigApiKey(path) {
|
|
|
87831
88081
|
async function readConfigRecord(path) {
|
|
87832
88082
|
let raw;
|
|
87833
88083
|
try {
|
|
87834
|
-
raw = await
|
|
88084
|
+
raw = await readFile22(path, "utf8");
|
|
87835
88085
|
} catch (error61) {
|
|
87836
88086
|
if (isMissingFile(error61)) return void 0;
|
|
87837
88087
|
throw error61;
|
|
@@ -90501,8 +90751,8 @@ function exactPriceFact(value) {
|
|
|
90501
90751
|
}
|
|
90502
90752
|
|
|
90503
90753
|
// ../mcp/src/agent/runtime.ts
|
|
90504
|
-
import { mkdir as mkdir18, readFile as
|
|
90505
|
-
import { join as
|
|
90754
|
+
import { mkdir as mkdir18, readFile as readFile23, readdir as readdir7, rm as rm2 } from "node:fs/promises";
|
|
90755
|
+
import { join as join19 } from "node:path";
|
|
90506
90756
|
|
|
90507
90757
|
// ../mcp/src/agent/run.ts
|
|
90508
90758
|
var loopSearchResultSchema = external_exports.array(
|
|
@@ -91803,19 +92053,19 @@ var runRecordSchema = external_exports.strictObject({
|
|
|
91803
92053
|
detail: external_exports.string().optional()
|
|
91804
92054
|
});
|
|
91805
92055
|
function runsDirectory(home) {
|
|
91806
|
-
return
|
|
92056
|
+
return join19(home, "runs");
|
|
91807
92057
|
}
|
|
91808
92058
|
function runRecordPath(home, runId) {
|
|
91809
92059
|
assertRunId(runId);
|
|
91810
|
-
return
|
|
92060
|
+
return join19(runsDirectory(home), `${runId}.json`);
|
|
91811
92061
|
}
|
|
91812
92062
|
function runLogPath(home, runId) {
|
|
91813
92063
|
assertRunId(runId);
|
|
91814
|
-
return
|
|
92064
|
+
return join19(runsDirectory(home), `${runId}.log`);
|
|
91815
92065
|
}
|
|
91816
92066
|
function runResultPath(home, runId) {
|
|
91817
92067
|
assertRunId(runId);
|
|
91818
|
-
return
|
|
92068
|
+
return join19(runsDirectory(home), `${runId}.result.json`);
|
|
91819
92069
|
}
|
|
91820
92070
|
async function writeRunRecord(home, record2) {
|
|
91821
92071
|
const path = runRecordPath(home, record2.runId);
|
|
@@ -91826,7 +92076,7 @@ async function writeRunRecord(home, record2) {
|
|
|
91826
92076
|
async function readRunRecord(home, runId) {
|
|
91827
92077
|
const path = runRecordPath(home, runId);
|
|
91828
92078
|
try {
|
|
91829
|
-
return runRecordSchema.parse(JSON.parse(await
|
|
92079
|
+
return runRecordSchema.parse(JSON.parse(await readFile23(path, "utf8")));
|
|
91830
92080
|
} catch (error61) {
|
|
91831
92081
|
if (isMissingFile3(error61)) return void 0;
|
|
91832
92082
|
throw error61;
|
|
@@ -91846,7 +92096,7 @@ async function listRunRecords(home, filter = {}) {
|
|
|
91846
92096
|
if (match === null) continue;
|
|
91847
92097
|
try {
|
|
91848
92098
|
const record2 = runRecordSchema.parse(
|
|
91849
|
-
JSON.parse(await
|
|
92099
|
+
JSON.parse(await readFile23(join19(runsDirectory(home), file2), "utf8"))
|
|
91850
92100
|
);
|
|
91851
92101
|
if (record2.runId !== match[1]) continue;
|
|
91852
92102
|
if (filter.swarm !== void 0 && record2.member.swarm !== filter.swarm) continue;
|
|
@@ -92123,7 +92373,7 @@ async function stopRun(args) {
|
|
|
92123
92373
|
}
|
|
92124
92374
|
}
|
|
92125
92375
|
function memberRunLockPath(home, account) {
|
|
92126
|
-
return
|
|
92376
|
+
return join19(runsDirectory(home), `.member-${account}.lock`);
|
|
92127
92377
|
}
|
|
92128
92378
|
function summarizeRunRecord(record2) {
|
|
92129
92379
|
return {
|
|
@@ -95727,8 +95977,8 @@ function rgbToAnsi256(red, green, blue) {
|
|
|
95727
95977
|
}
|
|
95728
95978
|
|
|
95729
95979
|
// src/accounts.ts
|
|
95730
|
-
import { readFile as
|
|
95731
|
-
import { join as
|
|
95980
|
+
import { readFile as readFile25, stat as stat16 } from "node:fs/promises";
|
|
95981
|
+
import { join as join22 } from "node:path";
|
|
95732
95982
|
|
|
95733
95983
|
// src/dashboard.ts
|
|
95734
95984
|
import { resolve as resolve2 } from "node:path";
|
|
@@ -95739,7 +95989,12 @@ var PROBE_MODES = ["origin", "endpoint", "openapi"];
|
|
|
95739
95989
|
var PAYOUT_CHAIN_ID = "eip155:8453";
|
|
95740
95990
|
var PAYOUT_STATEMENT = "Confirm this wallet receives vAPI Call payouts";
|
|
95741
95991
|
var CLAIM_STATEMENT_PREFIX = "Claim the vAPI Call listings served from";
|
|
95742
|
-
|
|
95992
|
+
function apiKeyConsoleUrl(baseUrl) {
|
|
95993
|
+
const url2 = listingsUrl(baseUrl, "/connect");
|
|
95994
|
+
url2.search = "advanced=keys";
|
|
95995
|
+
url2.hash = "api-keys";
|
|
95996
|
+
return url2;
|
|
95997
|
+
}
|
|
95743
95998
|
var RegistryApiError = class extends Error {
|
|
95744
95999
|
constructor(status, message, body) {
|
|
95745
96000
|
super(message);
|
|
@@ -95899,7 +96154,7 @@ async function registryError(response, baseUrl) {
|
|
|
95899
96154
|
[
|
|
95900
96155
|
"The vAPI API key was rejected.",
|
|
95901
96156
|
detail,
|
|
95902
|
-
`Create a key in the console at ${
|
|
96157
|
+
`Create a key in the console at ${apiKeyConsoleUrl(baseUrl).href} and store it with vapi auth set-key.`
|
|
95903
96158
|
].filter(Boolean).join(" "),
|
|
95904
96159
|
body
|
|
95905
96160
|
);
|
|
@@ -96400,12 +96655,12 @@ function shellQuote2(value) {
|
|
|
96400
96655
|
}
|
|
96401
96656
|
|
|
96402
96657
|
// src/status.ts
|
|
96403
|
-
import { stat as
|
|
96658
|
+
import { stat as stat15 } from "node:fs/promises";
|
|
96404
96659
|
import { homedir as homedir2 } from "node:os";
|
|
96405
96660
|
import { sep } from "node:path";
|
|
96406
96661
|
|
|
96407
96662
|
// ../core/src/cloud-backup.ts
|
|
96408
|
-
import { join as
|
|
96663
|
+
import { join as join21 } from "node:path";
|
|
96409
96664
|
|
|
96410
96665
|
// ../core/src/backup.ts
|
|
96411
96666
|
import {
|
|
@@ -96428,11 +96683,11 @@ import {
|
|
|
96428
96683
|
mkdir as mkdir19,
|
|
96429
96684
|
mkdtemp,
|
|
96430
96685
|
open as openFile,
|
|
96431
|
-
readFile as
|
|
96686
|
+
readFile as readFile24,
|
|
96432
96687
|
readdir as readdir8,
|
|
96433
96688
|
rm as rm3
|
|
96434
96689
|
} from "node:fs/promises";
|
|
96435
|
-
import { dirname as dirname12, join as
|
|
96690
|
+
import { dirname as dirname12, join as join20 } from "node:path";
|
|
96436
96691
|
var ERROR_MESSAGES = {
|
|
96437
96692
|
backup_too_large: "Backup envelope exceeds 65,536 bytes.",
|
|
96438
96693
|
backup_open_failed: "Unable to open backup.",
|
|
@@ -96715,8 +96970,8 @@ async function createBackup(options) {
|
|
|
96715
96970
|
assertDevice(options.device);
|
|
96716
96971
|
assertOwnerKey(options.ownerKey);
|
|
96717
96972
|
const createdAt = readCreatedAt(options.now ?? (() => /* @__PURE__ */ new Date()));
|
|
96718
|
-
const
|
|
96719
|
-
const nonce = readRandomBytes(
|
|
96973
|
+
const randomBytes18 = options.randomBytes ?? cryptoRandomBytes3;
|
|
96974
|
+
const nonce = readRandomBytes(randomBytes18, 12);
|
|
96720
96975
|
const salt = encodeBase64Url(options.ownerKey.salt);
|
|
96721
96976
|
const kdf = options.ownerKey.kdf === "hkdf-sha256" ? { name: "hkdf-sha256", salt } : { name: "scrypt", salt, N: SCRYPT_N2, r: SCRYPT_R2, p: SCRYPT_P2 };
|
|
96722
96977
|
const cipher = { name: CIPHER_NAME, nonce: encodeBase64Url(nonce) };
|
|
@@ -96910,7 +97165,7 @@ async function exportBackupSource(options) {
|
|
|
96910
97165
|
var BackupSnapshotChangedError = class extends Error {
|
|
96911
97166
|
};
|
|
96912
97167
|
async function exportBackupSourceAttempt(options, networks) {
|
|
96913
|
-
const path =
|
|
97168
|
+
const path = join20(options.store.home, "vault.json");
|
|
96914
97169
|
const { phrase, file: file2, accounts } = await withVaultLock(path, async () => {
|
|
96915
97170
|
const [phrase2, vault, file3] = await Promise.all([
|
|
96916
97171
|
exportVaultPhrase({ path, key: options.vaultKey }),
|
|
@@ -97046,16 +97301,16 @@ async function restoreBackupPlaintext(options) {
|
|
|
97046
97301
|
} catch {
|
|
97047
97302
|
throw new BackupError("backup_invalid_input");
|
|
97048
97303
|
}
|
|
97049
|
-
const vaultPath2 =
|
|
97050
|
-
const registryPath =
|
|
97304
|
+
const vaultPath2 = join20(options.home, "vault.json");
|
|
97305
|
+
const registryPath = join20(options.home, "wallets.json");
|
|
97051
97306
|
let stagingHome;
|
|
97052
97307
|
let beforePublishError;
|
|
97053
97308
|
let afterPublishError;
|
|
97054
97309
|
try {
|
|
97055
97310
|
await mkdir19(options.home, { recursive: true, mode: 448 });
|
|
97056
|
-
stagingHome = await mkdtemp(
|
|
97057
|
-
const stagedVaultPath =
|
|
97058
|
-
const stagedRegistryPath =
|
|
97311
|
+
stagingHome = await mkdtemp(join20(options.home, ".backup-restore-"));
|
|
97312
|
+
const stagedVaultPath = join20(stagingHome, "vault.json");
|
|
97313
|
+
const stagedRegistryPath = join20(stagingHome, "wallets.json");
|
|
97059
97314
|
await createVault({
|
|
97060
97315
|
path: stagedVaultPath,
|
|
97061
97316
|
key: options.vaultKey,
|
|
@@ -97114,7 +97369,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
97114
97369
|
protected: plaintext.protected,
|
|
97115
97370
|
networks: [...plaintext.registry.networks]
|
|
97116
97371
|
};
|
|
97117
|
-
const markerPath =
|
|
97372
|
+
const markerPath = join20(options.home, RESTORE_MARKER_FILE);
|
|
97118
97373
|
const fingerprint = restoreFingerprint(
|
|
97119
97374
|
plaintext,
|
|
97120
97375
|
stagedV2?.restoreDevice ?? options.device,
|
|
@@ -97325,13 +97580,13 @@ async function stageV2Restore(options) {
|
|
|
97325
97580
|
}
|
|
97326
97581
|
const agents = [];
|
|
97327
97582
|
for (const profile of validAgents) {
|
|
97328
|
-
const stagedPath =
|
|
97583
|
+
const stagedPath = join20(options.stagingHome, "agents", `${profile.name}.json`);
|
|
97329
97584
|
if (await stageRestoreBytes(stagedPath, prettyJson(profile))) {
|
|
97330
97585
|
agents.push({
|
|
97331
97586
|
kind: "agent",
|
|
97332
97587
|
name: profile.name,
|
|
97333
97588
|
stagedPath,
|
|
97334
|
-
targetPath:
|
|
97589
|
+
targetPath: join20(options.home, "agents", `${profile.name}.json`)
|
|
97335
97590
|
});
|
|
97336
97591
|
} else {
|
|
97337
97592
|
skipped2.push({ kind: "agent", name: profile.name, reason: "write_failed" });
|
|
@@ -97351,13 +97606,13 @@ async function stageV2Restore(options) {
|
|
|
97351
97606
|
if (restoreDevice !== void 0) {
|
|
97352
97607
|
for (const value of validSwarms) {
|
|
97353
97608
|
const swarm = swarmFileSchema.parse({ ...value, device: restoreDevice });
|
|
97354
|
-
const stagedPath =
|
|
97609
|
+
const stagedPath = join20(options.stagingHome, "swarms", `${swarm.name}.json`);
|
|
97355
97610
|
if (await stageRestoreBytes(stagedPath, prettyJson(swarm))) {
|
|
97356
97611
|
swarms.push({
|
|
97357
97612
|
kind: "swarm",
|
|
97358
97613
|
name: swarm.name,
|
|
97359
97614
|
stagedPath,
|
|
97360
|
-
targetPath:
|
|
97615
|
+
targetPath: join20(options.home, "swarms", `${swarm.name}.json`)
|
|
97361
97616
|
});
|
|
97362
97617
|
} else {
|
|
97363
97618
|
skipped2.push({ kind: "swarm", name: swarm.name, reason: "write_failed" });
|
|
@@ -97367,13 +97622,13 @@ async function stageV2Restore(options) {
|
|
|
97367
97622
|
const movements = [];
|
|
97368
97623
|
for (const movement of validMovements) {
|
|
97369
97624
|
const restored = reconcileRestoredMovement(movement, assumedReceiptKeys);
|
|
97370
|
-
const stagedPath =
|
|
97625
|
+
const stagedPath = join20(options.stagingHome, "movements", `${restored.id}.json`);
|
|
97371
97626
|
if (await stageRestoreBytes(stagedPath, serializeMovement(restored))) {
|
|
97372
97627
|
movements.push({
|
|
97373
97628
|
kind: "movement",
|
|
97374
97629
|
name: restored.id,
|
|
97375
97630
|
stagedPath,
|
|
97376
|
-
targetPath:
|
|
97631
|
+
targetPath: join20(options.home, "movements", `${restored.id}.json`),
|
|
97377
97632
|
movement: restored
|
|
97378
97633
|
});
|
|
97379
97634
|
} else {
|
|
@@ -97444,8 +97699,8 @@ async function publishRestoreFile(file2, staged) {
|
|
|
97444
97699
|
let identical = false;
|
|
97445
97700
|
try {
|
|
97446
97701
|
const [source, target] = await Promise.all([
|
|
97447
|
-
|
|
97448
|
-
|
|
97702
|
+
readFile24(file2.stagedPath),
|
|
97703
|
+
readFile24(file2.targetPath)
|
|
97449
97704
|
]);
|
|
97450
97705
|
identical = source.equals(target);
|
|
97451
97706
|
} catch {
|
|
@@ -97477,7 +97732,7 @@ async function publishRestoreReceiptsLocked(staged, targetPath) {
|
|
|
97477
97732
|
let existing = "";
|
|
97478
97733
|
let existingLines = /* @__PURE__ */ new Set();
|
|
97479
97734
|
try {
|
|
97480
|
-
await
|
|
97735
|
+
await readFile24(staged.receiptsPath, "utf8");
|
|
97481
97736
|
await mkdir19(dirname12(targetPath), { recursive: true, mode: 448 });
|
|
97482
97737
|
try {
|
|
97483
97738
|
const journal = await readRestoreReceiptJournal(targetPath);
|
|
@@ -97532,7 +97787,7 @@ async function reconcilePublishedMovements(staged, home, requireDurableSafety =
|
|
|
97532
97787
|
const unjournaledKeys = new Set([...signedKeys].filter((key2) => !journaledKeys.has(key2)));
|
|
97533
97788
|
let files;
|
|
97534
97789
|
try {
|
|
97535
|
-
files = await readdir8(
|
|
97790
|
+
files = await readdir8(join20(home, "movements"));
|
|
97536
97791
|
} catch (error61) {
|
|
97537
97792
|
if (isMissingFile4(error61)) return;
|
|
97538
97793
|
if (requireDurableSafety && unjournaledKeys.size > 0) throw error61;
|
|
@@ -97633,9 +97888,9 @@ function assertRelayKey(value) {
|
|
|
97633
97888
|
throw new BackupError("relay_invalid_key");
|
|
97634
97889
|
}
|
|
97635
97890
|
}
|
|
97636
|
-
function readRelayRandomBytes(
|
|
97891
|
+
function readRelayRandomBytes(randomBytes18, length) {
|
|
97637
97892
|
try {
|
|
97638
|
-
const value =
|
|
97893
|
+
const value = randomBytes18(length);
|
|
97639
97894
|
if (!(value instanceof Uint8Array) || value.byteLength !== length) throw new Error();
|
|
97640
97895
|
return Buffer.from(value);
|
|
97641
97896
|
} catch {
|
|
@@ -97753,7 +98008,7 @@ async function createRestoreMarker(vaultPath2, registryPath, fingerprint, vaultK
|
|
|
97753
98008
|
}
|
|
97754
98009
|
async function readRestoreMarker(path, fingerprint, vaultKey) {
|
|
97755
98010
|
try {
|
|
97756
|
-
const marker = restoreMarkerSchema.parse(JSON.parse(await
|
|
98011
|
+
const marker = restoreMarkerSchema.parse(JSON.parse(await readFile24(path, "utf8")));
|
|
97757
98012
|
const expectedMac = restoreMarkerMac(marker, vaultKey);
|
|
97758
98013
|
if (marker.fingerprint !== fingerprint || !timingSafeEqual(Buffer.from(marker.mac, "hex"), Buffer.from(expectedMac, "hex"))) {
|
|
97759
98014
|
throw new Error();
|
|
@@ -97770,7 +98025,7 @@ function restoreMarkerMac(marker, vaultKey) {
|
|
|
97770
98025
|
).digest("hex");
|
|
97771
98026
|
}
|
|
97772
98027
|
async function sha256File(path) {
|
|
97773
|
-
return createHash6("sha256").update(await
|
|
98028
|
+
return createHash6("sha256").update(await readFile24(path)).digest("hex");
|
|
97774
98029
|
}
|
|
97775
98030
|
async function notifyRestorePublish(hook, step2, rememberError) {
|
|
97776
98031
|
try {
|
|
@@ -98072,7 +98327,7 @@ function copyTransferReceipt(receipt) {
|
|
|
98072
98327
|
async function readReceiptJournal(path) {
|
|
98073
98328
|
let raw;
|
|
98074
98329
|
try {
|
|
98075
|
-
raw = await
|
|
98330
|
+
raw = await readFile24(path, "utf8");
|
|
98076
98331
|
} catch (error61) {
|
|
98077
98332
|
if (isMissingFile4(error61)) return [];
|
|
98078
98333
|
throw error61;
|
|
@@ -98082,7 +98337,7 @@ async function readReceiptJournal(path) {
|
|
|
98082
98337
|
async function readRestoreReceiptJournal(path) {
|
|
98083
98338
|
let raw;
|
|
98084
98339
|
try {
|
|
98085
|
-
raw = await
|
|
98340
|
+
raw = await readFile24(path, "utf8");
|
|
98086
98341
|
} catch (error61) {
|
|
98087
98342
|
if (isMissingFile4(error61)) return { raw: "", lines: /* @__PURE__ */ new Set(), signedKeys: /* @__PURE__ */ new Set() };
|
|
98088
98343
|
throw error61;
|
|
@@ -98201,8 +98456,8 @@ function assertOwnerKey(ownerKey) {
|
|
|
98201
98456
|
assertBytes(ownerKey.key, 32);
|
|
98202
98457
|
assertBytes(ownerKey.salt, 32);
|
|
98203
98458
|
}
|
|
98204
|
-
function readRandomBytes(
|
|
98205
|
-
const value =
|
|
98459
|
+
function readRandomBytes(randomBytes18, length) {
|
|
98460
|
+
const value = randomBytes18(length);
|
|
98206
98461
|
if (!(value instanceof Uint8Array) || value.byteLength !== length) {
|
|
98207
98462
|
throw new BackupError("backup_invalid_input");
|
|
98208
98463
|
}
|
|
@@ -98441,7 +98696,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
98441
98696
|
try {
|
|
98442
98697
|
let vaultFile;
|
|
98443
98698
|
try {
|
|
98444
|
-
vaultFile = await readVaultFileUnlocked(
|
|
98699
|
+
vaultFile = await readVaultFileUnlocked(join21(options.store.home, "vault.json"));
|
|
98445
98700
|
} catch (error61) {
|
|
98446
98701
|
if (error61 instanceof VaultError && error61.code === "not_found") {
|
|
98447
98702
|
return { status: "skipped", reason: "no_vault" };
|
|
@@ -98450,7 +98705,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
98450
98705
|
}
|
|
98451
98706
|
try {
|
|
98452
98707
|
vaultKey = vaultFile.protected ? await unlockProtectedVault({
|
|
98453
|
-
path:
|
|
98708
|
+
path: join21(options.store.home, "vault.json"),
|
|
98454
98709
|
secrets: options.secrets,
|
|
98455
98710
|
env: options.env,
|
|
98456
98711
|
...options.now === void 0 ? {} : { now: options.now }
|
|
@@ -99123,7 +99378,7 @@ async function readProcessStdin() {
|
|
|
99123
99378
|
}
|
|
99124
99379
|
|
|
99125
99380
|
// src/version.ts
|
|
99126
|
-
var CLI_VERSION = "0.
|
|
99381
|
+
var CLI_VERSION = "0.13.0";
|
|
99127
99382
|
|
|
99128
99383
|
// src/status.ts
|
|
99129
99384
|
async function statusCommand(argv, json2, io, dependencies) {
|
|
@@ -99290,7 +99545,7 @@ function withDeadlineSignal3(fetchImpl, deadline) {
|
|
|
99290
99545
|
}
|
|
99291
99546
|
async function statusConfig(path) {
|
|
99292
99547
|
try {
|
|
99293
|
-
await
|
|
99548
|
+
await stat15(path);
|
|
99294
99549
|
} catch (error61) {
|
|
99295
99550
|
if (isMissingFile(error61)) return getDefaultConfig(process.env);
|
|
99296
99551
|
throw error61;
|
|
@@ -99488,7 +99743,7 @@ async function siblingsFetchImpl(dependencies) {
|
|
|
99488
99743
|
const configPath = getVapiPaths().config;
|
|
99489
99744
|
let config2;
|
|
99490
99745
|
try {
|
|
99491
|
-
await
|
|
99746
|
+
await stat16(configPath);
|
|
99492
99747
|
config2 = await loadConfig(configPath, process.env);
|
|
99493
99748
|
} catch (error61) {
|
|
99494
99749
|
if (!isMissingFile(error61)) throw error61;
|
|
@@ -99577,7 +99832,7 @@ ${IMPORT_USAGE}`);
|
|
|
99577
99832
|
const passphrase = await secretPrompt(dependencies)(`Passphrase for ${keystorePath}: `);
|
|
99578
99833
|
privateKey = (await exportKeystoreKeys(passphrase, keystorePath)).evm.privateKey;
|
|
99579
99834
|
} else if (keyPath !== void 0) {
|
|
99580
|
-
privateKey = (await
|
|
99835
|
+
privateKey = (await readFile25(keyPath, "utf8")).trim();
|
|
99581
99836
|
} else {
|
|
99582
99837
|
privateKey = await secretPrompt(dependencies)("Private key: ");
|
|
99583
99838
|
}
|
|
@@ -99625,10 +99880,10 @@ async function accountsRenameCommand(argv, json2, io, dependencies) {
|
|
|
99625
99880
|
{
|
|
99626
99881
|
previous: from16,
|
|
99627
99882
|
...address4 === void 0 ? {} : { address: address4 },
|
|
99628
|
-
vault:
|
|
99883
|
+
vault: join22(store.home, "vault.json"),
|
|
99629
99884
|
message: `Wallet ${from16} is now ${renamed.name}.`
|
|
99630
99885
|
},
|
|
99631
|
-
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${
|
|
99886
|
+
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${join22(store.home, "vault.json")}`].join(
|
|
99632
99887
|
"\n"
|
|
99633
99888
|
)
|
|
99634
99889
|
);
|
|
@@ -99737,13 +99992,13 @@ async function accountsRestoreCommand(argv, json2, io, dependencies) {
|
|
|
99737
99992
|
{ name: restored.name, ...address4 === void 0 ? {} : { address: address4 } },
|
|
99738
99993
|
{
|
|
99739
99994
|
...address4 === void 0 ? {} : { address: address4 },
|
|
99740
|
-
vault:
|
|
99995
|
+
vault: join22(store.home, "vault.json"),
|
|
99741
99996
|
spendCaps: restored.entry.spendCaps,
|
|
99742
99997
|
message: `Wallet ${restored.name} restored to the device vault.`
|
|
99743
99998
|
},
|
|
99744
99999
|
[
|
|
99745
100000
|
`Wallet ${restored.name} restored to the device vault.`,
|
|
99746
|
-
`Vault: ${
|
|
100001
|
+
`Vault: ${join22(store.home, "vault.json")}`
|
|
99747
100002
|
].join("\n")
|
|
99748
100003
|
);
|
|
99749
100004
|
}
|
|
@@ -100073,7 +100328,7 @@ function formatNetworkAccounts(accounts) {
|
|
|
100073
100328
|
}
|
|
100074
100329
|
|
|
100075
100330
|
// src/cloud-backup.ts
|
|
100076
|
-
import { join as
|
|
100331
|
+
import { join as join23 } from "node:path";
|
|
100077
100332
|
var CLOUD_BACKUP_USAGE = "Usage: vapi backup --cloud [off] [--json]";
|
|
100078
100333
|
var OWNER_RESTORE_USAGE = "Usage: vapi restore --from-owner [--owner <0x\u2026>] [--json]";
|
|
100079
100334
|
var OWNER_PATTERN2 = /^0x[0-9a-fA-F]{40}$/u;
|
|
@@ -100096,7 +100351,7 @@ async function cloudBackupCommand(argv, json2, io, dependencies) {
|
|
|
100096
100351
|
}
|
|
100097
100352
|
async function enrollCloudBackup(json2, io, dependencies) {
|
|
100098
100353
|
const paths = getVapiPaths();
|
|
100099
|
-
if (!await
|
|
100354
|
+
if (!await fileExists3(join23(paths.directory, "vault.json"))) {
|
|
100100
100355
|
throw new Error("No vault on this device. Run vapi setup first.");
|
|
100101
100356
|
}
|
|
100102
100357
|
const context = await cloudContext(io, dependencies);
|
|
@@ -100208,7 +100463,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
100208
100463
|
}
|
|
100209
100464
|
const expectedOwner = ownerValue?.toLowerCase();
|
|
100210
100465
|
const paths = getVapiPaths();
|
|
100211
|
-
if (await
|
|
100466
|
+
if (await fileExists3(join23(paths.directory, "vault.json")) && !await fileExists3(join23(paths.directory, ".backup-restore.json"))) {
|
|
100212
100467
|
throw new Error(
|
|
100213
100468
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
100214
100469
|
);
|
|
@@ -100264,7 +100519,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
100264
100519
|
env: getEnvironment(dependencies),
|
|
100265
100520
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
100266
100521
|
});
|
|
100267
|
-
if (!await
|
|
100522
|
+
if (!await fileExists3(paths.config)) {
|
|
100268
100523
|
const networks = restored.networks.length === 0 ? ["base"] : restored.networks;
|
|
100269
100524
|
await writeDefaultConfig(paths.config, getEnvironment(dependencies), { networks });
|
|
100270
100525
|
}
|
|
@@ -101305,20 +101560,20 @@ function shortExcerpt(value) {
|
|
|
101305
101560
|
}
|
|
101306
101561
|
|
|
101307
101562
|
// src/agent.ts
|
|
101308
|
-
import { readFile as
|
|
101309
|
-
import { join as
|
|
101563
|
+
import { readFile as readFile27, stat as stat17 } from "node:fs/promises";
|
|
101564
|
+
import { join as join26 } from "node:path";
|
|
101310
101565
|
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
101311
101566
|
|
|
101312
101567
|
// src/headless.ts
|
|
101313
101568
|
import { chmod as chmod7, mkdtemp as mkdtemp2, rm as rm4, writeFile as writeFile10 } from "node:fs/promises";
|
|
101314
101569
|
import { rmSync } from "node:fs";
|
|
101315
101570
|
import { tmpdir as osTmpdir } from "node:os";
|
|
101316
|
-
import { join as
|
|
101571
|
+
import { join as join24 } from "node:path";
|
|
101317
101572
|
var BUNDLE_VARIABLE_PATTERN = /^[A-Z_][A-Z0-9_]*$/u;
|
|
101318
101573
|
var REMOTE_BLOCKED_GRANTS2 = /* @__PURE__ */ new Set(["delegate", "allocate"]);
|
|
101319
101574
|
var agentProfileOptions = { schema: registeredAgentProfileSchema };
|
|
101320
101575
|
async function createHeadlessHome(bundle, options = {}) {
|
|
101321
|
-
const home = await mkdtemp2(
|
|
101576
|
+
const home = await mkdtemp2(join24(options.tmpdir ?? osTmpdir(), "vapi-headless-"));
|
|
101322
101577
|
const cleanup = async () => {
|
|
101323
101578
|
await rm4(home, { recursive: true, force: true });
|
|
101324
101579
|
};
|
|
@@ -101518,18 +101773,18 @@ import { readFile as nodeReadFile } from "node:fs/promises";
|
|
|
101518
101773
|
|
|
101519
101774
|
// src/runtime-railway.ts
|
|
101520
101775
|
import { spawn as spawn2 } from "node:child_process";
|
|
101521
|
-
import { randomBytes as
|
|
101776
|
+
import { randomBytes as randomBytes17 } from "node:crypto";
|
|
101522
101777
|
import { closeSync, fsyncSync, mkdirSync, openSync, renameSync, rmSync as rmSync2, writeSync } from "node:fs";
|
|
101523
101778
|
import {
|
|
101524
101779
|
mkdtemp as nodeMkdtemp,
|
|
101525
101780
|
readdir as readdir9,
|
|
101526
|
-
readFile as
|
|
101781
|
+
readFile as readFile26,
|
|
101527
101782
|
rm as nodeRm,
|
|
101528
101783
|
stat as nodeStat,
|
|
101529
101784
|
writeFile as nodeWriteFile
|
|
101530
101785
|
} from "node:fs/promises";
|
|
101531
101786
|
import { tmpdir as osTmpdir2 } from "node:os";
|
|
101532
|
-
import { basename as basename4, dirname as dirname13, join as
|
|
101787
|
+
import { basename as basename4, dirname as dirname13, join as join25 } from "node:path";
|
|
101533
101788
|
var RAILWAY_CLI = {
|
|
101534
101789
|
binary: "railway",
|
|
101535
101790
|
create: (options) => [
|
|
@@ -101701,7 +101956,7 @@ async function assertRemoteSafeMember(args) {
|
|
|
101701
101956
|
}
|
|
101702
101957
|
function railwaySidecarPath(home, runId) {
|
|
101703
101958
|
if (!isRunId(runId)) throw new RuntimeError("invalid_run_id", `Invalid run id: ${runId}.`);
|
|
101704
|
-
return
|
|
101959
|
+
return join25(runsDirectory(home), `${runId}.railway.json`);
|
|
101705
101960
|
}
|
|
101706
101961
|
function createRailwayRuntime(options) {
|
|
101707
101962
|
const { home } = options;
|
|
@@ -102026,10 +102281,10 @@ function createRailwayRuntime(options) {
|
|
|
102026
102281
|
let createError;
|
|
102027
102282
|
let cleanupError;
|
|
102028
102283
|
try {
|
|
102029
|
-
directory = await fs.mkdtemp(
|
|
102284
|
+
directory = await fs.mkdtemp(join25(options.tmpdir ?? osTmpdir2(), "vapi-railway-"));
|
|
102030
102285
|
assertNotInterrupted();
|
|
102031
102286
|
await assertMode(fs, directory, 448, "env-file directory");
|
|
102032
|
-
envFile =
|
|
102287
|
+
envFile = join25(directory, "member.env");
|
|
102033
102288
|
await fs.writeFile(envFile, `${RAILWAY_CLI.bundleVariable}=${bundle}
|
|
102034
102289
|
`, {
|
|
102035
102290
|
encoding: "utf8",
|
|
@@ -102484,9 +102739,9 @@ async function writeSidecar(home, runId, sidecar) {
|
|
|
102484
102739
|
function writeSidecarSync(path, sidecar) {
|
|
102485
102740
|
const directory = dirname13(path);
|
|
102486
102741
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
102487
|
-
const temporary =
|
|
102742
|
+
const temporary = join25(
|
|
102488
102743
|
directory,
|
|
102489
|
-
`.${basename4(path)}.${process.pid}.${
|
|
102744
|
+
`.${basename4(path)}.${process.pid}.${randomBytes17(6).toString("hex")}.tmp`
|
|
102490
102745
|
);
|
|
102491
102746
|
try {
|
|
102492
102747
|
const descriptor2 = openSync(temporary, "wx", 384);
|
|
@@ -102524,7 +102779,7 @@ var LEGACY_SIDECAR_KEYS = ["checkpoint", "keepSandbox", "sandboxId", "v"];
|
|
|
102524
102779
|
async function readSidecar(home, runId) {
|
|
102525
102780
|
let parsed;
|
|
102526
102781
|
try {
|
|
102527
|
-
parsed = JSON.parse(await
|
|
102782
|
+
parsed = JSON.parse(await readFile26(railwaySidecarPath(home, runId), "utf8"));
|
|
102528
102783
|
} catch {
|
|
102529
102784
|
return void 0;
|
|
102530
102785
|
}
|
|
@@ -102582,7 +102837,7 @@ async function assertMode(fs, path, mode, what) {
|
|
|
102582
102837
|
}
|
|
102583
102838
|
}
|
|
102584
102839
|
async function deviceVaultKey(home, secrets, now) {
|
|
102585
|
-
const path =
|
|
102840
|
+
const path = join25(home, "vault.json");
|
|
102586
102841
|
const metadata = await readVaultFileUnlocked(path);
|
|
102587
102842
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
102588
102843
|
path,
|
|
@@ -102637,7 +102892,7 @@ function createLocalRuntime(options) {
|
|
|
102637
102892
|
const processCommand = options.processCommand ?? defaultProcessCommand;
|
|
102638
102893
|
const ownsProcess = (handle, pid) => processCommand(pid)?.includes(runResultPath(home, handle.runId)) === true;
|
|
102639
102894
|
const closeFd = options.closeFd ?? closeSync2;
|
|
102640
|
-
const
|
|
102895
|
+
const readFile33 = options.readFile ?? nodeReadFile;
|
|
102641
102896
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
102642
102897
|
const openLog = options.openLog ?? ((path) => {
|
|
102643
102898
|
mkdirSync2(runsDirectory(home), { recursive: true, mode: 448 });
|
|
@@ -102692,7 +102947,7 @@ function createLocalRuntime(options) {
|
|
|
102692
102947
|
return handle;
|
|
102693
102948
|
},
|
|
102694
102949
|
async status(handle) {
|
|
102695
|
-
const result = await readResultFile(
|
|
102950
|
+
const result = await readResultFile(readFile33, runResultPath(home, handle.runId));
|
|
102696
102951
|
if (result !== void 0) return result;
|
|
102697
102952
|
const pid = localPid(handle);
|
|
102698
102953
|
if (pid === void 0 || handle.kind !== "local") {
|
|
@@ -102795,10 +103050,10 @@ function childArguments(member, run) {
|
|
|
102795
103050
|
...run.drawUsd ? ["--draw", run.drawUsd] : []
|
|
102796
103051
|
];
|
|
102797
103052
|
}
|
|
102798
|
-
async function readResultFile(
|
|
103053
|
+
async function readResultFile(readFile33, path) {
|
|
102799
103054
|
let text;
|
|
102800
103055
|
try {
|
|
102801
|
-
text = await
|
|
103056
|
+
text = await readFile33(path, "utf8");
|
|
102802
103057
|
} catch (error61) {
|
|
102803
103058
|
if (hasCode3(error61, "ENOENT")) return void 0;
|
|
102804
103059
|
return { state: "failed", detail: "unreadable result file" };
|
|
@@ -102923,7 +103178,7 @@ async function createCommand(argv, json2, io, dependencies) {
|
|
|
102923
103178
|
if (await profileFileExists(paths.agentsDir, name)) {
|
|
102924
103179
|
throw new Error(`Agent ${name} already exists.`);
|
|
102925
103180
|
}
|
|
102926
|
-
const instructions = await
|
|
103181
|
+
const instructions = await readFile27(instructionsPath, "utf8");
|
|
102927
103182
|
if (instructions.length > 2e4) {
|
|
102928
103183
|
throw new UsageError("--instructions must contain at most 20000 characters.");
|
|
102929
103184
|
}
|
|
@@ -103509,7 +103764,7 @@ function explicitWallet(name) {
|
|
|
103509
103764
|
}
|
|
103510
103765
|
async function profileFileExists(directory, name) {
|
|
103511
103766
|
try {
|
|
103512
|
-
await
|
|
103767
|
+
await stat17(join26(directory, `${name}.json`));
|
|
103513
103768
|
return true;
|
|
103514
103769
|
} catch (error61) {
|
|
103515
103770
|
if (isMissingFile(error61)) return false;
|
|
@@ -103570,7 +103825,7 @@ function usd(value, minimumDecimals = 0) {
|
|
|
103570
103825
|
|
|
103571
103826
|
// src/mcp-install.ts
|
|
103572
103827
|
import { spawn as spawn3 } from "node:child_process";
|
|
103573
|
-
import { mkdir as mkdir20, readFile as
|
|
103828
|
+
import { mkdir as mkdir20, readFile as readFile28, writeFile as writeFile11 } from "node:fs/promises";
|
|
103574
103829
|
import { homedir as systemHomedir } from "node:os";
|
|
103575
103830
|
import { dirname as dirname14, posix, win32 as win322 } from "node:path";
|
|
103576
103831
|
|
|
@@ -103950,7 +104205,7 @@ function isRecord12(value) {
|
|
|
103950
104205
|
}
|
|
103951
104206
|
async function readExistingFile(path) {
|
|
103952
104207
|
try {
|
|
103953
|
-
return await
|
|
104208
|
+
return await readFile28(path, "utf8");
|
|
103954
104209
|
} catch (error61) {
|
|
103955
104210
|
if (isMissingFile(error61)) return void 0;
|
|
103956
104211
|
throw error61;
|
|
@@ -103958,7 +104213,7 @@ async function readExistingFile(path) {
|
|
|
103958
104213
|
}
|
|
103959
104214
|
async function pathExists5(path) {
|
|
103960
104215
|
try {
|
|
103961
|
-
await
|
|
104216
|
+
await readFile28(path);
|
|
103962
104217
|
return true;
|
|
103963
104218
|
} catch (error61) {
|
|
103964
104219
|
if (isMissingFile(error61)) return false;
|
|
@@ -103968,15 +104223,15 @@ async function pathExists5(path) {
|
|
|
103968
104223
|
|
|
103969
104224
|
// src/code.ts
|
|
103970
104225
|
import { constants as constants2 } from "node:fs";
|
|
103971
|
-
import { access, mkdir as mkdir21, readFile as
|
|
104226
|
+
import { access, mkdir as mkdir21, readFile as readFile29, realpath, unlink as unlink13, writeFile as writeFile12 } from "node:fs/promises";
|
|
103972
104227
|
import { homedir as homedir3 } from "node:os";
|
|
103973
|
-
import { basename as basename5, dirname as dirname15, join as
|
|
104228
|
+
import { basename as basename5, dirname as dirname15, join as join27, posix as posix2, win32 as win323 } from "node:path";
|
|
103974
104229
|
var VAPI_CODEX_PROVIDER = "vapi";
|
|
103975
104230
|
var VAPI_CODEX_PROFILE = "vapi";
|
|
103976
104231
|
var VAPI_CODEX_DEFAULT_MODEL = "venice/openai-gpt-61-sol";
|
|
103977
104232
|
var VAPI_ROUTER_KEY_ENV = "VAPI_ROUTER_KEY";
|
|
103978
104233
|
function codexConfigPath(env, home) {
|
|
103979
|
-
return
|
|
104234
|
+
return join27(env.CODEX_HOME || join27(home, ".codex"), "config.toml");
|
|
103980
104235
|
}
|
|
103981
104236
|
function hasVapiCodexProfile(contents) {
|
|
103982
104237
|
const roots = new Set(
|
|
@@ -104070,7 +104325,7 @@ function aliasContents(original, tools) {
|
|
|
104070
104325
|
}
|
|
104071
104326
|
async function readOptional(path) {
|
|
104072
104327
|
try {
|
|
104073
|
-
return await
|
|
104328
|
+
return await readFile29(path, "utf8");
|
|
104074
104329
|
} catch (error61) {
|
|
104075
104330
|
if (isMissingFile(error61)) return void 0;
|
|
104076
104331
|
throw error61;
|
|
@@ -104092,7 +104347,7 @@ async function codeCommand(argv, json2, io, dependencies) {
|
|
|
104092
104347
|
const env = getEnvironment(dependencies);
|
|
104093
104348
|
const home = dependencies.code?.homedir ?? homedir3();
|
|
104094
104349
|
const config2 = codexConfigPath(env, home);
|
|
104095
|
-
const rcPaths = [
|
|
104350
|
+
const rcPaths = [join27(home, ".zshrc"), join27(home, ".bashrc")];
|
|
104096
104351
|
if (command === "uninstall") {
|
|
104097
104352
|
const removed = [];
|
|
104098
104353
|
const previous = await readOptional(config2);
|
|
@@ -104216,7 +104471,7 @@ async function codeCommand(argv, json2, io, dependencies) {
|
|
|
104216
104471
|
|
|
104217
104472
|
// src/code-launch.ts
|
|
104218
104473
|
import { spawn as spawn4 } from "node:child_process";
|
|
104219
|
-
import { readFile as
|
|
104474
|
+
import { readFile as readFile30 } from "node:fs/promises";
|
|
104220
104475
|
import { constants as constants3, homedir as homedir4 } from "node:os";
|
|
104221
104476
|
var CLAUDE_MODELS = {
|
|
104222
104477
|
sonnet: "venice/claude-sonnet-5-5",
|
|
@@ -104430,7 +104685,7 @@ function claudeModel(model) {
|
|
|
104430
104685
|
async function codexArgs(env, baseURL, model, dependencies) {
|
|
104431
104686
|
let contents = "";
|
|
104432
104687
|
try {
|
|
104433
|
-
contents = await
|
|
104688
|
+
contents = await readFile30(
|
|
104434
104689
|
codexConfigPath(env, dependencies.code?.homedir ?? homedir4()),
|
|
104435
104690
|
"utf8"
|
|
104436
104691
|
);
|
|
@@ -104605,7 +104860,7 @@ async function sendConfig(dependencies) {
|
|
|
104605
104860
|
|
|
104606
104861
|
// src/setup.ts
|
|
104607
104862
|
import { rm as rm5 } from "node:fs/promises";
|
|
104608
|
-
import { join as
|
|
104863
|
+
import { join as join28 } from "node:path";
|
|
104609
104864
|
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.`;
|
|
104610
104865
|
var VAULT_CHOICE = "Create a new vault, or restore one from a recovery phrase? [new/restore] ";
|
|
104611
104866
|
async function setupCommand(argv, json2, io, dependencies) {
|
|
@@ -104624,18 +104879,24 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
104624
104879
|
const steps = [];
|
|
104625
104880
|
const humanIo = json2 ? stderrIo(io) : io;
|
|
104626
104881
|
const accountCount = parseAccountCount(parsed.one("--accounts"));
|
|
104627
|
-
if (!await
|
|
104882
|
+
if (!await fileExists3(paths.config)) {
|
|
104628
104883
|
await writeDefaultConfig(paths.config, process.env, { networks: ["base"] });
|
|
104629
104884
|
steps.push("config");
|
|
104630
104885
|
}
|
|
104631
104886
|
const config2 = await readConfig(paths.config, humanIo);
|
|
104887
|
+
if (!await fileExists3(join28(paths.directory, "vault.json"))) {
|
|
104888
|
+
const os = dependencies.secretBackendProbe ?? (dependencies.secretStore === void 0 ? osSecretStore() : void 0);
|
|
104889
|
+
if (os !== void 0) {
|
|
104890
|
+
await chooseSecretBackend({ home: paths.directory, os, env: getEnvironment(dependencies) });
|
|
104891
|
+
}
|
|
104892
|
+
}
|
|
104632
104893
|
let store = await openWalletStore(dependencies);
|
|
104633
104894
|
let vault = "existing";
|
|
104634
104895
|
let changedVault = false;
|
|
104635
104896
|
let changedAccount = false;
|
|
104636
104897
|
let changedLink = false;
|
|
104637
104898
|
let scannedAddresses;
|
|
104638
|
-
if (!await
|
|
104899
|
+
if (!await fileExists3(join28(paths.directory, "vault.json"))) {
|
|
104639
104900
|
const choice = await vaultChoice(dependencies);
|
|
104640
104901
|
if (choice === "restore") {
|
|
104641
104902
|
if (!isInteractive(dependencies)) {
|
|
@@ -104723,7 +104984,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
104723
104984
|
let scannedAddresses = 0;
|
|
104724
104985
|
try {
|
|
104725
104986
|
const restored = await restoreVault({
|
|
104726
|
-
path:
|
|
104987
|
+
path: join28(paths.directory, "vault.json"),
|
|
104727
104988
|
key: key2,
|
|
104728
104989
|
phrase: validatedPhrase,
|
|
104729
104990
|
probe: async (address4) => await readBalance3(address4) > 0n,
|
|
@@ -104734,7 +104995,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
104734
104995
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
104735
104996
|
});
|
|
104736
104997
|
names = restored.accounts().map((account) => account.name);
|
|
104737
|
-
await rm5(
|
|
104998
|
+
await rm5(join28(paths.directory, "wallets.json"), { force: true });
|
|
104738
104999
|
} finally {
|
|
104739
105000
|
key2.fill(0);
|
|
104740
105001
|
}
|
|
@@ -104852,7 +105113,7 @@ async function withRouterError2(operation) {
|
|
|
104852
105113
|
|
|
104853
105114
|
// src/task.ts
|
|
104854
105115
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
104855
|
-
import { readFile as
|
|
105116
|
+
import { readFile as readFile31 } from "node:fs/promises";
|
|
104856
105117
|
var TASK_HELP = `Usage:
|
|
104857
105118
|
vapi task search [--open] [--min <usd>] [--tab trending|new|closing|paid] [--limit <n>] [--json]
|
|
104858
105119
|
vapi task show <id> [--account <name>] [--json]
|
|
@@ -105188,7 +105449,7 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
105188
105449
|
if (maxAwards !== void 0 && maxAwards > TASK_LIMITS.maxAwardsMax)
|
|
105189
105450
|
throw new UsageError("--max-awards must be between 1 and 50.");
|
|
105190
105451
|
if (parsed.one("--webhook") !== void 0) httpsUrl2(parsed.one("--webhook"), "--webhook");
|
|
105191
|
-
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await
|
|
105452
|
+
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await readFile31(briefPath, "utf8");
|
|
105192
105453
|
const input2 = {
|
|
105193
105454
|
title: title.trim(),
|
|
105194
105455
|
description: brief.trim(),
|
|
@@ -106866,7 +107127,7 @@ async function referencedSleep(milliseconds, signal) {
|
|
|
106866
107127
|
}
|
|
106867
107128
|
|
|
106868
107129
|
// src/vault.ts
|
|
106869
|
-
import { join as
|
|
107130
|
+
import { join as join29 } from "node:path";
|
|
106870
107131
|
var VAULT_USAGE = "Usage: vapi vault protect|unprotect|lock|unlock|status [--json]";
|
|
106871
107132
|
var RESTORE_USAGE = "Usage: vapi restore [--accounts <n> | --from-owner [--owner <0x\u2026>]] [--json]";
|
|
106872
107133
|
var LEGACY_PASSWORD_NOTICE = "VAPI_KEYSTORE_PASSWORD is deprecated for vault passwords; use VAPI_VAULT_PASSWORD instead.";
|
|
@@ -106910,13 +107171,13 @@ async function restoreCommand(argv, json2, io, dependencies) {
|
|
|
106910
107171
|
}
|
|
106911
107172
|
const accountCount = parseRestoreAccountCount(parsed.one("--accounts"));
|
|
106912
107173
|
const paths = getVapiPaths();
|
|
106913
|
-
const path =
|
|
106914
|
-
if (await
|
|
107174
|
+
const path = join29(paths.directory, "vault.json");
|
|
107175
|
+
if (await fileExists3(path)) {
|
|
106915
107176
|
throw new Error(
|
|
106916
107177
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
106917
107178
|
);
|
|
106918
107179
|
}
|
|
106919
|
-
if (!await
|
|
107180
|
+
if (!await fileExists3(paths.config)) {
|
|
106920
107181
|
await writeDefaultConfig(paths.config, process.env, { networks: ["base"] });
|
|
106921
107182
|
}
|
|
106922
107183
|
const config2 = await readConfig(paths.config, json2 ? quietIo(io) : io);
|
|
@@ -107067,7 +107328,7 @@ function requireNoArguments(argv) {
|
|
|
107067
107328
|
parseArguments(argv, { valueOptions: /* @__PURE__ */ new Set(), maximumPositionals: 0 });
|
|
107068
107329
|
}
|
|
107069
107330
|
function vaultPath() {
|
|
107070
|
-
return
|
|
107331
|
+
return join29(getVapiPaths().directory, "vault.json");
|
|
107071
107332
|
}
|
|
107072
107333
|
function quietIo(io) {
|
|
107073
107334
|
return { stdout: () => void 0, stderr: io.stderr };
|
|
@@ -107518,7 +107779,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
107518
107779
|
break;
|
|
107519
107780
|
case "unlock":
|
|
107520
107781
|
io.stderr("vapi unlock is now vapi vault unlock; the old name works for one release.");
|
|
107521
|
-
if (await
|
|
107782
|
+
if (await fileExists3(join30(getVapiPaths().directory, "vault.json"))) {
|
|
107522
107783
|
parseArguments(args.slice(1), {
|
|
107523
107784
|
valueOptions: /* @__PURE__ */ new Set([WALLET_OPTION5]),
|
|
107524
107785
|
maximumPositionals: 0
|
|
@@ -107706,7 +107967,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
107706
107967
|
await recordAudit(dependencies, "wallet.create", { wallet: created.name });
|
|
107707
107968
|
const account = created.account;
|
|
107708
107969
|
if (!json2) await showRecoveryPhrase(created.recoveryPhrase, io, dependencies);
|
|
107709
|
-
if (!await
|
|
107970
|
+
if (!await fileExists3(paths.config)) {
|
|
107710
107971
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
107711
107972
|
} else {
|
|
107712
107973
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -107724,7 +107985,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
107724
107985
|
address: account.address,
|
|
107725
107986
|
accounts,
|
|
107726
107987
|
config: paths.config,
|
|
107727
|
-
vault:
|
|
107988
|
+
vault: join30(paths.directory, "vault.json"),
|
|
107728
107989
|
...configRewrites.length > 0 ? { configRewrites } : {},
|
|
107729
107990
|
custody: "self",
|
|
107730
107991
|
warning: CUSTODY_NOTICE,
|
|
@@ -107854,7 +108115,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
107854
108115
|
await recordAudit(dependencies, "wallet.create", { wallet: created.name });
|
|
107855
108116
|
const account = created.account;
|
|
107856
108117
|
if (!json2) await showRecoveryPhrase(created.recoveryPhrase, io, dependencies);
|
|
107857
|
-
if (!await
|
|
108118
|
+
if (!await fileExists3(paths.config)) {
|
|
107858
108119
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
107859
108120
|
} else {
|
|
107860
108121
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -107863,7 +108124,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
107863
108124
|
const result = {
|
|
107864
108125
|
address: account.address,
|
|
107865
108126
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
107866
|
-
vault:
|
|
108127
|
+
vault: join30(paths.directory, "vault.json"),
|
|
107867
108128
|
...label === void 0 ? {} : { label },
|
|
107868
108129
|
spendCaps: created.entry.spendCaps,
|
|
107869
108130
|
isDefault,
|
|
@@ -107903,7 +108164,7 @@ function formatCaps2(caps) {
|
|
|
107903
108164
|
function walletListResult(store, wallets, unlocked) {
|
|
107904
108165
|
return {
|
|
107905
108166
|
default: store.defaultName ?? null,
|
|
107906
|
-
vault:
|
|
108167
|
+
vault: join30(store.home, "vault.json"),
|
|
107907
108168
|
wallets: wallets.map((wallet) => ({
|
|
107908
108169
|
name: wallet.name,
|
|
107909
108170
|
...wallet.address === void 0 ? {} : { address: wallet.address },
|
|
@@ -108919,7 +109180,7 @@ function sameOrigin2(left, right) {
|
|
|
108919
109180
|
function noApiKeyMessage(baseUrl) {
|
|
108920
109181
|
return [
|
|
108921
109182
|
"No vAPI API key on this machine.",
|
|
108922
|
-
`Create one in the console at ${
|
|
109183
|
+
`Create one in the console at ${apiKeyConsoleUrl(baseUrl).href}, then store it with vapi auth set-key.`,
|
|
108923
109184
|
`In CI, set ${API_KEY_ENV} instead.`
|
|
108924
109185
|
].join("\n");
|
|
108925
109186
|
}
|
|
@@ -109176,7 +109437,7 @@ function formatClaimed(origin, claimed) {
|
|
|
109176
109437
|
}
|
|
109177
109438
|
var EXPORT_KEY_WARNING = "Anyone with this key can spend the wallet. Never paste it into a website or chat.";
|
|
109178
109439
|
async function deviceVaultKey2(store, dependencies) {
|
|
109179
|
-
const path =
|
|
109440
|
+
const path = join30(store.home, "vault.json");
|
|
109180
109441
|
const metadata = await readVaultFileUnlocked(path);
|
|
109181
109442
|
const secrets = getSecretStore(dependencies);
|
|
109182
109443
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
@@ -109269,7 +109530,7 @@ async function backupCommand(argv, json2, io, dependencies) {
|
|
|
109269
109530
|
const target = await targetWallet(parsed, dependencies);
|
|
109270
109531
|
const vaultAccount = await target.store.hasVaultAccount(target.name);
|
|
109271
109532
|
if (vaultAccount) {
|
|
109272
|
-
const vault = await readVaultFileUnlocked(
|
|
109533
|
+
const vault = await readVaultFileUnlocked(join30(target.store.home, "vault.json"));
|
|
109273
109534
|
if (vault.accounts.some((account) => account.name === target.name && account.kind === "imported")) {
|
|
109274
109535
|
throw new KeystoreError(
|
|
109275
109536
|
`Account ${target.name} was imported and is not recoverable from the vault phrase. Back it up with vapi export-key --account ${target.name}.`
|
|
@@ -109346,7 +109607,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109346
109607
|
const existed = store.has(name);
|
|
109347
109608
|
if (existed && !parsed.has("--replace")) {
|
|
109348
109609
|
const address4 = await store.readAddress(name);
|
|
109349
|
-
const location = await store.hasVaultAccount(name) ?
|
|
109610
|
+
const location = await store.hasVaultAccount(name) ? join30(store.home, "vault.json") : store.pathFor(name);
|
|
109350
109611
|
throw new Error(
|
|
109351
109612
|
[
|
|
109352
109613
|
`Wallet ${name} already exists at ${location}.`,
|
|
@@ -109374,7 +109635,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109374
109635
|
const imported = fromPhrase ? await store.create(name, "", { phrase: secret }) : await store.importKey(name, "", secret);
|
|
109375
109636
|
await recordAudit(dependencies, "wallet.import", { wallet: imported.name });
|
|
109376
109637
|
const account = imported.account;
|
|
109377
|
-
if (!await
|
|
109638
|
+
if (!await fileExists3(paths.config)) {
|
|
109378
109639
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
109379
109640
|
} else {
|
|
109380
109641
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -109382,7 +109643,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109382
109643
|
const result = {
|
|
109383
109644
|
address: account.address,
|
|
109384
109645
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
109385
|
-
vault:
|
|
109646
|
+
vault: join30(paths.directory, "vault.json"),
|
|
109386
109647
|
...previousKeystore ? { previousKeystore } : {},
|
|
109387
109648
|
message: "Wallet imported. Its encrypted key stays on this machine."
|
|
109388
109649
|
};
|
|
@@ -109990,9 +110251,9 @@ function isHttpUrl(value) {
|
|
|
109990
110251
|
return false;
|
|
109991
110252
|
}
|
|
109992
110253
|
}
|
|
109993
|
-
async function
|
|
110254
|
+
async function fileExists3(path) {
|
|
109994
110255
|
try {
|
|
109995
|
-
await
|
|
110256
|
+
await stat18(path);
|
|
109996
110257
|
return true;
|
|
109997
110258
|
} catch (error61) {
|
|
109998
110259
|
if (isMissingFile(error61)) return false;
|
|
@@ -110056,7 +110317,7 @@ async function latestNotice(options, env, signal) {
|
|
|
110056
110317
|
const now = (options.nowMs ?? Date.now)();
|
|
110057
110318
|
let cached2;
|
|
110058
110319
|
try {
|
|
110059
|
-
const value = JSON.parse(await
|
|
110320
|
+
const value = JSON.parse(await readFile32(paths.updateCheck, "utf8"));
|
|
110060
110321
|
if (isRecord13(value) && typeof value.checkedAt === "number" && Number.isFinite(value.checkedAt) && typeof value.latest === "string" && parseVersion(value.latest)) {
|
|
110061
110322
|
cached2 = { checkedAt: value.checkedAt, latest: value.latest };
|
|
110062
110323
|
}
|
|
@@ -110161,7 +110422,7 @@ export {
|
|
|
110161
110422
|
baseUsdcBalanceReader,
|
|
110162
110423
|
confirmWalletName,
|
|
110163
110424
|
deviceVaultKey2 as deviceVaultKey,
|
|
110164
|
-
|
|
110425
|
+
fileExists3 as fileExists,
|
|
110165
110426
|
getEnvironment,
|
|
110166
110427
|
getLinePrompt,
|
|
110167
110428
|
getPrompts,
|