@openape/core
v0.16.0
Published
Shared types, DNS resolver, JWT, PKCE, validation for OpenApe
Readme
@openape/core
Foundation layer for the OpenApe ecosystem. Provides shared types, cryptographic primitives, DNS resolution, and validation utilities used by all other packages.
Installation
npm install @openape/coreModules
Types
Core type definitions for the DDISA protocol and grant system.
DDISARecord— Parsed DNS TXT record pointing to an IdPSPManifest— Service Provider metadata (id, name, redirect URIs, JWKS)DDISAAssertionClaims— Signed assertion payload (iss, sub, aud, act, nonce, ...)AuthorizationRequest— Authorization endpoint parametersTokenExchangeRequest— Token endpoint parametersAuthFlowState— Client-side state during authorization flowOpenApeGrant— Grant object with status, requester, target, permissionsOpenApeGrantRequest— Grant creation requestOpenApeAuthZClaims— Authorization JWT payloadGrantType—'once' | 'timed' | 'always'GrantStatus—'pending' | 'approved' | 'denied' | 'revoked' | 'expired' | 'used'PolicyMode—'open' | 'allowlist-admin' | 'allowlist-user' | 'deny'ActorType—'human' | 'agent'ResolverOptions— DNS resolver configuration (cache TTL, DoH provider, mocks)
Crypto
Cryptographic utilities for key management, JWTs, PKCE, and password hashing.
generateKeyPair()— Generate an Ed25519 key pairsignJWT(payload, privateKey, options?)— Sign a JWTverifyJWT<T>(token, keyOrJWKS, options?)— Verify and decode a JWTcreateRemoteJWKS(jwksUri)— Create a JWKS fetcher for remote key setsexportPublicKeyJWK(publicKey, kid?)— Export public key as JWKimportJWK(jwk)— Import a JWK into a KeyLikegenerateCodeVerifier(length?)— Generate a PKCE code verifiergenerateCodeChallenge(verifier)— Compute S256 code challengegenerateState()— Random state parametergenerateNonce()— Random noncegenerateSalt()— Random salt for password hashinghashPassword(password)— Hash a password (argon2-like)verifyPassword(password, hash)— Verify a password against a hash
DNS
DDISA record resolution via DNS TXT lookups with DoH fallback and caching.
resolveDDISA(domain, options?)— Resolve DDISA record for a domainresolveIdP(domain, options?)— Shortcut: resolve and return only the IdP URLclearDNSCache()— Clear the in-memory DNS cacheparseDDISARecord(raw)— Parse a raw TXT record stringextractDomain(email)— Extract domain from an email addressresolveTXTviaDoh(domain, provider?)— Resolve TXT records via DNS-over-HTTPSdetectRuntime()— Detect current JS runtime ('node' | 'bun' | 'deno' | 'edge' | 'browser')
Validation
Validate assertions, authorization JWTs, and SP manifests.
validateAssertion(token, jwks, options?)— Validate a signed DDISA assertionvalidateAuthzJWT(token, jwks, options?)— Validate an authorization JWTcomputeCmdHash(command)— Compute command hash for grant verificationvalidateSPManifest(manifest)— Validate an SP manifest objectfetchAndValidateSPManifest(uri)— Fetch and validate a remote SP manifest
Constants
ALGORITHM— Signing algorithm (EdDSA)MAX_ASSERTION_TTL— Maximum assertion lifetimeWELL_KNOWN_JWKS,WELL_KNOWN_SP_MANIFEST— Well-known pathsDNS_TXT_TYPE— DNS record type for DDISADOH_PROVIDERS— Built-in DNS-over-HTTPS provider URLs
Usage
DNS Resolution
import { resolveDDISA, resolveIdP } from '@openape/core'
// Full DDISA record
const record = await resolveDDISA('example.com')
// { version: 'ddisa1', idp: 'https://id.example.com', mode: 'open', raw: '...' }
// Just the IdP URL
const idpUrl = await resolveIdP('example.com')
// 'https://id.example.com'JWT Signing & Verification
import { generateKeyPair, signJWT, verifyJWT } from '@openape/core'
const { publicKey, privateKey } = await generateKeyPair()
const token = await signJWT(
{ sub: '[email protected]', aud: 'sp.example.com' },
privateKey,
{ expiresIn: '5m' }
)
const { payload } = await verifyJWT(token, publicKey)PKCE
import { generateCodeVerifier, generateCodeChallenge } from '@openape/core'
const verifier = generateCodeVerifier()
const challenge = await generateCodeChallenge(verifier)