Blockchain API service for Hyperledger Sawtooth
Photo by Marc-Olivier Jodoin on Unsplash

Primechain-API for Hyperledger Sawtooth is a RESTful JSON APIs that makes it very simple for developers to add Sawtooth’s power to their code — electronic signatures, encrypted data storage & more. It is developed and maintained by Primechain Technologies.

Using Primechain-API for Hyperledger Sawtooth can save months of development time, reduce the development cycle and vastly increase the security and scalability of your applications.

Currently, it supports the following use cases:

Bank Guarantees Charge Registry Contract authentication, verification & storage Digital signatures Employee background verification Encrypted communication Encrypted data storage Know Your Customer (KYC) Letters of Credit Vendor on-boarding & rating

Introduction to Hyperledger Sawtooth

Hyperledger Sawtooth is a blockchain framework that allows developers to create smart contracts in multiple languages including Python, Javascript, Rust, C++, Go, Ethereum Virtual Machine and Java.

Key features:

Sawtooth nodes communicate through messages (containing information about transactions, blocks and peers), serialized using Google’s Protocol Buffers, and sent over TCP. Sawtooth nodes use access control lists to control who can connect to the network and sync with the current ledger state, who can send consensus messages and participate in the consensus process and who can submit transactions to the network. Sawtooth also supports the RAFT consensus protocol. Designed for high throughput, low latency transactions, RAFT is a crash-fault tolerant ‘voting’-style consensus algorithm. Sawtooth supports the Proof of Elapsed Time (PoET) consensus algorithm. As per official Sawtooth documentation, “At a high-level, PoET stochastically elects individual peers to execute requests at a given target rate. Individual peers sample an exponentially distributed random variable and wait for an amount of time dictated by the sample. The peer with the smallest sample wins the election. Cheating is prevented through the use of a trusted execution environment, identity verification and blacklisting based on asymmetric key cryptography, and an additional set of election policies”. Sawtooth also supports PoET-Simulator, an implementation of PoET that forgoes Byzantine fault tolerance.

Primechain-API for Hyperledger Sawtooth

Primechain-API for Hyperledger Sawtooth sets up multiple nodes and the API service which supports the following endpoints:

1. Create key pair

2. Publish data to the blockchain

3. Retrieve data from the blockchain

4. Creating a digital signature

5. Verify a digital signature

6. Create, encrypt, sign and publish data to the blockchain

7. Decrypt, verify and retrieve data from the blockchain

1. Create key pair

To create a key pair, use get /api/v1/create_user_key_sawtooth The output will be the

Private_key Public key

{

"status": 200,

"primechain_sawtooth_private_key": "89b0d0a7ef410e9dc19907b8d9297ec2239222c2b38d56056964495b517fe6c1",

"primechain_sawtooth_public_key": "02b023ef5ce8f6ef4e3419ebc925060ceb3ed9f80c489e34fb93033956581b4941",

"response": "User keys generated"

}

2. Publish data to the blockchain

To publish data to the blockchain, use post /api/v1/upload_data_sawtooth and pass 2 parameters:

Private_key The data

{

"primechain_sawtooth_private_key": "89b0d0a7ef410e9dc19907b8d9297ec2239222c2b38d56056964495b517fe6c1",

"data": "Mistakes are always forgivable, if one has the courage to admit them."

}

The output will be the Sawtooth transaction id for the transaction.

{

"status": 200,

"primechain_sawtooth_tx_id": "a31075ee02e17c73b520c3a379880e936a011a702fe412a5e4da0d02300b90623b442e627774671d542565c642d4aa246545faaedaecde16cfa5d979be231e62"

}

3. Retrieve data from the blockchain

To retrieve data from the blockchain, use post /api/v1/get_data_sawtooth and pass the Sawtooth transaction id of the transaction.

{

"primechain_sawtooth_tx_id": "a31075ee02e17c73b520c3a379880e936a011a702fe412a5e4da0d02300b90623b442e627774671d542565c642d4aa246545faaedaecde16cfa5d979be231e62"

}

The output will be the data.

