CodeSampleX

Ejemplo

utf8-byte-length 1.0.5

Muestra verificada para npm utf8-byte-length 1.0.5. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: utf8ByteLength returns 0 bytes for…

sha256:a3c0b9fd983a7cacd0b53f4d15750d60fce79e3c4900b8fbb187aa9ed709adf8

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
2
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-26
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-07

Caso

HOW
Objetivo
verify pkg:npm/utf8-byte-length@1.0.5
Paquetes
Entorno
node 22.23.2
Creado
2026-08-26T07:57:51Z

Contrato

  1. utf8ByteLength returns 0 bytes for an empty string
  2. utf8ByteLength calculates 1 byte per ASCII character
  3. utf8ByteLength calculates 2 bytes per 2-byte UTF-8 character
  4. utf8ByteLength calculates 3 bytes per 3-byte UTF-8 character
  5. utf8ByteLength calculates 4 bytes per 4-byte UTF-8 character such as emojis
  6. utf8ByteLength calculates the exact total byte length for mixed multi-byte strings
  7. utf8ByteLength throws an Error when passed non-string inputs

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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/utf8-byte-length@1.0.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/utf8-byte-length@1.0.5

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:ca5410aa997c02bb32ae7fa6bddb355d94443017d1362653f0ddb506cb7832e6","constraints":{"executionContext":"node"},"contract":["utf8ByteLength returns 0 bytes for an empty string","utf8ByteLength calculates 1 byte per ASCII character","utf8ByteLength calculates 2 bytes per 2-byte UTF-8 character","utf8ByteLength calculates 3 bytes per 3-byte UTF-8 character","utf8ByteLength calculates 4 bytes per 4-byte UTF-8 character such as emojis","utf8ByteLength calculates the exact total byte length for mixed multi-byte strings","utf8ByteLength throws an Error when passed non-string inputs"],"goal":"verify pkg:npm/utf8-byte-length@1.0.5","kind":"HOW","packages":["pkg:npm/utf8-byte-length@1.0.5"],"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/utf8-byte-length@1.0.5"],"schemaVersion":1,"subject":"pkg:npm/utf8-byte-length@1.0.5","verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const utf8ByteLength = require('utf8-byte-length');

function calculatePayloadSize(text) {
  return utf8ByteLength(text);
}

module.exports = {
  calculatePayloadSize,
};
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "utf8-byte-length": "1.0.5"
      }
    },
    "node_modules/utf8-byte-length": {
      "version": "1.0.5",
      "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.5.tgz",
      "integrity": "sha512-Xn0w3MtiQ6zoz2vFyUVruaCL53O/DwUvkEeOvj+uulMm0BkUGYWmBYVyElqZaSLhY6ZD0ulfU3aBra2aVT4xfA==",
      "license": "(WTFPL OR MIT)"
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of utf8-byte-length",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "utf8-byte-length": "1.0.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/utf8-byte-length@1.0.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/utf8-byte-length@1.0.5"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import utf8ByteLength from 'utf8-byte-length';
import { calculatePayloadSize } from '../index.js';

// 1. utf8ByteLength returns 0 bytes for an empty string
assert.equal(utf8ByteLength(''), 0);
assert.equal(calculatePayloadSize(''), 0);

// 2. utf8ByteLength calculates 1 byte per ASCII character
assert.equal(utf8ByteLength('a'), 1);
assert.equal(utf8ByteLength('hello world'), 11);
assert.equal(calculatePayloadSize('12345'), 5);

// 3. utf8ByteLength calculates 2 bytes per 2-byte UTF-8 character
assert.equal(utf8ByteLength('é'), 2);
assert.equal(utf8ByteLength('ñ'), 2);
assert.equal(utf8ByteLength('α'), 2);
assert.equal(utf8ByteLength('д'), 2);

// 4. utf8ByteLength calculates 3 bytes per 3-byte UTF-8 character
assert.equal(utf8ByteLength('한'), 3);
assert.equal(utf8ByteLength('글'), 3);
assert.equal(utf8ByteLength('日'), 3);
assert.equal(utf8ByteLength('本'), 3);
assert.equal(utf8ByteLength('語'), 3);
assert.equal(utf8ByteLength('€'), 3);

// 5. utf8ByteLength calculates 4 bytes per 4-byte UTF-8 character such as emojis
assert.equal(utf8ByteLength('🚀'), 4);
assert.equal(utf8ByteLength('🎉'), 4);
assert.equal(utf8ByteLength('👍'), 4);

// 6. utf8ByteLength calculates the exact total byte length for mixed multi-byte strings
assert.equal(utf8ByteLength('Hello, 世界! 🚀'), 19);
assert.equal(calculatePayloadSize('Hello, 世界! 🚀'), 19);

// 7. utf8ByteLength throws an Error when passed non-string inputs
assert.throws(() => utf8ByteLength(null), {
  name: 'Error',
  message: 'Input must be string',
});
assert.throws(() => utf8ByteLength(undefined), {
  name: 'Error',
  message: 'Input must be string',
});
assert.throws(() => utf8ByteLength(12345), {
  name: 'Error',
  message: 'Input must be string',
});
assert.throws(() => utf8ByteLength({}), {
  name: 'Error',
  message: 'Input must be string',
});
assert.throws(() => utf8ByteLength(true), {
  name: 'Error',
  message: 'Input must be string',
});

console.log('All contract assertions passed.');

Seeder de origen

anónimo