Skip to content

Commit

Permalink
fetchSubnetKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
krpeacock committed Nov 16, 2023
1 parent 08b3c48 commit af22411
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/agent/src/agent/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,23 @@ export class HttpAgent implements Agent {
} catch (error) {
// In case the node signatures have changed, refresh the subnet keys and try again
console.warn('Query response verification failed. Retrying with fresh subnet keys.');
const nodeId = Principal.from(query.signatures?.[0].identity);
this.#subnetKeys.delete(canisterId.toString());
await this.fetchSubnetKeys(nodeId);
await this.fetchSubnetKeys(canisterId.toString());
}
const updatedSubnetStatus = this.#subnetKeys.get(canisterId.toString());
return this.#verifyQueryResponse(query, updatedSubnetStatus);
if (!updatedSubnetStatus) {
throw new CertificateVerificationError(
'Invalid signature from replica signed query: no matching node key found.',
);
}
const isValid = this.#verifyQueryResponse(query, updatedSubnetStatus);
if (isValid) {
return query;
} else {
throw new CertificateVerificationError(
'Invalid signature from replica signed query: no matching node key found.',
);
}
}

/**
Expand Down

0 comments on commit af22411

Please sign in to comment.