CodeSampleX

示例

@img/sharp-webcontainers-wasm32 0.35.5

已验证示例 — npm @img/sharp-webcontainers-wasm32 0.35.5. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: Installing @img/sharp-webcontainers-wasm32@0.35.5…

sha256:f78f5514a2f981a97df96b59fffe5f177fc58104c3507632bbbb63a9c903e438

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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 debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-11-29

案例

HOW
目标
verify pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5
包
环境
node 22.23.2
创建时间
2026-11-29T03:40:30Z

契约

  1. Installing @img/sharp-webcontainers-wasm32@0.35.5 on linux/x64 requires force=true in .npmrc because package.json restricts cpu to wasm32
  2. Requiring @img/sharp-webcontainers-wasm32/sharp.node loads the WebAssembly libvips 8.18.7 addon with isWasm=true and isGlobal=false
  3. binding.format() reports png, jpeg, and webp codecs with buffer input and output enabled
  4. binding.cache(32, 12, 64) and binding.concurrency(1) update and return libvips runtime limits
  5. binding.metadata() decodes an offline 1x1 RGBA PNG returning format=png, mediaType=image/png, width=1, height=1, channels=4, hasAlpha=true, space=srgb
  6. binding.stats() returns isOpaque=false and exact 4-channel pixel statistics (255, 0, 128, 128) for the 1x1 RGBA PNG offline
  7. binding.metadata() passes an Error to its callback when given invalid image bytes
  8. Dynamic ESM import of @img/sharp-webcontainers-wasm32/sharp.node resolves to the same libvips 8.18.7 WASM addon
  9. Requiring @img/sharp-webcontainers-wasm32/package or @img/sharp-webcontainers-wasm32/versions throws ERR_PACKAGE_PATH_NOT_EXPORTED in 0.35.5 because @img/sharp-wasm32@0.35.5 omits *.json exports

文件

  • .npmrc
  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/binding.cjs
  • test/contract.cjs

下载源代码构件 (tar.gz)

源代码

