Auth, Errors & Types — TypeScript SDK¶
Admin authentication¶
Admin routes use Ed25519 over canonical JSON. The four headers:
Header |
Content |
|---|---|
|
The |
|
Ed25519 over |
|
ISO 8601 UTC timestamp |
|
UUID v4 replay-protection token |
canonicalJson produces deterministic JSON (sorted keys, no spaces) matching
Python’s json.dumps(..., sort_keys=True, separators=(",",":")).
The raw Ed25519 seed is wrapped in a PKCS8 DER prefix before being passed to
Node.js createPrivateKey (required in Node.js ≥ 22):
DER prefix: 302e020100300506032b657004220420
This is handled by signBytes in src/auth.ts — callers only provide the
base64-encoded 32-byte seed.
Raw admin calls¶
For NA admin routes not covered by a sub-client, use buildAdminHeaders
directly:
import { buildAdminHeaders } from 'genesis-mesh-sdk';
const body = {
subject_sovereign_id: 'BETA-NA',
subject_public_keys: ['<base64-pubkey>'],
scope: { allowed_roles: ['role:client'] },
validity_hours: 24,
};
const headers = buildAdminHeaders(body, keyId, signingKeyBase64);
const res = await fetch(`${baseUrl}/admin/recognition-treaties`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...headers },
body: JSON.stringify(body),
});
Error handling¶
All SDK errors extend GenesisMeshError with .code and .status:
Class |
HTTP |
When |
|---|---|---|
|
400 |
Malformed input |
|
401 |
Bad or missing admin signature |
|
404 |
Resource does not exist |
|
422 |
Constraint violation |
|
429 |
Rate limit exceeded |
|
— |
Connection refused, timeout, or fetch failure |
NA error responses use nested format:
{ error: { message: "...", code: "...", details: {}, request_id: "..." } }.
The SDK unwraps this automatically.
import { UnauthorizedError, ValidationError } from 'genesis-mesh-sdk';
try {
await client.agreement.offer({ ... });
} catch (err) {
if (err instanceof UnauthorizedError) { /* bad signing key or stale timestamp */ }
if (err instanceof ValidationError) { /* inspect err.message and err.code */ }
}
Types¶
All protocol interfaces are re-exported from genesis-mesh-sdk. Field names
use snake_case to match the NA JSON API exactly.
Key types: CapabilityOffer, AgreementRecord, BoundaryDecision,
TrustEvidence, MembershipAttestation, DataLicensePolicy,
DataAccessIntent, DataSourceDescriptor, ConsensusProof,
CapabilityCommitment, CapabilityMembershipProof.
See sdk-typescript/src/types.ts for the full list with JSDoc constraints.