@gnolang/tm2-js-client 2.0.2 → 2.0.3
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.
- package/dist/index.cjs +1 -0
- package/dist/index.mjs +1 -0
- package/dist/proto/google/protobuf/any.cjs +0 -1
- package/dist/proto/google/protobuf/any.cjs.map +1 -1
- package/dist/proto/google/protobuf/any.d.cts +1 -0
- package/dist/proto/google/protobuf/any.d.cts.map +1 -1
- package/dist/proto/google/protobuf/any.d.mts +1 -0
- package/dist/proto/google/protobuf/any.d.mts.map +1 -1
- package/dist/proto/google/protobuf/any.mjs +0 -1
- package/dist/proto/google/protobuf/any.mjs.map +1 -1
- package/dist/proto/tm2/abci.cjs +0 -1
- package/dist/proto/tm2/abci.cjs.map +1 -1
- package/dist/proto/tm2/abci.d.cts +1 -0
- package/dist/proto/tm2/abci.d.cts.map +1 -1
- package/dist/proto/tm2/abci.d.mts +1 -0
- package/dist/proto/tm2/abci.d.mts.map +1 -1
- package/dist/proto/tm2/abci.mjs +0 -1
- package/dist/proto/tm2/abci.mjs.map +1 -1
- package/dist/proto/tm2/multisig.d.cts +13 -0
- package/dist/proto/tm2/multisig.d.cts.map +1 -1
- package/dist/proto/tm2/multisig.d.mts +13 -0
- package/dist/proto/tm2/multisig.d.mts.map +1 -1
- package/dist/proto/tm2/tx.cjs.map +1 -1
- package/dist/proto/tm2/tx.mjs.map +1 -1
- package/dist/provider/errors/index.cjs +1 -0
- package/dist/provider/errors/index.d.cts +1 -0
- package/dist/provider/errors/index.d.mts +1 -0
- package/dist/provider/errors/index.mjs +2 -0
- package/dist/provider/index.cjs +2 -0
- package/dist/provider/index.mjs +2 -0
- package/dist/provider/provider.cjs +37 -18
- package/dist/provider/provider.cjs.map +1 -1
- package/dist/provider/provider.d.cts.map +1 -1
- package/dist/provider/provider.d.mts.map +1 -1
- package/dist/provider/provider.mjs +1 -0
- package/dist/provider/provider.mjs.map +1 -1
- package/dist/provider/types/common.cjs +0 -0
- package/dist/provider/types/common.mjs +1 -0
- package/dist/provider/types/index.cjs +3 -0
- package/dist/provider/types/index.d.cts +3 -0
- package/dist/provider/types/index.d.mts +3 -0
- package/dist/provider/types/index.mjs +4 -0
- package/dist/provider/types/jsonrpc.cjs +0 -0
- package/dist/provider/types/jsonrpc.mjs +1 -0
- package/dist/provider/utility/errors.utility.cjs +1 -0
- package/dist/provider/utility/errors.utility.cjs.map +1 -1
- package/dist/provider/utility/errors.utility.mjs +1 -0
- package/dist/provider/utility/errors.utility.mjs.map +1 -1
- package/dist/provider/utility/provider.utility.cjs +3 -1
- package/dist/provider/utility/provider.utility.cjs.map +1 -1
- package/dist/provider/utility/provider.utility.d.cts.map +1 -1
- package/dist/provider/utility/provider.utility.d.mts.map +1 -1
- package/dist/provider/utility/provider.utility.mjs +1 -0
- package/dist/provider/utility/provider.utility.mjs.map +1 -1
- package/dist/provider/utility/requests.utility.d.cts.map +1 -1
- package/dist/provider/utility/requests.utility.d.mts.map +1 -1
- package/dist/services/index.cjs +1 -0
- package/dist/services/index.mjs +1 -0
- package/dist/services/rest/restService.types.cjs +0 -0
- package/dist/services/rest/restService.types.mjs +1 -0
- package/dist/utility/index.cjs +1 -0
- package/dist/utility/index.mjs +2 -0
- package/dist/wallet/index.cjs +2 -0
- package/dist/wallet/index.mjs +2 -0
- package/dist/wallet/key/index.d.cts +1 -0
- package/dist/wallet/key/index.d.mts +1 -0
- package/dist/wallet/ledger/ledger.cjs +2 -1
- package/dist/wallet/ledger/ledger.cjs.map +1 -1
- package/dist/wallet/signer.cjs +0 -0
- package/dist/wallet/signer.mjs +1 -0
- package/dist/wallet/types/index.cjs +2 -0
- package/dist/wallet/types/index.d.cts +2 -0
- package/dist/wallet/types/index.d.mts +2 -0
- package/dist/wallet/types/index.mjs +3 -0
- package/dist/wallet/types/wallet.cjs +0 -0
- package/dist/wallet/types/wallet.mjs +1 -0
- package/dist/wallet/wallet.cjs +4 -2
- package/dist/wallet/wallet.cjs.map +1 -1
- package/dist/wallet/wallet.d.cts.map +1 -1
- package/dist/wallet/wallet.d.mts.map +1 -1
- package/dist/wallet/wallet.mjs +1 -0
- package/dist/wallet/wallet.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.utility.cjs","names":["parseABCI","constructRequestError","ABCIErrorKey","parseProto","ResponseDeliverTx","base64ToUint8Array","uint8ArrayToBase64","Tx"],"sources":["../../../src/provider/utility/provider.utility.ts"],"sourcesContent":["import {\n sha256,\n} from \"@cosmjs/crypto\";\n\nimport {\n Tx,\n} from \"../../proto/index.js\";\nimport {\n ResponseDeliverTx,\n} from \"../../proto/tm2/abci.js\";\nimport {\n Provider,\n} from \"../provider.js\";\nimport {\n ABCIAccount, ABCIErrorKey, ABCIResponse, BlockInfo,\n} from \"../types/index.js\";\nimport {\n constructRequestError,\n} from \"./errors.utility.js\";\nimport {\n base64ToUint8Array,\n parseABCI,\n parseProto,\n uint8ArrayToBase64,\n} from \"./requests.utility.js\";\n\n/**\n * Extracts the specific balance denomination from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n * @param {string} denomination the required denomination\n */\nexport const extractBalanceFromResponse = (\n abciData: string | null,\n denomination: string,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n // Extract the balances\n const balancesRaw = Buffer.from(abciData, \"base64\")\n .toString()\n .replace(/\"/gi, \"\");\n\n // Find the correct balance denomination\n const balances: string[] = balancesRaw.split(\",\");\n if (balances.length < 1) {\n return 0;\n }\n\n // Find the correct denomination\n const pattern = new RegExp(`^(\\\\d+)${denomination}$`);\n for (const balance of balances) {\n const match = balance.match(pattern);\n if (match) {\n return parseInt(match[1], 10);\n }\n }\n\n return 0;\n};\n\n/**\n * Extracts the account sequence from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractSequenceFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.sequence, 10);\n }\n catch (_e) {\n // unused case\n }\n\n // Account not initialized,\n // return default value (0)\n return 0;\n};\n\n/**\n * Extracts the account number from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountNumberFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.account_number, 10);\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the account from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountFromResponse = (\n abciData: string | null,\n): ABCIAccount => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return account;\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the simulate transaction response from the ABCI response value\n * @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message\n */\nexport const extractSimulateFromResponse = (\n abciResponse: ABCIResponse | null,\n): ResponseDeliverTx => {\n // Make sure the response is initialized\n if (!abciResponse) {\n throw new Error(\"abci data is not initialized\");\n }\n\n const error = abciResponse.response?.ResponseBase?.Error;\n if (error && error[ABCIErrorKey]) {\n throw constructRequestError(error[ABCIErrorKey]);\n }\n\n const value = abciResponse.response.Value;\n if (!value) {\n throw new Error(\"abci data is not initialized\");\n }\n\n try {\n return parseProto(value, ResponseDeliverTx.decode);\n }\n catch (e) {\n throw new Error(\"unable to parse simulate response\", {\n cause: e,\n });\n }\n};\n\n/**\n * Waits for the transaction to be committed to a block in the chain\n * of the specified provider. This helper does a search for incoming blocks\n * and checks if a transaction\n * @param {Provider} provider the provider instance\n * @param {string} hash the base64-encoded hash of the transaction\n * @param {number} [fromHeight=latest] the starting height for the search. If omitted, it is the latest block in the chain\n * @param {number} [timeout=15000] the timeout in MS for the search\n */\nexport const waitForTransaction = async (\n provider: Provider,\n hash: string,\n fromHeight?: number,\n timeout?: number,\n): Promise<Tx> => {\n // Fetch the starting point\n let currentHeight = fromHeight\n ? fromHeight\n : await provider.getBlockNumber();\n\n return new Promise((resolve, reject) => {\n const exitTimeout = timeout ? timeout : 15000;\n\n const fetchInterval = setInterval(async () => {\n // Fetch the latest block height\n const latestHeight = await provider.getBlockNumber();\n\n if (latestHeight < currentHeight) {\n // No need to parse older blocks\n return;\n }\n\n for (let blockNum = currentHeight; blockNum <= latestHeight; blockNum++) {\n // Fetch the block from the chain\n const block: BlockInfo = await provider.getBlock(blockNum);\n\n // Check if there are any transactions at all in the block\n if (!block.block.data.txs || block.block.data.txs.length == 0) {\n continue;\n }\n\n // Find the transaction among the block transactions\n for (const tx of block.block.data.txs) {\n // Decode the base-64 transaction\n const txRaw = base64ToUint8Array(tx);\n\n // Calculate the transaction hash\n const txHash = sha256(txRaw);\n\n if (uint8ArrayToBase64(txHash) == hash) {\n // Clear the interval\n clearInterval(fetchInterval);\n\n // Decode the transaction from amino\n resolve(Tx.decode(txRaw));\n }\n }\n }\n\n currentHeight = latestHeight + 1;\n }, 1000);\n\n setTimeout(() => {\n // Clear the fetch interval\n clearInterval(fetchInterval);\n\n reject(\"transaction fetch timeout\");\n }, exitTimeout);\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.utility.cjs","names":["parseABCI","constructRequestError","ABCIErrorKey","parseProto","ResponseDeliverTx","base64ToUint8Array","uint8ArrayToBase64","Tx"],"sources":["../../../src/provider/utility/provider.utility.ts"],"sourcesContent":["import {\n sha256,\n} from \"@cosmjs/crypto\";\n\nimport {\n Tx,\n} from \"../../proto/index.js\";\nimport {\n ResponseDeliverTx,\n} from \"../../proto/tm2/abci.js\";\nimport {\n Provider,\n} from \"../provider.js\";\nimport {\n ABCIAccount, ABCIErrorKey, ABCIResponse, BlockInfo,\n} from \"../types/index.js\";\nimport {\n constructRequestError,\n} from \"./errors.utility.js\";\nimport {\n base64ToUint8Array,\n parseABCI,\n parseProto,\n uint8ArrayToBase64,\n} from \"./requests.utility.js\";\n\n/**\n * Extracts the specific balance denomination from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n * @param {string} denomination the required denomination\n */\nexport const extractBalanceFromResponse = (\n abciData: string | null,\n denomination: string,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n // Extract the balances\n const balancesRaw = Buffer.from(abciData, \"base64\")\n .toString()\n .replace(/\"/gi, \"\");\n\n // Find the correct balance denomination\n const balances: string[] = balancesRaw.split(\",\");\n if (balances.length < 1) {\n return 0;\n }\n\n // Find the correct denomination\n const pattern = new RegExp(`^(\\\\d+)${denomination}$`);\n for (const balance of balances) {\n const match = balance.match(pattern);\n if (match) {\n return parseInt(match[1], 10);\n }\n }\n\n return 0;\n};\n\n/**\n * Extracts the account sequence from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractSequenceFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.sequence, 10);\n }\n catch (_e) {\n // unused case\n }\n\n // Account not initialized,\n // return default value (0)\n return 0;\n};\n\n/**\n * Extracts the account number from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountNumberFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.account_number, 10);\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the account from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountFromResponse = (\n abciData: string | null,\n): ABCIAccount => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return account;\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the simulate transaction response from the ABCI response value\n * @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message\n */\nexport const extractSimulateFromResponse = (\n abciResponse: ABCIResponse | null,\n): ResponseDeliverTx => {\n // Make sure the response is initialized\n if (!abciResponse) {\n throw new Error(\"abci data is not initialized\");\n }\n\n const error = abciResponse.response?.ResponseBase?.Error;\n if (error && error[ABCIErrorKey]) {\n throw constructRequestError(error[ABCIErrorKey]);\n }\n\n const value = abciResponse.response.Value;\n if (!value) {\n throw new Error(\"abci data is not initialized\");\n }\n\n try {\n return parseProto(value, ResponseDeliverTx.decode);\n }\n catch (e) {\n throw new Error(\"unable to parse simulate response\", {\n cause: e,\n });\n }\n};\n\n/**\n * Waits for the transaction to be committed to a block in the chain\n * of the specified provider. This helper does a search for incoming blocks\n * and checks if a transaction\n * @param {Provider} provider the provider instance\n * @param {string} hash the base64-encoded hash of the transaction\n * @param {number} [fromHeight=latest] the starting height for the search. If omitted, it is the latest block in the chain\n * @param {number} [timeout=15000] the timeout in MS for the search\n */\nexport const waitForTransaction = async (\n provider: Provider,\n hash: string,\n fromHeight?: number,\n timeout?: number,\n): Promise<Tx> => {\n // Fetch the starting point\n let currentHeight = fromHeight\n ? fromHeight\n : await provider.getBlockNumber();\n\n return new Promise((resolve, reject) => {\n const exitTimeout = timeout ? timeout : 15000;\n\n const fetchInterval = setInterval(async () => {\n // Fetch the latest block height\n const latestHeight = await provider.getBlockNumber();\n\n if (latestHeight < currentHeight) {\n // No need to parse older blocks\n return;\n }\n\n for (let blockNum = currentHeight; blockNum <= latestHeight; blockNum++) {\n // Fetch the block from the chain\n const block: BlockInfo = await provider.getBlock(blockNum);\n\n // Check if there are any transactions at all in the block\n if (!block.block.data.txs || block.block.data.txs.length == 0) {\n continue;\n }\n\n // Find the transaction among the block transactions\n for (const tx of block.block.data.txs) {\n // Decode the base-64 transaction\n const txRaw = base64ToUint8Array(tx);\n\n // Calculate the transaction hash\n const txHash = sha256(txRaw);\n\n if (uint8ArrayToBase64(txHash) == hash) {\n // Clear the interval\n clearInterval(fetchInterval);\n\n // Decode the transaction from amino\n resolve(Tx.decode(txRaw));\n }\n }\n }\n\n currentHeight = latestHeight + 1;\n }, 1000);\n\n setTimeout(() => {\n // Clear the fetch interval\n clearInterval(fetchInterval);\n\n reject(\"transaction fetch timeout\");\n }, exitTimeout);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;AA+BA,MAAa,8BACX,UACA,iBACW;AAEX,KAAI,CAAC,SACH,QAAO;CAST,MAAM,WALc,OAAO,KAAK,UAAU,SAAS,CAChD,UAAU,CACV,QAAQ,OAAO,GAAG,CAGkB,MAAM,IAAI;AACjD,KAAI,SAAS,SAAS,EACpB,QAAO;CAIT,MAAM,UAAU,IAAI,OAAO,UAAU,aAAa,GAAG;AACrD,MAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,QAAQ,QAAQ,MAAM,QAAQ;AACpC,MAAI,MACF,QAAO,SAAS,MAAM,IAAI,GAAG;;AAIjC,QAAO;;;;;;AAOT,MAAa,+BACX,aACW;AAEX,KAAI,CAAC,SACH,QAAO;AAGT,KAAI;EAEF,MAAM,UAAuBA,yBAAAA,UAAuB,SAAS;AAE7D,SAAO,SAAS,QAAQ,YAAY,UAAU,GAAG;UAE5C,IAAI;AAMX,QAAO;;;;;;AAOT,MAAa,oCACX,aACW;AAEX,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,6BAA6B;AAG/C,KAAI;EAEF,MAAM,UAAuBA,yB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M,KAAK,KAAK;KAErC,MAAM,QAAQC,yBAAAA,mBAAmB,GAAG;KAGpC,MAAM,UAAA,GAAA,eAAA,QAAgB,MAAM;AAE5B,SAAIC,yBAAAA,mBAAmB,OAAO,IAAI,MAAM;AAEtC,oBAAc,cAAc;AAG5B,cAAQC,WAAAA,GAAG,OAAO,MAAM,CAAC;;;;AAK/B,mBAAgB,eAAe;KAC9B,IAAK;AAER,mBAAiB;AAEf,iBAAc,cAAc;AAE5B,UAAO,4BAA4B;KAClC,YAAY;GACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.utility.d.cts","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.utility.d.cts","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"mappings":";;;;;;;;;;AA+BA;cAAa,0BAAA,GACX,QAAA,iBACA,YAAA;;;;AAkCF;cAAa,2BAAA,GACX,QAAA;;;;AA0BF;cAAa,gCAAA,GACX,QAAA;;;;AAwBF;cAAa,0BAAA,GACX,QAAA,oBACC,WAAA;;;;AAuBH;cAAa,2BAAA,GACX,YAAA,EAAc,YAAA,YACb,iBAAA;;;;;;;;AAmCH;;cAAa,kBAAA,GACX,QAAA,EAAU,QAAA,EACV,IAAA,UACA,UAAA,WACA,OAAA,cACC,OAAA,CAAQ,EAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.utility.d.mts","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.utility.d.mts","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"mappings":";;;;;;;;;;AA+BA;cAAa,0BAAA,GACX,QAAA,iBACA,YAAA;;;;AAkCF;cAAa,2BAAA,GACX,QAAA;;;;AA0BF;cAAa,gCAAA,GACX,QAAA;;;;AAwBF;cAAa,0BAAA,GACX,QAAA,oBACC,WAAA;;;;AAuBH;cAAa,2BAAA,GACX,YAAA,EAAc,YAAA,YACb,iBAAA;;;;;;;;AAmCH;;cAAa,kBAAA,GACX,QAAA,EAAU,QAAA,EACV,IAAA,UACA,UAAA,WACA,OAAA,cACC,OAAA,CAAQ,EAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Tx } from "../../proto/tm2/tx.mjs";
|
|
2
2
|
import "../../proto/index.mjs";
|
|
3
3
|
import { ABCIErrorKey } from "../types/abci.mjs";
|
|
4
|
+
import "../types/index.mjs";
|
|
4
5
|
import { constructRequestError } from "./errors.utility.mjs";
|
|
5
6
|
import { ResponseDeliverTx } from "../../proto/tm2/abci.mjs";
|
|
6
7
|
import { base64ToUint8Array, parseABCI, parseProto, uint8ArrayToBase64 } from "./requests.utility.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.utility.mjs","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"sourcesContent":["import {\n sha256,\n} from \"@cosmjs/crypto\";\n\nimport {\n Tx,\n} from \"../../proto/index.js\";\nimport {\n ResponseDeliverTx,\n} from \"../../proto/tm2/abci.js\";\nimport {\n Provider,\n} from \"../provider.js\";\nimport {\n ABCIAccount, ABCIErrorKey, ABCIResponse, BlockInfo,\n} from \"../types/index.js\";\nimport {\n constructRequestError,\n} from \"./errors.utility.js\";\nimport {\n base64ToUint8Array,\n parseABCI,\n parseProto,\n uint8ArrayToBase64,\n} from \"./requests.utility.js\";\n\n/**\n * Extracts the specific balance denomination from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n * @param {string} denomination the required denomination\n */\nexport const extractBalanceFromResponse = (\n abciData: string | null,\n denomination: string,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n // Extract the balances\n const balancesRaw = Buffer.from(abciData, \"base64\")\n .toString()\n .replace(/\"/gi, \"\");\n\n // Find the correct balance denomination\n const balances: string[] = balancesRaw.split(\",\");\n if (balances.length < 1) {\n return 0;\n }\n\n // Find the correct denomination\n const pattern = new RegExp(`^(\\\\d+)${denomination}$`);\n for (const balance of balances) {\n const match = balance.match(pattern);\n if (match) {\n return parseInt(match[1], 10);\n }\n }\n\n return 0;\n};\n\n/**\n * Extracts the account sequence from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractSequenceFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.sequence, 10);\n }\n catch (_e) {\n // unused case\n }\n\n // Account not initialized,\n // return default value (0)\n return 0;\n};\n\n/**\n * Extracts the account number from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountNumberFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.account_number, 10);\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the account from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountFromResponse = (\n abciData: string | null,\n): ABCIAccount => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return account;\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the simulate transaction response from the ABCI response value\n * @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message\n */\nexport const extractSimulateFromResponse = (\n abciResponse: ABCIResponse | null,\n): ResponseDeliverTx => {\n // Make sure the response is initialized\n if (!abciResponse) {\n throw new Error(\"abci data is not initialized\");\n }\n\n const error = abciResponse.response?.ResponseBase?.Error;\n if (error && error[ABCIErrorKey]) {\n throw constructRequestError(error[ABCIErrorKey]);\n }\n\n const value = abciResponse.response.Value;\n if (!value) {\n throw new Error(\"abci data is not initialized\");\n }\n\n try {\n return parseProto(value, ResponseDeliverTx.decode);\n }\n catch (e) {\n throw new Error(\"unable to parse simulate response\", {\n cause: e,\n });\n }\n};\n\n/**\n * Waits for the transaction to be committed to a block in the chain\n * of the specified provider. This helper does a search for incoming blocks\n * and checks if a transaction\n * @param {Provider} provider the provider instance\n * @param {string} hash the base64-encoded hash of the transaction\n * @param {number} [fromHeight=latest] the starting height for the search. If omitted, it is the latest block in the chain\n * @param {number} [timeout=15000] the timeout in MS for the search\n */\nexport const waitForTransaction = async (\n provider: Provider,\n hash: string,\n fromHeight?: number,\n timeout?: number,\n): Promise<Tx> => {\n // Fetch the starting point\n let currentHeight = fromHeight\n ? fromHeight\n : await provider.getBlockNumber();\n\n return new Promise((resolve, reject) => {\n const exitTimeout = timeout ? timeout : 15000;\n\n const fetchInterval = setInterval(async () => {\n // Fetch the latest block height\n const latestHeight = await provider.getBlockNumber();\n\n if (latestHeight < currentHeight) {\n // No need to parse older blocks\n return;\n }\n\n for (let blockNum = currentHeight; blockNum <= latestHeight; blockNum++) {\n // Fetch the block from the chain\n const block: BlockInfo = await provider.getBlock(blockNum);\n\n // Check if there are any transactions at all in the block\n if (!block.block.data.txs || block.block.data.txs.length == 0) {\n continue;\n }\n\n // Find the transaction among the block transactions\n for (const tx of block.block.data.txs) {\n // Decode the base-64 transaction\n const txRaw = base64ToUint8Array(tx);\n\n // Calculate the transaction hash\n const txHash = sha256(txRaw);\n\n if (uint8ArrayToBase64(txHash) == hash) {\n // Clear the interval\n clearInterval(fetchInterval);\n\n // Decode the transaction from amino\n resolve(Tx.decode(txRaw));\n }\n }\n }\n\n currentHeight = latestHeight + 1;\n }, 1000);\n\n setTimeout(() => {\n // Clear the fetch interval\n clearInterval(fetchInterval);\n\n reject(\"transaction fetch timeout\");\n }, exitTimeout);\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.utility.mjs","names":[],"sources":["../../../src/provider/utility/provider.utility.ts"],"sourcesContent":["import {\n sha256,\n} from \"@cosmjs/crypto\";\n\nimport {\n Tx,\n} from \"../../proto/index.js\";\nimport {\n ResponseDeliverTx,\n} from \"../../proto/tm2/abci.js\";\nimport {\n Provider,\n} from \"../provider.js\";\nimport {\n ABCIAccount, ABCIErrorKey, ABCIResponse, BlockInfo,\n} from \"../types/index.js\";\nimport {\n constructRequestError,\n} from \"./errors.utility.js\";\nimport {\n base64ToUint8Array,\n parseABCI,\n parseProto,\n uint8ArrayToBase64,\n} from \"./requests.utility.js\";\n\n/**\n * Extracts the specific balance denomination from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n * @param {string} denomination the required denomination\n */\nexport const extractBalanceFromResponse = (\n abciData: string | null,\n denomination: string,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n // Extract the balances\n const balancesRaw = Buffer.from(abciData, \"base64\")\n .toString()\n .replace(/\"/gi, \"\");\n\n // Find the correct balance denomination\n const balances: string[] = balancesRaw.split(\",\");\n if (balances.length < 1) {\n return 0;\n }\n\n // Find the correct denomination\n const pattern = new RegExp(`^(\\\\d+)${denomination}$`);\n for (const balance of balances) {\n const match = balance.match(pattern);\n if (match) {\n return parseInt(match[1], 10);\n }\n }\n\n return 0;\n};\n\n/**\n * Extracts the account sequence from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractSequenceFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n return 0;\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.sequence, 10);\n }\n catch (_e) {\n // unused case\n }\n\n // Account not initialized,\n // return default value (0)\n return 0;\n};\n\n/**\n * Extracts the account number from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountNumberFromResponse = (\n abciData: string | null,\n): number => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return parseInt(account.BaseAccount.account_number, 10);\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the account from the ABCI response\n * @param {string | null} abciData the base64-encoded ABCI data\n */\nexport const extractAccountFromResponse = (\n abciData: string | null,\n): ABCIAccount => {\n // Make sure the response is initialized\n if (!abciData) {\n throw new Error(\"account is not initialized\");\n }\n\n try {\n // Parse the account\n const account: ABCIAccount = parseABCI<ABCIAccount>(abciData);\n\n return account;\n }\n catch (e) {\n throw new Error(\"account is not initialized\", {\n cause: e,\n });\n }\n};\n\n/**\n * Extracts the simulate transaction response from the ABCI response value\n * @param {string | null} abciData the base64-encoded ResponseDeliverTx proto message\n */\nexport const extractSimulateFromResponse = (\n abciResponse: ABCIResponse | null,\n): ResponseDeliverTx => {\n // Make sure the response is initialized\n if (!abciResponse) {\n throw new Error(\"abci data is not initialized\");\n }\n\n const error = abciResponse.response?.ResponseBase?.Error;\n if (error && error[ABCIErrorKey]) {\n throw constructRequestError(error[ABCIErrorKey]);\n }\n\n const value = abciResponse.response.Value;\n if (!value) {\n throw new Error(\"abci data is not initialized\");\n }\n\n try {\n return parseProto(value, ResponseDeliverTx.decode);\n }\n catch (e) {\n throw new Error(\"unable to parse simulate response\", {\n cause: e,\n });\n }\n};\n\n/**\n * Waits for the transaction to be committed to a block in the chain\n * of the specified provider. This helper does a search for incoming blocks\n * and checks if a transaction\n * @param {Provider} provider the provider instance\n * @param {string} hash the base64-encoded hash of the transaction\n * @param {number} [fromHeight=latest] the starting height for the search. If omitted, it is the latest block in the chain\n * @param {number} [timeout=15000] the timeout in MS for the search\n */\nexport const waitForTransaction = async (\n provider: Provider,\n hash: string,\n fromHeight?: number,\n timeout?: number,\n): Promise<Tx> => {\n // Fetch the starting point\n let currentHeight = fromHeight\n ? fromHeight\n : await provider.getBlockNumber();\n\n return new Promise((resolve, reject) => {\n const exitTimeout = timeout ? timeout : 15000;\n\n const fetchInterval = setInterval(async () => {\n // Fetch the latest block height\n const latestHeight = await provider.getBlockNumber();\n\n if (latestHeight < currentHeight) {\n // No need to parse older blocks\n return;\n }\n\n for (let blockNum = currentHeight; blockNum <= latestHeight; blockNum++) {\n // Fetch the block from the chain\n const block: BlockInfo = await provider.getBlock(blockNum);\n\n // Check if there are any transactions at all in the block\n if (!block.block.data.txs || block.block.data.txs.length == 0) {\n continue;\n }\n\n // Find the transaction among the block transactions\n for (const tx of block.block.data.txs) {\n // Decode the base-64 transaction\n const txRaw = base64ToUint8Array(tx);\n\n // Calculate the transaction hash\n const txHash = sha256(txRaw);\n\n if (uint8ArrayToBase64(txHash) == hash) {\n // Clear the interval\n clearInterval(fetchInterval);\n\n // Decode the transaction from amino\n resolve(Tx.decode(txRaw));\n }\n }\n }\n\n currentHeight = latestHeight + 1;\n }, 1000);\n\n setTimeout(() => {\n // Clear the fetch interval\n clearInterval(fetchInterval);\n\n reject(\"transaction fetch timeout\");\n }, exitTimeout);\n });\n};\n"],"mappings":";;;;;;;;;;;;;;AA+BA,MAAa,8BACX,UACA,iBACW;AAEX,KAAI,CAAC,SACH,QAAO;CAST,MAAM,WALc,OAAO,KAAK,UAAU,SAAS,CAChD,UAAU,CACV,QAAQ,OAAO,GAAG,CAGkB,MAAM,IAAI;AACjD,KAAI,SAAS,SAAS,EACpB,QAAO;CAIT,MAAM,UAAU,IAAI,OAAO,UAAU,aAAa,GAAG;AACrD,MAAK,MAAM,WAAW,UAAU;EAC9B,MAAM,QAAQ,QAAQ,MAAM,QAAQ;AACpC,MAAI,MACF,QAAO,SAAS,MAAM,IAAI,GAAG;;AAIjC,QAAO;;;;;;AAOT,MAAa,+BACX,aACW;AAEX,KAAI,CAAC,SACH,QAAO;AAGT,KAAI;EAEF,MAAM,UAAuB,UAAuB,SAAS;AAE7D,S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SAAS;AAG1D,QAAI,CAAC,MAAM,MAAM,KAAK,OAAO,MAAM,MAAM,KAAK,IAAI,UAAU,EAC1D;AAIF,SAAK,MAAM,MAAM,MAAM,MAAM,KAAK,KAAK;KAErC,MAAM,QAAQ,mBAAmB,GAAG;AAKpC,SAAI,mBAFW,OAAO,MAAM,CAEE,IAAI,MAAM;AAEtC,oBAAc,cAAc;AAG5B,cAAQ,GAAG,OAAO,MAAM,CAAC;;;;AAK/B,mBAAgB,eAAe;KAC9B,IAAK;AAER,mBAAiB;AAEf,iBAAc,cAAc;AAE5B,UAAO,4BAA4B;KAClC,YAAY;GACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.utility.d.cts","names":[],"sources":["../../../src/provider/utility/requests.utility.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"requests.utility.d.cts","names":[],"sources":["../../../src/provider/utility/requests.utility.ts"],"mappings":";;;;;;;AAmBA;;cAAa,UAAA,GAAc,MAAA,UAAgB,MAAA,iBAAqB,UAAA;;;;;;cAgBnD,WAAA,WACX,MAAA,GAAS,MAAA,EACT,KAAA,GAAQ,QAAA,KACP,WAAA,CAAY,MAAA;AAHf;;;;AAAA,cAgBa,SAAA,WAAqB,IAAA,aAAe,MAAA;AAAA,cAWpC,UAAA,MACX,IAAA,UACA,QAAA,GAAW,KAAA,EAAO,YAAA,GAAe,UAAA,EAAY,MAAA,cAAoB,CAAA,KAAC,CAAA;;;;;cAWvD,cAAA,GAAkB,GAAA;;;;;cAUlB,kBAAA,GAAsB,GAAA,aAAc,UAAA;;;AAlCjD;;cA4Ca,kBAAA,GAAsB,IAAA,EAAM,UAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.utility.d.mts","names":[],"sources":["../../../src/provider/utility/requests.utility.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"requests.utility.d.mts","names":[],"sources":["../../../src/provider/utility/requests.utility.ts"],"mappings":";;;;;;;AAmBA;;cAAa,UAAA,GAAc,MAAA,UAAgB,MAAA,iBAAqB,UAAA;;;;;;cAgBnD,WAAA,WACX,MAAA,GAAS,MAAA,EACT,KAAA,GAAQ,QAAA,KACP,WAAA,CAAY,MAAA;AAHf;;;;AAAA,cAgBa,SAAA,WAAqB,IAAA,aAAe,MAAA;AAAA,cAWpC,UAAA,MACX,IAAA,UACA,QAAA,GAAW,KAAA,EAAO,YAAA,GAAe,UAAA,EAAY,MAAA,cAAoB,CAAA,KAAC,CAAA;;;;;cAWvD,cAAA,GAAkB,GAAA;;;;;cAUlB,kBAAA,GAAsB,GAAA,aAAc,UAAA;;;AAlCjD;;cA4Ca,kBAAA,GAAsB,IAAA,EAAM,UAAA"}
|
package/dist/services/index.cjs
CHANGED
package/dist/services/index.mjs
CHANGED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("./compact-bit-array.cjs");
|
package/dist/wallet/index.cjs
CHANGED
package/dist/wallet/index.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { KeySigner } from "./key.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { KeySigner } from "./key.mjs";
|
|
@@ -21,7 +21,8 @@ var LedgerSigner = class {
|
|
|
21
21
|
require_defineProperty._defineProperty(this, "addressPrefix", void 0);
|
|
22
22
|
require_defineProperty._defineProperty(this, "getAddress", async () => {
|
|
23
23
|
if (!this.connector) throw new Error("Ledger not connected");
|
|
24
|
-
|
|
24
|
+
const compressedPubKey = await this.connector.getPubkey(this.hdPath);
|
|
25
|
+
return (0, _cosmjs_amino.pubkeyToAddress)((0, _cosmjs_amino.encodeSecp256k1Pubkey)(compressedPubKey), this.addressPrefix);
|
|
25
26
|
});
|
|
26
27
|
require_defineProperty._defineProperty(this, "getPublicKey", async () => {
|
|
27
28
|
if (!this.connector) throw new Error("Ledger not connected");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger.cjs","names":["Secp256k1","Secp256k1Signature","generateHDPath"],"sources":["../../../src/wallet/ledger/ledger.ts"],"sourcesContent":["import {\n encodeSecp256k1Pubkey, pubkeyToAddress,\n} from \"@cosmjs/amino\";\nimport {\n HdPath, Secp256k1, Secp256k1Signature, sha256,\n} from \"@cosmjs/crypto\";\nimport {\n LedgerConnector,\n} from \"@cosmjs/ledger-amino\";\n\nimport {\n Signer,\n} from \"../signer.js\";\nimport {\n defaultAddressPrefix, generateHDPath,\n} from \"../utility/index.js\";\n\n/**\n * LedgerSigner implements the logic for the Ledger device signer\n */\nexport class LedgerSigner implements Signer {\n private readonly connector: LedgerConnector;\n private readonly hdPath: HdPath;\n private readonly addressPrefix: string;\n\n /**\n * Creates a new Ledger device signer instance\n * @param {LedgerConnector} connector the Ledger connector\n * @param {number} accountIndex the desired account index\n * @param {string} addressPrefix the address prefix\n */\n constructor(\n connector: LedgerConnector,\n accountIndex: number,\n addressPrefix: string = defaultAddressPrefix,\n ) {\n this.connector = connector;\n this.hdPath = generateHDPath(accountIndex);\n this.addressPrefix = addressPrefix;\n }\n\n getAddress = async (): Promise<string> => {\n if (!this.connector) {\n throw new Error(\"Ledger not connected\");\n }\n\n const compressedPubKey: Uint8Array = await this.connector.getPubkey(\n this.hdPath,\n );\n\n return pubkeyToAddress(\n encodeSecp256k1Pubkey(compressedPubKey),\n this.addressPrefix,\n );\n };\n\n getPublicKey = async (): Promise<Uint8Array> => {\n if (!this.connector) {\n throw new Error(\"Ledger not connected\");\n }\n\n return this.connector.getPubkey(this.hdPath);\n };\n\n getPrivateKey = async (): Promise<Uint8Array> => {\n throw new Error(\"Ledger does not support private key exports\");\n };\n\n signData = async (data: Uint8Array): Promise<Uint8Array> => {\n if (!this.connector) {\n throw new Error(\"Ledger not connected\");\n }\n\n return this.connector.sign(data, this.hdPath);\n };\n\n verifySignature = async (\n data: Uint8Array,\n signature: Uint8Array,\n ): Promise<boolean> => {\n const publicKey = await this.getPublicKey();\n\n return Secp256k1.verifySignature(\n Secp256k1Signature.fromFixedLength(signature),\n sha256(data),\n publicKey,\n );\n };\n}\n"],"mappings":";;;;;;;;;;AAoBA,IAAa,eAAb,MAA4C;;;;;;;CAW1C,YACE,WACA,cACA,gBAAA,KACA;+CAde,aAAA,KAAA,EAA2B;+CAC3B,UAAA,KAAA,EAAe;+CACf,iBAAA,KAAA,EAAsB;+CAkBvC,cAAa,YAA6B;AACxC,OAAI,CAAC,KAAK,UACR,OAAM,IAAI,MAAM,uBAAuB;
|
|
1
|
+
{"version":3,"file":"ledger.cjs","names":["Secp256k1","Secp256k1Signature","generateHDPath"],"sources":["../../../src/wallet/ledger/ledger.ts"],"sourcesContent":["import {\n encodeSecp256k1Pubkey, pubkeyToAddress,\n} from \"@cosmjs/amino\";\nimport {\n HdPath, Secp256k1, Secp256k1Signature, sha256,\n} from \"@cosmjs/crypto\";\nimport {\n LedgerConnector,\n} from \"@cosmjs/ledger-amino\";\n\nimport {\n Signer,\n} from \"../signer.js\";\nimport {\n defaultAddressPrefix, generateHDPath,\n} from \"../utility/index.js\";\n\n/**\n * LedgerSigner implements the logic for the Ledger device signer\n */\nexport class LedgerSigner implements Signer {\n private readonly connector: LedgerConnector;\n private readonly hdPath: HdPath;\n private readonly addressPrefix: string;\n\n /**\n * Creates a new Ledger device signer instance\n * @param {LedgerConnector} connector the Ledger connector\n * @param {number} accountIndex the desired account index\n * @param {string} addressPrefix the address prefix\n */\n constructor(\n connector: LedgerConnector,\n accountIndex: number,\n addressPrefix: string = defaultAddressPrefix,\n ) {\n this.connector = connector;\n this.hdPath = generateHDPath(accountIndex);\n this.addressPrefix = addressPrefix;\n }\n\n getAddress = async (): Promise<string> => {\n if (!this.connector) {\n throw new Error(\"Ledger not connected\");\n }\n\n const compressedPubKey: Uint8Array = await this.connector.getPubkey(\n this.hdPath,\n );\n\n return pubkeyToAddress(\n encodeSecp256k1Pubkey(compressedPubKey),\n this.addressPrefix,\n );\n };\n\n getPublicKey = async (): Promise<Uint8Array> => {\n if (!this.connector) {\n throw new Error(\"Ledger not connected\");\n }\n\n return this.connector.getPubkey(this.hdPath);\n };\n\n getPrivateKey = async (): Promise<Uint8Array> => {\n throw new Error(\"Ledger does not support private key exports\");\n };\n\n signData = async (data: Uint8Array): Promise<Uint8Array> => {\n if (!this.connector) {\n throw new Error(\"Ledger not connected\");\n }\n\n return this.connector.sign(data, this.hdPath);\n };\n\n verifySignature = async (\n data: Uint8Array,\n signature: Uint8Array,\n ): Promise<boolean> => {\n const publicKey = await this.getPublicKey();\n\n return Secp256k1.verifySignature(\n Secp256k1Signature.fromFixedLength(signature),\n sha256(data),\n publicKey,\n );\n };\n}\n"],"mappings":";;;;;;;;;;AAoBA,IAAa,eAAb,MAA4C;;;;;;;CAW1C,YACE,WACA,cACA,gBAAA,KACA;+CAde,aAAA,KAAA,EAA2B;+CAC3B,UAAA,KAAA,EAAe;+CACf,iBAAA,KAAA,EAAsB;+CAkBvC,cAAa,YAA6B;AACxC,OAAI,CAAC,KAAK,UACR,OAAM,IAAI,MAAM,uBAAuB;GAGzC,MAAM,mBAA+B,MAAM,KAAK,UAAU,UACxD,KAAK,OACN;AAED,WAAA,GAAA,cAAA,kBAAA,GAAA,cAAA,uBACwB,iBAAiB,EACvC,KAAK,cACN;IACD;+CAEF,gBAAe,YAAiC;AAC9C,OAAI,CAAC,KAAK,UACR,OAAM,IAAI,MAAM,uBAAuB;AAGzC,UAAO,KAAK,UAAU,UAAU,KAAK,OAAO;IAC5C;+CAEF,iBAAgB,YAAiC;AAC/C,SAAM,IAAI,MAAM,8CAA8C;IAC9D;+CAEF,YAAW,OAAO,SAA0C;AAC1D,OAAI,CAAC,KAAK,UACR,OAAM,IAAI,MAAM,uBAAuB;AAGzC,UAAO,KAAK,UAAU,KAAK,MAAM,KAAK,OAAO;IAC7C;+CAEF,mBAAkB,OAChB,MACA,cACqB;GACrB,MAAM,YAAY,MAAM,KAAK,cAAc;AAE3C,UAAOA,eAAAA,UAAU,gBACfC,eAAAA,mBAAmB,gBAAgB,UAAU,GAAA,GAAA,eAAA,QACtC,KAAK,EACZ,UACD;IACD;AAnDA,OAAK,YAAY;AACjB,OAAK,SAASC,gBAAAA,eAAe,aAAa;AAC1C,OAAK,gBAAgB"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/wallet/wallet.cjs
CHANGED
|
@@ -11,6 +11,7 @@ require("./key/index.cjs");
|
|
|
11
11
|
const require_ledger = require("./ledger/ledger.cjs");
|
|
12
12
|
require("./ledger/index.cjs");
|
|
13
13
|
const require_sign = require("./types/sign.cjs");
|
|
14
|
+
require("./types/index.cjs");
|
|
14
15
|
let _cosmjs_crypto = require("@cosmjs/crypto");
|
|
15
16
|
//#region src/wallet/wallet.ts
|
|
16
17
|
var _Wallet;
|
|
@@ -138,7 +139,7 @@ var Wallet = class {
|
|
|
138
139
|
if (accountSequence === void 0) accountSequence = account.BaseAccount.sequence;
|
|
139
140
|
}
|
|
140
141
|
const publicKey = await this.signer.getPublicKey();
|
|
141
|
-
const
|
|
142
|
+
const signPayload = {
|
|
142
143
|
chain_id: chainID,
|
|
143
144
|
account_number: accountNumber,
|
|
144
145
|
sequence: accountSequence,
|
|
@@ -148,7 +149,8 @@ var Wallet = class {
|
|
|
148
149
|
},
|
|
149
150
|
msgs: decodeTxMessages(tx.messages),
|
|
150
151
|
memo: tx.memo
|
|
151
|
-
}
|
|
152
|
+
};
|
|
153
|
+
const signBytes = require_utility.stringToUTF8(require_utility.encodeCharacterSet(require_utility.sortedJsonStringify(signPayload)));
|
|
152
154
|
const wrappedKey = { key: publicKey };
|
|
153
155
|
const txSignature = {
|
|
154
156
|
pub_key: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.cjs","names":["stringToUTF8","encodeCharacterSet","sortedJsonStringify","Secp256k1PubKeyType","PubKeySecp256k1","uint8ArrayToBase64","Tx","generateKeyPair","Bip39","generateEntropy","Wallet","KeySigner","Secp256k1","LedgerSigner"],"sources":["../../src/wallet/wallet.ts"],"sourcesContent":["import {\n Bip39, Secp256k1,\n} from \"@cosmjs/crypto\";\nimport {\n LedgerConnector,\n} from \"@cosmjs/ledger-amino\";\n\nimport {\n Any, PubKeySecp256k1, Tx, TxSignature,\n} from \"../proto/index.js\";\nimport {\n BroadcastTransactionMap,\n Provider,\n Status,\n uint8ArrayToBase64,\n} from \"../provider/index.js\";\nimport {\n KeySigner,\n} from \"./key/index.js\";\nimport {\n LedgerSigner,\n} from \"./ledger/index.js\";\nimport {\n Signer,\n} from \"./signer.js\";\nimport {\n AccountWalletOption,\n CreateWalletOptions,\n Secp256k1PubKeyType,\n TxSignPayload,\n} from \"./types/index.js\";\nimport {\n encodeCharacterSet,\n generateEntropy,\n generateKeyPair,\n stringToUTF8,\n} from \"./utility/index.js\";\nimport {\n sortedJsonStringify,\n} from \"./utility/index.js\";\nexport interface SignTransactionOptions {\n accountNumber?: string\n sequence?: string\n}\n\n/**\n * Wallet is a single account abstraction\n * that can interact with the blockchain\n */\nexport class Wallet {\n protected declare provider: Provider;\n protected declare signer: Signer;\n\n /**\n * Connects the wallet to the specified {@link Provider}\n * @param {Provider} provider the active {@link Provider}, if any\n */\n connect = (provider: Provider) => {\n this.provider = provider;\n };\n\n // Wallet initialization //\n\n /**\n * Generates a private key-based wallet, using a random seed\n * @param {AccountWalletOption} options the account options\n */\n static createRandom = async (\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n Bip39.encode(generateEntropy()).toString(),\n 0,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a custom signer-based wallet\n * @param {Signer} signer the custom signer implementing the Signer interface\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromSigner = async (signer: Signer): Promise<Wallet> => {\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = signer;\n\n return wallet;\n };\n\n /**\n * Generates a bip39 mnemonic-based wallet\n * @param {string} mnemonic the bip39 mnemonic\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromMnemonic = async (\n mnemonic: string,\n options?: CreateWalletOptions,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n mnemonic,\n options?.accountIndex,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a private key-based wallet\n * @param {string} privateKey the private key\n * @param {AccountWalletOption} options the account options\n */\n static fromPrivateKey = async (\n privateKey: Uint8Array,\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n // Derive the public key\n const {\n pubkey: publicKey,\n } = await Secp256k1.makeKeypair(privateKey);\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Creates a Ledger-based wallet\n * @param {LedgerConnector} connector the Ledger device connector\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromLedger = (\n connector: LedgerConnector,\n options?: CreateWalletOptions,\n ): Wallet => {\n const wallet: Wallet = new Wallet();\n\n wallet.signer = new LedgerSigner(\n connector,\n options?.accountIndex ?? 0,\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n // Account manipulation //\n\n /**\n * Fetches the address associated with the wallet\n */\n getAddress = (): Promise<string> => {\n return this.signer.getAddress();\n };\n\n /**\n * Fetches the account sequence for the wallet\n * @param {number} [height=latest] the block height\n */\n getAccountSequence = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountSequence(address, height);\n };\n\n /**\n * Fetches the account number for the wallet. Errors out if the\n * account is not initialized\n * @param {number} [height=latest] the block height\n */\n getAccountNumber = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountNumber(address, height);\n };\n\n /**\n * Fetches the account balance for the specific denomination\n * @param {string} [denomination=ugnot] the fund denomination\n */\n getBalance = async (denomination?: string): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getBalance(\n address,\n denomination ? denomination : \"ugnot\",\n );\n };\n\n /**\n * Fetches the current (recommended) average gas price\n */\n getGasPrice = async (): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.getGasPrice();\n };\n\n /**\n * Estimates the gas limit for the transaction\n * @param {Tx} tx the transaction that needs estimating\n */\n estimateGas = async (tx: Tx): Promise<bigint> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.estimateGas(tx);\n };\n\n /**\n * Returns the connected provider, if any\n */\n getProvider = (): Provider => {\n return this.provider;\n };\n\n /**\n * Generates a transaction signature, and appends it to the transaction\n * @param {Tx} tx the transaction to be signed\n * @param {(messages: Any[]) => any[]} decodeTxMessages tx message decode callback\n * that should expand the concrete message fields into an object. Required because\n * the transaction sign bytes are generated using sorted JSON, which requires\n * encoded message values to be decoded for sorting\n */\n signTransaction = async (\n tx: Tx,\n decodeTxMessages: (messages: Any[]) => unknown[],\n opts?: SignTransactionOptions,\n ): Promise<Tx> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Make sure the tx fee is initialized\n if (!tx.fee) {\n throw new Error(\"invalid transaction fee provided\");\n }\n\n // Extract the relevant chain data\n const status: Status = await this.provider.getStatus();\n const chainID: string = status.node_info.network;\n\n // Extract the relevant account data\n let accountNumber = opts?.accountNumber;\n let accountSequence = opts?.sequence;\n if (accountNumber === undefined || accountSequence === undefined) {\n const address: string = await this.getAddress();\n const account = await this.provider.getAccount(address);\n if (accountNumber === undefined) {\n accountNumber = account.BaseAccount.account_number;\n }\n if (accountSequence === undefined) {\n accountSequence = account.BaseAccount.sequence;\n }\n }\n const publicKey: Uint8Array = await this.signer.getPublicKey();\n\n // Create the signature payload\n const signPayload: TxSignPayload = {\n chain_id: chainID,\n account_number: accountNumber,\n sequence: accountSequence,\n fee: {\n gas_fee: tx.fee.gas_fee,\n gas_wanted: tx.fee.gas_wanted.toString(10),\n },\n msgs: decodeTxMessages(tx.messages), // unrolled message objects\n memo: tx.memo,\n };\n\n // The TM2 node does signature verification using\n // a sorted JSON object, so the payload needs to be sorted\n // before signing\n const signBytes: Uint8Array = stringToUTF8(\n encodeCharacterSet(sortedJsonStringify(signPayload)),\n );\n\n // The public key needs to be encoded using protobuf for Amino\n const wrappedKey: PubKeySecp256k1 = {\n key: publicKey,\n };\n\n // Generate the signature\n const txSignature: TxSignature = {\n pub_key: {\n type_url: Secp256k1PubKeyType,\n value: PubKeySecp256k1.encode(wrappedKey).finish(),\n },\n signature: await this.getSigner().signData(signBytes),\n };\n\n // Append the signature\n return {\n ...tx,\n signatures: [...tx.signatures, txSignature],\n };\n };\n\n /**\n * Encodes and sends the transaction. If the type of endpoint\n * is a broadcast commit, waits for the transaction to be committed to the chain.\n * The transaction needs to be signed beforehand.\n * Returns the transaction hash (base-64)\n * @param {Tx} tx the signed transaction\n * @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)\n */\n async sendTransaction<K extends keyof BroadcastTransactionMap>(\n tx: Tx,\n endpoint: K,\n ): Promise<BroadcastTransactionMap[K][\"result\"]> {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Encode the transaction to base-64\n const encodedTx: string = uint8ArrayToBase64(Tx.encode(tx).finish());\n\n // Send the encoded transaction\n return this.provider.sendTransaction(encodedTx, endpoint);\n }\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,SAAS;;;;+CAxSpD,gBAAe,OACpB,YACoB;CACpB,MAAM,EACJ,WAAW,eACT,MAAMC,gBAAAA,gBACRC,eAAAA,MAAM,OAAOC,gBAAAA,iBAAiB,CAAC,CAAC,UAAU,EAC1C,EACD;CAGD,MAAM,SAAiB,IAAIC,SAAQ;AACnC,QAAO,SAAS,IAAIC,YAAAA,UAClB,YACAC,eAAAA,UAAU,eAAe,UAAU,EACnC,SAAS,cACV;AAED,QAAO;EACP;+CAOK,cAAa,OAAO,WAAoC;CAE7D,MAAM,SAAiB,IAAIF,SAAQ;AACnC,QAAO,SAAS;AAEhB,QAAO;EACP;+CAOK,gBAAe,OACpB,UACA,YACoB;CACpB,MAAM,EACJ,WAAW,eACT,MAAMH,gBAAAA,gBACR,UACA,SAAS,aACV;CAGD,MAAM,SAAiB,IAAIG,SAAQ;AACnC,QAAO,SAAS,IAAIC,YAAAA,UAClB,YACAC,eAAAA,UAAU,eAAe,UAAU,EACnC,SAAS,cACV;AAED,QAAO;EACP;+CAOK,kBAAiB,OACtB,YACA,YACoB;CAEpB,MAAM,EACJ,QAAQ,cACN,MAAMA,eAAAA,UAAU,YAAY,WAAW;CAG3C,MAAM,SAAiB,IAAIF,SAAQ;AACnC,QAAO,SAAS,IAAIC,YAAAA,UAClB,YACAC,eAAAA,UAAU,eAAe,UAAU,EACnC,SAAS,cACV;AAED,QAAO;EACP;+CAOK,eACL,WACA,YACW;CACX,MAAM,SAAiB,IAAIF,SAAQ;AAEnC,QAAO,SAAS,IAAIG,eAAAA,aAClB,WACA,SAAS,gBAAgB,GACzB,SAAS,cACV;AAED,QAAO;EACP"}
|
|
1
|
+
{"version":3,"file":"wallet.cjs","names":["stringToUTF8","encodeCharacterSet","sortedJsonStringify","Secp256k1PubKeyType","PubKeySecp256k1","uint8ArrayToBase64","Tx","generateKeyPair","Bip39","generateEntropy","Wallet","KeySigner","Secp256k1","LedgerSigner"],"sources":["../../src/wallet/wallet.ts"],"sourcesContent":["import {\n Bip39, Secp256k1,\n} from \"@cosmjs/crypto\";\nimport {\n LedgerConnector,\n} from \"@cosmjs/ledger-amino\";\n\nimport {\n Any, PubKeySecp256k1, Tx, TxSignature,\n} from \"../proto/index.js\";\nimport {\n BroadcastTransactionMap,\n Provider,\n Status,\n uint8ArrayToBase64,\n} from \"../provider/index.js\";\nimport {\n KeySigner,\n} from \"./key/index.js\";\nimport {\n LedgerSigner,\n} from \"./ledger/index.js\";\nimport {\n Signer,\n} from \"./signer.js\";\nimport {\n AccountWalletOption,\n CreateWalletOptions,\n Secp256k1PubKeyType,\n TxSignPayload,\n} from \"./types/index.js\";\nimport {\n encodeCharacterSet,\n generateEntropy,\n generateKeyPair,\n stringToUTF8,\n} from \"./utility/index.js\";\nimport {\n sortedJsonStringify,\n} from \"./utility/index.js\";\nexport interface SignTransactionOptions {\n accountNumber?: string\n sequence?: string\n}\n\n/**\n * Wallet is a single account abstraction\n * that can interact with the blockchain\n */\nexport class Wallet {\n protected declare provider: Provider;\n protected declare signer: Signer;\n\n /**\n * Connects the wallet to the specified {@link Provider}\n * @param {Provider} provider the active {@link Provider}, if any\n */\n connect = (provider: Provider) => {\n this.provider = provider;\n };\n\n // Wallet initialization //\n\n /**\n * Generates a private key-based wallet, using a random seed\n * @param {AccountWalletOption} options the account options\n */\n static createRandom = async (\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n Bip39.encode(generateEntropy()).toString(),\n 0,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a custom signer-based wallet\n * @param {Signer} signer the custom signer implementing the Signer interface\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromSigner = async (signer: Signer): Promise<Wallet> => {\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = signer;\n\n return wallet;\n };\n\n /**\n * Generates a bip39 mnemonic-based wallet\n * @param {string} mnemonic the bip39 mnemonic\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromMnemonic = async (\n mnemonic: string,\n options?: CreateWalletOptions,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n mnemonic,\n options?.accountIndex,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a private key-based wallet\n * @param {string} privateKey the private key\n * @param {AccountWalletOption} options the account options\n */\n static fromPrivateKey = async (\n privateKey: Uint8Array,\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n // Derive the public key\n const {\n pubkey: publicKey,\n } = await Secp256k1.makeKeypair(privateKey);\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Creates a Ledger-based wallet\n * @param {LedgerConnector} connector the Ledger device connector\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromLedger = (\n connector: LedgerConnector,\n options?: CreateWalletOptions,\n ): Wallet => {\n const wallet: Wallet = new Wallet();\n\n wallet.signer = new LedgerSigner(\n connector,\n options?.accountIndex ?? 0,\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n // Account manipulation //\n\n /**\n * Fetches the address associated with the wallet\n */\n getAddress = (): Promise<string> => {\n return this.signer.getAddress();\n };\n\n /**\n * Fetches the account sequence for the wallet\n * @param {number} [height=latest] the block height\n */\n getAccountSequence = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountSequence(address, height);\n };\n\n /**\n * Fetches the account number for the wallet. Errors out if the\n * account is not initialized\n * @param {number} [height=latest] the block height\n */\n getAccountNumber = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountNumber(address, height);\n };\n\n /**\n * Fetches the account balance for the specific denomination\n * @param {string} [denomination=ugnot] the fund denomination\n */\n getBalance = async (denomination?: string): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getBalance(\n address,\n denomination ? denomination : \"ugnot\",\n );\n };\n\n /**\n * Fetches the current (recommended) average gas price\n */\n getGasPrice = async (): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.getGasPrice();\n };\n\n /**\n * Estimates the gas limit for the transaction\n * @param {Tx} tx the transaction that needs estimating\n */\n estimateGas = async (tx: Tx): Promise<bigint> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.estimateGas(tx);\n };\n\n /**\n * Returns the connected provider, if any\n */\n getProvider = (): Provider => {\n return this.provider;\n };\n\n /**\n * Generates a transaction signature, and appends it to the transaction\n * @param {Tx} tx the transaction to be signed\n * @param {(messages: Any[]) => any[]} decodeTxMessages tx message decode callback\n * that should expand the concrete message fields into an object. Required because\n * the transaction sign bytes are generated using sorted JSON, which requires\n * encoded message values to be decoded for sorting\n */\n signTransaction = async (\n tx: Tx,\n decodeTxMessages: (messages: Any[]) => unknown[],\n opts?: SignTransactionOptions,\n ): Promise<Tx> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Make sure the tx fee is initialized\n if (!tx.fee) {\n throw new Error(\"invalid transaction fee provided\");\n }\n\n // Extract the relevant chain data\n const status: Status = await this.provider.getStatus();\n const chainID: string = status.node_info.network;\n\n // Extract the relevant account data\n let accountNumber = opts?.accountNumber;\n let accountSequence = opts?.sequence;\n if (accountNumber === undefined || accountSequence === undefined) {\n const address: string = await this.getAddress();\n const account = await this.provider.getAccount(address);\n if (accountNumber === undefined) {\n accountNumber = account.BaseAccount.account_number;\n }\n if (accountSequence === undefined) {\n accountSequence = account.BaseAccount.sequence;\n }\n }\n const publicKey: Uint8Array = await this.signer.getPublicKey();\n\n // Create the signature payload\n const signPayload: TxSignPayload = {\n chain_id: chainID,\n account_number: accountNumber,\n sequence: accountSequence,\n fee: {\n gas_fee: tx.fee.gas_fee,\n gas_wanted: tx.fee.gas_wanted.toString(10),\n },\n msgs: decodeTxMessages(tx.messages), // unrolled message objects\n memo: tx.memo,\n };\n\n // The TM2 node does signature verification using\n // a sorted JSON object, so the payload needs to be sorted\n // before signing\n const signBytes: Uint8Array = stringToUTF8(\n encodeCharacterSet(sortedJsonStringify(signPayload)),\n );\n\n // The public key needs to be encoded using protobuf for Amino\n const wrappedKey: PubKeySecp256k1 = {\n key: publicKey,\n };\n\n // Generate the signature\n const txSignature: TxSignature = {\n pub_key: {\n type_url: Secp256k1PubKeyType,\n value: PubKeySecp256k1.encode(wrappedKey).finish(),\n },\n signature: await this.getSigner().signData(signBytes),\n };\n\n // Append the signature\n return {\n ...tx,\n signatures: [...tx.signatures, txSignature],\n };\n };\n\n /**\n * Encodes and sends the transaction. If the type of endpoint\n * is a broadcast commit, waits for the transaction to be committed to the chain.\n * The transaction needs to be signed beforehand.\n * Returns the transaction hash (base-64)\n * @param {Tx} tx the signed transaction\n * @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)\n */\n async sendTransaction<K extends keyof BroadcastTransactionMap>(\n tx: Tx,\n endpoint: K,\n ): Promise<BroadcastTransactionMap[K][\"result\"]> {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Encode the transaction to base-64\n const encodedTx: string = uint8ArrayToBase64(Tx.encode(tx).finish());\n\n // Send the encoded transaction\n return this.provider.sendTransaction(encodedTx, endpoint);\n }\n\n /**\n * Returns the associated signer\n */\n getSigner = (): Signer => {\n return this.signer;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiDA,IAAa,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gBAAAA,iBAAiB,CAAC,CAAC,UAAU,EAC1C,EACD;CAGD,MAAM,SAAiB,IAAIC,SAAQ;AACnC,QAAO,SAAS,IAAIC,YAAAA,UAClB,YACAC,eAAAA,UAAU,eAAe,UAAU,EACnC,SAAS,cACV;AAED,QAAO;EACP;+CAOK,cAAa,OAAO,WAAoC;CAE7D,MAAM,SAAiB,IAAIF,SAAQ;AACnC,QAAO,SAAS;AAEhB,QAAO;EACP;+CAOK,gBAAe,OACpB,UACA,YACoB;CACpB,MAAM,EACJ,WAAW,eACT,MAAMH,gBAAAA,gBACR,UACA,SAAS,aACV;CAGD,MAAM,SAAiB,IAAIG,SAAQ;AACnC,QAAO,SAAS,IAAIC,YAAAA,UAClB,YACAC,eAAAA,UAAU,eAAe,UAAU,EACnC,SAAS,cACV;AAED,QAAO;EACP;+CAOK,kBAAiB,OACtB,YACA,YACoB;CAEpB,MAAM,EACJ,QAAQ,cACN,MAAMA,eAAAA,UAAU,YAAY,WAAW;CAG3C,MAAM,SAAiB,IAAIF,SAAQ;AACnC,QAAO,SAAS,IAAIC,YAAAA,UAClB,YACAC,eAAAA,UAAU,eAAe,UAAU,EACnC,SAAS,cACV;AAED,QAAO;EACP;+CAOK,eACL,WACA,YACW;CACX,MAAM,SAAiB,IAAIF,SAAQ;AAEnC,QAAO,SAAS,IAAIG,eAAAA,aAClB,WACA,SAAS,gBAAgB,GACzB,SAAS,cACV;AAED,QAAO;EACP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.cts","names":[],"sources":["../../src/wallet/wallet.ts"],"mappings":";;;;;;;;;UAwCiB,sBAAA;EACf,aAAA;EACA,QAAA;AAAA
|
|
1
|
+
{"version":3,"file":"wallet.d.cts","names":[],"sources":["../../src/wallet/wallet.ts"],"mappings":";;;;;;;;;UAwCiB,sBAAA;EACf,aAAA;EACA,QAAA;AAAA;;;;AAFF;cASa,MAAA;EAAA,UACO,QAAA,EAAU,QAAA;EAAA,UACV,MAAA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O,sBAAA,KACN,OAAA,CAAQ,EAAA;EAlHE;;;;;;;;EAgMP,eAAA,iBAAgC,uBAAA,CAAA,CACpC,EAAA,EAAI,EAAA,EACJ,QAAA,EAAU,CAAA,GACT,OAAA,CAAQ,uBAAA,CAAwB,CAAA;EAxKW;;;EAuL9C,SAAA,QAAgB,MAAA;AAAA"}
|
package/dist/wallet/wallet.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import "./key/index.mjs";
|
|
|
10
10
|
import { LedgerSigner } from "./ledger/ledger.mjs";
|
|
11
11
|
import "./ledger/index.mjs";
|
|
12
12
|
import { Secp256k1PubKeyType } from "./types/sign.mjs";
|
|
13
|
+
import "./types/index.mjs";
|
|
13
14
|
import { Bip39, Secp256k1 } from "@cosmjs/crypto";
|
|
14
15
|
//#region src/wallet/wallet.ts
|
|
15
16
|
var _Wallet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.mjs","names":["Wallet"],"sources":["../../src/wallet/wallet.ts"],"sourcesContent":["import {\n Bip39, Secp256k1,\n} from \"@cosmjs/crypto\";\nimport {\n LedgerConnector,\n} from \"@cosmjs/ledger-amino\";\n\nimport {\n Any, PubKeySecp256k1, Tx, TxSignature,\n} from \"../proto/index.js\";\nimport {\n BroadcastTransactionMap,\n Provider,\n Status,\n uint8ArrayToBase64,\n} from \"../provider/index.js\";\nimport {\n KeySigner,\n} from \"./key/index.js\";\nimport {\n LedgerSigner,\n} from \"./ledger/index.js\";\nimport {\n Signer,\n} from \"./signer.js\";\nimport {\n AccountWalletOption,\n CreateWalletOptions,\n Secp256k1PubKeyType,\n TxSignPayload,\n} from \"./types/index.js\";\nimport {\n encodeCharacterSet,\n generateEntropy,\n generateKeyPair,\n stringToUTF8,\n} from \"./utility/index.js\";\nimport {\n sortedJsonStringify,\n} from \"./utility/index.js\";\nexport interface SignTransactionOptions {\n accountNumber?: string\n sequence?: string\n}\n\n/**\n * Wallet is a single account abstraction\n * that can interact with the blockchain\n */\nexport class Wallet {\n protected declare provider: Provider;\n protected declare signer: Signer;\n\n /**\n * Connects the wallet to the specified {@link Provider}\n * @param {Provider} provider the active {@link Provider}, if any\n */\n connect = (provider: Provider) => {\n this.provider = provider;\n };\n\n // Wallet initialization //\n\n /**\n * Generates a private key-based wallet, using a random seed\n * @param {AccountWalletOption} options the account options\n */\n static createRandom = async (\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n Bip39.encode(generateEntropy()).toString(),\n 0,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a custom signer-based wallet\n * @param {Signer} signer the custom signer implementing the Signer interface\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromSigner = async (signer: Signer): Promise<Wallet> => {\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = signer;\n\n return wallet;\n };\n\n /**\n * Generates a bip39 mnemonic-based wallet\n * @param {string} mnemonic the bip39 mnemonic\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromMnemonic = async (\n mnemonic: string,\n options?: CreateWalletOptions,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n mnemonic,\n options?.accountIndex,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a private key-based wallet\n * @param {string} privateKey the private key\n * @param {AccountWalletOption} options the account options\n */\n static fromPrivateKey = async (\n privateKey: Uint8Array,\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n // Derive the public key\n const {\n pubkey: publicKey,\n } = await Secp256k1.makeKeypair(privateKey);\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Creates a Ledger-based wallet\n * @param {LedgerConnector} connector the Ledger device connector\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromLedger = (\n connector: LedgerConnector,\n options?: CreateWalletOptions,\n ): Wallet => {\n const wallet: Wallet = new Wallet();\n\n wallet.signer = new LedgerSigner(\n connector,\n options?.accountIndex ?? 0,\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n // Account manipulation //\n\n /**\n * Fetches the address associated with the wallet\n */\n getAddress = (): Promise<string> => {\n return this.signer.getAddress();\n };\n\n /**\n * Fetches the account sequence for the wallet\n * @param {number} [height=latest] the block height\n */\n getAccountSequence = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountSequence(address, height);\n };\n\n /**\n * Fetches the account number for the wallet. Errors out if the\n * account is not initialized\n * @param {number} [height=latest] the block height\n */\n getAccountNumber = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountNumber(address, height);\n };\n\n /**\n * Fetches the account balance for the specific denomination\n * @param {string} [denomination=ugnot] the fund denomination\n */\n getBalance = async (denomination?: string): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getBalance(\n address,\n denomination ? denomination : \"ugnot\",\n );\n };\n\n /**\n * Fetches the current (recommended) average gas price\n */\n getGasPrice = async (): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.getGasPrice();\n };\n\n /**\n * Estimates the gas limit for the transaction\n * @param {Tx} tx the transaction that needs estimating\n */\n estimateGas = async (tx: Tx): Promise<bigint> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.estimateGas(tx);\n };\n\n /**\n * Returns the connected provider, if any\n */\n getProvider = (): Provider => {\n return this.provider;\n };\n\n /**\n * Generates a transaction signature, and appends it to the transaction\n * @param {Tx} tx the transaction to be signed\n * @param {(messages: Any[]) => any[]} decodeTxMessages tx message decode callback\n * that should expand the concrete message fields into an object. Required because\n * the transaction sign bytes are generated using sorted JSON, which requires\n * encoded message values to be decoded for sorting\n */\n signTransaction = async (\n tx: Tx,\n decodeTxMessages: (messages: Any[]) => unknown[],\n opts?: SignTransactionOptions,\n ): Promise<Tx> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Make sure the tx fee is initialized\n if (!tx.fee) {\n throw new Error(\"invalid transaction fee provided\");\n }\n\n // Extract the relevant chain data\n const status: Status = await this.provider.getStatus();\n const chainID: string = status.node_info.network;\n\n // Extract the relevant account data\n let accountNumber = opts?.accountNumber;\n let accountSequence = opts?.sequence;\n if (accountNumber === undefined || accountSequence === undefined) {\n const address: string = await this.getAddress();\n const account = await this.provider.getAccount(address);\n if (accountNumber === undefined) {\n accountNumber = account.BaseAccount.account_number;\n }\n if (accountSequence === undefined) {\n accountSequence = account.BaseAccount.sequence;\n }\n }\n const publicKey: Uint8Array = await this.signer.getPublicKey();\n\n // Create the signature payload\n const signPayload: TxSignPayload = {\n chain_id: chainID,\n account_number: accountNumber,\n sequence: accountSequence,\n fee: {\n gas_fee: tx.fee.gas_fee,\n gas_wanted: tx.fee.gas_wanted.toString(10),\n },\n msgs: decodeTxMessages(tx.messages), // unrolled message objects\n memo: tx.memo,\n };\n\n // The TM2 node does signature verification using\n // a sorted JSON object, so the payload needs to be sorted\n // before signing\n const signBytes: Uint8Array = stringToUTF8(\n encodeCharacterSet(sortedJsonStringify(signPayload)),\n );\n\n // The public key needs to be encoded using protobuf for Amino\n const wrappedKey: PubKeySecp256k1 = {\n key: publicKey,\n };\n\n // Generate the signature\n const txSignature: TxSignature = {\n pub_key: {\n type_url: Secp256k1PubKeyType,\n value: PubKeySecp256k1.encode(wrappedKey).finish(),\n },\n signature: await this.getSigner().signData(signBytes),\n };\n\n // Append the signature\n return {\n ...tx,\n signatures: [...tx.signatures, txSignature],\n };\n };\n\n /**\n * Encodes and sends the transaction. If the type of endpoint\n * is a broadcast commit, waits for the transaction to be committed to the chain.\n * The transaction needs to be signed beforehand.\n * Returns the transaction hash (base-64)\n * @param {Tx} tx the signed transaction\n * @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)\n */\n async sendTransaction<K extends keyof BroadcastTransactionMap>(\n tx: Tx,\n endpoint: K,\n ): Promise<BroadcastTransactionMap[K][\"result\"]> {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Encode the transaction to base-64\n const encodedTx: string = uint8ArrayToBase64(Tx.encode(tx).finish());\n\n // Send the encoded transaction\n return this.provider.sendTransaction(encodedTx, endpoint);\n }\n\n /**\n * Returns the associated signer\n */\n getSigner = (): Signer => {\n return this.signer;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiDA,IAAa,SAAb,MAAoB;;;;;;;;GAQlB;IAAW,aAAuB;AAChC,SAAK,WAAW;;GAChB;;;;;;GAuHF;SAAoC;AAClC,WAAO,KAAK,OAAO,YAAY;;GAC/B;;;;;;;GAMF;GAAqB,OAAO,WAAqC;AAC/D,QAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM,yBAAyB;IAI3C,MAAM,UAAkB,MAAM,KAAK,YAAY;AAE/C,WAAO,KAAK,SAAS,mBAAmB,SAAS,OAAO;;GACxD;;;;;;;;GAOF;GAAmB,OAAO,WAAqC;AAC7D,QAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM,yBAAyB;IAI3C,MAAM,UAAkB,MAAM,KAAK,YAAY;AAE/C,WAAO,KAAK,SAAS,iBAAiB,SAAS,OAAO;;GACtD;;;;;;;GAMF;GAAa,OAAO,iBAA2C;AAC7D,QAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM,yBAAyB;IAI3C,M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EACP;wBAOK,eACL,WACA,YACW;CACX,MAAM,SAAiB,IAAIA,SAAQ;AAEnC,QAAO,SAAS,IAAI,aAClB,WACA,SAAS,gBAAgB,GACzB,SAAS,cACV;AAED,QAAO;EACP"}
|
|
1
|
+
{"version":3,"file":"wallet.mjs","names":["Wallet"],"sources":["../../src/wallet/wallet.ts"],"sourcesContent":["import {\n Bip39, Secp256k1,\n} from \"@cosmjs/crypto\";\nimport {\n LedgerConnector,\n} from \"@cosmjs/ledger-amino\";\n\nimport {\n Any, PubKeySecp256k1, Tx, TxSignature,\n} from \"../proto/index.js\";\nimport {\n BroadcastTransactionMap,\n Provider,\n Status,\n uint8ArrayToBase64,\n} from \"../provider/index.js\";\nimport {\n KeySigner,\n} from \"./key/index.js\";\nimport {\n LedgerSigner,\n} from \"./ledger/index.js\";\nimport {\n Signer,\n} from \"./signer.js\";\nimport {\n AccountWalletOption,\n CreateWalletOptions,\n Secp256k1PubKeyType,\n TxSignPayload,\n} from \"./types/index.js\";\nimport {\n encodeCharacterSet,\n generateEntropy,\n generateKeyPair,\n stringToUTF8,\n} from \"./utility/index.js\";\nimport {\n sortedJsonStringify,\n} from \"./utility/index.js\";\nexport interface SignTransactionOptions {\n accountNumber?: string\n sequence?: string\n}\n\n/**\n * Wallet is a single account abstraction\n * that can interact with the blockchain\n */\nexport class Wallet {\n protected declare provider: Provider;\n protected declare signer: Signer;\n\n /**\n * Connects the wallet to the specified {@link Provider}\n * @param {Provider} provider the active {@link Provider}, if any\n */\n connect = (provider: Provider) => {\n this.provider = provider;\n };\n\n // Wallet initialization //\n\n /**\n * Generates a private key-based wallet, using a random seed\n * @param {AccountWalletOption} options the account options\n */\n static createRandom = async (\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n Bip39.encode(generateEntropy()).toString(),\n 0,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a custom signer-based wallet\n * @param {Signer} signer the custom signer implementing the Signer interface\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromSigner = async (signer: Signer): Promise<Wallet> => {\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = signer;\n\n return wallet;\n };\n\n /**\n * Generates a bip39 mnemonic-based wallet\n * @param {string} mnemonic the bip39 mnemonic\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromMnemonic = async (\n mnemonic: string,\n options?: CreateWalletOptions,\n ): Promise<Wallet> => {\n const {\n publicKey, privateKey,\n } = await generateKeyPair(\n mnemonic,\n options?.accountIndex,\n );\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Generates a private key-based wallet\n * @param {string} privateKey the private key\n * @param {AccountWalletOption} options the account options\n */\n static fromPrivateKey = async (\n privateKey: Uint8Array,\n options?: AccountWalletOption,\n ): Promise<Wallet> => {\n // Derive the public key\n const {\n pubkey: publicKey,\n } = await Secp256k1.makeKeypair(privateKey);\n\n // Initialize the wallet\n const wallet: Wallet = new Wallet();\n wallet.signer = new KeySigner(\n privateKey,\n Secp256k1.compressPubkey(publicKey),\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n /**\n * Creates a Ledger-based wallet\n * @param {LedgerConnector} connector the Ledger device connector\n * @param {CreateWalletOptions} options the wallet generation options\n */\n static fromLedger = (\n connector: LedgerConnector,\n options?: CreateWalletOptions,\n ): Wallet => {\n const wallet: Wallet = new Wallet();\n\n wallet.signer = new LedgerSigner(\n connector,\n options?.accountIndex ?? 0,\n options?.addressPrefix,\n );\n\n return wallet;\n };\n\n // Account manipulation //\n\n /**\n * Fetches the address associated with the wallet\n */\n getAddress = (): Promise<string> => {\n return this.signer.getAddress();\n };\n\n /**\n * Fetches the account sequence for the wallet\n * @param {number} [height=latest] the block height\n */\n getAccountSequence = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountSequence(address, height);\n };\n\n /**\n * Fetches the account number for the wallet. Errors out if the\n * account is not initialized\n * @param {number} [height=latest] the block height\n */\n getAccountNumber = async (height?: number): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getAccountNumber(address, height);\n };\n\n /**\n * Fetches the account balance for the specific denomination\n * @param {string} [denomination=ugnot] the fund denomination\n */\n getBalance = async (denomination?: string): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Get the address\n const address: string = await this.getAddress();\n\n return this.provider.getBalance(\n address,\n denomination ? denomination : \"ugnot\",\n );\n };\n\n /**\n * Fetches the current (recommended) average gas price\n */\n getGasPrice = async (): Promise<number> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.getGasPrice();\n };\n\n /**\n * Estimates the gas limit for the transaction\n * @param {Tx} tx the transaction that needs estimating\n */\n estimateGas = async (tx: Tx): Promise<bigint> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n return this.provider.estimateGas(tx);\n };\n\n /**\n * Returns the connected provider, if any\n */\n getProvider = (): Provider => {\n return this.provider;\n };\n\n /**\n * Generates a transaction signature, and appends it to the transaction\n * @param {Tx} tx the transaction to be signed\n * @param {(messages: Any[]) => any[]} decodeTxMessages tx message decode callback\n * that should expand the concrete message fields into an object. Required because\n * the transaction sign bytes are generated using sorted JSON, which requires\n * encoded message values to be decoded for sorting\n */\n signTransaction = async (\n tx: Tx,\n decodeTxMessages: (messages: Any[]) => unknown[],\n opts?: SignTransactionOptions,\n ): Promise<Tx> => {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Make sure the tx fee is initialized\n if (!tx.fee) {\n throw new Error(\"invalid transaction fee provided\");\n }\n\n // Extract the relevant chain data\n const status: Status = await this.provider.getStatus();\n const chainID: string = status.node_info.network;\n\n // Extract the relevant account data\n let accountNumber = opts?.accountNumber;\n let accountSequence = opts?.sequence;\n if (accountNumber === undefined || accountSequence === undefined) {\n const address: string = await this.getAddress();\n const account = await this.provider.getAccount(address);\n if (accountNumber === undefined) {\n accountNumber = account.BaseAccount.account_number;\n }\n if (accountSequence === undefined) {\n accountSequence = account.BaseAccount.sequence;\n }\n }\n const publicKey: Uint8Array = await this.signer.getPublicKey();\n\n // Create the signature payload\n const signPayload: TxSignPayload = {\n chain_id: chainID,\n account_number: accountNumber,\n sequence: accountSequence,\n fee: {\n gas_fee: tx.fee.gas_fee,\n gas_wanted: tx.fee.gas_wanted.toString(10),\n },\n msgs: decodeTxMessages(tx.messages), // unrolled message objects\n memo: tx.memo,\n };\n\n // The TM2 node does signature verification using\n // a sorted JSON object, so the payload needs to be sorted\n // before signing\n const signBytes: Uint8Array = stringToUTF8(\n encodeCharacterSet(sortedJsonStringify(signPayload)),\n );\n\n // The public key needs to be encoded using protobuf for Amino\n const wrappedKey: PubKeySecp256k1 = {\n key: publicKey,\n };\n\n // Generate the signature\n const txSignature: TxSignature = {\n pub_key: {\n type_url: Secp256k1PubKeyType,\n value: PubKeySecp256k1.encode(wrappedKey).finish(),\n },\n signature: await this.getSigner().signData(signBytes),\n };\n\n // Append the signature\n return {\n ...tx,\n signatures: [...tx.signatures, txSignature],\n };\n };\n\n /**\n * Encodes and sends the transaction. If the type of endpoint\n * is a broadcast commit, waits for the transaction to be committed to the chain.\n * The transaction needs to be signed beforehand.\n * Returns the transaction hash (base-64)\n * @param {Tx} tx the signed transaction\n * @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)\n */\n async sendTransaction<K extends keyof BroadcastTransactionMap>(\n tx: Tx,\n endpoint: K,\n ): Promise<BroadcastTransactionMap[K][\"result\"]> {\n if (!this.provider) {\n throw new Error(\"provider not connected\");\n }\n\n // Encode the transaction to base-64\n const encodedTx: string = uint8ArrayToBase64(Tx.encode(tx).finish());\n\n // Send the encoded transaction\n return this.provider.sendTransaction(encodedTx, endpoint);\n }\n\n /**\n * Returns the associated signer\n */\n getSigner = (): Signer => {\n return this.signer;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiDA,IAAa,SAAb,MAAoB;;;;;;;;GAQlB;IAAW,aAAuB;AAChC,SAAK,WAAW;;GAChB;;;;;;GAuHF;SAAoC;AAClC,WAAO,KAAK,OAAO,YAAY;;GAC/B;;;;;;;GAMF;GAAqB,OAAO,WAAqC;AAC/D,QAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM,yBAAyB;IAI3C,MAAM,UAAkB,MAAM,KAAK,YAAY;AAE/C,WAAO,KAAK,SAAS,mBAAmB,SAAS,OAAO;;GACxD;;;;;;;;GAOF;GAAmB,OAAO,WAAqC;AAC7D,QAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM,yBAAyB;IAI3C,MAAM,UAAkB,MAAM,KAAK,YAAY;AAE/C,WAAO,KAAK,SAAS,iBAAiB,SAAS,OAAO;;GACtD;;;;;;;GAMF;GAAa,OAAO,iBAA2C;AAC7D,QAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM,yBAAyB;IAI3C,MAAM,UAAkB,MAAM,KAAK,YAAY;AAE/C,WAAO,KAAK,SAAS,WACnB,SACA,eAAe,eAAe,QAC/B;;GACD;;;;;;GAKF;GAAc,YAA6B;AACzC,QAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM,yBAAyB;AAG3C,WAAO,KAAK,SAAS,aAAa;;GAClC;;;;;;;GAMF;GAAc,OAAO,OAA4B;AAC/C,QAAI,CAAC,KAAK,SACR,OAAM,IAAI,MAAM,yBAAyB;AAG3C,WAAO,KAAK,SAAS,YAAY,GAAG;;GACpC;;;;;;GAKF;SAA8B;AAC5B,WAAO,KAAK;;GACZ;;;;;;;;;;;GAU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