CodeSampleX

Ejemplo

@sigstore/verify 2.1.1: Verifier, toSignedEntity, toTrustMaterial

Muestra verificada para npm @sigstore/verify 2.1.1: Verifier, toSignedEntity, toTrustMaterial. El contrato se ejecutó en node 22 · linux debian/x64 · docker…

sha256:c6a6e060c709470af17ee9c33b623941c68721d8849ab6715e52712c77473692

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node linux 24 · ubuntu · glibc 2.39 x64 node javascript npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-10-18

Caso

HOW
Objetivo
verify pkg:npm/%40sigstore/verify@2.1.1
Paquetes
Símbolos
  • Verifier
  • toSignedEntity
  • toTrustMaterial
  • VerificationError
Entorno
node
Creado
2026-10-18T04:31:29Z

Contrato

  1. toTrustMaterial converts a TrustedRoot and public key map into TrustMaterial
  2. toSignedEntity converts a Sigstore bundle and artifact buffer into a SignedEntity
  3. Verifier.verify returns the Signer with key when signature matches the artifact and throws VerificationError with code SIGNATURE_ERROR when tampered

Archivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • test/contract.mjs

Descargar el artefacto de código fuente (tar.gz)

Código fuente

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:npm/%40sigstore/verify@2.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40sigstore/verify@2.1.1

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:b2bf6fd78e31e9cec2fb975b3db779f636de5779a2024406decbd6060301957b","contract":["toTrustMaterial converts a TrustedRoot and public key map into TrustMaterial","toSignedEntity converts a Sigstore bundle and artifact buffer into a SignedEntity","Verifier.verify returns the Signer with key when signature matches the artifact and throws VerificationError with code SIGNATURE_ERROR when tampered"],"goal":"verify pkg:npm/%40sigstore/verify@2.1.1","kind":"HOW","packages":["pkg:npm/%40sigstore/verify@2.1.1"],"schemaVersion":1,"symbols":["Verifier","toSignedEntity","toTrustMaterial","VerificationError"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40sigstore/verify@2.1.1"],"schemaVersion":1,"subject":"pkg:npm/%40sigstore/verify@2.1.1","symbols":["Verifier","toSignedEntity","toTrustMaterial","VerificationError"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sigstore-verify-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sigstore-verify-sample",
      "version": "1.0.0",
      "dependencies": {
        "@sigstore/verify": "2.1.1"
      }
    },
    "node_modules/@sigstore/bundle": {
      "version": "3.1.0",
      "resolved": "https://registry.npmjs.org/@sigstore/bundle/-/bundle-3.1.0.tgz",
      "integrity": "sha512-Mm1E3/CmDDCz3nDhFKTuYdB47EdRFRQMOE/EAbiG1MJW77/w1b3P7Qx7JSrVJs8PfwOLOVcKQCHErIwCTyPbag==",
      "license": "Apache-2.0",
      "dependencies": {
        "@sigstore/protobuf-specs": "^0.4.0"
      },
      "engines": {
        "node": "^18.17.0 || >=20.5.0"
      }
    },
    "node_modules/@sigstore/core": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/@sigstore/core/-/core-2.0.0.tgz",
      "integrity": "sha512-nYxaSb/MtlSI+JWcwTHQxyNmWeWrUXJJ/G4liLrGG7+tS4vAz6LF3xRXqLH6wPIVUoZQel2Fs4ddLx4NCpiIYg==",
      "license": "Apache-2.0",
      "engines": {
        "node": "^18.17.0 || >=20.5.0"
      }
    },
    "node_modules/@sigstore/protobuf-specs": {
      "version": "0.4.3",
      "resolved": "https://registry.npmjs.org/@sigstore/protobuf-specs/-/protobuf-specs-0.4.3.tgz",
      "integrity": "sha512-fk2zjD9117RL9BjqEwF7fwv7Q/P9yGsMV4MUJZ/DocaQJ6+3pKr+syBq1owU5Q5qGw5CUbXzm+4yJ2JVRDQeSA==",
      "license": "Apache-2.0",
      "engines": {
        "node": "^18.17.0 || >=20.5.0"
      }
    },
    "node_modules/@sigstore/verify": {
      "version": "2.1.1",
      "resolved": "https://registry.npmjs.org/@sigstore/verify/-/verify-2.1.1.tgz",
      "integrity": "sha512-hVJD77oT67aowHxwT4+M6PGOp+E2LtLdTK3+FC0lBO9T7sYwItDMXZ7Z07IDCvR1M717a4axbIWckrW67KMP/w==",
      "license": "Apache-2.0",
      "dependencies": {
        "@sigstore/bundle": "^3.1.0",
        "@sigstore/core": "^2.0.0",
        "@sigstore/protobuf-specs": "^0.4.1"
      },
      "engines": {
        "node": "^18.17.0 || >=20.5.0"
      }
    }
  }
}
package.json
{
  "name": "sigstore-verify-sample",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "dependencies": {
    "@sigstore/verify": "2.1.1"
  },
  "scripts": {
    "test": "node test/contract.mjs"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40sigstore/verify@2.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40sigstore/verify@2.1.1"
  ]
}
src/index.mjs
import { Verifier, toSignedEntity, toTrustMaterial, VerificationError } from '@sigstore/verify';
import crypto from 'node:crypto';

