示例
@napi-rs/wasm-runtime 1.2.3
已验证示例 — npm @napi-rs/wasm-runtime 1.2.3. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: @napi-rs/wasm-runtime exports createContext…
sha256:061fb307f8d82e515ded7aab39f4f60cacc50fae893c7ec65e2d1ae654bbf272
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 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@1 |
2026-08-20 |
案例
HOW- 目标
- verify pkg:npm/%40napi-rs/wasm-runtime@1.2.3
- 环境
- node 22.23.2
- 创建时间
- 2026-08-20T17:49:43Z
契约
- @napi-rs/wasm-runtime exports createContext, getDefaultContext, emnapiAsyncWorkPlugin, emnapiTSFNPlugin, instantiateNapiModule, instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy, and createOnMessage
- getDefaultContext returns the default emnapi Context instance with active handle and scope stores
- createContext creates an independent emnapi Context instance
- WASI can be instantiated with custom args and environment variables
- MessageHandler can be instantiated with onLoad and postMessage handlers
- @napi-rs/wasm-runtime/fs exports memfs, Volume, fs, and createFsFromVolume
- createOnMessage processes readFileSync requests over SharedArrayBuffer messaging protocol
- createOnMessage handles errors and reports status 1 with serialized error payload over SharedArrayBuffer
文件
- 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/%40napi-rs/wasm-runtime@1.2.3
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40napi-rs/wasm-runtime@1.2.3
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- 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:ec67fb4317cac69ce78ecec03ba049a1c5cf88f5c45a550e63f79cb5f42f18d9","constraints":{"executionContext":"node"},"contract":["@napi-rs/wasm-runtime exports createContext, getDefaultContext, emnapiAsyncWorkPlugin, emnapiTSFNPlugin, instantiateNapiModule, instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy, and createOnMessage","getDefaultContext returns the default emnapi Context instance with active handle and scope stores","createContext creates an independent emnapi Context instance","WASI can be instantiated with custom args and environment variables","MessageHandler can be instantiated with onLoad and postMessage handlers","@napi-rs/wasm-runtime/fs exports memfs, Volume, fs, and createFsFromVolume","createOnMessage processes readFileSync requests over SharedArrayBuffer messaging protocol","createOnMessage handles errors and reports status 1 with serialized error payload over SharedArrayBuffer"],"goal":"verify pkg:npm/%40napi-rs/wasm-runtime@1.2.3","kind":"HOW","packages":["pkg:npm/%40napi-rs/wasm-runtime@1.2.3"],"schemaVersion":1},"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/%40napi-rs/wasm-runtime@1.2.3"],"schemaVersion":1,"subject":"pkg:npm/%40napi-rs/wasm-runtime@1.2.3","verifierAdapter":"node-typescript@1"}
{
"name": "sample-napi-rs-wasm-runtime",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-napi-rs-wasm-runtime",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@napi-rs/wasm-runtime": "1.2.3"
}
},
"node_modules/@emnapi/core": {
"version": "1.11.3",
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.11.3.tgz",
"integrity": "sha512-zLpS5asjEb7lq8jYLq37N6XKaE41DIexlY1rF/z4/tIl3wo13Sqm28fRyfIsKZD+NZ8mM5RoKkpW/rBcuoSZSg==",
"license": "MIT",
"peer": true,
"dependencies": {
"@emnapi/wasi-threads": "1.2.3",
"tslib": "^2.4.0"
}
},
"node_modules/@emnapi/runtime": {
"version": "1.11.3",
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.11.3.tgz",
"integrity": "sha512-Xz4Tpyki7XyrpbUK1jR1AhdAdaXyhhY4lZ3neLodmhpuWfy2PAQN5B46sAiU4liOXGLkHypn/qU+jvfWSCYYLA==",
"license": "MIT",
"peer": true,
"dependencies": {
"tslib": "^2.4.0"
}
},
"node_modules/@emnapi/wasi-threads": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.3.tgz",
"integrity": "sha512-ELEBe8PsLvvJ6QMr0zLt8ffvOHW/dc1m3CEzNMg7aJUv3bMaoDtw2TXyDAwkYBuroxxuHEwhRTLJSe5sya547g==",
"license": "MIT",
"peer": true,
"dependencies": {
"tslib": "^2.4.0"
}
},
"node_modules/@napi-rs/wasm-runtime": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.3.tgz",
"integrity": "sha512-UMduMbqO5s5zF2NkNacMT/yK5Y5QiKvWr2+50bzIIxFDwVJ2h49b+oyjaCGPhJxd2/gC2x39EHv/gHVuu36x2Q==",
"license": "MIT",
"dependencies": {
"@tybys/wasm-util": "^0.10.3"
},
"engines": {
"node": "^20.19.0 || ^22.13.0 || >=23.5.0"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/Brooooooklyn"
},
"peerDependencies": {
"@emnapi/core": "^1.7.1 || ^2.0.0-alpha.4",
"@emnapi/runtime": "^1.7.1 || ^2.0.0-alpha.4"
}
},
"node_modules/@tybys/wasm-util": {
"version": "0.10.3",
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.3.tgz",
"integrity": "sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg==",
"license": "MIT",
"dependencies": {
"tslib": "^2.4.0"
}
},
"node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
}
}
}
{
"name": "sample-napi-rs-wasm-runtime",
"version": "1.0.0",
"type": "module",
"license": "MIT-0",
"dependencies": {
"@napi-rs/wasm-runtime": "1.2.3"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40napi-rs/wasm-runtime@1.2.3",
"kind": "HOW",
"packages": [
"pkg:npm/%40napi-rs/wasm-runtime@1.2.3"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert/strict';
import {
createContext,
getDefaultContext,
emnapiAsyncWorkPlugin,
emnapiTSFNPlugin,
instantiateNapiModule,
instantiateNapiModuleSync,
MessageHandler,
WASI,
createFsProxy,
createOnMessage
} from '@napi-rs/wasm-runtime';
import { memfs, Volume, createFsFromVolume, fs as defaultFs } from '@napi-rs/wasm-runtime/fs';
// 1. Export verification
assert.equal(typeof createContext, 'function', 'createContext must be exported as a function');
assert.equal(typeof getDefaultContext, 'function', 'getDefaultContext must be exported as a function');
assert.equal(typeof emnapiAsyncWorkPlugin, 'function', 'emnapiAsyncWorkPlugin must be exported as a function');
assert.equal(typeof emnapiTSFNPlugin, 'function', 'emnapiTSFNPlugin must be exported as a function');
assert.equal(typeof instantiateNapiModule, 'function', 'instantiateNapiModule must be exported as a function');
assert.equal(typeof instantiateNapiModuleSync, 'function', 'instantiateNapiModuleSync must be exported as a function');
assert.equal(typeof MessageHandler, 'function', 'MessageHandler must be exported as a constructor/function');
assert.equal(typeof WASI, 'function', 'WASI must be exported as a constructor/function');
assert.equal(typeof createFsProxy, 'function', 'createFsProxy must be exported as a function');
assert.equal(typeof createOnMessage, 'function', 'createOnMessage must be exported as a function');
// 2. Default context
const defaultCtx = getDefaultContext();
assert.ok(defaultCtx && typeof defaultCtx === 'object', 'getDefaultContext must return a context object');
assert.ok(defaultCtx.scopeStore, 'default context must have a scopeStore');
assert.ok(defaultCtx.handleStore, 'default context must have a handleStore');
// 3. New context creation
const customCtx = createContext();
assert.ok(customCtx && typeof customCtx === 'object', 'createContext must create a context object');
assert.notEqual(customCtx, defaultCtx, 'createContext must create a distinct context instance');
// 4. WASI instantiation
const wasi = new WASI({
args: ['node', 'app.wasm'],
env: { NODE_ENV: 'test' }
});
assert.equal(typeof wasi.start, 'function', 'WASI instance must provide start method');
assert.equal(typeof wasi.initialize, 'function', 'WASI instance must provide initialize method');
// 5. MessageHandler instantiation
let messageReceived = false;
const handler = new MessageHandler({
onLoad: () => {},
postMessage: () => { messageReceived = true; }
});
assert.ok(handler && typeof handler === 'object', 'MessageHandler instance should be created');
// 6. FS subpath export verification
assert.equal(typeof memfs, 'function', 'memfs must be a function');
assert.equal(typeof Volume, 'function', 'Volume must be a constructor');
assert.equal(typeof createFsFromVolume, 'function', 'createFsFromVolume must be a function');
assert.ok(defaultFs && typeof defaultFs === 'object', 'fs must be a filesystem object');
// 7. createOnMessage with SharedArrayBuffer success
const { fs: inMemoryFs } = memfs({ '/sample.txt': 'napi-rs wasm runtime test' });
const onMsg = createOnMessage(inMemoryFs);
const sabSuccess = new SharedArrayBuffer(16 + 10240);
const i32Success = new Int32Array(sabSuccess);
Atomics.store(i32Success, 0, 21);
onMsg({
data: {
__fs__: {
sab: i32Success,
type: 'readFileSync',
payload: ['/sample.txt', 'utf8']
}
}
});
const statusSuccess = Atomics.load(i32Success, 0);
const typeSuccess = Atomics.load(i32Success, 1);
const sizeSuccess = Atomics.load(i32Success, 2);
const payloadSuccess = new Uint8Array(sabSuccess, 16, sizeSuccess);
const decodedText = new TextDecoder().decode(payloadSuccess);
assert.equal(statusSuccess, 0, 'Status must be 0 for successful filesystem execution');
assert.equal(typeSuccess, 4, 'Type 4 indicates string return value');
assert.equal(decodedText, 'napi-rs wasm runtime test', 'Decoded text must match written file content');
// 8. createOnMessage error handling over SharedArrayBuffer
const sabError = new SharedArrayBuffer(16 + 10240);
const i32Error = new Int32Array(sabError);
Atomics.store(i32Error, 0, 21);
onMsg({
data: {
__fs__: {
sab: i32Error,
type: 'readFileSync',
payload: ['/nonexistent.txt', 'utf8']
}
}
});
const statusError = Atomics.load(i32Error, 0);
assert.equal(statusError, 1, 'Status must be 1 for filesystem errors');
console.log('Contract tests passed successfully.');
原始种子者
匿名