MCPcopy Create free account
hub / github.com/electric-sql/electric / decrypt

Function decrypt

examples/encryption/src/Example.tsx:63–85  ·  view source on GitHub ↗
(item: EncryptedItem)

Source from the content-addressed store, hash-verified

61 * Decrypt an `EncryptedItem` to an `Item`.
62 */
63async function decrypt(item: EncryptedItem): Promise<Item> {
64 const { id, ciphertext, iv: iv_str } = item
65
66 const encrypted = base64.toByteArray(ciphertext)
67 const iv = base64.toByteArray(iv_str)
68
69 const decrypted = await crypto.subtle.decrypt(
70 {
71 iv: iv as BufferSource,
72 name: `AES-GCM`,
73 },
74 key,
75 encrypted as BufferSource
76 )
77
78 const dec = new TextDecoder()
79 const title = dec.decode(decrypted)
80
81 return {
82 id,
83 title,
84 }
85}
86
87export const Example = () => {
88 const [items, setItems] = useState<Item[]>()

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected