@xyo-network/witness-blockchain-abstract 5.3.22 → 5.3.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/witness-blockchain-abstract",
3
- "version": "5.3.22",
3
+ "version": "5.3.25",
4
4
  "description": "Primary SDK for using XYO Protocol 2.0",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,15 +30,15 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
33
  "!**/*.bench.*",
35
34
  "!**/*.spec.*",
36
- "!**/*.test.*"
35
+ "!**/*.test.*",
36
+ "README.md"
37
37
  ],
38
38
  "devDependencies": {
39
39
  "@opentelemetry/api": "^1.9.1",
40
- "@xylabs/sdk-js": "^5.0.91",
41
- "@xylabs/tsconfig": "~7.6.8",
40
+ "@xylabs/sdk-js": "^5.0.93",
41
+ "@xylabs/tsconfig": "~7.6.16",
42
42
  "axios": "^1.14.0",
43
43
  "ethers": "^6.16.0",
44
44
  "typescript": "~5.9.3",
@@ -52,4 +52,4 @@
52
52
  "publishConfig": {
53
53
  "access": "public"
54
54
  }
55
- }
55
+ }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './lib/index.ts'
@@ -1,43 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
-
3
- const allowIpfsIoRepair = true
4
-
5
- /**
6
- * Returns the equivalent IPFS gateway URL for the supplied URL.
7
- * @param urlToCheck The URL to check
8
- * @returns If the supplied URL is an IPFS URL, it converts the URL to the
9
- * equivalent IPFS gateway URL. Otherwise, returns the original URL.
10
- */
11
- export const checkIpfsUrl = (urlToCheck: string, ipfsGateway?: string): string => {
12
- try {
13
- const url = new URL(urlToCheck)
14
- let protocol = url.protocol
15
- let host = url.host
16
- let path = url.pathname
17
- const query = url.search
18
- if (protocol === 'ipfs:') {
19
- protocol = 'https:'
20
- host = assertEx(ipfsGateway, () => 'No ipfsGateway provided')
21
- path = url.host === 'ipfs' ? `ipfs${path}` : `ipfs/${url.host}${path}`
22
- const root = `${protocol}//${host}/${path}`
23
- return query?.length > 0 ? `${root}?${query}` : root
24
- } else if (allowIpfsIoRepair && protocol === 'https' && host === 'ipfs.io') {
25
- protocol = 'https:'
26
- host = assertEx(ipfsGateway, () => 'No ipfsGateway provided')
27
- const pathParts = path.split('/')
28
- if (pathParts[0] === 'ipfs') {
29
- pathParts.shift()
30
- }
31
- path = pathParts.join('/')
32
- const root = `${protocol}//${host}/${path}`
33
- return query?.length > 0 ? `${root}?${query}` : root
34
- } else {
35
- return urlToCheck
36
- }
37
- } catch {
38
- // const error = ex as Error
39
- // console.error(`${error.name}:${error.message} [${urlToCheck}]`)
40
- // console.log(error.stack)
41
- return urlToCheck
42
- }
43
- }
@@ -1,100 +0,0 @@
1
- import { assertEx, isString } from '@xylabs/sdk-js'
2
- import type { Provider } from 'ethers'
3
- import {
4
- InfuraProvider, InfuraWebSocketProvider, JsonRpcProvider,
5
- WebSocketProvider,
6
- } from 'ethers'
7
-
8
- export type ProviderSource = 'infura' | 'quicknode'
9
- export type ProviderType = 'rpc' | 'wss'
10
-
11
- export interface GetProvidersFromEnvOptions {
12
- providerSource?: ProviderSource
13
- providerType?: ProviderType
14
- }
15
-
16
- const createInfuraRpc = (chainId: number) => {
17
- return isString(process.env.INFURA_PROJECT_ID) && isString(process.env.INFURA_PROJECT_SECRET)
18
- ? new InfuraProvider(chainId, process.env.INFURA_PROJECT_ID)
19
- : undefined
20
- }
21
-
22
- const createInfuraWss = (chainId: number) => {
23
- return isString(process.env.INFURA_PROJECT_ID) ? new InfuraWebSocketProvider(chainId, process.env.INFURA_PROJECT_ID) : undefined
24
- }
25
-
26
- const createQuicknodeWss = (chainId: number) => {
27
- const quickNodeWSSUri = process.env.QUICKNODE_WSS_URI
28
- return isString(quickNodeWSSUri) ? new WebSocketProvider(quickNodeWSSUri, chainId) : undefined
29
- }
30
-
31
- const createQuicknodeRpc = (chainId: number) => {
32
- const quickNodeHttpsUri = process.env.QUICKNODE_HTTPS_URI
33
- return isString(quickNodeHttpsUri) ? new JsonRpcProvider(quickNodeHttpsUri, chainId) : undefined
34
- }
35
-
36
- export const getProviderFromEnv = (
37
- chainId: number = 0x01,
38
- { providerSource = 'infura', providerType = 'rpc' }: GetProvidersFromEnvOptions = {},
39
- ): Provider => {
40
- let provider: Provider | undefined = undefined
41
-
42
- const quicknodeCases = () => {
43
- switch (providerType) {
44
- case 'rpc': {
45
- provider = createQuicknodeRpc(chainId)
46
- break
47
- }
48
- case 'wss': {
49
- provider = createQuicknodeWss(chainId)
50
- break
51
- }
52
- }
53
- }
54
-
55
- const infuraCases = () => {
56
- switch (providerType) {
57
- case 'wss': {
58
- provider = createInfuraWss(chainId)
59
- break
60
- }
61
- case 'rpc': {
62
- provider = createInfuraRpc(chainId)
63
- break
64
- }
65
- }
66
- }
67
-
68
- switch (providerSource ?? 'infura') {
69
- case 'quicknode': {
70
- quicknodeCases()
71
- break
72
- }
73
- case 'infura':{
74
- infuraCases()
75
- break
76
- }
77
- }
78
-
79
- provider = provider ?? createInfuraWss(chainId) ?? createInfuraRpc(chainId) ?? createQuicknodeRpc(chainId)
80
- return assertEx(provider, () => `Unable to create provider [${chainId}]: ${providerSource}|${providerType}`)
81
- }
82
-
83
- const providers: Record<string, Provider> = {}
84
-
85
- export const getSharedProviderFromEnv = (
86
- chainId: number = 0x01,
87
- options?: { providerSource?: ProviderSource; providerType?: ProviderType },
88
- ): Provider => {
89
- const key = `${chainId}:${options ? JSON.stringify(options) : 'default'}`
90
- providers[key] = providers[key] ?? getProviderFromEnv(chainId, options)
91
- return providers[key]
92
- }
93
-
94
- export const getProvidersFromEnv = (count: number = 1, chainId: number = 0x01, options: GetProvidersFromEnvOptions = {}): Provider[] => {
95
- const result: Provider[] = []
96
- for (let i = 0; i < count; i++) {
97
- result.push(getProviderFromEnv(chainId, options))
98
- }
99
- return result
100
- }
package/src/lib/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './checkIpfsUrl.ts'
2
- export * from './getProviderFromEnv.ts'