Canonical ANBS URNs in the form urn:anbs:<SchemaOrgType>.<OpaqueIdentifier>. The Schema.org type comes from @sovereignbase/schema-crdt, and the opaque identifier presentation is validated through @sovereignbase/cryptosuite.
crypto, crypto.subtle, crypto.getRandomValues.urn:anbs generation and deterministic derivation.npm install @sovereignbase/urn-anbs
# or
pnpm add @sovereignbase/urn-anbs
# or
yarn add @sovereignbase/urn-anbs
# or
bun add @sovereignbase/urn-anbs
# or
deno add jsr:@sovereignbase/urn-anbs
# or
vlt install jsr:@sovereignbase/urn-anbs
import { UrnAnbs } from '@sovereignbase/urn-anbs'
const generated = UrnAnbs.generate('Person')
const derived = await UrnAnbs.derive('Thing', new Uint8Array([1, 2, 3]))
if (UrnAnbs.is(generated)) {
const { type, id } = UrnAnbs.parse(generated)
console.log(type, id)
}
UrnAnbs.assert(derived)
Uses @sovereignbase/cryptosuite for opaque identifier generation, derivation, and validation. Node must provide WebCrypto.
Uses the same cryptosuite API surface and requires WebCrypto-compatible runtime globals.
UrnAnbs.is(value) first validates the ANBS URN lexical prefix and Schema.org type segment, then validates the opaque identifier with Cryptographic.identifier.validate(...).
UrnAnbs.assert(value) throws UrnAnbsError with code URN_ANBS_INVALID_IDENTIFIER when validation fails.
npm run test
What the current test suite covers:
dist/**/*.js: 100% statements, 100% branches,
100% functions, and 100% lines via c8.UrnAnbsError failure paths.npm run test passes on Node v22.14.0 (win32 x64).npm run bench
The benchmark suite measures the public ANBS URN operations.
Last measured on Node v22.14.0 (win32 x64):
| Benchmark | Result |
|---|---|
| generate | 104,791 ops/s (95.4 ms) |
| derive | 13,990 ops/s (71.5 ms) |
| is valid | 1,623,635 ops/s (61.6 ms) |
| parse valid | 768,429 ops/s (130.1 ms) |
Apache-2.0