@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
@@ -0,0 +1,144 @@
1
+ import { Principal } from '#principal';
2
+ import { RequestStatusResponseStatus } from '../agent/index.ts';
3
+ import { type PollStrategy } from './index.ts';
4
+ import { type RequestId } from '../request_id.ts';
5
+ import { ProtocolError, TimeoutWaitingForResponseErrorCode } from '../errors.ts';
6
+
7
+ export type Predicate<T> = (
8
+ canisterId: Principal,
9
+ requestId: RequestId,
10
+ status: RequestStatusResponseStatus,
11
+ ) => Promise<T>;
12
+
13
+ const FIVE_MINUTES_IN_MSEC = 5 * 60 * 1000;
14
+
15
+ /**
16
+ * A best practices polling strategy: wait 2 seconds before the first poll, then 1 second
17
+ * with an exponential backoff factor of 1.2. Timeout after 5 minutes.
18
+ *
19
+ * Note that calling this function will create the strategy chain described above and already start the 5 minutes timeout.
20
+ * You should only call this function when you want to start the polling, and not before, to avoid exhausting the 5 minutes timeout in advance.
21
+ */
22
+ export function defaultStrategy(): PollStrategy {
23
+ return chain(conditionalDelay(once(), 1000), backoff(1000, 1.2), timeout(FIVE_MINUTES_IN_MSEC));
24
+ }
25
+
26
+ /**
27
+ * Predicate that returns true once.
28
+ */
29
+ export function once(): Predicate<boolean> {
30
+ let first = true;
31
+ return async () => {
32
+ if (first) {
33
+ first = false;
34
+ return true;
35
+ }
36
+ return false;
37
+ };
38
+ }
39
+
40
+ /**
41
+ * Delay the polling once.
42
+ * @param condition A predicate that indicates when to delay.
43
+ * @param timeInMsec The amount of time to delay.
44
+ */
45
+ export function conditionalDelay(condition: Predicate<boolean>, timeInMsec: number): PollStrategy {
46
+ return async (
47
+ canisterId: Principal,
48
+ requestId: RequestId,
49
+ status: RequestStatusResponseStatus,
50
+ ) => {
51
+ if (await condition(canisterId, requestId, status)) {
52
+ return new Promise(resolve => setTimeout(resolve, timeInMsec));
53
+ }
54
+ };
55
+ }
56
+
57
+ /**
58
+ * Error out after a maximum number of polling has been done.
59
+ * @param count The maximum attempts to poll.
60
+ */
61
+ export function maxAttempts(count: number): PollStrategy {
62
+ let attempts = count;
63
+ return async (
64
+ _canisterId: Principal,
65
+ requestId: RequestId,
66
+ status: RequestStatusResponseStatus,
67
+ ) => {
68
+ if (--attempts <= 0) {
69
+ throw ProtocolError.fromCode(
70
+ new TimeoutWaitingForResponseErrorCode(
71
+ `Failed to retrieve a reply for request after ${count} attempts`,
72
+ requestId,
73
+ status,
74
+ ),
75
+ );
76
+ }
77
+ };
78
+ }
79
+
80
+ /**
81
+ * Throttle polling.
82
+ * @param throttleInMsec Amount in millisecond to wait between each polling.
83
+ */
84
+ export function throttle(throttleInMsec: number): PollStrategy {
85
+ return () => new Promise(resolve => setTimeout(resolve, throttleInMsec));
86
+ }
87
+
88
+ /**
89
+ * Reject a call after a certain amount of time.
90
+ * @param timeInMsec Time in milliseconds before the polling should be rejected.
91
+ */
92
+ export function timeout(timeInMsec: number): PollStrategy {
93
+ const end = Date.now() + timeInMsec;
94
+ return async (
95
+ _canisterId: Principal,
96
+ requestId: RequestId,
97
+ status: RequestStatusResponseStatus,
98
+ ) => {
99
+ if (Date.now() > end) {
100
+ throw ProtocolError.fromCode(
101
+ new TimeoutWaitingForResponseErrorCode(
102
+ `Request timed out after ${timeInMsec} msec`,
103
+ requestId,
104
+ status,
105
+ ),
106
+ );
107
+ }
108
+ };
109
+ }
110
+
111
+ /**
112
+ * A strategy that throttle, but using an exponential backoff strategy.
113
+ * @param startingThrottleInMsec The throttle in milliseconds to start with.
114
+ * @param backoffFactor The factor to multiple the throttle time between every poll. For
115
+ * example if using 2, the throttle will double between every run.
116
+ */
117
+ export function backoff(startingThrottleInMsec: number, backoffFactor: number): PollStrategy {
118
+ let currentThrottling = startingThrottleInMsec;
119
+
120
+ return () =>
121
+ new Promise(resolve =>
122
+ setTimeout(() => {
123
+ currentThrottling *= backoffFactor;
124
+ resolve();
125
+ }, currentThrottling),
126
+ );
127
+ }
128
+
129
+ /**
130
+ * Chain multiple polling strategy. This _chains_ the strategies, so if you pass in,
131
+ * say, two throttling strategy of 1 second, it will result in a throttle of 2 seconds.
132
+ * @param strategies A strategy list to chain.
133
+ */
134
+ export function chain(...strategies: PollStrategy[]): PollStrategy {
135
+ return async (
136
+ canisterId: Principal,
137
+ requestId: RequestId,
138
+ status: RequestStatusResponseStatus,
139
+ ) => {
140
+ for (const a of strategies) {
141
+ await a(canisterId, requestId, status);
142
+ }
143
+ };
144
+ }
@@ -0,0 +1,65 @@
1
+ import { type DerEncodedPublicKey, type PublicKey } from './auth.ts';
2
+ import { ED25519_OID, unwrapDER, wrapDER } from './der.ts';
3
+ import { DerDecodeErrorCode, InputError } from './errors.ts';
4
+
5
+ export class Ed25519PublicKey implements PublicKey {
6
+ public static from(key: PublicKey): Ed25519PublicKey {
7
+ return this.fromDer(key.toDer());
8
+ }
9
+
10
+ public static fromRaw(rawKey: Uint8Array): Ed25519PublicKey {
11
+ return new Ed25519PublicKey(rawKey);
12
+ }
13
+
14
+ public static fromDer(derKey: DerEncodedPublicKey): Ed25519PublicKey {
15
+ return new Ed25519PublicKey(this.derDecode(derKey));
16
+ }
17
+
18
+ // The length of Ed25519 public keys is always 32 bytes.
19
+ private static RAW_KEY_LENGTH = 32;
20
+
21
+ private static derEncode(publicKey: Uint8Array): DerEncodedPublicKey {
22
+ return wrapDER(publicKey, ED25519_OID) as DerEncodedPublicKey;
23
+ }
24
+
25
+ private static derDecode(key: DerEncodedPublicKey): Uint8Array {
26
+ const unwrapped = unwrapDER(key, ED25519_OID);
27
+ if (unwrapped.length !== this.RAW_KEY_LENGTH) {
28
+ throw InputError.fromCode(
29
+ new DerDecodeErrorCode('An Ed25519 public key must be exactly 32 bytes long'),
30
+ );
31
+ }
32
+ return unwrapped;
33
+ }
34
+
35
+ #rawKey: Uint8Array;
36
+
37
+ public get rawKey(): Uint8Array {
38
+ return this.#rawKey;
39
+ }
40
+
41
+ #derKey: DerEncodedPublicKey;
42
+
43
+ public get derKey(): DerEncodedPublicKey {
44
+ return this.#derKey;
45
+ }
46
+
47
+ // `fromRaw` and `fromDer` should be used for instantiation, not this constructor.
48
+ private constructor(key: Uint8Array) {
49
+ if (key.byteLength !== Ed25519PublicKey.RAW_KEY_LENGTH) {
50
+ throw InputError.fromCode(
51
+ new DerDecodeErrorCode('An Ed25519 public key must be exactly 32 bytes long'),
52
+ );
53
+ }
54
+ this.#rawKey = key;
55
+ this.#derKey = Ed25519PublicKey.derEncode(key);
56
+ }
57
+
58
+ public toDer(): DerEncodedPublicKey {
59
+ return this.derKey;
60
+ }
61
+
62
+ public toRaw(): Uint8Array {
63
+ return this.rawKey;
64
+ }
65
+ }
@@ -0,0 +1,92 @@
1
+ import { lebEncode, compare } from '#candid';
2
+ import { Principal } from '#principal';
3
+ import { HashValueErrorCode, InputError } from './errors.ts';
4
+ import { uint8FromBufLike } from './utils/buffer.ts';
5
+ import { concatBytes } from '@noble/hashes/utils';
6
+ import { sha256 } from '@noble/hashes/sha2';
7
+
8
+ export type RequestId = Uint8Array & { __requestId__: void };
9
+
10
+ interface ToHashable {
11
+ toHash(): unknown;
12
+ }
13
+
14
+ /**
15
+ *
16
+ * @param value unknown value
17
+ * @returns Uint8Array
18
+ */
19
+ export function hashValue(value: unknown): Uint8Array {
20
+ if (typeof value === 'string') {
21
+ return hashString(value);
22
+ } else if (typeof value === 'number') {
23
+ return sha256(lebEncode(value));
24
+ } else if (value instanceof Uint8Array || ArrayBuffer.isView(value)) {
25
+ return sha256(uint8FromBufLike(value));
26
+ } else if (Array.isArray(value)) {
27
+ const vals = value.map(hashValue);
28
+ return sha256(concatBytes(...vals));
29
+ } else if (value && typeof value === 'object' && (value as Principal)._isPrincipal) {
30
+ return sha256((value as Principal).toUint8Array());
31
+ } else if (
32
+ typeof value === 'object' &&
33
+ value !== null &&
34
+ typeof (value as ToHashable).toHash === 'function'
35
+ ) {
36
+ return hashValue((value as ToHashable).toHash());
37
+ // TODO This should be move to a specific async method as the webauthn flow required
38
+ // the flow to be synchronous to ensure Safari touch id works.
39
+ // } else if (value instanceof Promise) {
40
+ // return value.then(x => hashValue(x));
41
+ } else if (typeof value === 'object') {
42
+ return hashOfMap(value as Record<string, unknown>);
43
+ } else if (typeof value === 'bigint') {
44
+ // Do this check much later than the other bigint check because this one is much less
45
+ // type-safe.
46
+ // So we want to try all the high-assurance type guards before this 'probable' one.
47
+ return sha256(lebEncode(value));
48
+ }
49
+ throw InputError.fromCode(new HashValueErrorCode(value));
50
+ }
51
+
52
+ const hashString = (value: string): Uint8Array => {
53
+ const encoded = new TextEncoder().encode(value);
54
+ return sha256(encoded);
55
+ };
56
+
57
+ /**
58
+ * Get the RequestId of the provided ic-ref request.
59
+ * RequestId is the result of the representation-independent-hash function.
60
+ * https://sdk.dfinity.org/docs/interface-spec/index.html#hash-of-map
61
+ * @param request - ic-ref request to hash into RequestId
62
+ */
63
+ export function requestIdOf(request: Record<string, unknown>): RequestId {
64
+ return hashOfMap(request) as RequestId;
65
+ }
66
+
67
+ /**
68
+ * Hash a map into a Uint8Array using the representation-independent-hash function.
69
+ * https://sdk.dfinity.org/docs/interface-spec/index.html#hash-of-map
70
+ * @param map - Any non-nested object
71
+ * @returns Uint8Array
72
+ */
73
+ export function hashOfMap(map: Record<string, unknown>): Uint8Array {
74
+ const hashed: Array<[Uint8Array, Uint8Array]> = Object.entries(map)
75
+ .filter(([, value]) => value !== undefined)
76
+ .map(([key, value]: [string, unknown]) => {
77
+ const hashedKey = hashString(key);
78
+ const hashedValue = hashValue(value);
79
+
80
+ return [hashedKey, hashedValue] as [Uint8Array, Uint8Array];
81
+ });
82
+
83
+ const traversed: Array<[Uint8Array, Uint8Array]> = hashed;
84
+
85
+ const sorted: Array<[Uint8Array, Uint8Array]> = traversed.sort(([k1], [k2]) => {
86
+ return compare(k1, k2);
87
+ });
88
+
89
+ const concatenated = concatBytes(...sorted.map(x => concatBytes(...x)));
90
+ const result = sha256(concatenated);
91
+ return result;
92
+ }
@@ -0,0 +1,270 @@
1
+ import { Principal } from '#principal';
2
+ import {
3
+ CertificateVerificationErrorCode,
4
+ MissingRootKeyErrorCode,
5
+ ExternalError,
6
+ AgentError,
7
+ UnknownError,
8
+ UnexpectedErrorCode,
9
+ CertificateTimeErrorCode,
10
+ ProtocolError,
11
+ LookupErrorCode,
12
+ } from '../errors.ts';
13
+ import { HttpAgent } from '../agent/http/index.ts';
14
+ import {
15
+ type Cert,
16
+ type CanisterRanges,
17
+ Certificate,
18
+ lookupResultToBuffer,
19
+ decodeCanisterRanges,
20
+ lookup_path,
21
+ LookupPathStatus,
22
+ } from '../certificate.ts';
23
+ import * as cbor from '../cbor.ts';
24
+ import { decodeTime } from '../utils/leb.ts';
25
+ import { utf8ToBytes } from '@noble/hashes/utils';
26
+ import {
27
+ type BaseStatus,
28
+ type BaseSubnetStatus,
29
+ type SubnetNodeKeys,
30
+ CustomPath,
31
+ decodeValue,
32
+ isCustomPath,
33
+ lookupNodeKeysFromCertificate,
34
+ IC_ROOT_SUBNET_ID,
35
+ } from '../utils/readState.ts';
36
+
37
+ // Re-export shared types and functions
38
+ export { type DecodeStrategy, CustomPath, IC_ROOT_SUBNET_ID } from '../utils/readState.ts';
39
+
40
+ export type SubnetStatus = BaseSubnetStatus & {
41
+ /**
42
+ * The public key of the subnet
43
+ */
44
+ publicKey: Uint8Array;
45
+ };
46
+
47
+ export type Status = BaseStatus | SubnetNodeKeys | CanisterRanges;
48
+
49
+ /**
50
+ * Pre-configured fields for subnet status paths
51
+ */
52
+ export type Path = 'time' | 'canisterRanges' | 'publicKey' | 'nodeKeys' | CustomPath;
53
+
54
+ export type StatusMap = Map<Path | string, Status>;
55
+
56
+ export type SubnetStatusOptions = {
57
+ /**
58
+ * The subnet ID to query. Use {@link IC_ROOT_SUBNET_ID} for the IC mainnet root subnet.
59
+ * You can use {@link HttpAgent.getSubnetIdFromCanister} to get a subnet ID from a canister.
60
+ */
61
+ subnetId: Principal;
62
+ /**
63
+ * The agent to use to make the subnet request.
64
+ */
65
+ agent: HttpAgent;
66
+ /**
67
+ * The paths to request.
68
+ * @default []
69
+ */
70
+ paths?: Path[] | Set<Path>;
71
+ /**
72
+ * Whether to disable the certificate freshness checks.
73
+ * @default false
74
+ */
75
+ disableCertificateTimeVerification?: boolean;
76
+ };
77
+
78
+ /**
79
+ * Requests information from a subnet's `read_state` endpoint.
80
+ * Can be used to request information about the subnet's time, canister ranges, public key, node keys, and metrics.
81
+ * @param {SubnetStatusOptions} options The configuration for the subnet status request.
82
+ * @see {@link SubnetStatusOptions} for detailed options.
83
+ * @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.
84
+ * @example
85
+ * const status = await subnetStatus.request({
86
+ * subnetId: IC_ROOT_SUBNET_ID,
87
+ * paths: ['time', 'nodeKeys'],
88
+ * agent,
89
+ * });
90
+ *
91
+ * const time = status.get('time');
92
+ * const nodeKeys = status.get('nodeKeys');
93
+ */
94
+ export async function request(options: SubnetStatusOptions): Promise<StatusMap> {
95
+ const { agent, paths, disableCertificateTimeVerification = false } = options;
96
+ const subnetId = Principal.from(options.subnetId);
97
+
98
+ const uniquePaths = [...new Set(paths)];
99
+ const status = new Map<string | Path, Status>();
100
+
101
+ const promises = uniquePaths.map((path, index) => {
102
+ const encodedPath = encodePath(path, subnetId);
103
+
104
+ return (async () => {
105
+ try {
106
+ if (agent.rootKey === null) {
107
+ throw ExternalError.fromCode(new MissingRootKeyErrorCode());
108
+ }
109
+
110
+ const rootKey = agent.rootKey;
111
+
112
+ const response = await agent.readSubnetState(subnetId, {
113
+ paths: [encodedPath],
114
+ });
115
+
116
+ const certificate = await Certificate.create({
117
+ certificate: response.certificate,
118
+ rootKey,
119
+ principal: { subnetId },
120
+ disableTimeVerification: disableCertificateTimeVerification,
121
+ agent,
122
+ });
123
+
124
+ const lookup = (cert: Certificate, lookupPath: Path) => {
125
+ if (lookupPath === 'nodeKeys') {
126
+ // For node keys, we need to parse the certificate directly
127
+ const data = lookupNodeKeysFromCertificate(cert.cert, subnetId);
128
+ return {
129
+ path: lookupPath,
130
+ data,
131
+ };
132
+ } else {
133
+ return {
134
+ path: lookupPath,
135
+ data: lookupResultToBuffer(cert.lookup_path(encodedPath)),
136
+ };
137
+ }
138
+ };
139
+
140
+ const { path, data } = lookup(certificate, uniquePaths[index]);
141
+ if (!data) {
142
+ console.warn(`Expected to find result for path ${path}, but instead found nothing.`);
143
+ if (typeof path === 'string') {
144
+ status.set(path, null);
145
+ } else {
146
+ status.set(path.key, null);
147
+ }
148
+ } else {
149
+ switch (path) {
150
+ case 'time': {
151
+ status.set(path, decodeTime(data));
152
+ break;
153
+ }
154
+ case 'canisterRanges': {
155
+ status.set(path, decodeCanisterRanges(data));
156
+ break;
157
+ }
158
+ case 'publicKey': {
159
+ status.set(path, data);
160
+ break;
161
+ }
162
+ case 'nodeKeys': {
163
+ status.set(path, data);
164
+ break;
165
+ }
166
+ default: {
167
+ // Check for CustomPath signature
168
+ if (isCustomPath(path)) {
169
+ status.set(path.key, decodeValue(data, path.decodeStrategy));
170
+ }
171
+ }
172
+ }
173
+ }
174
+ } catch (error) {
175
+ // Throw on certificate errors
176
+ if (
177
+ error instanceof AgentError &&
178
+ (error.hasCode(CertificateVerificationErrorCode) ||
179
+ error.hasCode(CertificateTimeErrorCode))
180
+ ) {
181
+ throw error;
182
+ }
183
+ if (isCustomPath(path)) {
184
+ status.set(path.key, null);
185
+ } else {
186
+ status.set(path, null);
187
+ }
188
+ console.group();
189
+ console.warn(`Expected to find result for path ${path}, but instead found nothing.`);
190
+ console.warn(error);
191
+ console.groupEnd();
192
+ }
193
+ })();
194
+ });
195
+
196
+ // Fetch all values separately, as each option can fail
197
+ await Promise.all(promises);
198
+
199
+ return status;
200
+ }
201
+
202
+ /**
203
+ * Fetch subnet info including node keys from a certificate
204
+ * @param certificate the certificate bytes
205
+ * @param subnetId the subnet ID
206
+ * @returns SubnetStatus with subnet ID and node keys
207
+ */
208
+ export function lookupSubnetInfo(certificate: Uint8Array, subnetId: Principal): SubnetStatus {
209
+ const cert = cbor.decode<Cert>(certificate);
210
+ const nodeKeys = lookupNodeKeysFromCertificate(cert, subnetId);
211
+ const publicKey = lookupSubnetPublicKey(cert, subnetId);
212
+
213
+ return {
214
+ subnetId: subnetId.toText(),
215
+ nodeKeys,
216
+ publicKey,
217
+ };
218
+ }
219
+
220
+ function lookupSubnetPublicKey(certificate: Cert, subnetId: Principal): Uint8Array {
221
+ const subnetLookupResult = lookup_path(
222
+ ['subnet', subnetId.toUint8Array(), 'public_key'],
223
+ certificate.tree,
224
+ );
225
+ if (subnetLookupResult.status !== LookupPathStatus.Found) {
226
+ throw ProtocolError.fromCode(
227
+ new LookupErrorCode('Public key not found', subnetLookupResult.status),
228
+ );
229
+ }
230
+ return subnetLookupResult.value;
231
+ }
232
+
233
+ /**
234
+ * Encode a path for subnet state queries
235
+ * @param path the path to encode
236
+ * @param subnetId the subnet ID
237
+ * @returns the encoded path as an array of Uint8Arrays
238
+ */
239
+ export function encodePath(path: Path, subnetId: Principal): Uint8Array[] {
240
+ const subnetUint8Array = subnetId.toUint8Array();
241
+ switch (path) {
242
+ case 'time':
243
+ return [utf8ToBytes('time')];
244
+ case 'canisterRanges':
245
+ return [utf8ToBytes('canister_ranges'), subnetUint8Array];
246
+ case 'publicKey':
247
+ return [utf8ToBytes('subnet'), subnetUint8Array, utf8ToBytes('public_key')];
248
+ case 'nodeKeys':
249
+ return [utf8ToBytes('subnet'), subnetUint8Array, utf8ToBytes('node')];
250
+ default: {
251
+ // Check for CustomPath signature
252
+ if (isCustomPath(path)) {
253
+ if (typeof path['path'] === 'string' || path['path'] instanceof Uint8Array) {
254
+ // For string paths, treat as a subnet path segment
255
+ const encoded =
256
+ typeof path['path'] === 'string' ? utf8ToBytes(path['path']) : path['path'];
257
+ return [utf8ToBytes('subnet'), subnetUint8Array, encoded];
258
+ } else {
259
+ // For non-simple paths, return the provided custom path
260
+ return path['path'];
261
+ }
262
+ }
263
+ }
264
+ }
265
+ throw UnknownError.fromCode(
266
+ new UnexpectedErrorCode(
267
+ `Error while encoding your path for subnet status. Please ensure that your path ${path} was formatted correctly.`,
268
+ ),
269
+ );
270
+ }
@@ -0,0 +1,18 @@
1
+ import { bls12_381 } from '@noble/curves/bls12-381';
2
+ import { bytesToHex } from '@noble/hashes/utils';
3
+
4
+ export let verify: (pk: Uint8Array, sig: Uint8Array, msg: Uint8Array) => boolean;
5
+
6
+ /**
7
+ *
8
+ * @param pk primary key: Uint8Array
9
+ * @param sig signature: Uint8Array
10
+ * @param msg message: Uint8Array
11
+ * @returns boolean
12
+ */
13
+ export function blsVerify(pk: Uint8Array, sig: Uint8Array, msg: Uint8Array): boolean {
14
+ const primaryKey = typeof pk === 'string' ? pk : bytesToHex(pk);
15
+ const signature = typeof sig === 'string' ? sig : bytesToHex(sig);
16
+ const message = typeof msg === 'string' ? msg : bytesToHex(msg);
17
+ return bls12_381.verifyShortSignature(signature, message, primaryKey);
18
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Returns a true Uint8Array from an ArrayBufferLike object.
3
+ * @param bufLike a buffer-like object
4
+ * @returns Uint8Array
5
+ */
6
+ export function uint8FromBufLike(
7
+ bufLike:
8
+ | ArrayBuffer
9
+ | Uint8Array
10
+ | DataView
11
+ | ArrayBufferView
12
+ | ArrayBufferLike
13
+ | [number]
14
+ | number[]
15
+ | { buffer: ArrayBuffer },
16
+ ): Uint8Array {
17
+ if (!bufLike) {
18
+ throw new Error('Input cannot be null or undefined');
19
+ }
20
+
21
+ if (bufLike instanceof Uint8Array) {
22
+ return bufLike;
23
+ }
24
+ if (bufLike instanceof ArrayBuffer) {
25
+ return new Uint8Array(bufLike);
26
+ }
27
+ if (Array.isArray(bufLike)) {
28
+ return new Uint8Array(bufLike);
29
+ }
30
+ if ('buffer' in bufLike) {
31
+ return uint8FromBufLike(bufLike.buffer);
32
+ }
33
+ return new Uint8Array(bufLike);
34
+ }
35
+
36
+ /**
37
+ * Returns a true ArrayBuffer from a Uint8Array, as Uint8Array.buffer is unsafe.
38
+ * @param {Uint8Array} arr Uint8Array to convert
39
+ * @returns ArrayBuffer
40
+ */
41
+ export function uint8ToBuf(arr: Uint8Array): ArrayBuffer {
42
+ const buf = new ArrayBuffer(arr.byteLength);
43
+ const view = new Uint8Array(buf);
44
+ view.set(arr);
45
+ return buf;
46
+ }
47
+
48
+ /**
49
+ * Compares two Uint8Arrays for equality.
50
+ * @param a The first Uint8Array.
51
+ * @param b The second Uint8Array.
52
+ * @returns True if the Uint8Arrays are equal, false otherwise.
53
+ */
54
+ export function uint8Equals(a: Uint8Array, b: Uint8Array): boolean {
55
+ if (a.length !== b.length) return false;
56
+ for (let i = 0; i < a.length; i++) {
57
+ if (a[i] !== b[i]) return false;
58
+ }
59
+ return true;
60
+ }