@icp-sdk/core 4.2.3 → 5.0.0-beta.1

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 (474) hide show
  1. package/lib/cjs/agent/actor.d.ts +203 -0
  2. package/lib/cjs/agent/actor.d.ts.map +1 -0
  3. package/lib/cjs/agent/actor.js +341 -0
  4. package/lib/cjs/agent/actor.js.map +1 -0
  5. package/lib/cjs/agent/agent/api.d.ts +216 -0
  6. package/lib/cjs/agent/agent/api.d.ts.map +1 -0
  7. package/lib/cjs/agent/agent/api.js +39 -0
  8. package/lib/cjs/agent/agent/api.js.map +1 -0
  9. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts +37 -0
  10. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
  11. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js +51 -0
  12. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
  13. package/lib/cjs/agent/agent/http/index.d.ts +190 -0
  14. package/lib/cjs/agent/agent/http/index.d.ts.map +1 -0
  15. package/lib/cjs/agent/agent/http/index.js +1159 -0
  16. package/lib/cjs/agent/agent/http/index.js.map +1 -0
  17. package/lib/cjs/agent/agent/http/transforms.d.ts +54 -0
  18. package/lib/cjs/agent/agent/http/transforms.d.ts.map +1 -0
  19. package/lib/cjs/agent/agent/http/transforms.js +135 -0
  20. package/lib/cjs/agent/agent/http/transforms.js.map +1 -0
  21. package/lib/cjs/agent/agent/http/types.d.ts +81 -0
  22. package/lib/cjs/agent/agent/http/types.d.ts.map +1 -0
  23. package/lib/cjs/agent/agent/http/types.js +43 -0
  24. package/lib/cjs/agent/agent/http/types.js.map +1 -0
  25. package/lib/cjs/agent/agent/index.d.ts +3 -0
  26. package/lib/cjs/agent/agent/index.d.ts.map +1 -0
  27. package/lib/cjs/agent/agent/index.js +19 -0
  28. package/lib/cjs/agent/agent/index.js.map +1 -0
  29. package/lib/cjs/agent/auth.d.ts +91 -0
  30. package/lib/cjs/agent/auth.d.ts.map +1 -0
  31. package/lib/cjs/agent/auth.js +65 -0
  32. package/lib/cjs/agent/auth.js.map +1 -0
  33. package/lib/cjs/agent/canisterStatus/index.d.ts +61 -0
  34. package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -0
  35. package/lib/cjs/agent/canisterStatus/index.js +239 -0
  36. package/lib/cjs/agent/canisterStatus/index.js.map +1 -0
  37. package/lib/cjs/agent/cbor.d.ts +26 -0
  38. package/lib/cjs/agent/cbor.d.ts.map +1 -0
  39. package/lib/cjs/agent/cbor.js +93 -0
  40. package/lib/cjs/agent/cbor.js.map +1 -0
  41. package/lib/cjs/agent/certificate.d.ts +286 -0
  42. package/lib/cjs/agent/certificate.d.ts.map +1 -0
  43. package/lib/cjs/agent/certificate.js +762 -0
  44. package/lib/cjs/agent/certificate.js.map +1 -0
  45. package/lib/cjs/agent/constants.d.ts +18 -0
  46. package/lib/cjs/agent/constants.d.ts.map +1 -0
  47. package/lib/cjs/agent/constants.js +22 -0
  48. package/lib/cjs/agent/constants.js.map +1 -0
  49. package/lib/cjs/agent/der.d.ts +34 -0
  50. package/lib/cjs/agent/der.d.ts.map +1 -0
  51. package/lib/cjs/agent/der.js +175 -0
  52. package/lib/cjs/agent/der.js.map +1 -0
  53. package/lib/cjs/agent/errors.d.ts +386 -0
  54. package/lib/cjs/agent/errors.d.ts.map +1 -0
  55. package/lib/cjs/agent/errors.js +745 -0
  56. package/lib/cjs/agent/errors.js.map +1 -0
  57. package/lib/cjs/agent/fetch_candid.d.ts +9 -0
  58. package/lib/cjs/agent/fetch_candid.d.ts.map +1 -0
  59. package/lib/cjs/agent/fetch_candid.js +69 -0
  60. package/lib/cjs/agent/fetch_candid.js.map +1 -0
  61. package/lib/cjs/agent/index.d.ts +125 -1
  62. package/lib/cjs/agent/index.d.ts.map +1 -1
  63. package/lib/cjs/agent/index.js +142 -1
  64. package/lib/cjs/agent/index.js.map +1 -1
  65. package/lib/cjs/agent/observable.d.ts +24 -0
  66. package/lib/cjs/agent/observable.d.ts.map +1 -0
  67. package/lib/cjs/agent/observable.js +34 -0
  68. package/lib/cjs/agent/observable.js.map +1 -0
  69. package/lib/cjs/agent/polling/backoff.d.ts +50 -0
  70. package/lib/cjs/agent/polling/backoff.d.ts.map +1 -0
  71. package/lib/cjs/agent/polling/backoff.js +90 -0
  72. package/lib/cjs/agent/polling/backoff.js.map +1 -0
  73. package/lib/cjs/agent/polling/index.d.ts +63 -0
  74. package/lib/cjs/agent/polling/index.d.ts.map +1 -0
  75. package/lib/cjs/agent/polling/index.js +183 -0
  76. package/lib/cjs/agent/polling/index.js.map +1 -0
  77. package/lib/cjs/agent/polling/strategy.d.ts +52 -0
  78. package/lib/cjs/agent/polling/strategy.d.ts.map +1 -0
  79. package/lib/cjs/agent/polling/strategy.js +104 -0
  80. package/lib/cjs/agent/polling/strategy.js.map +1 -0
  81. package/lib/cjs/agent/public_key.d.ts +16 -0
  82. package/lib/cjs/agent/public_key.d.ts.map +1 -0
  83. package/lib/cjs/agent/public_key.js +52 -0
  84. package/lib/cjs/agent/public_key.js.map +1 -0
  85. package/lib/cjs/agent/request_id.d.ts +24 -0
  86. package/lib/cjs/agent/request_id.d.ts.map +1 -0
  87. package/lib/cjs/agent/request_id.js +88 -0
  88. package/lib/cjs/agent/request_id.js.map +1 -0
  89. package/lib/cjs/agent/subnetStatus/index.d.ts +70 -0
  90. package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -0
  91. package/lib/cjs/agent/subnetStatus/index.js +224 -0
  92. package/lib/cjs/agent/subnetStatus/index.js.map +1 -0
  93. package/lib/cjs/agent/utils/bls.d.ts +10 -0
  94. package/lib/cjs/agent/utils/bls.d.ts.map +1 -0
  95. package/lib/cjs/agent/utils/bls.js +20 -0
  96. package/lib/cjs/agent/utils/bls.js.map +1 -0
  97. package/lib/cjs/agent/utils/buffer.d.ts +22 -0
  98. package/lib/cjs/agent/utils/buffer.d.ts.map +1 -0
  99. package/lib/cjs/agent/utils/buffer.js +55 -0
  100. package/lib/cjs/agent/utils/buffer.js.map +1 -0
  101. package/lib/cjs/agent/utils/expirableMap.d.ts +80 -0
  102. package/lib/cjs/agent/utils/expirableMap.d.ts.map +1 -0
  103. package/lib/cjs/agent/utils/expirableMap.js +148 -0
  104. package/lib/cjs/agent/utils/expirableMap.js.map +1 -0
  105. package/lib/cjs/agent/utils/leb.d.ts +3 -0
  106. package/lib/cjs/agent/utils/leb.d.ts.map +1 -0
  107. package/lib/cjs/agent/utils/leb.js +17 -0
  108. package/lib/cjs/agent/utils/leb.js.map +1 -0
  109. package/lib/cjs/agent/utils/random.d.ts +6 -0
  110. package/lib/cjs/agent/utils/random.d.ts.map +1 -0
  111. package/lib/cjs/agent/utils/random.js +29 -0
  112. package/lib/cjs/agent/utils/random.js.map +1 -0
  113. package/lib/cjs/agent/utils/readState.d.ts +84 -0
  114. package/lib/cjs/agent/utils/readState.d.ts.map +1 -0
  115. package/lib/cjs/agent/utils/readState.js +149 -0
  116. package/lib/cjs/agent/utils/readState.js.map +1 -0
  117. package/lib/cjs/candid/candid-core.d.ts +72 -0
  118. package/lib/cjs/candid/candid-core.d.ts.map +1 -0
  119. package/lib/cjs/candid/candid-core.js +251 -0
  120. package/lib/cjs/candid/candid-core.js.map +1 -0
  121. package/lib/cjs/candid/candid-ui.d.ts +35 -0
  122. package/lib/cjs/candid/candid-ui.d.ts.map +1 -0
  123. package/lib/cjs/candid/candid-ui.js +317 -0
  124. package/lib/cjs/candid/candid-ui.js.map +1 -0
  125. package/lib/cjs/candid/idl.d.ts +579 -0
  126. package/lib/cjs/candid/idl.d.ts.map +1 -0
  127. package/lib/cjs/candid/idl.js +2228 -0
  128. package/lib/cjs/candid/idl.js.map +1 -0
  129. package/lib/cjs/candid/index.d.ts +30 -1
  130. package/lib/cjs/candid/index.d.ts.map +1 -1
  131. package/lib/cjs/candid/index.js +52 -1
  132. package/lib/cjs/candid/index.js.map +1 -1
  133. package/lib/cjs/candid/types.d.ts +6 -0
  134. package/lib/cjs/candid/types.d.ts.map +1 -0
  135. package/lib/cjs/candid/types.js +4 -0
  136. package/lib/cjs/candid/types.js.map +1 -0
  137. package/lib/cjs/candid/utils/bigint-math.d.ts +14 -0
  138. package/lib/cjs/candid/utils/bigint-math.d.ts.map +1 -0
  139. package/lib/cjs/candid/utils/bigint-math.js +30 -0
  140. package/lib/cjs/candid/utils/bigint-math.js.map +1 -0
  141. package/lib/cjs/candid/utils/buffer.d.ts +86 -0
  142. package/lib/cjs/candid/utils/buffer.d.ts.map +1 -0
  143. package/lib/cjs/candid/utils/buffer.js +191 -0
  144. package/lib/cjs/candid/utils/buffer.js.map +1 -0
  145. package/lib/cjs/candid/utils/hash.d.ts +7 -0
  146. package/lib/cjs/candid/utils/hash.d.ts.map +1 -0
  147. package/lib/cjs/candid/utils/hash.js +33 -0
  148. package/lib/cjs/candid/utils/hash.js.map +1 -0
  149. package/lib/cjs/candid/utils/leb128.d.ts +65 -0
  150. package/lib/cjs/candid/utils/leb128.d.ts.map +1 -0
  151. package/lib/cjs/candid/utils/leb128.js +228 -0
  152. package/lib/cjs/candid/utils/leb128.js.map +1 -0
  153. package/lib/cjs/identity/identity/delegation.d.ts +164 -0
  154. package/lib/cjs/identity/identity/delegation.d.ts.map +1 -0
  155. package/lib/cjs/identity/identity/delegation.js +302 -0
  156. package/lib/cjs/identity/identity/delegation.js.map +1 -0
  157. package/lib/cjs/identity/identity/ecdsa.d.ts +62 -0
  158. package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -0
  159. package/lib/cjs/identity/identity/ecdsa.js +117 -0
  160. package/lib/cjs/identity/identity/ecdsa.js.map +1 -0
  161. package/lib/cjs/identity/identity/ed25519.d.ts +67 -0
  162. package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -0
  163. package/lib/cjs/identity/identity/ed25519.js +200 -0
  164. package/lib/cjs/identity/identity/ed25519.js.map +1 -0
  165. package/lib/cjs/identity/identity/partial.d.ts +34 -0
  166. package/lib/cjs/identity/identity/partial.d.ts.map +1 -0
  167. package/lib/cjs/identity/identity/partial.js +54 -0
  168. package/lib/cjs/identity/identity/partial.js.map +1 -0
  169. package/lib/cjs/identity/identity/webauthn.d.ts +51 -0
  170. package/lib/cjs/identity/identity/webauthn.d.ts.map +1 -0
  171. package/lib/cjs/identity/identity/webauthn.js +197 -0
  172. package/lib/cjs/identity/identity/webauthn.js.map +1 -0
  173. package/lib/cjs/identity/index.d.ts +38 -1
  174. package/lib/cjs/identity/index.d.ts.map +1 -1
  175. package/lib/cjs/identity/index.js +44 -1
  176. package/lib/cjs/identity/index.js.map +1 -1
  177. package/lib/cjs/identity/secp256k1/der.d.ts +33 -0
  178. package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -0
  179. package/lib/cjs/identity/secp256k1/der.js +165 -0
  180. package/lib/cjs/identity/secp256k1/der.js.map +1 -0
  181. package/lib/cjs/identity/secp256k1/index.d.ts +51 -1
  182. package/lib/cjs/identity/secp256k1/index.d.ts.map +1 -1
  183. package/lib/cjs/identity/secp256k1/index.js +51 -1
  184. package/lib/cjs/identity/secp256k1/index.js.map +1 -1
  185. package/lib/cjs/identity/secp256k1/pem.d.ts +7 -0
  186. package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -0
  187. package/lib/cjs/identity/secp256k1/pem.js +75 -0
  188. package/lib/cjs/identity/secp256k1/pem.js.map +1 -0
  189. package/lib/cjs/identity/secp256k1/secp256k1.d.ts +87 -0
  190. package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -0
  191. package/lib/cjs/identity/secp256k1/secp256k1.js +260 -0
  192. package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -0
  193. package/lib/cjs/principal/index.d.ts +18 -1
  194. package/lib/cjs/principal/index.d.ts.map +1 -1
  195. package/lib/cjs/principal/index.js +22 -1
  196. package/lib/cjs/principal/index.js.map +1 -1
  197. package/lib/cjs/principal/principal.d.ts +50 -0
  198. package/lib/cjs/principal/principal.d.ts.map +1 -0
  199. package/lib/cjs/principal/principal.js +148 -0
  200. package/lib/cjs/principal/principal.js.map +1 -0
  201. package/lib/cjs/principal/utils/base32.d.ts +10 -0
  202. package/lib/cjs/principal/utils/base32.d.ts.map +1 -0
  203. package/lib/cjs/principal/utils/base32.js +90 -0
  204. package/lib/cjs/principal/utils/base32.js.map +1 -0
  205. package/lib/cjs/principal/utils/getCrc.d.ts +6 -0
  206. package/lib/cjs/principal/utils/getCrc.d.ts.map +1 -0
  207. package/lib/cjs/principal/utils/getCrc.js +53 -0
  208. package/lib/cjs/principal/utils/getCrc.js.map +1 -0
  209. package/lib/esm/agent/actor.d.ts +203 -0
  210. package/lib/esm/agent/actor.d.ts.map +1 -0
  211. package/lib/esm/agent/actor.js +337 -0
  212. package/lib/esm/agent/actor.js.map +1 -0
  213. package/lib/esm/agent/agent/api.d.ts +216 -0
  214. package/lib/esm/agent/agent/api.d.ts.map +1 -0
  215. package/lib/esm/agent/agent/api.js +34 -0
  216. package/lib/esm/agent/agent/api.js.map +1 -0
  217. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts +37 -0
  218. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
  219. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js +48 -0
  220. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
  221. package/lib/esm/agent/agent/http/index.d.ts +190 -0
  222. package/lib/esm/agent/agent/http/index.d.ts.map +1 -0
  223. package/lib/esm/agent/agent/http/index.js +1117 -0
  224. package/lib/esm/agent/agent/http/index.js.map +1 -0
  225. package/lib/esm/agent/agent/http/transforms.d.ts +54 -0
  226. package/lib/esm/agent/agent/http/transforms.d.ts.map +1 -0
  227. package/lib/esm/agent/agent/http/transforms.js +128 -0
  228. package/lib/esm/agent/agent/http/transforms.js.map +1 -0
  229. package/lib/esm/agent/agent/http/types.d.ts +81 -0
  230. package/lib/esm/agent/agent/http/types.d.ts.map +1 -0
  231. package/lib/esm/agent/agent/http/types.js +39 -0
  232. package/lib/esm/agent/agent/http/types.js.map +1 -0
  233. package/lib/esm/agent/agent/index.d.ts +3 -0
  234. package/lib/esm/agent/agent/index.d.ts.map +1 -0
  235. package/lib/esm/agent/agent/index.js +3 -0
  236. package/lib/esm/agent/agent/index.js.map +1 -0
  237. package/lib/esm/agent/auth.d.ts +91 -0
  238. package/lib/esm/agent/auth.d.ts.map +1 -0
  239. package/lib/esm/agent/auth.js +59 -0
  240. package/lib/esm/agent/auth.js.map +1 -0
  241. package/lib/esm/agent/canister-env/index.d.ts +111 -1
  242. package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
  243. package/lib/esm/agent/canister-env/index.js +111 -1
  244. package/lib/esm/agent/canister-env/index.js.map +1 -1
  245. package/lib/esm/agent/canisterStatus/index.d.ts +61 -0
  246. package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -0
  247. package/lib/esm/agent/canisterStatus/index.js +199 -0
  248. package/lib/esm/agent/canisterStatus/index.js.map +1 -0
  249. package/lib/esm/agent/cbor.d.ts +26 -0
  250. package/lib/esm/agent/cbor.d.ts.map +1 -0
  251. package/lib/esm/agent/cbor.js +54 -0
  252. package/lib/esm/agent/cbor.js.map +1 -0
  253. package/lib/esm/agent/certificate.d.ts +286 -0
  254. package/lib/esm/agent/certificate.d.ts.map +1 -0
  255. package/lib/esm/agent/certificate.js +712 -0
  256. package/lib/esm/agent/certificate.js.map +1 -0
  257. package/lib/esm/agent/constants.d.ts +18 -0
  258. package/lib/esm/agent/constants.d.ts.map +1 -0
  259. package/lib/esm/agent/constants.js +19 -0
  260. package/lib/esm/agent/constants.js.map +1 -0
  261. package/lib/esm/agent/der.d.ts +34 -0
  262. package/lib/esm/agent/der.d.ts.map +1 -0
  263. package/lib/esm/agent/der.js +166 -0
  264. package/lib/esm/agent/der.js.map +1 -0
  265. package/lib/esm/agent/errors.d.ts +386 -0
  266. package/lib/esm/agent/errors.d.ts.map +1 -0
  267. package/lib/esm/agent/errors.js +689 -0
  268. package/lib/esm/agent/errors.js.map +1 -0
  269. package/lib/esm/agent/fetch_candid.d.ts +9 -0
  270. package/lib/esm/agent/fetch_candid.d.ts.map +1 -0
  271. package/lib/esm/agent/fetch_candid.js +33 -0
  272. package/lib/esm/agent/fetch_candid.js.map +1 -0
  273. package/lib/esm/agent/index.d.ts +125 -1
  274. package/lib/esm/agent/index.d.ts.map +1 -1
  275. package/lib/esm/agent/index.js +125 -1
  276. package/lib/esm/agent/index.js.map +1 -1
  277. package/lib/esm/agent/observable.d.ts +24 -0
  278. package/lib/esm/agent/observable.d.ts.map +1 -0
  279. package/lib/esm/agent/observable.js +29 -0
  280. package/lib/esm/agent/observable.js.map +1 -0
  281. package/lib/esm/agent/polling/backoff.d.ts +50 -0
  282. package/lib/esm/agent/polling/backoff.d.ts.map +1 -0
  283. package/lib/esm/agent/polling/backoff.js +85 -0
  284. package/lib/esm/agent/polling/backoff.js.map +1 -0
  285. package/lib/esm/agent/polling/index.d.ts +63 -0
  286. package/lib/esm/agent/polling/index.d.ts.map +1 -0
  287. package/lib/esm/agent/polling/index.js +144 -0
  288. package/lib/esm/agent/polling/index.js.map +1 -0
  289. package/lib/esm/agent/polling/strategy.d.ts +52 -0
  290. package/lib/esm/agent/polling/strategy.d.ts.map +1 -0
  291. package/lib/esm/agent/polling/strategy.js +94 -0
  292. package/lib/esm/agent/polling/strategy.js.map +1 -0
  293. package/lib/esm/agent/public_key.d.ts +16 -0
  294. package/lib/esm/agent/public_key.d.ts.map +1 -0
  295. package/lib/esm/agent/public_key.js +48 -0
  296. package/lib/esm/agent/public_key.js.map +1 -0
  297. package/lib/esm/agent/request_id.d.ts +24 -0
  298. package/lib/esm/agent/request_id.d.ts.map +1 -0
  299. package/lib/esm/agent/request_id.js +83 -0
  300. package/lib/esm/agent/request_id.js.map +1 -0
  301. package/lib/esm/agent/subnetStatus/index.d.ts +70 -0
  302. package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -0
  303. package/lib/esm/agent/subnetStatus/index.js +183 -0
  304. package/lib/esm/agent/subnetStatus/index.js.map +1 -0
  305. package/lib/esm/agent/utils/bls.d.ts +10 -0
  306. package/lib/esm/agent/utils/bls.d.ts.map +1 -0
  307. package/lib/esm/agent/utils/bls.js +17 -0
  308. package/lib/esm/agent/utils/bls.js.map +1 -0
  309. package/lib/esm/agent/utils/buffer.d.ts +22 -0
  310. package/lib/esm/agent/utils/buffer.d.ts.map +1 -0
  311. package/lib/esm/agent/utils/buffer.js +50 -0
  312. package/lib/esm/agent/utils/buffer.js.map +1 -0
  313. package/lib/esm/agent/utils/expirableMap.d.ts +80 -0
  314. package/lib/esm/agent/utils/expirableMap.d.ts.map +1 -0
  315. package/lib/esm/agent/utils/expirableMap.js +144 -0
  316. package/lib/esm/agent/utils/expirableMap.js.map +1 -0
  317. package/lib/esm/agent/utils/leb.d.ts +3 -0
  318. package/lib/esm/agent/utils/leb.d.ts.map +1 -0
  319. package/lib/esm/agent/utils/leb.js +12 -0
  320. package/lib/esm/agent/utils/leb.js.map +1 -0
  321. package/lib/esm/agent/utils/random.d.ts +6 -0
  322. package/lib/esm/agent/utils/random.d.ts.map +1 -0
  323. package/lib/esm/agent/utils/random.js +25 -0
  324. package/lib/esm/agent/utils/random.js.map +1 -0
  325. package/lib/esm/agent/utils/readState.d.ts +84 -0
  326. package/lib/esm/agent/utils/readState.d.ts.map +1 -0
  327. package/lib/esm/agent/utils/readState.js +107 -0
  328. package/lib/esm/agent/utils/readState.js.map +1 -0
  329. package/lib/esm/candid/candid-core.d.ts +72 -0
  330. package/lib/esm/candid/candid-core.d.ts.map +1 -0
  331. package/lib/esm/candid/candid-core.js +241 -0
  332. package/lib/esm/candid/candid-core.js.map +1 -0
  333. package/lib/esm/candid/candid-ui.d.ts +35 -0
  334. package/lib/esm/candid/candid-ui.d.ts.map +1 -0
  335. package/lib/esm/candid/candid-ui.js +272 -0
  336. package/lib/esm/candid/candid-ui.js.map +1 -0
  337. package/lib/esm/candid/idl.d.ts +579 -0
  338. package/lib/esm/candid/idl.d.ts.map +1 -0
  339. package/lib/esm/candid/idl.js +2189 -0
  340. package/lib/esm/candid/idl.js.map +1 -0
  341. package/lib/esm/candid/index.d.ts +30 -1
  342. package/lib/esm/candid/index.d.ts.map +1 -1
  343. package/lib/esm/candid/index.js +29 -1
  344. package/lib/esm/candid/index.js.map +1 -1
  345. package/lib/esm/candid/types.d.ts +6 -0
  346. package/lib/esm/candid/types.d.ts.map +1 -0
  347. package/lib/esm/candid/types.js +3 -0
  348. package/lib/esm/candid/types.js.map +1 -0
  349. package/lib/esm/candid/utils/bigint-math.d.ts +14 -0
  350. package/lib/esm/candid/utils/bigint-math.d.ts.map +1 -0
  351. package/lib/esm/candid/utils/bigint-math.js +26 -0
  352. package/lib/esm/candid/utils/bigint-math.js.map +1 -0
  353. package/lib/esm/candid/utils/buffer.d.ts +86 -0
  354. package/lib/esm/candid/utils/buffer.d.ts.map +1 -0
  355. package/lib/esm/candid/utils/buffer.js +182 -0
  356. package/lib/esm/candid/utils/buffer.js.map +1 -0
  357. package/lib/esm/candid/utils/hash.d.ts +7 -0
  358. package/lib/esm/candid/utils/hash.d.ts.map +1 -0
  359. package/lib/esm/candid/utils/hash.js +30 -0
  360. package/lib/esm/candid/utils/hash.js.map +1 -0
  361. package/lib/esm/candid/utils/leb128.d.ts +65 -0
  362. package/lib/esm/candid/utils/leb128.d.ts.map +1 -0
  363. package/lib/esm/candid/utils/leb128.js +216 -0
  364. package/lib/esm/candid/utils/leb128.js.map +1 -0
  365. package/lib/esm/identity/identity/delegation.d.ts +164 -0
  366. package/lib/esm/identity/identity/delegation.d.ts.map +1 -0
  367. package/lib/esm/identity/identity/delegation.js +294 -0
  368. package/lib/esm/identity/identity/delegation.js.map +1 -0
  369. package/lib/esm/identity/identity/ecdsa.d.ts +62 -0
  370. package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -0
  371. package/lib/esm/identity/identity/ecdsa.js +112 -0
  372. package/lib/esm/identity/identity/ecdsa.js.map +1 -0
  373. package/lib/esm/identity/identity/ed25519.d.ts +67 -0
  374. package/lib/esm/identity/identity/ed25519.d.ts.map +1 -0
  375. package/lib/esm/identity/identity/ed25519.js +195 -0
  376. package/lib/esm/identity/identity/ed25519.js.map +1 -0
  377. package/lib/esm/identity/identity/partial.d.ts +34 -0
  378. package/lib/esm/identity/identity/partial.d.ts.map +1 -0
  379. package/lib/esm/identity/identity/partial.js +50 -0
  380. package/lib/esm/identity/identity/partial.js.map +1 -0
  381. package/lib/esm/identity/identity/webauthn.d.ts +51 -0
  382. package/lib/esm/identity/identity/webauthn.d.ts.map +1 -0
  383. package/lib/esm/identity/identity/webauthn.js +192 -0
  384. package/lib/esm/identity/identity/webauthn.js.map +1 -0
  385. package/lib/esm/identity/index.d.ts +38 -1
  386. package/lib/esm/identity/index.d.ts.map +1 -1
  387. package/lib/esm/identity/index.js +38 -1
  388. package/lib/esm/identity/index.js.map +1 -1
  389. package/lib/esm/identity/secp256k1/der.d.ts +33 -0
  390. package/lib/esm/identity/secp256k1/der.d.ts.map +1 -0
  391. package/lib/esm/identity/secp256k1/der.js +156 -0
  392. package/lib/esm/identity/secp256k1/der.js.map +1 -0
  393. package/lib/esm/identity/secp256k1/index.d.ts +51 -1
  394. package/lib/esm/identity/secp256k1/index.d.ts.map +1 -1
  395. package/lib/esm/identity/secp256k1/index.js +51 -1
  396. package/lib/esm/identity/secp256k1/index.js.map +1 -1
  397. package/lib/esm/identity/secp256k1/pem.d.ts +7 -0
  398. package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -0
  399. package/lib/esm/identity/secp256k1/pem.js +39 -0
  400. package/lib/esm/identity/secp256k1/pem.js.map +1 -0
  401. package/lib/esm/identity/secp256k1/secp256k1.d.ts +87 -0
  402. package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -0
  403. package/lib/esm/identity/secp256k1/secp256k1.js +222 -0
  404. package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -0
  405. package/lib/esm/principal/index.d.ts +18 -1
  406. package/lib/esm/principal/index.d.ts.map +1 -1
  407. package/lib/esm/principal/index.js +18 -1
  408. package/lib/esm/principal/index.js.map +1 -1
  409. package/lib/esm/principal/principal.d.ts +50 -0
  410. package/lib/esm/principal/principal.d.ts.map +1 -0
  411. package/lib/esm/principal/principal.js +144 -0
  412. package/lib/esm/principal/principal.js.map +1 -0
  413. package/lib/esm/principal/utils/base32.d.ts +10 -0
  414. package/lib/esm/principal/utils/base32.d.ts.map +1 -0
  415. package/lib/esm/principal/utils/base32.js +86 -0
  416. package/lib/esm/principal/utils/base32.js.map +1 -0
  417. package/lib/esm/principal/utils/getCrc.d.ts +6 -0
  418. package/lib/esm/principal/utils/getCrc.d.ts.map +1 -0
  419. package/lib/esm/principal/utils/getCrc.js +50 -0
  420. package/lib/esm/principal/utils/getCrc.js.map +1 -0
  421. package/package.json +17 -11
  422. package/src/agent/actor.ts +576 -0
  423. package/src/agent/agent/api.ts +262 -0
  424. package/src/agent/agent/http/index.ts +1518 -0
  425. package/src/agent/agent/http/transforms.ts +158 -0
  426. package/src/agent/agent/http/types.ts +126 -0
  427. package/src/agent/agent/index.ts +2 -0
  428. package/src/agent/auth.ts +147 -0
  429. package/src/agent/canister-env/index.ts +192 -1
  430. package/src/agent/canisterStatus/index.ts +267 -0
  431. package/src/agent/cbor.ts +63 -0
  432. package/src/agent/certificate.ts +1060 -0
  433. package/src/agent/constants.ts +24 -0
  434. package/src/agent/der.ts +170 -0
  435. package/src/agent/errors.ts +881 -0
  436. package/src/agent/fetch_candid.ts +37 -0
  437. package/src/agent/index.ts +131 -1
  438. package/src/agent/observable.ts +49 -0
  439. package/src/agent/polling/backoff.ts +130 -0
  440. package/src/agent/polling/index.ts +250 -0
  441. package/src/agent/polling/strategy.ts +144 -0
  442. package/src/agent/public_key.ts +65 -0
  443. package/src/agent/request_id.ts +92 -0
  444. package/src/agent/subnetStatus/index.ts +270 -0
  445. package/src/agent/utils/bls.ts +18 -0
  446. package/src/agent/utils/buffer.ts +60 -0
  447. package/src/agent/utils/expirableMap.ts +163 -0
  448. package/src/agent/utils/leb.ts +14 -0
  449. package/src/agent/utils/random.ts +30 -0
  450. package/src/agent/utils/readState.ts +180 -0
  451. package/src/candid/candid-core.ts +276 -0
  452. package/src/candid/candid-ui.ts +289 -0
  453. package/src/candid/idl.ts +2556 -0
  454. package/src/candid/index.ts +35 -1
  455. package/src/candid/types.ts +7 -0
  456. package/src/candid/utils/bigint-math.ts +26 -0
  457. package/src/candid/utils/buffer.ts +221 -0
  458. package/src/candid/utils/hash.ts +31 -0
  459. package/src/candid/utils/leb128.ts +234 -0
  460. package/src/identity/identity/delegation.ts +411 -0
  461. package/src/identity/identity/ecdsa.ts +158 -0
  462. package/src/identity/identity/ed25519.ts +239 -0
  463. package/src/identity/identity/partial.ts +60 -0
  464. package/src/identity/identity/webauthn.ts +265 -0
  465. package/src/identity/index.ts +39 -1
  466. package/src/identity/secp256k1/der.ts +156 -0
  467. package/src/identity/secp256k1/index.ts +52 -1
  468. package/src/identity/secp256k1/pem.ts +40 -0
  469. package/src/identity/secp256k1/secp256k1.ts +270 -0
  470. package/src/package.json +4 -0
  471. package/src/principal/index.ts +19 -1
  472. package/src/principal/principal.ts +171 -0
  473. package/src/principal/utils/base32.ts +101 -0
  474. package/src/principal/utils/getCrc.ts +52 -0
