fromWallet static method

Future<CommercioDoc> fromWallet({
  1. required Wallet wallet,
  2. required List<String> recipients,
  3. required String id,
  4. required CommercioDocMetadata metadata,
  5. String? contentUri,
  6. CommercioDocChecksum? checksum,
  7. CommercioDoSign? doSign,
  8. Set<CommercioEncryptedData>? encryptedData,
  9. Uint8List? aesKey,
  10. Client? client,
})

Creates a CommercioDoc from the given wallet, recipients, id, metadata and optionally contentUri, checksum, doSign, encryptedData, aesKey.

Implementation

static Future<CommercioDoc> fromWallet({
  required Wallet wallet,
  required List<String> recipients,
  required String id,
  required CommercioDocMetadata metadata,
  String? contentUri,
  CommercioDocChecksum? checksum,
  CommercioDoSign? doSign,
  Set<CommercioEncryptedData>? encryptedData,
  Uint8List? aesKey,
  http.Client? client,
}) async {
  // Build a commercio document
  var commercioDocument = CommercioDoc(
    senderDid: wallet.bech32Address,
    recipientDids: recipients,
    uuid: id,
    contentUri: contentUri,
    metadata: metadata,
    checksum: checksum,
    doSign: doSign,
  );

  // Encrypt its contents, if necessary
  if (encryptedData != null && encryptedData.isNotEmpty) {
    // Get a default aes key for encryption if needed
    final key = aesKey ?? await KeysHelper.generateAesKey();

    commercioDocument = await encryptField(
      commercioDocument,
      key,
      encryptedData,
      recipients,
      wallet,
      client: client,
    );
  }

  return commercioDocument;
}