@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,4 +1,3 @@
1
- import { lebEncode } from '#candid';
2
1
  import {
3
2
  Endpoint,
4
3
  type HttpAgentRequest,
@@ -7,112 +6,9 @@ import {
7
6
  makeNonce,
8
7
  type Nonce,
9
8
  } from './types.ts';
10
- import { ExpiryJsonDeserializeErrorCode, InputError } from '../../errors.ts';
9
+ import { Expiry } from './expiry.ts';
11
10
 
12
- export const JSON_KEY_EXPIRY = '__expiry__';
13
- const SECONDS_TO_MILLISECONDS = BigInt(1_000);
14
- const MILLISECONDS_TO_NANOSECONDS = BigInt(1_000_000);
15
- const MINUTES_TO_SECONDS = BigInt(60);
16
- const MINUTES_TO_MILLISECONDS = MINUTES_TO_SECONDS * SECONDS_TO_MILLISECONDS;
17
-
18
- const EXPIRY_DELTA_THRESHOLD_MILLISECONDS = BigInt(1) * MINUTES_TO_MILLISECONDS;
19
-
20
- function roundToSecond(millis: bigint): bigint {
21
- return (millis / SECONDS_TO_MILLISECONDS) * SECONDS_TO_MILLISECONDS;
22
- }
23
-
24
- function roundToMinute(millis: bigint): bigint {
25
- return (millis / MINUTES_TO_MILLISECONDS) * MINUTES_TO_MILLISECONDS;
26
- }
27
-
28
- export type JsonnableExpiry = {
29
- [JSON_KEY_EXPIRY]: string;
30
- };
31
-
32
- export class Expiry {
33
- public readonly _isExpiry = true;
34
-
35
- private constructor(private readonly __expiry__: bigint) {}
36
-
37
- /**
38
- * Creates an Expiry object from a delta in milliseconds.
39
- * The expiry is calculated as: current_time + delta + clock_drift
40
- * The resulting expiry is then rounded:
41
- * - If rounding down to the nearest minute still provides at least 60 seconds in the future, use minute precision
42
- * - Otherwise, use second precision
43
- * @param deltaInMs The milliseconds to add to the current time.
44
- * @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.
45
- * @returns {Expiry} The constructed Expiry object.
46
- */
47
- public static fromDeltaInMilliseconds(deltaInMs: number, clockDriftInMs: number = 0): Expiry {
48
- const correctedNowMs = BigInt(Date.now()) + BigInt(clockDriftInMs);
49
- const expiryMs = correctedNowMs + BigInt(deltaInMs);
50
-
51
- const roundedToMinute = roundToMinute(expiryMs);
52
-
53
- let roundedExpiryMs: bigint;
54
- if (roundedToMinute >= correctedNowMs + EXPIRY_DELTA_THRESHOLD_MILLISECONDS) {
55
- roundedExpiryMs = roundedToMinute;
56
- } else {
57
- const roundedToSecond = roundToSecond(expiryMs);
58
- roundedExpiryMs = roundedToSecond;
59
- }
60
-
61
- return new Expiry(roundedExpiryMs * MILLISECONDS_TO_NANOSECONDS);
62
- }
63
-
64
- public toBigInt(): bigint {
65
- return this.__expiry__;
66
- }
67
-
68
- public toHash(): Uint8Array {
69
- return lebEncode(this.__expiry__);
70
- }
71
-
72
- public toString(): string {
73
- return this.__expiry__.toString();
74
- }
75
-
76
- /**
77
- * Serializes to JSON
78
- * @returns {JsonnableExpiry} a JSON object with a single key, {@link JSON_KEY_EXPIRY}, whose value is the expiry as a string
79
- */
80
- public toJSON(): JsonnableExpiry {
81
- return { [JSON_KEY_EXPIRY]: this.toString() };
82
- }
83
-
84
- /**
85
- * Deserializes a {@link JsonnableExpiry} object from a JSON string.
86
- * @param input The JSON string to deserialize.
87
- * @returns {Expiry} The deserialized Expiry object.
88
- */
89
- public static fromJSON(input: string): Expiry {
90
- const obj = JSON.parse(input);
91
- if (obj[JSON_KEY_EXPIRY]) {
92
- try {
93
- const expiry = BigInt(obj[JSON_KEY_EXPIRY]);
94
- return new Expiry(expiry);
95
- } catch (error) {
96
- throw new InputError(new ExpiryJsonDeserializeErrorCode(`Not a valid BigInt: ${error}`));
97
- }
98
- }
99
- throw new InputError(
100
- new ExpiryJsonDeserializeErrorCode(`The input does not contain the key ${JSON_KEY_EXPIRY}`),
101
- );
102
- }
103
-
104
- public static isExpiry(other: unknown): other is Expiry {
105
- return (
106
- other instanceof Expiry ||
107
- (typeof other === 'object' &&
108
- other !== null &&
109
- '_isExpiry' in other &&
110
- (other as { _isExpiry: boolean })['_isExpiry'] === true &&
111
- '__expiry__' in other &&
112
- typeof (other as { __expiry__: bigint })['__expiry__'] === 'bigint')
113
- );
114
- }
115
- }
11
+ export { Expiry, JSON_KEY_EXPIRY, type JsonnableExpiry } from './expiry.ts';
116
12
 
117
13
  /**
118
14
  * Create a Nonce transform, which takes a function that returns a Buffer, and adds it
@@ -1,5 +1,5 @@
1
1
  import type { Principal } from '#principal';
2
- import { Expiry } from './transforms.ts';
2
+ import type { Expiry } from './expiry.ts';
3
3
  import { randomNumber } from '../../utils/random.ts';
4
4
 
5
5
  /**
package/src/agent/auth.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Principal } from '#principal';
2
- import { type HttpAgentRequest } from './agent/http/types.ts';
2
+ import type { HttpAgentRequest } from './agent/http/types.ts';
3
3
  import { requestIdOf } from './request_id.ts';
4
4
  import { bytesToHex, concatBytes } from '@noble/hashes/utils';
5
5
  import { IC_REQUEST_DOMAIN_SEPARATOR } from './constants.ts';
@@ -70,13 +70,13 @@ export interface CanisterEnv {
70
70
  * Options for the {@link getCanisterEnv} function
71
71
  * @experimental
72
72
  */
73
- export type GetCanisterEnvOptions = {
73
+ export interface GetCanisterEnvOptions {
74
74
  /**
75
75
  * The name of the cookie to get the environment variables from.
76
76
  * @default 'ic_env'
77
77
  */
78
78
  cookieName?: string;
79
- };
79
+ }
80
80
 
81
81
  /**
82
82
  * Get the environment variables served by the asset canister via the cookie.
@@ -9,15 +9,15 @@ import {
9
9
  InputError,
10
10
  CertificateTimeErrorCode,
11
11
  } from '../errors.ts';
12
- import { HttpAgent } from '../agent/http/index.ts';
12
+ import type { HttpAgent } from '../agent/http/index.ts';
13
13
  import { type Cert, Certificate, lookupResultToBuffer } from '../certificate.ts';
14
14
  import * as cbor from '../cbor.ts';
15
15
  import { decodeTime } from '../utils/leb.ts';
16
16
  import { utf8ToBytes, bytesToHex } from '@noble/hashes/utils';
17
+ import type { CustomPath } from '../utils/readState.ts';
17
18
  import {
18
19
  type BaseSubnetStatus,
19
20
  type BaseStatus,
20
- CustomPath,
21
21
  decodeValue,
22
22
  decodeControllers,
23
23
  encodeMetadataPath,
@@ -39,7 +39,7 @@ export type Path = 'time' | 'controllers' | 'subnet' | 'module_hash' | 'candid'
39
39
 
40
40
  export type StatusMap = Map<Path | string, Status>;
41
41
 
42
- export type CanisterStatusOptions = {
42
+ export interface CanisterStatusOptions {
43
43
  /**
44
44
  * The effective canister ID to use in the underlying {@link HttpAgent.readState} call.
45
45
  */
@@ -58,7 +58,7 @@ export type CanisterStatusOptions = {
58
58
  * @default false
59
59
  */
60
60
  disableCertificateTimeVerification?: boolean;
61
- };
61
+ }
62
62
 
