BIP85KMS provides a RESTful HTTP API for deterministic key derivation using BIP-Keychain semantic paths. Instead of arbitrary numeric indexes, derivation paths are built from meaningful JSON-LD objects using schema.org vocabulary. The service derives Age-compatible encryption keys from a master mnemonic and semantic metadata without storing any per-file keys.
Semantic paths use JSON-LD (JSON Linked Data) objects with schema.org vocabulary to create human-readable, self-documenting derivation paths. Each segment in the path represents a meaningful context:
[
{"@type": "Organization", "name": "AcmeCorp"},
{"@type": "SoftwareApplication", "name": "backup-system"},
{"@type": "DigitalDocument", "name": "database.sql"}
]This produces a BIP-32 path like m/83696968'/67797668'/923847291'/1837461928'/746291835' where each number is cryptographically derived from the semantic context.
Benefits:
- Self-documenting: Paths contain meaningful information
- Collision-resistant: Same segment at different positions = different indexes
- Order-sensitive:
[A, B] ≠ [B, A] - Deterministic: Same input always produces same output
The API is deployed as a Cloudflare Worker. You must deploy your own instance:
https://your-worker-domain.workers.dev
Or configure a custom route:
https://keys.example.com/*
- Retrieve public keys
- Request private key material if
getPrivateKey: trueis set
Production Recommendation: Implement one of the following authentication mechanisms:
- mTLS (mutual TLS) for client certificate validation
- JWT (JSON Web Tokens) with signature verification
- HMAC request signing
- IP allowlisting at the Cloudflare Worker level
- Cloudflare Access for identity-based authentication
The single endpoint for all key derivation operations.
HTTP Method: POST
Content-Type: application/json
Request Body Schema:
{
semanticPath: Array<{
"@type": string;
[key: string]: any;
}>;
getPrivateKey?: boolean;
}Field Descriptions:
| Field | Type | Required | Description |
|---|---|---|---|
semanticPath |
array | Yes | Array of JSON-LD objects with schema.org types. Each object must have an @type property. Minimum 1 segment. |
getPrivateKey |
boolean | No | If true, response includes private key material. Default false returns only public key. Use with extreme caution. |
Common schema.org Types:
| @type | Use Case | Example Properties |
|---|---|---|
Organization |
Company/team namespace | name, identifier |
SoftwareApplication |
Application context | name, applicationCategory |
DigitalDocument |
File/document identifier | name, encodingFormat |
WebSite |
Web service keys | url, name |
Person |
Personal keys | name, email |
CreateAction |
Key derivation operation | name, object |
Returns only the public key needed for encryption.
HTTP Status: 200 OK
Response Body:
{
"age_public_key": "age15vzcvrduzysjsns520xkrd9les2nxjllnrhql9lefm4rhtkjmqeqglns33",
"derivationPath": "m/83696968'/67797668'/923847291'/1837461928'/746291835'",
"semanticPath": [
{"@type": "Organization", "name": "AcmeCorp"},
{"@type": "SoftwareApplication", "name": "backup-system"},
{"@type": "DigitalDocument", "name": "database.sql"}
]
}Fields:
| Field | Type | Description |
|---|---|---|
age_public_key |
string | Age-format public key (bech32 encoding with "age" prefix). Used as the recipient for Age encryption. |
derivationPath |
string | BIP-32 derivation path showing the numeric indexes derived from semantic segments. |
semanticPath |
array | Echo of the input semantic path for verification. |
Returns full key material including private key, entropy, and derivation path.
HTTP Status: 200 OK
Response Body:
{
"derivationPath": "m/83696968'/67797668'/923847291'/1837461928'/746291835'",
"age_private_key": "AGE-SECRET-KEY-1M4XE5PZGVMPX0D923NHT6HRXT7VEZRMCYHJZYTD8UR6WX0A29WGSR6KPEW",
"age_public_key": "age15vzcvrduzysjsns520xkrd9les2nxjllnrhql9lefm4rhtkjmqeqglns33",
"raw_entropy": "d81b4fb9db6d620a5d8b26b24ee4423f74bf1a555137d2e0c6eec2ef088ddd81",
"semanticPath": [
{"@type": "Organization", "name": "AcmeCorp"},
{"@type": "SoftwareApplication", "name": "backup-system"},
{"@type": "DigitalDocument", "name": "database.sql"}
]
}Fields:
| Field | Type | Description |
|---|---|---|
derivationPath |
string | BIP-32 derivation path using BIP-Keychain format: m/83696968'/67797668'/{index1}'/{index2}'/{index3}' where indexes are cryptographically derived from semantic segments. |
age_private_key |
string | Age-format private key (bech32 encoding with "AGE-SECRET-KEY-" prefix). Used for Age decryption. Highly sensitive. |
age_public_key |
string | Age-format public key corresponding to the private key. |
raw_entropy |
string | 32 bytes (64 hex chars) of BIP85-derived entropy. The seed material from which keys are derived. Highly sensitive. |
semanticPath |
array | Echo of the input semantic path for verification. |
Returned when using HTTP methods other than POST.
HTTP Status: 405 Method Not Allowed
Response Body:
Method Not Allowed
Returned when semanticPath is missing, empty, or not an array.
HTTP Status: 400 Bad Request
Response Body:
{
"error": "semanticPath must be a non-empty array of JSON-LD objects"
}Returned when a segment is missing required properties (e.g., @type).
HTTP Status: 400 Bad Request
Response Body:
{
"error": "Invalid segment at index 0: Semantic segment must have @type property"
}BIP-Keychain paths follow this format:
m/83696968'/67797668'/{semantic_index_1}'/{semantic_index_2}'/...
83696968'= BIP-85 purpose code67797668'= BIP-Keychain application code- Subsequent indexes are derived from semantic segments using HMAC-SHA-256
For each semantic segment:
- Canonicalize: Convert JSON object to canonical form (JCS/RFC 8785)
- HMAC: Compute
HMAC-SHA-256(parent_entropy, canonical_json) - Extract: Take first 31 bits of HMAC output
- Harden: Set bit 31 to create hardened index
Each segment's index is derived using entropy from the parent path:
- Segment at depth 0 uses base BIP-Keychain entropy
- Segment at depth N uses entropy from path at depth N-1
- This ensures: Same segment at different depths = different indexes
- Deterministic: Same input always produces same output
- Order-sensitive:
[A, B] ≠ [B, A] - Context-dependent: Same segment in different positions = different indexes
- Collision-resistant: Different segments produce different indexes
Request public key for encrypting a document:
curl -X POST https://keys.example.com \
-H "Content-Type: application/json" \
-d '{
"semanticPath": [
{
"@type": "Organization",
"name": "AcmeCorp"
},
{
"@type": "DigitalDocument",
"name": "quarterly-report-2025.pdf"
}
]
}'Response:
{
"age_public_key": "age1qyv7kkr...",
"derivationPath": "m/83696968'/67797668'/923847291'/1837461928'",
"semanticPath": [
{"@type": "Organization", "name": "AcmeCorp"},
{"@type": "DigitalDocument", "name": "quarterly-report-2025.pdf"}
]
}Use Case: You have the public key to encrypt quarterly-report-2025.pdf for AcmeCorp using Age encryption.
Request private key with application context:
curl -X POST https://keys.example.com \
-H "Content-Type: application/json" \
-d '{
"semanticPath": [
{
"@type": "Organization",
"name": "AcmeCorp"
},
{
"@type": "SoftwareApplication",
"name": "backup-system",
"applicationCategory": "Utilities"
},
{
"@type": "DigitalDocument",
"name": "database-backup.sql",
"encodingFormat": "application/sql"
}
],
"getPrivateKey": true
}'Response:
{
"derivationPath": "m/83696968'/67797668'/923847291'/1234567890'/2147483647'",
"age_private_key": "AGE-SECRET-KEY-1...",
"age_public_key": "age1qyv7kkr...",
"raw_entropy": "d81b4fb9db6d620a5d8b26b24ee4423f74bf1a555137d2e0c6eec2ef088ddd81",
"semanticPath": [
{"@type": "Organization", "name": "AcmeCorp"},
{"@type": "SoftwareApplication", "name": "backup-system", "applicationCategory": "Utilities"},
{"@type": "DigitalDocument", "name": "database-backup.sql", "encodingFormat": "application/sql"}
]
}Use Case: Full application context for backup system with private key for decryption.
Derive keys for web service authentication:
curl -X POST https://keys.example.com \
-H "Content-Type: application/json" \
-d '{
"semanticPath": [
{
"@type": "Organization",
"name": "MyCompany"
},
{
"@type": "WebSite",
"url": "https://api.github.com",
"name": "GitHub API"
}
],
"getPrivateKey": true
}'Use Case: Derive consistent keys for API authentication across services.
Derive keys for personal use:
curl -X POST https://keys.example.com \
-H "Content-Type: application/json" \
-d '{
"semanticPath": [
{
"@type": "Person",
"name": "John Doe",
"email": "john@example.com"
},
{
"@type": "DigitalDocument",
"name": "personal-notes.txt"
}
]
}'Use Case: Personal file encryption with semantic context.
When you need to rotate keys, add version information to the semantic path:
# Version 1
curl -X POST https://keys.example.com \
-H "Content-Type: application/json" \
-d '{
"semanticPath": [
{"@type": "Organization", "name": "AcmeCorp"},
{"@type": "SoftwareApplication", "name": "backup", "version": "1.0"},
{"@type": "DigitalDocument", "name": "data.db"}
]
}'
# Version 2 (different keys due to version property)
curl -X POST https://keys.example.com \
-H "Content-Type": application/json" \
-d '{
"semanticPath": [
{"@type": "Organization", "name": "AcmeCorp"},
{"@type": "SoftwareApplication", "name": "backup", "version": "2.0"},
{"@type": "DigitalDocument", "name": "data.db"}
]
}'Different semantic paths (even with small changes like version numbers) produce different keys.
Different applications should use different semantic paths:
# App 1 - backup system
curl -X POST https://keys.example.com \
-H "Content-Type: application/json" \
-d '{
"semanticPath": [
{"@type": "SoftwareApplication", "name": "backup-system"},
{"@type": "DigitalDocument", "name": "config.json"}
]
}'
# App 2 - mobile app
curl -X POST https://keys.example.com \
-H "Content-Type: application/json" \
-d '{
"semanticPath": [
{"@type": "SoftwareApplication", "name": "mobile-app"},
{"@type": "DigitalDocument", "name": "config.json"}
]
}'The API returns Age-compatible keys that work with the age encryption tool.
# 1. Get public key from API
PUBLIC_KEY=$(curl -s -X POST https://keys.example.com \
-H "Content-Type: application/json" \
-d '{
"semanticPath": [
{"@type": "Organization", "name": "myorg"},
{"@type": "DigitalDocument", "name": "secret.txt"}
]
}' \
| jq -r '.age_public_key')
# 2. Encrypt file with age
echo "$PUBLIC_KEY" > /tmp/pubkey.txt
age -R /tmp/pubkey.txt -o secret.txt.age secret.txt# 1. Get private key from API (same semantic path!)
PRIVATE_KEY=$(curl -s -X POST https://keys.example.com \
-H "Content-Type: application/json" \
-d '{
"semanticPath": [
{"@type": "Organization", "name": "myorg"},
{"@type": "DigitalDocument", "name": "secret.txt"}
],
"getPrivateKey": true
}' \
| jq -r '.age_private_key')
# 2. Decrypt file with age
echo "$PRIVATE_KEY" > /tmp/privkey.txt
age -d -i /tmp/privkey.txt -o secret.txt secret.txt.age
rm /tmp/privkey.txt # Clean up sensitive materialCurrent Status: No rate limiting implemented.
Recommendation: Implement rate limiting at:
- Cloudflare Worker level (using Durable Objects or KV)
- Cloudflare rate limiting rules
- External API gateway
Without rate limiting, the service is vulnerable to:
- Brute-force enumeration attacks
- Denial of service
- Excessive API costs
Current Status: No CORS headers configured.
If you need to call this API from a browser, add CORS headers to the Worker response:
return new Response(JSON.stringify(result), {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "https://your-app.com",
"Access-Control-Allow-Methods": "POST",
"Access-Control-Allow-Headers": "Content-Type"
}
});-
Never expose
getPrivateKey: trueendpoints publicly- Use authentication and authorization
- Restrict to trusted clients only
- Consider IP allowlisting
-
Use TLS/HTTPS exclusively
- Cloudflare Workers provide TLS by default
- Never use HTTP for key material transmission
-
Implement request logging (without logging keys)
- Log request metadata (timestamp, IP, semanticPath summary)
- NEVER log the mnemonic, private keys, or entropy
- Use Cloudflare Workers logging or external logging services
- NEVER log the mnemonic, private keys, or entropy
- Use Cloudflare Workers logging or external logging services
-
Rotate the master mnemonic periodically
- Plan for mnemonic rotation
- Maintain key derivation history for decryption
-
Monitor for anomalous access patterns
- Unusual request volumes
- Requests for many different keyVersions
- Geographic anomalies
- No authentication: Anyone with the URL can request keys
- No rate limiting: Vulnerable to abuse
- No audit logging: No record of who requested which keys
- Single mnemonic: All keys derived from one secret
- No key revocation: Derived keys cannot be revoked individually
-
Semantic path entropy: The current semantic path derivation uses HMAC-SHA-256 chaining which provides good key separation. Each segment in the path contributes to the final entropy through the chaining mechanism.
-
No IV field in responses: The semantic path API does not return an
ivfield. Age encryption handles nonces internally, making the deterministic IV unnecessary for the primary use case.
Cause: The semanticPath field is missing, not an array, empty, or contains invalid segments.
Solution: Ensure semanticPath is a valid array with at least one object containing @type:
{
"semanticPath": [
{"@type": "Organization", "name": "myorg"},
{"@type": "DigitalDocument", "name": "file.txt"}
]
}Cause: The semantic path differs between requests.
Solution: Verify that semanticPath is exactly identical:
- Same number of segments
- Same order of segments
- Same property names and values
- JSON key order doesn't matter (canonicalization handles this)
Cause: Mismatch between encryption and decryption semantic paths.
Solution:
- Ensure you're using the exact same
semanticPathfor both operations - Verify the mnemonic hasn't changed
- Check that the encrypted file hasn't been corrupted
You can import the core derivation functions directly:
import { deriveFromSemanticPath, deriveMasterNodeFromMnemonic } from './src/bip85kms';
const mnemonic = process.env.MNEMONIC_SECRET;
const masterNode = deriveMasterNodeFromMnemonic(mnemonic);
const semanticPath = [
{"@type": "Organization", "name": "myorg"},
{"@type": "DigitalDocument", "name": "file.txt"}
];
const result = deriveFromSemanticPath(masterNode, semanticPath);
console.log(result.age_public_key);The browser demo at index.html shows how to use the derivation functions client-side:
import { deriveFromSemanticPath, deriveMasterNodeFromMnemonic } from "./src/core.js";
const masterNode = deriveMasterNodeFromMnemonic(mnemonic);
const semanticPath = [
{"@type": "Organization", "name": "myorg"},
{"@type": "DigitalDocument", "name": "file.txt"}
];
const result = deriveFromSemanticPath(masterNode, semanticPath);
// Use result.age_public_key
⚠️ Note: The Python CLI uses the legacyfilename/keyVersion/appIdAPI. For new projects, prefer the HTTP API with semantic paths.
See python/cli.py for a Python implementation using the bipsea library.
⚠️ Note: The shell scripts use the legacyfilename/keyVersion/appIdAPI. For new projects, prefer the HTTP API with semantic paths.
The scripts in bin/ show how to integrate with curl and Age:
bin/deterministic_age.sh- Age encryption/decryption wrapper (legacy API)
- ARCHITECTURE.md - System architecture and design decisions
- SECURITY.md - Security model and threat analysis
- README.md - Project overview and getting started guide
This is an open-source educational project. For issues or questions:
- Open an issue on GitHub: https://github.com/Amperstrand/BIP85KMS/issues
- Review the existing documentation in the
docs/folder
Important: This project is a proof-of-concept. Use in production at your own risk after thorough security review and hardening.