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

primea-objects

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

primea-objects - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

31

index.js

@@ -0,1 +1,2 @@

const crypto = require('crypto')
const cbor = require('borc')

@@ -190,2 +191,29 @@ const EventEmitter = require('events')

/**
* returns the ID of an actor
* @param {Object} id
* @param {Number} id.nonce - the actor's nonce
* @param {ID} id.parent - the actor's parent's ID
* @return {ID}
*/
function generateActorId (id) {
const encoded = _encodeActorId(id)
const hashed = _hash(encoded)
return new ID(hashed)
}
function _encodeActorId (id) {
if (id.parent) {
return cbor.encode([id.nonce, id.parent.id])
} else {
return cbor.encode([id.nonce, null])
}
}
function _hash (buf) {
const hash = crypto.createHash('sha256')
hash.update(buf)
return hash.digest().slice(0, 20)
}
module.exports = {

@@ -197,3 +225,4 @@ Message,

decoder,
getType
getType,
generateActorId
}

6

package.json
{
"name": "primea-objects",
"version": "0.0.3",
"version": "0.0.4",
"description": "Object helper classes for Primea's system Objects",

@@ -25,4 +25,4 @@ "main": "index.js",

"coveralls": "^3.0.0",
"documentation": "^6.1.0",
"nyc": "^11.6.0",
"documentation": "^6.3.0",
"nyc": "^11.7.1",
"standard": "^11.0.1",

@@ -29,0 +29,0 @@ "tape": "^4.9.0"

@@ -7,3 +7,2 @@ const Buffer = require('safe-buffer').Buffer

tape('system objects', t => {
t.equals(objects.getType(), 'invalid')

@@ -53,1 +52,17 @@ t.equals(objects.getType(true), 'invalid')

})
tape('actor IDs', t => {
const id0 = { nonce: 0, parent: null }
const hashedId0 = objects.generateActorId(id0)
t.deepEquals(hashedId0.id, Buffer.from('372a08b828598122fc64c4aa94735c770f25bbbc', 'hex'))
const id00 = { nonce: 0, parent: hashedId0 }
const hashedId00 = objects.generateActorId(id00)
t.deepEquals(hashedId00.id, Buffer.from('10d7d4be8663c37d8ea7cff89b7c01c059ebbc80', 'hex'))
const id01 = { nonce: 1, parent: hashedId0 }
const hashedId01 = objects.generateActorId(id01)
t.deepEquals(hashedId01.id, Buffer.from('0ca311b75efd27e7daf6eec8b51b5c1fe33ff233', 'hex'))
t.end()
})
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