.npmrc
force=true
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/%40img/sharp-webcontainers-wasm32@0.35.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - 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:0c398cac904079c573abf5d7f87acb79825ffb7ebbfded5be179f0534a93983d","constraints":{"executionContext":"node"},"contract":["Installing @img/sharp-webcontainers-wasm32@0.35.5 on linux/x64 requires force=true in .npmrc because package.json restricts cpu to wasm32","Requiring @img/sharp-webcontainers-wasm32/sharp.node loads the WebAssembly libvips 8.18.7 addon with isWasm=true and isGlobal=false","binding.format() reports png, jpeg, and webp codecs with buffer input and output enabled","binding.cache(32, 12, 64) and binding.concurrency(1) update and return libvips runtime limits","binding.metadata() decodes an offline 1x1 RGBA PNG returning format=png, mediaType=image/png, width=1, height=1, channels=4, hasAlpha=true, space=srgb","binding.stats() returns isOpaque=false and exact 4-channel pixel statistics (255, 0, 128, 128) for the 1x1 RGBA PNG offline","binding.metadata() passes an Error to its callback when given invalid image bytes","Dynamic ESM import of @img/sharp-webcontainers-wasm32/sharp.node resolves to the same libvips 8.18.7 WASM addon","Requiring @img/sharp-webcontainers-wasm32/package or @img/sharp-webcontainers-wasm32/versions throws ERR_PACKAGE_PATH_NOT_EXPORTED in 0.35.5 because @img/sharp-wasm32@0.35.5 omits *.json exports"],"goal":"verify pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5","kind":"HOW","packages":["pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"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/%40img/sharp-webcontainers-wasm32@0.35.5"],"schemaVersion":1,"subject":"pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sharp-webcontainers-wasm32-verify",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sharp-webcontainers-wasm32-verify",
      "version": "1.0.0",
      "dependencies": {
        "@img/sharp-webcontainers-wasm32": "0.35.5"
      }
    },
    "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",
      "dependencies": {
        "tslib": "^2.4.0"
      }
    },
    "node_modules/@img/sharp-wasm32": {
      "version": "0.35.5",
      "resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.35.5.tgz",
      "integrity": "sha512-Ptsga1su4tQx+LLF1ECS9U6nz5kmrXKo6XVbtR48Ke3ZRxxgaWBu7IDtEe1quo8hiupwm6WFqxVlXaSf7IINGQ==",
      "license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT",
      "dependencies": {
        "@emnapi/runtime": "^1.11.3"
      },
      "engines": {
        "node": ">=20.9.0"
      },
      "funding": {
        "url": "https://opencollective.com/libvips"
      }
    },
    "node_modules/@img/sharp-webcontainers-wasm32": {
      "version": "0.35.5",
      "resolved": "https://registry.npmjs.org/@img/sharp-webcontainers-wasm32/-/sharp-webcontainers-wasm32-0.35.5.tgz",
      "integrity": "sha512-hfhF/FmoQyTUkA0bIKFOtw536BQSeBMe6BF6QyWlrPxT754+TFLaZ7sKKTfvvM0yJgKgaYTwnFCIZ/GuDw5SUA==",
      "cpu": [
        "wasm32"
      ],
      "license": "Apache-2.0",
      "dependencies": {
        "@img/sharp-wasm32": "0.35.5"
      },
      "engines": {
        "node": ">=20.9.0"
      },
      "funding": {
        "url": "https://opencollective.com/libvips"
      }
    },
    "node_modules/tslib": {
      "version": "2.9.1",
      "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz",
      "integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==",
      "license": "0BSD"
    }
  }
}
package.json
{
  "name": "sharp-webcontainers-wasm32-verify",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of @img/sharp-webcontainers-wasm32@0.35.5 in Node.js",
  "main": "src/binding.cjs",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "@img/sharp-webcontainers-wasm32": "0.35.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40img/sharp-webcontainers-wasm32@0.35.5"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/binding.cjs
'use strict';

const binding = require('@img/sharp-webcontainers-wasm32/sharp.node');

function makeInputOptions(buffer) {
  return {
    input: {
      buffer,
      failOn: 'warning',
      limitInputPixels: 268402689,
      limitInputChannels: 0,
      unlimited: false,
      autoOrient: false,
      sequentialRead: false
    },
    debuglog: () => {}
  };
}

function queryRuntime() {
  return {
    version: binding.libvipsVersion(),
    formats: binding.format(),
    cache: binding.cache(),
    concurrency: binding.concurrency(),
    counters: binding.counters(),
    simd: binding.simd()
  };
}

function setLimits(memoryMb, maxFiles, maxItems, threads) {
  const cache = binding.cache(memoryMb, maxFiles, maxItems);
  const concurrency = binding.concurrency(threads);
  return { cache, concurrency };
}

function readMetadata(buffer) {
  return new Promise((resolve, reject) => {
    binding.metadata(makeInputOptions(buffer), (err, info) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(info);
    });
  });
}

function readStats(buffer) {
  return new Promise((resolve, reject) => {
    binding.stats(makeInputOptions(buffer), (err, info) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(info);
    });
  });
}

module.exports = {
  binding,
  queryRuntime,
  setLimits,
  readMetadata,
  readStats
};
test/contract.cjs
'use strict';

const assert = require('node:assert/strict');
const zlib = require('node:zlib');
const {
  binding,
  queryRuntime,
  setLimits,
  readMetadata,
  readStats
} = require('../src/binding.cjs');

function crc32(buf) {
  let crc = 0xffffffff;
  for (let i = 0; i < buf.length; i += 1) {
    crc ^= buf[i];
    for (let bit = 0; bit < 8; bit += 1) {
      crc = (crc & 1) ? (0xedb88320 ^ (crc >>> 1)) : (crc >>> 1);
    }
  }
  return (crc ^ 0xffffffff) >>> 0;
}

function pngChunk(type, data) {
  const typeBuf = Buffer.from(type, 'ascii');
  const lenBuf = Buffer.alloc(4);
  lenBuf.writeUInt32BE(data.length, 0);
  const crcBuf = Buffer.alloc(4);
  crcBuf.writeUInt32BE(crc32(Buffer.concat([typeBuf, data])), 0);
  return Buffer.concat([lenBuf, typeBuf, data, crcBuf]);
}

