fromWallet static method

Future<DidDocument> fromWallet({
  1. required Wallet wallet,
  2. required List<CommercioPublicKey> pubKeys,
  3. List<DidDocumentService>? service,
})

Creates a Did Document from the given wallet, pubKeys and optional service.

Implementation

static Future<DidDocument> fromWallet({
  required Wallet wallet,
  required List<CommercioPublicKey> pubKeys,
  List<DidDocumentService>? service,
}) async {
  if (pubKeys.length < 2) {
    throw ArgumentError('At least two keys are required');
  }

  final keys = <DidDocumentPublicKey>[];
  for (var i = 0; i < pubKeys.length; i++) {
    final convertedKey = await _convertKey(pubKeys[i], i + 1, wallet);
    keys.add(convertedKey);
  }

  final proofContent = DidDocumentProofSignatureContent(
    context: 'https://www.w3.org/ns/did/v1',
    id: wallet.bech32Address,
    publicKeys: keys,
    service: service,
  );

  final verificationMethod = wallet.bech32PublicKey;

  final proof = _computeProof(
    controller: proofContent.id,
    verificationMethod: verificationMethod,
    proofSignatureContent: proofContent,
    wallet: wallet,
  );

  return DidDocument(
    context: proofContent.context,
    id: proofContent.id,
    publicKeys: proofContent.publicKeys,
    proof: proof,
    service: service,
  );
}