@firmachain/firma-js 0.2.62 → 0.3.0-beta1

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 (243) hide show
  1. package/README.md +4 -1
  2. package/dist/sdk/FirmaAuthzService.d.ts +8 -8
  3. package/dist/sdk/FirmaAuthzService.js +12 -6
  4. package/dist/sdk/FirmaBankService.d.ts +4 -4
  5. package/dist/sdk/FirmaContractService.d.ts +4 -4
  6. package/dist/sdk/FirmaCosmWasmCw20.d.ts +14 -14
  7. package/dist/sdk/FirmaCosmWasmCw721.d.ts +31 -13
  8. package/dist/sdk/FirmaCosmWasmCw721.js +25 -0
  9. package/dist/sdk/FirmaCosmWasmCwBridge.d.ts +9 -9
  10. package/dist/sdk/FirmaCosmWasmCwMarketplace.d.ts +8 -8
  11. package/dist/sdk/FirmaCosmWasmService.d.ts +8 -8
  12. package/dist/sdk/FirmaCosmWasmService.js +2 -3
  13. package/dist/sdk/FirmaDistributionService.d.ts +6 -6
  14. package/dist/sdk/FirmaFeeGrantService.d.ts +4 -4
  15. package/dist/sdk/FirmaGovService.d.ts +12 -9
  16. package/dist/sdk/FirmaGovService.js +162 -97
  17. package/dist/sdk/FirmaIbcService.d.ts +3 -4
  18. package/dist/sdk/FirmaIbcService.js +5 -2
  19. package/dist/sdk/FirmaNftService.d.ts +5 -5
  20. package/dist/sdk/FirmaStakingService.d.ts +6 -6
  21. package/dist/sdk/FirmaTokenService.d.ts +5 -5
  22. package/dist/sdk/FirmaUtil.d.ts +1 -1
  23. package/dist/sdk/FirmaUtil.js +12 -14
  24. package/dist/sdk/firmachain/amino/addresses.js +1 -1
  25. package/dist/sdk/firmachain/amino/aminomsgs.d.ts +10 -0
  26. package/dist/sdk/firmachain/amino/aminomsgs.js +5 -1
  27. package/dist/sdk/firmachain/amino/aminotypes.js +27 -10
  28. package/dist/sdk/firmachain/amino/coins.d.ts +14 -2
  29. package/dist/sdk/firmachain/amino/coins.js +26 -5
  30. package/dist/sdk/firmachain/amino/encoding.d.ts +10 -1
  31. package/dist/sdk/firmachain/amino/encoding.js +21 -3
  32. package/dist/sdk/firmachain/amino/signdoc.d.ts +21 -3
  33. package/dist/sdk/firmachain/amino/signdoc.js +37 -11
  34. package/dist/sdk/firmachain/amino/signer.d.ts +2 -1
  35. package/dist/sdk/firmachain/authz/AuthzTxTypes.d.ts +7 -6
  36. package/dist/sdk/firmachain/authz/AuthzTxTypes.js +7 -6
  37. package/dist/sdk/firmachain/bank/BankQueryClient.js +1 -1
  38. package/dist/sdk/firmachain/common/CommonTxClient.js +11 -9
  39. package/dist/sdk/firmachain/common/ITxClient.d.ts +6 -6
  40. package/dist/sdk/firmachain/common/ITxClient.js +82 -24
  41. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +4 -9
  42. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +37 -32
  43. package/dist/sdk/firmachain/common/LedgerWallet.js +4 -8
  44. package/dist/sdk/firmachain/common/TxCommon.d.ts +1 -2
  45. package/dist/sdk/firmachain/common/accounts.d.ts +7 -3
  46. package/dist/sdk/firmachain/common/accounts.js +28 -33
  47. package/dist/sdk/firmachain/common/aminotypes.d.ts +19 -0
  48. package/dist/sdk/firmachain/common/aminotypes.js +74 -0
  49. package/dist/sdk/firmachain/common/events.d.ts +32 -0
  50. package/dist/sdk/firmachain/common/events.js +18 -0
  51. package/dist/sdk/firmachain/common/fee.d.ts +26 -0
  52. package/dist/sdk/firmachain/common/fee.js +83 -0
  53. package/dist/sdk/firmachain/common/index.d.ts +1 -0
  54. package/dist/sdk/firmachain/common/index.js +3 -0
  55. package/dist/sdk/firmachain/common/modules/auth/queries.d.ts +15 -0
  56. package/dist/sdk/firmachain/common/modules/auth/queries.js +64 -0
  57. package/dist/sdk/firmachain/common/modules/authz/aminomessages.d.ts +2 -0
  58. package/dist/sdk/firmachain/common/modules/authz/aminomessages.js +15 -0
  59. package/dist/sdk/firmachain/common/modules/authz/messages.d.ts +2 -0
  60. package/dist/sdk/firmachain/common/modules/authz/messages.js +9 -0
  61. package/dist/sdk/firmachain/common/modules/authz/queries.d.ts +10 -0
  62. package/dist/sdk/firmachain/common/modules/authz/queries.js +88 -0
  63. package/dist/sdk/firmachain/common/modules/bank/aminomessages.d.ts +35 -0
  64. package/dist/sdk/firmachain/common/modules/bank/aminomessages.js +85 -0
  65. package/dist/sdk/firmachain/common/modules/bank/messages.d.ts +8 -0
  66. package/dist/sdk/firmachain/common/modules/bank/messages.js +12 -0
  67. package/dist/sdk/firmachain/common/modules/bank/queries.d.ts +15 -0
  68. package/dist/sdk/firmachain/common/modules/bank/queries.js +128 -0
  69. package/dist/sdk/firmachain/common/modules/crisis/aminomessages.d.ts +14 -0
  70. package/dist/sdk/firmachain/common/modules/crisis/aminomessages.js +11 -0
  71. package/dist/sdk/firmachain/common/modules/distribution/aminomessages.d.ts +44 -0
  72. package/dist/sdk/firmachain/common/modules/distribution/aminomessages.js +113 -0
  73. package/dist/sdk/firmachain/common/modules/distribution/messages.d.ts +8 -0
  74. package/dist/sdk/firmachain/common/modules/distribution/messages.js +15 -0
  75. package/dist/sdk/firmachain/common/modules/distribution/queries.d.ts +16 -0
  76. package/dist/sdk/firmachain/common/modules/distribution/queries.js +171 -0
  77. package/dist/sdk/firmachain/common/modules/evidence/aminomessages.d.ts +18 -0
  78. package/dist/sdk/firmachain/common/modules/evidence/aminomessages.js +11 -0
  79. package/dist/sdk/firmachain/common/modules/feegrant/aminomessages.d.ts +2 -0
  80. package/dist/sdk/firmachain/common/modules/feegrant/aminomessages.js +14 -0
  81. package/dist/sdk/firmachain/common/modules/feegrant/messages.d.ts +2 -0
  82. package/dist/sdk/firmachain/common/modules/feegrant/messages.js +8 -0
  83. package/dist/sdk/firmachain/common/modules/feegrant/queries.d.ts +9 -0
  84. package/dist/sdk/firmachain/common/modules/feegrant/queries.js +81 -0
  85. package/dist/sdk/firmachain/common/modules/gov/aminomessages.d.ts +79 -0
  86. package/dist/sdk/firmachain/common/modules/gov/aminomessages.js +152 -0
  87. package/dist/sdk/firmachain/common/modules/gov/messages.d.ts +29 -0
  88. package/dist/sdk/firmachain/common/modules/gov/messages.js +38 -0
  89. package/dist/sdk/firmachain/common/modules/gov/queries.d.ts +19 -0
  90. package/dist/sdk/firmachain/common/modules/gov/queries.js +160 -0
  91. package/dist/sdk/firmachain/common/modules/group/aminomessages.d.ts +2 -0
  92. package/dist/sdk/firmachain/common/modules/group/aminomessages.js +8 -0
  93. package/dist/sdk/firmachain/common/modules/group/messages.d.ts +2 -0
  94. package/dist/sdk/firmachain/common/modules/group/messages.js +28 -0
  95. package/dist/sdk/firmachain/common/modules/ibc/aminomessages.d.ts +38 -0
  96. package/dist/sdk/firmachain/common/modules/ibc/aminomessages.js +55 -0
  97. package/dist/sdk/firmachain/common/modules/ibc/messages.d.ts +8 -0
  98. package/dist/sdk/firmachain/common/modules/ibc/messages.js +32 -0
  99. package/dist/sdk/firmachain/common/modules/ibc/queries.d.ts +58 -0
  100. package/dist/sdk/firmachain/common/modules/ibc/queries.js +576 -0
  101. package/dist/sdk/firmachain/common/modules/index.d.ts +32 -0
  102. package/dist/sdk/firmachain/common/modules/index.js +101 -0
  103. package/dist/sdk/firmachain/common/modules/mint/queries.d.ts +21 -0
  104. package/dist/sdk/firmachain/common/modules/mint/queries.js +95 -0
  105. package/dist/sdk/firmachain/common/modules/slashing/aminomessages.d.ts +12 -0
  106. package/dist/sdk/firmachain/common/modules/slashing/aminomessages.js +11 -0
  107. package/dist/sdk/firmachain/common/modules/slashing/queries.d.ts +10 -0
  108. package/dist/sdk/firmachain/common/modules/slashing/queries.js +88 -0
  109. package/dist/sdk/firmachain/common/modules/staking/aminomessages.d.ts +112 -0
  110. package/dist/sdk/firmachain/common/modules/staking/aminomessages.js +234 -0
  111. package/dist/sdk/firmachain/common/modules/staking/messages.d.ts +33 -0
  112. package/dist/sdk/firmachain/common/modules/staking/messages.js +37 -0
  113. package/dist/sdk/firmachain/common/modules/staking/queries.d.ts +23 -0
  114. package/dist/sdk/firmachain/common/modules/staking/queries.js +242 -0
  115. package/dist/sdk/firmachain/common/modules/tx/queries.d.ts +11 -0
  116. package/dist/sdk/firmachain/common/modules/tx/queries.js +103 -0
  117. package/dist/sdk/firmachain/common/modules/vesting/aminomessages.d.ts +16 -0
  118. package/dist/sdk/firmachain/common/modules/vesting/aminomessages.js +56 -0
  119. package/dist/sdk/firmachain/common/modules/vesting/messages.d.ts +2 -0
  120. package/dist/sdk/firmachain/common/modules/vesting/messages.js +7 -0
  121. package/dist/sdk/firmachain/common/queryclient/index.d.ts +2 -0
  122. package/dist/sdk/firmachain/common/queryclient/index.js +10 -0
  123. package/dist/sdk/firmachain/common/queryclient/queryclient.d.ts +75 -0
  124. package/dist/sdk/firmachain/common/queryclient/queryclient.js +157 -0
  125. package/dist/sdk/firmachain/common/queryclient/utils.d.ts +33 -0
  126. package/dist/sdk/firmachain/common/queryclient/utils.js +101 -0
  127. package/dist/sdk/firmachain/common/search.d.ts +10 -0
  128. package/dist/sdk/firmachain/common/search.js +7 -0
  129. package/dist/sdk/firmachain/common/signing.d.ts +8 -3
  130. package/dist/sdk/firmachain/common/signing.js +24 -12
  131. package/dist/sdk/firmachain/common/signingstargateclient.d.ts +107 -30
  132. package/dist/sdk/firmachain/common/signingstargateclient.js +445 -128
  133. package/dist/sdk/firmachain/common/stargateclient.d.ts +184 -20
  134. package/dist/sdk/firmachain/common/stargateclient.js +351 -35
  135. package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +2 -2
  136. package/dist/sdk/firmachain/contract/ContractTxClient.js +4 -4
  137. package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +1 -1
  138. package/dist/sdk/firmachain/contract/ContractTxTypes.js +3 -3
  139. package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.js +1 -1
  140. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +5 -5
  141. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +10 -8
  142. package/dist/sdk/firmachain/google/protobuf/any.d.ts +3 -2
  143. package/dist/sdk/firmachain/google/protobuf/any.js +2 -1
  144. package/dist/sdk/firmachain/google/protobuf/duration.d.ts +3 -2
  145. package/dist/sdk/firmachain/google/protobuf/duration.js +2 -1
  146. package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +3 -2
  147. package/dist/sdk/firmachain/google/protobuf/timestamp.js +2 -1
  148. package/dist/sdk/firmachain/gov/GovTxClient.d.ts +6 -0
  149. package/dist/sdk/firmachain/gov/GovTxClient.js +6 -1
  150. package/dist/sdk/firmachain/nft/NftTxClient.d.ts +3 -3
  151. package/dist/sdk/firmachain/nft/NftTxClient.js +6 -6
  152. package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +1 -1
  153. package/dist/sdk/firmachain/nft/NftTxTypes.js +4 -4
  154. package/dist/sdk/firmachain/staking/StakingQueryClient.js +0 -1
  155. package/dist/sdk/firmachain/token/TokenTxClient.d.ts +4 -4
  156. package/dist/sdk/firmachain/token/TokenTxClient.js +8 -8
  157. package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +1 -1
  158. package/dist/sdk/firmachain/token/TokenTxTypes.js +5 -5
  159. package/dist/test/00.wallet.test.d.ts +1 -0
  160. package/dist/test/00.wallet.test.js +96 -0
  161. package/dist/test/01.contract_tx.test.d.ts +1 -0
  162. package/dist/test/01.contract_tx.test.js +157 -0
  163. package/dist/test/02.contract_query.test.d.ts +1 -0
  164. package/dist/test/02.contract_query.test.js +245 -0
  165. package/dist/test/03.contract_scenario.test.d.ts +1 -0
  166. package/dist/test/03.contract_scenario.test.js +406 -0
  167. package/dist/test/04.bank_tx.test.d.ts +1 -0
  168. package/dist/test/04.bank_tx.test.js +126 -0
  169. package/dist/test/05.bank_query.test.d.ts +1 -0
  170. package/dist/test/05.bank_query.test.js +162 -0
  171. package/dist/test/06.feegrant_tx.test.d.ts +1 -0
  172. package/dist/test/06.feegrant_tx.test.js +161 -0
  173. package/dist/test/07.feegrant_query.test.d.ts +1 -0
  174. package/dist/test/07.feegrant_query.test.js +126 -0
  175. package/dist/test/08.gas_estimate.test.d.ts +1 -0
  176. package/dist/test/08.gas_estimate.test.js +675 -0
  177. package/dist/test/09.ipfs.test.d.ts +1 -0
  178. package/dist/test/09.ipfs.test.js +72 -0
  179. package/dist/test/10.nft_tx.test.d.ts +1 -0
  180. package/dist/test/10.nft_tx.test.js +209 -0
  181. package/dist/test/11.nft_query.test.d.ts +1 -0
  182. package/dist/test/11.nft_query.test.js +165 -0
  183. package/dist/test/12.staking_tx.test.d.ts +1 -0
  184. package/dist/test/12.staking_tx.test.js +199 -0
  185. package/dist/test/13.staking_query.test.d.ts +1 -0
  186. package/dist/test/13.staking_query.test.js +263 -0
  187. package/dist/test/14.distribution_tx.test.d.ts +1 -0
  188. package/dist/test/14.distribution_tx.test.js +170 -0
  189. package/dist/test/15.distribution_query.test.d.ts +1 -0
  190. package/dist/test/15.distribution_query.test.js +243 -0
  191. package/dist/test/16.gov_tx.test.d.ts +1 -0
  192. package/dist/test/16.gov_tx.test.js +311 -0
  193. package/dist/test/17.gov_query.test.d.ts +1 -0
  194. package/dist/test/17.gov_query.test.js +157 -0
  195. package/dist/test/18.util.test.d.ts +1 -0
  196. package/dist/test/18.util.test.js +251 -0
  197. package/dist/test/19.chain.test.d.ts +1 -0
  198. package/dist/test/19.chain.test.js +127 -0
  199. package/dist/test/20.slashing_query.test.d.ts +1 -0
  200. package/dist/test/20.slashing_query.test.js +112 -0
  201. package/dist/test/21.token_tx.test.d.ts +1 -0
  202. package/dist/test/21.token_tx.test.js +149 -0
  203. package/dist/test/22.token_query.test.d.ts +1 -0
  204. package/dist/test/22.token_query.test.js +103 -0
  205. package/dist/test/23.authz_tx.test.d.ts +1 -0
  206. package/dist/test/23.authz_tx.test.js +350 -0
  207. package/dist/test/24.authz_query.test.d.ts +1 -0
  208. package/dist/test/24.authz_query.test.js +203 -0
  209. package/dist/test/25.cosmwasm_tx.test.d.ts +1 -0
  210. package/dist/test/25.cosmwasm_tx.test.js +229 -0
  211. package/dist/test/26.cosmwasm_query.test.d.ts +1 -0
  212. package/dist/test/26.cosmwasm_query.test.js +209 -0
  213. package/dist/test/27.arbitary_sign.test.d.ts +1 -0
  214. package/dist/test/27.arbitary_sign.test.js +159 -0
  215. package/dist/test/28.ibc_tx.test.d.ts +1 -0
  216. package/dist/test/28.ibc_tx.test.js +98 -0
  217. package/dist/test/29.mint_query.test.d.ts +1 -0
  218. package/dist/test/29.mint_query.test.js +59 -0
  219. package/dist/test/30.cw20_tx.test.d.ts +1 -0
  220. package/dist/test/30.cw20_tx.test.js +450 -0
  221. package/dist/test/31.cw20_query.test.d.ts +1 -0
  222. package/dist/test/31.cw20_query.test.js +333 -0
  223. package/dist/test/32.cw721_tx.test.d.ts +1 -0
  224. package/dist/test/32.cw721_tx.test.js +431 -0
  225. package/dist/test/33.cw721_query.test.d.ts +1 -0
  226. package/dist/test/33.cw721_query.test.js +371 -0
  227. package/dist/test/34.cw_bridge_tx.test.d.ts +1 -0
  228. package/dist/test/34.cw_bridge_tx.test.js +476 -0
  229. package/dist/test/35.cw_bridge_tx_low.test.d.ts +1 -0
  230. package/dist/test/35.cw_bridge_tx_low.test.js +398 -0
  231. package/dist/test/36.cw_bridge_query.test.d.ts +1 -0
  232. package/dist/test/36.cw_bridge_query.test.js +318 -0
  233. package/dist/test/37.cw_marketplace_tx.test.d.ts +1 -0
  234. package/dist/test/37.cw_marketplace_tx.test.js +794 -0
  235. package/dist/test/38.cw_marketplace_query.test.d.ts +1 -0
  236. package/dist/test/38.cw_marketplace_query.test.js +128 -0
  237. package/dist/test/config_test.d.ts +11 -0
  238. package/dist/test/config_test.js +29 -0
  239. package/dist/test/config_test.sample.d.ts +5 -0
  240. package/dist/test/config_test.sample.js +8 -0
  241. package/package.json +9 -7
  242. package/dist/sdk/firmachain/common/signingaminostargateclient.d.ts +0 -50
  243. package/dist/sdk/firmachain/common/signingaminostargateclient.js +0 -267
