Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

ssb-crut

Package Overview
Dependencies
Maintainers
3
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssb-crut - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

2

lib/handle-publish.js

@@ -26,3 +26,3 @@ const stringify = require('fast-json-stable-stringify')

const dummyNode = msgToNode(dummyMsg)
const dummyNode = msgToNode(dummyMsg, 0)
// if this is a merge update, check if it would be a valid merge.

@@ -29,0 +29,0 @@ if (previous && previous.length > 1) {

@@ -5,3 +5,3 @@ const Reduce = require('@tangle/reduce')

const GetUpdates = require('./get-updates')
const { MsgToNode } = require('./util')
const { MsgsToNodes } = require('./util')

@@ -11,7 +11,7 @@ module.exports = function ResolveTangle (ssb, crut) {

const msgToNode = MsgToNode(spec)
const getRoot = GetRoot(ssb, crut)
const getUpdates = GetUpdates(ssb, crut)
const msgsToNodes = MsgsToNodes(spec)
return function resolveTangle (id, cb) {

@@ -28,3 +28,3 @@ // First, the root message and it's update messages are fetched from the ssb

const reduce = new Reduce(strategy, {
nodes: msgs.map(msgToNode),
nodes: msgsToNodes(msgs),
isValidNextStep: (context, node) => {

@@ -31,0 +31,0 @@ context.root = root

const merge = require('lodash.merge')
const Graph = require('@tangle/graph')

@@ -52,7 +53,7 @@ function isObject (obj) {

function MsgToNode (spec) {
return function msgToNode (msg) {
return function msgToNode (msg, d) {
return {
key: msg.key,
previous: msg.value.content.tangles[spec.tangle].previous,
data: spec.getTransformation(msg),
data: spec.getTransformation(msg, d),
// Note: getTransformation may include props that are not in the strategy

@@ -66,2 +67,31 @@

function MsgsToNodes (spec) {
const msgToNode = MsgToNode(spec)
return function msgsToNodes (msgs) {
if (spec.getTransformation === defaultGetTransformation) {
return msgs.map(msgToNode)
}
const graph = new Graph(
msgs.map(m => ({
key: m.key,
previous: m.value.content.tangles[spec.tangle].previous
}))
)
return msgs
.sort((a, b) => {
// if a is in the history of b, it came before b
if (graph.getHistory(b.key).includes(a.key)) return -1
// if b is in the history of a, it came before a
if (graph.getHistory(a.key).includes(b.key)) return +1
// otherwise, the messages were concurrent, so we break by timestamp
return a.value.timestamp - b.value.timestamp
})
.map((msg, i) => msgToNode(msg, i))
}
}
module.exports = {

@@ -73,3 +103,4 @@ isObject,

getCanonicalContent,
MsgToNode
MsgToNode,
MsgsToNodes
}
{
"name": "ssb-crut",
"version": "5.0.0",
"version": "5.1.0",
"description": "easy CRUT methods for secure scuttlebutt",

@@ -32,2 +32,3 @@ "main": "index.js",

"dependencies": {
"@tangle/graph": "^3.2.0",
"@tangle/reduce": "^5.0.4",

@@ -34,0 +35,0 @@ "@tangle/strategy": "^4.1.2",

@@ -176,4 +176,6 @@ # ssb-crut

- `spec.getTransformation` *Function*
- a function which is used to map a full message (`{ key, value }`) to a transformation
- default: `m => m.value.content`
- a function of signature `(msg, d)` used to map a full message to a transformation
- `msg` is a message in the form `{ key, value }`
- `d` is an index of the message within a flattened version of the tangle
- default: `(msg) => msg.value.content`
- this is particularly useful for coercing legacy messages into a format your spec can process

@@ -180,0 +182,0 @@ - WARNING: **create a new object** if you plan to mutate the shape of a message, otherwise ssb-crut will break

Sorry, the diff of this file is not supported yet

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