zk-credits 0.2.3 → 0.2.4
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 +10 -7
- package/dist/cli.js +2 -30
- package/dist/gateway-root-check.d.ts +2 -0
- package/dist/gateway-root-check.js +28 -0
- package/dist/responses-bridge.js +3 -2
- package/dist/zk-credits.js +43 -41
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ are founder-provisioned test credits, and the circuit is not independently
|
|
|
7
7
|
audited.
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install --global zk-credits@0.2.
|
|
10
|
+
npm install --global zk-credits@0.2.4
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Pinned pilot versions
|
|
@@ -17,11 +17,11 @@ not mix versions between the sidecar, the adapter package, and the gateway:
|
|
|
17
17
|
|
|
18
18
|
| Package | Version |
|
|
19
19
|
| --- | --- |
|
|
20
|
-
| `zk-credits` (this sidecar) | `0.2.
|
|
20
|
+
| `zk-credits` (this sidecar) | `0.2.4` |
|
|
21
21
|
| `@zk-credits/x402-zk-prepaid` (adapter) | `0.1.0` |
|
|
22
22
|
| `@zk-credits/shared` | `0.1.0` |
|
|
23
23
|
|
|
24
|
-
The pinned Base Sepolia trial version is `0.2.
|
|
24
|
+
The pinned Base Sepolia trial version is `0.2.4`. It uses the non-streaming
|
|
25
25
|
`POST /v1/chat/completions` path below, includes the loopback Responses bridge
|
|
26
26
|
for Codex, and acquires the pinned private proving bundle through the local
|
|
27
27
|
GitHub CLI session. It also synchronizes V2 Base events and checks the gateway
|
|
@@ -79,9 +79,11 @@ still receives the class. A rejected request consumes no credit.
|
|
|
79
79
|
owner-only permissions. Missing GitHub access or any mismatch stops setup.
|
|
80
80
|
It syncs public Base events from the pinned V2 bond and deployment block,
|
|
81
81
|
validates that the resulting witness resolves the activated credential,
|
|
82
|
-
and asks the gateway
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
and asks the gateway's public `POST /v1/root-known` endpoint whether the
|
|
83
|
+
resulting root is known. This check sends no admin token and returns only
|
|
84
|
+
`{ "known": boolean }`; the protected admin endpoints remain unavailable
|
|
85
|
+
to setup. The witness and event cache remain local. The package does not
|
|
86
|
+
accept a supplied witness file for this V2 deployment.
|
|
85
87
|
|
|
86
88
|
The package ships `circuits/manifest.json`, which fixes the immutable
|
|
87
89
|
release identity, the SHA-256 of the archive and each proving artifact, and
|
|
@@ -104,7 +106,8 @@ still receives the class. A rejected request consumes no credit.
|
|
|
104
106
|
zk-credits setup codex
|
|
105
107
|
```
|
|
106
108
|
|
|
107
|
-
Then run `zk-credits codex` to open
|
|
109
|
+
No gateway admin token is required. Then run `zk-credits codex` to open
|
|
110
|
+
Codex with the local sidecar.
|
|
108
111
|
|
|
109
112
|
The sidecar binds `127.0.0.1:3210` only. It does not modify `~/.cline` or
|
|
110
113
|
`~/.codex`.
|
package/dist/cli.js
CHANGED
|
@@ -24,6 +24,7 @@ import { createSidecarServer } from './sidecar.js';
|
|
|
24
24
|
import { runBaseRegisteredTrialExchange } from './base-registered-trial.js';
|
|
25
25
|
import { loadCircuitManifest } from './artifact-bundle.js';
|
|
26
26
|
import { BASE_SEPOLIA_NETWORK } from '@zk-credits/x402-zk-prepaid';
|
|
27
|
+
import { requireGatewayKnownRoot as checkGatewayKnownRoot } from './gateway-root-check.js';
|
|
27
28
|
const DEFAULT_GATEWAY_URL = 'https://zk-credits-gateway.onrender.com';
|
|
28
29
|
const DEFAULT_PORT = 3210;
|
|
29
30
|
function stateDirectory() {
|
|
@@ -260,36 +261,7 @@ async function readGatewayJson(url, headers) {
|
|
|
260
261
|
}
|
|
261
262
|
}
|
|
262
263
|
async function requireGatewayKnownRoot(root) {
|
|
263
|
-
|
|
264
|
-
const token = process.env.BILLING_INTERNAL_TOKEN?.trim() || await readHiddenValue('Gateway admin token: ');
|
|
265
|
-
if (!token)
|
|
266
|
-
throw new Error('Base Sepolia V2 setup requires gateway admin access to check the activated credential root');
|
|
267
|
-
let response;
|
|
268
|
-
try {
|
|
269
|
-
response = await fetch(new URL('/v1/admin/root-known', origin), {
|
|
270
|
-
method: 'POST',
|
|
271
|
-
headers: {
|
|
272
|
-
accept: 'application/json',
|
|
273
|
-
authorization: `Bearer ${token}`,
|
|
274
|
-
'content-type': 'application/json',
|
|
275
|
-
},
|
|
276
|
-
body: JSON.stringify({ root }),
|
|
277
|
-
signal: AbortSignal.timeout(10_000),
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
catch {
|
|
281
|
-
throw new Error('The gateway could not confirm that the activated credential root is known');
|
|
282
|
-
}
|
|
283
|
-
let body;
|
|
284
|
-
try {
|
|
285
|
-
body = await response.json();
|
|
286
|
-
}
|
|
287
|
-
catch {
|
|
288
|
-
body = undefined;
|
|
289
|
-
}
|
|
290
|
-
if (response.status !== 200 || !isRecord(body) || body.known !== true) {
|
|
291
|
-
throw new Error('The activated credential root is not in the gateway known-root set; stop setup and reconcile the V2 activation');
|
|
292
|
-
}
|
|
264
|
+
await checkGatewayKnownRoot(root, gatewayOrigin());
|
|
293
265
|
}
|
|
294
266
|
async function gatewayReadiness(origin) {
|
|
295
267
|
const response = await readGatewayJson(new URL('/ready', origin), { accept: 'application/json' });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
/** Public setup check. It sends the public root only and never needs an admin credential. */
|
|
5
|
+
export async function requireGatewayKnownRoot(root, origin, fetcher = fetch) {
|
|
6
|
+
let response;
|
|
7
|
+
try {
|
|
8
|
+
response = await fetcher(new URL('/v1/root-known', origin), {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
headers: { accept: 'application/json', 'content-type': 'application/json' },
|
|
11
|
+
body: JSON.stringify({ root }),
|
|
12
|
+
signal: AbortSignal.timeout(10_000),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
throw new Error('The gateway could not confirm that the activated credential root is known');
|
|
17
|
+
}
|
|
18
|
+
let body;
|
|
19
|
+
try {
|
|
20
|
+
body = await response.json();
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
body = undefined;
|
|
24
|
+
}
|
|
25
|
+
if (response.status !== 200 || !isRecord(body) || body.known !== true) {
|
|
26
|
+
throw new Error('The activated credential root is not in the gateway known-root set; stop setup and reconcile the V2 activation');
|
|
27
|
+
}
|
|
28
|
+
}
|
package/dist/responses-bridge.js
CHANGED
|
@@ -151,8 +151,9 @@ export function translateResponsesRequest(body) {
|
|
|
151
151
|
return { ok: false, error: 'unsupported_include' };
|
|
152
152
|
}
|
|
153
153
|
if (body.reasoning !== undefined
|
|
154
|
-
&& (!isRecord(body.reasoning) || !hasOnlyKeys(body.reasoning, ['summary'])
|
|
155
|
-
|| (body.reasoning.
|
|
154
|
+
&& (!isRecord(body.reasoning) || !hasOnlyKeys(body.reasoning, ['effort', 'summary'])
|
|
155
|
+
|| (body.reasoning.effort !== undefined && body.reasoning.effort !== 'none')
|
|
156
|
+
|| (body.reasoning.summary !== undefined && !['none', 'auto', 'concise', 'detailed'].includes(String(body.reasoning.summary))))) {
|
|
156
157
|
return { ok: false, error: 'unsupported_reasoning_controls' };
|
|
157
158
|
}
|
|
158
159
|
if (body.parallel_tool_calls !== undefined && typeof body.parallel_tool_calls !== 'boolean') {
|
package/dist/zk-credits.js
CHANGED
|
@@ -82937,7 +82937,7 @@ function translateResponsesRequest(body) {
|
|
|
82937
82937
|
if (body.include !== void 0 && (!Array.isArray(body.include) || body.include.some((value) => value !== "reasoning.encrypted_content"))) {
|
|
82938
82938
|
return { ok: false, error: "unsupported_include" };
|
|
82939
82939
|
}
|
|
82940
|
-
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)))) {
|
|
82940
|
+
if (body.reasoning !== void 0 && (!isRecord3(body.reasoning) || !hasOnlyKeys(body.reasoning, ["effort", "summary"]) || body.reasoning.effort !== void 0 && body.reasoning.effort !== "none" || body.reasoning.summary !== void 0 && !["none", "auto", "concise", "detailed"].includes(String(body.reasoning.summary)))) {
|
|
82941
82941
|
return { ok: false, error: "unsupported_reasoning_controls" };
|
|
82942
82942
|
}
|
|
82943
82943
|
if (body.parallel_tool_calls !== void 0 && typeof body.parallel_tool_calls !== "boolean") {
|
|
@@ -83477,6 +83477,35 @@ async function runBaseRegisteredTrialExchange(options) {
|
|
|
83477
83477
|
|
|
83478
83478
|
// dist/cli.js
|
|
83479
83479
|
import { BASE_SEPOLIA_NETWORK as BASE_SEPOLIA_NETWORK2 } from "@zk-credits/x402-zk-prepaid";
|
|
83480
|
+
|
|
83481
|
+
// dist/gateway-root-check.js
|
|
83482
|
+
function isRecord5(value) {
|
|
83483
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
83484
|
+
}
|
|
83485
|
+
async function requireGatewayKnownRoot(root, origin, fetcher = fetch) {
|
|
83486
|
+
let response;
|
|
83487
|
+
try {
|
|
83488
|
+
response = await fetcher(new URL("/v1/root-known", origin), {
|
|
83489
|
+
method: "POST",
|
|
83490
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
83491
|
+
body: JSON.stringify({ root }),
|
|
83492
|
+
signal: AbortSignal.timeout(1e4)
|
|
83493
|
+
});
|
|
83494
|
+
} catch {
|
|
83495
|
+
throw new Error("The gateway could not confirm that the activated credential root is known");
|
|
83496
|
+
}
|
|
83497
|
+
let body;
|
|
83498
|
+
try {
|
|
83499
|
+
body = await response.json();
|
|
83500
|
+
} catch {
|
|
83501
|
+
body = void 0;
|
|
83502
|
+
}
|
|
83503
|
+
if (response.status !== 200 || !isRecord5(body) || body.known !== true) {
|
|
83504
|
+
throw new Error("The activated credential root is not in the gateway known-root set; stop setup and reconcile the V2 activation");
|
|
83505
|
+
}
|
|
83506
|
+
}
|
|
83507
|
+
|
|
83508
|
+
// dist/cli.js
|
|
83480
83509
|
var DEFAULT_GATEWAY_URL = "https://zk-credits-gateway.onrender.com";
|
|
83481
83510
|
var DEFAULT_PORT = 3210;
|
|
83482
83511
|
function stateDirectory() {
|
|
@@ -83672,7 +83701,7 @@ var GATEWAY_COUNTER_NAMES = [
|
|
|
83672
83701
|
];
|
|
83673
83702
|
var GATEWAY_CLAIM_COUNT_NAMES = ["reserved", "ready", "committed", "cancelled"];
|
|
83674
83703
|
var GATEWAY_READINESS_CHECK_NAMES = /* @__PURE__ */ new Set(["launchControl", "database", "baseRoot", "baseRpc", "verifierAssets", "provider"]);
|
|
83675
|
-
function
|
|
83704
|
+
function isRecord6(value) {
|
|
83676
83705
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
83677
83706
|
}
|
|
83678
83707
|
function safeCount(value) {
|
|
@@ -83699,42 +83728,15 @@ async function readGatewayJson(url, headers) {
|
|
|
83699
83728
|
return { status: null };
|
|
83700
83729
|
}
|
|
83701
83730
|
}
|
|
83702
|
-
async function
|
|
83703
|
-
|
|
83704
|
-
const token = process.env.BILLING_INTERNAL_TOKEN?.trim() || await readHiddenValue("Gateway admin token: ");
|
|
83705
|
-
if (!token)
|
|
83706
|
-
throw new Error("Base Sepolia V2 setup requires gateway admin access to check the activated credential root");
|
|
83707
|
-
let response;
|
|
83708
|
-
try {
|
|
83709
|
-
response = await fetch(new URL("/v1/admin/root-known", origin), {
|
|
83710
|
-
method: "POST",
|
|
83711
|
-
headers: {
|
|
83712
|
-
accept: "application/json",
|
|
83713
|
-
authorization: `Bearer ${token}`,
|
|
83714
|
-
"content-type": "application/json"
|
|
83715
|
-
},
|
|
83716
|
-
body: JSON.stringify({ root }),
|
|
83717
|
-
signal: AbortSignal.timeout(1e4)
|
|
83718
|
-
});
|
|
83719
|
-
} catch {
|
|
83720
|
-
throw new Error("The gateway could not confirm that the activated credential root is known");
|
|
83721
|
-
}
|
|
83722
|
-
let body;
|
|
83723
|
-
try {
|
|
83724
|
-
body = await response.json();
|
|
83725
|
-
} catch {
|
|
83726
|
-
body = void 0;
|
|
83727
|
-
}
|
|
83728
|
-
if (response.status !== 200 || !isRecord5(body) || body.known !== true) {
|
|
83729
|
-
throw new Error("The activated credential root is not in the gateway known-root set; stop setup and reconcile the V2 activation");
|
|
83730
|
-
}
|
|
83731
|
+
async function requireGatewayKnownRoot2(root) {
|
|
83732
|
+
await requireGatewayKnownRoot(root, gatewayOrigin());
|
|
83731
83733
|
}
|
|
83732
83734
|
async function gatewayReadiness(origin) {
|
|
83733
83735
|
const response = await readGatewayJson(new URL("/ready", origin), { accept: "application/json" });
|
|
83734
|
-
const report =
|
|
83736
|
+
const report = isRecord6(response.body) ? response.body : void 0;
|
|
83735
83737
|
const checks = Array.isArray(report?.checks) ? report.checks : [];
|
|
83736
|
-
const failedChecks = checks.flatMap((check) =>
|
|
83737
|
-
const hasLaunchCheck = checks.some((check) =>
|
|
83738
|
+
const failedChecks = checks.flatMap((check) => isRecord6(check) && check.ok === true ? [] : [isRecord6(check) && typeof check.name === "string" && GATEWAY_READINESS_CHECK_NAMES.has(check.name) ? check.name : "unknown"]);
|
|
83739
|
+
const hasLaunchCheck = checks.some((check) => isRecord6(check) && check.name === "launchControl" && check.ok === true);
|
|
83738
83740
|
return {
|
|
83739
83741
|
status: response.status,
|
|
83740
83742
|
passed: response.status === 200 && report?.ready === true && failedChecks.length === 0 && hasLaunchCheck,
|
|
@@ -83746,12 +83748,12 @@ async function gatewayTrialSnapshot(origin, token) {
|
|
|
83746
83748
|
accept: "application/json",
|
|
83747
83749
|
authorization: `Bearer ${token}`
|
|
83748
83750
|
});
|
|
83749
|
-
const body =
|
|
83750
|
-
const launch =
|
|
83751
|
-
const base =
|
|
83752
|
-
const spend =
|
|
83753
|
-
const rawMetrics =
|
|
83754
|
-
const rawClaims =
|
|
83751
|
+
const body = isRecord6(response.body) ? response.body : void 0;
|
|
83752
|
+
const launch = isRecord6(body?.launchControl) ? body.launchControl : void 0;
|
|
83753
|
+
const base = isRecord6(body?.base) ? body.base : void 0;
|
|
83754
|
+
const spend = isRecord6(body?.spend) ? body.spend : void 0;
|
|
83755
|
+
const rawMetrics = isRecord6(body?.metrics) ? body.metrics : void 0;
|
|
83756
|
+
const rawClaims = isRecord6(body?.claims) ? body.claims : void 0;
|
|
83755
83757
|
const metrics = {};
|
|
83756
83758
|
const claims = {};
|
|
83757
83759
|
let countersValid = Boolean(rawMetrics && rawClaims);
|
|
@@ -84039,7 +84041,7 @@ async function main() {
|
|
|
84039
84041
|
const provider = await witnessProviderForSource(source, join7(stateDirectory(), "base-event-sync.json"));
|
|
84040
84042
|
const witness = validateBaseCreditWitness(await provider.witnessForCredential(credential));
|
|
84041
84043
|
if (manifest.deployment)
|
|
84042
|
-
await
|
|
84044
|
+
await requireGatewayKnownRoot2(witness.root);
|
|
84043
84045
|
},
|
|
84044
84046
|
chooseCandidate: chooseSetupCandidate
|
|
84045
84047
|
});
|
package/package.json
CHANGED