signet.js 0.0.3 → 0.0.4
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 +3 -0
- package/browser/index.browser.cjs.map +1 -0
- package/browser/index.browser.js +3 -0
- package/browser/index.browser.js.map +1 -0
- package/node/index.node.cjs +3 -0
- package/node/index.node.cjs.map +1 -0
- package/node/index.node.js +3 -0
- package/node/index.node.js.map +1 -0
- package/package.json +2 -2
- package/types/index.d.cts +919 -0
- package/types/index.d.ts +919 -0
- package/.eslintrc.json +0 -55
- package/.prettierrc +0 -1
- package/babel.config.js +0 -6
- package/docs/pages/index.mdx +0 -36
- package/docs/pages/signetjs/advanced/chain-signatures-contract.mdx +0 -52
- package/docs/pages/signetjs/advanced/chain.mdx +0 -45
- package/docs/pages/signetjs/chains/bitcoin/bitcoin.mdx +0 -171
- package/docs/pages/signetjs/chains/bitcoin/btc-rpc-adapter.mdx +0 -26
- package/docs/pages/signetjs/chains/cosmos.mdx +0 -171
- package/docs/pages/signetjs/chains/evm.mdx +0 -319
- package/docs/pages/signetjs/contract-addresses.mdx +0 -27
- package/docs/pages/signetjs/index.mdx +0 -88
- package/docs/snippets/code/contract.ts +0 -21
- package/docs/snippets/code/evm/env.ts +0 -16
- package/docs/snippets/code/near/env.ts +0 -13
- package/hardhat.config.mts +0 -19
- 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 -287
- package/src/chains/Bitcoin/types.ts +0 -48
- package/src/chains/Bitcoin/utils.ts +0 -14
- package/src/chains/Chain.ts +0 -92
- package/src/chains/ChainSignatureContract.ts +0 -65
- package/src/chains/Cosmos/Cosmos.ts +0 -258
- package/src/chains/Cosmos/types.ts +0 -35
- package/src/chains/Cosmos/utils.ts +0 -45
- package/src/chains/EVM/EVM.test.ts +0 -238
- package/src/chains/EVM/EVM.ts +0 -334
- package/src/chains/EVM/types.ts +0 -53
- package/src/chains/EVM/utils.ts +0 -27
- package/src/chains/index.ts +0 -38
- package/src/chains/types.ts +0 -46
- package/src/index.ts +0 -2
- package/src/utils/chains/evm/ChainSignaturesContract.ts +0 -286
- package/src/utils/chains/evm/ChainSignaturesContractABI.ts +0 -359
- package/src/utils/chains/evm/errors.ts +0 -52
- package/src/utils/chains/evm/index.ts +0 -3
- package/src/utils/chains/evm/types.ts +0 -28
- package/src/utils/chains/evm/utils.ts +0 -11
- package/src/utils/chains/index.ts +0 -2
- package/src/utils/chains/near/ChainSignatureContract.ts +0 -155
- 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/signAndSend/index.ts +0 -1
- package/src/utils/chains/near/signAndSend/keypair.ts +0 -178
- package/src/utils/chains/near/transactionBuilder.ts +0 -73
- package/src/utils/chains/near/types.ts +0 -77
- package/src/utils/constants.ts +0 -62
- package/src/utils/cryptography.ts +0 -131
- package/src/utils/index.ts +0 -3
- package/src/utils/publicKey.ts +0 -23
- package/tsconfig.eslint.json +0 -8
- package/tsconfig.json +0 -122
- package/tsup.config.ts +0 -55
- package/vitest.config.ts +0 -16
- package/vocs.config.ts +0 -73
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Hex } from 'viem'
|
|
2
|
-
|
|
3
|
-
export interface SignOptions {
|
|
4
|
-
sign: {
|
|
5
|
-
algo?: string
|
|
6
|
-
dest?: string
|
|
7
|
-
params?: string
|
|
8
|
-
}
|
|
9
|
-
retry: {
|
|
10
|
-
delay?: number
|
|
11
|
-
retryCount?: number
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface SignatureErrorData {
|
|
16
|
-
requestId: string
|
|
17
|
-
responder: string
|
|
18
|
-
error: string
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface SignRequest {
|
|
22
|
-
payload: Hex
|
|
23
|
-
path: string
|
|
24
|
-
keyVersion: number
|
|
25
|
-
algo: string
|
|
26
|
-
dest: string
|
|
27
|
-
params: string
|
|
28
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as chains from 'viem/chains'
|
|
2
|
-
import type { Chain } from 'viem/chains'
|
|
3
|
-
|
|
4
|
-
export const getChain = (chainId: number): Chain => {
|
|
5
|
-
for (const chain of Object.values(chains)) {
|
|
6
|
-
if (chain.id === chainId) {
|
|
7
|
-
return chain
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
throw new Error('Chain not found')
|
|
11
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { Contract } from '@near-js/accounts'
|
|
2
|
-
import { KeyPair } from '@near-js/crypto'
|
|
3
|
-
import BN from 'bn.js'
|
|
4
|
-
|
|
5
|
-
import { ChainSignatureContract as AbstractChainSignatureContract } from '@chains/ChainSignatureContract'
|
|
6
|
-
import type { SignArgs } from '@chains/ChainSignatureContract'
|
|
7
|
-
import type {
|
|
8
|
-
RSVSignature,
|
|
9
|
-
MPCSignature,
|
|
10
|
-
UncompressedPubKeySEC1,
|
|
11
|
-
NajPublicKey,
|
|
12
|
-
} from '@chains/types'
|
|
13
|
-
import { cryptography } from '@utils'
|
|
14
|
-
import { getNearAccount } from '@utils/chains/near/account'
|
|
15
|
-
import {
|
|
16
|
-
DONT_CARE_ACCOUNT_ID,
|
|
17
|
-
NEAR_MAX_GAS,
|
|
18
|
-
} from '@utils/chains/near/constants'
|
|
19
|
-
import {
|
|
20
|
-
type NearNetworkIds,
|
|
21
|
-
type ChainSignatureContractIds,
|
|
22
|
-
} from '@utils/chains/near/types'
|
|
23
|
-
import { najToUncompressedPubKeySEC1 } from '@utils/cryptography'
|
|
24
|
-
|
|
25
|
-
const requireAccount = (accountId: string): void => {
|
|
26
|
-
if (accountId === DONT_CARE_ACCOUNT_ID) {
|
|
27
|
-
throw new Error(
|
|
28
|
-
'A valid account ID and keypair are required for change methods. Please instantiate a new contract with valid credentials.'
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type NearContract = Contract & {
|
|
34
|
-
public_key: () => Promise<NajPublicKey>
|
|
35
|
-
sign: (args: {
|
|
36
|
-
args: { request: SignArgs }
|
|
37
|
-
gas: BN
|
|
38
|
-
amount: BN
|
|
39
|
-
}) => Promise<MPCSignature>
|
|
40
|
-
experimental_signature_deposit: () => Promise<number>
|
|
41
|
-
derived_public_key: (args: {
|
|
42
|
-
path: string
|
|
43
|
-
predecessor: string
|
|
44
|
-
}) => Promise<NajPublicKey>
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface ChainSignatureContractArgs {
|
|
48
|
-
networkId: NearNetworkIds
|
|
49
|
-
contractId: ChainSignatureContractIds
|
|
50
|
-
accountId?: string
|
|
51
|
-
keypair?: KeyPair
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Implementation of the ChainSignatureContract for NEAR chains.
|
|
56
|
-
*
|
|
57
|
-
* This class provides an interface to interact with the ChainSignatures contract
|
|
58
|
-
* deployed on NEAR. It supports both view methods (which don't require authentication)
|
|
59
|
-
* and change methods (which require a valid NEAR account and keypair).
|
|
60
|
-
*
|
|
61
|
-
* @extends AbstractChainSignatureContract
|
|
62
|
-
*/
|
|
63
|
-
export class ChainSignatureContract extends AbstractChainSignatureContract {
|
|
64
|
-
private readonly networkId: NearNetworkIds
|
|
65
|
-
private readonly contractId: ChainSignatureContractIds
|
|
66
|
-
private readonly accountId: string
|
|
67
|
-
private readonly keypair: KeyPair
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Creates a new instance of the ChainSignatureContract for NEAR chains.
|
|
71
|
-
*
|
|
72
|
-
* @param args - Configuration options for the contract
|
|
73
|
-
* @param args.networkId - The NEAR network ID (e.g. 'testnet', 'mainnet')
|
|
74
|
-
* @param args.contractId - The contract ID of the deployed ChainSignatures contract
|
|
75
|
-
* @param args.accountId - Optional NEAR account ID for signing transactions. Required for change methods.
|
|
76
|
-
* @param args.keypair - Optional NEAR KeyPair for signing transactions. Required for change methods.
|
|
77
|
-
*/
|
|
78
|
-
constructor({
|
|
79
|
-
networkId,
|
|
80
|
-
contractId,
|
|
81
|
-
accountId = DONT_CARE_ACCOUNT_ID,
|
|
82
|
-
keypair = KeyPair.fromRandom('ed25519'),
|
|
83
|
-
}: ChainSignatureContractArgs) {
|
|
84
|
-
// TODO: Should use the hardcoded ROOT_PUBLIC_KEY as in the EVM ChainSignatureContract
|
|
85
|
-
super()
|
|
86
|
-
|
|
87
|
-
this.networkId = networkId
|
|
88
|
-
this.contractId = contractId
|
|
89
|
-
this.accountId = accountId
|
|
90
|
-
this.keypair = keypair
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private async getContract(): Promise<NearContract> {
|
|
94
|
-
const account = await getNearAccount({
|
|
95
|
-
networkId: this.networkId,
|
|
96
|
-
accountId: this.accountId,
|
|
97
|
-
keypair: this.keypair,
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
return new Contract(account, this.contractId, {
|
|
101
|
-
viewMethods: [
|
|
102
|
-
'public_key',
|
|
103
|
-
'experimental_signature_deposit',
|
|
104
|
-
'derived_public_key',
|
|
105
|
-
],
|
|
106
|
-
changeMethods: ['sign'],
|
|
107
|
-
useLocalViewExecution: false,
|
|
108
|
-
}) as unknown as NearContract
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async getCurrentSignatureDeposit(): Promise<BN> {
|
|
112
|
-
const contract = await this.getContract()
|
|
113
|
-
return new BN(
|
|
114
|
-
(await contract.experimental_signature_deposit()).toLocaleString(
|
|
115
|
-
'fullwide',
|
|
116
|
-
{
|
|
117
|
-
useGrouping: false,
|
|
118
|
-
}
|
|
119
|
-
)
|
|
120
|
-
)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async getDerivedPublicKey(args: {
|
|
124
|
-
path: string
|
|
125
|
-
predecessor: string
|
|
126
|
-
}): Promise<UncompressedPubKeySEC1> {
|
|
127
|
-
const contract = await this.getContract()
|
|
128
|
-
|
|
129
|
-
const najPubKey = await contract.derived_public_key(args)
|
|
130
|
-
return najToUncompressedPubKeySEC1(najPubKey)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async getPublicKey(): Promise<UncompressedPubKeySEC1> {
|
|
134
|
-
const contract = await this.getContract()
|
|
135
|
-
|
|
136
|
-
const najPubKey = await contract.public_key()
|
|
137
|
-
return najToUncompressedPubKeySEC1(najPubKey)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// TODO: Should call the contract without the Contract instance as it doesn't allow for proper timeout handling on the BE
|
|
141
|
-
async sign(args: SignArgs): Promise<RSVSignature> {
|
|
142
|
-
requireAccount(this.accountId)
|
|
143
|
-
|
|
144
|
-
const contract = await this.getContract()
|
|
145
|
-
const deposit = await this.getCurrentSignatureDeposit()
|
|
146
|
-
|
|
147
|
-
const signature = await contract.sign({
|
|
148
|
-
args: { request: args },
|
|
149
|
-
gas: NEAR_MAX_GAS,
|
|
150
|
-
amount: deposit,
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
return cryptography.toRSV(signature)
|
|
154
|
-
}
|
|
155
|
-
}
|
|
@@ -1,42 +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
|
-
|
|
5
|
-
import { DONT_CARE_ACCOUNT_ID } from '@utils/chains/near/constants'
|
|
6
|
-
|
|
7
|
-
type SetConnectionArgs =
|
|
8
|
-
| {
|
|
9
|
-
networkId: string
|
|
10
|
-
accountId: string
|
|
11
|
-
keypair: KeyPair
|
|
12
|
-
}
|
|
13
|
-
| {
|
|
14
|
-
networkId: string
|
|
15
|
-
accountId?: never
|
|
16
|
-
keypair?: never
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const getNearAccount = async ({
|
|
20
|
-
networkId,
|
|
21
|
-
accountId = DONT_CARE_ACCOUNT_ID,
|
|
22
|
-
keypair = KeyPair.fromRandom('ed25519'),
|
|
23
|
-
}: SetConnectionArgs): Promise<Account> => {
|
|
24
|
-
const keyStore = new InMemoryKeyStore()
|
|
25
|
-
await keyStore.setKey(networkId, accountId, keypair)
|
|
26
|
-
|
|
27
|
-
const connection = Connection.fromConfig({
|
|
28
|
-
networkId,
|
|
29
|
-
provider: {
|
|
30
|
-
type: 'JsonRpcProvider',
|
|
31
|
-
args: {
|
|
32
|
-
url: {
|
|
33
|
-
testnet: 'https://rpc.testnet.near.org',
|
|
34
|
-
mainnet: 'https://rpc.mainnet.near.org',
|
|
35
|
-
}[networkId],
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
signer: { type: 'InMemorySigner', keyStore },
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
return new Account(connection, accountId)
|
|
42
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as keypair from './keypair'
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { type KeyPair } from '@near-js/crypto'
|
|
2
|
-
|
|
3
|
-
import { Bitcoin, Cosmos, EVM } from '@chains'
|
|
4
|
-
import { BTCRpcAdapters } from '@chains/Bitcoin/BTCRpcAdapter'
|
|
5
|
-
import { getNearAccount } from '@utils/chains/near/account'
|
|
6
|
-
import { ChainSignatureContract } from '@utils/chains/near/ChainSignatureContract'
|
|
7
|
-
import {
|
|
8
|
-
type Response,
|
|
9
|
-
type BitcoinRequest,
|
|
10
|
-
type CosmosRequest,
|
|
11
|
-
type EVMRequest,
|
|
12
|
-
} from '@utils/chains/near/types'
|
|
13
|
-
|
|
14
|
-
export const EVMTransaction = async (
|
|
15
|
-
req: EVMRequest,
|
|
16
|
-
keyPair: KeyPair
|
|
17
|
-
): Promise<Response> => {
|
|
18
|
-
try {
|
|
19
|
-
const account = await getNearAccount({
|
|
20
|
-
networkId: req.nearAuthentication.networkId,
|
|
21
|
-
accountId: req.nearAuthentication.accountId,
|
|
22
|
-
keypair: keyPair,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
const contract = new ChainSignatureContract({
|
|
26
|
-
networkId: req.nearAuthentication.networkId,
|
|
27
|
-
contractId: req.chainConfig.contract,
|
|
28
|
-
accountId: account.accountId,
|
|
29
|
-
keypair: keyPair,
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const evm = new EVM({
|
|
33
|
-
rpcUrl: req.chainConfig.providerUrl,
|
|
34
|
-
contract,
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
const { transaction, hashesToSign } =
|
|
38
|
-
await evm.prepareTransactionForSigning(req.transaction)
|
|
39
|
-
|
|
40
|
-
const signature = await contract.sign({
|
|
41
|
-
payload: hashesToSign[0],
|
|
42
|
-
path: req.derivationPath,
|
|
43
|
-
key_version: 0,
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const txSerialized = evm.attachTransactionSignature({
|
|
47
|
-
transaction,
|
|
48
|
-
rsvSignatures: [signature],
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
const txHash = await evm.broadcastTx(txSerialized)
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
transactionHash: txHash,
|
|
55
|
-
success: true,
|
|
56
|
-
}
|
|
57
|
-
} catch (e: unknown) {
|
|
58
|
-
console.error(e)
|
|
59
|
-
return {
|
|
60
|
-
success: false,
|
|
61
|
-
errorMessage: e instanceof Error ? e.message : String(e),
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const BTCTransaction = async (
|
|
67
|
-
req: BitcoinRequest,
|
|
68
|
-
keyPair: KeyPair
|
|
69
|
-
): Promise<Response> => {
|
|
70
|
-
try {
|
|
71
|
-
const account = await getNearAccount({
|
|
72
|
-
networkId: req.nearAuthentication.networkId,
|
|
73
|
-
accountId: req.nearAuthentication.accountId,
|
|
74
|
-
keypair: keyPair,
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
const contract = new ChainSignatureContract({
|
|
78
|
-
networkId: req.nearAuthentication.networkId,
|
|
79
|
-
contractId: req.chainConfig.contract,
|
|
80
|
-
accountId: account.accountId,
|
|
81
|
-
keypair: keyPair,
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
const btc = new Bitcoin({
|
|
85
|
-
btcRpcAdapter: new BTCRpcAdapters.Mempool(req.chainConfig.providerUrl),
|
|
86
|
-
contract,
|
|
87
|
-
network: req.chainConfig.network,
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
const { transaction, hashesToSign } =
|
|
91
|
-
await btc.prepareTransactionForSigning(req.transaction)
|
|
92
|
-
|
|
93
|
-
const signatures = await Promise.all(
|
|
94
|
-
hashesToSign.map(
|
|
95
|
-
async (payload) =>
|
|
96
|
-
await contract.sign({
|
|
97
|
-
payload,
|
|
98
|
-
path: req.derivationPath,
|
|
99
|
-
key_version: 0,
|
|
100
|
-
})
|
|
101
|
-
)
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
const txSerialized = btc.attachTransactionSignature({
|
|
105
|
-
transaction,
|
|
106
|
-
rsvSignatures: signatures,
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
const txHash = await btc.broadcastTx(txSerialized)
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
transactionHash: txHash,
|
|
113
|
-
success: true,
|
|
114
|
-
}
|
|
115
|
-
} catch (e: unknown) {
|
|
116
|
-
return {
|
|
117
|
-
success: false,
|
|
118
|
-
errorMessage: e instanceof Error ? e.message : String(e),
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export const CosmosTransaction = async (
|
|
124
|
-
req: CosmosRequest,
|
|
125
|
-
keyPair: KeyPair
|
|
126
|
-
): Promise<Response> => {
|
|
127
|
-
try {
|
|
128
|
-
const account = await getNearAccount({
|
|
129
|
-
networkId: req.nearAuthentication.networkId,
|
|
130
|
-
accountId: req.nearAuthentication.accountId,
|
|
131
|
-
keypair: keyPair,
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
const contract = new ChainSignatureContract({
|
|
135
|
-
networkId: req.nearAuthentication.networkId,
|
|
136
|
-
contractId: req.chainConfig.contract,
|
|
137
|
-
accountId: account.accountId,
|
|
138
|
-
keypair: keyPair,
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
const cosmos = new Cosmos({
|
|
142
|
-
contract,
|
|
143
|
-
chainId: req.chainConfig.chainId,
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
const { transaction, hashesToSign } =
|
|
147
|
-
await cosmos.prepareTransactionForSigning(req.transaction)
|
|
148
|
-
|
|
149
|
-
const signatures = await Promise.all(
|
|
150
|
-
hashesToSign.map(
|
|
151
|
-
async (payload) =>
|
|
152
|
-
await contract.sign({
|
|
153
|
-
payload,
|
|
154
|
-
path: req.derivationPath,
|
|
155
|
-
key_version: 0,
|
|
156
|
-
})
|
|
157
|
-
)
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
const txSerialized = cosmos.attachTransactionSignature({
|
|
161
|
-
transaction,
|
|
162
|
-
rsvSignatures: signatures,
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
const txHash = await cosmos.broadcastTx(txSerialized)
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
transactionHash: txHash,
|
|
169
|
-
success: true,
|
|
170
|
-
}
|
|
171
|
-
} catch (e: unknown) {
|
|
172
|
-
console.error(e)
|
|
173
|
-
return {
|
|
174
|
-
success: false,
|
|
175
|
-
errorMessage: e instanceof Error ? e.message : String(e),
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Action,
|
|
3
|
-
FinalExecutionOutcome,
|
|
4
|
-
NetworkId,
|
|
5
|
-
} from '@near-wallet-selector/core'
|
|
6
|
-
import BN from 'bn.js'
|
|
7
|
-
import { getTransactionLastResult } from 'near-api-js/lib/providers'
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
type RSVSignature,
|
|
11
|
-
type KeyDerivationPath,
|
|
12
|
-
type MPCSignature,
|
|
13
|
-
type HashToSign,
|
|
14
|
-
} from '@chains/types'
|
|
15
|
-
import { cryptography } from '@utils'
|
|
16
|
-
import { ChainSignatureContract } from '@utils/chains/near/ChainSignatureContract'
|
|
17
|
-
import { NEAR_MAX_GAS } from '@utils/chains/near/constants'
|
|
18
|
-
import { type ChainSignatureContractIds } from '@utils/chains/near/types'
|
|
19
|
-
|
|
20
|
-
export const mpcPayloadsToChainSigTransaction = async ({
|
|
21
|
-
networkId,
|
|
22
|
-
contractId,
|
|
23
|
-
hashesToSign,
|
|
24
|
-
path,
|
|
25
|
-
}: {
|
|
26
|
-
networkId: NetworkId
|
|
27
|
-
contractId: ChainSignatureContractIds
|
|
28
|
-
hashesToSign: HashToSign[]
|
|
29
|
-
path: KeyDerivationPath
|
|
30
|
-
}): Promise<{
|
|
31
|
-
receiverId: string
|
|
32
|
-
actions: Action[]
|
|
33
|
-
}> => {
|
|
34
|
-
const contract = new ChainSignatureContract({
|
|
35
|
-
networkId,
|
|
36
|
-
contractId,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const currentContractFee = await contract.getCurrentSignatureDeposit()
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
receiverId: contractId,
|
|
43
|
-
actions: hashesToSign.map((payload) => ({
|
|
44
|
-
type: 'FunctionCall',
|
|
45
|
-
params: {
|
|
46
|
-
methodName: 'sign',
|
|
47
|
-
args: {
|
|
48
|
-
request: {
|
|
49
|
-
payload: Array.from(payload),
|
|
50
|
-
path,
|
|
51
|
-
key_version: 0,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
gas: NEAR_MAX_GAS.div(new BN(hashesToSign.length)).toString(),
|
|
55
|
-
deposit: currentContractFee?.toString() || '1',
|
|
56
|
-
},
|
|
57
|
-
})),
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const responseToMpcSignature = ({
|
|
62
|
-
response,
|
|
63
|
-
}: {
|
|
64
|
-
response: FinalExecutionOutcome
|
|
65
|
-
}): RSVSignature | undefined => {
|
|
66
|
-
const signature: MPCSignature = getTransactionLastResult(response)
|
|
67
|
-
|
|
68
|
-
if (signature) {
|
|
69
|
-
return cryptography.toRSV(signature)
|
|
70
|
-
} else {
|
|
71
|
-
return undefined
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BTCTransactionRequest,
|
|
3
|
-
BTCNetworkIds,
|
|
4
|
-
} from '@chains/Bitcoin/types'
|
|
5
|
-
import type {
|
|
6
|
-
CosmosNetworkIds,
|
|
7
|
-
CosmosTransactionRequest,
|
|
8
|
-
} from '@chains/Cosmos/types'
|
|
9
|
-
import { type EVMTransactionRequest } from '@chains/EVM/types'
|
|
10
|
-
import type { KeyDerivationPath } from '@chains/types'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
Available ChainSignature contracts:
|
|
14
|
-
- Mainnet: v1.signer
|
|
15
|
-
- Testnet: v1.signer-prod.testnet
|
|
16
|
-
- Development (unstable): v1.signer-dev.testnet
|
|
17
|
-
*/
|
|
18
|
-
export type ChainSignatureContractIds = string
|
|
19
|
-
|
|
20
|
-
export type NearNetworkIds = 'mainnet' | 'testnet'
|
|
21
|
-
|
|
22
|
-
export interface ChainProvider {
|
|
23
|
-
providerUrl: string
|
|
24
|
-
contract: ChainSignatureContractIds
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface NearAuthentication {
|
|
28
|
-
networkId: NearNetworkIds
|
|
29
|
-
accountId: string
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface SuccessResponse {
|
|
33
|
-
transactionHash: string
|
|
34
|
-
success: true
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
interface FailureResponse {
|
|
38
|
-
success: false
|
|
39
|
-
errorMessage: string
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export type Response = SuccessResponse | FailureResponse
|
|
43
|
-
|
|
44
|
-
export type EVMChainConfigWithProviders = ChainProvider
|
|
45
|
-
|
|
46
|
-
export interface EVMRequest {
|
|
47
|
-
transaction: EVMTransactionRequest
|
|
48
|
-
chainConfig: EVMChainConfigWithProviders
|
|
49
|
-
nearAuthentication: NearAuthentication
|
|
50
|
-
fastAuthRelayerUrl?: string
|
|
51
|
-
derivationPath: KeyDerivationPath
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type BTCChainConfigWithProviders = ChainProvider & {
|
|
55
|
-
network: BTCNetworkIds
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface BitcoinRequest {
|
|
59
|
-
transaction: BTCTransactionRequest
|
|
60
|
-
chainConfig: BTCChainConfigWithProviders
|
|
61
|
-
nearAuthentication: NearAuthentication
|
|
62
|
-
fastAuthRelayerUrl?: string
|
|
63
|
-
derivationPath: KeyDerivationPath
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface CosmosChainConfig {
|
|
67
|
-
contract: ChainSignatureContractIds
|
|
68
|
-
chainId: CosmosNetworkIds
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface CosmosRequest {
|
|
72
|
-
chainConfig: CosmosChainConfig
|
|
73
|
-
transaction: CosmosTransactionRequest
|
|
74
|
-
nearAuthentication: NearAuthentication
|
|
75
|
-
derivationPath: KeyDerivationPath
|
|
76
|
-
fastAuthRelayerUrl?: string
|
|
77
|
-
}
|
package/src/utils/constants.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { type NajPublicKey } from '@chains'
|
|
2
|
-
|
|
3
|
-
export const ENVS = {
|
|
4
|
-
TESTNET_DEV: 'TESTNET_DEV',
|
|
5
|
-
TESTNET: 'TESTNET',
|
|
6
|
-
MAINNET: 'MAINNET',
|
|
7
|
-
} as const
|
|
8
|
-
|
|
9
|
-
export const CHAINS = {
|
|
10
|
-
ETHEREUM: 'ETHEREUM',
|
|
11
|
-
NEAR: 'NEAR',
|
|
12
|
-
} as const
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Root public keys for the Sig Network Smart Contracts across different environments.
|
|
16
|
-
*
|
|
17
|
-
* These keys should never change.
|
|
18
|
-
*/
|
|
19
|
-
export const ROOT_PUBLIC_KEYS: Record<keyof typeof ENVS, NajPublicKey> = {
|
|
20
|
-
[ENVS.TESTNET_DEV]:
|
|
21
|
-
'secp256k1:54hU5wcCmVUPFWLDALXMh1fFToZsVXrx9BbTbHzSfQq1Kd1rJZi52iPa4QQxo6s5TgjWqgpY8HamYuUDzG6fAaUq',
|
|
22
|
-
[ENVS.TESTNET]:
|
|
23
|
-
'secp256k1:3Ww8iFjqTHufye5aRGUvrQqETegR4gVUcW8FX5xzscaN9ENhpkffojsxJwi6N1RbbHMTxYa9UyKeqK3fsMuwxjR5',
|
|
24
|
-
[ENVS.MAINNET]:
|
|
25
|
-
'secp256k1:4tY4qMzusmgX5wYdG35663Y3Qar3CTbpApotwk9ZKLoF79XA4DjG8XoByaKdNHKQX9Lz5hd7iJqsWdTKyA7dKa6Z',
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Chain IDs used in the key derivation function (KDF) for deriving child public keys to
|
|
30
|
-
* distinguish between different chains.
|
|
31
|
-
*
|
|
32
|
-
* @see {@link deriveChildPublicKey} in cryptography.ts for usage details
|
|
33
|
-
*/
|
|
34
|
-
export const KDF_CHAIN_IDS = {
|
|
35
|
-
[CHAINS.ETHEREUM]: '0x1',
|
|
36
|
-
[CHAINS.NEAR]: '0x18d',
|
|
37
|
-
} as const
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Contract addresses for different chains and environments.
|
|
41
|
-
*
|
|
42
|
-
* - Testnet Dev: Used for internal development, very unstable
|
|
43
|
-
* - Testnet: Used for external development, stable
|
|
44
|
-
* - Mainnet: Production contract address
|
|
45
|
-
*
|
|
46
|
-
* @see ChainSignatureContract documentation for implementation details
|
|
47
|
-
*/
|
|
48
|
-
export const CONTRACT_ADDRESSES: Record<
|
|
49
|
-
keyof typeof CHAINS,
|
|
50
|
-
Record<keyof typeof ENVS, string>
|
|
51
|
-
> = {
|
|
52
|
-
[CHAINS.NEAR]: {
|
|
53
|
-
[ENVS.TESTNET_DEV]: 'dev.sig-net.testnet',
|
|
54
|
-
[ENVS.TESTNET]: 'v1.sig-net.testnet',
|
|
55
|
-
[ENVS.MAINNET]: 'v1.sig-net.near',
|
|
56
|
-
},
|
|
57
|
-
[CHAINS.ETHEREUM]: {
|
|
58
|
-
[ENVS.TESTNET_DEV]: '0x69C6b28Fdc74618817fa380De29a653060e14009',
|
|
59
|
-
[ENVS.TESTNET]: '0x83458E8Bf8206131Fe5c05127007FA164c0948A2',
|
|
60
|
-
[ENVS.MAINNET]: '0xf8bdC0612361a1E49a8E01423d4C0cFc5dF4791A',
|
|
61
|
-
},
|
|
62
|
-
}
|