Revoking Documents (Code)
For the current step, you can either opt to use the CLI or Code.
Installation
npm i @tradetrust-tt/tradetrust-core
Usage
To use the package, you will need to provide your own Web3 provider or signer (if you are writing to the blockchain).
Refer to the pre-requisite on document store deployment.
Connect to existing document store
import { DocumentStoreFactory } from "@tradetrust-tt/tradetrust-core";
import { Wallet, ethers } from "ethers";
const unconnectedWallet = new Wallet("privateKey");
const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545"); // Local network
const wallet = unconnectedWallet.connect(provider);
const documentStore = DocumentStoreFactory.connect("0x63A223E025256790E88778a01f480eBA77731D04", wallet);
console.log(`Document Store Name: ${await documentStore.name()}`); // Document Store Name: DemoDocumentStore
Revocation on document store
const unconnectedWallet = new Wallet("privateKey");
const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545"); // Local network
const wallet = unconnectedWallet.connect(provider);
const documentStore = DocumentStoreFactory.connect("0x63A223E025256790E88778a01f480eBA77731D04", wallet);
const tx = await documentStore.revoke("0x8dcf358a9436bca6654f565e3c5843d91c0052d3a2eff37bbd380038e8a1fa39");
const receipt = await tx.wait();
console.log(`Revoke Transaction: ${JSON.stringify(receipt)}`);
const isIssued = await documentStore.isRevoked("0x8dcf358a9436bca6654f565e3c5843d91c0052d3a2eff37bbd380038e8a1fa39");
console.log(`Has been Revoked: ${isIssued}`); // Has been Revoked: true
// Revoke Transaction:
{
"to": "0x63A223E025256790E88778a01f480eBA77731D04",
"from": "0xe0A71284EF59483795053266CB796B65E48B5124",
"contractAddress": null,
"transactionIndex": 0,
"gasUsed": { "type": "BigNumber", "hex": "0xbb6c" },
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000040000000000000000000000100000000400000000000000000000000000000000000000800000000000000000000000000000",
"blockHash": "0x7ba420b317c537731de1c70b9b1075213b40b6b69dcde48c592e1b3ab7926e95",
"transactionHash": "0xe15b2f8fda95ff29338722458be80fe14817019f565c82cd24115fda3bc36ae2",
"logs": [
{
"transactionIndex": 0,
"blockNumber": 4742644,
"transactionHash": "0xe15b2f8fda95ff29338722458be80fe14817019f565c82cd24115fda3bc36ae2",
"address": "0x63A223E025256790E88778a01f480eBA77731D04",
"topics": [
"0x7283b5ab9758f7fba773279e4fd50ea7b136bd1d8371dcae9c5ce529c55343d7",
"0x8dcf358a9436bca6654f565e3c5843d91c0052d3a2eff37bbd380038e8a1fa39"
],
"data": "0x",
"logIndex": 0,
"blockHash": "0x7ba420b317c537731de1c70b9b1075213b40b6b69dcde48c592e1b3ab7926e95"
}
],
"blockNumber": 4742644,
"confirmations": 1,
"cumulativeGasUsed": { "type": "BigNumber", "hex": "0xbb6c" },
"effectiveGasPrice": { "type": "BigNumber", "hex": "0x0184d5b7b1" },
"status": 1,
"type": 2,
"byzantium": true,
"events": [
{
"transactionIndex": 0,
"blockNumber": 4742644,
"transactionHash": "0xe15b2f8fda95ff29338722458be80fe14817019f565c82cd24115fda3bc36ae2",
"address": "0x63A223E025256790E88778a01f480eBA77731D04",
"topics": [
"0x7283b5ab9758f7fba773279e4fd50ea7b136bd1d8371dcae9c5ce529c55343d7",
"0x8dcf358a9436bca6654f565e3c5843d91c0052d3a2eff37bbd380038e8a1fa39"
],
"data": "0x",
"logIndex": 0,
"blockHash": "0x7ba420b317c537731de1c70b9b1075213b40b6b69dcde48c592e1b3ab7926e95",
"args": ["0x8dcf358a9436bca6654f565e3c5843d91c0052d3a2eff37bbd380038e8a1fa39"],
"event": "DocumentRevoked",
"eventSignature": "DocumentRevoked(bytes32)"
}
]
}
Please refer to Document-Store repository on other interfaces available on the smart contracts;
Verifying the document
Head to dev.tradetrust.io and drag and drop the revoked document. An error will be displayed by the portal.
The document has been revoked, thus, we do not display the content of the document on our document viewer.
Misc questions:
Q: hey you mentioned that if I use DID documents, I would not need to pay for transactions, but following this flow, I would still have to pay for at least 1 transaction (deploying a documentStore
), what gives?
A: yes, you are right, for now this implementation will still need at least 1 transaction to the ethereum blockchain. We are working on this so please be patient and watch this space.
Q: this might be a weird question but I did not issue any documents from the deployed documentStore
, how am I able to revoke this document from said documentStore
when in the first place, I did not even issue anything?
A: long story short, the revocation mapping in the documentStore
is a separate mapping from the issued mapping.