@signet-registry/operator 0.0.0-stage → 0.1.5

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.
Files changed (36) hide show
  1. package/LICENSE +29 -0
  2. package/README.md +191 -2
  3. package/dist/clients/api.js +257 -0
  4. package/dist/clients/mcp.js +118 -0
  5. package/dist/clients/verify.js +125 -0
  6. package/dist/config/env.js +42 -0
  7. package/dist/keyless.js +52 -0
  8. package/dist/main.js +7 -0
  9. package/dist/operator.js +1729 -0
  10. package/dist/transparency/sample-graph.js +203 -0
  11. package/dist/types.js +111 -0
  12. package/examples/bootstrap/agents/bootstrap-agent.md +5 -0
  13. package/examples/bootstrap/agents/bootstrap-ops-agent.md +8 -0
  14. package/examples/bootstrap/bootstrap.manifest.json +107 -0
  15. package/examples/bootstrap/skills/bootstrap-example.md +8 -0
  16. package/examples/bootstrap/skills/bootstrap-ops.md +8 -0
  17. package/examples/demo/agents/registry-agent.md +34 -0
  18. package/examples/demo/demo.manifest.json +90 -0
  19. package/examples/demo/skills/registry-mcp.md +74 -0
  20. package/examples/demo/skills/tame-llama.md +37 -0
  21. package/examples/signet-demo/agents/signet-demo-agent.md +39 -0
  22. package/examples/signet-demo/agents/signet-security-agent.md +36 -0
  23. package/examples/signet-demo/signet-demo.manifest.json +219 -0
  24. package/examples/signet-demo/skills/access-review.md +40 -0
  25. package/examples/signet-demo/skills/certification-workflow.md +39 -0
  26. package/examples/signet-demo/skills/governance-audit.md +39 -0
  27. package/examples/signet-demo/skills/graph-explorer.md +38 -0
  28. package/examples/signet-demo/skills/mcp-onboarding.md +39 -0
  29. package/examples/signet-demo/skills/policy-authoring.md +39 -0
  30. package/examples/signet-demo/skills/provenance-audit.md +39 -0
  31. package/examples/signet-demo/skills/registry-search.md +38 -0
  32. package/examples/signet-demo/skills/secrets-hygiene.md +39 -0
  33. package/examples/signet-demo/skills/skill-authoring.md +40 -0
  34. package/examples/transparency/README.md +39 -0
  35. package/examples/transparency/sample-graph.spec.json +16 -0
  36. package/package.json +58 -4
