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:
Property | Type | Description |
---|---|---|
data (required) | Uint8Array | Raw file contents. Used to generate the hash. Not stored on chain. |
algorithm (required) | String | Hashing algorithm. It can be either 'SHA-256' or 'SHA-512' . |
sign (optional) | Boolean | Specify 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) | Boolean | Specify 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 sign is true) | String | JWK | ES256 Public key of the receiver, either as JWK or as uncompressed hex string |
metadata (optional) | Object | Any 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.
Index | Description | Value |
---|---|---|
0 | Protocol ID | "hash" |
1 | Envelope | Serialized JWE/JWS |
2 | Receiver key | Public key of the receiver |