// Alternate constructor from Json JObject public CommercioDoc(JObject json) { this.uuid = (String)json["uuid"]; this.senderDid = (String)json["sender"]; this.recipientDids = ((JArray)json["recipients"]).Select(elem => (elem.ToString())).ToList(); this.contentUri = (String)json["content_uri"]; this.metadata = new CommercioDocMetadata(json["metadata"] as JObject); this.checksum = new CommercioDocChecksum(json["checksum"] as JObject); this.encryptionData = new CommercioDocEncryptionData(json["encryption_data"] as JObject); this.doSign = new CommercioDoSign(json["do_sign"] as JObject); //Object outValue; //if (json.TryGetValue("sender", out outValue)) // this.senderDid = outValue as String; //if (json.TryGetValue("recipients", out outValue)) // this.recipientDids = outValue as List<String>; //if (json.TryGetValue("uuid", out outValue)) // this.uuid = outValue as String; //if (json.TryGetValue("content_uri", out outValue)) // this.contentUri = outValue as String; //if (json.TryGetValue("metadata", out outValue)) // this.metadata = outValue as CommercioDocMetadata; //if (json.TryGetValue("checksum", out outValue)) // this.checksum = outValue as CommercioDocChecksum; //if (json.TryGetValue("encryption_data", out outValue)) // this.encryptionData = outValue as CommercioDocEncryptionData; //if (json.TryGetValue("do_sign", out outValue)) // this.doSign = outValue as CommercioDoSign; }
public CommercioDoc(String senderDid, List <String> recipientDids, String uuid, CommercioDocMetadata metadata, String contentUri = null, CommercioDocChecksum checksum = null, CommercioDocEncryptionData encryptionData = null, CommercioDoSign doSign = null) { Trace.Assert(senderDid != null); Trace.Assert(recipientDids != null); Trace.Assert(recipientDids.Count > 0); Trace.Assert(uuid != null); Trace.Assert(metadata != null); // Trace.Assert(contentUri != null); Removed - conflict with opt param //Check if contenturi is valorize 15/07/2021 Luigi Arena test se contenturi รจ valorizzato if (!string.IsNullOrEmpty(contentUri)) { Trace.Assert(contentUri.Length <= 512, "metadata.content_uri must have a valid length"); } this.uuid = uuid; this.senderDid = senderDid; this.recipientDids = recipientDids; this.contentUri = contentUri; this.metadata = metadata; this.checksum = checksum; this.encryptionData = encryptionData; this.doSign = doSign; }
/// Creates a CommercioDoc from the given [wallet], /// [recipients], [id], [metadata] /// and optionally [contentUri], [checksum], /// [doSign], [encryptedData], [aesKey]. public static async Task <CommercioDoc> fromWallet( Wallet wallet, List <String> recipients, String id, CommercioDocMetadata metadata, String contentUri = null, CommercioDocChecksum checksum = null, CommercioDoSign doSign = null, List <EncryptedData> encryptedData = null, KeyParameter aesKey = null ) { // Build a generic document CommercioDoc commercioDocument = new CommercioDoc( senderDid: wallet.bech32Address, recipientDids: recipients, uuid: id, contentUri: contentUri, metadata: metadata, checksum: checksum, encryptionData: null, doSign: doSign ); // Encrypt its contents, if necessary if ((encryptedData != null) && (encryptedData.Count > 0)) { // Get a default aes key for encryption if needed if (aesKey == null) { aesKey = KeysHelper.generateAesKey(); } // Encrypt its contents, if necessary commercioDocument = await DocsUtils.encryptField( commercioDocument, aesKey, encryptedData, recipients, wallet ); } return(commercioDocument); }
// This doesn't seem to be used, although it is there in Dart code... I will keep it as a placeholder // Use static HttpClient to avoid exhausting system resources for network connections. // private static HttpClient client = new HttpClient(); #endregion #region Properties #endregion #region Constructors #endregion #region Public Methods /// 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. public static async Task <TransactionResult> shareDocument( String id, CommercioDocMetadata metadata, List <String> recipients, Wallet wallet, CommercioDoSign doSign = null, CommercioDocChecksum checksum = null, KeyParameter aesKey = null, List <EncryptedData> encryptedData = null, StdFee fee = null, String contentUri = null, BroadcastingMode mode = BroadcastingMode.SYNC ) { // Build a generic document CommercioDoc commercioDoc = await CommercioDocHelper.fromWallet( wallet : wallet, recipients : recipients, id : id, metadata : metadata, checksum : checksum, contentUri : contentUri, doSign : doSign, encryptedData : encryptedData, aesKey : aesKey ); // Build the tx message MsgShareDocument msg = new MsgShareDocument(document: commercioDoc); // Careful here, Eugene: we are passing a list of BaseType containing the derived MsgSetDidDocument msg return(await TxHelper.createSignAndSendTx(new List <StdMsg> { msg }, wallet, fee : fee, mode : mode)); }
public CommercioDoc(String senderDid, List<String> recipientDids, String uuid, CommercioDocMetadata metadata, String contentUri = null, CommercioDocChecksum checksum = null, CommercioDocEncryptionData encryptionData = null, CommercioDoSign doSign = null) { Trace.Assert(senderDid != null); Trace.Assert(recipientDids != null); Trace.Assert(recipientDids.Count > 0); Trace.Assert(uuid != null); Trace.Assert(metadata != null); // Trace.Assert(contentUri != null); Removed - conflict with opt param this.uuid = uuid; this.senderDid = senderDid; this.recipientDids = recipientDids; this.contentUri = contentUri; this.metadata = metadata; this.checksum = checksum; this.encryptionData = encryptionData; this.doSign = doSign; }