@@ -14,6 +14,17 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
17
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -75,78 +86,316 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
75
86
  return (mod && mod.__esModule) ? mod : { "default": mod };
76
87
  };
77
88
  Object.defineProperty(exports, "__esModule", { value: true });
78
- exports.SigningStargateClient = void 0;
89
+ exports.SigningStargateClient = exports.isMsgSignData = exports.createDefaultAminoConverters = exports.defaultRegistryTypes = void 0;
90
+ var amino_1 = require("@cosmjs/amino");
91
+ var crypto_1 = require("@cosmjs/crypto");
79
92
  var encoding_1 = require("@cosmjs/encoding");
80
- var encoding_2 = require("@cosmjs/encoding");
93
+ var math_1 = require("@cosmjs/math");
81
94
  var proto_signing_1 = require("@cosmjs/proto-signing");
82
95
  var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
96
+ var utils_1 = require("@cosmjs/utils");
97
+ var coin_1 = require("cosmjs-types/cosmos/base/v1beta1/coin");
98
+ var tx_1 = require("cosmjs-types/cosmos/distribution/v1beta1/tx");
99
+ var tx_2 = require("cosmjs-types/cosmos/staking/v1beta1/tx");
83
100
  var signing_1 = require("cosmjs-types/cosmos/tx/signing/v1beta1/signing");
