getKeyAgreementKeyForDid method

Future<String?> getKeyAgreementKeyForDid(
  1. String did
)

Implementation

Future<String?> getKeyAgreementKeyForDid(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 getPrivateKeyForConnectionDid(did);
  } else if (did.startsWith('did:key:z6Mk')) {
    var cred = getCredential(did);
    if (cred != null) {
      var key = await ED25519_HD_KEY.derivePath(
          cred.hdPath, _keyBox!.get('seed').toList());
      return bytesToHex(_edPrivateToXPrivate(
          ed.newKeyFromSeed(Uint8List.fromList(key.key))));
    } else {
      var con = getConnection(did);
      if (con != null) {
        var key = await ED25519_HD_KEY.derivePath(
            con.hdPath, _keyBox!.get('seed').toList());
        return bytesToHex(_edPrivateToXPrivate(
            ed.newKeyFromSeed(Uint8List.fromList(key.key))));
      } else {
        throw Exception('Could not find a key for did `$did`');
      }
    }
  } else {
    throw Exception('unsupported did');
  }
}