@private.me/xbind 1.3.0 → 2.3.4
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/LICENSES.md +212 -0
- package/README.md +388 -6
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
- package/dist-standalone/_deps/shared/cjs/errors.js +1 -275
- package/dist-standalone/_deps/shared/cjs/index.js +1 -138
- package/dist-standalone/_deps/shared/cjs/types.js +1 -90
- package/dist-standalone/_deps/shared/errors.js +1 -262
- package/dist-standalone/_deps/shared/index.js +1 -77
- package/dist-standalone/_deps/shared/types.js +1 -91
- 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 +1 -642
- package/dist-standalone/agent-sdk.js +1 -328
- package/dist-standalone/agent.d.ts +95 -5
- package/dist-standalone/agent.js +1 -1545
- package/dist-standalone/approval.js +1 -193
- package/dist-standalone/async-iterators.d.ts +275 -0
- package/dist-standalone/async-iterators.js +1 -0
- package/dist-standalone/auth.js +1 -219
- package/dist-standalone/auto-accept.js +1 -229
- package/dist-standalone/backup-config.js +1 -201
- package/dist-standalone/backup.d.ts +114 -0
- package/dist-standalone/backup.js +1 -0
- package/dist-standalone/batch-operations.d.ts +297 -0
- package/dist-standalone/batch-operations.js +1 -0
- package/dist-standalone/cancellation.d.ts +301 -0
- package/dist-standalone/cancellation.js +1 -0
- package/dist-standalone/checkpoint.js +1 -186
- package/dist-standalone/circuit-breaker.d.ts +351 -0
- package/dist-standalone/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/agent-call.js +1 -651
- package/dist-standalone/cjs/agent-sdk.js +1 -332
- package/dist-standalone/cjs/agent.js +1 -1582
- package/dist-standalone/cjs/approval.js +1 -199
- package/dist-standalone/cjs/async-iterators.js +1 -0
- package/dist-standalone/cjs/auth.js +1 -225
- package/dist-standalone/cjs/auto-accept.js +1 -233
- package/dist-standalone/cjs/backup-config.js +1 -207
- package/dist-standalone/cjs/backup.js +1 -0
- package/dist-standalone/cjs/batch-operations.js +1 -0
- package/dist-standalone/cjs/cancellation.js +1 -0
- package/dist-standalone/cjs/checkpoint.js +1 -193
- package/dist-standalone/cjs/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/cli/init.js +1 -486
- package/dist-standalone/cjs/config-validation.js +1 -0
- package/dist-standalone/cjs/connect.js +1 -312
- package/dist-standalone/cjs/connection-pool.js +1 -0
- package/dist-standalone/cjs/correlation-id.js +1 -339
- package/dist-standalone/cjs/crypto-utils.js +1 -0
- package/dist-standalone/cjs/debug-mode.js +1 -0
- package/dist-standalone/cjs/did-document.js +1 -101
- package/dist-standalone/cjs/did-privateme.js +1 -130
- package/dist-standalone/cjs/did-web.js +1 -201
- package/dist-standalone/cjs/discovery.js +1 -462
- package/dist-standalone/cjs/dual-mode.js +1 -251
- package/dist-standalone/cjs/email-templates.js +1 -313
- package/dist-standalone/cjs/email-transport.js +1 -239
- package/dist-standalone/cjs/envelope.js +1 -510
- package/dist-standalone/cjs/errors.js +1 -826
- package/dist-standalone/cjs/event-emitter.js +1 -0
- package/dist-standalone/cjs/gateway-state.js +1 -55
- package/dist-standalone/cjs/gateway-transport.js +1 -120
- package/dist-standalone/cjs/graceful-degradation.js +1 -0
- package/dist-standalone/cjs/guardrails.js +1 -223
- package/dist-standalone/cjs/health-check.js +1 -0
- package/dist-standalone/cjs/http-compat.js +1 -272
- package/dist-standalone/cjs/http-status-map.js +1 -571
- package/dist-standalone/cjs/identity.js +1 -541
- package/dist-standalone/cjs/index.js +1 -237
- package/dist-standalone/cjs/invitation.js +1 -421
- package/dist-standalone/cjs/invite.js +1 -328
- package/dist-standalone/cjs/key-agreement.js +1 -246
- package/dist-standalone/cjs/lazy-init.js +1 -300
- package/dist-standalone/cjs/logger.js +1 -0
- package/dist-standalone/cjs/mdns-discovery.js +1 -202
- package/dist-standalone/cjs/nonce-store.js +1 -66
- package/dist-standalone/cjs/pairing-manager.js +1 -223
- package/dist-standalone/cjs/plugin-system.js +1 -0
- package/dist-standalone/cjs/plugins/logging.js +1 -0
- package/dist-standalone/cjs/plugins/metrics.js +1 -0
- package/dist-standalone/cjs/plugins/validation.js +1 -0
- package/dist-standalone/cjs/policy.js +1 -320
- package/dist-standalone/cjs/progress-callbacks.js +1 -0
- package/dist-standalone/cjs/redis-nonce-store.js +1 -76
- package/dist-standalone/cjs/registry-middleware.js +1 -50
- package/dist-standalone/cjs/retry-strategies.js +1 -0
- package/dist-standalone/cjs/retry-transport.js +1 -102
- package/dist-standalone/cjs/runtime/browser.js +1 -0
- package/dist-standalone/cjs/runtime/edge.js +1 -0
- package/dist-standalone/cjs/runtime/react-native.js +1 -0
- package/dist-standalone/cjs/security-policy.js +1 -245
- package/dist-standalone/cjs/serialization.js +1 -0
- package/dist-standalone/cjs/split-channel.js +1 -177
- package/dist-standalone/cjs/subscription-proof.js +1 -230
- package/dist-standalone/cjs/succession.js +1 -148
- package/dist-standalone/cjs/timeouts.js +1 -0
- package/dist-standalone/cjs/trace-context.js +1 -0
- package/dist-standalone/cjs/trace-spans.js +1 -0
- package/dist-standalone/cjs/transport.js +1 -63
- package/dist-standalone/cjs/trust-registry.js +1 -742
- package/dist-standalone/cjs/types/error-response.js +1 -56
- package/dist-standalone/cjs/vault-auth.js +1 -0
- package/dist-standalone/cjs/vault-store-loader.js +1 -0
- package/dist-standalone/cjs/verify.js +1 -25
- package/dist-standalone/cjs/version-info.js +1 -0
- package/dist-standalone/cjs/xfetch.js +1 -252
- package/dist-standalone/cli/init.js +1 -449
- package/dist-standalone/cli/setup.js +1 -514
- package/dist-standalone/cli/types.js +1 -27
- package/dist-standalone/cli/xbind.js +1 -148
- package/dist-standalone/config-validation.d.ts +185 -0
- package/dist-standalone/config-validation.js +1 -0
- package/dist-standalone/connect.js +1 -274
- package/dist-standalone/connection-pool.d.ts +251 -0
- package/dist-standalone/connection-pool.js +1 -0
- package/dist-standalone/correlation-id.js +1 -326
- package/dist-standalone/crypto-utils.d.ts +60 -0
- package/dist-standalone/crypto-utils.js +1 -0
- package/dist-standalone/debug-mode.d.ts +286 -0
- package/dist-standalone/debug-mode.js +1 -0
- package/dist-standalone/did-document.js +1 -96
- package/dist-standalone/did-privateme.js +1 -121
- package/dist-standalone/did-web.js +1 -196
- package/dist-standalone/discovery.js +1 -458
- package/dist-standalone/dual-mode.js +1 -247
- package/dist-standalone/email-templates.js +1 -309
- package/dist-standalone/email-transport.js +1 -232
- package/dist-standalone/envelope.d.ts +29 -1
- package/dist-standalone/envelope.js +1 -497
- package/dist-standalone/errors.d.ts +10 -0
- package/dist-standalone/errors.js +1 -811
- package/dist-standalone/event-emitter.d.ts +395 -0
- package/dist-standalone/event-emitter.js +1 -0
- package/dist-standalone/gateway-state.js +1 -51
- package/dist-standalone/gateway-transport.js +1 -116
- package/dist-standalone/graceful-degradation.d.ts +246 -0
- package/dist-standalone/graceful-degradation.js +1 -0
- package/dist-standalone/guardrails.js +1 -216
- package/dist-standalone/health-check.d.ts +150 -0
- package/dist-standalone/health-check.js +1 -0
- package/dist-standalone/http-compat.js +1 -267
- package/dist-standalone/http-status-map.js +1 -561
- package/dist-standalone/identity.d.ts +64 -1
- package/dist-standalone/identity.js +1 -516
- package/dist-standalone/index.d.ts +45 -3
- package/dist-standalone/index.js +1 -52
- package/dist-standalone/invitation.js +1 -415
- package/dist-standalone/invite.js +1 -324
- package/dist-standalone/key-agreement.d.ts +61 -13
- package/dist-standalone/key-agreement.js +1 -236
- package/dist-standalone/lazy-init.js +1 -295
- package/dist-standalone/logger.d.ts +77 -0
- package/dist-standalone/logger.js +1 -0
- package/dist-standalone/mdns-discovery.js +1 -195
- package/dist-standalone/nonce-store.d.ts +16 -3
- package/dist-standalone/nonce-store.js +1 -62
- package/dist-standalone/package.json +0 -1
- package/dist-standalone/pairing-manager.js +1 -219
- package/dist-standalone/plugin-system.d.ts +145 -0
- package/dist-standalone/plugin-system.js +1 -0
- package/dist-standalone/policy.js +1 -315
- package/dist-standalone/progress-callbacks.d.ts +394 -0
- package/dist-standalone/progress-callbacks.js +1 -0
- package/dist-standalone/redis-nonce-store.js +1 -72
- package/dist-standalone/registry-middleware.js +1 -47
- package/dist-standalone/retry-strategies.d.ts +382 -0
- package/dist-standalone/retry-strategies.js +1 -0
- package/dist-standalone/retry-transport.js +1 -98
- package/dist-standalone/security-policy.js +1 -239
- package/dist-standalone/serialization.d.ts +244 -0
- package/dist-standalone/serialization.js +1 -0
- package/dist-standalone/split-channel.d.ts +49 -1
- package/dist-standalone/split-channel.js +1 -171
- package/dist-standalone/subscription-proof.js +1 -224
- package/dist-standalone/succession.js +1 -142
- package/dist-standalone/timeouts.d.ts +275 -0
- package/dist-standalone/timeouts.js +1 -0
- package/dist-standalone/trace-context.d.ts +252 -0
- package/dist-standalone/trace-context.js +1 -0
- package/dist-standalone/trace-spans.d.ts +360 -0
- package/dist-standalone/trace-spans.js +1 -0
- package/dist-standalone/transport.js +1 -59
- package/dist-standalone/trust-registry.d.ts +106 -5
- package/dist-standalone/trust-registry.js +1 -702
- package/dist-standalone/vault-auth.d.ts +91 -0
- package/dist-standalone/vault-auth.js +1 -0
- package/dist-standalone/vault-store-loader.d.ts +110 -0
- package/dist-standalone/vault-store-loader.js +1 -0
- package/dist-standalone/verify.js +1 -16
- package/dist-standalone/version-info.d.ts +259 -0
- package/dist-standalone/version-info.js +1 -0
- package/dist-standalone/xfetch.js +1 -247
- package/llms.txt +1 -0
- package/package.json +66 -5
- package/share1.dat +0 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
- package/dist-standalone/_deps/crypto/base64.js +0 -209
- package/dist-standalone/_deps/crypto/cjs/base64.js +0 -103
- package/dist-standalone/_deps/crypto/cjs/errors.js +0 -119
- package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -71
- package/dist-standalone/_deps/crypto/cjs/index.js +0 -86
- package/dist-standalone/_deps/crypto/cjs/padding.js +0 -57
- package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -68
- package/dist-standalone/_deps/crypto/cjs/shares.js +0 -152
- package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -199
- package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -61
- package/dist-standalone/_deps/crypto/cjs/verify.js +0 -24
- package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -221
- package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
- package/dist-standalone/_deps/crypto/errors.js +0 -109
- package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
- package/dist-standalone/_deps/crypto/hmac.js +0 -66
- package/dist-standalone/_deps/crypto/index.d.ts +0 -20
- package/dist-standalone/_deps/crypto/index.js +0 -45
- package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
- package/dist-standalone/_deps/crypto/padding.js +0 -53
- package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
- package/dist-standalone/_deps/crypto/share-header.js +0 -63
- package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
- package/dist-standalone/_deps/crypto/shares.js +0 -148
- package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
- package/dist-standalone/_deps/crypto/tlv.js +0 -195
- package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
- package/dist-standalone/_deps/crypto/uuid.js +0 -56
- package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
- package/dist-standalone/_deps/crypto/verify.js +0 -15
- package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
- package/dist-standalone/_deps/crypto/xorida.js +0 -215
- package/dist-standalone/_deps/shared/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/errors.js.map +0 -1
- package/dist-standalone/_deps/shared/index.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/index.js.map +0 -1
- package/dist-standalone/_deps/shared/types.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.js.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.js.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.js.map +0 -1
- package/dist-standalone/_deps/xregistry/index.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/index.js.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.js.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.js.map +0 -1
- package/dist-standalone/_deps/xregistry/types.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/types.js.map +0 -1
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toBase64 = toBase64;
|
|
4
|
-
exports.fromBase64 = fromBase64;
|
|
5
|
-
exports.toBase64Url = toBase64Url;
|
|
6
|
-
exports.fromBase64Url = fromBase64Url;
|
|
7
|
-
const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
8
|
-
const URL_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
9
|
-
/**
|
|
10
|
-
* Encode bytes to standard Base64 (RFC 4648).
|
|
11
|
-
*
|
|
12
|
-
* @param data - Bytes to encode
|
|
13
|
-
* @returns Base64-encoded string with padding
|
|
14
|
-
*/
|
|
15
|
-
function toBase64(data) {
|
|
16
|
-
return encode(data, CHARS, true);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Decode standard Base64 string to bytes.
|
|
20
|
-
*
|
|
21
|
-
* @param str - Base64-encoded string
|
|
22
|
-
* @returns Decoded bytes
|
|
23
|
-
*/
|
|
24
|
-
function fromBase64(str) {
|
|
25
|
-
return decode(str, CHARS);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Encode bytes to Base64url (RFC 4648 Section 5).
|
|
29
|
-
* Uses URL-safe characters (-_ instead of +/) and no padding.
|
|
30
|
-
*
|
|
31
|
-
* @param data - Bytes to encode
|
|
32
|
-
* @returns Base64url-encoded string without padding
|
|
33
|
-
*/
|
|
34
|
-
function toBase64Url(data) {
|
|
35
|
-
return encode(data, URL_CHARS, false);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Decode Base64url string to bytes.
|
|
39
|
-
*
|
|
40
|
-
* @param str - Base64url-encoded string
|
|
41
|
-
* @returns Decoded bytes
|
|
42
|
-
*/
|
|
43
|
-
function fromBase64Url(str) {
|
|
44
|
-
return decode(str, URL_CHARS);
|
|
45
|
-
}
|
|
46
|
-
/** Encode bytes using the given alphabet. */
|
|
47
|
-
function encode(data, alphabet, pad) {
|
|
48
|
-
let result = '';
|
|
49
|
-
for (let i = 0; i < data.length; i += 3) {
|
|
50
|
-
const a = data[i];
|
|
51
|
-
const b = i + 1 < data.length ? data[i + 1] : 0;
|
|
52
|
-
const c = i + 2 < data.length ? data[i + 2] : 0;
|
|
53
|
-
result += alphabet[(a >> 2)];
|
|
54
|
-
result += alphabet[((a & 0x03) << 4) | (b >> 4)];
|
|
55
|
-
if (i + 1 < data.length) {
|
|
56
|
-
result += alphabet[((b & 0x0f) << 2) | (c >> 6)];
|
|
57
|
-
}
|
|
58
|
-
if (i + 2 < data.length) {
|
|
59
|
-
result += alphabet[c & 0x3f];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (pad) {
|
|
63
|
-
const remainder = data.length % 3;
|
|
64
|
-
if (remainder === 1)
|
|
65
|
-
result += '==';
|
|
66
|
-
else if (remainder === 2)
|
|
67
|
-
result += '=';
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
/** Build a reverse lookup map for a Base64 alphabet. */
|
|
72
|
-
function buildLookup(alphabet) {
|
|
73
|
-
const map = new Map();
|
|
74
|
-
for (let i = 0; i < alphabet.length; i++) {
|
|
75
|
-
map.set(alphabet[i], i);
|
|
76
|
-
}
|
|
77
|
-
return map;
|
|
78
|
-
}
|
|
79
|
-
const STD_LOOKUP = buildLookup(CHARS);
|
|
80
|
-
const URL_LOOKUP = buildLookup(URL_CHARS);
|
|
81
|
-
/** Decode a Base64 string using the given lookup. Tolerates whitespace (RFC 2045). */
|
|
82
|
-
function decode(str, alphabet) {
|
|
83
|
-
const lookup = alphabet === CHARS ? STD_LOOKUP : URL_LOOKUP;
|
|
84
|
-
const stripped = str.replace(/\s/g, '');
|
|
85
|
-
const cleaned = stripped.replace(/=+$/, '');
|
|
86
|
-
const byteLen = Math.floor((cleaned.length * 3) / 4);
|
|
87
|
-
const result = new Uint8Array(byteLen);
|
|
88
|
-
let byteIdx = 0;
|
|
89
|
-
for (let i = 0; i < cleaned.length; i += 4) {
|
|
90
|
-
const a = lookup.get(cleaned[i]) ?? 0;
|
|
91
|
-
const b = lookup.get(cleaned[i + 1]) ?? 0;
|
|
92
|
-
const c = i + 2 < cleaned.length ? (lookup.get(cleaned[i + 2]) ?? 0) : 0;
|
|
93
|
-
const d = i + 3 < cleaned.length ? (lookup.get(cleaned[i + 3]) ?? 0) : 0;
|
|
94
|
-
result[byteIdx++] = (a << 2) | (b >> 4);
|
|
95
|
-
if (i + 2 < cleaned.length) {
|
|
96
|
-
result[byteIdx++] = ((b & 0x0f) << 4) | (c >> 2);
|
|
97
|
-
}
|
|
98
|
-
if (i + 3 < cleaned.length) {
|
|
99
|
-
result[byteIdx++] = ((c & 0x03) << 6) | d;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module errors
|
|
4
|
-
* Named error class hierarchy for @private.me/crypto.
|
|
5
|
-
*
|
|
6
|
-
* Provides structured error types for XorIDA threshold sharing,
|
|
7
|
-
* HMAC integrity verification, PKCS#7 padding, and TLV serialization.
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.ERROR_DETAILS = exports.ERROR_MESSAGES = exports.CryptoSerializationError = exports.CryptoPaddingError = exports.CryptoIntegrityError = exports.CryptoSplitError = exports.CryptoError = void 0;
|
|
11
|
-
exports.toCryptoError = toCryptoError;
|
|
12
|
-
exports.isCryptoError = isCryptoError;
|
|
13
|
-
const DOC_BASE = 'https://private.me/docs/packages/crypto';
|
|
14
|
-
/** Base error class for all crypto operations. */
|
|
15
|
-
class CryptoError extends Error {
|
|
16
|
-
code;
|
|
17
|
-
subCode;
|
|
18
|
-
docUrl;
|
|
19
|
-
constructor(code, message, docUrl) {
|
|
20
|
-
super(message);
|
|
21
|
-
this.name = 'CryptoError';
|
|
22
|
-
const parts = code.split(':');
|
|
23
|
-
this.code = parts[0] ?? code;
|
|
24
|
-
this.subCode = parts.length > 1 ? parts.slice(1).join(':') : undefined;
|
|
25
|
-
this.docUrl = docUrl;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.CryptoError = CryptoError;
|
|
29
|
-
/** Error thrown during XorIDA split or reconstruction operations. */
|
|
30
|
-
class CryptoSplitError extends CryptoError {
|
|
31
|
-
constructor(code, message) {
|
|
32
|
-
super(code, message, `${DOC_BASE}#splitting`);
|
|
33
|
-
this.name = 'CryptoSplitError';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.CryptoSplitError = CryptoSplitError;
|
|
37
|
-
/** Error thrown when HMAC integrity verification fails. */
|
|
38
|
-
class CryptoIntegrityError extends CryptoError {
|
|
39
|
-
constructor(code, message) {
|
|
40
|
-
super(code, message, `${DOC_BASE}#integrity`);
|
|
41
|
-
this.name = 'CryptoIntegrityError';
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.CryptoIntegrityError = CryptoIntegrityError;
|
|
45
|
-
/** Error thrown for PKCS#7 padding issues. */
|
|
46
|
-
class CryptoPaddingError extends CryptoError {
|
|
47
|
-
constructor(code, message) {
|
|
48
|
-
super(code, message, `${DOC_BASE}#padding`);
|
|
49
|
-
this.name = 'CryptoPaddingError';
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.CryptoPaddingError = CryptoPaddingError;
|
|
53
|
-
/** Error thrown during TLV serialization or deserialization. */
|
|
54
|
-
class CryptoSerializationError extends CryptoError {
|
|
55
|
-
constructor(code, message) {
|
|
56
|
-
super(code, message, `${DOC_BASE}#serialization`);
|
|
57
|
-
this.name = 'CryptoSerializationError';
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.CryptoSerializationError = CryptoSerializationError;
|
|
61
|
-
/** Human-readable messages for each error code. */
|
|
62
|
-
exports.ERROR_MESSAGES = {
|
|
63
|
-
SPLIT_FAILED: 'XorIDA split operation failed',
|
|
64
|
-
RECONSTRUCTION_FAILED: 'XorIDA reconstruction failed',
|
|
65
|
-
INSUFFICIENT_SHARES: 'Not enough shares provided for reconstruction',
|
|
66
|
-
INVALID_SHARES: 'Shares have inconsistent UUID, n, or k values',
|
|
67
|
-
INVALID_INDEX: 'Share index is out of range or duplicated',
|
|
68
|
-
HMAC_FAILURE: 'HMAC integrity verification failed -- data may be corrupted',
|
|
69
|
-
UUID_MISMATCH: 'Envelope UUID does not match TLV payload UUID',
|
|
70
|
-
INVALID_PADDING: 'PKCS#7 padding is invalid or corrupted',
|
|
71
|
-
INVALID_TLV: 'TLV buffer is malformed or truncated',
|
|
72
|
-
BUFFER_OVERFLOW: 'TLV value length exceeds buffer bounds',
|
|
73
|
-
MISSING_FIELD: 'Required TLV field is missing from serialized data',
|
|
74
|
-
INVALID_CONFIG: 'Split configuration is invalid (n < 2, k < 2, or k > n)',
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Detailed descriptions for each error code.
|
|
78
|
-
* Maps error codes to comprehensive explanations including cause and resolution.
|
|
79
|
-
*/
|
|
80
|
-
exports.ERROR_DETAILS = {
|
|
81
|
-
INVALID_PADDING: 'PKCS#7 padding bytes are invalid or inconsistent. Data may be corrupted.',
|
|
82
|
-
HMAC_FAILURE: 'HMAC-SHA256 verification failed during reconstruction. One or more shares have been tampered with.',
|
|
83
|
-
INVALID_SHARES: 'Shares have inconsistent lengths, duplicate indices, or mismatched parameters.',
|
|
84
|
-
INSUFFICIENT_SHARES: 'Fewer shares provided than the required threshold k.',
|
|
85
|
-
INVALID_INDEX: 'A share index is out of range (must be 0 to n-1).',
|
|
86
|
-
UUID_MISMATCH: 'Shares reference different message UUIDs and cannot be combined.',
|
|
87
|
-
INVALID_TLV: 'TLV data is malformed or truncated.',
|
|
88
|
-
BUFFER_OVERFLOW: 'TLV length field exceeds available data.',
|
|
89
|
-
MISSING_FIELD: 'A required TLV field (e.g., MESSAGE_UUID) is absent.',
|
|
90
|
-
INVALID_TYPE: 'An unrecognized TLV type tag was encountered in a required position.',
|
|
91
|
-
HMAC_MISMATCH: 'Standalone HMAC verification failed. Data or key is incorrect.',
|
|
92
|
-
KEY_ERROR: 'HMAC key import failed (invalid length or format).',
|
|
93
|
-
SPLIT_FAILED: 'XorIDA split operation failed due to invalid input or configuration.',
|
|
94
|
-
RECONSTRUCTION_FAILED: 'XorIDA reconstruction failed. Check share integrity and parameters.',
|
|
95
|
-
INVALID_CONFIG: 'Split configuration is invalid. Requires n >= 2, k >= 2, and k <= n.',
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Convert an unknown error into a CryptoError.
|
|
99
|
-
*
|
|
100
|
-
* @param error - The unknown error to convert
|
|
101
|
-
* @returns A CryptoError instance
|
|
102
|
-
*/
|
|
103
|
-
function toCryptoError(error) {
|
|
104
|
-
if (error instanceof CryptoError)
|
|
105
|
-
return error;
|
|
106
|
-
if (error instanceof Error) {
|
|
107
|
-
return new CryptoError('SPLIT_FAILED', error.message);
|
|
108
|
-
}
|
|
109
|
-
return new CryptoError('SPLIT_FAILED', String(error));
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Type guard to check if an error is a CryptoError.
|
|
113
|
-
*
|
|
114
|
-
* @param error - The value to check
|
|
115
|
-
* @returns true if the value is a CryptoError instance
|
|
116
|
-
*/
|
|
117
|
-
function isCryptoError(error) {
|
|
118
|
-
return error instanceof CryptoError;
|
|
119
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* HMAC-SHA256 integrity verification using Web Crypto API.
|
|
4
|
-
*
|
|
5
|
-
* Provides message-level integrity for the XorIDA pipeline.
|
|
6
|
-
* The HMAC is computed over the padded payload (after TLV serialization + PKCS#7 padding)
|
|
7
|
-
* and verified after reconstruction, before unpadding.
|
|
8
|
-
*
|
|
9
|
-
* Uses crypto.subtle for constant-time verification (no manual byte comparison).
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.generateHMAC = generateHMAC;
|
|
13
|
-
exports.verifyHMAC = verifyHMAC;
|
|
14
|
-
exports.signHMAC = signHMAC;
|
|
15
|
-
/** HMAC key length in bytes. */
|
|
16
|
-
const HMAC_KEY_LENGTH = 32;
|
|
17
|
-
/** HMAC algorithm config. */
|
|
18
|
-
const HMAC_ALGO = { name: 'HMAC', hash: 'SHA-256' };
|
|
19
|
-
/** Copy a Uint8Array into a fresh ArrayBuffer (avoids SharedArrayBuffer type issues). */
|
|
20
|
-
function toArrayBuffer(data) {
|
|
21
|
-
const buf = new ArrayBuffer(data.byteLength);
|
|
22
|
-
new Uint8Array(buf).set(data);
|
|
23
|
-
return buf;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Import a raw key buffer for HMAC operations.
|
|
27
|
-
* Copies to a fresh ArrayBuffer to satisfy Web Crypto API typing.
|
|
28
|
-
*/
|
|
29
|
-
async function importKey(keyBytes, usage) {
|
|
30
|
-
return crypto.subtle.importKey('raw', toArrayBuffer(keyBytes), HMAC_ALGO, false, [usage]);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Generate a fresh random HMAC key and sign data with HMAC-SHA256.
|
|
34
|
-
*
|
|
35
|
-
* @param data - Bytes to sign (the padded payload)
|
|
36
|
-
* @returns Object containing the raw key bytes and the 32-byte signature
|
|
37
|
-
*/
|
|
38
|
-
async function generateHMAC(data) {
|
|
39
|
-
const keyBytes = new Uint8Array(HMAC_KEY_LENGTH);
|
|
40
|
-
crypto.getRandomValues(keyBytes);
|
|
41
|
-
const cryptoKey = await importKey(keyBytes, 'sign');
|
|
42
|
-
const sig = await crypto.subtle.sign('HMAC', cryptoKey, toArrayBuffer(data));
|
|
43
|
-
return { key: keyBytes, signature: new Uint8Array(sig) };
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Verify an HMAC-SHA256 signature using constant-time comparison.
|
|
47
|
-
*
|
|
48
|
-
* Uses crypto.subtle.verify() which is constant-time by specification.
|
|
49
|
-
* NEVER manually compare HMAC bytes (timing attack risk).
|
|
50
|
-
*
|
|
51
|
-
* @param key - Raw HMAC key bytes (32 bytes)
|
|
52
|
-
* @param data - Data that was signed
|
|
53
|
-
* @param signature - Expected HMAC-SHA256 signature (32 bytes)
|
|
54
|
-
* @returns true if signature is valid, false otherwise
|
|
55
|
-
*/
|
|
56
|
-
async function verifyHMAC(key, data, signature) {
|
|
57
|
-
const cryptoKey = await importKey(key, 'verify');
|
|
58
|
-
return crypto.subtle.verify('HMAC', cryptoKey, toArrayBuffer(signature), toArrayBuffer(data));
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Sign data with a provided HMAC key (for cases where the key is already known).
|
|
62
|
-
*
|
|
63
|
-
* @param key - Raw HMAC key bytes (32 bytes)
|
|
64
|
-
* @param data - Bytes to sign
|
|
65
|
-
* @returns 32-byte HMAC-SHA256 signature
|
|
66
|
-
*/
|
|
67
|
-
async function signHMAC(key, data) {
|
|
68
|
-
const cryptoKey = await importKey(key, 'sign');
|
|
69
|
-
const sig = await crypto.subtle.sign('HMAC', cryptoKey, toArrayBuffer(data));
|
|
70
|
-
return new Uint8Array(sig);
|
|
71
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// @private.me/crypto — public API
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.splitWithRandom = exports.hasShareHeader = exports.parseShareHeader = exports.formatShareHeader = exports.reconstructMessage = exports.createShares = exports.fromBase64Url = exports.toBase64Url = exports.fromBase64 = exports.toBase64 = exports.bytesToUuid = exports.uuidToBytes = exports.generateUUID = exports.deserializeMessage = exports.serializeMessage = exports.signHMAC = exports.verifyHMAC = exports.generateHMAC = exports.pkcs7Unpad = exports.pkcs7Pad = exports.nextOddPrime = exports.reconstructXorIDA = exports.splitXorIDA = void 0;
|
|
19
|
-
exports.isSupported = isSupported;
|
|
20
|
-
// Errors
|
|
21
|
-
__exportStar(require("./errors.js"), exports);
|
|
22
|
-
// XorIDA Threshold Sharing
|
|
23
|
-
var xorida_js_1 = require("./xorida.js");
|
|
24
|
-
Object.defineProperty(exports, "splitXorIDA", { enumerable: true, get: function () { return xorida_js_1.splitXorIDA; } });
|
|
25
|
-
Object.defineProperty(exports, "reconstructXorIDA", { enumerable: true, get: function () { return xorida_js_1.reconstructXorIDA; } });
|
|
26
|
-
Object.defineProperty(exports, "nextOddPrime", { enumerable: true, get: function () { return xorida_js_1.nextOddPrime; } });
|
|
27
|
-
// Padding
|
|
28
|
-
var padding_js_1 = require("./padding.js");
|
|
29
|
-
Object.defineProperty(exports, "pkcs7Pad", { enumerable: true, get: function () { return padding_js_1.pkcs7Pad; } });
|
|
30
|
-
Object.defineProperty(exports, "pkcs7Unpad", { enumerable: true, get: function () { return padding_js_1.pkcs7Unpad; } });
|
|
31
|
-
// Integrity
|
|
32
|
-
var hmac_js_1 = require("./hmac.js");
|
|
33
|
-
Object.defineProperty(exports, "generateHMAC", { enumerable: true, get: function () { return hmac_js_1.generateHMAC; } });
|
|
34
|
-
Object.defineProperty(exports, "verifyHMAC", { enumerable: true, get: function () { return hmac_js_1.verifyHMAC; } });
|
|
35
|
-
Object.defineProperty(exports, "signHMAC", { enumerable: true, get: function () { return hmac_js_1.signHMAC; } });
|
|
36
|
-
// Serialization
|
|
37
|
-
var tlv_js_1 = require("./tlv.js");
|
|
38
|
-
Object.defineProperty(exports, "serializeMessage", { enumerable: true, get: function () { return tlv_js_1.serializeMessage; } });
|
|
39
|
-
Object.defineProperty(exports, "deserializeMessage", { enumerable: true, get: function () { return tlv_js_1.deserializeMessage; } });
|
|
40
|
-
// UUID
|
|
41
|
-
var uuid_js_1 = require("./uuid.js");
|
|
42
|
-
Object.defineProperty(exports, "generateUUID", { enumerable: true, get: function () { return uuid_js_1.generateUUID; } });
|
|
43
|
-
Object.defineProperty(exports, "uuidToBytes", { enumerable: true, get: function () { return uuid_js_1.uuidToBytes; } });
|
|
44
|
-
Object.defineProperty(exports, "bytesToUuid", { enumerable: true, get: function () { return uuid_js_1.bytesToUuid; } });
|
|
45
|
-
// Base64
|
|
46
|
-
var base64_js_1 = require("./base64.js");
|
|
47
|
-
Object.defineProperty(exports, "toBase64", { enumerable: true, get: function () { return base64_js_1.toBase64; } });
|
|
48
|
-
Object.defineProperty(exports, "fromBase64", { enumerable: true, get: function () { return base64_js_1.fromBase64; } });
|
|
49
|
-
Object.defineProperty(exports, "toBase64Url", { enumerable: true, get: function () { return base64_js_1.toBase64Url; } });
|
|
50
|
-
Object.defineProperty(exports, "fromBase64Url", { enumerable: true, get: function () { return base64_js_1.fromBase64Url; } });
|
|
51
|
-
// High-level API
|
|
52
|
-
var shares_js_1 = require("./shares.js");
|
|
53
|
-
Object.defineProperty(exports, "createShares", { enumerable: true, get: function () { return shares_js_1.createShares; } });
|
|
54
|
-
Object.defineProperty(exports, "reconstructMessage", { enumerable: true, get: function () { return shares_js_1.reconstructMessage; } });
|
|
55
|
-
// Branded Share Header (IDA5 copyright layer)
|
|
56
|
-
var share_header_js_1 = require("./share-header.js");
|
|
57
|
-
Object.defineProperty(exports, "formatShareHeader", { enumerable: true, get: function () { return share_header_js_1.formatShareHeader; } });
|
|
58
|
-
Object.defineProperty(exports, "parseShareHeader", { enumerable: true, get: function () { return share_header_js_1.parseShareHeader; } });
|
|
59
|
-
Object.defineProperty(exports, "hasShareHeader", { enumerable: true, get: function () { return share_header_js_1.hasShareHeader; } });
|
|
60
|
-
// Capability check
|
|
61
|
-
/**
|
|
62
|
-
* Check if the runtime supports the required Web Crypto APIs.
|
|
63
|
-
*
|
|
64
|
-
* Verifies that `crypto.subtle` is available with HMAC, AES-GCM,
|
|
65
|
-
* and `crypto.getRandomValues`. Call this before using any crypto
|
|
66
|
-
* operations to provide a clear error message on unsupported runtimes.
|
|
67
|
-
*
|
|
68
|
-
* @returns `true` if the runtime has the required Web Crypto APIs.
|
|
69
|
-
*/
|
|
70
|
-
function isSupported() {
|
|
71
|
-
try {
|
|
72
|
-
return (typeof globalThis.crypto !== 'undefined' &&
|
|
73
|
-
typeof globalThis.crypto.subtle !== 'undefined' &&
|
|
74
|
-
typeof globalThis.crypto.subtle.importKey === 'function' &&
|
|
75
|
-
typeof globalThis.crypto.subtle.sign === 'function' &&
|
|
76
|
-
typeof globalThis.crypto.subtle.verify === 'function' &&
|
|
77
|
-
typeof globalThis.crypto.subtle.encrypt === 'function' &&
|
|
78
|
-
typeof globalThis.crypto.getRandomValues === 'function');
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
// Re-export for testing (internal, not part of public API contract)
|
|
85
|
-
var xorida_js_2 = require("./xorida.js");
|
|
86
|
-
Object.defineProperty(exports, "splitWithRandom", { enumerable: true, get: function () { return xorida_js_2.splitWithRandom; } });
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pkcs7Pad = pkcs7Pad;
|
|
4
|
-
exports.pkcs7Unpad = pkcs7Unpad;
|
|
5
|
-
const shared_1 = require("../../shared/index.js");
|
|
6
|
-
/**
|
|
7
|
-
* PKCS#7 pad data to a multiple of blockSize bytes.
|
|
8
|
-
* Always adds at least 1 byte of padding, even when already aligned.
|
|
9
|
-
*
|
|
10
|
-
* @param data - Input bytes to pad
|
|
11
|
-
* @param blockSize - Block size in bytes (must be 1–255)
|
|
12
|
-
* @returns Padded byte array
|
|
13
|
-
*/
|
|
14
|
-
function pkcs7Pad(data, blockSize) {
|
|
15
|
-
const padLen = blockSize - (data.length % blockSize);
|
|
16
|
-
const padded = new Uint8Array(data.length + padLen);
|
|
17
|
-
padded.set(data);
|
|
18
|
-
for (let i = data.length; i < padded.length; i++) {
|
|
19
|
-
padded[i] = padLen;
|
|
20
|
-
}
|
|
21
|
-
return padded;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Remove PKCS#7 padding. Validates that padding bytes are consistent.
|
|
25
|
-
* Returns an error if padding is invalid (possible tampering).
|
|
26
|
-
*
|
|
27
|
-
* @param data - Padded byte array
|
|
28
|
-
* @param blockSize - Block size used during padding (must be 1–255)
|
|
29
|
-
* @returns Unpadded bytes, or PaddingError if invalid
|
|
30
|
-
*/
|
|
31
|
-
function pkcs7Unpad(data, blockSize) {
|
|
32
|
-
if (data.length === 0) {
|
|
33
|
-
return (0, shared_1.err)({ code: 'INVALID_PADDING', message: 'Input is empty' });
|
|
34
|
-
}
|
|
35
|
-
if (data.length % blockSize !== 0) {
|
|
36
|
-
return (0, shared_1.err)({
|
|
37
|
-
code: 'INVALID_PADDING',
|
|
38
|
-
message: 'Input length is not a multiple of block size',
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
const padLen = data[data.length - 1];
|
|
42
|
-
if (padLen === undefined || padLen < 1 || padLen > blockSize) {
|
|
43
|
-
return (0, shared_1.err)({
|
|
44
|
-
code: 'INVALID_PADDING',
|
|
45
|
-
message: `Invalid padding value: ${padLen}`,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
for (let i = data.length - padLen; i < data.length; i++) {
|
|
49
|
-
if (data[i] !== padLen) {
|
|
50
|
-
return (0, shared_1.err)({
|
|
51
|
-
code: 'INVALID_PADDING',
|
|
52
|
-
message: 'Inconsistent padding bytes',
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return (0, shared_1.ok)(data.slice(0, data.length - padLen));
|
|
57
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Branded share header — IDA5 copyright layer.
|
|
4
|
-
*
|
|
5
|
-
* Wraps every XorIDA share output with the patent-locked branded string:
|
|
6
|
-
*
|
|
7
|
-
* Xecret (TM) -> PRIVATE .ME (R) -> IDA5 -> Encrypted:// [data] => Generated by Xecret (TM)
|
|
8
|
-
*
|
|
9
|
-
* This provides triple legal protection on every share artifact:
|
|
10
|
-
* - Patent (20 years): XorIDA algorithm and split-channel architecture
|
|
11
|
-
* - Copyright (95 years): the literal branded header expression
|
|
12
|
-
* - Trademark (indefinite): Xecret(TM) and PRIVATE .ME(R) marks
|
|
13
|
-
*
|
|
14
|
-
* NEVER modify the header format. It is patent-locked.
|
|
15
|
-
*/
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.formatShareHeader = formatShareHeader;
|
|
18
|
-
exports.parseShareHeader = parseShareHeader;
|
|
19
|
-
exports.hasShareHeader = hasShareHeader;
|
|
20
|
-
/** Start marker for the branded share data region. */
|
|
21
|
-
const START_MARKER = 'Encrypted://';
|
|
22
|
-
/** End marker for the branded share data region. */
|
|
23
|
-
const END_MARKER = '=> Generated by Xecret (TM)';
|
|
24
|
-
/** Branded prefix before the start marker. */
|
|
25
|
-
const BRAND_PREFIX = 'Xecret (TM) -> PRIVATE .ME (R) -> IDA5 -> ';
|
|
26
|
-
/**
|
|
27
|
-
* Wrap share data with the branded IDA5 copyright header.
|
|
28
|
-
*
|
|
29
|
-
* Output format (patent-locked, NEVER change):
|
|
30
|
-
* Xecret (TM) -> PRIVATE .ME (R) -> IDA5 -> Encrypted:// [data] => Generated by Xecret (TM)
|
|
31
|
-
*
|
|
32
|
-
* @param data - Base64-encoded share data (or any string payload)
|
|
33
|
-
* @returns Branded string with copyright header wrapping the data
|
|
34
|
-
*/
|
|
35
|
-
function formatShareHeader(data) {
|
|
36
|
-
return `${BRAND_PREFIX}${START_MARKER} ${data} ${END_MARKER}`;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Extract share data from a branded IDA5 header string.
|
|
40
|
-
*
|
|
41
|
-
* Backward-compatible: if the branded markers are not found, returns
|
|
42
|
-
* the input string trimmed (handles legacy headerless shares).
|
|
43
|
-
*
|
|
44
|
-
* @param input - Branded share string or legacy raw data
|
|
45
|
-
* @returns Extracted share data with whitespace trimmed
|
|
46
|
-
*/
|
|
47
|
-
function parseShareHeader(input) {
|
|
48
|
-
const startIdx = input.indexOf(START_MARKER);
|
|
49
|
-
if (startIdx < 0)
|
|
50
|
-
return input.trim();
|
|
51
|
-
const dataStart = startIdx + START_MARKER.length;
|
|
52
|
-
const endIdx = input.indexOf(END_MARKER, dataStart);
|
|
53
|
-
if (endIdx < 0)
|
|
54
|
-
return input.trim();
|
|
55
|
-
return input.substring(dataStart, endIdx).trim();
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Check whether a string contains the branded IDA5 share header.
|
|
59
|
-
*
|
|
60
|
-
* Useful for format detection — distinguishing branded shares from
|
|
61
|
-
* legacy raw base64 shares.
|
|
62
|
-
*
|
|
63
|
-
* @param input - String to check
|
|
64
|
-
* @returns true if the branded markers are present
|
|
65
|
-
*/
|
|
66
|
-
function hasShareHeader(input) {
|
|
67
|
-
return input.includes(START_MARKER) && input.includes(END_MARKER);
|
|
68
|
-
}
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* High-level share creation and reconstruction API.
|
|
4
|
-
*
|
|
5
|
-
* Sender pipeline: serialize (TLV) → pad (PKCS#7) → HMAC (sign) → split (XorIDA)
|
|
6
|
-
* Receiver pipeline: reconstruct (XorIDA) → verify (HMAC) → unpad (PKCS#7) → deserialize (TLV)
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.createShares = createShares;
|
|
10
|
-
exports.reconstructMessage = reconstructMessage;
|
|
11
|
-
const shared_1 = require("../../shared/index.js");
|
|
12
|
-
const tlv_js_1 = require("./tlv.js");
|
|
13
|
-
const padding_js_1 = require("./padding.js");
|
|
14
|
-
const hmac_js_1 = require("./hmac.js");
|
|
15
|
-
const xorida_js_1 = require("./xorida.js");
|
|
16
|
-
const uuid_js_1 = require("./uuid.js");
|
|
17
|
-
/**
|
|
18
|
-
* Create shares from a XailMessage.
|
|
19
|
-
*
|
|
20
|
-
* Pipeline: serialize → pad → HMAC → split → package as XailShare[]
|
|
21
|
-
*
|
|
22
|
-
* @param message - The message to split into shares
|
|
23
|
-
* @param n - Total number of shares to produce
|
|
24
|
-
* @param k - Threshold: minimum shares needed for reconstruction
|
|
25
|
-
* @returns Array of n XailShare objects ready for transport
|
|
26
|
-
*/
|
|
27
|
-
async function createShares(message, n, k) {
|
|
28
|
-
// Ensure UUID is set before serialization so TLV and share headers match.
|
|
29
|
-
const uuid = message.uuid || (0, uuid_js_1.generateUUID)();
|
|
30
|
-
const messageWithUuid = uuid !== message.uuid ? { ...message, uuid } : message;
|
|
31
|
-
// Step 1: Serialize to TLV
|
|
32
|
-
const tlvPayload = (0, tlv_js_1.serializeMessage)(messageWithUuid);
|
|
33
|
-
// Step 2: Pad to XorIDA block boundary
|
|
34
|
-
const p = (0, xorida_js_1.nextOddPrime)(n);
|
|
35
|
-
const blockSize = p - 1;
|
|
36
|
-
const padded = (0, padding_js_1.pkcs7Pad)(tlvPayload, blockSize);
|
|
37
|
-
// Step 3: HMAC the padded payload
|
|
38
|
-
const { key: hmacKey, signature: hmacSignature } = await (0, hmac_js_1.generateHMAC)(padded);
|
|
39
|
-
// Step 4: Split via XorIDA
|
|
40
|
-
const shareDataArrays = (0, xorida_js_1.splitXorIDA)(padded, n, k);
|
|
41
|
-
const shares = shareDataArrays.map((data, index) => ({
|
|
42
|
-
uuid,
|
|
43
|
-
index,
|
|
44
|
-
totalShares: n,
|
|
45
|
-
threshold: k,
|
|
46
|
-
data,
|
|
47
|
-
hmacKey: hmacKey.slice(), // each share carries a copy
|
|
48
|
-
hmacSignature: hmacSignature.slice(),
|
|
49
|
-
}));
|
|
50
|
-
return shares;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Reconstruct a XailMessage from k shares.
|
|
54
|
-
*
|
|
55
|
-
* Pipeline: validate → reconstruct → verify HMAC → unpad → deserialize
|
|
56
|
-
*
|
|
57
|
-
* @param shares - Array of k XailShare objects (must share the same UUID)
|
|
58
|
-
* @returns Reconstructed message, or ReconstructionError
|
|
59
|
-
*/
|
|
60
|
-
async function reconstructMessage(shares) {
|
|
61
|
-
// Validation: need at least k shares
|
|
62
|
-
if (shares.length === 0) {
|
|
63
|
-
return (0, shared_1.err)({ code: 'INSUFFICIENT_SHARES', message: 'No shares provided' });
|
|
64
|
-
}
|
|
65
|
-
const first = shares[0];
|
|
66
|
-
const k = first.threshold;
|
|
67
|
-
const n = first.totalShares;
|
|
68
|
-
if (shares.length < k) {
|
|
69
|
-
return (0, shared_1.err)({
|
|
70
|
-
code: 'INSUFFICIENT_SHARES',
|
|
71
|
-
message: `Need ${k} shares, got ${shares.length}`,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
// Validate consistency
|
|
75
|
-
const indices = [];
|
|
76
|
-
const indexSet = new Set();
|
|
77
|
-
for (const share of shares) {
|
|
78
|
-
if (share.uuid !== first.uuid) {
|
|
79
|
-
return (0, shared_1.err)({
|
|
80
|
-
code: 'INVALID_SHARES',
|
|
81
|
-
message: 'Shares have different UUIDs',
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
if (share.totalShares !== n || share.threshold !== k) {
|
|
85
|
-
return (0, shared_1.err)({
|
|
86
|
-
code: 'INVALID_SHARES',
|
|
87
|
-
message: 'Shares have inconsistent n/k values',
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
if (share.index < 0 || share.index >= n) {
|
|
91
|
-
return (0, shared_1.err)({
|
|
92
|
-
code: 'INVALID_INDEX',
|
|
93
|
-
message: `Share index ${share.index} out of range [0, ${n})`,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
if (indexSet.has(share.index)) {
|
|
97
|
-
return (0, shared_1.err)({
|
|
98
|
-
code: 'INVALID_INDEX',
|
|
99
|
-
message: `Duplicate share index ${share.index}`,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
indexSet.add(share.index);
|
|
103
|
-
indices.push(share.index);
|
|
104
|
-
}
|
|
105
|
-
// Take first k shares
|
|
106
|
-
const usedShares = shares.slice(0, k);
|
|
107
|
-
const usedIndices = indices.slice(0, k);
|
|
108
|
-
const shareData = usedShares.map((s) => s.data);
|
|
109
|
-
// Step 1: Reconstruct padded payload
|
|
110
|
-
const padded = (0, xorida_js_1.reconstructXorIDA)(shareData, usedIndices, n, k);
|
|
111
|
-
// Step 2: Verify HMAC (before unpadding — fail closed)
|
|
112
|
-
const hmacValid = await (0, hmac_js_1.verifyHMAC)(first.hmacKey, padded, first.hmacSignature);
|
|
113
|
-
if (!hmacValid) {
|
|
114
|
-
return (0, shared_1.err)({
|
|
115
|
-
code: 'HMAC_FAILURE',
|
|
116
|
-
message: 'HMAC verification failed — data may be corrupted or tampered',
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
// Step 3: Unpad
|
|
120
|
-
const p = (0, xorida_js_1.nextOddPrime)(n);
|
|
121
|
-
const blockSize = p - 1;
|
|
122
|
-
const unpadResult = (0, padding_js_1.pkcs7Unpad)(padded, blockSize);
|
|
123
|
-
if (!unpadResult.ok) {
|
|
124
|
-
return (0, shared_1.err)({
|
|
125
|
-
code: 'HMAC_FAILURE',
|
|
126
|
-
message: `Unpadding failed: ${unpadResult.error.message}`,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
// Step 4: Deserialize TLV
|
|
130
|
-
const msgResult = (0, tlv_js_1.deserializeMessage)(unpadResult.value);
|
|
131
|
-
if (!msgResult.ok) {
|
|
132
|
-
return (0, shared_1.err)({
|
|
133
|
-
code: 'INVALID_SHARES',
|
|
134
|
-
message: `Deserialization failed: ${msgResult.error.message}`,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
// UUID cross-check: if the TLV payload contains a UUID, it must match the envelope UUID.
|
|
138
|
-
// Normalize both to lowercase+trimmed — bytesToUuid() always returns lowercase,
|
|
139
|
-
// but envelope UUIDs from email headers may differ in casing or have whitespace.
|
|
140
|
-
const tlvUuid = msgResult.value.uuid;
|
|
141
|
-
if (tlvUuid && tlvUuid.toLowerCase().trim() !== first.uuid.toLowerCase().trim()) {
|
|
142
|
-
return (0, shared_1.err)({
|
|
143
|
-
code: 'UUID_MISMATCH',
|
|
144
|
-
message: 'TLV UUID does not match envelope UUID',
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
// The share headers carry the authoritative UUID (X-Xail-UUID).
|
|
148
|
-
// The TLV payload may have a stale or empty UUID if the sender didn't
|
|
149
|
-
// pre-populate message.uuid before calling createShares(). Stamp the
|
|
150
|
-
// share-header UUID onto the reconstructed message.
|
|
151
|
-
return (0, shared_1.ok)({ ...msgResult.value, uuid: first.uuid });
|
|
152
|
-
}
|