63
63
  /**
64
64
  * Requests information from a canister's `read_state` endpoint.
@@ -115,12 +115,11 @@ export const request = async (options: CanisterStatusOptions): Promise<StatusMap
115
115
  path,
116
116
  data,
117
117
  };
118
- } else {
119
- return {
120
- path,
121
- data: lookupResultToBuffer(cert.lookup_path(encodedPath)),
122
- };
123
118
  }
119
+ return {
120
+ path,
121
+ data: lookupResultToBuffer(cert.lookup_path(encodedPath)),
122
+ };
124
123
  };
125
124
 
126
125
  // must pass in the rootKey if we have no delegation
@@ -247,10 +246,9 @@ export const encodePath = (path: Path, canisterId: Principal): Uint8Array[] => {
247
246
  // For simplified metadata queries
248
247
  if (typeof path['path'] === 'string' || path['path'] instanceof Uint8Array) {
249
248
  return encodeMetadataPath(path.path, canisterUint8Array);
250
- } else {
251
- // For non-metadata, return the provided custom path
252
- return path['path'];
253
249
  }
250
+ // For non-metadata, return the provided custom path
251
+ return path['path'];
254
252
  }
255
253
  }
256
254
  }
package/src/agent/cbor.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Principal } from '#principal';
2
2
  import * as cbor from '@dfinity/cbor';
3
3
  import { CborDecodeErrorCode, CborEncodeErrorCode, InputError } from './errors.ts';
4
- import { Expiry } from './agent/index.ts';
4
+ import { Expiry } from './agent/http/expiry.ts';
5
5
 
6
6
  /**
7
7
  * Used to extend classes that need to provide a custom value for the CBOR encoding process.
@@ -78,7 +78,7 @@ export function hashTreeToString(tree: HashTree): string {
78
78
  const indent = (s: string) =>
79
79
  s
80
80
  .split('\n')
81
- .map(x => ' ' + x)
81
+ .map(x => ` ${x}`)
82
82
  .join('\n');
83
83
  function labelToString(label: Uint8Array): string {
84
84
  const decoder = new TextDecoder(undefined, { fatal: true });
@@ -94,24 +94,22 @@ export function hashTreeToString(tree: HashTree): string {
94
94
  case NodeType.Empty:
95
95
  return '()';
96
96
  case NodeType.Fork: {
97
- if (tree[1] instanceof Array && tree[2] instanceof Uint8Array) {
97
+ if (tree[1] instanceof Array && tree[2] instanceof Array) {
98
98
  const left = hashTreeToString(tree[1]);
99
99
  const right = hashTreeToString(tree[2]);
100
100
  return `sub(\n left:\n${indent(left)}\n---\n right:\n${indent(right)}\n)`;
101
- } else {
102
- throw UnknownError.fromCode(new HashTreeDecodeErrorCode('Invalid tree structure for fork'));
103
101
  }
102
+ throw UnknownError.fromCode(new HashTreeDecodeErrorCode('Invalid tree structure for fork'));
104
103
  }
105
104
  case NodeType.Labeled: {
106
- if (tree[1] instanceof Uint8Array && tree[2] instanceof Uint8Array) {
105
+ if (tree[1] instanceof Uint8Array && tree[2] instanceof Array) {
107
106
  const label = labelToString(tree[1]);
108
107
  const sub = hashTreeToString(tree[2]);
109
108
  return `label(\n label:\n${indent(label)}\n sub:\n${indent(sub)}\n)`;
110
- } else {
111
- throw UnknownError.fromCode(
112
- new HashTreeDecodeErrorCode('Invalid tree structure for labeled'),
113
- );
114
109
  }
110
+ throw UnknownError.fromCode(
111
+ new HashTreeDecodeErrorCode('Invalid tree structure for labeled'),
112
+ );
115
113
  }
116
114
  case NodeType.Leaf: {
117
115
  if (!tree[1]) {
@@ -184,7 +182,7 @@ export interface CreateCertificateOptions {
184
182
  */
