signet.js 0.0.1-beta.7 → 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 +18 -12
- package/types/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.d.ts +10 -0
- package/types/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.d.ts +15 -0
- package/types/chains/Bitcoin/BTCRpcAdapter/Mempool/index.d.ts +1 -0
- package/types/chains/Bitcoin/BTCRpcAdapter/Mempool/types.d.ts +69 -0
- package/types/chains/Bitcoin/BTCRpcAdapter/index.d.ts +5 -0
- package/types/chains/Bitcoin/Bitcoin.d.ts +42 -0
- package/types/chains/Bitcoin/types.d.ts +42 -0
- package/types/chains/Bitcoin/utils.d.ts +2 -0
- package/types/chains/Chain.d.ts +21 -0
- package/types/chains/ChainSignatureContract.d.ts +18 -0
- package/types/chains/Cosmos/Cosmos.d.ts +38 -0
- package/types/chains/Cosmos/types.d.ts +30 -0
- package/types/chains/Cosmos/utils.d.ts +2 -0
- package/types/chains/EVM/EVM.d.ts +32 -0
- package/types/chains/EVM/types.d.ts +5 -0
- package/types/chains/EVM/utils.d.ts +7 -0
- package/types/chains/index.d.ts +11 -0
- package/types/chains/types.d.ts +18 -0
- package/types/index.d.ts +2 -0
- package/types/utils/chains/index.d.ts +1 -0
- package/types/utils/chains/near/ChainSignatureContract.d.ts +35 -0
- package/types/utils/chains/near/account.d.ts +13 -0
- package/types/utils/chains/near/constants.d.ts +3 -0
- package/types/utils/chains/near/index.d.ts +3 -0
- package/types/utils/chains/near/relayer/index.d.ts +1 -0
- package/types/utils/chains/near/relayer/relayer.d.ts +3 -0
- package/types/utils/chains/near/relayer/types.d.ts +22 -0
- package/types/utils/chains/near/signAndSend/index.d.ts +1 -0
- package/types/utils/chains/near/signAndSend/keypair.d.ts +5 -0
- package/types/utils/chains/near/transactionBuilder.d.ts +26 -0
- package/types/utils/chains/near/types.d.ts +54 -0
- package/types/utils/cryptography.d.ts +3 -0
- package/types/utils/index.d.ts +2 -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
package/package.json
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
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
|
-
"publish-npm:beta": "npm run pre:deploy && npm publish --tag beta",
|
|
31
|
+
"publish-npm:beta": "npm run pre:deploy && cd dist && npm publish --tag beta",
|
|
26
32
|
"test": "jest",
|
|
27
33
|
"docs:dev": "vocs dev",
|
|
28
34
|
"docs:build": "vocs build",
|
|
@@ -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,42 @@
|
|
|
1
|
+
import { BTCRpcAdapter } from './BTCRpcAdapter';
|
|
2
|
+
import { BTCNetworkIds, BTCTransactionRequest, BTCUnsignedTransaction } from './types';
|
|
3
|
+
import { Chain } from '../Chain';
|
|
4
|
+
import { BaseChainSignatureContract } from '../ChainSignatureContract';
|
|
5
|
+
import { MPCPayloads, RSVSignature, KeyDerivationPath } from '../types';
|
|
6
|
+
import * as bitcoin from 'bitcoinjs-lib';
|
|
7
|
+
export declare class Bitcoin extends Chain<BTCTransactionRequest, BTCUnsignedTransaction> {
|
|
8
|
+
private static readonly SATOSHIS_PER_BTC;
|
|
9
|
+
private readonly network;
|
|
10
|
+
private readonly btcRpcAdapter;
|
|
11
|
+
private readonly contract;
|
|
12
|
+
constructor({ network, contract, btcRpcAdapter, }: {
|
|
13
|
+
network: BTCNetworkIds;
|
|
14
|
+
contract: BaseChainSignatureContract;
|
|
15
|
+
btcRpcAdapter: BTCRpcAdapter;
|
|
16
|
+
});
|
|
17
|
+
static toBTC(satoshis: number): number;
|
|
18
|
+
static toSatoshi(btc: number): number;
|
|
19
|
+
private fetchTransaction;
|
|
20
|
+
private static parseRSVSignature;
|
|
21
|
+
createPSBT({ transactionRequest, }: {
|
|
22
|
+
transactionRequest: BTCTransactionRequest;
|
|
23
|
+
}): Promise<bitcoin.Psbt>;
|
|
24
|
+
getBalance(address: string): Promise<string>;
|
|
25
|
+
deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
|
|
26
|
+
address: string;
|
|
27
|
+
publicKey: string;
|
|
28
|
+
}>;
|
|
29
|
+
setTransaction(transaction: BTCUnsignedTransaction, storageKey: string): void;
|
|
30
|
+
getTransaction(storageKey: string, options?: {
|
|
31
|
+
remove?: boolean;
|
|
32
|
+
}): BTCUnsignedTransaction | undefined;
|
|
33
|
+
getMPCPayloadAndTransaction(transactionRequest: BTCTransactionRequest): Promise<{
|
|
34
|
+
transaction: BTCUnsignedTransaction;
|
|
35
|
+
mpcPayloads: MPCPayloads;
|
|
36
|
+
}>;
|
|
37
|
+
addSignature({ transaction: { psbt, publicKey }, mpcSignatures, }: {
|
|
38
|
+
transaction: BTCUnsignedTransaction;
|
|
39
|
+
mpcSignatures: RSVSignature[];
|
|
40
|
+
}): string;
|
|
41
|
+
broadcastTx(txSerialized: string): Promise<string>;
|
|
42
|
+
}
|
|
@@ -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,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
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Chain } from '../Chain';
|
|
2
|
+
import { BaseChainSignatureContract } from '../ChainSignatureContract';
|
|
3
|
+
import { CosmosNetworkIds, CosmosTransactionRequest, CosmosUnsignedTransaction } from './types';
|
|
4
|
+
import { MPCPayloads, RSVSignature, KeyDerivationPath } from '../types';
|
|
5
|
+
export declare class Cosmos extends Chain<CosmosTransactionRequest, CosmosUnsignedTransaction> {
|
|
6
|
+
private readonly registry;
|
|
7
|
+
private readonly chainId;
|
|
8
|
+
private readonly contract;
|
|
9
|
+
private readonly endpoints?;
|
|
10
|
+
constructor({ chainId, contract, endpoints, }: {
|
|
11
|
+
contract: BaseChainSignatureContract;
|
|
12
|
+
chainId: CosmosNetworkIds;
|
|
13
|
+
endpoints?: {
|
|
14
|
+
rpcUrl?: string;
|
|
15
|
+
restUrl?: string;
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
private parseRSVSignature;
|
|
19
|
+
private getChainInfo;
|
|
20
|
+
getBalance(address: string): Promise<string>;
|
|
21
|
+
deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
|
|
22
|
+
address: string;
|
|
23
|
+
publicKey: string;
|
|
24
|
+
}>;
|
|
25
|
+
setTransaction(transaction: CosmosUnsignedTransaction, storageKey: string): void;
|
|
26
|
+
getTransaction(storageKey: string, options?: {
|
|
27
|
+
remove?: boolean;
|
|
28
|
+
}): CosmosUnsignedTransaction | undefined;
|
|
29
|
+
getMPCPayloadAndTransaction(transactionRequest: CosmosTransactionRequest): Promise<{
|
|
30
|
+
transaction: CosmosUnsignedTransaction;
|
|
31
|
+
mpcPayloads: MPCPayloads;
|
|
32
|
+
}>;
|
|
33
|
+
addSignature({ transaction, mpcSignatures, }: {
|
|
34
|
+
transaction: CosmosUnsignedTransaction;
|
|
35
|
+
mpcSignatures: RSVSignature[];
|
|
36
|
+
}): string;
|
|
37
|
+
broadcastTx(txSerialized: string): Promise<string>;
|
|
38
|
+
}
|
|
@@ -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,32 @@
|
|
|
1
|
+
import { Chain } from '../Chain';
|
|
2
|
+
import { BaseChainSignatureContract } from '../ChainSignatureContract';
|
|
3
|
+
import { EVMTransactionRequest, EVMUnsignedTransaction } from './types';
|
|
4
|
+
import { MPCPayloads, RSVSignature, KeyDerivationPath } from '../types';
|
|
5
|
+
export declare class EVM extends Chain<EVMTransactionRequest, EVMUnsignedTransaction> {
|
|
6
|
+
private readonly provider;
|
|
7
|
+
private readonly contract;
|
|
8
|
+
constructor({ rpcUrl, contract, }: {
|
|
9
|
+
rpcUrl: string;
|
|
10
|
+
contract: BaseChainSignatureContract;
|
|
11
|
+
});
|
|
12
|
+
private attachGasAndNonce;
|
|
13
|
+
private parseSignature;
|
|
14
|
+
deriveAddressAndPublicKey(predecessor: string, path: KeyDerivationPath): Promise<{
|
|
15
|
+
address: string;
|
|
16
|
+
publicKey: string;
|
|
17
|
+
}>;
|
|
18
|
+
getBalance(address: string): Promise<string>;
|
|
19
|
+
setTransaction(transaction: EVMUnsignedTransaction, storageKey: string): void;
|
|
20
|
+
getTransaction(storageKey: string, options?: {
|
|
21
|
+
remove?: boolean;
|
|
22
|
+
}): EVMUnsignedTransaction | undefined;
|
|
23
|
+
getMPCPayloadAndTransaction(transactionRequest: EVMTransactionRequest): Promise<{
|
|
24
|
+
transaction: EVMUnsignedTransaction;
|
|
25
|
+
mpcPayloads: MPCPayloads;
|
|
26
|
+
}>;
|
|
27
|
+
addSignature({ transaction, mpcSignatures, }: {
|
|
28
|
+
transaction: EVMUnsignedTransaction;
|
|
29
|
+
mpcSignatures: RSVSignature[];
|
|
30
|
+
}): string;
|
|
31
|
+
broadcastTx(txSerialized: string): Promise<string>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { Chain } from './Chain';
|
|
2
|
+
export { ChainSignatureContract, type SignArgs } from './ChainSignatureContract';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export { EVM } from './EVM/EVM';
|
|
5
|
+
export { fetchEVMFeeProperties } from './EVM/utils';
|
|
6
|
+
export type { EVMTransactionRequest, EVMUnsignedTransaction } from './EVM/types';
|
|
7
|
+
export { Bitcoin } from './Bitcoin/Bitcoin';
|
|
8
|
+
export { BTCRpcAdapters, BTCRpcAdapter } from './Bitcoin/BTCRpcAdapter';
|
|
9
|
+
export type { BTCTransactionRequest, BTCUnsignedTransaction, BTCTransaction, BTCOutput, BTCInput, BTCNetworkIds, } from './Bitcoin/types';
|
|
10
|
+
export { Cosmos } from './Cosmos/Cosmos';
|
|
11
|
+
export type { CosmosNetworkIds, CosmosTransactionRequest, CosmosUnsignedTransaction, } from './Cosmos/types';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SignArgs } from './ChainSignatureContract';
|
|
2
|
+
export type MPCPayloads = Array<SignArgs['payload']>;
|
|
3
|
+
export type UncompressedPubKeySEC1 = `04${string}`;
|
|
4
|
+
export type KeyDerivationPath = string;
|
|
5
|
+
export interface RSVSignature {
|
|
6
|
+
r: string;
|
|
7
|
+
s: string;
|
|
8
|
+
v: number;
|
|
9
|
+
}
|
|
10
|
+
export interface MPCSignature {
|
|
11
|
+
big_r: {
|
|
12
|
+
affine_point: string;
|
|
13
|
+
};
|
|
14
|
+
s: {
|
|
15
|
+
scalar: string;
|
|
16
|
+
};
|
|
17
|
+
recovery_id: number;
|
|
18
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as near from './near';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Account } from '@near-js/accounts';
|
|
2
|
+
import { KeyPair } from '@near-js/crypto';
|
|
3
|
+
import { default as BN } from 'bn.js';
|
|
4
|
+
import { ChainSignatureContract as AbstractChainSignatureContract, SignArgs } from '../../../chains/ChainSignatureContract';
|
|
5
|
+
import { RSVSignature, UncompressedPubKeySEC1 } from '../../../chains/types';
|
|
6
|
+
import { NearNetworkIds, ChainSignatureContractIds } from './types';
|
|
7
|
+
interface ChainSignatureContractArgs {
|
|
8
|
+
networkId: NearNetworkIds;
|
|
9
|
+
contractId: ChainSignatureContractIds;
|
|
10
|
+
accountId?: string;
|
|
11
|
+
keypair?: KeyPair;
|
|
12
|
+
}
|
|
13
|
+
export declare class ChainSignatureContract extends AbstractChainSignatureContract {
|
|
14
|
+
private readonly networkId;
|
|
15
|
+
private readonly contractId;
|
|
16
|
+
private readonly accountId;
|
|
17
|
+
private readonly keypair;
|
|
18
|
+
constructor({ networkId, contractId, accountId, keypair, }: ChainSignatureContractArgs);
|
|
19
|
+
private getContract;
|
|
20
|
+
getCurrentSignatureDeposit(): Promise<BN>;
|
|
21
|
+
getDerivedPublicKey(args: {
|
|
22
|
+
path: string;
|
|
23
|
+
predecessor: string;
|
|
24
|
+
}): Promise<UncompressedPubKeySEC1>;
|
|
25
|
+
getPublicKey(): Promise<UncompressedPubKeySEC1>;
|
|
26
|
+
sign(args: SignArgs): Promise<RSVSignature>;
|
|
27
|
+
static signWithRelayer({ account, contract, signArgs, deposit, relayerUrl, }: {
|
|
28
|
+
account: Account;
|
|
29
|
+
contract: ChainSignatureContractIds;
|
|
30
|
+
signArgs: SignArgs;
|
|
31
|
+
deposit: BN;
|
|
32
|
+
relayerUrl: string;
|
|
33
|
+
}): Promise<RSVSignature>;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './relayer';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
interface FunctionCallRelayer {
|
|
2
|
+
FunctionCall: {
|
|
3
|
+
method_name: string;
|
|
4
|
+
args: string;
|
|
5
|
+
gas: number;
|
|
6
|
+
deposit: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
type ActionsRelayer = FunctionCallRelayer;
|
|
10
|
+
interface DelegateActionRelayerFormat {
|
|
11
|
+
actions: ActionsRelayer[];
|
|
12
|
+
nonce: number;
|
|
13
|
+
max_block_height: number;
|
|
14
|
+
public_key: string;
|
|
15
|
+
receiver_id: string;
|
|
16
|
+
sender_id: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SignedDelegateRelayerFormat {
|
|
19
|
+
delegate_action: DelegateActionRelayerFormat;
|
|
20
|
+
signature: string;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as keypair from './keypair';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { KeyPair } from '@near-js/crypto';
|
|
2
|
+
import { Response, BitcoinRequest, CosmosRequest, EVMRequest } from '../types';
|
|
3
|
+
export declare const EVMTransaction: (req: EVMRequest, keyPair: KeyPair) => Promise<Response>;
|
|
4
|
+
export declare const BTCTransaction: (req: BitcoinRequest, keyPair: KeyPair) => Promise<Response>;
|
|
5
|
+
export declare const CosmosTransaction: (req: CosmosRequest, keyPair: KeyPair) => Promise<Response>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Action, FinalExecutionOutcome, NetworkId } from '@near-wallet-selector/core';
|
|
2
|
+
import { RSVSignature, KeyDerivationPath, MPCPayloads } from '../../../chains/types';
|
|
3
|
+
import { NFTKeysContracts, ChainSignatureContractIds } from './types';
|
|
4
|
+
export declare const mpcPayloadsToChainSigTransaction: ({ networkId, contractId, mpcPayloads, path, }: {
|
|
5
|
+
networkId: NetworkId;
|
|
6
|
+
contractId: ChainSignatureContractIds;
|
|
7
|
+
mpcPayloads: MPCPayloads;
|
|
8
|
+
path: KeyDerivationPath;
|
|
9
|
+
}) => Promise<{
|
|
10
|
+
receiverId: string;
|
|
11
|
+
actions: Action[];
|
|
12
|
+
}>;
|
|
13
|
+
export declare const mpcPayloadsToNFTKeysTransaction: ({ networkId, chainSigContract, nftKeysContract, mpcPayloads, path, tokenId, }: {
|
|
14
|
+
networkId: NetworkId;
|
|
15
|
+
chainSigContract: ChainSignatureContractIds;
|
|
16
|
+
nftKeysContract: NFTKeysContracts;
|
|
17
|
+
mpcPayloads: MPCPayloads;
|
|
18
|
+
path: KeyDerivationPath;
|
|
19
|
+
tokenId: string;
|
|
20
|
+
}) => Promise<{
|
|
21
|
+
receiverId: string;
|
|
22
|
+
actions: Action[];
|
|
23
|
+
}>;
|
|
24
|
+
export declare const responseToMpcSignature: ({ response, }: {
|
|
25
|
+
response: FinalExecutionOutcome;
|
|
26
|
+
}) => RSVSignature | undefined;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BTCTransactionRequest, BTCNetworkIds } from '../../../chains/Bitcoin/types';
|
|
2
|
+
import { CosmosNetworkIds, CosmosTransactionRequest } from '../../../chains/Cosmos/types';
|
|
3
|
+
import { EVMTransactionRequest } from '../../../chains/EVM/types';
|
|
4
|
+
import { KeyDerivationPath } from '../../../chains/types';
|
|
5
|
+
export type ChainSignatureContractIds = string;
|
|
6
|
+
export type NFTKeysContracts = string;
|
|
7
|
+
export type NearNetworkIds = 'mainnet' | 'testnet';
|
|
8
|
+
export interface ChainProvider {
|
|
9
|
+
providerUrl: string;
|
|
10
|
+
contract: ChainSignatureContractIds;
|
|
11
|
+
}
|
|
12
|
+
export interface NearAuthentication {
|
|
13
|
+
networkId: NearNetworkIds;
|
|
14
|
+
accountId: string;
|
|
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;
|
|
25
|
+
export type EVMChainConfigWithProviders = ChainProvider;
|
|
26
|
+
export interface EVMRequest {
|
|
27
|
+
transaction: EVMTransactionRequest;
|
|
28
|
+
chainConfig: EVMChainConfigWithProviders;
|
|
29
|
+
nearAuthentication: NearAuthentication;
|
|
30
|
+
fastAuthRelayerUrl?: string;
|
|
31
|
+
derivationPath: KeyDerivationPath;
|
|
32
|
+
}
|
|
33
|
+
export type BTCChainConfigWithProviders = ChainProvider & {
|
|
34
|
+
network: BTCNetworkIds;
|
|
35
|
+
};
|
|
36
|
+
export interface BitcoinRequest {
|
|
37
|
+
transaction: BTCTransactionRequest;
|
|
38
|
+
chainConfig: BTCChainConfigWithProviders;
|
|
39
|
+
nearAuthentication: NearAuthentication;
|
|
40
|
+
fastAuthRelayerUrl?: string;
|
|
41
|
+
derivationPath: KeyDerivationPath;
|
|
42
|
+
}
|
|
43
|
+
export interface CosmosChainConfig {
|
|
44
|
+
contract: ChainSignatureContractIds;
|
|
45
|
+
chainId: CosmosNetworkIds;
|
|
46
|
+
}
|
|
47
|
+
export interface CosmosRequest {
|
|
48
|
+
chainConfig: CosmosChainConfig;
|
|
49
|
+
transaction: CosmosTransactionRequest;
|
|
50
|
+
nearAuthentication: NearAuthentication;
|
|
51
|
+
derivationPath: KeyDerivationPath;
|
|
52
|
+
fastAuthRelayerUrl?: string;
|
|
53
|
+
}
|
|
54
|
+
export {};
|