Skip to content

Latest commit

 

History

History
142 lines (107 loc) · 3.74 KB

File metadata and controls

142 lines (107 loc) · 3.74 KB

4.3 sendReceipt(1->1)

Use cases

Creates a new transaction which tells the recipient that the document having the specified documentId and present inside the transaction with hash txHash has been properly seen.

Optionally send proof of reading.

Tools

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

Functions and APIs

  • DocsHelper sendDocumentReceipt.

Background

From Wikipedia:

A hash function is any function that can be used to map data of arbitrary size to fixed-size values. The values returned by a hash function are called hash values, hash codes, digests, or simply hashes.

Step by step sequence

  1. Share a document (Chapter 4.2);
  2. Save the transaction hash;
  3. Finally, execute the DocsHelper sendDocumentReceipt to send the receipt.

Code Examples

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

Dart

final wallet = Wallet.derive(mnemonic, networkInfo);
final recipientWallet = Wallet.derive(recipientMnemonic, networkInfo);
final docId = Uuid().v4();

final response = await DocsHelper.shareDocument(
  id: docId,
  ...,
  recipients: [recipientWallet.bech32Address],
  wallet: wallet,
  ...,
);

final hash = response.hash;

await DocsHelper.sendDocumentReceipt(
  recipient: wallet.bech32Address,
  txHash: hash,
  documentId: docId,
  wallet: recipientWallet,
);

Kotlin

val wallet = Wallet.derive(mnemonic = mnemonic, networkInfo = info)
val recipientWallet = Wallet.derive(recipientMnemonic, info)

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

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

val response = DocsHelper.shareDocument(
  id = docId,
  metadata = CommercioDoc.Metadata(
    contentUri = "https://example.com/document/metadata",
    schema = CommercioDoc.Metadata.Schema(
      uri = "https://example.com/custom/metadata/schema",
      version = "1.0.0"
    )
  ),
  recipients = listOf(docRecipientDid),
  wallet = wallet,
  contentUri = "https://example.com/document"  // optional
)

if (response is TxResponse.Successful) {

  val txHash = response.txHash
  val receiptRecipientDid = Did(wallet.bech32Address)

  DocsHelper.sendDocumentReceipt(
    recipient = receiptRecipientDid,
    txHash = txHash,
    documentId = docId,
    wallet = recipientWallet,
    fee = fee, // optional
    mode = mode // optional
  )
}

C#

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

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

var txHash = res.GetHashCode().ToString();

var receiptRecipientDid = senderWallet.bech32Address;

var response = commercio.sdk.DocsHelper.sendDocumentReceipt(
 recipient: receiptRecipientDid,
 txHash: txHash,
 documentId: docId,
 wallet: recipientWallet
);