buildProof method
FutureOr<Map<String, dynamic> >
buildProof(
- dynamic data,
- WalletStore wallet,
- String did, {
- String? challenge,
- String? domain,
- String? proofPurpose,
override
Build a LinkedDataProof / DataIntegrityProof
Implementation
@override
FutureOr<Map<String, dynamic>> buildProof(
data, WalletStore wallet, String did,
{String? challenge, String? domain, String? proofPurpose}) async {
var proofOptions = {
'@context': ed25519ContextIri,
'type': typeName,
'proofPurpose': proofPurpose ?? 'assertionMethod',
'verificationMethod': '$did#${did.split(':')[2]}',
'created': DateTime.now().toUtc().toIso8601String()
};
if (domain != null) {
proofOptions['domain'] = domain;
}
if (challenge != null) {
proofOptions['challenge'] = challenge;
}
String pOptions = await JsonLdProcessor.normalize(proofOptions,
options: JsonLdOptions(safeMode: true, documentLoader: loadDocument));
//proofOptions.remove('@context');
List<int> hashToSign = await _dataToHash(data);
var pOptionsHash = sha256.convert(utf8.encode(pOptions)).bytes;
var hash = pOptionsHash + hashToSign;
//print(hash);
var privateKey = await wallet.getPrivateKeyForCredentialDid(did);
privateKey ??= await wallet.getPrivateKeyForConnectionDid(did);
if (privateKey == null) throw Exception('Could not find a private key');
var signature = ed.sign(
ed.PrivateKey(web3_crypto.hexToBytes(privateKey).toList()),
Uint8List.fromList(hash));
proofOptions['proofValue'] = 'z${base58BitcoinEncode(signature)}';
return proofOptions;
}