@firmachain/firma-js 0.2.17 → 0.2.21

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 (157) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +136 -136
  3. package/dist/index.d.ts +4 -0
  4. package/dist/index.js +16 -0
  5. package/dist/sdk/FirmaBankService.d.ts +15 -0
  6. package/dist/sdk/FirmaBankService.js +211 -0
  7. package/dist/sdk/FirmaChainService.d.ts +8 -0
  8. package/dist/sdk/FirmaChainService.js +86 -0
  9. package/dist/sdk/FirmaConfig.d.ts +16 -0
  10. package/dist/sdk/FirmaConfig.js +55 -0
  11. package/dist/sdk/FirmaContractService.d.ts +31 -0
  12. package/dist/sdk/FirmaContractService.js +413 -0
  13. package/dist/sdk/FirmaDistributionService.d.ts +31 -0
  14. package/dist/sdk/FirmaDistributionService.js +524 -0
  15. package/dist/sdk/FirmaFeeGrantService.d.ts +21 -0
  16. package/dist/sdk/FirmaFeeGrantService.js +341 -0
  17. package/dist/sdk/FirmaGovService.d.ts +35 -0
  18. package/dist/sdk/FirmaGovService.js +775 -0
  19. package/dist/sdk/FirmaIpfsService.d.ts +12 -0
  20. package/dist/sdk/FirmaIpfsService.js +185 -0
  21. package/dist/sdk/FirmaMobileSDK.d.ts +27 -0
  22. package/dist/sdk/FirmaMobileSDK.js +45 -0
  23. package/dist/sdk/FirmaNftService.d.ts +31 -0
  24. package/dist/sdk/FirmaNftService.js +372 -0
  25. package/dist/sdk/FirmaSDK.d.ts +29 -0
  26. package/dist/sdk/FirmaSDK.js +48 -0
  27. package/dist/sdk/FirmaSlashingService.d.ts +9 -0
  28. package/dist/sdk/FirmaSlashingService.js +105 -0
  29. package/dist/sdk/FirmaStakingService.d.ts +34 -0
  30. package/dist/sdk/FirmaStakingService.js +604 -0
  31. package/dist/sdk/FirmaTokenService.d.ts +26 -0
  32. package/dist/sdk/FirmaTokenService.js +416 -0
  33. package/dist/sdk/FirmaUtil.d.ts +26 -0
  34. package/dist/sdk/FirmaUtil.js +210 -0
  35. package/dist/sdk/FirmaWalletService.d.ts +36 -0
  36. package/dist/sdk/FirmaWalletService.js +309 -0
  37. package/dist/sdk/firmachain/amino/addresses.d.ts +5 -0
  38. package/dist/sdk/firmachain/amino/addresses.js +46 -0
  39. package/dist/sdk/firmachain/amino/aminomsgs.d.ts +281 -0
  40. package/dist/sdk/firmachain/amino/aminomsgs.js +77 -0
  41. package/dist/sdk/firmachain/amino/aminotypes.d.ts +22 -0
  42. package/dist/sdk/firmachain/amino/aminotypes.js +521 -0
  43. package/dist/sdk/firmachain/amino/coins.d.ts +30 -0
  44. package/dist/sdk/firmachain/amino/coins.js +69 -0
  45. package/dist/sdk/firmachain/amino/encoding.d.ts +24 -0
  46. package/dist/sdk/firmachain/amino/encoding.js +234 -0
  47. package/dist/sdk/firmachain/amino/multisig.d.ts +10 -0
  48. package/dist/sdk/firmachain/amino/multisig.js +42 -0
  49. package/dist/sdk/firmachain/amino/paths.d.ts +6 -0
  50. package/dist/sdk/firmachain/amino/paths.js +18 -0
  51. package/dist/sdk/firmachain/amino/pubkeys.d.ts +47 -0
  52. package/dist/sdk/firmachain/amino/pubkeys.js +29 -0
  53. package/dist/sdk/firmachain/amino/secp256k1hdwallet.d.ts +94 -0
  54. package/dist/sdk/firmachain/amino/secp256k1hdwallet.js +437 -0
  55. package/dist/sdk/firmachain/amino/secp256k1wallet.d.ts +23 -0
  56. package/dist/sdk/firmachain/amino/secp256k1wallet.js +141 -0
  57. package/dist/sdk/firmachain/amino/signature.d.ts +16 -0
  58. package/dist/sdk/firmachain/amino/signature.js +36 -0
  59. package/dist/sdk/firmachain/amino/signdoc.d.ts +26 -0
  60. package/dist/sdk/firmachain/amino/signdoc.js +42 -0
  61. package/dist/sdk/firmachain/amino/signer.d.ts +33 -0
  62. package/dist/sdk/firmachain/amino/signer.js +2 -0
  63. package/dist/sdk/firmachain/amino/stdtx.d.ts +15 -0
  64. package/dist/sdk/firmachain/amino/stdtx.js +17 -0
  65. package/dist/sdk/firmachain/amino/wallet.d.ts +32 -0
  66. package/dist/sdk/firmachain/amino/wallet.js +132 -0
  67. package/dist/sdk/firmachain/bank/BankQueryClient.d.ts +12 -0
  68. package/dist/sdk/firmachain/bank/BankQueryClient.js +116 -0
  69. package/dist/sdk/firmachain/bank/BankTxClient.d.ts +17 -0
  70. package/dist/sdk/firmachain/bank/BankTxClient.js +40 -0
  71. package/dist/sdk/firmachain/bank/index.d.ts +3 -0
  72. package/dist/sdk/firmachain/bank/index.js +15 -0
  73. package/dist/sdk/firmachain/common/ITxClient.d.ts +15 -0
  74. package/dist/sdk/firmachain/common/ITxClient.js +102 -0
  75. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +27 -0
  76. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +165 -0
  77. package/dist/sdk/firmachain/common/LedgerWallet.d.ts +14 -0
  78. package/dist/sdk/firmachain/common/LedgerWallet.js +147 -0
  79. package/dist/sdk/firmachain/common/QueryCommon.d.ts +4 -0
  80. package/dist/sdk/firmachain/common/QueryCommon.js +2 -0
  81. package/dist/sdk/firmachain/common/TendermintQueryClient.d.ts +42 -0
  82. package/dist/sdk/firmachain/common/TendermintQueryClient.js +108 -0
  83. package/dist/sdk/firmachain/common/TxCommon.d.ts +94 -0
  84. package/dist/sdk/firmachain/common/TxCommon.js +34 -0
  85. package/dist/sdk/firmachain/common/accounts.d.ts +16 -0
  86. package/dist/sdk/firmachain/common/accounts.js +64 -0
  87. package/dist/sdk/firmachain/common/index.d.ts +2 -0
  88. package/dist/sdk/firmachain/common/index.js +14 -0
  89. package/dist/sdk/firmachain/common/signing.d.ts +10 -0
  90. package/dist/sdk/firmachain/common/signing.js +75 -0
  91. package/dist/sdk/firmachain/common/signingstargateclient.d.ts +37 -0
  92. package/dist/sdk/firmachain/common/signingstargateclient.js +298 -0
  93. package/dist/sdk/firmachain/common/stargateclient.d.ts +46 -0
  94. package/dist/sdk/firmachain/common/stargateclient.js +211 -0
  95. package/dist/sdk/firmachain/contract/ContractQueryClient.d.ts +32 -0
  96. package/dist/sdk/firmachain/contract/ContractQueryClient.js +156 -0
  97. package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +17 -0
  98. package/dist/sdk/firmachain/contract/ContractTxClient.js +40 -0
  99. package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +69 -0
  100. package/dist/sdk/firmachain/contract/ContractTxTypes.js +483 -0
  101. package/dist/sdk/firmachain/contract/index.d.ts +3 -0
  102. package/dist/sdk/firmachain/contract/index.js +15 -0
  103. package/dist/sdk/firmachain/distribution/DistributionQueryClient.d.ts +18 -0
  104. package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +167 -0
  105. package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +27 -0
  106. package/dist/sdk/firmachain/distribution/DistributionTxClient.js +48 -0
  107. package/dist/sdk/firmachain/distribution/index.d.ts +3 -0
  108. package/dist/sdk/firmachain/distribution/index.js +15 -0
  109. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.d.ts +17 -0
  110. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +86 -0
  111. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +17 -0
  112. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +40 -0
  113. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +76 -0
  114. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +194 -0
  115. package/dist/sdk/firmachain/feegrant/index.d.ts +2 -0
  116. package/dist/sdk/firmachain/feegrant/index.js +15 -0
  117. package/dist/sdk/firmachain/google/protobuf/any.d.ts +128 -0
  118. package/dist/sdk/firmachain/google/protobuf/any.js +106 -0
  119. package/dist/sdk/firmachain/google/protobuf/descriptor.d.ts +996 -0
  120. package/dist/sdk/firmachain/google/protobuf/descriptor.js +5329 -0
  121. package/dist/sdk/firmachain/google/protobuf/duration.d.ts +91 -0
  122. package/dist/sdk/firmachain/google/protobuf/duration.js +107 -0
  123. package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +109 -0
  124. package/dist/sdk/firmachain/google/protobuf/timestamp.js +107 -0
  125. package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +61 -0
  126. package/dist/sdk/firmachain/gov/GovQueryClient.js +152 -0
  127. package/dist/sdk/firmachain/gov/GovTxClient.d.ts +22 -0
  128. package/dist/sdk/firmachain/gov/GovTxClient.js +44 -0
  129. package/dist/sdk/firmachain/gov/index.d.ts +3 -0
  130. package/dist/sdk/firmachain/gov/index.js +15 -0
  131. package/dist/sdk/firmachain/nft/NftQueryClient.d.ts +20 -0
  132. package/dist/sdk/firmachain/nft/NftQueryClient.js +125 -0
  133. package/dist/sdk/firmachain/nft/NftTxClient.d.ts +22 -0
  134. package/dist/sdk/firmachain/nft/NftTxClient.js +44 -0
  135. package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +86 -0
  136. package/dist/sdk/firmachain/nft/NftTxTypes.js +424 -0
  137. package/dist/sdk/firmachain/nft/index.d.ts +3 -0
  138. package/dist/sdk/firmachain/nft/index.js +15 -0
  139. package/dist/sdk/firmachain/slashing/SlashingQueryClient.d.ts +22 -0
  140. package/dist/sdk/firmachain/slashing/SlashingQueryClient.js +101 -0
  141. package/dist/sdk/firmachain/slashing/index.d.ts +2 -0
  142. package/dist/sdk/firmachain/slashing/index.js +14 -0
  143. package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +93 -0
  144. package/dist/sdk/firmachain/staking/StakingQueryClient.js +223 -0
  145. package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +32 -0
  146. package/dist/sdk/firmachain/staking/StakingTxClient.js +52 -0
  147. package/dist/sdk/firmachain/staking/index.d.ts +3 -0
  148. package/dist/sdk/firmachain/staking/index.js +15 -0
  149. package/dist/sdk/firmachain/token/TokenQueryClient.d.ts +24 -0
  150. package/dist/sdk/firmachain/token/TokenQueryClient.js +106 -0
  151. package/dist/sdk/firmachain/token/TokenTxClient.d.ts +27 -0
  152. package/dist/sdk/firmachain/token/TokenTxClient.js +48 -0
  153. package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +116 -0
  154. package/dist/sdk/firmachain/token/TokenTxTypes.js +685 -0
  155. package/dist/sdk/firmachain/token/index.d.ts +3 -0
  156. package/dist/sdk/firmachain/token/index.js +15 -0
  157. package/package.json +54 -54
