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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (474) hide show
  1. package/lib/cjs/agent/actor.d.ts +203 -0
  2. package/lib/cjs/agent/actor.d.ts.map +1 -0
  3. package/lib/cjs/agent/actor.js +341 -0
  4. package/lib/cjs/agent/actor.js.map +1 -0
  5. package/lib/cjs/agent/agent/api.d.ts +216 -0
  6. package/lib/cjs/agent/agent/api.d.ts.map +1 -0
  7. package/lib/cjs/agent/agent/api.js +39 -0
  8. package/lib/cjs/agent/agent/api.js.map +1 -0
  9. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts +37 -0
  10. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
  11. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js +51 -0
  12. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
  13. package/lib/cjs/agent/agent/http/index.d.ts +190 -0
  14. package/lib/cjs/agent/agent/http/index.d.ts.map +1 -0
  15. package/lib/cjs/agent/agent/http/index.js +1159 -0
  16. package/lib/cjs/agent/agent/http/index.js.map +1 -0
  17. package/lib/cjs/agent/agent/http/transforms.d.ts +54 -0
  18. package/lib/cjs/agent/agent/http/transforms.d.ts.map +1 -0
  19. package/lib/cjs/agent/agent/http/transforms.js +135 -0
  20. package/lib/cjs/agent/agent/http/transforms.js.map +1 -0
  21. package/lib/cjs/agent/agent/http/types.d.ts +81 -0
  22. package/lib/cjs/agent/agent/http/types.d.ts.map +1 -0
  23. package/lib/cjs/agent/agent/http/types.js +43 -0
  24. package/lib/cjs/agent/agent/http/types.js.map +1 -0
  25. package/lib/cjs/agent/agent/index.d.ts +3 -0
  26. package/lib/cjs/agent/agent/index.d.ts.map +1 -0
  27. package/lib/cjs/agent/agent/index.js +19 -0
  28. package/lib/cjs/agent/agent/index.js.map +1 -0
  29. package/lib/cjs/agent/auth.d.ts +91 -0
  30. package/lib/cjs/agent/auth.d.ts.map +1 -0
  31. package/lib/cjs/agent/auth.js +65 -0
  32. package/lib/cjs/agent/auth.js.map +1 -0
  33. package/lib/cjs/agent/canisterStatus/index.d.ts +61 -0
  34. package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -0
  35. package/lib/cjs/agent/canisterStatus/index.js +239 -0
  36. package/lib/cjs/agent/canisterStatus/index.js.map +1 -0
  37. package/lib/cjs/agent/cbor.d.ts +26 -0
  38. package/lib/cjs/agent/cbor.d.ts.map +1 -0
  39. package/lib/cjs/agent/cbor.js +93 -0
  40. package/lib/cjs/agent/cbor.js.map +1 -0
  41. package/lib/cjs/agent/certificate.d.ts +286 -0
  42. package/lib/cjs/agent/certificate.d.ts.map +1 -0
  43. package/lib/cjs/agent/certificate.js +762 -0
  44. package/lib/cjs/agent/certificate.js.map +1 -0
  45. package/lib/cjs/agent/constants.d.ts +18 -0
  46. package/lib/cjs/agent/constants.d.ts.map +1 -0
  47. package/lib/cjs/agent/constants.js +22 -0
  48. package/lib/cjs/agent/constants.js.map +1 -0
  49. package/lib/cjs/agent/der.d.ts +34 -0
  50. package/lib/cjs/agent/der.d.ts.map +1 -0
  51. package/lib/cjs/agent/der.js +175 -0
  52. package/lib/cjs/agent/der.js.map +1 -0
  53. package/lib/cjs/agent/errors.d.ts +386 -0
  54. package/lib/cjs/agent/errors.d.ts.map +1 -0
  55. package/lib/cjs/agent/errors.js +745 -0
  56. package/lib/cjs/agent/errors.js.map +1 -0
  57. package/lib/cjs/agent/fetch_candid.d.ts +9 -0
  58. package/lib/cjs/agent/fetch_candid.d.ts.map +1 -0
  59. package/lib/cjs/agent/fetch_candid.js +69 -0
  60. package/lib/cjs/agent/fetch_candid.js.map +1 -0
  61. package/lib/cjs/agent/index.d.ts +125 -1
  62. package/lib/cjs/agent/index.d.ts.map +1 -1
  63. package/lib/cjs/agent/index.js +142 -1
  64. package/lib/cjs/agent/index.js.map +1 -1
  65. package/lib/cjs/agent/observable.d.ts +24 -0
  66. package/lib/cjs/agent/observable.d.ts.map +1 -0
  67. package/lib/cjs/agent/observable.js +34 -0
  68. package/lib/cjs/agent/observable.js.map +1 -0
  69. package/lib/cjs/agent/polling/backoff.d.ts +50 -0
  70. package/lib/cjs/agent/polling/backoff.d.ts.map +1 -0
  71. package/lib/cjs/agent/polling/backoff.js +90 -0
  72. package/lib/cjs/agent/polling/backoff.js.map +1 -0
  73. package/lib/cjs/agent/polling/index.d.ts +63 -0
  74. package/lib/cjs/agent/polling/index.d.ts.map +1 -0
  75. package/lib/cjs/agent/polling/index.js +183 -0
  76. package/lib/cjs/agent/polling/index.js.map +1 -0
  77. package/lib/cjs/agent/polling/strategy.d.ts +52 -0
  78. package/lib/cjs/agent/polling/strategy.d.ts.map +1 -0
  79. package/lib/cjs/agent/polling/strategy.js +104 -0
  80. package/lib/cjs/agent/polling/strategy.js.map +1 -0
  81. package/lib/cjs/agent/public_key.d.ts +16 -0
  82. package/lib/cjs/agent/public_key.d.ts.map +1 -0
  83. package/lib/cjs/agent/public_key.js +52 -0
  84. package/lib/cjs/agent/public_key.js.map +1 -0
  85. package/lib/cjs/agent/request_id.d.ts +24 -0
  86. package/lib/cjs/agent/request_id.d.ts.map +1 -0
  87. package/lib/cjs/agent/request_id.js +88 -0
  88. package/lib/cjs/agent/request_id.js.map +1 -0
  89. package/lib/cjs/agent/subnetStatus/index.d.ts +70 -0
  90. package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -0
  91. package/lib/cjs/agent/subnetStatus/index.js +224 -0
  92. package/lib/cjs/agent/subnetStatus/index.js.map +1 -0
  93. package/lib/cjs/agent/utils/bls.d.ts +10 -0
  94. package/lib/cjs/agent/utils/bls.d.ts.map +1 -0
  95. package/lib/cjs/agent/utils/bls.js +20 -0
  96. package/lib/cjs/agent/utils/bls.js.map +1 -0
  97. package/lib/cjs/agent/utils/buffer.d.ts +22 -0
  98. package/lib/cjs/agent/utils/buffer.d.ts.map +1 -0
  99. package/lib/cjs/agent/utils/buffer.js +55 -0
  100. package/lib/cjs/agent/utils/buffer.js.map +1 -0
  101. package/lib/cjs/agent/utils/expirableMap.d.ts +80 -0
  102. package/lib/cjs/agent/utils/expirableMap.d.ts.map +1 -0
  103. package/lib/cjs/agent/utils/expirableMap.js +148 -0
  104. package/lib/cjs/agent/utils/expirableMap.js.map +1 -0
  105. package/lib/cjs/agent/utils/leb.d.ts +3 -0
  106. package/lib/cjs/agent/utils/leb.d.ts.map +1 -0
  107. package/lib/cjs/agent/utils/leb.js +17 -0
  108. package/lib/cjs/agent/utils/leb.js.map +1 -0
  109. package/lib/cjs/agent/utils/random.d.ts +6 -0
  110. package/lib/cjs/agent/utils/random.d.ts.map +1 -0
  111. package/lib/cjs/agent/utils/random.js +29 -0
  112. package/lib/cjs/agent/utils/random.js.map +1 -0
  113. package/lib/cjs/agent/utils/readState.d.ts +84 -0
  114. package/lib/cjs/agent/utils/readState.d.ts.map +1 -0
  115. package/lib/cjs/agent/utils/readState.js +149 -0
  116. package/lib/cjs/agent/utils/readState.js.map +1 -0
  117. package/lib/cjs/candid/candid-core.d.ts +72 -0
  118. package/lib/cjs/candid/candid-core.d.ts.map +1 -0
  119. package/lib/cjs/candid/candid-core.js +251 -0
  120. package/lib/cjs/candid/candid-core.js.map +1 -0
  121. package/lib/cjs/candid/candid-ui.d.ts +35 -0
  122. package/lib/cjs/candid/candid-ui.d.ts.map +1 -0
  123. package/lib/cjs/candid/candid-ui.js +317 -0
  124. package/lib/cjs/candid/candid-ui.js.map +1 -0
  125. package/lib/cjs/candid/idl.d.ts +579 -0
  126. package/lib/cjs/candid/idl.d.ts.map +1 -0
  127. package/lib/cjs/candid/idl.js +2228 -0
  128. package/lib/cjs/candid/idl.js.map +1 -0
  129. package/lib/cjs/candid/index.d.ts +30 -1
  130. package/lib/cjs/candid/index.d.ts.map +1 -1
  131. package/lib/cjs/candid/index.js +52 -1
  132. package/lib/cjs/candid/index.js.map +1 -1
  133. package/lib/cjs/candid/types.d.ts +6 -0
  134. package/lib/cjs/candid/types.d.ts.map +1 -0
  135. package/lib/cjs/candid/types.js +4 -0
  136. package/lib/cjs/candid/types.js.map +1 -0
  137. package/lib/cjs/candid/utils/bigint-math.d.ts +14 -0
  138. package/lib/cjs/candid/utils/bigint-math.d.ts.map +1 -0
  139. package/lib/cjs/candid/utils/bigint-math.js +30 -0
  140. package/lib/cjs/candid/utils/bigint-math.js.map +1 -0
  141. package/lib/cjs/candid/utils/buffer.d.ts +86 -0
  142. package/lib/cjs/candid/utils/buffer.d.ts.map +1 -0
  143. package/lib/cjs/candid/utils/buffer.js +191 -0
  144. package/lib/cjs/candid/utils/buffer.js.map +1 -0
  145. package/lib/cjs/candid/utils/hash.d.ts +7 -0
  146. package/lib/cjs/candid/utils/hash.d.ts.map +1 -0
  147. package/lib/cjs/candid/utils/hash.js +33 -0
  148. package/lib/cjs/candid/utils/hash.js.map +1 -0
  149. package/lib/cjs/candid/utils/leb128.d.ts +65 -0
  150. package/lib/cjs/candid/utils/leb128.d.ts.map +1 -0
  151. package/lib/cjs/candid/utils/leb128.js +228 -0
  152. package/lib/cjs/candid/utils/leb128.js.map +1 -0
  153. package/lib/cjs/identity/identity/delegation.d.ts +164 -0
  154. package/lib/cjs/identity/identity/delegation.d.ts.map +1 -0
  155. package/lib/cjs/identity/identity/delegation.js +302 -0
  156. package/lib/cjs/identity/identity/delegation.js.map +1 -0
  157. package/lib/cjs/identity/identity/ecdsa.d.ts +62 -0
  158. package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -0
  159. package/lib/cjs/identity/identity/ecdsa.js +117 -0
  160. package/lib/cjs/identity/identity/ecdsa.js.map +1 -0
  161. package/lib/cjs/identity/identity/ed25519.d.ts +67 -0
  162. package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -0
  163. package/lib/cjs/identity/identity/ed25519.js +200 -0
  164. package/lib/cjs/identity/identity/ed25519.js.map +1 -0
  165. package/lib/cjs/identity/identity/partial.d.ts +34 -0
  166. package/lib/cjs/identity/identity/partial.d.ts.map +1 -0
  167. package/lib/cjs/identity/identity/partial.js +54 -0
  168. package/lib/cjs/identity/identity/partial.js.map +1 -0
  169. package/lib/cjs/identity/identity/webauthn.d.ts +51 -0
  170. package/lib/cjs/identity/identity/webauthn.d.ts.map +1 -0
  171. package/lib/cjs/identity/identity/webauthn.js +197 -0
  172. package/lib/cjs/identity/identity/webauthn.js.map +1 -0
  173. package/lib/cjs/identity/index.d.ts +38 -1
  174. package/lib/cjs/identity/index.d.ts.map +1 -1
  175. package/lib/cjs/identity/index.js +44 -1
  176. package/lib/cjs/identity/index.js.map +1 -1
  177. package/lib/cjs/identity/secp256k1/der.d.ts +33 -0
  178. package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -0
  179. package/lib/cjs/identity/secp256k1/der.js +165 -0
  180. package/lib/cjs/identity/secp256k1/der.js.map +1 -0
  181. package/lib/cjs/identity/secp256k1/index.d.ts +51 -1
  182. package/lib/cjs/identity/secp256k1/index.d.ts.map +1 -1
  183. package/lib/cjs/identity/secp256k1/index.js +51 -1
  184. package/lib/cjs/identity/secp256k1/index.js.map +1 -1
  185. package/lib/cjs/identity/secp256k1/pem.d.ts +7 -0
  186. package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -0
  187. package/lib/cjs/identity/secp256k1/pem.js +75 -0
  188. package/lib/cjs/identity/secp256k1/pem.js.map +1 -0
  189. package/lib/cjs/identity/secp256k1/secp256k1.d.ts +87 -0
  190. package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -0
  191. package/lib/cjs/identity/secp256k1/secp256k1.js +260 -0
  192. package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -0
  193. package/lib/cjs/principal/index.d.ts +18 -1
  194. package/lib/cjs/principal/index.d.ts.map +1 -1
  195. package/lib/cjs/principal/index.js +22 -1
  196. package/lib/cjs/principal/index.js.map +1 -1
  197. package/lib/cjs/principal/principal.d.ts +50 -0
  198. package/lib/cjs/principal/principal.d.ts.map +1 -0
  199. package/lib/cjs/principal/principal.js +148 -0
  200. package/lib/cjs/principal/principal.js.map +1 -0
  201. package/lib/cjs/principal/utils/base32.d.ts +10 -0
  202. package/lib/cjs/principal/utils/base32.d.ts.map +1 -0
  203. package/lib/cjs/principal/utils/base32.js +90 -0
  204. package/lib/cjs/principal/utils/base32.js.map +1 -0
  205. package/lib/cjs/principal/utils/getCrc.d.ts +6 -0
  206. package/lib/cjs/principal/utils/getCrc.d.ts.map +1 -0
  207. package/lib/cjs/principal/utils/getCrc.js +53 -0
  208. package/lib/cjs/principal/utils/getCrc.js.map +1 -0
  209. package/lib/esm/agent/actor.d.ts +203 -0
  210. package/lib/esm/agent/actor.d.ts.map +1 -0
  211. package/lib/esm/agent/actor.js +337 -0
  212. package/lib/esm/agent/actor.js.map +1 -0
  213. package/lib/esm/agent/agent/api.d.ts +216 -0
  214. package/lib/esm/agent/agent/api.d.ts.map +1 -0
  215. package/lib/esm/agent/agent/api.js +34 -0
  216. package/lib/esm/agent/agent/api.js.map +1 -0
  217. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts +37 -0
  218. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -0
  219. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js +48 -0
  220. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -0
  221. package/lib/esm/agent/agent/http/index.d.ts +190 -0
  222. package/lib/esm/agent/agent/http/index.d.ts.map +1 -0
  223. package/lib/esm/agent/agent/http/index.js +1117 -0
  224. package/lib/esm/agent/agent/http/index.js.map +1 -0
  225. package/lib/esm/agent/agent/http/transforms.d.ts +54 -0
  226. package/lib/esm/agent/agent/http/transforms.d.ts.map +1 -0
  227. package/lib/esm/agent/agent/http/transforms.js +128 -0
  228. package/lib/esm/agent/agent/http/transforms.js.map +1 -0
  229. package/lib/esm/agent/agent/http/types.d.ts +81 -0
  230. package/lib/esm/agent/agent/http/types.d.ts.map +1 -0
  231. package/lib/esm/agent/agent/http/types.js +39 -0
  232. package/lib/esm/agent/agent/http/types.js.map +1 -0
  233. package/lib/esm/agent/agent/index.d.ts +3 -0
  234. package/lib/esm/agent/agent/index.d.ts.map +1 -0
  235. package/lib/esm/agent/agent/index.js +3 -0
  236. package/lib/esm/agent/agent/index.js.map +1 -0
  237. package/lib/esm/agent/auth.d.ts +91 -0
  238. package/lib/esm/agent/auth.d.ts.map +1 -0
  239. package/lib/esm/agent/auth.js +59 -0
  240. package/lib/esm/agent/auth.js.map +1 -0
  241. package/lib/esm/agent/canister-env/index.d.ts +111 -1
  242. package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
  243. package/lib/esm/agent/canister-env/index.js +111 -1
  244. package/lib/esm/agent/canister-env/index.js.map +1 -1
  245. package/lib/esm/agent/canisterStatus/index.d.ts +61 -0
  246. package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -0
  247. package/lib/esm/agent/canisterStatus/index.js +199 -0
  248. package/lib/esm/agent/canisterStatus/index.js.map +1 -0
  249. package/lib/esm/agent/cbor.d.ts +26 -0
  250. package/lib/esm/agent/cbor.d.ts.map +1 -0
  251. package/lib/esm/agent/cbor.js +54 -0
  252. package/lib/esm/agent/cbor.js.map +1 -0
  253. package/lib/esm/agent/certificate.d.ts +286 -0
  254. package/lib/esm/agent/certificate.d.ts.map +1 -0
  255. package/lib/esm/agent/certificate.js +712 -0
  256. package/lib/esm/agent/certificate.js.map +1 -0
  257. package/lib/esm/agent/constants.d.ts +18 -0
  258. package/lib/esm/agent/constants.d.ts.map +1 -0
  259. package/lib/esm/agent/constants.js +19 -0
  260. package/lib/esm/agent/constants.js.map +1 -0
  261. package/lib/esm/agent/der.d.ts +34 -0
  262. package/lib/esm/agent/der.d.ts.map +1 -0
  263. package/lib/esm/agent/der.js +166 -0
  264. package/lib/esm/agent/der.js.map +1 -0
  265. package/lib/esm/agent/errors.d.ts +386 -0
  266. package/lib/esm/agent/errors.d.ts.map +1 -0
  267. package/lib/esm/agent/errors.js +689 -0
  268. package/lib/esm/agent/errors.js.map +1 -0
  269. package/lib/esm/agent/fetch_candid.d.ts +9 -0
  270. package/lib/esm/agent/fetch_candid.d.ts.map +1 -0
  271. package/lib/esm/agent/fetch_candid.js +33 -0
  272. package/lib/esm/agent/fetch_candid.js.map +1 -0
  273. package/lib/esm/agent/index.d.ts +125 -1
  274. package/lib/esm/agent/index.d.ts.map +1 -1
  275. package/lib/esm/agent/index.js +125 -1
  276. package/lib/esm/agent/index.js.map +1 -1
  277. package/lib/esm/agent/observable.d.ts +24 -0
  278. package/lib/esm/agent/observable.d.ts.map +1 -0
  279. package/lib/esm/agent/observable.js +29 -0
  280. package/lib/esm/agent/observable.js.map +1 -0
  281. package/lib/esm/agent/polling/backoff.d.ts +50 -0
  282. package/lib/esm/agent/polling/backoff.d.ts.map +1 -0
  283. package/lib/esm/agent/polling/backoff.js +85 -0
  284. package/lib/esm/agent/polling/backoff.js.map +1 -0
  285. package/lib/esm/agent/polling/index.d.ts +63 -0
  286. package/lib/esm/agent/polling/index.d.ts.map +1 -0
  287. package/lib/esm/agent/polling/index.js +144 -0
  288. package/lib/esm/agent/polling/index.js.map +1 -0
  289. package/lib/esm/agent/polling/strategy.d.ts +52 -0
  290. package/lib/esm/agent/polling/strategy.d.ts.map +1 -0
  291. package/lib/esm/agent/polling/strategy.js +94 -0
  292. package/lib/esm/agent/polling/strategy.js.map +1 -0
  293. package/lib/esm/agent/public_key.d.ts +16 -0
  294. package/lib/esm/agent/public_key.d.ts.map +1 -0
  295. package/lib/esm/agent/public_key.js +48 -0
  296. package/lib/esm/agent/public_key.js.map +1 -0
  297. package/lib/esm/agent/request_id.d.ts +24 -0
  298. package/lib/esm/agent/request_id.d.ts.map +1 -0
  299. package/lib/esm/agent/request_id.js +83 -0
  300. package/lib/esm/agent/request_id.js.map +1 -0
  301. package/lib/esm/agent/subnetStatus/index.d.ts +70 -0
  302. package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -0
  303. package/lib/esm/agent/subnetStatus/index.js +183 -0
  304. package/lib/esm/agent/subnetStatus/index.js.map +1 -0
  305. package/lib/esm/agent/utils/bls.d.ts +10 -0
  306. package/lib/esm/agent/utils/bls.d.ts.map +1 -0
  307. package/lib/esm/agent/utils/bls.js +17 -0
  308. package/lib/esm/agent/utils/bls.js.map +1 -0
  309. package/lib/esm/agent/utils/buffer.d.ts +22 -0
  310. package/lib/esm/agent/utils/buffer.d.ts.map +1 -0
  311. package/lib/esm/agent/utils/buffer.js +50 -0
  312. package/lib/esm/agent/utils/buffer.js.map +1 -0
  313. package/lib/esm/agent/utils/expirableMap.d.ts +80 -0
  314. package/lib/esm/agent/utils/expirableMap.d.ts.map +1 -0
  315. package/lib/esm/agent/utils/expirableMap.js +144 -0
  316. package/lib/esm/agent/utils/expirableMap.js.map +1 -0
  317. package/lib/esm/agent/utils/leb.d.ts +3 -0
  318. package/lib/esm/agent/utils/leb.d.ts.map +1 -0
  319. package/lib/esm/agent/utils/leb.js +12 -0
  320. package/lib/esm/agent/utils/leb.js.map +1 -0
  321. package/lib/esm/agent/utils/random.d.ts +6 -0
  322. package/lib/esm/agent/utils/random.d.ts.map +1 -0
  323. package/lib/esm/agent/utils/random.js +25 -0
  324. package/lib/esm/agent/utils/random.js.map +1 -0
  325. package/lib/esm/agent/utils/readState.d.ts +84 -0
  326. package/lib/esm/agent/utils/readState.d.ts.map +1 -0
  327. package/lib/esm/agent/utils/readState.js +107 -0
  328. package/lib/esm/agent/utils/readState.js.map +1 -0
  329. package/lib/esm/candid/candid-core.d.ts +72 -0
  330. package/lib/esm/candid/candid-core.d.ts.map +1 -0
  331. package/lib/esm/candid/candid-core.js +241 -0
  332. package/lib/esm/candid/candid-core.js.map +1 -0
  333. package/lib/esm/candid/candid-ui.d.ts +35 -0
  334. package/lib/esm/candid/candid-ui.d.ts.map +1 -0
  335. package/lib/esm/candid/candid-ui.js +272 -0
  336. package/lib/esm/candid/candid-ui.js.map +1 -0
  337. package/lib/esm/candid/idl.d.ts +579 -0
  338. package/lib/esm/candid/idl.d.ts.map +1 -0
  339. package/lib/esm/candid/idl.js +2189 -0
  340. package/lib/esm/candid/idl.js.map +1 -0
  341. package/lib/esm/candid/index.d.ts +30 -1
  342. package/lib/esm/candid/index.d.ts.map +1 -1
  343. package/lib/esm/candid/index.js +29 -1
  344. package/lib/esm/candid/index.js.map +1 -1
  345. package/lib/esm/candid/types.d.ts +6 -0
  346. package/lib/esm/candid/types.d.ts.map +1 -0
  347. package/lib/esm/candid/types.js +3 -0
  348. package/lib/esm/candid/types.js.map +1 -0
  349. package/lib/esm/candid/utils/bigint-math.d.ts +14 -0
  350. package/lib/esm/candid/utils/bigint-math.d.ts.map +1 -0
  351. package/lib/esm/candid/utils/bigint-math.js +26 -0
  352. package/lib/esm/candid/utils/bigint-math.js.map +1 -0
  353. package/lib/esm/candid/utils/buffer.d.ts +86 -0
  354. package/lib/esm/candid/utils/buffer.d.ts.map +1 -0
  355. package/lib/esm/candid/utils/buffer.js +182 -0
  356. package/lib/esm/candid/utils/buffer.js.map +1 -0
  357. package/lib/esm/candid/utils/hash.d.ts +7 -0
  358. package/lib/esm/candid/utils/hash.d.ts.map +1 -0
  359. package/lib/esm/candid/utils/hash.js +30 -0
  360. package/lib/esm/candid/utils/hash.js.map +1 -0
  361. package/lib/esm/candid/utils/leb128.d.ts +65 -0
  362. package/lib/esm/candid/utils/leb128.d.ts.map +1 -0
  363. package/lib/esm/candid/utils/leb128.js +216 -0
  364. package/lib/esm/candid/utils/leb128.js.map +1 -0
  365. package/lib/esm/identity/identity/delegation.d.ts +164 -0
  366. package/lib/esm/identity/identity/delegation.d.ts.map +1 -0
  367. package/lib/esm/identity/identity/delegation.js +294 -0
  368. package/lib/esm/identity/identity/delegation.js.map +1 -0
  369. package/lib/esm/identity/identity/ecdsa.d.ts +62 -0
  370. package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -0
  371. package/lib/esm/identity/identity/ecdsa.js +112 -0
  372. package/lib/esm/identity/identity/ecdsa.js.map +1 -0
  373. package/lib/esm/identity/identity/ed25519.d.ts +67 -0
  374. package/lib/esm/identity/identity/ed25519.d.ts.map +1 -0
  375. package/lib/esm/identity/identity/ed25519.js +195 -0
  376. package/lib/esm/identity/identity/ed25519.js.map +1 -0
  377. package/lib/esm/identity/identity/partial.d.ts +34 -0
  378. package/lib/esm/identity/identity/partial.d.ts.map +1 -0
  379. package/lib/esm/identity/identity/partial.js +50 -0
  380. package/lib/esm/identity/identity/partial.js.map +1 -0
  381. package/lib/esm/identity/identity/webauthn.d.ts +51 -0
  382. package/lib/esm/identity/identity/webauthn.d.ts.map +1 -0
  383. package/lib/esm/identity/identity/webauthn.js +192 -0
  384. package/lib/esm/identity/identity/webauthn.js.map +1 -0
  385. package/lib/esm/identity/index.d.ts +38 -1
  386. package/lib/esm/identity/index.d.ts.map +1 -1
  387. package/lib/esm/identity/index.js +38 -1
  388. package/lib/esm/identity/index.js.map +1 -1
  389. package/lib/esm/identity/secp256k1/der.d.ts +33 -0
  390. package/lib/esm/identity/secp256k1/der.d.ts.map +1 -0
  391. package/lib/esm/identity/secp256k1/der.js +156 -0
  392. package/lib/esm/identity/secp256k1/der.js.map +1 -0
  393. package/lib/esm/identity/secp256k1/index.d.ts +51 -1
  394. package/lib/esm/identity/secp256k1/index.d.ts.map +1 -1
  395. package/lib/esm/identity/secp256k1/index.js +51 -1
  396. package/lib/esm/identity/secp256k1/index.js.map +1 -1
  397. package/lib/esm/identity/secp256k1/pem.d.ts +7 -0
  398. package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -0
  399. package/lib/esm/identity/secp256k1/pem.js +39 -0
  400. package/lib/esm/identity/secp256k1/pem.js.map +1 -0
  401. package/lib/esm/identity/secp256k1/secp256k1.d.ts +87 -0
  402. package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -0
  403. package/lib/esm/identity/secp256k1/secp256k1.js +222 -0
  404. package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -0
  405. package/lib/esm/principal/index.d.ts +18 -1
  406. package/lib/esm/principal/index.d.ts.map +1 -1
  407. package/lib/esm/principal/index.js +18 -1
  408. package/lib/esm/principal/index.js.map +1 -1
  409. package/lib/esm/principal/principal.d.ts +50 -0
  410. package/lib/esm/principal/principal.d.ts.map +1 -0
  411. package/lib/esm/principal/principal.js +144 -0
  412. package/lib/esm/principal/principal.js.map +1 -0
  413. package/lib/esm/principal/utils/base32.d.ts +10 -0
  414. package/lib/esm/principal/utils/base32.d.ts.map +1 -0
  415. package/lib/esm/principal/utils/base32.js +86 -0
  416. package/lib/esm/principal/utils/base32.js.map +1 -0
  417. package/lib/esm/principal/utils/getCrc.d.ts +6 -0
  418. package/lib/esm/principal/utils/getCrc.d.ts.map +1 -0
  419. package/lib/esm/principal/utils/getCrc.js +50 -0
  420. package/lib/esm/principal/utils/getCrc.js.map +1 -0
  421. package/package.json +17 -11
  422. package/src/agent/actor.ts +576 -0
  423. package/src/agent/agent/api.ts +262 -0
  424. package/src/agent/agent/http/index.ts +1518 -0
  425. package/src/agent/agent/http/transforms.ts +158 -0
  426. package/src/agent/agent/http/types.ts +126 -0
  427. package/src/agent/agent/index.ts +2 -0
  428. package/src/agent/auth.ts +147 -0
  429. package/src/agent/canister-env/index.ts +192 -1
  430. package/src/agent/canisterStatus/index.ts +267 -0
  431. package/src/agent/cbor.ts +63 -0
  432. package/src/agent/certificate.ts +1060 -0
  433. package/src/agent/constants.ts +24 -0
  434. package/src/agent/der.ts +170 -0
  435. package/src/agent/errors.ts +881 -0
  436. package/src/agent/fetch_candid.ts +37 -0
  437. package/src/agent/index.ts +131 -1
  438. package/src/agent/observable.ts +49 -0
  439. package/src/agent/polling/backoff.ts +130 -0
  440. package/src/agent/polling/index.ts +250 -0
  441. package/src/agent/polling/strategy.ts +144 -0
  442. package/src/agent/public_key.ts +65 -0
  443. package/src/agent/request_id.ts +92 -0
  444. package/src/agent/subnetStatus/index.ts +270 -0
  445. package/src/agent/utils/bls.ts +18 -0
  446. package/src/agent/utils/buffer.ts +60 -0
  447. package/src/agent/utils/expirableMap.ts +163 -0
  448. package/src/agent/utils/leb.ts +14 -0
  449. package/src/agent/utils/random.ts +30 -0
  450. package/src/agent/utils/readState.ts +180 -0
  451. package/src/candid/candid-core.ts +276 -0
  452. package/src/candid/candid-ui.ts +289 -0
  453. package/src/candid/idl.ts +2556 -0
  454. package/src/candid/index.ts +35 -1
  455. package/src/candid/types.ts +7 -0
  456. package/src/candid/utils/bigint-math.ts +26 -0
  457. package/src/candid/utils/buffer.ts +221 -0
  458. package/src/candid/utils/hash.ts +31 -0
  459. package/src/candid/utils/leb128.ts +234 -0
  460. package/src/identity/identity/delegation.ts +411 -0
  461. package/src/identity/identity/ecdsa.ts +158 -0
  462. package/src/identity/identity/ed25519.ts +239 -0
  463. package/src/identity/identity/partial.ts +60 -0
  464. package/src/identity/identity/webauthn.ts +265 -0
  465. package/src/identity/index.ts +39 -1
  466. package/src/identity/secp256k1/der.ts +156 -0
  467. package/src/identity/secp256k1/index.ts +52 -1
  468. package/src/identity/secp256k1/pem.ts +40 -0
  469. package/src/identity/secp256k1/secp256k1.ts +270 -0
  470. package/src/package.json +4 -0
  471. package/src/principal/index.ts +19 -1
  472. package/src/principal/principal.ts +171 -0
  473. package/src/principal/utils/base32.ts +101 -0
  474. package/src/principal/utils/getCrc.ts +52 -0