84
- var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
85
- var accounts_1 = require("./accounts");
101
+ var tx_3 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
102
+ var tx_4 = require("cosmjs-types/ibc/applications/transfer/v1/tx");
103
+ var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
104
+ var aminotypes_1 = require("./aminotypes");
105
+ var fee_1 = require("./fee");
106
+ var modules_1 = require("./modules");
107
+ var modules_2 = require("./modules");
86
108
  var stargateclient_1 = require("./stargateclient");
87
- var axios_1 = __importDefault(require("axios"));
88
- var math_1 = require("@cosmjs/math");
89
- var any_1 = require("../google/protobuf/any");
90
- var long_1 = __importDefault(require("long"));
91
- var encoding_3 = require("../amino/encoding");
109
+ var FirmaUtil_1 = require("../../FirmaUtil");
110
+ exports.defaultRegistryTypes = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([
111
+ ["/cosmos.base.v1beta1.Coin", coin_1.Coin]
112
+ ], __read(modules_1.authzTypes)), __read(modules_1.bankTypes)), __read(modules_1.distributionTypes)), __read(modules_1.feegrantTypes)), __read(modules_1.govTypes)), __read(modules_1.groupTypes)), __read(modules_1.stakingTypes)), __read(modules_1.ibcTypes)), __read(modules_1.vestingTypes));
113
+ function createDefaultAminoConverters() {
114
+ return __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, modules_2.createAuthzAminoConverters()), modules_2.createBankAminoConverters()), modules_2.createDistributionAminoConverters()), modules_2.createGovAminoConverters()), modules_2.createStakingAminoConverters()), modules_2.createIbcAminoConverters()), modules_2.createFeegrantAminoConverters()), modules_2.createVestingAminoConverters());
115
+ }
116
+ exports.createDefaultAminoConverters = createDefaultAminoConverters;
117
+ function isMsgSignData(msg) {
118
+ var castedMsg = msg;
119
+ if (castedMsg.type !== "sign/MsgSignData")
120
+ return false;
121
+ if (!utils_1.isNonNullObject(castedMsg.value))
122
+ return false;
123
+ if (typeof castedMsg.value.signer !== "string")
124
+ return false;
125
+ if (typeof castedMsg.value.data !== "string")
126
+ return false;
127
+ return true;
128
+ }
129
+ exports.isMsgSignData = isMsgSignData;
92
130
  var SigningStargateClient = /** @class */ (function (_super) {
93
131
  __extends(SigningStargateClient, _super);
94
- function SigningStargateClient(tmClient, signer, registry) {
95
- var _this = _super.call(this, tmClient) || this;
132
+ function SigningStargateClient(cometClient, signer, options) {
133
+ var _this = _super.call(this, cometClient, options) || this;
134
+ // Starting with Cosmos SDK 0.47, we see many cases in which 1.3 is not enough anymore
135
+ // E.g. https://github.com/cosmos/cosmos-sdk/issues/16020
136
+ _this.defaultGasMultiplier = 1.4;
137
+ var _a = options.registry, registry = _a === void 0 ? new proto_signing_1.Registry(exports.defaultRegistryTypes) : _a, _b = options.aminoTypes, aminoTypes = _b === void 0 ? new aminotypes_1.AminoTypes(createDefaultAminoConverters()) : _b;
96
138
  _this.registry = registry;
139
+ _this.aminoTypes = aminoTypes;
97
140
  _this.signer = signer;
141
+ _this.broadcastTimeoutMs = options.broadcastTimeoutMs;
142
+ _this.broadcastPollIntervalMs = options.broadcastPollIntervalMs;
143
+ _this.gasPrice = options.gasPrice;
98
144
  return _this;
99
145
  }
100
- SigningStargateClient.prototype.getSigner = function () {
101
- return this.signer;
146
+ /**
147
+ * Creates an instance by connecting to the given CometBFT RPC endpoint.
148
+ *
149
+ * This uses auto-detection to decide between a CometBFT 0.38, Tendermint 0.37 and 0.34 client.
150
+ * To set the Comet client explicitly, use `createWithSigner`.
151
+ */
152
+ SigningStargateClient.connectWithSigner = function (endpoint, signer, options) {
153
+ if (options === void 0) { options = {}; }
154
+ return __awaiter(this, void 0, void 0, function () {
155
+ var cometClient;
156
+ return __generator(this, function (_a) {
157
+ switch (_a.label) {
158
+ case 0: return [4 /*yield*/, tendermint_rpc_1.connectComet(endpoint)];
159
+ case 1:
160
+ cometClient = _a.sent();
161
+ return [2 /*return*/, SigningStargateClient.createWithSigner(cometClient, signer, options)];
162
+ }
163
+ });
164
+ });
165
+ };
166
+ /**
167
+ * Creates an instance from a manually created Comet client.
168
+ * Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`.
169
+ */
170
+ SigningStargateClient.createWithSigner = function (cometClient, signer, options) {
171
+ if (options === void 0) { options = {}; }
172
+ return __awaiter(this, void 0, void 0, function () {
173
+ return __generator(this, function (_a) {
174
+ return [2 /*return*/, new SigningStargateClient(cometClient, signer, options)];
175
+ });
176
+ });
177
+ };
178
+ /**
179
+ * Creates a client in offline mode.
180
+ *
181
+ * This should only be used in niche cases where you know exactly what you're doing,
182
+ * e.g. when building an offline signing application.
183
+ *
184
+ * When you try to use online functionality with such a signer, an
185
+ * exception will be raised.
186
+ */
187
+ SigningStargateClient.offline = function (signer, options) {
188
+ if (options === void 0) { options = {}; }
189
+ return __awaiter(this, void 0, void 0, function () {
190
+ return __generator(this, function (_a) {
191
+ return [2 /*return*/, new SigningStargateClient(undefined, signer, options)];
192
+ });
193
+ });
194
+ };
195
+ SigningStargateClient.prototype.simulate = function (signerAddress, messages, memo) {
196
+ return __awaiter(this, void 0, void 0, function () {
197
+ var anyMsgs, accountFromSigner, pubkey, sequence, gasInfo;
198
+ var _this = this;
199
+ return __generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0:
202
+ anyMsgs = messages.map(function (m) { return _this.registry.encodeAsAny(m); });
203
+ return [4 /*yield*/, this.signer.getAccounts()];
204
+ case 1:
205
+ accountFromSigner = (_a.sent()).find(function (account) { return account.address === signerAddress; });
206
+ if (!accountFromSigner) {
207
+ throw new Error("Failed to retrieve account from signer");
208
+ }
209
+ pubkey = amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey);
210
+ return [4 /*yield*/, this.getSequence(signerAddress)];
211
+ case 2:
212
+ sequence = (_a.sent()).sequence;
213
+ return [4 /*yield*/, this.forceGetQueryClient().tx.simulate(anyMsgs, memo, pubkey, sequence)];
214
+ case 3:
215
+ gasInfo = (_a.sent()).gasInfo;
216
+ utils_1.assertDefined(gasInfo);
217
+ return [2 /*return*/, math_1.Uint53.fromString(gasInfo.gasUsed.toString()).toNumber()];
218
+ }
219
+ });
220
+ });
221
+ };
222
+ SigningStargateClient.prototype.sendTokens = function (senderAddress, recipientAddress, amount, fee, memo) {
223
+ if (memo === void 0) { memo = ""; }
224
+ return __awaiter(this, void 0, void 0, function () {
225
+ var sendMsg;
226
+ return __generator(this, function (_a) {
227
+ sendMsg = {
228
+ typeUrl: "/cosmos.bank.v1beta1.MsgSend",
229
+ value: {
230
+ fromAddress: senderAddress,
231
+ toAddress: recipientAddress,
232
+ amount: __spreadArray([], __read(amount)),
233
+ },
234
+ };
235
+ return [2 /*return*/, this.signAndBroadcast(senderAddress, [sendMsg], fee, memo)];
236
+ });
237
+ });
238
+ };
239
+ SigningStargateClient.prototype.delegateTokens = function (delegatorAddress, validatorAddress, amount, fee, memo) {
240
+ if (memo === void 0) { memo = ""; }
241
+ return __awaiter(this, void 0, void 0, function () {
242
+ var delegateMsg;
243
+ return __generator(this, function (_a) {
244
+ delegateMsg = {
245
+ typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
246
+ value: tx_2.MsgDelegate.fromPartial({
247
+ delegatorAddress: delegatorAddress,
248
+ validatorAddress: validatorAddress,
249
+ amount: amount,
250
+ }),
251
+ };
252
+ return [2 /*return*/, this.signAndBroadcast(delegatorAddress, [delegateMsg], fee, memo)];
253
+ });
254
+ });
255
+ };
256
+ SigningStargateClient.prototype.undelegateTokens = function (delegatorAddress, validatorAddress, amount, fee, memo) {
257
+ if (memo === void 0) { memo = ""; }
258
+ return __awaiter(this, void 0, void 0, function () {
259
+ var undelegateMsg;
260
+ return __generator(this, function (_a) {
261
+ undelegateMsg = {
262
+ typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate",
263
+ value: tx_2.MsgUndelegate.fromPartial({
264
+ delegatorAddress: delegatorAddress,
265
+ validatorAddress: validatorAddress,
266
+ amount: amount,
267
+ }),
268
+ };
269
+ return [2 /*return*/, this.signAndBroadcast(delegatorAddress, [undelegateMsg], fee, memo)];
270
+ });
271
+ });
272
+ };
273
+ SigningStargateClient.prototype.withdrawRewards = function (delegatorAddress, validatorAddress, fee, memo) {
274
+ if (memo === void 0) { memo = ""; }
275
+ return __awaiter(this, void 0, void 0, function () {
276
+ var withdrawMsg;
277
+ return __generator(this, function (_a) {
278
+ withdrawMsg = {
279
+ typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
280
+ value: tx_1.MsgWithdrawDelegatorReward.fromPartial({
281
+ delegatorAddress: delegatorAddress,
282
+ validatorAddress: validatorAddress,
283
+ }),
284
+ };
285
+ return [2 /*return*/, this.signAndBroadcast(delegatorAddress, [withdrawMsg], fee, memo)];
286
+ });
287
+ });
288
+ };
289
+ /**
290
+ * @deprecated This API does not support setting the memo field of `MsgTransfer` (only the transaction memo).
291
+ * We'll remove this method at some point because trying to wrap the various message types is a losing strategy.
292
+ * Please migrate to `signAndBroadcast` with an `MsgTransferEncodeObject` created in the caller code instead.
293
+ * @see https://github.com/cosmos/cosmjs/issues/1493
294
+ */
295
+ SigningStargateClient.prototype.sendIbcTokens = function (senderAddress, recipientAddress, transferAmount, sourcePort, sourceChannel, timeoutHeight,
296
+ /** timeout in seconds */
297
+ timeoutTimestamp, fee, memo) {
298
+ if (memo === void 0) { memo = ""; }
299
+ return __awaiter(this, void 0, void 0, function () {
300
+ var timeoutTimestampNanoseconds, transferMsg;
301
+ return __generator(this, function (_a) {
302
+ timeoutTimestampNanoseconds = timeoutTimestamp
303
+ ? BigInt(timeoutTimestamp) * BigInt(1000000000)
304
+ : undefined;
305
+ transferMsg = {
306
+ typeUrl: "/ibc.applications.transfer.v1.MsgTransfer",
307
+ value: tx_4.MsgTransfer.fromPartial({
308
+ sourcePort: sourcePort,
309
+ sourceChannel: sourceChannel,
310
+ sender: senderAddress,
311
+ receiver: recipientAddress,
312
+ token: transferAmount,
313
+ timeoutHeight: timeoutHeight,
314
+ timeoutTimestamp: timeoutTimestampNanoseconds,
315
+ }),
316
+ };
317
+ return [2 /*return*/, this.signAndBroadcast(senderAddress, [transferMsg], fee, memo)];
318
+ });
319
+ });
102
320
  };
