Updated on 2023-01-16 GMT+08:00

Chaincode Library APIs

The chaincode library is static and integrated in BCS instances. When developing a chaincode, you can use the API file to locally compile the chaincode.

Download the API file (for the download link, see Downloading Resources), and decompress it to the local GOPATH directory. Refer to the example chaincode provided in section 4.2.6 to import the homomorphic encryption library. After the chaincode is developed, install it in the BCS instance. The chaincode will automatically link to the library code in the instance to invoke the homomorphic encryption library for the chaincode.

The code for importing the homomorphic encryption library for the chaincode is import "ahe/PSW/api/ChainCode".

Do not modify this code line. Otherwise, the chaincode fails to invoke the homomorphic encryption library.

ValidateInitBalance

  • API prototype

    func ValidateInitBalance(BalanceInfo, PubKey string) (InitBalance string, err error)

  • Function description

    Verifies the validity of the balance proof in balanceinfo generated by sdk.InitBalance.

  • Input

    Parameter

    Type

    Description

    Mandatory

    BalanceInfo

    string

    Initial balance data

    Yes

    Pubkey

    string

    Public key for balance encryption

    Yes

  • Output

    Parameter

    Type

    Description

    Mandatory

    InitBalance

    string

    Initial balance ciphertext

    Yes

    err

    error

    Error message

    Yes

  • Processing

    Balance ciphertext provided after the balance validity verification

  • Note

    The account balance authenticity is ensured by the application logic. The chaincode can only check whether the amount is greater than 0 but cannot determine the actual balance of a user.

ValidateTxInfo

  • API prototype

    ValidateTxInfo(txInfo, cipherBalanceA, cipherBalanceB string) (newCipherBalanceA,newCipherBalanceB,newCipherTxA,newCipherTxB string,err error)

  • Function description

    Verifies the validity of the transaction proof in Txinfo generated by PrepareTxInfo.

  • Input

    Parameter

    Type

    Description

    Mandatory

    txinfo

    string

    Transaction proof data

    NOTE:

    The transaction data includes the transaction proof data in addition to the ciphertext of the transaction data. It is obtained from txinfo returned using sdk.PrepareTxInfo.

    Yes

    cipherBalanceA

    string

    Current balance of user A (ciphertext)

    Yes

    cipherBalanceB

    string

    Current balance of user B (ciphertext)

    Yes

  • Output

    Parameter

    Type

    Description

    newCipherBalanceA

    string

    User A' balance to be updated after the transaction

    newCipherBalanceB

    string

    User B' balance to be updated after the transaction

    newCipherTxA

    string

    Transaction amount (encrypted using user A' homomorphic public-key encryption)

    newCipherTxB

    string

    Transaction amount (encrypted using user B' homomorphic public-key encryption)

    err

    error

    Error message

  • Note

    In this money transfer transaction, user A is the payer, and B the payee.