@firmachain/firma-js 0.2.21 → 0.2.25
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/README.md +19 -13
- package/dist/sdk/FirmaBankService.js +5 -5
- package/dist/sdk/FirmaConfig.d.ts +3 -1
- package/dist/sdk/FirmaConfig.js +24 -16
- package/dist/sdk/FirmaContractService.js +12 -12
- package/dist/sdk/FirmaDistributionService.js +20 -20
- package/dist/sdk/FirmaFeeGrantService.js +12 -12
- package/dist/sdk/FirmaGovService.js +29 -29
- package/dist/sdk/FirmaNftService.js +12 -12
- package/dist/sdk/FirmaStakingService.js +18 -18
- package/dist/sdk/FirmaTokenService.js +16 -16
- package/dist/sdk/FirmaUtil.d.ts +12 -1
- package/dist/sdk/FirmaUtil.js +28 -8
- package/dist/sdk/firmachain/common/TxCommon.d.ts +0 -7
- package/dist/sdk/firmachain/common/TxCommon.js +1 -17
- package/package.json +5 -4
|
@@ -44,7 +44,7 @@ var TokenService = /** @class */ (function () {
|
|
|
44
44
|
this.config = config;
|
|
45
45
|
}
|
|
46
46
|
TokenService.prototype.getGasEstimationCreateToken = function (wallet, tokenName, tokenSymbol, tokenURI, totalSupply, decimal, isMintable, isBurnable, txMisc) {
|
|
47
|
-
if (txMisc === void 0) { txMisc =
|
|
47
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
48
48
|
return __awaiter(this, void 0, void 0, function () {
|
|
49
49
|
var newTotalSupply, txRaw, error_1;
|
|
50
50
|
return __generator(this, function (_a) {
|
|
@@ -67,7 +67,7 @@ var TokenService = /** @class */ (function () {
|
|
|
67
67
|
});
|
|
68
68
|
};
|
|
69
69
|
TokenService.prototype.getGasEstimationMint = function (wallet, tokenID, amount, decimal, toAddress, txMisc) {
|
|
70
|
-
if (txMisc === void 0) { txMisc =
|
|
70
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
71
71
|
return __awaiter(this, void 0, void 0, function () {
|
|
72
72
|
var newAmount, txRaw, error_2;
|
|
73
73
|
return __generator(this, function (_a) {
|
|
@@ -90,7 +90,7 @@ var TokenService = /** @class */ (function () {
|
|
|
90
90
|
});
|
|
91
91
|
};
|
|
92
92
|
TokenService.prototype.getGasEstimationBurn = function (wallet, tokenID, amount, decimal, txMisc) {
|
|
93
|
-
if (txMisc === void 0) { txMisc =
|
|
93
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
94
94
|
return __awaiter(this, void 0, void 0, function () {
|
|
95
95
|
var newAmount, txRaw, error_3;
|
|
96
96
|
return __generator(this, function (_a) {
|
|
@@ -113,7 +113,7 @@ var TokenService = /** @class */ (function () {
|
|
|
113
113
|
});
|
|
114
114
|
};
|
|
115
115
|
TokenService.prototype.getGasEstimationUpdateTokenURI = function (wallet, tokenID, tokenURI, txMisc) {
|
|
116
|
-
if (txMisc === void 0) { txMisc =
|
|
116
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
117
117
|
return __awaiter(this, void 0, void 0, function () {
|
|
118
118
|
var txRaw, error_4;
|
|
119
119
|
return __generator(this, function (_a) {
|
|
@@ -135,7 +135,7 @@ var TokenService = /** @class */ (function () {
|
|
|
135
135
|
});
|
|
136
136
|
};
|
|
137
137
|
TokenService.prototype.getSignedTxUpdateTokenURI = function (wallet, tokenID, tokenURI, txMisc) {
|
|
138
|
-
if (txMisc === void 0) { txMisc =
|
|
138
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
139
139
|
return __awaiter(this, void 0, void 0, function () {
|
|
140
140
|
var address, txClient, message, error_5;
|
|
141
141
|
return __generator(this, function (_a) {
|
|
@@ -151,7 +151,7 @@ var TokenService = /** @class */ (function () {
|
|
|
151
151
|
tokenID: tokenID,
|
|
152
152
|
tokenURI: tokenURI
|
|
153
153
|
});
|
|
154
|
-
return [4 /*yield*/, txClient.sign([message],
|
|
154
|
+
return [4 /*yield*/, txClient.sign([message], FirmaUtil_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
|
|
155
155
|
case 2: return [2 /*return*/, _a.sent()];
|
|
156
156
|
case 3:
|
|
157
157
|
error_5 = _a.sent();
|
|
@@ -163,7 +163,7 @@ var TokenService = /** @class */ (function () {
|
|
|
163
163
|
});
|
|
164
164
|
};
|
|
165
165
|
TokenService.prototype.getSignedTxBurn = function (wallet, tokenID, amount, txMisc) {
|
|
166
|
-
if (txMisc === void 0) { txMisc =
|
|
166
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
167
167
|
return __awaiter(this, void 0, void 0, function () {
|
|
168
168
|
var address, txClient, message, error_6;
|
|
169
169
|
return __generator(this, function (_a) {
|
|
@@ -179,7 +179,7 @@ var TokenService = /** @class */ (function () {
|
|
|
179
179
|
tokenID: tokenID,
|
|
180
180
|
amount: amount
|
|
181
181
|
});
|
|
182
|
-
return [4 /*yield*/, txClient.sign([message],
|
|
182
|
+
return [4 /*yield*/, txClient.sign([message], FirmaUtil_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
|
|
183
183
|
case 2: return [2 /*return*/, _a.sent()];
|
|
184
184
|
case 3:
|
|
185
185
|
error_6 = _a.sent();
|
|
@@ -191,7 +191,7 @@ var TokenService = /** @class */ (function () {
|
|
|
191
191
|
});
|
|
192
192
|
};
|
|
193
193
|
TokenService.prototype.getSignedTxMint = function (wallet, tokenID, amount, toAddress, txMisc) {
|
|
194
|
-
if (txMisc === void 0) { txMisc =
|
|
194
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
195
195
|
return __awaiter(this, void 0, void 0, function () {
|
|
196
196
|
var address, txClient, message, error_7;
|
|
197
197
|
return __generator(this, function (_a) {
|
|
@@ -208,7 +208,7 @@ var TokenService = /** @class */ (function () {
|
|
|
208
208
|
amount: amount,
|
|
209
209
|
toAddress: toAddress
|
|
210
210
|
});
|
|
211
|
-
return [4 /*yield*/, txClient.sign([message],
|
|
211
|
+
return [4 /*yield*/, txClient.sign([message], FirmaUtil_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
|
|
212
212
|
case 2: return [2 /*return*/, _a.sent()];
|
|
213
213
|
case 3:
|
|
214
214
|
error_7 = _a.sent();
|
|
@@ -220,7 +220,7 @@ var TokenService = /** @class */ (function () {
|
|
|
220
220
|
});
|
|
221
221
|
};
|
|
222
222
|
TokenService.prototype.getSignedTxCreateToken = function (wallet, tokenName, tokenSymbol, tokenURI, totalSupply, decimal, isMintable, isBurnable, txMisc) {
|
|
223
|
-
if (txMisc === void 0) { txMisc =
|
|
223
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
224
224
|
return __awaiter(this, void 0, void 0, function () {
|
|
225
225
|
var address, txClient, message, error_8;
|
|
226
226
|
return __generator(this, function (_a) {
|
|
@@ -241,7 +241,7 @@ var TokenService = /** @class */ (function () {
|
|
|
241
241
|
mintable: isMintable,
|
|
242
242
|
burnable: isBurnable
|
|
243
243
|
});
|
|
244
|
-
return [4 /*yield*/, txClient.sign([message],
|
|
244
|
+
return [4 /*yield*/, txClient.sign([message], FirmaUtil_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
|
|
245
245
|
case 2: return [2 /*return*/, _a.sent()];
|
|
246
246
|
case 3:
|
|
247
247
|
error_8 = _a.sent();
|
|
@@ -254,7 +254,7 @@ var TokenService = /** @class */ (function () {
|
|
|
254
254
|
};
|
|
255
255
|
//./firmachaind tx token mint ukai 1000000 firma1jmg3kwy5hntx66nl93dyk2d92943394qsf6gcf --from alice --fees 2000ufct --chain-id imperium-2
|
|
256
256
|
TokenService.prototype.createToken = function (wallet, tokenName, tokenSymbol, tokenURI, totalSupply, decimal, isMintable, isBurnable, txMisc) {
|
|
257
|
-
if (txMisc === void 0) { txMisc =
|
|
257
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
258
258
|
return __awaiter(this, void 0, void 0, function () {
|
|
259
259
|
var newTotalSupply, txRaw, nftTxClient, error_9;
|
|
260
260
|
return __generator(this, function (_a) {
|
|
@@ -278,7 +278,7 @@ var TokenService = /** @class */ (function () {
|
|
|
278
278
|
});
|
|
279
279
|
};
|
|
280
280
|
TokenService.prototype.mint = function (wallet, tokenID, amount, decimal, toAddress, txMisc) {
|
|
281
|
-
if (txMisc === void 0) { txMisc =
|
|
281
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
282
282
|
return __awaiter(this, void 0, void 0, function () {
|
|
283
283
|
var newAmount, txRaw, nftTxClient, error_10;
|
|
284
284
|
return __generator(this, function (_a) {
|
|
@@ -302,7 +302,7 @@ var TokenService = /** @class */ (function () {
|
|
|
302
302
|
});
|
|
303
303
|
};
|
|
304
304
|
TokenService.prototype.burn = function (wallet, tokenID, amount, decimal, txMisc) {
|
|
305
|
-
if (txMisc === void 0) { txMisc =
|
|
305
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
306
306
|
return __awaiter(this, void 0, void 0, function () {
|
|
307
307
|
var newAmount, txRaw, nftTxClient, error_11;
|
|
308
308
|
return __generator(this, function (_a) {
|
|
@@ -326,7 +326,7 @@ var TokenService = /** @class */ (function () {
|
|
|
326
326
|
});
|
|
327
327
|
};
|
|
328
328
|
TokenService.prototype.updateTokenURI = function (wallet, tokenID, tokenURI, txMisc) {
|
|
329
|
-
if (txMisc === void 0) { txMisc =
|
|
329
|
+
if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
|
|
330
330
|
return __awaiter(this, void 0, void 0, function () {
|
|
331
331
|
var txRaw, nftTxClient, error_12;
|
|
332
332
|
return __generator(this, function (_a) {
|
package/dist/sdk/FirmaUtil.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
|
|
2
2
|
import { FirmaConfig } from "./FirmaConfig";
|
|
3
3
|
import { SignerData } from "./firmachain/common/LedgerSigningStargateClient";
|
|
4
|
+
import { SignAndBroadcastOptions, TxMisc } from "./firmachain/common";
|
|
4
5
|
export declare class FirmaUtil {
|
|
5
6
|
static config: FirmaConfig;
|
|
6
7
|
static readonly FctDecimal: number;
|
|
7
8
|
constructor(firmaConfig: FirmaConfig);
|
|
9
|
+
static getSignAndBroadcastOption(denom: string, txMisc: TxMisc): SignAndBroadcastOptions;
|
|
8
10
|
static getUTokenStringFromTokenStr(tokenAmount: string, decimal: number): string;
|
|
9
11
|
static getTokenStringFromUTokenStr(uTokenAmount: string, decimal: number): string;
|
|
10
12
|
static getUTokenStringFromToken(tokenAmount: number, decimal: number): string;
|
|
@@ -15,7 +17,9 @@ export declare class FirmaUtil {
|
|
|
15
17
|
static getUFCTStringFromFCT(fctAmount: number): string;
|
|
16
18
|
static getFCTStringFromUFCT(uFctAmount: number): string;
|
|
17
19
|
static getFileHash(filePath: string): Promise<string>;
|
|
18
|
-
static getFileHashFromBuffer(buffer: Uint8Array):
|
|
20
|
+
static getFileHashFromBuffer(buffer: Uint8Array): string;
|
|
21
|
+
static getSha1HashFromString(text: string): string;
|
|
22
|
+
static getHashFromString(text: string): string;
|
|
19
23
|
static isValidAddress(address: string): boolean;
|
|
20
24
|
static getValOperAddressFromAccAddress(address: string): string;
|
|
21
25
|
static getAccAddressFromValOperAddress(address: string): string;
|
|
@@ -24,3 +28,10 @@ export declare class FirmaUtil {
|
|
|
24
28
|
static estimateGasRaw(txRaw: Uint8Array): Promise<number>;
|
|
25
29
|
static printLog(log: any): void;
|
|
26
30
|
}
|
|
31
|
+
export declare const DefaultTxMisc: {
|
|
32
|
+
memo: string;
|
|
33
|
+
fee: number;
|
|
34
|
+
gas: number;
|
|
35
|
+
feeGranter: string;
|
|
36
|
+
};
|
|
37
|
+
export declare const getSignAndBroadcastOption: typeof FirmaUtil.getSignAndBroadcastOption;
|
package/dist/sdk/FirmaUtil.js
CHANGED
|
@@ -36,19 +36,34 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.FirmaUtil = void 0;
|
|
39
|
+
exports.getSignAndBroadcastOption = exports.DefaultTxMisc = exports.FirmaUtil = void 0;
|
|
40
40
|
var fs_1 = require("fs");
|
|
41
41
|
var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
|
|
42
42
|
var TendermintQueryClient_1 = require("./firmachain/common/TendermintQueryClient");
|
|
43
43
|
var encoding_1 = require("@cosmjs/encoding");
|
|
44
44
|
var LedgerSigningStargateClient_1 = require("./firmachain/common/LedgerSigningStargateClient");
|
|
45
45
|
var CryptoJS = require("crypto-js");
|
|
46
|
+
var sha1 = require("crypto-js/sha1");
|
|
46
47
|
var sha256 = require("crypto-js/sha256");
|
|
47
48
|
var encHex = require("crypto-js/enc-hex");
|
|
48
49
|
var FirmaUtil = /** @class */ (function () {
|
|
49
50
|
function FirmaUtil(firmaConfig) {
|
|
50
51
|
FirmaUtil.config = firmaConfig;
|
|
51
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
|
+
};
|
|
52
67
|
FirmaUtil.getUTokenStringFromTokenStr = function (tokenAmount, decimal) {
|
|
53
68
|
var fct = Number.parseFloat(tokenAmount);
|
|
54
69
|
var decimalMutiplyer = Math.pow(10, decimal);
|
|
@@ -101,13 +116,16 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
101
116
|
});
|
|
102
117
|
};
|
|
103
118
|
FirmaUtil.getFileHashFromBuffer = function (buffer) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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);
|
|
111
129
|
};
|
|
112
130
|
FirmaUtil.isValidAddress = function (address) {
|
|
113
131
|
try {
|
|
@@ -208,3 +226,5 @@ var FirmaUtil = /** @class */ (function () {
|
|
|
208
226
|
return FirmaUtil;
|
|
209
227
|
}());
|
|
210
228
|
exports.FirmaUtil = FirmaUtil;
|
|
229
|
+
exports.DefaultTxMisc = { memo: "", fee: 0, gas: 0, feeGranter: "" };
|
|
230
|
+
exports.getSignAndBroadcastOption = FirmaUtil.getSignAndBroadcastOption;
|
|
@@ -28,13 +28,6 @@ export interface TxMisc {
|
|
|
28
28
|
gas?: number;
|
|
29
29
|
feeGranter?: string;
|
|
30
30
|
}
|
|
31
|
-
export declare function getSignAndBroadcastOption(denom: string, txMisc?: TxMisc): SignAndBroadcastOptions;
|
|
32
|
-
export declare const DefaultTxMisc: {
|
|
33
|
-
memo: string;
|
|
34
|
-
fee: number;
|
|
35
|
-
gas: number;
|
|
36
|
-
feeGranter: string;
|
|
37
|
-
};
|
|
38
31
|
export interface SignAndBroadcastOptions {
|
|
39
32
|
fee: StdFee;
|
|
40
33
|
memo: string;
|
|
@@ -1,23 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VotingOption = exports.
|
|
3
|
+
exports.VotingOption = exports.DefaultBasicFeeGrantOption = void 0;
|
|
4
4
|
exports.DefaultBasicFeeGrantOption = { spendLimit: undefined, expiration: undefined };
|
|
5
|
-
function getSignAndBroadcastOption(denom, txMisc) {
|
|
6
|
-
if (txMisc === void 0) { txMisc = exports.DefaultTxMisc; }
|
|
7
|
-
if (txMisc.memo == null)
|
|
8
|
-
txMisc.memo = "";
|
|
9
|
-
if (txMisc.fee == null)
|
|
10
|
-
txMisc.fee = 200000;
|
|
11
|
-
if (txMisc.gas == null)
|
|
12
|
-
txMisc.gas = 200000;
|
|
13
|
-
if (txMisc.feeGranter == null)
|
|
14
|
-
txMisc.feeGranter = "";
|
|
15
|
-
var gasFeeAmount = { denom: denom, amount: txMisc.fee.toString() };
|
|
16
|
-
var defaultFee = { amount: [gasFeeAmount], gas: txMisc.gas.toString(), granter: txMisc.feeGranter };
|
|
17
|
-
return { fee: defaultFee, memo: txMisc.memo };
|
|
18
|
-
}
|
|
19
|
-
exports.getSignAndBroadcastOption = getSignAndBroadcastOption;
|
|
20
|
-
exports.DefaultTxMisc = { memo: "", fee: 200000, gas: 200000, feeGranter: "" };
|
|
21
5
|
var VotingOption;
|
|
22
6
|
(function (VotingOption) {
|
|
23
7
|
/** VOTE_OPTION_UNSPECIFIED - VOTE_OPTION_UNSPECIFIED defines a no-op vote option. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firmachain/firma-js",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.25",
|
|
4
4
|
"description": "The Official FirmaChain Javascript SDK written in Typescript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"test": "mocha test/**/*.test.ts -r ts-node/register --timeout
|
|
11
|
+
"test": "mocha test/**/*.test.ts -r ts-node/register --timeout 1200000",
|
|
12
12
|
"lint": "eslint src test --ext .ts,.tsx",
|
|
13
13
|
"nodemon": "nodemon",
|
|
14
14
|
"dev": "ts-node ./test/test_index.ts",
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"cosmjs-types": "^0.2.0",
|
|
41
41
|
"crypto-js": "^4.1.1",
|
|
42
42
|
"ipfs-http-client": "^52.0.5",
|
|
43
|
-
"protobufjs": "^6.10.2"
|
|
43
|
+
"protobufjs": "^6.10.2",
|
|
44
|
+
"readline-sync": "^1.4.10"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@types/chai": "^4.2.21",
|
|
@@ -52,4 +53,4 @@
|
|
|
52
53
|
"ts-node": "^10.2.1",
|
|
53
54
|
"typescript": "^4.3.5"
|
|
54
55
|
}
|
|
55
|
-
}
|
|
56
|
+
}
|