@omnituum/pqc-shared 0.2.6

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.
Files changed (67) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +543 -0
  3. package/dist/crypto/index.cjs +807 -0
  4. package/dist/crypto/index.d.cts +641 -0
  5. package/dist/crypto/index.d.ts +641 -0
  6. package/dist/crypto/index.js +716 -0
  7. package/dist/decrypt-eSHlbh1j.d.cts +321 -0
  8. package/dist/decrypt-eSHlbh1j.d.ts +321 -0
  9. package/dist/fs/index.cjs +1168 -0
  10. package/dist/fs/index.d.cts +400 -0
  11. package/dist/fs/index.d.ts +400 -0
  12. package/dist/fs/index.js +1091 -0
  13. package/dist/index.cjs +2160 -0
  14. package/dist/index.d.cts +282 -0
  15. package/dist/index.d.ts +282 -0
  16. package/dist/index.js +2031 -0
  17. package/dist/integrity-CCYjrap3.d.ts +31 -0
  18. package/dist/integrity-Dx9jukMH.d.cts +31 -0
  19. package/dist/types-61c7Q9ri.d.ts +134 -0
  20. package/dist/types-Ch0y-n7K.d.cts +134 -0
  21. package/dist/utils/index.cjs +129 -0
  22. package/dist/utils/index.d.cts +49 -0
  23. package/dist/utils/index.d.ts +49 -0
  24. package/dist/utils/index.js +114 -0
  25. package/dist/vault/index.cjs +713 -0
  26. package/dist/vault/index.d.cts +237 -0
  27. package/dist/vault/index.d.ts +237 -0
  28. package/dist/vault/index.js +677 -0
  29. package/dist/version-BygzPVGs.d.cts +55 -0
  30. package/dist/version-BygzPVGs.d.ts +55 -0
  31. package/package.json +86 -0
  32. package/src/crypto/dilithium.ts +233 -0
  33. package/src/crypto/hybrid.ts +358 -0
  34. package/src/crypto/index.ts +181 -0
  35. package/src/crypto/kyber.ts +199 -0
  36. package/src/crypto/nacl.ts +204 -0
  37. package/src/crypto/primitives/blake3.ts +141 -0
  38. package/src/crypto/primitives/chacha.ts +211 -0
  39. package/src/crypto/primitives/hkdf.ts +192 -0
  40. package/src/crypto/primitives/index.ts +54 -0
  41. package/src/crypto/primitives.ts +144 -0
  42. package/src/crypto/x25519.ts +134 -0
  43. package/src/fs/aes.ts +343 -0
  44. package/src/fs/argon2.ts +184 -0
  45. package/src/fs/browser.ts +408 -0
  46. package/src/fs/decrypt.ts +320 -0
  47. package/src/fs/encrypt.ts +324 -0
  48. package/src/fs/format.ts +425 -0
  49. package/src/fs/index.ts +144 -0
  50. package/src/fs/types.ts +304 -0
  51. package/src/index.ts +414 -0
  52. package/src/kdf/index.ts +311 -0
  53. package/src/runtime/crypto.ts +16 -0
  54. package/src/security/index.ts +345 -0
  55. package/src/tunnel/index.ts +39 -0
  56. package/src/tunnel/session.ts +229 -0
  57. package/src/tunnel/types.ts +115 -0
  58. package/src/utils/entropy.ts +128 -0
  59. package/src/utils/index.ts +25 -0
  60. package/src/utils/integrity.ts +95 -0
  61. package/src/vault/decrypt.ts +167 -0
  62. package/src/vault/encrypt.ts +207 -0
  63. package/src/vault/index.ts +71 -0
  64. package/src/vault/manager.ts +327 -0
  65. package/src/vault/migrate.ts +190 -0
  66. package/src/vault/types.ts +177 -0
  67. package/src/version.ts +304 -0
