@firmachain/firma-js 0.2.26 → 0.2.27

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 (155) hide show
  1. package/package.json +1 -1
  2. package/dist/index.d.ts +0 -4
  3. package/dist/index.js +0 -16
  4. package/dist/sdk/FirmaBankService.d.ts +0 -15
  5. package/dist/sdk/FirmaBankService.js +0 -211
  6. package/dist/sdk/FirmaChainService.d.ts +0 -8
  7. package/dist/sdk/FirmaChainService.js +0 -86
  8. package/dist/sdk/FirmaConfig.d.ts +0 -18
  9. package/dist/sdk/FirmaConfig.js +0 -63
  10. package/dist/sdk/FirmaContractService.d.ts +0 -31
  11. package/dist/sdk/FirmaContractService.js +0 -413
  12. package/dist/sdk/FirmaDistributionService.d.ts +0 -31
  13. package/dist/sdk/FirmaDistributionService.js +0 -524
  14. package/dist/sdk/FirmaFeeGrantService.d.ts +0 -21
  15. package/dist/sdk/FirmaFeeGrantService.js +0 -341
  16. package/dist/sdk/FirmaGovService.d.ts +0 -35
  17. package/dist/sdk/FirmaGovService.js +0 -775
  18. package/dist/sdk/FirmaIpfsService.d.ts +0 -12
  19. package/dist/sdk/FirmaIpfsService.js +0 -185
  20. package/dist/sdk/FirmaMobileSDK.d.ts +0 -27
  21. package/dist/sdk/FirmaMobileSDK.js +0 -45
  22. package/dist/sdk/FirmaNftService.d.ts +0 -31
  23. package/dist/sdk/FirmaNftService.js +0 -372
  24. package/dist/sdk/FirmaSDK.d.ts +0 -29
  25. package/dist/sdk/FirmaSDK.js +0 -48
  26. package/dist/sdk/FirmaSlashingService.d.ts +0 -9
  27. package/dist/sdk/FirmaSlashingService.js +0 -105
  28. package/dist/sdk/FirmaStakingService.d.ts +0 -34
  29. package/dist/sdk/FirmaStakingService.js +0 -604
  30. package/dist/sdk/FirmaTokenService.d.ts +0 -26
  31. package/dist/sdk/FirmaTokenService.js +0 -416
  32. package/dist/sdk/FirmaUtil.d.ts +0 -37
  33. package/dist/sdk/FirmaUtil.js +0 -230
  34. package/dist/sdk/FirmaWalletService.d.ts +0 -36
  35. package/dist/sdk/FirmaWalletService.js +0 -309
  36. package/dist/sdk/firmachain/amino/addresses.d.ts +0 -5
  37. package/dist/sdk/firmachain/amino/addresses.js +0 -46
  38. package/dist/sdk/firmachain/amino/aminomsgs.d.ts +0 -281
  39. package/dist/sdk/firmachain/amino/aminomsgs.js +0 -77
  40. package/dist/sdk/firmachain/amino/aminotypes.d.ts +0 -22
  41. package/dist/sdk/firmachain/amino/aminotypes.js +0 -521
  42. package/dist/sdk/firmachain/amino/coins.d.ts +0 -30
  43. package/dist/sdk/firmachain/amino/coins.js +0 -69
  44. package/dist/sdk/firmachain/amino/encoding.d.ts +0 -24
  45. package/dist/sdk/firmachain/amino/encoding.js +0 -234
  46. package/dist/sdk/firmachain/amino/multisig.d.ts +0 -10
  47. package/dist/sdk/firmachain/amino/multisig.js +0 -42
  48. package/dist/sdk/firmachain/amino/paths.d.ts +0 -6
  49. package/dist/sdk/firmachain/amino/paths.js +0 -18
  50. package/dist/sdk/firmachain/amino/pubkeys.d.ts +0 -47
  51. package/dist/sdk/firmachain/amino/pubkeys.js +0 -29
  52. package/dist/sdk/firmachain/amino/secp256k1hdwallet.d.ts +0 -94
  53. package/dist/sdk/firmachain/amino/secp256k1hdwallet.js +0 -437
  54. package/dist/sdk/firmachain/amino/secp256k1wallet.d.ts +0 -23
  55. package/dist/sdk/firmachain/amino/secp256k1wallet.js +0 -141
  56. package/dist/sdk/firmachain/amino/signature.d.ts +0 -16
  57. package/dist/sdk/firmachain/amino/signature.js +0 -36
  58. package/dist/sdk/firmachain/amino/signdoc.d.ts +0 -26
  59. package/dist/sdk/firmachain/amino/signdoc.js +0 -42
  60. package/dist/sdk/firmachain/amino/signer.d.ts +0 -33
  61. package/dist/sdk/firmachain/amino/signer.js +0 -2
  62. package/dist/sdk/firmachain/amino/stdtx.d.ts +0 -15
  63. package/dist/sdk/firmachain/amino/stdtx.js +0 -17
  64. package/dist/sdk/firmachain/amino/wallet.d.ts +0 -32
  65. package/dist/sdk/firmachain/amino/wallet.js +0 -132
  66. package/dist/sdk/firmachain/bank/BankQueryClient.d.ts +0 -12
  67. package/dist/sdk/firmachain/bank/BankQueryClient.js +0 -116
  68. package/dist/sdk/firmachain/bank/BankTxClient.d.ts +0 -17
  69. package/dist/sdk/firmachain/bank/BankTxClient.js +0 -40
  70. package/dist/sdk/firmachain/bank/index.d.ts +0 -3
  71. package/dist/sdk/firmachain/bank/index.js +0 -15
  72. package/dist/sdk/firmachain/common/ITxClient.d.ts +0 -15
  73. package/dist/sdk/firmachain/common/ITxClient.js +0 -102
  74. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +0 -27
  75. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +0 -165
  76. package/dist/sdk/firmachain/common/LedgerWallet.d.ts +0 -14
  77. package/dist/sdk/firmachain/common/LedgerWallet.js +0 -147
  78. package/dist/sdk/firmachain/common/QueryCommon.d.ts +0 -4
  79. package/dist/sdk/firmachain/common/QueryCommon.js +0 -2
  80. package/dist/sdk/firmachain/common/TendermintQueryClient.d.ts +0 -42
  81. package/dist/sdk/firmachain/common/TendermintQueryClient.js +0 -111
  82. package/dist/sdk/firmachain/common/TxCommon.d.ts +0 -87
  83. package/dist/sdk/firmachain/common/TxCommon.js +0 -18
  84. package/dist/sdk/firmachain/common/accounts.d.ts +0 -16
  85. package/dist/sdk/firmachain/common/accounts.js +0 -64
  86. package/dist/sdk/firmachain/common/index.d.ts +0 -2
  87. package/dist/sdk/firmachain/common/index.js +0 -14
  88. package/dist/sdk/firmachain/common/signing.d.ts +0 -10
  89. package/dist/sdk/firmachain/common/signing.js +0 -75
  90. package/dist/sdk/firmachain/common/signingstargateclient.d.ts +0 -37
  91. package/dist/sdk/firmachain/common/signingstargateclient.js +0 -298
  92. package/dist/sdk/firmachain/common/stargateclient.d.ts +0 -46
  93. package/dist/sdk/firmachain/common/stargateclient.js +0 -211
  94. package/dist/sdk/firmachain/contract/ContractQueryClient.d.ts +0 -32
  95. package/dist/sdk/firmachain/contract/ContractQueryClient.js +0 -156
  96. package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +0 -17
  97. package/dist/sdk/firmachain/contract/ContractTxClient.js +0 -40
  98. package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +0 -69
  99. package/dist/sdk/firmachain/contract/ContractTxTypes.js +0 -483
  100. package/dist/sdk/firmachain/contract/index.d.ts +0 -3
  101. package/dist/sdk/firmachain/contract/index.js +0 -15
  102. package/dist/sdk/firmachain/distribution/DistributionQueryClient.d.ts +0 -18
  103. package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +0 -167
  104. package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +0 -27
  105. package/dist/sdk/firmachain/distribution/DistributionTxClient.js +0 -48
  106. package/dist/sdk/firmachain/distribution/index.d.ts +0 -3
  107. package/dist/sdk/firmachain/distribution/index.js +0 -15
  108. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.d.ts +0 -17
  109. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +0 -86
  110. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +0 -17
  111. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +0 -40
  112. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +0 -76
  113. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +0 -194
  114. package/dist/sdk/firmachain/feegrant/index.d.ts +0 -2
  115. package/dist/sdk/firmachain/feegrant/index.js +0 -15
  116. package/dist/sdk/firmachain/google/protobuf/any.d.ts +0 -128
  117. package/dist/sdk/firmachain/google/protobuf/any.js +0 -106
  118. package/dist/sdk/firmachain/google/protobuf/descriptor.d.ts +0 -996
  119. package/dist/sdk/firmachain/google/protobuf/descriptor.js +0 -5329
  120. package/dist/sdk/firmachain/google/protobuf/duration.d.ts +0 -91
  121. package/dist/sdk/firmachain/google/protobuf/duration.js +0 -107
  122. package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +0 -109
  123. package/dist/sdk/firmachain/google/protobuf/timestamp.js +0 -107
  124. package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +0 -61
  125. package/dist/sdk/firmachain/gov/GovQueryClient.js +0 -152
  126. package/dist/sdk/firmachain/gov/GovTxClient.d.ts +0 -22
  127. package/dist/sdk/firmachain/gov/GovTxClient.js +0 -44
  128. package/dist/sdk/firmachain/gov/index.d.ts +0 -3
  129. package/dist/sdk/firmachain/gov/index.js +0 -15
  130. package/dist/sdk/firmachain/nft/NftQueryClient.d.ts +0 -20
  131. package/dist/sdk/firmachain/nft/NftQueryClient.js +0 -125
  132. package/dist/sdk/firmachain/nft/NftTxClient.d.ts +0 -22
  133. package/dist/sdk/firmachain/nft/NftTxClient.js +0 -44
  134. package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +0 -86
  135. package/dist/sdk/firmachain/nft/NftTxTypes.js +0 -424
  136. package/dist/sdk/firmachain/nft/index.d.ts +0 -3
  137. package/dist/sdk/firmachain/nft/index.js +0 -15
  138. package/dist/sdk/firmachain/slashing/SlashingQueryClient.d.ts +0 -22
  139. package/dist/sdk/firmachain/slashing/SlashingQueryClient.js +0 -101
  140. package/dist/sdk/firmachain/slashing/index.d.ts +0 -2
  141. package/dist/sdk/firmachain/slashing/index.js +0 -14
  142. package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +0 -93
  143. package/dist/sdk/firmachain/staking/StakingQueryClient.js +0 -223
  144. package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +0 -32
  145. package/dist/sdk/firmachain/staking/StakingTxClient.js +0 -52
  146. package/dist/sdk/firmachain/staking/index.d.ts +0 -3
  147. package/dist/sdk/firmachain/staking/index.js +0 -15
  148. package/dist/sdk/firmachain/token/TokenQueryClient.d.ts +0 -24
  149. package/dist/sdk/firmachain/token/TokenQueryClient.js +0 -106
  150. package/dist/sdk/firmachain/token/TokenTxClient.d.ts +0 -27
  151. package/dist/sdk/firmachain/token/TokenTxClient.js +0 -48
  152. package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +0 -116
  153. package/dist/sdk/firmachain/token/TokenTxTypes.js +0 -685
  154. package/dist/sdk/firmachain/token/index.d.ts +0 -3
  155. package/dist/sdk/firmachain/token/index.js +0 -15
