signet.js 0.0.7 → 0.0.9-retry
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/README.md +8 -1
- 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 +19 -18
- package/types/index.d.cts +1048 -0
- package/types/index.d.ts +1048 -0
- package/.eslintrc.json +0 -67
- package/.prettierrc +0 -1
- package/babel.config.js +0 -6
- package/docs/dist/.vocs/icons/arrow-diagonal.svg +0 -3
- package/docs/dist/.vocs/icons/chevron-down.svg +0 -13
- package/docs/dist/.vocs/icons/chevron-up.svg +0 -13
- package/docs/dist/.vocs/icons/link.svg +0 -3
- package/docs/dist/.vocs/search-index-7b499e25.json +0 -1
- package/docs/dist/assets/arbitrary-hash-Cd6eo8ZD.js +0 -309
- package/docs/dist/assets/broadcast-tx-CeTEE9yX.js +0 -8
- package/docs/dist/assets/btc-rpc-adapter-C-qSHpFV.js +0 -226
- package/docs/dist/assets/chain-adapter-interface-B9TpOgQv.js +0 -1280
- package/docs/dist/assets/chain-contract-interface-DEku3k45.js +0 -392
- package/docs/dist/assets/constructor-73n7bp3b.js +0 -161
- package/docs/dist/assets/constructor-Bg7nvLe0.js +0 -14
- package/docs/dist/assets/contract-addresses-BYlrAOs3.js +0 -200
- package/docs/dist/assets/derive-address-and-public-key-DExrKiGV.js +0 -14
- package/docs/dist/assets/finalize-message-signing-W435d71R.js +0 -20
- package/docs/dist/assets/finalize-transaction-signing-BIgJ2dnc.js +0 -36
- package/docs/dist/assets/finalize-transaction-signing-C--HJs8D.js +0 -24
- package/docs/dist/assets/finalize-transaction-signing-CjGmN7d9.js +0 -24
- package/docs/dist/assets/finalize-typed-data-signing-CEOp_GWt.js +0 -21
- package/docs/dist/assets/get-balance-DBC-i6KG.js +0 -13
- package/docs/dist/assets/get-current-signature-deposit-BXm9AzYy.js +0 -6
- package/docs/dist/assets/get-current-signature-deposit-nOw4j1MN.js +0 -6
- package/docs/dist/assets/get-derived-public-key-BXvfo2m2.js +0 -14
- package/docs/dist/assets/get-derived-public-key-DQ1pyiFS.js +0 -14
- package/docs/dist/assets/get-latest-key-version-DWlkMCre.js +0 -6
- package/docs/dist/assets/get-public-key-B4PFoVqu.js +0 -6
- package/docs/dist/assets/get-public-key-B9xkYkD_.js +0 -6
- package/docs/dist/assets/index-BFuwoY4w.js +0 -601
- package/docs/dist/assets/index-C62Mf-vy.js +0 -426
- package/docs/dist/assets/index-D8xhaiVb.js +0 -121
- package/docs/dist/assets/index-DTr0DlO0.js +0 -36
- package/docs/dist/assets/index-V9dXf-ik.js +0 -457
- package/docs/dist/assets/prepare-message-for-signing-DESTq-Hg.js +0 -16
- package/docs/dist/assets/prepare-transaction-for-signing-DIKTU0zj.js +0 -33
- package/docs/dist/assets/prepare-transaction-for-signing-DV_wkZ5g.js +0 -21
- package/docs/dist/assets/prepare-transaction-for-signing-LVDP0COu.js +0 -33
- package/docs/dist/assets/prepare-typed-data-for-signing-CWcmJvw0.js +0 -192
- package/docs/dist/assets/sign-CwtS5LnB.js +0 -13
- package/docs/dist/assets/sign-OQxf9yn7.js +0 -15
- package/docs/dist/assets/signet-quick-start-CQK52nVG.js +0 -350
- package/docs/dist/assets/sponsor-foreign-chain-gas-C9iWXM8Q.js +0 -1
- package/docs/dist/assets/style-CKGXuRqx.css +0 -1
- package/docs/dist/examples/arbitrary-hash/index.html +0 -88
- package/docs/dist/examples/sponsor-foreign-chain-gas/index.html +0 -21
- package/docs/dist/index.html +0 -56
- package/docs/dist/initializeTheme.iife.js +0 -1
- package/docs/dist/introduction/signet-quick-start/index.html +0 -109
- package/docs/dist/primitives/chain-adapter-interface/index.html +0 -515
- package/docs/dist/primitives/chain-contract-interface/index.html +0 -306
- package/docs/dist/primitives/contract-addresses/index.html +0 -97
- package/docs/dist/signet-logo.png +0 -0
- package/docs/dist/signetjs/chain-adapters/bitcoin/btc-rpc-adapter/index.html +0 -148
- package/docs/dist/signetjs/chain-adapters/bitcoin/finalize-transaction-signing/index.html +0 -41
- package/docs/dist/signetjs/chain-adapters/bitcoin/index.html +0 -187
- package/docs/dist/signetjs/chain-adapters/bitcoin/prepare-transaction-for-signing/index.html +0 -34
- package/docs/dist/signetjs/chain-adapters/broadcast-tx/index.html +0 -28
- package/docs/dist/signetjs/chain-adapters/cosmos/finalize-transaction-signing/index.html +0 -41
- package/docs/dist/signetjs/chain-adapters/cosmos/index.html +0 -166
- package/docs/dist/signetjs/chain-adapters/cosmos/prepare-transaction-for-signing/index.html +0 -43
- package/docs/dist/signetjs/chain-adapters/derive-address-and-public-key/index.html +0 -31
- package/docs/dist/signetjs/chain-adapters/evm/finalize-message-signing/index.html +0 -38
- package/docs/dist/signetjs/chain-adapters/evm/finalize-transaction-signing/index.html +0 -41
- package/docs/dist/signetjs/chain-adapters/evm/finalize-typed-data-signing/index.html +0 -39
- package/docs/dist/signetjs/chain-adapters/evm/index.html +0 -129
- package/docs/dist/signetjs/chain-adapters/evm/prepare-message-for-signing/index.html +0 -31
- package/docs/dist/signetjs/chain-adapters/evm/prepare-transaction-for-signing/index.html +0 -34
- package/docs/dist/signetjs/chain-adapters/evm/prepare-typed-data-for-signing/index.html +0 -49
- package/docs/dist/signetjs/chain-adapters/get-balance/index.html +0 -30
- package/docs/dist/signetjs/contracts/evm/constructor/index.html +0 -45
- package/docs/dist/signetjs/contracts/evm/get-current-signature-deposit/index.html +0 -26
- package/docs/dist/signetjs/contracts/evm/get-derived-public-key/index.html +0 -31
- package/docs/dist/signetjs/contracts/evm/get-latest-key-version/index.html +0 -26
- package/docs/dist/signetjs/contracts/evm/get-public-key/index.html +0 -26
- package/docs/dist/signetjs/contracts/evm/sign/index.html +0 -32
- package/docs/dist/signetjs/contracts/near/constructor/index.html +0 -34
- package/docs/dist/signetjs/contracts/near/get-current-signature-deposit/index.html +0 -26
- package/docs/dist/signetjs/contracts/near/get-derived-public-key/index.html +0 -31
- package/docs/dist/signetjs/contracts/near/get-public-key/index.html +0 -26
- package/docs/dist/signetjs/contracts/near/sign/index.html +0 -32
- package/docs/pages/examples/arbitrary-hash.mdx +0 -73
- package/docs/pages/examples/sponsor-foreign-chain-gas.mdx +0 -1
- package/docs/pages/index.mdx +0 -36
- package/docs/pages/introduction/signet-quick-start.mdx +0 -88
- package/docs/pages/primitives/chain-adapter-interface.mdx +0 -45
- package/docs/pages/primitives/chain-contract-interface.mdx +0 -52
- package/docs/pages/primitives/contract-addresses.mdx +0 -27
- package/docs/pages/signetjs/chain-adapters/bitcoin/btc-rpc-adapter.mdx +0 -26
- package/docs/pages/signetjs/chain-adapters/bitcoin/finalize-transaction-signing.mdx +0 -47
- package/docs/pages/signetjs/chain-adapters/bitcoin/index.mdx +0 -119
- package/docs/pages/signetjs/chain-adapters/bitcoin/prepare-transaction-for-signing.mdx +0 -30
- package/docs/pages/signetjs/chain-adapters/broadcast-tx.mdx +0 -23
- package/docs/pages/signetjs/chain-adapters/cosmos/finalize-transaction-signing.mdx +0 -53
- package/docs/pages/signetjs/chain-adapters/cosmos/index.mdx +0 -108
- package/docs/pages/signetjs/chain-adapters/cosmos/prepare-transaction-for-signing.mdx +0 -39
- package/docs/pages/signetjs/chain-adapters/derive-address-and-public-key.mdx +0 -28
- package/docs/pages/signetjs/chain-adapters/evm/finalize-message-signing.mdx +0 -33
- package/docs/pages/signetjs/chain-adapters/evm/finalize-transaction-signing.mdx +0 -44
- package/docs/pages/signetjs/chain-adapters/evm/finalize-typed-data-signing.mdx +0 -34
- package/docs/pages/signetjs/chain-adapters/evm/index.mdx +0 -84
- package/docs/pages/signetjs/chain-adapters/evm/prepare-message-for-signing.mdx +0 -26
- package/docs/pages/signetjs/chain-adapters/evm/prepare-transaction-for-signing.mdx +0 -30
- package/docs/pages/signetjs/chain-adapters/evm/prepare-typed-data-for-signing.mdx +0 -44
- package/docs/pages/signetjs/chain-adapters/get-balance.mdx +0 -26
- package/docs/pages/signetjs/contracts/evm/constructor.mdx +0 -38
- package/docs/pages/signetjs/contracts/evm/get-current-signature-deposit.mdx +0 -17
- package/docs/pages/signetjs/contracts/evm/get-derived-public-key.mdx +0 -28
- package/docs/pages/signetjs/contracts/evm/get-latest-key-version.mdx +0 -17
- package/docs/pages/signetjs/contracts/evm/get-public-key.mdx +0 -17
- package/docs/pages/signetjs/contracts/evm/sign.mdx +0 -36
- package/docs/pages/signetjs/contracts/near/constructor.mdx +0 -29
- package/docs/pages/signetjs/contracts/near/get-current-signature-deposit.mdx +0 -17
- package/docs/pages/signetjs/contracts/near/get-derived-public-key.mdx +0 -28
- package/docs/pages/signetjs/contracts/near/get-public-key.mdx +0 -17
- package/docs/pages/signetjs/contracts/near/sign.mdx +0 -32
- package/docs/public/signet-logo.png +0 -0
- package/docs/snippets/code/chains.ts +0 -42
- package/docs/snippets/code/contract.ts +0 -44
- package/docs/snippets/code/evm/contract.ts +0 -24
- 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/chain-adapters/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts +0 -15
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts +0 -101
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/index.ts +0 -1
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/Mempool/types.ts +0 -72
- package/src/chain-adapters/Bitcoin/BTCRpcAdapter/index.ts +0 -6
- package/src/chain-adapters/Bitcoin/Bitcoin.ts +0 -287
- package/src/chain-adapters/Bitcoin/index.ts +0 -13
- package/src/chain-adapters/Bitcoin/types.ts +0 -48
- package/src/chain-adapters/Bitcoin/utils.ts +0 -14
- package/src/chain-adapters/ChainAdapter.ts +0 -92
- package/src/chain-adapters/Cosmos/Cosmos.ts +0 -258
- package/src/chain-adapters/Cosmos/index.ts +0 -8
- package/src/chain-adapters/Cosmos/types.ts +0 -35
- package/src/chain-adapters/Cosmos/utils.ts +0 -45
- package/src/chain-adapters/EVM/EVM.test.ts +0 -238
- package/src/chain-adapters/EVM/EVM.ts +0 -337
- package/src/chain-adapters/EVM/index.ts +0 -11
- package/src/chain-adapters/EVM/types.ts +0 -53
- package/src/chain-adapters/EVM/utils.ts +0 -27
- package/src/chain-adapters/index.ts +0 -5
- package/src/constants.ts +0 -62
- package/src/contracts/ChainSignatureContract.ts +0 -65
- package/src/contracts/evm/ChainSignaturesContract.ts +0 -323
- package/src/contracts/evm/ChainSignaturesContractABI.ts +0 -359
- package/src/contracts/evm/errors.ts +0 -52
- package/src/contracts/evm/index.ts +0 -10
- package/src/contracts/evm/types.ts +0 -39
- package/src/contracts/evm/utils.ts +0 -41
- package/src/contracts/index.ts +0 -4
- package/src/contracts/near/ChainSignatureContract.ts +0 -196
- package/src/contracts/near/account.ts +0 -42
- package/src/contracts/near/constants.ts +0 -4
- package/src/contracts/near/index.ts +0 -10
- package/src/contracts/near/signAndSend/index.ts +0 -1
- package/src/contracts/near/signAndSend/keypair.ts +0 -178
- package/src/contracts/near/transaction.ts +0 -202
- package/src/contracts/near/types.ts +0 -71
- package/src/index.ts +0 -5
- package/src/types.ts +0 -46
- package/src/utils/cryptography.ts +0 -141
- package/src/utils/index.ts +0 -1
- package/src/utils/publicKey.ts +0 -17
- package/tsconfig.eslint.json +0 -8
- package/tsconfig.json +0 -126
- package/tsup.config.ts +0 -58
- package/vitest.config.ts +0 -19
- package/vocs.config.ts +0 -213
|
@@ -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 '@contracts/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 * as chainAdapters from '@chain-adapters'
|
|
4
|
-
import { BTCRpcAdapters } from '@chain-adapters/Bitcoin/BTCRpcAdapter'
|
|
5
|
-
import { getNearAccount } from '@contracts/near/account'
|
|
6
|
-
import { ChainSignatureContract } from '@contracts/near/ChainSignatureContract'
|
|
7
|
-
import {
|
|
8
|
-
type Response,
|
|
9
|
-
type BitcoinRequest,
|
|
10
|
-
type CosmosRequest,
|
|
11
|
-
type EVMRequest,
|
|
12
|
-
} from '@contracts/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 chainAdapters.evm.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.finalizeTransactionSigning({
|
|
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 chainAdapters.btc.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.finalizeTransactionSigning({
|
|
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 chainAdapters.cosmos.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.finalizeTransactionSigning({
|
|
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,202 +0,0 @@
|
|
|
1
|
-
import { InMemoryKeyStore } from '@near-js/keystores'
|
|
2
|
-
import type { Action as TransactionAction } from '@near-js/transactions'
|
|
3
|
-
import type { TxExecutionStatus } from '@near-js/types'
|
|
4
|
-
import type {
|
|
5
|
-
Action as WalletAction,
|
|
6
|
-
FinalExecutionOutcome,
|
|
7
|
-
NetworkId,
|
|
8
|
-
} from '@near-wallet-selector/core'
|
|
9
|
-
import BN from 'bn.js'
|
|
10
|
-
import {
|
|
11
|
-
transactions,
|
|
12
|
-
utils as nearUtils,
|
|
13
|
-
connect,
|
|
14
|
-
type KeyPair,
|
|
15
|
-
} from 'near-api-js'
|
|
16
|
-
import { getTransactionLastResult } from 'near-api-js/lib/providers'
|
|
17
|
-
import { withRetry } from 'viem'
|
|
18
|
-
|
|
19
|
-
import { ChainSignatureContract } from '@contracts/near/ChainSignatureContract'
|
|
20
|
-
import { NEAR_MAX_GAS } from '@contracts/near/constants'
|
|
21
|
-
import { type ChainSignatureContractIds } from '@contracts/near/types'
|
|
22
|
-
import {
|
|
23
|
-
type RSVSignature,
|
|
24
|
-
type KeyDerivationPath,
|
|
25
|
-
type MPCSignature,
|
|
26
|
-
type HashToSign,
|
|
27
|
-
} from '@types'
|
|
28
|
-
import { cryptography } from '@utils'
|
|
29
|
-
|
|
30
|
-
export const mpcPayloadsToChainSigTransaction = async ({
|
|
31
|
-
networkId,
|
|
32
|
-
contractId,
|
|
33
|
-
hashesToSign,
|
|
34
|
-
path,
|
|
35
|
-
}: {
|
|
36
|
-
networkId: NetworkId
|
|
37
|
-
contractId: ChainSignatureContractIds
|
|
38
|
-
hashesToSign: HashToSign[]
|
|
39
|
-
path: KeyDerivationPath
|
|
40
|
-
}): Promise<{
|
|
41
|
-
receiverId: string
|
|
42
|
-
actions: WalletAction[]
|
|
43
|
-
}> => {
|
|
44
|
-
const contract = new ChainSignatureContract({
|
|
45
|
-
networkId,
|
|
46
|
-
contractId,
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const currentContractFee = await contract.getCurrentSignatureDeposit()
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
receiverId: contractId,
|
|
53
|
-
actions: hashesToSign.map((payload) => ({
|
|
54
|
-
type: 'FunctionCall',
|
|
55
|
-
params: {
|
|
56
|
-
methodName: 'sign',
|
|
57
|
-
args: {
|
|
58
|
-
request: {
|
|
59
|
-
payload: Array.from(payload),
|
|
60
|
-
path,
|
|
61
|
-
key_version: 0,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
gas: NEAR_MAX_GAS.div(new BN(hashesToSign.length)).toString(),
|
|
65
|
-
deposit: currentContractFee?.toString() || '1',
|
|
66
|
-
},
|
|
67
|
-
})),
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export const responseToMpcSignature = ({
|
|
72
|
-
response,
|
|
73
|
-
}: {
|
|
74
|
-
response: FinalExecutionOutcome
|
|
75
|
-
}): RSVSignature | undefined => {
|
|
76
|
-
const signature = getTransactionLastResult(response) as MPCSignature
|
|
77
|
-
|
|
78
|
-
if (signature) {
|
|
79
|
-
return cryptography.toRSV(signature)
|
|
80
|
-
} else {
|
|
81
|
-
return undefined
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface SendTransactionOptions {
|
|
86
|
-
until: TxExecutionStatus
|
|
87
|
-
retryCount: number
|
|
88
|
-
delay: number
|
|
89
|
-
nodeUrl: string
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export const sendTransactionUntil = async ({
|
|
93
|
-
accountId,
|
|
94
|
-
keypair,
|
|
95
|
-
networkId,
|
|
96
|
-
receiverId,
|
|
97
|
-
actions,
|
|
98
|
-
nonce,
|
|
99
|
-
options = {
|
|
100
|
-
until: 'EXECUTED_OPTIMISTIC',
|
|
101
|
-
retryCount: 3,
|
|
102
|
-
delay: 5000, // Near RPC timeout
|
|
103
|
-
nodeUrl:
|
|
104
|
-
networkId === 'testnet'
|
|
105
|
-
? 'https://test.rpc.fastnear.com'
|
|
106
|
-
: 'https://free.rpc.fastnear.com',
|
|
107
|
-
},
|
|
108
|
-
}: {
|
|
109
|
-
accountId: string
|
|
110
|
-
keypair: KeyPair
|
|
111
|
-
networkId: NetworkId
|
|
112
|
-
receiverId: string
|
|
113
|
-
actions: TransactionAction[]
|
|
114
|
-
nonce?: number
|
|
115
|
-
options?: SendTransactionOptions
|
|
116
|
-
}): Promise<FinalExecutionOutcome> => {
|
|
117
|
-
const keyStore = new InMemoryKeyStore()
|
|
118
|
-
await keyStore.setKey(networkId, accountId, keypair)
|
|
119
|
-
|
|
120
|
-
const near = await connect({
|
|
121
|
-
networkId,
|
|
122
|
-
keyStore,
|
|
123
|
-
nodeUrl: options.nodeUrl,
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
const { signer } = near.connection
|
|
127
|
-
const publicKey = await signer.getPublicKey(
|
|
128
|
-
accountId,
|
|
129
|
-
near.connection.networkId
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
const accessKey = (await near.connection.provider.query(
|
|
133
|
-
`access_key/${accountId}/${publicKey.toString()}`,
|
|
134
|
-
''
|
|
135
|
-
)) as unknown as {
|
|
136
|
-
block_hash: string
|
|
137
|
-
block_height: number
|
|
138
|
-
nonce: number
|
|
139
|
-
permission: string
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const recentBlockHash = nearUtils.serialize.base_decode(accessKey.block_hash)
|
|
143
|
-
|
|
144
|
-
const tx = transactions.createTransaction(
|
|
145
|
-
accountId,
|
|
146
|
-
publicKey,
|
|
147
|
-
receiverId,
|
|
148
|
-
nonce ?? ++accessKey.nonce,
|
|
149
|
-
actions,
|
|
150
|
-
recentBlockHash
|
|
151
|
-
)
|
|
152
|
-
|
|
153
|
-
const serializedTx = nearUtils.serialize.serialize(
|
|
154
|
-
transactions.SCHEMA.Transaction,
|
|
155
|
-
tx
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
const nearTransactionSignature = await signer.signMessage(
|
|
159
|
-
serializedTx,
|
|
160
|
-
accountId,
|
|
161
|
-
near.connection.networkId
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
const signedTransaction = new transactions.SignedTransaction({
|
|
165
|
-
transaction: tx,
|
|
166
|
-
signature: new transactions.Signature({
|
|
167
|
-
keyType: tx.publicKey.keyType,
|
|
168
|
-
data: nearTransactionSignature.signature,
|
|
169
|
-
}),
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
const { transaction } = await near.connection.provider.sendTransactionUntil(
|
|
173
|
-
signedTransaction,
|
|
174
|
-
'INCLUDED_FINAL'
|
|
175
|
-
)
|
|
176
|
-
|
|
177
|
-
const txHash = transaction.hash as string | undefined
|
|
178
|
-
|
|
179
|
-
if (!txHash) {
|
|
180
|
-
throw new Error('No transaction hash found')
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return await withRetry(
|
|
184
|
-
async () => {
|
|
185
|
-
const txOutcome = await near.connection.provider.txStatus(
|
|
186
|
-
txHash,
|
|
187
|
-
accountId,
|
|
188
|
-
options.until
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
if (txOutcome) {
|
|
192
|
-
return txOutcome
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
throw new Error('Transaction not found')
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
retryCount: options.retryCount,
|
|
199
|
-
delay: options.delay,
|
|
200
|
-
}
|
|
201
|
-
)
|
|
202
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BTCTransactionRequest,
|
|
3
|
-
BTCNetworkIds,
|
|
4
|
-
} from '@chain-adapters/Bitcoin/types'
|
|
5
|
-
import type {
|
|
6
|
-
CosmosNetworkIds,
|
|
7
|
-
CosmosTransactionRequest,
|
|
8
|
-
} from '@chain-adapters/Cosmos/types'
|
|
9
|
-
import { type EVMTransactionRequest } from '@chain-adapters/EVM/types'
|
|
10
|
-
import type { KeyDerivationPath } from '@types'
|
|
11
|
-
|
|
12
|
-
export type ChainSignatureContractIds = string
|
|
13
|
-
|
|
14
|
-
export type NearNetworkIds = 'mainnet' | 'testnet'
|
|
15
|
-
|
|
16
|
-
export interface ChainProvider {
|
|
17
|
-
providerUrl: string
|
|
18
|
-
contract: ChainSignatureContractIds
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface NearAuthentication {
|
|
22
|
-
networkId: NearNetworkIds
|
|
23
|
-
accountId: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface SuccessResponse {
|
|
27
|
-
transactionHash: string
|
|
28
|
-
success: true
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface FailureResponse {
|
|
32
|
-
success: false
|
|
33
|
-
errorMessage: string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type Response = SuccessResponse | FailureResponse
|
|
37
|
-
|
|
38
|
-
export type EVMChainConfigWithProviders = ChainProvider
|
|
39
|
-
|
|
40
|
-
export interface EVMRequest {
|
|
41
|
-
transaction: EVMTransactionRequest
|
|
42
|
-
chainConfig: EVMChainConfigWithProviders
|
|
43
|
-
nearAuthentication: NearAuthentication
|
|
44
|
-
fastAuthRelayerUrl?: string
|
|
45
|
-
derivationPath: KeyDerivationPath
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export type BTCChainConfigWithProviders = ChainProvider & {
|
|
49
|
-
network: BTCNetworkIds
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface BitcoinRequest {
|
|
53
|
-
transaction: BTCTransactionRequest
|
|
54
|
-
chainConfig: BTCChainConfigWithProviders
|
|
55
|
-
nearAuthentication: NearAuthentication
|
|
56
|
-
fastAuthRelayerUrl?: string
|
|
57
|
-
derivationPath: KeyDerivationPath
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface CosmosChainConfig {
|
|
61
|
-
contract: ChainSignatureContractIds
|
|
62
|
-
chainId: CosmosNetworkIds
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface CosmosRequest {
|
|
66
|
-
chainConfig: CosmosChainConfig
|
|
67
|
-
transaction: CosmosTransactionRequest
|
|
68
|
-
nearAuthentication: NearAuthentication
|
|
69
|
-
derivationPath: KeyDerivationPath
|
|
70
|
-
fastAuthRelayerUrl?: string
|
|
71
|
-
}
|
package/src/index.ts
DELETED
package/src/types.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { type SignArgs } from '@contracts/ChainSignatureContract'
|
|
2
|
-
|
|
3
|
-
export type HashToSign = SignArgs['payload']
|
|
4
|
-
|
|
5
|
-
type Base58String = string
|
|
6
|
-
|
|
7
|
-
export type NajPublicKey = `secp256k1:${Base58String}`
|
|
8
|
-
|
|
9
|
-
export type UncompressedPubKeySEC1 = `04${string}`
|
|
10
|
-
|
|
11
|
-
export type CompressedPubKeySEC1 = `02${string}` | `03${string}`
|
|
12
|
-
|
|
13
|
-
export type KeyDerivationPath = string
|
|
14
|
-
|
|
15
|
-
export interface RSVSignature {
|
|
16
|
-
r: string
|
|
17
|
-
s: string
|
|
18
|
-
v: number
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface NearNearMpcSignature {
|
|
22
|
-
big_r: {
|
|
23
|
-
affine_point: string
|
|
24
|
-
}
|
|
25
|
-
s: {
|
|
26
|
-
scalar: string
|
|
27
|
-
}
|
|
28
|
-
recovery_id: number
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface SigNetNearMpcSignature {
|
|
32
|
-
big_r: string
|
|
33
|
-
s: string
|
|
34
|
-
recovery_id: number
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface SigNetEvmMpcSignature {
|
|
38
|
-
bigR: { x: bigint; y: bigint }
|
|
39
|
-
s: bigint
|
|
40
|
-
recoveryId: number
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type MPCSignature =
|
|
44
|
-
| NearNearMpcSignature
|
|
45
|
-
| SigNetNearMpcSignature
|
|
46
|
-
| SigNetEvmMpcSignature
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { base58 } from '@scure/base'
|
|
2
|
-
import { ec as EC } from 'elliptic'
|
|
3
|
-
import { sha3_256 } from 'js-sha3'
|
|
4
|
-
import { keccak256 } from 'viem'
|
|
5
|
-
|
|
6
|
-
import { KDF_CHAIN_IDS } from '@constants'
|
|
7
|
-
import {
|
|
8
|
-
type NajPublicKey,
|
|
9
|
-
type MPCSignature,
|
|
10
|
-
type RSVSignature,
|
|
11
|
-
type UncompressedPubKeySEC1,
|
|
12
|
-
} from '@types'
|
|
13
|
-
|
|
14
|
-
export const toRSV = (signature: MPCSignature): RSVSignature => {
|
|
15
|
-
// Handle NearNearMpcSignature
|
|
16
|
-
if (
|
|
17
|
-
'big_r' in signature &&
|
|
18
|
-
typeof signature.big_r === 'object' &&
|
|
19
|
-
'affine_point' in signature.big_r &&
|
|
20
|
-
's' in signature &&
|
|
21
|
-
typeof signature.s === 'object' &&
|
|
22
|
-
'scalar' in signature.s
|
|
23
|
-
) {
|
|
24
|
-
return {
|
|
25
|
-
r: signature.big_r.affine_point.substring(2),
|
|
26
|
-
s: signature.s.scalar,
|
|
27
|
-
v: signature.recovery_id + 27,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// Handle SigNetNearMpcSignature
|
|
31
|
-
else if (
|
|
32
|
-
'big_r' in signature &&
|
|
33
|
-
typeof signature.big_r === 'string' &&
|
|
34
|
-
's' in signature &&
|
|
35
|
-
typeof signature.s === 'string'
|
|
36
|
-
) {
|
|
37
|
-
return {
|
|
38
|
-
r: signature.big_r.substring(2),
|
|
39
|
-
s: signature.s,
|
|
40
|
-
v: signature.recovery_id + 27,
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
// Handle SigNetEvmMpcSignature
|
|
44
|
-
else if (
|
|
45
|
-
'bigR' in signature &&
|
|
46
|
-
'x' in signature.bigR &&
|
|
47
|
-
's' in signature &&
|
|
48
|
-
typeof signature.s === 'bigint'
|
|
49
|
-
) {
|
|
50
|
-
return {
|
|
51
|
-
r: signature.bigR.x.toString(16).padStart(64, '0'),
|
|
52
|
-
s: signature.s.toString(16).padStart(64, '0'),
|
|
53
|
-
v: signature.recoveryId + 27,
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
throw new Error('Invalid signature format')
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Compresses an uncompressed public key to its compressed format following SEC1 standards.
|
|
62
|
-
* In SEC1, a compressed public key consists of a prefix (02 or 03) followed by the x-coordinate.
|
|
63
|
-
* The prefix indicates whether the y-coordinate is even (02) or odd (03).
|
|
64
|
-
*
|
|
65
|
-
* @param uncompressedPubKeySEC1 - The uncompressed public key in hex format, with or without '04' prefix
|
|
66
|
-
* @returns The compressed public key in hex format
|
|
67
|
-
* @throws Error if the uncompressed public key length is invalid
|
|
68
|
-
*/
|
|
69
|
-
export const compressPubKey = (
|
|
70
|
-
uncompressedPubKeySEC1: UncompressedPubKeySEC1
|
|
71
|
-
): string => {
|
|
72
|
-
const slicedPubKey = uncompressedPubKeySEC1.slice(2)
|
|
73
|
-
|
|
74
|
-
if (slicedPubKey.length !== 128) {
|
|
75
|
-
throw new Error('Invalid uncompressed public key length')
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const x = slicedPubKey.slice(0, 64)
|
|
79
|
-
const y = slicedPubKey.slice(64)
|
|
80
|
-
|
|
81
|
-
const isEven = parseInt(y.slice(-1), 16) % 2 === 0
|
|
82
|
-
const prefix = isEven ? '02' : '03'
|
|
83
|
-
|
|
84
|
-
return prefix + x
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Converts a NAJ public key to an uncompressed SEC1 public key.
|
|
89
|
-
*
|
|
90
|
-
* @param najPublicKey - The NAJ public key to convert (e.g. secp256k1:3Ww8iFjqTHufye5aRGUvrQqETegR4gVUcW8FX5xzscaN9ENhpkffojsxJwi6N1RbbHMTxYa9UyKeqK3fsMuwxjR5)
|
|
91
|
-
* @returns The uncompressed SEC1 public key (e.g. 04 || x || y)
|
|
92
|
-
*/
|
|
93
|
-
export const najToUncompressedPubKeySEC1 = (
|
|
94
|
-
najPublicKey: NajPublicKey
|
|
95
|
-
): UncompressedPubKeySEC1 => {
|
|
96
|
-
const decodedKey = base58.decode(najPublicKey.split(':')[1])
|
|
97
|
-
return `04${Buffer.from(decodedKey).toString('hex')}`
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Derives a child public key from a parent public key using the sig.network v1.0.0 epsilon derivation scheme.
|
|
102
|
-
* The parent public keys are defined in @constants.ts
|
|
103
|
-
*
|
|
104
|
-
* @param najPublicKey - The parent public key in uncompressed SEC1 format (e.g. 04 || x || y)
|
|
105
|
-
* @param predecessorId - The predecessor ID is the address of the account calling the signer contract (e.g EOA or Contract Address)
|
|
106
|
-
* @param path - Optional derivation path suffix (defaults to empty string)
|
|
107
|
-
* @returns The derived child public key in uncompressed SEC1 format (04 || x || y)
|
|
108
|
-
*/
|
|
109
|
-
export function deriveChildPublicKey(
|
|
110
|
-
rootUncompressedPubKeySEC1: UncompressedPubKeySEC1,
|
|
111
|
-
predecessorId: string,
|
|
112
|
-
path: string = '',
|
|
113
|
-
chainId: string
|
|
114
|
-
): UncompressedPubKeySEC1 {
|
|
115
|
-
const ec = new EC('secp256k1')
|
|
116
|
-
|
|
117
|
-
const EPSILON_DERIVATION_PREFIX = 'sig.network v1.0.0 epsilon derivation'
|
|
118
|
-
const derivationPath = `${EPSILON_DERIVATION_PREFIX},${chainId},${predecessorId},${path}`
|
|
119
|
-
|
|
120
|
-
let scalarHex = ''
|
|
121
|
-
|
|
122
|
-
if (chainId === KDF_CHAIN_IDS.ETHEREUM) {
|
|
123
|
-
scalarHex = keccak256(Buffer.from(derivationPath)).slice(2)
|
|
124
|
-
} else if (chainId === KDF_CHAIN_IDS.NEAR) {
|
|
125
|
-
scalarHex = sha3_256(derivationPath)
|
|
126
|
-
} else {
|
|
127
|
-
throw new Error('Invalid chain ID')
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const x = rootUncompressedPubKeySEC1.substring(2, 66)
|
|
131
|
-
const y = rootUncompressedPubKeySEC1.substring(66)
|
|
132
|
-
|
|
133
|
-
const oldPublicKeyPoint = ec.curve.point(x, y)
|
|
134
|
-
const scalarTimesG = ec.g.mul(scalarHex)
|
|
135
|
-
const newPublicKeyPoint = oldPublicKeyPoint.add(scalarTimesG)
|
|
136
|
-
|
|
137
|
-
const newX = newPublicKeyPoint.getX().toString('hex').padStart(64, '0')
|
|
138
|
-
const newY = newPublicKeyPoint.getY().toString('hex').padStart(64, '0')
|
|
139
|
-
|
|
140
|
-
return `04${newX}${newY}`
|
|
141
|
-
}
|
package/src/utils/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * as cryptography from './cryptography'
|