@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,50 @@
1
+ // This file is translated to JavaScript from
2
+ // https://lxp32.github.io/docs/a-simple-example-crc32-calculation/
3
+ const lookUpTable = new Uint32Array([
4
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
5
+ 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
6
+ 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
7
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
8
+ 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
9
+ 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
10
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
11
+ 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
12
+ 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
13
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
14
+ 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
15
+ 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
16
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
17
+ 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
18
+ 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
19
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
20
+ 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
21
+ 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
22
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
23
+ 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
24
+ 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
25
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
26
+ 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
27
+ 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
28
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
29
+ 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
30
+ 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
31
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
32
+ 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
33
+ 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
34
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
35
+ 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
36
+ ]);
37
+ /**
38
+ * Calculate the CRC32 of a Uint8Array.
39
+ * @param buf The Uint8Array to calculate the CRC32 of.
40
+ */
41
+ export function getCrc32(buf) {
42
+ let crc = -1;
43
+ for (let i = 0; i < buf.length; i++) {
44
+ const byte = buf[i];
45
+ const t = (byte ^ crc) & 0xff;
46
+ crc = lookUpTable[t] ^ (crc >>> 8);
47
+ }
48
+ return (crc ^ -1) >>> 0;
49
+ }
50
+ //# sourceMappingURL=getCrc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCrc.js","sourceRoot":"","sources":["../../../../src/principal/utils/getCrc.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,mEAAmE;AACnE,MAAM,WAAW,GAAgB,IAAI,WAAW,CAAC;IAC/C,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;IAC9F,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU;CAC/F,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAe;IACtC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC;IAEb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACpB,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;QAC9B,GAAG,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icp-sdk/core",
3
- "version": "4.2.3",
3
+ "version": "5.0.0-beta.1",
4
4
  "author": "DFINITY Stiftung <sdk@dfinity.org>",
5
5
  "license": "Apache-2.0",
6
6
  "description": "JavaScript and TypeScript library to interact with the Internet Computer",
@@ -32,13 +32,6 @@
32
32
  "api",
33
33
  "sdk"
34
34
  ],
35
- "peerDependencies": {
36
- "@dfinity/agent": "3.4.3",
37
- "@dfinity/candid": "3.4.3",
38
- "@dfinity/identity": "3.4.3",
39
- "@dfinity/identity-secp256k1": "3.4.3",
40
- "@dfinity/principal": "3.4.3"
41
- },
42
35
  "types": "./lib/esm/index.d.ts",
43
36
  "exports": {
44
37
  ".": {
@@ -88,10 +81,23 @@
88
81
  "default": "./lib/esm/principal/index.js"
89
82
  }
90
83
  },
84
+ "dependencies": {
85
+ "@dfinity/cbor": "^0.2.2",
86
+ "@noble/curves": "^1.9.2",
87
+ "@noble/hashes": "^1.8.0",
88
+ "@scure/bip32": "^1.7.0",
89
+ "@scure/bip39": "^1.6.0",
90
+ "asn1js": "^3.0.5"
91
+ },
92
+ "devDependencies": {
93
+ "@peculiar/webcrypto": "^1.5.0",
94
+ "tsc-alias": "^1.8.16"
95
+ },
91
96
  "scripts": {
92
- "build": "tsc -b && tsc -p tsconfig.cjs.json && cp src/package.json lib/esm/package.json",
97
+ "build": "tsc -b && tsc -p tsconfig.cjs.json && tsc-alias && tsc-alias -p tsconfig.cjs.json && cp src/package.json lib/esm/package.json",
93
98
  "build:watch": "tsc -b --watch",
94
- "bundle": "esbuild --bundle src/index.ts --outfile=dist/index.js --platform=browser",
95
- "attw": "attw --pack . --profile node16"
99
+ "bundle": "esbuild src/index.ts src/agent/index.ts src/candid/index.ts src/identity/index.ts src/identity/secp256k1/index.ts src/principal/index.ts --bundle --outdir=dist --platform=browser",
100
+ "attw": "attw --pack . --profile node16",
101
+ "test": "jest"
96
102
  }
