CodeSampleX

샘플

@napi-rs/wasm-runtime 1.1.4

검증된 샘플 — npm @napi-rs/wasm-runtime 1.1.4. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: @napi-rs/wasm-runtime exports getDefaultContext…

sha256:ab2c90f1828fbdb6d06246c9788f4c5a0f9db26d9e343a5525acc0549f0a862b

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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-09-19

케이스

HOW
목표
verify pkg:npm/%40napi-rs/wasm-runtime@1.1.4
패키지
환경
node 22.23.2
생성일
2026-09-18T20:38:58Z

컨트랙트

  1. @napi-rs/wasm-runtime exports getDefaultContext, instantiateNapiModule, instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy, createOnMessage, Asyncify, and Memory
  2. getDefaultContext returns the default emnapi Context instance with active handle and scope stores
  3. WASI can be instantiated with custom args and environment variables
  4. MessageHandler can be instantiated with onLoad and postMessage handlers
  5. @napi-rs/wasm-runtime/fs exports memfs, Volume, fs, and createFsFromVolume
  6. createOnMessage processes readFileSync requests over SharedArrayBuffer messaging protocol
  7. 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

소스 아티팩트 내려받기 (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 pkg:npm/%40napi-rs/wasm-runtime@1.1.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40napi-rs/wasm-runtime@1.1.4

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:8a73fb8afa37b45e7171edca5179e024445e8efd9e701faa8cf75a3378d5ab5b","constraints":{"executionContext":"node"},"contract":["@napi-rs/wasm-runtime exports getDefaultContext, instantiateNapiModule, instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy, createOnMessage, Asyncify, and Memory","getDefaultContext returns the default emnapi Context instance with active handle and scope stores","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.1.4","kind":"HOW","packages":["pkg:npm/%40napi-rs/wasm-runtime@1.1.4"],"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.1.4"],"schemaVersion":1,"subject":"pkg:npm/%40napi-rs/wasm-runtime@1.1.4","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.1.4"
      }
    },
    "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.1.4",
      "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.4.tgz",
      "integrity": "sha512-3NQNNgA1YSlJb/kMH1ildASP9HW7/7kYnRI2szWJaofaS1hWmbGI4H+d3+22aGzXXN9IJ+n+GiFVcGipJP18ow==",
      "license": "MIT",
      "dependencies": {
        "@tybys/wasm-util": "^0.10.1"
      },
      "funding": {
        "type": "github",
        "url": "https://github.com/sponsors/Brooooooklyn"
      },
      "peerDependencies": {
        "@emnapi/core": "^1.7.1",
        "@emnapi/runtime": "^1.7.1"
      }
    },
    "node_modules/@tybys/wasm-util": {
      "version": "0.10.4",
      "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.4.tgz",
      "integrity": "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==",
      "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.1.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40napi-rs/wasm-runtime@1.1.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40napi-rs/wasm-runtime@1.1.4"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  getDefaultContext,
  instantiateNapiModule,
  instantiateNapiModuleSync,
  MessageHandler,
  WASI,
  createFsProxy,
  createOnMessage,
  Asyncify,
  Memory
} from '@napi-rs/wasm-runtime';
import { memfs, Volume, createFsFromVolume, fs as defaultFs } from '@napi-rs/wasm-runtime/fs';

// 1. Export verification
assert.equal(typeof getDefaultContext, 'function', 'getDefaultContext 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');
assert.equal(typeof Asyncify, 'function', 'Asyncify must be exported as a constructor/function');
assert.equal(typeof Memory, 'function', 'Memory must be exported as a constructor/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. 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');

// 4. MessageHandler instantiation
let messageReceived = false;
const handler = new MessageHandler({
  onLoad: () => {},
  postMessage: () => { messageReceived = true; }
});
assert.ok(handler && typeof handler === 'object', 'MessageHandler instance should be created');

// 5. 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');

// 6. 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');

// 7. 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.');

오리진 시더

익명