function buildRgba1x1Png(r, g, b, a) {
  const sig = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
  const ihdr = Buffer.alloc(13);
  ihdr.writeUInt32BE(1, 0);
  ihdr.writeUInt32BE(1, 4);
  ihdr[8] = 8; // bit depth
  ihdr[9] = 6; // color type RGBA
  ihdr[10] = 0; // compression
  ihdr[11] = 0; // filter
  ihdr[12] = 0; // interlace
  const rawScanline = Buffer.from([0, r, g, b, a]);
  const idat = zlib.deflateSync(rawScanline);
  return Buffer.concat([
    sig,
    pngChunk('IHDR', ihdr),
    pngChunk('IDAT', idat),
    pngChunk('IEND', Buffer.alloc(0))
  ]);
}

async function run() {
  // 1. CJS ./sharp.node loads libvips 8.18.7 WebAssembly binding
  const runtime = queryRuntime();
  assert.equal(runtime.version.isWasm, true);
  assert.equal(runtime.version.isGlobal, false);
  assert.equal(runtime.version.semver, '8.18.7');
  assert.equal(typeof runtime.simd, 'boolean');
  assert.equal(runtime.counters.queue, 0);
  assert.equal(runtime.counters.process, 0);

  // 2. Buffer codecs are available for png, jpeg, and webp
  for (const codec of ['png', 'jpeg', 'webp']) {
    assert.ok(runtime.formats[codec], `expected format entry for ${codec}`);
    assert.equal(runtime.formats[codec].input.buffer, true);
    assert.equal(runtime.formats[codec].output.buffer, true);
  }

  // 3. Cache and concurrency limits can be updated and read back
  const limits = setLimits(32, 12, 64, 1);
  assert.equal(limits.cache.memory.max, 32);
  assert.equal(limits.cache.files.max, 12);
  assert.equal(limits.cache.items.max, 64);
  assert.equal(limits.concurrency, 1);
  assert.equal(binding.concurrency(), 1);

  // 4. metadata() decodes a 1x1 RGBA PNG generated offline
  const samplePng = buildRgba1x1Png(255, 0, 128, 128);
  const meta = await readMetadata(samplePng);
  assert.equal(meta.format, 'png');
  assert.equal(meta.mediaType, 'image/png');
  assert.equal(meta.width, 1);
  assert.equal(meta.height, 1);
  assert.equal(meta.channels, 4);
  assert.equal(meta.hasAlpha, true);
  assert.equal(meta.space, 'srgb');

  // 5. stats() computes exact 4-channel statistics for the 1x1 RGBA PNG
  const stats = await readStats(samplePng);
  assert.equal(stats.isOpaque, false);
  assert.equal(stats.channels.length, 4);
  assert.equal(stats.channels[0].min, 255);
  assert.equal(stats.channels[1].min, 0);
  assert.equal(stats.channels[2].min, 128);
  assert.equal(stats.channels[3].min, 128);

  // 6. metadata() rejects invalid image bytes via its error callback
  await assert.rejects(
    () => readMetadata(Buffer.from('invalid-image-payload')),
    (err) => err instanceof Error && err.message.length > 0
  );

  // 7. Dynamic ESM import of ./sharp.node resolves to the same libvips 8.18.7 WASM addon
  const esmAddon = await import('@img/sharp-webcontainers-wasm32/sharp.node');
  assert.equal(esmAddon.default.libvipsVersion().semver, '8.18.7');
  assert.equal(esmAddon.default.libvipsVersion().isWasm, true);

  // 8. ./package and ./versions subpaths fail in 0.35.5 because @img/sharp-wasm32@0.35.5 omits *.json exports
  for (const subpath of ['package', 'versions']) {
    assert.throws(
      () => require(`@img/sharp-webcontainers-wasm32/${subpath}`),
      (err) => err && err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'
    );
  }

  console.log('contract ok');
}

run().catch((err) => {
  console.error(err);
  process.exit(1);
});

原始种子者

匿名