@kontor/kontor-sdk 1.0.0-alpha.39 → 1.0.0-alpha.40

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 (270) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/sdk/actions/kontor/public/call-view.js.map +1 -1
  3. package/dist/cjs/sdk/chains/definitions/signet.js +2 -2
  4. package/dist/cjs/sdk/test/e2e.test-deprecated.js +2 -0
  5. package/dist/cjs/sdk/test/e2e.test-deprecated.js.map +1 -0
  6. package/dist/cjs/sdk/utils/wit/codecs/bool.js +9 -21
  7. package/dist/cjs/sdk/utils/wit/codecs/bool.js.map +1 -1
  8. package/dist/cjs/sdk/utils/wit/codecs/contract-address.js +92 -0
  9. package/dist/cjs/sdk/utils/wit/codecs/contract-address.js.map +1 -0
  10. package/dist/cjs/sdk/utils/wit/codecs/index.js +29 -0
  11. package/dist/cjs/sdk/utils/wit/codecs/index.js.map +1 -0
  12. package/dist/cjs/sdk/utils/wit/codecs/list.js +21 -95
  13. package/dist/cjs/sdk/utils/wit/codecs/list.js.map +1 -1
  14. package/dist/cjs/sdk/utils/wit/codecs/numerics.js +228 -0
  15. package/dist/cjs/sdk/utils/wit/codecs/numerics.js.map +1 -0
  16. package/dist/cjs/sdk/utils/wit/codecs/option.js +21 -72
  17. package/dist/cjs/sdk/utils/wit/codecs/option.js.map +1 -1
  18. package/dist/cjs/sdk/utils/wit/codecs/result.js +32 -0
  19. package/dist/cjs/sdk/utils/wit/codecs/result.js.map +1 -0
  20. package/dist/cjs/sdk/utils/wit/codecs/string.js +16 -21
  21. package/dist/cjs/sdk/utils/wit/codecs/string.js.map +1 -1
  22. package/dist/cjs/sdk/utils/wit/codecs/unit.js +11 -19
  23. package/dist/cjs/sdk/utils/wit/codecs/unit.js.map +1 -1
  24. package/dist/cjs/sdk/utils/wit/codecs/util.js +185 -0
  25. package/dist/cjs/sdk/utils/wit/codecs/util.js.map +1 -0
  26. package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js +297 -163
  27. package/dist/cjs/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
  28. package/dist/cjs/sdk/utils/wit/encode-wit-parameters.js +214 -221
  29. package/dist/cjs/sdk/utils/wit/encode-wit-parameters.js.map +1 -1
  30. package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
  31. package/dist/cjs/wit/built-ins.js +19 -0
  32. package/dist/cjs/wit/built-ins.js.map +1 -0
  33. package/dist/cjs/wit/regex.js +1 -1
  34. package/dist/cjs/wit/regex.js.map +1 -1
  35. package/dist/cjs/wit/wit-parser/core/errors/signature.js +17 -2
  36. package/dist/cjs/wit/wit-parser/core/errors/signature.js.map +1 -1
  37. package/dist/cjs/wit/wit-parser/core/signatures.js +18 -0
  38. package/dist/cjs/wit/wit-parser/core/signatures.js.map +1 -1
  39. package/dist/cjs/wit/wit-parser/core/types/{records.js → user-defined.js} +1 -1
  40. package/dist/cjs/wit/wit-parser/core/types/user-defined.js.map +1 -0
  41. package/dist/cjs/wit/wit-parser/core/user-defined.js +271 -0
  42. package/dist/cjs/wit/wit-parser/core/user-defined.js.map +1 -0
  43. package/dist/cjs/wit/wit-parser/core/utils.js +29 -7
  44. package/dist/cjs/wit/wit-parser/core/utils.js.map +1 -1
  45. package/dist/cjs/wit/wit-parser/parse-wit-parameter.js +9 -3
  46. package/dist/cjs/wit/wit-parser/parse-wit-parameter.js.map +1 -1
  47. package/dist/cjs/wit/wit-parser/parse-wit.js +7 -3
  48. package/dist/cjs/wit/wit-parser/parse-wit.js.map +1 -1
  49. package/dist/esm/sdk/actions/kontor/public/call-view.js.map +1 -1
  50. package/dist/esm/sdk/chains/definitions/signet.js +2 -2
  51. package/dist/esm/sdk/test/e2e.test-deprecated.js +197 -0
  52. package/dist/esm/sdk/test/e2e.test-deprecated.js.map +1 -0
  53. package/dist/esm/sdk/utils/wit/codecs/bool.js +9 -21
  54. package/dist/esm/sdk/utils/wit/codecs/bool.js.map +1 -1
  55. package/dist/esm/sdk/utils/wit/codecs/contract-address.js +92 -0
  56. package/dist/esm/sdk/utils/wit/codecs/contract-address.js.map +1 -0
  57. package/dist/esm/sdk/utils/wit/codecs/index.js +9 -0
  58. package/dist/esm/sdk/utils/wit/codecs/index.js.map +1 -0
  59. package/dist/esm/sdk/utils/wit/codecs/list.js +20 -114
  60. package/dist/esm/sdk/utils/wit/codecs/list.js.map +1 -1
  61. package/dist/esm/sdk/utils/wit/codecs/numerics.js +234 -0
  62. package/dist/esm/sdk/utils/wit/codecs/numerics.js.map +1 -0
  63. package/dist/esm/sdk/utils/wit/codecs/option.js +21 -88
  64. package/dist/esm/sdk/utils/wit/codecs/option.js.map +1 -1
  65. package/dist/esm/sdk/utils/wit/codecs/result.js +29 -0
  66. package/dist/esm/sdk/utils/wit/codecs/result.js.map +1 -0
  67. package/dist/esm/sdk/utils/wit/codecs/string.js +22 -22
  68. package/dist/esm/sdk/utils/wit/codecs/string.js.map +1 -1
  69. package/dist/esm/sdk/utils/wit/codecs/unit.js +12 -21
  70. package/dist/esm/sdk/utils/wit/codecs/unit.js.map +1 -1
  71. package/dist/esm/sdk/utils/wit/codecs/util.js +181 -0
  72. package/dist/esm/sdk/utils/wit/codecs/util.js.map +1 -0
  73. package/dist/esm/sdk/utils/wit/decode-wit-parameter.js +322 -188
  74. package/dist/esm/sdk/utils/wit/decode-wit-parameter.js.map +1 -1
  75. package/dist/esm/sdk/utils/wit/encode-wit-parameters.js +230 -233
  76. package/dist/esm/sdk/utils/wit/encode-wit-parameters.js.map +1 -1
  77. package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
  78. package/dist/esm/wit/built-ins.js +16 -0
  79. package/dist/esm/wit/built-ins.js.map +1 -0
  80. package/dist/esm/wit/regex.js +1 -1
  81. package/dist/esm/wit/regex.js.map +1 -1
  82. package/dist/esm/wit/wit-parser/core/errors/signature.js +15 -1
  83. package/dist/esm/wit/wit-parser/core/errors/signature.js.map +1 -1
  84. package/dist/esm/wit/wit-parser/core/signatures.js +14 -0
  85. package/dist/esm/wit/wit-parser/core/signatures.js.map +1 -1
  86. package/dist/esm/wit/wit-parser/core/types/signatures.js.map +1 -1
  87. package/dist/esm/wit/wit-parser/core/types/user-defined.js +2 -0
  88. package/dist/esm/wit/wit-parser/core/types/user-defined.js.map +1 -0
  89. package/dist/esm/wit/wit-parser/core/types/utils.js +25 -0
  90. package/dist/esm/wit/wit-parser/core/types/utils.js.map +1 -1
  91. package/dist/esm/wit/wit-parser/core/user-defined.js +280 -0
  92. package/dist/esm/wit/wit-parser/core/user-defined.js.map +1 -0
  93. package/dist/esm/wit/wit-parser/core/utils.js +33 -36
  94. package/dist/esm/wit/wit-parser/core/utils.js.map +1 -1
  95. package/dist/esm/wit/wit-parser/parse-wit-parameter.js +10 -4
  96. package/dist/esm/wit/wit-parser/parse-wit-parameter.js.map +1 -1
  97. package/dist/esm/wit/wit-parser/parse-wit.js +8 -4
  98. package/dist/esm/wit/wit-parser/parse-wit.js.map +1 -1
  99. package/dist/types/sdk/actions/kontor/public/call-view.d.ts +2 -1
  100. package/dist/types/sdk/actions/kontor/public/call-view.d.ts.map +1 -1
  101. package/dist/types/sdk/chains/definitions/signet.d.ts +2 -2
  102. package/dist/types/sdk/test/e2e.test-deprecated.d.ts +2 -0
  103. package/dist/types/sdk/test/e2e.test-deprecated.d.ts.map +1 -0
  104. package/dist/types/sdk/types/contract.d.ts +5 -5
  105. package/dist/types/sdk/types/contract.d.ts.map +1 -1
  106. package/dist/types/sdk/utils/wit/codecs/bool.d.ts +2 -2
  107. package/dist/types/sdk/utils/wit/codecs/bool.d.ts.map +1 -1
  108. package/dist/types/sdk/utils/wit/codecs/contract-address.d.ts +5 -0
  109. package/dist/types/sdk/utils/wit/codecs/contract-address.d.ts.map +1 -0
  110. package/dist/types/sdk/utils/wit/codecs/index.d.ts +9 -0
  111. package/dist/types/sdk/utils/wit/codecs/index.d.ts.map +1 -0
  112. package/dist/types/sdk/utils/wit/codecs/list.d.ts +2 -16
  113. package/dist/types/sdk/utils/wit/codecs/list.d.ts.map +1 -1
  114. package/dist/types/sdk/utils/wit/codecs/numerics.d.ts +14 -0
  115. package/dist/types/sdk/utils/wit/codecs/numerics.d.ts.map +1 -0
  116. package/dist/types/sdk/utils/wit/codecs/option.d.ts +3 -23
  117. package/dist/types/sdk/utils/wit/codecs/option.d.ts.map +1 -1
  118. package/dist/types/sdk/utils/wit/codecs/result.d.ts +4 -0
  119. package/dist/types/sdk/utils/wit/codecs/result.d.ts.map +1 -0
  120. package/dist/types/sdk/utils/wit/codecs/string.d.ts +6 -2
  121. package/dist/types/sdk/utils/wit/codecs/string.d.ts.map +1 -1
  122. package/dist/types/sdk/utils/wit/codecs/types.d.ts +4 -0
  123. package/dist/types/sdk/utils/wit/codecs/types.d.ts.map +1 -1
  124. package/dist/types/sdk/utils/wit/codecs/unit.d.ts +2 -11
  125. package/dist/types/sdk/utils/wit/codecs/unit.d.ts.map +1 -1
  126. package/dist/types/sdk/utils/wit/codecs/util.d.ts +12 -0
  127. package/dist/types/sdk/utils/wit/codecs/util.d.ts.map +1 -0
  128. package/dist/types/sdk/utils/wit/decode-wit-parameter.d.ts +9 -31
  129. package/dist/types/sdk/utils/wit/decode-wit-parameter.d.ts.map +1 -1
  130. package/dist/types/sdk/utils/wit/encode-wit-parameters.d.ts +9 -1
  131. package/dist/types/sdk/utils/wit/encode-wit-parameters.d.ts.map +1 -1
  132. package/dist/types/wit/built-ins.d.ts +6 -0
  133. package/dist/types/wit/built-ins.d.ts.map +1 -0
  134. package/dist/types/wit/regex.d.ts.map +1 -1
  135. package/dist/types/wit/utils.d.ts +53 -33
  136. package/dist/types/wit/utils.d.ts.map +1 -1
  137. package/dist/types/wit/wit-parser/core/errors/signature.d.ts +7 -1
  138. package/dist/types/wit/wit-parser/core/errors/signature.d.ts.map +1 -1
  139. package/dist/types/wit/wit-parser/core/signatures.d.ts +10 -0
  140. package/dist/types/wit/wit-parser/core/signatures.d.ts.map +1 -1
  141. package/dist/types/wit/wit-parser/core/types/signatures.d.ts +6 -2
  142. package/dist/types/wit/wit-parser/core/types/signatures.d.ts.map +1 -1
  143. package/dist/types/wit/wit-parser/core/types/user-defined.d.ts +134 -0
  144. package/dist/types/wit/wit-parser/core/types/user-defined.d.ts.map +1 -0
  145. package/dist/types/wit/wit-parser/core/types/utils.d.ts +86 -11
  146. package/dist/types/wit/wit-parser/core/types/utils.d.ts.map +1 -1
  147. package/dist/types/wit/wit-parser/core/user-defined.d.ts +19 -0
  148. package/dist/types/wit/wit-parser/core/user-defined.d.ts.map +1 -0
  149. package/dist/types/wit/wit-parser/core/utils.d.ts +8 -4
  150. package/dist/types/wit/wit-parser/core/utils.d.ts.map +1 -1
  151. package/dist/types/wit/wit-parser/parse-wit-parameter.d.ts +11 -5
  152. package/dist/types/wit/wit-parser/parse-wit-parameter.d.ts.map +1 -1
  153. package/dist/types/wit/wit-parser/parse-wit.d.ts +7 -3
  154. package/dist/types/wit/wit-parser/parse-wit.d.ts.map +1 -1
  155. package/dist/types/wit/wit.d.ts +20 -12
  156. package/dist/types/wit/wit.d.ts.map +1 -1
  157. package/package.json +1 -1
  158. package/src/sdk/actions/get-contract.test-d.ts +430 -50
  159. package/src/sdk/actions/get-contract.test.ts +324 -24
  160. package/src/sdk/actions/kontor/public/call-view.ts +2 -1
  161. package/src/sdk/actions/kontor/public/proc-contract.test-d.ts +107 -0
  162. package/src/sdk/actions/kontor/public/proc-contract.test.ts +234 -21
  163. package/src/sdk/actions/kontor/public/view-contract.test-d.ts +240 -0
  164. package/src/sdk/actions/kontor/public/view-contract.test.ts +613 -18
  165. package/src/sdk/chains/definitions/signet.ts +2 -2
  166. package/src/sdk/clients/base/create-rpc-client.test.ts +2 -2
  167. package/src/sdk/clients/create-public-client.test.ts +2 -2
  168. package/src/sdk/clients/kontor/create-public-client.test.ts +2 -2
  169. package/src/sdk/clients/transports/http-rpc.test.ts +0 -24
  170. package/src/sdk/test/e2e.test-deprecated.ts +195 -0
  171. package/src/sdk/types/contract.test-d.ts +489 -55
  172. package/src/sdk/types/contract.ts +6 -7
  173. package/src/sdk/utils/wit/codecs/bool.test.ts +29 -0
  174. package/src/sdk/utils/wit/codecs/bool.ts +10 -25
  175. package/src/sdk/utils/wit/codecs/contract-address.test.ts +37 -0
  176. package/src/sdk/utils/wit/codecs/contract-address.ts +114 -0
  177. package/src/sdk/utils/wit/codecs/index.ts +20 -0
  178. package/src/sdk/utils/wit/codecs/list.test-d.ts +13 -0
  179. package/src/sdk/utils/wit/codecs/list.test.ts +55 -0
  180. package/src/sdk/utils/wit/codecs/list.ts +21 -150
  181. package/src/sdk/utils/wit/codecs/numerics.test.ts +399 -0
  182. package/src/sdk/utils/wit/codecs/numerics.ts +304 -0
  183. package/src/sdk/utils/wit/codecs/option.test.ts +71 -0
  184. package/src/sdk/utils/wit/codecs/option.ts +21 -120
  185. package/src/sdk/utils/wit/codecs/result.test.ts +82 -0
  186. package/src/sdk/utils/wit/codecs/result.ts +37 -0
  187. package/src/sdk/utils/wit/codecs/string.test.ts +62 -0
  188. package/src/sdk/utils/wit/codecs/string.ts +23 -25
  189. package/src/sdk/utils/wit/codecs/types.ts +5 -0
  190. package/src/sdk/utils/wit/codecs/unit.test.ts +27 -0
  191. package/src/sdk/utils/wit/codecs/unit.ts +14 -38
  192. package/src/sdk/utils/wit/codecs/util.test.ts +221 -0
  193. package/src/sdk/utils/wit/codecs/util.ts +193 -0
  194. package/src/sdk/utils/wit/decode-wit-parameter.test.ts +1264 -32
  195. package/src/sdk/utils/wit/decode-wit-parameter.ts +508 -211
  196. package/src/sdk/utils/wit/encode-wit-parameters.test.ts +955 -91
  197. package/src/sdk/utils/wit/encode-wit-parameters.ts +277 -274
  198. package/src/sdk/utils/wit/get-wit-item.test.ts +1 -1
  199. package/src/wit/built-ins.ts +23 -0
  200. package/src/wit/regex.ts +1 -1
  201. package/src/wit/utils.ts +120 -74
  202. package/src/wit/wit-parser/core/errors/signature.ts +13 -2
  203. package/src/wit/wit-parser/core/signatures.ts +28 -0
  204. package/src/wit/wit-parser/core/types/signatures.test-d.ts +21 -0
  205. package/src/wit/wit-parser/core/types/signatures.ts +19 -2
  206. package/src/wit/wit-parser/core/types/user-defined.test-d.ts +1308 -0
  207. package/src/wit/wit-parser/core/types/user-defined.ts +412 -0
  208. package/src/wit/wit-parser/core/types/utils.test-d.ts +43 -2
  209. package/src/wit/wit-parser/core/types/utils.ts +143 -14
  210. package/src/wit/wit-parser/core/user-defined.test.ts +609 -0
  211. package/src/wit/wit-parser/core/user-defined.ts +392 -0
  212. package/src/wit/wit-parser/core/utils.test.ts +334 -115
  213. package/src/wit/wit-parser/core/utils.ts +54 -38
  214. package/src/wit/wit-parser/parse-wit-parameter.test.ts +282 -4
  215. package/src/wit/wit-parser/parse-wit-parameter.ts +37 -11
  216. package/src/wit/wit-parser/parse-wit.test.ts +738 -12
  217. package/src/wit/wit-parser/parse-wit.ts +25 -10
  218. package/src/wit/wit.ts +37 -16
  219. package/vitest.config.ts +5 -0
  220. package/dist/cjs/sdk/utils/wit/codecs/decimal.js +0 -148
  221. package/dist/cjs/sdk/utils/wit/codecs/decimal.js.map +0 -1
  222. package/dist/cjs/sdk/utils/wit/codecs/enum.js +0 -94
  223. package/dist/cjs/sdk/utils/wit/codecs/enum.js.map +0 -1
  224. package/dist/cjs/sdk/utils/wit/codecs/integer.js +0 -125
  225. package/dist/cjs/sdk/utils/wit/codecs/integer.js.map +0 -1
  226. package/dist/cjs/sdk/utils/wit/codecs/s64.js +0 -57
  227. package/dist/cjs/sdk/utils/wit/codecs/s64.js.map +0 -1
  228. package/dist/cjs/sdk/utils/wit/codecs/u64.js +0 -56
  229. package/dist/cjs/sdk/utils/wit/codecs/u64.js.map +0 -1
  230. package/dist/cjs/wit/wit-parser/core/records.js +0 -70
  231. package/dist/cjs/wit/wit-parser/core/records.js.map +0 -1
  232. package/dist/cjs/wit/wit-parser/core/types/records.js.map +0 -1
  233. package/dist/esm/sdk/utils/wit/codecs/decimal.js +0 -165
  234. package/dist/esm/sdk/utils/wit/codecs/decimal.js.map +0 -1
  235. package/dist/esm/sdk/utils/wit/codecs/enum.js +0 -104
  236. package/dist/esm/sdk/utils/wit/codecs/enum.js.map +0 -1
  237. package/dist/esm/sdk/utils/wit/codecs/integer.js +0 -167
  238. package/dist/esm/sdk/utils/wit/codecs/integer.js.map +0 -1
  239. package/dist/esm/sdk/utils/wit/codecs/s64.js +0 -65
  240. package/dist/esm/sdk/utils/wit/codecs/s64.js.map +0 -1
  241. package/dist/esm/sdk/utils/wit/codecs/u64.js +0 -63
  242. package/dist/esm/sdk/utils/wit/codecs/u64.js.map +0 -1
  243. package/dist/esm/wit/wit-parser/core/records.js +0 -73
  244. package/dist/esm/wit/wit-parser/core/records.js.map +0 -1
  245. package/dist/esm/wit/wit-parser/core/types/records.js +0 -2
  246. package/dist/esm/wit/wit-parser/core/types/records.js.map +0 -1
  247. package/dist/types/sdk/utils/wit/codecs/decimal.d.ts +0 -42
  248. package/dist/types/sdk/utils/wit/codecs/decimal.d.ts.map +0 -1
  249. package/dist/types/sdk/utils/wit/codecs/enum.d.ts +0 -49
  250. package/dist/types/sdk/utils/wit/codecs/enum.d.ts.map +0 -1
  251. package/dist/types/sdk/utils/wit/codecs/integer.d.ts +0 -36
  252. package/dist/types/sdk/utils/wit/codecs/integer.d.ts.map +0 -1
  253. package/dist/types/sdk/utils/wit/codecs/s64.d.ts +0 -23
  254. package/dist/types/sdk/utils/wit/codecs/s64.d.ts.map +0 -1
  255. package/dist/types/sdk/utils/wit/codecs/u64.d.ts +0 -23
  256. package/dist/types/sdk/utils/wit/codecs/u64.d.ts.map +0 -1
  257. package/dist/types/wit/wit-parser/core/records.d.ts +0 -4
  258. package/dist/types/wit/wit-parser/core/records.d.ts.map +0 -1
  259. package/dist/types/wit/wit-parser/core/types/records.d.ts +0 -51
  260. package/dist/types/wit/wit-parser/core/types/records.d.ts.map +0 -1
  261. package/src/sdk/test/e2e.test.ts +0 -194
  262. package/src/sdk/utils/wit/codecs/decimal.ts +0 -215
  263. package/src/sdk/utils/wit/codecs/enum.ts +0 -114
  264. package/src/sdk/utils/wit/codecs/integer.ts +0 -193
  265. package/src/sdk/utils/wit/codecs/s64.ts +0 -76
  266. package/src/sdk/utils/wit/codecs/u64.ts +0 -73
  267. package/src/wit/wit-parser/core/records.test.ts +0 -69
  268. package/src/wit/wit-parser/core/records.ts +0 -101
  269. package/src/wit/wit-parser/core/types/records.test-d.ts +0 -331
  270. package/src/wit/wit-parser/core/types/records.ts +0 -91
