@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
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RequestId } from '../request_id.ts';
|
|
2
2
|
import {
|
|
3
3
|
type CreateCertificateOptions,
|
|
4
4
|
Certificate,
|
|
5
5
|
lookupResultToBuffer,
|
|
6
6
|
} from '../certificate.ts';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { readCertifiedReject } from '../utils/certificateReject.ts';
|
|
8
|
+
import type { Agent, ReadStateResponse } from '../agent/api.ts';
|
|
9
|
+
import type { Principal } from '#principal';
|
|
9
10
|
import {
|
|
10
|
-
CertifiedRejectErrorCode,
|
|
11
11
|
ExternalError,
|
|
12
12
|
InputError,
|
|
13
13
|
InvalidReadStateRequestErrorCode,
|
|
@@ -20,16 +20,12 @@ import {
|
|
|
20
20
|
|
|
21
21
|
export * as strategy from './strategy.ts';
|
|
22
22
|
import { defaultStrategy } from './strategy.ts';
|
|
23
|
+
import type { PollStrategy, PollForResponseResult } from './types.ts';
|
|
23
24
|
import { ReadRequestType, type ReadStateRequest } from '../agent/http/types.ts';
|
|
24
|
-
import { RequestStatusResponseStatus } from '../agent/index.ts';
|
|
25
|
+
import { RequestStatusResponseStatus } from '../agent/http/index.ts';
|
|
25
26
|
import { utf8ToBytes } from '@noble/hashes/utils';
|
|
26
27
|
export { defaultStrategy } from './strategy.ts';
|
|
27
|
-
|
|
28
|
-
export type PollStrategy = (
|
|
29
|
-
canisterId: Principal,
|
|
30
|
-
requestId: RequestId,
|
|
31
|
-
status: RequestStatusResponseStatus,
|
|
32
|
-
) => Promise<void>;
|
|
28
|
+
export type { PollStrategy, PollForResponseResult } from './types.ts';
|
|
33
29
|
|
|
34
30
|
interface SignedReadStateRequestWithExpiry extends ReadStateRequest {
|
|
35
31
|
body: {
|
|
@@ -122,16 +118,17 @@ function isSignedReadStateRequestWithExpiry(
|
|
|
122
118
|
* @param canisterId The effective canister ID.
|
|
123
119
|
* @param requestId The Request ID to poll status for.
|
|
124
120
|
* @param options polling options to control behavior
|
|
121
|
+
* @returns The certificate, reply bytes, and raw certificate bytes for the request.
|
|
122
|
+
* @throws {ExternalError} If the agent's root key is not available.
|
|
123
|
+
* @throws {RejectError} If the request was rejected by the canister.
|
|
124
|
+
* @throws {UnknownError} If the request reached `done` status without a reply.
|
|
125
125
|
*/
|
|
126
126
|
export async function pollForResponse(
|
|
127
127
|
agent: Agent,
|
|
128
128
|
canisterId: Principal,
|
|
129
129
|
requestId: RequestId,
|
|
130
130
|
options: PollingOptions = {},
|
|
131
|
-
): Promise<{
|
|
132
|
-
certificate: Certificate;
|
|
133
|
-
reply: Uint8Array;
|
|
134
|
-
}> {
|
|
131
|
+
): Promise<PollForResponseResult> {
|
|
135
132
|
const path = [utf8ToBytes('request_status'), requestId];
|
|
136
133
|
|
|
137
134
|
let state: ReadStateResponse;
|
|
@@ -175,6 +172,7 @@ export async function pollForResponse(
|
|
|
175
172
|
return {
|
|
176
173
|
reply: lookupResultToBuffer(cert.lookup_path([...path, 'reply']))!,
|
|
177
174
|
certificate: cert,
|
|
175
|
+
rawCertificate: state.certificate,
|
|
178
176
|
};
|
|
179
177
|
}
|
|
180
178
|
|
|
@@ -194,17 +192,7 @@ export async function pollForResponse(
|
|
|
194
192
|
}
|
|
195
193
|
|
|
196
194
|
case RequestStatusResponseStatus.Rejected: {
|
|
197
|
-
|
|
198
|
-
lookupResultToBuffer(cert.lookup_path([...path, 'reject_code']))!,
|
|
199
|
-
)[0];
|
|
200
|
-
const rejectMessage = new TextDecoder().decode(
|
|
201
|
-
lookupResultToBuffer(cert.lookup_path([...path, 'reject_message']))!,
|
|
202
|
-
);
|
|
203
|
-
const errorCodeBuf = lookupResultToBuffer(cert.lookup_path([...path, 'error_code']));
|
|
204
|
-
const errorCode = errorCodeBuf ? new TextDecoder().decode(errorCodeBuf) : undefined;
|
|
205
|
-
throw RejectError.fromCode(
|
|
206
|
-
new CertifiedRejectErrorCode(requestId, rejectCode, rejectMessage, errorCode),
|
|
207
|
-
);
|
|
195
|
+
throw RejectError.fromCode(readCertifiedReject(cert, path, requestId));
|
|
208
196
|
}
|
|
209
197
|
|
|
210
198
|
case RequestStatusResponseStatus.Done:
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { Principal } from '#principal';
|
|
2
|
-
import { RequestStatusResponseStatus } from '../agent/index.ts';
|
|
3
|
-
import {
|
|
4
|
-
import { type RequestId } from '../request_id.ts';
|
|
1
|
+
import type { Principal } from '#principal';
|
|
2
|
+
import type { RequestStatusResponseStatus } from '../agent/http/index.ts';
|
|
3
|
+
import type { RequestId } from '../request_id.ts';
|
|
5
4
|
import { ProtocolError, TimeoutWaitingForResponseErrorCode } from '../errors.ts';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
requestId: RequestId,
|
|
10
|
-
status: RequestStatusResponseStatus,
|
|
11
|
-
) => Promise<T>;
|
|
6
|
+
import type { PollStrategy, Predicate } from './types.ts';
|
|
7
|
+
export type { PollStrategy, Predicate } from './types.ts';
|
|
12
8
|
|
|
13
9
|
const FIVE_MINUTES_IN_MSEC = 5 * 60 * 1000;
|
|
14
10
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Certificate } from '../certificate.ts';
|
|
2
|
+
import type { Principal } from '#principal';
|
|
3
|
+
import type { RequestStatusResponseStatus } from '../agent/http/index.ts';
|
|
4
|
+
import type { RequestId } from '../request_id.ts';
|
|
5
|
+
|
|
6
|
+
export type PollStrategy = (
|
|
7
|
+
canisterId: Principal,
|
|
8
|
+
requestId: RequestId,
|
|
9
|
+
status: RequestStatusResponseStatus,
|
|
10
|
+
) => Promise<void>;
|
|
11
|
+
|
|
12
|
+
export type Predicate<T> = (
|
|
13
|
+
canisterId: Principal,
|
|
14
|
+
requestId: RequestId,
|
|
15
|
+
status: RequestStatusResponseStatus,
|
|
16
|
+
) => Promise<T>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The result of polling for a response, including the certificate, reply bytes, and raw certificate bytes.
|
|
20
|
+
*/
|
|
21
|
+
export interface PollForResponseResult {
|
|
22
|
+
/** The certificate for the request, which can be used to verify the reply. */
|
|
23
|
+
certificate: Certificate;
|
|
24
|
+
/** The reply bytes for the request. */
|
|
25
|
+
reply: Uint8Array;
|
|
26
|
+
/** The raw certificate bytes for the request. */
|
|
27
|
+
rawCertificate: Uint8Array;
|
|
28
|
+
}
|
package/src/agent/public_key.ts
CHANGED
package/src/agent/request_id.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { lebEncode, compare } from '#candid';
|
|
2
|
-
import { Principal } from '#principal';
|
|
2
|
+
import type { Principal } from '#principal';
|
|
3
3
|
import { HashValueErrorCode, InputError } from './errors.ts';
|
|
4
4
|
import { uint8FromBufLike } from './utils/buffer.ts';
|
|
5
5
|
import { concatBytes } from '@noble/hashes/utils';
|
|
@@ -19,16 +19,21 @@ interface ToHashable {
|
|
|
19
19
|
export function hashValue(value: unknown): Uint8Array {
|
|
20
20
|
if (typeof value === 'string') {
|
|
21
21
|
return hashString(value);
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
|
+
if (typeof value === 'number') {
|
|
23
24
|
return sha256(lebEncode(value));
|
|
24
|
-
}
|
|
25
|
+
}
|
|
26
|
+
if (value instanceof Uint8Array || ArrayBuffer.isView(value)) {
|
|
25
27
|
return sha256(uint8FromBufLike(value));
|
|
26
|
-
}
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(value)) {
|
|
27
30
|
const vals = value.map(hashValue);
|
|
28
31
|
return sha256(concatBytes(...vals));
|
|
29
|
-
}
|
|
32
|
+
}
|
|
33
|
+
if (value && typeof value === 'object' && (value as Principal)._isPrincipal) {
|
|
30
34
|
return sha256((value as Principal).toUint8Array());
|
|
31
|
-
}
|
|
35
|
+
}
|
|
36
|
+
if (
|
|
32
37
|
typeof value === 'object' &&
|
|
33
38
|
value !== null &&
|
|
34
39
|
typeof (value as ToHashable).toHash === 'function'
|
|
@@ -38,9 +43,11 @@ export function hashValue(value: unknown): Uint8Array {
|
|
|
38
43
|
// the flow to be synchronous to ensure Safari touch id works.
|
|
39
44
|
// } else if (value instanceof Promise) {
|
|
40
45
|
// return value.then(x => hashValue(x));
|
|
41
|
-
}
|
|
46
|
+
}
|
|
47
|
+
if (typeof value === 'object') {
|
|
42
48
|
return hashOfMap(value as Record<string, unknown>);
|
|
43
|
-
}
|
|
49
|
+
}
|
|
50
|
+
if (typeof value === 'bigint') {
|
|
44
51
|
// Do this check much later than the other bigint check because this one is much less
|
|
45
52
|
// type-safe.
|
|
46
53
|
// So we want to try all the high-assurance type guards before this 'probable' one.
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
ProtocolError,
|
|
11
11
|
LookupErrorCode,
|
|
12
12
|
} from '../errors.ts';
|
|
13
|
-
import { HttpAgent } from '../agent/http/index.ts';
|
|
13
|
+
import type { HttpAgent } from '../agent/http/index.ts';
|
|
14
14
|
import {
|
|
15
15
|
type Cert,
|
|
16
16
|
type CanisterRanges,
|
|
@@ -23,11 +23,11 @@ import {
|
|
|
23
23
|
import * as cbor from '../cbor.ts';
|
|
24
24
|
import { decodeTime } from '../utils/leb.ts';
|
|
25
25
|
import { utf8ToBytes } from '@noble/hashes/utils';
|
|
26
|
+
import type { CustomPath } from '../utils/readState.ts';
|
|
26
27
|
import {
|
|
27
28
|
type BaseStatus,
|
|
28
29
|
type BaseSubnetStatus,
|
|
29
30
|
type SubnetNodeKeys,
|
|
30
|
-
CustomPath,
|
|
31
31
|
decodeValue,
|
|
32
32
|
isCustomPath,
|
|
33
33
|
lookupNodeKeysFromCertificate,
|
|
@@ -53,7 +53,7 @@ export type Path = 'time' | 'canisterRanges' | 'publicKey' | 'nodeKeys' | Custom
|
|
|
53
53
|
|
|
54
54
|
export type StatusMap = Map<Path | string, Status>;
|
|
55
55
|
|
|
56
|
-
export
|
|
56
|
+
export interface SubnetStatusOptions {
|
|
57
57
|
/**
|
|
58
58
|
* The subnet ID to query. Use {@link IC_ROOT_SUBNET_ID} for the IC mainnet root subnet.
|
|
59
59
|
* You can use {@link HttpAgent.getSubnetIdFromCanister} to get a subnet ID from a canister.
|
|
@@ -73,7 +73,7 @@ export type SubnetStatusOptions = {
|
|
|
73
73
|
* @default false
|
|
74
74
|
*/
|
|
75
75
|
disableCertificateTimeVerification?: boolean;
|
|
76
|
-
}
|
|
76
|
+
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
* Requests information from a subnet's `read_state` endpoint.
|
|
@@ -129,12 +129,11 @@ export async function request(options: SubnetStatusOptions): Promise<StatusMap>
|
|
|
129
129
|
path: lookupPath,
|
|
130
130
|
data,
|
|
131
131
|
};
|
|
132
|
-
} else {
|
|
133
|
-
return {
|
|
134
|
-
path: lookupPath,
|
|
135
|
-
data: lookupResultToBuffer(cert.lookup_path(encodedPath)),
|
|
136
|
-
};
|
|
137
132
|
}
|
|
133
|
+
return {
|
|
134
|
+
path: lookupPath,
|
|
135
|
+
data: lookupResultToBuffer(cert.lookup_path(encodedPath)),
|
|
136
|
+
};
|
|
138
137
|
};
|
|
139
138
|
|
|
140
139
|
const { path, data } = lookup(certificate, uniquePaths[index]);
|
|
@@ -250,10 +249,9 @@ export function encodePath(path: Path, subnetId: Principal): Uint8Array[] {
|
|
|
250
249
|
const encoded =
|
|
251
250
|
typeof path['path'] === 'string' ? utf8ToBytes(path['path']) : path['path'];
|
|
252
251
|
return [utf8ToBytes('subnet'), subnetUint8Array, encoded];
|
|
253
|
-
} else {
|
|
254
|
-
// For non-simple paths, return the provided custom path
|
|
255
|
-
return path['path'];
|
|
256
252
|
}
|
|
253
|
+
// For non-simple paths, return the provided custom path
|
|
254
|
+
return path['path'];
|
|
257
255
|
}
|
|
258
256
|
}
|
|
259
257
|
}
|
|
@@ -52,9 +52,13 @@ export function uint8ToBuf(arr: Uint8Array): ArrayBuffer {
|
|
|
52
52
|
* @returns True if the Uint8Arrays are equal, false otherwise.
|
|
53
53
|
*/
|
|
54
54
|
export function uint8Equals(a: Uint8Array, b: Uint8Array): boolean {
|
|
55
|
-
if (a.length !== b.length)
|
|
55
|
+
if (a.length !== b.length) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
56
58
|
for (let i = 0; i < a.length; i++) {
|
|
57
|
-
if (a[i] !== b[i])
|
|
59
|
+
if (a[i] !== b[i]) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
58
62
|
}
|
|
59
63
|
return true;
|
|
60
64
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Certificate, type NodePath, lookupResultToBuffer } from '../certificate.ts';
|
|
2
|
+
import { CertifiedRejectErrorCode } from '../errors.ts';
|
|
3
|
+
import type { RequestId } from '../request_id.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Read certified reject details from a certificate at the given request status path.
|
|
7
|
+
* @param certificate The certificate to read reject details from.
|
|
8
|
+
* @param path The lookup path prefix (e.g. `['request_status', requestId]`).
|
|
9
|
+
* @param requestId The request ID associated with the rejection.
|
|
10
|
+
*/
|
|
11
|
+
export function readCertifiedReject(
|
|
12
|
+
certificate: Certificate,
|
|
13
|
+
path: NodePath,
|
|
14
|
+
requestId: RequestId,
|
|
15
|
+
): CertifiedRejectErrorCode {
|
|
16
|
+
const rejectCode = new Uint8Array(
|
|
17
|
+
lookupResultToBuffer(certificate.lookup_path([...path, 'reject_code']))!,
|
|
18
|
+
)[0];
|
|
19
|
+
const rejectMessage = new TextDecoder().decode(
|
|
20
|
+
lookupResultToBuffer(certificate.lookup_path([...path, 'reject_message']))!,
|
|
21
|
+
);
|
|
22
|
+
const errorCodeBuf = lookupResultToBuffer(certificate.lookup_path([...path, 'error_code']));
|
|
23
|
+
const errorCode = errorCodeBuf ? new TextDecoder().decode(errorCodeBuf) : undefined;
|
|
24
|
+
return new CertifiedRejectErrorCode(requestId, rejectCode, rejectMessage, errorCode);
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ExpirableStore } from './expirableStore.ts';
|
|
2
|
+
import { IndexedDBExpirableStore } from './indexedDBExpirableStore.ts';
|
|
3
|
+
import { InMemoryExpirableStore } from './inMemoryExpirableStore.ts';
|
|
4
|
+
|
|
5
|
+
export interface CreateExpirableStoreOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Name of the IndexedDB database (used when IndexedDB is available).
|
|
8
|
+
*/
|
|
9
|
+
dbName: string;
|
|
10
|
+
/**
|
|
11
|
+
* Name of the IndexedDB object store (used when IndexedDB is available).
|
|
12
|
+
*/
|
|
13
|
+
storeName: string;
|
|
14
|
+
/**
|
|
15
|
+
* Time in milliseconds after which entries expire.
|
|
16
|
+
*/
|
|
17
|
+
expirationTime: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates an {@link ExpirableStore} with automatic runtime detection.
|
|
22
|
+
* Uses {@link IndexedDBExpirableStore} in browser environments (when IndexedDB is available),
|
|
23
|
+
* falls back to {@link InMemoryExpirableStore} otherwise.
|
|
24
|
+
* @param options - Configuration for the store (dbName, storeName, and expirationTime).
|
|
25
|
+
*/
|
|
26
|
+
export function createExpirableStore<V>(options: CreateExpirableStoreOptions): ExpirableStore<V> {
|
|
27
|
+
if (typeof globalThis.indexedDB !== 'undefined') {
|
|
28
|
+
return new IndexedDBExpirableStore<V>(options);
|
|
29
|
+
}
|
|
30
|
+
return new InMemoryExpirableStore<V>({ expirationTime: options.expirationTime });
|
|
31
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic interface for a key-value store with time-based expiration.
|
|
3
|
+
* Keys are strings, values are of type V.
|
|
4
|
+
* Implementations must handle expiration internally.
|
|
5
|
+
*/
|
|
6
|
+
export interface ExpirableStore<V> {
|
|
7
|
+
/**
|
|
8
|
+
* Time in milliseconds after which entries expire.
|
|
9
|
+
*/
|
|
10
|
+
readonly expirationTime: number;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Get the value for a key.
|
|
14
|
+
* Returns undefined if the key is not present or has expired.
|
|
15
|
+
*/
|
|
16
|
+
get(key: string): Promise<V | undefined>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Store a value for a key.
|
|
20
|
+
* Prunes expired entries before inserting.
|
|
21
|
+
*/
|
|
22
|
+
set(key: string, value: V): Promise<void>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Delete the entry for a key.
|
|
26
|
+
*/
|
|
27
|
+
delete(key: string): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ExpirableStoreOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Time in milliseconds after which entries expire.
|
|
33
|
+
* Must be a positive finite number.
|
|
34
|
+
*/
|
|
35
|
+
expirationTime: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Validates that expirationTime is a positive finite number.
|
|
40
|
+
* @param expirationTime - Time in milliseconds after which entries expire.
|
|
41
|
+
* @throws {Error} if expirationTime is not valid.
|
|
42
|
+
*/
|
|
43
|
+
export function validateExpirationTime(expirationTime: number): void {
|
|
44
|
+
if (!Number.isFinite(expirationTime) || expirationTime <= 0) {
|
|
45
|
+
throw new Error(`expirationTime must be a positive finite number, got ${expirationTime}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { validateExpirationTime } from './expirableStore.ts';
|
|
2
|
+
import type { ExpirableStore, ExpirableStoreOptions } from './expirableStore.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* In-memory key-value store with timestamp-based expiration.
|
|
6
|
+
* Prunes all expired entries on every {@link set} call.
|
|
7
|
+
*/
|
|
8
|
+
export class InMemoryExpirableStore<V> implements ExpirableStore<V> {
|
|
9
|
+
readonly expirationTime: number;
|
|
10
|
+
readonly #entries: Map<string, { value: V; timestamp: number }>;
|
|
11
|
+
|
|
12
|
+
constructor(options: ExpirableStoreOptions) {
|
|
13
|
+
validateExpirationTime(options.expirationTime);
|
|
14
|
+
this.expirationTime = options.expirationTime;
|
|
15
|
+
this.#entries = new Map();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get(key: string): Promise<V | undefined> {
|
|
19
|
+
const entry = this.#entries.get(key);
|
|
20
|
+
if (!entry) {
|
|
21
|
+
return Promise.resolve(undefined);
|
|
22
|
+
}
|
|
23
|
+
if (Date.now() - entry.timestamp > this.expirationTime) {
|
|
24
|
+
this.#entries.delete(key);
|
|
25
|
+
return Promise.resolve(undefined);
|
|
26
|
+
}
|
|
27
|
+
return Promise.resolve(entry.value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
set(key: string, value: V): Promise<void> {
|
|
31
|
+
this.#prune();
|
|
32
|
+
this.#entries.set(key, { value, timestamp: Date.now() });
|
|
33
|
+
return Promise.resolve();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
delete(key: string): Promise<void> {
|
|
37
|
+
this.#entries.delete(key);
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#prune(): void {
|
|
42
|
+
const now = Date.now();
|
|
43
|
+
for (const [key, entry] of this.#entries) {
|
|
44
|
+
if (now - entry.timestamp > this.expirationTime) {
|
|
45
|
+
this.#entries.delete(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { validateExpirationTime } from './expirableStore.ts';
|
|
2
|
+
import type { ExpirableStore } from './expirableStore.ts';
|
|
3
|
+
|
|
4
|
+
interface ExpirableRecord {
|
|
5
|
+
key: string;
|
|
6
|
+
value: unknown;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IndexedDBExpirableStoreOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Name of the IndexedDB database.
|
|
13
|
+
*/
|
|
14
|
+
dbName: string;
|
|
15
|
+
/**
|
|
16
|
+
* Name of the IndexedDB object store.
|
|
17
|
+
*/
|
|
18
|
+
storeName: string;
|
|
19
|
+
/**
|
|
20
|
+
* Time in milliseconds after which entries expire.
|
|
21
|
+
*/
|
|
22
|
+
expirationTime: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Key-value store backed by IndexedDB with time-based expiration.
|
|
27
|
+
* Enables sharing cached data across multiple instances and page reloads.
|
|
28
|
+
*/
|
|
29
|
+
export class IndexedDBExpirableStore<V> implements ExpirableStore<V> {
|
|
30
|
+
readonly expirationTime: number;
|
|
31
|
+
readonly #dbName: string;
|
|
32
|
+
readonly #storeName: string;
|
|
33
|
+
#dbPromise: Promise<IDBDatabase> | null = null;
|
|
34
|
+
|
|
35
|
+
constructor(options: IndexedDBExpirableStoreOptions) {
|
|
36
|
+
if (typeof globalThis.indexedDB === 'undefined') {
|
|
37
|
+
throw new Error(
|
|
38
|
+
'IndexedDBExpirableStore requires IndexedDB, which is not available in this environment',
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
validateExpirationTime(options.expirationTime);
|
|
42
|
+
this.#dbName = options.dbName;
|
|
43
|
+
this.#storeName = options.storeName;
|
|
44
|
+
this.expirationTime = options.expirationTime;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#getDb(): Promise<IDBDatabase> {
|
|
48
|
+
if (!this.#dbPromise) {
|
|
49
|
+
this.#dbPromise = this.#openDb().catch((error) => {
|
|
50
|
+
// Reset the cached promise so future calls can retry opening the DB
|
|
51
|
+
this.#dbPromise = null;
|
|
52
|
+
throw error;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return this.#dbPromise;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async #openDb(): Promise<IDBDatabase> {
|
|
59
|
+
const db = await this.#openRequest();
|
|
60
|
+
|
|
61
|
+
if (db.objectStoreNames.contains(this.#storeName)) {
|
|
62
|
+
return db;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Object store is missing — close and reopen with a bumped version
|
|
66
|
+
// to trigger onupgradeneeded.
|
|
67
|
+
const nextVersion = db.version + 1;
|
|
68
|
+
db.close();
|
|
69
|
+
return this.#openRequest(nextVersion);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#openRequest(version?: number): Promise<IDBDatabase> {
|
|
73
|
+
const storeName = this.#storeName;
|
|
74
|
+
|
|
75
|
+
return new Promise<IDBDatabase>((resolve, reject) => {
|
|
76
|
+
const request = globalThis.indexedDB.open(this.#dbName, version);
|
|
77
|
+
|
|
78
|
+
request.onupgradeneeded = () => {
|
|
79
|
+
const db = request.result;
|
|
80
|
+
if (!db.objectStoreNames.contains(storeName)) {
|
|
81
|
+
db.createObjectStore(storeName, { keyPath: 'key' });
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
request.onsuccess = () => {
|
|
86
|
+
const db = request.result;
|
|
87
|
+
|
|
88
|
+
// Cooperatively close when another instance (or this store with a
|
|
89
|
+
// different storeName) requests a version upgrade. The next
|
|
90
|
+
// operation will re-acquire the connection via #getDb().
|
|
91
|
+
db.onversionchange = () => {
|
|
92
|
+
db.close();
|
|
93
|
+
this.#dbPromise = null;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
resolve(db);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
request.onerror = () => reject(request.error);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async get(key: string): Promise<V | undefined> {
|
|
104
|
+
const db = await this.#getDb();
|
|
105
|
+
|
|
106
|
+
return new Promise<V | undefined>((resolve, reject) => {
|
|
107
|
+
const tx = db.transaction(this.#storeName, 'readonly');
|
|
108
|
+
const store = tx.objectStore(this.#storeName);
|
|
109
|
+
const request = store.get(key);
|
|
110
|
+
|
|
111
|
+
request.onsuccess = () => {
|
|
112
|
+
const record = request.result as ExpirableRecord | undefined;
|
|
113
|
+
if (!record) {
|
|
114
|
+
resolve(undefined);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (Date.now() - record.timestamp > this.expirationTime) {
|
|
119
|
+
// Lazy expiration: delete expired entry and return undefined
|
|
120
|
+
this.delete(key).then(
|
|
121
|
+
() => resolve(undefined),
|
|
122
|
+
() => resolve(undefined),
|
|
123
|
+
);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
resolve(record.value as V);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
request.onerror = () => reject(request.error);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async set(key: string, value: V): Promise<void> {
|
|
135
|
+
await this.#prune();
|
|
136
|
+
const db = await this.#getDb();
|
|
137
|
+
|
|
138
|
+
return new Promise<void>((resolve, reject) => {
|
|
139
|
+
const tx = db.transaction(this.#storeName, 'readwrite');
|
|
140
|
+
const store = tx.objectStore(this.#storeName);
|
|
141
|
+
|
|
142
|
+
const record: ExpirableRecord = {
|
|
143
|
+
key,
|
|
144
|
+
value,
|
|
145
|
+
timestamp: Date.now(),
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
store.put(record);
|
|
149
|
+
tx.oncomplete = () => resolve();
|
|
150
|
+
tx.onerror = () => reject(tx.error);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async delete(key: string): Promise<void> {
|
|
155
|
+
const db = await this.#getDb();
|
|
156
|
+
|
|
157
|
+
return new Promise<void>((resolve, reject) => {
|
|
158
|
+
const tx = db.transaction(this.#storeName, 'readwrite');
|
|
159
|
+
const store = tx.objectStore(this.#storeName);
|
|
160
|
+
store.delete(key);
|
|
161
|
+
tx.oncomplete = () => resolve();
|
|
162
|
+
tx.onerror = () => reject(tx.error);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async #prune(): Promise<void> {
|
|
167
|
+
const db = await this.#getDb();
|
|
168
|
+
const now = Date.now();
|
|
169
|
+
|
|
170
|
+
return new Promise<void>((resolve, reject) => {
|
|
171
|
+
const tx = db.transaction(this.#storeName, 'readwrite');
|
|
172
|
+
const store = tx.objectStore(this.#storeName);
|
|
173
|
+
const request = store.openCursor();
|
|
174
|
+
|
|
175
|
+
request.onsuccess = () => {
|
|
176
|
+
const cursor = request.result;
|
|
177
|
+
if (!cursor) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const record = cursor.value as ExpirableRecord;
|
|
181
|
+
if (now - record.timestamp > this.expirationTime) {
|
|
182
|
+
cursor.delete();
|
|
183
|
+
}
|
|
184
|
+
cursor.continue();
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
tx.oncomplete = () => resolve();
|
|
188
|
+
tx.onerror = () => reject(tx.error);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -16,9 +16,9 @@ export const randomNumber = (): number => {
|
|
|
16
16
|
return array[0];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
interface nodeCrypto {
|
|
20
20
|
randomInt: (min: number, max: number) => number;
|
|
21
|
-
}
|
|
21
|
+
}
|
|
22
22
|
|
|
23
23
|
// determine whether node crypto is available
|
|
24
24
|
if (typeof crypto !== 'undefined' && (crypto as unknown as nodeCrypto).randomInt) {
|
|
@@ -2,7 +2,7 @@ import { Principal } from '#principal';
|
|
|
2
2
|
import * as cbor from '../cbor.ts';
|
|
3
3
|
import { decodeLeb128 } from '../utils/leb.ts';
|
|
4
4
|
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils';
|
|
5
|
-
import {
|
|
5
|
+
import type { DerEncodedPublicKey } from '../auth.ts';
|
|
6
6
|
import {
|
|
7
7
|
type Cert,
|
|
8
8
|
flatten_forks,
|
|
@@ -32,7 +32,7 @@ export type SubnetNodeKeys = Map<string, DerEncodedPublicKey>;
|
|
|
32
32
|
/**
|
|
33
33
|
* Represents the useful information about a subnet
|
|
34
34
|
*/
|
|
35
|
-
export
|
|
35
|
+
export interface BaseSubnetStatus {
|
|
36
36
|
/**
|
|
37
37
|
* The subnet ID
|
|
38
38
|
*/
|
|
@@ -45,7 +45,7 @@ export type BaseSubnetStatus = {
|
|
|
45
45
|
* Not supported
|
|
46
46
|
*/
|
|
47
47
|
metrics?: never;
|
|
48
|
-
}
|
|
48
|
+
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Base types of an entry on the status map.
|