vapi-network 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/SKILL.md +1 -1
- package/dist/cli.js +1466 -1205
- package/dist/cli.js.map +3 -3
- package/dist/index.js +1484 -1214
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6672,7 +6672,7 @@ function weierstrass(curveDef) {
|
|
|
6672
6672
|
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
6673
6673
|
if (["recovered", "canonical"].some((k) => k in opts))
|
|
6674
6674
|
throw new Error("sign() legacy options not supported");
|
|
6675
|
-
const { hash: hash5, randomBytes:
|
|
6675
|
+
const { hash: hash5, randomBytes: randomBytes18 } = CURVE;
|
|
6676
6676
|
let { lowS, prehash, extraEntropy: ent } = opts;
|
|
6677
6677
|
if (lowS == null)
|
|
6678
6678
|
lowS = true;
|
|
@@ -6684,7 +6684,7 @@ function weierstrass(curveDef) {
|
|
|
6684
6684
|
const d = normPrivateKeyToScalar(privateKey);
|
|
6685
6685
|
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
6686
6686
|
if (ent != null && ent !== false) {
|
|
6687
|
-
const e3 = ent === true ?
|
|
6687
|
+
const e3 = ent === true ? randomBytes18(Fp.BYTES) : ent;
|
|
6688
6688
|
seedArgs.push(ensureBytes("extraEntropy", e3));
|
|
6689
6689
|
}
|
|
6690
6690
|
const seed = concatBytes3(...seedArgs);
|
|
@@ -10129,8 +10129,8 @@ __export(src_exports4, {
|
|
|
10129
10129
|
|
|
10130
10130
|
// ../cli/src/cli.ts
|
|
10131
10131
|
import { spawn as spawn5 } from "node:child_process";
|
|
10132
|
-
import { stat as
|
|
10133
|
-
import { join as
|
|
10132
|
+
import { stat as stat18 } from "node:fs/promises";
|
|
10133
|
+
import { join as join31 } from "node:path";
|
|
10134
10134
|
import { createInterface as createInterface3 } from "node:readline/promises";
|
|
10135
10135
|
|
|
10136
10136
|
// ../core/src/index.ts
|
|
@@ -10176,6 +10176,8 @@ __export(src_exports, {
|
|
|
10176
10176
|
ERC20_ABI: () => ERC20_ABI,
|
|
10177
10177
|
EVM_DERIVATION_PATH: () => EVM_DERIVATION_PATH,
|
|
10178
10178
|
EXECUTION_MODES: () => EXECUTION_MODES,
|
|
10179
|
+
FILE_SECRET_STORE_MIN_PASSWORD: () => FILE_SECRET_STORE_MIN_PASSWORD,
|
|
10180
|
+
FILE_SECRET_STORE_PASSWORD_ENV: () => FILE_SECRET_STORE_PASSWORD_ENV,
|
|
10179
10181
|
FIRST_PARTY_PROVENANCES: () => FIRST_PARTY_PROVENANCES,
|
|
10180
10182
|
FileLockedError: () => FileLockedError,
|
|
10181
10183
|
KeystoreError: () => KeystoreError,
|
|
@@ -10268,6 +10270,7 @@ __export(src_exports, {
|
|
|
10268
10270
|
ceilingFloorApplies: () => ceilingFloorApplies,
|
|
10269
10271
|
changeKeystorePassphrase: () => changeKeystorePassphrase,
|
|
10270
10272
|
checkReceiptSettlement: () => checkReceiptSettlement,
|
|
10273
|
+
chooseSecretBackend: () => chooseSecretBackend,
|
|
10271
10274
|
classifySettlement: () => classifySettlement,
|
|
10272
10275
|
completeX402Payment: () => completeX402Payment,
|
|
10273
10276
|
configSchema: () => configSchema,
|
|
@@ -10275,6 +10278,7 @@ __export(src_exports, {
|
|
|
10275
10278
|
createAccount: () => createAccount,
|
|
10276
10279
|
createAgentProfileSchema: () => createAgentProfileSchema,
|
|
10277
10280
|
createChain: () => createChain,
|
|
10281
|
+
createFileSecretStore: () => createFileSecretStore,
|
|
10278
10282
|
createKeystore: () => createKeystore,
|
|
10279
10283
|
createKeystoreFromPrivateKey: () => createKeystoreFromPrivateKey,
|
|
10280
10284
|
createNetworkHttpTransport: () => createNetworkHttpTransport,
|
|
@@ -10314,6 +10318,7 @@ __export(src_exports, {
|
|
|
10314
10318
|
explorerAddressUrl: () => explorerAddressUrl,
|
|
10315
10319
|
explorerTransactionUrl: () => explorerTransactionUrl,
|
|
10316
10320
|
fetchSiblings: () => fetchSiblings,
|
|
10321
|
+
fileSecretStore: () => fileSecretStore,
|
|
10317
10322
|
filterReceiptsByRange: () => filterReceiptsByRange,
|
|
10318
10323
|
filterReceiptsByWallet: () => filterReceiptsByWallet,
|
|
10319
10324
|
firstPartyProvenanceSchema: () => firstPartyProvenanceSchema,
|
|
@@ -10385,6 +10390,7 @@ __export(src_exports, {
|
|
|
10385
10390
|
noPassphraseHint: () => noPassphraseHint,
|
|
10386
10391
|
normalizeResourceUrl: () => normalizeResourceUrl,
|
|
10387
10392
|
openRequestMarketplaceHitSchema: () => openRequestMarketplaceHitSchema,
|
|
10393
|
+
osSecretStore: () => osSecretStore,
|
|
10388
10394
|
parse402Challenge: () => parse402Challenge,
|
|
10389
10395
|
parse402Response: () => parse402Response,
|
|
10390
10396
|
parseDiscovery: () => parseDiscovery,
|
|
@@ -10413,6 +10419,7 @@ __export(src_exports, {
|
|
|
10413
10419
|
readMovement: () => readMovement,
|
|
10414
10420
|
readReceipts: () => readReceipts,
|
|
10415
10421
|
readSearchEvents: () => readSearchEvents,
|
|
10422
|
+
readSecretBackend: () => readSecretBackend,
|
|
10416
10423
|
readSolanaGasBalance: () => readSolanaGasBalance,
|
|
10417
10424
|
readSolanaUsdcBalance: () => readSolanaUsdcBalance,
|
|
10418
10425
|
readSpendLedger: () => readSpendLedger,
|
|
@@ -10440,8 +10447,10 @@ __export(src_exports, {
|
|
|
10440
10447
|
scheduleCeilingSweep: () => scheduleCeilingSweep,
|
|
10441
10448
|
searchDocs: () => searchDocs,
|
|
10442
10449
|
searchServicesResponseSchema: () => searchServicesResponseSchema,
|
|
10450
|
+
secretBackendPath: () => secretBackendPath,
|
|
10443
10451
|
secretStore: () => secretStore,
|
|
10444
10452
|
secretsAllowed: () => secretsAllowed,
|
|
10453
|
+
secretsFilePath: () => secretsFilePath,
|
|
10445
10454
|
serviceOfferMarketplaceHitSchema: () => serviceOfferMarketplaceHitSchema,
|
|
10446
10455
|
serviceSummarySchema: () => serviceSummarySchema,
|
|
10447
10456
|
serviceTierSchema: () => serviceTierSchema,
|
|
@@ -45598,9 +45607,9 @@ var X402Error = class extends Error {
|
|
|
45598
45607
|
function isValidPaymentId(value) {
|
|
45599
45608
|
return typeof value === "string" && PAYMENT_ID_PATTERN.test(value);
|
|
45600
45609
|
}
|
|
45601
|
-
function createPaymentId(
|
|
45610
|
+
function createPaymentId(randomBytes18 = fillRandomBytes) {
|
|
45602
45611
|
const bytes = new Uint8Array(16);
|
|
45603
|
-
|
|
45612
|
+
randomBytes18(bytes);
|
|
45604
45613
|
return `pay_${bytesToHex(bytes).slice(2)}`;
|
|
45605
45614
|
}
|
|
45606
45615
|
function buildPaymentExtensions(serverExtensions, options = {}) {
|
|
@@ -47004,8 +47013,8 @@ function conciseError(error61) {
|
|
|
47004
47013
|
}
|
|
47005
47014
|
|
|
47006
47015
|
// ../core/src/account-add.ts
|
|
47007
|
-
import { stat as
|
|
47008
|
-
import { join as
|
|
47016
|
+
import { stat as stat10 } from "node:fs/promises";
|
|
47017
|
+
import { join as join10 } from "node:path";
|
|
47009
47018
|
|
|
47010
47019
|
// ../core/src/agent-link.ts
|
|
47011
47020
|
import { createHash } from "node:crypto";
|
|
@@ -70586,20 +70595,20 @@ async function promptForSecret(prompt, noTerminalHint) {
|
|
|
70586
70595
|
}
|
|
70587
70596
|
|
|
70588
70597
|
// ../core/src/wallet-store.ts
|
|
70589
|
-
import { randomBytes as
|
|
70598
|
+
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
70590
70599
|
import {
|
|
70591
70600
|
chmod as chmod3,
|
|
70592
70601
|
lstat as lstat2,
|
|
70593
70602
|
mkdir as mkdir10,
|
|
70594
|
-
open as
|
|
70603
|
+
open as open8,
|
|
70595
70604
|
readdir as readdir3,
|
|
70596
|
-
readFile as
|
|
70605
|
+
readFile as readFile12,
|
|
70597
70606
|
rename as rename7,
|
|
70598
|
-
stat as
|
|
70607
|
+
stat as stat9,
|
|
70599
70608
|
unlink as unlink6,
|
|
70600
70609
|
writeFile as writeFile5
|
|
70601
70610
|
} from "node:fs/promises";
|
|
70602
|
-
import { dirname as dirname7, join as
|
|
70611
|
+
import { dirname as dirname7, join as join9 } from "node:path";
|
|
70603
70612
|
|
|
70604
70613
|
// ../core/src/account-movement-lock.ts
|
|
70605
70614
|
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
@@ -70717,497 +70726,16 @@ function isOpenMovementLeg(leg, journalEvidence) {
|
|
|
70717
70726
|
// ../core/src/secret-store.ts
|
|
70718
70727
|
import { spawn } from "node:child_process";
|
|
70719
70728
|
import { existsSync } from "node:fs";
|
|
70720
|
-
import { delimiter, isAbsolute, join as
|
|
70721
|
-
var SECRET_STORE_SERVICE = "vapi-network";
|
|
70722
|
-
var SECURITY_BINARY = "/usr/bin/security";
|
|
70723
|
-
var SECRET_TOOL_BINARY = "secret-tool";
|
|
70724
|
-
var WINDOWS_POWERSHELL_ARGS = ["-NoProfile", "-NonInteractive", "-Command", "-"];
|
|
70725
|
-
var SECURITY_ITEM_NOT_FOUND = 44;
|
|
70726
|
-
var WINDOWS_SECRET_SUCCESS = 0;
|
|
70727
|
-
var WINDOWS_SECRET_NOT_FOUND = 2;
|
|
70728
|
-
var UNSUPPORTED_PLATFORM = "No OS secret store on this platform yet; use VAPI_KEYSTORE_PASSWORD.";
|
|
70729
|
-
var SECRET_TOOL_MISSING = [
|
|
70730
|
-
"secret-tool is not installed, so the passphrase cannot be kept in the OS secret store.",
|
|
70731
|
-
"Install libsecret-tools (Debian, Ubuntu) or libsecret (Fedora, Arch), or use VAPI_KEYSTORE_PASSWORD."
|
|
70732
|
-
].join(" ");
|
|
70733
|
-
var POWERSHELL_MISSING = [
|
|
70734
|
-
"Windows PowerShell (powershell.exe) was not found, so the passphrase cannot be kept in the OS secret store.",
|
|
70735
|
-
"Use VAPI_KEYSTORE_PASSWORD."
|
|
70736
|
-
].join(" ");
|
|
70737
|
-
function secretStore(options = {}) {
|
|
70738
|
-
const platform2 = options.platform ?? process.platform;
|
|
70739
|
-
const run = options.run ?? (async (file2, args, input2) => await spawnRunner(platform2, file2, args, input2));
|
|
70740
|
-
const env = options.env ?? process.env;
|
|
70741
|
-
const installed = options.installed ?? ((file2) => binaryInstalled(file2, env));
|
|
70742
|
-
if (platform2 === "darwin") return keychainStore(platform2, run);
|
|
70743
|
-
if (platform2 === "win32") return windowsDataProtectionStore(platform2, run, env, installed);
|
|
70744
|
-
if (platform2 === "linux") return libsecretStore(platform2, run, installed);
|
|
70745
|
-
return unsupportedStore(platform2);
|
|
70746
|
-
}
|
|
70747
|
-
function memorySecretStore(initial = {}) {
|
|
70748
|
-
const entries = new Map(Object.entries(initial));
|
|
70749
|
-
return {
|
|
70750
|
-
available: true,
|
|
70751
|
-
platform: process.platform,
|
|
70752
|
-
description: "an in-memory store",
|
|
70753
|
-
async get(name) {
|
|
70754
|
-
return entries.get(name);
|
|
70755
|
-
},
|
|
70756
|
-
async has(name) {
|
|
70757
|
-
return entries.has(name);
|
|
70758
|
-
},
|
|
70759
|
-
async set(name, passphrase) {
|
|
70760
|
-
entries.set(name, passphrase);
|
|
70761
|
-
},
|
|
70762
|
-
async remove(name) {
|
|
70763
|
-
return entries.delete(name);
|
|
70764
|
-
},
|
|
70765
|
-
async list() {
|
|
70766
|
-
return [...entries.keys()].sort();
|
|
70767
|
-
}
|
|
70768
|
-
};
|
|
70769
|
-
}
|
|
70770
|
-
function keychainStore(platform2, run) {
|
|
70771
|
-
const find = async (account, withPassword) => await run(SECURITY_BINARY, [
|
|
70772
|
-
"find-generic-password",
|
|
70773
|
-
"-a",
|
|
70774
|
-
account,
|
|
70775
|
-
"-s",
|
|
70776
|
-
SECRET_STORE_SERVICE,
|
|
70777
|
-
...withPassword ? ["-w"] : []
|
|
70778
|
-
]);
|
|
70779
|
-
const read = async (account, what) => {
|
|
70780
|
-
const result = await find(account, true);
|
|
70781
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return void 0;
|
|
70782
|
-
requireSuccess(result, what);
|
|
70783
|
-
const value = withoutTrailingNewline(result.stdout);
|
|
70784
|
-
return value.length === 0 ? void 0 : value;
|
|
70785
|
-
};
|
|
70786
|
-
const write2 = async (account, value, what) => {
|
|
70787
|
-
const result = await run(
|
|
70788
|
-
SECURITY_BINARY,
|
|
70789
|
-
[
|
|
70790
|
-
"add-generic-password",
|
|
70791
|
-
"-a",
|
|
70792
|
-
account,
|
|
70793
|
-
"-s",
|
|
70794
|
-
SECRET_STORE_SERVICE,
|
|
70795
|
-
"-l",
|
|
70796
|
-
`${SECRET_STORE_SERVICE} ${account}`,
|
|
70797
|
-
"-U",
|
|
70798
|
-
"-w"
|
|
70799
|
-
],
|
|
70800
|
-
// `security` asks for the password and then for its confirmation.
|
|
70801
|
-
`${value}
|
|
70802
|
-
${value}
|
|
70803
|
-
`
|
|
70804
|
-
);
|
|
70805
|
-
requireSuccess(result, what);
|
|
70806
|
-
};
|
|
70807
|
-
const erase = async (account, what) => {
|
|
70808
|
-
const result = await run(SECURITY_BINARY, [
|
|
70809
|
-
"delete-generic-password",
|
|
70810
|
-
"-a",
|
|
70811
|
-
account,
|
|
70812
|
-
"-s",
|
|
70813
|
-
SECRET_STORE_SERVICE
|
|
70814
|
-
]);
|
|
70815
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70816
|
-
requireSuccess(result, what);
|
|
70817
|
-
return true;
|
|
70818
|
-
};
|
|
70819
|
-
const erasePartsAfter = async (account, keep, what) => {
|
|
70820
|
-
for (let part = keep + 1; part <= MAX_KEYCHAIN_PARTS; part += 1) {
|
|
70821
|
-
if (!await erase(keychainPart(account, part), what)) return;
|
|
70822
|
-
}
|
|
70823
|
-
};
|
|
70824
|
-
return {
|
|
70825
|
-
available: true,
|
|
70826
|
-
platform: platform2,
|
|
70827
|
-
description: "the macOS Keychain",
|
|
70828
|
-
async get(name) {
|
|
70829
|
-
const account = accountFor(name);
|
|
70830
|
-
const what = `read the passphrase of ${name} from the macOS Keychain`;
|
|
70831
|
-
const value = await read(account, what);
|
|
70832
|
-
const parts = value === void 0 ? void 0 : chunkedPartCount(value);
|
|
70833
|
-
if (value === void 0 || parts === void 0) return value;
|
|
70834
|
-
let joined = "";
|
|
70835
|
-
for (let part = 1; part <= parts; part += 1) {
|
|
70836
|
-
const chunk = await read(keychainPart(account, part), what);
|
|
70837
|
-
if (chunk === void 0) {
|
|
70838
|
-
throw new KeystoreError(
|
|
70839
|
-
`The stored secret ${name} is incomplete in the macOS Keychain. Store it again.`
|
|
70840
|
-
);
|
|
70841
|
-
}
|
|
70842
|
-
joined += chunk;
|
|
70843
|
-
}
|
|
70844
|
-
return joined;
|
|
70845
|
-
},
|
|
70846
|
-
async has(name) {
|
|
70847
|
-
const result = await find(accountFor(name), false);
|
|
70848
|
-
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70849
|
-
requireSuccess(result, `look up ${name} in the macOS Keychain`);
|
|
70850
|
-
return true;
|
|
70851
|
-
},
|
|
70852
|
-
async set(name, passphrase) {
|
|
70853
|
-
requirePassphrase(passphrase);
|
|
70854
|
-
const account = accountFor(name);
|
|
70855
|
-
const what = `store the passphrase of ${name} in the macOS Keychain`;
|
|
70856
|
-
if (passphrase.length <= KEYCHAIN_PROMPT_LIMIT) {
|
|
70857
|
-
await write2(account, passphrase, what);
|
|
70858
|
-
return;
|
|
70859
|
-
}
|
|
70860
|
-
const chunks = [];
|
|
70861
|
-
for (let index2 = 0; index2 < passphrase.length; index2 += KEYCHAIN_CHUNK) {
|
|
70862
|
-
chunks.push(passphrase.slice(index2, index2 + KEYCHAIN_CHUNK));
|
|
70863
|
-
}
|
|
70864
|
-
if (chunks.length > MAX_KEYCHAIN_PARTS) {
|
|
70865
|
-
throw new KeystoreError(`The secret ${name} is too long for the macOS Keychain.`);
|
|
70866
|
-
}
|
|
70867
|
-
for (const [index2, chunk] of chunks.entries()) {
|
|
70868
|
-
await write2(keychainPart(account, index2 + 1), chunk, what);
|
|
70869
|
-
}
|
|
70870
|
-
await erasePartsAfter(account, chunks.length, what);
|
|
70871
|
-
await write2(account, `${CHUNKED_MARKER}${chunks.length}`, what);
|
|
70872
|
-
},
|
|
70873
|
-
async remove(name) {
|
|
70874
|
-
const account = accountFor(name);
|
|
70875
|
-
const what = `remove the passphrase of ${name} from the macOS Keychain`;
|
|
70876
|
-
const found = await find(account, true);
|
|
70877
|
-
if (found.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
70878
|
-
requireSuccess(found, what);
|
|
70879
|
-
if (chunkedPartCount(withoutTrailingNewline(found.stdout)) !== void 0) {
|
|
70880
|
-
await erasePartsAfter(account, 0, what);
|
|
70881
|
-
}
|
|
70882
|
-
return await erase(account, what);
|
|
70883
|
-
}
|
|
70884
|
-
};
|
|
70885
|
-
}
|
|
70886
|
-
var KEYCHAIN_PROMPT_LIMIT = 128;
|
|
70887
|
-
var KEYCHAIN_CHUNK = 120;
|
|
70888
|
-
var MAX_KEYCHAIN_PARTS = 32;
|
|
70889
|
-
var CHUNKED_MARKER = "vapi-chunked:v1:";
|
|
70890
|
-
function keychainPart(account, part) {
|
|
70891
|
-
return `${account}#${part}`;
|
|
70892
|
-
}
|
|
70893
|
-
function chunkedPartCount(value) {
|
|
70894
|
-
if (!value.startsWith(CHUNKED_MARKER)) return void 0;
|
|
70895
|
-
const parts = Number(value.slice(CHUNKED_MARKER.length));
|
|
70896
|
-
return Number.isInteger(parts) && parts > 0 && parts <= MAX_KEYCHAIN_PARTS ? parts : void 0;
|
|
70897
|
-
}
|
|
70898
|
-
function windowsSecretFileName(account) {
|
|
70899
|
-
let encoded = "";
|
|
70900
|
-
for (let index2 = 0; index2 < account.length; index2 += 1) {
|
|
70901
|
-
const character = account[index2];
|
|
70902
|
-
if (/^[a-z0-9._#-]$/u.test(character)) {
|
|
70903
|
-
encoded += character;
|
|
70904
|
-
continue;
|
|
70905
|
-
}
|
|
70906
|
-
encoded += `%${account.charCodeAt(index2).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
70907
|
-
}
|
|
70908
|
-
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu.test(encoded)) {
|
|
70909
|
-
encoded = `%${encoded.charCodeAt(0).toString(16).toUpperCase()}${encoded.slice(1)}`;
|
|
70910
|
-
}
|
|
70911
|
-
return `${encoded}.bin`;
|
|
70912
|
-
}
|
|
70913
|
-
function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
70914
|
-
const powershell = `${env.SystemRoot ?? "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
70915
|
-
const fileDetails = (name) => {
|
|
70916
|
-
const file2 = windowsSecretFileName(accountFor(name));
|
|
70917
|
-
return { file: file2, account: file2.slice(0, -".bin".length) };
|
|
70918
|
-
};
|
|
70919
|
-
const script = (file2, operations) => [
|
|
70920
|
-
"$ErrorActionPreference = 'Stop'",
|
|
70921
|
-
"try {",
|
|
70922
|
-
" Add-Type -AssemblyName System.Security",
|
|
70923
|
-
" $dir = Join-Path $env:LOCALAPPDATA 'vapi-network\\secrets'",
|
|
70924
|
-
` $path = Join-Path $dir '${file2}'`,
|
|
70925
|
-
...operations.map((operation) => ` ${operation}`),
|
|
70926
|
-
"} catch {",
|
|
70927
|
-
" [Console]::Error.WriteLine($_.Exception.Message)",
|
|
70928
|
-
" exit 1",
|
|
70929
|
-
"}"
|
|
70930
|
-
].join("\n");
|
|
70931
|
-
const execute = async (script2) => {
|
|
70932
|
-
const result = await run(powershell, WINDOWS_POWERSHELL_ARGS, `${script2}
|
|
70933
|
-
|
|
70934
|
-
`);
|
|
70935
|
-
requirePowerShell(result);
|
|
70936
|
-
return result;
|
|
70937
|
-
};
|
|
70938
|
-
return {
|
|
70939
|
-
available: installed(powershell),
|
|
70940
|
-
platform: platform2,
|
|
70941
|
-
description: "Windows Data Protection (DPAPI)",
|
|
70942
|
-
async get(name) {
|
|
70943
|
-
const { file: file2, account } = fileDetails(name);
|
|
70944
|
-
const result = await execute(
|
|
70945
|
-
script(file2, [
|
|
70946
|
-
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
70947
|
-
"$blob = [System.IO.File]::ReadAllBytes($path)",
|
|
70948
|
-
"$bytes = [System.Security.Cryptography.ProtectedData]::Unprotect($blob, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
70949
|
-
"[Console]::Out.Write([Convert]::ToBase64String($bytes))",
|
|
70950
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70951
|
-
])
|
|
70952
|
-
);
|
|
70953
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return void 0;
|
|
70954
|
-
requireSuccess(result, `read the passphrase of ${name} from Windows Data Protection`);
|
|
70955
|
-
const value = Buffer.from(result.stdout.trim(), "base64").toString("utf8");
|
|
70956
|
-
return value.length === 0 ? void 0 : value;
|
|
70957
|
-
},
|
|
70958
|
-
async has(name) {
|
|
70959
|
-
const { file: file2, account } = fileDetails(name);
|
|
70960
|
-
const result = await execute(
|
|
70961
|
-
script(file2, [
|
|
70962
|
-
`if (Test-Path -LiteralPath $path) { exit ${WINDOWS_SECRET_SUCCESS} }`,
|
|
70963
|
-
`[Console]::Error.WriteLine('No stored secret for ${account}.')`,
|
|
70964
|
-
`exit ${WINDOWS_SECRET_NOT_FOUND}`
|
|
70965
|
-
])
|
|
70966
|
-
);
|
|
70967
|
-
if (result.code === WINDOWS_SECRET_SUCCESS) return true;
|
|
70968
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
70969
|
-
requireSuccess(result, `look up ${name} in Windows Data Protection`);
|
|
70970
|
-
return false;
|
|
70971
|
-
},
|
|
70972
|
-
async set(name, passphrase) {
|
|
70973
|
-
requirePassphrase(passphrase);
|
|
70974
|
-
const { file: file2 } = fileDetails(name);
|
|
70975
|
-
const value = Buffer.from(passphrase, "utf8").toString("base64");
|
|
70976
|
-
const result = await execute(
|
|
70977
|
-
script(file2, [
|
|
70978
|
-
"[void][System.IO.Directory]::CreateDirectory($dir)",
|
|
70979
|
-
`$bytes = [Convert]::FromBase64String('${value}')`,
|
|
70980
|
-
"$blob = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
70981
|
-
"[System.IO.File]::WriteAllBytes($path, $blob)",
|
|
70982
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70983
|
-
])
|
|
70984
|
-
);
|
|
70985
|
-
requireSuccess(result, `store the passphrase of ${name} in Windows Data Protection`);
|
|
70986
|
-
},
|
|
70987
|
-
async remove(name) {
|
|
70988
|
-
const { file: file2, account } = fileDetails(name);
|
|
70989
|
-
const result = await execute(
|
|
70990
|
-
script(file2, [
|
|
70991
|
-
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
70992
|
-
"Remove-Item -LiteralPath $path -Force",
|
|
70993
|
-
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
70994
|
-
])
|
|
70995
|
-
);
|
|
70996
|
-
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
70997
|
-
requireSuccess(result, `remove the passphrase of ${name} from Windows Data Protection`);
|
|
70998
|
-
return true;
|
|
70999
|
-
}
|
|
71000
|
-
};
|
|
71001
|
-
}
|
|
71002
|
-
function libsecretStore(platform2, run, installed) {
|
|
71003
|
-
const lookup2 = async (name) => {
|
|
71004
|
-
const result = await run(SECRET_TOOL_BINARY, [
|
|
71005
|
-
"lookup",
|
|
71006
|
-
"service",
|
|
71007
|
-
SECRET_STORE_SERVICE,
|
|
71008
|
-
"account",
|
|
71009
|
-
accountFor(name)
|
|
71010
|
-
]);
|
|
71011
|
-
requireBinary(result);
|
|
71012
|
-
const value = withoutTrailingNewline(result.stdout);
|
|
71013
|
-
if (result.code === 0) return value.length === 0 ? void 0 : value;
|
|
71014
|
-
if (result.stderr.trim().length === 0) return void 0;
|
|
71015
|
-
requireSuccess(result, `read the passphrase of ${name} from the secret service`);
|
|
71016
|
-
return void 0;
|
|
71017
|
-
};
|
|
71018
|
-
return {
|
|
71019
|
-
available: installed(SECRET_TOOL_BINARY),
|
|
71020
|
-
platform: platform2,
|
|
71021
|
-
description: "the libsecret keyring",
|
|
71022
|
-
get: lookup2,
|
|
71023
|
-
async has(name) {
|
|
71024
|
-
return await lookup2(name) !== void 0;
|
|
71025
|
-
},
|
|
71026
|
-
async set(name, passphrase) {
|
|
71027
|
-
requirePassphrase(passphrase);
|
|
71028
|
-
const account = accountFor(name);
|
|
71029
|
-
const result = await run(
|
|
71030
|
-
SECRET_TOOL_BINARY,
|
|
71031
|
-
[
|
|
71032
|
-
"store",
|
|
71033
|
-
`--label=${SECRET_STORE_SERVICE} ${account}`,
|
|
71034
|
-
"service",
|
|
71035
|
-
SECRET_STORE_SERVICE,
|
|
71036
|
-
"account",
|
|
71037
|
-
account
|
|
71038
|
-
],
|
|
71039
|
-
`${passphrase}
|
|
71040
|
-
`
|
|
71041
|
-
);
|
|
71042
|
-
requireBinary(result);
|
|
71043
|
-
requireSuccess(result, `store the passphrase of ${name} in the secret service`);
|
|
71044
|
-
},
|
|
71045
|
-
async remove(name) {
|
|
71046
|
-
const existed = await lookup2(name) !== void 0;
|
|
71047
|
-
const result = await run(SECRET_TOOL_BINARY, [
|
|
71048
|
-
"clear",
|
|
71049
|
-
"service",
|
|
71050
|
-
SECRET_STORE_SERVICE,
|
|
71051
|
-
"account",
|
|
71052
|
-
accountFor(name)
|
|
71053
|
-
]);
|
|
71054
|
-
requireBinary(result);
|
|
71055
|
-
requireSuccess(result, `remove the passphrase of ${name} from the secret service`);
|
|
71056
|
-
return existed;
|
|
71057
|
-
}
|
|
71058
|
-
};
|
|
71059
|
-
}
|
|
71060
|
-
function unsupportedStore(platform2) {
|
|
71061
|
-
const refuse = () => {
|
|
71062
|
-
throw new KeystoreError(UNSUPPORTED_PLATFORM);
|
|
71063
|
-
};
|
|
71064
|
-
return {
|
|
71065
|
-
available: false,
|
|
71066
|
-
platform: platform2,
|
|
71067
|
-
description: "no OS secret store",
|
|
71068
|
-
get: async () => refuse(),
|
|
71069
|
-
has: async () => refuse(),
|
|
71070
|
-
set: async () => refuse(),
|
|
71071
|
-
remove: async () => refuse()
|
|
71072
|
-
};
|
|
71073
|
-
}
|
|
71074
|
-
function accountFor(name) {
|
|
71075
|
-
const account = name.trim();
|
|
71076
|
-
if (account.length === 0) {
|
|
71077
|
-
throw new KeystoreError("A wallet name is needed to reach the OS secret store.");
|
|
71078
|
-
}
|
|
71079
|
-
return account;
|
|
71080
|
-
}
|
|
71081
|
-
function requirePassphrase(passphrase) {
|
|
71082
|
-
if (passphrase.length === 0) {
|
|
71083
|
-
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
71084
|
-
}
|
|
71085
|
-
}
|
|
71086
|
-
function requireBinary(result) {
|
|
71087
|
-
if (result.notFound === true) throw new KeystoreError(SECRET_TOOL_MISSING);
|
|
71088
|
-
}
|
|
71089
|
-
function requirePowerShell(result) {
|
|
71090
|
-
if (result.notFound === true) throw new KeystoreError(POWERSHELL_MISSING);
|
|
71091
|
-
}
|
|
71092
|
-
function binaryInstalled(file2, env) {
|
|
71093
|
-
if (isAbsolute(file2) || win32.isAbsolute(file2)) return existsSync(file2);
|
|
71094
|
-
return (env.PATH ?? "").split(delimiter).some((directory) => existsSync(join6(directory, file2)));
|
|
71095
|
-
}
|
|
71096
|
-
function requireSuccess(result, what) {
|
|
71097
|
-
if (result.code === 0) return;
|
|
71098
|
-
const detail = result.stderr.trim() || result.stdout.trim();
|
|
71099
|
-
throw new KeystoreError(
|
|
71100
|
-
`Could not ${what}${result.code === null ? "" : ` (exit ${result.code})`}.${detail.length === 0 ? "" : ` ${detail}`}`
|
|
71101
|
-
);
|
|
71102
|
-
}
|
|
71103
|
-
function withoutTrailingNewline(value) {
|
|
71104
|
-
return value.replace(/\r?\n$/u, "");
|
|
71105
|
-
}
|
|
71106
|
-
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve4) => {
|
|
71107
|
-
let stdout = "";
|
|
71108
|
-
let stderr2 = "";
|
|
71109
|
-
let settled = false;
|
|
71110
|
-
const finish = (outcome) => {
|
|
71111
|
-
if (settled) return;
|
|
71112
|
-
settled = true;
|
|
71113
|
-
resolve4(outcome);
|
|
71114
|
-
};
|
|
71115
|
-
const child = spawn(file2, [...args], {
|
|
71116
|
-
detached: platform2 !== "win32",
|
|
71117
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
71118
|
-
windowsHide: true
|
|
71119
|
-
});
|
|
71120
|
-
child.stdout?.setEncoding("utf8");
|
|
71121
|
-
child.stdout?.on("data", (chunk) => {
|
|
71122
|
-
stdout += chunk;
|
|
71123
|
-
});
|
|
71124
|
-
child.stderr?.setEncoding("utf8");
|
|
71125
|
-
child.stderr?.on("data", (chunk) => {
|
|
71126
|
-
stderr2 += chunk;
|
|
71127
|
-
});
|
|
71128
|
-
child.on("error", (error61) => {
|
|
71129
|
-
finish({
|
|
71130
|
-
code: null,
|
|
71131
|
-
stdout,
|
|
71132
|
-
stderr: stderr2,
|
|
71133
|
-
...error61.code === "ENOENT" ? { notFound: true } : {}
|
|
71134
|
-
});
|
|
71135
|
-
});
|
|
71136
|
-
child.on("close", (code) => finish({ code, stdout, stderr: stderr2 }));
|
|
71137
|
-
child.stdin?.on("error", () => void 0);
|
|
71138
|
-
child.stdin?.end(input2 ?? "");
|
|
71139
|
-
});
|
|
71140
|
-
|
|
71141
|
-
// ../core/src/passphrase.ts
|
|
71142
|
-
var PASSPHRASE_ENVIRONMENT_VARIABLE = "VAPI_KEYSTORE_PASSWORD";
|
|
71143
|
-
function noPassphraseHint(walletName) {
|
|
71144
|
-
return `Set ${PASSPHRASE_ENVIRONMENT_VARIABLE}, or store this wallet's passphrase once with vapi unlock --wallet ${walletName}.`;
|
|
71145
|
-
}
|
|
71146
|
-
function staleStoredPassphraseMessage(walletName, store) {
|
|
71147
|
-
return [
|
|
71148
|
-
`The passphrase stored in ${store.description} no longer opens wallet ${walletName}.`,
|
|
71149
|
-
`Store the current one with vapi unlock --wallet ${walletName}, or remove it with vapi lock --wallet ${walletName}.`
|
|
71150
|
-
].join(" ");
|
|
71151
|
-
}
|
|
71152
|
-
async function resolvePassphrase(walletName, options = {}) {
|
|
71153
|
-
const env = options.env ?? process.env;
|
|
71154
|
-
const fromEnvironment = env[PASSPHRASE_ENVIRONMENT_VARIABLE];
|
|
71155
|
-
if (fromEnvironment !== void 0) {
|
|
71156
|
-
if (fromEnvironment.length === 0) {
|
|
71157
|
-
throw new KeystoreError(`${PASSPHRASE_ENVIRONMENT_VARIABLE} cannot be empty.`);
|
|
71158
|
-
}
|
|
71159
|
-
return { passphrase: fromEnvironment, source: "environment" };
|
|
71160
|
-
}
|
|
71161
|
-
if (options.confirm !== true) {
|
|
71162
|
-
const stored = await readStored(options.store ?? secretStore(), walletName);
|
|
71163
|
-
if (stored !== void 0) return { passphrase: stored, source: "secret-store" };
|
|
71164
|
-
}
|
|
71165
|
-
const hint = noPassphraseHint(walletName);
|
|
71166
|
-
if (options.interactive === false) {
|
|
71167
|
-
throw new KeystoreError(
|
|
71168
|
-
`No interactive terminal is available for the keystore prompt. ${hint}`
|
|
71169
|
-
);
|
|
71170
|
-
}
|
|
71171
|
-
const prompt = options.prompt ?? promptForSecret;
|
|
71172
|
-
const first = await prompt(`Passphrase for ${walletName}: `, hint);
|
|
71173
|
-
if (first.length === 0) {
|
|
71174
|
-
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
71175
|
-
}
|
|
71176
|
-
if (options.confirm === true) {
|
|
71177
|
-
const second = await prompt("Confirm passphrase: ", hint);
|
|
71178
|
-
if (first !== second) throw new KeystoreError("Passphrases do not match.");
|
|
71179
|
-
}
|
|
71180
|
-
return { passphrase: first, source: "prompt" };
|
|
71181
|
-
}
|
|
71182
|
-
async function readStored(store, walletName) {
|
|
71183
|
-
if (!store.available) return void 0;
|
|
71184
|
-
try {
|
|
71185
|
-
return await store.get(walletName);
|
|
71186
|
-
} catch {
|
|
71187
|
-
return void 0;
|
|
71188
|
-
}
|
|
71189
|
-
}
|
|
70729
|
+
import { delimiter, isAbsolute, join as join7, win32 } from "node:path";
|
|
71190
70730
|
|
|
71191
|
-
// ../core/src/
|
|
70731
|
+
// ../core/src/file-secret-store.ts
|
|
71192
70732
|
import { randomBytes as randomBytes6 } from "node:crypto";
|
|
71193
|
-
import {
|
|
71194
|
-
import { dirname as dirname5 } from "node:path";
|
|
70733
|
+
import { readFile as readFile8, stat as stat7 } from "node:fs/promises";
|
|
71195
70734
|
|
|
71196
|
-
// ../core/src/
|
|
70735
|
+
// ../core/src/vault.ts
|
|
71197
70736
|
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
71198
|
-
|
|
71199
|
-
|
|
71200
|
-
return typeof value === "string" && RUN_ID_PATTERN.test(value);
|
|
71201
|
-
}
|
|
71202
|
-
function createRunId(random = randomBytes5) {
|
|
71203
|
-
return `run_${Buffer.from(random(12)).toString("hex")}`;
|
|
71204
|
-
}
|
|
71205
|
-
var runRefSchema = external_exports.strictObject({
|
|
71206
|
-
id: external_exports.string().regex(RUN_ID_PATTERN),
|
|
71207
|
-
swarm: external_exports.string().optional(),
|
|
71208
|
-
member: external_exports.string().optional(),
|
|
71209
|
-
parentRunId: external_exports.string().optional()
|
|
71210
|
-
});
|
|
70737
|
+
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";
|
|
70738
|
+
import { dirname as dirname5 } from "node:path";
|
|
71211
70739
|
|
|
71212
70740
|
// ../core/src/wallet-name.ts
|
|
71213
70741
|
var DEFAULT_WALLET_NAME = "main";
|
|
@@ -71220,263 +70748,7 @@ function isWalletName(value) {
|
|
|
71220
70748
|
return WALLET_NAME_PATTERN.test(value);
|
|
71221
70749
|
}
|
|
71222
70750
|
|
|
71223
|
-
// ../core/src/receipts.ts
|
|
71224
|
-
var receiptTestHooks;
|
|
71225
|
-
function __setReceiptTestHooks(hooks) {
|
|
71226
|
-
receiptTestHooks = hooks;
|
|
71227
|
-
}
|
|
71228
|
-
var RECEIPT_JOURNAL_BUSY_MESSAGE = "The receipt journal is busy. Wait for the other vapi command to finish, then retry.";
|
|
71229
|
-
async function withReceiptJournalLock(path, operation) {
|
|
71230
|
-
return await withFileLock(`${path}.lock`, operation, {
|
|
71231
|
-
lockedMessage: RECEIPT_JOURNAL_BUSY_MESSAGE
|
|
71232
|
-
});
|
|
71233
|
-
}
|
|
71234
|
-
var durationSchema = external_exports.number().nonnegative().finite();
|
|
71235
|
-
var receiptSchema = external_exports.strictObject({
|
|
71236
|
-
id: external_exports.string().min(1),
|
|
71237
|
-
timestamp: external_exports.iso.datetime(),
|
|
71238
|
-
run: runRefSchema.optional(),
|
|
71239
|
-
kind: external_exports.literal("transfer").optional(),
|
|
71240
|
-
wallet: walletNameSchema.optional(),
|
|
71241
|
-
resourceUrl: external_exports.url(),
|
|
71242
|
-
method: external_exports.string().min(1).optional(),
|
|
71243
|
-
source: external_exports.string().min(1).optional(),
|
|
71244
|
-
provenance: external_exports.array(
|
|
71245
|
-
external_exports.strictObject({
|
|
71246
|
-
source: external_exports.string().min(1),
|
|
71247
|
-
sourceUrl: external_exports.string().optional(),
|
|
71248
|
-
ref: external_exports.string().optional()
|
|
71249
|
-
})
|
|
71250
|
-
).optional(),
|
|
71251
|
-
quote: external_exports.strictObject({
|
|
71252
|
-
network: external_exports.string(),
|
|
71253
|
-
asset: external_exports.string().optional(),
|
|
71254
|
-
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
71255
|
-
payTo: external_exports.string().optional()
|
|
71256
|
-
}).optional(),
|
|
71257
|
-
payer: external_exports.string().optional(),
|
|
71258
|
-
paymentId: external_exports.string().regex(/^[A-Za-z0-9_-]{16,128}$/).optional(),
|
|
71259
|
-
authorization: external_exports.strictObject({
|
|
71260
|
-
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71261
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
71262
|
-
validBefore: external_exports.string().regex(/^\d+$/)
|
|
71263
|
-
}).optional(),
|
|
71264
|
-
transfer: external_exports.strictObject({
|
|
71265
|
-
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71266
|
-
toName: external_exports.string().min(1),
|
|
71267
|
-
toKind: external_exports.enum(["owner", "account"]),
|
|
71268
|
-
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
71269
|
-
network: external_exports.string().min(1),
|
|
71270
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
71271
|
-
status: external_exports.enum(["sent", "unknown", "failed"]),
|
|
71272
|
-
txHash: external_exports.string().regex(/^0x[0-9a-fA-F]+$/).nullable(),
|
|
71273
|
-
replayed: external_exports.boolean(),
|
|
71274
|
-
reservedOn: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
71275
|
-
request: external_exports.strictObject({
|
|
71276
|
-
authorization: external_exports.strictObject({
|
|
71277
|
-
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71278
|
-
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
71279
|
-
value: external_exports.string().regex(/^\d+$/),
|
|
71280
|
-
validAfter: external_exports.string().regex(/^\d+$/),
|
|
71281
|
-
validBefore: external_exports.string().regex(/^\d+$/),
|
|
71282
|
-
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/)
|
|
71283
|
-
}),
|
|
71284
|
-
signature: external_exports.string().regex(/^0x[0-9a-fA-F]+$/)
|
|
71285
|
-
}).optional()
|
|
71286
|
-
}).optional(),
|
|
71287
|
-
settlement: external_exports.strictObject({
|
|
71288
|
-
outcome: external_exports.enum(["succeeded", "rejected", "unknown"]),
|
|
71289
|
-
transaction: external_exports.string().optional(),
|
|
71290
|
-
explorerUrl: external_exports.url().optional(),
|
|
71291
|
-
evidence: external_exports.unknown().optional()
|
|
71292
|
-
}).optional(),
|
|
71293
|
-
latencyMs: external_exports.number().nonnegative().finite().optional(),
|
|
71294
|
-
status: external_exports.number().int().min(100).max(599).optional(),
|
|
71295
|
-
error: external_exports.strictObject({ code: external_exports.string(), message: external_exports.string() }).optional(),
|
|
71296
|
-
phases: external_exports.strictObject({
|
|
71297
|
-
discoverMs: durationSchema.optional(),
|
|
71298
|
-
quoteMs: durationSchema.optional(),
|
|
71299
|
-
signMs: durationSchema.optional(),
|
|
71300
|
-
requestMs: durationSchema.optional(),
|
|
71301
|
-
settleMs: durationSchema.optional()
|
|
71302
|
-
}).optional(),
|
|
71303
|
-
listing: external_exports.strictObject({
|
|
71304
|
-
name: external_exports.string().min(1).optional(),
|
|
71305
|
-
providerHost: external_exports.string().min(1).optional(),
|
|
71306
|
-
source: external_exports.string().min(1)
|
|
71307
|
-
}).optional(),
|
|
71308
|
-
retry: external_exports.number().int().nonnegative().optional(),
|
|
71309
|
-
policy: external_exports.strictObject({
|
|
71310
|
-
maxPriceUsd: external_exports.string().regex(/^\d+(?:\.\d{1,6})?$/).optional(),
|
|
71311
|
-
capsApplied: external_exports.boolean()
|
|
71312
|
-
}).optional(),
|
|
71313
|
-
client: external_exports.strictObject({ name: external_exports.literal("vapi-network"), version: external_exports.string().min(1) }).optional(),
|
|
71314
|
-
outcome: external_exports.enum([
|
|
71315
|
-
"paid",
|
|
71316
|
-
"signed_in",
|
|
71317
|
-
"declined_policy",
|
|
71318
|
-
"failed_request",
|
|
71319
|
-
"settlement_rejected",
|
|
71320
|
-
"settlement_unknown"
|
|
71321
|
-
]).optional()
|
|
71322
|
-
});
|
|
71323
|
-
function parseReceipt(value) {
|
|
71324
|
-
const receipt = receiptSchema.parse(value);
|
|
71325
|
-
const transaction2 = receipt.settlement?.transaction;
|
|
71326
|
-
const network = receipt.quote?.network;
|
|
71327
|
-
const explorerUrl = transaction2 === void 0 || network === void 0 ? void 0 : explorerTransactionUrl(network, transaction2);
|
|
71328
|
-
if (explorerUrl === void 0 || receipt.settlement?.explorerUrl === explorerUrl) {
|
|
71329
|
-
return receipt;
|
|
71330
|
-
}
|
|
71331
|
-
return {
|
|
71332
|
-
...receipt,
|
|
71333
|
-
settlement: {
|
|
71334
|
-
outcome: receipt.settlement.outcome,
|
|
71335
|
-
...receipt.settlement.transaction ? { transaction: receipt.settlement.transaction } : {},
|
|
71336
|
-
explorerUrl,
|
|
71337
|
-
...receipt.settlement.evidence === void 0 ? {} : { evidence: receipt.settlement.evidence }
|
|
71338
|
-
}
|
|
71339
|
-
};
|
|
71340
|
-
}
|
|
71341
|
-
async function appendReceipt(receipt, path = getVapiPaths().receipts, options = {}) {
|
|
71342
|
-
const parsed = parseReceipt(
|
|
71343
|
-
receipt.wallet === void 0 && options.wallet !== void 0 ? { ...receipt, wallet: options.wallet } : receipt
|
|
71344
|
-
);
|
|
71345
|
-
await withReceiptJournalLock(path, async () => {
|
|
71346
|
-
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
71347
|
-
const handle = await open5(path, "a", 384);
|
|
71348
|
-
try {
|
|
71349
|
-
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
71350
|
-
`, "utf8");
|
|
71351
|
-
} finally {
|
|
71352
|
-
await handle.close();
|
|
71353
|
-
}
|
|
71354
|
-
});
|
|
71355
|
-
return parsed;
|
|
71356
|
-
}
|
|
71357
|
-
async function readReceipts(path = getVapiPaths().receipts, options = {}) {
|
|
71358
|
-
let raw;
|
|
71359
|
-
try {
|
|
71360
|
-
raw = await readFile7(path, "utf8");
|
|
71361
|
-
} catch (error61) {
|
|
71362
|
-
if (isMissingFile(error61)) return [];
|
|
71363
|
-
throw error61;
|
|
71364
|
-
}
|
|
71365
|
-
const records = coalesceTransferReceiptRevisions(
|
|
71366
|
-
raw.split("\n").filter((line) => line.trim().length > 0).map((line, index2) => {
|
|
71367
|
-
try {
|
|
71368
|
-
return parseReceipt(JSON.parse(line));
|
|
71369
|
-
} catch (error61) {
|
|
71370
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71371
|
-
}
|
|
71372
|
-
})
|
|
71373
|
-
);
|
|
71374
|
-
const filtered = options.wallet === void 0 ? records : filterReceiptsByWallet(records, options.wallet);
|
|
71375
|
-
const limit = options.limit;
|
|
71376
|
-
if (limit === void 0) return filtered;
|
|
71377
|
-
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
71378
|
-
throw new Error("Receipt limit must be a non-negative integer.");
|
|
71379
|
-
return limit === 0 ? [] : filtered.slice(-limit);
|
|
71380
|
-
}
|
|
71381
|
-
function coalesceTransferReceiptRevisions(receipts) {
|
|
71382
|
-
const coalesced = [];
|
|
71383
|
-
const transferIndexes = /* @__PURE__ */ new Map();
|
|
71384
|
-
for (const receipt of receipts) {
|
|
71385
|
-
const existing = receipt.kind === "transfer" ? transferIndexes.get(receipt.id) : void 0;
|
|
71386
|
-
if (existing === void 0) {
|
|
71387
|
-
if (receipt.kind === "transfer") transferIndexes.set(receipt.id, coalesced.length);
|
|
71388
|
-
coalesced.push(receipt);
|
|
71389
|
-
} else {
|
|
71390
|
-
coalesced[existing] = receipt;
|
|
71391
|
-
}
|
|
71392
|
-
}
|
|
71393
|
-
return coalesced;
|
|
71394
|
-
}
|
|
71395
|
-
function receiptWallet(receipt) {
|
|
71396
|
-
return receipt.wallet ?? DEFAULT_WALLET_NAME;
|
|
71397
|
-
}
|
|
71398
|
-
function filterReceiptsByWallet(receipts, name) {
|
|
71399
|
-
return receipts.filter((receipt) => receiptWallet(receipt) === name);
|
|
71400
|
-
}
|
|
71401
|
-
async function renameReceiptWallet(from16, to, path = getVapiPaths().receipts) {
|
|
71402
|
-
return await withReceiptJournalLock(path, async () => {
|
|
71403
|
-
let raw;
|
|
71404
|
-
try {
|
|
71405
|
-
raw = await readFile7(path, "utf8");
|
|
71406
|
-
} catch (error61) {
|
|
71407
|
-
if (isMissingFile(error61)) return 0;
|
|
71408
|
-
throw error61;
|
|
71409
|
-
}
|
|
71410
|
-
let changed = 0;
|
|
71411
|
-
const lines = raw.split("\n").map((line, index2) => {
|
|
71412
|
-
if (line.trim().length === 0) return line;
|
|
71413
|
-
let parsed;
|
|
71414
|
-
try {
|
|
71415
|
-
parsed = JSON.parse(line);
|
|
71416
|
-
} catch (error61) {
|
|
71417
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71418
|
-
}
|
|
71419
|
-
const current = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "wallet") : void 0;
|
|
71420
|
-
if ((typeof current === "string" ? current : DEFAULT_WALLET_NAME) !== from16) return line;
|
|
71421
|
-
changed += 1;
|
|
71422
|
-
return JSON.stringify(parseReceipt({ ...parsed, wallet: to }));
|
|
71423
|
-
});
|
|
71424
|
-
if (changed === 0) return 0;
|
|
71425
|
-
await receiptTestHooks?.beforeRenameReplace?.(path);
|
|
71426
|
-
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
71427
|
-
const temporaryPath = `${path}.${process.pid}.${randomBytes6(6).toString("hex")}.tmp`;
|
|
71428
|
-
await writeFile3(temporaryPath, lines.join("\n"), {
|
|
71429
|
-
encoding: "utf8",
|
|
71430
|
-
mode: 384,
|
|
71431
|
-
flag: "wx"
|
|
71432
|
-
});
|
|
71433
|
-
await rename4(temporaryPath, path);
|
|
71434
|
-
return changed;
|
|
71435
|
-
});
|
|
71436
|
-
}
|
|
71437
|
-
|
|
71438
|
-
// ../core/src/transfer-journal.ts
|
|
71439
|
-
import { readFile as readFile8 } from "node:fs/promises";
|
|
71440
|
-
async function readTransferJournal(home, from16, nonce) {
|
|
71441
|
-
let raw;
|
|
71442
|
-
try {
|
|
71443
|
-
raw = await readFile8(getVapiPaths(home).receipts, "utf8");
|
|
71444
|
-
} catch (error61) {
|
|
71445
|
-
if (isMissingFile(error61)) return { signed: false };
|
|
71446
|
-
throw error61;
|
|
71447
|
-
}
|
|
71448
|
-
let latest;
|
|
71449
|
-
let request;
|
|
71450
|
-
for (const [index2, line] of raw.split("\n").entries()) {
|
|
71451
|
-
if (!line.trim()) continue;
|
|
71452
|
-
let receipt;
|
|
71453
|
-
try {
|
|
71454
|
-
receipt = parseReceipt(JSON.parse(line));
|
|
71455
|
-
} catch (error61) {
|
|
71456
|
-
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
71457
|
-
}
|
|
71458
|
-
if (receiptWallet(receipt) !== from16 || receipt.transfer?.nonce.toLowerCase() !== nonce.toLowerCase()) {
|
|
71459
|
-
continue;
|
|
71460
|
-
}
|
|
71461
|
-
latest = receipt;
|
|
71462
|
-
if (receipt.transfer.request !== void 0) request = receipt;
|
|
71463
|
-
}
|
|
71464
|
-
return {
|
|
71465
|
-
signed: latest !== void 0,
|
|
71466
|
-
...latest === void 0 ? {} : { latest },
|
|
71467
|
-
...request === void 0 ? {} : { request },
|
|
71468
|
-
...request?.transfer?.request?.authorization.validBefore === void 0 ? {} : { validBefore: request.transfer.request.authorization.validBefore },
|
|
71469
|
-
...(latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn) === void 0 ? {} : { reservedOn: latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn }
|
|
71470
|
-
};
|
|
71471
|
-
}
|
|
71472
|
-
|
|
71473
|
-
// ../core/src/vault-key.ts
|
|
71474
|
-
import { randomBytes as cryptoRandomBytes } from "node:crypto";
|
|
71475
|
-
|
|
71476
70751
|
// ../core/src/vault.ts
|
|
71477
|
-
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
71478
|
-
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";
|
|
71479
|
-
import { dirname as dirname6 } from "node:path";
|
|
71480
70752
|
var VaultError = class extends Error {
|
|
71481
70753
|
code;
|
|
71482
70754
|
constructor(code, message, options) {
|
|
@@ -71862,249 +71134,1230 @@ async function exportVaultAccountKey(args) {
|
|
|
71862
71134
|
if (privateKeyToAccount(privateKey).address.toLowerCase() !== account.address.toLowerCase()) {
|
|
71863
71135
|
throw new VaultError("corrupt", "A vault key does not match its stored address.");
|
|
71864
71136
|
}
|
|
71865
|
-
return privateKey;
|
|
71866
|
-
} catch (error61) {
|
|
71867
|
-
throw asVaultError(error61, "corrupt", "Unable to export the vault account key.");
|
|
71137
|
+
return privateKey;
|
|
71138
|
+
} catch (error61) {
|
|
71139
|
+
throw asVaultError(error61, "corrupt", "Unable to export the vault account key.");
|
|
71140
|
+
}
|
|
71141
|
+
}
|
|
71142
|
+
async function exportMemberKey(args) {
|
|
71143
|
+
return await exportVaultAccountKey(args);
|
|
71144
|
+
}
|
|
71145
|
+
function assertVaultKey(key2) {
|
|
71146
|
+
if (key2.byteLength !== 32) {
|
|
71147
|
+
throw new VaultError("bad_key", "A device vault key must contain exactly 32 bytes.");
|
|
71148
|
+
}
|
|
71149
|
+
}
|
|
71150
|
+
function assertAccountName(name) {
|
|
71151
|
+
const parsed = walletNameSchema.safeParse(name);
|
|
71152
|
+
if (!parsed.success) {
|
|
71153
|
+
throw new VaultError("name_taken", "The vault account name is not valid.", {
|
|
71154
|
+
cause: parsed.error
|
|
71155
|
+
});
|
|
71156
|
+
}
|
|
71157
|
+
}
|
|
71158
|
+
function assertAvailableName(file2, name) {
|
|
71159
|
+
assertAccountName(name);
|
|
71160
|
+
if (file2.accounts.some((account) => account.name === name)) {
|
|
71161
|
+
throw new VaultError("name_taken", "A vault account already has that name.");
|
|
71162
|
+
}
|
|
71163
|
+
}
|
|
71164
|
+
function nextDerivedIndex(file2) {
|
|
71165
|
+
let next = file2.nextDerivedIndex ?? 0;
|
|
71166
|
+
for (const account of file2.accounts) {
|
|
71167
|
+
if (account.kind === "derived") next = Math.max(next, account.index + 1);
|
|
71168
|
+
}
|
|
71169
|
+
return next;
|
|
71170
|
+
}
|
|
71171
|
+
function copyAccount(account) {
|
|
71172
|
+
if (account.kind === "derived") return { ...account };
|
|
71173
|
+
return {
|
|
71174
|
+
name: account.name,
|
|
71175
|
+
kind: account.kind,
|
|
71176
|
+
address: account.address,
|
|
71177
|
+
createdAt: account.createdAt
|
|
71178
|
+
};
|
|
71179
|
+
}
|
|
71180
|
+
function sealField(key2, plaintext) {
|
|
71181
|
+
const { nonce, ciphertext, tag } = encryptWithKey(key2, plaintext);
|
|
71182
|
+
return [nonce, ciphertext, tag].map((part) => part.toString("base64url")).join(".");
|
|
71183
|
+
}
|
|
71184
|
+
function openField(key2, value) {
|
|
71185
|
+
const [nonce = "", ciphertext = "", tag = ""] = value.split(".");
|
|
71186
|
+
return decryptWithKey(key2, {
|
|
71187
|
+
nonce: Buffer.from(nonce, "base64url"),
|
|
71188
|
+
ciphertext: Buffer.from(ciphertext, "base64url"),
|
|
71189
|
+
tag: Buffer.from(tag, "base64url")
|
|
71190
|
+
});
|
|
71191
|
+
}
|
|
71192
|
+
function decryptField(key2, value) {
|
|
71193
|
+
try {
|
|
71194
|
+
return openField(key2, value);
|
|
71195
|
+
} catch (error61) {
|
|
71196
|
+
throw new VaultError("bad_key", "Unable to decrypt the vault with this device key.", {
|
|
71197
|
+
cause: error61
|
|
71198
|
+
});
|
|
71199
|
+
}
|
|
71200
|
+
}
|
|
71201
|
+
function decryptPhraseForOpen(key2, phrase) {
|
|
71202
|
+
try {
|
|
71203
|
+
return openField(key2, phrase);
|
|
71204
|
+
} catch (error61) {
|
|
71205
|
+
throw new VaultError("bad_key", "Unable to decrypt the vault with this device key.", {
|
|
71206
|
+
cause: error61
|
|
71207
|
+
});
|
|
71208
|
+
}
|
|
71209
|
+
}
|
|
71210
|
+
function validateStoredImportedAccount(key2, account) {
|
|
71211
|
+
let plaintext;
|
|
71212
|
+
try {
|
|
71213
|
+
plaintext = decryptField(key2, account.key);
|
|
71214
|
+
if (plaintext.byteLength !== 32) {
|
|
71215
|
+
throw new VaultError("bad_key", "The stored imported key has the wrong length.");
|
|
71216
|
+
}
|
|
71217
|
+
let address4;
|
|
71218
|
+
try {
|
|
71219
|
+
address4 = privateKeyToAccount(`0x${plaintext.toString("hex")}`).address;
|
|
71220
|
+
} catch (error61) {
|
|
71221
|
+
throw new VaultError("bad_key", "The stored imported key is not valid.", {
|
|
71222
|
+
cause: error61
|
|
71223
|
+
});
|
|
71224
|
+
}
|
|
71225
|
+
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
71226
|
+
throw new VaultError("bad_key", "The stored imported key does not match its address.");
|
|
71227
|
+
}
|
|
71228
|
+
} finally {
|
|
71229
|
+
plaintext?.fill(0);
|
|
71230
|
+
}
|
|
71231
|
+
}
|
|
71232
|
+
function validateStoredDerivedAccount(key2, file2, account) {
|
|
71233
|
+
const plaintext = decryptField(key2, file2.phrase);
|
|
71234
|
+
let seed;
|
|
71235
|
+
try {
|
|
71236
|
+
seed = phraseToSeed(plaintext.toString("utf8"));
|
|
71237
|
+
const address4 = privateKeyToAccount(
|
|
71238
|
+
deriveEvmPrivateKey(seed, `m/44'/60'/0'/0/${account.index}`)
|
|
71239
|
+
).address;
|
|
71240
|
+
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
71241
|
+
throw new VaultError("bad_key", "The stored derived account does not match this vault.");
|
|
71242
|
+
}
|
|
71243
|
+
} finally {
|
|
71244
|
+
seed?.fill(0);
|
|
71245
|
+
plaintext.fill(0);
|
|
71246
|
+
}
|
|
71247
|
+
}
|
|
71248
|
+
function parseVaultFile(raw) {
|
|
71249
|
+
let value;
|
|
71250
|
+
try {
|
|
71251
|
+
value = JSON.parse(raw);
|
|
71252
|
+
} catch (error61) {
|
|
71253
|
+
throw new VaultError("corrupt", "The vault file is not valid JSON.", { cause: error61 });
|
|
71254
|
+
}
|
|
71255
|
+
const parsed = vaultFileSchema.safeParse(value);
|
|
71256
|
+
if (!parsed.success) {
|
|
71257
|
+
throw new VaultError("corrupt", "The vault file has an invalid structure.", {
|
|
71258
|
+
cause: parsed.error
|
|
71259
|
+
});
|
|
71260
|
+
}
|
|
71261
|
+
if (parsed.data.protected !== (parsed.data.wrappedKey !== void 0)) {
|
|
71262
|
+
throw new VaultError("corrupt", "The vault protection metadata is inconsistent.");
|
|
71263
|
+
}
|
|
71264
|
+
const names = /* @__PURE__ */ new Set();
|
|
71265
|
+
const indexes = /* @__PURE__ */ new Set();
|
|
71266
|
+
for (const account of parsed.data.accounts) {
|
|
71267
|
+
if (names.has(account.name)) {
|
|
71268
|
+
throw new VaultError("corrupt", "The vault file contains duplicate account names.");
|
|
71269
|
+
}
|
|
71270
|
+
names.add(account.name);
|
|
71271
|
+
if (account.kind === "derived") {
|
|
71272
|
+
if (indexes.has(account.index)) {
|
|
71273
|
+
throw new VaultError("corrupt", "The vault file contains duplicate derived indexes.");
|
|
71274
|
+
}
|
|
71275
|
+
indexes.add(account.index);
|
|
71276
|
+
}
|
|
71277
|
+
}
|
|
71278
|
+
return parsed.data;
|
|
71279
|
+
}
|
|
71280
|
+
async function readVaultFile(path, key2) {
|
|
71281
|
+
const file2 = await readVaultFileUnlocked(path);
|
|
71282
|
+
const plaintext = decryptPhraseForOpen(key2, file2.phrase);
|
|
71283
|
+
try {
|
|
71284
|
+
try {
|
|
71285
|
+
validateRecoveryPhrase(plaintext.toString("utf8"));
|
|
71286
|
+
} catch (error61) {
|
|
71287
|
+
throw new VaultError("corrupt", "The vault recovery phrase is not valid.", {
|
|
71288
|
+
cause: error61
|
|
71289
|
+
});
|
|
71290
|
+
}
|
|
71291
|
+
} finally {
|
|
71292
|
+
plaintext.fill(0);
|
|
71293
|
+
}
|
|
71294
|
+
return file2;
|
|
71295
|
+
}
|
|
71296
|
+
async function readVaultFileUnlocked(path) {
|
|
71297
|
+
let raw;
|
|
71298
|
+
try {
|
|
71299
|
+
raw = await readFile7(path, "utf8");
|
|
71300
|
+
} catch (error61) {
|
|
71301
|
+
if (isMissingFile2(error61)) {
|
|
71302
|
+
throw new VaultError("not_found", "No vault file was found at the requested path.", {
|
|
71303
|
+
cause: error61
|
|
71304
|
+
});
|
|
71305
|
+
}
|
|
71306
|
+
throw new VaultError("corrupt", "Unable to read the vault file.", { cause: error61 });
|
|
71307
|
+
}
|
|
71308
|
+
return parseVaultFile(raw);
|
|
71309
|
+
}
|
|
71310
|
+
async function refuseExistingVault(path) {
|
|
71311
|
+
try {
|
|
71312
|
+
await stat6(path);
|
|
71313
|
+
} catch (error61) {
|
|
71314
|
+
if (isMissingFile2(error61)) return;
|
|
71315
|
+
throw new VaultError("corrupt", "Unable to check whether the vault already exists.", {
|
|
71316
|
+
cause: error61
|
|
71317
|
+
});
|
|
71318
|
+
}
|
|
71319
|
+
throw new VaultError("corrupt", "A vault already exists at the requested path.");
|
|
71320
|
+
}
|
|
71321
|
+
async function writeVaultFile(path, file2) {
|
|
71322
|
+
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
71323
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes5(6).toString("hex")}.tmp`;
|
|
71324
|
+
try {
|
|
71325
|
+
await writeFile3(temporaryPath, `${JSON.stringify(file2, null, 2)}
|
|
71326
|
+
`, {
|
|
71327
|
+
encoding: "utf8",
|
|
71328
|
+
mode: 384,
|
|
71329
|
+
flag: "wx"
|
|
71330
|
+
});
|
|
71331
|
+
await rename4(temporaryPath, path);
|
|
71332
|
+
} catch (error61) {
|
|
71333
|
+
await rm(temporaryPath, { force: true }).catch(() => void 0);
|
|
71334
|
+
throw error61;
|
|
71335
|
+
}
|
|
71336
|
+
}
|
|
71337
|
+
async function withVaultLock(path, operation) {
|
|
71338
|
+
await mkdir7(dirname5(path), { recursive: true, mode: 448 });
|
|
71339
|
+
const lockPath = `${path}.lock`;
|
|
71340
|
+
const deadline = Date.now() + VAULT_LOCK_TIMEOUT_MS;
|
|
71341
|
+
let handle;
|
|
71342
|
+
while (!handle) {
|
|
71343
|
+
try {
|
|
71344
|
+
handle = await open5(lockPath, "wx", 384);
|
|
71345
|
+
} catch (error61) {
|
|
71346
|
+
if (!isExistingFile(error61)) throw error61;
|
|
71347
|
+
await removeStaleVaultLock(lockPath);
|
|
71348
|
+
if (Date.now() >= deadline) {
|
|
71349
|
+
throw new VaultError("corrupt", "Timed out waiting for the vault lock.");
|
|
71350
|
+
}
|
|
71351
|
+
await new Promise((resolve4) => setTimeout(resolve4, 20));
|
|
71352
|
+
}
|
|
71353
|
+
}
|
|
71354
|
+
try {
|
|
71355
|
+
return await operation();
|
|
71356
|
+
} finally {
|
|
71357
|
+
await handle.close();
|
|
71358
|
+
await unlink4(lockPath).catch(() => void 0);
|
|
71359
|
+
}
|
|
71360
|
+
}
|
|
71361
|
+
async function removeStaleVaultLock(path) {
|
|
71362
|
+
try {
|
|
71363
|
+
const metadata = await stat6(path);
|
|
71364
|
+
if (Date.now() - metadata.mtimeMs > STALE_VAULT_LOCK_MS) await unlink4(path);
|
|
71365
|
+
} catch (error61) {
|
|
71366
|
+
if (!isMissingFile2(error61)) throw error61;
|
|
71367
|
+
}
|
|
71368
|
+
}
|
|
71369
|
+
function isMissingFile2(error61) {
|
|
71370
|
+
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "ENOENT";
|
|
71371
|
+
}
|
|
71372
|
+
function isExistingFile(error61) {
|
|
71373
|
+
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "EEXIST";
|
|
71374
|
+
}
|
|
71375
|
+
function asVaultError(error61, code, message) {
|
|
71376
|
+
return error61 instanceof VaultError ? error61 : new VaultError(code, message, { cause: error61 });
|
|
71377
|
+
}
|
|
71378
|
+
|
|
71379
|
+
// ../core/src/file-secret-store.ts
|
|
71380
|
+
var FILE_SECRET_STORE_PASSWORD_ENV = "VAPI_VAULT_PASSWORD";
|
|
71381
|
+
var FILE_SECRET_STORE_MIN_PASSWORD = 12;
|
|
71382
|
+
var CHECK_VALUE = "vapi-network file secret store";
|
|
71383
|
+
var sealedSchema = external_exports.object({ nonce: external_exports.string(), ciphertext: external_exports.string(), tag: external_exports.string() }).strict();
|
|
71384
|
+
var fileSchema = external_exports.object({
|
|
71385
|
+
v: external_exports.literal(1),
|
|
71386
|
+
salt: external_exports.string(),
|
|
71387
|
+
check: sealedSchema,
|
|
71388
|
+
entries: external_exports.record(external_exports.string(), sealedSchema)
|
|
71389
|
+
}).strict();
|
|
71390
|
+
async function createFileSecretStore(options) {
|
|
71391
|
+
const password = passwordFrom(options.env);
|
|
71392
|
+
if (password.length < FILE_SECRET_STORE_MIN_PASSWORD) {
|
|
71393
|
+
throw new KeystoreError(
|
|
71394
|
+
`${FILE_SECRET_STORE_PASSWORD_ENV} must be at least ${FILE_SECRET_STORE_MIN_PASSWORD} characters.`
|
|
71395
|
+
);
|
|
71396
|
+
}
|
|
71397
|
+
await withVaultLock(options.path, async () => {
|
|
71398
|
+
let exists = true;
|
|
71399
|
+
try {
|
|
71400
|
+
await stat7(options.path);
|
|
71401
|
+
} catch (error61) {
|
|
71402
|
+
if (!isMissingFile(error61)) throw error61;
|
|
71403
|
+
exists = false;
|
|
71404
|
+
}
|
|
71405
|
+
if (exists) {
|
|
71406
|
+
await withKey(options.path, options.env, async () => void 0);
|
|
71407
|
+
return;
|
|
71408
|
+
}
|
|
71409
|
+
const salt = randomBytes6(32);
|
|
71410
|
+
const key2 = await deriveScryptKey(password, salt);
|
|
71411
|
+
try {
|
|
71412
|
+
await writeJsonAtomic(
|
|
71413
|
+
options.path,
|
|
71414
|
+
{
|
|
71415
|
+
v: 1,
|
|
71416
|
+
salt: salt.toString("base64"),
|
|
71417
|
+
check: seal(key2, CHECK_VALUE),
|
|
71418
|
+
entries: {}
|
|
71419
|
+
},
|
|
71420
|
+
{ mode: 384 }
|
|
71421
|
+
);
|
|
71422
|
+
} finally {
|
|
71423
|
+
key2.fill(0);
|
|
71424
|
+
}
|
|
71425
|
+
});
|
|
71426
|
+
}
|
|
71427
|
+
function fileSecretStore(options) {
|
|
71428
|
+
const env = options.env ?? process.env;
|
|
71429
|
+
const write2 = async (change) => await withVaultLock(
|
|
71430
|
+
options.path,
|
|
71431
|
+
async () => await withKey(options.path, env, async (file2, key2) => {
|
|
71432
|
+
const changed = change(file2, key2);
|
|
71433
|
+
if (changed) await writeJsonAtomic(options.path, file2, { mode: 384 });
|
|
71434
|
+
return changed;
|
|
71435
|
+
})
|
|
71436
|
+
);
|
|
71437
|
+
const get = async (name) => await withKey(options.path, env, async (file2, key2) => {
|
|
71438
|
+
const sealed = Object.hasOwn(file2.entries, name) ? file2.entries[name] : void 0;
|
|
71439
|
+
return sealed === void 0 ? void 0 : open6(key2, sealed);
|
|
71440
|
+
});
|
|
71441
|
+
return {
|
|
71442
|
+
// A locked backend still exists; it must never enable a plaintext fallback.
|
|
71443
|
+
available: true,
|
|
71444
|
+
platform: process.platform,
|
|
71445
|
+
description: "the encrypted vAPI secrets file",
|
|
71446
|
+
get,
|
|
71447
|
+
async has(name) {
|
|
71448
|
+
return await get(name) !== void 0;
|
|
71449
|
+
},
|
|
71450
|
+
async set(name, value) {
|
|
71451
|
+
if (name === "__proto__") {
|
|
71452
|
+
throw new KeystoreError("The secret name is reserved in the encrypted vAPI secrets file.");
|
|
71453
|
+
}
|
|
71454
|
+
await write2((file2, key2) => {
|
|
71455
|
+
file2.entries[name] = seal(key2, value);
|
|
71456
|
+
return true;
|
|
71457
|
+
});
|
|
71458
|
+
},
|
|
71459
|
+
async remove(name) {
|
|
71460
|
+
return await write2((file2) => {
|
|
71461
|
+
if (!Object.hasOwn(file2.entries, name)) return false;
|
|
71462
|
+
delete file2.entries[name];
|
|
71463
|
+
return true;
|
|
71464
|
+
});
|
|
71465
|
+
}
|
|
71466
|
+
};
|
|
71467
|
+
}
|
|
71468
|
+
async function withKey(path, env, operation) {
|
|
71469
|
+
const file2 = await readStoredFile(path);
|
|
71470
|
+
const key2 = await deriveScryptKey(passwordFrom(env), Buffer.from(file2.salt, "base64"));
|
|
71471
|
+
try {
|
|
71472
|
+
if (open6(key2, file2.check) !== CHECK_VALUE) throw wrongPassword();
|
|
71473
|
+
return await operation(file2, key2);
|
|
71474
|
+
} finally {
|
|
71475
|
+
key2.fill(0);
|
|
71476
|
+
}
|
|
71477
|
+
}
|
|
71478
|
+
function passwordFrom(env) {
|
|
71479
|
+
const password = (env ?? process.env)[FILE_SECRET_STORE_PASSWORD_ENV];
|
|
71480
|
+
if (!password) {
|
|
71481
|
+
throw new KeystoreError(
|
|
71482
|
+
`This vault keeps its secrets in an encrypted file. Set ${FILE_SECRET_STORE_PASSWORD_ENV} to open it.`
|
|
71483
|
+
);
|
|
71484
|
+
}
|
|
71485
|
+
return password;
|
|
71486
|
+
}
|
|
71487
|
+
async function readStoredFile(path) {
|
|
71488
|
+
let raw;
|
|
71489
|
+
try {
|
|
71490
|
+
raw = await readFile8(path, "utf8");
|
|
71491
|
+
} catch (error61) {
|
|
71492
|
+
throw new KeystoreError("The vAPI secrets file is missing. Run vapi setup again.", {
|
|
71493
|
+
cause: error61
|
|
71494
|
+
});
|
|
71495
|
+
}
|
|
71496
|
+
let value;
|
|
71497
|
+
try {
|
|
71498
|
+
value = JSON.parse(raw);
|
|
71499
|
+
} catch {
|
|
71500
|
+
throw new KeystoreError("The vAPI secrets file is damaged.");
|
|
71501
|
+
}
|
|
71502
|
+
const parsed = fileSchema.safeParse(value);
|
|
71503
|
+
if (!parsed.success) throw new KeystoreError("The vAPI secrets file is damaged.");
|
|
71504
|
+
return parsed.data;
|
|
71505
|
+
}
|
|
71506
|
+
function seal(key2, value) {
|
|
71507
|
+
const { nonce, ciphertext, tag } = encryptWithKey(key2, Buffer.from(value, "utf8"));
|
|
71508
|
+
return {
|
|
71509
|
+
nonce: nonce.toString("base64"),
|
|
71510
|
+
ciphertext: ciphertext.toString("base64"),
|
|
71511
|
+
tag: tag.toString("base64")
|
|
71512
|
+
};
|
|
71513
|
+
}
|
|
71514
|
+
function open6(key2, sealed) {
|
|
71515
|
+
try {
|
|
71516
|
+
return decryptWithKey(key2, {
|
|
71517
|
+
nonce: Buffer.from(sealed.nonce, "base64"),
|
|
71518
|
+
ciphertext: Buffer.from(sealed.ciphertext, "base64"),
|
|
71519
|
+
tag: Buffer.from(sealed.tag, "base64")
|
|
71520
|
+
}).toString("utf8");
|
|
71521
|
+
} catch (error61) {
|
|
71522
|
+
throw wrongPassword(error61);
|
|
71523
|
+
}
|
|
71524
|
+
}
|
|
71525
|
+
function wrongPassword(cause) {
|
|
71526
|
+
return new KeystoreError(`Wrong ${FILE_SECRET_STORE_PASSWORD_ENV} for the vAPI secrets file.`, {
|
|
71527
|
+
cause
|
|
71528
|
+
});
|
|
71529
|
+
}
|
|
71530
|
+
|
|
71531
|
+
// ../core/src/secret-backend.ts
|
|
71532
|
+
import { readFileSync } from "node:fs";
|
|
71533
|
+
import { stat as stat8 } from "node:fs/promises";
|
|
71534
|
+
import { join as join6 } from "node:path";
|
|
71535
|
+
var PROBE_ACCOUNT = "setup-probe";
|
|
71536
|
+
var pinSchema = external_exports.object({ v: external_exports.literal(1), backend: external_exports.enum(["os", "file"]) }).strict();
|
|
71537
|
+
function secretBackendPath(home = getVapiPaths().directory) {
|
|
71538
|
+
return join6(home, "secret-store.json");
|
|
71539
|
+
}
|
|
71540
|
+
function secretsFilePath(home = getVapiPaths().directory) {
|
|
71541
|
+
return join6(home, "secrets.json");
|
|
71542
|
+
}
|
|
71543
|
+
function readSecretBackend(home = getVapiPaths().directory) {
|
|
71544
|
+
const path = secretBackendPath(home);
|
|
71545
|
+
try {
|
|
71546
|
+
const parsed = pinSchema.safeParse(JSON.parse(readFileSync(path, "utf8")));
|
|
71547
|
+
if (parsed.success) return parsed.data.backend;
|
|
71548
|
+
} catch (error61) {
|
|
71549
|
+
if (isMissingFile(error61)) return "os";
|
|
71550
|
+
}
|
|
71551
|
+
throw new KeystoreError(`The vAPI secret-store pin at ${path} is damaged.`);
|
|
71552
|
+
}
|
|
71553
|
+
async function chooseSecretBackend(options) {
|
|
71554
|
+
const env = options.env ?? process.env;
|
|
71555
|
+
const osWorks = options.os.platform !== "linux" || await osStoreWorks(options.os);
|
|
71556
|
+
const path = secretBackendPath(options.home);
|
|
71557
|
+
return await withVaultLock(path, async () => {
|
|
71558
|
+
if (await fileExists(path)) return readSecretBackend(options.home);
|
|
71559
|
+
if (await fileExists(join6(options.home, "vault.json"))) return "os";
|
|
71560
|
+
let backend;
|
|
71561
|
+
if (osWorks) {
|
|
71562
|
+
backend = "os";
|
|
71563
|
+
} else if (env[FILE_SECRET_STORE_PASSWORD_ENV]) {
|
|
71564
|
+
await createFileSecretStore({ path: secretsFilePath(options.home), env });
|
|
71565
|
+
backend = "file";
|
|
71566
|
+
} else {
|
|
71567
|
+
throw new KeystoreError(
|
|
71568
|
+
[
|
|
71569
|
+
`This machine has no working keyring (${options.os.description}).`,
|
|
71570
|
+
`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,`,
|
|
71571
|
+
"or run vapi on your own computer, or connect Claude from https://api.vapinetwork.ai/connect."
|
|
71572
|
+
].join(" ")
|
|
71573
|
+
);
|
|
71574
|
+
}
|
|
71575
|
+
await writeJsonAtomic(path, { v: 1, backend }, { mode: 384 });
|
|
71576
|
+
return backend;
|
|
71577
|
+
});
|
|
71578
|
+
}
|
|
71579
|
+
async function fileExists(path) {
|
|
71580
|
+
try {
|
|
71581
|
+
await stat8(path);
|
|
71582
|
+
return true;
|
|
71583
|
+
} catch (error61) {
|
|
71584
|
+
if (isMissingFile(error61)) return false;
|
|
71585
|
+
throw error61;
|
|
71586
|
+
}
|
|
71587
|
+
}
|
|
71588
|
+
async function osStoreWorks(store) {
|
|
71589
|
+
if (!store.available) return false;
|
|
71590
|
+
try {
|
|
71591
|
+
try {
|
|
71592
|
+
await store.set(PROBE_ACCOUNT, "ok");
|
|
71593
|
+
return await store.get(PROBE_ACCOUNT) === "ok";
|
|
71594
|
+
} finally {
|
|
71595
|
+
await store.remove(PROBE_ACCOUNT);
|
|
71596
|
+
}
|
|
71597
|
+
} catch {
|
|
71598
|
+
return false;
|
|
71599
|
+
}
|
|
71600
|
+
}
|
|
71601
|
+
|
|
71602
|
+
// ../core/src/secret-store.ts
|
|
71603
|
+
var SECRET_STORE_SERVICE = "vapi-network";
|
|
71604
|
+
var SECURITY_BINARY = "/usr/bin/security";
|
|
71605
|
+
var SECRET_TOOL_BINARY = "secret-tool";
|
|
71606
|
+
var WINDOWS_POWERSHELL_ARGS = ["-NoProfile", "-NonInteractive", "-Command", "-"];
|
|
71607
|
+
var SECURITY_ITEM_NOT_FOUND = 44;
|
|
71608
|
+
var WINDOWS_SECRET_SUCCESS = 0;
|
|
71609
|
+
var WINDOWS_SECRET_NOT_FOUND = 2;
|
|
71610
|
+
var UNSUPPORTED_PLATFORM = "No OS secret store on this platform yet; use VAPI_KEYSTORE_PASSWORD.";
|
|
71611
|
+
var SECRET_TOOL_MISSING = [
|
|
71612
|
+
"secret-tool is not installed, so the passphrase cannot be kept in the OS secret store.",
|
|
71613
|
+
"Install libsecret-tools (Debian, Ubuntu) or libsecret (Fedora, Arch), or use VAPI_KEYSTORE_PASSWORD."
|
|
71614
|
+
].join(" ");
|
|
71615
|
+
var POWERSHELL_MISSING = [
|
|
71616
|
+
"Windows PowerShell (powershell.exe) was not found, so the passphrase cannot be kept in the OS secret store.",
|
|
71617
|
+
"Use VAPI_KEYSTORE_PASSWORD."
|
|
71618
|
+
].join(" ");
|
|
71619
|
+
function secretStore(options = {}) {
|
|
71620
|
+
const home = options.home ?? getVapiPaths().directory;
|
|
71621
|
+
if (readSecretBackend(home) === "file") {
|
|
71622
|
+
return fileSecretStore({ path: secretsFilePath(home), env: options.env ?? process.env });
|
|
71623
|
+
}
|
|
71624
|
+
return osSecretStore(options);
|
|
71625
|
+
}
|
|
71626
|
+
function osSecretStore(options = {}) {
|
|
71627
|
+
const platform2 = options.platform ?? process.platform;
|
|
71628
|
+
const run = options.run ?? (async (file2, args, input2) => await spawnRunner(platform2, file2, args, input2));
|
|
71629
|
+
const env = options.env ?? process.env;
|
|
71630
|
+
const installed = options.installed ?? ((file2) => binaryInstalled(file2, env));
|
|
71631
|
+
if (platform2 === "darwin") return keychainStore(platform2, run);
|
|
71632
|
+
if (platform2 === "win32") return windowsDataProtectionStore(platform2, run, env, installed);
|
|
71633
|
+
if (platform2 === "linux") return libsecretStore(platform2, run, installed);
|
|
71634
|
+
return unsupportedStore(platform2);
|
|
71635
|
+
}
|
|
71636
|
+
function memorySecretStore(initial = {}) {
|
|
71637
|
+
const entries = new Map(Object.entries(initial));
|
|
71638
|
+
return {
|
|
71639
|
+
available: true,
|
|
71640
|
+
platform: process.platform,
|
|
71641
|
+
description: "an in-memory store",
|
|
71642
|
+
async get(name) {
|
|
71643
|
+
return entries.get(name);
|
|
71644
|
+
},
|
|
71645
|
+
async has(name) {
|
|
71646
|
+
return entries.has(name);
|
|
71647
|
+
},
|
|
71648
|
+
async set(name, passphrase) {
|
|
71649
|
+
entries.set(name, passphrase);
|
|
71650
|
+
},
|
|
71651
|
+
async remove(name) {
|
|
71652
|
+
return entries.delete(name);
|
|
71653
|
+
},
|
|
71654
|
+
async list() {
|
|
71655
|
+
return [...entries.keys()].sort();
|
|
71656
|
+
}
|
|
71657
|
+
};
|
|
71658
|
+
}
|
|
71659
|
+
function keychainStore(platform2, run) {
|
|
71660
|
+
const find = async (account, withPassword) => await run(SECURITY_BINARY, [
|
|
71661
|
+
"find-generic-password",
|
|
71662
|
+
"-a",
|
|
71663
|
+
account,
|
|
71664
|
+
"-s",
|
|
71665
|
+
SECRET_STORE_SERVICE,
|
|
71666
|
+
...withPassword ? ["-w"] : []
|
|
71667
|
+
]);
|
|
71668
|
+
const read = async (account, what) => {
|
|
71669
|
+
const result = await find(account, true);
|
|
71670
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return void 0;
|
|
71671
|
+
requireSuccess(result, what);
|
|
71672
|
+
const value = withoutTrailingNewline(result.stdout);
|
|
71673
|
+
return value.length === 0 ? void 0 : value;
|
|
71674
|
+
};
|
|
71675
|
+
const write2 = async (account, value, what) => {
|
|
71676
|
+
const result = await run(
|
|
71677
|
+
SECURITY_BINARY,
|
|
71678
|
+
[
|
|
71679
|
+
"add-generic-password",
|
|
71680
|
+
"-a",
|
|
71681
|
+
account,
|
|
71682
|
+
"-s",
|
|
71683
|
+
SECRET_STORE_SERVICE,
|
|
71684
|
+
"-l",
|
|
71685
|
+
`${SECRET_STORE_SERVICE} ${account}`,
|
|
71686
|
+
"-U",
|
|
71687
|
+
"-w"
|
|
71688
|
+
],
|
|
71689
|
+
// `security` asks for the password and then for its confirmation.
|
|
71690
|
+
`${value}
|
|
71691
|
+
${value}
|
|
71692
|
+
`
|
|
71693
|
+
);
|
|
71694
|
+
requireSuccess(result, what);
|
|
71695
|
+
};
|
|
71696
|
+
const erase = async (account, what) => {
|
|
71697
|
+
const result = await run(SECURITY_BINARY, [
|
|
71698
|
+
"delete-generic-password",
|
|
71699
|
+
"-a",
|
|
71700
|
+
account,
|
|
71701
|
+
"-s",
|
|
71702
|
+
SECRET_STORE_SERVICE
|
|
71703
|
+
]);
|
|
71704
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71705
|
+
requireSuccess(result, what);
|
|
71706
|
+
return true;
|
|
71707
|
+
};
|
|
71708
|
+
const erasePartsAfter = async (account, keep, what) => {
|
|
71709
|
+
for (let part = keep + 1; part <= MAX_KEYCHAIN_PARTS; part += 1) {
|
|
71710
|
+
if (!await erase(keychainPart(account, part), what)) return;
|
|
71711
|
+
}
|
|
71712
|
+
};
|
|
71713
|
+
return {
|
|
71714
|
+
available: true,
|
|
71715
|
+
platform: platform2,
|
|
71716
|
+
description: "the macOS Keychain",
|
|
71717
|
+
async get(name) {
|
|
71718
|
+
const account = accountFor(name);
|
|
71719
|
+
const what = `read the passphrase of ${name} from the macOS Keychain`;
|
|
71720
|
+
const value = await read(account, what);
|
|
71721
|
+
const parts = value === void 0 ? void 0 : chunkedPartCount(value);
|
|
71722
|
+
if (value === void 0 || parts === void 0) return value;
|
|
71723
|
+
let joined = "";
|
|
71724
|
+
for (let part = 1; part <= parts; part += 1) {
|
|
71725
|
+
const chunk = await read(keychainPart(account, part), what);
|
|
71726
|
+
if (chunk === void 0) {
|
|
71727
|
+
throw new KeystoreError(
|
|
71728
|
+
`The stored secret ${name} is incomplete in the macOS Keychain. Store it again.`
|
|
71729
|
+
);
|
|
71730
|
+
}
|
|
71731
|
+
joined += chunk;
|
|
71732
|
+
}
|
|
71733
|
+
return joined;
|
|
71734
|
+
},
|
|
71735
|
+
async has(name) {
|
|
71736
|
+
const result = await find(accountFor(name), false);
|
|
71737
|
+
if (result.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71738
|
+
requireSuccess(result, `look up ${name} in the macOS Keychain`);
|
|
71739
|
+
return true;
|
|
71740
|
+
},
|
|
71741
|
+
async set(name, passphrase) {
|
|
71742
|
+
requirePassphrase(passphrase);
|
|
71743
|
+
const account = accountFor(name);
|
|
71744
|
+
const what = `store the passphrase of ${name} in the macOS Keychain`;
|
|
71745
|
+
if (passphrase.length <= KEYCHAIN_PROMPT_LIMIT) {
|
|
71746
|
+
await write2(account, passphrase, what);
|
|
71747
|
+
return;
|
|
71748
|
+
}
|
|
71749
|
+
const chunks = [];
|
|
71750
|
+
for (let index2 = 0; index2 < passphrase.length; index2 += KEYCHAIN_CHUNK) {
|
|
71751
|
+
chunks.push(passphrase.slice(index2, index2 + KEYCHAIN_CHUNK));
|
|
71752
|
+
}
|
|
71753
|
+
if (chunks.length > MAX_KEYCHAIN_PARTS) {
|
|
71754
|
+
throw new KeystoreError(`The secret ${name} is too long for the macOS Keychain.`);
|
|
71755
|
+
}
|
|
71756
|
+
for (const [index2, chunk] of chunks.entries()) {
|
|
71757
|
+
await write2(keychainPart(account, index2 + 1), chunk, what);
|
|
71758
|
+
}
|
|
71759
|
+
await erasePartsAfter(account, chunks.length, what);
|
|
71760
|
+
await write2(account, `${CHUNKED_MARKER}${chunks.length}`, what);
|
|
71761
|
+
},
|
|
71762
|
+
async remove(name) {
|
|
71763
|
+
const account = accountFor(name);
|
|
71764
|
+
const what = `remove the passphrase of ${name} from the macOS Keychain`;
|
|
71765
|
+
const found = await find(account, true);
|
|
71766
|
+
if (found.code === SECURITY_ITEM_NOT_FOUND) return false;
|
|
71767
|
+
requireSuccess(found, what);
|
|
71768
|
+
if (chunkedPartCount(withoutTrailingNewline(found.stdout)) !== void 0) {
|
|
71769
|
+
await erasePartsAfter(account, 0, what);
|
|
71770
|
+
}
|
|
71771
|
+
return await erase(account, what);
|
|
71772
|
+
}
|
|
71773
|
+
};
|
|
71774
|
+
}
|
|
71775
|
+
var KEYCHAIN_PROMPT_LIMIT = 128;
|
|
71776
|
+
var KEYCHAIN_CHUNK = 120;
|
|
71777
|
+
var MAX_KEYCHAIN_PARTS = 32;
|
|
71778
|
+
var CHUNKED_MARKER = "vapi-chunked:v1:";
|
|
71779
|
+
function keychainPart(account, part) {
|
|
71780
|
+
return `${account}#${part}`;
|
|
71781
|
+
}
|
|
71782
|
+
function chunkedPartCount(value) {
|
|
71783
|
+
if (!value.startsWith(CHUNKED_MARKER)) return void 0;
|
|
71784
|
+
const parts = Number(value.slice(CHUNKED_MARKER.length));
|
|
71785
|
+
return Number.isInteger(parts) && parts > 0 && parts <= MAX_KEYCHAIN_PARTS ? parts : void 0;
|
|
71786
|
+
}
|
|
71787
|
+
function windowsSecretFileName(account) {
|
|
71788
|
+
let encoded = "";
|
|
71789
|
+
for (let index2 = 0; index2 < account.length; index2 += 1) {
|
|
71790
|
+
const character = account[index2];
|
|
71791
|
+
if (/^[a-z0-9._#-]$/u.test(character)) {
|
|
71792
|
+
encoded += character;
|
|
71793
|
+
continue;
|
|
71794
|
+
}
|
|
71795
|
+
encoded += `%${account.charCodeAt(index2).toString(16).toUpperCase().padStart(4, "0")}`;
|
|
71796
|
+
}
|
|
71797
|
+
if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/iu.test(encoded)) {
|
|
71798
|
+
encoded = `%${encoded.charCodeAt(0).toString(16).toUpperCase()}${encoded.slice(1)}`;
|
|
71799
|
+
}
|
|
71800
|
+
return `${encoded}.bin`;
|
|
71801
|
+
}
|
|
71802
|
+
function windowsDataProtectionStore(platform2, run, env, installed) {
|
|
71803
|
+
const powershell = `${env.SystemRoot ?? "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
71804
|
+
const fileDetails = (name) => {
|
|
71805
|
+
const file2 = windowsSecretFileName(accountFor(name));
|
|
71806
|
+
return { file: file2, account: file2.slice(0, -".bin".length) };
|
|
71807
|
+
};
|
|
71808
|
+
const script = (file2, operations) => [
|
|
71809
|
+
"$ErrorActionPreference = 'Stop'",
|
|
71810
|
+
"try {",
|
|
71811
|
+
" Add-Type -AssemblyName System.Security",
|
|
71812
|
+
" $dir = Join-Path $env:LOCALAPPDATA 'vapi-network\\secrets'",
|
|
71813
|
+
` $path = Join-Path $dir '${file2}'`,
|
|
71814
|
+
...operations.map((operation) => ` ${operation}`),
|
|
71815
|
+
"} catch {",
|
|
71816
|
+
" [Console]::Error.WriteLine($_.Exception.Message)",
|
|
71817
|
+
" exit 1",
|
|
71818
|
+
"}"
|
|
71819
|
+
].join("\n");
|
|
71820
|
+
const execute = async (script2) => {
|
|
71821
|
+
const result = await run(powershell, WINDOWS_POWERSHELL_ARGS, `${script2}
|
|
71822
|
+
|
|
71823
|
+
`);
|
|
71824
|
+
requirePowerShell(result);
|
|
71825
|
+
return result;
|
|
71826
|
+
};
|
|
71827
|
+
return {
|
|
71828
|
+
available: installed(powershell),
|
|
71829
|
+
platform: platform2,
|
|
71830
|
+
description: "Windows Data Protection (DPAPI)",
|
|
71831
|
+
async get(name) {
|
|
71832
|
+
const { file: file2, account } = fileDetails(name);
|
|
71833
|
+
const result = await execute(
|
|
71834
|
+
script(file2, [
|
|
71835
|
+
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
71836
|
+
"$blob = [System.IO.File]::ReadAllBytes($path)",
|
|
71837
|
+
"$bytes = [System.Security.Cryptography.ProtectedData]::Unprotect($blob, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
71838
|
+
"[Console]::Out.Write([Convert]::ToBase64String($bytes))",
|
|
71839
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71840
|
+
])
|
|
71841
|
+
);
|
|
71842
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return void 0;
|
|
71843
|
+
requireSuccess(result, `read the passphrase of ${name} from Windows Data Protection`);
|
|
71844
|
+
const value = Buffer.from(result.stdout.trim(), "base64").toString("utf8");
|
|
71845
|
+
return value.length === 0 ? void 0 : value;
|
|
71846
|
+
},
|
|
71847
|
+
async has(name) {
|
|
71848
|
+
const { file: file2, account } = fileDetails(name);
|
|
71849
|
+
const result = await execute(
|
|
71850
|
+
script(file2, [
|
|
71851
|
+
`if (Test-Path -LiteralPath $path) { exit ${WINDOWS_SECRET_SUCCESS} }`,
|
|
71852
|
+
`[Console]::Error.WriteLine('No stored secret for ${account}.')`,
|
|
71853
|
+
`exit ${WINDOWS_SECRET_NOT_FOUND}`
|
|
71854
|
+
])
|
|
71855
|
+
);
|
|
71856
|
+
if (result.code === WINDOWS_SECRET_SUCCESS) return true;
|
|
71857
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
71858
|
+
requireSuccess(result, `look up ${name} in Windows Data Protection`);
|
|
71859
|
+
return false;
|
|
71860
|
+
},
|
|
71861
|
+
async set(name, passphrase) {
|
|
71862
|
+
requirePassphrase(passphrase);
|
|
71863
|
+
const { file: file2 } = fileDetails(name);
|
|
71864
|
+
const value = Buffer.from(passphrase, "utf8").toString("base64");
|
|
71865
|
+
const result = await execute(
|
|
71866
|
+
script(file2, [
|
|
71867
|
+
"[void][System.IO.Directory]::CreateDirectory($dir)",
|
|
71868
|
+
`$bytes = [Convert]::FromBase64String('${value}')`,
|
|
71869
|
+
"$blob = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, [System.Security.Cryptography.DataProtectionScope]::CurrentUser)",
|
|
71870
|
+
"[System.IO.File]::WriteAllBytes($path, $blob)",
|
|
71871
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71872
|
+
])
|
|
71873
|
+
);
|
|
71874
|
+
requireSuccess(result, `store the passphrase of ${name} in Windows Data Protection`);
|
|
71875
|
+
},
|
|
71876
|
+
async remove(name) {
|
|
71877
|
+
const { file: file2, account } = fileDetails(name);
|
|
71878
|
+
const result = await execute(
|
|
71879
|
+
script(file2, [
|
|
71880
|
+
`if (-not (Test-Path -LiteralPath $path)) { [Console]::Error.WriteLine('No stored secret for ${account}.'); exit ${WINDOWS_SECRET_NOT_FOUND} }`,
|
|
71881
|
+
"Remove-Item -LiteralPath $path -Force",
|
|
71882
|
+
`exit ${WINDOWS_SECRET_SUCCESS}`
|
|
71883
|
+
])
|
|
71884
|
+
);
|
|
71885
|
+
if (result.code === WINDOWS_SECRET_NOT_FOUND) return false;
|
|
71886
|
+
requireSuccess(result, `remove the passphrase of ${name} from Windows Data Protection`);
|
|
71887
|
+
return true;
|
|
71888
|
+
}
|
|
71889
|
+
};
|
|
71890
|
+
}
|
|
71891
|
+
function libsecretStore(platform2, run, installed) {
|
|
71892
|
+
const lookup2 = async (name) => {
|
|
71893
|
+
const result = await run(SECRET_TOOL_BINARY, [
|
|
71894
|
+
"lookup",
|
|
71895
|
+
"service",
|
|
71896
|
+
SECRET_STORE_SERVICE,
|
|
71897
|
+
"account",
|
|
71898
|
+
accountFor(name)
|
|
71899
|
+
]);
|
|
71900
|
+
requireBinary(result);
|
|
71901
|
+
const value = withoutTrailingNewline(result.stdout);
|
|
71902
|
+
if (result.code === 0) return value.length === 0 ? void 0 : value;
|
|
71903
|
+
if (result.stderr.trim().length === 0) return void 0;
|
|
71904
|
+
requireSuccess(result, `read the passphrase of ${name} from the secret service`);
|
|
71905
|
+
return void 0;
|
|
71906
|
+
};
|
|
71907
|
+
return {
|
|
71908
|
+
available: installed(SECRET_TOOL_BINARY),
|
|
71909
|
+
platform: platform2,
|
|
71910
|
+
description: "the libsecret keyring",
|
|
71911
|
+
get: lookup2,
|
|
71912
|
+
async has(name) {
|
|
71913
|
+
return await lookup2(name) !== void 0;
|
|
71914
|
+
},
|
|
71915
|
+
async set(name, passphrase) {
|
|
71916
|
+
requirePassphrase(passphrase);
|
|
71917
|
+
const account = accountFor(name);
|
|
71918
|
+
const result = await run(
|
|
71919
|
+
SECRET_TOOL_BINARY,
|
|
71920
|
+
[
|
|
71921
|
+
"store",
|
|
71922
|
+
`--label=${SECRET_STORE_SERVICE} ${account}`,
|
|
71923
|
+
"service",
|
|
71924
|
+
SECRET_STORE_SERVICE,
|
|
71925
|
+
"account",
|
|
71926
|
+
account
|
|
71927
|
+
],
|
|
71928
|
+
`${passphrase}
|
|
71929
|
+
`
|
|
71930
|
+
);
|
|
71931
|
+
requireBinary(result);
|
|
71932
|
+
requireSuccess(result, `store the passphrase of ${name} in the secret service`);
|
|
71933
|
+
},
|
|
71934
|
+
async remove(name) {
|
|
71935
|
+
const existed = await lookup2(name) !== void 0;
|
|
71936
|
+
const result = await run(SECRET_TOOL_BINARY, [
|
|
71937
|
+
"clear",
|
|
71938
|
+
"service",
|
|
71939
|
+
SECRET_STORE_SERVICE,
|
|
71940
|
+
"account",
|
|
71941
|
+
accountFor(name)
|
|
71942
|
+
]);
|
|
71943
|
+
requireBinary(result);
|
|
71944
|
+
requireSuccess(result, `remove the passphrase of ${name} from the secret service`);
|
|
71945
|
+
return existed;
|
|
71946
|
+
}
|
|
71947
|
+
};
|
|
71948
|
+
}
|
|
71949
|
+
function unsupportedStore(platform2) {
|
|
71950
|
+
const refuse = () => {
|
|
71951
|
+
throw new KeystoreError(UNSUPPORTED_PLATFORM);
|
|
71952
|
+
};
|
|
71953
|
+
return {
|
|
71954
|
+
available: false,
|
|
71955
|
+
platform: platform2,
|
|
71956
|
+
description: "no OS secret store",
|
|
71957
|
+
get: async () => refuse(),
|
|
71958
|
+
has: async () => refuse(),
|
|
71959
|
+
set: async () => refuse(),
|
|
71960
|
+
remove: async () => refuse()
|
|
71961
|
+
};
|
|
71962
|
+
}
|
|
71963
|
+
function accountFor(name) {
|
|
71964
|
+
const account = name.trim();
|
|
71965
|
+
if (account.length === 0) {
|
|
71966
|
+
throw new KeystoreError("A wallet name is needed to reach the OS secret store.");
|
|
71967
|
+
}
|
|
71968
|
+
return account;
|
|
71969
|
+
}
|
|
71970
|
+
function requirePassphrase(passphrase) {
|
|
71971
|
+
if (passphrase.length === 0) {
|
|
71972
|
+
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
71973
|
+
}
|
|
71974
|
+
}
|
|
71975
|
+
function requireBinary(result) {
|
|
71976
|
+
if (result.notFound === true) throw new KeystoreError(SECRET_TOOL_MISSING);
|
|
71977
|
+
}
|
|
71978
|
+
function requirePowerShell(result) {
|
|
71979
|
+
if (result.notFound === true) throw new KeystoreError(POWERSHELL_MISSING);
|
|
71980
|
+
}
|
|
71981
|
+
function binaryInstalled(file2, env) {
|
|
71982
|
+
if (isAbsolute(file2) || win32.isAbsolute(file2)) return existsSync(file2);
|
|
71983
|
+
return (env.PATH ?? "").split(delimiter).some((directory) => existsSync(join7(directory, file2)));
|
|
71984
|
+
}
|
|
71985
|
+
var SAFE_FAILURE_DETAILS = [
|
|
71986
|
+
"Cannot autolaunch D-Bus without X11 $DISPLAY",
|
|
71987
|
+
"Cannot autolaunch D-Bus",
|
|
71988
|
+
"The name org.freedesktop.secrets was not provided by any .service files",
|
|
71989
|
+
"Cannot create an item in a locked collection",
|
|
71990
|
+
"User interaction is not allowed.",
|
|
71991
|
+
"Access to the path is denied."
|
|
71992
|
+
];
|
|
71993
|
+
function requireSuccess(result, what) {
|
|
71994
|
+
if (result.code === 0) return;
|
|
71995
|
+
const detail = SAFE_FAILURE_DETAILS.find((reason) => result.stderr.includes(reason));
|
|
71996
|
+
throw new KeystoreError(
|
|
71997
|
+
`Could not ${what}${result.code === null ? "" : ` (exit ${result.code})`}.${detail === void 0 ? "" : ` ${detail}`}`
|
|
71998
|
+
);
|
|
71999
|
+
}
|
|
72000
|
+
function withoutTrailingNewline(value) {
|
|
72001
|
+
return value.replace(/\r?\n$/u, "");
|
|
72002
|
+
}
|
|
72003
|
+
var spawnRunner = async (platform2, file2, args, input2) => await new Promise((resolve4) => {
|
|
72004
|
+
let stdout = "";
|
|
72005
|
+
let stderr2 = "";
|
|
72006
|
+
let settled = false;
|
|
72007
|
+
const finish = (outcome) => {
|
|
72008
|
+
if (settled) return;
|
|
72009
|
+
settled = true;
|
|
72010
|
+
resolve4(outcome);
|
|
72011
|
+
};
|
|
72012
|
+
const child = spawn(file2, [...args], {
|
|
72013
|
+
detached: platform2 !== "win32",
|
|
72014
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
72015
|
+
windowsHide: true
|
|
72016
|
+
});
|
|
72017
|
+
child.stdout?.setEncoding("utf8");
|
|
72018
|
+
child.stdout?.on("data", (chunk) => {
|
|
72019
|
+
stdout += chunk;
|
|
72020
|
+
});
|
|
72021
|
+
child.stderr?.setEncoding("utf8");
|
|
72022
|
+
child.stderr?.on("data", (chunk) => {
|
|
72023
|
+
stderr2 += chunk;
|
|
72024
|
+
});
|
|
72025
|
+
child.on("error", (error61) => {
|
|
72026
|
+
finish({
|
|
72027
|
+
code: null,
|
|
72028
|
+
stdout,
|
|
72029
|
+
stderr: stderr2,
|
|
72030
|
+
...error61.code === "ENOENT" ? { notFound: true } : {}
|
|
72031
|
+
});
|
|
72032
|
+
});
|
|
72033
|
+
child.on("close", (code) => finish({ code, stdout, stderr: stderr2 }));
|
|
72034
|
+
child.stdin?.on("error", () => void 0);
|
|
72035
|
+
child.stdin?.end(input2 ?? "");
|
|
72036
|
+
});
|
|
72037
|
+
|
|
72038
|
+
// ../core/src/passphrase.ts
|
|
72039
|
+
var PASSPHRASE_ENVIRONMENT_VARIABLE = "VAPI_KEYSTORE_PASSWORD";
|
|
72040
|
+
function noPassphraseHint(walletName) {
|
|
72041
|
+
return `Set ${PASSPHRASE_ENVIRONMENT_VARIABLE}, or store this wallet's passphrase once with vapi unlock --wallet ${walletName}.`;
|
|
72042
|
+
}
|
|
72043
|
+
function staleStoredPassphraseMessage(walletName, store) {
|
|
72044
|
+
return [
|
|
72045
|
+
`The passphrase stored in ${store.description} no longer opens wallet ${walletName}.`,
|
|
72046
|
+
`Store the current one with vapi unlock --wallet ${walletName}, or remove it with vapi lock --wallet ${walletName}.`
|
|
72047
|
+
].join(" ");
|
|
72048
|
+
}
|
|
72049
|
+
async function resolvePassphrase(walletName, options = {}) {
|
|
72050
|
+
const env = options.env ?? process.env;
|
|
72051
|
+
const fromEnvironment = env[PASSPHRASE_ENVIRONMENT_VARIABLE];
|
|
72052
|
+
if (fromEnvironment !== void 0) {
|
|
72053
|
+
if (fromEnvironment.length === 0) {
|
|
72054
|
+
throw new KeystoreError(`${PASSPHRASE_ENVIRONMENT_VARIABLE} cannot be empty.`);
|
|
72055
|
+
}
|
|
72056
|
+
return { passphrase: fromEnvironment, source: "environment" };
|
|
71868
72057
|
}
|
|
71869
|
-
|
|
71870
|
-
|
|
71871
|
-
|
|
71872
|
-
}
|
|
71873
|
-
function assertVaultKey(key2) {
|
|
71874
|
-
if (key2.byteLength !== 32) {
|
|
71875
|
-
throw new VaultError("bad_key", "A device vault key must contain exactly 32 bytes.");
|
|
72058
|
+
if (options.confirm !== true) {
|
|
72059
|
+
const stored = await readStored(options.store ?? secretStore(), walletName);
|
|
72060
|
+
if (stored !== void 0) return { passphrase: stored, source: "secret-store" };
|
|
71876
72061
|
}
|
|
71877
|
-
|
|
71878
|
-
|
|
71879
|
-
|
|
71880
|
-
|
|
71881
|
-
|
|
71882
|
-
cause: parsed.error
|
|
71883
|
-
});
|
|
72062
|
+
const hint = noPassphraseHint(walletName);
|
|
72063
|
+
if (options.interactive === false) {
|
|
72064
|
+
throw new KeystoreError(
|
|
72065
|
+
`No interactive terminal is available for the keystore prompt. ${hint}`
|
|
72066
|
+
);
|
|
71884
72067
|
}
|
|
71885
|
-
|
|
71886
|
-
|
|
71887
|
-
|
|
71888
|
-
|
|
71889
|
-
|
|
72068
|
+
const prompt = options.prompt ?? promptForSecret;
|
|
72069
|
+
const first = await prompt(`Passphrase for ${walletName}: `, hint);
|
|
72070
|
+
if (first.length === 0) {
|
|
72071
|
+
throw new KeystoreError("Keystore passphrase cannot be empty.");
|
|
72072
|
+
}
|
|
72073
|
+
if (options.confirm === true) {
|
|
72074
|
+
const second = await prompt("Confirm passphrase: ", hint);
|
|
72075
|
+
if (first !== second) throw new KeystoreError("Passphrases do not match.");
|
|
71890
72076
|
}
|
|
72077
|
+
return { passphrase: first, source: "prompt" };
|
|
71891
72078
|
}
|
|
71892
|
-
function
|
|
71893
|
-
|
|
71894
|
-
|
|
71895
|
-
|
|
72079
|
+
async function readStored(store, walletName) {
|
|
72080
|
+
if (!store.available) return void 0;
|
|
72081
|
+
try {
|
|
72082
|
+
return await store.get(walletName);
|
|
72083
|
+
} catch {
|
|
72084
|
+
return void 0;
|
|
71896
72085
|
}
|
|
71897
|
-
return next;
|
|
71898
72086
|
}
|
|
71899
|
-
|
|
71900
|
-
|
|
71901
|
-
|
|
71902
|
-
|
|
71903
|
-
|
|
71904
|
-
|
|
71905
|
-
|
|
71906
|
-
|
|
72087
|
+
|
|
72088
|
+
// ../core/src/receipts.ts
|
|
72089
|
+
import { randomBytes as randomBytes8 } from "node:crypto";
|
|
72090
|
+
import { mkdir as mkdir8, open as open7, readFile as readFile9, rename as rename5, writeFile as writeFile4 } from "node:fs/promises";
|
|
72091
|
+
import { dirname as dirname6 } from "node:path";
|
|
72092
|
+
|
|
72093
|
+
// ../core/src/agent-run.ts
|
|
72094
|
+
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
72095
|
+
var RUN_ID_PATTERN = /^run_[0-9a-f]{24}$/;
|
|
72096
|
+
function isRunId(value) {
|
|
72097
|
+
return typeof value === "string" && RUN_ID_PATTERN.test(value);
|
|
71907
72098
|
}
|
|
71908
|
-
function
|
|
71909
|
-
|
|
71910
|
-
return [nonce, ciphertext, tag].map((part) => part.toString("base64url")).join(".");
|
|
72099
|
+
function createRunId(random = randomBytes7) {
|
|
72100
|
+
return `run_${Buffer.from(random(12)).toString("hex")}`;
|
|
71911
72101
|
}
|
|
71912
|
-
|
|
71913
|
-
|
|
71914
|
-
|
|
71915
|
-
|
|
71916
|
-
|
|
71917
|
-
|
|
71918
|
-
|
|
72102
|
+
var runRefSchema = external_exports.strictObject({
|
|
72103
|
+
id: external_exports.string().regex(RUN_ID_PATTERN),
|
|
72104
|
+
swarm: external_exports.string().optional(),
|
|
72105
|
+
member: external_exports.string().optional(),
|
|
72106
|
+
parentRunId: external_exports.string().optional()
|
|
72107
|
+
});
|
|
72108
|
+
|
|
72109
|
+
// ../core/src/receipts.ts
|
|
72110
|
+
var receiptTestHooks;
|
|
72111
|
+
function __setReceiptTestHooks(hooks) {
|
|
72112
|
+
receiptTestHooks = hooks;
|
|
71919
72113
|
}
|
|
71920
|
-
|
|
71921
|
-
|
|
71922
|
-
|
|
71923
|
-
|
|
71924
|
-
|
|
71925
|
-
cause: error61
|
|
71926
|
-
});
|
|
71927
|
-
}
|
|
72114
|
+
var RECEIPT_JOURNAL_BUSY_MESSAGE = "The receipt journal is busy. Wait for the other vapi command to finish, then retry.";
|
|
72115
|
+
async function withReceiptJournalLock(path, operation) {
|
|
72116
|
+
return await withFileLock(`${path}.lock`, operation, {
|
|
72117
|
+
lockedMessage: RECEIPT_JOURNAL_BUSY_MESSAGE
|
|
72118
|
+
});
|
|
71928
72119
|
}
|
|
71929
|
-
|
|
71930
|
-
|
|
71931
|
-
|
|
71932
|
-
|
|
71933
|
-
|
|
71934
|
-
|
|
71935
|
-
|
|
72120
|
+
var durationSchema = external_exports.number().nonnegative().finite();
|
|
72121
|
+
var receiptSchema = external_exports.strictObject({
|
|
72122
|
+
id: external_exports.string().min(1),
|
|
72123
|
+
timestamp: external_exports.iso.datetime(),
|
|
72124
|
+
run: runRefSchema.optional(),
|
|
72125
|
+
kind: external_exports.literal("transfer").optional(),
|
|
72126
|
+
wallet: walletNameSchema.optional(),
|
|
72127
|
+
resourceUrl: external_exports.url(),
|
|
72128
|
+
method: external_exports.string().min(1).optional(),
|
|
72129
|
+
source: external_exports.string().min(1).optional(),
|
|
72130
|
+
provenance: external_exports.array(
|
|
72131
|
+
external_exports.strictObject({
|
|
72132
|
+
source: external_exports.string().min(1),
|
|
72133
|
+
sourceUrl: external_exports.string().optional(),
|
|
72134
|
+
ref: external_exports.string().optional()
|
|
72135
|
+
})
|
|
72136
|
+
).optional(),
|
|
72137
|
+
quote: external_exports.strictObject({
|
|
72138
|
+
network: external_exports.string(),
|
|
72139
|
+
asset: external_exports.string().optional(),
|
|
72140
|
+
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
72141
|
+
payTo: external_exports.string().optional()
|
|
72142
|
+
}).optional(),
|
|
72143
|
+
payer: external_exports.string().optional(),
|
|
72144
|
+
paymentId: external_exports.string().regex(/^[A-Za-z0-9_-]{16,128}$/).optional(),
|
|
72145
|
+
authorization: external_exports.strictObject({
|
|
72146
|
+
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
72147
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
72148
|
+
validBefore: external_exports.string().regex(/^\d+$/)
|
|
72149
|
+
}).optional(),
|
|
72150
|
+
transfer: external_exports.strictObject({
|
|
72151
|
+
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
72152
|
+
toName: external_exports.string().min(1),
|
|
72153
|
+
toKind: external_exports.enum(["owner", "account"]),
|
|
72154
|
+
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
72155
|
+
network: external_exports.string().min(1),
|
|
72156
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/),
|
|
72157
|
+
status: external_exports.enum(["sent", "unknown", "failed"]),
|
|
72158
|
+
txHash: external_exports.string().regex(/^0x[0-9a-fA-F]+$/).nullable(),
|
|
72159
|
+
replayed: external_exports.boolean(),
|
|
72160
|
+
reservedOn: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(),
|
|
72161
|
+
request: external_exports.strictObject({
|
|
72162
|
+
authorization: external_exports.strictObject({
|
|
72163
|
+
from: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
72164
|
+
to: external_exports.string().regex(/^0x[0-9a-fA-F]{40}$/),
|
|
72165
|
+
value: external_exports.string().regex(/^\d+$/),
|
|
72166
|
+
validAfter: external_exports.string().regex(/^\d+$/),
|
|
72167
|
+
validBefore: external_exports.string().regex(/^\d+$/),
|
|
72168
|
+
nonce: external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/)
|
|
72169
|
+
}),
|
|
72170
|
+
signature: external_exports.string().regex(/^0x[0-9a-fA-F]+$/)
|
|
72171
|
+
}).optional()
|
|
72172
|
+
}).optional(),
|
|
72173
|
+
settlement: external_exports.strictObject({
|
|
72174
|
+
outcome: external_exports.enum(["succeeded", "rejected", "unknown"]),
|
|
72175
|
+
transaction: external_exports.string().optional(),
|
|
72176
|
+
explorerUrl: external_exports.url().optional(),
|
|
72177
|
+
evidence: external_exports.unknown().optional()
|
|
72178
|
+
}).optional(),
|
|
72179
|
+
latencyMs: external_exports.number().nonnegative().finite().optional(),
|
|
72180
|
+
status: external_exports.number().int().min(100).max(599).optional(),
|
|
72181
|
+
error: external_exports.strictObject({ code: external_exports.string(), message: external_exports.string() }).optional(),
|
|
72182
|
+
phases: external_exports.strictObject({
|
|
72183
|
+
discoverMs: durationSchema.optional(),
|
|
72184
|
+
quoteMs: durationSchema.optional(),
|
|
72185
|
+
signMs: durationSchema.optional(),
|
|
72186
|
+
requestMs: durationSchema.optional(),
|
|
72187
|
+
settleMs: durationSchema.optional()
|
|
72188
|
+
}).optional(),
|
|
72189
|
+
listing: external_exports.strictObject({
|
|
72190
|
+
name: external_exports.string().min(1).optional(),
|
|
72191
|
+
providerHost: external_exports.string().min(1).optional(),
|
|
72192
|
+
source: external_exports.string().min(1)
|
|
72193
|
+
}).optional(),
|
|
72194
|
+
retry: external_exports.number().int().nonnegative().optional(),
|
|
72195
|
+
policy: external_exports.strictObject({
|
|
72196
|
+
maxPriceUsd: external_exports.string().regex(/^\d+(?:\.\d{1,6})?$/).optional(),
|
|
72197
|
+
capsApplied: external_exports.boolean()
|
|
72198
|
+
}).optional(),
|
|
72199
|
+
client: external_exports.strictObject({ name: external_exports.literal("vapi-network"), version: external_exports.string().min(1) }).optional(),
|
|
72200
|
+
outcome: external_exports.enum([
|
|
72201
|
+
"paid",
|
|
72202
|
+
"signed_in",
|
|
72203
|
+
"declined_policy",
|
|
72204
|
+
"failed_request",
|
|
72205
|
+
"settlement_rejected",
|
|
72206
|
+
"settlement_unknown"
|
|
72207
|
+
]).optional()
|
|
72208
|
+
});
|
|
72209
|
+
function parseReceipt(value) {
|
|
72210
|
+
const receipt = receiptSchema.parse(value);
|
|
72211
|
+
const transaction2 = receipt.settlement?.transaction;
|
|
72212
|
+
const network = receipt.quote?.network;
|
|
72213
|
+
const explorerUrl = transaction2 === void 0 || network === void 0 ? void 0 : explorerTransactionUrl(network, transaction2);
|
|
72214
|
+
if (explorerUrl === void 0 || receipt.settlement?.explorerUrl === explorerUrl) {
|
|
72215
|
+
return receipt;
|
|
71936
72216
|
}
|
|
71937
|
-
|
|
71938
|
-
|
|
71939
|
-
|
|
71940
|
-
|
|
71941
|
-
|
|
71942
|
-
|
|
71943
|
-
|
|
71944
|
-
}
|
|
71945
|
-
let address4;
|
|
71946
|
-
try {
|
|
71947
|
-
address4 = privateKeyToAccount(`0x${plaintext.toString("hex")}`).address;
|
|
71948
|
-
} catch (error61) {
|
|
71949
|
-
throw new VaultError("bad_key", "The stored imported key is not valid.", {
|
|
71950
|
-
cause: error61
|
|
71951
|
-
});
|
|
71952
|
-
}
|
|
71953
|
-
if (address4.toLowerCase() !== account.address.toLowerCase()) {
|
|
71954
|
-
throw new VaultError("bad_key", "The stored imported key does not match its address.");
|
|
72217
|
+
return {
|
|
72218
|
+
...receipt,
|
|
72219
|
+
settlement: {
|
|
72220
|
+
outcome: receipt.settlement.outcome,
|
|
72221
|
+
...receipt.settlement.transaction ? { transaction: receipt.settlement.transaction } : {},
|
|
72222
|
+
explorerUrl,
|
|
72223
|
+
...receipt.settlement.evidence === void 0 ? {} : { evidence: receipt.settlement.evidence }
|
|
71955
72224
|
}
|
|
71956
|
-
}
|
|
71957
|
-
plaintext?.fill(0);
|
|
71958
|
-
}
|
|
72225
|
+
};
|
|
71959
72226
|
}
|
|
71960
|
-
function
|
|
71961
|
-
const
|
|
71962
|
-
|
|
71963
|
-
|
|
71964
|
-
|
|
71965
|
-
|
|
71966
|
-
|
|
71967
|
-
|
|
71968
|
-
|
|
71969
|
-
|
|
72227
|
+
async function appendReceipt(receipt, path = getVapiPaths().receipts, options = {}) {
|
|
72228
|
+
const parsed = parseReceipt(
|
|
72229
|
+
receipt.wallet === void 0 && options.wallet !== void 0 ? { ...receipt, wallet: options.wallet } : receipt
|
|
72230
|
+
);
|
|
72231
|
+
await withReceiptJournalLock(path, async () => {
|
|
72232
|
+
await mkdir8(dirname6(path), { recursive: true, mode: 448 });
|
|
72233
|
+
const handle = await open7(path, "a", 384);
|
|
72234
|
+
try {
|
|
72235
|
+
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
72236
|
+
`, "utf8");
|
|
72237
|
+
} finally {
|
|
72238
|
+
await handle.close();
|
|
71970
72239
|
}
|
|
71971
|
-
}
|
|
71972
|
-
|
|
71973
|
-
plaintext.fill(0);
|
|
71974
|
-
}
|
|
72240
|
+
});
|
|
72241
|
+
return parsed;
|
|
71975
72242
|
}
|
|
71976
|
-
function
|
|
71977
|
-
let
|
|
72243
|
+
async function readReceipts(path = getVapiPaths().receipts, options = {}) {
|
|
72244
|
+
let raw;
|
|
71978
72245
|
try {
|
|
71979
|
-
|
|
72246
|
+
raw = await readFile9(path, "utf8");
|
|
71980
72247
|
} catch (error61) {
|
|
71981
|
-
|
|
71982
|
-
|
|
71983
|
-
const parsed = vaultFileSchema.safeParse(value);
|
|
71984
|
-
if (!parsed.success) {
|
|
71985
|
-
throw new VaultError("corrupt", "The vault file has an invalid structure.", {
|
|
71986
|
-
cause: parsed.error
|
|
71987
|
-
});
|
|
71988
|
-
}
|
|
71989
|
-
if (parsed.data.protected !== (parsed.data.wrappedKey !== void 0)) {
|
|
71990
|
-
throw new VaultError("corrupt", "The vault protection metadata is inconsistent.");
|
|
72248
|
+
if (isMissingFile(error61)) return [];
|
|
72249
|
+
throw error61;
|
|
71991
72250
|
}
|
|
71992
|
-
const
|
|
71993
|
-
|
|
71994
|
-
|
|
71995
|
-
|
|
71996
|
-
|
|
71997
|
-
|
|
71998
|
-
names.add(account.name);
|
|
71999
|
-
if (account.kind === "derived") {
|
|
72000
|
-
if (indexes.has(account.index)) {
|
|
72001
|
-
throw new VaultError("corrupt", "The vault file contains duplicate derived indexes.");
|
|
72251
|
+
const records = coalesceTransferReceiptRevisions(
|
|
72252
|
+
raw.split("\n").filter((line) => line.trim().length > 0).map((line, index2) => {
|
|
72253
|
+
try {
|
|
72254
|
+
return parseReceipt(JSON.parse(line));
|
|
72255
|
+
} catch (error61) {
|
|
72256
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
72002
72257
|
}
|
|
72003
|
-
|
|
72258
|
+
})
|
|
72259
|
+
);
|
|
72260
|
+
const filtered = options.wallet === void 0 ? records : filterReceiptsByWallet(records, options.wallet);
|
|
72261
|
+
const limit = options.limit;
|
|
72262
|
+
if (limit === void 0) return filtered;
|
|
72263
|
+
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
72264
|
+
throw new Error("Receipt limit must be a non-negative integer.");
|
|
72265
|
+
return limit === 0 ? [] : filtered.slice(-limit);
|
|
72266
|
+
}
|
|
72267
|
+
function coalesceTransferReceiptRevisions(receipts) {
|
|
72268
|
+
const coalesced = [];
|
|
72269
|
+
const transferIndexes = /* @__PURE__ */ new Map();
|
|
72270
|
+
for (const receipt of receipts) {
|
|
72271
|
+
const existing = receipt.kind === "transfer" ? transferIndexes.get(receipt.id) : void 0;
|
|
72272
|
+
if (existing === void 0) {
|
|
72273
|
+
if (receipt.kind === "transfer") transferIndexes.set(receipt.id, coalesced.length);
|
|
72274
|
+
coalesced.push(receipt);
|
|
72275
|
+
} else {
|
|
72276
|
+
coalesced[existing] = receipt;
|
|
72004
72277
|
}
|
|
72005
72278
|
}
|
|
72006
|
-
return
|
|
72279
|
+
return coalesced;
|
|
72007
72280
|
}
|
|
72008
|
-
|
|
72009
|
-
|
|
72010
|
-
|
|
72011
|
-
|
|
72281
|
+
function receiptWallet(receipt) {
|
|
72282
|
+
return receipt.wallet ?? DEFAULT_WALLET_NAME;
|
|
72283
|
+
}
|
|
72284
|
+
function filterReceiptsByWallet(receipts, name) {
|
|
72285
|
+
return receipts.filter((receipt) => receiptWallet(receipt) === name);
|
|
72286
|
+
}
|
|
72287
|
+
async function renameReceiptWallet(from16, to, path = getVapiPaths().receipts) {
|
|
72288
|
+
return await withReceiptJournalLock(path, async () => {
|
|
72289
|
+
let raw;
|
|
72012
72290
|
try {
|
|
72013
|
-
|
|
72291
|
+
raw = await readFile9(path, "utf8");
|
|
72014
72292
|
} catch (error61) {
|
|
72015
|
-
|
|
72016
|
-
|
|
72017
|
-
});
|
|
72018
|
-
}
|
|
72019
|
-
} finally {
|
|
72020
|
-
plaintext.fill(0);
|
|
72021
|
-
}
|
|
72022
|
-
return file2;
|
|
72023
|
-
}
|
|
72024
|
-
async function readVaultFileUnlocked(path) {
|
|
72025
|
-
let raw;
|
|
72026
|
-
try {
|
|
72027
|
-
raw = await readFile9(path, "utf8");
|
|
72028
|
-
} catch (error61) {
|
|
72029
|
-
if (isMissingFile2(error61)) {
|
|
72030
|
-
throw new VaultError("not_found", "No vault file was found at the requested path.", {
|
|
72031
|
-
cause: error61
|
|
72032
|
-
});
|
|
72293
|
+
if (isMissingFile(error61)) return 0;
|
|
72294
|
+
throw error61;
|
|
72033
72295
|
}
|
|
72034
|
-
|
|
72035
|
-
|
|
72036
|
-
|
|
72037
|
-
|
|
72038
|
-
|
|
72039
|
-
|
|
72040
|
-
|
|
72041
|
-
|
|
72042
|
-
|
|
72043
|
-
|
|
72044
|
-
|
|
72296
|
+
let changed = 0;
|
|
72297
|
+
const lines = raw.split("\n").map((line, index2) => {
|
|
72298
|
+
if (line.trim().length === 0) return line;
|
|
72299
|
+
let parsed;
|
|
72300
|
+
try {
|
|
72301
|
+
parsed = JSON.parse(line);
|
|
72302
|
+
} catch (error61) {
|
|
72303
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
72304
|
+
}
|
|
72305
|
+
const current = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "wallet") : void 0;
|
|
72306
|
+
if ((typeof current === "string" ? current : DEFAULT_WALLET_NAME) !== from16) return line;
|
|
72307
|
+
changed += 1;
|
|
72308
|
+
return JSON.stringify(parseReceipt({ ...parsed, wallet: to }));
|
|
72045
72309
|
});
|
|
72046
|
-
|
|
72047
|
-
|
|
72048
|
-
}
|
|
72049
|
-
|
|
72050
|
-
|
|
72051
|
-
const temporaryPath = `${path}.${process.pid}.${randomBytes7(6).toString("hex")}.tmp`;
|
|
72052
|
-
try {
|
|
72053
|
-
await writeFile4(temporaryPath, `${JSON.stringify(file2, null, 2)}
|
|
72054
|
-
`, {
|
|
72310
|
+
if (changed === 0) return 0;
|
|
72311
|
+
await receiptTestHooks?.beforeRenameReplace?.(path);
|
|
72312
|
+
await mkdir8(dirname6(path), { recursive: true, mode: 448 });
|
|
72313
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes8(6).toString("hex")}.tmp`;
|
|
72314
|
+
await writeFile4(temporaryPath, lines.join("\n"), {
|
|
72055
72315
|
encoding: "utf8",
|
|
72056
72316
|
mode: 384,
|
|
72057
72317
|
flag: "wx"
|
|
72058
72318
|
});
|
|
72059
72319
|
await rename5(temporaryPath, path);
|
|
72320
|
+
return changed;
|
|
72321
|
+
});
|
|
72322
|
+
}
|
|
72323
|
+
|
|
72324
|
+
// ../core/src/transfer-journal.ts
|
|
72325
|
+
import { readFile as readFile10 } from "node:fs/promises";
|
|
72326
|
+
async function readTransferJournal(home, from16, nonce) {
|
|
72327
|
+
let raw;
|
|
72328
|
+
try {
|
|
72329
|
+
raw = await readFile10(getVapiPaths(home).receipts, "utf8");
|
|
72060
72330
|
} catch (error61) {
|
|
72061
|
-
|
|
72331
|
+
if (isMissingFile(error61)) return { signed: false };
|
|
72062
72332
|
throw error61;
|
|
72063
72333
|
}
|
|
72064
|
-
|
|
72065
|
-
|
|
72066
|
-
|
|
72067
|
-
|
|
72068
|
-
|
|
72069
|
-
let handle;
|
|
72070
|
-
while (!handle) {
|
|
72334
|
+
let latest;
|
|
72335
|
+
let request;
|
|
72336
|
+
for (const [index2, line] of raw.split("\n").entries()) {
|
|
72337
|
+
if (!line.trim()) continue;
|
|
72338
|
+
let receipt;
|
|
72071
72339
|
try {
|
|
72072
|
-
|
|
72340
|
+
receipt = parseReceipt(JSON.parse(line));
|
|
72073
72341
|
} catch (error61) {
|
|
72074
|
-
|
|
72075
|
-
await removeStaleVaultLock(lockPath);
|
|
72076
|
-
if (Date.now() >= deadline) {
|
|
72077
|
-
throw new VaultError("corrupt", "Timed out waiting for the vault lock.");
|
|
72078
|
-
}
|
|
72079
|
-
await new Promise((resolve4) => setTimeout(resolve4, 20));
|
|
72342
|
+
throw new Error(`Invalid receipt on JSONL line ${index2 + 1}.`, { cause: error61 });
|
|
72080
72343
|
}
|
|
72344
|
+
if (receiptWallet(receipt) !== from16 || receipt.transfer?.nonce.toLowerCase() !== nonce.toLowerCase()) {
|
|
72345
|
+
continue;
|
|
72346
|
+
}
|
|
72347
|
+
latest = receipt;
|
|
72348
|
+
if (receipt.transfer.request !== void 0) request = receipt;
|
|
72081
72349
|
}
|
|
72082
|
-
|
|
72083
|
-
|
|
72084
|
-
|
|
72085
|
-
|
|
72086
|
-
|
|
72087
|
-
|
|
72088
|
-
}
|
|
72089
|
-
async function removeStaleVaultLock(path) {
|
|
72090
|
-
try {
|
|
72091
|
-
const metadata = await stat6(path);
|
|
72092
|
-
if (Date.now() - metadata.mtimeMs > STALE_VAULT_LOCK_MS) await unlink4(path);
|
|
72093
|
-
} catch (error61) {
|
|
72094
|
-
if (!isMissingFile2(error61)) throw error61;
|
|
72095
|
-
}
|
|
72096
|
-
}
|
|
72097
|
-
function isMissingFile2(error61) {
|
|
72098
|
-
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "ENOENT";
|
|
72099
|
-
}
|
|
72100
|
-
function isExistingFile(error61) {
|
|
72101
|
-
return typeof error61 === "object" && error61 !== null && "code" in error61 && Reflect.get(error61, "code") === "EEXIST";
|
|
72102
|
-
}
|
|
72103
|
-
function asVaultError(error61, code, message) {
|
|
72104
|
-
return error61 instanceof VaultError ? error61 : new VaultError(code, message, { cause: error61 });
|
|
72350
|
+
return {
|
|
72351
|
+
signed: latest !== void 0,
|
|
72352
|
+
...latest === void 0 ? {} : { latest },
|
|
72353
|
+
...request === void 0 ? {} : { request },
|
|
72354
|
+
...request?.transfer?.request?.authorization.validBefore === void 0 ? {} : { validBefore: request.transfer.request.authorization.validBefore },
|
|
72355
|
+
...(latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn) === void 0 ? {} : { reservedOn: latest?.transfer?.reservedOn ?? request?.transfer?.reservedOn }
|
|
72356
|
+
};
|
|
72105
72357
|
}
|
|
72106
72358
|
|
|
72107
72359
|
// ../core/src/vault-key.ts
|
|
72360
|
+
import { randomBytes as cryptoRandomBytes } from "node:crypto";
|
|
72108
72361
|
var VAULT_KEY_ACCOUNT = "vault-key";
|
|
72109
72362
|
var VAULT_SESSION_ACCOUNT = "vault-session";
|
|
72110
72363
|
var DEVICE_KEY_LENGTH = 32;
|
|
@@ -72126,7 +72379,7 @@ async function loadOrCreateDeviceKey(args) {
|
|
|
72126
72379
|
await args.secrets.set(VAULT_KEY_ACCOUNT, key2.toString("base64"));
|
|
72127
72380
|
return key2;
|
|
72128
72381
|
} catch (error61) {
|
|
72129
|
-
throw asVaultError2(error61,
|
|
72382
|
+
throw asVaultError2(error61, deviceKeyFailureMessage(error61, args.secrets.platform));
|
|
72130
72383
|
}
|
|
72131
72384
|
});
|
|
72132
72385
|
}
|
|
@@ -72332,8 +72585,8 @@ function passwordRequiredError() {
|
|
|
72332
72585
|
"A vault password is needed. Pass it or set VAPI_VAULT_PASSWORD."
|
|
72333
72586
|
);
|
|
72334
72587
|
}
|
|
72335
|
-
function randomKeyBytes(
|
|
72336
|
-
const key2 = Buffer.from((
|
|
72588
|
+
function randomKeyBytes(randomBytes18) {
|
|
72589
|
+
const key2 = Buffer.from((randomBytes18 ?? cryptoRandomBytes)(DEVICE_KEY_LENGTH));
|
|
72337
72590
|
if (key2.byteLength !== DEVICE_KEY_LENGTH) {
|
|
72338
72591
|
key2.fill(0);
|
|
72339
72592
|
throw new VaultError("corrupt", "A generated device vault key has the wrong length.");
|
|
@@ -72384,25 +72637,31 @@ function parseJson(value) {
|
|
|
72384
72637
|
function asVaultError2(error61, message) {
|
|
72385
72638
|
return error61 instanceof VaultError ? error61 : new VaultError("corrupt", message, { cause: error61 });
|
|
72386
72639
|
}
|
|
72640
|
+
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.";
|
|
72641
|
+
function deviceKeyFailureMessage(error61, platform2) {
|
|
72642
|
+
if (!(error61 instanceof KeystoreError)) return "Unable to load or create the device vault key.";
|
|
72643
|
+
const detail = `Unable to load or create the device vault key: ${error61.message.replace(/\.$/u, "")}.`;
|
|
72644
|
+
return platform2 === "linux" ? `${detail} ${HEADLESS_LINUX_HINT}` : detail;
|
|
72645
|
+
}
|
|
72387
72646
|
|
|
72388
72647
|
// ../core/src/vault-migrate.ts
|
|
72389
72648
|
import {
|
|
72390
72649
|
chmod as chmod2,
|
|
72391
72650
|
lstat,
|
|
72392
72651
|
mkdir as mkdir9,
|
|
72393
|
-
readFile as
|
|
72652
|
+
readFile as readFile11,
|
|
72394
72653
|
readlink,
|
|
72395
72654
|
readdir as readdir2,
|
|
72396
72655
|
rename as rename6,
|
|
72397
72656
|
symlink,
|
|
72398
72657
|
unlink as unlink5
|
|
72399
72658
|
} from "node:fs/promises";
|
|
72400
|
-
import { join as
|
|
72659
|
+
import { join as join8, resolve } from "node:path";
|
|
72401
72660
|
var MIGRATED_DIRECTORY = "wallets.migrated";
|
|
72402
72661
|
async function legacyKeystoreNames(home) {
|
|
72403
72662
|
let entries;
|
|
72404
72663
|
try {
|
|
72405
|
-
entries = await readdir2(
|
|
72664
|
+
entries = await readdir2(join8(home, "wallets"), { withFileTypes: true });
|
|
72406
72665
|
} catch (error61) {
|
|
72407
72666
|
if (isMissingFile(error61)) return [];
|
|
72408
72667
|
throw error61;
|
|
@@ -72418,14 +72677,14 @@ async function migrateKeystores(args) {
|
|
|
72418
72677
|
);
|
|
72419
72678
|
const result = { imported: [], skipped: [] };
|
|
72420
72679
|
for (const name of names) {
|
|
72421
|
-
const source =
|
|
72680
|
+
const source = join8(args.home, "wallets", `${name}.json`);
|
|
72422
72681
|
if (args.vault.accounts().some((account) => account.name === name)) {
|
|
72423
72682
|
result.skipped.push({ name, reason: "name_taken" });
|
|
72424
72683
|
continue;
|
|
72425
72684
|
}
|
|
72426
72685
|
let parsed;
|
|
72427
72686
|
try {
|
|
72428
|
-
parsed = parseAnyKeystore(JSON.parse(await
|
|
72687
|
+
parsed = parseAnyKeystore(JSON.parse(await readFile11(source, "utf8")));
|
|
72429
72688
|
} catch {
|
|
72430
72689
|
result.skipped.push({ name, reason: "unreadable" });
|
|
72431
72690
|
continue;
|
|
@@ -72455,15 +72714,15 @@ async function migrateKeystores(args) {
|
|
|
72455
72714
|
if (imported.address.toLowerCase() !== parsed.address.toLowerCase()) {
|
|
72456
72715
|
throw new KeystoreError(`Migrated wallet ${name} does not match its stored address.`);
|
|
72457
72716
|
}
|
|
72458
|
-
const migratedDirectory =
|
|
72459
|
-
const destination =
|
|
72717
|
+
const migratedDirectory = join8(args.home, MIGRATED_DIRECTORY);
|
|
72718
|
+
const destination = join8(migratedDirectory, `${name}.json`);
|
|
72460
72719
|
await mkdir9(migratedDirectory, { recursive: true, mode: 448 });
|
|
72461
72720
|
await archiveExistingDestination(destination, migratedDirectory, name, now);
|
|
72462
72721
|
await rename6(source, destination);
|
|
72463
72722
|
await chmod2(destination, 384);
|
|
72464
72723
|
try {
|
|
72465
72724
|
await removeCompatibilityLink(args.home, source);
|
|
72466
|
-
await symlink(
|
|
72725
|
+
await symlink(join8("..", MIGRATED_DIRECTORY, `${name}.json`), source);
|
|
72467
72726
|
await audit({
|
|
72468
72727
|
event: "vault.migrate",
|
|
72469
72728
|
wallet: name,
|
|
@@ -72491,16 +72750,16 @@ async function migrateKeystores(args) {
|
|
|
72491
72750
|
async function archiveExistingDestination(destination, directory, name, now) {
|
|
72492
72751
|
if (!await pathExists2(destination)) return;
|
|
72493
72752
|
const timestamp = now().toISOString();
|
|
72494
|
-
let archive =
|
|
72753
|
+
let archive = join8(directory, `${name}.${timestamp}.json`);
|
|
72495
72754
|
let suffix = 1;
|
|
72496
72755
|
while (await pathExists2(archive)) {
|
|
72497
|
-
archive =
|
|
72756
|
+
archive = join8(directory, `${name}.${timestamp}.${suffix}.json`);
|
|
72498
72757
|
suffix += 1;
|
|
72499
72758
|
}
|
|
72500
72759
|
await rename6(destination, archive);
|
|
72501
72760
|
}
|
|
72502
72761
|
async function removeCompatibilityLink(home, migratedSource) {
|
|
72503
|
-
const compatibilityPath =
|
|
72762
|
+
const compatibilityPath = join8(home, "keystore.json");
|
|
72504
72763
|
let metadata;
|
|
72505
72764
|
try {
|
|
72506
72765
|
metadata = await lstat(compatibilityPath);
|
|
@@ -72574,7 +72833,7 @@ var WalletStore = class _WalletStore {
|
|
|
72574
72833
|
this.home = home;
|
|
72575
72834
|
this.options = options;
|
|
72576
72835
|
this.registry = registry2;
|
|
72577
|
-
this.secrets = options.secrets ?? secretStore();
|
|
72836
|
+
this.secrets = options.secrets ?? secretStore({ home });
|
|
72578
72837
|
this.environment = options.env ?? process.env;
|
|
72579
72838
|
this.passphraseResolver = options.resolvePassphrase ?? defaultPassphraseResolver(this.environment, this.secrets);
|
|
72580
72839
|
this.audit = options.audit ?? (async (record2) => await appendAudit(this.home, record2, { now: () => this.now() }));
|
|
@@ -72621,17 +72880,17 @@ var WalletStore = class _WalletStore {
|
|
|
72621
72880
|
return store;
|
|
72622
72881
|
}
|
|
72623
72882
|
get registryPath() {
|
|
72624
|
-
return
|
|
72883
|
+
return join9(this.home, REGISTRY_FILE);
|
|
72625
72884
|
}
|
|
72626
72885
|
get walletsDirectory() {
|
|
72627
|
-
return
|
|
72886
|
+
return join9(this.home, WALLETS_DIRECTORY);
|
|
72628
72887
|
}
|
|
72629
72888
|
get trashDirectory() {
|
|
72630
|
-
return
|
|
72889
|
+
return join9(this.walletsDirectory, TRASH_DIRECTORY);
|
|
72631
72890
|
}
|
|
72632
72891
|
/** The legacy 0.5 keystore path of a wallet, whether or not it exists. */
|
|
72633
72892
|
pathFor(name) {
|
|
72634
|
-
return
|
|
72893
|
+
return join9(this.walletsDirectory, `${assertWalletName(name)}.json`);
|
|
72635
72894
|
}
|
|
72636
72895
|
/** The names this machine knows, in registry order. */
|
|
72637
72896
|
names() {
|
|
@@ -73204,7 +73463,7 @@ var WalletStore = class _WalletStore {
|
|
|
73204
73463
|
}
|
|
73205
73464
|
const removedAt = this.now().toISOString();
|
|
73206
73465
|
await mkdir10(this.trashDirectory, { recursive: true, mode: 448 });
|
|
73207
|
-
const trashedPath =
|
|
73466
|
+
const trashedPath = join9(this.trashDirectory, `${wallet.name}-${removedAt}.json`);
|
|
73208
73467
|
const storedAccount = (await this.readVaultUnlocked())?.accounts.find(
|
|
73209
73468
|
(candidate) => candidate.name === wallet.name
|
|
73210
73469
|
);
|
|
@@ -73226,7 +73485,7 @@ var WalletStore = class _WalletStore {
|
|
|
73226
73485
|
this.balanceProbe = void 0;
|
|
73227
73486
|
}
|
|
73228
73487
|
if (await pathExists3(wallet.path)) {
|
|
73229
|
-
const legacyTrashedPath =
|
|
73488
|
+
const legacyTrashedPath = join9(
|
|
73230
73489
|
this.trashDirectory,
|
|
73231
73490
|
`${wallet.name}-${removedAt}.legacy.json`
|
|
73232
73491
|
);
|
|
@@ -73316,7 +73575,7 @@ var WalletStore = class _WalletStore {
|
|
|
73316
73575
|
if (!match) continue;
|
|
73317
73576
|
const [, name, removedAt] = match;
|
|
73318
73577
|
if (name === void 0 || removedAt === void 0 || !isWalletName(name)) continue;
|
|
73319
|
-
const path =
|
|
73578
|
+
const path = join9(this.trashDirectory, file2);
|
|
73320
73579
|
const entry = await readEntrySidecar(entrySidecarPath(path));
|
|
73321
73580
|
trashed.push({ name, removedAt, path, ...entry ? { entry } : {} });
|
|
73322
73581
|
}
|
|
@@ -73385,7 +73644,7 @@ var WalletStore = class _WalletStore {
|
|
|
73385
73644
|
return entry;
|
|
73386
73645
|
}
|
|
73387
73646
|
get vaultPath() {
|
|
73388
|
-
return
|
|
73647
|
+
return join9(this.home, VAULT_FILE);
|
|
73389
73648
|
}
|
|
73390
73649
|
async readVaultUnlocked() {
|
|
73391
73650
|
try {
|
|
@@ -73490,7 +73749,7 @@ var WalletStore = class _WalletStore {
|
|
|
73490
73749
|
async readRegistry() {
|
|
73491
73750
|
let raw;
|
|
73492
73751
|
try {
|
|
73493
|
-
raw = await
|
|
73752
|
+
raw = await readFile12(this.registryPath, "utf8");
|
|
73494
73753
|
} catch (error61) {
|
|
73495
73754
|
if (isMissingFile(error61)) return emptyRegistry();
|
|
73496
73755
|
throw error61;
|
|
@@ -73511,7 +73770,7 @@ var WalletStore = class _WalletStore {
|
|
|
73511
73770
|
}
|
|
73512
73771
|
};
|
|
73513
73772
|
async function swarmReferencingAccount(home, account) {
|
|
73514
|
-
const directory =
|
|
73773
|
+
const directory = join9(home, "swarms");
|
|
73515
73774
|
let files;
|
|
73516
73775
|
try {
|
|
73517
73776
|
files = await readdir3(directory);
|
|
@@ -73522,7 +73781,7 @@ async function swarmReferencingAccount(home, account) {
|
|
|
73522
73781
|
for (const file2 of files.filter((name) => name.endsWith(".json")).sort()) {
|
|
73523
73782
|
let value;
|
|
73524
73783
|
try {
|
|
73525
|
-
value = JSON.parse(await
|
|
73784
|
+
value = JSON.parse(await readFile12(join9(directory, file2), "utf8"));
|
|
73526
73785
|
} catch {
|
|
73527
73786
|
throw new KeystoreError(
|
|
73528
73787
|
`Cannot verify swarm references because ${file2} is invalid. Repair or remove that swarm file before renaming an account.`
|
|
@@ -73554,7 +73813,7 @@ async function swarmReferencingAccount(home, account) {
|
|
|
73554
73813
|
return void 0;
|
|
73555
73814
|
}
|
|
73556
73815
|
async function unfinishedMovementReferencingAccount(home, account) {
|
|
73557
|
-
const directory =
|
|
73816
|
+
const directory = join9(home, "movements");
|
|
73558
73817
|
let files;
|
|
73559
73818
|
try {
|
|
73560
73819
|
files = await readdir3(directory);
|
|
@@ -73565,7 +73824,7 @@ async function unfinishedMovementReferencingAccount(home, account) {
|
|
|
73565
73824
|
for (const file2 of files.filter((name) => name.endsWith(".json")).sort()) {
|
|
73566
73825
|
let value;
|
|
73567
73826
|
try {
|
|
73568
|
-
value = JSON.parse(await
|
|
73827
|
+
value = JSON.parse(await readFile12(join9(directory, file2), "utf8"));
|
|
73569
73828
|
} catch {
|
|
73570
73829
|
throw invalidMovementReferenceError(file2);
|
|
73571
73830
|
}
|
|
@@ -73586,11 +73845,11 @@ async function unfinishedMovementReferencingAccount(home, account) {
|
|
|
73586
73845
|
const restored = Reflect.get(leg, "restored");
|
|
73587
73846
|
const legFrom = Reflect.get(leg, "from") ?? movementFrom;
|
|
73588
73847
|
const journal = restored !== true && status === "failed" && retryable !== true && typeof nonce === "string" ? await readTransferJournal(home, legFrom, nonce) : void 0;
|
|
73589
|
-
const
|
|
73848
|
+
const open13 = isOpenMovementLeg(
|
|
73590
73849
|
{ status, retryable, nonce, restored },
|
|
73591
73850
|
journal?.signed === true ? "signed" : "unsigned"
|
|
73592
73851
|
);
|
|
73593
|
-
if (
|
|
73852
|
+
if (open13) movementOpen = true;
|
|
73594
73853
|
}
|
|
73595
73854
|
if (movementOpen && (movementFrom === account || legs.some(
|
|
73596
73855
|
(leg) => (Reflect.get(leg, "from") ?? movementFrom) === account || Reflect.get(leg, "to") === account
|
|
@@ -73626,7 +73885,7 @@ async function withAccountMutationLocks(home, accounts, command, operation) {
|
|
|
73626
73885
|
const [account, ...remaining2] = [...new Set(accounts)].sort();
|
|
73627
73886
|
if (account === void 0) return await operation();
|
|
73628
73887
|
return await withFileLock(
|
|
73629
|
-
|
|
73888
|
+
join9(home, `.account-${account}.lock`),
|
|
73630
73889
|
async () => await withAccountMutationLocks(home, remaining2, command, operation),
|
|
73631
73890
|
{
|
|
73632
73891
|
lockedMessage: `Account ${account} is busy with another account change. Wait for it to finish, then retry ${command}.`
|
|
@@ -73701,7 +73960,7 @@ function isLockedVaultError(error61) {
|
|
|
73701
73960
|
async function readTrashedVaultAccount(path) {
|
|
73702
73961
|
let parsed;
|
|
73703
73962
|
try {
|
|
73704
|
-
parsed = JSON.parse(await
|
|
73963
|
+
parsed = JSON.parse(await readFile12(path, "utf8"));
|
|
73705
73964
|
} catch {
|
|
73706
73965
|
return void 0;
|
|
73707
73966
|
}
|
|
@@ -73710,7 +73969,7 @@ async function readTrashedVaultAccount(path) {
|
|
|
73710
73969
|
}
|
|
73711
73970
|
async function readEntrySidecar(path) {
|
|
73712
73971
|
try {
|
|
73713
|
-
const parsed = walletEntrySchema.safeParse(JSON.parse(await
|
|
73972
|
+
const parsed = walletEntrySchema.safeParse(JSON.parse(await readFile12(path, "utf8")));
|
|
73714
73973
|
return parsed.success ? parsed.data : void 0;
|
|
73715
73974
|
} catch {
|
|
73716
73975
|
return void 0;
|
|
@@ -73719,7 +73978,7 @@ async function readEntrySidecar(path) {
|
|
|
73719
73978
|
async function readKeystoreSummary(path) {
|
|
73720
73979
|
let parsed;
|
|
73721
73980
|
try {
|
|
73722
|
-
parsed = JSON.parse(await
|
|
73981
|
+
parsed = JSON.parse(await readFile12(path, "utf8"));
|
|
73723
73982
|
} catch {
|
|
73724
73983
|
return {};
|
|
73725
73984
|
}
|
|
@@ -73737,7 +73996,7 @@ async function readKeystoreSummary(path) {
|
|
|
73737
73996
|
}
|
|
73738
73997
|
async function readConfiguredSpendCaps(configPath) {
|
|
73739
73998
|
try {
|
|
73740
|
-
const parsed = JSON.parse(await
|
|
73999
|
+
const parsed = JSON.parse(await readFile12(configPath, "utf8"));
|
|
73741
74000
|
const caps = typeof parsed === "object" && parsed !== null ? Reflect.get(parsed, "spendCaps") : void 0;
|
|
73742
74001
|
const result = spendCapsSchema.safeParse(caps);
|
|
73743
74002
|
if (result.success) return result.data;
|
|
@@ -73829,7 +74088,7 @@ async function withRegistryLock(path, operation) {
|
|
|
73829
74088
|
let handle;
|
|
73830
74089
|
while (!handle) {
|
|
73831
74090
|
try {
|
|
73832
|
-
handle = await
|
|
74091
|
+
handle = await open8(lockPath, "wx", 384);
|
|
73833
74092
|
} catch (error61) {
|
|
73834
74093
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) throw error61;
|
|
73835
74094
|
await removeStaleRegistryLock(lockPath);
|
|
@@ -73848,7 +74107,7 @@ async function withRegistryLock(path, operation) {
|
|
|
73848
74107
|
}
|
|
73849
74108
|
async function removeStaleRegistryLock(path) {
|
|
73850
74109
|
try {
|
|
73851
|
-
const metadata = await
|
|
74110
|
+
const metadata = await stat9(path);
|
|
73852
74111
|
if (Date.now() - metadata.mtimeMs > 3e4) await unlink6(path);
|
|
73853
74112
|
} catch (error61) {
|
|
73854
74113
|
if (!isMissingFile(error61)) throw error61;
|
|
@@ -73856,7 +74115,7 @@ async function removeStaleRegistryLock(path) {
|
|
|
73856
74115
|
}
|
|
73857
74116
|
async function writeJsonFile(path, value) {
|
|
73858
74117
|
await mkdir10(dirname7(path), { recursive: true, mode: 448 });
|
|
73859
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
74118
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes9(6).toString("hex")}.tmp`;
|
|
73860
74119
|
await writeFile5(temporaryPath, `${JSON.stringify(value, null, 2)}
|
|
73861
74120
|
`, {
|
|
73862
74121
|
encoding: "utf8",
|
|
@@ -73894,7 +74153,7 @@ async function createAccount(args) {
|
|
|
73894
74153
|
created: false
|
|
73895
74154
|
};
|
|
73896
74155
|
}
|
|
73897
|
-
if (!await
|
|
74156
|
+
if (!await fileExists2(join10(args.store.home, "vault.json"))) {
|
|
73898
74157
|
throw new KeystoreError("No vault yet. Run vapi setup.");
|
|
73899
74158
|
}
|
|
73900
74159
|
const spendCaps = resolveNewAccountCaps(args.caps);
|
|
@@ -74161,9 +74420,9 @@ async function requireAddress(store, name) {
|
|
|
74161
74420
|
if (address4 === void 0) throw new KeystoreError(`No key for wallet ${name} in the vault.`);
|
|
74162
74421
|
return address4;
|
|
74163
74422
|
}
|
|
74164
|
-
async function
|
|
74423
|
+
async function fileExists2(path) {
|
|
74165
74424
|
try {
|
|
74166
|
-
await
|
|
74425
|
+
await stat10(path);
|
|
74167
74426
|
return true;
|
|
74168
74427
|
} catch (error61) {
|
|
74169
74428
|
if (isMissingFile(error61)) return false;
|
|
@@ -74225,9 +74484,9 @@ function secretsAllowed(env, streams) {
|
|
|
74225
74484
|
}
|
|
74226
74485
|
|
|
74227
74486
|
// ../core/src/agent-profile.ts
|
|
74228
|
-
import { randomBytes as
|
|
74229
|
-
import { mkdir as mkdir11, readFile as
|
|
74230
|
-
import { join as
|
|
74487
|
+
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
74488
|
+
import { mkdir as mkdir11, readFile as readFile13, readdir as readdir4, rename as rename8, unlink as unlink7, writeFile as writeFile6 } from "node:fs/promises";
|
|
74489
|
+
import { join as join11 } from "node:path";
|
|
74231
74490
|
var DEFAULT_AGENT_TOOLS = ["call.search", "call.inspect", "call.pay"];
|
|
74232
74491
|
var AGENT_GRANTS = ["read", "delegate", "allocate"];
|
|
74233
74492
|
var agentProfileShape = {
|
|
@@ -74257,7 +74516,7 @@ async function readAgentProfile(home, name, options = {}) {
|
|
|
74257
74516
|
const path = agentProfilePath(home, name);
|
|
74258
74517
|
let raw;
|
|
74259
74518
|
try {
|
|
74260
|
-
raw = await
|
|
74519
|
+
raw = await readFile13(path, "utf8");
|
|
74261
74520
|
} catch (error61) {
|
|
74262
74521
|
if (isMissingFile(error61)) {
|
|
74263
74522
|
throw new Error(`No agent named ${name}. Create it with vapi agent create ${name}.`);
|
|
@@ -74269,9 +74528,9 @@ async function readAgentProfile(home, name, options = {}) {
|
|
|
74269
74528
|
async function writeAgentProfile(home, profile, options = {}) {
|
|
74270
74529
|
const parsed = (options.schema ?? agentProfileSchema).parse(profile);
|
|
74271
74530
|
const directory = getVapiPaths(home).agentsDir;
|
|
74272
|
-
const path =
|
|
74531
|
+
const path = join11(directory, `${parsed.name}.json`);
|
|
74273
74532
|
await mkdir11(directory, { recursive: true, mode: 448 });
|
|
74274
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
74533
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes10(6).toString("hex")}.tmp`;
|
|
74275
74534
|
await writeFile6(temporaryPath, `${JSON.stringify(parsed, null, 2)}
|
|
74276
74535
|
`, {
|
|
74277
74536
|
encoding: "utf8",
|
|
@@ -74296,7 +74555,7 @@ async function listAgentProfiles(home, options = {}) {
|
|
|
74296
74555
|
try {
|
|
74297
74556
|
profiles.push(
|
|
74298
74557
|
(options.schema ?? agentProfileSchema).parse(
|
|
74299
|
-
JSON.parse(await
|
|
74558
|
+
JSON.parse(await readFile13(join11(directory, file2), "utf8"))
|
|
74300
74559
|
)
|
|
74301
74560
|
);
|
|
74302
74561
|
} catch {
|
|
@@ -74317,11 +74576,11 @@ async function removeAgentProfile(home, name) {
|
|
|
74317
74576
|
}
|
|
74318
74577
|
function agentProfilePath(home, name) {
|
|
74319
74578
|
const parsedName = walletNameSchema.parse(name);
|
|
74320
|
-
return
|
|
74579
|
+
return join11(getVapiPaths(home).agentsDir, `${parsedName}.json`);
|
|
74321
74580
|
}
|
|
74322
74581
|
|
|
74323
74582
|
// ../core/src/ceiling.ts
|
|
74324
|
-
import { randomBytes as
|
|
74583
|
+
import { randomBytes as randomBytes14 } from "node:crypto";
|
|
74325
74584
|
|
|
74326
74585
|
// ../core/src/authorization-state.ts
|
|
74327
74586
|
var EIP3009_AUTHORIZATION_STATE_ABI = [
|
|
@@ -74386,13 +74645,13 @@ function missingAuthorization(receipt) {
|
|
|
74386
74645
|
}
|
|
74387
74646
|
|
|
74388
74647
|
// ../core/src/movement.ts
|
|
74389
|
-
import { randomBytes as
|
|
74390
|
-
import { chmod as chmod4, mkdir as mkdir14, open as
|
|
74391
|
-
import { join as
|
|
74648
|
+
import { randomBytes as randomBytes13 } from "node:crypto";
|
|
74649
|
+
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";
|
|
74650
|
+
import { join as join12 } from "node:path";
|
|
74392
74651
|
|
|
74393
74652
|
// ../core/src/spend-policy.ts
|
|
74394
|
-
import { randomBytes as
|
|
74395
|
-
import { mkdir as mkdir12, open as
|
|
74653
|
+
import { randomBytes as randomBytes11 } from "node:crypto";
|
|
74654
|
+
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";
|
|
74396
74655
|
import { dirname as dirname8 } from "node:path";
|
|
74397
74656
|
var ledgerSchema = external_exports.object({
|
|
74398
74657
|
date: external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
@@ -74463,7 +74722,7 @@ async function readSpendLedgerRows(path = getAgentCashPaths().ledger, now = /* @
|
|
|
74463
74722
|
async function readStoredSpendLedgerRows(path, now, allDays = false) {
|
|
74464
74723
|
let raw;
|
|
74465
74724
|
try {
|
|
74466
|
-
raw = await
|
|
74725
|
+
raw = await readFile14(path, "utf8");
|
|
74467
74726
|
} catch (error61) {
|
|
74468
74727
|
if (isMissingFile(error61)) return [];
|
|
74469
74728
|
throw error61;
|
|
@@ -74596,7 +74855,7 @@ async function reserveSpend(amountAtomic2, caps, options) {
|
|
|
74596
74855
|
{ amountAtomic: amountAtomic2, limitAtomic: perDayAtomic, spentAtomic: BigInt(spentAtomic), wallet }
|
|
74597
74856
|
);
|
|
74598
74857
|
}
|
|
74599
|
-
const reservationId = options?.reservationId ?? (options?.taskKey === void 0 ? void 0 :
|
|
74858
|
+
const reservationId = options?.reservationId ?? (options?.taskKey === void 0 ? void 0 : randomBytes11(16).toString("hex"));
|
|
74600
74859
|
const nextRow = {
|
|
74601
74860
|
date: utcDateKey(now),
|
|
74602
74861
|
spentAtomic: nextSpent.toString(),
|
|
@@ -74702,7 +74961,7 @@ async function writeLedgerAtomically(path, rows) {
|
|
|
74702
74961
|
...rows[0].reservations === void 0 ? {} : { reservations: rows[0].reservations }
|
|
74703
74962
|
} : { version: 1, rows };
|
|
74704
74963
|
await mkdir12(dirname8(path), { recursive: true, mode: 448 });
|
|
74705
|
-
const temporaryPath = `${path}.${process.pid}.${
|
|
74964
|
+
const temporaryPath = `${path}.${process.pid}.${randomBytes11(6).toString("hex")}.tmp`;
|
|
74706
74965
|
await writeFile7(temporaryPath, `${JSON.stringify(ledger, null, 2)}
|
|
74707
74966
|
`, {
|
|
74708
74967
|
encoding: "utf8",
|
|
@@ -74718,7 +74977,7 @@ async function withLedgerLock(path, operation) {
|
|
|
74718
74977
|
let handle;
|
|
74719
74978
|
while (!handle) {
|
|
74720
74979
|
try {
|
|
74721
|
-
handle = await
|
|
74980
|
+
handle = await open9(lockPath, "wx", 384);
|
|
74722
74981
|
} catch (error61) {
|
|
74723
74982
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) {
|
|
74724
74983
|
throw error61;
|
|
@@ -74739,7 +74998,7 @@ async function withLedgerLock(path, operation) {
|
|
|
74739
74998
|
}
|
|
74740
74999
|
async function removeStaleLock3(path) {
|
|
74741
75000
|
try {
|
|
74742
|
-
const metadata = await
|
|
75001
|
+
const metadata = await stat11(path);
|
|
74743
75002
|
if (Date.now() - metadata.mtimeMs > 3e4) {
|
|
74744
75003
|
await unlink8(path);
|
|
74745
75004
|
}
|
|
@@ -74751,8 +75010,8 @@ async function removeStaleLock3(path) {
|
|
|
74751
75010
|
}
|
|
74752
75011
|
|
|
74753
75012
|
// ../core/src/transfer.ts
|
|
74754
|
-
import { randomBytes as
|
|
74755
|
-
import { mkdir as mkdir13, open as
|
|
75013
|
+
import { randomBytes as randomBytes12, randomUUID } from "node:crypto";
|
|
75014
|
+
import { mkdir as mkdir13, open as open10, stat as stat12, unlink as unlink9 } from "node:fs/promises";
|
|
74756
75015
|
import { dirname as dirname9 } from "node:path";
|
|
74757
75016
|
|
|
74758
75017
|
// ../core/src/siblings.ts
|
|
@@ -74961,7 +75220,7 @@ async function transferBetweenAccounts(args) {
|
|
|
74961
75220
|
if (args.resume !== void 0) {
|
|
74962
75221
|
return await resumeTransfer(context, args.resume);
|
|
74963
75222
|
}
|
|
74964
|
-
const nonce = args.nonce ?? bytesToHex(
|
|
75223
|
+
const nonce = args.nonce ?? bytesToHex(randomBytes12(32));
|
|
74965
75224
|
if (!NONCE_PATTERN.test(nonce)) {
|
|
74966
75225
|
throw new TransferError(
|
|
74967
75226
|
"authorization_invalid",
|
|
@@ -75354,7 +75613,7 @@ async function withTransferLock(context, nonce, operation) {
|
|
|
75354
75613
|
let handle;
|
|
75355
75614
|
while (!handle) {
|
|
75356
75615
|
try {
|
|
75357
|
-
handle = await
|
|
75616
|
+
handle = await open10(lockPath, "wx", 384);
|
|
75358
75617
|
} catch (error61) {
|
|
75359
75618
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "EEXIST")) throw error61;
|
|
75360
75619
|
await removeStaleTransferLock(lockPath, staleAfterMs);
|
|
@@ -75373,7 +75632,7 @@ async function withTransferLock(context, nonce, operation) {
|
|
|
75373
75632
|
}
|
|
75374
75633
|
async function removeStaleTransferLock(path, staleAfterMs) {
|
|
75375
75634
|
try {
|
|
75376
|
-
const metadata = await
|
|
75635
|
+
const metadata = await stat12(path);
|
|
75377
75636
|
if (Date.now() - metadata.mtimeMs > staleAfterMs) await unlink9(path);
|
|
75378
75637
|
} catch (error61) {
|
|
75379
75638
|
if (!(error61 instanceof Error && "code" in error61 && error61.code === "ENOENT")) throw error61;
|
|
@@ -75799,7 +76058,7 @@ async function listUnfinishedMovements(options) {
|
|
|
75799
76058
|
}
|
|
75800
76059
|
const summaries = [];
|
|
75801
76060
|
for (const name of names.filter((candidate) => candidate.endsWith(".json")).sort()) {
|
|
75802
|
-
const movement = parseMovement(JSON.parse(await
|
|
76061
|
+
const movement = parseMovement(JSON.parse(await readFile15(join12(directory, name), "utf8")));
|
|
75803
76062
|
if (options.from !== void 0 && !movement.legs.some((leg) => leg.from === options.from)) {
|
|
75804
76063
|
continue;
|
|
75805
76064
|
}
|
|
@@ -75830,7 +76089,7 @@ async function listUnfinishedMovementSnapshots(options) {
|
|
|
75830
76089
|
}
|
|
75831
76090
|
const snapshots = [];
|
|
75832
76091
|
for (const name of names.filter((candidate) => candidate.endsWith(".json")).sort()) {
|
|
75833
|
-
const movement = parseMovement(JSON.parse(await
|
|
76092
|
+
const movement = parseMovement(JSON.parse(await readFile15(join12(directory, name), "utf8")));
|
|
75834
76093
|
if (options.from !== void 0 && !movement.legs.some((leg) => leg.from === options.from)) {
|
|
75835
76094
|
continue;
|
|
75836
76095
|
}
|
|
@@ -75866,23 +76125,23 @@ async function movementHasOpenLeg(home, movement, from16) {
|
|
|
75866
76125
|
return false;
|
|
75867
76126
|
}
|
|
75868
76127
|
async function movementOpenEvidence(home, movement, from16) {
|
|
75869
|
-
let
|
|
76128
|
+
let open13 = false;
|
|
75870
76129
|
const signedFailedLegKeys = [];
|
|
75871
76130
|
for (const leg of movement.legs) {
|
|
75872
76131
|
if (from16 !== void 0 && leg.from !== from16) continue;
|
|
75873
|
-
if (isOpenMovementLeg(leg, "unsigned"))
|
|
76132
|
+
if (isOpenMovementLeg(leg, "unsigned")) open13 = true;
|
|
75874
76133
|
if (leg.status !== "failed") continue;
|
|
75875
76134
|
const journal = await readTransferJournal(home, leg.from, leg.nonce);
|
|
75876
76135
|
if (journal.signed) signedFailedLegKeys.push(movementTransferKey(leg.from, leg.nonce));
|
|
75877
|
-
if (isOpenMovementLeg(leg, journal.signed ? "signed" : "unsigned"))
|
|
76136
|
+
if (isOpenMovementLeg(leg, journal.signed ? "signed" : "unsigned")) open13 = true;
|
|
75878
76137
|
}
|
|
75879
|
-
return { open:
|
|
76138
|
+
return { open: open13, signedFailedLegKeys };
|
|
75880
76139
|
}
|
|
75881
76140
|
async function readMovement(home, id2) {
|
|
75882
76141
|
const safeId = parseMovementId(id2);
|
|
75883
76142
|
try {
|
|
75884
76143
|
return parseMovement(
|
|
75885
|
-
JSON.parse(await
|
|
76144
|
+
JSON.parse(await readFile15(join12(movementsDirectory(home), `${safeId}.json`), "utf8"))
|
|
75886
76145
|
);
|
|
75887
76146
|
} catch (error61) {
|
|
75888
76147
|
if (isMissingFile(error61)) {
|
|
@@ -76602,33 +76861,33 @@ function parseMovementId(value) {
|
|
|
76602
76861
|
return parsed.data;
|
|
76603
76862
|
}
|
|
76604
76863
|
function movementsDirectory(home) {
|
|
76605
|
-
return
|
|
76864
|
+
return join12(home, "movements");
|
|
76606
76865
|
}
|
|
76607
76866
|
function createMovementId() {
|
|
76608
|
-
return `mv_${
|
|
76867
|
+
return `mv_${randomBytes13(12).toString("hex")}`;
|
|
76609
76868
|
}
|
|
76610
76869
|
function createMovementNonce() {
|
|
76611
|
-
return bytesToHex(
|
|
76870
|
+
return bytesToHex(randomBytes13(32));
|
|
76612
76871
|
}
|
|
76613
76872
|
async function writeMovement(home, movement) {
|
|
76614
76873
|
const parsed = movementSchema.parse(movement);
|
|
76615
76874
|
const directory = movementsDirectory(home);
|
|
76616
76875
|
await mkdir14(directory, { recursive: true, mode: 448 });
|
|
76617
76876
|
await chmod4(directory, 448);
|
|
76618
|
-
const path =
|
|
76619
|
-
const temporary =
|
|
76877
|
+
const path = join12(directory, `${parsed.id}.json`);
|
|
76878
|
+
const temporary = join12(
|
|
76620
76879
|
directory,
|
|
76621
|
-
`.${parsed.id}.${process.pid}.${
|
|
76880
|
+
`.${parsed.id}.${process.pid}.${randomBytes13(6).toString("hex")}.tmp`
|
|
76622
76881
|
);
|
|
76623
76882
|
let handle;
|
|
76624
76883
|
try {
|
|
76625
|
-
handle = await
|
|
76884
|
+
handle = await open11(temporary, "wx", 384);
|
|
76626
76885
|
await handle.writeFile(serializeMovement(parsed), "utf8");
|
|
76627
76886
|
await handle.sync();
|
|
76628
76887
|
await handle.close();
|
|
76629
76888
|
handle = void 0;
|
|
76630
76889
|
await rename10(temporary, path);
|
|
76631
|
-
const directoryHandle = await
|
|
76890
|
+
const directoryHandle = await open11(directory, "r");
|
|
76632
76891
|
try {
|
|
76633
76892
|
await directoryHandle.sync();
|
|
76634
76893
|
} finally {
|
|
@@ -76848,7 +77107,7 @@ async function sweepAboveCeilingLocked(args) {
|
|
|
76848
77107
|
owner,
|
|
76849
77108
|
target,
|
|
76850
77109
|
amountAtomic: amountAtomic2.toString(),
|
|
76851
|
-
nonce: (args.randomNonce ?? (() => bytesToHex(
|
|
77110
|
+
nonce: (args.randomNonce ?? (() => bytesToHex(randomBytes14(32))))(),
|
|
76852
77111
|
createdAt: new Date(now()).toISOString(),
|
|
76853
77112
|
status: "planned"
|
|
76854
77113
|
};
|
|
@@ -77640,8 +77899,8 @@ function parseDecimal(value, scale) {
|
|
|
77640
77899
|
}
|
|
77641
77900
|
|
|
77642
77901
|
// ../core/src/swarm.ts
|
|
77643
|
-
import { readdir as readdir6, readFile as
|
|
77644
|
-
import { join as
|
|
77902
|
+
import { readdir as readdir6, readFile as readFile16, stat as stat13, unlink as unlink11 } from "node:fs/promises";
|
|
77903
|
+
import { join as join13 } from "node:path";
|
|
77645
77904
|
var SWARM_NAME_PATTERN = /^[a-z][a-z0-9-]{0,15}$/;
|
|
77646
77905
|
var SWARM_ROLE_PATTERN = /^[a-z][a-z0-9]{0,7}$/;
|
|
77647
77906
|
var DEFAULT_SWARM_MODEL = "venice/claude-sonnet-5";
|
|
@@ -77722,16 +77981,16 @@ var SwarmError = class extends Error {
|
|
|
77722
77981
|
code;
|
|
77723
77982
|
};
|
|
77724
77983
|
function swarmsDirectory(home) {
|
|
77725
|
-
return
|
|
77984
|
+
return join13(home, "swarms");
|
|
77726
77985
|
}
|
|
77727
77986
|
function swarmFilePath(home, name) {
|
|
77728
77987
|
assertName(name);
|
|
77729
|
-
return
|
|
77988
|
+
return join13(swarmsDirectory(home), `${name}.json`);
|
|
77730
77989
|
}
|
|
77731
77990
|
async function readSwarm(home, name) {
|
|
77732
77991
|
const path = swarmFilePath(home, name);
|
|
77733
77992
|
try {
|
|
77734
|
-
const swarm = parseSwarm(JSON.parse(await
|
|
77993
|
+
const swarm = parseSwarm(JSON.parse(await readFile16(path, "utf8")));
|
|
77735
77994
|
if (swarm.name !== name)
|
|
77736
77995
|
throw new SwarmError("invalid_swarm", "Swarm name does not match its file.");
|
|
77737
77996
|
return swarm;
|
|
@@ -77759,7 +78018,7 @@ async function writeSwarm(home, value) {
|
|
|
77759
78018
|
const bytes = `${JSON.stringify(swarm, null, 2)}
|
|
77760
78019
|
`;
|
|
77761
78020
|
try {
|
|
77762
|
-
if (await
|
|
78021
|
+
if (await readFile16(path, "utf8") === bytes) return;
|
|
77763
78022
|
} catch (error61) {
|
|
77764
78023
|
if (!isMissingFile(error61)) throw error61;
|
|
77765
78024
|
}
|
|
@@ -77774,7 +78033,7 @@ async function deleteSwarmFile(home, name) {
|
|
|
77774
78033
|
}
|
|
77775
78034
|
async function withSwarmLock(home, name, fn) {
|
|
77776
78035
|
assertName(name);
|
|
77777
|
-
const path =
|
|
78036
|
+
const path = join13(swarmsDirectory(home), `.${name}.lock`);
|
|
77778
78037
|
try {
|
|
77779
78038
|
return await withFileLock(path, fn, { lockedMessage: `Swarm ${name} is locked.` });
|
|
77780
78039
|
} catch (error61) {
|
|
@@ -78086,7 +78345,7 @@ async function swarmStatus(opts) {
|
|
|
78086
78345
|
);
|
|
78087
78346
|
let movementFiles;
|
|
78088
78347
|
try {
|
|
78089
|
-
movementFiles = await readdir6(
|
|
78348
|
+
movementFiles = await readdir6(join13(home, "movements"));
|
|
78090
78349
|
} catch (error61) {
|
|
78091
78350
|
if (!isMissingFile(error61)) throw error61;
|
|
78092
78351
|
movementFiles = [];
|
|
@@ -78143,11 +78402,11 @@ async function swarmStatus(opts) {
|
|
|
78143
78402
|
})
|
|
78144
78403
|
);
|
|
78145
78404
|
const accounts = new Set(swarmAccountNames(swarm));
|
|
78146
|
-
const
|
|
78405
|
+
const open13 = [];
|
|
78147
78406
|
for (const summary2 of await listUnfinishedMovements({ home })) {
|
|
78148
78407
|
const movement = await readMovement(home, summary2.id);
|
|
78149
78408
|
if (movement.treasury === swarm.treasury.account || movement.legs.some((leg) => accounts.has(leg.from) || accounts.has(leg.to))) {
|
|
78150
|
-
|
|
78409
|
+
open13.push(summary2);
|
|
78151
78410
|
}
|
|
78152
78411
|
}
|
|
78153
78412
|
return {
|
|
@@ -78156,7 +78415,7 @@ async function swarmStatus(opts) {
|
|
|
78156
78415
|
strategy: swarm.policy.strategy,
|
|
78157
78416
|
treasury,
|
|
78158
78417
|
members: members2,
|
|
78159
|
-
openMovements:
|
|
78418
|
+
openMovements: open13.sort(
|
|
78160
78419
|
(a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id)
|
|
78161
78420
|
)
|
|
78162
78421
|
};
|
|
@@ -78255,7 +78514,7 @@ async function assertNoConflicts(home, name, accounts) {
|
|
|
78255
78514
|
}
|
|
78256
78515
|
async function profileExists(home, account) {
|
|
78257
78516
|
try {
|
|
78258
|
-
await
|
|
78517
|
+
await stat13(join13(getVapiPaths(home).agentsDir, `${account}.json`));
|
|
78259
78518
|
return true;
|
|
78260
78519
|
} catch (error61) {
|
|
78261
78520
|
if (isMissingFile(error61)) return false;
|
|
@@ -78268,7 +78527,7 @@ async function refuseTreasuryProfile(home, account) {
|
|
|
78268
78527
|
}
|
|
78269
78528
|
|
|
78270
78529
|
// ../core/src/x402-pay.ts
|
|
78271
|
-
import { randomBytes as
|
|
78530
|
+
import { randomBytes as randomBytes15, randomUUID as randomUUID2 } from "node:crypto";
|
|
78272
78531
|
|
|
78273
78532
|
// ../core/src/run-budget.ts
|
|
78274
78533
|
var RunBudgetError = class extends Error {
|
|
@@ -78309,13 +78568,13 @@ function createRunBudget(args) {
|
|
|
78309
78568
|
// ../core/src/support-report.ts
|
|
78310
78569
|
import { mkdir as mkdir15, writeFile as writeFile8 } from "node:fs/promises";
|
|
78311
78570
|
import { arch, platform, release } from "node:os";
|
|
78312
|
-
import { join as
|
|
78313
|
-
var VAPI_CLIENT_VERSION = "0.
|
|
78571
|
+
import { join as join14 } from "node:path";
|
|
78572
|
+
var VAPI_CLIENT_VERSION = "0.13.0";
|
|
78314
78573
|
async function createSupportReport(options) {
|
|
78315
78574
|
const message = options.message.trim();
|
|
78316
78575
|
if (!message) throw new Error("Support report message must not be empty.");
|
|
78317
78576
|
const paths = getVapiPaths();
|
|
78318
|
-
const reportsDirectory = options.reportsDirectory ??
|
|
78577
|
+
const reportsDirectory = options.reportsDirectory ?? join14(paths.directory, "reports");
|
|
78319
78578
|
const receipts = await readReceipts(options.receiptsPath ?? paths.receipts, { limit: 5 });
|
|
78320
78579
|
const system = options.systemInfo ?? defaultSystemInfo();
|
|
78321
78580
|
const report = {
|
|
@@ -78345,7 +78604,7 @@ async function createSupportReport(options) {
|
|
|
78345
78604
|
};
|
|
78346
78605
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
78347
78606
|
const timestamp = now.toISOString();
|
|
78348
|
-
const path =
|
|
78607
|
+
const path = join14(reportsDirectory, `${sanitizeTimestamp(timestamp)}.json`);
|
|
78349
78608
|
await mkdir15(reportsDirectory, { recursive: true, mode: 448 });
|
|
78350
78609
|
const serialized = `${JSON.stringify(report, null, 2)}
|
|
78351
78610
|
`;
|
|
@@ -78541,7 +78800,7 @@ async function completeX402Payment(args) {
|
|
|
78541
78800
|
throw walletCapError(error61, quote.amountAtomic, args);
|
|
78542
78801
|
}
|
|
78543
78802
|
} else {
|
|
78544
|
-
reservationId = args.paymentId ?? `x402_${
|
|
78803
|
+
reservationId = args.paymentId ?? `x402_${randomBytes15(12).toString("hex")}`;
|
|
78545
78804
|
let reservation;
|
|
78546
78805
|
try {
|
|
78547
78806
|
reservation = await reserveSpend(quote.amountAtomic, args.caps, {
|
|
@@ -79942,8 +80201,8 @@ function freezeScopeTerms(structuredInput, briefInput) {
|
|
|
79942
80201
|
}
|
|
79943
80202
|
|
|
79944
80203
|
// ../core/src/tasks/scope-bindings.ts
|
|
79945
|
-
import { readFile as
|
|
79946
|
-
import { join as
|
|
80204
|
+
import { readFile as readFile17 } from "node:fs/promises";
|
|
80205
|
+
import { join as join15 } from "node:path";
|
|
79947
80206
|
|
|
79948
80207
|
// ../core/src/tasks/chain-port.ts
|
|
79949
80208
|
var TasksChainError = class extends Error {
|
|
@@ -80518,7 +80777,7 @@ var messageSchema = external_exports.looseObject({
|
|
|
80518
80777
|
})
|
|
80519
80778
|
)
|
|
80520
80779
|
});
|
|
80521
|
-
var
|
|
80780
|
+
var fileSchema2 = external_exports.looseObject({
|
|
80522
80781
|
id: uuidSchema,
|
|
80523
80782
|
purpose: workFilePurposeSchema,
|
|
80524
80783
|
fileName: external_exports.string(),
|
|
@@ -80824,11 +81083,11 @@ var tasksResponseSchemas = {
|
|
|
80824
81083
|
observedAt: isoDateTimeSchema
|
|
80825
81084
|
}),
|
|
80826
81085
|
createUpload: external_exports.looseObject({
|
|
80827
|
-
file:
|
|
81086
|
+
file: fileSchema2.extend({ state: external_exports.literal("pending"), sha256: external_exports.null() }),
|
|
80828
81087
|
uploadUrl: external_exports.url()
|
|
80829
81088
|
}),
|
|
80830
81089
|
finalizeUpload: external_exports.looseObject({
|
|
80831
|
-
file:
|
|
81090
|
+
file: fileSchema2.extend({
|
|
80832
81091
|
state: external_exports.literal("ready"),
|
|
80833
81092
|
sha256: external_exports.string().regex(/^[0-9a-fA-F]{64}$/)
|
|
80834
81093
|
})
|
|
@@ -81436,10 +81695,10 @@ function key(identity) {
|
|
|
81436
81695
|
return `${identity.orderId}:${identity.trancheOrdinal}:${identity.scopeVersion}:${identity.termsHash.toLowerCase()}:${identity.self.toLowerCase()}`;
|
|
81437
81696
|
}
|
|
81438
81697
|
function createScopeBindings(home) {
|
|
81439
|
-
const path =
|
|
81698
|
+
const path = join15(home, "tasks", "scope-bindings.json");
|
|
81440
81699
|
async function read() {
|
|
81441
81700
|
try {
|
|
81442
|
-
return storeSchema.parse(JSON.parse(await
|
|
81701
|
+
return storeSchema.parse(JSON.parse(await readFile17(path, "utf8")));
|
|
81443
81702
|
} catch (error61) {
|
|
81444
81703
|
if (error61 instanceof Error && "code" in error61 && error61.code === "ENOENT")
|
|
81445
81704
|
return { version: 1, bindings: {} };
|
|
@@ -82120,7 +82379,7 @@ function createTasksChain(options) {
|
|
|
82120
82379
|
const { account, client, pending, rpcFor } = options;
|
|
82121
82380
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
82122
82381
|
const sleep = options.sleep ?? ((ms) => new Promise((resolve4) => setTimeout(resolve4, ms)));
|
|
82123
|
-
const
|
|
82382
|
+
const randomBytes18 = options.randomBytes ?? cryptoRandomBytes2;
|
|
82124
82383
|
const confirmations = options.confirmations ?? 2;
|
|
82125
82384
|
if (!Number.isSafeInteger(confirmations) || confirmations < 1)
|
|
82126
82385
|
throw new TasksChainError("Tasks confirmations must be a positive integer.", false, {
|
|
@@ -82729,7 +82988,7 @@ function createTasksChain(options) {
|
|
|
82729
82988
|
await verifyClone(rpcFor(ready.chainId), expected, true);
|
|
82730
82989
|
if (validBefore <= BigInt(Math.floor(now().getTime() / 1e3)))
|
|
82731
82990
|
throw new TasksValidationError("The task funding offer has expired.");
|
|
82732
|
-
const bytes =
|
|
82991
|
+
const bytes = randomBytes18(32);
|
|
82733
82992
|
if (bytes.length !== 32)
|
|
82734
82993
|
throw new TasksValidationError(
|
|
82735
82994
|
"Funding authorization randomness must contain 32 bytes."
|
|
@@ -83007,8 +83266,8 @@ function createTasksRpcFor(config2, options = {}) {
|
|
|
83007
83266
|
}
|
|
83008
83267
|
|
|
83009
83268
|
// ../core/src/tasks/pending-transactions.ts
|
|
83010
|
-
import { readFile as
|
|
83011
|
-
import { join as
|
|
83269
|
+
import { readFile as readFile18 } from "node:fs/promises";
|
|
83270
|
+
import { join as join16 } from "node:path";
|
|
83012
83271
|
var hex3 = external_exports.string().regex(/^0x(?:[0-9a-fA-F]{2})+$/).transform((v) => v);
|
|
83013
83272
|
var hash4 = external_exports.string().regex(/^0x[0-9a-fA-F]{64}$/).transform((v) => v);
|
|
83014
83273
|
var step = external_exports.enum([
|
|
@@ -83090,11 +83349,11 @@ function validCheckpointStep(storedStep, response) {
|
|
|
83090
83349
|
}[response.operation.kind];
|
|
83091
83350
|
}
|
|
83092
83351
|
function createPendingTransactions(home) {
|
|
83093
|
-
const path =
|
|
83352
|
+
const path = join16(home, "tasks", "pending.json");
|
|
83094
83353
|
const lockPath = `${path}.lock`;
|
|
83095
83354
|
const read = async () => {
|
|
83096
83355
|
try {
|
|
83097
|
-
const state = stateSchema.parse(JSON.parse(await
|
|
83356
|
+
const state = stateSchema.parse(JSON.parse(await readFile18(path, "utf8")));
|
|
83098
83357
|
for (const [key2, value] of Object.entries(state.checkpoints)) {
|
|
83099
83358
|
const separator = key2.indexOf(":");
|
|
83100
83359
|
const operationId = key2.slice(0, separator);
|
|
@@ -83157,7 +83416,7 @@ function createPendingTransactions(home) {
|
|
|
83157
83416
|
},
|
|
83158
83417
|
withStepLock(operationId, step2, fn) {
|
|
83159
83418
|
return withFileLock(
|
|
83160
|
-
|
|
83419
|
+
join16(
|
|
83161
83420
|
home,
|
|
83162
83421
|
"tasks",
|
|
83163
83422
|
`step-${encodeURIComponent(operationId)}-${encodeURIComponent(step2)}.lock`
|
|
@@ -83169,13 +83428,13 @@ function createPendingTransactions(home) {
|
|
|
83169
83428
|
external_exports.number().int().positive().parse(chainId);
|
|
83170
83429
|
address3.parse(signer);
|
|
83171
83430
|
return withFileLock(
|
|
83172
|
-
|
|
83431
|
+
join16(home, "tasks", `signer-${chainId}-${signer.toLowerCase()}.lock`),
|
|
83173
83432
|
fn
|
|
83174
83433
|
);
|
|
83175
83434
|
},
|
|
83176
83435
|
withFundingLock(milestoneId, fn) {
|
|
83177
83436
|
milestoneKey(milestoneId);
|
|
83178
|
-
return withFileLock(
|
|
83437
|
+
return withFileLock(join16(home, "tasks", `fund-${milestoneId}.lock`), fn);
|
|
83179
83438
|
},
|
|
83180
83439
|
async nextNonce(chainId, signer) {
|
|
83181
83440
|
external_exports.number().int().positive().parse(chainId);
|
|
@@ -84001,7 +84260,7 @@ function policyAtomic(value) {
|
|
|
84001
84260
|
}
|
|
84002
84261
|
|
|
84003
84262
|
// ../core/src/tasks/operation-support.ts
|
|
84004
|
-
import { readFile as
|
|
84263
|
+
import { readFile as readFile19, stat as stat14 } from "node:fs/promises";
|
|
84005
84264
|
import { basename as basename3, extname } from "node:path";
|
|
84006
84265
|
var TaskOperationError = class extends Error {
|
|
84007
84266
|
constructor(code, message, manifestHash) {
|
|
@@ -84169,7 +84428,7 @@ function parseTaskDuration(text, now) {
|
|
|
84169
84428
|
async function readTaskFile(path) {
|
|
84170
84429
|
let details;
|
|
84171
84430
|
try {
|
|
84172
|
-
details = await
|
|
84431
|
+
details = await stat14(path);
|
|
84173
84432
|
} catch {
|
|
84174
84433
|
throw new TaskInputError(`Task file ${JSON.stringify(path)} could not be read.`);
|
|
84175
84434
|
}
|
|
@@ -84193,7 +84452,7 @@ async function readTaskFile(path) {
|
|
|
84193
84452
|
const contentType = types[extname(path).toLowerCase()];
|
|
84194
84453
|
if (!contentType)
|
|
84195
84454
|
throw new TaskInputError("Task files must be images, PDF, ZIP, text, Markdown, JSON or CSV.");
|
|
84196
|
-
const bytes = await
|
|
84455
|
+
const bytes = await readFile19(path);
|
|
84197
84456
|
if (bytes.length < TASK_LIMITS.uploadBytesMin || bytes.length > TASK_LIMITS.uploadBytesMax)
|
|
84198
84457
|
throw new TaskInputError("Task files must contain between 1 byte and 50 MiB.");
|
|
84199
84458
|
return {
|
|
@@ -84992,7 +85251,7 @@ async function resolveUnmatchedTaskOperation(context, input2) {
|
|
|
84992
85251
|
}
|
|
84993
85252
|
|
|
84994
85253
|
// ../core/src/searches.ts
|
|
84995
|
-
import { mkdir as mkdir16, open as
|
|
85254
|
+
import { mkdir as mkdir16, open as open12, readFile as readFile20 } from "node:fs/promises";
|
|
84996
85255
|
import { dirname as dirname10 } from "node:path";
|
|
84997
85256
|
var searchEventSchema = external_exports.strictObject({
|
|
84998
85257
|
timestamp: external_exports.iso.datetime(),
|
|
@@ -85014,7 +85273,7 @@ function parseSearchEvent(value) {
|
|
|
85014
85273
|
async function appendSearchEvent(event, path = getVapiPaths().searches) {
|
|
85015
85274
|
const parsed = parseSearchEvent(event);
|
|
85016
85275
|
await mkdir16(dirname10(path), { recursive: true, mode: 448 });
|
|
85017
|
-
const handle = await
|
|
85276
|
+
const handle = await open12(path, "a", 384);
|
|
85018
85277
|
try {
|
|
85019
85278
|
await handle.writeFile(`${JSON.stringify(parsed)}
|
|
85020
85279
|
`, "utf8");
|
|
@@ -85026,7 +85285,7 @@ async function appendSearchEvent(event, path = getVapiPaths().searches) {
|
|
|
85026
85285
|
async function readSearchEvents(path = getVapiPaths().searches) {
|
|
85027
85286
|
let raw;
|
|
85028
85287
|
try {
|
|
85029
|
-
raw = await
|
|
85288
|
+
raw = await readFile20(path, "utf8");
|
|
85030
85289
|
} catch (error61) {
|
|
85031
85290
|
if (isMissingFile(error61)) return [];
|
|
85032
85291
|
throw error61;
|
|
@@ -86131,9 +86390,9 @@ function csvCell(value) {
|
|
|
86131
86390
|
}
|
|
86132
86391
|
|
|
86133
86392
|
// ../core/src/swarm-capital.ts
|
|
86134
|
-
import { createHash as createHash5, randomBytes as
|
|
86135
|
-
import { readFile as
|
|
86136
|
-
import { join as
|
|
86393
|
+
import { createHash as createHash5, randomBytes as randomBytes16 } from "node:crypto";
|
|
86394
|
+
import { readFile as readFile21, unlink as unlink12 } from "node:fs/promises";
|
|
86395
|
+
import { join as join17 } from "node:path";
|
|
86137
86396
|
var movementIdSchema3 = external_exports.string().regex(/^mv_[A-Za-z0-9_-]{8,128}$/u);
|
|
86138
86397
|
var amountSchema2 = external_exports.string().regex(/^\d+\.\d{2}$/u);
|
|
86139
86398
|
var requestIdSchema = external_exports.string().min(1).max(512);
|
|
@@ -87014,7 +87273,7 @@ async function readDelegationRecord(home, movementId) {
|
|
|
87014
87273
|
const safeId = runRecordMovementId(movementId);
|
|
87015
87274
|
try {
|
|
87016
87275
|
const record2 = delegationRecordSchema.parse(
|
|
87017
|
-
JSON.parse(await
|
|
87276
|
+
JSON.parse(await readFile21(delegationRecordPath(home, safeId), "utf8"))
|
|
87018
87277
|
);
|
|
87019
87278
|
if (record2.movementId !== safeId) {
|
|
87020
87279
|
throw new SwarmError(
|
|
@@ -87041,7 +87300,7 @@ async function readTreasuryRequestRecord(home, movementId) {
|
|
|
87041
87300
|
const safeId = runRecordMovementId(movementId);
|
|
87042
87301
|
try {
|
|
87043
87302
|
const record2 = treasuryRequestRecordSchema.parse(
|
|
87044
|
-
JSON.parse(await
|
|
87303
|
+
JSON.parse(await readFile21(treasuryRequestRecordPath(home, safeId), "utf8"))
|
|
87045
87304
|
);
|
|
87046
87305
|
if (record2.movementId !== safeId) {
|
|
87047
87306
|
throw new SwarmError(
|
|
@@ -87072,18 +87331,18 @@ function runRecordMovementId(value) {
|
|
|
87072
87331
|
return parsed.data;
|
|
87073
87332
|
}
|
|
87074
87333
|
function treasuryRequestRecordPath(home, movementId) {
|
|
87075
|
-
return
|
|
87334
|
+
return join17(home, "runs", "requests", `${movementId}.json`);
|
|
87076
87335
|
}
|
|
87077
87336
|
function delegationRecordPath(home, movementId) {
|
|
87078
|
-
return
|
|
87337
|
+
return join17(home, "runs", "delegations", `${movementId}.json`);
|
|
87079
87338
|
}
|
|
87080
87339
|
function legacyFundingProgressPath(home, name) {
|
|
87081
|
-
return
|
|
87340
|
+
return join17(home, "swarms", `.${name}.funding`);
|
|
87082
87341
|
}
|
|
87083
87342
|
async function readLegacyFundingProgress(home, name) {
|
|
87084
87343
|
try {
|
|
87085
87344
|
const progress = legacyFundingProgressSchema.parse(
|
|
87086
|
-
JSON.parse(await
|
|
87345
|
+
JSON.parse(await readFile21(legacyFundingProgressPath(home, name), "utf8"))
|
|
87087
87346
|
);
|
|
87088
87347
|
if (progress.name !== name) {
|
|
87089
87348
|
throw new SwarmError("invalid_swarm", `Invalid funding progress for swarm ${name}.`);
|
|
@@ -87312,7 +87571,7 @@ async function optionalMovement(home, id2) {
|
|
|
87312
87571
|
}
|
|
87313
87572
|
}
|
|
87314
87573
|
function nextMovementId(deps) {
|
|
87315
|
-
return movementIdSchema3.parse(deps.randomId?.() ?? `mv_${
|
|
87574
|
+
return movementIdSchema3.parse(deps.randomId?.() ?? `mv_${randomBytes16(12).toString("hex")}`);
|
|
87316
87575
|
}
|
|
87317
87576
|
async function executeRecordedMovement(id2, plan, deps, home, options = {}) {
|
|
87318
87577
|
try {
|
|
@@ -87728,7 +87987,7 @@ async function removeMemberLocked(home, swarm, account) {
|
|
|
87728
87987
|
}
|
|
87729
87988
|
|
|
87730
87989
|
// ../core/src/status.ts
|
|
87731
|
-
import { join as
|
|
87990
|
+
import { join as join18 } from "node:path";
|
|
87732
87991
|
var STATUS_TIMEOUT_MS = 2e3;
|
|
87733
87992
|
async function buildStatus(deps) {
|
|
87734
87993
|
const timers = deps.timers ?? { setTimeout, clearTimeout };
|
|
@@ -87784,7 +88043,7 @@ function formatUsdAmount(value) {
|
|
|
87784
88043
|
}
|
|
87785
88044
|
async function readVaultStatus(deps) {
|
|
87786
88045
|
const store = deps.secrets.description.replace(/^the /u, "");
|
|
87787
|
-
const path =
|
|
88046
|
+
const path = join18(deps.home, "vault.json");
|
|
87788
88047
|
let file2;
|
|
87789
88048
|
try {
|
|
87790
88049
|
file2 = await readVaultFileUnlocked(path);
|
|
@@ -88218,7 +88477,7 @@ function isRecord4(value) {
|
|
|
88218
88477
|
|
|
88219
88478
|
// ../core/src/vault-setup.ts
|
|
88220
88479
|
import { rm as rm2 } from "node:fs/promises";
|
|
88221
|
-
import { join as
|
|
88480
|
+
import { join as join19 } from "node:path";
|
|
88222
88481
|
async function createVault2(home, options) {
|
|
88223
88482
|
if (options.password === "") {
|
|
88224
88483
|
throw new KeystoreError("A password cannot be empty.");
|
|
@@ -88230,7 +88489,7 @@ async function createVault2(home, options) {
|
|
|
88230
88489
|
const hadDeviceKey = options.password !== void 0 && await options.secrets.has(VAULT_KEY_ACCOUNT);
|
|
88231
88490
|
await store.createEmptyVault();
|
|
88232
88491
|
if (options.password !== void 0) {
|
|
88233
|
-
const path =
|
|
88492
|
+
const path = join19(home, "vault.json");
|
|
88234
88493
|
try {
|
|
88235
88494
|
await protectVault({
|
|
88236
88495
|
path,
|
|
@@ -88586,7 +88845,7 @@ function assertKeyMatchesAddress(bundle) {
|
|
|
88586
88845
|
}
|
|
88587
88846
|
|
|
88588
88847
|
// ../core/src/api-key.ts
|
|
88589
|
-
import { chmod as chmod5, mkdir as mkdir17, readFile as
|
|
88848
|
+
import { chmod as chmod5, mkdir as mkdir17, readFile as readFile22, rename as rename11, writeFile as writeFile9 } from "node:fs/promises";
|
|
88590
88849
|
import { dirname as dirname11 } from "node:path";
|
|
88591
88850
|
var API_KEY_PREFIX = "vapi_sk_";
|
|
88592
88851
|
var API_KEY_PATTERN = /^vapi_sk_[A-Za-z0-9_-]{16,128}$/;
|
|
@@ -88682,7 +88941,7 @@ async function readConfigApiKey(path) {
|
|
|
88682
88941
|
async function readConfigRecord(path) {
|
|
88683
88942
|
let raw;
|
|
88684
88943
|
try {
|
|
88685
|
-
raw = await
|
|
88944
|
+
raw = await readFile22(path, "utf8");
|
|
88686
88945
|
} catch (error61) {
|
|
88687
88946
|
if (isMissingFile(error61)) return void 0;
|
|
88688
88947
|
throw error61;
|
|
@@ -89097,14 +89356,14 @@ function hostname3(resourceUrl) {
|
|
|
89097
89356
|
}
|
|
89098
89357
|
|
|
89099
89358
|
// ../sources/src/local-file.ts
|
|
89100
|
-
import { readFile as
|
|
89359
|
+
import { readFile as readFile23 } from "node:fs/promises";
|
|
89101
89360
|
import { resolve as resolve2 } from "node:path";
|
|
89102
89361
|
function localFileSource(path) {
|
|
89103
89362
|
const absolutePath = resolve2(path);
|
|
89104
89363
|
async function listings() {
|
|
89105
89364
|
let parsed;
|
|
89106
89365
|
try {
|
|
89107
|
-
parsed = JSON.parse(await
|
|
89366
|
+
parsed = JSON.parse(await readFile23(absolutePath, "utf8"));
|
|
89108
89367
|
} catch (error61) {
|
|
89109
89368
|
throw new Error(`Could not read local discovery source ${JSON.stringify(absolutePath)}.`, {
|
|
89110
89369
|
cause: error61
|
|
@@ -91873,8 +92132,8 @@ function exactPriceFact(value) {
|
|
|
91873
92132
|
}
|
|
91874
92133
|
|
|
91875
92134
|
// ../mcp/src/agent/runtime.ts
|
|
91876
|
-
import { mkdir as mkdir18, readFile as
|
|
91877
|
-
import { join as
|
|
92135
|
+
import { mkdir as mkdir18, readFile as readFile24, readdir as readdir7, rm as rm3 } from "node:fs/promises";
|
|
92136
|
+
import { join as join20 } from "node:path";
|
|
91878
92137
|
|
|
91879
92138
|
// ../mcp/src/agent/run.ts
|
|
91880
92139
|
var loopSearchResultSchema = external_exports.array(
|
|
@@ -93175,19 +93434,19 @@ var runRecordSchema = external_exports.strictObject({
|
|
|
93175
93434
|
detail: external_exports.string().optional()
|
|
93176
93435
|
});
|
|
93177
93436
|
function runsDirectory(home) {
|
|
93178
|
-
return
|
|
93437
|
+
return join20(home, "runs");
|
|
93179
93438
|
}
|
|
93180
93439
|
function runRecordPath(home, runId) {
|
|
93181
93440
|
assertRunId(runId);
|
|
93182
|
-
return
|
|
93441
|
+
return join20(runsDirectory(home), `${runId}.json`);
|
|
93183
93442
|
}
|
|
93184
93443
|
function runLogPath(home, runId) {
|
|
93185
93444
|
assertRunId(runId);
|
|
93186
|
-
return
|
|
93445
|
+
return join20(runsDirectory(home), `${runId}.log`);
|
|
93187
93446
|
}
|
|
93188
93447
|
function runResultPath(home, runId) {
|
|
93189
93448
|
assertRunId(runId);
|
|
93190
|
-
return
|
|
93449
|
+
return join20(runsDirectory(home), `${runId}.result.json`);
|
|
93191
93450
|
}
|
|
93192
93451
|
async function writeRunRecord(home, record2) {
|
|
93193
93452
|
const path = runRecordPath(home, record2.runId);
|
|
@@ -93198,7 +93457,7 @@ async function writeRunRecord(home, record2) {
|
|
|
93198
93457
|
async function readRunRecord(home, runId) {
|
|
93199
93458
|
const path = runRecordPath(home, runId);
|
|
93200
93459
|
try {
|
|
93201
|
-
return runRecordSchema.parse(JSON.parse(await
|
|
93460
|
+
return runRecordSchema.parse(JSON.parse(await readFile24(path, "utf8")));
|
|
93202
93461
|
} catch (error61) {
|
|
93203
93462
|
if (isMissingFile3(error61)) return void 0;
|
|
93204
93463
|
throw error61;
|
|
@@ -93218,7 +93477,7 @@ async function listRunRecords(home, filter = {}) {
|
|
|
93218
93477
|
if (match === null) continue;
|
|
93219
93478
|
try {
|
|
93220
93479
|
const record2 = runRecordSchema.parse(
|
|
93221
|
-
JSON.parse(await
|
|
93480
|
+
JSON.parse(await readFile24(join20(runsDirectory(home), file2), "utf8"))
|
|
93222
93481
|
);
|
|
93223
93482
|
if (record2.runId !== match[1]) continue;
|
|
93224
93483
|
if (filter.swarm !== void 0 && record2.member.swarm !== filter.swarm) continue;
|
|
@@ -93495,7 +93754,7 @@ async function stopRun(args) {
|
|
|
93495
93754
|
}
|
|
93496
93755
|
}
|
|
93497
93756
|
function memberRunLockPath(home, account) {
|
|
93498
|
-
return
|
|
93757
|
+
return join20(runsDirectory(home), `.member-${account}.lock`);
|
|
93499
93758
|
}
|
|
93500
93759
|
function summarizeRunRecord(record2) {
|
|
93501
93760
|
return {
|
|
@@ -97102,8 +97361,8 @@ function rgbToAnsi256(red, green, blue) {
|
|
|
97102
97361
|
}
|
|
97103
97362
|
|
|
97104
97363
|
// ../cli/src/accounts.ts
|
|
97105
|
-
import { readFile as
|
|
97106
|
-
import { join as
|
|
97364
|
+
import { readFile as readFile26, stat as stat16 } from "node:fs/promises";
|
|
97365
|
+
import { join as join23 } from "node:path";
|
|
97107
97366
|
|
|
97108
97367
|
// ../cli/src/dashboard.ts
|
|
97109
97368
|
import { resolve as resolve3 } from "node:path";
|
|
@@ -97114,7 +97373,12 @@ var PROBE_MODES = ["origin", "endpoint", "openapi"];
|
|
|
97114
97373
|
var PAYOUT_CHAIN_ID = "eip155:8453";
|
|
97115
97374
|
var PAYOUT_STATEMENT = "Confirm this wallet receives vAPI Call payouts";
|
|
97116
97375
|
var CLAIM_STATEMENT_PREFIX = "Claim the vAPI Call listings served from";
|
|
97117
|
-
|
|
97376
|
+
function apiKeyConsoleUrl(baseUrl) {
|
|
97377
|
+
const url2 = listingsUrl(baseUrl, "/connect");
|
|
97378
|
+
url2.search = "advanced=keys";
|
|
97379
|
+
url2.hash = "api-keys";
|
|
97380
|
+
return url2;
|
|
97381
|
+
}
|
|
97118
97382
|
var RegistryApiError = class extends Error {
|
|
97119
97383
|
constructor(status, message, body) {
|
|
97120
97384
|
super(message);
|
|
@@ -97274,7 +97538,7 @@ async function registryError(response, baseUrl) {
|
|
|
97274
97538
|
[
|
|
97275
97539
|
"The vAPI API key was rejected.",
|
|
97276
97540
|
detail,
|
|
97277
|
-
`Create a key in the console at ${
|
|
97541
|
+
`Create a key in the console at ${apiKeyConsoleUrl(baseUrl).href} and store it with vapi auth set-key.`
|
|
97278
97542
|
].filter(Boolean).join(" "),
|
|
97279
97543
|
body
|
|
97280
97544
|
);
|
|
@@ -97775,12 +98039,12 @@ function shellQuote2(value) {
|
|
|
97775
98039
|
}
|
|
97776
98040
|
|
|
97777
98041
|
// ../cli/src/status.ts
|
|
97778
|
-
import { stat as
|
|
98042
|
+
import { stat as stat15 } from "node:fs/promises";
|
|
97779
98043
|
import { homedir as homedir2 } from "node:os";
|
|
97780
98044
|
import { sep } from "node:path";
|
|
97781
98045
|
|
|
97782
98046
|
// ../core/src/cloud-backup.ts
|
|
97783
|
-
import { join as
|
|
98047
|
+
import { join as join22 } from "node:path";
|
|
97784
98048
|
|
|
97785
98049
|
// ../core/src/backup.ts
|
|
97786
98050
|
import {
|
|
@@ -97803,11 +98067,11 @@ import {
|
|
|
97803
98067
|
mkdir as mkdir19,
|
|
97804
98068
|
mkdtemp,
|
|
97805
98069
|
open as openFile,
|
|
97806
|
-
readFile as
|
|
98070
|
+
readFile as readFile25,
|
|
97807
98071
|
readdir as readdir8,
|
|
97808
98072
|
rm as rm4
|
|
97809
98073
|
} from "node:fs/promises";
|
|
97810
|
-
import { dirname as dirname12, join as
|
|
98074
|
+
import { dirname as dirname12, join as join21 } from "node:path";
|
|
97811
98075
|
var ERROR_MESSAGES = {
|
|
97812
98076
|
backup_too_large: "Backup envelope exceeds 65,536 bytes.",
|
|
97813
98077
|
backup_open_failed: "Unable to open backup.",
|
|
@@ -98090,8 +98354,8 @@ async function createBackup(options) {
|
|
|
98090
98354
|
assertDevice(options.device);
|
|
98091
98355
|
assertOwnerKey(options.ownerKey);
|
|
98092
98356
|
const createdAt = readCreatedAt(options.now ?? (() => /* @__PURE__ */ new Date()));
|
|
98093
|
-
const
|
|
98094
|
-
const nonce = readRandomBytes(
|
|
98357
|
+
const randomBytes18 = options.randomBytes ?? cryptoRandomBytes3;
|
|
98358
|
+
const nonce = readRandomBytes(randomBytes18, 12);
|
|
98095
98359
|
const salt = encodeBase64Url(options.ownerKey.salt);
|
|
98096
98360
|
const kdf = options.ownerKey.kdf === "hkdf-sha256" ? { name: "hkdf-sha256", salt } : { name: "scrypt", salt, N: SCRYPT_N2, r: SCRYPT_R2, p: SCRYPT_P2 };
|
|
98097
98361
|
const cipher = { name: CIPHER_NAME, nonce: encodeBase64Url(nonce) };
|
|
@@ -98285,7 +98549,7 @@ async function exportBackupSource(options) {
|
|
|
98285
98549
|
var BackupSnapshotChangedError = class extends Error {
|
|
98286
98550
|
};
|
|
98287
98551
|
async function exportBackupSourceAttempt(options, networks) {
|
|
98288
|
-
const path =
|
|
98552
|
+
const path = join21(options.store.home, "vault.json");
|
|
98289
98553
|
const { phrase, file: file2, accounts } = await withVaultLock(path, async () => {
|
|
98290
98554
|
const [phrase2, vault, file3] = await Promise.all([
|
|
98291
98555
|
exportVaultPhrase({ path, key: options.vaultKey }),
|
|
@@ -98421,16 +98685,16 @@ async function restoreBackupPlaintext(options) {
|
|
|
98421
98685
|
} catch {
|
|
98422
98686
|
throw new BackupError("backup_invalid_input");
|
|
98423
98687
|
}
|
|
98424
|
-
const vaultPath2 =
|
|
98425
|
-
const registryPath =
|
|
98688
|
+
const vaultPath2 = join21(options.home, "vault.json");
|
|
98689
|
+
const registryPath = join21(options.home, "wallets.json");
|
|
98426
98690
|
let stagingHome;
|
|
98427
98691
|
let beforePublishError;
|
|
98428
98692
|
let afterPublishError;
|
|
98429
98693
|
try {
|
|
98430
98694
|
await mkdir19(options.home, { recursive: true, mode: 448 });
|
|
98431
|
-
stagingHome = await mkdtemp(
|
|
98432
|
-
const stagedVaultPath =
|
|
98433
|
-
const stagedRegistryPath =
|
|
98695
|
+
stagingHome = await mkdtemp(join21(options.home, ".backup-restore-"));
|
|
98696
|
+
const stagedVaultPath = join21(stagingHome, "vault.json");
|
|
98697
|
+
const stagedRegistryPath = join21(stagingHome, "wallets.json");
|
|
98434
98698
|
await createVault({
|
|
98435
98699
|
path: stagedVaultPath,
|
|
98436
98700
|
key: options.vaultKey,
|
|
@@ -98489,7 +98753,7 @@ async function restoreBackupPlaintext(options) {
|
|
|
98489
98753
|
protected: plaintext.protected,
|
|
98490
98754
|
networks: [...plaintext.registry.networks]
|
|
98491
98755
|
};
|
|
98492
|
-
const markerPath =
|
|
98756
|
+
const markerPath = join21(options.home, RESTORE_MARKER_FILE);
|
|
98493
98757
|
const fingerprint = restoreFingerprint(
|
|
98494
98758
|
plaintext,
|
|
98495
98759
|
stagedV2?.restoreDevice ?? options.device,
|
|
@@ -98700,13 +98964,13 @@ async function stageV2Restore(options) {
|
|
|
98700
98964
|
}
|
|
98701
98965
|
const agents = [];
|
|
98702
98966
|
for (const profile of validAgents) {
|
|
98703
|
-
const stagedPath =
|
|
98967
|
+
const stagedPath = join21(options.stagingHome, "agents", `${profile.name}.json`);
|
|
98704
98968
|
if (await stageRestoreBytes(stagedPath, prettyJson(profile))) {
|
|
98705
98969
|
agents.push({
|
|
98706
98970
|
kind: "agent",
|
|
98707
98971
|
name: profile.name,
|
|
98708
98972
|
stagedPath,
|
|
98709
|
-
targetPath:
|
|
98973
|
+
targetPath: join21(options.home, "agents", `${profile.name}.json`)
|
|
98710
98974
|
});
|
|
98711
98975
|
} else {
|
|
98712
98976
|
skipped2.push({ kind: "agent", name: profile.name, reason: "write_failed" });
|
|
@@ -98726,13 +98990,13 @@ async function stageV2Restore(options) {
|
|
|
98726
98990
|
if (restoreDevice !== void 0) {
|
|
98727
98991
|
for (const value of validSwarms) {
|
|
98728
98992
|
const swarm = swarmFileSchema.parse({ ...value, device: restoreDevice });
|
|
98729
|
-
const stagedPath =
|
|
98993
|
+
const stagedPath = join21(options.stagingHome, "swarms", `${swarm.name}.json`);
|
|
98730
98994
|
if (await stageRestoreBytes(stagedPath, prettyJson(swarm))) {
|
|
98731
98995
|
swarms.push({
|
|
98732
98996
|
kind: "swarm",
|
|
98733
98997
|
name: swarm.name,
|
|
98734
98998
|
stagedPath,
|
|
98735
|
-
targetPath:
|
|
98999
|
+
targetPath: join21(options.home, "swarms", `${swarm.name}.json`)
|
|
98736
99000
|
});
|
|
98737
99001
|
} else {
|
|
98738
99002
|
skipped2.push({ kind: "swarm", name: swarm.name, reason: "write_failed" });
|
|
@@ -98742,13 +99006,13 @@ async function stageV2Restore(options) {
|
|
|
98742
99006
|
const movements = [];
|
|
98743
99007
|
for (const movement of validMovements) {
|
|
98744
99008
|
const restored = reconcileRestoredMovement(movement, assumedReceiptKeys);
|
|
98745
|
-
const stagedPath =
|
|
99009
|
+
const stagedPath = join21(options.stagingHome, "movements", `${restored.id}.json`);
|
|
98746
99010
|
if (await stageRestoreBytes(stagedPath, serializeMovement(restored))) {
|
|
98747
99011
|
movements.push({
|
|
98748
99012
|
kind: "movement",
|
|
98749
99013
|
name: restored.id,
|
|
98750
99014
|
stagedPath,
|
|
98751
|
-
targetPath:
|
|
99015
|
+
targetPath: join21(options.home, "movements", `${restored.id}.json`),
|
|
98752
99016
|
movement: restored
|
|
98753
99017
|
});
|
|
98754
99018
|
} else {
|
|
@@ -98819,8 +99083,8 @@ async function publishRestoreFile(file2, staged) {
|
|
|
98819
99083
|
let identical = false;
|
|
98820
99084
|
try {
|
|
98821
99085
|
const [source, target] = await Promise.all([
|
|
98822
|
-
|
|
98823
|
-
|
|
99086
|
+
readFile25(file2.stagedPath),
|
|
99087
|
+
readFile25(file2.targetPath)
|
|
98824
99088
|
]);
|
|
98825
99089
|
identical = source.equals(target);
|
|
98826
99090
|
} catch {
|
|
@@ -98852,7 +99116,7 @@ async function publishRestoreReceiptsLocked(staged, targetPath) {
|
|
|
98852
99116
|
let existing = "";
|
|
98853
99117
|
let existingLines = /* @__PURE__ */ new Set();
|
|
98854
99118
|
try {
|
|
98855
|
-
await
|
|
99119
|
+
await readFile25(staged.receiptsPath, "utf8");
|
|
98856
99120
|
await mkdir19(dirname12(targetPath), { recursive: true, mode: 448 });
|
|
98857
99121
|
try {
|
|
98858
99122
|
const journal = await readRestoreReceiptJournal(targetPath);
|
|
@@ -98907,7 +99171,7 @@ async function reconcilePublishedMovements(staged, home, requireDurableSafety =
|
|
|
98907
99171
|
const unjournaledKeys = new Set([...signedKeys].filter((key2) => !journaledKeys.has(key2)));
|
|
98908
99172
|
let files;
|
|
98909
99173
|
try {
|
|
98910
|
-
files = await readdir8(
|
|
99174
|
+
files = await readdir8(join21(home, "movements"));
|
|
98911
99175
|
} catch (error61) {
|
|
98912
99176
|
if (isMissingFile4(error61)) return;
|
|
98913
99177
|
if (requireDurableSafety && unjournaledKeys.size > 0) throw error61;
|
|
@@ -99008,9 +99272,9 @@ function assertRelayKey(value) {
|
|
|
99008
99272
|
throw new BackupError("relay_invalid_key");
|
|
99009
99273
|
}
|
|
99010
99274
|
}
|
|
99011
|
-
function readRelayRandomBytes(
|
|
99275
|
+
function readRelayRandomBytes(randomBytes18, length) {
|
|
99012
99276
|
try {
|
|
99013
|
-
const value =
|
|
99277
|
+
const value = randomBytes18(length);
|
|
99014
99278
|
if (!(value instanceof Uint8Array) || value.byteLength !== length) throw new Error();
|
|
99015
99279
|
return Buffer.from(value);
|
|
99016
99280
|
} catch {
|
|
@@ -99128,7 +99392,7 @@ async function createRestoreMarker(vaultPath2, registryPath, fingerprint, vaultK
|
|
|
99128
99392
|
}
|
|
99129
99393
|
async function readRestoreMarker(path, fingerprint, vaultKey) {
|
|
99130
99394
|
try {
|
|
99131
|
-
const marker = restoreMarkerSchema.parse(JSON.parse(await
|
|
99395
|
+
const marker = restoreMarkerSchema.parse(JSON.parse(await readFile25(path, "utf8")));
|
|
99132
99396
|
const expectedMac = restoreMarkerMac(marker, vaultKey);
|
|
99133
99397
|
if (marker.fingerprint !== fingerprint || !timingSafeEqual(Buffer.from(marker.mac, "hex"), Buffer.from(expectedMac, "hex"))) {
|
|
99134
99398
|
throw new Error();
|
|
@@ -99145,7 +99409,7 @@ function restoreMarkerMac(marker, vaultKey) {
|
|
|
99145
99409
|
).digest("hex");
|
|
99146
99410
|
}
|
|
99147
99411
|
async function sha256File(path) {
|
|
99148
|
-
return createHash6("sha256").update(await
|
|
99412
|
+
return createHash6("sha256").update(await readFile25(path)).digest("hex");
|
|
99149
99413
|
}
|
|
99150
99414
|
async function notifyRestorePublish(hook, step2, rememberError) {
|
|
99151
99415
|
try {
|
|
@@ -99447,7 +99711,7 @@ function copyTransferReceipt(receipt) {
|
|
|
99447
99711
|
async function readReceiptJournal(path) {
|
|
99448
99712
|
let raw;
|
|
99449
99713
|
try {
|
|
99450
|
-
raw = await
|
|
99714
|
+
raw = await readFile25(path, "utf8");
|
|
99451
99715
|
} catch (error61) {
|
|
99452
99716
|
if (isMissingFile4(error61)) return [];
|
|
99453
99717
|
throw error61;
|
|
@@ -99457,7 +99721,7 @@ async function readReceiptJournal(path) {
|
|
|
99457
99721
|
async function readRestoreReceiptJournal(path) {
|
|
99458
99722
|
let raw;
|
|
99459
99723
|
try {
|
|
99460
|
-
raw = await
|
|
99724
|
+
raw = await readFile25(path, "utf8");
|
|
99461
99725
|
} catch (error61) {
|
|
99462
99726
|
if (isMissingFile4(error61)) return { raw: "", lines: /* @__PURE__ */ new Set(), signedKeys: /* @__PURE__ */ new Set() };
|
|
99463
99727
|
throw error61;
|
|
@@ -99576,8 +99840,8 @@ function assertOwnerKey(ownerKey) {
|
|
|
99576
99840
|
assertBytes(ownerKey.key, 32);
|
|
99577
99841
|
assertBytes(ownerKey.salt, 32);
|
|
99578
99842
|
}
|
|
99579
|
-
function readRandomBytes(
|
|
99580
|
-
const value =
|
|
99843
|
+
function readRandomBytes(randomBytes18, length) {
|
|
99844
|
+
const value = randomBytes18(length);
|
|
99581
99845
|
if (!(value instanceof Uint8Array) || value.byteLength !== length) {
|
|
99582
99846
|
throw new BackupError("backup_invalid_input");
|
|
99583
99847
|
}
|
|
@@ -99816,7 +100080,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
99816
100080
|
try {
|
|
99817
100081
|
let vaultFile;
|
|
99818
100082
|
try {
|
|
99819
|
-
vaultFile = await readVaultFileUnlocked(
|
|
100083
|
+
vaultFile = await readVaultFileUnlocked(join22(options.store.home, "vault.json"));
|
|
99820
100084
|
} catch (error61) {
|
|
99821
100085
|
if (error61 instanceof VaultError && error61.code === "not_found") {
|
|
99822
100086
|
return { status: "skipped", reason: "no_vault" };
|
|
@@ -99825,7 +100089,7 @@ async function uploadBackupLocked(options, signal) {
|
|
|
99825
100089
|
}
|
|
99826
100090
|
try {
|
|
99827
100091
|
vaultKey = vaultFile.protected ? await unlockProtectedVault({
|
|
99828
|
-
path:
|
|
100092
|
+
path: join22(options.store.home, "vault.json"),
|
|
99829
100093
|
secrets: options.secrets,
|
|
99830
100094
|
env: options.env,
|
|
99831
100095
|
...options.now === void 0 ? {} : { now: options.now }
|
|
@@ -100498,7 +100762,7 @@ async function readProcessStdin() {
|
|
|
100498
100762
|
}
|
|
100499
100763
|
|
|
100500
100764
|
// ../cli/src/version.ts
|
|
100501
|
-
var CLI_VERSION = "0.
|
|
100765
|
+
var CLI_VERSION = "0.13.0";
|
|
100502
100766
|
|
|
100503
100767
|
// ../cli/src/status.ts
|
|
100504
100768
|
async function statusCommand(argv, json2, io, dependencies) {
|
|
@@ -100665,7 +100929,7 @@ function withDeadlineSignal3(fetchImpl, deadline) {
|
|
|
100665
100929
|
}
|
|
100666
100930
|
async function statusConfig(path) {
|
|
100667
100931
|
try {
|
|
100668
|
-
await
|
|
100932
|
+
await stat15(path);
|
|
100669
100933
|
} catch (error61) {
|
|
100670
100934
|
if (isMissingFile(error61)) return getDefaultConfig(process.env);
|
|
100671
100935
|
throw error61;
|
|
@@ -100863,7 +101127,7 @@ async function siblingsFetchImpl(dependencies) {
|
|
|
100863
101127
|
const configPath = getVapiPaths().config;
|
|
100864
101128
|
let config2;
|
|
100865
101129
|
try {
|
|
100866
|
-
await
|
|
101130
|
+
await stat16(configPath);
|
|
100867
101131
|
config2 = await loadConfig(configPath, process.env);
|
|
100868
101132
|
} catch (error61) {
|
|
100869
101133
|
if (!isMissingFile(error61)) throw error61;
|
|
@@ -100952,7 +101216,7 @@ ${IMPORT_USAGE}`);
|
|
|
100952
101216
|
const passphrase = await secretPrompt(dependencies)(`Passphrase for ${keystorePath}: `);
|
|
100953
101217
|
privateKey = (await exportKeystoreKeys(passphrase, keystorePath)).evm.privateKey;
|
|
100954
101218
|
} else if (keyPath !== void 0) {
|
|
100955
|
-
privateKey = (await
|
|
101219
|
+
privateKey = (await readFile26(keyPath, "utf8")).trim();
|
|
100956
101220
|
} else {
|
|
100957
101221
|
privateKey = await secretPrompt(dependencies)("Private key: ");
|
|
100958
101222
|
}
|
|
@@ -101000,10 +101264,10 @@ async function accountsRenameCommand(argv, json2, io, dependencies) {
|
|
|
101000
101264
|
{
|
|
101001
101265
|
previous: from16,
|
|
101002
101266
|
...address4 === void 0 ? {} : { address: address4 },
|
|
101003
|
-
vault:
|
|
101267
|
+
vault: join23(store.home, "vault.json"),
|
|
101004
101268
|
message: `Wallet ${from16} is now ${renamed.name}.`
|
|
101005
101269
|
},
|
|
101006
|
-
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${
|
|
101270
|
+
[`Wallet ${from16} is now ${renamed.name}.`, `Vault: ${join23(store.home, "vault.json")}`].join(
|
|
101007
101271
|
"\n"
|
|
101008
101272
|
)
|
|
101009
101273
|
);
|
|
@@ -101112,13 +101376,13 @@ async function accountsRestoreCommand(argv, json2, io, dependencies) {
|
|
|
101112
101376
|
{ name: restored.name, ...address4 === void 0 ? {} : { address: address4 } },
|
|
101113
101377
|
{
|
|
101114
101378
|
...address4 === void 0 ? {} : { address: address4 },
|
|
101115
|
-
vault:
|
|
101379
|
+
vault: join23(store.home, "vault.json"),
|
|
101116
101380
|
spendCaps: restored.entry.spendCaps,
|
|
101117
101381
|
message: `Wallet ${restored.name} restored to the device vault.`
|
|
101118
101382
|
},
|
|
101119
101383
|
[
|
|
101120
101384
|
`Wallet ${restored.name} restored to the device vault.`,
|
|
101121
|
-
`Vault: ${
|
|
101385
|
+
`Vault: ${join23(store.home, "vault.json")}`
|
|
101122
101386
|
].join("\n")
|
|
101123
101387
|
);
|
|
101124
101388
|
}
|
|
@@ -101448,7 +101712,7 @@ function formatNetworkAccounts(accounts) {
|
|
|
101448
101712
|
}
|
|
101449
101713
|
|
|
101450
101714
|
// ../cli/src/cloud-backup.ts
|
|
101451
|
-
import { join as
|
|
101715
|
+
import { join as join24 } from "node:path";
|
|
101452
101716
|
var CLOUD_BACKUP_USAGE = "Usage: vapi backup --cloud [off] [--json]";
|
|
101453
101717
|
var OWNER_RESTORE_USAGE = "Usage: vapi restore --from-owner [--owner <0x\u2026>] [--json]";
|
|
101454
101718
|
var OWNER_PATTERN2 = /^0x[0-9a-fA-F]{40}$/u;
|
|
@@ -101471,7 +101735,7 @@ async function cloudBackupCommand(argv, json2, io, dependencies) {
|
|
|
101471
101735
|
}
|
|
101472
101736
|
async function enrollCloudBackup(json2, io, dependencies) {
|
|
101473
101737
|
const paths = getVapiPaths();
|
|
101474
|
-
if (!await
|
|
101738
|
+
if (!await fileExists3(join24(paths.directory, "vault.json"))) {
|
|
101475
101739
|
throw new Error("No vault on this device. Run vapi setup first.");
|
|
101476
101740
|
}
|
|
101477
101741
|
const context = await cloudContext(io, dependencies);
|
|
@@ -101583,7 +101847,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
101583
101847
|
}
|
|
101584
101848
|
const expectedOwner = ownerValue?.toLowerCase();
|
|
101585
101849
|
const paths = getVapiPaths();
|
|
101586
|
-
if (await
|
|
101850
|
+
if (await fileExists3(join24(paths.directory, "vault.json")) && !await fileExists3(join24(paths.directory, ".backup-restore.json"))) {
|
|
101587
101851
|
throw new Error(
|
|
101588
101852
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
101589
101853
|
);
|
|
@@ -101639,7 +101903,7 @@ async function restoreFromOwnerCommand(argv, json2, io, dependencies) {
|
|
|
101639
101903
|
env: getEnvironment(dependencies),
|
|
101640
101904
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
101641
101905
|
});
|
|
101642
|
-
if (!await
|
|
101906
|
+
if (!await fileExists3(paths.config)) {
|
|
101643
101907
|
const networks = restored.networks.length === 0 ? ["base"] : restored.networks;
|
|
101644
101908
|
await writeDefaultConfig(paths.config, getEnvironment(dependencies), { networks });
|
|
101645
101909
|
}
|
|
@@ -102680,20 +102944,20 @@ function shortExcerpt(value) {
|
|
|
102680
102944
|
}
|
|
102681
102945
|
|
|
102682
102946
|
// ../cli/src/agent.ts
|
|
102683
|
-
import { readFile as
|
|
102684
|
-
import { join as
|
|
102947
|
+
import { readFile as readFile28, stat as stat17 } from "node:fs/promises";
|
|
102948
|
+
import { join as join27 } from "node:path";
|
|
102685
102949
|
import { createInterface as createInterface2 } from "node:readline/promises";
|
|
102686
102950
|
|
|
102687
102951
|
// ../cli/src/headless.ts
|
|
102688
102952
|
import { chmod as chmod7, mkdtemp as mkdtemp2, rm as rm5, writeFile as writeFile10 } from "node:fs/promises";
|
|
102689
102953
|
import { rmSync } from "node:fs";
|
|
102690
102954
|
import { tmpdir as osTmpdir } from "node:os";
|
|
102691
|
-
import { join as
|
|
102955
|
+
import { join as join25 } from "node:path";
|
|
102692
102956
|
var BUNDLE_VARIABLE_PATTERN = /^[A-Z_][A-Z0-9_]*$/u;
|
|
102693
102957
|
var REMOTE_BLOCKED_GRANTS2 = /* @__PURE__ */ new Set(["delegate", "allocate"]);
|
|
102694
102958
|
var agentProfileOptions = { schema: registeredAgentProfileSchema };
|
|
102695
102959
|
async function createHeadlessHome(bundle, options = {}) {
|
|
102696
|
-
const home = await mkdtemp2(
|
|
102960
|
+
const home = await mkdtemp2(join25(options.tmpdir ?? osTmpdir(), "vapi-headless-"));
|
|
102697
102961
|
const cleanup = async () => {
|
|
102698
102962
|
await rm5(home, { recursive: true, force: true });
|
|
102699
102963
|
};
|
|
@@ -102893,18 +103157,18 @@ import { readFile as nodeReadFile } from "node:fs/promises";
|
|
|
102893
103157
|
|
|
102894
103158
|
// ../cli/src/runtime-railway.ts
|
|
102895
103159
|
import { spawn as spawn2 } from "node:child_process";
|
|
102896
|
-
import { randomBytes as
|
|
103160
|
+
import { randomBytes as randomBytes17 } from "node:crypto";
|
|
102897
103161
|
import { closeSync, fsyncSync, mkdirSync, openSync, renameSync, rmSync as rmSync2, writeSync } from "node:fs";
|
|
102898
103162
|
import {
|
|
102899
103163
|
mkdtemp as nodeMkdtemp,
|
|
102900
103164
|
readdir as readdir9,
|
|
102901
|
-
readFile as
|
|
103165
|
+
readFile as readFile27,
|
|
102902
103166
|
rm as nodeRm,
|
|
102903
103167
|
stat as nodeStat,
|
|
102904
103168
|
writeFile as nodeWriteFile
|
|
102905
103169
|
} from "node:fs/promises";
|
|
102906
103170
|
import { tmpdir as osTmpdir2 } from "node:os";
|
|
102907
|
-
import { basename as basename4, dirname as dirname13, join as
|
|
103171
|
+
import { basename as basename4, dirname as dirname13, join as join26 } from "node:path";
|
|
102908
103172
|
var RAILWAY_CLI = {
|
|
102909
103173
|
binary: "railway",
|
|
102910
103174
|
create: (options) => [
|
|
@@ -103076,7 +103340,7 @@ async function assertRemoteSafeMember(args) {
|
|
|
103076
103340
|
}
|
|
103077
103341
|
function railwaySidecarPath(home, runId) {
|
|
103078
103342
|
if (!isRunId(runId)) throw new RuntimeError("invalid_run_id", `Invalid run id: ${runId}.`);
|
|
103079
|
-
return
|
|
103343
|
+
return join26(runsDirectory(home), `${runId}.railway.json`);
|
|
103080
103344
|
}
|
|
103081
103345
|
function createRailwayRuntime(options) {
|
|
103082
103346
|
const { home } = options;
|
|
@@ -103401,10 +103665,10 @@ function createRailwayRuntime(options) {
|
|
|
103401
103665
|
let createError;
|
|
103402
103666
|
let cleanupError;
|
|
103403
103667
|
try {
|
|
103404
|
-
directory = await fs.mkdtemp(
|
|
103668
|
+
directory = await fs.mkdtemp(join26(options.tmpdir ?? osTmpdir2(), "vapi-railway-"));
|
|
103405
103669
|
assertNotInterrupted();
|
|
103406
103670
|
await assertMode(fs, directory, 448, "env-file directory");
|
|
103407
|
-
envFile =
|
|
103671
|
+
envFile = join26(directory, "member.env");
|
|
103408
103672
|
await fs.writeFile(envFile, `${RAILWAY_CLI.bundleVariable}=${bundle}
|
|
103409
103673
|
`, {
|
|
103410
103674
|
encoding: "utf8",
|
|
@@ -103859,9 +104123,9 @@ async function writeSidecar(home, runId, sidecar) {
|
|
|
103859
104123
|
function writeSidecarSync(path, sidecar) {
|
|
103860
104124
|
const directory = dirname13(path);
|
|
103861
104125
|
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
103862
|
-
const temporary =
|
|
104126
|
+
const temporary = join26(
|
|
103863
104127
|
directory,
|
|
103864
|
-
`.${basename4(path)}.${process.pid}.${
|
|
104128
|
+
`.${basename4(path)}.${process.pid}.${randomBytes17(6).toString("hex")}.tmp`
|
|
103865
104129
|
);
|
|
103866
104130
|
try {
|
|
103867
104131
|
const descriptor2 = openSync(temporary, "wx", 384);
|
|
@@ -103899,7 +104163,7 @@ var LEGACY_SIDECAR_KEYS = ["checkpoint", "keepSandbox", "sandboxId", "v"];
|
|
|
103899
104163
|
async function readSidecar(home, runId) {
|
|
103900
104164
|
let parsed;
|
|
103901
104165
|
try {
|
|
103902
|
-
parsed = JSON.parse(await
|
|
104166
|
+
parsed = JSON.parse(await readFile27(railwaySidecarPath(home, runId), "utf8"));
|
|
103903
104167
|
} catch {
|
|
103904
104168
|
return void 0;
|
|
103905
104169
|
}
|
|
@@ -103957,7 +104221,7 @@ async function assertMode(fs, path, mode, what) {
|
|
|
103957
104221
|
}
|
|
103958
104222
|
}
|
|
103959
104223
|
async function deviceVaultKey(home, secrets, now) {
|
|
103960
|
-
const path =
|
|
104224
|
+
const path = join26(home, "vault.json");
|
|
103961
104225
|
const metadata = await readVaultFileUnlocked(path);
|
|
103962
104226
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
103963
104227
|
path,
|
|
@@ -104012,7 +104276,7 @@ function createLocalRuntime(options) {
|
|
|
104012
104276
|
const processCommand = options.processCommand ?? defaultProcessCommand;
|
|
104013
104277
|
const ownsProcess = (handle, pid) => processCommand(pid)?.includes(runResultPath(home, handle.runId)) === true;
|
|
104014
104278
|
const closeFd = options.closeFd ?? closeSync2;
|
|
104015
|
-
const
|
|
104279
|
+
const readFile34 = options.readFile ?? nodeReadFile;
|
|
104016
104280
|
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
104017
104281
|
const openLog = options.openLog ?? ((path) => {
|
|
104018
104282
|
mkdirSync2(runsDirectory(home), { recursive: true, mode: 448 });
|
|
@@ -104067,7 +104331,7 @@ function createLocalRuntime(options) {
|
|
|
104067
104331
|
return handle;
|
|
104068
104332
|
},
|
|
104069
104333
|
async status(handle) {
|
|
104070
|
-
const result = await readResultFile(
|
|
104334
|
+
const result = await readResultFile(readFile34, runResultPath(home, handle.runId));
|
|
104071
104335
|
if (result !== void 0) return result;
|
|
104072
104336
|
const pid = localPid(handle);
|
|
104073
104337
|
if (pid === void 0 || handle.kind !== "local") {
|
|
@@ -104170,10 +104434,10 @@ function childArguments(member, run) {
|
|
|
104170
104434
|
...run.drawUsd ? ["--draw", run.drawUsd] : []
|
|
104171
104435
|
];
|
|
104172
104436
|
}
|
|
104173
|
-
async function readResultFile(
|
|
104437
|
+
async function readResultFile(readFile34, path) {
|
|
104174
104438
|
let text;
|
|
104175
104439
|
try {
|
|
104176
|
-
text = await
|
|
104440
|
+
text = await readFile34(path, "utf8");
|
|
104177
104441
|
} catch (error61) {
|
|
104178
104442
|
if (hasCode3(error61, "ENOENT")) return void 0;
|
|
104179
104443
|
return { state: "failed", detail: "unreadable result file" };
|
|
@@ -104298,7 +104562,7 @@ async function createCommand(argv, json2, io, dependencies) {
|
|
|
104298
104562
|
if (await profileFileExists(paths.agentsDir, name)) {
|
|
104299
104563
|
throw new Error(`Agent ${name} already exists.`);
|
|
104300
104564
|
}
|
|
104301
|
-
const instructions = await
|
|
104565
|
+
const instructions = await readFile28(instructionsPath, "utf8");
|
|
104302
104566
|
if (instructions.length > 2e4) {
|
|
104303
104567
|
throw new UsageError("--instructions must contain at most 20000 characters.");
|
|
104304
104568
|
}
|
|
@@ -104884,7 +105148,7 @@ function explicitWallet(name) {
|
|
|
104884
105148
|
}
|
|
104885
105149
|
async function profileFileExists(directory, name) {
|
|
104886
105150
|
try {
|
|
104887
|
-
await
|
|
105151
|
+
await stat17(join27(directory, `${name}.json`));
|
|
104888
105152
|
return true;
|
|
104889
105153
|
} catch (error61) {
|
|
104890
105154
|
if (isMissingFile(error61)) return false;
|
|
@@ -104945,7 +105209,7 @@ function usd(value, minimumDecimals = 0) {
|
|
|
104945
105209
|
|
|
104946
105210
|
// ../cli/src/mcp-install.ts
|
|
104947
105211
|
import { spawn as spawn3 } from "node:child_process";
|
|
104948
|
-
import { mkdir as mkdir20, readFile as
|
|
105212
|
+
import { mkdir as mkdir20, readFile as readFile29, writeFile as writeFile11 } from "node:fs/promises";
|
|
104949
105213
|
import { homedir as systemHomedir } from "node:os";
|
|
104950
105214
|
import { dirname as dirname14, posix, win32 as win322 } from "node:path";
|
|
104951
105215
|
|
|
@@ -105325,7 +105589,7 @@ function isRecord12(value) {
|
|
|
105325
105589
|
}
|
|
105326
105590
|
async function readExistingFile(path) {
|
|
105327
105591
|
try {
|
|
105328
|
-
return await
|
|
105592
|
+
return await readFile29(path, "utf8");
|
|
105329
105593
|
} catch (error61) {
|
|
105330
105594
|
if (isMissingFile(error61)) return void 0;
|
|
105331
105595
|
throw error61;
|
|
@@ -105333,7 +105597,7 @@ async function readExistingFile(path) {
|
|
|
105333
105597
|
}
|
|
105334
105598
|
async function pathExists5(path) {
|
|
105335
105599
|
try {
|
|
105336
|
-
await
|
|
105600
|
+
await readFile29(path);
|
|
105337
105601
|
return true;
|
|
105338
105602
|
} catch (error61) {
|
|
105339
105603
|
if (isMissingFile(error61)) return false;
|
|
@@ -105343,15 +105607,15 @@ async function pathExists5(path) {
|
|
|
105343
105607
|
|
|
105344
105608
|
// ../cli/src/code.ts
|
|
105345
105609
|
import { constants as constants2 } from "node:fs";
|
|
105346
|
-
import { access, mkdir as mkdir21, readFile as
|
|
105610
|
+
import { access, mkdir as mkdir21, readFile as readFile30, realpath, unlink as unlink13, writeFile as writeFile12 } from "node:fs/promises";
|
|
105347
105611
|
import { homedir as homedir3 } from "node:os";
|
|
105348
|
-
import { basename as basename5, dirname as dirname15, join as
|
|
105612
|
+
import { basename as basename5, dirname as dirname15, join as join28, posix as posix2, win32 as win323 } from "node:path";
|
|
105349
105613
|
var VAPI_CODEX_PROVIDER = "vapi";
|
|
105350
105614
|
var VAPI_CODEX_PROFILE = "vapi";
|
|
105351
105615
|
var VAPI_CODEX_DEFAULT_MODEL = "venice/openai-gpt-61-sol";
|
|
105352
105616
|
var VAPI_ROUTER_KEY_ENV = "VAPI_ROUTER_KEY";
|
|
105353
105617
|
function codexConfigPath(env, home) {
|
|
105354
|
-
return
|
|
105618
|
+
return join28(env.CODEX_HOME || join28(home, ".codex"), "config.toml");
|
|
105355
105619
|
}
|
|
105356
105620
|
function hasVapiCodexProfile(contents) {
|
|
105357
105621
|
const roots = new Set(
|
|
@@ -105445,7 +105709,7 @@ function aliasContents(original, tools) {
|
|
|
105445
105709
|
}
|
|
105446
105710
|
async function readOptional(path) {
|
|
105447
105711
|
try {
|
|
105448
|
-
return await
|
|
105712
|
+
return await readFile30(path, "utf8");
|
|
105449
105713
|
} catch (error61) {
|
|
105450
105714
|
if (isMissingFile(error61)) return void 0;
|
|
105451
105715
|
throw error61;
|
|
@@ -105467,7 +105731,7 @@ async function codeCommand(argv, json2, io, dependencies) {
|
|
|
105467
105731
|
const env = getEnvironment(dependencies);
|
|
105468
105732
|
const home = dependencies.code?.homedir ?? homedir3();
|
|
105469
105733
|
const config2 = codexConfigPath(env, home);
|
|
105470
|
-
const rcPaths = [
|
|
105734
|
+
const rcPaths = [join28(home, ".zshrc"), join28(home, ".bashrc")];
|
|
105471
105735
|
if (command === "uninstall") {
|
|
105472
105736
|
const removed = [];
|
|
105473
105737
|
const previous = await readOptional(config2);
|
|
@@ -105591,7 +105855,7 @@ async function codeCommand(argv, json2, io, dependencies) {
|
|
|
105591
105855
|
|
|
105592
105856
|
// ../cli/src/code-launch.ts
|
|
105593
105857
|
import { spawn as spawn4 } from "node:child_process";
|
|
105594
|
-
import { readFile as
|
|
105858
|
+
import { readFile as readFile31 } from "node:fs/promises";
|
|
105595
105859
|
import { constants as constants3, homedir as homedir4 } from "node:os";
|
|
105596
105860
|
var CLAUDE_MODELS = {
|
|
105597
105861
|
sonnet: "venice/claude-sonnet-5-5",
|
|
@@ -105805,7 +106069,7 @@ function claudeModel(model) {
|
|
|
105805
106069
|
async function codexArgs(env, baseURL, model, dependencies) {
|
|
105806
106070
|
let contents = "";
|
|
105807
106071
|
try {
|
|
105808
|
-
contents = await
|
|
106072
|
+
contents = await readFile31(
|
|
105809
106073
|
codexConfigPath(env, dependencies.code?.homedir ?? homedir4()),
|
|
105810
106074
|
"utf8"
|
|
105811
106075
|
);
|
|
@@ -105980,7 +106244,7 @@ async function sendConfig(dependencies) {
|
|
|
105980
106244
|
|
|
105981
106245
|
// ../cli/src/setup.ts
|
|
105982
106246
|
import { rm as rm6 } from "node:fs/promises";
|
|
105983
|
-
import { join as
|
|
106247
|
+
import { join as join29 } from "node:path";
|
|
105984
106248
|
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.`;
|
|
105985
106249
|
var VAULT_CHOICE = "Create a new vault, or restore one from a recovery phrase? [new/restore] ";
|
|
105986
106250
|
async function setupCommand(argv, json2, io, dependencies) {
|
|
@@ -105999,18 +106263,24 @@ async function setupCommand(argv, json2, io, dependencies) {
|
|
|
105999
106263
|
const steps = [];
|
|
106000
106264
|
const humanIo = json2 ? stderrIo(io) : io;
|
|
106001
106265
|
const accountCount = parseAccountCount(parsed.one("--accounts"));
|
|
106002
|
-
if (!await
|
|
106266
|
+
if (!await fileExists3(paths.config)) {
|
|
106003
106267
|
await writeDefaultConfig(paths.config, process.env, { networks: ["base"] });
|
|
106004
106268
|
steps.push("config");
|
|
106005
106269
|
}
|
|
106006
106270
|
const config2 = await readConfig(paths.config, humanIo);
|
|
106271
|
+
if (!await fileExists3(join29(paths.directory, "vault.json"))) {
|
|
106272
|
+
const os = dependencies.secretBackendProbe ?? (dependencies.secretStore === void 0 ? osSecretStore() : void 0);
|
|
106273
|
+
if (os !== void 0) {
|
|
106274
|
+
await chooseSecretBackend({ home: paths.directory, os, env: getEnvironment(dependencies) });
|
|
106275
|
+
}
|
|
106276
|
+
}
|
|
106007
106277
|
let store = await openWalletStore(dependencies);
|
|
106008
106278
|
let vault = "existing";
|
|
106009
106279
|
let changedVault = false;
|
|
106010
106280
|
let changedAccount = false;
|
|
106011
106281
|
let changedLink = false;
|
|
106012
106282
|
let scannedAddresses;
|
|
106013
|
-
if (!await
|
|
106283
|
+
if (!await fileExists3(join29(paths.directory, "vault.json"))) {
|
|
106014
106284
|
const choice = await vaultChoice(dependencies);
|
|
106015
106285
|
if (choice === "restore") {
|
|
106016
106286
|
if (!isInteractive(dependencies)) {
|
|
@@ -106098,7 +106368,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
106098
106368
|
let scannedAddresses = 0;
|
|
106099
106369
|
try {
|
|
106100
106370
|
const restored = await restoreVault({
|
|
106101
|
-
path:
|
|
106371
|
+
path: join29(paths.directory, "vault.json"),
|
|
106102
106372
|
key: key2,
|
|
106103
106373
|
phrase: validatedPhrase,
|
|
106104
106374
|
probe: async (address4) => await readBalance3(address4) > 0n,
|
|
@@ -106109,7 +106379,7 @@ async function restoreVaultFromPhrase(phrase, config2, io, dependencies, account
|
|
|
106109
106379
|
...dependencies.now === void 0 ? {} : { now: dependencies.now }
|
|
106110
106380
|
});
|
|
106111
106381
|
names = restored.accounts().map((account) => account.name);
|
|
106112
|
-
await rm6(
|
|
106382
|
+
await rm6(join29(paths.directory, "wallets.json"), { force: true });
|
|
106113
106383
|
} finally {
|
|
106114
106384
|
key2.fill(0);
|
|
106115
106385
|
}
|
|
@@ -106227,7 +106497,7 @@ async function withRouterError2(operation) {
|
|
|
106227
106497
|
|
|
106228
106498
|
// ../cli/src/task.ts
|
|
106229
106499
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
106230
|
-
import { readFile as
|
|
106500
|
+
import { readFile as readFile32 } from "node:fs/promises";
|
|
106231
106501
|
var TASK_HELP = `Usage:
|
|
106232
106502
|
vapi task search [--open] [--min <usd>] [--tab trending|new|closing|paid] [--limit <n>] [--json]
|
|
106233
106503
|
vapi task show <id> [--account <name>] [--json]
|
|
@@ -106563,7 +106833,7 @@ async function taskCommandInner(argv, json2, io, dependencies) {
|
|
|
106563
106833
|
if (maxAwards !== void 0 && maxAwards > TASK_LIMITS.maxAwardsMax)
|
|
106564
106834
|
throw new UsageError("--max-awards must be between 1 and 50.");
|
|
106565
106835
|
if (parsed.one("--webhook") !== void 0) httpsUrl2(parsed.one("--webhook"), "--webhook");
|
|
106566
|
-
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await
|
|
106836
|
+
const brief = briefPath === "-" ? await (dependencies.readStdin ?? readProcessStdin2)() : await readFile32(briefPath, "utf8");
|
|
106567
106837
|
const input2 = {
|
|
106568
106838
|
title: title.trim(),
|
|
106569
106839
|
description: brief.trim(),
|
|
@@ -108241,7 +108511,7 @@ async function referencedSleep(milliseconds, signal) {
|
|
|
108241
108511
|
}
|
|
108242
108512
|
|
|
108243
108513
|
// ../cli/src/vault.ts
|
|
108244
|
-
import { join as
|
|
108514
|
+
import { join as join30 } from "node:path";
|
|
108245
108515
|
var VAULT_USAGE = "Usage: vapi vault protect|unprotect|lock|unlock|status [--json]";
|
|
108246
108516
|
var RESTORE_USAGE = "Usage: vapi restore [--accounts <n> | --from-owner [--owner <0x\u2026>]] [--json]";
|
|
108247
108517
|
var LEGACY_PASSWORD_NOTICE = "VAPI_KEYSTORE_PASSWORD is deprecated for vault passwords; use VAPI_VAULT_PASSWORD instead.";
|
|
@@ -108285,13 +108555,13 @@ async function restoreCommand(argv, json2, io, dependencies) {
|
|
|
108285
108555
|
}
|
|
108286
108556
|
const accountCount = parseRestoreAccountCount(parsed.one("--accounts"));
|
|
108287
108557
|
const paths = getVapiPaths();
|
|
108288
|
-
const path =
|
|
108289
|
-
if (await
|
|
108558
|
+
const path = join30(paths.directory, "vault.json");
|
|
108559
|
+
if (await fileExists3(path)) {
|
|
108290
108560
|
throw new Error(
|
|
108291
108561
|
`A vault already exists in ${paths.directory}. Move it aside before restoring.`
|
|
108292
108562
|
);
|
|
108293
108563
|
}
|
|
108294
|
-
if (!await
|
|
108564
|
+
if (!await fileExists3(paths.config)) {
|
|
108295
108565
|
await writeDefaultConfig(paths.config, process.env, { networks: ["base"] });
|
|
108296
108566
|
}
|
|
108297
108567
|
const config2 = await readConfig(paths.config, json2 ? quietIo(io) : io);
|
|
@@ -108442,7 +108712,7 @@ function requireNoArguments(argv) {
|
|
|
108442
108712
|
parseArguments(argv, { valueOptions: /* @__PURE__ */ new Set(), maximumPositionals: 0 });
|
|
108443
108713
|
}
|
|
108444
108714
|
function vaultPath() {
|
|
108445
|
-
return
|
|
108715
|
+
return join30(getVapiPaths().directory, "vault.json");
|
|
108446
108716
|
}
|
|
108447
108717
|
function quietIo(io) {
|
|
108448
108718
|
return { stdout: () => void 0, stderr: io.stderr };
|
|
@@ -108893,7 +109163,7 @@ async function runCli(argv = process.argv.slice(2), io = processIo, dependencies
|
|
|
108893
109163
|
break;
|
|
108894
109164
|
case "unlock":
|
|
108895
109165
|
io.stderr("vapi unlock is now vapi vault unlock; the old name works for one release.");
|
|
108896
|
-
if (await
|
|
109166
|
+
if (await fileExists3(join31(getVapiPaths().directory, "vault.json"))) {
|
|
108897
109167
|
parseArguments(args.slice(1), {
|
|
108898
109168
|
valueOptions: /* @__PURE__ */ new Set([WALLET_OPTION5]),
|
|
108899
109169
|
maximumPositionals: 0
|
|
@@ -109081,7 +109351,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
109081
109351
|
await recordAudit(dependencies, "wallet.create", { wallet: created.name });
|
|
109082
109352
|
const account = created.account;
|
|
109083
109353
|
if (!json2) await showRecoveryPhrase(created.recoveryPhrase, io, dependencies);
|
|
109084
|
-
if (!await
|
|
109354
|
+
if (!await fileExists3(paths.config)) {
|
|
109085
109355
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
109086
109356
|
} else {
|
|
109087
109357
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -109099,7 +109369,7 @@ async function initCommand(argv, json2, io, dependencies) {
|
|
|
109099
109369
|
address: account.address,
|
|
109100
109370
|
accounts,
|
|
109101
109371
|
config: paths.config,
|
|
109102
|
-
vault:
|
|
109372
|
+
vault: join31(paths.directory, "vault.json"),
|
|
109103
109373
|
...configRewrites.length > 0 ? { configRewrites } : {},
|
|
109104
109374
|
custody: "self",
|
|
109105
109375
|
warning: CUSTODY_NOTICE,
|
|
@@ -109229,7 +109499,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
109229
109499
|
await recordAudit(dependencies, "wallet.create", { wallet: created.name });
|
|
109230
109500
|
const account = created.account;
|
|
109231
109501
|
if (!json2) await showRecoveryPhrase(created.recoveryPhrase, io, dependencies);
|
|
109232
|
-
if (!await
|
|
109502
|
+
if (!await fileExists3(paths.config)) {
|
|
109233
109503
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
109234
109504
|
} else {
|
|
109235
109505
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -109238,7 +109508,7 @@ async function walletCreateCommand(argv, json2, io, dependencies) {
|
|
|
109238
109508
|
const result = {
|
|
109239
109509
|
address: account.address,
|
|
109240
109510
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
109241
|
-
vault:
|
|
109511
|
+
vault: join31(paths.directory, "vault.json"),
|
|
109242
109512
|
...label === void 0 ? {} : { label },
|
|
109243
109513
|
spendCaps: created.entry.spendCaps,
|
|
109244
109514
|
isDefault,
|
|
@@ -109278,7 +109548,7 @@ function formatCaps2(caps) {
|
|
|
109278
109548
|
function walletListResult(store, wallets, unlocked) {
|
|
109279
109549
|
return {
|
|
109280
109550
|
default: store.defaultName ?? null,
|
|
109281
|
-
vault:
|
|
109551
|
+
vault: join31(store.home, "vault.json"),
|
|
109282
109552
|
wallets: wallets.map((wallet) => ({
|
|
109283
109553
|
name: wallet.name,
|
|
109284
109554
|
...wallet.address === void 0 ? {} : { address: wallet.address },
|
|
@@ -110294,7 +110564,7 @@ function sameOrigin2(left, right) {
|
|
|
110294
110564
|
function noApiKeyMessage(baseUrl) {
|
|
110295
110565
|
return [
|
|
110296
110566
|
"No vAPI API key on this machine.",
|
|
110297
|
-
`Create one in the console at ${
|
|
110567
|
+
`Create one in the console at ${apiKeyConsoleUrl(baseUrl).href}, then store it with vapi auth set-key.`,
|
|
110298
110568
|
`In CI, set ${API_KEY_ENV} instead.`
|
|
110299
110569
|
].join("\n");
|
|
110300
110570
|
}
|
|
@@ -110551,7 +110821,7 @@ function formatClaimed(origin, claimed) {
|
|
|
110551
110821
|
}
|
|
110552
110822
|
var EXPORT_KEY_WARNING = "Anyone with this key can spend the wallet. Never paste it into a website or chat.";
|
|
110553
110823
|
async function deviceVaultKey2(store, dependencies) {
|
|
110554
|
-
const path =
|
|
110824
|
+
const path = join31(store.home, "vault.json");
|
|
110555
110825
|
const metadata = await readVaultFileUnlocked(path);
|
|
110556
110826
|
const secrets = getSecretStore(dependencies);
|
|
110557
110827
|
const key2 = metadata.protected ? await unlockProtectedVault({
|
|
@@ -110644,7 +110914,7 @@ async function backupCommand(argv, json2, io, dependencies) {
|
|
|
110644
110914
|
const target = await targetWallet(parsed, dependencies);
|
|
110645
110915
|
const vaultAccount = await target.store.hasVaultAccount(target.name);
|
|
110646
110916
|
if (vaultAccount) {
|
|
110647
|
-
const vault = await readVaultFileUnlocked(
|
|
110917
|
+
const vault = await readVaultFileUnlocked(join31(target.store.home, "vault.json"));
|
|
110648
110918
|
if (vault.accounts.some((account) => account.name === target.name && account.kind === "imported")) {
|
|
110649
110919
|
throw new KeystoreError(
|
|
110650
110920
|
`Account ${target.name} was imported and is not recoverable from the vault phrase. Back it up with vapi export-key --account ${target.name}.`
|
|
@@ -110721,7 +110991,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
110721
110991
|
const existed = store.has(name);
|
|
110722
110992
|
if (existed && !parsed.has("--replace")) {
|
|
110723
110993
|
const address4 = await store.readAddress(name);
|
|
110724
|
-
const location = await store.hasVaultAccount(name) ?
|
|
110994
|
+
const location = await store.hasVaultAccount(name) ? join31(store.home, "vault.json") : store.pathFor(name);
|
|
110725
110995
|
throw new Error(
|
|
110726
110996
|
[
|
|
110727
110997
|
`Wallet ${name} already exists at ${location}.`,
|
|
@@ -110749,7 +111019,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
110749
111019
|
const imported = fromPhrase ? await store.create(name, "", { phrase: secret }) : await store.importKey(name, "", secret);
|
|
110750
111020
|
await recordAudit(dependencies, "wallet.import", { wallet: imported.name });
|
|
110751
111021
|
const account = imported.account;
|
|
110752
|
-
if (!await
|
|
111022
|
+
if (!await fileExists3(paths.config)) {
|
|
110753
111023
|
await writeDefaultConfig(paths.config, process.env, { networks });
|
|
110754
111024
|
} else {
|
|
110755
111025
|
if (enableArc) await enableDefaultNetwork("arc", paths.config);
|
|
@@ -110757,7 +111027,7 @@ async function importCommand(argv, json2, io, dependencies) {
|
|
|
110757
111027
|
const result = {
|
|
110758
111028
|
address: account.address,
|
|
110759
111029
|
...account.solana ? { solanaAddress: account.solana.address } : {},
|
|
110760
|
-
vault:
|
|
111030
|
+
vault: join31(paths.directory, "vault.json"),
|
|
110761
111031
|
...previousKeystore ? { previousKeystore } : {},
|
|
110762
111032
|
message: "Wallet imported. Its encrypted key stays on this machine."
|
|
110763
111033
|
};
|
|
@@ -111365,9 +111635,9 @@ function isHttpUrl2(value) {
|
|
|
111365
111635
|
return false;
|
|
111366
111636
|
}
|
|
111367
111637
|
}
|
|
111368
|
-
async function
|
|
111638
|
+
async function fileExists3(path) {
|
|
111369
111639
|
try {
|
|
111370
|
-
await
|
|
111640
|
+
await stat18(path);
|
|
111371
111641
|
return true;
|
|
111372
111642
|
} catch (error61) {
|
|
111373
111643
|
if (isMissingFile(error61)) return false;
|
|
@@ -111389,7 +111659,7 @@ function parseInitNetworks(value) {
|
|
|
111389
111659
|
|
|
111390
111660
|
// ../cli/src/update-check.ts
|
|
111391
111661
|
import { lookup } from "node:dns/promises";
|
|
111392
|
-
import { mkdir as mkdir22, readFile as
|
|
111662
|
+
import { mkdir as mkdir22, readFile as readFile33, writeFile as writeFile13 } from "node:fs/promises";
|
|
111393
111663
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
111394
111664
|
var CHECK_TIMEOUT_MS = 1500;
|
|
111395
111665
|
var LATEST_URL = "https://registry.npmjs.org/vapi-network/latest";
|
|
@@ -111433,7 +111703,7 @@ async function latestNotice(options, env, signal) {
|
|
|
111433
111703
|
const now = (options.nowMs ?? Date.now)();
|
|
111434
111704
|
let cached2;
|
|
111435
111705
|
try {
|
|
111436
|
-
const value = JSON.parse(await
|
|
111706
|
+
const value = JSON.parse(await readFile33(paths.updateCheck, "utf8"));
|
|
111437
111707
|
if (isRecord13(value) && typeof value.checkedAt === "number" && Number.isFinite(value.checkedAt) && typeof value.latest === "string" && parseVersion(value.latest)) {
|
|
111438
111708
|
cached2 = { checkedAt: value.checkedAt, latest: value.latest };
|
|
111439
111709
|
}
|
|
@@ -111515,14 +111785,14 @@ function isNewerVersion(latest, current) {
|
|
|
111515
111785
|
|
|
111516
111786
|
// src/client.ts
|
|
111517
111787
|
import { homedir as homedir5 } from "node:os";
|
|
111518
|
-
import { join as
|
|
111788
|
+
import { join as join32 } from "node:path";
|
|
111519
111789
|
var ACCOUNT_NOT_LINKED = "Not linked. Run vapi login on this machine, or set VAPI_HOME to a linked home.";
|
|
111520
111790
|
var DISCOVERY_PATH2 = "/api/call/discovery";
|
|
111521
111791
|
var warnedWalletOption = false;
|
|
111522
111792
|
async function createVapiClient(options = {}) {
|
|
111523
111793
|
if (options.wallet !== void 0) warnWalletOption();
|
|
111524
111794
|
const env = options.env ?? process.env;
|
|
111525
|
-
const home = options.home ?? (env.VAPI_HOME?.trim() ||
|
|
111795
|
+
const home = options.home ?? (env.VAPI_HOME?.trim() || join32(homedir5(), ".vapi"));
|
|
111526
111796
|
const paths = getVapiPaths(home);
|
|
111527
111797
|
const requestedName = typeof options.account === "string" ? options.account : options.wallet;
|
|
111528
111798
|
const injected = typeof options.account === "object" ? options.account : void 0;
|