@xyo-network/network 0.57.0 → 2.20.18

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 (84) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +67 -9
  3. package/babel.config.json +5 -0
  4. package/dist/cjs/XyoNetworkConfig.d.ts +6 -0
  5. package/dist/cjs/XyoNetworkConfig.js +3 -0
  6. package/dist/cjs/XyoNetworkConfig.js.map +1 -0
  7. package/dist/cjs/XyoNetworkConfigWrapper.d.ts +12 -0
  8. package/dist/cjs/XyoNetworkConfigWrapper.js +31 -0
  9. package/dist/cjs/XyoNetworkConfigWrapper.js.map +1 -0
  10. package/dist/cjs/XyoNodeConfig.d.ts +9 -0
  11. package/dist/cjs/XyoNodeConfig.js +3 -0
  12. package/dist/cjs/XyoNodeConfig.js.map +1 -0
  13. package/dist/cjs/XyoNodeConfigWrapper.d.ts +6 -0
  14. package/dist/cjs/XyoNodeConfigWrapper.js +18 -0
  15. package/dist/cjs/XyoNodeConfigWrapper.js.map +1 -0
  16. package/dist/cjs/index.d.ts +2 -0
  17. package/dist/cjs/index.js +6 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/knownArchivists.d.ts +2 -0
  20. package/dist/cjs/knownArchivists.js +36 -0
  21. package/dist/cjs/knownArchivists.js.map +1 -0
  22. package/dist/cjs/knownDiviners.d.ts +2 -0
  23. package/dist/cjs/knownDiviners.js +24 -0
  24. package/dist/cjs/knownDiviners.js.map +1 -0
  25. package/dist/cjs/knownNetworks.d.ts +2 -0
  26. package/dist/cjs/knownNetworks.js +31 -0
  27. package/dist/cjs/knownNetworks.js.map +1 -0
  28. package/dist/docs.json +297 -0
  29. package/dist/esm/XyoNetworkConfig.d.ts +6 -0
  30. package/dist/esm/XyoNetworkConfig.js +2 -0
  31. package/dist/esm/XyoNetworkConfig.js.map +1 -0
  32. package/dist/esm/XyoNetworkConfigWrapper.d.ts +12 -0
  33. package/dist/esm/XyoNetworkConfigWrapper.js +27 -0
  34. package/dist/esm/XyoNetworkConfigWrapper.js.map +1 -0
  35. package/dist/esm/XyoNodeConfig.d.ts +9 -0
  36. package/dist/esm/XyoNodeConfig.js +2 -0
  37. package/dist/esm/XyoNodeConfig.js.map +1 -0
  38. package/dist/esm/XyoNodeConfigWrapper.d.ts +6 -0
  39. package/dist/esm/XyoNodeConfigWrapper.js +13 -0
  40. package/dist/esm/XyoNodeConfigWrapper.js.map +1 -0
  41. package/dist/esm/index.d.ts +2 -0
  42. package/dist/esm/index.js +3 -0
  43. package/dist/esm/index.js.map +1 -0
  44. package/dist/esm/knownArchivists.d.ts +2 -0
  45. package/dist/esm/knownArchivists.js +32 -0
  46. package/dist/esm/knownArchivists.js.map +1 -0
  47. package/dist/esm/knownDiviners.d.ts +2 -0
  48. package/dist/esm/knownDiviners.js +20 -0
  49. package/dist/esm/knownDiviners.js.map +1 -0
  50. package/dist/esm/knownNetworks.d.ts +2 -0
  51. package/dist/esm/knownNetworks.js +24 -0
  52. package/dist/esm/knownNetworks.js.map +1 -0
  53. package/jest.config.cjs +25 -0
  54. package/package.json +114 -18
  55. package/rollup.config.js +5 -0
  56. package/src/XyoNetworkConfig.ts +7 -0
  57. package/src/XyoNetworkConfigWrapper.ts +41 -0
  58. package/src/XyoNodeConfig.ts +10 -0
  59. package/src/XyoNodeConfigWrapper.ts +18 -0
  60. package/src/index.ts +2 -102
  61. package/src/knownArchivists.ts +36 -0
  62. package/src/knownDiviners.ts +23 -0
  63. package/src/knownNetworks.ts +35 -0
  64. package/dist/@types/index.d.ts +0 -68
  65. package/dist/@types/index.d.ts.map +0 -1
  66. package/dist/@types/index.js +0 -13
  67. package/dist/@types/index.js.map +0 -1
  68. package/dist/catalogue-item.d.ts +0 -11
  69. package/dist/catalogue-item.d.ts.map +0 -1
  70. package/dist/catalogue-item.js +0 -24
  71. package/dist/catalogue-item.js.map +0 -1
  72. package/dist/index.d.ts +0 -35
  73. package/dist/index.d.ts.map +0 -1
  74. package/dist/index.js +0 -88
  75. package/dist/index.js.map +0 -1
  76. package/dist/xyo-mock-network-pipe.d.ts +0 -18
  77. package/dist/xyo-mock-network-pipe.d.ts.map +0 -1
  78. package/dist/xyo-mock-network-pipe.js +0 -52
  79. package/dist/xyo-mock-network-pipe.js.map +0 -1
  80. package/src/@types/index.ts +0 -97
  81. package/src/catalogue-item.ts +0 -21
  82. package/src/xyo-mock-network-pipe.ts +0 -54
  83. package/tsconfig.json +0 -24
  84. package/tsconfig.tsbuildinfo +0 -4287
