@firmachain/firma-js 0.2.18 → 0.2.22
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.
- package/LICENSE +20 -20
- package/README.md +136 -136
- package/dist/index.d.ts +4 -4
- package/dist/index.js +16 -16
- package/dist/sdk/FirmaBankService.d.ts +15 -15
- package/dist/sdk/FirmaBankService.js +211 -211
- package/dist/sdk/FirmaChainService.d.ts +8 -8
- package/dist/sdk/FirmaChainService.js +86 -86
- package/dist/sdk/FirmaConfig.d.ts +18 -16
- package/dist/sdk/FirmaConfig.js +63 -55
- package/dist/sdk/FirmaContractService.d.ts +31 -30
- package/dist/sdk/FirmaContractService.js +413 -394
- package/dist/sdk/FirmaDistributionService.d.ts +31 -31
- package/dist/sdk/FirmaDistributionService.js +524 -524
- package/dist/sdk/FirmaFeeGrantService.d.ts +21 -21
- package/dist/sdk/FirmaFeeGrantService.js +341 -341
- package/dist/sdk/FirmaGovService.d.ts +35 -35
- package/dist/sdk/FirmaGovService.js +775 -775
- package/dist/sdk/FirmaIpfsService.d.ts +12 -12
- package/dist/sdk/FirmaIpfsService.js +185 -185
- package/dist/sdk/FirmaMobileSDK.d.ts +27 -27
- package/dist/sdk/FirmaMobileSDK.js +45 -45
- package/dist/sdk/FirmaNftService.d.ts +31 -28
- package/dist/sdk/FirmaNftService.js +372 -390
- package/dist/sdk/FirmaSDK.d.ts +29 -29
- package/dist/sdk/FirmaSDK.js +48 -48
- package/dist/sdk/FirmaSlashingService.d.ts +9 -9
- package/dist/sdk/FirmaSlashingService.js +105 -105
- package/dist/sdk/FirmaStakingService.d.ts +34 -34
- package/dist/sdk/FirmaStakingService.js +604 -604
- package/dist/sdk/FirmaTokenService.d.ts +26 -26
- package/dist/sdk/FirmaTokenService.js +416 -416
- package/dist/sdk/FirmaUtil.d.ts +35 -25
- package/dist/sdk/FirmaUtil.js +226 -201
- package/dist/sdk/FirmaWalletService.d.ts +36 -40
- package/dist/sdk/FirmaWalletService.js +309 -309
- package/dist/sdk/firmachain/amino/addresses.d.ts +5 -5
- package/dist/sdk/firmachain/amino/addresses.js +46 -46
- package/dist/sdk/firmachain/amino/aminomsgs.d.ts +281 -281
- package/dist/sdk/firmachain/amino/aminomsgs.js +77 -77
- package/dist/sdk/firmachain/amino/aminotypes.d.ts +22 -22
- package/dist/sdk/firmachain/amino/aminotypes.js +521 -521
- package/dist/sdk/firmachain/amino/coins.d.ts +30 -30
- package/dist/sdk/firmachain/amino/coins.js +69 -69
- package/dist/sdk/firmachain/amino/encoding.d.ts +24 -24
- package/dist/sdk/firmachain/amino/encoding.js +234 -234
- package/dist/sdk/firmachain/amino/multisig.d.ts +10 -10
- package/dist/sdk/firmachain/amino/multisig.js +42 -42
- package/dist/sdk/firmachain/amino/paths.d.ts +6 -6
- package/dist/sdk/firmachain/amino/paths.js +18 -18
- package/dist/sdk/firmachain/amino/pubkeys.d.ts +47 -47
- package/dist/sdk/firmachain/amino/pubkeys.js +29 -29
- package/dist/sdk/firmachain/amino/secp256k1hdwallet.d.ts +94 -94
- package/dist/sdk/firmachain/amino/secp256k1hdwallet.js +437 -437
- package/dist/sdk/firmachain/amino/secp256k1wallet.d.ts +23 -23
- package/dist/sdk/firmachain/amino/secp256k1wallet.js +141 -141
- package/dist/sdk/firmachain/amino/signature.d.ts +16 -16
- package/dist/sdk/firmachain/amino/signature.js +36 -36
- package/dist/sdk/firmachain/amino/signdoc.d.ts +26 -26
- package/dist/sdk/firmachain/amino/signdoc.js +42 -42
- package/dist/sdk/firmachain/amino/signer.d.ts +33 -33
- package/dist/sdk/firmachain/amino/signer.js +2 -2
- package/dist/sdk/firmachain/amino/stdtx.d.ts +15 -15
- package/dist/sdk/firmachain/amino/stdtx.js +17 -17
- package/dist/sdk/firmachain/amino/wallet.d.ts +32 -32
- package/dist/sdk/firmachain/amino/wallet.js +132 -132
- package/dist/sdk/firmachain/bank/BankQueryClient.d.ts +12 -12
- package/dist/sdk/firmachain/bank/BankQueryClient.js +116 -116
- package/dist/sdk/firmachain/bank/BankTxClient.d.ts +17 -17
- package/dist/sdk/firmachain/bank/BankTxClient.js +40 -40
- package/dist/sdk/firmachain/bank/index.d.ts +3 -3
- package/dist/sdk/firmachain/bank/index.js +15 -15
- package/dist/sdk/firmachain/common/ITxClient.d.ts +15 -15
- package/dist/sdk/firmachain/common/ITxClient.js +102 -102
- package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +27 -27
- package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +165 -165
- package/dist/sdk/firmachain/common/LedgerWallet.d.ts +14 -9
- package/dist/sdk/firmachain/common/LedgerWallet.js +147 -150
- package/dist/sdk/firmachain/common/QueryCommon.d.ts +4 -4
- package/dist/sdk/firmachain/common/QueryCommon.js +2 -2
- package/dist/sdk/firmachain/common/TendermintQueryClient.d.ts +42 -42
- package/dist/sdk/firmachain/common/TendermintQueryClient.js +108 -108
- package/dist/sdk/firmachain/common/TxCommon.d.ts +87 -94
- package/dist/sdk/firmachain/common/TxCommon.js +18 -34
- package/dist/sdk/firmachain/common/accounts.d.ts +16 -16
- package/dist/sdk/firmachain/common/accounts.js +64 -64
- package/dist/sdk/firmachain/common/index.d.ts +2 -2
- package/dist/sdk/firmachain/common/index.js +14 -14
- package/dist/sdk/firmachain/common/signing.d.ts +10 -10
- package/dist/sdk/firmachain/common/signing.js +75 -75
- package/dist/sdk/firmachain/common/signingstargateclient.d.ts +37 -37
- package/dist/sdk/firmachain/common/signingstargateclient.js +298 -298
- package/dist/sdk/firmachain/common/stargateclient.d.ts +46 -46
- package/dist/sdk/firmachain/common/stargateclient.js +211 -211
- package/dist/sdk/firmachain/contract/ContractQueryClient.d.ts +32 -31
- package/dist/sdk/firmachain/contract/ContractQueryClient.js +156 -141
- package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +17 -17
- package/dist/sdk/firmachain/contract/ContractTxClient.js +40 -40
- package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +69 -69
- package/dist/sdk/firmachain/contract/ContractTxTypes.js +483 -483
- package/dist/sdk/firmachain/contract/index.d.ts +3 -3
- package/dist/sdk/firmachain/contract/index.js +15 -15
- package/dist/sdk/firmachain/distribution/DistributionQueryClient.d.ts +18 -18
- package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +167 -167
- package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +27 -27
- package/dist/sdk/firmachain/distribution/DistributionTxClient.js +48 -48
- package/dist/sdk/firmachain/distribution/index.d.ts +3 -3
- package/dist/sdk/firmachain/distribution/index.js +15 -15
- package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.d.ts +17 -17
- package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +86 -86
- package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +17 -17
- package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +40 -40
- package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +76 -76
- package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +194 -194
- package/dist/sdk/firmachain/feegrant/index.d.ts +2 -2
- package/dist/sdk/firmachain/feegrant/index.js +15 -15
- package/dist/sdk/firmachain/google/protobuf/any.d.ts +128 -128
- package/dist/sdk/firmachain/google/protobuf/any.js +106 -106
- package/dist/sdk/firmachain/google/protobuf/descriptor.d.ts +996 -996
- package/dist/sdk/firmachain/google/protobuf/descriptor.js +5329 -5329
- package/dist/sdk/firmachain/google/protobuf/duration.d.ts +91 -91
- package/dist/sdk/firmachain/google/protobuf/duration.js +107 -107
- package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +109 -109
- package/dist/sdk/firmachain/google/protobuf/timestamp.js +107 -107
- package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +61 -61
- package/dist/sdk/firmachain/gov/GovQueryClient.js +152 -152
- package/dist/sdk/firmachain/gov/GovTxClient.d.ts +22 -22
- package/dist/sdk/firmachain/gov/GovTxClient.js +44 -44
- package/dist/sdk/firmachain/gov/index.d.ts +3 -3
- package/dist/sdk/firmachain/gov/index.js +15 -15
- package/dist/sdk/firmachain/nft/NftQueryClient.d.ts +20 -17
- package/dist/sdk/firmachain/nft/NftQueryClient.js +125 -121
- package/dist/sdk/firmachain/nft/NftTxClient.d.ts +22 -22
- package/dist/sdk/firmachain/nft/NftTxClient.js +44 -44
- package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +86 -86
- package/dist/sdk/firmachain/nft/NftTxTypes.js +424 -424
- package/dist/sdk/firmachain/nft/index.d.ts +3 -3
- package/dist/sdk/firmachain/nft/index.js +15 -15
- package/dist/sdk/firmachain/slashing/SlashingQueryClient.d.ts +22 -22
- package/dist/sdk/firmachain/slashing/SlashingQueryClient.js +101 -101
- package/dist/sdk/firmachain/slashing/index.d.ts +2 -2
- package/dist/sdk/firmachain/slashing/index.js +14 -14
- package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +93 -93
- package/dist/sdk/firmachain/staking/StakingQueryClient.js +223 -223
- package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +32 -32
- package/dist/sdk/firmachain/staking/StakingTxClient.js +52 -52
- package/dist/sdk/firmachain/staking/index.d.ts +3 -3
- package/dist/sdk/firmachain/staking/index.js +15 -15
- package/dist/sdk/firmachain/token/TokenQueryClient.d.ts +24 -24
- package/dist/sdk/firmachain/token/TokenQueryClient.js +106 -106
- package/dist/sdk/firmachain/token/TokenTxClient.d.ts +27 -27
- package/dist/sdk/firmachain/token/TokenTxClient.js +48 -48
- package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +116 -116
- package/dist/sdk/firmachain/token/TokenTxTypes.js +685 -685
- package/dist/sdk/firmachain/token/index.d.ts +3 -3
- package/dist/sdk/firmachain/token/index.js +15 -15
- package/package.json +54 -54
package/dist/sdk/FirmaUtil.d.ts
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
|
-
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
2
|
-
import { FirmaConfig } from "./FirmaConfig";
|
|
3
|
-
import { SignerData } from "./firmachain/common/LedgerSigningStargateClient";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
static
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
static
|
|
10
|
-
static
|
|
11
|
-
static
|
|
12
|
-
static
|
|
13
|
-
static
|
|
14
|
-
static
|
|
15
|
-
static
|
|
16
|
-
static
|
|
17
|
-
static
|
|
18
|
-
static
|
|
19
|
-
static
|
|
20
|
-
static
|
|
21
|
-
static
|
|
22
|
-
static
|
|
23
|
-
static
|
|
24
|
-
static
|
|
25
|
-
|
|
1
|
+
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
2
|
+
import { FirmaConfig } from "./FirmaConfig";
|
|
3
|
+
import { SignerData } from "./firmachain/common/LedgerSigningStargateClient";
|
|
4
|
+
import { SignAndBroadcastOptions, TxMisc } from "./firmachain/common";
|
|
5
|
+
export declare class FirmaUtil {
|
|
6
|
+
static config: FirmaConfig;
|
|
7
|
+
static readonly FctDecimal: number;
|
|
8
|
+
constructor(firmaConfig: FirmaConfig);
|
|
9
|
+
static getSignAndBroadcastOption(denom: string, txMisc: TxMisc): SignAndBroadcastOptions;
|
|
10
|
+
static getUTokenStringFromTokenStr(tokenAmount: string, decimal: number): string;
|
|
11
|
+
static getTokenStringFromUTokenStr(uTokenAmount: string, decimal: number): string;
|
|
12
|
+
static getUTokenStringFromToken(tokenAmount: number, decimal: number): string;
|
|
13
|
+
static getUTokenFromToken(tokenAmount: number, decimal: number): number;
|
|
14
|
+
static getTokenStringFromUToken(uTokenAmount: number, decimal: number): string;
|
|
15
|
+
static getUFCTStringFromFCTStr(fctAmount: string): string;
|
|
16
|
+
static getFCTStringFromUFCTStr(uFctAmount: string): string;
|
|
17
|
+
static getUFCTStringFromFCT(fctAmount: number): string;
|
|
18
|
+
static getFCTStringFromUFCT(uFctAmount: number): string;
|
|
19
|
+
static getFileHash(filePath: string): Promise<string>;
|
|
20
|
+
static getFileHashFromBuffer(buffer: Uint8Array): Promise<string>;
|
|
21
|
+
static isValidAddress(address: string): boolean;
|
|
22
|
+
static getValOperAddressFromAccAddress(address: string): string;
|
|
23
|
+
static getAccAddressFromValOperAddress(address: string): string;
|
|
24
|
+
static getSignerDataForLedger(address: string): Promise<SignerData>;
|
|
25
|
+
static estimateGas(txRaw: TxRaw): Promise<number>;
|
|
26
|
+
static estimateGasRaw(txRaw: Uint8Array): Promise<number>;
|
|
27
|
+
static printLog(log: any): void;
|
|
28
|
+
}
|
|
29
|
+
export declare const DefaultTxMisc: {
|
|
30
|
+
memo: string;
|
|
31
|
+
fee: number;
|
|
32
|
+
gas: number;
|
|
33
|
+
feeGranter: string;
|
|
34
|
+
};
|
|
35
|
+
export declare const getSignAndBroadcastOption: typeof FirmaUtil.getSignAndBroadcastOption;
|
package/dist/sdk/FirmaUtil.js
CHANGED
|
@@ -1,201 +1,226 @@
|
|
|
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.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
var decimalMutiplyer = Math.pow(10, decimal);
|
|
75
|
-
return (
|
|
76
|
-
};
|
|
77
|
-
FirmaUtil.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
};
|
|
103
|
-
FirmaUtil.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
};
|
|
117
|
-
FirmaUtil.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
};
|
|
144
|
-
FirmaUtil.
|
|
145
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
-
var
|
|
147
|
-
return __generator(this, function (_a) {
|
|
148
|
-
switch (_a.label) {
|
|
149
|
-
case 0:
|
|
150
|
-
_a.trys.push([0,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return [4 /*yield*/,
|
|
155
|
-
case
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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 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.getSignAndBroadcastOption = function (denom, txMisc) {
|
|
53
|
+
if (txMisc.memo == null)
|
|
54
|
+
txMisc.memo = "";
|
|
55
|
+
// INFO: if fee or gas data is not set default, those value will be null. So we have to double check it.
|
|
56
|
+
if (txMisc.fee == 0 || txMisc.fee == null)
|
|
57
|
+
txMisc.fee = FirmaUtil.config.defaultFee;
|
|
58
|
+
if (txMisc.gas == 0 || txMisc.gas == null)
|
|
59
|
+
txMisc.gas = FirmaUtil.config.defaultGas;
|
|
60
|
+
if (txMisc.feeGranter == null)
|
|
61
|
+
txMisc.feeGranter = "";
|
|
62
|
+
var gasFeeAmount = { denom: denom, amount: txMisc.fee.toString() };
|
|
63
|
+
var defaultFee = { amount: [gasFeeAmount], gas: txMisc.gas.toString(), granter: txMisc.feeGranter };
|
|
64
|
+
return { fee: defaultFee, memo: txMisc.memo };
|
|
65
|
+
};
|
|
66
|
+
FirmaUtil.getUTokenStringFromTokenStr = function (tokenAmount, decimal) {
|
|
67
|
+
var fct = Number.parseFloat(tokenAmount);
|
|
68
|
+
var decimalMutiplyer = Math.pow(10, decimal);
|
|
69
|
+
var big = fct * decimalMutiplyer;
|
|
70
|
+
return big.toString();
|
|
71
|
+
};
|
|
72
|
+
FirmaUtil.getTokenStringFromUTokenStr = function (uTokenAmount, decimal) {
|
|
73
|
+
var ufct = Number.parseInt(uTokenAmount);
|
|
74
|
+
var decimalMutiplyer = Math.pow(10, decimal);
|
|
75
|
+
return (ufct / decimalMutiplyer).toString();
|
|
76
|
+
};
|
|
77
|
+
FirmaUtil.getUTokenStringFromToken = function (tokenAmount, decimal) {
|
|
78
|
+
var decimalMutiplyer = Math.pow(10, decimal);
|
|
79
|
+
var big = tokenAmount * decimalMutiplyer;
|
|
80
|
+
return big.toString();
|
|
81
|
+
};
|
|
82
|
+
FirmaUtil.getUTokenFromToken = function (tokenAmount, decimal) {
|
|
83
|
+
var decimalMutiplyer = Math.pow(10, decimal);
|
|
84
|
+
var big = tokenAmount * decimalMutiplyer;
|
|
85
|
+
return big;
|
|
86
|
+
};
|
|
87
|
+
FirmaUtil.getTokenStringFromUToken = function (uTokenAmount, decimal) {
|
|
88
|
+
var decimalMutiplyer = Math.pow(10, decimal);
|
|
89
|
+
return (uTokenAmount / decimalMutiplyer).toString();
|
|
90
|
+
};
|
|
91
|
+
FirmaUtil.getUFCTStringFromFCTStr = function (fctAmount) {
|
|
92
|
+
return this.getUTokenStringFromTokenStr(fctAmount, this.FctDecimal);
|
|
93
|
+
};
|
|
94
|
+
FirmaUtil.getFCTStringFromUFCTStr = function (uFctAmount) {
|
|
95
|
+
return this.getTokenStringFromUTokenStr(uFctAmount, this.FctDecimal);
|
|
96
|
+
};
|
|
97
|
+
FirmaUtil.getUFCTStringFromFCT = function (fctAmount) {
|
|
98
|
+
return this.getUTokenStringFromToken(fctAmount, this.FctDecimal);
|
|
99
|
+
};
|
|
100
|
+
FirmaUtil.getFCTStringFromUFCT = function (uFctAmount) {
|
|
101
|
+
return this.getTokenStringFromUToken(uFctAmount, this.FctDecimal);
|
|
102
|
+
};
|
|
103
|
+
FirmaUtil.getFileHash = function (filePath) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
+
var fileData, data;
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
switch (_a.label) {
|
|
108
|
+
case 0: return [4 /*yield*/, fs_1.promises.readFile(filePath)];
|
|
109
|
+
case 1:
|
|
110
|
+
fileData = _a.sent();
|
|
111
|
+
data = CryptoJS.lib.WordArray.create(fileData.buffer);
|
|
112
|
+
return [2 /*return*/, sha256(data).toString(encHex)];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
FirmaUtil.getFileHashFromBuffer = function (buffer) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
+
var data;
|
|
120
|
+
return __generator(this, function (_a) {
|
|
121
|
+
data = CryptoJS.lib.WordArray.create(buffer);
|
|
122
|
+
return [2 /*return*/, sha256(data).toString(encHex)];
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
FirmaUtil.isValidAddress = function (address) {
|
|
127
|
+
try {
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
129
|
+
encoding_1.Bech32.decode(address).data;
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
};
|
|
136
|
+
FirmaUtil.getValOperAddressFromAccAddress = function (address) {
|
|
137
|
+
var data = encoding_1.Bech32.decode(address).data;
|
|
138
|
+
return encoding_1.Bech32.encode(FirmaUtil.config.prefix + "valoper", data);
|
|
139
|
+
};
|
|
140
|
+
FirmaUtil.getAccAddressFromValOperAddress = function (address) {
|
|
141
|
+
var data = encoding_1.Bech32.decode(address).data;
|
|
142
|
+
return encoding_1.Bech32.encode(FirmaUtil.config.prefix, data);
|
|
143
|
+
};
|
|
144
|
+
FirmaUtil.getSignerDataForLedger = function (address) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
var signingClient, sequence, error_1;
|
|
147
|
+
return __generator(this, function (_a) {
|
|
148
|
+
switch (_a.label) {
|
|
149
|
+
case 0:
|
|
150
|
+
_a.trys.push([0, 3, , 4]);
|
|
151
|
+
return [4 /*yield*/, LedgerSigningStargateClient_1.LedgerSigningStargateClient.connectWithSigner(FirmaUtil.config.rpcAddress)];
|
|
152
|
+
case 1:
|
|
153
|
+
signingClient = _a.sent();
|
|
154
|
+
return [4 /*yield*/, signingClient.getSignerData(address)];
|
|
155
|
+
case 2:
|
|
156
|
+
sequence = _a.sent();
|
|
157
|
+
return [2 /*return*/, sequence];
|
|
158
|
+
case 3:
|
|
159
|
+
error_1 = _a.sent();
|
|
160
|
+
FirmaUtil.printLog(error_1);
|
|
161
|
+
throw error_1;
|
|
162
|
+
case 4: return [2 /*return*/];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
FirmaUtil.estimateGas = function (txRaw) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
169
|
+
var encodedTx, hexTx, queryClient, gas, multiplier, error_2;
|
|
170
|
+
return __generator(this, function (_a) {
|
|
171
|
+
switch (_a.label) {
|
|
172
|
+
case 0:
|
|
173
|
+
_a.trys.push([0, 2, , 3]);
|
|
174
|
+
encodedTx = Uint8Array.from(tx_1.TxRaw.encode(txRaw).finish());
|
|
175
|
+
hexTx = "0x" + Buffer.from(encodedTx).toString("hex");
|
|
176
|
+
queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
|
|
177
|
+
return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
|
|
178
|
+
case 1:
|
|
179
|
+
gas = _a.sent();
|
|
180
|
+
multiplier = 1.25;
|
|
181
|
+
return [2 /*return*/, Math.ceil(gas * multiplier)];
|
|
182
|
+
case 2:
|
|
183
|
+
error_2 = _a.sent();
|
|
184
|
+
FirmaUtil.printLog(error_2);
|
|
185
|
+
throw error_2;
|
|
186
|
+
case 3: return [2 /*return*/];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
FirmaUtil.estimateGasRaw = function (txRaw) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
+
var encodedTx, hexTx, queryClient, gas, multiplier, error_3;
|
|
194
|
+
return __generator(this, function (_a) {
|
|
195
|
+
switch (_a.label) {
|
|
196
|
+
case 0:
|
|
197
|
+
_a.trys.push([0, 2, , 3]);
|
|
198
|
+
encodedTx = Uint8Array.from(txRaw);
|
|
199
|
+
hexTx = "0x" + Buffer.from(encodedTx).toString("hex");
|
|
200
|
+
console.log("hexTx:" + hexTx);
|
|
201
|
+
queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
|
|
202
|
+
return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
|
|
203
|
+
case 1:
|
|
204
|
+
gas = _a.sent();
|
|
205
|
+
multiplier = 1.25;
|
|
206
|
+
return [2 /*return*/, Math.ceil(gas * multiplier)];
|
|
207
|
+
case 2:
|
|
208
|
+
error_3 = _a.sent();
|
|
209
|
+
FirmaUtil.printLog(error_3);
|
|
210
|
+
throw error_3;
|
|
211
|
+
case 3: return [2 /*return*/];
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
FirmaUtil.printLog = function (log) {
|
|
217
|
+
if (FirmaUtil.config.isShowLog === false)
|
|
218
|
+
return;
|
|
219
|
+
console.log("[FirmaSDK] " + log);
|
|
220
|
+
};
|
|
221
|
+
FirmaUtil.FctDecimal = 6;
|
|
222
|
+
return FirmaUtil;
|
|
223
|
+
}());
|
|
224
|
+
exports.FirmaUtil = FirmaUtil;
|
|
225
|
+
exports.DefaultTxMisc = { memo: "", fee: 0, gas: 0, feeGranter: "" };
|
|
226
|
+
exports.getSignAndBroadcastOption = FirmaUtil.getSignAndBroadcastOption;
|
|
@@ -1,40 +1,36 @@
|
|
|
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 {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
fromMnemonic(mnemonic: string, accountIndex?: number): Promise<FirmaWalletService>;
|
|
38
|
-
fromPrivateKey(privateKey: string): Promise<FirmaWalletService>;
|
|
39
|
-
generateMnemonic(): Promise<string>;
|
|
40
|
-
}
|
|
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
|
+
}
|