holepunchto / hypercore-crypto Goto Github PK
View Code? Open in Web Editor NEWThe crypto primitives used in hypercore, extracted into a separate module
License: MIT License
The crypto primitives used in hypercore, extracted into a separate module
License: MIT License
Hey,
Today we update hypercore-crypto
and it seems that b4a
is missing some buffer operations for the browser, one of them is writeUInt32BE
and it breaks the encodeUInt64
of hypercore-crypto.
index.js?fc28:14 Uncaught (in promise) TypeError: buf.writeUInt32BE is not a function
at Object.exports.encode (index.js?fc28:14)
at encodeUInt64 (index.js?4681:184)
at Object.exports.data (index.js?4681:104)
at MerkleGenerator.exports.leaf [as _leaf] (index.js?4681:112)
at MerkleGenerator.next (generator.js?b45a:37)
at Feed._append (index.js?d11e:1500)
at work (index.js?d11e:158)
at Feed.append [as _batch] (index.js?3518:44)
at Feed.append (index.js?d11e:1404)
at eval (index.js?44d0:106)
sodium.crypto_generichash
expects an input
buffer of arbitrary length and an optional key
. According to sodium docs the input
is hashed, and the optional key
"can be used to make sure that different applications generate different fingerprints even if they process the same data." and different keys "are very likely to produce distinct fingerprints". This "very likely" seems to suggest that this is not as reliable as a hash.
The sodium-native docs say the input
is the second arg, and key
is the third arg, however discoveryKey
seems to call the arguments in the wrong order:
exports.discoveryKey = function (tree) {
var digest = bufferAlloc(32)
sodium.crypto_generichash(digest, HYPERCORE, tree)
return digest
}
As far as I understand, HYPERCORE
should be the key
. I understand from #3 that tree
is actually the publicKey
. The consequence of this (I think, although I don't know the internals of sodium) is that the hash is not as guaranteed against collisions. It may be that this doesn't matter and changing the key
is being hashed with the same algorithm as the input
, but it doesn't seem like this was the intended way for this to work.
For example, leaf
and parent
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.