103
- SigningStargateClient.connectWithSigner = function (endpoint, signer, registry) {
321
+ SigningStargateClient.prototype.signAndBroadcast = function (signerAddress, messages, fee, memo, timeoutHeight) {
322
+ if (memo === void 0) { memo = ""; }
104
323
  return __awaiter(this, void 0, void 0, function () {
105
- var tmClient;
324
+ var usedFee, gasEstimation, multiplier, txRaw, txBytes;
106
325
  return __generator(this, function (_a) {
107
326
  switch (_a.label) {
108
327
  case 0:
109
- this._endpoint = endpoint;
110
- return [4 /*yield*/, tendermint_rpc_1.Tendermint34Client.connect(endpoint)];
328
+ if (!(fee == "auto" || typeof fee === "number")) return [3 /*break*/, 2];
329
+ utils_1.assertDefined(this.gasPrice, "Gas price must be set in the client options when auto gas is used.");
330
+ return [4 /*yield*/, this.simulate(signerAddress, messages, memo)];
111
331
  case 1:
112
- tmClient = _a.sent();
113
- return [2 /*return*/, new SigningStargateClient(tmClient, signer, registry)];
332
+ gasEstimation = _a.sent();
333
+ multiplier = typeof fee === "number" ? fee : this.defaultGasMultiplier;
334
+ usedFee = fee_1.calculateFee(Math.round(gasEstimation * multiplier), this.gasPrice);
335
+ return [3 /*break*/, 3];
336
+ case 2:
337
+ usedFee = fee;
338
+ _a.label = 3;
339
+ case 3: return [4 /*yield*/, this.sign(signerAddress, messages, usedFee, memo, undefined, timeoutHeight)];
340
+ case 4:
341
+ txRaw = _a.sent();
342
+ txBytes = tx_3.TxRaw.encode(txRaw).finish();
343
+ return [2 /*return*/, this.broadcastTx(txBytes, this.broadcastTimeoutMs, this.broadcastPollIntervalMs)];
114
344
  }
115
345
  });
116
346
  });
117
347
  };
118
- SigningStargateClient.prototype.signAndBroadcast = function (signerAddress, messages, fee, memo) {
348
+ /**
349
+ * This method is useful if you want to send a transaction in broadcast,
350
+ * without waiting for it to be placed inside a block, because for example
351
+ * I would like to receive the hash to later track the transaction with another tool.
352
+ * @returns Returns the hash of the transaction
353
+ */
354
+ SigningStargateClient.prototype.signAndBroadcastSync = function (signerAddress, messages, fee, memo, timeoutHeight) {
119
355
  if (memo === void 0) { memo = ""; }
120
356
  return __awaiter(this, void 0, void 0, function () {
121
- var txRaw, txBytes;
357
+ var usedFee, gasEstimation, multiplier, txRaw, txBytes;
122
358
  return __generator(this, function (_a) {
123
359
  switch (_a.label) {
124
- case 0: return [4 /*yield*/, this.sign(signerAddress, messages, fee, memo)];
360
+ case 0:
361
+ if (!(fee == "auto" || typeof fee === "number")) return [3 /*break*/, 2];
362
+ utils_1.assertDefined(this.gasPrice, "Gas price must be set in the client options when auto gas is used.");
363
+ return [4 /*yield*/, this.simulate(signerAddress, messages, memo)];
125
364
  case 1:
365
+ gasEstimation = _a.sent();
366
+ multiplier = typeof fee === "number" ? fee : this.defaultGasMultiplier;
367
+ usedFee = fee_1.calculateFee(Math.round(gasEstimation * multiplier), this.gasPrice);
368
+ return [3 /*break*/, 3];
369
+ case 2:
370
+ usedFee = fee;
371
+ _a.label = 3;
372
+ case 3: return [4 /*yield*/, this.sign(signerAddress, messages, usedFee, memo, undefined, timeoutHeight)];
373
+ case 4:
126
374
  txRaw = _a.sent();
127
- txBytes = tx_1.TxRaw.encode(txRaw).finish();
128
- return [2 /*return*/, this.broadcastTx(txBytes)];
375
+ txBytes = tx_3.TxRaw.encode(txRaw).finish();
376
+ return [2 /*return*/, this.broadcastTxSync(txBytes)];
129
377
  }
130
378
  });
131
379
  });
132
380
  };
133
381
  SigningStargateClient.makeSignDocForSend = function (signerAddress, pubkeyStr, messages, fee, memo, serverUrl, chainId, registry) {
134
382
  return __awaiter(this, void 0, void 0, function () {
135
- var _a, accountNumber, sequence, account, rawSecp256k1Pubkey, pubkey, txBodyEncodeObject, txBodyBytes, gasLimit, authInfoBytes;
383
+ var client, _a, accountNumber, sequence, account, rawSecp256k1Pubkey, pubkey, txBodyEncodeObject, txBodyBytes, gasLimit, feePayer, authInfoBytes;
136
384
  return __generator(this, function (_b) {
137
385
  switch (_b.label) {
138
- case 0:
139
- SigningStargateClient._endpoint = serverUrl;
140
- return [4 /*yield*/, SigningStargateClient.getSequence(signerAddress)];
386
+ case 0: return [4 /*yield*/, SigningStargateClient.connect(serverUrl)];
141
387
  case 1:
142
- _a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
143
- return [4 /*yield*/, SigningStargateClient.getAccount(signerAddress)];
388
+ client = _b.sent();
389
+ return [4 /*yield*/, client.getSequence(signerAddress)];
144
390
  case 2:
391
+ _a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
392
+ return [4 /*yield*/, client.getAccount(signerAddress)];
393
+ case 3:
145
394
  account = _b.sent();
146
395
  if (account == null)
147
396
  throw new Error("Failed to retrieve account from signer");
148
397
  rawSecp256k1Pubkey = encoding_1.fromBase64(pubkeyStr);
149
- pubkey = proto_signing_1.encodePubkey(encoding_3.encodeSecp256k1Pubkey(rawSecp256k1Pubkey));
398
+ pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(rawSecp256k1Pubkey));
150
399
  txBodyEncodeObject = {
151
400
  typeUrl: "/cosmos.tx.v1beta1.TxBody",
152
401
  value: {
@@ -156,13 +405,24 @@ var SigningStargateClient = /** @class */ (function (_super) {
156
405
  };
157
406
  txBodyBytes = registry.encode(txBodyEncodeObject);
158
407
  gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
159
- authInfoBytes = this.makeAuthInfoBytes([{ pubkey: pubkey, sequence: sequence }], fee.amount, gasLimit, fee.granter);
408
+ feePayer = signerAddress;
409
+ authInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey: pubkey, sequence: sequence }], fee.amount, gasLimit, fee.granter, feePayer);
160
410
  return [2 /*return*/, proto_signing_1.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber)];
161
411
  }
162
412
  });
163
413
  });
164
414
  };
