@signet-registry/operator 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/api.js +6 -0
- package/dist/clients/verify.js +19 -0
- package/dist/operator.js +156 -40
- package/dist/transparency/sample-graph.js +15 -3
- package/package.json +1 -1
package/dist/clients/api.js
CHANGED
|
@@ -181,6 +181,12 @@ export class HttpRegistryOperatorApiClient {
|
|
|
181
181
|
async getAgentProvenance(agentKey, version, apiToken) {
|
|
182
182
|
return await this.fetchJson(`/v1/agents/${encodeURIComponent(agentKey)}/versions/${version}/provenance`, undefined, apiToken);
|
|
183
183
|
}
|
|
184
|
+
async getSkillReportSignatures(skillKey, version, apiToken) {
|
|
185
|
+
return await this.fetchJson(`/v1/skills/${encodeURIComponent(skillKey)}/versions/${version}/report-signatures`, undefined, apiToken);
|
|
186
|
+
}
|
|
187
|
+
async getAgentReportSignatures(agentKey, version, apiToken) {
|
|
188
|
+
return await this.fetchJson(`/v1/agents/${encodeURIComponent(agentKey)}/versions/${version}/report-signatures`, undefined, apiToken);
|
|
189
|
+
}
|
|
184
190
|
async getAgentPublicationVerification(agentKey, version, apiToken) {
|
|
185
191
|
return await this.fetchJson(`/v1/agents/${encodeURIComponent(agentKey)}/versions/${version}/verification`, undefined, apiToken);
|
|
186
192
|
}
|
package/dist/clients/verify.js
CHANGED
|
@@ -11,6 +11,25 @@ function parseSignatureBytes(signature) {
|
|
|
11
11
|
}
|
|
12
12
|
throw new Error('Signature must use a supported encoding prefix such as base64: or hex:.');
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Mirrors the registry's trusted-key resolver: a key is usable only when its
|
|
16
|
+
* status is `trusted` and the current time is inside its validity window
|
|
17
|
+
* (`valid_from` inclusive, `valid_to` exclusive; absent bounds are
|
|
18
|
+
* unlimited). Revoked/expired/not-yet-valid keys must stay out of local
|
|
19
|
+
* verification so CLI verdicts match the server's
|
|
20
|
+
* `trusted_public_key_resolved` semantics.
|
|
21
|
+
*/
|
|
22
|
+
export function isTrustedKeyUsableAt(properties, nowIso) {
|
|
23
|
+
if (properties['trust_status'] !== 'trusted')
|
|
24
|
+
return false;
|
|
25
|
+
const validFrom = typeof properties['valid_from'] === 'string' ? properties['valid_from'] : undefined;
|
|
26
|
+
const validTo = typeof properties['valid_to'] === 'string' ? properties['valid_to'] : undefined;
|
|
27
|
+
if (validFrom && nowIso < validFrom)
|
|
28
|
+
return false;
|
|
29
|
+
if (validTo && nowIso >= validTo)
|
|
30
|
+
return false;
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
14
33
|
// Mirrors the algorithms accepted by the registry core so operator verification
|
|
15
34
|
// reproduces the server verdict locally.
|
|
16
35
|
export function verifyDetachedSignature(input) {
|
package/dist/operator.js
CHANGED
|
@@ -8,7 +8,7 @@ import { cfAccessHeaders, loadEnv } from './config/env.js';
|
|
|
8
8
|
import { AgentSeedSpecSchema, BootstrapManifestSchema, SkillSeedSpecSchema, } from './types.js';
|
|
9
9
|
import { HttpRegistryOperatorApiClient, RegistryOperatorApiError } from './clients/api.js';
|
|
10
10
|
import { RegistryOperatorMcpClient } from './clients/mcp.js';
|
|
11
|
-
import { sha256Hex, verifyEnvelopeSignatures, verifyProvenanceSignature } from './clients/verify.js';
|
|
11
|
+
import { sha256Hex, isTrustedKeyUsableAt, verifyEnvelopeSignatures, verifyProvenanceSignature } from './clients/verify.js';
|
|
12
12
|
import { buildTransparencySampleGraphSpec, readTransparencySampleGraphSpec, seedTransparencySampleGraph, } from './transparency/sample-graph.js';
|
|
13
13
|
const AuthCreateApiKeyResultSchema = z.object({
|
|
14
14
|
token: z.string().min(1),
|
|
@@ -51,6 +51,8 @@ export async function runCli(argv) {
|
|
|
51
51
|
return await runVerifyArtifact(env, command.args);
|
|
52
52
|
if (command.action === 'provenance')
|
|
53
53
|
return await runVerifyProvenance(env, command.args);
|
|
54
|
+
if (command.action === 'report-signatures')
|
|
55
|
+
return await runVerifyReportSignatures(env, command.args);
|
|
54
56
|
return await runVerifyBrowserSession(env, command.args);
|
|
55
57
|
case 'bootstrap':
|
|
56
58
|
return await runBootstrapTest(env, command.args);
|
|
@@ -73,7 +75,7 @@ export function parseArgs(argv) {
|
|
|
73
75
|
if (group === 'seed' && (action === 'skill' || action === 'agent' || action === 'bootstrap' || action === 'transparency-sample')) {
|
|
74
76
|
return { group: 'seed', action, args };
|
|
75
77
|
}
|
|
76
|
-
if (group === 'verify' && (action === 'api' || action === 'mcp' || action === 'okta-config' || action === 'browser-session' || action === 'publication' || action === 'artifact' || action === 'provenance')) {
|
|
78
|
+
if (group === 'verify' && (action === 'api' || action === 'mcp' || action === 'okta-config' || action === 'browser-session' || action === 'publication' || action === 'artifact' || action === 'provenance' || action === 'report-signatures')) {
|
|
77
79
|
return { group: 'verify', action, args };
|
|
78
80
|
}
|
|
79
81
|
if (group === 'bootstrap' && action === 'test') {
|
|
@@ -441,6 +443,39 @@ async function runVerifyMcp(env, args) {
|
|
|
441
443
|
// Non-strict mode passes for a publication with no signatures (vacuous
|
|
442
444
|
// validity); --strict additionally requires the server verdict, at least one
|
|
443
445
|
// valid signature, and a matching frozen-envelope artifact when present.
|
|
446
|
+
/**
|
|
447
|
+
* Resolve trusted signing keys to their PEMs (stored as CAS artifacts),
|
|
448
|
+
* mirroring the registry's resolver: the key must be `trusted` and inside
|
|
449
|
+
* its validity window before its PEM is used. Revoked/expired/not-yet-valid
|
|
450
|
+
* keys stay absent so local verdicts match the server's
|
|
451
|
+
* `trusted_public_key_resolved` semantics (a revoked key's signatures must
|
|
452
|
+
* read as invalid, not verified).
|
|
453
|
+
*/
|
|
454
|
+
async function loadTrustedPublicKeyPems(api, keyRefs, apiToken) {
|
|
455
|
+
const publicKeys = new Map();
|
|
456
|
+
const now = new Date().toISOString();
|
|
457
|
+
for (const keyRef of new Set(keyRefs)) {
|
|
458
|
+
if (!keyRef)
|
|
459
|
+
continue;
|
|
460
|
+
try {
|
|
461
|
+
const key = await api.getPublicKey(keyRef, apiToken);
|
|
462
|
+
const publicKey = key['public_key'];
|
|
463
|
+
const properties = publicKey?.properties;
|
|
464
|
+
if (!properties || !isTrustedKeyUsableAt(properties, now))
|
|
465
|
+
continue;
|
|
466
|
+
const artifacts = Array.isArray(key['artifacts']) ? key['artifacts'] : [];
|
|
467
|
+
const sha = parseArtifactUrnSha256(artifacts[0]?.artifact_urn);
|
|
468
|
+
if (!sha)
|
|
469
|
+
continue;
|
|
470
|
+
const { bytes } = await api.getArtifactBytes(sha, apiToken);
|
|
471
|
+
publicKeys.set(keyRef, new TextDecoder().decode(bytes));
|
|
472
|
+
}
|
|
473
|
+
catch {
|
|
474
|
+
// Unresolvable or untrusted keys stay absent; their signatures fail verification.
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return publicKeys;
|
|
478
|
+
}
|
|
444
479
|
async function runVerifyPublication(env, args) {
|
|
445
480
|
const skillKey = asString(args.skill);
|
|
446
481
|
const agentKey = asString(args.agent);
|
|
@@ -460,26 +495,14 @@ async function runVerifyPublication(env, args) {
|
|
|
460
495
|
const signatures = Array.isArray(envelope['detached_signatures'])
|
|
461
496
|
? envelope['detached_signatures']
|
|
462
497
|
: [];
|
|
463
|
-
// Resolve every trusted signing key to its PEM
|
|
464
|
-
//
|
|
465
|
-
//
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
const key = await api.getPublicKey(keyRef, apiToken);
|
|
472
|
-
const artifacts = Array.isArray(key['artifacts']) ? key['artifacts'] : [];
|
|
473
|
-
const sha = parseArtifactUrnSha256(artifacts[0]?.artifact_urn);
|
|
474
|
-
if (!sha)
|
|
475
|
-
continue;
|
|
476
|
-
const { bytes } = await api.getArtifactBytes(sha, apiToken);
|
|
477
|
-
publicKeys.set(keyRef, new TextDecoder().decode(bytes));
|
|
478
|
-
}
|
|
479
|
-
catch {
|
|
480
|
-
// Unresolvable keys stay absent; their signatures fail verification.
|
|
481
|
-
}
|
|
482
|
-
}
|
|
498
|
+
// Resolve every trusted signing key to its PEM, enforcing the same trust
|
|
499
|
+
// status + validity window as the registry. Keyless signatures carry no
|
|
500
|
+
// registered key: their trust policy lives with the registry, so their
|
|
501
|
+
// verdict is taken from the server verification.
|
|
502
|
+
const publicKeys = await loadTrustedPublicKeyPems(api, signatures
|
|
503
|
+
.filter((signature) => !signature.keyless)
|
|
504
|
+
.map((signature) => signature.key_ref)
|
|
505
|
+
.filter((keyRef) => Boolean(keyRef)), apiToken);
|
|
483
506
|
const clientVerdict = verifyEnvelopeSignatures({
|
|
484
507
|
envelope: {
|
|
485
508
|
canonical_json: String(envelope['canonical_json'] ?? ''),
|
|
@@ -597,24 +620,9 @@ async function runVerifyProvenance(env, args) {
|
|
|
597
620
|
const servedSignatures = Array.isArray(provenance['provenance_signatures'])
|
|
598
621
|
? provenance['provenance_signatures']
|
|
599
622
|
: [];
|
|
600
|
-
// Resolve every trusted signing key to its PEM
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
if (!keyRef)
|
|
604
|
-
continue;
|
|
605
|
-
try {
|
|
606
|
-
const key = await api.getPublicKey(keyRef, apiToken);
|
|
607
|
-
const artifacts = Array.isArray(key['artifacts']) ? key['artifacts'] : [];
|
|
608
|
-
const sha = parseArtifactUrnSha256(artifacts[0]?.artifact_urn);
|
|
609
|
-
if (!sha)
|
|
610
|
-
continue;
|
|
611
|
-
const { bytes } = await api.getArtifactBytes(sha, apiToken);
|
|
612
|
-
publicKeys.set(keyRef, new TextDecoder().decode(bytes));
|
|
613
|
-
}
|
|
614
|
-
catch {
|
|
615
|
-
// Unresolvable keys stay absent; their signatures fail verification.
|
|
616
|
-
}
|
|
617
|
-
}
|
|
623
|
+
// Resolve every trusted signing key to its PEM, enforcing the same trust
|
|
624
|
+
// status + validity window as the registry.
|
|
625
|
+
const publicKeys = await loadTrustedPublicKeyPems(api, servedSignatures.map((row) => row.key_ref).filter((keyRef) => Boolean(keyRef)), apiToken);
|
|
618
626
|
// Reproduce each verdict locally: fetch the stored signature record, the
|
|
619
627
|
// canonical artifact it binds, and check the crypto against the key.
|
|
620
628
|
const signatures = [];
|
|
@@ -678,6 +686,114 @@ async function runVerifyProvenance(env, args) {
|
|
|
678
686
|
throw new Error('Provenance did not verify.');
|
|
679
687
|
}
|
|
680
688
|
}
|
|
689
|
+
async function runVerifyReportSignatures(env, args) {
|
|
690
|
+
const skillKey = asString(args.skill);
|
|
691
|
+
const agentKey = asString(args.agent);
|
|
692
|
+
const version = Number(asString(args.version));
|
|
693
|
+
const strict = args.strict === true;
|
|
694
|
+
const apiToken = asString(args['api-token']);
|
|
695
|
+
if ((!skillKey && !agentKey) || (skillKey && agentKey) || !Number.isInteger(version) || version <= 0) {
|
|
696
|
+
throw new Error('Usage: registry-operator verify report-signatures (--skill <key> | --agent <key>) --version <n> [--strict] [--api-token <token>]');
|
|
697
|
+
}
|
|
698
|
+
const api = new HttpRegistryOperatorApiClient({ apiOrigin: env.API_ORIGIN, extraHeaders: cfAccessHeaders(env) });
|
|
699
|
+
const served = skillKey
|
|
700
|
+
? await api.getSkillReportSignatures(skillKey, version, apiToken)
|
|
701
|
+
: await api.getAgentReportSignatures(agentKey, version, apiToken);
|
|
702
|
+
const rows = Array.isArray(served['report_signatures'])
|
|
703
|
+
? served['report_signatures']
|
|
704
|
+
: [];
|
|
705
|
+
// Resolve every trusted signing key to its PEM, enforcing the same trust
|
|
706
|
+
// status + validity window as the registry.
|
|
707
|
+
const publicKeys = await loadTrustedPublicKeyPems(api, rows.map((row) => row.key_ref).filter((keyRef) => Boolean(keyRef)), apiToken);
|
|
708
|
+
// Reproduce each verdict locally: the stored signature record, the target
|
|
709
|
+
// report (must still declare the signed digest), and the canonical RDF
|
|
710
|
+
// artifact the signature binds.
|
|
711
|
+
const signatures = [];
|
|
712
|
+
for (const row of rows) {
|
|
713
|
+
const recordSha = parseArtifactUrnSha256(row.artifact_urn);
|
|
714
|
+
let record = null;
|
|
715
|
+
try {
|
|
716
|
+
if (recordSha) {
|
|
717
|
+
const { bytes } = await api.getArtifactBytes(recordSha, apiToken);
|
|
718
|
+
record = JSON.parse(new TextDecoder().decode(bytes));
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
catch {
|
|
722
|
+
// Missing/unreadable signature record: the row fails verification.
|
|
723
|
+
}
|
|
724
|
+
const key_ref = typeof record?.['key_ref'] === 'string' ? record['key_ref'] : (row.key_ref ?? '');
|
|
725
|
+
const algorithm = typeof record?.['algorithm'] === 'string' ? record['algorithm'] : (row.algorithm ?? '');
|
|
726
|
+
const report_artifact_urn = typeof record?.['report_artifact_urn'] === 'string' ? record['report_artifact_urn'] : (row.report_artifact_urn ?? '');
|
|
727
|
+
const report_canonical_rdf_sha256 = typeof record?.['report_canonical_rdf_sha256'] === 'string'
|
|
728
|
+
? record['report_canonical_rdf_sha256']
|
|
729
|
+
: (row.report_canonical_rdf_sha256 ?? '');
|
|
730
|
+
const signature = typeof record?.['signature'] === 'string' ? record['signature'] : undefined;
|
|
731
|
+
const failRow = {
|
|
732
|
+
key_ref,
|
|
733
|
+
algorithm,
|
|
734
|
+
report_artifact_present: false,
|
|
735
|
+
digest_matches: false,
|
|
736
|
+
signature_valid: false,
|
|
737
|
+
verdict: 'invalid',
|
|
738
|
+
};
|
|
739
|
+
if (!signature || !report_canonical_rdf_sha256) {
|
|
740
|
+
signatures.push(failRow);
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
const reportSha = parseArtifactUrnSha256(report_artifact_urn);
|
|
744
|
+
let report_artifact_present = false;
|
|
745
|
+
try {
|
|
746
|
+
if (reportSha) {
|
|
747
|
+
const { bytes } = await api.getArtifactBytes(reportSha, apiToken);
|
|
748
|
+
const parsed = JSON.parse(new TextDecoder().decode(bytes));
|
|
749
|
+
report_artifact_present = parsed.payload?.rdf?.canonical_rdf_sha256 === report_canonical_rdf_sha256;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
catch {
|
|
753
|
+
report_artifact_present = false;
|
|
754
|
+
}
|
|
755
|
+
let signedBytes = null;
|
|
756
|
+
try {
|
|
757
|
+
const { bytes } = await api.getArtifactBytes(report_canonical_rdf_sha256, apiToken);
|
|
758
|
+
signedBytes = bytes;
|
|
759
|
+
}
|
|
760
|
+
catch {
|
|
761
|
+
// Missing/unreadable canonical artifact: the signature fails verification.
|
|
762
|
+
}
|
|
763
|
+
if (!signedBytes) {
|
|
764
|
+
signatures.push({ ...failRow, report_artifact_present });
|
|
765
|
+
continue;
|
|
766
|
+
}
|
|
767
|
+
const check = verifyProvenanceSignature({
|
|
768
|
+
canonicalRdfBytes: signedBytes,
|
|
769
|
+
signature: { key_ref, algorithm, provenance_sha256: report_canonical_rdf_sha256, signature },
|
|
770
|
+
resolvePublicKey: (ref) => publicKeys.get(ref),
|
|
771
|
+
});
|
|
772
|
+
signatures.push({
|
|
773
|
+
key_ref: check.key_ref,
|
|
774
|
+
algorithm: check.algorithm,
|
|
775
|
+
report_artifact_present,
|
|
776
|
+
digest_matches: check.digest_matches,
|
|
777
|
+
signature_valid: check.signature_valid,
|
|
778
|
+
verdict: report_artifact_present && check.verdict === 'valid' ? 'valid' : 'invalid',
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
const validSignatures = signatures.filter((check) => check.verdict === 'valid').length;
|
|
782
|
+
const invalidSignatures = signatures.filter((check) => check.verdict === 'invalid').length;
|
|
783
|
+
const strictFailures = strict && validSignatures === 0 ? ['no valid report signature'] : [];
|
|
784
|
+
const verified = invalidSignatures === 0 && strictFailures.length === 0;
|
|
785
|
+
console.log(JSON.stringify({
|
|
786
|
+
strict,
|
|
787
|
+
report_signatures: signatures,
|
|
788
|
+
valid_signatures: validSignatures,
|
|
789
|
+
invalid_signatures: invalidSignatures,
|
|
790
|
+
strict_failures: strictFailures,
|
|
791
|
+
verdict: verified ? 'verified' : 'unverified',
|
|
792
|
+
}, null, 2));
|
|
793
|
+
if (!verified) {
|
|
794
|
+
throw new Error('Report signatures did not verify.');
|
|
795
|
+
}
|
|
796
|
+
}
|
|
681
797
|
async function runVerifyArtifact(env, args) {
|
|
682
798
|
const apiToken = asString(args['api-token']);
|
|
683
799
|
const sha256 = asString(args.sha256) ?? parseArtifactUrnSha256(asString(args['artifact-urn']));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash, generateKeyPairSync, sign as signBytes } from 'node:crypto';
|
|
1
|
+
import { createHash, createPublicKey, generateKeyPairSync, sign as signBytes } from 'node:crypto';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
export const TransparencySampleGraphSpecSchema = z.object({
|
|
@@ -81,7 +81,7 @@ export async function seedTransparencySampleGraph(api, apiToken, input = {}) {
|
|
|
81
81
|
{
|
|
82
82
|
signer: spec.logId,
|
|
83
83
|
detachedSignature: checkpointSigTwo,
|
|
84
|
-
keyHintBytes:
|
|
84
|
+
keyHintBytes: specKeyHint(spec.logId, checkpointKey),
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
signer: spec.signerName,
|
|
@@ -108,7 +108,9 @@ export async function seedTransparencySampleGraph(api, apiToken, input = {}) {
|
|
|
108
108
|
const rootTwoAlt = `base64:${nodeHash(leafOne, leafTwoAlt).toString('base64')}`;
|
|
109
109
|
const checkpointBodyTwoAlt = checkpointBody(spec.logId, 2, rootTwoAlt);
|
|
110
110
|
const checkpointSigTwoAlt = encodeSignature(checkpointBodyTwoAlt, checkpointKey);
|
|
111
|
-
const checkpointTwoAltNote = signedCheckpointNote(checkpointBodyTwoAlt,
|
|
111
|
+
const checkpointTwoAltNote = signedCheckpointNote(checkpointBodyTwoAlt, [
|
|
112
|
+
{ signer: spec.logId, detachedSignature: checkpointSigTwoAlt, keyHintBytes: specKeyHint(spec.logId, checkpointKey) },
|
|
113
|
+
]);
|
|
112
114
|
await api.createTransparencyObservation(spec.logId, {
|
|
113
115
|
signed_note: checkpointTwoAltNote,
|
|
114
116
|
observed_from_type: 'peer',
|
|
@@ -198,6 +200,16 @@ function signedCheckpointNote(body, signatures) {
|
|
|
198
200
|
});
|
|
199
201
|
return `${body}\n${signatureLines.join('\n')}\n`;
|
|
200
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* Spec note-key hint (bigendian32(SHA256(origin + "\n" + 0x01||pubkey))[:4]).
|
|
205
|
+
* The registry's checkpoint seam enforces it for Ed25519 trusted keys, so
|
|
206
|
+
* seeded signed notes must bind to the log's key identity.
|
|
207
|
+
*/
|
|
208
|
+
function specKeyHint(origin, privateKey) {
|
|
209
|
+
const publicDer = createPublicKey(privateKey).export({ type: 'spki', format: 'der' });
|
|
210
|
+
const keyData = Buffer.concat([Buffer.from([0x01]), publicDer.subarray(publicDer.length - 32)]);
|
|
211
|
+
return [...createHash('sha256').update(origin).update('\n').update(keyData).digest().subarray(0, 4)];
|
|
212
|
+
}
|
|
201
213
|
function sha256Hex(bytes) {
|
|
202
214
|
return createHash('sha256').update(bytes).digest('hex');
|
|
203
215
|
}
|
package/package.json
CHANGED