@firmachain/firma-js 0.2.18 → 0.2.22

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 (157) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +136 -136
  3. package/dist/index.d.ts +4 -4
  4. package/dist/index.js +16 -16
  5. package/dist/sdk/FirmaBankService.d.ts +15 -15
  6. package/dist/sdk/FirmaBankService.js +211 -211
  7. package/dist/sdk/FirmaChainService.d.ts +8 -8
  8. package/dist/sdk/FirmaChainService.js +86 -86
  9. package/dist/sdk/FirmaConfig.d.ts +18 -16
  10. package/dist/sdk/FirmaConfig.js +63 -55
  11. package/dist/sdk/FirmaContractService.d.ts +31 -30
  12. package/dist/sdk/FirmaContractService.js +413 -394
  13. package/dist/sdk/FirmaDistributionService.d.ts +31 -31
  14. package/dist/sdk/FirmaDistributionService.js +524 -524
  15. package/dist/sdk/FirmaFeeGrantService.d.ts +21 -21
  16. package/dist/sdk/FirmaFeeGrantService.js +341 -341
  17. package/dist/sdk/FirmaGovService.d.ts +35 -35
  18. package/dist/sdk/FirmaGovService.js +775 -775
  19. package/dist/sdk/FirmaIpfsService.d.ts +12 -12
  20. package/dist/sdk/FirmaIpfsService.js +185 -185
  21. package/dist/sdk/FirmaMobileSDK.d.ts +27 -27
  22. package/dist/sdk/FirmaMobileSDK.js +45 -45
  23. package/dist/sdk/FirmaNftService.d.ts +31 -28
  24. package/dist/sdk/FirmaNftService.js +372 -390
  25. package/dist/sdk/FirmaSDK.d.ts +29 -29
  26. package/dist/sdk/FirmaSDK.js +48 -48
  27. package/dist/sdk/FirmaSlashingService.d.ts +9 -9
  28. package/dist/sdk/FirmaSlashingService.js +105 -105
  29. package/dist/sdk/FirmaStakingService.d.ts +34 -34
  30. package/dist/sdk/FirmaStakingService.js +604 -604
  31. package/dist/sdk/FirmaTokenService.d.ts +26 -26
  32. package/dist/sdk/FirmaTokenService.js +416 -416
  33. package/dist/sdk/FirmaUtil.d.ts +35 -25
  34. package/dist/sdk/FirmaUtil.js +226 -201
  35. package/dist/sdk/FirmaWalletService.d.ts +36 -40
  36. package/dist/sdk/FirmaWalletService.js +309 -309
  37. package/dist/sdk/firmachain/amino/addresses.d.ts +5 -5
  38. package/dist/sdk/firmachain/amino/addresses.js +46 -46
  39. package/dist/sdk/firmachain/amino/aminomsgs.d.ts +281 -281
  40. package/dist/sdk/firmachain/amino/aminomsgs.js +77 -77
  41. package/dist/sdk/firmachain/amino/aminotypes.d.ts +22 -22
  42. package/dist/sdk/firmachain/amino/aminotypes.js +521 -521
  43. package/dist/sdk/firmachain/amino/coins.d.ts +30 -30
  44. package/dist/sdk/firmachain/amino/coins.js +69 -69
  45. package/dist/sdk/firmachain/amino/encoding.d.ts +24 -24
  46. package/dist/sdk/firmachain/amino/encoding.js +234 -234
  47. package/dist/sdk/firmachain/amino/multisig.d.ts +10 -10
  48. package/dist/sdk/firmachain/amino/multisig.js +42 -42
  49. package/dist/sdk/firmachain/amino/paths.d.ts +6 -6
  50. package/dist/sdk/firmachain/amino/paths.js +18 -18
  51. package/dist/sdk/firmachain/amino/pubkeys.d.ts +47 -47
  52. package/dist/sdk/firmachain/amino/pubkeys.js +29 -29
  53. package/dist/sdk/firmachain/amino/secp256k1hdwallet.d.ts +94 -94
  54. package/dist/sdk/firmachain/amino/secp256k1hdwallet.js +437 -437
  55. package/dist/sdk/firmachain/amino/secp256k1wallet.d.ts +23 -23
  56. package/dist/sdk/firmachain/amino/secp256k1wallet.js +141 -141
  57. package/dist/sdk/firmachain/amino/signature.d.ts +16 -16
  58. package/dist/sdk/firmachain/amino/signature.js +36 -36
  59. package/dist/sdk/firmachain/amino/signdoc.d.ts +26 -26
  60. package/dist/sdk/firmachain/amino/signdoc.js +42 -42
  61. package/dist/sdk/firmachain/amino/signer.d.ts +33 -33
  62. package/dist/sdk/firmachain/amino/signer.js +2 -2
  63. package/dist/sdk/firmachain/amino/stdtx.d.ts +15 -15
  64. package/dist/sdk/firmachain/amino/stdtx.js +17 -17
  65. package/dist/sdk/firmachain/amino/wallet.d.ts +32 -32
  66. package/dist/sdk/firmachain/amino/wallet.js +132 -132
  67. package/dist/sdk/firmachain/bank/BankQueryClient.d.ts +12 -12
  68. package/dist/sdk/firmachain/bank/BankQueryClient.js +116 -116
  69. package/dist/sdk/firmachain/bank/BankTxClient.d.ts +17 -17
  70. package/dist/sdk/firmachain/bank/BankTxClient.js +40 -40
  71. package/dist/sdk/firmachain/bank/index.d.ts +3 -3
  72. package/dist/sdk/firmachain/bank/index.js +15 -15
  73. package/dist/sdk/firmachain/common/ITxClient.d.ts +15 -15
  74. package/dist/sdk/firmachain/common/ITxClient.js +102 -102
  75. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +27 -27
  76. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +165 -165
  77. package/dist/sdk/firmachain/common/LedgerWallet.d.ts +14 -9
  78. package/dist/sdk/firmachain/common/LedgerWallet.js +147 -150
  79. package/dist/sdk/firmachain/common/QueryCommon.d.ts +4 -4
  80. package/dist/sdk/firmachain/common/QueryCommon.js +2 -2
  81. package/dist/sdk/firmachain/common/TendermintQueryClient.d.ts +42 -42
  82. package/dist/sdk/firmachain/common/TendermintQueryClient.js +108 -108
  83. package/dist/sdk/firmachain/common/TxCommon.d.ts +87 -94
  84. package/dist/sdk/firmachain/common/TxCommon.js +18 -34
  85. package/dist/sdk/firmachain/common/accounts.d.ts +16 -16
  86. package/dist/sdk/firmachain/common/accounts.js +64 -64
  87. package/dist/sdk/firmachain/common/index.d.ts +2 -2
  88. package/dist/sdk/firmachain/common/index.js +14 -14
  89. package/dist/sdk/firmachain/common/signing.d.ts +10 -10
  90. package/dist/sdk/firmachain/common/signing.js +75 -75
  91. package/dist/sdk/firmachain/common/signingstargateclient.d.ts +37 -37
  92. package/dist/sdk/firmachain/common/signingstargateclient.js +298 -298
  93. package/dist/sdk/firmachain/common/stargateclient.d.ts +46 -46
  94. package/dist/sdk/firmachain/common/stargateclient.js +211 -211
  95. package/dist/sdk/firmachain/contract/ContractQueryClient.d.ts +32 -31
  96. package/dist/sdk/firmachain/contract/ContractQueryClient.js +156 -141
  97. package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +17 -17
  98. package/dist/sdk/firmachain/contract/ContractTxClient.js +40 -40
  99. package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +69 -69
  100. package/dist/sdk/firmachain/contract/ContractTxTypes.js +483 -483
  101. package/dist/sdk/firmachain/contract/index.d.ts +3 -3
  102. package/dist/sdk/firmachain/contract/index.js +15 -15
  103. package/dist/sdk/firmachain/distribution/DistributionQueryClient.d.ts +18 -18
  104. package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +167 -167
  105. package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +27 -27
  106. package/dist/sdk/firmachain/distribution/DistributionTxClient.js +48 -48
  107. package/dist/sdk/firmachain/distribution/index.d.ts +3 -3
  108. package/dist/sdk/firmachain/distribution/index.js +15 -15
  109. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.d.ts +17 -17
  110. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +86 -86
  111. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +17 -17
  112. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +40 -40
  113. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +76 -76
  114. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +194 -194
  115. package/dist/sdk/firmachain/feegrant/index.d.ts +2 -2
  116. package/dist/sdk/firmachain/feegrant/index.js +15 -15
  117. package/dist/sdk/firmachain/google/protobuf/any.d.ts +128 -128
  118. package/dist/sdk/firmachain/google/protobuf/any.js +106 -106
  119. package/dist/sdk/firmachain/google/protobuf/descriptor.d.ts +996 -996
  120. package/dist/sdk/firmachain/google/protobuf/descriptor.js +5329 -5329
  121. package/dist/sdk/firmachain/google/protobuf/duration.d.ts +91 -91
  122. package/dist/sdk/firmachain/google/protobuf/duration.js +107 -107
  123. package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +109 -109
  124. package/dist/sdk/firmachain/google/protobuf/timestamp.js +107 -107
  125. package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +61 -61
  126. package/dist/sdk/firmachain/gov/GovQueryClient.js +152 -152
  127. package/dist/sdk/firmachain/gov/GovTxClient.d.ts +22 -22
  128. package/dist/sdk/firmachain/gov/GovTxClient.js +44 -44
  129. package/dist/sdk/firmachain/gov/index.d.ts +3 -3
  130. package/dist/sdk/firmachain/gov/index.js +15 -15
  131. package/dist/sdk/firmachain/nft/NftQueryClient.d.ts +20 -17
  132. package/dist/sdk/firmachain/nft/NftQueryClient.js +125 -121
  133. package/dist/sdk/firmachain/nft/NftTxClient.d.ts +22 -22
  134. package/dist/sdk/firmachain/nft/NftTxClient.js +44 -44
  135. package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +86 -86
  136. package/dist/sdk/firmachain/nft/NftTxTypes.js +424 -424
  137. package/dist/sdk/firmachain/nft/index.d.ts +3 -3
  138. package/dist/sdk/firmachain/nft/index.js +15 -15
  139. package/dist/sdk/firmachain/slashing/SlashingQueryClient.d.ts +22 -22
  140. package/dist/sdk/firmachain/slashing/SlashingQueryClient.js +101 -101
  141. package/dist/sdk/firmachain/slashing/index.d.ts +2 -2
  142. package/dist/sdk/firmachain/slashing/index.js +14 -14
  143. package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +93 -93
  144. package/dist/sdk/firmachain/staking/StakingQueryClient.js +223 -223
  145. package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +32 -32
  146. package/dist/sdk/firmachain/staking/StakingTxClient.js +52 -52
  147. package/dist/sdk/firmachain/staking/index.d.ts +3 -3
  148. package/dist/sdk/firmachain/staking/index.js +15 -15
  149. package/dist/sdk/firmachain/token/TokenQueryClient.d.ts +24 -24
  150. package/dist/sdk/firmachain/token/TokenQueryClient.js +106 -106
  151. package/dist/sdk/firmachain/token/TokenTxClient.d.ts +27 -27
  152. package/dist/sdk/firmachain/token/TokenTxClient.js +48 -48
  153. package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +116 -116
  154. package/dist/sdk/firmachain/token/TokenTxTypes.js +685 -685
  155. package/dist/sdk/firmachain/token/index.d.ts +3 -3
  156. package/dist/sdk/firmachain/token/index.js +15 -15
  157. package/package.json +54 -54
