// Cross-check our PLC-op primitives against Bluesky's implementation-neutral conformance
// vectors (atproto-interop-tests, vendored from ~/indigo/atproto/atcrypto/testdata, CC-0). These
// pin the EXACT bytes the atproto specs require. If a fixture disagrees with our output, our code
// is wrong — this is the offline, spec-authoritative cross-check that gates the PLC migration
// (stronger than goat; no permanent write). See the atproto-interop-tests + did-plc skills.
import test from 'brittle'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, join } from 'node:path'
import { keyFromPrivate } from '../lib/atproto-identity.js'
import { verifySig } from '../lib/plc-directory.js'
const here = dirname(fileURLToPath(import.meta.url))
const load = (name) => JSON.parse(readFileSync(join(here, 'vectors', name), 'utf8'))
const b64 = (s) => new Uint8Array(Buffer.from(s, 'base64'))
const hex = (s) => new Uint8Array(Buffer.from(s, 'hex'))
test('did:key (secp256k1): private key → did:key byte-exact (w3c_didkey_K256)', (t) => {
const cases = load('w3c_didkey_K256.json')
t.ok(cases.length >= 5, cases.length + ' K256 did:key vectors')
for (const c of cases) {
t.is(keyFromPrivate(hex(c.privateKeyBytesHex)).didKey, c.publicDidKey, c.publicDidKey.slice(0, 24) + '…')
}
})
test('ECDSA low-S signature validity (signature-fixtures, both curves)', (t) => {
const cases = load('signature-fixtures.json')
t.ok(cases.length === 6, '6 signature vectors')
for (const c of cases) {
const ok = verifySig(b64(c.messageBase64), b64(c.signatureBase64), c.publicKeyDid)
// valid low-S sigs verify true; high-S and DER-encoded sigs MUST verify false (§2 low-S rule)
t.is(ok, c.validSignature, c.comment + (c.tags.length ? ' [' + c.tags.join(',') + ']' : ''))
}
})