@@ -0,0 +1,31 @@
1
+ import { H as HybridIdentityRecord } from './types-61c7Q9ri.js';
2
+
3
+ /**
4
+ * Omnituum PQC Shared - Integrity Verification
5
+ *
6
+ * SHA-256 based integrity checking for vault contents.
7
+ */
8
+
9
+ /**
10
+ * Compute SHA-256 integrity hash for a list of identities.
11
+ * Uses only the public keys and metadata to create a deterministic hash.
12
+ */
13
+ declare function computeIntegrityHash(identities: HybridIdentityRecord[]): string;
14
+ /**
15
+ * Compute SHA-256 hash asynchronously using Web Crypto or Node fallback.
16
+ */
17
+ declare function computeHashAsync(data: string): Promise<string>;
18
+ /**
19
+ * Verify vault integrity.
20
+ */
21
+ declare function verifyIntegrity(identities: HybridIdentityRecord[], expectedHash: string): Promise<boolean>;
22
+ /**
23
+ * Compute a short fingerprint for an identity's public keys.
24
+ */
25
+ declare function computeKeyFingerprint(identity: HybridIdentityRecord): Promise<string>;
26
+ /**
27
+ * Format a fingerprint for display (groups of 4).
28
+ */
29
+ declare function formatFingerprint(fingerprint: string): string;
30
+
31
+ export { computeHashAsync as a, computeKeyFingerprint as b, computeIntegrityHash as c, formatFingerprint as f, verifyIntegrity as v };
@@ -0,0 +1,31 @@
1
+ import { H as HybridIdentityRecord } from './types-Ch0y-n7K.cjs';
2
+
3
+ /**
4
+ * Omnituum PQC Shared - Integrity Verification
5
+ *
6
+ * SHA-256 based integrity checking for vault contents.
7
+ */
8
+
9
+ /**
10
+ * Compute SHA-256 integrity hash for a list of identities.
11
+ * Uses only the public keys and metadata to create a deterministic hash.
12
+ */
13
+ declare function computeIntegrityHash(identities: HybridIdentityRecord[]): string;
14
+ /**
15
+ * Compute SHA-256 hash asynchronously using Web Crypto or Node fallback.
16
+ */
17
+ declare function computeHashAsync(data: string): Promise<string>;
18
+ /**
19
+ * Verify vault integrity.
20
+ */
21
+ declare function verifyIntegrity(identities: HybridIdentityRecord[], expectedHash: string): Promise<boolean>;
22
+ /**
23
+ * Compute a short fingerprint for an identity's public keys.
24
+ */
25
+ declare function computeKeyFingerprint(identity: HybridIdentityRecord): Promise<string>;
26
+ /**
27
+ * Format a fingerprint for display (groups of 4).
28
+ */
29
+ declare function formatFingerprint(fingerprint: string): string;
30
+
31
+ export { computeHashAsync as a, computeKeyFingerprint as b, computeIntegrityHash as c, formatFingerprint as f, verifyIntegrity as v };
@@ -0,0 +1,134 @@
1
+ import { V as VAULT_VERSION, a as VAULT_ENCRYPTED_VERSION, b as VAULT_KDF, c as VAULT_ALGORITHM, d as VAULT_ENCRYPTED_VERSION_V2, e as VAULT_KDF_V2 } from './version-BygzPVGs.js';
2
+
3
+ /**
4
+ * Omnituum PQC Shared - Vault Types
5
+ *
6
+ * Type definitions for the PQC identity vault.
7
+ * FROZEN CONTRACTS - see pqc-docs/specs/vault.v1.md
8
+ */
9
+
10
+ interface HybridIdentityRecord {
11
+ /** Unique identity ID */
12
+ id: string;
13
+ /** Display name */
14
+ name: string;
15
+ /** X25519 public key (hex) */
16
+ x25519PubHex: string;
17
+ /** X25519 secret key (hex) - encrypted in vault */
18
+ x25519SecHex: string;
19
+ /** Kyber public key (base64) */
20
+ kyberPubB64: string;
21
+ /** Kyber secret key (base64) - encrypted in vault */
22
+ kyberSecB64: string;
23
+ /** Creation timestamp */
24
+ createdAt: string;
25
+ /** Last rotation timestamp */
26
+ lastRotatedAt?: string;
27
+ /** Device fingerprint */
28
+ deviceFingerprint?: string;
29
+ /** Key rotation count */
30
+ rotationCount: number;
31
+ /** Identity metadata */
32
+ metadata?: {
33
+ label?: string;
34
+ notes?: string;
35
+ tags?: string[];
36
+ };
37
+ }
38
+ interface VaultSettings {
39
+ /** Auto-unlock on return (session memory) */
40
+ autoUnlock: boolean;
41
+ /** Last used identity ID */
42
+ lastUsedIdentity?: string;
43
+ /** Lock timeout in minutes (0 = never auto-lock) */
44
+ lockTimeout: number;
45
+ /** Show key fingerprints in UI */
46
+ showFingerprints: boolean;
47
+ }
48
+ interface OmnituumVault {
49
+ /** Vault format version (FROZEN - see pqc-docs/specs/vault.v1.md) */
50
+ version: typeof VAULT_VERSION;
51
+ /** Stored identities */
52
+ identities: HybridIdentityRecord[];
53
+ /** Vault settings */
54
+ settings: VaultSettings;
55
+ /** SHA-256 hash of serialized identities (integrity check) */
56
+ integrityHash: string;
57
+ /** Vault creation timestamp */
58
+ createdAt: string;
59
+ /** Last modified timestamp */
60
+ modifiedAt: string;
61
+ }
62
+ /** V1 encrypted vault (PBKDF2) */
63
+ interface EncryptedVaultFileV1 {
64
+ /** File format version (FROZEN - see pqc-docs/specs/vault.v1.md) */
65
+ version: typeof VAULT_ENCRYPTED_VERSION;
66
+ /** Key derivation function */
67
+ kdf: typeof VAULT_KDF;
68
+ /** PBKDF2 iterations */
69
+ iterations: number;
70
+ /** Salt (base64) */
71
+ salt: string;
72
+ /** AES-GCM IV (base64) */
73
+ iv: string;
74
+ /** Encrypted vault (base64) */
75
+ ciphertext: string;
76
+ /** Auth tag included in ciphertext (AES-GCM) */
77
+ algorithm: typeof VAULT_ALGORITHM;
78
+ }
79
+ /** V2 encrypted vault (Argon2id) */
80
+ interface EncryptedVaultFileV2 {
81
+ /** File format version */
82
+ version: typeof VAULT_ENCRYPTED_VERSION_V2;
83
+ /** Key derivation function */
84
+ kdf: typeof VAULT_KDF_V2;
85
+ /** Argon2id memory cost (KiB) */
86
+ memoryCost: number;
87
+ /** Argon2id time cost (iterations) */
88
+ timeCost: number;
89
+ /** Argon2id parallelism */
90
+ parallelism: number;
91
+ /** Salt (base64) */
92
+ salt: string;
93
+ /** AES-GCM IV (base64) */
94
+ iv: string;
95
+ /** Encrypted vault (base64) */
96
+ ciphertext: string;
97
+ /** Auth tag included in ciphertext (AES-GCM) */
98
+ algorithm: typeof VAULT_ALGORITHM;
99
+ }
100
+ /** Union type for any encrypted vault version */
101
+ type EncryptedVaultFile = EncryptedVaultFileV1 | EncryptedVaultFileV2;
102
+ type HealthStatus = 'healthy' | 'needs-rotation' | 'warning' | 'error';
103
+ interface IdentityHealth {
104
+ /** Overall health status */
105
+ status: HealthStatus;
106
+ /** Entropy score (0-100) */
107
+ entropyScore: number;
108
+ /** Integrity verified */
109
+ integrityValid: boolean;
110
+ /** SHA-256 fingerprint */
111
+ fingerprint: string;
112
+ /** Days since last rotation */
113
+ daysSinceRotation: number;
114
+ /** Kyber key valid */
115
+ kyberValid: boolean;
116
+ /** X25519 key valid */
117
+ x25519Valid: boolean;
118
+ /** Recommendations */
119
+ recommendations: string[];
120
+ }
121
+ interface VaultSession {
122
+ /** Session active */
123
+ unlocked: boolean;
124
+ /** Derived encryption key (in memory only) */
125
+ sessionKey: CryptoKey | null;
126
+ /** Unlock timestamp */
127
+ unlockedAt: number | null;
128
+ /** Active identity ID */
129
+ activeIdentityId: string | null;
130
+ }
131
+ declare const DEFAULT_VAULT_SETTINGS: VaultSettings;
132
+ declare const PBKDF2_ITERATIONS = 600000;
133
+
134
+ export { DEFAULT_VAULT_SETTINGS as D, type EncryptedVaultFile as E, type HybridIdentityRecord as H, type IdentityHealth as I, type OmnituumVault as O, PBKDF2_ITERATIONS as P, type VaultSettings as V, type EncryptedVaultFileV2 as a, type VaultSession as b, type EncryptedVaultFileV1 as c, type HealthStatus as d };
@@ -0,0 +1,134 @@
1
+ import { V as VAULT_VERSION, a as VAULT_ENCRYPTED_VERSION, b as VAULT_KDF, c as VAULT_ALGORITHM, d as VAULT_ENCRYPTED_VERSION_V2, e as VAULT_KDF_V2 } from './version-BygzPVGs.cjs';
2
+
3
+ /**
4
+ * Omnituum PQC Shared - Vault Types
5
+ *
6
+ * Type definitions for the PQC identity vault.
7
+ * FROZEN CONTRACTS - see pqc-docs/specs/vault.v1.md
8
+ */
9
+
10
+ interface HybridIdentityRecord {
11
+ /** Unique identity ID */
12
+ id: string;
13
+ /** Display name */
14
+ name: string;
15
+ /** X25519 public key (hex) */
16
+ x25519PubHex: string;
17
+ /** X25519 secret key (hex) - encrypted in vault */
18
+ x25519SecHex: string;
19
+ /** Kyber public key (base64) */
20
+ kyberPubB64: string;
21
+ /** Kyber secret key (base64) - encrypted in vault */
22
+ kyberSecB64: string;
23
+ /** Creation timestamp */
24
+ createdAt: string;
25
+ /** Last rotation timestamp */
26
+ lastRotatedAt?: string;
27
+ /** Device fingerprint */
28
+ deviceFingerprint?: string;
29
+ /** Key rotation count */
30
+ rotationCount: number;
31
+ /** Identity metadata */
32
+ metadata?: {
33
+ label?: string;
34
+ notes?: string;
35
+ tags?: string[];
36
+ };
37
+ }
38
+ interface VaultSettings {
39
+ /** Auto-unlock on return (session memory) */
40
+ autoUnlock: boolean;
41
+ /** Last used identity ID */
42
+ lastUsedIdentity?: string;
43
+ /** Lock timeout in minutes (0 = never auto-lock) */
44
+ lockTimeout: number;
45
+ /** Show key fingerprints in UI */
46
+ showFingerprints: boolean;
47
+ }
48
+ interface OmnituumVault {
49
+ /** Vault format version (FROZEN - see pqc-docs/specs/vault.v1.md) */
50
+ version: typeof VAULT_VERSION;
51
+ /** Stored identities */
52
+ identities: HybridIdentityRecord[];
53
+ /** Vault settings */
54
+ settings: VaultSettings;
55
+ /** SHA-256 hash of serialized identities (integrity check) */
56
+ integrityHash: string;
57
+ /** Vault creation timestamp */
58
+ createdAt: string;
59
+ /** Last modified timestamp */
60
+ modifiedAt: string;
61
+ }
62
+ /** V1 encrypted vault (PBKDF2) */
63
+ interface EncryptedVaultFileV1 {
64
+ /** File format version (FROZEN - see pqc-docs/specs/vault.v1.md) */
65
+ version: typeof VAULT_ENCRYPTED_VERSION;
66
+ /** Key derivation function */
67
+ kdf: typeof VAULT_KDF;
68
+ /** PBKDF2 iterations */
69
+ iterations: number;
70
+ /** Salt (base64) */
71
+ salt: string;
72
+ /** AES-GCM IV (base64) */
73
+ iv: string;
74
+ /** Encrypted vault (base64) */
75
+ ciphertext: string;
76
+ /** Auth tag included in ciphertext (AES-GCM) */
77
+ algorithm: typeof VAULT_ALGORITHM;
78
+ }
79
+ /** V2 encrypted vault (Argon2id) */
80
+ interface EncryptedVaultFileV2 {
81
+ /** File format version */
82
+ version: typeof VAULT_ENCRYPTED_VERSION_V2;
83
+ /** Key derivation function */
84
+ kdf: typeof VAULT_KDF_V2;
85
+ /** Argon2id memory cost (KiB) */
86
+ memoryCost: number;
87
+ /** Argon2id time cost (iterations) */
88
+ timeCost: number;
89
+ /** Argon2id parallelism */
90
+ parallelism: number;
91
+ /** Salt (base64) */
92
+ salt: string;
93
+ /** AES-GCM IV (base64) */
94
+ iv: string;
95
+ /** Encrypted vault (base64) */
96
+ ciphertext: string;
97
+ /** Auth tag included in ciphertext (AES-GCM) */
98
+ algorithm: typeof VAULT_ALGORITHM;
99
+ }
100
+ /** Union type for any encrypted vault version */
101
+ type EncryptedVaultFile = EncryptedVaultFileV1 | EncryptedVaultFileV2;
102
+ type HealthStatus = 'healthy' | 'needs-rotation' | 'warning' | 'error';
103
+ interface IdentityHealth {
104
+ /** Overall health status */
105
+ status: HealthStatus;
106
+ /** Entropy score (0-100) */
107
+ entropyScore: number;
108
+ /** Integrity verified */
109
+ integrityValid: boolean;
110
+ /** SHA-256 fingerprint */
111
+ fingerprint: string;
112
+ /** Days since last rotation */
113
+ daysSinceRotation: number;
114
+ /** Kyber key valid */
115
+ kyberValid: boolean;
116
+ /** X25519 key valid */
117
+ x25519Valid: boolean;
118
+ /** Recommendations */
119
+ recommendations: string[];
120
+ }
121
+ interface VaultSession {
122
+ /** Session active */
123
+ unlocked: boolean;
124
+ /** Derived encryption key (in memory only) */
125
+ sessionKey: CryptoKey | null;
126
+ /** Unlock timestamp */
127
+ unlockedAt: number | null;
128
+ /** Active identity ID */
129
+ activeIdentityId: string | null;
130
+ }
131
+ declare const DEFAULT_VAULT_SETTINGS: VaultSettings;
132
+ declare const PBKDF2_ITERATIONS = 600000;
133
+
134
+ export { DEFAULT_VAULT_SETTINGS as D, type EncryptedVaultFile as E, type HybridIdentityRecord as H, type IdentityHealth as I, type OmnituumVault as O, PBKDF2_ITERATIONS as P, type VaultSettings as V, type EncryptedVaultFileV2 as a, type VaultSession as b, type EncryptedVaultFileV1 as c, type HealthStatus as d };
@@ -0,0 +1,129 @@
1
+ 'use strict';
2
+
3
+ require('@noble/hashes/sha256');
4
+ require('@noble/hashes/hmac');
5
+
6
+ // src/utils/entropy.ts
7
+ function generateId() {
8
+ const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
9
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
10
+ }
11
+ function generateShortId() {
12
+ const bytes = globalThis.crypto.getRandomValues(new Uint8Array(4));
13
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
14
+ }
15
+ function calculateShannonEntropy(bytes) {
16
+ if (bytes.length === 0) return 0;
17
+ const freq = /* @__PURE__ */ new Map();
18
+ for (const byte of bytes) {
19
+ freq.set(byte, (freq.get(byte) || 0) + 1);
20
+ }
21
+ let entropy = 0;
22
+ const len = bytes.length;
23
+ for (const count of freq.values()) {
24
+ const p = count / len;
25
+ entropy -= p * Math.log2(p);
26
+ }
27
+ return entropy;
28
+ }
29
+ function calculateEntropyScore(hexKey) {
30
+ const clean = hexKey.startsWith("0x") ? hexKey.slice(2) : hexKey;
31
+ const bytes = new Uint8Array(clean.length / 2);
32
+ for (let i = 0; i < bytes.length; i++) {
33
+ bytes[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
34
+ }
35
+ const entropy = calculateShannonEntropy(bytes);
36
+ return Math.min(100, Math.round(entropy / 8 * 100));
37
+ }
38
+ function hasGoodEntropy(hexKey, threshold = 70) {
39
+ return calculateEntropyScore(hexKey) >= threshold;
40
+ }
41
+ function isValidX25519Key(hexKey) {
42
+ const clean = hexKey.startsWith("0x") ? hexKey.slice(2) : hexKey;
43
+ return /^[0-9a-fA-F]{64}$/.test(clean);
44
+ }
45
+ function isValidKyberKey(b64Key) {
46
+ try {
47
+ const decoded = atob(b64Key);
48
+ return decoded.length >= 1e3 && decoded.length <= 1500;
49
+ } catch {
50
+ return false;
51
+ }
52
+ }
53
+ function daysSinceRotation(lastRotatedAt, createdAt) {
54
+ const dateStr = lastRotatedAt || createdAt;
55
+ if (!dateStr) return 0;
56
+ const date = new Date(dateStr);
57
+ const now = /* @__PURE__ */ new Date();
58
+ const diffMs = now.getTime() - date.getTime();
59
+ return Math.floor(diffMs / (1e3 * 60 * 60 * 24));
60
+ }
61
+ function shouldRotate(lastRotatedAt, createdAt, maxDays = 90) {
62
+ return daysSinceRotation(lastRotatedAt, createdAt) >= maxDays;
63
+ }
64
+ new TextEncoder();
65
+ new TextDecoder();
66
+ function toHex(bytes) {
67
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
68
+ }
69
+
70
+ // src/utils/integrity.ts
71
+ function computeIntegrityHash(identities) {
72
+ const canonical = identities.map((i) => ({
73
+ id: i.id,
74
+ name: i.name,
75
+ x25519PubHex: i.x25519PubHex,
76
+ kyberPubB64: i.kyberPubB64,
77
+ createdAt: i.createdAt,
78
+ rotationCount: i.rotationCount
79
+ }));
80
+ const serialized = JSON.stringify(canonical, Object.keys(canonical[0] || {}).sort());
81
+ return computeStringHash(serialized);
82
+ }
83
+ function computeStringHash(str) {
84
+ let hash = 0;
85
+ for (let i = 0; i < str.length; i++) {
86
+ const char = str.charCodeAt(i);
87
+ hash = (hash << 5) - hash + char;
88
+ hash = hash & hash;
89
+ }
90
+ return Math.abs(hash).toString(16).padStart(16, "0");
91
+ }
92
+ async function computeHashAsync(data) {
93
+ const encoder = new TextEncoder();
94
+ const bytes = encoder.encode(data);
95
+ const subtle = globalThis.crypto?.subtle;
96
+ if (subtle) {
97
+ const hashBuffer = await subtle.digest("SHA-256", bytes);
98
+ return toHex(new Uint8Array(hashBuffer));
99
+ }
100
+ const { createHash } = await import('crypto');
101
+ return toHex(new Uint8Array(createHash("sha256").update(bytes).digest()));
102
+ }
103
+ async function verifyIntegrity(identities, expectedHash) {
104
+ const computed = computeIntegrityHash(identities);
105
+ return computed === expectedHash;
106
+ }
107
+ async function computeKeyFingerprint(identity) {
108
+ const combined = identity.x25519PubHex + identity.kyberPubB64;
109
+ const hash = await computeHashAsync(combined);
110
+ return hash.slice(0, 16).toUpperCase();
111
+ }
112
+ function formatFingerprint(fingerprint) {
113
+ return fingerprint.match(/.{1,4}/g)?.join(" ") || fingerprint;
114
+ }
115
+
116
+ exports.calculateEntropyScore = calculateEntropyScore;
117
+ exports.calculateShannonEntropy = calculateShannonEntropy;
118
+ exports.computeHashAsync = computeHashAsync;
119
+ exports.computeIntegrityHash = computeIntegrityHash;
120
+ exports.computeKeyFingerprint = computeKeyFingerprint;
121
+ exports.daysSinceRotation = daysSinceRotation;
122
+ exports.formatFingerprint = formatFingerprint;
123
+ exports.generateId = generateId;
124
+ exports.generateShortId = generateShortId;
125
+ exports.hasGoodEntropy = hasGoodEntropy;
126
+ exports.isValidKyberKey = isValidKyberKey;
127
+ exports.isValidX25519Key = isValidX25519Key;
128
+ exports.shouldRotate = shouldRotate;
129
+ exports.verifyIntegrity = verifyIntegrity;
@@ -0,0 +1,49 @@
1
+ export { a as computeHashAsync, c as computeIntegrityHash, b as computeKeyFingerprint, f as formatFingerprint, v as verifyIntegrity } from '../integrity-Dx9jukMH.cjs';
2
+ import '../types-Ch0y-n7K.cjs';
3
+ import '../version-BygzPVGs.cjs';
4
+
5
+ /**
6
+ * Omnituum PQC Shared - Entropy & Randomness Utilities
7
+ *
8
+ * Functions for generating secure random values and measuring entropy.
9
+ */
10
+ /**
11
+ * Generate a cryptographically secure random ID.
12
+ */
13
+ declare function generateId(): string;
14
+ /**
15
+ * Generate a short random ID (8 characters).
16
+ */
17
+ declare function generateShortId(): string;
18
+ /**
19
+ * Calculate Shannon entropy of a byte array.
20
+ * Returns bits per byte (max 8.0 for perfect randomness).
21
+ */
22
+ declare function calculateShannonEntropy(bytes: Uint8Array): number;
23
+ /**
24
+ * Calculate entropy score (0-100) for key material.
25
+ * 100 = perfect entropy, 0 = no entropy.
26
+ */
27
+ declare function calculateEntropyScore(hexKey: string): number;
28
+ /**
29
+ * Check if a key has sufficient entropy.
30
+ */
31
+ declare function hasGoodEntropy(hexKey: string, threshold?: number): boolean;
32
+ /**
33
+ * Validate X25519 public key format.
34
+ */
35
+ declare function isValidX25519Key(hexKey: string): boolean;
36
+ /**
37
+ * Validate Kyber public key format (base64, ~1568 bytes for ML-KEM-768).
38
+ */
39
+ declare function isValidKyberKey(b64Key: string): boolean;
40
+ /**
41
+ * Calculate days since last rotation.
42
+ */
43
+ declare function daysSinceRotation(lastRotatedAt?: string, createdAt?: string): number;
44
+ /**
45
+ * Check if keys should be rotated (default: 90 days).
46
+ */
47
+ declare function shouldRotate(lastRotatedAt?: string, createdAt?: string, maxDays?: number): boolean;
48
+
49
+ export { calculateEntropyScore, calculateShannonEntropy, daysSinceRotation, generateId, generateShortId, hasGoodEntropy, isValidKyberKey, isValidX25519Key, shouldRotate };
@@ -0,0 +1,49 @@
1
+ export { a as computeHashAsync, c as computeIntegrityHash, b as computeKeyFingerprint, f as formatFingerprint, v as verifyIntegrity } from '../integrity-CCYjrap3.js';
2
+ import '../types-61c7Q9ri.js';
3
+ import '../version-BygzPVGs.js';
4
+
5
+ /**
6
+ * Omnituum PQC Shared - Entropy & Randomness Utilities
7
+ *
8
+ * Functions for generating secure random values and measuring entropy.
9
+ */
10
+ /**
11
+ * Generate a cryptographically secure random ID.
12
+ */
13
+ declare function generateId(): string;
14
+ /**
15
+ * Generate a short random ID (8 characters).
16
+ */
17
+ declare function generateShortId(): string;
18
+ /**
19
+ * Calculate Shannon entropy of a byte array.
20
+ * Returns bits per byte (max 8.0 for perfect randomness).
21
+ */
22
+ declare function calculateShannonEntropy(bytes: Uint8Array): number;
23
+ /**
24
+ * Calculate entropy score (0-100) for key material.
25
+ * 100 = perfect entropy, 0 = no entropy.
26
+ */
27
+ declare function calculateEntropyScore(hexKey: string): number;
28
+ /**
29
+ * Check if a key has sufficient entropy.
30
+ */
31
+ declare function hasGoodEntropy(hexKey: string, threshold?: number): boolean;
32
+ /**
33
+ * Validate X25519 public key format.
34
+ */
35
+ declare function isValidX25519Key(hexKey: string): boolean;
36
+ /**
37
+ * Validate Kyber public key format (base64, ~1568 bytes for ML-KEM-768).
38
+ */
39
+ declare function isValidKyberKey(b64Key: string): boolean;
40
+ /**
41
+ * Calculate days since last rotation.
42
+ */
43
+ declare function daysSinceRotation(lastRotatedAt?: string, createdAt?: string): number;
44
+ /**
45
+ * Check if keys should be rotated (default: 90 days).
46
+ */
47
+ declare function shouldRotate(lastRotatedAt?: string, createdAt?: string, maxDays?: number): boolean;
48
+
49
+ export { calculateEntropyScore, calculateShannonEntropy, daysSinceRotation, generateId, generateShortId, hasGoodEntropy, isValidKyberKey, isValidX25519Key, shouldRotate };
@@ -0,0 +1,114 @@
1
+ import '@noble/hashes/sha256';
2
+ import '@noble/hashes/hmac';
3
+
4
+ // src/utils/entropy.ts
5
+ function generateId() {
6
+ const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
7
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
8
+ }
9
+ function generateShortId() {
10
+ const bytes = globalThis.crypto.getRandomValues(new Uint8Array(4));
11
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
12
+ }
13
+ function calculateShannonEntropy(bytes) {
14
+ if (bytes.length === 0) return 0;
15
+ const freq = /* @__PURE__ */ new Map();
16
+ for (const byte of bytes) {
17
+ freq.set(byte, (freq.get(byte) || 0) + 1);
18
+ }
19
+ let entropy = 0;
20
+ const len = bytes.length;
21
+ for (const count of freq.values()) {
22
+ const p = count / len;
23
+ entropy -= p * Math.log2(p);
24
+ }
25
+ return entropy;
26
+ }
27
+ function calculateEntropyScore(hexKey) {
28
+ const clean = hexKey.startsWith("0x") ? hexKey.slice(2) : hexKey;
29
+ const bytes = new Uint8Array(clean.length / 2);
30
+ for (let i = 0; i < bytes.length; i++) {
31
+ bytes[i] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
32
+ }
33
+ const entropy = calculateShannonEntropy(bytes);
34
+ return Math.min(100, Math.round(entropy / 8 * 100));
35
+ }
36
+ function hasGoodEntropy(hexKey, threshold = 70) {
37
+ return calculateEntropyScore(hexKey) >= threshold;
38
+ }
39
+ function isValidX25519Key(hexKey) {
40
+ const clean = hexKey.startsWith("0x") ? hexKey.slice(2) : hexKey;
41
+ return /^[0-9a-fA-F]{64}$/.test(clean);
42
+ }
43
+ function isValidKyberKey(b64Key) {
44
+ try {
45
+ const decoded = atob(b64Key);
46
+ return decoded.length >= 1e3 && decoded.length <= 1500;
47
+ } catch {
48
+ return false;
49
+ }
50
+ }
51
+ function daysSinceRotation(lastRotatedAt, createdAt) {
52
+ const dateStr = lastRotatedAt || createdAt;
53
+ if (!dateStr) return 0;
54
+ const date = new Date(dateStr);
55
+ const now = /* @__PURE__ */ new Date();
56
+ const diffMs = now.getTime() - date.getTime();
57
+ return Math.floor(diffMs / (1e3 * 60 * 60 * 24));
58
+ }
59
+ function shouldRotate(lastRotatedAt, createdAt, maxDays = 90) {
60
+ return daysSinceRotation(lastRotatedAt, createdAt) >= maxDays;
61
+ }
62
+ new TextEncoder();
63
+ new TextDecoder();
64
+ function toHex(bytes) {
65
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
66
+ }
67
+
68
+ // src/utils/integrity.ts
69
+ function computeIntegrityHash(identities) {
70
+ const canonical = identities.map((i) => ({
71
+ id: i.id,
72
+ name: i.name,
73
+ x25519PubHex: i.x25519PubHex,
74
+ kyberPubB64: i.kyberPubB64,
75
+ createdAt: i.createdAt,
76
+ rotationCount: i.rotationCount
77
+ }));
78
+ const serialized = JSON.stringify(canonical, Object.keys(canonical[0] || {}).sort());
79
+ return computeStringHash(serialized);
80
+ }
81
+ function computeStringHash(str) {
82
+ let hash = 0;
83
+ for (let i = 0; i < str.length; i++) {
84
+ const char = str.charCodeAt(i);
85
+ hash = (hash << 5) - hash + char;
86
+ hash = hash & hash;
87
+ }
88
+ return Math.abs(hash).toString(16).padStart(16, "0");
89
+ }
90
+ async function computeHashAsync(data) {
91
+ const encoder = new TextEncoder();
92
+ const bytes = encoder.encode(data);
93
+ const subtle = globalThis.crypto?.subtle;
94
+ if (subtle) {
95
+ const hashBuffer = await subtle.digest("SHA-256", bytes);
96
+ return toHex(new Uint8Array(hashBuffer));
97
+ }
98
+ const { createHash } = await import('crypto');
99
+ return toHex(new Uint8Array(createHash("sha256").update(bytes).digest()));
100
+ }
101
+ async function verifyIntegrity(identities, expectedHash) {
102
+ const computed = computeIntegrityHash(identities);
103
+ return computed === expectedHash;
104
+ }
105
+ async function computeKeyFingerprint(identity) {
106
+ const combined = identity.x25519PubHex + identity.kyberPubB64;
107
+ const hash = await computeHashAsync(combined);
108
+ return hash.slice(0, 16).toUpperCase();
109
+ }
110
+ function formatFingerprint(fingerprint) {
111
+ return fingerprint.match(/.{1,4}/g)?.join(" ") || fingerprint;
112
+ }
113
+
114
+ export { calculateEntropyScore, calculateShannonEntropy, computeHashAsync, computeIntegrityHash, computeKeyFingerprint, daysSinceRotation, formatFingerprint, generateId, generateShortId, hasGoodEntropy, isValidKyberKey, isValidX25519Key, shouldRotate, verifyIntegrity };