signet.js 0.0.1-beta.1 → 0.0.1-beta.11
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/LICENSE +19 -0
- package/README.md +41 -14
- package/browser/index.cjs +3 -0
- package/browser/index.cjs.map +1 -0
- package/browser/index.d.cts +693 -0
- package/browser/index.d.ts +693 -0
- package/browser/index.js +3 -0
- package/browser/index.js.map +1 -0
- package/node/index.cjs +3 -0
- package/node/index.cjs.map +1 -0
- package/node/index.d.cts +693 -0
- package/node/index.d.ts +693 -0
- package/node/index.js +3 -0
- package/node/index.js.map +1 -0
- package/package.json +43 -14
- package/src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.d.ts +0 -10
- package/src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.js +0 -2
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.d.ts +0 -15
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.js +0 -69
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/index.d.ts +0 -1
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/index.js +0 -1
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/types.d.ts +0 -69
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/types.js +0 -1
- package/src/chains/Bitcoin/BTCRpcAdapter/index.d.ts +0 -5
- package/src/chains/Bitcoin/BTCRpcAdapter/index.js +0 -5
- package/src/chains/Bitcoin/Bitcoin.d.ts +0 -66
- package/src/chains/Bitcoin/Bitcoin.js +0 -197
- package/src/chains/Bitcoin/types.d.ts +0 -42
- package/src/chains/Bitcoin/types.js +0 -1
- package/src/chains/Bitcoin/utils.d.ts +0 -2
- package/src/chains/Bitcoin/utils.js +0 -13
- package/src/chains/Chain.d.ts +0 -89
- package/src/chains/Chain.js +0 -9
- package/src/chains/ChainSignatureContract.d.ts +0 -62
- package/src/chains/ChainSignatureContract.js +0 -7
- package/src/chains/Cosmos/Cosmos.d.ts +0 -49
- package/src/chains/Cosmos/Cosmos.js +0 -156
- package/src/chains/Cosmos/types.d.ts +0 -30
- package/src/chains/Cosmos/types.js +0 -1
- package/src/chains/Cosmos/utils.d.ts +0 -2
- package/src/chains/Cosmos/utils.js +0 -27
- package/src/chains/EVM/EVM.d.ts +0 -40
- package/src/chains/EVM/EVM.js +0 -108
- package/src/chains/EVM/types.d.ts +0 -5
- package/src/chains/EVM/types.js +0 -1
- package/src/chains/EVM/utils.d.ts +0 -7
- package/src/chains/EVM/utils.js +0 -14
- package/src/chains/index.d.ts +0 -12
- package/src/chains/index.js +0 -12
- package/src/chains/types.d.ts +0 -31
- package/src/chains/types.js +0 -1
- package/src/chains/utils.d.ts +0 -12
- package/src/chains/utils.js +0 -27
- package/src/index.d.ts +0 -2
- package/src/index.js +0 -2
- package/src/utils/chains/index.d.ts +0 -1
- package/src/utils/chains/index.js +0 -1
- package/src/utils/chains/near/account.d.ts +0 -13
- package/src/utils/chains/near/account.js +0 -22
- package/src/utils/chains/near/constants.d.ts +0 -3
- package/src/utils/chains/near/constants.js +0 -3
- package/src/utils/chains/near/contract.d.ts +0 -39
- package/src/utils/chains/near/contract.js +0 -101
- package/src/utils/chains/near/index.d.ts +0 -3
- package/src/utils/chains/near/index.js +0 -3
- package/src/utils/chains/near/relayer/index.d.ts +0 -1
- package/src/utils/chains/near/relayer/index.js +0 -1
- package/src/utils/chains/near/relayer/relayer.d.ts +0 -8
- package/src/utils/chains/near/relayer/relayer.js +0 -33
- package/src/utils/chains/near/relayer/types.d.ts +0 -22
- package/src/utils/chains/near/relayer/types.js +0 -1
- package/src/utils/chains/near/signAndSend/index.d.ts +0 -1
- package/src/utils/chains/near/signAndSend/index.js +0 -1
- package/src/utils/chains/near/signAndSend/keypair.d.ts +0 -6
- package/src/utils/chains/near/signAndSend/keypair.js +0 -126
- package/src/utils/chains/near/transactionBuilder.d.ts +0 -26
- package/src/utils/chains/near/transactionBuilder.js +0 -72
- package/src/utils/chains/near/types.d.ts +0 -47
- package/src/utils/chains/near/types.js +0 -1
- package/src/utils/index.d.ts +0 -1
- package/src/utils/index.js +0 -1
- package/vocs.config.d.ts +0 -3
- package/vocs.config.js +0 -71
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { encodeSecp256k1Pubkey } from '@cosmjs/amino';
|
|
2
|
-
import { ripemd160, sha256 } from '@cosmjs/crypto';
|
|
3
|
-
import { toBase64, fromBase64, fromHex } from '@cosmjs/encoding';
|
|
4
|
-
import { Registry, makeSignBytes, encodePubkey, makeAuthInfoBytes, makeSignDoc, } from '@cosmjs/proto-signing';
|
|
5
|
-
import { GasPrice, StargateClient, calculateFee } from '@cosmjs/stargate';
|
|
6
|
-
import { bech32 } from 'bech32';
|
|
7
|
-
import { SignMode } from 'cosmjs-types/cosmos/tx/signing/v1beta1/signing';
|
|
8
|
-
import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
9
|
-
import { Chain, utils } from '@chains';
|
|
10
|
-
import { fetchChainInfo } from '@chains/Cosmos/utils';
|
|
11
|
-
/**
|
|
12
|
-
* Implementation of the Chain interface for Cosmos-based networks.
|
|
13
|
-
* Handles interactions with Cosmos SDK chains like Cosmos Hub, Osmosis, etc.
|
|
14
|
-
*/
|
|
15
|
-
export class Cosmos extends Chain {
|
|
16
|
-
/**
|
|
17
|
-
* Creates a new Cosmos chain instance
|
|
18
|
-
* @param params - Configuration parameters
|
|
19
|
-
* @param params.chainId - Chain id for the Cosmos network
|
|
20
|
-
* @param params.contract - Instance of the chain signature contract for MPC operations
|
|
21
|
-
* @param params.endpoints - Optional RPC and REST endpoints
|
|
22
|
-
* @param params.endpoints.rpcUrl - Optional RPC endpoint URL
|
|
23
|
-
* @param params.endpoints.restUrl - Optional REST endpoint URL
|
|
24
|
-
*/
|
|
25
|
-
constructor({ chainId, contract, endpoints, }) {
|
|
26
|
-
super();
|
|
27
|
-
this.contract = contract;
|
|
28
|
-
this.registry = new Registry();
|
|
29
|
-
this.chainId = chainId;
|
|
30
|
-
this.endpoints = endpoints;
|
|
31
|
-
}
|
|
32
|
-
parseRSVSignature(rsvSignature) {
|
|
33
|
-
return new Uint8Array([
|
|
34
|
-
...fromHex(rsvSignature.r),
|
|
35
|
-
...fromHex(rsvSignature.s),
|
|
36
|
-
]);
|
|
37
|
-
}
|
|
38
|
-
async getChainInfo() {
|
|
39
|
-
return {
|
|
40
|
-
...(await fetchChainInfo(this.chainId)),
|
|
41
|
-
...this.endpoints,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
async getBalance(address) {
|
|
45
|
-
try {
|
|
46
|
-
const { restUrl, denom, decimals } = await this.getChainInfo();
|
|
47
|
-
const response = await fetch(`${restUrl}/cosmos/bank/v1beta1/balances/${address}`);
|
|
48
|
-
if (!response.ok) {
|
|
49
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
50
|
-
}
|
|
51
|
-
const data = (await response.json());
|
|
52
|
-
const balance = data.balances.find((b) => b.denom === denom);
|
|
53
|
-
const amount = balance?.amount ?? '0';
|
|
54
|
-
const formattedBalance = (parseInt(amount) / Math.pow(10, decimals)).toString();
|
|
55
|
-
return formattedBalance;
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
console.error('Failed to fetch Cosmos balance:', error);
|
|
59
|
-
throw new Error('Failed to fetch Cosmos balance');
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async deriveAddressAndPublicKey(predecessor, path) {
|
|
63
|
-
const { prefix } = await this.getChainInfo();
|
|
64
|
-
const uncompressedPubKey = await this.contract.getDerivedPublicKey({
|
|
65
|
-
path,
|
|
66
|
-
predecessor,
|
|
67
|
-
});
|
|
68
|
-
if (!uncompressedPubKey) {
|
|
69
|
-
throw new Error('Failed to get derived public key');
|
|
70
|
-
}
|
|
71
|
-
const derivedKey = utils.compressPubKey(uncompressedPubKey);
|
|
72
|
-
const pubKeySha256 = sha256(fromHex(derivedKey));
|
|
73
|
-
const ripemd160Hash = ripemd160(pubKeySha256);
|
|
74
|
-
const address = bech32.encode(prefix, bech32.toWords(ripemd160Hash));
|
|
75
|
-
return { address, publicKey: derivedKey };
|
|
76
|
-
}
|
|
77
|
-
setTransaction(transaction, storageKey) {
|
|
78
|
-
const serialized = TxRaw.encode(transaction).finish();
|
|
79
|
-
window.localStorage.setItem(storageKey, toBase64(serialized));
|
|
80
|
-
}
|
|
81
|
-
getTransaction(storageKey, options) {
|
|
82
|
-
const serialized = window.localStorage.getItem(storageKey);
|
|
83
|
-
if (!serialized)
|
|
84
|
-
return undefined;
|
|
85
|
-
if (options?.remove) {
|
|
86
|
-
window.localStorage.removeItem(storageKey);
|
|
87
|
-
}
|
|
88
|
-
return TxRaw.decode(fromBase64(serialized));
|
|
89
|
-
}
|
|
90
|
-
async getMPCPayloadAndTransaction(transactionRequest) {
|
|
91
|
-
const { denom, rpcUrl, gasPrice } = await this.getChainInfo();
|
|
92
|
-
const publicKeyBytes = fromHex(transactionRequest.publicKey);
|
|
93
|
-
const gasLimit = transactionRequest.gas || 200000;
|
|
94
|
-
const fee = calculateFee(gasLimit, GasPrice.fromString(`${gasPrice}${denom}`));
|
|
95
|
-
const client = await StargateClient.connect(rpcUrl);
|
|
96
|
-
const accountOnChain = await client.getAccount(transactionRequest.address);
|
|
97
|
-
if (!accountOnChain) {
|
|
98
|
-
throw new Error(`Account ${transactionRequest.address} does not exist on chain`);
|
|
99
|
-
}
|
|
100
|
-
const { accountNumber, sequence } = accountOnChain;
|
|
101
|
-
const txBodyEncodeObject = {
|
|
102
|
-
typeUrl: '/cosmos.tx.v1beta1.TxBody',
|
|
103
|
-
value: {
|
|
104
|
-
messages: transactionRequest.messages,
|
|
105
|
-
memo: transactionRequest.memo || '',
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
const txBodyBytes = this.registry.encode(txBodyEncodeObject);
|
|
109
|
-
const pubkey = encodePubkey(encodeSecp256k1Pubkey(publicKeyBytes));
|
|
110
|
-
// TODO: Allow caller to provide: multiple signers, fee payer, fee granter
|
|
111
|
-
const authInfoBytes = makeAuthInfoBytes([
|
|
112
|
-
{
|
|
113
|
-
pubkey,
|
|
114
|
-
sequence,
|
|
115
|
-
},
|
|
116
|
-
], fee.amount, Number(fee.gas), undefined, undefined, SignMode.SIGN_MODE_DIRECT);
|
|
117
|
-
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, this.chainId, accountNumber);
|
|
118
|
-
const signBytes = makeSignBytes(signDoc);
|
|
119
|
-
const payload = Array.from(sha256(signBytes));
|
|
120
|
-
return {
|
|
121
|
-
transaction: TxRaw.fromPartial({
|
|
122
|
-
bodyBytes: txBodyBytes,
|
|
123
|
-
authInfoBytes,
|
|
124
|
-
signatures: [],
|
|
125
|
-
}),
|
|
126
|
-
mpcPayloads: [
|
|
127
|
-
{
|
|
128
|
-
index: 0,
|
|
129
|
-
payload,
|
|
130
|
-
},
|
|
131
|
-
],
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
addSignature({ transaction, mpcSignatures, }) {
|
|
135
|
-
// Allow support for multi-sig but the package only supports single-sig
|
|
136
|
-
transaction.signatures = mpcSignatures.map((sig) => this.parseRSVSignature(sig));
|
|
137
|
-
const txBytes = TxRaw.encode(transaction).finish();
|
|
138
|
-
return Buffer.from(txBytes).toString('hex');
|
|
139
|
-
}
|
|
140
|
-
async broadcastTx(txSerialized) {
|
|
141
|
-
try {
|
|
142
|
-
const { rpcUrl } = await this.getChainInfo();
|
|
143
|
-
const client = await StargateClient.connect(rpcUrl);
|
|
144
|
-
const txBytes = fromHex(txSerialized);
|
|
145
|
-
const broadcastResponse = await client.broadcastTx(txBytes);
|
|
146
|
-
if (broadcastResponse.code !== 0) {
|
|
147
|
-
throw new Error(`Broadcast error: ${broadcastResponse.rawLog}`);
|
|
148
|
-
}
|
|
149
|
-
return broadcastResponse.transactionHash;
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
console.error('Transaction broadcast failed:', error);
|
|
153
|
-
throw new Error('Failed to broadcast transaction.');
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { type EncodeObject } from '@cosmjs/proto-signing';
|
|
2
|
-
import { type 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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { chains, assets } from 'chain-registry';
|
|
2
|
-
export const fetchChainInfo = async (chainId) => {
|
|
3
|
-
const chainInfo = chains.find((chain) => chain.chain_id === chainId);
|
|
4
|
-
if (!chainInfo) {
|
|
5
|
-
throw new Error(`Chain info not found for chainId: ${chainId}`);
|
|
6
|
-
}
|
|
7
|
-
const { bech32_prefix: prefix, chain_id: expectedChainId } = chainInfo;
|
|
8
|
-
const denom = chainInfo.staking?.staking_tokens?.[0]?.denom;
|
|
9
|
-
const rpcUrl = chainInfo.apis?.rpc?.[0]?.address;
|
|
10
|
-
const restUrl = chainInfo.apis?.rest?.[0]?.address;
|
|
11
|
-
const gasPrice = chainInfo.fees?.fee_tokens?.[0]?.average_gas_price;
|
|
12
|
-
if (!prefix ||
|
|
13
|
-
!denom ||
|
|
14
|
-
!rpcUrl ||
|
|
15
|
-
!restUrl ||
|
|
16
|
-
!expectedChainId ||
|
|
17
|
-
gasPrice === undefined) {
|
|
18
|
-
throw new Error(`Missing required chain information for ${chainInfo.chain_name}`);
|
|
19
|
-
}
|
|
20
|
-
const assetList = assets.find((asset) => asset.chain_name === chainInfo.chain_name);
|
|
21
|
-
const asset = assetList?.assets.find((asset) => asset.base === denom);
|
|
22
|
-
const decimals = asset?.denom_units.find((unit) => unit.denom === asset.display)?.exponent;
|
|
23
|
-
if (decimals === undefined) {
|
|
24
|
-
throw new Error(`Could not find decimals for ${denom} on chain ${chainInfo.chain_name}`);
|
|
25
|
-
}
|
|
26
|
-
return { prefix, denom, rpcUrl, restUrl, expectedChainId, gasPrice, decimals };
|
|
27
|
-
};
|
package/src/chains/EVM/EVM.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { type MPCPayloads, type RSVSignature, type KeyDerivationPath, type EVMTransactionRequest, type EVMUnsignedTransaction, type ChainSignatureContract } from '@chains';
|
|
2
|
-
import { Chain } from '@chains';
|
|
3
|
-
/**
|
|
4
|
-
* Implementation of the Chain interface for EVM-compatible networks.
|
|
5
|
-
* Handles interactions with Ethereum Virtual Machine based blockchains like Ethereum, BSC, Polygon, etc.
|
|
6
|
-
*/
|
|
7
|
-
export declare class EVM extends Chain<EVMTransactionRequest, EVMUnsignedTransaction> {
|
|
8
|
-
private readonly provider;
|
|
9
|
-
private readonly contract;
|
|
10
|
-
/**
|
|
11
|
-
* Creates a new EVM chain instance
|
|
12
|
-
* @param params - Configuration parameters
|
|
13
|
-
* @param params.rpcUrl - URL of the EVM JSON-RPC provider (e.g., Infura endpoint)
|
|
14
|
-
* @param params.contract - Instance of the chain signature contract for MPC operations
|
|
15
|
-
*/
|
|
16
|
-
constructor({ rpcUrl, contract, }: {
|
|
17
|
-
rpcUrl: string;
|
|
18
|
-
contract: ChainSignatureContract;
|
|
19
|
-
});
|
|
20
|
-
private attachGasAndNonce;
|
|
21
|
-
private parseSignature;
|
|
22
|
-
deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
|
|
23
|
-
address: string;
|
|
24
|
-
publicKey: string;
|
|
25
|
-
}>;
|
|
26
|
-
getBalance(address: string): Promise<string>;
|
|
27
|
-
setTransaction(transaction: EVMUnsignedTransaction, storageKey: string): void;
|
|
28
|
-
getTransaction(storageKey: string, options?: {
|
|
29
|
-
remove?: boolean;
|
|
30
|
-
}): EVMUnsignedTransaction | undefined;
|
|
31
|
-
getMPCPayloadAndTransaction(transactionRequest: EVMTransactionRequest): Promise<{
|
|
32
|
-
transaction: EVMUnsignedTransaction;
|
|
33
|
-
mpcPayloads: MPCPayloads;
|
|
34
|
-
}>;
|
|
35
|
-
addSignature({ transaction, mpcSignatures, }: {
|
|
36
|
-
transaction: EVMUnsignedTransaction;
|
|
37
|
-
mpcSignatures: RSVSignature[];
|
|
38
|
-
}): string;
|
|
39
|
-
broadcastTx(txSerialized: string): Promise<string>;
|
|
40
|
-
}
|
package/src/chains/EVM/EVM.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { fromHex } from '@cosmjs/encoding';
|
|
2
|
-
import { ethers, keccak256 } from 'ethers';
|
|
3
|
-
import { Chain, fetchEVMFeeProperties } from '@chains';
|
|
4
|
-
/**
|
|
5
|
-
* Implementation of the Chain interface for EVM-compatible networks.
|
|
6
|
-
* Handles interactions with Ethereum Virtual Machine based blockchains like Ethereum, BSC, Polygon, etc.
|
|
7
|
-
*/
|
|
8
|
-
export class EVM extends Chain {
|
|
9
|
-
/**
|
|
10
|
-
* Creates a new EVM chain instance
|
|
11
|
-
* @param params - Configuration parameters
|
|
12
|
-
* @param params.rpcUrl - URL of the EVM JSON-RPC provider (e.g., Infura endpoint)
|
|
13
|
-
* @param params.contract - Instance of the chain signature contract for MPC operations
|
|
14
|
-
*/
|
|
15
|
-
constructor({ rpcUrl, contract, }) {
|
|
16
|
-
super();
|
|
17
|
-
this.contract = contract;
|
|
18
|
-
this.provider = new ethers.JsonRpcProvider(rpcUrl);
|
|
19
|
-
}
|
|
20
|
-
async attachGasAndNonce(transaction) {
|
|
21
|
-
const fees = await fetchEVMFeeProperties(this.provider._getConnection().url, transaction);
|
|
22
|
-
const nonce = await this.provider.getTransactionCount(transaction.from, 'latest');
|
|
23
|
-
const { from, ...rest } = transaction;
|
|
24
|
-
return {
|
|
25
|
-
...fees,
|
|
26
|
-
chainId: this.provider._network.chainId,
|
|
27
|
-
nonce,
|
|
28
|
-
type: 2,
|
|
29
|
-
...rest,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
parseSignature(signature) {
|
|
33
|
-
return ethers.Signature.from({
|
|
34
|
-
r: `0x${signature.r}`,
|
|
35
|
-
s: `0x${signature.s}`,
|
|
36
|
-
v: signature.v,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
async deriveAddressAndPublicKey(predecessor, path) {
|
|
40
|
-
const uncompressedPubKey = await this.contract.getDerivedPublicKey({
|
|
41
|
-
path,
|
|
42
|
-
predecessor,
|
|
43
|
-
});
|
|
44
|
-
if (!uncompressedPubKey) {
|
|
45
|
-
throw new Error('Failed to get derived public key');
|
|
46
|
-
}
|
|
47
|
-
const publicKeyNoPrefix = uncompressedPubKey.startsWith('04')
|
|
48
|
-
? uncompressedPubKey.substring(2)
|
|
49
|
-
: uncompressedPubKey;
|
|
50
|
-
const hash = ethers.keccak256(fromHex(publicKeyNoPrefix));
|
|
51
|
-
return {
|
|
52
|
-
address: `0x${hash.substring(hash.length - 40)}`,
|
|
53
|
-
publicKey: uncompressedPubKey,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
async getBalance(address) {
|
|
57
|
-
try {
|
|
58
|
-
const balance = await this.provider.getBalance(address);
|
|
59
|
-
return ethers.formatEther(balance);
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
console.error(`Failed to fetch balance for address ${address}:`, error);
|
|
63
|
-
throw new Error('Failed to fetch balance.');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
setTransaction(transaction, storageKey) {
|
|
67
|
-
const serializedTransaction = JSON.stringify(transaction, (_, value) => typeof value === 'bigint' ? value.toString() : value);
|
|
68
|
-
window.localStorage.setItem(storageKey, serializedTransaction);
|
|
69
|
-
}
|
|
70
|
-
getTransaction(storageKey, options) {
|
|
71
|
-
const txSerialized = window.localStorage.getItem(storageKey);
|
|
72
|
-
if (options?.remove) {
|
|
73
|
-
window.localStorage.removeItem(storageKey);
|
|
74
|
-
}
|
|
75
|
-
return txSerialized ? JSON.parse(txSerialized) : undefined;
|
|
76
|
-
}
|
|
77
|
-
async getMPCPayloadAndTransaction(transactionRequest) {
|
|
78
|
-
const transaction = await this.attachGasAndNonce(transactionRequest);
|
|
79
|
-
const txSerialized = ethers.Transaction.from(transaction).unsignedSerialized;
|
|
80
|
-
const transactionHash = keccak256(txSerialized);
|
|
81
|
-
const txHash = Array.from(ethers.getBytes(transactionHash));
|
|
82
|
-
return {
|
|
83
|
-
transaction,
|
|
84
|
-
mpcPayloads: [
|
|
85
|
-
{
|
|
86
|
-
index: 0,
|
|
87
|
-
payload: txHash,
|
|
88
|
-
},
|
|
89
|
-
],
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
addSignature({ transaction, mpcSignatures, }) {
|
|
93
|
-
return ethers.Transaction.from({
|
|
94
|
-
...transaction,
|
|
95
|
-
signature: this.parseSignature(mpcSignatures[0]),
|
|
96
|
-
}).serialized;
|
|
97
|
-
}
|
|
98
|
-
async broadcastTx(txSerialized) {
|
|
99
|
-
try {
|
|
100
|
-
const txResponse = await this.provider.broadcastTransaction(txSerialized);
|
|
101
|
-
return txResponse.hash;
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
console.error('Transaction broadcast failed:', error);
|
|
105
|
-
throw new Error('Failed to broadcast transaction.');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
package/src/chains/EVM/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/chains/EVM/utils.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
export async function fetchEVMFeeProperties(providerUrl, transaction) {
|
|
3
|
-
const provider = new ethers.JsonRpcProvider(providerUrl);
|
|
4
|
-
const gasLimit = await provider.estimateGas(transaction);
|
|
5
|
-
const feeData = await provider.getFeeData();
|
|
6
|
-
const maxFeePerGas = feeData.maxFeePerGas ?? ethers.parseUnits('10', 'gwei');
|
|
7
|
-
const maxPriorityFeePerGas = feeData.maxPriorityFeePerGas ?? ethers.parseUnits('10', 'gwei');
|
|
8
|
-
return {
|
|
9
|
-
gasLimit,
|
|
10
|
-
maxFeePerGas,
|
|
11
|
-
maxPriorityFeePerGas,
|
|
12
|
-
maxFee: maxFeePerGas * gasLimit,
|
|
13
|
-
};
|
|
14
|
-
}
|
package/src/chains/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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';
|
package/src/chains/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { Chain } from './Chain';
|
|
2
|
-
export { ChainSignatureContract } from './ChainSignatureContract';
|
|
3
|
-
export * from './types';
|
|
4
|
-
export * as utils from './utils';
|
|
5
|
-
// EVM
|
|
6
|
-
export { EVM } from './EVM/EVM';
|
|
7
|
-
export { fetchEVMFeeProperties } from './EVM/utils';
|
|
8
|
-
// Bitcoin
|
|
9
|
-
export { Bitcoin } from './Bitcoin/Bitcoin';
|
|
10
|
-
export { BTCRpcAdapters, BTCRpcAdapter } from './Bitcoin/BTCRpcAdapter';
|
|
11
|
-
// Cosmos
|
|
12
|
-
export { Cosmos } from './Cosmos/Cosmos';
|
package/src/chains/types.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type SignArgs } from '@chains';
|
|
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 {};
|
package/src/chains/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/chains/utils.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type MPCSignature, type RSVSignature, type UncompressedPubKeySEC1 } from '@chains';
|
|
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/src/chains/utils.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const toRSV = (signature) => {
|
|
2
|
-
return {
|
|
3
|
-
r: signature.big_r.affine_point.substring(2),
|
|
4
|
-
s: signature.s.scalar,
|
|
5
|
-
v: signature.recovery_id,
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Compresses an uncompressed public key to its compressed format following SEC1 standards.
|
|
10
|
-
* In SEC1, a compressed public key consists of a prefix (02 or 03) followed by the x-coordinate.
|
|
11
|
-
* The prefix indicates whether the y-coordinate is even (02) or odd (03).
|
|
12
|
-
*
|
|
13
|
-
* @param uncompressedPubKeySEC1 - The uncompressed public key in hex format, with or without '04' prefix
|
|
14
|
-
* @returns The compressed public key in hex format
|
|
15
|
-
* @throws Error if the uncompressed public key length is invalid
|
|
16
|
-
*/
|
|
17
|
-
export const compressPubKey = (uncompressedPubKeySEC1) => {
|
|
18
|
-
const slicedPubKey = uncompressedPubKeySEC1.slice(2);
|
|
19
|
-
if (slicedPubKey.length !== 128) {
|
|
20
|
-
throw new Error('Invalid uncompressed public key length');
|
|
21
|
-
}
|
|
22
|
-
const x = slicedPubKey.slice(0, 64);
|
|
23
|
-
const y = slicedPubKey.slice(64);
|
|
24
|
-
const isEven = parseInt(y.slice(-1), 16) % 2 === 0;
|
|
25
|
-
const prefix = isEven ? '02' : '03';
|
|
26
|
-
return prefix + x;
|
|
27
|
-
};
|
package/src/index.d.ts
DELETED
package/src/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as near from './near';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as near from './near';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Account } from '@near-js/accounts';
|
|
2
|
-
import { KeyPair } from '@near-js/crypto';
|
|
3
|
-
type SetConnectionArgs = {
|
|
4
|
-
networkId: string;
|
|
5
|
-
accountId: string;
|
|
6
|
-
keypair: KeyPair;
|
|
7
|
-
} | {
|
|
8
|
-
networkId: string;
|
|
9
|
-
accountId?: never;
|
|
10
|
-
keypair?: never;
|
|
11
|
-
};
|
|
12
|
-
export declare const getNearAccount: ({ networkId, accountId, keypair, }: SetConnectionArgs) => Promise<Account>;
|
|
13
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Account, Connection } from '@near-js/accounts';
|
|
2
|
-
import { KeyPair } from '@near-js/crypto';
|
|
3
|
-
import { InMemoryKeyStore } from '@near-js/keystores';
|
|
4
|
-
import { DONT_CARE_ACCOUNT_ID } from '@utils/chains/near/constants';
|
|
5
|
-
export const getNearAccount = async ({ networkId, accountId = DONT_CARE_ACCOUNT_ID, keypair = KeyPair.fromRandom('ed25519'), }) => {
|
|
6
|
-
const keyStore = new InMemoryKeyStore();
|
|
7
|
-
await keyStore.setKey(networkId, accountId, keypair);
|
|
8
|
-
const connection = Connection.fromConfig({
|
|
9
|
-
networkId,
|
|
10
|
-
provider: {
|
|
11
|
-
type: 'JsonRpcProvider',
|
|
12
|
-
args: {
|
|
13
|
-
url: {
|
|
14
|
-
testnet: 'https://rpc.testnet.near.org',
|
|
15
|
-
mainnet: 'https://rpc.mainnet.near.org',
|
|
16
|
-
}[networkId],
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
signer: { type: 'InMemorySigner', keyStore },
|
|
20
|
-
});
|
|
21
|
-
return new Account(connection, accountId);
|
|
22
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type Account } from '@near-js/accounts';
|
|
2
|
-
import { KeyPair } from '@near-js/crypto';
|
|
3
|
-
import BN from 'bn.js';
|
|
4
|
-
import { ChainSignatureContract } from '@chains';
|
|
5
|
-
import type { RSVSignature, UncompressedPubKeySEC1, SignArgs } from '@chains';
|
|
6
|
-
import { type NearNetworkIds, type ChainSignatureContractIds } from '@utils/chains/near/types';
|
|
7
|
-
interface ChainSignatureContractArgs {
|
|
8
|
-
networkId: NearNetworkIds;
|
|
9
|
-
contractId: ChainSignatureContractIds;
|
|
10
|
-
accountId?: string;
|
|
11
|
-
keypair?: KeyPair;
|
|
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
|
-
export declare class NearChainSignatureContract extends ChainSignatureContract {
|
|
18
|
-
private readonly networkId;
|
|
19
|
-
private readonly contractId;
|
|
20
|
-
private readonly accountId;
|
|
21
|
-
private readonly keypair;
|
|
22
|
-
constructor({ networkId, contractId, accountId, keypair, }: ChainSignatureContractArgs);
|
|
23
|
-
private getContract;
|
|
24
|
-
getPublicKey(): Promise<UncompressedPubKeySEC1>;
|
|
25
|
-
getCurrentSignatureDeposit(): Promise<BN>;
|
|
26
|
-
getDerivedPublicKey(args: {
|
|
27
|
-
path: string;
|
|
28
|
-
predecessor: string;
|
|
29
|
-
}): Promise<UncompressedPubKeySEC1>;
|
|
30
|
-
sign(args: SignArgs): Promise<RSVSignature>;
|
|
31
|
-
static signWithRelayer({ account, contract, signArgs, deposit, relayerUrl, }: {
|
|
32
|
-
account: Account;
|
|
33
|
-
contract: ChainSignatureContractIds;
|
|
34
|
-
signArgs: SignArgs;
|
|
35
|
-
deposit: BN;
|
|
36
|
-
relayerUrl: string;
|
|
37
|
-
}): Promise<RSVSignature>;
|
|
38
|
-
}
|
|
39
|
-
export {};
|