@firmachain/firma-js 0.2.30 → 0.2.33

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 (75) hide show
  1. package/dist/sdk/FirmaAuthzService.d.ts +41 -0
  2. package/dist/sdk/FirmaAuthzService.js +633 -0
  3. package/dist/sdk/FirmaBankService.d.ts +2 -1
  4. package/dist/sdk/FirmaBankService.js +4 -1
  5. package/dist/sdk/FirmaContractService.js +10 -12
  6. package/dist/sdk/FirmaCosmWasmService.d.ts +38 -0
  7. package/dist/sdk/FirmaCosmWasmService.js +667 -0
  8. package/dist/sdk/FirmaDistributionService.d.ts +2 -1
  9. package/dist/sdk/FirmaDistributionService.js +8 -5
  10. package/dist/sdk/FirmaFeeGrantService.js +3 -3
  11. package/dist/sdk/FirmaGovService.js +19 -19
  12. package/dist/sdk/FirmaIbcService.d.ts +15 -0
  13. package/dist/sdk/FirmaIbcService.js +144 -0
  14. package/dist/sdk/FirmaMobileSDK.d.ts +3 -1
  15. package/dist/sdk/FirmaMobileSDK.js +4 -1
  16. package/dist/sdk/FirmaNftService.js +6 -6
  17. package/dist/sdk/FirmaSDK.d.ts +7 -1
  18. package/dist/sdk/FirmaSDK.js +10 -1
  19. package/dist/sdk/FirmaStakingService.d.ts +18 -5
  20. package/dist/sdk/FirmaStakingService.js +20 -13
  21. package/dist/sdk/FirmaTokenService.js +12 -12
  22. package/dist/sdk/FirmaUtil.d.ts +18 -1
  23. package/dist/sdk/FirmaUtil.js +193 -0
  24. package/dist/sdk/FirmaWalletService.d.ts +3 -0
  25. package/dist/sdk/FirmaWalletService.js +18 -10
  26. package/dist/sdk/firmachain/amino/signer.d.ts +1 -2
  27. package/dist/sdk/firmachain/authz/AuthzQueryClient.d.ts +48 -0
  28. package/dist/sdk/firmachain/authz/AuthzQueryClient.js +142 -0
  29. package/dist/sdk/firmachain/authz/AuthzTxClient.d.ts +23 -0
  30. package/dist/sdk/firmachain/authz/AuthzTxClient.js +47 -0
  31. package/dist/sdk/firmachain/authz/AuthzTxTypes.d.ts +147 -0
  32. package/dist/sdk/firmachain/authz/AuthzTxTypes.js +358 -0
  33. package/dist/sdk/firmachain/authz/index.d.ts +3 -0
  34. package/dist/sdk/firmachain/authz/index.js +15 -0
  35. package/dist/sdk/firmachain/bank/BankTxClient.d.ts +4 -3
  36. package/dist/sdk/firmachain/bank/BankTxClient.js +5 -2
  37. package/dist/sdk/firmachain/common/ITxClient.d.ts +4 -1
  38. package/dist/sdk/firmachain/common/ITxClient.js +15 -0
  39. package/dist/sdk/firmachain/common/signingaminostargateclient.d.ts +50 -0
  40. package/dist/sdk/firmachain/common/signingaminostargateclient.js +267 -0
  41. package/dist/sdk/firmachain/common/signingstargateclient.d.ts +15 -8
  42. package/dist/sdk/firmachain/common/signingstargateclient.js +68 -9
  43. package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +4 -3
  44. package/dist/sdk/firmachain/contract/ContractTxClient.js +5 -2
  45. package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.d.ts +52 -0
  46. package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.js +193 -0
  47. package/dist/sdk/firmachain/cosmwasm/CosmWasmTxClient.d.ts +38 -0
  48. package/dist/sdk/firmachain/cosmwasm/CosmWasmTxClient.js +59 -0
  49. package/dist/sdk/firmachain/cosmwasm/index.d.ts +3 -0
  50. package/dist/sdk/firmachain/cosmwasm/index.js +15 -0
  51. package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +6 -5
  52. package/dist/sdk/firmachain/distribution/DistributionTxClient.js +7 -4
  53. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +4 -3
  54. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +5 -2
  55. package/dist/sdk/firmachain/gov/GovTxClient.d.ts +5 -4
  56. package/dist/sdk/firmachain/gov/GovTxClient.js +6 -3
  57. package/dist/sdk/firmachain/ibc/IbcQueryClient.d.ts +34 -0
  58. package/dist/sdk/firmachain/ibc/IbcQueryClient.js +71 -0
  59. package/dist/sdk/firmachain/ibc/IbcTxClient.d.ts +13 -0
  60. package/dist/sdk/firmachain/ibc/IbcTxClient.js +39 -0
  61. package/dist/sdk/firmachain/ibc/index.d.ts +3 -0
  62. package/dist/sdk/firmachain/ibc/index.js +15 -0
  63. package/dist/sdk/firmachain/nft/NftTxClient.d.ts +5 -4
  64. package/dist/sdk/firmachain/nft/NftTxClient.js +6 -3
  65. package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +17 -4
  66. package/dist/sdk/firmachain/staking/StakingQueryClient.js +38 -18
  67. package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +7 -6
  68. package/dist/sdk/firmachain/staking/StakingTxClient.js +8 -5
  69. package/dist/sdk/firmachain/token/TokenTxClient.d.ts +6 -5
  70. package/dist/sdk/firmachain/token/TokenTxClient.js +7 -4
  71. package/package.json +3 -1
  72. package/dist/sdk/firmachain/amino/secp256k1hdwallet.d.ts +0 -94
  73. package/dist/sdk/firmachain/amino/secp256k1hdwallet.js +0 -437
  74. package/dist/sdk/firmachain/amino/secp256k1wallet.d.ts +0 -23
  75. package/dist/sdk/firmachain/amino/secp256k1wallet.js +0 -141
