@helios-lang/effect 0.1.14 → 0.2.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 (387) hide show
  1. package/dist/Cardano/CoinSelection.js +130 -0
  2. package/dist/Cardano/CoinSelection.js.map +1 -0
  3. package/dist/{Ledger → Cardano/Ledger}/Address.js +30 -20
  4. package/dist/Cardano/Ledger/Address.js.map +1 -0
  5. package/dist/{Ledger → Cardano/Ledger}/AssetClass.js +16 -11
  6. package/dist/Cardano/Ledger/AssetClass.js.map +1 -0
  7. package/dist/Cardano/Ledger/Assets.js +235 -0
  8. package/dist/Cardano/Ledger/Assets.js.map +1 -0
  9. package/dist/Cardano/Ledger/Credential.js +53 -0
  10. package/dist/Cardano/Ledger/Credential.js.map +1 -0
  11. package/dist/Cardano/Ledger/DCert.js +117 -0
  12. package/dist/Cardano/Ledger/DCert.js.map +1 -0
  13. package/dist/Cardano/Ledger/DatumHash.js +25 -0
  14. package/dist/Cardano/Ledger/DatumHash.js.map +1 -0
  15. package/dist/Cardano/Ledger/MintingPolicy.js +40 -0
  16. package/dist/Cardano/Ledger/MintingPolicy.js.map +1 -0
  17. package/dist/Cardano/Ledger/NativeScript.js +140 -0
  18. package/dist/Cardano/Ledger/NativeScript.js.map +1 -0
  19. package/dist/Cardano/Ledger/PubKey.js +22 -0
  20. package/dist/Cardano/Ledger/PubKey.js.map +1 -0
  21. package/dist/{Ledger → Cardano/Ledger}/PubKeyHash.js +5 -5
  22. package/dist/Cardano/Ledger/PubKeyHash.js.map +1 -0
  23. package/dist/Cardano/Ledger/Redeemer.js +155 -0
  24. package/dist/Cardano/Ledger/Redeemer.js.map +1 -0
  25. package/dist/Cardano/Ledger/RewardAddress.js +93 -0
  26. package/dist/Cardano/Ledger/RewardAddress.js.map +1 -0
  27. package/dist/Cardano/Ledger/Signature.js +23 -0
  28. package/dist/Cardano/Ledger/Signature.js.map +1 -0
  29. package/dist/Cardano/Ledger/Tx.js +498 -0
  30. package/dist/Cardano/Ledger/Tx.js.map +1 -0
  31. package/dist/Cardano/Ledger/TxHash.js +38 -0
  32. package/dist/Cardano/Ledger/TxHash.js.map +1 -0
  33. package/dist/Cardano/Ledger/TxOutput.js +167 -0
  34. package/dist/Cardano/Ledger/TxOutput.js.map +1 -0
  35. package/dist/{Ledger → Cardano/Ledger}/TxOutputDatum.js +44 -8
  36. package/dist/Cardano/Ledger/TxOutputDatum.js.map +1 -0
  37. package/dist/Cardano/Ledger/UTxO.js +100 -0
  38. package/dist/Cardano/Ledger/UTxO.js.map +1 -0
  39. package/dist/{Ledger → Cardano/Ledger}/UTxORef.js +28 -6
  40. package/dist/Cardano/Ledger/UTxORef.js.map +1 -0
  41. package/dist/{Ledger → Cardano/Ledger}/ValidatorHash.js +5 -5
  42. package/dist/Cardano/Ledger/ValidatorHash.js.map +1 -0
  43. package/dist/{Ledger → Cardano/Ledger}/index.js +5 -0
  44. package/dist/Cardano/Ledger/index.js.map +1 -0
  45. package/dist/Cardano/Network/IsMainnet.js.map +1 -0
  46. package/dist/{Network → Cardano/Network}/Params.js +27 -3
  47. package/dist/Cardano/Network/Params.js.map +1 -0
  48. package/dist/Cardano/Network/UTxO.js +20 -0
  49. package/dist/Cardano/Network/UTxO.js.map +1 -0
  50. package/dist/Cardano/Network/UTxOsAt.js +4 -0
  51. package/dist/Cardano/Network/UTxOsAt.js.map +1 -0
  52. package/dist/Cardano/Network/errors.js +33 -0
  53. package/dist/Cardano/Network/errors.js.map +1 -0
  54. package/dist/{Network → Cardano/Network}/index.js +1 -0
  55. package/dist/Cardano/Network/index.js.map +1 -0
  56. package/dist/Cardano/TxBuilder.js +946 -0
  57. package/dist/Cardano/TxBuilder.js.map +1 -0
  58. package/dist/Cardano/Uplc/Builtins.js +1820 -0
  59. package/dist/Cardano/Uplc/Builtins.js.map +1 -0
  60. package/dist/Cardano/Uplc/Cek.js +716 -0
  61. package/dist/Cardano/Uplc/Cek.js.map +1 -0
  62. package/dist/Cardano/Uplc/Cost.js +956 -0
  63. package/dist/Cardano/Uplc/Cost.js.map +1 -0
  64. package/dist/{Uplc → Cardano/Uplc}/Data.js +143 -22
  65. package/dist/Cardano/Uplc/Data.js.map +1 -0
  66. package/dist/Cardano/Uplc/Script.js +118 -0
  67. package/dist/Cardano/Uplc/Script.js.map +1 -0
  68. package/dist/Cardano/Uplc/ScriptContext.js +259 -0
  69. package/dist/Cardano/Uplc/ScriptContext.js.map +1 -0
  70. package/dist/Cardano/Uplc/Term.js +384 -0
  71. package/dist/Cardano/Uplc/Term.js.map +1 -0
  72. package/dist/Cardano/Uplc/Type.js +131 -0
  73. package/dist/Cardano/Uplc/Type.js.map +1 -0
  74. package/dist/Cardano/Uplc/Value.js +315 -0
  75. package/dist/Cardano/Uplc/Value.js.map +1 -0
  76. package/dist/Cardano/Uplc/index.js +7 -0
  77. package/dist/Cardano/Uplc/index.js.map +1 -0
  78. package/dist/Cardano/index.js +6 -0
  79. package/dist/Cardano/index.js.map +1 -0
  80. package/dist/{internal → Codecs}/Base32.js +2 -2
  81. package/dist/Codecs/Base32.js.map +1 -0
  82. package/dist/{Bech32.js → Codecs/Bech32.js} +2 -2
  83. package/dist/Codecs/Bech32.js.map +1 -0
  84. package/dist/Codecs/BigEndian.js.map +1 -0
  85. package/dist/Codecs/Bits.js.map +1 -0
  86. package/dist/{internal → Codecs}/Bytes.js +23 -12
  87. package/dist/Codecs/Bytes.js.map +1 -0
  88. package/dist/{Cbor.js → Codecs/Cbor.js} +559 -328
  89. package/dist/Codecs/Cbor.js.map +1 -0
  90. package/dist/{internal → Codecs}/Flat.js +16 -0
  91. package/dist/Codecs/Flat.js.map +1 -0
  92. package/dist/Codecs/Float.js.map +1 -0
  93. package/dist/Codecs/LittleEndian.js +27 -0
  94. package/dist/Codecs/LittleEndian.js.map +1 -0
  95. package/dist/Codecs/Uint64.js +89 -0
  96. package/dist/Codecs/Uint64.js.map +1 -0
  97. package/dist/{internal → Codecs}/Utf8.js +7 -2
  98. package/dist/Codecs/Utf8.js.map +1 -0
  99. package/dist/Codecs/ZigZag.js +26 -0
  100. package/dist/Codecs/ZigZag.js.map +1 -0
  101. package/dist/Codecs/index.js +8 -0
  102. package/dist/Codecs/index.js.map +1 -0
  103. package/dist/Crypto/Blake2b.js +156 -0
  104. package/dist/Crypto/Blake2b.js.map +1 -0
  105. package/dist/Crypto/Curve.js +92 -0
  106. package/dist/Crypto/Curve.js.map +1 -0
  107. package/dist/Crypto/Ed25519.js +323 -0
  108. package/dist/Crypto/Ed25519.js.map +1 -0
  109. package/dist/Crypto/EdDSA.js +222 -0
  110. package/dist/Crypto/EdDSA.js.map +1 -0
  111. package/dist/Crypto/Field.js +323 -0
  112. package/dist/Crypto/Field.js.map +1 -0
  113. package/dist/Crypto/Hmac.js +51 -0
  114. package/dist/Crypto/Hmac.js.map +1 -0
  115. package/dist/Crypto/Keccak.js +167 -0
  116. package/dist/Crypto/Keccak.js.map +1 -0
  117. package/dist/Crypto/Pbkdf2.js +45 -0
  118. package/dist/Crypto/Pbkdf2.js.map +1 -0
  119. package/dist/Crypto/Sha2_256.js +200 -0
  120. package/dist/Crypto/Sha2_256.js.map +1 -0
  121. package/dist/Crypto/Sha2_512.js +264 -0
  122. package/dist/Crypto/Sha2_512.js.map +1 -0
  123. package/dist/Crypto/Sha3_256.js +10 -0
  124. package/dist/Crypto/Sha3_256.js.map +1 -0
  125. package/dist/Crypto/errors.js +9 -0
  126. package/dist/Crypto/errors.js.map +1 -0
  127. package/dist/Crypto/index.js +12 -0
  128. package/dist/Crypto/index.js.map +1 -0
  129. package/dist/index.js +3 -5
  130. package/dist/index.js.map +1 -1
  131. package/package.json +24 -6
  132. package/tsconfig.build.json +1 -1
  133. package/tsconfig.build.tsbuildinfo +1 -1
  134. package/tsconfig.tsbuildinfo +1 -1
  135. package/types/Cardano/CoinSelection.d.ts +26 -0
  136. package/types/Cardano/CoinSelection.d.ts.map +1 -0
  137. package/types/{Ledger → Cardano/Ledger}/Address.d.ts +7 -6
  138. package/types/Cardano/Ledger/Address.d.ts.map +1 -0
  139. package/types/{Ledger → Cardano/Ledger}/AssetClass.d.ts +2 -2
  140. package/types/Cardano/Ledger/AssetClass.d.ts.map +1 -0
  141. package/types/Cardano/Ledger/Assets.d.ts +114 -0
  142. package/types/Cardano/Ledger/Assets.d.ts.map +1 -0
  143. package/types/{Ledger → Cardano/Ledger}/Credential.d.ts +10 -4
  144. package/types/Cardano/Ledger/Credential.d.ts.map +1 -0
  145. package/types/Cardano/Ledger/DCert.d.ts +40 -0
  146. package/types/Cardano/Ledger/DCert.d.ts.map +1 -0
  147. package/types/{Ledger → Cardano/Ledger}/DatumHash.d.ts +6 -5
  148. package/types/Cardano/Ledger/DatumHash.d.ts.map +1 -0
  149. package/types/{Ledger → Cardano/Ledger}/MintingPolicy.d.ts +11 -8
  150. package/types/Cardano/Ledger/MintingPolicy.d.ts.map +1 -0
  151. package/types/Cardano/Ledger/NativeScript.d.ts +105 -0
  152. package/types/Cardano/Ledger/NativeScript.d.ts.map +1 -0
  153. package/types/Cardano/Ledger/PubKey.d.ts +41 -0
  154. package/types/Cardano/Ledger/PubKey.d.ts.map +1 -0
  155. package/types/{Ledger → Cardano/Ledger}/PubKeyHash.d.ts +5 -5
  156. package/types/Cardano/Ledger/PubKeyHash.d.ts.map +1 -0
  157. package/types/Cardano/Ledger/Redeemer.d.ts +303 -0
  158. package/types/Cardano/Ledger/Redeemer.d.ts.map +1 -0
  159. package/types/Cardano/Ledger/RewardAddress.d.ts +60 -0
  160. package/types/Cardano/Ledger/RewardAddress.d.ts.map +1 -0
  161. package/types/Cardano/Ledger/Signature.d.ts +13 -0
  162. package/types/Cardano/Ledger/Signature.d.ts.map +1 -0
  163. package/types/Cardano/Ledger/Tx.d.ts +375 -0
  164. package/types/Cardano/Ledger/Tx.d.ts.map +1 -0
  165. package/types/{Ledger → Cardano/Ledger}/TxHash.d.ts +35 -5
  166. package/types/Cardano/Ledger/TxHash.d.ts.map +1 -0
  167. package/types/Cardano/Ledger/TxOutput.d.ts +438 -0
  168. package/types/Cardano/Ledger/TxOutput.d.ts.map +1 -0
  169. package/types/Cardano/Ledger/TxOutputDatum.d.ts +98 -0
  170. package/types/Cardano/Ledger/TxOutputDatum.d.ts.map +1 -0
  171. package/types/Cardano/Ledger/UTxO.d.ts +1420 -0
  172. package/types/Cardano/Ledger/UTxO.d.ts.map +1 -0
  173. package/types/Cardano/Ledger/UTxORef.d.ts +222 -0
  174. package/types/Cardano/Ledger/UTxORef.d.ts.map +1 -0
  175. package/types/{Ledger → Cardano/Ledger}/ValidatorHash.d.ts +5 -5
  176. package/types/Cardano/Ledger/ValidatorHash.d.ts.map +1 -0
  177. package/types/{Ledger → Cardano/Ledger}/index.d.ts +5 -0
  178. package/types/Cardano/Ledger/index.d.ts.map +1 -0
  179. package/types/Cardano/Network/IsMainnet.d.ts.map +1 -0
  180. package/types/{Network → Cardano/Network}/Params.d.ts +32 -4
  181. package/types/Cardano/Network/Params.d.ts.map +1 -0
  182. package/types/Cardano/Network/UTxO.d.ts +15 -0
  183. package/types/Cardano/Network/UTxO.d.ts.map +1 -0
  184. package/types/Cardano/Network/UTxOsAt.d.ts +9 -0
  185. package/types/Cardano/Network/UTxOsAt.d.ts.map +1 -0
  186. package/types/Cardano/Network/errors.d.ts +39 -0
  187. package/types/Cardano/Network/errors.d.ts.map +1 -0
  188. package/types/{Network → Cardano/Network}/index.d.ts +1 -0
  189. package/types/Cardano/Network/index.d.ts.map +1 -0
  190. package/types/Cardano/TxBuilder.d.ts +261 -0
  191. package/types/Cardano/TxBuilder.d.ts.map +1 -0
  192. package/types/Cardano/Uplc/Builtins.d.ts +163 -0
  193. package/types/Cardano/Uplc/Builtins.d.ts.map +1 -0
  194. package/types/Cardano/Uplc/Cek.d.ts +165 -0
  195. package/types/Cardano/Uplc/Cek.d.ts.map +1 -0
  196. package/types/Cardano/Uplc/Cost.d.ts +93 -0
  197. package/types/Cardano/Uplc/Cost.d.ts.map +1 -0
  198. package/types/{Uplc → Cardano/Uplc}/Data.d.ts +149 -15
  199. package/types/Cardano/Uplc/Data.d.ts.map +1 -0
  200. package/types/Cardano/Uplc/Script.d.ts +87 -0
  201. package/types/Cardano/Uplc/Script.d.ts.map +1 -0
  202. package/types/Cardano/Uplc/ScriptContext.d.ts +21 -0
  203. package/types/Cardano/Uplc/ScriptContext.d.ts.map +1 -0
  204. package/types/Cardano/Uplc/Term.d.ts +454 -0
  205. package/types/Cardano/Uplc/Term.d.ts.map +1 -0
  206. package/types/Cardano/Uplc/Type.d.ts +29 -0
  207. package/types/Cardano/Uplc/Type.d.ts.map +1 -0
  208. package/types/Cardano/Uplc/Value.d.ts +152 -0
  209. package/types/Cardano/Uplc/Value.d.ts.map +1 -0
  210. package/types/Cardano/Uplc/index.d.ts +7 -0
  211. package/types/Cardano/Uplc/index.d.ts.map +1 -0
  212. package/types/Cardano/index.d.ts +6 -0
  213. package/types/Cardano/index.d.ts.map +1 -0
  214. package/types/Codecs/Base32.d.ts.map +1 -0
  215. package/types/Codecs/Bech32.d.ts.map +1 -0
  216. package/types/Codecs/BigEndian.d.ts.map +1 -0
  217. package/types/Codecs/Bits.d.ts.map +1 -0
  218. package/types/{internal → Codecs}/Bytes.d.ts +7 -6
  219. package/types/Codecs/Bytes.d.ts.map +1 -0
  220. package/types/{Cbor.d.ts → Codecs/Cbor.d.ts} +77 -55
  221. package/types/Codecs/Cbor.d.ts.map +1 -0
  222. package/types/{internal → Codecs}/Flat.d.ts +2 -0
  223. package/types/Codecs/Flat.d.ts.map +1 -0
  224. package/types/Codecs/Float.d.ts.map +1 -0
  225. package/types/Codecs/LittleEndian.d.ts +18 -0
  226. package/types/Codecs/LittleEndian.d.ts.map +1 -0
  227. package/types/Codecs/Uint64.d.ts +16 -0
  228. package/types/Codecs/Uint64.d.ts.map +1 -0
  229. package/types/{internal → Codecs}/Utf8.d.ts +2 -2
  230. package/types/Codecs/Utf8.d.ts.map +1 -0
  231. package/types/Codecs/ZigZag.d.ts +3 -0
  232. package/types/Codecs/ZigZag.d.ts.map +1 -0
  233. package/types/Codecs/index.d.ts +8 -0
  234. package/types/Codecs/index.d.ts.map +1 -0
  235. package/types/Crypto/Blake2b.d.ts +16 -0
  236. package/types/Crypto/Blake2b.d.ts.map +1 -0
  237. package/types/Crypto/Curve.d.ts +161 -0
  238. package/types/Crypto/Curve.d.ts.map +1 -0
  239. package/types/Crypto/Ed25519.d.ts +155 -0
  240. package/types/Crypto/Ed25519.d.ts.map +1 -0
  241. package/types/Crypto/EdDSA.d.ts +159 -0
  242. package/types/Crypto/EdDSA.d.ts.map +1 -0
  243. package/types/Crypto/Field.d.ts +273 -0
  244. package/types/Crypto/Field.d.ts.map +1 -0
  245. package/types/Crypto/Hmac.d.ts +20 -0
  246. package/types/Crypto/Hmac.d.ts.map +1 -0
  247. package/types/Crypto/Keccak.d.ts +16 -0
  248. package/types/Crypto/Keccak.d.ts.map +1 -0
  249. package/types/Crypto/Pbkdf2.d.ts +15 -0
  250. package/types/Crypto/Pbkdf2.d.ts.map +1 -0
  251. package/types/Crypto/Sha2_256.d.ts +36 -0
  252. package/types/Crypto/Sha2_256.d.ts.map +1 -0
  253. package/types/Crypto/Sha2_512.d.ts +31 -0
  254. package/types/Crypto/Sha2_512.d.ts.map +1 -0
  255. package/types/Crypto/Sha3_256.d.ts +8 -0
  256. package/types/Crypto/Sha3_256.d.ts.map +1 -0
  257. package/types/Crypto/errors.d.ts +10 -0
  258. package/types/Crypto/errors.d.ts.map +1 -0
  259. package/types/Crypto/index.d.ts +12 -0
  260. package/types/Crypto/index.d.ts.map +1 -0
  261. package/types/index.d.ts +3 -5
  262. package/types/index.d.ts.map +1 -1
  263. package/dist/Address.js +0 -13
  264. package/dist/Address.js.map +0 -1
  265. package/dist/Bech32.js.map +0 -1
  266. package/dist/Cbor.js.map +0 -1
  267. package/dist/Ledger/Address.js.map +0 -1
  268. package/dist/Ledger/AssetClass.js.map +0 -1
  269. package/dist/Ledger/Assets.js +0 -120
  270. package/dist/Ledger/Assets.js.map +0 -1
  271. package/dist/Ledger/Credential.js +0 -17
  272. package/dist/Ledger/Credential.js.map +0 -1
  273. package/dist/Ledger/DatumHash.js +0 -21
  274. package/dist/Ledger/DatumHash.js.map +0 -1
  275. package/dist/Ledger/IsMainnet.js +0 -4
  276. package/dist/Ledger/IsMainnet.js.map +0 -1
  277. package/dist/Ledger/MintingPolicy.js +0 -45
  278. package/dist/Ledger/MintingPolicy.js.map +0 -1
  279. package/dist/Ledger/NetworkParams.js +0 -40
  280. package/dist/Ledger/NetworkParams.js.map +0 -1
  281. package/dist/Ledger/PubKeyHash.js.map +0 -1
  282. package/dist/Ledger/TxHash.js +0 -23
  283. package/dist/Ledger/TxHash.js.map +0 -1
  284. package/dist/Ledger/TxId.js +0 -23
  285. package/dist/Ledger/TxId.js.map +0 -1
  286. package/dist/Ledger/TxInput.js +0 -51
  287. package/dist/Ledger/TxInput.js.map +0 -1
  288. package/dist/Ledger/TxOutput.js +0 -118
  289. package/dist/Ledger/TxOutput.js.map +0 -1
  290. package/dist/Ledger/TxOutputDatum.js.map +0 -1
  291. package/dist/Ledger/TxOutputId.js +0 -55
  292. package/dist/Ledger/TxOutputId.js.map +0 -1
  293. package/dist/Ledger/UTxO.js +0 -43
  294. package/dist/Ledger/UTxO.js.map +0 -1
  295. package/dist/Ledger/UTxORef.js.map +0 -1
  296. package/dist/Ledger/ValidatorHash.js.map +0 -1
  297. package/dist/Ledger/index.js.map +0 -1
  298. package/dist/Network/IsMainnet.js.map +0 -1
  299. package/dist/Network/Params.js.map +0 -1
  300. package/dist/Network/UTxOsAt.js +0 -4
  301. package/dist/Network/UTxOsAt.js.map +0 -1
  302. package/dist/Network/errors.js +0 -16
  303. package/dist/Network/errors.js.map +0 -1
  304. package/dist/Network/index.js.map +0 -1
  305. package/dist/Uplc/Cek.js +0 -3
  306. package/dist/Uplc/Cek.js.map +0 -1
  307. package/dist/Uplc/Data.js.map +0 -1
  308. package/dist/Uplc/DataSchema.js +0 -118
  309. package/dist/Uplc/DataSchema.js.map +0 -1
  310. package/dist/Uplc/Primitive.js +0 -23
  311. package/dist/Uplc/Primitive.js.map +0 -1
  312. package/dist/Uplc/index.js +0 -3
  313. package/dist/Uplc/index.js.map +0 -1
  314. package/dist/internal/Base32.js.map +0 -1
  315. package/dist/internal/BigEndian.js.map +0 -1
  316. package/dist/internal/Bits.js.map +0 -1
  317. package/dist/internal/Bytes.js.map +0 -1
  318. package/dist/internal/Flat.js.map +0 -1
  319. package/dist/internal/Float.js.map +0 -1
  320. package/dist/internal/Utf8.js.map +0 -1
  321. package/tsconfig.check.tsbuildinfo +0 -1
  322. package/types/Address.d.ts +0 -5
  323. package/types/Address.d.ts.map +0 -1
  324. package/types/Bech32.d.ts.map +0 -1
  325. package/types/Cbor.d.ts.map +0 -1
  326. package/types/Ledger/Address.d.ts.map +0 -1
  327. package/types/Ledger/AssetClass.d.ts.map +0 -1
  328. package/types/Ledger/Assets.d.ts +0 -70
  329. package/types/Ledger/Assets.d.ts.map +0 -1
  330. package/types/Ledger/Credential.d.ts.map +0 -1
  331. package/types/Ledger/DatumHash.d.ts.map +0 -1
  332. package/types/Ledger/IsMainnet.d.ts +0 -6
  333. package/types/Ledger/IsMainnet.d.ts.map +0 -1
  334. package/types/Ledger/MintingPolicy.d.ts.map +0 -1
  335. package/types/Ledger/NetworkParams.d.ts +0 -40
  336. package/types/Ledger/NetworkParams.d.ts.map +0 -1
  337. package/types/Ledger/PubKeyHash.d.ts.map +0 -1
  338. package/types/Ledger/TxHash.d.ts.map +0 -1
  339. package/types/Ledger/TxId.d.ts +0 -70
  340. package/types/Ledger/TxId.d.ts.map +0 -1
  341. package/types/Ledger/TxInput.d.ts +0 -55
  342. package/types/Ledger/TxInput.d.ts.map +0 -1
  343. package/types/Ledger/TxOutput.d.ts +0 -63
  344. package/types/Ledger/TxOutput.d.ts.map +0 -1
  345. package/types/Ledger/TxOutputDatum.d.ts +0 -41
  346. package/types/Ledger/TxOutputDatum.d.ts.map +0 -1
  347. package/types/Ledger/TxOutputId.d.ts +0 -133
  348. package/types/Ledger/TxOutputId.d.ts.map +0 -1
  349. package/types/Ledger/UTxO.d.ts +0 -55
  350. package/types/Ledger/UTxO.d.ts.map +0 -1
  351. package/types/Ledger/UTxORef.d.ts +0 -133
  352. package/types/Ledger/UTxORef.d.ts.map +0 -1
  353. package/types/Ledger/ValidatorHash.d.ts.map +0 -1
  354. package/types/Ledger/index.d.ts.map +0 -1
  355. package/types/Network/IsMainnet.d.ts.map +0 -1
  356. package/types/Network/Params.d.ts.map +0 -1
  357. package/types/Network/UTxOsAt.d.ts +0 -9
  358. package/types/Network/UTxOsAt.d.ts.map +0 -1
  359. package/types/Network/errors.d.ts +0 -18
  360. package/types/Network/errors.d.ts.map +0 -1
  361. package/types/Network/index.d.ts.map +0 -1
  362. package/types/Uplc/Cek.d.ts +0 -72
  363. package/types/Uplc/Cek.d.ts.map +0 -1
  364. package/types/Uplc/Data.d.ts.map +0 -1
  365. package/types/Uplc/DataSchema.d.ts +0 -227
  366. package/types/Uplc/DataSchema.d.ts.map +0 -1
  367. package/types/Uplc/Primitive.d.ts +0 -26
  368. package/types/Uplc/Primitive.d.ts.map +0 -1
  369. package/types/Uplc/index.d.ts +0 -3
  370. package/types/Uplc/index.d.ts.map +0 -1
  371. package/types/internal/Base32.d.ts.map +0 -1
  372. package/types/internal/BigEndian.d.ts.map +0 -1
  373. package/types/internal/Bits.d.ts.map +0 -1
  374. package/types/internal/Bytes.d.ts.map +0 -1
  375. package/types/internal/Flat.d.ts.map +0 -1
  376. package/types/internal/Float.d.ts.map +0 -1
  377. package/types/internal/Utf8.d.ts.map +0 -1
  378. /package/dist/{Network → Cardano/Network}/IsMainnet.js +0 -0
  379. /package/dist/{internal → Codecs}/BigEndian.js +0 -0
  380. /package/dist/{internal → Codecs}/Bits.js +0 -0
  381. /package/dist/{internal → Codecs}/Float.js +0 -0
  382. /package/types/{Network → Cardano/Network}/IsMainnet.d.ts +0 -0
  383. /package/types/{internal → Codecs}/Base32.d.ts +0 -0
  384. /package/types/{Bech32.d.ts → Codecs/Bech32.d.ts} +0 -0
  385. /package/types/{internal → Codecs}/BigEndian.d.ts +0 -0
  386. /package/types/{internal → Codecs}/Bits.d.ts +0 -0
  387. /package/types/{internal → Codecs}/Float.d.ts +0 -0