185
183
  principal: CertificatePrincipal;
186
184
  /**
187
- * BLS Verification strategy. Default strategy uses bls12_381 from @noble/curves
185
+ * BLS Verification strategy. Default strategy uses bls12_381 from `@noble/curves`
188
186
  */
189
187
  blsVerify?: VerifyFunc;
190
188
 
@@ -221,7 +219,7 @@ export class Certificate {
221
219
  /**
222
220
  * Create a new instance of a certificate, automatically verifying it.
223
221
  * @param {CreateCertificateOptions} options {@link CreateCertificateOptions}
224
- * @throws if the verification of the certificate fails
222
+ * @throws {Error} if the verification of the certificate fails
225
223
  */
226
224
  public static async create(options: CreateCertificateOptions): Promise<Certificate> {
227
225
  const cert = Certificate.createUnverified(options);
@@ -875,11 +873,11 @@ function list_paths(path: Array<NodeLabel>, tree: HashTree): Array<Array<NodeLab
875
873
  }
876
874
  }
877
875
 
878
- export type CheckCanisterRangesParams = {
876
+ export interface CheckCanisterRangesParams {
879
877
  canisterId: Principal;
880
878
  subnetId: Principal;
881
879
  tree: HashTree;
882
- };
880
+ }
883
881
 
