getKeyAgreementKeyForDidAsJwk method

Future<Map<String, dynamic>?> getKeyAgreementKeyForDidAsJwk(
  1. String did
)

Implementation

Future<Map<String, dynamic>?> getKeyAgreementKeyForDidAsJwk(
    String did) async {
  if (did.startsWith('did:ethr')) {
    throw Exception('Could not resolve an agreement key for did:ethr');
  } else if (did.startsWith('did:key:z6LS')) {
    return getPrivateKeyForConnectionDidAsJwk(did);
  } else if (did.startsWith('did:key:z6Mk')) {
    var private = await getKeyAgreementKeyForDid(did);
    if (private != null) {
      Map<String, dynamic> key = {};
      key['kid'] =
          '$did#z${ed25519PublicToX25519Public(base58Bitcoin.decode(did.split(':').last.substring(1)).sublist(2))}';
      key['kty'] = 'OKP';
      key['crv'] = 'X25519';
      key['d'] = removePaddingFromBase64(
          base64UrlEncode(hexToBytes(private).sublist(0, 32)));
      return key;
    }
  } else {
    //throw Exception('unsupported did');
    return null;
  }
  return null;
}