@@ -1,8 +1,8 @@
1
- import { Data, Effect, Either } from "effect";
2
- import * as BigEndian from "./internal/BigEndian.js";
3
- import * as Bytes from "./internal/Bytes.js";
4
- import * as Float from "./internal/Float.js";
5
- import * as Utf8 from "./internal/Utf8.js";
1
+ import { Data, Either } from "effect";
2
+ import * as BigEndian from "./BigEndian.js";
3
+ import * as Bytes from "./Bytes.js";
4
+ import * as Float from "./Float.js";
5
+ import * as Utf8 from "./Utf8.js";
6
6
  const FALSE_BYTE = 244; // m = 7, n = 20
7
7
  const TRUE_BYTE = 245; // m = 7, n = 21
8
8
  export class DecodeError extends Data.TaggedError("Cbor.DecodeError") {
@@ -16,19 +16,20 @@ export class DecodeError extends Data.TaggedError("Cbor.DecodeError") {
16
16
  * @param bytes
17
17
  * @returns
18
18
  */
19
- export const decodeBool = (bytes) => Effect.gen(function* () {
19
+ export const decodeBool = (bytes) => {
20
20
  const stream = Bytes.makeStream(bytes);
21
- const b = yield* stream.shiftOne();
22
- if (b == TRUE_BYTE) {
23
- return true;
24
- }
25
- else if (b == FALSE_BYTE) {
26
- return false;
27
- }
28
- else {
29
- return yield* new DecodeError(stream, "unexpected non-boolean cbor object");
30
- }
31
- });
21
+ return stream.shiftOne().pipe(Either.flatMap((b) => {
22
+ if (b == TRUE_BYTE) {
23
+ return Either.right(true);
24
+ }
25
+ else if (b == FALSE_BYTE) {
26
+ return Either.right(false);
27
+ }
28
+ else {
29
+ return Either.left(new DecodeError(stream, "unexpected non-boolean cbor object"));
30
+ }
31
+ }));
32
+ };
32
33
  /**
33
34
  * Encodes a `boolean` into its CBOR representation.
34
35
  * @param b
@@ -46,41 +47,54 @@ export function encodeBool(b) {
46
47
  * @param bytes
47
48
  * @returns
48
49
  */
49
- export const isBool = (bytes) => Bytes.makeStream(bytes)
50
- .peekOne()
51
- .pipe(Effect.map((head) => head == FALSE_BYTE || head == TRUE_BYTE));
50
+ export const isBool = (bytes) => {
51
+ const head = Bytes.makeStream(bytes).peekOne();
52
+ if (Either.isLeft(head)) {
53
+ return false;
54
+ }
55
+ return head.right == FALSE_BYTE || head.right == TRUE_BYTE;
56
+ };
57
+ const decodeIndefBytes = (stream) => Either.gen(function* () {
58
+ yield* stream.shiftOne();
59
+ // multiple chunks
60
+ let res = [];
61
+ let next = yield* stream.peekOne();
62
+ while (next != 255) {
63
+ const [, n] = yield* decodeDefHead(stream);
64
+ if (n > 64n) {
65
+ return yield* Either.left(new DecodeError(stream, "Bytearray chunk too large"));
66
+ }
67
+ const chunk = yield* stream.shiftMany(Number(n));
68
+ res = res.concat(chunk);
69
+ next = yield* stream.peekOne();
70
+ }
71
+ const last = yield* stream.shiftOne();
72
+ if (last != 255) {
73
+ return yield* Either.left(new DecodeError(stream, "invalid indef bytes termination byte"));
74
+ }
75
+ return res;
76
+ });
77
+ const decodeDefBytes = (stream) => decodeDefHead(stream).pipe(Either.flatMap(([m, n]) => {
78
+ if (m != 2) {
79
+ return Either.left(new DecodeError(stream, "Invalid def bytes"));
80
+ }
81
+ return stream.shiftMany(Number(n));
82
+ }));
52
83
  /**
53
84
  * Unwraps a CBOR encoded list of bytes
54
85
  * @param bytes
55
86
  * cborbytes, mutated to form remaining
56
87
  * @returns byteArray
57
88
  */
58
- export const decodeBytes = (bytes) => Effect.gen(function* () {
89
+ export const decodeBytes = (bytes) => {
59
90
  const stream = Bytes.makeStream(bytes);
60
- if (yield* isIndefBytes(bytes)) {
61
- yield* stream.shiftOne();
62
- // multiple chunks
63
- let res = [];
64
- while ((yield* stream.peekOne()) != 255) {
65
- const [, n] = yield* decodeDefHead(stream);
66
- if (n > 64n) {
67
- return yield* new DecodeError(stream, "Bytearray chunk too large");
68
- }
69
- res = res.concat(yield* stream.shiftMany(Number(n)));
70
- }
71
- if ((yield* stream.shiftOne()) != 255) {
72
- throw new Error("invalid indef bytes termination byte");
73
- }
74
- return res;
91
+ if (isIndefBytes(bytes)) {
92
+ return decodeIndefBytes(stream);
75
93
  }
76
94
  else {
77
- const [m, n] = yield* decodeDefHead(stream);
78
- if (m != 2) {
79
- return yield* new DecodeError(stream, "Invalid def bytes");
80
- }
81
- return yield* stream.shiftMany(Number(n));
95
+ return decodeDefBytes(stream);
82
96
  }
83
- });
97
+ };
84
98
  /**
85
99
  * Wraps a list of bytes using CBOR. Optionally splits the bytes into chunks.
86
100
  * @example
@@ -90,8 +104,8 @@ export const decodeBytes = (bytes) => Effect.gen(function* () {
90
104
  * @returns
91
105
  * cbor bytes
92
106
  */
93
- export function encodeBytes(bytes, splitIntoChunks = false) {
94
- bytes = Bytes.toArray(bytes).slice();
107
+ export function encodeBytes(bs, splitIntoChunks = false) {
108
+ const bytes = Bytes.toArray(bs).slice();
95
109
  if (bytes.length <= 64 || !splitIntoChunks) {
96
110
  const head = encodeDefHead(2, BigInt(bytes.length));
97
111
  return head.concat(bytes);
@@ -110,23 +124,40 @@ export function encodeBytes(bytes, splitIntoChunks = false) {
110
124
  * @param bytes
111
125
  * @returns
112
126
  */
113
- export const isBytes = (bytes) => peekMajorType(bytes).pipe(Effect.map((m) => m == 2));
127
+ export const isBytes = (bytes) => {
128
+ const m = peekMajorType(bytes);
129
+ if (Either.isLeft(m)) {
130
+ return false;
131
+ }
132
+ return m.right == 2;
133
+ };
114
134
  /**
115
135
  * @param bytes
116
136
  * @returns
117
137
  */
118
- export const isDefBytes = (bytes) => Effect.gen(function* () {
138
+ export const isDefBytes = (bytes) => {
119
139
  const stream = Bytes.makeStream(bytes);
120
- const m = yield* peekMajorType(stream);
121
- return m == 2 && (yield* stream.peekOne()) != 2 * 32 + 31;
122
- });
140
+ const m = peekMajorType(stream);
141
+ if (Either.isLeft(m)) {
142
+ return false;
143
+ }
144
+ const n = stream.peekOne();
145
+ if (Either.isLeft(n)) {
146
+ return false;
147
+ }
148
+ return m.right == 2 && n.right != 2 * 32 + 31;
149
+ };
123
150
  /**
124
151
  * @param bytes
125
152
  * @returns
126
153
  */
127
- export const isIndefBytes = (bytes) => Bytes.makeStream(bytes)
128
- .peekOne()
129
- .pipe(Effect.map((head) => head == 2 * 32 + 31));
154
+ export const isIndefBytes = (bytes) => {
155
+ const head = Bytes.makeStream(bytes).peekOne();
156
+ if (Either.isLeft(head)) {
157
+ return false;
158
+ }
159
+ return head.right == 2 * 32 + 31;
160
+ };
130
161
  /**
131
162
  * The homogenous field type case is used by the uplc ConstrData (undetermined number of UplcData items)
132
163
  * @template Decoders
@@ -135,26 +166,24 @@ export const isIndefBytes = (bytes) => Bytes.makeStream(bytes)
135
166
  * Array for heterogenous item types, single function for homogenous item types
136
167
  * @returns
137
168
  */
138
- export const decodeConstr = (fieldDecoder) => (bytes) => Effect.gen(function* () {
169
+ export const decodeConstr = (fieldDecoder) => (bytes) => Either.gen(function* () {
139
170
  const stream = Bytes.makeStream(bytes);
140
171
  const tag = yield* decodeConstrTag(stream);
141
- const res = yield* decodeList((itemStream, i) => Effect.gen(function* () {
172
+ const res = yield* decodeList((itemStream, i) => {
142
173
  if (Array.isArray(fieldDecoder)) {
143
174
  const decoder = fieldDecoder[i];
144
175
  if (decoder === undefined) {
145
- return yield* new DecodeError(stream, `expected ${fieldDecoder.length} fields, got more than ${i}`);
176
+ return Either.left(new DecodeError(stream, `expected ${fieldDecoder.length} fields, got more than ${i}`));
146
177
  }
147
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
148
- return yield* decoder(itemStream);
178
+ return decoder(itemStream);
149
179
  }
150
180
  else {
151
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
152
- return yield* fieldDecoder(itemStream);
181
+ return fieldDecoder(itemStream);
153
182
  }
154
- }))(stream);
183
+ })(stream);
155
184
  if (Array.isArray(fieldDecoder)) {
156
185
  if (res.length < fieldDecoder.length) {
157
- return yield* new DecodeError(stream, `expected ${fieldDecoder.length} fields, only got ${res.length}`);
186
+ return yield* Either.left(new DecodeError(stream, `expected ${fieldDecoder.length} fields, only got ${res.length}`));
158
187
  }
159
188
  }
160
189
  return [tag, res];
@@ -163,49 +192,55 @@ export const decodeConstr = (fieldDecoder) => (bytes) => Effect.gen(function* ()
163
192
  * @param bytes
164
193
  * @returns
165
194
  */
166
- export const decodeConstrLazy = (bytes) => Effect.gen(function* () {
195
+ export const decodeConstrLazy = (bytes) => {
167
196
  const stream = Bytes.makeStream(bytes);
168
- const tag = yield* decodeConstrTag(stream);
169
- const decodeField = yield* decodeListLazy(bytes);
170
- return [tag, decodeField];
171
- });
197
+ return Either.zipWith(decodeConstrTag(stream), decodeListLazy(bytes), (tag, decodeField) => [tag, decodeField]);
198
+ };
172
199
  /**
173
200
  * @param bytes
174
201
  * @returns
175
202
  */
176
- const decodeConstrTag = (bytes) => Effect.gen(function* () {
203
+ const decodeConstrTag = (bytes) => {
177
204
  const stream = Bytes.makeStream(bytes);
178
205
  // constr
179
- const [m, n] = yield* decodeDefHead(stream);
206
+ const head = decodeDefHead(stream);
207
+ if (Either.isLeft(head)) {
208
+ return Either.left(head.left);
209
+ }
210
+ const [m, n] = head.right;
180
211
  if (m != 6) {
181
- return yield* new DecodeError(stream, "Unexpected constr tag head");
212
+ return Either.left(new DecodeError(stream, "Unexpected constr tag head"));
182
213
  }
183
214
  if (n < 102n) {
184
- return yield* new DecodeError(stream, `unexpected encoded constr tag ${n}`);
215
+ return Either.left(new DecodeError(stream, `unexpected encoded constr tag ${n}`));
185
216
  }
186
217
  else if (n == 102n) {
187
- const [mCheck, nCheck] = yield* decodeDefHead(stream);
218
+ const check = decodeDefHead(stream);
219
+ if (Either.isLeft(check)) {
220
+ return Either.left(check.left);
221
+ }
222
+ const [mCheck, nCheck] = check.right;
188
223
  if (mCheck != 4 || nCheck != 2n) {
189
- return yield* new DecodeError(stream, "Unexpected constr tag nested head");
224
+ return Either.left(new DecodeError(stream, "Unexpected constr tag nested head"));
190
225
  }
191
- return Number(yield* decodeInt(stream));
226
+ return decodeInt(stream).pipe(Either.map(Number));
192
227
  }
193
228
  else if (n < 121n) {
194
- return yield* new DecodeError(stream, `unexpected encoded constr tag ${n}`);
229
+ return Either.left(new DecodeError(stream, `unexpected encoded constr tag ${n}`));
195
230
  }
196
231
  else if (n <= 127n) {
197
- return Number(n - 121n);
232
+ return Either.right(Number(n - 121n));
198
233
  }
199
234
  else if (n < 1280n) {
200
- return yield* new DecodeError(stream, `unexpected encoded constr tag ${n}`);
235
+ return Either.left(new DecodeError(stream, `unexpected encoded constr tag ${n}`));
201
236
  }
202
237
  else if (n <= 1400n) {
203
- return Number(n - 1280n + 7n);
238
+ return Either.right(Number(n - 1280n + 7n));
204
239
  }
205
240
  else {
206
- return yield* new DecodeError(stream, `unexpected encoded constr tag ${n}`);
241
+ return Either.left(new DecodeError(stream, `unexpected encoded constr tag ${n}`));
207
242
  }
208
- });
243
+ };
209
244
  /**
210
245
  * Note: internally the indef list format is used if the number of fields is > 0, if the number of fields is 0 the def list format is used
211
246
  * see [well-typed/cborg/serialise/src/Codec/Serialise/Class.hs](https://github.com/well-typed/cborg/blob/4bdc818a1f0b35f38bc118a87944630043b58384/serialise/src/Codec/Serialise/Class.hs#L181).
@@ -243,73 +278,93 @@ function encodeConstrTag(tag) {
243
278
  * @param bytes
244
279
  * @returns
245
280
  */
246
- export const isConstr = (bytes) => decodeDefHead(Bytes.makeStream(bytes).copy()).pipe(Effect.map(([m, n]) => {
247
- if (m == 6) {
248
- return (n == 102n || (n >= 121n && n <= 127n) || (n >= 1280n && n <= 1400n));
281
+ export const isConstr = (bytes) => {
282
+ const head = decodeDefHead(Bytes.makeStream(bytes).copy());
283
+ if (Either.isLeft(head)) {
284
+ return false;
249
285
  }
250
- else {
286
+ const [m, n] = head.right;
287
+ if (m != 6) {
251
288
  return false;
252
289
  }
253
- }), Effect.catchTag("Cbor.DecodeError", () => {
254
- return Effect.succeed(false);
255
- }));
290
+ return n == 102n || (n >= 121n && n <= 127n) || (n >= 1280n && n <= 1400n);
291
+ };
256
292
  const FLOAT16_HEAD = 249;
257
293
  const FLOAT32_HEAD = 250;
258
294
  const FLOAT64_HEAD = 251;
295
+ const decodeFloat16Body = (stream) => stream.shiftMany(2).pipe(Either.flatMap(Float.decodeFloat16), Either.mapLeft((e) => {
296
+ return e._tag == "DecodeException"
297
+ ? new DecodeError(stream, `failed to decode float16 (${e.message})`)
298
+ : e;
299
+ }));
300
+ const decodeFloat32Body = (stream) => stream.shiftMany(4).pipe(Either.flatMap(Float.decodeFloat32), Either.mapLeft((e) => {
301
+ return e._tag == "DecodeException"
302
+ ? new DecodeError(stream, `failed to decode float32 (${e.message})`)
303
+ : e;
304
+ }));
305
+ const decodeFloat64Body = (stream) => stream.shiftMany(8).pipe(Either.flatMap(Float.decodeFloat64), Either.mapLeft((e) => {
306
+ return e._tag == "DecodeException"
307
+ ? new DecodeError(stream, `failed to decode float64 (${e.message})`)
308
+ : e;
309
+ }));
259
310
  /**
260
311
  * @param bytes
261
312
  * @returns
262
313
  */
263
- export const decodeFloat = (bytes) => Effect.gen(function* () {
314
+ export const decodeFloat = (bytes) => {
264
315
  const stream = Bytes.makeStream(bytes);
265
- const head = yield* stream.shiftOne();
266
- switch (head) {
267
- case FLOAT16_HEAD:
268
- return yield* Either.mapLeft(Float.decodeFloat16(yield* stream.shiftMany(2)), (e) => new DecodeError(stream, `failed to decode float16 (${e.message})`));
269
- case FLOAT32_HEAD:
270
- return yield* Either.mapLeft(Float.decodeFloat32(yield* stream.shiftMany(4)), (e) => new DecodeError(stream, `failed to decode float32 (${e.message})`));
271
- case FLOAT64_HEAD:
272
- return yield* Either.mapLeft(Float.decodeFloat64(yield* stream.shiftMany(8)), (e) => new DecodeError(stream, `faild to decode float64 (${e.message})`));
273
- default:
274
- return yield* new DecodeError(stream, "invalid float header");
275
- }
276
- });
316
+ return stream.shiftOne().pipe(Either.flatMap((head) => {
317
+ switch (head) {
318
+ case FLOAT16_HEAD:
319
+ return decodeFloat16Body(stream);
320
+ case FLOAT32_HEAD:
321
+ return decodeFloat32Body(stream);
322
+ case FLOAT64_HEAD:
323
+ return decodeFloat64Body(stream);
324
+ default:
325
+ return Either.left(new DecodeError(stream, "invalid float header"));
326
+ }
327
+ }));
328
+ };
277
329
  /**
278
330
  * @param bytes
279
331
  * @returns
280
332
  */
281
- export const decodeFloat16 = (bytes) => Effect.gen(function* () {
333
+ export const decodeFloat16 = (bytes) => {
282
334
  const stream = Bytes.makeStream(bytes);
283
- const head = yield* stream.shiftOne();
284
- if (head != FLOAT16_HEAD) {
285
- return yield* new DecodeError(stream, "invalid Float16 header");
286
- }
287
- return yield* Either.mapLeft(Float.decodeFloat16(yield* stream.shiftMany(2)), (e) => new DecodeError(stream, `failed to decode float16 (${e.message})`));
288
- });
335
+ return stream.shiftOne().pipe(Either.flatMap((head) => {
336
+ if (head != FLOAT16_HEAD) {
337
+ return Either.left(new DecodeError(stream, "invalid Float16 header"));
338
+ }
339
+ return decodeFloat16Body(stream);
340
+ }));
341
+ };
289
342
  /**
290
343
  * @param bytes
291
344
  * @returns
292
345
  */
293
- export const decodeFloat32 = (bytes) => Effect.gen(function* () {
346
+ export const decodeFloat32 = (bytes) => {
294
347
  const stream = Bytes.makeStream(bytes);
295
- const head = yield* stream.shiftOne();
296
- if (head != FLOAT32_HEAD) {
297
- return yield* new DecodeError(stream, "invalid Float32 header");
298
- }
299
- return yield* Either.mapLeft(Float.decodeFloat32(yield* stream.shiftMany(4)), (e) => new DecodeError(stream, `failed to decode float32 (${e.message})`));
300
- });
348
+ return stream.shiftOne().pipe(Either.flatMap((head) => {
349
+ if (head != FLOAT32_HEAD) {
350
+ return Either.left(new DecodeError(stream, "invalid Float32 header"));
351
+ }
352
+ return decodeFloat32Body(stream);
353
+ }));
354
+ };
301
355
  /**
302
356
  * @param bytes
303
357
  * @returns
304
358
  */
305
- export const decodeFloat64 = (bytes) => Effect.gen(function* () {
359
+ export const decodeFloat64 = (bytes) => {
306
360
  const stream = Bytes.makeStream(bytes);
307
- const head = yield* stream.shiftOne();
308
- if (head != FLOAT64_HEAD) {
309
- return yield* new DecodeError(stream, "invalid Float64 header");
310
- }
311
- return yield* Either.mapLeft(Float.decodeFloat64(yield* stream.shiftMany(8)), (e) => new DecodeError(stream, `failed to decode float32 (${e.message})`));
312
- });
361
+ return stream.shiftOne().pipe(Either.flatMap((head) => {
362
+ if (head != FLOAT64_HEAD) {
363
+ return Either.left(new DecodeError(stream, "invalid Float64 header"));
364
+ }
365
+ return decodeFloat64Body(stream);
366
+ }));
367
+ };
313
368
  /**
314
369
  * @param f
315
370
  * @returns
@@ -335,30 +390,48 @@ export function encodeFloat64(f) {
335
390
  * @param bytes
336
391
  * @returns
337
392
  */
338
- export const isFloat = (bytes) => Bytes.makeStream(bytes)
339
- .peekOne()
340
- .pipe(Effect.map((head) => head == FLOAT16_HEAD || head == FLOAT32_HEAD || head == FLOAT64_HEAD));
393
+ export const isFloat = (bytes) => {
394
+ const head = Bytes.makeStream(bytes).peekOne();
395
+ if (Either.isLeft(head)) {
396
+ return false;
397
+ }
398
+ return (head.right == FLOAT16_HEAD ||
399
+ head.right == FLOAT32_HEAD ||
400
+ head.right == FLOAT64_HEAD);
401
+ };
341
402
  /**
342
403
  * @param bytes
343
404
  * @returns
344
405
  */
345
- export const isFloat16 = (bytes) => Bytes.makeStream(bytes)
346
- .peekOne()
347
- .pipe(Effect.map((head) => head == FLOAT16_HEAD));
406
+ export const isFloat16 = (bytes) => {
407
+ const head = Bytes.makeStream(bytes).peekOne();
408
+ if (Either.isLeft(head)) {
409
+ return false;
410
+ }
411
+ return head.right == FLOAT16_HEAD;
412
+ };
348
413
  /**
349
414
  * @param bytes
350
415
  * @returns
351
416
  */
352
- export const isFloat32 = (bytes) => Bytes.makeStream(bytes)
353
- .peekOne()
354
- .pipe(Effect.map((head) => head == FLOAT32_HEAD));
417
+ export const isFloat32 = (bytes) => {
418
+ const head = Bytes.makeStream(bytes).peekOne();
419
+ if (Either.isLeft(head)) {
420
+ return false;
421
+ }
422
+ return head.right == FLOAT32_HEAD;
423
+ };
355
424
  /**
356
425
  * @param bytes
357
426
  * @returns
358
427
  */
359
- export const isFloat64 = (bytes) => Bytes.makeStream(bytes)
360
- .peekOne()
361
- .pipe(Effect.map((head) => head == FLOAT64_HEAD));
428
+ export const isFloat64 = (bytes) => {
429
+ const head = Bytes.makeStream(bytes).peekOne();
430
+ if (Either.isLeft(head)) {
431
+ return false;
432
+ }
433
+ return head.right == FLOAT64_HEAD;
434
+ };
362
435
  /**
363
436
  * @param b0
364
437
  * @returns
@@ -373,47 +446,64 @@ function decodeFirstHeadByte(b0) {
373
446
  * @returns
374
447
  * [majorType, n]
375
448
  */
376
- export const decodeDefHead = (bytes) => Effect.gen(function* () {
449
+ export const decodeDefHead = (bytes) => {
377
450
  const stream = Bytes.makeStream(bytes);
378
451
  if (stream.isAtEnd()) {
379
- return yield* new DecodeError(stream, "Empty CBOR head");
452
+ return Either.left(new DecodeError(stream, "Empty CBOR head"));
453
+ }
454
+ const first = stream.shiftOne();
455
+ if (Either.isLeft(first)) {
456
+ return Either.left(first.left);
380
457
  }
381
- const first = yield* stream.shiftOne();
382
- const [m, n0] = decodeFirstHeadByte(first);
458
+ const [m, n0] = decodeFirstHeadByte(first.right);
383
459
  if (n0 <= 23) {
384
- return [m, BigInt(n0)];
460
+ return Either.right([m, BigInt(n0)]);
385
461
  }
386
462
  else if (n0 == 24) {
387
- const l = yield* decodeIntInternal(stream, 1);
388
- return [m, l];
463
+ const l = decodeIntInternal(stream, 1);
464
+ if (Either.isLeft(l)) {
465
+ return Either.left(l.left);
466
+ }
467
+ return Either.right([m, l.right]);
389
468
  }
390
469
  else if (n0 == 25) {
391
470
  if (m == 7) {
392
- return yield* new DecodeError(stream, "Unexpected float16 (hint: decode float16 by calling decodeFloat16 directly)");
471
+ return Either.left(new DecodeError(stream, "Unexpected float16 (hint: decode float16 by calling decodeFloat16 directly)"));
472
+ }
473
+ const n = decodeIntInternal(stream, 2);
474
+ if (Either.isLeft(n)) {
475
+ return Either.left(n.left);
393
476
  }
394
- const n = yield* decodeIntInternal(stream, 2);
395
- return [m, n];
477
+ return Either.right([m, n.right]);
396
478
  }
397
479
  else if (n0 == 26) {
398
480
  if (m == 7) {
399
- return yield* new DecodeError(stream, "Unexpected float32 (hint: decode float32 by calling decodeFloat32 directly)");
481
+ return Either.left(new DecodeError(stream, "Unexpected float32 (hint: decode float32 by calling decodeFloat32 directly)"));
482
+ }
483
+ const n = decodeIntInternal(stream, 4);
484
+ if (Either.isLeft(n)) {
485
+ return Either.left(n.left);
400
486
  }
401
- return [m, yield* decodeIntInternal(stream, 4)];
487
+ return Either.right([m, n.right]);
402
488
  }
403
489
  else if (n0 == 27) {
404
490
  if (m == 7) {
405
- return yield* new DecodeError(stream, "Unexpected float64 (hint: decode float64 by calling decodeFloat64 directly)");
491
+ return Either.left(new DecodeError(stream, "Unexpected float64 (hint: decode float64 by calling decodeFloat64 directly)"));
406
492
  }
407
- return [m, yield* decodeIntInternal(stream, 8)];
493
+ const n = decodeIntInternal(stream, 8);
494
+ if (Either.isLeft(n)) {
495
+ return Either.left(n.left);
496
+ }
497
+ return Either.right([m, n.right]);
408
498
  }
409
499
  else if ((m == 2 || m == 3 || m == 4 || m == 5 || m == 7) && n0 == 31) {
410
500
  // head value 31 is used an indefinite length marker for 2,3,4,5,7 (never for 0,1,6)
411
- return yield* new DecodeError(stream, `Unexpected header m=${m} n0=${n0} (expected def instead of indef)`);
501
+ return Either.left(new DecodeError(stream, `Unexpected header m=${m} n0=${n0} (expected def instead of indef)`));
412
502
  }
413
503
  else {
414
- return yield* new DecodeError(stream, "Bad CBOR header");
504
+ return Either.left(new DecodeError(stream, "Bad CBOR header"));
415
505
  }
416
- });
506
+ };
417
507
  /**
418
508
  * @param m major type
419
509
  * @param n size parameter
@@ -467,51 +557,48 @@ export function encodeIndefHead(m) {
467
557
  */
468
558
  export const peekMajorType = (bytes) => Bytes.makeStream(bytes)
469
559
  .peekOne()
470
- .pipe(Effect.map((head) => Math.trunc(head / 32)));
560
+ .pipe(Either.map((head) => Math.trunc(head / 32)));
471
561
  /**
472
562
  * @param bytes
473
563
  * @returns
474
564
  */
475
- export const peekMajorAndSimpleMinorType = (bytes) => Bytes.makeStream(bytes).peekOne().pipe(Effect.map(decodeFirstHeadByte));
565
+ export const peekMajorAndSimpleMinorType = (bytes) => Bytes.makeStream(bytes).peekOne().pipe(Either.map(decodeFirstHeadByte));
476
566
  /**
477
567
  * Decodes a CBOR encoded bigint integer.
478
568
  * @param bytes
479
569
  * @returns
480
570
  */
481
- export const decodeInt = (bytes) => Effect.gen(function* () {
571
+ export const decodeInt = (bytes) => {
482
572
  const stream = Bytes.makeStream(bytes);
483
- const [m, n] = yield* decodeDefHead(stream);
484
- if (m == 0) {
485
- return n;
486
- }
487
- else if (m == 1) {
488
- return -n - 1n;
489
- }
490
- else if (m == 6) {
491
- if (n == 2n) {
492
- return yield* decodeIntInternal(stream);
493
- }
494
- else if (n == 3n) {
495
- return -(yield* decodeIntInternal(stream)) - 1n;
573
+ return decodeDefHead(stream).pipe(Either.flatMap(([m, n]) => {
574
+ if (m == 0) {
575
+ return Either.right(n);
496
576
  }
497
- else {
498
- return yield* new DecodeError(stream, `Unexpected tag m:${m}`);
577
+ else if (m == 1) {
578
+ return Either.right(-n - 1n);
499
579
  }
500
- }
501
- else {
502
- return yield* new DecodeError(stream, `Unexpected tag m:${m}`);
503
- }
504
- });
505
- const decodeIntInternal = (stream, nBytes = undefined) => {
506
- return (nBytes === undefined ? decodeBytes(stream) : stream.shiftMany(nBytes)).pipe(Effect.map(BigEndian.decode), Effect.flatMap((result) => {
507
- if (result._tag == "Left") {
508
- return Effect.fail(new DecodeError(stream, `failed to decode BigEndian int (${result.left.message})`));
580
+ else if (m == 6) {
581
+ if (n == 2n) {
582
+ return decodeIntInternal(stream);
583
+ }
584
+ else if (n == 3n) {
585
+ return decodeIntInternal(stream).pipe(Either.map((x) => -x - 1n));
586
+ }
587
+ else {
588
+ return Either.left(new DecodeError(stream, `Unexpected tag m:${m}`));
589
+ }
509
590
  }
510
591
  else {
511
- return Effect.succeed(result.right);
592
+ return Either.left(new DecodeError(stream, `Unexpected tag m:${m}`));
512
593
  }
513
594
  }));
514
595
  };
596
+ export const decodeIntAsNumber = (bytes) => decodeInt(bytes).pipe(Either.map(Number));
597
+ const decodeIntInternal = (stream, nBytes = undefined) => {
598
+ return (nBytes === undefined ? decodeBytes(stream) : stream.shiftMany(nBytes)).pipe(Either.flatMap(BigEndian.decode), Either.mapLeft((e) => e._tag == "DecodeException"
599
+ ? new DecodeError(stream, `failed to decode BigEndian int (${e.message})`)
600
+ : e));
601
+ };
515
602
  /**
516
603
  * Encodes a bigint integer using CBOR.
517
604
  * @param n
@@ -538,7 +625,12 @@ export function encodeInt(n) {
538
625
  * @param bytes
539
626
  * @returns
540
627
  */
541
- export const isInt = (bytes) => peekMajorAndSimpleMinorType(bytes).pipe(Effect.map(([m, n0]) => {
628
+ export const isInt = (bytes) => {
629
+ const mn0 = peekMajorAndSimpleMinorType(bytes);
630
+ if (Either.isLeft(mn0)) {
631
+ return false;
632
+ }
633
+ const [m, n0] = mn0.right;
542
634
  if (m == 0 || m == 1) {
543
635
  return true;
544
636
  }
@@ -548,7 +640,32 @@ export const isInt = (bytes) => peekMajorAndSimpleMinorType(bytes).pipe(Effect.m
548
640
  else {
549
641
  return false;
550
642
  }
551
- }));
643
+ };
644
+ const decodeIndefList = (stream, itemDecoder) => Either.gen(function* () {
645
+ const res = [];
646
+ yield* stream.shiftOne();
647
+ let i = 0;
648
+ while ((yield* stream.peekOne()) != 255) {
649
+ res.push(yield* itemDecoder(stream, i));
650
+ i++;
651
+ }
652
+ const last = yield* stream.shiftOne();
653
+ if (last != 255) {
654
+ return yield* Either.left(new DecodeError(stream, "Invalid def list head byte"));
655
+ }
656
+ return res;
657
+ });
658
+ const decodeDefList = (stream, itemDecoder) => Either.gen(function* () {
659
+ const res = [];
660
+ const [m, n] = yield* decodeDefHead(stream);
661
+ if (m != 4) {
662
+ return yield* Either.left(new DecodeError(stream, "invalid def list head byte"));
663
+ }
664
+ for (let i = 0; i < Number(n); i++) {
665
+ res.push(yield* itemDecoder(stream, i));
666
+ }
667
+ return res;
668
+ });
552
669
  /**
553
670
  * Decodes a CBOR encoded list.
554
671
  * A decoder function is called with the bytes of every contained item (nothing is returning directly).
@@ -556,72 +673,56 @@ export const isInt = (bytes) => peekMajorAndSimpleMinorType(bytes).pipe(Effect.m
556
673
  * @param itemDecoder
557
674
  * @returns
558
675
  */
559
- export const decodeList = (itemDecoder) => (bytes) => Effect.gen(function* () {
676
+ export const decodeList = (itemDecoder) => (bytes) => {
560
677
  const stream = Bytes.makeStream(bytes);
561
- const res = [];
562
- if (yield* isIndefList(stream)) {
563
- yield* stream.shiftOne();
564
- let i = 0;
565
- while ((yield* stream.peekOne()) != 255) {
566
- res.push(yield* itemDecoder(stream, i));
567
- i++;
568
- }
569
- const last = yield* stream.shiftOne();
570
- if (last != 255) {
571
- return yield* new DecodeError(stream, "Invalid def list head byte");
572
- }
678
+ if (isIndefList(stream)) {
679
+ return decodeIndefList(stream, itemDecoder);
573
680
  }
574
681
  else {
575
- const [m, n] = yield* decodeDefHead(stream);
576
- if (m != 4) {
577
- return yield* new DecodeError(stream, "invalid def list head byte");
578
- }
579
- for (let i = 0; i < Number(n); i++) {
580
- res.push(yield* itemDecoder(stream, i));
581
- }
682
+ return decodeDefList(stream, itemDecoder);
582
683
  }
583
- return res;
584
- });
585
- /**
586
- * @param bytes
587
- * @returns
588
- *
589
- *
590
- */
591
- export const decodeListLazy = (bytes) => Effect.gen(function* () {
592
- const stream = Bytes.makeStream(bytes);
684
+ };
685
+ const decodeIndefListLazy = (stream) => Either.gen(function* () {
593
686
  let i = 0;
594
687
  let done = false;
595
- let checkDone;
596
- if (yield* isIndefList(stream)) {
688
+ yield* stream.shiftOne();
689
+ if ((yield* stream.peekOne()) == 255) {
597
690
  yield* stream.shiftOne();
598
- checkDone = () => Effect.gen(function* () {
599
- if ((yield* stream.peekOne()) == 255) {
600
- yield* stream.shiftOne();
601
- done = true;
602
- }
603
- });
691
+ done = true;
604
692
  }
605
- else {
606
- const [m, n] = yield* decodeDefHead(stream);
607
- if (m != 4) {
608
- return yield* new DecodeError(stream, "Unexpected header major type");
693
+ const decodeItem = (itemDecoder) => Either.gen(function* () {
694
+ if (done) {
695
+ return yield* Either.left(new DecodeError(stream, "end-of-list"));
609
696
  }
610
- checkDone = () => {
611
- if (i >= n) {
612
- done = true;
613
- }
614
- return Effect.void;
615
- };
697
+ const res = yield* itemDecoder(stream, i);
698
+ i++;
699
+ if ((yield* stream.peekOne()) == 255) {
700
+ yield* stream.shiftOne();
701
+ done = true;
702
+ }
703
+ return res;
704
+ });
705
+ return decodeItem;
706
+ });
707
+ const decodeDefListLazy = (stream) => Either.gen(function* () {
708
+ let i = 0;
709
+ let done = false;
710
+ const [m, n] = yield* decodeDefHead(stream);
711
+ if (m != 4) {
712
+ return yield* Either.left(new DecodeError(stream, "Unexpected header major type"));
713
+ }
714
+ if (i >= n) {
715
+ done = true;
616
716
  }
617
- yield* checkDone();
618
- const decodeItem = (itemDecoder) => Effect.gen(function* () {
717
+ const decodeItem = (itemDecoder) => Either.gen(function* () {
619
718
  if (done) {
620
- return yield* new DecodeError(stream, "end-of-list");
719
+ return yield* Either.left(new DecodeError(stream, "end-of-list"));
621
720
  }
622
721
  const res = yield* itemDecoder(stream, i);
623
722
  i++;
624
- yield* checkDone();
723
+ if (i >= n) {
724
+ done = true;
725
+ }
625
726
  return res;
626
727
  });
627
728
  return decodeItem;
@@ -630,44 +731,73 @@ export const decodeListLazy = (bytes) => Effect.gen(function* () {
630
731
  * @param bytes
631
732
  * @returns
632
733
  */
633
- export const decodeListLazyOption = (bytes) => Effect.gen(function* () {
734
+ export const decodeListLazy = (bytes) => {
634
735
  const stream = Bytes.makeStream(bytes);
736
+ if (isIndefList(stream)) {
737
+ return decodeIndefListLazy(stream);
738
+ }
739
+ else {
740
+ return decodeDefListLazy(stream);
741
+ }
742
+ };
743
+ const decodeIndefListLazyOption = (stream) => Either.gen(function* () {
635
744
  let i = 0;
636
745
  let done = false;
637
- let checkDone;
638
- if (yield* isIndefList(stream)) {
746
+ yield* stream.shiftOne();
747
+ if ((yield* stream.peekOne()) == 255) {
639
748
  yield* stream.shiftOne();
640
- checkDone = () => Effect.gen(function* () {
641
- if ((yield* stream.peekOne()) == 255) {
642
- yield* stream.shiftOne();
643
- done = true;
644
- }
645
- });
749
+ done = true;
646
750
  }
647
- else {
648
- const [m, n] = yield* decodeDefHead(stream);
649
- if (m != 4) {
650
- return yield* new DecodeError(stream, "Unexpected major type for list");
751
+ const decodeItem = (itemDecoder) => Either.gen(function* () {
752
+ if (done) {
753
+ return undefined;
651
754
  }
652
- checkDone = () => {
653
- if (i >= n) {
654
- done = true;
655
- }
656
- return Effect.void;
657
- };
755
+ const res = yield* itemDecoder(stream, i);
756
+ i++;
757
+ if ((yield* stream.peekOne()) == 255) {
758
+ yield* stream.shiftOne();
759
+ done = true;
760
+ }
761
+ return res;
762
+ });
763
+ return decodeItem;
764
+ });
765
+ const decodeDefListLazyOption = (stream) => Either.gen(function* () {
766
+ let i = 0;
767
+ let done = false;
768
+ const [m, n] = yield* decodeDefHead(stream);
769
+ if (m != 4) {
770
+ return yield* Either.left(new DecodeError(stream, "Unexpected major type for list"));
658
771
  }
659
- yield* checkDone();
660
- const decodeItem = (itemDecoder) => Effect.gen(function* () {
772
+ if (i >= n) {
773
+ done = true;
774
+ }
775
+ const decodeItem = (itemDecoder) => Either.gen(function* () {
661
776
  if (done) {
662
777
  return undefined;
663
778
  }
664
779
  const res = yield* itemDecoder(stream, i);
665
780
  i++;
666
- yield* checkDone();
781
+ if (i >= n) {
782
+ done = true;
783
+ }
667
784
  return res;
668
785
  });
669
786
  return decodeItem;
670
787
  });
788
+ /**
789
+ * @param bytes
790
+ * @returns
791
+ */
792
+ export const decodeListLazyOption = (bytes) => {
793
+ const stream = Bytes.makeStream(bytes);
794
+ if (isIndefList(stream)) {
795
+ return decodeIndefListLazyOption(stream);
796
+ }
797
+ else {
798
+ return decodeDefListLazyOption(stream);
799
+ }
800
+ };
671
801
  /**
672
802
  * This follows the serialization format that the Haskell input-output-hk/plutus UPLC evaluator (i.e. empty lists use `encodeDefList`, non-empty lists use `encodeIndefList`).
673
803
  * See [well-typed/cborg/serialise/src/Codec/Serialise/Class.hs](https://github.com/well-typed/cborg/blob/4bdc818a1f0b35f38bc118a87944630043b58384/serialise/src/Codec/Serialise/Class.hs#L181).
@@ -728,23 +858,40 @@ export function encodeDefList(items) {
728
858
  * @param bytes
729
859
  * @returns
730
860
  */
731
- export const isList = (bytes) => peekMajorType(bytes).pipe(Effect.map((m) => m == 4));
861
+ export const isList = (bytes) => {
862
+ const m = peekMajorType(bytes);
863
+ if (Either.isLeft(m)) {
864
+ return false;
865
+ }
866
+ return m.right == 4;
867
+ };
732
868
  /**
733
869
  * @param bytes
734
870
  * @returns
735
871
  */
736
- export const isDefList = (bytes) => Effect.gen(function* () {
872
+ export const isDefList = (bytes) => {
737
873
  const stream = Bytes.makeStream(bytes);
738
- return ((yield* peekMajorType(stream)) == 4 &&
739
- (yield* stream.peekOne()) != 4 * 32 + 31);
740
- });
874
+ const m = peekMajorType(stream);
875
+ if (Either.isLeft(m)) {
876
+ return false;
877
+ }
878
+ const n = stream.peekOne();
879
+ if (Either.isLeft(n)) {
880
+ return false;
881
+ }
882
+ return m.right == 4 && n.right != 4 * 32 + 31;
883
+ };
741
884
  /**
742
885
  * @param bytes
743
886
  * @returns
744
887
  */
745
- export const isIndefList = (bytes) => Bytes.makeStream(bytes)
746
- .peekOne()
747
- .pipe(Effect.map((head) => head == 4 * 32 + 31));
888
+ export const isIndefList = (bytes) => {
889
+ const head = Bytes.makeStream(bytes).peekOne();
890
+ if (Either.isLeft(head)) {
891
+ return false;
892
+ }
893
+ return head.right == 4 * 32 + 31;
894
+ };
748
895
  /**
749
896
  * Decodes a CBOR encoded map.
750
897
  * Calls a decoder function for each key-value pair (nothing is returned directly).
@@ -755,16 +902,16 @@ export const isIndefList = (bytes) => Bytes.makeStream(bytes)
755
902
  * @param valueDecoder
756
903
  * @returns
757
904
  */
758
- export const decodeMap = (keyDecoder, valueDecoder) => (bytes) => Effect.gen(function* () {
905
+ export const decodeMap = (keyDecoder, valueDecoder) => (bytes) => Either.gen(function* () {
759
906
  const stream = Bytes.makeStream(bytes);
760
- if (yield* isIndefMap(stream)) {
907
+ if (isIndefMap(stream)) {
761
908
  yield* stream.shiftOne();
762
909
  return yield* decodeIndefMap(stream, keyDecoder, valueDecoder);
763
910
  }
764
911
  else {
765
912
  const [m, n] = yield* decodeDefHead(stream);
766
913
  if (m != 5) {
767
- return yield* new DecodeError(stream, "invalid def map");
914
+ return yield* Either.left(new DecodeError(stream, "invalid def map"));
768
915
  }
769
916
  return yield* decodeDefMap(stream, Number(n), keyDecoder, valueDecoder);
770
917
  }
@@ -777,7 +924,7 @@ export const decodeMap = (keyDecoder, valueDecoder) => (bytes) => Effect.gen(fun
777
924
  * @param valueDecoder
778
925
  * @returns
779
926
  */
780
- const decodeDefMap = (stream, n, keyDecoder, valueDecoder) => Effect.gen(function* () {
927
+ const decodeDefMap = (stream, n, keyDecoder, valueDecoder) => Either.gen(function* () {
781
928
  const res = [];
782
929
  for (let i = 0; i < n; i++) {
783
930
  res.push([yield* keyDecoder(stream), yield* valueDecoder(stream)]);
@@ -793,7 +940,7 @@ const decodeDefMap = (stream, n, keyDecoder, valueDecoder) => Effect.gen(functio
793
940
  * @param valueDecoder
794
941
  * @returns
795
942
  */
796
- const decodeIndefMap = (stream, keyDecoder, valueDecoder) => Effect.gen(function* () {
943
+ const decodeIndefMap = (stream, keyDecoder, valueDecoder) => Either.gen(function* () {
797
944
  const res = [];
798
945
  while ((yield* stream.peekOne()) != 255) {
799
946
  res.push([yield* keyDecoder(stream), yield* valueDecoder(stream)]);
@@ -845,14 +992,24 @@ function encodeMapInternal(pairs) {
845
992
  * @param bytes
846
993
  * @returns
847
994
  */
848
- export const isMap = (bytes) => peekMajorType(bytes).pipe(Effect.map((m) => m == 5));
995
+ export const isMap = (bytes) => {
996
+ const m = peekMajorType(bytes);
997
+ if (Either.isLeft(m)) {
998
+ return false;
999
+ }
1000
+ return m.right == 5;
1001
+ };
849
1002
  /**
850
1003
  * @param bytes
851
1004
  * @returns
852
1005
  */
853
- const isIndefMap = (bytes) => Bytes.makeStream(bytes)
854
- .peekOne()
855
- .pipe(Effect.map((head) => head == 5 * 32 + 31));
1006
+ const isIndefMap = (bytes) => {
1007
+ const head = Bytes.makeStream(bytes).peekOne();
1008
+ if (Either.isLeft(head)) {
1009
+ return false;
1010
+ }
1011
+ return head.right == 5 * 32 + 31;
1012
+ };
856
1013
  const NULL_BYTE = 246; // m = 7, n = 22
857
1014
  /**
858
1015
  * Checks if next element in `bytes` is a `null`.
@@ -860,14 +1017,15 @@ const NULL_BYTE = 246; // m = 7, n = 22
860
1017
  * @param bytes
861
1018
  * @returns
862
1019
  */
863
- export const decodeNull = (bytes) => Effect.gen(function* () {
1020
+ export const decodeNull = (bytes) => {
864
1021
  const stream = Bytes.makeStream(bytes);
865
- const b = yield* stream.shiftOne();
866
- if (b != NULL_BYTE) {
867
- return yield* new DecodeError(stream, "not null");
868
- }
869
- return null;
870
- });
1022
+ return stream.shiftOne().pipe(Either.flatMap((b) => {
1023
+ if (b != NULL_BYTE) {
1024
+ return Either.left(new DecodeError(stream, "not null"));
1025
+ }
1026
+ return Either.right(null);
1027
+ }));
1028
+ };
871
1029
  /**
872
1030
  * Encode `null` into its CBOR representation.
873
1031
  * @param _null ignored
@@ -880,9 +1038,48 @@ export function encodeNull(_null = null) {
880
1038
  * @param bytes
881
1039
  * @returns
882
1040
  */
883
- export const isNull = (bytes) => Bytes.makeStream(bytes)
884
- .peekOne()
885
- .pipe(Effect.map((head) => head == NULL_BYTE));
1041
+ export const isNull = (bytes) => {
1042
+ const head = Bytes.makeStream(bytes).peekOne();
1043
+ if (Either.isLeft(head)) {
1044
+ return false;
1045
+ }
1046
+ return head.right == NULL_BYTE;
1047
+ };
1048
+ /**
1049
+ * @template T
1050
+ * @param decodeSome
1051
+ * @returns
1052
+ */
1053
+ export const decodeNullOption = (decodeSome) => (bytes) => {
1054
+ const stream = Bytes.makeStream(bytes);
1055
+ if (isNull(stream)) {
1056
+ return decodeNull(stream).pipe(Either.map(() => undefined));
1057
+ }
1058
+ else {
1059
+ return decodeSome(stream);
1060
+ }
1061
+ };
1062
+ /**
1063
+ * @param option
1064
+ * @returns
1065
+ */
1066
+ export function encodeNullOption(option) {
1067
+ return option ?? encodeNull();
1068
+ }
1069
+ /**
1070
+ * @template T
1071
+ * @param bytes
1072
+ * @param decodeSome
1073
+ * @returns
1074
+ */
1075
+ export const decodeListOption = (decodeSome) => (bytes) => decodeListLazyOption(bytes).pipe(Either.flatMap((decodeItem) => decodeItem(decodeSome)));
1076
+ /**
1077
+ * @param option
1078
+ * @returns
1079
+ */
1080
+ export function encodeListOption(option) {
1081
+ return encodeList(option ? [option] : []);
1082
+ }
886
1083
  /**
887
1084
  * Decodes a CBOR encoded object with integer keys.
888
1085
  * For each field a decoder is called which takes the field index and the field bytes as arguments.
@@ -893,16 +1090,15 @@ export const isNull = (bytes) => Bytes.makeStream(bytes)
893
1090
  export const decodeObjectIKey = (fieldDecoders) => (bytes) => {
894
1091
  const stream = Bytes.makeStream(bytes);
895
1092
  const res = {};
896
- return decodeMap(() => Effect.succeed(null), (pairStream) => Effect.gen(function* () {
1093
+ return decodeMap(() => Either.right(null), (pairStream) => Either.gen(function* () {
897
1094
  const key = Number(yield* decodeInt(pairStream));
898
1095
  const decoder = fieldDecoders[key];
899
1096
  if (decoder === undefined) {
900
- return yield* new DecodeError(pairStream, `unhandled object field ${key}`);
1097
+ return yield* Either.left(new DecodeError(pairStream, `unhandled object field ${key}`));
901
1098
  }
902
1099
  /* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */
903
1100
  res[key] = yield* decoder(pairStream);
904
- return Effect.void;
905
- }))(stream).pipe(Effect.map(() => {
1101
+ }))(stream).pipe(Either.map(() => {
906
1102
  return res;
907
1103
  }));
908
1104
  };
@@ -916,16 +1112,15 @@ export const decodeObjectIKey = (fieldDecoders) => (bytes) => {
916
1112
  export const decodeObjectSKey = (fieldDecoders) => (bytes) => {
917
1113
  const stream = Bytes.makeStream(bytes);
918
1114
  const res = {};
919
- return decodeMap(() => Effect.succeed(null), (pairStream) => Effect.gen(function* () {
1115
+ return decodeMap(() => Either.right(null), (pairStream) => Either.gen(function* () {
920
1116
  const key = yield* decodeString(pairStream);
921
1117
  const decoder = fieldDecoders[key];
922
1118
  if (decoder === undefined) {
923
- return yield* new DecodeError(pairStream, `unhandled object field ${key}`);
1119
+ return yield* Either.left(new DecodeError(pairStream, `unhandled object field ${key}`));
924
1120
  }
925
1121
  /* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */
926
1122
  res[key] = yield* decoder(pairStream);
927
- return Effect.void;
928
- }))(stream).pipe(Effect.map(() => {
1123
+ }))(stream).pipe(Either.map(() => {
929
1124
  return res;
930
1125
  }));
931
1126
  };
@@ -975,16 +1170,19 @@ const SET_TAG = 258n;
975
1170
  * @param itemDecoder
976
1171
  * @returns
977
1172
  */
978
- export const decodeSet = (itemDecoder) => (bytes) => Effect.gen(function* () {
1173
+ export const decodeSet = (itemDecoder) => (bytes) => {
979
1174
  const stream = Bytes.makeStream(bytes);
980
- if (yield* isTag(stream)) {
981
- const tag = yield* decodeTag(stream);
982
- if (tag != SET_TAG) {
983
- return yield* new DecodeError(stream, `expected tag ${SET_TAG} for set, got tag ${tag}`);
1175
+ if (isTag(stream)) {
1176
+ const tag = decodeTag(stream);
1177
+ if (Either.isLeft(tag)) {
1178
+ return Either.left(tag.left);
1179
+ }
1180
+ if (tag.right != SET_TAG) {
1181
+ return Either.left(new DecodeError(stream, `expected tag ${SET_TAG} for set, got tag ${tag.right}`));
984
1182
  }
985
1183
  }
986
- return yield* decodeList(itemDecoder)(stream);
987
- });
1184
+ return decodeList(itemDecoder)(stream);
1185
+ };
988
1186
  /**
989
1187
  * A tagged def list (tag 258n)
990
1188
  * @param items
@@ -997,36 +1195,45 @@ export function encodeSet(items) {
997
1195
  * @param bytes
998
1196
  * @returns
999
1197
  */
1000
- export const isSet = (bytes) => peekTag(bytes).pipe(Effect.map((t) => t == SET_TAG));
1198
+ export const isSet = (bytes) => {
1199
+ const t = peekTag(bytes);
1200
+ if (Either.isLeft(t)) {
1201
+ return false;
1202
+ }
1203
+ return t.right == SET_TAG;
1204
+ };
1205
+ const decodeSplitString = (stream) => decodeList((itemBytes) => decodeStringInternal(itemBytes))(stream).pipe(Either.map((parts) => parts.join("")));
1001
1206
  /**
1002
1207
  * @param bytes
1003
1208
  * @returns
1004
1209
  */
1005
- export const decodeString = (bytes) => Effect.gen(function* () {
1210
+ export const decodeString = (bytes) => {
1006
1211
  const stream = Bytes.makeStream(bytes);
1007
- if (yield* isDefList(stream)) {
1008
- let result = "";
1009
- yield* decodeList((itemBytes) => decodeStringInternal(itemBytes).pipe(Effect.tap((s) => {
1010
- result += s;
1011
- })))(stream);
1012
- return result;
1212
+ if (isDefList(stream)) {
1213
+ return decodeSplitString(stream);
1013
1214
  }
1014
1215
  else {
1015
- return yield* decodeStringInternal(stream);
1216
+ return decodeStringInternal(stream);
1016
1217
  }
1017
- });
1218
+ };
1018
1219
  /**
1019
1220
  * @param bytes
1020
1221
  * @returns
1021
1222
  */
1022
- const decodeStringInternal = (bytes) => Effect.gen(function* () {
1223
+ const decodeStringInternal = (bytes) => {
1023
1224
  const stream = Bytes.makeStream(bytes);
1024
- const [m, n] = yield* decodeDefHead(stream);
1025
- if (m !== 3) {
1026
- return yield* new DecodeError(stream, "unexpected");
1027
- }
1028
- return yield* Utf8.decode(yield* stream.shiftMany(Number(n))).pipe(Effect.mapError((e) => new DecodeError(stream, `invalid utf8 (${e.message})`)));
1029
- });
1225
+ return decodeDefHead(stream).pipe(Either.flatMap(([m, n]) => {
1226
+ if (m != 3) {
1227
+ return Either.left(new DecodeError(stream, "unexpected"));
1228
+ }
1229
+ return stream.shiftMany(Number(n));
1230
+ }), Either.flatMap(Utf8.decode), Either.mapLeft((e) => {
1231
+ if (e._tag == "DecodeException") {
1232
+ return new DecodeError(stream, `invalid utf8 (${e.message})`);
1233
+ }
1234
+ return e;
1235
+ }));
1236
+ };
1030
1237
  /**
1031
1238
  * Encodes a Utf8 string into Cbor bytes.
1032
1239
  * Strings can be split into lists with chunks of up to 64 bytes
@@ -1065,19 +1272,26 @@ export function encodeString(str, split = false) {
1065
1272
  * @param bytes
1066
1273
  * @returns
1067
1274
  */
1068
- export const isString = (bytes) => peekMajorType(bytes).pipe(Effect.map((m) => m == 3));
1275
+ export const isString = (bytes) => {
1276
+ const m = peekMajorType(bytes);
1277
+ if (Either.isLeft(m)) {
1278
+ return false;
1279
+ }
1280
+ return m.right == 3;
1281
+ };
1069
1282
  /**
1070
1283
  * @param bytes
1071
1284
  * @returns
1072
1285
  */
1073
- export const decodeTag = (bytes) => Effect.gen(function* () {
1286
+ export const decodeTag = (bytes) => {
1074
1287
  const stream = Bytes.makeStream(bytes);
1075
- const [m, n] = yield* decodeDefHead(stream);
1076
- if (m != 6) {
1077
- return yield* new DecodeError(stream, "unexpected major type for tag");
1078
- }
1079
- return n;
1080
- });
1288
+ return decodeDefHead(stream).pipe(Either.flatMap(([m, n]) => {
1289
+ if (m != 6) {
1290
+ return Either.left(new DecodeError(stream, "unexpected major type for tag"));
1291
+ }
1292
+ return Either.right(n);
1293
+ }));
1294
+ };
1081
1295
  /**
1082
1296
  * Unrelated to constructor
1083
1297
  * @param tag
@@ -1096,19 +1310,36 @@ export function encodeTag(tag) {
1096
1310
  * @param bytes
1097
1311
  * @returns
1098
1312
  */
1099
- export const isTag = (bytes) => peekMajorType(bytes).pipe(Effect.map((m) => m == 6));
1313
+ export const isTag = (bytes) => {
1314
+ const m = peekMajorType(bytes);
1315
+ if (Either.isLeft(m)) {
1316
+ return false;
1317
+ }
1318
+ return m.right == 6;
1319
+ };
1100
1320
  /**
1101
1321
  * @param bytes
1102
1322
  * @returns
1103
1323
  */
1104
- export const peekTag = (bytes) => decodeTag(Bytes.makeStream(bytes).copy()).pipe(Effect.catchTag("Cbor.DecodeError", () => Effect.succeed(undefined)));
1324
+ export const peekTag = (bytes) => {
1325
+ const t = decodeTag(Bytes.makeStream(bytes).copy());
1326
+ if (Either.isLeft(t)) {
1327
+ if (t.left._tag == "Cbor.DecodeError") {
1328
+ return Either.right(undefined);
1329
+ }
1330
+ else {
1331
+ return Either.left(t.left);
1332
+ }
1333
+ }
1334
+ return Either.right(t.right);
1335
+ };
1105
1336
  /**
1106
1337
  * @param bytes
1107
1338
  * @returns
1108
1339
  */
1109
- export const decodeTagged = (bytes) => Effect.gen(function* () {
1340
+ export const decodeTagged = (bytes) => Either.gen(function* () {
1110
1341
  const stream = Bytes.makeStream(bytes);
1111
- if (yield* isList(stream)) {
1342
+ if (isList(stream)) {
1112
1343
  const decodeItem = yield* decodeListLazy(stream);
1113
1344
  const tag = Number(yield* decodeItem(decodeInt));
1114
1345
  return [tag, decodeItem];
@@ -1125,25 +1356,25 @@ export const decodeTagged = (bytes) => Effect.gen(function* () {
1125
1356
  * Defaults to empty tuple
1126
1357
  * @returns
1127
1358
  */
1128
- export const decodeTuple = (itemDecoders, optionalDecoders = []) => (bytes) => Effect.gen(function* () {
1359
+ export const decodeTuple = (itemDecoders, optionalDecoders = []) => (bytes) => Either.gen(function* () {
1129
1360
  const stream = Bytes.makeStream(bytes);
1130
1361
  /**
1131
1362
  * decodeList is the right decoder, but has the wrong type interface
1132
1363
  * Cast the result to `any` to avoid type errors
1133
1364
  */
1134
- const res = yield* decodeList((itemStream, i) => Effect.gen(function* () {
1365
+ const res = yield* decodeList((itemStream, i) => Either.gen(function* () {
1135
1366
  let decoder = itemDecoders[i];
1136
1367
  if (decoder === undefined) {
1137
1368
  decoder = optionalDecoders[i - itemDecoders.length];
1138
1369
  if (decoder === undefined) {
1139
- return yield* new DecodeError(itemStream, `expected at most ${itemDecoders.length + optionalDecoders.length} items, got more than ${i}`);
1370
+ return yield* Either.left(new DecodeError(itemStream, `expected at most ${itemDecoders.length + optionalDecoders.length} items, got more than ${i}`));
1140
1371
  }
1141
1372
  }
1142
1373
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
1143
1374
  return yield* decoder(itemStream);
1144
1375
  }))(stream);
1145
1376
  if (res.length < itemDecoders.length) {
1146
- return yield* new DecodeError(stream, `expected at least ${itemDecoders.length} items, only got ${res.length}`);
1377
+ return yield* Either.left(new DecodeError(stream, `expected at least ${itemDecoders.length} items, only got ${res.length}`));
1147
1378
  }
1148
1379
  return res;
1149
1380
  });