# Docs helper
Docs helper allows to easily perform all the operations related to the commercio.network docs module.
# Provided operations
Creates a new transaction that allows to share the document associated with the given
metadata, documentid,recipientsand with the senderwallet. Optional fields arecontentUri,doSign,checksum,feeand the broadcastingmode.If
encryptedDatais specified, encrypts the proper data and optionalaesKeyfor the specifiedrecipientsand then sends the transaction to the blockchain. IfdoSignis provided then also thechecksumfield is required.static Future<TransactionResult> shareDocument({ required String id, required CommercioDocMetadata metadata, required List<String> recipients, required Wallet wallet, String? contentUri, CommercioDoSign? doSign, CommercioDocChecksum? checksum, Uint8List? aesKey, Set<CommercioEncryptedData>? encryptedData, StdFee? fee, BroadcastingMode? mode, http.Client? client, })1
2
3
4
5
6
7
8
9
10
11
12
13
14Example:
final txResult = await DocsHelper.shareDocument( wallet: wallet, id: Uuid().v4(), recipients: ['did:com:14ttg3eyu88jda8udvxpwjl2pwxemh72w0grsau'], metadata: CommercioDocMetadata( contentUri: 'https://example.com/document.pdf', schemaType: '-', ), );1
2
3
4
5
6
7
8
9Create a new transaction that allows to share a list of previously generated documents
commercioDocsListsigning the transaction withwallet. Optionallyfeeand broadcastingmodeparameters can be specified.static Future<List<CommercioDoc>> getSentDocuments({ required String address, required NetworkInfo networkInfo, http.Client? client, })1
2
3
4
5Example:
final commercioDoc = await CommercioDocHelper.fromWallet( wallet: wallet, id: Uuid().v4(), recipients: ['did:com:14ttg3eyu88jda8udvxpwjl2pwxemh72w0grsau'], metadata: CommercioDocMetadata( contentUri: 'https://example.com/document.pdf', schemaType: '-', ), ); final txResult = await DocsHelper.shareDocumentsList([commercioDoc], wallet);1
2
3
4
5
6
7
8
9
10
11Returns the list of all the
CommercioDocthat the specifiedaddresshas sentstatic Future<List<CommercioDoc>> getSentDocuments({ required String address, required NetworkInfo networkInfo, http.Client? client, })1
2
3
4
5Example:
final documents = await DocsHelper.getSentDocuments( address: wallet.bech32Address, networkInfo: networkInfo, );1
2
3
4Returns the list of all the
CommercioDocthat the specifiedaddresshas receivedstatic Future<List<CommercioDoc>> getReceivedDocuments({ required String address, required NetworkInfo networkInfo, http.Client? client, })1
2
3
4
5Example:
final documents = await DocsHelper.getSentDocuments({ String address, NetworkInfo networkInfo, http.Client client, });1
2
3
4
5Creates a new transaction which tells the
recipientthat the document having the specifieddocumentIdand present inside the transaction withtxHashhas been properly seen; optionallyproofof reading,feeand broadcastingmode.static Future<TransactionResult> sendDocumentReceipt({ required String recipient, required String txHash, required String documentId, required Wallet wallet, String? proof, StdFee? fee, BroadcastingMode? mode, http.Client? client, })1
2
3
4
5
6
7
8
9
10Creates a new transaction which sends a list of previously generated receipts
commercioDocReceiptsList. Optionallyfeeand broadcastingmodeparameters can be specified.static Future<TransactionResult> sendDocumentReceiptsList( List<CommercioDocReceipt> commercioDocReceiptsList, Wallet wallet, { StdFee? fee, BroadcastingMode? mode, http.Client? client, })1
2
3
4
5
6
7Returns the list of all the
CommercioDocReceiptthat have been sent from the givenaddressstatic Future<List<CommercioDocReceipt>> getSentReceipts({ required String address, required NetworkInfo networkInfo, http.Client? client, })1
2
3
4
5Returns the list of all the
CommercioDocRecepitthat have been received from the givenaddressstatic Future<List<CommercioDocReceipt>> getReceivedReceipts({ required String address, required NetworkInfo networkInfo, http.Client? client, })1
2
3
4
5
# Usage examples
final info = NetworkInfo(
bech32Hrp: 'did:com:',
lcdUrl: Uri.parse('http://localhost:1317'),
);
final senderMnemonic = ['will', 'hard', ..., 'man'];
final senderWallet = Wallet.derive(senderMnemonic, info);
final recipientMnemonic = ['crisp', 'become', ..., 'cereal'];
final recipientWallet = Wallet.derive(recipientMnemonic, info);
final recipientDid = recipientWallet.bech32Address;
final docId = Uuid().v4();
final checksum = CommercioDocChecksum(
value: "a00ab326fc8a3dd93ec84f7e7773ac2499b381c4833e53110107f21c3b90509c",
algorithm: CommercioDocChecksumAlgorithm.SHA256,
);
final doSign = CommercioDoSign(
storageUri: "http://www.commercio.network",
signerIstance: "did:com:1cc65t29yuwuc32ep2h9uqhnwrregfq230lf2rj",
sdnData: {
CommercioSdnData.COMMON_NAME,
CommercioSdnData.SURNAME,
},
vcrId: "xxxxx",
certificateProfile: "xxxxx",
);
try {
// --- Share a document
final response = await DocsHelper.shareDocument(
id: docId,
contentUri: 'https://example.com/document',
metadata: CommercioDocMetadata(
contentUri: 'https://example.com/document/metadata',
schema: CommercioDocMetadataSchema(
uri: 'https://example.com/custom/metadata/schema',
version: '1.0.0',
),
),
recipients: [recipientDid],
wallet: senderWallet,
checksum: checksum,
encryptedData: const {CommercioEncryptedData.CONTENT_URI},
doSign: doSign,
fee: const StdFee(
gas: '200000',
amount: [StdCoin(denom: 'ucommercio', amount: '10000')],
),
);
// --- Send receipt
final senderDid = senderWallet.bech32Address;
await DocsHelper.sendDocumentReceipt(
recipient: senderDid,
txHash: response.hash,
documentId: docId,
wallet: recipientWallet,
);
} catch (error) {
// Handle error
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63