signet.js 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/browser/index.browser.cjs +3 -0
  2. package/browser/index.browser.cjs.map +1 -0
  3. package/browser/index.browser.js +3 -0
  4. package/browser/index.browser.js.map +1 -0
  5. package/node/index.node.cjs +3 -0
  6. package/node/index.node.cjs.map +1 -0
  7. package/node/index.node.js +3 -0
  8. package/node/index.node.js.map +1 -0
  9. package/package.json +2 -2
  10. package/types/index.d.cts +919 -0
  11. package/types/index.d.ts +919 -0
  12. package/.eslintrc.json +0 -55
  13. package/.prettierrc +0 -1
  14. package/babel.config.js +0 -6
  15. package/docs/pages/index.mdx +0 -36
  16. package/docs/pages/signetjs/advanced/chain-signatures-contract.mdx +0 -52
  17. package/docs/pages/signetjs/advanced/chain.mdx +0 -45
  18. package/docs/pages/signetjs/chains/bitcoin/bitcoin.mdx +0 -171
  19. package/docs/pages/signetjs/chains/bitcoin/btc-rpc-adapter.mdx +0 -26
  20. package/docs/pages/signetjs/chains/cosmos.mdx +0 -171
  21. package/docs/pages/signetjs/chains/evm.mdx +0 -319
  22. package/docs/pages/signetjs/contract-addresses.mdx +0 -27
  23. package/docs/pages/signetjs/index.mdx +0 -88
  24. package/docs/snippets/code/contract.ts +0 -21
  25. package/docs/snippets/code/evm/env.ts +0 -16
  26. package/docs/snippets/code/near/env.ts +0 -13
  27. package/hardhat.config.mts +0 -19
  28. package/src/chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter.ts +0 -11
  29. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/Mempool.ts +0 -96
  30. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/index.ts +0 -1
  31. package/src/chains/Bitcoin/BTCRpcAdapter/Mempool/types.ts +0 -72
  32. package/src/chains/Bitcoin/BTCRpcAdapter/index.ts +0 -6
  33. package/src/chains/Bitcoin/Bitcoin.ts +0 -287
  34. package/src/chains/Bitcoin/types.ts +0 -48
  35. package/src/chains/Bitcoin/utils.ts +0 -14
  36. package/src/chains/Chain.ts +0 -92
  37. package/src/chains/ChainSignatureContract.ts +0 -65
  38. package/src/chains/Cosmos/Cosmos.ts +0 -258
  39. package/src/chains/Cosmos/types.ts +0 -35
  40. package/src/chains/Cosmos/utils.ts +0 -45
  41. package/src/chains/EVM/EVM.test.ts +0 -238
  42. package/src/chains/EVM/EVM.ts +0 -334
  43. package/src/chains/EVM/types.ts +0 -53
  44. package/src/chains/EVM/utils.ts +0 -27
  45. package/src/chains/index.ts +0 -38
  46. package/src/chains/types.ts +0 -46
  47. package/src/index.ts +0 -2
  48. package/src/utils/chains/evm/ChainSignaturesContract.ts +0 -286
  49. package/src/utils/chains/evm/ChainSignaturesContractABI.ts +0 -359
  50. package/src/utils/chains/evm/errors.ts +0 -52
  51. package/src/utils/chains/evm/index.ts +0 -3
  52. package/src/utils/chains/evm/types.ts +0 -28
  53. package/src/utils/chains/evm/utils.ts +0 -11
  54. package/src/utils/chains/index.ts +0 -2
  55. package/src/utils/chains/near/ChainSignatureContract.ts +0 -155
  56. package/src/utils/chains/near/account.ts +0 -42
  57. package/src/utils/chains/near/constants.ts +0 -4
  58. package/src/utils/chains/near/index.ts +0 -3
  59. package/src/utils/chains/near/signAndSend/index.ts +0 -1
  60. package/src/utils/chains/near/signAndSend/keypair.ts +0 -178
  61. package/src/utils/chains/near/transactionBuilder.ts +0 -73
  62. package/src/utils/chains/near/types.ts +0 -77
  63. package/src/utils/constants.ts +0 -62
  64. package/src/utils/cryptography.ts +0 -131
  65. package/src/utils/index.ts +0 -3
  66. package/src/utils/publicKey.ts +0 -23
  67. package/tsconfig.eslint.json +0 -8
  68. package/tsconfig.json +0 -122
  69. package/tsup.config.ts +0 -55
  70. package/vitest.config.ts +0 -16
  71. package/vocs.config.ts +0 -73
