signet.js 0.0.1-beta.5 → 0.0.1-beta.7
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/.eslintrc.json +55 -0
- package/.prettierrc +1 -0
- package/LICENSE +19 -0
- package/README.md +42 -14
- package/babel.config.js +6 -0
- package/docs/pages/chain-signatures-contract.mdx +56 -0
- package/docs/pages/chain.mdx +45 -0
- package/docs/pages/chains/bitcoin/bitcoin.mdx +191 -0
- package/docs/pages/chains/bitcoin/btc-rpc-adapter.mdx +307 -0
- package/docs/pages/chains/cosmos.mdx +181 -0
- package/docs/pages/chains/evm.mdx +189 -0
- package/docs/pages/index.mdx +99 -0
- package/docs/snippets/contract.ts +21 -0
- package/docs/snippets/env.ts +13 -0
- package/jest.config.ts +199 -0
- package/package.json +21 -11
- package/src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts +11 -0
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts +96 -0
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/index.ts +1 -0
- package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/types.ts +72 -0
- package/src/chains/Bitcoin/BTCRpcAdapter/index.ts +6 -0
- package/src/chains/Bitcoin/Bitcoin.ts +301 -0
- package/src/chains/Bitcoin/types.ts +45 -0
- package/src/chains/Bitcoin/utils.ts +14 -0
- package/src/chains/Chain.ts +96 -0
- package/src/chains/ChainSignatureContract.ts +48 -0
- package/src/chains/Cosmos/Cosmos.ts +279 -0
- package/src/chains/Cosmos/types.ts +35 -0
- package/src/chains/Cosmos/utils.ts +45 -0
- package/src/chains/EVM/EVM.ts +180 -0
- package/src/chains/EVM/types.ts +7 -0
- package/src/chains/EVM/utils.ts +26 -0
- package/src/chains/index.ts +34 -0
- package/src/chains/types.ts +35 -0
- package/src/chains/utils.ts +40 -0
- package/src/index.ts +2 -0
- package/src/utils/chains/index.ts +1 -0
- package/src/utils/chains/near/ChainSignatureContract.ts +195 -0
- package/src/utils/chains/near/account.ts +42 -0
- package/src/utils/chains/near/constants.ts +4 -0
- package/src/utils/chains/near/index.ts +3 -0
- package/src/utils/chains/near/relayer/index.ts +1 -0
- package/src/utils/chains/near/relayer/relayer.ts +39 -0
- package/src/utils/chains/near/relayer/types.ts +24 -0
- package/src/utils/chains/near/signAndSend/index.ts +1 -0
- package/src/utils/chains/near/signAndSend/keypair.ts +180 -0
- package/src/utils/chains/near/transactionBuilder.ts +138 -0
- package/src/utils/chains/near/types.ts +67 -0
- package/src/utils/index.ts +1 -0
- package/tsconfig.eslint.json +8 -0
- package/tsconfig.json +116 -0
- package/vite.config.ts +47 -0
- package/vocs.config.ts +60 -0
- 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 -69
- package/src/chains/Bitcoin/Bitcoin.js +0 -198
- 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 -51
- package/src/chains/Cosmos/Cosmos.js +0 -157
- 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 -42
- package/src/chains/EVM/EVM.js +0 -109
- 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 -40
- package/src/utils/chains/near/contract.js +0 -102
- 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 -127
- 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 -50
- 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
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": true,
|
|
4
|
+
"es2021": true
|
|
5
|
+
},
|
|
6
|
+
"extends": [
|
|
7
|
+
"standard-with-typescript",
|
|
8
|
+
"plugin:import/typescript",
|
|
9
|
+
"plugin:prettier/recommended"
|
|
10
|
+
],
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"project": ["./tsconfig.json", "./tsconfig.eslint.json"]
|
|
13
|
+
},
|
|
14
|
+
"rules": {
|
|
15
|
+
"@typescript-eslint/strict-boolean-expressions": "off",
|
|
16
|
+
"@typescript-eslint/prefer-nullish-coalescing": "off",
|
|
17
|
+
"import/order": [
|
|
18
|
+
"error",
|
|
19
|
+
{
|
|
20
|
+
"groups": [
|
|
21
|
+
"builtin",
|
|
22
|
+
"external",
|
|
23
|
+
"internal",
|
|
24
|
+
"parent",
|
|
25
|
+
"sibling",
|
|
26
|
+
"index"
|
|
27
|
+
],
|
|
28
|
+
"pathGroups": [
|
|
29
|
+
{
|
|
30
|
+
"pattern": "@chains",
|
|
31
|
+
"group": "internal"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"pattern": "@chains/**",
|
|
35
|
+
"group": "internal"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"pattern": "@utils",
|
|
39
|
+
"group": "internal"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"pattern": "@utils/**",
|
|
43
|
+
"group": "internal"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"pathGroupsExcludedImportTypes": ["builtin"],
|
|
47
|
+
"newlines-between": "always",
|
|
48
|
+
"alphabetize": {
|
|
49
|
+
"order": "asc",
|
|
50
|
+
"caseInsensitive": true
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
}
|
package/.prettierrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "singleQuote": true, "trailingComma": "es5", "semi": false }
|
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -28,38 +28,66 @@ pnpm add signet.js
|
|
|
28
28
|
## Quick Example
|
|
29
29
|
|
|
30
30
|
```ts twoslash
|
|
31
|
-
import { EVM,
|
|
31
|
+
import { EVM, utils } from 'signet.js'
|
|
32
|
+
import { KeyPair, type KeyPairString } from '@near-js/crypto'
|
|
32
33
|
|
|
33
|
-
// Initialize
|
|
34
|
-
const
|
|
34
|
+
// Initialize NEAR connection with credentials from environment
|
|
35
|
+
const accountId = process.env.NEAR_ACCOUNT_ID
|
|
36
|
+
const privateKey = process.env.NEAR_PRIVATE_KEY as KeyPairString
|
|
37
|
+
|
|
38
|
+
if (!accountId || !privateKey) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
'NEAR_ACCOUNT_ID and NEAR_PRIVATE_KEY must be set in environment'
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const keypair = KeyPair.fromString(privateKey)
|
|
45
|
+
|
|
46
|
+
const contract = new utils.chains.near.ChainSignatureContract({
|
|
35
47
|
networkId: 'testnet',
|
|
36
|
-
contractId: '
|
|
48
|
+
contractId: 'v1.signer-prod.testnet',
|
|
49
|
+
accountId,
|
|
50
|
+
keypair,
|
|
37
51
|
})
|
|
38
52
|
|
|
39
|
-
|
|
40
|
-
const chain = new EVM({
|
|
53
|
+
const evmChain = new EVM({
|
|
41
54
|
rpcUrl: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID',
|
|
42
55
|
contract,
|
|
43
56
|
})
|
|
44
57
|
|
|
45
|
-
//
|
|
46
|
-
const {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
// Derive address and public key
|
|
59
|
+
const { address, publicKey } = await evmChain.deriveAddressAndPublicKey(
|
|
60
|
+
accountId,
|
|
61
|
+
'any_string'
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
// Check balance
|
|
65
|
+
const balance = await evmChain.getBalance(address)
|
|
50
66
|
|
|
67
|
+
// Create and sign transaction
|
|
68
|
+
const { transaction, mpcPayloads } = await evmChain.getMPCPayloadAndTransaction(
|
|
69
|
+
{
|
|
70
|
+
from: '0x...',
|
|
71
|
+
to: '0x...',
|
|
72
|
+
value: '1000000000000000000',
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
// Sign with MPC
|
|
51
77
|
const signature = await contract.sign({
|
|
52
78
|
payload: mpcPayloads[0].payload,
|
|
53
79
|
path: 'any_string',
|
|
54
80
|
key_version: 0,
|
|
55
81
|
})
|
|
56
82
|
|
|
57
|
-
|
|
83
|
+
// Add signature
|
|
84
|
+
const signedTx = evmChain.addSignature({
|
|
58
85
|
transaction,
|
|
59
86
|
mpcSignatures: [signature],
|
|
60
87
|
})
|
|
61
88
|
|
|
62
|
-
|
|
89
|
+
// Broadcast transaction
|
|
90
|
+
const txHash = await evmChain.broadcastTx(signedTx)
|
|
63
91
|
```
|
|
64
92
|
|
|
65
93
|
## Documentation
|
|
@@ -72,4 +100,4 @@ For detailed documentation, including:
|
|
|
72
100
|
- Implementation guides
|
|
73
101
|
- API reference
|
|
74
102
|
|
|
75
|
-
Visit our [documentation site](https://
|
|
103
|
+
Visit our [documentation site](https://signet-js.vercel.app/).
|
package/babel.config.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Implementing a Custom Chain Signature Contract
|
|
2
|
+
|
|
3
|
+
This guide explains how to implement a custom Chain Signature Contract to provide as argument when instantiating a Chain instance.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The `ChainSignatureContract` is an abstract class that defines the interface for interacting with the Sig Network infrastructure.
|
|
8
|
+
|
|
9
|
+
- Key Derivation: Derive the child key from the root key using Sig Network key derivation function
|
|
10
|
+
- Sign: Sigs the given payload using Sig Network MPC
|
|
11
|
+
- Current Fee: Gets the current signature deposit that handles network congestion
|
|
12
|
+
|
|
13
|
+
While the library includes a default implementation for the NEAR protocol, you have the flexibility to implement your own contract for other blockchain networks.
|
|
14
|
+
|
|
15
|
+
## Using the NEAR Implementation
|
|
16
|
+
|
|
17
|
+
```ts twoslash
|
|
18
|
+
// [!include ~/snippets/env.ts]
|
|
19
|
+
// ---cut---
|
|
20
|
+
import { utils, EVM } from 'signet.js'
|
|
21
|
+
|
|
22
|
+
const contract = new utils.chains.near.ChainSignatureContract({
|
|
23
|
+
networkId: 'testnet',
|
|
24
|
+
contractId: 'v1.signer-prod.testnet',
|
|
25
|
+
accountId,
|
|
26
|
+
keypair,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const evmChain = new EVM({
|
|
30
|
+
rpcUrl: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID',
|
|
31
|
+
contract,
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Currently the contracts are available on the following Near addresses:
|
|
36
|
+
|
|
37
|
+
- Mainnet:
|
|
38
|
+
- `v1.signer`
|
|
39
|
+
- Testnet:
|
|
40
|
+
- `v1.signer-prod.testnet`
|
|
41
|
+
|
|
42
|
+
## Implementing a Custom Chain Signature Contract
|
|
43
|
+
|
|
44
|
+
To create your own implementation, your contract must implement the `ChainSignatureContract` interface.
|
|
45
|
+
|
|
46
|
+
```ts twoslash
|
|
47
|
+
// [!include ~/../src/chains/ChainSignatureContract.ts]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Example: NEAR Implementation
|
|
51
|
+
|
|
52
|
+
Below is the reference implementation for the NEAR, which you can use as a guide for implementing your own chain signature contract:
|
|
53
|
+
|
|
54
|
+
```ts twoslash
|
|
55
|
+
// [!include ~/../src/utils/chains/near/ChainSignatureContract.ts]
|
|
56
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Chain
|
|
2
|
+
|
|
3
|
+
Chain is the most basic interface of the signet.js library. It provides a standard set of methods that all chains must implement.
|
|
4
|
+
|
|
5
|
+
With this interface you will be able to interact with Sig Network smart contracts in a standard way to:
|
|
6
|
+
|
|
7
|
+
- getBalance
|
|
8
|
+
- deriveAddressAndPublicKey
|
|
9
|
+
- setTransaction
|
|
10
|
+
- getTransaction
|
|
11
|
+
- getMPCPayloadAndTransaction
|
|
12
|
+
- addSignature
|
|
13
|
+
- broadcastTx
|
|
14
|
+
|
|
15
|
+
If you wanna have a look this is the chain interface with a brief description of each method:
|
|
16
|
+
|
|
17
|
+
```ts twoslash
|
|
18
|
+
// [!include ~/../src/chains/Chain.ts]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
# Implementing a New Chain
|
|
22
|
+
|
|
23
|
+
This guide explains how to implement support for a new blockchain network in the signet.js library.
|
|
24
|
+
|
|
25
|
+
## Overview
|
|
26
|
+
|
|
27
|
+
To add support for a new blockchain, you need to implement the `Chain` interface:
|
|
28
|
+
|
|
29
|
+
## Step-by-Step Guide
|
|
30
|
+
|
|
31
|
+
### 1. Create the Chain Types
|
|
32
|
+
|
|
33
|
+
First, define the transaction types for your chain:
|
|
34
|
+
|
|
35
|
+
```ts twoslash
|
|
36
|
+
// [!include ~/../src/chains/EVM/types.ts]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 2. Implement the Chain Interface
|
|
40
|
+
|
|
41
|
+
Create a new class that implements the `Chain` interface:
|
|
42
|
+
|
|
43
|
+
```ts twoslash
|
|
44
|
+
// [!include ~/../src/chains/EVM/EVM.ts]
|
|
45
|
+
```
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Bitcoin Chain Implementation
|
|
2
|
+
|
|
3
|
+
The Bitcoin chain implementation supports both Bitcoin mainnet and testnet networks, with a focus on P2WPKH (Native SegWit) transactions.
|
|
4
|
+
|
|
5
|
+
## Configuration
|
|
6
|
+
|
|
7
|
+
```ts twoslash filename="base.ts"
|
|
8
|
+
// [!include ~/snippets/contract.ts]
|
|
9
|
+
// ---cut---
|
|
10
|
+
import { Bitcoin, BTCRpcAdapters } from 'signet.js'
|
|
11
|
+
|
|
12
|
+
// Initialize the RPC adapter using Mempool
|
|
13
|
+
const btcRpcAdapter = new BTCRpcAdapters.Mempool('https://mempool.space/api')
|
|
14
|
+
|
|
15
|
+
// Initialize the chain
|
|
16
|
+
const bitcoinChain = new Bitcoin({
|
|
17
|
+
network: 'testnet', // 'mainnet' | 'testnet' | 'regtest'
|
|
18
|
+
contract,
|
|
19
|
+
btcRpcAdapter,
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## RPC Adapter
|
|
24
|
+
|
|
25
|
+
The RPC adapter is a class that provides an interface for interacting with the Bitcoin network. It handles essential operations such as:
|
|
26
|
+
|
|
27
|
+
- Fetching UTXOs (Unspent Transaction Outputs)
|
|
28
|
+
- Retrieving transaction details
|
|
29
|
+
- Getting current network fees
|
|
30
|
+
- Broadcasting transactions
|
|
31
|
+
- Querying address balances
|
|
32
|
+
|
|
33
|
+
The adapter abstracts away the complexity of different Bitcoin API providers, allowing you to easily switch between services like Mempool.space, BlockCypher, or your own Bitcoin node.
|
|
34
|
+
|
|
35
|
+
For detailed implementation and configuration options, see the [RPC Adapter](./btc-rpc-adapter) documentation.
|
|
36
|
+
|
|
37
|
+
## Methods
|
|
38
|
+
|
|
39
|
+
### getBalance
|
|
40
|
+
|
|
41
|
+
Gets the BTC balance of an address.
|
|
42
|
+
|
|
43
|
+
```ts twoslash
|
|
44
|
+
// [!include base.ts]
|
|
45
|
+
// ---cut---
|
|
46
|
+
const balance = await bitcoinChain.getBalance(
|
|
47
|
+
'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh'
|
|
48
|
+
)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Parameters:**
|
|
52
|
+
|
|
53
|
+
- `address`: The Bitcoin address to check
|
|
54
|
+
|
|
55
|
+
**Returns:**
|
|
56
|
+
|
|
57
|
+
- The balance in BTC as a string
|
|
58
|
+
|
|
59
|
+
### deriveAddressAndPublicKey
|
|
60
|
+
|
|
61
|
+
Derives a Bitcoin address and public key for a given path.
|
|
62
|
+
|
|
63
|
+
```ts twoslash
|
|
64
|
+
// [!include base.ts]
|
|
65
|
+
// ---cut---
|
|
66
|
+
const { address, publicKey } = await bitcoinChain.deriveAddressAndPublicKey(
|
|
67
|
+
'predecessor_id',
|
|
68
|
+
'any_string'
|
|
69
|
+
)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Parameters:**
|
|
73
|
+
|
|
74
|
+
- `predecessor`: The ID of the signer to derive from
|
|
75
|
+
- `path`: The derivation path to use
|
|
76
|
+
|
|
77
|
+
**Returns:**
|
|
78
|
+
|
|
79
|
+
- Object containing:
|
|
80
|
+
- `address`: The derived Bitcoin P2WPKH address
|
|
81
|
+
- `publicKey`: The corresponding compressed public key
|
|
82
|
+
|
|
83
|
+
### getMPCPayloadAndTransaction
|
|
84
|
+
|
|
85
|
+
Prepares a transaction for MPC signing.
|
|
86
|
+
|
|
87
|
+
```ts twoslash filename="unsigned-transaction.ts"
|
|
88
|
+
// [!include base.ts]
|
|
89
|
+
// ---cut---
|
|
90
|
+
import { BTCTransactionRequest } from 'signet.js'
|
|
91
|
+
|
|
92
|
+
// Simple transfer format
|
|
93
|
+
const transactionRequest: BTCTransactionRequest = {
|
|
94
|
+
from: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
|
|
95
|
+
to: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
|
|
96
|
+
value: '0.001', // 0.001 BTC
|
|
97
|
+
publicKey: '0235a3...',
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const { transaction: unsignedTransaction, mpcPayloads } =
|
|
101
|
+
await bitcoinChain.getMPCPayloadAndTransaction(transactionRequest)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Parameters:**
|
|
105
|
+
|
|
106
|
+
- `transactionRequest`: Either:
|
|
107
|
+
- Simple format:
|
|
108
|
+
```ts
|
|
109
|
+
{
|
|
110
|
+
from: string // Source address
|
|
111
|
+
to: string // Destination address
|
|
112
|
+
value: string // Amount in BTC
|
|
113
|
+
publicKey: string // Signer's public key
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
- Advanced format (manual UTXO selection):
|
|
117
|
+
```ts
|
|
118
|
+
{
|
|
119
|
+
inputs: BTCInput[] // Selected UTXOs
|
|
120
|
+
outputs: BTCOutput[] // Transaction outputs
|
|
121
|
+
publicKey: string // Signer's public key
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Returns:**
|
|
126
|
+
|
|
127
|
+
- Object containing:
|
|
128
|
+
- `transaction`: The unsigned transaction with PSBT
|
|
129
|
+
- `mpcPayloads`: Array of payloads to be signed
|
|
130
|
+
|
|
131
|
+
### addSignature
|
|
132
|
+
|
|
133
|
+
Adds signatures to a PSBT.
|
|
134
|
+
|
|
135
|
+
```ts twoslash filename="add-signature.ts"
|
|
136
|
+
// [!include unsigned-transaction.ts]
|
|
137
|
+
// ---cut---
|
|
138
|
+
import { RSVSignature } from 'signet.js'
|
|
139
|
+
|
|
140
|
+
// Ideally it would be a request to the Sig Network Smart Contract
|
|
141
|
+
const mpcSignatures: RSVSignature[] = [
|
|
142
|
+
{
|
|
143
|
+
r: '0x...',
|
|
144
|
+
s: '0x...',
|
|
145
|
+
v: 27,
|
|
146
|
+
},
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
const signedTx = bitcoinChain.addSignature({
|
|
150
|
+
transaction: unsignedTransaction,
|
|
151
|
+
mpcSignatures,
|
|
152
|
+
})
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Parameters:**
|
|
156
|
+
|
|
157
|
+
- `transaction`: The unsigned transaction with PSBT
|
|
158
|
+
- `mpcSignatures`: Array of RSV signatures from MPC
|
|
159
|
+
|
|
160
|
+
**Returns:**
|
|
161
|
+
|
|
162
|
+
- The serialized signed transaction in hex format
|
|
163
|
+
|
|
164
|
+
### broadcastTx
|
|
165
|
+
|
|
166
|
+
Broadcasts a signed transaction to the network.
|
|
167
|
+
|
|
168
|
+
```ts twoslash filename="broadcast-tx.ts"
|
|
169
|
+
// [!include add-signature.ts]
|
|
170
|
+
// ---cut---
|
|
171
|
+
const txid = await bitcoinChain.broadcastTx(signedTx)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Parameters:**
|
|
175
|
+
|
|
176
|
+
- `txSerialized`: The serialized transaction in hex format
|
|
177
|
+
|
|
178
|
+
**Returns:**
|
|
179
|
+
|
|
180
|
+
- The transaction ID (txid)
|
|
181
|
+
|
|
182
|
+
## Technical Details
|
|
183
|
+
|
|
184
|
+
The implementation:
|
|
185
|
+
|
|
186
|
+
- Uses `bitcoinjs-lib` for transaction handling
|
|
187
|
+
- Supports P2WPKH (Native SegWit) addresses
|
|
188
|
+
- Handles automatic UTXO selection and change outputs
|
|
189
|
+
- Supports custom fee rates through the RPC adapter
|
|
190
|
+
- Uses PSBT (Partially Signed Bitcoin Transactions)
|
|
191
|
+
- Supports both mainnet and testnet networks
|