{"name":"hypercore","version":"11.7.1","license":"MIT","_id":"hypercore@11.7.1","maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"andrewosh","email":"andrewosh@gmail.com"},{"name":"chm-diederichs","email":"chm-diederichs@protonmail.com"}],"contributors":[{"url":"https://mafinto.sh","name":"Mathias Buus","email":"mathiasbuus@gmail.com"},{"url":"https://andrewosh.com","name":"Andrew Osheroff","email":"andrewosh@gmail.com"}],"homepage":"https://github.com/holepunchto/hypercore#readme","bugs":{"url":"https://github.com/holepunchto/hypercore/issues"},"dist":{"shasum":"0af59bfc02d54b672c209416bfd6d177231c7031","tarball":"http://registry-npm.ywwl.com/hypercore/download/hypercore-11.7.1.tgz","fileCount":27,"integrity":"sha512-mfSpcXglAHQgcUH0cc658q3XAlwZDIIiDwPDkeJ7/F8Y/g3f1t92KzHUlzPYqOwx1+VBn8Fy4KnXQFaF2r97yA==","signatures":[{"sig":"MEYCIQDowUESnDnn4YxPLuroOAVX0xrlVtSBm0/XhH/GrI2TxQIhAMip9HZQIob3jiXCCpsFWuBOFicFYiALSBJF3BVNmsCs","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":297357,"size":69023,"noattachment":false,"key":"/hypercore/-/hypercore-11.7.1.tgz"},"main":"index.js","gitHead":"884acf702c109db5f8ebc6f32b2051f3040de679","imports":{"events":{"bare":"bare-events","default":"events"}},"scripts":{"test":"standard && node test/all.js","test:bare":"bare test/all.js","test:generate":"brittle -r test/all.js test/*.js"},"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"repository":{"url":"git+https://github.com/holepunchto/hypercore.git","type":"git"},"_npmVersion":"10.9.0","description":"Hypercore is a secure, distributed append-only log","directories":{},"_nodeVersion":"22.12.0","dependencies":{"b4a":"^1.1.0","z32":"^1.0.0","unslab":"^1.3.0","streamx":"^2.12.4","protomux":"^3.5.0","fast-fifo":"^1.3.0","flat-tree":"^1.9.0","is-options":"^1.0.1","nanoassert":"^2.0.0","bare-events":"^2.2.0","safety-catch":"^1.0.1","big-sparse-array":"^1.0.3","compact-encoding":"^2.11.0","hypercore-crypto":"^3.2.1","hypercore-errors":"^1.2.0","sodium-universal":"^5.0.1","hypercore-storage":"^1.0.0","quickbit-universal":"^2.2.0","hypercore-id-encoding":"^1.2.0","random-array-iterator":"^1.0.0","@hyperswarm/secret-stream":"^6.0.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"rache":"^1.0.0","brittle":"^3.0.0","standard":"^17.0.0","test-tmp":"^1.0.2","uncaughts":"^1.1.0","hyperswarm":"^4.3.6","udx-native":"^1.6.1","speedometer":"^1.1.0","range-parser":"^1.2.1","tiny-byte-size":"^1.1.0","debugging-stream":"^3.1.0"},"_npmOperationalInternal":{"tmp":"tmp/hypercore_11.7.1_1748692362698_0.473768596929236","host":"s3://npm-registry-packages-npm-production"},"readme":"# Hypercore\n\n### [See the full API docs at docs.pears.com](https://docs.pears.com/building-blocks/hypercore)\n\nHypercore is a secure, distributed append-only log.\n\nBuilt for sharing large datasets and streams of real time data\n\n## Features\n\n- **Sparse replication.** Only download the data you are interested in.\n- **Realtime.** Get the latest updates to the log fast and securely.\n- **Performant.** Uses a simple flat file structure to maximize I/O performance.\n- **Secure.** Uses signed merkle trees to verify log integrity in real time.\n- **Modular.** Hypercore aims to do one thing and one thing well - distributing a stream of data.\n\nNote that the latest release is Hypercore 10, which adds support for truncate and many other things.\nVersion 10 is not compatible with earlier versions (9 and earlier), but is considered LTS, meaning the storage format and wire protocol is forward compatible with future versions.\n\n## Install\n\n```sh\nnpm install hypercore\n```\n\n## API\n\n#### `const core = new Hypercore(storage, [key], [options])`\n\nMake a new Hypercore instance.\n\n`storage` should be set to a directory where you want to store the data and core metadata.\n\n```js\nconst core = new Hypercore('./directory') // store data in ./directory\n```\n\nAlternatively you can pass a [Hypercore Storage](https://github.com/holepunchto/hypercore-storage) or use a [Corestore](https://github.com/holepunchto/corestore) if you want to make many Hypercores efficiently. Note that `random-access-storage` is no longer supported.\n\n`key` can be set to a Hypercore key which is a hash of Hypercore's internal auth manifest, describing how to validate the Hypercore. If you do not set this, it will be loaded from storage. If nothing is previously stored, a new auth manifest will be generated giving you local write access to it.\n\n`options` include:\n\n```js\n{\n  createIfMissing: true, // create a new Hypercore key pair if none was present in storage\n  overwrite: false, // overwrite any old Hypercore that might already exist\n  force: false, // Advanced option. Will force overwrite even if the header's key & the passed key don't match\n  valueEncoding: 'json' | 'utf-8' | 'binary', // defaults to binary\n  encodeBatch: batch => { ... }, // optionally apply an encoding to complete batches\n  keyPair: kp, // optionally pass the public key and secret key as a key pair\n  encryption: { key: buffer }, // the block encryption key\n  onwait: () => {}, // hook that is called if gets are waiting for download\n  timeout: 0, // wait at max some milliseconds (0 means no timeout)\n  writable: true, // disable appends and truncates\n  inflightRange: null, // Advanced option. Set to [minInflight, maxInflight] to change the min and max inflight blocks per peer when downloading.\n  ongc: (session) => { ... }, // A callback called when the session is garbage collected\n  onseq: (index, core) => { ... }, // A callback called when core.get(index) is called.\n  notDownloadingLinger: 20000, // How many milliseconds to wait after downloading finishes keeping the connection open. Defaults to a random number between 20-40s\n  allowFork: true, // Enables updating core when it forks\n  allowLatestBlock: false, // Request latest block when requesting upgrade\n  userData: { foo: 'bar' }, // An object to assign to the local User Data storage\n  manifest: undefined, // Advanced option. Set the manifest when creating the hypercore. See Manifest section for more info\n  preload: undefined, // Advanced option. A promise that returns constructor options overrides before the core is opened\n  storage: undefined, // An alternative to passing storage as a dedicated argument\n  key: null, // An alternative to passing key as a dedicated argument\n}\n```\n\nYou can also set `valueEncoding` to any [compact-encoding](https://github.com/holepunchto/compact-encoding) instance.\n\n`valueEncoding`s will be applied to individual blocks, even if you append batches. If you want to control encoding at the batch-level, you can use the `encodeBatch` option, which is a function that takes a batch and returns a binary-encoded batch. If you provide a custom `valueEncoding`, it will not be applied prior to `encodeBatch`.\n\nThe user may provide a custom encryption module as `opts.encryption`, which should satisfy the [HypercoreEncryption](https://github.com/holepunchto/hypercore-encryption) interface.\n\n##### User Data\n\nUser Data is a key-value store that is persisted locally and is not replicated with the Hypercore. This is useful as a quick store for data only used by the current peer. For example, `autobase` uses User Data to store information such as encryption keys and connections between a peer's local writer and the Autobase's bootstrap core.\n\nKeys are always strings and values can be strings or buffers.\n\nSee [`core.setUserData(key, value)`](#await-coresetuserdatakey-value) and [`core.getUserData(key)`](#const-value--await-coregetuserdatakey) for updating User Data.\n\n##### Manifest\n\nThe manifest is metadata about authenticating a hypercore including things like the signers (only one by default) and the prologue. Manifest has the following structure:\n\n```\n{\n  version: 1,                       // Version of the manifest format\n  hash: 'blake2b',                  // Only Blake2b is supported currently\n  allowPatch: false,                // Whether the hypercore can be \"patched\" to change the signers\n  quorum: (signers.length / 2) + 1, // How many signers needed to verify a block\n  signers,                          // Array of signers for the core\n  prologue: null,                   // The tree hash and length of the core\n  linked: null,                     // Array of associated core keys. Only supported in versions >= 2\n  userData: null                    // Arbitrary buffer for User Data integral to the core. Only supported in versions >= 2\n}\n```\n\nThe `linked` property in the manifest is used to reference other hypercores that are associated with the current core. For example in `autobase` the encryption view is loaded from the `linked` property in the system view core. Note, as with everything in the manifest, changing the `linked` property changes the core's `key`.\n\nSigners are an array of objects with the following structure:\n\n```\n{\n  signature: 'ed25519',               // The signature method\n  namespace: caps.DEFAULT_NAMESPACE,  // A cryptographic namespace for the signature\n  publicKey: Buffer                   // Signer's public key\n}\n```\n\n#### `const { length, byteLength } = await core.append(block, options = {})`\n\nAppend a block of data (or an array of blocks) to the core.\nReturns the new length and byte length of the core.\n\n```js\n// simple call append with a new block of data\nawait core.append(Buffer.from('I am a block of data'))\n\n// pass an array to append multiple blocks as a batch\nawait core.append([Buffer.from('batch block 1'), Buffer.from('batch block 2')])\n```\n\n`options` include:\n\n```\n{\n  writable: false // Enabled ignores writable check. Does not override whether core is writable.\n  maxLength: undefined // The maximum resulting length of the core after appending\n  keyPair: core.keyPair // KeyPair used to sign the block(s)\n  signature: null // Set signature for block(s)\n}\n```\n\n#### `const block = await core.get(index, [options])`\n\nGet a block of data.\nIf the data is not available locally this method will prioritize and wait for the data to be downloaded.\n\n```js\n// get block #42\nconst block = await core.get(42)\n\n// get block #43, but only wait 5s\nconst blockIfFast = await core.get(43, { timeout: 5000 })\n\n// get block #44, but only if we have it locally\nconst blockLocal = await core.get(44, { wait: false })\n```\n\n`options` include:\n\n```js\n{\n  wait: true, // wait for block to be downloaded\n  onwait: () => {}, // hook that is called if the get is waiting for download\n  timeout: 0, // wait at max some milliseconds (0 means no timeout)\n  activeRequests: undefined, // Advanced option. Pass BlockRequest for replicating the block\n  valueEncoding: 'json' | 'utf-8' | 'binary', // defaults to the core's valueEncoding\n  decrypt: true, // automatically decrypts the block if encrypted\n  raw: false, // Return block without decoding\n}\n```\n\n#### `const has = await core.has(start, [end])`\n\nCheck if the core has all blocks between `start` and `end`.\n\n#### `const updated = await core.update([options])`\n\nWaits for initial proof of the new core length until all `findingPeers` calls have finished.\n\n```js\nconst updated = await core.update()\n\nconsole.log('core was updated?', updated, 'length is', core.length)\n```\n\n`options` include:\n\n```js\n{\n  wait: false,\n  activeRequests: undefined, // Advanced option. Pass requests for replicating blocks\n  force: false, // Force an update even if core is writable.\n}\n```\n\nUse `core.findingPeers()` or `{ wait: true }` to make `await core.update()` blocking.\n\n#### `const [index, relativeOffset] = await core.seek(byteOffset, [options])`\n\nSeek to a byte offset.\n\nReturns `[index, relativeOffset]`, where `index` is the data block the `byteOffset` is contained in and `relativeOffset` is\nthe relative byte offset in the data block.\n\n```js\nawait core.append([Buffer.from('abc'), Buffer.from('d'), Buffer.from('efg')])\n\nconst first = await core.seek(1) // returns [0, 1]\nconst second = await core.seek(3) // returns [1, 0]\nconst third = await core.seek(5) // returns [2, 1]\n```\n\n```js\n{\n  wait: true, // wait for data to be downloaded\n  timeout: 0, // wait at max some milliseconds (0 means no timeout)\n  activeRequests: undefined // Advanced option. Pass requests for replicating blocks\n}\n```\n\n#### `const stream = core.createReadStream([options])`\n\nMake a read stream to read a range of data out at once.\n\n```js\n// read the full core\nconst fullStream = core.createReadStream()\n\n// read from block 10-14\nconst partialStream = core.createReadStream({ start: 10, end: 15 })\n\n// pipe the stream somewhere using the .pipe method on Node.js or consume it as\n// an async iterator\n\nfor await (const data of fullStream) {\n  console.log('data:', data)\n}\n```\n\n`options` include:\n\n```js\n{\n  start: 0,\n  end: core.length,\n  wait: core.wait, // Whether to wait for updates from peers\n  timeout: core.timeout, // How long to wait for updates from peers\n  live: false, // Wait for next block keeping stream open / live\n  snapshot: true // auto set end to core.length on open or update it on every read\n}\n```\n\n#### `const bs = core.createByteStream([options])`\n\nMake a byte stream to read a range of bytes.\n\n```js\n// Read the full core\nconst fullStream = core.createByteStream()\n\n// Read from byte 3, and from there read 50 bytes\nconst partialStream = core.createByteStream({ byteOffset: 3, byteLength: 50 })\n\n// Consume it as an async iterator\nfor await (const data of fullStream) {\n  console.log('data:', data)\n}\n\n// Or pipe it somewhere like any stream:\npartialStream.pipe(process.stdout)\n```\n\n`options` include:\n\n```js\n{\n  byteOffset: 0, // Offset where to start from\n  byteLength: core.byteLength - options.byteOffset, // How many bytes to read\n  prefetch: 32 // How many bytes to download at a time\n}\n```\n\n#### `const stream = core.createWriteStream()`\n\nMake a write stream to append chunks as blocks.\n\n```js\nconst ws = core.createWriteStream()\n\n// Listen for stream finishing\nconst done = new Promise((resolve) => ws.on('finish', resolve))\n\nfor (const data of ['hello', 'world']) ws.write(data)\nws.end()\n\nawait done\n\nconsole.log(await core.get(core.length - 2)) // 'hello'\nconsole.log(await core.get(core.length - 1)) // 'world'\n```\n\n#### `const cleared = await core.clear(start, [end], [options])`\n\nClear stored blocks between `start` and `end`, reclaiming storage when possible.\n\n```js\nawait core.clear(4) // clear block 4 from your local cache\nawait core.clear(0, 10) // clear block 0-10 from your local cache\n```\n\nThe core will also gossip to peers it is connected to, that is no longer has these blocks.\n\n`options` include:\n\n```js\n{\n  diff: false // Returned `cleared` bytes object is null unless you enable this\n}\n```\n\n#### `await core.truncate(newLength, [options])`\n\nTruncate the core to a smaller length.\n\nPer default this will update the fork id of the core to `+ 1`, but you can set the fork id you prefer with the option `fork`.\nNote that the fork id should be monotonely incrementing.\n\n`options` include:\n\n```js\n{\n  fork: core.fork + 1, // The new fork id after truncating\n  keyPair: core.keyPair, // Key pair used for signing the truncation\n  signature: null, // Set signature for truncation\n}\n```\n\nIf `options` is a number, it will be used as the `fork` id.\n\n#### `const hash = await core.treeHash([length])`\n\nGet the Merkle Tree hash of the core at a given length, defaulting to the current length of the core.\n\n#### `const proof = await core.proof(opts)`\n\nGenerate a proof (a `TreeProof` instance) for the request `opts`.\n\n`opts` include:\n\n```\n{\n  block: { index, nodes }, // Block request\n  hash: { index, nodes }, // Hash Request\n  seek: { bytes, padding }, // Seek Request\n  upgrade: { start, length } // Upgrade request\n}\n```\n\nNote that you cannot seek & provide a block / hash request when upgrading.\n\n#### `const batch = await core.verifyFullyRemote(proof)`\n\nReturn the merkle tree batch from the proof. Will throw if the proof cannot be verified.\n\nNote that you cannot seek & provide a block / hash request when upgrading.\n\n#### `const buffer = await core.signable([length], [fork])`\n\nReturn a buffer which encodes the core's `key`, tree hash (`core.treeHash()`), `length`, & `fork`. If the `length` & `fork` arguments are not provided, the current values for the core are used by default.\n\n#### `const range = core.download([range])`\n\nDownload a range of data.\n\nYou can await when the range has been fully downloaded by doing:\n\n```js\nawait range.done()\n```\n\nA range can have the following properties:\n\n```js\n{\n  start: startIndex,\n  end: nonInclusiveEndIndex,\n  blocks: [index1, index2, ...],\n  linear: false, // download range linearly and not randomly\n  activeRequests: undefined // Advanced option. Pass requests for replicating blocks\n}\n```\n\nTo download the full core continuously (often referred to as non sparse mode) do\n\n```js\n// Note that this will never be considered downloaded as the range\n// will keep waiting for new blocks to be appended.\ncore.download({ start: 0, end: -1 })\n```\n\nTo download a discrete range of blocks pass a list of indices.\n\n```js\ncore.download({ blocks: [4, 9, 7] })\n```\n\nTo cancel downloading a range simply destroy the range instance.\n\n```js\n// will stop downloading now\nrange.destroy()\n```\n\n#### `const ext = core.registerExtension(name, handlers = {})`\n\nRegister a custom protocol extension. This is a legacy implementation and is no longer recommended. Creating a [`Protomux`](https://github.com/holepunchto/protomux) protocol is recommended instead.\n\n`handlers` include:\n\n```\n{\n  encoding: 'json' | 'utf-8' | 'binary', // Compact encoding to use for messages. Defaults to buffer\n  onmessage: (message, peer) => { ... } // Callback for when a message for the extension is received\n}\n```\n\n##### ext.send(message, peer)\n\nSends the `message` to a specific `peer`.\n\n##### ext.broadcast(message)\n\nSends the `message` to all peers.\n\n##### ext.destroy()\n\nUnregister and remove extension from the hypercore.\n\n#### `const session = core.session([options])`\n\nCreates a new Hypercore instance that shares the same underlying core.\n\nYou must close any session you make.\n\nOptions are inherited from the parent instance, unless they are re-set.\n\n`options` are the same as in the constructor with the following additions:\n\n```\n{\n  weak: false // Creates the session as a \"weak ref\" which closes when all non-weak sessions are closed\n  exclusive: false, // Create a session with exclusive access to the core. Creating an exclusive session on a core with other exclusive sessions, will wait for the session with access to close before the next exclusive session is `ready`\n  checkout: undefined, // A index to checkout the core at. Checkout sessions must be an atom or a named session\n  atom: undefined, // A storage atom for making atomic batch changes across hypercores\n  name: null, // Name the session creating a persisted branch of the core. Still beta so may break in the future\n}\n```\n\nAtoms allow making atomic changes across multiple hypercores. Atoms can be created using a `core`'s `storage` (eg. `const atom = core.state.storage.createAtom()`). Changes made with an atom based session is not persisted until the atom is flushed via `await atom.flush()`, but can be read at any time. When atoms flush, all changes made outside of the atom will be clobbered as the core blocks will now match the atom's blocks. For example:\n\n```js\nconst core = new Hypercore('./atom-example')\nawait core.ready()\n\nawait core.append('block 1')\n\nconst atom = core.state.storage.createAtom()\nconst atomicSession = core.session({ atom })\n\nawait core.append('block 2') // Add blocks not using the atom\n\nawait atomicSession.append('atom block 2') // Add different block to atom\nawait atom.flush()\n\nconsole.log((await core.get(core.length - 1)).toString()) // prints 'atom block 2' not 'block 2'\n```\n\n#### `const { byteLength, length } = core.commit(session, opts = {})`\n\nAttempt to apply blocks from the session to the `core`. `core` must be a default core, aka a non-named session.\n\nReturns `null` if committing failed.\n\n`opts` includes:\n\n```\n{\n  length: session.length, // the core's length after committing the blocks\n  treeLength: core.length, // The expected length of the core's merkle tree prior to commit\n  keyPair: core.keyPair, // The keypair to use when committing\n  signature: undefined, // The signature for the blocks being committed\n}\n```\n\n#### `const snapshot = core.snapshot([options])`\n\nSame as [`core.session(options)`](#const-session--coresessionoptions), but backed by a storage snapshot so will not truncate nor append.\n\n#### `const info = await core.info([options])`\n\nGet information about this core, such as its total size in bytes.\n\nThe object will look like this:\n\n```js\nInfo {\n  key: Buffer(...),\n  discoveryKey: Buffer(...),\n  length: 18,\n  contiguousLength: 16,\n  byteLength: 742,\n  fork: 0,\n  padding: 8,\n  storage: {\n    oplog: 8192,\n    tree: 4096,\n    blocks: 4096,\n    bitfield: 4096\n  }\n}\n```\n\n`options` include:\n\n```js\n{\n  storage: false // get storage estimates in bytes, disabled by default\n}\n```\n\n#### `await core.setGroup(topic)`\n\n> [!IMPORTANT]\n> This feature is _experimental_. The API is subject to change, and everything may break.\n\nSet the group `topic` that the hypercore belongs to. Useful for grouping hypercores together that need to update a larger data structure (eg. `autobee`) that is comprised of them. See `corestore`'s `store.notifyGroup(topic)` for more details.\n\n`topic` is a 32 byte buffer. A hypercore can only have one `topic`.\n\n#### `await core.startMarking()`\n\nThis enables marking mode for the \"mark & sweep\" approach to clear hypercore storage. When called the current markings are cleared.\n\n##### Mark & Sweep\n\nThis technique allows for marking blocks that should be kept and assuming all other blocks should be cleared. It can be achieved using the following steps:\n\n1. Enable marking mode via `await core.startMarking()`.\n2. Get all blocks that should be kept.  \n   While the marking mode is enabled, all blocks retrieved (via `.get()`, etc) will be \"marked\". Marked blocks will not be cleared when sweeping.\n3. Sweep to clear unmarked blocks via `await core.sweep()`.  \n   Once complete, all blocks that were not marked will be cleared.\n\n> [!CAUTION]\n> Be careful that caching does not skip a call to `.get()`.  \n> For example, `hyperbee` has caches for looking up the b-tree nodes that\n> needs to be cleared before using mark & sweep.\n\nExample:\n\n```js\nawait core.startMarking()\nawait core.get(2)\nawait core.get(4)\nawait core.sweep() // All blocks but blocks 2 & 4 are cleared\n```\n\n#### `await core.markBlock(start, end = start + 1)`\n\nManually mark a block or range of blocks to be retained when sweeping. Useful to mark blocks without loading them into memory. `end` is non-inclusive and defaults to `start + 1` so `core.markBlock(index)` only marks the block at `index`.\n\n#### `await core.clearMarkings()`\n\nManually remove all markings. Automatically called when calling `core.startMarking()`.\n\n#### `await core.sweep(opts)`\n\nClear all unmarked blocks from storage.\n\n`opts` can include:\n\n```\n{\n  batchSize: 1000 // How frequently to flush clears to storage.\n}\n```\n\n#### `await core.close([{ error }])`\n\nFully close this core. Passing an error via `{ error }` is optional and all pending replicator requests will be rejected with the error.\n\n#### `core.on('close')`\n\nEmitted when the core has been fully closed.\n\n#### `await core.ready()`\n\nWait for the core to fully open.\n\nAfter this has called `core.length` and other properties have been set.\n\nIn general you do NOT need to wait for `ready`, unless checking a synchronous property,\nas all internals await this themself.\n\n#### `core.on('ready')`\n\nEmitted after the core has initially opened all its internal state.\n\n#### `core.writable`\n\nCan we append to or truncate this core?\n\nPopulated after `ready` has been emitted. Will be `false` before the event.\n\n#### `core.readable`\n\nCan we read from this core? After closing the core this will be false.\n\nPopulated after `ready` has been emitted. Will be `false` before the event.\n\n#### `core.id`\n\nString containing the id (z-base-32 of the public key) identifying this core.\n\nPopulated after `ready` has been emitted. Will be `null` before the event.\n\n#### `core.key`\n\nBuffer containing the public key identifying this core.\n\nPopulated after `ready` has been emitted. Will be `null` before the event.\n\n#### `core.keyPair`\n\nObject containing buffers of the core's public and secret key\n\nPopulated after `ready` has been emitted. Will be `null` before the event.\n\n#### `core.discoveryKey`\n\nBuffer containing a key derived from the core's public key.\nIn contrast to `core.key` this key does not allow you to verify the data but can be used to announce or look for peers that are sharing the same core, without leaking the core key.\n\nPopulated after `ready` has been emitted. Will be `null` before the event.\n\n#### `core.length`\n\nHow many blocks of data are available on this core.\n\nPopulated after `ready` has been emitted. Will be `0` before the event.\n\n#### `core.signedLength`\n\nHow many blocks of data are available on this core that have been signed by a quorum. This is equal to `core.length` for Hypercores with a single signer.\n\nPopulated after `ready` has been emitted. Will be `0` before the event.\n\n#### `core.contiguousLength`\n\nHow many blocks are contiguously available starting from the first block of this core.\n\nPopulated after `ready` has been emitted. Will be `0` before the event.\n\n#### `core.remoteContiguousLength`\n\nHow many blocks are contiguously available starting from the first block of this core on any known remote. This is only updated when a remote thinks it is fully contiguous such that they have all known blocks.\n\nPopulated after `ready` has been emitted. Will be `0` before the event.\n\n#### `core.fork`\n\nWhat is the current fork id of this core?\n\nPopulated after `ready` has been emitted. Will be `0` before the event.\n\n#### `core.padding`\n\nHow much padding is applied to each block of this core? Will be `0` unless block encryption is enabled.\n\n#### `core.peers`\n\nArray of current peers the core is replicating with.\n\n#### `await core.setEncryption(encryption)`\n\nSet the encryption, which should satisfy the [HypercoreEncryption](https://github.com/holepunchto/hypercore-encryption) interface.\n\n#### `await core.setEncryptionKey(key, [opts])`\n\nSet the encryption key.\n\n`opts` includes:\n\n```\n{\n  block: false, // Whether the key is for block encryption\n}\n```\n\n#### `core.setKeyPair(keyPair)`\n\nUpdate the core's `keyPair`. Advanced as the `keyPair` is used throughout Hypercore, e.g. verifying blocks, identifying the core, etc.\n\n#### `core.setActive(active)`\n\nSet the core to be active or not. A core is considered 'active' if it should linger to download blocks from peers.\n\nWhen calling `core.setActive(true)` make sure to later call `core.setActive(false)` to mark it as inactive otherwise the core's activity tracking will be inaccurate and keep replication channels open.\n\n#### `core.setAlwaysLatestBlock(enabled)`\n\nSet whether the replicator should always include a request for the latest block in an upgrade request (aka the peer has a length update). A runtime method for updating the `allowLatestBlock` option.\n\n#### `await core.setUserData(key, value)`\n\nSet a key in the User Data key-value store.\n\n`key` is a string and `value` can be a string or buffer.\n\n#### `const value = await core.getUserData(key)`\n\nReturn the value for a key in the User Data key-value store.\n\n`key` is a string.\n\n#### `const stream = core.replicate(isInitiatorOrReplicationStream, opts = {})`\n\nCreate a replication stream. You should pipe this to another Hypercore instance.\n\nThe `isInitiator` argument is a boolean indicating whether you are the initiator of the connection (ie the client)\nor if you are the passive part (ie the server).\n\nIf you are using a P2P swarm like [Hyperswarm](https://github.com/hyperswarm/hyperswarm) you can know this by checking if the swarm connection is a client socket or server socket. In Hyperswarm you can check that using the [client property on the peer details object](https://github.com/hyperswarm/hyperswarm#swarmonconnection-socket-details--)\n\nIf you want to multiplex the replication over an existing Hypercore replication stream you can pass\nanother stream instance instead of the `isInitiator` boolean.\n\n```js\n// assuming we have two cores, localCore + remoteCore, sharing the same key\n// on a server\nconst net = require('net')\nconst server = net.createServer(function (socket) {\n  socket.pipe(remoteCore.replicate(false)).pipe(socket)\n})\n\n// on a client\nconst socket = net.connect(...)\nsocket.pipe(localCore.replicate(true)).pipe(socket)\n```\n\n`opts` are same as [`Hypercore.createProtocolStream()`](#const-stream--hypercorecreateprotocolstreamisinitiator-opts--).\n\n#### `const done = core.findingPeers()`\n\nCreate a hook that tells Hypercore you are finding peers for this core in the background. Call `done` when your current discovery iteration is done.\nIf you're using Hyperswarm, you'd normally call this after a `swarm.flush()` finishes.\n\nThis allows `core.update` to wait for either the `findingPeers` hook to finish or one peer to appear before deciding whether it should wait for a merkle tree update before returning.\n\n#### `core.on('append')`\n\nEmitted when the core has been appended to (i.e. has a new length / byteLength), either locally or remotely.\n\n#### `core.on('truncate', ancestors, forkId)`\n\nEmitted when the core has been truncated, either locally or remotely.\n\n#### `core.on('peer-add')`\n\nEmitted when a new connection has been established with a peer.\n\n#### `core.on('peer-remove')`\n\nEmitted when a peer's connection has been closed.\n\n#### `core.on('upload', index, byteLength, peer)`\n\nEmitted when a block is uploaded to a peer.\n\n#### `core.on('download', index, byteLength, peer)`\n\nEmitted when a block is downloaded from a peer.\n\n#### `core.on('remote-contiguous-length', length)`\n\nEmitted when the max known contiguous `length` from a remote, ie `core.remoteContiguousLength`, is updated. Note this is not emitted when core is truncated.\n\n#### `Hypercore.MAX_SUGGESTED_BLOCK_SIZE`\n\nThe constant for max size (15MB) for blocks appended to Hypercore. This max ensures blocks are replicated smoothly.\n\n#### `const key = Hypercore.key(manifest, options = {})`\n\nReturns the key for a given manifest.\n\n`options` include:\n\n```\n{\n  compat: false,  // Whether the manifest has a single signer whose public key is the key\n  version,        // Manifest version if the manifest argument is the public key of a single signer\n  namespace       // The signer namespace if the manifest argument is the public key of a single signer\n}\n```\n\n#### `const dKey = Hypercore.discoveryKey(key)`\n\nReturns the discovery key for the provided `key`.\n\n#### `const bkey = Hypercore.blockEncryptionKey(key, encryptionKey)`\n\nReturns a block encryption key derived from the `key` and `encryptionKey`.\n\n#### `const mux = Hypercore.getProtocolMuxer(stream)`\n\nReturns a protomux instance from the provided `stream` Hypercore protocol stream.\n\n#### `const core = Hypercore.createCore(storage, opts)`\n\nReturns the internal core using the `storage` and `opts` without creating a full Hypercore instance.\n\n#### `const stream = Hypercore.createProtocolStream(isInitiator, opts = {})`\n\nCreate an encrypted noise stream with a protomux instance attached used for Hypercore's replication protocol.\n\n`isInitiator` can be a framed stream, a protomux or a boolean for whether the stream should be the initiator in the noise handshake.\n\n`opts` can include:\n\n```\n{\n  ondiscoverykey: () => {}, // A handler for when a discovery key is set over the stream for corestore management\n}\n```\n\n#### `const storage = Hypercore.defaultStorage(storage, opts = {})`\n\nReturns a default hypercore storage. The `storage` argument can be a path where to create the `hypercore-storage` instance or an existing `hypercore-storage` instance. If an existing instance, it is immediately returned.\n","publish_time":1748692362863,"_cnpm_publish_time":1748692362863,"dist-tags":{"latest":"11.40.4","next":"10.36.1"}}