@firmachain/firma-js 0.2.17 → 0.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.js +16 -0
  3. package/dist/sdk/FirmaBankService.d.ts +15 -0
  4. package/dist/sdk/FirmaBankService.js +211 -0
  5. package/dist/sdk/FirmaChainService.d.ts +8 -0
  6. package/dist/sdk/FirmaChainService.js +86 -0
  7. package/dist/sdk/FirmaConfig.d.ts +16 -0
  8. package/dist/sdk/FirmaConfig.js +55 -0
  9. package/dist/sdk/FirmaContractService.d.ts +30 -0
  10. package/dist/sdk/FirmaContractService.js +394 -0
  11. package/dist/sdk/FirmaDistributionService.d.ts +31 -0
  12. package/dist/sdk/FirmaDistributionService.js +524 -0
  13. package/dist/sdk/FirmaFeeGrantService.d.ts +21 -0
  14. package/dist/sdk/FirmaFeeGrantService.js +341 -0
  15. package/dist/sdk/FirmaGovService.d.ts +35 -0
  16. package/dist/sdk/FirmaGovService.js +775 -0
  17. package/dist/sdk/FirmaIpfsService.d.ts +12 -0
  18. package/dist/sdk/FirmaIpfsService.js +185 -0
  19. package/dist/sdk/FirmaMobileSDK.d.ts +27 -0
  20. package/dist/sdk/FirmaMobileSDK.js +45 -0
  21. package/dist/sdk/FirmaNftService.d.ts +28 -0
  22. package/dist/sdk/FirmaNftService.js +390 -0
  23. package/dist/sdk/FirmaSDK.d.ts +29 -0
  24. package/dist/sdk/FirmaSDK.js +48 -0
  25. package/dist/sdk/FirmaSlashingService.d.ts +9 -0
  26. package/dist/sdk/FirmaSlashingService.js +105 -0
  27. package/dist/sdk/FirmaStakingService.d.ts +34 -0
  28. package/dist/sdk/FirmaStakingService.js +604 -0
  29. package/dist/sdk/FirmaTokenService.d.ts +26 -0
  30. package/dist/sdk/FirmaTokenService.js +416 -0
  31. package/dist/sdk/FirmaUtil.d.ts +25 -0
  32. package/dist/sdk/FirmaUtil.js +201 -0
  33. package/dist/sdk/FirmaWalletService.d.ts +40 -0
  34. package/dist/sdk/FirmaWalletService.js +309 -0
  35. package/dist/sdk/firmachain/amino/addresses.d.ts +5 -0
  36. package/dist/sdk/firmachain/amino/addresses.js +46 -0
  37. package/dist/sdk/firmachain/amino/aminomsgs.d.ts +281 -0
  38. package/dist/sdk/firmachain/amino/aminomsgs.js +77 -0
  39. package/dist/sdk/firmachain/amino/aminotypes.d.ts +22 -0
  40. package/dist/sdk/firmachain/amino/aminotypes.js +521 -0
  41. package/dist/sdk/firmachain/amino/coins.d.ts +30 -0
  42. package/dist/sdk/firmachain/amino/coins.js +69 -0
  43. package/dist/sdk/firmachain/amino/encoding.d.ts +24 -0
  44. package/dist/sdk/firmachain/amino/encoding.js +234 -0
  45. package/dist/sdk/firmachain/amino/multisig.d.ts +10 -0
  46. package/dist/sdk/firmachain/amino/multisig.js +42 -0
  47. package/dist/sdk/firmachain/amino/paths.d.ts +6 -0
  48. package/dist/sdk/firmachain/amino/paths.js +18 -0
  49. package/dist/sdk/firmachain/amino/pubkeys.d.ts +47 -0
  50. package/dist/sdk/firmachain/amino/pubkeys.js +29 -0
  51. package/dist/sdk/firmachain/amino/secp256k1hdwallet.d.ts +94 -0
  52. package/dist/sdk/firmachain/amino/secp256k1hdwallet.js +437 -0
  53. package/dist/sdk/firmachain/amino/secp256k1wallet.d.ts +23 -0
  54. package/dist/sdk/firmachain/amino/secp256k1wallet.js +141 -0
  55. package/dist/sdk/firmachain/amino/signature.d.ts +16 -0
  56. package/dist/sdk/firmachain/amino/signature.js +36 -0
  57. package/dist/sdk/firmachain/amino/signdoc.d.ts +26 -0
  58. package/dist/sdk/firmachain/amino/signdoc.js +42 -0
  59. package/dist/sdk/firmachain/amino/signer.d.ts +33 -0
  60. package/dist/sdk/firmachain/amino/signer.js +2 -0
  61. package/dist/sdk/firmachain/amino/stdtx.d.ts +15 -0
  62. package/dist/sdk/firmachain/amino/stdtx.js +17 -0
  63. package/dist/sdk/firmachain/amino/wallet.d.ts +32 -0
  64. package/dist/sdk/firmachain/amino/wallet.js +132 -0
  65. package/dist/sdk/firmachain/bank/BankQueryClient.d.ts +12 -0
  66. package/dist/sdk/firmachain/bank/BankQueryClient.js +116 -0
  67. package/dist/sdk/firmachain/bank/BankTxClient.d.ts +17 -0
  68. package/dist/sdk/firmachain/bank/BankTxClient.js +40 -0
  69. package/dist/sdk/firmachain/bank/index.d.ts +3 -0
  70. package/dist/sdk/firmachain/bank/index.js +15 -0
  71. package/dist/sdk/firmachain/common/ITxClient.d.ts +15 -0
  72. package/dist/sdk/firmachain/common/ITxClient.js +102 -0
  73. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +27 -0
  74. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +165 -0
  75. package/dist/sdk/firmachain/common/LedgerWallet.d.ts +9 -0
  76. package/dist/sdk/firmachain/common/LedgerWallet.js +150 -0
  77. package/dist/sdk/firmachain/common/QueryCommon.d.ts +4 -0
  78. package/dist/sdk/firmachain/common/QueryCommon.js +2 -0
  79. package/dist/sdk/firmachain/common/TendermintQueryClient.d.ts +42 -0
  80. package/dist/sdk/firmachain/common/TendermintQueryClient.js +108 -0
  81. package/dist/sdk/firmachain/common/TxCommon.d.ts +94 -0
  82. package/dist/sdk/firmachain/common/TxCommon.js +34 -0
  83. package/dist/sdk/firmachain/common/accounts.d.ts +16 -0
  84. package/dist/sdk/firmachain/common/accounts.js +64 -0
  85. package/dist/sdk/firmachain/common/index.d.ts +2 -0
  86. package/dist/sdk/firmachain/common/index.js +14 -0
  87. package/dist/sdk/firmachain/common/signing.d.ts +10 -0
  88. package/dist/sdk/firmachain/common/signing.js +75 -0
  89. package/dist/sdk/firmachain/common/signingstargateclient.d.ts +37 -0
  90. package/dist/sdk/firmachain/common/signingstargateclient.js +298 -0
  91. package/dist/sdk/firmachain/common/stargateclient.d.ts +46 -0
  92. package/dist/sdk/firmachain/common/stargateclient.js +211 -0
  93. package/dist/sdk/firmachain/contract/ContractQueryClient.d.ts +31 -0
  94. package/dist/sdk/firmachain/contract/ContractQueryClient.js +141 -0
  95. package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +17 -0
  96. package/dist/sdk/firmachain/contract/ContractTxClient.js +40 -0
  97. package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +69 -0
  98. package/dist/sdk/firmachain/contract/ContractTxTypes.js +483 -0
  99. package/dist/sdk/firmachain/contract/index.d.ts +3 -0
  100. package/dist/sdk/firmachain/contract/index.js +15 -0
  101. package/dist/sdk/firmachain/distribution/DistributionQueryClient.d.ts +18 -0
  102. package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +167 -0
  103. package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +27 -0
  104. package/dist/sdk/firmachain/distribution/DistributionTxClient.js +48 -0
  105. package/dist/sdk/firmachain/distribution/index.d.ts +3 -0
  106. package/dist/sdk/firmachain/distribution/index.js +15 -0
  107. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.d.ts +17 -0
  108. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +86 -0
  109. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +17 -0
  110. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +40 -0
  111. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +76 -0
  112. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +194 -0
  113. package/dist/sdk/firmachain/feegrant/index.d.ts +2 -0
  114. package/dist/sdk/firmachain/feegrant/index.js +15 -0
  115. package/dist/sdk/firmachain/google/protobuf/any.d.ts +128 -0
  116. package/dist/sdk/firmachain/google/protobuf/any.js +106 -0
  117. package/dist/sdk/firmachain/google/protobuf/descriptor.d.ts +996 -0
  118. package/dist/sdk/firmachain/google/protobuf/descriptor.js +5329 -0
  119. package/dist/sdk/firmachain/google/protobuf/duration.d.ts +91 -0
  120. package/dist/sdk/firmachain/google/protobuf/duration.js +107 -0
  121. package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +109 -0
  122. package/dist/sdk/firmachain/google/protobuf/timestamp.js +107 -0
  123. package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +61 -0
  124. package/dist/sdk/firmachain/gov/GovQueryClient.js +152 -0
  125. package/dist/sdk/firmachain/gov/GovTxClient.d.ts +22 -0
  126. package/dist/sdk/firmachain/gov/GovTxClient.js +44 -0
  127. package/dist/sdk/firmachain/gov/index.d.ts +3 -0
  128. package/dist/sdk/firmachain/gov/index.js +15 -0
  129. package/dist/sdk/firmachain/nft/NftQueryClient.d.ts +17 -0
  130. package/dist/sdk/firmachain/nft/NftQueryClient.js +121 -0
  131. package/dist/sdk/firmachain/nft/NftTxClient.d.ts +22 -0
  132. package/dist/sdk/firmachain/nft/NftTxClient.js +44 -0
  133. package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +86 -0
  134. package/dist/sdk/firmachain/nft/NftTxTypes.js +424 -0
  135. package/dist/sdk/firmachain/nft/index.d.ts +3 -0
  136. package/dist/sdk/firmachain/nft/index.js +15 -0
  137. package/dist/sdk/firmachain/slashing/SlashingQueryClient.d.ts +22 -0
  138. package/dist/sdk/firmachain/slashing/SlashingQueryClient.js +101 -0
  139. package/dist/sdk/firmachain/slashing/index.d.ts +2 -0
  140. package/dist/sdk/firmachain/slashing/index.js +14 -0
  141. package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +93 -0
  142. package/dist/sdk/firmachain/staking/StakingQueryClient.js +223 -0
  143. package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +32 -0
  144. package/dist/sdk/firmachain/staking/StakingTxClient.js +52 -0
  145. package/dist/sdk/firmachain/staking/index.d.ts +3 -0
  146. package/dist/sdk/firmachain/staking/index.js +15 -0
  147. package/dist/sdk/firmachain/token/TokenQueryClient.d.ts +24 -0
  148. package/dist/sdk/firmachain/token/TokenQueryClient.js +106 -0
  149. package/dist/sdk/firmachain/token/TokenTxClient.d.ts +27 -0
  150. package/dist/sdk/firmachain/token/TokenTxClient.js +48 -0
  151. package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +116 -0
  152. package/dist/sdk/firmachain/token/TokenTxTypes.js +685 -0
  153. package/dist/sdk/firmachain/token/index.d.ts +3 -0
  154. package/dist/sdk/firmachain/token/index.js +15 -0
  155. package/package.json +1 -1
