signet.js 0.0.1-beta.7 → 0.0.1-beta.8
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/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.d.ts +10 -0
- package/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.d.ts +15 -0
- package/chains/Bitcoin/BTCRpcAdapter/Mempool/index.d.ts +1 -0
- package/chains/Bitcoin/BTCRpcAdapter/Mempool/types.d.ts +69 -0
- package/chains/Bitcoin/BTCRpcAdapter/index.d.ts +5 -0
- package/chains/Bitcoin/Bitcoin.d.ts +69 -0
- package/chains/Bitcoin/types.d.ts +42 -0
- package/chains/Bitcoin/utils.d.ts +2 -0
- package/chains/Chain.d.ts +74 -0
- package/chains/ChainSignatureContract.d.ts +41 -0
- package/chains/Cosmos/Cosmos.d.ts +51 -0
- package/chains/Cosmos/types.d.ts +30 -0
- package/chains/Cosmos/utils.d.ts +2 -0
- package/chains/EVM/EVM.d.ts +42 -0
- package/chains/EVM/types.d.ts +5 -0
- package/chains/EVM/utils.d.ts +7 -0
- package/chains/index.d.ts +12 -0
- package/chains/types.d.ts +31 -0
- package/chains/utils.d.ts +12 -0
- package/index.cjs +2 -0
- package/index.cjs.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +2674 -0
- package/index.js.map +1 -0
- package/package.json +2 -2
- package/utils/chains/index.d.ts +1 -0
- package/utils/chains/near/ChainSignatureContract.d.ts +38 -0
- package/utils/chains/near/account.d.ts +13 -0
- package/utils/chains/near/constants.d.ts +3 -0
- package/utils/chains/near/index.d.ts +3 -0
- package/utils/chains/near/relayer/index.d.ts +1 -0
- package/utils/chains/near/relayer/relayer.d.ts +8 -0
- package/utils/chains/near/relayer/types.d.ts +22 -0
- package/utils/chains/near/signAndSend/index.d.ts +1 -0
- package/utils/chains/near/signAndSend/keypair.d.ts +6 -0
- package/utils/chains/near/transactionBuilder.d.ts +26 -0
- package/utils/chains/near/types.d.ts +50 -0
- package/utils/index.d.ts +1 -0
- package/.eslintrc.json +0 -55
- package/.prettierrc +0 -1
- package/babel.config.js +0 -6
- package/docs/pages/chain-signatures-contract.mdx +0 -56
- package/docs/pages/chain.mdx +0 -45
- package/docs/pages/chains/bitcoin/bitcoin.mdx +0 -191
- package/docs/pages/chains/bitcoin/btc-rpc-adapter.mdx +0 -307
- package/docs/pages/chains/cosmos.mdx +0 -181
- package/docs/pages/chains/evm.mdx +0 -189
- package/docs/pages/index.mdx +0 -99
- package/docs/snippets/contract.ts +0 -21
- package/docs/snippets/env.ts +0 -13
- package/jest.config.ts +0 -199
- package/src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts +0 -11
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts +0 -96
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/index.ts +0 -1
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/types.ts +0 -72
- package/src/chains/Bitcoin/BTCRpcAdapter/index.ts +0 -6
- package/src/chains/Bitcoin/Bitcoin.ts +0 -301
- package/src/chains/Bitcoin/types.ts +0 -45
- package/src/chains/Bitcoin/utils.ts +0 -14
- package/src/chains/Chain.ts +0 -96
- package/src/chains/ChainSignatureContract.ts +0 -48
- package/src/chains/Cosmos/Cosmos.ts +0 -279
- package/src/chains/Cosmos/types.ts +0 -35
- package/src/chains/Cosmos/utils.ts +0 -45
- package/src/chains/EVM/EVM.ts +0 -180
- package/src/chains/EVM/types.ts +0 -7
- package/src/chains/EVM/utils.ts +0 -26
- package/src/chains/index.ts +0 -34
- package/src/chains/types.ts +0 -35
- package/src/chains/utils.ts +0 -40
- package/src/index.ts +0 -2
- package/src/utils/chains/index.ts +0 -1
- package/src/utils/chains/near/ChainSignatureContract.ts +0 -195
- package/src/utils/chains/near/account.ts +0 -42
- package/src/utils/chains/near/constants.ts +0 -4
- package/src/utils/chains/near/index.ts +0 -3
- package/src/utils/chains/near/relayer/index.ts +0 -1
- package/src/utils/chains/near/relayer/relayer.ts +0 -39
- package/src/utils/chains/near/relayer/types.ts +0 -24
- package/src/utils/chains/near/signAndSend/index.ts +0 -1
- package/src/utils/chains/near/signAndSend/keypair.ts +0 -180
- package/src/utils/chains/near/transactionBuilder.ts +0 -138
- package/src/utils/chains/near/types.ts +0 -67
- package/src/utils/index.ts +0 -1
- package/tsconfig.eslint.json +0 -8
- package/tsconfig.json +0 -116
- package/vite.config.ts +0 -47
- package/vocs.config.ts +0 -60
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BTCTransaction, BTCInput, BTCOutput } from '../types';
|
|
2
|
+
export declare abstract class BTCRpcAdapter {
|
|
3
|
+
abstract selectUTXOs(from: string, targets: BTCOutput[]): Promise<{
|
|
4
|
+
inputs: BTCInput[];
|
|
5
|
+
outputs: BTCOutput[];
|
|
6
|
+
}>;
|
|
7
|
+
abstract broadcastTransaction(transactionHex: string): Promise<string>;
|
|
8
|
+
abstract getBalance(address: string): Promise<number>;
|
|
9
|
+
abstract getTransaction(txid: string): Promise<BTCTransaction>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BTCRpcAdapter } from '../BTCRpcAdapter';
|
|
2
|
+
import { BTCTransaction, BTCInput, BTCOutput } from '../../types';
|
|
3
|
+
export declare class Mempool extends BTCRpcAdapter {
|
|
4
|
+
private readonly providerUrl;
|
|
5
|
+
constructor(providerUrl: string);
|
|
6
|
+
private fetchFeeRate;
|
|
7
|
+
private fetchUTXOs;
|
|
8
|
+
selectUTXOs(from: string, targets: BTCOutput[], confirmationTarget?: number): Promise<{
|
|
9
|
+
inputs: BTCInput[];
|
|
10
|
+
outputs: BTCOutput[];
|
|
11
|
+
}>;
|
|
12
|
+
broadcastTransaction(transactionHex: string): Promise<string>;
|
|
13
|
+
getBalance(address: string): Promise<number>;
|
|
14
|
+
getTransaction(txid: string): Promise<BTCTransaction>;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Mempool } from './Mempool';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export interface BTCFeeRecommendation {
|
|
2
|
+
fastestFee: number;
|
|
3
|
+
halfHourFee: number;
|
|
4
|
+
hourFee: number;
|
|
5
|
+
economyFee: number;
|
|
6
|
+
minimumFee: number;
|
|
7
|
+
}
|
|
8
|
+
interface BTCAddressStats {
|
|
9
|
+
funded_txo_count: number;
|
|
10
|
+
funded_txo_sum: number;
|
|
11
|
+
spent_txo_count: number;
|
|
12
|
+
spent_txo_sum: number;
|
|
13
|
+
tx_count: number;
|
|
14
|
+
}
|
|
15
|
+
export interface BTCAddressInfo {
|
|
16
|
+
address: string;
|
|
17
|
+
chain_stats: BTCAddressStats;
|
|
18
|
+
mempool_stats: BTCAddressStats;
|
|
19
|
+
}
|
|
20
|
+
export interface Transaction {
|
|
21
|
+
txid: string;
|
|
22
|
+
version: number;
|
|
23
|
+
locktime: number;
|
|
24
|
+
vin: Array<{
|
|
25
|
+
txid: string;
|
|
26
|
+
vout: number;
|
|
27
|
+
prevout: {
|
|
28
|
+
scriptpubkey: string;
|
|
29
|
+
scriptpubkey_asm: string;
|
|
30
|
+
scriptpubkey_type: string;
|
|
31
|
+
scriptpubkey_address: string;
|
|
32
|
+
value: number;
|
|
33
|
+
};
|
|
34
|
+
scriptsig: string;
|
|
35
|
+
scriptsig_asm: string;
|
|
36
|
+
witness: string[];
|
|
37
|
+
is_coinbase: boolean;
|
|
38
|
+
sequence: number;
|
|
39
|
+
}>;
|
|
40
|
+
vout: Array<{
|
|
41
|
+
scriptpubkey: string;
|
|
42
|
+
scriptpubkey_asm: string;
|
|
43
|
+
scriptpubkey_type: string;
|
|
44
|
+
scriptpubkey_address: string;
|
|
45
|
+
value: number;
|
|
46
|
+
}>;
|
|
47
|
+
size: number;
|
|
48
|
+
weight: number;
|
|
49
|
+
sigops?: number;
|
|
50
|
+
fee: number;
|
|
51
|
+
status: {
|
|
52
|
+
confirmed: boolean;
|
|
53
|
+
block_height: number;
|
|
54
|
+
block_hash: string;
|
|
55
|
+
block_time: number;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export interface UTXO {
|
|
59
|
+
txid: string;
|
|
60
|
+
vout: number;
|
|
61
|
+
status: {
|
|
62
|
+
confirmed: boolean;
|
|
63
|
+
block_height: number;
|
|
64
|
+
block_hash: string;
|
|
65
|
+
block_time: number;
|
|
66
|
+
};
|
|
67
|
+
value: number;
|
|
68
|
+
}
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BTCRpcAdapter } from './BTCRpcAdapter';
|
|
2
|
+
import { BTCNetworkIds, BTCTransactionRequest, BTCUnsignedTransaction } from './types';
|
|
3
|
+
import { Chain } from '../Chain';
|
|
4
|
+
import { ChainSignatureContract } from '../ChainSignatureContract';
|
|
5
|
+
import { MPCPayloads, RSVSignature, KeyDerivationPath } from '../types';
|
|
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
|
+
export declare class Bitcoin extends Chain<BTCTransactionRequest, BTCUnsignedTransaction> {
|
|
12
|
+
private static readonly SATOSHIS_PER_BTC;
|
|
13
|
+
private readonly network;
|
|
14
|
+
private readonly btcRpcAdapter;
|
|
15
|
+
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
|
+
constructor({ network, contract, btcRpcAdapter, }: {
|
|
24
|
+
network: BTCNetworkIds;
|
|
25
|
+
contract: ChainSignatureContract;
|
|
26
|
+
btcRpcAdapter: BTCRpcAdapter;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Converts satoshis to BTC
|
|
30
|
+
* @param satoshis - Amount in satoshis
|
|
31
|
+
* @returns Amount in BTC
|
|
32
|
+
*/
|
|
33
|
+
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
|
+
static toSatoshi(btc: number): number;
|
|
40
|
+
private fetchTransaction;
|
|
41
|
+
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
|
+
createPSBT({ transactionRequest, }: {
|
|
49
|
+
transactionRequest: BTCTransactionRequest;
|
|
50
|
+
}): Promise<bitcoin.Psbt>;
|
|
51
|
+
getBalance(address: string): Promise<string>;
|
|
52
|
+
deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
|
|
53
|
+
address: string;
|
|
54
|
+
publicKey: string;
|
|
55
|
+
}>;
|
|
56
|
+
setTransaction(transaction: BTCUnsignedTransaction, storageKey: string): void;
|
|
57
|
+
getTransaction(storageKey: string, options?: {
|
|
58
|
+
remove?: boolean;
|
|
59
|
+
}): BTCUnsignedTransaction | undefined;
|
|
60
|
+
getMPCPayloadAndTransaction(transactionRequest: BTCTransactionRequest): Promise<{
|
|
61
|
+
transaction: BTCUnsignedTransaction;
|
|
62
|
+
mpcPayloads: MPCPayloads;
|
|
63
|
+
}>;
|
|
64
|
+
addSignature({ transaction: { psbt, publicKey }, mpcSignatures, }: {
|
|
65
|
+
transaction: BTCUnsignedTransaction;
|
|
66
|
+
mpcSignatures: RSVSignature[];
|
|
67
|
+
}): string;
|
|
68
|
+
broadcastTx(txSerialized: string): Promise<string>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type * as bitcoin from 'bitcoinjs-lib';
|
|
2
|
+
export interface BTCTransaction {
|
|
3
|
+
vout: Array<{
|
|
4
|
+
scriptpubkey: string;
|
|
5
|
+
value: number;
|
|
6
|
+
}>;
|
|
7
|
+
}
|
|
8
|
+
export interface BTCInput {
|
|
9
|
+
txid: string;
|
|
10
|
+
vout: number;
|
|
11
|
+
value: number;
|
|
12
|
+
scriptPubKey: Buffer;
|
|
13
|
+
}
|
|
14
|
+
export type BTCOutput = {
|
|
15
|
+
value: number;
|
|
16
|
+
} & ({
|
|
17
|
+
address: string;
|
|
18
|
+
script?: never;
|
|
19
|
+
} | {
|
|
20
|
+
address?: never;
|
|
21
|
+
script: Buffer;
|
|
22
|
+
});
|
|
23
|
+
export type BTCTransactionRequest = {
|
|
24
|
+
publicKey: string;
|
|
25
|
+
} & ({
|
|
26
|
+
inputs: BTCInput[];
|
|
27
|
+
outputs: BTCOutput[];
|
|
28
|
+
from?: never;
|
|
29
|
+
to?: never;
|
|
30
|
+
value?: never;
|
|
31
|
+
} | {
|
|
32
|
+
inputs?: never;
|
|
33
|
+
outputs?: never;
|
|
34
|
+
from: string;
|
|
35
|
+
to: string;
|
|
36
|
+
value: string;
|
|
37
|
+
});
|
|
38
|
+
export interface BTCUnsignedTransaction {
|
|
39
|
+
psbt: bitcoin.Psbt;
|
|
40
|
+
publicKey: string;
|
|
41
|
+
}
|
|
42
|
+
export type BTCNetworkIds = 'mainnet' | 'testnet' | 'regtest';
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CosmosNetworkIds, CosmosTransactionRequest, CosmosUnsignedTransaction } from './types';
|
|
2
|
+
import { ChainSignatureContract } from '../ChainSignatureContract';
|
|
3
|
+
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
|
+
export declare class Cosmos extends Chain<CosmosTransactionRequest, CosmosUnsignedTransaction> {
|
|
10
|
+
private readonly registry;
|
|
11
|
+
private readonly chainId;
|
|
12
|
+
private readonly contract;
|
|
13
|
+
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
|
+
constructor({ chainId, contract, endpoints, }: {
|
|
24
|
+
contract: ChainSignatureContract;
|
|
25
|
+
chainId: CosmosNetworkIds;
|
|
26
|
+
endpoints?: {
|
|
27
|
+
rpcUrl?: string;
|
|
28
|
+
restUrl?: string;
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
private parseRSVSignature;
|
|
32
|
+
private getChainInfo;
|
|
33
|
+
getBalance(address: string): Promise<string>;
|
|
34
|
+
deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
|
|
35
|
+
address: string;
|
|
36
|
+
publicKey: string;
|
|
37
|
+
}>;
|
|
38
|
+
setTransaction(transaction: CosmosUnsignedTransaction, storageKey: string): void;
|
|
39
|
+
getTransaction(storageKey: string, options?: {
|
|
40
|
+
remove?: boolean;
|
|
41
|
+
}): CosmosUnsignedTransaction | undefined;
|
|
42
|
+
getMPCPayloadAndTransaction(transactionRequest: CosmosTransactionRequest): Promise<{
|
|
43
|
+
transaction: CosmosUnsignedTransaction;
|
|
44
|
+
mpcPayloads: MPCPayloads;
|
|
45
|
+
}>;
|
|
46
|
+
addSignature({ transaction, mpcSignatures, }: {
|
|
47
|
+
transaction: CosmosUnsignedTransaction;
|
|
48
|
+
mpcSignatures: RSVSignature[];
|
|
49
|
+
}): string;
|
|
50
|
+
broadcastTx(txSerialized: string): Promise<string>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EncodeObject } from '@cosmjs/proto-signing';
|
|
2
|
+
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
3
|
+
export type CosmosNetworkIds = string;
|
|
4
|
+
export type CosmosUnsignedTransaction = TxRaw;
|
|
5
|
+
export interface CosmosTransactionRequest {
|
|
6
|
+
address: string;
|
|
7
|
+
publicKey: string;
|
|
8
|
+
messages: EncodeObject[];
|
|
9
|
+
memo?: string;
|
|
10
|
+
gas?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface BalanceResponse {
|
|
13
|
+
balances: Array<{
|
|
14
|
+
denom: string;
|
|
15
|
+
amount: string;
|
|
16
|
+
}>;
|
|
17
|
+
pagination: {
|
|
18
|
+
next_key: string | null;
|
|
19
|
+
total: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface ChainInfo {
|
|
23
|
+
prefix: string;
|
|
24
|
+
denom: string;
|
|
25
|
+
rpcUrl: string;
|
|
26
|
+
restUrl: string;
|
|
27
|
+
expectedChainId: string;
|
|
28
|
+
gasPrice: number;
|
|
29
|
+
decimals: number;
|
|
30
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Chain } from '../Chain';
|
|
2
|
+
import { ChainSignatureContract } from '../ChainSignatureContract';
|
|
3
|
+
import { EVMTransactionRequest, EVMUnsignedTransaction } from './types';
|
|
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
|
+
export declare class EVM extends Chain<EVMTransactionRequest, EVMUnsignedTransaction> {
|
|
10
|
+
private readonly provider;
|
|
11
|
+
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
|
+
constructor({ rpcUrl, contract, }: {
|
|
19
|
+
rpcUrl: string;
|
|
20
|
+
contract: ChainSignatureContract;
|
|
21
|
+
});
|
|
22
|
+
private attachGasAndNonce;
|
|
23
|
+
private parseSignature;
|
|
24
|
+
deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
|
|
25
|
+
address: string;
|
|
26
|
+
publicKey: string;
|
|
27
|
+
}>;
|
|
28
|
+
getBalance(address: string): Promise<string>;
|
|
29
|
+
setTransaction(transaction: EVMUnsignedTransaction, storageKey: string): void;
|
|
30
|
+
getTransaction(storageKey: string, options?: {
|
|
31
|
+
remove?: boolean;
|
|
32
|
+
}): EVMUnsignedTransaction | undefined;
|
|
33
|
+
getMPCPayloadAndTransaction(transactionRequest: EVMTransactionRequest): Promise<{
|
|
34
|
+
transaction: EVMUnsignedTransaction;
|
|
35
|
+
mpcPayloads: MPCPayloads;
|
|
36
|
+
}>;
|
|
37
|
+
addSignature({ transaction, mpcSignatures, }: {
|
|
38
|
+
transaction: EVMUnsignedTransaction;
|
|
39
|
+
mpcSignatures: RSVSignature[];
|
|
40
|
+
}): string;
|
|
41
|
+
broadcastTx(txSerialized: string): Promise<string>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { Chain } from './Chain';
|
|
2
|
+
export { ChainSignatureContract, type SignArgs } from './ChainSignatureContract';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export * as utils from './utils';
|
|
5
|
+
export { EVM } from './EVM/EVM';
|
|
6
|
+
export { fetchEVMFeeProperties } from './EVM/utils';
|
|
7
|
+
export type { EVMTransactionRequest, EVMUnsignedTransaction } from './EVM/types';
|
|
8
|
+
export { Bitcoin } from './Bitcoin/Bitcoin';
|
|
9
|
+
export { BTCRpcAdapters, BTCRpcAdapter } from './Bitcoin/BTCRpcAdapter';
|
|
10
|
+
export type { BTCTransactionRequest, BTCUnsignedTransaction, BTCTransaction, BTCOutput, BTCInput, BTCNetworkIds, } from './Bitcoin/types';
|
|
11
|
+
export { Cosmos } from './Cosmos/Cosmos';
|
|
12
|
+
export type { CosmosNetworkIds, CosmosTransactionRequest, CosmosUnsignedTransaction, } from './Cosmos/types';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SignArgs } from './ChainSignatureContract';
|
|
2
|
+
interface SuccessResponse {
|
|
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
|
+
}>;
|
|
15
|
+
export type UncompressedPubKeySEC1 = `04${string}`;
|
|
16
|
+
export type KeyDerivationPath = string;
|
|
17
|
+
export interface RSVSignature {
|
|
18
|
+
r: string;
|
|
19
|
+
s: string;
|
|
20
|
+
v: number;
|
|
21
|
+
}
|
|
22
|
+
export interface MPCSignature {
|
|
23
|
+
big_r: {
|
|
24
|
+
affine_point: string;
|
|
25
|
+
};
|
|
26
|
+
s: {
|
|
27
|
+
scalar: string;
|
|
28
|
+
};
|
|
29
|
+
recovery_id: number;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
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;
|