@icp-sdk/core 5.0.0 → 5.1.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 (286) hide show
  1. package/lib/cjs/agent/actor.d.ts +15 -1
  2. package/lib/cjs/agent/actor.d.ts.map +1 -1
  3. package/lib/cjs/agent/actor.js +37 -91
  4. package/lib/cjs/agent/actor.js.map +1 -1
  5. package/lib/cjs/agent/agent/api.d.ts +29 -6
  6. package/lib/cjs/agent/agent/api.d.ts.map +1 -1
  7. package/lib/cjs/agent/agent/api.js.map +1 -1
  8. package/lib/cjs/agent/agent/http/expiry.d.ts +36 -0
  9. package/lib/cjs/agent/agent/http/expiry.d.ts.map +1 -0
  10. package/lib/cjs/agent/agent/http/expiry.js +92 -0
  11. package/lib/cjs/agent/agent/http/expiry.js.map +1 -0
  12. package/lib/cjs/agent/agent/http/index.d.ts +11 -2
  13. package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
  14. package/lib/cjs/agent/agent/http/index.js +142 -73
  15. package/lib/cjs/agent/agent/http/index.js.map +1 -1
  16. package/lib/cjs/agent/agent/http/transforms.d.ts +1 -35
  17. package/lib/cjs/agent/agent/http/transforms.d.ts.map +1 -1
  18. package/lib/cjs/agent/agent/http/transforms.js +6 -90
  19. package/lib/cjs/agent/agent/http/transforms.js.map +1 -1
  20. package/lib/cjs/agent/agent/http/types.d.ts +1 -1
  21. package/lib/cjs/agent/agent/http/types.d.ts.map +1 -1
  22. package/lib/cjs/agent/auth.d.ts +1 -1
  23. package/lib/cjs/agent/auth.d.ts.map +1 -1
  24. package/lib/cjs/agent/canisterStatus/index.d.ts +5 -4
  25. package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
  26. package/lib/cjs/agent/canisterStatus/index.js +6 -10
  27. package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
  28. package/lib/cjs/agent/cbor.js +2 -2
  29. package/lib/cjs/agent/cbor.js.map +1 -1
  30. package/lib/cjs/agent/certificate.d.ts +4 -4
  31. package/lib/cjs/agent/certificate.d.ts.map +1 -1
  32. package/lib/cjs/agent/certificate.js +6 -10
  33. package/lib/cjs/agent/certificate.js.map +1 -1
  34. package/lib/cjs/agent/constants.d.ts +4 -4
  35. package/lib/cjs/agent/constants.d.ts.map +1 -1
  36. package/lib/cjs/agent/der.d.ts.map +1 -1
  37. package/lib/cjs/agent/der.js +26 -21
  38. package/lib/cjs/agent/der.js.map +1 -1
  39. package/lib/cjs/agent/errors.d.ts +27 -18
  40. package/lib/cjs/agent/errors.d.ts.map +1 -1
  41. package/lib/cjs/agent/errors.js +18 -15
  42. package/lib/cjs/agent/errors.js.map +1 -1
  43. package/lib/cjs/agent/observable.d.ts +1 -1
  44. package/lib/cjs/agent/observable.d.ts.map +1 -1
  45. package/lib/cjs/agent/polling/backoff.d.ts +7 -7
  46. package/lib/cjs/agent/polling/backoff.d.ts.map +1 -1
  47. package/lib/cjs/agent/polling/backoff.js +3 -5
  48. package/lib/cjs/agent/polling/backoff.js.map +1 -1
  49. package/lib/cjs/agent/polling/index.d.ts +11 -10
  50. package/lib/cjs/agent/polling/index.d.ts.map +1 -1
  51. package/lib/cjs/agent/polling/index.js +8 -6
  52. package/lib/cjs/agent/polling/index.js.map +1 -1
  53. package/lib/cjs/agent/polling/strategy.d.ts +2 -5
  54. package/lib/cjs/agent/polling/strategy.d.ts.map +1 -1
  55. package/lib/cjs/agent/polling/strategy.js.map +1 -1
  56. package/lib/cjs/agent/polling/types.d.ts +18 -0
  57. package/lib/cjs/agent/polling/types.d.ts.map +1 -0
  58. package/lib/cjs/agent/polling/types.js +3 -0
  59. package/lib/cjs/agent/polling/types.js.map +1 -0
  60. package/lib/cjs/agent/public_key.d.ts +1 -1
  61. package/lib/cjs/agent/public_key.d.ts.map +1 -1
  62. package/lib/cjs/agent/request_id.d.ts.map +1 -1
  63. package/lib/cjs/agent/request_id.js +7 -7
  64. package/lib/cjs/agent/request_id.js.map +1 -1
  65. package/lib/cjs/agent/subnetStatus/index.d.ts +5 -4
  66. package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -1
  67. package/lib/cjs/agent/subnetStatus/index.js +6 -10
  68. package/lib/cjs/agent/subnetStatus/index.js.map +1 -1
  69. package/lib/cjs/agent/utils/buffer.d.ts.map +1 -1
  70. package/lib/cjs/agent/utils/buffer.js +4 -2
  71. package/lib/cjs/agent/utils/buffer.js.map +1 -1
  72. package/lib/cjs/agent/utils/certificateReject.d.ts +11 -0
  73. package/lib/cjs/agent/utils/certificateReject.d.ts.map +1 -0
  74. package/lib/cjs/agent/utils/certificateReject.js +19 -0
  75. package/lib/cjs/agent/utils/certificateReject.js.map +1 -0
  76. package/lib/cjs/agent/utils/expirableMap.d.ts +4 -4
  77. package/lib/cjs/agent/utils/expirableMap.d.ts.map +1 -1
  78. package/lib/cjs/agent/utils/expirableMap.js +2 -2
  79. package/lib/cjs/agent/utils/readState.d.ts +3 -3
  80. package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
  81. package/lib/cjs/candid/candid-core.d.ts +1 -1
  82. package/lib/cjs/candid/candid-core.d.ts.map +1 -1
  83. package/lib/cjs/candid/candid-core.js +7 -9
  84. package/lib/cjs/candid/candid-core.js.map +1 -1
  85. package/lib/cjs/candid/candid-ui.d.ts.map +1 -1
  86. package/lib/cjs/candid/candid-ui.js +8 -24
  87. package/lib/cjs/candid/candid-ui.js.map +1 -1
  88. package/lib/cjs/candid/idl.d.ts +14 -1
  89. package/lib/cjs/candid/idl.d.ts.map +1 -1
  90. package/lib/cjs/candid/idl.js +164 -125
  91. package/lib/cjs/candid/idl.js.map +1 -1
  92. package/lib/cjs/candid/utils/leb128.d.ts.map +1 -1
  93. package/lib/cjs/candid/utils/leb128.js +1 -3
  94. package/lib/cjs/candid/utils/leb128.js.map +1 -1
  95. package/lib/cjs/identity/identity/delegation.d.ts +4 -3
  96. package/lib/cjs/identity/identity/delegation.d.ts.map +1 -1
  97. package/lib/cjs/identity/identity/delegation.js +3 -3
  98. package/lib/cjs/identity/identity/delegation.js.map +1 -1
  99. package/lib/cjs/identity/identity/ecdsa.d.ts +2 -2
  100. package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -1
  101. package/lib/cjs/identity/identity/ecdsa.js +2 -4
  102. package/lib/cjs/identity/identity/ecdsa.js.map +1 -1
  103. package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -1
  104. package/lib/cjs/identity/identity/ed25519.js +9 -10
  105. package/lib/cjs/identity/identity/ed25519.js.map +1 -1
  106. package/lib/cjs/identity/identity/partial.d.ts +1 -1
  107. package/lib/cjs/identity/identity/partial.d.ts.map +1 -1
  108. package/lib/cjs/identity/identity/webauthn.js +4 -5
  109. package/lib/cjs/identity/identity/webauthn.js.map +1 -1
  110. package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -1
  111. package/lib/cjs/identity/secp256k1/der.js +27 -22
  112. package/lib/cjs/identity/secp256k1/der.js.map +1 -1
  113. package/lib/cjs/identity/secp256k1/pem.js +1 -1
  114. package/lib/cjs/identity/secp256k1/pem.js.map +1 -1
  115. package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -1
  116. package/lib/cjs/identity/secp256k1/secp256k1.js +6 -6
  117. package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -1
  118. package/lib/cjs/principal/principal.d.ts +2 -2
  119. package/lib/cjs/principal/principal.d.ts.map +1 -1
  120. package/lib/cjs/principal/principal.js +10 -6
  121. package/lib/cjs/principal/principal.js.map +1 -1
  122. package/lib/esm/agent/actor.d.ts +15 -1
  123. package/lib/esm/agent/actor.d.ts.map +1 -1
  124. package/lib/esm/agent/actor.js +40 -94
  125. package/lib/esm/agent/actor.js.map +1 -1
  126. package/lib/esm/agent/agent/api.d.ts +29 -6
  127. package/lib/esm/agent/agent/api.d.ts.map +1 -1
  128. package/lib/esm/agent/agent/api.js.map +1 -1
  129. package/lib/esm/agent/agent/http/expiry.d.ts +36 -0
  130. package/lib/esm/agent/agent/http/expiry.d.ts.map +1 -0
  131. package/lib/esm/agent/agent/http/expiry.js +88 -0
  132. package/lib/esm/agent/agent/http/expiry.js.map +1 -0
  133. package/lib/esm/agent/agent/http/index.d.ts +11 -2
  134. package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
  135. package/lib/esm/agent/agent/http/index.js +145 -76
  136. package/lib/esm/agent/agent/http/index.js.map +1 -1
  137. package/lib/esm/agent/agent/http/transforms.d.ts +1 -35
  138. package/lib/esm/agent/agent/http/transforms.d.ts.map +1 -1
  139. package/lib/esm/agent/agent/http/transforms.js +2 -87
  140. package/lib/esm/agent/agent/http/transforms.js.map +1 -1
  141. package/lib/esm/agent/agent/http/types.d.ts +1 -1
  142. package/lib/esm/agent/agent/http/types.d.ts.map +1 -1
  143. package/lib/esm/agent/auth.d.ts +1 -1
  144. package/lib/esm/agent/auth.d.ts.map +1 -1
  145. package/lib/esm/agent/canister-env/index.d.ts +2 -2
  146. package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
  147. package/lib/esm/agent/canisterStatus/index.d.ts +5 -4
  148. package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
  149. package/lib/esm/agent/canisterStatus/index.js +6 -10
  150. package/lib/esm/agent/canisterStatus/index.js.map +1 -1
  151. package/lib/esm/agent/cbor.js +1 -1
  152. package/lib/esm/agent/cbor.js.map +1 -1
  153. package/lib/esm/agent/certificate.d.ts +4 -4
  154. package/lib/esm/agent/certificate.d.ts.map +1 -1
  155. package/lib/esm/agent/certificate.js +6 -10
  156. package/lib/esm/agent/certificate.js.map +1 -1
  157. package/lib/esm/agent/constants.d.ts +4 -4
  158. package/lib/esm/agent/constants.d.ts.map +1 -1
  159. package/lib/esm/agent/der.d.ts.map +1 -1
  160. package/lib/esm/agent/der.js +26 -21
  161. package/lib/esm/agent/der.js.map +1 -1
  162. package/lib/esm/agent/errors.d.ts +27 -18
  163. package/lib/esm/agent/errors.d.ts.map +1 -1
  164. package/lib/esm/agent/errors.js +16 -13
  165. package/lib/esm/agent/errors.js.map +1 -1
  166. package/lib/esm/agent/observable.d.ts +1 -1
  167. package/lib/esm/agent/observable.d.ts.map +1 -1
  168. package/lib/esm/agent/polling/backoff.d.ts +7 -7
  169. package/lib/esm/agent/polling/backoff.d.ts.map +1 -1
  170. package/lib/esm/agent/polling/backoff.js +3 -5
  171. package/lib/esm/agent/polling/backoff.js.map +1 -1
  172. package/lib/esm/agent/polling/index.d.ts +11 -10
  173. package/lib/esm/agent/polling/index.d.ts.map +1 -1
  174. package/lib/esm/agent/polling/index.js +9 -7
  175. package/lib/esm/agent/polling/index.js.map +1 -1
  176. package/lib/esm/agent/polling/strategy.d.ts +2 -5
  177. package/lib/esm/agent/polling/strategy.d.ts.map +1 -1
  178. package/lib/esm/agent/polling/strategy.js.map +1 -1
  179. package/lib/esm/agent/polling/types.d.ts +18 -0
  180. package/lib/esm/agent/polling/types.d.ts.map +1 -0
  181. package/lib/esm/agent/polling/types.js +2 -0
  182. package/lib/esm/agent/polling/types.js.map +1 -0
  183. package/lib/esm/agent/public_key.d.ts +1 -1
  184. package/lib/esm/agent/public_key.d.ts.map +1 -1
  185. package/lib/esm/agent/request_id.d.ts.map +1 -1
  186. package/lib/esm/agent/request_id.js +7 -7
  187. package/lib/esm/agent/request_id.js.map +1 -1
  188. package/lib/esm/agent/subnetStatus/index.d.ts +5 -4
  189. package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -1
  190. package/lib/esm/agent/subnetStatus/index.js +6 -10
  191. package/lib/esm/agent/subnetStatus/index.js.map +1 -1
  192. package/lib/esm/agent/utils/buffer.d.ts.map +1 -1
  193. package/lib/esm/agent/utils/buffer.js +4 -2
  194. package/lib/esm/agent/utils/buffer.js.map +1 -1
  195. package/lib/esm/agent/utils/certificateReject.d.ts +11 -0
  196. package/lib/esm/agent/utils/certificateReject.d.ts.map +1 -0
  197. package/lib/esm/agent/utils/certificateReject.js +16 -0
  198. package/lib/esm/agent/utils/certificateReject.js.map +1 -0
  199. package/lib/esm/agent/utils/expirableMap.d.ts +4 -4
  200. package/lib/esm/agent/utils/expirableMap.d.ts.map +1 -1
  201. package/lib/esm/agent/utils/expirableMap.js +2 -2
  202. package/lib/esm/agent/utils/readState.d.ts +3 -3
  203. package/lib/esm/agent/utils/readState.d.ts.map +1 -1
  204. package/lib/esm/candid/candid-core.d.ts +1 -1
  205. package/lib/esm/candid/candid-core.d.ts.map +1 -1
  206. package/lib/esm/candid/candid-core.js +7 -9
  207. package/lib/esm/candid/candid-core.js.map +1 -1
  208. package/lib/esm/candid/candid-ui.d.ts.map +1 -1
  209. package/lib/esm/candid/candid-ui.js +7 -23
  210. package/lib/esm/candid/candid-ui.js.map +1 -1
  211. package/lib/esm/candid/idl.d.ts +14 -1
  212. package/lib/esm/candid/idl.d.ts.map +1 -1
  213. package/lib/esm/candid/idl.js +162 -124
  214. package/lib/esm/candid/idl.js.map +1 -1
  215. package/lib/esm/candid/utils/leb128.d.ts.map +1 -1
  216. package/lib/esm/candid/utils/leb128.js +1 -3
  217. package/lib/esm/candid/utils/leb128.js.map +1 -1
  218. package/lib/esm/identity/identity/delegation.d.ts +4 -3
  219. package/lib/esm/identity/identity/delegation.d.ts.map +1 -1
  220. package/lib/esm/identity/identity/delegation.js +3 -3
  221. package/lib/esm/identity/identity/delegation.js.map +1 -1
  222. package/lib/esm/identity/identity/ecdsa.d.ts +2 -2
  223. package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -1
  224. package/lib/esm/identity/identity/ecdsa.js +2 -4
  225. package/lib/esm/identity/identity/ecdsa.js.map +1 -1
  226. package/lib/esm/identity/identity/ed25519.d.ts.map +1 -1
  227. package/lib/esm/identity/identity/ed25519.js +9 -10
  228. package/lib/esm/identity/identity/ed25519.js.map +1 -1
  229. package/lib/esm/identity/identity/partial.d.ts +1 -1
  230. package/lib/esm/identity/identity/partial.d.ts.map +1 -1
  231. package/lib/esm/identity/identity/webauthn.js +4 -5
  232. package/lib/esm/identity/identity/webauthn.js.map +1 -1
  233. package/lib/esm/identity/secp256k1/der.d.ts.map +1 -1
  234. package/lib/esm/identity/secp256k1/der.js +27 -22
  235. package/lib/esm/identity/secp256k1/der.js.map +1 -1
  236. package/lib/esm/identity/secp256k1/pem.js +1 -1
  237. package/lib/esm/identity/secp256k1/pem.js.map +1 -1
  238. package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -1
  239. package/lib/esm/identity/secp256k1/secp256k1.js +6 -6
  240. package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -1
  241. package/lib/esm/principal/principal.d.ts +2 -2
  242. package/lib/esm/principal/principal.d.ts.map +1 -1
  243. package/lib/esm/principal/principal.js +10 -6
  244. package/lib/esm/principal/principal.js.map +1 -1
  245. package/package.json +13 -13
  246. package/src/agent/actor.ts +74 -126
  247. package/src/agent/agent/api.ts +36 -6
  248. package/src/agent/agent/http/expiry.ts +107 -0
  249. package/src/agent/agent/http/index.ts +217 -90
  250. package/src/agent/agent/http/transforms.ts +2 -106
  251. package/src/agent/agent/http/types.ts +1 -1
  252. package/src/agent/auth.ts +1 -1
  253. package/src/agent/canister-env/index.ts +2 -2
  254. package/src/agent/canisterStatus/index.ts +10 -12
  255. package/src/agent/cbor.ts +1 -1
  256. package/src/agent/certificate.ts +11 -13
  257. package/src/agent/der.ts +40 -19
  258. package/src/agent/errors.ts +41 -31
  259. package/src/agent/fetch_candid.ts +1 -1
  260. package/src/agent/observable.ts +1 -1
  261. package/src/agent/polling/backoff.ts +9 -10
  262. package/src/agent/polling/index.ts +14 -26
  263. package/src/agent/polling/strategy.ts +5 -9
  264. package/src/agent/polling/types.ts +28 -0
  265. package/src/agent/public_key.ts +1 -1
  266. package/src/agent/request_id.ts +15 -8
  267. package/src/agent/subnetStatus/index.ts +10 -12
  268. package/src/agent/utils/buffer.ts +6 -2
  269. package/src/agent/utils/certificateReject.ts +25 -0
  270. package/src/agent/utils/expirableMap.ts +4 -4
  271. package/src/agent/utils/random.ts +2 -2
  272. package/src/agent/utils/readState.ts +3 -3
  273. package/src/candid/candid-core.ts +9 -11
  274. package/src/candid/candid-ui.ts +8 -16
  275. package/src/candid/idl.ts +210 -112
  276. package/src/candid/utils/leb128.ts +1 -2
  277. package/src/identity/identity/delegation.ts +5 -5
  278. package/src/identity/identity/ecdsa.ts +12 -8
  279. package/src/identity/identity/ed25519.ts +16 -9
  280. package/src/identity/identity/partial.ts +1 -1
  281. package/src/identity/identity/webauthn.ts +21 -21
  282. package/src/identity/secp256k1/der.ts +41 -20
  283. package/src/identity/secp256k1/pem.ts +1 -1
  284. package/src/identity/secp256k1/secp256k1.ts +12 -6
  285. package/src/principal/principal.ts +18 -8
  286. package/LICENSE +0 -201
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Principal = exports.Nat64 = exports.Nat32 = exports.Nat16 = exports.Nat8 = exports.Int64 = exports.Int32 = exports.Int16 = exports.Int8 = exports.Float64 = exports.Float32 = exports.Nat = exports.Int = exports.Text = exports.Null = exports.Bool = exports.Unknown = exports.Reserved = exports.Empty = exports.ServiceClass = exports.FuncClass = exports.PrincipalClass = exports.RecClass = exports.VariantClass = exports.TupleClass = exports.RecordClass = exports.OptClass = exports.VecClass = exports.FixedNatClass = exports.FixedIntClass = exports.FloatClass = exports.NatClass = exports.IntClass = exports.TextClass = exports.ReservedClass = exports.NullClass = exports.BoolClass = exports.UnknownClass = exports.EmptyClass = exports.ConstructType = exports.PrimitiveType = exports.Type = exports.Visitor = void 0;
3
+ exports.Principal = exports.Nat64 = exports.Nat32 = exports.Nat16 = exports.Nat8 = exports.Int64 = exports.Int32 = exports.Int16 = exports.Int8 = exports.Float64 = exports.Float32 = exports.Nat = exports.Int = exports.Text = exports.Null = exports.Bool = exports.Unknown = exports.Reserved = exports.Empty = exports.ServiceClass = exports.FuncClass = exports.PrincipalClass = exports.RecClass = exports.VariantClass = exports.TupleClass = exports.RecordClass = exports.OptClass = exports.VecClass = exports.FixedNatClass = exports.FixedIntClass = exports.FloatClass = exports.NatClass = exports.IntClass = exports.TextClass = exports.ReservedClass = exports.NullClass = exports.BoolClass = exports.UnknownClass = exports.EmptyClass = exports.ConstructType = exports.PrimitiveType = exports.Type = exports.Visitor = exports.CandidDecodeError = void 0;
4
4
  exports.encode = encode;
