All Products
Search
Document Center

Privacy protection interface

Last Updated: May 08, 2020

The Java SDK provides privacy protection APIs to hide the transaction amount in smart contract transactions. Three APIs are available:

  • ValueHiding: encrypts the transaction amount.
  • PedersenCommitment: creates a commitment to the transaction amount and uses ValueHiding to encrypt the transaction amount.
  • Proofs: creates the proof required for a transaction.

ValueHiding

Function prototype Function description
ValueHiding() Creates the default ValueHiding.
ValueHiding(final byte[] pub, final byte[] priv, HidingType type) Creates ValueHiding. pub indicates the public key, and priv indicates the private key. type specifies the encryption and decryption method, which can be HidingType.ECIES or HidingType.RSA_2048. In this function, pub can be deduced from priv. If only pub is provided, ValueHiding can only be used for encryption.
public boolean loadKey(final String path, final String passwd) path specifies the key file to initialize ValueHiding, and passwd indicates the password for the key file.
public static ValueHiding genKeyPair(HidingType type) Randomly generates ValueHiding. type specifies the encryption and decryption method, which can be HidingType.ECIES or HidingType.RSA_2048.

PedersenCommitment

Function prototype Function description
public native static byte[] genBlind() Generates a blind factor for creating a pedersen commitment and a range proof.
public static PedersenCommitment createCommitment(long value, final byte[] blind, ValueHiding keypair, final byte[] extensions) Creates a commitment to the transaction amount. blind indicates a blind factor, and keypair encrypts the transaction amount and blind factor.
public static long getDecryptedValue(final byte[] commitment, ValueHiding keypair) keypair decrypts the transaction amount from the commitment.
public static byte[] getDecryptedBlind(final byte[] commitment, ValueHiding keypair) keypair decrypts the blind factor from the commitment.
public static byte[] computeBlindDelta(final List<byte[]> inputs, final List<byte[]> outputs) Calculates the difference between the list of blind factors represented by inputs and that represented by outputs. The difference between blind factors is used to prove that the total input amount is equal to the total output amount.

Proofs

Function prototype Function description
Proofs() Create a Proofs object.
public boolean addCommitment(PedersenCommitment commitment) Adds a pedersen commitment created for the output amount.
public void setBlindDelta(final byte[] delta) Sets the difference between blind factors of the total input amount and those of the total output amount.
public boolean addRangeProof(final List values, final List minValues, final List<byte[]> blindValues,final List commitments) Adds a range proof. values indicates the list of the input amounts. min_value indicates the minimum value of the range proof and is generally set to 0. blind_values indicates the blind factors used for creating the pedersen commitment to the input amount. commitments indicates the index of the pedersen commitment to the amount specified by values in the Proofs object. The index starts from 0, and the index of the pedersen commitment corresponds to the order of calling AddCommitment.
public final byte[] toBytes() Serializes the Proofs object into bytes. To create a privacy protection transaction, add the serialized bytes of the Proofs object to the extensions field of the transaction.