All Products
Search
Document Center

Privacy Protection Interface

Last Updated: Sep 05, 2019

Java SDK provides operations to protect users’ privacy by hiding the transaction amounts in smart contract transactions. Three operations are provided:

  • ValueHiding: You can call this operation to encrypt the transaction amount.
  • PedersenCommitment: You can call this operation to create commitments on the transaction amounts, and use ValueHiding to encrypt the transaction amounts.
  • Proofs: You can call this operation to create the proof of work required to confirm transactions.

ValueHiding

Function Description
ValueHiding() Creates a default ValueHiding field.
ValueHiding(final byte[] pub, final byte[] priv, HidingType type) Creates a ValueHiding field: the pub parameter is the public key, and the priv parameter is the private key. Uses the type parameter to specify the encryption and decryption methods.HidingType.ECIES and HidingType.RSA_2048 are supported. This function can derive the pub parameter using the priv parameter. If only the pub parameter is provided, ValueHiding can only be used for encryption.
public boolean loadKey(final String path, final String passwd) Uses the path parameter to read the secret key file to initialize ValueHiding. The passwd parameter is the password corresponding to the secret key file.
public static ValueHiding genKeyPair(HidingType type) Randomly generates a ValueHiding field. Uses the type parameter to specify the encryption and decryption methods. HidingType.ECIES and HidingType.RSA_2048 are supported.

PedersenCommitment

Function Description
public native static byte[] genBlind() Generates the blinding factor to create a Pedersen commitment and the range proof.
public static PedersenCommitment createCommitment(long value, final byte[] blind, ValueHiding keypair, final byte[] extensions) Creates a commitment for the value parameter. This parameter refers to the transaction amount. The blind parameter is the blinding factor, and the keypair parameter is used to encrypt the blinding factor and the transaction amount.
public static long getDecryptedValue(final byte[] commitment, ValueHiding keypair) Uses the keypair parameter to decrypt the transaction amount from the commitment represented by the commitment parameter.
public static byte[] getDecryptedBlind(final byte[] commitment, ValueHiding keypair) Uses the keypair parameter to decrypt the transaction blinding factor from the commitment represented by the commitment parameter.
public static byte[] computeBlindDelta(final Listinputs, final List outputs) Calculates the difference between the blinding factor list represented by the inputs parameter and the blinding factor list represented by the outputs parameter. The difference between the blinding factor lists is used to prove that the total amount of input and the total amount of output are equal.

Proofs

Function Description
Proofs() Creates the Proofs object.
public boolean addCommitment(PedersenCommitment commitment) Adds a created Pedersen commitment for the output amount.
public void setBlindDelta(final byte[] delta) Sets the difference between the blinding factors of the input amount and the blinding factors of the output amount.
public boolean addRangeProof(final List values, final List minValues, final List blindValues,final Listcommitments) Adds the range proof: the values parameter ​​is the list of input amounts. The min_value parameter is typically set to 0, indicating the minimum value to be proved by the range proofs. The blind_values parameter ​​is the blinding factor used to create the Pedersen commitment corresponding to the input amount. Each value is corresponding to a commitment, and each commitment is a proof object. All the commitments are in the Pedersen commitment object. The index value starts from 0, and the index value corresponding to the Pedersen commitment corresponds to the order when AddCommitment is called.
public final byte[] toBytes() Serializes Proofs objects to bytes. Adds the bytes to the extensions field in Transaction when a private transaction is created.