Human Network
  • ☀️Welcome to Human Network
  • Overview
    • What is Human Network? What are Human Keys?
    • Methods and their use cases
      • Deriving keys from low-entropy data
      • Deriving keys from web accounts
      • Provably encrypting to Human Network, and setting custom decryption conditions.
    • FAQ
  • For Operators
    • Register and Run a Human Node
      • Use Keystore for private key encryption
      • Keyshare backup
    • Diagnostics using the Network UI
  • Decentralization
    • Architecture
      • Preventing Collusion
      • Scalability
      • Credit System
    • Mainnets and Testnets
  • Usage Instructions
    • Human Network Credits
    • Making Requests to Human Network
      • OPRF To Derive Keys From Low-Entropy Data
      • PRF to Derive Keys from JWTs
      • Decryption of Provably Encrypted Data
    • Sponsor Requests
Powered by GitBook
On this page
  1. Usage Instructions
  2. Making Requests to Human Network

Decryption of Provably Encrypted Data

With mishtiwasm

Install.

npm i @holonym-foundation/mishtiwasm

Import, fetch parameters, and decrypt.

import wasm from '@holonym-foundation/mishtiwasm'

// -------- Fetch parameters --------
// To decrypt, Mishti needs to verify the user's signature of the
// access conditions contract address. We retrieve the ciphertext
// as well as the signature and conditions contract from the observer.

const user = '0x123'
// This example uses Holonym's default observer to store ciphertext and assist in decryption
const observerUrl = 'https://observer.holonym.io'

const resp = await fetch(`${observerUrl}/observations?user_address=${user}`)
const data = await resp.json()
const { 
  user_address,
  signature,
  access_contract,
  zkp_public_values,
} = data[0]

// C1 and C2 are the two points in the ElGamal Ciphertext: the ephemeral public key and the masked plaintext, respectively
const ciphertext = {
  c1: {
    x: BigInt('0x' + zkp_public_values[7]).toString(),
    y: BigInt('0x' + zkp_public_values[8]).toString()
  },
  c2: {
    x: BigInt('0x' + zkp_public_values[9]).toString(),
    y: BigInt('0x' + zkp_public_values[10]).toString()
  }
}

// -------- Decrypt --------

// privateKey should be the private key to your wallet with Mishti credits.
// It is used to sign the request to Mishti Network.
const privateKey = '0x123'

const result = await wasm.decrypt(
  privateKey,
  JSON.stringify(ciphertext),
  access_contract,
  signature
);

// If the decrypted value is a UTF-8 encoded string, we need to decode
// by doing something like this:
const decoded = Buffer.from(BigInt(result).toString(16), 'hex').toString()

PreviousPRF to Derive Keys from JWTsNextSponsor Requests

Last updated 8 months ago