{

"status": 200,

"response": "Mistakes are always forgivable, if one has the courage to admit them."

}

4. Creating a digital signature

To create a digital signature, use post /api/v1/create_signature_sawtooth and pass 2 parameters:

Private key the data

{

"primechain_sawtooth_private_key": "89b0d0a7ef410e9dc19907b8d9297ec2239222c2b38d56056964495b517fe6c1",

"data": "Mistakes are always forgivable, if one has the courage to admit them."

}

The output will be the digital signature:

{

"status": 200,

"signature": "235de04e222dfcfcc0a2cdec32c1a2aaa56b404dc6b0e4e721eef264ce891e1920ff05ee6345635bd017fca97fef2407b57364a287dd27eddc8a82dec61bb87b"

}

5. Verify a digital signature

To verify a digital signature, use post /api/v1/verify_signature_sawtooth and pass 3 parameters:

public key the data the digital signature

{

"primechain_sawtooth_public_key": "02b023ef5ce8f6ef4e3419ebc925060ceb3ed9f80c489e34fb93033956581b4941",

"data": "Mistakes are always forgivable, if one has the courage to admit them.",

"signature": "235de04e222dfcfcc0a2cdec32c1a2aaa56b404dc6b0e4e721eef264ce891e1920ff05ee6345635bd017fca97fef2407b57364a287dd27eddc8a82dec61bb87b"

}

The output will be:

{

"status": 200,

"response": true

}

or

{

"status": 200,

"response": false

}

6. Create, encrypt, sign and publish data to the blockchain

To create, encrypt, sign and publish data to the blockchain, use post /api/v1/encrypt_sign_store_data_sawtooth and pass 2 parameters:

the primechain sawtooth private key the data

Sample input

{

"primechain_sawtooth_private_key": "89b0d0a7ef410e9dc19907b8d9297ec2239222c2b38d56056964495b517fe6c1",

"data":

{

"guarantee_number": "ASDRE76464",

"guarantee_currency": "USD",

"guarantee_amount_words": "Twenty Two million",

"guarantee_amount_figures": "22,000,000.00",

"guarantee_date_of_issue": "17-December-2018",

"guarantee_date_of_maturity": "16-March-2019",

"guarantee_beneficiary": "Nicole Corporation",

"guarantee_details": "On behalf of our client, Nicole Corporation, for value received, we, Global Bank, hereby irrevocably and unconditionally and without protest or notification, promise to pay against this, our irrevocable bank guarantee, to the order of Nicole Corporation, as beneficiary, on the maturity date, the sum of Twenty Two million United States Dollars ($22,000,000.00 USD), upon their first written demand for payment hereunder. Such payment shall be made without set-off, free and clear of any deductions, charges, fees, levies, taxes or withholdings of any nature. This bank guarantee is transferable, without payment of any transfer fees. This bank guarantee is issued in accordance with the uniform customs and practices for bank guarantees, as set forth by the International Chamber of Commerce, Paris, France, latest revision of ICC 500 publication. This bank guarantee shall be governed by and construed in accordance with the laws of the Republic of India and is free and clear of any lien and encumbrances and is of non-criminal origin.",

"authorized_bank_officer_name": "Nicole Kidman",

"authorized_bank_officer_title": "Vice President",

"authorized_bank_officer_telephone": "230950934545",

"authorized_bank_officer_facsimile": "367645455624",

"authorized_bank_officer_email": "nicole@example.com"

}

}

This is what happens:

Step 1: Hash computation

The SHA-512 hash of the data is computed.

Step 2: Signing

The hash is signed using the private key of the signer, using the secp256k1 algorithm.

Step 3: Encrypting the data

The data is encrypted using the AES (Advanced Encryption Standard) algorithm and the following are generated:

the encrypted version of the data the AES password the Initialization Vector (IV). Initialization Vector is a nonce that is associated with an invocation of authenticated encryption on a particular plaintext and Additional Authenticated Data (AAD). the Authentication Tag (tag), which is a cryptographic checksum on data that is designed to reveal both accidental errors and the intentional modification of the data.

Step 4: Storing the encrypted data

