zk-credits 0.2.1 → 0.2.2
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 +32 -18
- package/dist/cli.js +91 -22
- package/dist/setup-config.d.ts +36 -0
- package/dist/setup-config.js +320 -0
- package/dist/zk-credits.js +495 -142
- package/package.json +1 -1
- package/dist/setup-preflight.d.ts +0 -2
- package/dist/setup-preflight.js +0 -12
package/dist/zk-credits.js
CHANGED
|
@@ -34651,7 +34651,7 @@ var require_lib = __commonJS({
|
|
|
34651
34651
|
};
|
|
34652
34652
|
}
|
|
34653
34653
|
// @__NO_SIDE_EFFECTS__
|
|
34654
|
-
function
|
|
34654
|
+
function join7(separator = "") {
|
|
34655
34655
|
astr("join", separator);
|
|
34656
34656
|
return {
|
|
34657
34657
|
encode: (from) => {
|
|
@@ -34867,15 +34867,15 @@ var require_lib = __commonJS({
|
|
|
34867
34867
|
convertRadix2,
|
|
34868
34868
|
radix,
|
|
34869
34869
|
radix2,
|
|
34870
|
-
join:
|
|
34870
|
+
join: join7,
|
|
34871
34871
|
padding
|
|
34872
34872
|
};
|
|
34873
|
-
exports.base16 = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(4), /* @__PURE__ */ alphabet("0123456789ABCDEF"), /* @__PURE__ */
|
|
34874
|
-
exports.base32 = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), /* @__PURE__ */ padding(5), /* @__PURE__ */
|
|
34875
|
-
exports.base32nopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), /* @__PURE__ */
|
|
34876
|
-
exports.base32hex = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), /* @__PURE__ */ padding(5), /* @__PURE__ */
|
|
34877
|
-
exports.base32hexnopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), /* @__PURE__ */
|
|
34878
|
-
exports.base32crockford = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), /* @__PURE__ */
|
|
34873
|
+
exports.base16 = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(4), /* @__PURE__ */ alphabet("0123456789ABCDEF"), /* @__PURE__ */ join7(""));
|
|
34874
|
+
exports.base32 = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), /* @__PURE__ */ padding(5), /* @__PURE__ */ join7(""));
|
|
34875
|
+
exports.base32nopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), /* @__PURE__ */ join7(""));
|
|
34876
|
+
exports.base32hex = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), /* @__PURE__ */ padding(5), /* @__PURE__ */ join7(""));
|
|
34877
|
+
exports.base32hexnopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), /* @__PURE__ */ join7(""));
|
|
34878
|
+
exports.base32crockford = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), /* @__PURE__ */ join7(""), /* @__PURE__ */ normalize((s) => s.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
34879
34879
|
var hasBase64Builtin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toBase64 === "function" && typeof Uint8Array.fromBase64 === "function")();
|
|
34880
34880
|
var decodeBase64Builtin = (s, isUrl) => {
|
|
34881
34881
|
astr("base64", s);
|
|
@@ -34893,8 +34893,8 @@ var require_lib = __commonJS({
|
|
|
34893
34893
|
decode(s) {
|
|
34894
34894
|
return decodeBase64Builtin(s, false);
|
|
34895
34895
|
}
|
|
34896
|
-
} : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding(6), /* @__PURE__ */
|
|
34897
|
-
exports.base64nopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */
|
|
34896
|
+
} : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding(6), /* @__PURE__ */ join7(""));
|
|
34897
|
+
exports.base64nopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ join7(""));
|
|
34898
34898
|
exports.base64url = hasBase64Builtin ? {
|
|
34899
34899
|
encode(b) {
|
|
34900
34900
|
abytes(b);
|
|
@@ -34903,9 +34903,9 @@ var require_lib = __commonJS({
|
|
|
34903
34903
|
decode(s) {
|
|
34904
34904
|
return decodeBase64Builtin(s, true);
|
|
34905
34905
|
}
|
|
34906
|
-
} : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), /* @__PURE__ */ padding(6), /* @__PURE__ */
|
|
34907
|
-
exports.base64urlnopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), /* @__PURE__ */
|
|
34908
|
-
var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */
|
|
34906
|
+
} : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), /* @__PURE__ */ padding(6), /* @__PURE__ */ join7(""));
|
|
34907
|
+
exports.base64urlnopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), /* @__PURE__ */ join7(""));
|
|
34908
|
+
var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join7(""));
|
|
34909
34909
|
exports.base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
34910
34910
|
exports.base58flickr = /* @__PURE__ */ genBase58("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
34911
34911
|
exports.base58xrp = /* @__PURE__ */ genBase58("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");
|
|
@@ -34937,7 +34937,7 @@ var require_lib = __commonJS({
|
|
|
34937
34937
|
var createBase58check = (sha256) => /* @__PURE__ */ chain(checksum(4, (data) => sha256(sha256(data))), exports.base58);
|
|
34938
34938
|
exports.createBase58check = createBase58check;
|
|
34939
34939
|
exports.base58check = exports.createBase58check;
|
|
34940
|
-
var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */
|
|
34940
|
+
var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join7(""));
|
|
34941
34941
|
var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
34942
34942
|
function bech32Polymod(pre) {
|
|
34943
34943
|
const b = pre >> 25;
|
|
@@ -35046,7 +35046,7 @@ var require_lib = __commonJS({
|
|
|
35046
35046
|
return Uint8Array.fromHex(s);
|
|
35047
35047
|
}
|
|
35048
35048
|
};
|
|
35049
|
-
exports.hex = hasHexBuiltin ? hexBuiltin : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(4), /* @__PURE__ */ alphabet("0123456789abcdef"), /* @__PURE__ */
|
|
35049
|
+
exports.hex = hasHexBuiltin ? hexBuiltin : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(4), /* @__PURE__ */ alphabet("0123456789abcdef"), /* @__PURE__ */ join7(""), /* @__PURE__ */ normalize((s) => {
|
|
35050
35050
|
if (typeof s !== "string" || s.length % 2 !== 0)
|
|
35051
35051
|
throw new TypeError(`hex.decode: expected string, got ${typeof s} with length ${s.length}`);
|
|
35052
35052
|
return s.toLowerCase();
|
|
@@ -38760,20 +38760,20 @@ var require_TempoAddress = __commonJS({
|
|
|
38760
38760
|
"use strict";
|
|
38761
38761
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38762
38762
|
exports.InvalidPrefixError = void 0;
|
|
38763
|
-
exports.resolve =
|
|
38763
|
+
exports.resolve = resolve3;
|
|
38764
38764
|
exports.format = format;
|
|
38765
38765
|
exports.parse = parse;
|
|
38766
38766
|
exports.validate = validate;
|
|
38767
38767
|
var core_Address = require_Address();
|
|
38768
38768
|
var Errors = require_Errors();
|
|
38769
38769
|
var Hex = require_Hex();
|
|
38770
|
-
function
|
|
38770
|
+
function resolve3(address2) {
|
|
38771
38771
|
if (address2.startsWith("tempo"))
|
|
38772
38772
|
return parse(address2).address;
|
|
38773
38773
|
return address2;
|
|
38774
38774
|
}
|
|
38775
38775
|
function format(address2) {
|
|
38776
|
-
const resolved =
|
|
38776
|
+
const resolved = resolve3(address2);
|
|
38777
38777
|
return `tempox${resolved.toLowerCase()}`;
|
|
38778
38778
|
}
|
|
38779
38779
|
function parse(tempoAddress) {
|
|
@@ -42868,13 +42868,13 @@ var require_virtualMasterPool = __commonJS({
|
|
|
42868
42868
|
"node_modules/ox/_cjs/tempo/internal/virtualMasterPool.js"(exports) {
|
|
42869
42869
|
"use strict";
|
|
42870
42870
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42871
|
-
exports.resolve =
|
|
42871
|
+
exports.resolve = resolve3;
|
|
42872
42872
|
exports.resolveNode = resolveNode;
|
|
42873
42873
|
exports.resolveBrowser = resolveBrowser;
|
|
42874
42874
|
var Errors = require_Errors();
|
|
42875
42875
|
var cachedPool;
|
|
42876
42876
|
var isNode = typeof globalThis.process !== "undefined" && typeof globalThis.process.versions?.node === "string";
|
|
42877
|
-
async function
|
|
42877
|
+
async function resolve3() {
|
|
42878
42878
|
if (cachedPool)
|
|
42879
42879
|
return cachedPool;
|
|
42880
42880
|
cachedPool = isNode ? await resolveNode() : await resolveBrowser();
|
|
@@ -43152,7 +43152,7 @@ var require_VirtualMaster = __commonJS({
|
|
|
43152
43152
|
}
|
|
43153
43153
|
function mineSaltWithWorkerPool(value) {
|
|
43154
43154
|
const startedAt = Date.now();
|
|
43155
|
-
return new Promise((
|
|
43155
|
+
return new Promise((resolve3, reject) => {
|
|
43156
43156
|
let settled = false;
|
|
43157
43157
|
let attempts = 0;
|
|
43158
43158
|
let completedWorkers = 0;
|
|
@@ -43182,7 +43182,7 @@ var require_VirtualMaster = __commonJS({
|
|
|
43182
43182
|
settled = true;
|
|
43183
43183
|
value.signal?.removeEventListener("abort", onAbort);
|
|
43184
43184
|
terminateAll();
|
|
43185
|
-
|
|
43185
|
+
resolve3(result);
|
|
43186
43186
|
};
|
|
43187
43187
|
const fail = (error) => {
|
|
43188
43188
|
if (settled)
|
|
@@ -46248,13 +46248,13 @@ var require_withResolvers = __commonJS({
|
|
|
46248
46248
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46249
46249
|
exports.withResolvers = withResolvers;
|
|
46250
46250
|
function withResolvers() {
|
|
46251
|
-
let
|
|
46251
|
+
let resolve3 = () => void 0;
|
|
46252
46252
|
let reject = () => void 0;
|
|
46253
46253
|
const promise = new Promise((resolve_, reject_) => {
|
|
46254
|
-
|
|
46254
|
+
resolve3 = resolve_;
|
|
46255
46255
|
reject = reject_;
|
|
46256
46256
|
});
|
|
46257
|
-
return { promise, resolve:
|
|
46257
|
+
return { promise, resolve: resolve3, reject };
|
|
46258
46258
|
}
|
|
46259
46259
|
}
|
|
46260
46260
|
});
|
|
@@ -46278,8 +46278,8 @@ var require_createBatchScheduler = __commonJS({
|
|
|
46278
46278
|
if (sort && Array.isArray(data))
|
|
46279
46279
|
data.sort(sort);
|
|
46280
46280
|
for (let i = 0; i < scheduler.length; i++) {
|
|
46281
|
-
const { resolve:
|
|
46282
|
-
|
|
46281
|
+
const { resolve: resolve3 } = scheduler[i];
|
|
46282
|
+
resolve3?.([data[i], data]);
|
|
46283
46283
|
}
|
|
46284
46284
|
}).catch((err) => {
|
|
46285
46285
|
for (let i = 0; i < scheduler.length; i++) {
|
|
@@ -46295,16 +46295,16 @@ var require_createBatchScheduler = __commonJS({
|
|
|
46295
46295
|
return {
|
|
46296
46296
|
flush,
|
|
46297
46297
|
async schedule(args) {
|
|
46298
|
-
const { promise, resolve:
|
|
46298
|
+
const { promise, resolve: resolve3, reject } = (0, withResolvers_js_1.withResolvers)();
|
|
46299
46299
|
const split = shouldSplitBatch?.([...getBatchedArgs(), args]);
|
|
46300
46300
|
if (split)
|
|
46301
46301
|
exec();
|
|
46302
46302
|
const hasActiveScheduler = getScheduler().length > 0;
|
|
46303
46303
|
if (hasActiveScheduler) {
|
|
46304
|
-
setScheduler({ args, resolve:
|
|
46304
|
+
setScheduler({ args, resolve: resolve3, reject });
|
|
46305
46305
|
return promise;
|
|
46306
46306
|
}
|
|
46307
|
-
setScheduler({ args, resolve:
|
|
46307
|
+
setScheduler({ args, resolve: resolve3, reject });
|
|
46308
46308
|
setTimeout(exec, wait);
|
|
46309
46309
|
return promise;
|
|
46310
46310
|
}
|
|
@@ -47463,7 +47463,7 @@ var require_wait = __commonJS({
|
|
|
47463
47463
|
exports.wait = wait;
|
|
47464
47464
|
var utils_js_1 = require_utils5();
|
|
47465
47465
|
async function wait(time, { signal } = {}) {
|
|
47466
|
-
return new Promise((
|
|
47466
|
+
return new Promise((resolve3, reject) => {
|
|
47467
47467
|
if (signal?.aborted) {
|
|
47468
47468
|
reject((0, utils_js_1.getAbortError)(signal));
|
|
47469
47469
|
return;
|
|
@@ -47471,7 +47471,7 @@ var require_wait = __commonJS({
|
|
|
47471
47471
|
const cleanup = () => signal?.removeEventListener("abort", onAbort);
|
|
47472
47472
|
const timeout = setTimeout(() => {
|
|
47473
47473
|
cleanup();
|
|
47474
|
-
|
|
47474
|
+
resolve3();
|
|
47475
47475
|
}, time);
|
|
47476
47476
|
const onAbort = () => {
|
|
47477
47477
|
clearTimeout(timeout);
|
|
@@ -49127,7 +49127,7 @@ var require_withRetry = __commonJS({
|
|
|
49127
49127
|
var utils_js_1 = require_utils5();
|
|
49128
49128
|
var wait_js_1 = require_wait();
|
|
49129
49129
|
function withRetry(fn, { delay: delay_ = 100, retryCount = 2, shouldRetry = () => true, signal } = {}) {
|
|
49130
|
-
return new Promise((
|
|
49130
|
+
return new Promise((resolve3, reject) => {
|
|
49131
49131
|
const attemptRetry = async ({ count = 0 } = {}) => {
|
|
49132
49132
|
if (signal?.aborted) {
|
|
49133
49133
|
reject((0, utils_js_1.getAbortError)(signal));
|
|
@@ -49147,7 +49147,7 @@ var require_withRetry = __commonJS({
|
|
|
49147
49147
|
};
|
|
49148
49148
|
try {
|
|
49149
49149
|
const data = await fn();
|
|
49150
|
-
|
|
49150
|
+
resolve3(data);
|
|
49151
49151
|
} catch (err) {
|
|
49152
49152
|
if (signal?.aborted) {
|
|
49153
49153
|
reject((0, utils_js_1.getAbortError)(signal));
|
|
@@ -49327,13 +49327,13 @@ var require_waitForTransactionReceipt = __commonJS({
|
|
|
49327
49327
|
let retrying = false;
|
|
49328
49328
|
let _unobserve;
|
|
49329
49329
|
let _unwatch;
|
|
49330
|
-
const { promise, resolve:
|
|
49330
|
+
const { promise, resolve: resolve3, reject } = (0, withResolvers_js_1.withResolvers)();
|
|
49331
49331
|
const timer = timeout ? setTimeout(() => {
|
|
49332
49332
|
_unwatch?.();
|
|
49333
49333
|
_unobserve?.();
|
|
49334
49334
|
reject(new transaction_js_1.WaitForTransactionReceiptTimeoutError({ hash }));
|
|
49335
49335
|
}, timeout) : void 0;
|
|
49336
|
-
_unobserve = (0, observe_js_1.observe)(observerId, { onReplaced, resolve:
|
|
49336
|
+
_unobserve = (0, observe_js_1.observe)(observerId, { onReplaced, resolve: resolve3, reject }, async (emit) => {
|
|
49337
49337
|
receipt = await (0, getAction_js_1.getAction)(client, getTransactionReceipt_js_1.getTransactionReceipt, "getTransactionReceipt")({ hash }).catch(() => void 0);
|
|
49338
49338
|
if (receipt && confirmations <= 1) {
|
|
49339
49339
|
clearTimeout(timer);
|
|
@@ -60344,7 +60344,7 @@ var require_withTimeout = __commonJS({
|
|
|
60344
60344
|
exports.withTimeout = withTimeout;
|
|
60345
60345
|
var utils_js_1 = require_utils5();
|
|
60346
60346
|
function withTimeout(fn, { errorInstance = new Error("timed out"), timeout, signal }) {
|
|
60347
|
-
return new Promise((
|
|
60347
|
+
return new Promise((resolve3, reject) => {
|
|
60348
60348
|
;
|
|
60349
60349
|
(async () => {
|
|
60350
60350
|
let timeoutId;
|
|
@@ -60359,7 +60359,7 @@ var require_withTimeout = __commonJS({
|
|
|
60359
60359
|
}
|
|
60360
60360
|
}, timeout);
|
|
60361
60361
|
}
|
|
60362
|
-
|
|
60362
|
+
resolve3(await fn({ signal: controller?.signal || null }));
|
|
60363
60363
|
} catch (err) {
|
|
60364
60364
|
if (controller?.signal.aborted && (0, utils_js_1.isAbortError)(err)) {
|
|
60365
60365
|
reject(errorInstance);
|
|
@@ -63943,7 +63943,7 @@ var require_stream = __commonJS({
|
|
|
63943
63943
|
};
|
|
63944
63944
|
duplex._final = function(callback) {
|
|
63945
63945
|
if (ws.readyState === ws.CONNECTING) {
|
|
63946
|
-
ws.once("open", function
|
|
63946
|
+
ws.once("open", function open3() {
|
|
63947
63947
|
duplex._final(callback);
|
|
63948
63948
|
});
|
|
63949
63949
|
return;
|
|
@@ -63964,7 +63964,7 @@ var require_stream = __commonJS({
|
|
|
63964
63964
|
};
|
|
63965
63965
|
duplex._write = function(chunk, encoding, callback) {
|
|
63966
63966
|
if (ws.readyState === ws.CONNECTING) {
|
|
63967
|
-
ws.once("open", function
|
|
63967
|
+
ws.once("open", function open3() {
|
|
63968
63968
|
duplex._write(chunk, encoding, callback);
|
|
63969
63969
|
});
|
|
63970
63970
|
return;
|
|
@@ -64527,10 +64527,10 @@ var require_webSocket = __commonJS({
|
|
|
64527
64527
|
socket.addEventListener("error", onError);
|
|
64528
64528
|
socket.addEventListener("open", onOpen);
|
|
64529
64529
|
if (socket.readyState === WebSocket2.CONNECTING) {
|
|
64530
|
-
await new Promise((
|
|
64530
|
+
await new Promise((resolve3, reject) => {
|
|
64531
64531
|
if (!socket)
|
|
64532
64532
|
return;
|
|
64533
|
-
socket.onopen =
|
|
64533
|
+
socket.onopen = resolve3;
|
|
64534
64534
|
socket.onerror = reject;
|
|
64535
64535
|
});
|
|
64536
64536
|
}
|
|
@@ -73671,7 +73671,7 @@ var require_sendCalls = __commonJS({
|
|
|
73671
73671
|
results.push({ reason, status: "rejected" });
|
|
73672
73672
|
}
|
|
73673
73673
|
if (experimental_fallbackDelay > 0)
|
|
73674
|
-
await new Promise((
|
|
73674
|
+
await new Promise((resolve3) => setTimeout(resolve3, experimental_fallbackDelay));
|
|
73675
73675
|
}
|
|
73676
73676
|
if (results.every((r) => r.status === "rejected"))
|
|
73677
73677
|
throw results[0].reason;
|
|
@@ -73793,9 +73793,9 @@ var require_waitForCallsStatus = __commonJS({
|
|
|
73793
73793
|
async function waitForCallsStatus(client, parameters) {
|
|
73794
73794
|
const { id, pollingInterval = client.pollingInterval, status = ({ statusCode }) => statusCode === 200 || statusCode >= 300, retryCount = 4, retryDelay = ({ count }) => ~~(1 << count) * 200, timeout = 6e4, throwOnFailure = false } = parameters;
|
|
73795
73795
|
const observerId = (0, stringify_js_1.stringify)(["waitForCallsStatus", client.uid, id]);
|
|
73796
|
-
const { promise, resolve:
|
|
73796
|
+
const { promise, resolve: resolve3, reject } = (0, withResolvers_js_1.withResolvers)();
|
|
73797
73797
|
let timer;
|
|
73798
|
-
const unobserve = (0, observe_js_1.observe)(observerId, { resolve:
|
|
73798
|
+
const unobserve = (0, observe_js_1.observe)(observerId, { resolve: resolve3, reject }, (emit) => {
|
|
73799
73799
|
const unpoll = (0, poll_js_1.poll)(async () => {
|
|
73800
73800
|
const done = (fn) => {
|
|
73801
73801
|
clearTimeout(timer);
|
|
@@ -74281,13 +74281,13 @@ var require_utils11 = __commonJS({
|
|
|
74281
74281
|
}
|
|
74282
74282
|
if (!Object.hasOwn(globalThis, "Image"))
|
|
74283
74283
|
return false;
|
|
74284
|
-
return new Promise((
|
|
74284
|
+
return new Promise((resolve3) => {
|
|
74285
74285
|
const img = new Image();
|
|
74286
74286
|
img.onload = () => {
|
|
74287
|
-
|
|
74287
|
+
resolve3(true);
|
|
74288
74288
|
};
|
|
74289
74289
|
img.onerror = () => {
|
|
74290
|
-
|
|
74290
|
+
resolve3(false);
|
|
74291
74291
|
};
|
|
74292
74292
|
img.src = uri;
|
|
74293
74293
|
});
|
|
@@ -78763,7 +78763,7 @@ var require_webSocket2 = __commonJS({
|
|
|
78763
78763
|
},
|
|
78764
78764
|
async subscribe({ params, onData, onError }) {
|
|
78765
78765
|
const rpcClient = await (0, webSocket_js_1.getWebSocketRpcClient)(url_, wsRpcClientOpts);
|
|
78766
|
-
const { result: subscriptionId } = await new Promise((
|
|
78766
|
+
const { result: subscriptionId } = await new Promise((resolve3, reject) => rpcClient.request({
|
|
78767
78767
|
body: {
|
|
78768
78768
|
method: "eth_subscribe",
|
|
78769
78769
|
params
|
|
@@ -78780,7 +78780,7 @@ var require_webSocket2 = __commonJS({
|
|
|
78780
78780
|
return;
|
|
78781
78781
|
}
|
|
78782
78782
|
if (typeof response.id === "number") {
|
|
78783
|
-
|
|
78783
|
+
resolve3(response);
|
|
78784
78784
|
return;
|
|
78785
78785
|
}
|
|
78786
78786
|
if (response.method !== "eth_subscription")
|
|
@@ -78791,12 +78791,12 @@ var require_webSocket2 = __commonJS({
|
|
|
78791
78791
|
return {
|
|
78792
78792
|
subscriptionId,
|
|
78793
78793
|
async unsubscribe() {
|
|
78794
|
-
return new Promise((
|
|
78794
|
+
return new Promise((resolve3) => rpcClient.request({
|
|
78795
78795
|
body: {
|
|
78796
78796
|
method: "eth_unsubscribe",
|
|
78797
78797
|
params: [subscriptionId]
|
|
78798
78798
|
},
|
|
78799
|
-
onResponse:
|
|
78799
|
+
onResponse: resolve3
|
|
78800
78800
|
}));
|
|
78801
78801
|
}
|
|
78802
78802
|
};
|
|
@@ -80654,8 +80654,8 @@ var require_cjs2 = __commonJS({
|
|
|
80654
80654
|
|
|
80655
80655
|
// dist/cli.js
|
|
80656
80656
|
import { homedir } from "node:os";
|
|
80657
|
-
import { readFile as
|
|
80658
|
-
import { join as
|
|
80657
|
+
import { readFile as readFile6 } from "node:fs/promises";
|
|
80658
|
+
import { join as join6 } from "node:path";
|
|
80659
80659
|
import { createInterface } from "node:readline/promises";
|
|
80660
80660
|
|
|
80661
80661
|
// dist/codex-launcher.js
|
|
@@ -80768,7 +80768,7 @@ async function isCodexProfileInstalled(codexHome) {
|
|
|
80768
80768
|
var spawnCommand = (command, args, options) => spawn(command, args, options);
|
|
80769
80769
|
async function launchCodexProcess(args, spawnImpl = spawnCommand) {
|
|
80770
80770
|
const child = spawnImpl("codex", ["--profile", CODEX_PROFILE_NAME, ...args], { stdio: "inherit" });
|
|
80771
|
-
return new Promise((
|
|
80771
|
+
return new Promise((resolve3, reject) => {
|
|
80772
80772
|
child.once("error", (error) => {
|
|
80773
80773
|
if (error.code === "ENOENT") {
|
|
80774
80774
|
reject(new Error("Codex CLI was not found; install it before running zk-credits codex"));
|
|
@@ -80776,7 +80776,7 @@ async function launchCodexProcess(args, spawnImpl = spawnCommand) {
|
|
|
80776
80776
|
}
|
|
80777
80777
|
reject(error);
|
|
80778
80778
|
});
|
|
80779
|
-
child.once("exit", (code) =>
|
|
80779
|
+
child.once("exit", (code) => resolve3(code ?? 1));
|
|
80780
80780
|
});
|
|
80781
80781
|
}
|
|
80782
80782
|
|
|
@@ -80818,7 +80818,7 @@ function assertManagedProviderArguments(args) {
|
|
|
80818
80818
|
}
|
|
80819
80819
|
}
|
|
80820
80820
|
function waitForCline(child) {
|
|
80821
|
-
return new Promise((
|
|
80821
|
+
return new Promise((resolve3, reject) => {
|
|
80822
80822
|
child.once("error", (error) => {
|
|
80823
80823
|
if (error.code === "ENOENT") {
|
|
80824
80824
|
reject(new Error("Cline CLI was not found; install it with npm install --global cline"));
|
|
@@ -80826,7 +80826,7 @@ function waitForCline(child) {
|
|
|
80826
80826
|
}
|
|
80827
80827
|
reject(error);
|
|
80828
80828
|
});
|
|
80829
|
-
child.once("exit", (code) =>
|
|
80829
|
+
child.once("exit", (code) => resolve3(code ?? 1));
|
|
80830
80830
|
});
|
|
80831
80831
|
}
|
|
80832
80832
|
async function launchClineProcess(options, spawnImpl = spawnCommand2) {
|
|
@@ -81683,8 +81683,8 @@ function proverProcessFactory(proverPath) {
|
|
|
81683
81683
|
execArgv: [],
|
|
81684
81684
|
stdio: ["ignore", "pipe", "pipe", "ipc"]
|
|
81685
81685
|
});
|
|
81686
|
-
const result = new Promise((
|
|
81687
|
-
child.once("message", (message) =>
|
|
81686
|
+
const result = new Promise((resolve3, reject) => {
|
|
81687
|
+
child.once("message", (message) => resolve3(message));
|
|
81688
81688
|
child.once("error", (error) => reject(error));
|
|
81689
81689
|
child.once("exit", (code, signal) => {
|
|
81690
81690
|
if (code !== 0 && signal === null)
|
|
@@ -81698,11 +81698,11 @@ function proverProcessFactory(proverPath) {
|
|
|
81698
81698
|
terminate: async () => {
|
|
81699
81699
|
if (child.exitCode === null && child.signalCode === null)
|
|
81700
81700
|
child.kill("SIGKILL");
|
|
81701
|
-
await new Promise((
|
|
81701
|
+
await new Promise((resolve3) => {
|
|
81702
81702
|
if (child.exitCode !== null || child.signalCode !== null)
|
|
81703
|
-
|
|
81703
|
+
resolve3();
|
|
81704
81704
|
else
|
|
81705
|
-
child.once("exit", () =>
|
|
81705
|
+
child.once("exit", () => resolve3());
|
|
81706
81706
|
});
|
|
81707
81707
|
}
|
|
81708
81708
|
};
|
|
@@ -82116,8 +82116,8 @@ async function startDetachedProcess(specification) {
|
|
|
82116
82116
|
env: specification.env,
|
|
82117
82117
|
stdio: [specification.stdin === void 0 ? "ignore" : "pipe", log.fd, log.fd]
|
|
82118
82118
|
});
|
|
82119
|
-
await new Promise((
|
|
82120
|
-
child.once("spawn",
|
|
82119
|
+
await new Promise((resolve3, reject) => {
|
|
82120
|
+
child.once("spawn", resolve3);
|
|
82121
82121
|
child.once("error", reject);
|
|
82122
82122
|
});
|
|
82123
82123
|
if (specification.stdin !== void 0 && child.stdin) {
|
|
@@ -82132,7 +82132,7 @@ async function startDetachedProcess(specification) {
|
|
|
82132
82132
|
var defaultRuntime = {
|
|
82133
82133
|
fetchHealth: async (url) => fetch(url, { signal: AbortSignal.timeout(500) }),
|
|
82134
82134
|
startDetachedProcess,
|
|
82135
|
-
wait: async (milliseconds) => new Promise((
|
|
82135
|
+
wait: async (milliseconds) => new Promise((resolve3) => setTimeout(resolve3, milliseconds))
|
|
82136
82136
|
};
|
|
82137
82137
|
function createNodeSidecarLifecycle(options, runtime = defaultRuntime) {
|
|
82138
82138
|
const url = new URL(options.loopbackBaseUrl);
|
|
@@ -82176,6 +82176,305 @@ async function activateSidecarServer(activation) {
|
|
|
82176
82176
|
return address2;
|
|
82177
82177
|
}
|
|
82178
82178
|
|
|
82179
|
+
// dist/setup-config.js
|
|
82180
|
+
import { randomUUID } from "node:crypto";
|
|
82181
|
+
import { chmod as chmod5, lstat, mkdir as mkdir7, open as open2, readFile as readFile5, readdir, realpath as realpath2, rename as rename4, rm } from "node:fs/promises";
|
|
82182
|
+
import { dirname as dirname6, join as join5, resolve as resolve2 } from "node:path";
|
|
82183
|
+
var WITNESS_FILENAMES = /* @__PURE__ */ new Set([
|
|
82184
|
+
"base-tree.json",
|
|
82185
|
+
"base-sepolia-tree.json",
|
|
82186
|
+
"base-tree-artifact.json",
|
|
82187
|
+
"public-tree.json",
|
|
82188
|
+
"base-witness.json",
|
|
82189
|
+
"zk-credits-witness.json",
|
|
82190
|
+
"witness.json",
|
|
82191
|
+
"tree.json"
|
|
82192
|
+
]);
|
|
82193
|
+
function isRecord2(value) {
|
|
82194
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
82195
|
+
}
|
|
82196
|
+
function absolutePath(value, label) {
|
|
82197
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
82198
|
+
throw new Error("Setup configuration " + label + " is required");
|
|
82199
|
+
}
|
|
82200
|
+
return resolve2(value);
|
|
82201
|
+
}
|
|
82202
|
+
function optionalUnsignedString(value, label) {
|
|
82203
|
+
if (value === void 0)
|
|
82204
|
+
return void 0;
|
|
82205
|
+
if (typeof value !== "string" || !/^\d+$/u.test(value)) {
|
|
82206
|
+
throw new Error("Local setup config " + label + " must be a non-negative integer");
|
|
82207
|
+
}
|
|
82208
|
+
return value;
|
|
82209
|
+
}
|
|
82210
|
+
function parseSetupConfig(value) {
|
|
82211
|
+
if (!isRecord2(value) || value.version !== 1 || !isRecord2(value.witness)) {
|
|
82212
|
+
throw new Error("Local setup config is malformed; remove ~/.zk-credits/config.json and run setup again.");
|
|
82213
|
+
}
|
|
82214
|
+
const artifactDirectory = absolutePath(value.artifactDirectory, "artifactDirectory");
|
|
82215
|
+
const witnessValue = value.witness;
|
|
82216
|
+
let witness;
|
|
82217
|
+
if (witnessValue.kind === "file") {
|
|
82218
|
+
witness = { kind: "file", path: absolutePath(witnessValue.path, "witness.path") };
|
|
82219
|
+
} else if (witnessValue.kind === "base-events") {
|
|
82220
|
+
if (typeof witnessValue.rpcUrl !== "string" || !/^https?:\/\//u.test(witnessValue.rpcUrl)) {
|
|
82221
|
+
throw new Error("Local setup config has an invalid Base RPC URL");
|
|
82222
|
+
}
|
|
82223
|
+
if (typeof witnessValue.contractAddress !== "string" || !/^0x[0-9a-fA-F]{40}$/u.test(witnessValue.contractAddress)) {
|
|
82224
|
+
throw new Error("Local setup config has an invalid Base bond contract address");
|
|
82225
|
+
}
|
|
82226
|
+
const deploymentBlock = optionalUnsignedString(witnessValue.deploymentBlock, "deploymentBlock");
|
|
82227
|
+
const confirmations = optionalUnsignedString(witnessValue.confirmations, "confirmations");
|
|
82228
|
+
witness = {
|
|
82229
|
+
kind: "base-events",
|
|
82230
|
+
rpcUrl: witnessValue.rpcUrl,
|
|
82231
|
+
contractAddress: witnessValue.contractAddress,
|
|
82232
|
+
...deploymentBlock === void 0 ? {} : { deploymentBlock },
|
|
82233
|
+
...confirmations === void 0 ? {} : { confirmations }
|
|
82234
|
+
};
|
|
82235
|
+
} else {
|
|
82236
|
+
throw new Error("Local setup config has an unknown witness source");
|
|
82237
|
+
}
|
|
82238
|
+
return { version: 1, artifactDirectory, witness };
|
|
82239
|
+
}
|
|
82240
|
+
function optionalEnvironmentInteger(environment, name) {
|
|
82241
|
+
const value = environment[name]?.trim();
|
|
82242
|
+
if (!value)
|
|
82243
|
+
return void 0;
|
|
82244
|
+
if (!/^\d+$/u.test(value))
|
|
82245
|
+
throw new Error(name + " must be a non-negative integer");
|
|
82246
|
+
return value;
|
|
82247
|
+
}
|
|
82248
|
+
async function candidateDirectories(homeDirectory, stateDirectory2) {
|
|
82249
|
+
const roots = [
|
|
82250
|
+
join5(stateDirectory2, "artifacts", "base-sepolia"),
|
|
82251
|
+
join5(homeDirectory, ".zk-credits", "artifacts", "base-sepolia"),
|
|
82252
|
+
join5(homeDirectory, "Downloads")
|
|
82253
|
+
];
|
|
82254
|
+
const candidates = [...roots];
|
|
82255
|
+
for (const root of roots) {
|
|
82256
|
+
let entries;
|
|
82257
|
+
try {
|
|
82258
|
+
entries = await readdir(root, { withFileTypes: true });
|
|
82259
|
+
} catch {
|
|
82260
|
+
continue;
|
|
82261
|
+
}
|
|
82262
|
+
for (const entry of entries) {
|
|
82263
|
+
if (entry.isDirectory())
|
|
82264
|
+
candidates.push(join5(root, entry.name));
|
|
82265
|
+
}
|
|
82266
|
+
}
|
|
82267
|
+
return [...new Set(candidates.map((path) => resolve2(path)))];
|
|
82268
|
+
}
|
|
82269
|
+
async function chooseOne(kind, candidates, chooseCandidate) {
|
|
82270
|
+
if (candidates.length === 1)
|
|
82271
|
+
return candidates[0];
|
|
82272
|
+
if (!chooseCandidate) {
|
|
82273
|
+
const variable = kind === "proving bundle" ? "ZK_CREDITS_ARTIFACT_DIR" : "ZK_CREDITS_WITNESS_PATH";
|
|
82274
|
+
throw new Error("Found more than one valid " + kind + "; set " + variable + " to choose one.");
|
|
82275
|
+
}
|
|
82276
|
+
const selected = await chooseCandidate(kind, candidates);
|
|
82277
|
+
if (!candidates.includes(resolve2(selected))) {
|
|
82278
|
+
throw new Error("The selected " + kind + " is not one of the validated local candidates");
|
|
82279
|
+
}
|
|
82280
|
+
return resolve2(selected);
|
|
82281
|
+
}
|
|
82282
|
+
async function resolveArtifactDirectory(options, saved) {
|
|
82283
|
+
const explicit = options.environment.ZK_CREDITS_ARTIFACT_DIR?.trim();
|
|
82284
|
+
const candidates = explicit ? [resolve2(options.workingDirectory ?? process.cwd(), explicit)] : [
|
|
82285
|
+
...saved ? [saved.artifactDirectory] : [],
|
|
82286
|
+
...await candidateDirectories(options.homeDirectory, options.stateDirectory)
|
|
82287
|
+
];
|
|
82288
|
+
const valid = /* @__PURE__ */ new Map();
|
|
82289
|
+
let explicitError;
|
|
82290
|
+
for (const candidate of candidates) {
|
|
82291
|
+
try {
|
|
82292
|
+
const bundle = await resolvePinnedArtifactBundle({
|
|
82293
|
+
artifactDirectory: candidate,
|
|
82294
|
+
manifest: options.manifest
|
|
82295
|
+
});
|
|
82296
|
+
let identity = resolve2(bundle.directory);
|
|
82297
|
+
try {
|
|
82298
|
+
identity = await realpath2(bundle.directory);
|
|
82299
|
+
} catch {
|
|
82300
|
+
}
|
|
82301
|
+
valid.set(identity, bundle.directory);
|
|
82302
|
+
} catch (error) {
|
|
82303
|
+
if (explicit)
|
|
82304
|
+
explicitError = error;
|
|
82305
|
+
}
|
|
82306
|
+
}
|
|
82307
|
+
if (explicit && valid.size === 0) {
|
|
82308
|
+
const reason = explicitError instanceof Error ? " " + explicitError.message : "";
|
|
82309
|
+
throw new Error("The configured proving bundle at " + explicit + " failed its pinned checks." + reason);
|
|
82310
|
+
}
|
|
82311
|
+
if (valid.size === 0) {
|
|
82312
|
+
throw new Error("Could not find a valid pinned proving bundle. Extract the bundle from your pilot contact into ~/.zk-credits/artifacts/base-sepolia or ~/Downloads, or set ZK_CREDITS_ARTIFACT_DIR.");
|
|
82313
|
+
}
|
|
82314
|
+
const selected = await chooseOne("proving bundle", [...valid.values()], options.chooseCandidate);
|
|
82315
|
+
return resolve2(selected);
|
|
82316
|
+
}
|
|
82317
|
+
function eventSourceFromEnvironment(environment) {
|
|
82318
|
+
const rpcUrl = environment.BASE_RPC_URL?.trim();
|
|
82319
|
+
const contractAddress = environment.BASE_PRIVATE_CREDIT_BOND_ADDRESS?.trim();
|
|
82320
|
+
if (!rpcUrl || !contractAddress)
|
|
82321
|
+
return void 0;
|
|
82322
|
+
const deploymentBlock = optionalEnvironmentInteger(environment, "BASE_DEPLOYMENT_BLOCK");
|
|
82323
|
+
const confirmations = optionalEnvironmentInteger(environment, "BASE_CONFIRMATIONS");
|
|
82324
|
+
return {
|
|
82325
|
+
kind: "base-events",
|
|
82326
|
+
rpcUrl,
|
|
82327
|
+
contractAddress,
|
|
82328
|
+
...deploymentBlock === void 0 ? {} : { deploymentBlock },
|
|
82329
|
+
...confirmations === void 0 ? {} : { confirmations }
|
|
82330
|
+
};
|
|
82331
|
+
}
|
|
82332
|
+
function witnessCandidates(homeDirectory, stateDirectory2) {
|
|
82333
|
+
const roots = [
|
|
82334
|
+
join5(stateDirectory2, "witnesses"),
|
|
82335
|
+
join5(stateDirectory2, "witness"),
|
|
82336
|
+
join5(homeDirectory, ".zk-credits", "witnesses"),
|
|
82337
|
+
join5(homeDirectory, "Downloads")
|
|
82338
|
+
];
|
|
82339
|
+
return [...new Set(roots.flatMap((root) => [...WITNESS_FILENAMES].map((name) => resolve2(root, name))))];
|
|
82340
|
+
}
|
|
82341
|
+
async function resolveWitnessSource(options, saved) {
|
|
82342
|
+
const environment = options.environment;
|
|
82343
|
+
const explicitPath = environment.ZK_CREDITS_WITNESS_PATH?.trim();
|
|
82344
|
+
if (explicitPath) {
|
|
82345
|
+
const source = {
|
|
82346
|
+
kind: "file",
|
|
82347
|
+
path: resolve2(options.workingDirectory ?? process.cwd(), explicitPath)
|
|
82348
|
+
};
|
|
82349
|
+
try {
|
|
82350
|
+
await options.validateWitness(source);
|
|
82351
|
+
return source;
|
|
82352
|
+
} catch (error) {
|
|
82353
|
+
const reason = error instanceof Error ? " " + error.message : "";
|
|
82354
|
+
throw new Error("The configured Base witness at " + explicitPath + " failed validation." + reason);
|
|
82355
|
+
}
|
|
82356
|
+
}
|
|
82357
|
+
const environmentSource = eventSourceFromEnvironment(environment);
|
|
82358
|
+
if (environmentSource) {
|
|
82359
|
+
try {
|
|
82360
|
+
await options.validateWitness(environmentSource);
|
|
82361
|
+
return environmentSource;
|
|
82362
|
+
} catch (error) {
|
|
82363
|
+
const reason = error instanceof Error ? " " + error.message : "";
|
|
82364
|
+
throw new Error("Base event witness sync failed." + reason);
|
|
82365
|
+
}
|
|
82366
|
+
}
|
|
82367
|
+
if (saved?.witness.kind === "base-events") {
|
|
82368
|
+
try {
|
|
82369
|
+
await options.validateWitness(saved.witness);
|
|
82370
|
+
return saved.witness;
|
|
82371
|
+
} catch (error) {
|
|
82372
|
+
const reason = error instanceof Error ? " " + error.message : "";
|
|
82373
|
+
throw new Error("Saved Base event witness source failed validation." + reason);
|
|
82374
|
+
}
|
|
82375
|
+
}
|
|
82376
|
+
if (saved?.witness.kind === "file") {
|
|
82377
|
+
try {
|
|
82378
|
+
await options.validateWitness(saved.witness);
|
|
82379
|
+
return saved.witness;
|
|
82380
|
+
} catch {
|
|
82381
|
+
}
|
|
82382
|
+
}
|
|
82383
|
+
const valid = [];
|
|
82384
|
+
for (const path of witnessCandidates(options.homeDirectory, options.stateDirectory)) {
|
|
82385
|
+
try {
|
|
82386
|
+
const info = await lstat(path);
|
|
82387
|
+
if (!info.isFile())
|
|
82388
|
+
continue;
|
|
82389
|
+
const source = { kind: "file", path };
|
|
82390
|
+
await options.validateWitness(source);
|
|
82391
|
+
valid.push(path);
|
|
82392
|
+
} catch {
|
|
82393
|
+
}
|
|
82394
|
+
}
|
|
82395
|
+
if (valid.length > 0) {
|
|
82396
|
+
return { kind: "file", path: await chooseOne("witness file", valid, options.chooseCandidate) };
|
|
82397
|
+
}
|
|
82398
|
+
throw new Error("Could not find a public Base witness for this credential. Put base-tree.json or witness.json in ~/.zk-credits/witnesses or ~/Downloads, set ZK_CREDITS_WITNESS_PATH, or configure BASE_RPC_URL and BASE_PRIVATE_CREDIT_BOND_ADDRESS.");
|
|
82399
|
+
}
|
|
82400
|
+
async function resolveSetupInputs(options) {
|
|
82401
|
+
const saved = await readSetupConfig(options.configPath);
|
|
82402
|
+
const artifactDirectory = await resolveArtifactDirectory(options, saved);
|
|
82403
|
+
const witness = await resolveWitnessSource(options, saved);
|
|
82404
|
+
return { version: 1, artifactDirectory, witness };
|
|
82405
|
+
}
|
|
82406
|
+
async function readSetupConfig(path) {
|
|
82407
|
+
let raw;
|
|
82408
|
+
try {
|
|
82409
|
+
const info = await lstat(path);
|
|
82410
|
+
if (!info.isFile())
|
|
82411
|
+
throw new Error("Local setup config must be a regular file");
|
|
82412
|
+
raw = await readFile5(path, "utf8");
|
|
82413
|
+
} catch (error) {
|
|
82414
|
+
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
82415
|
+
return void 0;
|
|
82416
|
+
throw error;
|
|
82417
|
+
}
|
|
82418
|
+
try {
|
|
82419
|
+
return parseSetupConfig(JSON.parse(raw));
|
|
82420
|
+
} catch (error) {
|
|
82421
|
+
if (error instanceof SyntaxError) {
|
|
82422
|
+
throw new Error("Local setup config is not valid JSON; remove ~/.zk-credits/config.json and run setup again.");
|
|
82423
|
+
}
|
|
82424
|
+
throw error;
|
|
82425
|
+
}
|
|
82426
|
+
}
|
|
82427
|
+
async function writeSetupConfig(path, config) {
|
|
82428
|
+
const normalized = parseSetupConfig(config);
|
|
82429
|
+
const directory = dirname6(resolve2(path));
|
|
82430
|
+
await mkdir7(directory, { recursive: true, mode: 448 });
|
|
82431
|
+
const destination = resolve2(path);
|
|
82432
|
+
try {
|
|
82433
|
+
const existing = await lstat(destination);
|
|
82434
|
+
if (existing.isSymbolicLink())
|
|
82435
|
+
throw new Error("Local setup config cannot be a symbolic link");
|
|
82436
|
+
} catch (error) {
|
|
82437
|
+
if (!(error && typeof error === "object" && "code" in error && error.code === "ENOENT"))
|
|
82438
|
+
throw error;
|
|
82439
|
+
}
|
|
82440
|
+
const temporary = join5(directory, ".config-" + randomUUID() + ".tmp");
|
|
82441
|
+
try {
|
|
82442
|
+
const file = await open2(temporary, "wx", 384);
|
|
82443
|
+
try {
|
|
82444
|
+
await file.writeFile(JSON.stringify(normalized, null, 2) + "\n", "utf8");
|
|
82445
|
+
await file.sync();
|
|
82446
|
+
} finally {
|
|
82447
|
+
await file.close();
|
|
82448
|
+
}
|
|
82449
|
+
await rename4(temporary, destination);
|
|
82450
|
+
await chmod5(destination, 384);
|
|
82451
|
+
} finally {
|
|
82452
|
+
await rm(temporary, { force: true });
|
|
82453
|
+
}
|
|
82454
|
+
}
|
|
82455
|
+
function applySetupConfig(environment, config) {
|
|
82456
|
+
if (!environment.ZK_CREDITS_ARTIFACT_DIR?.trim()) {
|
|
82457
|
+
environment.ZK_CREDITS_ARTIFACT_DIR = config.artifactDirectory;
|
|
82458
|
+
}
|
|
82459
|
+
if (config.witness.kind === "file") {
|
|
82460
|
+
if (!environment.ZK_CREDITS_WITNESS_PATH?.trim()) {
|
|
82461
|
+
environment.ZK_CREDITS_WITNESS_PATH = config.witness.path;
|
|
82462
|
+
}
|
|
82463
|
+
return;
|
|
82464
|
+
}
|
|
82465
|
+
if (!environment.BASE_RPC_URL?.trim())
|
|
82466
|
+
environment.BASE_RPC_URL = config.witness.rpcUrl;
|
|
82467
|
+
if (!environment.BASE_PRIVATE_CREDIT_BOND_ADDRESS?.trim()) {
|
|
82468
|
+
environment.BASE_PRIVATE_CREDIT_BOND_ADDRESS = config.witness.contractAddress;
|
|
82469
|
+
}
|
|
82470
|
+
if (!environment.BASE_DEPLOYMENT_BLOCK?.trim() && config.witness.deploymentBlock !== void 0) {
|
|
82471
|
+
environment.BASE_DEPLOYMENT_BLOCK = config.witness.deploymentBlock;
|
|
82472
|
+
}
|
|
82473
|
+
if (!environment.BASE_CONFIRMATIONS?.trim() && config.witness.confirmations !== void 0) {
|
|
82474
|
+
environment.BASE_CONFIRMATIONS = config.witness.confirmations;
|
|
82475
|
+
}
|
|
82476
|
+
}
|
|
82477
|
+
|
|
82179
82478
|
// dist/sidecar-lifecycle.js
|
|
82180
82479
|
async function ensureSidecarReady(dependencies, options = {}) {
|
|
82181
82480
|
if (await dependencies.isHealthy())
|
|
@@ -82195,8 +82494,8 @@ async function ensureSidecarReady(dependencies, options = {}) {
|
|
|
82195
82494
|
import { createServer } from "node:http";
|
|
82196
82495
|
|
|
82197
82496
|
// dist/responses-bridge.js
|
|
82198
|
-
import { randomUUID } from "node:crypto";
|
|
82199
|
-
function
|
|
82497
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
82498
|
+
function isRecord3(value) {
|
|
82200
82499
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
82201
82500
|
}
|
|
82202
82501
|
function hasOnlyKeys(value, allowed) {
|
|
@@ -82209,7 +82508,7 @@ function textContent(value) {
|
|
|
82209
82508
|
return void 0;
|
|
82210
82509
|
const parts = [];
|
|
82211
82510
|
for (const part of value) {
|
|
82212
|
-
if (!
|
|
82511
|
+
if (!isRecord3(part) || !hasOnlyKeys(part, ["type", "text"]) || part.type !== "input_text" && part.type !== "output_text" || typeof part.text !== "string")
|
|
82213
82512
|
return void 0;
|
|
82214
82513
|
parts.push({ type: "text", text: part.text });
|
|
82215
82514
|
}
|
|
@@ -82222,7 +82521,7 @@ function responseInputMessages(input) {
|
|
|
82222
82521
|
return void 0;
|
|
82223
82522
|
const messages = [];
|
|
82224
82523
|
for (const item of input) {
|
|
82225
|
-
if (!
|
|
82524
|
+
if (!isRecord3(item) || typeof item.type !== "string")
|
|
82226
82525
|
return void 0;
|
|
82227
82526
|
if (item.type === "message") {
|
|
82228
82527
|
if (!hasOnlyKeys(item, ["type", "id", "role", "content"]) || item.id !== void 0 && typeof item.id !== "string" || !["system", "developer", "user", "assistant"].includes(String(item.role)))
|
|
@@ -82258,10 +82557,10 @@ function responseTools(value) {
|
|
|
82258
82557
|
return void 0;
|
|
82259
82558
|
const tools = [];
|
|
82260
82559
|
for (const tool of value) {
|
|
82261
|
-
if (!
|
|
82560
|
+
if (!isRecord3(tool) || typeof tool.type !== "string")
|
|
82262
82561
|
return void 0;
|
|
82263
82562
|
if (tool.type === "function") {
|
|
82264
|
-
if (!hasOnlyKeys(tool, ["type", "name", "description", "parameters", "strict"]) || typeof tool.name !== "string" || tool.name.length === 0 || tool.description !== void 0 && typeof tool.description !== "string" || tool.parameters !== void 0 && !
|
|
82563
|
+
if (!hasOnlyKeys(tool, ["type", "name", "description", "parameters", "strict"]) || typeof tool.name !== "string" || tool.name.length === 0 || tool.description !== void 0 && typeof tool.description !== "string" || tool.parameters !== void 0 && !isRecord3(tool.parameters) || tool.strict !== void 0 && typeof tool.strict !== "boolean")
|
|
82265
82564
|
return void 0;
|
|
82266
82565
|
const definition = { name: tool.name };
|
|
82267
82566
|
if (tool.description !== void 0)
|
|
@@ -82279,7 +82578,7 @@ function responseTools(value) {
|
|
|
82279
82578
|
continue;
|
|
82280
82579
|
}
|
|
82281
82580
|
if (tool.type === "namespace") {
|
|
82282
|
-
if (!hasOnlyKeys(tool, ["type", "name", "description", "tools"]) || typeof tool.name !== "string" || tool.description !== void 0 && typeof tool.description !== "string" || !Array.isArray(tool.tools) || tool.tools.some((nested) => !
|
|
82581
|
+
if (!hasOnlyKeys(tool, ["type", "name", "description", "tools"]) || typeof tool.name !== "string" || tool.description !== void 0 && typeof tool.description !== "string" || !Array.isArray(tool.tools) || tool.tools.some((nested) => !isRecord3(nested) || nested.type !== "function" || typeof nested.name !== "string"))
|
|
82283
82582
|
return void 0;
|
|
82284
82583
|
continue;
|
|
82285
82584
|
}
|
|
@@ -82290,12 +82589,12 @@ function responseTools(value) {
|
|
|
82290
82589
|
function translatedToolChoice(value) {
|
|
82291
82590
|
if (value === "none" || value === "auto" || value === "required")
|
|
82292
82591
|
return value;
|
|
82293
|
-
if (!
|
|
82592
|
+
if (!isRecord3(value) || value.type !== "function" || !hasOnlyKeys(value, ["type", "name"]) || typeof value.name !== "string")
|
|
82294
82593
|
return void 0;
|
|
82295
82594
|
return { type: "function", function: { name: value.name } };
|
|
82296
82595
|
}
|
|
82297
82596
|
function translateResponsesRequest(body) {
|
|
82298
|
-
if (!
|
|
82597
|
+
if (!isRecord3(body))
|
|
82299
82598
|
return { ok: false, error: "invalid_request_body" };
|
|
82300
82599
|
const allowed = [
|
|
82301
82600
|
"model",
|
|
@@ -82331,13 +82630,13 @@ function translateResponsesRequest(body) {
|
|
|
82331
82630
|
return { ok: false, error: "invalid_instructions" };
|
|
82332
82631
|
if (body.prompt_cache_key !== void 0 && typeof body.prompt_cache_key !== "string")
|
|
82333
82632
|
return { ok: false, error: "invalid_prompt_cache_key" };
|
|
82334
|
-
if (body.client_metadata !== void 0 && (!
|
|
82633
|
+
if (body.client_metadata !== void 0 && (!isRecord3(body.client_metadata) || Object.values(body.client_metadata).some((value) => typeof value !== "string"))) {
|
|
82335
82634
|
return { ok: false, error: "invalid_client_metadata" };
|
|
82336
82635
|
}
|
|
82337
82636
|
if (body.include !== void 0 && (!Array.isArray(body.include) || body.include.some((value) => value !== "reasoning.encrypted_content"))) {
|
|
82338
82637
|
return { ok: false, error: "unsupported_include" };
|
|
82339
82638
|
}
|
|
82340
|
-
if (body.reasoning !== void 0 && (!
|
|
82639
|
+
if (body.reasoning !== void 0 && (!isRecord3(body.reasoning) || !hasOnlyKeys(body.reasoning, ["summary"]) || body.reasoning.summary !== void 0 && !["auto", "concise", "detailed"].includes(String(body.reasoning.summary)))) {
|
|
82341
82640
|
return { ok: false, error: "unsupported_reasoning_controls" };
|
|
82342
82641
|
}
|
|
82343
82642
|
if (body.parallel_tool_calls !== void 0 && typeof body.parallel_tool_calls !== "boolean") {
|
|
@@ -82379,7 +82678,7 @@ function translateResponsesRequest(body) {
|
|
|
82379
82678
|
return { ok: true, chatRequest, responseModel: body.model };
|
|
82380
82679
|
}
|
|
82381
82680
|
function usageFor(chat) {
|
|
82382
|
-
if (!
|
|
82681
|
+
if (!isRecord3(chat.usage))
|
|
82383
82682
|
return null;
|
|
82384
82683
|
const promptTokens = chat.usage.prompt_tokens;
|
|
82385
82684
|
const completionTokens = chat.usage.completion_tokens;
|
|
@@ -82393,14 +82692,14 @@ function usageFor(chat) {
|
|
|
82393
82692
|
};
|
|
82394
82693
|
}
|
|
82395
82694
|
function responsesEventStream(chatValue, model) {
|
|
82396
|
-
if (!
|
|
82695
|
+
if (!isRecord3(chatValue) || !Array.isArray(chatValue.choices) || !isRecord3(chatValue.choices[0])) {
|
|
82397
82696
|
throw new Error("Gateway returned an invalid chat completion");
|
|
82398
82697
|
}
|
|
82399
82698
|
const choice = chatValue.choices[0];
|
|
82400
|
-
if (!
|
|
82699
|
+
if (!isRecord3(choice.message))
|
|
82401
82700
|
throw new Error("Gateway returned an invalid chat message");
|
|
82402
82701
|
const message = choice.message;
|
|
82403
|
-
const responseSuffix =
|
|
82702
|
+
const responseSuffix = randomUUID2().replaceAll("-", "");
|
|
82404
82703
|
const responseId = `resp_${responseSuffix}`;
|
|
82405
82704
|
const events = [];
|
|
82406
82705
|
let sequence = 0;
|
|
@@ -82434,7 +82733,7 @@ function responsesEventStream(chatValue, model) {
|
|
|
82434
82733
|
if (refusal !== void 0 && typeof refusal !== "string")
|
|
82435
82734
|
throw new Error("Gateway returned an invalid refusal value");
|
|
82436
82735
|
if (typeof text === "string" || typeof refusal === "string") {
|
|
82437
|
-
const itemId = `msg_${
|
|
82736
|
+
const itemId = `msg_${randomUUID2().replaceAll("-", "")}`;
|
|
82438
82737
|
const isRefusal = typeof refusal === "string";
|
|
82439
82738
|
const part = isRefusal ? { type: "refusal", refusal } : { type: "output_text", text: text ?? "", annotations: [] };
|
|
82440
82739
|
const item = { id: itemId, type: "message", status: "completed", role: "assistant", content: [part] };
|
|
@@ -82464,11 +82763,11 @@ function responsesEventStream(chatValue, model) {
|
|
|
82464
82763
|
if (!Array.isArray(message.tool_calls))
|
|
82465
82764
|
throw new Error("Gateway returned invalid tool calls");
|
|
82466
82765
|
for (const callValue of message.tool_calls) {
|
|
82467
|
-
if (!
|
|
82766
|
+
if (!isRecord3(callValue) || callValue.type !== "function" || !isRecord3(callValue.function) || typeof callValue.function.name !== "string" || typeof callValue.function.arguments !== "string") {
|
|
82468
82767
|
throw new Error("Gateway returned an invalid function call");
|
|
82469
82768
|
}
|
|
82470
|
-
const callId = typeof callValue.id === "string" ? callValue.id : `call_${
|
|
82471
|
-
const itemId = `fc_${
|
|
82769
|
+
const callId = typeof callValue.id === "string" ? callValue.id : `call_${randomUUID2().replaceAll("-", "")}`;
|
|
82770
|
+
const itemId = `fc_${randomUUID2().replaceAll("-", "")}`;
|
|
82472
82771
|
const item = {
|
|
82473
82772
|
id: itemId,
|
|
82474
82773
|
type: "function_call",
|
|
@@ -82554,12 +82853,12 @@ async function readJsonBody(req) {
|
|
|
82554
82853
|
throw new Error("OpenAI request body must be valid JSON");
|
|
82555
82854
|
}
|
|
82556
82855
|
}
|
|
82557
|
-
function
|
|
82856
|
+
function isRecord4(value) {
|
|
82558
82857
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
82559
82858
|
}
|
|
82560
82859
|
var STREAM_KEYS = ["stream", "stream_options", "streamOptions", "stream-options"];
|
|
82561
82860
|
function completionRejection(body) {
|
|
82562
|
-
if (!
|
|
82861
|
+
if (!isRecord4(body))
|
|
82563
82862
|
return "invalid_request_body";
|
|
82564
82863
|
if (STREAM_KEYS.some((key) => Object.prototype.hasOwnProperty.call(body, key)))
|
|
82565
82864
|
return "streaming_not_supported";
|
|
@@ -82709,11 +83008,11 @@ function createSidecarServer(options) {
|
|
|
82709
83008
|
const request = handler(req, res).finally(() => inFlight.delete(request));
|
|
82710
83009
|
inFlight.add(request);
|
|
82711
83010
|
});
|
|
82712
|
-
await new Promise((
|
|
83011
|
+
await new Promise((resolve3, reject) => {
|
|
82713
83012
|
server.once("error", reject);
|
|
82714
83013
|
server.listen(port, "127.0.0.1", () => {
|
|
82715
83014
|
server.off("error", reject);
|
|
82716
|
-
|
|
83015
|
+
resolve3();
|
|
82717
83016
|
});
|
|
82718
83017
|
});
|
|
82719
83018
|
const address2 = server.address();
|
|
@@ -82724,11 +83023,11 @@ function createSidecarServer(options) {
|
|
|
82724
83023
|
return;
|
|
82725
83024
|
const activeServer = server;
|
|
82726
83025
|
server = null;
|
|
82727
|
-
await new Promise((
|
|
83026
|
+
await new Promise((resolve3, reject) => activeServer.close((error) => {
|
|
82728
83027
|
if (error)
|
|
82729
83028
|
reject(error);
|
|
82730
83029
|
else
|
|
82731
|
-
|
|
83030
|
+
resolve3();
|
|
82732
83031
|
}));
|
|
82733
83032
|
await Promise.all(inFlight);
|
|
82734
83033
|
}
|
|
@@ -82875,25 +83174,20 @@ async function runBaseRegisteredTrialExchange(options) {
|
|
|
82875
83174
|
return result;
|
|
82876
83175
|
}
|
|
82877
83176
|
|
|
82878
|
-
// dist/setup-preflight.js
|
|
82879
|
-
function setupPrerequisiteError(environment) {
|
|
82880
|
-
if (!environment.ZK_CREDITS_ARTIFACT_DIR?.trim()) {
|
|
82881
|
-
return "Get the pinned proving bundle from your pilot contact, then set ZK_CREDITS_ARTIFACT_DIR to its folder.";
|
|
82882
|
-
}
|
|
82883
|
-
const hasWitnessFile = Boolean(environment.ZK_CREDITS_WITNESS_PATH?.trim());
|
|
82884
|
-
const hasBaseEventSource = Boolean(environment.BASE_RPC_URL?.trim() && environment.BASE_PRIVATE_CREDIT_BOND_ADDRESS?.trim());
|
|
82885
|
-
if (!hasWitnessFile && !hasBaseEventSource) {
|
|
82886
|
-
return "Get the public Base tree file from your pilot contact and set ZK_CREDITS_WITNESS_PATH, or configure BASE_RPC_URL and BASE_PRIVATE_CREDIT_BOND_ADDRESS.";
|
|
82887
|
-
}
|
|
82888
|
-
return void 0;
|
|
82889
|
-
}
|
|
82890
|
-
|
|
82891
83177
|
// dist/cli.js
|
|
82892
83178
|
import { BASE_SEPOLIA_NETWORK as BASE_SEPOLIA_NETWORK2 } from "@zk-credits/x402-zk-prepaid";
|
|
82893
83179
|
var DEFAULT_GATEWAY_URL = "https://zk-credits-gateway.onrender.com";
|
|
82894
83180
|
var DEFAULT_PORT = 3210;
|
|
82895
83181
|
function stateDirectory() {
|
|
82896
|
-
return process.env.ZK_CREDITS_HOME ||
|
|
83182
|
+
return process.env.ZK_CREDITS_HOME || join6(homedir(), ".zk-credits");
|
|
83183
|
+
}
|
|
83184
|
+
function setupConfigPath(directory = stateDirectory()) {
|
|
83185
|
+
return join6(directory, "config.json");
|
|
83186
|
+
}
|
|
83187
|
+
async function applySavedSetupConfig(environment, directory = stateDirectory()) {
|
|
83188
|
+
const config = await readSetupConfig(setupConfigPath(directory));
|
|
83189
|
+
if (config)
|
|
83190
|
+
applySetupConfig(environment, config);
|
|
82897
83191
|
}
|
|
82898
83192
|
function loopbackBaseUrl() {
|
|
82899
83193
|
const port = Number(process.env.ZK_CREDITS_SIDECAR_PORT || DEFAULT_PORT);
|
|
@@ -82912,6 +83206,43 @@ function readPort(args) {
|
|
|
82912
83206
|
}
|
|
82913
83207
|
return parsed;
|
|
82914
83208
|
}
|
|
83209
|
+
async function chooseSetupCandidate(kind, candidates) {
|
|
83210
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
83211
|
+
const variable = kind === "proving bundle" ? "ZK_CREDITS_ARTIFACT_DIR" : "ZK_CREDITS_WITNESS_PATH";
|
|
83212
|
+
throw new Error("Found more than one valid local " + kind + ". Rerun in an interactive terminal or set " + variable + " explicitly.");
|
|
83213
|
+
}
|
|
83214
|
+
const input = createInterface({ input: process.stdin, output: process.stdout });
|
|
83215
|
+
try {
|
|
83216
|
+
console.log("Found multiple valid " + kind + "s:");
|
|
83217
|
+
candidates.forEach((candidate, index2) => console.log(" " + (index2 + 1) + ") " + candidate));
|
|
83218
|
+
const answer = await input.question("Select a number: ");
|
|
83219
|
+
const index = Number(answer);
|
|
83220
|
+
if (!Number.isInteger(index) || index < 1 || index > candidates.length) {
|
|
83221
|
+
throw new Error("Choose one of the listed local candidates");
|
|
83222
|
+
}
|
|
83223
|
+
return candidates[index - 1];
|
|
83224
|
+
} finally {
|
|
83225
|
+
input.close();
|
|
83226
|
+
}
|
|
83227
|
+
}
|
|
83228
|
+
async function witnessProviderForSource(source, cachePath) {
|
|
83229
|
+
if (source.kind === "file") {
|
|
83230
|
+
let value;
|
|
83231
|
+
try {
|
|
83232
|
+
value = JSON.parse(await readFile6(source.path, "utf8"));
|
|
83233
|
+
} catch {
|
|
83234
|
+
throw new Error("The Base witness file could not be read as JSON");
|
|
83235
|
+
}
|
|
83236
|
+
return createFileWitnessProvider(value);
|
|
83237
|
+
}
|
|
83238
|
+
return createBaseEventWitnessProvider({
|
|
83239
|
+
rpcUrl: source.rpcUrl,
|
|
83240
|
+
contractAddress: source.contractAddress,
|
|
83241
|
+
deploymentBlock: source.deploymentBlock === void 0 ? void 0 : BigInt(source.deploymentBlock),
|
|
83242
|
+
confirmations: source.confirmations === void 0 ? void 0 : BigInt(source.confirmations),
|
|
83243
|
+
cachePath
|
|
83244
|
+
});
|
|
83245
|
+
}
|
|
82915
83246
|
async function readCredentialPasswordFromStdin() {
|
|
82916
83247
|
const chunks = [];
|
|
82917
83248
|
let byteLength = 0;
|
|
@@ -82931,7 +83262,7 @@ async function readHiddenValue(prompt) {
|
|
|
82931
83262
|
process.stdout.write(prompt);
|
|
82932
83263
|
process.stdin.setRawMode(true);
|
|
82933
83264
|
process.stdin.resume();
|
|
82934
|
-
return new Promise((
|
|
83265
|
+
return new Promise((resolve3, reject) => {
|
|
82935
83266
|
let value = "";
|
|
82936
83267
|
const done = (error) => {
|
|
82937
83268
|
process.stdin.off("data", onData);
|
|
@@ -82941,7 +83272,7 @@ async function readHiddenValue(prompt) {
|
|
|
82941
83272
|
if (error)
|
|
82942
83273
|
reject(error);
|
|
82943
83274
|
else
|
|
82944
|
-
|
|
83275
|
+
resolve3(value.trim());
|
|
82945
83276
|
};
|
|
82946
83277
|
const onData = (chunk) => {
|
|
82947
83278
|
for (const byte of chunk) {
|
|
@@ -82964,7 +83295,7 @@ async function readHiddenValue(prompt) {
|
|
|
82964
83295
|
});
|
|
82965
83296
|
}
|
|
82966
83297
|
async function readEncryptedCredential(path, password) {
|
|
82967
|
-
const parsed = JSON.parse(await
|
|
83298
|
+
const parsed = JSON.parse(await readFile6(path, "utf8"));
|
|
82968
83299
|
if (parsed.format !== "zk-credits-credential" || parsed.version !== 1 && parsed.version !== 2) {
|
|
82969
83300
|
throw new Error("Credential file is not a supported zk-credits export");
|
|
82970
83301
|
}
|
|
@@ -82986,9 +83317,11 @@ non-streaming POST /v1/chat/completions; Codex Responses requests pass through
|
|
|
82986
83317
|
the sidecar's bounded local compatibility bridge.
|
|
82987
83318
|
"zk-credits trial-registered-adapter" runs one confirmed, billable internal
|
|
82988
83319
|
trial request through the directly registered official x402 client adapter.
|
|
82989
|
-
Set ZK_CREDITS_CREDENTIAL_PATH
|
|
82990
|
-
|
|
82991
|
-
|
|
83320
|
+
Set ZK_CREDITS_CREDENTIAL_PATH before setup. The wizard searches Downloads and
|
|
83321
|
+
~/.zk-credits for the pinned bundle and local Base witness, validates both,
|
|
83322
|
+
then saves their paths locally. Alternatively, set ZK_CREDITS_ARTIFACT_DIR and
|
|
83323
|
+
ZK_CREDITS_WITNESS_PATH explicitly. Setup prompts for the credential password
|
|
83324
|
+
without echo; the encrypted export is decrypted only in local memory.`);
|
|
82992
83325
|
}
|
|
82993
83326
|
async function loadBaseClientRuntime(passwordInput) {
|
|
82994
83327
|
const credentialPath = process.env.ZK_CREDITS_CREDENTIAL_PATH;
|
|
@@ -83001,18 +83334,18 @@ async function loadBaseClientRuntime(passwordInput) {
|
|
|
83001
83334
|
if (!artifactDirectory) {
|
|
83002
83335
|
throw new Error("Set ZK_CREDITS_ARTIFACT_DIR to the directory holding the installed pinned proving bundle");
|
|
83003
83336
|
}
|
|
83004
|
-
const witnessProvider = witnessPath ? createFileWitnessProvider(JSON.parse(await
|
|
83337
|
+
const witnessProvider = witnessPath ? createFileWitnessProvider(JSON.parse(await readFile6(witnessPath, "utf8"))) : process.env.BASE_RPC_URL && process.env.BASE_PRIVATE_CREDIT_BOND_ADDRESS ? createBaseEventWitnessProvider({
|
|
83005
83338
|
rpcUrl: process.env.BASE_RPC_URL,
|
|
83006
83339
|
contractAddress: process.env.BASE_PRIVATE_CREDIT_BOND_ADDRESS,
|
|
83007
83340
|
deploymentBlock: process.env.BASE_DEPLOYMENT_BLOCK && /^\d+$/u.test(process.env.BASE_DEPLOYMENT_BLOCK) ? BigInt(process.env.BASE_DEPLOYMENT_BLOCK) : void 0,
|
|
83008
83341
|
confirmations: process.env.BASE_CONFIRMATIONS && /^\d+$/u.test(process.env.BASE_CONFIRMATIONS) ? BigInt(process.env.BASE_CONFIRMATIONS) : void 0,
|
|
83009
|
-
cachePath:
|
|
83342
|
+
cachePath: join6(stateDirectory(), "base-event-sync.json")
|
|
83010
83343
|
}) : (() => {
|
|
83011
83344
|
throw new Error("Set ZK_CREDITS_WITNESS_PATH or configure BASE_RPC_URL and BASE_PRIVATE_CREDIT_BOND_ADDRESS");
|
|
83012
83345
|
})();
|
|
83013
83346
|
const proofMetrics = createBaseProofMetrics();
|
|
83014
83347
|
const exchangeMetrics = createZkPrepaidLifecycleMetrics();
|
|
83015
|
-
const slotLedger = await BaseSlotLedger.open({ path:
|
|
83348
|
+
const slotLedger = await BaseSlotLedger.open({ path: join6(stateDirectory(), "base-slots.json") });
|
|
83016
83349
|
const prove = await createPinnedBaseProofGenerator({ artifactDirectory, metrics: proofMetrics });
|
|
83017
83350
|
validateBaseCreditWitness(await witnessProvider.witnessForCredential(credential));
|
|
83018
83351
|
return { credential, witnessProvider, slotLedger, proofMetrics, exchangeMetrics, prove };
|
|
@@ -83037,7 +83370,7 @@ var GATEWAY_COUNTER_NAMES = [
|
|
|
83037
83370
|
];
|
|
83038
83371
|
var GATEWAY_CLAIM_COUNT_NAMES = ["reserved", "ready", "committed", "cancelled"];
|
|
83039
83372
|
var GATEWAY_READINESS_CHECK_NAMES = /* @__PURE__ */ new Set(["launchControl", "database", "baseRoot", "baseRpc", "verifierAssets", "provider"]);
|
|
83040
|
-
function
|
|
83373
|
+
function isRecord5(value) {
|
|
83041
83374
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
83042
83375
|
}
|
|
83043
83376
|
function safeCount(value) {
|
|
@@ -83066,10 +83399,10 @@ async function readGatewayJson(url, headers) {
|
|
|
83066
83399
|
}
|
|
83067
83400
|
async function gatewayReadiness(origin) {
|
|
83068
83401
|
const response = await readGatewayJson(new URL("/ready", origin), { accept: "application/json" });
|
|
83069
|
-
const report =
|
|
83402
|
+
const report = isRecord5(response.body) ? response.body : void 0;
|
|
83070
83403
|
const checks = Array.isArray(report?.checks) ? report.checks : [];
|
|
83071
|
-
const failedChecks = checks.flatMap((check) =>
|
|
83072
|
-
const hasLaunchCheck = checks.some((check) =>
|
|
83404
|
+
const failedChecks = checks.flatMap((check) => isRecord5(check) && check.ok === true ? [] : [isRecord5(check) && typeof check.name === "string" && GATEWAY_READINESS_CHECK_NAMES.has(check.name) ? check.name : "unknown"]);
|
|
83405
|
+
const hasLaunchCheck = checks.some((check) => isRecord5(check) && check.name === "launchControl" && check.ok === true);
|
|
83073
83406
|
return {
|
|
83074
83407
|
status: response.status,
|
|
83075
83408
|
passed: response.status === 200 && report?.ready === true && failedChecks.length === 0 && hasLaunchCheck,
|
|
@@ -83081,12 +83414,12 @@ async function gatewayTrialSnapshot(origin, token) {
|
|
|
83081
83414
|
accept: "application/json",
|
|
83082
83415
|
authorization: `Bearer ${token}`
|
|
83083
83416
|
});
|
|
83084
|
-
const body =
|
|
83085
|
-
const launch =
|
|
83086
|
-
const base =
|
|
83087
|
-
const spend =
|
|
83088
|
-
const rawMetrics =
|
|
83089
|
-
const rawClaims =
|
|
83417
|
+
const body = isRecord5(response.body) ? response.body : void 0;
|
|
83418
|
+
const launch = isRecord5(body?.launchControl) ? body.launchControl : void 0;
|
|
83419
|
+
const base = isRecord5(body?.base) ? body.base : void 0;
|
|
83420
|
+
const spend = isRecord5(body?.spend) ? body.spend : void 0;
|
|
83421
|
+
const rawMetrics = isRecord5(body?.metrics) ? body.metrics : void 0;
|
|
83422
|
+
const rawClaims = isRecord5(body?.claims) ? body.claims : void 0;
|
|
83090
83423
|
const metrics = {};
|
|
83091
83424
|
const claims = {};
|
|
83092
83425
|
let countersValid = Boolean(rawMetrics && rawClaims);
|
|
@@ -83308,6 +83641,10 @@ async function main() {
|
|
|
83308
83641
|
printHelp();
|
|
83309
83642
|
return;
|
|
83310
83643
|
}
|
|
83644
|
+
const sidecarHome = stateDirectory();
|
|
83645
|
+
if (args[0] !== "setup" && args[0] !== "status" && args[0] !== "env") {
|
|
83646
|
+
await applySavedSetupConfig(process.env, sidecarHome);
|
|
83647
|
+
}
|
|
83311
83648
|
if (args[0] === "serve") {
|
|
83312
83649
|
const passwordFromStdin = args.includes("--credential-password-stdin") ? await readCredentialPasswordFromStdin() : void 0;
|
|
83313
83650
|
await serve(args.slice(1).filter((argument) => argument !== "--credential-password-stdin"), passwordFromStdin);
|
|
@@ -83317,19 +83654,26 @@ async function main() {
|
|
|
83317
83654
|
await trialRegisteredAdapter();
|
|
83318
83655
|
return;
|
|
83319
83656
|
}
|
|
83320
|
-
const sidecarHome = stateDirectory();
|
|
83321
83657
|
const statePaths = sidecarStatePaths(sidecarHome);
|
|
83322
83658
|
const codexHome = resolveCodexHome(process.env, homedir());
|
|
83323
83659
|
const cliEntryPath = process.argv[1];
|
|
83324
83660
|
if (!cliEntryPath)
|
|
83325
83661
|
throw new Error("Unable to resolve the zk-credits executable path");
|
|
83662
|
+
let setupCredentialPassword;
|
|
83326
83663
|
const lifecycle = createNodeSidecarLifecycle({
|
|
83327
83664
|
loopbackBaseUrl: loopbackBaseUrl(),
|
|
83328
83665
|
stateDirectory: sidecarHome,
|
|
83329
83666
|
tokenPath: statePaths.tokenPath,
|
|
83330
83667
|
logPath: statePaths.logPath,
|
|
83331
83668
|
cliEntryPath,
|
|
83332
|
-
readCredentialPassword: () =>
|
|
83669
|
+
readCredentialPassword: async () => {
|
|
83670
|
+
if (setupCredentialPassword !== void 0) {
|
|
83671
|
+
const password = setupCredentialPassword;
|
|
83672
|
+
setupCredentialPassword = void 0;
|
|
83673
|
+
return password;
|
|
83674
|
+
}
|
|
83675
|
+
return readHiddenValue("Credential backup password: ");
|
|
83676
|
+
}
|
|
83333
83677
|
});
|
|
83334
83678
|
const exitCode = await runCliCommand(args, {
|
|
83335
83679
|
loopbackBaseUrl: loopbackBaseUrl(),
|
|
@@ -83340,28 +83684,32 @@ async function main() {
|
|
|
83340
83684
|
if (!path)
|
|
83341
83685
|
return false;
|
|
83342
83686
|
try {
|
|
83343
|
-
await
|
|
83687
|
+
await readFile6(path);
|
|
83344
83688
|
return true;
|
|
83345
83689
|
} catch {
|
|
83346
83690
|
return false;
|
|
83347
83691
|
}
|
|
83348
83692
|
},
|
|
83349
83693
|
validateSetupPrerequisites: async () => {
|
|
83350
|
-
const
|
|
83351
|
-
if (
|
|
83352
|
-
throw new Error(
|
|
83353
|
-
const
|
|
83354
|
-
|
|
83355
|
-
|
|
83356
|
-
const
|
|
83357
|
-
|
|
83358
|
-
|
|
83359
|
-
|
|
83360
|
-
|
|
83361
|
-
|
|
83362
|
-
|
|
83363
|
-
|
|
83364
|
-
|
|
83694
|
+
const credentialPath = process.env.ZK_CREDITS_CREDENTIAL_PATH;
|
|
83695
|
+
if (!credentialPath?.trim())
|
|
83696
|
+
throw new Error("Set ZK_CREDITS_CREDENTIAL_PATH to the encrypted browser export");
|
|
83697
|
+
const password = await readHiddenValue("Credential backup password: ");
|
|
83698
|
+
const credential = await readEncryptedCredential(credentialPath, password);
|
|
83699
|
+
const manifest = await loadCircuitManifest();
|
|
83700
|
+
const config = await resolveSetupInputs({
|
|
83701
|
+
environment: process.env,
|
|
83702
|
+
homeDirectory: homedir(),
|
|
83703
|
+
stateDirectory: sidecarHome,
|
|
83704
|
+
configPath: setupConfigPath(sidecarHome),
|
|
83705
|
+
manifest,
|
|
83706
|
+
validateWitness: async (source) => {
|
|
83707
|
+
const provider = await witnessProviderForSource(source, join6(stateDirectory(), "base-event-sync.json"));
|
|
83708
|
+
validateBaseCreditWitness(await provider.witnessForCredential(credential));
|
|
83709
|
+
},
|
|
83710
|
+
chooseCandidate: chooseSetupCandidate
|
|
83711
|
+
});
|
|
83712
|
+
const artifactDirectory = config.artifactDirectory;
|
|
83365
83713
|
try {
|
|
83366
83714
|
await createPinnedBaseProofGenerator({
|
|
83367
83715
|
artifactDirectory,
|
|
@@ -83372,6 +83720,11 @@ async function main() {
|
|
|
83372
83720
|
throw new Error(`Pinned proving bundle check failed: ${error.message}`);
|
|
83373
83721
|
throw new Error("Pinned proving bundle check failed. Reinstall the bundle from your pilot invite.");
|
|
83374
83722
|
}
|
|
83723
|
+
await writeSetupConfig(setupConfigPath(sidecarHome), config);
|
|
83724
|
+
applySetupConfig(process.env, config);
|
|
83725
|
+
setupCredentialPassword = password;
|
|
83726
|
+
console.log("Pinned proving bundle and witness validated for this activated credential.");
|
|
83727
|
+
console.log("Local setup paths saved to " + setupConfigPath(sidecarHome));
|
|
83375
83728
|
},
|
|
83376
83729
|
configureCodex: async (model) => {
|
|
83377
83730
|
await writeCodexProfile({ codexHome, loopbackBaseUrl: loopbackBaseUrl(), model });
|