Skip to main content

Hash

The Hash envelope allows storing a document hash on the blockchain. It does not store the document.

By storing the document hash, a user can implement file tampering prevention, allowing other users to be able to validate that the document contents are equal to the original.

Creating a Hash Envelope​

Creating a new hash envelope to be stored on chain, can be achieved by adding a specific output object of type hash and add it to the createTransaction outputs argument.

This output type requires the following properties:

PropertyTypeDescription
data (required)Uint8ArrayRaw file contents. Used to generate the hash. Not stored on chain.
algorithm (required)StringHashing algorithm. It can be either 'SHA-256' or 'SHA-512'.
sign (optional)BooleanSpecify true if the envelope is going to be signed. If this is the case, a signing key needs to be specified. See: key property below.
encrypt(optional)BooleanSpecify true if the envelope is going to be encrypted. If this is the case, an encryption key needs to be specified. See: key property below.
key (required only if encrypt or signis true)String | JWKES256 Public key of the receiver, either as JWK or as uncompressed hex string
metadata(optional)ObjectAny extra information to store within mintBlue. Not stored on chain.

Example​

const data = new Uint8Array(Buffer.from('My file contents'));

const outputs = [
{
type: 'hash',
data: data,
algorithm: 'SHA-256',
},
];

// Replace [PROJECT_ID] below with yours.
const { txid, rawtx } = await client.createTransaction({project_id: '[PROJECT_ID]', outputs});

OP_RETURN​

The following OP_RETURN arguments are created when a hash envelope is published on a blockchain transaction.

IndexDescriptionValue
0Protocol ID"hash"
1EnvelopeSerialized JWE/JWS
2Receiver keyPublic key of the receiver