CodeSampleX

Exemple

@napi-rs/wasm-runtime 1.2.3

Échantillon vérifié pour npm @napi-rs/wasm-runtime 1.2.3. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:061fb307f8d82e515ded7aab39f4f60cacc50fae893c7ec65e2d1ae654bbf272

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:npm/%40napi-rs/wasm-runtime@1.2.3
Paquets
Environnement
node 22.23.2
Créé
2026-08-20T17:49:43Z

Contrat

  1. @napi-rs/wasm-runtime exports createContext, getDefaultContext, emnapiAsyncWorkPlugin, emnapiTSFNPlugin, instantiateNapiModule, instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy, and createOnMessage
  2. getDefaultContext returns the default emnapi Context instance with active handle and scope stores
  3. createContext creates an independent emnapi Context instance
  4. WASI can be instantiated with custom args and environment variables
  5. MessageHandler can be instantiated with onLoad and postMessage handlers
  6. @napi-rs/wasm-runtime/fs exports memfs, Volume, fs, and createFsFromVolume
  7. createOnMessage processes readFileSync requests over SharedArrayBuffer messaging protocol
  8. createOnMessage handles errors and reports status 1 with serialized error payload over SharedArrayBuffer

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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/%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.
csx.json
{"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"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "name": "sample-napi-rs-wasm-runtime",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@napi-rs/wasm-runtime": "1.2.3"
  }
}
spec.json
{
  "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"
  }
}
test/contract.mjs
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.');

Seeder d'origine

anonyme