@firmachain/firma-js 0.2.30 → 0.2.31

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 (33) hide show
  1. package/dist/sdk/FirmaAuthzService.d.ts +32 -0
  2. package/dist/sdk/FirmaAuthzService.js +630 -0
  3. package/dist/sdk/FirmaBankService.d.ts +2 -1
  4. package/dist/sdk/FirmaBankService.js +3 -0
  5. package/dist/sdk/FirmaCosmWasmService.d.ts +38 -0
  6. package/dist/sdk/FirmaCosmWasmService.js +667 -0
  7. package/dist/sdk/FirmaDistributionService.d.ts +2 -1
  8. package/dist/sdk/FirmaDistributionService.js +3 -0
  9. package/dist/sdk/FirmaMobileSDK.d.ts +3 -1
  10. package/dist/sdk/FirmaMobileSDK.js +4 -1
  11. package/dist/sdk/FirmaSDK.d.ts +5 -1
  12. package/dist/sdk/FirmaSDK.js +7 -1
  13. package/dist/sdk/FirmaStakingService.d.ts +2 -1
  14. package/dist/sdk/FirmaStakingService.js +3 -0
  15. package/dist/sdk/FirmaUtil.d.ts +1 -0
  16. package/dist/sdk/FirmaUtil.js +3 -0
  17. package/dist/sdk/firmachain/authz/AuthzQueryClient.d.ts +38 -0
  18. package/dist/sdk/firmachain/authz/AuthzQueryClient.js +115 -0
  19. package/dist/sdk/firmachain/authz/AuthzTxClient.d.ts +22 -0
  20. package/dist/sdk/firmachain/authz/AuthzTxClient.js +44 -0
  21. package/dist/sdk/firmachain/authz/AuthzTxTypes.d.ts +147 -0
  22. package/dist/sdk/firmachain/authz/AuthzTxTypes.js +358 -0
  23. package/dist/sdk/firmachain/authz/index.d.ts +3 -0
  24. package/dist/sdk/firmachain/authz/index.js +15 -0
  25. package/dist/sdk/firmachain/common/ITxClient.d.ts +3 -0
  26. package/dist/sdk/firmachain/common/ITxClient.js +9 -0
  27. package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.d.ts +52 -0
  28. package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.js +193 -0
  29. package/dist/sdk/firmachain/cosmwasm/CosmWasmTxClient.d.ts +37 -0
  30. package/dist/sdk/firmachain/cosmwasm/CosmWasmTxClient.js +56 -0
  31. package/dist/sdk/firmachain/cosmwasm/index.d.ts +3 -0
  32. package/dist/sdk/firmachain/cosmwasm/index.js +15 -0
  33. package/package.json +4 -2
