@bigmi/core 0.3.0-beta.3 → 0.3.0-beta.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 (154) hide show
  1. package/dist/cjs/actions/getBalance.d.ts +1 -1
  2. package/dist/cjs/actions/getBlock.d.ts +1 -1
  3. package/dist/cjs/actions/getBlock.js.map +1 -1
  4. package/dist/cjs/actions/getBlockCount.d.ts +1 -1
  5. package/dist/cjs/actions/getBlockStats.d.ts +1 -1
  6. package/dist/cjs/actions/getUTXOTransaction.d.ts +1 -1
  7. package/dist/cjs/actions/sendUTXOTransaction.d.ts +1 -1
  8. package/dist/cjs/actions/signPsbt.d.ts +1 -1
  9. package/dist/cjs/actions/waitForTransaction.d.ts +1 -1
  10. package/dist/cjs/actions/waitForTransaction.js.map +1 -1
  11. package/dist/cjs/actions/watchBlockNumber.d.ts +1 -1
  12. package/dist/cjs/clients/decorators/public.d.ts +1 -1
  13. package/dist/cjs/clients/decorators/wallet.d.ts +3 -3
  14. package/dist/cjs/clients/decorators/wallet.js.map +1 -1
  15. package/dist/cjs/factories/createClient.d.ts +1 -1
  16. package/dist/cjs/factories/createTransport.d.ts +1 -30
  17. package/dist/cjs/factories/createTransport.js.map +1 -1
  18. package/dist/cjs/transports/ankr/ankr.js +6 -1
  19. package/dist/cjs/transports/ankr/ankr.js.map +1 -1
  20. package/dist/cjs/transports/blockchair/blockchair.js +4 -0
  21. package/dist/cjs/transports/blockchair/blockchair.js.map +1 -1
  22. package/dist/cjs/transports/blockcypher/blockcypher.js +4 -0
  23. package/dist/cjs/transports/blockcypher/blockcypher.js.map +1 -1
  24. package/dist/cjs/transports/custom.d.ts +1 -1
  25. package/dist/cjs/transports/custom.js.map +1 -1
  26. package/dist/cjs/transports/fallback.js +7 -7
  27. package/dist/cjs/transports/fallback.js.map +1 -1
  28. package/dist/cjs/transports/http.d.ts +1 -1
  29. package/dist/cjs/transports/http.js.map +1 -1
  30. package/dist/cjs/transports/mempool/mempool.js +4 -0
  31. package/dist/cjs/transports/mempool/mempool.js.map +1 -1
  32. package/dist/cjs/transports/types.d.ts +1 -1
  33. package/dist/cjs/transports/types.js.map +1 -1
  34. package/dist/cjs/transports/utxo.js +2 -5
  35. package/dist/cjs/transports/utxo.js.map +1 -1
  36. package/dist/cjs/types/request.d.ts +3 -2
  37. package/dist/cjs/types/transport.d.ts +3 -2
  38. package/dist/cjs/utils/getAction.d.ts +1 -1
  39. package/dist/cjs/version.d.ts +1 -1
  40. package/dist/cjs/version.js +1 -1
  41. package/dist/esm/actions/getBalance.d.ts +1 -1
  42. package/dist/esm/actions/getBlock.d.ts +1 -1
  43. package/dist/esm/actions/getBlock.js.map +1 -1
  44. package/dist/esm/actions/getBlockCount.d.ts +1 -1
  45. package/dist/esm/actions/getBlockStats.d.ts +1 -1
  46. package/dist/esm/actions/getUTXOTransaction.d.ts +1 -1
  47. package/dist/esm/actions/sendUTXOTransaction.d.ts +1 -1
  48. package/dist/esm/actions/signPsbt.d.ts +1 -1
  49. package/dist/esm/actions/waitForTransaction.d.ts +1 -1
  50. package/dist/esm/actions/waitForTransaction.js.map +1 -1
  51. package/dist/esm/actions/watchBlockNumber.d.ts +1 -1
  52. package/dist/esm/clients/decorators/public.d.ts +1 -1
  53. package/dist/esm/clients/decorators/wallet.d.ts +3 -3
  54. package/dist/esm/clients/decorators/wallet.js.map +1 -1
  55. package/dist/esm/factories/createClient.d.ts +1 -1
  56. package/dist/esm/factories/createTransport.d.ts +1 -38
  57. package/dist/esm/factories/createTransport.js.map +1 -1
  58. package/dist/esm/transports/ankr/ankr.js +6 -1
  59. package/dist/esm/transports/ankr/ankr.js.map +1 -1
  60. package/dist/esm/transports/blockchair/blockchair.js +4 -0
  61. package/dist/esm/transports/blockchair/blockchair.js.map +1 -1
  62. package/dist/esm/transports/blockcypher/blockcypher.js +4 -0
  63. package/dist/esm/transports/blockcypher/blockcypher.js.map +1 -1
  64. package/dist/esm/transports/custom.d.ts +1 -1
  65. package/dist/esm/transports/custom.js +1 -1
  66. package/dist/esm/transports/custom.js.map +1 -1
  67. package/dist/esm/transports/fallback.js +7 -7
  68. package/dist/esm/transports/fallback.js.map +1 -1
  69. package/dist/esm/transports/http.d.ts +1 -1
  70. package/dist/esm/transports/http.js +1 -1
  71. package/dist/esm/transports/http.js.map +1 -1
  72. package/dist/esm/transports/mempool/mempool.js +4 -0
  73. package/dist/esm/transports/mempool/mempool.js.map +1 -1
  74. package/dist/esm/transports/types.d.ts +1 -1
  75. package/dist/esm/transports/types.js.map +1 -1
  76. package/dist/esm/transports/utxo.js +2 -5
  77. package/dist/esm/transports/utxo.js.map +1 -1
  78. package/dist/esm/types/request.d.ts +3 -2
  79. package/dist/esm/types/transport.d.ts +3 -2
  80. package/dist/esm/utils/getAction.d.ts +1 -1
  81. package/dist/esm/version.d.ts +1 -1
  82. package/dist/esm/version.js +1 -1
  83. package/dist/types/actions/getBalance.d.ts +1 -1
  84. package/dist/types/actions/getBalance.d.ts.map +1 -1
  85. package/dist/types/actions/getBlock.d.ts +1 -1
  86. package/dist/types/actions/getBlock.d.ts.map +1 -1
  87. package/dist/types/actions/getBlockCount.d.ts +1 -1
  88. package/dist/types/actions/getBlockCount.d.ts.map +1 -1
  89. package/dist/types/actions/getBlockStats.d.ts +1 -1
  90. package/dist/types/actions/getBlockStats.d.ts.map +1 -1
  91. package/dist/types/actions/getUTXOTransaction.d.ts +1 -1
  92. package/dist/types/actions/getUTXOTransaction.d.ts.map +1 -1
  93. package/dist/types/actions/sendUTXOTransaction.d.ts +1 -1
  94. package/dist/types/actions/sendUTXOTransaction.d.ts.map +1 -1
  95. package/dist/types/actions/signPsbt.d.ts +1 -1
  96. package/dist/types/actions/signPsbt.d.ts.map +1 -1
  97. package/dist/types/actions/waitForTransaction.d.ts +1 -1
  98. package/dist/types/actions/waitForTransaction.d.ts.map +1 -1
  99. package/dist/types/actions/watchBlockNumber.d.ts +1 -1
  100. package/dist/types/actions/watchBlockNumber.d.ts.map +1 -1
  101. package/dist/types/clients/decorators/public.d.ts +1 -1
  102. package/dist/types/clients/decorators/public.d.ts.map +1 -1
  103. package/dist/types/clients/decorators/wallet.d.ts +3 -3
  104. package/dist/types/clients/decorators/wallet.d.ts.map +1 -1
  105. package/dist/types/factories/createClient.d.ts +1 -1
  106. package/dist/types/factories/createClient.d.ts.map +1 -1
  107. package/dist/types/factories/createTransport.d.ts +1 -38
  108. package/dist/types/factories/createTransport.d.ts.map +1 -1
  109. package/dist/types/transports/ankr/ankr.d.ts.map +1 -1
  110. package/dist/types/transports/blockchair/blockchair.d.ts.map +1 -1
  111. package/dist/types/transports/blockcypher/blockcypher.d.ts.map +1 -1
  112. package/dist/types/transports/custom.d.ts +1 -1
  113. package/dist/types/transports/custom.d.ts.map +1 -1
  114. package/dist/types/transports/http.d.ts +1 -1
  115. package/dist/types/transports/http.d.ts.map +1 -1
  116. package/dist/types/transports/mempool/mempool.d.ts.map +1 -1
  117. package/dist/types/transports/types.d.ts +1 -1
  118. package/dist/types/transports/types.d.ts.map +1 -1
  119. package/dist/types/transports/utxo.d.ts.map +1 -1
  120. package/dist/types/types/request.d.ts +3 -2
  121. package/dist/types/types/request.d.ts.map +1 -1
  122. package/dist/types/types/transport.d.ts +3 -2
  123. package/dist/types/types/transport.d.ts.map +1 -1
  124. package/dist/types/utils/getAction.d.ts +1 -1
  125. package/dist/types/utils/getAction.d.ts.map +1 -1
  126. package/dist/types/version.d.ts +1 -1
  127. package/package.json +1 -1
  128. package/package.json.tmp +1 -1
  129. package/src/actions/getBalance.ts +1 -1
  130. package/src/actions/getBlock.ts +1 -3
  131. package/src/actions/getBlockCount.ts +1 -1
  132. package/src/actions/getBlockStats.ts +1 -1
  133. package/src/actions/getUTXOTransaction.ts +1 -1
  134. package/src/actions/sendUTXOTransaction.ts +1 -1
  135. package/src/actions/signPsbt.ts +1 -1
  136. package/src/actions/waitForTransaction.ts +1 -3
  137. package/src/actions/watchBlockNumber.ts +1 -1
  138. package/src/clients/decorators/public.ts +1 -1
  139. package/src/clients/decorators/wallet.ts +3 -4
  140. package/src/factories/createClient.ts +1 -1
  141. package/src/factories/createTransport.ts +1 -55
  142. package/src/transports/ankr/ankr.ts +8 -1
  143. package/src/transports/blockchair/blockchair.ts +6 -0
  144. package/src/transports/blockcypher/blockcypher.ts +5 -0
  145. package/src/transports/custom.ts +6 -6
  146. package/src/transports/fallback.ts +7 -7
  147. package/src/transports/http.ts +6 -6
  148. package/src/transports/mempool/mempool.ts +5 -0
  149. package/src/transports/types.ts +1 -1
  150. package/src/transports/utxo.ts +3 -4
  151. package/src/types/request.ts +3 -2
  152. package/src/types/transport.ts +3 -2
  153. package/src/utils/getAction.ts +1 -1
  154. package/src/version.ts +1 -1
