Sample
node-addon-api 7.1.1: Napi::Function, Napi::Number, Napi::Object
Verified sample for npm node-addon-api 7.1.1: Napi::Function, Napi::Number, Napi::Object. The contract ran on node 22 · linux alpine/x64 · docker and passed.
sha256:eefb6e92365d6aea6b771004fe25ff4bb21274caf48bec93d3c4ff2e3f5f05b6
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 1
- Signing keys that built it
- 1
Declared environment
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| 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-28 |
Case
HOW- Goal
- verify pkg:npm/node-addon-api@7.1.1
- Packages
- Symbols
-
- Napi::Function
- Napi::Number
- Napi::Object
- Napi::String
- Environment
- node 22.23.2
- Created
- 2026-08-28T08:06:13Z
Contract
- include directory exposes napi.h with C++ headers for Node-API addons
- napi.h declares Napi::String class inheriting from Name with New constructor and Utf8Value conversion
- napi.h declares Napi::Number class inheriting from Value with New constructor and DoubleValue/Int32Value conversion
- napi.h declares Napi::Object class inheriting from TypeTaggable with New constructor and Set/Get property methods
- napi.h declares Napi::Function class inheriting from Object with New constructor and Call method
- node-addon-api exports gyp path and targets file for build integration
Files
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Source
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/node-addon-api@7.1.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/node-addon-api@7.1.1
Demonstrate these symbols/APIs:
- Napi::Function
- Napi::Number
- Napi::Object
- Napi::String
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:c3d112170eaebb22aac0d99424693da8b1c29aeb6ac42b8dd8fee22eae4a3277","contract":["include directory exposes napi.h with C++ headers for Node-API addons","napi.h declares Napi::String class inheriting from Name with New constructor and Utf8Value conversion","napi.h declares Napi::Number class inheriting from Value with New constructor and DoubleValue/Int32Value conversion","napi.h declares Napi::Object class inheriting from TypeTaggable with New constructor and Set/Get property methods","napi.h declares Napi::Function class inheriting from Object with New constructor and Call method","node-addon-api exports gyp path and targets file for build integration"],"goal":"verify pkg:npm/node-addon-api@7.1.1","kind":"HOW","packages":["pkg:npm/node-addon-api@7.1.1"],"schemaVersion":1,"symbols":["Napi::Function","Napi::Number","Napi::Object","Napi::String"]},"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/node-addon-api@7.1.1"],"schemaVersion":1,"subject":"pkg:npm/node-addon-api@7.1.1","symbols":["Napi::Function","Napi::Number","Napi::Object","Napi::String"],"verifierAdapter":"node-typescript@1"}
{
"name": "csx-sample-node-addon-api",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "csx-sample-node-addon-api",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"node-addon-api": "7.1.1"
}
},
"node_modules/node-addon-api": {
"version": "7.1.1",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz",
"integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==",
"license": "MIT"
}
}
}
{
"name": "csx-sample-node-addon-api",
"version": "1.0.0",
"private": true,
"type": "module",
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"node-addon-api": "7.1.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/node-addon-api@7.1.1",
"kind": "HOW",
"packages": [
"pkg:npm/node-addon-api@7.1.1"
],
"symbols": [
"Napi::Function",
"Napi::Number",
"Napi::Object",
"Napi::String"
]
}
import fs from 'node:fs';
import path from 'node:path';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const nodeAddonApi = require('node-addon-api');
/**
* Returns the resolved include directory path for node-addon-api headers.
* @returns {string} Path to headers.
*/
export function getIncludeDir() {
const inc = nodeAddonApi.include;
return inc ? inc.replace(/^"|"$/g, '') : '';
}
/**
* Reads header file content from the include directory.
* @param {string} headerName - e.g. 'napi.h' or 'napi-inl.h'
* @returns {string} Header file content.
*/
export function readHeader(headerName) {
const dir = getIncludeDir();
const filePath = path.join(dir, headerName);
return fs.readFileSync(filePath, 'utf8');
}
/**
* Verifies that the C++ header exports core Node-API symbol class definitions and methods.
* @returns {object} Map of verified symbol classes and their presence.
*/
export function verifyCoreSymbols() {
const headerContent = readHeader('napi.h');
return {
hasString: /class String\s*:\s*public Name/.test(headerContent) &&
/static String New\(napi_env env/.test(headerContent) &&
/Utf8Value\(\)/.test(headerContent),
hasNumber: /class Number\s*:\s*public Value/.test(headerContent) &&
/static Number New\(napi_env env/.test(headerContent) &&
/DoubleValue\(\)/.test(headerContent),
hasObject: /class Object\s*:\s*public TypeTaggable/.test(headerContent) &&
/static Object New\(napi_env env/.test(headerContent) &&
headerContent.includes('Set(napi_value key') &&
headerContent.includes('Get(napi_value key'),
hasFunction: /class Function\s*:\s*public Object/.test(headerContent) &&
/static Function New\(napi_env env/.test(headerContent) &&
headerContent.includes('Call(const std::initializer_list<napi_value>& args)'),
};
}
/**
* Returns package configuration flags and paths.
* @returns {object}
*/
export function getAddonConfig() {
return {
include: nodeAddonApi.include,
include_dir: nodeAddonApi.include_dir,
gyp: nodeAddonApi.gyp,
targets: nodeAddonApi.targets,
isNodeApiBuiltin: nodeAddonApi.isNodeApiBuiltin,
needsFlag: nodeAddonApi.needsFlag,
};
}
export default {
getIncludeDir,
readHeader,
verifyCoreSymbols,
getAddonConfig,
};
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { getIncludeDir, readHeader, verifyCoreSymbols, getAddonConfig } from '../src/index.js';
// 1. Verify include directory and header files
const includeDir = getIncludeDir();
assert.ok(includeDir && typeof includeDir === 'string', 'Include directory should be a non-empty string');
assert.ok(fs.existsSync(includeDir), 'Include directory should exist on disk');
const napiHeader = readHeader('napi.h');
assert.ok(napiHeader.length > 0, 'napi.h header should not be empty');
// 2. Napi::String verification in header
assert.ok(/class String\s*:\s*public Name/.test(napiHeader), 'napi.h must define Napi::String class');
assert.ok(/static String New\(napi_env env/.test(napiHeader), 'napi.h must declare Napi::String::New');
assert.ok(/Utf8Value\(\)/.test(napiHeader), 'napi.h must declare Utf8Value method');
// 3. Napi::Number verification in header
assert.ok(/class Number\s*:\s*public Value/.test(napiHeader), 'napi.h must define Napi::Number class');
assert.ok(/static Number New\(napi_env env/.test(napiHeader), 'napi.h must declare Napi::Number::New');
assert.ok(/DoubleValue\(\)/.test(napiHeader), 'napi.h must declare DoubleValue method');
assert.ok(/Int32Value\(\)/.test(napiHeader), 'napi.h must declare Int32Value method');
// 4. Napi::Object verification in header
assert.ok(/class Object\s*:\s*public TypeTaggable/.test(napiHeader), 'napi.h must define Napi::Object class');
assert.ok(/static Object New\(napi_env env/.test(napiHeader), 'napi.h must declare Napi::Object::New');
assert.ok(napiHeader.includes('Set(napi_value key'), 'napi.h must declare Set method on Object');
assert.ok(napiHeader.includes('Get(napi_value key'), 'napi.h must declare Get method on Object');
// 5. Napi::Function verification in header
assert.ok(/class Function\s*:\s*public Object/.test(napiHeader), 'napi.h must define Napi::Function class');
assert.ok(/static Function New\(napi_env env/.test(napiHeader), 'napi.h must declare Napi::Function::New');
assert.ok(napiHeader.includes('Call(const std::initializer_list<napi_value>& args)'), 'napi.h must declare Call method on Function');
// 6. Helper verification
const symbols = verifyCoreSymbols();
assert.deepStrictEqual(symbols, {
hasString: true,
hasNumber: true,
hasObject: true,
hasFunction: true,
});
// 7. Addon configuration and gyp integration exports
const config = getAddonConfig();
assert.ok(typeof config.include === 'string' && config.include.length > 0);
assert.ok(typeof config.include_dir === 'string' && config.include_dir.length > 0);
assert.ok(typeof config.gyp === 'string' && config.gyp.endsWith('nothing'));
assert.ok(typeof config.targets === 'string' && config.targets.endsWith('node_addon_api.gyp'));
assert.strictEqual(config.isNodeApiBuiltin, true);
assert.strictEqual(config.needsFlag, false);
console.log('All node-addon-api contract assertions passed successfully.');
Origin Seeder
anonymous