The encrypted data and the tag are published to the blockchain.

Step 5: Output

The following is the output:

the relevant Sawtooth transaction id the digital signature the AES password the Initialization Vector (IV)

Sample output

{

"status": 200,

"response": {

"primechain_sawtooth_tx_id": "82cde773d6b25b9a48dcb16f602fbcd5ed3649183d595e19ed545650bdfcc8fc2a9316121281910f43c52d3ba5c9e2d0c0eb6fce3ece54b6a257462bc6d395c1",

"signature": "cb36670bc1e53389473f1fcac881bf8c30e3a8b44ea34a8adb8608ab7dd7dec850073c9d2e6e868b1a4fe94603a2a3fa3187dfd506edf26fc7173a64e9c4e699",

"aes_password": "gkSQEaVPI9bHwGM37NmtjNBUad7mwoHm",

"aes_iv": "RaaizYEJvqxg"

}

}

7. Decrypt, verify and retrieve data from the blockchain

To retrieve data from the blockchain, use post /api/v1/decrypt_download_data_sawtooth and pass these values:

the relevant Sawtooth transaction id the sawtooth public key of the signer the AES password the Initialization Vector (IV) the digital signature

Sample input

{

"primechain_sawtooth_tx_id": "82cde773d6b25b9a48dcb16f602fbcd5ed3649183d595e19ed545650bdfcc8fc2a9316121281910f43c52d3ba5c9e2d0c0eb6fce3ece54b6a257462bc6d395c1", "primechain_sawtooth_public_key": "02b023ef5ce8f6ef4e3419ebc925060ceb3ed9f80c489e34fb93033956581b4941",

"signature": "cb36670bc1e53389473f1fcac881bf8c30e3a8b44ea34a8adb8608ab7dd7dec850073c9d2e6e868b1a4fe94603a2a3fa3187dfd506edf26fc7173a64e9c4e699",

"aes_password": "gkSQEaVPI9bHwGM37NmtjNBUad7mwoHm",

"aes_iv": "RaaizYEJvqxg"

}

This is what happens:

Step 1: Retrieval of encrypted data

The encrypted data and tag are retrieved from the blockchain.

Step 2: Decryption

The encrypted data is decrypted.

Step 3: Verification

The digital signature is verified.

Step 4: Output

The output will be the data if the signature is verified and valid.

Sample output

{

"status": 200,

"response": {

"guarantee_number": "ASDRE76464",

"guarantee_currency": "USD",

"guarantee_amount_words": "Twenty Two million",

"guarantee_amount_figures": "22,000,000.00",

"guarantee_date_of_issue": "17-December-2018",

"guarantee_date_of_maturity": "16-March-2019",

"guarantee_beneficiary": "Nicole Corporation",

"guarantee_details": "On behalf of our client, Nicole Corporation, for value received, we, Global Bank, hereby irrevocably and unconditionally and without protest or notification, promise to pay against this, our irrevocable bank guarantee, to the order of Nicole Corporation, as beneficiary, on the maturity date, the sum of Twenty Two million United States Dollars ($22,000,000.00 USD), upon their first written demand for payment hereunder. Such payment shall be made without set-off, free and clear of any deductions, charges, fees, levies, taxes or withholdings of any nature. This bank guarantee is transferable, without payment of any transfer fees. This bank guarantee is issued in accordance with the uniform customs and practices for bank guarantees, as set forth by the International Chamber of Commerce, Paris, France, latest revision of ICC 500 publication. This bank guarantee shall be governed by and construed in accordance with the laws of the Republic of India and is free and clear of any lien and encumbrances and is of non-criminal origin.",

"authorized_bank_officer_name": "Nicole Kidman",

"authorized_bank_officer_title": "Vice President",

"authorized_bank_officer_telephone": "230950934545",

"authorized_bank_officer_facsimile": "367645455624",

"authorized_bank_officer_email": "nicole@example.com"

}

}

Have a query? Email us on info@primechain.in
['Rohas Nagpal']
['Primechain', 'Blockchain', 'Blockchain Technology', 'Blockchain Application', 'Hyperledger']