| 55 | // --- NaCl box encryption (for data encryption key unwrapping) --- |
| 56 | |
| 57 | export function decryptBox( |
| 58 | bundle: Uint8Array, |
| 59 | recipientSecretKey: Uint8Array, |
| 60 | ): Uint8Array | null { |
| 61 | const ephemeralPublicKey = bundle.slice(0, 32); |
| 62 | const nonce = bundle.slice(32, 56); |
| 63 | const encrypted = bundle.slice(56); |
| 64 | try { |
| 65 | return sodium.crypto_box_open_easy( |
| 66 | encrypted, |
| 67 | nonce, |
| 68 | ephemeralPublicKey, |
| 69 | recipientSecretKey, |
| 70 | ); |
| 71 | } catch { |
| 72 | return null; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | export function boxKeyPairFromSeed(seed: Uint8Array): { |
| 77 | publicKey: Uint8Array; |