@firmachain/firma-js 0.2.37 → 0.2.40

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 (181) hide show
  1. package/dist/index.d.ts +16 -0
  2. package/dist/index.js +32 -0
  3. package/dist/sdk/FirmaAuthzService.d.ts +41 -0
  4. package/dist/sdk/FirmaAuthzService.js +633 -0
  5. package/dist/sdk/FirmaBankService.d.ts +17 -0
  6. package/dist/sdk/FirmaBankService.js +236 -0
  7. package/dist/sdk/FirmaChainService.d.ts +8 -0
  8. package/dist/sdk/FirmaChainService.js +86 -0
  9. package/dist/sdk/FirmaConfig.d.ts +18 -0
  10. package/dist/sdk/FirmaConfig.js +63 -0
  11. package/dist/sdk/FirmaContractService.d.ts +32 -0
  12. package/dist/sdk/FirmaContractService.js +434 -0
  13. package/dist/sdk/FirmaCosmWasmService.d.ts +38 -0
  14. package/dist/sdk/FirmaCosmWasmService.js +667 -0
  15. package/dist/sdk/FirmaDistributionService.d.ts +32 -0
  16. package/dist/sdk/FirmaDistributionService.js +527 -0
  17. package/dist/sdk/FirmaFeeGrantService.d.ts +21 -0
  18. package/dist/sdk/FirmaFeeGrantService.js +341 -0
  19. package/dist/sdk/FirmaGovService.d.ts +35 -0
  20. package/dist/sdk/FirmaGovService.js +775 -0
  21. package/dist/sdk/FirmaIbcService.d.ts +15 -0
  22. package/dist/sdk/FirmaIbcService.js +144 -0
  23. package/dist/sdk/FirmaIpfsService.d.ts +10 -0
  24. package/dist/sdk/FirmaIpfsService.js +143 -0
  25. package/dist/sdk/FirmaMobileSDK.d.ts +29 -0
  26. package/dist/sdk/FirmaMobileSDK.js +48 -0
  27. package/dist/sdk/FirmaNftService.d.ts +31 -0
  28. package/dist/sdk/FirmaNftService.js +372 -0
  29. package/dist/sdk/FirmaSDK.d.ts +35 -0
  30. package/dist/sdk/FirmaSDK.js +57 -0
  31. package/dist/sdk/FirmaSlashingService.d.ts +9 -0
  32. package/dist/sdk/FirmaSlashingService.js +105 -0
  33. package/dist/sdk/FirmaStakingService.d.ts +47 -0
  34. package/dist/sdk/FirmaStakingService.js +611 -0
  35. package/dist/sdk/FirmaTokenService.d.ts +26 -0
  36. package/dist/sdk/FirmaTokenService.js +416 -0
  37. package/dist/sdk/FirmaUtil.d.ts +56 -0
  38. package/dist/sdk/FirmaUtil.js +430 -0
  39. package/dist/sdk/FirmaWalletService.d.ts +39 -0
  40. package/dist/sdk/FirmaWalletService.js +317 -0
  41. package/dist/sdk/firmachain/amino/addresses.d.ts +5 -0
  42. package/dist/sdk/firmachain/amino/addresses.js +46 -0
  43. package/dist/sdk/firmachain/amino/aminomsgs.d.ts +281 -0
  44. package/dist/sdk/firmachain/amino/aminomsgs.js +77 -0
  45. package/dist/sdk/firmachain/amino/aminotypes.d.ts +22 -0
  46. package/dist/sdk/firmachain/amino/aminotypes.js +525 -0
  47. package/dist/sdk/firmachain/amino/coins.d.ts +30 -0
  48. package/dist/sdk/firmachain/amino/coins.js +69 -0
  49. package/dist/sdk/firmachain/amino/encoding.d.ts +24 -0
  50. package/dist/sdk/firmachain/amino/encoding.js +238 -0
  51. package/dist/sdk/firmachain/amino/multisig.d.ts +10 -0
  52. package/dist/sdk/firmachain/amino/multisig.js +42 -0
  53. package/dist/sdk/firmachain/amino/paths.d.ts +6 -0
  54. package/dist/sdk/firmachain/amino/paths.js +18 -0
  55. package/dist/sdk/firmachain/amino/pubkeys.d.ts +47 -0
  56. package/dist/sdk/firmachain/amino/pubkeys.js +29 -0
  57. package/dist/sdk/firmachain/amino/signature.d.ts +16 -0
  58. package/dist/sdk/firmachain/amino/signature.js +36 -0
  59. package/dist/sdk/firmachain/amino/signdoc.d.ts +26 -0
  60. package/dist/sdk/firmachain/amino/signdoc.js +42 -0
  61. package/dist/sdk/firmachain/amino/signer.d.ts +32 -0
  62. package/dist/sdk/firmachain/amino/signer.js +2 -0
  63. package/dist/sdk/firmachain/amino/stdtx.d.ts +15 -0
  64. package/dist/sdk/firmachain/amino/stdtx.js +17 -0
  65. package/dist/sdk/firmachain/amino/wallet.d.ts +32 -0
  66. package/dist/sdk/firmachain/amino/wallet.js +136 -0
  67. package/dist/sdk/firmachain/authz/AuthzQueryClient.d.ts +48 -0
  68. package/dist/sdk/firmachain/authz/AuthzQueryClient.js +142 -0
  69. package/dist/sdk/firmachain/authz/AuthzTxClient.d.ts +23 -0
  70. package/dist/sdk/firmachain/authz/AuthzTxClient.js +47 -0
  71. package/dist/sdk/firmachain/authz/AuthzTxTypes.d.ts +147 -0
  72. package/dist/sdk/firmachain/authz/AuthzTxTypes.js +358 -0
  73. package/dist/sdk/firmachain/authz/index.d.ts +4 -0
  74. package/dist/sdk/firmachain/authz/index.js +20 -0
  75. package/dist/sdk/firmachain/bank/BankQueryClient.d.ts +12 -0
  76. package/dist/sdk/firmachain/bank/BankQueryClient.js +116 -0
  77. package/dist/sdk/firmachain/bank/BankTxClient.d.ts +18 -0
  78. package/dist/sdk/firmachain/bank/BankTxClient.js +43 -0
  79. package/dist/sdk/firmachain/bank/index.d.ts +3 -0
  80. package/dist/sdk/firmachain/bank/index.js +19 -0
  81. package/dist/sdk/firmachain/common/CommonTxClient.d.ts +7 -0
  82. package/dist/sdk/firmachain/common/CommonTxClient.js +79 -0
  83. package/dist/sdk/firmachain/common/ITxClient.d.ts +18 -0
  84. package/dist/sdk/firmachain/common/ITxClient.js +117 -0
  85. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +27 -0
  86. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +165 -0
  87. package/dist/sdk/firmachain/common/LedgerWallet.d.ts +14 -0
  88. package/dist/sdk/firmachain/common/LedgerWallet.js +151 -0
  89. package/dist/sdk/firmachain/common/QueryCommon.d.ts +4 -0
  90. package/dist/sdk/firmachain/common/QueryCommon.js +2 -0
  91. package/dist/sdk/firmachain/common/TendermintQueryClient.d.ts +42 -0
  92. package/dist/sdk/firmachain/common/TendermintQueryClient.js +111 -0
  93. package/dist/sdk/firmachain/common/TxCommon.d.ts +87 -0
  94. package/dist/sdk/firmachain/common/TxCommon.js +18 -0
  95. package/dist/sdk/firmachain/common/accounts.d.ts +16 -0
  96. package/dist/sdk/firmachain/common/accounts.js +64 -0
  97. package/dist/sdk/firmachain/common/index.d.ts +2 -0
  98. package/dist/sdk/firmachain/common/index.js +18 -0
  99. package/dist/sdk/firmachain/common/signing.d.ts +10 -0
  100. package/dist/sdk/firmachain/common/signing.js +79 -0
  101. package/dist/sdk/firmachain/common/signingaminostargateclient.d.ts +50 -0
  102. package/dist/sdk/firmachain/common/signingaminostargateclient.js +267 -0
  103. package/dist/sdk/firmachain/common/signingstargateclient.d.ts +44 -0
  104. package/dist/sdk/firmachain/common/signingstargateclient.js +361 -0
  105. package/dist/sdk/firmachain/common/stargateclient.d.ts +46 -0
  106. package/dist/sdk/firmachain/common/stargateclient.js +211 -0
  107. package/dist/sdk/firmachain/contract/ContractQueryClient.d.ts +32 -0
  108. package/dist/sdk/firmachain/contract/ContractQueryClient.js +156 -0
  109. package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +18 -0
  110. package/dist/sdk/firmachain/contract/ContractTxClient.js +43 -0
  111. package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +69 -0
  112. package/dist/sdk/firmachain/contract/ContractTxTypes.js +483 -0
  113. package/dist/sdk/firmachain/contract/index.d.ts +3 -0
  114. package/dist/sdk/firmachain/contract/index.js +19 -0
  115. package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.d.ts +52 -0
  116. package/dist/sdk/firmachain/cosmwasm/CosmWasmQueryClient.js +193 -0
  117. package/dist/sdk/firmachain/cosmwasm/CosmWasmTxClient.d.ts +38 -0
  118. package/dist/sdk/firmachain/cosmwasm/CosmWasmTxClient.js +59 -0
  119. package/dist/sdk/firmachain/cosmwasm/index.d.ts +3 -0
  120. package/dist/sdk/firmachain/cosmwasm/index.js +19 -0
  121. package/dist/sdk/firmachain/distribution/DistributionQueryClient.d.ts +18 -0
  122. package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +167 -0
  123. package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +28 -0
  124. package/dist/sdk/firmachain/distribution/DistributionTxClient.js +51 -0
  125. package/dist/sdk/firmachain/distribution/index.d.ts +3 -0
  126. package/dist/sdk/firmachain/distribution/index.js +19 -0
  127. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.d.ts +17 -0
  128. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +86 -0
  129. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +18 -0
  130. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +43 -0
  131. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +76 -0
  132. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +194 -0
  133. package/dist/sdk/firmachain/feegrant/index.d.ts +3 -0
  134. package/dist/sdk/firmachain/feegrant/index.js +19 -0
  135. package/dist/sdk/firmachain/google/protobuf/any.d.ts +128 -0
  136. package/dist/sdk/firmachain/google/protobuf/any.js +106 -0
  137. package/dist/sdk/firmachain/google/protobuf/descriptor.d.ts +996 -0
  138. package/dist/sdk/firmachain/google/protobuf/descriptor.js +5329 -0
  139. package/dist/sdk/firmachain/google/protobuf/duration.d.ts +91 -0
  140. package/dist/sdk/firmachain/google/protobuf/duration.js +107 -0
  141. package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +109 -0
  142. package/dist/sdk/firmachain/google/protobuf/timestamp.js +107 -0
  143. package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +61 -0
  144. package/dist/sdk/firmachain/gov/GovQueryClient.js +152 -0
  145. package/dist/sdk/firmachain/gov/GovTxClient.d.ts +23 -0
  146. package/dist/sdk/firmachain/gov/GovTxClient.js +47 -0
  147. package/dist/sdk/firmachain/gov/index.d.ts +3 -0
  148. package/dist/sdk/firmachain/gov/index.js +19 -0
  149. package/dist/sdk/firmachain/ibc/IbcQueryClient.d.ts +34 -0
  150. package/dist/sdk/firmachain/ibc/IbcQueryClient.js +71 -0
  151. package/dist/sdk/firmachain/ibc/IbcTxClient.d.ts +13 -0
  152. package/dist/sdk/firmachain/ibc/IbcTxClient.js +39 -0
  153. package/dist/sdk/firmachain/ibc/index.d.ts +3 -0
  154. package/dist/sdk/firmachain/ibc/index.js +19 -0
  155. package/dist/sdk/firmachain/nft/NftQueryClient.d.ts +20 -0
  156. package/dist/sdk/firmachain/nft/NftQueryClient.js +125 -0
  157. package/dist/sdk/firmachain/nft/NftTxClient.d.ts +23 -0
  158. package/dist/sdk/firmachain/nft/NftTxClient.js +47 -0
  159. package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +86 -0
  160. package/dist/sdk/firmachain/nft/NftTxTypes.js +424 -0
  161. package/dist/sdk/firmachain/nft/index.d.ts +3 -0
  162. package/dist/sdk/firmachain/nft/index.js +19 -0
  163. package/dist/sdk/firmachain/slashing/SlashingQueryClient.d.ts +22 -0
  164. package/dist/sdk/firmachain/slashing/SlashingQueryClient.js +101 -0
  165. package/dist/sdk/firmachain/slashing/index.d.ts +2 -0
  166. package/dist/sdk/firmachain/slashing/index.js +18 -0
  167. package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +106 -0
  168. package/dist/sdk/firmachain/staking/StakingQueryClient.js +243 -0
  169. package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +33 -0
  170. package/dist/sdk/firmachain/staking/StakingTxClient.js +55 -0
  171. package/dist/sdk/firmachain/staking/index.d.ts +3 -0
  172. package/dist/sdk/firmachain/staking/index.js +19 -0
  173. package/dist/sdk/firmachain/token/TokenQueryClient.d.ts +24 -0
  174. package/dist/sdk/firmachain/token/TokenQueryClient.js +106 -0
  175. package/dist/sdk/firmachain/token/TokenTxClient.d.ts +28 -0
  176. package/dist/sdk/firmachain/token/TokenTxClient.js +51 -0
  177. package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +116 -0
  178. package/dist/sdk/firmachain/token/TokenTxTypes.js +685 -0
  179. package/dist/sdk/firmachain/token/index.d.ts +3 -0
  180. package/dist/sdk/firmachain/token/index.js +19 -0
  181. package/package.json +3 -7
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCoins = exports.coins = exports.coin = void 0;
4
+ var math_1 = require("@cosmjs/math");
5
+ /**
6
+ * Creates a coin.
7
+ *
8
+ * If your values do not exceed the safe integer range of JS numbers (53 bit),
9
+ * you can use the number type here. This is the case for all typical Cosmos SDK
10
+ * chains that use the default 6 decimals.
11
+ *
12
+ * In case you need to supportr larger values, use unsigned integer strings instead.
13
+ */
14
+ function coin(amount, denom) {
15
+ var outAmount;
16
+ if (typeof amount === "number") {
17
+ try {
18
+ outAmount = new math_1.Uint53(amount).toString();
19
+ }
20
+ catch (_err) {
21
+ throw new Error("Given amount is not a safe integer. Consider using a string instead to overcome the limitations of JS numbers.");
22
+ }
23
+ }
24
+ else {
25
+ if (!amount.match(/^[0-9]+$/)) {
26
+ throw new Error("Invalid unsigned integer string format");
27
+ }
28
+ outAmount = amount.replace(/^0*/, "") || "0";
29
+ }
30
+ return {
31
+ amount: outAmount,
32
+ denom: denom,
33
+ };
34
+ }
35
+ exports.coin = coin;
36
+ /**
37
+ * Creates a list of coins with one element.
38
+ */
39
+ function coins(amount, denom) {
40
+ return [coin(amount, denom)];
41
+ }
42
+ exports.coins = coins;
43
+ /**
44
+ * Takes a coins list like "819966000ucosm,700000000ustake" and parses it.
45
+ *
46
+ * A Stargate-ready variant of this function is available via:
47
+ *
48
+ * ```
49
+ * import { parseCoins } from "@cosmjs/proto-signing";
50
+ * // or
51
+ * import { parseCoins } from "@cosmjs/stargate";
52
+ * ```
53
+ */
54
+ function parseCoins(input) {
55
+ return input
56
+ .replace(/\s/g, "")
57
+ .split(",")
58
+ .filter(Boolean)
59
+ .map(function (part) {
60
+ var match = part.match(/^([0-9]+)([a-zA-Z]+)/);
61
+ if (!match)
62
+ throw new Error("Got an invalid coin string");
63
+ return {
64
+ amount: math_1.Uint64.fromString(match[1]).toString(),
65
+ denom: match[2],
66
+ };
67
+ });
68
+ }
69
+ exports.parseCoins = parseCoins;
@@ -0,0 +1,24 @@
1
+ import { Pubkey, Secp256k1Pubkey } from "./pubkeys";
2
+ export declare function encodeSecp256k1Pubkey(pubkey: Uint8Array): Secp256k1Pubkey;
3
+ /**
4
+ * Decodes a pubkey in the Amino binary format to a type/value object.
5
+ */
6
+ export declare function decodeAminoPubkey(data: Uint8Array): Pubkey;
7
+ /**
8
+ * Decodes a bech32 pubkey to Amino binary, which is then decoded to a type/value object.
9
+ * The bech32 prefix is ignored and discareded.
10
+ *
11
+ * @param bechEncoded the bech32 encoded pubkey
12
+ */
13
+ export declare function decodeBech32Pubkey(bechEncoded: string): Pubkey;
14
+ /**
15
+ * Encodes a public key to binary Amino.
16
+ */
17
+ export declare function encodeAminoPubkey(pubkey: Pubkey): Uint8Array;
18
+ /**
19
+ * Encodes a public key to binary Amino and then to bech32.
20
+ *
21
+ * @param pubkey the public key to encode
22
+ * @param prefix the bech32 prefix (human readable part)
23
+ */
24
+ export declare function encodeBech32Pubkey(pubkey: Pubkey, prefix: string): string;
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
26
+ };
27
+ var __values = (this && this.__values) || function(o) {
28
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
29
+ if (m) return m.call(o);
30
+ if (o && typeof o.length === "number") return {
31
+ next: function () {
32
+ if (o && i >= o.length) o = void 0;
33
+ return { value: o && o[i++], done: !o };
34
+ }
35
+ };
36
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.encodeBech32Pubkey = exports.encodeAminoPubkey = exports.decodeBech32Pubkey = exports.decodeAminoPubkey = exports.encodeSecp256k1Pubkey = void 0;
40
+ var encoding_1 = require("@cosmjs/encoding");
41
+ var math_1 = require("@cosmjs/math");
42
+ var utils_1 = require("@cosmjs/utils");
43
+ var pubkeys_1 = require("./pubkeys");
44
+ function encodeSecp256k1Pubkey(pubkey) {
45
+ if (pubkey.length !== 33 || (pubkey[0] !== 0x02 && pubkey[0] !== 0x03)) {
46
+ throw new Error("Public key must be compressed secp256k1, i.e. 33 bytes starting with 0x02 or 0x03");
47
+ }
48
+ return {
49
+ type: pubkeys_1.pubkeyType.secp256k1,
50
+ value: (0, encoding_1.toBase64)(pubkey),
51
+ };
52
+ }
53
+ exports.encodeSecp256k1Pubkey = encodeSecp256k1Pubkey;
54
+ // As discussed in https://github.com/binance-chain/javascript-sdk/issues/163
55
+ // Prefixes listed here: https://github.com/tendermint/tendermint/blob/d419fffe18531317c28c29a292ad7d253f6cafdf/docs/spec/blockchain/encoding.md#public-key-cryptography
56
+ // Last bytes is varint-encoded length prefix
57
+ var pubkeyAminoPrefixSecp256k1 = (0, encoding_1.fromHex)("eb5ae987" + "21" /* fixed length */);
58
+ var pubkeyAminoPrefixEd25519 = (0, encoding_1.fromHex)("1624de64" + "20" /* fixed length */);
59
+ var pubkeyAminoPrefixSr25519 = (0, encoding_1.fromHex)("0dfb1005" + "20" /* fixed length */);
60
+ /** See https://github.com/tendermint/tendermint/commit/38b401657e4ad7a7eeb3c30a3cbf512037df3740 */
61
+ var pubkeyAminoPrefixMultisigThreshold = (0, encoding_1.fromHex)("22c1f7e2" /* variable length not included */);
62
+ /**
63
+ * Decodes a pubkey in the Amino binary format to a type/value object.
64
+ */
65
+ function decodeAminoPubkey(data) {
66
+ if ((0, utils_1.arrayContentStartsWith)(data, pubkeyAminoPrefixSecp256k1)) {
67
+ var rest = data.slice(pubkeyAminoPrefixSecp256k1.length);
68
+ if (rest.length !== 33) {
69
+ throw new Error("Invalid rest data length. Expected 33 bytes (compressed secp256k1 pubkey).");
70
+ }
71
+ return {
72
+ type: pubkeys_1.pubkeyType.secp256k1,
73
+ value: (0, encoding_1.toBase64)(rest),
74
+ };
75
+ }
76
+ else if ((0, utils_1.arrayContentStartsWith)(data, pubkeyAminoPrefixEd25519)) {
77
+ var rest = data.slice(pubkeyAminoPrefixEd25519.length);
78
+ if (rest.length !== 32) {
79
+ throw new Error("Invalid rest data length. Expected 32 bytes (Ed25519 pubkey).");
80
+ }
81
+ return {
82
+ type: pubkeys_1.pubkeyType.ed25519,
83
+ value: (0, encoding_1.toBase64)(rest),
84
+ };
85
+ }
86
+ else if ((0, utils_1.arrayContentStartsWith)(data, pubkeyAminoPrefixSr25519)) {
87
+ var rest = data.slice(pubkeyAminoPrefixSr25519.length);
88
+ if (rest.length !== 32) {
89
+ throw new Error("Invalid rest data length. Expected 32 bytes (Sr25519 pubkey).");
90
+ }
91
+ return {
92
+ type: pubkeys_1.pubkeyType.sr25519,
93
+ value: (0, encoding_1.toBase64)(rest),
94
+ };
95
+ }
96
+ else if ((0, utils_1.arrayContentStartsWith)(data, pubkeyAminoPrefixMultisigThreshold)) {
97
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
98
+ return decodeMultisigPubkey(data);
99
+ }
100
+ else {
101
+ throw new Error("Unsupported public key type. Amino data starts with: " + (0, encoding_1.toHex)(data.slice(0, 5)));
102
+ }
103
+ }
104
+ exports.decodeAminoPubkey = decodeAminoPubkey;
105
+ /**
106
+ * Decodes a bech32 pubkey to Amino binary, which is then decoded to a type/value object.
107
+ * The bech32 prefix is ignored and discareded.
108
+ *
109
+ * @param bechEncoded the bech32 encoded pubkey
110
+ */
111
+ function decodeBech32Pubkey(bechEncoded) {
112
+ var data = encoding_1.Bech32.decode(bechEncoded).data;
113
+ return decodeAminoPubkey(data);
114
+ }
115
+ exports.decodeBech32Pubkey = decodeBech32Pubkey;
116
+ /**
117
+ * Uvarint decoder for Amino.
118
+ * @see https://github.com/tendermint/go-amino/blob/8e779b71f40d175/decoder.go#L64-76
119
+ * @returns varint as number, and bytes count occupied by varaint
120
+ */
121
+ function decodeUvarint(reader) {
122
+ if (reader.length < 1) {
123
+ throw new Error("Can't decode varint. EOF");
124
+ }
125
+ if (reader[0] > 127) {
126
+ throw new Error("Decoding numbers > 127 is not supported here. Please tell those lazy CosmJS maintainers to port the binary.Varint implementation from the Go standard library and write some tests.");
127
+ }
128
+ return [reader[0], 1];
129
+ }
130
+ /**
131
+ * Decodes a multisig pubkey to type object.
132
+ * Pubkey structure [ prefix + const + threshold + loop:(const + pubkeyLength + pubkey ) ]
133
+ * [ 4b + 1b + varint + loop:(1b + varint + pubkeyLength bytes) ]
134
+ * @param data encoded pubkey
135
+ */
136
+ function decodeMultisigPubkey(data) {
137
+ var reader = Array.from(data);
138
+ // remove multisig amino prefix;
139
+ var prefixFromReader = reader.splice(0, pubkeyAminoPrefixMultisigThreshold.length);
140
+ if (!(0, utils_1.arrayContentStartsWith)(prefixFromReader, pubkeyAminoPrefixMultisigThreshold)) {
141
+ throw new Error("Invalid multisig prefix.");
142
+ }
143
+ // remove 0x08 threshold prefix;
144
+ if (reader.shift() != 0x08) {
145
+ throw new Error("Invalid multisig data. Expecting 0x08 prefix before threshold.");
146
+ }
147
+ // read threshold
148
+ var _a = __read(decodeUvarint(reader), 2), threshold = _a[0], thresholdBytesLength = _a[1];
149
+ reader.splice(0, thresholdBytesLength);
150
+ // read participants pubkeys
151
+ var pubkeys = [];
152
+ while (reader.length > 0) {
153
+ // remove 0x12 threshold prefix;
154
+ if (reader.shift() != 0x12) {
155
+ throw new Error("Invalid multisig data. Expecting 0x12 prefix before participant pubkey length.");
156
+ }
157
+ // read pubkey length
158
+ var _b = __read(decodeUvarint(reader), 2), pubkeyLength = _b[0], pubkeyLengthBytesSize = _b[1];
159
+ reader.splice(0, pubkeyLengthBytesSize);
160
+ // verify that we can read pubkey
161
+ if (reader.length < pubkeyLength) {
162
+ throw new Error("Invalid multisig data length.");
163
+ }
164
+ // read and decode participant pubkey
165
+ var encodedPubkey = reader.splice(0, pubkeyLength);
166
+ var pubkey = decodeAminoPubkey(Uint8Array.from(encodedPubkey));
167
+ pubkeys.push(pubkey);
168
+ }
169
+ return {
170
+ type: pubkeys_1.pubkeyType.multisigThreshold,
171
+ value: {
172
+ threshold: threshold.toString(),
173
+ pubkeys: pubkeys,
174
+ },
175
+ };
176
+ }
177
+ /**
178
+ * Uvarint encoder for Amino. This is the same encoding as `binary.PutUvarint` from the Go
179
+ * standard library.
180
+ *
181
+ * @see https://github.com/tendermint/go-amino/blob/8e779b71f40d175/encoder.go#L77-L85
182
+ */
183
+ function encodeUvarint(value) {
184
+ var checked = math_1.Uint53.fromString(value.toString()).toNumber();
185
+ if (checked > 127) {
186
+ throw new Error("Encoding numbers > 127 is not supported here. Please tell those lazy CosmJS maintainers to port the binary.PutUvarint implementation from the Go standard library and write some tests.");
187
+ }
188
+ return [checked];
189
+ }
190
+ /**
191
+ * Encodes a public key to binary Amino.
192
+ */
193
+ function encodeAminoPubkey(pubkey) {
194
+ var e_1, _a;
195
+ if ((0, pubkeys_1.isMultisigThresholdPubkey)(pubkey)) {
196
+ var out = Array.from(pubkeyAminoPrefixMultisigThreshold);
197
+ out.push(0x08); // TODO: What is this?
198
+ out.push.apply(// TODO: What is this?
199
+ out, __spreadArray([], __read(encodeUvarint(pubkey.value.threshold)), false));
200
+ try {
201
+ for (var _b = __values(pubkey.value.pubkeys.map(function (p) { return encodeAminoPubkey(p); })), _c = _b.next(); !_c.done; _c = _b.next()) {
202
+ var pubkeyData = _c.value;
203
+ out.push(0x12); // TODO: What is this?
204
+ out.push.apply(// TODO: What is this?
205
+ out, __spreadArray([], __read(encodeUvarint(pubkeyData.length)), false));
206
+ out.push.apply(out, __spreadArray([], __read(pubkeyData), false));
207
+ }
208
+ }
209
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
210
+ finally {
211
+ try {
212
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
213
+ }
214
+ finally { if (e_1) throw e_1.error; }
215
+ }
216
+ return new Uint8Array(out);
217
+ }
218
+ else if ((0, pubkeys_1.isEd25519Pubkey)(pubkey)) {
219
+ return new Uint8Array(__spreadArray(__spreadArray([], __read(pubkeyAminoPrefixEd25519), false), __read((0, encoding_1.fromBase64)(pubkey.value)), false));
220
+ }
221
+ else if ((0, pubkeys_1.isSecp256k1Pubkey)(pubkey)) {
222
+ return new Uint8Array(__spreadArray(__spreadArray([], __read(pubkeyAminoPrefixSecp256k1), false), __read((0, encoding_1.fromBase64)(pubkey.value)), false));
223
+ }
224
+ else {
225
+ throw new Error("Unsupported pubkey type");
226
+ }
227
+ }
228
+ exports.encodeAminoPubkey = encodeAminoPubkey;
229
+ /**
230
+ * Encodes a public key to binary Amino and then to bech32.
231
+ *
232
+ * @param pubkey the public key to encode
233
+ * @param prefix the bech32 prefix (human readable part)
234
+ */
235
+ function encodeBech32Pubkey(pubkey, prefix) {
236
+ return encoding_1.Bech32.encode(prefix, encodeAminoPubkey(pubkey));
237
+ }
238
+ exports.encodeBech32Pubkey = encodeBech32Pubkey;
@@ -0,0 +1,10 @@
1
+ import { MultisigThresholdPubkey, SinglePubkey } from "./pubkeys";
2
+ /**
3
+ * Compare arrays lexicographically.
4
+ *
5
+ * Returns value < 0 if `a < b`.
6
+ * Returns value > 0 if `a > b`.
7
+ * Returns 0 if `a === b`.
8
+ */
9
+ export declare function compareArrays(a: Uint8Array, b: Uint8Array): number;
10
+ export declare function createMultisigThresholdPubkey(pubkeys: readonly SinglePubkey[], threshold: number, nosort?: boolean): MultisigThresholdPubkey;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMultisigThresholdPubkey = exports.compareArrays = void 0;
4
+ var encoding_1 = require("@cosmjs/encoding");
5
+ var math_1 = require("@cosmjs/math");
6
+ var addresses_1 = require("./addresses");
7
+ /**
8
+ * Compare arrays lexicographically.
9
+ *
10
+ * Returns value < 0 if `a < b`.
11
+ * Returns value > 0 if `a > b`.
12
+ * Returns 0 if `a === b`.
13
+ */
14
+ function compareArrays(a, b) {
15
+ var aHex = (0, encoding_1.toHex)(a);
16
+ var bHex = (0, encoding_1.toHex)(b);
17
+ return aHex === bHex ? 0 : aHex < bHex ? -1 : 1;
18
+ }
19
+ exports.compareArrays = compareArrays;
20
+ function createMultisigThresholdPubkey(pubkeys, threshold, nosort) {
21
+ if (nosort === void 0) { nosort = false; }
22
+ var uintThreshold = new math_1.Uint53(threshold);
23
+ if (uintThreshold.toNumber() > pubkeys.length) {
24
+ throw new Error("Threshold k = ".concat(uintThreshold.toNumber(), " exceeds number of keys n = ").concat(pubkeys.length));
25
+ }
26
+ var outPubkeys = nosort
27
+ ? pubkeys
28
+ : Array.from(pubkeys).sort(function (lhs, rhs) {
29
+ // https://github.com/cosmos/cosmos-sdk/blob/v0.42.2/client/keys/add.go#L172-L174
30
+ var addressLhs = (0, addresses_1.pubkeyToRawAddress)(lhs);
31
+ var addressRhs = (0, addresses_1.pubkeyToRawAddress)(rhs);
32
+ return compareArrays(addressLhs, addressRhs);
33
+ });
34
+ return {
35
+ type: "tendermint/PubKeyMultisigThreshold",
36
+ value: {
37
+ threshold: uintThreshold.toString(),
38
+ pubkeys: outPubkeys,
39
+ },
40
+ };
41
+ }
42
+ exports.createMultisigThresholdPubkey = createMultisigThresholdPubkey;
@@ -0,0 +1,6 @@
1
+ import { HdPath } from "@cosmjs/crypto";
2
+ /**
3
+ * The Cosmos Hub derivation path in the form `m/44'/118'/0'/0/a`
4
+ * with 0-based account index `a`.
5
+ */
6
+ export declare function makeCosmoshubPath(a: number): HdPath;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeCosmoshubPath = void 0;
4
+ var crypto_1 = require("@cosmjs/crypto");
5
+ /**
6
+ * The Cosmos Hub derivation path in the form `m/44'/118'/0'/0/a`
7
+ * with 0-based account index `a`.
8
+ */
9
+ function makeCosmoshubPath(a) {
10
+ return [
11
+ crypto_1.Slip10RawIndex.hardened(44),
12
+ crypto_1.Slip10RawIndex.hardened(118),
13
+ crypto_1.Slip10RawIndex.hardened(0),
14
+ crypto_1.Slip10RawIndex.normal(0),
15
+ crypto_1.Slip10RawIndex.normal(a),
16
+ ];
17
+ }
18
+ exports.makeCosmoshubPath = makeCosmoshubPath;
@@ -0,0 +1,47 @@
1
+ export interface Pubkey {
2
+ readonly type: string;
3
+ readonly value: any;
4
+ }
5
+ export interface Ed25519Pubkey extends SinglePubkey {
6
+ readonly type: "tendermint/PubKeyEd25519";
7
+ readonly value: string;
8
+ }
9
+ export declare function isEd25519Pubkey(pubkey: Pubkey): pubkey is Ed25519Pubkey;
10
+ export interface Secp256k1Pubkey extends SinglePubkey {
11
+ readonly type: "tendermint/PubKeySecp256k1";
12
+ readonly value: string;
13
+ }
14
+ export declare function isSecp256k1Pubkey(pubkey: Pubkey): pubkey is Secp256k1Pubkey;
15
+ export declare const pubkeyType: {
16
+ /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/ed25519/ed25519.go#L22 */
17
+ secp256k1: "tendermint/PubKeySecp256k1";
18
+ /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/secp256k1/secp256k1.go#L23 */
19
+ ed25519: "tendermint/PubKeyEd25519";
20
+ /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/sr25519/codec.go#L12 */
21
+ sr25519: "tendermint/PubKeySr25519";
22
+ multisigThreshold: "tendermint/PubKeyMultisigThreshold";
23
+ };
24
+ /**
25
+ * A pubkey which contains the data directly without further nesting.
26
+ *
27
+ * You can think of this as a non-multisig pubkey.
28
+ */
29
+ export interface SinglePubkey extends Pubkey {
30
+ readonly type: string;
31
+ /**
32
+ * The base64 encoding of the Amino binary encoded pubkey.
33
+ *
34
+ * Note: if type is Secp256k1, this must contain a 33 bytes compressed pubkey.
35
+ */
36
+ readonly value: string;
37
+ }
38
+ export declare function isSinglePubkey(pubkey: Pubkey): pubkey is SinglePubkey;
39
+ export interface MultisigThresholdPubkey extends Pubkey {
40
+ readonly type: "tendermint/PubKeyMultisigThreshold";
41
+ readonly value: {
42
+ /** A string-encoded integer */
43
+ readonly threshold: string;
44
+ readonly pubkeys: readonly SinglePubkey[];
45
+ };
46
+ }
47
+ export declare function isMultisigThresholdPubkey(pubkey: Pubkey): pubkey is MultisigThresholdPubkey;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMultisigThresholdPubkey = exports.isSinglePubkey = exports.pubkeyType = exports.isSecp256k1Pubkey = exports.isEd25519Pubkey = void 0;
4
+ function isEd25519Pubkey(pubkey) {
5
+ return pubkey.type === "tendermint/PubKeyEd25519";
6
+ }
7
+ exports.isEd25519Pubkey = isEd25519Pubkey;
8
+ function isSecp256k1Pubkey(pubkey) {
9
+ return pubkey.type === "tendermint/PubKeySecp256k1";
10
+ }
11
+ exports.isSecp256k1Pubkey = isSecp256k1Pubkey;
12
+ exports.pubkeyType = {
13
+ /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/ed25519/ed25519.go#L22 */
14
+ secp256k1: "tendermint/PubKeySecp256k1",
15
+ /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/secp256k1/secp256k1.go#L23 */
16
+ ed25519: "tendermint/PubKeyEd25519",
17
+ /** @see https://github.com/tendermint/tendermint/blob/v0.33.0/crypto/sr25519/codec.go#L12 */
18
+ sr25519: "tendermint/PubKeySr25519",
19
+ multisigThreshold: "tendermint/PubKeyMultisigThreshold",
20
+ };
21
+ function isSinglePubkey(pubkey) {
22
+ var singPubkeyTypes = [exports.pubkeyType.ed25519, exports.pubkeyType.secp256k1, exports.pubkeyType.sr25519];
23
+ return singPubkeyTypes.includes(pubkey.type);
24
+ }
25
+ exports.isSinglePubkey = isSinglePubkey;
26
+ function isMultisigThresholdPubkey(pubkey) {
27
+ return pubkey.type === "tendermint/PubKeyMultisigThreshold";
28
+ }
29
+ exports.isMultisigThresholdPubkey = isMultisigThresholdPubkey;
@@ -0,0 +1,16 @@
1
+ import { Pubkey } from "./pubkeys";
2
+ export interface StdSignature {
3
+ readonly pub_key: Pubkey;
4
+ readonly signature: string;
5
+ }
6
+ /**
7
+ * Takes a binary pubkey and signature to create a signature object
8
+ *
9
+ * @param pubkey a compressed secp256k1 public key
10
+ * @param signature a 64 byte fixed length representation of secp256k1 signature components r and s
11
+ */
12
+ export declare function encodeSecp256k1Signature(pubkey: Uint8Array, signature: Uint8Array): StdSignature;
13
+ export declare function decodeSignature(signature: StdSignature): {
14
+ readonly pubkey: Uint8Array;
15
+ readonly signature: Uint8Array;
16
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeSignature = exports.encodeSecp256k1Signature = void 0;
4
+ /* eslint-disable @typescript-eslint/naming-convention */
5
+ var encoding_1 = require("@cosmjs/encoding");
6
+ var encoding_2 = require("./encoding");
7
+ var pubkeys_1 = require("./pubkeys");
8
+ /**
9
+ * Takes a binary pubkey and signature to create a signature object
10
+ *
11
+ * @param pubkey a compressed secp256k1 public key
12
+ * @param signature a 64 byte fixed length representation of secp256k1 signature components r and s
13
+ */
14
+ function encodeSecp256k1Signature(pubkey, signature) {
15
+ if (signature.length !== 64) {
16
+ throw new Error("Signature must be 64 bytes long. Cosmos SDK uses a 2x32 byte fixed length encoding for the secp256k1 signature integers r and s.");
17
+ }
18
+ return {
19
+ pub_key: (0, encoding_2.encodeSecp256k1Pubkey)(pubkey),
20
+ signature: (0, encoding_1.toBase64)(signature),
21
+ };
22
+ }
23
+ exports.encodeSecp256k1Signature = encodeSecp256k1Signature;
24
+ function decodeSignature(signature) {
25
+ switch (signature.pub_key.type) {
26
+ // Note: please don't add cases here without writing additional unit tests
27
+ case pubkeys_1.pubkeyType.secp256k1:
28
+ return {
29
+ pubkey: (0, encoding_1.fromBase64)(signature.pub_key.value),
30
+ signature: (0, encoding_1.fromBase64)(signature.signature),
31
+ };
32
+ default:
33
+ throw new Error("Unsupported pubkey type");
34
+ }
35
+ }
36
+ exports.decodeSignature = decodeSignature;
@@ -0,0 +1,26 @@
1
+ import { Coin } from "./coins";
2
+ export interface AminoMsg {
3
+ readonly type: string;
4
+ readonly value: any;
5
+ }
6
+ export interface StdFee {
7
+ amount: Coin[];
8
+ gas: string;
9
+ }
10
+ /**
11
+ * The document to be signed
12
+ *
13
+ * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdsigndoc
14
+ */
15
+ export interface StdSignDoc {
16
+ readonly chain_id: string;
17
+ readonly account_number: string;
18
+ readonly sequence: string;
19
+ readonly fee: StdFee;
20
+ readonly msgs: readonly AminoMsg[];
21
+ readonly memo: string;
22
+ }
23
+ /** Returns a JSON string with objects sorted by key */
24
+ export declare function sortedJsonStringify(obj: any): string;
25
+ export declare function makeSignDoc(msgs: readonly AminoMsg[], fee: StdFee, chainId: string, memo: string | undefined, accountNumber: number | string, sequence: number | string): StdSignDoc;
26
+ export declare function serializeSignDoc(signDoc: StdSignDoc): Uint8Array;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeSignDoc = exports.makeSignDoc = exports.sortedJsonStringify = void 0;
4
+ /* eslint-disable @typescript-eslint/naming-convention */
5
+ var encoding_1 = require("@cosmjs/encoding");
6
+ var math_1 = require("@cosmjs/math");
7
+ function sortedObject(obj) {
8
+ if (typeof obj !== "object" || obj === null) {
9
+ return obj;
10
+ }
11
+ if (Array.isArray(obj)) {
12
+ return obj.map(sortedObject);
13
+ }
14
+ var sortedKeys = Object.keys(obj).sort();
15
+ var result = {};
16
+ // NOTE: Use forEach instead of reduce for performance with large objects eg Wasm code
17
+ sortedKeys.forEach(function (key) {
18
+ result[key] = sortedObject(obj[key]);
19
+ });
20
+ return result;
21
+ }
22
+ /** Returns a JSON string with objects sorted by key */
23
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
24
+ function sortedJsonStringify(obj) {
25
+ return JSON.stringify(sortedObject(obj));
26
+ }
27
+ exports.sortedJsonStringify = sortedJsonStringify;
28
+ function makeSignDoc(msgs, fee, chainId, memo, accountNumber, sequence) {
29
+ return {
30
+ chain_id: chainId,
31
+ account_number: math_1.Uint53.fromString(accountNumber.toString()).toString(),
32
+ sequence: math_1.Uint53.fromString(sequence.toString()).toString(),
33
+ fee: fee,
34
+ msgs: msgs,
35
+ memo: memo || "",
36
+ };
37
+ }
38
+ exports.makeSignDoc = makeSignDoc;
39
+ function serializeSignDoc(signDoc) {
40
+ return (0, encoding_1.toUtf8)(sortedJsonStringify(signDoc));
41
+ }
42
+ exports.serializeSignDoc = serializeSignDoc;
@@ -0,0 +1,32 @@
1
+ import { StdSignature, StdSignDoc } from "@cosmjs/amino";
2
+ export declare type Algo = "secp256k1" | "ed25519" | "sr25519";
3
+ export interface AccountData {
4
+ /** A printable address (typically bech32 encoded) */
5
+ readonly address: string;
6
+ readonly algo: Algo;
7
+ readonly pubkey: Uint8Array;
8
+ }
9
+ export interface AminoSignResponse {
10
+ /**
11
+ * The sign doc that was signed.
12
+ * This may be different from the input signDoc when the signer modifies it as part of the signing process.
13
+ */
14
+ readonly signed: StdSignDoc;
15
+ readonly signature: StdSignature;
16
+ }
17
+ export interface OfflineAminoSigner {
18
+ /**
19
+ * Get AccountData array from wallet. Rejects if not enabled.
20
+ */
21
+ readonly getAccounts: () => Promise<readonly AccountData[]>;
22
+ /**
23
+ * Request signature from whichever key corresponds to provided bech32-encoded address. Rejects if not enabled.
24
+ *
25
+ * The signer implementation may offer the user the ability to override parts of the signDoc. It must
26
+ * return the doc that was signed in the response.
27
+ *
28
+ * @param signerAddress The address of the account that should sign the transaction
29
+ * @param signDoc The content that should be signed
30
+ */
31
+ readonly signAmino: (signerAddress: string, signDoc: StdSignDoc) => Promise<AminoSignResponse>;
32
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,15 @@
1
+ import { StdSignature } from "./signature";
2
+ import { AminoMsg, StdFee, StdSignDoc } from "./signdoc";
3
+ /**
4
+ * A Cosmos SDK StdTx
5
+ *
6
+ * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdtx
7
+ */
8
+ export interface StdTx {
9
+ readonly msg: readonly AminoMsg[];
10
+ readonly fee: StdFee;
11
+ readonly signatures: readonly StdSignature[];
12
+ readonly memo: string | undefined;
13
+ }
14
+ export declare function isStdTx(txValue: unknown): txValue is StdTx;
15
+ export declare function makeStdTx(content: Pick<StdSignDoc, "msgs" | "fee" | "memo">, signatures: StdSignature | readonly StdSignature[]): StdTx;