Zero Knowledge

Zero Knowledge requires the API caller to encrypt the destination value before posting to the Branta server. Below is a javascript example of the encryption algorithm.

async function encrypt(value, secret) {
  const keyData = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(secret));
  const key = await crypto.subtle.importKey('raw', keyData, { name: 'AES-GCM' }, false, ['encrypt']);

  const iv = crypto.getRandomValues(new Uint8Array(12));
  const encrypted = await crypto.subtle.encrypt(
    { name: 'AES-GCM', iv: iv },
    key,
    new TextEncoder().encode(value)
  );

  const combined = new Uint8Array(iv.length + encrypted.byteLength);
  combined.set(iv, 0);
  combined.set(new Uint8Array(encrypted), iv.length);

  return btoa(String.fromCharCode(...combined));
}
const address = '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa';
const secret = crypto.randomUUID();

await encrypt(address, secret);
// Result:
// LQdBBewrzglmPYwUVoSjBJihA/Br8o+T1ArXGLaAuh7yJiW2dClzSBSUbUH1zhPo1WUBtr7JaFQ7wkK7CG4=

Last updated