@pdtf/core (TypeScript)
The TypeScript reference implementation of PDTF 2.0. All core functionality in a single dependency.
npm install @pdtf/coreRepository: property-data-standards-co/core-ts
Modules
Section titled “Modules”Ed25519 key generation and did:key derivation.
import { generateKeyPair, deriveDidKey, publicKeyToMultibase } from '@pdtf/core';
const keypair = generateKeyPair();// { publicKey: Uint8Array, secretKey: Uint8Array }
const did = deriveDidKey(keypair.publicKey);// did:key:z6Mk...
const multibase = publicKeyToMultibase(keypair.publicKey);// z6Mk...Keys use the 0xed01 multicodec prefix with base58-btc encoding (z prefix). All PDTF did:key identifiers start with did:key:z6Mk.
Key Providers
Section titled “Key Providers”@pdtf/core ships with four KeyProvider implementations for different environments:
| Provider | Backend | Use case | Install |
|---|---|---|---|
InMemoryKeyProvider | RAM | Unit tests | Built-in |
SqliteKeyProvider | Local file | Dev / third-party testing | npm i better-sqlite3 |
FirestoreKeyProvider | Firestore | Staging | npm i @google-cloud/firestore |
KmsKeyProvider | GCP Cloud KMS (HSM) | Production | npm i @google-cloud/kms |
import { SqliteKeyProvider, VcSigner } from '@pdtf/core';
// Zero-config local key managementconst keys = new SqliteKeyProvider({ dbPath: './pdtf-keys.db' });const key = await keys.generateKey('my-adapter', 'adapter');const signer = new VcSigner(keys, 'my-adapter', key.did);
// Start signing credentialsconst vc = await signer.sign({ type: 'PropertyDataCredential', credentialSubject: { id: 'urn:pdtf:uprn:100023336956', energyEfficiency: { rating: 'B', score: 85 }, },});For production with Cloud KMS:
import { KmsKeyProvider, VcSigner } from '@pdtf/core';
const keys = new KmsKeyProvider({ projectId: 'my-project', locationId: 'europe-west2', keyRingId: 'pdtf',});const key = await keys.generateKey('epc-adapter', 'adapter');const signer = new VcSigner(keys, 'epc-adapter', key.did);See the Key Management guide for full setup instructions.
signer
Section titled “signer”Create DataIntegrityProof signatures using eddsa-jcs-2022.
import { VcSigner } from '@pdtf/core';
const signer = new VcSigner(keyProvider);const signed = await signer.sign(credential, { keyId: 'my-key', verificationMethod: 'did:key:z6Mk...#z6Mk...',});Signing algorithm (eddsa-jcs-2022):
- JCS-canonicalize proof options → SHA-256 hash
- JCS-canonicalize document (without proof) → SHA-256 hash
- Concatenate both hashes (64 bytes)
- Sign with Ed25519 (raw, not pre-hashed)
- Encode signature as base58-btc (
zprefix)
validator
Section titled “validator”Verify DataIntegrityProof signatures.
import { verifyProof } from '@pdtf/core';
const valid = verifyProof(signedCredential, publicKey);// true | falseDID resolution for did:key and URN identifiers (urn:pdtf:uprn:*, urn:pdtf:titleNumber:*).
import { resolveDidKey, TransactionDidManager } from '@pdtf/core';
// Resolve did:key to DID Documentconst doc = resolveDidKey('did:key:z6Mk...');
// Transaction DID lifecycleconst manager = new TransactionDidManager(config);const txDid = await manager.create({ uprn: '100023336956' });status
Section titled “status”Bitstring Status List — create, encode, decode, and check credential revocation.
import { createStatusList, encodeStatusList, decodeStatusList, setBit, getBit } from '@pdtf/core';
const list = createStatusList(131072); // 131,072-bit minimumsetBit(list, 42);const encoded = encodeStatusList(list); // base64(gzip(bitstring))
const decoded = decodeStatusList(encoded);const isRevoked = getBit(decoded, 42); // trueTrusted Issuer Registry client — load and validate issuer authorisations.
import { loadRegistry, isAuthorised } from '@pdtf/core';
const registry = await loadRegistry('https://github.com/property-data-standards-co/tir');const result = isAuthorised(registry, issuerDid, ['Property:/energyEfficiency/certificate']);// { trusted: true, issuerSlug: 'epc-adapter', trustLevel: 'rootIssuer', ... }Path matching: The TIR supports wildcard patterns:
Property:/energyEfficiency/certificate— exact matchProperty:/energyEfficiency/*— matches any path under/energyEfficiency/Property:*— matches any Property path
Five commands for development and testing:
# Resolve a DID documentnpx @pdtf/core did-resolve did:key:z6Mk...
# Initialise an organisation DIDnpx @pdtf/core org-init --domain example.com --output ./keys
# Validate a TIR registry filenpx @pdtf/core tir-validate ./registry.json
# Inspect a VC (print structure without verification)npx @pdtf/core vc-inspect ./credential.json
# Verify a VC signaturenpx @pdtf/core vc-verify ./credential.json86 tests covering all modules:
| Module | Tests | Coverage |
|---|---|---|
| keys | 17 | Key generation, did:key derivation, roundtrip, multibase encoding, SQLite provider, KMS provider |
| signer | 3 | Proof creation, deterministic signing, proof structure |
| did | 29 | Transaction DID manager, URN parsing, did:key resolution |
| status | 7 | Create, encode/decode, set/get bits, roundtrip |
| tir | 7 | Path matching, wildcard semantics, edge cases |
| vectors | 17 | Cross-language vector generation and self-validation |
npm test