signet.js 0.0.1-beta.8 → 0.0.1-beta.9
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/browser/index.browser.cjs +12 -0
- package/browser/index.browser.cjs.map +1 -0
- package/browser/index.browser.js +3927 -0
- package/browser/index.browser.js.map +1 -0
- package/node/index.node.cjs +19 -0
- package/node/index.node.cjs.map +1 -0
- package/node/index.node.js +4099 -0
- package/node/index.node.js.map +1 -0
- package/package.json +17 -11
- package/{chains → types/chains}/Bitcoin/Bitcoin.d.ts +2 -29
- package/types/chains/Chain.d.ts +21 -0
- package/types/chains/ChainSignatureContract.d.ts +18 -0
- package/{chains → types/chains}/Cosmos/Cosmos.d.ts +3 -16
- package/{chains → types/chains}/EVM/EVM.d.ts +2 -12
- package/{chains → types/chains}/index.d.ts +0 -1
- package/{chains → types/chains}/types.d.ts +1 -14
- package/{utils → types/utils}/chains/near/ChainSignatureContract.d.ts +1 -4
- package/types/utils/chains/near/relayer/relayer.d.ts +3 -0
- package/{utils → types/utils}/chains/near/signAndSend/keypair.d.ts +1 -2
- package/{utils → types/utils}/chains/near/types.d.ts +10 -6
- package/types/utils/cryptography.d.ts +3 -0
- package/types/utils/index.d.ts +2 -0
- package/chains/Chain.d.ts +0 -74
- package/chains/ChainSignatureContract.d.ts +0 -41
- package/chains/utils.d.ts +0 -12
- package/index.cjs +0 -2
- package/index.cjs.map +0 -1
- package/index.js +0 -2674
- package/index.js.map +0 -1
- package/utils/chains/near/relayer/relayer.d.ts +0 -8
- package/utils/index.d.ts +0 -1
- /package/{chains → types/chains}/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.d.ts +0 -0
- /package/{chains → types/chains}/Bitcoin/BTCRpcAdapter/Mempool/Mempool.d.ts +0 -0
- /package/{chains → types/chains}/Bitcoin/BTCRpcAdapter/Mempool/index.d.ts +0 -0
- /package/{chains → types/chains}/Bitcoin/BTCRpcAdapter/Mempool/types.d.ts +0 -0
- /package/{chains → types/chains}/Bitcoin/BTCRpcAdapter/index.d.ts +0 -0
- /package/{chains → types/chains}/Bitcoin/types.d.ts +0 -0
- /package/{chains → types/chains}/Bitcoin/utils.d.ts +0 -0
- /package/{chains → types/chains}/Cosmos/types.d.ts +0 -0
- /package/{chains → types/chains}/Cosmos/utils.d.ts +0 -0
- /package/{chains → types/chains}/EVM/types.d.ts +0 -0
- /package/{chains → types/chains}/EVM/utils.d.ts +0 -0
- /package/{index.d.ts → types/index.d.ts} +0 -0
- /package/{utils → types/utils}/chains/index.d.ts +0 -0
- /package/{utils → types/utils}/chains/near/account.d.ts +0 -0
- /package/{utils → types/utils}/chains/near/constants.d.ts +0 -0
- /package/{utils → types/utils}/chains/near/index.d.ts +0 -0
- /package/{utils → types/utils}/chains/near/relayer/index.d.ts +0 -0
- /package/{utils → types/utils}/chains/near/relayer/types.d.ts +0 -0
- /package/{utils → types/utils}/chains/near/signAndSend/index.d.ts +0 -0
- /package/{utils → types/utils}/chains/near/transactionBuilder.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "signet.js",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"types": "./
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
9
|
+
"browser": {
|
|
10
|
+
"import": "./browser/index.browser.js",
|
|
11
|
+
"require": "./browser/index.browser.cjs"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
13
|
+
"node": {
|
|
14
|
+
"import": "./node/index.node.js",
|
|
15
|
+
"require": "./node/index.node.cjs"
|
|
16
|
+
},
|
|
17
|
+
"default": "./browser/index.browser.js"
|
|
14
18
|
}
|
|
15
19
|
},
|
|
16
|
-
"main": "./index.cjs",
|
|
17
|
-
"module": "./index.js",
|
|
18
|
-
"browser": "./index.js",
|
|
19
|
-
"types": "./
|
|
20
|
+
"main": "./node/index.node.cjs",
|
|
21
|
+
"module": "./node/index.node.js",
|
|
22
|
+
"browser": "./browser/index.browser.js",
|
|
23
|
+
"types": "./types/index.d.ts",
|
|
20
24
|
"scripts": {
|
|
21
|
-
"build": "rm -rf dist && vite build && cp package.json README.md LICENSE dist/",
|
|
22
25
|
"watch": "vite build --watch",
|
|
26
|
+
"build": "rm -rf dist && npm run build:browser && npm run build:node && cp package.json README.md LICENSE dist/",
|
|
27
|
+
"build:browser": "vite build --mode browser",
|
|
28
|
+
"build:node": "vite build --mode node",
|
|
23
29
|
"pre:deploy": "npm run build && npm run docs:build",
|
|
24
30
|
"publish-npm": "npm run pre:deploy && npm publish",
|
|
25
31
|
"publish-npm:beta": "npm run pre:deploy && cd dist && npm publish --tag beta",
|
|
@@ -1,50 +1,23 @@
|
|
|
1
1
|
import { BTCRpcAdapter } from './BTCRpcAdapter';
|
|
2
2
|
import { BTCNetworkIds, BTCTransactionRequest, BTCUnsignedTransaction } from './types';
|
|
3
3
|
import { Chain } from '../Chain';
|
|
4
|
-
import {
|
|
4
|
+
import { BaseChainSignatureContract } from '../ChainSignatureContract';
|
|
5
5
|
import { MPCPayloads, RSVSignature, KeyDerivationPath } from '../types';
|
|
6
6
|
import * as bitcoin from 'bitcoinjs-lib';
|
|
7
|
-
/**
|
|
8
|
-
* Implementation of the Chain interface for Bitcoin network.
|
|
9
|
-
* Handles interactions with both Bitcoin mainnet and testnet, supporting P2WPKH transactions.
|
|
10
|
-
*/
|
|
11
7
|
export declare class Bitcoin extends Chain<BTCTransactionRequest, BTCUnsignedTransaction> {
|
|
12
8
|
private static readonly SATOSHIS_PER_BTC;
|
|
13
9
|
private readonly network;
|
|
14
10
|
private readonly btcRpcAdapter;
|
|
15
11
|
private readonly contract;
|
|
16
|
-
/**
|
|
17
|
-
* Creates a new Bitcoin chain instance
|
|
18
|
-
* @param params - Configuration parameters
|
|
19
|
-
* @param params.network - Network identifier (mainnet/testnet)
|
|
20
|
-
* @param params.contract - Instance of the chain signature contract for MPC operations
|
|
21
|
-
* @param params.btcRpcAdapter - Bitcoin RPC adapter for network interactions
|
|
22
|
-
*/
|
|
23
12
|
constructor({ network, contract, btcRpcAdapter, }: {
|
|
24
13
|
network: BTCNetworkIds;
|
|
25
|
-
contract:
|
|
14
|
+
contract: BaseChainSignatureContract;
|
|
26
15
|
btcRpcAdapter: BTCRpcAdapter;
|
|
27
16
|
});
|
|
28
|
-
/**
|
|
29
|
-
* Converts satoshis to BTC
|
|
30
|
-
* @param satoshis - Amount in satoshis
|
|
31
|
-
* @returns Amount in BTC
|
|
32
|
-
*/
|
|
33
17
|
static toBTC(satoshis: number): number;
|
|
34
|
-
/**
|
|
35
|
-
* Converts BTC to satoshis
|
|
36
|
-
* @param btc - Amount in BTC
|
|
37
|
-
* @returns Amount in satoshis (rounded)
|
|
38
|
-
*/
|
|
39
18
|
static toSatoshi(btc: number): number;
|
|
40
19
|
private fetchTransaction;
|
|
41
20
|
private static parseRSVSignature;
|
|
42
|
-
/**
|
|
43
|
-
* Creates a Partially Signed Bitcoin Transaction (PSBT)
|
|
44
|
-
* @param params - Parameters for creating the PSBT
|
|
45
|
-
* @param params.transactionRequest - Transaction request containing inputs and outputs
|
|
46
|
-
* @returns Created PSBT instance
|
|
47
|
-
*/
|
|
48
21
|
createPSBT({ transactionRequest, }: {
|
|
49
22
|
transactionRequest: BTCTransactionRequest;
|
|
50
23
|
}): Promise<bitcoin.Psbt>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { KeyDerivationPath, MPCPayloads, RSVSignature } from './types';
|
|
2
|
+
export declare abstract class Chain<TransactionRequest, UnsignedTransaction> {
|
|
3
|
+
abstract getBalance(address: string): Promise<string>;
|
|
4
|
+
abstract deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
|
|
5
|
+
address: string;
|
|
6
|
+
publicKey: string;
|
|
7
|
+
}>;
|
|
8
|
+
abstract setTransaction(transaction: UnsignedTransaction, storageKey: string): void;
|
|
9
|
+
abstract getTransaction(storageKey: string, options?: {
|
|
10
|
+
remove?: boolean;
|
|
11
|
+
}): UnsignedTransaction | undefined;
|
|
12
|
+
abstract getMPCPayloadAndTransaction(transactionRequest: TransactionRequest): Promise<{
|
|
13
|
+
transaction: UnsignedTransaction;
|
|
14
|
+
mpcPayloads: MPCPayloads;
|
|
15
|
+
}>;
|
|
16
|
+
abstract addSignature(params: {
|
|
17
|
+
transaction: UnsignedTransaction;
|
|
18
|
+
mpcSignatures: RSVSignature[];
|
|
19
|
+
}): string;
|
|
20
|
+
abstract broadcastTx(txSerialized: string): Promise<string>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { default as BN } from 'bn.js';
|
|
2
|
+
import { RSVSignature, UncompressedPubKeySEC1 } from './types';
|
|
3
|
+
export interface SignArgs {
|
|
4
|
+
payload: number[];
|
|
5
|
+
path: string;
|
|
6
|
+
key_version: number;
|
|
7
|
+
}
|
|
8
|
+
export declare abstract class BaseChainSignatureContract {
|
|
9
|
+
abstract getCurrentSignatureDeposit(): Promise<BN>;
|
|
10
|
+
abstract getDerivedPublicKey(args: {
|
|
11
|
+
path: string;
|
|
12
|
+
predecessor: string;
|
|
13
|
+
} & Record<string, unknown>): Promise<UncompressedPubKeySEC1>;
|
|
14
|
+
}
|
|
15
|
+
export declare abstract class ChainSignatureContract extends BaseChainSignatureContract {
|
|
16
|
+
abstract sign(args: SignArgs & Record<string, unknown>): Promise<RSVSignature>;
|
|
17
|
+
abstract getPublicKey(): Promise<UncompressedPubKeySEC1>;
|
|
18
|
+
}
|
|
@@ -1,27 +1,14 @@
|
|
|
1
|
+
import { Chain } from '../Chain';
|
|
2
|
+
import { BaseChainSignatureContract } from '../ChainSignatureContract';
|
|
1
3
|
import { CosmosNetworkIds, CosmosTransactionRequest, CosmosUnsignedTransaction } from './types';
|
|
2
|
-
import { ChainSignatureContract } from '../ChainSignatureContract';
|
|
3
4
|
import { MPCPayloads, RSVSignature, KeyDerivationPath } from '../types';
|
|
4
|
-
import { Chain } from '../Chain';
|
|
5
|
-
/**
|
|
6
|
-
* Implementation of the Chain interface for Cosmos-based networks.
|
|
7
|
-
* Handles interactions with Cosmos SDK chains like Cosmos Hub, Osmosis, etc.
|
|
8
|
-
*/
|
|
9
5
|
export declare class Cosmos extends Chain<CosmosTransactionRequest, CosmosUnsignedTransaction> {
|
|
10
6
|
private readonly registry;
|
|
11
7
|
private readonly chainId;
|
|
12
8
|
private readonly contract;
|
|
13
9
|
private readonly endpoints?;
|
|
14
|
-
/**
|
|
15
|
-
* Creates a new Cosmos chain instance
|
|
16
|
-
* @param params - Configuration parameters
|
|
17
|
-
* @param params.chainId - Chain id for the Cosmos network
|
|
18
|
-
* @param params.contract - Instance of the chain signature contract for MPC operations
|
|
19
|
-
* @param params.endpoints - Optional RPC and REST endpoints
|
|
20
|
-
* @param params.endpoints.rpcUrl - Optional RPC endpoint URL
|
|
21
|
-
* @param params.endpoints.restUrl - Optional REST endpoint URL
|
|
22
|
-
*/
|
|
23
10
|
constructor({ chainId, contract, endpoints, }: {
|
|
24
|
-
contract:
|
|
11
|
+
contract: BaseChainSignatureContract;
|
|
25
12
|
chainId: CosmosNetworkIds;
|
|
26
13
|
endpoints?: {
|
|
27
14
|
rpcUrl?: string;
|
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
import { Chain } from '../Chain';
|
|
2
|
-
import {
|
|
2
|
+
import { BaseChainSignatureContract } from '../ChainSignatureContract';
|
|
3
3
|
import { EVMTransactionRequest, EVMUnsignedTransaction } from './types';
|
|
4
4
|
import { MPCPayloads, RSVSignature, KeyDerivationPath } from '../types';
|
|
5
|
-
/**
|
|
6
|
-
* Implementation of the Chain interface for EVM-compatible networks.
|
|
7
|
-
* Handles interactions with Ethereum Virtual Machine based blockchains like Ethereum, BSC, Polygon, etc.
|
|
8
|
-
*/
|
|
9
5
|
export declare class EVM extends Chain<EVMTransactionRequest, EVMUnsignedTransaction> {
|
|
10
6
|
private readonly provider;
|
|
11
7
|
private readonly contract;
|
|
12
|
-
/**
|
|
13
|
-
* Creates a new EVM chain instance
|
|
14
|
-
* @param params - Configuration parameters
|
|
15
|
-
* @param params.rpcUrl - URL of the EVM JSON-RPC provider (e.g., Infura endpoint)
|
|
16
|
-
* @param params.contract - Instance of the chain signature contract for MPC operations
|
|
17
|
-
*/
|
|
18
8
|
constructor({ rpcUrl, contract, }: {
|
|
19
9
|
rpcUrl: string;
|
|
20
|
-
contract:
|
|
10
|
+
contract: BaseChainSignatureContract;
|
|
21
11
|
});
|
|
22
12
|
private attachGasAndNonce;
|
|
23
13
|
private parseSignature;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { Chain } from './Chain';
|
|
2
2
|
export { ChainSignatureContract, type SignArgs } from './ChainSignatureContract';
|
|
3
3
|
export * from './types';
|
|
4
|
-
export * as utils from './utils';
|
|
5
4
|
export { EVM } from './EVM/EVM';
|
|
6
5
|
export { fetchEVMFeeProperties } from './EVM/utils';
|
|
7
6
|
export type { EVMTransactionRequest, EVMUnsignedTransaction } from './EVM/types';
|
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
import { SignArgs } from './ChainSignatureContract';
|
|
2
|
-
|
|
3
|
-
transactionHash: string;
|
|
4
|
-
success: true;
|
|
5
|
-
}
|
|
6
|
-
interface FailureResponse {
|
|
7
|
-
success: false;
|
|
8
|
-
errorMessage: string;
|
|
9
|
-
}
|
|
10
|
-
export type Response = SuccessResponse | FailureResponse;
|
|
11
|
-
export type MPCPayloads = Array<{
|
|
12
|
-
index: number;
|
|
13
|
-
payload: SignArgs['payload'];
|
|
14
|
-
}>;
|
|
2
|
+
export type MPCPayloads = Array<SignArgs['payload']>;
|
|
15
3
|
export type UncompressedPubKeySEC1 = `04${string}`;
|
|
16
4
|
export type KeyDerivationPath = string;
|
|
17
5
|
export interface RSVSignature {
|
|
@@ -28,4 +16,3 @@ export interface MPCSignature {
|
|
|
28
16
|
};
|
|
29
17
|
recovery_id: number;
|
|
30
18
|
}
|
|
31
|
-
export {};
|
|
@@ -10,10 +10,6 @@ interface ChainSignatureContractArgs {
|
|
|
10
10
|
accountId?: string;
|
|
11
11
|
keypair?: KeyPair;
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
14
|
-
* This contract will default to view methods only.
|
|
15
|
-
* If you want to use the change methods, you need to provide an account and keypair.
|
|
16
|
-
*/
|
|
17
13
|
export declare class ChainSignatureContract extends AbstractChainSignatureContract {
|
|
18
14
|
private readonly networkId;
|
|
19
15
|
private readonly contractId;
|
|
@@ -26,6 +22,7 @@ export declare class ChainSignatureContract extends AbstractChainSignatureContra
|
|
|
26
22
|
path: string;
|
|
27
23
|
predecessor: string;
|
|
28
24
|
}): Promise<UncompressedPubKeySEC1>;
|
|
25
|
+
getPublicKey(): Promise<UncompressedPubKeySEC1>;
|
|
29
26
|
sign(args: SignArgs): Promise<RSVSignature>;
|
|
30
27
|
static signWithRelayer({ account, contract, signArgs, deposit, relayerUrl, }: {
|
|
31
28
|
account: Account;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { KeyPair } from '@near-js/crypto';
|
|
2
|
-
import { Response } from '
|
|
3
|
-
import { BitcoinRequest, CosmosRequest, EVMRequest } from '../types';
|
|
2
|
+
import { Response, BitcoinRequest, CosmosRequest, EVMRequest } from '../types';
|
|
4
3
|
export declare const EVMTransaction: (req: EVMRequest, keyPair: KeyPair) => Promise<Response>;
|
|
5
4
|
export declare const BTCTransaction: (req: BitcoinRequest, keyPair: KeyPair) => Promise<Response>;
|
|
6
5
|
export declare const CosmosTransaction: (req: CosmosRequest, keyPair: KeyPair) => Promise<Response>;
|
|
@@ -2,12 +2,6 @@ import { BTCTransactionRequest, BTCNetworkIds } from '../../../chains/Bitcoin/ty
|
|
|
2
2
|
import { CosmosNetworkIds, CosmosTransactionRequest } from '../../../chains/Cosmos/types';
|
|
3
3
|
import { EVMTransactionRequest } from '../../../chains/EVM/types';
|
|
4
4
|
import { KeyDerivationPath } from '../../../chains/types';
|
|
5
|
-
/**
|
|
6
|
-
Available ChainSignature contracts:
|
|
7
|
-
- Mainnet: v1.signer
|
|
8
|
-
- Testnet: v1.signer-prod.testnet
|
|
9
|
-
- Development (unstable): v1.signer-dev.testnet
|
|
10
|
-
*/
|
|
11
5
|
export type ChainSignatureContractIds = string;
|
|
12
6
|
export type NFTKeysContracts = string;
|
|
13
7
|
export type NearNetworkIds = 'mainnet' | 'testnet';
|
|
@@ -19,6 +13,15 @@ export interface NearAuthentication {
|
|
|
19
13
|
networkId: NearNetworkIds;
|
|
20
14
|
accountId: string;
|
|
21
15
|
}
|
|
16
|
+
interface SuccessResponse {
|
|
17
|
+
transactionHash: string;
|
|
18
|
+
success: true;
|
|
19
|
+
}
|
|
20
|
+
interface FailureResponse {
|
|
21
|
+
success: false;
|
|
22
|
+
errorMessage: string;
|
|
23
|
+
}
|
|
24
|
+
export type Response = SuccessResponse | FailureResponse;
|
|
22
25
|
export type EVMChainConfigWithProviders = ChainProvider;
|
|
23
26
|
export interface EVMRequest {
|
|
24
27
|
transaction: EVMTransactionRequest;
|
|
@@ -48,3 +51,4 @@ export interface CosmosRequest {
|
|
|
48
51
|
derivationPath: KeyDerivationPath;
|
|
49
52
|
fastAuthRelayerUrl?: string;
|
|
50
53
|
}
|
|
54
|
+
export {};
|
package/chains/Chain.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { KeyDerivationPath, MPCPayloads, RSVSignature } from './types';
|
|
2
|
-
export declare abstract class Chain<TransactionRequest, UnsignedTransaction> {
|
|
3
|
-
/**
|
|
4
|
-
* Gets the native token balance for a given address
|
|
5
|
-
*
|
|
6
|
-
* @param address - The address to check
|
|
7
|
-
* @returns Promise resolving to the balance as a string, formatted according to the chain's decimal places (e.g. ETH, BTC, etc.)
|
|
8
|
-
*/
|
|
9
|
-
abstract getBalance(address: string): Promise<string>;
|
|
10
|
-
/**
|
|
11
|
-
* Uses Sig Network Key Derivation Function to derive the address and public key. from a signer ID and string path.
|
|
12
|
-
*
|
|
13
|
-
* @param predecessor - The id/address of the account requesting signature
|
|
14
|
-
* @param path - The string path used to derive the key
|
|
15
|
-
* @returns Promise resolving to the derived address and public key
|
|
16
|
-
*/
|
|
17
|
-
abstract deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
|
|
18
|
-
address: string;
|
|
19
|
-
publicKey: string;
|
|
20
|
-
}>;
|
|
21
|
-
/**
|
|
22
|
-
* Stores an unsigned transaction in local storage for later use.
|
|
23
|
-
* Particularly useful for browser-based wallets that redirects the user to a different page.
|
|
24
|
-
*
|
|
25
|
-
* @param transaction - The unsigned transaction to store
|
|
26
|
-
* @param storageKey - Unique key to identify the stored transaction
|
|
27
|
-
*/
|
|
28
|
-
abstract setTransaction(transaction: UnsignedTransaction, storageKey: string): void;
|
|
29
|
-
/**
|
|
30
|
-
* Retrieves a previously stored transaction from local storage.
|
|
31
|
-
*
|
|
32
|
-
* @param storageKey - The key used to store the transaction
|
|
33
|
-
* @param options - Additional options
|
|
34
|
-
* @param options.remove - If true, removes the transaction from storage after retrieval
|
|
35
|
-
* @returns The stored transaction or undefined if not found
|
|
36
|
-
*/
|
|
37
|
-
abstract getTransaction(storageKey: string, options?: {
|
|
38
|
-
remove?: boolean;
|
|
39
|
-
}): UnsignedTransaction | undefined;
|
|
40
|
-
/**
|
|
41
|
-
* Prepares a transaction for Sig Network MPC signing by creating the necessary payloads.
|
|
42
|
-
* This method handles chain-specific transaction preparation including:
|
|
43
|
-
* - Fee calculation
|
|
44
|
-
* - Nonce/sequence management
|
|
45
|
-
* - UTXO selection (for UTXO-based chains)
|
|
46
|
-
* - Transaction encoding
|
|
47
|
-
*
|
|
48
|
-
* @param transactionRequest - The transaction request containing parameters like recipient, amount, etc.
|
|
49
|
-
* @returns Promise resolving to the unsigned transaction and MPC payloads for signing
|
|
50
|
-
*/
|
|
51
|
-
abstract getMPCPayloadAndTransaction(transactionRequest: TransactionRequest): Promise<{
|
|
52
|
-
transaction: UnsignedTransaction;
|
|
53
|
-
mpcPayloads: MPCPayloads;
|
|
54
|
-
}>;
|
|
55
|
-
/**
|
|
56
|
-
* Adds Sig Network MPC-generated signatures to an unsigned transaction.
|
|
57
|
-
*
|
|
58
|
-
* @param params - Parameters for adding signatures
|
|
59
|
-
* @param params.transaction - The unsigned transaction to add signatures to
|
|
60
|
-
* @param params.mpcSignatures - Array of RSV signatures generated through MPC
|
|
61
|
-
* @returns The serialized signed transaction ready for broadcast
|
|
62
|
-
*/
|
|
63
|
-
abstract addSignature(params: {
|
|
64
|
-
transaction: UnsignedTransaction;
|
|
65
|
-
mpcSignatures: RSVSignature[];
|
|
66
|
-
}): string;
|
|
67
|
-
/**
|
|
68
|
-
* Broadcasts a signed transaction to the network.
|
|
69
|
-
*
|
|
70
|
-
* @param txSerialized - The serialized signed transaction
|
|
71
|
-
* @returns Promise resolving to the transaction hash/ID
|
|
72
|
-
*/
|
|
73
|
-
abstract broadcastTx(txSerialized: string): Promise<string>;
|
|
74
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { default as BN } from 'bn.js';
|
|
2
|
-
import { RSVSignature, UncompressedPubKeySEC1 } from './types';
|
|
3
|
-
export interface SignArgs {
|
|
4
|
-
/** The payload to sign as an array of 32 bytes */
|
|
5
|
-
payload: number[];
|
|
6
|
-
/** The derivation path for key generation */
|
|
7
|
-
path: string;
|
|
8
|
-
/** Version of the key to use */
|
|
9
|
-
key_version: number;
|
|
10
|
-
}
|
|
11
|
-
export declare abstract class ChainSignatureContract {
|
|
12
|
-
/**
|
|
13
|
-
* Gets the current signature deposit required by the contract.
|
|
14
|
-
* This deposit amount helps manage network congestion.
|
|
15
|
-
*
|
|
16
|
-
* @returns Promise resolving to the required deposit amount as a BigNumber
|
|
17
|
-
*/
|
|
18
|
-
abstract getCurrentSignatureDeposit(): Promise<BN>;
|
|
19
|
-
/**
|
|
20
|
-
* Signs a payload using Sig Network MPC.
|
|
21
|
-
*
|
|
22
|
-
* @param args - Arguments for the signing operation
|
|
23
|
-
* @param args.payload - The data to sign as an array of 32 bytes
|
|
24
|
-
* @param args.path - The string path to use derive the key
|
|
25
|
-
* @param args.key_version - Version of the key to use
|
|
26
|
-
* @returns Promise resolving to the RSV signature
|
|
27
|
-
*/
|
|
28
|
-
abstract sign(args: SignArgs & Record<string, unknown>): Promise<RSVSignature>;
|
|
29
|
-
/**
|
|
30
|
-
* Derives a child public key using a derivation path and predecessor.
|
|
31
|
-
*
|
|
32
|
-
* @param args - Arguments for key derivation
|
|
33
|
-
* @param args.path - The string path to use derive the key
|
|
34
|
-
* @param args.predecessor - The id/address of the account requesting signature
|
|
35
|
-
* @returns Promise resolving to the derived SEC1 uncompressed public key
|
|
36
|
-
*/
|
|
37
|
-
abstract getDerivedPublicKey(args: {
|
|
38
|
-
path: string;
|
|
39
|
-
predecessor: string;
|
|
40
|
-
} & Record<string, unknown>): Promise<UncompressedPubKeySEC1>;
|
|
41
|
-
}
|
package/chains/utils.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { MPCSignature, RSVSignature, UncompressedPubKeySEC1 } from './types';
|
|
2
|
-
export declare const toRSV: (signature: MPCSignature) => RSVSignature;
|
|
3
|
-
/**
|
|
4
|
-
* Compresses an uncompressed public key to its compressed format following SEC1 standards.
|
|
5
|
-
* In SEC1, a compressed public key consists of a prefix (02 or 03) followed by the x-coordinate.
|
|
6
|
-
* The prefix indicates whether the y-coordinate is even (02) or odd (03).
|
|
7
|
-
*
|
|
8
|
-
* @param uncompressedPubKeySEC1 - The uncompressed public key in hex format, with or without '04' prefix
|
|
9
|
-
* @returns The compressed public key in hex format
|
|
10
|
-
* @throws Error if the uncompressed public key length is invalid
|
|
11
|
-
*/
|
|
12
|
-
export declare const compressPubKey: (uncompressedPubKeySEC1: UncompressedPubKeySEC1) => string;
|
package/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("bn.js"),U=require("@cosmjs/encoding"),C=require("ethers"),Pe=require("bitcoinjs-lib"),Ce=require("coinselect"),Ee=require("@cosmjs/amino"),Q=require("@cosmjs/crypto"),q=require("@cosmjs/proto-signing"),z=require("@cosmjs/stargate"),ie=require("bech32"),ae=require("chain-registry"),te=require("@near-js/accounts"),Se=require("@near-js/crypto"),xe=require("@near-js/transactions"),Me=require("borsh"),Je=require("@near-js/utils"),Ue=require("@near-js/keystores"),Re=require("bs58");function Fe(i){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const d in i)if(d!=="default"){const c=Object.getOwnPropertyDescriptor(i,d);Object.defineProperty(r,d,c.get?c:{enumerable:!0,get:()=>i[d]})}}return r.default=i,Object.freeze(r)}const R=Fe(Pe);class Z{}let be=class{};const Ie=i=>({r:i.big_r.affine_point.substring(2),s:i.s.scalar,v:i.recovery_id}),Be=i=>{const r=i.slice(2);if(r.length!==128)throw new Error("Invalid uncompressed public key length");const d=r.slice(0,64),c=r.slice(64);return(parseInt(c.slice(-1),16)%2===0?"02":"03")+d};async function we(i,r){const d=new C.ethers.JsonRpcProvider(i),c=await d.estimateGas(r),s=await d.getFeeData(),o=s.maxFeePerGas??C.ethers.parseUnits("10","gwei"),a=s.maxPriorityFeePerGas??C.ethers.parseUnits("10","gwei");return{gasLimit:c,maxFeePerGas:o,maxPriorityFeePerGas:a,maxFee:o*c}}class _e extends Z{constructor({rpcUrl:r,contract:d}){super(),this.contract=d,this.provider=new C.ethers.JsonRpcProvider(r)}async attachGasAndNonce(r){const d=await we(this.provider._getConnection().url,r),c=await this.provider.getTransactionCount(r.from,"latest"),{from:s,...o}=r;return{...d,chainId:this.provider._network.chainId,nonce:c,type:2,...o}}parseSignature(r){return C.ethers.Signature.from({r:`0x${r.r}`,s:`0x${r.s}`,v:r.v})}async deriveAddressAndPublicKey(r,d){const c=await this.contract.getDerivedPublicKey({path:d,predecessor:r});if(!c)throw new Error("Failed to get derived public key");const s=c.startsWith("04")?c.substring(2):c,o=C.ethers.keccak256(U.fromHex(s));return{address:`0x${o.substring(o.length-40)}`,publicKey:c}}async getBalance(r){try{const d=await this.provider.getBalance(r);return C.ethers.formatEther(d)}catch(d){throw console.error(`Failed to fetch balance for address ${r}:`,d),new Error("Failed to fetch balance.")}}setTransaction(r,d){const c=JSON.stringify(r,(s,o)=>typeof o=="bigint"?o.toString():o);window.localStorage.setItem(d,c)}getTransaction(r,d){const c=window.localStorage.getItem(r);return d!=null&&d.remove&&window.localStorage.removeItem(r),c?JSON.parse(c):void 0}async getMPCPayloadAndTransaction(r){const d=await this.attachGasAndNonce(r),c=C.ethers.Transaction.from(d).unsignedSerialized,s=C.keccak256(c),o=Array.from(C.ethers.getBytes(s));return{transaction:d,mpcPayloads:[{index:0,payload:o}]}}addSignature({transaction:r,mpcSignatures:d}){return C.ethers.Transaction.from({...r,signature:this.parseSignature(d[0])}).serialized}async broadcastTx(r){try{return(await this.provider.broadcastTransaction(r)).hash}catch(d){throw console.error("Transaction broadcast failed:",d),new Error("Failed to broadcast transaction.")}}}function oe(i){switch(i.toLowerCase()){case"mainnet":return R.networks.bitcoin;case"testnet":return R.networks.testnet;case"regtest":return R.networks.regtest;default:throw new Error(`Unknown Bitcoin network: ${i}`)}}const K=class K extends Z{constructor({network:r,contract:d,btcRpcAdapter:c}){super(),this.network=r,this.btcRpcAdapter=c,this.contract=d}static toBTC(r){return r/K.SATOSHIS_PER_BTC}static toSatoshi(r){return Math.round(r*K.SATOSHIS_PER_BTC)}async fetchTransaction(r){const d=await this.btcRpcAdapter.getTransaction(r),c=new R.Transaction;return d.vout.forEach(s=>{const o=Buffer.from(s.scriptpubkey,"hex");c.addOutput(o,Number(s.value))}),c}static parseRSVSignature(r){const d=r.r.padStart(64,"0"),c=r.s.padStart(64,"0"),s=Buffer.from(d+c,"hex");if(s.length!==64)throw new Error("Invalid signature length.");return s}async createPSBT({transactionRequest:r}){const{inputs:d,outputs:c}=r.inputs&&r.outputs?r:await this.btcRpcAdapter.selectUTXOs(r.from,[{address:r.to,value:parseFloat(r.value)}]),s=new R.Psbt({network:oe(this.network)});return await Promise.all(d.map(async o=>{if(!o.scriptPubKey){const f=(await this.fetchTransaction(o.txid)).outs[o.vout];o.scriptPubKey=f.script}s.addInput({hash:o.txid,index:o.vout,witnessUtxo:{script:o.scriptPubKey,value:o.value}})})),c.forEach(o=>{o.address?s.addOutput({address:o.address,value:o.value}):o.script&&s.addOutput({script:o.script,value:o.value})}),s}async getBalance(r){const d=await this.btcRpcAdapter.getBalance(r);return K.toBTC(d).toString()}async deriveAddressAndPublicKey(r,d){const c=await this.contract.getDerivedPublicKey({path:d,predecessor:r});if(!c)throw new Error("Failed to get derived public key");const s=Be(c),o=Buffer.from(s,"hex"),a=oe(this.network),f=R.payments.p2wpkh({pubkey:o,network:a}),{address:g}=f;if(!g)throw new Error("Failed to generate Bitcoin address");return{address:g,publicKey:s}}setTransaction(r,d){window.localStorage.setItem(d,JSON.stringify({psbt:r.psbt.toHex(),publicKey:r.publicKey}))}getTransaction(r,d){const c=window.localStorage.getItem(r);if(!c)return;d!=null&&d.remove&&window.localStorage.removeItem(r);const s=JSON.parse(c);return{psbt:R.Psbt.fromHex(s.psbt),publicKey:s.publicKey}}async getMPCPayloadAndTransaction(r){const d=Buffer.from(r.publicKey,"hex"),c=await this.createPSBT({transactionRequest:r}),s=c.toHex(),o=[],a=f=>({publicKey:d,sign:g=>(o.push({index:f,payload:Array.from(g)}),Buffer.alloc(64))});for(let f=0;f<c.inputCount;f++)c.signInput(f,a(f));return{transaction:{psbt:R.Psbt.fromHex(s),publicKey:r.publicKey},mpcPayloads:o.sort((f,g)=>f.index-g.index)}}addSignature({transaction:{psbt:r,publicKey:d},mpcSignatures:c}){const s=Buffer.from(d,"hex"),o=a=>({publicKey:s,sign:()=>{const f=c[a];return K.parseRSVSignature(f)}});for(let a=0;a<r.inputCount;a++)r.signInput(a,o(a));return r.finalizeAllInputs(),r.extractTransaction().toHex()}async broadcastTx(r){return await this.btcRpcAdapter.broadcastTransaction(r)}};K.SATOSHIS_PER_BTC=1e8;let V=K;class Oe{}class Ke extends Oe{constructor(r){super(),this.providerUrl=r}async fetchFeeRate(r=6){const c=await(await fetch(`${this.providerUrl}/v1/fees/recommended`)).json();return r<=1?c.fastestFee:r<=3?c.halfHourFee:r<=6?c.hourFee:c.economyFee}async fetchUTXOs(r){try{return await(await fetch(`${this.providerUrl}/address/${r}/utxo`)).json()}catch(d){return console.error("Failed to fetch UTXOs:",d),[]}}async selectUTXOs(r,d,c=6){const s=await this.fetchUTXOs(r),o=await this.fetchFeeRate(c),a=Ce(s,d,Math.ceil(o+1));if(!a.inputs||!a.outputs)throw new Error("Invalid transaction: coinselect failed to find a suitable set of inputs and outputs. This could be due to insufficient funds, or no inputs being available that meet the criteria.");return{inputs:a.inputs,outputs:a.outputs}}async broadcastTransaction(r){const d=await fetch(`${this.providerUrl}/tx`,{method:"POST",body:r});if(d.ok)return await d.text();throw new Error(`Failed to broadcast transaction: ${await d.text()}`)}async getBalance(r){const c=await(await fetch(`${this.providerUrl}/address/${r}`)).json();return c.chain_stats.funded_txo_sum-c.chain_stats.spent_txo_sum}async getTransaction(r){return await(await fetch(`${this.providerUrl}/tx/${r}`)).json()}}const ke={Mempool:Ke};var se=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},j={},x={},M={},J={},ue;function Ge(){if(ue)return J;ue=1,Object.defineProperty(J,"__esModule",{value:!0}),J.utf8Write=J.utf8Read=J.utf8Length=void 0;function i(c){let s=0,o=0;for(let a=0;a<c.length;++a)o=c.charCodeAt(a),o<128?s+=1:o<2048?s+=2:(o&64512)===55296&&(c.charCodeAt(a+1)&64512)===56320?(++a,s+=4):s+=3;return s}J.utf8Length=i;function r(c,s,o){if(o-s<1)return"";const f=[];let g=[],_=0,I;for(;s<o;)I=c[s++],I<128?f[_++]=I:I>191&&I<224?f[_++]=(I&31)<<6|c[s++]&63:I>239&&I<365?(I=((I&7)<<18|(c[s++]&63)<<12|(c[s++]&63)<<6|c[s++]&63)-65536,f[_++]=55296+(I>>10),f[_++]=56320+(I&1023)):f[_++]=(I&15)<<12|(c[s++]&63)<<6|c[s++]&63,_>8191&&(g.push(String.fromCharCode(...f)),_=0);return _&&g.push(String.fromCharCode(...f.slice(0,_))),g.join("")}J.utf8Read=r;function d(c,s,o){const a=o;let f,g;for(let _=0;_<c.length;++_)f=c.charCodeAt(_),f<128?s[o++]=f:f<2048?(s[o++]=f>>6|192,s[o++]=f&63|128):(f&64512)===55296&&((g=c.charCodeAt(_+1))&64512)===56320?(f=65536+((f&1023)<<10)+(g&1023),++_,s[o++]=f>>18|240,s[o++]=f>>12&63|128,s[o++]=f>>6&63|128,s[o++]=f&63|128):(s[o++]=f>>12|224,s[o++]=f>>6&63|128,s[o++]=f&63|128);return o-a}return J.utf8Write=d,J}var k={},ce;function qe(){if(ce)return k;ce=1,Object.defineProperty(k,"__esModule",{value:!0}),k.writeByte=k.writeFixed32=k.int64Length=k.writeVarint64=k.writeVarint32=k.readInt32=k.readUInt32=k.zzDecode=k.zzEncode=k.varint32read=k.varint32write=k.uInt64ToString=k.int64ToString=k.int64FromString=k.varint64write=k.varint64read=void 0;function i(){let n=0,t=0;for(let h=0;h<28;h+=7){let B=this.buf[this.pos++];if(n|=(B&127)<<h,!(B&128))return this.assertBounds(),[n,t]}let m=this.buf[this.pos++];if(n|=(m&15)<<28,t=(m&112)>>4,!(m&128))return this.assertBounds(),[n,t];for(let h=3;h<=31;h+=7){let B=this.buf[this.pos++];if(t|=(B&127)<<h,!(B&128))return this.assertBounds(),[n,t]}throw new Error("invalid varint")}k.varint64read=i;function r(n,t,m){for(let A=0;A<28;A=A+7){const T=n>>>A,E=!(!(T>>>7)&&t==0),P=(E?T|128:T)&255;if(m.push(P),!E)return}const h=n>>>28&15|(t&7)<<4,B=!!(t>>3);if(m.push((B?h|128:h)&255),!!B){for(let A=3;A<31;A=A+7){const T=t>>>A,E=!!(T>>>7),P=(E?T|128:T)&255;if(m.push(P),!E)return}m.push(t>>>31&1)}}k.varint64write=r;const d=4294967296;function c(n){const t=n[0]==="-";t&&(n=n.slice(1));const m=1e6;let h=0,B=0;function A(T,E){const P=Number(n.slice(T,E));B*=m,h=h*m+P,h>=d&&(B=B+(h/d|0),h=h%d)}return A(-24,-18),A(-18,-12),A(-12,-6),A(-6),t?g(h,B):f(h,B)}k.int64FromString=c;function s(n,t){let m=f(n,t);const h=m.hi&2147483648;h&&(m=g(m.lo,m.hi));const B=o(m.lo,m.hi);return h?"-"+B:B}k.int64ToString=s;function o(n,t){if({lo:n,hi:t}=a(n,t),t<=2097151)return String(d*t+n);const m=n&16777215,h=(n>>>24|t<<8)&16777215,B=t>>16&65535;let A=m+h*6777216+B*6710656,T=h+B*8147497,E=B*2;const P=1e7;return A>=P&&(T+=Math.floor(A/P),A%=P),T>=P&&(E+=Math.floor(T/P),T%=P),E.toString()+_(T)+_(A)}k.uInt64ToString=o;function a(n,t){return{lo:n>>>0,hi:t>>>0}}function f(n,t){return{lo:n|0,hi:t|0}}function g(n,t){return t=~t,n?n=~n+1:t+=1,f(n,t)}const _=n=>{const t=String(n);return"0000000".slice(t.length)+t};function I(n,t){if(n>=0){for(;n>127;)t.push(n&127|128),n=n>>>7;t.push(n)}else{for(let m=0;m<9;m++)t.push(n&127|128),n=n>>7;t.push(1)}}k.varint32write=I;function l(){let n=this.buf[this.pos++],t=n&127;if(!(n&128))return this.assertBounds(),t;if(n=this.buf[this.pos++],t|=(n&127)<<7,!(n&128))return this.assertBounds(),t;if(n=this.buf[this.pos++],t|=(n&127)<<14,!(n&128))return this.assertBounds(),t;if(n=this.buf[this.pos++],t|=(n&127)<<21,!(n&128))return this.assertBounds(),t;n=this.buf[this.pos++],t|=(n&15)<<28;for(let m=5;n&128&&m<10;m++)n=this.buf[this.pos++];if(n&128)throw new Error("invalid varint");return this.assertBounds(),t>>>0}k.varint32read=l;function b(n,t){let m=t>>31;return t=((t<<1|n>>>31)^m)>>>0,n=(n<<1^m)>>>0,[n,t]}k.zzEncode=b;function u(n,t){let m=-(n&1);return n=((n>>>1|t<<31)^m)>>>0,t=(t>>>1^m)>>>0,[n,t]}k.zzDecode=u;function y(n,t){return(n[t]|n[t+1]<<8|n[t+2]<<16)+n[t+3]*16777216}k.readUInt32=y;function S(n,t){return(n[t]|n[t+1]<<8|n[t+2]<<16)+(n[t+3]<<24)}k.readInt32=S;function p(n,t,m){for(;n>127;)t[m++]=n&127|128,n>>>=7;t[m]=n}k.writeVarint32=p;function w(n,t,m){for(;n.hi;)t[m++]=n.lo&127|128,n.lo=(n.lo>>>7|n.hi<<25)>>>0,n.hi>>>=7;for(;n.lo>127;)t[m++]=n.lo&127|128,n.lo=n.lo>>>7;t[m++]=n.lo}k.writeVarint64=w;function O(n,t){let m=n,h=(n>>>28|t<<4)>>>0,B=t>>>24;return B===0?h===0?m<16384?m<128?1:2:m<2097152?3:4:h<16384?h<128?5:6:h<2097152?7:8:B<128?9:10}k.int64Length=O;function D(n,t,m){t[m]=n&255,t[m+1]=n>>>8&255,t[m+2]=n>>>16&255,t[m+3]=n>>>24}k.writeFixed32=D;function e(n,t,m){t[m]=n&255}return k.writeByte=e,k}var de;function H(){if(de)return M;de=1,Object.defineProperty(M,"__esModule",{value:!0}),M.BinaryWriter=M.BinaryReader=M.WireType=void 0;const i=Ge(),r=qe();var d;(function(I){I[I.Varint=0]="Varint",I[I.Fixed64=1]="Fixed64",I[I.Bytes=2]="Bytes",I[I.Fixed32=5]="Fixed32"})(d||(M.WireType=d={}));class c{assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}constructor(l){this.buf=l?new Uint8Array(l):new Uint8Array(0),this.pos=0,this.type=0,this.len=this.buf.length}tag(){const l=this.uint32(),b=l>>>3,u=l&7;if(b<=0||u<0||u>5)throw new Error("illegal tag: field no "+b+" wire type "+u);return[b,u,l]}skip(l){if(typeof l=="number"){if(this.pos+l>this.len)throw _(this,l);this.pos+=l}else do if(this.pos>=this.len)throw _(this);while(this.buf[this.pos++]&128);return this}skipType(l){switch(l){case d.Varint:this.skip();break;case d.Fixed64:this.skip(8);break;case d.Bytes:this.skip(this.uint32());break;case 3:for(;(l=this.uint32()&7)!==4;)this.skipType(l);break;case d.Fixed32:this.skip(4);break;default:throw Error("invalid wire type "+l+" at offset "+this.pos)}return this}uint32(){return r.varint32read.bind(this)()}int32(){return this.uint32()|0}sint32(){const l=this.uint32();return l%2===1?(l+1)/-2:l/2}fixed32(){const l=(0,r.readUInt32)(this.buf,this.pos);return this.pos+=4,l}sfixed32(){const l=(0,r.readInt32)(this.buf,this.pos);return this.pos+=4,l}int64(){const[l,b]=r.varint64read.bind(this)();return BigInt((0,r.int64ToString)(l,b))}uint64(){const[l,b]=r.varint64read.bind(this)();return BigInt((0,r.uInt64ToString)(l,b))}sint64(){let[l,b]=r.varint64read.bind(this)();return[l,b]=(0,r.zzDecode)(l,b),BigInt((0,r.int64ToString)(l,b))}fixed64(){const l=this.sfixed32(),b=this.sfixed32();return BigInt((0,r.uInt64ToString)(l,b))}sfixed64(){const l=this.sfixed32(),b=this.sfixed32();return BigInt((0,r.int64ToString)(l,b))}float(){throw new Error("float not supported")}double(){throw new Error("double not supported")}bool(){const[l,b]=r.varint64read.bind(this)();return l!==0||b!==0}bytes(){const l=this.uint32(),b=this.pos;return this.pos+=l,this.assertBounds(),this.buf.subarray(b,b+l)}string(){const l=this.bytes();return(0,i.utf8Read)(l,0,l.length)}}M.BinaryReader=c;class s{constructor(l,b,u){this.fn=l,this.len=b,this.val=u}proceed(l,b){this.fn&&this.fn(this.val,l,b)}}class o{constructor(l){this.head=l.head,this.tail=l.tail,this.len=l.len,this.next=l.states}}class a{constructor(){this.len=0,this.uint64=a.prototype.int64,this.sfixed64=a.prototype.fixed64,this.sfixed32=a.prototype.fixed32,this.head=new s(null,0,0),this.tail=this.head,this.states=null}static create(){return new a}static alloc(l){return typeof Uint8Array<"u"?g(b=>new Uint8Array(b),Uint8Array.prototype.subarray)(l):new Array(l)}_push(l,b,u){return this.tail=this.tail.next=new s(l,b,u),this.len+=b,this}finish(){let l=this.head.next,b=0;const u=a.alloc(this.len);for(;l;)l.proceed(u,b),b+=l.len,l=l.next;return u}fork(){return this.states=new o(this),this.head=this.tail=new s(null,0,0),this.len=0,this}reset(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new s(null,0,0),this.len=0),this}ldelim(){const l=this.head,b=this.tail,u=this.len;return this.reset().uint32(u),u&&(this.tail.next=l.next,this.tail=b,this.len+=u),this}tag(l,b){return this.uint32((l<<3|b)>>>0)}uint32(l){return this.len+=(this.tail=this.tail.next=new s(r.writeVarint32,(l=l>>>0)<128?1:l<16384?2:l<2097152?3:l<268435456?4:5,l)).len,this}int32(l){return l<0?this._push(r.writeVarint64,10,(0,r.int64FromString)(l.toString())):this.uint32(l)}sint32(l){return this.uint32((l<<1^l>>31)>>>0)}int64(l){const{lo:b,hi:u}=(0,r.int64FromString)(l.toString());return this._push(r.writeVarint64,(0,r.int64Length)(b,u),{lo:b,hi:u})}sint64(l){let{lo:b,hi:u}=(0,r.int64FromString)(l.toString());return[b,u]=(0,r.zzEncode)(b,u),this._push(r.writeVarint64,(0,r.int64Length)(b,u),{lo:b,hi:u})}fixed64(l){const{lo:b,hi:u}=(0,r.int64FromString)(l.toString());return this._push(r.writeFixed32,4,b)._push(r.writeFixed32,4,u)}bool(l){return this._push(r.writeByte,1,l?1:0)}fixed32(l){return this._push(r.writeFixed32,4,l>>>0)}float(l){throw new Error("float not supported"+l)}double(l){throw new Error("double not supported"+l)}bytes(l){const b=l.length>>>0;return b?this.uint32(b)._push(f,b,l):this._push(r.writeByte,1,0)}string(l){const b=(0,i.utf8Length)(l);return b?this.uint32(b)._push(i.utf8Write,b,l):this._push(r.writeByte,1,0)}}M.BinaryWriter=a;function f(I,l,b){if(typeof Uint8Array<"u")l.set(I,b);else for(let u=0;u<I.length;++u)l[b+u]=I[u]}function g(I,l,b){let S=null,p=8192;return function(O){if(O<1||O>4096)return I(O);p+O>8192&&(S=I(8192),p=0);const D=l.call(S,p,p+=O);return p&7&&(p=(p|7)+1),D}}function _(I,l){return RangeError("index out of range: "+I.pos+" + "+(l||1)+" > "+I.len)}return M}var N={},fe;function L(){if(fe)return N;fe=1,Object.defineProperty(N,"__esModule",{value:!0}),N.fromJsonTimestamp=N.fromTimestamp=N.toTimestamp=N.setPaginationParams=N.isObject=N.isSet=N.fromDuration=N.toDuration=N.omitDefault=N.base64FromBytes=N.bytesFromBase64=void 0;var i=(()=>{if(typeof i<"u")return i;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof se<"u")return se;throw"Unable to locate global object"})();const r=i.atob||(p=>i.Buffer.from(p,"base64").toString("binary"));function d(p){const w=r(p),O=new Uint8Array(w.length);for(let D=0;D<w.length;++D)O[D]=w.charCodeAt(D);return O}N.bytesFromBase64=d;const c=i.btoa||(p=>i.Buffer.from(p,"binary").toString("base64"));function s(p){const w=[];return p.forEach(O=>{w.push(String.fromCharCode(O))}),c(w.join(""))}N.base64FromBytes=s;function o(p){if(typeof p=="string")return p===""?void 0:p;if(typeof p=="number")return p===0?void 0:p;if(typeof p=="bigint")return p===BigInt(0)?void 0:p;throw new Error(`Got unsupported type ${typeof p}`)}N.omitDefault=o;function a(p){return{seconds:BigInt(Math.floor(parseInt(p)/1e9)),nanos:parseInt(p)%1e9}}N.toDuration=a;function f(p){return(parseInt(p.seconds.toString())*1e9+p.nanos).toString()}N.fromDuration=f;function g(p){return p!=null}N.isSet=g;function _(p){return typeof p=="object"&&p!==null}N.isObject=_;const I=(p,w)=>(w&&(typeof(w==null?void 0:w.countTotal)<"u"&&(p.params["pagination.count_total"]=w.countTotal),typeof(w==null?void 0:w.key)<"u"&&(p.params["pagination.key"]=Buffer.from(w.key).toString("base64")),typeof(w==null?void 0:w.limit)<"u"&&(p.params["pagination.limit"]=w.limit.toString()),typeof(w==null?void 0:w.offset)<"u"&&(p.params["pagination.offset"]=w.offset.toString()),typeof(w==null?void 0:w.reverse)<"u"&&(p.params["pagination.reverse"]=w.reverse)),p);N.setPaginationParams=I;function l(p){const w=S(p.getTime()/1e3),O=p.getTime()%1e3*1e6;return{seconds:w,nanos:O}}N.toTimestamp=l;function b(p){let w=Number(p.seconds)*1e3;return w+=p.nanos/1e6,new Date(w)}N.fromTimestamp=b;const u=p=>({seconds:g(p.seconds)?BigInt(p.seconds.toString()):BigInt(0),nanos:g(p.nanos)?Number(p.nanos):0});function y(p){return p instanceof Date?l(p):typeof p=="string"?l(new Date(p)):u(p)}N.fromJsonTimestamp=y;function S(p){return BigInt(Math.trunc(p))}return N}var le;function Ne(){if(le)return x;le=1,Object.defineProperty(x,"__esModule",{value:!0}),x.CompactBitArray=x.MultiSignature=x.protobufPackage=void 0;const i=H(),r=L();x.protobufPackage="cosmos.crypto.multisig.v1beta1";function d(){return{signatures:[]}}x.MultiSignature={typeUrl:"/cosmos.crypto.multisig.v1beta1.MultiSignature",encode(s,o=i.BinaryWriter.create()){for(const a of s.signatures)o.uint32(10).bytes(a);return o},decode(s,o){const a=s instanceof i.BinaryReader?s:new i.BinaryReader(s);let f=o===void 0?a.len:a.pos+o;const g=d();for(;a.pos<f;){const _=a.uint32();switch(_>>>3){case 1:g.signatures.push(a.bytes());break;default:a.skipType(_&7);break}}return g},fromJSON(s){const o=d();return Array.isArray(s==null?void 0:s.signatures)&&(o.signatures=s.signatures.map(a=>(0,r.bytesFromBase64)(a))),o},toJSON(s){const o={};return s.signatures?o.signatures=s.signatures.map(a=>(0,r.base64FromBytes)(a!==void 0?a:new Uint8Array)):o.signatures=[],o},fromPartial(s){var a;const o=d();return o.signatures=((a=s.signatures)==null?void 0:a.map(f=>f))||[],o}};function c(){return{extraBitsStored:0,elems:new Uint8Array}}return x.CompactBitArray={typeUrl:"/cosmos.crypto.multisig.v1beta1.CompactBitArray",encode(s,o=i.BinaryWriter.create()){return s.extraBitsStored!==0&&o.uint32(8).uint32(s.extraBitsStored),s.elems.length!==0&&o.uint32(18).bytes(s.elems),o},decode(s,o){const a=s instanceof i.BinaryReader?s:new i.BinaryReader(s);let f=o===void 0?a.len:a.pos+o;const g=c();for(;a.pos<f;){const _=a.uint32();switch(_>>>3){case 1:g.extraBitsStored=a.uint32();break;case 2:g.elems=a.bytes();break;default:a.skipType(_&7);break}}return g},fromJSON(s){const o=c();return(0,r.isSet)(s.extraBitsStored)&&(o.extraBitsStored=Number(s.extraBitsStored)),(0,r.isSet)(s.elems)&&(o.elems=(0,r.bytesFromBase64)(s.elems)),o},toJSON(s){const o={};return s.extraBitsStored!==void 0&&(o.extraBitsStored=Math.round(s.extraBitsStored)),s.elems!==void 0&&(o.elems=(0,r.base64FromBytes)(s.elems!==void 0?s.elems:new Uint8Array)),o},fromPartial(s){const o=c();return o.extraBitsStored=s.extraBitsStored??0,o.elems=s.elems??new Uint8Array,o}},x}var F={},ye;function Ae(){if(ye)return F;ye=1,Object.defineProperty(F,"__esModule",{value:!0}),F.Any=F.protobufPackage=void 0;const i=H(),r=L();F.protobufPackage="google.protobuf";function d(){return{typeUrl:"",value:new Uint8Array}}return F.Any={typeUrl:"/google.protobuf.Any",encode(c,s=i.BinaryWriter.create()){return c.typeUrl!==""&&s.uint32(10).string(c.typeUrl),c.value.length!==0&&s.uint32(18).bytes(c.value),s},decode(c,s){const o=c instanceof i.BinaryReader?c:new i.BinaryReader(c);let a=s===void 0?o.len:o.pos+s;const f=d();for(;o.pos<a;){const g=o.uint32();switch(g>>>3){case 1:f.typeUrl=o.string();break;case 2:f.value=o.bytes();break;default:o.skipType(g&7);break}}return f},fromJSON(c){const s=d();return(0,r.isSet)(c.typeUrl)&&(s.typeUrl=String(c.typeUrl)),(0,r.isSet)(c.value)&&(s.value=(0,r.bytesFromBase64)(c.value)),s},toJSON(c){const s={};return c.typeUrl!==void 0&&(s.typeUrl=c.typeUrl),c.value!==void 0&&(s.value=(0,r.base64FromBytes)(c.value!==void 0?c.value:new Uint8Array)),s},fromPartial(c){const s=d();return s.typeUrl=c.typeUrl??"",s.value=c.value??new Uint8Array,s}},F}var he;function De(){return he||(he=1,function(i){Object.defineProperty(i,"__esModule",{value:!0}),i.SignatureDescriptor_Data_Multi=i.SignatureDescriptor_Data_Single=i.SignatureDescriptor_Data=i.SignatureDescriptor=i.SignatureDescriptors=i.signModeToJSON=i.signModeFromJSON=i.SignMode=i.protobufPackage=void 0;const r=Ne(),d=Ae(),c=H(),s=L();i.protobufPackage="cosmos.tx.signing.v1beta1";var o;(function(u){u[u.SIGN_MODE_UNSPECIFIED=0]="SIGN_MODE_UNSPECIFIED",u[u.SIGN_MODE_DIRECT=1]="SIGN_MODE_DIRECT",u[u.SIGN_MODE_TEXTUAL=2]="SIGN_MODE_TEXTUAL",u[u.SIGN_MODE_DIRECT_AUX=3]="SIGN_MODE_DIRECT_AUX",u[u.SIGN_MODE_LEGACY_AMINO_JSON=127]="SIGN_MODE_LEGACY_AMINO_JSON",u[u.SIGN_MODE_EIP_191=191]="SIGN_MODE_EIP_191",u[u.UNRECOGNIZED=-1]="UNRECOGNIZED"})(o||(i.SignMode=o={}));function a(u){switch(u){case 0:case"SIGN_MODE_UNSPECIFIED":return o.SIGN_MODE_UNSPECIFIED;case 1:case"SIGN_MODE_DIRECT":return o.SIGN_MODE_DIRECT;case 2:case"SIGN_MODE_TEXTUAL":return o.SIGN_MODE_TEXTUAL;case 3:case"SIGN_MODE_DIRECT_AUX":return o.SIGN_MODE_DIRECT_AUX;case 127:case"SIGN_MODE_LEGACY_AMINO_JSON":return o.SIGN_MODE_LEGACY_AMINO_JSON;case 191:case"SIGN_MODE_EIP_191":return o.SIGN_MODE_EIP_191;case-1:case"UNRECOGNIZED":default:return o.UNRECOGNIZED}}i.signModeFromJSON=a;function f(u){switch(u){case o.SIGN_MODE_UNSPECIFIED:return"SIGN_MODE_UNSPECIFIED";case o.SIGN_MODE_DIRECT:return"SIGN_MODE_DIRECT";case o.SIGN_MODE_TEXTUAL:return"SIGN_MODE_TEXTUAL";case o.SIGN_MODE_DIRECT_AUX:return"SIGN_MODE_DIRECT_AUX";case o.SIGN_MODE_LEGACY_AMINO_JSON:return"SIGN_MODE_LEGACY_AMINO_JSON";case o.SIGN_MODE_EIP_191:return"SIGN_MODE_EIP_191";case o.UNRECOGNIZED:default:return"UNRECOGNIZED"}}i.signModeToJSON=f;function g(){return{signatures:[]}}i.SignatureDescriptors={typeUrl:"/cosmos.tx.signing.v1beta1.SignatureDescriptors",encode(u,y=c.BinaryWriter.create()){for(const S of u.signatures)i.SignatureDescriptor.encode(S,y.uint32(10).fork()).ldelim();return y},decode(u,y){const S=u instanceof c.BinaryReader?u:new c.BinaryReader(u);let p=y===void 0?S.len:S.pos+y;const w=g();for(;S.pos<p;){const O=S.uint32();switch(O>>>3){case 1:w.signatures.push(i.SignatureDescriptor.decode(S,S.uint32()));break;default:S.skipType(O&7);break}}return w},fromJSON(u){const y=g();return Array.isArray(u==null?void 0:u.signatures)&&(y.signatures=u.signatures.map(S=>i.SignatureDescriptor.fromJSON(S))),y},toJSON(u){const y={};return u.signatures?y.signatures=u.signatures.map(S=>S?i.SignatureDescriptor.toJSON(S):void 0):y.signatures=[],y},fromPartial(u){var S;const y=g();return y.signatures=((S=u.signatures)==null?void 0:S.map(p=>i.SignatureDescriptor.fromPartial(p)))||[],y}};function _(){return{publicKey:void 0,data:void 0,sequence:BigInt(0)}}i.SignatureDescriptor={typeUrl:"/cosmos.tx.signing.v1beta1.SignatureDescriptor",encode(u,y=c.BinaryWriter.create()){return u.publicKey!==void 0&&d.Any.encode(u.publicKey,y.uint32(10).fork()).ldelim(),u.data!==void 0&&i.SignatureDescriptor_Data.encode(u.data,y.uint32(18).fork()).ldelim(),u.sequence!==BigInt(0)&&y.uint32(24).uint64(u.sequence),y},decode(u,y){const S=u instanceof c.BinaryReader?u:new c.BinaryReader(u);let p=y===void 0?S.len:S.pos+y;const w=_();for(;S.pos<p;){const O=S.uint32();switch(O>>>3){case 1:w.publicKey=d.Any.decode(S,S.uint32());break;case 2:w.data=i.SignatureDescriptor_Data.decode(S,S.uint32());break;case 3:w.sequence=S.uint64();break;default:S.skipType(O&7);break}}return w},fromJSON(u){const y=_();return(0,s.isSet)(u.publicKey)&&(y.publicKey=d.Any.fromJSON(u.publicKey)),(0,s.isSet)(u.data)&&(y.data=i.SignatureDescriptor_Data.fromJSON(u.data)),(0,s.isSet)(u.sequence)&&(y.sequence=BigInt(u.sequence.toString())),y},toJSON(u){const y={};return u.publicKey!==void 0&&(y.publicKey=u.publicKey?d.Any.toJSON(u.publicKey):void 0),u.data!==void 0&&(y.data=u.data?i.SignatureDescriptor_Data.toJSON(u.data):void 0),u.sequence!==void 0&&(y.sequence=(u.sequence||BigInt(0)).toString()),y},fromPartial(u){const y=_();return u.publicKey!==void 0&&u.publicKey!==null&&(y.publicKey=d.Any.fromPartial(u.publicKey)),u.data!==void 0&&u.data!==null&&(y.data=i.SignatureDescriptor_Data.fromPartial(u.data)),u.sequence!==void 0&&u.sequence!==null&&(y.sequence=BigInt(u.sequence.toString())),y}};function I(){return{single:void 0,multi:void 0}}i.SignatureDescriptor_Data={typeUrl:"/cosmos.tx.signing.v1beta1.Data",encode(u,y=c.BinaryWriter.create()){return u.single!==void 0&&i.SignatureDescriptor_Data_Single.encode(u.single,y.uint32(10).fork()).ldelim(),u.multi!==void 0&&i.SignatureDescriptor_Data_Multi.encode(u.multi,y.uint32(18).fork()).ldelim(),y},decode(u,y){const S=u instanceof c.BinaryReader?u:new c.BinaryReader(u);let p=y===void 0?S.len:S.pos+y;const w=I();for(;S.pos<p;){const O=S.uint32();switch(O>>>3){case 1:w.single=i.SignatureDescriptor_Data_Single.decode(S,S.uint32());break;case 2:w.multi=i.SignatureDescriptor_Data_Multi.decode(S,S.uint32());break;default:S.skipType(O&7);break}}return w},fromJSON(u){const y=I();return(0,s.isSet)(u.single)&&(y.single=i.SignatureDescriptor_Data_Single.fromJSON(u.single)),(0,s.isSet)(u.multi)&&(y.multi=i.SignatureDescriptor_Data_Multi.fromJSON(u.multi)),y},toJSON(u){const y={};return u.single!==void 0&&(y.single=u.single?i.SignatureDescriptor_Data_Single.toJSON(u.single):void 0),u.multi!==void 0&&(y.multi=u.multi?i.SignatureDescriptor_Data_Multi.toJSON(u.multi):void 0),y},fromPartial(u){const y=I();return u.single!==void 0&&u.single!==null&&(y.single=i.SignatureDescriptor_Data_Single.fromPartial(u.single)),u.multi!==void 0&&u.multi!==null&&(y.multi=i.SignatureDescriptor_Data_Multi.fromPartial(u.multi)),y}};function l(){return{mode:0,signature:new Uint8Array}}i.SignatureDescriptor_Data_Single={typeUrl:"/cosmos.tx.signing.v1beta1.Single",encode(u,y=c.BinaryWriter.create()){return u.mode!==0&&y.uint32(8).int32(u.mode),u.signature.length!==0&&y.uint32(18).bytes(u.signature),y},decode(u,y){const S=u instanceof c.BinaryReader?u:new c.BinaryReader(u);let p=y===void 0?S.len:S.pos+y;const w=l();for(;S.pos<p;){const O=S.uint32();switch(O>>>3){case 1:w.mode=S.int32();break;case 2:w.signature=S.bytes();break;default:S.skipType(O&7);break}}return w},fromJSON(u){const y=l();return(0,s.isSet)(u.mode)&&(y.mode=a(u.mode)),(0,s.isSet)(u.signature)&&(y.signature=(0,s.bytesFromBase64)(u.signature)),y},toJSON(u){const y={};return u.mode!==void 0&&(y.mode=f(u.mode)),u.signature!==void 0&&(y.signature=(0,s.base64FromBytes)(u.signature!==void 0?u.signature:new Uint8Array)),y},fromPartial(u){const y=l();return y.mode=u.mode??0,y.signature=u.signature??new Uint8Array,y}};function b(){return{bitarray:void 0,signatures:[]}}i.SignatureDescriptor_Data_Multi={typeUrl:"/cosmos.tx.signing.v1beta1.Multi",encode(u,y=c.BinaryWriter.create()){u.bitarray!==void 0&&r.CompactBitArray.encode(u.bitarray,y.uint32(10).fork()).ldelim();for(const S of u.signatures)i.SignatureDescriptor_Data.encode(S,y.uint32(18).fork()).ldelim();return y},decode(u,y){const S=u instanceof c.BinaryReader?u:new c.BinaryReader(u);let p=y===void 0?S.len:S.pos+y;const w=b();for(;S.pos<p;){const O=S.uint32();switch(O>>>3){case 1:w.bitarray=r.CompactBitArray.decode(S,S.uint32());break;case 2:w.signatures.push(i.SignatureDescriptor_Data.decode(S,S.uint32()));break;default:S.skipType(O&7);break}}return w},fromJSON(u){const y=b();return(0,s.isSet)(u.bitarray)&&(y.bitarray=r.CompactBitArray.fromJSON(u.bitarray)),Array.isArray(u==null?void 0:u.signatures)&&(y.signatures=u.signatures.map(S=>i.SignatureDescriptor_Data.fromJSON(S))),y},toJSON(u){const y={};return u.bitarray!==void 0&&(y.bitarray=u.bitarray?r.CompactBitArray.toJSON(u.bitarray):void 0),u.signatures?y.signatures=u.signatures.map(S=>S?i.SignatureDescriptor_Data.toJSON(S):void 0):y.signatures=[],y},fromPartial(u){var S;const y=b();return u.bitarray!==void 0&&u.bitarray!==null&&(y.bitarray=r.CompactBitArray.fromPartial(u.bitarray)),y.signatures=((S=u.signatures)==null?void 0:S.map(p=>i.SignatureDescriptor_Data.fromPartial(p)))||[],y}}}(j)),j}var He=De(),ee={},v={},me;function Le(){if(me)return v;me=1,Object.defineProperty(v,"__esModule",{value:!0}),v.DecProto=v.IntProto=v.DecCoin=v.Coin=v.protobufPackage=void 0;const i=H(),r=L();v.protobufPackage="cosmos.base.v1beta1";function d(){return{denom:"",amount:""}}v.Coin={typeUrl:"/cosmos.base.v1beta1.Coin",encode(a,f=i.BinaryWriter.create()){return a.denom!==""&&f.uint32(10).string(a.denom),a.amount!==""&&f.uint32(18).string(a.amount),f},decode(a,f){const g=a instanceof i.BinaryReader?a:new i.BinaryReader(a);let _=f===void 0?g.len:g.pos+f;const I=d();for(;g.pos<_;){const l=g.uint32();switch(l>>>3){case 1:I.denom=g.string();break;case 2:I.amount=g.string();break;default:g.skipType(l&7);break}}return I},fromJSON(a){const f=d();return(0,r.isSet)(a.denom)&&(f.denom=String(a.denom)),(0,r.isSet)(a.amount)&&(f.amount=String(a.amount)),f},toJSON(a){const f={};return a.denom!==void 0&&(f.denom=a.denom),a.amount!==void 0&&(f.amount=a.amount),f},fromPartial(a){const f=d();return f.denom=a.denom??"",f.amount=a.amount??"",f}};function c(){return{denom:"",amount:""}}v.DecCoin={typeUrl:"/cosmos.base.v1beta1.DecCoin",encode(a,f=i.BinaryWriter.create()){return a.denom!==""&&f.uint32(10).string(a.denom),a.amount!==""&&f.uint32(18).string(a.amount),f},decode(a,f){const g=a instanceof i.BinaryReader?a:new i.BinaryReader(a);let _=f===void 0?g.len:g.pos+f;const I=c();for(;g.pos<_;){const l=g.uint32();switch(l>>>3){case 1:I.denom=g.string();break;case 2:I.amount=g.string();break;default:g.skipType(l&7);break}}return I},fromJSON(a){const f=c();return(0,r.isSet)(a.denom)&&(f.denom=String(a.denom)),(0,r.isSet)(a.amount)&&(f.amount=String(a.amount)),f},toJSON(a){const f={};return a.denom!==void 0&&(f.denom=a.denom),a.amount!==void 0&&(f.amount=a.amount),f},fromPartial(a){const f=c();return f.denom=a.denom??"",f.amount=a.amount??"",f}};function s(){return{int:""}}v.IntProto={typeUrl:"/cosmos.base.v1beta1.IntProto",encode(a,f=i.BinaryWriter.create()){return a.int!==""&&f.uint32(10).string(a.int),f},decode(a,f){const g=a instanceof i.BinaryReader?a:new i.BinaryReader(a);let _=f===void 0?g.len:g.pos+f;const I=s();for(;g.pos<_;){const l=g.uint32();switch(l>>>3){case 1:I.int=g.string();break;default:g.skipType(l&7);break}}return I},fromJSON(a){const f=s();return(0,r.isSet)(a.int)&&(f.int=String(a.int)),f},toJSON(a){const f={};return a.int!==void 0&&(f.int=a.int),f},fromPartial(a){const f=s();return f.int=a.int??"",f}};function o(){return{dec:""}}return v.DecProto={typeUrl:"/cosmos.base.v1beta1.DecProto",encode(a,f=i.BinaryWriter.create()){return a.dec!==""&&f.uint32(10).string(a.dec),f},decode(a,f){const g=a instanceof i.BinaryReader?a:new i.BinaryReader(a);let _=f===void 0?g.len:g.pos+f;const I=o();for(;g.pos<_;){const l=g.uint32();switch(l>>>3){case 1:I.dec=g.string();break;default:g.skipType(l&7);break}}return I},fromJSON(a){const f=o();return(0,r.isSet)(a.dec)&&(f.dec=String(a.dec)),f},toJSON(a){const f={};return a.dec!==void 0&&(f.dec=a.dec),f},fromPartial(a){const f=o();return f.dec=a.dec??"",f}},v}var pe;function ze(){return pe||(pe=1,function(i){Object.defineProperty(i,"__esModule",{value:!0}),i.AuxSignerData=i.Tip=i.Fee=i.ModeInfo_Multi=i.ModeInfo_Single=i.ModeInfo=i.SignerInfo=i.AuthInfo=i.TxBody=i.SignDocDirectAux=i.SignDoc=i.TxRaw=i.Tx=i.protobufPackage=void 0;const r=Ae(),d=De(),c=Ne(),s=Le(),o=H(),a=L();i.protobufPackage="cosmos.tx.v1beta1";function f(){return{body:void 0,authInfo:void 0,signatures:[]}}i.Tx={typeUrl:"/cosmos.tx.v1beta1.Tx",encode(e,n=o.BinaryWriter.create()){e.body!==void 0&&i.TxBody.encode(e.body,n.uint32(10).fork()).ldelim(),e.authInfo!==void 0&&i.AuthInfo.encode(e.authInfo,n.uint32(18).fork()).ldelim();for(const t of e.signatures)n.uint32(26).bytes(t);return n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=f();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.body=i.TxBody.decode(t,t.uint32());break;case 2:h.authInfo=i.AuthInfo.decode(t,t.uint32());break;case 3:h.signatures.push(t.bytes());break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=f();return(0,a.isSet)(e.body)&&(n.body=i.TxBody.fromJSON(e.body)),(0,a.isSet)(e.authInfo)&&(n.authInfo=i.AuthInfo.fromJSON(e.authInfo)),Array.isArray(e==null?void 0:e.signatures)&&(n.signatures=e.signatures.map(t=>(0,a.bytesFromBase64)(t))),n},toJSON(e){const n={};return e.body!==void 0&&(n.body=e.body?i.TxBody.toJSON(e.body):void 0),e.authInfo!==void 0&&(n.authInfo=e.authInfo?i.AuthInfo.toJSON(e.authInfo):void 0),e.signatures?n.signatures=e.signatures.map(t=>(0,a.base64FromBytes)(t!==void 0?t:new Uint8Array)):n.signatures=[],n},fromPartial(e){var t;const n=f();return e.body!==void 0&&e.body!==null&&(n.body=i.TxBody.fromPartial(e.body)),e.authInfo!==void 0&&e.authInfo!==null&&(n.authInfo=i.AuthInfo.fromPartial(e.authInfo)),n.signatures=((t=e.signatures)==null?void 0:t.map(m=>m))||[],n}};function g(){return{bodyBytes:new Uint8Array,authInfoBytes:new Uint8Array,signatures:[]}}i.TxRaw={typeUrl:"/cosmos.tx.v1beta1.TxRaw",encode(e,n=o.BinaryWriter.create()){e.bodyBytes.length!==0&&n.uint32(10).bytes(e.bodyBytes),e.authInfoBytes.length!==0&&n.uint32(18).bytes(e.authInfoBytes);for(const t of e.signatures)n.uint32(26).bytes(t);return n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=g();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.bodyBytes=t.bytes();break;case 2:h.authInfoBytes=t.bytes();break;case 3:h.signatures.push(t.bytes());break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=g();return(0,a.isSet)(e.bodyBytes)&&(n.bodyBytes=(0,a.bytesFromBase64)(e.bodyBytes)),(0,a.isSet)(e.authInfoBytes)&&(n.authInfoBytes=(0,a.bytesFromBase64)(e.authInfoBytes)),Array.isArray(e==null?void 0:e.signatures)&&(n.signatures=e.signatures.map(t=>(0,a.bytesFromBase64)(t))),n},toJSON(e){const n={};return e.bodyBytes!==void 0&&(n.bodyBytes=(0,a.base64FromBytes)(e.bodyBytes!==void 0?e.bodyBytes:new Uint8Array)),e.authInfoBytes!==void 0&&(n.authInfoBytes=(0,a.base64FromBytes)(e.authInfoBytes!==void 0?e.authInfoBytes:new Uint8Array)),e.signatures?n.signatures=e.signatures.map(t=>(0,a.base64FromBytes)(t!==void 0?t:new Uint8Array)):n.signatures=[],n},fromPartial(e){var t;const n=g();return n.bodyBytes=e.bodyBytes??new Uint8Array,n.authInfoBytes=e.authInfoBytes??new Uint8Array,n.signatures=((t=e.signatures)==null?void 0:t.map(m=>m))||[],n}};function _(){return{bodyBytes:new Uint8Array,authInfoBytes:new Uint8Array,chainId:"",accountNumber:BigInt(0)}}i.SignDoc={typeUrl:"/cosmos.tx.v1beta1.SignDoc",encode(e,n=o.BinaryWriter.create()){return e.bodyBytes.length!==0&&n.uint32(10).bytes(e.bodyBytes),e.authInfoBytes.length!==0&&n.uint32(18).bytes(e.authInfoBytes),e.chainId!==""&&n.uint32(26).string(e.chainId),e.accountNumber!==BigInt(0)&&n.uint32(32).uint64(e.accountNumber),n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=_();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.bodyBytes=t.bytes();break;case 2:h.authInfoBytes=t.bytes();break;case 3:h.chainId=t.string();break;case 4:h.accountNumber=t.uint64();break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=_();return(0,a.isSet)(e.bodyBytes)&&(n.bodyBytes=(0,a.bytesFromBase64)(e.bodyBytes)),(0,a.isSet)(e.authInfoBytes)&&(n.authInfoBytes=(0,a.bytesFromBase64)(e.authInfoBytes)),(0,a.isSet)(e.chainId)&&(n.chainId=String(e.chainId)),(0,a.isSet)(e.accountNumber)&&(n.accountNumber=BigInt(e.accountNumber.toString())),n},toJSON(e){const n={};return e.bodyBytes!==void 0&&(n.bodyBytes=(0,a.base64FromBytes)(e.bodyBytes!==void 0?e.bodyBytes:new Uint8Array)),e.authInfoBytes!==void 0&&(n.authInfoBytes=(0,a.base64FromBytes)(e.authInfoBytes!==void 0?e.authInfoBytes:new Uint8Array)),e.chainId!==void 0&&(n.chainId=e.chainId),e.accountNumber!==void 0&&(n.accountNumber=(e.accountNumber||BigInt(0)).toString()),n},fromPartial(e){const n=_();return n.bodyBytes=e.bodyBytes??new Uint8Array,n.authInfoBytes=e.authInfoBytes??new Uint8Array,n.chainId=e.chainId??"",e.accountNumber!==void 0&&e.accountNumber!==null&&(n.accountNumber=BigInt(e.accountNumber.toString())),n}};function I(){return{bodyBytes:new Uint8Array,publicKey:void 0,chainId:"",accountNumber:BigInt(0),sequence:BigInt(0),tip:void 0}}i.SignDocDirectAux={typeUrl:"/cosmos.tx.v1beta1.SignDocDirectAux",encode(e,n=o.BinaryWriter.create()){return e.bodyBytes.length!==0&&n.uint32(10).bytes(e.bodyBytes),e.publicKey!==void 0&&r.Any.encode(e.publicKey,n.uint32(18).fork()).ldelim(),e.chainId!==""&&n.uint32(26).string(e.chainId),e.accountNumber!==BigInt(0)&&n.uint32(32).uint64(e.accountNumber),e.sequence!==BigInt(0)&&n.uint32(40).uint64(e.sequence),e.tip!==void 0&&i.Tip.encode(e.tip,n.uint32(50).fork()).ldelim(),n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=I();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.bodyBytes=t.bytes();break;case 2:h.publicKey=r.Any.decode(t,t.uint32());break;case 3:h.chainId=t.string();break;case 4:h.accountNumber=t.uint64();break;case 5:h.sequence=t.uint64();break;case 6:h.tip=i.Tip.decode(t,t.uint32());break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=I();return(0,a.isSet)(e.bodyBytes)&&(n.bodyBytes=(0,a.bytesFromBase64)(e.bodyBytes)),(0,a.isSet)(e.publicKey)&&(n.publicKey=r.Any.fromJSON(e.publicKey)),(0,a.isSet)(e.chainId)&&(n.chainId=String(e.chainId)),(0,a.isSet)(e.accountNumber)&&(n.accountNumber=BigInt(e.accountNumber.toString())),(0,a.isSet)(e.sequence)&&(n.sequence=BigInt(e.sequence.toString())),(0,a.isSet)(e.tip)&&(n.tip=i.Tip.fromJSON(e.tip)),n},toJSON(e){const n={};return e.bodyBytes!==void 0&&(n.bodyBytes=(0,a.base64FromBytes)(e.bodyBytes!==void 0?e.bodyBytes:new Uint8Array)),e.publicKey!==void 0&&(n.publicKey=e.publicKey?r.Any.toJSON(e.publicKey):void 0),e.chainId!==void 0&&(n.chainId=e.chainId),e.accountNumber!==void 0&&(n.accountNumber=(e.accountNumber||BigInt(0)).toString()),e.sequence!==void 0&&(n.sequence=(e.sequence||BigInt(0)).toString()),e.tip!==void 0&&(n.tip=e.tip?i.Tip.toJSON(e.tip):void 0),n},fromPartial(e){const n=I();return n.bodyBytes=e.bodyBytes??new Uint8Array,e.publicKey!==void 0&&e.publicKey!==null&&(n.publicKey=r.Any.fromPartial(e.publicKey)),n.chainId=e.chainId??"",e.accountNumber!==void 0&&e.accountNumber!==null&&(n.accountNumber=BigInt(e.accountNumber.toString())),e.sequence!==void 0&&e.sequence!==null&&(n.sequence=BigInt(e.sequence.toString())),e.tip!==void 0&&e.tip!==null&&(n.tip=i.Tip.fromPartial(e.tip)),n}};function l(){return{messages:[],memo:"",timeoutHeight:BigInt(0),extensionOptions:[],nonCriticalExtensionOptions:[]}}i.TxBody={typeUrl:"/cosmos.tx.v1beta1.TxBody",encode(e,n=o.BinaryWriter.create()){for(const t of e.messages)r.Any.encode(t,n.uint32(10).fork()).ldelim();e.memo!==""&&n.uint32(18).string(e.memo),e.timeoutHeight!==BigInt(0)&&n.uint32(24).uint64(e.timeoutHeight);for(const t of e.extensionOptions)r.Any.encode(t,n.uint32(8186).fork()).ldelim();for(const t of e.nonCriticalExtensionOptions)r.Any.encode(t,n.uint32(16378).fork()).ldelim();return n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=l();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.messages.push(r.Any.decode(t,t.uint32()));break;case 2:h.memo=t.string();break;case 3:h.timeoutHeight=t.uint64();break;case 1023:h.extensionOptions.push(r.Any.decode(t,t.uint32()));break;case 2047:h.nonCriticalExtensionOptions.push(r.Any.decode(t,t.uint32()));break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=l();return Array.isArray(e==null?void 0:e.messages)&&(n.messages=e.messages.map(t=>r.Any.fromJSON(t))),(0,a.isSet)(e.memo)&&(n.memo=String(e.memo)),(0,a.isSet)(e.timeoutHeight)&&(n.timeoutHeight=BigInt(e.timeoutHeight.toString())),Array.isArray(e==null?void 0:e.extensionOptions)&&(n.extensionOptions=e.extensionOptions.map(t=>r.Any.fromJSON(t))),Array.isArray(e==null?void 0:e.nonCriticalExtensionOptions)&&(n.nonCriticalExtensionOptions=e.nonCriticalExtensionOptions.map(t=>r.Any.fromJSON(t))),n},toJSON(e){const n={};return e.messages?n.messages=e.messages.map(t=>t?r.Any.toJSON(t):void 0):n.messages=[],e.memo!==void 0&&(n.memo=e.memo),e.timeoutHeight!==void 0&&(n.timeoutHeight=(e.timeoutHeight||BigInt(0)).toString()),e.extensionOptions?n.extensionOptions=e.extensionOptions.map(t=>t?r.Any.toJSON(t):void 0):n.extensionOptions=[],e.nonCriticalExtensionOptions?n.nonCriticalExtensionOptions=e.nonCriticalExtensionOptions.map(t=>t?r.Any.toJSON(t):void 0):n.nonCriticalExtensionOptions=[],n},fromPartial(e){var t,m,h;const n=l();return n.messages=((t=e.messages)==null?void 0:t.map(B=>r.Any.fromPartial(B)))||[],n.memo=e.memo??"",e.timeoutHeight!==void 0&&e.timeoutHeight!==null&&(n.timeoutHeight=BigInt(e.timeoutHeight.toString())),n.extensionOptions=((m=e.extensionOptions)==null?void 0:m.map(B=>r.Any.fromPartial(B)))||[],n.nonCriticalExtensionOptions=((h=e.nonCriticalExtensionOptions)==null?void 0:h.map(B=>r.Any.fromPartial(B)))||[],n}};function b(){return{signerInfos:[],fee:void 0,tip:void 0}}i.AuthInfo={typeUrl:"/cosmos.tx.v1beta1.AuthInfo",encode(e,n=o.BinaryWriter.create()){for(const t of e.signerInfos)i.SignerInfo.encode(t,n.uint32(10).fork()).ldelim();return e.fee!==void 0&&i.Fee.encode(e.fee,n.uint32(18).fork()).ldelim(),e.tip!==void 0&&i.Tip.encode(e.tip,n.uint32(26).fork()).ldelim(),n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=b();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.signerInfos.push(i.SignerInfo.decode(t,t.uint32()));break;case 2:h.fee=i.Fee.decode(t,t.uint32());break;case 3:h.tip=i.Tip.decode(t,t.uint32());break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=b();return Array.isArray(e==null?void 0:e.signerInfos)&&(n.signerInfos=e.signerInfos.map(t=>i.SignerInfo.fromJSON(t))),(0,a.isSet)(e.fee)&&(n.fee=i.Fee.fromJSON(e.fee)),(0,a.isSet)(e.tip)&&(n.tip=i.Tip.fromJSON(e.tip)),n},toJSON(e){const n={};return e.signerInfos?n.signerInfos=e.signerInfos.map(t=>t?i.SignerInfo.toJSON(t):void 0):n.signerInfos=[],e.fee!==void 0&&(n.fee=e.fee?i.Fee.toJSON(e.fee):void 0),e.tip!==void 0&&(n.tip=e.tip?i.Tip.toJSON(e.tip):void 0),n},fromPartial(e){var t;const n=b();return n.signerInfos=((t=e.signerInfos)==null?void 0:t.map(m=>i.SignerInfo.fromPartial(m)))||[],e.fee!==void 0&&e.fee!==null&&(n.fee=i.Fee.fromPartial(e.fee)),e.tip!==void 0&&e.tip!==null&&(n.tip=i.Tip.fromPartial(e.tip)),n}};function u(){return{publicKey:void 0,modeInfo:void 0,sequence:BigInt(0)}}i.SignerInfo={typeUrl:"/cosmos.tx.v1beta1.SignerInfo",encode(e,n=o.BinaryWriter.create()){return e.publicKey!==void 0&&r.Any.encode(e.publicKey,n.uint32(10).fork()).ldelim(),e.modeInfo!==void 0&&i.ModeInfo.encode(e.modeInfo,n.uint32(18).fork()).ldelim(),e.sequence!==BigInt(0)&&n.uint32(24).uint64(e.sequence),n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=u();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.publicKey=r.Any.decode(t,t.uint32());break;case 2:h.modeInfo=i.ModeInfo.decode(t,t.uint32());break;case 3:h.sequence=t.uint64();break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=u();return(0,a.isSet)(e.publicKey)&&(n.publicKey=r.Any.fromJSON(e.publicKey)),(0,a.isSet)(e.modeInfo)&&(n.modeInfo=i.ModeInfo.fromJSON(e.modeInfo)),(0,a.isSet)(e.sequence)&&(n.sequence=BigInt(e.sequence.toString())),n},toJSON(e){const n={};return e.publicKey!==void 0&&(n.publicKey=e.publicKey?r.Any.toJSON(e.publicKey):void 0),e.modeInfo!==void 0&&(n.modeInfo=e.modeInfo?i.ModeInfo.toJSON(e.modeInfo):void 0),e.sequence!==void 0&&(n.sequence=(e.sequence||BigInt(0)).toString()),n},fromPartial(e){const n=u();return e.publicKey!==void 0&&e.publicKey!==null&&(n.publicKey=r.Any.fromPartial(e.publicKey)),e.modeInfo!==void 0&&e.modeInfo!==null&&(n.modeInfo=i.ModeInfo.fromPartial(e.modeInfo)),e.sequence!==void 0&&e.sequence!==null&&(n.sequence=BigInt(e.sequence.toString())),n}};function y(){return{single:void 0,multi:void 0}}i.ModeInfo={typeUrl:"/cosmos.tx.v1beta1.ModeInfo",encode(e,n=o.BinaryWriter.create()){return e.single!==void 0&&i.ModeInfo_Single.encode(e.single,n.uint32(10).fork()).ldelim(),e.multi!==void 0&&i.ModeInfo_Multi.encode(e.multi,n.uint32(18).fork()).ldelim(),n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=y();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.single=i.ModeInfo_Single.decode(t,t.uint32());break;case 2:h.multi=i.ModeInfo_Multi.decode(t,t.uint32());break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=y();return(0,a.isSet)(e.single)&&(n.single=i.ModeInfo_Single.fromJSON(e.single)),(0,a.isSet)(e.multi)&&(n.multi=i.ModeInfo_Multi.fromJSON(e.multi)),n},toJSON(e){const n={};return e.single!==void 0&&(n.single=e.single?i.ModeInfo_Single.toJSON(e.single):void 0),e.multi!==void 0&&(n.multi=e.multi?i.ModeInfo_Multi.toJSON(e.multi):void 0),n},fromPartial(e){const n=y();return e.single!==void 0&&e.single!==null&&(n.single=i.ModeInfo_Single.fromPartial(e.single)),e.multi!==void 0&&e.multi!==null&&(n.multi=i.ModeInfo_Multi.fromPartial(e.multi)),n}};function S(){return{mode:0}}i.ModeInfo_Single={typeUrl:"/cosmos.tx.v1beta1.Single",encode(e,n=o.BinaryWriter.create()){return e.mode!==0&&n.uint32(8).int32(e.mode),n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=S();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.mode=t.int32();break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=S();return(0,a.isSet)(e.mode)&&(n.mode=(0,d.signModeFromJSON)(e.mode)),n},toJSON(e){const n={};return e.mode!==void 0&&(n.mode=(0,d.signModeToJSON)(e.mode)),n},fromPartial(e){const n=S();return n.mode=e.mode??0,n}};function p(){return{bitarray:void 0,modeInfos:[]}}i.ModeInfo_Multi={typeUrl:"/cosmos.tx.v1beta1.Multi",encode(e,n=o.BinaryWriter.create()){e.bitarray!==void 0&&c.CompactBitArray.encode(e.bitarray,n.uint32(10).fork()).ldelim();for(const t of e.modeInfos)i.ModeInfo.encode(t,n.uint32(18).fork()).ldelim();return n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=p();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.bitarray=c.CompactBitArray.decode(t,t.uint32());break;case 2:h.modeInfos.push(i.ModeInfo.decode(t,t.uint32()));break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=p();return(0,a.isSet)(e.bitarray)&&(n.bitarray=c.CompactBitArray.fromJSON(e.bitarray)),Array.isArray(e==null?void 0:e.modeInfos)&&(n.modeInfos=e.modeInfos.map(t=>i.ModeInfo.fromJSON(t))),n},toJSON(e){const n={};return e.bitarray!==void 0&&(n.bitarray=e.bitarray?c.CompactBitArray.toJSON(e.bitarray):void 0),e.modeInfos?n.modeInfos=e.modeInfos.map(t=>t?i.ModeInfo.toJSON(t):void 0):n.modeInfos=[],n},fromPartial(e){var t;const n=p();return e.bitarray!==void 0&&e.bitarray!==null&&(n.bitarray=c.CompactBitArray.fromPartial(e.bitarray)),n.modeInfos=((t=e.modeInfos)==null?void 0:t.map(m=>i.ModeInfo.fromPartial(m)))||[],n}};function w(){return{amount:[],gasLimit:BigInt(0),payer:"",granter:""}}i.Fee={typeUrl:"/cosmos.tx.v1beta1.Fee",encode(e,n=o.BinaryWriter.create()){for(const t of e.amount)s.Coin.encode(t,n.uint32(10).fork()).ldelim();return e.gasLimit!==BigInt(0)&&n.uint32(16).uint64(e.gasLimit),e.payer!==""&&n.uint32(26).string(e.payer),e.granter!==""&&n.uint32(34).string(e.granter),n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=w();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.amount.push(s.Coin.decode(t,t.uint32()));break;case 2:h.gasLimit=t.uint64();break;case 3:h.payer=t.string();break;case 4:h.granter=t.string();break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=w();return Array.isArray(e==null?void 0:e.amount)&&(n.amount=e.amount.map(t=>s.Coin.fromJSON(t))),(0,a.isSet)(e.gasLimit)&&(n.gasLimit=BigInt(e.gasLimit.toString())),(0,a.isSet)(e.payer)&&(n.payer=String(e.payer)),(0,a.isSet)(e.granter)&&(n.granter=String(e.granter)),n},toJSON(e){const n={};return e.amount?n.amount=e.amount.map(t=>t?s.Coin.toJSON(t):void 0):n.amount=[],e.gasLimit!==void 0&&(n.gasLimit=(e.gasLimit||BigInt(0)).toString()),e.payer!==void 0&&(n.payer=e.payer),e.granter!==void 0&&(n.granter=e.granter),n},fromPartial(e){var t;const n=w();return n.amount=((t=e.amount)==null?void 0:t.map(m=>s.Coin.fromPartial(m)))||[],e.gasLimit!==void 0&&e.gasLimit!==null&&(n.gasLimit=BigInt(e.gasLimit.toString())),n.payer=e.payer??"",n.granter=e.granter??"",n}};function O(){return{amount:[],tipper:""}}i.Tip={typeUrl:"/cosmos.tx.v1beta1.Tip",encode(e,n=o.BinaryWriter.create()){for(const t of e.amount)s.Coin.encode(t,n.uint32(10).fork()).ldelim();return e.tipper!==""&&n.uint32(18).string(e.tipper),n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=O();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.amount.push(s.Coin.decode(t,t.uint32()));break;case 2:h.tipper=t.string();break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=O();return Array.isArray(e==null?void 0:e.amount)&&(n.amount=e.amount.map(t=>s.Coin.fromJSON(t))),(0,a.isSet)(e.tipper)&&(n.tipper=String(e.tipper)),n},toJSON(e){const n={};return e.amount?n.amount=e.amount.map(t=>t?s.Coin.toJSON(t):void 0):n.amount=[],e.tipper!==void 0&&(n.tipper=e.tipper),n},fromPartial(e){var t;const n=O();return n.amount=((t=e.amount)==null?void 0:t.map(m=>s.Coin.fromPartial(m)))||[],n.tipper=e.tipper??"",n}};function D(){return{address:"",signDoc:void 0,mode:0,sig:new Uint8Array}}i.AuxSignerData={typeUrl:"/cosmos.tx.v1beta1.AuxSignerData",encode(e,n=o.BinaryWriter.create()){return e.address!==""&&n.uint32(10).string(e.address),e.signDoc!==void 0&&i.SignDocDirectAux.encode(e.signDoc,n.uint32(18).fork()).ldelim(),e.mode!==0&&n.uint32(24).int32(e.mode),e.sig.length!==0&&n.uint32(34).bytes(e.sig),n},decode(e,n){const t=e instanceof o.BinaryReader?e:new o.BinaryReader(e);let m=n===void 0?t.len:t.pos+n;const h=D();for(;t.pos<m;){const B=t.uint32();switch(B>>>3){case 1:h.address=t.string();break;case 2:h.signDoc=i.SignDocDirectAux.decode(t,t.uint32());break;case 3:h.mode=t.int32();break;case 4:h.sig=t.bytes();break;default:t.skipType(B&7);break}}return h},fromJSON(e){const n=D();return(0,a.isSet)(e.address)&&(n.address=String(e.address)),(0,a.isSet)(e.signDoc)&&(n.signDoc=i.SignDocDirectAux.fromJSON(e.signDoc)),(0,a.isSet)(e.mode)&&(n.mode=(0,d.signModeFromJSON)(e.mode)),(0,a.isSet)(e.sig)&&(n.sig=(0,a.bytesFromBase64)(e.sig)),n},toJSON(e){const n={};return e.address!==void 0&&(n.address=e.address),e.signDoc!==void 0&&(n.signDoc=e.signDoc?i.SignDocDirectAux.toJSON(e.signDoc):void 0),e.mode!==void 0&&(n.mode=(0,d.signModeToJSON)(e.mode)),e.sig!==void 0&&(n.sig=(0,a.base64FromBytes)(e.sig!==void 0?e.sig:new Uint8Array)),n},fromPartial(e){const n=D();return n.address=e.address??"",e.signDoc!==void 0&&e.signDoc!==null&&(n.signDoc=i.SignDocDirectAux.fromPartial(e.signDoc)),n.mode=e.mode??0,n.sig=e.sig??new Uint8Array,n}}}(ee)),ee}var $=ze();const $e=async i=>{var l,b,u,y,S,p,w,O,D,e,n,t,m;const r=ae.chains.find(h=>h.chain_id===i);if(!r)throw new Error(`Chain info not found for chainId: ${i}`);const{bech32_prefix:d,chain_id:c}=r,s=(u=(b=(l=r.staking)==null?void 0:l.staking_tokens)==null?void 0:b[0])==null?void 0:u.denom,o=(p=(S=(y=r.apis)==null?void 0:y.rpc)==null?void 0:S[0])==null?void 0:p.address,a=(D=(O=(w=r.apis)==null?void 0:w.rest)==null?void 0:O[0])==null?void 0:D.address,f=(t=(n=(e=r.fees)==null?void 0:e.fee_tokens)==null?void 0:n[0])==null?void 0:t.average_gas_price;if(!d||!s||!o||!a||!c||f===void 0)throw new Error(`Missing required chain information for ${r.chain_name}`);const g=ae.assets.find(h=>h.chain_name===r.chain_name),_=g==null?void 0:g.assets.find(h=>h.base===s),I=(m=_==null?void 0:_.denom_units.find(h=>h.denom===_.display))==null?void 0:m.exponent;if(I===void 0)throw new Error(`Could not find decimals for ${s} on chain ${r.chain_name}`);return{prefix:d,denom:s,rpcUrl:o,restUrl:a,expectedChainId:c,gasPrice:f,decimals:I}};class Te extends Z{constructor({chainId:r,contract:d,endpoints:c}){super(),this.contract=d,this.registry=new q.Registry,this.chainId=r,this.endpoints=c}parseRSVSignature(r){return new Uint8Array([...U.fromHex(r.r),...U.fromHex(r.s)])}async getChainInfo(){return{...await $e(this.chainId),...this.endpoints}}async getBalance(r){try{const{restUrl:d,denom:c,decimals:s}=await this.getChainInfo(),o=await fetch(`${d}/cosmos/bank/v1beta1/balances/${r}`);if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);const f=(await o.json()).balances.find(I=>I.denom===c),g=(f==null?void 0:f.amount)??"0";return(parseInt(g)/Math.pow(10,s)).toString()}catch(d){throw console.error("Failed to fetch Cosmos balance:",d),new Error("Failed to fetch Cosmos balance")}}async deriveAddressAndPublicKey(r,d){const{prefix:c}=await this.getChainInfo(),s=await this.contract.getDerivedPublicKey({path:d,predecessor:r});if(!s)throw new Error("Failed to get derived public key");const o=Be(s),a=Q.sha256(U.fromHex(o)),f=Q.ripemd160(a);return{address:ie.bech32.encode(c,ie.bech32.toWords(f)),publicKey:o}}setTransaction(r,d){const c=$.TxRaw.encode(r).finish();window.localStorage.setItem(d,U.toBase64(c))}getTransaction(r,d){const c=window.localStorage.getItem(r);if(c)return d!=null&&d.remove&&window.localStorage.removeItem(r),$.TxRaw.decode(U.fromBase64(c))}async getMPCPayloadAndTransaction(r){const{denom:d,rpcUrl:c,gasPrice:s}=await this.getChainInfo(),o=U.fromHex(r.publicKey),a=r.gas||2e5,f=z.calculateFee(a,z.GasPrice.fromString(`${s}${d}`)),_=await(await z.StargateClient.connect(c)).getAccount(r.address);if(!_)throw new Error(`Account ${r.address} does not exist on chain`);const{accountNumber:I,sequence:l}=_,b={typeUrl:"/cosmos.tx.v1beta1.TxBody",value:{messages:r.messages,memo:r.memo||""}},u=this.registry.encode(b),y=q.encodePubkey(Ee.encodeSecp256k1Pubkey(o)),S=q.makeAuthInfoBytes([{pubkey:y,sequence:l}],f.amount,Number(f.gas),void 0,void 0,He.SignMode.SIGN_MODE_DIRECT),p=q.makeSignDoc(u,S,this.chainId,I),w=q.makeSignBytes(p),O=Array.from(Q.sha256(w));return{transaction:$.TxRaw.fromPartial({bodyBytes:u,authInfoBytes:S,signatures:[]}),mpcPayloads:[{index:0,payload:O}]}}addSignature({transaction:r,mpcSignatures:d}){r.signatures=d.map(s=>this.parseRSVSignature(s));const c=$.TxRaw.encode(r).finish();return Buffer.from(c).toString("hex")}async broadcastTx(r){try{const{rpcUrl:d}=await this.getChainInfo(),c=await z.StargateClient.connect(d),s=U.fromHex(r),o=await c.broadcastTx(s);if(o.code!==0)throw new Error(`Broadcast error: ${o.rawLog}`);return o.transactionHash}catch(d){throw console.error("Transaction broadcast failed:",d),new Error("Failed to broadcast transaction.")}}}var ne={},ge;function Ve(){return ge||(ge=1,function(i){Object.defineProperty(i,"__esModule",{value:!0}),i.base_decode=i.base_encode=i.deserialize=i.serialize=void 0;var r=Me;Object.defineProperty(i,"serialize",{enumerable:!0,get:function(){return r.serialize}}),Object.defineProperty(i,"deserialize",{enumerable:!0,get:function(){return r.deserialize}});var d=Je;Object.defineProperty(i,"base_encode",{enumerable:!0,get:function(){return d.baseEncode}}),Object.defineProperty(i,"base_decode",{enumerable:!0,get:function(){return d.baseDecode}})}(ne)),ne}var We=Ve();const W=new X("300000000000000"),re="dontcare",Y=async({networkId:i,accountId:r=re,keypair:d=Se.KeyPair.fromRandom("ed25519")})=>{const c=new Ue.InMemoryKeyStore;await c.setKey(i,r,d);const s=te.Connection.fromConfig({networkId:i,provider:{type:"JsonRpcProvider",args:{url:{testnet:"https://rpc.testnet.near.org",mainnet:"https://rpc.mainnet.near.org"}[i]}},signer:{type:"InMemorySigner",keyStore:c}});return new te.Account(s,r)};function Xe(i){return{delegate_action:{actions:i.delegateAction.actions.map(r=>{if(r.functionCall)return{FunctionCall:{method_name:r.functionCall.methodName,args:Buffer.from(r.functionCall.args).toString("base64"),gas:Number(r.functionCall.gas),deposit:r.functionCall.deposit.toString()}}}).flatMap(r=>r?[r]:[]),nonce:Number(i.delegateAction.nonce),max_block_height:Number(i.delegateAction.maxBlockHeight),public_key:i.delegateAction.publicKey.toString(),receiver_id:i.delegateAction.receiverId,sender_id:i.delegateAction.senderId},signature:`ed25519:${Re.encode(i.signature.data)}`}}const Ze=i=>`04${Buffer.from(We.base_decode(i.split(":")[1])).toString("hex")}`,Ye=i=>{if(i===re)throw new Error("A valid account ID and keypair are required for change methods. Please instantiate a new contract with valid credentials.")};class G extends be{constructor({networkId:r,contractId:d,accountId:c=re,keypair:s=Se.KeyPair.fromRandom("ed25519")}){super(),this.networkId=r,this.contractId=d,this.accountId=c,this.keypair=s}async getContract(){const r=await Y({networkId:this.networkId,accountId:this.accountId,keypair:this.keypair});return new te.Contract(r,this.contractId,{viewMethods:["public_key","experimental_signature_deposit","derived_public_key"],changeMethods:["sign"],useLocalViewExecution:!1})}async getCurrentSignatureDeposit(){const r=await this.getContract();return new X((await r.experimental_signature_deposit()).toLocaleString("fullwide",{useGrouping:!1}))}async getDerivedPublicKey(r){const c=await(await this.getContract()).derived_public_key(r);return Ze(c)}async sign(r){Ye(this.accountId);const d=await this.getContract(),c=await this.getCurrentSignatureDeposit(),s=await d.sign({args:{request:r},gas:W,amount:c});return Ie(s)}static async signWithRelayer({account:r,contract:d,signArgs:c,deposit:s,relayerUrl:o}){const a=xe.actionCreators.functionCall("sign",{request:c},BigInt(W.toString()),BigInt(s.toString())),f=await r.signedDelegate({receiverId:d,actions:[a],blockHeightTtl:60});delete r.accessKeyByPublicKeyCache[f.delegateAction.publicKey.toString()];const _=await(await fetch(`${o}/send_meta_tx_async`,{method:"POST",mode:"cors",body:JSON.stringify(Xe(f)),headers:new Headers({"Content-Type":"application/json"})})).text(),I=await r.connection.provider.txStatus(_,r.accountId,"FINAL"),l=ve({response:I});if(!l)throw new Error("Signature error, please retry");return l}}const Qe=async({networkId:i,contractId:r,mpcPayloads:d,path:c})=>{const o=await new G({networkId:i,contractId:r}).getCurrentSignatureDeposit();return{receiverId:r,actions:d.map(({payload:a})=>({type:"FunctionCall",params:{methodName:"sign",args:{request:{payload:Array.from(a),path:c,key_version:0}},gas:W.div(new X(d.length)).toString(),deposit:(o==null?void 0:o.toString())||"1"}}))}},je=async({networkId:i,chainSigContract:r,nftKeysContract:d,mpcPayloads:c,path:s,tokenId:o})=>{const f=await new G({networkId:i,contractId:r}).getCurrentSignatureDeposit();return{receiverId:d,actions:c.map(({payload:g})=>({type:"FunctionCall",params:{methodName:"ckt_sign_hash",args:{token_id:o,path:s,payload:Array.from(g)},gas:W.div(new X(c.length)).toString(),deposit:(f==null?void 0:f.toString())||"1"}}))}},ve=({response:i})=>{const r=i.receipts_outcome.reduce((d,c)=>{if(d)return d;const{status:s}=c.outcome;return typeof s=="object"&&s.SuccessValue&&s.SuccessValue!==""&&Buffer.from(s.SuccessValue,"base64").toString("utf-8")||""},"");if(r){const d=JSON.parse(r);return Ie(d.Ok)}else return},en=Object.freeze(Object.defineProperty({__proto__:null,mpcPayloadsToChainSigTransaction:Qe,mpcPayloadsToNFTKeysTransaction:je,responseToMpcSignature:ve},Symbol.toStringTag,{value:"Module"})),nn=async(i,r)=>{try{const d=await Y({networkId:i.nearAuthentication.networkId,accountId:i.nearAuthentication.accountId,keypair:r}),c=new G({networkId:i.nearAuthentication.networkId,contractId:i.chainConfig.contract,accountId:d.accountId,keypair:r}),s=new _e({rpcUrl:i.chainConfig.providerUrl,contract:c}),{transaction:o,mpcPayloads:a}=await s.getMPCPayloadAndTransaction(i.transaction),f=await c.sign({payload:a[0].payload,path:i.derivationPath,key_version:0}),g=s.addSignature({transaction:o,mpcSignatures:[f]});return{transactionHash:await s.broadcastTx(g),success:!0}}catch(d){return console.error(d),{success:!1,errorMessage:d instanceof Error?d.message:String(d)}}},tn=async(i,r)=>{try{const d=await Y({networkId:i.nearAuthentication.networkId,accountId:i.nearAuthentication.accountId,keypair:r}),c=new G({networkId:i.nearAuthentication.networkId,contractId:i.chainConfig.contract,accountId:d.accountId,keypair:r}),s=new V({btcRpcAdapter:new ke.Mempool(i.chainConfig.providerUrl),contract:c,network:i.chainConfig.network}),{transaction:o,mpcPayloads:a}=await s.getMPCPayloadAndTransaction(i.transaction),f=await Promise.all(a.map(async({payload:I})=>await c.sign({payload:I,path:i.derivationPath,key_version:0}))),g=s.addSignature({transaction:o,mpcSignatures:f});return{transactionHash:await s.broadcastTx(g),success:!0}}catch(d){return{success:!1,errorMessage:d instanceof Error?d.message:String(d)}}},rn=async(i,r)=>{try{const d=await Y({networkId:i.nearAuthentication.networkId,accountId:i.nearAuthentication.accountId,keypair:r}),c=new G({networkId:i.nearAuthentication.networkId,contractId:i.chainConfig.contract,accountId:d.accountId,keypair:r}),s=new Te({contract:c,chainId:i.chainConfig.chainId}),{transaction:o,mpcPayloads:a}=await s.getMPCPayloadAndTransaction(i.transaction),f=await Promise.all(a.map(async({payload:I})=>await c.sign({payload:I,path:i.derivationPath,key_version:0}))),g=s.addSignature({transaction:o,mpcSignatures:f});return{transactionHash:await s.broadcastTx(g),success:!0}}catch(d){return console.error(d),{success:!1,errorMessage:d instanceof Error?d.message:String(d)}}},an=Object.freeze(Object.defineProperty({__proto__:null,BTCTransaction:tn,CosmosTransaction:rn,EVMTransaction:nn},Symbol.toStringTag,{value:"Module"})),on=Object.freeze(Object.defineProperty({__proto__:null,keypair:an},Symbol.toStringTag,{value:"Module"})),sn=Object.freeze(Object.defineProperty({__proto__:null,ChainSignatureContract:G,signAndSend:on,transactionBuilder:en},Symbol.toStringTag,{value:"Module"})),un=Object.freeze(Object.defineProperty({__proto__:null,near:sn},Symbol.toStringTag,{value:"Module"})),cn=Object.freeze(Object.defineProperty({__proto__:null,chains:un},Symbol.toStringTag,{value:"Module"}));exports.BTCRpcAdapter=Oe;exports.BTCRpcAdapters=ke;exports.Bitcoin=V;exports.Chain=Z;exports.ChainSignatureContract=be;exports.Cosmos=Te;exports.EVM=_e;exports.fetchEVMFeeProperties=we;exports.utils=cn;
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|