@private.me/xbind 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +778 -0
- package/LICENSE.md +27 -0
- package/README.md +400 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +29 -0
- package/dist-standalone/_deps/crypto/base64.js +97 -0
- package/dist-standalone/_deps/crypto/cjs/base64.js +103 -0
- package/dist-standalone/_deps/crypto/cjs/errors.js +119 -0
- package/dist-standalone/_deps/crypto/cjs/hmac.js +71 -0
- package/dist-standalone/_deps/crypto/cjs/index.js +86 -0
- package/dist-standalone/_deps/crypto/cjs/padding.js +57 -0
- package/dist-standalone/_deps/crypto/cjs/share-header.js +68 -0
- package/dist-standalone/_deps/crypto/cjs/shares.js +152 -0
- package/dist-standalone/_deps/crypto/cjs/tlv.js +199 -0
- package/dist-standalone/_deps/crypto/cjs/uuid.js +61 -0
- package/dist-standalone/_deps/crypto/cjs/verify.js +24 -0
- package/dist-standalone/_deps/crypto/cjs/xorida.js +221 -0
- package/dist-standalone/_deps/crypto/errors.d.ts +51 -0
- package/dist-standalone/_deps/crypto/errors.js +109 -0
- package/dist-standalone/_deps/crypto/hmac.d.ts +39 -0
- package/dist-standalone/_deps/crypto/hmac.js +66 -0
- package/dist-standalone/_deps/crypto/index.d.ts +20 -0
- package/dist-standalone/_deps/crypto/index.js +45 -0
- package/dist-standalone/_deps/crypto/padding.d.ts +19 -0
- package/dist-standalone/_deps/crypto/padding.js +53 -0
- package/dist-standalone/_deps/crypto/share-header.d.ts +44 -0
- package/dist-standalone/_deps/crypto/share-header.js +63 -0
- package/dist-standalone/_deps/crypto/shares.d.ts +27 -0
- package/dist-standalone/_deps/crypto/shares.js +148 -0
- package/dist-standalone/_deps/crypto/tlv.d.ts +26 -0
- package/dist-standalone/_deps/crypto/tlv.js +195 -0
- package/dist-standalone/_deps/crypto/uuid.d.ts +22 -0
- package/dist-standalone/_deps/crypto/uuid.js +56 -0
- package/dist-standalone/_deps/crypto/verify.d.ts +15 -0
- package/dist-standalone/_deps/crypto/verify.js +15 -0
- package/dist-standalone/_deps/crypto/xorida.d.ts +44 -0
- package/dist-standalone/_deps/crypto/xorida.js +215 -0
- package/dist-standalone/_deps/mldsa-wasm/LICENSE +24 -0
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -0
- package/dist-standalone/_deps/mldsa-wasm/package.json +46 -0
- package/dist-standalone/_deps/mldsa-wasm/types/mldsa.d.ts +30 -0
- package/dist-standalone/_deps/shared/cjs/errors.js +582 -0
- package/dist-standalone/_deps/shared/cjs/index.js +492 -0
- package/dist-standalone/_deps/shared/cjs/package.json +1 -0
- package/dist-standalone/_deps/shared/cjs/types.js +403 -0
- package/dist-standalone/_deps/shared/errors.d.ts +48 -0
- package/dist-standalone/_deps/shared/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/errors.js +192 -0
- package/dist-standalone/_deps/shared/errors.js.map +1 -0
- package/dist-standalone/_deps/shared/index.d.ts +4 -0
- package/dist-standalone/_deps/shared/index.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/index.js +78 -0
- package/dist-standalone/_deps/shared/index.js.map +1 -0
- package/dist-standalone/_deps/shared/types.d.ts +1097 -0
- package/dist-standalone/_deps/shared/types.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/types.js +89 -0
- package/dist-standalone/_deps/shared/types.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts +115 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts +13 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/package.json +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts +39 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +83 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts +99 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +143 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts +32 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +119 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts +109 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +8 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/errors.d.ts +115 -0
- package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/errors.js +253 -0
- package/dist-standalone/_deps/ux-helpers/errors.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/index.d.ts +13 -0
- package/dist-standalone/_deps/ux-helpers/index.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/index.js +16 -0
- package/dist-standalone/_deps/ux-helpers/index.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts +39 -0
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/pagination.js +79 -0
- package/dist-standalone/_deps/ux-helpers/pagination.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/progress.d.ts +99 -0
- package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/progress.js +138 -0
- package/dist-standalone/_deps/ux-helpers/progress.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/search.d.ts +32 -0
- package/dist-standalone/_deps/ux-helpers/search.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/search.js +116 -0
- package/dist-standalone/_deps/ux-helpers/search.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/types.d.ts +109 -0
- package/dist-standalone/_deps/ux-helpers/types.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/types.js +7 -0
- package/dist-standalone/_deps/ux-helpers/types.js.map +1 -0
- package/dist-standalone/_deps/xchange/auto-accept.d.ts +127 -0
- package/dist-standalone/_deps/xchange/auto-accept.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/errors.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/index.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/package.json +1 -0
- package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -0
- package/dist-standalone/_deps/xchange/errors.d.ts +69 -0
- package/dist-standalone/_deps/xchange/errors.js +1 -0
- package/dist-standalone/_deps/xchange/index.d.ts +15 -0
- package/dist-standalone/_deps/xchange/index.js +1 -0
- package/dist-standalone/_deps/xchange/invite-client.d.ts +178 -0
- package/dist-standalone/_deps/xchange/invite-client.js +1 -0
- package/dist-standalone/_deps/xchange/lazy-init.d.ts +176 -0
- package/dist-standalone/_deps/xchange/lazy-init.js +1 -0
- package/dist-standalone/_deps/xchange/trust-integration.d.ts +102 -0
- package/dist-standalone/_deps/xchange/trust-integration.js +1 -0
- package/dist-standalone/_deps/xchange/xchange.d.ts +60 -0
- package/dist-standalone/_deps/xchange/xchange.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/index.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/package.json +1 -0
- package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/types.js +1 -0
- package/dist-standalone/_deps/xregistry/discovery.d.ts +126 -0
- package/dist-standalone/_deps/xregistry/discovery.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/discovery.js +1 -0
- package/dist-standalone/_deps/xregistry/discovery.js.map +1 -0
- package/dist-standalone/_deps/xregistry/errors.d.ts +41 -0
- package/dist-standalone/_deps/xregistry/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/errors.js +1 -0
- package/dist-standalone/_deps/xregistry/errors.js.map +1 -0
- package/dist-standalone/_deps/xregistry/index.d.ts +8 -0
- package/dist-standalone/_deps/xregistry/index.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/index.js +1 -0
- package/dist-standalone/_deps/xregistry/index.js.map +1 -0
- package/dist-standalone/_deps/xregistry/registry.d.ts +85 -0
- package/dist-standalone/_deps/xregistry/registry.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/registry.js +1 -0
- package/dist-standalone/_deps/xregistry/registry.js.map +1 -0
- package/dist-standalone/_deps/xregistry/schema.d.ts +81 -0
- package/dist-standalone/_deps/xregistry/schema.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/schema.js +1 -0
- package/dist-standalone/_deps/xregistry/schema.js.map +1 -0
- package/dist-standalone/_deps/xregistry/types.d.ts +95 -0
- package/dist-standalone/_deps/xregistry/types.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/types.js +1 -0
- package/dist-standalone/_deps/xregistry/types.js.map +1 -0
- package/dist-standalone/agent-call.d.ts +286 -0
- package/dist-standalone/agent-call.js +642 -0
- package/dist-standalone/agent-sdk.d.ts +207 -0
- package/dist-standalone/agent-sdk.js +328 -0
- package/dist-standalone/agent.d.ts +670 -0
- package/dist-standalone/agent.js +1529 -0
- package/dist-standalone/approval.d.ts +145 -0
- package/dist-standalone/approval.js +193 -0
- package/dist-standalone/auth.d.ts +75 -0
- package/dist-standalone/auth.js +219 -0
- package/dist-standalone/auto-accept.d.ts +102 -0
- package/dist-standalone/auto-accept.js +229 -0
- package/dist-standalone/backup-config.d.ts +150 -0
- package/dist-standalone/backup-config.js +201 -0
- package/dist-standalone/checkpoint.d.ts +125 -0
- package/dist-standalone/checkpoint.js +186 -0
- package/dist-standalone/cjs/agent-call.js +651 -0
- package/dist-standalone/cjs/agent-sdk.js +332 -0
- package/dist-standalone/cjs/agent.js +1566 -0
- package/dist-standalone/cjs/approval.js +199 -0
- package/dist-standalone/cjs/auth.js +225 -0
- package/dist-standalone/cjs/auto-accept.js +233 -0
- package/dist-standalone/cjs/backup-config.js +207 -0
- package/dist-standalone/cjs/checkpoint.js +193 -0
- package/dist-standalone/cjs/cli/init.js +487 -0
- package/dist-standalone/cjs/connect.js +312 -0
- package/dist-standalone/cjs/did-document.js +101 -0
- package/dist-standalone/cjs/did-privateme.js +130 -0
- package/dist-standalone/cjs/did-web.js +201 -0
- package/dist-standalone/cjs/discovery.js +462 -0
- package/dist-standalone/cjs/dual-mode.js +251 -0
- package/dist-standalone/cjs/email-templates.js +313 -0
- package/dist-standalone/cjs/email-transport.js +239 -0
- package/dist-standalone/cjs/envelope.js +510 -0
- package/dist-standalone/cjs/errors.js +562 -0
- package/dist-standalone/cjs/gateway-state.js +55 -0
- package/dist-standalone/cjs/gateway-transport.js +120 -0
- package/dist-standalone/cjs/guardrails.js +223 -0
- package/dist-standalone/cjs/http-compat.js +272 -0
- package/dist-standalone/cjs/identity.js +541 -0
- package/dist-standalone/cjs/index.js +224 -0
- package/dist-standalone/cjs/invitation.js +421 -0
- package/dist-standalone/cjs/invite.js +328 -0
- package/dist-standalone/cjs/key-agreement.js +246 -0
- package/dist-standalone/cjs/lazy-init.js +300 -0
- package/dist-standalone/cjs/mdns-discovery.js +202 -0
- package/dist-standalone/cjs/nonce-store.js +66 -0
- package/dist-standalone/cjs/package.json +3 -0
- package/dist-standalone/cjs/pairing-manager.js +223 -0
- package/dist-standalone/cjs/policy.js +320 -0
- package/dist-standalone/cjs/redis-nonce-store.js +76 -0
- package/dist-standalone/cjs/registry-middleware.js +50 -0
- package/dist-standalone/cjs/retry-transport.js +102 -0
- package/dist-standalone/cjs/security-policy.js +204 -0
- package/dist-standalone/cjs/split-channel.js +177 -0
- package/dist-standalone/cjs/subscription-proof.js +230 -0
- package/dist-standalone/cjs/succession.js +148 -0
- package/dist-standalone/cjs/transport.js +63 -0
- package/dist-standalone/cjs/trust-registry.js +742 -0
- package/dist-standalone/cjs/verify.js +25 -0
- package/dist-standalone/cjs/xfetch.js +252 -0
- package/dist-standalone/cli/init.d.ts +63 -0
- package/dist-standalone/cli/init.js +450 -0
- package/dist-standalone/connect.d.ts +143 -0
- package/dist-standalone/connect.js +274 -0
- package/dist-standalone/did-document.d.ts +65 -0
- package/dist-standalone/did-document.js +96 -0
- package/dist-standalone/did-privateme.d.ts +70 -0
- package/dist-standalone/did-privateme.js +121 -0
- package/dist-standalone/did-web.d.ts +73 -0
- package/dist-standalone/did-web.js +196 -0
- package/dist-standalone/discovery.d.ts +176 -0
- package/dist-standalone/discovery.js +458 -0
- package/dist-standalone/dual-mode.d.ts +145 -0
- package/dist-standalone/dual-mode.js +247 -0
- package/dist-standalone/email-templates.d.ts +41 -0
- package/dist-standalone/email-templates.js +309 -0
- package/dist-standalone/email-transport.d.ts +139 -0
- package/dist-standalone/email-transport.js +232 -0
- package/dist-standalone/envelope.d.ts +288 -0
- package/dist-standalone/envelope.js +497 -0
- package/dist-standalone/errors.d.ts +74 -0
- package/dist-standalone/errors.js +548 -0
- package/dist-standalone/gateway-state.d.ts +32 -0
- package/dist-standalone/gateway-state.js +51 -0
- package/dist-standalone/gateway-transport.d.ts +59 -0
- package/dist-standalone/gateway-transport.js +116 -0
- package/dist-standalone/guardrails.d.ts +136 -0
- package/dist-standalone/guardrails.js +216 -0
- package/dist-standalone/http-compat.d.ts +150 -0
- package/dist-standalone/http-compat.js +267 -0
- package/dist-standalone/identity.d.ts +176 -0
- package/dist-standalone/identity.js +516 -0
- package/dist-standalone/index.d.ts +83 -0
- package/dist-standalone/index.js +51 -0
- package/dist-standalone/invitation.d.ts +211 -0
- package/dist-standalone/invitation.js +415 -0
- package/dist-standalone/invite.d.ts +192 -0
- package/dist-standalone/invite.js +324 -0
- package/dist-standalone/key-agreement.d.ts +122 -0
- package/dist-standalone/key-agreement.js +236 -0
- package/dist-standalone/lazy-init.d.ts +167 -0
- package/dist-standalone/lazy-init.js +295 -0
- package/dist-standalone/mdns-discovery.d.ts +117 -0
- package/dist-standalone/mdns-discovery.js +195 -0
- package/dist-standalone/nonce-store.d.ts +39 -0
- package/dist-standalone/nonce-store.js +62 -0
- package/dist-standalone/package.json +11 -0
- package/dist-standalone/pairing-manager.d.ts +147 -0
- package/dist-standalone/pairing-manager.js +219 -0
- package/dist-standalone/policy.d.ts +150 -0
- package/dist-standalone/policy.js +315 -0
- package/dist-standalone/redis-nonce-store.d.ts +93 -0
- package/dist-standalone/redis-nonce-store.js +72 -0
- package/dist-standalone/registry-middleware.d.ts +38 -0
- package/dist-standalone/registry-middleware.js +47 -0
- package/dist-standalone/retry-transport.d.ts +76 -0
- package/dist-standalone/retry-transport.js +98 -0
- package/dist-standalone/security-policy.d.ts +146 -0
- package/dist-standalone/security-policy.js +198 -0
- package/dist-standalone/split-channel.d.ts +69 -0
- package/dist-standalone/split-channel.js +171 -0
- package/dist-standalone/subscription-proof.d.ts +103 -0
- package/dist-standalone/subscription-proof.js +224 -0
- package/dist-standalone/succession.d.ts +57 -0
- package/dist-standalone/succession.js +142 -0
- package/dist-standalone/transport.d.ts +50 -0
- package/dist-standalone/transport.js +59 -0
- package/dist-standalone/trust-registry.d.ts +286 -0
- package/dist-standalone/trust-registry.js +702 -0
- package/dist-standalone/verify.d.ts +16 -0
- package/dist-standalone/verify.js +16 -0
- package/dist-standalone/xfetch.d.ts +129 -0
- package/dist-standalone/xfetch.js +247 -0
- package/llms.txt +800 -0
- package/package.json +79 -0
- package/share1.dat +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { Result } from '@private.me/shared';
|
|
2
|
+
/** Error codes for checkpoint operations. */
|
|
3
|
+
export type CheckpointError = 'SIGN_FAILED' | 'VERIFY_FAILED' | 'INVALID_FORMAT' | 'INVALID_TIMESTAMP' | 'INVALID_SIGNATURE' | 'STALE_CACHE';
|
|
4
|
+
/**
|
|
5
|
+
* Gateway-signed DID state checkpoint (freshness primitive).
|
|
6
|
+
*
|
|
7
|
+
* Checkpoints provide cryptographic proof of DID state at a specific timestamp.
|
|
8
|
+
* Clients compare checkpoint rotation_sequence against local cache to detect staleness.
|
|
9
|
+
*
|
|
10
|
+
* Format:
|
|
11
|
+
* - subject: DID being checkpointed
|
|
12
|
+
* - current_public_key: Current public key (base64)
|
|
13
|
+
* - revoked: Revocation status
|
|
14
|
+
* - rotation_sequence: Monotonic counter from succession events
|
|
15
|
+
* - timestamp: Unix milliseconds when checkpoint was created
|
|
16
|
+
* - checkpoint_signature: ML-DSA-65 signature from gateway key
|
|
17
|
+
*/
|
|
18
|
+
export interface DIDStateCheckpoint {
|
|
19
|
+
readonly type: 'DIDStateCheckpoint';
|
|
20
|
+
readonly version: '1.0';
|
|
21
|
+
readonly subject: string;
|
|
22
|
+
readonly current_public_key: string;
|
|
23
|
+
readonly revoked: boolean;
|
|
24
|
+
readonly rotation_sequence: number;
|
|
25
|
+
readonly timestamp: number;
|
|
26
|
+
readonly checkpoint_signature_algorithm: 'ML-DSA-65';
|
|
27
|
+
readonly checkpoint_signature: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Local cache entry for DID state.
|
|
31
|
+
* Used for staleness detection against signed checkpoints.
|
|
32
|
+
*/
|
|
33
|
+
export interface LocalDIDCache {
|
|
34
|
+
readonly did: string;
|
|
35
|
+
readonly publicKey: Uint8Array;
|
|
36
|
+
readonly revoked: boolean;
|
|
37
|
+
readonly rotationSequence: number;
|
|
38
|
+
readonly cachedAt: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a signed checkpoint for a DID (gateway-side operation).
|
|
42
|
+
*
|
|
43
|
+
* Gateway signs the DID state snapshot using its ML-DSA-65 private key.
|
|
44
|
+
* Clients verify this signature using the gateway's published public key.
|
|
45
|
+
*
|
|
46
|
+
* @param subject - DID being checkpointed
|
|
47
|
+
* @param publicKey - Current public key bytes
|
|
48
|
+
* @param revoked - Current revocation status
|
|
49
|
+
* @param rotationSequence - Current rotation sequence counter
|
|
50
|
+
* @param gatewayPrivateKey - Gateway's ML-DSA-65 secret key (32-byte seed or 4032-byte expanded)
|
|
51
|
+
* @returns Signed checkpoint or error
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const checkpoint = await createCheckpoint(
|
|
56
|
+
* 'did:key:z6Mk...',
|
|
57
|
+
* publicKeyBytes,
|
|
58
|
+
* false,
|
|
59
|
+
* 5,
|
|
60
|
+
* gatewaySecretKey
|
|
61
|
+
* );
|
|
62
|
+
* if (checkpoint.ok) {
|
|
63
|
+
* // Send checkpoint to client for staleness detection
|
|
64
|
+
* sendToClient(checkpoint.value);
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function createCheckpoint(subject: string, publicKey: Uint8Array, revoked: boolean, rotationSequence: number, gatewayPrivateKey: Uint8Array): Promise<Result<DIDStateCheckpoint, CheckpointError>>;
|
|
69
|
+
/**
|
|
70
|
+
* Verify a checkpoint signature (client-side operation).
|
|
71
|
+
*
|
|
72
|
+
* Clients MUST verify checkpoint signatures before trusting the state.
|
|
73
|
+
* Uses gateway's published ML-DSA-65 public key to verify signature.
|
|
74
|
+
*
|
|
75
|
+
* @param checkpoint - Checkpoint to verify
|
|
76
|
+
* @param gatewayPublicKey - Gateway's ML-DSA-65 public key (1952 bytes)
|
|
77
|
+
* @returns true if signature valid, false if invalid, error if verification fails
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const valid = await verifyCheckpoint(checkpoint, gatewayPubKey);
|
|
82
|
+
* if (valid.ok && valid.value) {
|
|
83
|
+
* // Checkpoint is authentic - safe to use for staleness detection
|
|
84
|
+
* if (isCacheStale(localCache, checkpoint)) {
|
|
85
|
+
* // Refresh local cache
|
|
86
|
+
* }
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function verifyCheckpoint(checkpoint: DIDStateCheckpoint, gatewayPublicKey: Uint8Array): Promise<Result<boolean, CheckpointError>>;
|
|
91
|
+
/**
|
|
92
|
+
* Detect if local cache is stale compared to gateway checkpoint.
|
|
93
|
+
*
|
|
94
|
+
* Cache is stale if:
|
|
95
|
+
* 1. Checkpoint rotation_sequence > local rotationSequence (key rotated)
|
|
96
|
+
* 2. Checkpoint revoked !== local revoked (revocation status changed)
|
|
97
|
+
* 3. Checkpoint public key !== local publicKey (state drift)
|
|
98
|
+
*
|
|
99
|
+
* @param localCache - Local cache entry for DID
|
|
100
|
+
* @param checkpoint - Verified checkpoint from gateway
|
|
101
|
+
* @returns true if cache needs refresh, false if cache is current
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* if (isCacheStale(localCache, checkpoint)) {
|
|
106
|
+
* // Local cache is outdated - fetch fresh state from gateway
|
|
107
|
+
* const freshState = await registry.getEntry(did);
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function isCacheStale(localCache: LocalDIDCache, checkpoint: DIDStateCheckpoint): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Encode checkpoint to JSON string for wire transport.
|
|
114
|
+
*
|
|
115
|
+
* @param checkpoint - Checkpoint to encode
|
|
116
|
+
* @returns JSON string
|
|
117
|
+
*/
|
|
118
|
+
export declare function encodeCheckpoint(checkpoint: DIDStateCheckpoint): string;
|
|
119
|
+
/**
|
|
120
|
+
* Decode checkpoint from JSON string.
|
|
121
|
+
*
|
|
122
|
+
* @param encoded - JSON string
|
|
123
|
+
* @returns Parsed checkpoint or error
|
|
124
|
+
*/
|
|
125
|
+
export declare function decodeCheckpoint(encoded: string): Result<DIDStateCheckpoint, CheckpointError>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { ok, err } from"./_deps/shared/index.js";
|
|
2
|
+
import { signMlDsa65, verifyMlDsa65 } from './identity.js';
|
|
3
|
+
/* ── Checkpoint Creation (Gateway-side) ── */
|
|
4
|
+
/**
|
|
5
|
+
* Create a signed checkpoint for a DID (gateway-side operation).
|
|
6
|
+
*
|
|
7
|
+
* Gateway signs the DID state snapshot using its ML-DSA-65 private key.
|
|
8
|
+
* Clients verify this signature using the gateway's published public key.
|
|
9
|
+
*
|
|
10
|
+
* @param subject - DID being checkpointed
|
|
11
|
+
* @param publicKey - Current public key bytes
|
|
12
|
+
* @param revoked - Current revocation status
|
|
13
|
+
* @param rotationSequence - Current rotation sequence counter
|
|
14
|
+
* @param gatewayPrivateKey - Gateway's ML-DSA-65 secret key (32-byte seed or 4032-byte expanded)
|
|
15
|
+
* @returns Signed checkpoint or error
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const checkpoint = await createCheckpoint(
|
|
20
|
+
* 'did:key:z6Mk...',
|
|
21
|
+
* publicKeyBytes,
|
|
22
|
+
* false,
|
|
23
|
+
* 5,
|
|
24
|
+
* gatewaySecretKey
|
|
25
|
+
* );
|
|
26
|
+
* if (checkpoint.ok) {
|
|
27
|
+
* // Send checkpoint to client for staleness detection
|
|
28
|
+
* sendToClient(checkpoint.value);
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export async function createCheckpoint(subject, publicKey, revoked, rotationSequence, gatewayPrivateKey) {
|
|
33
|
+
const timestamp = Date.now();
|
|
34
|
+
// Construct canonical message to sign
|
|
35
|
+
const publicKeyB64 = Buffer.from(publicKey).toString('base64');
|
|
36
|
+
const message = `DIDStateCheckpoint||1.0||${subject}||${publicKeyB64}||${revoked}||${rotationSequence}||${timestamp}`;
|
|
37
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
38
|
+
// Sign using gateway's ML-DSA-65 key
|
|
39
|
+
const sigResult = await signMlDsa65(gatewayPrivateKey, messageBytes);
|
|
40
|
+
if (!sigResult.ok) {
|
|
41
|
+
return err('SIGN_FAILED');
|
|
42
|
+
}
|
|
43
|
+
return ok({
|
|
44
|
+
type: 'DIDStateCheckpoint',
|
|
45
|
+
version: '1.0',
|
|
46
|
+
subject,
|
|
47
|
+
current_public_key: publicKeyB64,
|
|
48
|
+
revoked,
|
|
49
|
+
rotation_sequence: rotationSequence,
|
|
50
|
+
timestamp,
|
|
51
|
+
checkpoint_signature_algorithm: 'ML-DSA-65',
|
|
52
|
+
checkpoint_signature: Buffer.from(sigResult.value).toString('base64')
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/* ── Checkpoint Verification (Client-side) ── */
|
|
56
|
+
/**
|
|
57
|
+
* Verify a checkpoint signature (client-side operation).
|
|
58
|
+
*
|
|
59
|
+
* Clients MUST verify checkpoint signatures before trusting the state.
|
|
60
|
+
* Uses gateway's published ML-DSA-65 public key to verify signature.
|
|
61
|
+
*
|
|
62
|
+
* @param checkpoint - Checkpoint to verify
|
|
63
|
+
* @param gatewayPublicKey - Gateway's ML-DSA-65 public key (1952 bytes)
|
|
64
|
+
* @returns true if signature valid, false if invalid, error if verification fails
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const valid = await verifyCheckpoint(checkpoint, gatewayPubKey);
|
|
69
|
+
* if (valid.ok && valid.value) {
|
|
70
|
+
* // Checkpoint is authentic - safe to use for staleness detection
|
|
71
|
+
* if (isCacheStale(localCache, checkpoint)) {
|
|
72
|
+
* // Refresh local cache
|
|
73
|
+
* }
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export async function verifyCheckpoint(checkpoint, gatewayPublicKey) {
|
|
78
|
+
// Validate checkpoint format
|
|
79
|
+
if (checkpoint.type !== 'DIDStateCheckpoint') {
|
|
80
|
+
return err('INVALID_FORMAT');
|
|
81
|
+
}
|
|
82
|
+
if (checkpoint.version !== '1.0') {
|
|
83
|
+
return err('INVALID_FORMAT');
|
|
84
|
+
}
|
|
85
|
+
if (!checkpoint.subject || !checkpoint.current_public_key) {
|
|
86
|
+
return err('INVALID_FORMAT');
|
|
87
|
+
}
|
|
88
|
+
if (typeof checkpoint.rotation_sequence !== 'number' || checkpoint.rotation_sequence < 0) {
|
|
89
|
+
return err('INVALID_FORMAT');
|
|
90
|
+
}
|
|
91
|
+
if (typeof checkpoint.timestamp !== 'number' || checkpoint.timestamp <= 0) {
|
|
92
|
+
return err('INVALID_TIMESTAMP');
|
|
93
|
+
}
|
|
94
|
+
if (checkpoint.checkpoint_signature_algorithm !== 'ML-DSA-65') {
|
|
95
|
+
return err('INVALID_FORMAT');
|
|
96
|
+
}
|
|
97
|
+
// Reconstruct canonical message
|
|
98
|
+
const message = `DIDStateCheckpoint||1.0||${checkpoint.subject}||${checkpoint.current_public_key}||${checkpoint.revoked}||${checkpoint.rotation_sequence}||${checkpoint.timestamp}`;
|
|
99
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
100
|
+
// Decode signature
|
|
101
|
+
let signature;
|
|
102
|
+
try {
|
|
103
|
+
signature = Buffer.from(checkpoint.checkpoint_signature, 'base64');
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return err('INVALID_SIGNATURE');
|
|
107
|
+
}
|
|
108
|
+
// Verify signature using gateway public key
|
|
109
|
+
const verifyResult = await verifyMlDsa65(gatewayPublicKey, signature, messageBytes);
|
|
110
|
+
if (!verifyResult.ok) {
|
|
111
|
+
return err('VERIFY_FAILED');
|
|
112
|
+
}
|
|
113
|
+
return ok(verifyResult.value);
|
|
114
|
+
}
|
|
115
|
+
/* ── Staleness Detection ── */
|
|
116
|
+
/**
|
|
117
|
+
* Detect if local cache is stale compared to gateway checkpoint.
|
|
118
|
+
*
|
|
119
|
+
* Cache is stale if:
|
|
120
|
+
* 1. Checkpoint rotation_sequence > local rotationSequence (key rotated)
|
|
121
|
+
* 2. Checkpoint revoked !== local revoked (revocation status changed)
|
|
122
|
+
* 3. Checkpoint public key !== local publicKey (state drift)
|
|
123
|
+
*
|
|
124
|
+
* @param localCache - Local cache entry for DID
|
|
125
|
+
* @param checkpoint - Verified checkpoint from gateway
|
|
126
|
+
* @returns true if cache needs refresh, false if cache is current
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* if (isCacheStale(localCache, checkpoint)) {
|
|
131
|
+
* // Local cache is outdated - fetch fresh state from gateway
|
|
132
|
+
* const freshState = await registry.getEntry(did);
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export function isCacheStale(localCache, checkpoint) {
|
|
137
|
+
// Sequence number mismatch indicates key rotation
|
|
138
|
+
if (checkpoint.rotation_sequence > localCache.rotationSequence) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
// Revocation status changed
|
|
142
|
+
if (checkpoint.revoked !== localCache.revoked) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
// Public key mismatch indicates state drift
|
|
146
|
+
const checkpointPubKey = Buffer.from(checkpoint.current_public_key, 'base64');
|
|
147
|
+
if (!Buffer.from(localCache.publicKey).equals(checkpointPubKey)) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
/* ── Encoding/Decoding ── */
|
|
153
|
+
/**
|
|
154
|
+
* Encode checkpoint to JSON string for wire transport.
|
|
155
|
+
*
|
|
156
|
+
* @param checkpoint - Checkpoint to encode
|
|
157
|
+
* @returns JSON string
|
|
158
|
+
*/
|
|
159
|
+
export function encodeCheckpoint(checkpoint) {
|
|
160
|
+
return JSON.stringify(checkpoint);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Decode checkpoint from JSON string.
|
|
164
|
+
*
|
|
165
|
+
* @param encoded - JSON string
|
|
166
|
+
* @returns Parsed checkpoint or error
|
|
167
|
+
*/
|
|
168
|
+
export function decodeCheckpoint(encoded) {
|
|
169
|
+
try {
|
|
170
|
+
const parsed = JSON.parse(encoded);
|
|
171
|
+
// Basic validation
|
|
172
|
+
if (parsed.type !== 'DIDStateCheckpoint') {
|
|
173
|
+
return err('INVALID_FORMAT');
|
|
174
|
+
}
|
|
175
|
+
if (parsed.version !== '1.0') {
|
|
176
|
+
return err('INVALID_FORMAT');
|
|
177
|
+
}
|
|
178
|
+
if (!parsed.subject || !parsed.current_public_key || !parsed.checkpoint_signature) {
|
|
179
|
+
return err('INVALID_FORMAT');
|
|
180
|
+
}
|
|
181
|
+
return ok(parsed);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return err('INVALID_FORMAT');
|
|
185
|
+
}
|
|
186
|
+
}
|