Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@pryv/stable-object-representation
Advanced tools
It provides utility to
stableRepresentation.event.stringify(event)
Returns a "stable" JSON reprersentation of an event as described bellow.
stableRepresentation.event.hash(event, [algorithm])
Returns a hash of "stable" JSON reprersentation of an event, prefixed with 'EVENT:O' and encoded in base64 following subresource integrity (SRI) specifcation See W3.org/TR/SRI. By default SHA256 is used.
Example: EVENT:0:sha256-X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=
stableRepresentation.event.key(event)
Returns a unique key for this event version.
stableRepresentation.event.compute(event, [algorithm])
Returns an object equivalent of { key: key(event), hash: hash(event, algorithm) }
{
key: 'EVENT:0:ckoxy0giw000hrs9yvi3rnlfm:1621578570.151',
integrity: 'EVENT:0:sha256-X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE='
}
In this example we will use javascript as pseudo code examples.
JSON.parse(stableRep)
must be valid. (stableRep;
is a stable representation of a JSON object as a string.){"keyA":"valueA","keyB":["item0B","item1B"]}
is valid,{"keyA": "valueA", "keyB": ["item0B", "item1B"]}
is not."
.{"keyForNumericalValue":12.23}
is valid,{"keyForNumericalValue":"12.23"}
is not."
.{"keyForBooleanValue":false}
is valid,{"keyForBooleanValue":"false"}
is not.sort()
function./**
* Compare two strings based on the UTF16 code value of their characters.
* Characters are consumed one by one on each string.
* if the shortest string equals the first characters of the longest one, the shortest is before.
* @param a
* @param b
* @returns {number} -1 if a is before b, 1 if b is before a, 0 if they are equals.
*/
function utf16StrCompare(a, b) {
var lA = a.length;
var lB = b.length;
// default A is shorter and equals firstsB chars: A first
var l = lA;
var dres = -1;
// B is shorter and equals firstsA chars: B first
if (lA > lB) { l = lB; dres = -1; }
// A and B are the same size
if (lA === lB) {dres = 0; }
var res;
for (var i = 0; i < l; i++) {
res = a.charCodeAt(i) - b.charCodeAt(i);
if (res !== 0) {
return res;
}
}
return dres;
}
. key
. structure: {item code}:{item code version}:{item id}:{item version}
usually the item version is the modified
date property
. They key is unique it is used to find a corresponding checksum.
. integrity
. structure: {item code}:{item code version}:{algorithm}-{checksum base64 encode}
. EVENT:0:
correspond to item id = event.id
and item version = event.modified
. If event.modified
is not present, then event.deleted
is used.
. ACCESS:0:
correspond to item id =access.id
and item version = access.modified
. If access.modified
is not present, then access.deleted
is used.
. EVENT:0:
correspond to encoding of current implementation of stableRepresentation.event.stringify0(event)
. ACCESS:0:
correspond to encoding of current implementation of stableRepresentation.access.stringify0(access)
Properties with a null values, will be ignored from the representation.
Special attention is required for
Properties with a null values, will be ignored from the representation.
Special attention is required for
false
is ignored from the representation.null
is ignored from the representation.0
is ignored from the representation <=> to undefined
.streamIds
whith the value [streamId]
Example
{
"id": "ciusga35r000sgwg4o1sr1j5q",
"time": 1477575221.247,
"streamId": "diary",
"duration": 0,
"type": "picture/attached",
"tags": [],
"description": "test\"te\"st",
"attachments": [
{
"id": "ciusga35r000tgwg4hcz2i22u",
"fileName": "photo.jpg",
"type": "image/jpeg",
"size": 2561,
"readToken": "cjasdashdhgad-asdjhasdhsdh"
},
{
"id": "ciusga35r000tgwg4hcz2i32u",
"fileName": "photo.jpg",
"type": "image/jpeg",
"size": 2561,
"readToken": "cjasdashdhgad-asdjhasdhsdh"
}
],
"created": 1477575221.247,
"createdBy": "ciusga33w0004gwg436uhtqs2",
"modified": 1477575221.247,
"modifiedBy": "ciusga33w0004gwg436uhtqs2",
"trashed": false,
"clientData": {
"key2": "value2",
"key1": "value1"
}
}
Stable representation:
{"attachments":[{"fileName":"photo.jpg","id":"ciusga35r000tgwg4hcz2i22u","size":2561,"type":"image/jpeg"},{"fileName":"photo.jpg","id":"ciusga35r000tgwg4hcz2i32u","size":2561,"type":"image/jpeg"}],"clientData":{"key1":"value1","key2":"value2"},"created":1477575221.247,"createdBy":"ciusga33w0004gwg436uhtqs2","description":"test\"te\"st","id":"ciusga35r000sgwg4o1sr1j5q","modified":1477575221.247,"modifiedBy":"ciusga33w0004gwg436uhtqs2","streamId":"diary","time":1477575221.247,"type":"picture/attached"}
Copyright (C) 2020-2021 Pryv S.A. https://pryv.com This file is part of Open-Pryv.io and released under BSD-Clause-3 License SPDX-License-Identifier: BSD-3-Clause
FAQs
Stable JSON Object representation
We found that @pryv/stable-object-representation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.