@gnolang/tm2-js-client 1.3.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (316) hide show
  1. package/README.md +1 -1
  2. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.cjs +12 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs +12 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.cjs +14 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.mjs +14 -0
  6. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.cjs +9 -0
  7. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.mjs +9 -0
  8. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.cjs +16 -0
  9. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.mjs +11 -0
  10. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  11. package/dist/index.cjs +92 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.d.cts +23 -0
  14. package/dist/index.d.cts.map +1 -0
  15. package/dist/index.d.mts +23 -0
  16. package/dist/index.d.mts.map +1 -0
  17. package/dist/index.mjs +22 -0
  18. package/dist/index.mjs.map +1 -0
  19. package/dist/proto/google/protobuf/any.cjs +84 -0
  20. package/dist/proto/google/protobuf/any.cjs.map +1 -0
  21. package/dist/proto/google/protobuf/any.d.cts +141 -0
  22. package/dist/proto/google/protobuf/any.d.cts.map +1 -0
  23. package/dist/proto/google/protobuf/any.d.mts +141 -0
  24. package/dist/proto/google/protobuf/any.d.mts.map +1 -0
  25. package/dist/proto/google/protobuf/any.mjs +83 -0
  26. package/dist/proto/google/protobuf/any.mjs.map +1 -0
  27. package/dist/proto/index.cjs +2 -0
  28. package/dist/proto/index.d.cts +2 -0
  29. package/dist/proto/index.d.mts +2 -0
  30. package/dist/proto/index.mjs +3 -0
  31. package/dist/proto/tm2/abci.cjs +182 -0
  32. package/dist/proto/tm2/abci.cjs.map +1 -0
  33. package/dist/proto/tm2/abci.d.cts +33 -0
  34. package/dist/proto/tm2/abci.d.cts.map +1 -0
  35. package/dist/proto/tm2/abci.d.mts +33 -0
  36. package/dist/proto/tm2/abci.d.mts.map +1 -0
  37. package/dist/proto/tm2/abci.mjs +181 -0
  38. package/dist/proto/tm2/abci.mjs.map +1 -0
  39. package/dist/proto/tm2/tx.cjs +263 -0
  40. package/dist/proto/tm2/tx.cjs.map +1 -0
  41. package/dist/proto/tm2/tx.d.cts +49 -0
  42. package/dist/proto/tm2/tx.d.cts.map +1 -0
  43. package/dist/proto/tm2/tx.d.mts +49 -0
  44. package/dist/proto/tm2/tx.d.mts.map +1 -0
  45. package/dist/proto/tm2/tx.mjs +258 -0
  46. package/dist/proto/tm2/tx.mjs.map +1 -0
  47. package/dist/provider/endpoints.cjs +43 -0
  48. package/dist/provider/endpoints.cjs.map +1 -0
  49. package/dist/provider/endpoints.d.cts +33 -0
  50. package/dist/provider/endpoints.d.cts.map +1 -0
  51. package/dist/provider/endpoints.d.mts +33 -0
  52. package/dist/provider/endpoints.d.mts.map +1 -0
  53. package/dist/provider/endpoints.mjs +39 -0
  54. package/dist/provider/endpoints.mjs.map +1 -0
  55. package/dist/provider/errors/errors.cjs +122 -0
  56. package/dist/provider/errors/errors.cjs.map +1 -0
  57. package/dist/provider/errors/errors.d.cts +62 -0
  58. package/dist/provider/errors/errors.d.cts.map +1 -0
  59. package/dist/provider/errors/errors.d.mts +62 -0
  60. package/dist/provider/errors/errors.d.mts.map +1 -0
  61. package/dist/provider/errors/errors.mjs +104 -0
  62. package/dist/provider/errors/errors.mjs.map +1 -0
  63. package/dist/provider/errors/messages.cjs +40 -0
  64. package/dist/provider/errors/messages.cjs.map +1 -0
  65. package/dist/provider/errors/messages.mjs +23 -0
  66. package/dist/provider/errors/messages.mjs.map +1 -0
  67. package/dist/provider/index.cjs +12 -0
  68. package/dist/provider/index.d.cts +11 -0
  69. package/dist/provider/index.d.mts +11 -0
  70. package/dist/provider/index.mjs +13 -0
  71. package/dist/provider/jsonrpc/index.cjs +1 -0
  72. package/dist/provider/jsonrpc/index.d.cts +1 -0
  73. package/dist/provider/jsonrpc/index.d.mts +1 -0
  74. package/dist/provider/jsonrpc/index.mjs +2 -0
  75. package/dist/provider/jsonrpc/jsonrpc.cjs +20 -0
  76. package/dist/provider/jsonrpc/jsonrpc.cjs.map +1 -0
  77. package/dist/provider/jsonrpc/jsonrpc.d.cts +16 -0
  78. package/dist/provider/jsonrpc/jsonrpc.d.cts.map +1 -0
  79. package/dist/provider/jsonrpc/jsonrpc.d.mts +16 -0
  80. package/dist/provider/jsonrpc/jsonrpc.d.mts.map +1 -0
  81. package/dist/provider/jsonrpc/jsonrpc.mjs +19 -0
  82. package/dist/provider/jsonrpc/jsonrpc.mjs.map +1 -0
  83. package/dist/provider/provider.cjs +130 -0
  84. package/dist/provider/provider.cjs.map +1 -0
  85. package/dist/provider/provider.d.cts +130 -0
  86. package/dist/provider/provider.d.cts.map +1 -0
  87. package/dist/provider/provider.d.mts +130 -0
  88. package/dist/provider/provider.d.mts.map +1 -0
  89. package/dist/provider/provider.mjs +130 -0
  90. package/dist/provider/provider.mjs.map +1 -0
  91. package/dist/provider/types/abci.cjs +6 -0
  92. package/dist/provider/types/abci.cjs.map +1 -0
  93. package/dist/provider/types/abci.d.cts +42 -0
  94. package/dist/provider/types/abci.d.cts.map +1 -0
  95. package/dist/provider/types/abci.d.mts +42 -0
  96. package/dist/provider/types/abci.d.mts.map +1 -0
  97. package/dist/provider/types/abci.mjs +6 -0
  98. package/dist/provider/types/abci.mjs.map +1 -0
  99. package/dist/provider/types/common.d.cts +186 -0
  100. package/dist/provider/types/common.d.cts.map +1 -0
  101. package/dist/provider/types/common.d.mts +186 -0
  102. package/dist/provider/types/common.d.mts.map +1 -0
  103. package/dist/provider/types/jsonrpc.d.cts +30 -0
  104. package/dist/provider/types/jsonrpc.d.cts.map +1 -0
  105. package/dist/provider/types/jsonrpc.d.mts +30 -0
  106. package/dist/provider/types/jsonrpc.d.mts.map +1 -0
  107. package/dist/provider/utility/adapters.cjs +241 -0
  108. package/dist/provider/utility/adapters.cjs.map +1 -0
  109. package/dist/provider/utility/adapters.d.cts +19 -0
  110. package/dist/provider/utility/adapters.d.cts.map +1 -0
  111. package/dist/provider/utility/adapters.d.mts +19 -0
  112. package/dist/provider/utility/adapters.d.mts.map +1 -0
  113. package/dist/provider/utility/adapters.mjs +231 -0
  114. package/dist/provider/utility/adapters.mjs.map +1 -0
  115. package/dist/provider/utility/errors.utility.cjs +38 -0
  116. package/dist/provider/utility/errors.utility.cjs.map +1 -0
  117. package/dist/provider/utility/errors.utility.mjs +38 -0
  118. package/dist/provider/utility/errors.utility.mjs.map +1 -0
  119. package/dist/provider/utility/index.cjs +3 -0
  120. package/dist/provider/utility/index.d.cts +3 -0
  121. package/dist/provider/utility/index.d.mts +3 -0
  122. package/dist/provider/utility/index.mjs +4 -0
  123. package/dist/provider/utility/provider.utility.cjs +122 -0
  124. package/dist/provider/utility/provider.utility.cjs.map +1 -0
  125. package/{bin/provider/utility/provider.utility.d.ts → dist/provider/utility/provider.utility.d.cts} +15 -10
  126. package/dist/provider/utility/provider.utility.d.cts.map +1 -0
  127. package/dist/provider/utility/provider.utility.d.mts +45 -0
  128. package/dist/provider/utility/provider.utility.d.mts.map +1 -0
  129. package/dist/provider/utility/provider.utility.mjs +116 -0
  130. package/dist/provider/utility/provider.utility.mjs.map +1 -0
  131. package/dist/provider/utility/requests.utility.cjs +75 -0
  132. package/dist/provider/utility/requests.utility.cjs.map +1 -0
  133. package/dist/provider/utility/requests.utility.d.cts +40 -0
  134. package/dist/provider/utility/requests.utility.d.cts.map +1 -0
  135. package/dist/provider/utility/requests.utility.d.mts +40 -0
  136. package/dist/provider/utility/requests.utility.d.mts.map +1 -0
  137. package/dist/provider/utility/requests.utility.mjs +68 -0
  138. package/dist/provider/utility/requests.utility.mjs.map +1 -0
  139. package/dist/provider/websocket/index.cjs +1 -0
  140. package/dist/provider/websocket/index.d.cts +1 -0
  141. package/dist/provider/websocket/index.d.mts +1 -0
  142. package/dist/provider/websocket/index.mjs +2 -0
  143. package/dist/provider/websocket/ws.cjs +27 -0
  144. package/dist/provider/websocket/ws.cjs.map +1 -0
  145. package/dist/provider/websocket/ws.d.cts +21 -0
  146. package/dist/provider/websocket/ws.d.cts.map +1 -0
  147. package/dist/provider/websocket/ws.d.mts +21 -0
  148. package/dist/provider/websocket/ws.d.mts.map +1 -0
  149. package/dist/provider/websocket/ws.mjs +26 -0
  150. package/dist/provider/websocket/ws.mjs.map +1 -0
  151. package/dist/services/index.cjs +1 -0
  152. package/dist/services/index.d.cts +2 -0
  153. package/dist/services/index.d.mts +2 -0
  154. package/dist/services/index.mjs +2 -0
  155. package/dist/services/rest/restService.cjs +16 -0
  156. package/dist/services/rest/restService.cjs.map +1 -0
  157. package/dist/services/rest/restService.d.cts +9 -0
  158. package/dist/services/rest/restService.d.cts.map +1 -0
  159. package/dist/services/rest/restService.d.mts +9 -0
  160. package/dist/services/rest/restService.d.mts.map +1 -0
  161. package/dist/services/rest/restService.mjs +14 -0
  162. package/dist/services/rest/restService.mjs.map +1 -0
  163. package/dist/services/rest/restService.types.d.cts +11 -0
  164. package/dist/services/rest/restService.types.d.cts.map +1 -0
  165. package/dist/services/rest/restService.types.d.mts +11 -0
  166. package/dist/services/rest/restService.types.d.mts.map +1 -0
  167. package/dist/wallet/index.cjs +8 -0
  168. package/dist/wallet/index.d.cts +7 -0
  169. package/dist/wallet/index.d.mts +7 -0
  170. package/dist/wallet/index.mjs +9 -0
  171. package/dist/wallet/key/index.cjs +1 -0
  172. package/dist/wallet/key/index.mjs +2 -0
  173. package/dist/wallet/key/key.cjs +46 -0
  174. package/dist/wallet/key/key.cjs.map +1 -0
  175. package/dist/wallet/key/key.d.cts +26 -0
  176. package/dist/wallet/key/key.d.cts.map +1 -0
  177. package/dist/wallet/key/key.d.mts +26 -0
  178. package/dist/wallet/key/key.d.mts.map +1 -0
  179. package/dist/wallet/key/key.mjs +45 -0
  180. package/dist/wallet/key/key.mjs.map +1 -0
  181. package/dist/wallet/ledger/index.cjs +1 -0
  182. package/dist/wallet/ledger/index.d.cts +1 -0
  183. package/dist/wallet/ledger/index.d.mts +1 -0
  184. package/dist/wallet/ledger/index.mjs +2 -0
  185. package/dist/wallet/ledger/ledger.cjs +49 -0
  186. package/dist/wallet/ledger/ledger.cjs.map +1 -0
  187. package/dist/wallet/ledger/ledger.d.cts +27 -0
  188. package/dist/wallet/ledger/ledger.d.cts.map +1 -0
  189. package/dist/wallet/ledger/ledger.d.mts +27 -0
  190. package/dist/wallet/ledger/ledger.d.mts.map +1 -0
  191. package/dist/wallet/ledger/ledger.mjs +48 -0
  192. package/dist/wallet/ledger/ledger.mjs.map +1 -0
  193. package/dist/wallet/signer.d.cts +33 -0
  194. package/dist/wallet/signer.d.cts.map +1 -0
  195. package/dist/wallet/signer.d.mts +33 -0
  196. package/dist/wallet/signer.d.mts.map +1 -0
  197. package/dist/wallet/types/sign.cjs +6 -0
  198. package/dist/wallet/types/sign.cjs.map +1 -0
  199. package/dist/wallet/types/sign.d.cts +20 -0
  200. package/dist/wallet/types/sign.d.cts.map +1 -0
  201. package/dist/wallet/types/sign.d.mts +20 -0
  202. package/dist/wallet/types/sign.d.mts.map +1 -0
  203. package/dist/wallet/types/sign.mjs +6 -0
  204. package/dist/wallet/types/sign.mjs.map +1 -0
  205. package/dist/wallet/types/wallet.d.cts +9 -0
  206. package/dist/wallet/types/wallet.d.cts.map +1 -0
  207. package/dist/wallet/types/wallet.d.mts +9 -0
  208. package/dist/wallet/types/wallet.d.mts.map +1 -0
  209. package/dist/wallet/utility/index.cjs +1 -0
  210. package/dist/wallet/utility/index.d.cts +1 -0
  211. package/dist/wallet/utility/index.d.mts +1 -0
  212. package/dist/wallet/utility/index.mjs +2 -0
  213. package/dist/wallet/utility/utility.cjs +83 -0
  214. package/dist/wallet/utility/utility.cjs.map +1 -0
  215. package/dist/wallet/utility/utility.d.cts +42 -0
  216. package/dist/wallet/utility/utility.d.cts.map +1 -0
  217. package/dist/wallet/utility/utility.d.mts +42 -0
  218. package/dist/wallet/utility/utility.d.mts.map +1 -0
  219. package/dist/wallet/utility/utility.mjs +75 -0
  220. package/dist/wallet/utility/utility.mjs.map +1 -0
  221. package/dist/wallet/wallet.cjs +223 -0
  222. package/dist/wallet/wallet.cjs.map +1 -0
  223. package/dist/wallet/wallet.d.cts +113 -0
  224. package/dist/wallet/wallet.d.cts.map +1 -0
  225. package/dist/wallet/wallet.d.mts +113 -0
  226. package/dist/wallet/wallet.d.mts.map +1 -0
  227. package/dist/wallet/wallet.mjs +222 -0
  228. package/dist/wallet/wallet.mjs.map +1 -0
  229. package/package.json +57 -38
  230. package/bin/index.d.ts +0 -4
  231. package/bin/index.js +0 -20
  232. package/bin/proto/google/protobuf/any.d.ts +0 -145
  233. package/bin/proto/google/protobuf/any.js +0 -113
  234. package/bin/proto/index.d.ts +0 -2
  235. package/bin/proto/index.js +0 -20
  236. package/bin/proto/tm2/abci.d.ts +0 -37
  237. package/bin/proto/tm2/abci.js +0 -277
  238. package/bin/proto/tm2/multisig.d.ts +0 -43
  239. package/bin/proto/tm2/multisig.js +0 -322
  240. package/bin/proto/tm2/multisig.test.d.ts +0 -1
  241. package/bin/proto/tm2/multisig.test.js +0 -63
  242. package/bin/proto/tm2/tx.d.ts +0 -52
  243. package/bin/proto/tm2/tx.js +0 -360
  244. package/bin/provider/endpoints.d.ts +0 -29
  245. package/bin/provider/endpoints.js +0 -37
  246. package/bin/provider/errors/errors.d.ts +0 -59
  247. package/bin/provider/errors/errors.js +0 -173
  248. package/bin/provider/errors/index.d.ts +0 -1
  249. package/bin/provider/errors/index.js +0 -17
  250. package/bin/provider/errors/messages.d.ts +0 -19
  251. package/bin/provider/errors/messages.js +0 -41
  252. package/bin/provider/index.d.ts +0 -7
  253. package/bin/provider/index.js +0 -23
  254. package/bin/provider/jsonrpc/index.d.ts +0 -1
  255. package/bin/provider/jsonrpc/index.js +0 -17
  256. package/bin/provider/jsonrpc/jsonrpc.d.ts +0 -31
  257. package/bin/provider/jsonrpc/jsonrpc.js +0 -327
  258. package/bin/provider/jsonrpc/jsonrpc.test.d.ts +0 -1
  259. package/bin/provider/jsonrpc/jsonrpc.test.js +0 -488
  260. package/bin/provider/provider.d.ts +0 -98
  261. package/bin/provider/provider.js +0 -2
  262. package/bin/provider/types/abci.d.ts +0 -39
  263. package/bin/provider/types/abci.js +0 -4
  264. package/bin/provider/types/common.d.ts +0 -184
  265. package/bin/provider/types/common.js +0 -3
  266. package/bin/provider/types/index.d.ts +0 -3
  267. package/bin/provider/types/index.js +0 -19
  268. package/bin/provider/types/jsonrpc.d.ts +0 -26
  269. package/bin/provider/types/jsonrpc.js +0 -2
  270. package/bin/provider/utility/errors.utility.d.ts +0 -11
  271. package/bin/provider/utility/errors.utility.js +0 -56
  272. package/bin/provider/utility/index.d.ts +0 -2
  273. package/bin/provider/utility/index.js +0 -18
  274. package/bin/provider/utility/provider.utility.js +0 -244
  275. package/bin/provider/utility/requests.utility.d.ts +0 -35
  276. package/bin/provider/utility/requests.utility.js +0 -80
  277. package/bin/provider/websocket/index.d.ts +0 -1
  278. package/bin/provider/websocket/index.js +0 -17
  279. package/bin/provider/websocket/ws.d.ts +0 -58
  280. package/bin/provider/websocket/ws.js +0 -415
  281. package/bin/provider/websocket/ws.test.d.ts +0 -1
  282. package/bin/provider/websocket/ws.test.js +0 -648
  283. package/bin/services/index.d.ts +0 -2
  284. package/bin/services/index.js +0 -18
  285. package/bin/services/rest/restService.d.ts +0 -4
  286. package/bin/services/rest/restService.js +0 -72
  287. package/bin/services/rest/restService.types.d.ts +0 -6
  288. package/bin/services/rest/restService.types.js +0 -2
  289. package/bin/wallet/index.d.ts +0 -6
  290. package/bin/wallet/index.js +0 -22
  291. package/bin/wallet/key/index.d.ts +0 -1
  292. package/bin/wallet/key/index.js +0 -17
  293. package/bin/wallet/key/key.d.ts +0 -21
  294. package/bin/wallet/key/key.js +0 -102
  295. package/bin/wallet/key/key.test.d.ts +0 -1
  296. package/bin/wallet/key/key.test.js +0 -121
  297. package/bin/wallet/ledger/index.d.ts +0 -1
  298. package/bin/wallet/ledger/index.js +0 -17
  299. package/bin/wallet/ledger/ledger.d.ts +0 -22
  300. package/bin/wallet/ledger/ledger.js +0 -109
  301. package/bin/wallet/signer.d.ts +0 -29
  302. package/bin/wallet/signer.js +0 -2
  303. package/bin/wallet/types/index.d.ts +0 -2
  304. package/bin/wallet/types/index.js +0 -18
  305. package/bin/wallet/types/sign.d.ts +0 -16
  306. package/bin/wallet/types/sign.js +0 -4
  307. package/bin/wallet/types/wallet.d.ts +0 -5
  308. package/bin/wallet/types/wallet.js +0 -2
  309. package/bin/wallet/utility/index.d.ts +0 -1
  310. package/bin/wallet/utility/index.js +0 -17
  311. package/bin/wallet/utility/utility.d.ts +0 -36
  312. package/bin/wallet/utility/utility.js +0 -117
  313. package/bin/wallet/wallet.d.ts +0 -106
  314. package/bin/wallet/wallet.js +0 -361
  315. package/bin/wallet/wallet.test.d.ts +0 -1
  316. package/bin/wallet/wallet.test.js +0 -423