@@ -0,0 +1,32 @@
1
+ import { FirmaWalletService } from "./FirmaWalletService";
2
+ import { FirmaConfig } from "./FirmaConfig";
3
+ import { BroadcastTxResponse } from "./firmachain/common/stargateclient";
4
+ import { Any } from "./firmachain/google/protobuf/any";
5
+ import { GrantGenericData, GrantSendData, GrantStakingData, TxMisc } from "./firmachain/authz";
6
+ import { AuthorizationType } from "./firmachain/authz/AuthzTxTypes";
7
+ export declare class FirmaAuthzService {
8
+ private readonly config;
9
+ constructor(config: FirmaConfig);
10
+ private getSignedTxGrantSendAutorization;
11
+ private getSignedTxGrantStakeAutorization;
12
+ private getSignedTxGrantGenericAuthorization;
13
+ private getSignedTxRevokeGenericAuthorization;
14
+ private getSignedTxExecuteAllowance;
15
+ getGasEstimationGrantSendAuthorization(wallet: FirmaWalletService, granteeAddress: string, expirationDate: Date, maxTokens: number, txMisc?: TxMisc): Promise<number>;
16
+ grantSendAuthorization(wallet: FirmaWalletService, granteeAddress: string, expirationDate: Date, maxTokens: number, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
17
+ getGasEstimationGrantStakeAuthorization(wallet: FirmaWalletService, granteeAddress: string, validatorAddress: string, type: AuthorizationType, expirationDate: Date, maxTokens?: number, txMisc?: TxMisc): Promise<number>;
18
+ grantStakeAuthorization(wallet: FirmaWalletService, granteeAddress: string, validatorAddress: string, type: AuthorizationType, expirationDate: Date, maxTokens?: number, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
19
+ getGasEstimationGrantGenericAuthorization(wallet: FirmaWalletService, granteeAddress: string, msg: string, expirationDate: Date, txMisc?: TxMisc): Promise<number>;
20
+ grantGenericAuthorization(wallet: FirmaWalletService, granteeAddress: string, msg: string, expirationDate: Date, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
21
+ getGasEstimationRevokeGenericAuthorization(wallet: FirmaWalletService, granteeAddress: string, msgType: string, txMisc?: TxMisc): Promise<number>;
22
+ revokeGenericAuthorization(wallet: FirmaWalletService, granteeAddress: string, msgType: string, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
23
+ getGasEstimationRevokeSendAuthorization(wallet: FirmaWalletService, granteeAddress: string, txMisc?: TxMisc): Promise<number>;
24
+ revokeSendAuthorization(wallet: FirmaWalletService, granteeAddress: string, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
25
+ getGasEstimationRevokeStakeAuthorization(wallet: FirmaWalletService, granteeAddress: string, type: AuthorizationType, txMisc?: TxMisc): Promise<number>;
26
+ revokeStakeAuthorization(wallet: FirmaWalletService, granteeAddress: string, type: AuthorizationType, txMisc?: TxMisc): Promise<BroadcastTxResponse>;
27
+ getGasEstimationExecuteAllowance(wallet: FirmaWalletService, msgs: Any[], txMisc?: TxMisc): Promise<number>;
28
+ executeAllowance(wallet: FirmaWalletService, msgs: Any[], txMisc?: TxMisc): Promise<BroadcastTxResponse>;
29
+ getSendGrantData(granterAddress: string, granteeAddress: string): Promise<GrantSendData[]>;
30
+ getGenericGrantData(granterAddress: string, granteeAddress: string, msgType: string): Promise<GrantGenericData[]>;
31
+ getStakingGrantData(granterAddress: string, granteeAddress: string, msgType: AuthorizationType): Promise<GrantStakingData[]>;
32
+ }
@@ -0,0 +1,630 @@
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.FirmaAuthzService = void 0;
40
+ var FirmaUtil_1 = require("./FirmaUtil");
41
+ var any_1 = require("./firmachain/google/protobuf/any");
42
+ var authz_1 = require("./firmachain/authz");
43
+ var AuthzTxTypes_1 = require("./firmachain/authz/AuthzTxTypes");
44
+ var timestamp_1 = require("./firmachain/google/protobuf/timestamp");
45
+ var FirmaAuthzService = /** @class */ (function () {
46
+ function FirmaAuthzService(config) {
47
+ this.config = config;
48
+ }
49
+ FirmaAuthzService.prototype.getSignedTxGrantSendAutorization = function (wallet, granteeAddress, maxTokens, expirationDate, txMisc) {
50
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
51
+ return __awaiter(this, void 0, void 0, function () {
52
+ var authzTxClient, address, authorization, timestamp, message, error_1;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ _a.trys.push([0, 3, , 4]);
57
+ authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
58
+ return [4 /*yield*/, wallet.getAddress()];
59
+ case 1:
60
+ address = _a.sent();
61
+ authorization = any_1.Any.fromPartial({
62
+ typeUrl: "/cosmos.bank.v1beta1.SendAuthorization",
63
+ value: Uint8Array.from(AuthzTxTypes_1.SendAuthorization.encode(AuthzTxTypes_1.SendAuthorization.fromPartial({
64
+ spendLimit: [{ denom: this.config.denom, amount: maxTokens }],
65
+ })).finish()),
66
+ });
67
+ timestamp = timestamp_1.Timestamp.fromPartial({ seconds: expirationDate.getTime() / 1000 });
68
+ message = authzTxClient.msgGrantAllowance({
69
+ granter: address,
70
+ grantee: granteeAddress,
71
+ grant: {
72
+ authorization: authorization,
73
+ expiration: timestamp
74
+ }
75
+ });
76
+ return [4 /*yield*/, authzTxClient.sign([message], FirmaUtil_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
77
+ case 2: return [2 /*return*/, _a.sent()];
78
+ case 3:
79
+ error_1 = _a.sent();
80
+ FirmaUtil_1.FirmaUtil.printLog(error_1);
81
+ throw error_1;
82
+ case 4: return [2 /*return*/];
83
+ }
84
+ });
85
+ });
86
+ };
87
+ FirmaAuthzService.prototype.getSignedTxGrantStakeAutorization = function (wallet, granteeAddress, validatorAddress, type, maxTokens, expirationDate, txMisc) {
88
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
89
+ return __awaiter(this, void 0, void 0, function () {
90
+ var authzTxClient, address, authorization, timestamp, message, error_2;
91
+ return __generator(this, function (_a) {
92
+ switch (_a.label) {
93
+ case 0:
94
+ _a.trys.push([0, 3, , 4]);
95
+ authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
96
+ return [4 /*yield*/, wallet.getAddress()];
97
+ case 1:
98
+ address = _a.sent();
99
+ authorization = any_1.Any.fromPartial({
100
+ typeUrl: "/cosmos.staking.v1beta1.StakeAuthorization",
101
+ value: Uint8Array.from(AuthzTxTypes_1.StakeAuthorization.encode(AuthzTxTypes_1.StakeAuthorization.fromPartial({
102
+ allowList: { address: [validatorAddress] },
103
+ maxTokens: (maxTokens === "0") ? undefined : { denom: this.config.denom, amount: maxTokens },
104
+ authorizationType: type
105
+ })).finish()),
106
+ });
107
+ timestamp = timestamp_1.Timestamp.fromPartial({ seconds: expirationDate.getTime() / 1000 });
108
+ message = authzTxClient.msgGrantAllowance({
109
+ granter: address,
110
+ grantee: granteeAddress,
111
+ grant: {
112
+ authorization: authorization,
113
+ expiration: timestamp
114
+ }
115
+ });
116
+ return [4 /*yield*/, authzTxClient.sign([message], FirmaUtil_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
117
+ case 2: return [2 /*return*/, _a.sent()];
118
+ case 3:
119
+ error_2 = _a.sent();
120
+ FirmaUtil_1.FirmaUtil.printLog(error_2);
121
+ throw error_2;
122
+ case 4: return [2 /*return*/];
123
+ }
124
+ });
125
+ });
126
+ };
127
+ FirmaAuthzService.prototype.getSignedTxGrantGenericAuthorization = function (wallet, granteeAddress, msgType, expirationDate, txMisc) {
128
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
129
+ return __awaiter(this, void 0, void 0, function () {
130
+ var authzTxClient, address, authorization, timestamp, message, error_3;
131
+ return __generator(this, function (_a) {
132
+ switch (_a.label) {
133
+ case 0:
134
+ _a.trys.push([0, 3, , 4]);
135
+ authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
136
+ return [4 /*yield*/, wallet.getAddress()];
137
+ case 1:
138
+ address = _a.sent();
139
+ authorization = any_1.Any.fromPartial({
140
+ typeUrl: "/cosmos.authz.v1beta1.GenericAuthorization",
141
+ value: Uint8Array.from(AuthzTxTypes_1.GenericAuthorization.encode(AuthzTxTypes_1.GenericAuthorization.fromPartial({
142
+ msg: msgType
143
+ })).finish()),
144
+ });
145
+ timestamp = timestamp_1.Timestamp.fromPartial({ seconds: expirationDate.getTime() / 1000 });
146
+ message = authzTxClient.msgGrantAllowance({
147
+ granter: address,
148
+ grantee: granteeAddress,
149
+ grant: {
150
+ authorization: authorization,
151
+ expiration: timestamp
152
+ }
153
+ });
154
+ return [4 /*yield*/, authzTxClient.sign([message], FirmaUtil_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
155
+ case 2: return [2 /*return*/, _a.sent()];
156
+ case 3:
157
+ error_3 = _a.sent();
158
+ FirmaUtil_1.FirmaUtil.printLog(error_3);
159
+ throw error_3;
160
+ case 4: return [2 /*return*/];
161
+ }
162
+ });
163
+ });
164
+ };
165
+ FirmaAuthzService.prototype.getSignedTxRevokeGenericAuthorization = function (wallet, granteeAddress, msgType, txMisc) {
166
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
167
+ return __awaiter(this, void 0, void 0, function () {
168
+ var authzTxClient, address, message, error_4;
169
+ return __generator(this, function (_a) {
170
+ switch (_a.label) {
171
+ case 0:
172
+ _a.trys.push([0, 3, , 4]);
173
+ authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
174
+ return [4 /*yield*/, wallet.getAddress()];
175
+ case 1:
176
+ address = _a.sent();
177
+ message = authzTxClient.msgRevokeAllowance({
178
+ granter: address,
179
+ grantee: granteeAddress,
180
+ msgTypeUrl: msgType
181
+ });
182
+ return [4 /*yield*/, authzTxClient.sign([message], FirmaUtil_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
183
+ case 2: return [2 /*return*/, _a.sent()];
184
+ case 3:
185
+ error_4 = _a.sent();
186
+ FirmaUtil_1.FirmaUtil.printLog(error_4);
187
+ throw error_4;
188
+ case 4: return [2 /*return*/];
189
+ }
190
+ });
191
+ });
192
+ };
193
+ // executeAllowance
194
+ FirmaAuthzService.prototype.getSignedTxExecuteAllowance = function (wallet, msgs, txMisc) {
195
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
196
+ return __awaiter(this, void 0, void 0, function () {
197
+ var authzTxClient, address, message, error_5;
198
+ return __generator(this, function (_a) {
199
+ switch (_a.label) {
200
+ case 0:
201
+ _a.trys.push([0, 3, , 4]);
202
+ authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
203
+ return [4 /*yield*/, wallet.getAddress()];
204
+ case 1:
205
+ address = _a.sent();
206
+ message = authzTxClient.msgExecAllowance({
207
+ grantee: address,
208
+ msgs: msgs
209
+ });
210
+ return [4 /*yield*/, authzTxClient.sign([message], FirmaUtil_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
211
+ case 2: return [2 /*return*/, _a.sent()];
212
+ case 3:
213
+ error_5 = _a.sent();
214
+ FirmaUtil_1.FirmaUtil.printLog(error_5);
215
+ throw error_5;
216
+ case 4: return [2 /*return*/];
217
+ }
218
+ });
219
+ });
220
+ };
221
+ FirmaAuthzService.prototype.getGasEstimationGrantSendAuthorization = function (wallet, granteeAddress, expirationDate, maxTokens, txMisc) {
222
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
223
+ return __awaiter(this, void 0, void 0, function () {
224
+ var txRaw, error_6;
225
+ return __generator(this, function (_a) {
226
+ switch (_a.label) {
227
+ case 0:
228
+ _a.trys.push([0, 3, , 4]);
229
+ return [4 /*yield*/, this.getSignedTxGrantSendAutorization(wallet, granteeAddress, FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(maxTokens), expirationDate, txMisc)];
230
+ case 1:
231
+ txRaw = _a.sent();
232
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
233
+ case 2: return [2 /*return*/, _a.sent()];
234
+ case 3:
235
+ error_6 = _a.sent();
236
+ FirmaUtil_1.FirmaUtil.printLog(error_6);
237
+ throw error_6;
238
+ case 4: return [2 /*return*/];
239
+ }
240
+ });
241
+ });
242
+ };
243
+ FirmaAuthzService.prototype.grantSendAuthorization = function (wallet, granteeAddress, expirationDate, maxTokens, txMisc) {
244
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
245
+ return __awaiter(this, void 0, void 0, function () {
246
+ var txRaw, authzTxClient, error_7;
247
+ return __generator(this, function (_a) {
248
+ switch (_a.label) {
249
+ case 0:
250
+ _a.trys.push([0, 3, , 4]);
251
+ return [4 /*yield*/, this.getSignedTxGrantSendAutorization(wallet, granteeAddress, FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(maxTokens), expirationDate, txMisc)];
252
+ case 1:
253
+ txRaw = _a.sent();
254
+ authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
255
+ return [4 /*yield*/, authzTxClient.broadcast(txRaw)];
256
+ case 2: return [2 /*return*/, _a.sent()];
257
+ case 3:
258
+ error_7 = _a.sent();
259
+ FirmaUtil_1.FirmaUtil.printLog(error_7);
260
+ throw error_7;
261
+ case 4: return [2 /*return*/];
262
+ }
263
+ });
264
+ });
265
+ };
266
+ FirmaAuthzService.prototype.getGasEstimationGrantStakeAuthorization = function (wallet, granteeAddress, validatorAddress, type, expirationDate, maxTokens, txMisc) {
267
+ if (maxTokens === void 0) { maxTokens = 0; }
268
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
269
+ return __awaiter(this, void 0, void 0, function () {
270
+ var txRaw, error_8;
271
+ return __generator(this, function (_a) {
272
+ switch (_a.label) {
273
+ case 0:
274
+ _a.trys.push([0, 3, , 4]);
275
+ return [4 /*yield*/, this.getSignedTxGrantStakeAutorization(wallet, granteeAddress, validatorAddress, type, FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(maxTokens), expirationDate, txMisc)];
276
+ case 1:
277
+ txRaw = _a.sent();
278
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
279
+ case 2: return [2 /*return*/, _a.sent()];
280
+ case 3:
281
+ error_8 = _a.sent();
282
+ FirmaUtil_1.FirmaUtil.printLog(error_8);
283
+ throw error_8;
284
+ case 4: return [2 /*return*/];
285
+ }
286
+ });
287
+ });
288
+ };
289
+ FirmaAuthzService.prototype.grantStakeAuthorization = function (wallet, granteeAddress, validatorAddress, type, expirationDate, maxTokens, txMisc) {
290
+ if (maxTokens === void 0) { maxTokens = 0; }
291
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
292
+ return __awaiter(this, void 0, void 0, function () {
293
+ var txRaw, authzTxClient, error_9;
294
+ return __generator(this, function (_a) {
295
+ switch (_a.label) {
296
+ case 0:
297
+ _a.trys.push([0, 3, , 4]);
298
+ return [4 /*yield*/, this.getSignedTxGrantStakeAutorization(wallet, granteeAddress, validatorAddress, type, FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(maxTokens), expirationDate, txMisc)];
299
+ case 1:
300
+ txRaw = _a.sent();
301
+ authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
302
+ return [4 /*yield*/, authzTxClient.broadcast(txRaw)];
303
+ case 2: return [2 /*return*/, _a.sent()];
304
+ case 3:
305
+ error_9 = _a.sent();
306
+ FirmaUtil_1.FirmaUtil.printLog(error_9);
307
+ throw error_9;
308
+ case 4: return [2 /*return*/];
309
+ }
310
+ });
311
+ });
312
+ };
313
+ FirmaAuthzService.prototype.getGasEstimationGrantGenericAuthorization = function (wallet, granteeAddress, msg, expirationDate, txMisc) {
314
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
315
+ return __awaiter(this, void 0, void 0, function () {
316
+ var txRaw, error_10;
317
+ return __generator(this, function (_a) {
318
+ switch (_a.label) {
319
+ case 0:
320
+ _a.trys.push([0, 3, , 4]);
321
+ return [4 /*yield*/, this.getSignedTxGrantGenericAuthorization(wallet, granteeAddress, msg, expirationDate, txMisc)];
322
+ case 1:
323
+ txRaw = _a.sent();
324
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
325
+ case 2: return [2 /*return*/, _a.sent()];
326
+ case 3:
327
+ error_10 = _a.sent();
328
+ FirmaUtil_1.FirmaUtil.printLog(error_10);
329
+ throw error_10;
330
+ case 4: return [2 /*return*/];
331
+ }
332
+ });
333
+ });
334
+ };
335
+ FirmaAuthzService.prototype.grantGenericAuthorization = function (wallet, granteeAddress, msg, expirationDate, txMisc) {
336
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
337
+ return __awaiter(this, void 0, void 0, function () {
338
+ var txRaw, authzTxClient, error_11;
339
+ return __generator(this, function (_a) {
340
+ switch (_a.label) {
341
+ case 0:
342
+ _a.trys.push([0, 3, , 4]);
343
+ return [4 /*yield*/, this.getSignedTxGrantGenericAuthorization(wallet, granteeAddress, msg, expirationDate, txMisc)];
344
+ case 1:
345
+ txRaw = _a.sent();
346
+ authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
347
+ return [4 /*yield*/, authzTxClient.broadcast(txRaw)];
348
+ case 2: return [2 /*return*/, _a.sent()];
349
+ case 3:
350
+ error_11 = _a.sent();
351
+ FirmaUtil_1.FirmaUtil.printLog(error_11);
352
+ throw error_11;
353
+ case 4: return [2 /*return*/];
354
+ }
355
+ });
356
+ });
357
+ };
358
+ FirmaAuthzService.prototype.getGasEstimationRevokeGenericAuthorization = function (wallet, granteeAddress, msgType, txMisc) {
359
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
360
+ return __awaiter(this, void 0, void 0, function () {
361
+ var txRaw, error_12;
362
+ return __generator(this, function (_a) {
363
+ switch (_a.label) {
364
+ case 0:
365
+ _a.trys.push([0, 3, , 4]);
366
+ return [4 /*yield*/, this.getSignedTxRevokeGenericAuthorization(wallet, granteeAddress, msgType, txMisc)];
367
+ case 1:
368
+ txRaw = _a.sent();
369
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
370
+ case 2: return [2 /*return*/, _a.sent()];
371
+ case 3:
372
+ error_12 = _a.sent();
373
+ FirmaUtil_1.FirmaUtil.printLog(error_12);
374
+ throw error_12;
375
+ case 4: return [2 /*return*/];
376
+ }
377
+ });
378
+ });
379
+ };
380
+ FirmaAuthzService.prototype.revokeGenericAuthorization = function (wallet, granteeAddress, msgType, txMisc) {
381
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
382
+ return __awaiter(this, void 0, void 0, function () {
383
+ var txRaw, authzTxClient, error_13;
384
+ return __generator(this, function (_a) {
385
+ switch (_a.label) {
386
+ case 0:
387
+ _a.trys.push([0, 3, , 4]);
388
+ return [4 /*yield*/, this.getSignedTxRevokeGenericAuthorization(wallet, granteeAddress, msgType, txMisc)];
389
+ case 1:
390
+ txRaw = _a.sent();
391
+ authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
392
+ return [4 /*yield*/, authzTxClient.broadcast(txRaw)];
393
+ case 2: return [2 /*return*/, _a.sent()];
394
+ case 3:
395
+ error_13 = _a.sent();
396
+ FirmaUtil_1.FirmaUtil.printLog(error_13);
397
+ throw error_13;
398
+ case 4: return [2 /*return*/];
399
+ }
400
+ });
401
+ });
402
+ };
403
+ FirmaAuthzService.prototype.getGasEstimationRevokeSendAuthorization = function (wallet, granteeAddress, txMisc) {
404
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
405
+ return __awaiter(this, void 0, void 0, function () {
406
+ var msgType, txRaw, error_14;
407
+ return __generator(this, function (_a) {
408
+ switch (_a.label) {
409
+ case 0:
410
+ _a.trys.push([0, 3, , 4]);
411
+ msgType = "/cosmos.bank.v1beta1.MsgSend";
412
+ return [4 /*yield*/, this.getSignedTxRevokeGenericAuthorization(wallet, granteeAddress, msgType, txMisc)];
413
+ case 1:
414
+ txRaw = _a.sent();
415
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
416
+ case 2: return [2 /*return*/, _a.sent()];
417
+ case 3:
418
+ error_14 = _a.sent();
419
+ FirmaUtil_1.FirmaUtil.printLog(error_14);
420
+ throw error_14;
421
+ case 4: return [2 /*return*/];
422
+ }
423
+ });
424
+ });
425
+ };
426
+ FirmaAuthzService.prototype.revokeSendAuthorization = function (wallet, granteeAddress, txMisc) {
427
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
428
+ return __awaiter(this, void 0, void 0, function () {
429
+ var msgType, error_15;
430
+ return __generator(this, function (_a) {
431
+ switch (_a.label) {
432
+ case 0:
433
+ _a.trys.push([0, 2, , 3]);
434
+ msgType = "/cosmos.bank.v1beta1.MsgSend";
435
+ return [4 /*yield*/, this.revokeGenericAuthorization(wallet, granteeAddress, msgType, txMisc)];
436
+ case 1: return [2 /*return*/, _a.sent()];
437
+ case 2:
438
+ error_15 = _a.sent();
439
+ FirmaUtil_1.FirmaUtil.printLog(error_15);
440
+ throw error_15;
441
+ case 3: return [2 /*return*/];
442
+ }
443
+ });
444
+ });
445
+ };
446
+ FirmaAuthzService.prototype.getGasEstimationRevokeStakeAuthorization = function (wallet, granteeAddress, type, txMisc) {
447
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
448
+ return __awaiter(this, void 0, void 0, function () {
449
+ var msgType, txRaw, error_16;
450
+ return __generator(this, function (_a) {
451
+ switch (_a.label) {
452
+ case 0:
453
+ _a.trys.push([0, 3, , 4]);
454
+ msgType = "";
455
+ switch (type) {
456
+ case AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_DELEGATE:
457
+ msgType = "/cosmos.staking.v1beta1.MsgDelegate";
458
+ break;
459
+ case AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_UNDELEGATE:
460
+ msgType = "/cosmos.staking.v1beta1.MsgUndelegate";
461
+ break;
462
+ case AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_REDELEGATE:
463
+ msgType = "/cosmos.staking.v1beta1.MsgBeginRedelegate";
464
+ break;
465
+ default:
466
+ throw "AuthorizationType Error : " + type;
467
+ }
468
+ return [4 /*yield*/, this.getSignedTxRevokeGenericAuthorization(wallet, granteeAddress, msgType, txMisc)];
469
+ case 1:
470
+ txRaw = _a.sent();
471
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
472
+ case 2: return [2 /*return*/, _a.sent()];
473
+ case 3:
474
+ error_16 = _a.sent();
475
+ FirmaUtil_1.FirmaUtil.printLog(error_16);
476
+ throw error_16;
477
+ case 4: return [2 /*return*/];
478
+ }
479
+ });
480
+ });
481
+ };
482
+ FirmaAuthzService.prototype.revokeStakeAuthorization = function (wallet, granteeAddress, type, txMisc) {
483
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
484
+ return __awaiter(this, void 0, void 0, function () {
485
+ var msgType, txRaw, authzTxClient, error_17;
486
+ return __generator(this, function (_a) {
487
+ switch (_a.label) {
488
+ case 0:
489
+ _a.trys.push([0, 3, , 4]);
490
+ msgType = "";
491
+ switch (type) {
492
+ case AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_DELEGATE:
493
+ msgType = "/cosmos.staking.v1beta1.MsgDelegate";
494
+ break;
495
+ case AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_UNDELEGATE:
496
+ msgType = "/cosmos.staking.v1beta1.MsgUndelegate";
497
+ break;
498
+ case AuthzTxTypes_1.AuthorizationType.AUTHORIZATION_TYPE_REDELEGATE:
499
+ msgType = "/cosmos.staking.v1beta1.MsgBeginRedelegate";
500
+ break;
501
+ default:
502
+ throw "AuthorizationType Error : " + type;
503
+ }
504
+ return [4 /*yield*/, this.getSignedTxRevokeGenericAuthorization(wallet, granteeAddress, msgType, txMisc)];
505
+ case 1:
506
+ txRaw = _a.sent();
507
+ authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
508
+ return [4 /*yield*/, authzTxClient.broadcast(txRaw)];
509
+ case 2: return [2 /*return*/, _a.sent()];
510
+ case 3:
511
+ error_17 = _a.sent();
512
+ FirmaUtil_1.FirmaUtil.printLog(error_17);
513
+ throw error_17;
514
+ case 4: return [2 /*return*/];
515
+ }
516
+ });
517
+ });
518
+ };
519
+ FirmaAuthzService.prototype.getGasEstimationExecuteAllowance = function (wallet, msgs, txMisc) {
520
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
521
+ return __awaiter(this, void 0, void 0, function () {
522
+ var txRaw, error_18;
523
+ return __generator(this, function (_a) {
524
+ switch (_a.label) {
525
+ case 0:
526
+ _a.trys.push([0, 3, , 4]);
527
+ return [4 /*yield*/, this.getSignedTxExecuteAllowance(wallet, msgs, txMisc)];
528
+ case 1:
529
+ txRaw = _a.sent();
530
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
531
+ case 2: return [2 /*return*/, _a.sent()];
532
+ case 3:
533
+ error_18 = _a.sent();
534
+ FirmaUtil_1.FirmaUtil.printLog(error_18);
535
+ throw error_18;
536
+ case 4: return [2 /*return*/];
537
+ }
538
+ });
539
+ });
540
+ };
541
+ FirmaAuthzService.prototype.executeAllowance = function (wallet, msgs, txMisc) {
542
+ if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
543
+ return __awaiter(this, void 0, void 0, function () {
544
+ var txRaw, authzTxClient, error_19;
545
+ return __generator(this, function (_a) {
546
+ switch (_a.label) {
547
+ case 0:
548
+ _a.trys.push([0, 3, , 4]);
549
+ return [4 /*yield*/, this.getSignedTxExecuteAllowance(wallet, msgs, txMisc)];
550
+ case 1:
551
+ txRaw = _a.sent();
552
+ authzTxClient = new authz_1.AuthzTxClient(wallet, this.config.rpcAddress);
553
+ return [4 /*yield*/, authzTxClient.broadcast(txRaw)];
554
+ case 2: return [2 /*return*/, _a.sent()];
555
+ case 3:
556
+ error_19 = _a.sent();
557
+ FirmaUtil_1.FirmaUtil.printLog(error_19);
558
+ throw error_19;
559
+ case 4: return [2 /*return*/];
560
+ }
561
+ });
562
+ });
563
+ };
564
+ // query
565
+ FirmaAuthzService.prototype.getSendGrantData = function (granterAddress, granteeAddress) {
566
+ return __awaiter(this, void 0, void 0, function () {
567
+ var queryClient, result, error_20;
568
+ return __generator(this, function (_a) {
569
+ switch (_a.label) {
570
+ case 0:
571
+ _a.trys.push([0, 2, , 3]);
572
+ queryClient = new authz_1.AuthzQueryClient(this.config.restApiAddress);
573
+ return [4 /*yield*/, queryClient.getSendGrantData(granterAddress, granteeAddress)];
574
+ case 1:
575
+ result = _a.sent();
576
+ return [2 /*return*/, result];
577
+ case 2:
578
+ error_20 = _a.sent();
579
+ FirmaUtil_1.FirmaUtil.printLog(error_20);
580
+ throw error_20;
581
+ case 3: return [2 /*return*/];
582
+ }
583
+ });
584
+ });
585
+ };
586
+ FirmaAuthzService.prototype.getGenericGrantData = function (granterAddress, granteeAddress, msgType) {
587
+ return __awaiter(this, void 0, void 0, function () {
588
+ var queryClient, result, error_21;
589
+ return __generator(this, function (_a) {
590
+ switch (_a.label) {
591
+ case 0:
592
+ _a.trys.push([0, 2, , 3]);
593
+ queryClient = new authz_1.AuthzQueryClient(this.config.restApiAddress);
594
+ return [4 /*yield*/, queryClient.getGenericGrantData(granterAddress, granteeAddress, msgType)];
595
+ case 1:
596
+ result = _a.sent();
597
+ return [2 /*return*/, result];
598
+ case 2:
599
+ error_21 = _a.sent();
600
+ FirmaUtil_1.FirmaUtil.printLog(error_21);
601
+ throw error_21;
602
+ case 3: return [2 /*return*/];
603
+ }
604
+ });
605
+ });
606
+ };
607
+ FirmaAuthzService.prototype.getStakingGrantData = function (granterAddress, granteeAddress, msgType) {
608
+ return __awaiter(this, void 0, void 0, function () {
609
+ var queryClient, result, error_22;
610
+ return __generator(this, function (_a) {
611
+ switch (_a.label) {
612
+ case 0:
613
+ _a.trys.push([0, 2, , 3]);
614
+ queryClient = new authz_1.AuthzQueryClient(this.config.restApiAddress);
615
+ return [4 /*yield*/, queryClient.getStakingGrantData(granterAddress, granteeAddress, msgType)];
616
+ case 1:
617
+ result = _a.sent();
618
+ return [2 /*return*/, result];
619
+ case 2:
620
+ error_22 = _a.sent();
621
+ FirmaUtil_1.FirmaUtil.printLog(error_22);
622
+ throw error_22;
623
+ case 3: return [2 /*return*/];
624
+ }
625
+ });
626
+ });
627
+ };
628
+ return FirmaAuthzService;
629
+ }());
630
+ exports.FirmaAuthzService = FirmaAuthzService;