@@ -1,194 +0,0 @@
1
- import { test } from "vitest";
2
- // import { procContract } from "./proc-contract.js";
3
- import { parseWit } from "../../wit/wit-parser/parse-wit.js";
4
- import { createPublicClient as createKontorPublicClient } from "../clients/kontor/create-public-client.js";
5
- import { http } from "../clients/transports/http.js";
6
- import { mnemonicToAccount } from "../accounts/mnemonic-to-account.js";
7
- import { createWalletClient as createKontorWalletClient } from "../clients/kontor/create-wallet-client.js";
8
-
9
- import { custom } from "../clients/transports/custom.js";
10
- import { signet } from "../chains/definitions/signet.js";
11
- import { Instruction } from "../types/kontor.js";
12
-
13
- export const nativeTokenRaw = [
14
- "record balance { acc: string, amt: decimal }",
15
- "record transfer { src: string, dst: string, amt: decimal }",
16
- "record burn { src: string, amt: decimal }",
17
- "record mint { dst: string, amt: decimal }",
18
-
19
- "export issuance: func(ctx: borrow<core-context>, amt: decimal) -> result<mint, error>;",
20
- "export hold: func(ctx: borrow<core-context>, amt: decimal) -> result<transfer, error>;",
21
- "export release: func(ctx: borrow<core-context>, burn-amt: decimal) -> result<burn, error>;",
22
- "export init: func(ctx: borrow<proc-context>);",
23
- "export mint: func(ctx: borrow<proc-context>, amt: decimal) -> result<mint, error>;",
24
- "export burn: func(ctx: borrow<proc-context>, amt: decimal) -> result<burn, error>;",
25
- "export transfer: func(ctx: borrow<proc-context>, dst: string, amt: decimal) -> result<transfer, error>;",
26
- "export balance: func(ctx: borrow<view-context>, acc: string) -> option<decimal>;",
27
- "export balances: func(ctx: borrow<view-context>) -> list<balance>;",
28
- "export total-supply: func(ctx: borrow<view-context>) -> decimal;",
29
- "export attach: func(ctx: borrow<proc-context>, vout: u64, amt: decimal) -> result<transfer, error>;",
30
- "export detach: func(ctx: borrow<proc-context>) -> result<transfer, error>;",
31
- ] as const;
32
-
33
- export const wit = parseWit(nativeTokenRaw);
34
-
35
- // test("e2e kontor wallet client", async () => {
36
- // const account = mnemonicToAccount(process.env.TEST_MNEMONIC!);
37
- //
38
- // const kontorPublicClient = createKontorPublicClient({
39
- // transport: http("https://signet-staging.kontor.network:35000/api"),
40
- // account,
41
- // chain: signet,
42
- // });
43
- //
44
- // const kontorWalletClient = createKontorWalletClient({
45
- // account,
46
- // // TODO: transport is not used for local account.
47
- // transport: custom({
48
- // request: async (_args: any) => null,
49
- // }),
50
- // });
51
- //
52
- // const res = await kontorPublicClient.procContract({
53
- // wit: wit,
54
- // // TODO: add optional account override
55
- //
56
- // functionName: "mint", // functin name is only valid if it's got a proc-context
57
- // contractAddress: "token_0_0",
58
- // args: [[7n, 18]],
59
- // satsPerVByte: 1,
60
- // utxos: [
61
- // "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
62
- // ],
63
- // gas: 10n,
64
- // });
65
- //
66
- // const commit: string = await kontorWalletClient.signCommit({
67
- // account: account,
68
- // chain: signet,
69
- // psbt: res.result.commit_psbt_hex,
70
- // });
71
- //
72
- // const reveal: string = await kontorWalletClient.signReveal({
73
- // account: account,
74
- // chain: signet,
75
- // psbt: res.result.reveal_psbt_hex,
76
- // participantScripts: res.result.per_participant,
77
- // });
78
- //
79
- // // const m = await btcPublicClient.testMempoolAccept({
80
- // // rawtx: [hex.encode(commitExtracted), hex.encode(revealExtracted)],
81
- // // options: {},
82
- // // });
83
- // //
84
- //
85
- // const r = await fetch("https://signet.kontor.network:38332", {
86
- // method: "POST",
87
- // headers: {
88
- // "Content-Type": "application/json",
89
- // Authorization: `Basic ${Buffer.from("rpc:rpc").toString("base64")}`,
90
- // },
91
- // body: JSON.stringify({
92
- // method: "testmempoolaccept",
93
- // params: [[commit, reveal]],
94
- // }),
95
- // });
96
- //
97
- // const j = await r.json();
98
- //
99
- // //
100
- // // const op = await kontorPublicClient.inspect({
101
- // // hex: hex.encode(revealExtracted),
102
- // // });
103
- //
104
- // // console.log(JSON.stringify(op.result[0]!.op));
105
- // //
106
- // });
107
-
108
- test("e2e kontor wallet client", async () => {
109
- const account = mnemonicToAccount(process.env.TEST_MNEMONIC!, {
110
- coinType: 1,
111
- networkConfig: signet.networkConfig,
112
- });
113
-
114
- const kontorPublicClient = createKontorPublicClient({
115
- transport: http("https://signet-staging.kontor.network:35000/api"),
116
- chain: signet,
117
- account,
118
- });
119
-
120
- const kontorWalletClient = createKontorWalletClient({
121
- account,
122
- chain: signet,
123
- transport: custom({
124
- request: async (_args: any) => null,
125
- }),
126
- });
127
-
128
- const res = await kontorPublicClient.callCompose({
129
- utxos: [
130
- "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
131
- ],
132
- instruction: Instruction.issuance(),
133
- satsPerVByte: 1,
134
- });
135
-
136
- // TODO: add separate tests for these
137
- // const instructionQuery_ = kontorPublicClient.buildInstructionQuery({
138
- // utxos: [
139
- // "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
140
- // ],
141
- // instruction: Instruction.issuance(),
142
- // });
143
- //
144
- // const composeQuery_ = kontorPublicClient.buildComposeQuery({
145
- // utxos: [
146
- // "641c40edf4cf0f1cdaea5c259bf50267bd8743dbade84c98bb9e360c2d0e2a33:1",
147
- // ],
148
- //
149
- // instruction: Instruction.issuance(),
150
- // satsPerVByte: 1,
151
- // });
152
- // const x = await kontorPublicClient.callView({
153
- // contractAddress: "token_0_0",
154
- // wave: "balances()",
155
- // });
156
-
157
- // TODO: should this return hex
158
-
159
- // TODO: need to handle account override / defaults
160
- const commit = await kontorWalletClient.signCommit({
161
- psbt: res.result.commit_psbt_hex,
162
- });
163
-
164
- const reveal = await kontorWalletClient.signReveal({
165
- psbt: res.result.reveal_psbt_hex,
166
- participantScripts: res.result.per_participant,
167
- });
168
-
169
- // const commitExtracted = commit.extract();
170
- // const revealExtracted = reveal.extract();
171
-
172
- const r = await fetch("https://signet.kontor.network:38332", {
173
- method: "POST",
174
- headers: {
175
- "Content-Type": "application/json",
176
- Authorization: `Basic ${Buffer.from("rpc:rpc").toString("base64")}`,
177
- },
178
- body: JSON.stringify({
179
- method: "testmempoolaccept",
180
- params: [[commit, reveal]],
181
- }),
182
- });
183
-
184
- const mempoolAccept = await r.json();
185
-
186
- console.log({ mempoolAccept: mempoolAccept.result });
187
- //
188
- const op = await kontorPublicClient.inspect({
189
- hex: reveal,
190
- });
191
-
192
- console.log(JSON.stringify(op.result[0]!.op));
193
- //
194
- });
@@ -1,215 +0,0 @@
1
- import * as z from "zod";
2
-
3
- import type { CodecConstructor, CodecInstance, WaveExpr } from "./types.js";
4
-
5
- type Decimal_ = [bigint, number];
6
-
7
- const TARGET_SCALE = 18;
8
- const U64_MAX = (1n << 64n) - 1n;
9
-
10
- export const U64 = z
11
- .bigint()
12
- .min(0n, { message: "must be ≥ 0" })
13
- .max(U64_MAX, { message: "must be ≤ 2^64-1" });
14
-
15
- function pow10n(n: number): bigint {
16
- if (n < 0) throw new Error("pow10n expects n ≥ 0");
17
- let p = 1n;
18
- for (let i = 0; i < n; i++) p *= 10n;
19
- return p;
20
- }
21
-
22
- // const fromLimbs = ({ r0, r1, r2, r3 }: _Decimal.T) =>
23
- // (r3 << 192n) | (r2 << 128n) | (r1 << 64n) | r0;
24
-
25
- function splitToU64Limbs(x: bigint): {
26
- r0: bigint;
27
- r1: bigint;
28
- r2: bigint;
29
- r3: bigint;
30
- } {
31
- const r0 = x & U64_MAX;
32
- const r1 = (x >> 64n) & U64_MAX;
33
- const r2 = (x >> 128n) & U64_MAX;
34
- const r3 = (x >> 192n) & U64_MAX;
35
-
36
- // overflow if any higher bits remain
37
- if (x >> 256n !== 0n) {
38
- throw new Error("decimal magnitude does not fit in 256 bits");
39
- }
40
-
41
- return { r0, r1, r2, r3 };
42
- }
43
-
44
- export namespace _Decimal {
45
- export namespace Sign {
46
- export const schema = z.enum(["plus", "minus"]);
47
- export type T = z.infer<typeof schema>;
48
- }
49
-
50
- // Raw limbs + sign; limbs are real u64 (bigint), not JS numbers
51
- export const schema = z.object({
52
- r0: U64,
53
- r1: U64,
54
- r2: U64,
55
- r3: U64,
56
- sign: Sign.schema,
57
- });
58
-
59
- export type T = z.infer<typeof schema>;
60
- }
61
-
62
- /**
63
- * Parses a wave-ish struct like:
64
- * "{ r0: 1337, r1: 0, r2: 0, r3: 0, sign: plus }"
65
- * Returns a validated _Decimal.T with bigint limbs.
66
- */
67
- export function parseDecimalWaveExpr(expr: string): _Decimal.T {
68
- const trimmed = expr.trim();
69
- // Optional braces; tolerate with or without
70
- const inner = trimmed.replace(/^\{\s*/, "").replace(/\s*\}$/, "");
71
-
72
- if (inner.length === 0) {
73
- throw new Error("empty decimal expression");
74
- }
75
-
76
- // Split by commas that separate top-level pairs (no nesting expected here)
77
- const parts = inner
78
- .split(",")
79
- .map((p) => p.trim())
80
- .filter(Boolean);
81
-
82
- const seen = new Set<string>();
83
- // Default r1..r3 to 0 for ergonomics; require r0 + sign at minimum.
84
- let out: Partial<_Decimal.T> & {
85
- r0?: bigint;
86
- r1?: bigint;
87
- r2?: bigint;
88
- r3?: bigint;
89
- } = {
90
- r1: 0n,
91
- r2: 0n,
92
- r3: 0n,
93
- };
94
-
95
- for (const part of parts) {
96
- const idx = part.indexOf(":");
97
- if (idx === -1) {
98
- throw new Error(`expected "key: value" pair, got "${part}"`);
99
- }
100
- const keyRaw = part.slice(0, idx).trim();
101
- const valRaw = part.slice(idx + 1).trim();
102
-
103
- if (seen.has(keyRaw)) {
104
- throw new Error(`duplicate key "${keyRaw}"`);
105
- }
106
- seen.add(keyRaw);
107
-
108
- switch (keyRaw) {
109
- case "r0":
110
- case "r1":
111
- case "r2":
112
- case "r3": {
113
- // allow underscores for readability, like Rust literals
114
- const normalized = valRaw.replace(/_/g, "");
115
- // BigInt constructor handles decimal strings; reject non-integers explicitly
116
- if (!/^[+-]?\d+$/.test(normalized)) {
117
- throw new Error(`invalid integer for ${keyRaw}: "${valRaw}"`);
118
- }
119
- const limb = BigInt(normalized);
120
- // zod will re-validate bounds, but fail fast here for nicer messages
121
- if (limb < 0n || limb > U64_MAX) {
122
- throw new Error(`value for ${keyRaw} out of u64 range: ${valRaw}`);
123
- }
124
- (out as any)[keyRaw] = limb;
125
- break;
126
- }
127
-
128
- case "sign": {
129
- if (valRaw !== "plus" && valRaw !== "minus") {
130
- throw new Error(`invalid sign "${valRaw}" (expected plus|minus)`);
131
- }
132
- (out as any).sign = valRaw;
133
- break;
134
- }
135
-
136
- default:
137
- throw new Error(`unexpected key "${keyRaw}"`);
138
- }
139
- }
140
-
141
- // Require at least r0 and sign (r1..r3 default to 0 if not given)
142
- if (out.r0 === undefined) {
143
- throw new Error(`missing required key "r0"`);
144
- }
145
- if (!out.sign) {
146
- throw new Error(`missing required key "sign"`);
147
- }
148
-
149
- // Final validation & typing
150
- return _Decimal.schema.parse(out);
151
- }
152
-
153
- class _DecimalCodec implements CodecInstance<Decimal_> {
154
- public readonly data: _Decimal.T;
155
-
156
- constructor(data: _Decimal.T) {
157
- this.data = data;
158
- }
159
-
160
- static fromJs(
161
- value: Decimal_,
162
- targetScale: number = TARGET_SCALE,
163
- ): _DecimalCodec {
164
- // dn.Dnum is effectively [coef, decimals]
165
- const [coefRaw, decs] = value as unknown as Decimal_;
166
-
167
- const sign: _Decimal.Sign.T = coefRaw < 0n ? "minus" : "plus";
168
- const coefAbs = coefRaw < 0n ? -coefRaw : coefRaw;
169
-
170
- if (decs > decs) {
171
- // would require rounding; be strict
172
- throw new Error(
173
- `cannot downscale from ${decs} to ${targetScale} decimals without rounding`,
174
- );
175
- }
176
-
177
- // upscale to target scale exactly
178
- const scaleDelta = targetScale - decs;
179
- const scaled = coefAbs * pow10n(scaleDelta);
180
-
181
- const { r0, r1, r2, r3 } = splitToU64Limbs(scaled);
182
- const out = _Decimal.schema.parse({ r0, r1, r2, r3, sign });
183
- return new _DecimalCodec(out);
184
- }
185
-
186
- static fromKontor(data: _Decimal.T): _DecimalCodec {
187
- return new _DecimalCodec(data);
188
- }
189
-
190
- static parseWave(expr: string): _Decimal.T {
191
- return _Decimal.schema.parse(parseDecimalWaveExpr(expr));
192
- }
193
-
194
- toJs(): Decimal_ {
195
- const mag =
196
- (BigInt(this.data.r3) << 192n) |
197
- (BigInt(this.data.r2) << 128n) |
198
- (BigInt(this.data.r1) << 64n) |
199
- BigInt(this.data.r0);
200
-
201
- const signed = this.data.sign === "minus" ? -mag : mag;
202
- return [signed, 18];
203
- }
204
-
205
- toWave(): WaveExpr {
206
- // NOTE: adjust quoting on sign if your Wave syntax needs `"plus"` etc.
207
- return `{r0: ${this.data.r0}, r1: ${this.data.r1}, r2: ${this.data.r2}, r3: ${this.data.r3}, sign: ${this.data.sign}}` as WaveExpr;
208
- }
209
- }
210
-
211
- export const DecimalCodec = _DecimalCodec as unknown as CodecConstructor<
212
- Decimal_,
213
- _DecimalCodec,
214
- _Decimal.T
215
- >;
@@ -1,114 +0,0 @@
1
- import * as z from "zod";
2
-
3
- export namespace Enum {
4
- export namespace Parens {
5
- export const schema = z.templateLiteral([
6
- z.literal("("),
7
- z.string(),
8
- z.literal(")"),
9
- ]);
10
- }
11
-
12
- export namespace Option {
13
- // some(foo) or some( foo bar ) or even some()
14
- // also allow just "some" ??? we'll decide below.
15
- export const waveRegex =
16
- /^(?<kind>some)(?:\((?<value>[\s\S]*?)\))$|^(?<none>none)$/;
17
-
18
- // We'll keep these tiny sub-schemas because they're readable elsewhere.
19
- export namespace None {
20
- export const schema = z.literal("none");
21
- }
22
-
23
- export namespace Some {
24
- // NOTE: we REQUIRE parens for "some(...)"
25
- // If you want plain "some" to be valid, we could relax later.
26
- export const schema = z.templateLiteral([
27
- z.literal("some"),
28
- Parens.schema,
29
- ]);
30
- }
31
-
32
- // Raw union of the spellings we accept as input
33
- // e.g. "none" or "some(<stuff>)"
34
- const rawSchema = z.union([None.schema, Some.schema]);
35
-
36
- // Transform raw string -> { kind: "none" | "some"; value: string | null }
37
- // Then pipe into a discriminated union so .infer<> is nice & strict.
38
- export const schema = rawSchema
39
- .transform((expr) => {
40
- const trimmed = expr.trim();
41
-
42
- // Fast path for "none"
43
- if (trimmed === "none") {
44
- return {
45
- kind: "none" as const,
46
- };
47
- }
48
-
49
- // else parse "some(...)"
50
- const match = /^some\((?<value>[\s\S]*?)\)$/.exec(trimmed);
51
- if (!match?.groups) {
52
- throw new Error(`invariant: invalid wave option expression: ${expr}`);
53
- }
54
-
55
- const value = match.groups.value?.trim() ?? "";
56
- return {
57
- kind: "some" as const,
58
- value: value === "" ? null : value,
59
- };
60
- })
61
- .pipe(
62
- z.discriminatedUnion("kind", [
63
- z.object({
64
- kind: z.literal("none"),
65
- }),
66
- z.object({
67
- kind: z.literal("some"),
68
- value: z.string().nullable(), // raw value contents or null (for `some()`)
69
- }),
70
- ]),
71
- );
72
-
73
- export type T = z.infer<typeof schema>;
74
- }
75
-
76
- export namespace Result {
77
- export const waveRegex = /^(?<_tag>ok|err)(?:\((?<value>[\s\S]*?)\))?$/;
78
-
79
- export namespace Ok {
80
- export const schema = z.literal("ok");
81
- }
82
- export namespace Err {
83
- export const schema = z.literal("err");
84
- }
85
-
86
- export const schema = z
87
- .templateLiteral([
88
- z.union([Ok.schema, Err.schema]),
89
- Parens.schema.optional(),
90
- ])
91
- .transform((expr) => {
92
- const match = waveRegex.exec(expr.trim());
93
- if (!match?.groups) {
94
- throw new Error(`invariant: invalid wave expression: ${expr}`);
95
- }
96
- const { _tag, value } = match.groups;
97
- return { _tag, value: value?.trim() || null };
98
- })
99
- .pipe(
100
- // lock the output into a discriminated union so z.infer<> is nice
101
- z.discriminatedUnion("_tag", [
102
- z.object({
103
- _tag: Ok.schema, // "ok"
104
- value: z.string().nullable(), // raw value text (we haven't parsed r0..sign here)
105
- }),
106
- z.object({
107
- _tag: Err.schema, // "err"
108
- value: z.string().nullable(), // err(message("...")) -> 'message("...")' or null
109
- }),
110
- ]),
111
- );
112
- export type T = z.infer<typeof schema>;
113
- }
114
- }