Gathering detailed insights and metrics for @govtechsg/document-store-ethers-v5
Gathering detailed insights and metrics for @govtechsg/document-store-ethers-v5
Smart Contracts for OpenAttestation's Document Store
npm install @govtechsg/document-store-ethers-v5
Typescript
Module System
Node Version
NPM Version
78.2
Supply Chain
99.2
Quality
86
Maintenance
100
Vulnerability
100
License
Solidity (94.05%)
Shell (4.91%)
JavaScript (0.72%)
TypeScript (0.32%)
Total Downloads
1,001
Last Day
3
Last Week
9
Last Month
44
Last Year
1,001
26 Stars
162 Commits
16 Forks
15 Watching
6 Branches
15 Contributors
Minified
Minified + Gzipped
Latest Version
4.1.0
Package Id
@govtechsg/document-store-ethers-v5@4.1.0
Unpacked Size
1.92 MB
Size
289.17 kB
File Count
45
NPM Version
10.8.1
Node Version
20.15.0
Publised On
16 Jul 2024
Cumulative downloads
Total Downloads
Last day
0%
3
Compared to previous day
Last week
800%
9
Compared to previous week
Last month
22.2%
44
Compared to previous month
Last year
0%
1,001
Compared to previous year
1
Document Store (ethers-v5)
Document Store Smart Contracts for the OpenAttestation framework
The Document Store is a set of smart contracts for managing the issuance and revocation of documents. It is designed to be used in conjunction with the OpenAttestation library to issue and verify documents on the blockchains.
There are 2 types of document stores, namely, the regular Document Store and the Transferable Document Store.
The regular Document Store allows issuers to issue and revoke documents. However, these documents do not have an owner and are, hence, not transferable. Multiple documents issued on the Document Store can be "batched" under a single hash for issuance.
The Transferable Document Store allows issuers to issue and revoke documents, and these documents have an owner and are transferable. Each document is essentially an ERC-721 NFT (Non-Fungible Token). Thus, documents are issued individually and the document holder's identity can be verified. Although the documents are transferable, they can also be issued as "soulbound" documents which bounds to an owner. This can be particularly useful for certain use cases such as POAP.
To make integration easier, we have provided the packages containing the Typechain bindings for interacting with the document store.
1npm install @govtechsg/document-store-ethers-v6
1npm install @govtechsg/document-store-ethers-v5
For a complete list of functions, refer to IDocumentStoreBatchable.sol.
1import { DocumentStore__factory } from "@govtechsg/document-store-ethers-v6"; // Or from "@govtechsg/document-store-ethers-v5" 2 3const documentStore = DocumentStore__factory.connect(documentStoreAddress, signer); 4const tx = await documentStore["issue"]("0x1234"); 5await tx.wait();
1const oaDocumentSignature = { 2 documentRoot: "0xMerkleRoot", 3 targetHash: "0xTargetHash", 4 proof: ["0xProof1", "0xProof2"] 5}; 6 7const documentStore = DocumentStore__factory.connect(documentStoreAddress, signer); 8const tx = await documentStore["issue"](oaDocumentSignature.documentRoot); 9await tx.wait(); 10 11try { 12 const isDocIssued = await documentStore.isIssued( 13 oaDocumentSignature.documentRoot, 14 oaDocumentSignature.targetHash, 15 oaDocumentSignature.proof 16 ); 17 18 console.log(isDocIssued); // Returns true or false 19} catch (e) { 20 // Error will be thrown if proof is invalid 21 console.error(e); 22}
Note that this is different from batching. This issues multiple documents or document roots at once.
1const documentStore = DocumentStore__factory.connect(documentStoreAddress, signer); 2const bulkIssuances = [ 3 documentStore.interface.encodeFunctionData("issue", ["0xDocRoot1"]), 4 documentStore.interface.encodeFunctionData("issue", ["0xDocRoot2"]) 5]; 6const tx = await documentStore.multicall(bulkIssuances); 7await tx.wait();
1const documentStore = DocumentStore__factory.connect(documentStoreAddress, signer); 2const tx = await documentStore["revoke"]("0x1234"); 3await tx.wait();
1const documentStore = DocumentStore__factory.connect(documentStoreAddress, signer); 2const tx = await documentStore["revoke"]("0xDocumentRoot", "0xTargetHash", ["0xProof1", "0xProof2"]); 3await tx.wait();
For a complete list of functions, refer to ITransferableDocumentStore.sol.
1import { TransferableDocumentStore__factory } from "@govtechsg/document-store-ethers-v6"; // Or from "@govtechsg/document-store-ethers-v5" 2 3const transferableDocumentStore = TransferableDocumentStore__factory.connect(transferableDocumentStoreAddress, signer); 4 5// Issues a transferable document 6const tx = await transferableDocumentStore.issue("0xRecipientAddress", "0xDocTargetHash", false); 7await tx.wait(); 8 9//Issues a soulbound document 10const tx = await transferableDocumentStore.issue("0xRecipientAddress", "0xDocTargetHash", true); 11await tx.wait();
1const transferableDocumentStore = TransferableDocumentStore__factory.connect(transferableDocumentStoreAddress, signer); 2const tx = await transferableDocumentStore.revoke("0xDocTargetHash"); 3await tx.wait();
Roles are useful for granting users to access certain functions only. Here are the designated roles meant for the different key operations.
Role | Access |
---|---|
DEFAULT_ADMIN_ROLE | Able to perform all operations |
ISSUER_ROLE | Able to issue documents |
REVOKER_ROLE | Able to revoke documents |
A trusted user can be granted multiple roles by the admin user to perform different operations. The following functions can be called on the token contract by the admin user to grant and revoke roles to and from users.
1const issuerRole = await documentStore.issuerRole(); 2await documentStore.grantRole(issuerRole, "0xIssuerStaff");
Can only be called by default admin or role admin.
1const revokerRole = await documentStore.revokerRole(); 2await documentStore.revokeRole(revokerRole, "0xRevokerStaff");
Can only be called by default admin or role admin.
In all the deployment commands, you can replace network
argument to any of the supported networks. Optionally, you can also supply --verify=1
if you wish to verify the contracts. During deployment, you will be prompted to supply your private key interactively.
[!IMPORTANT] The
DEPLOYER_ADDRESS
in.env
is required to be the address of the deployer. See Configuration section.
1npm run -s deploy:ds --network="mainnet" --name="My Document Store" --admin="0x1234"
The name
is the name you want to have for the document store and the admin
is the address who will be the default admin of the document store.
1npm run -s deploy:ds:upgradeable --network="mainnet" --name="My Document Store" --admin="0x1234" --verify=1
Note that in the example above, the --verify=1
is optionally passed to verify the contracts.
1npm run -s deploy:tds --network="mainnet" --name="My Transferable Document Store" --symbol="XYZ" --admin="0x1234" --verify=1
The name
and symbol
are the standard ERC-721 token name and symbol respectively. The admin
is the address who will be the default admin of the document store.
1npm run -s deploy:tds:upgradeable --network="mainnet" --name="My Transferable Document Store" --symbol="XYZ" --admin="0x1234" --verify=1
To deploy using a hardware wallet, you can set the OA_LEDGER
environment variable to the HD path of your wallet. For example, OA_LEDGER=m/44'/60'/0'/0/0
.
You can pass --verify=1
to the deployment commands if you wish to verify the contracts. You will need to include your Etherscan API keys for the respective networks in your .env
configuration. See Configuration section for more info.
Most EVM-based blockchains should support the document store contracts. For the more common blockchains listed below, we may deploy implementations to help reduce deployment gas fees.
[!NOTE] For a list of pre-configured network names for passing to
--network
during deployment, refer to the foundry.toml file.
If you wish to deploy to a network not configured yet, you can add it to the foundry.toml
file and pass the name of the network you've added to --network
during deployment.
Create a .env
file based on .env.example
and provide the information in it.
The DEPLOYER_ADDRESS
is required to be the address of the deployer during deployment. The Etherscan API keys are only required if you plan to verify the contracts on their respective chains.
This repository uses Foundry for its development. To install Foundry, run the following commands:
1curl -L https://foundry.paradigm.xyz | bash
The contracts have not gone through formal audits yet. Please use them at your own discretion.
No vulnerabilities found.
No security vulnerabilities found.