165
- SigningStargateClient.prototype.sign = function (signerAddress, messages, fee, memo, explicitSignerData) {
415
+ /**
416
+ * Gets account number and sequence from the API, creates a sign doc,
417
+ * creates a single signature and assembles the signed transaction.
418
+ *
419
+ * The sign mode (SIGN_MODE_DIRECT or SIGN_MODE_LEGACY_AMINO_JSON) is determined by this client's signer.
420
+ *
421
+ * You can pass signer data (account number, sequence and chain ID) explicitly instead of querying them
422
+ * from the chain. This is needed when signing for a multisig account, but it also allows for offline signing
423
+ * (See the SigningStargateClient.offline constructor).
424
+ */
425
+ SigningStargateClient.prototype.sign = function (signerAddress, messages, fee, memo, explicitSignerData, timeoutHeight) {
166
426
  return __awaiter(this, void 0, void 0, function () {
167
427
  var signerData, _a, accountNumber, sequence, chainId;
168
428
  return __generator(this, function (_b) {
@@ -171,7 +431,7 @@ var SigningStargateClient = /** @class */ (function (_super) {
171
431
  if (!explicitSignerData) return [3 /*break*/, 1];
172
432
  signerData = explicitSignerData;
173
433
  return [3 /*break*/, 4];
174
- case 1: return [4 /*yield*/, SigningStargateClient.getSequence(signerAddress)];
434
+ case 1: return [4 /*yield*/, this.getSequence(signerAddress)];
175
435
  case 2:
176
436
  _a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
177
437
  return [4 /*yield*/, this.getChainId()];
@@ -183,7 +443,9 @@ var SigningStargateClient = /** @class */ (function (_super) {
183
443
  chainId: chainId,
184
444
  };
185
445
  _b.label = 4;
186
- case 4: return [2 /*return*/, this.signDirect(signerAddress, messages, fee, memo, signerData)];
446
+ case 4: return [2 /*return*/, proto_signing_1.isOfflineDirectSigner(this.signer)
447
+ ? this.signDirect(signerAddress, messages, fee, memo, signerData, timeoutHeight)
448
+ : this.signAmino(signerAddress, messages, fee, memo, signerData, timeoutHeight)];
187
449
  }
188
450
  });
189
451
  });
@@ -195,7 +457,7 @@ var SigningStargateClient = /** @class */ (function (_super) {
195
457
  switch (_a.label) {
196
458
  case 0:
197
459
  if (!!this.chainId) return [3 /*break*/, 2];
198
- return [4 /*yield*/, this.forceGetTmClient().status()];
460
+ return [4 /*yield*/, this.forceGetCometClient().status()];
199
461
  case 1:
200
462
  response = _a.sent();
201
463
  chainId = response.nodeInfo.network;
@@ -208,117 +470,81 @@ var SigningStargateClient = /** @class */ (function (_super) {
208
470
  });
209
471
  });
210
472
  };
211
- /**
212
- * Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded.
213
- * This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data.
214
- * The result is typically 20 bytes long but not restricted to that.
215
- */
216
- SigningStargateClient.toAccAddress = function (address) {
217
- return encoding_2.Bech32.decode(address).data;
218
- };
219
- SigningStargateClient.getAccount = function (address) {
473
+ SigningStargateClient.prototype.signAmino = function (signerAddress, messages, fee, memo, _a, timeoutHeight) {
474
+ var accountNumber = _a.accountNumber, sequence = _a.sequence, chainId = _a.chainId;
220
475
  return __awaiter(this, void 0, void 0, function () {
221
- var accAddress, hexAccAddress, axios, path, result, finalData, account, finalAccount, error_1;
222
- return __generator(this, function (_a) {
223
- switch (_a.label) {
476
+ var accountFromSigner, pubkey, signMode, msgs, signDoc, _b, signature, signed, signedTxBody, signedTxBodyEncodeObject, signedTxBodyBytes, signedGasLimit, signedSequence, signedAuthInfoBytes;
477
+ var _this = this;
478
+ return __generator(this, function (_c) {
479
+ switch (_c.label) {
224
480
  case 0:
225
- _a.trys.push([0, 2, , 3]);
226
- accAddress = this.toAccAddress(address);
227
- hexAccAddress = "0x01" + Buffer.from(accAddress).toString("hex");
228
- axios = axios_1.default.create({
229
- baseURL: SigningStargateClient._endpoint,
230
- headers: {
231
- Accept: "application/json",
232
- },
233
- timeout: 15000
234
- });
235
- path = "/abci_query?path=\"/store/acc/key\"";
236
- return [4 /*yield*/, axios.get(path, { params: { data: hexAccAddress } })];
481
+ utils_1.assert(!proto_signing_1.isOfflineDirectSigner(this.signer));
482
+ return [4 /*yield*/, this.signer.getAccounts()];
237
483
  case 1:
238
- result = _a.sent();
239
- finalData = result.data.result.response.value;
240
- account = any_1.Any.decode(Buffer.from(finalData, "base64"));
241
- finalAccount = accounts_1.accountFromAny(account);
242
- return [2 /*return*/, finalAccount];
243
- case 2:
244
- error_1 = _a.sent();
245
- return [2 /*return*/, undefined];
246
- case 3: return [2 /*return*/];
247
- }
248
- });
249
- });
250
- };
251
- SigningStargateClient.getSequence = function (address) {
252
- return __awaiter(this, void 0, void 0, function () {
253
- var account;
254
- return __generator(this, function (_a) {
255
- switch (_a.label) {
256
- case 0: return [4 /*yield*/, this.getAccount(address)];
257
- case 1:
258
- account = _a.sent();
259
- if (!account) {
260
- throw new Error("Account does not exist on chain. Send some tokens there before trying to query sequence.");
484
+ accountFromSigner = (_c.sent()).find(function (account) { return account.address === signerAddress; });
485
+ if (!accountFromSigner) {
486
+ throw new Error("Failed to retrieve account from signer");
261
487
  }
262
- return [2 /*return*/, {
263
- accountNumber: account.accountNumber,
264
- sequence: account.sequence,
265
- }];
488
+ pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
489
+ signMode = signing_1.SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
490
+ msgs = messages.map(function (msg) { return _this.aminoTypes.toAmino(msg); });
491
+ signDoc = amino_1.makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence, timeoutHeight);
492
+ return [4 /*yield*/, this.signer.signAmino(signerAddress, signDoc)];
493
+ case 2:
494
+ _b = _c.sent(), signature = _b.signature, signed = _b.signed;
495
+ signedTxBody = {
496
+ messages: signed.msgs.map(function (msg) { return _this.aminoTypes.fromAmino(msg); }),
497
+ memo: signed.memo,
498
+ timeoutHeight: timeoutHeight,
499
+ };
500
+ signedTxBodyEncodeObject = {
501
+ typeUrl: "/cosmos.tx.v1beta1.TxBody",
502
+ value: signedTxBody,
503
+ };
504
+ signedTxBodyBytes = this.registry.encode(signedTxBodyEncodeObject);
505
+ signedGasLimit = math_1.Int53.fromString(signed.fee.gas).toNumber();
506
+ signedSequence = math_1.Int53.fromString(signed.sequence).toNumber();
507
+ signedAuthInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey: pubkey, sequence: signedSequence }], signed.fee.amount, signedGasLimit, signed.fee.granter, signed.fee.payer, signMode);
508
+ return [2 /*return*/, tx_3.TxRaw.fromPartial({
509
+ bodyBytes: signedTxBodyBytes,
510
+ authInfoBytes: signedAuthInfoBytes,
511
+ signatures: [encoding_1.fromBase64(signature.signature)],
512
+ })];
266
513
  }
267
514
  });
268
515
  });
269
516
  };
270
- SigningStargateClient.makeSignerInfos = function (signers, signMode) {
271
- return signers.map(function (_a) {
272
- var pubkey = _a.pubkey, sequence = _a.sequence;
273
- return ({
274
- publicKey: pubkey,
275
- modeInfo: {
276
- single: { mode: signMode },
277
- },
278
- sequence: long_1.default.fromNumber(sequence),
279
- });
280
- });
281
- };
282
- SigningStargateClient.makeAuthInfoBytes = function (signers, feeAmount, gasLimit, granter, signMode) {
283
- if (signMode === void 0) { signMode = signing_1.SignMode.SIGN_MODE_DIRECT; }
284
- var authInfo = {
285
- signerInfos: this.makeSignerInfos(signers, signMode),
286
- fee: {
287
- amount: __spreadArray([], __read(feeAmount)),
288
- gasLimit: long_1.default.fromNumber(gasLimit),
289
- granter: granter,
290
- },
291
- };
292
- return tx_1.AuthInfo.encode(tx_1.AuthInfo.fromPartial(authInfo)).finish();
293
- };
294
- SigningStargateClient.prototype.signDirect = function (signerAddress, messages, fee, memo, _a) {
517
+ SigningStargateClient.prototype.signDirect = function (signerAddress, messages, fee, memo, _a, timeoutHeight) {
295
518
  var accountNumber = _a.accountNumber, sequence = _a.sequence, chainId = _a.chainId;
296
519
  return __awaiter(this, void 0, void 0, function () {
297
520
  var accountFromSigner, pubkey, txBodyEncodeObject, txBodyBytes, gasLimit, authInfoBytes, signDoc, _b, signature, signed;
298
521
  return __generator(this, function (_c) {
299
522
  switch (_c.label) {
300
- case 0: return [4 /*yield*/, this.getSigner().getAccounts()];
523
+ case 0:
524
+ utils_1.assert(proto_signing_1.isOfflineDirectSigner(this.signer));
525
+ return [4 /*yield*/, this.signer.getAccounts()];
301
526
  case 1:
302
527
  accountFromSigner = (_c.sent()).find(function (account) { return account.address === signerAddress; });
303
528
  if (!accountFromSigner) {
304
529
  throw new Error("Failed to retrieve account from signer");
305
530
  }
306
- pubkey = proto_signing_1.encodePubkey(encoding_3.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
531
+ pubkey = proto_signing_1.encodePubkey(amino_1.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
307
532
  txBodyEncodeObject = {
308
533
  typeUrl: "/cosmos.tx.v1beta1.TxBody",
309
534
  value: {
310
535
  messages: messages,
311
536
  memo: memo,
537
+ timeoutHeight: timeoutHeight,
312
538
  },
313
539
  };
314
540
  txBodyBytes = this.registry.encode(txBodyEncodeObject);
315
541
  gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
316
- authInfoBytes = SigningStargateClient.makeAuthInfoBytes([{ pubkey: pubkey, sequence: sequence }], fee.amount, gasLimit, fee.granter);
542
+ authInfoBytes = proto_signing_1.makeAuthInfoBytes([{ pubkey: pubkey, sequence: sequence }], fee.amount, gasLimit, fee.granter, fee.payer);
317
543
  signDoc = proto_signing_1.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
318
- return [4 /*yield*/, this.getSigner().signDirect(signerAddress, signDoc)];
544
+ return [4 /*yield*/, this.signer.signDirect(signerAddress, signDoc)];
319
545
  case 2:
320
546
  _b = _c.sent(), signature = _b.signature, signed = _b.signed;
321
- return [2 /*return*/, tx_1.TxRaw.fromPartial({
547
+ return [2 /*return*/, tx_3.TxRaw.fromPartial({
322
548
  bodyBytes: signed.bodyBytes,
323
549
  authInfoBytes: signed.authInfoBytes,
324
550
  signatures: [encoding_1.fromBase64(signature.signature)],
@@ -327,31 +553,122 @@ var SigningStargateClient = /** @class */ (function (_super) {
327
553
  });
328
554
  });
329
555
  };
330
- SigningStargateClient.prototype.signDirectForSignDoc = function (signerAddress, signDoc) {
556
+ SigningStargateClient.experimentalAdr36Verify = function (data, checkMsg) {
557
+ return __awaiter(this, void 0, void 0, function () {
558
+ var newSignature, signed, accountNumber, sequence, chainId, signedMessages, sourceMsg, signatures, signature, signBytes, prehashed, secpSignature, rawSecp256k1Pubkey, rawSignerAddress, ok;
559
+ return __generator(this, function (_a) {
560
+ switch (_a.label) {
561
+ case 0:
562
+ newSignature = amino_1.encodeSecp256k1Signature(FirmaUtil_1.FirmaUtil.base64ToArrayBuffer(data.pubkey), FirmaUtil_1.FirmaUtil.base64ToArrayBuffer(data.signature));
563
+ signed = {
564
+ fee: {
565
+ gas: "0",
566
+ amount: [],
567
+ },
568
+ msg: [{
569
+ type: data.type,
570
+ value: { signer: data.signer, data: data.data }
571
+ }],
572
+ signatures: [newSignature],
573
+ memo: ""
574
+ };
575
+ // Restrictions from ADR-036
576
+ if (signed.memo !== "")
577
+ throw new Error("Memo must be empty.");
578
+ if (signed.fee.gas !== "0")
579
+ throw new Error("Fee gas must 0.");
580
+ if (signed.fee.amount.length !== 0)
581
+ throw new Error("Fee amount must be an empty array.");
582
+ accountNumber = 0;
583
+ sequence = 0;
584
+ chainId = "";
585
+ signedMessages = signed.msg;
586
+ if (!signedMessages.every(isMsgSignData)) {
587
+ throw new Error("Found message that is not the expected type.");
588
+ }
589
+ if (signedMessages.length === 0) {
590
+ throw new Error("No message found. Without messages we cannot determine the signer address.");
591
+ }
592
+ sourceMsg = Buffer.from(signedMessages[0].value.data, 'base64').toString();
593
+ if (sourceMsg !== checkMsg) {
594
+ throw new Error("Different Msg error. source:" + sourceMsg + ", target:" + checkMsg);
595
+ }
596
+ signatures = signed.signatures;
597
+ if (signatures.length !== 1)
598
+ throw new Error("Must have exactly one signature to be supported.");
599
+ signature = signatures[0];
600
+ if (!amino_1.isSecp256k1Pubkey(signature.pub_key)) {
601
+ throw new Error("Only secp256k1 signatures are supported.");
602
+ }
603
+ signBytes = amino_1.serializeSignDoc(amino_1.makeSignDoc(signed.msg, signed.fee, chainId, signed.memo, accountNumber, sequence));
604
+ prehashed = crypto_1.sha256(signBytes);
605
+ secpSignature = crypto_1.Secp256k1Signature.fromFixedLength(encoding_1.fromBase64(signature.signature));
606
+ rawSecp256k1Pubkey = encoding_1.fromBase64(signature.pub_key.value);
607
+ rawSignerAddress = amino_1.rawSecp256k1PubkeyToRawAddress(rawSecp256k1Pubkey);
608
+ if (signedMessages.some(function (msg) { return !utils_1.arrayContentEquals(encoding_1.fromBech32(msg.value.signer).data, rawSignerAddress); })) {
609
+ throw new Error("Found mismatch between signer in message and public key");
610
+ }
611
+ return [4 /*yield*/, crypto_1.Secp256k1.verifySignature(secpSignature, prehashed, rawSecp256k1Pubkey)];
612
+ case 1:
613
+ ok = _a.sent();
614
+ return [2 /*return*/, ok];
615
+ }
616
+ });
617
+ });
618
+ };
619
+ SigningStargateClient.prototype.experimentalAdr36Sign = function (signerAddress, data) {
331
620
  return __awaiter(this, void 0, void 0, function () {
332
- var accountFromSigner, _a, signature, signed, txRaw;
621
+ var accountNumber, sequence, chainId, fee, memo, datas, msgs, accountFromSigner, signDoc, _a, signature, signed, signatureResult, decodeData, jsonData;
333
622
  return __generator(this, function (_b) {
334
623
  switch (_b.label) {
335
- case 0: return [4 /*yield*/, this.getSigner().getAccounts()];
624
+ case 0:
625
+ accountNumber = 0;
626
+ sequence = 0;
627
+ chainId = "";
628
+ fee = {
629
+ gas: "0",
630
+ amount: [],
631
+ //granter: "" // added by DH
632
+ };
633
+ memo = "";
634
+ datas = Array.isArray(data) ? data : [data];
635
+ msgs = datas.map(function (d) { return ({
636
+ type: "sign/MsgSignData",
637
+ value: {
638
+ signer: signerAddress,
639
+ data: encoding_1.toBase64(d),
640
+ },
641
+ }); });
642
+ return [4 /*yield*/, this.signer.getAccounts()];
336
643
  case 1:
337
644
  accountFromSigner = (_b.sent()).find(function (account) { return account.address === signerAddress; });
338
645
  if (!accountFromSigner) {
339
646
  throw new Error("Failed to retrieve account from signer");
340
647
  }
341
- return [4 /*yield*/, this.getSigner().signDirect(signerAddress, signDoc)];
648
+ if (!("signAmino" in this.signer)) {
649
+ throw new Error("The signer does not support signAmino. Please use an OfflineAminoSigner instance.");
650
+ }
651
+ signDoc = amino_1.makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence);
652
+ return [4 /*yield*/, this.signer.signAmino(signerAddress, signDoc)];
342
653
  case 2:
343
654
  _a = _b.sent(), signature = _a.signature, signed = _a.signed;
344
- txRaw = tx_1.TxRaw.fromPartial({
345
- bodyBytes: signed.bodyBytes,
346
- authInfoBytes: signed.authInfoBytes,
347
- signatures: [encoding_1.fromBase64(signature.signature)],
348
- });
349
- return [2 /*return*/, { txRaw: txRaw, signature: signature.signature }];
655
+ if (!fast_deep_equal_1.default(signDoc, signed)) {
656
+ throw new Error("The signed document differs from the signing instruction. This is not supported for ADR-036.");
657
+ }
658
+ signatureResult = amino_1.makeStdTx(signDoc, signature);
659
+ decodeData = amino_1.decodeSignature(signatureResult.signatures[0]);
660
+ jsonData = {
661
+ type: "sign/MsgSignData",
662
+ signer: signatureResult.msg[0].value.signer,
663
+ data: signatureResult.msg[0].value.data,
664
+ pubkey: FirmaUtil_1.FirmaUtil.arrayBufferToBase64(decodeData.pubkey),
665
+ signature: FirmaUtil_1.FirmaUtil.arrayBufferToBase64(decodeData.signature)
666
+ };
667
+ return [2 /*return*/, jsonData];
350
668
  }
351
669
  });
352
670
  });
353
671
  };
354
- SigningStargateClient._endpoint = "";
355
672
  return SigningStargateClient;
356
673
  }(stargateclient_1.StargateClient));
357
674
  exports.SigningStargateClient = SigningStargateClient;