884
882
  /**
885
883
  * Canister ranges in the form of an array of [start, end] principal tuples,
package/src/agent/der.ts CHANGED
@@ -9,57 +9,78 @@ import { uint8Equals } from './utils/buffer.ts';
9
9
  export const encodeLenBytes = (len: number): number => {
10
10
  if (len <= 0x7f) {
11
11
  return 1;
12
- } else if (len <= 0xff) {
12
+ }
13
+ if (len <= 0xff) {
13
14
  return 2;
14
- } else if (len <= 0xffff) {
15
+ }
16
+ if (len <= 0xffff) {
15
17
  return 3;
16
- } else if (len <= 0xffffff) {
18
+ }
19
+ if (len <= 0xffffff) {
17
20
  return 4;
18
- } else {
19
- throw InputError.fromCode(new DerEncodeErrorCode('Length too long (> 4 bytes)'));
20
21
  }
22
+ throw InputError.fromCode(new DerEncodeErrorCode('Length too long (> 4 bytes)'));
21
23
  };
22
24
 
23
25
  export const encodeLen = (buf: Uint8Array, offset: number, len: number): number => {
24
26
  if (len <= 0x7f) {
25
27
  buf[offset] = len;
26
28
  return 1;
27
- } else if (len <= 0xff) {
29
+ }
30
+ if (len <= 0xff) {
28
31
  buf[offset] = 0x81;
29
32
  buf[offset + 1] = len;
30
33
  return 2;
31
- } else if (len <= 0xffff) {
34
+ }
35
+ if (len <= 0xffff) {
32
36
  buf[offset] = 0x82;
33
37
  buf[offset + 1] = len >> 8;
34
38
  buf[offset + 2] = len;
35
39
  return 3;
36
- } else if (len <= 0xffffff) {
40
+ }
41
+ if (len <= 0xffffff) {
37
42
  buf[offset] = 0x83;
38
43
  buf[offset + 1] = len >> 16;
39
44
  buf[offset + 2] = len >> 8;
40
45
  buf[offset + 3] = len;
41
46
  return 4;
42
- } else {
43
- throw InputError.fromCode(new DerEncodeErrorCode('Length too long (> 4 bytes)'));
44
47
  }
48
+ throw InputError.fromCode(new DerEncodeErrorCode('Length too long (> 4 bytes)'));
45
49
  };
46
50
 
47
51
  export const decodeLenBytes = (buf: Uint8Array, offset: number): number => {
48
- if (buf[offset] < 0x80) return 1;
49
- if (buf[offset] === 0x80) throw InputError.fromCode(new DerDecodeErrorCode('Invalid length 0'));
50
- if (buf[offset] === 0x81) return 2;
51
- if (buf[offset] === 0x82) return 3;
52
- if (buf[offset] === 0x83) return 4;
52
+ if (buf[offset] < 0x80) {
53
+ return 1;
54
+ }
55
+ if (buf[offset] === 0x80) {
56
+ throw InputError.fromCode(new DerDecodeErrorCode('Invalid length 0'));
57
+ }
58
+ if (buf[offset] === 0x81) {
59
+ return 2;
60
+ }
61
+ if (buf[offset] === 0x82) {
62
+ return 3;
63
+ }
64
+ if (buf[offset] === 0x83) {
65
+ return 4;
66
+ }
53
67
  throw InputError.fromCode(new DerDecodeErrorCode('Length too long (> 4 bytes)'));
54
68
  };
55
69
 
56
70
  export const decodeLen = (buf: Uint8Array, offset: number): number => {
57
71
  const lenBytes = decodeLenBytes(buf, offset);
58
- if (lenBytes === 1) return buf[offset];
59
- else if (lenBytes === 2) return buf[offset + 1];
60
- else if (lenBytes === 3) return (buf[offset + 1] << 8) + buf[offset + 2];
61
- else if (lenBytes === 4)
72
+ if (lenBytes === 1) {
73
+ return buf[offset];
74
+ }
75
+ if (lenBytes === 2) {
76
+ return buf[offset + 1];
77
+ }
78
+ if (lenBytes === 3) {
79
+ return (buf[offset + 1] << 8) + buf[offset + 2];
80
+ }
81
+ if (lenBytes === 4) {
62
82
  return (buf[offset + 1] << 16) + (buf[offset + 2] << 8) + buf[offset + 3];
83
+ }
63
84
  throw InputError.fromCode(new DerDecodeErrorCode('Length too long (> 4 bytes)'));
64
85
  };
65
86
 
@@ -1,14 +1,10 @@
1
- import { Principal } from '#principal';
2
- import {
3
- type HttpDetailsResponse,
4
- type NodeSignature,
5
- type ReplicaRejectCode,
6
- } from './agent/api.ts';
7
- import { type RequestId } from './request_id.ts';
8
- import { type RequestStatusResponseStatus } from './agent/http/index.ts';
9
- import { type Expiry } from './agent/http/transforms.ts';
10
- import { type HttpHeaderField } from './agent/http/types.ts';
11
- import { LookupPathStatus, LookupSubtreeStatus } from './certificate.ts';
1
+ import type { Principal } from '#principal';
2
+ import type { HttpDetailsResponse, NodeSignature, ReplicaRejectCode } from './agent/api.ts';
3
+ import type { RequestId } from './request_id.ts';
4
+ import type { RequestStatusResponseStatus } from './agent/http/index.ts';
5
+ import type { Expiry } from './agent/http/expiry.ts';
6
+ import type { HttpHeaderField } from './agent/http/types.ts';
7
+ import type { LookupPathStatus, LookupSubtreeStatus } from './certificate.ts';
12
8
  import { bytesToHex } from '@noble/hashes/utils';
13
9
 
14
10
  export enum ErrorKindEnum {
@@ -22,22 +18,59 @@ export enum ErrorKindEnum {
22
18
  Unknown = 'Unknown',
23
19
  }
24
20
 
25
- export type RequestContext = {
21
+ export interface RequestContext {
26
22
  requestId?: RequestId;
27
23
  senderPubKey: Uint8Array;
28
24
  senderSignature: Uint8Array;
29
25
  ingressExpiry: Expiry;
30
- };
26
+ }
31
27
 
32
- export type CallContext = {
28
+ /**
29
+ * Call context for errors that arise during polling.
30
+ */
31
+ export interface PollingCallContext {
33
32
  canisterId: Principal;
34
33
  methodName: string;
34
+ }
35
+
36
+ /**
37
+ * Call context for errors that arise from a direct HTTP call response.
38
+ */
39
+ export interface CallContext extends PollingCallContext {
35
40
  httpDetails: HttpDetailsResponse;
36
- };
41
+ }
42
+
43
+ /**
44
+ * Controls the level of detail included in error messages.
45
+ * - `Normal` (default): includes error message, call context, and HTTP details, but omits large binary fields (arg, certificate, nonce).
46
+ * - `Verbose`: same as Normal, but includes hex-encoded binary fields.
47
+ *
48
+ * To enable verbose mode: `ErrorCode.verbosity = ErrorVerbosity.Verbose`
49
+ */
50
+ export enum ErrorVerbosity {
51
+ Normal = 'normal',
52
+ Verbose = 'verbose',
53
+ }
54
+
55
+ const VERBOSE_ONLY_KEYS = new Set(['arg', 'certificate', 'nonce']);
56
+
57
+ function bytesReplacer(verbosity: ErrorVerbosity): (key: string, value: unknown) => unknown {
58
+ return (key: string, value: unknown): unknown => {
59
+ if (value instanceof Uint8Array) {
60
+ if (verbosity === ErrorVerbosity.Normal && VERBOSE_ONLY_KEYS.has(key)) {
61
+ return `<${value.length} bytes, set ErrorCode.verbosity = ErrorVerbosity.Verbose to display>`;
62
+ }
63
+ return `hex(${value.length}):${bytesToHex(value)}`;
64
+ }
65
+ return value;
66
+ };
67
+ }
68
+
69
+ export abstract class ErrorCode {
70
+ static verbosity: ErrorVerbosity = ErrorVerbosity.Normal;
37
71
 
38
- abstract class ErrorCode {
39
72
  public requestContext?: RequestContext;
40
- public callContext?: CallContext;
73
+ public callContext?: CallContext | PollingCallContext;
41
74
 
42
75
  constructor(public readonly isCertified: boolean = false) {}
43
76
 
@@ -57,8 +90,10 @@ abstract class ErrorCode {
57
90
  errorMessage +=
58
91
  `\nCall context:\n` +
59
92
  ` Canister ID: ${this.callContext.canisterId.toText()}\n` +
60
- ` Method name: ${this.callContext.methodName}\n` +
61
- ` HTTP details: ${JSON.stringify(this.callContext.httpDetails, null, 2)}`;
93
+ ` Method name: ${this.callContext.methodName}`;
94
+ if ('httpDetails' in this.callContext) {
95
+ errorMessage += `\n HTTP details: ${JSON.stringify(this.callContext.httpDetails, bytesReplacer(ErrorCode.verbosity), 2)}`;
96
+ }
62
97
  }
63
98
  return errorMessage;
64
99
  }
@@ -598,19 +633,6 @@ export class HashValueErrorCode extends ErrorCode {
598
633
  }
599
634
  }
