Ejemplo
sqids 0.3.0: encode
Muestra verificada para npm sqids 0.3.0: encode. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó: assert sqids.encode encodes array of…
sha256:9288fcf5ed7a48059a1bdf7302a7475c66f67fb74cc9b8bddd5067538644a0bf
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
- 1
- 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 debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-11 |
Caso
HOW- Objetivo
- verify encode in pkg:npm/sqids@0.3.0
- Paquetes
- Símbolos
-
- encode
- Entorno
- node 22.23.2
- Creado
- 2026-09-11T23:07:04Z
Contrato
- assert sqids.encode encodes array of numbers into a unique string ID
- assert sqids.encode produces distinct string IDs for different number arrays
- assert sqids.encode encodes empty array to empty string
- assert sqids.encode satisfies minimum length when minLength option is configured
- assert sqids.encode restricts output characters to provided custom alphabet
- assert sqids.encode throws error when negative numbers are provided
Archivos
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código fuente
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 encode in pkg:npm/sqids@0.3.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/sqids@0.3.0
Demonstrate these symbols/APIs:
- encode
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:0488ea56fa111e66247cf05cb5d9b8a9c0a9b781b1a6236fa2ce0389d8535a4b","contract":["assert sqids.encode encodes array of numbers into a unique string ID","assert sqids.encode produces distinct string IDs for different number arrays","assert sqids.encode encodes empty array to empty string","assert sqids.encode satisfies minimum length when minLength option is configured","assert sqids.encode restricts output characters to provided custom alphabet","assert sqids.encode throws error when negative numbers are provided"],"goal":"verify encode in pkg:npm/sqids@0.3.0","kind":"HOW","packages":["pkg:npm/sqids@0.3.0"],"schemaVersion":1,"symbols":["encode"]},"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/sqids@0.3.0"],"schemaVersion":1,"subject":"pkg:npm/sqids@0.3.0","symbols":["encode"],"verifierAdapter":"node-typescript@1"}
const sqidsModule = require('sqids');
const Sqids = sqidsModule.default || sqidsModule;
/**
* Encodes an array of numbers into a unique string ID using Sqids.
*
* @param {number[]} numbers - Array of non-negative integers to encode.
* @param {Object} [options] - Optional Sqids configuration options.
* @returns {string} The encoded string ID.
*/
function encodeNumbers(numbers, options) {
const instance = options ? new Sqids(options) : new Sqids();
return instance.encode(numbers);
}
module.exports = {
encodeNumbers,
Sqids,
};
{
"name": "sample-sqids-encode",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-sqids-encode",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"sqids": "0.3.0"
}
},
"node_modules/sqids": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/sqids/-/sqids-0.3.0.tgz",
"integrity": "sha512-lOQK1ucVg+W6n3FhRwwSeUijxe93b51Bfz5PMRMihVf1iVkl82ePQG7V5vwrhzB11v0NtsR25PSZRGiSomJaJw==",
"license": "MIT"
}
}
}
{
"name": "sample-sqids-encode",
"version": "1.0.0",
"description": "Clean-room sample verifying encode in pkg:npm/sqids@0.3.0",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"sqids": "0.3.0"
}
}
{
"schemaVersion": 1,
"goal": "verify encode in pkg:npm/sqids@0.3.0",
"kind": "HOW",
"packages": [
"pkg:npm/sqids@0.3.0"
],
"symbols": [
"encode"
]
}
import assert from 'node:assert';
import Sqids from 'sqids';
import { encodeNumbers } from '../index.js';
// 1. Basic encoding: encodes array of numbers to a unique string
const defaultSqids = new Sqids();
const encoded1 = defaultSqids.encode([1, 2, 3]);
assert.strictEqual(typeof encoded1, 'string');
assert.strictEqual(encoded1, '86Rf07', 'sqids.encode must encode [1, 2, 3] to 86Rf07');
assert.deepStrictEqual(
defaultSqids.decode(encoded1),
[1, 2, 3],
'sqids.decode must decode back to the original array'
);
const encodedHelper = encodeNumbers([1, 2, 3]);
assert.strictEqual(encodedHelper, '86Rf07', 'encodeNumbers must produce identical result to sqids.encode');
// 2. Distinct inputs produce distinct strings
const encoded2 = defaultSqids.encode([1, 2, 4]);
assert.notStrictEqual(encoded1, encoded2, 'sqids.encode must produce different IDs for different inputs');
// 3. Empty array encoding: returns empty string
const encodedEmpty = defaultSqids.encode([]);
assert.strictEqual(encodedEmpty, '', 'sqids.encode must return empty string for empty array');
// 4. Custom minLength option: ensures minimum length of generated ID
const sqidsMin = new Sqids({ minLength: 10 });
const encodedMin = sqidsMin.encode([1, 2, 3]);
assert(encodedMin.length >= 10, 'sqids.encode must satisfy minLength requirement');
assert.strictEqual(encodedMin, '86Rf07xd4z', 'sqids.encode with minLength 10 matches expected output');
assert.deepStrictEqual(
sqidsMin.decode(encodedMin),
[1, 2, 3],
'sqids.decode must decode minLength-padded IDs correctly'
);
// 5. Custom alphabet option: uses characters from the provided alphabet
const customAlphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
const sqidsCustom = new Sqids({ alphabet: customAlphabet });
const encodedCustom = sqidsCustom.encode([1, 2, 3]);
assert.strictEqual(encodedCustom, 'UOYbqf', 'sqids.encode with custom alphabet matches expected output');
for (const char of encodedCustom) {
assert(customAlphabet.includes(char), `character ${char} must be within custom alphabet`);
}
assert.deepStrictEqual(
sqidsCustom.decode(encodedCustom),
[1, 2, 3],
'sqids.decode must decode custom alphabet IDs correctly'
);
// 6. Error handling: throws error on negative numbers
assert.throws(
() => {
defaultSqids.encode([-1]);
},
{
message: /Encoding supports numbers between 0 and/,
},
'sqids.encode must throw error when negative number is passed'
);
console.log('All contract assertions passed.');
Seeder de origen
anónimo