New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hypercore

Package Overview
Dependencies
Maintainers
2
Versions
510
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hypercore - npm Package Compare versions

Comparing version 11.0.1 to 11.0.2

14

index.js

@@ -210,3 +210,3 @@ const { EventEmitter } = require('events')

const wait = opts.wait === false ? false : this.wait
const writable = opts.writable === false ? false : !this._readonly
const writable = opts.writable === undefined ? !this._readonly : opts.writable === true
const onwait = opts.onwait === undefined ? this.onwait : opts.onwait

@@ -249,3 +249,2 @@ const timeout = opts.timeout === undefined ? this.timeout : opts.timeout

if (!this.keyPair) this.keyPair = parent.keyPair
this.writable = this._isWritable()

@@ -346,9 +345,9 @@ const s = parent.state

const parent = opts.parent || this.core
const checkout = opts.checkout === undefined ? -1 : opts.checkout
if (opts.atom) {
this.state = await parent.state.createSession(null, -1, false, opts.atom)
this.state = await parent.state.createSession(null, checkout, false, opts.atom)
} else if (opts.name) {
// todo: need to make named sessions safe before ready
// atm we always copy the state in passCapabilities
const checkout = opts.checkout === undefined ? -1 : opts.checkout
const state = this.state

@@ -366,2 +365,4 @@

this.writable = this._isWritable()
if (this.snapshotted && this.core) this._updateSnapshot()

@@ -411,4 +412,5 @@

_isWritable () {
if (this.draft) return true
return !this._readonly && !!(this.keyPair && this.keyPair.secretKey)
if (this._readonly) return false
if (this.state && !this.state.isDefault()) return true
return !!(this.keyPair && this.keyPair.secretKey)
}

@@ -415,0 +417,0 @@

@@ -129,3 +129,3 @@ const crypto = require('hypercore-crypto')

for (const { key, value } of userData) {
tx.setUserData(key, value)
tx.putUserData(key, value)
}

@@ -132,0 +132,0 @@

@@ -11,3 +11,3 @@ const crypto = require('hypercore-crypto')

const RemoteBitfield = require('./remote-bitfield')
const { BAD_ARGUMENT, STORAGE_EMPTY, STORAGE_CONFLICT, INVALID_OPERATION, INVALID_SIGNATURE, INVALID_CHECKSUM } = require('hypercore-errors')
const { BAD_ARGUMENT, STORAGE_EMPTY, STORAGE_CONFLICT, INVALID_SIGNATURE, INVALID_CHECKSUM } = require('hypercore-errors')
const Verifier = require('./verifier')

@@ -378,3 +378,3 @@ const audit = require('./audit')

if (this.state.length > state.length) {
throw new Error('Invalid commit: partial commit') // TODO: partial commit in the future if possible
return false // TODO: partial commit in the future if possible
}

@@ -386,3 +386,3 @@

if (batchRoot.size !== root.size || !b4a.equals(batchRoot.hash, root.hash)) {
throw new Error('Invalid commit: tree conflict')
return false
}

@@ -393,4 +393,6 @@ }

if (this.verifier === null) {
throw INVALID_OPERATION('Cannot commit without manifest') // easier to assert than upsert
return false // easier to assert than upsert
}
return true
}

@@ -397,0 +399,0 @@

@@ -24,3 +24,3 @@ const c = require('compact-encoding')

async function partialSignature (core, signer, from, to = core.state.length, signature = core.state.signature) {
if (from > core.tree.length) return null
if (from > core.state.length) return null
const nodes = to <= from ? null : await upgradeNodes(core, from, to)

@@ -39,6 +39,6 @@

async function upgradeNodes (core, from, to) {
const batch = core.storage.read()
const rx = core.state.storage.read()
const treeBatch = core.state.createTreeBatch()
const p = await core.tree.proof(batch, treeBatch, { upgrade: { start: from, length: to - from } })
batch.tryFlush()
const p = await core.state.tree.proof(rx, treeBatch, { upgrade: { start: from, length: to - from } })
rx.tryFlush()
return (await p.settle()).upgrade.nodes

@@ -45,0 +45,0 @@ }

@@ -38,2 +38,3 @@ const crypto = require('hypercore-crypto')

if (treeInfo.length < this.dependencyLength) this.dependencyLength = treeInfo.length
if (treeInfo.roots.length) this.setRoots(treeInfo.roots)

@@ -113,3 +114,4 @@

length: this.length,
prologue: this.prologue
prologue: this.prologue,
signature: this.signature
}

@@ -149,7 +151,7 @@ }

updateDependency (storage, length) {
updateDependency (tx, length) {
const dependency = updateDependency(this, length)
if (dependency) {
this.dependencyLength = dependency.length
storage.setDependency(dependency)
tx.setDependency(dependency)
}

@@ -208,2 +210,4 @@

async _oncommit (src, bitfield) {
const currLength = this.length
this.fork = src.fork

@@ -236,7 +240,12 @@ this.length = src.length

if (!bitfield || !bitfield.drop) {
this.onappend(tree, bitfield, true)
} else {
this.ontruncate(tree, bitfield.start, bitfield.start + bitfield.length, true)
const truncated = (bitfield && bitfield.truncated !== -1)
? bitfield.truncated
: src.dependencyLength
if (truncated < currLength) {
this.ontruncate(tree, truncated, currLength, true)
if (!bitfield || bitfield.length === 0) return
}
this.onappend(tree, bitfield, true)
}

@@ -519,18 +528,36 @@

_updateBitfield (bitfield, flushed) {
if (!bitfield) return
const p = this._pendingBitfield
const b = bitfield
if (b.drop) {
if (p === null) {
this._pendingBitfield = { truncated: b.start, start: b.start, length: 0, drop: false }
return
}
if (p.drop) {
if (p.truncated !== b.start + b.length) throw INVALID_OPERATION('Atomic truncations must be contiguous')
p.truncated = b.start
return
}
if (b.start < p.start) throw INVALID_OPERATION('Atomic truncations must be contiguous')
p.length = b.start - p.start
if (p.length === 0) this._pendingBitfield = null
return
}
if (p === null) {
if (bitfield) this._pendingBitfield = bitfield
this._pendingBitfield = { truncated: -1, start: b.start, length: b.length, drop: false }
return
}
if (p.drop) {
const from = bitfield.start + bitfield.length
if (!bitfield.drop || p.start !== from) throw INVALID_OPERATION('Atomic truncations must be contiguous')
if (b.start !== p.start + p.length) {
throw INVALID_OPERATION('Atomic operations must be contiguous')
}
p.length += bitfield.length
p.start = bitfield.start
} else {
p.length = bitfield.start + bitfield.length - p.start
}
p.length += b.length
}

@@ -679,3 +706,3 @@

await this.core._validateCommit(state, treeLength)
if (!(await this.core._validateCommit(state, treeLength))) return null

@@ -739,2 +766,4 @@ if (this.length < length && !signature) {

if (length === this.length) head.signature = this.signature
return head

@@ -750,2 +779,6 @@ }

// storage was updated
const deps = this.storage.dependencies
this.dependencyLength = deps[deps.length - 1].length
for (let i = this.sessions.length - 1; i >= 0; i--) this.sessions[i].transferSession(this.core)

@@ -843,3 +876,4 @@ }

length,
prologue: this.prologue
prologue: this.prologue,
signature: length === this.length ? this.signature : null
}

@@ -846,0 +880,0 @@

{
"name": "hypercore",
"version": "11.0.1",
"version": "11.0.2",
"description": "Hypercore is a secure, distributed append-only log",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc