Skip to content

Commit

Permalink
chore: skip delegation range check. refactor UpdateCallRejectedError …
Browse files Browse the repository at this point in the history
…throw
  • Loading branch information
Jason I committed Oct 18, 2024
1 parent edf0e51 commit db92356
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
29 changes: 14 additions & 15 deletions packages/agent/src/actor.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { Buffer } from 'buffer/';
import { Buffer } from "buffer/";
import {
Agent,
getDefaultAgent,
HttpDetailsResponse,
QueryResponseRejected,
QueryResponseStatus,
ReplicaRejectCode,
SubmitResponse, v2ResponseBody,
SubmitResponse,
v2ResponseBody,
v3ResponseBody,
} from "./agent";
import { AgentError } from './errors';
import { bufFromBufLike, IDL } from '@dfinity/candid';
import { pollForResponse, PollStrategyFactory, strategy } from './polling';
import { Principal } from '@dfinity/principal';
import { RequestId } from './request_id';
import { toHex } from './utils/buffer';
import { Certificate, CreateCertificateOptions, lookupResultToBuffer } from './certificate';
import managementCanisterIdl from './canisters/management_idl';
import _SERVICE, { canister_install_mode, canister_settings } from './canisters/management_service';
import { AgentError } from "./errors";
import { bufFromBufLike, IDL } from "@dfinity/candid";
import { pollForResponse, PollStrategyFactory, strategy } from "./polling";
import { Principal } from "@dfinity/principal";
import { RequestId } from "./request_id";
import { toHex } from "./utils/buffer";
import { Certificate, CreateCertificateOptions, lookupResultToBuffer } from "./certificate";
import managementCanisterIdl from "./canisters/management_idl";
import _SERVICE, { canister_install_mode, canister_settings } from "./canisters/management_service";

export class ActorCallError extends AgentError {
constructor(
Expand Down Expand Up @@ -581,10 +582,8 @@ function _createActorMethod(
);
}
}
}

// handle v2 response errors by throwing an UpdateCallRejectedError object
if (!response.ok || response.body /* IC-1462 */) {
} else if (!response.ok || response.body /* IC-1462 */) {
// handle v2 response errors by throwing an UpdateCallRejectedError object
const { reject_code, reject_message, error_code } = response.body as v2ResponseBody;
throw new UpdateCallRejectedError(cid,
methodName,
Expand Down
38 changes: 20 additions & 18 deletions packages/agent/src/certificate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as cbor from './cbor';
import { AgentError } from './errors';
import { hash } from './request_id';
import { bufEquals, concat, fromHex, toHex } from './utils/buffer';
import { Principal } from '@dfinity/principal';
import * as bls from './utils/bls';
import { decodeTime } from './utils/leb';
import * as cbor from "./cbor";
import { AgentError } from "./errors";
import { hash } from "./request_id";
import { bufEquals, concat, fromHex, toHex } from "./utils/buffer";
import { Principal } from "@dfinity/principal";
import * as bls from "./utils/bls";
import { decodeTime } from "./utils/leb";
import { MANAGEMENT_CANISTER_ID } from "./agent";

/**
Expand Down Expand Up @@ -272,17 +272,19 @@ export class Certificate {

await cert.verify();

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,
)}`,
);
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 publicKeyLookup = lookupResultToBuffer(
cert.lookup(['subnet', d.subnet_id, 'public_key']),
Expand Down

0 comments on commit db92356

Please sign in to comment.