@@ -1,61 +1,7 @@
1
- import type { ErrorType } from '../errors/utils.js'
2
- import type { Chain } from '../types/chain.js'
3
- import type { ClientConfig } from '../types/client.js'
4
- import type { BtcRpcRequestFn } from '../types/request.js'
5
- import type { OneOf } from '../types/utils.js'
1
+ import type { Transport, TransportConfig } from '../types/transport.js'
6
2
  import { buildRequest } from '../utils/buildRequest.js'
7
3
  import { uid as uid_ } from '../utils/uid.js'
8
4
 
9
- export type TransportConfig<
10
- type extends string = string,
11
- rpcRequestFn extends BtcRpcRequestFn = BtcRpcRequestFn,
12
- > = {
13
- /** The name of the transport. */
14
- name: string
15
- /** The key of the transport. */
16
- key: string
17
- /** Methods to include or exclude from executing RPC requests. */
18
- methods?:
19
- | OneOf<
20
- | {
21
- include?: string[] | undefined
22
- }
23
- | {
24
- exclude?: string[] | undefined
25
- }
26
- >
27
- | undefined
28
- /** The JSON-RPC request function that matches the EIP-1193 request spec. */
29
- request: rpcRequestFn
30
- /** The base delay (in ms) between retries. */
31
- retryDelay?: number | undefined
32
- /** The max number of times to retry. */
33
- retryCount?: number | undefined
34
- /** The timeout (in ms) for requests. */
35
- timeout?: number | undefined
36
- /** The type of the transport. */
37
- type: type
38
- }
39
-
40
- export type Transport<
41
- type extends string = string,
42
- rpcAttributes = Record<string, any>,
43
- rpcRequestFn extends BtcRpcRequestFn = BtcRpcRequestFn,
44
- > = <chain extends Chain | undefined = Chain>({
45
- chain,
46
- }: {
47
- chain?: chain | undefined
48
- pollingInterval?: ClientConfig['pollingInterval'] | undefined
49
- retryCount?: TransportConfig['retryCount'] | undefined
50
- timeout?: TransportConfig['timeout'] | undefined
51
- }) => {
52
- config: TransportConfig<type>
53
- request: rpcRequestFn
54
- value?: rpcAttributes | undefined
55
- }
56
-
57
- export type CreateTransportErrorType = ErrorType
58
-
59
5
  /**
60
6
  * @description Creates an transport intended to be used with a client.
61
7
  */