@@ -43,6 +43,9 @@ var FirmaStakingService = /** @class */ (function () {
43
43
  function FirmaStakingService(config) {
44
44
  this.config = config;
45
45
  }
46
+ FirmaStakingService.prototype.getTxClient = function (wallet) {
47
+ return new staking_1.StakingTxClient(wallet, this.config.rpcAddress);
48
+ };
46
49
  FirmaStakingService.prototype.getGasEstimationDelegate = function (wallet, validatorAddres, amount, txMisc) {
47
50
  if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
48
51
  return __awaiter(this, void 0, void 0, function () {
@@ -122,7 +125,7 @@ var FirmaStakingService = /** @class */ (function () {
122
125
  case 1:
123
126
  address = _a.sent();
124
127
  sendAmount = { denom: this.config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amount) };
125
- message = txClient.msgDelegate({
128
+ message = staking_1.StakingTxClient.msgDelegate({
126
129
  delegatorAddress: address,
127
130
  validatorAddress: validatorAddres,
128
131
  amount: sendAmount
@@ -151,7 +154,7 @@ var FirmaStakingService = /** @class */ (function () {
151
154
  case 1:
152
155
  address = _a.sent();
153
156
  sendAmount = { denom: this.config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amount) };
154
- message = txClient.msgUndelegate({
157
+ message = staking_1.StakingTxClient.msgUndelegate({
155
158
  delegatorAddress: address,
156
159
  validatorAddress: validatorAddres,
157
160
  amount: sendAmount
@@ -180,7 +183,7 @@ var FirmaStakingService = /** @class */ (function () {
180
183
  case 1:
181
184
  address = _a.sent();
182
185
  sendAmount = { denom: this.config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amount) };
183
- message = txClient.msgRedelegate({
186
+ message = staking_1.StakingTxClient.msgRedelegate({
184
187
  delegatorAddress: address,
185
188
  validatorSrcAddress: validatorSrcAddress,
186
189
  validatorDstAddress: validatorDstAddress,
@@ -206,7 +209,7 @@ var FirmaStakingService = /** @class */ (function () {
206
209
  case 0:
207
210
  _a.trys.push([0, 2, , 3]);
208
211
  txClient = new staking_1.StakingTxClient(wallet, this.config.rpcAddress);
209
- message = txClient.msgCreateValidator({
212
+ message = staking_1.StakingTxClient.msgCreateValidator({
210
213
  description: validatorInfo.description,
211
214
  commission: validatorInfo.commission,
212
215
  minSelfDelegation: validatorInfo.minSelfDelegation,
@@ -235,7 +238,7 @@ var FirmaStakingService = /** @class */ (function () {
235
238
  case 0:
236
239
  _a.trys.push([0, 2, , 3]);
237
240
  txClient = new staking_1.StakingTxClient(wallet, this.config.rpcAddress);
238
- message = txClient.msgEditValidator({
241
+ message = staking_1.StakingTxClient.msgEditValidator({
239
242
  validatorAddress: validatorAddress,
240
243
  description: description,
241
244
  commissionRate: commissionRate,
@@ -452,7 +455,8 @@ var FirmaStakingService = /** @class */ (function () {
452
455
  });
453
456
  });
454
457
  };
455
- FirmaStakingService.prototype.getUndelegationListFromValidator = function (valoperAddress) {
458
+ FirmaStakingService.prototype.getUndelegationListFromValidator = function (valoperAddress, paginationKey) {
459
+ if (paginationKey === void 0) { paginationKey = ""; }
456
460
  return __awaiter(this, void 0, void 0, function () {
457
461
  var queryClient, result, error_18;
458
462
  return __generator(this, function (_a) {
@@ -460,7 +464,7 @@ var FirmaStakingService = /** @class */ (function () {
460
464
  case 0:
461
465
  _a.trys.push([0, 2, , 3]);
462
466
  queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
463
- return [4 /*yield*/, queryClient.queryGetUndelegationListFromValidator(valoperAddress)];
467
+ return [4 /*yield*/, queryClient.queryGetUndelegationListFromValidator(valoperAddress, paginationKey)];
464
468
  case 1:
465
469
  result = _a.sent();
466
470
  return [2 /*return*/, result];
@@ -473,7 +477,8 @@ var FirmaStakingService = /** @class */ (function () {
473
477
  });
474
478
  });
475
479
  };
476
- FirmaStakingService.prototype.getDelegationListFromValidator = function (valoperAddress) {
480
+ FirmaStakingService.prototype.getDelegationListFromValidator = function (valoperAddress, paginationKey) {
481
+ if (paginationKey === void 0) { paginationKey = ""; }
477
482
  return __awaiter(this, void 0, void 0, function () {
478
483
  var queryClient, result, error_19;
479
484
  return __generator(this, function (_a) {
@@ -481,7 +486,7 @@ var FirmaStakingService = /** @class */ (function () {
481
486
  case 0:
482
487
  _a.trys.push([0, 2, , 3]);
483
488
  queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
484
- return [4 /*yield*/, queryClient.queryGetDelegateListFromValidator(valoperAddress)];
489
+ return [4 /*yield*/, queryClient.queryGetDelegateListFromValidator(valoperAddress, paginationKey)];
485
490
  case 1:
486
491
  result = _a.sent();
487
492
  return [2 /*return*/, result];
@@ -494,7 +499,8 @@ var FirmaStakingService = /** @class */ (function () {
494
499
  });
495
500
  });
496
501
  };
497
- FirmaStakingService.prototype.getTotalDelegationInfo = function (address) {
502
+ FirmaStakingService.prototype.getTotalDelegationInfo = function (address, paginationKey) {
503
+ if (paginationKey === void 0) { paginationKey = ""; }
498
504
  return __awaiter(this, void 0, void 0, function () {
499
505
  var queryClient, result, error_20;
500
506
  return __generator(this, function (_a) {
@@ -502,7 +508,7 @@ var FirmaStakingService = /** @class */ (function () {
502
508
  case 0:
503
509
  _a.trys.push([0, 2, , 3]);
504
510
  queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
505
- return [4 /*yield*/, queryClient.queryGetTotalDelegationInfo(address)];
511
+ return [4 /*yield*/, queryClient.queryGetTotalDelegationInfo(address, paginationKey)];
506
512
  case 1:
507
513
  result = _a.sent();
508
514
  return [2 /*return*/, result];
@@ -578,7 +584,8 @@ var FirmaStakingService = /** @class */ (function () {
578
584
  });
579
585
  });
580
586
  };
581
- FirmaStakingService.prototype.getValidatorList = function () {
587
+ FirmaStakingService.prototype.getValidatorList = function (paginationKey) {
588
+ if (paginationKey === void 0) { paginationKey = ""; }
582
589
  return __awaiter(this, void 0, void 0, function () {
583
590
  var queryClient, result, error_24;
584
591
  return __generator(this, function (_a) {
@@ -586,7 +593,7 @@ var FirmaStakingService = /** @class */ (function () {
586
593
  case 0:
587
594
  _a.trys.push([0, 2, , 3]);
588
595
  queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
589
- return [4 /*yield*/, queryClient.queryValidators()];
596
+ return [4 /*yield*/, queryClient.queryValidators(paginationKey)];
590
597
  case 1:
591
598
  result = _a.sent();
592
599
  return [2 /*return*/, result];
@@ -137,7 +137,7 @@ var TokenService = /** @class */ (function () {
137
137
  TokenService.prototype.getSignedTxUpdateTokenURI = function (wallet, tokenID, tokenURI, txMisc) {
138
138
  if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
139
139
  return __awaiter(this, void 0, void 0, function () {
140
- var address, txClient, message, error_5;
140
+ var address, message, txClient, error_5;
141
141
  return __generator(this, function (_a) {
142
142
  switch (_a.label) {
143
143
  case 0:
@@ -145,12 +145,12 @@ var TokenService = /** @class */ (function () {
145
145
  return [4 /*yield*/, wallet.getAddress()];
146
146
  case 1:
147
147
  address = _a.sent();
148
- txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
149
- message = txClient.msgUpdateTokenURI({
148
+ message = token_1.TokenTxClient.msgUpdateTokenURI({
150
149
  owner: address,
151
150
  tokenID: tokenID,
152
151
  tokenURI: tokenURI
153
152
  });
153
+ txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
154
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:
@@ -165,7 +165,7 @@ var TokenService = /** @class */ (function () {
165
165
  TokenService.prototype.getSignedTxBurn = function (wallet, tokenID, amount, txMisc) {
166
166
  if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
167
167
  return __awaiter(this, void 0, void 0, function () {
168
- var address, txClient, message, error_6;
168
+ var address, message, txClient, error_6;
169
169
  return __generator(this, function (_a) {
170
170
  switch (_a.label) {
171
171
  case 0:
@@ -173,12 +173,12 @@ var TokenService = /** @class */ (function () {
173
173
  return [4 /*yield*/, wallet.getAddress()];
174
174
  case 1:
175
175
  address = _a.sent();
176
- txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
177
- message = txClient.msgBurn({
176
+ message = token_1.TokenTxClient.msgBurn({
178
177
  owner: address,
179
178
  tokenID: tokenID,
180
179
  amount: amount
181
180
  });
181
+ txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
182
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:
@@ -193,7 +193,7 @@ var TokenService = /** @class */ (function () {
193
193
  TokenService.prototype.getSignedTxMint = function (wallet, tokenID, amount, toAddress, txMisc) {
194
194
  if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
195
195
  return __awaiter(this, void 0, void 0, function () {
196
- var address, txClient, message, error_7;
196
+ var address, message, txClient, error_7;
197
197
  return __generator(this, function (_a) {
198
198
  switch (_a.label) {
199
199
  case 0:
@@ -201,13 +201,13 @@ var TokenService = /** @class */ (function () {
201
201
  return [4 /*yield*/, wallet.getAddress()];
202
202
  case 1:
203
203
  address = _a.sent();
204
- txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
205
- message = txClient.msgMint({
204
+ message = token_1.TokenTxClient.msgMint({
206
205
  owner: address,
207
206
  tokenID: tokenID,
208
207
  amount: amount,
209
208
  toAddress: toAddress
210
209
  });
210
+ txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
211
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:
@@ -222,7 +222,7 @@ var TokenService = /** @class */ (function () {
222
222
  TokenService.prototype.getSignedTxCreateToken = function (wallet, tokenName, tokenSymbol, tokenURI, totalSupply, decimal, isMintable, isBurnable, txMisc) {
223
223
  if (txMisc === void 0) { txMisc = FirmaUtil_1.DefaultTxMisc; }
224
224
  return __awaiter(this, void 0, void 0, function () {
225
- var address, txClient, message, error_8;
225
+ var address, message, txClient, error_8;
226
226
  return __generator(this, function (_a) {
227
227
  switch (_a.label) {
228
228
  case 0:
@@ -230,8 +230,7 @@ var TokenService = /** @class */ (function () {
230
230
  return [4 /*yield*/, wallet.getAddress()];
231
231
  case 1:
232
232
  address = _a.sent();
233
- txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
234
- message = txClient.msgCreateToken({
233
+ message = token_1.TokenTxClient.msgCreateToken({
235
234
  owner: address,
236
235
  name: tokenName,
237
236
  symbol: tokenSymbol,
@@ -241,6 +240,7 @@ var TokenService = /** @class */ (function () {
241
240
  mintable: isMintable,
242
241
  burnable: isBurnable
243
242
  });
243
+ txClient = new token_1.TokenTxClient(wallet, this.config.rpcAddress);
244
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:
@@ -1,7 +1,11 @@
1
- import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
1
+ import { SignDoc, TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
2
2
  import { FirmaConfig } from "./FirmaConfig";
3
3
  import { SignerData } from "./firmachain/common/LedgerSigningStargateClient";
4
4
  import { SignAndBroadcastOptions, TxMisc } from "./firmachain/common";
5
+ import { ArbitraryVerifyData } from "./firmachain/common/signingaminostargateclient";
6
+ import { EncodeObject, Registry } from "@cosmjs/proto-signing";
7
+ import { FirmaWalletService } from "./FirmaWalletService";
8
+ import { Any } from "./firmachain/google/protobuf/any";
5
9
  export declare class FirmaUtil {
6
10
  static config: FirmaConfig;
7
11
  static readonly FctDecimal: number;
@@ -11,8 +15,11 @@ export declare class FirmaUtil {
11
15
  static getTokenStringFromUTokenStr(uTokenAmount: string, decimal: number): string;
12
16
  static getUTokenStringFromToken(tokenAmount: number, decimal: number): string;
13
17
  static getUTokenFromToken(tokenAmount: number, decimal: number): number;
18
+ static arrayBufferToBase64(buffer: Uint8Array): string;
19
+ static base64ToArrayBuffer(base64: string): Uint8Array;
14
20
  static getTokenStringFromUToken(uTokenAmount: number, decimal: number): string;
15
21
  static getUFCTStringFromFCTStr(fctAmount: string): string;
22
+ static getUFCTFromFCT(fctAmount: number): number;
16
23
  static getFCTStringFromUFCTStr(uFctAmount: string): string;
17
24
  static getUFCTStringFromFCT(fctAmount: number): string;
18
25
  static getFCTStringFromUFCT(uFctAmount: number): string;
@@ -27,6 +34,16 @@ export declare class FirmaUtil {
27
34
  static estimateGas(txRaw: TxRaw): Promise<number>;
28
35
  static estimateGasRaw(txRaw: Uint8Array): Promise<number>;
29
36
  static printLog(log: any): void;
37
+ static experimentalAdr36Sign(wallet: FirmaWalletService, data: string): Promise<ArbitraryVerifyData>;
38
+ static experimentalAdr36Verify(data: ArbitraryVerifyData, checkMsg: string): Promise<boolean>;
39
+ private static recoverSigningAddress;
40
+ private static verifySignature;
41
+ static verifyDirectSignature(address: string, signature: string, signDoc: SignDoc): Promise<boolean>;
42
+ static parseSignDocValues(signDocString: any): any;
43
+ static stringifySignDocValues(signDoc: any): any;
44
+ static makeSignDoc(registry: Registry, signerAddress: string, messages: readonly EncodeObject[], txMisc?: TxMisc): Promise<SignDoc>;
45
+ static makeSignDocWithStringify(registry: Registry, signerAddress: string, messages: readonly EncodeObject[], txMisc?: TxMisc): Promise<SignDoc>;
46
+ static getAnyData(registry: Registry, message: EncodeObject): Any;
30
47
  }
31
48
  export declare const DefaultTxMisc: {
32
49
  memo: string;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,6 +46,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
47
  }
37
48
  };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
38
52
  Object.defineProperty(exports, "__esModule", { value: true });
39
53
  exports.getSignAndBroadcastOption = exports.DefaultTxMisc = exports.FirmaUtil = void 0;
40
54
  var fs_1 = require("fs");
@@ -42,6 +56,14 @@ var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
42
56
  var TendermintQueryClient_1 = require("./firmachain/common/TendermintQueryClient");
43
57
  var encoding_1 = require("@cosmjs/encoding");
44
58
  var LedgerSigningStargateClient_1 = require("./firmachain/common/LedgerSigningStargateClient");
59
+ var encoding_2 = require("@cosmjs/encoding");
60
+ var crypto_1 = require("@cosmjs/crypto");
61
+ var amino_1 = require("@cosmjs/amino");
62
+ var signingaminostargateclient_1 = require("./firmachain/common/signingaminostargateclient");
63
+ var proto_signing_1 = require("@cosmjs/proto-signing");
64
+ var signingstargateclient_1 = require("./firmachain/common/signingstargateclient");
65
+ var any_1 = require("./firmachain/google/protobuf/any");
66
+ var long_1 = __importDefault(require("long"));
45
67
  var CryptoJS = require("crypto-js");
46
68
  var sha1 = require("crypto-js/sha1");
47
69
  var sha256 = require("crypto-js/sha256");
@@ -86,6 +108,27 @@ var FirmaUtil = /** @class */ (function () {
86
108
  var newBig = big.toFixed(0);
87
109
  return Number.parseInt(newBig);
88
110
  };
111
+ FirmaUtil.arrayBufferToBase64 = function (buffer) {
112
+ return Buffer.from(buffer).toString("base64");
113
+ /*var binary = '';
114
+ var bytes = new Uint8Array(buffer);
115
+ var len = bytes.byteLength;
116
+ for (var i = 0; i < len; i++) {
117
+ binary += String.fromCharCode(bytes[i]);
118
+ }
119
+ return btoa(binary);*/
120
+ };
121
+ FirmaUtil.base64ToArrayBuffer = function (base64) {
122
+ var buffer = Buffer.from(base64, "base64");
123
+ return new Uint8Array(buffer);
124
+ /* var binary_string = atob(base64);
125
+ var len = binary_string.length;
126
+ var bytes = new Uint8Array(len);
127
+ for (var i = 0; i < len; i++) {
128
+ bytes[i] = binary_string.charCodeAt(i);
129
+ }
130
+ return bytes;*/
131
+ };
89
132
  FirmaUtil.getTokenStringFromUToken = function (uTokenAmount, decimal) {
90
133
  var fixedUTokenAmount = Math.floor(uTokenAmount);
91
134
  var decimalMutiplyer = Math.pow(10, decimal);
@@ -94,6 +137,9 @@ var FirmaUtil = /** @class */ (function () {
94
137
  FirmaUtil.getUFCTStringFromFCTStr = function (fctAmount) {
95
138
  return this.getUTokenStringFromTokenStr(fctAmount, this.FctDecimal);
96
139
  };
140
+ FirmaUtil.getUFCTFromFCT = function (fctAmount) {
141
+ return this.getUTokenFromToken(fctAmount, this.FctDecimal);
142
+ };
97
143
  FirmaUtil.getFCTStringFromUFCTStr = function (uFctAmount) {
98
144
  return this.getTokenStringFromUTokenStr(uFctAmount, this.FctDecimal);
99
145
  };
@@ -224,6 +270,153 @@ var FirmaUtil = /** @class */ (function () {
224
270
  return;
225
271
  console.log("[FirmaSDK] " + log);
226
272
  };
273
+ FirmaUtil.experimentalAdr36Sign = function (wallet, data) {
274
+ return __awaiter(this, void 0, void 0, function () {
275
+ var registry, aliceClient, address, userData, error_4;
276
+ return __generator(this, function (_a) {
277
+ switch (_a.label) {
278
+ case 0:
279
+ _a.trys.push([0, 4, , 5]);
280
+ registry = new proto_signing_1.Registry();
281
+ return [4 /*yield*/, signingaminostargateclient_1.SigningAminoStargateClient.connectWithSigner(FirmaUtil.config.rpcAddress, wallet.getRawAminoWallet(), registry)];
282
+ case 1:
283
+ aliceClient = _a.sent();
284
+ return [4 /*yield*/, wallet.getAddress()];
285
+ case 2:
286
+ address = _a.sent();
287
+ userData = Buffer.from(data);
288
+ return [4 /*yield*/, aliceClient.experimentalAdr36Sign(address, userData)];
289
+ case 3: return [2 /*return*/, _a.sent()];
290
+ case 4:
291
+ error_4 = _a.sent();
292
+ FirmaUtil.printLog(error_4);
293
+ throw error_4;
294
+ case 5: return [2 /*return*/];
295
+ }
296
+ });
297
+ });
298
+ };
299
+ FirmaUtil.experimentalAdr36Verify = function (data, checkMsg) {
300
+ return __awaiter(this, void 0, void 0, function () {
301
+ var error_5;
302
+ return __generator(this, function (_a) {
303
+ switch (_a.label) {
304
+ case 0:
305
+ _a.trys.push([0, 2, , 3]);
306
+ return [4 /*yield*/, signingaminostargateclient_1.SigningAminoStargateClient.experimentalAdr36Verify(data, checkMsg)];
307
+ case 1: return [2 /*return*/, _a.sent()];
308
+ case 2:
309
+ error_5 = _a.sent();
310
+ FirmaUtil.printLog(error_5);
311
+ throw error_5;
312
+ case 3: return [2 /*return*/];
313
+ }
314
+ });
315
+ });
316
+ };
317
+ FirmaUtil.recoverSigningAddress = function (signature, hash, recoveryIndex) {
318
+ return __awaiter(this, void 0, void 0, function () {
319
+ var sig, extendedSig, recoveredPubKey, _a;
320
+ return __generator(this, function (_b) {
321
+ switch (_b.label) {
322
+ case 0:
323
+ if (recoveryIndex > 3) {
324
+ throw new Error('Invalid recovery index');
325
+ }
326
+ sig = crypto_1.Secp256k1Signature.fromFixedLength(encoding_2.fromBase64(signature));
327
+ extendedSig = new crypto_1.ExtendedSecp256k1Signature(sig.r(), sig.s(), recoveryIndex);
328
+ _b.label = 1;
329
+ case 1:
330
+ _b.trys.push([1, 3, , 4]);
331
+ return [4 /*yield*/, crypto_1.Secp256k1.recoverPubkey(extendedSig, hash)];
332
+ case 2:
333
+ recoveredPubKey = _b.sent();
334
+ return [2 /*return*/, amino_1.pubkeyToAddress({
335
+ type: 'tendermint/PubKeySecp256k1',
336
+ value: encoding_2.toBase64(crypto_1.Secp256k1.compressPubkey(recoveredPubKey)),
337
+ }, 'firma')];
338
+ case 3:
339
+ _a = _b.sent();
340
+ return [2 /*return*/, null];
341
+ case 4: return [2 /*return*/];
342
+ }
343
+ });
344
+ });
345
+ };
346
+ FirmaUtil.verifySignature = function (address, signature, hash) {
347
+ return __awaiter(this, void 0, void 0, function () {
348
+ var i, recoveredAddress;
349
+ return __generator(this, function (_a) {
350
+ switch (_a.label) {
351
+ case 0:
352
+ i = 0;
353
+ _a.label = 1;
354
+ case 1:
355
+ if (!(i < 4)) return [3 /*break*/, 4];
356
+ return [4 /*yield*/, this.recoverSigningAddress(signature, hash, i)];
357
+ case 2:
358
+ recoveredAddress = _a.sent();
359
+ if (recoveredAddress === address) {
360
+ return [2 /*return*/, true];
361
+ }
362
+ _a.label = 3;
363
+ case 3:
364
+ i++;
365
+ return [3 /*break*/, 1];
366
+ case 4: return [2 /*return*/, false];
367
+ }
368
+ });
369
+ });
370
+ };
371
+ FirmaUtil.verifyDirectSignature = function (address, signature, signDoc) {
372
+ var messageHash = crypto_1.sha256(proto_signing_1.makeSignBytes(signDoc));
373
+ return this.verifySignature(address, signature, messageHash);
374
+ };
375
+ ;
376
+ FirmaUtil.parseSignDocValues = function (signDocString) {
377
+ return __assign(__assign({}, signDocString), { bodyBytes: encoding_2.fromHex(signDocString.bodyBytes), authInfoBytes: encoding_2.fromHex(signDocString.authInfoBytes), accountNumber: new long_1.default(signDocString.accountNumber) });
378
+ };
379
+ FirmaUtil.stringifySignDocValues = function (signDoc) {
380
+ return __assign(__assign({}, signDoc), { bodyBytes: encoding_2.toHex(signDoc.bodyBytes), authInfoBytes: encoding_2.toHex(signDoc.authInfoBytes), accountNumber: signDoc.accountNumber.toString(16) });
381
+ };
382
+ FirmaUtil.makeSignDoc = function (registry, signerAddress, messages, txMisc) {
383
+ if (txMisc === void 0) { txMisc = exports.DefaultTxMisc; }
384
+ return __awaiter(this, void 0, void 0, function () {
385
+ var result, chainID, serverUrl;
386
+ return __generator(this, function (_a) {
387
+ switch (_a.label) {
388
+ case 0:
389
+ result = FirmaUtil.getSignAndBroadcastOption(FirmaUtil.config.denom, txMisc);
390
+ chainID = FirmaUtil.config.chainID;
391
+ serverUrl = FirmaUtil.config.rpcAddress;
392
+ return [4 /*yield*/, signingstargateclient_1.SigningStargateClient.makeSignDocForSend(signerAddress, messages, result.fee, result.memo, serverUrl, chainID, registry)];
393
+ case 1: return [2 /*return*/, _a.sent()];
394
+ }
395
+ });
396
+ });
397
+ };
398
+ FirmaUtil.makeSignDocWithStringify = function (registry, signerAddress, messages, txMisc) {
399
+ if (txMisc === void 0) { txMisc = exports.DefaultTxMisc; }
400
+ return __awaiter(this, void 0, void 0, function () {
401
+ var signDoc, stringSignDoc;
402
+ return __generator(this, function (_a) {
403
+ switch (_a.label) {
404
+ case 0: return [4 /*yield*/, this.makeSignDoc(registry, signerAddress, messages, txMisc)];
405
+ case 1:
406
+ signDoc = _a.sent();
407
+ stringSignDoc = this.stringifySignDocValues(signDoc);
408
+ return [2 /*return*/, stringSignDoc];
409
+ }
410
+ });
411
+ });
412
+ };
413
+ FirmaUtil.getAnyData = function (registry, message) {
414
+ var anyData = any_1.Any.fromPartial({
415
+ typeUrl: message.typeUrl,
416
+ value: registry.encode(message)
417
+ });
418
+ return anyData;
419
+ };
227
420
  FirmaUtil.FctDecimal = 6;
228
421
  return FirmaUtil;
229
422
  }());
@@ -4,16 +4,19 @@ import { FirmaConfig } from "./FirmaConfig";
4
4
  import { SignAndBroadcastOptions } from "./firmachain/common";
5
5
  import { LedgerWalletInterface } from "./firmachain/common/LedgerWallet";
6
6
  import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
7
+ import { Secp256k1Wallet } from "@cosmjs/amino";
7
8
  export declare class FirmaWalletService {
8
9
  private readonly config;
9
10
  private mnemonic;
10
11
  private privateKey;
11
12
  private accountIndex;
13
+ private aminoWallet;
12
14
  private wallet;
13
15
  private ledger;
14
16
  getHdPath(): string;
15
17
  getPrefix(): string;
16
18
  getRawWallet(): DirectSecp256k1Wallet;
19
+ getRawAminoWallet(): Secp256k1Wallet;
17
20
  getPrivateKey(): string;
18
21
  getMnemonic(): string;
19
22
  isLedger(): boolean;
@@ -41,6 +41,7 @@ var proto_signing_1 = require("@cosmjs/proto-signing");
41
41
  var crypto_1 = require("@cosmjs/crypto");
42
42
  var FirmaUtil_1 = require("./FirmaUtil");
43
43
  var LedgerWallet_1 = require("./firmachain/common/LedgerWallet");
44
+ var amino_1 = require("@cosmjs/amino");
44
45
  var CryptoJS = require("crypto-js");
45
46
  var FirmaWalletService = /** @class */ (function () {
46
47
  function FirmaWalletService(config) {
@@ -58,6 +59,9 @@ var FirmaWalletService = /** @class */ (function () {
58
59
  FirmaWalletService.prototype.getRawWallet = function () {
59
60
  return this.wallet;
60
61
  };
62
+ FirmaWalletService.prototype.getRawAminoWallet = function () {
63
+ return this.aminoWallet;
64
+ };
61
65
  FirmaWalletService.prototype.getPrivateKey = function () {
62
66
  return this.privateKey;
63
67
  };
@@ -163,7 +167,7 @@ var FirmaWalletService = /** @class */ (function () {
163
167
  return [4 /*yield*/, crypto_1.Bip39.mnemonicToSeed(mnemonicChecked)];
164
168
  case 1:
165
169
  seed = _a.sent();
166
- hdpath = FirmaWalletService.getHdPath(this.getHdPath(), this.accountIndex);
170
+ hdpath = FirmaWalletService.getHdPath(this.getHdPath(), accountIndex);
167
171
  privkey = crypto_1.Slip10.derivePath(crypto_1.Slip10Curve.Secp256k1, seed, hdpath[0]).privkey;
168
172
  privateKey = "0x" + Buffer.from(privkey).toString("hex");
169
173
  return [2 /*return*/, privateKey];
@@ -178,23 +182,27 @@ var FirmaWalletService = /** @class */ (function () {
178
182
  };
179
183
  FirmaWalletService.prototype.initFromPrivateKey = function (privateKey) {
180
184
  return __awaiter(this, void 0, void 0, function () {
181
- var tempPrivateKey, _a, error_4;
182
- return __generator(this, function (_b) {
183
- switch (_b.label) {
185
+ var tempPrivateKey, _a, _b, error_4;
186
+ return __generator(this, function (_c) {
187
+ switch (_c.label) {
184
188
  case 0:
185
- _b.trys.push([0, 2, , 3]);
189
+ _c.trys.push([0, 3, , 4]);
186
190
  tempPrivateKey = Buffer.from(privateKey.replace("0x", ""), "hex");
187
191
  _a = this;
188
192
  return [4 /*yield*/, proto_signing_1.DirectSecp256k1Wallet.fromKey(tempPrivateKey, this.getPrefix())];
189
193
  case 1:
190
- _a.wallet = _b.sent();
191
- this.privateKey = privateKey;
192
- return [3 /*break*/, 3];
194
+ _a.wallet = _c.sent();
195
+ _b = this;
196
+ return [4 /*yield*/, amino_1.Secp256k1Wallet.fromKey(tempPrivateKey, this.getPrefix())];
193
197
  case 2:
194
- error_4 = _b.sent();
198
+ _b.aminoWallet = _c.sent();
199
+ this.privateKey = privateKey;
200
+ return [3 /*break*/, 4];
201
+ case 3:
202
+ error_4 = _c.sent();
195
203
  FirmaUtil_1.FirmaUtil.printLog(error_4);
196
204
  throw error_4;
197
- case 3: return [2 /*return*/];
205
+ case 4: return [2 /*return*/];
198
206
  }
199
207
  });
200
208
  });
@@ -1,5 +1,4 @@
1
- import { StdSignature } from "./signature";
2
- import { StdSignDoc } from "./signdoc";
1
+ import { StdSignature, StdSignDoc } from "@cosmjs/amino";
3
2
  export declare type Algo = "secp256k1" | "ed25519" | "sr25519";
4
3
  export interface AccountData {
5
4
  /** A printable address (typically bech32 encoded) */
@@ -0,0 +1,48 @@
1
+ import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
2
+ import { Pagination } from ".";
3
+ import { AuthorizationType } from "./AuthzTxTypes";
4
+ export interface GrantSendData {
5
+ authorization: authorization_send;
6
+ expiration: string;
7
+ }
8
+ export interface GrantGenericData {
9
+ authorization: authorization_generic;
10
+ expiration: string;
11
+ }
12
+ export interface GrantStakingData {
13
+ authorization: authorization_staking;
14
+ expiration: string;
15
+ }
16
+ export interface authorization_send {
17
+ "@type": string;
18
+ spend_limit: Coin[];
19
+ }
20
+ export interface authorization_generic {
21
+ "@type": string;
22
+ msg: string;
23
+ }
24
+ export interface authorization_staking {
25
+ "@type": string;
26
+ max_tokens: Coin;
27
+ allow_list: allowList;
28
+ authorization_type: string;
29
+ }
30
+ export interface allowList {
31
+ address: string[];
32
+ }
33
+ export declare class AuthzQueryClient {
34
+ private readonly axios;
35
+ constructor(baseUrl: string);
36
+ getSendGrantData(granterAddress: string, granteeAddress: string, paginationKey?: string): Promise<{
37
+ dataList: GrantSendData[];
38
+ pagination: Pagination;
39
+ }>;
40
+ getGenericGrantData(granterAddress: string, granteeAddress: string, msgType: string, paginationKey?: string): Promise<{
41
+ dataList: GrantGenericData[];
42
+ pagination: Pagination;
43
+ }>;
44
+ getStakingGrantData(granterAddress: string, granteeAddress: string, type: AuthorizationType, paginationKey?: string): Promise<{
45
+ dataList: GrantStakingData[];
46
+ pagination: Pagination;
47
+ }>;
48
+ }