@dxos/hypercore 0.1.22 → 0.1.24-next.6b1f434
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 +3 -3
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +3 -3
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/crypto.d.ts +2 -2
- package/dist/types/src/crypto.d.ts.map +1 -1
- package/dist/types/src/hypercore-factory.d.ts +1 -2
- package/dist/types/src/hypercore-factory.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/crypto.ts +4 -4
|
@@ -4,9 +4,9 @@ import "@dxos/node-std/globals"
|
|
|
4
4
|
import assert from "@dxos/node-std/assert";
|
|
5
5
|
import { callbackify } from "@dxos/node-std/util";
|
|
6
6
|
import { verifySignature } from "@dxos/crypto";
|
|
7
|
-
var createCodecEncoding = (codec) => ({
|
|
8
|
-
encode: (obj) => Buffer.from(codec.encode(obj)),
|
|
9
|
-
decode: (buffer) => codec.decode(buffer)
|
|
7
|
+
var createCodecEncoding = (codec, opts) => ({
|
|
8
|
+
encode: (obj) => Buffer.from(codec.encode(obj, opts)),
|
|
9
|
+
decode: (buffer) => codec.decode(buffer, opts)
|
|
10
10
|
});
|
|
11
11
|
var createCrypto = (signer, publicKey) => {
|
|
12
12
|
assert(signer);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/crypto.ts", "../../../src/defaults.ts", "../../../src/hypercore-factory.ts", "../../../src/util.ts", "../../../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
|
|
5
|
-
"mappings": ";;;AAKA,OAAOA,YAAY;AACnB,SAASC,mBAAmB;AAG5B,SAAiBC,uBAAuB;AAMjC,IAAMC,sBAAsB,CAAIC,
|
|
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"]
|
|
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, EncodingOptions } 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>, opts?: EncodingOptions): AbstractValueEncoding<T> => ({\n encode: (obj: T) => Buffer.from(codec.encode(obj, opts)),\n decode: (buffer: Buffer) => codec.decode(buffer, opts)\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,OAAiBC,UAAsD;EAC5GC,QAAQ,CAACC,QAAWC,OAAOC,KAAKL,MAAME,OAAOC,KAAKF,IAAAA,CAAAA;EAClDK,QAAQ,CAACC,WAAmBP,MAAMM,OAAOC,QAAQN,IAAAA;AACnD;AAMO,IAAMO,eAAe,CAACC,QAAgBC,cAAiC;AAC5Ed,SAAOa,MAAAA;AACPb,SAAOc,SAAAA;AAEP,SAAO;IACLC,MAAM,CAACC,SAASC,WAAWC,OAAO;AAChCjB,kBAAYY,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;AAE7CjB,kBAAYC,eAAAA,EAAiBY,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,aAAa,EAAC;AACrC;",
|
|
6
|
+
"names": ["assert", "callbackify", "verifySignature", "createCodecEncoding", "codec", "opts", "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
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/common/hypercore/src/crypto.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/common/hypercore/src/crypto.ts":{"bytes":4377,"imports":[{"path":"@dxos/node-std/assert","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true}]},"packages/common/hypercore/src/defaults.ts":{"bytes":3698,"imports":[]},"packages/common/hypercore/src/util.ts":{"bytes":713,"imports":[{"path":"@dxos/node-std/util","kind":"import-statement","external":true}]},"packages/common/hypercore/src/hypercore-factory.ts":{"bytes":4820,"imports":[{"path":"hypercore","kind":"import-statement","external":true},{"path":"@dxos/node-std/assert","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"packages/common/hypercore/src/util.ts","kind":"import-statement","original":"./util"}]},"packages/common/hypercore/src/iterator.ts":{"bytes":3893,"imports":[{"path":"readable-stream","kind":"import-statement","external":true}]},"packages/common/hypercore/src/index.ts":{"bytes":659,"imports":[{"path":"packages/common/hypercore/src/crypto.ts","kind":"import-statement","original":"./crypto"},{"path":"packages/common/hypercore/src/defaults.ts","kind":"import-statement","original":"./defaults"},{"path":"packages/common/hypercore/src/hypercore-factory.ts","kind":"import-statement","original":"./hypercore-factory"},{"path":"packages/common/hypercore/src/iterator.ts","kind":"import-statement","original":"./iterator"}]}},"outputs":{"packages/common/hypercore/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":8713},"packages/common/hypercore/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/node-std/assert","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true},{"path":"hypercore","kind":"import-statement","external":true},{"path":"@dxos/node-std/assert","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"@dxos/node-std/util","kind":"import-statement","external":true},{"path":"readable-stream","kind":"import-statement","external":true}],"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":782},"packages/common/hypercore/src/index.ts":{"bytesInOutput":0},"packages/common/hypercore/src/defaults.ts":{"bytesInOutput":426},"packages/common/hypercore/src/hypercore-factory.ts":{"bytesInOutput":1074},"packages/common/hypercore/src/util.ts":{"bytesInOutput":92},"packages/common/hypercore/src/iterator.ts":{"bytesInOutput":230}},"bytes":3176}}}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -46,9 +46,9 @@ module.exports = __toCommonJS(src_exports);
|
|
|
46
46
|
var import_node_assert = __toESM(require("node:assert"));
|
|
47
47
|
var import_node_util = require("node:util");
|
|
48
48
|
var import_crypto = require("@dxos/crypto");
|
|
49
|
-
var createCodecEncoding = (codec) => ({
|
|
50
|
-
encode: (obj) => Buffer.from(codec.encode(obj)),
|
|
51
|
-
decode: (buffer) => codec.decode(buffer)
|
|
49
|
+
var createCodecEncoding = (codec, opts) => ({
|
|
50
|
+
encode: (obj) => Buffer.from(codec.encode(obj, opts)),
|
|
51
|
+
decode: (buffer) => codec.decode(buffer, opts)
|
|
52
52
|
});
|
|
53
53
|
var createCrypto = (signer, publicKey) => {
|
|
54
54
|
(0, import_node_assert.default)(signer);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/crypto.ts", "../../../src/defaults.ts", "../../../src/hypercore-factory.ts", "../../../src/util.ts", "../../../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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;ACKA,yBAAmB;AACnB,uBAA4B;AAG5B,oBAAwC;AAMjC,IAAMA,sBAAsB,CAAIC,
|
|
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"]
|
|
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, EncodingOptions } 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>, opts?: EncodingOptions): AbstractValueEncoding<T> => ({\n encode: (obj: T) => Buffer.from(codec.encode(obj, opts)),\n decode: (buffer: Buffer) => codec.decode(buffer, opts)\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,OAAiBC,UAAsD;EAC5GC,QAAQ,CAACC,QAAWC,OAAOC,KAAKL,MAAME,OAAOC,KAAKF,IAAAA,CAAAA;EAClDK,QAAQ,CAACC,WAAmBP,MAAMM,OAAOC,QAAQN,IAAAA;AACnD;AAMO,IAAMO,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,aAAa,EAAC;AACrC;",
|
|
6
|
+
"names": ["createCodecEncoding", "codec", "opts", "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
7
|
}
|
package/dist/lib/node/meta.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/common/hypercore/src/crypto.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/common/hypercore/src/crypto.ts":{"bytes":4377,"imports":[{"path":"node:assert","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true},{"path":"@dxos/crypto","kind":"import-statement","external":true}]},"packages/common/hypercore/src/defaults.ts":{"bytes":3698,"imports":[]},"packages/common/hypercore/src/util.ts":{"bytes":713,"imports":[{"path":"node:util","kind":"import-statement","external":true}]},"packages/common/hypercore/src/hypercore-factory.ts":{"bytes":4820,"imports":[{"path":"hypercore","kind":"import-statement","external":true},{"path":"node:assert","kind":"import-statement","external":true},{"path":"@dxos/random-access-storage","kind":"import-statement","external":true},{"path":"packages/common/hypercore/src/util.ts","kind":"import-statement","original":"./util"}]},"packages/common/hypercore/src/iterator.ts":{"bytes":3893,"imports":[{"path":"readable-stream","kind":"import-statement","external":true}]},"packages/common/hypercore/src/index.ts":{"bytes":659,"imports":[{"path":"packages/common/hypercore/src/crypto.ts","kind":"import-statement","original":"./crypto"},{"path":"packages/common/hypercore/src/defaults.ts","kind":"import-statement","original":"./defaults"},{"path":"packages/common/hypercore/src/hypercore-factory.ts","kind":"import-statement","original":"./hypercore-factory"},{"path":"packages/common/hypercore/src/iterator.ts","kind":"import-statement","original":"./iterator"}]}},"outputs":{"packages/common/hypercore/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":8931},"packages/common/hypercore/dist/lib/node/index.cjs":{"imports":[{"path":"node:assert","kind":"require-call","external":true},{"path":"node:util","kind":"require-call","external":true},{"path":"@dxos/crypto","kind":"require-call","external":true},{"path":"hypercore","kind":"require-call","external":true},{"path":"node:assert","kind":"require-call","external":true},{"path":"@dxos/random-access-storage","kind":"require-call","external":true},{"path":"node:util","kind":"require-call","external":true},{"path":"readable-stream","kind":"require-call","external":true}],"exports":[],"entryPoint":"packages/common/hypercore/src/index.ts","inputs":{"packages/common/hypercore/src/index.ts":{"bytesInOutput":541},"packages/common/hypercore/src/crypto.ts":{"bytesInOutput":895},"packages/common/hypercore/src/defaults.ts":{"bytesInOutput":426},"packages/common/hypercore/src/hypercore-factory.ts":{"bytesInOutput":1216},"packages/common/hypercore/src/util.ts":{"bytesInOutput":128},"packages/common/hypercore/src/iterator.ts":{"bytesInOutput":266}},"bytes":5530}}}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AbstractValueEncoding, Crypto } from 'hypercore';
|
|
2
|
-
import { Codec } from '@dxos/codec-protobuf';
|
|
2
|
+
import { Codec, EncodingOptions } from '@dxos/codec-protobuf';
|
|
3
3
|
import { Signer } from '@dxos/crypto';
|
|
4
4
|
import { PublicKey } from '@dxos/keys';
|
|
5
5
|
/**
|
|
6
6
|
* Create encoding (e.g., from protobuf codec).
|
|
7
7
|
*/
|
|
8
|
-
export declare const createCodecEncoding: <T>(codec: Codec<T
|
|
8
|
+
export declare const createCodecEncoding: <T>(codec: Codec<T>, opts?: EncodingOptions) => AbstractValueEncoding<T>;
|
|
9
9
|
/**
|
|
10
10
|
* Create a custom hypercore crypto signer.
|
|
11
11
|
*/
|
|
@@ -1 +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;
|
|
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,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAmB,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,mBAAmB,8BAA+B,eAAe,6BAG5E,CAAC;AAEH;;GAEG;AAEH,eAAO,MAAM,YAAY,WAAY,MAAM,aAAa,SAAS,KAAG,MAqBnE,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import hypercore from 'hypercore';
|
|
3
2
|
import type { Hypercore, HypercoreOptions } from 'hypercore';
|
|
4
3
|
import { Directory } from '@dxos/random-access-storage';
|
|
5
4
|
/**
|
|
@@ -8,7 +7,7 @@ import { Directory } from '@dxos/random-access-storage';
|
|
|
8
7
|
export declare class HypercoreFactory<T> {
|
|
9
8
|
private readonly _root;
|
|
10
9
|
private readonly _options?;
|
|
11
|
-
constructor(_root?: Directory, _options?:
|
|
10
|
+
constructor(_root?: Directory, _options?: HypercoreOptions | undefined);
|
|
12
11
|
/**
|
|
13
12
|
* Creates a feed using a storage factory prefixed with the feed's key.
|
|
14
13
|
* NOTE: We have to use our `random-access-storage` implementation since the native ones
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hypercore-factory.d.ts","sourceRoot":"","sources":["../../../src/hypercore-factory.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"hypercore-factory.d.ts","sourceRoot":"","sources":["../../../src/hypercore-factory.ts"],"names":[],"mappings":";AAKA,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,8BAAkB;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/hypercore",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24-next.6b1f434",
|
|
4
4
|
"description": "Hypercore wrapper and utils.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"hypercore-protocol": "^8.0.7",
|
|
21
21
|
"readable-stream": "^3.6.0",
|
|
22
22
|
"streamx": "^2.12.5",
|
|
23
|
-
"@dxos/async": "0.1.
|
|
24
|
-
"@dxos/codec-protobuf": "0.1.
|
|
25
|
-
"@dxos/crypto": "0.1.
|
|
26
|
-
"@dxos/debug": "0.1.
|
|
27
|
-
"@dxos/keys": "0.1.
|
|
28
|
-
"@dxos/node-std": "0.1.
|
|
29
|
-
"@dxos/random-access-storage": "0.1.
|
|
23
|
+
"@dxos/async": "0.1.24-next.6b1f434",
|
|
24
|
+
"@dxos/codec-protobuf": "0.1.24-next.6b1f434",
|
|
25
|
+
"@dxos/crypto": "0.1.24-next.6b1f434",
|
|
26
|
+
"@dxos/debug": "0.1.24-next.6b1f434",
|
|
27
|
+
"@dxos/keys": "0.1.24-next.6b1f434",
|
|
28
|
+
"@dxos/node-std": "0.1.24-next.6b1f434",
|
|
29
|
+
"@dxos/random-access-storage": "0.1.24-next.6b1f434"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/debug": "^4.1.7",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"debug": "^4.3.3",
|
|
37
37
|
"faker": "^5.5.3",
|
|
38
38
|
"random-access-memory": "^4.1.0",
|
|
39
|
-
"@dxos/log": "0.1.
|
|
40
|
-
"@dxos/util": "0.1.
|
|
39
|
+
"@dxos/log": "0.1.24-next.6b1f434",
|
|
40
|
+
"@dxos/util": "0.1.24-next.6b1f434"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
package/src/crypto.ts
CHANGED
|
@@ -6,16 +6,16 @@ import { AbstractValueEncoding, Crypto } from 'hypercore';
|
|
|
6
6
|
import assert from 'node:assert';
|
|
7
7
|
import { callbackify } from 'node:util';
|
|
8
8
|
|
|
9
|
-
import { Codec } from '@dxos/codec-protobuf';
|
|
9
|
+
import { Codec, EncodingOptions } from '@dxos/codec-protobuf';
|
|
10
10
|
import { Signer, verifySignature } from '@dxos/crypto';
|
|
11
11
|
import { PublicKey } from '@dxos/keys';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Create encoding (e.g., from protobuf codec).
|
|
15
15
|
*/
|
|
16
|
-
export const createCodecEncoding = <T>(codec: Codec<T
|
|
17
|
-
encode: (obj: T) => Buffer.from(codec.encode(obj)),
|
|
18
|
-
decode: (buffer: Buffer) => codec.decode(buffer)
|
|
16
|
+
export const createCodecEncoding = <T>(codec: Codec<T>, opts?: EncodingOptions): AbstractValueEncoding<T> => ({
|
|
17
|
+
encode: (obj: T) => Buffer.from(codec.encode(obj, opts)),
|
|
18
|
+
decode: (buffer: Buffer) => codec.decode(buffer, opts)
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
/**
|