@icp-sdk/core 5.0.0 → 5.2.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (331) hide show
  1. package/lib/cjs/agent/actor.d.ts +15 -1
  2. package/lib/cjs/agent/actor.d.ts.map +1 -1
  3. package/lib/cjs/agent/actor.js +37 -91
  4. package/lib/cjs/agent/actor.js.map +1 -1
  5. package/lib/cjs/agent/agent/api.d.ts +29 -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/expiry.d.ts +36 -0
  9. package/lib/cjs/agent/agent/http/expiry.d.ts.map +1 -0
  10. package/lib/cjs/agent/agent/http/expiry.js +92 -0
  11. package/lib/cjs/agent/agent/http/expiry.js.map +1 -0
  12. package/lib/cjs/agent/agent/http/index.d.ts +28 -2
  13. package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
  14. package/lib/cjs/agent/agent/http/index.js +182 -90
  15. package/lib/cjs/agent/agent/http/index.js.map +1 -1
  16. package/lib/cjs/agent/agent/http/transforms.d.ts +1 -35
  17. package/lib/cjs/agent/agent/http/transforms.d.ts.map +1 -1
  18. package/lib/cjs/agent/agent/http/transforms.js +6 -90
  19. package/lib/cjs/agent/agent/http/transforms.js.map +1 -1
  20. package/lib/cjs/agent/agent/http/types.d.ts +1 -1
  21. package/lib/cjs/agent/agent/http/types.d.ts.map +1 -1
  22. package/lib/cjs/agent/auth.d.ts +1 -1
  23. package/lib/cjs/agent/auth.d.ts.map +1 -1
  24. package/lib/cjs/agent/canisterStatus/index.d.ts +5 -4
  25. package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
  26. package/lib/cjs/agent/canisterStatus/index.js +6 -10
  27. package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
  28. package/lib/cjs/agent/cbor.js +2 -2
  29. package/lib/cjs/agent/cbor.js.map +1 -1
  30. package/lib/cjs/agent/certificate.d.ts +4 -4
  31. package/lib/cjs/agent/certificate.d.ts.map +1 -1
  32. package/lib/cjs/agent/certificate.js +6 -10
  33. package/lib/cjs/agent/certificate.js.map +1 -1
  34. package/lib/cjs/agent/constants.d.ts +4 -4
  35. package/lib/cjs/agent/constants.d.ts.map +1 -1
  36. package/lib/cjs/agent/der.d.ts.map +1 -1
  37. package/lib/cjs/agent/der.js +26 -21
  38. package/lib/cjs/agent/der.js.map +1 -1
  39. package/lib/cjs/agent/errors.d.ts +45 -19
  40. package/lib/cjs/agent/errors.d.ts.map +1 -1
  41. package/lib/cjs/agent/errors.js +58 -18
  42. package/lib/cjs/agent/errors.js.map +1 -1
  43. package/lib/cjs/agent/index.d.ts +1 -0
  44. package/lib/cjs/agent/index.d.ts.map +1 -1
  45. package/lib/cjs/agent/index.js.map +1 -1
  46. package/lib/cjs/agent/observable.d.ts +1 -1
  47. package/lib/cjs/agent/observable.d.ts.map +1 -1
  48. package/lib/cjs/agent/polling/backoff.d.ts +7 -7
  49. package/lib/cjs/agent/polling/backoff.d.ts.map +1 -1
  50. package/lib/cjs/agent/polling/backoff.js +3 -5
  51. package/lib/cjs/agent/polling/backoff.js.map +1 -1
  52. package/lib/cjs/agent/polling/index.d.ts +11 -10
  53. package/lib/cjs/agent/polling/index.d.ts.map +1 -1
  54. package/lib/cjs/agent/polling/index.js +8 -6
  55. package/lib/cjs/agent/polling/index.js.map +1 -1
  56. package/lib/cjs/agent/polling/strategy.d.ts +2 -5
  57. package/lib/cjs/agent/polling/strategy.d.ts.map +1 -1
  58. package/lib/cjs/agent/polling/strategy.js.map +1 -1
  59. package/lib/cjs/agent/polling/types.d.ts +18 -0
  60. package/lib/cjs/agent/polling/types.d.ts.map +1 -0
  61. package/lib/cjs/agent/polling/types.js +3 -0
  62. package/lib/cjs/agent/polling/types.js.map +1 -0
  63. package/lib/cjs/agent/public_key.d.ts +1 -1
  64. package/lib/cjs/agent/public_key.d.ts.map +1 -1
  65. package/lib/cjs/agent/request_id.d.ts.map +1 -1
  66. package/lib/cjs/agent/request_id.js +7 -7
  67. package/lib/cjs/agent/request_id.js.map +1 -1
  68. package/lib/cjs/agent/subnetStatus/index.d.ts +5 -4
  69. package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -1
  70. package/lib/cjs/agent/subnetStatus/index.js +6 -10
  71. package/lib/cjs/agent/subnetStatus/index.js.map +1 -1
  72. package/lib/cjs/agent/utils/buffer.d.ts.map +1 -1
  73. package/lib/cjs/agent/utils/buffer.js +4 -2
  74. package/lib/cjs/agent/utils/buffer.js.map +1 -1
  75. package/lib/cjs/agent/utils/certificateReject.d.ts +11 -0
  76. package/lib/cjs/agent/utils/certificateReject.d.ts.map +1 -0
  77. package/lib/cjs/agent/utils/certificateReject.js +19 -0
  78. package/lib/cjs/agent/utils/certificateReject.js.map +1 -0
  79. package/lib/cjs/agent/utils/createExpirableStore.d.ts +23 -0
  80. package/lib/cjs/agent/utils/createExpirableStore.d.ts.map +1 -0
  81. package/lib/cjs/agent/utils/createExpirableStore.js +18 -0
  82. package/lib/cjs/agent/utils/createExpirableStore.js.map +1 -0
  83. package/lib/cjs/agent/utils/expirableStore.d.ts +39 -0
  84. package/lib/cjs/agent/utils/expirableStore.d.ts.map +1 -0
  85. package/lib/cjs/agent/utils/expirableStore.js +14 -0
  86. package/lib/cjs/agent/utils/expirableStore.js.map +1 -0
  87. package/lib/cjs/agent/utils/inMemoryExpirableStore.d.ts +14 -0
  88. package/lib/cjs/agent/utils/inMemoryExpirableStore.d.ts.map +1 -0
  89. package/lib/cjs/agent/utils/inMemoryExpirableStore.js +46 -0
  90. package/lib/cjs/agent/utils/inMemoryExpirableStore.js.map +1 -0
  91. package/lib/cjs/agent/utils/indexedDBExpirableStore.d.ts +28 -0
  92. package/lib/cjs/agent/utils/indexedDBExpirableStore.d.ts.map +1 -0
  93. package/lib/cjs/agent/utils/indexedDBExpirableStore.js +139 -0
  94. package/lib/cjs/agent/utils/indexedDBExpirableStore.js.map +1 -0
  95. package/lib/cjs/agent/utils/readState.d.ts +3 -3
  96. package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
  97. package/lib/cjs/candid/candid-core.d.ts +1 -1
  98. package/lib/cjs/candid/candid-core.d.ts.map +1 -1
  99. package/lib/cjs/candid/candid-core.js +7 -9
  100. package/lib/cjs/candid/candid-core.js.map +1 -1
  101. package/lib/cjs/candid/candid-ui.d.ts.map +1 -1
  102. package/lib/cjs/candid/candid-ui.js +8 -24
  103. package/lib/cjs/candid/candid-ui.js.map +1 -1
  104. package/lib/cjs/candid/idl.d.ts +14 -1
  105. package/lib/cjs/candid/idl.d.ts.map +1 -1
  106. package/lib/cjs/candid/idl.js +164 -125
  107. package/lib/cjs/candid/idl.js.map +1 -1
  108. package/lib/cjs/candid/utils/leb128.d.ts.map +1 -1
  109. package/lib/cjs/candid/utils/leb128.js +1 -3
  110. package/lib/cjs/candid/utils/leb128.js.map +1 -1
  111. package/lib/cjs/identity/identity/delegation.d.ts +4 -3
  112. package/lib/cjs/identity/identity/delegation.d.ts.map +1 -1
  113. package/lib/cjs/identity/identity/delegation.js +3 -3
  114. package/lib/cjs/identity/identity/delegation.js.map +1 -1
  115. package/lib/cjs/identity/identity/ecdsa.d.ts +2 -2
  116. package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -1
  117. package/lib/cjs/identity/identity/ecdsa.js +2 -4
  118. package/lib/cjs/identity/identity/ecdsa.js.map +1 -1
  119. package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -1
  120. package/lib/cjs/identity/identity/ed25519.js +9 -10
  121. package/lib/cjs/identity/identity/ed25519.js.map +1 -1
  122. package/lib/cjs/identity/identity/partial.d.ts +1 -1
  123. package/lib/cjs/identity/identity/partial.d.ts.map +1 -1
  124. package/lib/cjs/identity/identity/webauthn.js +4 -5
  125. package/lib/cjs/identity/identity/webauthn.js.map +1 -1
  126. package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -1
  127. package/lib/cjs/identity/secp256k1/der.js +27 -22
  128. package/lib/cjs/identity/secp256k1/der.js.map +1 -1
  129. package/lib/cjs/identity/secp256k1/pem.js +1 -1
  130. package/lib/cjs/identity/secp256k1/pem.js.map +1 -1
  131. package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -1
  132. package/lib/cjs/identity/secp256k1/secp256k1.js +6 -6
  133. package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -1
  134. package/lib/cjs/principal/principal.d.ts +2 -2
  135. package/lib/cjs/principal/principal.d.ts.map +1 -1
  136. package/lib/cjs/principal/principal.js +10 -6
  137. package/lib/cjs/principal/principal.js.map +1 -1
  138. package/lib/esm/agent/actor.d.ts +15 -1
  139. package/lib/esm/agent/actor.d.ts.map +1 -1
  140. package/lib/esm/agent/actor.js +40 -94
  141. package/lib/esm/agent/actor.js.map +1 -1
  142. package/lib/esm/agent/agent/api.d.ts +29 -6
  143. package/lib/esm/agent/agent/api.d.ts.map +1 -1
  144. package/lib/esm/agent/agent/api.js.map +1 -1
  145. package/lib/esm/agent/agent/http/expiry.d.ts +36 -0
  146. package/lib/esm/agent/agent/http/expiry.d.ts.map +1 -0
  147. package/lib/esm/agent/agent/http/expiry.js +88 -0
  148. package/lib/esm/agent/agent/http/expiry.js.map +1 -0
  149. package/lib/esm/agent/agent/http/index.d.ts +28 -2
  150. package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
  151. package/lib/esm/agent/agent/http/index.js +185 -93
  152. package/lib/esm/agent/agent/http/index.js.map +1 -1
  153. package/lib/esm/agent/agent/http/transforms.d.ts +1 -35
  154. package/lib/esm/agent/agent/http/transforms.d.ts.map +1 -1
  155. package/lib/esm/agent/agent/http/transforms.js +2 -87
  156. package/lib/esm/agent/agent/http/transforms.js.map +1 -1
  157. package/lib/esm/agent/agent/http/types.d.ts +1 -1
  158. package/lib/esm/agent/agent/http/types.d.ts.map +1 -1
  159. package/lib/esm/agent/auth.d.ts +1 -1
  160. package/lib/esm/agent/auth.d.ts.map +1 -1
  161. package/lib/esm/agent/canister-env/index.d.ts +2 -2
  162. package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
  163. package/lib/esm/agent/canisterStatus/index.d.ts +5 -4
  164. package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
  165. package/lib/esm/agent/canisterStatus/index.js +6 -10
  166. package/lib/esm/agent/canisterStatus/index.js.map +1 -1
  167. package/lib/esm/agent/cbor.js +1 -1
  168. package/lib/esm/agent/cbor.js.map +1 -1
  169. package/lib/esm/agent/certificate.d.ts +4 -4
  170. package/lib/esm/agent/certificate.d.ts.map +1 -1
  171. package/lib/esm/agent/certificate.js +6 -10
  172. package/lib/esm/agent/certificate.js.map +1 -1
  173. package/lib/esm/agent/constants.d.ts +4 -4
  174. package/lib/esm/agent/constants.d.ts.map +1 -1
  175. package/lib/esm/agent/der.d.ts.map +1 -1
  176. package/lib/esm/agent/der.js +26 -21
  177. package/lib/esm/agent/der.js.map +1 -1
  178. package/lib/esm/agent/errors.d.ts +45 -19
  179. package/lib/esm/agent/errors.d.ts.map +1 -1
  180. package/lib/esm/agent/errors.js +54 -16
  181. package/lib/esm/agent/errors.js.map +1 -1
  182. package/lib/esm/agent/index.d.ts +1 -0
  183. package/lib/esm/agent/index.d.ts.map +1 -1
  184. package/lib/esm/agent/index.js.map +1 -1
  185. package/lib/esm/agent/observable.d.ts +1 -1
  186. package/lib/esm/agent/observable.d.ts.map +1 -1
  187. package/lib/esm/agent/polling/backoff.d.ts +7 -7
  188. package/lib/esm/agent/polling/backoff.d.ts.map +1 -1
  189. package/lib/esm/agent/polling/backoff.js +3 -5
  190. package/lib/esm/agent/polling/backoff.js.map +1 -1
  191. package/lib/esm/agent/polling/index.d.ts +11 -10
  192. package/lib/esm/agent/polling/index.d.ts.map +1 -1
  193. package/lib/esm/agent/polling/index.js +9 -7
  194. package/lib/esm/agent/polling/index.js.map +1 -1
  195. package/lib/esm/agent/polling/strategy.d.ts +2 -5
  196. package/lib/esm/agent/polling/strategy.d.ts.map +1 -1
  197. package/lib/esm/agent/polling/strategy.js.map +1 -1
  198. package/lib/esm/agent/polling/types.d.ts +18 -0
  199. package/lib/esm/agent/polling/types.d.ts.map +1 -0
  200. package/lib/esm/agent/polling/types.js +2 -0
  201. package/lib/esm/agent/polling/types.js.map +1 -0
  202. package/lib/esm/agent/public_key.d.ts +1 -1
  203. package/lib/esm/agent/public_key.d.ts.map +1 -1
  204. package/lib/esm/agent/request_id.d.ts.map +1 -1
  205. package/lib/esm/agent/request_id.js +7 -7
  206. package/lib/esm/agent/request_id.js.map +1 -1
  207. package/lib/esm/agent/subnetStatus/index.d.ts +5 -4
  208. package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -1
  209. package/lib/esm/agent/subnetStatus/index.js +6 -10
  210. package/lib/esm/agent/subnetStatus/index.js.map +1 -1
  211. package/lib/esm/agent/utils/buffer.d.ts.map +1 -1
  212. package/lib/esm/agent/utils/buffer.js +4 -2
  213. package/lib/esm/agent/utils/buffer.js.map +1 -1
  214. package/lib/esm/agent/utils/certificateReject.d.ts +11 -0
  215. package/lib/esm/agent/utils/certificateReject.d.ts.map +1 -0
  216. package/lib/esm/agent/utils/certificateReject.js +16 -0
  217. package/lib/esm/agent/utils/certificateReject.js.map +1 -0
  218. package/lib/esm/agent/utils/createExpirableStore.d.ts +23 -0
  219. package/lib/esm/agent/utils/createExpirableStore.d.ts.map +1 -0
  220. package/lib/esm/agent/utils/createExpirableStore.js +15 -0
  221. package/lib/esm/agent/utils/createExpirableStore.js.map +1 -0
  222. package/lib/esm/agent/utils/expirableStore.d.ts +39 -0
  223. package/lib/esm/agent/utils/expirableStore.d.ts.map +1 -0
  224. package/lib/esm/agent/utils/expirableStore.js +11 -0
  225. package/lib/esm/agent/utils/expirableStore.js.map +1 -0
  226. package/lib/esm/agent/utils/inMemoryExpirableStore.d.ts +14 -0
  227. package/lib/esm/agent/utils/inMemoryExpirableStore.d.ts.map +1 -0
  228. package/lib/esm/agent/utils/inMemoryExpirableStore.js +42 -0
  229. package/lib/esm/agent/utils/inMemoryExpirableStore.js.map +1 -0
  230. package/lib/esm/agent/utils/indexedDBExpirableStore.d.ts +28 -0
  231. package/lib/esm/agent/utils/indexedDBExpirableStore.d.ts.map +1 -0
  232. package/lib/esm/agent/utils/indexedDBExpirableStore.js +135 -0
  233. package/lib/esm/agent/utils/indexedDBExpirableStore.js.map +1 -0
  234. package/lib/esm/agent/utils/readState.d.ts +3 -3
  235. package/lib/esm/agent/utils/readState.d.ts.map +1 -1
  236. package/lib/esm/candid/candid-core.d.ts +1 -1
  237. package/lib/esm/candid/candid-core.d.ts.map +1 -1
  238. package/lib/esm/candid/candid-core.js +7 -9
  239. package/lib/esm/candid/candid-core.js.map +1 -1
  240. package/lib/esm/candid/candid-ui.d.ts.map +1 -1
  241. package/lib/esm/candid/candid-ui.js +7 -23
  242. package/lib/esm/candid/candid-ui.js.map +1 -1
  243. package/lib/esm/candid/idl.d.ts +14 -1
  244. package/lib/esm/candid/idl.d.ts.map +1 -1
  245. package/lib/esm/candid/idl.js +162 -124
  246. package/lib/esm/candid/idl.js.map +1 -1
  247. package/lib/esm/candid/utils/leb128.d.ts.map +1 -1
  248. package/lib/esm/candid/utils/leb128.js +1 -3
  249. package/lib/esm/candid/utils/leb128.js.map +1 -1
  250. package/lib/esm/identity/identity/delegation.d.ts +4 -3
  251. package/lib/esm/identity/identity/delegation.d.ts.map +1 -1
  252. package/lib/esm/identity/identity/delegation.js +3 -3
  253. package/lib/esm/identity/identity/delegation.js.map +1 -1
  254. package/lib/esm/identity/identity/ecdsa.d.ts +2 -2
  255. package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -1
  256. package/lib/esm/identity/identity/ecdsa.js +2 -4
  257. package/lib/esm/identity/identity/ecdsa.js.map +1 -1
  258. package/lib/esm/identity/identity/ed25519.d.ts.map +1 -1
  259. package/lib/esm/identity/identity/ed25519.js +9 -10
  260. package/lib/esm/identity/identity/ed25519.js.map +1 -1
  261. package/lib/esm/identity/identity/partial.d.ts +1 -1
  262. package/lib/esm/identity/identity/partial.d.ts.map +1 -1
  263. package/lib/esm/identity/identity/webauthn.js +4 -5
  264. package/lib/esm/identity/identity/webauthn.js.map +1 -1
  265. package/lib/esm/identity/secp256k1/der.d.ts.map +1 -1
  266. package/lib/esm/identity/secp256k1/der.js +27 -22
  267. package/lib/esm/identity/secp256k1/der.js.map +1 -1
  268. package/lib/esm/identity/secp256k1/pem.js +1 -1
  269. package/lib/esm/identity/secp256k1/pem.js.map +1 -1
  270. package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -1
  271. package/lib/esm/identity/secp256k1/secp256k1.js +6 -6
  272. package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -1
  273. package/lib/esm/principal/principal.d.ts +2 -2
  274. package/lib/esm/principal/principal.d.ts.map +1 -1
  275. package/lib/esm/principal/principal.js +10 -6
  276. package/lib/esm/principal/principal.js.map +1 -1
  277. package/package.json +14 -13
  278. package/src/agent/actor.ts +74 -126
  279. package/src/agent/agent/api.ts +36 -6
  280. package/src/agent/agent/http/expiry.ts +107 -0
  281. package/src/agent/agent/http/index.ts +262 -104
  282. package/src/agent/agent/http/transforms.ts +2 -106
  283. package/src/agent/agent/http/types.ts +1 -1
  284. package/src/agent/auth.ts +1 -1
  285. package/src/agent/canister-env/index.ts +2 -2
  286. package/src/agent/canisterStatus/index.ts +10 -12
  287. package/src/agent/cbor.ts +1 -1
  288. package/src/agent/certificate.ts +11 -13
  289. package/src/agent/der.ts +40 -19
  290. package/src/agent/errors.ts +85 -34
  291. package/src/agent/fetch_candid.ts +1 -1
  292. package/src/agent/index.ts +1 -0
  293. package/src/agent/observable.ts +1 -1
  294. package/src/agent/polling/backoff.ts +9 -10
  295. package/src/agent/polling/index.ts +14 -26
  296. package/src/agent/polling/strategy.ts +5 -9
  297. package/src/agent/polling/types.ts +28 -0
  298. package/src/agent/public_key.ts +1 -1
  299. package/src/agent/request_id.ts +15 -8
  300. package/src/agent/subnetStatus/index.ts +10 -12
  301. package/src/agent/utils/buffer.ts +6 -2
  302. package/src/agent/utils/certificateReject.ts +25 -0
  303. package/src/agent/utils/createExpirableStore.ts +31 -0
  304. package/src/agent/utils/expirableStore.ts +47 -0
  305. package/src/agent/utils/inMemoryExpirableStore.ts +49 -0
  306. package/src/agent/utils/indexedDBExpirableStore.ts +191 -0
  307. package/src/agent/utils/random.ts +2 -2
  308. package/src/agent/utils/readState.ts +3 -3
  309. package/src/candid/candid-core.ts +9 -11
  310. package/src/candid/candid-ui.ts +8 -16
  311. package/src/candid/idl.ts +210 -112
  312. package/src/candid/utils/leb128.ts +1 -2
  313. package/src/identity/identity/delegation.ts +5 -5
  314. package/src/identity/identity/ecdsa.ts +12 -8
  315. package/src/identity/identity/ed25519.ts +16 -9
  316. package/src/identity/identity/partial.ts +1 -1
  317. package/src/identity/identity/webauthn.ts +21 -21
  318. package/src/identity/secp256k1/der.ts +41 -20
  319. package/src/identity/secp256k1/pem.ts +1 -1
  320. package/src/identity/secp256k1/secp256k1.ts +12 -6
  321. package/src/principal/principal.ts +18 -8
  322. package/LICENSE +0 -201
  323. package/lib/cjs/agent/utils/expirableMap.d.ts +0 -80
  324. package/lib/cjs/agent/utils/expirableMap.d.ts.map +0 -1
  325. package/lib/cjs/agent/utils/expirableMap.js +0 -148
  326. package/lib/cjs/agent/utils/expirableMap.js.map +0 -1
  327. package/lib/esm/agent/utils/expirableMap.d.ts +0 -80
  328. package/lib/esm/agent/utils/expirableMap.d.ts.map +0 -1
  329. package/lib/esm/agent/utils/expirableMap.js +0 -144
  330. package/lib/esm/agent/utils/expirableMap.js.map +0 -1
  331. package/src/agent/utils/expirableMap.ts +0 -163
