@firmachain/firma-js 0.2.17 → 0.2.21

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 -0
  4. package/dist/index.js +16 -0
  5. package/dist/sdk/FirmaBankService.d.ts +15 -0
  6. package/dist/sdk/FirmaBankService.js +211 -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 +16 -0
  10. package/dist/sdk/FirmaConfig.js +55 -0
  11. package/dist/sdk/FirmaContractService.d.ts +31 -0
  12. package/dist/sdk/FirmaContractService.js +413 -0
  13. package/dist/sdk/FirmaDistributionService.d.ts +31 -0
  14. package/dist/sdk/FirmaDistributionService.js +524 -0
  15. package/dist/sdk/FirmaFeeGrantService.d.ts +21 -0
  16. package/dist/sdk/FirmaFeeGrantService.js +341 -0
  17. package/dist/sdk/FirmaGovService.d.ts +35 -0
  18. package/dist/sdk/FirmaGovService.js +775 -0
  19. package/dist/sdk/FirmaIpfsService.d.ts +12 -0
  20. package/dist/sdk/FirmaIpfsService.js +185 -0
  21. package/dist/sdk/FirmaMobileSDK.d.ts +27 -0
  22. package/dist/sdk/FirmaMobileSDK.js +45 -0
  23. package/dist/sdk/FirmaNftService.d.ts +31 -0
  24. package/dist/sdk/FirmaNftService.js +372 -0
  25. package/dist/sdk/FirmaSDK.d.ts +29 -0
  26. package/dist/sdk/FirmaSDK.js +48 -0
  27. package/dist/sdk/FirmaSlashingService.d.ts +9 -0
  28. package/dist/sdk/FirmaSlashingService.js +105 -0
  29. package/dist/sdk/FirmaStakingService.d.ts +34 -0
  30. package/dist/sdk/FirmaStakingService.js +604 -0
  31. package/dist/sdk/FirmaTokenService.d.ts +26 -0
  32. package/dist/sdk/FirmaTokenService.js +416 -0
  33. package/dist/sdk/FirmaUtil.d.ts +26 -0
  34. package/dist/sdk/FirmaUtil.js +210 -0
  35. package/dist/sdk/FirmaWalletService.d.ts +36 -0
  36. package/dist/sdk/FirmaWalletService.js +309 -0
  37. package/dist/sdk/firmachain/amino/addresses.d.ts +5 -0
  38. package/dist/sdk/firmachain/amino/addresses.js +46 -0
  39. package/dist/sdk/firmachain/amino/aminomsgs.d.ts +281 -0
  40. package/dist/sdk/firmachain/amino/aminomsgs.js +77 -0
  41. package/dist/sdk/firmachain/amino/aminotypes.d.ts +22 -0
  42. package/dist/sdk/firmachain/amino/aminotypes.js +521 -0
  43. package/dist/sdk/firmachain/amino/coins.d.ts +30 -0
  44. package/dist/sdk/firmachain/amino/coins.js +69 -0
  45. package/dist/sdk/firmachain/amino/encoding.d.ts +24 -0
  46. package/dist/sdk/firmachain/amino/encoding.js +234 -0
  47. package/dist/sdk/firmachain/amino/multisig.d.ts +10 -0
  48. package/dist/sdk/firmachain/amino/multisig.js +42 -0
  49. package/dist/sdk/firmachain/amino/paths.d.ts +6 -0
  50. package/dist/sdk/firmachain/amino/paths.js +18 -0
  51. package/dist/sdk/firmachain/amino/pubkeys.d.ts +47 -0
  52. package/dist/sdk/firmachain/amino/pubkeys.js +29 -0
  53. package/dist/sdk/firmachain/amino/secp256k1hdwallet.d.ts +94 -0
  54. package/dist/sdk/firmachain/amino/secp256k1hdwallet.js +437 -0
  55. package/dist/sdk/firmachain/amino/secp256k1wallet.d.ts +23 -0
  56. package/dist/sdk/firmachain/amino/secp256k1wallet.js +141 -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 +33 -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 +132 -0
  67. package/dist/sdk/firmachain/bank/BankQueryClient.d.ts +12 -0
  68. package/dist/sdk/firmachain/bank/BankQueryClient.js +116 -0
  69. package/dist/sdk/firmachain/bank/BankTxClient.d.ts +17 -0
  70. package/dist/sdk/firmachain/bank/BankTxClient.js +40 -0
  71. package/dist/sdk/firmachain/bank/index.d.ts +3 -0
  72. package/dist/sdk/firmachain/bank/index.js +15 -0
  73. package/dist/sdk/firmachain/common/ITxClient.d.ts +15 -0
  74. package/dist/sdk/firmachain/common/ITxClient.js +102 -0
  75. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.d.ts +27 -0
  76. package/dist/sdk/firmachain/common/LedgerSigningStargateClient.js +165 -0
  77. package/dist/sdk/firmachain/common/LedgerWallet.d.ts +14 -0
  78. package/dist/sdk/firmachain/common/LedgerWallet.js +147 -0
  79. package/dist/sdk/firmachain/common/QueryCommon.d.ts +4 -0
  80. package/dist/sdk/firmachain/common/QueryCommon.js +2 -0
  81. package/dist/sdk/firmachain/common/TendermintQueryClient.d.ts +42 -0
  82. package/dist/sdk/firmachain/common/TendermintQueryClient.js +108 -0
  83. package/dist/sdk/firmachain/common/TxCommon.d.ts +94 -0
  84. package/dist/sdk/firmachain/common/TxCommon.js +34 -0
  85. package/dist/sdk/firmachain/common/accounts.d.ts +16 -0
  86. package/dist/sdk/firmachain/common/accounts.js +64 -0
  87. package/dist/sdk/firmachain/common/index.d.ts +2 -0
  88. package/dist/sdk/firmachain/common/index.js +14 -0
  89. package/dist/sdk/firmachain/common/signing.d.ts +10 -0
  90. package/dist/sdk/firmachain/common/signing.js +75 -0
  91. package/dist/sdk/firmachain/common/signingstargateclient.d.ts +37 -0
  92. package/dist/sdk/firmachain/common/signingstargateclient.js +298 -0
  93. package/dist/sdk/firmachain/common/stargateclient.d.ts +46 -0
  94. package/dist/sdk/firmachain/common/stargateclient.js +211 -0
  95. package/dist/sdk/firmachain/contract/ContractQueryClient.d.ts +32 -0
  96. package/dist/sdk/firmachain/contract/ContractQueryClient.js +156 -0
  97. package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +17 -0
  98. package/dist/sdk/firmachain/contract/ContractTxClient.js +40 -0
  99. package/dist/sdk/firmachain/contract/ContractTxTypes.d.ts +69 -0
  100. package/dist/sdk/firmachain/contract/ContractTxTypes.js +483 -0
  101. package/dist/sdk/firmachain/contract/index.d.ts +3 -0
  102. package/dist/sdk/firmachain/contract/index.js +15 -0
  103. package/dist/sdk/firmachain/distribution/DistributionQueryClient.d.ts +18 -0
  104. package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +167 -0
  105. package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +27 -0
  106. package/dist/sdk/firmachain/distribution/DistributionTxClient.js +48 -0
  107. package/dist/sdk/firmachain/distribution/index.d.ts +3 -0
  108. package/dist/sdk/firmachain/distribution/index.js +15 -0
  109. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.d.ts +17 -0
  110. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +86 -0
  111. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +17 -0
  112. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +40 -0
  113. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.d.ts +76 -0
  114. package/dist/sdk/firmachain/feegrant/FeeGrantTxTypes.js +194 -0
  115. package/dist/sdk/firmachain/feegrant/index.d.ts +2 -0
  116. package/dist/sdk/firmachain/feegrant/index.js +15 -0
  117. package/dist/sdk/firmachain/google/protobuf/any.d.ts +128 -0
  118. package/dist/sdk/firmachain/google/protobuf/any.js +106 -0
  119. package/dist/sdk/firmachain/google/protobuf/descriptor.d.ts +996 -0
  120. package/dist/sdk/firmachain/google/protobuf/descriptor.js +5329 -0
  121. package/dist/sdk/firmachain/google/protobuf/duration.d.ts +91 -0
  122. package/dist/sdk/firmachain/google/protobuf/duration.js +107 -0
  123. package/dist/sdk/firmachain/google/protobuf/timestamp.d.ts +109 -0
  124. package/dist/sdk/firmachain/google/protobuf/timestamp.js +107 -0
  125. package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +61 -0
  126. package/dist/sdk/firmachain/gov/GovQueryClient.js +152 -0
  127. package/dist/sdk/firmachain/gov/GovTxClient.d.ts +22 -0
  128. package/dist/sdk/firmachain/gov/GovTxClient.js +44 -0
  129. package/dist/sdk/firmachain/gov/index.d.ts +3 -0
  130. package/dist/sdk/firmachain/gov/index.js +15 -0
  131. package/dist/sdk/firmachain/nft/NftQueryClient.d.ts +20 -0
  132. package/dist/sdk/firmachain/nft/NftQueryClient.js +125 -0
  133. package/dist/sdk/firmachain/nft/NftTxClient.d.ts +22 -0
  134. package/dist/sdk/firmachain/nft/NftTxClient.js +44 -0
  135. package/dist/sdk/firmachain/nft/NftTxTypes.d.ts +86 -0
  136. package/dist/sdk/firmachain/nft/NftTxTypes.js +424 -0
  137. package/dist/sdk/firmachain/nft/index.d.ts +3 -0
  138. package/dist/sdk/firmachain/nft/index.js +15 -0
  139. package/dist/sdk/firmachain/slashing/SlashingQueryClient.d.ts +22 -0
  140. package/dist/sdk/firmachain/slashing/SlashingQueryClient.js +101 -0
  141. package/dist/sdk/firmachain/slashing/index.d.ts +2 -0
  142. package/dist/sdk/firmachain/slashing/index.js +14 -0
  143. package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +93 -0
  144. package/dist/sdk/firmachain/staking/StakingQueryClient.js +223 -0
  145. package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +32 -0
  146. package/dist/sdk/firmachain/staking/StakingTxClient.js +52 -0
  147. package/dist/sdk/firmachain/staking/index.d.ts +3 -0
  148. package/dist/sdk/firmachain/staking/index.js +15 -0
  149. package/dist/sdk/firmachain/token/TokenQueryClient.d.ts +24 -0
  150. package/dist/sdk/firmachain/token/TokenQueryClient.js +106 -0
  151. package/dist/sdk/firmachain/token/TokenTxClient.d.ts +27 -0
  152. package/dist/sdk/firmachain/token/TokenTxClient.js +48 -0
  153. package/dist/sdk/firmachain/token/TokenTxTypes.d.ts +116 -0
  154. package/dist/sdk/firmachain/token/TokenTxTypes.js +685 -0
  155. package/dist/sdk/firmachain/token/index.d.ts +3 -0
  156. package/dist/sdk/firmachain/token/index.js +15 -0
  157. package/package.json +54 -54
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.accountFromAny = void 0;
4
+ var math_1 = require("@cosmjs/math");
5
+ var proto_signing_1 = require("@cosmjs/proto-signing");
6
+ var auth_1 = require("cosmjs-types/cosmos/auth/v1beta1/auth");
7
+ var vesting_1 = require("cosmjs-types/cosmos/vesting/v1beta1/vesting");
8
+ function uint64FromProto(input) {
9
+ return math_1.Uint64.fromString(input.toString());
10
+ }
11
+ function accountFromBaseAccount(input) {
12
+ var address = input.address, pubKey = input.pubKey, accountNumber = input.accountNumber, sequence = input.sequence;
13
+ var pubkey = proto_signing_1.decodePubkey(pubKey);
14
+ return {
15
+ address: address,
16
+ pubkey: pubkey,
17
+ accountNumber: uint64FromProto(accountNumber).toNumber(),
18
+ sequence: uint64FromProto(sequence).toNumber(),
19
+ };
20
+ }
21
+ /**
22
+ * Takes an `Any` encoded account from the chain and extracts some common
23
+ * `Account` information from it. This is supposed to support the most relevant
24
+ * common Cosmos SDK account types. If you need support for exotic account types,
25
+ * you'll need to write your own account decoder.
26
+ */
27
+ function accountFromAny(input) {
28
+ var _a, _b, _c, _d, _e, _f, _g;
29
+ var typeUrl = input.typeUrl, value = input.value;
30
+ switch (typeUrl) {
31
+ // auth
32
+ case "/cosmos.auth.v1beta1.BaseAccount":
33
+ return accountFromBaseAccount(auth_1.BaseAccount.decode(value));
34
+ case "/cosmos.auth.v1beta1.ModuleAccount":
35
+ {
36
+ var baseAccount = auth_1.ModuleAccount.decode(value).baseAccount;
37
+ return accountFromBaseAccount(baseAccount);
38
+ }
39
+ // vesting
40
+ case "/cosmos.vesting.v1beta1.BaseVestingAccount":
41
+ {
42
+ var baseAccount = (_a = vesting_1.BaseVestingAccount.decode(value)) === null || _a === void 0 ? void 0 : _a.baseAccount;
43
+ return accountFromBaseAccount(baseAccount);
44
+ }
45
+ case "/cosmos.vesting.v1beta1.ContinuousVestingAccount":
46
+ {
47
+ var baseAccount = (_c = (_b = vesting_1.ContinuousVestingAccount.decode(value)) === null || _b === void 0 ? void 0 : _b.baseVestingAccount) === null || _c === void 0 ? void 0 : _c.baseAccount;
48
+ return accountFromBaseAccount(baseAccount);
49
+ }
50
+ case "/cosmos.vesting.v1beta1.DelayedVestingAccount":
51
+ {
52
+ var baseAccount = (_e = (_d = vesting_1.DelayedVestingAccount.decode(value)) === null || _d === void 0 ? void 0 : _d.baseVestingAccount) === null || _e === void 0 ? void 0 : _e.baseAccount;
53
+ return accountFromBaseAccount(baseAccount);
54
+ }
55
+ case "/cosmos.vesting.v1beta1.PeriodicVestingAccount":
56
+ {
57
+ var baseAccount = (_g = (_f = vesting_1.PeriodicVestingAccount.decode(value)) === null || _f === void 0 ? void 0 : _f.baseVestingAccount) === null || _g === void 0 ? void 0 : _g.baseAccount;
58
+ return accountFromBaseAccount(baseAccount);
59
+ }
60
+ default:
61
+ throw new Error("Unsupported type: '" + typeUrl + "'");
62
+ }
63
+ }
64
+ exports.accountFromAny = accountFromAny;
@@ -0,0 +1,2 @@
1
+ export * from './TxCommon';
2
+ export * from './QueryCommon';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./TxCommon"), exports);
14
+ __exportStar(require("./QueryCommon"), exports);
@@ -0,0 +1,10 @@
1
+ import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
2
+ import { SignMode } from "cosmjs-types/cosmos/tx/signing/v1beta1/signing";
3
+ import { SignDoc } from "cosmjs-types/cosmos/tx/v1beta1/tx";
4
+ import { Any } from "../google/protobuf/any";
5
+ export declare function makeAuthInfoBytes(signers: ReadonlyArray<{
6
+ readonly pubkey: Any;
7
+ readonly sequence: number;
8
+ }>, feeAmount: readonly Coin[], gasLimit: number, granter: string, signMode?: SignMode): Uint8Array;
9
+ export declare function makeSignDoc(bodyBytes: Uint8Array, authInfoBytes: Uint8Array, chainId: string, accountNumber: number): SignDoc;
10
+ export declare function makeSignBytes({ accountNumber, authInfoBytes, bodyBytes, chainId }: SignDoc): Uint8Array;
@@ -0,0 +1,75 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
24
+ return (mod && mod.__esModule) ? mod : { "default": mod };
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.makeSignBytes = exports.makeSignDoc = exports.makeAuthInfoBytes = void 0;
28
+ var signing_1 = require("cosmjs-types/cosmos/tx/signing/v1beta1/signing");
29
+ var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
30
+ var long_1 = __importDefault(require("long"));
31
+ function makeSignerInfos(signers, signMode) {
32
+ return signers.map(function (_a) {
33
+ var pubkey = _a.pubkey, sequence = _a.sequence;
34
+ return ({
35
+ publicKey: pubkey,
36
+ modeInfo: {
37
+ single: { mode: signMode },
38
+ },
39
+ sequence: long_1.default.fromNumber(sequence),
40
+ });
41
+ });
42
+ }
43
+ function makeAuthInfoBytes(signers, feeAmount, gasLimit, granter, signMode) {
44
+ if (signMode === void 0) { signMode = signing_1.SignMode.SIGN_MODE_DIRECT; }
45
+ var authInfo = {
46
+ signerInfos: makeSignerInfos(signers, signMode),
47
+ fee: {
48
+ amount: __spreadArray([], __read(feeAmount)),
49
+ gasLimit: long_1.default.fromNumber(gasLimit),
50
+ granter: granter,
51
+ },
52
+ };
53
+ return tx_1.AuthInfo.encode(tx_1.AuthInfo.fromPartial(authInfo)).finish();
54
+ }
55
+ exports.makeAuthInfoBytes = makeAuthInfoBytes;
56
+ function makeSignDoc(bodyBytes, authInfoBytes, chainId, accountNumber) {
57
+ return {
58
+ bodyBytes: bodyBytes,
59
+ authInfoBytes: authInfoBytes,
60
+ chainId: chainId,
61
+ accountNumber: long_1.default.fromNumber(accountNumber),
62
+ };
63
+ }
64
+ exports.makeSignDoc = makeSignDoc;
65
+ function makeSignBytes(_a) {
66
+ var accountNumber = _a.accountNumber, authInfoBytes = _a.authInfoBytes, bodyBytes = _a.bodyBytes, chainId = _a.chainId;
67
+ var signDoc = tx_1.SignDoc.fromPartial({
68
+ accountNumber: accountNumber,
69
+ authInfoBytes: authInfoBytes,
70
+ bodyBytes: bodyBytes,
71
+ chainId: chainId,
72
+ });
73
+ return tx_1.SignDoc.encode(signDoc).finish();
74
+ }
75
+ exports.makeSignBytes = makeSignBytes;
@@ -0,0 +1,37 @@
1
+ import { EncodeObject, OfflineDirectSigner, Registry } from "@cosmjs/proto-signing";
2
+ import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
3
+ import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
4
+ import { StdFee } from ".";
5
+ import { Account } from "./accounts";
6
+ import { BroadcastTxResponse, StargateClient } from "./stargateclient";
7
+ export interface SignerData {
8
+ readonly accountNumber: number;
9
+ readonly sequence: number;
10
+ readonly chainId: string;
11
+ }
12
+ export interface SequenceResponse {
13
+ readonly accountNumber: number;
14
+ readonly sequence: number;
15
+ }
16
+ export declare class SigningStargateClient extends StargateClient {
17
+ private readonly signer;
18
+ private readonly registry;
19
+ private chainId;
20
+ private static _endpoint;
21
+ static connectWithSigner(endpoint: string, signer: OfflineDirectSigner, registry: Registry): Promise<SigningStargateClient>;
22
+ protected constructor(tmClient: Tendermint34Client | undefined, signer: OfflineDirectSigner, registry: Registry);
23
+ signAndBroadcast(signerAddress: string, messages: readonly EncodeObject[], fee: StdFee, memo?: string): Promise<BroadcastTxResponse>;
24
+ sign(signerAddress: string, messages: readonly EncodeObject[], fee: StdFee, memo: string, explicitSignerData?: SignerData): Promise<TxRaw>;
25
+ getChainId(): Promise<string>;
26
+ /**
27
+ * Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded.
28
+ * This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data.
29
+ * The result is typically 20 bytes long but not restricted to that.
30
+ */
31
+ private toAccAddress;
32
+ getAccount(address: string): Promise<Account | undefined>;
33
+ getSequence(address: string): Promise<SequenceResponse>;
34
+ private makeSignerInfos;
35
+ private makeAuthInfoBytes;
36
+ private signDirect;
37
+ }
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __read = (this && this.__read) || function (o, n) {
54
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
55
+ if (!m) return o;
56
+ var i = m.call(o), r, ar = [], e;
57
+ try {
58
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
59
+ }
60
+ catch (error) { e = { error: error }; }
61
+ finally {
62
+ try {
63
+ if (r && !r.done && (m = i["return"])) m.call(i);
64
+ }
65
+ finally { if (e) throw e.error; }
66
+ }
67
+ return ar;
68
+ };
69
+ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
70
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
71
+ to[j] = from[i];
72
+ return to;
73
+ };
74
+ var __importDefault = (this && this.__importDefault) || function (mod) {
75
+ return (mod && mod.__esModule) ? mod : { "default": mod };
76
+ };
77
+ Object.defineProperty(exports, "__esModule", { value: true });
78
+ exports.SigningStargateClient = void 0;
79
+ var encoding_1 = require("@cosmjs/encoding");
80
+ var encoding_2 = require("@cosmjs/encoding");
81
+ var proto_signing_1 = require("@cosmjs/proto-signing");
82
+ var tendermint_rpc_1 = require("@cosmjs/tendermint-rpc");
83
+ var signing_1 = require("cosmjs-types/cosmos/tx/signing/v1beta1/signing");
84
+ var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
85
+ var accounts_1 = require("./accounts");
86
+ var stargateclient_1 = require("./stargateclient");
87
+ var axios_1 = __importDefault(require("axios"));
88
+ var math_1 = require("@cosmjs/math");
89
+ var any_1 = require("../google/protobuf/any");
90
+ var long_1 = __importDefault(require("long"));
91
+ var encoding_3 = require("../amino/encoding");
92
+ var SigningStargateClient = /** @class */ (function (_super) {
93
+ __extends(SigningStargateClient, _super);
94
+ function SigningStargateClient(tmClient, signer, registry) {
95
+ var _this = _super.call(this, tmClient) || this;
96
+ _this.registry = registry;
97
+ _this.signer = signer;
98
+ return _this;
99
+ }
100
+ SigningStargateClient.connectWithSigner = function (endpoint, signer, registry) {
101
+ return __awaiter(this, void 0, void 0, function () {
102
+ var tmClient;
103
+ return __generator(this, function (_a) {
104
+ switch (_a.label) {
105
+ case 0:
106
+ this._endpoint = endpoint;
107
+ return [4 /*yield*/, tendermint_rpc_1.Tendermint34Client.connect(endpoint)];
108
+ case 1:
109
+ tmClient = _a.sent();
110
+ return [2 /*return*/, new SigningStargateClient(tmClient, signer, registry)];
111
+ }
112
+ });
113
+ });
114
+ };
115
+ SigningStargateClient.prototype.signAndBroadcast = function (signerAddress, messages, fee, memo) {
116
+ if (memo === void 0) { memo = ""; }
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ var txRaw, txBytes;
119
+ return __generator(this, function (_a) {
120
+ switch (_a.label) {
121
+ case 0: return [4 /*yield*/, this.sign(signerAddress, messages, fee, memo)];
122
+ case 1:
123
+ txRaw = _a.sent();
124
+ txBytes = tx_1.TxRaw.encode(txRaw).finish();
125
+ return [2 /*return*/, this.broadcastTx(txBytes)];
126
+ }
127
+ });
128
+ });
129
+ };
130
+ SigningStargateClient.prototype.sign = function (signerAddress, messages, fee, memo, explicitSignerData) {
131
+ return __awaiter(this, void 0, void 0, function () {
132
+ var signerData, _a, accountNumber, sequence, chainId;
133
+ return __generator(this, function (_b) {
134
+ switch (_b.label) {
135
+ case 0:
136
+ if (!explicitSignerData) return [3 /*break*/, 1];
137
+ signerData = explicitSignerData;
138
+ return [3 /*break*/, 4];
139
+ case 1: return [4 /*yield*/, this.getSequence(signerAddress)];
140
+ case 2:
141
+ _a = _b.sent(), accountNumber = _a.accountNumber, sequence = _a.sequence;
142
+ return [4 /*yield*/, this.getChainId()];
143
+ case 3:
144
+ chainId = _b.sent();
145
+ signerData = {
146
+ accountNumber: accountNumber,
147
+ sequence: sequence,
148
+ chainId: chainId,
149
+ };
150
+ _b.label = 4;
151
+ case 4: return [2 /*return*/, this.signDirect(signerAddress, messages, fee, memo, signerData)];
152
+ }
153
+ });
154
+ });
155
+ };
156
+ SigningStargateClient.prototype.getChainId = function () {
157
+ return __awaiter(this, void 0, void 0, function () {
158
+ var response, chainId;
159
+ return __generator(this, function (_a) {
160
+ switch (_a.label) {
161
+ case 0:
162
+ if (!!this.chainId) return [3 /*break*/, 2];
163
+ return [4 /*yield*/, this.forceGetTmClient().status()];
164
+ case 1:
165
+ response = _a.sent();
166
+ chainId = response.nodeInfo.network;
167
+ if (!chainId)
168
+ throw new Error("Chain ID must not be empty");
169
+ this.chainId = chainId;
170
+ _a.label = 2;
171
+ case 2: return [2 /*return*/, this.chainId];
172
+ }
173
+ });
174
+ });
175
+ };
176
+ /**
177
+ * Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded.
178
+ * This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data.
179
+ * The result is typically 20 bytes long but not restricted to that.
180
+ */
181
+ SigningStargateClient.prototype.toAccAddress = function (address) {
182
+ return encoding_2.Bech32.decode(address).data;
183
+ };
184
+ SigningStargateClient.prototype.getAccount = function (address) {
185
+ return __awaiter(this, void 0, void 0, function () {
186
+ var accAddress, hexAccAddress, axios, path, result, finalData, account, finalAccount, error_1;
187
+ return __generator(this, function (_a) {
188
+ switch (_a.label) {
189
+ case 0:
190
+ _a.trys.push([0, 2, , 3]);
191
+ accAddress = this.toAccAddress(address);
192
+ hexAccAddress = "0x01" + Buffer.from(accAddress).toString("hex");
193
+ axios = axios_1.default.create({
194
+ baseURL: SigningStargateClient._endpoint,
195
+ headers: {
196
+ Accept: "application/json",
197
+ },
198
+ timeout: 15000
199
+ });
200
+ path = "/abci_query?path=\"/store/acc/key\"";
201
+ return [4 /*yield*/, axios.get(path, { params: { data: hexAccAddress } })];
202
+ case 1:
203
+ result = _a.sent();
204
+ finalData = result.data.result.response.value;
205
+ account = any_1.Any.decode(Buffer.from(finalData, "base64"));
206
+ finalAccount = accounts_1.accountFromAny(account);
207
+ return [2 /*return*/, finalAccount];
208
+ case 2:
209
+ error_1 = _a.sent();
210
+ return [2 /*return*/, undefined];
211
+ case 3: return [2 /*return*/];
212
+ }
213
+ });
214
+ });
215
+ };
216
+ SigningStargateClient.prototype.getSequence = function (address) {
217
+ return __awaiter(this, void 0, void 0, function () {
218
+ var account;
219
+ return __generator(this, function (_a) {
220
+ switch (_a.label) {
221
+ case 0: return [4 /*yield*/, this.getAccount(address)];
222
+ case 1:
223
+ account = _a.sent();
224
+ if (!account) {
225
+ throw new Error("Account does not exist on chain. Send some tokens there before trying to query sequence.");
226
+ }
227
+ return [2 /*return*/, {
228
+ accountNumber: account.accountNumber,
229
+ sequence: account.sequence,
230
+ }];
231
+ }
232
+ });
233
+ });
234
+ };
235
+ SigningStargateClient.prototype.makeSignerInfos = function (signers, signMode) {
236
+ return signers.map(function (_a) {
237
+ var pubkey = _a.pubkey, sequence = _a.sequence;
238
+ return ({
239
+ publicKey: pubkey,
240
+ modeInfo: {
241
+ single: { mode: signMode },
242
+ },
243
+ sequence: long_1.default.fromNumber(sequence),
244
+ });
245
+ });
246
+ };
247
+ SigningStargateClient.prototype.makeAuthInfoBytes = function (signers, feeAmount, gasLimit, granter, signMode) {
248
+ if (signMode === void 0) { signMode = signing_1.SignMode.SIGN_MODE_DIRECT; }
249
+ var authInfo = {
250
+ signerInfos: this.makeSignerInfos(signers, signMode),
251
+ fee: {
252
+ amount: __spreadArray([], __read(feeAmount)),
253
+ gasLimit: long_1.default.fromNumber(gasLimit),
254
+ granter: granter,
255
+ },
256
+ };
257
+ return tx_1.AuthInfo.encode(tx_1.AuthInfo.fromPartial(authInfo)).finish();
258
+ };
259
+ SigningStargateClient.prototype.signDirect = function (signerAddress, messages, fee, memo, _a) {
260
+ var accountNumber = _a.accountNumber, sequence = _a.sequence, chainId = _a.chainId;
261
+ return __awaiter(this, void 0, void 0, function () {
262
+ var accountFromSigner, pubkey, txBodyEncodeObject, txBodyBytes, gasLimit, authInfoBytes, signDoc, _b, signature, signed;
263
+ return __generator(this, function (_c) {
264
+ switch (_c.label) {
265
+ case 0: return [4 /*yield*/, this.signer.getAccounts()];
266
+ case 1:
267
+ accountFromSigner = (_c.sent()).find(function (account) { return account.address === signerAddress; });
268
+ if (!accountFromSigner) {
269
+ throw new Error("Failed to retrieve account from signer");
270
+ }
271
+ pubkey = proto_signing_1.encodePubkey(encoding_3.encodeSecp256k1Pubkey(accountFromSigner.pubkey));
272
+ txBodyEncodeObject = {
273
+ typeUrl: "/cosmos.tx.v1beta1.TxBody",
274
+ value: {
275
+ messages: messages,
276
+ memo: memo,
277
+ },
278
+ };
279
+ txBodyBytes = this.registry.encode(txBodyEncodeObject);
280
+ gasLimit = math_1.Int53.fromString(fee.gas).toNumber();
281
+ authInfoBytes = this.makeAuthInfoBytes([{ pubkey: pubkey, sequence: sequence }], fee.amount, gasLimit, fee.granter);
282
+ signDoc = proto_signing_1.makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
283
+ return [4 /*yield*/, this.signer.signDirect(signerAddress, signDoc)];
284
+ case 2:
285
+ _b = _c.sent(), signature = _b.signature, signed = _b.signed;
286
+ return [2 /*return*/, tx_1.TxRaw.fromPartial({
287
+ bodyBytes: signed.bodyBytes,
288
+ authInfoBytes: signed.authInfoBytes,
289
+ signatures: [encoding_1.fromBase64(signature.signature)],
290
+ })];
291
+ }
292
+ });
293
+ });
294
+ };
295
+ SigningStargateClient._endpoint = "";
296
+ return SigningStargateClient;
297
+ }(stargateclient_1.StargateClient));
298
+ exports.SigningStargateClient = SigningStargateClient;
@@ -0,0 +1,46 @@
1
+ import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
2
+ import { MsgData } from "cosmjs-types/cosmos/base/abci/v1beta1/abci";
3
+ export declare class TimeoutError extends Error {
4
+ readonly txId: string;
5
+ constructor(message: string, txId: string);
6
+ }
7
+ /** A transaction that is indexed as part of the transaction history */
8
+ export interface IndexedTx {
9
+ readonly height: number;
10
+ readonly hash: string;
11
+ readonly code: number;
12
+ readonly rawLog: string;
13
+ readonly tx: Uint8Array;
14
+ readonly gasUsed: number;
15
+ readonly gasWanted: number;
16
+ }
17
+ export interface BroadcastTxFailure {
18
+ readonly height: number;
19
+ readonly code: number;
20
+ readonly transactionHash: string;
21
+ readonly rawLog?: string;
22
+ readonly data?: readonly MsgData[];
23
+ }
24
+ export interface BroadcastTxSuccess {
25
+ readonly height: number;
26
+ readonly code: number;
27
+ readonly transactionHash: string;
28
+ readonly rawLog?: string;
29
+ readonly data?: readonly MsgData[];
30
+ readonly gasUsed: number;
31
+ readonly gasWanted: number;
32
+ }
33
+ export declare type BroadcastTxResponse = BroadcastTxSuccess | BroadcastTxFailure;
34
+ export declare function isBroadcastTxFailure(result: BroadcastTxResponse): boolean;
35
+ export declare function isBroadcastTxSuccess(result: BroadcastTxResponse): boolean;
36
+ export declare class StargateClient {
37
+ private readonly tmClient;
38
+ static connect(endpoint: string): Promise<StargateClient>;
39
+ protected constructor(tmClient: Tendermint34Client | undefined);
40
+ protected getTmClient(): Tendermint34Client | undefined;
41
+ protected forceGetTmClient(): Tendermint34Client;
42
+ getTx(id: string): Promise<IndexedTx | null>;
43
+ disconnect(): void;
44
+ broadcastTx(tx: Uint8Array, timeoutMs?: number, pollIntervalMs?: number): Promise<BroadcastTxResponse>;
45
+ private txsQuery;
46
+ }