@@ -1,11 +1,17 @@
1
+ import type { TransportConfig } from '../../types/transport.js'
1
2
  import type { HttpTransportConfig } from '../http.js'
3
+ import type { UTXOAPISchema, UTXOMethod } from '../types.js'
2
4
  import { utxo } from '../utxo.js'
5
+ import { ankrMethods } from './methods.js'
3
6
 
4
7
  type AnkrConfig = { baseUrl?: string; apiKey?: string } & HttpTransportConfig
5
8
 
6
9
  export const ankr = (config?: AnkrConfig) => {
10
+ const methods: TransportConfig['methods'] = {
11
+ include: Object.keys(ankrMethods) as UTXOMethod[],
12
+ }
7
13
  if (config?.baseUrl) {
8
- return utxo(config.baseUrl, { key: 'ankr', ...config })
14
+ return utxo(config.baseUrl, { key: 'ankr', ...config, methods })
9
15
  }
10
16
 
11
17
  if (!config?.apiKey) {
@@ -15,6 +21,7 @@ export const ankr = (config?: AnkrConfig) => {
15
21
  `https://rpc.ankr.com/premium-http/btc_blockbook/${config.apiKey}/api/v2`,
16
22
  {
17
23
  key: 'ankr',
24
+ methods,
18
25
  ...config,
19
26
  }
20
27
  )
@@ -1,5 +1,8 @@
1
+ import type { TransportConfig } from '../../types/transport.js'
1
2
  import type { HttpTransportConfig } from '../http.js'
3
+ import type { UTXOMethod } from '../types.js'
2
4
  import { utxo } from '../utxo.js'
5
+ import { blockchairMethods } from './methods.js'
3
6
 
4
7
  type BlockchairConfig = {
5
8
  baseUrl?: string
@@ -10,5 +13,8 @@ export const blockchair = (config?: BlockchairConfig) =>
10
13
  utxo(config?.baseUrl || 'https://api.blockchair.com', {
11
14
  key: 'blockchair',
12
15
  includeChainToURL: true,
16
+ methods: {
17
+ include: Object.keys(blockchairMethods) as UTXOMethod[],
18
+ },
13
19
  ...config,
14
20
  })
@@ -1,5 +1,7 @@
1
1
  import type { HttpTransportConfig } from '../http.js'
2
+ import type { UTXOMethod } from '../types.js'
2
3
  import { utxo } from '../utxo.js'
4
+ import { blockcypherMethods } from './methods.js'
3
5
 
4
6
  type BlockcypherConfig = {
5
7
  baseUrl?: string
@@ -9,5 +11,8 @@ type BlockcypherConfig = {
9
11
  export const blockcypher = (config?: BlockcypherConfig) =>
10
12
  utxo(config?.baseUrl || 'https://api.blockcypher.com/v1/btc/main', {
11
13
  key: 'blockcypher',
14
+ methods: {
15
+ include: Object.keys(blockcypherMethods) as UTXOMethod[],
16
+ },
12
17
  ...config,
13
18
  })
@@ -1,10 +1,10 @@
1
1
  import type { ErrorType } from '../errors/utils.js'
2
- import {
3
- type CreateTransportErrorType,
4
- type Transport,
5
- type TransportConfig,
6
- createTransport,
7
- } from '../factories/createTransport.js'
2
+ import { createTransport } from '../factories/createTransport.js'
3
+ import type {
4
+ CreateTransportErrorType,
5
+ Transport,
6
+ TransportConfig,
7
+ } from '../types/transport.js'
8
8
 
9
9
  type BitcoinProvider = { request(...args: any): Promise<any> }
10
10
 
@@ -125,7 +125,7 @@ export function fallback<const transports extends readonly Transport[]>(
125
125
  // Filter transports to only those that support the requested method
126
126
  const supportedTransports = transports.reduce<
127
127
  ReturnType<Transport>[]
128
- >((acc, transport) => {
128
+ >((supportedTransports, transport) => {
129
129
  const instance = transport({
130
130
  ...rest,
131
131
  chain,
@@ -135,18 +135,18 @@ export function fallback<const transports extends readonly Transport[]>(
135
135
  const { include, exclude } = instance.config.methods || {}
136
136
  if (include) {
137
137
  if (include.includes(method)) {
138
- acc.push(instance)
138
+ supportedTransports.push(instance)
139
139
  }
140
- return acc
140
+ return supportedTransports
141
141
  }
142
142
  if (exclude) {
143
143
  if (!exclude.includes(method)) {
144
- acc.push(instance)
144
+ supportedTransports.push(instance)
145
145
  }
146
- return acc
146
+ return supportedTransports
147
147
  }
148
- acc.push(instance)
149
- return acc
148
+ supportedTransports.push(instance)
149
+ return supportedTransports
150
150
  }, [])
151
151
 
152
152
  if (!supportedTransports.length) {
@@ -4,13 +4,13 @@ import {
4
4
  type UrlRequiredErrorType,
5
5
  } from '../errors/transport.js'
6
6
  import type { ErrorType } from '../errors/utils.js'
7
- import {
8
- type CreateTransportErrorType,
9
- type Transport,
10
- type TransportConfig,
11
- createTransport,
12
- } from '../factories/createTransport.js'
7
+ import { createTransport } from '../factories/createTransport.js'
13
8
  import type { BtcRpcRequestFn, RpcSchema } from '../types/request.js'
9
+ import type {
10
+ CreateTransportErrorType,
11
+ Transport,
12
+ TransportConfig,
13
+ } from '../types/transport.js'
14
14
  import { createBatchScheduler } from '../utils/createBatchScheduler.js'
15
15
  import {
16
16
  type HttpRpcClientOptions,
@@ -1,5 +1,7 @@
1
1
  import type { HttpTransportConfig } from '../http.js'
2
+ import type { UTXOMethod } from '../types.js'
2
3
  import { utxo } from '../utxo.js'
4
+ import { mempoolMethods } from './methods.js'
3
5
 
4
6
  type MempoolConfig = {
5
7
  baseUrl?: string
@@ -8,5 +10,8 @@ type MempoolConfig = {
8
10
  export const mempool = (config?: MempoolConfig) =>
9
11
  utxo(config?.baseUrl || 'https://mempool.space/api', {
10
12
  key: 'mempool',
13
+ methods: {
14
+ include: Object.keys(mempoolMethods) as UTXOMethod[],
15
+ },
11
16
  ...config,
12
17
  })
@@ -2,7 +2,7 @@ import type { BlockStats, BlockStatsKeys } from '../types/blockStats.js'
2
2
  import type { UTXO, UTXOTransaction } from '../types/transaction.js'
3
3
  import type { HttpRpcClient } from './getHttpRpcClient.js'
4
4
 
5
- export const UTXOAPISchemaMethods = [
5
+ export const UTXOAPISchemaMethods: UTXOMethod[] = [
6
6
  'getBalance',
7
7
  'getTransactions',
8
8
  'getUTXOs',
@@ -4,7 +4,7 @@ import { createTransport } from '../factories/createTransport.js'
4
4
  import { getHttpRpcClient } from './getHttpRpcClient.js'
5
5
  import { getRpcProviderMethods } from './getRpcProviderMethods.js'
6
6
  import type { HttpTransport, HttpTransportConfig } from './http.js'
7
- import { UTXOAPISchemaMethods, type UTXOMethod } from './types.js'
7
+ import type { UTXOMethod } from './types.js'
8
8
 
9
9
  type UTXOHttpTransportConfig = HttpTransportConfig & {
10
10
  includeChainToURL?: boolean
@@ -23,6 +23,7 @@ export function utxo(
23
23
  onFetchResponse,
24
24
  retryDelay,
25
25
  apiKey,
26
+ methods,
26
27
  } = config
27
28
 
28
29
  return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {
@@ -50,9 +51,7 @@ export function utxo(
50
51
  {
51
52
  key,
52
53
  name,
53
- methods: {
54
- include: UTXOAPISchemaMethods,
55
- },
54
+ methods,
56
55
  async request({ method, params }) {
57
56
  const body = { method, params }
58
57
  const methodHandler = rpcMethods?.[method as UTXOMethod]
@@ -1,4 +1,5 @@
1
1
  import type { ErrorType } from '../errors/utils.js'
2
+ import type { UTXOMethod } from '../transports/types.js'
2
3
  import type { OneOf } from './utils.js'
3
4
 
4
5
  export type RpcSchema = readonly {
@@ -34,10 +35,10 @@ export type BtcRpcRequestOptions = {
34
35
  methods?:
35
36
  | OneOf<
36
37
  | {
37
- include?: string[] | undefined
38
+ include?: UTXOMethod[] | undefined
38
39
  }
39
40
  | {
40
- exclude?: string[] | undefined
41
+ exclude?: UTXOMethod[] | undefined
41
42
  }
42
43
  >
43
44
  | undefined
@@ -1,4 +1,5 @@
1
1
  import type { ErrorType } from '../errors/utils.js'
2
+ import type { UTXOMethod } from '../transports/types.js'
2
3
  import type { Chain } from './chain.js'
3
4
  import type { BtcRpcRequestFn, RpcSchema } from './request.js'
4
5
  import type { OneOf } from './utils.js'
@@ -15,10 +16,10 @@ export type TransportConfig<
15
16
  methods?:
16
17
  | OneOf<
17
18
  | {
18
- include?: string[] | undefined
19
+ include?: UTXOMethod[] | undefined
19
20
  }
20
21
  | {
21
- exclude?: string[] | undefined
22
+ exclude?: UTXOMethod[] | undefined
22
23
  }
23
24
  >
24
25
  | undefined
@@ -1,8 +1,8 @@
1
1
  import type { PublicActions } from '../clients/decorators/public.js'
2
2
  import type { WalletActions } from '../clients/decorators/wallet.js'
3
- import type { Transport } from '../factories/createTransport.js'
4
3
  import type { UTXOSchema } from '../transports/types.js'
5
4
  import type { Client } from '../types/client.js'
5
+ import type { Transport } from '../types/transport.js'
6
6
 
7
7
  import type { Account } from '../types/account.js'
8
8
  import type { Chain } from '../types/chain.js'
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@bigmi/core'
2
- export const version = '0.3.0-beta.3'
2
+ export const version = '0.3.0-beta.4'