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