97
103
  }
@@ -0,0 +1,576 @@
1
+ import {
2
+ type Agent,
3
+ type HttpDetailsResponse,
4
+ isV2ResponseBody,
5
+ isV4ResponseBody,
6
+ QueryResponseStatus,
7
+ } from './agent/index.ts';
8
+ import {
9
+ CertifiedRejectErrorCode,
10
+ ExternalError,
11
+ InputError,
12
+ MissingCanisterIdErrorCode,
13
+ MissingRootKeyErrorCode,
14
+ RejectError,
15
+ UncertifiedRejectErrorCode,
16
+ UncertifiedRejectUpdateErrorCode,
17
+ UnexpectedErrorCode,
18
+ UnknownError,
19
+ } from './errors.ts';
20
+ import { IDL } from '#candid';
21
+ import { pollForResponse, type PollingOptions, DEFAULT_POLLING_OPTIONS } from './polling/index.ts';
22
+ import { Principal } from '#principal';
23
+ import { Certificate, type CreateCertificateOptions, lookupResultToBuffer } from './certificate.ts';
24
+ import { HttpAgent } from './agent/http/index.ts';
25
+ import { utf8ToBytes } from '@noble/hashes/utils';
26
+
27
+ /**
28
+ * Configuration to make calls to the Replica.
29
+ */
30
+ export interface CallConfig {
31
+ /**
32
+ * An agent to use in this call, otherwise the actor or call will try to discover the
33
+ * agent to use.
34
+ */
35
+ agent?: Agent;
36
+
37
+ /**
38
+ * Options for controlling polling behavior.
39
+ */
40
+ pollingOptions?: PollingOptions;
41
+
42
+ /**
43
+ * The canister ID of this Actor.
44
+ */
45
+ canisterId?: string | Principal;
46
+
47
+ /**
48
+ * The effective canister ID.
49
+ */
50
+ effectiveCanisterId?: Principal;
51
+
52
+ /**
53
+ * The nonce to use for this call. This is used to prevent replay attacks.
54
+ */
55
+ nonce?: Uint8Array;
56
+ }
57
+
58
+ /**
59
+ * Configuration that can be passed to customize the Actor behavior.
60
+ */
61
+ export interface ActorConfig extends Pick<CallConfig, 'agent' | 'effectiveCanisterId'> {
62
+ /**
63
+ * The Canister ID of this Actor. This is required for an Actor.
64
+ */
65
+ canisterId: string | Principal;
66
+
67
+ /**
68
+ * An override function for update calls' CallConfig. This will be called on every calls.
69
+ */
70
+ callTransform?(
71
+ methodName: string,
72
+ args: unknown[],
73
+ callConfig: CallConfig,
74
+ ): Partial<CallConfig> | void;
75
+
76
+ /**
77
+ * An override function for query calls' CallConfig. This will be called on every query.
78
+ */
79
+ queryTransform?(
80
+ methodName: string,
81
+ args: unknown[],
82
+ callConfig: CallConfig,
83
+ ): Partial<CallConfig> | void;
84
+
85
+ /**
86
+ * Polyfill for BLS Certificate verification in case wasm is not supported
87
+ */
88
+ blsVerify?: CreateCertificateOptions['blsVerify'];
89
+
90
+ /**
91
+ * Polling options to use when making update calls. This will override the default DEFAULT_POLLING_OPTIONS.
92
+ */
93
+ pollingOptions?: PollingOptions;
94
+ }
95
+
96
+ // TODO: move this to proper typing when Candid support TypeScript.
97
+ /**
98
+ * A subclass of an actor. Actor class itself is meant to be a based class.
99
+ */
100
+ export type ActorSubclass<T = Record<string, ActorMethod>> = Actor & T;
101
+
102
+ /**
103
+ * An actor method type, defined for each methods of the actor service.
104
+ */
105
+ export interface ActorMethod<Args extends unknown[] = unknown[], Ret = unknown> {
106
+ (...args: Args): Promise<Ret>;
107
+
108
+ withOptions(options: CallConfig): (...args: Args) => Promise<Ret>;
109
+ }
110
+
111
+ /**
112
+ * An actor method type, defined for each methods of the actor service.
113
+ */
114
+ export interface ActorMethodWithHttpDetails<Args extends unknown[] = unknown[], Ret = unknown>
115
+ extends ActorMethod {
116
+ (...args: Args): Promise<{ httpDetails: HttpDetailsResponse; result: Ret }>;
117
+ }
118
+
119
+ /**
120
+ * An actor method type, defined for each methods of the actor service.
121
+ */
122
+ export interface ActorMethodExtended<Args extends unknown[] = unknown[], Ret = unknown>
123
+ extends ActorMethod {
124
+ (...args: Args): Promise<{
125
+ certificate?: Certificate;
126
+ httpDetails?: HttpDetailsResponse;
127
+ result: Ret;
128
+ }>;
129
+ }
130
+
131
+ export type FunctionWithArgsAndReturn<Args extends unknown[] = unknown[], Ret = unknown> = (
132
+ ...args: Args
133
+ ) => Ret;
134
+
135
+ // Update all entries of T with the extra information from ActorMethodWithInfo
136
+ export type ActorMethodMappedWithHttpDetails<T> = {
137
+ [K in keyof T]: T[K] extends FunctionWithArgsAndReturn<infer Args, infer Ret>
138
+ ? ActorMethodWithHttpDetails<Args, Ret>
139
+ : never;
140
+ };
141
+
142
+ // Update all entries of T with the extra information from ActorMethodWithInfo
143
+ export type ActorMethodMappedExtended<T> = {
144
+ [K in keyof T]: T[K] extends FunctionWithArgsAndReturn<infer Args, infer Ret>
145
+ ? ActorMethodExtended<Args, Ret>
146
+ : never;
147
+ };
148
+
149
+ /**
150
+ * Internal metadata for actors. It's an enhanced version of ActorConfig with
151
+ * some fields marked as required (as they are defaulted) and canisterId as
152
+ * a Principal type.
153
+ */
154
+ interface ActorMetadata {
155
+ service: IDL.ServiceClass;
156
+ agent?: Agent;
157
+ config: ActorConfig;
158
+ }
159
+
160
+ const metadataSymbol = Symbol.for('ic-agent-metadata');
161
+
162
+ export interface CreateActorClassOpts {
163
+ httpDetails?: boolean;
164
+ certificate?: boolean;
165
+ }
166
+
167
+ /**
168
+ * An actor base class. An actor is an object containing only functions that will
169
+ * return a promise. These functions are derived from the IDL definition.
170
+ */
171
+ export class Actor {
172
+ /**
173
+ * Get the Agent class this Actor would call, or undefined if the Actor would use
174
+ * the default agent (global.ic.agent).
175
+ * @param actor The actor to get the agent of.
176
+ */
177
+ public static agentOf(actor: Actor): Agent | undefined {
178
+ return actor[metadataSymbol].config.agent;
179
+ }
180
+
181
+ /**
182
+ * Get the interface of an actor, in the form of an instance of a Service.
183
+ * @param actor The actor to get the interface of.
184
+ */
185
+ public static interfaceOf(actor: Actor): IDL.ServiceClass {
186
+ return actor[metadataSymbol].service;
187
+ }
188
+
189
+ public static canisterIdOf(actor: Actor): Principal {
190
+ return Principal.from(actor[metadataSymbol].config.canisterId);
191
+ }
192
+
193
+ public static createActorClass(
194
+ interfaceFactory: IDL.InterfaceFactory,
195
+ options?: CreateActorClassOpts,
196
+ ): ActorConstructor {
197
+ const service = interfaceFactory({ IDL });
198
+
199
+ class CanisterActor extends Actor {
200
+ [x: string]: ActorMethod;
201
+
202
+ constructor(config: ActorConfig) {
203
+ if (!config.canisterId) {
204
+ throw InputError.fromCode(new MissingCanisterIdErrorCode(config.canisterId));
205
+ }
206
+ const canisterId =
207
+ typeof config.canisterId === 'string'
208
+ ? Principal.fromText(config.canisterId)
209
+ : config.canisterId;
210
+
211
+ super({
212
+ config: {
213
+ ...DEFAULT_ACTOR_CONFIG,
214
+ ...config,
215
+ canisterId,
216
+ },
217
+ service,
218
+ });
219
+
220
+ for (const [methodName, func] of service._fields) {
221
+ if (options?.httpDetails) {
222
+ func.annotations.push(ACTOR_METHOD_WITH_HTTP_DETAILS);
223
+ }
224
+ if (options?.certificate) {
225
+ func.annotations.push(ACTOR_METHOD_WITH_CERTIFICATE);
226
+ }
227
+
228
+ this[methodName] = _createActorMethod(this, methodName, func, config.blsVerify);
229
+ }
230
+ }
231
+ }
232
+
233
+ return CanisterActor;
234
+ }
235
+
236
+ /**
237
+ * Creates an actor with the given interface factory and configuration.
238
+ *
239
+ * The [`@icp-sdk/bindgen`](https://js.icp.build/bindgen/) package can be used to generate the interface factory for your canister.
240
+ * @param interfaceFactory - the interface factory for the actor, typically generated by the [`@icp-sdk/bindgen`](https://js.icp.build/bindgen/) package
241
+ * @param configuration - the configuration for the actor
242
+ * @returns an actor with the given interface factory and configuration
243
+ * @see The {@link https://js.icp.build/core/latest/canister-environment/ | Canister Environment Guide} for more details on how to configure an actor using the canister environment.
244
+ * @example
245
+ * Using the interface factory generated by the [`@icp-sdk/bindgen`](https://js.icp.build/bindgen/) package:
246
+ * ```ts
247
+ * import { Actor, HttpAgent } from '@icp-sdk/core/agent';
248
+ * import { Principal } from '@icp-sdk/core/principal';
249
+ * import { idlFactory } from './api/declarations/hello-world.did';
250
+ *
251
+ * // For a convenient way to get the canister ID,
252
+ * // see the https://js.icp.build/core/latest/canister-environment/ guide.
253
+ * const canisterId = Principal.fromText('rrkah-fqaaa-aaaaa-aaaaq-cai');
254
+ *
255
+ * const agent = await HttpAgent.create({
256
+ * host: 'https://icp-api.io',
257
+ * });
258
+ *
259
+ * const actor = Actor.createActor(idlFactory, {
260
+ * agent,
261
+ * canisterId,
262
+ * });
263
+ *
264
+ * const response = await actor.greet('world');
265
+ * console.log(response);
266
+ * ```
267
+ * @example
268
+ * Using the `createActor` wrapper function generated by the [`@icp-sdk/bindgen`](https://js.icp.build/bindgen/) package:
269
+ * ```ts
270
+ * import { HttpAgent } from '@icp-sdk/core/agent';
271
+ * import { Principal } from '@icp-sdk/core/principal';
272
+ * import { createActor } from './api/hello-world';
273
+ *
274
+ * // For a convenient way to get the canister ID,
275
+ * // see the https://js.icp.build/core/latest/canister-environment/ guide.
276
+ * const canisterId = Principal.fromText('rrkah-fqaaa-aaaaa-aaaaq-cai');
277
+ *
278
+ * const agent = await HttpAgent.create({
279
+ * host: 'https://icp-api.io',
280
+ * });
281
+ *
282
+ * const actor = createActor(canisterId, {
283
+ * agent,
284
+ * });
285
+ *
286
+ * const response = await actor.greet('world');
287
+ * console.log(response);
288
+ * ```
289
+ */
290
+ public static createActor<T = Record<string, ActorMethod>>(
291
+ interfaceFactory: IDL.InterfaceFactory,
292
+ configuration: ActorConfig,
293
+ ): ActorSubclass<T> {
294
+ if (!configuration.canisterId) {
295
+ throw InputError.fromCode(new MissingCanisterIdErrorCode(configuration.canisterId));
296
+ }
297
+ return new (this.createActorClass(interfaceFactory))(
298
+ configuration,
299
+ ) as unknown as ActorSubclass<T>;
300
+ }
301
+
302
+ /**
303
+ * Returns an actor with methods that return the http response details along with the result
304
+ * @param interfaceFactory - the interface factory for the actor
305
+ * @param configuration - the configuration for the actor
306
+ * @deprecated - use createActor with actorClassOptions instead
307
+ */
308
+ public static createActorWithHttpDetails<T = Record<string, ActorMethod>>(
309
+ interfaceFactory: IDL.InterfaceFactory,
310
+ configuration: ActorConfig,
311
+ ): ActorSubclass<ActorMethodMappedWithHttpDetails<T>> {
312
+ return new (this.createActorClass(interfaceFactory, { httpDetails: true }))(
313
+ configuration,
314
+ ) as unknown as ActorSubclass<ActorMethodMappedWithHttpDetails<T>>;
315
+ }
316
+
317
+ /**
318
+ * Returns an actor with methods that return the http response details along with the result
319
+ * @param interfaceFactory - the interface factory for the actor
320
+ * @param configuration - the configuration for the actor
321
+ * @param actorClassOptions - options for the actor class extended details to return with the result
322
+ */
323
+ public static createActorWithExtendedDetails<T = Record<string, ActorMethod>>(
324
+ interfaceFactory: IDL.InterfaceFactory,
325
+ configuration: ActorConfig,
326
+ actorClassOptions: CreateActorClassOpts = {
327
+ httpDetails: true,
328
+ certificate: true,
329
+ },
330
+ ): ActorSubclass<ActorMethodMappedExtended<T>> {
331
+ return new (this.createActorClass(interfaceFactory, actorClassOptions))(
332
+ configuration,
333
+ ) as unknown as ActorSubclass<ActorMethodMappedExtended<T>>;
334
+ }
335
+
336
+ private [metadataSymbol]: ActorMetadata;
337
+
338
+ protected constructor(metadata: ActorMetadata) {
339
+ this[metadataSymbol] = Object.freeze(metadata);
340
+ }
341
+ }
342
+
343
+ // IDL functions can have multiple return values, so decoding always
344
+ // produces an array. Ensure that functions with single or zero return
345
+ // values behave as expected.
346
+ function decodeReturnValue(types: IDL.Type[], msg: Uint8Array) {
347
+ const returnValues = IDL.decode(types, msg);
348
+ switch (returnValues.length) {
349
+ case 0:
350
+ return undefined;
351
+ case 1:
352
+ return returnValues[0];
353
+ default:
354
+ return returnValues;
355
+ }
356
+ }
357
+
358
+ const DEFAULT_ACTOR_CONFIG: Partial<ActorConfig> = {
359
+ pollingOptions: DEFAULT_POLLING_OPTIONS,
360
+ };
361
+
362
+ export type ActorConstructor = new (config: ActorConfig) => ActorSubclass;
363
+
364
+ export const ACTOR_METHOD_WITH_HTTP_DETAILS = 'http-details';
365
+ export const ACTOR_METHOD_WITH_CERTIFICATE = 'certificate';
366
+
367
+ function _createActorMethod(
368
+ actor: Actor,
369
+ methodName: string,
370
+ func: IDL.FuncClass,
371
+ blsVerify?: CreateCertificateOptions['blsVerify'],
372
+ ): ActorMethod {
373
+ let caller: (options: CallConfig, ...args: unknown[]) => Promise<unknown>;
374
+ if (func.annotations.includes('query') || func.annotations.includes('composite_query')) {
375
+ caller = async (options, ...args) => {
376
+ // First, if there's a config transformation, call it.
377
+ options = {
378
+ ...options,
379
+ ...actor[metadataSymbol].config.queryTransform?.(methodName, args, {
380
+ ...actor[metadataSymbol].config,
381
+ ...options,
382
+ }),
383
+ };
384
+
385
+ const agent = options.agent || actor[metadataSymbol].config.agent || new HttpAgent();
386
+ const cid = Principal.from(options.canisterId || actor[metadataSymbol].config.canisterId);
387
+ const arg = IDL.encode(func.argTypes, args);
388
+
389
+ const result = await agent.query(cid, {
390
+ methodName,
391
+ arg,
392
+ effectiveCanisterId: options.effectiveCanisterId,
393
+ });
394
+ const httpDetails = {
395
+ ...result.httpDetails,
396
+ requestDetails: result.requestDetails,
397
+ } as HttpDetailsResponse;
398
+
399
+ switch (result.status) {
400
+ case QueryResponseStatus.Rejected: {
401
+ const uncertifiedRejectErrorCode = new UncertifiedRejectErrorCode(
402
+ result.requestId,
403
+ result.reject_code,
404
+ result.reject_message,
405
+ result.error_code,
406
+ result.signatures,
407
+ );
408
+ uncertifiedRejectErrorCode.callContext = {
409
+ canisterId: cid,
410
+ methodName,
411
+ httpDetails,
412
+ };
413
+ throw RejectError.fromCode(uncertifiedRejectErrorCode);
414
+ }
415
+
416
+ case QueryResponseStatus.Replied:
417
+ return func.annotations.includes(ACTOR_METHOD_WITH_HTTP_DETAILS)
418
+ ? {
419
+ httpDetails,
420
+ result: decodeReturnValue(func.retTypes, result.reply.arg),
421
+ }
422
+ : decodeReturnValue(func.retTypes, result.reply.arg);
423
+ }
424
+ };
425
+ } else {
426
+ caller = async (options, ...args) => {
427
+ // First, if there's a config transformation, call it.
428
+ options = {
429
+ ...options,
430
+ ...actor[metadataSymbol].config.callTransform?.(methodName, args, {
431
+ ...actor[metadataSymbol].config,
432
+ ...options,
433
+ }),
434
+ };
435
+
436
+ const agent = options.agent || actor[metadataSymbol].config.agent || HttpAgent.createSync();
437
+
438
+ const { canisterId, effectiveCanisterId, pollingOptions } = {
439
+ ...DEFAULT_ACTOR_CONFIG,
440
+ ...actor[metadataSymbol].config,
441
+ ...options,
442
+ };
443
+ const cid = Principal.from(canisterId);
444
+ const ecid = effectiveCanisterId !== undefined ? Principal.from(effectiveCanisterId) : cid;
445
+ const arg = IDL.encode(func.argTypes, args);
446
+
447
+ const { requestId, response, requestDetails } = await agent.call(cid, {
448
+ methodName,
449
+ arg,
450
+ effectiveCanisterId: ecid,
451
+ nonce: options.nonce,
452
+ });
453
+ let reply: Uint8Array | undefined;
454
+ let certificate: Certificate | undefined;
455
+ if (isV4ResponseBody(response.body)) {
456
+ if (agent.rootKey == null) {
457
+ throw ExternalError.fromCode(new MissingRootKeyErrorCode());
458
+ }
459
+ const cert = response.body.certificate;
460
+ certificate = await Certificate.create({
461
+ certificate: cert,
462
+ rootKey: agent.rootKey,
463
+ principal: { canisterId: ecid },
464
+ blsVerify,
465
+ agent,
466
+ });
467
+ const path = [utf8ToBytes('request_status'), requestId];
468
+ const status = new TextDecoder().decode(
469
+ lookupResultToBuffer(certificate.lookup_path([...path, 'status'])),
470
+ );
471
+
472
+ switch (status) {
473
+ case 'replied':
474
+ reply = lookupResultToBuffer(certificate.lookup_path([...path, 'reply']));
475
+ break;
476
+ case 'rejected': {
477
+ // Find rejection details in the certificate
478
+ const rejectCode = new Uint8Array(
479
+ lookupResultToBuffer(certificate.lookup_path([...path, 'reject_code']))!,
480
+ )[0];
481
+ const rejectMessage = new TextDecoder().decode(
482
+ lookupResultToBuffer(certificate.lookup_path([...path, 'reject_message']))!,
483
+ );
484
+
485
+ const error_code_buf = lookupResultToBuffer(
486
+ certificate.lookup_path([...path, 'error_code']),
487
+ );
488
+ const error_code = error_code_buf
489
+ ? new TextDecoder().decode(error_code_buf)
490
+ : undefined;
491
+
492
+ const certifiedRejectErrorCode = new CertifiedRejectErrorCode(
493
+ requestId,
494
+ rejectCode,
495
+ rejectMessage,
496
+ error_code,
497
+ );
498
+ certifiedRejectErrorCode.callContext = {
499
+ canisterId: cid,
500
+ methodName,
501
+ httpDetails: response,
502
+ };
503
+ throw RejectError.fromCode(certifiedRejectErrorCode);
504
+ }
505
+ }
506
+ } else if (isV2ResponseBody(response.body)) {
507
+ const { reject_code, reject_message, error_code } = response.body;
508
+ const errorCode = new UncertifiedRejectUpdateErrorCode(
509
+ requestId,
510
+ reject_code,
511
+ reject_message,
512
+ error_code,
513
+ );
514
+ errorCode.callContext = {
515
+ canisterId: cid,
516
+ methodName,
517
+ httpDetails: response,
518
+ };
519
+ throw RejectError.fromCode(errorCode);
520
+ }
521
+
522
+ // Fall back to polling if we receive an Accepted response code
523
+ if (response.status === 202) {
524
+ const pollOptions: PollingOptions = {
525
+ ...pollingOptions,
526
+ blsVerify,
527
+ };
528
+ // Contains the certificate and the reply from the boundary node
529
+ const response = await pollForResponse(agent, ecid, requestId, pollOptions);
530
+ certificate = response.certificate;
531
+ reply = response.reply;
532
+ }
533
+ const shouldIncludeHttpDetails = func.annotations.includes(ACTOR_METHOD_WITH_HTTP_DETAILS);
534
+ const shouldIncludeCertificate = func.annotations.includes(ACTOR_METHOD_WITH_CERTIFICATE);
535
+
536
+ const httpDetails = { ...response, requestDetails } as HttpDetailsResponse;
537
+ if (reply !== undefined) {
538
+ if (shouldIncludeHttpDetails && shouldIncludeCertificate) {
539
+ return {
540
+ httpDetails,
541
+ certificate,
542
+ result: decodeReturnValue(func.retTypes, reply),
543
+ };
544
+ } else if (shouldIncludeCertificate) {
545
+ return {
546
+ certificate,
547
+ result: decodeReturnValue(func.retTypes, reply),
548
+ };
549
+ } else if (shouldIncludeHttpDetails) {
550
+ return {
551
+ httpDetails,
552
+ result: decodeReturnValue(func.retTypes, reply),
553
+ };
554
+ }
555
+ return decodeReturnValue(func.retTypes, reply);
556
+ } else {
557
+ const errorCode = new UnexpectedErrorCode(
558
+ `Call was returned undefined. We cannot determine if the call was successful or not. Return types: [${func.retTypes.map(t => t.display()).join(',')}].`,
559
+ );
560
+ errorCode.callContext = {
561
+ canisterId: cid,
562
+ methodName,
563
+ httpDetails,
564
+ };
565
+ throw UnknownError.fromCode(errorCode);
566
+ }
567
+ };
568
+ }
569
+
570
+ const handler = (...args: unknown[]) => caller({}, ...args);
571
+ handler.withOptions =
572
+ (options: CallConfig) =>
573
+ (...args: unknown[]) =>
574
+ caller(options, ...args);
575
+ return handler as ActorMethod;
576
+ }