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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (456) 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 +7 -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 +19 -0
  12. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
  13. package/lib/cjs/agent/agent/http/index.d.ts +171 -0
  14. package/lib/cjs/agent/agent/http/index.d.ts.map +1 -0
  15. package/lib/cjs/agent/agent/http/index.js +1079 -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 +93 -0
  34. package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -0
  35. package/lib/cjs/agent/canisterStatus/index.js +301 -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 +228 -0
  42. package/lib/cjs/agent/certificate.d.ts.map +1 -0
  43. package/lib/cjs/agent/certificate.js +591 -0
  44. package/lib/cjs/agent/certificate.js.map +1 -0
  45. package/lib/cjs/agent/constants.d.ts +14 -0
  46. package/lib/cjs/agent/constants.d.ts.map +1 -0
  47. package/lib/cjs/agent/constants.js +18 -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 +380 -0
  54. package/lib/cjs/agent/errors.d.ts.map +1 -0
  55. package/lib/cjs/agent/errors.js +733 -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 +31 -1
  62. package/lib/cjs/agent/index.d.ts.map +1 -1
  63. package/lib/cjs/agent/index.js +59 -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/utils/bls.d.ts +10 -0
  90. package/lib/cjs/agent/utils/bls.d.ts.map +1 -0
  91. package/lib/cjs/agent/utils/bls.js +20 -0
  92. package/lib/cjs/agent/utils/bls.js.map +1 -0
  93. package/lib/cjs/agent/utils/buffer.d.ts +22 -0
  94. package/lib/cjs/agent/utils/buffer.d.ts.map +1 -0
  95. package/lib/cjs/agent/utils/buffer.js +55 -0
  96. package/lib/cjs/agent/utils/buffer.js.map +1 -0
  97. package/lib/cjs/agent/utils/expirableMap.d.ts +80 -0
  98. package/lib/cjs/agent/utils/expirableMap.d.ts.map +1 -0
  99. package/lib/cjs/agent/utils/expirableMap.js +148 -0
  100. package/lib/cjs/agent/utils/expirableMap.js.map +1 -0
  101. package/lib/cjs/agent/utils/leb.d.ts +3 -0
  102. package/lib/cjs/agent/utils/leb.d.ts.map +1 -0
  103. package/lib/cjs/agent/utils/leb.js +17 -0
  104. package/lib/cjs/agent/utils/leb.js.map +1 -0
  105. package/lib/cjs/agent/utils/random.d.ts +6 -0
  106. package/lib/cjs/agent/utils/random.d.ts.map +1 -0
  107. package/lib/cjs/agent/utils/random.js +29 -0
  108. package/lib/cjs/agent/utils/random.js.map +1 -0
  109. package/lib/cjs/candid/candid-core.d.ts +72 -0
  110. package/lib/cjs/candid/candid-core.d.ts.map +1 -0
  111. package/lib/cjs/candid/candid-core.js +251 -0
  112. package/lib/cjs/candid/candid-core.js.map +1 -0
  113. package/lib/cjs/candid/candid-ui.d.ts +35 -0
  114. package/lib/cjs/candid/candid-ui.d.ts.map +1 -0
  115. package/lib/cjs/candid/candid-ui.js +317 -0
  116. package/lib/cjs/candid/candid-ui.js.map +1 -0
  117. package/lib/cjs/candid/idl.d.ts +579 -0
  118. package/lib/cjs/candid/idl.d.ts.map +1 -0
  119. package/lib/cjs/candid/idl.js +2228 -0
  120. package/lib/cjs/candid/idl.js.map +1 -0
  121. package/lib/cjs/candid/index.d.ts +11 -1
  122. package/lib/cjs/candid/index.d.ts.map +1 -1
  123. package/lib/cjs/candid/index.js +33 -1
  124. package/lib/cjs/candid/index.js.map +1 -1
  125. package/lib/cjs/candid/types.d.ts +6 -0
  126. package/lib/cjs/candid/types.d.ts.map +1 -0
  127. package/lib/cjs/candid/types.js +4 -0
  128. package/lib/cjs/candid/types.js.map +1 -0
  129. package/lib/cjs/candid/utils/bigint-math.d.ts +14 -0
  130. package/lib/cjs/candid/utils/bigint-math.d.ts.map +1 -0
  131. package/lib/cjs/candid/utils/bigint-math.js +30 -0
  132. package/lib/cjs/candid/utils/bigint-math.js.map +1 -0
  133. package/lib/cjs/candid/utils/buffer.d.ts +86 -0
  134. package/lib/cjs/candid/utils/buffer.d.ts.map +1 -0
  135. package/lib/cjs/candid/utils/buffer.js +191 -0
  136. package/lib/cjs/candid/utils/buffer.js.map +1 -0
  137. package/lib/cjs/candid/utils/hash.d.ts +7 -0
  138. package/lib/cjs/candid/utils/hash.d.ts.map +1 -0
  139. package/lib/cjs/candid/utils/hash.js +33 -0
  140. package/lib/cjs/candid/utils/hash.js.map +1 -0
  141. package/lib/cjs/candid/utils/leb128.d.ts +65 -0
  142. package/lib/cjs/candid/utils/leb128.d.ts.map +1 -0
  143. package/lib/cjs/candid/utils/leb128.js +228 -0
  144. package/lib/cjs/candid/utils/leb128.js.map +1 -0
  145. package/lib/cjs/identity/identity/delegation.d.ts +164 -0
  146. package/lib/cjs/identity/identity/delegation.d.ts.map +1 -0
  147. package/lib/cjs/identity/identity/delegation.js +302 -0
  148. package/lib/cjs/identity/identity/delegation.js.map +1 -0
  149. package/lib/cjs/identity/identity/ecdsa.d.ts +62 -0
  150. package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -0
  151. package/lib/cjs/identity/identity/ecdsa.js +117 -0
  152. package/lib/cjs/identity/identity/ecdsa.js.map +1 -0
  153. package/lib/cjs/identity/identity/ed25519.d.ts +67 -0
  154. package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -0
  155. package/lib/cjs/identity/identity/ed25519.js +200 -0
  156. package/lib/cjs/identity/identity/ed25519.js.map +1 -0
  157. package/lib/cjs/identity/identity/partial.d.ts +34 -0
  158. package/lib/cjs/identity/identity/partial.d.ts.map +1 -0
  159. package/lib/cjs/identity/identity/partial.js +54 -0
  160. package/lib/cjs/identity/identity/partial.js.map +1 -0
  161. package/lib/cjs/identity/identity/webauthn.d.ts +51 -0
  162. package/lib/cjs/identity/identity/webauthn.d.ts.map +1 -0
  163. package/lib/cjs/identity/identity/webauthn.js +197 -0
  164. package/lib/cjs/identity/identity/webauthn.js.map +1 -0
  165. package/lib/cjs/identity/index.d.ts +15 -1
  166. package/lib/cjs/identity/index.d.ts.map +1 -1
  167. package/lib/cjs/identity/index.js +24 -1
  168. package/lib/cjs/identity/index.js.map +1 -1
  169. package/lib/cjs/identity/secp256k1/der.d.ts +33 -0
  170. package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -0
  171. package/lib/cjs/identity/secp256k1/der.js +165 -0
  172. package/lib/cjs/identity/secp256k1/der.js.map +1 -0
  173. package/lib/cjs/identity/secp256k1/index.d.ts +4 -1
  174. package/lib/cjs/identity/secp256k1/index.d.ts.map +1 -1
  175. package/lib/cjs/identity/secp256k1/index.js +4 -1
  176. package/lib/cjs/identity/secp256k1/index.js.map +1 -1
  177. package/lib/cjs/identity/secp256k1/pem.d.ts +7 -0
  178. package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -0
  179. package/lib/cjs/identity/secp256k1/pem.js +75 -0
  180. package/lib/cjs/identity/secp256k1/pem.js.map +1 -0
  181. package/lib/cjs/identity/secp256k1/secp256k1.d.ts +87 -0
  182. package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -0
  183. package/lib/cjs/identity/secp256k1/secp256k1.js +260 -0
  184. package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -0
  185. package/lib/cjs/principal/index.d.ts +3 -1
  186. package/lib/cjs/principal/index.d.ts.map +1 -1
  187. package/lib/cjs/principal/index.js +7 -1
  188. package/lib/cjs/principal/index.js.map +1 -1
  189. package/lib/cjs/principal/principal.d.ts +50 -0
  190. package/lib/cjs/principal/principal.d.ts.map +1 -0
  191. package/lib/cjs/principal/principal.js +148 -0
  192. package/lib/cjs/principal/principal.js.map +1 -0
  193. package/lib/cjs/principal/utils/base32.d.ts +10 -0
  194. package/lib/cjs/principal/utils/base32.d.ts.map +1 -0
  195. package/lib/cjs/principal/utils/base32.js +90 -0
  196. package/lib/cjs/principal/utils/base32.js.map +1 -0
  197. package/lib/cjs/principal/utils/getCrc.d.ts +6 -0
  198. package/lib/cjs/principal/utils/getCrc.d.ts.map +1 -0
  199. package/lib/cjs/principal/utils/getCrc.js +53 -0
  200. package/lib/cjs/principal/utils/getCrc.js.map +1 -0
  201. package/lib/esm/agent/actor.d.ts +203 -0
  202. package/lib/esm/agent/actor.d.ts.map +1 -0
  203. package/lib/esm/agent/actor.js +337 -0
  204. package/lib/esm/agent/actor.js.map +1 -0
  205. package/lib/esm/agent/agent/api.d.ts +216 -0
  206. package/lib/esm/agent/agent/api.d.ts.map +1 -0
  207. package/lib/esm/agent/agent/api.js +34 -0
  208. package/lib/esm/agent/agent/api.js.map +1 -0
  209. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts +7 -0
  210. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
  211. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js +16 -0
  212. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
  213. package/lib/esm/agent/agent/http/index.d.ts +171 -0
  214. package/lib/esm/agent/agent/http/index.d.ts.map +1 -0
  215. package/lib/esm/agent/agent/http/index.js +1037 -0
  216. package/lib/esm/agent/agent/http/index.js.map +1 -0
  217. package/lib/esm/agent/agent/http/transforms.d.ts +54 -0
  218. package/lib/esm/agent/agent/http/transforms.d.ts.map +1 -0
  219. package/lib/esm/agent/agent/http/transforms.js +128 -0
  220. package/lib/esm/agent/agent/http/transforms.js.map +1 -0
  221. package/lib/esm/agent/agent/http/types.d.ts +81 -0
  222. package/lib/esm/agent/agent/http/types.d.ts.map +1 -0
  223. package/lib/esm/agent/agent/http/types.js +39 -0
  224. package/lib/esm/agent/agent/http/types.js.map +1 -0
  225. package/lib/esm/agent/agent/index.d.ts +3 -0
  226. package/lib/esm/agent/agent/index.d.ts.map +1 -0
  227. package/lib/esm/agent/agent/index.js +3 -0
  228. package/lib/esm/agent/agent/index.js.map +1 -0
  229. package/lib/esm/agent/auth.d.ts +91 -0
  230. package/lib/esm/agent/auth.d.ts.map +1 -0
  231. package/lib/esm/agent/auth.js +59 -0
  232. package/lib/esm/agent/auth.js.map +1 -0
  233. package/lib/esm/agent/canister-env/index.d.ts +110 -1
  234. package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
  235. package/lib/esm/agent/canister-env/index.js +110 -1
  236. package/lib/esm/agent/canister-env/index.js.map +1 -1
  237. package/lib/esm/agent/canisterStatus/index.d.ts +93 -0
  238. package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -0
  239. package/lib/esm/agent/canisterStatus/index.js +261 -0
  240. package/lib/esm/agent/canisterStatus/index.js.map +1 -0
  241. package/lib/esm/agent/cbor.d.ts +26 -0
  242. package/lib/esm/agent/cbor.d.ts.map +1 -0
  243. package/lib/esm/agent/cbor.js +54 -0
  244. package/lib/esm/agent/cbor.js.map +1 -0
  245. package/lib/esm/agent/certificate.d.ts +228 -0
  246. package/lib/esm/agent/certificate.d.ts.map +1 -0
  247. package/lib/esm/agent/certificate.js +545 -0
  248. package/lib/esm/agent/certificate.js.map +1 -0
  249. package/lib/esm/agent/constants.d.ts +14 -0
  250. package/lib/esm/agent/constants.d.ts.map +1 -0
  251. package/lib/esm/agent/constants.js +15 -0
  252. package/lib/esm/agent/constants.js.map +1 -0
  253. package/lib/esm/agent/der.d.ts +34 -0
  254. package/lib/esm/agent/der.d.ts.map +1 -0
  255. package/lib/esm/agent/der.js +166 -0
  256. package/lib/esm/agent/der.js.map +1 -0
  257. package/lib/esm/agent/errors.d.ts +380 -0
  258. package/lib/esm/agent/errors.d.ts.map +1 -0
  259. package/lib/esm/agent/errors.js +678 -0
  260. package/lib/esm/agent/errors.js.map +1 -0
  261. package/lib/esm/agent/fetch_candid.d.ts +9 -0
  262. package/lib/esm/agent/fetch_candid.d.ts.map +1 -0
  263. package/lib/esm/agent/fetch_candid.js +33 -0
  264. package/lib/esm/agent/fetch_candid.js.map +1 -0
  265. package/lib/esm/agent/index.d.ts +31 -1
  266. package/lib/esm/agent/index.d.ts.map +1 -1
  267. package/lib/esm/agent/index.js +31 -1
  268. package/lib/esm/agent/index.js.map +1 -1
  269. package/lib/esm/agent/observable.d.ts +24 -0
  270. package/lib/esm/agent/observable.d.ts.map +1 -0
  271. package/lib/esm/agent/observable.js +29 -0
  272. package/lib/esm/agent/observable.js.map +1 -0
  273. package/lib/esm/agent/polling/backoff.d.ts +50 -0
  274. package/lib/esm/agent/polling/backoff.d.ts.map +1 -0
  275. package/lib/esm/agent/polling/backoff.js +85 -0
  276. package/lib/esm/agent/polling/backoff.js.map +1 -0
  277. package/lib/esm/agent/polling/index.d.ts +63 -0
  278. package/lib/esm/agent/polling/index.d.ts.map +1 -0
  279. package/lib/esm/agent/polling/index.js +144 -0
  280. package/lib/esm/agent/polling/index.js.map +1 -0
  281. package/lib/esm/agent/polling/strategy.d.ts +52 -0
  282. package/lib/esm/agent/polling/strategy.d.ts.map +1 -0
  283. package/lib/esm/agent/polling/strategy.js +94 -0
  284. package/lib/esm/agent/polling/strategy.js.map +1 -0
  285. package/lib/esm/agent/public_key.d.ts +16 -0
  286. package/lib/esm/agent/public_key.d.ts.map +1 -0
  287. package/lib/esm/agent/public_key.js +48 -0
  288. package/lib/esm/agent/public_key.js.map +1 -0
  289. package/lib/esm/agent/request_id.d.ts +24 -0
  290. package/lib/esm/agent/request_id.d.ts.map +1 -0
  291. package/lib/esm/agent/request_id.js +83 -0
  292. package/lib/esm/agent/request_id.js.map +1 -0
  293. package/lib/esm/agent/utils/bls.d.ts +10 -0
  294. package/lib/esm/agent/utils/bls.d.ts.map +1 -0
  295. package/lib/esm/agent/utils/bls.js +17 -0
  296. package/lib/esm/agent/utils/bls.js.map +1 -0
  297. package/lib/esm/agent/utils/buffer.d.ts +22 -0
  298. package/lib/esm/agent/utils/buffer.d.ts.map +1 -0
  299. package/lib/esm/agent/utils/buffer.js +50 -0
  300. package/lib/esm/agent/utils/buffer.js.map +1 -0
  301. package/lib/esm/agent/utils/expirableMap.d.ts +80 -0
  302. package/lib/esm/agent/utils/expirableMap.d.ts.map +1 -0
  303. package/lib/esm/agent/utils/expirableMap.js +144 -0
  304. package/lib/esm/agent/utils/expirableMap.js.map +1 -0
  305. package/lib/esm/agent/utils/leb.d.ts +3 -0
  306. package/lib/esm/agent/utils/leb.d.ts.map +1 -0
  307. package/lib/esm/agent/utils/leb.js +12 -0
  308. package/lib/esm/agent/utils/leb.js.map +1 -0
  309. package/lib/esm/agent/utils/random.d.ts +6 -0
  310. package/lib/esm/agent/utils/random.d.ts.map +1 -0
  311. package/lib/esm/agent/utils/random.js +25 -0
  312. package/lib/esm/agent/utils/random.js.map +1 -0
  313. package/lib/esm/candid/candid-core.d.ts +72 -0
  314. package/lib/esm/candid/candid-core.d.ts.map +1 -0
  315. package/lib/esm/candid/candid-core.js +241 -0
  316. package/lib/esm/candid/candid-core.js.map +1 -0
  317. package/lib/esm/candid/candid-ui.d.ts +35 -0
  318. package/lib/esm/candid/candid-ui.d.ts.map +1 -0
  319. package/lib/esm/candid/candid-ui.js +272 -0
  320. package/lib/esm/candid/candid-ui.js.map +1 -0
  321. package/lib/esm/candid/idl.d.ts +579 -0
  322. package/lib/esm/candid/idl.d.ts.map +1 -0
  323. package/lib/esm/candid/idl.js +2189 -0
  324. package/lib/esm/candid/idl.js.map +1 -0
  325. package/lib/esm/candid/index.d.ts +11 -1
  326. package/lib/esm/candid/index.d.ts.map +1 -1
  327. package/lib/esm/candid/index.js +10 -1
  328. package/lib/esm/candid/index.js.map +1 -1
  329. package/lib/esm/candid/types.d.ts +6 -0
  330. package/lib/esm/candid/types.d.ts.map +1 -0
  331. package/lib/esm/candid/types.js +3 -0
  332. package/lib/esm/candid/types.js.map +1 -0
  333. package/lib/esm/candid/utils/bigint-math.d.ts +14 -0
  334. package/lib/esm/candid/utils/bigint-math.d.ts.map +1 -0
  335. package/lib/esm/candid/utils/bigint-math.js +26 -0
  336. package/lib/esm/candid/utils/bigint-math.js.map +1 -0
  337. package/lib/esm/candid/utils/buffer.d.ts +86 -0
  338. package/lib/esm/candid/utils/buffer.d.ts.map +1 -0
  339. package/lib/esm/candid/utils/buffer.js +182 -0
  340. package/lib/esm/candid/utils/buffer.js.map +1 -0
  341. package/lib/esm/candid/utils/hash.d.ts +7 -0
  342. package/lib/esm/candid/utils/hash.d.ts.map +1 -0
  343. package/lib/esm/candid/utils/hash.js +30 -0
  344. package/lib/esm/candid/utils/hash.js.map +1 -0
  345. package/lib/esm/candid/utils/leb128.d.ts +65 -0
  346. package/lib/esm/candid/utils/leb128.d.ts.map +1 -0
  347. package/lib/esm/candid/utils/leb128.js +216 -0
  348. package/lib/esm/candid/utils/leb128.js.map +1 -0
  349. package/lib/esm/identity/identity/delegation.d.ts +164 -0
  350. package/lib/esm/identity/identity/delegation.d.ts.map +1 -0
  351. package/lib/esm/identity/identity/delegation.js +294 -0
  352. package/lib/esm/identity/identity/delegation.js.map +1 -0
  353. package/lib/esm/identity/identity/ecdsa.d.ts +62 -0
  354. package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -0
  355. package/lib/esm/identity/identity/ecdsa.js +112 -0
  356. package/lib/esm/identity/identity/ecdsa.js.map +1 -0
  357. package/lib/esm/identity/identity/ed25519.d.ts +67 -0
  358. package/lib/esm/identity/identity/ed25519.d.ts.map +1 -0
  359. package/lib/esm/identity/identity/ed25519.js +195 -0
  360. package/lib/esm/identity/identity/ed25519.js.map +1 -0
  361. package/lib/esm/identity/identity/partial.d.ts +34 -0
  362. package/lib/esm/identity/identity/partial.d.ts.map +1 -0
  363. package/lib/esm/identity/identity/partial.js +50 -0
  364. package/lib/esm/identity/identity/partial.js.map +1 -0
  365. package/lib/esm/identity/identity/webauthn.d.ts +51 -0
  366. package/lib/esm/identity/identity/webauthn.d.ts.map +1 -0
  367. package/lib/esm/identity/identity/webauthn.js +192 -0
  368. package/lib/esm/identity/identity/webauthn.js.map +1 -0
  369. package/lib/esm/identity/index.d.ts +15 -1
  370. package/lib/esm/identity/index.d.ts.map +1 -1
  371. package/lib/esm/identity/index.js +17 -1
  372. package/lib/esm/identity/index.js.map +1 -1
  373. package/lib/esm/identity/secp256k1/der.d.ts +33 -0
  374. package/lib/esm/identity/secp256k1/der.d.ts.map +1 -0
  375. package/lib/esm/identity/secp256k1/der.js +156 -0
  376. package/lib/esm/identity/secp256k1/der.js.map +1 -0
  377. package/lib/esm/identity/secp256k1/index.d.ts +4 -1
  378. package/lib/esm/identity/secp256k1/index.d.ts.map +1 -1
  379. package/lib/esm/identity/secp256k1/index.js +4 -1
  380. package/lib/esm/identity/secp256k1/index.js.map +1 -1
  381. package/lib/esm/identity/secp256k1/pem.d.ts +7 -0
  382. package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -0
  383. package/lib/esm/identity/secp256k1/pem.js +39 -0
  384. package/lib/esm/identity/secp256k1/pem.js.map +1 -0
  385. package/lib/esm/identity/secp256k1/secp256k1.d.ts +87 -0
  386. package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -0
  387. package/lib/esm/identity/secp256k1/secp256k1.js +222 -0
  388. package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -0
  389. package/lib/esm/principal/index.d.ts +3 -1
  390. package/lib/esm/principal/index.d.ts.map +1 -1
  391. package/lib/esm/principal/index.js +3 -1
  392. package/lib/esm/principal/index.js.map +1 -1
  393. package/lib/esm/principal/principal.d.ts +50 -0
  394. package/lib/esm/principal/principal.d.ts.map +1 -0
  395. package/lib/esm/principal/principal.js +144 -0
  396. package/lib/esm/principal/principal.js.map +1 -0
  397. package/lib/esm/principal/utils/base32.d.ts +10 -0
  398. package/lib/esm/principal/utils/base32.d.ts.map +1 -0
  399. package/lib/esm/principal/utils/base32.js +86 -0
  400. package/lib/esm/principal/utils/base32.js.map +1 -0
  401. package/lib/esm/principal/utils/getCrc.d.ts +6 -0
  402. package/lib/esm/principal/utils/getCrc.d.ts.map +1 -0
  403. package/lib/esm/principal/utils/getCrc.js +50 -0
  404. package/lib/esm/principal/utils/getCrc.js.map +1 -0
  405. package/package.json +17 -11
  406. package/src/agent/actor.ts +576 -0
  407. package/src/agent/agent/api.ts +262 -0
  408. package/src/agent/agent/http/index.ts +1405 -0
  409. package/src/agent/agent/http/transforms.ts +158 -0
  410. package/src/agent/agent/http/types.ts +126 -0
  411. package/src/agent/agent/index.ts +2 -0
  412. package/src/agent/auth.ts +147 -0
  413. package/src/agent/canister-env/index.ts +191 -1
  414. package/src/agent/canisterStatus/index.ts +412 -0
  415. package/src/agent/cbor.ts +63 -0
  416. package/src/agent/certificate.ts +841 -0
  417. package/src/agent/constants.ts +19 -0
  418. package/src/agent/der.ts +170 -0
  419. package/src/agent/errors.ts +868 -0
  420. package/src/agent/fetch_candid.ts +37 -0
  421. package/src/agent/index.ts +37 -1
  422. package/src/agent/observable.ts +49 -0
  423. package/src/agent/polling/backoff.ts +130 -0
  424. package/src/agent/polling/index.ts +250 -0
  425. package/src/agent/polling/strategy.ts +144 -0
  426. package/src/agent/public_key.ts +65 -0
  427. package/src/agent/request_id.ts +92 -0
  428. package/src/agent/utils/bls.ts +18 -0
  429. package/src/agent/utils/buffer.ts +60 -0
  430. package/src/agent/utils/expirableMap.ts +163 -0
  431. package/src/agent/utils/leb.ts +14 -0
  432. package/src/agent/utils/random.ts +30 -0
  433. package/src/candid/candid-core.ts +276 -0
  434. package/src/candid/candid-ui.ts +289 -0
  435. package/src/candid/idl.ts +2556 -0
  436. package/src/candid/index.ts +16 -1
  437. package/src/candid/types.ts +7 -0
  438. package/src/candid/utils/bigint-math.ts +26 -0
  439. package/src/candid/utils/buffer.ts +221 -0
  440. package/src/candid/utils/hash.ts +31 -0
  441. package/src/candid/utils/leb128.ts +234 -0
  442. package/src/identity/identity/delegation.ts +411 -0
  443. package/src/identity/identity/ecdsa.ts +158 -0
  444. package/src/identity/identity/ed25519.ts +239 -0
  445. package/src/identity/identity/partial.ts +60 -0
  446. package/src/identity/identity/webauthn.ts +265 -0
  447. package/src/identity/index.ts +19 -1
  448. package/src/identity/secp256k1/der.ts +156 -0
  449. package/src/identity/secp256k1/index.ts +5 -1
  450. package/src/identity/secp256k1/pem.ts +40 -0
  451. package/src/identity/secp256k1/secp256k1.ts +270 -0
  452. package/src/package.json +4 -0
  453. package/src/principal/index.ts +3 -1
  454. package/src/principal/principal.ts +171 -0
  455. package/src/principal/utils/base32.ts +101 -0
  456. package/src/principal/utils/getCrc.ts +52 -0
