@shieldfive/crypto 1.0.0-beta.4 → 1.0.0-rc.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 +56 -0
- package/README.md +73 -20
- package/SECURITY.md +11 -21
- package/dist/identity/inbound.d.ts +72 -0
- package/dist/identity/inbound.d.ts.map +1 -0
- package/dist/identity/inbound.js +120 -0
- package/dist/identity/inbound.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/types.d.ts +2 -0
- package/dist/internal/types.d.ts.map +1 -1
- package/dist/internal/types.js +9 -0
- package/dist/internal/types.js.map +1 -1
- package/dist/suites/aes-gcm-v0/api.d.ts +2 -1
- package/dist/suites/aes-gcm-v0/api.d.ts.map +1 -1
- package/dist/suites/aes-gcm-v0/api.js +1 -0
- package/dist/suites/aes-gcm-v0/api.js.map +1 -1
- package/dist/suites/aes-gcm-v2/api.d.ts +15 -2
- package/dist/suites/aes-gcm-v2/api.d.ts.map +1 -1
- package/dist/suites/aes-gcm-v2/api.js.map +1 -1
- package/dist/suites/pq-hybrid-v1/api.d.ts +6 -6
- package/dist/suites/pq-hybrid-v1/api.d.ts.map +1 -1
- package/dist/suites/pq-hybrid-v1/api.js +2 -1
- package/dist/suites/pq-hybrid-v1/api.js.map +1 -1
- package/dist/suites/xchacha-v1/api.d.ts +6 -6
- package/dist/suites/xchacha-v1/api.d.ts.map +1 -1
- package/dist/suites/xchacha-v1/api.js +2 -1
- package/dist/suites/xchacha-v1/api.js.map +1 -1
- package/package.json +1 -1
- package/src/identity/inbound.ts +173 -0
- package/src/index.ts +4 -3
- package/src/internal/types.ts +9 -0
- package/src/suites/aes-gcm-v0/api.ts +2 -1
- package/src/suites/aes-gcm-v2/api.ts +15 -2
- package/src/suites/pq-hybrid-v1/api.ts +10 -8
- package/src/suites/xchacha-v1/api.ts +10 -8
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
|
|
36
36
|
const LENGTH_PREFIX_BYTES = 4
|
|
37
37
|
|
|
38
|
-
export interface
|
|
38
|
+
export interface EncryptOptions {
|
|
39
39
|
blob: Blob
|
|
40
40
|
/**
|
|
41
41
|
* SECURITY: `contentKey` and `fileId` together form a one-use AEAD nonce
|
|
@@ -54,7 +54,7 @@ export interface XChaChaEncryptOptions {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export async function encryptBlob(
|
|
57
|
-
options:
|
|
57
|
+
options: EncryptOptions,
|
|
58
58
|
): Promise<EncryptedFile & { contentKey: Uint8Array }> {
|
|
59
59
|
const { blob, onProgress } = options
|
|
60
60
|
if (!(blob instanceof Blob)) {
|
|
@@ -132,7 +132,7 @@ export async function encryptBlob(
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
export interface
|
|
135
|
+
export interface DecryptOptions {
|
|
136
136
|
blob: Blob
|
|
137
137
|
contentKey: Uint8Array
|
|
138
138
|
onProgress?: ProgressCallback
|
|
@@ -140,7 +140,7 @@ export interface XChaChaDecryptOptions {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
export async function decryptBlob(
|
|
143
|
-
options:
|
|
143
|
+
options: DecryptOptions,
|
|
144
144
|
): Promise<Blob> {
|
|
145
145
|
const { blob, contentKey, onProgress } = options
|
|
146
146
|
if (!(blob instanceof Blob)) {
|
|
@@ -248,15 +248,17 @@ export async function decryptBlob(
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
export async function encryptBytes(
|
|
251
|
-
bytes: Uint8Array,
|
|
252
|
-
options: Omit<
|
|
251
|
+
bytes: Uint8Array | ArrayBuffer,
|
|
252
|
+
options: Omit<EncryptOptions, 'blob'>,
|
|
253
253
|
): Promise<EncryptedFile & { contentKey: Uint8Array }> {
|
|
254
|
-
const
|
|
254
|
+
const part: BlobPart =
|
|
255
|
+
bytes instanceof ArrayBuffer ? bytes : asBlobPart(bytes)
|
|
256
|
+
const blob = new Blob([part])
|
|
255
257
|
return encryptBlob({ blob, ...options })
|
|
256
258
|
}
|
|
257
259
|
|
|
258
260
|
export async function decryptToBytes(
|
|
259
|
-
options:
|
|
261
|
+
options: DecryptOptions,
|
|
260
262
|
): Promise<Uint8Array> {
|
|
261
263
|
const blob = await decryptBlob(options)
|
|
262
264
|
return new Uint8Array(await blob.arrayBuffer())
|