@@ -1,234 +1,234 @@
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) {
19
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
20
- to[j] = from[i];
21
- return to;
22
- };
23
- var __values = (this && this.__values) || function(o) {
24
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
25
- if (m) return m.call(o);
26
- if (o && typeof o.length === "number") return {
27
- next: function () {
28
- if (o && i >= o.length) o = void 0;
29
- return { value: o && o[i++], done: !o };
30
- }
31
- };
32
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.encodeBech32Pubkey = exports.encodeAminoPubkey = exports.decodeBech32Pubkey = exports.decodeAminoPubkey = exports.encodeSecp256k1Pubkey = void 0;
36
- var encoding_1 = require("@cosmjs/encoding");
37
- var math_1 = require("@cosmjs/math");
38
- var utils_1 = require("@cosmjs/utils");
39
- var pubkeys_1 = require("./pubkeys");
40
- function encodeSecp256k1Pubkey(pubkey) {
41
- if (pubkey.length !== 33 || (pubkey[0] !== 0x02 && pubkey[0] !== 0x03)) {
42
- throw new Error("Public key must be compressed secp256k1, i.e. 33 bytes starting with 0x02 or 0x03");
43
- }
44
- return {
45
- type: pubkeys_1.pubkeyType.secp256k1,
46
- value: encoding_1.toBase64(pubkey),
47
- };
48
- }
49
- exports.encodeSecp256k1Pubkey = encodeSecp256k1Pubkey;
50
- // As discussed in https://github.com/binance-chain/javascript-sdk/issues/163
51
- // Prefixes listed here: https://github.com/tendermint/tendermint/blob/d419fffe18531317c28c29a292ad7d253f6cafdf/docs/spec/blockchain/encoding.md#public-key-cryptography
52
- // Last bytes is varint-encoded length prefix
53
- var pubkeyAminoPrefixSecp256k1 = encoding_1.fromHex("eb5ae987" + "21" /* fixed length */);
54
- var pubkeyAminoPrefixEd25519 = encoding_1.fromHex("1624de64" + "20" /* fixed length */);
55
- var pubkeyAminoPrefixSr25519 = encoding_1.fromHex("0dfb1005" + "20" /* fixed length */);
56
- /** See https://github.com/tendermint/tendermint/commit/38b401657e4ad7a7eeb3c30a3cbf512037df3740 */
57
- var pubkeyAminoPrefixMultisigThreshold = encoding_1.fromHex("22c1f7e2" /* variable length not included */);
58
- /**
59
- * Decodes a pubkey in the Amino binary format to a type/value object.
60
- */
61
- function decodeAminoPubkey(data) {
62
- if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixSecp256k1)) {
63
- var rest = data.slice(pubkeyAminoPrefixSecp256k1.length);
64
- if (rest.length !== 33) {
65
- throw new Error("Invalid rest data length. Expected 33 bytes (compressed secp256k1 pubkey).");
66
- }
67
- return {
68
- type: pubkeys_1.pubkeyType.secp256k1,
69
- value: encoding_1.toBase64(rest),
70
- };
71
- }
72
- else if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixEd25519)) {
73
- var rest = data.slice(pubkeyAminoPrefixEd25519.length);
74
- if (rest.length !== 32) {
75
- throw new Error("Invalid rest data length. Expected 32 bytes (Ed25519 pubkey).");
76
- }
77
- return {
78
- type: pubkeys_1.pubkeyType.ed25519,
79
- value: encoding_1.toBase64(rest),
80
- };
81
- }
82
- else if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixSr25519)) {
83
- var rest = data.slice(pubkeyAminoPrefixSr25519.length);
84
- if (rest.length !== 32) {
85
- throw new Error("Invalid rest data length. Expected 32 bytes (Sr25519 pubkey).");
86
- }
87
- return {
88
- type: pubkeys_1.pubkeyType.sr25519,
89
- value: encoding_1.toBase64(rest),
90
- };
91
- }
92
- else if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixMultisigThreshold)) {
93
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
94
- return decodeMultisigPubkey(data);
95
- }
96
- else {
97
- throw new Error("Unsupported public key type. Amino data starts with: " + encoding_1.toHex(data.slice(0, 5)));
98
- }
99
- }
100
- exports.decodeAminoPubkey = decodeAminoPubkey;
101
- /**
102
- * Decodes a bech32 pubkey to Amino binary, which is then decoded to a type/value object.
103
- * The bech32 prefix is ignored and discareded.
104
- *
105
- * @param bechEncoded the bech32 encoded pubkey
106
- */
107
- function decodeBech32Pubkey(bechEncoded) {
108
- var data = encoding_1.Bech32.decode(bechEncoded).data;
109
- return decodeAminoPubkey(data);
110
- }
111
- exports.decodeBech32Pubkey = decodeBech32Pubkey;
112
- /**
113
- * Uvarint decoder for Amino.
114
- * @see https://github.com/tendermint/go-amino/blob/8e779b71f40d175/decoder.go#L64-76
115
- * @returns varint as number, and bytes count occupied by varaint
116
- */
117
- function decodeUvarint(reader) {
118
- if (reader.length < 1) {
119
- throw new Error("Can't decode varint. EOF");
120
- }
121
- if (reader[0] > 127) {
122
- 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.");
123
- }
124
- return [reader[0], 1];
125
- }
126
- /**
127
- * Decodes a multisig pubkey to type object.
128
- * Pubkey structure [ prefix + const + threshold + loop:(const + pubkeyLength + pubkey ) ]
129
- * [ 4b + 1b + varint + loop:(1b + varint + pubkeyLength bytes) ]
130
- * @param data encoded pubkey
131
- */
132
- function decodeMultisigPubkey(data) {
133
- var reader = Array.from(data);
134
- // remove multisig amino prefix;
135
- var prefixFromReader = reader.splice(0, pubkeyAminoPrefixMultisigThreshold.length);
136
- if (!utils_1.arrayContentStartsWith(prefixFromReader, pubkeyAminoPrefixMultisigThreshold)) {
137
- throw new Error("Invalid multisig prefix.");
138
- }
139
- // remove 0x08 threshold prefix;
140
- if (reader.shift() != 0x08) {
141
- throw new Error("Invalid multisig data. Expecting 0x08 prefix before threshold.");
142
- }
143
- // read threshold
144
- var _a = __read(decodeUvarint(reader), 2), threshold = _a[0], thresholdBytesLength = _a[1];
145
- reader.splice(0, thresholdBytesLength);
146
- // read participants pubkeys
147
- var pubkeys = [];
148
- while (reader.length > 0) {
149
- // remove 0x12 threshold prefix;
150
- if (reader.shift() != 0x12) {
151
- throw new Error("Invalid multisig data. Expecting 0x12 prefix before participant pubkey length.");
152
- }
153
- // read pubkey length
154
- var _b = __read(decodeUvarint(reader), 2), pubkeyLength = _b[0], pubkeyLengthBytesSize = _b[1];
155
- reader.splice(0, pubkeyLengthBytesSize);
156
- // verify that we can read pubkey
157
- if (reader.length < pubkeyLength) {
158
- throw new Error("Invalid multisig data length.");
159
- }
160
- // read and decode participant pubkey
161
- var encodedPubkey = reader.splice(0, pubkeyLength);
162
- var pubkey = decodeAminoPubkey(Uint8Array.from(encodedPubkey));
163
- pubkeys.push(pubkey);
164
- }
165
- return {
166
- type: pubkeys_1.pubkeyType.multisigThreshold,
167
- value: {
168
- threshold: threshold.toString(),
169
- pubkeys: pubkeys,
170
- },
171
- };
172
- }
173
- /**
174
- * Uvarint encoder for Amino. This is the same encoding as `binary.PutUvarint` from the Go
175
- * standard library.
176
- *
177
- * @see https://github.com/tendermint/go-amino/blob/8e779b71f40d175/encoder.go#L77-L85
178
- */
179
- function encodeUvarint(value) {
180
- var checked = math_1.Uint53.fromString(value.toString()).toNumber();
181
- if (checked > 127) {
182
- 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.");
183
- }
184
- return [checked];
185
- }
186
- /**
187
- * Encodes a public key to binary Amino.
188
- */
189
- function encodeAminoPubkey(pubkey) {
190
- var e_1, _a;
191
- if (pubkeys_1.isMultisigThresholdPubkey(pubkey)) {
192
- var out = Array.from(pubkeyAminoPrefixMultisigThreshold);
193
- out.push(0x08); // TODO: What is this?
194
- out.push.apply(// TODO: What is this?
195
- out, __spreadArray([], __read(encodeUvarint(pubkey.value.threshold))));
196
- try {
197
- for (var _b = __values(pubkey.value.pubkeys.map(function (p) { return encodeAminoPubkey(p); })), _c = _b.next(); !_c.done; _c = _b.next()) {
198
- var pubkeyData = _c.value;
199
- out.push(0x12); // TODO: What is this?
200
- out.push.apply(// TODO: What is this?
201
- out, __spreadArray([], __read(encodeUvarint(pubkeyData.length))));
202
- out.push.apply(out, __spreadArray([], __read(pubkeyData)));
203
- }
204
- }
205
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
206
- finally {
207
- try {
208
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
209
- }
210
- finally { if (e_1) throw e_1.error; }
211
- }
212
- return new Uint8Array(out);
213
- }
214
- else if (pubkeys_1.isEd25519Pubkey(pubkey)) {
215
- return new Uint8Array(__spreadArray(__spreadArray([], __read(pubkeyAminoPrefixEd25519)), __read(encoding_1.fromBase64(pubkey.value))));
216
- }
217
- else if (pubkeys_1.isSecp256k1Pubkey(pubkey)) {
218
- return new Uint8Array(__spreadArray(__spreadArray([], __read(pubkeyAminoPrefixSecp256k1)), __read(encoding_1.fromBase64(pubkey.value))));
219
- }
220
- else {
221
- throw new Error("Unsupported pubkey type");
222
- }
223
- }
224
- exports.encodeAminoPubkey = encodeAminoPubkey;
225
- /**
226
- * Encodes a public key to binary Amino and then to bech32.
227
- *
228
- * @param pubkey the public key to encode
229
- * @param prefix the bech32 prefix (human readable part)
230
- */
231
- function encodeBech32Pubkey(pubkey, prefix) {
232
- return encoding_1.Bech32.encode(prefix, encodeAminoPubkey(pubkey));
233
- }
234
- exports.encodeBech32Pubkey = encodeBech32Pubkey;
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) {
19
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
20
+ to[j] = from[i];
21
+ return to;
22
+ };
23
+ var __values = (this && this.__values) || function(o) {
24
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
25
+ if (m) return m.call(o);
26
+ if (o && typeof o.length === "number") return {
27
+ next: function () {
28
+ if (o && i >= o.length) o = void 0;
29
+ return { value: o && o[i++], done: !o };
30
+ }
31
+ };
32
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.encodeBech32Pubkey = exports.encodeAminoPubkey = exports.decodeBech32Pubkey = exports.decodeAminoPubkey = exports.encodeSecp256k1Pubkey = void 0;
36
+ var encoding_1 = require("@cosmjs/encoding");
37
+ var math_1 = require("@cosmjs/math");
38
+ var utils_1 = require("@cosmjs/utils");
39
+ var pubkeys_1 = require("./pubkeys");
40
+ function encodeSecp256k1Pubkey(pubkey) {
41
+ if (pubkey.length !== 33 || (pubkey[0] !== 0x02 && pubkey[0] !== 0x03)) {
42
+ throw new Error("Public key must be compressed secp256k1, i.e. 33 bytes starting with 0x02 or 0x03");
43
+ }
44
+ return {
45
+ type: pubkeys_1.pubkeyType.secp256k1,
46
+ value: encoding_1.toBase64(pubkey),
47
+ };
48
+ }
49
+ exports.encodeSecp256k1Pubkey = encodeSecp256k1Pubkey;
50
+ // As discussed in https://github.com/binance-chain/javascript-sdk/issues/163
51
+ // Prefixes listed here: https://github.com/tendermint/tendermint/blob/d419fffe18531317c28c29a292ad7d253f6cafdf/docs/spec/blockchain/encoding.md#public-key-cryptography
52
+ // Last bytes is varint-encoded length prefix
53
+ var pubkeyAminoPrefixSecp256k1 = encoding_1.fromHex("eb5ae987" + "21" /* fixed length */);
54
+ var pubkeyAminoPrefixEd25519 = encoding_1.fromHex("1624de64" + "20" /* fixed length */);
55
+ var pubkeyAminoPrefixSr25519 = encoding_1.fromHex("0dfb1005" + "20" /* fixed length */);
56
+ /** See https://github.com/tendermint/tendermint/commit/38b401657e4ad7a7eeb3c30a3cbf512037df3740 */
57
+ var pubkeyAminoPrefixMultisigThreshold = encoding_1.fromHex("22c1f7e2" /* variable length not included */);
58
+ /**
59
+ * Decodes a pubkey in the Amino binary format to a type/value object.
60
+ */
61
+ function decodeAminoPubkey(data) {
62
+ if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixSecp256k1)) {
63
+ var rest = data.slice(pubkeyAminoPrefixSecp256k1.length);
64
+ if (rest.length !== 33) {
65
+ throw new Error("Invalid rest data length. Expected 33 bytes (compressed secp256k1 pubkey).");
66
+ }
67
+ return {
68
+ type: pubkeys_1.pubkeyType.secp256k1,
69
+ value: encoding_1.toBase64(rest),
70
+ };
71
+ }
72
+ else if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixEd25519)) {
73
+ var rest = data.slice(pubkeyAminoPrefixEd25519.length);
74
+ if (rest.length !== 32) {
75
+ throw new Error("Invalid rest data length. Expected 32 bytes (Ed25519 pubkey).");
76
+ }
77
+ return {
78
+ type: pubkeys_1.pubkeyType.ed25519,
79
+ value: encoding_1.toBase64(rest),
80
+ };
81
+ }
82
+ else if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixSr25519)) {
83
+ var rest = data.slice(pubkeyAminoPrefixSr25519.length);
84
+ if (rest.length !== 32) {
85
+ throw new Error("Invalid rest data length. Expected 32 bytes (Sr25519 pubkey).");
86
+ }
87
+ return {
88
+ type: pubkeys_1.pubkeyType.sr25519,
89
+ value: encoding_1.toBase64(rest),
90
+ };
91
+ }
92
+ else if (utils_1.arrayContentStartsWith(data, pubkeyAminoPrefixMultisigThreshold)) {
93
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
94
+ return decodeMultisigPubkey(data);
95
+ }
96
+ else {
97
+ throw new Error("Unsupported public key type. Amino data starts with: " + encoding_1.toHex(data.slice(0, 5)));
98
+ }
99
+ }
100
+ exports.decodeAminoPubkey = decodeAminoPubkey;
101
+ /**
102
+ * Decodes a bech32 pubkey to Amino binary, which is then decoded to a type/value object.
103
+ * The bech32 prefix is ignored and discareded.
104
+ *
105
+ * @param bechEncoded the bech32 encoded pubkey
106
+ */
107
+ function decodeBech32Pubkey(bechEncoded) {
108
+ var data = encoding_1.Bech32.decode(bechEncoded).data;
109
+ return decodeAminoPubkey(data);
110
+ }
111
+ exports.decodeBech32Pubkey = decodeBech32Pubkey;
112
+ /**
113
+ * Uvarint decoder for Amino.
114
+ * @see https://github.com/tendermint/go-amino/blob/8e779b71f40d175/decoder.go#L64-76
115
+ * @returns varint as number, and bytes count occupied by varaint
116
+ */
117
+ function decodeUvarint(reader) {
118
+ if (reader.length < 1) {
119
+ throw new Error("Can't decode varint. EOF");
120
+ }
121
+ if (reader[0] > 127) {
122
+ 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.");
123
+ }
124
+ return [reader[0], 1];
125
+ }
126
+ /**
127
+ * Decodes a multisig pubkey to type object.
128
+ * Pubkey structure [ prefix + const + threshold + loop:(const + pubkeyLength + pubkey ) ]
129
+ * [ 4b + 1b + varint + loop:(1b + varint + pubkeyLength bytes) ]
130
+ * @param data encoded pubkey
131
+ */
132
+ function decodeMultisigPubkey(data) {
133
+ var reader = Array.from(data);
134
+ // remove multisig amino prefix;
135
+ var prefixFromReader = reader.splice(0, pubkeyAminoPrefixMultisigThreshold.length);
136
+ if (!utils_1.arrayContentStartsWith(prefixFromReader, pubkeyAminoPrefixMultisigThreshold)) {
137
+ throw new Error("Invalid multisig prefix.");
138
+ }
139
+ // remove 0x08 threshold prefix;
140
+ if (reader.shift() != 0x08) {
141
+ throw new Error("Invalid multisig data. Expecting 0x08 prefix before threshold.");
142
+ }
143
+ // read threshold
144
+ var _a = __read(decodeUvarint(reader), 2), threshold = _a[0], thresholdBytesLength = _a[1];
145
+ reader.splice(0, thresholdBytesLength);
146
+ // read participants pubkeys
147
+ var pubkeys = [];
148
+ while (reader.length > 0) {
149
+ // remove 0x12 threshold prefix;
150
+ if (reader.shift() != 0x12) {
151
+ throw new Error("Invalid multisig data. Expecting 0x12 prefix before participant pubkey length.");
152
+ }
153
+ // read pubkey length
154
+ var _b = __read(decodeUvarint(reader), 2), pubkeyLength = _b[0], pubkeyLengthBytesSize = _b[1];
155
+ reader.splice(0, pubkeyLengthBytesSize);
156
+ // verify that we can read pubkey
157
+ if (reader.length < pubkeyLength) {
158
+ throw new Error("Invalid multisig data length.");
159
+ }
160
+ // read and decode participant pubkey
161
+ var encodedPubkey = reader.splice(0, pubkeyLength);
162
+ var pubkey = decodeAminoPubkey(Uint8Array.from(encodedPubkey));
163
+ pubkeys.push(pubkey);
164
+ }
165
+ return {
166
+ type: pubkeys_1.pubkeyType.multisigThreshold,
167
+ value: {
168
+ threshold: threshold.toString(),
169
+ pubkeys: pubkeys,
170
+ },
171
+ };
172
+ }
173
+ /**
174
+ * Uvarint encoder for Amino. This is the same encoding as `binary.PutUvarint` from the Go
175
+ * standard library.
176
+ *
177
+ * @see https://github.com/tendermint/go-amino/blob/8e779b71f40d175/encoder.go#L77-L85
178
+ */
179
+ function encodeUvarint(value) {
180
+ var checked = math_1.Uint53.fromString(value.toString()).toNumber();
181
+ if (checked > 127) {
182
+ 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.");
183
+ }
184
+ return [checked];
185
+ }
186
+ /**
187
+ * Encodes a public key to binary Amino.
188
+ */
189
+ function encodeAminoPubkey(pubkey) {
190
+ var e_1, _a;
191
+ if (pubkeys_1.isMultisigThresholdPubkey(pubkey)) {
192
+ var out = Array.from(pubkeyAminoPrefixMultisigThreshold);
193
+ out.push(0x08); // TODO: What is this?
194
+ out.push.apply(// TODO: What is this?
195
+ out, __spreadArray([], __read(encodeUvarint(pubkey.value.threshold))));
196
+ try {
197
+ for (var _b = __values(pubkey.value.pubkeys.map(function (p) { return encodeAminoPubkey(p); })), _c = _b.next(); !_c.done; _c = _b.next()) {
198
+ var pubkeyData = _c.value;
199
+ out.push(0x12); // TODO: What is this?
200
+ out.push.apply(// TODO: What is this?
201
+ out, __spreadArray([], __read(encodeUvarint(pubkeyData.length))));
202
+ out.push.apply(out, __spreadArray([], __read(pubkeyData)));
203
+ }
204
+ }
205
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
206
+ finally {
207
+ try {
208
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
209
+ }
210
+ finally { if (e_1) throw e_1.error; }
211
+ }
212
+ return new Uint8Array(out);
213
+ }
214
+ else if (pubkeys_1.isEd25519Pubkey(pubkey)) {
215
+ return new Uint8Array(__spreadArray(__spreadArray([], __read(pubkeyAminoPrefixEd25519)), __read(encoding_1.fromBase64(pubkey.value))));
216
+ }
217
+ else if (pubkeys_1.isSecp256k1Pubkey(pubkey)) {
218
+ return new Uint8Array(__spreadArray(__spreadArray([], __read(pubkeyAminoPrefixSecp256k1)), __read(encoding_1.fromBase64(pubkey.value))));
219
+ }
220
+ else {
221
+ throw new Error("Unsupported pubkey type");
222
+ }
223
+ }
224
+ exports.encodeAminoPubkey = encodeAminoPubkey;
225
+ /**
226
+ * Encodes a public key to binary Amino and then to bech32.
227
+ *
228
+ * @param pubkey the public key to encode
229
+ * @param prefix the bech32 prefix (human readable part)
230
+ */
231
+ function encodeBech32Pubkey(pubkey, prefix) {
232
+ return encoding_1.Bech32.encode(prefix, encodeAminoPubkey(pubkey));
233
+ }
234
+ exports.encodeBech32Pubkey = encodeBech32Pubkey;
@@ -1,10 +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;
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;
@@ -1,42 +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 = encoding_1.toHex(a);
16
- var bHex = 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 = " + uintThreshold.toNumber() + " exceeds number of keys n = " + 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 = addresses_1.pubkeyToRawAddress(lhs);
31
- var addressRhs = 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;
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 = encoding_1.toHex(a);
16
+ var bHex = 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 = " + uintThreshold.toNumber() + " exceeds number of keys n = " + 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 = addresses_1.pubkeyToRawAddress(lhs);
31
+ var addressRhs = 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;
@@ -1,6 +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;
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;
@@ -1,18 +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;
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;