CodeSampleX

Sample

buffer-equal-constant-time 1.0.1: bufferEqualConstantTime

Verified sample for npm buffer-equal-constant-time 1.0.1: bufferEqualConstantTime. The contract ran on node 22 · linux alpine/x64 · docker and passed.

sha256:dd9c775176ce2232c346a5f020231a2b19e605ee1bcd1ac2ccefc8471c84107d

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify bufferEqualConstantTime in pkg:npm/buffer-equal-constant-time@1.0.1
Packages
Symbols
  • bufferEqualConstantTime
Environment
node 22.23.2
Created
2026-08-26T04:31:15Z

Contract

  1. bufferEqualConstantTime returns true for equal buffers of same length and identical content
  2. bufferEqualConstantTime returns false for buffers with different content but same length
  3. bufferEqualConstantTime returns false for buffers of different lengths
  4. bufferEqualConstantTime returns false if first argument is not a Buffer
  5. bufferEqualConstantTime returns false if second argument is not a Buffer
  6. bufferEqualConstantTime.install extends Buffer prototype with equal method and restore reverts it

Files

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

Download the source artifact (tar.gz)

Source

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 bufferEqualConstantTime in pkg:npm/buffer-equal-constant-time@1.0.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/buffer-equal-constant-time@1.0.1
Demonstrate these symbols/APIs:
  - bufferEqualConstantTime
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:ad1d9dc941988b8165f94ebd28d51cae8050c6d3703f5afdb853e39e741691e7","constraints":{"executionContext":"node"},"contract":["bufferEqualConstantTime returns true for equal buffers of same length and identical content","bufferEqualConstantTime returns false for buffers with different content but same length","bufferEqualConstantTime returns false for buffers of different lengths","bufferEqualConstantTime returns false if first argument is not a Buffer","bufferEqualConstantTime returns false if second argument is not a Buffer","bufferEqualConstantTime.install extends Buffer prototype with equal method and restore reverts it"],"goal":"verify bufferEqualConstantTime in pkg:npm/buffer-equal-constant-time@1.0.1","kind":"HOW","packages":["pkg:npm/buffer-equal-constant-time@1.0.1"],"schemaVersion":1,"symbols":["bufferEqualConstantTime"]},"contractCommand":["node","test/contract.js"],"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/buffer-equal-constant-time@1.0.1"],"schemaVersion":1,"subject":"pkg:npm/buffer-equal-constant-time@1.0.1","symbols":["bufferEqualConstantTime"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-buffer-equal-constant-time",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-buffer-equal-constant-time",
      "version": "1.0.0",
      "dependencies": {
        "buffer-equal-constant-time": "1.0.1"
      }
    },
    "node_modules/buffer-equal-constant-time": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
      "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==",
      "license": "BSD-3-Clause"
    }
  }
}
package.json
{
  "name": "sample-buffer-equal-constant-time",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for buffer-equal-constant-time",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "buffer-equal-constant-time": "1.0.1"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify bufferEqualConstantTime in pkg:npm/buffer-equal-constant-time@1.0.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/buffer-equal-constant-time@1.0.1"
  ],
  "symbols": [
    "bufferEqualConstantTime"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.js
'use strict';

const bufferEqualConstantTime = require('buffer-equal-constant-time');

/**
 * Compares two buffers in constant time.
 * @param {Buffer} a
 * @param {Buffer} b
 * @returns {boolean}
 */
function compareBuffers(a, b) {
  return bufferEqualConstantTime(a, b);
}

module.exports = {
  bufferEqualConstantTime,
  compareBuffers
};
test/contract.js
'use strict';

const assert = require('assert');
const bufferEqualConstantTime = require('buffer-equal-constant-time');
const { compareBuffers } = require('../src/index.js');

// 1. bufferEqualConstantTime returns true for equal buffers of same length and identical content
{
  const buf1 = Buffer.from('hello world');
  const buf2 = Buffer.from('hello world');
  assert.strictEqual(bufferEqualConstantTime(buf1, buf2), true);
  assert.strictEqual(compareBuffers(buf1, buf2), true);

  const empty1 = Buffer.alloc(0);
  const empty2 = Buffer.alloc(0);
  assert.strictEqual(bufferEqualConstantTime(empty1, empty2), true);
}

// 2. bufferEqualConstantTime returns false for buffers with different content but same length
{
  const buf1 = Buffer.from('hello world');
  const buf2 = Buffer.from('hello warld');
  assert.strictEqual(bufferEqualConstantTime(buf1, buf2), false);
  assert.strictEqual(compareBuffers(buf1, buf2), false);

  const hex1 = Buffer.from([0x01, 0x02, 0x03]);
  const hex2 = Buffer.from([0x01, 0x02, 0x04]);
  assert.strictEqual(bufferEqualConstantTime(hex1, hex2), false);
}

// 3. bufferEqualConstantTime returns false for buffers of different lengths
{
  const shortBuf = Buffer.from('short');
  const longBuf = Buffer.from('longer buffer');
  assert.strictEqual(bufferEqualConstantTime(shortBuf, longBuf), false);
  assert.strictEqual(bufferEqualConstantTime(longBuf, shortBuf), false);
}

// 4. bufferEqualConstantTime returns false if first argument is not a Buffer
{
  const validBuf = Buffer.from('test');
  assert.strictEqual(bufferEqualConstantTime('test', validBuf), false);
  assert.strictEqual(bufferEqualConstantTime(null, validBuf), false);
  assert.strictEqual(bufferEqualConstantTime(undefined, validBuf), false);
  assert.strictEqual(bufferEqualConstantTime([116, 101, 115, 116], validBuf), false);
  assert.strictEqual(bufferEqualConstantTime({ length: 4 }, validBuf), false);
}

// 5. bufferEqualConstantTime returns false if second argument is not a Buffer
{
  const validBuf = Buffer.from('test');
  assert.strictEqual(bufferEqualConstantTime(validBuf, 'test'), false);
  assert.strictEqual(bufferEqualConstantTime(validBuf, null), false);
  assert.strictEqual(bufferEqualConstantTime(validBuf, undefined), false);
  assert.strictEqual(bufferEqualConstantTime(validBuf, [116, 101, 115, 116]), false);
  assert.strictEqual(bufferEqualConstantTime(validBuf, {}), false);
}

// 6. bufferEqualConstantTime.install extends Buffer prototype with equal method and restore reverts it
{
  const origEqual = Buffer.prototype.equal;
  bufferEqualConstantTime.install();
  assert.strictEqual(typeof Buffer.prototype.equal, 'function');

  const bufA = Buffer.from('secret_token_123');
  const bufB = Buffer.from('secret_token_123');
  const bufC = Buffer.from('secret_token_456');

  assert.strictEqual(bufA.equal(bufB), true);
  assert.strictEqual(bufA.equal(bufC), false);

  bufferEqualConstantTime.restore();
  assert.strictEqual(Buffer.prototype.equal, origEqual);
}

console.log('Contract tests passed successfully.');

Origin Seeder

anonymous