600
635
 
601
- export class HttpDefaultFetchErrorCode extends ErrorCode {
602
- public name = 'HttpDefaultFetchErrorCode';
603
-
604
- constructor(public readonly error: string) {
605
- super();
606
- Object.setPrototypeOf(this, HttpDefaultFetchErrorCode.prototype);
607
- }
608
-
609
- public toErrorMessage(): string {
610
- return this.error;
611
- }
612
- }
613
-
614
636
  export class IdentityInvalidErrorCode extends ErrorCode {
615
637
  public name = 'IdentityInvalidErrorCode';
616
638
 
@@ -640,6 +662,19 @@ export class IngressExpiryInvalidErrorCode extends ErrorCode {
640
662
  }
641
663
  }
642
664
 
665
+ export class MissingFetchErrorCode extends ErrorCode {
666
+ public name = 'MissingFetchErrorCode';
667
+
668
+ constructor() {
669
+ super();
670
+ Object.setPrototypeOf(this, MissingFetchErrorCode.prototype);
671
+ }
672
+
673
+ public toErrorMessage(): string {
674
+ return 'No fetch implementation available. Provide a `fetch` function in HttpAgentOptions or ensure `globalThis.fetch` is defined.';
675
+ }
676
+ }
677
+
643
678
  export class CreateHttpAgentErrorCode extends ErrorCode {
644
679
  public name = 'CreateHttpAgentErrorCode';
645
680
 
@@ -653,6 +688,22 @@ export class CreateHttpAgentErrorCode extends ErrorCode {
653
688
  }
654
689
  }
