@trustvc/trustvc 2.6.1 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +217 -0
- package/dist/cjs/document-store/contract-interfaces.js +24 -0
- package/dist/cjs/document-store/deploy.js +49 -0
- package/dist/cjs/document-store/document-store-roles.js +38 -0
- package/dist/cjs/document-store/grant-role.js +67 -0
- package/dist/cjs/document-store/index.js +49 -0
- package/dist/cjs/document-store/issue.js +66 -0
- package/dist/cjs/document-store/revoke-role.js +67 -0
- package/dist/cjs/document-store/revoke.js +66 -0
- package/dist/cjs/document-store/supportInterfaceIds.js +22 -0
- package/dist/cjs/document-store/transferOwnership.js +42 -0
- package/dist/cjs/document-store/tt-document-store-abi.js +231 -0
- package/dist/cjs/document-store/types.js +2 -0
- package/dist/cjs/index.js +29 -0
- package/dist/esm/document-store/contract-interfaces.js +22 -0
- package/dist/esm/document-store/deploy.js +47 -0
- package/dist/esm/document-store/document-store-roles.js +35 -0
- package/dist/esm/document-store/grant-role.js +65 -0
- package/dist/esm/document-store/index.js +8 -0
- package/dist/esm/document-store/issue.js +64 -0
- package/dist/esm/document-store/revoke-role.js +65 -0
- package/dist/esm/document-store/revoke.js +64 -0
- package/dist/esm/document-store/supportInterfaceIds.js +20 -0
- package/dist/esm/document-store/transferOwnership.js +40 -0
- package/dist/esm/document-store/tt-document-store-abi.js +229 -0
- package/dist/esm/document-store/types.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/types/document-store/contract-interfaces.d.ts +14 -0
- package/dist/types/document-store/deploy.d.ts +29 -0
- package/dist/types/document-store/document-store-roles.d.ts +14 -0
- package/dist/types/document-store/grant-role.d.ts +28 -0
- package/dist/types/document-store/index.d.ts +15 -0
- package/dist/types/document-store/issue.d.ts +27 -0
- package/dist/types/document-store/revoke-role.d.ts +28 -0
- package/dist/types/document-store/revoke.d.ts +32 -0
- package/dist/types/document-store/supportInterfaceIds.d.ts +16 -0
- package/dist/types/document-store/transferOwnership.d.ts +30 -0
- package/dist/types/document-store/tt-document-store-abi.d.ts +388 -0
- package/dist/types/document-store/types.d.ts +15 -0
- package/dist/types/index.d.ts +17 -10
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ TrustVC is a comprehensive wrapper library designed to simplify the signing and
|
|
|
26
26
|
- [a) Token Registry v4](#a-token-registry-v4)
|
|
27
27
|
- [b) Token Registry V5](#b-token-registry-v5)
|
|
28
28
|
- [8. **Document Builder**](#8-document-builder)
|
|
29
|
+
- [9. **Document Store**](#9-document-store)
|
|
29
30
|
|
|
30
31
|
## Installation
|
|
31
32
|
|
|
@@ -890,3 +891,219 @@ To get the current state of the document as a JSON string:
|
|
|
890
891
|
const documentJson = builder.toString();
|
|
891
892
|
console.log(documentJson);
|
|
892
893
|
```
|
|
894
|
+
|
|
895
|
+
## 9. Document Store
|
|
896
|
+
|
|
897
|
+
> TrustVC provides comprehensive Document Store functionality for managing blockchain-based document storage and verification. The Document Store module supports both standard DocumentStore and TransferableDocumentStore contracts, enabling secure document issuance, revocation, and role management on various blockchain networks.
|
|
898
|
+
|
|
899
|
+
### Key Features
|
|
900
|
+
|
|
901
|
+
- **Dual Contract Support**: Works with both DocumentStore and TransferableDocumentStore contracts
|
|
902
|
+
- **Automatic Contract Detection**: Uses ERC-165 interface checking to automatically identify contract types
|
|
903
|
+
- **Ethers Compatibility**: Full support for both ethers v5 and v6
|
|
904
|
+
- **Type Safety**: Full TypeScript support with comprehensive type definitions
|
|
905
|
+
|
|
906
|
+
### Functions
|
|
907
|
+
|
|
908
|
+
#### deployDocumentStore
|
|
909
|
+
|
|
910
|
+
Deploys a new DocumentStore contract to the blockchain.
|
|
911
|
+
|
|
912
|
+
**Parameters:**
|
|
913
|
+
- `storeName` (string): The name of the document store
|
|
914
|
+
- `owner` (string): The owner address of the document store
|
|
915
|
+
- `signer` (Signer): Ethers v5 or v6 signer instance
|
|
916
|
+
- `options` (DeployOptions, optional): Deployment configuration
|
|
917
|
+
|
|
918
|
+
**DeployOptions:**
|
|
919
|
+
- `chainId` (CHAIN_ID, optional): Target blockchain network
|
|
920
|
+
- `maxFeePerGas` (GasValue, optional): Maximum fee per gas
|
|
921
|
+
- `maxPriorityFeePerGas` (GasValue, optional): Maximum priority fee per gas
|
|
922
|
+
- `isTransferable` (boolean, optional): Whether to deploy TransferableDocumentStore
|
|
923
|
+
|
|
924
|
+
**Returns:** `Promise<TransactionReceipt>` - The deployment transaction receipt
|
|
925
|
+
|
|
926
|
+
**Example:**
|
|
927
|
+
|
|
928
|
+
```ts
|
|
929
|
+
import { deployDocumentStore } from '@trustvc/trustvc';
|
|
930
|
+
|
|
931
|
+
const receipt = await deployDocumentStore(
|
|
932
|
+
'My Document Store',
|
|
933
|
+
'0x1234567890123456789012345678901234567890',
|
|
934
|
+
signer,
|
|
935
|
+
{
|
|
936
|
+
chainId: CHAIN_ID.sepolia,
|
|
937
|
+
isTransferable: true,
|
|
938
|
+
}
|
|
939
|
+
);
|
|
940
|
+
|
|
941
|
+
console.log('Contract deployed at:', receipt.contractAddress);
|
|
942
|
+
```
|
|
943
|
+
|
|
944
|
+
#### documentStoreIssue
|
|
945
|
+
|
|
946
|
+
Issues a document to the Document Store.
|
|
947
|
+
|
|
948
|
+
**Parameters:**
|
|
949
|
+
- `documentStoreAddress` (string): Address of the Document Store contract
|
|
950
|
+
- `documentHash` (string): Hash of the document to issue
|
|
951
|
+
- `signer` (Signer): Ethers v5 or v6 signer instance
|
|
952
|
+
- `options` (IssueOptions, optional): Issuance configuration
|
|
953
|
+
|
|
954
|
+
**IssueOptions:**
|
|
955
|
+
- `chainId` (CHAIN_ID, optional): Target blockchain network
|
|
956
|
+
- `maxFeePerGas` (GasValue, optional): Maximum fee per gas
|
|
957
|
+
- `maxPriorityFeePerGas` (GasValue, optional): Maximum priority fee per gas
|
|
958
|
+
- `isTransferable` (boolean, optional): Whether the contract is TransferableDocumentStore
|
|
959
|
+
|
|
960
|
+
**Returns:** `Promise<string>` - Transaction hash of the issuance
|
|
961
|
+
|
|
962
|
+
**Example:**
|
|
963
|
+
|
|
964
|
+
```ts
|
|
965
|
+
import { documentStoreIssue } from '@trustvc/trustvc';
|
|
966
|
+
|
|
967
|
+
const txHash = await documentStoreIssue(
|
|
968
|
+
'0x1234567890123456789012345678901234567890',
|
|
969
|
+
'0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
|
|
970
|
+
signer,
|
|
971
|
+
{
|
|
972
|
+
chainId: CHAIN_ID.sepolia,
|
|
973
|
+
isTransferable: false,
|
|
974
|
+
}
|
|
975
|
+
);
|
|
976
|
+
|
|
977
|
+
console.log('Document issued, transaction:', txHash);
|
|
978
|
+
```
|
|
979
|
+
|
|
980
|
+
#### documentStoreRevoke
|
|
981
|
+
|
|
982
|
+
Revokes a document from the Document Store.
|
|
983
|
+
|
|
984
|
+
**Parameters:**
|
|
985
|
+
- `documentStoreAddress` (string): Address of the Document Store contract
|
|
986
|
+
- `documentHash` (string): Hash of the document to revoke
|
|
987
|
+
- `signer` (Signer): Ethers v5 or v6 signer instance
|
|
988
|
+
- `options` (RevokeOptions, optional): Revocation configuration
|
|
989
|
+
|
|
990
|
+
**RevokeOptions:**
|
|
991
|
+
- `chainId` (CHAIN_ID, optional): Target blockchain network
|
|
992
|
+
- `maxFeePerGas` (GasValue, optional): Maximum fee per gas
|
|
993
|
+
- `maxPriorityFeePerGas` (GasValue, optional): Maximum priority fee per gas
|
|
994
|
+
- `isTransferable` (boolean, optional): Whether the contract is TransferableDocumentStore
|
|
995
|
+
|
|
996
|
+
**Returns:** `Promise<string>` - Transaction hash of the revocation
|
|
997
|
+
|
|
998
|
+
**Example:**
|
|
999
|
+
|
|
1000
|
+
```ts
|
|
1001
|
+
import { documentStoreRevoke } from '@trustvc/trustvc';
|
|
1002
|
+
|
|
1003
|
+
const txHash = await documentStoreRevoke(
|
|
1004
|
+
'0x1234567890123456789012345678901234567890',
|
|
1005
|
+
'0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890',
|
|
1006
|
+
signer,
|
|
1007
|
+
{
|
|
1008
|
+
chainId: CHAIN_ID.sepolia,
|
|
1009
|
+
isTransferable: false,
|
|
1010
|
+
}
|
|
1011
|
+
);
|
|
1012
|
+
|
|
1013
|
+
console.log('Document revoked, transaction:', txHash);
|
|
1014
|
+
```
|
|
1015
|
+
|
|
1016
|
+
### Contract Types
|
|
1017
|
+
|
|
1018
|
+
#### DocumentStore
|
|
1019
|
+
- Basic document store functionality
|
|
1020
|
+
- Supports document issuance and revocation
|
|
1021
|
+
- ERC-165 interface: `0x01ffc9a7` (IDocumentStore)
|
|
1022
|
+
|
|
1023
|
+
#### TransferableDocumentStore
|
|
1024
|
+
- Extended document store with transfer capabilities
|
|
1025
|
+
- All DocumentStore functionality plus transfer features
|
|
1026
|
+
- ERC-165 interface: `0x8c5a6b8a` (ITransferableDocumentStore)
|
|
1027
|
+
|
|
1028
|
+
### Error Handling
|
|
1029
|
+
|
|
1030
|
+
All functions include comprehensive error handling:
|
|
1031
|
+
|
|
1032
|
+
- **Validation Errors**: Invalid addresses, missing parameters, provider issues
|
|
1033
|
+
- **Contract Errors**: Pre-check failures, insufficient permissions, contract reverts
|
|
1034
|
+
- **Network Errors**: Connection issues, transaction failures
|
|
1035
|
+
- **Interface Detection**: Automatic fallback when ERC-165 interfaces are not supported
|
|
1036
|
+
|
|
1037
|
+
### Gas Optimization
|
|
1038
|
+
|
|
1039
|
+
The Document Store functions support gas optimization through configurable transaction options:
|
|
1040
|
+
|
|
1041
|
+
```ts
|
|
1042
|
+
const options = {
|
|
1043
|
+
maxFeePerGas: '50000000000', // 50 gwei
|
|
1044
|
+
maxPriorityFeePerGas: '2000000000', // 2 gwei
|
|
1045
|
+
chainId: CHAIN_ID.mainnet,
|
|
1046
|
+
};
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
### Usage Patterns
|
|
1050
|
+
|
|
1051
|
+
#### Basic Usage
|
|
1052
|
+
|
|
1053
|
+
```ts
|
|
1054
|
+
import { deployDocumentStore, documentStoreIssue, documentStoreRevoke } from '@trustvc/trustvc';
|
|
1055
|
+
|
|
1056
|
+
// Deploy a new document store
|
|
1057
|
+
const receipt = await deployDocumentStore('My Store', ownerAddress, signer);
|
|
1058
|
+
|
|
1059
|
+
// Issue a document
|
|
1060
|
+
await documentStoreIssue(receipt.contractAddress, documentHash, signer);
|
|
1061
|
+
|
|
1062
|
+
// Revoke if needed
|
|
1063
|
+
await documentStoreRevoke(receipt.contractAddress, documentHash, signer);
|
|
1064
|
+
```
|
|
1065
|
+
|
|
1066
|
+
#### Advanced Usage with Options
|
|
1067
|
+
|
|
1068
|
+
```ts
|
|
1069
|
+
import { CHAIN_ID } from '@trustvc/trustvc';
|
|
1070
|
+
|
|
1071
|
+
// Deploy with specific network and gas settings
|
|
1072
|
+
const receipt = await deployDocumentStore(
|
|
1073
|
+
'Production Store',
|
|
1074
|
+
ownerAddress,
|
|
1075
|
+
signer,
|
|
1076
|
+
{
|
|
1077
|
+
chainId: CHAIN_ID.mainnet,
|
|
1078
|
+
maxFeePerGas: '100000000000', // 100 gwei
|
|
1079
|
+
maxPriorityFeePerGas: '5000000000', // 5 gwei
|
|
1080
|
+
isTransferable: true,
|
|
1081
|
+
}
|
|
1082
|
+
);
|
|
1083
|
+
|
|
1084
|
+
// Issue with explicit contract type detection
|
|
1085
|
+
await documentStoreIssue(
|
|
1086
|
+
receipt.contractAddress,
|
|
1087
|
+
documentHash,
|
|
1088
|
+
signer,
|
|
1089
|
+
{
|
|
1090
|
+
chainId: CHAIN_ID.mainnet,
|
|
1091
|
+
isTransferable: true, // Explicit type detection
|
|
1092
|
+
}
|
|
1093
|
+
);
|
|
1094
|
+
```
|
|
1095
|
+
|
|
1096
|
+
#### Batch Operations
|
|
1097
|
+
|
|
1098
|
+
```ts
|
|
1099
|
+
// Issue multiple documents
|
|
1100
|
+
const documentHashes = [
|
|
1101
|
+
'0xhash1...',
|
|
1102
|
+
'0xhash2...',
|
|
1103
|
+
'0xhash3...',
|
|
1104
|
+
];
|
|
1105
|
+
|
|
1106
|
+
for (const hash of documentHashes) {
|
|
1107
|
+
await documentStoreIssue(storeAddress, hash, signer);
|
|
1108
|
+
}
|
|
1109
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var documentStore = require('@trustvc/document-store');
|
|
4
|
+
|
|
5
|
+
const IDocumentStoreInterface = documentStore.IDocumentStore__factory.createInterface();
|
|
6
|
+
const ITransferableDocumentStoreInterface = documentStore.ITransferableDocumentStore__factory.createInterface();
|
|
7
|
+
const IDocumentStoreFunctions = Object.values(IDocumentStoreInterface.fragments).filter((f) => f.type === "function").map((f) => f.format("sighash"));
|
|
8
|
+
const ITransferableDocumentStoreFunctions = Object.values(
|
|
9
|
+
ITransferableDocumentStoreInterface.fragments
|
|
10
|
+
).filter((f) => f.type === "function").map((f) => f.format("sighash"));
|
|
11
|
+
const contractInterfaces = {
|
|
12
|
+
/**
|
|
13
|
+
* IDocumentStore interface functions
|
|
14
|
+
* Functions: isActive, isIssued, isRevoked, name, revoke
|
|
15
|
+
*/
|
|
16
|
+
DocumentStore: IDocumentStoreFunctions,
|
|
17
|
+
/**
|
|
18
|
+
* ITransferableDocumentStore interface functions
|
|
19
|
+
* Functions: isActive, isIssued, isRevoked, issue, name, revoke
|
|
20
|
+
*/
|
|
21
|
+
TransferableDocumentStore: ITransferableDocumentStoreFunctions
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.contractInterfaces = contractInterfaces;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var documentStore = require('@trustvc/document-store');
|
|
4
|
+
var ethersV6 = require('ethersV6');
|
|
5
|
+
var ethers$1 = require('ethers');
|
|
6
|
+
var ethers = require('../utils/ethers');
|
|
7
|
+
var utils = require('../token-registry-functions/utils');
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
const deployDocumentStore = /* @__PURE__ */ __name(async (storeName, owner, signer, options = {}) => {
|
|
12
|
+
if (!storeName) throw new Error("Store name is required");
|
|
13
|
+
if (!owner) throw new Error("Owner address is required");
|
|
14
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
15
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas } = options;
|
|
16
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
17
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
18
|
+
const DocumentStoreFactory = options.isTransferable ? documentStore.TransferableDocumentStore__factory : documentStore.DocumentStore__factory;
|
|
19
|
+
try {
|
|
20
|
+
if (isV6) {
|
|
21
|
+
const ContractFactory = new ethersV6.ContractFactory(
|
|
22
|
+
DocumentStoreFactory.abi,
|
|
23
|
+
DocumentStoreFactory.bytecode,
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
signer
|
|
26
|
+
);
|
|
27
|
+
const contract = await ContractFactory.deploy(storeName, owner, txOptions);
|
|
28
|
+
const receipt = await contract.deploymentTransaction()?.wait();
|
|
29
|
+
return receipt;
|
|
30
|
+
} else {
|
|
31
|
+
const ContractFactory = new ethers$1.ContractFactory(
|
|
32
|
+
DocumentStoreFactory.abi,
|
|
33
|
+
DocumentStoreFactory.bytecode,
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
signer
|
|
36
|
+
);
|
|
37
|
+
const contract = await ContractFactory.deploy(storeName, owner, txOptions);
|
|
38
|
+
const receipt = await contract.deployTransaction.wait();
|
|
39
|
+
return receipt;
|
|
40
|
+
}
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.error("Deployment failed:", e);
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Failed to deploy DocumentStore: ${e instanceof Error ? e.message : String(e)}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}, "deployDocumentStore");
|
|
48
|
+
|
|
49
|
+
exports.deployDocumentStore = deployDocumentStore;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ttVerify = require('@tradetrust-tt/tt-verify');
|
|
4
|
+
var utils = require('../utils');
|
|
5
|
+
var ethers = require('../utils/ethers');
|
|
6
|
+
var ttDocumentStoreAbi = require('./tt-document-store-abi');
|
|
7
|
+
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
const getRoleString = /* @__PURE__ */ __name(async (documentStoreAddress, role, options) => {
|
|
11
|
+
const { chainId } = options || {};
|
|
12
|
+
let provider = options?.provider;
|
|
13
|
+
if (!provider) {
|
|
14
|
+
if (!chainId) throw new Error("Either provider or chainId must be provided");
|
|
15
|
+
provider = ttVerify.utils.getProvider({ network: utils.SUPPORTED_CHAINS[chainId].name });
|
|
16
|
+
}
|
|
17
|
+
const Contract = ethers.getEthersContractFromProvider(provider);
|
|
18
|
+
const documentStore = new Contract(
|
|
19
|
+
documentStoreAddress,
|
|
20
|
+
ttDocumentStoreAbi.TT_DOCUMENT_STORE_ABI,
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
provider
|
|
23
|
+
);
|
|
24
|
+
switch (role) {
|
|
25
|
+
case "admin":
|
|
26
|
+
return await documentStore.DEFAULT_ADMIN_ROLE();
|
|
27
|
+
case "issuer":
|
|
28
|
+
return await documentStore.ISSUER_ROLE();
|
|
29
|
+
case "revoker":
|
|
30
|
+
return await documentStore.REVOKER_ROLE();
|
|
31
|
+
default:
|
|
32
|
+
throw new Error("Invalid role");
|
|
33
|
+
}
|
|
34
|
+
}, "getRoleString");
|
|
35
|
+
const rolesList = ["admin", "issuer", "revoker"];
|
|
36
|
+
|
|
37
|
+
exports.getRoleString = getRoleString;
|
|
38
|
+
exports.rolesList = rolesList;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('../core');
|
|
4
|
+
var supportInterfaceIds = require('./supportInterfaceIds');
|
|
5
|
+
var ttDocumentStoreAbi = require('./tt-document-store-abi');
|
|
6
|
+
var ethers = require('../utils/ethers');
|
|
7
|
+
var documentStore = require('@trustvc/document-store');
|
|
8
|
+
var utils = require('../token-registry-functions/utils');
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
const documentStoreGrantRole = /* @__PURE__ */ __name(async (documentStoreAddress, role, account, signer, options = {}) => {
|
|
13
|
+
if (!documentStoreAddress) throw new Error("Document store address is required");
|
|
14
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
15
|
+
if (!role) throw new Error("Role is required");
|
|
16
|
+
if (!account) throw new Error("Account is required");
|
|
17
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, isTransferable } = options;
|
|
18
|
+
let isDocumentStore = !isTransferable;
|
|
19
|
+
let isTransferableDocumentStore = isTransferable;
|
|
20
|
+
let isTTDocumentStore = false;
|
|
21
|
+
if (isTransferable === void 0) {
|
|
22
|
+
[isDocumentStore, isTransferableDocumentStore] = await Promise.all([
|
|
23
|
+
core.checkSupportsInterface(
|
|
24
|
+
documentStoreAddress,
|
|
25
|
+
supportInterfaceIds.supportInterfaceIds.IDocumentStore,
|
|
26
|
+
signer.provider
|
|
27
|
+
),
|
|
28
|
+
core.checkSupportsInterface(
|
|
29
|
+
documentStoreAddress,
|
|
30
|
+
supportInterfaceIds.supportInterfaceIds.ITransferableDocumentStore,
|
|
31
|
+
signer.provider
|
|
32
|
+
)
|
|
33
|
+
]);
|
|
34
|
+
if (!isDocumentStore && !isTransferableDocumentStore) {
|
|
35
|
+
isTTDocumentStore = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const Contract = ethers.getEthersContractFromProvider(signer.provider);
|
|
39
|
+
let documentStoreAbi;
|
|
40
|
+
if (isTTDocumentStore) {
|
|
41
|
+
documentStoreAbi = ttDocumentStoreAbi.TT_DOCUMENT_STORE_ABI;
|
|
42
|
+
} else {
|
|
43
|
+
const DocumentStoreFactory = isTransferableDocumentStore ? documentStore.TransferableDocumentStore__factory : documentStore.DocumentStore__factory;
|
|
44
|
+
documentStoreAbi = DocumentStoreFactory.abi;
|
|
45
|
+
}
|
|
46
|
+
const documentStoreContract = new Contract(
|
|
47
|
+
documentStoreAddress,
|
|
48
|
+
documentStoreAbi,
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
signer
|
|
51
|
+
);
|
|
52
|
+
try {
|
|
53
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
54
|
+
if (isV6) {
|
|
55
|
+
await documentStoreContract.grantRole.staticCall(role, account);
|
|
56
|
+
} else {
|
|
57
|
+
await documentStoreContract.callStatic.grantRole(role, account);
|
|
58
|
+
}
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.error("callStatic failed:", e);
|
|
61
|
+
throw new Error("Pre-check (callStatic) for grant-role failed");
|
|
62
|
+
}
|
|
63
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
64
|
+
return await documentStoreContract.grantRole(role, account, txOptions);
|
|
65
|
+
}, "documentStoreGrantRole");
|
|
66
|
+
|
|
67
|
+
exports.documentStoreGrantRole = documentStoreGrantRole;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var issue = require('./issue');
|
|
4
|
+
var revoke = require('./revoke');
|
|
5
|
+
var revokeRole = require('./revoke-role');
|
|
6
|
+
var grantRole = require('./grant-role');
|
|
7
|
+
var transferOwnership = require('./transferOwnership');
|
|
8
|
+
var deploy = require('./deploy');
|
|
9
|
+
var supportInterfaceIds = require('./supportInterfaceIds');
|
|
10
|
+
var documentStore = require('@trustvc/document-store');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Object.defineProperty(exports, "documentStoreIssue", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return issue.documentStoreIssue; }
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "documentStoreRevoke", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return revoke.documentStoreRevoke; }
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "documentStoreRevokeRole", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return revokeRole.documentStoreRevokeRole; }
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, "documentStoreGrantRole", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () { return grantRole.documentStoreGrantRole; }
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "documentStoreTransferOwnership", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return transferOwnership.documentStoreTransferOwnership; }
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "deployDocumentStore", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () { return deploy.deployDocumentStore; }
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(exports, "supportInterfaceIds", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () { return supportInterfaceIds.supportInterfaceIds; }
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "DocumentStore__factory", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () { return documentStore.DocumentStore__factory; }
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, "TransferableDocumentStore__factory", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () { return documentStore.TransferableDocumentStore__factory; }
|
|
49
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var documentStore = require('@trustvc/document-store');
|
|
4
|
+
var ethers = require('../utils/ethers');
|
|
5
|
+
var utils = require('../token-registry-functions/utils');
|
|
6
|
+
var core = require('../core');
|
|
7
|
+
var supportInterfaceIds = require('./supportInterfaceIds');
|
|
8
|
+
var ttDocumentStoreAbi = require('./tt-document-store-abi');
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
const documentStoreIssue = /* @__PURE__ */ __name(async (documentStoreAddress, documentHash, signer, options = {}) => {
|
|
13
|
+
if (!documentStoreAddress) throw new Error("Document store address is required");
|
|
14
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
15
|
+
if (!documentHash) throw new Error("Document hash is required");
|
|
16
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, isTransferable } = options;
|
|
17
|
+
let isDocumentStore = !isTransferable;
|
|
18
|
+
let isTransferableDocumentStore = isTransferable;
|
|
19
|
+
let isTTDocumentStore = false;
|
|
20
|
+
if (isTransferable === void 0) {
|
|
21
|
+
[isDocumentStore, isTransferableDocumentStore] = await Promise.all([
|
|
22
|
+
core.checkSupportsInterface(
|
|
23
|
+
documentStoreAddress,
|
|
24
|
+
supportInterfaceIds.supportInterfaceIds.IDocumentStore,
|
|
25
|
+
signer.provider
|
|
26
|
+
),
|
|
27
|
+
core.checkSupportsInterface(
|
|
28
|
+
documentStoreAddress,
|
|
29
|
+
supportInterfaceIds.supportInterfaceIds.ITransferableDocumentStore,
|
|
30
|
+
signer.provider
|
|
31
|
+
)
|
|
32
|
+
]);
|
|
33
|
+
if (!isDocumentStore && !isTransferableDocumentStore) {
|
|
34
|
+
isTTDocumentStore = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const Contract = ethers.getEthersContractFromProvider(signer.provider);
|
|
38
|
+
let documentStoreAbi;
|
|
39
|
+
if (isTTDocumentStore) {
|
|
40
|
+
documentStoreAbi = ttDocumentStoreAbi.TT_DOCUMENT_STORE_ABI;
|
|
41
|
+
} else {
|
|
42
|
+
const DocumentStoreFactory = isTransferableDocumentStore ? documentStore.TransferableDocumentStore__factory : documentStore.DocumentStore__factory;
|
|
43
|
+
documentStoreAbi = DocumentStoreFactory.abi;
|
|
44
|
+
}
|
|
45
|
+
const documentStoreContract = new Contract(
|
|
46
|
+
documentStoreAddress,
|
|
47
|
+
documentStoreAbi,
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
signer
|
|
50
|
+
);
|
|
51
|
+
try {
|
|
52
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
53
|
+
if (isV6) {
|
|
54
|
+
await documentStoreContract.issue.staticCall(documentHash);
|
|
55
|
+
} else {
|
|
56
|
+
await documentStoreContract.callStatic.issue(documentHash);
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error("callStatic failed:", e);
|
|
60
|
+
throw new Error("Pre-check (callStatic) for issue failed");
|
|
61
|
+
}
|
|
62
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
63
|
+
return await documentStoreContract.issue(documentHash, txOptions);
|
|
64
|
+
}, "documentStoreIssue");
|
|
65
|
+
|
|
66
|
+
exports.documentStoreIssue = documentStoreIssue;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('../core');
|
|
4
|
+
var supportInterfaceIds = require('./supportInterfaceIds');
|
|
5
|
+
var ttDocumentStoreAbi = require('./tt-document-store-abi');
|
|
6
|
+
var ethers = require('../utils/ethers');
|
|
7
|
+
var documentStore = require('@trustvc/document-store');
|
|
8
|
+
var utils = require('../token-registry-functions/utils');
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
const documentStoreRevokeRole = /* @__PURE__ */ __name(async (documentStoreAddress, role, account, signer, options = {}) => {
|
|
13
|
+
if (!documentStoreAddress) throw new Error("Document store address is required");
|
|
14
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
15
|
+
if (!role) throw new Error("Role is required");
|
|
16
|
+
if (!account) throw new Error("Account is required");
|
|
17
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, isTransferable } = options;
|
|
18
|
+
let isDocumentStore = !isTransferable;
|
|
19
|
+
let isTransferableDocumentStore = isTransferable;
|
|
20
|
+
let isTTDocumentStore = false;
|
|
21
|
+
if (isTransferable === void 0) {
|
|
22
|
+
[isDocumentStore, isTransferableDocumentStore] = await Promise.all([
|
|
23
|
+
core.checkSupportsInterface(
|
|
24
|
+
documentStoreAddress,
|
|
25
|
+
supportInterfaceIds.supportInterfaceIds.IDocumentStore,
|
|
26
|
+
signer.provider
|
|
27
|
+
),
|
|
28
|
+
core.checkSupportsInterface(
|
|
29
|
+
documentStoreAddress,
|
|
30
|
+
supportInterfaceIds.supportInterfaceIds.ITransferableDocumentStore,
|
|
31
|
+
signer.provider
|
|
32
|
+
)
|
|
33
|
+
]);
|
|
34
|
+
if (!isDocumentStore && !isTransferableDocumentStore) {
|
|
35
|
+
isTTDocumentStore = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const Contract = ethers.getEthersContractFromProvider(signer.provider);
|
|
39
|
+
let documentStoreAbi;
|
|
40
|
+
if (isTTDocumentStore) {
|
|
41
|
+
documentStoreAbi = ttDocumentStoreAbi.TT_DOCUMENT_STORE_ABI;
|
|
42
|
+
} else {
|
|
43
|
+
const DocumentStoreFactory = isTransferableDocumentStore ? documentStore.TransferableDocumentStore__factory : documentStore.DocumentStore__factory;
|
|
44
|
+
documentStoreAbi = DocumentStoreFactory.abi;
|
|
45
|
+
}
|
|
46
|
+
const documentStoreContract = new Contract(
|
|
47
|
+
documentStoreAddress,
|
|
48
|
+
documentStoreAbi,
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
signer
|
|
51
|
+
);
|
|
52
|
+
try {
|
|
53
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
54
|
+
if (isV6) {
|
|
55
|
+
await documentStoreContract.revokeRole.staticCall(role, account);
|
|
56
|
+
} else {
|
|
57
|
+
await documentStoreContract.callStatic.revokeRole(role, account);
|
|
58
|
+
}
|
|
59
|
+
} catch (e) {
|
|
60
|
+
console.error("callStatic failed:", e);
|
|
61
|
+
throw new Error("Pre-check (callStatic) for revoke-role failed");
|
|
62
|
+
}
|
|
63
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
64
|
+
return await documentStoreContract.revokeRole(role, account, txOptions);
|
|
65
|
+
}, "documentStoreRevokeRole");
|
|
66
|
+
|
|
67
|
+
exports.documentStoreRevokeRole = documentStoreRevokeRole;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var documentStore = require('@trustvc/document-store');
|
|
4
|
+
var ethers = require('../utils/ethers');
|
|
5
|
+
var utils = require('../token-registry-functions/utils');
|
|
6
|
+
var core = require('../core');
|
|
7
|
+
var supportInterfaceIds = require('./supportInterfaceIds');
|
|
8
|
+
var ttDocumentStoreAbi = require('./tt-document-store-abi');
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
const documentStoreRevoke = /* @__PURE__ */ __name(async (documentStoreAddress, documentHash, signer, options = {}) => {
|
|
13
|
+
if (!documentStoreAddress) throw new Error("Document store address is required");
|
|
14
|
+
if (!signer.provider) throw new Error("Provider is required");
|
|
15
|
+
if (!documentHash) throw new Error("Document hash is required");
|
|
16
|
+
const { chainId, maxFeePerGas, maxPriorityFeePerGas, isTransferable } = options;
|
|
17
|
+
let isDocumentStore = !isTransferable;
|
|
18
|
+
let isTransferableDocumentStore = isTransferable;
|
|
19
|
+
let isTTDocumentStore = false;
|
|
20
|
+
if (isTransferable === void 0) {
|
|
21
|
+
[isDocumentStore, isTransferableDocumentStore] = await Promise.all([
|
|
22
|
+
core.checkSupportsInterface(
|
|
23
|
+
documentStoreAddress,
|
|
24
|
+
supportInterfaceIds.supportInterfaceIds.IDocumentStore,
|
|
25
|
+
signer.provider
|
|
26
|
+
),
|
|
27
|
+
core.checkSupportsInterface(
|
|
28
|
+
documentStoreAddress,
|
|
29
|
+
supportInterfaceIds.supportInterfaceIds.ITransferableDocumentStore,
|
|
30
|
+
signer.provider
|
|
31
|
+
)
|
|
32
|
+
]);
|
|
33
|
+
if (!isDocumentStore && !isTransferableDocumentStore) {
|
|
34
|
+
isTTDocumentStore = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const Contract = ethers.getEthersContractFromProvider(signer.provider);
|
|
38
|
+
let documentStoreAbi;
|
|
39
|
+
if (isTTDocumentStore) {
|
|
40
|
+
documentStoreAbi = ttDocumentStoreAbi.TT_DOCUMENT_STORE_ABI;
|
|
41
|
+
} else {
|
|
42
|
+
const DocumentStoreFactory = isTransferableDocumentStore ? documentStore.TransferableDocumentStore__factory : documentStore.DocumentStore__factory;
|
|
43
|
+
documentStoreAbi = DocumentStoreFactory.abi;
|
|
44
|
+
}
|
|
45
|
+
const documentStoreContract = new Contract(
|
|
46
|
+
documentStoreAddress,
|
|
47
|
+
documentStoreAbi,
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
signer
|
|
50
|
+
);
|
|
51
|
+
try {
|
|
52
|
+
const isV6 = ethers.isV6EthersProvider(signer.provider);
|
|
53
|
+
if (isV6) {
|
|
54
|
+
await documentStoreContract.revoke.staticCall(documentHash);
|
|
55
|
+
} else {
|
|
56
|
+
await documentStoreContract.callStatic.revoke(documentHash);
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.error("callStatic failed:", e);
|
|
60
|
+
throw new Error("Pre-check (callStatic) for revoke failed");
|
|
61
|
+
}
|
|
62
|
+
const txOptions = await utils.getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
|
|
63
|
+
return await documentStoreContract.revoke(documentHash, txOptions);
|
|
64
|
+
}, "documentStoreRevoke");
|
|
65
|
+
|
|
66
|
+
exports.documentStoreRevoke = documentStoreRevoke;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tokenRegistryV5 = require('@tradetrust-tt/token-registry-v5');
|
|
4
|
+
var contractInterfaces = require('./contract-interfaces');
|
|
5
|
+
|
|
6
|
+
const { computeInterfaceId } = tokenRegistryV5.utils;
|
|
7
|
+
const supportInterfaceIds = {
|
|
8
|
+
/**
|
|
9
|
+
* IDocumentStore interface ID
|
|
10
|
+
* Functions: isActive, isIssued, isRevoked, name, revoke
|
|
11
|
+
* Computed: 0xb9391097
|
|
12
|
+
*/
|
|
13
|
+
IDocumentStore: computeInterfaceId(contractInterfaces.contractInterfaces.DocumentStore),
|
|
14
|
+
/**
|
|
15
|
+
* ITransferableDocumentStore interface ID
|
|
16
|
+
* Functions: isActive, isIssued, isRevoked, issue, name, revoke
|
|
17
|
+
* Computed: 0xc2cb4227
|
|
18
|
+
*/
|
|
19
|
+
ITransferableDocumentStore: computeInterfaceId(contractInterfaces.contractInterfaces.TransferableDocumentStore)
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.supportInterfaceIds = supportInterfaceIds;
|