From db92356b29e339e1b9411b140368aeeb91502d98 Mon Sep 17 00:00:00 2001 From: Jason I Date: Fri, 18 Oct 2024 11:50:26 -0700 Subject: [PATCH] chore: skip delegation range check. refactor UpdateCallRejectedError throw --- packages/agent/src/actor.ts | 29 ++++++++++++----------- packages/agent/src/certificate.ts | 38 ++++++++++++++++--------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/packages/agent/src/actor.ts b/packages/agent/src/actor.ts index cc588e41..8ea0f2b8 100644 --- a/packages/agent/src/actor.ts +++ b/packages/agent/src/actor.ts @@ -1,4 +1,4 @@ -import { Buffer } from 'buffer/'; +import { Buffer } from "buffer/"; import { Agent, getDefaultAgent, @@ -6,18 +6,19 @@ import { 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( @@ -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, diff --git a/packages/agent/src/certificate.ts b/packages/agent/src/certificate.ts index 1f537478..d20cb925 100644 --- a/packages/agent/src/certificate.ts +++ b/packages/agent/src/certificate.ts @@ -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"; /** @@ -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']),