signet.js 0.0.3 → 0.0.5
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 +1 -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 +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
package/.eslintrc.json
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{ "singleQuote": true, "trailingComma": "es5", "semi": false }
|
package/babel.config.js
DELETED
package/docs/pages/index.mdx
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
## Introduction
|
|
2
|
-
|
|
3
|
-
Managing multiple accounts across different blockchains is a headache. Every chain has its own wallets, private keys, and authentication systems, making cross-chain interactions complex and fragmented. But what if a single abstract account could seamlessly control multiple accounts across different chains—without compromising security? That's now possible through Chain Signatures.
|
|
4
|
-
|
|
5
|
-
### What Are Chain Signatures?
|
|
6
|
-
|
|
7
|
-
Chain Signatures are programmable digital signatures that enable cross-chain control, allowing one account on one blockchain to securely manage accounts and assets on entirely different chains.
|
|
8
|
-
The system:
|
|
9
|
-
|
|
10
|
-
- **Derives keys** from a single base key.
|
|
11
|
-
- Allows third parties (e.g., dApps, wallets, or protocols) to **request signatures** on-chain.
|
|
12
|
-
- Introduces **flexible usage controls**, such as daily spending limits or rate limits, by combining these keys with custom on-chain logic.
|
|
13
|
-
|
|
14
|
-
### Benefits & Use Cases:
|
|
15
|
-
|
|
16
|
-
- **One Identity, Many Chains**: Instead of juggling multiple wallets, a single signature from your Ethereum account could authorize actions on any other supported EVM or non-EVM chain, without needing to manage separate private keys.
|
|
17
|
-
- **Seamless Cross-Chain Transactions**: Move assets or execute smart contract functions across different chains, without relying on third-party bridges or centralized custodians.
|
|
18
|
-
- **Usage Controls**: rate or time-based restrictions can be enforced by the on-chain contract that manages key usage (e.g., "this key can only send up to 1 ETH per day").
|
|
19
|
-
- **Recovery or Fallback Conditions**: Instead of storing private keys in a single hardware device, you can use a multi-party computation (MPC) setup that offers user-friendly ways to recover accounts.
|
|
20
|
-
- **Signs the Arbitrary State of a Foreign Chain**: Gives your smart contract awareness of whether a transaction it signed went through so that it can perform actions accordingly. For example, it allows for a smart contract to keep track of local chain assets based on the foreign chain's state.
|
|
21
|
-
|
|
22
|
-
## How It Works?
|
|
23
|
-
|
|
24
|
-
### Contract Background
|
|
25
|
-
|
|
26
|
-
The **ChainSignatures** contract:
|
|
27
|
-
|
|
28
|
-
- Holds a base public key (`publicKey`), expressed in affine coordinates on the secp256k1 curve.
|
|
29
|
-
- Derives new public keys for each `(user, path)` combination by computing an integer `epsilon` (based on a `path` string and user’s address) and performing an EC point addition:
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
DerivedPubKey = BasePubKey + (epsilon × G)
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
- Allows a user to request a signature on a 32-byte payload by calling `sign(...)`. A minimal deposit may be required to discourage spam; any unused deposit is refunded once the request is completed.
|
|
36
|
-
- Awaits the **MPC network** to compute the actual ECDSA signature offline, then call `respond(...)` with that signature. The contract then emits an event with the signature, and refunds the deposit.
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
-
- Root Public Key: Gets the root public key of the Smart Contract on Sig Network MPC
|
|
13
|
-
|
|
14
|
-
While the library includes a default implementation for the NEAR protocol, you have the flexibility to implement your own contract for other blockchain networks.
|
|
15
|
-
|
|
16
|
-
## Using the NEAR Implementation
|
|
17
|
-
|
|
18
|
-
```ts twoslash
|
|
19
|
-
// [!include ~/snippets/code/near/env.ts]
|
|
20
|
-
// ---cut---
|
|
21
|
-
import { utils, EVM } from 'signet.js'
|
|
22
|
-
|
|
23
|
-
const contract = new utils.chains.near.ChainSignatureContract({
|
|
24
|
-
networkId: 'testnet',
|
|
25
|
-
contractId: 'v1.signer-prod.testnet',
|
|
26
|
-
accountId,
|
|
27
|
-
keypair,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
const evmChain = new EVM({
|
|
31
|
-
rpcUrl: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID',
|
|
32
|
-
contract,
|
|
33
|
-
})
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Implementing a Custom Chain Signature Contract
|
|
37
|
-
|
|
38
|
-
To create your own implementation to use on the [Chain](./chain.mdx) Instance, your contract must implement the `BaseChainSignatureContract` interface.
|
|
39
|
-
|
|
40
|
-
In case you need you want all Sig Network Smart Contract capabilities, you can implement the `ChainSignatureContract` interface.
|
|
41
|
-
|
|
42
|
-
```ts twoslash
|
|
43
|
-
// [!include ~/../src/chains/ChainSignatureContract.ts]
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### Example: NEAR Implementation
|
|
47
|
-
|
|
48
|
-
Below is the reference implementation for the NEAR, which you can use as a guide for implementing your own chain signature contract:
|
|
49
|
-
|
|
50
|
-
```ts twoslash
|
|
51
|
-
// [!include ~/../src/utils/chains/near/ChainSignatureContract.ts]
|
|
52
|
-
```
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
- serializeTransaction
|
|
10
|
-
- deserializeTransaction
|
|
11
|
-
- prepareTransactionForSigning
|
|
12
|
-
- attachTransactionSignature
|
|
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
|
-
```
|
|
@@ -1,171 +0,0 @@
|
|
|
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/code/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 chain = 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](/signetjs/chains/bitcoin/btc-rpc-adapter) documentation.
|
|
36
|
-
|
|
37
|
-
## Methods
|
|
38
|
-
|
|
39
|
-
### getBalance
|
|
40
|
-
|
|
41
|
-
Gets the native token balance of an address in the chain's base units.
|
|
42
|
-
|
|
43
|
-
```ts twoslash
|
|
44
|
-
// [!include base.ts]
|
|
45
|
-
// ---cut---
|
|
46
|
-
const { balance, decimals } = await chain.getBalance('bc1qx...')
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
**Parameters:**
|
|
50
|
-
|
|
51
|
-
- `address`: The Bitcoin P2WPKH address to check
|
|
52
|
-
|
|
53
|
-
**Returns:**
|
|
54
|
-
|
|
55
|
-
- The balance in the chain's base units as a bigint
|
|
56
|
-
- The number of decimals used to format the balance
|
|
57
|
-
|
|
58
|
-
### deriveAddressAndPublicKey
|
|
59
|
-
|
|
60
|
-
Derives an Bitcoin address and public key from a predecessor ID and derivation path.
|
|
61
|
-
|
|
62
|
-
```ts twoslash
|
|
63
|
-
// [!include base.ts]
|
|
64
|
-
// ---cut---
|
|
65
|
-
const { address, publicKey } = await chain.deriveAddressAndPublicKey(
|
|
66
|
-
'bc1qx...',
|
|
67
|
-
'any_string'
|
|
68
|
-
)
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
**Parameters:**
|
|
72
|
-
|
|
73
|
-
- `predecessor`: The wallet/contract address requesting the signature
|
|
74
|
-
- `path`: The derivation path to use
|
|
75
|
-
|
|
76
|
-
**Returns:**
|
|
77
|
-
|
|
78
|
-
- Object containing:
|
|
79
|
-
- `address`: The derived Bitcoin P2WPKH address
|
|
80
|
-
- `publicKey`: The corresponding public key in SEC1 uncompressed format
|
|
81
|
-
|
|
82
|
-
### prepareTransactionForSigning
|
|
83
|
-
|
|
84
|
-
Prepares a transaction for MPC signing.
|
|
85
|
-
|
|
86
|
-
```ts twoslash filename="unsigned-transaction.ts"
|
|
87
|
-
// [!include base.ts]
|
|
88
|
-
// ---cut---
|
|
89
|
-
import { BTCTransactionRequest } from 'signet.js'
|
|
90
|
-
|
|
91
|
-
// Simple transfer format
|
|
92
|
-
const transactionRequest: BTCTransactionRequest = {
|
|
93
|
-
from: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
|
|
94
|
-
to: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
|
|
95
|
-
value: '0.001', // 0.001 BTC
|
|
96
|
-
publicKey: '0235a3...',
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const { transaction: unsignedTransaction, hashesToSign } =
|
|
100
|
-
await chain.prepareTransactionForSigning(transactionRequest)
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### attachTransactionSignature
|
|
104
|
-
|
|
105
|
-
Adds signatures to a PSBT.
|
|
106
|
-
|
|
107
|
-
```ts twoslash filename="add-signature.ts"
|
|
108
|
-
// [!include unsigned-transaction.ts]
|
|
109
|
-
// ---cut---
|
|
110
|
-
import { RSVSignature } from 'signet.js'
|
|
111
|
-
|
|
112
|
-
// Ideally it would be a request to the Sig Network Smart Contract
|
|
113
|
-
const rsvSignatures: RSVSignature[] = [
|
|
114
|
-
{
|
|
115
|
-
r: '0x...',
|
|
116
|
-
s: '0x...',
|
|
117
|
-
v: 27,
|
|
118
|
-
},
|
|
119
|
-
]
|
|
120
|
-
|
|
121
|
-
const signedTx = chain.attachTransactionSignature({
|
|
122
|
-
transaction: unsignedTransaction,
|
|
123
|
-
rsvSignatures,
|
|
124
|
-
})
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
**Parameters:**
|
|
128
|
-
|
|
129
|
-
- `transaction`: The unsigned transaction with PSBT
|
|
130
|
-
- `rsvSignatures`: Array of RSV signatures from MPC
|
|
131
|
-
|
|
132
|
-
**Returns:**
|
|
133
|
-
|
|
134
|
-
- The serialized signed transaction in hex format
|
|
135
|
-
|
|
136
|
-
### broadcastTx
|
|
137
|
-
|
|
138
|
-
Broadcasts a signed transaction to the network.
|
|
139
|
-
|
|
140
|
-
```ts twoslash
|
|
141
|
-
// [!include base.ts]
|
|
142
|
-
// ---cut---
|
|
143
|
-
const txHash = await chain.broadcastTx('0x...transactionSerialized')
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
**Parameters:**
|
|
147
|
-
|
|
148
|
-
- `txSerialized`: The serialized signed transaction
|
|
149
|
-
|
|
150
|
-
**Returns:**
|
|
151
|
-
|
|
152
|
-
- The transaction hash
|
|
153
|
-
|
|
154
|
-
## Types
|
|
155
|
-
|
|
156
|
-
The following types are used on the Bitcoin chain:
|
|
157
|
-
|
|
158
|
-
```ts twoslash
|
|
159
|
-
// [!include ~/../src/chains/Bitcoin/types.ts]
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
## Technical Details
|
|
163
|
-
|
|
164
|
-
The implementation:
|
|
165
|
-
|
|
166
|
-
- Uses `bitcoinjs-lib` for transaction handling
|
|
167
|
-
- Supports P2WPKH (Native SegWit) addresses
|
|
168
|
-
- Handles automatic UTXO selection and change outputs
|
|
169
|
-
- Supports custom fee rates through the RPC adapter
|
|
170
|
-
- Uses PSBT (Partially Signed Bitcoin Transactions)
|
|
171
|
-
- Supports both mainnet and testnet networks../../../../snippets/docs/chain/broadcast-tx
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# Implementing a Bitcoin RPC Adapter
|
|
2
|
-
|
|
3
|
-
This guide explains how to implement a custom RPC adapter for interacting with Bitcoin nodes or services.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The `BTCRpcAdapter` provides an abstraction layer for Bitcoin-specific operations like UTXO management, balance queries, and transaction broadcasting. You might want to implement a custom adapter when:
|
|
8
|
-
|
|
9
|
-
- Using a different Bitcoin API provider
|
|
10
|
-
- Implementing specialized UTXO selection strategies
|
|
11
|
-
|
|
12
|
-
## Base Class
|
|
13
|
-
|
|
14
|
-
In order to implement a custom adapter, you need to implement the `BTCRpcAdapter` abstract class:
|
|
15
|
-
|
|
16
|
-
```ts twoslash
|
|
17
|
-
// [!include ~/../src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts]
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
### 2. Example
|
|
21
|
-
|
|
22
|
-
There is an example implementation of the `BTCRpcAdapter` abstract class in the `Mempool` class:
|
|
23
|
-
|
|
24
|
-
```ts twoslash
|
|
25
|
-
// [!include ~/../src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts]
|
|
26
|
-
```
|
|
@@ -1,171 +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/code/contract.ts]
|
|
9
|
-
// ---cut---
|
|
10
|
-
import { Cosmos } from 'signet.js'
|
|
11
|
-
|
|
12
|
-
const chain = 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 in the chain's base units.
|
|
23
|
-
|
|
24
|
-
```ts twoslash
|
|
25
|
-
// [!include base.ts]
|
|
26
|
-
// ---cut---
|
|
27
|
-
const { balance, decimals } = await chain.getBalance('cosmos1...')
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
**Parameters:**
|
|
31
|
-
|
|
32
|
-
- `address`: The Cosmos bech32 address to check
|
|
33
|
-
|
|
34
|
-
**Returns:**
|
|
35
|
-
|
|
36
|
-
- The balance in the chain's base units as a bigint
|
|
37
|
-
- The number of decimals used to format the balance
|
|
38
|
-
|
|
39
|
-
### deriveAddressAndPublicKey
|
|
40
|
-
|
|
41
|
-
Derives an Cosmos bech32 address and public key from a predecessor ID and derivation path.
|
|
42
|
-
|
|
43
|
-
```ts twoslash
|
|
44
|
-
// [!include base.ts]
|
|
45
|
-
// ---cut---
|
|
46
|
-
const { address, publicKey } = await chain.deriveAddressAndPublicKey(
|
|
47
|
-
'cosmos1...',
|
|
48
|
-
'any_string'
|
|
49
|
-
)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
**Parameters:**
|
|
53
|
-
|
|
54
|
-
- `predecessor`: The wallet/contract address requesting the signature
|
|
55
|
-
- `path`: The derivation path to use
|
|
56
|
-
|
|
57
|
-
**Returns:**
|
|
58
|
-
|
|
59
|
-
- Object containing:
|
|
60
|
-
- `address`: The derived Cosmos bech32 address
|
|
61
|
-
- `publicKey`: The corresponding public key in SEC1 uncompressed format
|
|
62
|
-
|
|
63
|
-
### prepareTransactionForSigning
|
|
64
|
-
|
|
65
|
-
Prepares a transaction for MPC signing.
|
|
66
|
-
|
|
67
|
-
```ts twoslash filename="unsigned-transaction.ts"
|
|
68
|
-
// [!include base.ts]
|
|
69
|
-
// ---cut---
|
|
70
|
-
import { CosmosTransactionRequest } from 'signet.js'
|
|
71
|
-
import { MsgSend } from 'cosmjs-types/cosmos/bank/v1beta1/tx'
|
|
72
|
-
|
|
73
|
-
// Create a token transfer message
|
|
74
|
-
const transactionRequest: CosmosTransactionRequest = {
|
|
75
|
-
address: 'cosmos1...',
|
|
76
|
-
publicKey: '0350e8...',
|
|
77
|
-
messages: [
|
|
78
|
-
{
|
|
79
|
-
typeUrl: '/cosmos.bank.v1beta1.MsgSend',
|
|
80
|
-
value: {
|
|
81
|
-
fromAddress: 'cosmos1...',
|
|
82
|
-
toAddress: 'cosmos1...',
|
|
83
|
-
amount: [
|
|
84
|
-
{
|
|
85
|
-
denom: 'uatom',
|
|
86
|
-
amount: '1000000',
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
memo: 'Token transfer',
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const { transaction: unsignedTransaction, hashesToSign } =
|
|
96
|
-
await chain.prepareTransactionForSigning(transactionRequest)
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### attachTransactionSignature
|
|
100
|
-
|
|
101
|
-
Adds signatures to a transaction.
|
|
102
|
-
|
|
103
|
-
```ts twoslash filename="add-signature.ts"
|
|
104
|
-
// [!include unsigned-transaction.ts]
|
|
105
|
-
// ---cut---
|
|
106
|
-
import { RSVSignature } from 'signet.js'
|
|
107
|
-
|
|
108
|
-
// Ideally it would be a request to the Sig Network Smart Contract
|
|
109
|
-
const rsvSignatures: RSVSignature[] = [
|
|
110
|
-
{
|
|
111
|
-
r: '0x...',
|
|
112
|
-
s: '0x...',
|
|
113
|
-
v: 27,
|
|
114
|
-
},
|
|
115
|
-
]
|
|
116
|
-
|
|
117
|
-
const signedTx = chain.attachTransactionSignature({
|
|
118
|
-
transaction: unsignedTransaction,
|
|
119
|
-
rsvSignatures,
|
|
120
|
-
})
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
**Parameters:**
|
|
124
|
-
|
|
125
|
-
- `transaction`: The unsigned transaction
|
|
126
|
-
- `rsvSignatures`: Array of RSV signatures from MPC
|
|
127
|
-
|
|
128
|
-
**Returns:**
|
|
129
|
-
|
|
130
|
-
- The serialized signed transaction in hex format
|
|
131
|
-
|
|
132
|
-
### broadcastTx
|
|
133
|
-
|
|
134
|
-
Broadcasts a signed transaction to the network.
|
|
135
|
-
|
|
136
|
-
```ts twoslash
|
|
137
|
-
// [!include base.ts]
|
|
138
|
-
// ---cut---
|
|
139
|
-
const txHash = await chain.broadcastTx('0x...transactionSerialized')
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
**Parameters:**
|
|
143
|
-
|
|
144
|
-
- `txSerialized`: The serialized signed transaction
|
|
145
|
-
|
|
146
|
-
**Returns:**
|
|
147
|
-
|
|
148
|
-
- The transaction hash
|
|
149
|
-
|
|
150
|
-
## Types
|
|
151
|
-
|
|
152
|
-
The following types are used on the Cosmos chain:
|
|
153
|
-
|
|
154
|
-
```ts twoslash
|
|
155
|
-
// [!include ~/../src/chains/Cosmos/types.ts]
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## Technical Details
|
|
159
|
-
|
|
160
|
-
The implementation:
|
|
161
|
-
|
|
162
|
-
- Uses `@cosmjs/stargate` for transaction handling
|
|
163
|
-
- Supports SIGN_MODE_DIRECT signing
|
|
164
|
-
- Uses Protobuf for message encoding
|
|
165
|
-
- Supports standard Cosmos SDK messages:
|
|
166
|
-
- Bank (Send, MultiSend)
|
|
167
|
-
- Staking (Delegate, Undelegate, Redelegate)
|
|
168
|
-
- Distribution (Withdraw Rewards)
|
|
169
|
-
- IBC (Transfer)
|
|
170
|
-
- Handles automatic fee calculation based on gas prices
|
|
171
|
-
- Supports custom message types through the Registry
|