示例
@tybys/wasm-util 0.10.2: extendMemory
已验证示例 — npm @tybys/wasm-util 0.10.2: extendMemory. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: extendMemory upgrades a standard WebAssembly.Memory…
sha256:d2e9fb2a1859c7b769e056a2becdc208c3af149ecafc9787385a47a8ba3ea49e
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 2
- 构建过它的签名密钥
- 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 | SKIPPED | compile:SKIPPED · contract:SKIPPED · load:SKIPPED · resolve:FAIL CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-10-13 |
| 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-10-13 |
案例
HOW- 目标
- verify @tybys/wasm-util.extendMemory in pkg:npm/%40tybys/wasm-util@0.10.2
- 符号
-
- @tybys/wasm-util.extendMemory
- 环境
- node 22.23.2
- 创建时间
- 2026-10-13T05:06:31Z
契约
- extendMemory upgrades a standard WebAssembly.Memory instance to provide typed array getters
- extendMemory returns the exact same WebAssembly.Memory instance reference
- Typed array views and DataView reflect shared buffer byte mutations across representations
- extendMemory is idempotent when called multiple times on the same memory instance
- Typed array views remain accessible and dynamically re-reference the buffer after memory growth
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- 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 @tybys/wasm-util.extendMemory in pkg:npm/%40tybys/wasm-util@0.10.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40tybys/wasm-util@0.10.2
Demonstrate these symbols/APIs:
- @tybys/wasm-util.extendMemory
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:e2a742622b6529577067a69ea727e44488bfa6bc090197c5ebac461277ac138e","contract":["extendMemory upgrades a standard WebAssembly.Memory instance to provide typed array getters","extendMemory returns the exact same WebAssembly.Memory instance reference","Typed array views and DataView reflect shared buffer byte mutations across representations","extendMemory is idempotent when called multiple times on the same memory instance","Typed array views remain accessible and dynamically re-reference the buffer after memory growth"],"goal":"verify @tybys/wasm-util.extendMemory in pkg:npm/%40tybys/wasm-util@0.10.2","kind":"HOW","packages":["pkg:npm/%40tybys/wasm-util@0.10.2"],"schemaVersion":1,"symbols":["@tybys/wasm-util.extendMemory"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40tybys/wasm-util@0.10.2"],"schemaVersion":1,"subject":"pkg:npm/%40tybys/wasm-util@0.10.2","symbols":["@tybys/wasm-util.extendMemory"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-tybys-wasm-util",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-tybys-wasm-util",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@tybys/wasm-util": "0.10.2"
}
},
"node_modules/@tybys/wasm-util": {
"version": "0.10.2",
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.2.tgz",
"integrity": "sha512-RoBvJ2X0wuKlWFIjrwffGw1IqZHKQqzIchKaadZZfnNpsAYp2mM0h36JtPCjNDAHGgYez/15uMBpfGwchhiMgg==",
"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-tybys-wasm-util",
"version": "1.0.0",
"type": "module",
"private": true,
"description": "verify @tybys/wasm-util.extendMemory in pkg:npm/@tybys/wasm-util@0.10.2",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@tybys/wasm-util": "0.10.2"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify @tybys/wasm-util.extendMemory in pkg:npm/%40tybys/wasm-util@0.10.2",
"kind": "HOW",
"packages": [
"pkg:npm/%40tybys/wasm-util@0.10.2"
],
"symbols": [
"@tybys/wasm-util.extendMemory"
]
}
import { extendMemory, Memory } from '@tybys/wasm-util';
export function wrapMemory(wasmMemory) {
return extendMemory(wasmMemory);
}
export function createAndExtendMemory(descriptor = { initial: 1 }) {
const mem = new WebAssembly.Memory(descriptor);
return extendMemory(mem);
}
export function writeUint32(memory, offset, value, littleEndian = true) {
memory.view.setUint32(offset, value, littleEndian);
}
export function readUint32(memory, offset, littleEndian = true) {
return memory.view.getUint32(offset, littleEndian);
}
export { extendMemory, Memory };
import assert from 'node:assert';
import {
extendMemory,
Memory,
wrapMemory,
createAndExtendMemory,
writeUint32,
readUint32
} from '../src/index.mjs';
// 1. extendMemory upgrades a standard WebAssembly.Memory instance to provide typed array getters
const rawMem = new WebAssembly.Memory({ initial: 1 });
assert(!(rawMem instanceof Memory), 'Standard WebAssembly.Memory should not be Memory instance prior to extension');
const extended = extendMemory(rawMem);
assert.strictEqual(extended, rawMem, 'extendMemory returns the exact same WebAssembly.Memory instance reference');
assert(extended instanceof Memory, 'extended memory inherits from Memory');
assert(extended.HEAP8 instanceof Int8Array, 'HEAP8 is an Int8Array view');
assert(extended.HEAPU8 instanceof Uint8Array, 'HEAPU8 is a Uint8Array view');
assert(extended.HEAP16 instanceof Int16Array, 'HEAP16 is an Int16Array view');
assert(extended.HEAPU16 instanceof Uint16Array, 'HEAPU16 is a Uint16Array view');
assert(extended.HEAP32 instanceof Int32Array, 'HEAP32 is an Int32Array view');
assert(extended.HEAPU32 instanceof Uint32Array, 'HEAPU32 is a Uint32Array view');
assert(extended.HEAPF32 instanceof Float32Array, 'HEAPF32 is a Float32Array view');
assert(extended.HEAPF64 instanceof Float64Array, 'HEAPF64 is a Float64Array view');
assert(extended.view instanceof DataView, 'view is a DataView instance');
// 2. extendMemory returns the exact same WebAssembly.Memory instance reference
const mem2 = new WebAssembly.Memory({ initial: 1 });
const wrapped = wrapMemory(mem2);
assert.strictEqual(wrapped, mem2, 'wrapMemory returns the same object reference');
// 3. Typed array views and DataView reflect shared buffer byte mutations across representations
extended.HEAPU8[0] = 0xef;
extended.HEAPU8[1] = 0xbe;
extended.HEAPU8[2] = 0xad;
extended.HEAPU8[3] = 0xde;
assert.strictEqual(extended.view.getUint32(0, true), 0xdeadbeef, 'DataView reflects byte mutations');
assert.strictEqual(extended.HEAP32[0], -559038737, 'HEAP32 reflects signed 32-bit integer');
writeUint32(extended, 4, 0x12345678, true);
assert.strictEqual(readUint32(extended, 4, true), 0x12345678, 'readUint32 retrieves written value');
// 4. extendMemory is idempotent when called multiple times on the same memory instance
const reExtended = extendMemory(extended);
assert.strictEqual(reExtended, extended, 'Calling extendMemory again returns the same instance');
assert(reExtended instanceof Memory, 'Re-extended memory remains an instance of Memory');
// 5. Typed array views remain accessible and dynamically re-reference the buffer after memory growth
const grown = createAndExtendMemory({ initial: 1, maximum: 2 });
assert.strictEqual(grown.buffer.byteLength, 65536, 'Initial buffer size is 65536');
assert.strictEqual(grown.grow(1), 1, 'grow should return previous page count');
assert.strictEqual(grown.buffer.byteLength, 131072, 'Buffer size after grow is 131072');
assert.strictEqual(grown.HEAPU8.length, 131072, 'HEAPU8 view dynamically resizes with the buffer');
console.log('Contract assertions passed.');
process.exit(0);
原始种子者
匿名