@icp-sdk/core 5.4.0 → 6.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 +7 -3
- package/lib/cjs/agent/actor.d.ts.map +1 -1
- package/lib/cjs/agent/actor.js +18 -5
- package/lib/cjs/agent/actor.js.map +1 -1
- package/lib/cjs/agent/agent/api.d.ts +71 -10
- package/lib/cjs/agent/agent/api.d.ts.map +1 -1
- package/lib/cjs/agent/agent/api.js +6 -1
- package/lib/cjs/agent/agent/api.js.map +1 -1
- package/lib/cjs/agent/agent/http/index.d.ts +9 -12
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/index.js +224 -176
- package/lib/cjs/agent/agent/http/index.js.map +1 -1
- package/lib/cjs/agent/auth.d.ts +6 -5
- package/lib/cjs/agent/auth.d.ts.map +1 -1
- package/lib/cjs/agent/auth.js +3 -3
- package/lib/cjs/agent/auth.js.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.d.ts +2 -3
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.js +65 -122
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
- package/lib/cjs/agent/cbor.d.ts +2 -1
- package/lib/cjs/agent/cbor.d.ts.map +1 -1
- package/lib/cjs/agent/cbor.js +4 -1
- package/lib/cjs/agent/cbor.js.map +1 -1
- package/lib/cjs/agent/certificate.d.ts +6 -5
- package/lib/cjs/agent/certificate.d.ts.map +1 -1
- package/lib/cjs/agent/certificate.js +14 -18
- package/lib/cjs/agent/certificate.js.map +1 -1
- package/lib/cjs/agent/der.d.ts +3 -2
- package/lib/cjs/agent/der.d.ts.map +1 -1
- package/lib/cjs/agent/der.js.map +1 -1
- package/lib/cjs/agent/errors.d.ts +7 -1
- package/lib/cjs/agent/errors.d.ts.map +1 -1
- package/lib/cjs/agent/errors.js +34 -16
- package/lib/cjs/agent/errors.js.map +1 -1
- package/lib/cjs/agent/polling/index.d.ts +7 -7
- package/lib/cjs/agent/polling/index.d.ts.map +1 -1
- package/lib/cjs/agent/polling/index.js +19 -20
- package/lib/cjs/agent/polling/index.js.map +1 -1
- package/lib/cjs/agent/polling/strategy.d.ts.map +1 -1
- package/lib/cjs/agent/polling/strategy.js +6 -6
- package/lib/cjs/agent/polling/strategy.js.map +1 -1
- package/lib/cjs/agent/polling/types.d.ts +3 -4
- package/lib/cjs/agent/polling/types.d.ts.map +1 -1
- package/lib/cjs/agent/public_key.d.ts +3 -2
- package/lib/cjs/agent/public_key.d.ts.map +1 -1
- package/lib/cjs/agent/public_key.js +2 -2
- package/lib/cjs/agent/public_key.js.map +1 -1
- package/lib/cjs/agent/request_id.js +10 -10
- package/lib/cjs/agent/request_id.js.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.d.ts +3 -2
- package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.js +65 -88
- package/lib/cjs/agent/subnetStatus/index.js.map +1 -1
- package/lib/cjs/agent/utils/bls.d.ts.map +1 -1
- package/lib/cjs/agent/utils/bls.js +7 -6
- package/lib/cjs/agent/utils/bls.js.map +1 -1
- package/lib/cjs/agent/utils/readState.d.ts +104 -15
- package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
- package/lib/cjs/agent/utils/readState.js +106 -17
- package/lib/cjs/agent/utils/readState.js.map +1 -1
- package/lib/cjs/agent/utils/target.d.ts +15 -0
- package/lib/cjs/agent/utils/target.d.ts.map +1 -0
- package/lib/cjs/agent/utils/target.js +27 -0
- package/lib/cjs/agent/utils/target.js.map +1 -0
- package/lib/cjs/candid/utils/buffer.d.ts +2 -1
- package/lib/cjs/candid/utils/buffer.d.ts.map +1 -1
- package/lib/cjs/candid/utils/buffer.js +5 -2
- package/lib/cjs/candid/utils/buffer.js.map +1 -1
- package/lib/cjs/identity/identity/delegation.d.ts +10 -3
- package/lib/cjs/identity/identity/delegation.d.ts.map +1 -1
- package/lib/cjs/identity/identity/delegation.js +25 -12
- 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 +3 -2
- package/lib/cjs/identity/identity/ecdsa.js.map +1 -1
- package/lib/cjs/identity/identity/ed25519.d.ts +3 -2
- package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -1
- package/lib/cjs/identity/identity/ed25519.js +18 -15
- package/lib/cjs/identity/identity/ed25519.js.map +1 -1
- package/lib/cjs/identity/identity/webauthn.d.ts +4 -3
- package/lib/cjs/identity/identity/webauthn.d.ts.map +1 -1
- package/lib/cjs/identity/identity/webauthn.js +12 -11
- package/lib/cjs/identity/identity/webauthn.js.map +1 -1
- package/lib/cjs/identity/secp256k1/der.d.ts +2 -1
- package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/der.js.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.d.ts +4 -3
- package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.js +2 -2
- package/lib/cjs/identity/secp256k1/pem.js.map +1 -1
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts +5 -4
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/secp256k1.js +17 -20
- package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -1
- package/lib/cjs/principal/principal.js +5 -5
- package/lib/cjs/principal/principal.js.map +1 -1
- package/lib/esm/agent/actor.d.ts +7 -3
- package/lib/esm/agent/actor.d.ts.map +1 -1
- package/lib/esm/agent/actor.js +18 -5
- package/lib/esm/agent/actor.js.map +1 -1
- package/lib/esm/agent/agent/api.d.ts +71 -10
- package/lib/esm/agent/agent/api.d.ts.map +1 -1
- package/lib/esm/agent/agent/api.js +1 -0
- package/lib/esm/agent/agent/api.js.map +1 -1
- package/lib/esm/agent/agent/http/index.d.ts +9 -12
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/index.js +218 -170
- package/lib/esm/agent/agent/http/index.js.map +1 -1
- package/lib/esm/agent/auth.d.ts +6 -5
- package/lib/esm/agent/auth.d.ts.map +1 -1
- package/lib/esm/agent/auth.js +1 -1
- package/lib/esm/agent/auth.js.map +1 -1
- package/lib/esm/agent/canister-env/index.js +1 -1
- package/lib/esm/agent/canister-env/index.js.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts +2 -3
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/canisterStatus/index.js +66 -122
- package/lib/esm/agent/canisterStatus/index.js.map +1 -1
- package/lib/esm/agent/cbor.d.ts +2 -1
- package/lib/esm/agent/cbor.d.ts.map +1 -1
- package/lib/esm/agent/cbor.js +4 -1
- package/lib/esm/agent/cbor.js.map +1 -1
- package/lib/esm/agent/certificate.d.ts +6 -5
- package/lib/esm/agent/certificate.d.ts.map +1 -1
- package/lib/esm/agent/certificate.js +5 -9
- package/lib/esm/agent/certificate.js.map +1 -1
- package/lib/esm/agent/der.d.ts +3 -2
- package/lib/esm/agent/der.d.ts.map +1 -1
- package/lib/esm/agent/der.js.map +1 -1
- package/lib/esm/agent/errors.d.ts +7 -1
- package/lib/esm/agent/errors.d.ts.map +1 -1
- package/lib/esm/agent/errors.js +18 -1
- package/lib/esm/agent/errors.js.map +1 -1
- package/lib/esm/agent/polling/index.d.ts +7 -7
- package/lib/esm/agent/polling/index.d.ts.map +1 -1
- package/lib/esm/agent/polling/index.js +19 -20
- package/lib/esm/agent/polling/index.js.map +1 -1
- package/lib/esm/agent/polling/strategy.d.ts.map +1 -1
- package/lib/esm/agent/polling/strategy.js +6 -6
- package/lib/esm/agent/polling/strategy.js.map +1 -1
- package/lib/esm/agent/polling/types.d.ts +3 -4
- package/lib/esm/agent/polling/types.d.ts.map +1 -1
- package/lib/esm/agent/public_key.d.ts +3 -2
- package/lib/esm/agent/public_key.d.ts.map +1 -1
- package/lib/esm/agent/public_key.js +2 -2
- package/lib/esm/agent/public_key.js.map +1 -1
- package/lib/esm/agent/request_id.js +2 -2
- package/lib/esm/agent/request_id.js.map +1 -1
- package/lib/esm/agent/subnetStatus/index.d.ts +3 -2
- package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/subnetStatus/index.js +63 -86
- package/lib/esm/agent/subnetStatus/index.js.map +1 -1
- package/lib/esm/agent/utils/bls.d.ts.map +1 -1
- package/lib/esm/agent/utils/bls.js +7 -6
- package/lib/esm/agent/utils/bls.js.map +1 -1
- package/lib/esm/agent/utils/readState.d.ts +104 -15
- package/lib/esm/agent/utils/readState.d.ts.map +1 -1
- package/lib/esm/agent/utils/readState.js +103 -16
- package/lib/esm/agent/utils/readState.js.map +1 -1
- package/lib/esm/agent/utils/target.d.ts +15 -0
- package/lib/esm/agent/utils/target.d.ts.map +1 -0
- package/lib/esm/agent/utils/target.js +23 -0
- package/lib/esm/agent/utils/target.js.map +1 -0
- package/lib/esm/candid/utils/buffer.d.ts +2 -1
- package/lib/esm/candid/utils/buffer.d.ts.map +1 -1
- package/lib/esm/candid/utils/buffer.js +5 -2
- package/lib/esm/candid/utils/buffer.js.map +1 -1
- package/lib/esm/identity/identity/delegation.d.ts +10 -3
- package/lib/esm/identity/identity/delegation.d.ts.map +1 -1
- package/lib/esm/identity/identity/delegation.js +22 -9
- 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 +3 -2
- package/lib/esm/identity/identity/ecdsa.js.map +1 -1
- package/lib/esm/identity/identity/ed25519.d.ts +3 -2
- package/lib/esm/identity/identity/ed25519.d.ts.map +1 -1
- package/lib/esm/identity/identity/ed25519.js +10 -7
- package/lib/esm/identity/identity/ed25519.js.map +1 -1
- package/lib/esm/identity/identity/webauthn.d.ts +4 -3
- package/lib/esm/identity/identity/webauthn.d.ts.map +1 -1
- package/lib/esm/identity/identity/webauthn.js +8 -7
- package/lib/esm/identity/identity/webauthn.js.map +1 -1
- package/lib/esm/identity/secp256k1/der.d.ts +2 -1
- package/lib/esm/identity/secp256k1/der.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/der.js.map +1 -1
- package/lib/esm/identity/secp256k1/pem.d.ts +4 -3
- package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/pem.js +2 -2
- package/lib/esm/identity/secp256k1/pem.js.map +1 -1
- package/lib/esm/identity/secp256k1/secp256k1.d.ts +5 -4
- package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/secp256k1.js +10 -13
- package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -1
- package/lib/esm/principal/principal.js +2 -2
- package/lib/esm/principal/principal.js.map +1 -1
- package/package.json +20 -10
- package/src/agent/actor.ts +0 -524
- package/src/agent/agent/api.ts +0 -310
- package/src/agent/agent/http/expiry.ts +0 -107
- package/src/agent/agent/http/index.ts +0 -1724
- package/src/agent/agent/http/transforms.ts +0 -54
- package/src/agent/agent/http/types.ts +0 -145
- package/src/agent/agent/index.ts +0 -4
- package/src/agent/auth.ts +0 -147
- package/src/agent/canister-env/index.ts +0 -192
- package/src/agent/canisterStatus/index.ts +0 -260
- package/src/agent/cbor.ts +0 -63
- package/src/agent/certificate.ts +0 -1058
- package/src/agent/constants.ts +0 -24
- package/src/agent/der.ts +0 -191
- package/src/agent/errors.ts +0 -962
- package/src/agent/fetch_candid.ts +0 -37
- package/src/agent/index.ts +0 -130
- package/src/agent/observable.ts +0 -49
- package/src/agent/polling/backoff.ts +0 -129
- package/src/agent/polling/index.ts +0 -238
- package/src/agent/polling/strategy.ts +0 -140
- package/src/agent/polling/types.ts +0 -28
- package/src/agent/public_key.ts +0 -65
- package/src/agent/request_id.ts +0 -99
- package/src/agent/subnetStatus/index.ts +0 -263
- package/src/agent/utils/bls.ts +0 -18
- package/src/agent/utils/buffer.ts +0 -64
- package/src/agent/utils/certificateReject.ts +0 -25
- package/src/agent/utils/createExpirableStore.ts +0 -31
- package/src/agent/utils/expirableStore.ts +0 -47
- package/src/agent/utils/inMemoryExpirableStore.ts +0 -49
- package/src/agent/utils/indexedDBExpirableStore.ts +0 -191
- package/src/agent/utils/leb.ts +0 -14
- package/src/agent/utils/random.ts +0 -30
- package/src/agent/utils/readState.ts +0 -180
- package/src/candid/candid-core.ts +0 -274
- package/src/candid/candid-ui.ts +0 -281
- package/src/candid/idl.ts +0 -2654
- package/src/candid/index.ts +0 -35
- package/src/candid/types.ts +0 -7
- package/src/candid/utils/bigint-math.ts +0 -26
- package/src/candid/utils/buffer.ts +0 -221
- package/src/candid/utils/hash.ts +0 -31
- package/src/candid/utils/leb128.ts +0 -233
- package/src/identity/identity/attributes.ts +0 -91
- package/src/identity/identity/delegation.ts +0 -411
- package/src/identity/identity/ecdsa.ts +0 -162
- package/src/identity/identity/ed25519.ts +0 -246
- package/src/identity/identity/partial.ts +0 -60
- package/src/identity/identity/webauthn.ts +0 -265
- package/src/identity/index.ts +0 -44
- package/src/identity/secp256k1/der.ts +0 -177
- package/src/identity/secp256k1/index.ts +0 -52
- package/src/identity/secp256k1/pem.ts +0 -39
- package/src/identity/secp256k1/secp256k1.ts +0 -276
- package/src/index.ts +0 -3
- package/src/principal/index.ts +0 -19
- package/src/principal/principal.ts +0 -181
- package/src/principal/utils/base32.ts +0 -101
- package/src/principal/utils/getCrc.ts +0 -52
package/src/agent/agent/api.ts
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
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
|
-
import type { CallRequest, HttpHeaderField, QueryRequest } from './http/types.ts';
|
|
6
|
-
import type { PollForResponseResult, PollingOptions } from '../polling/index.ts';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Codes used by the replica for rejecting a message.
|
|
10
|
-
* See {@link https://sdk.dfinity.org/docs/interface-spec/#reject-codes | the interface spec}.
|
|
11
|
-
*/
|
|
12
|
-
export enum ReplicaRejectCode {
|
|
13
|
-
SysFatal = 1,
|
|
14
|
-
SysTransient = 2,
|
|
15
|
-
DestinationInvalid = 3,
|
|
16
|
-
CanisterReject = 4,
|
|
17
|
-
CanisterError = 5,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Options when doing a {@link Agent.readState} call.
|
|
22
|
-
*/
|
|
23
|
-
export interface ReadStateOptions {
|
|
24
|
-
/**
|
|
25
|
-
* A list of paths to read the state of.
|
|
26
|
-
*/
|
|
27
|
-
paths: Uint8Array[][];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
export type QueryResponse = QueryResponseReplied | QueryResponseRejected;
|
|
34
|
-
|
|
35
|
-
export enum QueryResponseStatus {
|
|
36
|
-
Replied = 'replied',
|
|
37
|
-
Rejected = 'rejected',
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface HttpDetailsResponse {
|
|
41
|
-
ok: boolean;
|
|
42
|
-
status: number;
|
|
43
|
-
statusText: string;
|
|
44
|
-
headers: HttpHeaderField[];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type ApiQueryResponse = QueryResponse & {
|
|
48
|
-
httpDetails: HttpDetailsResponse;
|
|
49
|
-
requestId: RequestId;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export interface QueryResponseBase {
|
|
53
|
-
status: QueryResponseStatus;
|
|
54
|
-
requestDetails?: QueryRequest;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface NodeSignature {
|
|
58
|
-
// the batch time
|
|
59
|
-
timestamp: bigint;
|
|
60
|
-
// the signature
|
|
61
|
-
signature: Uint8Array;
|
|
62
|
-
// the ID of the node that created the signature
|
|
63
|
-
identity: Uint8Array;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface QueryResponseReplied extends QueryResponseBase {
|
|
67
|
-
status: QueryResponseStatus.Replied;
|
|
68
|
-
reply: { arg: Uint8Array };
|
|
69
|
-
signatures?: NodeSignature[];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface QueryResponseRejected extends QueryResponseBase {
|
|
73
|
-
status: QueryResponseStatus.Rejected;
|
|
74
|
-
reject_code: ReplicaRejectCode;
|
|
75
|
-
reject_message: string;
|
|
76
|
-
error_code: string;
|
|
77
|
-
signatures?: NodeSignature[];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Options when doing a {@link Agent.query} call.
|
|
82
|
-
*/
|
|
83
|
-
export interface QueryFields {
|
|
84
|
-
/**
|
|
85
|
-
* The method name to call.
|
|
86
|
-
*/
|
|
87
|
-
methodName: string;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* A binary encoded argument. This is already encoded and will be sent as is.
|
|
91
|
-
*/
|
|
92
|
-
arg: Uint8Array;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Overrides canister id for path to fetch. This is used for management canister calls.
|
|
96
|
-
*/
|
|
97
|
-
effectiveCanisterId?: Principal;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Options when doing a {@link Agent.call} call.
|
|
102
|
-
*/
|
|
103
|
-
export interface CallOptions {
|
|
104
|
-
/**
|
|
105
|
-
* The method name to call.
|
|
106
|
-
*/
|
|
107
|
-
methodName: string;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* A binary encoded argument. This is already encoded and will be sent as is.
|
|
111
|
-
*/
|
|
112
|
-
arg: Uint8Array;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* An effective canister ID, used for routing. Usually the canister ID, except for management canister calls.
|
|
116
|
-
* @see https://internetcomputer.org/docs/current/references/ic-interface-spec/#http-effective-canister-id
|
|
117
|
-
*/
|
|
118
|
-
effectiveCanisterId: Principal | string;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Whether to use synchronous call mode. Defaults to true.
|
|
122
|
-
*/
|
|
123
|
-
callSync?: boolean;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* An optional nonce to use for the call, used to prevent replay attacks.
|
|
127
|
-
*/
|
|
128
|
-
nonce?: Uint8Array;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface UpdateOptions extends CallOptions {
|
|
132
|
-
/**
|
|
133
|
-
* An optional callback that will be invoked once the agent starts polling for the result of the
|
|
134
|
-
* update call.
|
|
135
|
-
*
|
|
136
|
-
* If `callSync` is set to false, polling will start, and the callback will be invoked, once the
|
|
137
|
-
* request has been accepted by a single node. If `callSync` is set to true, the IC will first
|
|
138
|
-
* try to process the request synchronously. But if the synchronous request timeout is exceeded,
|
|
139
|
-
* the agent will start polling for the result, at which point the callback will be invoked.
|
|
140
|
-
*/
|
|
141
|
-
onPollingStarted?: () => void;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export interface ReadStateResponse {
|
|
145
|
-
certificate: Uint8Array;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export interface v2ResponseBody {
|
|
149
|
-
error_code?: string;
|
|
150
|
-
reject_code: number;
|
|
151
|
-
reject_message: string;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Utility function to check if a body is a v2ResponseBody for type safety.
|
|
156
|
-
* @param body The body to check
|
|
157
|
-
* @returns boolean indicating if the body is a v2ResponseBody
|
|
158
|
-
*/
|
|
159
|
-
export function isV2ResponseBody(
|
|
160
|
-
body: v2ResponseBody | v4ResponseBody | null,
|
|
161
|
-
): body is v2ResponseBody {
|
|
162
|
-
return body !== null && body !== undefined && 'reject_code' in body;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export interface v4ResponseBody {
|
|
166
|
-
certificate: Uint8Array;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Utility function to check if a body is a v4ResponseBody for type safety.
|
|
171
|
-
* @param body The body to check
|
|
172
|
-
* @returns boolean indicating if the body is a v4ResponseBody
|
|
173
|
-
*/
|
|
174
|
-
export function isV4ResponseBody(
|
|
175
|
-
body: v2ResponseBody | v4ResponseBody | null,
|
|
176
|
-
): body is v4ResponseBody {
|
|
177
|
-
return body !== null && body !== undefined && 'certificate' in body;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export interface SubmitResponse {
|
|
181
|
-
requestId: RequestId;
|
|
182
|
-
response: {
|
|
183
|
-
ok: boolean;
|
|
184
|
-
status: number;
|
|
185
|
-
statusText: string;
|
|
186
|
-
body: v2ResponseBody | v4ResponseBody | null;
|
|
187
|
-
headers: HttpHeaderField[];
|
|
188
|
-
};
|
|
189
|
-
requestDetails?: CallRequest;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* The result of {@link Agent.update}, extending {@link PollForResponseResult}
|
|
194
|
-
* with the request details and raw HTTP response from the call.
|
|
195
|
-
*/
|
|
196
|
-
export interface UpdateResult extends PollForResponseResult {
|
|
197
|
-
/** The request details from the call, if available. */
|
|
198
|
-
requestDetails?: CallRequest;
|
|
199
|
-
/** The raw HTTP response from the call endpoint. */
|
|
200
|
-
callResponse: SubmitResponse['response'];
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* An Agent able to make calls and queries to a Replica.
|
|
205
|
-
*/
|
|
206
|
-
export interface Agent {
|
|
207
|
-
readonly rootKey: Uint8Array | null;
|
|
208
|
-
/**
|
|
209
|
-
* Returns the principal ID associated with this agent (by default). It only shows
|
|
210
|
-
* the principal of the default identity in the agent, which is the principal used
|
|
211
|
-
* when calls don't specify it.
|
|
212
|
-
*/
|
|
213
|
-
getPrincipal(): Promise<Principal>;
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Create the request for the read state call.
|
|
217
|
-
* `readState` uses this internally.
|
|
218
|
-
* Useful to avoid signing the same request multiple times.
|
|
219
|
-
*/
|
|
220
|
-
createReadStateRequest?(options: ReadStateOptions, identity?: Identity): Promise<unknown>;
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Send a read state query to the replica. This includes a list of paths to return,
|
|
224
|
-
* and will return a Certificate. This will only reject on communication errors,
|
|
225
|
-
* but the certificate might contain less information than requested.
|
|
226
|
-
* @param effectiveCanisterId A Canister ID related to this call.
|
|
227
|
-
* @param options The options for this call.
|
|
228
|
-
* @param identity Identity for the call. If not specified, uses the instance identity.
|
|
229
|
-
* @param request The request to send in case it has already been created.
|
|
230
|
-
*/
|
|
231
|
-
readState(
|
|
232
|
-
effectiveCanisterId: Principal | string,
|
|
233
|
-
options: ReadStateOptions,
|
|
234
|
-
identity?: Identity,
|
|
235
|
-
request?: unknown,
|
|
236
|
-
): Promise<ReadStateResponse>;
|
|
237
|
-
|
|
238
|
-
call(canisterId: Principal | string, fields: CallOptions): Promise<SubmitResponse>;
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Executes an update call to a canister and returns the certified result.
|
|
242
|
-
* @param canisterId The canister to call.
|
|
243
|
-
* @param fields The call options (method name, arg, effective canister ID, optional nonce).
|
|
244
|
-
* @param pollingOptions Optional polling configuration.
|
|
245
|
-
* @returns The certified result including the certificate, reply bytes, and raw certificate bytes.
|
|
246
|
-
*/
|
|
247
|
-
update(
|
|
248
|
-
canisterId: Principal | string,
|
|
249
|
-
fields: CallOptions,
|
|
250
|
-
pollingOptions?: PollingOptions,
|
|
251
|
-
): Promise<UpdateResult>;
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Query the status endpoint of the replica. This normally has a few fields that
|
|
255
|
-
* corresponds to the version of the replica, its root public key, and any other
|
|
256
|
-
* information made public.
|
|
257
|
-
* @returns A JsonObject that is essentially a record of fields from the status
|
|
258
|
-
* endpoint.
|
|
259
|
-
*/
|
|
260
|
-
status(): Promise<JsonObject>;
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Send a query call to a canister. See
|
|
264
|
-
* {@link https://sdk.dfinity.org/docs/interface-spec/#http-query | the interface spec}.
|
|
265
|
-
* @param canisterId The Principal of the Canister to send the query to. Sending a query to
|
|
266
|
-
* the management canister is not supported (as it has no meaning from an agent).
|
|
267
|
-
* @param options Options to use to create and send the query.
|
|
268
|
-
* @param identity Sender principal to use when sending the query.
|
|
269
|
-
* @returns The response from the replica. The Promise will only reject when the communication
|
|
270
|
-
* failed. If the query itself failed but no protocol errors happened, the response will
|
|
271
|
-
* be of type QueryResponseRejected.
|
|
272
|
-
*/
|
|
273
|
-
query(
|
|
274
|
-
canisterId: Principal | string,
|
|
275
|
-
options: QueryFields,
|
|
276
|
-
identity?: Identity | Promise<Identity>,
|
|
277
|
-
): Promise<ApiQueryResponse>;
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* By default, the agent is configured to talk to the main Internet Computer,
|
|
281
|
-
* and verifies responses using a hard-coded public key.
|
|
282
|
-
*
|
|
283
|
-
* This function will instruct the agent to ask the endpoint for its public
|
|
284
|
-
* key, and use that instead. This is required when talking to a local test
|
|
285
|
-
* instance, for example.
|
|
286
|
-
*
|
|
287
|
-
* Only use this when you are _not_ talking to the main Internet Computer,
|
|
288
|
-
* otherwise you are prone to man-in-the-middle attacks! Do not call this
|
|
289
|
-
* function by default.
|
|
290
|
-
*/
|
|
291
|
-
fetchRootKey(): Promise<Uint8Array>;
|
|
292
|
-
/**
|
|
293
|
-
* If an application needs to invalidate an identity under certain conditions, an `Agent` may expose an `invalidateIdentity` method.
|
|
294
|
-
* Invoking this method will set the inner identity used by the `Agent` to `null`.
|
|
295
|
-
*
|
|
296
|
-
* A use case for this would be - after a certain period of inactivity, a secure application chooses to invalidate the identity of any `HttpAgent` instances. An invalid identity can be replaced by `Agent.replaceIdentity`
|
|
297
|
-
*/
|
|
298
|
-
invalidateIdentity?(): void;
|
|
299
|
-
/**
|
|
300
|
-
* If an application needs to replace an identity under certain conditions, an `Agent` may expose a `replaceIdentity` method.
|
|
301
|
-
* Invoking this method will set the inner identity used by the `Agent` to a newly provided identity.
|
|
302
|
-
*
|
|
303
|
-
* A use case for this would be - after authenticating using `@icp-sdk/auth/client`, you can replace the `AnonymousIdentity` of your `Actor` with a `DelegationIdentity`.
|
|
304
|
-
*
|
|
305
|
-
* ```ts
|
|
306
|
-
* Actor.agentOf(defaultActor).replaceIdentity(await authClient.getIdentity());
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
replaceIdentity?(identity: Identity): void;
|
|
310
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
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
|
-
}
|