@@ -1,319 +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/code/contract.ts]
9
- // ---cut---
10
- import { EVM } from 'signet.js'
11
-
12
- // Initialize the chain
13
- const chain = 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 the chain's base units.
24
-
25
- ```ts twoslash
26
- // [!include base.ts]
27
- // ---cut---
28
- const { balance, decimals } = await chain.getBalance('0x...')
29
- ```
30
-
31
- **Parameters:**
32
-
33
- - `address`: The EVM address to check
34
-
35
- **Returns:**
36
-
37
- - The balance in the chain's base units as a bigint
38
- - The number of decimals used to format the balance
39
-
40
- ### deriveAddressAndPublicKey
41
-
42
- Derives an EVM address and public key from a predecessor ID and derivation path.
43
-
44
- ```ts twoslash
45
- // [!include base.ts]
46
- // ---cut---
47
- const { address, publicKey } = await chain.deriveAddressAndPublicKey(
48
- '0x...',
49
- 'any_string'
50
- )
51
- ```
52
-
53
- **Parameters:**
54
-
55
- - `predecessor`: The wallet/contract address requesting the signature
56
- - `path`: The derivation path to use
57
-
58
- **Returns:**
59
-
60
- - Object containing:
61
- - `address`: The derived EVM address
62
- - `publicKey`: The corresponding public key in SEC1 uncompressed format
63
-
64
- ### prepareTransactionForSigning
65
-
66
- Prepares a transaction for MPC signing.
67
-
68
- ```ts twoslash filename="unsigned-transaction.ts"
69
- // [!include base.ts]
70
- // ---cut---
71
- import { EVMTransactionRequest } from 'signet.js'
72
-
73
- const transactionRequest: EVMTransactionRequest = {
74
- to: '0x...',
75
- from: '0x...',
76
- value: 100000000000000000n,
77
- data: '0x...',
78
- }
79
-
80
- const { transaction: unsignedTransaction, hashesToSign } =
81
- await chain.prepareTransactionForSigning(transactionRequest)
82
- ```
83
-
84
- The transaction is enhanced with:
85
-
86
- - Gas estimation
87
- - Nonce calculation
88
- - Chain ID
89
- - EIP-1559 fee parameters
90
-
91
- ### attachTransactionSignature
92
-
93
- Adds a signature to an unsigned transaction.
94
-
95
- ```ts twoslash
96
- // [!include unsigned-transaction.ts]
97
- // ---cut---
98
- import { RSVSignature } from 'signet.js'
99
-
100
- // Ideally it would be a request to the Sig Network Smart Contract
101
- const rsvSignatures: RSVSignature[] = [
102
- {
103
- r: '0x...',
104
- s: '0x...',
105
- v: 27,
106
- },
107
- ]
108
-
109
- const txSerialized = await chain.attachTransactionSignature({
110
- transaction: unsignedTransaction,
111
- rsvSignatures,
112
- })
113
- ```
114
-
115
- **Parameters:**
116
-
117
- - `transaction`: The unsigned transaction
118
- - `rsvSignatures`: Array of RSV signatures from MPC
119
-
120
- **Returns:**
121
-
122
- - The serialized signed transaction
123
-
124
- ### broadcastTx
125
-
126
- Broadcasts a signed transaction to the network.
127
-
128
- ```ts twoslash
129
- // [!include base.ts]
130
- // ---cut---
131
- const txHash = await chain.broadcastTx('0x...transactionSerialized')
132
- ```
133
-
134
- **Parameters:**
135
-
136
- - `txSerialized`: The serialized signed transaction
137
-
138
- **Returns:**
139
-
140
- - The transaction hash
141
-
142
- ### prepareMessageForSigning
143
-
144
- Prepares a message for MPC signing according to EIP-191.
145
-
146
- ```ts twoslash filename="message-signing.ts"
147
- // [!include base.ts]
148
- // ---cut---
149
- import { EVMMessage } from 'signet.js'
150
-
151
- const message: EVMMessage = 'Sign this message'
152
-
153
- const { hashesToSign } = await chain.prepareMessageForSigning(message)
154
- ```
155
-
156
- **Parameters:**
157
-
158
- - `message`: The message to be signed
159
-
160
- **Returns:**
161
-
162
- - Object containing:
163
-
164
- - `hashesToSign`: Array of payloads for MPC signing
165
-
166
- ### assembleMessageSignature
167
-
168
- Adds a signature to a message.
169
-
170
- ```ts twoslash
171
- // [!include message-signing.ts]
172
- // ---cut---
173
- import { RSVSignature } from 'signet.js'
174
-
175
- // Ideally it would be a request to the Sig Network Smart Contract
176
- const rsvSignatures: RSVSignature[] = [
177
- {
178
- r: '0x...',
179
- s: '0x...',
180
- v: 27,
181
- },
182
- ]
183
-
184
- const signature = chain.assembleMessageSignature({
185
- rsvSignatures,
186
- })
187
- ```
188
-
189
- **Parameters:**
190
-
191
- - `rsvSignatures`: Array of RSV signatures from MPC
192
-
193
- **Returns:**
194
-
195
- - The signature in hex format
196
-
197
- ### prepareTypedDataForSigning
198
-
199
- Prepares EIP-712 typed data for MPC signing.
200
-
201
- ```ts twoslash filename="typed-data-signing.ts"
202
- // [!include base.ts]
203
- // ---cut---
204
- import { EVMTypedData } from 'signet.js'
205
-
206
- const typedData: EVMTypedData = {
207
- domain: {
208
- name: 'Test',
209
- version: '1',
210
- chainId: 1,
211
- verifyingContract: '0x1234567890123456789012345678901234567890',
212
- },
213
- types: {
214
- Person: [
215
- { name: 'name', type: 'string' },
216
- { name: 'wallet', type: 'address' },
217
- ],
218
- },
219
- primaryType: 'Person',
220
- message: {
221
- name: 'Bob',
222
- wallet: '0x1234567890123456789012345678901234567890',
223
- },
224
- }
225
-
226
- const { hashesToSign } = await chain.prepareTypedDataForSigning(typedData)
227
- ```
228
-
229
- **Parameters:**
230
-
231
- - `typedData`: The EIP-712 typed data object to be signed
232
-
233
- **Returns:**
234
-
235
- - Object containing:
236
- - `hashesToSign`: Array of payloads for MPC signing
237
-
238
- ### assembleTypedDataSignature
239
-
240
- Adds a signature to typed data.
241
-
242
- ```ts twoslash
243
- // [!include typed-data-signing.ts]
244
- // ---cut---
245
- import { RSVSignature } from 'signet.js'
246
-
247
- // Ideally it would be a request to the Sig Network Smart Contract
248
- const rsvSignatures: RSVSignature[] = [
249
- {
250
- r: '0x...',
251
- s: '0x...',
252
- v: 27,
253
- },
254
- ]
255
-
256
- const signature = chain.assembleTypedDataSignature({
257
- rsvSignatures,
258
- })
259
- ```
260
-
261
- **Parameters:**
262
-
263
- - `rsvSignatures`: Array of RSV signatures from MPC
264
-
265
- **Returns:**
266
-
267
- - The signature in hex format
268
-
269
- ## Adding New EVM Chains
270
-
271
- 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.
272
-
273
- ```ts twoslash
274
- // [!include ~/snippets/code/contract.ts]
275
- // ---cut---
276
- import { EVM } from 'signet.js'
277
-
278
- // For Polygon (Matic)
279
- const polygonChain = new EVM({
280
- rpcUrl: 'https://polygon-rpc.com',
281
- contract,
282
- })
283
-
284
- // For Binance Smart Chain
285
- const bscChain = new EVM({
286
- rpcUrl: 'https://bsc-dataseed.binance.org',
287
- contract,
288
- })
289
-
290
- // For Arbitrum
291
- const arbitrumChain = new EVM({
292
- rpcUrl: 'https://arb1.arbitrum.io/rpc',
293
- contract,
294
- })
295
- ```
296
-
297
- ## Types
298
-
299
- The following types are used on the EVM chain:
300
-
301
- ```ts twoslash
302
- // [!include ~/../src/chains/EVM/types.ts]
303
- ```
304
-
305
- ## Technical Details
306
-
307
- The implementation:
308
-
309
- - Uses `viem` for transaction handling and RPC communication
310
- - Supports both legacy and EIP-1559 transactions
311
- - Handles automatic nonce management
312
- - Supports contract interactions through ABI encoding
313
- - Provides automatic gas estimation and fee calculation
314
- - Compatible with all EVM-based networks
315
- - Supports ENS name resolution on networks that implement it
316
- - Handles transaction signing according to EIP-155
317
- - Supports raw transaction data for custom contract interactions
318
- - Supports EIP-191 personal message signing
319
- - Supports EIP-712 typed data signing
@@ -1,27 +0,0 @@
1
- # Contract Addresses
2
-
3
- All the necessary constants to interact with the Sig Network are exported from the `constants.ts` file.
4
-
5
- ## Using the Constants in your code
6
-
7
- You can import and use them in your code as follows:
8
-
9
- ```ts twoslash
10
- import { utils } from 'signet.js'
11
-
12
- const evmTestnetAddress = utils.constants.CONTRACT_ADDRESSES.ETHEREUM.TESTNET
13
-
14
- console.log(evmTestnetAddress) // '0x83458E8Bf8206131Fe5c05127007FA164c0948A2'
15
-
16
- const testnetPublicKey = utils.constants.ROOT_PUBLIC_KEYS.TESTNET
17
-
18
- console.log(testnetPublicKey) // 'secp256k1:3Ww8iFjqTHufye5aRGUvrQqETegR4gVUcW8FX5xzscaN9ENhpkffojsxJwi6N1RbbHMTxYa9UyKeqK3fsMuwxjR5'
19
- ```
20
-
21
- ## Constants file
22
-
23
- For reference, here is the file with the full list of constants and their explanations:
24
-
25
- ```ts twoslash
26
- // [!include ~/../src/utils/constants.ts]
27
- ```
@@ -1,88 +0,0 @@
1
- # Quick Start
2
-
3
- ## Installation
4
-
5
- ```bash
6
- npm install signet.js
7
- # or
8
- yarn add signet.js
9
- # or
10
- pnpm add signet.js
11
- ```
12
-
13
- ## Signing a Transaction
14
-
15
- Here's a basic example using the EVM implementation:
16
-
17
- ```ts twoslash
18
- import { utils, EVM } from 'signet.js'
19
- // [!include ~/snippets/code/evm/env.ts]
20
-
21
- const chainSigContract = new utils.chains.evm.ChainSignatureContract({
22
- publicClient,
23
- walletClient,
24
- contractAddress: utils.constants.CONTRACT_ADDRESSES.ETHEREUM
25
- .TESTNET_DEV as `0x${string}`,
26
- })
27
-
28
- const evm = new EVM({
29
- rpcUrl: 'https://sepolia.infura.io/v3/YOUR-PROJECT-ID',
30
- contract: chainSigContract,
31
- })
32
-
33
- const path = 'eth' // The path is an arbitrary string, it can be anything, each path will map to a different address/key
34
- const predecessorId = walletClient.account.address // The predecessor ID is your wallet/contract address that will call the ChainSignatureContract
35
-
36
- const { address: from, publicKey } = await evm.deriveAddressAndPublicKey(
37
- predecessorId,
38
- path
39
- )
40
-
41
- const { balance, decimals } = await evm.getBalance(from)
42
-
43
- const { transaction, hashesToSign } = await evm.prepareTransactionForSigning({
44
- from: from as `0x${string}`,
45
- to: '0x4174678c78fEaFd778c1ff319D5D326701449b25',
46
- value: 1n, // Amount in wei (1 wei in this example)
47
- })
48
-
49
- const rsvSignature = await chainSigContract?.sign({
50
- payload: hashesToSign[0],
51
- path,
52
- key_version: 0, // The version of the key to use (usually 0)
53
- })
54
-
55
- const tx = evm.attachTransactionSignature({
56
- transaction,
57
- rsvSignatures: [rsvSignature],
58
- })
59
-
60
- const txHash = await evm.broadcastTx(tx)
61
- ```
62
-
63
- ## Supported Chains
64
-
65
- - [EVM Chains](/signetjs/chains/evm.mdx) - Ethereum and compatible networks
66
- - [Bitcoin](/signetjs/chains/bitcoin/bitcoin.mdx) - Bitcoin network
67
- - [Cosmos Chains](/signetjs/chains/cosmos.mdx) - Cosmos SDK-based networks
68
-
69
- ## Architecture
70
-
71
- 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.
72
-
73
- For more details check the [Chain](/signetjs/advanced/chain.mdx) page.
74
-
75
- ## Utility Functions
76
-
77
- Besides the Chain classes the library also provide utility functions to assist you on building transactions, requesting signature in wrapped methods.
78
-
79
- Currently we support:
80
-
81
- - Near
82
- - EVM
83
-
84
- ## Repositories
85
-
86
- - Signet.js: [https://github.com/sig-net/signet.js](https://github.com/sig-net/signet.js).
87
- - Examples: [https://github.com/sig-net/signet-examples](https://github.com/sig-net/signet-examples).
88
- - 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
- })
@@ -1,16 +0,0 @@
1
- import { createPublicClient, createWalletClient, http } from 'viem'
2
- import { privateKeyToAccount } from 'viem/accounts'
3
- import { sepolia } from 'viem/chains'
4
-
5
- const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
6
-
7
- const publicClient = createPublicClient({
8
- chain: sepolia,
9
- transport: http(),
10
- })
11
-
12
- const walletClient = createWalletClient({
13
- account,
14
- chain: sepolia,
15
- transport: http(),
16
- })
@@ -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)
@@ -1,19 +0,0 @@
1
- import '@nomicfoundation/hardhat-toolbox'
2
-
3
- const config = {
4
- solidity: '0.8.24',
5
- networks: {
6
- hardhat: {
7
- mining: {
8
- auto: true,
9
- interval: 1000,
10
- },
11
- },
12
- localhost: {
13
- url: 'http://127.0.0.1:8545',
14
- chainId: 31337,
15
- },
16
- },
17
- }
18
-
19
- export default config
@@ -1,11 +0,0 @@
1
- import type { BTCTransaction, BTCInput, BTCOutput } from '@chains/Bitcoin/types'
2
-
3
- export abstract class BTCRpcAdapter {
4
- abstract selectUTXOs(
5
- from: string,
6
- targets: BTCOutput[]
7
- ): Promise<{ inputs: BTCInput[]; outputs: BTCOutput[] }>
8
- abstract broadcastTransaction(transactionHex: string): Promise<string>
9
- abstract getBalance(address: string): Promise<number>
10
- abstract getTransaction(txid: string): Promise<BTCTransaction>
11
- }
@@ -1,96 +0,0 @@
1
- // There is no types for coinselect
2
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3
- // @ts-expect-error
4
- import coinselect from 'coinselect'
5
-
6
- import { BTCRpcAdapter } from '@chains/Bitcoin/BTCRpcAdapter/BTCRpcAdapter'
7
- import {
8
- type BTCFeeRecommendation,
9
- type UTXO,
10
- } from '@chains/Bitcoin/BTCRpcAdapter/Mempool/types'
11
- import type { BTCTransaction, BTCInput, BTCOutput } from '@chains/Bitcoin/types'
12
-
13
- export class Mempool extends BTCRpcAdapter {
14
- private readonly providerUrl: string
15
-
16
- constructor(providerUrl: string) {
17
- super()
18
- this.providerUrl = providerUrl
19
- }
20
-
21
- private async fetchFeeRate(confirmationTarget = 6): Promise<number> {
22
- const response = await fetch(`${this.providerUrl}/v1/fees/recommended`)
23
- const data = (await response.json()) as BTCFeeRecommendation
24
-
25
- if (confirmationTarget <= 1) {
26
- return data.fastestFee
27
- } else if (confirmationTarget <= 3) {
28
- return data.halfHourFee
29
- } else if (confirmationTarget <= 6) {
30
- return data.hourFee
31
- } else {
32
- return data.economyFee
33
- }
34
- }
35
-
36
- private async fetchUTXOs(address: string): Promise<UTXO[]> {
37
- try {
38
- const response = await fetch(
39
- `${this.providerUrl}/address/${address}/utxo`
40
- )
41
- return (await response.json()) as UTXO[]
42
- } catch (error) {
43
- console.error('Failed to fetch UTXOs:', error)
44
- return []
45
- }
46
- }
47
-
48
- async selectUTXOs(
49
- from: string,
50
- targets: BTCOutput[],
51
- confirmationTarget = 6
52
- ): Promise<{ inputs: BTCInput[]; outputs: BTCOutput[] }> {
53
- const utxos = await this.fetchUTXOs(from)
54
- const feeRate = await this.fetchFeeRate(confirmationTarget)
55
-
56
- // Add a small amount to the fee rate to ensure the transaction is confirmed
57
- const ret = coinselect(utxos, targets, Math.ceil(feeRate + 1))
58
-
59
- if (!ret.inputs || !ret.outputs) {
60
- throw new Error(
61
- 'Invalid transaction: coinselect failed to find a suitable set of inputs and outputs. This could be due to insufficient funds, or no inputs being available that meet the criteria.'
62
- )
63
- }
64
-
65
- return {
66
- inputs: ret.inputs,
67
- outputs: ret.outputs,
68
- }
69
- }
70
-
71
- async broadcastTransaction(transactionHex: string): Promise<string> {
72
- const response = await fetch(`${this.providerUrl}/tx`, {
73
- method: 'POST',
74
- body: transactionHex,
75
- })
76
-
77
- if (response.ok) {
78
- return await response.text()
79
- }
80
-
81
- throw new Error(`Failed to broadcast transaction: ${await response.text()}`)
82
- }
83
-
84
- async getBalance(address: string): Promise<number> {
85
- const response = await fetch(`${this.providerUrl}/address/${address}`)
86
- const data = (await response.json()) as {
87
- chain_stats: { funded_txo_sum: number; spent_txo_sum: number }
88
- }
89
- return data.chain_stats.funded_txo_sum - data.chain_stats.spent_txo_sum
90
- }
91
-
92
- async getTransaction(txid: string): Promise<BTCTransaction> {
93
- const response = await fetch(`${this.providerUrl}/tx/${txid}`)
94
- return (await response.json()) as BTCTransaction
95
- }
96
- }
@@ -1 +0,0 @@
1
- export { Mempool } from './Mempool'
@@ -1,72 +0,0 @@
1
- export interface BTCFeeRecommendation {
2
- fastestFee: number
3
- halfHourFee: number
4
- hourFee: number
5
- economyFee: number
6
- minimumFee: number
7
- }
8
-
9
- interface BTCAddressStats {
10
- funded_txo_count: number
11
- funded_txo_sum: number
12
- spent_txo_count: number
13
- spent_txo_sum: number
14
- tx_count: number
15
- }
16
-
17
- export interface BTCAddressInfo {
18
- address: string
19
- chain_stats: BTCAddressStats
20
- mempool_stats: BTCAddressStats
21
- }
22
-
23
- export interface Transaction {
24
- txid: string
25
- version: number
26
- locktime: number
27
- vin: Array<{
28
- txid: string
29
- vout: number
30
- prevout: {
31
- scriptpubkey: string
32
- scriptpubkey_asm: string
33
- scriptpubkey_type: string
34
- scriptpubkey_address: string
35
- value: number
36
- }
37
- scriptsig: string
38
- scriptsig_asm: string
39
- witness: string[]
40
- is_coinbase: boolean
41
- sequence: number
42
- }>
43
- vout: Array<{
44
- scriptpubkey: string
45
- scriptpubkey_asm: string
46
- scriptpubkey_type: string
47
- scriptpubkey_address: string
48
- value: number
49
- }>
50
- size: number
51
- weight: number
52
- sigops?: number
53
- fee: number
54
- status: {
55
- confirmed: boolean
56
- block_height: number
57
- block_hash: string
58
- block_time: number
59
- }
60
- }
61
-
62
- export interface UTXO {
63
- txid: string
64
- vout: number
65
- status: {
66
- confirmed: boolean
67
- block_height: number
68
- block_hash: string
69
- block_time: number
70
- }
71
- value: number
72
- }
@@ -1,6 +0,0 @@
1
- import { Mempool } from './Mempool'
2
- export { BTCRpcAdapter } from './BTCRpcAdapter'
3
-
4
- export const BTCRpcAdapters = {
5
- Mempool,
6
- }