@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.
Files changed (38) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +73 -20
  3. package/SECURITY.md +11 -21
  4. package/dist/identity/inbound.d.ts +72 -0
  5. package/dist/identity/inbound.d.ts.map +1 -0
  6. package/dist/identity/inbound.js +120 -0
  7. package/dist/identity/inbound.js.map +1 -0
  8. package/dist/index.d.ts +4 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +2 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/internal/types.d.ts +2 -0
  13. package/dist/internal/types.d.ts.map +1 -1
  14. package/dist/internal/types.js +9 -0
  15. package/dist/internal/types.js.map +1 -1
  16. package/dist/suites/aes-gcm-v0/api.d.ts +2 -1
  17. package/dist/suites/aes-gcm-v0/api.d.ts.map +1 -1
  18. package/dist/suites/aes-gcm-v0/api.js +1 -0
  19. package/dist/suites/aes-gcm-v0/api.js.map +1 -1
  20. package/dist/suites/aes-gcm-v2/api.d.ts +15 -2
  21. package/dist/suites/aes-gcm-v2/api.d.ts.map +1 -1
  22. package/dist/suites/aes-gcm-v2/api.js.map +1 -1
  23. package/dist/suites/pq-hybrid-v1/api.d.ts +6 -6
  24. package/dist/suites/pq-hybrid-v1/api.d.ts.map +1 -1
  25. package/dist/suites/pq-hybrid-v1/api.js +2 -1
  26. package/dist/suites/pq-hybrid-v1/api.js.map +1 -1
  27. package/dist/suites/xchacha-v1/api.d.ts +6 -6
  28. package/dist/suites/xchacha-v1/api.d.ts.map +1 -1
  29. package/dist/suites/xchacha-v1/api.js +2 -1
  30. package/dist/suites/xchacha-v1/api.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/identity/inbound.ts +173 -0
  33. package/src/index.ts +4 -3
  34. package/src/internal/types.ts +9 -0
  35. package/src/suites/aes-gcm-v0/api.ts +2 -1
  36. package/src/suites/aes-gcm-v2/api.ts +15 -2
  37. package/src/suites/pq-hybrid-v1/api.ts +10 -8
  38. 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 XChaChaEncryptOptions {
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: XChaChaEncryptOptions,
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 XChaChaDecryptOptions {
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: XChaChaDecryptOptions,
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<XChaChaEncryptOptions, 'blob'>,
251
+ bytes: Uint8Array | ArrayBuffer,
252
+ options: Omit<EncryptOptions, 'blob'>,
253
253
  ): Promise<EncryptedFile & { contentKey: Uint8Array }> {
254
- const blob = new Blob([asBlobPart(bytes)])
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: XChaChaDecryptOptions,
261
+ options: DecryptOptions,
260
262
  ): Promise<Uint8Array> {
261
263
  const blob = await decryptBlob(options)
262
264
  return new Uint8Array(await blob.arrayBuffer())