@@ -0,0 +1,276 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ /* eslint-disable @typescript-eslint/no-this-alias */
3
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
+ import * as IDL from './idl.ts';
5
+
6
+ export interface ParseConfig {
7
+ random?: boolean;
8
+ }
9
+
10
+ export interface UIConfig {
11
+ input?: HTMLElement;
12
+ form?: InputForm;
13
+ parse(t: IDL.Type, config: ParseConfig, v: string): any;
14
+ }
15
+
16
+ export interface FormConfig {
17
+ open?: HTMLElement;
18
+ event?: string;
19
+ labelMap?: Record<string, string>;
20
+ container?: HTMLElement;
21
+ render(t: IDL.Type): InputBox;
22
+ }
23
+
24
+ export class InputBox {
25
+ public status: HTMLElement;
26
+ public label: string | null = null;
27
+ public value: any = undefined;
28
+
29
+ constructor(
30
+ public idl: IDL.Type,
31
+ public ui: UIConfig,
32
+ ) {
33
+ const status = document.createElement('span');
34
+ status.className = 'status';
35
+ this.status = status;
36
+
37
+ if (ui.input) {
38
+ ui.input.addEventListener('blur', () => {
39
+ if ((ui.input as HTMLInputElement).value === '') {
40
+ return;
41
+ }
42
+ this.parse();
43
+ });
44
+ ui.input.addEventListener('input', () => {
45
+ status.style.display = 'none';
46
+ ui.input!.classList.remove('reject');
47
+ });
48
+ }
49
+ }
50
+ public isRejected(): boolean {
51
+ return this.value === undefined;
52
+ }
53
+
54
+ public parse(config: ParseConfig = {}): any {
55
+ if (this.ui.form) {
56
+ const value = this.ui.form.parse(config);
57
+ this.value = value;
58
+ return value;
59
+ }
60
+
61
+ if (this.ui.input) {
62
+ const input = this.ui.input as HTMLInputElement;
63
+ try {
64
+ const value = this.ui.parse(this.idl, config, input.value);
65
+ if (!this.idl.covariant(value)) {
66
+ throw new Error(`${input.value} is not of type ${this.idl.display()}`);
67
+ }
68
+ this.status.style.display = 'none';
69
+ this.value = value;
70
+ return value;
71
+ } catch (err) {
72
+ input.classList.add('reject');
73
+ this.status.style.display = 'block';
74
+ this.status.innerHTML = 'InputError: ' + (err as Error).message;
75
+ this.value = undefined;
76
+ return undefined;
77
+ }
78
+ }
79
+ return null;
80
+ }
81
+ public render(dom: HTMLElement): void {
82
+ const container = document.createElement('span');
83
+ if (this.label) {
84
+ const label = document.createElement('label');
85
+ label.innerText = this.label;
86
+ container.appendChild(label);
87
+ }
88
+ if (this.ui.input) {
89
+ container.appendChild(this.ui.input);
90
+ container.appendChild(this.status);
91
+ }
92
+
93
+ if (this.ui.form) {
94
+ this.ui.form.render(container);
95
+ }
96
+ dom.appendChild(container);
97
+ }
98
+ }
99
+
100
+ export abstract class InputForm {
101
+ public form: InputBox[] = [];
102
+ constructor(public ui: FormConfig) {}
103
+
104
+ public abstract parse(config: ParseConfig): any;
105
+ public abstract generateForm(): any;
106
+ public renderForm(dom: HTMLElement): void {
107
+ if (this.ui.container) {
108
+ this.form.forEach(e => e.render(this.ui.container!));
109
+ dom.appendChild(this.ui.container);
110
+ } else {
111
+ this.form.forEach(e => e.render(dom));
112
+ }
113
+ }
114
+ public render(dom: HTMLElement): void {
115
+ if (this.ui.open && this.ui.event) {
116
+ dom.appendChild(this.ui.open);
117
+ const form = this;
118
+
119
+ form.ui.open!.addEventListener(form.ui.event!, () => {
120
+ // Remove old form
121
+ if (form.ui.container) {
122
+ form.ui.container.innerHTML = '';
123
+ } else {
124
+ const oldContainer = form.ui.open!.nextElementSibling;
125
+ if (oldContainer) {
126
+ oldContainer.parentNode!.removeChild(oldContainer);
127
+ }
128
+ }
129
+ // Render form
130
+ form.generateForm();
131
+ form.renderForm(dom);
132
+ });
133
+ } else {
134
+ this.generateForm();
135
+ this.renderForm(dom);
136
+ }
137
+ }
138
+ }
139
+
140
+ export class RecordForm extends InputForm {
141
+ constructor(
142
+ public fields: Array<[string, IDL.Type]>,
143
+ public ui: FormConfig,
144
+ ) {
145
+ super(ui);
146
+ }
147
+ public generateForm(): void {
148
+ this.form = this.fields.map(([key, type]) => {
149
+ const input = this.ui.render(type);
150
+ // eslint-disable-next-line
151
+ if (this.ui.labelMap && this.ui.labelMap.hasOwnProperty(key)) {
152
+ input.label = this.ui.labelMap[key] + ' ';
153
+ } else {
154
+ input.label = key + ' ';
155
+ }
156
+ return input;
157
+ });
158
+ }
159
+ public parse(config: ParseConfig): Record<string, any> | undefined {
160
+ const v: Record<string, any> = {};
161
+ this.fields.forEach(([key, _], i) => {
162
+ const value = this.form[i].parse(config);
163
+ v[key] = value;
164
+ });
165
+ if (this.form.some(input => input.isRejected())) {
166
+ return undefined;
167
+ }
168
+ return v;
169
+ }
170
+ }
171
+
172
+ export class TupleForm extends InputForm {
173
+ constructor(
174
+ public components: IDL.Type[],
175
+ public ui: FormConfig,
176
+ ) {
177
+ super(ui);
178
+ }
179
+ public generateForm(): void {
180
+ this.form = this.components.map(type => {
181
+ const input = this.ui.render(type);
182
+ return input;
183
+ });
184
+ }
185
+ public parse(config: ParseConfig): any[] | undefined {
186
+ const v: any[] = [];
187
+ this.components.forEach((_, i) => {
188
+ const value = this.form[i].parse(config);
189
+ v.push(value);
190
+ });
191
+ if (this.form.some(input => input.isRejected())) {
192
+ return undefined;
193
+ }
194
+ return v;
195
+ }
196
+ }
197
+
198
+ export class VariantForm extends InputForm {
199
+ constructor(
200
+ public fields: Array<[string, IDL.Type]>,
201
+ public ui: FormConfig,
202
+ ) {
203
+ super(ui);
204
+ }
205
+ public generateForm(): void {
206
+ const index = (this.ui.open as HTMLSelectElement).selectedIndex;
207
+ const [_, type] = this.fields[index];
208
+ const variant = this.ui.render(type);
209
+ this.form = [variant];
210
+ }
211
+ public parse(config: ParseConfig): Record<string, any> | undefined {
212
+ const select = this.ui.open as HTMLSelectElement;
213
+ const selected = select.options[select.selectedIndex].value;
214
+ const value = this.form[0].parse(config);
215
+ if (value === undefined) {
216
+ return undefined;
217
+ }
218
+ const v: Record<string, any> = {};
219
+ v[selected] = value;
220
+ return v;
221
+ }
222
+ }
223
+
224
+ export class OptionForm extends InputForm {
225
+ constructor(
226
+ public ty: IDL.Type,
227
+ public ui: FormConfig,
228
+ ) {
229
+ super(ui);
230
+ }
231
+ public generateForm(): void {
232
+ if ((this.ui.open as HTMLInputElement).checked) {
233
+ const opt = this.ui.render(this.ty);
234
+ this.form = [opt];
235
+ } else {
236
+ this.form = [];
237
+ }
238
+ }
239
+ public parse<T>(config: ParseConfig): [T] | [] | undefined {
240
+ if (this.form.length === 0) {
241
+ return [];
242
+ } else {
243
+ const value = this.form[0].parse(config);
244
+ if (value === undefined) {
245
+ return undefined;
246
+ }
247
+ return [value];
248
+ }
249
+ }
250
+ }
251
+
252
+ export class VecForm extends InputForm {
253
+ constructor(
254
+ public ty: IDL.Type,
255
+ public ui: FormConfig,
256
+ ) {
257
+ super(ui);
258
+ }
259
+ public generateForm(): void {
260
+ const len = +(this.ui.open as HTMLInputElement).value;
261
+ this.form = [];
262
+ for (let i = 0; i < len; i++) {
263
+ const t = this.ui.render(this.ty);
264
+ this.form.push(t);
265
+ }
266
+ }
267
+ public parse<T>(config: ParseConfig): T[] | undefined {
268
+ const value = this.form.map(input => {
269
+ return input.parse(config);
270
+ });
271
+ if (this.form.some(input => input.isRejected())) {
272
+ return undefined;
273
+ }
274
+ return value;
275
+ }
276
+ }
@@ -0,0 +1,289 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable @typescript-eslint/no-unused-vars */
3
+ import * as IDL from './idl.ts';
4
+ import { Principal } from '#principal';
5
+ import * as UI from './candid-core.ts';
6
+
7
+ type InputBox = UI.InputBox;
8
+
9
+ const InputConfig: UI.UIConfig = { parse: parsePrimitive };
10
+ const FormConfig: UI.FormConfig = { render: renderInput };
11
+
12
+ export const inputBox = (t: IDL.Type, config: Partial<UI.UIConfig>) => {
13
+ return new UI.InputBox(t, { ...InputConfig, ...config });
14
+ };
15
+ export const recordForm = (fields: Array<[string, IDL.Type]>, config: Partial<UI.FormConfig>) => {
16
+ return new UI.RecordForm(fields, { ...FormConfig, ...config });
17
+ };
18
+ export const tupleForm = (components: IDL.Type[], config: Partial<UI.FormConfig>) => {
19
+ return new UI.TupleForm(components, { ...FormConfig, ...config });
20
+ };
21
+ export const variantForm = (fields: Array<[string, IDL.Type]>, config: Partial<UI.FormConfig>) => {
22
+ return new UI.VariantForm(fields, { ...FormConfig, ...config });
23
+ };
24
+ export const optForm = (ty: IDL.Type, config: Partial<UI.FormConfig>) => {
25
+ return new UI.OptionForm(ty, { ...FormConfig, ...config });
26
+ };
27
+ export const vecForm = (ty: IDL.Type, config: Partial<UI.FormConfig>) => {
28
+ return new UI.VecForm(ty, { ...FormConfig, ...config });
29
+ };
30
+
31
+ export class Render extends IDL.Visitor<null, InputBox> {
32
+ public visitType<T>(t: IDL.Type<T>, _d: null): InputBox {
33
+ const input = document.createElement('input');
34
+ input.classList.add('argument');
35
+ input.placeholder = t.display();
36
+ return inputBox(t, { input });
37
+ }
38
+ public visitNull(t: IDL.NullClass, _d: null): InputBox {
39
+ return inputBox(t, {});
40
+ }
41
+ public visitRecord(t: IDL.RecordClass, fields: Array<[string, IDL.Type]>, _d: null): InputBox {
42
+ let config = {};
43
+ if (fields.length > 1) {
44
+ const container = document.createElement('div');
45
+ container.classList.add('popup-form');
46
+ config = { container };
47
+ }
48
+ const form = recordForm(fields, config);
49
+ return inputBox(t as IDL.Type<any>, { form });
50
+ }
51
+ public visitTuple<T extends any[]>(
52
+ t: IDL.TupleClass<T>,
53
+ components: IDL.Type[],
54
+ _d: null,
55
+ ): InputBox {
56
+ let config = {};
57
+ if (components.length > 1) {
58
+ const container = document.createElement('div');
59
+ container.classList.add('popup-form');
60
+ config = { container };
61
+ }
62
+ const form = tupleForm(components, config);
63
+ return inputBox(t as IDL.Type<any>, { form });
64
+ }
65
+ public visitVariant(t: IDL.VariantClass, fields: Array<[string, IDL.Type]>, _d: null): InputBox {
66
+ const select = document.createElement('select');
67
+ for (const [key, _type] of fields) {
68
+ const option = new Option(key);
69
+ select.add(option);
70
+ }
71
+ select.selectedIndex = -1;
72
+ select.classList.add('open');
73
+ const config: Partial<UI.FormConfig> = { open: select, event: 'change' };
74
+ const form = variantForm(fields, config);
75
+ return inputBox(t as IDL.Type<any>, { form });
76
+ }
77
+ public visitOpt<T>(t: IDL.OptClass<T>, ty: IDL.Type<T>, _d: null): InputBox {
78
+ const checkbox = document.createElement('input');
79
+ checkbox.type = 'checkbox';
80
+ checkbox.classList.add('open');
81
+ const form = optForm(ty, { open: checkbox, event: 'change' });
82
+ return inputBox(t as IDL.Type<any>, { form });
83
+ }
84
+ public visitVec<T>(t: IDL.VecClass<T>, ty: IDL.Type<T>, _d: null): InputBox {
85
+ const len = document.createElement('input');
86
+ len.type = 'number';
87
+ len.min = '0';
88
+ len.max = '100';
89
+ len.style.width = '8rem';
90
+ len.placeholder = 'len';
91
+ len.classList.add('open');
92
+ const container = document.createElement('div');
93
+ container.classList.add('popup-form');
94
+ const form = vecForm(ty, { open: len, event: 'change', container });
95
+ return inputBox(t, { form });
96
+ }
97
+ public visitRec<T>(_t: IDL.RecClass<T>, ty: IDL.ConstructType<T>, _d: null): InputBox {
98
+ return renderInput(ty);
99
+ }
100
+ }
101
+
102
+ class Parse extends IDL.Visitor<string, any> {
103
+ public visitNull(_t: IDL.NullClass, _v: string): null {
104
+ return null;
105
+ }
106
+ public visitBool(_t: IDL.BoolClass, v: string): boolean {
107
+ if (v === 'true') {
108
+ return true;
109
+ }
110
+ if (v === 'false') {
111
+ return false;
112
+ }
113
+ throw new Error(`Cannot parse ${v} as boolean`);
114
+ }
115
+ public visitText(_t: IDL.TextClass, v: string): string {
116
+ return v;
117
+ }
118
+ public visitFloat(_t: IDL.FloatClass, v: string): number {
119
+ return parseFloat(v);
120
+ }
121
+ public visitFixedInt(t: IDL.FixedIntClass, v: string): number | bigint {
122
+ if (t._bits <= 32) {
123
+ return parseInt(v, 10);
124
+ } else {
125
+ return BigInt(v);
126
+ }
127
+ }
128
+ public visitFixedNat(t: IDL.FixedNatClass, v: string): number | bigint {
129
+ if (t._bits <= 32) {
130
+ return parseInt(v, 10);
131
+ } else {
132
+ return BigInt(v);
133
+ }
134
+ }
135
+ public visitNumber(_t: IDL.PrimitiveType, v: string): bigint {
136
+ return BigInt(v);
137
+ }
138
+ public visitPrincipal(_t: IDL.PrincipalClass, v: string): Principal {
139
+ return Principal.fromText(v);
140
+ }
141
+ public visitService(_t: IDL.ServiceClass, v: string): Principal {
142
+ return Principal.fromText(v);
143
+ }
144
+ public visitFunc(_t: IDL.FuncClass, v: string): [Principal, string] {
145
+ const x = v.split('.', 2);
146
+ return [Principal.fromText(x[0]), x[1]];
147
+ }
148
+ }
149
+
150
+ class Random extends IDL.Visitor<string, any> {
151
+ public visitNull(_t: IDL.NullClass, _v: string): null {
152
+ return null;
153
+ }
154
+ public visitBool(_t: IDL.BoolClass, _v: string): boolean {
155
+ return Math.random() < 0.5;
156
+ }
157
+ public visitText(_t: IDL.TextClass, _v: string): string {
158
+ return Math.random().toString(36).substring(6);
159
+ }
160
+ public visitFloat(_t: IDL.FloatClass, _v: string): number {
161
+ return Math.random();
162
+ }
163
+ public visitInt(_t: IDL.IntClass, _v: string): bigint {
164
+ return BigInt(this.generateNumber(true));
165
+ }
166
+ public visitNat(_t: IDL.NatClass, _v: string): bigint {
167
+ return BigInt(this.generateNumber(false));
168
+ }
169
+ public visitFixedInt(t: IDL.FixedIntClass, v: string): number | bigint {
170
+ const x = this.generateNumber(true);
171
+ if (t._bits <= 32) {
172
+ return x;
173
+ } else {
174
+ return BigInt(v);
175
+ }
176
+ }
177
+ public visitFixedNat(t: IDL.FixedNatClass, v: string): number | bigint {
178
+ const x = this.generateNumber(false);
179
+ if (t._bits <= 32) {
180
+ return x;
181
+ } else {
182
+ return BigInt(v);
183
+ }
184
+ }
185
+ private generateNumber(signed: boolean): number {
186
+ const num = Math.floor(Math.random() * 100);
187
+ if (signed && Math.random() < 0.5) {
188
+ return -num;
189
+ } else {
190
+ return num;
191
+ }
192
+ }
193
+ }
194
+
195
+ function parsePrimitive(t: IDL.Type, config: UI.ParseConfig, d: string) {
196
+ if (config.random && d === '') {
197
+ return t.accept(new Random(), d);
198
+ } else {
199
+ return t.accept(new Parse(), d);
200
+ }
201
+ }
202
+
203
+ /**
204
+ *
205
+ * @param t an IDL type
206
+ * @returns an input for that type
207
+ */
208
+ export function renderInput(t: IDL.Type): InputBox {
209
+ return t.accept(new Render(), null);
210
+ }
211
+
212
+ interface ValueConfig {
213
+ input: InputBox;
214
+ value: any;
215
+ }
216
+
217
+ /**
218
+ *
219
+ * @param t an IDL Type
220
+ * @param input an InputBox
221
+ * @param value any
222
+ * @returns rendering that value to the provided input
223
+ */
224
+ export function renderValue(t: IDL.Type, input: InputBox, value: any) {
225
+ return t.accept(new RenderValue(), { input, value });
226
+ }
227
+
228
+ class RenderValue extends IDL.Visitor<ValueConfig, void> {
229
+ public visitType<T>(t: IDL.Type<T>, d: ValueConfig) {
230
+ (d.input.ui.input as HTMLInputElement).value = t.valueToString(d.value);
231
+ }
232
+
233
+ public visitNull(_t: IDL.NullClass, _d: ValueConfig) {}
234
+ public visitText(_t: IDL.TextClass, d: ValueConfig) {
235
+ (d.input.ui.input as HTMLInputElement).value = d.value;
236
+ }
237
+ public visitRec<T>(_t: IDL.RecClass<T>, ty: IDL.ConstructType<T>, d: ValueConfig): void {
238
+ renderValue(ty, d.input, d.value);
239
+ }
240
+ public visitOpt<T>(_t: IDL.OptClass<T>, ty: IDL.Type<T>, d: ValueConfig): void {
241
+ if (d.value.length === 0) {
242
+ return;
243
+ } else {
244
+ const form = d.input.ui.form!;
245
+ const open = form.ui.open as HTMLInputElement;
246
+ open.checked = true;
247
+ open.dispatchEvent(new Event(form.ui.event!));
248
+ renderValue(ty, form.form[0], d.value[0]);
249
+ }
250
+ }
251
+ public visitRecord(_t: IDL.RecordClass, fields: Array<[string, IDL.Type]>, d: ValueConfig) {
252
+ const form = d.input.ui.form!;
253
+ fields.forEach(([key, type], i) => {
254
+ renderValue(type, form.form[i], d.value[key]);
255
+ });
256
+ }
257
+ public visitTuple<T extends any[]>(
258
+ _t: IDL.TupleClass<T>,
259
+ components: IDL.Type[],
260
+ d: ValueConfig,
261
+ ) {
262
+ const form = d.input.ui.form!;
263
+ components.forEach((type, i) => {
264
+ renderValue(type, form.form[i], d.value[i]);
265
+ });
266
+ }
267
+ public visitVariant(_t: IDL.VariantClass, fields: Array<[string, IDL.Type]>, d: ValueConfig) {
268
+ const form = d.input.ui.form!;
269
+ const selected = Object.entries(d.value)[0];
270
+ fields.forEach(([key, type], i) => {
271
+ if (key === selected[0]) {
272
+ const open = form.ui.open as HTMLSelectElement;
273
+ open.selectedIndex = i;
274
+ open.dispatchEvent(new Event(form.ui.event!));
275
+ renderValue(type, form.form[0], selected[1]);
276
+ }
277
+ });
278
+ }
279
+ public visitVec<T>(_t: IDL.VecClass<T>, ty: IDL.Type<T>, d: ValueConfig) {
280
+ const form = d.input.ui.form!;
281
+ const len = d.value.length;
282
+ const open = form.ui.open as HTMLInputElement;
283
+ open.value = len;
284
+ open.dispatchEvent(new Event(form.ui.event!));
285
+ d.value.forEach((v: T, i: number) => {
286
+ renderValue(ty, form.form[i], v);
287
+ });
288
+ }
289
+ }