@dxos/hypercore 0.1.12 → 0.1.14

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 (87) hide show
  1. package/dist/lib/browser/index.mjs +106 -0
  2. package/dist/lib/browser/index.mjs.map +7 -0
  3. package/dist/lib/browser/meta.json +1 -0
  4. package/dist/lib/node/index.cjs +147 -0
  5. package/dist/lib/node/index.cjs.map +7 -0
  6. package/dist/lib/node/meta.json +1 -0
  7. package/dist/{src → types/src}/crypto.d.ts +0 -0
  8. package/dist/types/src/crypto.d.ts.map +1 -0
  9. package/dist/{src → types/src}/defaults.d.ts +0 -0
  10. package/dist/types/src/defaults.d.ts.map +1 -0
  11. package/dist/{src → types/src}/hypercore-factory.d.ts +0 -0
  12. package/dist/types/src/hypercore-factory.d.ts.map +1 -0
  13. package/dist/{src → types/src}/hypercore-factory.test.d.ts +0 -0
  14. package/dist/types/src/hypercore-factory.test.d.ts.map +1 -0
  15. package/dist/{src → types/src}/hypercore-protocol.test.d.ts +0 -0
  16. package/dist/types/src/hypercore-protocol.test.d.ts.map +1 -0
  17. package/dist/{src → types/src}/hypercore.test.d.ts +0 -0
  18. package/dist/{src → types/src}/hypercore.test.d.ts.map +1 -1
  19. package/dist/{src → types/src}/index.d.ts +0 -0
  20. package/dist/types/src/index.d.ts.map +1 -0
  21. package/dist/{src → types/src}/iterator.d.ts +0 -0
  22. package/dist/types/src/iterator.d.ts.map +1 -0
  23. package/dist/{src → types/src}/iterator.test.d.ts +0 -0
  24. package/dist/{src → types/src}/iterator.test.d.ts.map +1 -1
  25. package/dist/{src → types/src}/multiplexer.d.ts +0 -0
  26. package/dist/types/src/multiplexer.d.ts.map +1 -0
  27. package/dist/{src → types/src}/multiplexer.test.d.ts +0 -0
  28. package/dist/types/src/multiplexer.test.d.ts.map +1 -0
  29. package/dist/{src → types/src}/replicate.test.d.ts +0 -0
  30. package/dist/{src → types/src}/replicate.test.d.ts.map +1 -1
  31. package/dist/{src → types/src}/streams.test.d.ts +0 -0
  32. package/dist/{src → types/src}/streams.test.d.ts.map +1 -1
  33. package/dist/{src → types/src}/testing.d.ts +2 -3
  34. package/dist/types/src/testing.d.ts.map +1 -0
  35. package/dist/types/src/util.d.ts +2 -0
  36. package/dist/types/src/util.d.ts.map +1 -0
  37. package/package.json +13 -15
  38. package/src/crypto.ts +1 -1
  39. package/src/hypercore-factory.test.ts +5 -3
  40. package/src/hypercore-factory.ts +2 -2
  41. package/src/hypercore-protocol.test.ts +5 -4
  42. package/src/hypercore.test.ts +4 -3
  43. package/src/iterator.test.ts +3 -2
  44. package/src/multiplexer.test.ts +6 -4
  45. package/src/multiplexer.ts +1 -1
  46. package/src/replicate.test.ts +5 -4
  47. package/src/streams.test.ts +4 -3
  48. package/src/testing.ts +0 -3
  49. package/src/util.ts +7 -0
  50. package/dist/src/crypto.d.ts.map +0 -1
  51. package/dist/src/crypto.js +0 -45
  52. package/dist/src/crypto.js.map +0 -1
  53. package/dist/src/defaults.d.ts.map +0 -1
  54. package/dist/src/defaults.js +0 -44
  55. package/dist/src/defaults.js.map +0 -1
  56. package/dist/src/hypercore-factory.d.ts.map +0 -1
  57. package/dist/src/hypercore-factory.js +0 -44
  58. package/dist/src/hypercore-factory.js.map +0 -1
  59. package/dist/src/hypercore-factory.test.d.ts.map +0 -1
  60. package/dist/src/hypercore-factory.test.js +0 -46
  61. package/dist/src/hypercore-factory.test.js.map +0 -1
  62. package/dist/src/hypercore-protocol.test.d.ts.map +0 -1
  63. package/dist/src/hypercore-protocol.test.js +0 -191
  64. package/dist/src/hypercore-protocol.test.js.map +0 -1
  65. package/dist/src/hypercore.test.js +0 -79
  66. package/dist/src/hypercore.test.js.map +0 -1
  67. package/dist/src/index.d.ts.map +0 -1
  68. package/dist/src/index.js +0 -24
  69. package/dist/src/index.js.map +0 -1
  70. package/dist/src/iterator.d.ts.map +0 -1
  71. package/dist/src/iterator.js +0 -37
  72. package/dist/src/iterator.js.map +0 -1
  73. package/dist/src/iterator.test.js +0 -61
  74. package/dist/src/iterator.test.js.map +0 -1
  75. package/dist/src/multiplexer.d.ts.map +0 -1
  76. package/dist/src/multiplexer.js +0 -103
  77. package/dist/src/multiplexer.js.map +0 -1
  78. package/dist/src/multiplexer.test.d.ts.map +0 -1
  79. package/dist/src/multiplexer.test.js +0 -142
  80. package/dist/src/multiplexer.test.js.map +0 -1
  81. package/dist/src/replicate.test.js +0 -197
  82. package/dist/src/replicate.test.js.map +0 -1
  83. package/dist/src/streams.test.js +0 -65
  84. package/dist/src/streams.test.js.map +0 -1
  85. package/dist/src/testing.d.ts.map +0 -1
  86. package/dist/src/testing.js +0 -36
  87. package/dist/src/testing.js.map +0 -1