package/package.json CHANGED
@@ -1,22 +1,118 @@
1
1
  {
2
- "name": "@xyo-network/network",
3
- "version": "0.57.0",
4
- "description": "An abstraction around sending messages over a network from node to node in the XYO network",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "author": "XY Development Team",
8
- "license": "MIT",
2
+ "author": {
3
+ "email": "support@xyo.network",
4
+ "name": "XYO Development Team",
5
+ "url": "https://xyo.network"
6
+ },
7
+ "bugs": {
8
+ "email": "support@xyo.network",
9
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
10
+ },
9
11
  "dependencies": {
10
- "@xyo-network/serialization": "^0.57.0"
12
+ "@ethersproject/providers": "^5.6.5",
13
+ "@xylabs/sdk-js": "^2.5.5",
14
+ "@xyo-network/core": "^2.20.18",
15
+ "@xyo-network/ethers-wrappers": "^2.6.17",
16
+ "@xyo-network/sdk-xyo-mongo-js": "^2.2.7",
17
+ "@xyo-network/sdk-xyo-typechain": "^1.0.3",
18
+ "ajv": "^8.11.0",
19
+ "axios": "^0.27.2",
20
+ "bn.js": "^5.2.0",
21
+ "bowser": "^2.11.0",
22
+ "elliptic": "^6.5.4",
23
+ "keccak256": "^1.0.6",
24
+ "lodash": "^4.17.21",
25
+ "lru-cache": "^7.10.1",
26
+ "mongodb": "^4.6.0",
27
+ "neo4j-driver": "^4.4.5",
28
+ "neo4j-driver-core": "^4.4.5",
29
+ "pako": "^2.0.4",
30
+ "randombytes": "^2.1.0",
31
+ "sha.js": "^2.4.11",
32
+ "systeminformation": "^5.11.15",
33
+ "ua-parser-js": "^1.0.2",
34
+ "uuid": "^8.3.2"
11
35
  },
36
+ "description": "Primary SDK for using XYO Protocol 2.0",
12
37
  "devDependencies": {
13
- "@types/jest": "^24.0.11",
14
- "@types/node": "^11.12.1",
15
- "jest": "^24.5.0",
16
- "ts-jest": "^24.0.0",
17
- "ts-node": "^8.0.3",
18
- "tslint": "^5.12.1",
19
- "typescript": "^3.2.2"
20
- },
21
- "gitHead": "4645b6a2e22b5a220c416bb05175abd1a7b77d66"
22
- }
38
+ "@babel/core": "^7.17.10",
39
+ "@babel/preset-env": "^7.17.10",
40
+ "@types/bn.js": "^5.1.0",
41
+ "@types/elliptic": "^6.4.14",
42
+ "@types/jest": "^27.5.1",
43
+ "@types/json-schema": "^7.0.11",
44
+ "@types/lodash": "^4.14.182",
45
+ "@types/lru-cache": "^7.6.1",
46
+ "@types/node": "^17.0.32",
47
+ "@types/pako": "^1.0.3",
48
+ "@types/randombytes": "^2.0.0",
49
+ "@types/sha.js": "^2.4.0",
50
+ "@types/ua-parser-js": "^0.7.36",
51
+ "@types/uuid": "^8.3.4",
52
+ "@xylabs/eslint-config": "^2.3.22",
53
+ "@xylabs/rollup-config": "^1.1.17",
54
+ "@xylabs/ts-scripts": "^1.0.66",
55
+ "@xylabs/tsconfig": "^1.0.13",
56
+ "babel-jest": "^28.1.0",
57
+ "copyfiles": "^2.4.1",
58
+ "dotenv": "^16.0.1",
59
+ "eslint": "^8.15.0",
60
+ "ethers": "^5.6.5",
61
+ "jest": "^28.1.0",
62
+ "jest-environment-jsdom": "^28.1.0",
63
+ "jest-sorted": "^1.0.14",
64
+ "license-checker": "^25.0.1",
65
+ "npm-package-json-lint": "^6.3.0",
66
+ "npm-package-json-lint-config-default": "^5.0.0",
67
+ "rimraf": "^3.0.2",
68
+ "rollbar": "^2.25.0",
69
+ "rollup": "^2.72.1",
70
+ "ts-jest": "^28.0.2",
71
+ "ts-node": "^10.7.0",
72
+ "tslib": "^2.4.0",
73
+ "typedoc": "^0.22.15",
74
+ "typescript": "^4.6.4"
75
+ },
76
+ "browser": "dist/esm/browserIndex.js",
77
+ "docs": "dist/docs.json",
78
+ "exports": {
79
+ ".": {
80
+ "node": {
81
+ "import": "./dist/esm/nodeIndex.js",
82
+ "require": "./dist/cjs/nodeIndex.js"
83
+ },
84
+ "browser": {
85
+ "import": "./dist/esm/browserIndex.js",
86
+ "require": "./dist/cjs/browserIndex.js"
87
+ },
88
+ "default": "./dist/esm/index.js"
89
+ },
90
+ "./dist/docs.json": {
91
+ "default": "./dist/docs.json"
92
+ },
93
+ "./package.json": "./package.json"
94
+ },
95
+ "main": "dist/cjs/index.js",
96
+ "module": "dist/esm/index.js",
97
+ "homepage": "https://xyo.network",
98
+ "license": "LGPL-3.0-only",
99
+ "name": "@xyo-network/network",
100
+ "publishConfig": {
101
+ "access": "public"
102
+ },
103
+ "repository": {
104
+ "type": "git",
105
+ "url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
106
+ },
107
+ "scripts": {
108
+ "deploy": "yarn deploy3",
109
+ "lint-pkg": "npmPkgJsonLint .",
110
+ "build": "yarn clean && tsc -p tsconfig.build.cjs.json && tsc -p tsconfig.build.esm.json && yarn gen:docs",
111
+ "gen:docs": "typedoc ./src/index.ts --json ./dist/docs.json --tsconfig ./tsconfig.json",
112
+ "license": "yarn license-checker --exclude \"MIT, ISC, Apache-2.0, BSD, BSD-2-Clause, CC-BY-4.0, Unlicense, CC-BY-3.0, CC0-1.0\""
113
+ },
114
+ "sideEffects": true,
115
+ "types": "dist/esm/index.d.ts",
116
+ "version": "2.20.18",
117
+ "packageManager": "yarn@3.1.1"
118
+ }
@@ -0,0 +1,5 @@
1
+ import { getRollupConfig } from '@xylabs/rollup-config'
2
+
3
+ import pkg from './package.json'
4
+
5
+ export default getRollupConfig({pkg, browserIndex: './src/browserIndex.ts', nodeIndex: './src/nodeIndex.ts', bundlePrefix: 'bundle/', outputs: ['cjs5', 'node', 'node-esm']})
@@ -0,0 +1,7 @@
1
+ import { XyoNodeConfig } from './XyoNodeConfig'
2
+
3
+ export interface XyoNetworkConfig {
4
+ slug: string
5
+ name: string
6
+ nodes: XyoNodeConfig[]
7
+ }
@@ -0,0 +1,41 @@
1
+ import { assertEx } from '@xylabs/sdk-js'
2
+
3
+ import { knownNetworks } from './knownNetworks'
4
+ import { XyoNetworkConfig } from './XyoNetworkConfig'
5
+ import { XyoNodeType } from './XyoNodeConfig'
6
+
7
+ export class XyoNetworkConfigWrapper {
8
+ public config: XyoNetworkConfig
9
+
10
+ constructor(config: XyoNetworkConfig) {
11
+ this.config = config
12
+ }
13
+
14
+ public filterNodesByType(type: XyoNodeType) {
15
+ return this.config.nodes.filter((node) => node.type === type)
16
+ }
17
+
18
+ public get archivists() {
19
+ return this.filterNodesByType('archivist')
20
+ }
21
+
22
+ public get diviners() {
23
+ return this.filterNodesByType('diviner')
24
+ }
25
+
26
+ public get bridges() {
27
+ return this.filterNodesByType('bridge')
28
+ }
29
+
30
+ public get sentinels() {
31
+ return this.filterNodesByType('sentinel')
32
+ }
33
+
34
+ static known(slug: string) {
35
+ const config = assertEx(
36
+ knownNetworks().find((config) => config.slug === slug),
37
+ 'Unknown network'
38
+ )
39
+ return new XyoNetworkConfigWrapper(config)
40
+ }
41
+ }
@@ -0,0 +1,10 @@
1
+ export type XyoNodeType = 'archivist' | 'diviner' | 'bridge' | 'sentinel'
2
+
3
+ export interface XyoNodeConfig {
4
+ type: XyoNodeType
5
+ slug: string
6
+ name: string
7
+ uri: string
8
+ web?: string
9
+ docs?: string
10
+ }
@@ -0,0 +1,18 @@
1
+ import { assertEx } from '@xylabs/sdk-js'
2
+
3
+ import { knownArchivists } from './knownArchivists'
4
+ import { knownDiviners } from './knownDiviners'
5
+ import { XyoNodeConfig } from './XyoNodeConfig'
6
+
7
+ export class XyoNodeConfigWrapper {
8
+ public config: XyoNodeConfig
9
+
10
+ constructor(config: XyoNodeConfig) {
11
+ this.config = config
12
+ }
13
+
14
+ static known(slug: string) {
15
+ const config = assertEx(knownArchivists().find((config) => config.slug === slug) ?? knownDiviners().find((config) => config.slug === slug), 'Unknown node')
16
+ return new XyoNodeConfigWrapper(config)
17
+ }
18
+ }
package/src/index.ts CHANGED
@@ -1,102 +1,2 @@
1
- /*
2
- * @Author: XY | The Findables Company <ryanxyo>
3
- * @Date: Tuesday, 20th November 2018 10:18:42 am
4
- * @Email: developer@xyfindables.com
5
- * @Filename: index.ts
6
- * @Last modified by: ryanxyo
7
- * @Last modified time: Wednesday, 13th February 2019 1:28:15 pm
8
- * @License: All Rights Reserved
9
- * @Copyright: Copyright XY | The Findables Company
10
- */
11
-
12
- import { CatalogueItem } from './catalogue-item'
13
- import { IXyoNetworkProcedureCatalogue } from './@types'
14
-
15
- export { CatalogueItem } from './catalogue-item'
16
- export { XyoMockNetworkPipe } from './xyo-mock-network-pipe'
17
- export { IXyoNetworkPeer, IXyoNetworkPipe, IXyoNetworkProcedureCatalogue, IXyoNetworkProvider } from './@types'
18
-
19
- /**
20
- * Some very important numbers that factor into the catalogue negotiation protocol
21
- */
22
-
23
- /** The current number of bytes that encode the length if the catalogue */
24
- export const CATALOGUE_LENGTH_IN_BYTES = 4
25
-
26
- /** This number of bytes allowed to encode how big the catalogue can be */
27
- export const CATALOGUE_SIZE_OF_SIZE_BYTES = 1
28
-
29
- /**
30
- * When a payload is passed it is padded with the length of bytes of the payload.
31
- * It gets 4 bytes to do so
32
- */
33
- export const CATALOGUE_SIZE_OF_PAYLOAD_BYTES = 4
34
-
35
- /**
36
- * A utility function for translating a buffer to a list of catalogues items
37
- * that another node is willing to do.
38
- *
39
- * @param buffer The data buffer to read and translate
40
- */
41
-
42
- export function bufferToCatalogueItems(buffer: Buffer): CatalogueItem[] {
43
- const values = readNumberFromBufferCatalogue(buffer)
44
-
45
- return [
46
- (CatalogueItem.BOUND_WITNESS & values) > 0 ? CatalogueItem.BOUND_WITNESS : null,
47
- (CatalogueItem.TAKE_ORIGIN_CHAIN & values) > 0 ? CatalogueItem.TAKE_ORIGIN_CHAIN : null,
48
- (CatalogueItem.GIVE_ORIGIN_CHAIN & values) > 0 ? CatalogueItem.GIVE_ORIGIN_CHAIN : null
49
- ]
50
- .filter(catalogueItem => catalogueItem !== null) as CatalogueItem[]
51
- }
52
-
53
- export function flipChoice(choice: CatalogueItem): CatalogueItem {
54
- if (CatalogueItem.GIVE_ORIGIN_CHAIN === choice) {
55
- return CatalogueItem.TAKE_ORIGIN_CHAIN
56
- }
57
-
58
- if (CatalogueItem.TAKE_ORIGIN_CHAIN === choice) {
59
- return CatalogueItem.GIVE_ORIGIN_CHAIN
60
- }
61
-
62
- return choice
63
- }
64
-
65
- const readNumberFromBufferCatalogue = (buffer: Buffer): number => {
66
- if (buffer.length === 4) {
67
- return buffer.readUInt32BE(0)
68
- }
69
-
70
- if (buffer.length === 2) {
71
- return buffer.readUInt16BE(0)
72
- }
73
-
74
- if (buffer.length === 1) {
75
- return buffer.readUInt8(0)
76
- }
77
-
78
- return 0
79
- }
80
-
81
- /** Returns a number, which is feature-mask representing CatalogueItems */
82
- export function catalogueItemsToMask(catalogueItems: CatalogueItem[]) {
83
- return catalogueItems.reduce((sum, item) => sum + item, 0)
84
- }
85
-
86
- export class XyoNetworkProcedureCatalogue implements IXyoNetworkProcedureCatalogue {
87
-
88
- private catalogue: CatalogueItem[] = []
89
-
90
- public canDo(catalogueItem: CatalogueItem): boolean {
91
- return this.catalogue.indexOf(catalogueItem) > -1
92
- }
93
-
94
- public getCurrentCatalogue(): CatalogueItem[] {
95
- return this.catalogue
96
- }
97
-
98
- public setCatalogue(catalogue: CatalogueItem[]) {
99
- this.catalogue = catalogue
100
- }
101
-
102
- }
1
+ export * from './XyoNetworkConfig'
2
+ export * from './XyoNodeConfig'
@@ -0,0 +1,36 @@
1
+ import { XyoNodeConfig } from './XyoNodeConfig'
2
+
3
+ const kerplunkArchivist = (): XyoNodeConfig => {
4
+ return {
5
+ docs: 'https://beta.archivist.xyo.network/api',
6
+ name: 'XYO Shared Archivist (kerplunk)',
7
+ slug: 'kerplunk-archivist-xyo-network',
8
+ type: 'archivist',
9
+ uri: 'https://beta.api.archivist.xyo.network',
10
+ web: 'https://beta.archivist.xyo.network',
11
+ }
12
+ }
13
+
14
+ const mainArchivist = (): XyoNodeConfig => {
15
+ return {
16
+ docs: 'https://archivist.xyo.network/api',
17
+ name: 'XYO Shared Archivist (main)',
18
+ slug: 'main-archivist-xyo-network',
19
+ type: 'archivist',
20
+ uri: 'https://api.archivist.xyo.network',
21
+ web: 'https://archivist.xyo.network',
22
+ }
23
+ }
24
+
25
+ const localArchivist = (): XyoNodeConfig => {
26
+ return {
27
+ docs: 'http://localhost:8080/api',
28
+ name: 'XYO Shared Archivist (local)',
29
+ slug: 'local-archivist-xyo-network',
30
+ type: 'archivist',
31
+ uri: 'http://localhost:8080',
32
+ web: 'http://localhost:8081',
33
+ }
34
+ }
35
+
36
+ export const knownArchivists = (): XyoNodeConfig[] => [kerplunkArchivist(), mainArchivist(), localArchivist()]
@@ -0,0 +1,23 @@
1
+ import { XyoNodeConfig } from './XyoNodeConfig'
2
+
3
+ const beta = (): XyoNodeConfig => {
4
+ return {
5
+ name: 'XYO Location (beta)',
6
+ slug: 'beta-location-diviner-xyo-network',
7
+ type: 'diviner',
8
+ uri: 'https://beta.api.location.diviner.xyo.network',
9
+ web: 'https://beta.explore.xyo.network',
10
+ }
11
+ }
12
+
13
+ const main = (): XyoNodeConfig => {
14
+ return {
15
+ name: 'XYO Location',
16
+ slug: 'location-diviner-xyo-network',
17
+ type: 'diviner',
18
+ uri: 'https://api.location.diviner.xyo.network',
19
+ web: 'https://explore.xyo.network',
20
+ }
21
+ }
22
+
23
+ export const knownDiviners = (): XyoNodeConfig[] => [beta(), main()]
@@ -0,0 +1,35 @@
1
+ import { XyoNetworkConfig } from './XyoNetworkConfig'
2
+ import { XyoNodeConfig } from './XyoNodeConfig'
3
+ import { XyoNodeConfigWrapper } from './XyoNodeConfigWrapper'
4
+
5
+ const kerplunk = (): XyoNetworkConfig => {
6
+ return {
7
+ name: 'Kerplunk',
8
+ nodes: [XyoNodeConfigWrapper.known('kerplunk-archivist-xyo-network')?.config, XyoNodeConfigWrapper.known('beta-location-diviner-xyo-network')?.config].filter(
9
+ (item) => item
10
+ ) as XyoNodeConfig[],
11
+ slug: 'kerplunk',
12
+ }
13
+ }
14
+
15
+ const main = (): XyoNetworkConfig => {
16
+ return {
17
+ name: 'Main',
18
+ nodes: [XyoNodeConfigWrapper.known('main-archivist-xyo-network')?.config, XyoNodeConfigWrapper.known('location-diviner-xyo-network')?.config].filter(
19
+ (item) => item
20
+ ) as XyoNodeConfig[],
21
+ slug: 'main',
22
+ }
23
+ }
24
+
25
+ const local = (): XyoNetworkConfig => {
26
+ return {
27
+ name: 'Local',
28
+ nodes: [XyoNodeConfigWrapper.known('kerplunk-archivist-xyo-network')?.config, XyoNodeConfigWrapper.known('beta-location-diviner-xyo-network')?.config].filter(
29
+ (item) => item
30
+ ) as XyoNodeConfig[],
31
+ slug: 'local',
32
+ }
33
+ }
34
+
35
+ export const knownNetworks = (): XyoNetworkConfig[] => [kerplunk(), main(), local()]
@@ -1,68 +0,0 @@
1
- /// <reference types="node" />
2
- import { CatalogueItem } from "../catalogue-item";
3
- import { IXyoSerializableObject } from "@xyo-network/serialization";
4
- /**
5
- * The necessary communication interfaces that xyo-nodes will
6
- * use to communicate to other nodes on a `network`
7
- */
8
- /**
9
- * A peer, meant to represent the meaningful attributes of the
10
- * node on the other side of the network pipe
11
- */
12
- export interface IXyoNetworkPeer {
13
- /**
14
- * Returns an id for a peer that should be consistent across multiple connections
15
- * to the same node
16
- */
17
- getTemporaryPeerId(): Buffer;
18
- }
19
- /**
20
- * An interface that allows the network to delegate to implementer of
21
- * this interface as to which operations the xyo-node supports
22
- */
23
- export interface IXyoNetworkProcedureCatalogue {
24
- /**
25
- * Since not all operations are symmetric, a `canDo` interface
26
- * is required so that an XyoNode can agree to partake in operation
27
- * where one party is one role and the other party is the other role.
28
- *
29
- * For example, an archivist can take origin-chains but does not
30
- * want to give origin-chains. So if an archivist is queried with
31
- * `canDo(TAKE_ORIGIN_CHAIN)` it should return true
32
- */
33
- canDo(catalogueItem: CatalogueItem): boolean;
34
- /**
35
- * The list of current `CatalogueItems` the `XyoNode` can perform
36
- */
37
- getCurrentCatalogue(): CatalogueItem[];
38
- setCatalogue(catalogue: CatalogueItem[]): void;
39
- }
40
- /**
41
- * An XyoNetworkPipe is a communication channel between two
42
- * nodes and will be used the fundamental way that two
43
- * nodes communicate with one another
44
- */
45
- export interface IXyoNetworkPipe {
46
- /** A representation of the peer on the other side of the pipe */
47
- peer: IXyoNetworkPeer;
48
- /** Any data that was initially passed to start an interaction */
49
- initiationData: Buffer | undefined;
50
- networkHeuristics: IXyoSerializableObject[];
51
- /** A consumer may register a handler for when the other peer disconnects */
52
- onPeerDisconnect(callback: (hasError: boolean) => void): () => void;
53
- /** Sends message to the peer. If awaitResponse is true it will wait for a message from the other node */
54
- send(data: Buffer, awaitResponse?: boolean): Promise<Buffer | undefined>;
55
- /** Closes the connection to the peer */
56
- close(): Promise<void>;
57
- }
58
- /**
59
- * A network-provider will try to find peers who are compatible with the catalogue passed in.
60
- * Once a peer is found, it returns a pipe to send messages on.
61
- */
62
- export interface IXyoNetworkProvider {
63
- /** Attempts to find a peer with a compatible catalogue. */
64
- find(catalogue: IXyoNetworkProcedureCatalogue): Promise<IXyoNetworkPipe>;
65
- /** Tells the network-provider to stop finding peers */
66
- stopServer(): Promise<void>;
67
- }
68
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/@types/index.ts"],"names":[],"mappings":";AAWA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAEnE;;;GAGG;AAEH;;;GAGG;AACH,MAAM,WAAW,eAAe;IAE9B;;;OAGG;IACH,kBAAkB,IAAI,MAAM,CAAA;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAE5C;;;;;;;;OAQG;IAEH,KAAK,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAA;IAE5C;;OAEG;IAEH,mBAAmB,IAAI,aAAa,EAAE,CAAA;IAEtC,YAAY,CAAC,SAAS,EAAE,aAAa,EAAE,GAAG,IAAI,CAAA;CAC/C;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAE9B,iEAAiE;IACjE,IAAI,EAAE,eAAe,CAAA;IAErB,iEAAiE;IACjE,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;IAElC,iBAAiB,EAAE,sBAAsB,EAAE,CAAA;IAE3C,4EAA4E;IAC5E,gBAAgB,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAA;IAEnE,yGAAyG;IACzG,IAAI,CAAE,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAEzE,wCAAwC;IACxC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAEvB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAElC,2DAA2D;IAC3D,IAAI,CAAC,SAAS,EAAE,6BAA6B,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IAExE,uDAAuD;IACvD,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5B"}
@@ -1,13 +0,0 @@
1
- "use strict";
2
- /*
3
- * @Author: XY | The Findables Company <ryanxyo>
4
- * @Date: Tuesday, 11th December 2018 9:32:12 am
5
- * @Email: developer@xyfindables.com
6
- * @Filename: index.ts
7
- * @Last modified by: ryanxyo
8
- * @Last modified time: Wednesday, 13th February 2019 1:28:35 pm
9
- * @License: All Rights Reserved
10
- * @Copyright: Copyright XY | The Findables Company
11
- */
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/@types/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG"}
@@ -1,11 +0,0 @@
1
- /**
2
- * The catalogue items this node knows about
3
- */
4
- export declare enum CatalogueItem {
5
- BOUND_WITNESS,
6
- TAKE_ORIGIN_CHAIN,
7
- GIVE_ORIGIN_CHAIN,
8
- TAKE_REQUESTED_BLOCKS,
9
- GIVE_REQUESTED_BLOCKS
10
- }
11
- //# sourceMappingURL=catalogue-item.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"catalogue-item.d.ts","sourceRoot":"","sources":["../src/catalogue-item.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,oBAAY,aAAa;IACvB,aAA8B;IAC9B,iBAAkC;IAClC,iBAAkC;IAClC,qBAAsC;IACtC,qBAAsC;CACvC"}
@@ -1,24 +0,0 @@
1
- "use strict";
2
- /*
3
- * @Author: XY | The Findables Company <ryanxyo>
4
- * @Date: Tuesday, 11th December 2018 9:33:01 am
5
- * @Email: developer@xyfindables.com
6
- * @Filename: catalogue-item.ts
7
- * @Last modified by: ryanxyo
8
- * @Last modified time: Tuesday, 22nd January 2019 10:19:26 am
9
- * @License: All Rights Reserved
10
- * @Copyright: Copyright XY | The Findables Company
11
- */
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- /**
14
- * The catalogue items this node knows about
15
- */
16
- var CatalogueItem;
17
- (function (CatalogueItem) {
18
- CatalogueItem[CatalogueItem["BOUND_WITNESS"] = Math.pow(2, 0)] = "BOUND_WITNESS";
19
- CatalogueItem[CatalogueItem["TAKE_ORIGIN_CHAIN"] = Math.pow(2, 1)] = "TAKE_ORIGIN_CHAIN";
20
- CatalogueItem[CatalogueItem["GIVE_ORIGIN_CHAIN"] = Math.pow(2, 2)] = "GIVE_ORIGIN_CHAIN";
21
- CatalogueItem[CatalogueItem["TAKE_REQUESTED_BLOCKS"] = Math.pow(2, 3)] = "TAKE_REQUESTED_BLOCKS";
22
- CatalogueItem[CatalogueItem["GIVE_REQUESTED_BLOCKS"] = Math.pow(2, 4)] = "GIVE_REQUESTED_BLOCKS";
23
- })(CatalogueItem = exports.CatalogueItem || (exports.CatalogueItem = {}));
24
- //# sourceMappingURL=catalogue-item.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"catalogue-item.js","sourceRoot":"","sources":["../src/catalogue-item.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAEH;;GAEG;AACH,IAAY,aAMX;AAND,WAAY,aAAa;IACvB,+CAAgB,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,mBAAA,CAAA;IAC9B,mDAAoB,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,uBAAA,CAAA;IAClC,mDAAoB,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,uBAAA,CAAA;IAClC,uDAAwB,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,2BAAA,CAAA;IACtC,uDAAwB,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,2BAAA,CAAA;AACxC,CAAC,EANW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAMxB"}
package/dist/index.d.ts DELETED
@@ -1,35 +0,0 @@
1
- /// <reference types="node" />
2
- import { CatalogueItem } from './catalogue-item';
3
- import { IXyoNetworkProcedureCatalogue } from './@types';
4
- export { CatalogueItem } from './catalogue-item';
5
- export { XyoMockNetworkPipe } from './xyo-mock-network-pipe';
6
- export { IXyoNetworkPeer, IXyoNetworkPipe, IXyoNetworkProcedureCatalogue, IXyoNetworkProvider } from './@types';
7
- /**
8
- * Some very important numbers that factor into the catalogue negotiation protocol
9
- */
10
- /** The current number of bytes that encode the length if the catalogue */
11
- export declare const CATALOGUE_LENGTH_IN_BYTES = 4;
12
- /** This number of bytes allowed to encode how big the catalogue can be */
13
- export declare const CATALOGUE_SIZE_OF_SIZE_BYTES = 1;
14
- /**
15
- * When a payload is passed it is padded with the length of bytes of the payload.
16
- * It gets 4 bytes to do so
17
- */
18
- export declare const CATALOGUE_SIZE_OF_PAYLOAD_BYTES = 4;
19
- /**
20
- * A utility function for translating a buffer to a list of catalogues items
21
- * that another node is willing to do.
22
- *
23
- * @param buffer The data buffer to read and translate
24
- */
25
- export declare function bufferToCatalogueItems(buffer: Buffer): CatalogueItem[];
26
- export declare function flipChoice(choice: CatalogueItem): CatalogueItem;
27
- /** Returns a number, which is feature-mask representing CatalogueItems */
28
- export declare function catalogueItemsToMask(catalogueItems: CatalogueItem[]): number;
29
- export declare class XyoNetworkProcedureCatalogue implements IXyoNetworkProcedureCatalogue {
30
- private catalogue;
31
- canDo(catalogueItem: CatalogueItem): boolean;
32
- getCurrentCatalogue(): CatalogueItem[];
33
- setCatalogue(catalogue: CatalogueItem[]): void;
34
- }
35
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAWA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,6BAA6B,EAAE,MAAM,UAAU,CAAA;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAE/G;;GAEG;AAEH,0EAA0E;AAC1E,eAAO,MAAM,yBAAyB,IAAI,CAAA;AAE1C,0EAA0E;AAC1E,eAAO,MAAM,4BAA4B,IAAI,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,+BAA+B,IAAI,CAAA;AAEhD;;;;;GAKG;AAEH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,EAAE,CAStE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAU/D;AAkBD,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAAC,cAAc,EAAE,aAAa,EAAE,UAEnE;AAED,qBAAa,4BAA6B,YAAW,6BAA6B;IAEhF,OAAO,CAAC,SAAS,CAAsB;IAEhC,KAAK,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO;IAI5C,mBAAmB,IAAI,aAAa,EAAE;IAItC,YAAY,CAAC,SAAS,EAAE,aAAa,EAAE;CAI/C"}