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
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
# Cosmos Chain Implementation
|
|
2
|
-
|
|
3
|
-
The Cosmos chain implementation supports Cosmos SDK-based networks (Cosmos Hub, Osmosis, etc.) with a focus on standard transactions and IBC transfers.
|
|
4
|
-
|
|
5
|
-
## Configuration
|
|
6
|
-
|
|
7
|
-
```ts twoslash filename="base.ts"
|
|
8
|
-
// [!include ~/snippets/contract.ts]
|
|
9
|
-
// ---cut---
|
|
10
|
-
import { Cosmos } from 'signet.js'
|
|
11
|
-
|
|
12
|
-
const cosmosChain = new Cosmos({
|
|
13
|
-
chainId: 'cosmoshub-4', // Chain ID of the target network
|
|
14
|
-
contract,
|
|
15
|
-
})
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Methods
|
|
19
|
-
|
|
20
|
-
### getBalance
|
|
21
|
-
|
|
22
|
-
Gets the native token balance of an address.
|
|
23
|
-
|
|
24
|
-
```ts twoslash
|
|
25
|
-
// [!include base.ts]
|
|
26
|
-
// ---cut---
|
|
27
|
-
const balance = await cosmosChain.getBalance('cosmos1...')
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
**Parameters:**
|
|
31
|
-
|
|
32
|
-
- `address`: The Cosmos address to check
|
|
33
|
-
|
|
34
|
-
**Returns:**
|
|
35
|
-
|
|
36
|
-
- The balance formatted according to the chain's decimal places
|
|
37
|
-
|
|
38
|
-
### deriveAddressAndPublicKey
|
|
39
|
-
|
|
40
|
-
Derives a Cosmos address and public key for a given path.
|
|
41
|
-
|
|
42
|
-
```ts twoslash
|
|
43
|
-
// [!include base.ts]
|
|
44
|
-
// ---cut---
|
|
45
|
-
const { address, publicKey } = await cosmosChain.deriveAddressAndPublicKey(
|
|
46
|
-
'predecessor_id',
|
|
47
|
-
'any_string'
|
|
48
|
-
)
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
**Parameters:**
|
|
52
|
-
|
|
53
|
-
- `predecessor`: The ID of the signer to derive from
|
|
54
|
-
- `path`: The derivation path to use
|
|
55
|
-
|
|
56
|
-
**Returns:**
|
|
57
|
-
|
|
58
|
-
- Object containing:
|
|
59
|
-
- `address`: The derived Cosmos address (bech32 format)
|
|
60
|
-
- `publicKey`: The corresponding compressed public key
|
|
61
|
-
|
|
62
|
-
### getMPCPayloadAndTransaction
|
|
63
|
-
|
|
64
|
-
Prepares a transaction for MPC signing.
|
|
65
|
-
|
|
66
|
-
```ts twoslash filename="unsigned-transaction.ts"
|
|
67
|
-
// [!include base.ts]
|
|
68
|
-
// ---cut---
|
|
69
|
-
import { CosmosTransactionRequest } from 'signet.js'
|
|
70
|
-
import { MsgSend } from 'cosmjs-types/cosmos/bank/v1beta1/tx'
|
|
71
|
-
|
|
72
|
-
// Create a token transfer message
|
|
73
|
-
const sendMsg = {
|
|
74
|
-
typeUrl: '/cosmos.bank.v1beta1.MsgSend',
|
|
75
|
-
value: MsgSend.fromPartial({
|
|
76
|
-
fromAddress: 'cosmos1...',
|
|
77
|
-
toAddress: 'cosmos1...',
|
|
78
|
-
amount: [
|
|
79
|
-
{
|
|
80
|
-
denom: 'uatom',
|
|
81
|
-
amount: '1000000', // 1 ATOM (1,000,000 uatom)
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
}),
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const transactionRequest: CosmosTransactionRequest = {
|
|
88
|
-
address: 'cosmos1...',
|
|
89
|
-
publicKey: '0235a3...',
|
|
90
|
-
messages: [sendMsg],
|
|
91
|
-
memo: 'Token transfer',
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const { transaction: unsignedTransaction, mpcPayloads } =
|
|
95
|
-
await cosmosChain.getMPCPayloadAndTransaction(transactionRequest)
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
**Parameters:**
|
|
99
|
-
|
|
100
|
-
- `transactionRequest`: Transaction configuration:
|
|
101
|
-
```ts
|
|
102
|
-
{
|
|
103
|
-
address: string // Sender's address
|
|
104
|
-
publicKey: string // Signer's public key
|
|
105
|
-
messages: Message[] // Array of Cosmos SDK messages
|
|
106
|
-
memo?: string // Optional transaction memo
|
|
107
|
-
gas?: number // Optional gas limit (default: 200,000)
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
**Returns:**
|
|
112
|
-
|
|
113
|
-
- Object containing:
|
|
114
|
-
- `transaction`: The unsigned transaction
|
|
115
|
-
- `mpcPayloads`: Array of payloads to be signed
|
|
116
|
-
|
|
117
|
-
### addSignature
|
|
118
|
-
|
|
119
|
-
Adds signatures to a transaction.
|
|
120
|
-
|
|
121
|
-
```ts twoslash filename="add-signature.ts"
|
|
122
|
-
// [!include unsigned-transaction.ts]
|
|
123
|
-
// ---cut---
|
|
124
|
-
import { RSVSignature } from 'signet.js'
|
|
125
|
-
|
|
126
|
-
// Ideally it would be a request to the Sig Network Smart Contract
|
|
127
|
-
const mpcSignatures: RSVSignature[] = [
|
|
128
|
-
{
|
|
129
|
-
r: '0x...',
|
|
130
|
-
s: '0x...',
|
|
131
|
-
v: 27,
|
|
132
|
-
},
|
|
133
|
-
]
|
|
134
|
-
|
|
135
|
-
const signedTx = cosmosChain.addSignature({
|
|
136
|
-
transaction: unsignedTransaction,
|
|
137
|
-
mpcSignatures,
|
|
138
|
-
})
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
**Parameters:**
|
|
142
|
-
|
|
143
|
-
- `transaction`: The unsigned transaction
|
|
144
|
-
- `mpcSignatures`: Array of RSV signatures from MPC
|
|
145
|
-
|
|
146
|
-
**Returns:**
|
|
147
|
-
|
|
148
|
-
- The serialized signed transaction in hex format
|
|
149
|
-
|
|
150
|
-
### broadcastTx
|
|
151
|
-
|
|
152
|
-
Broadcasts a signed transaction to the network.
|
|
153
|
-
|
|
154
|
-
```ts twoslash filename="broadcast-tx.ts"
|
|
155
|
-
// [!include add-signature.ts]
|
|
156
|
-
// ---cut---
|
|
157
|
-
const txHash = await cosmosChain.broadcastTx(signedTx)
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
**Parameters:**
|
|
161
|
-
|
|
162
|
-
- `txSerialized`: The serialized transaction in hex format
|
|
163
|
-
|
|
164
|
-
**Returns:**
|
|
165
|
-
|
|
166
|
-
- The transaction hash
|
|
167
|
-
|
|
168
|
-
## Technical Details
|
|
169
|
-
|
|
170
|
-
The implementation:
|
|
171
|
-
|
|
172
|
-
- Uses `@cosmjs/stargate` for transaction handling
|
|
173
|
-
- Supports SIGN_MODE_DIRECT signing
|
|
174
|
-
- Uses Protobuf for message encoding
|
|
175
|
-
- Supports standard Cosmos SDK messages:
|
|
176
|
-
- Bank (Send, MultiSend)
|
|
177
|
-
- Staking (Delegate, Undelegate, Redelegate)
|
|
178
|
-
- Distribution (Withdraw Rewards)
|
|
179
|
-
- IBC (Transfer)
|
|
180
|
-
- Handles automatic fee calculation based on gas prices
|
|
181
|
-
- Supports custom message types through the Registry
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
# EVM Chain Implementation
|
|
2
|
-
|
|
3
|
-
This implementation supports all EVM-compatible networks (Ethereum, Binance Smart Chain, Polygon, etc.).
|
|
4
|
-
|
|
5
|
-
## Configuration
|
|
6
|
-
|
|
7
|
-
```ts twoslash filename="base.ts"
|
|
8
|
-
// [!include ~/snippets/contract.ts]
|
|
9
|
-
// ---cut---
|
|
10
|
-
import { EVM } from 'signet.js'
|
|
11
|
-
|
|
12
|
-
// Initialize the chain
|
|
13
|
-
const evmChain = new EVM({
|
|
14
|
-
rpcUrl: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID',
|
|
15
|
-
contract,
|
|
16
|
-
})
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Methods
|
|
20
|
-
|
|
21
|
-
### getBalance
|
|
22
|
-
|
|
23
|
-
Gets the native token balance of an address in ETH units.
|
|
24
|
-
|
|
25
|
-
```ts twoslash
|
|
26
|
-
// [!include base.ts]
|
|
27
|
-
// ---cut---
|
|
28
|
-
const balance = await evmChain.getBalance('0x...')
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
**Parameters:**
|
|
32
|
-
|
|
33
|
-
- `address`: The Ethereum address to check
|
|
34
|
-
|
|
35
|
-
**Returns:**
|
|
36
|
-
|
|
37
|
-
- The balance in ETH as a string
|
|
38
|
-
|
|
39
|
-
### deriveAddressAndPublicKey
|
|
40
|
-
|
|
41
|
-
Derives an Ethereum address and public key from a signer ID and derivation path.
|
|
42
|
-
|
|
43
|
-
```ts twoslash
|
|
44
|
-
// [!include base.ts]
|
|
45
|
-
// ---cut---
|
|
46
|
-
const { address, publicKey } = await evmChain.deriveAddressAndPublicKey(
|
|
47
|
-
'0x...',
|
|
48
|
-
'any_string'
|
|
49
|
-
)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
**Parameters:**
|
|
53
|
-
|
|
54
|
-
- `predecessor`: The ID/address of the signer requesting the signature
|
|
55
|
-
- `path`: The derivation path to use
|
|
56
|
-
|
|
57
|
-
**Returns:**
|
|
58
|
-
|
|
59
|
-
- Object containing:
|
|
60
|
-
- `address`: The derived Ethereum address
|
|
61
|
-
- `publicKey`: The corresponding public key in SEC1 uncompressed format
|
|
62
|
-
|
|
63
|
-
### getMPCPayloadAndTransaction
|
|
64
|
-
|
|
65
|
-
Prepares a transaction for MPC signing.
|
|
66
|
-
|
|
67
|
-
```ts twoslash filename="unsigned-transaction.ts"
|
|
68
|
-
// [!include base.ts]
|
|
69
|
-
// ---cut---
|
|
70
|
-
import { EVMTransactionRequest } from 'signet.js'
|
|
71
|
-
|
|
72
|
-
const transactionRequest: EVMTransactionRequest = {
|
|
73
|
-
to: '0x...',
|
|
74
|
-
from: '0x...',
|
|
75
|
-
value: '100000000000000000',
|
|
76
|
-
data: '0x...',
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const { transaction: unsignedTransaction, mpcPayloads } =
|
|
80
|
-
await evmChain.getMPCPayloadAndTransaction(transactionRequest)
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
The transaction is enhanced with:
|
|
84
|
-
|
|
85
|
-
- Gas estimation
|
|
86
|
-
- Nonce calculation
|
|
87
|
-
- Chain ID
|
|
88
|
-
- EIP-1559 fee parameters
|
|
89
|
-
|
|
90
|
-
### addSignature
|
|
91
|
-
|
|
92
|
-
Adds a signature to an unsigned transaction.
|
|
93
|
-
|
|
94
|
-
```ts twoslash filename="add-signature.ts"
|
|
95
|
-
// [!include unsigned-transaction.ts]
|
|
96
|
-
// ---cut---
|
|
97
|
-
import { RSVSignature } from 'signet.js'
|
|
98
|
-
|
|
99
|
-
// Ideally it would be a request to the Sig Network Smart Contract
|
|
100
|
-
const mpcSignatures: RSVSignature[] = [
|
|
101
|
-
{
|
|
102
|
-
r: '0x...',
|
|
103
|
-
s: '0x...',
|
|
104
|
-
v: 27,
|
|
105
|
-
},
|
|
106
|
-
]
|
|
107
|
-
|
|
108
|
-
const txSerialized = await evmChain.addSignature({
|
|
109
|
-
transaction: unsignedTransaction,
|
|
110
|
-
mpcSignatures,
|
|
111
|
-
})
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
**Parameters:**
|
|
115
|
-
|
|
116
|
-
- `transaction`: The unsigned transaction
|
|
117
|
-
- `mpcSignatures`: Array of RSV signatures from MPC
|
|
118
|
-
|
|
119
|
-
**Returns:**
|
|
120
|
-
|
|
121
|
-
- The serialized signed transaction
|
|
122
|
-
|
|
123
|
-
### broadcastTx
|
|
124
|
-
|
|
125
|
-
Broadcasts a signed transaction to the network.
|
|
126
|
-
|
|
127
|
-
```ts twoslash filename="broadcast-tx.ts"
|
|
128
|
-
// [!include add-signature.ts]
|
|
129
|
-
// ---cut---
|
|
130
|
-
const txHash = await evmChain.broadcastTx(txSerialized)
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
**Parameters:**
|
|
134
|
-
|
|
135
|
-
- `txSerialized`: The serialized signed transaction
|
|
136
|
-
|
|
137
|
-
**Returns:**
|
|
138
|
-
|
|
139
|
-
- The transaction hash
|
|
140
|
-
|
|
141
|
-
## Adding New EVM Chains
|
|
142
|
-
|
|
143
|
-
To add support for a new EVM-compatible chain, you only need to configure the provider URL. The chain ID and network configuration are automatically retrieved from the provider.
|
|
144
|
-
|
|
145
|
-
```ts twoslash
|
|
146
|
-
// [!include ~/snippets/contract.ts]
|
|
147
|
-
// ---cut---
|
|
148
|
-
import { EVM } from 'signet.js'
|
|
149
|
-
|
|
150
|
-
// For Polygon (Matic)
|
|
151
|
-
const polygonChain = new EVM({
|
|
152
|
-
rpcUrl: 'https://polygon-rpc.com',
|
|
153
|
-
contract,
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
// For Binance Smart Chain
|
|
157
|
-
const bscChain = new EVM({
|
|
158
|
-
rpcUrl: 'https://bsc-dataseed.binance.org',
|
|
159
|
-
contract,
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
// For Arbitrum
|
|
163
|
-
const arbitrumChain = new EVM({
|
|
164
|
-
rpcUrl: 'https://arb1.arbitrum.io/rpc',
|
|
165
|
-
contract,
|
|
166
|
-
})
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
## Technical Details
|
|
170
|
-
|
|
171
|
-
The implementation:
|
|
172
|
-
|
|
173
|
-
- Uses `ethers.js` for transaction handling and RPC communication
|
|
174
|
-
- Supports both legacy and EIP-1559 transactions
|
|
175
|
-
- Handles automatic nonce management
|
|
176
|
-
- Supports contract interactions through ABI encoding
|
|
177
|
-
- Provides automatic gas estimation and fee calculation
|
|
178
|
-
- Compatible with all EVM-based networks
|
|
179
|
-
- Supports ENS name resolution on networks that implement it
|
|
180
|
-
- Handles transaction signing according to EIP-155
|
|
181
|
-
- Supports raw transaction data for custom contract interactions
|
|
182
|
-
|
|
183
|
-
## Types
|
|
184
|
-
|
|
185
|
-
The following types are used on the EVM chain:
|
|
186
|
-
|
|
187
|
-
```ts twoslash
|
|
188
|
-
// [!include ~/../src/chains/EVM/types.ts]
|
|
189
|
-
```
|
package/docs/pages/index.mdx
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# Signet.js Documentation
|
|
2
|
-
|
|
3
|
-
A TypeScript library for handling interactions with Sig Network MPC and Smart Contracts
|
|
4
|
-
|
|
5
|
-
## Supported Chains
|
|
6
|
-
|
|
7
|
-
- [EVM Chains](./chains/evm.mdx) - Ethereum and compatible networks
|
|
8
|
-
- [Bitcoin](./chains/bitcoin/bitcoin.mdx) - Bitcoin network
|
|
9
|
-
- [Cosmos Chains](./chains/cosmos.mdx) - Cosmos SDK-based networks
|
|
10
|
-
|
|
11
|
-
## Core Features
|
|
12
|
-
|
|
13
|
-
- **Balance Checking**: Query account balances across different chains
|
|
14
|
-
- **Address and Public Key Derivation**: Derive addresses and public keys following Sig Network derivation function
|
|
15
|
-
- **Transaction Management**: Create, store, and retrieve transactions
|
|
16
|
-
- **Signature Handling**: Process MPC signatures for transactions
|
|
17
|
-
- **Transaction Broadcasting**: Submit signed transactions to the network
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
npm install signet.js
|
|
23
|
-
# or
|
|
24
|
-
yarn add signet.js
|
|
25
|
-
# or
|
|
26
|
-
pnpm add signet.js
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Quick Start
|
|
30
|
-
|
|
31
|
-
Here's a basic example using the EVM implementation:
|
|
32
|
-
|
|
33
|
-
```ts twoslash
|
|
34
|
-
import { EVM, utils } from 'signet.js'
|
|
35
|
-
// [!include ~/snippets/env.ts]
|
|
36
|
-
|
|
37
|
-
const contract = new utils.chains.near.ChainSignatureContract({
|
|
38
|
-
networkId: 'testnet',
|
|
39
|
-
contractId: 'v1.signer-prod.testnet',
|
|
40
|
-
accountId,
|
|
41
|
-
keypair,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const evmChain = new EVM({
|
|
45
|
-
rpcUrl: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID',
|
|
46
|
-
contract,
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
// Derive address and public key
|
|
50
|
-
const { address, publicKey } = await evmChain.deriveAddressAndPublicKey(
|
|
51
|
-
accountId,
|
|
52
|
-
'any_string'
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
// Check balance
|
|
56
|
-
const balance = await evmChain.getBalance(address)
|
|
57
|
-
|
|
58
|
-
// Create and sign transaction
|
|
59
|
-
const { transaction, mpcPayloads } = await evmChain.getMPCPayloadAndTransaction(
|
|
60
|
-
{
|
|
61
|
-
from: '0x...',
|
|
62
|
-
to: '0x...',
|
|
63
|
-
value: '1000000000000000000',
|
|
64
|
-
}
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
// Sign with MPC
|
|
68
|
-
const signature = await contract.sign({
|
|
69
|
-
payload: mpcPayloads[0].payload,
|
|
70
|
-
path: 'any_string',
|
|
71
|
-
key_version: 0,
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
// Add signature
|
|
75
|
-
const signedTx = evmChain.addSignature({
|
|
76
|
-
transaction,
|
|
77
|
-
mpcSignatures: [signature],
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
// Broadcast transaction
|
|
81
|
-
const txHash = await evmChain.broadcastTx(signedTx)
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
## Architecture
|
|
85
|
-
|
|
86
|
-
The library is built around a core `Chain` interface that defines common functionality across all supported blockchain networks. Each specific chain implementation extends this interface with network-specific features while maintaining a consistent API.
|
|
87
|
-
|
|
88
|
-
For more details check the [Chain](./chain.mdx) page.
|
|
89
|
-
|
|
90
|
-
## Utility Functions
|
|
91
|
-
|
|
92
|
-
Besides the Chain classes the library also provide utility functions to assist you on building transactions, requesting signature in wrapped methods.
|
|
93
|
-
|
|
94
|
-
Currently we support only Near, but we are working on adding support for other chains.
|
|
95
|
-
|
|
96
|
-
## Repositories
|
|
97
|
-
|
|
98
|
-
- Signet.js: [https://github.com/sig-net/signet.js](https://github.com/sig-net/signet.js).
|
|
99
|
-
- MPC: [https://github.com/sig-net/mpc](https://github.com/sig-net/mpc).
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { KeyPair, type KeyPairString } from '@near-js/crypto'
|
|
2
|
-
import { utils } from 'signet.js'
|
|
3
|
-
|
|
4
|
-
// Initialize NEAR connection with credentials from environment
|
|
5
|
-
const accountId = process.env.NEAR_ACCOUNT_ID
|
|
6
|
-
const privateKey = process.env.NEAR_PRIVATE_KEY as KeyPairString
|
|
7
|
-
|
|
8
|
-
if (!accountId || !privateKey) {
|
|
9
|
-
throw new Error(
|
|
10
|
-
'NEAR_ACCOUNT_ID and NEAR_PRIVATE_KEY must be set in environment'
|
|
11
|
-
)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const keypair = KeyPair.fromString(privateKey)
|
|
15
|
-
|
|
16
|
-
const contract = new utils.chains.near.ChainSignatureContract({
|
|
17
|
-
networkId: 'testnet',
|
|
18
|
-
contractId: 'v1.signer-prod.testnet',
|
|
19
|
-
accountId,
|
|
20
|
-
keypair,
|
|
21
|
-
})
|
package/docs/snippets/env.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { KeyPair, type KeyPairString } from '@near-js/crypto'
|
|
2
|
-
|
|
3
|
-
// Initialize NEAR connection with credentials from environment
|
|
4
|
-
const accountId = process.env.NEAR_ACCOUNT_ID
|
|
5
|
-
const privateKey = process.env.NEAR_PRIVATE_KEY as KeyPairString
|
|
6
|
-
|
|
7
|
-
if (!accountId || !privateKey) {
|
|
8
|
-
throw new Error(
|
|
9
|
-
'NEAR_ACCOUNT_ID and NEAR_PRIVATE_KEY must be set in environment'
|
|
10
|
-
)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const keypair = KeyPair.fromString(privateKey)
|
package/jest.config.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For a detailed explanation regarding each configuration property, visit:
|
|
3
|
-
* https://jestjs.io/docs/configuration
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type {Config} from 'jest';
|
|
7
|
-
|
|
8
|
-
const config: Config = {
|
|
9
|
-
// All imported modules in your tests should be mocked automatically
|
|
10
|
-
// automock: false,
|
|
11
|
-
|
|
12
|
-
// Stop running tests after `n` failures
|
|
13
|
-
// bail: 0,
|
|
14
|
-
|
|
15
|
-
// The directory where Jest should store its cached dependency information
|
|
16
|
-
// cacheDirectory: "/private/var/folders/dn/p7pfr0cd1x94jsqf6_79fg8m0000gn/T/jest_dx",
|
|
17
|
-
|
|
18
|
-
// Automatically clear mock calls, instances, contexts and results before every test
|
|
19
|
-
clearMocks: true,
|
|
20
|
-
|
|
21
|
-
// Indicates whether the coverage information should be collected while executing the test
|
|
22
|
-
// collectCoverage: false,
|
|
23
|
-
|
|
24
|
-
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
25
|
-
// collectCoverageFrom: undefined,
|
|
26
|
-
|
|
27
|
-
// The directory where Jest should output its coverage files
|
|
28
|
-
// coverageDirectory: undefined,
|
|
29
|
-
|
|
30
|
-
// An array of regexp pattern strings used to skip coverage collection
|
|
31
|
-
// coveragePathIgnorePatterns: [
|
|
32
|
-
// "/node_modules/"
|
|
33
|
-
// ],
|
|
34
|
-
|
|
35
|
-
// Indicates which provider should be used to instrument code for coverage
|
|
36
|
-
coverageProvider: "v8",
|
|
37
|
-
|
|
38
|
-
// A list of reporter names that Jest uses when writing coverage reports
|
|
39
|
-
// coverageReporters: [
|
|
40
|
-
// "json",
|
|
41
|
-
// "text",
|
|
42
|
-
// "lcov",
|
|
43
|
-
// "clover"
|
|
44
|
-
// ],
|
|
45
|
-
|
|
46
|
-
// An object that configures minimum threshold enforcement for coverage results
|
|
47
|
-
// coverageThreshold: undefined,
|
|
48
|
-
|
|
49
|
-
// A path to a custom dependency extractor
|
|
50
|
-
// dependencyExtractor: undefined,
|
|
51
|
-
|
|
52
|
-
// Make calling deprecated APIs throw helpful error messages
|
|
53
|
-
// errorOnDeprecated: false,
|
|
54
|
-
|
|
55
|
-
// The default configuration for fake timers
|
|
56
|
-
// fakeTimers: {
|
|
57
|
-
// "enableGlobally": false
|
|
58
|
-
// },
|
|
59
|
-
|
|
60
|
-
// Force coverage collection from ignored files using an array of glob patterns
|
|
61
|
-
// forceCoverageMatch: [],
|
|
62
|
-
|
|
63
|
-
// A path to a module which exports an async function that is triggered once before all test suites
|
|
64
|
-
// globalSetup: undefined,
|
|
65
|
-
|
|
66
|
-
// A path to a module which exports an async function that is triggered once after all test suites
|
|
67
|
-
// globalTeardown: undefined,
|
|
68
|
-
|
|
69
|
-
// A set of global variables that need to be available in all test environments
|
|
70
|
-
// globals: {},
|
|
71
|
-
|
|
72
|
-
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
73
|
-
// maxWorkers: "50%",
|
|
74
|
-
|
|
75
|
-
// An array of directory names to be searched recursively up from the requiring module's location
|
|
76
|
-
// moduleDirectories: [
|
|
77
|
-
// "node_modules"
|
|
78
|
-
// ],
|
|
79
|
-
|
|
80
|
-
// An array of file extensions your modules use
|
|
81
|
-
// moduleFileExtensions: [
|
|
82
|
-
// "js",
|
|
83
|
-
// "mjs",
|
|
84
|
-
// "cjs",
|
|
85
|
-
// "jsx",
|
|
86
|
-
// "ts",
|
|
87
|
-
// "tsx",
|
|
88
|
-
// "json",
|
|
89
|
-
// "node"
|
|
90
|
-
// ],
|
|
91
|
-
|
|
92
|
-
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
93
|
-
// moduleNameMapper: {},
|
|
94
|
-
|
|
95
|
-
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
96
|
-
// modulePathIgnorePatterns: [],
|
|
97
|
-
|
|
98
|
-
// Activates notifications for test results
|
|
99
|
-
// notify: false,
|
|
100
|
-
|
|
101
|
-
// An enum that specifies notification mode. Requires { notify: true }
|
|
102
|
-
// notifyMode: "failure-change",
|
|
103
|
-
|
|
104
|
-
// A preset that is used as a base for Jest's configuration
|
|
105
|
-
// preset: undefined,
|
|
106
|
-
|
|
107
|
-
// Run tests from one or more projects
|
|
108
|
-
// projects: undefined,
|
|
109
|
-
|
|
110
|
-
// Use this configuration option to add custom reporters to Jest
|
|
111
|
-
// reporters: undefined,
|
|
112
|
-
|
|
113
|
-
// Automatically reset mock state before every test
|
|
114
|
-
// resetMocks: false,
|
|
115
|
-
|
|
116
|
-
// Reset the module registry before running each individual test
|
|
117
|
-
// resetModules: false,
|
|
118
|
-
|
|
119
|
-
// A path to a custom resolver
|
|
120
|
-
// resolver: undefined,
|
|
121
|
-
|
|
122
|
-
// Automatically restore mock state and implementation before every test
|
|
123
|
-
// restoreMocks: false,
|
|
124
|
-
|
|
125
|
-
// The root directory that Jest should scan for tests and modules within
|
|
126
|
-
// rootDir: undefined,
|
|
127
|
-
|
|
128
|
-
// A list of paths to directories that Jest should use to search for files in
|
|
129
|
-
// roots: [
|
|
130
|
-
// "<rootDir>"
|
|
131
|
-
// ],
|
|
132
|
-
|
|
133
|
-
// Allows you to use a custom runner instead of Jest's default test runner
|
|
134
|
-
// runner: "jest-runner",
|
|
135
|
-
|
|
136
|
-
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
137
|
-
// setupFiles: [],
|
|
138
|
-
|
|
139
|
-
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
140
|
-
// setupFilesAfterEnv: [],
|
|
141
|
-
|
|
142
|
-
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
143
|
-
// slowTestThreshold: 5,
|
|
144
|
-
|
|
145
|
-
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
146
|
-
// snapshotSerializers: [],
|
|
147
|
-
|
|
148
|
-
// The test environment that will be used for testing
|
|
149
|
-
// testEnvironment: "jest-environment-node",
|
|
150
|
-
|
|
151
|
-
// Options that will be passed to the testEnvironment
|
|
152
|
-
// testEnvironmentOptions: {},
|
|
153
|
-
|
|
154
|
-
// Adds a location field to test results
|
|
155
|
-
// testLocationInResults: false,
|
|
156
|
-
|
|
157
|
-
// The glob patterns Jest uses to detect test files
|
|
158
|
-
// testMatch: [
|
|
159
|
-
// "**/__tests__/**/*.[jt]s?(x)",
|
|
160
|
-
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
161
|
-
// ],
|
|
162
|
-
|
|
163
|
-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
164
|
-
// testPathIgnorePatterns: [
|
|
165
|
-
// "/node_modules/"
|
|
166
|
-
// ],
|
|
167
|
-
|
|
168
|
-
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
169
|
-
// testRegex: [],
|
|
170
|
-
|
|
171
|
-
// This option allows the use of a custom results processor
|
|
172
|
-
// testResultsProcessor: undefined,
|
|
173
|
-
|
|
174
|
-
// This option allows use of a custom test runner
|
|
175
|
-
// testRunner: "jest-circus/runner",
|
|
176
|
-
|
|
177
|
-
// A map from regular expressions to paths to transformers
|
|
178
|
-
// transform: undefined,
|
|
179
|
-
|
|
180
|
-
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
181
|
-
// transformIgnorePatterns: [
|
|
182
|
-
// "/node_modules/",
|
|
183
|
-
// "\\.pnp\\.[^\\/]+$"
|
|
184
|
-
// ],
|
|
185
|
-
|
|
186
|
-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
187
|
-
// unmockedModulePathPatterns: undefined,
|
|
188
|
-
|
|
189
|
-
// Indicates whether each individual test should be reported during the run
|
|
190
|
-
// verbose: undefined,
|
|
191
|
-
|
|
192
|
-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
193
|
-
// watchPathIgnorePatterns: [],
|
|
194
|
-
|
|
195
|
-
// Whether to use watchman for file crawling
|
|
196
|
-
// watchman: true,
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
export default config;
|