mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 14:57:28 +00:00
M1 of the ANS SDK (docs/ans-sdk.md): - name: parse/format ans://v<semver>.<agent>.<domain> - cbor: minimal RFC 8949 codec for the COSE_Sign1 subset - verify/merkle: RFC 6962 leaf/node hashing, tree build, inclusion-proof generation + verification - verify/es256 + cose: COSE_Sign1 build/parse, Sig_structure, ES256 (WebCrypto) - verify/rootkeys: kid -> verifier key (JWKS entries; sumdb-note is M2) - verify: verifyReceipt() + verifyResolution() (signature + inclusion proof + name binding), pure and offline - client: AnsClient resolve/rootKeys/register/status over injectable fetch, with a DnsApplier hook for verify-dns Tests (24) cover name parsing, CBOR round-trips/vectors, RFC 6962 proofs, a full ES256+Merkle receipt round-trip with positive/negative cases, and the client against mocked fetch. Wired into the root build script. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { CborTag, decodeCbor, encodeCbor } from './cbor.js';
|
|
|
|
describe('cbor codec', () => {
|
|
it('encodes known RFC 8949 vectors', () => {
|
|
expect([...encodeCbor(0)]).toEqual([0x00]);
|
|
expect([...encodeCbor(23)]).toEqual([0x17]);
|
|
expect([...encodeCbor(24)]).toEqual([0x18, 0x18]);
|
|
expect([...encodeCbor(1000)]).toEqual([0x19, 0x03, 0xe8]);
|
|
expect([...encodeCbor(-1)]).toEqual([0x20]);
|
|
expect([...encodeCbor(-7)]).toEqual([0x26]);
|
|
expect([...encodeCbor('a')]).toEqual([0x61, 0x61]);
|
|
expect([...encodeCbor(new Uint8Array([1, 2, 3]))]).toEqual([0x43, 0x01, 0x02, 0x03]);
|
|
expect([...encodeCbor([1, 2, 3])]).toEqual([0x83, 0x01, 0x02, 0x03]);
|
|
});
|
|
|
|
it('round-trips ints, bytes, strings, arrays, maps, tags', () => {
|
|
const value = new CborTag(18, [
|
|
new Uint8Array([0xa1, 0x01, 0x26]),
|
|
new Map<unknown, unknown>([
|
|
[4, new Uint8Array([1, 2, 3, 4])],
|
|
['ans-proof', new Map<unknown, unknown>([['index', 1], ['size', 3], ['path', [new Uint8Array([9])]]])],
|
|
]),
|
|
new Uint8Array([0xde, 0xad]),
|
|
new Uint8Array(64).fill(7),
|
|
]);
|
|
const decoded = decodeCbor(encodeCbor(value as never));
|
|
expect(decoded).toEqual(value);
|
|
});
|
|
|
|
it('round-trips a large (4-byte and 8-byte) integer', () => {
|
|
expect(decodeCbor(encodeCbor(70000))).toBe(70000);
|
|
expect(decodeCbor(encodeCbor(5_000_000_000))).toBe(5_000_000_000);
|
|
});
|
|
});
|