@@ -1,230 +0,0 @@
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.getSignAndBroadcastOption = exports.DefaultTxMisc = 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 sha1 = require("crypto-js/sha1");
47
- var sha256 = require("crypto-js/sha256");
48
- var encHex = require("crypto-js/enc-hex");
49
- var FirmaUtil = /** @class */ (function () {
50
- function FirmaUtil(firmaConfig) {
51
- FirmaUtil.config = firmaConfig;
52
- }
53
- FirmaUtil.getSignAndBroadcastOption = function (denom, txMisc) {
54
- if (txMisc.memo == null)
55
- txMisc.memo = "";
56
- // INFO: if fee or gas data is not set default, those value will be null. So we have to double check it.
57
- if (txMisc.fee == 0 || txMisc.fee == null)
58
- txMisc.fee = FirmaUtil.config.defaultFee;
59
- if (txMisc.gas == 0 || txMisc.gas == null)
60
- txMisc.gas = FirmaUtil.config.defaultGas;
61
- if (txMisc.feeGranter == null)
62
- txMisc.feeGranter = "";
63
- var gasFeeAmount = { denom: denom, amount: txMisc.fee.toString() };
64
- var defaultFee = { amount: [gasFeeAmount], gas: txMisc.gas.toString(), granter: txMisc.feeGranter };
65
- return { fee: defaultFee, memo: txMisc.memo };
66
- };
67
- FirmaUtil.getUTokenStringFromTokenStr = function (tokenAmount, decimal) {
68
- var fct = Number.parseFloat(tokenAmount);
69
- var decimalMutiplyer = Math.pow(10, decimal);
70
- var big = fct * decimalMutiplyer;
71
- return big.toString();
72
- };
73
- FirmaUtil.getTokenStringFromUTokenStr = function (uTokenAmount, decimal) {
74
- var ufct = Number.parseInt(uTokenAmount);
75
- var decimalMutiplyer = Math.pow(10, decimal);
76
- return (ufct / decimalMutiplyer).toString();
77
- };
78
- FirmaUtil.getUTokenStringFromToken = function (tokenAmount, decimal) {
79
- var decimalMutiplyer = Math.pow(10, decimal);
80
- var big = tokenAmount * decimalMutiplyer;
81
- return big.toString();
82
- };
83
- FirmaUtil.getUTokenFromToken = function (tokenAmount, decimal) {
84
- var decimalMutiplyer = Math.pow(10, decimal);
85
- var big = tokenAmount * decimalMutiplyer;
86
- return big;
87
- };
88
- FirmaUtil.getTokenStringFromUToken = function (uTokenAmount, decimal) {
89
- var decimalMutiplyer = Math.pow(10, decimal);
90
- return (uTokenAmount / decimalMutiplyer).toString();
91
- };
92
- FirmaUtil.getUFCTStringFromFCTStr = function (fctAmount) {
93
- return this.getUTokenStringFromTokenStr(fctAmount, this.FctDecimal);
94
- };
95
- FirmaUtil.getFCTStringFromUFCTStr = function (uFctAmount) {
96
- return this.getTokenStringFromUTokenStr(uFctAmount, this.FctDecimal);
97
- };
98
- FirmaUtil.getUFCTStringFromFCT = function (fctAmount) {
99
- return this.getUTokenStringFromToken(fctAmount, this.FctDecimal);
100
- };
101
- FirmaUtil.getFCTStringFromUFCT = function (uFctAmount) {
102
- return this.getTokenStringFromUToken(uFctAmount, this.FctDecimal);
103
- };
104
- FirmaUtil.getFileHash = function (filePath) {
105
- return __awaiter(this, void 0, void 0, function () {
106
- var fileData, data;
107
- return __generator(this, function (_a) {
108
- switch (_a.label) {
109
- case 0: return [4 /*yield*/, fs_1.promises.readFile(filePath)];
110
- case 1:
111
- fileData = _a.sent();
112
- data = CryptoJS.lib.WordArray.create(fileData.buffer);
113
- return [2 /*return*/, sha256(data).toString(encHex)];
114
- }
115
- });
116
- });
117
- };
118
- FirmaUtil.getFileHashFromBuffer = function (buffer) {
119
- var data = CryptoJS.lib.WordArray.create(buffer);
120
- return sha256(data).toString(encHex);
121
- };
122
- FirmaUtil.getSha1HashFromString = function (text) {
123
- var data = CryptoJS.lib.WordArray.create(text);
124
- return sha1(data).toString(encHex);
125
- };
126
- FirmaUtil.getHashFromString = function (text) {
127
- var data = CryptoJS.lib.WordArray.create(text);
128
- return sha256(data).toString(encHex);
129
- };
130
- FirmaUtil.isValidAddress = function (address) {
131
- try {
132
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
133
- encoding_1.Bech32.decode(address).data;
134
- return true;
135
- }
136
- catch (e) {
137
- }
138
- return false;
139
- };
140
- FirmaUtil.getValOperAddressFromAccAddress = function (address) {
141
- var data = encoding_1.Bech32.decode(address).data;
142
- return encoding_1.Bech32.encode(FirmaUtil.config.prefix + "valoper", data);
143
- };
144
- FirmaUtil.getAccAddressFromValOperAddress = function (address) {
145
- var data = encoding_1.Bech32.decode(address).data;
146
- return encoding_1.Bech32.encode(FirmaUtil.config.prefix, data);
147
- };
148
- FirmaUtil.getSignerDataForLedger = function (address) {
149
- return __awaiter(this, void 0, void 0, function () {
150
- var signingClient, sequence, error_1;
151
- return __generator(this, function (_a) {
152
- switch (_a.label) {
153
- case 0:
154
- _a.trys.push([0, 3, , 4]);
155
- return [4 /*yield*/, LedgerSigningStargateClient_1.LedgerSigningStargateClient.connectWithSigner(FirmaUtil.config.rpcAddress)];
156
- case 1:
157
- signingClient = _a.sent();
158
- return [4 /*yield*/, signingClient.getSignerData(address)];
159
- case 2:
160
- sequence = _a.sent();
161
- return [2 /*return*/, sequence];
162
- case 3:
163
- error_1 = _a.sent();
164
- FirmaUtil.printLog(error_1);
165
- throw error_1;
166
- case 4: return [2 /*return*/];
167
- }
168
- });
169
- });
170
- };
171
- FirmaUtil.estimateGas = function (txRaw) {
172
- return __awaiter(this, void 0, void 0, function () {
173
- var encodedTx, hexTx, queryClient, gas, multiplier, error_2;
174
- return __generator(this, function (_a) {
175
- switch (_a.label) {
176
- case 0:
177
- _a.trys.push([0, 2, , 3]);
178
- encodedTx = Uint8Array.from(tx_1.TxRaw.encode(txRaw).finish());
179
- hexTx = "0x" + Buffer.from(encodedTx).toString("hex");
180
- queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
181
- return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
182
- case 1:
183
- gas = _a.sent();
184
- multiplier = 1.25;
185
- return [2 /*return*/, Math.ceil(gas * multiplier)];
186
- case 2:
187
- error_2 = _a.sent();
188
- FirmaUtil.printLog(error_2);
189
- throw error_2;
190
- case 3: return [2 /*return*/];
191
- }
192
- });
193
- });
194
- };
195
- FirmaUtil.estimateGasRaw = function (txRaw) {
196
- return __awaiter(this, void 0, void 0, function () {
197
- var encodedTx, hexTx, queryClient, gas, multiplier, error_3;
198
- return __generator(this, function (_a) {
199
- switch (_a.label) {
200
- case 0:
201
- _a.trys.push([0, 2, , 3]);
202
- encodedTx = Uint8Array.from(txRaw);
203
- hexTx = "0x" + Buffer.from(encodedTx).toString("hex");
204
- console.log("hexTx:" + hexTx);
205
- queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
206
- return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
207
- case 1:
208
- gas = _a.sent();
209
- multiplier = 1.25;
210
- return [2 /*return*/, Math.ceil(gas * multiplier)];
211
- case 2:
212
- error_3 = _a.sent();
213
- FirmaUtil.printLog(error_3);
214
- throw error_3;
215
- case 3: return [2 /*return*/];
216
- }
217
- });
218
- });
219
- };
220
- FirmaUtil.printLog = function (log) {
221
- if (FirmaUtil.config.isShowLog === false)
222
- return;
223
- console.log("[FirmaSDK] " + log);
224
- };
225
- FirmaUtil.FctDecimal = 6;
226
- return FirmaUtil;
227
- }());
228
- exports.FirmaUtil = FirmaUtil;
229
- exports.DefaultTxMisc = { memo: "", fee: 0, gas: 0, feeGranter: "" };
230
- exports.getSignAndBroadcastOption = FirmaUtil.getSignAndBroadcastOption;
@@ -1,36 +0,0 @@
1
- import { DirectSecp256k1Wallet, Registry } from "@cosmjs/proto-signing";
2
- import { EncodeObject } from "@cosmjs/proto-signing";
3
- import { FirmaConfig } from "./FirmaConfig";
4
- import { SignAndBroadcastOptions } from "./firmachain/common";
5
- import { LedgerWalletInterface } from "./firmachain/common/LedgerWallet";
6
- import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
7
- export declare class FirmaWalletService {
8
- private readonly config;
9
- private mnemonic;
10
- private privateKey;
11
- private accountIndex;
12
- private wallet;
13
- private ledger;
14
- getHdPath(): string;
15
- getPrefix(): string;
16
- getRawWallet(): DirectSecp256k1Wallet;
17
- getPrivateKey(): string;
18
- getMnemonic(): string;
19
- isLedger(): boolean;
20
- initFromLedger(ledger: LedgerWalletInterface): Promise<FirmaWalletService>;
21
- signLedger(messages: EncodeObject[], option: SignAndBroadcastOptions, registry: Registry): Promise<TxRaw>;
22
- getAddress(): Promise<string>;
23
- constructor(config: FirmaConfig);
24
- private static getHdPath;
25
- initFromMnemonic(mnemonic: string, accountIndex?: number): Promise<{
26
- success: boolean;
27
- }>;
28
- private getPrivateKeyInternal;
29
- initFromPrivateKey(privateKey: string): Promise<void>;
30
- decryptData(data: string): string;
31
- encryptData(data: string): string;
32
- newWallet(): Promise<FirmaWalletService>;
33
- fromMnemonic(mnemonic: string, accountIndex?: number): Promise<FirmaWalletService>;
34
- fromPrivateKey(privateKey: string): Promise<FirmaWalletService>;
35
- generateMnemonic(): Promise<string>;
36
- }
@@ -1,309 +0,0 @@
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.FirmaWalletService = void 0;
40
- var proto_signing_1 = require("@cosmjs/proto-signing");
41
- var crypto_1 = require("@cosmjs/crypto");
42
- var FirmaUtil_1 = require("./FirmaUtil");
43
- var LedgerWallet_1 = require("./firmachain/common/LedgerWallet");
44
- var CryptoJS = require("crypto-js");
45
- var FirmaWalletService = /** @class */ (function () {
46
- function FirmaWalletService(config) {
47
- this.config = config;
48
- this.mnemonic = "";
49
- this.privateKey = "";
50
- this.accountIndex = 0;
51
- }
52
- FirmaWalletService.prototype.getHdPath = function () {
53
- return this.config.hdPath;
54
- };
55
- FirmaWalletService.prototype.getPrefix = function () {
56
- return this.config.prefix;
57
- };
58
- FirmaWalletService.prototype.getRawWallet = function () {
59
- return this.wallet;
60
- };
61
- FirmaWalletService.prototype.getPrivateKey = function () {
62
- return this.privateKey;
63
- };
64
- FirmaWalletService.prototype.getMnemonic = function () {
65
- return this.mnemonic;
66
- };
67
- FirmaWalletService.prototype.isLedger = function () {
68
- return (this.ledger != null);
69
- };
70
- FirmaWalletService.prototype.initFromLedger = function (ledger) {
71
- return __awaiter(this, void 0, void 0, function () {
72
- var wallet;
73
- return __generator(this, function (_a) {
74
- try {
75
- wallet = new FirmaWalletService(this.config);
76
- wallet.ledger = ledger;
77
- return [2 /*return*/, wallet];
78
- }
79
- catch (error) {
80
- FirmaUtil_1.FirmaUtil.printLog(error);
81
- throw error;
82
- }
83
- return [2 /*return*/];
84
- });
85
- });
86
- };
87
- FirmaWalletService.prototype.signLedger = function (messages, option, registry) {
88
- return __awaiter(this, void 0, void 0, function () {
89
- return __generator(this, function (_a) {
90
- switch (_a.label) {
91
- case 0: return [4 /*yield*/, LedgerWallet_1.signFromLedger(this.ledger, messages, option, registry)];
92
- case 1: return [2 /*return*/, _a.sent()];
93
- }
94
- });
95
- });
96
- };
97
- FirmaWalletService.prototype.getAddress = function () {
98
- return __awaiter(this, void 0, void 0, function () {
99
- var accounts, error_1;
100
- return __generator(this, function (_a) {
101
- switch (_a.label) {
102
- case 0:
103
- _a.trys.push([0, 4, , 5]);
104
- if (!(this.ledger != null)) return [3 /*break*/, 2];
105
- return [4 /*yield*/, this.ledger.getAddress()];
106
- case 1: return [2 /*return*/, _a.sent()];
107
- case 2: return [4 /*yield*/, this.wallet.getAccounts()];
108
- case 3:
109
- accounts = _a.sent();
110
- return [2 /*return*/, accounts[0].address];
111
- case 4:
112
- error_1 = _a.sent();
113
- FirmaUtil_1.FirmaUtil.printLog(error_1);
114
- throw error_1;
115
- case 5: return [2 /*return*/];
116
- }
117
- });
118
- });
119
- };
120
- FirmaWalletService.getHdPath = function (hdPath, accountIndex) {
121
- try {
122
- return [crypto_1.stringToPath(hdPath + accountIndex + "'/0/0")];
123
- }
124
- catch (error) {
125
- FirmaUtil_1.FirmaUtil.printLog(error);
126
- throw error;
127
- }
128
- };
129
- FirmaWalletService.prototype.initFromMnemonic = function (mnemonic, accountIndex) {
130
- if (accountIndex === void 0) { accountIndex = 0; }
131
- return __awaiter(this, void 0, void 0, function () {
132
- var privateKey, error_2;
133
- return __generator(this, function (_a) {
134
- switch (_a.label) {
135
- case 0:
136
- _a.trys.push([0, 3, , 4]);
137
- this.mnemonic = mnemonic;
138
- this.accountIndex = accountIndex;
139
- return [4 /*yield*/, this.getPrivateKeyInternal(this.mnemonic, this.accountIndex)];
140
- case 1:
141
- privateKey = _a.sent();
142
- return [4 /*yield*/, this.initFromPrivateKey(privateKey)];
143
- case 2:
144
- _a.sent();
145
- return [2 /*return*/, { success: true }];
146
- case 3:
147
- error_2 = _a.sent();
148
- FirmaUtil_1.FirmaUtil.printLog(error_2);
149
- throw error_2;
150
- case 4: return [2 /*return*/];
151
- }
152
- });
153
- });
154
- };
155
- FirmaWalletService.prototype.getPrivateKeyInternal = function (mnemonic, accountIndex) {
156
- return __awaiter(this, void 0, void 0, function () {
157
- var mnemonicChecked, seed, hdpath, privkey, privateKey, error_3;
158
- return __generator(this, function (_a) {
159
- switch (_a.label) {
160
- case 0:
161
- _a.trys.push([0, 2, , 3]);
162
- mnemonicChecked = new crypto_1.EnglishMnemonic(mnemonic);
163
- return [4 /*yield*/, crypto_1.Bip39.mnemonicToSeed(mnemonicChecked)];
164
- case 1:
165
- seed = _a.sent();
166
- hdpath = FirmaWalletService.getHdPath(this.getHdPath(), this.accountIndex);
167
- privkey = crypto_1.Slip10.derivePath(crypto_1.Slip10Curve.Secp256k1, seed, hdpath[0]).privkey;
168
- privateKey = "0x" + Buffer.from(privkey).toString("hex");
169
- return [2 /*return*/, privateKey];
170
- case 2:
171
- error_3 = _a.sent();
172
- FirmaUtil_1.FirmaUtil.printLog(error_3);
173
- throw error_3;
174
- case 3: return [2 /*return*/];
175
- }
176
- });
177
- });
178
- };
179
- FirmaWalletService.prototype.initFromPrivateKey = function (privateKey) {
180
- return __awaiter(this, void 0, void 0, function () {
181
- var tempPrivateKey, _a, error_4;
182
- return __generator(this, function (_b) {
183
- switch (_b.label) {
184
- case 0:
185
- _b.trys.push([0, 2, , 3]);
186
- tempPrivateKey = Buffer.from(privateKey.replace("0x", ""), "hex");
187
- _a = this;
188
- return [4 /*yield*/, proto_signing_1.DirectSecp256k1Wallet.fromKey(tempPrivateKey, this.getPrefix())];
189
- case 1:
190
- _a.wallet = _b.sent();
191
- this.privateKey = privateKey;
192
- return [3 /*break*/, 3];
193
- case 2:
194
- error_4 = _b.sent();
195
- FirmaUtil_1.FirmaUtil.printLog(error_4);
196
- throw error_4;
197
- case 3: return [2 /*return*/];
198
- }
199
- });
200
- });
201
- };
202
- FirmaWalletService.prototype.decryptData = function (data) {
203
- try {
204
- var bytes = CryptoJS.AES.decrypt(data, this.getPrivateKey());
205
- return bytes.toString(CryptoJS.enc.Utf8);
206
- }
207
- catch (error) {
208
- FirmaUtil_1.FirmaUtil.printLog(error);
209
- throw error;
210
- }
211
- };
212
- FirmaWalletService.prototype.encryptData = function (data) {
213
- try {
214
- return CryptoJS.AES.encrypt(data, this.getPrivateKey()).toString();
215
- }
216
- catch (error) {
217
- FirmaUtil_1.FirmaUtil.printLog(error);
218
- throw error;
219
- }
220
- };
221
- FirmaWalletService.prototype.newWallet = function () {
222
- return __awaiter(this, void 0, void 0, function () {
223
- var mnemonic, wallet, error_5;
224
- return __generator(this, function (_a) {
225
- switch (_a.label) {
226
- case 0:
227
- _a.trys.push([0, 3, , 4]);
228
- return [4 /*yield*/, this.generateMnemonic()];
229
- case 1:
230
- mnemonic = _a.sent();
231
- return [4 /*yield*/, this.fromMnemonic(mnemonic)];
232
- case 2:
233
- wallet = _a.sent();
234
- return [2 /*return*/, wallet];
235
- case 3:
236
- error_5 = _a.sent();
237
- FirmaUtil_1.FirmaUtil.printLog(error_5);
238
- throw error_5;
239
- case 4: return [2 /*return*/];
240
- }
241
- });
242
- });
243
- };
244
- FirmaWalletService.prototype.fromMnemonic = function (mnemonic, accountIndex) {
245
- if (accountIndex === void 0) { accountIndex = 0; }
246
- return __awaiter(this, void 0, void 0, function () {
247
- var wallet, error_6;
248
- return __generator(this, function (_a) {
249
- switch (_a.label) {
250
- case 0:
251
- _a.trys.push([0, 2, , 3]);
252
- wallet = new FirmaWalletService(this.config);
253
- return [4 /*yield*/, wallet.initFromMnemonic(mnemonic, accountIndex)];
254
- case 1:
255
- _a.sent();
256
- return [2 /*return*/, wallet];
257
- case 2:
258
- error_6 = _a.sent();
259
- FirmaUtil_1.FirmaUtil.printLog(error_6);
260
- throw error_6;
261
- case 3: return [2 /*return*/];
262
- }
263
- });
264
- });
265
- };
266
- FirmaWalletService.prototype.fromPrivateKey = function (privateKey) {
267
- return __awaiter(this, void 0, void 0, function () {
268
- var wallet, error_7;
269
- return __generator(this, function (_a) {
270
- switch (_a.label) {
271
- case 0:
272
- _a.trys.push([0, 2, , 3]);
273
- wallet = new FirmaWalletService(this.config);
274
- return [4 /*yield*/, wallet.initFromPrivateKey(privateKey)];
275
- case 1:
276
- _a.sent();
277
- return [2 /*return*/, wallet];
278
- case 2:
279
- error_7 = _a.sent();
280
- FirmaUtil_1.FirmaUtil.printLog(error_7);
281
- throw error_7;
282
- case 3: return [2 /*return*/];
283
- }
284
- });
285
- });
286
- };
287
- FirmaWalletService.prototype.generateMnemonic = function () {
288
- return __awaiter(this, void 0, void 0, function () {
289
- var wallet, error_8;
290
- return __generator(this, function (_a) {
291
- switch (_a.label) {
292
- case 0:
293
- _a.trys.push([0, 2, , 3]);
294
- return [4 /*yield*/, proto_signing_1.DirectSecp256k1HdWallet.generate(24)];
295
- case 1:
296
- wallet = _a.sent();
297
- return [2 /*return*/, wallet.mnemonic];
298
- case 2:
299
- error_8 = _a.sent();
300
- FirmaUtil_1.FirmaUtil.printLog(error_8);
301
- throw error_8;
302
- case 3: return [2 /*return*/];
303
- }
304
- });
305
- });
306
- };
307
- return FirmaWalletService;
308
- }());
309
- exports.FirmaWalletService = FirmaWalletService;
@@ -1,5 +0,0 @@
1
- import { Pubkey } from "./pubkeys";
2
- export declare function rawEd25519PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8Array;
3
- export declare function rawSecp256k1PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8Array;
4
- export declare function pubkeyToRawAddress(pubkey: Pubkey): Uint8Array;
5
- export declare function pubkeyToAddress(pubkey: Pubkey, prefix: string): string;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- // See https://github.com/tendermint/tendermint/blob/f2ada0a604b4c0763bda2f64fac53d506d3beca7/docs/spec/blockchain/encoding.md#public-key-cryptography
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.pubkeyToAddress = exports.pubkeyToRawAddress = exports.rawSecp256k1PubkeyToRawAddress = exports.rawEd25519PubkeyToRawAddress = void 0;
5
- var crypto_1 = require("@cosmjs/crypto");
6
- var encoding_1 = require("@cosmjs/encoding");
7
- var encoding_2 = require("./encoding");
8
- var pubkeys_1 = require("./pubkeys");
9
- function rawEd25519PubkeyToRawAddress(pubkeyData) {
10
- if (pubkeyData.length !== 32) {
11
- throw new Error("Invalid Ed25519 pubkey length: " + pubkeyData.length);
12
- }
13
- return crypto_1.sha256(pubkeyData).slice(0, 20);
14
- }
15
- exports.rawEd25519PubkeyToRawAddress = rawEd25519PubkeyToRawAddress;
16
- function rawSecp256k1PubkeyToRawAddress(pubkeyData) {
17
- if (pubkeyData.length !== 33) {
18
- throw new Error("Invalid Secp256k1 pubkey length (compressed): " + pubkeyData.length);
19
- }
20
- return crypto_1.ripemd160(crypto_1.sha256(pubkeyData));
21
- }
22
- exports.rawSecp256k1PubkeyToRawAddress = rawSecp256k1PubkeyToRawAddress;
23
- // For secp256k1 this assumes we already have a compressed pubkey.
24
- function pubkeyToRawAddress(pubkey) {
25
- if (pubkeys_1.isSecp256k1Pubkey(pubkey)) {
26
- var pubkeyData = encoding_1.fromBase64(pubkey.value);
27
- return rawSecp256k1PubkeyToRawAddress(pubkeyData);
28
- }
29
- else if (pubkeys_1.isEd25519Pubkey(pubkey)) {
30
- var pubkeyData = encoding_1.fromBase64(pubkey.value);
31
- return rawEd25519PubkeyToRawAddress(pubkeyData);
32
- }
33
- else if (pubkeys_1.isMultisigThresholdPubkey(pubkey)) {
34
- // https://github.com/tendermint/tendermint/blob/38b401657e4ad7a7eeb3c30a3cbf512037df3740/crypto/multisig/threshold_pubkey.go#L71-L74
35
- var pubkeyData = encoding_2.encodeAminoPubkey(pubkey);
36
- return crypto_1.sha256(pubkeyData).slice(0, 20);
37
- }
38
- else {
39
- throw new Error("Unsupported public key type");
40
- }
41
- }
42
- exports.pubkeyToRawAddress = pubkeyToRawAddress;
43
- function pubkeyToAddress(pubkey, prefix) {
44
- return encoding_1.Bech32.encode(prefix, pubkeyToRawAddress(pubkey));
45
- }
46
- exports.pubkeyToAddress = pubkeyToAddress;