샘플
compact-encoding 3.3.2: c.string
검증된 샘플 — npm compact-encoding 3.3.2: c.string. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: c.string is exported as a codec object with…
sha256:d5385b6d113f7dfe9becb65cdaa6168cd300f1635cdd335be544944677cb2e69
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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-02 |
케이스
HOW- 목표
- verify c.string in pkg:npm/compact-encoding@3.3.2
- 심벌
-
- c.string
- 환경
- node 22.23.2
- 생성일
- 2026-09-02T15:25:05Z
컨트랙트
- c.string is exported as a codec object with preencode, encode, decode, and fixed
- c.string encodes and decodes standard UTF-8 strings
- c.string handles empty strings correctly
- c.string handles multi-byte unicode characters and emojis
- c.string supports manual state preencoding, encoding, and decoding
- c.string supports sequential encoding of multiple strings with state tracking
- c.string.fixed creates a fixed-length string codec without length prefix
- c.string throws an out of bounds error when decoding truncated buffers
- c.string.fixed throws an out of bounds error when decoding insufficient byte buffers
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- 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 c.string in pkg:npm/compact-encoding@3.3.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/compact-encoding@3.3.2
Demonstrate these symbols/APIs:
- c.string
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:4617fbdc69794887bdf1f3cb15ab94abf44b8e4cf00274598f77c3b5819ca4ff","contract":["c.string is exported as a codec object with preencode, encode, decode, and fixed","c.string encodes and decodes standard UTF-8 strings","c.string handles empty strings correctly","c.string handles multi-byte unicode characters and emojis","c.string supports manual state preencoding, encoding, and decoding","c.string supports sequential encoding of multiple strings with state tracking","c.string.fixed creates a fixed-length string codec without length prefix","c.string throws an out of bounds error when decoding truncated buffers","c.string.fixed throws an out of bounds error when decoding insufficient byte buffers"],"goal":"verify c.string in pkg:npm/compact-encoding@3.3.2","kind":"HOW","packages":["pkg:npm/compact-encoding@3.3.2"],"schemaVersion":1,"symbols":["c.string"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/compact-encoding@3.3.2"],"schemaVersion":1,"subject":"pkg:npm/compact-encoding@3.3.2","symbols":["c.string"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-compact-encoding-string",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-compact-encoding-string",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"compact-encoding": "3.3.2"
}
},
"node_modules/b4a": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/b4a/-/b4a-1.8.1.tgz",
"integrity": "sha512-aiqre1Nr0B/6DgE2N5vwTc+2/oQZ4Wh1t4NznYY4E00y8LCt6NqdRv81so00oo27D8MVKTpUa/MwUUtBLXCoDw==",
"license": "Apache-2.0",
"peerDependencies": {
"react-native-b4a": "*"
},
"peerDependenciesMeta": {
"react-native-b4a": {
"optional": true
}
}
},
"node_modules/compact-encoding": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/compact-encoding/-/compact-encoding-3.3.2.tgz",
"integrity": "sha512-bgZ84oVSzjQmVHXBYWON+wQUkdVflrr8fM5+0X6UwQHZyzolsGIkdsjNK3vLLn22dhdASGFz5mS6Lf7rfrPdlg==",
"license": "Apache-2.0",
"dependencies": {
"b4a": "^1.3.0"
}
}
}
}
{
"name": "sample-compact-encoding-string",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification of c.string in compact-encoding",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"compact-encoding": "3.3.2"
}
}
{
"schemaVersion": 1,
"goal": "verify c.string in pkg:npm/compact-encoding@3.3.2",
"kind": "HOW",
"packages": [
"pkg:npm/compact-encoding@3.3.2"
],
"symbols": [
"c.string"
]
}
'use strict';
const c = require('compact-encoding');
/**
* Encode a string using compact-encoding string codec.
* @param {string} value - string to encode
* @returns {Buffer|Uint8Array} encoded buffer
*/
function encodeString(value) {
return c.encode(c.string, value);
}
/**
* Decode a string from binary buffer using compact-encoding string codec.
* @param {Buffer|Uint8Array} buffer - binary buffer to decode
* @returns {string} decoded string
*/
function decodeString(buffer) {
return c.decode(c.string, buffer);
}
/**
* Create a fixed-length string codec.
* @param {number} length - byte length of the string
* @returns {object} codec
*/
function createFixedStringCodec(length) {
return c.string.fixed(length);
}
module.exports = {
c,
compactEncoding: c,
string: c.string,
encodeString,
decodeString,
createFixedStringCodec
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
c,
compactEncoding,
string,
encodeString,
decodeString,
createFixedStringCodec
} = require('../src/index.js');
// 1. c.string is exported as a codec object with preencode, encode, decode, and fixed
assert.equal(typeof string, 'object', 'string codec must be exported as an object');
assert.equal(typeof string.preencode, 'function', 'string.preencode must be a function');
assert.equal(typeof string.encode, 'function', 'string.encode must be a function');
assert.equal(typeof string.decode, 'function', 'string.decode must be a function');
assert.equal(typeof string.fixed, 'function', 'string.fixed must be a function');
assert.equal(typeof c.string, 'object', 'c.string must match exported string');
assert.equal(typeof encodeString, 'function', 'encodeString helper must be a function');
assert.equal(typeof decodeString, 'function', 'decodeString helper must be a function');
assert.equal(typeof createFixedStringCodec, 'function', 'createFixedStringCodec helper must be a function');
// 2. c.string encodes and decodes standard UTF-8 strings
{
const expected = 'Hello, CodeSampleX clean-room verification!';
const encoded = encodeString(expected);
const decoded = decodeString(encoded);
assert.equal(decoded, expected, 'Decoded string must match original standard ASCII/UTF-8 string');
}
// 3. c.string handles empty strings correctly
{
const empty = '';
const encoded = encodeString(empty);
assert.equal(encoded.length, 1, 'Empty string should encode to a single length prefix byte (0)');
const decoded = decodeString(encoded);
assert.equal(decoded, empty, 'Decoded empty string must match empty string');
}
// 4. c.string handles multi-byte unicode characters and emojis
{
const unicodeText = 'Hello 🌍 세계 🚀 Привет 🦔';
const encoded = encodeString(unicodeText);
const decoded = decodeString(encoded);
assert.equal(decoded, unicodeText, 'Decoded string must match unicode string with emojis');
}
// 5. c.string supports manual state preencoding, encoding, and decoding
{
const text = 'state-based manual buffer encoding';
const state = c.state();
string.preencode(state, text);
assert.ok(state.end > 0, 'State end pointer must advance after preencode');
state.buffer = Buffer.allocUnsafe(state.end);
string.encode(state, text);
assert.equal(state.start, state.end, 'State start pointer must equal end pointer after encoding');
state.start = 0;
const decoded = string.decode(state);
assert.equal(decoded, text, 'Decoded string from manual state must match original');
}
// 6. c.string supports sequential encoding of multiple strings with state tracking
{
const state = c.state();
const first = 'first segment';
const second = 'second segment';
string.preencode(state, first);
string.preencode(state, second);
state.buffer = Buffer.allocUnsafe(state.end);
string.encode(state, first);
string.encode(state, second);
state.start = 0;
const decodedFirst = string.decode(state);
const decodedSecond = string.decode(state);
assert.equal(decodedFirst, first, 'First sequentially decoded string must match');
assert.equal(decodedSecond, second, 'Second sequentially decoded string must match');
assert.equal(state.start, state.end, 'State start pointer must reach end after sequential decoding');
}
// 7. c.string.fixed creates a fixed-length string codec without length prefix
{
const fixedLen = 11;
const fixedCodec = createFixedStringCodec(fixedLen);
assert.equal(typeof fixedCodec.preencode, 'function', 'fixedCodec.preencode must be a function');
assert.equal(typeof fixedCodec.encode, 'function', 'fixedCodec.encode must be a function');
assert.equal(typeof fixedCodec.decode, 'function', 'fixedCodec.decode must be a function');
const text = 'fixedlength';
const encoded = c.encode(fixedCodec, text);
assert.equal(encoded.length, fixedLen, 'Fixed string encoding must not include a length prefix byte');
const decoded = c.decode(fixedCodec, encoded);
assert.equal(decoded, text, 'Decoded fixed-length string must match original');
}
// 8. c.string throws an out of bounds error when decoding truncated buffers
{
const truncated = Buffer.from([10, 0x41]);
assert.throws(
() => decodeString(truncated),
/Out of bounds/,
'c.string must throw Out of bounds error on truncated buffer'
);
}
// 9. c.string.fixed throws an out of bounds error when decoding insufficient byte buffers
{
const fixedCodec = createFixedStringCodec(10);
const truncated = Buffer.from([0x41, 0x42, 0x43]);
assert.throws(
() => c.decode(fixedCodec, truncated),
/Out of bounds/,
'c.string.fixed must throw Out of bounds error on buffer shorter than fixed length'
);
}
console.log('Contract assertions passed.');
오리진 시더
익명