@@ -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 { pollForResponse, type PollingOptions, DEFAULT_POLLING_OPTIONS } from './polling/index.ts';
14
+ import { type PollingOptions, DEFAULT_POLLING_OPTIONS } from './polling/index.ts';
22
15
  import { Principal } from '#principal';
23
- import { Certificate, type CreateCertificateOptions, lookupResultToBuffer } from './certificate.ts';
16
+ import type { Certificate, CreateCertificateOptions } from './certificate.ts';
24
17
  import { HttpAgent } from './agent/http/index.ts';
25
- import { utf8ToBytes } from '@noble/hashes/utils';
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<Args extends unknown[] = unknown[], Ret = unknown>
115
- extends ActorMethod {
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<Args extends unknown[] = unknown[], Ret = unknown>
123
- extends ActorMethod {
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
- if (func.annotations.includes('query') || func.annotations.includes('composite_query')) {
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
- const { requestId, response, requestDetails } = await agent.call(cid, {
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
- if (isV4ResponseBody(response.body)) {
456
- if (agent.rootKey == null) {
457
- throw ExternalError.fromCode(new MissingRootKeyErrorCode());
458
- }
459
- const cert = response.body.certificate;
460
- certificate = await Certificate.create({
461
- certificate: cert,
462
- rootKey: agent.rootKey,
463
- principal: { canisterId: ecid },
464
- blsVerify,
465
- agent,
466
- });
467
- const path = [utf8ToBytes('request_status'), requestId];
468
- const status = new TextDecoder().decode(
469
- lookupResultToBuffer(certificate.lookup_path([...path, 'status'])),
470
- );
471
-
472
- switch (status) {
473
- case 'replied':
474
- reply = lookupResultToBuffer(certificate.lookup_path([...path, 'reply']));
475
- break;
476
- case 'rejected': {
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
- } else if (isV2ResponseBody(response.body)) {
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 = { ...response, requestDetails } as HttpDetailsResponse;
537
- if (reply !== undefined) {
538
- if (shouldIncludeHttpDetails && shouldIncludeCertificate) {
539
- return {
540
- httpDetails,
541
- certificate,
542
- result: decodeReturnValue(func.retTypes, reply),
543
- };
544
- } else if (shouldIncludeCertificate) {
545
- return {
546
- certificate,
547
- result: decodeReturnValue(func.retTypes, reply),
548
- };
549
- } else if (shouldIncludeHttpDetails) {
550
- return {
551
- httpDetails,
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
 
@@ -1,8 +1,9 @@
1
- import { Principal } from '#principal';
2
- import { type RequestId } from '../request_id.ts';
3
- import { type JsonObject } from '#candid';
4
- import { type Identity } from '../auth.ts';
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 type NodeSignature = {
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
+ }