@shieldfive/crypto 1.0.0-alpha.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/CHANGELOG.md +81 -0
- package/LICENSE +201 -0
- package/README.md +241 -0
- package/SECURITY.md +123 -0
- package/dist/format/header.d.ts +60 -0
- package/dist/format/header.d.ts.map +1 -0
- package/dist/format/header.js +203 -0
- package/dist/format/header.js.map +1 -0
- package/dist/identity/index.d.ts +117 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +217 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +124 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/encoding.d.ts +33 -0
- package/dist/internal/encoding.d.ts.map +1 -0
- package/dist/internal/encoding.js +136 -0
- package/dist/internal/encoding.js.map +1 -0
- package/dist/internal/hkdf.d.ts +14 -0
- package/dist/internal/hkdf.d.ts.map +1 -0
- package/dist/internal/hkdf.js +27 -0
- package/dist/internal/hkdf.js.map +1 -0
- package/dist/internal/hmac.d.ts +9 -0
- package/dist/internal/hmac.d.ts.map +1 -0
- package/dist/internal/hmac.js +18 -0
- package/dist/internal/hmac.js.map +1 -0
- package/dist/internal/runtime.d.ts +29 -0
- package/dist/internal/runtime.d.ts.map +1 -0
- package/dist/internal/runtime.js +67 -0
- package/dist/internal/runtime.js.map +1 -0
- package/dist/internal/sodium.d.ts +12 -0
- package/dist/internal/sodium.d.ts.map +1 -0
- package/dist/internal/sodium.js +34 -0
- package/dist/internal/sodium.js.map +1 -0
- package/dist/internal/types.d.ts +94 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +65 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/kdf/argon2id.d.ts +72 -0
- package/dist/kdf/argon2id.d.ts.map +1 -0
- package/dist/kdf/argon2id.js +97 -0
- package/dist/kdf/argon2id.js.map +1 -0
- package/dist/migration/v0-bridge.d.ts +94 -0
- package/dist/migration/v0-bridge.d.ts.map +1 -0
- package/dist/migration/v0-bridge.js +203 -0
- package/dist/migration/v0-bridge.js.map +1 -0
- package/dist/streams/aes-gcm-v1.d.ts +76 -0
- package/dist/streams/aes-gcm-v1.d.ts.map +1 -0
- package/dist/streams/aes-gcm-v1.js +322 -0
- package/dist/streams/aes-gcm-v1.js.map +1 -0
- package/dist/suites/aes-gcm-v0/api.d.ts +48 -0
- package/dist/suites/aes-gcm-v0/api.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v0/api.js +110 -0
- package/dist/suites/aes-gcm-v0/api.js.map +1 -0
- package/dist/suites/aes-gcm-v1/api.d.ts +54 -0
- package/dist/suites/aes-gcm-v1/api.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v1/api.js +179 -0
- package/dist/suites/aes-gcm-v1/api.js.map +1 -0
- package/dist/suites/aes-gcm-v1/index.d.ts +56 -0
- package/dist/suites/aes-gcm-v1/index.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v1/index.js +174 -0
- package/dist/suites/aes-gcm-v1/index.js.map +1 -0
- package/dist/suites/pq-hybrid-v1/api.d.ts +40 -0
- package/dist/suites/pq-hybrid-v1/api.d.ts.map +1 -0
- package/dist/suites/pq-hybrid-v1/api.js +157 -0
- package/dist/suites/pq-hybrid-v1/api.js.map +1 -0
- package/dist/suites/pq-hybrid-v1/index.d.ts +101 -0
- package/dist/suites/pq-hybrid-v1/index.d.ts.map +1 -0
- package/dist/suites/pq-hybrid-v1/index.js +225 -0
- package/dist/suites/pq-hybrid-v1/index.js.map +1 -0
- package/dist/suites/xchacha-v1/api.d.ts +29 -0
- package/dist/suites/xchacha-v1/api.d.ts.map +1 -0
- package/dist/suites/xchacha-v1/api.js +151 -0
- package/dist/suites/xchacha-v1/api.js.map +1 -0
- package/dist/suites/xchacha-v1/index.d.ts +50 -0
- package/dist/suites/xchacha-v1/index.d.ts.map +1 -0
- package/dist/suites/xchacha-v1/index.js +133 -0
- package/dist/suites/xchacha-v1/index.js.map +1 -0
- package/package.json +112 -0
- package/spec/format-v0.md +81 -0
- package/spec/format-v1.md +245 -0
- package/spec/key-derivation.md +122 -0
- package/spec/threat-model.md +152 -0
- package/src/format/header.ts +284 -0
- package/src/identity/index.ts +358 -0
- package/src/index.ts +197 -0
- package/src/internal/encoding.ts +153 -0
- package/src/internal/hkdf.ts +47 -0
- package/src/internal/hmac.ts +33 -0
- package/src/internal/runtime.ts +80 -0
- package/src/internal/sodium.ts +38 -0
- package/src/internal/types.ts +128 -0
- package/src/kdf/argon2id.ts +164 -0
- package/src/migration/v0-bridge.ts +347 -0
- package/src/streams/aes-gcm-v1.ts +443 -0
- package/src/suites/aes-gcm-v0/api.ts +155 -0
- package/src/suites/aes-gcm-v1/api.ts +291 -0
- package/src/suites/aes-gcm-v1/index.ts +266 -0
- package/src/suites/pq-hybrid-v1/api.ts +259 -0
- package/src/suites/pq-hybrid-v1/index.ts +343 -0
- package/src/suites/xchacha-v1/api.ts +251 -0
- package/src/suites/xchacha-v1/index.ts +213 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @shieldfive/crypto — open-source, post-quantum-hybrid client-side
|
|
3
|
+
* encryption for cloud storage.
|
|
4
|
+
*
|
|
5
|
+
* Public entry point. Most callers should import from a specific suite
|
|
6
|
+
* subpath instead of the bare module name:
|
|
7
|
+
*
|
|
8
|
+
* import { encryptBlob, decryptBlob } from '@shieldfive/crypto/pq-hybrid-v1'
|
|
9
|
+
* import { encryptBlob, decryptBlob } from '@shieldfive/crypto/aes-gcm-v1'
|
|
10
|
+
* import { encryptBlob, decryptBlob } from '@shieldfive/crypto/xchacha-v1'
|
|
11
|
+
* import { decryptV0 } from '@shieldfive/crypto/legacy-v0'
|
|
12
|
+
*
|
|
13
|
+
* The umbrella `import { ... } from '@shieldfive/crypto'` exposes shared
|
|
14
|
+
* format primitives, type definitions, and an auto-routing decryptor that
|
|
15
|
+
* dispatches by suite ID.
|
|
16
|
+
*/
|
|
17
|
+
export { buildAuthenticatedHeader, buildChunkAad, buildHeaderUnauthenticated, deriveHeaderMacKey, HeaderError, parseHeader, verifyHeaderMac, } from './format/header.js';
|
|
18
|
+
export { CHUNK_AAD_DOMAIN, CHUNK_AAD_LENGTH, DEFAULT_CHUNK_SIZE, FORMAT_MAGIC, FORMAT_MAGIC_LENGTH, HEADER_FIXED_PREFIX_LENGTH, HEADER_SIZES, HKDF_INFO, MAX_CHUNK_SIZE, MAX_TOTAL_CHUNKS, SUITE, SUITE_NAMES, } from './internal/types.js';
|
|
19
|
+
export type { EncryptedFile, ParsedHeader, ProgressCallback, SuiteId, SuiteName, } from './internal/types.js';
|
|
20
|
+
export { base64ToBytes, bytesToBase64, bytesToHex, hexToBytes, concatBytes, } from './internal/encoding.js';
|
|
21
|
+
export { constantTimeEqual, randomBytes, zeroize, } from './internal/runtime.js';
|
|
22
|
+
export * as aesGcmV1 from './suites/aes-gcm-v1/api.js';
|
|
23
|
+
export * as xchachaV1 from './suites/xchacha-v1/api.js';
|
|
24
|
+
export * as pqHybridV1 from './suites/pq-hybrid-v1/api.js';
|
|
25
|
+
export * as legacyV0 from './suites/aes-gcm-v0/api.js';
|
|
26
|
+
export * as streamsAesGcmV1 from './streams/aes-gcm-v1.js';
|
|
27
|
+
export * as kdfArgon2id from './kdf/argon2id.js';
|
|
28
|
+
export * as identity from './identity/index.js';
|
|
29
|
+
export * as migrationV0 from './migration/v0-bridge.js';
|
|
30
|
+
export interface AutoDecryptOptions {
|
|
31
|
+
blob: Blob;
|
|
32
|
+
/** Used for AES-GCM-v1 and XChaCha-v1 (32-byte raw content key) */
|
|
33
|
+
contentKey?: Uint8Array;
|
|
34
|
+
/** Required for PQ-hybrid: ML-KEM-1024 secret key (3168 bytes) */
|
|
35
|
+
recipientSecretKey?: Uint8Array;
|
|
36
|
+
/** Required for PQ-hybrid: classical 32-byte envelope key */
|
|
37
|
+
envelopeKey?: Uint8Array;
|
|
38
|
+
/** Optional progress callback (0..1) */
|
|
39
|
+
onProgress?: (progress: number) => void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Decrypt a v1-format blob, automatically dispatching to the correct suite
|
|
43
|
+
* based on the header's suite byte. Throws if the suite requires inputs the
|
|
44
|
+
* caller didn't provide. For v0 (legacy) files, use `legacyV0.decryptV0`
|
|
45
|
+
* directly — v0 has no header, so the dispatcher cannot route to it.
|
|
46
|
+
*/
|
|
47
|
+
export declare function autoDecryptBlob(options: AutoDecryptOptions): Promise<Blob>;
|
|
48
|
+
/** Library version, also written into format documentation. */
|
|
49
|
+
export declare const SHIELDFIVE_CRYPTO_VERSION = "1.0.0-alpha.2";
|
|
50
|
+
/** Default cipher suite for new files when not specified by the caller. */
|
|
51
|
+
export declare const DEFAULT_SUITE: 3;
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,EACL,wBAAwB,EACxB,aAAa,EACb,0BAA0B,EAC1B,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,eAAe,GAChB,MAAM,oBAAoB,CAAA;AAK3B,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,0BAA0B,EAC1B,YAAY,EACZ,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,KAAK,EACL,WAAW,GACZ,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,OAAO,EACP,SAAS,GACV,MAAM,qBAAqB,CAAA;AAK5B,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,WAAW,GACZ,MAAM,wBAAwB,CAAA;AAK/B,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,OAAO,GACR,MAAM,uBAAuB,CAAA;AAK9B,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAA;AACtD,OAAO,KAAK,SAAS,MAAM,4BAA4B,CAAA;AACvD,OAAO,KAAK,UAAU,MAAM,8BAA8B,CAAA;AAC1D,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAA;AACtD,OAAO,KAAK,eAAe,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,OAAO,KAAK,WAAW,MAAM,0BAA0B,CAAA;AAWvD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,IAAI,CAAA;IACV,mEAAmE;IACnE,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,kEAAkE;IAClE,kBAAkB,CAAC,EAAE,UAAU,CAAA;IAC/B,6DAA6D;IAC7D,WAAW,CAAC,EAAE,UAAU,CAAA;IACxB,wCAAwC;IACxC,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,IAAI,CAAC,CA0Ef;AAED,+DAA+D;AAC/D,eAAO,MAAM,yBAAyB,kBAAkB,CAAA;AAExD,2EAA2E;AAC3E,eAAO,MAAM,aAAa,GAAuC,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @shieldfive/crypto — open-source, post-quantum-hybrid client-side
|
|
3
|
+
* encryption for cloud storage.
|
|
4
|
+
*
|
|
5
|
+
* Public entry point. Most callers should import from a specific suite
|
|
6
|
+
* subpath instead of the bare module name:
|
|
7
|
+
*
|
|
8
|
+
* import { encryptBlob, decryptBlob } from '@shieldfive/crypto/pq-hybrid-v1'
|
|
9
|
+
* import { encryptBlob, decryptBlob } from '@shieldfive/crypto/aes-gcm-v1'
|
|
10
|
+
* import { encryptBlob, decryptBlob } from '@shieldfive/crypto/xchacha-v1'
|
|
11
|
+
* import { decryptV0 } from '@shieldfive/crypto/legacy-v0'
|
|
12
|
+
*
|
|
13
|
+
* The umbrella `import { ... } from '@shieldfive/crypto'` exposes shared
|
|
14
|
+
* format primitives, type definitions, and an auto-routing decryptor that
|
|
15
|
+
* dispatches by suite ID.
|
|
16
|
+
*/
|
|
17
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
18
|
+
// Format primitives
|
|
19
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
20
|
+
export { buildAuthenticatedHeader, buildChunkAad, buildHeaderUnauthenticated, deriveHeaderMacKey, HeaderError, parseHeader, verifyHeaderMac, } from './format/header.js';
|
|
21
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
22
|
+
// Type definitions and constants
|
|
23
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
24
|
+
export { CHUNK_AAD_DOMAIN, CHUNK_AAD_LENGTH, DEFAULT_CHUNK_SIZE, FORMAT_MAGIC, FORMAT_MAGIC_LENGTH, HEADER_FIXED_PREFIX_LENGTH, HEADER_SIZES, HKDF_INFO, MAX_CHUNK_SIZE, MAX_TOTAL_CHUNKS, SUITE, SUITE_NAMES, } from './internal/types.js';
|
|
25
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
26
|
+
// Encoding utilities (base64, hex, uint codecs)
|
|
27
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
28
|
+
export { base64ToBytes, bytesToBase64, bytesToHex, hexToBytes, concatBytes, } from './internal/encoding.js';
|
|
29
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
30
|
+
// Runtime helpers
|
|
31
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
32
|
+
export { constantTimeEqual, randomBytes, zeroize, } from './internal/runtime.js';
|
|
33
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
34
|
+
// Re-export suite namespaces for direct consumption
|
|
35
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
36
|
+
export * as aesGcmV1 from './suites/aes-gcm-v1/api.js';
|
|
37
|
+
export * as xchachaV1 from './suites/xchacha-v1/api.js';
|
|
38
|
+
export * as pqHybridV1 from './suites/pq-hybrid-v1/api.js';
|
|
39
|
+
export * as legacyV0 from './suites/aes-gcm-v0/api.js';
|
|
40
|
+
export * as streamsAesGcmV1 from './streams/aes-gcm-v1.js';
|
|
41
|
+
export * as kdfArgon2id from './kdf/argon2id.js';
|
|
42
|
+
export * as identity from './identity/index.js';
|
|
43
|
+
export * as migrationV0 from './migration/v0-bridge.js';
|
|
44
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
45
|
+
// Auto-routing decryptor
|
|
46
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
47
|
+
import { parseHeader, HeaderError } from './format/header.js';
|
|
48
|
+
import { SUITE } from './internal/types.js';
|
|
49
|
+
import * as aes from './suites/aes-gcm-v1/api.js';
|
|
50
|
+
import * as xchacha from './suites/xchacha-v1/api.js';
|
|
51
|
+
import * as pqHybrid from './suites/pq-hybrid-v1/api.js';
|
|
52
|
+
/**
|
|
53
|
+
* Decrypt a v1-format blob, automatically dispatching to the correct suite
|
|
54
|
+
* based on the header's suite byte. Throws if the suite requires inputs the
|
|
55
|
+
* caller didn't provide. For v0 (legacy) files, use `legacyV0.decryptV0`
|
|
56
|
+
* directly — v0 has no header, so the dispatcher cannot route to it.
|
|
57
|
+
*/
|
|
58
|
+
export async function autoDecryptBlob(options) {
|
|
59
|
+
const { blob } = options;
|
|
60
|
+
if (!(blob instanceof Blob)) {
|
|
61
|
+
throw new TypeError('autoDecryptBlob: blob must be a Blob or File');
|
|
62
|
+
}
|
|
63
|
+
const headerProbe = new Uint8Array(await blob.slice(0, Math.min(blob.size, 4096)).arrayBuffer());
|
|
64
|
+
let suite;
|
|
65
|
+
try {
|
|
66
|
+
const parsed = parseHeader(headerProbe);
|
|
67
|
+
suite = parsed.suite;
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
// If parse fails because of a too-short probe, escalate. Suites with
|
|
71
|
+
// larger suite_payloads (notably PQ hybrid at 1664 bytes) need more.
|
|
72
|
+
if (err instanceof HeaderError && err.code === 'header_too_short') {
|
|
73
|
+
const bigger = new Uint8Array(await blob
|
|
74
|
+
.slice(0, Math.min(blob.size, 4 + 0xffff + 64))
|
|
75
|
+
.arrayBuffer());
|
|
76
|
+
const parsed = parseHeader(bigger);
|
|
77
|
+
suite = parsed.suite;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
switch (suite) {
|
|
84
|
+
case SUITE.AES_256_GCM_V1: {
|
|
85
|
+
if (!options.contentKey) {
|
|
86
|
+
throw new Error('autoDecryptBlob: contentKey required for aes-256-gcm-v1');
|
|
87
|
+
}
|
|
88
|
+
return aes.decryptBlob({
|
|
89
|
+
blob,
|
|
90
|
+
contentKey: options.contentKey,
|
|
91
|
+
...(options.onProgress ? { onProgress: options.onProgress } : {}),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
case SUITE.XCHACHA20_POLY1305_V1: {
|
|
95
|
+
if (!options.contentKey) {
|
|
96
|
+
throw new Error('autoDecryptBlob: contentKey required for xchacha20-poly1305-v1');
|
|
97
|
+
}
|
|
98
|
+
return xchacha.decryptBlob({
|
|
99
|
+
blob,
|
|
100
|
+
contentKey: options.contentKey,
|
|
101
|
+
...(options.onProgress ? { onProgress: options.onProgress } : {}),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
case SUITE.PQ_HYBRID_XCHACHA_MLKEM1024_V1: {
|
|
105
|
+
if (!options.recipientSecretKey || !options.envelopeKey) {
|
|
106
|
+
throw new Error('autoDecryptBlob: recipientSecretKey and envelopeKey required for pq-hybrid-v1');
|
|
107
|
+
}
|
|
108
|
+
return pqHybrid.decryptBlob({
|
|
109
|
+
blob,
|
|
110
|
+
recipientSecretKey: options.recipientSecretKey,
|
|
111
|
+
envelopeKey: options.envelopeKey,
|
|
112
|
+
...(options.onProgress ? { onProgress: options.onProgress } : {}),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
default: {
|
|
116
|
+
throw new HeaderError(`autoDecryptBlob: unknown suite 0x${suite.toString(16)}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** Library version, also written into format documentation. */
|
|
121
|
+
export const SHIELDFIVE_CRYPTO_VERSION = '1.0.0-alpha.2';
|
|
122
|
+
/** Default cipher suite for new files when not specified by the caller. */
|
|
123
|
+
export const DEFAULT_SUITE = SUITE.PQ_HYBRID_XCHACHA_MLKEM1024_V1;
|
|
124
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,yEAAyE;AACzE,oBAAoB;AACpB,yEAAyE;AACzE,OAAO,EACL,wBAAwB,EACxB,aAAa,EACb,0BAA0B,EAC1B,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,eAAe,GAChB,MAAM,oBAAoB,CAAA;AAE3B,yEAAyE;AACzE,iCAAiC;AACjC,yEAAyE;AACzE,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,0BAA0B,EAC1B,YAAY,EACZ,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,KAAK,EACL,WAAW,GACZ,MAAM,qBAAqB,CAAA;AAS5B,yEAAyE;AACzE,gDAAgD;AAChD,yEAAyE;AACzE,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,WAAW,GACZ,MAAM,wBAAwB,CAAA;AAE/B,yEAAyE;AACzE,kBAAkB;AAClB,yEAAyE;AACzE,OAAO,EACL,iBAAiB,EACjB,WAA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,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAClE,CAAC,CAAA;QACJ,CAAC;QACD,KAAK,KAAK,CAAC,8BAA8B,CAAC,CAAC,CAAC;YAC1C,IAAI,CAAC,OAAO,CAAC,kBAAkB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;gBACxD,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAA;YACH,CAAC;YACD,OAAO,QAAQ,CAAC,WAAW,CAAC;gBAC1B,IAAI;gBACJ,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;gBAC9C,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAClE,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,IAAI,WAAW,CACnB,oCAAqC,KAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CACrE,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED,+DAA+D;AAC/D,MAAM,CAAC,MAAM,yBAAyB,GAAG,eAAe,CAAA;AAExD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC,8BAA8B,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cast helper: TypeScript 5.7+ distinguishes Uint8Array<ArrayBuffer> from
|
|
3
|
+
* Uint8Array<ArrayBufferLike>. Blob and many Web Crypto APIs require the
|
|
4
|
+
* narrower variant. This helper centralizes the cast so we don't sprinkle
|
|
5
|
+
* `as Uint8Array<ArrayBuffer>` across the codebase.
|
|
6
|
+
*
|
|
7
|
+
* Functionally a no-op at runtime; purely a type annotation.
|
|
8
|
+
*/
|
|
9
|
+
export declare function asBlobPart(bytes: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
10
|
+
/**
|
|
11
|
+
* Byte-level encoding helpers.
|
|
12
|
+
*
|
|
13
|
+
* All multi-byte integer functions are explicitly big-endian to match the
|
|
14
|
+
* v1 wire format. Callers should prefer these over hand-rolled bit-shifting.
|
|
15
|
+
*/
|
|
16
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
17
|
+
export declare function base64ToBytes(value: string): Uint8Array;
|
|
18
|
+
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
19
|
+
export declare function hexToBytes(hex: string): Uint8Array;
|
|
20
|
+
export declare function concatBytes(parts: ReadonlyArray<Uint8Array>): Uint8Array;
|
|
21
|
+
export declare function uint32BE(value: number): Uint8Array;
|
|
22
|
+
export declare function readUint32BE(bytes: Uint8Array, offset?: number): number;
|
|
23
|
+
export declare function uint16BE(value: number): Uint8Array;
|
|
24
|
+
export declare function readUint16BE(bytes: Uint8Array, offset?: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Encode a non-negative integer as 8 big-endian bytes. The library never
|
|
27
|
+
* emits values exceeding Number.MAX_SAFE_INTEGER (2^53 - 1) because the
|
|
28
|
+
* format spec caps total_chunks at 1e9 and plaintext_size is bounded by
|
|
29
|
+
* what JavaScript can sensibly handle.
|
|
30
|
+
*/
|
|
31
|
+
export declare function uint64BE(value: number): Uint8Array;
|
|
32
|
+
export declare function readUint64BE(bytes: Uint8Array, offset?: number): number;
|
|
33
|
+
//# sourceMappingURL=encoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/internal/encoding.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,CAErE;AAED;;;;;GAKG;AAEH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAWvD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAavD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAMpD;AAID,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAYlD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,UAAU,CAUxE;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAOlD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,SAAI,GAAG,MAAM,CAQlE;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAOlD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,SAAI,GAAG,MAAM,CAQlE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAWlD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,SAAI,GAAG,MAAM,CAYlE"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cast helper: TypeScript 5.7+ distinguishes Uint8Array<ArrayBuffer> from
|
|
3
|
+
* Uint8Array<ArrayBufferLike>. Blob and many Web Crypto APIs require the
|
|
4
|
+
* narrower variant. This helper centralizes the cast so we don't sprinkle
|
|
5
|
+
* `as Uint8Array<ArrayBuffer>` across the codebase.
|
|
6
|
+
*
|
|
7
|
+
* Functionally a no-op at runtime; purely a type annotation.
|
|
8
|
+
*/
|
|
9
|
+
export function asBlobPart(bytes) {
|
|
10
|
+
return bytes;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Byte-level encoding helpers.
|
|
14
|
+
*
|
|
15
|
+
* All multi-byte integer functions are explicitly big-endian to match the
|
|
16
|
+
* v1 wire format. Callers should prefer these over hand-rolled bit-shifting.
|
|
17
|
+
*/
|
|
18
|
+
export function bytesToBase64(bytes) {
|
|
19
|
+
if (typeof btoa === 'function') {
|
|
20
|
+
let binary = '';
|
|
21
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
22
|
+
binary += String.fromCharCode(bytes[i]);
|
|
23
|
+
}
|
|
24
|
+
return btoa(binary);
|
|
25
|
+
}
|
|
26
|
+
// Node fallback. Uses Buffer; safe in any Node version.
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
28
|
+
return Buffer.from(bytes).toString('base64');
|
|
29
|
+
}
|
|
30
|
+
export function base64ToBytes(value) {
|
|
31
|
+
if (typeof value !== 'string') {
|
|
32
|
+
throw new TypeError('base64ToBytes: input must be a string');
|
|
33
|
+
}
|
|
34
|
+
if (typeof atob === 'function') {
|
|
35
|
+
const binary = atob(value);
|
|
36
|
+
const out = new Uint8Array(binary.length);
|
|
37
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
38
|
+
out[i] = binary.charCodeAt(i);
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
return new Uint8Array(Buffer.from(value, 'base64'));
|
|
43
|
+
}
|
|
44
|
+
export function bytesToHex(bytes) {
|
|
45
|
+
let out = '';
|
|
46
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
47
|
+
out += bytes[i].toString(16).padStart(2, '0');
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
const HEX_RE = /^[0-9a-f]*$/i;
|
|
52
|
+
export function hexToBytes(hex) {
|
|
53
|
+
if (typeof hex !== 'string') {
|
|
54
|
+
throw new TypeError('hexToBytes: input must be a string');
|
|
55
|
+
}
|
|
56
|
+
if (hex.length % 2 !== 0 || !HEX_RE.test(hex)) {
|
|
57
|
+
throw new TypeError('hexToBytes: input must be even-length hexadecimal');
|
|
58
|
+
}
|
|
59
|
+
const out = new Uint8Array(hex.length / 2);
|
|
60
|
+
for (let i = 0; i < out.length; i += 1) {
|
|
61
|
+
out[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
export function concatBytes(parts) {
|
|
66
|
+
let total = 0;
|
|
67
|
+
for (const part of parts)
|
|
68
|
+
total += part.length;
|
|
69
|
+
const out = new Uint8Array(total);
|
|
70
|
+
let offset = 0;
|
|
71
|
+
for (const part of parts) {
|
|
72
|
+
out.set(part, offset);
|
|
73
|
+
offset += part.length;
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
export function uint32BE(value) {
|
|
78
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > 0xffff_ffff) {
|
|
79
|
+
throw new RangeError('uint32BE: value out of range');
|
|
80
|
+
}
|
|
81
|
+
const out = new Uint8Array(4);
|
|
82
|
+
new DataView(out.buffer).setUint32(0, value, false);
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
export function readUint32BE(bytes, offset = 0) {
|
|
86
|
+
if (offset + 4 > bytes.length) {
|
|
87
|
+
throw new RangeError('readUint32BE: insufficient bytes');
|
|
88
|
+
}
|
|
89
|
+
return new DataView(bytes.buffer, bytes.byteOffset + offset, 4).getUint32(0, false);
|
|
90
|
+
}
|
|
91
|
+
export function uint16BE(value) {
|
|
92
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > 0xffff) {
|
|
93
|
+
throw new RangeError('uint16BE: value out of range');
|
|
94
|
+
}
|
|
95
|
+
const out = new Uint8Array(2);
|
|
96
|
+
new DataView(out.buffer).setUint16(0, value, false);
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
export function readUint16BE(bytes, offset = 0) {
|
|
100
|
+
if (offset + 2 > bytes.length) {
|
|
101
|
+
throw new RangeError('readUint16BE: insufficient bytes');
|
|
102
|
+
}
|
|
103
|
+
return new DataView(bytes.buffer, bytes.byteOffset + offset, 2).getUint16(0, false);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Encode a non-negative integer as 8 big-endian bytes. The library never
|
|
107
|
+
* emits values exceeding Number.MAX_SAFE_INTEGER (2^53 - 1) because the
|
|
108
|
+
* format spec caps total_chunks at 1e9 and plaintext_size is bounded by
|
|
109
|
+
* what JavaScript can sensibly handle.
|
|
110
|
+
*/
|
|
111
|
+
export function uint64BE(value) {
|
|
112
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
113
|
+
throw new RangeError('uint64BE: value must be a non-negative safe integer');
|
|
114
|
+
}
|
|
115
|
+
const out = new Uint8Array(8);
|
|
116
|
+
// Top 4 bytes: high uint32 (value / 2^32, truncated)
|
|
117
|
+
const high = Math.floor(value / 0x1_0000_0000);
|
|
118
|
+
const low = value >>> 0;
|
|
119
|
+
new DataView(out.buffer).setUint32(0, high, false);
|
|
120
|
+
new DataView(out.buffer).setUint32(4, low, false);
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
export function readUint64BE(bytes, offset = 0) {
|
|
124
|
+
if (offset + 8 > bytes.length) {
|
|
125
|
+
throw new RangeError('readUint64BE: insufficient bytes');
|
|
126
|
+
}
|
|
127
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset + offset, 8);
|
|
128
|
+
const high = view.getUint32(0, false);
|
|
129
|
+
const low = view.getUint32(4, false);
|
|
130
|
+
// Reject values that don't fit in a safe JS integer (> 2^53 - 1).
|
|
131
|
+
if (high > 0x1f_ffff) {
|
|
132
|
+
throw new RangeError('readUint64BE: value exceeds Number.MAX_SAFE_INTEGER');
|
|
133
|
+
}
|
|
134
|
+
return high * 0x1_0000_0000 + low;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=encoding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/intern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AClD,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;IACjD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAiB,EAAE,MAAM,GAAG,CAAC;IACxD,IAAI,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;QAC9B,MAAM,IAAI,UAAU,CAAC,kCAAkC,CAAC,CAAA;IAC1D,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,GAAG,MAAM,EAAE,CAAC,CAAC,CAAA;IACrE,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IACrC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IACpC,kEAAkE;IAClE,IAAI,IAAI,GAAG,SAAS,EAAE,CAAC;QACrB,MAAM,IAAI,UAAU,CAAC,qDAAqD,CAAC,CAAA;IAC7E,CAAC;IACD,OAAO,IAAI,GAAG,aAAa,GAAG,GAAG,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HKDF-SHA-256 wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Every domain-separated key the library derives from another key flows
|
|
5
|
+
* through this function. Domain strings are constants in `internal/types.ts`
|
|
6
|
+
* — never construct an `info` parameter ad-hoc at the call site.
|
|
7
|
+
*/
|
|
8
|
+
export declare function hkdfSha256(options: {
|
|
9
|
+
ikm: Uint8Array;
|
|
10
|
+
salt?: Uint8Array;
|
|
11
|
+
info: string;
|
|
12
|
+
length: number;
|
|
13
|
+
}): Promise<Uint8Array>;
|
|
14
|
+
//# sourceMappingURL=hkdf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hkdf.d.ts","sourceRoot":"","sources":["../../src/internal/hkdf.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,wBAAsB,UAAU,CAAC,OAAO,EAAE;IACxC,GAAG,EAAE,UAAU,CAAA;IACf,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf,GAAG,OAAO,CAAC,UAAU,CAAC,CA6BtB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HKDF-SHA-256 wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Every domain-separated key the library derives from another key flows
|
|
5
|
+
* through this function. Domain strings are constants in `internal/types.ts`
|
|
6
|
+
* — never construct an `info` parameter ad-hoc at the call site.
|
|
7
|
+
*/
|
|
8
|
+
import { getSubtle } from './runtime.js';
|
|
9
|
+
const TEXT_ENCODER = new TextEncoder();
|
|
10
|
+
export async function hkdfSha256(options) {
|
|
11
|
+
const { ikm, info, length } = options;
|
|
12
|
+
const salt = options.salt ?? new Uint8Array(32); // SHA-256 zero-salt fallback
|
|
13
|
+
if (!Number.isSafeInteger(length) || length <= 0 || length > 8160) {
|
|
14
|
+
// 8160 = 255 * 32, the HKDF-SHA-256 output bound.
|
|
15
|
+
throw new RangeError('hkdfSha256: length out of range (1..8160)');
|
|
16
|
+
}
|
|
17
|
+
const subtle = getSubtle();
|
|
18
|
+
const baseKey = await subtle.importKey('raw', ikm, 'HKDF', false, ['deriveBits']);
|
|
19
|
+
const bits = await subtle.deriveBits({
|
|
20
|
+
name: 'HKDF',
|
|
21
|
+
hash: 'SHA-256',
|
|
22
|
+
salt: salt,
|
|
23
|
+
info: TEXT_ENCODER.encode(info),
|
|
24
|
+
}, baseKey, length * 8);
|
|
25
|
+
return new Uint8Array(bits);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=hkdf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hkdf.js","sourceRoot":"","sources":["../../src/internal/hkdf.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAA;AAEtC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAKhC;IACC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IACrC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,UAAU,CAAC,EAAE,CAAC,CAAA,CAAC,6BAA6B;IAC7E,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,IAAI,MAAM,GAAG,IAAI,EAAE,CAAC;QAClE,kDAAkD;QAClD,MAAM,IAAI,UAAU,CAAC,2CAA2C,CAAC,CAAA;IACnE,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,SAAS,CACpC,KAAK,EACL,GAA8B,EAC9B,MAAM,EACN,KAAK,EACL,CAAC,YAAY,CAAC,CACf,CAAA;IAED,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,UAAU,CAClC;QACE,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,IAA+B;QACrC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,IAAI,CAA4B;KAC3D,EACD,OAAO,EACP,MAAM,GAAG,CAAC,CACX,CAAA;IAED,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HMAC-SHA-256 wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Used for the file-format header MAC and for any application-level
|
|
5
|
+
* authenticator the library exposes. Always verify with constantTimeEqual.
|
|
6
|
+
*/
|
|
7
|
+
export declare function hmacSha256(key: Uint8Array, data: Uint8Array): Promise<Uint8Array>;
|
|
8
|
+
export declare function hmacSha256Verify(key: Uint8Array, data: Uint8Array, expected: Uint8Array): Promise<boolean>;
|
|
9
|
+
//# sourceMappingURL=hmac.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../../src/internal/hmac.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,UAAU,CAAC,CAWrB;AAED,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,UAAU,GACnB,OAAO,CAAC,OAAO,CAAC,CAGlB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HMAC-SHA-256 wrapper.
|
|
3
|
+
*
|
|
4
|
+
* Used for the file-format header MAC and for any application-level
|
|
5
|
+
* authenticator the library exposes. Always verify with constantTimeEqual.
|
|
6
|
+
*/
|
|
7
|
+
import { constantTimeEqual, getSubtle } from './runtime.js';
|
|
8
|
+
export async function hmacSha256(key, data) {
|
|
9
|
+
const subtle = getSubtle();
|
|
10
|
+
const hmacKey = await subtle.importKey('raw', key, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
|
|
11
|
+
const sig = await subtle.sign('HMAC', hmacKey, data);
|
|
12
|
+
return new Uint8Array(sig);
|
|
13
|
+
}
|
|
14
|
+
export async function hmacSha256Verify(key, data, expected) {
|
|
15
|
+
const computed = await hmacSha256(key, data);
|
|
16
|
+
return constantTimeEqual(computed, expected);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=hmac.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmac.js","sourceRoot":"","sources":["../../src/internal/hmac.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE3D,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAe,EACf,IAAgB;IAEhB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,SAAS,CACpC,KAAK,EACL,GAA8B,EAC9B,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EACjC,KAAK,EACL,CAAC,MAAM,CAAC,CACT,CAAA;IACD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAA+B,CAAC,CAAA;IAC/E,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;AAC5B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,GAAe,EACf,IAAgB,EAChB,QAAoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC5C,OAAO,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;AAC9C,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime detection and validation for the host environment.
|
|
3
|
+
*
|
|
4
|
+
* This module is intentionally tiny. The library targets any environment
|
|
5
|
+
* exposing the WHATWG Web Crypto API at `globalThis.crypto.subtle` —
|
|
6
|
+
* modern browsers, Node 20+, Deno, Bun, Cloudflare Workers, and any
|
|
7
|
+
* compatible WebAssembly runtime.
|
|
8
|
+
*
|
|
9
|
+
* Suites that require additional primitives (Argon2id, ML-KEM,
|
|
10
|
+
* XChaCha20-Poly1305) load those primitives lazily from
|
|
11
|
+
* `libsodium-wrappers-sumo` and `@noble/post-quantum`. Consumers that
|
|
12
|
+
* only use the AES-GCM suite never load those WASM blobs.
|
|
13
|
+
*/
|
|
14
|
+
import type { Crypto, SubtleCrypto } from './types.js';
|
|
15
|
+
export declare function getCrypto(): Crypto;
|
|
16
|
+
export declare function getSubtle(): SubtleCrypto;
|
|
17
|
+
export declare function randomBytes(length: number): Uint8Array;
|
|
18
|
+
/**
|
|
19
|
+
* Constant-time equality for byte arrays. Used wherever a comparison failure
|
|
20
|
+
* could leak timing information (MAC verification, key comparison).
|
|
21
|
+
*/
|
|
22
|
+
export declare function constantTimeEqual(a: Uint8Array | null | undefined, b: Uint8Array | null | undefined): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Best-effort zeroization of secret material. JavaScript engines may have
|
|
25
|
+
* already copied or reallocated the underlying buffer; this is a hint, not
|
|
26
|
+
* a guarantee. Use only for in-process hardening.
|
|
27
|
+
*/
|
|
28
|
+
export declare function zeroize(buffer: Uint8Array): void;
|
|
29
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/internal/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAItD,wBAAgB,SAAS,IAAI,MAAM,CAkBlC;AAED,wBAAgB,SAAS,IAAI,YAAY,CAExC;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAWtD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,EAChC,CAAC,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GAC/B,OAAO,CAQT;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAEhD"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime detection and validation for the host environment.
|
|
3
|
+
*
|
|
4
|
+
* This module is intentionally tiny. The library targets any environment
|
|
5
|
+
* exposing the WHATWG Web Crypto API at `globalThis.crypto.subtle` —
|
|
6
|
+
* modern browsers, Node 20+, Deno, Bun, Cloudflare Workers, and any
|
|
7
|
+
* compatible WebAssembly runtime.
|
|
8
|
+
*
|
|
9
|
+
* Suites that require additional primitives (Argon2id, ML-KEM,
|
|
10
|
+
* XChaCha20-Poly1305) load those primitives lazily from
|
|
11
|
+
* `libsodium-wrappers-sumo` and `@noble/post-quantum`. Consumers that
|
|
12
|
+
* only use the AES-GCM suite never load those WASM blobs.
|
|
13
|
+
*/
|
|
14
|
+
let cachedCrypto = null;
|
|
15
|
+
export function getCrypto() {
|
|
16
|
+
if (cachedCrypto)
|
|
17
|
+
return cachedCrypto;
|
|
18
|
+
const candidate = globalThis.crypto;
|
|
19
|
+
if (!candidate ||
|
|
20
|
+
!candidate.subtle ||
|
|
21
|
+
typeof candidate.getRandomValues !== 'function') {
|
|
22
|
+
throw new Error('shieldfive-crypto: Web Crypto API is not available. ' +
|
|
23
|
+
'This library requires globalThis.crypto with SubtleCrypto support. ' +
|
|
24
|
+
'In Node, use Node 20 or later.');
|
|
25
|
+
}
|
|
26
|
+
cachedCrypto = candidate;
|
|
27
|
+
return candidate;
|
|
28
|
+
}
|
|
29
|
+
export function getSubtle() {
|
|
30
|
+
return getCrypto().subtle;
|
|
31
|
+
}
|
|
32
|
+
export function randomBytes(length) {
|
|
33
|
+
if (!Number.isSafeInteger(length) || length <= 0) {
|
|
34
|
+
throw new RangeError('randomBytes: length must be a positive integer');
|
|
35
|
+
}
|
|
36
|
+
if (length > 65536) {
|
|
37
|
+
// Web Crypto specification limits getRandomValues to 65536 bytes per call.
|
|
38
|
+
throw new RangeError('randomBytes: length exceeds 65536');
|
|
39
|
+
}
|
|
40
|
+
const out = new Uint8Array(length);
|
|
41
|
+
getCrypto().getRandomValues(out);
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Constant-time equality for byte arrays. Used wherever a comparison failure
|
|
46
|
+
* could leak timing information (MAC verification, key comparison).
|
|
47
|
+
*/
|
|
48
|
+
export function constantTimeEqual(a, b) {
|
|
49
|
+
if (!a || !b)
|
|
50
|
+
return false;
|
|
51
|
+
if (a.length !== b.length)
|
|
52
|
+
return false;
|
|
53
|
+
let diff = 0;
|
|
54
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
55
|
+
diff |= a[i] ^ b[i];
|
|
56
|
+
}
|
|
57
|
+
return diff === 0;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Best-effort zeroization of secret material. JavaScript engines may have
|
|
61
|
+
* already copied or reallocated the underlying buffer; this is a hint, not
|
|
62
|
+
* a guarantee. Use only for in-process hardening.
|
|
63
|
+
*/
|
|
64
|
+
export function zeroize(buffer) {
|
|
65
|
+
buffer.fill(0);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/internal/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,IAAI,YAAY,GAAkB,IAAI,CAAA;AAEtC,MAAM,UAAU,SAAS;IACvB,IAAI,YAAY;QAAE,OAAO,YAAY,CAAA;IAErC,MAAM,SAAS,GAAI,UAAkC,CAAC,MAAM,CAAA;IAC5D,IACE,CAAC,SAAS;QACV,CAAC,SAAS,CAAC,MAAM;QACjB,OAAO,SAAS,CAAC,eAAe,KAAK,UAAU,EAC/C,CAAC;QACD,MAAM,IAAI,KAAK,CACb,sDAAsD;YACpD,qEAAqE;YACrE,gCAAgC,CACnC,CAAA;IACH,CAAC;IAED,YAAY,GAAG,SAAS,CAAA;IACxB,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,SAAS,EAAE,CAAC,MAAM,CAAA;AAC3B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,UAAU,CAAC,gDAAgD,CAAC,CAAA;IACxE,CAAC;IACD,IAAI,MAAM,GAAG,KAAK,EAAE,CAAC;QACnB,2EAA2E;QAC3E,MAAM,IAAI,UAAU,CAAC,mCAAmC,CAAC,CAAA;IAC3D,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAA;IAClC,SAAS,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;IAChC,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,CAAgC,EAChC,CAAgC;IAEhC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,KAAK,CAAA;IAC1B,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAA;IACvC,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,CAAE,CAAA;IACvB,CAAC;IACD,OAAO,IAAI,KAAK,CAAC,CAAA;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,MAAkB;IACxC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAChB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy loader for libsodium-wrappers-sumo.
|
|
3
|
+
*
|
|
4
|
+
* libsodium is loaded on demand only when a suite that needs it (XChaCha,
|
|
5
|
+
* PQ hybrid, password-based KDF) is actually used. Consumers using only
|
|
6
|
+
* AES-256-GCM never load the WASM blob.
|
|
7
|
+
*
|
|
8
|
+
* libsodium is declared as an optional peer dependency in package.json.
|
|
9
|
+
* Bundlers should treat it as side-effect-free.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getSodium(): Promise<any>;
|
|
12
|
+
//# sourceMappingURL=sodium.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sodium.d.ts","sourceRoot":"","sources":["../../src/internal/sodium.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,wBAAsB,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,CAuB9C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy loader for libsodium-wrappers-sumo.
|
|
3
|
+
*
|
|
4
|
+
* libsodium is loaded on demand only when a suite that needs it (XChaCha,
|
|
5
|
+
* PQ hybrid, password-based KDF) is actually used. Consumers using only
|
|
6
|
+
* AES-256-GCM never load the WASM blob.
|
|
7
|
+
*
|
|
8
|
+
* libsodium is declared as an optional peer dependency in package.json.
|
|
9
|
+
* Bundlers should treat it as side-effect-free.
|
|
10
|
+
*/
|
|
11
|
+
let cachedSodium = null;
|
|
12
|
+
let pendingInit = null;
|
|
13
|
+
export async function getSodium() {
|
|
14
|
+
if (cachedSodium)
|
|
15
|
+
return cachedSodium;
|
|
16
|
+
if (!pendingInit) {
|
|
17
|
+
pendingInit = (async () => {
|
|
18
|
+
let sodium;
|
|
19
|
+
try {
|
|
20
|
+
// Dynamic import keeps libsodium out of bundles that don't use it.
|
|
21
|
+
sodium = (await import('libsodium-wrappers-sumo')).default;
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
throw new Error('shieldfive-crypto: libsodium-wrappers-sumo is required for ' +
|
|
25
|
+
'this cipher suite. Install it as a dependency.', { cause: err });
|
|
26
|
+
}
|
|
27
|
+
await sodium.ready;
|
|
28
|
+
cachedSodium = sodium;
|
|
29
|
+
return sodium;
|
|
30
|
+
})();
|
|
31
|
+
}
|
|
32
|
+
return pendingInit;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=sodium.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sodium.js","sourceRoot":"","sources":["../../src/internal/sodium.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,IAAI,YAAY,GAAe,IAAI,CAAA;AACnC,IAAI,WAAW,GAAwB,IAAI,CAAA;AAE3C,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,IAAI,YAAY;QAAE,OAAO,YAAY,CAAA;IAErC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,WAAW,GAAG,CAAC,KAAK,IAAI,EAAE;YACxB,IAAI,MAAW,CAAA;YACf,IAAI,CAAC;gBACH,mEAAmE;gBACnE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,OAAO,CAAA;YAC5D,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,IAAI,KAAK,CACb,6DAA6D;oBAC3D,gDAAgD,EAClD,EAAE,KAAK,EAAE,GAAY,EAAE,CACxB,CAAA;YACH,CAAC;YACD,MAAM,MAAM,CAAC,KAAK,CAAA;YAClB,YAAY,GAAG,MAAM,CAAA;YACrB,OAAO,MAAM,CAAA;QACf,CAAC,CAAC,EAAE,CAAA;IACN,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC"}
|