~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/pds.js

An atproto PDS in JavaScript, for Cloudflare Workers and Node

0
0
main
32 lines · 801 B Raw History
// The reference vectors, test/fixtures/space-vectors.json (see
// scripts/gen-space-vectors.md).
import { readFileSync } from 'node:fs';

export const vectors = JSON.parse(
  readFileSync(
    new URL('../../../../test/fixtures/space-vectors.json', import.meta.url),
    'utf8',
  ),
);

/** @param {string} h */
export const fromHex = (h) =>
  new Uint8Array((h.match(/../g) || []).map((x) => Number.parseInt(x, 16)));

/** @param {Uint8Array} bytes */
export const toHex = (bytes) =>
  Array.from(bytes)
    .map((b) => b.toString(16).padStart(2, '0'))
    .join('');

/** The reference commit, with `data` as bytes. */
export function referenceCommit() {
  const c = vectors.commit;
  return {
    ver: 1,
    repo: c.repo,
    space: c.space,
    rev: c.rev,
    data: fromHex(c.dataHex),
  };
}