getPublicKey function
Retrieves the public key associated with the given peer ID from the value store.
If the ValueStore is also a PubKeyFetcher, this method will call getPublicKey (which may be better optimized) instead of getValue.
Implementation
Future<dynamic> getPublicKey(ValueStore store, PeerId id) async {
// First try to extract the public key from the peer ID if possible
try {
final key = await id.extractPublicKey();
if (key != null) {
return key;
}
} catch (e) {
// If extraction fails, continue to fetch from the store
}
// If the store is a PubKeyFetcher, use the optimized method
if (store is PubKeyFetcher) {
PubKeyFetcher pkFetcher = store as PubKeyFetcher;
return await pkFetcher.getPublicKey(id);
}
// Otherwise, use the regular getValue method
final key = keyForPublicKey(id);
final pkval = await store.getValue(key, null);
// Unmarshal the public key (implementation would depend on the key format)
// This is a placeholder for the actual implementation
return pkval;
}