Skip to Content
Client Lib

Crypto

Fail-closed field decryption: a field that does not decrypt becomes null.

Usage

import { decryptFields } from "@dapplelight/signet-lib/crypto"
import { myCipher } from "./cipher"

const response = await fetch("/api/transactions").then((r) => r.json())

const { data, undecrypted } = await decryptFields(
  response, // { transactions: [{ description, merchant: { name } }] }
  ["transactions.description", "transactions.merchant.name"],
  {
    decrypt: (ciphertext, path) => myCipher.decrypt(ciphertext), // bring your own
    isCiphertext: (value) => value.startsWith("enc:"),            // optional
  },
)
// undecrypted: ["transactions.3.description"]

Never throws, never mutates the input. Ciphertext is never passed through as plaintext.

API

ExportWhat it does
decryptFields(input, paths, options)Decrypts the fields at paths; resolves to { data, undecrypted }
DecryptFieldsOptions, DecryptFieldsResultTypes

decryptFields(input, paths, options)

OptionTypeDefault
pathsstring[]requiredDot-separated; arrays are walked without an index
decrypt(ciphertext, path) => string | Promise<string>requiredA throw counts as a failure
isCiphertext(value, path) => booleanevery non-empty stringReturn false only for certain plaintext. A throw means ciphertext

Missing keys, null, "" and non-strings are left as they are. Failed fields become null and their concrete paths (with indexes) are listed in undecrypted.