@icp-sdk/core 5.0.0-beta.2 → 5.1.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 +11 -2
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/index.js +142 -73
- 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 +27 -18
- package/lib/cjs/agent/errors.d.ts.map +1 -1
- package/lib/cjs/agent/errors.js +18 -15
- package/lib/cjs/agent/errors.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/expirableMap.d.ts +4 -4
- package/lib/cjs/agent/utils/expirableMap.d.ts.map +1 -1
- package/lib/cjs/agent/utils/expirableMap.js +2 -2
- 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 +11 -2
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/index.js +145 -76
- 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 +27 -18
- package/lib/esm/agent/errors.d.ts.map +1 -1
- package/lib/esm/agent/errors.js +16 -13
- package/lib/esm/agent/errors.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/expirableMap.d.ts +4 -4
- package/lib/esm/agent/utils/expirableMap.d.ts.map +1 -1
- package/lib/esm/agent/utils/expirableMap.js +2 -2
- 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 +13 -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 +217 -90
- 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 +41 -31
- package/src/agent/fetch_candid.ts +1 -1
- 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/expirableMap.ts +4 -4
- 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/src/agent/actor.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type Agent,
|
|
3
|
+
type UpdateResult,
|
|
3
4
|
type HttpDetailsResponse,
|
|
4
|
-
isV2ResponseBody,
|
|
5
|
-
isV4ResponseBody,
|
|
6
5
|
QueryResponseStatus,
|
|
7
6
|
} from './agent/index.ts';
|
|
8
7
|
import {
|
|
9
|
-
CertifiedRejectErrorCode,
|
|
10
|
-
ExternalError,
|
|
11
8
|
InputError,
|
|
12
9
|
MissingCanisterIdErrorCode,
|
|
13
|
-
MissingRootKeyErrorCode,
|
|
14
10
|
RejectError,
|
|
15
11
|
UncertifiedRejectErrorCode,
|
|
16
|
-
UncertifiedRejectUpdateErrorCode,
|
|
17
|
-
UnexpectedErrorCode,
|
|
18
|
-
UnknownError,
|
|
19
12
|
} from './errors.ts';
|
|
20
13
|
import { IDL } from '#candid';
|
|
21
|
-
import {
|
|
14
|
+
import { type PollingOptions, DEFAULT_POLLING_OPTIONS } from './polling/index.ts';
|
|
22
15
|
import { Principal } from '#principal';
|
|
23
|
-
import { Certificate,
|
|
16
|
+
import type { Certificate, CreateCertificateOptions } from './certificate.ts';
|
|
24
17
|
import { HttpAgent } from './agent/http/index.ts';
|
|
25
|
-
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Controls how query and composite_query methods are executed.
|
|
21
|
+
*
|
|
22
|
+
* - `'query'` — standard non-replicated query call (default).
|
|
23
|
+
* - `'update'` — send query methods as update calls that go through consensus.
|
|
24
|
+
*/
|
|
25
|
+
export type QueryStrategy = 'query' | 'update';
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Configuration to make calls to the Replica.
|
|
@@ -91,6 +91,14 @@ export interface ActorConfig extends Pick<CallConfig, 'agent' | 'effectiveCanist
|
|
|
91
91
|
* Polling options to use when making update calls. This will override the default DEFAULT_POLLING_OPTIONS.
|
|
92
92
|
*/
|
|
93
93
|
pollingOptions?: PollingOptions;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Controls how query and composite_query methods are executed.
|
|
97
|
+
* - `'query'` (default) — standard non-replicated query call.
|
|
98
|
+
* - `'update'` — send query methods as update calls that go through consensus.
|
|
99
|
+
* @default 'query'
|
|
100
|
+
*/
|
|
101
|
+
queryStrategy?: QueryStrategy;
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
// TODO: move this to proper typing when Candid support TypeScript.
|
|
@@ -111,16 +119,20 @@ export interface ActorMethod<Args extends unknown[] = unknown[], Ret = unknown>
|
|
|
111
119
|
/**
|
|
112
120
|
* An actor method type, defined for each methods of the actor service.
|
|
113
121
|
*/
|
|
114
|
-
export interface ActorMethodWithHttpDetails<
|
|
115
|
-
extends
|
|
122
|
+
export interface ActorMethodWithHttpDetails<
|
|
123
|
+
Args extends unknown[] = unknown[],
|
|
124
|
+
Ret = unknown,
|
|
125
|
+
> extends ActorMethod {
|
|
116
126
|
(...args: Args): Promise<{ httpDetails: HttpDetailsResponse; result: Ret }>;
|
|
117
127
|
}
|
|
118
128
|
|
|
119
129
|
/**
|
|
120
130
|
* An actor method type, defined for each methods of the actor service.
|
|
121
131
|
*/
|
|
122
|
-
export interface ActorMethodExtended<
|
|
123
|
-
extends
|
|
132
|
+
export interface ActorMethodExtended<
|
|
133
|
+
Args extends unknown[] = unknown[],
|
|
134
|
+
Ret = unknown,
|
|
135
|
+
> extends ActorMethod {
|
|
124
136
|
(...args: Args): Promise<{
|
|
125
137
|
certificate?: Certificate;
|
|
126
138
|
httpDetails?: HttpDetailsResponse;
|
|
@@ -357,6 +369,7 @@ function decodeReturnValue(types: IDL.Type[], msg: Uint8Array) {
|
|
|
357
369
|
|
|
358
370
|
const DEFAULT_ACTOR_CONFIG: Partial<ActorConfig> = {
|
|
359
371
|
pollingOptions: DEFAULT_POLLING_OPTIONS,
|
|
372
|
+
queryStrategy: 'query',
|
|
360
373
|
};
|
|
361
374
|
|
|
362
375
|
export type ActorConstructor = new (config: ActorConfig) => ActorSubclass;
|
|
@@ -371,7 +384,10 @@ function _createActorMethod(
|
|
|
371
384
|
blsVerify?: CreateCertificateOptions['blsVerify'],
|
|
372
385
|
): ActorMethod {
|
|
373
386
|
let caller: (options: CallConfig, ...args: unknown[]) => Promise<unknown>;
|
|
374
|
-
|
|
387
|
+
const isQueryAnnotated =
|
|
388
|
+
func.annotations.includes('query') || func.annotations.includes('composite_query');
|
|
389
|
+
const queryStrategy = actor[metadataSymbol].config.queryStrategy;
|
|
390
|
+
if (isQueryAnnotated && queryStrategy === 'query') {
|
|
375
391
|
caller = async (options, ...args) => {
|
|
376
392
|
// First, if there's a config transformation, call it.
|
|
377
393
|
options = {
|
|
@@ -444,126 +460,58 @@ function _createActorMethod(
|
|
|
444
460
|
const ecid = effectiveCanisterId !== undefined ? Principal.from(effectiveCanisterId) : cid;
|
|
445
461
|
const arg = IDL.encode(func.argTypes, args);
|
|
446
462
|
|
|
447
|
-
|
|
448
|
-
methodName,
|
|
449
|
-
arg,
|
|
450
|
-
effectiveCanisterId: ecid,
|
|
451
|
-
nonce: options.nonce,
|
|
452
|
-
});
|
|
453
|
-
let reply: Uint8Array | undefined;
|
|
463
|
+
let reply: Uint8Array;
|
|
454
464
|
let certificate: Certificate | undefined;
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
)
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
// Find rejection details in the certificate
|
|
478
|
-
const rejectCode = new Uint8Array(
|
|
479
|
-
lookupResultToBuffer(certificate.lookup_path([...path, 'reject_code']))!,
|
|
480
|
-
)[0];
|
|
481
|
-
const rejectMessage = new TextDecoder().decode(
|
|
482
|
-
lookupResultToBuffer(certificate.lookup_path([...path, 'reject_message']))!,
|
|
483
|
-
);
|
|
484
|
-
|
|
485
|
-
const error_code_buf = lookupResultToBuffer(
|
|
486
|
-
certificate.lookup_path([...path, 'error_code']),
|
|
487
|
-
);
|
|
488
|
-
const error_code = error_code_buf
|
|
489
|
-
? new TextDecoder().decode(error_code_buf)
|
|
490
|
-
: undefined;
|
|
491
|
-
|
|
492
|
-
const certifiedRejectErrorCode = new CertifiedRejectErrorCode(
|
|
493
|
-
requestId,
|
|
494
|
-
rejectCode,
|
|
495
|
-
rejectMessage,
|
|
496
|
-
error_code,
|
|
497
|
-
);
|
|
498
|
-
certifiedRejectErrorCode.callContext = {
|
|
499
|
-
canisterId: cid,
|
|
500
|
-
methodName,
|
|
501
|
-
httpDetails: response,
|
|
502
|
-
};
|
|
503
|
-
throw RejectError.fromCode(certifiedRejectErrorCode);
|
|
504
|
-
}
|
|
465
|
+
let callResponse: UpdateResult['callResponse'];
|
|
466
|
+
let requestDetails: UpdateResult['requestDetails'];
|
|
467
|
+
// Calls the canister and handles v4/v2 responses, falling back to polling on 202
|
|
468
|
+
try {
|
|
469
|
+
({ reply, certificate, callResponse, requestDetails } = await agent.update(
|
|
470
|
+
cid,
|
|
471
|
+
{
|
|
472
|
+
methodName,
|
|
473
|
+
arg,
|
|
474
|
+
effectiveCanisterId: ecid,
|
|
475
|
+
nonce: options.nonce,
|
|
476
|
+
},
|
|
477
|
+
{ ...pollingOptions, blsVerify },
|
|
478
|
+
));
|
|
479
|
+
} catch (e) {
|
|
480
|
+
if (e instanceof RejectError) {
|
|
481
|
+
const enrichedCode = Object.create(
|
|
482
|
+
Object.getPrototypeOf(e.code),
|
|
483
|
+
Object.getOwnPropertyDescriptors(e.code),
|
|
484
|
+
);
|
|
485
|
+
enrichedCode.callContext = { ...e.code.callContext, canisterId: cid, methodName };
|
|
486
|
+
throw RejectError.fromCode(enrichedCode);
|
|
505
487
|
}
|
|
506
|
-
|
|
507
|
-
const { reject_code, reject_message, error_code } = response.body;
|
|
508
|
-
const errorCode = new UncertifiedRejectUpdateErrorCode(
|
|
509
|
-
requestId,
|
|
510
|
-
reject_code,
|
|
511
|
-
reject_message,
|
|
512
|
-
error_code,
|
|
513
|
-
);
|
|
514
|
-
errorCode.callContext = {
|
|
515
|
-
canisterId: cid,
|
|
516
|
-
methodName,
|
|
517
|
-
httpDetails: response,
|
|
518
|
-
};
|
|
519
|
-
throw RejectError.fromCode(errorCode);
|
|
488
|
+
throw e;
|
|
520
489
|
}
|
|
521
490
|
|
|
522
|
-
// Fall back to polling if we receive an Accepted response code
|
|
523
|
-
if (response.status === 202) {
|
|
524
|
-
const pollOptions: PollingOptions = {
|
|
525
|
-
...pollingOptions,
|
|
526
|
-
blsVerify,
|
|
527
|
-
};
|
|
528
|
-
// Contains the certificate and the reply from the boundary node
|
|
529
|
-
const response = await pollForResponse(agent, ecid, requestId, pollOptions);
|
|
530
|
-
certificate = response.certificate;
|
|
531
|
-
reply = response.reply;
|
|
532
|
-
}
|
|
533
491
|
const shouldIncludeHttpDetails = func.annotations.includes(ACTOR_METHOD_WITH_HTTP_DETAILS);
|
|
534
492
|
const shouldIncludeCertificate = func.annotations.includes(ACTOR_METHOD_WITH_CERTIFICATE);
|
|
535
493
|
|
|
536
|
-
const httpDetails = { ...
|
|
537
|
-
if (
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
result: decodeReturnValue(func.retTypes, reply),
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
return decodeReturnValue(func.retTypes, reply);
|
|
556
|
-
} else {
|
|
557
|
-
const errorCode = new UnexpectedErrorCode(
|
|
558
|
-
`Call was returned undefined. We cannot determine if the call was successful or not. Return types: [${func.retTypes.map(t => t.display()).join(',')}].`,
|
|
559
|
-
);
|
|
560
|
-
errorCode.callContext = {
|
|
561
|
-
canisterId: cid,
|
|
562
|
-
methodName,
|
|
494
|
+
const httpDetails = { ...callResponse, requestDetails } as HttpDetailsResponse;
|
|
495
|
+
if (shouldIncludeHttpDetails && shouldIncludeCertificate) {
|
|
496
|
+
return {
|
|
497
|
+
httpDetails,
|
|
498
|
+
certificate,
|
|
499
|
+
result: decodeReturnValue(func.retTypes, reply),
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
if (shouldIncludeCertificate) {
|
|
503
|
+
return {
|
|
504
|
+
certificate,
|
|
505
|
+
result: decodeReturnValue(func.retTypes, reply),
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
if (shouldIncludeHttpDetails) {
|
|
509
|
+
return {
|
|
563
510
|
httpDetails,
|
|
511
|
+
result: decodeReturnValue(func.retTypes, reply),
|
|
564
512
|
};
|
|
565
|
-
throw UnknownError.fromCode(errorCode);
|
|
566
513
|
}
|
|
514
|
+
return decodeReturnValue(func.retTypes, reply);
|
|
567
515
|
};
|
|
568
516
|
}
|
|
569
517
|
|
package/src/agent/agent/api.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Principal } from '#principal';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { Principal } from '#principal';
|
|
2
|
+
import type { RequestId } from '../request_id.ts';
|
|
3
|
+
import type { JsonObject } from '#candid';
|
|
4
|
+
import type { Identity } from '../auth.ts';
|
|
5
5
|
import type { CallRequest, HttpHeaderField, QueryRequest } from './http/types.ts';
|
|
6
|
+
import type { PollForResponseResult, PollingOptions } from '../polling/index.ts';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Codes used by the replica for rejecting a message.
|
|
@@ -53,14 +54,14 @@ export interface QueryResponseBase {
|
|
|
53
54
|
requestDetails?: QueryRequest;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
export
|
|
57
|
+
export interface NodeSignature {
|
|
57
58
|
// the batch time
|
|
58
59
|
timestamp: bigint;
|
|
59
60
|
// the signature
|
|
60
61
|
signature: Uint8Array;
|
|
61
62
|
// the ID of the node that created the signature
|
|
62
63
|
identity: Uint8Array;
|
|
63
|
-
}
|
|
64
|
+
}
|
|
64
65
|
|
|
65
66
|
export interface QueryResponseReplied extends QueryResponseBase {
|
|
66
67
|
status: QueryResponseStatus.Replied;
|
|
@@ -115,6 +116,11 @@ export interface CallOptions {
|
|
|
115
116
|
* @see https://internetcomputer.org/docs/current/references/ic-interface-spec/#http-effective-canister-id
|
|
116
117
|
*/
|
|
117
118
|
effectiveCanisterId: Principal | string;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* An optional nonce to use for the call, used to prevent replay attacks.
|
|
122
|
+
*/
|
|
123
|
+
nonce?: Uint8Array;
|
|
118
124
|
}
|
|
119
125
|
|
|
120
126
|
export interface ReadStateResponse {
|
|
@@ -165,6 +171,17 @@ export interface SubmitResponse {
|
|
|
165
171
|
requestDetails?: CallRequest;
|
|
166
172
|
}
|
|
167
173
|
|
|
174
|
+
/**
|
|
175
|
+
* The result of {@link Agent.update}, extending {@link PollForResponseResult}
|
|
176
|
+
* with the request details and raw HTTP response from the call.
|
|
177
|
+
*/
|
|
178
|
+
export interface UpdateResult extends PollForResponseResult {
|
|
179
|
+
/** The request details from the call, if available. */
|
|
180
|
+
requestDetails?: CallRequest;
|
|
181
|
+
/** The raw HTTP response from the call endpoint. */
|
|
182
|
+
callResponse: SubmitResponse['response'];
|
|
183
|
+
}
|
|
184
|
+
|
|
168
185
|
/**
|
|
169
186
|
* An Agent able to make calls and queries to a Replica.
|
|
170
187
|
*/
|
|
@@ -202,6 +219,19 @@ export interface Agent {
|
|
|
202
219
|
|
|
203
220
|
call(canisterId: Principal | string, fields: CallOptions): Promise<SubmitResponse>;
|
|
204
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Executes an update call to a canister and returns the certified result.
|
|
224
|
+
* @param canisterId The canister to call.
|
|
225
|
+
* @param fields The call options (method name, arg, effective canister ID, optional nonce).
|
|
226
|
+
* @param pollingOptions Optional polling configuration.
|
|
227
|
+
* @returns The certified result including the certificate, reply bytes, and raw certificate bytes.
|
|
228
|
+
*/
|
|
229
|
+
update(
|
|
230
|
+
canisterId: Principal | string,
|
|
231
|
+
fields: CallOptions,
|
|
232
|
+
pollingOptions?: PollingOptions,
|
|
233
|
+
): Promise<UpdateResult>;
|
|
234
|
+
|
|
205
235
|
/**
|
|
206
236
|
* Query the status endpoint of the replica. This normally has a few fields that
|
|
207
237
|
* corresponds to the version of the replica, its root public key, and any other
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { lebEncode } from '#candid';
|
|
2
|
+
import { ExpiryJsonDeserializeErrorCode, InputError } from '../../errors.ts';
|
|
3
|
+
|
|
4
|
+
export const JSON_KEY_EXPIRY = '__expiry__';
|
|
5
|
+
const SECONDS_TO_MILLISECONDS = BigInt(1_000);
|
|
6
|
+
const MILLISECONDS_TO_NANOSECONDS = BigInt(1_000_000);
|
|
7
|
+
const MINUTES_TO_SECONDS = BigInt(60);
|
|
8
|
+
const MINUTES_TO_MILLISECONDS = MINUTES_TO_SECONDS * SECONDS_TO_MILLISECONDS;
|
|
9
|
+
|
|
10
|
+
const EXPIRY_DELTA_THRESHOLD_MILLISECONDS = BigInt(1) * MINUTES_TO_MILLISECONDS;
|
|
11
|
+
|
|
12
|
+
function roundToSecond(millis: bigint): bigint {
|
|
13
|
+
return (millis / SECONDS_TO_MILLISECONDS) * SECONDS_TO_MILLISECONDS;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function roundToMinute(millis: bigint): bigint {
|
|
17
|
+
return (millis / MINUTES_TO_MILLISECONDS) * MINUTES_TO_MILLISECONDS;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface JsonnableExpiry {
|
|
21
|
+
[JSON_KEY_EXPIRY]: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class Expiry {
|
|
25
|
+
public readonly _isExpiry = true;
|
|
26
|
+
|
|
27
|
+
private constructor(private readonly __expiry__: bigint) {}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates an Expiry object from a delta in milliseconds.
|
|
31
|
+
* The expiry is calculated as: current_time + delta + clock_drift
|
|
32
|
+
* The resulting expiry is then rounded:
|
|
33
|
+
* - If rounding down to the nearest minute still provides at least 60 seconds in the future, use minute precision
|
|
34
|
+
* - Otherwise, use second precision
|
|
35
|
+
* @param deltaInMs The milliseconds to add to the current time.
|
|
36
|
+
* @param clockDriftInMs The milliseconds to add to the current time, typically the clock drift between IC network clock and the client's clock. Defaults to `0` if not provided.
|
|
37
|
+
* @returns {Expiry} The constructed Expiry object.
|
|
38
|
+
*/
|
|
39
|
+
public static fromDeltaInMilliseconds(deltaInMs: number, clockDriftInMs: number = 0): Expiry {
|
|
40
|
+
const correctedNowMs = BigInt(Date.now()) + BigInt(clockDriftInMs);
|
|
41
|
+
const expiryMs = correctedNowMs + BigInt(deltaInMs);
|
|
42
|
+
|
|
43
|
+
const roundedToMinute = roundToMinute(expiryMs);
|
|
44
|
+
|
|
45
|
+
let roundedExpiryMs: bigint;
|
|
46
|
+
if (roundedToMinute >= correctedNowMs + EXPIRY_DELTA_THRESHOLD_MILLISECONDS) {
|
|
47
|
+
roundedExpiryMs = roundedToMinute;
|
|
48
|
+
} else {
|
|
49
|
+
const roundedToSecond = roundToSecond(expiryMs);
|
|
50
|
+
roundedExpiryMs = roundedToSecond;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return new Expiry(roundedExpiryMs * MILLISECONDS_TO_NANOSECONDS);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public toBigInt(): bigint {
|
|
57
|
+
return this.__expiry__;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public toHash(): Uint8Array {
|
|
61
|
+
return lebEncode(this.__expiry__);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public toString(): string {
|
|
65
|
+
return this.__expiry__.toString();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Serializes to JSON
|
|
70
|
+
* @returns {JsonnableExpiry} a JSON object with a single key, {@link JSON_KEY_EXPIRY}, whose value is the expiry as a string
|
|
71
|
+
*/
|
|
72
|
+
public toJSON(): JsonnableExpiry {
|
|
73
|
+
return { [JSON_KEY_EXPIRY]: this.toString() };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Deserializes a {@link JsonnableExpiry} object from a JSON string.
|
|
78
|
+
* @param input The JSON string to deserialize.
|
|
79
|
+
* @returns {Expiry} The deserialized Expiry object.
|
|
80
|
+
*/
|
|
81
|
+
public static fromJSON(input: string): Expiry {
|
|
82
|
+
const obj = JSON.parse(input);
|
|
83
|
+
if (obj[JSON_KEY_EXPIRY]) {
|
|
84
|
+
try {
|
|
85
|
+
const expiry = BigInt(obj[JSON_KEY_EXPIRY]);
|
|
86
|
+
return new Expiry(expiry);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
throw new InputError(new ExpiryJsonDeserializeErrorCode(`Not a valid BigInt: ${error}`));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
throw new InputError(
|
|
92
|
+
new ExpiryJsonDeserializeErrorCode(`The input does not contain the key ${JSON_KEY_EXPIRY}`),
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public static isExpiry(other: unknown): other is Expiry {
|
|
97
|
+
return (
|
|
98
|
+
other instanceof Expiry ||
|
|
99
|
+
(typeof other === 'object' &&
|
|
100
|
+
other !== null &&
|
|
101
|
+
'_isExpiry' in other &&
|
|
102
|
+
(other as { _isExpiry: boolean })['_isExpiry'] === true &&
|
|
103
|
+
'__expiry__' in other &&
|
|
104
|
+
typeof (other as { __expiry__: bigint })['__expiry__'] === 'bigint')
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|