@@ -0,0 +1,125 @@
1
+ import { createHash, createPublicKey, verify as verifySignature } from 'node:crypto';
2
+ export function sha256Hex(input) {
3
+ return createHash('sha256').update(input).digest('hex');
4
+ }
5
+ function parseSignatureBytes(signature) {
6
+ if (signature.startsWith('base64:')) {
7
+ return Buffer.from(signature.slice('base64:'.length), 'base64');
8
+ }
9
+ if (signature.startsWith('hex:')) {
10
+ return Buffer.from(signature.slice('hex:'.length), 'hex');
11
+ }
12
+ throw new Error('Signature must use a supported encoding prefix such as base64: or hex:.');
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
+ }
33
+ // Mirrors the algorithms accepted by the registry core so operator verification
34
+ // reproduces the server verdict locally.
35
+ export function verifyDetachedSignature(input) {
36
+ try {
37
+ const key = createPublicKey(input.publicKeyPem);
38
+ const signatureBytes = parseSignatureBytes(input.signature);
39
+ const message = typeof input.message === 'string' ? Buffer.from(input.message, 'utf8') : input.message;
40
+ switch (input.algorithm) {
41
+ case 'ed25519':
42
+ case 'ed448':
43
+ return verifySignature(null, message, key, signatureBytes);
44
+ case 'rsa-sha256':
45
+ case 'ecdsa-p256-sha256':
46
+ case 'ecdsa-sha256':
47
+ return verifySignature('sha256', message, key, signatureBytes);
48
+ case 'ecdsa-p384-sha384':
49
+ case 'ecdsa-sha384':
50
+ return verifySignature('sha384', message, key, signatureBytes);
51
+ default:
52
+ return false;
53
+ }
54
+ }
55
+ catch {
56
+ return false;
57
+ }
58
+ }
59
+ /**
60
+ * Mirrors the registry's verdict logic for detached provenance signatures.
61
+ * Fetch the canonical N-Quads artifact the signature binds
62
+ * (`provenance_sha256`, via \`GET /v1/artifacts/{sha256}\`), pass those bytes
63
+ * here, and pass the current export digest as \`currentProvenanceSha256\` to
64
+ * distinguish \`valid\` from \`stale\` after the provenance has grown.
65
+ */
66
+ export function verifyProvenanceSignature(input) {
67
+ const bytes = typeof input.canonicalRdfBytes === 'string'
68
+ ? Buffer.from(input.canonicalRdfBytes, 'utf8')
69
+ : input.canonicalRdfBytes;
70
+ const digest_matches = sha256Hex(bytes) === input.signature.provenance_sha256;
71
+ const publicKeyPem = input.resolvePublicKey(input.signature.key_ref);
72
+ const signature_valid = digest_matches && publicKeyPem !== undefined
73
+ ? verifyDetachedSignature({
74
+ algorithm: input.signature.algorithm,
75
+ publicKeyPem,
76
+ message: bytes,
77
+ signature: input.signature.signature,
78
+ })
79
+ : false;
80
+ const verdict = !digest_matches || !signature_valid
81
+ ? 'invalid'
82
+ : input.currentProvenanceSha256 !== undefined &&
83
+ input.signature.provenance_sha256 !== input.currentProvenanceSha256
84
+ ? 'stale'
85
+ : 'valid';
86
+ return {
87
+ key_ref: input.signature.key_ref,
88
+ algorithm: input.signature.algorithm,
89
+ digest_matches,
90
+ signature_valid,
91
+ verdict,
92
+ };
93
+ }
94
+ export function verifyEnvelopeSignatures(input) {
95
+ const canonical_json_sha256_matches = sha256Hex(Buffer.from(input.envelope.canonical_json, 'utf8')) === input.envelope.canonical_json_sha256;
96
+ const signatures = input.envelope.detached_signatures.map((signature) => {
97
+ const signedPayload = signature.signed_payload ?? 'canonical_json';
98
+ const expectedDigest = signedPayload === 'canonical_rdf' ? input.envelope.canonical_rdf_sha256 : input.envelope.canonical_json_sha256;
99
+ const digest_matches = expectedDigest !== undefined && signature.envelope_sha256 === expectedDigest;
100
+ const message = signedPayload === 'canonical_rdf'
101
+ ? input.canonicalRdfBytes
102
+ : Buffer.from(input.envelope.canonical_json, 'utf8');
103
+ const publicKeyPem = message ? input.resolvePublicKey(signature.key_ref) : undefined;
104
+ const signature_valid = digest_matches && publicKeyPem !== undefined && message !== undefined
105
+ ? verifyDetachedSignature({
106
+ algorithm: signature.algorithm,
107
+ publicKeyPem,
108
+ message,
109
+ signature: signature.signature,
110
+ })
111
+ : false;
112
+ return {
113
+ key_ref: signature.key_ref,
114
+ algorithm: signature.algorithm,
115
+ signed_payload: signedPayload,
116
+ digest_matches,
117
+ signature_valid,
118
+ };
119
+ });
120
+ return {
121
+ canonical_json_sha256_matches,
122
+ signatures,
123
+ all_signatures_valid: signatures.every((signature) => signature.signature_valid),
124
+ };
125
+ }
@@ -0,0 +1,42 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import * as path from 'node:path';
3
+ import { z } from 'zod';
4
+ function defaultRepoRoot() {
5
+ const here = path.dirname(fileURLToPath(import.meta.url));
6
+ return path.resolve(here, '..', '..', '..', '..');
7
+ }
8
+ function defaultApiEnvFile() {
9
+ return path.join(defaultRepoRoot(), 'service', 'api', 'infra', '.env');
10
+ }
11
+ function defaultWebappEnvFile() {
12
+ return path.join(defaultRepoRoot(), 'service', 'webapp', 'knowledge-manager', 'infra', '.env');
13
+ }
14
+ function defaultMcpEnvFile() {
15
+ return path.join(defaultRepoRoot(), 'service', 'mcp', 'infra', '.env');
16
+ }
17
+ const EnvSchema = z.object({
18
+ API_ORIGIN: z.string().url().default('http://localhost:3100'),
19
+ MCP_ORIGIN: z.string().url().default('http://localhost:3000'),
20
+ WEBAPP_ORIGIN: z.string().url().default('http://localhost:3200'),
21
+ REPO_ROOT: z.string().default(defaultRepoRoot()),
22
+ API_ENV_FILE: z.string().default(defaultApiEnvFile()),
23
+ WEBAPP_ENV_FILE: z.string().default(defaultWebappEnvFile()),
24
+ MCP_ENV_FILE: z.string().default(defaultMcpEnvFile()),
25
+ // Cloudflare Access service-token headers for the deployed tunnels
26
+ // (machine clients outside the edge access layer). Both must be set to take effect.
27
+ SIGNET_CF_ACCESS_CLIENT_ID: z.string().optional(),
28
+ SIGNET_CF_ACCESS_CLIENT_SECRET: z.string().optional(),
29
+ });
30
+ export function loadEnv(input = process.env) {
31
+ return EnvSchema.parse(input);
32
+ }
33
+ /** Cloudflare Access headers for machine clients, when configured. */
34
+ export function cfAccessHeaders(env) {
35
+ if (env.SIGNET_CF_ACCESS_CLIENT_ID && env.SIGNET_CF_ACCESS_CLIENT_SECRET) {
36
+ return {
37
+ 'CF-Access-Client-Id': env.SIGNET_CF_ACCESS_CLIENT_ID,
38
+ 'CF-Access-Client-Secret': env.SIGNET_CF_ACCESS_CLIENT_SECRET,
39
+ };
40
+ }
41
+ return {};
42
+ }
@@ -0,0 +1,52 @@
1
+ import { bundleToJSON } from '@sigstore/bundle';
2
+ import { X509Certificate } from '@sigstore/core';
3
+ import { CIContextProvider, FulcioSigner, MessageSignatureBundleBuilder, RekorWitness } from '@sigstore/sign';
4
+ const OIDC_ISSUER_OID_V1 = '1.3.6.1.4.1.57264.1.1';
5
+ const OIDC_ISSUER_OID_V2 = '1.3.6.1.4.1.57264.1.8';
6
+ function oidcIssuerFromCertificate(cert) {
7
+ const v2 = cert.extension(OIDC_ISSUER_OID_V2);
8
+ if (v2) {
9
+ const value = v2.valueObj?.subs?.[0]?.value;
10
+ if (value)
11
+ return value.toString('ascii');
12
+ }
13
+ const v1 = cert.extension(OIDC_ISSUER_OID_V1);
14
+ return v1 ? v1.value.toString('ascii') : undefined;
15
+ }
16
+ function readBundleIdentity(bundle) {
17
+ const material = bundle['verificationMaterial'];
18
+ const chain = material?.['x509CertificateChain'];
19
+ const certificate = material?.['certificate'] ?? chain?.certificates?.[0];
20
+ const rawBytes = certificate?.['rawBytes'];
21
+ if (typeof rawBytes !== 'string') {
22
+ throw new Error('Fulcio bundle does not carry a signing certificate.');
23
+ }
24
+ const cert = X509Certificate.parse(Buffer.from(rawBytes, 'base64'));
25
+ const identity = cert.subjectAltName;
26
+ const issuer = oidcIssuerFromCertificate(cert);
27
+ if (!identity || !issuer) {
28
+ throw new Error('Signing certificate is missing its subject alternative name or OIDC issuer.');
29
+ }
30
+ return { identity, issuer };
31
+ }
32
+ // Keyless (sigstore) signing for CI: the OIDC identity (ambient in GitHub
33
+ // Actions via CIContextProvider, or an explicit token) is exchanged at Fulcio
34
+ // for a short-lived certificate, the payload bytes are signed with an
35
+ // ephemeral P-256 key, and the sigstore bundle is assembled (serialized JSON,
36
+ // the shape the registry verifies). Rekor upload is optional.
37
+ export async function buildKeylessBundle(input) {
38
+ const identityProvider = input.oidcToken
39
+ ? { getToken: async () => input.oidcToken }
40
+ : new CIContextProvider();
41
+ const signer = new FulcioSigner({
42
+ identityProvider,
43
+ ...(input.fulcioBaseURL ? { fulcioBaseURL: input.fulcioBaseURL } : {}),
44
+ });
45
+ const builder = new MessageSignatureBundleBuilder({
46
+ signer,
47
+ witnesses: input.rekorBaseURL ? [new RekorWitness({ rekorBaseURL: input.rekorBaseURL })] : [],
48
+ });
49
+ const bundle = await builder.create({ data: input.data });
50
+ const serialized = bundleToJSON(bundle);
51
+ return { bundle: serialized, ...readBundleIdentity(serialized) };
52
+ }
package/dist/main.js ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { runCli } from './operator.js';
3
+ await runCli(process.argv.slice(2)).catch((err) => {
4
+ const message = err instanceof Error ? err.message : String(err);
5
+ console.error(message);
6
+ process.exitCode = 1;
7
+ });