示例
bare-hrtime 2.1.1: hrtime, hrtime.bigint
已验证示例 — npm bare-hrtime 2.1.1: hrtime, hrtime.bigint. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: package manifest specifies Bare addon…
sha256:a291e096b3782d3028b6e755dbb63774b53e57cba58f94a9d4a6159e8a9d07e8
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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 alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-27 |
案例
HOW- 目标
- verify pkg:npm/bare-hrtime@2.1.1
- 符号
-
- hrtime
- hrtime.bigint
- 环境
- node 22.23.2
- 创建时间
- 2026-08-27T14:19:47Z
契约
- package manifest specifies Bare addon configuration and exports for root and package subpaths
- declares high-resolution timer functions hrtime and hrtime.bigint in index.d.ts
- implements nanosecond to second/nanosecond tuple conversion and past timestamp differential calculation
- ships native Bare C addon binding with uv_hrtime and multi-platform prebuild artifacts
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
源代码
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/bare-hrtime@2.1.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/bare-hrtime@2.1.1
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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.
{"case":{"caseId":"case:sha256:df7d8b1a0d94523e1a670ff31b6d329beab9d4cf140ba15743559813f9d3b913","constraints":{"executionContext":"node"},"contract":["package manifest specifies Bare addon configuration and exports for root and package subpaths","declares high-resolution timer functions hrtime and hrtime.bigint in index.d.ts","implements nanosecond to second/nanosecond tuple conversion and past timestamp differential calculation","ships native Bare C addon binding with uv_hrtime and multi-platform prebuild artifacts"],"goal":"verify pkg:npm/bare-hrtime@2.1.1","kind":"HOW","packages":["pkg:npm/bare-hrtime@2.1.1"],"schemaVersion":1,"symbols":["hrtime","hrtime.bigint"]},"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/bare-hrtime@2.1.1"],"schemaVersion":1,"subject":"pkg:npm/bare-hrtime@2.1.1","symbols":["hrtime","hrtime.bigint"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-bare-hrtime",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-bare-hrtime",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"bare-hrtime": "2.1.1"
}
},
"node_modules/bare-hrtime": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/bare-hrtime/-/bare-hrtime-2.1.1.tgz",
"integrity": "sha512-VMb3tHo05gsnbu3OXTmkDiwTjMlOsbQmKoysKqKEyR09m77TuDrYFbj3Q5GGk10dAKsUHrnXmwCaeJqzVpB5ZA==",
"license": "Apache-2.0"
}
}
}
{
"name": "sample-bare-hrtime",
"version": "1.0.0",
"private": true,
"license": "MIT-0",
"dependencies": {
"bare-hrtime": "2.1.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/bare-hrtime@2.1.1",
"kind": "HOW",
"packages": [
"pkg:npm/bare-hrtime@2.1.1"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from "node:assert/strict";
import { createRequire } from "node:module";
import fs from "node:fs";
import path from "node:path";
const require = createRequire(import.meta.url);
// 1. Resolve bare-hrtime package manifest and verify exports and metadata
const pkgPath = require.resolve("bare-hrtime/package");
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
assert.equal(pkg.name, "bare-hrtime", "Package name must be bare-hrtime");
assert.equal(pkg.version, "2.1.1", "Package version must be 2.1.1");
assert.equal(pkg.description, "High-resolution timers for JavaScript", "Description must match");
assert.equal(pkg.license, "Apache-2.0", "Package license must be Apache-2.0");
assert.equal(pkg.addon, true, "Package must be marked as addon");
assert.ok(pkg.exports, "Package must define exports");
assert.equal(pkg.exports["."].types, "./index.d.ts", "Root export must have index.d.ts types");
assert.equal(pkg.exports["."].default, "./index.js", "Root export must have index.js default");
assert.equal(pkg.exports["./package"], "./package.json", "Package export must point to package.json");
const pkgDir = path.dirname(pkgPath);
const indexDts = fs.readFileSync(path.join(pkgDir, "index.d.ts"), "utf8");
const indexJs = fs.readFileSync(path.join(pkgDir, "index.js"), "utf8");
const bindingJs = fs.readFileSync(path.join(pkgDir, "binding.js"), "utf8");
const bindingC = fs.readFileSync(path.join(pkgDir, "binding.c"), "utf8");
// 2. Verify TypeScript declarations (index.d.ts) for hrtime and hrtime.bigint
assert.ok(indexDts.includes("declare function hrtime("), "index.d.ts must declare hrtime function");
assert.ok(indexDts.includes("prev?: ArrayLike<number>"), "index.d.ts must accept optional prev parameter");
assert.ok(indexDts.includes("[seconds: number, nanoseconds: number]"), "index.d.ts must return [seconds, nanoseconds] tuple");
assert.ok(indexDts.includes("declare namespace hrtime"), "index.d.ts must declare hrtime namespace");
assert.ok(indexDts.includes("export function bigint(): bigint"), "index.d.ts must declare hrtime.bigint returning bigint");
assert.ok(indexDts.includes("export = hrtime"), "index.d.ts must export hrtime");
// 3. Verify JavaScript wrapper implementation & timing arithmetic contract
assert.ok(indexJs.includes("const binding = require('./binding')"), "index.js must require binding");
assert.ok(indexJs.includes("module.exports = exports = function hrtime(past)"), "index.js must define hrtime(past)");
assert.ok(indexJs.includes("exports.bigint = function hrtime()"), "index.js must define exports.bigint");
// Test the high-resolution timing arithmetic behavior as implemented in index.js
function simulateHrtime(nowBigInt, past) {
let now = nowBigInt;
if (past) now -= BigInt(past[0]) * 1000000000n + BigInt(past[1]);
return [Number(now / 1000000000n), Number(now % 1000000000n)];
}
// Case A: Base timestamp conversion from nanoseconds to [seconds, nanoseconds]
const t0 = 123456789012345678n; // 123456789 seconds, 12345678 nanoseconds
const tuple0 = simulateHrtime(t0);
assert.equal(tuple0[0], 123456789, "Seconds part must match");
assert.equal(tuple0[1], 12345678, "Nanoseconds part must match");
// Case B: Differential timing (past timestamp diff)
// Elapsed: 2 seconds and 500,000,000 nanoseconds
const pastTimestamp = [123456787, 12345678];
const diff = simulateHrtime(t0, pastTimestamp);
assert.equal(diff[0], 2, "Diff seconds part must be 2");
assert.equal(diff[1], 0, "Diff nanoseconds part must be 0");
// Case C: Sub-second elapsed delta with nanosecond rollover
const t1 = 1000000000n; // 1s 0ns
const pastSubSecond = [0, 500000000]; // 0s 500000000ns
const diffSubSecond = simulateHrtime(t1, pastSubSecond);
assert.equal(diffSubSecond[0], 0, "Elapsed seconds should be 0");
assert.equal(diffSubSecond[1], 500000000, "Elapsed nanoseconds should be 500000000");
// 4. Verify C native addon binding and multi-platform prebuilt binaries
assert.ok(bindingC.includes("BARE_MODULE(bare_hrtime, bare_hrtime_exports)"), "binding.c must register bare_hrtime BARE_MODULE");
assert.ok(bindingC.includes("uv_hrtime()"), "binding.c must invoke uv_hrtime() for high-resolution timestamps");
assert.ok(bindingC.includes("js_create_bigint_uint64"), "binding.c must return uint64 BigInt value");
assert.ok(bindingJs.includes("module.exports = require.addon()"), "binding.js must load native addon via require.addon()");
assert.ok(fs.existsSync(path.join(pkgDir, "CMakeLists.txt")), "CMakeLists.txt must exist");
// Verify prebuilt native binaries for supported platforms
const prebuildsDir = path.join(pkgDir, "prebuilds");
const expectedTargets = [
"linux-x64",
"linux-arm64",
"darwin-x64",
"darwin-arm64",
"win32-x64",
"win32-arm64",
"android-arm64",
"ios-arm64"
];
for (const target of expectedTargets) {
const prebuildPath = path.join(prebuildsDir, target, "bare-hrtime.bare");
assert.ok(fs.existsSync(prebuildPath), `Prebuild binary for ${target} must exist at ${prebuildPath}`);
const stats = fs.statSync(prebuildPath);
assert.ok(stats.size > 0, `Prebuild binary for ${target} must not be empty`);
}
console.log("Contract tests passed successfully.");
原始种子者
匿名