@icp-sdk/core 5.0.0 → 5.2.0-beta.0
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/actor.d.ts +15 -1
- package/lib/cjs/agent/actor.d.ts.map +1 -1
- package/lib/cjs/agent/actor.js +37 -91
- package/lib/cjs/agent/actor.js.map +1 -1
- package/lib/cjs/agent/agent/api.d.ts +29 -6
- package/lib/cjs/agent/agent/api.d.ts.map +1 -1
- package/lib/cjs/agent/agent/api.js.map +1 -1
- package/lib/cjs/agent/agent/http/expiry.d.ts +36 -0
- package/lib/cjs/agent/agent/http/expiry.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/expiry.js +92 -0
- package/lib/cjs/agent/agent/http/expiry.js.map +1 -0
- package/lib/cjs/agent/agent/http/index.d.ts +28 -2
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/index.js +182 -90
- package/lib/cjs/agent/agent/http/index.js.map +1 -1
- package/lib/cjs/agent/agent/http/transforms.d.ts +1 -35
- package/lib/cjs/agent/agent/http/transforms.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/transforms.js +6 -90
- package/lib/cjs/agent/agent/http/transforms.js.map +1 -1
- package/lib/cjs/agent/agent/http/types.d.ts +1 -1
- package/lib/cjs/agent/agent/http/types.d.ts.map +1 -1
- package/lib/cjs/agent/auth.d.ts +1 -1
- package/lib/cjs/agent/auth.d.ts.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.d.ts +5 -4
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.js +6 -10
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
- package/lib/cjs/agent/cbor.js +2 -2
- package/lib/cjs/agent/cbor.js.map +1 -1
- package/lib/cjs/agent/certificate.d.ts +4 -4
- package/lib/cjs/agent/certificate.d.ts.map +1 -1
- package/lib/cjs/agent/certificate.js +6 -10
- package/lib/cjs/agent/certificate.js.map +1 -1
- package/lib/cjs/agent/constants.d.ts +4 -4
- package/lib/cjs/agent/constants.d.ts.map +1 -1
- package/lib/cjs/agent/der.d.ts.map +1 -1
- package/lib/cjs/agent/der.js +26 -21
- package/lib/cjs/agent/der.js.map +1 -1
- package/lib/cjs/agent/errors.d.ts +45 -19
- package/lib/cjs/agent/errors.d.ts.map +1 -1
- package/lib/cjs/agent/errors.js +58 -18
- package/lib/cjs/agent/errors.js.map +1 -1
- package/lib/cjs/agent/index.d.ts +1 -0
- package/lib/cjs/agent/index.d.ts.map +1 -1
- package/lib/cjs/agent/index.js.map +1 -1
- package/lib/cjs/agent/observable.d.ts +1 -1
- package/lib/cjs/agent/observable.d.ts.map +1 -1
- package/lib/cjs/agent/polling/backoff.d.ts +7 -7
- package/lib/cjs/agent/polling/backoff.d.ts.map +1 -1
- package/lib/cjs/agent/polling/backoff.js +3 -5
- package/lib/cjs/agent/polling/backoff.js.map +1 -1
- package/lib/cjs/agent/polling/index.d.ts +11 -10
- package/lib/cjs/agent/polling/index.d.ts.map +1 -1
- package/lib/cjs/agent/polling/index.js +8 -6
- package/lib/cjs/agent/polling/index.js.map +1 -1
- package/lib/cjs/agent/polling/strategy.d.ts +2 -5
- package/lib/cjs/agent/polling/strategy.d.ts.map +1 -1
- package/lib/cjs/agent/polling/strategy.js.map +1 -1
- package/lib/cjs/agent/polling/types.d.ts +18 -0
- package/lib/cjs/agent/polling/types.d.ts.map +1 -0
- package/lib/cjs/agent/polling/types.js +3 -0
- package/lib/cjs/agent/polling/types.js.map +1 -0
- package/lib/cjs/agent/public_key.d.ts +1 -1
- package/lib/cjs/agent/public_key.d.ts.map +1 -1
- package/lib/cjs/agent/request_id.d.ts.map +1 -1
- package/lib/cjs/agent/request_id.js +7 -7
- package/lib/cjs/agent/request_id.js.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.d.ts +5 -4
- package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.js +6 -10
- package/lib/cjs/agent/subnetStatus/index.js.map +1 -1
- package/lib/cjs/agent/utils/buffer.d.ts.map +1 -1
- package/lib/cjs/agent/utils/buffer.js +4 -2
- package/lib/cjs/agent/utils/buffer.js.map +1 -1
- package/lib/cjs/agent/utils/certificateReject.d.ts +11 -0
- package/lib/cjs/agent/utils/certificateReject.d.ts.map +1 -0
- package/lib/cjs/agent/utils/certificateReject.js +19 -0
- package/lib/cjs/agent/utils/certificateReject.js.map +1 -0
- package/lib/cjs/agent/utils/createExpirableStore.d.ts +23 -0
- package/lib/cjs/agent/utils/createExpirableStore.d.ts.map +1 -0
- package/lib/cjs/agent/utils/createExpirableStore.js +18 -0
- package/lib/cjs/agent/utils/createExpirableStore.js.map +1 -0
- package/lib/cjs/agent/utils/expirableStore.d.ts +39 -0
- package/lib/cjs/agent/utils/expirableStore.d.ts.map +1 -0
- package/lib/cjs/agent/utils/expirableStore.js +14 -0
- package/lib/cjs/agent/utils/expirableStore.js.map +1 -0
- package/lib/cjs/agent/utils/inMemoryExpirableStore.d.ts +14 -0
- package/lib/cjs/agent/utils/inMemoryExpirableStore.d.ts.map +1 -0
- package/lib/cjs/agent/utils/inMemoryExpirableStore.js +46 -0
- package/lib/cjs/agent/utils/inMemoryExpirableStore.js.map +1 -0
- package/lib/cjs/agent/utils/indexedDBExpirableStore.d.ts +28 -0
- package/lib/cjs/agent/utils/indexedDBExpirableStore.d.ts.map +1 -0
- package/lib/cjs/agent/utils/indexedDBExpirableStore.js +139 -0
- package/lib/cjs/agent/utils/indexedDBExpirableStore.js.map +1 -0
- package/lib/cjs/agent/utils/readState.d.ts +3 -3
- package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
- package/lib/cjs/candid/candid-core.d.ts +1 -1
- package/lib/cjs/candid/candid-core.d.ts.map +1 -1
- package/lib/cjs/candid/candid-core.js +7 -9
- package/lib/cjs/candid/candid-core.js.map +1 -1
- package/lib/cjs/candid/candid-ui.d.ts.map +1 -1
- package/lib/cjs/candid/candid-ui.js +8 -24
- package/lib/cjs/candid/candid-ui.js.map +1 -1
- package/lib/cjs/candid/idl.d.ts +14 -1
- package/lib/cjs/candid/idl.d.ts.map +1 -1
- package/lib/cjs/candid/idl.js +164 -125
- 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 +1 -3
- package/lib/cjs/candid/utils/leb128.js.map +1 -1
- package/lib/cjs/identity/identity/delegation.d.ts +4 -3
- package/lib/cjs/identity/identity/delegation.d.ts.map +1 -1
- package/lib/cjs/identity/identity/delegation.js +3 -3
- package/lib/cjs/identity/identity/delegation.js.map +1 -1
- package/lib/cjs/identity/identity/ecdsa.d.ts +2 -2
- package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -1
- package/lib/cjs/identity/identity/ecdsa.js +2 -4
- package/lib/cjs/identity/identity/ecdsa.js.map +1 -1
- package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -1
- package/lib/cjs/identity/identity/ed25519.js +9 -10
- package/lib/cjs/identity/identity/ed25519.js.map +1 -1
- package/lib/cjs/identity/identity/partial.d.ts +1 -1
- package/lib/cjs/identity/identity/partial.d.ts.map +1 -1
- package/lib/cjs/identity/identity/webauthn.js +4 -5
- package/lib/cjs/identity/identity/webauthn.js.map +1 -1
- package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/der.js +27 -22
- package/lib/cjs/identity/secp256k1/der.js.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.js +1 -1
- package/lib/cjs/identity/secp256k1/pem.js.map +1 -1
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/secp256k1.js +6 -6
- package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -1
- package/lib/cjs/principal/principal.d.ts +2 -2
- package/lib/cjs/principal/principal.d.ts.map +1 -1
- package/lib/cjs/principal/principal.js +10 -6
- package/lib/cjs/principal/principal.js.map +1 -1
- package/lib/esm/agent/actor.d.ts +15 -1
- package/lib/esm/agent/actor.d.ts.map +1 -1
- package/lib/esm/agent/actor.js +40 -94
- package/lib/esm/agent/actor.js.map +1 -1
- package/lib/esm/agent/agent/api.d.ts +29 -6
- package/lib/esm/agent/agent/api.d.ts.map +1 -1
- package/lib/esm/agent/agent/api.js.map +1 -1
- package/lib/esm/agent/agent/http/expiry.d.ts +36 -0
- package/lib/esm/agent/agent/http/expiry.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/expiry.js +88 -0
- package/lib/esm/agent/agent/http/expiry.js.map +1 -0
- package/lib/esm/agent/agent/http/index.d.ts +28 -2
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/index.js +185 -93
- package/lib/esm/agent/agent/http/index.js.map +1 -1
- package/lib/esm/agent/agent/http/transforms.d.ts +1 -35
- package/lib/esm/agent/agent/http/transforms.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/transforms.js +2 -87
- package/lib/esm/agent/agent/http/transforms.js.map +1 -1
- package/lib/esm/agent/agent/http/types.d.ts +1 -1
- package/lib/esm/agent/agent/http/types.d.ts.map +1 -1
- package/lib/esm/agent/auth.d.ts +1 -1
- package/lib/esm/agent/auth.d.ts.map +1 -1
- package/lib/esm/agent/canister-env/index.d.ts +2 -2
- package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts +5 -4
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/canisterStatus/index.js +6 -10
- package/lib/esm/agent/canisterStatus/index.js.map +1 -1
- package/lib/esm/agent/cbor.js +1 -1
- package/lib/esm/agent/cbor.js.map +1 -1
- package/lib/esm/agent/certificate.d.ts +4 -4
- package/lib/esm/agent/certificate.d.ts.map +1 -1
- package/lib/esm/agent/certificate.js +6 -10
- package/lib/esm/agent/certificate.js.map +1 -1
- package/lib/esm/agent/constants.d.ts +4 -4
- package/lib/esm/agent/constants.d.ts.map +1 -1
- package/lib/esm/agent/der.d.ts.map +1 -1
- package/lib/esm/agent/der.js +26 -21
- package/lib/esm/agent/der.js.map +1 -1
- package/lib/esm/agent/errors.d.ts +45 -19
- package/lib/esm/agent/errors.d.ts.map +1 -1
- package/lib/esm/agent/errors.js +54 -16
- package/lib/esm/agent/errors.js.map +1 -1
- package/lib/esm/agent/index.d.ts +1 -0
- package/lib/esm/agent/index.d.ts.map +1 -1
- package/lib/esm/agent/index.js.map +1 -1
- package/lib/esm/agent/observable.d.ts +1 -1
- package/lib/esm/agent/observable.d.ts.map +1 -1
- package/lib/esm/agent/polling/backoff.d.ts +7 -7
- package/lib/esm/agent/polling/backoff.d.ts.map +1 -1
- package/lib/esm/agent/polling/backoff.js +3 -5
- package/lib/esm/agent/polling/backoff.js.map +1 -1
- package/lib/esm/agent/polling/index.d.ts +11 -10
- package/lib/esm/agent/polling/index.d.ts.map +1 -1
- package/lib/esm/agent/polling/index.js +9 -7
- package/lib/esm/agent/polling/index.js.map +1 -1
- package/lib/esm/agent/polling/strategy.d.ts +2 -5
- package/lib/esm/agent/polling/strategy.d.ts.map +1 -1
- package/lib/esm/agent/polling/strategy.js.map +1 -1
- package/lib/esm/agent/polling/types.d.ts +18 -0
- package/lib/esm/agent/polling/types.d.ts.map +1 -0
- package/lib/esm/agent/polling/types.js +2 -0
- package/lib/esm/agent/polling/types.js.map +1 -0
- package/lib/esm/agent/public_key.d.ts +1 -1
- package/lib/esm/agent/public_key.d.ts.map +1 -1
- package/lib/esm/agent/request_id.d.ts.map +1 -1
- package/lib/esm/agent/request_id.js +7 -7
- package/lib/esm/agent/request_id.js.map +1 -1
- package/lib/esm/agent/subnetStatus/index.d.ts +5 -4
- package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/subnetStatus/index.js +6 -10
- package/lib/esm/agent/subnetStatus/index.js.map +1 -1
- package/lib/esm/agent/utils/buffer.d.ts.map +1 -1
- package/lib/esm/agent/utils/buffer.js +4 -2
- package/lib/esm/agent/utils/buffer.js.map +1 -1
- package/lib/esm/agent/utils/certificateReject.d.ts +11 -0
- package/lib/esm/agent/utils/certificateReject.d.ts.map +1 -0
- package/lib/esm/agent/utils/certificateReject.js +16 -0
- package/lib/esm/agent/utils/certificateReject.js.map +1 -0
- package/lib/esm/agent/utils/createExpirableStore.d.ts +23 -0
- package/lib/esm/agent/utils/createExpirableStore.d.ts.map +1 -0
- package/lib/esm/agent/utils/createExpirableStore.js +15 -0
- package/lib/esm/agent/utils/createExpirableStore.js.map +1 -0
- package/lib/esm/agent/utils/expirableStore.d.ts +39 -0
- package/lib/esm/agent/utils/expirableStore.d.ts.map +1 -0
- package/lib/esm/agent/utils/expirableStore.js +11 -0
- package/lib/esm/agent/utils/expirableStore.js.map +1 -0
- package/lib/esm/agent/utils/inMemoryExpirableStore.d.ts +14 -0
- package/lib/esm/agent/utils/inMemoryExpirableStore.d.ts.map +1 -0
- package/lib/esm/agent/utils/inMemoryExpirableStore.js +42 -0
- package/lib/esm/agent/utils/inMemoryExpirableStore.js.map +1 -0
- package/lib/esm/agent/utils/indexedDBExpirableStore.d.ts +28 -0
- package/lib/esm/agent/utils/indexedDBExpirableStore.d.ts.map +1 -0
- package/lib/esm/agent/utils/indexedDBExpirableStore.js +135 -0
- package/lib/esm/agent/utils/indexedDBExpirableStore.js.map +1 -0
- package/lib/esm/agent/utils/readState.d.ts +3 -3
- package/lib/esm/agent/utils/readState.d.ts.map +1 -1
- package/lib/esm/candid/candid-core.d.ts +1 -1
- package/lib/esm/candid/candid-core.d.ts.map +1 -1
- package/lib/esm/candid/candid-core.js +7 -9
- package/lib/esm/candid/candid-core.js.map +1 -1
- package/lib/esm/candid/candid-ui.d.ts.map +1 -1
- package/lib/esm/candid/candid-ui.js +7 -23
- package/lib/esm/candid/candid-ui.js.map +1 -1
- package/lib/esm/candid/idl.d.ts +14 -1
- package/lib/esm/candid/idl.d.ts.map +1 -1
- package/lib/esm/candid/idl.js +162 -124
- 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 +1 -3
- package/lib/esm/candid/utils/leb128.js.map +1 -1
- package/lib/esm/identity/identity/delegation.d.ts +4 -3
- package/lib/esm/identity/identity/delegation.d.ts.map +1 -1
- package/lib/esm/identity/identity/delegation.js +3 -3
- package/lib/esm/identity/identity/delegation.js.map +1 -1
- package/lib/esm/identity/identity/ecdsa.d.ts +2 -2
- package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -1
- package/lib/esm/identity/identity/ecdsa.js +2 -4
- package/lib/esm/identity/identity/ecdsa.js.map +1 -1
- package/lib/esm/identity/identity/ed25519.d.ts.map +1 -1
- package/lib/esm/identity/identity/ed25519.js +9 -10
- package/lib/esm/identity/identity/ed25519.js.map +1 -1
- package/lib/esm/identity/identity/partial.d.ts +1 -1
- package/lib/esm/identity/identity/partial.d.ts.map +1 -1
- package/lib/esm/identity/identity/webauthn.js +4 -5
- package/lib/esm/identity/identity/webauthn.js.map +1 -1
- package/lib/esm/identity/secp256k1/der.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/der.js +27 -22
- package/lib/esm/identity/secp256k1/der.js.map +1 -1
- package/lib/esm/identity/secp256k1/pem.js +1 -1
- package/lib/esm/identity/secp256k1/pem.js.map +1 -1
- package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/secp256k1.js +6 -6
- package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -1
- package/lib/esm/principal/principal.d.ts +2 -2
- package/lib/esm/principal/principal.d.ts.map +1 -1
- package/lib/esm/principal/principal.js +10 -6
- package/lib/esm/principal/principal.js.map +1 -1
- package/package.json +14 -13
- package/src/agent/actor.ts +74 -126
- package/src/agent/agent/api.ts +36 -6
- package/src/agent/agent/http/expiry.ts +107 -0
- package/src/agent/agent/http/index.ts +262 -104
- package/src/agent/agent/http/transforms.ts +2 -106
- package/src/agent/agent/http/types.ts +1 -1
- package/src/agent/auth.ts +1 -1
- package/src/agent/canister-env/index.ts +2 -2
- package/src/agent/canisterStatus/index.ts +10 -12
- package/src/agent/cbor.ts +1 -1
- package/src/agent/certificate.ts +11 -13
- package/src/agent/der.ts +40 -19
- package/src/agent/errors.ts +85 -34
- package/src/agent/fetch_candid.ts +1 -1
- package/src/agent/index.ts +1 -0
- package/src/agent/observable.ts +1 -1
- package/src/agent/polling/backoff.ts +9 -10
- package/src/agent/polling/index.ts +14 -26
- package/src/agent/polling/strategy.ts +5 -9
- package/src/agent/polling/types.ts +28 -0
- package/src/agent/public_key.ts +1 -1
- package/src/agent/request_id.ts +15 -8
- package/src/agent/subnetStatus/index.ts +10 -12
- package/src/agent/utils/buffer.ts +6 -2
- package/src/agent/utils/certificateReject.ts +25 -0
- package/src/agent/utils/createExpirableStore.ts +31 -0
- package/src/agent/utils/expirableStore.ts +47 -0
- package/src/agent/utils/inMemoryExpirableStore.ts +49 -0
- package/src/agent/utils/indexedDBExpirableStore.ts +191 -0
- package/src/agent/utils/random.ts +2 -2
- package/src/agent/utils/readState.ts +3 -3
- package/src/candid/candid-core.ts +9 -11
- package/src/candid/candid-ui.ts +8 -16
- package/src/candid/idl.ts +210 -112
- package/src/candid/utils/leb128.ts +1 -2
- package/src/identity/identity/delegation.ts +5 -5
- package/src/identity/identity/ecdsa.ts +12 -8
- package/src/identity/identity/ed25519.ts +16 -9
- package/src/identity/identity/partial.ts +1 -1
- package/src/identity/identity/webauthn.ts +21 -21
- package/src/identity/secp256k1/der.ts +41 -20
- package/src/identity/secp256k1/pem.ts +1 -1
- package/src/identity/secp256k1/secp256k1.ts +12 -6
- package/src/principal/principal.ts +18 -8
- package/LICENSE +0 -201
- package/lib/cjs/agent/utils/expirableMap.d.ts +0 -80
- package/lib/cjs/agent/utils/expirableMap.d.ts.map +0 -1
- package/lib/cjs/agent/utils/expirableMap.js +0 -148
- package/lib/cjs/agent/utils/expirableMap.js.map +0 -1
- package/lib/esm/agent/utils/expirableMap.d.ts +0 -80
- package/lib/esm/agent/utils/expirableMap.d.ts.map +0 -1
- package/lib/esm/agent/utils/expirableMap.js +0 -144
- package/lib/esm/agent/utils/expirableMap.js.map +0 -1
- package/src/agent/utils/expirableMap.ts +0 -163
|
@@ -47,22 +47,34 @@ const index_ts_1 = require("../../canisterStatus/index.js");
|
|
|
47
47
|
const index_ts_2 = require("../../subnetStatus/index.js");
|
|
48
48
|
const readState_ts_1 = require("../../utils/readState.js");
|
|
49
49
|
const certificate_ts_1 = require("../../certificate.js");
|
|
50
|
+
const certificateReject_ts_1 = require("../../utils/certificateReject.js");
|
|
50
51
|
const ed25519_1 = require("@noble/curves/ed25519");
|
|
51
|
-
const
|
|
52
|
+
const createExpirableStore_ts_1 = require("../../utils/createExpirableStore.js");
|
|
52
53
|
const public_key_ts_1 = require("../../public_key.js");
|
|
53
54
|
const observable_ts_1 = require("../../observable.js");
|
|
54
55
|
const backoff_ts_1 = require("../../polling/backoff.js");
|
|
55
56
|
const leb_ts_1 = require("../../utils/leb.js");
|
|
57
|
+
const index_ts_3 = require("../../polling/index.js");
|
|
56
58
|
const utils_1 = require("@noble/hashes/utils");
|
|
57
59
|
const buffer_ts_1 = require("../../utils/buffer.js");
|
|
58
60
|
const constants_ts_1 = require("../../constants.js");
|
|
61
|
+
/**
|
|
62
|
+
* Possible values for the request status in the IC state tree.
|
|
63
|
+
* @see https://internetcomputer.org/docs/references/ic-interface-spec#state-tree-request-status
|
|
64
|
+
*/
|
|
59
65
|
var RequestStatusResponseStatus;
|
|
60
66
|
(function (RequestStatusResponseStatus) {
|
|
67
|
+
/** The call has made it past the endpoint into the IC's state. */
|
|
61
68
|
RequestStatusResponseStatus["Received"] = "received";
|
|
69
|
+
/** The initial effect of the call has happened or will happen. */
|
|
62
70
|
RequestStatusResponseStatus["Processing"] = "processing";
|
|
71
|
+
/** The call completed successfully; the reply is available at `/request_status/<id>/reply`. */
|
|
63
72
|
RequestStatusResponseStatus["Replied"] = "replied";
|
|
73
|
+
/** The call failed; reject code and message are available at `/request_status/<id>/reject_code` and `/request_status/<id>/reject_message`. */
|
|
64
74
|
RequestStatusResponseStatus["Rejected"] = "rejected";
|
|
75
|
+
/** The request status path is absent from the state tree, the request is unknown to the IC (never received or pruned after expiry). */
|
|
65
76
|
RequestStatusResponseStatus["Unknown"] = "unknown";
|
|
77
|
+
/** The IC has pruned the response data but remembers the request to prevent replay attacks. */
|
|
66
78
|
RequestStatusResponseStatus["Done"] = "done";
|
|
67
79
|
})(RequestStatusResponseStatus || (exports.RequestStatusResponseStatus = RequestStatusResponseStatus = {}));
|
|
68
80
|
const MINUTE_TO_MSECS = 60 * 1_000;
|
|
@@ -84,41 +96,11 @@ const ICP_API_SUB_DOMAIN = '.icp-api.io';
|
|
|
84
96
|
const HTTP_STATUS_OK = 200;
|
|
85
97
|
const HTTP_STATUS_ACCEPTED = 202;
|
|
86
98
|
const HTTP_STATUS_NOT_FOUND = 404;
|
|
87
|
-
function getDefaultFetch() {
|
|
88
|
-
let defaultFetch;
|
|
89
|
-
if (typeof window !== 'undefined') {
|
|
90
|
-
// Browser context
|
|
91
|
-
if (window.fetch) {
|
|
92
|
-
defaultFetch = window.fetch.bind(window);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
throw errors_ts_1.ExternalError.fromCode(new errors_ts_1.HttpDefaultFetchErrorCode('Fetch implementation was not available. You appear to be in a browser context, but window.fetch was not present.'));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else if (typeof global !== 'undefined') {
|
|
99
|
-
// Node context
|
|
100
|
-
if (global.fetch) {
|
|
101
|
-
defaultFetch = global.fetch.bind(global);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
throw errors_ts_1.ExternalError.fromCode(new errors_ts_1.HttpDefaultFetchErrorCode('Fetch implementation was not available. You appear to be in a Node.js context, but global.fetch was not available.'));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else if (typeof self !== 'undefined') {
|
|
108
|
-
if (self.fetch) {
|
|
109
|
-
defaultFetch = self.fetch.bind(self);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (defaultFetch) {
|
|
113
|
-
return defaultFetch;
|
|
114
|
-
}
|
|
115
|
-
throw errors_ts_1.ExternalError.fromCode(new errors_ts_1.HttpDefaultFetchErrorCode('Fetch implementation was not available. Please provide fetch to the HttpAgent constructor, or ensure it is available in the window or global context.'));
|
|
116
|
-
}
|
|
117
99
|
function determineHost(configuredHost) {
|
|
118
100
|
let host;
|
|
119
101
|
if (configuredHost !== undefined) {
|
|
120
102
|
if (!configuredHost.match(/^[a-z]+:/) && typeof window !== 'undefined') {
|
|
121
|
-
host = new URL(window.location.protocol
|
|
103
|
+
host = new URL(`${window.location.protocol}//${configuredHost}`);
|
|
122
104
|
}
|
|
123
105
|
else {
|
|
124
106
|
host = new URL(configuredHost);
|
|
@@ -141,7 +123,7 @@ function determineHost(configuredHost) {
|
|
|
141
123
|
}
|
|
142
124
|
if (location && knownHost) {
|
|
143
125
|
// If the user is on a boundary-node provided host, we can use the same host for the agent
|
|
144
|
-
host = new URL(`${location.protocol}//${knownHost}${location.port ?
|
|
126
|
+
host = new URL(`${location.protocol}//${knownHost}${location.port ? `:${location.port}` : ''}`);
|
|
145
127
|
}
|
|
146
128
|
else {
|
|
147
129
|
host = new URL('https://icp-api.io');
|
|
@@ -174,12 +156,15 @@ class HttpAgent {
|
|
|
174
156
|
#retryTimes; // Retry requests N times before erroring by default
|
|
175
157
|
#backoffStrategy;
|
|
176
158
|
#maxIngressExpiryInMinutes;
|
|
159
|
+
#subnetNodeKeyExpirableStore;
|
|
177
160
|
get #maxIngressExpiryInMs() {
|
|
178
161
|
return this.#maxIngressExpiryInMinutes * MINUTE_TO_MSECS;
|
|
179
162
|
}
|
|
180
163
|
#queryPipeline;
|
|
181
164
|
#updatePipeline;
|
|
182
|
-
|
|
165
|
+
// Tracks in-flight fetchSubnetKeys promises to deduplicate parallel requests
|
|
166
|
+
// for the same canister, preventing redundant read_state round-trips.
|
|
167
|
+
#subnetKeysFetching;
|
|
183
168
|
#verifyQuerySignatures;
|
|
184
169
|
/**
|
|
185
170
|
* @param options - Options for the HttpAgent
|
|
@@ -198,9 +183,9 @@ class HttpAgent {
|
|
|
198
183
|
this.log = new observable_ts_1.ObservableLog();
|
|
199
184
|
this.#queryPipeline = [];
|
|
200
185
|
this.#updatePipeline = [];
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
186
|
+
// Tracks in-flight fetchSubnetKeys promises to deduplicate parallel requests
|
|
187
|
+
// for the same canister, preventing redundant read_state round-trips.
|
|
188
|
+
this.#subnetKeysFetching = new Map();
|
|
204
189
|
this.#verifyQuerySignatures = true;
|
|
205
190
|
/**
|
|
206
191
|
* See https://internetcomputer.org/docs/current/references/ic-interface-spec/#http-query for details on validation
|
|
@@ -214,6 +199,10 @@ class HttpAgent {
|
|
|
214
199
|
return queryResponse;
|
|
215
200
|
}
|
|
216
201
|
const { status, signatures = [], requestId } = queryResponse;
|
|
202
|
+
const maxSignatures = subnetNodeKeys.size;
|
|
203
|
+
if (signatures.length > maxSignatures) {
|
|
204
|
+
throw errors_ts_1.ProtocolError.fromCode(new errors_ts_1.ExcessiveSignaturesErrorCode(signatures.length, maxSignatures));
|
|
205
|
+
}
|
|
217
206
|
for (const sig of signatures) {
|
|
218
207
|
const { timestamp, identity } = sig;
|
|
219
208
|
const nodeId = _principal_1.Principal.fromUint8Array(identity).toText();
|
|
@@ -222,8 +211,8 @@ class HttpAgent {
|
|
|
222
211
|
if (status === api_ts_1.QueryResponseStatus.Replied) {
|
|
223
212
|
const { reply } = queryResponse;
|
|
224
213
|
hash = (0, request_id_ts_1.hashOfMap)({
|
|
225
|
-
status
|
|
226
|
-
reply
|
|
214
|
+
status,
|
|
215
|
+
reply,
|
|
227
216
|
timestamp: BigInt(timestamp),
|
|
228
217
|
request_id: requestId,
|
|
229
218
|
});
|
|
@@ -231,10 +220,10 @@ class HttpAgent {
|
|
|
231
220
|
else if (status === api_ts_1.QueryResponseStatus.Rejected) {
|
|
232
221
|
const { reject_code, reject_message, error_code } = queryResponse;
|
|
233
222
|
hash = (0, request_id_ts_1.hashOfMap)({
|
|
234
|
-
status
|
|
235
|
-
reject_code
|
|
236
|
-
reject_message
|
|
237
|
-
error_code
|
|
223
|
+
status,
|
|
224
|
+
reject_code,
|
|
225
|
+
reject_message,
|
|
226
|
+
error_code,
|
|
238
227
|
timestamp: BigInt(timestamp),
|
|
239
228
|
request_id: requestId,
|
|
240
229
|
});
|
|
@@ -256,7 +245,16 @@ class HttpAgent {
|
|
|
256
245
|
return queryResponse;
|
|
257
246
|
};
|
|
258
247
|
this.config = options;
|
|
259
|
-
|
|
248
|
+
if (options.fetch) {
|
|
249
|
+
this.#fetch = options.fetch;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
const globalFetch = globalThis.fetch;
|
|
253
|
+
if (typeof globalFetch !== 'function') {
|
|
254
|
+
throw errors_ts_1.InputError.fromCode(new errors_ts_1.MissingFetchErrorCode());
|
|
255
|
+
}
|
|
256
|
+
this.#fetch = globalFetch.bind(globalThis);
|
|
257
|
+
}
|
|
260
258
|
this.#fetchOptions = options.fetchOptions;
|
|
261
259
|
this.#callOptions = options.callOptions;
|
|
262
260
|
this.#shouldFetchRootKey = options.shouldFetchRootKey ?? false;
|
|
@@ -273,9 +271,26 @@ class HttpAgent {
|
|
|
273
271
|
}
|
|
274
272
|
const host = determineHost(options.host);
|
|
275
273
|
this.host = new URL(host);
|
|
274
|
+
// Rewrite to avoid redirects and normalize the host before using it for namespacing caches
|
|
275
|
+
if (this.host.hostname.endsWith(IC0_SUB_DOMAIN)) {
|
|
276
|
+
this.host.hostname = IC0_DOMAIN;
|
|
277
|
+
}
|
|
278
|
+
else if (this.host.hostname.endsWith(ICP0_SUB_DOMAIN)) {
|
|
279
|
+
this.host.hostname = ICP0_DOMAIN;
|
|
280
|
+
}
|
|
281
|
+
else if (this.host.hostname.endsWith(ICP_API_SUB_DOMAIN)) {
|
|
282
|
+
this.host.hostname = ICP_API_DOMAIN;
|
|
283
|
+
}
|
|
276
284
|
if (options.verifyQuerySignatures !== undefined) {
|
|
277
285
|
this.#verifyQuerySignatures = options.verifyQuerySignatures;
|
|
278
286
|
}
|
|
287
|
+
this.#subnetNodeKeyExpirableStore =
|
|
288
|
+
options.subnetNodeKeyExpirableStore ??
|
|
289
|
+
(0, createExpirableStore_ts_1.createExpirableStore)({
|
|
290
|
+
dbName: `icp-sdk-${this.host.host}`,
|
|
291
|
+
storeName: 'subnetNodeKeys',
|
|
292
|
+
expirationTime: 5 * MINUTE_TO_MSECS,
|
|
293
|
+
});
|
|
279
294
|
// Default is 3
|
|
280
295
|
this.#retryTimes = options.retryTimes ?? 3;
|
|
281
296
|
// Delay strategy for retries. Default is exponential backoff
|
|
@@ -283,19 +298,9 @@ class HttpAgent {
|
|
|
283
298
|
maxIterations: this.#retryTimes,
|
|
284
299
|
});
|
|
285
300
|
this.#backoffStrategy = options.backoffStrategy || defaultBackoffFactory;
|
|
286
|
-
// Rewrite to avoid redirects
|
|
287
|
-
if (this.host.hostname.endsWith(IC0_SUB_DOMAIN)) {
|
|
288
|
-
this.host.hostname = IC0_DOMAIN;
|
|
289
|
-
}
|
|
290
|
-
else if (this.host.hostname.endsWith(ICP0_SUB_DOMAIN)) {
|
|
291
|
-
this.host.hostname = ICP0_DOMAIN;
|
|
292
|
-
}
|
|
293
|
-
else if (this.host.hostname.endsWith(ICP_API_SUB_DOMAIN)) {
|
|
294
|
-
this.host.hostname = ICP_API_DOMAIN;
|
|
295
|
-
}
|
|
296
301
|
if (options.credentials) {
|
|
297
302
|
const { name, password } = options.credentials;
|
|
298
|
-
this.#credentials = `${name}${password ?
|
|
303
|
+
this.#credentials = `${name}${password ? `:${password}` : ''}`;
|
|
299
304
|
}
|
|
300
305
|
this.#identity = Promise.resolve(options.identity || new auth_ts_1.AnonymousIdentity());
|
|
301
306
|
if (options.ingressExpiryInMinutes && options.ingressExpiryInMinutes > 5) {
|
|
@@ -319,6 +324,7 @@ class HttpAgent {
|
|
|
319
324
|
console.warn(log.message);
|
|
320
325
|
}
|
|
321
326
|
else {
|
|
327
|
+
// eslint-disable-next-line no-console -- logToConsole opt-in
|
|
322
328
|
console.log(log.message);
|
|
323
329
|
}
|
|
324
330
|
});
|
|
@@ -410,7 +416,7 @@ class HttpAgent {
|
|
|
410
416
|
method: 'POST',
|
|
411
417
|
headers: {
|
|
412
418
|
'Content-Type': 'application/cbor',
|
|
413
|
-
...(this.#credentials ? { Authorization:
|
|
419
|
+
...(this.#credentials ? { Authorization: `Basic ${btoa(this.#credentials)}` } : {}),
|
|
414
420
|
},
|
|
415
421
|
},
|
|
416
422
|
endpoint: types_ts_1.Endpoint.Call,
|
|
@@ -493,22 +499,20 @@ class HttpAgent {
|
|
|
493
499
|
callSync: false,
|
|
494
500
|
}, identity);
|
|
495
501
|
}
|
|
496
|
-
|
|
502
|
+
if (error.hasCode(errors_ts_1.IngressExpiryInvalidErrorCode) && !this.#hasSyncedTime) {
|
|
497
503
|
// if there is an ingress expiry error and the time has not been synced yet,
|
|
498
504
|
// sync time with the network and try again
|
|
499
505
|
await this.syncTime(canister);
|
|
500
506
|
return this.call(canister, options, identity);
|
|
501
507
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
callError = error;
|
|
511
|
-
}
|
|
508
|
+
// override the error code to include the request details
|
|
509
|
+
error.code.requestContext = {
|
|
510
|
+
requestId,
|
|
511
|
+
senderPubKey: transformedRequest.body.sender_pubkey,
|
|
512
|
+
senderSignature: transformedRequest.body.sender_sig,
|
|
513
|
+
ingressExpiry: transformedRequest.body.content.ingress_expiry,
|
|
514
|
+
};
|
|
515
|
+
callError = error;
|
|
512
516
|
}
|
|
513
517
|
else {
|
|
514
518
|
callError = errors_ts_1.UnknownError.fromCode(new errors_ts_1.UnexpectedErrorCode(error));
|
|
@@ -517,6 +521,89 @@ class HttpAgent {
|
|
|
517
521
|
throw callError;
|
|
518
522
|
}
|
|
519
523
|
}
|
|
524
|
+
/**
|
|
525
|
+
* Executes an update call to a canister and returns the certified result.
|
|
526
|
+
* @param canisterId The canister to call.
|
|
527
|
+
* @param fields The call options (method name, arg, effective canister ID, optional nonce).
|
|
528
|
+
* @param pollingOptions Optional polling configuration.
|
|
529
|
+
* @returns The certified result including the certificate, reply bytes, and raw certificate bytes.
|
|
530
|
+
*/
|
|
531
|
+
async update(canisterId, fields, pollingOptions = {}) {
|
|
532
|
+
const effectiveCanisterId = _principal_1.Principal.from(fields.effectiveCanisterId);
|
|
533
|
+
const { requestId, response, requestDetails } = await this.call(canisterId, fields);
|
|
534
|
+
const { body, ...httpDetails } = response;
|
|
535
|
+
if ((0, api_ts_1.isV4ResponseBody)(body)) {
|
|
536
|
+
return this.#handleV4SyncResponse(body, response, requestId, effectiveCanisterId, fields.methodName, httpDetails, requestDetails, pollingOptions);
|
|
537
|
+
}
|
|
538
|
+
if ((0, api_ts_1.isV2ResponseBody)(body)) {
|
|
539
|
+
this.#handleV2Rejection(body, requestId, effectiveCanisterId, fields.methodName, httpDetails);
|
|
540
|
+
}
|
|
541
|
+
if (response.status === HTTP_STATUS_ACCEPTED) {
|
|
542
|
+
const pollResult = await (0, index_ts_3.pollForResponse)(this, effectiveCanisterId, requestId, pollingOptions);
|
|
543
|
+
return { ...pollResult, requestDetails, callResponse: response };
|
|
544
|
+
}
|
|
545
|
+
const unexpectedErrorCode = new errors_ts_1.UnexpectedErrorCode(`Unexpected response from call: status ${response.status} with unrecognized body`);
|
|
546
|
+
unexpectedErrorCode.callContext = {
|
|
547
|
+
canisterId: effectiveCanisterId,
|
|
548
|
+
methodName: fields.methodName,
|
|
549
|
+
httpDetails,
|
|
550
|
+
};
|
|
551
|
+
throw errors_ts_1.UnknownError.fromCode(unexpectedErrorCode);
|
|
552
|
+
}
|
|
553
|
+
async #handleV4SyncResponse(body, response, requestId, effectiveCanisterId, methodName, httpDetails, requestDetails, pollingOptions) {
|
|
554
|
+
if (this.rootKey == null) {
|
|
555
|
+
throw errors_ts_1.ExternalError.fromCode(new errors_ts_1.MissingRootKeyErrorCode());
|
|
556
|
+
}
|
|
557
|
+
const rawCertificate = body.certificate;
|
|
558
|
+
const certificate = await certificate_ts_1.Certificate.create({
|
|
559
|
+
certificate: rawCertificate,
|
|
560
|
+
rootKey: this.rootKey,
|
|
561
|
+
principal: { canisterId: effectiveCanisterId },
|
|
562
|
+
blsVerify: pollingOptions.blsVerify,
|
|
563
|
+
agent: this,
|
|
564
|
+
});
|
|
565
|
+
const path = [(0, utils_1.utf8ToBytes)('request_status'), requestId];
|
|
566
|
+
const maybeBuf = (0, certificate_ts_1.lookupResultToBuffer)(certificate.lookup_path([...path, (0, utils_1.utf8ToBytes)('status')]));
|
|
567
|
+
const status = maybeBuf ? new TextDecoder().decode(maybeBuf) : undefined;
|
|
568
|
+
switch (status) {
|
|
569
|
+
case RequestStatusResponseStatus.Replied:
|
|
570
|
+
return {
|
|
571
|
+
reply: (0, certificate_ts_1.lookupResultToBuffer)(certificate.lookup_path([...path, 'reply'])),
|
|
572
|
+
certificate,
|
|
573
|
+
rawCertificate,
|
|
574
|
+
requestDetails,
|
|
575
|
+
callResponse: response,
|
|
576
|
+
};
|
|
577
|
+
case RequestStatusResponseStatus.Rejected: {
|
|
578
|
+
const error = (0, certificateReject_ts_1.readCertifiedReject)(certificate, path, requestId);
|
|
579
|
+
error.callContext = {
|
|
580
|
+
canisterId: effectiveCanisterId,
|
|
581
|
+
methodName,
|
|
582
|
+
httpDetails,
|
|
583
|
+
};
|
|
584
|
+
throw errors_ts_1.RejectError.fromCode(error);
|
|
585
|
+
}
|
|
586
|
+
default: {
|
|
587
|
+
const unexpectedErrorCode = new errors_ts_1.UnexpectedErrorCode(`Unexpected request status in v4 sync response: "${status}"`);
|
|
588
|
+
unexpectedErrorCode.callContext = {
|
|
589
|
+
canisterId: effectiveCanisterId,
|
|
590
|
+
methodName,
|
|
591
|
+
httpDetails,
|
|
592
|
+
};
|
|
593
|
+
throw errors_ts_1.UnknownError.fromCode(unexpectedErrorCode);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
#handleV2Rejection(body, requestId, effectiveCanisterId, methodName, httpDetails) {
|
|
598
|
+
const { reject_code, reject_message, error_code } = body;
|
|
599
|
+
const errorCode = new errors_ts_1.UncertifiedRejectUpdateErrorCode(requestId, reject_code, reject_message, error_code);
|
|
600
|
+
errorCode.callContext = {
|
|
601
|
+
canisterId: effectiveCanisterId,
|
|
602
|
+
methodName,
|
|
603
|
+
httpDetails,
|
|
604
|
+
};
|
|
605
|
+
throw errors_ts_1.RejectError.fromCode(errorCode);
|
|
606
|
+
}
|
|
520
607
|
async #requestAndRetryQuery(args) {
|
|
521
608
|
const { ecid, transformedRequest, body, requestId, backoff, tries } = args;
|
|
522
609
|
const delay = tries === 0 ? 0 : backoff.next();
|
|
@@ -691,7 +778,7 @@ class HttpAgent {
|
|
|
691
778
|
method: 'POST',
|
|
692
779
|
headers: {
|
|
693
780
|
'Content-Type': 'application/cbor',
|
|
694
|
-
...(this.#credentials ? { Authorization:
|
|
781
|
+
...(this.#credentials ? { Authorization: `Basic ${btoa(this.#credentials)}` } : {}),
|
|
695
782
|
},
|
|
696
783
|
},
|
|
697
784
|
endpoint: types_ts_1.Endpoint.Query,
|
|
@@ -717,18 +804,6 @@ class HttpAgent {
|
|
|
717
804
|
...query,
|
|
718
805
|
};
|
|
719
806
|
};
|
|
720
|
-
const getSubnetNodeKeys = async () => {
|
|
721
|
-
const cachedSubnetNodeKeys = this.#subnetKeys.get(ecid.toString());
|
|
722
|
-
if (cachedSubnetNodeKeys) {
|
|
723
|
-
return cachedSubnetNodeKeys;
|
|
724
|
-
}
|
|
725
|
-
await this.fetchSubnetKeys(ecid.toString());
|
|
726
|
-
const subnetNodeKeys = this.#subnetKeys.get(ecid.toString());
|
|
727
|
-
if (!subnetNodeKeys) {
|
|
728
|
-
throw errors_ts_1.TrustError.fromCode(new errors_ts_1.MissingSignatureErrorCode());
|
|
729
|
-
}
|
|
730
|
-
return subnetNodeKeys;
|
|
731
|
-
};
|
|
732
807
|
try {
|
|
733
808
|
if (!this.#verifyQuerySignatures) {
|
|
734
809
|
// Skip verification if the user has disabled it
|
|
@@ -737,7 +812,7 @@ class HttpAgent {
|
|
|
737
812
|
// Make query and fetch subnet keys in parallel
|
|
738
813
|
const [queryWithDetails, subnetNodeKeys] = await Promise.all([
|
|
739
814
|
makeQuery(),
|
|
740
|
-
|
|
815
|
+
this.fetchSubnetKeys(ecid),
|
|
741
816
|
]);
|
|
742
817
|
try {
|
|
743
818
|
return this.#verifyQueryResponse(queryWithDetails, subnetNodeKeys);
|
|
@@ -745,8 +820,8 @@ class HttpAgent {
|
|
|
745
820
|
catch {
|
|
746
821
|
// In case the node signatures have changed, refresh the subnet keys and try again
|
|
747
822
|
this.log.warn('Query response verification failed. Retrying with fresh subnet keys.');
|
|
748
|
-
this.#
|
|
749
|
-
const updatedSubnetNodeKeys = await
|
|
823
|
+
await this.#subnetNodeKeyExpirableStore.delete(ecid.toString());
|
|
824
|
+
const updatedSubnetNodeKeys = await this.fetchSubnetKeys(ecid);
|
|
750
825
|
return this.#verifyQueryResponse(queryWithDetails, updatedSubnetNodeKeys);
|
|
751
826
|
}
|
|
752
827
|
}
|
|
@@ -794,7 +869,7 @@ class HttpAgent {
|
|
|
794
869
|
method: 'POST',
|
|
795
870
|
headers: {
|
|
796
871
|
'Content-Type': 'application/cbor',
|
|
797
|
-
...(this.#credentials ? { Authorization:
|
|
872
|
+
...(this.#credentials ? { Authorization: `Basic ${btoa(this.#credentials)}` } : {}),
|
|
798
873
|
},
|
|
799
874
|
},
|
|
800
875
|
endpoint: types_ts_1.Endpoint.ReadState,
|
|
@@ -925,9 +1000,7 @@ class HttpAgent {
|
|
|
925
1000
|
this.log.print('Time from response in milliseconds:', date.getTime());
|
|
926
1001
|
return date.getTime();
|
|
927
1002
|
}
|
|
928
|
-
|
|
929
|
-
this.log.warn('No certificate found in response');
|
|
930
|
-
}
|
|
1003
|
+
this.log.warn('No certificate found in response');
|
|
931
1004
|
return 0;
|
|
932
1005
|
}
|
|
933
1006
|
/**
|
|
@@ -1036,7 +1109,7 @@ class HttpAgent {
|
|
|
1036
1109
|
async status() {
|
|
1037
1110
|
const headers = this.#credentials
|
|
1038
1111
|
? {
|
|
1039
|
-
Authorization:
|
|
1112
|
+
Authorization: `Basic ${btoa(this.#credentials)}`,
|
|
1040
1113
|
}
|
|
1041
1114
|
: {};
|
|
1042
1115
|
const url = new URL(`/api/v2/status`, this.host);
|
|
@@ -1071,7 +1144,7 @@ class HttpAgent {
|
|
|
1071
1144
|
if (this.rootKey) {
|
|
1072
1145
|
return;
|
|
1073
1146
|
}
|
|
1074
|
-
|
|
1147
|
+
if (this.rootKey === null &&
|
|
1075
1148
|
this.host.toString() !== 'https://icp-api.io' &&
|
|
1076
1149
|
this.#shouldFetchRootKey) {
|
|
1077
1150
|
await this.fetchRootKey();
|
|
@@ -1093,6 +1166,25 @@ class HttpAgent {
|
|
|
1093
1166
|
}
|
|
1094
1167
|
async fetchSubnetKeys(canisterId) {
|
|
1095
1168
|
const effectiveCanisterId = _principal_1.Principal.from(canisterId);
|
|
1169
|
+
// Return cached result if available within the TTL.
|
|
1170
|
+
const cached = await this.#subnetNodeKeyExpirableStore.get(effectiveCanisterId.toText());
|
|
1171
|
+
if (cached) {
|
|
1172
|
+
return cached;
|
|
1173
|
+
}
|
|
1174
|
+
// Deduplicate parallel requests for the same canister so that concurrent
|
|
1175
|
+
// query calls share a single read_state round-trip instead of each
|
|
1176
|
+
// issuing their own.
|
|
1177
|
+
const inflight = this.#subnetKeysFetching.get(effectiveCanisterId.toText());
|
|
1178
|
+
if (inflight) {
|
|
1179
|
+
return inflight;
|
|
1180
|
+
}
|
|
1181
|
+
const fetchPromise = this.#doFetchSubnetKeys(effectiveCanisterId).finally(() => {
|
|
1182
|
+
this.#subnetKeysFetching.delete(effectiveCanisterId.toText());
|
|
1183
|
+
});
|
|
1184
|
+
this.#subnetKeysFetching.set(effectiveCanisterId.toText(), fetchPromise);
|
|
1185
|
+
return fetchPromise;
|
|
1186
|
+
}
|
|
1187
|
+
async #doFetchSubnetKeys(effectiveCanisterId) {
|
|
1096
1188
|
await this.#asyncGuard(effectiveCanisterId);
|
|
1097
1189
|
const rootKey = this.rootKey;
|
|
1098
1190
|
const canisterReadState = await this.readState(effectiveCanisterId, {
|
|
@@ -1117,7 +1209,7 @@ class HttpAgent {
|
|
|
1117
1209
|
}
|
|
1118
1210
|
const subnetId = (0, certificate_ts_1.getSubnetIdFromCertificate)(canisterCertificate.cert, rootKey);
|
|
1119
1211
|
const nodeKeys = (0, readState_ts_1.lookupNodeKeysFromCertificate)(canisterCertificate.cert, subnetId);
|
|
1120
|
-
this.#
|
|
1212
|
+
await this.#subnetNodeKeyExpirableStore.set(effectiveCanisterId.toText(), nodeKeys);
|
|
1121
1213
|
return nodeKeys;
|
|
1122
1214
|
}
|
|
1123
1215
|
/**
|