CodeSampleX

示例

@sigstore/verify 2.1.1: VerificationError

已验证示例 — npm @sigstore/verify 2.1.1: VerificationError. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: assert new VerificationError({ code, message…

sha256:c7edb640de6a3eaccfa1cfeca7c1859951cbc7c440e7931adfa6b6f856b4c70b

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
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

案例

HOW
目标
verify @sigstore/verify.VerificationError in pkg:npm/%40sigstore/verify@2.1.1
包
符号
  • @sigstore/verify.VerificationError
环境
node 22.23.2
创建时间
2026-10-18T06:12:56Z

契约

  1. assert new VerificationError({ code, message, cause }) creates an Error and VerificationError instance with name 'VerificationError', code, message, and cause
  2. assert new VerificationError({ code, message }) without cause sets cause to undefined across all supported VerificationErrorCode values
  3. assert Verifier.prototype.verify throws VerificationError with code 'TIMESTAMP_ERROR' when transparency log timestamps are below tlogThreshold
  4. assert Verifier.prototype.verify throws VerificationError with code 'SIGNATURE_ERROR' when signature verification fails

文件

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

下载源代码构件 (tar.gz)

源代码

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 @sigstore/verify.VerificationError in pkg:npm/%40sigstore/verify@2.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40sigstore/verify@2.1.1
Demonstrate these symbols/APIs:
  - @sigstore/verify.VerificationError

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:accf68edb686c1994c55a34f67206b21b5bb366a7a4b651743eba4271a84b8ab","contract":["assert new VerificationError({ code, message, cause }) creates an Error and VerificationError instance with name 'VerificationError', code, message, and cause","assert new VerificationError({ code, message }) without cause sets cause to undefined across all supported VerificationErrorCode values","assert Verifier.prototype.verify throws VerificationError with code 'TIMESTAMP_ERROR' when transparency log timestamps are below tlogThreshold","assert Verifier.prototype.verify throws VerificationError with code 'SIGNATURE_ERROR' when signature verification fails"],"goal":"verify @sigstore/verify.VerificationError in pkg:npm/%40sigstore/verify@2.1.1","kind":"HOW","packages":["pkg:npm/%40sigstore/verify@2.1.1"],"schemaVersion":1,"symbols":["@sigstore/verify.VerificationError"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40sigstore/verify@2.1.1"],"schemaVersion":1,"subject":"pkg:npm/%40sigstore/verify@2.1.1","symbols":["@sigstore/verify.VerificationError"],"verifierAdapter":"node-typescript@1"}
index.js
const { VerificationError, Verifier } = require('@sigstore/verify');

function createVerificationError({ code, message, cause }) {
  return new VerificationError({ code, message, cause });
}

function isVerificationError(err, expectedCode) {
  if (!(err instanceof VerificationError)) {
    return false;
  }
  if (expectedCode !== undefined && err.code !== expectedCode) {
    return false;
  }
  return true;
}

module.exports = {
  VerificationError,
  Verifier,
  createVerificationError,
  isVerificationError,
};
package-lock.json
{
  "name": "sample-sigstore-verify-verification-error",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-sigstore-verify-verification-error",
      "version": "1.0.0",
      "license": "MIT-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": "sample-sigstore-verify-verification-error",
  "version": "1.0.0",
  "description": "Clean-room sample verifying @sigstore/verify.VerificationError",
  "main": "index.js",
  "license": "MIT-0",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@sigstore/verify": "2.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @sigstore/verify.VerificationError in pkg:npm/%40sigstore/verify@2.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40sigstore/verify@2.1.1"
  ],
  "symbols": [
    "@sigstore/verify.VerificationError"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import crypto from 'node:crypto';
import {
  VerificationError,
  Verifier,
  createVerificationError,
  isVerificationError,
} from '../index.js';

// 1. Construct VerificationError with code, message, and cause
const rootCause = new Error('underlying failure');
const errWithCause = createVerificationError({
  code: 'SIGNATURE_ERROR',
  message: 'signature verification failed',
  cause: rootCause,
});

assert(errWithCause instanceof Error, 'VerificationError must be an instance of Error');
assert(
  errWithCause instanceof VerificationError,
  'VerificationError must be an instance of VerificationError'
);
assert.strictEqual(errWithCause.name, 'VerificationError');
assert.strictEqual(errWithCause.code, 'SIGNATURE_ERROR');
assert.strictEqual(errWithCause.message, 'signature verification failed');
assert.strictEqual(errWithCause.cause, rootCause);
assert.strictEqual(isVerificationError(errWithCause, 'SIGNATURE_ERROR'), true);
assert.strictEqual(isVerificationError(errWithCause, 'TIMESTAMP_ERROR'), false);

// 2. Construct VerificationError without cause across supported error codes
const codes = [
  'NOT_IMPLEMENTED_ERROR',
  'TLOG_INCLUSION_PROOF_ERROR',
  'TLOG_INCLUSION_PROMISE_ERROR',
  'TLOG_MISSING_INCLUSION_ERROR',
  'TLOG_BODY_ERROR',
  'CERTIFICATE_ERROR',
  'PUBLIC_KEY_ERROR',
  'SIGNATURE_ERROR',
  'TIMESTAMP_ERROR',
];

for (const code of codes) {
  const err = new VerificationError({
    code,
    message: `error for ${code}`,
  });
  assert.strictEqual(err.name, 'VerificationError');
  assert.strictEqual(err.code, code);
  assert.strictEqual(err.message, `error for ${code}`);
  assert.strictEqual(err.cause, undefined);
}

// 3. Verifier throws VerificationError with TIMESTAMP_ERROR when tlog count is below threshold
const { publicKey } = crypto.generateKeyPairSync('ec', { namedCurve: 'P-256' });
const trustMaterial = {
  certificateAuthorities: [],
  tlogs: [],
  ctlogs: [],
  timestampAuthorities: [],
  publicKey: () => ({
    key: publicKey,
    validFor: () => true,
  }),
};

const verifierDefault = new Verifier(trustMaterial, { tlogThreshold: 1 });
const entityWithoutTimestamps = {
  timestamps: [],
  key: { $case: 'public-key', hint: 'key-1' },
  tlogEntries: [],
  signature: {
    signature: Buffer.from('sig'),
    verifySignature: () => true,
  },
};

assert.throws(
  () => verifierDefault.verify(entityWithoutTimestamps),
  (err) => {
    assert(err instanceof VerificationError);
    assert.strictEqual(err.name, 'VerificationError');
    assert.strictEqual(err.code, 'TIMESTAMP_ERROR');
    assert.strictEqual(err.message, 'expected 1 tlog timestamps, got 0');
    return true;
  }
);

// 4. Verifier throws VerificationError with SIGNATURE_ERROR when signature verification fails
const verifierNoThresholds = new Verifier(trustMaterial, {
  tlogThreshold: 0,
  ctlogThreshold: 0,
  tsaThreshold: 0,
});
const entityBadSignature = {
  timestamps: [],
  key: { $case: 'public-key', hint: 'key-1' },
  tlogEntries: [],
  signature: {
    signature: Buffer.from('invalid-sig'),
    verifySignature: () => false,
  },
};

assert.throws(
  () => verifierNoThresholds.verify(entityBadSignature),
  (err) => {
    assert(err instanceof VerificationError);
    assert.strictEqual(err.name, 'VerificationError');
    assert.strictEqual(err.code, 'SIGNATURE_ERROR');
    assert.strictEqual(err.message, 'signature verification failed');
    return true;
  }
);

console.log('All contract assertions passed.');

原始种子者

匿名