@icp-sdk/core 5.0.0-beta.0 → 5.0.0-beta.2
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/README.md +0 -2
- package/lib/cjs/agent/actor.js +2 -2
- package/lib/cjs/agent/actor.js.map +1 -1
- package/lib/cjs/agent/agent/api.d.ts +6 -6
- package/lib/cjs/agent/agent/api.js +4 -4
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts +30 -0
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js +33 -1
- package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -1
- package/lib/cjs/agent/agent/http/index.d.ts +23 -5
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/index.js +201 -86
- package/lib/cjs/agent/agent/http/index.js.map +1 -1
- package/lib/cjs/agent/agent/index.d.ts +2 -0
- package/lib/cjs/agent/agent/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/index.js +2 -0
- package/lib/cjs/agent/agent/index.js.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.d.ts +18 -50
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.js +30 -97
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
- package/lib/cjs/agent/certificate.d.ts +68 -10
- package/lib/cjs/agent/certificate.d.ts.map +1 -1
- package/lib/cjs/agent/certificate.js +198 -27
- package/lib/cjs/agent/certificate.js.map +1 -1
- package/lib/cjs/agent/constants.d.ts +4 -0
- package/lib/cjs/agent/constants.d.ts.map +1 -1
- package/lib/cjs/agent/constants.js +5 -1
- package/lib/cjs/agent/constants.js.map +1 -1
- package/lib/cjs/agent/errors.d.ts +9 -2
- package/lib/cjs/agent/errors.d.ts.map +1 -1
- package/lib/cjs/agent/errors.js +19 -7
- package/lib/cjs/agent/errors.js.map +1 -1
- package/lib/cjs/agent/index.d.ts +97 -5
- package/lib/cjs/agent/index.d.ts.map +1 -1
- package/lib/cjs/agent/index.js +92 -11
- package/lib/cjs/agent/index.js.map +1 -1
- package/lib/cjs/agent/polling/index.js +1 -1
- package/lib/cjs/agent/polling/index.js.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.d.ts +70 -0
- package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -0
- package/lib/cjs/agent/subnetStatus/index.js +219 -0
- package/lib/cjs/agent/subnetStatus/index.js.map +1 -0
- package/lib/cjs/agent/utils/readState.d.ts +84 -0
- package/lib/cjs/agent/utils/readState.d.ts.map +1 -0
- package/lib/cjs/agent/utils/readState.js +149 -0
- package/lib/cjs/agent/utils/readState.js.map +1 -0
- package/lib/cjs/candid/index.d.ts +20 -1
- package/lib/cjs/candid/index.d.ts.map +1 -1
- package/lib/cjs/candid/index.js +20 -1
- package/lib/cjs/candid/index.js.map +1 -1
- package/lib/cjs/identity/index.d.ts +30 -7
- package/lib/cjs/identity/index.d.ts.map +1 -1
- package/lib/cjs/identity/index.js +31 -11
- package/lib/cjs/identity/index.js.map +1 -1
- package/lib/cjs/identity/secp256k1/index.d.ts +48 -1
- package/lib/cjs/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/index.js +48 -1
- package/lib/cjs/identity/secp256k1/index.js.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.js +1 -2
- package/lib/cjs/identity/secp256k1/pem.js.map +1 -1
- package/lib/cjs/principal/index.d.ts +15 -0
- package/lib/cjs/principal/index.d.ts.map +1 -1
- package/lib/cjs/principal/index.js +15 -0
- package/lib/cjs/principal/index.js.map +1 -1
- package/lib/esm/agent/actor.js +3 -3
- package/lib/esm/agent/actor.js.map +1 -1
- package/lib/esm/agent/agent/api.d.ts +6 -6
- package/lib/esm/agent/agent/api.js +3 -3
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts +30 -0
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js +33 -1
- package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -1
- package/lib/esm/agent/agent/http/index.d.ts +23 -5
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/index.js +203 -84
- package/lib/esm/agent/agent/http/index.js.map +1 -1
- package/lib/esm/agent/agent/index.d.ts +2 -0
- package/lib/esm/agent/agent/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/index.js +2 -0
- package/lib/esm/agent/agent/index.js.map +1 -1
- package/lib/esm/agent/canister-env/index.d.ts +2 -1
- package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
- package/lib/esm/agent/canister-env/index.js +2 -1
- package/lib/esm/agent/canister-env/index.js.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts +18 -50
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/canisterStatus/index.js +31 -98
- package/lib/esm/agent/canisterStatus/index.js.map +1 -1
- package/lib/esm/agent/certificate.d.ts +68 -10
- package/lib/esm/agent/certificate.d.ts.map +1 -1
- package/lib/esm/agent/certificate.js +196 -29
- package/lib/esm/agent/certificate.js.map +1 -1
- package/lib/esm/agent/constants.d.ts +4 -0
- package/lib/esm/agent/constants.d.ts.map +1 -1
- package/lib/esm/agent/constants.js +4 -0
- package/lib/esm/agent/constants.js.map +1 -1
- package/lib/esm/agent/errors.d.ts +9 -2
- package/lib/esm/agent/errors.d.ts.map +1 -1
- package/lib/esm/agent/errors.js +15 -4
- package/lib/esm/agent/errors.js.map +1 -1
- package/lib/esm/agent/index.d.ts +97 -5
- package/lib/esm/agent/index.d.ts.map +1 -1
- package/lib/esm/agent/index.js +97 -5
- package/lib/esm/agent/index.js.map +1 -1
- package/lib/esm/agent/polling/index.js +1 -1
- package/lib/esm/agent/polling/index.js.map +1 -1
- package/lib/esm/agent/subnetStatus/index.d.ts +70 -0
- package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -0
- package/lib/esm/agent/subnetStatus/index.js +178 -0
- package/lib/esm/agent/subnetStatus/index.js.map +1 -0
- package/lib/esm/agent/utils/readState.d.ts +84 -0
- package/lib/esm/agent/utils/readState.d.ts.map +1 -0
- package/lib/esm/agent/utils/readState.js +107 -0
- package/lib/esm/agent/utils/readState.js.map +1 -0
- package/lib/esm/candid/index.d.ts +20 -1
- package/lib/esm/candid/index.d.ts.map +1 -1
- package/lib/esm/candid/index.js +20 -1
- package/lib/esm/candid/index.js.map +1 -1
- package/lib/esm/identity/index.d.ts +30 -7
- package/lib/esm/identity/index.d.ts.map +1 -1
- package/lib/esm/identity/index.js +30 -9
- package/lib/esm/identity/index.js.map +1 -1
- package/lib/esm/identity/secp256k1/index.d.ts +48 -1
- package/lib/esm/identity/secp256k1/index.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/index.js +48 -1
- package/lib/esm/identity/secp256k1/index.js.map +1 -1
- package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/pem.js +1 -2
- package/lib/esm/identity/secp256k1/pem.js.map +1 -1
- package/lib/esm/principal/index.d.ts +15 -0
- package/lib/esm/principal/index.d.ts.map +1 -1
- package/lib/esm/principal/index.js +15 -0
- package/lib/esm/principal/index.js.map +1 -1
- package/package.json +3 -1
- package/src/agent/actor.ts +3 -3
- package/src/agent/agent/api.ts +8 -8
- package/src/agent/agent/http/index.ts +259 -97
- package/src/agent/agent/index.ts +2 -0
- package/src/agent/canister-env/index.ts +2 -1
- package/src/agent/canisterStatus/index.ts +46 -196
- package/src/agent/certificate.ts +271 -52
- package/src/agent/constants.ts +5 -0
- package/src/agent/errors.ts +19 -5
- package/src/agent/index.ts +97 -5
- package/src/agent/polling/index.ts +1 -1
- package/src/agent/subnetStatus/index.ts +265 -0
- package/src/agent/utils/readState.ts +180 -0
- package/src/candid/index.ts +20 -1
- package/src/identity/index.ts +30 -10
- package/src/identity/secp256k1/index.ts +48 -1
- package/src/identity/secp256k1/pem.ts +1 -2
- package/src/principal/index.ts +16 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/agent/agent/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/agent/agent/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA8BvC,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGjE,OAAO,EAEL,KAAK,KAAK,EACV,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAEhB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,MAAM,EAA4C,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAGhC,KAAK,KAAK,EAMX,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAiC,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAY9F,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAEL,KAAK,sBAAsB,EAE5B,MAAM,0BAA0B,CAAC;AAMlC,oBAAY,2BAA2B;IACrC,QAAQ,aAAa;IACrB,UAAU,eAAe;IACzB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,IAAI,SAAS;CACd;AAQD,eAAO,MAAM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G,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAiBxF,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"}
|
|
@@ -32,11 +32,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.HttpAgent = exports.MANAGEMENT_CANISTER_ID = exports.IC_ROOT_KEY = exports.RequestStatusResponseStatus =
|
|
36
|
+
exports.HttpAgent = exports.MANAGEMENT_CANISTER_ID = exports.IC_ROOT_KEY = exports.RequestStatusResponseStatus = void 0;
|
|
40
37
|
exports.calculateIngressExpiry = calculateIngressExpiry;
|
|
41
38
|
const _principal_1 = require("../../../principal/index.js");
|
|
42
39
|
const errors_ts_1 = require("../../errors.js");
|
|
@@ -47,6 +44,8 @@ const api_ts_1 = require("../api.js");
|
|
|
47
44
|
const transforms_ts_1 = require("./transforms.js");
|
|
48
45
|
const types_ts_1 = require("./types.js");
|
|
49
46
|
const index_ts_1 = require("../../canisterStatus/index.js");
|
|
47
|
+
const index_ts_2 = require("../../subnetStatus/index.js");
|
|
48
|
+
const readState_ts_1 = require("../../utils/readState.js");
|
|
50
49
|
const certificate_ts_1 = require("../../certificate.js");
|
|
51
50
|
const ed25519_1 = require("@noble/curves/ed25519");
|
|
52
51
|
const expirableMap_ts_1 = require("../../utils/expirableMap.js");
|
|
@@ -57,9 +56,6 @@ const leb_ts_1 = require("../../utils/leb.js");
|
|
|
57
56
|
const utils_1 = require("@noble/hashes/utils");
|
|
58
57
|
const buffer_ts_1 = require("../../utils/buffer.js");
|
|
59
58
|
const constants_ts_1 = require("../../constants.js");
|
|
60
|
-
__exportStar(require("./transforms.js"), exports);
|
|
61
|
-
var types_ts_2 = require("./types.js");
|
|
62
|
-
Object.defineProperty(exports, "makeNonce", { enumerable: true, get: function () { return types_ts_2.makeNonce; } });
|
|
63
59
|
var RequestStatusResponseStatus;
|
|
64
60
|
(function (RequestStatusResponseStatus) {
|
|
65
61
|
RequestStatusResponseStatus["Received"] = "received";
|
|
@@ -209,10 +205,10 @@ class HttpAgent {
|
|
|
209
205
|
/**
|
|
210
206
|
* See https://internetcomputer.org/docs/current/references/ic-interface-spec/#http-query for details on validation
|
|
211
207
|
* @param queryResponse - The response from the query
|
|
212
|
-
* @param
|
|
208
|
+
* @param subnetNodeKeys - The subnet node keys
|
|
213
209
|
* @returns ApiQueryResponse
|
|
214
210
|
*/
|
|
215
|
-
this.#verifyQueryResponse = (queryResponse,
|
|
211
|
+
this.#verifyQueryResponse = (queryResponse, subnetNodeKeys) => {
|
|
216
212
|
if (this.#verifyQuerySignatures === false) {
|
|
217
213
|
// This should not be called if the user has disabled verification
|
|
218
214
|
return queryResponse;
|
|
@@ -247,16 +243,15 @@ class HttpAgent {
|
|
|
247
243
|
throw errors_ts_1.UnknownError.fromCode(new errors_ts_1.UnexpectedErrorCode(`Unknown status: ${status}`));
|
|
248
244
|
}
|
|
249
245
|
const separatorWithHash = (0, utils_1.concatBytes)(constants_ts_1.IC_RESPONSE_DOMAIN_SEPARATOR, hash);
|
|
250
|
-
|
|
251
|
-
const pubKey = subnetStatus.nodeKeys.get(nodeId);
|
|
246
|
+
const pubKey = subnetNodeKeys.get(nodeId);
|
|
252
247
|
if (!pubKey) {
|
|
253
248
|
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.MalformedPublicKeyErrorCode());
|
|
254
249
|
}
|
|
255
250
|
const rawKey = public_key_ts_1.Ed25519PublicKey.fromDer(pubKey).rawKey;
|
|
256
251
|
const valid = ed25519_1.ed25519.verify(sig.signature, separatorWithHash, rawKey);
|
|
257
|
-
if (valid)
|
|
258
|
-
|
|
259
|
-
|
|
252
|
+
if (!valid) {
|
|
253
|
+
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.QuerySignatureVerificationFailedErrorCode(nodeId));
|
|
254
|
+
}
|
|
260
255
|
}
|
|
261
256
|
return queryResponse;
|
|
262
257
|
};
|
|
@@ -451,9 +446,9 @@ class HttpAgent {
|
|
|
451
446
|
const backoff = this.#backoffStrategy();
|
|
452
447
|
const requestId = (0, request_id_ts_1.requestIdOf)(submit);
|
|
453
448
|
try {
|
|
454
|
-
// Attempt
|
|
449
|
+
// Attempt v4 sync call
|
|
455
450
|
const requestSync = () => {
|
|
456
|
-
const url = new URL(`/api/
|
|
451
|
+
const url = new URL(`/api/v4/canister/${ecid.toText()}/call`, this.host);
|
|
457
452
|
this.log.print(`fetching "${url.pathname}" with request:`, transformedRequest);
|
|
458
453
|
return this.#fetch(url, {
|
|
459
454
|
...this.#callOptions,
|
|
@@ -489,12 +484,12 @@ class HttpAgent {
|
|
|
489
484
|
catch (error) {
|
|
490
485
|
let callError;
|
|
491
486
|
if (error instanceof errors_ts_1.AgentError) {
|
|
492
|
-
// If the error is due to the
|
|
493
|
-
if (error.hasCode(errors_ts_1.
|
|
494
|
-
this.log.warn('
|
|
487
|
+
// If the error is due to the v4 api not being supported, fall back to v2
|
|
488
|
+
if (error.hasCode(errors_ts_1.HttpV4ApiNotSupportedErrorCode)) {
|
|
489
|
+
this.log.warn('v4 api not supported. Fall back to v2');
|
|
495
490
|
return this.call(canisterId, {
|
|
496
491
|
...options,
|
|
497
|
-
// disable
|
|
492
|
+
// disable v4 api
|
|
498
493
|
callSync: false,
|
|
499
494
|
}, identity);
|
|
500
495
|
}
|
|
@@ -525,7 +520,7 @@ class HttpAgent {
|
|
|
525
520
|
async #requestAndRetryQuery(args) {
|
|
526
521
|
const { ecid, transformedRequest, body, requestId, backoff, tries } = args;
|
|
527
522
|
const delay = tries === 0 ? 0 : backoff.next();
|
|
528
|
-
const url = new URL(`/api/
|
|
523
|
+
const url = new URL(`/api/v3/canister/${ecid.toString()}/query`, this.host);
|
|
529
524
|
this.log.print(`fetching "${url.pathname}" with tries:`, {
|
|
530
525
|
tries,
|
|
531
526
|
backoff,
|
|
@@ -538,31 +533,15 @@ class HttpAgent {
|
|
|
538
533
|
if (delay > 0) {
|
|
539
534
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
540
535
|
}
|
|
541
|
-
let
|
|
536
|
+
let fetchResponse;
|
|
542
537
|
// Make the request and retry if it throws an error
|
|
543
538
|
try {
|
|
544
539
|
this.log.print(`fetching "${url.pathname}" with request:`, transformedRequest);
|
|
545
|
-
|
|
540
|
+
fetchResponse = await this.#fetch(url, {
|
|
546
541
|
...this.#fetchOptions,
|
|
547
542
|
...transformedRequest.request,
|
|
548
543
|
body,
|
|
549
544
|
});
|
|
550
|
-
if (fetchResponse.status === HTTP_STATUS_OK) {
|
|
551
|
-
const queryResponse = cbor.decode((0, buffer_ts_1.uint8FromBufLike)(await fetchResponse.arrayBuffer()));
|
|
552
|
-
response = {
|
|
553
|
-
...queryResponse,
|
|
554
|
-
httpDetails: {
|
|
555
|
-
ok: fetchResponse.ok,
|
|
556
|
-
status: fetchResponse.status,
|
|
557
|
-
statusText: fetchResponse.statusText,
|
|
558
|
-
headers: (0, transforms_ts_1.httpHeadersTransform)(fetchResponse.headers),
|
|
559
|
-
},
|
|
560
|
-
requestId,
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
else {
|
|
564
|
-
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.HttpErrorCode(fetchResponse.status, fetchResponse.statusText, (0, transforms_ts_1.httpHeadersTransform)(fetchResponse.headers), await fetchResponse.text()));
|
|
565
|
-
}
|
|
566
545
|
}
|
|
567
546
|
catch (error) {
|
|
568
547
|
if (tries < this.#retryTimes) {
|
|
@@ -571,13 +550,30 @@ class HttpAgent {
|
|
|
571
550
|
` Retrying query.`);
|
|
572
551
|
return await this.#requestAndRetryQuery({ ...args, tries: tries + 1 });
|
|
573
552
|
}
|
|
574
|
-
if (error instanceof errors_ts_1.AgentError) {
|
|
575
|
-
// if it's an error that we have thrown, just throw it as is
|
|
576
|
-
throw error;
|
|
577
|
-
}
|
|
578
|
-
// if it's an error that we have not thrown, wrap it in a TransportError
|
|
579
553
|
throw errors_ts_1.TransportError.fromCode(new errors_ts_1.HttpFetchErrorCode(error));
|
|
580
554
|
}
|
|
555
|
+
const headers = (0, transforms_ts_1.httpHeadersTransform)(fetchResponse.headers);
|
|
556
|
+
if (fetchResponse.status !== HTTP_STATUS_OK) {
|
|
557
|
+
const responseText = await fetchResponse.text();
|
|
558
|
+
if (isIngressExpiryInvalidResponse(responseText)) {
|
|
559
|
+
throw errors_ts_1.InputError.fromCode(new errors_ts_1.IngressExpiryInvalidErrorCode(responseText, this.#maxIngressExpiryInMinutes));
|
|
560
|
+
}
|
|
561
|
+
if (tries < this.#retryTimes) {
|
|
562
|
+
return await this.#requestAndRetryQuery({ ...args, tries: tries + 1 });
|
|
563
|
+
}
|
|
564
|
+
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.HttpErrorCode(fetchResponse.status, fetchResponse.statusText, headers, responseText));
|
|
565
|
+
}
|
|
566
|
+
const queryResponse = cbor.decode((0, buffer_ts_1.uint8FromBufLike)(await fetchResponse.arrayBuffer()));
|
|
567
|
+
const response = {
|
|
568
|
+
...queryResponse,
|
|
569
|
+
httpDetails: {
|
|
570
|
+
ok: fetchResponse.ok,
|
|
571
|
+
status: fetchResponse.status,
|
|
572
|
+
statusText: fetchResponse.statusText,
|
|
573
|
+
headers,
|
|
574
|
+
},
|
|
575
|
+
requestId,
|
|
576
|
+
};
|
|
581
577
|
// Skip timestamp verification if the user has set verifyQuerySignatures to false
|
|
582
578
|
if (!this.#verifyQuerySignatures) {
|
|
583
579
|
return response;
|
|
@@ -595,6 +591,7 @@ class HttpAgent {
|
|
|
595
591
|
requestId,
|
|
596
592
|
signatureTimestampMs,
|
|
597
593
|
});
|
|
594
|
+
await this.syncTime(ecid);
|
|
598
595
|
return await this.#requestAndRetryQuery({ ...args, tries: tries + 1 });
|
|
599
596
|
}
|
|
600
597
|
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.CertificateOutdatedErrorCode(this.#maxIngressExpiryInMinutes, requestId, tries));
|
|
@@ -653,11 +650,10 @@ class HttpAgent {
|
|
|
653
650
|
};
|
|
654
651
|
}
|
|
655
652
|
const responseText = await response.text();
|
|
656
|
-
if (response.status === HTTP_STATUS_NOT_FOUND && response.url.includes('api/
|
|
657
|
-
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.
|
|
653
|
+
if (response.status === HTTP_STATUS_NOT_FOUND && response.url.includes('api/v4')) {
|
|
654
|
+
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.HttpV4ApiNotSupportedErrorCode());
|
|
658
655
|
}
|
|
659
|
-
|
|
660
|
-
if (responseText.startsWith('Invalid request expiry: ')) {
|
|
656
|
+
if (isIngressExpiryInvalidResponse(responseText)) {
|
|
661
657
|
throw errors_ts_1.InputError.fromCode(new errors_ts_1.IngressExpiryInvalidErrorCode(responseText, this.#maxIngressExpiryInMinutes));
|
|
662
658
|
}
|
|
663
659
|
if (tries < this.#retryTimes) {
|
|
@@ -721,17 +717,17 @@ class HttpAgent {
|
|
|
721
717
|
...query,
|
|
722
718
|
};
|
|
723
719
|
};
|
|
724
|
-
const
|
|
725
|
-
const
|
|
726
|
-
if (
|
|
727
|
-
return
|
|
720
|
+
const getSubnetNodeKeys = async () => {
|
|
721
|
+
const cachedSubnetNodeKeys = this.#subnetKeys.get(ecid.toString());
|
|
722
|
+
if (cachedSubnetNodeKeys) {
|
|
723
|
+
return cachedSubnetNodeKeys;
|
|
728
724
|
}
|
|
729
725
|
await this.fetchSubnetKeys(ecid.toString());
|
|
730
|
-
const
|
|
731
|
-
if (!
|
|
726
|
+
const subnetNodeKeys = this.#subnetKeys.get(ecid.toString());
|
|
727
|
+
if (!subnetNodeKeys) {
|
|
732
728
|
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.MissingSignatureErrorCode());
|
|
733
729
|
}
|
|
734
|
-
return
|
|
730
|
+
return subnetNodeKeys;
|
|
735
731
|
};
|
|
736
732
|
try {
|
|
737
733
|
if (!this.#verifyQuerySignatures) {
|
|
@@ -739,21 +735,30 @@ class HttpAgent {
|
|
|
739
735
|
return await makeQuery();
|
|
740
736
|
}
|
|
741
737
|
// Make query and fetch subnet keys in parallel
|
|
742
|
-
const [queryWithDetails,
|
|
738
|
+
const [queryWithDetails, subnetNodeKeys] = await Promise.all([
|
|
739
|
+
makeQuery(),
|
|
740
|
+
getSubnetNodeKeys(),
|
|
741
|
+
]);
|
|
743
742
|
try {
|
|
744
|
-
return this.#verifyQueryResponse(queryWithDetails,
|
|
743
|
+
return this.#verifyQueryResponse(queryWithDetails, subnetNodeKeys);
|
|
745
744
|
}
|
|
746
745
|
catch {
|
|
747
746
|
// In case the node signatures have changed, refresh the subnet keys and try again
|
|
748
747
|
this.log.warn('Query response verification failed. Retrying with fresh subnet keys.');
|
|
749
748
|
this.#subnetKeys.delete(ecid.toString());
|
|
750
|
-
const
|
|
751
|
-
return this.#verifyQueryResponse(queryWithDetails,
|
|
749
|
+
const updatedSubnetNodeKeys = await getSubnetNodeKeys();
|
|
750
|
+
return this.#verifyQueryResponse(queryWithDetails, updatedSubnetNodeKeys);
|
|
752
751
|
}
|
|
753
752
|
}
|
|
754
753
|
catch (error) {
|
|
755
754
|
let queryError;
|
|
756
755
|
if (error instanceof errors_ts_1.AgentError) {
|
|
756
|
+
if (error.hasCode(errors_ts_1.IngressExpiryInvalidErrorCode) && !this.#hasSyncedTime) {
|
|
757
|
+
// if there is an ingress expiry error and the time has not been synced yet,
|
|
758
|
+
// sync time with the network and try again
|
|
759
|
+
await this.syncTime(ecid);
|
|
760
|
+
return this.query(canisterId, fields, identity);
|
|
761
|
+
}
|
|
757
762
|
// override the error code to include the request details
|
|
758
763
|
error.code.requestContext = {
|
|
759
764
|
requestId,
|
|
@@ -773,7 +778,7 @@ class HttpAgent {
|
|
|
773
778
|
/**
|
|
774
779
|
* See https://internetcomputer.org/docs/current/references/ic-interface-spec/#http-query for details on validation
|
|
775
780
|
* @param queryResponse - The response from the query
|
|
776
|
-
* @param
|
|
781
|
+
* @param subnetNodeKeys - The subnet node keys
|
|
777
782
|
* @returns ApiQueryResponse
|
|
778
783
|
*/
|
|
779
784
|
#verifyQueryResponse;
|
|
@@ -823,7 +828,6 @@ class HttpAgent {
|
|
|
823
828
|
if (request) {
|
|
824
829
|
// This is a pre-signed request
|
|
825
830
|
transformedRequest = request;
|
|
826
|
-
requestId = (0, request_id_ts_1.requestIdOf)(transformedRequest);
|
|
827
831
|
}
|
|
828
832
|
else {
|
|
829
833
|
// This is fields, we need to create a request
|
|
@@ -835,8 +839,23 @@ class HttpAgent {
|
|
|
835
839
|
}
|
|
836
840
|
transformedRequest = await this.createReadStateRequest(fields, identity);
|
|
837
841
|
}
|
|
838
|
-
const url = new URL(`/api/
|
|
839
|
-
this
|
|
842
|
+
const url = new URL(`/api/v3/canister/${canister.toString()}/read_state`, this.host);
|
|
843
|
+
return await this.#readStateInner(url, { canisterId: canister }, transformedRequest, requestId);
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Reads the state of a subnet from the `/api/v3/subnet/{subnetId}/read_state` endpoint.
|
|
847
|
+
* @param subnetId The ID of the subnet to read the state of. If you have a canister ID, you can use {@link HttpAgent.getSubnetIdFromCanister | getSubnetIdFromCanister} to get the subnet ID.
|
|
848
|
+
* @param options The options for the read state request.
|
|
849
|
+
* @returns The response from the read state request.
|
|
850
|
+
*/
|
|
851
|
+
async readSubnetState(subnetId, options) {
|
|
852
|
+
await this.#rootKeyGuard();
|
|
853
|
+
const subnet = _principal_1.Principal.from(subnetId);
|
|
854
|
+
const url = new URL(`/api/v3/subnet/${subnet.toString()}/read_state`, this.host);
|
|
855
|
+
const transformedRequest = await this.createReadStateRequest(options, this.#identity ?? undefined);
|
|
856
|
+
return await this.#readStateInner(url, { subnetId: subnet }, transformedRequest);
|
|
857
|
+
}
|
|
858
|
+
async #readStateInner(url, principal, transformedRequest, requestId) {
|
|
840
859
|
const backoff = this.#backoffStrategy();
|
|
841
860
|
try {
|
|
842
861
|
const { responseBodyBytes } = await this.#requestAndRetry({
|
|
@@ -849,15 +868,28 @@ class HttpAgent {
|
|
|
849
868
|
tries: 0,
|
|
850
869
|
});
|
|
851
870
|
const decodedResponse = cbor.decode(responseBodyBytes);
|
|
852
|
-
this.log.print('Read state response:', decodedResponse);
|
|
853
871
|
return decodedResponse;
|
|
854
872
|
}
|
|
855
873
|
catch (error) {
|
|
856
874
|
let readStateError;
|
|
857
875
|
if (error instanceof errors_ts_1.AgentError) {
|
|
876
|
+
if (error.hasCode(errors_ts_1.IngressExpiryInvalidErrorCode) && !this.#hasSyncedTime) {
|
|
877
|
+
// if there is an ingress expiry error and the time has not been synced yet,
|
|
878
|
+
// sync time with the network and try again
|
|
879
|
+
if ('canisterId' in principal) {
|
|
880
|
+
await this.syncTime(principal.canisterId);
|
|
881
|
+
}
|
|
882
|
+
else if ('subnetId' in principal) {
|
|
883
|
+
await this.syncTimeWithSubnet(principal.subnetId);
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
throw errors_ts_1.UNREACHABLE_ERROR;
|
|
887
|
+
}
|
|
888
|
+
return await this.#readStateInner(url, principal, transformedRequest, requestId);
|
|
889
|
+
}
|
|
858
890
|
// override the error code to include the request details
|
|
859
891
|
error.code.requestContext = {
|
|
860
|
-
requestId,
|
|
892
|
+
requestId: requestId ?? (0, request_id_ts_1.requestIdOf)(transformedRequest),
|
|
861
893
|
senderPubKey: transformedRequest.body.sender_pubkey,
|
|
862
894
|
senderSignature: transformedRequest.body.sender_sig,
|
|
863
895
|
ingressExpiry: transformedRequest.body.content.ingress_expiry,
|
|
@@ -899,7 +931,7 @@ class HttpAgent {
|
|
|
899
931
|
return 0;
|
|
900
932
|
}
|
|
901
933
|
/**
|
|
902
|
-
* Allows agent to sync its time with the network. Can be called during
|
|
934
|
+
* Allows agent to sync its time with the network. Can be called during initialization or mid-lifecycle if the device's clock has drifted away from the network time. This is necessary to set the Expiry for a request
|
|
903
935
|
* @param {Principal} canisterIdOverride - Pass a canister ID if you need to sync the time with a particular subnet. Uses the ICP ledger canister by default.
|
|
904
936
|
*/
|
|
905
937
|
async syncTime(canisterIdOverride) {
|
|
@@ -936,17 +968,7 @@ class HttpAgent {
|
|
|
936
968
|
return date.getTime();
|
|
937
969
|
}
|
|
938
970
|
}, []));
|
|
939
|
-
|
|
940
|
-
return typeof current === 'number' && current > max ? current : max;
|
|
941
|
-
}, 0);
|
|
942
|
-
if (maxReplicaTime > 0) {
|
|
943
|
-
this.#timeDiffMsecs = maxReplicaTime - callTime;
|
|
944
|
-
this.#hasSyncedTime = true;
|
|
945
|
-
this.log.notify({
|
|
946
|
-
message: `Syncing time: offset of ${this.#timeDiffMsecs}`,
|
|
947
|
-
level: 'info',
|
|
948
|
-
});
|
|
949
|
-
}
|
|
971
|
+
this.#setTimeDiffMsecs(callTime, replicaTimes);
|
|
950
972
|
}
|
|
951
973
|
catch (error) {
|
|
952
974
|
const syncTimeError = error instanceof errors_ts_1.AgentError
|
|
@@ -960,6 +982,57 @@ class HttpAgent {
|
|
|
960
982
|
this.#syncTimePromise = null;
|
|
961
983
|
});
|
|
962
984
|
}
|
|
985
|
+
/**
|
|
986
|
+
* Allows agent to sync its time with the network.
|
|
987
|
+
* @param {Principal} subnetId - Pass the subnet ID you need to sync the time with.
|
|
988
|
+
*/
|
|
989
|
+
async syncTimeWithSubnet(subnetId) {
|
|
990
|
+
await this.#rootKeyGuard();
|
|
991
|
+
const callTime = Date.now();
|
|
992
|
+
try {
|
|
993
|
+
const anonymousAgent = HttpAgent.createSync({
|
|
994
|
+
identity: new auth_ts_1.AnonymousIdentity(),
|
|
995
|
+
host: this.host.toString(),
|
|
996
|
+
fetch: this.#fetch,
|
|
997
|
+
retryTimes: 0,
|
|
998
|
+
rootKey: this.rootKey ?? undefined,
|
|
999
|
+
shouldSyncTime: false,
|
|
1000
|
+
});
|
|
1001
|
+
const replicaTimes = await Promise.all(Array(3)
|
|
1002
|
+
.fill(null)
|
|
1003
|
+
.map(async () => {
|
|
1004
|
+
const status = await (0, index_ts_2.request)({
|
|
1005
|
+
subnetId,
|
|
1006
|
+
agent: anonymousAgent,
|
|
1007
|
+
paths: ['time'],
|
|
1008
|
+
disableCertificateTimeVerification: true, // avoid recursive calls to syncTime
|
|
1009
|
+
});
|
|
1010
|
+
const date = status.get('time');
|
|
1011
|
+
if (date instanceof Date) {
|
|
1012
|
+
return date.getTime();
|
|
1013
|
+
}
|
|
1014
|
+
}, []));
|
|
1015
|
+
this.#setTimeDiffMsecs(callTime, replicaTimes);
|
|
1016
|
+
}
|
|
1017
|
+
catch (error) {
|
|
1018
|
+
const syncTimeError = error instanceof errors_ts_1.AgentError ? error : errors_ts_1.UnknownError.fromCode(new errors_ts_1.UnexpectedErrorCode(error));
|
|
1019
|
+
this.log.error('Caught exception while attempting to sync time with subnet', syncTimeError);
|
|
1020
|
+
throw syncTimeError;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
#setTimeDiffMsecs(callTime, replicaTimes) {
|
|
1024
|
+
const maxReplicaTime = replicaTimes.reduce((max, current) => {
|
|
1025
|
+
return typeof current === 'number' && current > max ? current : max;
|
|
1026
|
+
}, 0);
|
|
1027
|
+
if (maxReplicaTime > 0) {
|
|
1028
|
+
this.#timeDiffMsecs = maxReplicaTime - callTime;
|
|
1029
|
+
this.#hasSyncedTime = true;
|
|
1030
|
+
this.log.notify({
|
|
1031
|
+
message: `Syncing time: offset of ${this.#timeDiffMsecs}`,
|
|
1032
|
+
level: 'info',
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
963
1036
|
async status() {
|
|
964
1037
|
const headers = this.#credentials
|
|
965
1038
|
? {
|
|
@@ -1021,18 +1094,51 @@ class HttpAgent {
|
|
|
1021
1094
|
async fetchSubnetKeys(canisterId) {
|
|
1022
1095
|
const effectiveCanisterId = _principal_1.Principal.from(canisterId);
|
|
1023
1096
|
await this.#asyncGuard(effectiveCanisterId);
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
-
paths: ['subnet'],
|
|
1097
|
+
const rootKey = this.rootKey;
|
|
1098
|
+
const canisterReadState = await this.readState(effectiveCanisterId, {
|
|
1099
|
+
paths: [[(0, utils_1.utf8ToBytes)('subnet')]],
|
|
1100
|
+
});
|
|
1101
|
+
const canisterCertificate = await certificate_ts_1.Certificate.create({
|
|
1102
|
+
certificate: canisterReadState.certificate,
|
|
1103
|
+
rootKey,
|
|
1104
|
+
principal: { canisterId: effectiveCanisterId },
|
|
1027
1105
|
agent: this,
|
|
1028
1106
|
});
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1107
|
+
if (!canisterCertificate.cert.delegation) {
|
|
1108
|
+
const subnetId = _principal_1.Principal.selfAuthenticating(rootKey);
|
|
1109
|
+
const canisterInRange = (0, certificate_ts_1.check_canister_ranges)({
|
|
1110
|
+
canisterId: effectiveCanisterId,
|
|
1111
|
+
subnetId,
|
|
1112
|
+
tree: canisterCertificate.cert.tree,
|
|
1113
|
+
});
|
|
1114
|
+
if (!canisterInRange) {
|
|
1115
|
+
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.CertificateNotAuthorizedErrorCode(effectiveCanisterId, subnetId));
|
|
1116
|
+
}
|
|
1033
1117
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1118
|
+
const subnetId = (0, certificate_ts_1.getSubnetIdFromCertificate)(canisterCertificate.cert, rootKey);
|
|
1119
|
+
const nodeKeys = (0, readState_ts_1.lookupNodeKeysFromCertificate)(canisterCertificate.cert, subnetId);
|
|
1120
|
+
this.#subnetKeys.set(effectiveCanisterId.toText(), nodeKeys);
|
|
1121
|
+
return nodeKeys;
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Returns the subnet ID for a given canister ID, by looking at the certificate delegation
|
|
1125
|
+
* returned by the canister's state obtained by requesting the `/time` path with {@link HttpAgent.readState | readState}.
|
|
1126
|
+
* @param canisterId The canister ID to get the subnet ID for.
|
|
1127
|
+
* @returns The subnet ID for the given canister ID.
|
|
1128
|
+
*/
|
|
1129
|
+
async getSubnetIdFromCanister(canisterId) {
|
|
1130
|
+
const effectiveCanisterId = _principal_1.Principal.from(canisterId);
|
|
1131
|
+
await this.#asyncGuard(effectiveCanisterId);
|
|
1132
|
+
const canisterReadState = await this.readState(effectiveCanisterId, {
|
|
1133
|
+
paths: [[(0, utils_1.utf8ToBytes)('time')]],
|
|
1134
|
+
});
|
|
1135
|
+
const canisterCertificate = await certificate_ts_1.Certificate.create({
|
|
1136
|
+
certificate: canisterReadState.certificate,
|
|
1137
|
+
rootKey: this.rootKey,
|
|
1138
|
+
principal: { canisterId: effectiveCanisterId },
|
|
1139
|
+
agent: this,
|
|
1140
|
+
});
|
|
1141
|
+
return (0, certificate_ts_1.getSubnetIdFromCertificate)(canisterCertificate.cert, this.rootKey);
|
|
1036
1142
|
}
|
|
1037
1143
|
_transform(request) {
|
|
1038
1144
|
let p = Promise.resolve(request);
|
|
@@ -1076,4 +1182,13 @@ function calculateIngressExpiry(maxIngressExpiryInMinutes, timeDiffMsecs) {
|
|
|
1076
1182
|
const ingressExpiryMs = maxIngressExpiryInMinutes * MINUTE_TO_MSECS;
|
|
1077
1183
|
return transforms_ts_1.Expiry.fromDeltaInMilliseconds(ingressExpiryMs, timeDiffMsecs);
|
|
1078
1184
|
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Checks if the response text is an ingress expiry invalid response.
|
|
1187
|
+
* @see https://github.com/dfinity/ic/blob/23d5990bfc5277c32e54f0087b5a38fa412171e1/rs/validator/src/ingress_validation.rs#L233
|
|
1188
|
+
* @param responseText The response body as string.
|
|
1189
|
+
* @returns `true` if the response text is an ingress expiry invalid response, `false` otherwise.
|
|
1190
|
+
*/
|
|
1191
|
+
function isIngressExpiryInvalidResponse(responseText) {
|
|
1192
|
+
return responseText.includes('Invalid request expiry: ');
|
|
1193
|
+
}
|
|
1079
1194
|
//# sourceMappingURL=index.js.map
|