@@ -1,2 +1,112 @@
1
- export * from '@dfinity/agent/canister-env';
1
+ /**
2
+ * @experimental
3
+ * @see https://js.icp.build/core/latest/canister-environment
4
+ * @module libs/agent/canister-env/api
5
+ */
6
+ /**
7
+ * The environment variables served by the asset canister that hosts the frontend.
8
+ * You can extend the `CanisterEnv` interface to add your own environment variables
9
+ * and have strong typing for them.
10
+ * @see The {@link https://js.icp.build/core/latest/canister-environment/ | Canister Environment Guide} for more details on how to use the canister environment in a frontend application
11
+ * @experimental
12
+ * @example
13
+ * Extend the global `CanisterEnv` interface to add your own environment variables:
14
+ * ```ts title="index.ts"
15
+ * // You can declare the interface to have strong typing
16
+ * // for your own environment variables across your codebase
17
+ * declare module '@icp-sdk/core/agent/canister-env' {
18
+ * interface CanisterEnv {
19
+ * readonly ['PUBLIC_CANISTER_ID:backend']: string;
20
+ * readonly PUBLIC_API_URL: string;
21
+ * }
22
+ * }
23
+ *
24
+ * const env = getCanisterEnv();
25
+ *
26
+ * console.log(env.IC_ROOT_KEY); // by default served by the asset canister
27
+ * console.log(env['PUBLIC_CANISTER_ID:backend']); // ✅ TS passes
28
+ * console.log(env.PUBLIC_API_URL); // ✅ TS passes
29
+ * console.log(env['PUBLIC_CANISTER_ID:another']); // ❌ TS will show an error
30
+ * ```
31
+ * @example
32
+ * Alternatively, use the generic parameter to specify additional properties:
33
+ * ```ts title="index.ts"
34
+ * const env = getCanisterEnv<{ readonly ['PUBLIC_CANISTER_ID:backend']: string }>();
35
+ *
36
+ * console.log(env.IC_ROOT_KEY); // by default served by the asset canister
37
+ * console.log(env['PUBLIC_CANISTER_ID:backend']); // ✅ from generic parameter, TS passes
38
+ * console.log(env['PUBLIC_CANISTER_ID:frontend']); // ❌ TS will show an error
39
+ * ```
40
+ */
41
+ export interface CanisterEnv {
42
+ /**
43
+ * The root key of the IC network where the asset canister is deployed.
44
+ * Served by default by the asset canister that hosts the frontend.
45
+ */
46
+ readonly IC_ROOT_KEY: Uint8Array;
47
+ }
48
+ /**
49
+ * Options for the {@link getCanisterEnv} function
50
+ * @experimental
51
+ */
52
+ export type GetCanisterEnvOptions = {
53
+ /**
54
+ * The name of the cookie to get the environment variables from.
55
+ * @default 'ic_env'
56
+ */
57
+ cookieName?: string;
58
+ };
59
+ /**
60
+ * Get the environment variables served by the asset canister via the cookie.
61
+ *
62
+ * The returned object always includes `IC_ROOT_KEY` property.
63
+ * You can extend the global `CanisterEnv` interface to add your own environment variables
64
+ * and have strong typing for them.
65
+ *
66
+ * In Node.js environment (or any other environment where `globalThis.document` is not available), this function will throw an error.
67
+ * Use {@link safeGetCanisterEnv} if you need a function that returns `undefined` instead of throwing errors.
68
+ * @param options The options for loading the canister environment variables
69
+ * @returns The environment variables for the asset canister, always including `IC_ROOT_KEY`
70
+ * @throws {TypeError} When `globalThis.document` is not available
71
+ * @throws {InputError} When the cookie is not found
72
+ * @throws {InputError} When the `IC_ROOT_KEY` is missing or has an invalid length
73
+ * @see The {@link https://js.icp.build/core/latest/canister-environment/ | Canister Environment Guide} for more details on how to use the canister environment in a frontend application
74
+ * @experimental
75
+ * @example
76
+ * ```ts
77
+ * type MyCanisterEnv = {
78
+ * readonly ['PUBLIC_CANISTER_ID:backend']: string;
79
+ * };
80
+ *
81
+ * const env = getCanisterEnv<MyCanisterEnv>();
82
+ *
83
+ * console.log(env.IC_ROOT_KEY); // always available (Uint8Array)
84
+ * console.log(env['PUBLIC_CANISTER_ID:backend']); // ✅ from generic parameter, TS passes
85
+ * console.log(env['PUBLIC_CANISTER_ID:frontend']); // ❌ TS will show an error
86
+ * ```
87
+ * Have a look at {@link CanisterEnv} for more details on how to extend the interface
88
+ */
89
+ export declare function getCanisterEnv<T = Record<string, never>>(options?: GetCanisterEnvOptions): CanisterEnv & T;
90
+ /**
91
+ * Safe version of {@link getCanisterEnv} that returns `undefined` instead of throwing errors.
92
+ * @param options The options for loading the asset canister environment variables
93
+ * @returns The environment variables for the asset canister, or `undefined` if any error occurs
94
+ * @see The {@link https://js.icp.build/core/latest/canister-environment/ | Canister Environment Guide} for more details on how to use the canister environment in a frontend application
95
+ * @experimental
96
+ * @example
97
+ * ```ts
98
+ * // in a browser environment with valid cookie
99
+ * const env = safeGetCanisterEnv();
100
+ * console.log(env); // { IC_ROOT_KEY: Uint8Array, ... }
101
+ *
102
+ * // in a Node.js environment
103
+ * const env = safeGetCanisterEnv();
104
+ * console.log(env); // undefined
105
+ *
106
+ * // in a browser without the environment cookie
107
+ * const env = safeGetCanisterEnv();
108
+ * console.log(env); // undefined
109
+ * ```
110
+ */
111
+ export declare function safeGetCanisterEnv<T = Record<string, never>>(options?: GetCanisterEnvOptions): (CanisterEnv & T) | undefined;
2
112
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/agent/canister-env/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/agent/canister-env/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqBH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,UAAU,CAAC;CAClC;AAED;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EACtD,OAAO,GAAE,qBAA0B,GAClC,WAAW,GAAG,CAAC,CAoBjB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC1D,OAAO,GAAE,qBAA0B,GAClC,CAAC,WAAW,GAAG,CAAC,CAAC,GAAG,SAAS,CAM/B"}
@@ -1,2 +1,112 @@
1
- export * from '@dfinity/agent/canister-env';
1
+ /**
2
+ * @experimental
3
+ * @see https://js.icp.build/core/latest/canister-environment
4
+ * @module libs/agent/canister-env/api
5
+ */
6
+ import { hexToBytes } from '@noble/hashes/utils';
7
+ import { InputError, InvalidRootKeyErrorCode, EmptyCookieErrorCode, MissingRootKeyErrorCode, MissingCookieErrorCode, } from "../errors.js";
8
+ const IC_ENV_COOKIE_NAME = 'ic_env';
9
+ const ENV_VAR_SEPARATOR = '&';
10
+ const ENV_VAR_ASSIGNMENT_SYMBOL = '=';
11
+ const IC_ROOT_KEY_VALUE_NAME = 'ic_root_key';
12
+ const IC_ROOT_KEY_ENV_NAME = 'IC_ROOT_KEY'; // the value must be the same as the `CanisterEnv.IC_ROOT_KEY` property name
13
+ const IC_ROOT_KEY_BYTES_LENGTH = 133;
14
+ /**
15
+ * Get the environment variables served by the asset canister via the cookie.
16
+ *
17
+ * The returned object always includes `IC_ROOT_KEY` property.
18
+ * You can extend the global `CanisterEnv` interface to add your own environment variables
19
+ * and have strong typing for them.
20
+ *
21
+ * In Node.js environment (or any other environment where `globalThis.document` is not available), this function will throw an error.
22
+ * Use {@link safeGetCanisterEnv} if you need a function that returns `undefined` instead of throwing errors.
23
+ * @param options The options for loading the canister environment variables
24
+ * @returns The environment variables for the asset canister, always including `IC_ROOT_KEY`
25
+ * @throws {TypeError} When `globalThis.document` is not available
26
+ * @throws {InputError} When the cookie is not found
27
+ * @throws {InputError} When the `IC_ROOT_KEY` is missing or has an invalid length
28
+ * @see The {@link https://js.icp.build/core/latest/canister-environment/ | Canister Environment Guide} for more details on how to use the canister environment in a frontend application
29
+ * @experimental
30
+ * @example
31
+ * ```ts
32
+ * type MyCanisterEnv = {
33
+ * readonly ['PUBLIC_CANISTER_ID:backend']: string;
34
+ * };
35
+ *
36
+ * const env = getCanisterEnv<MyCanisterEnv>();
37
+ *
38
+ * console.log(env.IC_ROOT_KEY); // always available (Uint8Array)
39
+ * console.log(env['PUBLIC_CANISTER_ID:backend']); // ✅ from generic parameter, TS passes
40
+ * console.log(env['PUBLIC_CANISTER_ID:frontend']); // ❌ TS will show an error
41
+ * ```
42
+ * Have a look at {@link CanisterEnv} for more details on how to extend the interface
43
+ */
44
+ export function getCanisterEnv(options = {}) {
45
+ const { cookieName = IC_ENV_COOKIE_NAME } = options;
46
+ const cookie = getCookie(cookieName);
47
+ if (!cookie) {
48
+ throw InputError.fromCode(new MissingCookieErrorCode(cookieName));
49
+ }
50
+ const cookieValue = cookie.split('=')[1].trim();
51
+ if (!cookieValue) {
52
+ throw InputError.fromCode(new EmptyCookieErrorCode(cookieName));
53
+ }
54
+ const decodedCookieValue = decodeURIComponent(cookieValue);
55
+ const envVars = parseEnvVars(decodedCookieValue);
56
+ if (!envVars.IC_ROOT_KEY) {
57
+ throw InputError.fromCode(new MissingRootKeyErrorCode());
58
+ }
59
+ return envVars;
60
+ }
61
+ /**
62
+ * Safe version of {@link getCanisterEnv} that returns `undefined` instead of throwing errors.
63
+ * @param options The options for loading the asset canister environment variables
64
+ * @returns The environment variables for the asset canister, or `undefined` if any error occurs
65
+ * @see The {@link https://js.icp.build/core/latest/canister-environment/ | Canister Environment Guide} for more details on how to use the canister environment in a frontend application
66
+ * @experimental
67
+ * @example
68
+ * ```ts
69
+ * // in a browser environment with valid cookie
70
+ * const env = safeGetCanisterEnv();
71
+ * console.log(env); // { IC_ROOT_KEY: Uint8Array, ... }
72
+ *
73
+ * // in a Node.js environment
74
+ * const env = safeGetCanisterEnv();
75
+ * console.log(env); // undefined
76
+ *
77
+ * // in a browser without the environment cookie
78
+ * const env = safeGetCanisterEnv();
79
+ * console.log(env); // undefined
80
+ * ```
81
+ */
82
+ export function safeGetCanisterEnv(options = {}) {
83
+ try {
84
+ return getCanisterEnv(options);
85
+ }
86
+ catch {
87
+ return undefined;
88
+ }
89
+ }
90
+ function getCookie(cookieName) {
91
+ return globalThis.document.cookie
92
+ .split(';')
93
+ .find(cookie => cookie.trim().startsWith(`${cookieName}=`));
94
+ }
95
+ function parseEnvVars(decoded) {
96
+ const entries = decoded.split(ENV_VAR_SEPARATOR).map(v => {
97
+ // we only want to split at the first occurrence of the assignment symbol
98
+ const symbolIndex = v.indexOf(ENV_VAR_ASSIGNMENT_SYMBOL);
99
+ const key = v.slice(0, symbolIndex);
100
+ const value = v.substring(symbolIndex + 1);
101
+ if (key === IC_ROOT_KEY_VALUE_NAME) {
102
+ const rootKey = hexToBytes(value);
103
+ if (rootKey.length !== IC_ROOT_KEY_BYTES_LENGTH) {
104
+ throw InputError.fromCode(new InvalidRootKeyErrorCode(rootKey, IC_ROOT_KEY_BYTES_LENGTH));
105
+ }
106
+ return [IC_ROOT_KEY_ENV_NAME, rootKey];
107
+ }
108
+ return [key, value];
109
+ });
110
+ return Object.fromEntries(entries);
111
+ }
2
112
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/agent/canister-env/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/agent/canister-env/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EACL,UAAU,EACV,uBAAuB,EACvB,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAEtB,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAEpC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAEtC,MAAM,sBAAsB,GAAG,aAAa,CAAC;AAC7C,MAAM,oBAAoB,GAAG,aAAa,CAAC,CAAC,4EAA4E;AAExH,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAyDrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,cAAc,CAC5B,UAAiC,EAAE;IAEnC,MAAM,EAAE,UAAU,GAAG,kBAAkB,EAAE,GAAG,OAAO,CAAC;IAEpD,MAAM,MAAM,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;IACrC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,UAAU,CAAC,QAAQ,CAAC,IAAI,sBAAsB,CAAC,UAAU,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChD,IAAI,C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,GAAG,KAAK,sBAAsB,EAAE,CAAC;YACnC,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;YAClC,IAAI,OAAO,CAAC,MAAM,KAAK,wBAAwB,EAAE,CAAC;gBAChD,MAAM,UAAU,CAAC,QAAQ,CAAC,IAAI,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAC;YAC5F,CAAC;YACD,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;QACzC,CAAC;QAED,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { Principal } from '../../principal/index.js';
2
+ import { HttpAgent } from '../agent/http/index.ts';
3
+ import { type BaseSubnetStatus, type BaseStatus, CustomPath } from '../utils/readState.ts';
4
+ export { type DecodeStrategy, CustomPath } from '../utils/readState.ts';
5
+ export type SubnetStatus = BaseSubnetStatus;
6
+ export type Status = BaseStatus | SubnetStatus;
7
+ /**
8
+ * Pre-configured fields for canister status paths
9
+ */
10
+ export type Path = 'time' | 'controllers' | 'subnet' | 'module_hash' | 'candid' | CustomPath;
11
+ export type StatusMap = Map<Path | string, Status>;
12
+ export type CanisterStatusOptions = {
13
+ /**
14
+ * The effective canister ID to use in the underlying {@link HttpAgent.readState} call.
15
+ */
16
+ canisterId: Principal;
17
+ /**
18
+ * The agent to use to make the canister request. Must be authenticated.
19
+ */
20
+ agent: HttpAgent;
21
+ /**
22
+ * The paths to request.
23
+ * @default []
24
+ */
25
+ paths?: Path[] | Set<Path>;
26
+ /**
27
+ * Whether to disable the certificate freshness checks.
28
+ * @default false
29
+ */
30
+ disableCertificateTimeVerification?: boolean;
31
+ };
32
+ /**
33
+ * Requests information from a canister's `read_state` endpoint.
34
+ * Can be used to request information about the canister's controllers, time, module hash, candid interface, and more.
35
+ *
36
+ * > [!WARNING]
37
+ * > Requesting the `subnet` path from the canister status might be deprecated in the future.
38
+ * > Use {@link https://js.icp.build/core/latest/libs/agent/api/namespaces/subnetstatus/functions/request | SubnetStatus.request} to fetch subnet information instead.
39
+ * @param {CanisterStatusOptions} options The configuration for the canister status request.
40
+ * @see {@link CanisterStatusOptions} for detailed options.
41
+ * @returns {Promise<StatusMap>} A map populated with data from the requested paths. Each path is a key in the map, and the value is the data obtained from the certificate for that path.
42
+ * @example
43
+ * const status = await canisterStatus({
44
+ * paths: ['controllers', 'candid'],
45
+ * ...options
46
+ * });
47
+ *
48
+ * const controllers = status.get('controllers');
49
+ */
50
+ export declare const request: (options: CanisterStatusOptions) => Promise<StatusMap>;
51
+ /**
52
+ * Lookup node keys from a certificate for a given canister.
53
+ * The certificate is assumed to be already verified, including whether the canister is in range of the subnet.
54
+ * @param certificate the certificate to lookup node keys from
55
+ * @param canisterId the canister ID to lookup node keys for
56
+ * @param root_key the root key to use to lookup node keys
57
+ * @returns a map of node IDs to public keys
58
+ */
59
+ export declare const fetchNodeKeys: (certificate: Uint8Array, canisterId: Principal, root_key?: Uint8Array) => BaseSubnetStatus;
60
+ export declare const encodePath: (path: Path, canisterId: Principal) => Uint8Array[];
61
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/agent/canisterStatus/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAWvC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAKnD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,UAAU,EAOX,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,KAAK,cAAc,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExE,MAAM,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAC5C,MAAM,MAAM,MAAM,GAAG,UAAU,GAAG,YAAY,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,aAAa,GAAG,QAAQ,GAAG,aAAa,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE7F,MAAM,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,GAAG,MAAM,EAAE,MAAM,CAAC,CAAC;AAEnD,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,UAAU,EAAE,SAAS,CAAC;IACtB;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3B;;;OAGG;IACH,kCAAkC,CAAC,EAAE,OAAO,CAAC;CAC9C,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,OAAO,GAAU,SAAS,qBAAqB,KAAG,OAAO,CAAC,SAAS,CA+G/E,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GACxB,aAAa,UAAU,EACvB,YAAY,SAAS,EACrB,WAAW,UAAU,KACpB,gBAuBF,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,EAAE,YAAY,SAAS,KAAG,UAAU,EAoCxE,CAAC"}
@@ -0,0 +1,199 @@
1
+ import { Principal } from '../../principal/index.js';
2
+ import { CertificateVerificationErrorCode, MissingRootKeyErrorCode, ExternalError, AgentError, UnknownError, UnexpectedErrorCode, InputError, CertificateTimeErrorCode, } from "../errors.js";
3
+ import { Certificate, lookupResultToBuffer } from "../certificate.js";
4
+ import * as cbor from "../cbor.js";
5
+ import { decodeTime } from "../utils/leb.js";
6
+ import { utf8ToBytes, bytesToHex } from '@noble/hashes/utils';
7
+ import { decodeValue, decodeControllers, encodeMetadataPath, isCustomPath, lookupNodeKeysFromCertificate, IC_ROOT_SUBNET_ID, } from "../utils/readState.js";
8
+ // Re-export shared types for backwards compatibility
9
+ export { CustomPath } from "../utils/readState.js";
10
+ /**
11
+ * Requests information from a canister's `read_state` endpoint.
12
+ * Can be used to request information about the canister's controllers, time, module hash, candid interface, and more.
13
+ *
14
+ * > [!WARNING]
15
+ * > Requesting the `subnet` path from the canister status might be deprecated in the future.
16
+ * > Use {@link https://js.icp.build/core/latest/libs/agent/api/namespaces/subnetstatus/functions/request | SubnetStatus.request} to fetch subnet information instead.
17
+ * @param {CanisterStatusOptions} options The configuration for the canister status request.
18
+ * @see {@link CanisterStatusOptions} for detailed options.
19
+ * @returns {Promise<StatusMap>} A map populated with data from the requested paths. Each path is a key in the map, and the value is the data obtained from the certificate for that path.
20
+ * @example
21
+ * const status = await canisterStatus({
22
+ * paths: ['controllers', 'candid'],
23
+ * ...options
24
+ * });
25
+ *
26
+ * const controllers = status.get('controllers');
27
+ */
28
+ export const request = async (options) => {
29
+ const { agent, paths, disableCertificateTimeVerification = false } = options;
30
+ const canisterId = Principal.from(options.canisterId);
31
+ const uniquePaths = [...new Set(paths)];
32
+ const status = new Map();
33
+ const promises = uniquePaths.map((path, index) => {
34
+ const encodedPath = encodePath(path, canisterId);
35
+ return (async () => {
36
+ try {
37
+ if (agent.rootKey === null) {
38
+ throw ExternalError.fromCode(new MissingRootKeyErrorCode());
39
+ }
40
+ const rootKey = agent.rootKey;
41
+ const response = await agent.readState(canisterId, {
42
+ paths: [encodedPath],
43
+ });
44
+ const certificate = await Certificate.create({
45
+ certificate: response.certificate,
46
+ rootKey,
47
+ principal: { canisterId },
48
+ disableTimeVerification: disableCertificateTimeVerification,
49
+ agent,
50
+ });
51
+ const lookup = (cert, path) => {
52
+ if (path === 'subnet') {
53
+ const data = fetchNodeKeys(response.certificate, canisterId, rootKey);
54
+ return {
55
+ path,
56
+ data,
57
+ };
58
+ }
59
+ else {
60
+ return {
61
+ path,
62
+ data: lookupResultToBuffer(cert.lookup_path(encodedPath)),
63
+ };
64
+ }
65
+ };
66
+ // must pass in the rootKey if we have no delegation
67
+ const { path, data } = lookup(certificate, uniquePaths[index]);
68
+ if (!data) {
69
+ // Typically, the cert lookup will throw
70
+ console.warn(`Expected to find result for path ${path}, but instead found nothing.`);
71
+ if (typeof path === 'string') {
72
+ status.set(path, null);
73
+ }
74
+ else {
75
+ status.set(path.key, null);
76
+ }
77
+ }
78
+ else {
79
+ switch (path) {
80
+ case 'time': {
81
+ status.set(path, decodeTime(data));
82
+ break;
83
+ }
84
+ case 'controllers': {
85
+ status.set(path, decodeControllers(data));
86
+ break;
87
+ }
88
+ case 'module_hash': {
89
+ status.set(path, bytesToHex(data));
90
+ break;
91
+ }
92
+ case 'subnet': {
93
+ status.set(path, data);
94
+ break;
95
+ }
96
+ case 'candid': {
97
+ status.set(path, new TextDecoder().decode(data));
98
+ break;
99
+ }
100
+ default: {
101
+ // Check for CustomPath signature
102
+ if (isCustomPath(path)) {
103
+ status.set(path.key, decodeValue(data, path.decodeStrategy));
104
+ }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ catch (error) {
110
+ // Throw on certificate errors
111
+ if (error instanceof AgentError &&
112
+ (error.hasCode(CertificateVerificationErrorCode) ||
113
+ error.hasCode(CertificateTimeErrorCode))) {
114
+ throw error;
115
+ }
116
+ if (isCustomPath(path)) {
117
+ status.set(path.key, null);
118
+ }
119
+ else {
120
+ status.set(path, null);
121
+ }
122
+ console.group();
123
+ console.warn(`Expected to find result for path ${path}, but instead found nothing.`);
124
+ console.warn(error);
125
+ console.groupEnd();
126
+ }
127
+ })();
128
+ });
129
+ // Fetch all values separately, as each option can fail
130
+ await Promise.all(promises);
131
+ return status;
132
+ };
133
+ /**
134
+ * Lookup node keys from a certificate for a given canister.
135
+ * The certificate is assumed to be already verified, including whether the canister is in range of the subnet.
136
+ * @param certificate the certificate to lookup node keys from
137
+ * @param canisterId the canister ID to lookup node keys for
138
+ * @param root_key the root key to use to lookup node keys
139
+ * @returns a map of node IDs to public keys
140
+ */
141
+ export const fetchNodeKeys = (certificate, canisterId, root_key) => {
142
+ if (!canisterId._isPrincipal) {
143
+ throw InputError.fromCode(new UnexpectedErrorCode('Invalid canisterId'));
144
+ }
145
+ const cert = cbor.decode(certificate);
146
+ const { delegation } = cert;
147
+ let subnetId;
148
+ if (delegation && delegation.subnet_id) {
149
+ subnetId = Principal.fromUint8Array(new Uint8Array(delegation.subnet_id));
150
+ }
151
+ else if (!delegation && typeof root_key !== 'undefined') {
152
+ // On local replica, with System type subnet, there is no delegation
153
+ subnetId = Principal.selfAuthenticating(new Uint8Array(root_key));
154
+ }
155
+ else {
156
+ // otherwise use default NNS subnet id
157
+ subnetId = IC_ROOT_SUBNET_ID;
158
+ }
159
+ const nodeKeys = lookupNodeKeysFromCertificate(cert, subnetId);
160
+ return {
161
+ subnetId: subnetId.toText(),
162
+ nodeKeys,
163
+ };
164
+ };
165
+ export const encodePath = (path, canisterId) => {
166
+ const canisterUint8Array = canisterId.toUint8Array();
167
+ switch (path) {
168
+ case 'time':
169
+ return [utf8ToBytes('time')];
170
+ case 'controllers':
171
+ return [utf8ToBytes('canister'), canisterUint8Array, utf8ToBytes('controllers')];
172
+ case 'module_hash':
173
+ return [utf8ToBytes('canister'), canisterUint8Array, utf8ToBytes('module_hash')];
174
+ case 'subnet':
175
+ return [utf8ToBytes('subnet')];
176
+ case 'candid':
177
+ return [
178
+ utf8ToBytes('canister'),
179
+ canisterUint8Array,
180
+ utf8ToBytes('metadata'),
181
+ utf8ToBytes('candid:service'),
182
+ ];
183
+ default: {
184
+ // Check for CustomPath signature
185
+ if (isCustomPath(path)) {
186
+ // For simplified metadata queries
187
+ if (typeof path['path'] === 'string' || path['path'] instanceof Uint8Array) {
188
+ return encodeMetadataPath(path.path, canisterUint8Array);
189
+ }
190
+ else {
191
+ // For non-metadata, return the provided custom path
192
+ return path['path'];
193
+ }
194
+ }
195
+ }
196
+ }
197
+ throw UnknownError.fromCode(new UnexpectedErrorCode(`Error while encoding your path for canister status. Please ensure that your path ${path} was formatted correctly.`));
198
+ };
199
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@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gBAClB,WAAW,CAAC,UAAU,CAAC;gBACvB,WAAW,CAAC,gBAAgB,CAAC;aAC9B,CAAC;QACJ,OAAO,CAAC,CAAC,CAAC;YACR,iCAAiC;YACjC,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvB,kCAAkC;gBAClC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,UAAU,EAAE,CAAC;oBAC3E,OAAO,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;gBAC3D,CAAC;qBAAM,CAAC;oBACN,oDAAoD;oBACpD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;gBACtB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,MAAM,YAAY,CAAC,QAAQ,CACzB,IAAI,mBAAmB,CACrB,oFAAoF,IAAI,2BAA2B,CACpH,CACF,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import * as cbor from '@dfinity/cbor';
2
+ /**
3
+ * Used to extend classes that need to provide a custom value for the CBOR encoding process.
4
+ */
5
+ export declare abstract class ToCborValue {
6
+ /**
7
+ * Returns a value that can be encoded with CBOR. Typically called in the replacer function of the {@link encode} function.
8
+ */
9
+ abstract toCborValue(): cbor.CborValue;
10
+ }
11
+ /**
12
+ * Encode a JavaScript value into CBOR. If the value is an instance of {@link ToCborValue},
13
+ * the {@link ToCborValue.toCborValue} method will be called to get the value to encode.
14
+ * @param value The value to encode
15
+ */
16
+ export declare function encode(value: unknown): Uint8Array;
17
+ /**
18
+ * Decode a CBOR encoded value into a JavaScript value.
19
+ * @param input The CBOR encoded value
20
+ */
21
+ export declare function decode<T>(input: Uint8Array): T;
22
+ export declare const Cbor: {
23
+ encode: typeof encode;
24
+ decode: typeof decode;
25
+ };
26
+ //# sourceMappingURL=cbor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cbor.d.ts","sourceRoot":"","sources":["../../../src/agent/cbor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAItC;;GAEG;AACH,8BAAsB,WAAW;IAC/B;;OAEG;aACa,WAAW,IAAI,IAAI,CAAC,SAAS;CAC9C;AAMD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAoBjD;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,GAAG,CAAC,CAM9C;AAGD,eAAO,MAAM,IAAI;;;CAGhB,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { Principal } from '../principal/index.js';
2
+ import * as cbor from '@dfinity/cbor';
3
+ import { CborDecodeErrorCode, CborEncodeErrorCode, InputError } from "./errors.js";
4
+ import { Expiry } from "./agent/index.js";
5
+ /**
6
+ * Used to extend classes that need to provide a custom value for the CBOR encoding process.
7
+ */
8
+ export class ToCborValue {
9
+ }
10
+ function hasCborValueMethod(value) {
11
+ return typeof value === 'object' && value !== null && 'toCborValue' in value;
12
+ }
13
+ /**
14
+ * Encode a JavaScript value into CBOR. If the value is an instance of {@link ToCborValue},
15
+ * the {@link ToCborValue.toCborValue} method will be called to get the value to encode.
16
+ * @param value The value to encode
17
+ */
18
+ export function encode(value) {
19
+ try {
20
+ return cbor.encodeWithSelfDescribedTag(value, value => {
21
+ if (Principal.isPrincipal(value)) {
22
+ return value.toUint8Array();
23
+ }
24
+ if (Expiry.isExpiry(value)) {
25
+ return value.toBigInt();
26
+ }
27
+ if (hasCborValueMethod(value)) {
28
+ return value.toCborValue();
29
+ }
30
+ return value;
31
+ });
32
+ }
33
+ catch (error) {
34
+ throw InputError.fromCode(new CborEncodeErrorCode(error, value));
35
+ }
36
+ }
37
+ /**
38
+ * Decode a CBOR encoded value into a JavaScript value.
39
+ * @param input The CBOR encoded value
40
+ */
41
+ export function decode(input) {
42
+ try {
43
+ return cbor.decode(input);
44
+ }
45
+ catch (error) {
46
+ throw InputError.fromCode(new CborDecodeErrorCode(error, input));
47
+ }
48
+ }
49
+ // Not strictly necessary, we're just keeping it for backwards compatibility.
50
+ export const Cbor = {
51
+ encode,
52
+ decode,
53
+ };
54
+ //# sourceMappingURL=cbor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cbor.js","sourceRoot":"","sources":["../../../src/agent/cbor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C;;GAEG;AACH,MAAM,OAAgB,WAAW;CAKhC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,aAAa,IAAI,KAAK,CAAC;AAC/E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,0BAA0B,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE;YACpD,IAAI,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjC,OAAO,KAAK,CAAC,YAAY,EAAE,CAAC;YAC9B,CAAC;YAED,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;YAC1B,CAAC;YAED,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC9B,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC;YAC7B,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf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