@@ -0,0 +1,113 @@
1
+ import { Any } from "../proto/google/protobuf/any.cjs";
2
+ import { Tx } from "../proto/tm2/tx.cjs";
3
+ import { BroadcastTransactionMap } from "../provider/types/common.cjs";
4
+ import { Provider } from "../provider/provider.cjs";
5
+ import { Signer } from "./signer.cjs";
6
+ import { AccountWalletOption, CreateWalletOptions } from "./types/wallet.cjs";
7
+ import { LedgerConnector } from "@cosmjs/ledger-amino";
8
+
9
+ //#region src/wallet/wallet.d.ts
10
+ interface SignTransactionOptions {
11
+ accountNumber?: string;
12
+ sequence?: string;
13
+ }
14
+ /**
15
+ * Wallet is a single account abstraction
16
+ * that can interact with the blockchain
17
+ */
18
+ declare class Wallet {
19
+ protected provider: Provider;
20
+ protected signer: Signer;
21
+ /**
22
+ * Connects the wallet to the specified {@link Provider}
23
+ * @param {Provider} provider the active {@link Provider}, if any
24
+ */
25
+ connect: (provider: Provider) => void;
26
+ /**
27
+ * Generates a private key-based wallet, using a random seed
28
+ * @param {AccountWalletOption} options the account options
29
+ */
30
+ static createRandom: (options?: AccountWalletOption) => Promise<Wallet>;
31
+ /**
32
+ * Generates a custom signer-based wallet
33
+ * @param {Signer} signer the custom signer implementing the Signer interface
34
+ * @param {CreateWalletOptions} options the wallet generation options
35
+ */
36
+ static fromSigner: (signer: Signer) => Promise<Wallet>;
37
+ /**
38
+ * Generates a bip39 mnemonic-based wallet
39
+ * @param {string} mnemonic the bip39 mnemonic
40
+ * @param {CreateWalletOptions} options the wallet generation options
41
+ */
42
+ static fromMnemonic: (mnemonic: string, options?: CreateWalletOptions) => Promise<Wallet>;
43
+ /**
44
+ * Generates a private key-based wallet
45
+ * @param {string} privateKey the private key
46
+ * @param {AccountWalletOption} options the account options
47
+ */
48
+ static fromPrivateKey: (privateKey: Uint8Array, options?: AccountWalletOption) => Promise<Wallet>;
49
+ /**
50
+ * Creates a Ledger-based wallet
51
+ * @param {LedgerConnector} connector the Ledger device connector
52
+ * @param {CreateWalletOptions} options the wallet generation options
53
+ */
54
+ static fromLedger: (connector: LedgerConnector, options?: CreateWalletOptions) => Wallet;
55
+ /**
56
+ * Fetches the address associated with the wallet
57
+ */
58
+ getAddress: () => Promise<string>;
59
+ /**
60
+ * Fetches the account sequence for the wallet
61
+ * @param {number} [height=latest] the block height
62
+ */
63
+ getAccountSequence: (height?: number) => Promise<number>;
64
+ /**
65
+ * Fetches the account number for the wallet. Errors out if the
66
+ * account is not initialized
67
+ * @param {number} [height=latest] the block height
68
+ */
69
+ getAccountNumber: (height?: number) => Promise<number>;
70
+ /**
71
+ * Fetches the account balance for the specific denomination
72
+ * @param {string} [denomination=ugnot] the fund denomination
73
+ */
74
+ getBalance: (denomination?: string) => Promise<number>;
75
+ /**
76
+ * Fetches the current (recommended) average gas price
77
+ */
78
+ getGasPrice: () => Promise<number>;
79
+ /**
80
+ * Estimates the gas limit for the transaction
81
+ * @param {Tx} tx the transaction that needs estimating
82
+ */
83
+ estimateGas: (tx: Tx) => Promise<bigint>;
84
+ /**
85
+ * Returns the connected provider, if any
86
+ */
87
+ getProvider: () => Provider;
88
+ /**
89
+ * Generates a transaction signature, and appends it to the transaction
90
+ * @param {Tx} tx the transaction to be signed
91
+ * @param {(messages: Any[]) => any[]} decodeTxMessages tx message decode callback
92
+ * that should expand the concrete message fields into an object. Required because
93
+ * the transaction sign bytes are generated using sorted JSON, which requires
94
+ * encoded message values to be decoded for sorting
95
+ */
96
+ signTransaction: (tx: Tx, decodeTxMessages: (messages: Any[]) => unknown[], opts?: SignTransactionOptions) => Promise<Tx>;
97
+ /**
98
+ * Encodes and sends the transaction. If the type of endpoint
99
+ * is a broadcast commit, waits for the transaction to be committed to the chain.
100
+ * The transaction needs to be signed beforehand.
101
+ * Returns the transaction hash (base-64)
102
+ * @param {Tx} tx the signed transaction
103
+ * @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)
104
+ */
105
+ sendTransaction<K extends keyof BroadcastTransactionMap>(tx: Tx, endpoint: K): Promise<BroadcastTransactionMap[K]["result"]>;
106
+ /**
107
+ * Returns the associated signer
108
+ */
109
+ getSigner: () => Signer;
110
+ }
111
+ //#endregion
112
+ export { SignTransactionOptions, Wallet };
113
+ //# sourceMappingURL=wallet.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.cts","names":[],"sources":["../../src/wallet/wallet.ts"],"mappings":";;;;;;;;;UAwCiB,sBAAA;EACf,aAAA;EACA,QAAA;AAAA;;;AAFF;;cASa,MAAA;EAAA,UACO,QAAA,EAAU,QAAA;EAAA,UACV,MAAA,EAAQ,MAAA;EAFf;;;;EAQX,OAAA,GAAW,QAAA,EAAU,QAAA;EAAA;;;;EAAA,OAUd,YAAA,GACL,OAAA,GAAU,mBAAA,KACT,OAAA,CAAQ,MAAA;EAwByC;;;;;EAAA,OAA7C,UAAA,GAAoB,MAAA,EAAQ,MAAA,KAAS,OAAA,CAAQ,MAAA;EA0CxC;;;;;EAAA,OA7BL,YAAA,GACL,QAAA,UACA,OAAA,GAAU,mBAAA,KACT,OAAA,CAAQ,MAAA;EAqEM;;;;;EAAA,OA7CV,cAAA,GACL,UAAA,EAAY,UAAA,EACZ,OAAA,GAAU,mBAAA,KACT,OAAA,CAAQ,MAAA;EA8GmB;;;;;EAAA,OAxFvB,UAAA,GACL,SAAA,EAAW,eAAA,EACX,OAAA,GAAU,mBAAA,KACT,MAAA;EAgHA;;;EA/FH,UAAA,QAAiB,OAAA;EAgLN;;;;EAxKX,kBAAA,GAA4B,MAAA,cAAkB,OAAA;EAuLxB;;;;;EAvKtB,gBAAA,GAA0B,MAAA,cAAkB,OAAA;EAjJvB;;;;EAgKrB,UAAA,GAAoB,YAAA,cAAwB,OAAA;EApJzC;;;EAqKH,WAAA,QAAwB,OAAA;EA7IG;;;;EAyJ3B,WAAA,GAAqB,EAAA,EAAI,EAAA,KAAK,OAAA;EA1IlB;;;EAqJZ,WAAA,QAAkB,QAAA;EA5HX;;;;;;;;EAwIP,eAAA,GACE,EAAA,EAAI,EAAA,EACJ,gBAAA,GAAmB,QAAA,EAAU,GAAA,kBAC7B,IAAA,GAAO,sBAAA,KACN,OAAA,CAAQ,EAAA;EAlHT;;;;;;;;EAgMI,eAAA,iBAAgC,uBAAA,CAAA,CACpC,EAAA,EAAI,EAAA,EACJ,QAAA,EAAU,CAAA,GACT,OAAA,CAAQ,uBAAA,CAAwB,CAAA;EAxJnC;;;EAuKA,SAAA,QAAgB,MAAA;AAAA"}
@@ -0,0 +1,113 @@
1
+ import { Any } from "../proto/google/protobuf/any.mjs";
2
+ import { Tx } from "../proto/tm2/tx.mjs";
3
+ import { BroadcastTransactionMap } from "../provider/types/common.mjs";
4
+ import { Provider } from "../provider/provider.mjs";
5
+ import { Signer } from "./signer.mjs";
6
+ import { AccountWalletOption, CreateWalletOptions } from "./types/wallet.mjs";
7
+ import { LedgerConnector } from "@cosmjs/ledger-amino";
8
+
9
+ //#region src/wallet/wallet.d.ts
10
+ interface SignTransactionOptions {
11
+ accountNumber?: string;
12
+ sequence?: string;
13
+ }
14
+ /**
15
+ * Wallet is a single account abstraction
16
+ * that can interact with the blockchain
17
+ */
18
+ declare class Wallet {
19
+ protected provider: Provider;
20
+ protected signer: Signer;
21
+ /**
22
+ * Connects the wallet to the specified {@link Provider}
23
+ * @param {Provider} provider the active {@link Provider}, if any
24
+ */
25
+ connect: (provider: Provider) => void;
26
+ /**
27
+ * Generates a private key-based wallet, using a random seed
28
+ * @param {AccountWalletOption} options the account options
29
+ */
30
+ static createRandom: (options?: AccountWalletOption) => Promise<Wallet>;
31
+ /**
32
+ * Generates a custom signer-based wallet
33
+ * @param {Signer} signer the custom signer implementing the Signer interface
34
+ * @param {CreateWalletOptions} options the wallet generation options
35
+ */
36
+ static fromSigner: (signer: Signer) => Promise<Wallet>;
37
+ /**
38
+ * Generates a bip39 mnemonic-based wallet
39
+ * @param {string} mnemonic the bip39 mnemonic
40
+ * @param {CreateWalletOptions} options the wallet generation options
41
+ */
42
+ static fromMnemonic: (mnemonic: string, options?: CreateWalletOptions) => Promise<Wallet>;
43
+ /**
44
+ * Generates a private key-based wallet
45
+ * @param {string} privateKey the private key
46
+ * @param {AccountWalletOption} options the account options
47
+ */
48
+ static fromPrivateKey: (privateKey: Uint8Array, options?: AccountWalletOption) => Promise<Wallet>;
49
+ /**
50
+ * Creates a Ledger-based wallet
51
+ * @param {LedgerConnector} connector the Ledger device connector
52
+ * @param {CreateWalletOptions} options the wallet generation options
53
+ */
54
+ static fromLedger: (connector: LedgerConnector, options?: CreateWalletOptions) => Wallet;
55
+ /**
56
+ * Fetches the address associated with the wallet
57
+ */
58
+ getAddress: () => Promise<string>;
59
+ /**
60
+ * Fetches the account sequence for the wallet
61
+ * @param {number} [height=latest] the block height
62
+ */
63
+ getAccountSequence: (height?: number) => Promise<number>;
64
+ /**
65
+ * Fetches the account number for the wallet. Errors out if the
66
+ * account is not initialized
67
+ * @param {number} [height=latest] the block height
68
+ */
69
+ getAccountNumber: (height?: number) => Promise<number>;
70
+ /**
71
+ * Fetches the account balance for the specific denomination
72
+ * @param {string} [denomination=ugnot] the fund denomination
73
+ */
74
+ getBalance: (denomination?: string) => Promise<number>;
75
+ /**
76
+ * Fetches the current (recommended) average gas price
77
+ */
78
+ getGasPrice: () => Promise<number>;
79
+ /**
80
+ * Estimates the gas limit for the transaction
81
+ * @param {Tx} tx the transaction that needs estimating
82
+ */
83
+ estimateGas: (tx: Tx) => Promise<bigint>;
84
+ /**
85
+ * Returns the connected provider, if any
86
+ */
87
+ getProvider: () => Provider;
88
+ /**
89
+ * Generates a transaction signature, and appends it to the transaction
90
+ * @param {Tx} tx the transaction to be signed
91
+ * @param {(messages: Any[]) => any[]} decodeTxMessages tx message decode callback
92
+ * that should expand the concrete message fields into an object. Required because
93
+ * the transaction sign bytes are generated using sorted JSON, which requires
94
+ * encoded message values to be decoded for sorting
95
+ */
96
+ signTransaction: (tx: Tx, decodeTxMessages: (messages: Any[]) => unknown[], opts?: SignTransactionOptions) => Promise<Tx>;
97
+ /**
98
+ * Encodes and sends the transaction. If the type of endpoint
99
+ * is a broadcast commit, waits for the transaction to be committed to the chain.
100
+ * The transaction needs to be signed beforehand.
101
+ * Returns the transaction hash (base-64)
102
+ * @param {Tx} tx the signed transaction
103
+ * @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)
104
+ */
105
+ sendTransaction<K extends keyof BroadcastTransactionMap>(tx: Tx, endpoint: K): Promise<BroadcastTransactionMap[K]["result"]>;
106
+ /**
107
+ * Returns the associated signer
108
+ */
109
+ getSigner: () => Signer;
110
+ }
111
+ //#endregion
112
+ export { SignTransactionOptions, Wallet };
113
+ //# sourceMappingURL=wallet.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.mts","names":[],"sources":["../../src/wallet/wall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BAAA,CAAwB,CAAA;EAxJnC;;;EAuKA,SAAA,QAAgB,MAAA;AAAA"}
@@ -0,0 +1,222 @@
1
+ import { PubKeySecp256k1, Tx } from "../proto/tm2/tx.mjs";
2
+ import "../proto/index.mjs";
3
+ import { _defineProperty } from "../_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.mjs";
4
+ import { uint8ArrayToBase64 } from "../provider/utility/requests.utility.mjs";
5
+ import "../provider/index.mjs";
6
+ import { encodeCharacterSet, generateEntropy, generateKeyPair, sortedJsonStringify, stringToUTF8 } from "./utility/utility.mjs";
7
+ import "./utility/index.mjs";
8
+ import { KeySigner } from "./key/key.mjs";
9
+ import "./key/index.mjs";
10
+ import { LedgerSigner } from "./ledger/ledger.mjs";
11
+ import "./ledger/index.mjs";
12
+ import { Secp256k1PubKeyType } from "./types/sign.mjs";
13
+ import { Bip39, Secp256k1 } from "@cosmjs/crypto";
14
+ //#region src/wallet/wallet.ts
15
+ var _Wallet;
16
+ /**
17
+ * Wallet is a single account abstraction
18
+ * that can interact with the blockchain
19
+ */
20
+ var Wallet = class {
21
+ constructor() {
22
+ _defineProperty(
23
+ this,
24
+ /**
25
+ * Connects the wallet to the specified {@link Provider}
26
+ * @param {Provider} provider the active {@link Provider}, if any
27
+ */
28
+ "connect",
29
+ (provider) => {
30
+ this.provider = provider;
31
+ }
32
+ );
33
+ _defineProperty(
34
+ this,
35
+ /**
36
+ * Fetches the address associated with the wallet
37
+ */
38
+ "getAddress",
39
+ () => {
40
+ return this.signer.getAddress();
41
+ }
42
+ );
43
+ _defineProperty(
44
+ this,
45
+ /**
46
+ * Fetches the account sequence for the wallet
47
+ * @param {number} [height=latest] the block height
48
+ */
49
+ "getAccountSequence",
50
+ async (height) => {
51
+ if (!this.provider) throw new Error("provider not connected");
52
+ const address = await this.getAddress();
53
+ return this.provider.getAccountSequence(address, height);
54
+ }
55
+ );
56
+ _defineProperty(
57
+ this,
58
+ /**
59
+ * Fetches the account number for the wallet. Errors out if the
60
+ * account is not initialized
61
+ * @param {number} [height=latest] the block height
62
+ */
63
+ "getAccountNumber",
64
+ async (height) => {
65
+ if (!this.provider) throw new Error("provider not connected");
66
+ const address = await this.getAddress();
67
+ return this.provider.getAccountNumber(address, height);
68
+ }
69
+ );
70
+ _defineProperty(
71
+ this,
72
+ /**
73
+ * Fetches the account balance for the specific denomination
74
+ * @param {string} [denomination=ugnot] the fund denomination
75
+ */
76
+ "getBalance",
77
+ async (denomination) => {
78
+ if (!this.provider) throw new Error("provider not connected");
79
+ const address = await this.getAddress();
80
+ return this.provider.getBalance(address, denomination ? denomination : "ugnot");
81
+ }
82
+ );
83
+ _defineProperty(
84
+ this,
85
+ /**
86
+ * Fetches the current (recommended) average gas price
87
+ */
88
+ "getGasPrice",
89
+ async () => {
90
+ if (!this.provider) throw new Error("provider not connected");
91
+ return this.provider.getGasPrice();
92
+ }
93
+ );
94
+ _defineProperty(
95
+ this,
96
+ /**
97
+ * Estimates the gas limit for the transaction
98
+ * @param {Tx} tx the transaction that needs estimating
99
+ */
100
+ "estimateGas",
101
+ async (tx) => {
102
+ if (!this.provider) throw new Error("provider not connected");
103
+ return this.provider.estimateGas(tx);
104
+ }
105
+ );
106
+ _defineProperty(
107
+ this,
108
+ /**
109
+ * Returns the connected provider, if any
110
+ */
111
+ "getProvider",
112
+ () => {
113
+ return this.provider;
114
+ }
115
+ );
116
+ _defineProperty(
117
+ this,
118
+ /**
119
+ * Generates a transaction signature, and appends it to the transaction
120
+ * @param {Tx} tx the transaction to be signed
121
+ * @param {(messages: Any[]) => any[]} decodeTxMessages tx message decode callback
122
+ * that should expand the concrete message fields into an object. Required because
123
+ * the transaction sign bytes are generated using sorted JSON, which requires
124
+ * encoded message values to be decoded for sorting
125
+ */
126
+ "signTransaction",
127
+ async (tx, decodeTxMessages, opts) => {
128
+ if (!this.provider) throw new Error("provider not connected");
129
+ if (!tx.fee) throw new Error("invalid transaction fee provided");
130
+ const chainID = (await this.provider.getStatus()).node_info.network;
131
+ let accountNumber = opts?.accountNumber;
132
+ let accountSequence = opts?.sequence;
133
+ if (accountNumber === void 0 || accountSequence === void 0) {
134
+ const address = await this.getAddress();
135
+ const account = await this.provider.getAccount(address);
136
+ if (accountNumber === void 0) accountNumber = account.BaseAccount.account_number;
137
+ if (accountSequence === void 0) accountSequence = account.BaseAccount.sequence;
138
+ }
139
+ const publicKey = await this.signer.getPublicKey();
140
+ const signBytes = stringToUTF8(encodeCharacterSet(sortedJsonStringify({
141
+ chain_id: chainID,
142
+ account_number: accountNumber,
143
+ sequence: accountSequence,
144
+ fee: {
145
+ gas_fee: tx.fee.gas_fee,
146
+ gas_wanted: tx.fee.gas_wanted.toString(10)
147
+ },
148
+ msgs: decodeTxMessages(tx.messages),
149
+ memo: tx.memo
150
+ })));
151
+ const wrappedKey = { key: publicKey };
152
+ const txSignature = {
153
+ pub_key: {
154
+ type_url: Secp256k1PubKeyType,
155
+ value: PubKeySecp256k1.encode(wrappedKey).finish()
156
+ },
157
+ signature: await this.getSigner().signData(signBytes)
158
+ };
159
+ return {
160
+ ...tx,
161
+ signatures: [...tx.signatures, txSignature]
162
+ };
163
+ }
164
+ );
165
+ _defineProperty(
166
+ this,
167
+ /**
168
+ * Returns the associated signer
169
+ */
170
+ "getSigner",
171
+ () => {
172
+ return this.signer;
173
+ }
174
+ );
175
+ }
176
+ /**
177
+ * Encodes and sends the transaction. If the type of endpoint
178
+ * is a broadcast commit, waits for the transaction to be committed to the chain.
179
+ * The transaction needs to be signed beforehand.
180
+ * Returns the transaction hash (base-64)
181
+ * @param {Tx} tx the signed transaction
182
+ * @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)
183
+ */
184
+ async sendTransaction(tx, endpoint) {
185
+ if (!this.provider) throw new Error("provider not connected");
186
+ const encodedTx = uint8ArrayToBase64(Tx.encode(tx).finish());
187
+ return this.provider.sendTransaction(encodedTx, endpoint);
188
+ }
189
+ };
190
+ _Wallet = Wallet;
191
+ _defineProperty(Wallet, "createRandom", async (options) => {
192
+ const { publicKey, privateKey } = await generateKeyPair(Bip39.encode(generateEntropy()).toString(), 0);
193
+ const wallet = new _Wallet();
194
+ wallet.signer = new KeySigner(privateKey, Secp256k1.compressPubkey(publicKey), options?.addressPrefix);
195
+ return wallet;
196
+ });
197
+ _defineProperty(Wallet, "fromSigner", async (signer) => {
198
+ const wallet = new _Wallet();
199
+ wallet.signer = signer;
200
+ return wallet;
201
+ });
202
+ _defineProperty(Wallet, "fromMnemonic", async (mnemonic, options) => {
203
+ const { publicKey, privateKey } = await generateKeyPair(mnemonic, options?.accountIndex);
204
+ const wallet = new _Wallet();
205
+ wallet.signer = new KeySigner(privateKey, Secp256k1.compressPubkey(publicKey), options?.addressPrefix);
206
+ return wallet;
207
+ });
208
+ _defineProperty(Wallet, "fromPrivateKey", async (privateKey, options) => {
209
+ const { pubkey: publicKey } = await Secp256k1.makeKeypair(privateKey);
210
+ const wallet = new _Wallet();
211
+ wallet.signer = new KeySigner(privateKey, Secp256k1.compressPubkey(publicKey), options?.addressPrefix);
212
+ return wallet;
213
+ });
214
+ _defineProperty(Wallet, "fromLedger", (connector, options) => {
215
+ const wallet = new _Wallet();
216
+ wallet.signer = new LedgerSigner(connector, options?.accountIndex ?? 0, options?.addressPrefix);
217
+ return wallet;
218
+ });
219
+ //#endregion
220
+ export { Wallet };
221
+
222
+ //# sourceMappingURL=wallet.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.mjs","names":["Wallet"],"sources":["../../src/wallet/wallet.ts"],"sourcesContent":["import {\n Bip39, Secp256k1,\n} from \"@cosmjs/crypto\";\nimport {\n LedgerConnector,\n} from \"@cosmjs/ledger-amino\";\n\nimport {\n Any, PubKeySecp256k1, Tx, TxSignature,\n} from \"../proto/index.js\";\nimport {\n BroadcastTransactionMap,\n Provider,\n Status,\n uint8ArrayToBase64,\n} from \"../provider/index.js\";\nimport {\n KeySigner,\n} from \"./key/index.js\";\nimport {\n LedgerSigner,\n} from \"./ledger/index.js\";\nimport {\n Signer,\n} from \"./signer.js\";\nimport {\n AccountWalletOption,\n CreateWalletOptions,\n Secp256k1PubKeyType,\n TxSignPayload,\n} from \"./types/index.js\";\nimport {\n encodeCharacterSet,\n generateEntropy,\n generateKeyPair,\n stringToUTF8,\n} from \"./utility/index.js\";\nimport {\n sortedJsonStringify,\n} from \"./utility/index.js\";\nexport interface SignTransactionOptions {\n accountNumber?: string\n sequence?: string\n}\n\n/**\n * Wallet is a single account abstraction\n * that can interact with the blockchain\n */\nexport class Wallet {\n protected declare provider: Provider;\n protected declare signer: Signer;\n\n /**\n * Connects the wallet to the specified {@link Provider}\n * @param {Provider} provider the active {@link Provider}, if any\n */\n connect = (provider: Provider) => {\n this.provider = provider;\n };\n\n // Wallet initialization //\n\n /**\n * Generates a private key-based wallet, using a random seed\n * @param {AccountWalletOption} options the account options\n */\n static createRandom = async (\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n Bip39.encode(generateEntropy()).toString(),\n 0,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a custom signer-based wallet\n * @param {Signer} signer the custom signer implementing the Signer interface\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromSigner = async (signer: Signer): Promise<Wallet> => {\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = signer;\n\n return wallet;\n };\n\n /**\n * Generates a bip39 mnemonic-based wallet\n * @param {string} mnemonic the bip39 mnemonic\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromMnemonic = async (\n mnemonic: string,\n options?: CreateWalletOptions,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n mnemonic,\n options?.accountIndex,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a private key-based wallet\n * @param {string} privateKey the private key\n * @param {AccountWalletOption} options the account options\n */\n static fromPrivateKey = async (\n privateKey: Uint8Array,\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n // Derive the public key\n const {\n pubkey: publicKey,\n } = await Secp256k1.makeKeypair(privateKey);\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Creates a Ledger-based wallet\n * @param {LedgerConnector} connector the Ledger device connector\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromLedger = (\n connector: LedgerConnector,\n options?: CreateWalletOptions,\n ): Wallet => {\n const wallet: Wallet = new Wallet();\n\n wallet.signer = new LedgerSigner(\n connector,\n options?.accountIndex ?? 0,\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n // Account manipulation //\n\n /**\n * Fetches the address associated with the wallet\n */\n getAddress = (): Promise<string> => {\n return this.signer.getAddress();\n };\n\n /**\n * Fetches the account sequence for the wallet\n * @param {number} [height=latest] the block height\n */\n getAccountSequence = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountSequence(address, height);\n };\n\n /**\n * Fetches the account number for the wallet. Errors out if the\n * account is not initialized\n * @param {number} [height=latest] the block height\n */\n getAccountNumber = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountNumber(address, height);\n };\n\n /**\n * Fetches the account balance for the specific denomination\n * @param {string} [denomination=ugnot] the fund denomination\n */\n getBalance = async (denomination?: string): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getBalance(\n address,\n denomination ? denomination : \"ugnot\",\n );\n };\n\n /**\n * Fetches the current (recommended) average gas price\n */\n getGasPrice = async (): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.getGasPrice();\n };\n\n /**\n * Estimates the gas limit for the transaction\n * @param {Tx} tx the transaction that needs estimating\n */\n estimateGas = async (tx: Tx): Promise<bigint> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.estimateGas(tx);\n };\n\n /**\n * Returns the connected provider, if any\n */\n getProvider = (): Provider => {\n return this.provider;\n };\n\n /**\n * Generates a transaction signature, and appends it to the transaction\n * @param {Tx} tx the transaction to be signed\n * @param {(messages: Any[]) => any[]} decodeTxMessages tx message decode callback\n * that should expand the concrete message fields into an object. Required because\n * the transaction sign bytes are generated using sorted JSON, which requires\n * encoded message values to be decoded for sorting\n */\n signTransaction = async (\n tx: Tx,\n decodeTxMessages: (messages: Any[]) => unknown[],\n opts?: SignTransactionOptions,\n ): Promise<Tx> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Make sure the tx fee is initialized\n if (!tx.fee) {\n throw new Error(\"invalid transaction fee provided\");\n }\n\n // Extract the relevant chain data\n const status: Status = await this.provider.getStatus();\n const chainID: string = status.node_info.network;\n\n // Extract the relevant account data\n let accountNumber = opts?.accountNumber;\n let accountSequence = opts?.sequence;\n if (accountNumber === undefined || accountSequence === undefined) {\n const address: string = await this.getAddress();\n const account = await this.provider.getAccount(address);\n if (accountNumber === undefined) {\n accountNumber = account.BaseAccount.account_number;\n }\n if (accountSequence === undefined) {\n accountSequence = account.BaseAccount.sequence;\n }\n }\n const publicKey: Uint8Array = await this.signer.getPublicKey();\n\n // Create the signature payload\n const signPayload: TxSignPayload = {\n chain_id: chainID,\n account_number: accountNumber,\n sequence: accountSequence,\n fee: {\n gas_fee: tx.fee.gas_fee,\n gas_wanted: tx.fee.gas_wanted.toString(10),\n },\n msgs: decodeTxMessages(tx.messages), // unrolled message objects\n memo: tx.memo,\n };\n\n // The TM2 node does signature verification using\n // a sorted JSON object, so the payload needs to be sorted\n // before signing\n const signBytes: Uint8Array = stringToUTF8(\n encodeCharacterSet(sortedJsonStringify(signPayload)),\n );\n\n // The public key needs to be encoded using protobuf for Amino\n const wrappedKey: PubKeySecp256k1 = {\n key: publicKey,\n };\n\n // Generate the signature\n const txSignature: TxSignature = {\n pub_key: {\n type_url: Secp256k1PubKeyType,\n value: PubKeySecp256k1.encode(wrappedKey).finish(),\n },\n signature: await this.getSigner().signData(signBytes),\n };\n\n // Append the signature\n return {\n ...tx,\n signatures: [...tx.signatures, txSignature],\n };\n };\n\n /**\n * Encodes and sends the transaction. If the type of endpoint\n * is a broadcast commit, waits for the transaction to be committed to the chain.\n * The transaction needs to be signed beforehand.\n * Returns the transaction hash (base-64)\n * @param {Tx} tx the signed transaction\n * @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)\n */\n async sendTransaction<K extends keyof BroadcastTransactionMap>(\n tx: Tx,\n endpoint: K,\n ): Promise<BroadcastTransactionMap[K][\"result\"]> {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Encode the transaction to base-64\n const encodedTx: string = uint8ArrayToBase64(Tx.encode(tx).finish());\n\n // Send the encoded transaction\n return this.provider.sendTransaction(encodedTx, endpoint);\n }\n\n /**\n * Returns the associated signer\n */\n getSigner = (): Signer => {\n return this.signer;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiDA,IAAa,SAAb,MAAoB;;;;;;;;GAQlB;IAAW,aAAuB;AAChC,SAAK,WAAW;;GAChB;;;;;;GAuHF;SAAoC;AAClC,WAAO,KAAK,OAAO,YAAY;;GAC/B;;;;;;;GAMF;GAAqB,OAAO,WAAqC;AAC/D,QAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM,yBAAyB;IAI3C,MAAM,UAAkB,MAAM,KAAK,YAAY;AAE/C,WAAO,KAAK,SAAS,mB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iB,IAAIA,SAAQ;AACnC,QAAO,SAAS,IAAI,UAClB,YACA,UAAU,eAAe,UAAU,EACnC,SAAS,cACV;AAED,QAAO;EACP;wBAOK,kBAAiB,OACtB,YACA,YACoB;CAEpB,MAAM,EACJ,QAAQ,cACN,MAAM,UAAU,YAAY,WAAW;CAG3C,MAAM,SAAiB,IAAIA,SAAQ;AACnC,QAAO,SAAS,IAAI,UAClB,YACA,UAAU,eAAe,UAAU,EACnC,SAAS,cACV;AAED,QAAO;EACP;wBAOK,eACL,WACA,YACW;CACX,MAAM,SAAiB,IAAIA,SAAQ;AAEnC,QAAO,SAAS,IAAI,aAClB,WACA,SAAS,gBAAgB,GACzB,SAAS,cACV;AAED,QAAO;EACP"}
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@gnolang/tm2-js-client",
3
- "version": "1.3.3",
3
+ "version": "2.0.1",
4
4
  "description": "Tendermint2 JS / TS Client",
