mergeSdJwt function
Implementation
Map<String, dynamic> mergeSdJwt(String sdJwt) {
Map<String, dynamic> merged = {};
var split = sdJwt.split('.');
if (split.length != 3) {
throw Exception('JWT consists of 3 parts');
}
var sig = split.last;
var disclosures = sig.split('~');
disclosures.removeAt(0);
Map<String, Disclosure> disclosureMap = {};
Map<String, dynamic> payload = jsonDecode(split[1]);
var hashAlg = payload['_sd_hash_alg'];
if (hashAlg != 'sha-256') {
throw UnimplementedError('Only sha-256 hashing is supported');
}
for (var d in disclosures) {
var hash = sha256.convert(ascii.encode(d));
disclosureMap[base64UrlEncode(hash.bytes)] = Disclosure.fromBase64(d);
}
return merged;
}