샘플
compact-encoding 3.3.2: c.encode
검증된 샘플 — npm compact-encoding 3.3.2: c.encode. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: c.encode encodes uint numbers into compact binary…
sha256:125e56ab8222164888548daf51943ae648cfcc6693f4bd1c748a7acc9d8cc785
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 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.encode in pkg:npm/compact-encoding@3.3.2
- 심벌
-
- c.encode
- 생성일
- 2026-09-02T15:41:49Z
컨트랙트
- c.encode encodes uint numbers into compact binary buffers using c.uint
- c.encode encodes utf8 strings with length prefix into binary buffers using c.string
- c.encode encodes boolean values into single-byte buffers using c.bool
- c.encode serializes array elements with length prefix using composite c.array encoding
- c.encode serializes custom structured records when provided an object with preencode and encode methods
- c.encode throws an error when attempting to encode numbers outside the safe unsigned integer range
파일
- 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 c.encode 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.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:187fab42cba0284b6e6d6148e1d7bbac577315f68f3fc80c6e7d2d943809ebae","contract":["c.encode encodes uint numbers into compact binary buffers using c.uint","c.encode encodes utf8 strings with length prefix into binary buffers using c.string","c.encode encodes boolean values into single-byte buffers using c.bool","c.encode serializes array elements with length prefix using composite c.array encoding","c.encode serializes custom structured records when provided an object with preencode and encode methods","c.encode throws an error when attempting to encode numbers outside the safe unsigned integer range"],"goal":"verify c.encode in pkg:npm/compact-encoding@3.3.2","kind":"HOW","packages":["pkg:npm/compact-encoding@3.3.2"],"schemaVersion":1,"symbols":["c.encode"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","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.encode"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-compact-encoding",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-compact-encoding",
"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",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"compact-encoding": "3.3.2"
}
}
{
"schemaVersion": 1,
"goal": "verify c.encode in pkg:npm/compact-encoding@3.3.2",
"kind": "HOW",
"packages": [
"pkg:npm/compact-encoding@3.3.2"
],
"symbols": [
"c.encode"
]
}
import c from 'compact-encoding';
/**
* Encode a primitive or composite value using a compact-encoding type descriptor.
* @param {object} enc - Encoding descriptor with preencode and encode methods
* @param {*} value - Value to encode
* @returns {Uint8Array}
*/
export function encodeValue(enc, value) {
return c.encode(enc, value);
}
/**
* Encode an unsigned integer using c.encode and c.uint.
* @param {number} value
* @returns {Uint8Array}
*/
export function encodeUint(value) {
return c.encode(c.uint, value);
}
/**
* Encode a string using c.encode and c.string.
* @param {string} value
* @returns {Uint8Array}
*/
export function encodeString(value) {
return c.encode(c.string, value);
}
/**
* Encode a boolean using c.encode and c.bool.
* @param {boolean} value
* @returns {Uint8Array}
*/
export function encodeBool(value) {
return c.encode(c.bool, value);
}
/**
* Encode an array of values using c.encode and c.array.
* @param {object} itemEncoding - Encoding descriptor for array elements
* @param {Array<*>} list - Array of elements to encode
* @returns {Uint8Array}
*/
export function encodeList(itemEncoding, list) {
return c.encode(c.array(itemEncoding), list);
}
/**
* Encode a structured object using a custom encoder definition.
* @param {{ id: number, tag: string }} item
* @returns {Uint8Array}
*/
export function encodeRecord(item) {
const recordEncoding = {
preencode(state, val) {
c.uint.preencode(state, val.id);
c.string.preencode(state, val.tag);
},
encode(state, val) {
c.uint.encode(state, val.id);
c.string.encode(state, val.tag);
},
decode(state) {
return {
id: c.uint.decode(state),
tag: c.string.decode(state)
};
}
};
return c.encode(recordEncoding, item);
}
export default c;
import assert from 'node:assert/strict';
import c, {
encodeValue,
encodeUint,
encodeString,
encodeBool,
encodeList,
encodeRecord
} from '../src/index.mjs';
// 1. c.encode encodes uint numbers into compact binary buffers using c.uint
{
const values = [0, 1, 100, 252, 253, 65535, 4294967295];
for (const val of values) {
const buf = c.encode(c.uint, val);
assert(buf instanceof Uint8Array);
assert(buf.byteLength > 0);
const decoded = c.decode(c.uint, buf);
assert.equal(decoded, val);
const helperBuf = encodeUint(val);
assert.deepEqual(helperBuf, buf);
}
}
// 2. c.encode encodes utf8 strings with length prefix into binary buffers using c.string
{
const strings = ['', 'hello', 'CodeSampleX', 'UTF-8 🚀⚡'];
for (const str of strings) {
const buf = c.encode(c.string, str);
assert(buf instanceof Uint8Array);
const decoded = c.decode(c.string, buf);
assert.equal(decoded, str);
const helperBuf = encodeString(str);
assert.deepEqual(helperBuf, buf);
}
}
// 3. c.encode encodes boolean values into single-byte buffers using c.bool
{
const trueBuf = c.encode(c.bool, true);
const falseBuf = c.encode(c.bool, false);
assert.equal(trueBuf.byteLength, 1);
assert.equal(falseBuf.byteLength, 1);
assert.equal(c.decode(c.bool, trueBuf), true);
assert.equal(c.decode(c.bool, falseBuf), false);
assert.deepEqual(encodeBool(true), trueBuf);
assert.deepEqual(encodeBool(false), falseBuf);
}
// 4. c.encode serializes array elements with length prefix using composite c.array encoding
{
const numbers = [10, 20, 30, 40];
const buf = c.encode(c.array(c.uint), numbers);
assert(buf instanceof Uint8Array);
const decoded = c.decode(c.array(c.uint), buf);
assert.deepEqual(decoded, numbers);
const helperBuf = encodeList(c.uint, numbers);
assert.deepEqual(helperBuf, buf);
}
// 5. c.encode serializes custom structured records when provided an object with preencode and encode methods
{
const item = { id: 101, tag: 'verified' };
const customEncoding = {
preencode(state, val) {
c.uint.preencode(state, val.id);
c.string.preencode(state, val.tag);
},
encode(state, val) {
c.uint.encode(state, val.id);
c.string.encode(state, val.tag);
},
decode(state) {
return {
id: c.uint.decode(state),
tag: c.string.decode(state)
};
}
};
const directBuf = c.encode(customEncoding, item);
assert(directBuf instanceof Uint8Array);
assert.deepEqual(c.decode(customEncoding, directBuf), item);
const helperBuf = encodeRecord(item);
assert.deepEqual(helperBuf, directBuf);
assert.deepEqual(c.decode(customEncoding, helperBuf), item);
}
// 6. c.encode throws an error when attempting to encode numbers outside the safe unsigned integer range
{
assert.throws(() => {
c.encode(c.uint, -1);
}, /uint must be between 0 and 9007199254740991/);
assert.throws(() => {
c.encode(c.uint, Number.MAX_SAFE_INTEGER + 1);
}, /uint must be between 0 and 9007199254740991/);
}
console.log('Contract assertions passed.');
오리진 시더
익명