Choose what this site may use

This site uses strictly necessary cookies to work and to remember your privacy choices. With your permission it would also load content hosted by other services, such as videos, maps and fonts, which then receive your network address and device data. We do not sell or share your personal information and we run no advertising. Choose Accept all, Reject all or Customise. You can change your mind at any time through Privacy choices at the foot of every page.

  • Always on

    Needed for the site to work and to remember your privacy choices. Always on.

  • Remembers settings you choose, such as the light or dark display, in your browser.

  • Loads videos, maps and other content hosted by other services. Those services receive your address and device data.

Menu Close
In this section: Build
Start
Reference code
Tools
API reference
Public services
Agents
Bindings and crosswalks

obsp-sdk (TypeScript / ES modules)

REFERENCE Source reference/typescript/obsp-sdk/README.md

FieldValue
StatusReference code; no conformance claim
Version0.0.1

Building blocks for Observatory Protocol documents that run unchanged in a browser and in Node.js 20 or later. Plain ES modules with JSDoc types and generated declarations (types/); no runtime dependencies and no build step. This library makes no conformance claim.

Module What it does
src/jcs.js RFC 8785 canonical JSON (canonicalize, canonicalBytes); numbers use the ECMAScript rules natively; non-finite numbers and lone surrogates are refused
src/digest.js the Digest form <alg>:<hex> (specification section 4.1): parseDigest, digestBytes, computeDigest (over the canonical bytes), verifyDigest; SHA-256, SHA-384 and SHA-512 through WebCrypto
src/uni.js UNI syntax (parseUni, isUni), with the uni:<kind>:<local> scheme split when present
src/schema.js a JSON Schema 2020-12 validator for the repository’s schemas (Schema, SchemaSet): every keyword the schemas use, local $ref only, format as an annotation (as in tools/validate.py); a schema using an unsupported keyword is refused when compiled; SchemaSet.checkFixture picks the schema from a fixture’s _schemaTitle; SchemaSet.detect finds the schema of a bare document
src/cbor.js minimal deterministic CBOR (RFC 8949 section 4.2.1), enough for COSE_Sign1
src/signature.js signature envelope verification as proposed by the OIP-0008 draft: COSE_Sign1 (RFC 9052) with a detached JCS payload, Sig_structure, key resolution against key records by UNI or RFC 7638 thumbprint, failure codes OBS-SIG-0001 to OBS-SIG-0008; Ed25519, ES256 and ES384 through WebCrypto; ML-DSA only where the platform’s WebCrypto offers it, otherwise the result is unavailable, never valid
src/algorithms.js the algorithm register of the OIP-0008 draft, reduced to what a verifier needs; OBJECT_CLASSES_0_2, its object classes in the 0.2 integration series (the proof and connector documents carry the envelope)
src/draft-checks.js DRAFT_CHECKS and runDraftChecks: the checks the draft proposals define, one row per subject document with the draft and requirement ids it checks (PASS, FAIL, or INCONCLUSIVE when the set lacks a document the check needs)
src/proofs.js OIP-0002 (0.2 series): challenge freshness (PRV-1), receipt bound to its challenge and window (PRV-2, PRV-3), nonce replay (PRV-4), report inputs (PRV-5, PRV-9), independent location sources (PRV-6: fewer than two is INCONCLUSIVE), trusted time (PRV-7), custody chain (PRV-8), transparency receipt (PRV-10)
src/plans.js OIP-0003 (0.2 series): a node’s decision planDecision (OBS-PLAN-0001 to OBS-PLAN-0007: version, expiry, threshold, mix-and-match, freeze, root, reserved kind) and the checks over a set (ORCH-1 to ORCH-8)
src/observation.js OIP-0006 (0.2 series): origin (OBS-3) and subject class (OBS-4)
src/mobile.js OIP-0013 (draft outside the series): trajectory time order (MOB-2) and per-kind speed limits (MOB-3)
src/triggers.js OIP-0018 (draft outside the series): the deterministic trigger evaluator (evaluateTrigger; correctly rounded sums, half-to-even rounding to six places) and the checks that an evaluation names its definition (TRG-6, TRG-4) and reproduces (TRG-7)
src/coverage.js OIP-0020 (draft outside the series): chunk manifest digest and unique keys (EOP-2), and verifyChunk for a consumer reading a chunk