@@ -0,0 +1,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 { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
6
+ export interface LedgerWalletInterface {
7
+ getAddress(): Promise<string>;
8
+ sign(message: string): Promise<Uint8Array>;
9
+ getPublicKey(): Promise<Uint8Array>;
10
+ }
11
+ export declare class FirmaWalletService {
12
+ private readonly config;
13
+ private mnemonic;
14
+ private privateKey;
15
+ private accountIndex;
16
+ private wallet;
17
+ private ledger;
18
+ getHdPath(): string;
19
+ getPrefix(): string;
20
+ getRawWallet(): DirectSecp256k1Wallet;
21
+ getPrivateKey(): string;
22
+ getMnemonic(): string;
23
+ isLedger(): boolean;
24
+ initFromLedger(ledger: LedgerWalletInterface): Promise<FirmaWalletService>;
25
+ signLedger(messages: EncodeObject[], option: SignAndBroadcastOptions, registry: Registry): Promise<TxRaw>;
26
+ getAddress(): Promise<string>;
27
+ constructor(config: FirmaConfig);
28
+ private static getHdPath;
29
+ initFromMnemonic(mnemonic: string, accountIndex?: number): Promise<{
30
+ success: boolean;
31
+ }>;
32
+ private getPrivateKeyInternal;
33
+ initFromPrivateKey(privateKey: string): Promise<void>;
34
+ decryptData(data: string): string;
35
+ encryptData(data: string): string;
36
+ newWallet(): Promise<FirmaWalletService>;
37
+ fromMnemonic(mnemonic: string, accountIndex?: number): Promise<FirmaWalletService>;
38
+ fromPrivateKey(privateKey: string): Promise<FirmaWalletService>;
39
+ generateMnemonic(): Promise<string>;
40
+ }
@@ -0,0 +1,309 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.FirmaWalletService = void 0;
40
+ var proto_signing_1 = require("@cosmjs/proto-signing");
41
+ var crypto_1 = require("@cosmjs/crypto");
42
+ var FirmaUtil_1 = require("./FirmaUtil");
43
+ var LedgerWallet_1 = require("./firmachain/common/LedgerWallet");
44
+ var CryptoJS = require("crypto-js");
45
+ var FirmaWalletService = /** @class */ (function () {
46
+ function FirmaWalletService(config) {
47
+ this.config = config;
48
+ this.mnemonic = "";
49
+ this.privateKey = "";
50
+ this.accountIndex = 0;
51
+ }
52
+ FirmaWalletService.prototype.getHdPath = function () {
53
+ return this.config.hdPath;
54
+ };
55
+ FirmaWalletService.prototype.getPrefix = function () {
56
+ return this.config.prefix;
57
+ };
58
+ FirmaWalletService.prototype.getRawWallet = function () {
59
+ return this.wallet;
60
+ };
61
+ FirmaWalletService.prototype.getPrivateKey = function () {
62
+ return this.privateKey;
63
+ };
64
+ FirmaWalletService.prototype.getMnemonic = function () {
65
+ return this.mnemonic;
66
+ };
67
+ FirmaWalletService.prototype.isLedger = function () {
68
+ return (this.ledger != null);
69
+ };
70
+ FirmaWalletService.prototype.initFromLedger = function (ledger) {
71
+ return __awaiter(this, void 0, void 0, function () {
72
+ var wallet;
73
+ return __generator(this, function (_a) {
74
+ try {
75
+ wallet = new FirmaWalletService(this.config);
76
+ wallet.ledger = ledger;
77
+ return [2 /*return*/, wallet];
78
+ }
79
+ catch (error) {
80
+ FirmaUtil_1.FirmaUtil.printLog(error);
81
+ throw error;
82
+ }
83
+ return [2 /*return*/];
84
+ });
85
+ });
86
+ };
87
+ FirmaWalletService.prototype.signLedger = function (messages, option, registry) {
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ return __generator(this, function (_a) {
90
+ switch (_a.label) {
91
+ case 0: return [4 /*yield*/, LedgerWallet_1.signFromLedger(this.ledger, messages, option, registry)];
92
+ case 1: return [2 /*return*/, _a.sent()];
93
+ }
94
+ });
95
+ });
96
+ };
97
+ FirmaWalletService.prototype.getAddress = function () {
98
+ return __awaiter(this, void 0, void 0, function () {
99
+ var accounts, error_1;
100
+ return __generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0:
103
+ _a.trys.push([0, 4, , 5]);
104
+ if (!(this.ledger != null)) return [3 /*break*/, 2];
105
+ return [4 /*yield*/, this.ledger.getAddress()];
106
+ case 1: return [2 /*return*/, _a.sent()];
107
+ case 2: return [4 /*yield*/, this.wallet.getAccounts()];
108
+ case 3:
109
+ accounts = _a.sent();
110
+ return [2 /*return*/, accounts[0].address];
111
+ case 4:
112
+ error_1 = _a.sent();
113
+ FirmaUtil_1.FirmaUtil.printLog(error_1);
114
+ throw error_1;
115
+ case 5: return [2 /*return*/];
116
+ }
117
+ });
118
+ });
119
+ };
120
+ FirmaWalletService.getHdPath = function (hdPath, accountIndex) {
121
+ try {
122
+ return [crypto_1.stringToPath(hdPath + accountIndex + "'/0/0")];
123
+ }
124
+ catch (error) {
125
+ FirmaUtil_1.FirmaUtil.printLog(error);
126
+ throw error;
127
+ }
128
+ };
129
+ FirmaWalletService.prototype.initFromMnemonic = function (mnemonic, accountIndex) {
130
+ if (accountIndex === void 0) { accountIndex = 0; }
131
+ return __awaiter(this, void 0, void 0, function () {
132
+ var privateKey, error_2;
133
+ return __generator(this, function (_a) {
134
+ switch (_a.label) {
135
+ case 0:
136
+ _a.trys.push([0, 3, , 4]);
137
+ this.mnemonic = mnemonic;
138
+ this.accountIndex = accountIndex;
139
+ return [4 /*yield*/, this.getPrivateKeyInternal(this.mnemonic, this.accountIndex)];
140
+ case 1:
141
+ privateKey = _a.sent();
142
+ return [4 /*yield*/, this.initFromPrivateKey(privateKey)];
143
+ case 2:
144
+ _a.sent();
145
+ return [2 /*return*/, { success: true }];
146
+ case 3:
147
+ error_2 = _a.sent();
148
+ FirmaUtil_1.FirmaUtil.printLog(error_2);
149
+ throw error_2;
150
+ case 4: return [2 /*return*/];
151
+ }
152
+ });
153
+ });
154
+ };
155
+ FirmaWalletService.prototype.getPrivateKeyInternal = function (mnemonic, accountIndex) {
156
+ return __awaiter(this, void 0, void 0, function () {
157
+ var mnemonicChecked, seed, hdpath, privkey, privateKey, error_3;
158
+ return __generator(this, function (_a) {
159
+ switch (_a.label) {
160
+ case 0:
161
+ _a.trys.push([0, 2, , 3]);
162
+ mnemonicChecked = new crypto_1.EnglishMnemonic(mnemonic);
163
+ return [4 /*yield*/, crypto_1.Bip39.mnemonicToSeed(mnemonicChecked)];
164
+ case 1:
165
+ seed = _a.sent();
166
+ hdpath = FirmaWalletService.getHdPath(this.getHdPath(), this.accountIndex);
167
+ privkey = crypto_1.Slip10.derivePath(crypto_1.Slip10Curve.Secp256k1, seed, hdpath[0]).privkey;
168
+ privateKey = "0x" + Buffer.from(privkey).toString("hex");
169
+ return [2 /*return*/, privateKey];
170
+ case 2:
171
+ error_3 = _a.sent();
172
+ FirmaUtil_1.FirmaUtil.printLog(error_3);
173
+ throw error_3;
174
+ case 3: return [2 /*return*/];
175
+ }
176
+ });
177
+ });
178
+ };
179
+ FirmaWalletService.prototype.initFromPrivateKey = function (privateKey) {
180
+ return __awaiter(this, void 0, void 0, function () {
181
+ var tempPrivateKey, _a, error_4;
182
+ return __generator(this, function (_b) {
183
+ switch (_b.label) {
184
+ case 0:
185
+ _b.trys.push([0, 2, , 3]);
186
+ tempPrivateKey = Buffer.from(privateKey.replace("0x", ""), "hex");
187
+ _a = this;
188
+ return [4 /*yield*/, proto_signing_1.DirectSecp256k1Wallet.fromKey(tempPrivateKey, this.getPrefix())];
189
+ case 1:
190
+ _a.wallet = _b.sent();
191
+ this.privateKey = privateKey;
192
+ return [3 /*break*/, 3];
193
+ case 2:
194
+ error_4 = _b.sent();
195
+ FirmaUtil_1.FirmaUtil.printLog(error_4);
196
+ throw error_4;
197
+ case 3: return [2 /*return*/];
198
+ }
199
+ });
200
+ });
201
+ };
202
+ FirmaWalletService.prototype.decryptData = function (data) {
203
+ try {
204
+ var bytes = CryptoJS.AES.decrypt(data, this.getPrivateKey());
205
+ return bytes.toString(CryptoJS.enc.Utf8);
206
+ }
207
+ catch (error) {
208
+ FirmaUtil_1.FirmaUtil.printLog(error);
209
+ throw error;
210
+ }
211
+ };
212
+ FirmaWalletService.prototype.encryptData = function (data) {
213
+ try {
214
+ return CryptoJS.AES.encrypt(data, this.getPrivateKey()).toString();
215
+ }
216
+ catch (error) {
217
+ FirmaUtil_1.FirmaUtil.printLog(error);
218
+ throw error;
219
+ }
220
+ };
221
+ FirmaWalletService.prototype.newWallet = function () {
222
+ return __awaiter(this, void 0, void 0, function () {
223
+ var mnemonic, wallet, error_5;
224
+ return __generator(this, function (_a) {
225
+ switch (_a.label) {
226
+ case 0:
227
+ _a.trys.push([0, 3, , 4]);
228
+ return [4 /*yield*/, this.generateMnemonic()];
229
+ case 1:
230
+ mnemonic = _a.sent();
231
+ return [4 /*yield*/, this.fromMnemonic(mnemonic)];
232
+ case 2:
233
+ wallet = _a.sent();
234
+ return [2 /*return*/, wallet];
235
+ case 3:
236
+ error_5 = _a.sent();
237
+ FirmaUtil_1.FirmaUtil.printLog(error_5);
238
+ throw error_5;
239
+ case 4: return [2 /*return*/];
240
+ }
241
+ });
242
+ });
243
+ };
244
+ FirmaWalletService.prototype.fromMnemonic = function (mnemonic, accountIndex) {
245
+ if (accountIndex === void 0) { accountIndex = 0; }
246
+ return __awaiter(this, void 0, void 0, function () {
247
+ var wallet, error_6;
248
+ return __generator(this, function (_a) {
249
+ switch (_a.label) {
250
+ case 0:
251
+ _a.trys.push([0, 2, , 3]);
252
+ wallet = new FirmaWalletService(this.config);
253
+ return [4 /*yield*/, wallet.initFromMnemonic(mnemonic, accountIndex)];
254
+ case 1:
255
+ _a.sent();
256
+ return [2 /*return*/, wallet];
257
+ case 2:
258
+ error_6 = _a.sent();
259
+ FirmaUtil_1.FirmaUtil.printLog(error_6);
260
+ throw error_6;
261
+ case 3: return [2 /*return*/];
262
+ }
263
+ });
264
+ });
265
+ };
266
+ FirmaWalletService.prototype.fromPrivateKey = function (privateKey) {
267
+ return __awaiter(this, void 0, void 0, function () {
268
+ var wallet, error_7;
269
+ return __generator(this, function (_a) {
270
+ switch (_a.label) {
271
+ case 0:
272
+ _a.trys.push([0, 2, , 3]);
273
+ wallet = new FirmaWalletService(this.config);
274
+ return [4 /*yield*/, wallet.initFromPrivateKey(privateKey)];
275
+ case 1:
276
+ _a.sent();
277
+ return [2 /*return*/, wallet];
278
+ case 2:
279
+ error_7 = _a.sent();
280
+ FirmaUtil_1.FirmaUtil.printLog(error_7);
281
+ throw error_7;
282
+ case 3: return [2 /*return*/];
283
+ }
284
+ });
285
+ });
286
+ };
287
+ FirmaWalletService.prototype.generateMnemonic = function () {
288
+ return __awaiter(this, void 0, void 0, function () {
289
+ var wallet, error_8;
290
+ return __generator(this, function (_a) {
291
+ switch (_a.label) {
292
+ case 0:
293
+ _a.trys.push([0, 2, , 3]);
294
+ return [4 /*yield*/, proto_signing_1.DirectSecp256k1HdWallet.generate(24)];
295
+ case 1:
296
+ wallet = _a.sent();
297
+ return [2 /*return*/, wallet.mnemonic];
298
+ case 2:
299
+ error_8 = _a.sent();
300
+ FirmaUtil_1.FirmaUtil.printLog(error_8);
301
+ throw error_8;
302
+ case 3: return [2 /*return*/];
303
+ }
304
+ });
305
+ });
306
+ };
307
+ return FirmaWalletService;
308
+ }());
309
+ exports.FirmaWalletService = FirmaWalletService;
@@ -0,0 +1,5 @@
1
+ import { Pubkey } from "./pubkeys";
2
+ export declare function rawEd25519PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8Array;
3
+ export declare function rawSecp256k1PubkeyToRawAddress(pubkeyData: Uint8Array): Uint8Array;
4
+ export declare function pubkeyToRawAddress(pubkey: Pubkey): Uint8Array;
5
+ export declare function pubkeyToAddress(pubkey: Pubkey, prefix: string): string;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ // See https://github.com/tendermint/tendermint/blob/f2ada0a604b4c0763bda2f64fac53d506d3beca7/docs/spec/blockchain/encoding.md#public-key-cryptography
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.pubkeyToAddress = exports.pubkeyToRawAddress = exports.rawSecp256k1PubkeyToRawAddress = exports.rawEd25519PubkeyToRawAddress = void 0;
5
+ var crypto_1 = require("@cosmjs/crypto");
6
+ var encoding_1 = require("@cosmjs/encoding");
7
+ var encoding_2 = require("./encoding");
8
+ var pubkeys_1 = require("./pubkeys");
9
+ function rawEd25519PubkeyToRawAddress(pubkeyData) {
10
+ if (pubkeyData.length !== 32) {
11
+ throw new Error("Invalid Ed25519 pubkey length: " + pubkeyData.length);
12
+ }
13
+ return crypto_1.sha256(pubkeyData).slice(0, 20);
14
+ }
15
+ exports.rawEd25519PubkeyToRawAddress = rawEd25519PubkeyToRawAddress;
16
+ function rawSecp256k1PubkeyToRawAddress(pubkeyData) {
17
+ if (pubkeyData.length !== 33) {
18
+ throw new Error("Invalid Secp256k1 pubkey length (compressed): " + pubkeyData.length);
19
+ }
20
+ return crypto_1.ripemd160(crypto_1.sha256(pubkeyData));
21
+ }
22
+ exports.rawSecp256k1PubkeyToRawAddress = rawSecp256k1PubkeyToRawAddress;
23
+ // For secp256k1 this assumes we already have a compressed pubkey.
24
+ function pubkeyToRawAddress(pubkey) {
25
+ if (pubkeys_1.isSecp256k1Pubkey(pubkey)) {
26
+ var pubkeyData = encoding_1.fromBase64(pubkey.value);
27
+ return rawSecp256k1PubkeyToRawAddress(pubkeyData);
28
+ }
29
+ else if (pubkeys_1.isEd25519Pubkey(pubkey)) {
30
+ var pubkeyData = encoding_1.fromBase64(pubkey.value);
31
+ return rawEd25519PubkeyToRawAddress(pubkeyData);
32
+ }
33
+ else if (pubkeys_1.isMultisigThresholdPubkey(pubkey)) {
34
+ // https://github.com/tendermint/tendermint/blob/38b401657e4ad7a7eeb3c30a3cbf512037df3740/crypto/multisig/threshold_pubkey.go#L71-L74
35
+ var pubkeyData = encoding_2.encodeAminoPubkey(pubkey);
36
+ return crypto_1.sha256(pubkeyData).slice(0, 20);
37
+ }
38
+ else {
39
+ throw new Error("Unsupported public key type");
40
+ }
41
+ }
42
+ exports.pubkeyToRawAddress = pubkeyToRawAddress;
43
+ function pubkeyToAddress(pubkey, prefix) {
44
+ return encoding_1.Bech32.encode(prefix, pubkeyToRawAddress(pubkey));
45
+ }
46
+ exports.pubkeyToAddress = pubkeyToAddress;
@@ -0,0 +1,281 @@
1
+ import { Coin } from "./coins";
2
+ import { AminoMsg } from "./signdoc";
3
+ /** A high level transaction of the coin module */
4
+ export interface AminoMsgSend extends AminoMsg {
5
+ readonly type: "cosmos-sdk/MsgSend";
6
+ readonly value: {
7
+ /** Bech32 account address */
8
+ readonly from_address: string;
9
+ /** Bech32 account address */
10
+ readonly to_address: string;
11
+ readonly amount: readonly Coin[];
12
+ };
13
+ }
14
+ export declare function isAminoMsgSend(msg: AminoMsg): msg is AminoMsgSend;
15
+ interface Input {
16
+ /** Bech32 account address */
17
+ readonly address: string;
18
+ readonly coins: readonly Coin[];
19
+ }
20
+ interface Output {
21
+ /** Bech32 account address */
22
+ readonly address: string;
23
+ readonly coins: readonly Coin[];
24
+ }
25
+ /** A high level transaction of the coin module */
26
+ export interface AminoMsgMultiSend extends AminoMsg {
27
+ readonly type: "cosmos-sdk/MsgMultiSend";
28
+ readonly value: {
29
+ readonly inputs: readonly Input[];
30
+ readonly outputs: readonly Output[];
31
+ };
32
+ }
33
+ export declare function isAminoMsgMultiSend(msg: AminoMsg): msg is AminoMsgMultiSend;
34
+ /** Verifies a particular invariance */
35
+ export interface AminoMsgVerifyInvariant extends AminoMsg {
36
+ readonly type: "cosmos-sdk/MsgVerifyInvariant";
37
+ readonly value: {
38
+ /** Bech32 account address */
39
+ readonly sender: string;
40
+ readonly invariant_module_name: string;
41
+ readonly invariant_route: string;
42
+ };
43
+ }
44
+ export declare function isAminoMsgVerifyInvariant(msg: AminoMsg): msg is AminoMsgVerifyInvariant;
45
+ /** Changes the withdraw address for a delegator (or validator self-delegation) */
46
+ export interface AminoMsgSetWithdrawAddress extends AminoMsg {
47
+ readonly type: "cosmos-sdk/MsgModifyWithdrawAddress";
48
+ readonly value: {
49
+ /** Bech32 account address */
50
+ readonly delegator_address: string;
51
+ /** Bech32 account address */
52
+ readonly withdraw_address: string;
53
+ };
54
+ }
55
+ export declare function isAminoMsgSetWithdrawAddress(msg: AminoMsg): msg is AminoMsgSetWithdrawAddress;
56
+ /** Message for delegation withdraw from a single validator */
57
+ export interface AminoMsgWithdrawDelegatorReward extends AminoMsg {
58
+ readonly type: "cosmos-sdk/MsgWithdrawDelegationReward";
59
+ readonly value: {
60
+ /** Bech32 account address */
61
+ readonly delegator_address: string;
62
+ /** Bech32 account address */
63
+ readonly validator_address: string;
64
+ };
65
+ }
66
+ export declare function isAminoMsgWithdrawDelegatorReward(msg: AminoMsg): msg is AminoMsgWithdrawDelegatorReward;
67
+ /** Message for validator withdraw */
68
+ export interface AminoMsgWithdrawValidatorCommission extends AminoMsg {
69
+ readonly type: "cosmos-sdk/MsgWithdrawValidatorCommission";
70
+ readonly value: {
71
+ /** Bech32 account address */
72
+ readonly validator_address: string;
73
+ };
74
+ }
75
+ export declare function isAminoMsgWithdrawValidatorCommission(msg: AminoMsg): msg is AminoMsgWithdrawValidatorCommission;
76
+ /** Allows an account to directly fund the community pool. */
77
+ export interface AminoMsgFundCommunityPool extends AminoMsg {
78
+ readonly type: "cosmos-sdk/MsgFundCommunityPool";
79
+ readonly value: {
80
+ readonly amount: readonly Coin[];
81
+ /** Bech32 account address */
82
+ readonly depositor: string;
83
+ };
84
+ }
85
+ export declare function isAminoMsgFundCommunityPool(msg: AminoMsg): msg is AminoMsgFundCommunityPool;
86
+ interface Any {
87
+ readonly type_url: string;
88
+ readonly value: Uint8Array;
89
+ }
90
+ /** Supports submitting arbitrary evidence */
91
+ export interface AminoMsgSubmitEvidence extends AminoMsg {
92
+ readonly type: "cosmos-sdk/MsgSubmitEvidence";
93
+ readonly value: {
94
+ /** Bech32 account address */
95
+ readonly submitter: string;
96
+ readonly evidence: Any;
97
+ };
98
+ }
99
+ export declare function isAminoMsgSubmitEvidence(msg: AminoMsg): msg is AminoMsgSubmitEvidence;
100
+ /** Supports submitting arbitrary proposal content. */
101
+ export interface AminoMsgSubmitProposal extends AminoMsg {
102
+ readonly type: "cosmos-sdk/MsgSubmitProposal";
103
+ readonly value: {
104
+ /**
105
+ * A proposal structure, e.g.
106
+ *
107
+ * ```
108
+ * {
109
+ * type: 'cosmos-sdk/TextProposal',
110
+ * value: {
111
+ * description: 'This proposal proposes to test whether this proposal passes',
112
+ * title: 'Test Proposal'
113
+ * }
114
+ * }
115
+ * ```
116
+ */
117
+ readonly content: {
118
+ readonly type: string;
119
+ readonly value: any;
120
+ };
121
+ readonly initial_deposit: readonly Coin[];
122
+ /** Bech32 account address */
123
+ readonly proposer: string;
124
+ };
125
+ }
126
+ export declare function isAminoMsgSubmitProposal(msg: AminoMsg): msg is AminoMsgSubmitProposal;
127
+ /** Casts a vote */
128
+ export interface AminoMsgVote extends AminoMsg {
129
+ readonly type: "cosmos-sdk/MsgVote";
130
+ readonly value: {
131
+ readonly proposal_id: string;
132
+ /** Bech32 account address */
133
+ readonly voter: string;
134
+ /**
135
+ * VoteOption as integer from 0 to 4 🤷‍
136
+ *
137
+ * @see https://github.com/cosmos/cosmos-sdk/blob/v0.42.9/x/gov/types/gov.pb.go#L38-L49
138
+ */
139
+ readonly option: number;
140
+ };
141
+ }
142
+ export declare function isAminoMsgVote(msg: AminoMsg): msg is AminoMsgVote;
143
+ /** Submits a deposit to an existing proposal */
144
+ export interface AminoMsgDeposit extends AminoMsg {
145
+ readonly type: "cosmos-sdk/MsgDeposit";
146
+ readonly value: {
147
+ readonly proposal_id: string;
148
+ /** Bech32 account address */
149
+ readonly depositor: string;
150
+ readonly amount: readonly Coin[];
151
+ };
152
+ }
153
+ export declare function isAminoMsgDeposit(msg: AminoMsg): msg is AminoMsgDeposit;
154
+ /** Unjails a jailed validator */
155
+ export interface AminoMsgUnjail extends AminoMsg {
156
+ readonly type: "cosmos-sdk/MsgUnjail";
157
+ readonly value: {
158
+ /** Bech32 account address */
159
+ readonly validator_addr: string;
160
+ };
161
+ }
162
+ export declare function isAminoMsgUnjail(msg: AminoMsg): msg is AminoMsgUnjail;
163
+ /** The initial commission rates to be used for creating a validator */
164
+ interface CommissionRates {
165
+ readonly rate: string;
166
+ readonly max_rate: string;
167
+ readonly max_change_rate: string;
168
+ }
169
+ /** A validator description. */
170
+ interface Description {
171
+ readonly moniker: string;
172
+ readonly identity: string;
173
+ readonly website: string;
174
+ readonly security_contact: string;
175
+ readonly details: string;
176
+ }
177
+ /** Creates a new validator. */
178
+ export interface AminoMsgCreateValidator extends AminoMsg {
179
+ readonly type: "cosmos-sdk/MsgCreateValidator";
180
+ readonly value: {
181
+ readonly description: Description;
182
+ readonly commission: CommissionRates;
183
+ readonly min_self_delegation: string;
184
+ /** Bech32 encoded delegator address */
185
+ readonly delegator_address: string;
186
+ /** Bech32 encoded validator address */
187
+ readonly validator_address: string;
188
+ /** Bech32 encoded public key */
189
+ readonly pubkey: string;
190
+ readonly value: Coin;
191
+ };
192
+ }
193
+ export declare function isAminoMsgCreateValidator(msg: AminoMsg): msg is AminoMsgCreateValidator;
194
+ /** Edits an existing validator. */
195
+ export interface AminoMsgEditValidator extends AminoMsg {
196
+ readonly type: "cosmos-sdk/MsgEditValidator";
197
+ readonly value: {
198
+ readonly description: Description;
199
+ /** Bech32 encoded validator address */
200
+ readonly validator_address: string;
201
+ readonly commission_rate: string;
202
+ readonly min_self_delegation: string;
203
+ };
204
+ }
205
+ export declare function isAminoMsgEditValidator(msg: AminoMsg): msg is AminoMsgEditValidator;
206
+ /**
207
+ * Performs a delegation from a delegate to a validator.
208
+ *
209
+ * @see https://docs.cosmos.network/master/modules/staking/03_messages.html#msgdelegate
210
+ */
211
+ export interface AminoMsgDelegate extends AminoMsg {
212
+ readonly type: "cosmos-sdk/MsgDelegate";
213
+ readonly value: {
214
+ /** Bech32 encoded delegator address */
215
+ readonly delegator_address: string;
216
+ /** Bech32 encoded validator address */
217
+ readonly validator_address: string;
218
+ readonly amount: Coin;
219
+ };
220
+ }
221
+ export declare function isAminoMsgDelegate(msg: AminoMsg): msg is AminoMsgDelegate;
222
+ /** Performs a redelegation from a delegate and source validator to a destination validator */
223
+ export interface AminoMsgBeginRedelegate extends AminoMsg {
224
+ readonly type: "cosmos-sdk/MsgBeginRedelegate";
225
+ readonly value: {
226
+ /** Bech32 encoded delegator address */
227
+ readonly delegator_address: string;
228
+ /** Bech32 encoded source validator address */
229
+ readonly validator_src_address: string;
230
+ /** Bech32 encoded destination validator address */
231
+ readonly validator_dst_address: string;
232
+ readonly amount: Coin;
233
+ };
234
+ }
235
+ export declare function isAminoMsgBeginRedelegate(msg: AminoMsg): msg is AminoMsgBeginRedelegate;
236
+ /** Performs an undelegation from a delegate and a validator */
237
+ export interface AminoMsgUndelegate extends AminoMsg {
238
+ readonly type: "cosmos-sdk/MsgUndelegate";
239
+ readonly value: {
240
+ /** Bech32 encoded delegator address */
241
+ readonly delegator_address: string;
242
+ /** Bech32 encoded validator address */
243
+ readonly validator_address: string;
244
+ readonly amount: Coin;
245
+ };
246
+ }
247
+ export declare function isAminoMsgUndelegate(msg: AminoMsg): msg is AminoMsgUndelegate;
248
+ interface AminoHeight {
249
+ /** 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/core/02-client/types/client.pb.go#L252). */
250
+ readonly revision_number?: string;
251
+ /** 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/core/02-client/types/client.pb.go#L254). */
252
+ readonly revision_height?: string;
253
+ }
254
+ /** Transfers fungible tokens (i.e Coins) between ICS20 enabled chains */
255
+ export interface AminoMsgTransfer extends AminoMsg {
256
+ readonly type: "cosmos-sdk/MsgTransfer";
257
+ readonly value: {
258
+ readonly source_port: string;
259
+ readonly source_channel: string;
260
+ readonly token?: Coin;
261
+ /** Bech32 account address */
262
+ readonly sender: string;
263
+ /** Bech32 account address */
264
+ readonly receiver: string;
265
+ /**
266
+ * The timeout as a (revision_number, revision_height) pair.
267
+ *
268
+ * This fied is is non-optional (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/applications/transfer/types/tx.pb.go#L49).
269
+ * In order to not set the timeout height, set it to {}.
270
+ */
271
+ readonly timeout_height: AminoHeight;
272
+ /**
273
+ * Timeout timestamp (in nanoseconds). The timeout is disabled when set to 0.
274
+ *
275
+ * 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/applications/transfer/types/tx.pb.go#L52).
276
+ */
277
+ readonly timeout_timestamp?: string;
278
+ };
279
+ }
280
+ export declare function isAminoMsgTransfer(msg: AminoMsg): msg is AminoMsgTransfer;
281
+ export {};