@icp-sdk/core 6.0.0 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/agent/agent/api.d.ts +52 -4
- package/lib/cjs/agent/agent/api.d.ts.map +1 -1
- package/lib/cjs/agent/agent/api.js +6 -1
- package/lib/cjs/agent/agent/api.js.map +1 -1
- package/lib/cjs/agent/agent/http/index.d.ts +2 -2
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/index.js +109 -35
- package/lib/cjs/agent/agent/http/index.js.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.d.ts +2 -3
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.js +63 -120
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
- package/lib/cjs/agent/certificate.d.ts +1 -1
- package/lib/cjs/agent/certificate.d.ts.map +1 -1
- package/lib/cjs/agent/certificate.js.map +1 -1
- package/lib/cjs/agent/errors.d.ts +13 -0
- package/lib/cjs/agent/errors.d.ts.map +1 -1
- package/lib/cjs/agent/errors.js +26 -1
- package/lib/cjs/agent/errors.js.map +1 -1
- package/lib/cjs/agent/polling/index.d.ts +4 -3
- package/lib/cjs/agent/polling/index.d.ts.map +1 -1
- package/lib/cjs/agent/polling/index.js +5 -13
- package/lib/cjs/agent/polling/index.js.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.d.ts +3 -2
- package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.js +59 -82
- package/lib/cjs/agent/subnetStatus/index.js.map +1 -1
- package/lib/cjs/agent/utils/readState.d.ts +102 -13
- package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
- package/lib/cjs/agent/utils/readState.js +104 -15
- package/lib/cjs/agent/utils/readState.js.map +1 -1
- package/lib/cjs/candid/candid-core.js +1 -1
- package/lib/cjs/candid/candid-core.js.map +1 -1
- package/lib/cjs/candid/idl.d.ts.map +1 -1
- package/lib/cjs/candid/idl.js +88 -10
- package/lib/cjs/candid/idl.js.map +1 -1
- package/lib/cjs/candid/utils/leb128.d.ts.map +1 -1
- package/lib/cjs/candid/utils/leb128.js +19 -0
- package/lib/cjs/candid/utils/leb128.js.map +1 -1
- package/lib/esm/agent/agent/api.d.ts +52 -4
- package/lib/esm/agent/agent/api.d.ts.map +1 -1
- package/lib/esm/agent/agent/api.js +1 -0
- package/lib/esm/agent/agent/api.js.map +1 -1
- package/lib/esm/agent/agent/http/index.d.ts +2 -2
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/index.js +110 -36
- package/lib/esm/agent/agent/http/index.js.map +1 -1
- package/lib/esm/agent/canister-env/index.d.ts +2 -0
- package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
- package/lib/esm/agent/canister-env/index.js +85 -12
- package/lib/esm/agent/canister-env/index.js.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts +2 -3
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/canisterStatus/index.js +65 -121
- package/lib/esm/agent/canisterStatus/index.js.map +1 -1
- package/lib/esm/agent/certificate.d.ts +1 -1
- package/lib/esm/agent/certificate.d.ts.map +1 -1
- package/lib/esm/agent/certificate.js.map +1 -1
- package/lib/esm/agent/errors.d.ts +13 -0
- package/lib/esm/agent/errors.d.ts.map +1 -1
- package/lib/esm/agent/errors.js +23 -0
- package/lib/esm/agent/errors.js.map +1 -1
- package/lib/esm/agent/polling/index.d.ts +4 -3
- package/lib/esm/agent/polling/index.d.ts.map +1 -1
- package/lib/esm/agent/polling/index.js +7 -15
- package/lib/esm/agent/polling/index.js.map +1 -1
- package/lib/esm/agent/subnetStatus/index.d.ts +3 -2
- package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/subnetStatus/index.js +62 -85
- package/lib/esm/agent/subnetStatus/index.js.map +1 -1
- package/lib/esm/agent/utils/readState.d.ts +102 -13
- package/lib/esm/agent/utils/readState.d.ts.map +1 -1
- package/lib/esm/agent/utils/readState.js +102 -15
- package/lib/esm/agent/utils/readState.js.map +1 -1
- package/lib/esm/candid/candid-core.js +1 -1
- package/lib/esm/candid/candid-core.js.map +1 -1
- package/lib/esm/candid/idl.d.ts.map +1 -1
- package/lib/esm/candid/idl.js +88 -10
- package/lib/esm/candid/idl.js.map +1 -1
- package/lib/esm/candid/utils/leb128.d.ts.map +1 -1
- package/lib/esm/candid/utils/leb128.js +19 -0
- package/lib/esm/candid/utils/leb128.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,9 @@ import type { JsonObject } from '../../candid/index.js';
|
|
|
4
4
|
import type { Identity } from '../auth.ts';
|
|
5
5
|
import type { CallRequest, HttpHeaderField, QueryRequest } from './http/types.ts';
|
|
6
6
|
import type { PollForResponseResult, PollingOptions } from '../polling/index.ts';
|
|
7
|
+
import type { Certificate, VerifyFunc } from '../certificate.ts';
|
|
8
|
+
import type { Path, StateValues } from '../utils/readState.ts';
|
|
9
|
+
export { KnownPath, StatePaths, StateValues, encodePath, type Path } from '../utils/readState.ts';
|
|
7
10
|
/**
|
|
8
11
|
* Codes used by the replica for rejecting a message.
|
|
9
12
|
* See {@link https://sdk.dfinity.org/docs/interface-spec/#reject-codes | the interface spec}.
|
|
@@ -21,7 +24,36 @@ export declare enum ReplicaRejectCode {
|
|
|
21
24
|
export interface ReadStateOptions {
|
|
22
25
|
/**
|
|
23
26
|
* A list of paths to read the state of.
|
|
27
|
+
*
|
|
28
|
+
* Each {@link Path} may be a raw encoded path (an array of buffers) or a {@link KnownPath}
|
|
29
|
+
* (see {@link import('../utils/readState.ts').StatePaths | StatePaths} for the well-known ones).
|
|
30
|
+
* KnownPaths are encoded internally, and their values are decoded into
|
|
31
|
+
* {@link ReadStateResponse.values}.
|
|
32
|
+
*/
|
|
33
|
+
paths: Path[];
|
|
34
|
+
/**
|
|
35
|
+
* BLS verification strategy used to verify the returned certificate.
|
|
36
|
+
* Defaults to bls12_381 from `@noble/curves`.
|
|
37
|
+
*/
|
|
38
|
+
blsVerify?: VerifyFunc;
|
|
39
|
+
/**
|
|
40
|
+
* The maximum age of the returned certificate in minutes, used for the freshness check.
|
|
41
|
+
* @default 5
|
|
42
|
+
*/
|
|
43
|
+
maxAgeInMinutes?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Skips the certificate freshness (time) check when verifying the returned certificate.
|
|
46
|
+
* Required for time-sync bootstrapping and for inspecting certificates when the local clock
|
|
47
|
+
* is known to be out of sync with the network.
|
|
48
|
+
* @default false
|
|
24
49
|
*/
|
|
50
|
+
disableTimeVerification?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* {@link ReadStateOptions} with every path already encoded to its raw form. Used by the low-level
|
|
54
|
+
* request builders ({@link Agent.createReadStateRequest}), which do not perform path encoding.
|
|
55
|
+
*/
|
|
56
|
+
export interface ResolvedReadStateOptions extends Omit<ReadStateOptions, 'paths'> {
|
|
25
57
|
paths: Uint8Array[][];
|
|
26
58
|
}
|
|
27
59
|
/**
|
|
@@ -130,6 +162,18 @@ export interface UpdateOptions extends CallOptions {
|
|
|
130
162
|
}
|
|
131
163
|
export interface ReadStateResponse {
|
|
132
164
|
certificate: Uint8Array;
|
|
165
|
+
/**
|
|
166
|
+
* The parsed and verified {@link Certificate}, checked against the agent's root key and the
|
|
167
|
+
* effective target of the request. Unless {@link ReadStateOptions.disableTimeVerification} is
|
|
168
|
+
* set, verification includes the certificate freshness check.
|
|
169
|
+
*/
|
|
170
|
+
verifiedCertificate: Certificate;
|
|
171
|
+
/**
|
|
172
|
+
* Decoded values for each requested {@link KnownPath}, looked up by passing the same KnownPath
|
|
173
|
+
* instance to {@link StateValues.get}. Each value is decoded with the path's
|
|
174
|
+
* {@link KnownPath.decode}. Raw (pre-encoded `Uint8Array[]`) paths are not decoded and are absent.
|
|
175
|
+
*/
|
|
176
|
+
values: StateValues;
|
|
133
177
|
}
|
|
134
178
|
export interface v2ResponseBody {
|
|
135
179
|
error_code?: string;
|
|
@@ -192,12 +236,16 @@ export interface Agent {
|
|
|
192
236
|
* Create the request for the read state call.
|
|
193
237
|
* `readState` uses this internally.
|
|
194
238
|
* Useful to avoid signing the same request multiple times.
|
|
239
|
+
*
|
|
240
|
+
* Paths must already be encoded ({@link ResolvedReadStateOptions}); path resolution is done by
|
|
241
|
+
* {@link Agent.readState} before this is called.
|
|
195
242
|
*/
|
|
196
|
-
createReadStateRequest?(options:
|
|
243
|
+
createReadStateRequest?(options: ResolvedReadStateOptions, identity?: Identity): Promise<unknown>;
|
|
197
244
|
/**
|
|
198
|
-
* Send a read state query to the replica
|
|
199
|
-
*
|
|
200
|
-
*
|
|
245
|
+
* Send a read state query to the replica, given a list of paths to return. Returns the raw
|
|
246
|
+
* certificate alongside a parsed {@link Certificate} that has been verified against the agent's
|
|
247
|
+
* root key and the effective target, rejecting on communication errors or if verification fails.
|
|
248
|
+
* The certificate might contain less information than requested.
|
|
201
249
|
* @param effectiveTarget A Canister ID or Subnet ID related to this call.
|
|
202
250
|
* @param options The options for this call.
|
|
203
251
|
* @param identity Identity for the call. If not specified, uses the instance identity.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../../src/agent/agent/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,qBAAq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C,CAAC;IAEzB;;;;;;OAMG;IACH,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IAE9B;;;;;;;;;;OAUG;IACH,KAAK,CACH,UAAU,EAAE,SAAS,GAAG,MAAM,EAC9B,OAAO,EAAE,WAAW,EACpB,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GACtC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAE7B;;;;;;;;;;;OAWG;IACH,YAAY,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IACpC;;;;;OAKG;IACH,kBAAkB,CAAC,IAAI,IAAI,CAAC;IAC5B;;;;;;;;;OASG;IACH,eAAe,CAAC,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC5C"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueryResponseStatus = exports.ReplicaRejectCode = void 0;
|
|
3
|
+
exports.QueryResponseStatus = exports.ReplicaRejectCode = exports.encodePath = exports.StateValues = exports.StatePaths = exports.KnownPath = void 0;
|
|
4
4
|
exports.isV2ResponseBody = isV2ResponseBody;
|
|
5
5
|
exports.isV4ResponseBody = isV4ResponseBody;
|
|
6
|
+
var readState_ts_1 = require("../utils/readState.js");
|
|
7
|
+
Object.defineProperty(exports, "KnownPath", { enumerable: true, get: function () { return readState_ts_1.KnownPath; } });
|
|
8
|
+
Object.defineProperty(exports, "StatePaths", { enumerable: true, get: function () { return readState_ts_1.StatePaths; } });
|
|
9
|
+
Object.defineProperty(exports, "StateValues", { enumerable: true, get: function () { return readState_ts_1.StateValues; } });
|
|
10
|
+
Object.defineProperty(exports, "encodePath", { enumerable: true, get: function () { return readState_ts_1.encodePath; } });
|
|
6
11
|
/**
|
|
7
12
|
* Codes used by the replica for rejecting a message.
|
|
8
13
|
* See {@link https://sdk.dfinity.org/docs/interface-spec/#reject-codes | the interface spec}.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/agent/agent/api.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/agent/agent/api.ts"],"names":[],"mappings":";;;AAyNA,4CAIC;AAWD,4CAIC;AAnOD,sDAAkG;AAAzF,yGAAA,SAAS,OAAA;AAAE,0GAAA,UAAU,OAAA;AAAE,2GAAA,WAAW,OAAA;AAAE,0GAAA,UAAU,OAAA;AAEvD;;;GAGG;AACH,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,iEAAY,CAAA;IACZ,yEAAgB,CAAA;IAChB,qFAAsB,CAAA;IACtB,6EAAkB,CAAA;IAClB,2EAAiB,CAAA;AACnB,CAAC,EANW,iBAAiB,iCAAjB,iBAAiB,QAM5B;AAkDD,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,0CAAmB,CAAA;IACnB,4CAAqB,CAAA;AACvB,CAAC,EAHW,mBAAmB,mCAAnB,mBAAmB,QAG9B;AA0ID;;;;GAIG;AACH,SAAgB,gBAAgB,CAC9B,IAA4C;IAE5C,OAAO,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,IAAI,aAAa,IAAI,IAAI,CAAC;AACtE,CAAC;AAMD;;;;GAIG;AACH,SAAgB,gBAAgB,CAC9B,IAA4C;IAE5C,OAAO,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,IAAI,aAAa,IAAI,IAAI,CAAC;AACtE,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { JsonObject } from '../../../candid/index.js';
|
|
2
2
|
import { Principal } from '../../../principal/index.js';
|
|
3
3
|
import { type Identity } from '../../auth.ts';
|
|
4
|
-
import { type Agent, type ApiQueryResponse, type UpdateResult, type InputTargetPrincipal, type QueryFields, type ReadStateOptions, type ReadStateResponse, type SubmitResponse, type CallOptions, type UpdateOptions } from '../api.ts';
|
|
4
|
+
import { type Agent, type ApiQueryResponse, type UpdateResult, type InputTargetPrincipal, type QueryFields, type ReadStateOptions, type ReadStateResponse, type ResolvedReadStateOptions, type SubmitResponse, type CallOptions, type UpdateOptions } from '../api.ts';
|
|
5
5
|
import { Expiry } from './transforms.ts';
|
|
6
6
|
import { type HttpAgentRequest, type HttpAgentRequestTransformFn } from './types.ts';
|
|
7
7
|
import { type SubnetNodeKeys } from '../../utils/readState.ts';
|
|
@@ -129,7 +129,7 @@ export declare class HttpAgent implements Agent {
|
|
|
129
129
|
*/
|
|
130
130
|
update(canisterId: Principal | string, fields: UpdateOptions, pollingOptions?: PollingOptions): Promise<UpdateResult>;
|
|
131
131
|
query(canisterId: Principal | string, fields: QueryFields, identity?: Identity | Promise<Identity>): Promise<ApiQueryResponse>;
|
|
132
|
-
createReadStateRequest(fields:
|
|
132
|
+
createReadStateRequest(fields: ResolvedReadStateOptions, identity?: Identity | Promise<Identity>): Promise<any>;
|
|
133
133
|
readState(effectiveTarget: InputTargetPrincipal, fields: ReadStateOptions, _identity?: Identity | Promise<Identity>, request?: any): Promise<ReadStateResponse>;
|
|
134
134
|
/**
|
|
135
135
|
* @deprecated Use `readState`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/agent/agent/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAiCvC,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGjE,OAAO,EAEL,KAAK,KAAK,EACV,KAAK,gBAAgB,EACrB,KAAK,YAAY,EAEjB,KAAK,oBAAoB,EACzB,KAAK,WAAW,EAEhB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,aAAa,EAKnB,MA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xF,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAe1E;;;;;OAKG;IACI,gBAAgB,IAAI,MAAM;IAIjC;;OAEG;IACI,aAAa,IAAI,OAAO;CAGhC;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,yBAAyB,EAAE,MAAM,EACjC,aAAa,EAAE,MAAM,GACpB,MAAM,CAGR"}
|
|
@@ -130,6 +130,8 @@ class HttpAgent {
|
|
|
130
130
|
#rootKeyPromise;
|
|
131
131
|
#shouldFetchRootKey;
|
|
132
132
|
#timeDiffMsecs;
|
|
133
|
+
// The latest synced certified time, and the local time right after it was received.
|
|
134
|
+
#syncedCertifiedTime;
|
|
133
135
|
#hasSyncedTime;
|
|
134
136
|
#syncTimePromise;
|
|
135
137
|
#shouldSyncTime;
|
|
@@ -159,6 +161,8 @@ class HttpAgent {
|
|
|
159
161
|
this.#rootKeyPromise = null;
|
|
160
162
|
this.#shouldFetchRootKey = false;
|
|
161
163
|
this.#timeDiffMsecs = DEFAULT_TIME_DIFF_MSECS;
|
|
164
|
+
// The latest synced certified time, and the local time right after it was received.
|
|
165
|
+
this.#syncedCertifiedTime = null;
|
|
162
166
|
this.#hasSyncedTime = false;
|
|
163
167
|
this.#syncTimePromise = null;
|
|
164
168
|
this.#shouldSyncTime = false;
|
|
@@ -439,8 +443,14 @@ class HttpAgent {
|
|
|
439
443
|
const requestId = (0, request_id_ts_1.requestIdOf)(transformedRequest.body.content ?? submit);
|
|
440
444
|
const body = cbor.encode(transformedRequest.body);
|
|
441
445
|
const backoff = this.#backoffStrategy();
|
|
446
|
+
// Local time before the request is first sent, used to reason about the
|
|
447
|
+
// replica time at which the signed request could have been received.
|
|
448
|
+
const submittedAt = localTimestamp();
|
|
442
449
|
try {
|
|
443
450
|
let requestFn;
|
|
451
|
+
// The v2 endpoint accepts the same signed envelope as v4, so falling back
|
|
452
|
+
// resends `body` as-is and the request ID stays the same.
|
|
453
|
+
let fallbackRequestFn;
|
|
444
454
|
if ('canisterId' in target) {
|
|
445
455
|
// Attempt v4 sync call
|
|
446
456
|
const requestSync = () => {
|
|
@@ -462,6 +472,7 @@ class HttpAgent {
|
|
|
462
472
|
});
|
|
463
473
|
};
|
|
464
474
|
requestFn = callSync ? requestSync : requestAsync;
|
|
475
|
+
fallbackRequestFn = callSync ? requestAsync : undefined;
|
|
465
476
|
}
|
|
466
477
|
else {
|
|
467
478
|
if (!callSync) {
|
|
@@ -477,11 +488,24 @@ class HttpAgent {
|
|
|
477
488
|
});
|
|
478
489
|
};
|
|
479
490
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
backoff,
|
|
483
|
-
|
|
484
|
-
|
|
491
|
+
let rawResponse;
|
|
492
|
+
try {
|
|
493
|
+
rawResponse = await this.#requestAndRetry({ requestFn, backoff, tries: 0 });
|
|
494
|
+
}
|
|
495
|
+
catch (error) {
|
|
496
|
+
if (!fallbackRequestFn ||
|
|
497
|
+
!(error instanceof errors_ts_1.AgentError) ||
|
|
498
|
+
!error.hasCode(errors_ts_1.HttpV4ApiNotSupportedErrorCode)) {
|
|
499
|
+
throw error;
|
|
500
|
+
}
|
|
501
|
+
this.log.warn('v4 api not supported. Fall back to v2');
|
|
502
|
+
rawResponse = await this.#requestAndRetry({
|
|
503
|
+
requestFn: fallbackRequestFn,
|
|
504
|
+
backoff: this.#backoffStrategy(),
|
|
505
|
+
tries: 0,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
const { responseBodyBytes, ...response } = rawResponse;
|
|
485
509
|
const responseBody = (responseBodyBytes.byteLength > 0 ? cbor.decode(responseBodyBytes) : null);
|
|
486
510
|
return {
|
|
487
511
|
requestId,
|
|
@@ -495,20 +519,14 @@ class HttpAgent {
|
|
|
495
519
|
catch (error) {
|
|
496
520
|
let callError;
|
|
497
521
|
if (error instanceof errors_ts_1.AgentError) {
|
|
498
|
-
// If the error is due to the v4 api not being supported, fall back to v2
|
|
499
|
-
if ('canisterId' in target && error.hasCode(errors_ts_1.HttpV4ApiNotSupportedErrorCode)) {
|
|
500
|
-
this.log.warn('v4 api not supported. Fall back to v2');
|
|
501
|
-
return this.call(canisterId, {
|
|
502
|
-
...options,
|
|
503
|
-
// disable v4 api
|
|
504
|
-
callSync: false,
|
|
505
|
-
}, identity);
|
|
506
|
-
}
|
|
507
522
|
if (error.hasCode(errors_ts_1.IngressExpiryInvalidErrorCode) && !this.#hasSyncedTime) {
|
|
508
523
|
// if there is an ingress expiry error and the time has not been synced yet,
|
|
509
|
-
// sync time with the network and
|
|
524
|
+
// sync time with the network, and sign a new request only if the certified
|
|
525
|
+
// time shows the original request's expiry had already passed when it was sent
|
|
510
526
|
await this.syncTime(target);
|
|
511
|
-
|
|
527
|
+
if (this.#isExpiredAt(transformedRequest.body.content.ingress_expiry, submittedAt)) {
|
|
528
|
+
return this.call(canister, options, identity);
|
|
529
|
+
}
|
|
512
530
|
}
|
|
513
531
|
// override the error code to include the request details
|
|
514
532
|
error.code.requestContext = {
|
|
@@ -936,6 +954,21 @@ class HttpAgent {
|
|
|
936
954
|
}
|
|
937
955
|
await this.#rootKeyGuard();
|
|
938
956
|
const target = (0, target_ts_1.inputToTarget)(effectiveTarget);
|
|
957
|
+
if (!fields.disableTimeVerification) {
|
|
958
|
+
await this.#syncTimeGuard(target);
|
|
959
|
+
}
|
|
960
|
+
// Encode paths into their raw form. Raw (pre-encoded) paths pass through unchanged; each
|
|
961
|
+
// KnownPath is retained alongside its encoded form so its value can be decoded below.
|
|
962
|
+
const encodedPaths = [];
|
|
963
|
+
const knownPaths = [];
|
|
964
|
+
for (const path of fields.paths) {
|
|
965
|
+
const encoded = (0, readState_ts_1.encodePath)(path);
|
|
966
|
+
encodedPaths.push(encoded);
|
|
967
|
+
if (!Array.isArray(path)) {
|
|
968
|
+
knownPaths.push({ path, encoded });
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
const resolvedFields = { ...fields, paths: encodedPaths };
|
|
939
972
|
let transformedRequest;
|
|
940
973
|
let requestId;
|
|
941
974
|
// If a pre-signed request is provided, use it
|
|
@@ -945,18 +978,39 @@ class HttpAgent {
|
|
|
945
978
|
}
|
|
946
979
|
else {
|
|
947
980
|
// This is fields, we need to create a request
|
|
948
|
-
requestId = this.#getRequestId(
|
|
981
|
+
requestId = this.#getRequestId(resolvedFields);
|
|
949
982
|
// Always create a fresh request with the current identity
|
|
950
983
|
const identity = await this.#identity;
|
|
951
984
|
if (!identity) {
|
|
952
985
|
throw errors_ts_1.ExternalError.fromCode(new errors_ts_1.IdentityInvalidErrorCode());
|
|
953
986
|
}
|
|
954
|
-
transformedRequest = await this.createReadStateRequest(
|
|
987
|
+
transformedRequest = await this.createReadStateRequest(resolvedFields, identity);
|
|
955
988
|
}
|
|
956
989
|
const url = 'canisterId' in target
|
|
957
990
|
? new URL(`api/v3/canister/${target.canisterId.toString()}/read_state`, this.host)
|
|
958
991
|
: new URL(`api/v3/subnet/${target.subnetId.toString()}/read_state`, this.host);
|
|
959
|
-
|
|
992
|
+
if (this.rootKey === null) {
|
|
993
|
+
throw errors_ts_1.ExternalError.fromCode(new errors_ts_1.MissingRootKeyErrorCode(this.#shouldFetchRootKey));
|
|
994
|
+
}
|
|
995
|
+
const rootKey = this.rootKey;
|
|
996
|
+
const { certificate } = await this.#readStateInner(url, target, transformedRequest, requestId);
|
|
997
|
+
const verifiedCertificate = await certificate_ts_1.Certificate.create({
|
|
998
|
+
certificate,
|
|
999
|
+
rootKey,
|
|
1000
|
+
principal: target,
|
|
1001
|
+
blsVerify: fields.blsVerify,
|
|
1002
|
+
maxAgeInMinutes: fields.maxAgeInMinutes,
|
|
1003
|
+
disableTimeVerification: fields.disableTimeVerification,
|
|
1004
|
+
agent: this,
|
|
1005
|
+
});
|
|
1006
|
+
// Decode the value at each KnownPath with its own decoder, keyed by the path. A value absent
|
|
1007
|
+
// from the certificate maps to null.
|
|
1008
|
+
const decoded = new Map();
|
|
1009
|
+
for (const { path, encoded } of knownPaths) {
|
|
1010
|
+
const buffer = (0, certificate_ts_1.lookupResultToBuffer)(verifiedCertificate.lookup_path(encoded));
|
|
1011
|
+
decoded.set(path.key, buffer === undefined ? null : path.decode(buffer));
|
|
1012
|
+
}
|
|
1013
|
+
return { certificate, verifiedCertificate, values: new readState_ts_1.StateValues(decoded) };
|
|
960
1014
|
}
|
|
961
1015
|
// eslint-disable-next-line
|
|
962
1016
|
/**
|
|
@@ -1082,7 +1136,7 @@ class HttpAgent {
|
|
|
1082
1136
|
return date.getTime();
|
|
1083
1137
|
}
|
|
1084
1138
|
}, []));
|
|
1085
|
-
this.#setTimeDiffMsecs(callTime, replicaTimes);
|
|
1139
|
+
this.#setTimeDiffMsecs(callTime, localTimestamp(), replicaTimes);
|
|
1086
1140
|
}
|
|
1087
1141
|
catch (error) {
|
|
1088
1142
|
const syncTimeError = error instanceof errors_ts_1.AgentError
|
|
@@ -1103,12 +1157,13 @@ class HttpAgent {
|
|
|
1103
1157
|
syncTimeWithSubnet(subnetId) {
|
|
1104
1158
|
return this.syncTime({ subnetId });
|
|
1105
1159
|
}
|
|
1106
|
-
#setTimeDiffMsecs(callTime, replicaTimes) {
|
|
1160
|
+
#setTimeDiffMsecs(callTime, receivedAt, replicaTimes) {
|
|
1107
1161
|
const maxReplicaTime = replicaTimes.reduce((max, current) => {
|
|
1108
1162
|
return typeof current === 'number' && current > max ? current : max;
|
|
1109
1163
|
}, 0);
|
|
1110
1164
|
if (maxReplicaTime > 0) {
|
|
1111
1165
|
this.#timeDiffMsecs = maxReplicaTime - callTime;
|
|
1166
|
+
this.#syncedCertifiedTime = { replicaTimeMs: maxReplicaTime, receivedAt };
|
|
1112
1167
|
this.#hasSyncedTime = true;
|
|
1113
1168
|
this.log.notify({
|
|
1114
1169
|
message: `Syncing time: offset of ${this.#timeDiffMsecs}`,
|
|
@@ -1116,6 +1171,26 @@ class HttpAgent {
|
|
|
1116
1171
|
});
|
|
1117
1172
|
}
|
|
1118
1173
|
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Whether the given expiry had already passed, according to the synced certified time,
|
|
1176
|
+
* at the given local time.
|
|
1177
|
+
* @param expiry The ingress expiry of the request.
|
|
1178
|
+
* @param at The local time to check the expiry at.
|
|
1179
|
+
* @returns `true` only if time has been synced and the expiry is before the lower bound
|
|
1180
|
+
* of the replica time at `at`.
|
|
1181
|
+
*/
|
|
1182
|
+
#isExpiredAt(expiry, at) {
|
|
1183
|
+
if (this.#syncedCertifiedTime === null) {
|
|
1184
|
+
return false;
|
|
1185
|
+
}
|
|
1186
|
+
const { replicaTimeMs, receivedAt } = this.#syncedCertifiedTime;
|
|
1187
|
+
// The certified time is not later than the replica time when it was received. Subtract
|
|
1188
|
+
// the larger of the wall-clock and monotonic elapsed times, so that neither a wall-clock
|
|
1189
|
+
// adjustment nor a paused monotonic clock (e.g. system sleep) inflates the bound.
|
|
1190
|
+
const elapsedMs = Math.max(receivedAt.wallMs - at.wallMs, receivedAt.monotonicMs - at.monotonicMs);
|
|
1191
|
+
const replicaTimeLowerBoundNs = BigInt(Math.floor(replicaTimeMs - elapsedMs)) * BigInt(MSECS_TO_NANOSECONDS);
|
|
1192
|
+
return expiry.toBigInt() < replicaTimeLowerBoundNs;
|
|
1193
|
+
}
|
|
1119
1194
|
async status() {
|
|
1120
1195
|
const headers = this.#credentials
|
|
1121
1196
|
? {
|
|
@@ -1202,15 +1277,9 @@ class HttpAgent {
|
|
|
1202
1277
|
async #doFetchSubnetKeys(target) {
|
|
1203
1278
|
await this.#asyncGuard(target);
|
|
1204
1279
|
const rootKey = this.rootKey;
|
|
1205
|
-
const
|
|
1280
|
+
const { verifiedCertificate: canisterCertificate } = await this.readState(target, {
|
|
1206
1281
|
paths: [[(0, utils_js_1.utf8ToBytes)('subnet')]],
|
|
1207
1282
|
});
|
|
1208
|
-
const canisterCertificate = await certificate_ts_1.Certificate.create({
|
|
1209
|
-
certificate: canisterReadState.certificate,
|
|
1210
|
-
rootKey,
|
|
1211
|
-
principal: target,
|
|
1212
|
-
agent: this,
|
|
1213
|
-
});
|
|
1214
1283
|
const targetKey = (0, target_ts_1.getTargetKey)(target);
|
|
1215
1284
|
if ('canisterId' in target && !canisterCertificate.cert.delegation) {
|
|
1216
1285
|
const subnetId = _principal_1.Principal.selfAuthenticating(rootKey);
|
|
@@ -1237,15 +1306,9 @@ class HttpAgent {
|
|
|
1237
1306
|
async getSubnetIdFromCanister(canisterId) {
|
|
1238
1307
|
const effectiveCanisterId = _principal_1.Principal.from(canisterId);
|
|
1239
1308
|
await this.#asyncGuard({ canisterId: effectiveCanisterId });
|
|
1240
|
-
const
|
|
1309
|
+
const { verifiedCertificate: canisterCertificate } = await this.readState({ canisterId: effectiveCanisterId }, {
|
|
1241
1310
|
paths: [[(0, utils_js_1.utf8ToBytes)('time')]],
|
|
1242
1311
|
});
|
|
1243
|
-
const canisterCertificate = await certificate_ts_1.Certificate.create({
|
|
1244
|
-
certificate: canisterReadState.certificate,
|
|
1245
|
-
rootKey: this.rootKey,
|
|
1246
|
-
principal: { canisterId: effectiveCanisterId },
|
|
1247
|
-
agent: this,
|
|
1248
|
-
});
|
|
1249
1312
|
return (0, certificate_ts_1.getSubnetIdFromCertificate)(canisterCertificate.cert, this.rootKey);
|
|
1250
1313
|
}
|
|
1251
1314
|
_transform(request) {
|
|
@@ -1290,6 +1353,17 @@ function calculateIngressExpiry(maxIngressExpiryInMinutes, timeDiffMsecs) {
|
|
|
1290
1353
|
const ingressExpiryMs = maxIngressExpiryInMinutes * MINUTE_TO_MSECS;
|
|
1291
1354
|
return transforms_ts_1.Expiry.fromDeltaInMilliseconds(ingressExpiryMs, timeDiffMsecs);
|
|
1292
1355
|
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Reads the local wall-clock time, and a monotonic time where available.
|
|
1358
|
+
* @returns the current local timestamp.
|
|
1359
|
+
*/
|
|
1360
|
+
function localTimestamp() {
|
|
1361
|
+
const wallMs = Date.now();
|
|
1362
|
+
const monotonicMs = typeof performance !== 'undefined' && typeof performance.now === 'function'
|
|
1363
|
+
? performance.now()
|
|
1364
|
+
: wallMs;
|
|
1365
|
+
return { wallMs, monotonicMs };
|
|
1366
|
+
}
|
|
1293
1367
|
/**
|
|
1294
1368
|
* Checks if the response text is an ingress expiry invalid response.
|
|
1295
1369
|
* @see https://github.com/dfinity/ic/blob/23d5990bfc5277c32e54f0087b5a38fa412171e1/rs/validator/src/ingress_validation.rs#L233
|