@private.me/xbind 3.0.0 → 3.0.2
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/README.md +55 -7
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -1
- package/dist-standalone/_deps/shared/cjs/errors.js +729 -1
- package/dist-standalone/_deps/shared/cjs/index.js +463 -1
- package/dist-standalone/_deps/shared/cjs/types.js +315 -1
- package/dist-standalone/_deps/shared/errors.js +244 -1
- package/dist-standalone/_deps/shared/index.js +72 -1
- package/dist-standalone/_deps/shared/types.js +86 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
- package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/search.js +1 -1
- package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
- package/dist-standalone/_deps/xchange/errors.js +1 -1
- package/dist-standalone/_deps/xchange/index.js +1 -1
- package/dist-standalone/_deps/xchange/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/xchange.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
- package/dist-standalone/_deps/xregistry/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/index.js +1 -1
- package/dist-standalone/_deps/xregistry/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/types.js +1 -1
- package/dist-standalone/agent-call.js +659 -1
- package/dist-standalone/agent-sdk.js +328 -1
- package/dist-standalone/agent.js +1800 -1
- package/dist-standalone/approval.js +193 -1
- package/dist-standalone/async-iterators.js +382 -1
- package/dist-standalone/auth.js +219 -1
- package/dist-standalone/auto-accept.js +229 -1
- package/dist-standalone/backup-config.js +201 -1
- package/dist-standalone/backup.js +326 -1
- package/dist-standalone/batch-operations.js +388 -1
- package/dist-standalone/cancellation.js +477 -1
- package/dist-standalone/checkpoint.js +186 -1
- package/dist-standalone/circuit-breaker.js +468 -1
- package/dist-standalone/cjs/agent-call.js +701 -1
- package/dist-standalone/cjs/agent-sdk.js +332 -1
- package/dist-standalone/cjs/agent.js +1837 -1
- package/dist-standalone/cjs/approval.js +199 -1
- package/dist-standalone/cjs/async-iterators.js +392 -1
- package/dist-standalone/cjs/auth.js +225 -1
- package/dist-standalone/cjs/auto-accept.js +233 -1
- package/dist-standalone/cjs/backup-config.js +207 -1
- package/dist-standalone/cjs/backup.js +330 -1
- package/dist-standalone/cjs/batch-operations.js +397 -1
- package/dist-standalone/cjs/cancellation.js +490 -1
- package/dist-standalone/cjs/checkpoint.js +193 -1
- package/dist-standalone/cjs/circuit-breaker.js +476 -1
- package/dist-standalone/cjs/cli/init.js +492 -1
- package/dist-standalone/cjs/config-validation.js +522 -1
- package/dist-standalone/cjs/connect.js +312 -1
- package/dist-standalone/cjs/connection-pool.js +506 -1
- package/dist-standalone/cjs/correlation-id.js +339 -1
- package/dist-standalone/cjs/crypto-utils.js +176 -1
- package/dist-standalone/cjs/debug-mode.js +534 -1
- package/dist-standalone/cjs/did-document.js +101 -1
- package/dist-standalone/cjs/did-privateme.js +130 -1
- package/dist-standalone/cjs/did-web.js +201 -1
- package/dist-standalone/cjs/discovery.js +462 -1
- package/dist-standalone/cjs/dual-mode.js +251 -1
- package/dist-standalone/cjs/email-templates.js +313 -1
- package/dist-standalone/cjs/email-transport.js +239 -1
- package/dist-standalone/cjs/envelope.js +538 -1
- package/dist-standalone/cjs/errors.js +913 -1
- package/dist-standalone/cjs/event-emitter.js +461 -1
- package/dist-standalone/cjs/gateway-state.js +55 -1
- package/dist-standalone/cjs/gateway-transport.js +120 -1
- package/dist-standalone/cjs/graceful-degradation.js +403 -1
- package/dist-standalone/cjs/guardrails.js +223 -1
- package/dist-standalone/cjs/health-check.js +336 -1
- package/dist-standalone/cjs/http-compat.js +272 -1
- package/dist-standalone/cjs/http-status-map.js +571 -1
- package/dist-standalone/cjs/identity.js +645 -1
- package/dist-standalone/cjs/index.js +406 -1
- package/dist-standalone/cjs/invitation.js +421 -1
- package/dist-standalone/cjs/invite.js +328 -1
- package/dist-standalone/cjs/key-agreement.js +335 -1
- package/dist-standalone/cjs/lazy-init.js +300 -1
- package/dist-standalone/cjs/logger.js +291 -1
- package/dist-standalone/cjs/mdns-discovery.js +202 -1
- package/dist-standalone/cjs/nonce-store.js +80 -1
- package/dist-standalone/cjs/pairing-manager.js +223 -1
- package/dist-standalone/cjs/plugin-system.js +264 -1
- package/dist-standalone/cjs/plugins/logging.js +168 -1
- package/dist-standalone/cjs/plugins/metrics.js +181 -1
- package/dist-standalone/cjs/plugins/validation.js +302 -1
- package/dist-standalone/cjs/policy.js +320 -1
- package/dist-standalone/cjs/progress-callbacks.js +583 -1
- package/dist-standalone/cjs/redis-nonce-store.js +76 -1
- package/dist-standalone/cjs/registry-middleware.js +50 -1
- package/dist-standalone/cjs/retry-strategies.js +544 -1
- package/dist-standalone/cjs/retry-transport.js +102 -1
- package/dist-standalone/cjs/runtime/browser.js +533 -1
- package/dist-standalone/cjs/runtime/edge.js +526 -1
- package/dist-standalone/cjs/runtime/react-native.js +394 -1
- package/dist-standalone/cjs/security-policy.js +245 -1
- package/dist-standalone/cjs/serialization.js +1040 -1
- package/dist-standalone/cjs/split-channel.js +225 -1
- package/dist-standalone/cjs/subscription-proof.js +230 -1
- package/dist-standalone/cjs/succession.js +148 -1
- package/dist-standalone/cjs/timeouts.js +412 -1
- package/dist-standalone/cjs/trace-context.js +424 -1
- package/dist-standalone/cjs/trace-spans.js +495 -1
- package/dist-standalone/cjs/transport.js +63 -1
- package/dist-standalone/cjs/trust-registry.js +991 -1
- package/dist-standalone/cjs/types/error-response.js +56 -1
- package/dist-standalone/cjs/vault-auth.js +178 -1
- package/dist-standalone/cjs/vault-store-loader.js +194 -1
- package/dist-standalone/cjs/verify.js +25 -1
- package/dist-standalone/cjs/version-info.js +543 -1
- package/dist-standalone/cjs/xfetch.js +340 -1
- package/dist-standalone/cli/init.js +455 -1
- package/dist-standalone/cli/setup.js +514 -1
- package/dist-standalone/cli/types.js +27 -1
- package/dist-standalone/cli/xbind.js +148 -1
- package/dist-standalone/config-validation.js +513 -1
- package/dist-standalone/connect.js +274 -1
- package/dist-standalone/connection-pool.js +500 -1
- package/dist-standalone/correlation-id.js +326 -1
- package/dist-standalone/crypto-utils.js +157 -1
- package/dist-standalone/debug-mode.js +510 -1
- package/dist-standalone/did-document.js +96 -1
- package/dist-standalone/did-privateme.js +121 -1
- package/dist-standalone/did-web.js +196 -1
- package/dist-standalone/discovery.js +458 -1
- package/dist-standalone/dual-mode.js +247 -1
- package/dist-standalone/email-templates.js +309 -1
- package/dist-standalone/email-transport.js +232 -1
- package/dist-standalone/envelope.js +525 -1
- package/dist-standalone/errors.js +896 -1
- package/dist-standalone/event-emitter.js +456 -1
- package/dist-standalone/gateway-state.js +51 -1
- package/dist-standalone/gateway-transport.js +116 -1
- package/dist-standalone/graceful-degradation.js +396 -1
- package/dist-standalone/guardrails.js +216 -1
- package/dist-standalone/health-check.js +332 -1
- package/dist-standalone/http-compat.js +267 -1
- package/dist-standalone/http-status-map.js +561 -1
- package/dist-standalone/identity.js +619 -1
- package/dist-standalone/index.js +78 -1
- package/dist-standalone/invitation.js +415 -1
- package/dist-standalone/invite.js +324 -1
- package/dist-standalone/key-agreement.js +325 -1
- package/dist-standalone/lazy-init.js +295 -1
- package/dist-standalone/logger.js +285 -1
- package/dist-standalone/mdns-discovery.js +195 -1
- package/dist-standalone/nonce-store.js +76 -1
- package/dist-standalone/pairing-manager.js +219 -1
- package/dist-standalone/plugin-system.js +257 -1
- package/dist-standalone/plugins/logging.d.ts +84 -0
- package/dist-standalone/plugins/logging.js +163 -0
- package/dist-standalone/plugins/metrics.d.ts +111 -0
- package/dist-standalone/plugins/metrics.js +176 -0
- package/dist-standalone/plugins/validation.d.ts +104 -0
- package/dist-standalone/plugins/validation.js +297 -0
- package/dist-standalone/policy.js +315 -1
- package/dist-standalone/progress-callbacks.js +576 -1
- package/dist-standalone/redis-nonce-store.js +72 -1
- package/dist-standalone/registry-middleware.js +47 -1
- package/dist-standalone/retry-strategies.js +534 -1
- package/dist-standalone/retry-transport.js +98 -1
- package/dist-standalone/runtime/browser.d.ts +311 -0
- package/dist-standalone/runtime/browser.js +516 -0
- package/dist-standalone/runtime/edge.d.ts +282 -0
- package/dist-standalone/runtime/edge.js +511 -0
- package/dist-standalone/runtime/react-native.d.ts +157 -0
- package/dist-standalone/runtime/react-native.js +383 -0
- package/dist-standalone/security-policy.js +239 -1
- package/dist-standalone/serialization.js +1031 -1
- package/dist-standalone/split-channel.js +219 -1
- package/dist-standalone/subscription-proof.js +224 -1
- package/dist-standalone/succession.js +142 -1
- package/dist-standalone/timeouts.js +398 -1
- package/dist-standalone/trace-context.js +414 -1
- package/dist-standalone/trace-spans.js +488 -1
- package/dist-standalone/transport.js +59 -1
- package/dist-standalone/trust-registry.js +950 -1
- package/dist-standalone/types/error-response.d.ts +209 -0
- package/dist-standalone/types/error-response.js +52 -0
- package/dist-standalone/vault-auth.js +174 -1
- package/dist-standalone/vault-store-loader.js +187 -1
- package/dist-standalone/verify.js +16 -1
- package/dist-standalone/version-info.js +530 -1
- package/dist-standalone/xfetch.js +335 -1
- package/package.json +4 -10
- package/share1.dat +0 -0
- package/dist-standalone/_deps/mldsa-wasm/LICENSE +0 -24
- package/dist-standalone/_deps/mldsa-wasm/package.json +0 -46
- package/dist-standalone/_deps/shared/cjs/package.json +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/package.json +0 -1
- package/dist-standalone/_deps/xchange/cjs/package.json +0 -1
- package/dist-standalone/_deps/xregistry/cjs/package.json +0 -1
- package/dist-standalone/cjs/package.json +0 -3
- package/dist-standalone/package.json +0 -10
|
@@ -1 +1,225 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* XorIDA split-channel bridge for @private.me/xbind.
|
|
4
|
+
*
|
|
5
|
+
* Bridges @private.me/crypto threshold sharing with the agent-sdk
|
|
6
|
+
* TransportEnvelope format. Splits plaintext into n shares with HMAC
|
|
7
|
+
* integrity, each share wrapped in its own envelope for independent routing.
|
|
8
|
+
*
|
|
9
|
+
* Pipeline:
|
|
10
|
+
* split: pad -> HMAC -> XorIDA split -> share Uint8Arrays with metadata
|
|
11
|
+
* reconstruct: collect k shares -> XorIDA reconstruct -> HMAC verify -> unpad
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.DEFAULT_SPLIT_CONFIG = void 0;
|
|
15
|
+
exports.splitForChannel = splitForChannel;
|
|
16
|
+
exports.splitForChannelWithGroupId = splitForChannelWithGroupId;
|
|
17
|
+
exports.reconstructFromChannel = reconstructFromChannel;
|
|
18
|
+
const shared_1 = require("../_deps/shared/index.js");
|
|
19
|
+
const crypto_utils_js_1 = require("./crypto-utils.js");
|
|
20
|
+
/** Default split-channel configuration: 3 shares, threshold 2. */
|
|
21
|
+
exports.DEFAULT_SPLIT_CONFIG = {
|
|
22
|
+
totalShares: 3,
|
|
23
|
+
threshold: 2,
|
|
24
|
+
};
|
|
25
|
+
/* ── Split ── */
|
|
26
|
+
/**
|
|
27
|
+
* Split plaintext into n shares via XorIDA with HMAC integrity.
|
|
28
|
+
*
|
|
29
|
+
* Pipeline: pad(PKCS#7) -> HMAC(padded) -> XorIDA split -> ChannelShare[]
|
|
30
|
+
*
|
|
31
|
+
* Information-theoretic security: Any k shares can reconstruct the plaintext,
|
|
32
|
+
* but k-1 shares reveal ZERO information (proven secure).
|
|
33
|
+
*
|
|
34
|
+
* @param plaintext - Raw plaintext bytes to split
|
|
35
|
+
* @param config - Split configuration (totalShares, threshold)
|
|
36
|
+
* @returns Array of n ChannelShare objects ready for envelope wrapping
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import { splitForChannel, DEFAULT_SPLIT_CONFIG } from '@private.me/xbind';
|
|
41
|
+
*
|
|
42
|
+
* const plaintext = new TextEncoder().encode('Sensitive data');
|
|
43
|
+
*
|
|
44
|
+
* // Default: 3 shares, need 2 to reconstruct
|
|
45
|
+
* const shares = await splitForChannel(plaintext);
|
|
46
|
+
* if (!shares.ok) throw new Error(shares.error);
|
|
47
|
+
*
|
|
48
|
+
* console.log('Created shares:', shares.value.length);
|
|
49
|
+
* // Send each share through different channels (email, SMS, push)
|
|
50
|
+
* shares.value.forEach((share, i) => {
|
|
51
|
+
* console.log(`Share ${i}: ${share.groupId}`);
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Custom configuration: 5 shares, need 3
|
|
55
|
+
* const customShares = await splitForChannel(plaintext, {
|
|
56
|
+
* totalShares: 5,
|
|
57
|
+
* threshold: 3
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
async function splitForChannel(plaintext, config = exports.DEFAULT_SPLIT_CONFIG) {
|
|
62
|
+
const { totalShares: n, threshold: k } = config;
|
|
63
|
+
if (n < 2 || k < 2 || k > n) {
|
|
64
|
+
return (0, shared_1.err)('SPLIT_FAILED:INVALID_PARAMS');
|
|
65
|
+
}
|
|
66
|
+
const groupId = (0, crypto_utils_js_1.generateUUID)();
|
|
67
|
+
return splitForChannelWithGroupId(plaintext, config, groupId);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Split plaintext with a specific groupId (for testability).
|
|
71
|
+
*
|
|
72
|
+
* @param plaintext - Raw plaintext bytes
|
|
73
|
+
* @param config - Split configuration
|
|
74
|
+
* @param groupId - UUID to use for the share group
|
|
75
|
+
* @returns Array of ChannelShare objects
|
|
76
|
+
*/
|
|
77
|
+
async function splitForChannelWithGroupId(plaintext, config, groupId) {
|
|
78
|
+
const { totalShares: n, threshold: k } = config;
|
|
79
|
+
if (n < 2 || k < 2 || k > n) {
|
|
80
|
+
return (0, shared_1.err)('SPLIT_FAILED:INVALID_PARAMS');
|
|
81
|
+
}
|
|
82
|
+
const p = (0, crypto_utils_js_1.nextOddPrime)(n);
|
|
83
|
+
const blockSize = p - 1;
|
|
84
|
+
const padded = (0, crypto_utils_js_1.pkcs7Pad)(plaintext, blockSize);
|
|
85
|
+
const { key: hmacKey, signature: hmacSig } = await (0, crypto_utils_js_1.generateHMAC)(padded);
|
|
86
|
+
let shareArrays;
|
|
87
|
+
try {
|
|
88
|
+
shareArrays = (0, crypto_utils_js_1.splitXorIDA)(padded, n, k);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return (0, shared_1.err)('SPLIT_FAILED');
|
|
92
|
+
}
|
|
93
|
+
const hmacKeyB64 = (0, crypto_utils_js_1.toBase64)(hmacKey);
|
|
94
|
+
const hmacSigB64 = (0, crypto_utils_js_1.toBase64)(hmacSig);
|
|
95
|
+
const shares = shareArrays.map((data, index) => ({
|
|
96
|
+
data: (0, crypto_utils_js_1.formatShareHeader)((0, crypto_utils_js_1.toBase64)(data)),
|
|
97
|
+
index,
|
|
98
|
+
total: n,
|
|
99
|
+
threshold: k,
|
|
100
|
+
groupId,
|
|
101
|
+
hmacKey: hmacKeyB64,
|
|
102
|
+
hmacSig: hmacSigB64,
|
|
103
|
+
}));
|
|
104
|
+
return (0, shared_1.ok)(shares);
|
|
105
|
+
}
|
|
106
|
+
/* ── Reconstruct ── */
|
|
107
|
+
/**
|
|
108
|
+
* Reconstruct plaintext from k-of-n shares.
|
|
109
|
+
*
|
|
110
|
+
* Pipeline: validate -> XorIDA reconstruct -> HMAC verify -> unpad -> plaintext
|
|
111
|
+
* HMAC verification happens BEFORE the data is trusted.
|
|
112
|
+
*
|
|
113
|
+
* @param shares - Array of at least k ChannelShare objects (must have same groupId)
|
|
114
|
+
* @returns Reconstructed plaintext bytes
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* import { reconstructFromChannel, type ChannelShare } from '@private.me/xbind';
|
|
119
|
+
*
|
|
120
|
+
* // Collect shares from different channels
|
|
121
|
+
* const receivedShares: ChannelShare[] = [
|
|
122
|
+
* emailShare, // Received via email
|
|
123
|
+
* smsShare, // Received via SMS
|
|
124
|
+
* // Only need 2 shares (threshold = 2)
|
|
125
|
+
* ];
|
|
126
|
+
*
|
|
127
|
+
* // Reconstruct original message
|
|
128
|
+
* const plaintext = await reconstructFromChannel(receivedShares);
|
|
129
|
+
* if (!plaintext.ok) {
|
|
130
|
+
* console.error('Reconstruction failed:', plaintext.error);
|
|
131
|
+
* return;
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* const message = new TextDecoder().decode(plaintext.value);
|
|
135
|
+
* console.log('Reconstructed message:', message);
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
async function reconstructFromChannel(shares) {
|
|
139
|
+
const validationResult = validateShares(shares);
|
|
140
|
+
if (!validationResult.ok)
|
|
141
|
+
return validationResult;
|
|
142
|
+
const { k, n } = validationResult.value;
|
|
143
|
+
const usedShares = shares.slice(0, k);
|
|
144
|
+
return reconstructValidated(usedShares, n, k);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Validate share consistency before reconstruction.
|
|
148
|
+
*
|
|
149
|
+
* @param shares - Shares to validate
|
|
150
|
+
* @returns Validated parameters or error
|
|
151
|
+
*/
|
|
152
|
+
function validateShares(shares) {
|
|
153
|
+
if (shares.length === 0) {
|
|
154
|
+
return (0, shared_1.err)('INSUFFICIENT_SHARES');
|
|
155
|
+
}
|
|
156
|
+
const first = shares[0];
|
|
157
|
+
const k = first.threshold;
|
|
158
|
+
const n = first.total;
|
|
159
|
+
if (shares.length < k) {
|
|
160
|
+
return (0, shared_1.err)('INSUFFICIENT_SHARES');
|
|
161
|
+
}
|
|
162
|
+
const indexSet = new Set();
|
|
163
|
+
for (const share of shares) {
|
|
164
|
+
if (share.groupId !== first.groupId) {
|
|
165
|
+
return (0, shared_1.err)('INCONSISTENT_SHARES');
|
|
166
|
+
}
|
|
167
|
+
if (share.total !== n || share.threshold !== k) {
|
|
168
|
+
return (0, shared_1.err)('INCONSISTENT_SHARES');
|
|
169
|
+
}
|
|
170
|
+
if (share.index < 0 || share.index >= n) {
|
|
171
|
+
return (0, shared_1.err)('INVALID_SHARE_DATA');
|
|
172
|
+
}
|
|
173
|
+
if (indexSet.has(share.index)) {
|
|
174
|
+
return (0, shared_1.err)('INVALID_SHARE_DATA');
|
|
175
|
+
}
|
|
176
|
+
indexSet.add(share.index);
|
|
177
|
+
}
|
|
178
|
+
return (0, shared_1.ok)({ k, n, groupId: first.groupId });
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Perform XorIDA reconstruction and HMAC verification.
|
|
182
|
+
*
|
|
183
|
+
* @param usedShares - Exactly k validated shares
|
|
184
|
+
* @param n - Total shares
|
|
185
|
+
* @param k - Threshold
|
|
186
|
+
* @returns Reconstructed plaintext
|
|
187
|
+
*/
|
|
188
|
+
async function reconstructValidated(usedShares, n, k) {
|
|
189
|
+
let shareData;
|
|
190
|
+
try {
|
|
191
|
+
shareData = usedShares.map((s) => (0, crypto_utils_js_1.fromBase64)((0, crypto_utils_js_1.parseShareHeader)(s.data)));
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
return (0, shared_1.err)('INVALID_SHARE_DATA:BASE64');
|
|
195
|
+
}
|
|
196
|
+
const indices = usedShares.map((s) => s.index);
|
|
197
|
+
let padded;
|
|
198
|
+
try {
|
|
199
|
+
padded = (0, crypto_utils_js_1.reconstructXorIDA)(shareData, indices, n, k);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return (0, shared_1.err)('SPLIT_FAILED:RECONSTRUCT');
|
|
203
|
+
}
|
|
204
|
+
const first = usedShares[0];
|
|
205
|
+
let hmacKey;
|
|
206
|
+
let hmacSig;
|
|
207
|
+
try {
|
|
208
|
+
hmacKey = (0, crypto_utils_js_1.fromBase64)(first.hmacKey);
|
|
209
|
+
hmacSig = (0, crypto_utils_js_1.fromBase64)(first.hmacSig);
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return (0, shared_1.err)('INVALID_SHARE_DATA:HMAC_DECODE');
|
|
213
|
+
}
|
|
214
|
+
const hmacValid = await (0, crypto_utils_js_1.verifyHMAC)(hmacKey, padded, hmacSig);
|
|
215
|
+
if (!hmacValid) {
|
|
216
|
+
return (0, shared_1.err)('HMAC_VERIFICATION_FAILED');
|
|
217
|
+
}
|
|
218
|
+
const p = (0, crypto_utils_js_1.nextOddPrime)(n);
|
|
219
|
+
const blockSize = p - 1;
|
|
220
|
+
const unpadResult = (0, crypto_utils_js_1.pkcs7Unpad)(padded, blockSize);
|
|
221
|
+
if (!unpadResult.ok) {
|
|
222
|
+
return (0, shared_1.err)('UNPAD_FAILED');
|
|
223
|
+
}
|
|
224
|
+
return (0, shared_1.ok)(unpadResult.value);
|
|
225
|
+
}
|
|
@@ -1 +1,230 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSubscriptionProof = createSubscriptionProof;
|
|
4
|
+
exports.verifySubscriptionProof = verifySubscriptionProof;
|
|
5
|
+
exports.resumeSubscription = resumeSubscription;
|
|
6
|
+
exports.hashBloomFilter = hashBloomFilter;
|
|
7
|
+
const shared_1 = require("../_deps/shared/index.js");
|
|
8
|
+
const identity_js_1 = require("./identity.js");
|
|
9
|
+
/* ── Internal Helpers ── */
|
|
10
|
+
/**
|
|
11
|
+
* Compute SHA-256 hash of a Uint8Array.
|
|
12
|
+
*
|
|
13
|
+
* @param data - Data to hash.
|
|
14
|
+
* @returns Hex-encoded SHA-256 hash.
|
|
15
|
+
*/
|
|
16
|
+
async function sha256Hash(data) {
|
|
17
|
+
try {
|
|
18
|
+
// SAFETY: Creating fresh copy ensures proper ArrayBuffer type (not SharedArrayBuffer)
|
|
19
|
+
const buffer = new Uint8Array(data);
|
|
20
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', buffer);
|
|
21
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
22
|
+
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
23
|
+
return (0, shared_1.ok)(hashHex);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return (0, shared_1.err)('HASH_FAILED');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Serialize subscription proof data for signing (canonical format).
|
|
31
|
+
*
|
|
32
|
+
* Format: type|version|peer_did|bloom_filter_hash|asserted_at|expires_at
|
|
33
|
+
*
|
|
34
|
+
* @param proof - Subscription proof (without signature).
|
|
35
|
+
* @returns Canonical byte representation.
|
|
36
|
+
*/
|
|
37
|
+
function serializeForSigning(proof) {
|
|
38
|
+
const canonical = `${proof.type}|${proof.version}|${proof.peer_did}|${proof.bloom_filter_hash}|${proof.asserted_at}|${proof.expires_at}`;
|
|
39
|
+
return new TextEncoder().encode(canonical);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Base64 encode (standard, not URL-safe).
|
|
43
|
+
*/
|
|
44
|
+
function toBase64(data) {
|
|
45
|
+
// Use Buffer in Node.js, btoa in browser
|
|
46
|
+
if (typeof Buffer !== 'undefined') {
|
|
47
|
+
return Buffer.from(data).toString('base64');
|
|
48
|
+
}
|
|
49
|
+
// SAFETY: btoa is standard in browsers
|
|
50
|
+
return globalThis.btoa(String.fromCharCode(...data));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Base64 decode (standard, not URL-safe).
|
|
54
|
+
*/
|
|
55
|
+
function fromBase64(data) {
|
|
56
|
+
// Use Buffer in Node.js, atob in browser
|
|
57
|
+
if (typeof Buffer !== 'undefined') {
|
|
58
|
+
return new Uint8Array(Buffer.from(data, 'base64'));
|
|
59
|
+
}
|
|
60
|
+
// SAFETY: atob is standard in browsers
|
|
61
|
+
const binary = globalThis.atob(data);
|
|
62
|
+
const bytes = new Uint8Array(binary.length);
|
|
63
|
+
for (let i = 0; i < binary.length; i++) {
|
|
64
|
+
bytes[i] = binary.charCodeAt(i);
|
|
65
|
+
}
|
|
66
|
+
return bytes;
|
|
67
|
+
}
|
|
68
|
+
/* ── Public API ── */
|
|
69
|
+
/**
|
|
70
|
+
* Create a subscription proof (client-side).
|
|
71
|
+
*
|
|
72
|
+
* Signs a bloom filter hash with the peer's ML-DSA-65 private key, creating
|
|
73
|
+
* a portable proof that can be used to resume subscriptions on a new gateway.
|
|
74
|
+
*
|
|
75
|
+
* @param peerDid - Subscriber's DID (must match the private key).
|
|
76
|
+
* @param bloomFilterHash - SHA-256 hash of the bloom filter (hex string).
|
|
77
|
+
* @param privateKey - 32-byte ML-DSA-65 secret key seed.
|
|
78
|
+
* @param expiresAt - Optional expiration timestamp (ms). Default: 30 days from now.
|
|
79
|
+
* @returns Subscription proof with ML-DSA-65 signature.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const proof = await createSubscriptionProof(
|
|
84
|
+
* 'did:key:z6Mk...',
|
|
85
|
+
* 'a1b2c3...',
|
|
86
|
+
* mlDsaPrivateKey,
|
|
87
|
+
* Date.now() + 30 * 24 * 60 * 60 * 1000
|
|
88
|
+
* );
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
async function createSubscriptionProof(peerDid, bloomFilterHash, privateKey, expiresAt) {
|
|
92
|
+
const assertedAt = Date.now();
|
|
93
|
+
const expiresAtFinal = expiresAt ?? (assertedAt + 30 * 24 * 60 * 60 * 1000); // 30 days default
|
|
94
|
+
// Build proof without signature
|
|
95
|
+
const proofWithoutSig = {
|
|
96
|
+
type: 'SubscriptionProof',
|
|
97
|
+
version: '1.0',
|
|
98
|
+
peer_did: peerDid,
|
|
99
|
+
bloom_filter_hash: bloomFilterHash,
|
|
100
|
+
asserted_at: assertedAt,
|
|
101
|
+
expires_at: expiresAtFinal,
|
|
102
|
+
};
|
|
103
|
+
// Serialize and sign
|
|
104
|
+
const dataToSign = serializeForSigning(proofWithoutSig);
|
|
105
|
+
const signatureResult = await (0, identity_js_1.signMlDsa65)(privateKey, dataToSign);
|
|
106
|
+
if (!signatureResult.ok) {
|
|
107
|
+
return (0, shared_1.err)('SIGNATURE_VERIFICATION_FAILED');
|
|
108
|
+
}
|
|
109
|
+
const signature = signatureResult.value;
|
|
110
|
+
if (signature.length !== identity_js_1.ML_DSA65_SIG_BYTES) {
|
|
111
|
+
return (0, shared_1.err)('SIGNATURE_VERIFICATION_FAILED');
|
|
112
|
+
}
|
|
113
|
+
// Build final proof
|
|
114
|
+
const proof = {
|
|
115
|
+
...proofWithoutSig,
|
|
116
|
+
peer_signature_algorithm: 'ML-DSA-65',
|
|
117
|
+
peer_signature: toBase64(signature),
|
|
118
|
+
};
|
|
119
|
+
return (0, shared_1.ok)(proof);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Verify a subscription proof (gateway-side).
|
|
123
|
+
*
|
|
124
|
+
* Validates the ML-DSA-65 signature and checks expiration.
|
|
125
|
+
*
|
|
126
|
+
* @param proof - Subscription proof to verify.
|
|
127
|
+
* @param peerPublicKey - 1952-byte ML-DSA-65 public key of the subscriber.
|
|
128
|
+
* @returns true if valid, false if invalid or expired.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const isValid = await verifySubscriptionProof(proof, mlDsaPublicKey);
|
|
133
|
+
* if (isValid.ok && isValid.value) {
|
|
134
|
+
* // Resume subscription
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
async function verifySubscriptionProof(proof, peerPublicKey) {
|
|
139
|
+
// Check proof version
|
|
140
|
+
if (proof.version !== '1.0' || proof.type !== 'SubscriptionProof') {
|
|
141
|
+
return (0, shared_1.ok)(false);
|
|
142
|
+
}
|
|
143
|
+
// Check expiration
|
|
144
|
+
if (Date.now() > proof.expires_at) {
|
|
145
|
+
return (0, shared_1.err)('EXPIRED');
|
|
146
|
+
}
|
|
147
|
+
// Check signature algorithm
|
|
148
|
+
if (proof.peer_signature_algorithm !== 'ML-DSA-65') {
|
|
149
|
+
return (0, shared_1.ok)(false);
|
|
150
|
+
}
|
|
151
|
+
// Decode signature
|
|
152
|
+
let signature;
|
|
153
|
+
try {
|
|
154
|
+
signature = fromBase64(proof.peer_signature);
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return (0, shared_1.ok)(false);
|
|
158
|
+
}
|
|
159
|
+
if (signature.length !== identity_js_1.ML_DSA65_SIG_BYTES) {
|
|
160
|
+
return (0, shared_1.ok)(false);
|
|
161
|
+
}
|
|
162
|
+
// Reconstruct signed data
|
|
163
|
+
const proofWithoutSig = {
|
|
164
|
+
type: proof.type,
|
|
165
|
+
version: proof.version,
|
|
166
|
+
peer_did: proof.peer_did,
|
|
167
|
+
bloom_filter_hash: proof.bloom_filter_hash,
|
|
168
|
+
asserted_at: proof.asserted_at,
|
|
169
|
+
expires_at: proof.expires_at,
|
|
170
|
+
};
|
|
171
|
+
const dataToVerify = serializeForSigning(proofWithoutSig);
|
|
172
|
+
// Verify signature
|
|
173
|
+
const verifyResult = await (0, identity_js_1.verifyMlDsa65)(peerPublicKey, signature, dataToVerify);
|
|
174
|
+
if (!verifyResult.ok) {
|
|
175
|
+
return (0, shared_1.err)('SIGNATURE_VERIFICATION_FAILED');
|
|
176
|
+
}
|
|
177
|
+
return (0, shared_1.ok)(verifyResult.value);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Resume subscription on a new gateway using a proof.
|
|
181
|
+
*
|
|
182
|
+
* Presents the subscription proof to the new gateway, allowing the client
|
|
183
|
+
* to resume receiving trust events without re-subscribing.
|
|
184
|
+
*
|
|
185
|
+
* @param proof - Valid subscription proof.
|
|
186
|
+
* @param newGatewayUrl - Base URL of the new gateway (e.g., https://atelier2.xail.io).
|
|
187
|
+
* @returns Success or network error.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const result = await resumeSubscription(proof, 'https://atelier2.xail.io');
|
|
192
|
+
* if (result.ok) {
|
|
193
|
+
* console.log('Subscription resumed on new gateway');
|
|
194
|
+
* }
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
async function resumeSubscription(proof, newGatewayUrl) {
|
|
198
|
+
try {
|
|
199
|
+
const baseUrl = newGatewayUrl.replace(/\/$/, '');
|
|
200
|
+
const response = await fetch(`${baseUrl}/trust/resume`, {
|
|
201
|
+
method: 'POST',
|
|
202
|
+
headers: { 'Content-Type': 'application/json' },
|
|
203
|
+
body: JSON.stringify(proof),
|
|
204
|
+
});
|
|
205
|
+
if (!response.ok) {
|
|
206
|
+
return (0, shared_1.err)('NETWORK_ERROR');
|
|
207
|
+
}
|
|
208
|
+
return (0, shared_1.ok)(undefined);
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return (0, shared_1.err)('NETWORK_ERROR');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Compute SHA-256 hash of a bloom filter for proof creation.
|
|
216
|
+
*
|
|
217
|
+
* @param bloomFilter - Bloom filter bytes.
|
|
218
|
+
* @returns Hex-encoded SHA-256 hash.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const hash = await hashBloomFilter(bloomFilterBytes);
|
|
223
|
+
* if (hash.ok) {
|
|
224
|
+
* const proof = await createSubscriptionProof(did, hash.value, privateKey);
|
|
225
|
+
* }
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
async function hashBloomFilter(bloomFilter) {
|
|
229
|
+
return sha256Hash(bloomFilter);
|
|
230
|
+
}
|
|
@@ -1 +1,148 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSuccession = createSuccession;
|
|
4
|
+
exports.verifySuccession = verifySuccession;
|
|
5
|
+
exports.encodeSuccession = encodeSuccession;
|
|
6
|
+
exports.decodeSuccession = decodeSuccession;
|
|
7
|
+
const identity_js_1 = require("./identity.js");
|
|
8
|
+
const shared_1 = require("../_deps/shared/index.js");
|
|
9
|
+
/**
|
|
10
|
+
* Create DID succession announcement with dual signatures.
|
|
11
|
+
*
|
|
12
|
+
* Format: did:key:OLD||did:key:NEW||sequence||effective_at||expires_at||grace_period||timestamp||sig_OLD||sig_NEW
|
|
13
|
+
* Both old and new keys must sign to prove possession.
|
|
14
|
+
*
|
|
15
|
+
* @param oldDid - DID being rotated (old key)
|
|
16
|
+
* @param oldPrivateKey - ML-DSA-65 secret key (32-byte seed) for old DID
|
|
17
|
+
* @param newDid - DID replacing old DID
|
|
18
|
+
* @param newPrivateKey - ML-DSA-65 secret key (32-byte seed) for new DID
|
|
19
|
+
* @param rotationSequence - Monotonically increasing sequence number
|
|
20
|
+
* @param gracePeriodMs - Overlap window in milliseconds (default: 7 days)
|
|
21
|
+
* @returns Succession announcement with dual signatures or error
|
|
22
|
+
*/
|
|
23
|
+
async function createSuccession(oldDid, oldPrivateKey, newDid, newPrivateKey, rotationSequence, gracePeriodMs = 7 * 24 * 60 * 60 * 1000 // 7 days default
|
|
24
|
+
) {
|
|
25
|
+
const timestamp = Date.now();
|
|
26
|
+
const effective_at = timestamp;
|
|
27
|
+
const expires_at = timestamp + 30 * 24 * 60 * 60 * 1000; // 30 days proof validity
|
|
28
|
+
const message = `${oldDid}||${newDid}||${rotationSequence}||${effective_at}||${expires_at}||${gracePeriodMs}||${timestamp}`;
|
|
29
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
30
|
+
const oldSigResult = await (0, identity_js_1.signMlDsa65)(oldPrivateKey, messageBytes);
|
|
31
|
+
if (!oldSigResult.ok) {
|
|
32
|
+
return (0, shared_1.err)('SIGN_FAILED');
|
|
33
|
+
}
|
|
34
|
+
const newSigResult = await (0, identity_js_1.signMlDsa65)(newPrivateKey, messageBytes);
|
|
35
|
+
if (!newSigResult.ok) {
|
|
36
|
+
return (0, shared_1.err)('SIGN_FAILED');
|
|
37
|
+
}
|
|
38
|
+
return (0, shared_1.ok)({
|
|
39
|
+
oldDid,
|
|
40
|
+
newDid,
|
|
41
|
+
rotation_sequence: rotationSequence,
|
|
42
|
+
effective_at,
|
|
43
|
+
expires_at,
|
|
44
|
+
grace_period_ms: gracePeriodMs,
|
|
45
|
+
timestamp,
|
|
46
|
+
oldSignature: oldSigResult.value,
|
|
47
|
+
newSignature: newSigResult.value
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Verify succession announcement dual signatures.
|
|
52
|
+
*
|
|
53
|
+
* Both old and new keys must have valid signatures.
|
|
54
|
+
* Also checks sequence monotonicity (new sequence must be greater than current).
|
|
55
|
+
*
|
|
56
|
+
* @param announcement - Succession announcement to verify
|
|
57
|
+
* @param oldPublicKey - ML-DSA-65 public key (1952 bytes) for old DID
|
|
58
|
+
* @param newPublicKey - ML-DSA-65 public key (1952 bytes) for new DID
|
|
59
|
+
* @returns true if both signatures valid, false otherwise
|
|
60
|
+
*/
|
|
61
|
+
async function verifySuccession(announcement, oldPublicKey, newPublicKey) {
|
|
62
|
+
const message = `${announcement.oldDid}||${announcement.newDid}||${announcement.rotation_sequence}||${announcement.effective_at}||${announcement.expires_at}||${announcement.grace_period_ms}||${announcement.timestamp}`;
|
|
63
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
64
|
+
const oldValidResult = await (0, identity_js_1.verifyMlDsa65)(oldPublicKey, announcement.oldSignature, messageBytes);
|
|
65
|
+
if (!oldValidResult.ok) {
|
|
66
|
+
return (0, shared_1.err)('VERIFY_FAILED');
|
|
67
|
+
}
|
|
68
|
+
const newValidResult = await (0, identity_js_1.verifyMlDsa65)(newPublicKey, announcement.newSignature, messageBytes);
|
|
69
|
+
if (!newValidResult.ok) {
|
|
70
|
+
return (0, shared_1.err)('VERIFY_FAILED');
|
|
71
|
+
}
|
|
72
|
+
const bothValid = oldValidResult.value && newValidResult.value;
|
|
73
|
+
return (0, shared_1.ok)(bothValid);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Encode succession announcement to wire format.
|
|
77
|
+
*
|
|
78
|
+
* Format: did:key:OLD||did:key:NEW||sequence||effective_at||expires_at||grace_period||timestamp||sig_OLD||sig_NEW
|
|
79
|
+
*
|
|
80
|
+
* @param announcement - Succession announcement to encode
|
|
81
|
+
* @returns Wire format string (base64-encoded signatures)
|
|
82
|
+
*/
|
|
83
|
+
function encodeSuccession(announcement) {
|
|
84
|
+
const parts = [
|
|
85
|
+
announcement.oldDid,
|
|
86
|
+
announcement.newDid,
|
|
87
|
+
announcement.rotation_sequence.toString(),
|
|
88
|
+
announcement.effective_at.toString(),
|
|
89
|
+
announcement.expires_at.toString(),
|
|
90
|
+
announcement.grace_period_ms.toString(),
|
|
91
|
+
announcement.timestamp.toString(),
|
|
92
|
+
Buffer.from(announcement.oldSignature).toString('base64'),
|
|
93
|
+
Buffer.from(announcement.newSignature).toString('base64')
|
|
94
|
+
];
|
|
95
|
+
return parts.join('||');
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Decode succession announcement from wire format.
|
|
99
|
+
*
|
|
100
|
+
* @param encoded - Wire format string
|
|
101
|
+
* @returns Parsed succession announcement or error
|
|
102
|
+
*/
|
|
103
|
+
function decodeSuccession(encoded) {
|
|
104
|
+
const parts = encoded.split('||');
|
|
105
|
+
if (parts.length !== 9) {
|
|
106
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
107
|
+
}
|
|
108
|
+
const oldDid = parts[0];
|
|
109
|
+
const newDid = parts[1];
|
|
110
|
+
const sequenceStr = parts[2];
|
|
111
|
+
const effectiveAtStr = parts[3];
|
|
112
|
+
const expiresAtStr = parts[4];
|
|
113
|
+
const gracePeriodStr = parts[5];
|
|
114
|
+
const timestampStr = parts[6];
|
|
115
|
+
const oldSigB64 = parts[7];
|
|
116
|
+
const newSigB64 = parts[8];
|
|
117
|
+
if (!oldDid || !newDid || !sequenceStr || !effectiveAtStr || !expiresAtStr || !gracePeriodStr || !timestampStr || !oldSigB64 || !newSigB64) {
|
|
118
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
119
|
+
}
|
|
120
|
+
const rotation_sequence = parseInt(sequenceStr, 10);
|
|
121
|
+
const effective_at = parseInt(effectiveAtStr, 10);
|
|
122
|
+
const expires_at = parseInt(expiresAtStr, 10);
|
|
123
|
+
const grace_period_ms = parseInt(gracePeriodStr, 10);
|
|
124
|
+
const timestamp = parseInt(timestampStr, 10);
|
|
125
|
+
if (isNaN(rotation_sequence) || rotation_sequence < 0 ||
|
|
126
|
+
isNaN(effective_at) || effective_at < 0 ||
|
|
127
|
+
isNaN(expires_at) || expires_at < 0 ||
|
|
128
|
+
isNaN(grace_period_ms) || grace_period_ms < 0 ||
|
|
129
|
+
isNaN(timestamp) || timestamp < 0) {
|
|
130
|
+
return (0, shared_1.err)('INVALID_TIMESTAMP');
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
return (0, shared_1.ok)({
|
|
134
|
+
oldDid,
|
|
135
|
+
newDid,
|
|
136
|
+
rotation_sequence,
|
|
137
|
+
effective_at,
|
|
138
|
+
expires_at,
|
|
139
|
+
grace_period_ms,
|
|
140
|
+
timestamp,
|
|
141
|
+
oldSignature: new Uint8Array(Buffer.from(oldSigB64, 'base64')),
|
|
142
|
+
newSignature: new Uint8Array(Buffer.from(newSigB64, 'base64'))
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return (0, shared_1.err)('INVALID_FORMAT');
|
|
147
|
+
}
|
|
148
|
+
}
|