@vapi-network/cli 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1448 -1206
- package/dist/cli.js.map +3 -3
- package/dist/index.js +1447 -1205
- package/dist/index.js.map +3 -3
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/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,505 +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
|
-
var SAFE_FAILURE_DETAILS = [
|
|
70542
|
-
"Cannot autolaunch D-Bus without X11 $DISPLAY",
|
|
70543
|
-
"Cannot autolaunch D-Bus",
|
|
70544
|
-
"The name org.freedesktop.secrets was not provided by any .service files",
|
|
70545
|
-
"Cannot create an item in a locked collection",
|
|
70546
|
-
"User interaction is not allowed.",
|
|
70547
|
-
"Access to the path is denied."
|
|
70548
|
-
];
|
|
70549
|
-
function requireSuccess(result, what) {
|
|
70550
|
-
if (result.code === 0) return;
|
|
70551
|
-
const detail = SAFE_FAILURE_DETAILS.find((reason) => result.stderr.includes(reason));
|
|
70552
|
-
throw new KeystoreError(
|
|
70553
|
-
`Could not ${what}${result.code === null ? "" : ` (exit ${result.code})`}.${detail === void 0 ? "" : ` ${detail}`}`
|
|
70554
|
-
);
|
|
70555
|
-
}
|
|
70556
|
-
function withoutTrailingNewline(value) {
|
|
70557
|
-
return value.replace(/\r?\n$/u, "");
|
|
70558
|
-
}
|
|
70559
|
-
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve3) => {
|
|
70560
|
-
let stdout = "";
|
|
70561
|
-
let stderr2 = "";
|
|
70562
|
-
let settled = false;
|
|
70563
|
-
const finish = (outcome) => {
|
|
70564
|
-
if (settled) return;
|
|
70565
|
-
settled = true;
|
|
70566
|
-
resolve3(outcome);
|
|
70567
|
-
};
|
|
70568
|
-
const child = spawn(file2, [...args], {
|
|
70569
|
-
detached: platform2 !== "win32",
|
|
70570
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
70571
|
-
windowsHide: true
|
|
70572
|
-
});
|
|
70573
|
-
child.stdout?.setEncoding("utf8");
|
|
70574
|
-
child.stdout?.on("data", (chunk) => {
|
|
70575
|
-
stdout += chunk;
|
|
70576
|
-
});
|
|
70577
|
-
child.stderr?.setEncoding("utf8");
|
|
70578
|
-
child.stderr?.on("data", (chunk) => {
|
|
70579
|
-
stderr2 += chunk;
|
|
70580
|
-
});
|
|
70581
|
-
child.on("error", (error61) => {
|
|
70582
|
-
finish({
|
|
70583
|
-
code: null,
|
|
70584
|
-
stdout,
|
|
70585
|
-
stderr: stderr2,
|
|
70586
|
-
...error61.code === "ENOENT" ? { notFound: true } : {}
|
|
70587
|
-
});
|
|
70588
|
-
});
|
|
70589
|
-
child.on("close", (code) => finish({ code, stdout, stderr: stderr2 }));
|
|
70590
|
-
child.stdin?.on("error", () => void 0);
|
|
70591
|
-
child.stdin?.end(input2 ?? "");
|
|
70592
|
-
});
|
|
70593
|
-
|
|
70594
|
-
// ../core/src/passphrase.ts
|
|
70595
|
-
var PASSPHRASE_ENVIRONMENT_VARIABLE = "VAPI_KEYSTORE_PASSWORD";
|
|
70596
|
-
function noPassphraseHint(walletName) {
|
|
70597
|
-
return `Set ${PASSPHRASE_ENVIRONMENT_VARIABLE}, or store this wallet's passphrase once with vapi unlock --wallet ${walletName}.`;
|
|
70598
|
-
}
|
|
70599
|
-
function staleStoredPassphraseMessage(walletName, store) {
|
|
70600
|
-
return [
|
|
70601
|
-
`The passphrase stored in ${store.description} no longer opens wallet ${walletName}.`,
|
|
70602
|
-
`Store the current one with vapi unlock --wallet ${walletName}, or remove it with vapi lock --wallet ${walletName}.`
|
|
70603
|
-
].join(" ");
|
|
70604
|
-
}
|
|
70605
|
-
async function resolvePassphrase(walletName, options = {}) {
|
|
70606
|
-
const env = options.env ?? process.env;
|
|
70607
|
-
const fromEnvironment = env[PASSPHRASE_ENVIRONMENT_VARIABLE];
|
|
70608
|
-
if (fromEnvironment !== void 0) {
|
|
70609
|
-
if (fromEnvironment.length === 0) {
|
|
70610
|
-
throw new KeystoreError(`${PASSPHRASE_ENVIRONMENT_VARIABLE} cannot be empty.`);
|
|
70611
|
-
}
|
|
70612
|
-
return { passphrase: fromEnvironment, source: "environment" };
|
|
70613
|
-
}
|
|
70614
|
-
if (options.confirm !== true) {
|
|
70615
|
-
const stored = await readStored(options.store ?? secretStore(), walletName);
|
|
70616
|
-
if (stored !== void 0) return { passphrase: stored, source: "secret-store" };
|
|
70617
|
-
}
|
|
70618
|
-
const hint = noPassphraseHint(walletName);
|
|
70619
|
-
if (options.interactive === false) {
|
|
70620
|
-
throw new KeystoreError(
|
|
70621
|
-
`No interactive terminal is available for the keystore prompt. ${hint}`
|
|
70622
|
-
);
|
|
70623
|
-
}
|
|
70624
|
-
const prompt = options.prompt ?? promptForSecret;
|
|
70625
|
-
const first = await prompt(`Passphrase for ${walletName}: `, hint);
|
|
70626
|
-
if (first.length === 0) {
|
|
70627
|
-
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
70628
|
-
}
|
|
70629
|
-
if (options.confirm === true) {
|
|
70630
|
-
const second = await prompt("Confirm passphrase: ", hint);
|
|
70631
|
-
if (first !== second) throw new KeystoreError("Passphrases do not match.");
|
|
70632
|
-
}
|
|
70633
|
-
return { passphrase: first, source: "prompt" };
|
|
70634
|
-
}
|
|
70635
|
-
async function readStored(store, walletName) {
|
|
70636
|
-
if (!store.available) return void 0;
|
|
70637
|
-
try {
|
|
70638
|
-
return await store.get(walletName);
|
|
70639
|
-
} catch {
|
|
70640
|
-
return void 0;
|
|
70641
|
-
}
|
|
70642
|
-
}
|
|
70165
|
+
import { delimiter, isAbsolute, join as join7, win32 } from "node:path";
|
|
70643
70166
|
|
|
70644
|
-
// ../core/src/
|
|
70167
|
+
// ../core/src/file-secret-store.ts
|
|
70645
70168
|
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
70646
|
-
import {
|
|
70647
|
-
import { dirname as dirname5 } from "node:path";
|
|
70169
|
+
import { readFile as readFile8, stat as stat7 } from "node:fs/promises";
|
|
70648
70170
|
|
|
70649
|
-
// ../core/src/
|
|
70171
|
+
// ../core/src/vault.ts
|
|
70650
70172
|
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
70651
|
-
|
|
70652
|
-
|
|
70653
|
-
return typeof value === "string" && RUN_ID_PATTERN.test(value);
|
|
70654
|
-
}
|
|
70655
|
-
function createRunId(random = randomBytes5) {
|
|
70656
|
-
return `run_${Buffer.from(random(12)).toString("hex")}`;
|
|
70657
|
-
}
|
|
70658
|
-
var runRefSchema = external_exports.strictObject({
|
|
70659
|
-
id: external_exports.string().regex(RUN_ID_PATTERN),
|
|
70660
|
-
swarm: external_exports.string().optional(),
|
|
70661
|
-
member: external_exports.string().optional(),
|
|
70662
|
-
parentRunId: external_exports.string().optional()
|
|
70663
|
-
});
|
|
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";
|
|
70664
70175
|
|
|
70665
70176
|
// ../core/src/wallet-name.ts
|
|
70666
70177
|
var DEFAULT_WALLET_NAME = "main";
|
|
@@ -70673,260 +70184,7 @@ function isWalletName(value) {
|
|
|
70673
70184
|
return WALLET_NAME_PATTERN.test(value);
|
|
70674
70185
|
}
|
|
70675
70186
|
|
|
70676
|
-
// ../core/src/receipts.ts
|
|
70677
|
-
var receiptTestHooks;
|
|
70678
|
-
var RECEIPT_JOURNAL_BUSY_MESSAGE = "The receipt journal is busy. Wait for the other vapi command to finish, then retry.";
|
|
70679
|
-
async function withReceiptJournalLock(path, operation) {
|
|
70680
|
-
return await withFileLock(`${path}.lock`, operation, {
|
|
70681
|
-
lockedMessage: RECEIPT_JOURNAL_BUSY_MESSAGE
|
|
70682
|
-
});
|
|
70683
|
-
}
|
|
70684
|
-
var durationSchema = external_exports.number().nonnegative().finite();
|
|
70685
|
-
var receiptSchema = external_exports.strictObject({
|
|
70686
|
-
id: external_exports.string().min(1),
|
|
70687
|
-
timestamp: external_exports.iso.datetime(),
|
|
70688
|
-
run: runRefSchema.optional(),
|
|
70689
|
-
kind: external_exports.literal("transfer").optional(),
|
|
70690
|
-
wallet: walletNameSchema.optional(),
|
|
70691
|
-
resourceUrl: external_exports.url(),
|
|
70692
|
-
method: external_exports.string().min(1).optional(),
|
|
70693
|
-
source: external_exports.string().min(1).optional(),
|
|
70694
|
-
provenance: external_exports.array(
|
|
70695
|
-
external_exports.strictObject({
|
|
70696
|
-
source: external_exports.string().min(1),
|
|
70697
|
-
sourceUrl: external_exports.string().optional(),
|
|
70698
|
-
ref: external_exports.string().optional()
|
|
70699
|
-
})
|
|
70700
|
-
).optional(),
|
|
70701
|
-
quote: external_exports.strictObject({
|
|
70702
|
-
network: external_exports.string(),
|
|
70703
|
-
asset: external_exports.string().optional(),
|
|
70704
|
-
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
70705
|
-
payTo: external_exports.string().optional()
|
|
70706
|
-
}).optional(),
|
|
70707
|
-
payer: external_exports.string().optional(),
|
|
70708
|
-
paymentId: external_exports.string().regex(/^[A-Za-z0-9_-]{16,128}$/).optional(),
|
|
70709
|
-
authorization: external_exports.strictObject({
|
|
70710
|
-
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70711
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
70712
|
-
validBefore: external_exports.string().regex(/^\d+$/)
|
|
70713
|
-
}).optional(),
|
|
70714
|
-
transfer: external_exports.strictObject({
|
|
70715
|
-
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70716
|
-
toName: external_exports.string().min(1),
|
|
70717
|
-
toKind: external_exports.enum(["owner", "account"]),
|
|
70718
|
-
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
70719
|
-
network: external_exports.string().min(1),
|
|
70720
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
70721
|
-
status: external_exports.enum(["sent", "unknown", "failed"]),
|
|
70722
|
-
txHash: external_exports.string().regex(/^0x[0-9a-fA-F]+$/).nullable(),
|
|
70723
|
-
replayed: external_exports.boolean(),
|
|
70724
|
-
reservedOn: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
70725
|
-
request: external_exports.strictObject({
|
|
70726
|
-
authorization: external_exports.strictObject({
|
|
70727
|
-
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70728
|
-
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
70729
|
-
value: external_exports.string().regex(/^\d+$/),
|
|
70730
|
-
validAfter: external_exports.string().regex(/^\d+$/),
|
|
70731
|
-
validBefore: external_exports.string().regex(/^\d+$/),
|
|
70732
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/)
|
|
70733
|
-
}),
|
|
70734
|
-
signature: external_exports.string().regex(/^0x[0-9a-fA-F]+$/)
|
|
70735
|
-
}).optional()
|
|
70736
|
-
}).optional(),
|
|
70737
|
-
settlement: external_exports.strictObject({
|
|
70738
|
-
outcome: external_exports.enum(["succeeded", "rejected", "unknown"]),
|
|
70739
|
-
transaction: external_exports.string().optional(),
|
|
70740
|
-
explorerUrl: external_exports.url().optional(),
|
|
70741
|
-
evidence: external_exports.unknown().optional()
|
|
70742
|
-
}).optional(),
|
|
70743
|
-
latencyMs: external_exports.number().nonnegative().finite().optional(),
|
|
70744
|
-
status: external_exports.number().int().min(100).max(599).optional(),
|
|
70745
|
-
error: external_exports.strictObject({ code: external_exports.string(), message: external_exports.string() }).optional(),
|
|
70746
|
-
phases: external_exports.strictObject({
|
|
70747
|
-
discoverMs: durationSchema.optional(),
|
|
70748
|
-
quoteMs: durationSchema.optional(),
|
|
70749
|
-
signMs: durationSchema.optional(),
|
|
70750
|
-
requestMs: durationSchema.optional(),
|
|
70751
|
-
settleMs: durationSchema.optional()
|
|
70752
|
-
}).optional(),
|
|
70753
|
-
listing: external_exports.strictObject({
|
|
70754
|
-
name: external_exports.string().min(1).optional(),
|
|
70755
|
-
providerHost: external_exports.string().min(1).optional(),
|
|
70756
|
-
source: external_exports.string().min(1)
|
|
70757
|
-
}).optional(),
|
|
70758
|
-
retry: external_exports.number().int().nonnegative().optional(),
|
|
70759
|
-
policy: external_exports.strictObject({
|
|
70760
|
-
maxPriceUsd: external_exports.string().regex(/^\d+(?:\.\d{1,6})?$/).optional(),
|
|
70761
|
-
capsApplied: external_exports.boolean()
|
|
70762
|
-
}).optional(),
|
|
70763
|
-
client: external_exports.strictObject({ name: external_exports.literal("vapi-network"), version: external_exports.string().min(1) }).optional(),
|
|
70764
|
-
outcome: external_exports.enum([
|
|
70765
|
-
"paid",
|
|
70766
|
-
"signed_in",
|
|
70767
|
-
"declined_policy",
|
|
70768
|
-
"failed_request",
|
|
70769
|
-
"settlement_rejected",
|
|
70770
|
-
"settlement_unknown"
|
|
70771
|
-
]).optional()
|
|
70772
|
-
});
|
|
70773
|
-
function parseReceipt(value) {
|
|
70774
|
-
const receipt = receiptSchema.parse(value);
|
|
70775
|
-
const transaction2 = receipt.settlement?.transaction;
|
|
70776
|
-
const network = receipt.quote?.network;
|
|
70777
|
-
const explorerUrl = transaction2 === void 0 || network === void 0 ? void 0 : explorerTransactionUrl(network, transaction2);
|
|
70778
|
-
if (explorerUrl === void 0 || receipt.settlement?.explorerUrl === explorerUrl) {
|
|
70779
|
-
return receipt;
|
|
70780
|
-
}
|
|
70781
|
-
return {
|
|
70782
|
-
...receipt,
|
|
70783
|
-
settlement: {
|
|
70784
|
-
outcome: receipt.settlement.outcome,
|
|
70785
|
-
...receipt.settlement.transaction ? { transaction: receipt.settlement.transaction } : {},
|
|
70786
|
-
explorerUrl,
|
|
70787
|
-
...receipt.settlement.evidence === void 0 ? {} : { evidence: receipt.settlement.evidence }
|
|
70788
|
-
}
|
|
70789
|
-
};
|
|
70790
|
-
}
|
|
70791
|
-
async function appendReceipt(receipt, path = getVapiPaths().receipts, options = {}) {
|
|
70792
|
-
const parsed = parseReceipt(
|
|
70793
|
-
receipt.wallet === void 0 && options.wallet !== void 0 ? { ...receipt, wallet: options.wallet } : receipt
|
|
70794
|
-
);
|
|
70795
|
-
await withReceiptJournalLock(path, async () => {
|
|
70796
|
-
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70797
|
-
const handle = await open5(path, "a", 384);
|
|
70798
|
-
try {
|
|
70799
|
-
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
70800
|
-
`, "utf8");
|
|
70801
|
-
} finally {
|
|
70802
|
-
await handle.close();
|
|
70803
|
-
}
|
|
70804
|
-
});
|
|
70805
|
-
return parsed;
|
|
70806
|
-
}
|
|
70807
|
-
async function readReceipts(path = getVapiPaths().receipts, options = {}) {
|
|
70808
|
-
let raw;
|
|
70809
|
-
try {
|
|
70810
|
-
raw = await readFile7(path, "utf8");
|
|
70811
|
-
} catch (error61) {
|
|
70812
|
-
if (isMissingFile(error61)) return [];
|
|
70813
|
-
throw error61;
|
|
70814
|
-
}
|
|
70815
|
-
const records = coalesceTransferReceiptRevisions(
|
|
70816
|
-
raw.split("\n").filter((line) => line.trim().length > 0).map((line, index2) => {
|
|
70817
|
-
try {
|
|
70818
|
-
return parseReceipt(JSON.parse(line));
|
|
70819
|
-
} catch (error61) {
|
|
70820
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70821
|
-
}
|
|
70822
|
-
})
|
|
70823
|
-
);
|
|
70824
|
-
const filtered = options.wallet === void 0 ? records : filterReceiptsByWallet(records, options.wallet);
|
|
70825
|
-
const limit = options.limit;
|
|
70826
|
-
if (limit === void 0) return filtered;
|
|
70827
|
-
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
70828
|
-
throw new Error("Receipt limit must be a non-negative integer.");
|
|
70829
|
-
return limit === 0 ? [] : filtered.slice(-limit);
|
|
70830
|
-
}
|
|
70831
|
-
function coalesceTransferReceiptRevisions(receipts) {
|
|
70832
|
-
const coalesced = [];
|
|
70833
|
-
const transferIndexes = /* @__PURE__ */ new Map();
|
|
70834
|
-
for (const receipt of receipts) {
|
|
70835
|
-
const existing = receipt.kind === "transfer" ? transferIndexes.get(receipt.id) : void 0;
|
|
70836
|
-
if (existing === void 0) {
|
|
70837
|
-
if (receipt.kind === "transfer") transferIndexes.set(receipt.id, coalesced.length);
|
|
70838
|
-
coalesced.push(receipt);
|
|
70839
|
-
} else {
|
|
70840
|
-
coalesced[existing] = receipt;
|
|
70841
|
-
}
|
|
70842
|
-
}
|
|
70843
|
-
return coalesced;
|
|
70844
|
-
}
|
|
70845
|
-
function receiptWallet(receipt) {
|
|
70846
|
-
return receipt.wallet ?? DEFAULT_WALLET_NAME;
|
|
70847
|
-
}
|
|
70848
|
-
function filterReceiptsByWallet(receipts, name) {
|
|
70849
|
-
return receipts.filter((receipt) => receiptWallet(receipt) === name);
|
|
70850
|
-
}
|
|
70851
|
-
async function renameReceiptWallet(from16, to, path = getVapiPaths().receipts) {
|
|
70852
|
-
return await withReceiptJournalLock(path, async () => {
|
|
70853
|
-
let raw;
|
|
70854
|
-
try {
|
|
70855
|
-
raw = await readFile7(path, "utf8");
|
|
70856
|
-
} catch (error61) {
|
|
70857
|
-
if (isMissingFile(error61)) return 0;
|
|
70858
|
-
throw error61;
|
|
70859
|
-
}
|
|
70860
|
-
let changed = 0;
|
|
70861
|
-
const lines = raw.split("\n").map((line, index2) => {
|
|
70862
|
-
if (line.trim().length === 0) return line;
|
|
70863
|
-
let parsed;
|
|
70864
|
-
try {
|
|
70865
|
-
parsed = JSON.parse(line);
|
|
70866
|
-
} catch (error61) {
|
|
70867
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70868
|
-
}
|
|
70869
|
-
const current = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "wallet") : void 0;
|
|
70870
|
-
if ((typeof current === "string" ? current : DEFAULT_WALLET_NAME) !== from16) return line;
|
|
70871
|
-
changed += 1;
|
|
70872
|
-
return JSON.stringify(parseReceipt({ ...parsed, wallet: to }));
|
|
70873
|
-
});
|
|
70874
|
-
if (changed === 0) return 0;
|
|
70875
|
-
await receiptTestHooks?.beforeRenameReplace?.(path);
|
|
70876
|
-
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
70877
|
-
const temporaryPath = `${path}.${process.pid}.${randomBytes6(6).toString("hex")}.tmp`;
|
|
70878
|
-
await writeFile3(temporaryPath, lines.join("\n"), {
|
|
70879
|
-
encoding: "utf8",
|
|
70880
|
-
mode: 384,
|
|
70881
|
-
flag: "wx"
|
|
70882
|
-
});
|
|
70883
|
-
await rename4(temporaryPath, path);
|
|
70884
|
-
return changed;
|
|
70885
|
-
});
|
|
70886
|
-
}
|
|
70887
|
-
|
|
70888
|
-
// ../core/src/transfer-journal.ts
|
|
70889
|
-
import { readFile as readFile8 } from "node:fs/promises";
|
|
70890
|
-
async function readTransferJournal(home, from16, nonce) {
|
|
70891
|
-
let raw;
|
|
70892
|
-
try {
|
|
70893
|
-
raw = await readFile8(getVapiPaths(home).receipts, "utf8");
|
|
70894
|
-
} catch (error61) {
|
|
70895
|
-
if (isMissingFile(error61)) return { signed: false };
|
|
70896
|
-
throw error61;
|
|
70897
|
-
}
|
|
70898
|
-
let latest;
|
|
70899
|
-
let request;
|
|
70900
|
-
for (const [index2, line] of raw.split("\n").entries()) {
|
|
70901
|
-
if (!line.trim()) continue;
|
|
70902
|
-
let receipt;
|
|
70903
|
-
try {
|
|
70904
|
-
receipt = parseReceipt(JSON.parse(line));
|
|
70905
|
-
} catch (error61) {
|
|
70906
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
70907
|
-
}
|
|
70908
|
-
if (receiptWallet(receipt) !== from16 || receipt.transfer?.nonce.toLowerCase() !== nonce.toLowerCase()) {
|
|
70909
|
-
continue;
|
|
70910
|
-
}
|
|
70911
|
-
latest = receipt;
|
|
70912
|
-
if (receipt.transfer.request !== void 0) request = receipt;
|
|
70913
|
-
}
|
|
70914
|
-
return {
|
|
70915
|
-
signed: latest !== void 0,
|
|
70916
|
-
...latest === void 0 ? {} : { latest },
|
|
70917
|
-
...request === void 0 ? {} : { request },
|
|
70918
|
-
...request?.transfer?.request?.authorization.validBefore === void 0 ? {} : { validBefore: request.transfer.request.authorization.validBefore },
|
|
70919
|
-
...(latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn) === void 0 ? {} : { reservedOn: latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn }
|
|
70920
|
-
};
|
|
70921
|
-
}
|
|
70922
|
-
|
|
70923
|
-
// ../core/src/vault-key.ts
|
|
70924
|
-
import { randomBytes as cryptoRandomBytes } from "node:crypto";
|
|
70925
|
-
|
|
70926
70187
|
// ../core/src/vault.ts
|
|
70927
|
-
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
70928
|
-
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";
|
|
70929
|
-
import { dirname as dirname6 } from "node:path";
|
|
70930
70188
|
var VaultError = class extends Error {
|
|
70931
70189
|
code;
|
|
70932
70190
|
constructor(code, message, options) {
|
|
@@ -71317,244 +70575,1222 @@ async function exportVaultAccountKey(args) {
|
|
|
71317
70575
|
throw asVaultError(error61, "corrupt", "Unable to export the vault account key.");
|
|
71318
70576
|
}
|
|
71319
70577
|
}
|
|
71320
|
-
async function exportMemberKey(args) {
|
|
71321
|
-
return await exportVaultAccountKey(args);
|
|
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(" ");
|
|
71322
71484
|
}
|
|
71323
|
-
function
|
|
71324
|
-
|
|
71325
|
-
|
|
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" };
|
|
71326
71493
|
}
|
|
71327
|
-
|
|
71328
|
-
|
|
71329
|
-
|
|
71330
|
-
if (!parsed.success) {
|
|
71331
|
-
throw new VaultError("name_taken", "The vault account name is not valid.", {
|
|
71332
|
-
cause: parsed.error
|
|
71333
|
-
});
|
|
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" };
|
|
71334
71497
|
}
|
|
71335
|
-
|
|
71336
|
-
|
|
71337
|
-
|
|
71338
|
-
|
|
71339
|
-
|
|
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
|
+
);
|
|
71503
|
+
}
|
|
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.");
|
|
71340
71512
|
}
|
|
71513
|
+
return { passphrase: first, source: "prompt" };
|
|
71341
71514
|
}
|
|
71342
|
-
function
|
|
71343
|
-
|
|
71344
|
-
|
|
71345
|
-
|
|
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;
|
|
71346
71521
|
}
|
|
71347
|
-
return next;
|
|
71348
71522
|
}
|
|
71349
|
-
|
|
71350
|
-
|
|
71351
|
-
|
|
71352
|
-
|
|
71353
|
-
|
|
71354
|
-
|
|
71355
|
-
|
|
71356
|
-
|
|
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);
|
|
71357
71534
|
}
|
|
71358
|
-
function
|
|
71359
|
-
|
|
71360
|
-
return [nonce, ciphertext, tag].map((part) => part.toString("base64url")).join(".");
|
|
71535
|
+
function createRunId(random = randomBytes7) {
|
|
71536
|
+
return `run_${Buffer.from(random(12)).toString("hex")}`;
|
|
71361
71537
|
}
|
|
71362
|
-
|
|
71363
|
-
|
|
71364
|
-
|
|
71365
|
-
|
|
71366
|
-
|
|
71367
|
-
|
|
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
|
|
71368
71551
|
});
|
|
71369
71552
|
}
|
|
71370
|
-
|
|
71371
|
-
|
|
71372
|
-
|
|
71373
|
-
|
|
71374
|
-
|
|
71375
|
-
|
|
71376
|
-
|
|
71377
|
-
|
|
71378
|
-
|
|
71379
|
-
|
|
71380
|
-
|
|
71381
|
-
|
|
71382
|
-
|
|
71383
|
-
|
|
71384
|
-
|
|
71385
|
-
})
|
|
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;
|
|
71386
71649
|
}
|
|
71387
|
-
|
|
71388
|
-
|
|
71389
|
-
|
|
71390
|
-
|
|
71391
|
-
|
|
71392
|
-
|
|
71393
|
-
|
|
71394
|
-
}
|
|
71395
|
-
let address4;
|
|
71396
|
-
try {
|
|
71397
|
-
address4 = privateKeyToAccount(`0x${plaintext.toString("hex")}`).address;
|
|
71398
|
-
} catch (error61) {
|
|
71399
|
-
throw new VaultError("bad_key", "The stored imported key is not valid.", {
|
|
71400
|
-
cause: error61
|
|
71401
|
-
});
|
|
71402
|
-
}
|
|
71403
|
-
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
71404
|
-
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 }
|
|
71405
71657
|
}
|
|
71406
|
-
}
|
|
71407
|
-
plaintext?.fill(0);
|
|
71408
|
-
}
|
|
71658
|
+
};
|
|
71409
71659
|
}
|
|
71410
|
-
function
|
|
71411
|
-
const
|
|
71412
|
-
|
|
71413
|
-
|
|
71414
|
-
|
|
71415
|
-
|
|
71416
|
-
|
|
71417
|
-
|
|
71418
|
-
|
|
71419
|
-
|
|
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();
|
|
71420
71672
|
}
|
|
71421
|
-
}
|
|
71422
|
-
|
|
71423
|
-
plaintext.fill(0);
|
|
71424
|
-
}
|
|
71673
|
+
});
|
|
71674
|
+
return parsed;
|
|
71425
71675
|
}
|
|
71426
|
-
function
|
|
71427
|
-
let
|
|
71676
|
+
async function readReceipts(path = getVapiPaths().receipts, options = {}) {
|
|
71677
|
+
let raw;
|
|
71428
71678
|
try {
|
|
71429
|
-
|
|
71679
|
+
raw = await readFile9(path, "utf8");
|
|
71430
71680
|
} catch (error61) {
|
|
71431
|
-
|
|
71432
|
-
|
|
71433
|
-
const parsed = vaultFileSchema.safeParse(value);
|
|
71434
|
-
if (!parsed.success) {
|
|
71435
|
-
throw new VaultError("corrupt", "The vault file has an invalid structure.", {
|
|
71436
|
-
cause: parsed.error
|
|
71437
|
-
});
|
|
71438
|
-
}
|
|
71439
|
-
if (parsed.data.protected !== (parsed.data.wrappedKey !== void 0)) {
|
|
71440
|
-
throw new VaultError("corrupt", "The vault protection metadata is inconsistent.");
|
|
71681
|
+
if (isMissingFile(error61)) return [];
|
|
71682
|
+
throw error61;
|
|
71441
71683
|
}
|
|
71442
|
-
const
|
|
71443
|
-
|
|
71444
|
-
|
|
71445
|
-
|
|
71446
|
-
|
|
71447
|
-
|
|
71448
|
-
names.add(account.name);
|
|
71449
|
-
if (account.kind === "derived") {
|
|
71450
|
-
if (indexes.has(account.index)) {
|
|
71451
|
-
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 });
|
|
71452
71690
|
}
|
|
71453
|
-
|
|
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;
|
|
71454
71710
|
}
|
|
71455
71711
|
}
|
|
71456
|
-
return
|
|
71712
|
+
return coalesced;
|
|
71457
71713
|
}
|
|
71458
|
-
|
|
71459
|
-
|
|
71460
|
-
|
|
71461
|
-
|
|
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;
|
|
71462
71723
|
try {
|
|
71463
|
-
|
|
71724
|
+
raw = await readFile9(path, "utf8");
|
|
71464
71725
|
} catch (error61) {
|
|
71465
|
-
|
|
71466
|
-
|
|
71467
|
-
});
|
|
71468
|
-
}
|
|
71469
|
-
} finally {
|
|
71470
|
-
plaintext.fill(0);
|
|
71471
|
-
}
|
|
71472
|
-
return file2;
|
|
71473
|
-
}
|
|
71474
|
-
async function readVaultFileUnlocked(path) {
|
|
71475
|
-
let raw;
|
|
71476
|
-
try {
|
|
71477
|
-
raw = await readFile9(path, "utf8");
|
|
71478
|
-
} catch (error61) {
|
|
71479
|
-
if (isMissingFile2(error61)) {
|
|
71480
|
-
throw new VaultError("not_found", "No vault file was found at the requested path.", {
|
|
71481
|
-
cause: error61
|
|
71482
|
-
});
|
|
71726
|
+
if (isMissingFile(error61)) return 0;
|
|
71727
|
+
throw error61;
|
|
71483
71728
|
}
|
|
71484
|
-
|
|
71485
|
-
|
|
71486
|
-
|
|
71487
|
-
|
|
71488
|
-
|
|
71489
|
-
|
|
71490
|
-
|
|
71491
|
-
|
|
71492
|
-
|
|
71493
|
-
|
|
71494
|
-
|
|
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 }));
|
|
71495
71742
|
});
|
|
71496
|
-
|
|
71497
|
-
|
|
71498
|
-
}
|
|
71499
|
-
|
|
71500
|
-
|
|
71501
|
-
const temporaryPath = `${path}.${process.pid}.${randomBytes7(6).toString("hex")}.tmp`;
|
|
71502
|
-
try {
|
|
71503
|
-
await writeFile4(temporaryPath, `${JSON.stringify(file2, null, 2)}
|
|
71504
|
-
`, {
|
|
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"), {
|
|
71505
71748
|
encoding: "utf8",
|
|
71506
71749
|
mode: 384,
|
|
71507
71750
|
flag: "wx"
|
|
71508
71751
|
});
|
|
71509
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");
|
|
71510
71763
|
} catch (error61) {
|
|
71511
|
-
|
|
71764
|
+
if (isMissingFile(error61)) return { signed: false };
|
|
71512
71765
|
throw error61;
|
|
71513
71766
|
}
|
|
71514
|
-
|
|
71515
|
-
|
|
71516
|
-
|
|
71517
|
-
|
|
71518
|
-
|
|
71519
|
-
let handle;
|
|
71520
|
-
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;
|
|
71521
71772
|
try {
|
|
71522
|
-
|
|
71773
|
+
receipt = parseReceipt(JSON.parse(line));
|
|
71523
71774
|
} catch (error61) {
|
|
71524
|
-
|
|
71525
|
-
await removeStaleVaultLock(lockPath);
|
|
71526
|
-
if (Date.now() >= deadline) {
|
|
71527
|
-
throw new VaultError("corrupt", "Timed out waiting for the vault lock.");
|
|
71528
|
-
}
|
|
71529
|
-
await new Promise((resolve3) => setTimeout(resolve3, 20));
|
|
71775
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71530
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;
|
|
71531
71782
|
}
|
|
71532
|
-
|
|
71533
|
-
|
|
71534
|
-
|
|
71535
|
-
|
|
71536
|
-
|
|
71537
|
-
|
|
71538
|
-
}
|
|
71539
|
-
async function removeStaleVaultLock(path) {
|
|
71540
|
-
try {
|
|
71541
|
-
const metadata = await stat6(path);
|
|
71542
|
-
if (Date.now() - metadata.mtimeMs > STALE_VAULT_LOCK_MS) await unlink4(path);
|
|
71543
|
-
} catch (error61) {
|
|
71544
|
-
if (!isMissingFile2(error61)) throw error61;
|
|
71545
|
-
}
|
|
71546
|
-
}
|
|
71547
|
-
function isMissingFile2(error61) {
|
|
71548
|
-
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "ENOENT";
|
|
71549
|
-
}
|
|
71550
|
-
function isExistingFile(error61) {
|
|
71551
|
-
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "EEXIST";
|
|
71552
|
-
}
|
|
71553
|
-
function asVaultError(error61, code, message) {
|
|
71554
|
-
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
|
+
};
|
|
71555
71790
|
}
|
|
71556
71791
|
|
|
71557
71792
|
// ../core/src/vault-key.ts
|
|
71793
|
+
import { randomBytes as cryptoRandomBytes } from "node:crypto";
|
|
71558
71794
|
var VAULT_KEY_ACCOUNT = "vault-key";
|
|
71559
71795
|
var VAULT_SESSION_ACCOUNT = "vault-session";
|
|
71560
71796
|
var DEVICE_KEY_LENGTH = 32;
|
|
@@ -71782,8 +72018,8 @@ function passwordRequiredError() {
|
|
|
71782
72018
|
"A vault password is needed. Pass it or set VAPI_VAULT_PASSWORD."
|
|
71783
72019
|
);
|
|
71784
72020
|
}
|
|
71785
|
-
function randomKeyBytes(
|
|
71786
|
-
const key2 = Buffer.from((
|
|
72021
|
+
function randomKeyBytes(randomBytes18) {
|
|
72022
|
+
const key2 = Buffer.from((randomBytes18 ?? cryptoRandomBytes)(DEVICE_KEY_LENGTH));
|
|
71787
72023
|
if (key2.byteLength !== DEVICE_KEY_LENGTH) {
|
|
71788
72024
|
key2.fill(0);
|
|
71789
72025
|
throw new VaultError("corrupt", "A generated device vault key has the wrong length.");
|
|
@@ -71834,7 +72070,7 @@ function parseJson(value) {
|
|
|
71834
72070
|
function asVaultError2(error61, message) {
|
|
71835
72071
|
return error61 instanceof VaultError ? error61 : new VaultError("corrupt", message, { cause: error61 });
|
|
71836
72072
|
}
|
|
71837
|
-
var HEADLESS_LINUX_HINT = "A server, container or GitHub Codespace usually has no keyring.
|
|
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.";
|
|
71838
72074
|
function deviceKeyFailureMessage(error61, platform2) {
|
|
71839
72075
|
if (!(error61 instanceof KeystoreError)) return "Unable to load or create the device vault key.";
|
|
71840
72076
|
const detail = `Unable to load or create the device vault key: ${error61.message.replace(/\.$/u, "")}.`;
|
|
@@ -71846,19 +72082,19 @@ import {
|
|
|
71846
72082
|
chmod as chmod2,
|
|
71847
72083
|
lstat,
|
|
71848
72084
|
mkdir as mkdir9,
|
|
71849
|
-
readFile as
|
|
72085
|
+
readFile as readFile11,
|
|
71850
72086
|
readlink,
|
|
71851
72087
|
readdir as readdir2,
|
|
71852
72088
|
rename as rename6,
|
|
71853
72089
|
symlink,
|
|
71854
72090
|
unlink as unlink5
|
|
71855
72091
|
} from "node:fs/promises";
|
|
71856
|
-
import { join as
|
|
72092
|
+
import { join as join8, resolve } from "node:path";
|
|
71857
72093
|
var MIGRATED_DIRECTORY = "wallets.migrated";
|
|
71858
72094
|
async function legacyKeystoreNames(home) {
|
|
71859
72095
|
let entries;
|
|
71860
72096
|
try {
|
|
71861
|
-
entries = await readdir2(
|
|
72097
|
+
entries = await readdir2(join8(home, "wallets"), { withFileTypes: true });
|
|
71862
72098
|
} catch (error61) {
|
|
71863
72099
|
if (isMissingFile(error61)) return [];
|
|
71864
72100
|
throw error61;
|
|
@@ -71874,14 +72110,14 @@ async function migrateKeystores(args) {
|
|
|
71874
72110
|
);
|
|
71875
72111
|
const result = { imported: [], skipped: [] };
|
|
71876
72112
|
for (const name of names) {
|
|
71877
|
-
const source =
|
|
72113
|
+
const source = join8(args.home, "wallets", `${name}.json`);
|
|
71878
72114
|
if (args.vault.accounts().some((account) => account.name === name)) {
|
|
71879
72115
|
result.skipped.push({ name, reason: "name_taken" });
|
|
71880
72116
|
continue;
|
|
71881
72117
|
}
|
|
71882
72118
|
let parsed;
|
|
71883
72119
|
try {
|
|
71884
|
-
parsed = parseAnyKeystore(JSON.parse(await
|
|
72120
|
+
parsed = parseAnyKeystore(JSON.parse(await readFile11(source, "utf8")));
|
|
71885
72121
|
} catch {
|
|
71886
72122
|
result.skipped.push({ name, reason: "unreadable" });
|
|
71887
72123
|
continue;
|
|
@@ -71911,15 +72147,15 @@ async function migrateKeystores(args) {
|
|
|
71911
72147
|
if (imported.address.toLowerCase() !== parsed.address.toLowerCase()) {
|
|
71912
72148
|
throw new KeystoreError(`Migrated wallet ${name} does not match its stored address.`);
|
|
71913
72149
|
}
|
|
71914
|
-
const migratedDirectory =
|
|
71915
|
-
const destination =
|
|
72150
|
+
const migratedDirectory = join8(args.home, MIGRATED_DIRECTORY);
|
|
72151
|
+
const destination = join8(migratedDirectory, `${name}.json`);
|
|
71916
72152
|
await mkdir9(migratedDirectory, { recursive: true, mode: 448 });
|
|
71917
72153
|
await archiveExistingDestination(destination, migratedDirectory, name, now);
|
|
71918
72154
|
await rename6(source, destination);
|
|
71919
72155
|
await chmod2(destination, 384);
|
|
71920
72156
|
try {
|
|
71921
72157
|
await removeCompatibilityLink(args.home, source);
|
|
71922
|
-
await symlink(
|
|
72158
|
+
await symlink(join8("..", MIGRATED_DIRECTORY, `${name}.json`), source);
|
|
71923
72159
|
await audit({
|
|
71924
72160
|
event: "vault.migrate",
|
|
71925
72161
|
wallet: name,
|
|
@@ -71947,16 +72183,16 @@ async function migrateKeystores(args) {
|
|
|
71947
72183
|
async function archiveExistingDestination(destination, directory, name, now) {
|
|
71948
72184
|
if (!await pathExists2(destination)) return;
|
|
71949
72185
|
const timestamp = now().toISOString();
|
|
71950
|
-
let archive =
|
|
72186
|
+
let archive = join8(directory, `${name}.${timestamp}.json`);
|
|
71951
72187
|
let suffix = 1;
|
|
71952
72188
|
while (await pathExists2(archive)) {
|
|
71953
|
-
archive =
|
|
72189
|
+
archive = join8(directory, `${name}.${timestamp}.${suffix}.json`);
|
|
71954
72190
|
suffix += 1;
|
|
71955
72191
|
}
|
|
71956
72192
|
await rename6(destination, archive);
|
|
71957
72193
|
}
|
|
71958
72194
|
async function removeCompatibilityLink(home, migratedSource) {
|
|
71959
|
-
const compatibilityPath =
|
|
72195
|
+
const compatibilityPath = join8(home, "keystore.json");
|
|
71960
72196
|
let metadata;
|
|
71961
72197
|
try {
|
|
71962
72198
|
metadata = await lstat(compatibilityPath);
|
|
@@ -72030,7 +72266,7 @@ var WalletStore = class _WalletStore {
|
|
|
72030
72266
|
this.home = home;
|
|
72031
72267
|
this.options = options;
|
|
72032
72268
|
this.registry = registry2;
|
|
72033
|
-
this.secrets = options.secrets ?? secretStore();
|
|
72269
|
+
this.secrets = options.secrets ?? secretStore({ home });
|
|
72034
72270
|
this.environment = options.env ?? process.env;
|
|
72035
72271
|
this.passphraseResolver = options.resolvePassphrase ?? defaultPassphraseResolver(this.environment, this.secrets);
|
|
72036
72272
|
this.audit = options.audit ?? (async (record2) => await appendAudit(this.home, record2, { now: () => this.now() }));
|
|
@@ -72077,17 +72313,17 @@ var WalletStore = class _WalletStore {
|
|
|
72077
72313
|
return store;
|
|
72078
72314
|
}
|
|
72079
72315
|
get registryPath() {
|
|
72080
|
-
return
|
|
72316
|
+
return join9(this.home, REGISTRY_FILE);
|
|
72081
72317
|
}
|
|
72082
72318
|
get walletsDirectory() {
|
|
72083
|
-
return
|
|
72319
|
+
return join9(this.home, WALLETS_DIRECTORY);
|
|
72084
72320
|
}
|
|
72085
72321
|
get trashDirectory() {
|
|
72086
|
-
return
|
|
72322
|
+
return join9(this.walletsDirectory, TRASH_DIRECTORY);
|
|
72087
72323
|
}
|
|
72088
72324
|
/** The legacy 0.5 keystore path of a wallet, whether or not it exists. */
|
|
72089
72325
|
pathFor(name) {
|
|
72090
|
-
return
|
|
72326
|
+
return join9(this.walletsDirectory, `${assertWalletName(name)}.json`);
|
|
72091
72327
|
}
|
|
72092
72328
|
/** The names this machine knows, in registry order. */
|
|
72093
72329
|
names() {
|
|
@@ -72660,7 +72896,7 @@ var WalletStore = class _WalletStore {
|
|
|
72660
72896
|
}
|
|
72661
72897
|
const removedAt = this.now().toISOString();
|
|
72662
72898
|
await mkdir10(this.trashDirectory, { recursive: true, mode: 448 });
|
|
72663
|
-
const trashedPath =
|
|
72899
|
+
const trashedPath = join9(this.trashDirectory, `${wallet.name}-${removedAt}.json`);
|
|
72664
72900
|
const storedAccount = (await this.readVaultUnlocked())?.accounts.find(
|
|
72665
72901
|
(candidate) => candidate.name === wallet.name
|
|
72666
72902
|
);
|
|
@@ -72682,7 +72918,7 @@ var WalletStore = class _WalletStore {
|
|
|
72682
72918
|
this.balanceProbe = void 0;
|
|
72683
72919
|
}
|
|
72684
72920
|
if (await pathExists3(wallet.path)) {
|
|
72685
|
-
const legacyTrashedPath =
|
|
72921
|
+
const legacyTrashedPath = join9(
|
|
72686
72922
|
this.trashDirectory,
|
|
72687
72923
|
`${wallet.name}-${removedAt}.legacy.json`
|
|
72688
72924
|
);
|
|
@@ -72772,7 +73008,7 @@ var WalletStore = class _WalletStore {
|
|
|
72772
73008
|
if (!match) continue;
|
|
72773
73009
|
const [, name, removedAt] = match;
|
|
72774
73010
|
if (name === void 0 || removedAt === void 0 || !isWalletName(name)) continue;
|
|
72775
|
-
const path =
|
|
73011
|
+
const path = join9(this.trashDirectory, file2);
|
|
72776
73012
|
const entry = await readEntrySidecar(entrySidecarPath(path));
|
|
72777
73013
|
trashed.push({ name, removedAt, path, ...entry ? { entry } : {} });
|
|
72778
73014
|
}
|
|
@@ -72841,7 +73077,7 @@ var WalletStore = class _WalletStore {
|
|
|
72841
73077
|
return entry;
|
|
72842
73078
|
}
|
|
72843
73079
|
get vaultPath() {
|
|
72844
|
-
return
|
|
73080
|
+
return join9(this.home, VAULT_FILE);
|
|
72845
73081
|
}
|
|
72846
73082
|
async readVaultUnlocked() {
|
|
72847
73083
|
try {
|
|
@@ -72946,7 +73182,7 @@ var WalletStore = class _WalletStore {
|
|
|
72946
73182
|
async readRegistry() {
|
|
72947
73183
|
let raw;
|
|
72948
73184
|
try {
|
|
72949
|
-
raw = await
|
|
73185
|
+
raw = await readFile12(this.registryPath, "utf8");
|
|
72950
73186
|
} catch (error61) {
|
|
72951
73187
|
if (isMissingFile(error61)) return emptyRegistry();
|
|
72952
73188
|
throw error61;
|
|
@@ -72967,7 +73203,7 @@ var WalletStore = class _WalletStore {
|
|
|
72967
73203
|
}
|
|
72968
73204
|
};
|
|
72969
73205
|
async function swarmReferencingAccount(home, account) {
|
|
72970
|
-
const directory =
|
|
73206
|
+
const directory = join9(home, "swarms");
|
|
72971
73207
|
let files;
|
|
72972
73208
|
try {
|
|
72973
73209
|
files = await readdir3(directory);
|
|
@@ -72978,7 +73214,7 @@ async function swarmReferencingAccount(home, account) {
|
|
|
72978
73214
|
for (const file2 of files.filter((name) => name.endsWith(".json")).sort()) {
|
|
72979
73215
|
let value;
|
|
72980
73216
|
try {
|
|
72981
|
-
value = JSON.parse(await
|
|
73217
|
+
value = JSON.parse(await readFile12(join9(directory, file2), "utf8"));
|
|
72982
73218
|
} catch {
|
|
72983
73219
|
throw new KeystoreError(
|
|
72984
73220
|
`Cannot verify swarm references because ${file2} is invalid. Repair or remove that swarm file before renaming an account.`
|
|
@@ -73010,7 +73246,7 @@ async function swarmReferencingAccount(home, account) {
|
|
|
73010
73246
|
return void 0;
|
|
73011
73247
|
}
|
|
73012
73248
|
async function unfinishedMovementReferencingAccount(home, account) {
|
|
73013
|
-
const directory =
|
|
73249
|
+
const directory = join9(home, "movements");
|
|
73014
73250
|
let files;
|
|
73015
73251
|
try {
|
|
73016
73252
|
files = await readdir3(directory);
|
|
@@ -73021,7 +73257,7 @@ async function unfinishedMovementReferencingAccount(home, account) {
|
|
|
73021
73257
|
for (const file2 of files.filter((name) => name.endsWith(".json")).sort()) {
|
|
73022
73258
|
let value;
|
|
73023
73259
|
try {
|
|
73024
|
-
value = JSON.parse(await
|
|
73260
|
+
value = JSON.parse(await readFile12(join9(directory, file2), "utf8"));
|
|
73025
73261
|
} catch {
|
|
73026
73262
|
throw invalidMovementReferenceError(file2);
|
|
73027
73263
|
}
|
|
@@ -73042,11 +73278,11 @@ async function unfinishedMovementReferencingAccount(home, account) {
|
|
|
73042
73278
|
const restored = Reflect.get(leg, "restored");
|
|
73043
73279
|
const legFrom = Reflect.get(leg, "from") ?? movementFrom;
|
|
73044
73280
|
const journal = restored !== true && status === "failed" && retryable !== true && typeof nonce === "string" ? await readTransferJournal(home, legFrom, nonce) : void 0;
|
|
73045
|
-
const
|
|
73281
|
+
const open13 = isOpenMovementLeg(
|
|
73046
73282
|
{ status, retryable, nonce, restored },
|
|
73047
73283
|
journal?.signed === true ? "signed" : "unsigned"
|
|
73048
73284
|
);
|
|
73049
|
-
if (
|
|
73285
|
+
if (open13) movementOpen = true;
|
|
73050
73286
|
}
|
|
73051
73287
|
if (movementOpen && (movementFrom === account || legs.some(
|
|
73052
73288
|
(leg) => (Reflect.get(leg, "from") ?? movementFrom) === account || Reflect.get(leg, "to") === account
|
|
@@ -73082,7 +73318,7 @@ async function withAccountMutationLocks(home, accounts, command, operation) {
|
|
|
73082
73318
|
const [account, ...remaining2] = [...new Set(accounts)].sort();
|
|
73083
73319
|
if (account === void 0) return await operation();
|
|
73084
73320
|
return await withFileLock(
|
|
73085
|
-
|
|
73321
|
+
join9(home, `.account-${account}.lock`),
|
|
73086
73322
|
async () => await withAccountMutationLocks(home, remaining2, command, operation),
|
|
73087
73323
|
{
|
|
73088
73324
|
lockedMessage: `Account ${account} is busy with another account change. Wait for it to finish, then retry ${command}.`
|
|
@@ -73157,7 +73393,7 @@ function isLockedVaultError(error61) {
|
|
|
73157
73393
|
async function readTrashedVaultAccount(path) {
|
|
73158
73394
|
let parsed;
|
|
73159
73395
|
try {
|
|
73160
|
-
parsed = JSON.parse(await
|
|
73396
|
+
parsed = JSON.parse(await readFile12(path, "utf8"));
|
|
73161
73397
|
} catch {
|
|
73162
73398
|
return void 0;
|
|
73163
73399
|
}
|
|
@@ -73166,7 +73402,7 @@ async function readTrashedVaultAccount(path) {
|
|
|
73166
73402
|
}
|
|
73167
73403
|
async function readEntrySidecar(path) {
|
|
73168
73404
|
try {
|
|
73169
|
-
const parsed = walletEntrySchema.safeParse(JSON.parse(await
|
|
73405
|
+
const parsed = walletEntrySchema.safeParse(JSON.parse(await readFile12(path, "utf8")));
|
|
73170
73406
|
return parsed.success ? parsed.data : void 0;
|
|
73171
73407
|
} catch {
|
|
73172
73408
|
return void 0;
|
|
@@ -73175,7 +73411,7 @@ async function readEntrySidecar(path) {
|
|
|
73175
73411
|
async function readKeystoreSummary(path) {
|
|
73176
73412
|
let parsed;
|
|
73177
73413
|
try {
|
|
73178
|
-
parsed = JSON.parse(await
|
|
73414
|
+
parsed = JSON.parse(await readFile12(path, "utf8"));
|
|
73179
73415
|
} catch {
|
|
73180
73416
|
return {};
|
|
73181
73417
|
}
|
|
@@ -73193,7 +73429,7 @@ async function readKeystoreSummary(path) {
|
|
|
73193
73429
|
}
|
|
73194
73430
|
async function readConfiguredSpendCaps(configPath) {
|
|
73195
73431
|
try {
|
|
73196
|
-
const parsed = JSON.parse(await
|
|
73432
|
+
const parsed = JSON.parse(await readFile12(configPath, "utf8"));
|
|
73197
73433
|
const caps = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "spendCaps") : void 0;
|
|
73198
73434
|
const result = spendCapsSchema.safeParse(caps);
|
|
73199
73435
|
if (result.success) return result.data;
|
|
@@ -73285,7 +73521,7 @@ async function withRegistryLock(path, operation) {
|
|
|
73285
73521
|
let handle;
|
|
73286
73522
|
while (!handle) {
|
|
73287
73523
|
try {
|
|
73288
|
-
handle = await
|
|
73524
|
+
handle = await open8(lockPath, "wx", 384);
|
|
73289
73525
|
} catch (error61) {
|
|
73290
73526
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) throw error61;
|
|
73291
73527
|
await removeStaleRegistryLock(lockPath);
|
|
@@ -73304,7 +73540,7 @@ async function withRegistryLock(path, operation) {
|
|
|
73304
73540
|
}
|
|
73305
73541
|
async function removeStaleRegistryLock(path) {
|
|
73306
73542
|
try {
|
|
73307
|
-
const metadata = await
|
|
73543
|
+
const metadata = await stat9(path);
|
|
73308
73544
|
if (Date.now() - metadata.mtimeMs > 3e4) await unlink6(path);
|
|
73309
73545
|
} catch (error61) {
|
|
73310
73546
|
if (!isMissingFile(error61)) throw error61;
|
|
@@ -73312,7 +73548,7 @@ async function removeStaleRegistryLock(path) {
|
|
|
73312
73548
|
}
|
|
73313
73549
|
async function writeJsonFile(path, value) {
|
|
73314
73550
|
await mkdir10(dirname7(path), { recursive: true, mode: 448 });
|
|
73315
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
73551
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes9(6).toString("hex")}.tmp`;
|
|
73316
73552
|
await writeFile5(temporaryPath, `${JSON.stringify(value, null, 2)}
|
|
73317
73553
|
`, {
|
|
73318
73554
|
encoding: "utf8",
|
|
@@ -73350,7 +73586,7 @@ async function createAccount(args) {
|
|
|
73350
73586
|
created: false
|
|
73351
73587
|
};
|
|
73352
73588
|
}
|
|
73353
|
-
if (!await
|
|
73589
|
+
if (!await fileExists2(join10(args.store.home, "vault.json"))) {
|
|
73354
73590
|
throw new KeystoreError("No vault yet. Run vapi setup.");
|
|
73355
73591
|
}
|
|
73356
73592
|
const spendCaps = resolveNewAccountCaps(args.caps);
|
|
@@ -73617,9 +73853,9 @@ async function requireAddress(store, name) {
|
|
|
73617
73853
|
if (address4 === void 0) throw new KeystoreError(`No key for wallet ${name} in the vault.`);
|
|
73618
73854
|
return address4;
|
|
73619
73855
|
}
|
|
73620
|
-
async function
|
|
73856
|
+
async function fileExists2(path) {
|
|
73621
73857
|
try {
|
|
73622
|
-
await
|
|
73858
|
+
await stat10(path);
|
|
73623
73859
|
return true;
|
|
73624
73860
|
} catch (error61) {
|
|
73625
73861
|
if (isMissingFile(error61)) return false;
|
|
@@ -73681,9 +73917,9 @@ function secretsAllowed(env, streams) {
|
|
|
73681
73917
|
}
|
|
73682
73918
|
|
|
73683
73919
|
// ../core/src/agent-profile.ts
|
|
73684
|
-
import { randomBytes as
|
|
73685
|
-
import { mkdir as mkdir11, readFile as
|
|
73686
|
-
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";
|
|
73687
73923
|
var DEFAULT_AGENT_TOOLS = ["call.search", "call.inspect", "call.pay"];
|
|
73688
73924
|
var AGENT_GRANTS = ["read", "delegate", "allocate"];
|
|
73689
73925
|
var agentProfileShape = {
|
|
@@ -73713,7 +73949,7 @@ async function readAgentProfile(home, name, options = {}) {
|
|
|
73713
73949
|
const path = agentProfilePath(home, name);
|
|
73714
73950
|
let raw;
|
|
73715
73951
|
try {
|
|
73716
|
-
raw = await
|
|
73952
|
+
raw = await readFile13(path, "utf8");
|
|
73717
73953
|
} catch (error61) {
|
|
73718
73954
|
if (isMissingFile(error61)) {
|
|
73719
73955
|
throw new Error(`No agent named ${name}. Create it with vapi agent create ${name}.`);
|
|
@@ -73725,9 +73961,9 @@ async function readAgentProfile(home, name, options = {}) {
|
|
|
73725
73961
|
async function writeAgentProfile(home, profile, options = {}) {
|
|
73726
73962
|
const parsed = (options.schema ?? agentProfileSchema).parse(profile);
|
|
73727
73963
|
const directory = getVapiPaths(home).agentsDir;
|
|
73728
|
-
const path =
|
|
73964
|
+
const path = join11(directory, `${parsed.name}.json`);
|
|
73729
73965
|
await mkdir11(directory, { recursive: true, mode: 448 });
|
|
73730
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
73966
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes10(6).toString("hex")}.tmp`;
|
|
73731
73967
|
await writeFile6(temporaryPath, `${JSON.stringify(parsed, null, 2)}
|
|
73732
73968
|
`, {
|
|
73733
73969
|
encoding: "utf8",
|
|
@@ -73752,7 +73988,7 @@ async function listAgentProfiles(home, options = {}) {
|
|
|
73752
73988
|
try {
|
|
73753
73989
|
profiles.push(
|
|
73754
73990
|
(options.schema ?? agentProfileSchema).parse(
|
|
73755
|
-
JSON.parse(await
|
|
73991
|
+
JSON.parse(await readFile13(join11(directory, file2), "utf8"))
|
|
73756
73992
|
)
|
|
73757
73993
|
);
|
|
73758
73994
|
} catch {
|
|
@@ -73773,11 +74009,11 @@ async function removeAgentProfile(home, name) {
|
|
|
73773
74009
|
}
|
|
73774
74010
|
function agentProfilePath(home, name) {
|
|
73775
74011
|
const parsedName = walletNameSchema.parse(name);
|
|
73776
|
-
return
|
|
74012
|
+
return join11(getVapiPaths(home).agentsDir, `${parsedName}.json`);
|
|
73777
74013
|
}
|
|
73778
74014
|
|
|
73779
74015
|
// ../core/src/ceiling.ts
|
|
73780
|
-
import { randomBytes as
|
|
74016
|
+
import { randomBytes as randomBytes14 } from "node:crypto";
|
|
73781
74017
|
|
|
73782
74018
|
// ../core/src/authorization-state.ts
|
|
73783
74019
|
var EIP3009_AUTHORIZATION_STATE_ABI = [
|
|
@@ -73842,13 +74078,13 @@ function missingAuthorization(receipt) {
|
|
|
73842
74078
|
}
|
|
73843
74079
|
|
|
73844
74080
|
// ../core/src/movement.ts
|
|
73845
|
-
import { randomBytes as
|
|
73846
|
-
import { chmod as chmod4, mkdir as mkdir14, open as
|
|
73847
|
-
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";
|
|
73848
74084
|
|
|
73849
74085
|
// ../core/src/spend-policy.ts
|
|
73850
|
-
import { randomBytes as
|
|
73851
|
-
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";
|
|
73852
74088
|
import { dirname as dirname8 } from "node:path";
|
|
73853
74089
|
var ledgerSchema = external_exports.object({
|
|
73854
74090
|
date: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
@@ -73919,7 +74155,7 @@ async function readSpendLedgerRows(path = getAgentCashPaths().ledger, now = /* @
|
|
|
73919
74155
|
async function readStoredSpendLedgerRows(path, now, allDays = false) {
|
|
73920
74156
|
let raw;
|
|
73921
74157
|
try {
|
|
73922
|
-
raw = await
|
|
74158
|
+
raw = await readFile14(path, "utf8");
|
|
73923
74159
|
} catch (error61) {
|
|
73924
74160
|
if (isMissingFile(error61)) return [];
|
|
73925
74161
|
throw error61;
|
|
@@ -74052,7 +74288,7 @@ async function reserveSpend(amountAtomic2, caps, options) {
|
|
|
74052
74288
|
{ amountAtomic: amountAtomic2, limitAtomic: perDayAtomic, spentAtomic: BigInt(spentAtomic), wallet }
|
|
74053
74289
|
);
|
|
74054
74290
|
}
|
|
74055
|
-
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"));
|
|
74056
74292
|
const nextRow = {
|
|
74057
74293
|
date: utcDateKey(now),
|
|
74058
74294
|
spentAtomic: nextSpent.toString(),
|
|
@@ -74158,7 +74394,7 @@ async function writeLedgerAtomically(path, rows) {
|
|
|
74158
74394
|
...rows[0].reservations === void 0 ? {} : { reservations: rows[0].reservations }
|
|
74159
74395
|
} : { version: 1, rows };
|
|
74160
74396
|
await mkdir12(dirname8(path), { recursive: true, mode: 448 });
|
|
74161
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
74397
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes11(6).toString("hex")}.tmp`;
|
|
74162
74398
|
await writeFile7(temporaryPath, `${JSON.stringify(ledger, null, 2)}
|
|
74163
74399
|
`, {
|
|
74164
74400
|
encoding: "utf8",
|
|
@@ -74174,7 +74410,7 @@ async function withLedgerLock(path, operation) {
|
|
|
74174
74410
|
let handle;
|
|
74175
74411
|
while (!handle) {
|
|
74176
74412
|
try {
|
|
74177
|
-
handle = await
|
|
74413
|
+
handle = await open9(lockPath, "wx", 384);
|
|
74178
74414
|
} catch (error61) {
|
|
74179
74415
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) {
|
|
74180
74416
|
throw error61;
|
|
@@ -74195,7 +74431,7 @@ async function withLedgerLock(path, operation) {
|
|
|
74195
74431
|
}
|
|
74196
74432
|
async function removeStaleLock3(path) {
|
|
74197
74433
|
try {
|
|
74198
|
-
const metadata = await
|
|
74434
|
+
const metadata = await stat11(path);
|
|
74199
74435
|
if (Date.now() - metadata.mtimeMs > 3e4) {
|
|
74200
74436
|
await unlink8(path);
|
|
74201
74437
|
}
|
|
@@ -74207,8 +74443,8 @@ async function removeStaleLock3(path) {
|
|
|
74207
74443
|
}
|
|
74208
74444
|
|
|
74209
74445
|
// ../core/src/transfer.ts
|
|
74210
|
-
import { randomBytes as
|
|
74211
|
-
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";
|
|
74212
74448
|
import { dirname as dirname9 } from "node:path";
|
|
74213
74449
|
|
|
74214
74450
|
// ../core/src/siblings.ts
|
|
@@ -74417,7 +74653,7 @@ async function transferBetweenAccounts(args) {
|
|
|
74417
74653
|
if (args.resume !== void 0) {
|
|
74418
74654
|
return await resumeTransfer(context, args.resume);
|
|
74419
74655
|
}
|
|
74420
|
-
const nonce = args.nonce ?? bytesToHex(
|
|
74656
|
+
const nonce = args.nonce ?? bytesToHex(randomBytes12(32));
|
|
74421
74657
|
if (!NONCE_PATTERN.test(nonce)) {
|
|
74422
74658
|
throw new TransferError(
|
|
74423
74659
|
"authorization_invalid",
|
|
@@ -74810,7 +75046,7 @@ async function withTransferLock(context, nonce, operation) {
|
|
|
74810
75046
|
let handle;
|
|
74811
75047
|
while (!handle) {
|
|
74812
75048
|
try {
|
|
74813
|
-
handle = await
|
|
75049
|
+
handle = await open10(lockPath, "wx", 384);
|
|
74814
75050
|
} catch (error61) {
|
|
74815
75051
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) throw error61;
|
|
74816
75052
|
await removeStaleTransferLock(lockPath, staleAfterMs);
|
|
@@ -74829,7 +75065,7 @@ async function withTransferLock(context, nonce, operation) {
|
|
|
74829
75065
|
}
|
|
74830
75066
|
async function removeStaleTransferLock(path, staleAfterMs) {
|
|
74831
75067
|
try {
|
|
74832
|
-
const metadata = await
|
|
75068
|
+
const metadata = await stat12(path);
|
|
74833
75069
|
if (Date.now() - metadata.mtimeMs > staleAfterMs) await unlink9(path);
|
|
74834
75070
|
} catch (error61) {
|
|
74835
75071
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "ENOENT")) throw error61;
|
|
@@ -75255,7 +75491,7 @@ async function listUnfinishedMovements(options) {
|
|
|
75255
75491
|
}
|
|
75256
75492
|
const summaries = [];
|
|
75257
75493
|
for (const name of names.filter((candidate) => candidate.endsWith(".json")).sort()) {
|
|
75258
|
-
const movement = parseMovement(JSON.parse(await
|
|
75494
|
+
const movement = parseMovement(JSON.parse(await readFile15(join12(directory, name), "utf8")));
|
|
75259
75495
|
if (options.from !== void 0 && !movement.legs.some((leg) => leg.from === options.from)) {
|
|
75260
75496
|
continue;
|
|
75261
75497
|
}
|
|
@@ -75286,7 +75522,7 @@ async function listUnfinishedMovementSnapshots(options) {
|
|
|
75286
75522
|
}
|
|
75287
75523
|
const snapshots = [];
|
|
75288
75524
|
for (const name of names.filter((candidate) => candidate.endsWith(".json")).sort()) {
|
|
75289
|
-
const movement = parseMovement(JSON.parse(await
|
|
75525
|
+
const movement = parseMovement(JSON.parse(await readFile15(join12(directory, name), "utf8")));
|
|
75290
75526
|
if (options.from !== void 0 && !movement.legs.some((leg) => leg.from === options.from)) {
|
|
75291
75527
|
continue;
|
|
75292
75528
|
}
|
|
@@ -75322,23 +75558,23 @@ async function movementHasOpenLeg(home, movement, from16) {
|
|
|
75322
75558
|
return false;
|
|
75323
75559
|
}
|
|
75324
75560
|
async function movementOpenEvidence(home, movement, from16) {
|
|
75325
|
-
let
|
|
75561
|
+
let open13 = false;
|
|
75326
75562
|
const signedFailedLegKeys = [];
|
|
75327
75563
|
for (const leg of movement.legs) {
|
|
75328
75564
|
if (from16 !== void 0 && leg.from !== from16) continue;
|
|
75329
|
-
if (isOpenMovementLeg(leg, "unsigned"))
|
|
75565
|
+
if (isOpenMovementLeg(leg, "unsigned")) open13 = true;
|
|
75330
75566
|
if (leg.status !== "failed") continue;
|
|
75331
75567
|
const journal = await readTransferJournal(home, leg.from, leg.nonce);
|
|
75332
75568
|
if (journal.signed) signedFailedLegKeys.push(movementTransferKey(leg.from, leg.nonce));
|
|
75333
|
-
if (isOpenMovementLeg(leg, journal.signed ? "signed" : "unsigned"))
|
|
75569
|
+
if (isOpenMovementLeg(leg, journal.signed ? "signed" : "unsigned")) open13 = true;
|
|
75334
75570
|
}
|
|
75335
|
-
return { open:
|
|
75571
|
+
return { open: open13, signedFailedLegKeys };
|
|
75336
75572
|
}
|
|
75337
75573
|
async function readMovement(home, id2) {
|
|
75338
75574
|
const safeId = parseMovementId(id2);
|
|
75339
75575
|
try {
|
|
75340
75576
|
return parseMovement(
|
|
75341
|
-
JSON.parse(await
|
|
75577
|
+
JSON.parse(await readFile15(join12(movementsDirectory(home), `${safeId}.json`), "utf8"))
|
|
75342
75578
|
);
|
|
75343
75579
|
} catch (error61) {
|
|
75344
75580
|
if (isMissingFile(error61)) {
|
|
@@ -76058,33 +76294,33 @@ function parseMovementId(value) {
|
|
|
76058
76294
|
return parsed.data;
|
|
76059
76295
|
}
|
|
76060
76296
|
function movementsDirectory(home) {
|
|
76061
|
-
return
|
|
76297
|
+
return join12(home, "movements");
|
|
76062
76298
|
}
|
|
76063
76299
|
function createMovementId() {
|
|
76064
|
-
return `mv_${
|
|
76300
|
+
return `mv_${randomBytes13(12).toString("hex")}`;
|
|
76065
76301
|
}
|
|
76066
76302
|
function createMovementNonce() {
|
|
76067
|
-
return bytesToHex(
|
|
76303
|
+
return bytesToHex(randomBytes13(32));
|
|
76068
76304
|
}
|
|
76069
76305
|
async function writeMovement(home, movement) {
|
|
76070
76306
|
const parsed = movementSchema.parse(movement);
|
|
76071
76307
|
const directory = movementsDirectory(home);
|
|
76072
76308
|
await mkdir14(directory, { recursive: true, mode: 448 });
|
|
76073
76309
|
await chmod4(directory, 448);
|
|
76074
|
-
const path =
|
|
76075
|
-
const temporary =
|
|
76310
|
+
const path = join12(directory, `${parsed.id}.json`);
|
|
76311
|
+
const temporary = join12(
|
|
76076
76312
|
directory,
|
|
76077
|
-
`.${parsed.id}.${process.pid}.${
|
|
76313
|
+
`.${parsed.id}.${process.pid}.${randomBytes13(6).toString("hex")}.tmp`
|
|
76078
76314
|
);
|
|
76079
76315
|
let handle;
|
|
76080
76316
|
try {
|
|
76081
|
-
handle = await
|
|
76317
|
+
handle = await open11(temporary, "wx", 384);
|
|
76082
76318
|
await handle.writeFile(serializeMovement(parsed), "utf8");
|
|
76083
76319
|
await handle.sync();
|
|
76084
76320
|
await handle.close();
|
|
76085
76321
|
handle = void 0;
|
|
76086
76322
|
await rename10(temporary, path);
|
|
76087
|
-
const directoryHandle = await
|
|
76323
|
+
const directoryHandle = await open11(directory, "r");
|
|
76088
76324
|
try {
|
|
76089
76325
|
await directoryHandle.sync();
|
|
76090
76326
|
} finally {
|
|
@@ -76304,7 +76540,7 @@ async function sweepAboveCeilingLocked(args) {
|
|
|
76304
76540
|
owner,
|
|
76305
76541
|
target,
|
|
76306
76542
|
amountAtomic: amountAtomic2.toString(),
|
|
76307
|
-
nonce: (args.randomNonce ?? (() => bytesToHex(
|
|
76543
|
+
nonce: (args.randomNonce ?? (() => bytesToHex(randomBytes14(32))))(),
|
|
76308
76544
|
createdAt: new Date(now()).toISOString(),
|
|
76309
76545
|
status: "planned"
|
|
76310
76546
|
};
|
|
@@ -77096,8 +77332,8 @@ function parseDecimal(value, scale) {
|
|
|
77096
77332
|
}
|
|
77097
77333
|
|
|
77098
77334
|
// ../core/src/swarm.ts
|
|
77099
|
-
import { readdir as readdir6, readFile as
|
|
77100
|
-
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";
|
|
77101
77337
|
var SWARM_NAME_PATTERN = /^[a-z][a-z0-9-]{0,15}$/;
|
|
77102
77338
|
var SWARM_ROLE_PATTERN = /^[a-z][a-z0-9]{0,7}$/;
|
|
77103
77339
|
var DEFAULT_SWARM_MODEL = "venice/claude-sonnet-5";
|
|
@@ -77178,16 +77414,16 @@ var SwarmError = class extends Error {
|
|
|
77178
77414
|
code;
|
|
77179
77415
|
};
|
|
77180
77416
|
function swarmsDirectory(home) {
|
|
77181
|
-
return
|
|
77417
|
+
return join13(home, "swarms");
|
|
77182
77418
|
}
|
|
77183
77419
|
function swarmFilePath(home, name) {
|
|
77184
77420
|
assertName(name);
|
|
77185
|
-
return
|
|
77421
|
+
return join13(swarmsDirectory(home), `${name}.json`);
|
|
77186
77422
|
}
|
|
77187
77423
|
async function readSwarm(home, name) {
|
|
77188
77424
|
const path = swarmFilePath(home, name);
|
|
77189
77425
|
try {
|
|
77190
|
-
const swarm = parseSwarm(JSON.parse(await
|
|
77426
|
+
const swarm = parseSwarm(JSON.parse(await readFile16(path, "utf8")));
|
|
77191
77427
|
if (swarm.name !== name)
|
|
77192
77428
|
throw new SwarmError("invalid_swarm", "Swarm name does not match its file.");
|
|
77193
77429
|
return swarm;
|
|
@@ -77215,7 +77451,7 @@ async function writeSwarm(home, value) {
|
|
|
77215
77451
|
const bytes = `${JSON.stringify(swarm, null, 2)}
|
|
77216
77452
|
`;
|
|
77217
77453
|
try {
|
|
77218
|
-
if (await
|
|
77454
|
+
if (await readFile16(path, "utf8") === bytes) return;
|
|
77219
77455
|
} catch (error61) {
|
|
77220
77456
|
if (!isMissingFile(error61)) throw error61;
|
|
77221
77457
|
}
|
|
@@ -77230,7 +77466,7 @@ async function deleteSwarmFile(home, name) {
|
|
|
77230
77466
|
}
|
|
77231
77467
|
async function withSwarmLock(home, name, fn) {
|
|
77232
77468
|
assertName(name);
|
|
77233
|
-
const path =
|
|
77469
|
+
const path = join13(swarmsDirectory(home), `.${name}.lock`);
|
|
77234
77470
|
try {
|
|
77235
77471
|
return await withFileLock(path, fn, { lockedMessage: `Swarm ${name} is locked.` });
|
|
77236
77472
|
} catch (error61) {
|
|
@@ -77542,7 +77778,7 @@ async function swarmStatus(opts) {
|
|
|
77542
77778
|
);
|
|
77543
77779
|
let movementFiles;
|
|
77544
77780
|
try {
|
|
77545
|
-
movementFiles = await readdir6(
|
|
77781
|
+
movementFiles = await readdir6(join13(home, "movements"));
|
|
77546
77782
|
} catch (error61) {
|
|
77547
77783
|
if (!isMissingFile(error61)) throw error61;
|
|
77548
77784
|
movementFiles = [];
|
|
@@ -77599,11 +77835,11 @@ async function swarmStatus(opts) {
|
|
|
77599
77835
|
})
|
|
77600
77836
|
);
|
|
77601
77837
|
const accounts = new Set(swarmAccountNames(swarm));
|
|
77602
|
-
const
|
|
77838
|
+
const open13 = [];
|
|
77603
77839
|
for (const summary2 of await listUnfinishedMovements({ home })) {
|
|
77604
77840
|
const movement = await readMovement(home, summary2.id);
|
|
77605
77841
|
if (movement.treasury === swarm.treasury.account || movement.legs.some((leg) => accounts.has(leg.from) || accounts.has(leg.to))) {
|
|
77606
|
-
|
|
77842
|
+
open13.push(summary2);
|
|
77607
77843
|
}
|
|
77608
77844
|
}
|
|
77609
77845
|
return {
|
|
@@ -77612,7 +77848,7 @@ async function swarmStatus(opts) {
|
|
|
77612
77848
|
strategy: swarm.policy.strategy,
|
|
77613
77849
|
treasury,
|
|
77614
77850
|
members: members2,
|
|
77615
|
-
openMovements:
|
|
77851
|
+
openMovements: open13.sort(
|
|
77616
77852
|
(a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id)
|
|
77617
77853
|
)
|
|
77618
77854
|
};
|
|
@@ -77711,7 +77947,7 @@ async function assertNoConflicts(home, name, accounts) {
|
|
|
77711
77947
|
}
|
|
77712
77948
|
async function profileExists(home, account) {
|
|
77713
77949
|
try {
|
|
77714
|
-
await
|
|
77950
|
+
await stat13(join13(getVapiPaths(home).agentsDir, `${account}.json`));
|
|
77715
77951
|
return true;
|
|
77716
77952
|
} catch (error61) {
|
|
77717
77953
|
if (isMissingFile(error61)) return false;
|
|
@@ -77724,7 +77960,7 @@ async function refuseTreasuryProfile(home, account) {
|
|
|
77724
77960
|
}
|
|
77725
77961
|
|
|
77726
77962
|
// ../core/src/x402-pay.ts
|
|
77727
|
-
import { randomBytes as
|
|
77963
|
+
import { randomBytes as randomBytes15, randomUUID as randomUUID2 } from "node:crypto";
|
|
77728
77964
|
|
|
77729
77965
|
// ../core/src/run-budget.ts
|
|
77730
77966
|
var RunBudgetError = class extends Error {
|
|
@@ -77765,13 +78001,13 @@ function createRunBudget(args) {
|
|
|
77765
78001
|
// ../core/src/support-report.ts
|
|
77766
78002
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
77767
78003
|
import { arch, platform, release } from "node:os";
|
|
77768
|
-
import { join as
|
|
77769
|
-
var VAPI_CLIENT_VERSION = "0.
|
|
78004
|
+
import { join as join14 } from "node:path";
|
|
78005
|
+
var VAPI_CLIENT_VERSION = "0.13.0";
|
|
77770
78006
|
async function createSupportReport(options) {
|
|
77771
78007
|
const message = options.message.trim();
|
|
77772
78008
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
77773
78009
|
const paths = getVapiPaths();
|
|
77774
|
-
const reportsDirectory = options.reportsDirectory ??
|
|
78010
|
+
const reportsDirectory = options.reportsDirectory ?? join14(paths.directory, "reports");
|
|
77775
78011
|
const receipts = await readReceipts(options.receiptsPath ?? paths.receipts, { limit: 5 });
|
|
77776
78012
|
const system = options.systemInfo ?? defaultSystemInfo();
|
|
77777
78013
|
const report = {
|
|
@@ -77801,7 +78037,7 @@ async function createSupportReport(options) {
|
|
|
77801
78037
|
};
|
|
77802
78038
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
77803
78039
|
const timestamp = now.toISOString();
|
|
77804
|
-
const path =
|
|
78040
|
+
const path = join14(reportsDirectory, `${sanitizeTimestamp(timestamp)}.json`);
|
|
77805
78041
|
await mkdir15(reportsDirectory, { recursive: true, mode: 448 });
|
|
77806
78042
|
const serialized = `${JSON.stringify(report, null, 2)}
|
|
77807
78043
|
`;
|
|
@@ -77997,7 +78233,7 @@ async function completeX402Payment(args) {
|
|
|
77997
78233
|
throw walletCapError(error61, quote.amountAtomic, args);
|
|
77998
78234
|
}
|
|
77999
78235
|
} else {
|
|
78000
|
-
reservationId = args.paymentId ?? `x402_${
|
|
78236
|
+
reservationId = args.paymentId ?? `x402_${randomBytes15(12).toString("hex")}`;
|
|
78001
78237
|
let reservation;
|
|
78002
78238
|
try {
|
|
78003
78239
|
reservation = await reserveSpend(quote.amountAtomic, args.caps, {
|
|
@@ -79398,8 +79634,8 @@ function freezeScopeTerms(structuredInput, briefInput) {
|
|
|
79398
79634
|
}
|
|
79399
79635
|
|
|
79400
79636
|
// ../core/src/tasks/scope-bindings.ts
|
|
79401
|
-
import { readFile as
|
|
79402
|
-
import { join as
|
|
79637
|
+
import { readFile as readFile17 } from "node:fs/promises";
|
|
79638
|
+
import { join as join15 } from "node:path";
|
|
79403
79639
|
|
|
79404
79640
|
// ../core/src/tasks/chain-port.ts
|
|
79405
79641
|
var TasksChainError = class extends Error {
|
|
@@ -79974,7 +80210,7 @@ var messageSchema = external_exports.looseObject({
|
|
|
79974
80210
|
})
|
|
79975
80211
|
)
|
|
79976
80212
|
});
|
|
79977
|
-
var
|
|
80213
|
+
var fileSchema2 = external_exports.looseObject({
|
|
79978
80214
|
id: uuidSchema,
|
|
79979
80215
|
purpose: workFilePurposeSchema,
|
|
79980
80216
|
fileName: external_exports.string(),
|
|
@@ -80280,11 +80516,11 @@ var tasksResponseSchemas = {
|
|
|
80280
80516
|
observedAt: isoDateTimeSchema
|
|
80281
80517
|
}),
|
|
80282
80518
|
createUpload: external_exports.looseObject({
|
|
80283
|
-
file:
|
|
80519
|
+
file: fileSchema2.extend({ state: external_exports.literal("pending"), sha256: external_exports.null() }),
|
|
80284
80520
|
uploadUrl: external_exports.url()
|
|
80285
80521
|
}),
|
|
80286
80522
|
finalizeUpload: external_exports.looseObject({
|
|
80287
|
-
file:
|
|
80523
|
+
file: fileSchema2.extend({
|
|
80288
80524
|
state: external_exports.literal("ready"),
|
|
80289
80525
|
sha256: external_exports.string().regex(/^[0-9a-fA-F]{64}$/)
|
|
80290
80526
|
})
|
|
@@ -80892,10 +81128,10 @@ function key(identity) {
|
|
|
80892
81128
|
return `${identity.orderId}:${identity.trancheOrdinal}:${identity.scopeVersion}:${identity.termsHash.toLowerCase()}:${identity.self.toLowerCase()}`;
|
|
80893
81129
|
}
|
|
80894
81130
|
function createScopeBindings(home) {
|
|
80895
|
-
const path =
|
|
81131
|
+
const path = join15(home, "tasks", "scope-bindings.json");
|
|
80896
81132
|
async function read() {
|
|
80897
81133
|
try {
|
|
80898
|
-
return storeSchema.parse(JSON.parse(await
|
|
81134
|
+
return storeSchema.parse(JSON.parse(await readFile17(path, "utf8")));
|
|
80899
81135
|
} catch (error61) {
|
|
80900
81136
|
if (error61 instanceof Error && "code" in error61 && error61.code === "ENOENT")
|
|
80901
81137
|
return { version: 1, bindings: {} };
|
|
@@ -81576,7 +81812,7 @@ function createTasksChain(options) {
|
|
|
81576
81812
|
const { account, client, pending, rpcFor } = options;
|
|
81577
81813
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
81578
81814
|
const sleep = options.sleep ?? ((ms) => new Promise((resolve3) => setTimeout(resolve3, ms)));
|
|
81579
|
-
const
|
|
81815
|
+
const randomBytes18 = options.randomBytes ?? cryptoRandomBytes2;
|
|
81580
81816
|
const confirmations = options.confirmations ?? 2;
|
|
81581
81817
|
if (!Number.isSafeInteger(confirmations) || confirmations < 1)
|
|
81582
81818
|
throw new TasksChainError("Tasks confirmations must be a positive integer.", false, {
|
|
@@ -82185,7 +82421,7 @@ function createTasksChain(options) {
|
|
|
82185
82421
|
await verifyClone(rpcFor(ready.chainId), expected, true);
|
|
82186
82422
|
if (validBefore <= BigInt(Math.floor(now().getTime() / 1e3)))
|
|
82187
82423
|
throw new TasksValidationError("The task funding offer has expired.");
|
|
82188
|
-
const bytes =
|
|
82424
|
+
const bytes = randomBytes18(32);
|
|
82189
82425
|
if (bytes.length !== 32)
|
|
82190
82426
|
throw new TasksValidationError(
|
|
82191
82427
|
"Funding authorization randomness must contain 32 bytes."
|
|
@@ -82463,8 +82699,8 @@ function createTasksRpcFor(config2, options = {}) {
|
|
|
82463
82699
|
}
|
|
82464
82700
|
|
|
82465
82701
|
// ../core/src/tasks/pending-transactions.ts
|
|
82466
|
-
import { readFile as
|
|
82467
|
-
import { join as
|
|
82702
|
+
import { readFile as readFile18 } from "node:fs/promises";
|
|
82703
|
+
import { join as join16 } from "node:path";
|
|
82468
82704
|
var hex3 = external_exports.string().regex(/^0x(?:[0-9a-fA-F]{2})+$/).transform((v) => v);
|
|
82469
82705
|
var hash4 = external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/).transform((v) => v);
|
|
82470
82706
|
var step = external_exports.enum([
|
|
@@ -82546,11 +82782,11 @@ function validCheckpointStep(storedStep, response) {
|
|
|
82546
82782
|
}[response.operation.kind];
|
|
82547
82783
|
}
|
|
82548
82784
|
function createPendingTransactions(home) {
|
|
82549
|
-
const path =
|
|
82785
|
+
const path = join16(home, "tasks", "pending.json");
|
|
82550
82786
|
const lockPath = `${path}.lock`;
|
|
82551
82787
|
const read = async () => {
|
|
82552
82788
|
try {
|
|
82553
|
-
const state = stateSchema.parse(JSON.parse(await
|
|
82789
|
+
const state = stateSchema.parse(JSON.parse(await readFile18(path, "utf8")));
|
|
82554
82790
|
for (const [key2, value] of Object.entries(state.checkpoints)) {
|
|
82555
82791
|
const separator = key2.indexOf(":");
|
|
82556
82792
|
const operationId = key2.slice(0, separator);
|
|
@@ -82613,7 +82849,7 @@ function createPendingTransactions(home) {
|
|
|
82613
82849
|
},
|
|
82614
82850
|
withStepLock(operationId, step2, fn) {
|
|
82615
82851
|
return withFileLock(
|
|
82616
|
-
|
|
82852
|
+
join16(
|
|
82617
82853
|
home,
|
|
82618
82854
|
"tasks",
|
|
82619
82855
|
`step-${encodeURIComponent(operationId)}-${encodeURIComponent(step2)}.lock`
|
|
@@ -82625,13 +82861,13 @@ function createPendingTransactions(home) {
|
|
|
82625
82861
|
external_exports.number().int().positive().parse(chainId);
|
|
82626
82862
|
address3.parse(signer);
|
|
82627
82863
|
return withFileLock(
|
|
82628
|
-
|
|
82864
|
+
join16(home, "tasks", `signer-${chainId}-${signer.toLowerCase()}.lock`),
|
|
82629
82865
|
fn
|
|
82630
82866
|
);
|
|
82631
82867
|
},
|
|
82632
82868
|
withFundingLock(milestoneId, fn) {
|
|
82633
82869
|
milestoneKey(milestoneId);
|
|
82634
|
-
return withFileLock(
|
|
82870
|
+
return withFileLock(join16(home, "tasks", `fund-${milestoneId}.lock`), fn);
|
|
82635
82871
|
},
|
|
82636
82872
|
async nextNonce(chainId, signer) {
|
|
82637
82873
|
external_exports.number().int().positive().parse(chainId);
|
|
@@ -83457,7 +83693,7 @@ function policyAtomic(value) {
|
|
|
83457
83693
|
}
|
|
83458
83694
|
|
|
83459
83695
|
// ../core/src/tasks/operation-support.ts
|
|
83460
|
-
import { readFile as
|
|
83696
|
+
import { readFile as readFile19, stat as stat14 } from "node:fs/promises";
|
|
83461
83697
|
import { basename as basename3, extname } from "node:path";
|
|
83462
83698
|
var TaskOperationError = class extends Error {
|
|
83463
83699
|
constructor(code, message, manifestHash) {
|
|
@@ -83625,7 +83861,7 @@ function parseTaskDuration(text, now) {
|
|
|
83625
83861
|
async function readTaskFile(path) {
|
|
83626
83862
|
let details;
|
|
83627
83863
|
try {
|
|
83628
|
-
details = await
|
|
83864
|
+
details = await stat14(path);
|
|
83629
83865
|
} catch {
|
|
83630
83866
|
throw new TaskInputError(`Task file ${JSON.stringify(path)} could not be read.`);
|
|
83631
83867
|
}
|
|
@@ -83649,7 +83885,7 @@ async function readTaskFile(path) {
|
|
|
83649
83885
|
const contentType = types[extname(path).toLowerCase()];
|
|
83650
83886
|
if (!contentType)
|
|
83651
83887
|
throw new TaskInputError("Task files must be images, PDF, ZIP, text, Markdown, JSON or CSV.");
|
|
83652
|
-
const bytes = await
|
|
83888
|
+
const bytes = await readFile19(path);
|
|
83653
83889
|
if (bytes.length < TASK_LIMITS.uploadBytesMin || bytes.length > TASK_LIMITS.uploadBytesMax)
|
|
83654
83890
|
throw new TaskInputError("Task files must contain between 1 byte and 50 MiB.");
|
|
83655
83891
|
return {
|
|
@@ -84448,7 +84684,7 @@ async function resolveUnmatchedTaskOperation(context, input2) {
|
|
|
84448
84684
|
}
|
|
84449
84685
|
|
|
84450
84686
|
// ../core/src/searches.ts
|
|
84451
|
-
import { mkdir as mkdir16, open as
|
|
84687
|
+
import { mkdir as mkdir16, open as open12, readFile as readFile20 } from "node:fs/promises";
|
|
84452
84688
|
import { dirname as dirname10 } from "node:path";
|
|
84453
84689
|
var searchEventSchema = external_exports.strictObject({
|
|
84454
84690
|
timestamp: external_exports.iso.datetime(),
|
|
@@ -84470,7 +84706,7 @@ function parseSearchEvent(value) {
|
|
|
84470
84706
|
async function appendSearchEvent(event, path = getVapiPaths().searches) {
|
|
84471
84707
|
const parsed = parseSearchEvent(event);
|
|
84472
84708
|
await mkdir16(dirname10(path), { recursive: true, mode: 448 });
|
|
84473
|
-
const handle = await
|
|
84709
|
+
const handle = await open12(path, "a", 384);
|
|
84474
84710
|
try {
|
|
84475
84711
|
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
84476
84712
|
`, "utf8");
|
|
@@ -84482,7 +84718,7 @@ async function appendSearchEvent(event, path = getVapiPaths().searches) {
|
|
|
84482
84718
|
async function readSearchEvents(path = getVapiPaths().searches) {
|
|
84483
84719
|
let raw;
|
|
84484
84720
|
try {
|
|
84485
|
-
raw = await
|
|
84721
|
+
raw = await readFile20(path, "utf8");
|
|
84486
84722
|
} catch (error61) {
|
|
84487
84723
|
if (isMissingFile(error61)) return [];
|
|
84488
84724
|
throw error61;
|
|
@@ -85384,9 +85620,9 @@ function csvCell(value) {
|
|
|
85384
85620
|
}
|
|
85385
85621
|
|
|
85386
85622
|
// ../core/src/swarm-capital.ts
|
|
85387
|
-
import { createHash as createHash5, randomBytes as
|
|
85388
|
-
import { readFile as
|
|
85389
|
-
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";
|
|
85390
85626
|
var movementIdSchema3 = external_exports.string().regex(/^mv_[A-Za-z0-9_-]{8,128}$/u);
|
|
85391
85627
|
var amountSchema2 = external_exports.string().regex(/^\d+\.\d{2}$/u);
|
|
85392
85628
|
var requestIdSchema = external_exports.string().min(1).max(512);
|
|
@@ -86267,7 +86503,7 @@ async function readDelegationRecord(home, movementId) {
|
|
|
86267
86503
|
const safeId = runRecordMovementId(movementId);
|
|
86268
86504
|
try {
|
|
86269
86505
|
const record2 = delegationRecordSchema.parse(
|
|
86270
|
-
JSON.parse(await
|
|
86506
|
+
JSON.parse(await readFile21(delegationRecordPath(home, safeId), "utf8"))
|
|
86271
86507
|
);
|
|
86272
86508
|
if (record2.movementId !== safeId) {
|
|
86273
86509
|
throw new SwarmError(
|
|
@@ -86294,7 +86530,7 @@ async function readTreasuryRequestRecord(home, movementId) {
|
|
|
86294
86530
|
const safeId = runRecordMovementId(movementId);
|
|
86295
86531
|
try {
|
|
86296
86532
|
const record2 = treasuryRequestRecordSchema.parse(
|
|
86297
|
-
JSON.parse(await
|
|
86533
|
+
JSON.parse(await readFile21(treasuryRequestRecordPath(home, safeId), "utf8"))
|
|
86298
86534
|
);
|
|
86299
86535
|
if (record2.movementId !== safeId) {
|
|
86300
86536
|
throw new SwarmError(
|
|
@@ -86325,18 +86561,18 @@ function runRecordMovementId(value) {
|
|
|
86325
86561
|
return parsed.data;
|
|
86326
86562
|
}
|
|
86327
86563
|
function treasuryRequestRecordPath(home, movementId) {
|
|
86328
|
-
return
|
|
86564
|
+
return join17(home, "runs", "requests", `${movementId}.json`);
|
|
86329
86565
|
}
|
|
86330
86566
|
function delegationRecordPath(home, movementId) {
|
|
86331
|
-
return
|
|
86567
|
+
return join17(home, "runs", "delegations", `${movementId}.json`);
|
|
86332
86568
|
}
|
|
86333
86569
|
function legacyFundingProgressPath(home, name) {
|
|
86334
|
-
return
|
|
86570
|
+
return join17(home, "swarms", `.${name}.funding`);
|
|
86335
86571
|
}
|
|
86336
86572
|
async function readLegacyFundingProgress(home, name) {
|
|
86337
86573
|
try {
|
|
86338
86574
|
const progress = legacyFundingProgressSchema.parse(
|
|
86339
|
-
JSON.parse(await
|
|
86575
|
+
JSON.parse(await readFile21(legacyFundingProgressPath(home, name), "utf8"))
|
|
86340
86576
|
);
|
|
86341
86577
|
if (progress.name !== name) {
|
|
86342
86578
|
throw new SwarmError("invalid_swarm", `Invalid funding progress for swarm ${name}.`);
|
|
@@ -86565,7 +86801,7 @@ async function optionalMovement(home, id2) {
|
|
|
86565
86801
|
}
|
|
86566
86802
|
}
|
|
86567
86803
|
function nextMovementId(deps) {
|
|
86568
|
-
return movementIdSchema3.parse(deps.randomId?.() ?? `mv_${
|
|
86804
|
+
return movementIdSchema3.parse(deps.randomId?.() ?? `mv_${randomBytes16(12).toString("hex")}`);
|
|
86569
86805
|
}
|
|
86570
86806
|
async function executeRecordedMovement(id2, plan, deps, home, options = {}) {
|
|
86571
86807
|
try {
|
|
@@ -86981,7 +87217,7 @@ async function removeMemberLocked(home, swarm, account) {
|
|
|
86981
87217
|
}
|
|
86982
87218
|
|
|
86983
87219
|
// ../core/src/status.ts
|
|
86984
|
-
import { join as
|
|
87220
|
+
import { join as join18 } from "node:path";
|
|
86985
87221
|
var STATUS_TIMEOUT_MS = 2e3;
|
|
86986
87222
|
async function buildStatus(deps) {
|
|
86987
87223
|
const timers = deps.timers ?? { setTimeout, clearTimeout };
|
|
@@ -87037,7 +87273,7 @@ function formatUsdAmount(value) {
|
|
|
87037
87273
|
}
|
|
87038
87274
|
async function readVaultStatus(deps) {
|
|
87039
87275
|
const store = deps.secrets.description.replace(/^the /u, "");
|
|
87040
|
-
const path =
|
|
87276
|
+
const path = join18(deps.home, "vault.json");
|
|
87041
87277
|
let file2;
|
|
87042
87278
|
try {
|
|
87043
87279
|
file2 = await readVaultFileUnlocked(path);
|
|
@@ -87471,8 +87707,8 @@ function isRecord4(value) {
|
|
|
87471
87707
|
|
|
87472
87708
|
// src/cli.ts
|
|
87473
87709
|
import { spawn as spawn5 } from "node:child_process";
|
|
87474
|
-
import { stat as
|
|
87475
|
-
import { join as
|
|
87710
|
+
import { stat as stat18 } from "node:fs/promises";
|
|
87711
|
+
import { join as join30 } from "node:path";
|
|
87476
87712
|
import { createInterface as createInterface3 } from "node:readline/promises";
|
|
87477
87713
|
|
|
87478
87714
|
// ../core/src/member-bundle.ts
|
|
@@ -87749,7 +87985,7 @@ function assertKeyMatchesAddress(bundle) {
|
|
|
87749
87985
|
}
|
|
87750
87986
|
|
|
87751
87987
|
// ../core/src/api-key.ts
|
|
87752
|
-
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";
|
|
87753
87989
|
import { dirname as dirname11 } from "node:path";
|
|
87754
87990
|
var API_KEY_PREFIX = "vapi_sk_";
|
|
87755
87991
|
var API_KEY_PATTERN = /^vapi_sk_[A-Za-z0-9_-]{16,128}$/;
|
|
@@ -87845,7 +88081,7 @@ async function readConfigApiKey(path) {
|
|
|
87845
88081
|
async function readConfigRecord(path) {
|
|
87846
88082
|
let raw;
|
|
87847
88083
|
try {
|
|
87848
|
-
raw = await
|
|
88084
|
+
raw = await readFile22(path, "utf8");
|
|
87849
88085
|
} catch (error61) {
|
|
87850
88086
|
if (isMissingFile(error61)) return void 0;
|
|
87851
88087
|
throw error61;
|
|
@@ -90515,8 +90751,8 @@ function exactPriceFact(value) {
|
|
|
90515
90751
|
}
|
|
90516
90752
|
|
|
90517
90753
|
// ../mcp/src/agent/runtime.ts
|
|
90518
|
-
import { mkdir as mkdir18, readFile as
|
|
90519
|
-
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";
|
|
90520
90756
|
|
|
90521
90757
|
// ../mcp/src/agent/run.ts
|
|
90522
90758
|
var loopSearchResultSchema = external_exports.array(
|
|
@@ -91817,19 +92053,19 @@ var runRecordSchema = external_exports.strictObject({
|
|
|
91817
92053
|
detail: external_exports.string().optional()
|
|
91818
92054
|
});
|
|
91819
92055
|
function runsDirectory(home) {
|
|
91820
|
-
return
|
|
92056
|
+
return join19(home, "runs");
|
|
91821
92057
|
}
|
|
91822
92058
|
function runRecordPath(home, runId) {
|
|
91823
92059
|
assertRunId(runId);
|
|
91824
|
-
return
|
|
92060
|
+
return join19(runsDirectory(home), `${runId}.json`);
|
|
91825
92061
|
}
|
|
91826
92062
|
function runLogPath(home, runId) {
|
|
91827
92063
|
assertRunId(runId);
|
|
91828
|
-
return
|
|
92064
|
+
return join19(runsDirectory(home), `${runId}.log`);
|
|
91829
92065
|
}
|
|
91830
92066
|
function runResultPath(home, runId) {
|
|
91831
92067
|
assertRunId(runId);
|
|
91832
|
-
return
|
|
92068
|
+
return join19(runsDirectory(home), `${runId}.result.json`);
|
|
91833
92069
|
}
|
|
91834
92070
|
async function writeRunRecord(home, record2) {
|
|
91835
92071
|
const path = runRecordPath(home, record2.runId);
|
|
@@ -91840,7 +92076,7 @@ async function writeRunRecord(home, record2) {
|
|
|
91840
92076
|
async function readRunRecord(home, runId) {
|
|
91841
92077
|
const path = runRecordPath(home, runId);
|
|
91842
92078
|
try {
|
|
91843
|
-
return runRecordSchema.parse(JSON.parse(await
|
|
92079
|
+
return runRecordSchema.parse(JSON.parse(await readFile23(path, "utf8")));
|
|
91844
92080
|
} catch (error61) {
|
|
91845
92081
|
if (isMissingFile3(error61)) return void 0;
|
|
91846
92082
|
throw error61;
|
|
@@ -91860,7 +92096,7 @@ async function listRunRecords(home, filter = {}) {
|
|
|
91860
92096
|
if (match === null) continue;
|
|
91861
92097
|
try {
|
|
91862
92098
|
const record2 = runRecordSchema.parse(
|
|
91863
|
-
JSON.parse(await
|
|
92099
|
+
JSON.parse(await readFile23(join19(runsDirectory(home), file2), "utf8"))
|
|
91864
92100
|
);
|
|
91865
92101
|
if (record2.runId !== match[1]) continue;
|
|
91866
92102
|
if (filter.swarm !== void 0 && record2.member.swarm !== filter.swarm) continue;
|
|
@@ -92137,7 +92373,7 @@ async function stopRun(args) {
|
|
|
92137
92373
|
}
|
|
92138
92374
|
}
|
|
92139
92375
|
function memberRunLockPath(home, account) {
|
|
92140
|
-
return
|
|
92376
|
+
return join19(runsDirectory(home), `.member-${account}.lock`);
|
|
92141
92377
|
}
|
|
92142
92378
|
function summarizeRunRecord(record2) {
|
|
92143
92379
|
return {
|
|
@@ -95741,8 +95977,8 @@ function rgbToAnsi256(red, green, blue) {
|
|
|
95741
95977
|
}
|
|
95742
95978
|
|
|
95743
95979
|
// src/accounts.ts
|
|
95744
|
-
import { readFile as
|
|
95745
|
-
import { join as
|
|
95980
|
+
import { readFile as readFile25, stat as stat16 } from "node:fs/promises";
|
|
95981
|
+
import { join as join22 } from "node:path";
|
|
95746
95982
|
|
|
95747
95983
|
// src/dashboard.ts
|
|
95748
95984
|
import { resolve as resolve2 } from "node:path";
|
|
@@ -96419,12 +96655,12 @@ function shellQuote2(value) {
|
|
|
96419
96655
|
}
|
|
96420
96656
|
|
|
96421
96657
|
// src/status.ts
|
|
96422
|
-
import { stat as
|
|
96658
|
+
import { stat as stat15 } from "node:fs/promises";
|
|
96423
96659
|
import { homedir as homedir2 } from "node:os";
|
|
96424
96660
|
import { sep } from "node:path";
|
|
96425
96661
|
|
|
96426
96662
|
// ../core/src/cloud-backup.ts
|
|
96427
|
-
import { join as
|
|
96663
|
+
import { join as join21 } from "node:path";
|
|
96428
96664
|
|
|
96429
96665
|
// ../core/src/backup.ts
|
|
96430
96666
|
import {
|
|
@@ -96447,11 +96683,11 @@ import {
|
|
|
96447
96683
|
mkdir as mkdir19,
|
|
96448
96684
|
mkdtemp,
|
|
96449
96685
|
open as openFile,
|
|
96450
|
-
readFile as
|
|
96686
|
+
readFile as readFile24,
|
|
96451
96687
|
readdir as readdir8,
|
|
96452
96688
|
rm as rm3
|
|
96453
96689
|
} from "node:fs/promises";
|
|
96454
|
-
import { dirname as dirname12, join as
|
|
96690
|
+
import { dirname as dirname12, join as join20 } from "node:path";
|
|
96455
96691
|
var ERROR_MESSAGES = {
|
|
96456
96692
|
backup_too_large: "Backup envelope exceeds 65,536 bytes.",
|
|
96457
96693
|
backup_open_failed: "Unable to open backup.",
|
|
@@ -96734,8 +96970,8 @@ async function createBackup(options) {
|
|
|
96734
96970
|
assertDevice(options.device);
|
|
96735
96971
|
assertOwnerKey(options.ownerKey);
|
|
96736
96972
|
const createdAt = readCreatedAt(options.now ?? (() => /* @__PURE__ */ new Date()));
|
|
96737
|
-
const
|
|
96738
|
-
const nonce = readRandomBytes(
|
|
96973
|
+
const randomBytes18 = options.randomBytes ?? cryptoRandomBytes3;
|
|
96974
|
+
const nonce = readRandomBytes(randomBytes18, 12);
|
|
96739
96975
|
const salt = encodeBase64Url(options.ownerKey.salt);
|
|
96740
96976
|
const kdf = options.ownerKey.kdf === "hkdf-sha256" ? { name: "hkdf-sha256", salt } : { name: "scrypt", salt, N: SCRYPT_N2, r: SCRYPT_R2, p: SCRYPT_P2 };
|
|
96741
96977
|
const cipher = { name: CIPHER_NAME, nonce: encodeBase64Url(nonce) };
|
|
@@ -96929,7 +97165,7 @@ async function exportBackupSource(options) {
|
|
|
96929
97165
|
var BackupSnapshotChangedError = class extends Error {
|
|
96930
97166
|
};
|
|
96931
97167
|
async function exportBackupSourceAttempt(options, networks) {
|
|
96932
|
-
const path =
|
|
97168
|
+
const path = join20(options.store.home, "vault.json");
|
|
96933
97169
|
const { phrase, file: file2, accounts } = await withVaultLock(path, async () => {
|
|
96934
97170
|
const [phrase2, vault, file3] = await Promise.all([
|
|
96935
97171
|
exportVaultPhrase({ path, key: options.vaultKey }),
|
|
@@ -97065,16 +97301,16 @@ async function restoreBackupPlaintext(options) {
|
|
|
97065
97301
|
} catch {
|
|
97066
97302
|
throw new BackupError("backup_invalid_input");
|
|
97067
97303
|
}
|
|
97068
|
-
const vaultPath2 =
|
|
97069
|
-
const registryPath =
|
|
97304
|
+
const vaultPath2 = join20(options.home, "vault.json");
|
|
97305
|
+
const registryPath = join20(options.home, "wallets.json");
|
|
97070
97306
|
let stagingHome;
|
|
97071
97307
|
let beforePublishError;
|
|
97072
97308
|
let afterPublishError;
|
|
97073
97309
|
try {
|
|
97074
97310
|
await mkdir19(options.home, { recursive: true, mode: 448 });
|
|
97075
|
-
stagingHome = await mkdtemp(
|
|
97076
|
-
const stagedVaultPath =
|
|
97077
|
-
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");
|
|
97078
97314
|
await createVault({
|
|
97079
97315
|
path: stagedVaultPath,
|
|
97080
97316
|
key: options.vaultKey,
|
|
@@ -97133,7 +97369,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
97133
97369
|
protected: plaintext.protected,
|
|
97134
97370
|
networks: [...plaintext.registry.networks]
|
|
97135
97371
|
};
|
|
97136
|
-
const markerPath =
|
|
97372
|
+
const markerPath = join20(options.home, RESTORE_MARKER_FILE);
|
|
97137
97373
|
const fingerprint = restoreFingerprint(
|
|
97138
97374
|
plaintext,
|
|
97139
97375
|
stagedV2?.restoreDevice ?? options.device,
|
|
@@ -97344,13 +97580,13 @@ async function stageV2Restore(options) {
|
|
|
97344
97580
|
}
|
|
97345
97581
|
const agents = [];
|
|
97346
97582
|
for (const profile of validAgents) {
|
|
97347
|
-
const stagedPath =
|
|
97583
|
+
const stagedPath = join20(options.stagingHome, "agents", `${profile.name}.json`);
|
|
97348
97584
|
if (await stageRestoreBytes(stagedPath, prettyJson(profile))) {
|
|
97349
97585
|
agents.push({
|
|
97350
97586
|
kind: "agent",
|
|
97351
97587
|
name: profile.name,
|
|
97352
97588
|
stagedPath,
|
|
97353
|
-
targetPath:
|
|
97589
|
+
targetPath: join20(options.home, "agents", `${profile.name}.json`)
|
|
97354
97590
|
});
|
|
97355
97591
|
} else {
|
|
97356
97592
|
skipped2.push({ kind: "agent", name: profile.name, reason: "write_failed" });
|
|
@@ -97370,13 +97606,13 @@ async function stageV2Restore(options) {
|
|
|
97370
97606
|
if (restoreDevice !== void 0) {
|
|
97371
97607
|
for (const value of validSwarms) {
|
|
97372
97608
|
const swarm = swarmFileSchema.parse({ ...value, device: restoreDevice });
|
|
97373
|
-
const stagedPath =
|
|
97609
|
+
const stagedPath = join20(options.stagingHome, "swarms", `${swarm.name}.json`);
|
|
97374
97610
|
if (await stageRestoreBytes(stagedPath, prettyJson(swarm))) {
|
|
97375
97611
|
swarms.push({
|
|
97376
97612
|
kind: "swarm",
|
|
97377
97613
|
name: swarm.name,
|
|
97378
97614
|
stagedPath,
|
|
97379
|
-
targetPath:
|
|
97615
|
+
targetPath: join20(options.home, "swarms", `${swarm.name}.json`)
|
|
97380
97616
|
});
|
|
97381
97617
|
} else {
|
|
97382
97618
|
skipped2.push({ kind: "swarm", name: swarm.name, reason: "write_failed" });
|
|
@@ -97386,13 +97622,13 @@ async function stageV2Restore(options) {
|
|
|
97386
97622
|
const movements = [];
|
|
97387
97623
|
for (const movement of validMovements) {
|
|
97388
97624
|
const restored = reconcileRestoredMovement(movement, assumedReceiptKeys);
|
|
97389
|
-
const stagedPath =
|
|
97625
|
+
const stagedPath = join20(options.stagingHome, "movements", `${restored.id}.json`);
|
|
97390
97626
|
if (await stageRestoreBytes(stagedPath, serializeMovement(restored))) {
|
|
97391
97627
|
movements.push({
|
|
97392
97628
|
kind: "movement",
|
|
97393
97629
|
name: restored.id,
|
|
97394
97630
|
stagedPath,
|
|
97395
|
-
targetPath:
|
|
97631
|
+
targetPath: join20(options.home, "movements", `${restored.id}.json`),
|
|
97396
97632
|
movement: restored
|
|
97397
97633
|
});
|
|
97398
97634
|
} else {
|
|
@@ -97463,8 +97699,8 @@ async function publishRestoreFile(file2, staged) {
|
|
|
97463
97699
|
let identical = false;
|
|
97464
97700
|
try {
|
|
97465
97701
|
const [source, target] = await Promise.all([
|
|
97466
|
-
|
|
97467
|
-
|
|
97702
|
+
readFile24(file2.stagedPath),
|
|
97703
|
+
readFile24(file2.targetPath)
|
|
97468
97704
|
]);
|
|
97469
97705
|
identical = source.equals(target);
|
|
97470
97706
|
} catch {
|
|
@@ -97496,7 +97732,7 @@ async function publishRestoreReceiptsLocked(staged, targetPath) {
|
|
|
97496
97732
|
let existing = "";
|
|
97497
97733
|
let existingLines = /* @__PURE__ */ new Set();
|
|
97498
97734
|
try {
|
|
97499
|
-
await
|
|
97735
|
+
await readFile24(staged.receiptsPath, "utf8");
|
|
97500
97736
|
await mkdir19(dirname12(targetPath), { recursive: true, mode: 448 });
|
|
97501
97737
|
try {
|
|
97502
97738
|
const journal = await readRestoreReceiptJournal(targetPath);
|
|
@@ -97551,7 +97787,7 @@ async function reconcilePublishedMovements(staged, home, requireDurableSafety =
|
|
|
97551
97787
|
const unjournaledKeys = new Set([...signedKeys].filter((key2) => !journaledKeys.has(key2)));
|
|
97552
97788
|
let files;
|
|
97553
97789
|
try {
|
|
97554
|
-
files = await readdir8(
|
|
97790
|
+
files = await readdir8(join20(home, "movements"));
|
|
97555
97791
|
} catch (error61) {
|
|
97556
97792
|
if (isMissingFile4(error61)) return;
|
|
97557
97793
|
if (requireDurableSafety && unjournaledKeys.size > 0) throw error61;
|
|
@@ -97652,9 +97888,9 @@ function assertRelayKey(value) {
|
|
|
97652
97888
|
throw new BackupError("relay_invalid_key");
|
|
97653
97889
|
}
|
|
97654
97890
|
}
|
|
97655
|
-
function readRelayRandomBytes(
|
|
97891
|
+
function readRelayRandomBytes(randomBytes18, length) {
|
|
97656
97892
|
try {
|
|
97657
|
-
const value =
|
|
97893
|
+
const value = randomBytes18(length);
|
|
97658
97894
|
if (!(value instanceof Uint8Array) || value.byteLength !== length) throw new Error();
|
|
97659
97895
|
return Buffer.from(value);
|
|
97660
97896
|
} catch {
|
|
@@ -97772,7 +98008,7 @@ async function createRestoreMarker(vaultPath2, registryPath, fingerprint, vaultK
|
|
|
97772
98008
|
}
|
|
97773
98009
|
async function readRestoreMarker(path, fingerprint, vaultKey) {
|
|
97774
98010
|
try {
|
|
97775
|
-
const marker = restoreMarkerSchema.parse(JSON.parse(await
|
|
98011
|
+
const marker = restoreMarkerSchema.parse(JSON.parse(await readFile24(path, "utf8")));
|
|
97776
98012
|
const expectedMac = restoreMarkerMac(marker, vaultKey);
|
|
97777
98013
|
if (marker.fingerprint !== fingerprint || !timingSafeEqual(Buffer.from(marker.mac, "hex"), Buffer.from(expectedMac, "hex"))) {
|
|
97778
98014
|
throw new Error();
|
|
@@ -97789,7 +98025,7 @@ function restoreMarkerMac(marker, vaultKey) {
|
|
|
97789
98025
|
).digest("hex");
|
|
97790
98026
|
}
|
|
97791
98027
|
async function sha256File(path) {
|
|
97792
|
-
return createHash6("sha256").update(await
|
|
98028
|
+
return createHash6("sha256").update(await readFile24(path)).digest("hex");
|
|
97793
98029
|
}
|
|
97794
98030
|
async function notifyRestorePublish(hook, step2, rememberError) {
|
|
97795
98031
|
try {
|
|
@@ -98091,7 +98327,7 @@ function copyTransferReceipt(receipt) {
|
|
|
98091
98327
|
async function readReceiptJournal(path) {
|
|
98092
98328
|
let raw;
|
|
98093
98329
|
try {
|
|
98094
|
-
raw = await
|
|
98330
|
+
raw = await readFile24(path, "utf8");
|
|
98095
98331
|
} catch (error61) {
|
|
98096
98332
|
if (isMissingFile4(error61)) return [];
|
|
98097
98333
|
throw error61;
|
|
@@ -98101,7 +98337,7 @@ async function readReceiptJournal(path) {
|
|
|
98101
98337
|
async function readRestoreReceiptJournal(path) {
|
|
98102
98338
|
let raw;
|
|
98103
98339
|
try {
|
|
98104
|
-
raw = await
|
|
98340
|
+
raw = await readFile24(path, "utf8");
|
|
98105
98341
|
} catch (error61) {
|
|
98106
98342
|
if (isMissingFile4(error61)) return { raw: "", lines: /* @__PURE__ */ new Set(), signedKeys: /* @__PURE__ */ new Set() };
|
|
98107
98343
|
throw error61;
|
|
@@ -98220,8 +98456,8 @@ function assertOwnerKey(ownerKey) {
|
|
|
98220
98456
|
assertBytes(ownerKey.key, 32);
|
|
98221
98457
|
assertBytes(ownerKey.salt, 32);
|
|
98222
98458
|
}
|
|
98223
|
-
function readRandomBytes(
|
|
98224
|
-
const value =
|
|
98459
|
+
function readRandomBytes(randomBytes18, length) {
|
|
98460
|
+
const value = randomBytes18(length);
|
|
98225
98461
|
if (!(value instanceof Uint8Array) || value.byteLength !== length) {
|
|
98226
98462
|
throw new BackupError("backup_invalid_input");
|
|
98227
98463
|
}
|
|
@@ -98460,7 +98696,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
98460
98696
|
try {
|
|
98461
98697
|
let vaultFile;
|
|
98462
98698
|
try {
|
|
98463
|
-
vaultFile = await readVaultFileUnlocked(
|
|
98699
|
+
vaultFile = await readVaultFileUnlocked(join21(options.store.home, "vault.json"));
|
|
98464
98700
|
} catch (error61) {
|
|
98465
98701
|
if (error61 instanceof VaultError && error61.code === "not_found") {
|
|
98466
98702
|
return { status: "skipped", reason: "no_vault" };
|
|
@@ -98469,7 +98705,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
98469
98705
|
}
|
|
98470
98706
|
try {
|
|
98471
98707
|
vaultKey = vaultFile.protected ? await unlockProtectedVault({
|
|
98472
|
-
path:
|
|
98708
|
+
path: join21(options.store.home, "vault.json"),
|
|
98473
98709
|
secrets: options.secrets,
|
|
98474
98710
|
env: options.env,
|
|
98475
98711
|
...options.now === void 0 ? {} : { now: options.now }
|
|
@@ -99142,7 +99378,7 @@ async function readProcessStdin() {
|
|
|
99142
99378
|
}
|
|
99143
99379
|
|
|
99144
99380
|
// src/version.ts
|
|
99145
|
-
var CLI_VERSION = "0.
|
|
99381
|
+
var CLI_VERSION = "0.13.0";
|
|
99146
99382
|
|
|
99147
99383
|
// src/status.ts
|
|
99148
99384
|
async function statusCommand(argv, json2, io, dependencies) {
|
|
@@ -99309,7 +99545,7 @@ function withDeadlineSignal3(fetchImpl, deadline) {
|
|
|
99309
99545
|
}
|
|
99310
99546
|
async function statusConfig(path) {
|
|
99311
99547
|
try {
|
|
99312
|
-
await
|
|
99548
|
+
await stat15(path);
|
|
99313
99549
|
} catch (error61) {
|
|
99314
99550
|
if (isMissingFile(error61)) return getDefaultConfig(process.env);
|
|
99315
99551
|
throw error61;
|
|
@@ -99507,7 +99743,7 @@ async function siblingsFetchImpl(dependencies) {
|
|
|
99507
99743
|
const configPath = getVapiPaths().config;
|
|
99508
99744
|
let config2;
|
|
99509
99745
|
try {
|
|
99510
|
-
await
|
|
99746
|
+
await stat16(configPath);
|
|
99511
99747
|
config2 = await loadConfig(configPath, process.env);
|
|
99512
99748
|
} catch (error61) {
|
|
99513
99749
|
if (!isMissingFile(error61)) throw error61;
|
|
@@ -99596,7 +99832,7 @@ ${IMPORT_USAGE}`);
|
|
|
99596
99832
|
const passphrase = await secretPrompt(dependencies)(`Passphrase for ${keystorePath}: `);
|
|
99597
99833
|
privateKey = (await exportKeystoreKeys(passphrase, keystorePath)).evm.privateKey;
|
|
99598
99834
|
} else if (keyPath !== void 0) {
|
|
99599
|
-
privateKey = (await
|
|
99835
|
+
privateKey = (await readFile25(keyPath, "utf8")).trim();
|
|
99600
99836
|
} else {
|
|
99601
99837
|
privateKey = await secretPrompt(dependencies)("Private key: ");
|
|
99602
99838
|
}
|
|
@@ -99644,10 +99880,10 @@ async function accountsRenameCommand(argv, json2, io, dependencies) {
|
|
|
99644
99880
|
{
|
|
99645
99881
|
previous: from16,
|
|
99646
99882
|
...address4 === void 0 ? {} : { address: address4 },
|
|
99647
|
-
vault:
|
|
99883
|
+
vault: join22(store.home, "vault.json"),
|
|
99648
99884
|
message: `Wallet ${from16} is now ${renamed.name}.`
|
|
99649
99885
|
},
|
|
99650
|
-
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${
|
|
99886
|
+
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${join22(store.home, "vault.json")}`].join(
|
|
99651
99887
|
"\n"
|
|
99652
99888
|
)
|
|
99653
99889
|
);
|
|
@@ -99756,13 +99992,13 @@ async function accountsRestoreCommand(argv, json2, io, dependencies) {
|
|
|
99756
99992
|
{ name: restored.name, ...address4 === void 0 ? {} : { address: address4 } },
|
|
99757
99993
|
{
|
|
99758
99994
|
...address4 === void 0 ? {} : { address: address4 },
|
|
99759
|
-
vault:
|
|
99995
|
+
vault: join22(store.home, "vault.json"),
|
|
99760
99996
|
spendCaps: restored.entry.spendCaps,
|
|
99761
99997
|
message: `Wallet ${restored.name} restored to the device vault.`
|
|
99762
99998
|
},
|
|
99763
99999
|
[
|
|
99764
100000
|
`Wallet ${restored.name} restored to the device vault.`,
|
|
99765
|
-
`Vault: ${
|
|
100001
|
+
`Vault: ${join22(store.home, "vault.json")}`
|
|
99766
100002
|
].join("\n")
|
|
99767
100003
|
);
|
|
99768
100004
|
}
|
|
@@ -100092,7 +100328,7 @@ function formatNetworkAccounts(accounts) {
|
|
|
100092
100328
|
}
|
|
100093
100329
|
|
|
100094
100330
|
// src/cloud-backup.ts
|
|
100095
|
-
import { join as
|
|
100331
|
+
import { join as join23 } from "node:path";
|
|
100096
100332
|
var CLOUD_BACKUP_USAGE = "Usage: vapi backup --cloud [off] [--json]";
|
|
100097
100333
|
var OWNER_RESTORE_USAGE = "Usage: vapi restore --from-owner [--owner <0x\u2026>] [--json]";
|
|
100098
100334
|
var OWNER_PATTERN2 = /^0x[0-9a-fA-F]{40}$/u;
|
|
@@ -100115,7 +100351,7 @@ async function cloudBackupCommand(argv, json2, io, dependencies) {
|
|
|
100115
100351
|
}
|
|
100116
100352
|
async function enrollCloudBackup(json2, io, dependencies) {
|
|
100117
100353
|
const paths = getVapiPaths();
|
|
100118
|
-
if (!await
|
|
100354
|
+
if (!await fileExists3(join23(paths.directory, "vault.json"))) {
|
|
100119
100355
|
throw new Error("No vault on this device. Run vapi setup first.");
|
|
100120
100356
|
}
|
|
100121
100357
|
const context = await cloudContext(io, dependencies);
|
|
@@ -100227,7 +100463,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
100227
100463
|
}
|
|
100228
100464
|
const expectedOwner = ownerValue?.toLowerCase();
|
|
100229
100465
|
const paths = getVapiPaths();
|
|
100230
|
-
if (await
|
|
100466
|
+
if (await fileExists3(join23(paths.directory, "vault.json")) && !await fileExists3(join23(paths.directory, ".backup-restore.json"))) {
|
|
100231
100467
|
throw new Error(
|
|
100232
100468
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
100233
100469
|
);
|
|
@@ -100283,7 +100519,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
100283
100519
|
env: getEnvironment(dependencies),
|
|
100284
100520
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
100285
100521
|
});
|
|
100286
|
-
if (!await
|
|
100522
|
+
if (!await fileExists3(paths.config)) {
|
|
100287
100523
|
const networks = restored.networks.length === 0 ? ["base"] : restored.networks;
|
|
100288
100524
|
await writeDefaultConfig(paths.config, getEnvironment(dependencies), { networks });
|
|
100289
100525
|
}
|
|
@@ -101324,20 +101560,20 @@ function shortExcerpt(value) {
|
|
|
101324
101560
|
}
|
|
101325
101561
|
|
|
101326
101562
|
// src/agent.ts
|
|
101327
|
-
import { readFile as
|
|
101328
|
-
import { join as
|
|
101563
|
+
import { readFile as readFile27, stat as stat17 } from "node:fs/promises";
|
|
101564
|
+
import { join as join26 } from "node:path";
|
|
101329
101565
|
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
101330
101566
|
|
|
101331
101567
|
// src/headless.ts
|
|
101332
101568
|
import { chmod as chmod7, mkdtemp as mkdtemp2, rm as rm4, writeFile as writeFile10 } from "node:fs/promises";
|
|
101333
101569
|
import { rmSync } from "node:fs";
|
|
101334
101570
|
import { tmpdir as osTmpdir } from "node:os";
|
|
101335
|
-
import { join as
|
|
101571
|
+
import { join as join24 } from "node:path";
|
|
101336
101572
|
var BUNDLE_VARIABLE_PATTERN = /^[A-Z_][A-Z0-9_]*$/u;
|
|
101337
101573
|
var REMOTE_BLOCKED_GRANTS2 = /* @__PURE__ */ new Set(["delegate", "allocate"]);
|
|
101338
101574
|
var agentProfileOptions = { schema: registeredAgentProfileSchema };
|
|
101339
101575
|
async function createHeadlessHome(bundle, options = {}) {
|
|
101340
|
-
const home = await mkdtemp2(
|
|
101576
|
+
const home = await mkdtemp2(join24(options.tmpdir ?? osTmpdir(), "vapi-headless-"));
|
|
101341
101577
|
const cleanup = async () => {
|
|
101342
101578
|
await rm4(home, { recursive: true, force: true });
|
|
101343
101579
|
};
|
|
@@ -101537,18 +101773,18 @@ import { readFile as nodeReadFile } from "node:fs/promises";
|
|
|
101537
101773
|
|
|
101538
101774
|
// src/runtime-railway.ts
|
|
101539
101775
|
import { spawn as spawn2 } from "node:child_process";
|
|
101540
|
-
import { randomBytes as
|
|
101776
|
+
import { randomBytes as randomBytes17 } from "node:crypto";
|
|
101541
101777
|
import { closeSync, fsyncSync, mkdirSync, openSync, renameSync, rmSync as rmSync2, writeSync } from "node:fs";
|
|
101542
101778
|
import {
|
|
101543
101779
|
mkdtemp as nodeMkdtemp,
|
|
101544
101780
|
readdir as readdir9,
|
|
101545
|
-
readFile as
|
|
101781
|
+
readFile as readFile26,
|
|
101546
101782
|
rm as nodeRm,
|
|
101547
101783
|
stat as nodeStat,
|
|
101548
101784
|
writeFile as nodeWriteFile
|
|
101549
101785
|
} from "node:fs/promises";
|
|
101550
101786
|
import { tmpdir as osTmpdir2 } from "node:os";
|
|
101551
|
-
import { basename as basename4, dirname as dirname13, join as
|
|
101787
|
+
import { basename as basename4, dirname as dirname13, join as join25 } from "node:path";
|
|
101552
101788
|
var RAILWAY_CLI = {
|
|
101553
101789
|
binary: "railway",
|
|
101554
101790
|
create: (options) => [
|
|
@@ -101720,7 +101956,7 @@ async function assertRemoteSafeMember(args) {
|
|
|
101720
101956
|
}
|
|
101721
101957
|
function railwaySidecarPath(home, runId) {
|
|
101722
101958
|
if (!isRunId(runId)) throw new RuntimeError("invalid_run_id", `Invalid run id: ${runId}.`);
|
|
101723
|
-
return
|
|
101959
|
+
return join25(runsDirectory(home), `${runId}.railway.json`);
|
|
101724
101960
|
}
|
|
101725
101961
|
function createRailwayRuntime(options) {
|
|
101726
101962
|
const { home } = options;
|
|
@@ -102045,10 +102281,10 @@ function createRailwayRuntime(options) {
|
|
|
102045
102281
|
let createError;
|
|
102046
102282
|
let cleanupError;
|
|
102047
102283
|
try {
|
|
102048
|
-
directory = await fs.mkdtemp(
|
|
102284
|
+
directory = await fs.mkdtemp(join25(options.tmpdir ?? osTmpdir2(), "vapi-railway-"));
|
|
102049
102285
|
assertNotInterrupted();
|
|
102050
102286
|
await assertMode(fs, directory, 448, "env-file directory");
|
|
102051
|
-
envFile =
|
|
102287
|
+
envFile = join25(directory, "member.env");
|
|
102052
102288
|
await fs.writeFile(envFile, `${RAILWAY_CLI.bundleVariable}=${bundle}
|
|
102053
102289
|
`, {
|
|
102054
102290
|
encoding: "utf8",
|
|
@@ -102503,9 +102739,9 @@ async function writeSidecar(home, runId, sidecar) {
|
|
|
102503
102739
|
function writeSidecarSync(path, sidecar) {
|
|
102504
102740
|
const directory = dirname13(path);
|
|
102505
102741
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
102506
|
-
const temporary =
|
|
102742
|
+
const temporary = join25(
|
|
102507
102743
|
directory,
|
|
102508
|
-
`.${basename4(path)}.${process.pid}.${
|
|
102744
|
+
`.${basename4(path)}.${process.pid}.${randomBytes17(6).toString("hex")}.tmp`
|
|
102509
102745
|
);
|
|
102510
102746
|
try {
|
|
102511
102747
|
const descriptor2 = openSync(temporary, "wx", 384);
|
|
@@ -102543,7 +102779,7 @@ var LEGACY_SIDECAR_KEYS = ["checkpoint", "keepSandbox", "sandboxId", "v"];
|
|
|
102543
102779
|
async function readSidecar(home, runId) {
|
|
102544
102780
|
let parsed;
|
|
102545
102781
|
try {
|
|
102546
|
-
parsed = JSON.parse(await
|
|
102782
|
+
parsed = JSON.parse(await readFile26(railwaySidecarPath(home, runId), "utf8"));
|
|
102547
102783
|
} catch {
|
|
102548
102784
|
return void 0;
|
|
102549
102785
|
}
|
|
@@ -102601,7 +102837,7 @@ async function assertMode(fs, path, mode, what) {
|
|
|
102601
102837
|
}
|
|
102602
102838
|
}
|
|
102603
102839
|
async function deviceVaultKey(home, secrets, now) {
|
|
102604
|
-
const path =
|
|
102840
|
+
const path = join25(home, "vault.json");
|
|
102605
102841
|
const metadata = await readVaultFileUnlocked(path);
|
|
102606
102842
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
102607
102843
|
path,
|
|
@@ -102656,7 +102892,7 @@ function createLocalRuntime(options) {
|
|
|
102656
102892
|
const processCommand = options.processCommand ?? defaultProcessCommand;
|
|
102657
102893
|
const ownsProcess = (handle, pid) => processCommand(pid)?.includes(runResultPath(home, handle.runId)) === true;
|
|
102658
102894
|
const closeFd = options.closeFd ?? closeSync2;
|
|
102659
|
-
const
|
|
102895
|
+
const readFile33 = options.readFile ?? nodeReadFile;
|
|
102660
102896
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
102661
102897
|
const openLog = options.openLog ?? ((path) => {
|
|
102662
102898
|
mkdirSync2(runsDirectory(home), { recursive: true, mode: 448 });
|
|
@@ -102711,7 +102947,7 @@ function createLocalRuntime(options) {
|
|
|
102711
102947
|
return handle;
|
|
102712
102948
|
},
|
|
102713
102949
|
async status(handle) {
|
|
102714
|
-
const result = await readResultFile(
|
|
102950
|
+
const result = await readResultFile(readFile33, runResultPath(home, handle.runId));
|
|
102715
102951
|
if (result !== void 0) return result;
|
|
102716
102952
|
const pid = localPid(handle);
|
|
102717
102953
|
if (pid === void 0 || handle.kind !== "local") {
|
|
@@ -102814,10 +103050,10 @@ function childArguments(member, run) {
|
|
|
102814
103050
|
...run.drawUsd ? ["--draw", run.drawUsd] : []
|
|
102815
103051
|
];
|
|
102816
103052
|
}
|
|
102817
|
-
async function readResultFile(
|
|
103053
|
+
async function readResultFile(readFile33, path) {
|
|
102818
103054
|
let text;
|
|
102819
103055
|
try {
|
|
102820
|
-
text = await
|
|
103056
|
+
text = await readFile33(path, "utf8");
|
|
102821
103057
|
} catch (error61) {
|
|
102822
103058
|
if (hasCode3(error61, "ENOENT")) return void 0;
|
|
102823
103059
|
return { state: "failed", detail: "unreadable result file" };
|
|
@@ -102942,7 +103178,7 @@ async function createCommand(argv, json2, io, dependencies) {
|
|
|
102942
103178
|
if (await profileFileExists(paths.agentsDir, name)) {
|
|
102943
103179
|
throw new Error(`Agent ${name} already exists.`);
|
|
102944
103180
|
}
|
|
102945
|
-
const instructions = await
|
|
103181
|
+
const instructions = await readFile27(instructionsPath, "utf8");
|
|
102946
103182
|
if (instructions.length > 2e4) {
|
|
102947
103183
|
throw new UsageError("--instructions must contain at most 20000 characters.");
|
|
102948
103184
|
}
|
|
@@ -103528,7 +103764,7 @@ function explicitWallet(name) {
|
|
|
103528
103764
|
}
|
|
103529
103765
|
async function profileFileExists(directory, name) {
|
|
103530
103766
|
try {
|
|
103531
|
-
await
|
|
103767
|
+
await stat17(join26(directory, `${name}.json`));
|
|
103532
103768
|
return true;
|
|
103533
103769
|
} catch (error61) {
|
|
103534
103770
|
if (isMissingFile(error61)) return false;
|
|
@@ -103589,7 +103825,7 @@ function usd(value, minimumDecimals = 0) {
|
|
|
103589
103825
|
|
|
103590
103826
|
// src/mcp-install.ts
|
|
103591
103827
|
import { spawn as spawn3 } from "node:child_process";
|
|
103592
|
-
import { mkdir as mkdir20, readFile as
|
|
103828
|
+
import { mkdir as mkdir20, readFile as readFile28, writeFile as writeFile11 } from "node:fs/promises";
|
|
103593
103829
|
import { homedir as systemHomedir } from "node:os";
|
|
103594
103830
|
import { dirname as dirname14, posix, win32 as win322 } from "node:path";
|
|
103595
103831
|
|
|
@@ -103969,7 +104205,7 @@ function isRecord12(value) {
|
|
|
103969
104205
|
}
|
|
103970
104206
|
async function readExistingFile(path) {
|
|
103971
104207
|
try {
|
|
103972
|
-
return await
|
|
104208
|
+
return await readFile28(path, "utf8");
|
|
103973
104209
|
} catch (error61) {
|
|
103974
104210
|
if (isMissingFile(error61)) return void 0;
|
|
103975
104211
|
throw error61;
|
|
@@ -103977,7 +104213,7 @@ async function readExistingFile(path) {
|
|
|
103977
104213
|
}
|
|
103978
104214
|
async function pathExists5(path) {
|
|
103979
104215
|
try {
|
|
103980
|
-
await
|
|
104216
|
+
await readFile28(path);
|
|
103981
104217
|
return true;
|
|
103982
104218
|
} catch (error61) {
|
|
103983
104219
|
if (isMissingFile(error61)) return false;
|
|
@@ -103987,15 +104223,15 @@ async function pathExists5(path) {
|
|
|
103987
104223
|
|
|
103988
104224
|
// src/code.ts
|
|
103989
104225
|
import { constants as constants2 } from "node:fs";
|
|
103990
|
-
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";
|
|
103991
104227
|
import { homedir as homedir3 } from "node:os";
|
|
103992
|
-
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";
|
|
103993
104229
|
var VAPI_CODEX_PROVIDER = "vapi";
|
|
103994
104230
|
var VAPI_CODEX_PROFILE = "vapi";
|
|
103995
104231
|
var VAPI_CODEX_DEFAULT_MODEL = "venice/openai-gpt-61-sol";
|
|
103996
104232
|
var VAPI_ROUTER_KEY_ENV = "VAPI_ROUTER_KEY";
|
|
103997
104233
|
function codexConfigPath(env, home) {
|
|
103998
|
-
return
|
|
104234
|
+
return join27(env.CODEX_HOME || join27(home, ".codex"), "config.toml");
|
|
103999
104235
|
}
|
|
104000
104236
|
function hasVapiCodexProfile(contents) {
|
|
104001
104237
|
const roots = new Set(
|
|
@@ -104089,7 +104325,7 @@ function aliasContents(original, tools) {
|
|
|
104089
104325
|
}
|
|
104090
104326
|
async function readOptional(path) {
|
|
104091
104327
|
try {
|
|
104092
|
-
return await
|
|
104328
|
+
return await readFile29(path, "utf8");
|
|
104093
104329
|
} catch (error61) {
|
|
104094
104330
|
if (isMissingFile(error61)) return void 0;
|
|
104095
104331
|
throw error61;
|
|
@@ -104111,7 +104347,7 @@ async function codeCommand(argv, json2, io, dependencies) {
|
|
|
104111
104347
|
const env = getEnvironment(dependencies);
|
|
104112
104348
|
const home = dependencies.code?.homedir ?? homedir3();
|
|
104113
104349
|
const config2 = codexConfigPath(env, home);
|
|
104114
|
-
const rcPaths = [
|
|
104350
|
+
const rcPaths = [join27(home, ".zshrc"), join27(home, ".bashrc")];
|
|
104115
104351
|
if (command === "uninstall") {
|
|
104116
104352
|
const removed = [];
|
|
104117
104353
|
const previous = await readOptional(config2);
|
|
@@ -104235,7 +104471,7 @@ async function codeCommand(argv, json2, io, dependencies) {
|
|
|
104235
104471
|
|
|
104236
104472
|
// src/code-launch.ts
|
|
104237
104473
|
import { spawn as spawn4 } from "node:child_process";
|
|
104238
|
-
import { readFile as
|
|
104474
|
+
import { readFile as readFile30 } from "node:fs/promises";
|
|
104239
104475
|
import { constants as constants3, homedir as homedir4 } from "node:os";
|
|
104240
104476
|
var CLAUDE_MODELS = {
|
|
104241
104477
|
sonnet: "venice/claude-sonnet-5-5",
|
|
@@ -104449,7 +104685,7 @@ function claudeModel(model) {
|
|
|
104449
104685
|
async function codexArgs(env, baseURL, model, dependencies) {
|
|
104450
104686
|
let contents = "";
|
|
104451
104687
|
try {
|
|
104452
|
-
contents = await
|
|
104688
|
+
contents = await readFile30(
|
|
104453
104689
|
codexConfigPath(env, dependencies.code?.homedir ?? homedir4()),
|
|
104454
104690
|
"utf8"
|
|
104455
104691
|
);
|
|
@@ -104624,7 +104860,7 @@ async function sendConfig(dependencies) {
|
|
|
104624
104860
|
|
|
104625
104861
|
// src/setup.ts
|
|
104626
104862
|
import { rm as rm5 } from "node:fs/promises";
|
|
104627
|
-
import { join as
|
|
104863
|
+
import { join as join28 } from "node:path";
|
|
104628
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.`;
|
|
104629
104865
|
var VAULT_CHOICE = "Create a new vault, or restore one from a recovery phrase? [new/restore] ";
|
|
104630
104866
|
async function setupCommand(argv, json2, io, dependencies) {
|
|
@@ -104643,18 +104879,24 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
104643
104879
|
const steps = [];
|
|
104644
104880
|
const humanIo = json2 ? stderrIo(io) : io;
|
|
104645
104881
|
const accountCount = parseAccountCount(parsed.one("--accounts"));
|
|
104646
|
-
if (!await
|
|
104882
|
+
if (!await fileExists3(paths.config)) {
|
|
104647
104883
|
await writeDefaultConfig(paths.config, process.env, { networks: ["base"] });
|
|
104648
104884
|
steps.push("config");
|
|
104649
104885
|
}
|
|
104650
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
|
+
}
|
|
104651
104893
|
let store = await openWalletStore(dependencies);
|
|
104652
104894
|
let vault = "existing";
|
|
104653
104895
|
let changedVault = false;
|
|
104654
104896
|
let changedAccount = false;
|
|
104655
104897
|
let changedLink = false;
|
|
104656
104898
|
let scannedAddresses;
|
|
104657
|
-
if (!await
|
|
104899
|
+
if (!await fileExists3(join28(paths.directory, "vault.json"))) {
|
|
104658
104900
|
const choice = await vaultChoice(dependencies);
|
|
104659
104901
|
if (choice === "restore") {
|
|
104660
104902
|
if (!isInteractive(dependencies)) {
|
|
@@ -104742,7 +104984,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
104742
104984
|
let scannedAddresses = 0;
|
|
104743
104985
|
try {
|
|
104744
104986
|
const restored = await restoreVault({
|
|
104745
|
-
path:
|
|
104987
|
+
path: join28(paths.directory, "vault.json"),
|
|
104746
104988
|
key: key2,
|
|
104747
104989
|
phrase: validatedPhrase,
|
|
104748
104990
|
probe: async (address4) => await readBalance3(address4) > 0n,
|
|
@@ -104753,7 +104995,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
104753
104995
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
104754
104996
|
});
|
|
104755
104997
|
names = restored.accounts().map((account) => account.name);
|
|
104756
|
-
await rm5(
|
|
104998
|
+
await rm5(join28(paths.directory, "wallets.json"), { force: true });
|
|
104757
104999
|
} finally {
|
|
104758
105000
|
key2.fill(0);
|
|
104759
105001
|
}
|
|
@@ -104871,7 +105113,7 @@ async function withRouterError2(operation) {
|
|
|
104871
105113
|
|
|
104872
105114
|
// src/task.ts
|
|
104873
105115
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
104874
|
-
import { readFile as
|
|
105116
|
+
import { readFile as readFile31 } from "node:fs/promises";
|
|
104875
105117
|
var TASK_HELP = `Usage:
|
|
104876
105118
|
vapi task search [--open] [--min <usd>] [--tab trending|new|closing|paid] [--limit <n>] [--json]
|
|
104877
105119
|
vapi task show <id> [--account <name>] [--json]
|
|
@@ -105207,7 +105449,7 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
105207
105449
|
if (maxAwards !== void 0 && maxAwards > TASK_LIMITS.maxAwardsMax)
|
|
105208
105450
|
throw new UsageError("--max-awards must be between 1 and 50.");
|
|
105209
105451
|
if (parsed.one("--webhook") !== void 0) httpsUrl2(parsed.one("--webhook"), "--webhook");
|
|
105210
|
-
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await
|
|
105452
|
+
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await readFile31(briefPath, "utf8");
|
|
105211
105453
|
const input2 = {
|
|
105212
105454
|
title: title.trim(),
|
|
105213
105455
|
description: brief.trim(),
|
|
@@ -106885,7 +107127,7 @@ async function referencedSleep(milliseconds, signal) {
|
|
|
106885
107127
|
}
|
|
106886
107128
|
|
|
106887
107129
|
// src/vault.ts
|
|
106888
|
-
import { join as
|
|
107130
|
+
import { join as join29 } from "node:path";
|
|
106889
107131
|
var VAULT_USAGE = "Usage: vapi vault protect|unprotect|lock|unlock|status [--json]";
|
|
106890
107132
|
var RESTORE_USAGE = "Usage: vapi restore [--accounts <n> | --from-owner [--owner <0x\u2026>]] [--json]";
|
|
106891
107133
|
var LEGACY_PASSWORD_NOTICE = "VAPI_KEYSTORE_PASSWORD is deprecated for vault passwords; use VAPI_VAULT_PASSWORD instead.";
|
|
@@ -106929,13 +107171,13 @@ async function restoreCommand(argv, json2, io, dependencies) {
|
|
|
106929
107171
|
}
|
|
106930
107172
|
const accountCount = parseRestoreAccountCount(parsed.one("--accounts"));
|
|
106931
107173
|
const paths = getVapiPaths();
|
|
106932
|
-
const path =
|
|
106933
|
-
if (await
|
|
107174
|
+
const path = join29(paths.directory, "vault.json");
|
|
107175
|
+
if (await fileExists3(path)) {
|
|
106934
107176
|
throw new Error(
|
|
106935
107177
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
106936
107178
|
);
|
|
106937
107179
|
}
|
|
106938
|
-
if (!await
|
|
107180
|
+
if (!await fileExists3(paths.config)) {
|
|
106939
107181
|
await writeDefaultConfig(paths.config, process.env, { networks: ["base"] });
|
|
106940
107182
|
}
|
|
106941
107183
|
const config2 = await readConfig(paths.config, json2 ? quietIo(io) : io);
|
|
@@ -107086,7 +107328,7 @@ function requireNoArguments(argv) {
|
|
|
107086
107328
|
parseArguments(argv, { valueOptions: /* @__PURE__ */ new Set(), maximumPositionals: 0 });
|
|
107087
107329
|
}
|
|
107088
107330
|
function vaultPath() {
|
|
107089
|
-
return
|
|
107331
|
+
return join29(getVapiPaths().directory, "vault.json");
|
|
107090
107332
|
}
|
|
107091
107333
|
function quietIo(io) {
|
|
107092
107334
|
return { stdout: () => void 0, stderr: io.stderr };
|
|
@@ -107537,7 +107779,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
107537
107779
|
break;
|
|
107538
107780
|
case "unlock":
|
|
107539
107781
|
io.stderr("vapi unlock is now vapi vault unlock; the old name works for one release.");
|
|
107540
|
-
if (await
|
|
107782
|
+
if (await fileExists3(join30(getVapiPaths().directory, "vault.json"))) {
|
|
107541
107783
|
parseArguments(args.slice(1), {
|
|
107542
107784
|
valueOptions: /* @__PURE__ */ new Set([WALLET_OPTION5]),
|
|
107543
107785
|
maximumPositionals: 0
|
|
@@ -107725,7 +107967,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
107725
107967
|
await recordAudit(dependencies, "wallet.create", { wallet: created.name });
|
|
107726
107968
|
const account = created.account;
|
|
107727
107969
|
if (!json2) await showRecoveryPhrase(created.recoveryPhrase, io, dependencies);
|
|
107728
|
-
if (!await
|
|
107970
|
+
if (!await fileExists3(paths.config)) {
|
|
107729
107971
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
107730
107972
|
} else {
|
|
107731
107973
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -107743,7 +107985,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
107743
107985
|
address: account.address,
|
|
107744
107986
|
accounts,
|
|
107745
107987
|
config: paths.config,
|
|
107746
|
-
vault:
|
|
107988
|
+
vault: join30(paths.directory, "vault.json"),
|
|
107747
107989
|
...configRewrites.length > 0 ? { configRewrites } : {},
|
|
107748
107990
|
custody: "self",
|
|
107749
107991
|
warning: CUSTODY_NOTICE,
|
|
@@ -107873,7 +108115,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
107873
108115
|
await recordAudit(dependencies, "wallet.create", { wallet: created.name });
|
|
107874
108116
|
const account = created.account;
|
|
107875
108117
|
if (!json2) await showRecoveryPhrase(created.recoveryPhrase, io, dependencies);
|
|
107876
|
-
if (!await
|
|
108118
|
+
if (!await fileExists3(paths.config)) {
|
|
107877
108119
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
107878
108120
|
} else {
|
|
107879
108121
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -107882,7 +108124,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
107882
108124
|
const result = {
|
|
107883
108125
|
address: account.address,
|
|
107884
108126
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
107885
|
-
vault:
|
|
108127
|
+
vault: join30(paths.directory, "vault.json"),
|
|
107886
108128
|
...label === void 0 ? {} : { label },
|
|
107887
108129
|
spendCaps: created.entry.spendCaps,
|
|
107888
108130
|
isDefault,
|
|
@@ -107922,7 +108164,7 @@ function formatCaps2(caps) {
|
|
|
107922
108164
|
function walletListResult(store, wallets, unlocked) {
|
|
107923
108165
|
return {
|
|
107924
108166
|
default: store.defaultName ?? null,
|
|
107925
|
-
vault:
|
|
108167
|
+
vault: join30(store.home, "vault.json"),
|
|
107926
108168
|
wallets: wallets.map((wallet) => ({
|
|
107927
108169
|
name: wallet.name,
|
|
107928
108170
|
...wallet.address === void 0 ? {} : { address: wallet.address },
|
|
@@ -109195,7 +109437,7 @@ function formatClaimed(origin, claimed) {
|
|
|
109195
109437
|
}
|
|
109196
109438
|
var EXPORT_KEY_WARNING = "Anyone with this key can spend the wallet. Never paste it into a website or chat.";
|
|
109197
109439
|
async function deviceVaultKey2(store, dependencies) {
|
|
109198
|
-
const path =
|
|
109440
|
+
const path = join30(store.home, "vault.json");
|
|
109199
109441
|
const metadata = await readVaultFileUnlocked(path);
|
|
109200
109442
|
const secrets = getSecretStore(dependencies);
|
|
109201
109443
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
@@ -109288,7 +109530,7 @@ async function backupCommand(argv, json2, io, dependencies) {
|
|
|
109288
109530
|
const target = await targetWallet(parsed, dependencies);
|
|
109289
109531
|
const vaultAccount = await target.store.hasVaultAccount(target.name);
|
|
109290
109532
|
if (vaultAccount) {
|
|
109291
|
-
const vault = await readVaultFileUnlocked(
|
|
109533
|
+
const vault = await readVaultFileUnlocked(join30(target.store.home, "vault.json"));
|
|
109292
109534
|
if (vault.accounts.some((account) => account.name === target.name && account.kind === "imported")) {
|
|
109293
109535
|
throw new KeystoreError(
|
|
109294
109536
|
`Account ${target.name} was imported and is not recoverable from the vault phrase. Back it up with vapi export-key --account ${target.name}.`
|
|
@@ -109365,7 +109607,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109365
109607
|
const existed = store.has(name);
|
|
109366
109608
|
if (existed && !parsed.has("--replace")) {
|
|
109367
109609
|
const address4 = await store.readAddress(name);
|
|
109368
|
-
const location = await store.hasVaultAccount(name) ?
|
|
109610
|
+
const location = await store.hasVaultAccount(name) ? join30(store.home, "vault.json") : store.pathFor(name);
|
|
109369
109611
|
throw new Error(
|
|
109370
109612
|
[
|
|
109371
109613
|
`Wallet ${name} already exists at ${location}.`,
|
|
@@ -109393,7 +109635,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109393
109635
|
const imported = fromPhrase ? await store.create(name, "", { phrase: secret }) : await store.importKey(name, "", secret);
|
|
109394
109636
|
await recordAudit(dependencies, "wallet.import", { wallet: imported.name });
|
|
109395
109637
|
const account = imported.account;
|
|
109396
|
-
if (!await
|
|
109638
|
+
if (!await fileExists3(paths.config)) {
|
|
109397
109639
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
109398
109640
|
} else {
|
|
109399
109641
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -109401,7 +109643,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
109401
109643
|
const result = {
|
|
109402
109644
|
address: account.address,
|
|
109403
109645
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
109404
|
-
vault:
|
|
109646
|
+
vault: join30(paths.directory, "vault.json"),
|
|
109405
109647
|
...previousKeystore ? { previousKeystore } : {},
|
|
109406
109648
|
message: "Wallet imported. Its encrypted key stays on this machine."
|
|
109407
109649
|
};
|
|
@@ -110009,9 +110251,9 @@ function isHttpUrl(value) {
|
|
|
110009
110251
|
return false;
|
|
110010
110252
|
}
|
|
110011
110253
|
}
|
|
110012
|
-
async function
|
|
110254
|
+
async function fileExists3(path) {
|
|
110013
110255
|
try {
|
|
110014
|
-
await
|
|
110256
|
+
await stat18(path);
|
|
110015
110257
|
return true;
|
|
110016
110258
|
} catch (error61) {
|
|
110017
110259
|
if (isMissingFile(error61)) return false;
|
|
@@ -110075,7 +110317,7 @@ async function latestNotice(options, env, signal) {
|
|
|
110075
110317
|
const now = (options.nowMs ?? Date.now)();
|
|
110076
110318
|
let cached2;
|
|
110077
110319
|
try {
|
|
110078
|
-
const value = JSON.parse(await
|
|
110320
|
+
const value = JSON.parse(await readFile32(paths.updateCheck, "utf8"));
|
|
110079
110321
|
if (isRecord13(value) && typeof value.checkedAt === "number" && Number.isFinite(value.checkedAt) && typeof value.latest === "string" && parseVersion(value.latest)) {
|
|
110080
110322
|
cached2 = { checkedAt: value.checkedAt, latest: value.latest };
|
|
110081
110323
|
}
|
|
@@ -110180,7 +110422,7 @@ export {
|
|
|
110180
110422
|
baseUsdcBalanceReader,
|
|
110181
110423
|
confirmWalletName,
|
|
110182
110424
|
deviceVaultKey2 as deviceVaultKey,
|
|
110183
|
-
|
|
110425
|
+
fileExists3 as fileExists,
|
|
110184
110426
|
getEnvironment,
|
|
110185
110427
|
getLinePrompt,
|
|
110186
110428
|
getPrompts,
|