Skip to main content

Wrap documents

Every OA 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) is stored onto the document store as evidence of issuance. To compute the checksum, a raw document goes through a process known as wrapping to become a wrapped document.

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.

In this task, you will learn how to generate the checksum by running the wrapping process.

You 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. The merkleRoot represents documents either individually or in a batch, and is crucial for verifying the issuance status of OA documents.

Replacing folder names

Important: If you are using both the Ethereum and DID methods, use different folders to contain the wrapped documents. This will prevent the files from being overwritten.

Before running the command below, replace the folder names. For example:

  • Replace <RAW_DOCUMENTS_FOLDER> with raw-documents-did
  • Replace <WRAPPED_DOCUMENTS_FOLDER> with wrapped-documents-did

Running the wrap command

From the folder containing the <RAW_DOCUMENTS_FOLDER> folder, run the command:

open-attestation wrap <RAW_DOCUMENTS_FOLDER> --output-dir <WRAPPED_DOCUMENTS_FOLDER>

Getting the response

In the response, you will see the success message with the Batch Document Root.

✔  success   Batch Document Root: 0x80cc53b77c0539fc383f8d434ac5ffad281f3d64ae5a0e59e9f36f19548e1fff

Saving the merkle root

In the above sample, the batch document root (also known as "merkle root") is 0x80cc53b77c0539fc383f8d434ac5ffad281f3d64ae5a0e59e9f36f19548e1fff.

You will definitely have a different value.

Important: Save this value for future reference.

Viewing the wrapped documents

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

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

In the wrapped-documents-did directory, you will find the wrapped documents that will be signed with your DID in the next article.

Wrapping a single document

This is an alternative way. Instead of wrapping all documents in a folder in a batch, you can also wrap a single document at a time.

Replace the folder/file names below and run the command:

open-attestation wrap ./<RAW_DOCUMENTS_FOLDER>/<FILENAME>.json --output-dir <WRAPPED_DOCUMENTS_FOLDER> 

Change directory to the <WRAPPED_DOCUMENTS_FOLDER> to check the wrapped document in JSON format has been created.