@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/dist/index.js DELETED
@@ -1,88 +0,0 @@
1
- "use strict";
2
- /*
3
- * @Author: XY | The Findables Company <ryanxyo>
4
- * @Date: Tuesday, 20th November 2018 10:18:42 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:15 pm
9
- * @License: All Rights Reserved
10
- * @Copyright: Copyright XY | The Findables Company
11
- */
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- const catalogue_item_1 = require("./catalogue-item");
14
- var catalogue_item_2 = require("./catalogue-item");
15
- exports.CatalogueItem = catalogue_item_2.CatalogueItem;
16
- var xyo_mock_network_pipe_1 = require("./xyo-mock-network-pipe");
17
- exports.XyoMockNetworkPipe = xyo_mock_network_pipe_1.XyoMockNetworkPipe;
18
- /**
19
- * Some very important numbers that factor into the catalogue negotiation protocol
20
- */
21
- /** The current number of bytes that encode the length if the catalogue */
22
- exports.CATALOGUE_LENGTH_IN_BYTES = 4;
23
- /** This number of bytes allowed to encode how big the catalogue can be */
24
- exports.CATALOGUE_SIZE_OF_SIZE_BYTES = 1;
25
- /**
26
- * When a payload is passed it is padded with the length of bytes of the payload.
27
- * It gets 4 bytes to do so
28
- */
29
- exports.CATALOGUE_SIZE_OF_PAYLOAD_BYTES = 4;
30
- /**
31
- * A utility function for translating a buffer to a list of catalogues items
32
- * that another node is willing to do.
33
- *
34
- * @param buffer The data buffer to read and translate
35
- */
36
- function bufferToCatalogueItems(buffer) {
37
- const values = readNumberFromBufferCatalogue(buffer);
38
- return [
39
- (catalogue_item_1.CatalogueItem.BOUND_WITNESS & values) > 0 ? catalogue_item_1.CatalogueItem.BOUND_WITNESS : null,
40
- (catalogue_item_1.CatalogueItem.TAKE_ORIGIN_CHAIN & values) > 0 ? catalogue_item_1.CatalogueItem.TAKE_ORIGIN_CHAIN : null,
41
- (catalogue_item_1.CatalogueItem.GIVE_ORIGIN_CHAIN & values) > 0 ? catalogue_item_1.CatalogueItem.GIVE_ORIGIN_CHAIN : null
42
- ]
43
- .filter(catalogueItem => catalogueItem !== null);
44
- }
45
- exports.bufferToCatalogueItems = bufferToCatalogueItems;
46
- function flipChoice(choice) {
47
- if (catalogue_item_1.CatalogueItem.GIVE_ORIGIN_CHAIN === choice) {
48
- return catalogue_item_1.CatalogueItem.TAKE_ORIGIN_CHAIN;
49
- }
50
- if (catalogue_item_1.CatalogueItem.TAKE_ORIGIN_CHAIN === choice) {
51
- return catalogue_item_1.CatalogueItem.GIVE_ORIGIN_CHAIN;
52
- }
53
- return choice;
54
- }
55
- exports.flipChoice = flipChoice;
56
- const readNumberFromBufferCatalogue = (buffer) => {
57
- if (buffer.length === 4) {
58
- return buffer.readUInt32BE(0);
59
- }
60
- if (buffer.length === 2) {
61
- return buffer.readUInt16BE(0);
62
- }
63
- if (buffer.length === 1) {
64
- return buffer.readUInt8(0);
65
- }
66
- return 0;
67
- };
68
- /** Returns a number, which is feature-mask representing CatalogueItems */
69
- function catalogueItemsToMask(catalogueItems) {
70
- return catalogueItems.reduce((sum, item) => sum + item, 0);
71
- }
72
- exports.catalogueItemsToMask = catalogueItemsToMask;
73
- class XyoNetworkProcedureCatalogue {
74
- constructor() {
75
- this.catalogue = [];
76
- }
77
- canDo(catalogueItem) {
78
- return this.catalogue.indexOf(catalogueItem) > -1;
79
- }
80
- getCurrentCatalogue() {
81
- return this.catalogue;
82
- }
83
- setCatalogue(catalogue) {
84
- this.catalogue = catalogue;
85
- }
86
- }
87
- exports.XyoNetworkProcedureCatalogue = XyoNetworkProcedureCatalogue;
88
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAEH,qDAAgD;AAGhD,mDAAgD;AAAvC,yCAAA,aAAa,CAAA;AACtB,iEAA4D;AAAnD,qDAAA,kBAAkB,CAAA;AAG3B;;GAEG;AAEH,0EAA0E;AAC7D,QAAA,yBAAyB,GAAG,CAAC,CAAA;AAE1C,0EAA0E;AAC7D,QAAA,4BAA4B,GAAG,CAAC,CAAA;AAE7C;;;GAGG;AACU,QAAA,+BAA+B,GAAG,CAAC,CAAA;AAEhD;;;;;GAKG;AAEH,SAAgB,sBAAsB,CAAC,MAAc;IACnD,MAAM,MAAM,GAAG,6BAA6B,CAAC,MAAM,CAAC,CAAA;IAEpD,OAAO;QACL,CAAC,8BAAa,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,8BAAa,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI;QAC/E,CAAC,8BAAa,CAAC,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,8BAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI;QACvF,CAAC,8BAAa,CAAC,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,8BAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI;KACxF;SACA,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,aAAa,KAAK,IAAI,CAAoB,CAAA;AACrE,CAAC;AATD,wDASC;AAED,SAAgB,UAAU,CAAC,MAAqB;IAC9C,IAAI,8BAAa,CAAC,iBAAiB,KAAK,MAAM,EAAE;QAC9C,OAAO,8BAAa,CAAC,iBAAiB,CAAA;KACvC;IAED,IAAI,8BAAa,CAAC,iBAAiB,KAAK,MAAM,EAAE;QAC9C,OAAO,8BAAa,CAAC,iBAAiB,CAAA;KACvC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAVD,gCAUC;AAED,MAAM,6BAA6B,GAAG,CAAC,MAAc,EAAU,EAAE;IAC/D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;KAC9B;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;KAC9B;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;KAC3B;IAED,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAED,0EAA0E;AAC1E,SAAgB,oBAAoB,CAAC,cAA+B;IAClE,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,EAAE,CAAC,CAAC,CAAA;AAC5D,CAAC;AAFD,oDAEC;AAED,MAAa,4BAA4B;IAAzC;QAEU,cAAS,GAAoB,EAAE,CAAA;IAczC,CAAC;IAZQ,KAAK,CAAC,aAA4B;QACvC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAA;IACnD,CAAC;IAEM,mBAAmB;QACxB,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IAEM,YAAY,CAAC,SAA0B;QAC5C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;CAEF;AAhBD,oEAgBC"}
@@ -1,18 +0,0 @@
1
- /// <reference types="node" />
2
- import { IXyoNetworkPipe, IXyoNetworkPeer } from './@types';
3
- import { IXyoSerializableObject } from "@xyo-network/serialization";
4
- export declare class XyoMockNetworkPipe implements IXyoNetworkPipe {
5
- private readonly intercepts;
6
- private readonly expectedMessages;
7
- networkHeuristics: IXyoSerializableObject[];
8
- sendCount: number;
9
- peer: IXyoNetworkPeer;
10
- initiationData: Buffer;
11
- constructor(intercepts: {
12
- [s: string]: (data: Buffer, awaitResponse?: boolean) => Promise<Buffer>;
13
- }, expectedMessages: Buffer[]);
14
- onPeerDisconnect(callback: (hasError: boolean) => void): () => void;
15
- send(data: Buffer, awaitResponse?: boolean): Promise<Buffer>;
16
- close(): Promise<void>;
17
- }
18
- //# sourceMappingURL=xyo-mock-network-pipe.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"xyo-mock-network-pipe.d.ts","sourceRoot":"","sources":["../src/xyo-mock-network-pipe.ts"],"names":[],"mappings":";AAWA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAEnE,qBAAa,kBAAmB,YAAW,eAAe;IAWtD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAX5B,iBAAiB,EAAE,sBAAsB,EAAE,CAAK;IAEhD,SAAS,SAAI;IAEb,IAAI,EAAE,eAAe,CAAK;IAG1B,cAAc,EAAE,MAAM,CAAA;gBAGV,UAAU,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;KAAC,EACtF,gBAAgB,EAAE,MAAM,EAAE;IAGtC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI;IAK7D,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAe5D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
@@ -1,52 +0,0 @@
1
- "use strict";
2
- /*
3
- * @Author: XY | The Findables Company <ryanxyo>
4
- * @Date: Thursday, 29th November 2018 4:23:34 pm
5
- * @Email: developer@xyfindables.com
6
- * @Filename: xyo-mock-network-pipe.ts
7
- * @Last modified by: ryanxyo
8
- * @Last modified time: Tuesday, 11th December 2018 9:34:57 am
9
- * @License: All Rights Reserved
10
- * @Copyright: Copyright XY | The Findables Company
11
- */
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- return new (P || (P = Promise))(function (resolve, reject) {
14
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
17
- step((generator = generator.apply(thisArg, _arguments || [])).next());
18
- });
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- class XyoMockNetworkPipe {
22
- constructor(intercepts, expectedMessages) {
23
- this.intercepts = intercepts;
24
- this.expectedMessages = expectedMessages;
25
- this.networkHeuristics = [];
26
- this.sendCount = 0;
27
- // @ts-ignore
28
- this.peer = {};
29
- }
30
- onPeerDisconnect(callback) {
31
- // tslint:disable-next-line:no-empty
32
- return () => { };
33
- }
34
- send(data, awaitResponse) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- const expected = this.expectedMessages.length > this.sendCount ? this.expectedMessages[this.sendCount] : undefined;
37
- if (expected) {
38
- expect(expected.equals(data)).toBe(true);
39
- }
40
- const returnMsg = (this.intercepts[this.sendCount] && this.intercepts[this.sendCount](data, awaitResponse)) || Buffer.alloc(0);
41
- this.sendCount += 1;
42
- return returnMsg;
43
- });
44
- }
45
- close() {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- return;
48
- });
49
- }
50
- }
51
- exports.XyoMockNetworkPipe = XyoMockNetworkPipe;
52
- //# sourceMappingURL=xyo-mock-network-pipe.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"xyo-mock-network-pipe.js","sourceRoot":"","sources":["../src/xyo-mock-network-pipe.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;AAMH,MAAa,kBAAkB;IAU7B,YACmB,UAAsF,EACtF,gBAA0B;QAD1B,eAAU,GAAV,UAAU,CAA4E;QACtF,qBAAgB,GAAhB,gBAAgB,CAAU;QAXtC,sBAAiB,GAA6B,EAAE,CAAA;QAEhD,cAAS,GAAG,CAAC,CAAA;QACpB,aAAa;QACN,SAAI,GAAoB,EAAE,CAAA;IAQ9B,CAAC;IAEG,gBAAgB,CAAC,QAAqC;QAC3D,oCAAoC;QACpC,OAAO,GAAG,EAAE,GAAG,CAAC,CAAA;IAClB,CAAC;IAEY,IAAI,CAAC,IAAY,EAAE,aAAuB;;YACrD,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;YAClH,IAAI,QAAQ,EAAE;gBACZ,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;aACzC;YAED,MAAM,SAAS,GAAG,CAChB,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,aAAa,CAAC,CACxF,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YAEpB,IAAI,CAAC,SAAS,IAAI,CAAC,CAAA;YAEnB,OAAO,SAAS,CAAA;QAClB,CAAC;KAAA;IAEY,KAAK;;YAChB,OAAM;QACR,CAAC;KAAA;CACF;AAtCD,gDAsCC"}
@@ -1,97 +0,0 @@
1
- /*
2
- * @Author: XY | The Findables Company <ryanxyo>
3
- * @Date: Tuesday, 11th December 2018 9:32:12 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:35 pm
8
- * @License: All Rights Reserved
9
- * @Copyright: Copyright XY | The Findables Company
10
- */
11
-
12
- import { CatalogueItem } from "../catalogue-item"
13
- import { IXyoSerializableObject } from "@xyo-network/serialization"
14
-
15
- /**
16
- * The necessary communication interfaces that xyo-nodes will
17
- * use to communicate to other nodes on a `network`
18
- */
19
-
20
- /**
21
- * A peer, meant to represent the meaningful attributes of the
22
- * node on the other side of the network pipe
23
- */
24
- export interface IXyoNetworkPeer {
25
-
26
- /**
27
- * Returns an id for a peer that should be consistent across multiple connections
28
- * to the same node
29
- */
30
- getTemporaryPeerId(): Buffer
31
- }
32
-
33
- /**
34
- * An interface that allows the network to delegate to implementer of
35
- * this interface as to which operations the xyo-node supports
36
- */
37
- export interface IXyoNetworkProcedureCatalogue {
38
-
39
- /**
40
- * Since not all operations are symmetric, a `canDo` interface
41
- * is required so that an XyoNode can agree to partake in operation
42
- * where one party is one role and the other party is the other role.
43
- *
44
- * For example, an archivist can take origin-chains but does not
45
- * want to give origin-chains. So if an archivist is queried with
46
- * `canDo(TAKE_ORIGIN_CHAIN)` it should return true
47
- */
48
-
49
- canDo(catalogueItem: CatalogueItem): boolean
50
-
51
- /**
52
- * The list of current `CatalogueItems` the `XyoNode` can perform
53
- */
54
-
55
- getCurrentCatalogue(): CatalogueItem[]
56
-
57
- setCatalogue(catalogue: CatalogueItem[]): void
58
- }
59
-
60
- /**
61
- * An XyoNetworkPipe is a communication channel between two
62
- * nodes and will be used the fundamental way that two
63
- * nodes communicate with one another
64
- */
65
- export interface IXyoNetworkPipe {
66
-
67
- /** A representation of the peer on the other side of the pipe */
68
- peer: IXyoNetworkPeer
69
-
70
- /** Any data that was initially passed to start an interaction */
71
- initiationData: Buffer | undefined
72
-
73
- networkHeuristics: IXyoSerializableObject[]
74
-
75
- /** A consumer may register a handler for when the other peer disconnects */
76
- onPeerDisconnect(callback: (hasError: boolean) => void): () => void
77
-
78
- /** Sends message to the peer. If awaitResponse is true it will wait for a message from the other node */
79
- send (data: Buffer, awaitResponse?: boolean): Promise<Buffer | undefined>
80
-
81
- /** Closes the connection to the peer */
82
- close(): Promise<void>
83
-
84
- }
85
-
86
- /**
87
- * A network-provider will try to find peers who are compatible with the catalogue passed in.
88
- * Once a peer is found, it returns a pipe to send messages on.
89
- */
90
- export interface IXyoNetworkProvider {
91
-
92
- /** Attempts to find a peer with a compatible catalogue. */
93
- find(catalogue: IXyoNetworkProcedureCatalogue): Promise<IXyoNetworkPipe>
94
-
95
- /** Tells the network-provider to stop finding peers */
96
- stopServer(): Promise<void>
97
- }
@@ -1,21 +0,0 @@
1
- /*
2
- * @Author: XY | The Findables Company <ryanxyo>
3
- * @Date: Tuesday, 11th December 2018 9:33:01 am
4
- * @Email: developer@xyfindables.com
5
- * @Filename: catalogue-item.ts
6
- * @Last modified by: ryanxyo
7
- * @Last modified time: Tuesday, 22nd January 2019 10:19:26 am
8
- * @License: All Rights Reserved
9
- * @Copyright: Copyright XY | The Findables Company
10
- */
11
-
12
- /**
13
- * The catalogue items this node knows about
14
- */
15
- export enum CatalogueItem {
16
- BOUND_WITNESS = Math.pow(2, 0),
17
- TAKE_ORIGIN_CHAIN = Math.pow(2, 1),
18
- GIVE_ORIGIN_CHAIN = Math.pow(2, 2),
19
- TAKE_REQUESTED_BLOCKS = Math.pow(2, 3),
20
- GIVE_REQUESTED_BLOCKS = Math.pow(2, 4)
21
- }
@@ -1,54 +0,0 @@
1
- /*
2
- * @Author: XY | The Findables Company <ryanxyo>
3
- * @Date: Thursday, 29th November 2018 4:23:34 pm
4
- * @Email: developer@xyfindables.com
5
- * @Filename: xyo-mock-network-pipe.ts
6
- * @Last modified by: ryanxyo
7
- * @Last modified time: Tuesday, 11th December 2018 9:34:57 am
8
- * @License: All Rights Reserved
9
- * @Copyright: Copyright XY | The Findables Company
10
- */
11
-
12
- import { IXyoNetworkPipe, IXyoNetworkPeer } from './@types'
13
- import { CatalogueItem } from './catalogue-item'
14
- import { IXyoSerializableObject } from "@xyo-network/serialization"
15
-
16
- export class XyoMockNetworkPipe implements IXyoNetworkPipe {
17
- public networkHeuristics: IXyoSerializableObject[] = []
18
-
19
- public sendCount = 0
20
- // @ts-ignore
21
- public peer: IXyoNetworkPeer = {}
22
-
23
- // @ts-ignore
24
- public initiationData: Buffer
25
-
26
- constructor(
27
- private readonly intercepts: { [s: string]: (data: Buffer, awaitResponse?: boolean) => Promise<Buffer>},
28
- private readonly expectedMessages: Buffer[]
29
- ) {}
30
-
31
- public onPeerDisconnect(callback: (hasError: boolean) => void): () => void {
32
- // tslint:disable-next-line:no-empty
33
- return () => { }
34
- }
35
-
36
- public async send(data: Buffer, awaitResponse?: boolean): Promise<Buffer> {
37
- const expected = this.expectedMessages.length > this.sendCount ? this.expectedMessages[this.sendCount] : undefined
38
- if (expected) {
39
- expect(expected.equals(data)).toBe(true)
40
- }
41
-
42
- const returnMsg = (
43
- this.intercepts[this.sendCount] && this.intercepts[this.sendCount](data, awaitResponse)
44
- ) || Buffer.alloc(0)
45
-
46
- this.sendCount += 1
47
-
48
- return returnMsg
49
- }
50
-
51
- public async close(): Promise<void> {
52
- return
53
- }
54
- }
package/tsconfig.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es6",
4
- "module": "commonjs",
5
- "lib": ["esnext"],
6
- "declaration": true,
7
- "declarationMap": true,
8
- "sourceMap": true,
9
- "strict": true,
10
- "composite": true,
11
- "esModuleInterop": true,
12
- "noImplicitAny": true,
13
- "moduleResolution": "node",
14
- "outDir": "dist",
15
- "rootDir": "src"
16
- },
17
- "exclude": [
18
- "node_modules",
19
- "src/**/test/*",
20
- "src/**/spec",
21
- "src/**/*.spec.ts"
22
- ],
23
- "include": ["src/**/*"]
24
- }