OIP-0008 is a DRAFT. Until the editors accept it the protocol defines no signature, and signature.js, algorithms.js and the copied draft schemas follow the proposal, not the live specification. The SIG-2 payload has two rules (PAYLOAD_RULES, option payloadRule of verifyEnvelope): oip-0008 (the default, the draft as written: the payload leaves out signature) and integration-0.2 (the 0.2 integration series, which adopts OIP-0002’s proposal that the payload also leaves out transparencyReceipt; OIP-0002’s open question 2 stays open).

Every module of the draft checks follows a DRAFT proposal and is ported from that proposal’s Python reference (sdk/python in the draft or the integrated tree). None of them is part of the protocol, and their results describe the documents checked, never an implementation.

import { SchemaSet, computeDigest, verifyEnvelope } from './src/index.js';
const set = new SchemaSet(schemasByFileName);           // e.g. { 'observation-record': {...}, ... }
const { valid, errors } = set.validate('observation-record', doc);
const digest = await computeDigest(doc);               // 'sha256:...'
const result = await verifyEnvelope(signedDoc, keyRecords, { objectClass: 'receipt' });

Package

package.json is ready for the npm registry and is not published: version 0.0.x, licence Apache-2.0 (LICENSE), an exports map (the package root and one subpath per module, each with its declaration, ES modules only), and a files list of src, types, the README and the licence. npm pack --dry-run lists exactly those files (a test checks it). npm publish stops in prepublishOnly unless OBSP_SDK_PUBLISH_APPROVED=yes is set, which is for a release the maintainers have decided.

Tests

make ts from the repository root (or node --test "test/*.test.js" here) runs:

  • every fixture of fixtures/positive validates and every one of fixtures/negative fails against the schema its _schemaTitle names, and every positive fixture’s schema is found by detect;

  • RFC 8785 examples, digest known answers, UNI syntax, CBOR known answers from RFC 8949 Appendix A;

  • every signature test vector of the OIP-0008 draft reproduces its published bytes (JCS, protected header, Sig_structure, COSE_Sign1) and verifies or fails with the code it states. On a platform without ML-DSA in WebCrypto (Node.js 22 today) the two ML-DSA vectors that need the signature itself are reported as skipped.

  • every draft check passes on the copied examples and fails (or is INCONCLUSIVE) when one thing is changed; the plan vectors of the 0.2 series give their failing checks and node codes; the OIP-0018 evaluator reproduces the ten vectors of the draft whatever the input order; the eo-custody receipt of the series verifies under the integration-0.2 payload rule and fails OBS-SIG-0004 under the oip-0008 rule; the copies are current.

test/fixtures/integration-0.2/ and test/fixtures/drafts/OIP-0013, OIP-0018, OIP-0020 hold copies made by node tools/copy-draft-fixtures.mjs (--check reports stale copies; a test runs it): from the 0.2 integration series (the series applied to the touched files of the live tree in a temporary folder, tools/draft-sources.mjs) and from the patches of the three drafts. Each folder’s README lists its files. Rerun the tool when the series or a draft changes.

test/fixtures/oip-0008/ holds copies, taken from the patches of oips/drafts/OIP-0008/: the draft schemas (signature-envelope, key-record and the migrated attestation-result and correction-notice), some of their fixtures, the test keys and the vectors. The keys are test keys whose private parts are public. Refresh the copies when the draft changes.

The declarations in types/ are generated with the TypeScript compiler (tsc -p tsconfig.json, which also type-checks the sources in strict mode); the compiler is not needed to use or test the library.