5
5
  exports.decode = decode;
6
6
  exports.Tuple = Tuple;
@@ -25,6 +25,18 @@ const bigint_math_ts_1 = require("./utils/bigint-math.js");
25
25
  * between JavaScript values and IDL used by canisters on the Internet Computer,
26
26
  * as documented at https://github.com/dfinity/candid/blob/119703ba342d2fef6ab4972d2541b9fe36ae8e36/spec/Candid.md
27
27
  */
28
+ /**
29
+ * Error thrown when candid decoding fails due to a type mismatch
30
+ * between the expected and received types.
31
+ */
32
+ class CandidDecodeError extends Error {
33
+ constructor(message) {
34
+ super(message);
35
+ this.name = 'CandidDecodeError';
36
+ Object.setPrototypeOf(this, CandidDecodeError.prototype);
37
+ }
38
+ }
39
+ exports.CandidDecodeError = CandidDecodeError;
28
40
  var IDLTypeIds;
29
41
  (function (IDLTypeIds) {
30
42
  IDLTypeIds[IDLTypeIds["Null"] = -1] = "Null";
@@ -73,10 +85,10 @@ class TypeTable {
73
85
  const idx = this._idx.get(obj.name);
74
86
  const knotIdx = this._idx.get(knot);
75
87
  if (idx === undefined) {
76
- throw new Error('Missing type index for ' + obj);
88
+ throw new Error(`Missing type index for ${obj}`);
77
89
  }
78
90
  if (knotIdx === undefined) {
79
- throw new Error('Missing type index for ' + knot);
91
+ throw new Error(`Missing type index for ${knot}`);
80
92
  }
81
93
  // Point the recursive placeholder (obj) to the concrete type bytes
82
94
  this._typs[idx] = this._typs[knotIdx];
@@ -113,7 +125,7 @@ class TypeTable {
113
125
  }
114
126
  indexOf(typeName) {
115
127
  if (!this._idx.has(typeName)) {
116
- throw new Error('Missing type index for ' + typeName);
128
+ throw new Error(`Missing type index for ${typeName}`);
117
129
  }
118
130
  return (0, leb128_ts_1.slebEncode)(this._idx.get(typeName) || 0);
119
131
  }
@@ -243,7 +255,6 @@ class PrimitiveType extends Type {
243
255
  }
244
256
  _buildTypeTableImpl(_typeTable) {
245
257
  // No type table encoding for Primitive types.
246
- return;
247
258
  }
248
259
  }
249
260
  exports.PrimitiveType = PrimitiveType;
@@ -252,7 +263,7 @@ class ConstructType extends Type {
252
263
  if (t instanceof RecClass) {
253
264
  const ty = t.getType();
254
265
  if (typeof ty === 'undefined') {
255
- throw new Error('type mismatch with uninitialized type');
266
+ throw new CandidDecodeError('Type mismatch: cannot decode from uninitialized recursive type');
256
267
  }
257
268
  return ty;
258
269
  }
@@ -379,8 +390,9 @@ class BoolClass extends PrimitiveType {
379
390
  return v.visitBool(this, d);
380
391
  }
381
392
  covariant(x) {
382
- if (typeof x === 'boolean')
393
+ if (typeof x === 'boolean') {
383
394
  return true;
395
+ }
384
396
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
385
397
  }
386
398
  encodeValue(x) {
@@ -419,8 +431,9 @@ class NullClass extends PrimitiveType {
419
431
  return v.visitNull(this, d);
420
432
  }
421
433
  covariant(x) {
422
- if (x === null)
434
+ if (x === null) {
423
435
  return true;
436
+ }
424
437
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
425
438
  }
426
439
  encodeValue() {
@@ -485,8 +498,9 @@ class TextClass extends PrimitiveType {
485
498
  return v.visitText(this, d);
486
499
  }
487
500
  covariant(x) {
488
- if (typeof x === 'string')
501
+ if (typeof x === 'string') {
489
502
  return true;
503
+ }
490
504
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
491
505
  }
492
506
  encodeValue(x) {
@@ -508,7 +522,7 @@ class TextClass extends PrimitiveType {
508
522
  return 'text';
509
523
  }
510
524
  valueToString(x) {
511
- return '"' + x + '"';
525
+ return `"${x}"`;
512
526
  }
513
527
  }
514
528
  exports.TextClass = TextClass;
@@ -528,8 +542,9 @@ class IntClass extends PrimitiveType {
528
542
  covariant(x) {
529
543
  // We allow encoding of JavaScript plain numbers.
530
544
  // But we will always decode to bigint.
531
- if (typeof x === 'bigint' || Number.isInteger(x))
545
+ if (typeof x === 'bigint' || Number.isInteger(x)) {
532
546
  return true;
547
+ }
533
548
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
534
549
  }
535
550
  encodeValue(x) {
@@ -566,8 +581,9 @@ class NatClass extends PrimitiveType {
566
581
  covariant(x) {
567
582
  // We allow encoding of JavaScript plain numbers.
568
583
  // But we will always decode to bigint.
569
- if ((typeof x === 'bigint' && x >= BigInt(0)) || (Number.isInteger(x) && x >= 0))
584
+ if ((typeof x === 'bigint' && x >= BigInt(0)) || (Number.isInteger(x) && x >= 0)) {
570
585
  return true;
586
+ }
571
587
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
572
588
  }
573
589
  encodeValue(x) {
@@ -609,8 +625,9 @@ class FloatClass extends PrimitiveType {
609
625
  return v.visitFloat(this, d);
610
626
  }
611
627
  covariant(x) {
612
- if (typeof x === 'number' || x instanceof Number)
628
+ if (typeof x === 'number' || x instanceof Number) {
613
629
  return true;
630
+ }
614
631
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
615
632
  }
616
633
  encodeValue(x) {
@@ -635,12 +652,10 @@ class FloatClass extends PrimitiveType {
635
652
  if (this._bits === 32) {
636
653
  return view.getFloat32(0, true);
637
654
  }
638
- else {
639
- return view.getFloat64(0, true);
640
- }
655
+ return view.getFloat64(0, true);
641
656
  }
642
657
  get name() {
643
- return 'float' + this._bits;
658
+ return `float${this._bits}`;
644
659
  }
645
660
  valueToString(x) {
646
661
  return x.toString();
@@ -667,19 +682,17 @@ class FixedIntClass extends PrimitiveType {
667
682
  covariant(x) {
668
683
  const min = (0, bigint_math_ts_1.iexp2)(this._bits - 1) * BigInt(-1);
669
684
  const max = (0, bigint_math_ts_1.iexp2)(this._bits - 1) - BigInt(1);
670
- let ok = false;
671
685
  if (typeof x === 'bigint') {
672
- ok = x >= min && x <= max;
686
+ if (x >= min && x <= max) {
687
+ return true;
688
+ }
673
689
  }
674
690
  else if (Number.isInteger(x)) {
675
691
  const v = BigInt(x);
676
- ok = v >= min && v <= max;
677
- }
678
- else {
679
- ok = false;
692
+ if (v >= min && v <= max) {
693
+ return true;
694
+ }
680
695
  }
681
- if (ok)
682
- return true;
683
696
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
684
697
  }
685
698
  encodeValue(x) {
@@ -695,9 +708,7 @@ class FixedIntClass extends PrimitiveType {
695
708
  if (this._bits <= 32) {
696
709
  return Number(num);
697
710
  }
698
- else {
699
- return num;
700
- }
711
+ return num;
701
712
  }
702
713
  get name() {
703
714
  return `int${this._bits}`;
@@ -726,19 +737,17 @@ class FixedNatClass extends PrimitiveType {
726
737
  }
727
738
  covariant(x) {
728
739
  const max = (0, bigint_math_ts_1.iexp2)(this._bits);
729
- let ok = false;
730
740
  if (typeof x === 'bigint' && x >= BigInt(0)) {
731
- ok = x < max;
741
+ if (x < max) {
742
+ return true;
743
+ }
732
744
  }
733
745
  else if (Number.isInteger(x) && x >= 0) {
734
746
  const v = BigInt(x);
735
- ok = v < max;
736
- }
737
- else {
738
- ok = false;
747
+ if (v < max) {
748
+ return true;
749
+ }
739
750
  }
740
- if (ok)
741
- return true;
742
751
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
743
752
  }
744
753
  encodeValue(x) {
@@ -754,9 +763,7 @@ class FixedNatClass extends PrimitiveType {
754
763
  if (this._bits <= 32) {
755
764
  return Number(num);
756
765
  }
757
- else {
758
- return num;
759
- }
766
+ return num;
760
767
  }
761
768
  get name() {
762
769
  return `nat${this._bits}`;
@@ -811,10 +818,11 @@ class VecClass extends ConstructType {
811
818
  return this._type.covariant(v);
812
819
  }
813
820
  catch (e) {
814
- throw new Error(`Invalid ${this.display()} argument: \n\nindex ${idx} -> ${e.message}`);
821
+ throw new Error(`Invalid ${this.display()} argument: \n\nindex ${idx} -> ${e.message}`, { cause: e });
815
822
  }
816
- })))
823
+ }))) {
817
824
  return true;
825
+ }
818
826
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
819
827
  }
820
828
  encodeValue(x) {
@@ -836,7 +844,7 @@ class VecClass extends ConstructType {
836
844
  }
837
845
  return (0, buffer_ts_1.concat)(len, new Uint8Array(buffer.buffer));
838
846
  }
839
- else if (x instanceof Int32Array || x instanceof Uint32Array) {
847
+ if (x instanceof Int32Array || x instanceof Uint32Array) {
840
848
  const buffer = new DataView(new ArrayBuffer(x.length * 4));
841
849
  for (let i = 0; i < x.length; i++) {
842
850
  if (x instanceof Int32Array) {
@@ -848,7 +856,7 @@ class VecClass extends ConstructType {
848
856
  }
849
857
  return (0, buffer_ts_1.concat)(len, new Uint8Array(buffer.buffer));
850
858
  }
851
- else if (x instanceof BigInt64Array || x instanceof BigUint64Array) {
859
+ if (x instanceof BigInt64Array || x instanceof BigUint64Array) {
852
860
  const buffer = new DataView(new ArrayBuffer(x.length * 8));
853
861
  for (let i = 0; i < x.length; i++) {
854
862
  if (x instanceof BigInt64Array) {
@@ -860,10 +868,8 @@ class VecClass extends ConstructType {
860
868
  }
861
869
  return (0, buffer_ts_1.concat)(len, new Uint8Array(buffer.buffer));
862
870
  }
863
- else {
864
- // For Uint8Array, Int8Array, etc. that don't have endianness concerns
865
- return (0, buffer_ts_1.concat)(len, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
866
- }
871
+ // For Uint8Array, Int8Array, etc. that don't have endianness concerns
872
+ return (0, buffer_ts_1.concat)(len, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
867
873
  }
868
874
  const buf = new buffer_ts_1.PipeArrayBuffer(new Uint8Array(len.byteLength + x.length), 0);
869
875
  buf.write(len);
@@ -882,7 +888,7 @@ class VecClass extends ConstructType {
882
888
  decodeValue(b, t) {
883
889
  const vec = this.checkType(t);
884
890
  if (!(vec instanceof VecClass)) {
885
- throw new Error('Not a vector type');
891
+ throw new CandidDecodeError(`Expected type '${this.display()}', but received non-vector type '${vec.display()}'`);
886
892
  }
887
893
  const len = Number((0, leb128_ts_1.lebDecode)(b));
888
894
  if (this._type instanceof FixedNatClass) {
@@ -953,7 +959,7 @@ class VecClass extends ConstructType {
953
959
  }
954
960
  valueToString(x) {
955
961
  const elements = x.map(e => this._type.valueToString(e));
956
- return 'vec {' + elements.join('; ') + '}';
962
+ return `vec {${elements.join('; ')}}`;
957
963
  }
958
964
  }
959
965
  exports.VecClass = VecClass;
@@ -977,11 +983,12 @@ class OptClass extends ConstructType {
977
983
  }
978
984
  covariant(x) {
979
985
  try {
980
- if (Array.isArray(x) && (x.length === 0 || (x.length === 1 && this._type.covariant(x[0]))))
986
+ if (Array.isArray(x) && (x.length === 0 || (x.length === 1 && this._type.covariant(x[0])))) {
981
987
  return true;
988
+ }
982
989
  }
983
990
  catch (e) {
984
- throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)} \n\n-> ${e.message}`);
991
+ throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)} \n\n-> ${e.message}`, { cause: e });
985
992
  }
986
993
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
987
994
  }
@@ -989,9 +996,7 @@ class OptClass extends ConstructType {
989
996
  if (x.length === 0) {
990
997
  return new Uint8Array([0]);
991
998
  }
992
- else {
993
- return (0, buffer_ts_1.concat)(new Uint8Array([1]), this._type.encodeValue(x[0]));
994
- }
999
+ return (0, buffer_ts_1.concat)(new Uint8Array([1]), this._type.encodeValue(x[0]));
995
1000
  }
996
1001
  _buildTypeTableImpl(typeTable) {
997
1002
  this._type.buildTypeTable(typeTable);
@@ -1011,10 +1016,11 @@ class OptClass extends ConstructType {
1011
1016
  if (t instanceof RecClass) {
1012
1017
  const ty = t.getType();
1013
1018
  if (typeof ty === 'undefined') {
1014
- throw new Error('type mismatch with uninitialized type');
1019
+ throw new CandidDecodeError('Type mismatch: cannot decode from uninitialized recursive type');
1015
1020
  }
1016
- else
1021
+ else {
1017
1022
  wireType = ty;
1023
+ }
1018
1024
  }
1019
1025
  if (wireType instanceof OptClass) {
1020
1026
  switch ((0, leb128_ts_1.safeReadUint8)(b)) {
@@ -1038,7 +1044,7 @@ class OptClass extends ConstructType {
1038
1044
  }
1039
1045
  }
1040
1046
  default:
1041
- throw new Error('Not an option value');
1047
+ throw new CandidDecodeError(`Invalid option value: expected 0 (None) or 1 (Some) for type '${this.display()}'`);
1042
1048
  }
1043
1049
  }
1044
1050
  else if (
@@ -1079,9 +1085,7 @@ class OptClass extends ConstructType {
1079
1085
  if (x.length === 0) {
1080
1086
  return 'null';
1081
1087
  }
1082
- else {
1083
- return `opt ${this._type.valueToString(x[0])}`;
1084
- }
1088
+ return `opt ${this._type.valueToString(x[0])}`;
1085
1089
  }
1086
1090
  }
1087
1091
  exports.OptClass = OptClass;
@@ -1126,10 +1130,13 @@ class RecordClass extends ConstructType {
1126
1130
  return t.covariant(x[k]);
1127
1131
  }
1128
1132
  catch (e) {
1129
- throw new Error(`Invalid ${this.display()} argument: \n\nfield ${k} -> ${e.message}`);
1133
+ throw new Error(`Invalid ${this.display()} argument: \n\nfield ${k} -> ${e.message}`, {
1134
+ cause: e,
1135
+ });
1130
1136
  }
1131
- }))
1137
+ })) {
1132
1138
  return true;
1139
+ }
1133
1140
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
1134
1141
  }
1135
1142
  encodeValue(x) {
@@ -1147,7 +1154,7 @@ class RecordClass extends ConstructType {
1147
1154
  decodeValue(b, t) {
1148
1155
  const record = this.checkType(t);
1149
1156
  if (!(record instanceof RecordClass)) {
1150
- throw new Error('Not a record type');
1157
+ throw new CandidDecodeError(`Expected type '${this.display()}', but received non-record type '${record.display()}'`);
1151
1158
  }
1152
1159
  const x = {};
1153
1160
  let expectedRecordIdx = 0;
@@ -1176,7 +1183,9 @@ class RecordClass extends ConstructType {
1176
1183
  expectedRecordIdx++;
1177
1184
  }
1178
1185
  else {
1179
- throw new Error('Cannot find required field ' + expectKey);
1186
+ const expectedFields = this._fields.map(([name]) => name).join(', ');
1187
+ const receivedFields = record._fields.map(([name]) => name).join(', ');
1188
+ throw new CandidDecodeError(`Cannot find required field '${expectKey}' in record, expected fields: [${expectedFields}], received fields: [${receivedFields}]`);
1180
1189
  }
1181
1190
  }
1182
1191
  else {
@@ -1192,7 +1201,9 @@ class RecordClass extends ConstructType {
1192
1201
  x[expectKey] = [];
1193
1202
  }
1194
1203
  else {
1195
- throw new Error('Cannot find required field ' + expectKey);
1204
+ const expectedFields = this._fields.map(([name]) => name).join(', ');
1205
+ const receivedFields = record._fields.map(([name]) => name).join(', ');
1206
+ throw new CandidDecodeError(`Cannot find required field '${expectKey}' in record, expected fields: [${expectedFields}], received fields: [${receivedFields}]`);
1196
1207
  }
1197
1208
  }
1198
1209
  return x;
@@ -1205,16 +1216,16 @@ class RecordClass extends ConstructType {
1205
1216
  return fields;
1206
1217
  }
1207
1218
  get name() {
1208
- const fields = this._fields.map(([key, value]) => key + ':' + value.name);
1219
+ const fields = this._fields.map(([key, value]) => `${key}:${value.name}`);
1209
1220
  return `record {${fields.join('; ')}}`;
1210
1221
  }
1211
1222
  display() {
1212
- const fields = this._fields.map(([key, value]) => key + ':' + value.display());
1223
+ const fields = this._fields.map(([key, value]) => `${key}:${value.display()}`);
1213
1224
  return `record {${fields.join('; ')}}`;
1214
1225
  }
1215
1226
  valueToString(x) {
1216
1227
  const values = this._fields.map(([key]) => x[key]);
1217
- const fields = zipWith(this._fields, values, ([k, c], d) => k + '=' + c.valueToString(d));
1228
+ const fields = zipWith(this._fields, values, ([k, c], d) => `${k}=${c.valueToString(d)}`);
1218
1229
  return `record {${fields.join('; ')}}`;
1219
1230
  }
1220
1231
  }
@@ -1232,7 +1243,7 @@ class TupleClass extends RecordClass {
1232
1243
  }
1233
1244
  constructor(_components) {
1234
1245
  const x = {};
1235
- _components.forEach((e, i) => (x['_' + i + '_'] = e));
1246
+ _components.forEach((e, i) => (x[`_${i}_`] = e));
1236
1247
  super(x);
1237
1248
  this._components = _components;
1238
1249
  }
@@ -1248,10 +1259,13 @@ class TupleClass extends RecordClass {
1248
1259
  return t.covariant(x[i]);
1249
1260
  }
1250
1261
  catch (e) {
1251
- throw new Error(`Invalid ${this.display()} argument: \n\nindex ${i} -> ${e.message}`);
1262
+ throw new Error(`Invalid ${this.display()} argument: \n\nindex ${i} -> ${e.message}`, {
1263
+ cause: e,
1264
+ });
1252
1265
  }
1253
- }))
1266
+ })) {
1254
1267
  return true;
1268
+ }
1255
1269
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
1256
1270
  }
1257
1271
  encodeValue(x) {
@@ -1261,10 +1275,10 @@ class TupleClass extends RecordClass {
1261
1275
  decodeValue(b, t) {
1262
1276
  const tuple = this.checkType(t);
1263
1277
  if (!(tuple instanceof TupleClass)) {
1264
- throw new Error('not a tuple type');
1278
+ throw new CandidDecodeError(`Expected type '${this.display()}', but received non-tuple type '${tuple.display()}'`);
1265
1279
  }
1266
1280
  if (tuple._components.length < this._components.length) {
1267
- throw new Error('tuple mismatch');
1281
+ throw new CandidDecodeError(`Tuple mismatch: expected ${this._components.length} components, but received ${tuple._components.length}`);
1268
1282
  }
1269
1283
  const res = [];
1270
1284
  for (const [i, wireType] of tuple._components.entries()) {
@@ -1315,10 +1329,13 @@ class VariantClass extends ConstructType {
1315
1329
  return !x.hasOwnProperty(k) || v.covariant(x[k]);
1316
1330
  }
1317
1331
  catch (e) {
1318
- throw new Error(`Invalid ${this.display()} argument: \n\nvariant ${k} -> ${e.message}`);
1332
+ throw new Error(`Invalid ${this.display()} argument: \n\nvariant ${k} -> ${e.message}`, {
1333
+ cause: e,
1334
+ });
1319
1335
  }
1320
- }))
1336
+ })) {
1321
1337
  return true;
1338
+ }
1322
1339
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
1323
1340
  }