@@ -10,13 +10,15 @@ import { latch } from '@dxos/async';
10
10
  import { createKeyPair } from '@dxos/crypto';
11
11
  import { PublicKey } from '@dxos/keys';
12
12
  import { log } from '@dxos/log';
13
+ import { describe, test } from '@dxos/test';
13
14
 
14
15
  import { HypercoreFactory } from './hypercore-factory';
15
16
  import { Multiplexer } from './multiplexer';
16
- import { noop, py } from './testing';
17
+ import { noop } from './testing';
18
+ import { py } from './util';
17
19
 
18
- describe('Multiplexing', function () {
19
- it.only('multiplexes feeds', async function () {
20
+ describe('Multiplexing', () => {
21
+ test('multiplexes feeds', async () => {
20
22
  const plex1 = new Multiplexer('A');
21
23
  const plex2 = new Multiplexer('B');
22
24
 
@@ -82,7 +84,7 @@ describe('Multiplexing', function () {
82
84
  expect(count).to.eq(numMessages);
83
85
  });
84
86
 
85
- it('pipelines', async function () {
87
+ test('pipelines', async () => {
86
88
  const factory = new HypercoreFactory();
87
89
  const { publicKey, secretKey } = createKeyPair();
88
90
  const core1 = factory.createFeed(publicKey, { secretKey });
@@ -2,9 +2,9 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import assert from 'assert';
6
5
  import { Hypercore } from 'hypercore';
7
6
  import { ProtocolStream } from 'hypercore-protocol';
7
+ import assert from 'node:assert';
8
8
  import { PassThrough, Transform, Writable } from 'streamx';
9
9
 
10
10
  import { latch, Trigger } from '@dxos/async';
@@ -8,6 +8,7 @@ import faker from 'faker';
8
8
  import { latch } from '@dxos/async';
9
9
  import { createKeyPair } from '@dxos/crypto';
10
10
  import { log } from '@dxos/log';
11
+ import { describe, test } from '@dxos/test';
11
12
 
12
13
  import { HypercoreFactory } from './hypercore-factory';
13
14
  import { createReadable } from './iterator';
@@ -15,11 +16,11 @@ import { batch, createDataItem, TestDataItem } from './testing';
15
16
 
16
17
  const noop = () => {};
17
18
 
18
- describe('Replication', function () {
19
+ describe('Replication', () => {
19
20
  const factory1 = new HypercoreFactory();
20
21
  const factory2 = new HypercoreFactory();
21
22
 
22
- it('replicates feeds', async function () {
23
+ test('replicates feeds', async () => {
23
24
  const { publicKey, secretKey } = createKeyPair();
24
25
  const core1 = factory1.createFeed(publicKey, { secretKey });
25
26
  const core2 = factory2.createFeed(publicKey);
@@ -72,7 +73,7 @@ describe('Replication', function () {
72
73
  expect(core2.stats.totals.downloadedBlocks).to.eq(numBlocks);
73
74
  });
74
75
 
75
- it('replicates feeds in batches', async function () {
76
+ test('replicates feeds in batches', async () => {
76
77
  const numBlocks = 100;
77
78
 
78
79
  // Replicating feeds must have the same public key.
@@ -171,7 +172,7 @@ describe('Replication', function () {
171
172
  }
172
173
  }).timeout(5_000);
173
174
 
174
- it('replicates feeds with read stream', async function () {
175
+ test('replicates feeds with read stream', async () => {
175
176
  const numBlocks = 10;
176
177
 
177
178
  const { publicKey, secretKey } = createKeyPair();
@@ -8,11 +8,12 @@ import { Writable } from 'streamx';
8
8
  import { latch } from '@dxos/async';
9
9
  import { createKeyPair } from '@dxos/crypto';
10
10
  import { log } from '@dxos/log';
11
+ import { describe, test } from '@dxos/test';
11
12
 
12
13
  import { HypercoreFactory } from './hypercore-factory';
13
14
 
14
- describe('Streams', function () {
15
- it('reads from stream', async function () {
15
+ describe('Streams', () => {
16
+ test('reads from stream', async () => {
16
17
  const factory = new HypercoreFactory<string>();
17
18
  const { publicKey, secretKey } = createKeyPair();
18
19
  const core = factory.createFeed(publicKey, { secretKey });
@@ -52,7 +53,7 @@ describe('Streams', function () {
52
53
  }
53
54
  });
54
55
 
55
- it('feed closed while stream is open', async function () {
56
+ test('feed closed while stream is open', async () => {
56
57
  const factory = new HypercoreFactory<string>();
57
58
  const { publicKey, secretKey } = createKeyPair();
58
59
  const core = factory.createFeed(publicKey, { secretKey });
package/src/testing.ts CHANGED
@@ -3,12 +3,9 @@
3
3
  //
4
4
 
5
5
  import faker from 'faker';
6
- import util from 'node:util';
7
6
 
8
7
  export const noop = () => {};
9
8
 
10
- export const py = (obj: any, fn: Function) => util.promisify(fn.bind(obj));
11
-
12
9
  // TODO(burdon): Replace with proto def.
13
10
  export type TestDataItem = { id: number; text: string };
14
11
 
package/src/util.ts ADDED
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import util from 'node:util';
6
+
7
+ export const py = (obj: any, fn: Function) => util.promisify(fn.bind(obj));
@@ -1 +0,0 @@
1
- {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/crypto.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAG1D,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAmB,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,mBAAmB,kDAG9B,CAAC;AAEH;;GAEG;AAEH,eAAO,MAAM,YAAY,WAAY,MAAM,aAAa,SAAS,KAAG,MAqBnE,CAAC"}
@@ -1,45 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2022 DXOS.org
4
- //
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.createCrypto = exports.createCodecEncoding = void 0;
10
- const assert_1 = __importDefault(require("assert"));
11
- const node_util_1 = require("node:util");
12
- const crypto_1 = require("@dxos/crypto");
13
- /**
14
- * Create encoding (e.g., from protobuf codec).
15
- */
16
- const createCodecEncoding = (codec) => ({
17
- encode: (obj) => Buffer.from(codec.encode(obj)),
18
- decode: (buffer) => codec.decode(buffer)
19
- });
20
- exports.createCodecEncoding = createCodecEncoding;
21
- /**
22
- * Create a custom hypercore crypto signer.
23
- */
24
- // TODO(burdon): Create test without adding deps.
25
- const createCrypto = (signer, publicKey) => {
26
- (0, assert_1.default)(signer);
27
- (0, assert_1.default)(publicKey);
28
- return {
29
- sign: (message, secretKey, cb) => {
30
- (0, node_util_1.callbackify)(signer.sign.bind(signer))(publicKey, message, (err, result) => {
31
- if (err) {
32
- cb(err, null);
33
- return;
34
- }
35
- cb(null, Buffer.from(result));
36
- });
37
- },
38
- verify: async (message, signature, key, cb) => {
39
- // NOTE: Uses the public key passed into function.
40
- (0, node_util_1.callbackify)(crypto_1.verifySignature)(publicKey, message, signature, cb);
41
- }
42
- };
43
- };
44
- exports.createCrypto = createCrypto;
45
- //# sourceMappingURL=crypto.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/crypto.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,oDAA4B;AAE5B,yCAAwC;AAGxC,yCAAuD;AAGvD;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAI,KAAe,EAA4B,EAAE,CAAC,CAAC;IACpF,MAAM,EAAE,CAAC,GAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAClD,MAAM,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;CACjD,CAAC,CAAC;AAH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yBAAyB,EAAE,kBAEvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,kBAOrC,CAAC"}
@@ -1,44 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2022 DXOS.org
4
- //
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.defaultReplicateOptions = exports.defaultWriteStreamOptions = exports.defaultReadStreamOptions = exports.defaultFeedOptions = void 0;
7
- /**
8
- * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-feed--hypercorestorage-key-options
9
- */
10
- exports.defaultFeedOptions = {
11
- createIfMissing: true,
12
- valueEncoding: 'binary'
13
- };
14
- /**
15
- * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatereadstreamoptions
16
- */
17
- exports.defaultReadStreamOptions = {
18
- start: 0,
19
- end: Infinity,
20
- snapshot: true,
21
- tail: false,
22
- live: false,
23
- timeout: 0,
24
- wait: true,
25
- batch: 1
26
- };
27
- /**
28
- * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatewritestreamopts
29
- */
30
- exports.defaultWriteStreamOptions = {
31
- maxBlockSize: Infinity
32
- };
33
- /**
34
- * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedreplicateisinitiator-options
35
- */
36
- exports.defaultReplicateOptions = {
37
- live: false,
38
- ack: false,
39
- download: true,
40
- upload: true,
41
- encrypted: true,
42
- noise: true
43
- };
44
- //# sourceMappingURL=defaults.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/defaults.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAIF;;GAEG;AACU,QAAA,kBAAkB,GAAqB;IAClD,eAAe,EAAE,IAAI;IACrB,aAAa,EAAE,QAAQ;CACxB,CAAC;AAEF;;GAEG;AACU,QAAA,wBAAwB,GAAsB;IACzD,KAAK,EAAE,CAAC;IACR,GAAG,EAAE,QAAQ;IACb,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,CAAC;CACT,CAAC;AAEF;;GAEG;AACU,QAAA,yBAAyB,GAAuB;IAC3D,YAAY,EAAE,QAAQ;CACvB,CAAC;AAEF;;GAEG;AACU,QAAA,uBAAuB,GAAuB;IACzD,IAAI,EAAE,KAAK;IACX,GAAG,EAAE,KAAK;IACV,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,IAAI;IACf,KAAK,EAAE,IAAI;CACZ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hypercore-factory.d.ts","sourceRoot":"","sources":["../../src/hypercore-factory.ts"],"names":[],"mappings":";AAKA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7D,OAAO,EAAiB,SAAS,EAAe,MAAM,6BAA6B,CAAC;AAIpF;;GAEG;AACH,qBAAa,gBAAgB,CAAC,CAAC;IAG3B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBADT,KAAK,GAAE,SAAsE,EAC7E,QAAQ,CAAC,wCAAkB;IAK9C;;;;OAIG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC,CAAC,CAAC;IAMvE;;OAEG;IACG,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;CAKrF"}
@@ -1,44 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2022 DXOS.org
4
- //
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.HypercoreFactory = void 0;
10
- const assert_1 = __importDefault(require("assert"));
11
- const hypercore_1 = __importDefault(require("hypercore"));
12
- const random_access_storage_1 = require("@dxos/random-access-storage");
13
- const testing_1 = require("./testing");
14
- /**
15
- * Creates feeds with default properties.
16
- */
17
- class HypercoreFactory {
18
- // prettier-ignore
19
- constructor(_root = (0, random_access_storage_1.createStorage)({ type: random_access_storage_1.StorageType.RAM }).createDirectory(), _options) {
20
- this._root = _root;
21
- this._options = _options;
22
- (0, assert_1.default)(this._root);
23
- }
24
- /**
25
- * Creates a feed using a storage factory prefixed with the feed's key.
26
- * NOTE: We have to use our `random-access-storage` implementation since the native ones
27
- * do not behave uniformly across platforms.
28
- */
29
- createFeed(publicKey, options) {
30
- const directory = this._root.createDirectory(publicKey.toString());
31
- const storage = (filename) => directory.getOrCreateFile(filename).native;
32
- return (0, hypercore_1.default)(storage, publicKey, Object.assign({}, this._options, options));
33
- }
34
- /**
35
- * Creates and opens a feed.
36
- */
37
- async openFeed(publicKey, options) {
38
- const feed = this.createFeed(publicKey, options);
39
- await (0, testing_1.py)(feed, feed.open)(); // TODO(burdon): Sometimes strange bug if done inside function.
40
- return feed;
41
- }
42
- }
43
- exports.HypercoreFactory = HypercoreFactory;
44
- //# sourceMappingURL=hypercore-factory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hypercore-factory.js","sourceRoot":"","sources":["../../src/hypercore-factory.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,oDAA4B;AAC5B,0DAAkC;AAGlC,uEAAoF;AAEpF,uCAA+B;AAE/B;;GAEG;AACH,MAAa,gBAAgB;IAC3B,kBAAkB;IAClB,YACmB,QAAmB,IAAA,qCAAa,EAAC,EAAE,IAAI,EAAE,mCAAW,CAAC,GAAG,EAAE,CAAC,CAAC,eAAe,EAAE,EAC7E,QAA2B;QAD3B,UAAK,GAAL,KAAK,CAAwE;QAC7E,aAAQ,GAAR,QAAQ,CAAmB;QAE5C,IAAA,gBAAM,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,UAAU,CAAC,SAAiB,EAAE,OAA0B;QACtD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnE,MAAM,OAAO,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,SAAS,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;QACjF,OAAO,IAAA,mBAAS,EAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAClF,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,SAAiB,EAAE,OAA0B;QAC1D,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACjD,MAAM,IAAA,YAAE,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,+DAA+D;QAC5F,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA5BD,4CA4BC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hypercore-factory.test.d.ts","sourceRoot":"","sources":["../../src/hypercore-factory.test.ts"],"names":[],"mappings":""}
@@ -1,46 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2019 DXOS.org
4
- //
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const chai_1 = require("chai");
10
- const faker_1 = __importDefault(require("faker"));
11
- const crypto_1 = require("@dxos/crypto");
12
- const hypercore_factory_1 = require("./hypercore-factory");
13
- const testing_1 = require("./testing");
14
- describe('HypercoreFactory', function () {
15
- it('appends to, and read from, multiple feeds', async function () {
16
- const factory = new hypercore_factory_1.HypercoreFactory();
17
- const numFeeds = 10;
18
- const numBlocks = 100;
19
- // Create feeds.
20
- const feeds = await Promise.all(Array.from({ length: numFeeds }).map(async () => {
21
- const { publicKey, secretKey } = (0, crypto_1.createKeyPair)();
22
- return await factory.openFeed(publicKey, { secretKey });
23
- }));
24
- // Write data.
25
- {
26
- const data = Array.from({ length: numBlocks }).map((_, i) => (0, testing_1.createDataItem)(i));
27
- for await (const datum of data) {
28
- const feed = faker_1.default.random.arrayElement(feeds);
29
- await (0, testing_1.py)(feed, feed.append)(Buffer.from(JSON.stringify(datum)));
30
- }
31
- }
32
- // Test.
33
- {
34
- const total = feeds.reduce((result, feed) => result + feed.length, 0);
35
- (0, chai_1.expect)(total).to.eq(numBlocks);
36
- const feed = faker_1.default.random.arrayElement(feeds);
37
- const block1 = await (0, testing_1.py)(feed, feed.head)();
38
- const block2 = await (0, testing_1.py)(feed, feed.get)(feed.length - 1);
39
- (0, chai_1.expect)(block1.toString()).to.eq(block2.toString());
40
- const blocks = await (0, testing_1.py)(feed, feed.getBatch)(0, feed.length);
41
- (0, chai_1.expect)(blocks.length).to.eq(feed.length);
42
- }
43
- await Promise.all(feeds.map((feed) => feed.close()));
44
- });
45
- });
46
- //# sourceMappingURL=hypercore-factory.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hypercore-factory.test.js","sourceRoot":"","sources":["../../src/hypercore-factory.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;AAEF,+BAA8B;AAC9B,kDAA0B;AAE1B,yCAA6C;AAE7C,2DAAuD;AACvD,uCAA+C;AAE/C,QAAQ,CAAC,kBAAkB,EAAE;IAC3B,EAAE,CAAC,2CAA2C,EAAE,KAAK;QACnD,MAAM,OAAO,GAAG,IAAI,oCAAgB,EAAE,CAAC;QAEvC,MAAM,QA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AAC,CAAC;YAC9C,MAAM,MAAM,GAAG,MAAM,IAAA,YAAE,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3C,MAAM,MAAM,GAAG,MAAM,IAAA,YAAE,EAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YACzD,IAAA,aAAM,EAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;YAEnD,MAAM,MAAM,GAAG,MAAM,IAAA,YAAE,EAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC7D,IAAA,aAAM,EAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SAC1C;QAED,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hypercore-protocol.test.d.ts","sourceRoot":"","sources":["../../src/hypercore-protocol.test.ts"],"names":[],"mappings":""}
@@ -1,191 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2020 DXOS.org
4
- //
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const chai_1 = require("chai");
10
- const faker_1 = __importDefault(require("faker"));
11
- const hypercore_protocol_1 = __importDefault(require("hypercore-protocol"));
12
- const async_1 = require("@dxos/async");
13
- const crypto_1 = require("@dxos/crypto");
14
- const keys_1 = require("@dxos/keys");
15
- const log_1 = require("@dxos/log");
16
- const hypercore_factory_1 = require("./hypercore-factory");
17
- // TODO(burdon): Test encoding.
18
- // TODO(burdon): Simulate multiple peers and broadcast.
19
- describe('ProtocolStream', function () {
20
- it('protocol stream handshake completes', async function () {
21
- const [handshake, setHandshake] = (0, async_1.latch)({ count: 2 });
22
- const stream1 = new hypercore_protocol_1.default(true, {
23
- onhandshake: () => {
24
- (0, log_1.log)('onhandshake', { key: keys_1.PublicKey.from(stream1.publicKey) }, { file: "packages/common/hypercore/src/hypercore-protocol.test.ts", line: 25, scope: this, bugcheck: "If you see this message then it means that the source code preprocessor for @dxos/log is broken. It probably has misinterpreted an unrelated call for a logger invocation.", callSite: (fn, args) => fn(...args) });
25
- setHandshake();
26
- }
27
- });
28
- const stream2 = new hypercore_protocol_1.default(false, {
29
- onhandshake: () => {
30
- (0, log_1.log)('onhandshake', { key: keys_1.PublicKey.from(stream2.publicKey) }, { file: "packages/common/hypercore/src/hypercore-protocol.test.ts", line: 32, scope: this, bugcheck: "If you see this message then it means that the source code preprocessor for @dxos/log is broken. It probably has misinterpreted an unrelated call for a logger invocation.", callSite: (fn, args) => fn(...args) });
31
- setHandshake();
32
- }
33
- });
34
- const [closed, setClosed] = (0, async_1.latch)({ count: 2 });
35
- const pipeline = stream1.pipe(stream2, setClosed).pipe(stream1, setClosed);
36
- await handshake();
37
- pipeline.destroy();
38
- await closed();
39
- });
40
- it('protocol stream handshake completes with feeds', async function () {
41
- //
42
- // Pipeline and handshake.
43
- //
44
- const [handshake, setHandshake] = (0, async_1.latch)({ count: 2 });
45
- const stream1 = new hypercore_protocol_1.default(true, {
46
- onhandshake: () => {
47
- (0, log_1.log)('onhandshake', { key: keys_1.PublicKey.from(stream1.publicKey) }, { file: "packages/common/hypercore/src/hypercore-protocol.test.ts", line: 54, scope: this, bugcheck: "If you see this message then it means that the source code preprocessor for @dxos/log is broken. It probably has misinterpreted an unrelated call for a logger invocation.", callSite: (fn, args) => fn(...args) });
48
- setHandshake();
49
- }
50
- });
51
- const stream2 = new hypercore_protocol_1.default(false, {
52
- onhandshake: () => {
53
- (0, log_1.log)('onhandshake', { key: keys_1.PublicKey.from(stream2.publicKey) }, { file: "packages/common/hypercore/src/hypercore-protocol.test.ts", line: 61, scope: this, bugcheck: "If you see this message then it means that the source code preprocessor for @dxos/log is broken. It probably has misinterpreted an unrelated call for a logger invocation.", callSite: (fn, args) => fn(...args) });
54
- setHandshake();
55
- }
56
- });
57
- const [streamClosed, setStreamClosed] = (0, async_1.latch)({ count: 2 });
58
- const pipeline = stream1.pipe(stream2, setStreamClosed).pipe(stream1, setStreamClosed);
59
- await handshake();
60
- //
61
- // Hypercore replication.
62
- // https://github.com/hypercore-protocol/hypercore-protocol#const-channel--streamopenkey-handlers
63
- //
64
- const factory = new hypercore_factory_1.HypercoreFactory();
65
- const { publicKey, secretKey } = (0, crypto_1.createKeyPair)();
66
- const core1 = factory.createFeed(publicKey, { secretKey });
67
- const core2 = factory.createFeed(publicKey);
68
- const [feedsClosed, setFeedClosed] = (0, async_1.latch)({ count: 2 });
69
- core1.once('close', setFeedClosed);
70
- core2.once('close', setFeedClosed);
71
- core1.replicate(true, { stream: stream1, live: true });
72
- core2.replicate(false, { stream: stream2, live: true });
73
- //
74
- // Extensions.
75
- //
76
- const [received, incMessage] = (0, async_1.latch)({ count: 2 });
77
- const extension1 = stream1.registerExtension('stream-extension', {
78
- onmessage: (msg) => {
79
- (0, log_1.log)('onmessage', {
80
- key: keys_1.PublicKey.from(stream1.publicKey),
81
- msg: msg.toString()
82
- }, { file: "packages/common/hypercore/src/hypercore-protocol.test.ts", line: 95, scope: this, bugcheck: "If you see this message then it means that the source code preprocessor for @dxos/log is broken. It probably has misinterpreted an unrelated call for a logger invocation.", callSite: (fn, args) => fn(...args) });
83
- incMessage();
84
- }
85
- });
86
- const extension2 = stream2.registerExtension('stream-extension', {
87
- onmessage: (msg) => {
88
- (0, log_1.log)('onmessage', {
89
- key: keys_1.PublicKey.from(stream2.publicKey),
90
- msg: msg.toString()
91
- }, { file: "packages/common/hypercore/src/hypercore-protocol.test.ts", line: 105, scope: this, bugcheck: "If you see this message then it means that the source code preprocessor for @dxos/log is broken. It probably has misinterpreted an unrelated call for a logger invocation.", callSite: (fn, args) => fn(...args) });
92
- incMessage();
93
- }
94
- });
95
- extension1.send(Buffer.from('message-1'));
96
- extension2.send(Buffer.from('message-2'));
97
- await received();
98
- //
99
- // Replication.
100
- //
101
- const [synced, setSynced] = (0, async_1.latch)({ count: 1 });
102
- {
103
- const numBlocks = 10;
104
- Array.from(Array(numBlocks)).forEach((_, i) => {
105
- core1.append(`block-${i}`, () => { });
106
- });
107
- core2.on('sync', () => {
108
- (0, log_1.log)('sync', {
109
- core: { key: keys_1.PublicKey.from(core2.key), length: core2.length }
110
- }, { file: "packages/common/hypercore/src/hypercore-protocol.test.ts", line: 130, scope: this, bugcheck: "If you see this message then it means that the source code preprocessor for @dxos/log is broken. It probably has misinterpreted an unrelated call for a logger invocation.", callSite: (fn, args) => fn(...args) });
111
- (0, chai_1.expect)(core2.length).to.eq(numBlocks);
112
- setSynced();
113
- });
114
- }
115
- await synced();
116
- //
117
- // Close.
118
- //
119
- // Gracefully shutdown.
120
- pipeline.finalize();
121
- await streamClosed();
122
- // TODO(burdon): Destroy and finalize don't seem to close the feeds.
123
- (0, chai_1.expect)(core1.closed).to.be.false;
124
- (0, chai_1.expect)(core2.closed).to.be.false;
125
- core1.close(setFeedClosed);
126
- core2.close(setFeedClosed);
127
- await feedsClosed();
128
- (0, chai_1.expect)(core1.closed).to.be.true;
129
- (0, chai_1.expect)(core2.closed).to.be.true;
130
- });
131
- it('multi-feed multiplexing', async function () {
132
- //
133
- // Handshake.
134
- //
135
- const [handshake, setHandshake] = (0, async_1.latch)({ count: 2 });
136
- const stream1 = new hypercore_protocol_1.default(true, { onhandshake: setHandshake });
137
- const stream2 = new hypercore_protocol_1.default(false, { onhandshake: setHandshake });
138
- const [streamClosed, setStreamClosed] = (0, async_1.latch)({ count: 2 });
139
- const pipeline = stream1.pipe(stream2, setStreamClosed).pipe(stream1, setStreamClosed);
140
- await handshake();
141
- //
142
- // Feeds.
143
- //
144
- const factory = new hypercore_factory_1.HypercoreFactory();
145
- const numFeeds = 5;
146
- const [feedsClosed, setFeedClosed] = (0, async_1.latch)({ count: 2 * numFeeds });
147
- // Create set of feed pairs.
148
- const feeds = Array.from(Array(numFeeds)).map(() => {
149
- const { publicKey, secretKey } = (0, crypto_1.createKeyPair)();
150
- const core1 = factory.createFeed(publicKey, { secretKey });
151
- const core2 = factory.createFeed(publicKey);
152
- core1.once('close', setFeedClosed);
153
- core2.once('close', setFeedClosed);
154
- core1.replicate(true, { stream: stream1, live: true });
155
- core2.replicate(false, { stream: stream2, live: true });
156
- return [core1, core2];
157
- });
158
- //
159
- // Replicate.
160
- //
161
- let total = 0;
162
- const numBlocks = 100;
163
- const [synced, setSynced] = (0, async_1.latch)({ count: numFeeds });
164
- feeds.forEach(([, core2]) => {
165
- core2.on('sync', () => {
166
- core2.audit((_, data) => {
167
- total += data.valid;
168
- (0, log_1.log)('synced', { data }, { file: "packages/common/hypercore/src/hypercore-protocol.test.ts", line: 208, scope: this, bugcheck: "If you see this message then it means that the source code preprocessor for @dxos/log is broken. It probably has misinterpreted an unrelated call for a logger invocation.", callSite: (fn, args) => fn(...args) });
169
- setSynced();
170
- });
171
- });
172
- });
173
- Array.from(Array(numBlocks)).forEach((_, i) => {
174
- const [core1] = faker_1.default.random.arrayElement(feeds);
175
- core1.append(`block-${i}`, () => { });
176
- });
177
- await synced();
178
- (0, chai_1.expect)(total).to.eq(numBlocks);
179
- //
180
- // Close.
181
- //
182
- pipeline.finalize();
183
- await streamClosed();
184
- feeds.forEach(([core1, core2]) => {
185
- core1.close();
186
- core2.close();
187
- });
188
- await feedsClosed();
189
- });
190
- });
191
- //# sourceMappingURL=hypercore-protocol.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hypercore-protocol.test.js","sourceRoot":"","sources":["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
2
- //
3
- // Copyright 2019 DXOS.org
4
- //
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const chai_1 = require("chai");
10
- const node_util_1 = __importDefault(require("node:util"));
11
- const crypto_1 = require("@dxos/crypto");
12
- const crypto_2 = require("./crypto");
13
- const hypercore_factory_1 = require("./hypercore-factory");
14
- const codec = {
15
- encode: (obj) => Buffer.from(JSON.stringify(obj)),
16
- decode: (buffer) => JSON.parse(buffer.toString())
17
- };
18
- const valueEncoding = (0, crypto_2.createCodecEncoding)(codec);
19
- describe('Hypercore', function () {
20
- it('create, append, and close a feed', async function () {
21
- const factory = new hypercore_factory_1.HypercoreFactory();
22
- const { publicKey, secretKey } = (0, crypto_1.createKeyPair)();
23
- const core = factory.createFeed(publicKey, { secretKey });
24
- {
25
- // Check open is idempotent.
26
- const open = node_util_1.default.promisify(core.open.bind(core));
27
- await open();
28
- await open();
29
- }
30
- {
31
- // Append block.
32
- (0, chai_1.expect)(core.length).to.eq(0);
33
- const append = node_util_1.default.promisify(core.append.bind(core));
34
- const seq = await append('test');
35
- (0, chai_1.expect)(core.length).to.eq(1);
36
- (0, chai_1.expect)(seq).to.eq(0);
37
- }
38
- {
39
- // Get block.
40
- const get = node_util_1.default.promisify(core.get.bind(core));
41
- const block = await get(0);
42
- (0, chai_1.expect)(block.toString()).to.eq('test');
43
- }
44
- {
45
- // Check open is idempotent.
46
- const close = node_util_1.default.promisify(core.close.bind(core));
47
- await close();
48
- await close();
49
- }
50
- });
51
- it('encoding with typed hypercore', async function () {
52
- const factory = new hypercore_factory_1.HypercoreFactory();
53
- const { publicKey, secretKey } = (0, crypto_1.createKeyPair)();
54
- const core = factory.createFeed(publicKey, { secretKey, valueEncoding });
55
- {
56
- const append = node_util_1.default.promisify(core.append.bind(core));
57
- (0, chai_1.expect)(core.length).to.eq(0);
58
- const seq = await append({
59
- key: 'test-1',
60
- value: 'test'
61
- });
62
- (0, chai_1.expect)(core.length).to.eq(1);
63
- (0, chai_1.expect)(seq).to.eq(0);
64
- }
65
- {
66
- const head = node_util_1.default.promisify(core.head.bind(core));
67
- const { key, value } = await head();
68
- (0, chai_1.expect)(key).to.eq('test-1');
69
- (0, chai_1.expect)(value).to.eq('test');
70
- }
71
- {
72
- const get = node_util_1.default.promisify(core.get.bind(core));
73
- const { key, value } = await get(0);
74
- (0, chai_1.expect)(key).to.eq('test-1');
75
- (0, chai_1.expect)(value).to.eq('test');
76
- }
77
- });
78
- });
79
- //# sourceMappingURL=hypercore.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hypercore.test.js","sourceRoot":"","sources":["../../src/hypercore.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;AAEF,+BAA8B;AAE9B,0DAA6B;AAG7B,yCAA6C;AAE7C,qCAA+C;AAC/C,2DAAuD;AAOvD,MAAM,KAAK,GAAoB;IAC7B,MAAM,EAAE,CAAC,GAAa,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC3D,MAAM,EAAE,CAAC,MAAkB,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;CAC9D,CAAC;AAEF,MAAM,aAAa,GAAoC,IAAA,4BAAmB,EAAC,KAAK,CAAC,CAAC;AAElF,QAAQ,CAAC,WAAW,EAAE;IACpB,EAAE,CAAC,kCAAkC,EAAE,KAAK;QAC1C,MAAM,OAAO,GAAG,IAAI,oCAAgB,EAAU,CAAC;QAC/C,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,sBAAa,GAAE,CAAC;QACjD,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;QAE1D;YACE,4BAA4B;YAC5B,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