@shieldfive/crypto 1.0.0-alpha.11
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 +228 -0
- package/LICENSE +201 -0
- package/README.md +275 -0
- package/SECURITY.md +130 -0
- package/dist/format/header.d.ts +73 -0
- package/dist/format/header.d.ts.map +1 -0
- package/dist/format/header.js +230 -0
- package/dist/format/header.js.map +1 -0
- package/dist/identity/index.d.ts +119 -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/identity/sign.d.ts +92 -0
- package/dist/identity/sign.d.ts.map +1 -0
- package/dist/identity/sign.js +182 -0
- package/dist/identity/sign.js.map +1 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +146 -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 +135 -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 +98 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +70 -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 +98 -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 +144 -0
- package/dist/streams/aes-gcm-v1.d.ts.map +1 -0
- package/dist/streams/aes-gcm-v1.js +456 -0
- package/dist/streams/aes-gcm-v1.js.map +1 -0
- package/dist/streams/pq-hybrid-v1.d.ts +219 -0
- package/dist/streams/pq-hybrid-v1.d.ts.map +1 -0
- package/dist/streams/pq-hybrid-v1.js +473 -0
- package/dist/streams/pq-hybrid-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 +181 -0
- package/dist/suites/aes-gcm-v1/api.js.map +1 -0
- package/dist/suites/aes-gcm-v1/index.d.ts +59 -0
- package/dist/suites/aes-gcm-v1/index.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v1/index.js +177 -0
- package/dist/suites/aes-gcm-v1/index.js.map +1 -0
- package/dist/suites/aes-gcm-v2/api.d.ts +44 -0
- package/dist/suites/aes-gcm-v2/api.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v2/api.js +162 -0
- package/dist/suites/aes-gcm-v2/api.js.map +1 -0
- package/dist/suites/aes-gcm-v2/index.d.ts +63 -0
- package/dist/suites/aes-gcm-v2/index.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v2/index.js +193 -0
- package/dist/suites/aes-gcm-v2/index.js.map +1 -0
- package/dist/suites/pq-hybrid-v1/api.d.ts +67 -0
- package/dist/suites/pq-hybrid-v1/api.d.ts.map +1 -0
- package/dist/suites/pq-hybrid-v1/api.js +190 -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 +154 -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 +124 -0
- package/spec/format-v0.md +81 -0
- package/spec/format-v1.md +400 -0
- package/spec/key-derivation.md +167 -0
- package/spec/threat-model.md +242 -0
- package/src/format/header.ts +316 -0
- package/src/identity/index.ts +371 -0
- package/src/identity/sign.ts +221 -0
- package/src/index.ts +224 -0
- package/src/internal/encoding.ts +152 -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 +134 -0
- package/src/kdf/argon2id.ts +165 -0
- package/src/migration/v0-bridge.ts +347 -0
- package/src/streams/aes-gcm-v1.ts +647 -0
- package/src/streams/pq-hybrid-v1.ts +722 -0
- package/src/suites/aes-gcm-v0/api.ts +155 -0
- package/src/suites/aes-gcm-v1/api.ts +292 -0
- package/src/suites/aes-gcm-v1/index.ts +269 -0
- package/src/suites/aes-gcm-v2/api.ts +268 -0
- package/src/suites/aes-gcm-v2/index.ts +289 -0
- package/src/suites/pq-hybrid-v1/api.ts +299 -0
- package/src/suites/pq-hybrid-v1/index.ts +343 -0
- package/src/suites/xchacha-v1/api.ts +254 -0
- package/src/suites/xchacha-v1/index.ts +213 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cipher suite "0x00" / v0: legacy AES-256-GCM, READ-ONLY.
|
|
3
|
+
*
|
|
4
|
+
* This module decrypts files written by the pre-v1 ShieldFive client.
|
|
5
|
+
* It is intentionally read-only: there is no `encryptV0` exported symbol,
|
|
6
|
+
* and applications MUST NOT write new files in this format.
|
|
7
|
+
*
|
|
8
|
+
* v0 wire format (described in `spec/format-v0.md`):
|
|
9
|
+
*
|
|
10
|
+
* v0_file := chunk_0 || chunk_1 || ... || chunk_n
|
|
11
|
+
* chunk_i := AES-GCM(key=content_key, iv=prefix(4)||counter_be(8), aad=∅, pt=plain_i)
|
|
12
|
+
*
|
|
13
|
+
* No on-disk header. The reader must be told the chunk size and nonce
|
|
14
|
+
* prefix out of band (from the application database).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { uint64BE } from '../../internal/encoding.js'
|
|
18
|
+
import { getSubtle } from '../../internal/runtime.js'
|
|
19
|
+
|
|
20
|
+
export const V0_TAG_BYTES = 16
|
|
21
|
+
export const V0_IV_BYTES = 12
|
|
22
|
+
export const V0_KEY_BYTES = 32
|
|
23
|
+
export const V0_NONCE_PREFIX_BYTES = 4
|
|
24
|
+
|
|
25
|
+
export interface V0DecryptOptions {
|
|
26
|
+
/** Encrypted file bytes (concatenated chunks; no header) */
|
|
27
|
+
blob: Blob
|
|
28
|
+
/** 32-byte AES-256 content key, already unwrapped from the envelope */
|
|
29
|
+
contentKey: Uint8Array
|
|
30
|
+
/** 4-byte per-file random prefix, stored in the database */
|
|
31
|
+
noncePrefix: Uint8Array
|
|
32
|
+
/** Plaintext bytes per chunk (5 MiB or 8 MiB in production) */
|
|
33
|
+
chunkSize: number
|
|
34
|
+
/** Optional progress callback (0..1) */
|
|
35
|
+
onProgress?: (progress: number) => void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function buildIv(prefix: Uint8Array, counter: number): Uint8Array {
|
|
39
|
+
const iv = new Uint8Array(V0_IV_BYTES)
|
|
40
|
+
iv.set(prefix, 0)
|
|
41
|
+
iv.set(uint64BE(counter), 4)
|
|
42
|
+
return iv
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Decrypt a v0 file. Throws if any chunk fails to authenticate, if the
|
|
47
|
+
* blob size is inconsistent with the chunk size (no clean chunk boundary),
|
|
48
|
+
* or if the inputs have wrong sizes.
|
|
49
|
+
*/
|
|
50
|
+
export async function decryptV0(options: V0DecryptOptions): Promise<Blob> {
|
|
51
|
+
const { blob, contentKey, noncePrefix, chunkSize, onProgress } = options
|
|
52
|
+
|
|
53
|
+
if (!(blob instanceof Blob)) {
|
|
54
|
+
throw new TypeError('decryptV0: blob must be a Blob or File')
|
|
55
|
+
}
|
|
56
|
+
if (contentKey.length !== V0_KEY_BYTES) {
|
|
57
|
+
throw new RangeError('decryptV0: contentKey must be 32 bytes')
|
|
58
|
+
}
|
|
59
|
+
if (noncePrefix.length !== V0_NONCE_PREFIX_BYTES) {
|
|
60
|
+
throw new RangeError('decryptV0: noncePrefix must be 4 bytes')
|
|
61
|
+
}
|
|
62
|
+
if (!Number.isSafeInteger(chunkSize) || chunkSize <= 0) {
|
|
63
|
+
throw new RangeError('decryptV0: chunkSize must be a positive integer')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Compute chunk layout from blob size.
|
|
67
|
+
const fullCipherLen = chunkSize + V0_TAG_BYTES
|
|
68
|
+
const totalSize = blob.size
|
|
69
|
+
|
|
70
|
+
if (totalSize === 0) {
|
|
71
|
+
return new Blob([], { type: 'application/octet-stream' })
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const fullChunkCount = Math.floor(totalSize / fullCipherLen)
|
|
75
|
+
const trailingBytes = totalSize - fullChunkCount * fullCipherLen
|
|
76
|
+
|
|
77
|
+
let totalChunks: number
|
|
78
|
+
if (trailingBytes === 0) {
|
|
79
|
+
totalChunks = fullChunkCount
|
|
80
|
+
} else if (trailingBytes <= V0_TAG_BYTES) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`decryptV0: trailing bytes (${trailingBytes}) too small for an AEAD tag — file truncated`,
|
|
83
|
+
)
|
|
84
|
+
} else {
|
|
85
|
+
totalChunks = fullChunkCount + 1
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Import the AES-GCM key once.
|
|
89
|
+
const key = await getSubtle().importKey(
|
|
90
|
+
'raw',
|
|
91
|
+
contentKey as Uint8Array<ArrayBuffer>,
|
|
92
|
+
{ name: 'AES-GCM' },
|
|
93
|
+
false,
|
|
94
|
+
['decrypt'],
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
const plaintextParts: BlobPart[] = []
|
|
98
|
+
let cursor = 0
|
|
99
|
+
for (let i = 0; i < totalChunks; i += 1) {
|
|
100
|
+
const isFinal = i === totalChunks - 1
|
|
101
|
+
const cipherLen = isFinal && trailingBytes > 0 ? trailingBytes : fullCipherLen
|
|
102
|
+
const cipherBytes = new Uint8Array(
|
|
103
|
+
await blob.slice(cursor, cursor + cipherLen).arrayBuffer(),
|
|
104
|
+
)
|
|
105
|
+
cursor += cipherLen
|
|
106
|
+
|
|
107
|
+
const iv = buildIv(noncePrefix, i)
|
|
108
|
+
let pt: ArrayBuffer
|
|
109
|
+
try {
|
|
110
|
+
pt = await getSubtle().decrypt(
|
|
111
|
+
{ name: 'AES-GCM', iv: iv as Uint8Array<ArrayBuffer>, tagLength: 128 },
|
|
112
|
+
key,
|
|
113
|
+
cipherBytes as Uint8Array<ArrayBuffer>,
|
|
114
|
+
)
|
|
115
|
+
} catch (err) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
`decryptV0: chunk ${i} failed authentication`,
|
|
118
|
+
{ cause: err as Error },
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
plaintextParts.push(pt)
|
|
122
|
+
|
|
123
|
+
onProgress?.((i + 1) / totalChunks)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return new Blob(plaintextParts, { type: 'application/octet-stream' })
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Convenience wrapper that returns plaintext bytes directly.
|
|
131
|
+
*/
|
|
132
|
+
export async function decryptV0ToBytes(
|
|
133
|
+
options: V0DecryptOptions,
|
|
134
|
+
): Promise<Uint8Array> {
|
|
135
|
+
const blob = await decryptV0(options)
|
|
136
|
+
return new Uint8Array(await blob.arrayBuffer())
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Detect whether a blob is v0 (legacy) by checking the absence of the v1
|
|
141
|
+
* magic prefix. Use only when out-of-band metadata is unavailable. For
|
|
142
|
+
* normal application use, the database flag `cipher_version` is canonical.
|
|
143
|
+
*/
|
|
144
|
+
export async function looksLikeV0(blob: Blob): Promise<boolean> {
|
|
145
|
+
if (blob.size < 5) return true // too small to be v1
|
|
146
|
+
const head = new Uint8Array(await blob.slice(0, 5).arrayBuffer())
|
|
147
|
+
// v1 magic is "SF5\x01\x00" = 0x53 0x46 0x35 0x01 0x00
|
|
148
|
+
return !(
|
|
149
|
+
head[0] === 0x53 &&
|
|
150
|
+
head[1] === 0x46 &&
|
|
151
|
+
head[2] === 0x35 &&
|
|
152
|
+
head[3] === 0x01 &&
|
|
153
|
+
head[4] === 0x00
|
|
154
|
+
)
|
|
155
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level encrypt/decrypt API for the AES-256-GCM v1 suite.
|
|
3
|
+
*
|
|
4
|
+
* This is what most callers will import. It glues together:
|
|
5
|
+
* - header construction
|
|
6
|
+
* - chunk encryption/decryption with full AAD binding
|
|
7
|
+
* - the v1 wire format
|
|
8
|
+
*
|
|
9
|
+
* Suites 0x02 (XChaCha20-Poly1305) and 0x03 (PQ hybrid) provide identical
|
|
10
|
+
* APIs in their own modules.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
buildAuthenticatedHeader,
|
|
15
|
+
parseHeader,
|
|
16
|
+
verifyHeaderMac,
|
|
17
|
+
HeaderError,
|
|
18
|
+
} from '../../format/header.js'
|
|
19
|
+
import {
|
|
20
|
+
AES_GCM_V1_SUITE_PAYLOAD_LENGTH,
|
|
21
|
+
AES_GCM_V1_TAG_BYTES,
|
|
22
|
+
createChunkContext,
|
|
23
|
+
decryptChunk,
|
|
24
|
+
encryptChunk,
|
|
25
|
+
generateContentMaterial,
|
|
26
|
+
parseAesGcmV1SuitePayload,
|
|
27
|
+
} from './index.js'
|
|
28
|
+
import {
|
|
29
|
+
DEFAULT_CHUNK_SIZE,
|
|
30
|
+
type EncryptedFile,
|
|
31
|
+
HEADER_SIZES,
|
|
32
|
+
MAX_TOTAL_CHUNKS,
|
|
33
|
+
type ProgressCallback,
|
|
34
|
+
SUITE,
|
|
35
|
+
} from '../../internal/types.js'
|
|
36
|
+
import {
|
|
37
|
+
asBlobPart,
|
|
38
|
+
readUint32BE,
|
|
39
|
+
uint32BE,
|
|
40
|
+
} from '../../internal/encoding.js'
|
|
41
|
+
|
|
42
|
+
const LENGTH_PREFIX_BYTES = 4
|
|
43
|
+
|
|
44
|
+
export interface EncryptOptions {
|
|
45
|
+
blob: Blob
|
|
46
|
+
/** Optional pre-existing content key (32 bytes). If omitted, generated. */
|
|
47
|
+
contentKey?: Uint8Array
|
|
48
|
+
/** Optional pre-existing file_id (16 bytes). If omitted, generated. */
|
|
49
|
+
fileId?: Uint8Array
|
|
50
|
+
/** Optional embedded wrapped key + IV (60 + 12 bytes). Defaults to zeros. */
|
|
51
|
+
suitePayloadOverride?: Uint8Array
|
|
52
|
+
/** Plaintext bytes per chunk. Defaults to 4 MiB. */
|
|
53
|
+
chunkSize?: number
|
|
54
|
+
/** Progress callback (0..1). Called once per chunk and once at completion. */
|
|
55
|
+
onProgress?: ProgressCallback
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Encrypt a Blob/File with the AES-256-GCM v1 suite.
|
|
60
|
+
* Returns the encrypted blob (header + chunks), plus the content key and
|
|
61
|
+
* file id so the caller can wrap/store them externally.
|
|
62
|
+
*/
|
|
63
|
+
export async function encryptBlob(
|
|
64
|
+
options: EncryptOptions,
|
|
65
|
+
): Promise<EncryptedFile & { contentKey: Uint8Array }> {
|
|
66
|
+
const { blob, onProgress } = options
|
|
67
|
+
if (!(blob instanceof Blob)) {
|
|
68
|
+
throw new TypeError('encryptBlob: blob must be a Blob or File')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE
|
|
72
|
+
if (!Number.isSafeInteger(chunkSize) || chunkSize <= 0) {
|
|
73
|
+
throw new RangeError('encryptBlob: chunkSize must be a positive integer')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const plaintextSize = blob.size
|
|
77
|
+
const totalChunks =
|
|
78
|
+
plaintextSize === 0 ? 0 : Math.ceil(plaintextSize / chunkSize)
|
|
79
|
+
if (totalChunks > MAX_TOTAL_CHUNKS) {
|
|
80
|
+
throw new RangeError('encryptBlob: file would exceed total_chunks limit')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Resolve key material
|
|
84
|
+
const generated = generateContentMaterial()
|
|
85
|
+
const contentKey = options.contentKey ?? generated.contentKey
|
|
86
|
+
const fileId = options.fileId ?? generated.fileId
|
|
87
|
+
if (contentKey.length !== 32) {
|
|
88
|
+
throw new RangeError('encryptBlob: contentKey must be 32 bytes')
|
|
89
|
+
}
|
|
90
|
+
if (fileId.length !== HEADER_SIZES.FILE_ID) {
|
|
91
|
+
throw new RangeError('encryptBlob: fileId must be 16 bytes')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Suite payload (caller-supplied or zero-filled placeholder)
|
|
95
|
+
const suitePayload =
|
|
96
|
+
options.suitePayloadOverride ??
|
|
97
|
+
new Uint8Array(AES_GCM_V1_SUITE_PAYLOAD_LENGTH)
|
|
98
|
+
if (suitePayload.length !== AES_GCM_V1_SUITE_PAYLOAD_LENGTH) {
|
|
99
|
+
throw new RangeError(
|
|
100
|
+
`encryptBlob: suitePayloadOverride must be ${AES_GCM_V1_SUITE_PAYLOAD_LENGTH} bytes`,
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const header = await buildAuthenticatedHeader(
|
|
105
|
+
{
|
|
106
|
+
suite: SUITE.AES_256_GCM_V1,
|
|
107
|
+
fileId,
|
|
108
|
+
chunkSize,
|
|
109
|
+
totalChunks,
|
|
110
|
+
plaintextSize,
|
|
111
|
+
suitePayload,
|
|
112
|
+
},
|
|
113
|
+
contentKey,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
const ctx = await createChunkContext(contentKey, fileId, totalChunks)
|
|
117
|
+
|
|
118
|
+
const parts: BlobPart[] = [asBlobPart(header)]
|
|
119
|
+
|
|
120
|
+
for (let i = 0; i < totalChunks; i += 1) {
|
|
121
|
+
const start = i * chunkSize
|
|
122
|
+
const end = Math.min(start + chunkSize, plaintextSize)
|
|
123
|
+
const plaintextBytes = new Uint8Array(
|
|
124
|
+
await blob.slice(start, end).arrayBuffer(),
|
|
125
|
+
)
|
|
126
|
+
const ciphertext = await encryptChunk(ctx, i, plaintextBytes)
|
|
127
|
+
parts.push(asBlobPart(uint32BE(ciphertext.length)))
|
|
128
|
+
parts.push(asBlobPart(ciphertext))
|
|
129
|
+
onProgress?.((i + 1) / Math.max(totalChunks, 1))
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (totalChunks === 0) onProgress?.(1)
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
blob: new Blob(parts, { type: 'application/octet-stream' }),
|
|
136
|
+
suite: SUITE.AES_256_GCM_V1,
|
|
137
|
+
fileId,
|
|
138
|
+
chunkSize,
|
|
139
|
+
totalChunks,
|
|
140
|
+
plaintextSize,
|
|
141
|
+
contentKey,
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface DecryptOptions {
|
|
146
|
+
blob: Blob
|
|
147
|
+
contentKey: Uint8Array
|
|
148
|
+
onProgress?: ProgressCallback
|
|
149
|
+
/**
|
|
150
|
+
* If provided, the parser checks the suite matches before any AEAD
|
|
151
|
+
* operation. Callers who want to refuse, e.g., legacy suites can pass
|
|
152
|
+
* an explicit allowlist.
|
|
153
|
+
*/
|
|
154
|
+
allowedSuites?: ReadonlyArray<number>
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Decrypt a v1 blob produced by `encryptBlob`. Reads the entire blob into
|
|
159
|
+
* memory in chunked passes; for streaming decryption see `streams/`.
|
|
160
|
+
*/
|
|
161
|
+
export async function decryptBlob(options: DecryptOptions): Promise<Blob> {
|
|
162
|
+
const { blob, contentKey, onProgress } = options
|
|
163
|
+
if (!(blob instanceof Blob)) {
|
|
164
|
+
throw new TypeError('decryptBlob: blob must be a Blob or File')
|
|
165
|
+
}
|
|
166
|
+
if (contentKey.length !== 32) {
|
|
167
|
+
throw new RangeError('decryptBlob: contentKey must be 32 bytes')
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Read enough to parse the header. The header is fixed-length plus a
|
|
171
|
+
// bounded suite_payload (max 65535 bytes). We read up to 4 KiB and
|
|
172
|
+
// fall back to streaming if the suite_payload is unusually large.
|
|
173
|
+
const headerProbeBytes = new Uint8Array(
|
|
174
|
+
await blob.slice(0, Math.min(blob.size, 4096)).arrayBuffer(),
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
let parsed: ReturnType<typeof parseHeader>
|
|
178
|
+
try {
|
|
179
|
+
parsed = parseHeader(headerProbeBytes)
|
|
180
|
+
} catch (err) {
|
|
181
|
+
if (err instanceof HeaderError && err.code === 'header_too_short') {
|
|
182
|
+
// The probe might have been too small. Read the whole blob.
|
|
183
|
+
const allHeaderBytes = new Uint8Array(
|
|
184
|
+
await blob
|
|
185
|
+
.slice(0, Math.min(blob.size, 4 + 0xffff + 1024))
|
|
186
|
+
.arrayBuffer(),
|
|
187
|
+
)
|
|
188
|
+
parsed = parseHeader(allHeaderBytes)
|
|
189
|
+
} else {
|
|
190
|
+
throw err
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (
|
|
195
|
+
options.allowedSuites &&
|
|
196
|
+
!options.allowedSuites.includes(parsed.suite)
|
|
197
|
+
) {
|
|
198
|
+
throw new HeaderError('suite_not_allowed')
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (parsed.suite !== SUITE.AES_256_GCM_V1) {
|
|
202
|
+
throw new HeaderError(
|
|
203
|
+
`decryptBlob: this entry point only supports aes-256-gcm-v1; got suite 0x${parsed.suite.toString(16)}`,
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// MUST verify the header MAC before reading or interpreting any
|
|
208
|
+
// suite_payload bytes — see parseHeader docstring and
|
|
209
|
+
// spec/format-v1.md § "verification order".
|
|
210
|
+
await verifyHeaderMac(parsed, contentKey)
|
|
211
|
+
|
|
212
|
+
// Validate the suite payload structure (length etc).
|
|
213
|
+
parseAesGcmV1SuitePayload(parsed.suitePayload)
|
|
214
|
+
|
|
215
|
+
const ctx = await createChunkContext(
|
|
216
|
+
contentKey,
|
|
217
|
+
parsed.fileId,
|
|
218
|
+
parsed.totalChunks,
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
const plaintextParts: BlobPart[] = []
|
|
222
|
+
let cursor = parsed.headerLength
|
|
223
|
+
let bytesEmitted = 0
|
|
224
|
+
|
|
225
|
+
for (let i = 0; i < parsed.totalChunks; i += 1) {
|
|
226
|
+
if (cursor + LENGTH_PREFIX_BYTES > blob.size) {
|
|
227
|
+
throw new HeaderError('chunk_length_truncated')
|
|
228
|
+
}
|
|
229
|
+
const lenBytes = new Uint8Array(
|
|
230
|
+
await blob.slice(cursor, cursor + LENGTH_PREFIX_BYTES).arrayBuffer(),
|
|
231
|
+
)
|
|
232
|
+
cursor += LENGTH_PREFIX_BYTES
|
|
233
|
+
const cipherLen = readUint32BE(lenBytes)
|
|
234
|
+
|
|
235
|
+
// Sanity check: ciphertext for AES-GCM-v1 is exactly chunkSize+tag
|
|
236
|
+
// for non-final chunks. Final chunk is between 1+tag and chunkSize+tag.
|
|
237
|
+
const isFinal = i === parsed.totalChunks - 1
|
|
238
|
+
const minCipher = 1 + AES_GCM_V1_TAG_BYTES
|
|
239
|
+
const maxCipher = parsed.chunkSize + AES_GCM_V1_TAG_BYTES
|
|
240
|
+
if (cipherLen < minCipher || cipherLen > maxCipher) {
|
|
241
|
+
throw new HeaderError('chunk_length_out_of_range')
|
|
242
|
+
}
|
|
243
|
+
if (!isFinal && cipherLen !== maxCipher) {
|
|
244
|
+
throw new HeaderError('non_final_chunk_wrong_size')
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (cursor + cipherLen > blob.size) {
|
|
248
|
+
throw new HeaderError('chunk_truncated')
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const cipherBytes = new Uint8Array(
|
|
252
|
+
await blob.slice(cursor, cursor + cipherLen).arrayBuffer(),
|
|
253
|
+
)
|
|
254
|
+
cursor += cipherLen
|
|
255
|
+
|
|
256
|
+
const plaintext = await decryptChunk(ctx, i, cipherBytes)
|
|
257
|
+
bytesEmitted += plaintext.length
|
|
258
|
+
plaintextParts.push(asBlobPart(plaintext))
|
|
259
|
+
|
|
260
|
+
onProgress?.((i + 1) / Math.max(parsed.totalChunks, 1))
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Final consistency: total bytes emitted must equal plaintextSize, and
|
|
264
|
+
// the file must have no trailing garbage past the last chunk.
|
|
265
|
+
if (bytesEmitted !== parsed.plaintextSize) {
|
|
266
|
+
throw new HeaderError('plaintext_size_mismatch')
|
|
267
|
+
}
|
|
268
|
+
if (cursor !== blob.size) {
|
|
269
|
+
throw new HeaderError('trailing_bytes_after_last_chunk')
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (parsed.totalChunks === 0) onProgress?.(1)
|
|
273
|
+
|
|
274
|
+
return new Blob(plaintextParts, { type: 'application/octet-stream' })
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export async function encryptBytes(
|
|
278
|
+
bytes: Uint8Array | ArrayBuffer,
|
|
279
|
+
options: Omit<EncryptOptions, 'blob'>,
|
|
280
|
+
): Promise<EncryptedFile & { contentKey: Uint8Array }> {
|
|
281
|
+
const part: BlobPart =
|
|
282
|
+
bytes instanceof ArrayBuffer ? bytes : asBlobPart(bytes)
|
|
283
|
+
const blob = new Blob([part])
|
|
284
|
+
return encryptBlob({ blob, ...options })
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export async function decryptToBytes(
|
|
288
|
+
options: DecryptOptions,
|
|
289
|
+
): Promise<Uint8Array> {
|
|
290
|
+
const blob = await decryptBlob(options)
|
|
291
|
+
return new Uint8Array(await blob.arrayBuffer())
|
|
292
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cipher suite 0x01: AES-256-GCM v1.
|
|
3
|
+
*
|
|
4
|
+
* Decrypt-only for legacy files created before 2026-05-21; new encrypts
|
|
5
|
+
* use 0x04 aes-gcm-v2, which widens the file-derived nonce prefix.
|
|
6
|
+
*
|
|
7
|
+
* Per-file content key. Per-chunk AEAD with file_id-bound AAD that
|
|
8
|
+
* authenticates chunk index, total chunks, and the is-final flag. The
|
|
9
|
+
* 12-byte GCM IV is split into a 4-byte file-derived prefix and an 8-byte
|
|
10
|
+
* big-endian counter.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { buildChunkAad } from '../../format/header.js'
|
|
14
|
+
import {
|
|
15
|
+
HKDF_INFO,
|
|
16
|
+
HEADER_SIZES,
|
|
17
|
+
type ParsedHeader,
|
|
18
|
+
} from '../../internal/types.js'
|
|
19
|
+
import { concatBytes, uint64BE } from '../../internal/encoding.js'
|
|
20
|
+
import { hkdfSha256 } from '../../internal/hkdf.js'
|
|
21
|
+
import { getSubtle, randomBytes } from '../../internal/runtime.js'
|
|
22
|
+
|
|
23
|
+
export const AES_GCM_V1_TAG_BYTES = 16
|
|
24
|
+
export const AES_GCM_V1_IV_BYTES = 12
|
|
25
|
+
export const AES_GCM_V1_KEY_BYTES = 32
|
|
26
|
+
|
|
27
|
+
/** Suite payload layout: 60-byte wrapped key + 12-byte wrap IV = 72 bytes. */
|
|
28
|
+
export const AES_GCM_V1_SUITE_PAYLOAD_LENGTH = 72
|
|
29
|
+
|
|
30
|
+
export interface AesGcmV1SuitePayload {
|
|
31
|
+
wrappedKey: Uint8Array // 60 bytes (32-byte key + 16-byte tag + 12-byte AAD-padded reserved zeros)
|
|
32
|
+
wrapIv: Uint8Array // 12 bytes
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function buildAesGcmV1SuitePayload(
|
|
36
|
+
payload: AesGcmV1SuitePayload,
|
|
37
|
+
): Uint8Array {
|
|
38
|
+
if (payload.wrappedKey.length !== 60) {
|
|
39
|
+
throw new RangeError('aes-gcm-v1: wrappedKey must be 60 bytes')
|
|
40
|
+
}
|
|
41
|
+
if (payload.wrapIv.length !== AES_GCM_V1_IV_BYTES) {
|
|
42
|
+
throw new RangeError('aes-gcm-v1: wrapIv must be 12 bytes')
|
|
43
|
+
}
|
|
44
|
+
return concatBytes([payload.wrappedKey, payload.wrapIv])
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function parseAesGcmV1SuitePayload(
|
|
48
|
+
bytes: Uint8Array,
|
|
49
|
+
): AesGcmV1SuitePayload {
|
|
50
|
+
if (bytes.length !== AES_GCM_V1_SUITE_PAYLOAD_LENGTH) {
|
|
51
|
+
throw new RangeError(
|
|
52
|
+
'aes-gcm-v1: suite payload must be 72 bytes',
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
wrappedKey: bytes.slice(0, 60),
|
|
57
|
+
wrapIv: bytes.slice(60, 72),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Derive the per-file chunk key from the content key.
|
|
63
|
+
* Even though the content key is fresh per file, we run it through HKDF
|
|
64
|
+
* so that any future bug that recycles a content key cannot also recycle
|
|
65
|
+
* the chunk key under the same file_id.
|
|
66
|
+
*/
|
|
67
|
+
async function deriveChunkKey(
|
|
68
|
+
contentKey: Uint8Array,
|
|
69
|
+
fileId: Uint8Array,
|
|
70
|
+
): Promise<Uint8Array> {
|
|
71
|
+
return hkdfSha256({
|
|
72
|
+
ikm: contentKey,
|
|
73
|
+
salt: fileId,
|
|
74
|
+
info: HKDF_INFO.AES_GCM_CHUNK_KEY,
|
|
75
|
+
length: AES_GCM_V1_KEY_BYTES,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Derive the 4-byte nonce prefix from file_id. Stable per file.
|
|
81
|
+
*/
|
|
82
|
+
async function deriveNoncePrefix(fileId: Uint8Array): Promise<Uint8Array> {
|
|
83
|
+
const out = await hkdfSha256({
|
|
84
|
+
ikm: fileId,
|
|
85
|
+
info: HKDF_INFO.AES_GCM_NONCE_PREFIX,
|
|
86
|
+
length: 4,
|
|
87
|
+
})
|
|
88
|
+
return out
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function buildIv(noncePrefix: Uint8Array, chunkIndex: number): Uint8Array {
|
|
92
|
+
const iv = new Uint8Array(AES_GCM_V1_IV_BYTES)
|
|
93
|
+
iv.set(noncePrefix, 0)
|
|
94
|
+
iv.set(uint64BE(chunkIndex), 4)
|
|
95
|
+
return iv
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function importAesGcmKey(
|
|
99
|
+
keyBytes: Uint8Array,
|
|
100
|
+
usages: KeyUsage[],
|
|
101
|
+
): Promise<CryptoKey> {
|
|
102
|
+
if (keyBytes.length !== AES_GCM_V1_KEY_BYTES) {
|
|
103
|
+
throw new RangeError('aes-gcm-v1: key must be 32 bytes')
|
|
104
|
+
}
|
|
105
|
+
return getSubtle().importKey(
|
|
106
|
+
'raw',
|
|
107
|
+
keyBytes as Uint8Array<ArrayBuffer>,
|
|
108
|
+
{ name: 'AES-GCM' },
|
|
109
|
+
false,
|
|
110
|
+
usages,
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Generate a fresh per-file content key and file_id. */
|
|
115
|
+
export function generateContentMaterial(): {
|
|
116
|
+
contentKey: Uint8Array
|
|
117
|
+
fileId: Uint8Array
|
|
118
|
+
} {
|
|
119
|
+
return {
|
|
120
|
+
contentKey: randomBytes(AES_GCM_V1_KEY_BYTES),
|
|
121
|
+
fileId: randomBytes(HEADER_SIZES.FILE_ID),
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface AesGcmV1ChunkContext {
|
|
126
|
+
cryptoKey: CryptoKey
|
|
127
|
+
noncePrefix: Uint8Array
|
|
128
|
+
totalChunks: number
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export async function createChunkContext(
|
|
132
|
+
contentKey: Uint8Array,
|
|
133
|
+
fileId: Uint8Array,
|
|
134
|
+
totalChunks: number,
|
|
135
|
+
): Promise<AesGcmV1ChunkContext> {
|
|
136
|
+
const chunkKeyBytes = await deriveChunkKey(contentKey, fileId)
|
|
137
|
+
const noncePrefix = await deriveNoncePrefix(fileId)
|
|
138
|
+
const cryptoKey = await importAesGcmKey(chunkKeyBytes, ['encrypt', 'decrypt'])
|
|
139
|
+
return { cryptoKey, noncePrefix, totalChunks }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function encryptChunk(
|
|
143
|
+
ctx: AesGcmV1ChunkContext,
|
|
144
|
+
chunkIndex: number,
|
|
145
|
+
plaintext: Uint8Array,
|
|
146
|
+
): Promise<Uint8Array> {
|
|
147
|
+
const isFinal = chunkIndex === ctx.totalChunks - 1
|
|
148
|
+
const aad = buildChunkAad(chunkIndex, ctx.totalChunks, isFinal)
|
|
149
|
+
const iv = buildIv(ctx.noncePrefix, chunkIndex)
|
|
150
|
+
const ct = await getSubtle().encrypt(
|
|
151
|
+
{
|
|
152
|
+
name: 'AES-GCM',
|
|
153
|
+
iv: iv as Uint8Array<ArrayBuffer>,
|
|
154
|
+
additionalData: aad as Uint8Array<ArrayBuffer>,
|
|
155
|
+
tagLength: 128,
|
|
156
|
+
},
|
|
157
|
+
ctx.cryptoKey,
|
|
158
|
+
plaintext as Uint8Array<ArrayBuffer>,
|
|
159
|
+
)
|
|
160
|
+
return new Uint8Array(ct)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function decryptChunk(
|
|
164
|
+
ctx: AesGcmV1ChunkContext,
|
|
165
|
+
chunkIndex: number,
|
|
166
|
+
ciphertext: Uint8Array,
|
|
167
|
+
): Promise<Uint8Array> {
|
|
168
|
+
const isFinal = chunkIndex === ctx.totalChunks - 1
|
|
169
|
+
const aad = buildChunkAad(chunkIndex, ctx.totalChunks, isFinal)
|
|
170
|
+
const iv = buildIv(ctx.noncePrefix, chunkIndex)
|
|
171
|
+
const pt = await getSubtle().decrypt(
|
|
172
|
+
{
|
|
173
|
+
name: 'AES-GCM',
|
|
174
|
+
iv: iv as Uint8Array<ArrayBuffer>,
|
|
175
|
+
additionalData: aad as Uint8Array<ArrayBuffer>,
|
|
176
|
+
tagLength: 128,
|
|
177
|
+
},
|
|
178
|
+
ctx.cryptoKey,
|
|
179
|
+
ciphertext as Uint8Array<ArrayBuffer>,
|
|
180
|
+
)
|
|
181
|
+
return new Uint8Array(pt)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Wrap (encrypt) a content key under an envelope key (folder/vault key).
|
|
186
|
+
* This is what the suite_payload's wrappedKey field carries when the
|
|
187
|
+
* caller chooses to embed the wrapped key in the file rather than store
|
|
188
|
+
* it in a database.
|
|
189
|
+
*/
|
|
190
|
+
export async function wrapContentKey(options: {
|
|
191
|
+
contentKey: Uint8Array
|
|
192
|
+
envelopeKey: Uint8Array
|
|
193
|
+
envelopeAad?: Uint8Array
|
|
194
|
+
}): Promise<{ wrapped: Uint8Array; wrapIv: Uint8Array }> {
|
|
195
|
+
const { contentKey, envelopeKey } = options
|
|
196
|
+
if (contentKey.length !== AES_GCM_V1_KEY_BYTES) {
|
|
197
|
+
throw new RangeError('wrapContentKey: contentKey must be 32 bytes')
|
|
198
|
+
}
|
|
199
|
+
if (envelopeKey.length !== AES_GCM_V1_KEY_BYTES) {
|
|
200
|
+
throw new RangeError('wrapContentKey: envelopeKey must be 32 bytes')
|
|
201
|
+
}
|
|
202
|
+
const wrapIv = randomBytes(AES_GCM_V1_IV_BYTES)
|
|
203
|
+
const wrapKey = await importAesGcmKey(envelopeKey, ['encrypt'])
|
|
204
|
+
const wrapped = await getSubtle().encrypt(
|
|
205
|
+
{
|
|
206
|
+
name: 'AES-GCM',
|
|
207
|
+
iv: wrapIv as Uint8Array<ArrayBuffer>,
|
|
208
|
+
additionalData:
|
|
209
|
+
(options.envelopeAad ?? new Uint8Array(0)) as Uint8Array<ArrayBuffer>,
|
|
210
|
+
tagLength: 128,
|
|
211
|
+
},
|
|
212
|
+
wrapKey,
|
|
213
|
+
contentKey as Uint8Array<ArrayBuffer>,
|
|
214
|
+
)
|
|
215
|
+
// wrapped = 32-byte key + 16-byte tag = 48 bytes; pad to 60 with zeros
|
|
216
|
+
// so the suite_payload size is fixed regardless of whether the file
|
|
217
|
+
// embeds an inline wrapped key or zero-fills the field.
|
|
218
|
+
const wrappedBytes = new Uint8Array(wrapped)
|
|
219
|
+
if (wrappedBytes.length !== 48) {
|
|
220
|
+
throw new Error('wrapContentKey: unexpected wrapped length')
|
|
221
|
+
}
|
|
222
|
+
const padded = new Uint8Array(60)
|
|
223
|
+
padded.set(wrappedBytes, 0)
|
|
224
|
+
return { wrapped: padded, wrapIv }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export async function unwrapContentKey(options: {
|
|
228
|
+
envelopeKey: Uint8Array
|
|
229
|
+
wrappedField: Uint8Array
|
|
230
|
+
wrapIv: Uint8Array
|
|
231
|
+
envelopeAad?: Uint8Array
|
|
232
|
+
}): Promise<Uint8Array> {
|
|
233
|
+
const { envelopeKey, wrappedField, wrapIv } = options
|
|
234
|
+
if (envelopeKey.length !== AES_GCM_V1_KEY_BYTES) {
|
|
235
|
+
throw new RangeError('unwrapContentKey: envelopeKey must be 32 bytes')
|
|
236
|
+
}
|
|
237
|
+
if (wrappedField.length !== 60) {
|
|
238
|
+
throw new RangeError('unwrapContentKey: wrappedField must be 60 bytes')
|
|
239
|
+
}
|
|
240
|
+
if (wrapIv.length !== AES_GCM_V1_IV_BYTES) {
|
|
241
|
+
throw new RangeError('unwrapContentKey: wrapIv must be 12 bytes')
|
|
242
|
+
}
|
|
243
|
+
// The first 48 bytes are key+tag; the last 12 are reserved zeros.
|
|
244
|
+
const wrapped = wrappedField.slice(0, 48)
|
|
245
|
+
const wrapKey = await importAesGcmKey(envelopeKey, ['decrypt'])
|
|
246
|
+
const pt = await getSubtle().decrypt(
|
|
247
|
+
{
|
|
248
|
+
name: 'AES-GCM',
|
|
249
|
+
iv: wrapIv as Uint8Array<ArrayBuffer>,
|
|
250
|
+
additionalData:
|
|
251
|
+
(options.envelopeAad ?? new Uint8Array(0)) as Uint8Array<ArrayBuffer>,
|
|
252
|
+
tagLength: 128,
|
|
253
|
+
},
|
|
254
|
+
wrapKey,
|
|
255
|
+
wrapped as Uint8Array<ArrayBuffer>,
|
|
256
|
+
)
|
|
257
|
+
const ptBytes = new Uint8Array(pt)
|
|
258
|
+
if (ptBytes.length !== AES_GCM_V1_KEY_BYTES) {
|
|
259
|
+
throw new Error('unwrapContentKey: bad plaintext length')
|
|
260
|
+
}
|
|
261
|
+
return ptBytes
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Header parser hook — exposes ParsedHeader convenience for suite consumers. */
|
|
265
|
+
export function getSuitePayloadFromHeader(
|
|
266
|
+
header: ParsedHeader,
|
|
267
|
+
): AesGcmV1SuitePayload {
|
|
268
|
+
return parseAesGcmV1SuitePayload(header.suitePayload)
|
|
269
|
+
}
|