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,101 +0,0 @@
|
|
|
1
|
-
import { Contract } from '@near-js/accounts';
|
|
2
|
-
import { KeyPair } from '@near-js/crypto';
|
|
3
|
-
import { actionCreators } from '@near-js/transactions';
|
|
4
|
-
import BN from 'bn.js';
|
|
5
|
-
import { base_decode } from 'near-api-js/lib/utils/serialize';
|
|
6
|
-
import { ChainSignatureContract, utils } from '@chains';
|
|
7
|
-
import { chains } from '@utils';
|
|
8
|
-
import { getNearAccount } from '@utils/chains/near/account';
|
|
9
|
-
import { DONT_CARE_ACCOUNT_ID, NEAR_MAX_GAS, } from '@utils/chains/near/constants';
|
|
10
|
-
import { parseSignedDelegateForRelayer } from '@utils/chains/near/relayer';
|
|
11
|
-
const najToUncompressedPubKey = (najPubKey) => {
|
|
12
|
-
return `04${Buffer.from(base_decode(najPubKey.split(':')[1])).toString('hex')}`;
|
|
13
|
-
};
|
|
14
|
-
const requireAccount = (accountId) => {
|
|
15
|
-
if (accountId === DONT_CARE_ACCOUNT_ID) {
|
|
16
|
-
throw new Error('A valid account ID and keypair are required for change methods. Please instantiate a new contract with valid credentials.');
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* This contract will default to view methods only.
|
|
21
|
-
* If you want to use the change methods, you need to provide an account and keypair.
|
|
22
|
-
*/
|
|
23
|
-
export class NearChainSignatureContract extends ChainSignatureContract {
|
|
24
|
-
constructor({ networkId, contractId, accountId = DONT_CARE_ACCOUNT_ID, keypair = KeyPair.fromRandom('ed25519'), }) {
|
|
25
|
-
super();
|
|
26
|
-
this.networkId = networkId;
|
|
27
|
-
this.contractId = contractId;
|
|
28
|
-
this.accountId = accountId;
|
|
29
|
-
this.keypair = keypair;
|
|
30
|
-
}
|
|
31
|
-
async getContract() {
|
|
32
|
-
const account = await getNearAccount({
|
|
33
|
-
networkId: this.networkId,
|
|
34
|
-
accountId: this.accountId,
|
|
35
|
-
keypair: this.keypair,
|
|
36
|
-
});
|
|
37
|
-
return new Contract(account, this.contractId, {
|
|
38
|
-
viewMethods: [
|
|
39
|
-
'public_key',
|
|
40
|
-
'experimental_signature_deposit',
|
|
41
|
-
'derived_public_key',
|
|
42
|
-
],
|
|
43
|
-
changeMethods: ['sign'],
|
|
44
|
-
useLocalViewExecution: false,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
async getPublicKey() {
|
|
48
|
-
const contract = await this.getContract();
|
|
49
|
-
const najPubKey = await contract.public_key();
|
|
50
|
-
return najToUncompressedPubKey(najPubKey);
|
|
51
|
-
}
|
|
52
|
-
async getCurrentSignatureDeposit() {
|
|
53
|
-
const contract = await this.getContract();
|
|
54
|
-
return new BN((await contract.experimental_signature_deposit()).toLocaleString('fullwide', {
|
|
55
|
-
useGrouping: false,
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
async getDerivedPublicKey(args) {
|
|
59
|
-
const contract = await this.getContract();
|
|
60
|
-
const najPubKey = await contract.derived_public_key(args);
|
|
61
|
-
return najToUncompressedPubKey(najPubKey);
|
|
62
|
-
}
|
|
63
|
-
async sign(args) {
|
|
64
|
-
requireAccount(this.accountId);
|
|
65
|
-
const contract = await this.getContract();
|
|
66
|
-
const deposit = await this.getCurrentSignatureDeposit();
|
|
67
|
-
const signature = await contract.sign({
|
|
68
|
-
args: { request: args },
|
|
69
|
-
gas: NEAR_MAX_GAS,
|
|
70
|
-
amount: deposit,
|
|
71
|
-
});
|
|
72
|
-
return utils.toRSV(signature);
|
|
73
|
-
}
|
|
74
|
-
static async signWithRelayer({ account, contract, signArgs, deposit, relayerUrl, }) {
|
|
75
|
-
const functionCall = actionCreators.functionCall('sign', { request: signArgs }, BigInt(NEAR_MAX_GAS.toString()), BigInt(deposit.toString()));
|
|
76
|
-
const signedDelegate = await account.signedDelegate({
|
|
77
|
-
receiverId: contract,
|
|
78
|
-
actions: [functionCall],
|
|
79
|
-
blockHeightTtl: 60,
|
|
80
|
-
});
|
|
81
|
-
// Remove the cached access key to prevent nonce reuse
|
|
82
|
-
delete account.accessKeyByPublicKeyCache[
|
|
83
|
-
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
84
|
-
signedDelegate.delegateAction.publicKey.toString()];
|
|
85
|
-
const res = await fetch(`${relayerUrl}/send_meta_tx_async`, {
|
|
86
|
-
method: 'POST',
|
|
87
|
-
mode: 'cors',
|
|
88
|
-
body: JSON.stringify(parseSignedDelegateForRelayer(signedDelegate)),
|
|
89
|
-
headers: new Headers({ 'Content-Type': 'application/json' }),
|
|
90
|
-
});
|
|
91
|
-
const txHash = await res.text();
|
|
92
|
-
const txStatus = await account.connection.provider.txStatus(txHash, account.accountId, 'FINAL');
|
|
93
|
-
const signature = chains.near.transactionBuilder.responseToMpcSignature({
|
|
94
|
-
response: txStatus,
|
|
95
|
-
});
|
|
96
|
-
if (!signature) {
|
|
97
|
-
throw new Error('Signature error, please retry');
|
|
98
|
-
}
|
|
99
|
-
return signature;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './relayer';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './relayer';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type SignedDelegate } from '@near-js/transactions';
|
|
2
|
-
import { type SignedDelegateRelayerFormat } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Parses the signedDelegate object from the Multi-Party Computation (MPC) format to the Relayer format.
|
|
5
|
-
* @param signedDelegate - The signedDelegate object in MPC format.
|
|
6
|
-
* @returns The signedDelegate object in Relayer format.
|
|
7
|
-
*/
|
|
8
|
-
export declare function parseSignedDelegateForRelayer(signedDelegate: SignedDelegate): SignedDelegateRelayerFormat;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import bs58 from 'bs58';
|
|
2
|
-
/**
|
|
3
|
-
* Parses the signedDelegate object from the Multi-Party Computation (MPC) format to the Relayer format.
|
|
4
|
-
* @param signedDelegate - The signedDelegate object in MPC format.
|
|
5
|
-
* @returns The signedDelegate object in Relayer format.
|
|
6
|
-
*/
|
|
7
|
-
export function parseSignedDelegateForRelayer(signedDelegate) {
|
|
8
|
-
return {
|
|
9
|
-
delegate_action: {
|
|
10
|
-
actions: signedDelegate.delegateAction.actions
|
|
11
|
-
.map((action) => {
|
|
12
|
-
if (action.functionCall) {
|
|
13
|
-
return {
|
|
14
|
-
FunctionCall: {
|
|
15
|
-
method_name: action.functionCall.methodName,
|
|
16
|
-
args: Buffer.from(action.functionCall.args).toString('base64'),
|
|
17
|
-
gas: Number(action.functionCall.gas),
|
|
18
|
-
deposit: action.functionCall.deposit.toString(),
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return undefined;
|
|
23
|
-
})
|
|
24
|
-
.flatMap((t) => (t ? [t] : [])),
|
|
25
|
-
nonce: Number(signedDelegate.delegateAction.nonce),
|
|
26
|
-
max_block_height: Number(signedDelegate.delegateAction.maxBlockHeight),
|
|
27
|
-
public_key: signedDelegate.delegateAction.publicKey.toString(),
|
|
28
|
-
receiver_id: signedDelegate.delegateAction.receiverId,
|
|
29
|
-
sender_id: signedDelegate.delegateAction.senderId,
|
|
30
|
-
},
|
|
31
|
-
signature: `ed25519:${bs58.encode(signedDelegate.signature.data)}`,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
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 {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as keypair from './keypair';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as keypair from './keypair';
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type KeyPair } from '@near-js/crypto';
|
|
2
|
-
import { type Response } from '@chains';
|
|
3
|
-
import { type BitcoinRequest, type CosmosRequest, type EVMRequest } from '@utils/chains/near/types';
|
|
4
|
-
export declare const EVMTransaction: (req: EVMRequest, keyPair: KeyPair) => Promise<Response>;
|
|
5
|
-
export declare const BTCTransaction: (req: BitcoinRequest, keyPair: KeyPair) => Promise<Response>;
|
|
6
|
-
export declare const CosmosTransaction: (req: CosmosRequest, keyPair: KeyPair) => Promise<Response>;
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { Bitcoin, Cosmos, EVM, BTCRpcAdapters } from '@chains';
|
|
2
|
-
import { getNearAccount } from '@utils/chains/near/account';
|
|
3
|
-
import { NearChainSignatureContract } from '@utils/chains/near/contract';
|
|
4
|
-
export const EVMTransaction = async (req, keyPair) => {
|
|
5
|
-
try {
|
|
6
|
-
const account = await getNearAccount({
|
|
7
|
-
networkId: req.nearAuthentication.networkId,
|
|
8
|
-
accountId: req.nearAuthentication.accountId,
|
|
9
|
-
keypair: keyPair,
|
|
10
|
-
});
|
|
11
|
-
const contract = new NearChainSignatureContract({
|
|
12
|
-
networkId: req.nearAuthentication.networkId,
|
|
13
|
-
contractId: req.chainConfig.contract,
|
|
14
|
-
accountId: account.accountId,
|
|
15
|
-
keypair: keyPair,
|
|
16
|
-
});
|
|
17
|
-
const evm = new EVM({
|
|
18
|
-
rpcUrl: req.chainConfig.providerUrl,
|
|
19
|
-
contract,
|
|
20
|
-
});
|
|
21
|
-
const { transaction, mpcPayloads } = await evm.getMPCPayloadAndTransaction(req.transaction);
|
|
22
|
-
const signature = await contract.sign({
|
|
23
|
-
payload: mpcPayloads[0].payload,
|
|
24
|
-
path: req.derivationPath,
|
|
25
|
-
key_version: 0,
|
|
26
|
-
});
|
|
27
|
-
const txSerialized = evm.addSignature({
|
|
28
|
-
transaction,
|
|
29
|
-
mpcSignatures: [signature],
|
|
30
|
-
});
|
|
31
|
-
const txHash = await evm.broadcastTx(txSerialized);
|
|
32
|
-
return {
|
|
33
|
-
transactionHash: txHash,
|
|
34
|
-
success: true,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
console.error(e);
|
|
39
|
-
return {
|
|
40
|
-
success: false,
|
|
41
|
-
errorMessage: e instanceof Error ? e.message : String(e),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
export const BTCTransaction = async (req, keyPair) => {
|
|
46
|
-
try {
|
|
47
|
-
const account = await getNearAccount({
|
|
48
|
-
networkId: req.nearAuthentication.networkId,
|
|
49
|
-
accountId: req.nearAuthentication.accountId,
|
|
50
|
-
keypair: keyPair,
|
|
51
|
-
});
|
|
52
|
-
const contract = new NearChainSignatureContract({
|
|
53
|
-
networkId: req.nearAuthentication.networkId,
|
|
54
|
-
contractId: req.chainConfig.contract,
|
|
55
|
-
accountId: account.accountId,
|
|
56
|
-
keypair: keyPair,
|
|
57
|
-
});
|
|
58
|
-
const btc = new Bitcoin({
|
|
59
|
-
btcRpcAdapter: new BTCRpcAdapters.Mempool(req.chainConfig.providerUrl),
|
|
60
|
-
contract,
|
|
61
|
-
network: req.chainConfig.network,
|
|
62
|
-
});
|
|
63
|
-
const { transaction, mpcPayloads } = await btc.getMPCPayloadAndTransaction(req.transaction);
|
|
64
|
-
const signatures = await Promise.all(mpcPayloads.map(async ({ payload }) => await contract.sign({
|
|
65
|
-
payload,
|
|
66
|
-
path: req.derivationPath,
|
|
67
|
-
key_version: 0,
|
|
68
|
-
})));
|
|
69
|
-
const txSerialized = btc.addSignature({
|
|
70
|
-
transaction,
|
|
71
|
-
mpcSignatures: signatures,
|
|
72
|
-
});
|
|
73
|
-
const txHash = await btc.broadcastTx(txSerialized);
|
|
74
|
-
return {
|
|
75
|
-
transactionHash: txHash,
|
|
76
|
-
success: true,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
catch (e) {
|
|
80
|
-
return {
|
|
81
|
-
success: false,
|
|
82
|
-
errorMessage: e instanceof Error ? e.message : String(e),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
export const CosmosTransaction = async (req, keyPair) => {
|
|
87
|
-
try {
|
|
88
|
-
const account = await getNearAccount({
|
|
89
|
-
networkId: req.nearAuthentication.networkId,
|
|
90
|
-
accountId: req.nearAuthentication.accountId,
|
|
91
|
-
keypair: keyPair,
|
|
92
|
-
});
|
|
93
|
-
const contract = new NearChainSignatureContract({
|
|
94
|
-
networkId: req.nearAuthentication.networkId,
|
|
95
|
-
contractId: req.chainConfig.contract,
|
|
96
|
-
accountId: account.accountId,
|
|
97
|
-
keypair: keyPair,
|
|
98
|
-
});
|
|
99
|
-
const cosmos = new Cosmos({
|
|
100
|
-
contract,
|
|
101
|
-
chainId: req.chainConfig.chainId,
|
|
102
|
-
});
|
|
103
|
-
const { transaction, mpcPayloads } = await cosmos.getMPCPayloadAndTransaction(req.transaction);
|
|
104
|
-
const signatures = await Promise.all(mpcPayloads.map(async ({ payload }) => await contract.sign({
|
|
105
|
-
payload,
|
|
106
|
-
path: req.derivationPath,
|
|
107
|
-
key_version: 0,
|
|
108
|
-
})));
|
|
109
|
-
const txSerialized = cosmos.addSignature({
|
|
110
|
-
transaction,
|
|
111
|
-
mpcSignatures: signatures,
|
|
112
|
-
});
|
|
113
|
-
const txHash = await cosmos.broadcastTx(txSerialized);
|
|
114
|
-
return {
|
|
115
|
-
transactionHash: txHash,
|
|
116
|
-
success: true,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
catch (e) {
|
|
120
|
-
console.error(e);
|
|
121
|
-
return {
|
|
122
|
-
success: false,
|
|
123
|
-
errorMessage: e instanceof Error ? e.message : String(e),
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Action, FinalExecutionOutcome, NetworkId } from '@near-wallet-selector/core';
|
|
2
|
-
import { type RSVSignature, type KeyDerivationPath, type MPCPayloads } from '@chains';
|
|
3
|
-
import { type NFTKeysContracts, type ChainSignatureContractIds } from '@utils/chains/near/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;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import BN from 'bn.js';
|
|
2
|
-
import { utils } from '@chains';
|
|
3
|
-
import { NEAR_MAX_GAS } from '@utils/chains/near/constants';
|
|
4
|
-
import { NearChainSignatureContract } from '@utils/chains/near/contract';
|
|
5
|
-
export const mpcPayloadsToChainSigTransaction = async ({ networkId, contractId, mpcPayloads, path, }) => {
|
|
6
|
-
const contract = new NearChainSignatureContract({
|
|
7
|
-
networkId,
|
|
8
|
-
contractId,
|
|
9
|
-
});
|
|
10
|
-
const currentContractFee = await contract.getCurrentSignatureDeposit();
|
|
11
|
-
return {
|
|
12
|
-
receiverId: contractId,
|
|
13
|
-
actions: mpcPayloads.map(({ payload }) => ({
|
|
14
|
-
type: 'FunctionCall',
|
|
15
|
-
params: {
|
|
16
|
-
methodName: 'sign',
|
|
17
|
-
args: {
|
|
18
|
-
request: {
|
|
19
|
-
payload: Array.from(payload),
|
|
20
|
-
path,
|
|
21
|
-
key_version: 0,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
gas: NEAR_MAX_GAS.div(new BN(mpcPayloads.length)).toString(),
|
|
25
|
-
deposit: currentContractFee?.toString() || '1',
|
|
26
|
-
},
|
|
27
|
-
})),
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
export const mpcPayloadsToNFTKeysTransaction = async ({ networkId, chainSigContract, nftKeysContract, mpcPayloads, path, tokenId, }) => {
|
|
31
|
-
const contract = new NearChainSignatureContract({
|
|
32
|
-
networkId,
|
|
33
|
-
contractId: chainSigContract,
|
|
34
|
-
});
|
|
35
|
-
const currentContractFee = await contract.getCurrentSignatureDeposit();
|
|
36
|
-
return {
|
|
37
|
-
receiverId: nftKeysContract,
|
|
38
|
-
actions: mpcPayloads.map(({ payload }) => ({
|
|
39
|
-
type: 'FunctionCall',
|
|
40
|
-
params: {
|
|
41
|
-
methodName: 'ckt_sign_hash',
|
|
42
|
-
args: {
|
|
43
|
-
token_id: tokenId,
|
|
44
|
-
path,
|
|
45
|
-
payload: Array.from(payload),
|
|
46
|
-
},
|
|
47
|
-
gas: NEAR_MAX_GAS.div(new BN(mpcPayloads.length)).toString(),
|
|
48
|
-
deposit: currentContractFee?.toString() || '1',
|
|
49
|
-
},
|
|
50
|
-
})),
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
export const responseToMpcSignature = ({ response, }) => {
|
|
54
|
-
const signature = response.receipts_outcome.reduce((acc, curr) => {
|
|
55
|
-
if (acc) {
|
|
56
|
-
return acc;
|
|
57
|
-
}
|
|
58
|
-
const { status } = curr.outcome;
|
|
59
|
-
return ((typeof status === 'object' &&
|
|
60
|
-
status.SuccessValue &&
|
|
61
|
-
status.SuccessValue !== '' &&
|
|
62
|
-
Buffer.from(status.SuccessValue, 'base64').toString('utf-8')) ||
|
|
63
|
-
'');
|
|
64
|
-
}, '');
|
|
65
|
-
if (signature) {
|
|
66
|
-
const parsedJSONSignature = JSON.parse(signature);
|
|
67
|
-
return utils.toRSV(parsedJSONSignature.Ok);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type BTCTransactionRequest, type BTCNetworkIds, type CosmosNetworkIds, type CosmosTransactionRequest, type EVMTransactionRequest, type KeyDerivationPath } from '@chains';
|
|
2
|
-
/**
|
|
3
|
-
Available ChainSignature contracts:
|
|
4
|
-
- Mainnet: v1.signer
|
|
5
|
-
- Testnet: v1.signer-prod.testnet
|
|
6
|
-
- Development (unstable): v1.signer-dev.testnet
|
|
7
|
-
*/
|
|
8
|
-
export type ChainSignatureContractIds = string;
|
|
9
|
-
export type NFTKeysContracts = string;
|
|
10
|
-
export type NearNetworkIds = 'mainnet' | 'testnet';
|
|
11
|
-
export interface ChainProvider {
|
|
12
|
-
providerUrl: string;
|
|
13
|
-
contract: ChainSignatureContractIds;
|
|
14
|
-
}
|
|
15
|
-
export interface NearAuthentication {
|
|
16
|
-
networkId: NearNetworkIds;
|
|
17
|
-
accountId: string;
|
|
18
|
-
}
|
|
19
|
-
export type EVMChainConfigWithProviders = ChainProvider;
|
|
20
|
-
export interface EVMRequest {
|
|
21
|
-
transaction: EVMTransactionRequest;
|
|
22
|
-
chainConfig: EVMChainConfigWithProviders;
|
|
23
|
-
nearAuthentication: NearAuthentication;
|
|
24
|
-
fastAuthRelayerUrl?: string;
|
|
25
|
-
derivationPath: KeyDerivationPath;
|
|
26
|
-
}
|
|
27
|
-
export type BTCChainConfigWithProviders = ChainProvider & {
|
|
28
|
-
network: BTCNetworkIds;
|
|
29
|
-
};
|
|
30
|
-
export interface BitcoinRequest {
|
|
31
|
-
transaction: BTCTransactionRequest;
|
|
32
|
-
chainConfig: BTCChainConfigWithProviders;
|
|
33
|
-
nearAuthentication: NearAuthentication;
|
|
34
|
-
fastAuthRelayerUrl?: string;
|
|
35
|
-
derivationPath: KeyDerivationPath;
|
|
36
|
-
}
|
|
37
|
-
export interface CosmosChainConfig {
|
|
38
|
-
contract: ChainSignatureContractIds;
|
|
39
|
-
chainId: CosmosNetworkIds;
|
|
40
|
-
}
|
|
41
|
-
export interface CosmosRequest {
|
|
42
|
-
chainConfig: CosmosChainConfig;
|
|
43
|
-
transaction: CosmosTransactionRequest;
|
|
44
|
-
nearAuthentication: NearAuthentication;
|
|
45
|
-
derivationPath: KeyDerivationPath;
|
|
46
|
-
fastAuthRelayerUrl?: string;
|
|
47
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as chains from './chains';
|
package/src/utils/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as chains from './chains';
|
package/vocs.config.d.ts
DELETED
package/vocs.config.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vocs';
|
|
2
|
-
export default defineConfig({
|
|
3
|
-
title: 'Signet.js',
|
|
4
|
-
description: 'A TypeScript library for handling multi-chain transactions and signatures using MPC',
|
|
5
|
-
twoslash: {
|
|
6
|
-
compilerOptions: {
|
|
7
|
-
strict: true,
|
|
8
|
-
paths: {
|
|
9
|
-
'signet.js': ['./src'],
|
|
10
|
-
'@chains': ['./src/chains'],
|
|
11
|
-
'@utils': ['./src/utils'],
|
|
12
|
-
'@chains/*': ['./src/chains/*'],
|
|
13
|
-
'@utils/*': ['./src/utils/*'],
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
sidebar: [
|
|
18
|
-
{
|
|
19
|
-
text: 'Getting Started',
|
|
20
|
-
items: [
|
|
21
|
-
{ text: 'Overview', link: '/' },
|
|
22
|
-
{ text: 'Sig Network', link: '/sig-net' },
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
text: 'Supported Chains',
|
|
27
|
-
items: [
|
|
28
|
-
{ text: 'EVM Chains', link: '/chains/evm' },
|
|
29
|
-
{ text: 'Bitcoin', link: '/chains/bitcoin' },
|
|
30
|
-
{ text: 'Cosmos', link: '/chains/cosmos' },
|
|
31
|
-
],
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
text: 'Core Concepts',
|
|
35
|
-
items: [
|
|
36
|
-
{ text: 'Chain Interface', link: '/guides/implementing-new-chain' },
|
|
37
|
-
{ text: 'MPC Overview', link: '/guides/mpc-overview' },
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
text: 'Implementation Guides',
|
|
42
|
-
collapsed: true,
|
|
43
|
-
items: [
|
|
44
|
-
{
|
|
45
|
-
text: 'Creating a New Chain',
|
|
46
|
-
link: '/guides/implementing-new-chain',
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
text: 'Bitcoin RPC Adapter',
|
|
50
|
-
link: '/guides/implementing-btc-adapter',
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
text: 'Chain Signature Contract',
|
|
54
|
-
link: '/guides/implementing-signature-contract',
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
socials: [
|
|
60
|
-
{
|
|
61
|
-
icon: 'github',
|
|
62
|
-
link: 'https://github.com/near/signet.js',
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
theme: {
|
|
66
|
-
accentColor: {
|
|
67
|
-
light: '#00C08B',
|
|
68
|
-
dark: '#00E6A6',
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
});
|