Skip to content

Commit

Permalink
chore: revert certificate.ts. throw UpdateCallRejectedError for v2 re…
Browse files Browse the repository at this point in the history
…ject messages
  • Loading branch information
Jason I committed Oct 18, 2024
1 parent 613da0f commit edf0e51
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
17 changes: 15 additions & 2 deletions packages/agent/src/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
QueryResponseRejected,
QueryResponseStatus,
ReplicaRejectCode,
SubmitResponse,
SubmitResponse, v2ResponseBody,
v3ResponseBody,
} from './agent';
} from "./agent";
import { AgentError } from './errors';
import { bufFromBufLike, IDL } from '@dfinity/candid';
import { pollForResponse, PollStrategyFactory, strategy } from './polling';
Expand Down Expand Up @@ -582,6 +582,19 @@ function _createActorMethod(
}
}
}

// handle v2 response errors by throwing an UpdateCallRejectedError object
if (!response.ok || response.body /* IC-1462 */) {
const { reject_code, reject_message, error_code } = response.body as v2ResponseBody;
throw new UpdateCallRejectedError(cid,
methodName,
requestId,
response,
reject_code,
reject_message,
error_code)
}

// Fall back to polling if we receive an Accepted response code
if (response.status === 202) {
const pollStrategy = pollingStrategyFactory();
Expand Down
24 changes: 11 additions & 13 deletions packages/agent/src/certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,17 @@ export class Certificate {

await cert.verify();

if (this._canisterId.toString() !== MANAGEMENT_CANISTER_ID) {
const canisterInRange = check_canister_ranges({
canisterId: this._canisterId,
subnetId: Principal.fromUint8Array(new Uint8Array(d.subnet_id)),
tree: cert.cert.tree,
});
if (!canisterInRange) {
throw new CertificateVerificationError(
`Canister ${this._canisterId} not in range of delegations for subnet 0x${toHex(
d.subnet_id,
)}`,
);
}
const canisterInRange = check_canister_ranges({
canisterId: this._canisterId,
subnetId: Principal.fromUint8Array(new Uint8Array(d.subnet_id)),
tree: cert.cert.tree,
});
if (!canisterInRange) {
throw new CertificateVerificationError(
`Canister ${this._canisterId} not in range of delegations for subnet 0x${toHex(
d.subnet_id,
)}`,
);
}
const publicKeyLookup = lookupResultToBuffer(
cert.lookup(['subnet', d.subnet_id, 'public_key']),
Expand Down

0 comments on commit edf0e51

Please sign in to comment.