# 4.2 shareDoc(1->1. 1->n, plain/encrypted)

# Use cases

Creates a new transaction that allows to share the document associated with the given contentUri and having the given metadata and checksum. If encryptedData is specified, encrypts the proper data for the specified recipients and then sends the transaction to the blockchain.

# Tools

The Sacco library, our own open source tool to sign and send transactions to any Cosmos SDK based blockchain, including Commercio.network.

The Commercio SDK, our own open source tool to format transactions to Commercio.network

# Functions and APIs

  • Wallet derive;
  • DocsHelper shareDocument.

# Background

From Wikipedia:

A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems.

# Step by step sequence

  1. Setup NetworkInfo;
  2. Derive the wallet from the menemonic using the wallet derive function;
  3. Get a random document Id;
  4. Setup the metadata;
  5. Setup the recipient dids;
  6. Add optional parameters such as checksum, doSign, aesKey, encryptedData, fee, contentUri and mode;
  7. Finally, execute the DocsHelper shareDocument function.

# Code Examples

Here's an example of the implemetation in all the available languages.

# Dart

final networkInfo = NetworkInfo(
  bech32Hrp: 'did:com:',
  lcdUrl: 'http://localhost:1317',
);

final mnemonic = ['curve', 'attend', ..., 'mail',];
final wallet = Wallet.derive(mnemonic, networkInfo);

final docId = Uuid().v4();
final recipients = ["did:com:1z6ezqssnqqc6un3henna0flr05aukcwcr5ge6t"];

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",
);

final fee = StdFee(
  gas: "200000",
  amount: [
    StdCoin(denom: "ucommercio", amount: "10000")
  ],
);

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: '7.0.0',
    ),
  ),
  recipients: recipients,
  wallet: wallet,
  checksum: checksum,
  encryptedData: [EncryptedData.CONTENT_URI],
  doSign: doSign,
  fee: fee,
);
1
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

# Kotlin

val networkInfo = NetworkInfo(
  bech32Hrp = "did:com:",
  lcdUrl = "http://localhost:1317"
)

val mnemonic = listOf("curve", "attend", ..., "mail")
val wallet = Wallet.derive(mnemonic = mnemonic, networkInfo = networkInfo)

val recipientMnemonic = listOf("push", "grace", ..., "second")
val recipientWallet = Wallet.derive(recipientMnemonic, networkInfo)

val docId = UUID.randomUUID().toString()
val docRecipientDid = Did(recipientWallet.bech32Address)

var checksum = CommercioDoc.Checksum(
  value = "bd29066606c7496d3e0bae11b1c7a3557ed0881535673e81c9a3ed4f",
  algorithm = CommercioDoc.Checksum.Algorithm.SHA224
)  // optional

val doSign = CommercioDoc.CommercioDoSign(
  storageUri = "http://www.commercio.network",
  signerIstance = "did:com:1cc65t29yuwuc32ep2h9uqhnwrregfq230lf2rj",
  sdnData = listOf(
    CommercioDoc.CommercioDoSign.CommercioSdnData.COMMON_NAME,
    CommercioDoc.CommercioDoSign.CommercioSdnData.SURNAME
  ),
  vcrId = "xxxxx",
  certificateProfile = "xxxxx"
) // optional

val mode = TxHelper.BroadcastingMode.BLOCK // optional
val fee = StdFee(gas = "200000", amount = listOf(StdCoin(denom = "ucommercio", amount = "10000"))) // optional

val response = DocsHelper.shareDocument(
  id = docId,
  recipients = listOf(docRecipientDid),
  wallet = senderWallet,
  metadata = CommercioDoc.Metadata(
    contentUri = "https://example.com/document/metadata",
    schema = CommercioDoc.Metadata.Schema(
      uri = "https://example.com/custom/metadata/schema",
      version = "1.0.0"
    )
  ),
  fee = fee, // optional
  mode = mode, // optional
  contentUri = "https://example.com/document", // optional
  checksum = checksum, // optional
  doSign = doSign, // optional
  encryptedData = listOf(EncryptedData.METADATA_CONTENT_URI) // optional
)
1
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

# C#

static commercio.sacco.lib.NetworkInfo networkInfo = new commercio.sacco.lib.NetworkInfo(
                bech32Hrp: "did:com:",
                lcdUrl: "http://localhost:1317"
              );

String senderMnemonicString = "curve attend elephant garage tide neither enforce auction dumb brief divert creek palm equip festival spice race message domain seed ship hunt mercy mail";
List<String> senderMnemonic = new List<String>(senderMnemonicString.Split(" ", StringSplitOptions.RemoveEmptyEntries));

var senderWallet = commercio.sacco.lib.Wallet.derive(senderMnemonic, networkInfo);

String recipientMnemonicString = "push grace power desk arrive horror gallery physical kingdom ecology fat firm future service table little live reason maximum short motion planet stage second";
List<String> recipientMnemonic = new List<String>(recipientMnemonicString.Split(" ", StringSplitOptions.RemoveEmptyEntries));

var recipientWallet = commercio.sacco.lib.Wallet.derive(recipientMnemonic, networkInfo);

var docRecipientDid = new List<string>();
docRecipientDid.Add(recipientWallet.bech32Address);
var docId = System.Guid.NewGuid().ToString();

var fees = new List<commercio.sacco.lib.StdCoin>();
fees.Add(new commercio.sacco.lib.StdCoin(denom: "ucommercio", amount: "10000"));

var res = commercio.sdk.DocsHelper.shareDocument(
 id: docId,
 contentUri: "https://example.com/document",
 metadata: new commercio.sdk.CommercioDocMetadata(
   contentUri: "https://example.com/document/metadata",
   schema: new commercio.sdk.CommercioDocMetadataSchema(
     uri: "https://example.com/custom/metadata/schema",
     version: "1.2.3"
   ),
   schemaType: ""
 ),
 recipients: docRecipientDid,
 fees: fees,
 wallet: senderWallet,
 aesKey: null,
 checksum: null,
 encryptedData: null
);
1
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