@dxos/hypercore 0.1.13 → 0.1.16
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/dist/lib/browser/index.mjs +108 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/node/index.cjs +147 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/{src → types/src}/crypto.d.ts +0 -0
- package/dist/types/src/crypto.d.ts.map +1 -0
- package/dist/{src → types/src}/defaults.d.ts +0 -0
- package/dist/types/src/defaults.d.ts.map +1 -0
- package/dist/{src → types/src}/hypercore-factory.d.ts +0 -0
- package/dist/types/src/hypercore-factory.d.ts.map +1 -0
- package/dist/{src → types/src}/hypercore-factory.test.d.ts +0 -0
- package/dist/types/src/hypercore-factory.test.d.ts.map +1 -0
- package/dist/{src → types/src}/hypercore-protocol.test.d.ts +0 -0
- package/dist/types/src/hypercore-protocol.test.d.ts.map +1 -0
- package/dist/{src → types/src}/hypercore.test.d.ts +0 -0
- package/dist/{src → types/src}/hypercore.test.d.ts.map +1 -1
- package/dist/{src → types/src}/index.d.ts +0 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/{src → types/src}/iterator.d.ts +0 -0
- package/dist/types/src/iterator.d.ts.map +1 -0
- package/dist/{src → types/src}/iterator.test.d.ts +0 -0
- package/dist/{src → types/src}/iterator.test.d.ts.map +1 -1
- package/dist/{src → types/src}/multiplexer.d.ts +0 -0
- package/dist/types/src/multiplexer.d.ts.map +1 -0
- package/dist/{src → types/src}/multiplexer.test.d.ts +0 -0
- package/dist/types/src/multiplexer.test.d.ts.map +1 -0
- package/dist/{src → types/src}/replicate.test.d.ts +0 -0
- package/dist/{src → types/src}/replicate.test.d.ts.map +1 -1
- package/dist/{src → types/src}/streams.test.d.ts +0 -0
- package/dist/{src → types/src}/streams.test.d.ts.map +1 -1
- package/dist/{src → types/src}/testing.d.ts +2 -3
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +2 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/package.json +13 -15
- package/src/crypto.ts +1 -1
- package/src/hypercore-factory.test.ts +5 -3
- package/src/hypercore-factory.ts +2 -2
- package/src/hypercore-protocol.test.ts +5 -4
- package/src/hypercore.test.ts +4 -3
- package/src/iterator.test.ts +3 -2
- package/src/multiplexer.test.ts +6 -4
- package/src/multiplexer.ts +1 -1
- package/src/replicate.test.ts +5 -4
- package/src/streams.test.ts +4 -3
- package/src/testing.ts +0 -3
- package/src/util.ts +7 -0
- package/dist/src/crypto.d.ts.map +0 -1
- package/dist/src/crypto.js +0 -45
- package/dist/src/crypto.js.map +0 -1
- package/dist/src/defaults.d.ts.map +0 -1
- package/dist/src/defaults.js +0 -44
- package/dist/src/defaults.js.map +0 -1
- package/dist/src/hypercore-factory.d.ts.map +0 -1
- package/dist/src/hypercore-factory.js +0 -44
- package/dist/src/hypercore-factory.js.map +0 -1
- package/dist/src/hypercore-factory.test.d.ts.map +0 -1
- package/dist/src/hypercore-factory.test.js +0 -46
- package/dist/src/hypercore-factory.test.js.map +0 -1
- package/dist/src/hypercore-protocol.test.d.ts.map +0 -1
- package/dist/src/hypercore-protocol.test.js +0 -191
- package/dist/src/hypercore-protocol.test.js.map +0 -1
- package/dist/src/hypercore.test.js +0 -79
- package/dist/src/hypercore.test.js.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -24
- package/dist/src/index.js.map +0 -1
- package/dist/src/iterator.d.ts.map +0 -1
- package/dist/src/iterator.js +0 -37
- package/dist/src/iterator.js.map +0 -1
- package/dist/src/iterator.test.js +0 -61
- package/dist/src/iterator.test.js.map +0 -1
- package/dist/src/multiplexer.d.ts.map +0 -1
- package/dist/src/multiplexer.js +0 -103
- package/dist/src/multiplexer.js.map +0 -1
- package/dist/src/multiplexer.test.d.ts.map +0 -1
- package/dist/src/multiplexer.test.js +0 -142
- package/dist/src/multiplexer.test.js.map +0 -1
- package/dist/src/replicate.test.js +0 -197
- package/dist/src/replicate.test.js.map +0 -1
- package/dist/src/streams.test.js +0 -65
- package/dist/src/streams.test.js.map +0 -1
- package/dist/src/testing.d.ts.map +0 -1
- package/dist/src/testing.js +0 -36
- package/dist/src/testing.js.map +0 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import "@dxos/node-std/globals"
|
|
2
|
+
|
|
3
|
+
// packages/common/hypercore/src/crypto.ts
|
|
4
|
+
import assert from "@dxos/node-std/assert";
|
|
5
|
+
import { callbackify } from "@dxos/node-std/util";
|
|
6
|
+
import { verifySignature } from "@dxos/crypto";
|
|
7
|
+
var createCodecEncoding = (codec) => ({
|
|
8
|
+
encode: (obj) => Buffer.from(codec.encode(obj)),
|
|
9
|
+
decode: (buffer) => codec.decode(buffer)
|
|
10
|
+
});
|
|
11
|
+
var createCrypto = (signer, publicKey) => {
|
|
12
|
+
assert(signer);
|
|
13
|
+
assert(publicKey);
|
|
14
|
+
return {
|
|
15
|
+
sign: (message, secretKey, cb) => {
|
|
16
|
+
callbackify(signer.sign.bind(signer))(publicKey, message, (err, result) => {
|
|
17
|
+
if (err) {
|
|
18
|
+
cb(err, null);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
cb(null, Buffer.from(result));
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
verify: async (message, signature, key, cb) => {
|
|
25
|
+
callbackify(verifySignature)(publicKey, message, signature, cb);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// packages/common/hypercore/src/defaults.ts
|
|
31
|
+
var defaultFeedOptions = {
|
|
32
|
+
createIfMissing: true,
|
|
33
|
+
valueEncoding: "binary"
|
|
34
|
+
};
|
|
35
|
+
var defaultReadStreamOptions = {
|
|
36
|
+
start: 0,
|
|
37
|
+
end: Infinity,
|
|
38
|
+
snapshot: true,
|
|
39
|
+
tail: false,
|
|
40
|
+
live: false,
|
|
41
|
+
timeout: 0,
|
|
42
|
+
wait: true,
|
|
43
|
+
batch: 1
|
|
44
|
+
};
|
|
45
|
+
var defaultWriteStreamOptions = {
|
|
46
|
+
maxBlockSize: Infinity
|
|
47
|
+
};
|
|
48
|
+
var defaultReplicateOptions = {
|
|
49
|
+
live: false,
|
|
50
|
+
ack: false,
|
|
51
|
+
download: true,
|
|
52
|
+
upload: true,
|
|
53
|
+
encrypted: true,
|
|
54
|
+
noise: true
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// packages/common/hypercore/src/hypercore-factory.ts
|
|
58
|
+
import hypercore from "hypercore";
|
|
59
|
+
import assert2 from "@dxos/node-std/assert";
|
|
60
|
+
import { createStorage, StorageType } from "@dxos/random-access-storage";
|
|
61
|
+
|
|
62
|
+
// packages/common/hypercore/src/util.ts
|
|
63
|
+
import util from "@dxos/node-std/util";
|
|
64
|
+
var py = (obj, fn) => util.promisify(fn.bind(obj));
|
|
65
|
+
|
|
66
|
+
// packages/common/hypercore/src/hypercore-factory.ts
|
|
67
|
+
var HypercoreFactory = class {
|
|
68
|
+
constructor(_root = createStorage({
|
|
69
|
+
type: StorageType.RAM
|
|
70
|
+
}).createDirectory(), _options) {
|
|
71
|
+
this._root = _root;
|
|
72
|
+
this._options = _options;
|
|
73
|
+
assert2(this._root);
|
|
74
|
+
}
|
|
75
|
+
createFeed(publicKey, options) {
|
|
76
|
+
const directory = this._root.createDirectory(publicKey.toString());
|
|
77
|
+
const storage = (filename) => directory.getOrCreateFile(filename).native;
|
|
78
|
+
return hypercore(storage, publicKey, Object.assign({}, this._options, options));
|
|
79
|
+
}
|
|
80
|
+
async openFeed(publicKey, options) {
|
|
81
|
+
const feed = this.createFeed(publicKey, options);
|
|
82
|
+
await py(feed, feed.open)();
|
|
83
|
+
return feed;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// packages/common/hypercore/src/iterator.ts
|
|
88
|
+
import { Readable } from "readable-stream";
|
|
89
|
+
var createReadable = (stream) => {
|
|
90
|
+
return new Readable({
|
|
91
|
+
objectMode: true
|
|
92
|
+
}).wrap(stream);
|
|
93
|
+
};
|
|
94
|
+
var createAsyncIterator = (stream) => {
|
|
95
|
+
return stream[Symbol.asyncIterator]();
|
|
96
|
+
};
|
|
97
|
+
export {
|
|
98
|
+
HypercoreFactory,
|
|
99
|
+
createAsyncIterator,
|
|
100
|
+
createCodecEncoding,
|
|
101
|
+
createCrypto,
|
|
102
|
+
createReadable,
|
|
103
|
+
defaultFeedOptions,
|
|
104
|
+
defaultReadStreamOptions,
|
|
105
|
+
defaultReplicateOptions,
|
|
106
|
+
defaultWriteStreamOptions
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/home/runner/work/dxos/dxos/packages/common/hypercore/src/crypto.ts", "../../../src/home/runner/work/dxos/dxos/packages/common/hypercore/src/defaults.ts", "../../../src/home/runner/work/dxos/dxos/packages/common/hypercore/src/hypercore-factory.ts", "../../../src/home/runner/work/dxos/dxos/packages/common/hypercore/src/util.ts", "../../../src/home/runner/work/dxos/dxos/packages/common/hypercore/src/iterator.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { AbstractValueEncoding, Crypto } from 'hypercore';\nimport assert from 'node:assert';\nimport { callbackify } from 'node:util';\n\nimport { Codec } from '@dxos/codec-protobuf';\nimport { Signer, verifySignature } from '@dxos/crypto';\nimport { PublicKey } from '@dxos/keys';\n\n/**\n * Create encoding (e.g., from protobuf codec).\n */\nexport const createCodecEncoding = <T>(codec: Codec<T>): AbstractValueEncoding<T> => ({\n encode: (obj: T) => Buffer.from(codec.encode(obj)),\n decode: (buffer: Buffer) => codec.decode(buffer)\n});\n\n/**\n * Create a custom hypercore crypto signer.\n */\n// TODO(burdon): Create test without adding deps.\nexport const createCrypto = (signer: Signer, publicKey: PublicKey): Crypto => {\n assert(signer);\n assert(publicKey);\n\n return {\n sign: (message, secretKey, cb) => {\n callbackify(signer.sign.bind(signer!))(publicKey, message, (err, result) => {\n if (err) {\n cb(err, null);\n return;\n }\n\n cb(null, Buffer.from(result));\n });\n },\n\n verify: async (message, signature, key, cb) => {\n // NOTE: Uses the public key passed into function.\n callbackify(verifySignature)(publicKey, message, signature, cb);\n }\n };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport type { HypercoreOptions, ReadStreamOptions, ReplicationOptions, WriteStreamOptions } from 'hypercore';\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-feed--hypercorestorage-key-options\n */\nexport const defaultFeedOptions: HypercoreOptions = {\n createIfMissing: true,\n valueEncoding: 'binary'\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatereadstreamoptions\n */\nexport const defaultReadStreamOptions: ReadStreamOptions = {\n start: 0,\n end: Infinity,\n snapshot: true,\n tail: false,\n live: false,\n timeout: 0,\n wait: true,\n batch: 1\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatewritestreamopts\n */\nexport const defaultWriteStreamOptions: WriteStreamOptions = {\n maxBlockSize: Infinity\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedreplicateisinitiator-options\n */\nexport const defaultReplicateOptions: ReplicationOptions = {\n live: false,\n ack: false,\n download: true,\n upload: true,\n encrypted: true,\n noise: true\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport hypercore from 'hypercore';\nimport type { Hypercore, HypercoreOptions } from 'hypercore';\nimport assert from 'node:assert';\n\nimport { createStorage, Directory, StorageType } from '@dxos/random-access-storage';\n\nimport { py } from './util';\n\n/**\n * Creates feeds with default properties.\n */\nexport class HypercoreFactory<T> {\n // prettier-ignore\n constructor(\n private readonly _root: Directory = createStorage({ type: StorageType.RAM }).createDirectory(),\n private readonly _options?: HypercoreOptions\n ) {\n assert(this._root);\n }\n\n /**\n * Creates a feed using a storage factory prefixed with the feed's key.\n * NOTE: We have to use our `random-access-storage` implementation since the native ones\n * do not behave uniformly across platforms.\n */\n createFeed(publicKey: Buffer, options?: HypercoreOptions): Hypercore<T> {\n const directory = this._root.createDirectory(publicKey.toString());\n const storage = (filename: string) => directory.getOrCreateFile(filename).native;\n return hypercore(storage, publicKey, Object.assign({}, this._options, options));\n }\n\n /**\n * Creates and opens a feed.\n */\n async openFeed(publicKey: Buffer, options?: HypercoreOptions): Promise<Hypercore<T>> {\n const feed = this.createFeed(publicKey, options);\n await py(feed, feed.open)(); // TODO(burdon): Sometimes strange bug if done inside function.\n return feed;\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport util from 'node:util';\n\nexport const py = (obj: any, fn: Function) => util.promisify(fn.bind(obj));\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Readable } from 'readable-stream';\nimport { Readable as StreamXReadable } from 'streamx';\n\n/**\n * Wraps streamx.Readable (hypercore.createReadStream) to a standard Readable stream.\n *\n * The read-stream package is mirror of the streams implementations in Node.js 18.9.0.\n * This function is here to standardize the cast in case there are incompatibilities\n * across different platforms.\n *\n * Hypercore createReadStream returns a `streamx` Readable, which does not close properly on destroy.\n *\n * https://github.com/nodejs/readable-stream\n * https://nodejs.org/api/stream.html#readable-streams\n * https://nodejs.org/dist/v18.9.0/docs/api/stream.html#readablewrapstream\n */\nexport const createReadable = (stream: StreamXReadable): Readable => {\n return new Readable({ objectMode: true }).wrap(stream as any);\n};\n\n/**\n * Converts streamx.Readable (hypercore.createReadStream) to an async iterator.\n *\n * https://github.com/tc39/proposal-async-iteration\n * https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html#async-iteration\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols\n */\nexport const createAsyncIterator = (stream: Readable): AsyncIterator<any> => {\n return stream[Symbol.asyncIterator]();\n};\n"],
|
|
5
|
+
"mappings": ";;;AAKA,OAAOA,YAAY;AACnB,SAASC,mBAAmB;AAG5B,SAAiBC,uBAAuB;AAMjC,IAAMC,sBAAsB,CAAIC,WAA+C;EACpFC,QAAQ,CAACC,QAAWC,OAAOC,KAAKJ,MAAMC,OAAOC,GAAAA,CAAAA;EAC7CG,QAAQ,CAACC,WAAmBN,MAAMK,OAAOC,MAAAA;AAC3C;AAMO,IAAMC,eAAe,CAACC,QAAgBC,cAAiC;AAC5Eb,SAAOY,MAAAA;AACPZ,SAAOa,SAAAA;AAEP,SAAO;IACLC,MAAM,CAACC,SAASC,WAAWC,OAAO;AAChChB,kBAAYW,OAAOE,KAAKI,KAAKN,MAAAA,CAAAA,EAAUC,WAAWE,SAAS,CAACI,KAAKC,WAAW;AAC1E,YAAID,KAAK;AACPF,aAAGE,KAAK,IAAI;AACZ;QACF;AAEAF,WAAG,MAAMV,OAAOC,KAAKY,MAAAA,CAAAA;MACvB,CAAA;IACF;IAEAC,QAAQ,OAAON,SAASO,WAAWC,KAAKN,OAAO;AAE7ChB,kBAAYC,eAAAA,EAAiBW,WAAWE,SAASO,WAAWL,EAAAA;IAC9D;EACF;AACF;;;ACpCO,IAAMO,qBAAuC;EAClDC,iBAAiB;EACjBC,eAAe;AACjB;AAKO,IAAMC,2BAA8C;EACzDC,OAAO;EACPC,KAAKC;EACLC,UAAU;EACVC,MAAM;EACNC,MAAM;EACNC,SAAS;EACTC,MAAM;EACNC,OAAO;AACT;AAKO,IAAMC,4BAAgD;EAC3DC,cAAcR;AAChB;AAKO,IAAMS,0BAA8C;EACzDN,MAAM;EACNO,KAAK;EACLC,UAAU;EACVC,QAAQ;EACRC,WAAW;EACXC,OAAO;AACT;;;ACzCA,OAAOC,eAAe;AAEtB,OAAOC,aAAY;AAEnB,SAASC,eAA0BC,mBAAmB;;;ACJtD,OAAOC,UAAU;AAEV,IAAMC,KAAK,CAACC,KAAUC,OAAiBH,KAAKI,UAAUD,GAAGE,KAAKH,GAAAA,CAAAA;;;ADS9D,IAAMI,mBAAN,MAAMA;EAEXC,YACmBC,QAAmBC,cAAc;IAAEC,MAAMC,YAAYC;EAAI,CAAA,EAAGC,gBAAe,GAC3EC,UACjB;iBAFiBN;oBACAM;AAEjBC,IAAAA,QAAO,KAAKP,KAAK;EACnB;EAOAQ,WAAWC,WAAmBC,SAA0C;AACtE,UAAMC,YAAY,KAAKX,MAAMK,gBAAgBI,UAAUG,SAAQ,CAAA;AAC/D,UAAMC,UAAU,CAACC,aAAqBH,UAAUI,gBAAgBD,QAAAA,EAAUE;AAC1E,WAAOC,UAAUJ,SAASJ,WAAWS,OAAOC,OAAO,CAAC,GAAG,KAAKb,UAAUI,OAAAA,CAAAA;EACxE;EAKA,MAAMU,SAASX,WAAmBC,SAAmD;AACnF,UAAMW,OAAO,KAAKb,WAAWC,WAAWC,OAAAA;AACxC,UAAMY,GAAGD,MAAMA,KAAKE,IAAI,EAAA;AACxB,WAAOF;EACT;AACF;;;AEvCA,SAASG,gBAAgB;AAgBlB,IAAMC,iBAAiB,CAACC,WAAsC;AACnE,SAAO,IAAIF,SAAS;IAAEG,YAAY;EAAK,CAAA,EAAGC,KAAKF,MAAAA;AACjD;AAUO,IAAMG,sBAAsB,CAACH,WAAyC;AAC3E,SAAOA,OAAOI,OAAOC,eAAc;AACrC;",
|
|
6
|
+
"names": ["assert", "callbackify", "verifySignature", "createCodecEncoding", "codec", "encode", "obj", "Buffer", "from", "decode", "buffer", "createCrypto", "signer", "publicKey", "sign", "message", "secretKey", "cb", "bind", "err", "result", "verify", "signature", "key", "defaultFeedOptions", "createIfMissing", "valueEncoding", "defaultReadStreamOptions", "start", "end", "Infinity", "snapshot", "tail", "live", "timeout", "wait", "batch", "defaultWriteStreamOptions", "maxBlockSize", "defaultReplicateOptions", "ack", "download", "upload", "encrypted", "noise", "hypercore", "assert", "createStorage", "StorageType", "util", "py", "obj", "fn", "promisify", "bind", "HypercoreFactory", "constructor", "_root", "createStorage", "type", "StorageType", "RAM", "createDirectory", "_options", "assert", "createFeed", "publicKey", "options", "directory", "toString", "storage", "filename", "getOrCreateFile", "native", "hypercore", "Object", "assign", "openFeed", "feed", "py", "open", "Readable", "createReadable", "stream", "objectMode", "wrap", "createAsyncIterator", "Symbol", "asyncIterator"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/common/hypercore/src/crypto.ts":{"bytes":4331,"imports":[]},"packages/common/hypercore/src/defaults.ts":{"bytes":3778,"imports":[]},"packages/common/hypercore/src/util.ts":{"bytes":789,"imports":[]},"packages/common/hypercore/src/hypercore-factory.ts":{"bytes":4900,"imports":[{"path":"packages/common/hypercore/src/util.ts","kind":"import-statement"}]},"packages/common/hypercore/src/iterator.ts":{"bytes":3969,"imports":[]},"packages/common/hypercore/src/index.ts":{"bytes":735,"imports":[{"path":"packages/common/hypercore/src/crypto.ts","kind":"import-statement"},{"path":"packages/common/hypercore/src/defaults.ts","kind":"import-statement"},{"path":"packages/common/hypercore/src/hypercore-factory.ts","kind":"import-statement"},{"path":"packages/common/hypercore/src/iterator.ts","kind":"import-statement"}]}},"outputs":{"packages/common/hypercore/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":8904},"packages/common/hypercore/dist/lib/browser/index.mjs":{"imports":[],"exports":["HypercoreFactory","createAsyncIterator","createCodecEncoding","createCrypto","createReadable","defaultFeedOptions","defaultReadStreamOptions","defaultReplicateOptions","defaultWriteStreamOptions"],"entryPoint":"packages/common/hypercore/src/index.ts","inputs":{"packages/common/hypercore/src/crypto.ts":{"bytesInOutput":764},"packages/common/hypercore/src/index.ts":{"bytesInOutput":0},"packages/common/hypercore/src/defaults.ts":{"bytesInOutput":426},"packages/common/hypercore/src/hypercore-factory.ts":{"bytesInOutput":792},"packages/common/hypercore/src/util.ts":{"bytesInOutput":92},"packages/common/hypercore/src/iterator.ts":{"bytesInOutput":230}},"bytes":2876}}}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
|
|
26
|
+
// packages/common/hypercore/src/index.ts
|
|
27
|
+
var src_exports = {};
|
|
28
|
+
__export(src_exports, {
|
|
29
|
+
HypercoreFactory: () => HypercoreFactory,
|
|
30
|
+
createAsyncIterator: () => createAsyncIterator,
|
|
31
|
+
createCodecEncoding: () => createCodecEncoding,
|
|
32
|
+
createCrypto: () => createCrypto,
|
|
33
|
+
createReadable: () => createReadable,
|
|
34
|
+
defaultFeedOptions: () => defaultFeedOptions,
|
|
35
|
+
defaultReadStreamOptions: () => defaultReadStreamOptions,
|
|
36
|
+
defaultReplicateOptions: () => defaultReplicateOptions,
|
|
37
|
+
defaultWriteStreamOptions: () => defaultWriteStreamOptions
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(src_exports);
|
|
40
|
+
|
|
41
|
+
// packages/common/hypercore/src/crypto.ts
|
|
42
|
+
var import_node_assert = __toESM(require("node:assert"));
|
|
43
|
+
var import_node_util = require("node:util");
|
|
44
|
+
var import_crypto = require("@dxos/crypto");
|
|
45
|
+
var createCodecEncoding = (codec) => ({
|
|
46
|
+
encode: (obj) => Buffer.from(codec.encode(obj)),
|
|
47
|
+
decode: (buffer) => codec.decode(buffer)
|
|
48
|
+
});
|
|
49
|
+
var createCrypto = (signer, publicKey) => {
|
|
50
|
+
(0, import_node_assert.default)(signer);
|
|
51
|
+
(0, import_node_assert.default)(publicKey);
|
|
52
|
+
return {
|
|
53
|
+
sign: (message, secretKey, cb) => {
|
|
54
|
+
(0, import_node_util.callbackify)(signer.sign.bind(signer))(publicKey, message, (err, result) => {
|
|
55
|
+
if (err) {
|
|
56
|
+
cb(err, null);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
cb(null, Buffer.from(result));
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
verify: async (message, signature, key, cb) => {
|
|
63
|
+
(0, import_node_util.callbackify)(import_crypto.verifySignature)(publicKey, message, signature, cb);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// packages/common/hypercore/src/defaults.ts
|
|
69
|
+
var defaultFeedOptions = {
|
|
70
|
+
createIfMissing: true,
|
|
71
|
+
valueEncoding: "binary"
|
|
72
|
+
};
|
|
73
|
+
var defaultReadStreamOptions = {
|
|
74
|
+
start: 0,
|
|
75
|
+
end: Infinity,
|
|
76
|
+
snapshot: true,
|
|
77
|
+
tail: false,
|
|
78
|
+
live: false,
|
|
79
|
+
timeout: 0,
|
|
80
|
+
wait: true,
|
|
81
|
+
batch: 1
|
|
82
|
+
};
|
|
83
|
+
var defaultWriteStreamOptions = {
|
|
84
|
+
maxBlockSize: Infinity
|
|
85
|
+
};
|
|
86
|
+
var defaultReplicateOptions = {
|
|
87
|
+
live: false,
|
|
88
|
+
ack: false,
|
|
89
|
+
download: true,
|
|
90
|
+
upload: true,
|
|
91
|
+
encrypted: true,
|
|
92
|
+
noise: true
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// packages/common/hypercore/src/hypercore-factory.ts
|
|
96
|
+
var import_hypercore = __toESM(require("hypercore"));
|
|
97
|
+
var import_node_assert2 = __toESM(require("node:assert"));
|
|
98
|
+
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
99
|
+
|
|
100
|
+
// packages/common/hypercore/src/util.ts
|
|
101
|
+
var import_node_util2 = __toESM(require("node:util"));
|
|
102
|
+
var py = (obj, fn) => import_node_util2.default.promisify(fn.bind(obj));
|
|
103
|
+
|
|
104
|
+
// packages/common/hypercore/src/hypercore-factory.ts
|
|
105
|
+
var HypercoreFactory = class {
|
|
106
|
+
constructor(_root = (0, import_random_access_storage.createStorage)({
|
|
107
|
+
type: import_random_access_storage.StorageType.RAM
|
|
108
|
+
}).createDirectory(), _options) {
|
|
109
|
+
this._root = _root;
|
|
110
|
+
this._options = _options;
|
|
111
|
+
(0, import_node_assert2.default)(this._root);
|
|
112
|
+
}
|
|
113
|
+
createFeed(publicKey, options) {
|
|
114
|
+
const directory = this._root.createDirectory(publicKey.toString());
|
|
115
|
+
const storage = (filename) => directory.getOrCreateFile(filename).native;
|
|
116
|
+
return (0, import_hypercore.default)(storage, publicKey, Object.assign({}, this._options, options));
|
|
117
|
+
}
|
|
118
|
+
async openFeed(publicKey, options) {
|
|
119
|
+
const feed = this.createFeed(publicKey, options);
|
|
120
|
+
await py(feed, feed.open)();
|
|
121
|
+
return feed;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// packages/common/hypercore/src/iterator.ts
|
|
126
|
+
var import_readable_stream = require("readable-stream");
|
|
127
|
+
var createReadable = (stream) => {
|
|
128
|
+
return new import_readable_stream.Readable({
|
|
129
|
+
objectMode: true
|
|
130
|
+
}).wrap(stream);
|
|
131
|
+
};
|
|
132
|
+
var createAsyncIterator = (stream) => {
|
|
133
|
+
return stream[Symbol.asyncIterator]();
|
|
134
|
+
};
|
|
135
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
+
0 && (module.exports = {
|
|
137
|
+
HypercoreFactory,
|
|
138
|
+
createAsyncIterator,
|
|
139
|
+
createCodecEncoding,
|
|
140
|
+
createCrypto,
|
|
141
|
+
createReadable,
|
|
142
|
+
defaultFeedOptions,
|
|
143
|
+
defaultReadStreamOptions,
|
|
144
|
+
defaultReplicateOptions,
|
|
145
|
+
defaultWriteStreamOptions
|
|
146
|
+
});
|
|
147
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/home/runner/work/dxos/dxos/packages/common/hypercore/src/index.ts", "../../../src/home/runner/work/dxos/dxos/packages/common/hypercore/src/crypto.ts", "../../../src/home/runner/work/dxos/dxos/packages/common/hypercore/src/defaults.ts", "../../../src/home/runner/work/dxos/dxos/packages/common/hypercore/src/hypercore-factory.ts", "../../../src/home/runner/work/dxos/dxos/packages/common/hypercore/src/util.ts", "../../../src/home/runner/work/dxos/dxos/packages/common/hypercore/src/iterator.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nexport * from './crypto';\nexport * from './defaults';\nexport * from './hypercore-factory';\nexport * from './iterator';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { AbstractValueEncoding, Crypto } from 'hypercore';\nimport assert from 'node:assert';\nimport { callbackify } from 'node:util';\n\nimport { Codec } from '@dxos/codec-protobuf';\nimport { Signer, verifySignature } from '@dxos/crypto';\nimport { PublicKey } from '@dxos/keys';\n\n/**\n * Create encoding (e.g., from protobuf codec).\n */\nexport const createCodecEncoding = <T>(codec: Codec<T>): AbstractValueEncoding<T> => ({\n encode: (obj: T) => Buffer.from(codec.encode(obj)),\n decode: (buffer: Buffer) => codec.decode(buffer)\n});\n\n/**\n * Create a custom hypercore crypto signer.\n */\n// TODO(burdon): Create test without adding deps.\nexport const createCrypto = (signer: Signer, publicKey: PublicKey): Crypto => {\n assert(signer);\n assert(publicKey);\n\n return {\n sign: (message, secretKey, cb) => {\n callbackify(signer.sign.bind(signer!))(publicKey, message, (err, result) => {\n if (err) {\n cb(err, null);\n return;\n }\n\n cb(null, Buffer.from(result));\n });\n },\n\n verify: async (message, signature, key, cb) => {\n // NOTE: Uses the public key passed into function.\n callbackify(verifySignature)(publicKey, message, signature, cb);\n }\n };\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport type { HypercoreOptions, ReadStreamOptions, ReplicationOptions, WriteStreamOptions } from 'hypercore';\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-feed--hypercorestorage-key-options\n */\nexport const defaultFeedOptions: HypercoreOptions = {\n createIfMissing: true,\n valueEncoding: 'binary'\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatereadstreamoptions\n */\nexport const defaultReadStreamOptions: ReadStreamOptions = {\n start: 0,\n end: Infinity,\n snapshot: true,\n tail: false,\n live: false,\n timeout: 0,\n wait: true,\n batch: 1\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedcreatewritestreamopts\n */\nexport const defaultWriteStreamOptions: WriteStreamOptions = {\n maxBlockSize: Infinity\n};\n\n/**\n * https://github.com/hypercore-protocol/hypercore/tree/v9.12.0#var-stream--feedreplicateisinitiator-options\n */\nexport const defaultReplicateOptions: ReplicationOptions = {\n live: false,\n ack: false,\n download: true,\n upload: true,\n encrypted: true,\n noise: true\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport hypercore from 'hypercore';\nimport type { Hypercore, HypercoreOptions } from 'hypercore';\nimport assert from 'node:assert';\n\nimport { createStorage, Directory, StorageType } from '@dxos/random-access-storage';\n\nimport { py } from './util';\n\n/**\n * Creates feeds with default properties.\n */\nexport class HypercoreFactory<T> {\n // prettier-ignore\n constructor(\n private readonly _root: Directory = createStorage({ type: StorageType.RAM }).createDirectory(),\n private readonly _options?: HypercoreOptions\n ) {\n assert(this._root);\n }\n\n /**\n * Creates a feed using a storage factory prefixed with the feed's key.\n * NOTE: We have to use our `random-access-storage` implementation since the native ones\n * do not behave uniformly across platforms.\n */\n createFeed(publicKey: Buffer, options?: HypercoreOptions): Hypercore<T> {\n const directory = this._root.createDirectory(publicKey.toString());\n const storage = (filename: string) => directory.getOrCreateFile(filename).native;\n return hypercore(storage, publicKey, Object.assign({}, this._options, options));\n }\n\n /**\n * Creates and opens a feed.\n */\n async openFeed(publicKey: Buffer, options?: HypercoreOptions): Promise<Hypercore<T>> {\n const feed = this.createFeed(publicKey, options);\n await py(feed, feed.open)(); // TODO(burdon): Sometimes strange bug if done inside function.\n return feed;\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport util from 'node:util';\n\nexport const py = (obj: any, fn: Function) => util.promisify(fn.bind(obj));\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { Readable } from 'readable-stream';\nimport { Readable as StreamXReadable } from 'streamx';\n\n/**\n * Wraps streamx.Readable (hypercore.createReadStream) to a standard Readable stream.\n *\n * The read-stream package is mirror of the streams implementations in Node.js 18.9.0.\n * This function is here to standardize the cast in case there are incompatibilities\n * across different platforms.\n *\n * Hypercore createReadStream returns a `streamx` Readable, which does not close properly on destroy.\n *\n * https://github.com/nodejs/readable-stream\n * https://nodejs.org/api/stream.html#readable-streams\n * https://nodejs.org/dist/v18.9.0/docs/api/stream.html#readablewrapstream\n */\nexport const createReadable = (stream: StreamXReadable): Readable => {\n return new Readable({ objectMode: true }).wrap(stream as any);\n};\n\n/**\n * Converts streamx.Readable (hypercore.createReadStream) to an async iterator.\n *\n * https://github.com/tc39/proposal-async-iteration\n * https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html#async-iteration\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols\n */\nexport const createAsyncIterator = (stream: Readable): AsyncIterator<any> => {\n return stream[Symbol.asyncIterator]();\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;ACKA,yBAAmB;AACnB,uBAA4B;AAG5B,oBAAwC;AAMjC,IAAMA,sBAAsB,CAAIC,WAA+C;EACpFC,QAAQ,CAACC,QAAWC,OAAOC,KAAKJ,MAAMC,OAAOC,GAAAA,CAAAA;EAC7CG,QAAQ,CAACC,WAAmBN,MAAMK,OAAOC,MAAAA;AAC3C;AAMO,IAAMC,eAAe,CAACC,QAAgBC,cAAiC;AAC5EC,yBAAAA,SAAOF,MAAAA;AACPE,yBAAAA,SAAOD,SAAAA;AAEP,SAAO;IACLE,MAAM,CAACC,SAASC,WAAWC,OAAO;AAChCC,wCAAYP,OAAOG,KAAKK,KAAKR,MAAAA,CAAAA,EAAUC,WAAWG,SAAS,CAACK,KAAKC,WAAW;AAC1E,YAAID,KAAK;AACPH,aAAGG,KAAK,IAAI;AACZ;QACF;AAEAH,WAAG,MAAMX,OAAOC,KAAKc,MAAAA,CAAAA;MACvB,CAAA;IACF;IAEAC,QAAQ,OAAOP,SAASQ,WAAWC,KAAKP,OAAO;AAE7CC,wCAAYO,6BAAAA,EAAiBb,WAAWG,SAASQ,WAAWN,EAAAA;IAC9D;EACF;AACF;;;ACpCO,IAAMS,qBAAuC;EAClDC,iBAAiB;EACjBC,eAAe;AACjB;AAKO,IAAMC,2BAA8C;EACzDC,OAAO;EACPC,KAAKC;EACLC,UAAU;EACVC,MAAM;EACNC,MAAM;EACNC,SAAS;EACTC,MAAM;EACNC,OAAO;AACT;AAKO,IAAMC,4BAAgD;EAC3DC,cAAcR;AAChB;AAKO,IAAMS,0BAA8C;EACzDN,MAAM;EACNO,KAAK;EACLC,UAAU;EACVC,QAAQ;EACRC,WAAW;EACXC,OAAO;AACT;;;ACzCA,uBAAsB;AAEtB,IAAAC,sBAAmB;AAEnB,mCAAsD;;;ACJtD,IAAAC,oBAAiB;AAEV,IAAMC,KAAK,CAACC,KAAUC,OAAiBC,kBAAAA,QAAKC,UAAUF,GAAGG,KAAKJ,GAAAA,CAAAA;;;ADS9D,IAAMK,mBAAN,MAAMA;EAEXC,YACmBC,YAAmBC,4CAAc;IAAEC,MAAMC,yCAAYC;EAAI,CAAA,EAAGC,gBAAe,GAC3EC,UACjB;iBAFiBN;oBACAM;AAEjBC,4BAAAA,SAAO,KAAKP,KAAK;EACnB;EAOAQ,WAAWC,WAAmBC,SAA0C;AACtE,UAAMC,YAAY,KAAKX,MAAMK,gBAAgBI,UAAUG,SAAQ,CAAA;AAC/D,UAAMC,UAAU,CAACC,aAAqBH,UAAUI,gBAAgBD,QAAAA,EAAUE;AAC1E,eAAOC,iBAAAA,SAAUJ,SAASJ,WAAWS,OAAOC,OAAO,CAAC,GAAG,KAAKb,UAAUI,OAAAA,CAAAA;EACxE;EAKA,MAAMU,SAASX,WAAmBC,SAAmD;AACnF,UAAMW,OAAO,KAAKb,WAAWC,WAAWC,OAAAA;AACxC,UAAMY,GAAGD,MAAMA,KAAKE,IAAI,EAAA;AACxB,WAAOF;EACT;AACF;;;AEvCA,6BAAyB;AAgBlB,IAAMG,iBAAiB,CAACC,WAAsC;AACnE,SAAO,IAAIC,gCAAS;IAAEC,YAAY;EAAK,CAAA,EAAGC,KAAKH,MAAAA;AACjD;AAUO,IAAMI,sBAAsB,CAACJ,WAAyC;AAC3E,SAAOA,OAAOK,OAAOC,eAAc;AACrC;",
|
|
6
|
+
"names": ["createCodecEncoding", "codec", "encode", "obj", "Buffer", "from", "decode", "buffer", "createCrypto", "signer", "publicKey", "assert", "sign", "message", "secretKey", "cb", "callbackify", "bind", "err", "result", "verify", "signature", "key", "verifySignature", "defaultFeedOptions", "createIfMissing", "valueEncoding", "defaultReadStreamOptions", "start", "end", "Infinity", "snapshot", "tail", "live", "timeout", "wait", "batch", "defaultWriteStreamOptions", "maxBlockSize", "defaultReplicateOptions", "ack", "download", "upload", "encrypted", "noise", "import_node_assert", "import_node_util", "py", "obj", "fn", "util", "promisify", "bind", "HypercoreFactory", "constructor", "_root", "createStorage", "type", "StorageType", "RAM", "createDirectory", "_options", "assert", "createFeed", "publicKey", "options", "directory", "toString", "storage", "filename", "getOrCreateFile", "native", "hypercore", "Object", "assign", "openFeed", "feed", "py", "open", "createReadable", "stream", "Readable", "objectMode", "wrap", "createAsyncIterator", "Symbol", "asyncIterator"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"packages/common/hypercore/src/crypto.ts":{"bytes":4331,"imports":[]},"packages/common/hypercore/src/defaults.ts":{"bytes":3778,"imports":[]},"packages/common/hypercore/src/util.ts":{"bytes":789,"imports":[]},"packages/common/hypercore/src/hypercore-factory.ts":{"bytes":4900,"imports":[{"path":"packages/common/hypercore/src/util.ts","kind":"import-statement"}]},"packages/common/hypercore/src/iterator.ts":{"bytes":3969,"imports":[]},"packages/common/hypercore/src/index.ts":{"bytes":735,"imports":[{"path":"packages/common/hypercore/src/crypto.ts","kind":"import-statement"},{"path":"packages/common/hypercore/src/defaults.ts","kind":"import-statement"},{"path":"packages/common/hypercore/src/hypercore-factory.ts","kind":"import-statement"},{"path":"packages/common/hypercore/src/iterator.ts","kind":"import-statement"}]}},"outputs":{"packages/common/hypercore/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9175},"packages/common/hypercore/dist/lib/node/index.cjs":{"imports":[],"exports":[],"entryPoint":"packages/common/hypercore/src/index.ts","inputs":{"packages/common/hypercore/src/index.ts":{"bytesInOutput":541},"packages/common/hypercore/src/crypto.ts":{"bytesInOutput":877},"packages/common/hypercore/src/defaults.ts":{"bytesInOutput":426},"packages/common/hypercore/src/hypercore-factory.ts":{"bytesInOutput":934},"packages/common/hypercore/src/util.ts":{"bytesInOutput":128},"packages/common/hypercore/src/iterator.ts":{"bytesInOutput":266}},"bytes":4944}}}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/crypto.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAI1D,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"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../src/defaults.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE7G;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBAGhC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,iBAStC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,kBAEvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,kBAOrC,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hypercore-factory.d.ts","sourceRoot":"","sources":["../../../src/hypercore-factory.ts"],"names":[],"mappings":";AAIA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7D,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"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hypercore-factory.test.d.ts","sourceRoot":"","sources":["../../../src/hypercore-factory.test.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hypercore-protocol.test.d.ts","sourceRoot":"","sources":["../../../src/hypercore-protocol.test.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hypercore.test.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"hypercore.test.d.ts","sourceRoot":"","sources":["../../../src/hypercore.test.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterator.d.ts","sourceRoot":"","sources":["../../../src/iterator.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,WAAY,eAAe,KAAG,QAExD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,WAAY,QAAQ,KAAG,cAAc,GAAG,CAEvE,CAAC"}
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterator.test.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"iterator.test.d.ts","sourceRoot":"","sources":["../../../src/iterator.test.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiplexer.d.ts","sourceRoot":"","sources":["../../../src/multiplexer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAE,WAAW,EAAuB,MAAM,SAAS,CAAC;AAO3D;;GAEG;AAEH,qBAAa,WAAW;IAYpB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAXtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwD;IAC/E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6D;IAEtF,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAoC;IAE1D,SAAgB,KAAK,cAAqB;IAC1C,SAAgB,MAAM,cAAqB;gBAIxB,GAAG,EAAE,MAAM;IAG9B,IAAI,MAAM,YAET;IAED,IAAI,KAAK,qBAER;IAED,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,UAAQ;IA6BpC,IAAI;IAuBJ,KAAK;CA4BZ"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiplexer.test.d.ts","sourceRoot":"","sources":["../../../src/multiplexer.test.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replicate.test.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"replicate.test.d.ts","sourceRoot":"","sources":["../../../src/replicate.test.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streams.test.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"streams.test.d.ts","sourceRoot":"","sources":["../../../src/streams.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export declare const noop: () => void;
|
|
2
|
-
export declare
|
|
3
|
-
export type TestDataItem = {
|
|
2
|
+
export declare type TestDataItem = {
|
|
4
3
|
id: number;
|
|
5
4
|
text: string;
|
|
6
5
|
};
|
|
7
6
|
export declare const createDataItem: (n: number) => TestDataItem;
|
|
8
|
-
type BatchCallback = (next: (num: number) => void, index: number, remaining: number) => void;
|
|
7
|
+
declare type BatchCallback = (next: (num: number) => void, index: number, remaining: number) => void;
|
|
9
8
|
export declare const batch: (cb: BatchCallback, total: number) => void;
|
|
10
9
|
export {};
|
|
11
10
|
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../src/testing.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,IAAI,YAAW,CAAC;AAG7B,oBAAY,YAAY,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAExD,eAAO,MAAM,cAAc,MAAO,MAAM,KAAG,YAGzC,CAAC;AAEH,aAAK,aAAa,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;AAG7F,eAAO,MAAM,KAAK,OAAQ,aAAa,SAAS,MAAM,SAiBrD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,EAAE,QAAS,GAAG,MAAM,QAAQ,aAAiC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,34 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/hypercore",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Hypercore wrapper and utils.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "DXOS.org",
|
|
9
|
-
"main": "./dist/
|
|
9
|
+
"main": "./dist/lib/node/index.cjs",
|
|
10
10
|
"browser": {
|
|
11
|
-
"node
|
|
12
|
-
"node:util": "util"
|
|
11
|
+
"./dist/lib/node/index.cjs": "./dist/lib/browser/index.mjs"
|
|
13
12
|
},
|
|
14
|
-
"types": "./dist/src/index.d.ts",
|
|
13
|
+
"types": "./dist/types/src/index.d.ts",
|
|
15
14
|
"files": [
|
|
16
15
|
"dist",
|
|
17
16
|
"src"
|
|
18
17
|
],
|
|
19
18
|
"dependencies": {
|
|
20
|
-
"assert": "^2.0.0",
|
|
21
19
|
"hypercore": "^9.12.0",
|
|
22
20
|
"hypercore-protocol": "^8.0.7",
|
|
23
21
|
"readable-stream": "^3.6.0",
|
|
24
22
|
"streamx": "^2.12.5",
|
|
25
|
-
"
|
|
26
|
-
"@dxos/codec-protobuf": "0.1.
|
|
27
|
-
"@dxos/crypto": "0.1.
|
|
28
|
-
"@dxos/
|
|
29
|
-
"@dxos/
|
|
30
|
-
"@dxos/
|
|
31
|
-
"@dxos/random-access-storage": "0.1.
|
|
23
|
+
"@dxos/async": "0.1.16",
|
|
24
|
+
"@dxos/codec-protobuf": "0.1.16",
|
|
25
|
+
"@dxos/crypto": "0.1.16",
|
|
26
|
+
"@dxos/debug": "0.1.16",
|
|
27
|
+
"@dxos/keys": "0.1.16",
|
|
28
|
+
"@dxos/node-std": "0.1.16",
|
|
29
|
+
"@dxos/random-access-storage": "0.1.16"
|
|
32
30
|
},
|
|
33
31
|
"devDependencies": {
|
|
34
32
|
"@types/debug": "^4.1.7",
|
|
@@ -38,8 +36,8 @@
|
|
|
38
36
|
"debug": "^4.3.3",
|
|
39
37
|
"faker": "^5.5.3",
|
|
40
38
|
"random-access-memory": "^4.1.0",
|
|
41
|
-
"@dxos/log": "0.1.
|
|
42
|
-
"@dxos/util": "0.1.
|
|
39
|
+
"@dxos/log": "0.1.16",
|
|
40
|
+
"@dxos/util": "0.1.16"
|
|
43
41
|
},
|
|
44
42
|
"publishConfig": {
|
|
45
43
|
"access": "public"
|
package/src/crypto.ts
CHANGED
|
@@ -6,12 +6,14 @@ import { expect } from 'chai';
|
|
|
6
6
|
import faker from 'faker';
|
|
7
7
|
|
|
8
8
|
import { createKeyPair } from '@dxos/crypto';
|
|
9
|
+
import { describe, test } from '@dxos/test';
|
|
9
10
|
|
|
10
11
|
import { HypercoreFactory } from './hypercore-factory';
|
|
11
|
-
import { createDataItem
|
|
12
|
+
import { createDataItem } from './testing';
|
|
13
|
+
import { py } from './util';
|
|
12
14
|
|
|
13
|
-
describe('HypercoreFactory',
|
|
14
|
-
|
|
15
|
+
describe('HypercoreFactory', () => {
|
|
16
|
+
test('appends to, and read from, multiple feeds', async () => {
|
|
15
17
|
const factory = new HypercoreFactory();
|
|
16
18
|
|
|
17
19
|
const numFeeds = 10;
|
package/src/hypercore-factory.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import assert from 'assert';
|
|
6
5
|
import hypercore from 'hypercore';
|
|
7
6
|
import type { Hypercore, HypercoreOptions } from 'hypercore';
|
|
7
|
+
import assert from 'node:assert';
|
|
8
8
|
|
|
9
9
|
import { createStorage, Directory, StorageType } from '@dxos/random-access-storage';
|
|
10
10
|
|
|
11
|
-
import { py } from './
|
|
11
|
+
import { py } from './util';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Creates feeds with default properties.
|
|
@@ -10,14 +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
|
|
|
16
17
|
// TODO(burdon): Test encoding.
|
|
17
18
|
// TODO(burdon): Simulate multiple peers and broadcast.
|
|
18
19
|
|
|
19
|
-
describe('ProtocolStream',
|
|
20
|
-
|
|
20
|
+
describe('ProtocolStream', () => {
|
|
21
|
+
test('protocol stream handshake completes', async () => {
|
|
21
22
|
const [handshake, setHandshake] = latch({ count: 2 });
|
|
22
23
|
|
|
23
24
|
const stream1 = new ProtocolStream(true, {
|
|
@@ -42,7 +43,7 @@ describe('ProtocolStream', function () {
|
|
|
42
43
|
await closed();
|
|
43
44
|
});
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
test('protocol stream handshake completes with feeds', async () => {
|
|
46
47
|
//
|
|
47
48
|
// Pipeline and handshake.
|
|
48
49
|
//
|
|
@@ -157,7 +158,7 @@ describe('ProtocolStream', function () {
|
|
|
157
158
|
expect(core2.closed).to.be.true;
|
|
158
159
|
});
|
|
159
160
|
|
|
160
|
-
|
|
161
|
+
test('multi-feed multiplexing', async () => {
|
|
161
162
|
//
|
|
162
163
|
// Handshake.
|
|
163
164
|
//
|
package/src/hypercore.test.ts
CHANGED
|
@@ -8,6 +8,7 @@ import util from 'node:util';
|
|
|
8
8
|
|
|
9
9
|
import { Codec } from '@dxos/codec-protobuf';
|
|
10
10
|
import { createKeyPair } from '@dxos/crypto';
|
|
11
|
+
import { describe, test } from '@dxos/test';
|
|
11
12
|
|
|
12
13
|
import { createCodecEncoding } from './crypto';
|
|
13
14
|
import { HypercoreFactory } from './hypercore-factory';
|
|
@@ -24,8 +25,8 @@ const codec: Codec<TestItem> = {
|
|
|
24
25
|
|
|
25
26
|
const valueEncoding: AbstractValueEncoding<TestItem> = createCodecEncoding(codec);
|
|
26
27
|
|
|
27
|
-
describe('Hypercore',
|
|
28
|
-
|
|
28
|
+
describe('Hypercore', () => {
|
|
29
|
+
test('create, append, and close a feed', async () => {
|
|
29
30
|
const factory = new HypercoreFactory<string>();
|
|
30
31
|
const { publicKey, secretKey } = createKeyPair();
|
|
31
32
|
const core = factory.createFeed(publicKey, { secretKey });
|
|
@@ -61,7 +62,7 @@ describe('Hypercore', function () {
|
|
|
61
62
|
}
|
|
62
63
|
});
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
test('encoding with typed hypercore', async () => {
|
|
65
66
|
const factory = new HypercoreFactory<TestItem>();
|
|
66
67
|
const { publicKey, secretKey } = createKeyPair();
|
|
67
68
|
const core = factory.createFeed(publicKey, { secretKey, valueEncoding });
|
package/src/iterator.test.ts
CHANGED
|
@@ -7,12 +7,13 @@ import util from 'node:util';
|
|
|
7
7
|
import { latch } from '@dxos/async';
|
|
8
8
|
import { createKeyPair } from '@dxos/crypto';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
|
+
import { describe, test } from '@dxos/test';
|
|
10
11
|
|
|
11
12
|
import { HypercoreFactory } from './hypercore-factory';
|
|
12
13
|
import { createAsyncIterator, createReadable } from './iterator';
|
|
13
14
|
|
|
14
|
-
describe('AsyncIterator',
|
|
15
|
-
|
|
15
|
+
describe('AsyncIterator', () => {
|
|
16
|
+
test('iterates a feed until stopped', async () => {
|
|
16
17
|
const factory = new HypercoreFactory();
|
|
17
18
|
const { publicKey, secretKey } = createKeyPair();
|
|
18
19
|
const core = factory.createFeed(publicKey, { secretKey });
|