Skip to main content

Feedback

Loading...
Version: 5.x

Wrapping Documents (CLI)

For the current step, you can either opt to use the CLI or Code.

Every TradeTrust document has a checksum that provides it a tamper-proof property. At the same time, because the checksum can be used to uniquely identify a document, the checksum (or its derived value) will be signed as evidence of issuance. To compute the checksum, a raw document goes through a process known as wrapping to become a wrapped document. Only then, the document is ready to be signed.

Multiple documents can be wrapped at the same time in a single batch operation, creating a single checksum for the entire batch of raw documents. This is especially useful when using document store on the Ethereum blockchain to lower the transaction cost and time.

In this guide, we will learn how to generate the checksum by running the wrapping process.

We will use the CLI tool to read all the files in the raw-documents folder, wrap them and then output the files in another directory wrapped-documents.

A merkleRoot, a 64 character long string prepended with 0x will be generated.

From the folder containing the raw-documents folder, run:

tradetrust wrap raw-documents --output-dir wrapped-documents
✔ success Batch Document Root: 0x80cc53b77c0539fc383f8d434ac5ffad281f3d64ae5a0e59e9f36f19548e1fff

After running the CLI you will see the success message with the Batch Document Root. In the above sample, the document root (also known as merkle root) is 0x80cc53b77c0539fc383f8d434ac5ffad281f3d64ae5a0e59e9f36f19548e1fff, you will definitely have a different value.

Save this value for future reference.

At the same time, you will notice that another directory, wrapped-document, has been created:

wallet.json
raw-documents
|-- certificate-1.json
|-- certificate-2.json
wrapped-documents
|-- certificate-1.json
|-- certificate-2.json

In the wrapped-document directory, you will find the wrapped document which can be sent to the recipient later once the merkleRoot has been issued to the document store.

Visit our github page to learn more about TradeTrust CLI wrapping!

Now let us take a look at a wrapped document.

// wrappedDocument
{
"version": "https://schema.openattestation.com/2.0/schema.json",
"data": {
"recipient": { "name": "2ddbe317-a9d1-4af7-9ff1-085036d83cc8:string:John Doe" },
"$template": {
"name": "338403ee-cbfa-4fdd-9f8f-4535803ca1d2:string:main",
"type": "172389bf-ef30-448f-9153-79475c4a0236:string:EMBEDDED_RENDERER",
"url": "8aaf3835-f1d5-444d-9855-0ec230c271ec:string:https://tutorial-renderer.openattestation.com"
},
"issuers": [
{
"id": "592202e4-bf4b-4826-9639-a9a3fad38314:string:did:ethr:0xaCc51f664D647C9928196c4e33D46fd98FDaA91D",
"name": "2fb102d4-00b2-4c42-87b9-ab545829a4ab:string:Demo Issuer",
"revocation": { "type": "f86d77af-296a-46d1-8a5e-3af549d03773:string:NONE" },
"identityProof": {
"type": "f8bf7139-6ca5-4678-b2c7-49aa81ac3ccc:string:DNS-DID",
"location": "a84e9b5b-a99f-4248-ac4d-087b66eec523:string:intermediate-sapphire-catfish.sandbox.openattestation.com",
"key": "5bc9f48f-5f85-4a8f-a3c4-2e99ee94b509:string:did:ethr:0xaCc51f664D647C9928196c4e33D46fd98FDaA91D#controller"
}
}
]
},
"signature": {
"type": "SHA3MerkleProof",
"targetHash": "1d9f8d9sd9fjeiweob50ac63129782a1c3y837f6s78s8cg8hjg76hj5h342k33h",
"proof": [],
"merkleRoot": "d83534d672d96753ea3cb50ac63129782a1c345d98b1141f9fe5449f1c225601"
}
}

The signature section includes the fields of targetHash and merkleRoot.

signature.targetHash is the generated hash of the document, computed on the algorithm stated on the signature.type.

In this scenario, signature.merkleRoot will not be the same as signature.targetHash as we just did a batch wrapping of the documents.

Please keep in mind that if we were to wrap a single file, the signature.merkleRoot and the signature.targetHash will be the same.

Congratulation! you have successfully wrapped the documents, next lets see how we can sign the documents to 'issue' it.