CodeSampleX

Beispiel

@noble/hashes 2.3.0: concatBytes

Verifiziertes Beispiel für npm @noble/hashes 2.3.0: concatBytes. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.

sha256:28b4c603f45b4b6eaec568c2b06f1dc1e8cfa95c54ad35f3f532158eb74ce58f

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-06

Fall

HOW
Ziel
verify @noble/hashes.concatBytes in pkg:npm/%40noble/hashes@2.3.0
Pakete
Symbole
  • @noble/hashes.concatBytes
Umgebung
node 22.23.2
Erstellt
2026-09-06T12:42:35Z

Contract

  1. concatBytes concatenates multiple Uint8Array instances into a single contiguous Uint8Array
  2. concatBytes returns an empty Uint8Array when called with no arguments or empty arrays
  3. concatBytes correctly handles Uint8Array subarrays and offset buffer views
  4. concatBytes produces an independent copy of byte data without mutating input arrays
  5. concatBytes rejects non-Uint8Array inputs by throwing TypeError

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 @noble/hashes.concatBytes in pkg:npm/%40noble/hashes@2.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40noble/hashes@2.3.0
Demonstrate these symbols/APIs:
  - @noble/hashes.concatBytes
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:8488c016c306c23d0c92b2191441b69e2602b3b7d6ecf26d3af4f36650b64549","constraints":{"executionContext":"node"},"contract":["concatBytes concatenates multiple Uint8Array instances into a single contiguous Uint8Array","concatBytes returns an empty Uint8Array when called with no arguments or empty arrays","concatBytes correctly handles Uint8Array subarrays and offset buffer views","concatBytes produces an independent copy of byte data without mutating input arrays","concatBytes rejects non-Uint8Array inputs by throwing TypeError"],"goal":"verify @noble/hashes.concatBytes in pkg:npm/%40noble/hashes@2.3.0","kind":"HOW","packages":["pkg:npm/%40noble/hashes@2.3.0"],"schemaVersion":1,"symbols":["@noble/hashes.concatBytes"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40noble/hashes@2.3.0"],"schemaVersion":1,"subject":"pkg:npm/%40noble/hashes@2.3.0","symbols":["@noble/hashes.concatBytes"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-noble-hashes-concat-bytes",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-noble-hashes-concat-bytes",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@noble/hashes": "2.3.0"
      }
    },
    "node_modules/@noble/hashes": {
      "version": "2.3.0",
      "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.3.0.tgz",
      "integrity": "sha512-oN+QwyX7VSHotibwubG3kpzbwKrfnyR6OOO+3Nk/53ADL7FmgHHz4TgrbaYKvvOw09u6QTx0oiH1cNCIOuN0CQ==",
      "license": "MIT",
      "engines": {
        "node": ">= 20.19.0"
      },
      "funding": {
        "url": "https://paulmillr.com/funding/"
      }
    }
  }
}
package.json
{
  "name": "sample-noble-hashes-concat-bytes",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@noble/hashes": "2.3.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @noble/hashes.concatBytes in pkg:npm/%40noble/hashes@2.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40noble/hashes@2.3.0"
  ],
  "symbols": [
    "@noble/hashes.concatBytes"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.mjs
import { concatBytes } from '@noble/hashes/utils.js';

export { concatBytes };

/**
 * Combines multiple Uint8Array instances into a single contiguous Uint8Array.
 * @param {...Uint8Array} arrays
 * @returns {Uint8Array}
 */
export function combineChunks(...arrays) {
  return concatBytes(...arrays);
}

/**
 * Concatenates UTF-8 encoded text strings into a single Uint8Array.
 * @param {...string} strings
 * @returns {Uint8Array}
 */
export function concatStrings(...strings) {
  const encoder = new TextEncoder();
  const byteArrays = strings.map((s) => encoder.encode(s));
  return concatBytes(...byteArrays);
}
test/contract.mjs
import assert from 'node:assert/strict';
import { concatBytes, combineChunks, concatStrings } from '../src/index.mjs';

// 1. concatBytes concatenates multiple Uint8Array instances into a single contiguous Uint8Array
{
  const a = new Uint8Array([0x01, 0x02]);
  const b = new Uint8Array([0x03, 0x04, 0x05]);
  const c = new Uint8Array([0x06]);
  const merged = concatBytes(a, b, c);

  assert.equal(merged instanceof Uint8Array, true);
  assert.equal(merged.length, 6);
  assert.deepEqual(merged, new Uint8Array([1, 2, 3, 4, 5, 6]));

  const combined = combineChunks(a, b, c);
  assert.deepEqual(combined, new Uint8Array([1, 2, 3, 4, 5, 6]));

  const textMerged = concatStrings('hello', ' ', 'world');
  assert.deepEqual(textMerged, new TextEncoder().encode('hello world'));
}

// 2. concatBytes returns an empty Uint8Array when called with no arguments or empty arrays
{
  const empty1 = concatBytes();
  assert.equal(empty1 instanceof Uint8Array, true);
  assert.equal(empty1.length, 0);

  const empty2 = concatBytes(new Uint8Array(0), new Uint8Array(0));
  assert.equal(empty2 instanceof Uint8Array, true);
  assert.equal(empty2.length, 0);

  const emptyCombined = combineChunks();
  assert.equal(emptyCombined.length, 0);

  const emptyStrings = concatStrings();
  assert.equal(emptyStrings.length, 0);
}

// 3. concatBytes correctly handles Uint8Array subarrays and offset buffer views
{
  const buffer = new ArrayBuffer(8);
  const view1 = new Uint8Array(buffer, 2, 3);
  view1[0] = 0xaa;
  view1[1] = 0xbb;
  view1[2] = 0xcc;

  const base = new Uint8Array([0x10, 0x20, 0x30, 0x40]);
  const view2 = base.subarray(1, 3); // [0x20, 0x30]

  const merged = concatBytes(view1, view2);
  assert.equal(merged.length, 5);
  assert.deepEqual(merged, new Uint8Array([0xaa, 0xbb, 0xcc, 0x20, 0x30]));
}

// 4. concatBytes produces an independent copy of byte data without mutating input arrays
{
  const part1 = new Uint8Array([10, 20]);
  const part2 = new Uint8Array([30, 40]);
  const result = concatBytes(part1, part2);

  assert.deepEqual(result, new Uint8Array([10, 20, 30, 40]));

  // Mutating output does not affect inputs
  result[0] = 99;
  assert.equal(part1[0], 10);

  // Mutating input after concat does not affect output
  part2[1] = 88;
  assert.equal(result[3], 40);
}

// 5. concatBytes rejects non-Uint8Array inputs by throwing TypeError
{
  assert.throws(() => concatBytes('not a byte array'), TypeError);
  assert.throws(() => concatBytes(null), TypeError);
  assert.throws(() => concatBytes(undefined), TypeError);
  assert.throws(() => concatBytes([1, 2, 3]), TypeError);
  assert.throws(() => concatBytes(12345), TypeError);
  assert.throws(() => concatBytes({}), TypeError);
  assert.throws(() => concatBytes(new Uint8Array([1]), 'invalid'), TypeError);

  assert.throws(() => combineChunks('invalid'), TypeError);
}

console.log('All contract tests passed successfully.');

Ursprungs-Seeder

anonym