1324
1341
  encodeValue(x) {
@@ -1331,7 +1348,7 @@ class VariantClass extends ConstructType {
1331
1348
  return (0, buffer_ts_1.concat)(idx, buf);
1332
1349
  }
1333
1350
  }
1334
- throw Error('Variant has no data: ' + x);
1351
+ throw Error(`Variant has no data: ${x}`);
1335
1352
  }
1336
1353
  _buildTypeTableImpl(typeTable) {
1337
1354
  this._fields.forEach(([, type]) => {
@@ -1345,11 +1362,11 @@ class VariantClass extends ConstructType {
1345
1362
  decodeValue(b, t) {
1346
1363
  const variant = this.checkType(t);
1347
1364
  if (!(variant instanceof VariantClass)) {
1348
- throw new Error('Not a variant type');
1365
+ throw new CandidDecodeError(`Expected type '${this.display()}', but received non-variant type '${variant.display()}'`);
1349
1366
  }
1350
1367
  const idx = Number((0, leb128_ts_1.lebDecode)(b));
1351
1368
  if (idx >= variant._fields.length) {
1352
- throw Error('Invalid variant index: ' + idx);
1369
+ throw Error(`Invalid variant index: ${idx}`);
1353
1370
  }
1354
1371
  const [wireHash, wireType] = variant._fields[idx];
1355
1372
  for (const [key, expectType] of this._fields) {
@@ -1358,10 +1375,11 @@ class VariantClass extends ConstructType {
1358
1375
  return { [key]: value };
1359
1376
  }
1360
1377
  }
1361
- throw new Error('Cannot find field hash ' + wireHash);
1378
+ const expectedFields = this._fields.map(([name]) => name).join(', ');
1379
+ throw new CandidDecodeError(`Cannot find field hash ${wireHash} in variant, expected fields: [${expectedFields}]`);
1362
1380
  }
1363
1381
  get name() {
1364
- const fields = this._fields.map(([key, type]) => key + ':' + type.name);
1382
+ const fields = this._fields.map(([key, type]) => `${key}:${type.name}`);
1365
1383
  return `variant {${fields.join('; ')}}`;
1366
1384
  }
1367
1385
  display() {
@@ -1376,12 +1394,10 @@ class VariantClass extends ConstructType {
1376
1394
  if (value === 'null') {
1377
1395
  return `variant {${name}}`;
1378
1396
  }
1379
- else {
1380
- return `variant {${name}=${value}}`;
1381
- }
1397
+ return `variant {${name}=${value}}`;
1382
1398
  }
1383
1399
  }
1384
- throw new Error('Variant has no data: ' + x);
1400
+ throw new Error(`Variant has no data: ${x}`);
1385
1401
  }
1386
1402
  get alternativesAsObject() {
1387
1403
  const alternatives = {};
@@ -1421,8 +1437,9 @@ class RecClass extends ConstructType {
1421
1437
  return this._type;
1422
1438
  }
1423
1439
  covariant(x) {
1424
- if (this._type ? this._type.covariant(x) : false)
1440
+ if (this._type ? this._type.covariant(x) : false) {
1425
1441
  return true;
1442
+ }
1426
1443
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
1427
1444
  }
1428
1445
  encodeValue(x) {
@@ -1484,8 +1501,9 @@ class PrincipalClass extends PrimitiveType {
1484
1501
  return v.visitPrincipal(this, d);
1485
1502
  }
1486
1503
  covariant(x) {
1487
- if (x && x._isPrincipal)
1504
+ if (x && x._isPrincipal) {
1488
1505
  return true;
1506
+ }
1489
1507
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
1490
1508
  }
1491
1509
  encodeValue(x) {
@@ -1525,7 +1543,7 @@ class FuncClass extends ConstructType {
1525
1543
  if (types.length !== v.length) {
1526
1544
  throw new Error('arity mismatch');
1527
1545
  }
1528
- return '(' + types.map((t, i) => t.valueToString(v[i])).join(', ') + ')';
1546
+ return `(${types.map((t, i) => t.valueToString(v[i])).join(', ')})`;
1529
1547
  }
1530
1548
  constructor(argTypes, retTypes, annotations = []) {
1531
1549
  super();
@@ -1537,8 +1555,13 @@ class FuncClass extends ConstructType {
1537
1555
  return v.visitFunc(this, d);
1538
1556
  }
1539
1557
  covariant(x) {
1540
- if (Array.isArray(x) && x.length === 2 && x[0] && x[0]._isPrincipal && typeof x[1] === 'string')
1558
+ if (Array.isArray(x) &&
1559
+ x.length === 2 &&
1560
+ x[0] &&
1561
+ x[0]._isPrincipal &&
1562
+ typeof x[1] === 'string') {
1541
1563
  return true;
1564
+ }
1542
1565
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
1543
1566
  }
1544
1567
  encodeValue([principal, methodName]) {
@@ -1580,7 +1603,7 @@ class FuncClass extends ConstructType {
1580
1603
  get name() {
1581
1604
  const args = this.argTypes.map(arg => arg.name).join(', ');
1582
1605
  const rets = this.retTypes.map(arg => arg.name).join(', ');
1583
- const annon = ' ' + this.annotations.join(' ');
1606
+ const annon = ` ${this.annotations.join(' ')}`;
1584
1607
  return `(${args}) -> (${rets})${annon}`;
1585
1608
  }
1586
1609
  valueToString([principal, str]) {
@@ -1589,22 +1612,20 @@ class FuncClass extends ConstructType {
1589
1612
  display() {
1590
1613
  const args = this.argTypes.map(arg => arg.display()).join(', ');
1591
1614
  const rets = this.retTypes.map(arg => arg.display()).join(', ');
1592
- const annon = ' ' + this.annotations.join(' ');
1615
+ const annon = ` ${this.annotations.join(' ')}`;
1593
1616
  return `(${args}) → (${rets})${annon}`;
1594
1617
  }
1595
1618
  encodeAnnotation(ann) {
1596
1619
  if (ann === 'query') {
1597
1620
  return new Uint8Array([1]);
1598
1621
  }
1599
- else if (ann === 'oneway') {
1622
+ if (ann === 'oneway') {
1600
1623
  return new Uint8Array([2]);
1601
1624
  }
1602
- else if (ann === 'composite_query') {
1625
+ if (ann === 'composite_query') {
1603
1626
  return new Uint8Array([3]);
1604
1627
  }
1605
- else {
1606
- throw new Error('Illegal function annotation');
1607
- }
1628
+ throw new Error('Illegal function annotation');
1608
1629
  }
1609
1630
  }
1610
1631
  exports.FuncClass = FuncClass;
@@ -1631,8 +1652,9 @@ class ServiceClass extends ConstructType {
1631
1652
  return v.visitService(this, d);
1632
1653
  }
1633
1654
  covariant(x) {
1634
- if (x && x._isPrincipal)
1655
+ if (x && x._isPrincipal) {
1635
1656
  return true;
1657
+ }
1636
1658
  throw new Error(`Invalid ${this.display()} argument: ${toReadableString(x)}`);
1637
1659
  }
1638
1660
  encodeValue(x) {
@@ -1659,7 +1681,7 @@ class ServiceClass extends ConstructType {
1659
1681
  return decodePrincipalId(b);
1660
1682
  }
1661
1683
  get name() {
1662
- const fields = this._fields.map(([key, value]) => key + ':' + value.name);
1684
+ const fields = this._fields.map(([key, value]) => `${key}:${value.name}`);
1663
1685
  return `service {${fields.join('; ')}}`;
1664
1686
  }
1665
1687
  valueToString(x) {
@@ -1682,7 +1704,7 @@ exports.ServiceClass = ServiceClass;
1682
1704
  function toReadableString(x) {
1683
1705
  const str = JSON.stringify(x, (_key, value) => typeof value === 'bigint' ? `BigInt(${value})` : value);
1684
1706
  return str && str.length > toReadableString_max
1685
- ? str.substring(0, toReadableString_max - 3) + '...'
1707
+ ? `${str.substring(0, toReadableString_max - 3)}...`
1686
1708
  : str;
1687
1709
  }
1688
1710
  /**
@@ -1705,7 +1727,7 @@ function encode(argTypes, args) {
1705
1727
  t.covariant(x);
1706
1728
  }
1707
1729
  catch (e) {
1708
- const err = new Error(e.message + '\n\n');
1730
+ const err = new Error(`${e.message}\n\n`);
1709
1731
  throw err;
1710
1732
  }
1711
1733
  return t.encodeValue(x);
@@ -1726,7 +1748,7 @@ function decode(retTypes, bytes) {
1726
1748
  const magicBuffer = (0, leb128_ts_1.safeRead)(b, magicNumber.length);
1727
1749
  const magic = new TextDecoder().decode(magicBuffer);
1728
1750
  if (magic !== magicNumber) {
1729
- throw new Error('Wrong magic number: ' + JSON.stringify(magic));
1751
+ throw new Error(`Wrong magic number: ${JSON.stringify(magic)}`);
1730
1752
  }
1731
1753
  function readTypeTable(pipe) {
1732
1754
  const typeTable = [];
@@ -1808,7 +1830,7 @@ function decode(retTypes, bytes) {
1808
1830
  break;
1809
1831
  }
1810
1832
  default:
1811
- throw new Error('Illegal op_code: ' + ty);
1833
+ throw new Error(`Illegal op_code: ${ty}`);
1812
1834
  }
1813
1835
  }
1814
1836
  const rawList = [];
@@ -1866,7 +1888,7 @@ function decode(retTypes, bytes) {
1866
1888
  case -24:
1867
1889
  return exports.Principal;
1868
1890
  default:
1869
- throw new Error('Illegal op_code: ' + t);
1891
+ throw new Error(`Illegal op_code: ${t}`);
1870
1892
  }
1871
1893
  }
1872
1894
  if (t >= rawTable.length) {
@@ -1895,9 +1917,7 @@ function decode(retTypes, bytes) {
1895
1917
  if (Array.isArray(tuple)) {
1896
1918
  return Tuple(...tuple);
1897
1919
  }
1898
- else {
1899
- return record;
1900
- }
1920
+ return record;
1901
1921
  }
1902
1922
  case IDLTypeIds.Variant: {
1903
1923
  const fields = {};
@@ -1928,7 +1948,7 @@ function decode(retTypes, bytes) {
1928
1948
  return Service(rec);
1929
1949
  }
1930
1950
  default:
1931
- throw new Error('Illegal op_code: ' + entry[0]);
1951
+ throw new Error(`Illegal op_code: ${entry[0]}`);
1932
1952
  }
1933
1953
  }
1934
1954
  rawTable.forEach((entry, i) => {
@@ -2112,8 +2132,9 @@ function eqFunctionAnnotations(t1, t2) {
2112
2132
  return false;
2113
2133
  }
2114
2134
  for (const a of t1Annotations) {
2115
- if (!t2Annotations.has(a))
2135
+ if (!t2Annotations.has(a)) {
2116
2136
  return false;
2137
+ }
2117
2138
  }
2118
2139
  return true;
2119
2140
  }
@@ -2137,60 +2158,74 @@ function subtype(t1, t2) {
2137
2158
  return isSubtype;
2138
2159
  }
2139
2160
  function subtype_(relations, t1, t2) {
2140
- if (t1.name === t2.name)
2161
+ if (t1.name === t2.name) {
2141
2162
  return true;
2163
+ }
2142
2164
  const known = relations.known(t1, t2);
2143
- if (known !== undefined)
2165
+ if (known !== undefined) {
2144
2166
  return known;
2167
+ }
2145
2168
  relations.add(t1, t2);
2146
- if (t2 instanceof ReservedClass)
2169
+ if (t2 instanceof ReservedClass) {
2147
2170
  return true;
2148
- if (t1 instanceof EmptyClass)
2171
+ }
2172
+ if (t1 instanceof EmptyClass) {
2149
2173
  return true;
2150
- if (t1 instanceof NatClass && t2 instanceof IntClass)
2174
+ }
2175
+ if (t1 instanceof NatClass && t2 instanceof IntClass) {
2151
2176
  return true;
2152
- if (t1 instanceof VecClass && t2 instanceof VecClass)
2177
+ }
2178
+ if (t1 instanceof VecClass && t2 instanceof VecClass) {
2153
2179
  return subtype_(relations, t1._type, t2._type);
2154
- if (t2 instanceof OptClass)
2180
+ }
2181
+ if (t2 instanceof OptClass) {
2155
2182
  return true;
2183
+ }
2156
2184
  if (t1 instanceof RecordClass && t2 instanceof RecordClass) {
2157
2185
  const t1Object = t1.fieldsAsObject;
2158
2186
  for (const [label, ty2] of t2._fields) {
2159
2187
  const ty1 = t1Object[(0, hash_ts_1.idlLabelToId)(label)];
2160
2188
  if (!ty1) {
2161
- if (!canBeOmmitted(ty2))
2189
+ if (!canBeOmmitted(ty2)) {
2162
2190
  return false;
2191
+ }
2163
2192
  }
2164
2193
  else {
2165
- if (!subtype_(relations, ty1, ty2))
2194
+ if (!subtype_(relations, ty1, ty2)) {
2166
2195
  return false;
2196
+ }
2167
2197
  }
2168
2198
  }
2169
2199
  return true;
2170
2200
  }
2171
2201
  if (t1 instanceof FuncClass && t2 instanceof FuncClass) {
2172
- if (!eqFunctionAnnotations(t1, t2))
2202
+ if (!eqFunctionAnnotations(t1, t2)) {
2173
2203
  return false;
2204
+ }
2174
2205
  for (let i = 0; i < t1.argTypes.length; i++) {
2175
2206
  const argTy1 = t1.argTypes[i];
2176
2207
  if (i < t2.argTypes.length) {
2177
- if (!subtype_(relations, t2.argTypes[i], argTy1))
2208
+ if (!subtype_(relations, t2.argTypes[i], argTy1)) {
2178
2209
  return false;
2210
+ }
2179
2211
  }
2180
2212
  else {
2181
- if (!canBeOmmitted(argTy1))
2213
+ if (!canBeOmmitted(argTy1)) {
2182
2214
  return false;
2215
+ }
2183
2216
  }
2184
2217
  }
2185
2218
  for (let i = 0; i < t2.retTypes.length; i++) {
2186
2219
  const retTy2 = t2.retTypes[i];
2187
2220
  if (i < t1.retTypes.length) {
2188
- if (!subtype_(relations, t1.retTypes[i], retTy2))
2221
+ if (!subtype_(relations, t1.retTypes[i], retTy2)) {
2189
2222
  return false;
2223
+ }
2190
2224
  }
2191
2225
  else {
2192
- if (!canBeOmmitted(retTy2))
2226
+ if (!canBeOmmitted(retTy2)) {
2193
2227
  return false;
2228
+ }
2194
2229
  }
2195
2230
  }
2196
2231
  return true;
@@ -2199,10 +2234,12 @@ function subtype_(relations, t1, t2) {
2199
2234
  const t2Object = t2.alternativesAsObject;
2200
2235
  for (const [label, ty1] of t1._fields) {
2201
2236
  const ty2 = t2Object[(0, hash_ts_1.idlLabelToId)(label)];
2202
- if (!ty2)
2237
+ if (!ty2) {
2203
2238
  return false;
2204
- if (!subtype_(relations, ty1, ty2))
2239
+ }
2240
+ if (!subtype_(relations, ty1, ty2)) {
2205
2241
  return false;
2242
+ }
2206
2243
  }
2207
2244
  return true;
2208
2245
  }
@@ -2210,10 +2247,12 @@ function subtype_(relations, t1, t2) {
2210
2247
  const t1Object = t1.fieldsAsObject();
2211
2248
  for (const [name, ty2] of t2._fields) {
2212
2249
  const ty1 = t1Object[name];
2213
- if (!ty1)
2250
+ if (!ty1) {
2214
2251
  return false;
2215
- if (!subtype_(relations, ty1, ty2))
2252
+ }
2253
+ if (!subtype_(relations, ty1, ty2)) {
2216
2254
  return false;
2255
+ }
2217
2256
  }
2218
2257
  return true;
2219
2258
  }