5
- "main": "./bin/index.js",
6
5
  "repository": {
7
6
  "type": "git",
8
7
  "url": "git+https://github.com/gnolang/tm2-js-client.git"
@@ -18,52 +17,72 @@
18
17
  "license": "Apache-2.0",
19
18
  "homepage": "https://gno.land/",
20
19
  "files": [
21
- "bin/**/*"
20
+ "dist/",
21
+ "*.md",
22
+ "!*.spec.*",
23
+ "!**/testdata/"
22
24
  ],
23
25
  "publishConfig": {
24
26
  "access": "public",
25
27
  "registry": "https://registry.npmjs.org/"
26
28
  },
29
+ "type": "module",
27
30
  "devDependencies": {
28
- "@eslint/js": "^9.33.0",
29
- "@types/jest": "^30.0.0",
30
- "@types/long": "^5.0.0",
31
- "@types/node": "^24.3.0",
32
- "@types/ws": "^8.5.11",
33
- "@typescript-eslint/eslint-plugin": "^8.42.0",
34
- "@typescript-eslint/parser": "^8.42.0",
35
- "@typescript-eslint/typescript-estree": "^8.42.0",
36
- "eslint": "^9.35.0",
37
- "eslint-config-prettier": "^10.1.5",
38
- "eslint-plugin-prettier": "5.5.1",
39
- "globals": "^16.3.0",
40
- "jest": "^30.0.4",
41
- "jest-mock-extended": "^4.0.0",
42
- "jest-websocket-mock": "^2.4.0",
43
- "prettier": "^3.6.2",
44
- "ts-jest": "^29.4.0",
45
- "ts-proto": "^2.7.5",
46
- "typescript": "^5.9.2",
47
- "typescript-eslint": "^8.39.1"
31
+ "@arethetypeswrong/core": "^0.18.2",
32
+ "@eslint/js": "^10.0.1",
33
+ "@stylistic/eslint-plugin": "^5.10.0",
34
+ "@types/node": "^25.5.0",
35
+ "@types/ws": "^8.18.1",
36
+ "@vitest/coverage-istanbul": "^4.1.2",
37
+ "eslint": "^10.1.0",
38
+ "eslint-plugin-simple-import-sort": "^12.1.1",
39
+ "globals": "^17.4.0",
40
+ "ts-proto": "^2.11.6",
41
+ "tsdown": "^0.21.7",
42
+ "type-fest": "^5.5.0",
43
+ "typescript": "^6.0.2",
44
+ "typescript-eslint": "^8.57.2",
45
+ "vitest": "^4.1.2",
46
+ "vitest-websocket-mock": "^0.5.0"
48
47
  },
49
48
  "dependencies": {
50
- "@cosmjs/amino": "^0.36.0",
51
- "@cosmjs/crypto": "^0.36.0",
52
- "@cosmjs/ledger-amino": "^0.36.0",
53
- "@types/uuid": "^10.0.0",
54
- "axios": "^1.11.0",
55
- "long": "^5.3.2",
56
- "protobufjs": "^7.5.3",
57
- "uuid": "^11.1.0",
58
- "ws": "^8.18.0"
49
+ "@bufbuild/protobuf": "^2.11.0",
50
+ "@cosmjs/amino": "^0.38.1",
51
+ "@cosmjs/crypto": "^0.38.1",
52
+ "@cosmjs/ledger-amino": "^0.38.1",
53
+ "@gnolang/tm2-rpc": "^1.0.0",
54
+ "@noble/hashes": "^2.0.1",
55
+ "axios": "^1.14.0",
56
+ "protobufjs": "^8.0.0",
57
+ "uuid": "^13.0.0",
58
+ "ws": "^8.20.0"
59
59
  },
60
60
  "scripts": {
61
61
  "tsc": "tsc",
62
- "lint": "eslint '**/*.ts' --fix",
63
- "prettier": "prettier --write .",
64
- "build": "yarn tsc",
65
- "test": "jest",
66
- "prepare": "yarn build",
67
- "prepublishOnly": "yarn lint && yarn prettier"
62
+ "lint": "eslint",
63
+ "lint:fix": "eslint --fix",
64
+ "build": "tsc --noEmit && tsdown",
65
+ "test": "vitest",
66
+ "test:watch": "vitest --watch",
67
+ "test:coverage": "vitest --coverage",
68
+ "prepare": "pnpm build",
69
+ "prepublishOnly": "pnpm lint"
70
+ },
71
+ "packageManager": "pnpm@10.33.0",
72
+ "main": "dist/index.cjs",
73
+ "module": "dist/index.mjs",
74
+ "types": "dist/index.d.mts",
75
+ "exports": {
76
+ ".": {
77
+ "import": {
78
+ "types": "./dist/index.d.mts",
79
+ "default": "./dist/index.mjs"
80
+ },
81
+ "require": {
82
+ "types": "./dist/index.d.cts",
83
+ "default": "./dist/index.cjs"
84
+ }
85
+ },
86
+ "./package.json": "./package.json"
68
87
  }
69
88
  }
package/bin/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './provider';
2
- export * from './wallet';
3
- export * from './proto';
4
- export * from './services';
package/bin/index.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./provider"), exports);
18
- __exportStar(require("./wallet"), exports);
19
- __exportStar(require("./proto"), exports);
20
- __exportStar(require("./services"), exports);