TypeScript Helper
The standalone TypeScript reference implementation lives at grigb/um-typescript. It is optional — you can implement the specification in any language — but it provides a complete TypeScript path for create, validate, sign, verify, and resolve operations.
Installation
Section titled “Installation”npm install @universalmanifest/typescriptValidate a v0.1 Manifest
Section titled “Validate a v0.1 Manifest”import { assertValidManifest, getManifestId,} from '@universalmanifest/typescript'
const raw = JSON.parse(jsonString)
// Structural validation -- throws if the manifest is malformedassertValidManifest(raw)
// After assertion, `raw` is typed as UniversalManifestV01console.log('UMID:', getManifestId(raw))console.log('Subject:', raw.subject)Verify a v0.2 Signed Manifest
Section titled “Verify a v0.2 Signed Manifest”v0.2 manifests require an Ed25519 signature. The helper validates the structure and verifies the signature in one call:
import { verify } from '@universalmanifest/typescript'
const signed = JSON.parse(signedJsonString)const result = verify(signed)if (!result.ok) { throw new Error(result.error)}Signature verification uses the inline
publicKeySpkiB64field. External key resolution viakeyRef(DID documents, HTTPS endpoints) is out of scope for this helper.
Exported Types
Section titled “Exported Types”| Type | Description |
|---|---|
UniversalManifestV01 | Full v0.1 manifest document |
UniversalManifestV02 | Full v0.2 manifest document (requires signature) |
UmEntityV01 | A typed entity embedded inside a shard |
UmShardV01 | A named data section within a manifest |
UmSignatureV01 | Signature for v0.1 |
UmSignatureV02 | Ed25519 + JCS signature for v0.2 |
JsonLdContext | JSON-LD @context value |
JsonLdType | JSON-LD @type value |
Exported Functions
Section titled “Exported Functions”| Function | Description |
|---|---|
create(input) | Create a v0.1 manifest or unsigned v0.2 draft |
assertValidManifest(value, options?) | Structural validation for v0.1/v0.2 manifests |
sign(unsignedV02, options) | Sign a v0.2 manifest with Ed25519 + JCS |
verify(value, options?) | Verify v0.2 signature (and optional freshness) |
resolve(input, options?) | Resolve from inline object, registry, callback, or resolver URL |
getManifestId(manifest) | Extract the @id (UMID) from a manifest |
Running Tests
Section titled “Running Tests”The reference implementation includes unit tests and conformance verification:
git clone https://github.com/grigb/um-typescript.gitcd um-typescriptnpm installnpm testnpm run conformanceSource
Section titled “Source”The full source is available in the standalone repository at grigb/um-typescript.