655
690
 
691
+ export class ExcessiveSignaturesErrorCode extends ErrorCode {
692
+ public name = 'ExcessiveSignaturesErrorCode';
693
+
694
+ constructor(
695
+ public readonly signatureCount: number,
696
+ public readonly maxExpected: number,
697
+ ) {
698
+ super();
699
+ Object.setPrototypeOf(this, ExcessiveSignaturesErrorCode.prototype);
700
+ }
701
+
702
+ public toErrorMessage(): string {
703
+ return `Query response contains ${this.signatureCount} signatures, which exceeds the subnet size of ${this.maxExpected}. This suggests a malformed or malicious response.`;
704
+ }
705
+ }
706
+
656
707
  export class MalformedSignatureErrorCode extends ErrorCode {
657
708
  public name = 'MalformedSignatureErrorCode';
658
709
 
@@ -748,7 +799,7 @@ export class HttpErrorCode extends ErrorCode {
748
799
  let errorMessage =
749
800
  'HTTP request failed:\n' +
750
801
  ` Status: ${this.status} (${this.statusText})\n` +
751
- ` Headers: ${JSON.stringify(this.headers)}\n`;
802
+ ` Headers: ${JSON.stringify(this.headers, bytesReplacer(ErrorCode.verbosity))}\n`;
752
803
  if (this.bodyText) {
753
804
  errorMessage += ` Body: ${this.bodyText}\n`;
754
805
  }
@@ -868,7 +919,7 @@ function formatUnknownError(error: unknown): string {
868
919
  return error.stack ?? error.message;
869
920
  }
870
921
  try {
871
- return JSON.stringify(error);
922
+ return JSON.stringify(error, bytesReplacer(ErrorCode.verbosity));
872
923
  } catch {
873
924
  return String(error);
874
925
  }
@@ -1,6 +1,6 @@
1
1
  import { Principal } from '#principal';
2
2
  import * as CanisterStatus from './canisterStatus/index.ts';
3
- import { IDL } from '#candid';
3
+ import type { IDL } from '#candid';
4
4
  import { HttpAgent } from './agent/http/index.ts';
5
5
  import { Actor, type ActorSubclass } from './actor.ts';
6
6
 
@@ -108,6 +108,7 @@ export * from './request_id.ts';
108
108
  export * from './utils/bls.ts';
109
109
  export * from './utils/buffer.ts';
110
110
  export * from './utils/random.ts';
111
+ export { type ExpirableStore } from './utils/expirableStore.ts';
111
112
  export * as polling from './polling/index.ts';
112
113
  import * as CanisterStatus from './canisterStatus/index.ts';
113
114
  import * as SubnetStatus from './subnetStatus/index.ts';
@@ -1,4 +1,4 @@
1
- import { AgentError } from './errors.ts';
1
+ import type { AgentError } from './errors.ts';
2
2
 
3
3
  export type ObserveFunction<T> = (data: T, ...rest: unknown[]) => void;
4
4
 
@@ -5,23 +5,23 @@ const MAX_INTERVAL_MSEC = 60_000;
5
5
  const MAX_ELAPSED_TIME_MSEC = 900_000;
6
6
  const MAX_ITERATIONS = 10;
7
7
 
8
- export type BackoffStrategy = {
8
+ export interface BackoffStrategy {
9
9
  next: () => number | null;
10
10
  currentInterval?: number;
11
11
  count?: number;
12
12
  ellapsedTimeInMsec?: number;
13
- };
13
+ }
14
14
 
15
- export type BackoffStrategyArgs = {
15
+ export interface BackoffStrategyArgs {
16
16
  maxIterations?: number;
17
17
  maxElapsedTime?: number;
18
- };
18
+ }
19
19
 
20
20
  export type BackoffStrategyFactory = (args?: BackoffStrategyArgs) => BackoffStrategy;
21
21
 
22
22
  // export type BackoffStrategyGenerator = Generator<number, void, unknown>;
23
23
 
24
- export type ExponentialBackoffOptions = {
24
+ export interface ExponentialBackoffOptions {
25
25
  initialInterval?: number;
26
26
  randomizationFactor?: number;
27
27
  multiplier?: number;
@@ -29,7 +29,7 @@ export type ExponentialBackoffOptions = {
29
29
  maxElapsedTime?: number;
30
30
  maxIterations?: number;
31
31
  date?: DateConstructor;
32
- };
32
+ }
33
33
 
34
34
  /**
35
35
  * Exponential backoff strategy.
@@ -105,17 +105,16 @@ export class ExponentialBackoff {
105
105
  public next() {
106
106
  if (this.ellapsedTimeInMsec >= this.#maxElapsedTime || this.#count >= this.#maxIterations) {
107
107
  return null;
108
- } else {
109
- this.incrementCurrentInterval();
110
- return this.randomValueFromInterval;
111
108
  }
109
+ this.incrementCurrentInterval();
110
+ return this.randomValueFromInterval;
112
111
  }
113
112
  }
114
113
  /**
115
114
  * Utility function to create an exponential backoff iterator.
116
115
  * @param options - for the exponential backoff
117
116
  * @returns an iterator that yields the next delay in the exponential backoff
118
- * @yields the next delay in the exponential backoff
117
+ * @yields {number} the next delay in the exponential backoff
119
118
  */
120
119
  export function* exponentialBackoff(
121
120
  options: ExponentialBackoffOptions = ExponentialBackoff.default,