export function createKeyPairAndSign(artifact) {
  const { publicKey, privateKey } = crypto.generateKeyPairSync('ec', {
    namedCurve: 'P-256',
  });
  const signature = crypto.sign(null, artifact, privateKey);
  const digest = crypto.createHash('sha256').update(artifact).digest();
  const spkiDer = publicKey.export({ type: 'spki', format: 'der' });

  const bundle = {
    mediaType: 'application/vnd.dev.sigstore.bundle.v0.3+json',
    verificationMaterial: {
      content: {
        $case: 'publicKey',
        publicKey: {
          hint: 'key-1',
        },
      },
      tlogEntries: [],
      timestampVerificationData: {
        rfc3161Timestamps: [],
      },
    },
    content: {
      $case: 'messageSignature',
      messageSignature: {
        messageDigest: {
          algorithm: 1,
          digest,
        },
        signature,
      },
    },
  };

  const trustedRoot = {
    mediaType: 'application/vnd.dev.sigstore.trustedroot+json;version=0.1',
    certificateAuthorities: [],
    timestampAuthorities: [],
    tlogs: [],
    ctlogs: [],
  };

  const trustMaterial = toTrustMaterial(trustedRoot, {
    'key-1': {
      rawBytes: spkiDer,
      keyDetails: 5,
    },
  });

  return { bundle, trustMaterial, publicKey };
}

export function verifyBundle(bundle, artifact, trustMaterial) {
  const entity = toSignedEntity(bundle, artifact);
  const verifier = new Verifier(trustMaterial, {
    tlogThreshold: 0,
    ctlogThreshold: 0,
    tsaThreshold: 0,
  });
  return verifier.verify(entity);
}

export { VerificationError };
test/contract.mjs
import assert from 'node:assert/strict';
import { createKeyPairAndSign, verifyBundle, VerificationError } from '../src/index.mjs';

const artifact = Buffer.from('hello sigstore verification');
const { bundle, trustMaterial } = createKeyPairAndSign(artifact);

// 1. Valid verification succeeds and returns signer with public key
const signer = verifyBundle(bundle, artifact, trustMaterial);
assert.ok(signer && signer.key, 'Expected verifyBundle to return a signer with a key');
assert.equal(signer.key.asymmetricKeyType, 'ec');

// 2. Tampered artifact fails signature verification with VerificationError
const tamperedArtifact = Buffer.from('tampered content');
assert.throws(
  () => verifyBundle(bundle, tamperedArtifact, trustMaterial),
  (err) => err instanceof VerificationError && err.code === 'SIGNATURE_ERROR'
);

Seeder de origen

anónimo