@me2em/crypto
    Preparing search index...

    Function withSecureWipe

    • Runs an async operation with secret bytes and wipes them afterwards — even if the operation throws.

      Guarantees that data is zeroed in the finally block regardless of whether operation succeeds or throws.

      Type Parameters

      • T

      Parameters

      • data: Uint8Array

        Secret byte array to wipe after operation.

      • operation: (data: Uint8Array) => Promise<T>

        Async function receiving the data.

      Returns Promise<T>

      The result of the operation.

      Whatever the operation throws, after wiping data.

      const result = await withSecureWipe(privateKey, async (key) => {
      return await encrypt(payload, key);
      });
      // privateKey is wiped now