@gnolang/tm2-js-client 2.0.1 → 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 +4 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +3 -1
- package/dist/proto/google/protobuf/any.cjs +2 -3
- 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 +2 -3
- package/dist/proto/google/protobuf/any.mjs.map +1 -1
- package/dist/proto/tm2/abci.cjs +8 -9
- 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 +8 -9
- package/dist/proto/tm2/abci.mjs.map +1 -1
- package/dist/proto/tm2/multisig.d.cts +37 -0
- package/dist/proto/tm2/multisig.d.cts.map +1 -0
- package/dist/proto/tm2/multisig.d.mts +37 -0
- package/dist/proto/tm2/multisig.d.mts.map +1 -0
- package/dist/proto/tm2/tx.cjs +6 -6
- package/dist/proto/tm2/tx.cjs.map +1 -1
- package/dist/proto/tm2/tx.d.cts.map +1 -1
- package/dist/proto/tm2/tx.d.mts.map +1 -1
- package/dist/proto/tm2/tx.mjs +6 -6
- 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/compact-bit-array.cjs +55 -0
- package/dist/utility/compact-bit-array.cjs.map +1 -0
- package/dist/utility/compact-bit-array.d.cts +26 -0
- package/dist/utility/compact-bit-array.d.cts.map +1 -0
- package/dist/utility/compact-bit-array.d.mts +26 -0
- package/dist/utility/compact-bit-array.d.mts.map +1 -0
- package/dist/utility/compact-bit-array.mjs +54 -0
- package/dist/utility/compact-bit-array.mjs.map +1 -0
- package/dist/utility/index.cjs +1 -0
- package/dist/utility/index.d.cts +1 -0
- package/dist/utility/index.d.mts +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.mjs","names":[],"sources":["../../src/provider/provider.ts"],"sourcesContent":["import {\n Tm2Client,\n} from \"@gnolang/tm2-rpc\";\n\nimport {\n Tx,\n} from \"../proto/index.js\";\nimport {\n TransactionEndpoint,\n} from \"./endpoints.js\";\nimport {\n ABCIAccount,\n ABCIErrorKey,\n ABCIResponse,\n BlockInfo,\n BlockResult,\n BroadcastAsGeneric,\n BroadcastTransactionMap,\n BroadcastTxCommitResult,\n BroadcastTxSyncResult,\n ConsensusParams,\n NetworkInfo,\n Status,\n TxResult,\n} from \"./types/index.js\";\nimport {\n constructRequestError,\n} from \"./utility/errors.utility.js\";\nimport {\n adaptAbciQueryResponse,\n adaptBlockResponse,\n adaptBlockResultsResponse,\n adaptBroadcastTxCommitResponse,\n adaptBroadcastTxSyncResponse,\n adaptConsensusParamsResponse,\n adaptNetInfoResponse,\n adaptStatusResponse,\n adaptTxResponse,\n extractAccountFromResponse,\n extractAccountNumberFromResponse,\n extractBalanceFromResponse,\n extractSequenceFromResponse,\n extractSimulateFromResponse,\n uint8ArrayToBase64,\n waitForTransaction,\n} from \"./utility/index.js\";\n\n/**\n * Read-only abstraction for accessing blockchain data\n */\nexport interface Provider {\n // Account-specific methods //\n\n /**\n * Fetches the denomination balance of the account\n * @param {string} address the bech32 address of the account\n * @param {string} [denomination=ugnot] the balance denomination\n * @param {number} [height=0] the height for querying.\n * If omitted, the latest height is used\n */\n getBalance(\n address: string,\n denomination?: string,\n height?: number\n ): Promise<number>\n\n /**\n * Fetches the account sequence\n * @param {string} address the bech32 address of the account\n * @param {number} [height=0] the height for querying.\n * If omitted, the latest height is used.\n * @deprecated use {@link getAccount} instead\n */\n getAccountSequence(address: string, height?: number): Promise<number>\n\n /**\n * Fetches the account number. Errors out if the account\n * is not initialized\n * @param {string} address the bech32 address of the account\n * @param {number} [height=0] the height for querying.\n * If omitted, the latest height is used\n * @deprecated use {@link getAccount} instead\n */\n getAccountNumber(address: string, height?: number): Promise<number>\n\n /**\n * Fetches the account. Errors out if the account\n * is not initialized\n * @param {string} address the bech32 address of the account\n * @param {number} [height=0] the height for querying.\n * If omitted, the latest height is used\n */\n getAccount(address: string, height?: number): Promise<ABCIAccount>\n\n /**\n * Fetches the block at the specific height, if any\n * @param {number} height the height for querying\n */\n getBlock(height: number): Promise<BlockInfo>\n\n /**\n * Fetches the block at the specific height, if any\n * @param {number} height the height for querying\n */\n getBlockResult(height: number): Promise<BlockResult>\n\n /**\n * Fetches the latest block number from the chain\n */\n getBlockNumber(): Promise<number>\n\n // Network-specific methods //\n\n /**\n * Fetches the network information\n */\n getNetwork(): Promise<NetworkInfo>\n\n /**\n * Fetches the consensus params for the specific block height\n * @param {number} height the height for querying\n */\n getConsensusParams(height: number): Promise<ConsensusParams>\n\n /**\n * Fetches the current node status\n */\n getStatus(): Promise<Status>\n\n /**\n * Fetches the current (recommended) average gas price\n */\n getGasPrice(): Promise<number>\n\n /**\n * Estimates the gas limit for the transaction\n * @param {Tx} tx the transaction that needs estimating\n */\n estimateGas(tx: Tx): Promise<bigint>\n\n // Transaction specific methods //\n\n /**\n * Sends the transaction to the node. 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 broadcast result.\n * @param {string} tx the base64-encoded signed transaction\n * @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)\n */\n sendTransaction<K extends keyof BroadcastTransactionMap>(\n tx: string,\n endpoint: K\n ): Promise<BroadcastAsGeneric<K>[\"result\"]>\n\n /**\n * Waits for the transaction to be committed on the chain.\n * NOTE: This method will not take in the fromHeight parameter once\n * proper transaction indexing is added - the implementation should\n * simply try to fetch the transaction first to see if it's included in a block\n * before starting to wait for it; Until then, this method should be used\n * in the sequence:\n * get latest block -> send transaction -> waitForTransaction(block before send)\n * @param {string} hash The transaction hash\n * @param {number} [fromHeight=latest] The block height used to begin the search\n * @param {number} [timeout=15000] Optional wait timeout in MS\n */\n waitForTransaction(\n hash: string,\n fromHeight?: number,\n timeout?: number\n ): Promise<Tx>\n}\n\n/**\n * Base provider implementation backed by a Tm2Client.\n * Subclasses only need to provide a static `create()` factory.\n */\nexport abstract class BaseTm2Provider implements Provider {\n protected readonly client: Tm2Client;\n\n protected constructor(client: Tm2Client) {\n this.client = client;\n }\n\n async estimateGas(tx: Tx): Promise<bigint> {\n const encodedTx = uint8ArrayToBase64(Tx.encode(tx).finish());\n const rpcResponse = await this.client.abciQuery({\n path: \".app/simulate\",\n data: new TextEncoder().encode(encodedTx),\n height: 0,\n prove: false,\n });\n\n const abciResponse: ABCIResponse = adaptAbciQueryResponse(rpcResponse);\n const simulateResult = extractSimulateFromResponse(abciResponse);\n\n const resultErrorKey = simulateResult.response_base?.error?.type_url;\n if (resultErrorKey) {\n throw constructRequestError(resultErrorKey);\n }\n\n return simulateResult.gas_used;\n }\n\n async getBalance(\n address: string,\n denomination?: string,\n height?: number,\n ): Promise<number> {\n const rpcResponse = await this.client.abciQuery({\n path: `bank/balances/${address}`,\n data: new Uint8Array(),\n height: height ? height : 0,\n prove: false,\n });\n\n const abciResponse: ABCIResponse = adaptAbciQueryResponse(rpcResponse);\n\n return extractBalanceFromResponse(\n abciResponse.response.ResponseBase.Data,\n denomination ? denomination : \"ugnot\",\n );\n }\n\n async getBlock(height: number): Promise<BlockInfo> {\n const rpcResponse = await this.client.block(height);\n return adaptBlockResponse(rpcResponse);\n }\n\n async getBlockResult(height: number): Promise<BlockResult> {\n const rpcResponse = await this.client.blockResults(height);\n return adaptBlockResultsResponse(rpcResponse);\n }\n\n async getBlockNumber(): Promise<number> {\n const status = await this.getStatus();\n return parseInt(status.sync_info.latest_block_height);\n }\n\n async getConsensusParams(height: number): Promise<ConsensusParams> {\n const rpcResponse = await this.client.consensusParams(height);\n return adaptConsensusParamsResponse(rpcResponse);\n }\n\n getGasPrice(): Promise<number> {\n return Promise.reject(\"not supported\");\n }\n\n async getNetwork(): Promise<NetworkInfo> {\n const rpcResponse = await this.client.netInfo();\n return adaptNetInfoResponse(rpcResponse);\n }\n\n async getAccountSequence(address: string, height?: number): Promise<number> {\n const rpcResponse = await this.client.abciQuery({\n path: `auth/accounts/${address}`,\n data: new Uint8Array(),\n height: height ? height : 0,\n prove: false,\n });\n\n const abciResponse: ABCIResponse = adaptAbciQueryResponse(rpcResponse);\n return extractSequenceFromResponse(abciResponse.response.ResponseBase.Data);\n }\n\n async getAccountNumber(address: string, height?: number): Promise<number> {\n const rpcResponse = await this.client.abciQuery({\n path: `auth/accounts/${address}`,\n data: new Uint8Array(),\n height: height ? height : 0,\n prove: false,\n });\n\n const abciResponse: ABCIResponse = adaptAbciQueryResponse(rpcResponse);\n return extractAccountNumberFromResponse(\n abciResponse.response.ResponseBase.Data,\n );\n }\n\n async getAccount(address: string, height?: number): Promise<ABCIAccount> {\n const rpcResponse = await this.client.abciQuery({\n path: `auth/accounts/${address}`,\n data: new Uint8Array(),\n height: height ? height : 0,\n prove: false,\n });\n\n const abciResponse: ABCIResponse = adaptAbciQueryResponse(rpcResponse);\n return extractAccountFromResponse(abciResponse.response.ResponseBase.Data);\n }\n\n async getStatus(): Promise<Status> {\n const rpcResponse = await this.client.status();\n return adaptStatusResponse(rpcResponse);\n }\n\n async getTransaction(hash: string): Promise<TxResult> {\n const hashBytes = Uint8Array.from(\n (hash.match(/.{1,2}/g) ?? []).map(byte => parseInt(byte, 16)),\n );\n const rpcResponse = await this.client.tx({\n hash: hashBytes,\n });\n return adaptTxResponse(rpcResponse);\n }\n\n async sendTransaction<K extends keyof BroadcastTransactionMap>(\n tx: string,\n endpoint: K,\n ): Promise<BroadcastTransactionMap[K][\"result\"]> {\n const txBytes = Uint8Array.from(Buffer.from(tx, \"base64\"));\n\n switch (endpoint) {\n case TransactionEndpoint.BROADCAST_TX_COMMIT:\n return this.broadcastTxCommit(txBytes);\n case TransactionEndpoint.BROADCAST_TX_SYNC:\n default:\n return this.broadcastTxSync(txBytes);\n }\n }\n\n private async broadcastTxSync(\n txBytes: Uint8Array,\n ): Promise<BroadcastTxSyncResult> {\n const rpcResponse = await this.client.broadcastTxSync({\n tx: txBytes,\n });\n const response = adaptBroadcastTxSyncResponse(rpcResponse);\n\n if (response.error) {\n const errType: string = response.error[ABCIErrorKey];\n const log: string = response.Log;\n\n throw constructRequestError(errType, log);\n }\n\n return response;\n }\n\n private async broadcastTxCommit(\n txBytes: Uint8Array,\n ): Promise<BroadcastTxCommitResult> {\n const rpcResponse = await this.client.broadcastTxCommit({\n tx: txBytes,\n });\n const response = adaptBroadcastTxCommitResponse(rpcResponse);\n\n const {\n check_tx, deliver_tx,\n } = response;\n\n if (check_tx.ResponseBase.Error) {\n const errType: string = check_tx.ResponseBase.Error[ABCIErrorKey];\n const log: string = check_tx.ResponseBase.Log;\n\n throw constructRequestError(errType, log);\n }\n\n if (deliver_tx.ResponseBase.Error) {\n const errType: string = deliver_tx.ResponseBase.Error[ABCIErrorKey];\n const log: string = deliver_tx.ResponseBase.Log;\n\n throw constructRequestError(errType, log);\n }\n\n return response;\n }\n\n async waitForTransaction(\n hash: string,\n fromHeight?: number,\n timeout?: number,\n ): Promise<Tx> {\n return waitForTransaction(this, hash, fromHeight, timeout);\n }\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"provider.mjs","names":[],"sources":["../../src/provider/provider.ts"],"sourcesContent":["import {\n Tm2Client,\n} from \"@gnolang/tm2-rpc\";\n\nimport {\n Tx,\n} from \"../proto/index.js\";\nimport {\n TransactionEndpoint,\n} from \"./endpoints.js\";\nimport {\n ABCIAccount,\n ABCIErrorKey,\n ABCIResponse,\n BlockInfo,\n BlockResult,\n BroadcastAsGeneric,\n BroadcastTransactionMap,\n BroadcastTxCommitResult,\n BroadcastTxSyncResult,\n ConsensusParams,\n NetworkInfo,\n Status,\n TxResult,\n} from \"./types/index.js\";\nimport {\n constructRequestError,\n} from \"./utility/errors.utility.js\";\nimport {\n adaptAbciQueryResponse,\n adaptBlockResponse,\n adaptBlockResultsResponse,\n adaptBroadcastTxCommitResponse,\n adaptBroadcastTxSyncResponse,\n adaptConsensusParamsResponse,\n adaptNetInfoResponse,\n adaptStatusResponse,\n adaptTxResponse,\n extractAccountFromResponse,\n extractAccountNumberFromResponse,\n extractBalanceFromResponse,\n extractSequenceFromResponse,\n extractSimulateFromResponse,\n uint8ArrayToBase64,\n waitForTransaction,\n} from \"./utility/index.js\";\n\n/**\n * Read-only abstraction for accessing blockchain data\n */\nexport interface Provider {\n // Account-specific methods //\n\n /**\n * Fetches the denomination balance of the account\n * @param {string} address the bech32 address of the account\n * @param {string} [denomination=ugnot] the balance denomination\n * @param {number} [height=0] the height for querying.\n * If omitted, the latest height is used\n */\n getBalance(\n address: string,\n denomination?: string,\n height?: number\n ): Promise<number>\n\n /**\n * Fetches the account sequence\n * @param {string} address the bech32 address of the account\n * @param {number} [height=0] the height for querying.\n * If omitted, the latest height is used.\n * @deprecated use {@link getAccount} instead\n */\n getAccountSequence(address: string, height?: number): Promise<number>\n\n /**\n * Fetches the account number. Errors out if the account\n * is not initialized\n * @param {string} address the bech32 address of the account\n * @param {number} [height=0] the height for querying.\n * If omitted, the latest height is used\n * @deprecated use {@link getAccount} instead\n */\n getAccountNumber(address: string, height?: number): Promise<number>\n\n /**\n * Fetches the account. Errors out if the account\n * is not initialized\n * @param {string} address the bech32 address of the account\n * @param {number} [height=0] the height for querying.\n * If omitted, the latest height is used\n */\n getAccount(address: string, height?: number): Promise<ABCIAccount>\n\n /**\n * Fetches the block at the specific height, if any\n * @param {number} height the height for querying\n */\n getBlock(height: number): Promise<BlockInfo>\n\n /**\n * Fetches the block at the specific height, if any\n * @param {number} height the height for querying\n */\n getBlockResult(height: number): Promise<BlockResult>\n\n /**\n * Fetches the latest block number from the chain\n */\n getBlockNumber(): Promise<number>\n\n // Network-specific methods //\n\n /**\n * Fetches the network information\n */\n getNetwork(): Promise<NetworkInfo>\n\n /**\n * Fetches the consensus params for the specific block height\n * @param {number} height the height for querying\n */\n getConsensusParams(height: number): Promise<ConsensusParams>\n\n /**\n * Fetches the current node status\n */\n getStatus(): Promise<Status>\n\n /**\n * Fetches the current (recommended) average gas price\n */\n getGasPrice(): Promise<number>\n\n /**\n * Estimates the gas limit for the transaction\n * @param {Tx} tx the transaction that needs estimating\n */\n estimateGas(tx: Tx): Promise<bigint>\n\n // Transaction specific methods //\n\n /**\n * Sends the transaction to the node. 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 broadcast result.\n * @param {string} tx the base64-encoded signed transaction\n * @param {BroadcastType} endpoint the transaction broadcast type (sync / commit)\n */\n sendTransaction<K extends keyof BroadcastTransactionMap>(\n tx: string,\n endpoint: K\n ): Promise<BroadcastAsGeneric<K>[\"result\"]>\n\n /**\n * Waits for the transaction to be committed on the chain.\n * NOTE: This method will not take in the fromHeight parameter once\n * proper transaction indexing is added - the implementation should\n * simply try to fetch the transaction first to see if it's included in a block\n * before starting to wait for it; Until then, this method should be used\n * in the sequence:\n * get latest block -> send transaction -> waitForTransaction(block before send)\n * @param {string} hash The transaction hash\n * @param {number} [fromHeight=latest] The block height used to begin the search\n * @param {number} [timeout=15000] Optional wait timeout in MS\n */\n waitForTransaction(\n hash: string,\n fromHeight?: number,\n timeout?: number\n ): Promise<Tx>\n}\n\n/**\n * Base provider implementation backed by a Tm2Client.\n * Subclasses only need to provide a static `create()` factory.\n */\nexport abstract class BaseTm2Provider implements Provider {\n protected readonly client: Tm2Client;\n\n protected constructor(client: Tm2Client) {\n this.client = client;\n }\n\n async estimateGas(tx: Tx): Promise<bigint> {\n const encodedTx = uint8ArrayToBase64(Tx.encode(tx).finish());\n const rpcResponse = await this.client.abciQuery({\n path: \".app/simulate\",\n data: new TextEncoder().encode(encodedTx),\n height: 0,\n prove: false,\n });\n\n const abciResponse: ABCIResponse = adaptAbciQueryResponse(rpcResponse);\n const simulateResult = extractSimulateFromResponse(abciResponse);\n\n const resultErrorKey = simulateResult.response_base?.error?.type_url;\n if (resultErrorKey) {\n throw constructRequestError(resultErrorKey);\n }\n\n return simulateResult.gas_used;\n }\n\n async getBalance(\n address: string,\n denomination?: string,\n height?: number,\n ): Promise<number> {\n const rpcResponse = await this.client.abciQuery({\n path: `bank/balances/${address}`,\n data: new Uint8Array(),\n height: height ? height : 0,\n prove: false,\n });\n\n const abciResponse: ABCIResponse = adaptAbciQueryResponse(rpcResponse);\n\n return extractBalanceFromResponse(\n abciResponse.response.ResponseBase.Data,\n denomination ? denomination : \"ugnot\",\n );\n }\n\n async getBlock(height: number): Promise<BlockInfo> {\n const rpcResponse = await this.client.block(height);\n return adaptBlockResponse(rpcResponse);\n }\n\n async getBlockResult(height: number): Promise<BlockResult> {\n const rpcResponse = await this.client.blockResults(height);\n return adaptBlockResultsResponse(rpcResponse);\n }\n\n async getBlockNumber(): Promise<number> {\n const status = await this.getStatus();\n return parseInt(status.sync_info.latest_block_height);\n }\n\n async getConsensusParams(height: number): Promise<ConsensusParams> {\n const rpcResponse = await this.client.consensusParams(height);\n return adaptConsensusParamsResponse(rpcResponse);\n }\n\n getGasPrice(): Promise<number> {\n return Promise.reject(\"not supported\");\n }\n\n async getNetwork(): Promise<NetworkInfo> {\n const rpcResponse = await this.client.netInfo();\n return adaptNetInfoResponse(rpcResponse);\n }\n\n async getAccountSequence(address: string, height?: number): Promise<number> {\n const rpcResponse = await this.client.abciQuery({\n path: `auth/accounts/${address}`,\n data: new Uint8Array(),\n height: height ? height : 0,\n prove: false,\n });\n\n const abciResponse: ABCIResponse = adaptAbciQueryResponse(rpcResponse);\n return extractSequenceFromResponse(abciResponse.response.ResponseBase.Data);\n }\n\n async getAccountNumber(address: string, height?: number): Promise<number> {\n const rpcResponse = await this.client.abciQuery({\n path: `auth/accounts/${address}`,\n data: new Uint8Array(),\n height: height ? height : 0,\n prove: false,\n });\n\n const abciResponse: ABCIResponse = adaptAbciQueryResponse(rpcResponse);\n return extractAccountNumberFromResponse(\n abciResponse.response.ResponseBase.Data,\n );\n }\n\n async getAccount(address: string, height?: number): Promise<ABCIAccount> {\n const rpcResponse = await this.client.abciQuery({\n path: `auth/accounts/${address}`,\n data: new Uint8Array(),\n height: height ? height : 0,\n prove: false,\n });\n\n const abciResponse: ABCIResponse = adaptAbciQueryResponse(rpcResponse);\n return extractAccountFromResponse(abciResponse.response.ResponseBase.Data);\n }\n\n async getStatus(): Promise<Status> {\n const rpcResponse = await this.client.status();\n return adaptStatusResponse(rpcResponse);\n }\n\n async getTransaction(hash: string): Promise<TxResult> {\n const hashBytes = Uint8Array.from(\n (hash.match(/.{1,2}/g) ?? []).map(byte => parseInt(byte, 16)),\n );\n const rpcResponse = await this.client.tx({\n hash: hashBytes,\n });\n return adaptTxResponse(rpcResponse);\n }\n\n async sendTransaction<K extends keyof BroadcastTransactionMap>(\n tx: string,\n endpoint: K,\n ): Promise<BroadcastTransactionMap[K][\"result\"]> {\n const txBytes = Uint8Array.from(Buffer.from(tx, \"base64\"));\n\n switch (endpoint) {\n case TransactionEndpoint.BROADCAST_TX_COMMIT:\n return this.broadcastTxCommit(txBytes);\n case TransactionEndpoint.BROADCAST_TX_SYNC:\n default:\n return this.broadcastTxSync(txBytes);\n }\n }\n\n private async broadcastTxSync(\n txBytes: Uint8Array,\n ): Promise<BroadcastTxSyncResult> {\n const rpcResponse = await this.client.broadcastTxSync({\n tx: txBytes,\n });\n const response = adaptBroadcastTxSyncResponse(rpcResponse);\n\n if (response.error) {\n const errType: string = response.error[ABCIErrorKey];\n const log: string = response.Log;\n\n throw constructRequestError(errType, log);\n }\n\n return response;\n }\n\n private async broadcastTxCommit(\n txBytes: Uint8Array,\n ): Promise<BroadcastTxCommitResult> {\n const rpcResponse = await this.client.broadcastTxCommit({\n tx: txBytes,\n });\n const response = adaptBroadcastTxCommitResponse(rpcResponse);\n\n const {\n check_tx, deliver_tx,\n } = response;\n\n if (check_tx.ResponseBase.Error) {\n const errType: string = check_tx.ResponseBase.Error[ABCIErrorKey];\n const log: string = check_tx.ResponseBase.Log;\n\n throw constructRequestError(errType, log);\n }\n\n if (deliver_tx.ResponseBase.Error) {\n const errType: string = deliver_tx.ResponseBase.Error[ABCIErrorKey];\n const log: string = deliver_tx.ResponseBase.Log;\n\n throw constructRequestError(errType, log);\n }\n\n return response;\n }\n\n async waitForTransaction(\n hash: string,\n fromHeight?: number,\n timeout?: number,\n ): Promise<Tx> {\n return waitForTransaction(this, hash, fromHeight, timeout);\n }\n}\n"],"mappings":"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"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ABCIAccount, ABCIErrorKey, ABCIResponse, ABCIResponseBase } from "./abci.cjs";
|
|
2
|
+
import { BeginBlock, Block, BlockHeader, BlockID, BlockInfo, BlockMeta, BlockResult, BroadcastAsGeneric, BroadcastTransactionCommit, BroadcastTransactionMap, BroadcastTransactionSync, BroadcastTxCommitResult, BroadcastTxSyncResult, BroadcastType, ConsensusParams, ConsensusState, DeliverTx, EndBlock, NetworkInfo, PrecommitInfo, Status, TxResult } from "./common.cjs";
|
|
3
|
+
import { RPCError, RPCRequest, RPCResponse } from "./jsonrpc.cjs";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ABCIAccount, ABCIErrorKey, ABCIResponse, ABCIResponseBase } from "./abci.mjs";
|
|
2
|
+
import { BeginBlock, Block, BlockHeader, BlockID, BlockInfo, BlockMeta, BlockResult, BroadcastAsGeneric, BroadcastTransactionCommit, BroadcastTransactionMap, BroadcastTransactionSync, BroadcastTxCommitResult, BroadcastTxSyncResult, BroadcastType, ConsensusParams, ConsensusState, DeliverTx, EndBlock, NetworkInfo, PrecommitInfo, Status, TxResult } from "./common.mjs";
|
|
3
|
+
import { RPCError, RPCRequest, RPCResponse } from "./jsonrpc.mjs";
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.utility.cjs","names":["InternalError","TxDecodeError","InvalidSequenceError","UnauthorizedError","InsufficientFundsError","UnknownRequestError","InvalidAddressError","UnknownAddressError","InvalidPubKeyError","InsufficientCoinsError","InvalidCoinsError","InvalidGasWantedError","OutOfGasError","MemoTooLargeError","InsufficientFeeError","TooManySignaturesError","NoSignaturesError","GasOverflowError","TM2Error"],"sources":["../../../src/provider/utility/errors.utility.ts"],"sourcesContent":["import {\n GasOverflowError,\n InsufficientCoinsError,\n InsufficientFeeError,\n InsufficientFundsError,\n InternalError,\n InvalidAddressError,\n InvalidCoinsError,\n InvalidGasWantedError,\n InvalidPubKeyError,\n InvalidSequenceError,\n MemoTooLargeError,\n NoSignaturesError,\n OutOfGasError,\n TM2Error,\n TooManySignaturesError,\n TxDecodeError,\n UnauthorizedError,\n UnknownAddressError,\n UnknownRequestError,\n} from \"../errors/index.js\";\n\n/**\n * Constructs the appropriate Tendermint2\n * error based on the error ID.\n * Error IDs retrieved from:\n * https://github.com/gnolang/gno/blob/64f0fd0fa44021a076e1453b1767fbc914ed3b66/tm2/pkg/std/package.go#L20C1-L38\n * @param {string} errorID the proto ID of the error\n * @param {string} [log] the log associated with the error, if any\n * @returns {TM2Error}\n */\nexport const constructRequestError = (\n errorID: string,\n log?: string,\n): TM2Error => {\n switch (errorID) {\n case \"/std.InternalError\":\n return new InternalError(log);\n case \"/std.TxDecodeError\":\n return new TxDecodeError(log);\n case \"/std.InvalidSequenceError\":\n return new InvalidSequenceError(log);\n case \"/std.UnauthorizedError\":\n return new UnauthorizedError(log);\n case \"/std.InsufficientFundsError\":\n return new InsufficientFundsError(log);\n case \"/std.UnknownRequestError\":\n return new UnknownRequestError(log);\n case \"/std.InvalidAddressError\":\n return new InvalidAddressError(log);\n case \"/std.UnknownAddressError\":\n return new UnknownAddressError(log);\n case \"/std.InvalidPubKeyError\":\n return new InvalidPubKeyError(log);\n case \"/std.InsufficientCoinsError\":\n return new InsufficientCoinsError(log);\n case \"/std.InvalidCoinsError\":\n return new InvalidCoinsError(log);\n case \"/std.InvalidGasWantedError\":\n return new InvalidGasWantedError(log);\n case \"/std.OutOfGasError\":\n return new OutOfGasError(log);\n case \"/std.MemoTooLargeError\":\n return new MemoTooLargeError(log);\n case \"/std.InsufficientFeeError\":\n return new InsufficientFeeError(log);\n case \"/std.TooManySignaturesError\":\n return new TooManySignaturesError(log);\n case \"/std.NoSignaturesError\":\n return new NoSignaturesError(log);\n case \"/std.GasOverflowError\":\n return new GasOverflowError(log);\n default:\n return new TM2Error(`unknown error: ${errorID}`, log);\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.utility.cjs","names":["InternalError","TxDecodeError","InvalidSequenceError","UnauthorizedError","InsufficientFundsError","UnknownRequestError","InvalidAddressError","UnknownAddressError","InvalidPubKeyError","InsufficientCoinsError","InvalidCoinsError","InvalidGasWantedError","OutOfGasError","MemoTooLargeError","InsufficientFeeError","TooManySignaturesError","NoSignaturesError","GasOverflowError","TM2Error"],"sources":["../../../src/provider/utility/errors.utility.ts"],"sourcesContent":["import {\n GasOverflowError,\n InsufficientCoinsError,\n InsufficientFeeError,\n InsufficientFundsError,\n InternalError,\n InvalidAddressError,\n InvalidCoinsError,\n InvalidGasWantedError,\n InvalidPubKeyError,\n InvalidSequenceError,\n MemoTooLargeError,\n NoSignaturesError,\n OutOfGasError,\n TM2Error,\n TooManySignaturesError,\n TxDecodeError,\n UnauthorizedError,\n UnknownAddressError,\n UnknownRequestError,\n} from \"../errors/index.js\";\n\n/**\n * Constructs the appropriate Tendermint2\n * error based on the error ID.\n * Error IDs retrieved from:\n * https://github.com/gnolang/gno/blob/64f0fd0fa44021a076e1453b1767fbc914ed3b66/tm2/pkg/std/package.go#L20C1-L38\n * @param {string} errorID the proto ID of the error\n * @param {string} [log] the log associated with the error, if any\n * @returns {TM2Error}\n */\nexport const constructRequestError = (\n errorID: string,\n log?: string,\n): TM2Error => {\n switch (errorID) {\n case \"/std.InternalError\":\n return new InternalError(log);\n case \"/std.TxDecodeError\":\n return new TxDecodeError(log);\n case \"/std.InvalidSequenceError\":\n return new InvalidSequenceError(log);\n case \"/std.UnauthorizedError\":\n return new UnauthorizedError(log);\n case \"/std.InsufficientFundsError\":\n return new InsufficientFundsError(log);\n case \"/std.UnknownRequestError\":\n return new UnknownRequestError(log);\n case \"/std.InvalidAddressError\":\n return new InvalidAddressError(log);\n case \"/std.UnknownAddressError\":\n return new UnknownAddressError(log);\n case \"/std.InvalidPubKeyError\":\n return new InvalidPubKeyError(log);\n case \"/std.InsufficientCoinsError\":\n return new InsufficientCoinsError(log);\n case \"/std.InvalidCoinsError\":\n return new InvalidCoinsError(log);\n case \"/std.InvalidGasWantedError\":\n return new InvalidGasWantedError(log);\n case \"/std.OutOfGasError\":\n return new OutOfGasError(log);\n case \"/std.MemoTooLargeError\":\n return new MemoTooLargeError(log);\n case \"/std.InsufficientFeeError\":\n return new InsufficientFeeError(log);\n case \"/std.TooManySignaturesError\":\n return new TooManySignaturesError(log);\n case \"/std.NoSignaturesError\":\n return new NoSignaturesError(log);\n case \"/std.GasOverflowError\":\n return new GasOverflowError(log);\n default:\n return new TM2Error(`unknown error: ${errorID}`, log);\n }\n};\n"],"mappings":";;;;;;;;;;;;AA+BA,MAAa,yBACX,SACA,QACa;AACb,SAAQ,SAAR;EACE,KAAK,qBACH,QAAO,IAAIA,eAAAA,cAAc,IAAI;EAC/B,KAAK,qBACH,QAAO,IAAIC,eAAAA,cAAc,IAAI;EAC/B,KAAK,4BACH,QAAO,IAAIC,eAAAA,qBAAqB,IAAI;EACtC,KAAK,yBACH,QAAO,IAAIC,eAAAA,kBAAkB,IAAI;EACnC,KAAK,8BACH,QAAO,IAAIC,eAAAA,uBAAuB,IAAI;EACxC,KAAK,2BACH,QAAO,IAAIC,eAAAA,oBAAoB,IAAI;EACrC,KAAK,2BACH,QAAO,IAAIC,eAAAA,oBAAoB,IAAI;EACrC,KAAK,2BACH,QAAO,IAAIC,eAAAA,oBAAoB,IAAI;EACrC,KAAK,0BACH,QAAO,IAAIC,eAAAA,mBAAmB,IAAI;EACpC,KAAK,8BACH,QAAO,IAAIC,eAAAA,uBAAuB,IAAI;EACxC,KAAK,yBACH,QAAO,IAAIC,eAAAA,kBAAkB,IAAI;EACnC,KAAK,6BACH,QAAO,IAAIC,eAAAA,sBAAsB,IAAI;EACvC,KAAK,qBACH,QAAO,IAAIC,eAAAA,cAAc,IAAI;EAC/B,KAAK,yBACH,QAAO,IAAIC,eAAAA,kBAAkB,IAAI;EACnC,KAAK,4BACH,QAAO,IAAIC,eAAAA,qBAAqB,IAAI;EACtC,KAAK,8BACH,QAAO,IAAIC,eAAAA,uBAAuB,IAAI;EACxC,KAAK,yBACH,QAAO,IAAIC,eAAAA,kBAAkB,IAAI;EACnC,KAAK,wBACH,QAAO,IAAIC,eAAAA,iBAAiB,IAAI;EAClC,QACE,QAAO,IAAIC,eAAAA,SAAS,kBAAkB,WAAW,IAAI"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GasOverflowError, InsufficientCoinsError, InsufficientFeeError, InsufficientFundsError, InternalError, InvalidAddressError, InvalidCoinsError, InvalidGasWantedError, InvalidPubKeyError, InvalidSequenceError, MemoTooLargeError, NoSignaturesError, OutOfGasError, TM2Error, TooManySignaturesError, TxDecodeError, UnauthorizedError, UnknownAddressError, UnknownRequestError } from "../errors/errors.mjs";
|
|
2
|
+
import "../errors/index.mjs";
|
|
2
3
|
//#region src/provider/utility/errors.utility.ts
|
|
3
4
|
/**
|
|
4
5
|
* Constructs the appropriate Tendermint2
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.utility.mjs","names":[],"sources":["../../../src/provider/utility/errors.utility.ts"],"sourcesContent":["import {\n GasOverflowError,\n InsufficientCoinsError,\n InsufficientFeeError,\n InsufficientFundsError,\n InternalError,\n InvalidAddressError,\n InvalidCoinsError,\n InvalidGasWantedError,\n InvalidPubKeyError,\n InvalidSequenceError,\n MemoTooLargeError,\n NoSignaturesError,\n OutOfGasError,\n TM2Error,\n TooManySignaturesError,\n TxDecodeError,\n UnauthorizedError,\n UnknownAddressError,\n UnknownRequestError,\n} from \"../errors/index.js\";\n\n/**\n * Constructs the appropriate Tendermint2\n * error based on the error ID.\n * Error IDs retrieved from:\n * https://github.com/gnolang/gno/blob/64f0fd0fa44021a076e1453b1767fbc914ed3b66/tm2/pkg/std/package.go#L20C1-L38\n * @param {string} errorID the proto ID of the error\n * @param {string} [log] the log associated with the error, if any\n * @returns {TM2Error}\n */\nexport const constructRequestError = (\n errorID: string,\n log?: string,\n): TM2Error => {\n switch (errorID) {\n case \"/std.InternalError\":\n return new InternalError(log);\n case \"/std.TxDecodeError\":\n return new TxDecodeError(log);\n case \"/std.InvalidSequenceError\":\n return new InvalidSequenceError(log);\n case \"/std.UnauthorizedError\":\n return new UnauthorizedError(log);\n case \"/std.InsufficientFundsError\":\n return new InsufficientFundsError(log);\n case \"/std.UnknownRequestError\":\n return new UnknownRequestError(log);\n case \"/std.InvalidAddressError\":\n return new InvalidAddressError(log);\n case \"/std.UnknownAddressError\":\n return new UnknownAddressError(log);\n case \"/std.InvalidPubKeyError\":\n return new InvalidPubKeyError(log);\n case \"/std.InsufficientCoinsError\":\n return new InsufficientCoinsError(log);\n case \"/std.InvalidCoinsError\":\n return new InvalidCoinsError(log);\n case \"/std.InvalidGasWantedError\":\n return new InvalidGasWantedError(log);\n case \"/std.OutOfGasError\":\n return new OutOfGasError(log);\n case \"/std.MemoTooLargeError\":\n return new MemoTooLargeError(log);\n case \"/std.InsufficientFeeError\":\n return new InsufficientFeeError(log);\n case \"/std.TooManySignaturesError\":\n return new TooManySignaturesError(log);\n case \"/std.NoSignaturesError\":\n return new NoSignaturesError(log);\n case \"/std.GasOverflowError\":\n return new GasOverflowError(log);\n default:\n return new TM2Error(`unknown error: ${errorID}`, log);\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.utility.mjs","names":[],"sources":["../../../src/provider/utility/errors.utility.ts"],"sourcesContent":["import {\n GasOverflowError,\n InsufficientCoinsError,\n InsufficientFeeError,\n InsufficientFundsError,\n InternalError,\n InvalidAddressError,\n InvalidCoinsError,\n InvalidGasWantedError,\n InvalidPubKeyError,\n InvalidSequenceError,\n MemoTooLargeError,\n NoSignaturesError,\n OutOfGasError,\n TM2Error,\n TooManySignaturesError,\n TxDecodeError,\n UnauthorizedError,\n UnknownAddressError,\n UnknownRequestError,\n} from \"../errors/index.js\";\n\n/**\n * Constructs the appropriate Tendermint2\n * error based on the error ID.\n * Error IDs retrieved from:\n * https://github.com/gnolang/gno/blob/64f0fd0fa44021a076e1453b1767fbc914ed3b66/tm2/pkg/std/package.go#L20C1-L38\n * @param {string} errorID the proto ID of the error\n * @param {string} [log] the log associated with the error, if any\n * @returns {TM2Error}\n */\nexport const constructRequestError = (\n errorID: string,\n log?: string,\n): TM2Error => {\n switch (errorID) {\n case \"/std.InternalError\":\n return new InternalError(log);\n case \"/std.TxDecodeError\":\n return new TxDecodeError(log);\n case \"/std.InvalidSequenceError\":\n return new InvalidSequenceError(log);\n case \"/std.UnauthorizedError\":\n return new UnauthorizedError(log);\n case \"/std.InsufficientFundsError\":\n return new InsufficientFundsError(log);\n case \"/std.UnknownRequestError\":\n return new UnknownRequestError(log);\n case \"/std.InvalidAddressError\":\n return new InvalidAddressError(log);\n case \"/std.UnknownAddressError\":\n return new UnknownAddressError(log);\n case \"/std.InvalidPubKeyError\":\n return new InvalidPubKeyError(log);\n case \"/std.InsufficientCoinsError\":\n return new InsufficientCoinsError(log);\n case \"/std.InvalidCoinsError\":\n return new InvalidCoinsError(log);\n case \"/std.InvalidGasWantedError\":\n return new InvalidGasWantedError(log);\n case \"/std.OutOfGasError\":\n return new OutOfGasError(log);\n case \"/std.MemoTooLargeError\":\n return new MemoTooLargeError(log);\n case \"/std.InsufficientFeeError\":\n return new InsufficientFeeError(log);\n case \"/std.TooManySignaturesError\":\n return new TooManySignaturesError(log);\n case \"/std.NoSignaturesError\":\n return new NoSignaturesError(log);\n case \"/std.GasOverflowError\":\n return new GasOverflowError(log);\n default:\n return new TM2Error(`unknown error: ${errorID}`, log);\n }\n};\n"],"mappings":";;;;;;;;;;;;AA+BA,MAAa,yBACX,SACA,QACa;AACb,SAAQ,SAAR;EACE,KAAK,qBACH,QAAO,IAAI,cAAc,IAAI;EAC/B,KAAK,qBACH,QAAO,IAAI,cAAc,IAAI;EAC/B,KAAK,4BACH,QAAO,IAAI,qBAAqB,IAAI;EACtC,KAAK,yBACH,QAAO,IAAI,kBAAkB,IAAI;EACnC,KAAK,8BACH,QAAO,IAAI,uBAAuB,IAAI;EACxC,KAAK,2BACH,QAAO,IAAI,oBAAoB,IAAI;EACrC,KAAK,2BACH,QAAO,IAAI,oBAAoB,IAAI;EACrC,KAAK,2BACH,QAAO,IAAI,oBAAoB,IAAI;EACrC,KAAK,0BACH,QAAO,IAAI,mBAAmB,IAAI;EACpC,KAAK,8BACH,QAAO,IAAI,uBAAuB,IAAI;EACxC,KAAK,yBACH,QAAO,IAAI,kBAAkB,IAAI;EACnC,KAAK,6BACH,QAAO,IAAI,sBAAsB,IAAI;EACvC,KAAK,qBACH,QAAO,IAAI,cAAc,IAAI;EAC/B,KAAK,yBACH,QAAO,IAAI,kBAAkB,IAAI;EACnC,KAAK,4BACH,QAAO,IAAI,qBAAqB,IAAI;EACtC,KAAK,8BACH,QAAO,IAAI,uBAAuB,IAAI;EACxC,KAAK,yBACH,QAAO,IAAI,kBAAkB,IAAI;EACnC,KAAK,wBACH,QAAO,IAAI,iBAAiB,IAAI;EAClC,QACE,QAAO,IAAI,SAAS,kBAAkB,WAAW,IAAI"}
|
|
@@ -2,6 +2,7 @@ require("../../_virtual/_rolldown/runtime.cjs");
|
|
|
2
2
|
const require_tx = require("../../proto/tm2/tx.cjs");
|
|
3
3
|
require("../../proto/index.cjs");
|
|
4
4
|
const require_abci = require("../types/abci.cjs");
|
|
5
|
+
require("../types/index.cjs");
|
|
5
6
|
const require_errors_utility = require("./errors.utility.cjs");
|
|
6
7
|
const require_abci$1 = require("../../proto/tm2/abci.cjs");
|
|
7
8
|
const require_requests_utility = require("./requests.utility.cjs");
|
|
@@ -97,7 +98,8 @@ const waitForTransaction = async (provider, hash, fromHeight, timeout) => {
|
|
|
97
98
|
if (!block.block.data.txs || block.block.data.txs.length == 0) continue;
|
|
98
99
|
for (const tx of block.block.data.txs) {
|
|
99
100
|
const txRaw = require_requests_utility.base64ToUint8Array(tx);
|
|
100
|
-
|
|
101
|
+
const txHash = (0, _cosmjs_crypto.sha256)(txRaw);
|
|
102
|
+
if (require_requests_utility.uint8ArrayToBase64(txHash) == hash) {
|
|
101
103
|
clearInterval(fetchInterval);
|
|
102
104
|
resolve(require_tx.Tx.decode(txRaw));
|
|
103
105
|
}
|
|
@@ -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,yBAAAA,UAAuB,SAAS;AAE7D,SAAO,SAAS,QAAQ,YAAY,gBAAgB,GAAG;UAElD,GAAG;AACR,QAAM,IAAI,MAAM,8BAA8B,EAC5C,OAAO,GACR,CAAC;;;;;;;AAQN,MAAa,8BACX,aACgB;AAEhB,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,6BAA6B;AAG/C,KAAI;AAIF,SAF6BA,yBAAAA,UAAuB,SAAS;UAIxD,GAAG;AACR,QAAM,IAAI,MAAM,8BAA8B,EAC5C,OAAO,GACR,CAAC;;;;;;;AAQN,MAAa,+BACX,iBACsB;AAEtB,KAAI,CAAC,aACH,OAAM,IAAI,MAAM,+BAA+B;CAGjD,MAAM,QAAQ,aAAa,UAAU,cAAc;AACnD,KAAI,SAAS,MAAA,SACX,OAAMC,uBAAAA,sBAAsB,MAAMC,aAAAA,cAAc;CAGlD,MAAM,QAAQ,aAAa,SAAS;AACpC,KAAI,CAAC,MACH,OAAM,IAAI,MAAM,+BAA+B;AAGjD,KAAI;AACF,SAAOC,yBAAAA,WAAW,OAAOC,eAAAA,kBAAkB,OAAO;UAE7C,GAAG;AACR,QAAM,IAAI,MAAM,qCAAqC,EACnD,OAAO,GACR,CAAC;;;;;;;;;;;;AAaN,MAAa,qBAAqB,OAChC,UACA,MACA,YACA,YACgB;CAEhB,IAAI,gBAAgB,aAChB,aACA,MAAM,SAAS,gBAAgB;AAEnC,QAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,cAAc,UAAU,UAAU;EAExC,MAAM,gBAAgB,YAAY,YAAY;GAE5C,MAAM,eAAe,MAAM,SAAS,gBAAgB;AAEpD,OAAI,eAAe,cAEjB;AAGF,QAAK,IAAI,WAAW,eAAe,YAAY,cAAc,YAAY;IAEvE,MAAM,QAAmB,MAAM,SAAS,SAAS,SAAS;AAG1D,QAAI,CAAC,MAAM,MAAM,KAAK,OAAO,MAAM,MAAM,KAAK,IAAI,UAAU,EAC1D;AAIF,SAAK,MAAM,MAAM,MAAM,MAAM,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,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,UAAuB,UAAuB,SAAS;AAE7D,SAAO,SAAS,QAAQ,YAAY,gBAAgB,GAAG;UAElD,GAAG;AACR,QAAM,IAAI,MAAM,8BAA8B,EAC5C,OAAO,GACR,CAAC;;;;;;;AAQN,MAAa,8BACX,aACgB;AAEhB,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,6BAA6B;AAG/C,KAAI;AAIF,SAF6B,UAAuB,SAAS;UAIxD,GAAG;AACR,QAAM,IAAI,MAAM,8BAA8B,EAC5C,OAAO,GACR,CAAC;;;;;;;AAQN,MAAa,+BACX,iBACsB;AAEtB,KAAI,CAAC,aACH,OAAM,IAAI,MAAM,+BAA+B;CAGjD,MAAM,QAAQ,aAAa,UAAU,cAAc;AACnD,KAAI,SAAS,MAAA,SACX,OAAM,sBAAsB,MAAM,cAAc;CAGlD,MAAM,QAAQ,aAAa,SAAS;AACpC,KAAI,CAAC,MACH,OAAM,IAAI,MAAM,+BAA+B;AAGjD,KAAI;AACF,SAAO,WAAW,OAAO,kBAAkB,OAAO;UAE7C,GAAG;AACR,QAAM,IAAI,MAAM,qCAAqC,EACnD,OAAO,GACR,CAAC;;;;;;;;;;;;AAaN,MAAa,qBAAqB,OAChC,UACA,MACA,YACA,YACgB;CAEhB,IAAI,gBAAgB,aAChB,aACA,MAAM,SAAS,gBAAgB;AAEnC,QAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,cAAc,UAAU,UAAU;EAExC,MAAM,gBAAgB,YAAY,YAAY;GAE5C,MAAM,eAAe,MAAM,SAAS,gBAAgB;AAEpD,OAAI,eAAe,cAEjB;AAGF,QAAK,IAAI,WAAW,eAAe,YAAY,cAAc,YAAY;IAEvE,MAAM,QAAmB,MAAM,SAAS,SAAS,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,55 @@
|
|
|
1
|
+
//#region src/utility/compact-bit-array.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts an amino-encoded compact bit array string to a CompactBitArray.
|
|
4
|
+
* In the amino format, 'x' represents a set bit (1) and '_' represents
|
|
5
|
+
* an unset bit (0). A null input produces an empty CompactBitArray.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* compactBitArrayFromAmino("xx___") // { extra_bits_stored: 5, elems: Uint8Array([0xC0]) }
|
|
9
|
+
* compactBitArrayFromAmino(null) // { extra_bits_stored: 0, elems: Uint8Array([]) }
|
|
10
|
+
*/
|
|
11
|
+
function compactBitArrayFromAmino(amino) {
|
|
12
|
+
if (amino === null) return {
|
|
13
|
+
extra_bits_stored: 0,
|
|
14
|
+
elems: new Uint8Array(0)
|
|
15
|
+
};
|
|
16
|
+
const count = amino.length;
|
|
17
|
+
const extraBits = count % 8;
|
|
18
|
+
const numBytes = Math.ceil(count / 8);
|
|
19
|
+
const elems = new Uint8Array(numBytes);
|
|
20
|
+
for (let i = 0; i < count; i++) if (amino[i] === "x") {
|
|
21
|
+
const byteIndex = Math.floor(i / 8);
|
|
22
|
+
const bitIndex = 7 - i % 8;
|
|
23
|
+
elems[byteIndex] |= 1 << bitIndex;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
extra_bits_stored: extraBits,
|
|
27
|
+
elems
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts a CompactBitArray to its amino string representation.
|
|
32
|
+
* Set bits (1) become 'x' and unset bits (0) become '_'.
|
|
33
|
+
* Returns null for empty bit arrays (zero length).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* compactBitArrayToAmino({ extra_bits_stored: 5, elems: Uint8Array([0xC0]) }) // "xx___"
|
|
37
|
+
* compactBitArrayToAmino({ extra_bits_stored: 0, elems: Uint8Array([]) }) // null
|
|
38
|
+
*/
|
|
39
|
+
function compactBitArrayToAmino(cba) {
|
|
40
|
+
if (cba.elems.length === 0) return null;
|
|
41
|
+
const totalBits = (cba.extra_bits_stored === 0 ? cba.elems.length : cba.elems.length - 1) * 8 + cba.extra_bits_stored;
|
|
42
|
+
let result = "";
|
|
43
|
+
for (let i = 0; i < totalBits; i++) {
|
|
44
|
+
const byteIndex = Math.floor(i / 8);
|
|
45
|
+
const bitIndex = 7 - i % 8;
|
|
46
|
+
const isSet = (cba.elems[byteIndex] & 1 << bitIndex) !== 0;
|
|
47
|
+
result += isSet ? "x" : "_";
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
exports.compactBitArrayFromAmino = compactBitArrayFromAmino;
|
|
53
|
+
exports.compactBitArrayToAmino = compactBitArrayToAmino;
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=compact-bit-array.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-bit-array.cjs","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"sourcesContent":["import type {\n CompactBitArray,\n} from \"../proto/tm2/multisig.js\";\n\n/**\n * Converts an amino-encoded compact bit array string to a CompactBitArray.\n * In the amino format, 'x' represents a set bit (1) and '_' represents\n * an unset bit (0). A null input produces an empty CompactBitArray.\n *\n * @example\n * compactBitArrayFromAmino(\"xx___\") // { extra_bits_stored: 5, elems: Uint8Array([0xC0]) }\n * compactBitArrayFromAmino(null) // { extra_bits_stored: 0, elems: Uint8Array([]) }\n */\nexport function compactBitArrayFromAmino(\n amino: string | null,\n): CompactBitArray {\n if (amino === null) {\n return {\n extra_bits_stored: 0,\n elems: new Uint8Array(0),\n };\n }\n\n const count = amino.length;\n const extraBits = count % 8;\n const numBytes = Math.ceil(count / 8);\n const elems = new Uint8Array(numBytes);\n\n for (let i = 0; i < count; i++) {\n if (amino[i] === \"x\") {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n elems[byteIndex] |= 1 << bitIndex;\n }\n }\n\n return {\n extra_bits_stored: extraBits,\n elems,\n };\n}\n\n/**\n * Converts a CompactBitArray to its amino string representation.\n * Set bits (1) become 'x' and unset bits (0) become '_'.\n * Returns null for empty bit arrays (zero length).\n *\n * @example\n * compactBitArrayToAmino({ extra_bits_stored: 5, elems: Uint8Array([0xC0]) }) // \"xx___\"\n * compactBitArrayToAmino({ extra_bits_stored: 0, elems: Uint8Array([]) }) // null\n */\nexport function compactBitArrayToAmino(\n cba: CompactBitArray,\n): string | null {\n if (cba.elems.length === 0) {\n return null;\n }\n\n const fullBytes = cba.extra_bits_stored === 0\n ? cba.elems.length\n : cba.elems.length - 1;\n const totalBits = fullBytes * 8 + cba.extra_bits_stored;\n\n let result = \"\";\n for (let i = 0; i < totalBits; i++) {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n const isSet = (cba.elems[byteIndex] & (1 << bitIndex)) !== 0;\n result += isSet ? \"x\" : \"_\";\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,yBACd,OACiB;AACjB,KAAI,UAAU,KACZ,QAAO;EACL,mBAAmB;EACnB,OAAO,IAAI,WAAW,EAAE;EACzB;CAGH,MAAM,QAAQ,MAAM;CACpB,MAAM,YAAY,QAAQ;CAC1B,MAAM,WAAW,KAAK,KAAK,QAAQ,EAAE;CACrC,MAAM,QAAQ,IAAI,WAAW,SAAS;AAEtC,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,IACzB,KAAI,MAAM,OAAO,KAAK;EACpB,MAAM,YAAY,KAAK,MAAM,IAAI,EAAE;EACnC,MAAM,WAAW,IAAK,IAAI;AAC1B,QAAM,cAAc,KAAK;;AAI7B,QAAO;EACL,mBAAmB;EACnB;EACD;;;;;;;;;;;AAYH,SAAgB,uBACd,KACe;AACf,KAAI,IAAI,MAAM,WAAW,EACvB,QAAO;CAMT,MAAM,aAHY,IAAI,sBAAsB,IACxC,IAAI,MAAM,SACV,IAAI,MAAM,SAAS,KACO,IAAI,IAAI;CAEtC,IAAI,SAAS;AACb,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,KAAK;EAClC,MAAM,YAAY,KAAK,MAAM,IAAI,EAAE;EACnC,MAAM,WAAW,IAAK,IAAI;EAC1B,MAAM,SAAS,IAAI,MAAM,aAAc,KAAK,cAAe;AAC3D,YAAU,QAAQ,MAAM;;AAG1B,QAAO"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CompactBitArray } from "../proto/tm2/multisig.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utility/compact-bit-array.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts an amino-encoded compact bit array string to a CompactBitArray.
|
|
6
|
+
* In the amino format, 'x' represents a set bit (1) and '_' represents
|
|
7
|
+
* an unset bit (0). A null input produces an empty CompactBitArray.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* compactBitArrayFromAmino("xx___") // { extra_bits_stored: 5, elems: Uint8Array([0xC0]) }
|
|
11
|
+
* compactBitArrayFromAmino(null) // { extra_bits_stored: 0, elems: Uint8Array([]) }
|
|
12
|
+
*/
|
|
13
|
+
declare function compactBitArrayFromAmino(amino: string | null): CompactBitArray;
|
|
14
|
+
/**
|
|
15
|
+
* Converts a CompactBitArray to its amino string representation.
|
|
16
|
+
* Set bits (1) become 'x' and unset bits (0) become '_'.
|
|
17
|
+
* Returns null for empty bit arrays (zero length).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* compactBitArrayToAmino({ extra_bits_stored: 5, elems: Uint8Array([0xC0]) }) // "xx___"
|
|
21
|
+
* compactBitArrayToAmino({ extra_bits_stored: 0, elems: Uint8Array([]) }) // null
|
|
22
|
+
*/
|
|
23
|
+
declare function compactBitArrayToAmino(cba: CompactBitArray): string | null;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { compactBitArrayFromAmino, compactBitArrayToAmino };
|
|
26
|
+
//# sourceMappingURL=compact-bit-array.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-bit-array.d.cts","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"mappings":";;;;;AAaA;;;;;AAsCA;;iBAtCgB,wBAAA,CACd,KAAA,kBACC,eAAA;;;;;;;;;;iBAoCa,sBAAA,CACd,GAAA,EAAK,eAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CompactBitArray } from "../proto/tm2/multisig.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utility/compact-bit-array.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts an amino-encoded compact bit array string to a CompactBitArray.
|
|
6
|
+
* In the amino format, 'x' represents a set bit (1) and '_' represents
|
|
7
|
+
* an unset bit (0). A null input produces an empty CompactBitArray.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* compactBitArrayFromAmino("xx___") // { extra_bits_stored: 5, elems: Uint8Array([0xC0]) }
|
|
11
|
+
* compactBitArrayFromAmino(null) // { extra_bits_stored: 0, elems: Uint8Array([]) }
|
|
12
|
+
*/
|
|
13
|
+
declare function compactBitArrayFromAmino(amino: string | null): CompactBitArray;
|
|
14
|
+
/**
|
|
15
|
+
* Converts a CompactBitArray to its amino string representation.
|
|
16
|
+
* Set bits (1) become 'x' and unset bits (0) become '_'.
|
|
17
|
+
* Returns null for empty bit arrays (zero length).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* compactBitArrayToAmino({ extra_bits_stored: 5, elems: Uint8Array([0xC0]) }) // "xx___"
|
|
21
|
+
* compactBitArrayToAmino({ extra_bits_stored: 0, elems: Uint8Array([]) }) // null
|
|
22
|
+
*/
|
|
23
|
+
declare function compactBitArrayToAmino(cba: CompactBitArray): string | null;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { compactBitArrayFromAmino, compactBitArrayToAmino };
|
|
26
|
+
//# sourceMappingURL=compact-bit-array.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-bit-array.d.mts","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"mappings":";;;;;AAaA;;;;;AAsCA;;iBAtCgB,wBAAA,CACd,KAAA,kBACC,eAAA;;;;;;;;;;iBAoCa,sBAAA,CACd,GAAA,EAAK,eAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region src/utility/compact-bit-array.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts an amino-encoded compact bit array string to a CompactBitArray.
|
|
4
|
+
* In the amino format, 'x' represents a set bit (1) and '_' represents
|
|
5
|
+
* an unset bit (0). A null input produces an empty CompactBitArray.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* compactBitArrayFromAmino("xx___") // { extra_bits_stored: 5, elems: Uint8Array([0xC0]) }
|
|
9
|
+
* compactBitArrayFromAmino(null) // { extra_bits_stored: 0, elems: Uint8Array([]) }
|
|
10
|
+
*/
|
|
11
|
+
function compactBitArrayFromAmino(amino) {
|
|
12
|
+
if (amino === null) return {
|
|
13
|
+
extra_bits_stored: 0,
|
|
14
|
+
elems: new Uint8Array(0)
|
|
15
|
+
};
|
|
16
|
+
const count = amino.length;
|
|
17
|
+
const extraBits = count % 8;
|
|
18
|
+
const numBytes = Math.ceil(count / 8);
|
|
19
|
+
const elems = new Uint8Array(numBytes);
|
|
20
|
+
for (let i = 0; i < count; i++) if (amino[i] === "x") {
|
|
21
|
+
const byteIndex = Math.floor(i / 8);
|
|
22
|
+
const bitIndex = 7 - i % 8;
|
|
23
|
+
elems[byteIndex] |= 1 << bitIndex;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
extra_bits_stored: extraBits,
|
|
27
|
+
elems
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts a CompactBitArray to its amino string representation.
|
|
32
|
+
* Set bits (1) become 'x' and unset bits (0) become '_'.
|
|
33
|
+
* Returns null for empty bit arrays (zero length).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* compactBitArrayToAmino({ extra_bits_stored: 5, elems: Uint8Array([0xC0]) }) // "xx___"
|
|
37
|
+
* compactBitArrayToAmino({ extra_bits_stored: 0, elems: Uint8Array([]) }) // null
|
|
38
|
+
*/
|
|
39
|
+
function compactBitArrayToAmino(cba) {
|
|
40
|
+
if (cba.elems.length === 0) return null;
|
|
41
|
+
const totalBits = (cba.extra_bits_stored === 0 ? cba.elems.length : cba.elems.length - 1) * 8 + cba.extra_bits_stored;
|
|
42
|
+
let result = "";
|
|
43
|
+
for (let i = 0; i < totalBits; i++) {
|
|
44
|
+
const byteIndex = Math.floor(i / 8);
|
|
45
|
+
const bitIndex = 7 - i % 8;
|
|
46
|
+
const isSet = (cba.elems[byteIndex] & 1 << bitIndex) !== 0;
|
|
47
|
+
result += isSet ? "x" : "_";
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { compactBitArrayFromAmino, compactBitArrayToAmino };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=compact-bit-array.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact-bit-array.mjs","names":[],"sources":["../../src/utility/compact-bit-array.ts"],"sourcesContent":["import type {\n CompactBitArray,\n} from \"../proto/tm2/multisig.js\";\n\n/**\n * Converts an amino-encoded compact bit array string to a CompactBitArray.\n * In the amino format, 'x' represents a set bit (1) and '_' represents\n * an unset bit (0). A null input produces an empty CompactBitArray.\n *\n * @example\n * compactBitArrayFromAmino(\"xx___\") // { extra_bits_stored: 5, elems: Uint8Array([0xC0]) }\n * compactBitArrayFromAmino(null) // { extra_bits_stored: 0, elems: Uint8Array([]) }\n */\nexport function compactBitArrayFromAmino(\n amino: string | null,\n): CompactBitArray {\n if (amino === null) {\n return {\n extra_bits_stored: 0,\n elems: new Uint8Array(0),\n };\n }\n\n const count = amino.length;\n const extraBits = count % 8;\n const numBytes = Math.ceil(count / 8);\n const elems = new Uint8Array(numBytes);\n\n for (let i = 0; i < count; i++) {\n if (amino[i] === \"x\") {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n elems[byteIndex] |= 1 << bitIndex;\n }\n }\n\n return {\n extra_bits_stored: extraBits,\n elems,\n };\n}\n\n/**\n * Converts a CompactBitArray to its amino string representation.\n * Set bits (1) become 'x' and unset bits (0) become '_'.\n * Returns null for empty bit arrays (zero length).\n *\n * @example\n * compactBitArrayToAmino({ extra_bits_stored: 5, elems: Uint8Array([0xC0]) }) // \"xx___\"\n * compactBitArrayToAmino({ extra_bits_stored: 0, elems: Uint8Array([]) }) // null\n */\nexport function compactBitArrayToAmino(\n cba: CompactBitArray,\n): string | null {\n if (cba.elems.length === 0) {\n return null;\n }\n\n const fullBytes = cba.extra_bits_stored === 0\n ? cba.elems.length\n : cba.elems.length - 1;\n const totalBits = fullBytes * 8 + cba.extra_bits_stored;\n\n let result = \"\";\n for (let i = 0; i < totalBits; i++) {\n const byteIndex = Math.floor(i / 8);\n const bitIndex = 7 - (i % 8);\n const isSet = (cba.elems[byteIndex] & (1 << bitIndex)) !== 0;\n result += isSet ? \"x\" : \"_\";\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,yBACd,OACiB;AACjB,KAAI,UAAU,KACZ,QAAO;EACL,mBAAmB;EACnB,OAAO,IAAI,WAAW,EAAE;EACzB;CAGH,MAAM,QAAQ,MAAM;CACpB,MAAM,YAAY,QAAQ;CAC1B,MAAM,WAAW,KAAK,KAAK,QAAQ,EAAE;CACrC,MAAM,QAAQ,IAAI,WAAW,SAAS;AAEtC,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,IACzB,KAAI,MAAM,OAAO,KAAK;EACpB,MAAM,YAAY,KAAK,MAAM,IAAI,EAAE;EACnC,MAAM,WAAW,IAAK,IAAI;AAC1B,QAAM,cAAc,KAAK;;AAI7B,QAAO;EACL,mBAAmB;EACnB;EACD;;;;;;;;;;;AAYH,SAAgB,uBACd,KACe;AACf,KAAI,IAAI,MAAM,WAAW,EACvB,QAAO;CAMT,MAAM,aAHY,IAAI,sBAAsB,IACxC,IAAI,MAAM,SACV,IAAI,MAAM,SAAS,KACO,IAAI,IAAI;CAEtC,IAAI,SAAS;AACb,MAAK,IAAI,IAAI,GAAG,IAAI,WAAW,KAAK;EAClC,MAAM,YAAY,KAAK,MAAM,IAAI,EAAE;EACnC,MAAM,WAAW,IAAK,IAAI;EAC1B,MAAM,SAAS,IAAI,MAAM,aAAc,KAAK,cAAe;AAC3D,YAAU,QAAQ,MAAM;;AAG1B,QAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("./compact-bit-array.cjs");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { compactBitArrayFromAmino, compactBitArrayToAmino } from "./compact-bit-array.cjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { compactBitArrayFromAmino, compactBitArrayToAmino } from "./compact-bit-array.mjs";
|
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 {};
|