@@ -0,0 +1,416 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.TokenService = void 0;
40
+ var token_1 = require("./firmachain/token");
41
+ var FirmaUtil_1 = require("./FirmaUtil");
42
+ var TokenService = /** @class */ (function () {
43
+ function TokenService(config) {
44
+ this.config = config;
45
+ }
46
+ TokenService.prototype.getGasEstimationCreateToken = function (wallet, tokenName, tokenSymbol, tokenURI, totalSupply, decimal, isMintable, isBurnable, txMisc) {
47
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var newTotalSupply, txRaw, error_1;
50
+ return __generator(this, function (_a) {
51
+ switch (_a.label) {
52
+ case 0:
53
+ _a.trys.push([0, 3, , 4]);
54
+ newTotalSupply = FirmaUtil_1.FirmaUtil.getUTokenFromToken(totalSupply, decimal);
55
+ return [4 /*yield*/, this.getSignedTxCreateToken(wallet, tokenName, tokenSymbol, tokenURI, newTotalSupply, decimal, isMintable, isBurnable, txMisc)];
56
+ case 1:
57
+ txRaw = _a.sent();
58
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
59
+ case 2: return [2 /*return*/, _a.sent()];
60
+ case 3:
61
+ error_1 = _a.sent();
62
+ FirmaUtil_1.FirmaUtil.printLog(error_1);
63
+ throw error_1;
64
+ case 4: return [2 /*return*/];
65
+ }
66
+ });
67
+ });
68
+ };
69
+ TokenService.prototype.getGasEstimationMint = function (wallet, tokenID, amount, decimal, toAddress, txMisc) {
70
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ var newAmount, txRaw, error_2;
73
+ return __generator(this, function (_a) {
74
+ switch (_a.label) {
75
+ case 0:
76
+ _a.trys.push([0, 3, , 4]);
77
+ newAmount = FirmaUtil_1.FirmaUtil.getUTokenFromToken(amount, decimal);
78
+ return [4 /*yield*/, this.getSignedTxMint(wallet, tokenID, amount, toAddress, txMisc)];
79
+ case 1:
80
+ txRaw = _a.sent();
81
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
82
+ case 2: return [2 /*return*/, _a.sent()];
83
+ case 3:
84
+ error_2 = _a.sent();
85
+ FirmaUtil_1.FirmaUtil.printLog(error_2);
86
+ throw error_2;
87
+ case 4: return [2 /*return*/];
88
+ }
89
+ });
90
+ });
91
+ };
92
+ TokenService.prototype.getGasEstimationBurn = function (wallet, tokenID, amount, decimal, txMisc) {
93
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
94
+ return __awaiter(this, void 0, void 0, function () {
95
+ var newAmount, txRaw, error_3;
96
+ return __generator(this, function (_a) {
97
+ switch (_a.label) {
98
+ case 0:
99
+ _a.trys.push([0, 3, , 4]);
100
+ newAmount = FirmaUtil_1.FirmaUtil.getUTokenFromToken(amount, decimal);
101
+ return [4 /*yield*/, this.getSignedTxBurn(wallet, tokenID, newAmount, txMisc)];
102
+ case 1:
103
+ txRaw = _a.sent();
104
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
105
+ case 2: return [2 /*return*/, _a.sent()];
106
+ case 3:
107
+ error_3 = _a.sent();
108
+ FirmaUtil_1.FirmaUtil.printLog(error_3);
109
+ throw error_3;
110
+ case 4: return [2 /*return*/];
111
+ }
112
+ });
113
+ });
114
+ };
115
+ TokenService.prototype.getGasEstimationUpdateTokenURI = function (wallet, tokenID, tokenURI, txMisc) {
116
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ var txRaw, error_4;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0:
122
+ _a.trys.push([0, 3, , 4]);
123
+ return [4 /*yield*/, this.getSignedTxUpdateTokenURI(wallet, tokenID, tokenURI, txMisc)];
124
+ case 1:
125
+ txRaw = _a.sent();
126
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
127
+ case 2: return [2 /*return*/, _a.sent()];
128
+ case 3:
129
+ error_4 = _a.sent();
130
+ FirmaUtil_1.FirmaUtil.printLog(error_4);
131
+ throw error_4;
132
+ case 4: return [2 /*return*/];
133
+ }
134
+ });
135
+ });
136
+ };
137
+ TokenService.prototype.getSignedTxUpdateTokenURI = function (wallet, tokenID, tokenURI, txMisc) {
138
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
139
+ return __awaiter(this, void 0, void 0, function () {
140
+ var address, txClient, message, error_5;
141
+ return __generator(this, function (_a) {
142
+ switch (_a.label) {
143
+ case 0:
144
+ _a.trys.push([0, 3, , 4]);
145
+ return [4 /*yield*/, wallet.getAddress()];
146
+ case 1:
147
+ address = _a.sent();
148
+ txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
149
+ message = txClient.msgUpdateTokenURI({
150
+ owner: address,
151
+ tokenID: tokenID,
152
+ tokenURI: tokenURI
153
+ });
154
+ return [4 /*yield*/, txClient.sign([message], token_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
155
+ case 2: return [2 /*return*/, _a.sent()];
156
+ case 3:
157
+ error_5 = _a.sent();
158
+ FirmaUtil_1.FirmaUtil.printLog(error_5);
159
+ throw error_5;
160
+ case 4: return [2 /*return*/];
161
+ }
162
+ });
163
+ });
164
+ };
165
+ TokenService.prototype.getSignedTxBurn = function (wallet, tokenID, amount, txMisc) {
166
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
167
+ return __awaiter(this, void 0, void 0, function () {
168
+ var address, txClient, message, error_6;
169
+ return __generator(this, function (_a) {
170
+ switch (_a.label) {
171
+ case 0:
172
+ _a.trys.push([0, 3, , 4]);
173
+ return [4 /*yield*/, wallet.getAddress()];
174
+ case 1:
175
+ address = _a.sent();
176
+ txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
177
+ message = txClient.msgBurn({
178
+ owner: address,
179
+ tokenID: tokenID,
180
+ amount: amount
181
+ });
182
+ return [4 /*yield*/, txClient.sign([message], token_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
183
+ case 2: return [2 /*return*/, _a.sent()];
184
+ case 3:
185
+ error_6 = _a.sent();
186
+ FirmaUtil_1.FirmaUtil.printLog(error_6);
187
+ throw error_6;
188
+ case 4: return [2 /*return*/];
189
+ }
190
+ });
191
+ });
192
+ };
193
+ TokenService.prototype.getSignedTxMint = function (wallet, tokenID, amount, toAddress, txMisc) {
194
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
195
+ return __awaiter(this, void 0, void 0, function () {
196
+ var address, txClient, message, error_7;
197
+ return __generator(this, function (_a) {
198
+ switch (_a.label) {
199
+ case 0:
200
+ _a.trys.push([0, 3, , 4]);
201
+ return [4 /*yield*/, wallet.getAddress()];
202
+ case 1:
203
+ address = _a.sent();
204
+ txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
205
+ message = txClient.msgMint({
206
+ owner: address,
207
+ tokenID: tokenID,
208
+ amount: amount,
209
+ toAddress: toAddress
210
+ });
211
+ return [4 /*yield*/, txClient.sign([message], token_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
212
+ case 2: return [2 /*return*/, _a.sent()];
213
+ case 3:
214
+ error_7 = _a.sent();
215
+ FirmaUtil_1.FirmaUtil.printLog(error_7);
216
+ throw error_7;
217
+ case 4: return [2 /*return*/];
218
+ }
219
+ });
220
+ });
221
+ };
222
+ TokenService.prototype.getSignedTxCreateToken = function (wallet, tokenName, tokenSymbol, tokenURI, totalSupply, decimal, isMintable, isBurnable, txMisc) {
223
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
224
+ return __awaiter(this, void 0, void 0, function () {
225
+ var address, txClient, message, error_8;
226
+ return __generator(this, function (_a) {
227
+ switch (_a.label) {
228
+ case 0:
229
+ _a.trys.push([0, 3, , 4]);
230
+ return [4 /*yield*/, wallet.getAddress()];
231
+ case 1:
232
+ address = _a.sent();
233
+ txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
234
+ message = txClient.msgCreateToken({
235
+ owner: address,
236
+ name: tokenName,
237
+ symbol: tokenSymbol,
238
+ tokenURI: tokenURI,
239
+ totalSupply: totalSupply,
240
+ decimal: decimal,
241
+ mintable: isMintable,
242
+ burnable: isBurnable
243
+ });
244
+ return [4 /*yield*/, txClient.sign([message], token_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
245
+ case 2: return [2 /*return*/, _a.sent()];
246
+ case 3:
247
+ error_8 = _a.sent();
248
+ FirmaUtil_1.FirmaUtil.printLog(error_8);
249
+ throw error_8;
250
+ case 4: return [2 /*return*/];
251
+ }
252
+ });
253
+ });
254
+ };
255
+ //./firmachaind tx token mint ukai 1000000 firma1jmg3kwy5hntx66nl93dyk2d92943394qsf6gcf --from alice --fees 2000ufct --chain-id imperium-2
256
+ TokenService.prototype.createToken = function (wallet, tokenName, tokenSymbol, tokenURI, totalSupply, decimal, isMintable, isBurnable, txMisc) {
257
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
258
+ return __awaiter(this, void 0, void 0, function () {
259
+ var newTotalSupply, txRaw, nftTxClient, error_9;
260
+ return __generator(this, function (_a) {
261
+ switch (_a.label) {
262
+ case 0:
263
+ _a.trys.push([0, 3, , 4]);
264
+ newTotalSupply = FirmaUtil_1.FirmaUtil.getUTokenFromToken(totalSupply, decimal);
265
+ return [4 /*yield*/, this.getSignedTxCreateToken(wallet, tokenName, tokenSymbol, tokenURI, newTotalSupply, decimal, isMintable, isBurnable, txMisc)];
266
+ case 1:
267
+ txRaw = _a.sent();
268
+ nftTxClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
269
+ return [4 /*yield*/, nftTxClient.broadcast(txRaw)];
270
+ case 2: return [2 /*return*/, _a.sent()];
271
+ case 3:
272
+ error_9 = _a.sent();
273
+ FirmaUtil_1.FirmaUtil.printLog(error_9);
274
+ throw error_9;
275
+ case 4: return [2 /*return*/];
276
+ }
277
+ });
278
+ });
279
+ };
280
+ TokenService.prototype.mint = function (wallet, tokenID, amount, decimal, toAddress, txMisc) {
281
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
282
+ return __awaiter(this, void 0, void 0, function () {
283
+ var newAmount, txRaw, nftTxClient, error_10;
284
+ return __generator(this, function (_a) {
285
+ switch (_a.label) {
286
+ case 0:
287
+ _a.trys.push([0, 3, , 4]);
288
+ newAmount = FirmaUtil_1.FirmaUtil.getUTokenFromToken(amount, decimal);
289
+ return [4 /*yield*/, this.getSignedTxMint(wallet, tokenID, newAmount, toAddress, txMisc)];
290
+ case 1:
291
+ txRaw = _a.sent();
292
+ nftTxClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
293
+ return [4 /*yield*/, nftTxClient.broadcast(txRaw)];
294
+ case 2: return [2 /*return*/, _a.sent()];
295
+ case 3:
296
+ error_10 = _a.sent();
297
+ FirmaUtil_1.FirmaUtil.printLog(error_10);
298
+ throw error_10;
299
+ case 4: return [2 /*return*/];
300
+ }
301
+ });
302
+ });
303
+ };
304
+ TokenService.prototype.burn = function (wallet, tokenID, amount, decimal, txMisc) {
305
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
306
+ return __awaiter(this, void 0, void 0, function () {
307
+ var newAmount, txRaw, nftTxClient, error_11;
308
+ return __generator(this, function (_a) {
309
+ switch (_a.label) {
310
+ case 0:
311
+ _a.trys.push([0, 3, , 4]);
312
+ newAmount = FirmaUtil_1.FirmaUtil.getUTokenFromToken(amount, decimal);
313
+ return [4 /*yield*/, this.getSignedTxBurn(wallet, tokenID, newAmount, txMisc)];
314
+ case 1:
315
+ txRaw = _a.sent();
316
+ nftTxClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
317
+ return [4 /*yield*/, nftTxClient.broadcast(txRaw)];
318
+ case 2: return [2 /*return*/, _a.sent()];
319
+ case 3:
320
+ error_11 = _a.sent();
321
+ FirmaUtil_1.FirmaUtil.printLog(error_11);
322
+ throw error_11;
323
+ case 4: return [2 /*return*/];
324
+ }
325
+ });
326
+ });
327
+ };
328
+ TokenService.prototype.updateTokenURI = function (wallet, tokenID, tokenURI, txMisc) {
329
+ if (txMisc === void 0) { txMisc = token_1.DefaultTxMisc; }
330
+ return __awaiter(this, void 0, void 0, function () {
331
+ var txRaw, nftTxClient, error_12;
332
+ return __generator(this, function (_a) {
333
+ switch (_a.label) {
334
+ case 0:
335
+ _a.trys.push([0, 3, , 4]);
336
+ return [4 /*yield*/, this.getSignedTxUpdateTokenURI(wallet, tokenID, tokenURI, txMisc)];
337
+ case 1:
338
+ txRaw = _a.sent();
339
+ nftTxClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
340
+ return [4 /*yield*/, nftTxClient.broadcast(txRaw)];
341
+ case 2: return [2 /*return*/, _a.sent()];
342
+ case 3:
343
+ error_12 = _a.sent();
344
+ FirmaUtil_1.FirmaUtil.printLog(error_12);
345
+ throw error_12;
346
+ case 4: return [2 /*return*/];
347
+ }
348
+ });
349
+ });
350
+ };
351
+ // query
352
+ TokenService.prototype.getGetTokenDataAll = function (paginationKey) {
353
+ if (paginationKey === void 0) { paginationKey = ""; }
354
+ return __awaiter(this, void 0, void 0, function () {
355
+ var queryClient, error_13;
356
+ return __generator(this, function (_a) {
357
+ switch (_a.label) {
358
+ case 0:
359
+ _a.trys.push([0, 2, , 3]);
360
+ queryClient = new token_1.TokenQueryClient(this.config.restApiAddress);
361
+ return [4 /*yield*/, queryClient.queryTokenDataAll(paginationKey)];
362
+ case 1: return [2 /*return*/, _a.sent()];
363
+ case 2:
364
+ error_13 = _a.sent();
365
+ FirmaUtil_1.FirmaUtil.printLog(error_13);
366
+ throw error_13;
367
+ case 3: return [2 /*return*/];
368
+ }
369
+ });
370
+ });
371
+ };
372
+ TokenService.prototype.getTokenData = function (tokenID) {
373
+ return __awaiter(this, void 0, void 0, function () {
374
+ var queryClient, tokenData, error_14;
375
+ return __generator(this, function (_a) {
376
+ switch (_a.label) {
377
+ case 0:
378
+ _a.trys.push([0, 2, , 3]);
379
+ queryClient = new token_1.TokenQueryClient(this.config.restApiAddress);
380
+ return [4 /*yield*/, queryClient.queryTokenData(tokenID)];
381
+ case 1:
382
+ tokenData = _a.sent();
383
+ return [2 /*return*/, tokenData];
384
+ case 2:
385
+ error_14 = _a.sent();
386
+ FirmaUtil_1.FirmaUtil.printLog(error_14);
387
+ throw error_14;
388
+ case 3: return [2 /*return*/];
389
+ }
390
+ });
391
+ });
392
+ };
393
+ TokenService.prototype.getTokenDataListFromOwner = function (ownerAddress) {
394
+ return __awaiter(this, void 0, void 0, function () {
395
+ var queryClient, tokenData, error_15;
396
+ return __generator(this, function (_a) {
397
+ switch (_a.label) {
398
+ case 0:
399
+ _a.trys.push([0, 2, , 3]);
400
+ queryClient = new token_1.TokenQueryClient(this.config.restApiAddress);
401
+ return [4 /*yield*/, queryClient.queryTokenDataFromOwner(ownerAddress)];
402
+ case 1:
403
+ tokenData = _a.sent();
404
+ return [2 /*return*/, tokenData];
405
+ case 2:
406
+ error_15 = _a.sent();
407
+ FirmaUtil_1.FirmaUtil.printLog(error_15);
408
+ throw error_15;
409
+ case 3: return [2 /*return*/];
410
+ }
411
+ });
412
+ });
413
+ };
414
+ return TokenService;
415
+ }());
416
+ exports.TokenService = TokenService;
@@ -0,0 +1,26 @@
1
+ import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
2
+ import { FirmaConfig } from "./FirmaConfig";
3
+ import { SignerData } from "./firmachain/common/LedgerSigningStargateClient";
4
+ export declare class FirmaUtil {
5
+ static config: FirmaConfig;
6
+ static readonly FctDecimal: number;
7
+ constructor(firmaConfig: FirmaConfig);
8
+ static getUTokenStringFromTokenStr(tokenAmount: string, decimal: number): string;
9
+ static getTokenStringFromUTokenStr(uTokenAmount: string, decimal: number): string;
10
+ static getUTokenStringFromToken(tokenAmount: number, decimal: number): string;
11
+ static getUTokenFromToken(tokenAmount: number, decimal: number): number;
12
+ static getTokenStringFromUToken(uTokenAmount: number, decimal: number): string;
13
+ static getUFCTStringFromFCTStr(fctAmount: string): string;
14
+ static getFCTStringFromUFCTStr(uFctAmount: string): string;
15
+ static getUFCTStringFromFCT(fctAmount: number): string;
16
+ static getFCTStringFromUFCT(uFctAmount: number): string;
17
+ static getFileHash(filePath: string): Promise<string>;
18
+ static getFileHashFromBuffer(buffer: Uint8Array): Promise<string>;
19
+ static isValidAddress(address: string): boolean;
20
+ static getValOperAddressFromAccAddress(address: string): string;
21
+ static getAccAddressFromValOperAddress(address: string): string;
22
+ static getSignerDataForLedger(address: string): Promise<SignerData>;
23
+ static estimateGas(txRaw: TxRaw): Promise<number>;
24
+ static estimateGasRaw(txRaw: Uint8Array): Promise<number>;
25
+ static printLog(log: any): void;
26
+ }
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.FirmaUtil = void 0;
40
+ var fs_1 = require("fs");
41
+ var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
42
+ var TendermintQueryClient_1 = require("./firmachain/common/TendermintQueryClient");
43
+ var encoding_1 = require("@cosmjs/encoding");
44
+ var LedgerSigningStargateClient_1 = require("./firmachain/common/LedgerSigningStargateClient");
45
+ var CryptoJS = require("crypto-js");
46
+ var sha256 = require("crypto-js/sha256");
47
+ var encHex = require("crypto-js/enc-hex");
48
+ var FirmaUtil = /** @class */ (function () {
49
+ function FirmaUtil(firmaConfig) {
50
+ FirmaUtil.config = firmaConfig;
51
+ }
52
+ FirmaUtil.getUTokenStringFromTokenStr = function (tokenAmount, decimal) {
53
+ var fct = Number.parseFloat(tokenAmount);
54
+ var decimalMutiplyer = Math.pow(10, decimal);
55
+ var big = fct * decimalMutiplyer;
56
+ return big.toString();
57
+ };
58
+ FirmaUtil.getTokenStringFromUTokenStr = function (uTokenAmount, decimal) {
59
+ var ufct = Number.parseInt(uTokenAmount);
60
+ var decimalMutiplyer = Math.pow(10, decimal);
61
+ return (ufct / decimalMutiplyer).toString();
62
+ };
63
+ FirmaUtil.getUTokenStringFromToken = function (tokenAmount, decimal) {
64
+ var decimalMutiplyer = Math.pow(10, decimal);
65
+ var big = tokenAmount * decimalMutiplyer;
66
+ return big.toString();
67
+ };
68
+ FirmaUtil.getUTokenFromToken = function (tokenAmount, decimal) {
69
+ var decimalMutiplyer = Math.pow(10, decimal);
70
+ var big = tokenAmount * decimalMutiplyer;
71
+ return big;
72
+ };
73
+ FirmaUtil.getTokenStringFromUToken = function (uTokenAmount, decimal) {
74
+ var decimalMutiplyer = Math.pow(10, decimal);
75
+ return (uTokenAmount / decimalMutiplyer).toString();
76
+ };
77
+ FirmaUtil.getUFCTStringFromFCTStr = function (fctAmount) {
78
+ return this.getUTokenStringFromTokenStr(fctAmount, this.FctDecimal);
79
+ };
80
+ FirmaUtil.getFCTStringFromUFCTStr = function (uFctAmount) {
81
+ return this.getTokenStringFromUTokenStr(uFctAmount, this.FctDecimal);
82
+ };
83
+ FirmaUtil.getUFCTStringFromFCT = function (fctAmount) {
84
+ return this.getUTokenStringFromToken(fctAmount, this.FctDecimal);
85
+ };
86
+ FirmaUtil.getFCTStringFromUFCT = function (uFctAmount) {
87
+ return this.getTokenStringFromUToken(uFctAmount, this.FctDecimal);
88
+ };
89
+ FirmaUtil.getFileHash = function (filePath) {
90
+ return __awaiter(this, void 0, void 0, function () {
91
+ var fileData, data;
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0: return [4 /*yield*/, fs_1.promises.readFile(filePath)];
95
+ case 1:
96
+ fileData = _a.sent();
97
+ data = CryptoJS.lib.WordArray.create(fileData.buffer);
98
+ return [2 /*return*/, sha256(data).toString(encHex)];
99
+ }
100
+ });
101
+ });
102
+ };
103
+ FirmaUtil.getFileHashFromBuffer = function (buffer) {
104
+ return __awaiter(this, void 0, void 0, function () {
105
+ var data;
106
+ return __generator(this, function (_a) {
107
+ data = CryptoJS.lib.WordArray.create(buffer);
108
+ return [2 /*return*/, sha256(data).toString(encHex)];
109
+ });
110
+ });
111
+ };
112
+ FirmaUtil.isValidAddress = function (address) {
113
+ try {
114
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
115
+ encoding_1.Bech32.decode(address).data;
116
+ return true;
117
+ }
118
+ catch (e) {
119
+ }
120
+ return false;
121
+ };
122
+ FirmaUtil.getValOperAddressFromAccAddress = function (address) {
123
+ var data = encoding_1.Bech32.decode(address).data;
124
+ return encoding_1.Bech32.encode(FirmaUtil.config.prefix + "valoper", data);
125
+ };
126
+ FirmaUtil.getAccAddressFromValOperAddress = function (address) {
127
+ var data = encoding_1.Bech32.decode(address).data;
128
+ return encoding_1.Bech32.encode(FirmaUtil.config.prefix, data);
129
+ };
130
+ FirmaUtil.getSignerDataForLedger = function (address) {
131
+ return __awaiter(this, void 0, void 0, function () {
132
+ var signingClient, sequence, error_1;
133
+ return __generator(this, function (_a) {
134
+ switch (_a.label) {
135
+ case 0:
136
+ _a.trys.push([0, 3, , 4]);
137
+ return [4 /*yield*/, LedgerSigningStargateClient_1.LedgerSigningStargateClient.connectWithSigner(FirmaUtil.config.rpcAddress)];
138
+ case 1:
139
+ signingClient = _a.sent();
140
+ return [4 /*yield*/, signingClient.getSignerData(address)];
141
+ case 2:
142
+ sequence = _a.sent();
143
+ return [2 /*return*/, sequence];
144
+ case 3:
145
+ error_1 = _a.sent();
146
+ FirmaUtil.printLog(error_1);
147
+ throw error_1;
148
+ case 4: return [2 /*return*/];
149
+ }
150
+ });
151
+ });
152
+ };
153
+ FirmaUtil.estimateGas = function (txRaw) {
154
+ return __awaiter(this, void 0, void 0, function () {
155
+ var encodedTx, hexTx, queryClient, gas, multiplier, error_2;
156
+ return __generator(this, function (_a) {
157
+ switch (_a.label) {
158
+ case 0:
159
+ _a.trys.push([0, 2, , 3]);
160
+ encodedTx = Uint8Array.from(tx_1.TxRaw.encode(txRaw).finish());
161
+ hexTx = "0x" + Buffer.from(encodedTx).toString("hex");
162
+ queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
163
+ return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
164
+ case 1:
165
+ gas = _a.sent();
166
+ multiplier = 1.25;
167
+ return [2 /*return*/, Math.ceil(gas * multiplier)];
168
+ case 2:
169
+ error_2 = _a.sent();
170
+ FirmaUtil.printLog(error_2);
171
+ throw error_2;
172
+ case 3: return [2 /*return*/];
173
+ }
174
+ });
175
+ });
176
+ };
177
+ FirmaUtil.estimateGasRaw = function (txRaw) {
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ var encodedTx, hexTx, queryClient, gas, multiplier, error_3;
180
+ return __generator(this, function (_a) {
181
+ switch (_a.label) {
182
+ case 0:
183
+ _a.trys.push([0, 2, , 3]);
184
+ encodedTx = Uint8Array.from(txRaw);
185
+ hexTx = "0x" + Buffer.from(encodedTx).toString("hex");
186
+ console.log("hexTx:" + hexTx);
187
+ queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
188
+ return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
189
+ case 1:
190
+ gas = _a.sent();
191
+ multiplier = 1.25;
192
+ return [2 /*return*/, Math.ceil(gas * multiplier)];
193
+ case 2:
194
+ error_3 = _a.sent();
195
+ FirmaUtil.printLog(error_3);
196
+ throw error_3;
197
+ case 3: return [2 /*return*/];
198
+ }
199
+ });
200
+ });
201
+ };
202
+ FirmaUtil.printLog = function (log) {
203
+ if (FirmaUtil.config.isShowLog === false)
204
+ return;
205
+ console.log("[FirmaSDK] " + log);
206
+ };
207
+ FirmaUtil.FctDecimal = 6;
208
+ return FirmaUtil;
209
+ }());
210
+ exports.FirmaUtil = FirmaUtil;