buildProof method
Future<Map<String, dynamic> >
buildProof(
- dynamic data,
- WalletStore wallet,
- String did, {
- String? challenge,
- String? domain,
- String? proofPurpose,
override
Build a LinkedDataProof / DataIntegrityProof
Implementation
@override
Future<Map<String, dynamic>> buildProof(data, WalletStore wallet, String did,
{String? challenge, String? domain, String? proofPurpose}) async {
var proofOptions = {
'@context': ecdsaRecoveryContextIri,
'type': typeName,
'proofPurpose': proofPurpose ?? 'assertionMethod',
'verificationMethod': '$did#controller',
'created': DateTime.now().toUtc().toIso8601String()
};
if (domain != null) {
proofOptions['domain'] = domain;
}
if (challenge != null) {
proofOptions['challenge'] = challenge;
}
List<int> hash = await _dataToHash(data);
var pOptionsHash = sha256
.convert(utf8.encode(await JsonLdProcessor.normalize(proofOptions,
options:
JsonLdOptions(safeMode: true, documentLoader: loadDocument))))
.bytes;
var payload = pOptionsHash + hash;
var critical = <String, dynamic>{};
critical['b64'] = false;
var header = buildJwsHeader(alg: 'ES256K-R', extra: critical);
var headerEnc = removePaddingFromBase64(header);
var hashToSign = sha256.convert(utf8.encode('$headerEnc.') + payload).bytes;
//proofOptions.remove('@context');
var privateKeyHex = await wallet.getPrivateKeyForCredentialDid(did);
privateKeyHex ??= await wallet.getPrivateKeyForConnectionDid(did);
if (privateKeyHex == null) throw Exception('Could not find a private key');
var key = EthPrivateKey.fromHex(privateKeyHex);
var sigArray = _buildSignatureArray(Uint8List.fromList(hashToSign), key);
while (sigArray.length != 65) {
sigArray = _buildSignatureArray(Uint8List.fromList(hashToSign), key);
}
proofOptions['jws'] = '$headerEnc.'
'.${base64UrlEncode(sigArray)}';
return proofOptions;
}