@@ -1 +1,35 @@
1
- export * from '@dfinity/candid';
1
+ /**
2
+ * JavaScript and TypeScript module to work with Candid interfaces
3
+ *
4
+ * ## Usage
5
+ *
6
+ * ```ts
7
+ * import { IDL } from '@icp-sdk/core/candid';
8
+ *
9
+ * const MyType = IDL.Record({
10
+ * name: IDL.Text,
11
+ * age: IDL.Nat8,
12
+ * });
13
+ *
14
+ * const encoded = IDL.encode([MyType], [{ name: 'John', age: 30 }]);
15
+ * const decoded = IDL.decode([MyType], encoded);
16
+ *
17
+ * console.log(decoded); // [{ name: 'John', age: 30 }]
18
+ * ```
19
+ *
20
+ * <!-- split here -->
21
+ * @module libs/candid/api
22
+ */
23
+
24
+ export * from './candid-ui.ts';
25
+ export * from './candid-core.ts';
26
+ export * as IDL from './idl.ts';
27
+ export {
28
+ type GenericIdlFuncArgs,
29
+ type GenericIdlFuncRets,
30
+ type GenericIdlServiceFields,
31
+ } from './idl.ts';
32
+ export * from './utils/hash.ts';
33
+ export * from './utils/leb128.ts';
34
+ export * from './utils/buffer.ts';
35
+ export * from './types.ts';
@@ -0,0 +1,7 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-object-type */
2
+
3
+ export interface JsonArray extends Array<JsonValue> {}
4
+
5
+ export interface JsonObject extends Record<string, JsonValue> {}
6
+
7
+ export type JsonValue = boolean | string | number | bigint | JsonArray | JsonObject;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Equivalent to `Math.log2(n)` with support for `BigInt` values
3
+ * @param n bigint or integer
4
+ * @returns integer
5
+ */
6
+ export function ilog2(n: bigint | number): number {
7
+ const nBig = BigInt(n);
8
+ if (n <= 0) {
9
+ throw new RangeError('Input must be positive');
10
+ }
11
+ return nBig.toString(2).length - 1;
12
+ }
13
+
14
+ /**
15
+ * Equivalent to `2 ** n` with support for `BigInt` values
16
+ * (necessary for browser preprocessors which replace the `**` operator with `Math.pow`)
17
+ * @param n bigint or integer
18
+ * @returns bigint
19
+ */
20
+ export function iexp2(n: bigint | number): bigint {
21
+ const nBig = BigInt(n);
22
+ if (n < 0) {
23
+ throw new RangeError('Input must be non-negative');
24
+ }
25
+ return BigInt(1) << nBig;
26
+ }
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Concatenate multiple Uint8Arrays.
3
+ * @param uint8Arrays The Uint8Arrays to concatenate.
4
+ */
5
+ export function concat(...uint8Arrays: Uint8Array[]): Uint8Array {
6
+ const result = new Uint8Array(uint8Arrays.reduce((acc, curr) => acc + curr.byteLength, 0));
7
+ let index = 0;
8
+ for (const b of uint8Arrays) {
9
+ result.set(b, index);
10
+ index += b.byteLength;
11
+ }
12
+ return result;
13
+ }
14
+
15
+ /**
16
+ * A class that abstracts a pipe-like Uint8Array.
17
+ */
18
+ export class PipeArrayBuffer {
19
+ /**
20
+ * The reading view. It's a sliding window as we read and write, pointing to the buffer.
21
+ * @private
22
+ */
23
+ private _view: Uint8Array;
24
+
25
+ /**
26
+ * Save a checkpoint of the reading view (for backtracking)
27
+ */
28
+ public save(): Uint8Array {
29
+ return this._view;
30
+ }
31
+
32
+ /**
33
+ * Restore a checkpoint of the reading view (for backtracking)
34
+ * @param checkPoint a previously saved checkpoint
35
+ */
36
+ public restore(checkPoint: Uint8Array) {
37
+ if (!(checkPoint instanceof Uint8Array)) {
38
+ throw new Error('Checkpoint must be a Uint8Array');
39
+ }
40
+ this._view = checkPoint;
41
+ }
42
+
43
+ /**
44
+ * The actual buffer containing the bytes.
45
+ * @private
46
+ */
47
+ private _buffer: Uint8Array;
48
+
49
+ /**
50
+ * Creates a new instance of a pipe
51
+ * @param buffer an optional buffer to start with
52
+ * @param length an optional amount of bytes to use for the length.
53
+ */
54
+ constructor(buffer?: Uint8Array, length = buffer?.byteLength || 0) {
55
+ if (buffer && !(buffer instanceof Uint8Array)) {
56
+ try {
57
+ buffer = uint8FromBufLike(buffer);
58
+ } catch {
59
+ throw new Error('Buffer must be a Uint8Array');
60
+ }
61
+ }
62
+ if (length < 0 || !Number.isInteger(length)) {
63
+ throw new Error('Length must be a non-negative integer');
64
+ }
65
+ if (buffer && length > buffer.byteLength) {
66
+ throw new Error('Length cannot exceed buffer length');
67
+ }
68
+ this._buffer = buffer || new Uint8Array(0);
69
+ this._view = new Uint8Array(this._buffer.buffer, 0, length);
70
+ }
71
+
72
+ get buffer(): Uint8Array {
73
+ // Return a copy of the buffer.
74
+ return this._view.slice();
75
+ }
76
+
77
+ get byteLength(): number {
78
+ return this._view.byteLength;
79
+ }
80
+
81
+ /**
82
+ * Read `num` number of bytes from the front of the pipe.
83
+ * @param num The number of bytes to read.
84
+ */
85
+ public read(num: number): Uint8Array {
86
+ const result = this._view.subarray(0, num);
87
+ this._view = this._view.subarray(num);
88
+ return result.slice();
89
+ }
90
+
91
+ public readUint8(): number | undefined {
92
+ if (this._view.byteLength === 0) {
93
+ return undefined;
94
+ }
95
+ const result = this._view[0];
96
+ this._view = this._view.subarray(1);
97
+ return result;
98
+ }
99
+
100
+ /**
101
+ * Write a buffer to the end of the pipe.
102
+ * @param buf The bytes to write.
103
+ */
104
+ public write(buf: Uint8Array): void {
105
+ if (!(buf instanceof Uint8Array)) {
106
+ throw new Error('Buffer must be a Uint8Array');
107
+ }
108
+ const offset = this._view.byteLength;
109
+ if (this._view.byteOffset + this._view.byteLength + buf.byteLength >= this._buffer.byteLength) {
110
+ // Alloc grow the view to include the new bytes.
111
+ this.alloc(buf.byteLength);
112
+ } else {
113
+ // Update the view to include the new bytes.
114
+ this._view = new Uint8Array(
115
+ this._buffer.buffer,
116
+ this._view.byteOffset,
117
+ this._view.byteLength + buf.byteLength,
118
+ );
119
+ }
120
+
121
+ this._view.set(buf, offset);
122
+ }
123
+
124
+ /**
125
+ * Whether or not there is more data to read from the buffer
126
+ */
127
+ public get end(): boolean {
128
+ return this._view.byteLength === 0;
129
+ }
130
+
131
+ /**
132
+ * Allocate a fixed amount of memory in the buffer. This does not affect the view.
133
+ * @param amount A number of bytes to add to the buffer.
134
+ */
135
+ public alloc(amount: number) {
136
+ if (amount <= 0 || !Number.isInteger(amount)) {
137
+ throw new Error('Amount must be a positive integer');
138
+ }
139
+ // Add a little bit of exponential growth.
140
+ const b = new Uint8Array(((this._buffer.byteLength + amount) * 1.2) | 0);
141
+ const v = new Uint8Array(b.buffer, 0, this._view.byteLength + amount);
142
+ v.set(this._view);
143
+ this._buffer = b;
144
+ this._view = v;
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Returns a true Uint8Array from an ArrayBufferLike object.
150
+ * @param bufLike a buffer-like object
151
+ * @returns Uint8Array
152
+ */
153
+ export function uint8FromBufLike(
154
+ bufLike:
155
+ | ArrayBuffer
156
+ | Uint8Array
157
+ | DataView
158
+ | ArrayBufferView
159
+ | ArrayBufferLike
160
+ | [number]
161
+ | number[]
162
+ | { buffer: ArrayBuffer },
163
+ ): Uint8Array {
164
+ if (!bufLike) {
165
+ throw new Error('Input cannot be null or undefined');
166
+ }
167
+
168
+ if (bufLike instanceof Uint8Array) {
169
+ return bufLike;
170
+ }
171
+ if (bufLike instanceof ArrayBuffer) {
172
+ return new Uint8Array(bufLike);
173
+ }
174
+ if (Array.isArray(bufLike)) {
175
+ return new Uint8Array(bufLike);
176
+ }
177
+ if ('buffer' in bufLike) {
178
+ return uint8FromBufLike(bufLike.buffer);
179
+ }
180
+ return new Uint8Array(bufLike);
181
+ }
182
+
183
+ /**
184
+ *
185
+ * @param u1 uint8Array 1
186
+ * @param u2 uint8Array 2
187
+ * @returns number - negative if u1 < u2, positive if u1 > u2, 0 if u1 === u2
188
+ */
189
+ export function compare(u1: Uint8Array, u2: Uint8Array): number {
190
+ if (u1.byteLength !== u2.byteLength) {
191
+ return u1.byteLength - u2.byteLength;
192
+ }
193
+ for (let i = 0; i < u1.length; i++) {
194
+ if (u1[i] !== u2[i]) {
195
+ return u1[i] - u2[i];
196
+ }
197
+ }
198
+ return 0;
199
+ }
200
+
201
+ /**
202
+ * Checks two uint8Arrays for equality.
203
+ * @param u1 uint8Array 1
204
+ * @param u2 uint8Array 2
205
+ * @returns boolean
206
+ */
207
+ export function uint8Equals(u1: Uint8Array, u2: Uint8Array): boolean {
208
+ return compare(u1, u2) === 0;
209
+ }
210
+
211
+ /**
212
+ * Helpers to convert a Uint8Array to a DataView.
213
+ * @param uint8 Uint8Array
214
+ * @returns DataView
215
+ */
216
+ export function uint8ToDataView(uint8: Uint8Array): DataView {
217
+ if (!(uint8 instanceof Uint8Array)) {
218
+ throw new Error('Input must be a Uint8Array');
219
+ }
220
+ return new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength);
221
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Hashes a string to a number. Algorithm can be found here:
3
+ * https://caml.inria.fr/pub/papers/garrigue-polymorphic_variants-ml98.pdf
4
+ * @param s - string to hash
5
+ * @returns number representing hashed string
6
+ */
7
+ function idlHash(s: string): number {
8
+ const utf8encoder = new TextEncoder();
9
+ const array = utf8encoder.encode(s);
10
+
11
+ let h = 0;
12
+ for (const c of array) {
13
+ h = (h * 223 + c) % 2 ** 32;
14
+ }
15
+ return h;
16
+ }
17
+
18
+ /**
19
+ *
20
+ * @param label string
21
+ * @returns number representing hashed label
22
+ */
23
+ export function idlLabelToId(label: string): number {
24
+ if (/^_\d+_$/.test(label) || /^_0x[0-9a-fA-F]+_$/.test(label)) {
25
+ const num = +label.slice(1, -1);
26
+ if (Number.isSafeInteger(num) && num >= 0 && num < 2 ** 32) {
27
+ return num;
28
+ }
29
+ }
30
+ return idlHash(label);
31
+ }
@@ -0,0 +1,234 @@
1
+ // Note: this file uses buffer-pipe, which on Node only, uses the Node Buffer
2
+ // implementation, which isn't compatible with the NPM buffer package
3
+ // which we use everywhere else. This means that we have to transform
4
+ // one into the other, hence why every function that returns a Buffer
5
+ // actually return `new Buffer(pipe.buffer)`.
6
+ // TODO: The best solution would be to have our own buffer type around
7
+ // Uint8Array which is standard.
8
+ import { PipeArrayBuffer as Pipe } from './buffer.ts';
9
+ import { ilog2 } from './bigint-math.ts';
10
+
11
+ function eob(): never {
12
+ throw new Error('unexpected end of buffer');
13
+ }
14
+
15
+ /**
16
+ *
17
+ * @param pipe Pipe from buffer-pipe
18
+ * @param num number
19
+ * @returns Uint8Array
20
+ */
21
+ export function safeRead(pipe: Pipe, num: number): Uint8Array {
22
+ if (pipe.byteLength < num) {
23
+ eob();
24
+ }
25
+ return pipe.read(num);
26
+ }
27
+
28
+ /**
29
+ * @param pipe - PipeArrayBuffer simulating buffer-pipe api
30
+ */
31
+ export function safeReadUint8(pipe: Pipe): number {
32
+ const byte = pipe.readUint8();
33
+ if (byte === undefined) {
34
+ eob();
35
+ }
36
+ return byte;
37
+ }
38
+
39
+ /**
40
+ * Encode a positive number (or bigint) into a Buffer. The number will be floored to the
41
+ * nearest integer.
42
+ * @param value The number to encode.
43
+ */
44
+ export function lebEncode(value: bigint | number): Uint8Array {
45
+ if (typeof value === 'number') {
46
+ value = BigInt(value);
47
+ }
48
+
49
+ if (value < BigInt(0)) {
50
+ throw new Error('Cannot leb encode negative values.');
51
+ }
52
+
53
+ const byteLength = (value === BigInt(0) ? 0 : ilog2(value)) + 1;
54
+ const pipe = new Pipe(new Uint8Array(byteLength), 0);
55
+ while (true) {
56
+ const i = Number(value & BigInt(0x7f));
57
+ value /= BigInt(0x80);
58
+ if (value === BigInt(0)) {
59
+ pipe.write(new Uint8Array([i]));
60
+ break;
61
+ } else {
62
+ pipe.write(new Uint8Array([i | 0x80]));
63
+ }
64
+ }
65
+
66
+ return pipe.buffer;
67
+ }
68
+
69
+ /**
70
+ * Decode a leb encoded buffer into a bigint. The number will always be positive (does not
71
+ * support signed leb encoding).
72
+ * @param pipe A Buffer containing the leb encoded bits.
73
+ */
74
+ export function lebDecode(pipe: Pipe): bigint {
75
+ let weight = BigInt(1);
76
+ let value = BigInt(0);
77
+ let byte;
78
+
79
+ do {
80
+ byte = safeReadUint8(pipe);
81
+ value += BigInt(byte & 0x7f).valueOf() * weight;
82
+ weight *= BigInt(128);
83
+ } while (byte >= 0x80);
84
+
85
+ return value;
86
+ }
87
+
88
+ /**
89
+ * Encode a number (or bigint) into a Buffer, with support for negative numbers. The number
90
+ * will be floored to the nearest integer.
91
+ * @param value The number to encode.
92
+ */
93
+ export function slebEncode(value: bigint | number): Uint8Array {
94
+ if (typeof value === 'number') {
95
+ value = BigInt(value);
96
+ }
97
+
98
+ const isNeg = value < BigInt(0);
99
+ if (isNeg) {
100
+ value = -value - BigInt(1);
101
+ }
102
+ const byteLength = (value === BigInt(0) ? 0 : ilog2(value)) + 1;
103
+ const pipe = new Pipe(new Uint8Array(byteLength), 0);
104
+ while (true) {
105
+ const i = getLowerBytes(value);
106
+ value /= BigInt(0x80);
107
+
108
+ // prettier-ignore
109
+ if ( ( isNeg && value === BigInt(0) && (i & 0x40) !== 0)
110
+ || (!isNeg && value === BigInt(0) && (i & 0x40) === 0)) {
111
+ pipe.write(new Uint8Array([i]));
112
+ break;
113
+ } else {
114
+ pipe.write(new Uint8Array([i | 0x80]));
115
+ }
116
+ }
117
+
118
+ function getLowerBytes(num: bigint): number {
119
+ const bytes = num % BigInt(0x80);
120
+ if (isNeg) {
121
+ // We swap the bits here again, and remove 1 to do two's complement.
122
+ return Number(BigInt(0x80) - bytes - BigInt(1));
123
+ } else {
124
+ return Number(bytes);
125
+ }
126
+ }
127
+ return pipe.buffer;
128
+ }
129
+
130
+ /**
131
+ * Decode a leb encoded buffer into a bigint. The number is decoded with support for negative
132
+ * signed-leb encoding.
133
+ * @param pipe A Buffer containing the signed leb encoded bits.
134
+ */
135
+ export function slebDecode(pipe: Pipe): bigint {
136
+ // Get the size of the buffer, then cut a buffer of that size.
137
+ const pipeView = new Uint8Array(pipe.buffer);
138
+ let len = 0;
139
+ for (; len < pipeView.byteLength; len++) {
140
+ if (pipeView[len] < 0x80) {
141
+ // If it's a positive number, we reuse lebDecode.
142
+ if ((pipeView[len] & 0x40) === 0) {
143
+ return lebDecode(pipe);
144
+ }
145
+ break;
146
+ }
147
+ }
148
+
149
+ const bytes = new Uint8Array(safeRead(pipe, len + 1));
150
+ let value = BigInt(0);
151
+ for (let i = bytes.byteLength - 1; i >= 0; i--) {
152
+ value = value * BigInt(0x80) + BigInt(0x80 - (bytes[i] & 0x7f) - 1);
153
+ }
154
+ return -value - BigInt(1);
155
+ }
156
+
157
+ /**
158
+ *
159
+ * @param value bigint or number
160
+ * @param byteLength number
161
+ * @returns Uint8Array
162
+ */
163
+ export function writeUIntLE(value: bigint | number, byteLength: number): Uint8Array {
164
+ if (BigInt(value) < BigInt(0)) {
165
+ throw new Error('Cannot write negative values.');
166
+ }
167
+ return writeIntLE(value, byteLength);
168
+ }
169
+
170
+ /**
171
+ *
172
+ * @param value - bigint or number
173
+ * @param byteLength - number
174
+ * @returns Uint8Array
175
+ */
176
+ export function writeIntLE(value: bigint | number, byteLength: number): Uint8Array {
177
+ value = BigInt(value);
178
+
179
+ const pipe = new Pipe(new Uint8Array(Math.min(1, byteLength)), 0);
180
+ let i = 0;
181
+ let mul = BigInt(256);
182
+ let sub = BigInt(0);
183
+ let byte = Number(value % mul);
184
+ pipe.write(new Uint8Array([byte]));
185
+ while (++i < byteLength) {
186
+ if (value < 0 && sub === BigInt(0) && byte !== 0) {
187
+ sub = BigInt(1);
188
+ }
189
+ byte = Number((value / mul - sub) % BigInt(256));
190
+ pipe.write(new Uint8Array([byte]));
191
+ mul *= BigInt(256);
192
+ }
193
+
194
+ return pipe.buffer;
195
+ }
196
+
197
+ /**
198
+ *
199
+ * @param pipe Pipe from buffer-pipe
200
+ * @param byteLength number
201
+ * @returns bigint
202
+ */
203
+ export function readUIntLE(pipe: Pipe, byteLength: number): bigint {
204
+ if (byteLength <= 0 || !Number.isInteger(byteLength)) {
205
+ throw new Error('Byte length must be a positive integer');
206
+ }
207
+ let val = BigInt(safeReadUint8(pipe));
208
+ let mul = BigInt(1);
209
+ let i = 0;
210
+ while (++i < byteLength) {
211
+ mul *= BigInt(256);
212
+ const byte = BigInt(safeReadUint8(pipe));
213
+ val = val + mul * byte;
214
+ }
215
+ return val;
216
+ }
217
+
218
+ /**
219
+ *
220
+ * @param pipe Pipe from buffer-pipe
221
+ * @param byteLength number
222
+ * @returns bigint
223
+ */
224
+ export function readIntLE(pipe: Pipe, byteLength: number): bigint {
225
+ if (byteLength <= 0 || !Number.isInteger(byteLength)) {
226
+ throw new Error('Byte length must be a positive integer');
227
+ }
228
+ let val = readUIntLE(pipe, byteLength);
229
+ const mul = BigInt(2) ** (BigInt(8) * BigInt(byteLength - 1) + BigInt(7));
230
+ if (val >= mul) {
231
+ val -= mul * BigInt(2);
232
+ }
233
+ return val;
234
+ }