mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-07-21 21:42:03 +00:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
df23d634c5 | ||
|
88e1bcf75f | ||
|
c54ea206f0 | ||
|
857d2bd902 | ||
|
200110cb9d | ||
|
9e5778694c | ||
|
87e8f1c86f | ||
|
df75980a88 |
32
.travis.yml
32
.travis.yml
@@ -1,32 +0,0 @@
|
||||
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
|
||||
sudo: false
|
||||
language: node_js
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- node_js: 6
|
||||
env: CXX=g++-4.8
|
||||
- node_js: 8
|
||||
env: CXX=g++-4.8
|
||||
# - node_js: stable
|
||||
# env: CXX=g++-4.8
|
||||
|
||||
script:
|
||||
- npm run lint
|
||||
- npm run test
|
||||
- npm run coverage
|
||||
|
||||
before_script:
|
||||
- export DISPLAY=:99.0
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
|
||||
after_success:
|
||||
- npm run coverage-publish
|
||||
|
||||
addons:
|
||||
firefox: 'latest'
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-4.8
|
20
CHANGELOG.md
20
CHANGELOG.md
@@ -1,3 +1,23 @@
|
||||
<a name="0.15.0"></a>
|
||||
# [0.15.0](https://github.com/libp2p/js-libp2p-crypto/compare/v0.14.1...v0.15.0) (2019-01-03)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* nextTick instead of setImmediate, and fix sync in async ([#136](https://github.com/libp2p/js-libp2p-crypto/issues/136)) ([c54ea20](https://github.com/libp2p/js-libp2p-crypto/commit/c54ea20))
|
||||
|
||||
|
||||
|
||||
<a name="0.14.1"></a>
|
||||
## [0.14.1](https://github.com/libp2p/js-libp2p-crypto/compare/v0.14.0...v0.14.1) (2018-11-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* dont setimmediate when its not needed ([9e57786](https://github.com/libp2p/js-libp2p-crypto/commit/9e57786))
|
||||
|
||||
|
||||
|
||||
<a name="0.14.0"></a>
|
||||
# [0.14.0](https://github.com/libp2p/js-libp2p-crypto/compare/v0.13.0...v0.14.0) (2018-09-17)
|
||||
|
||||
|
29
appveyor.yml
29
appveyor.yml
@@ -1,29 +0,0 @@
|
||||
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
|
||||
version: "{build}"
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- nodejs_version: "6"
|
||||
- nodejs_version: "8"
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
install:
|
||||
# Install Node.js
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
|
||||
# Upgrade npm
|
||||
- npm install -g npm
|
||||
|
||||
# Output our current versions for debugging
|
||||
- node --version
|
||||
- npm --version
|
||||
|
||||
# Install our package dependencies
|
||||
- npm install
|
||||
|
||||
test_script:
|
||||
- npm run test:node
|
||||
|
||||
build: off
|
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
'use strict'
|
||||
|
||||
const Benchmark = require('benchmark')
|
||||
@@ -24,4 +25,4 @@ curves.forEach((curve) => {
|
||||
|
||||
suite
|
||||
.on('cycle', (event) => console.log(String(event.target)))
|
||||
.run({async: true})
|
||||
.run({ async: true })
|
||||
|
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
'use strict'
|
||||
|
||||
const Benchmark = require('benchmark')
|
||||
@@ -24,7 +25,7 @@ async.waterfall([
|
||||
|
||||
suite
|
||||
.on('cycle', (event) => console.log(String(event.target)))
|
||||
.run({async: true})
|
||||
.run({ async: true })
|
||||
})
|
||||
|
||||
function setup (cipher, hash, secret) {
|
||||
|
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-console */
|
||||
'use strict'
|
||||
|
||||
const Benchmark = require('benchmark')
|
||||
@@ -39,4 +40,4 @@ suite.add('sign and verify', (d) => {
|
||||
|
||||
suite
|
||||
.on('cycle', (event) => console.log(String(event.target)))
|
||||
.run({async: true})
|
||||
.run({ async: true })
|
||||
|
15
circle.yml
15
circle.yml
@@ -1,15 +0,0 @@
|
||||
# Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
|
||||
machine:
|
||||
node:
|
||||
version: stable
|
||||
|
||||
dependencies:
|
||||
pre:
|
||||
- google-chrome --version
|
||||
- curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
||||
- sudo dpkg -i google-chrome.deb || true
|
||||
- sudo apt-get update
|
||||
- sudo apt-get install -f
|
||||
- sudo apt-get install --only-upgrade lsb-base
|
||||
- sudo dpkg -i google-chrome.deb
|
||||
- google-chrome --version
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p-crypto",
|
||||
"version": "0.14.0",
|
||||
"version": "0.15.0",
|
||||
"description": "Crypto primitives for libp2p",
|
||||
"main": "src/index.js",
|
||||
"leadMaintainer": "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||
@@ -42,13 +42,13 @@
|
||||
"protons": "^1.0.1",
|
||||
"rsa-pem-to-jwk": "^1.1.3",
|
||||
"tweetnacl": "^1.0.0",
|
||||
"ursa-optional": "~0.9.8",
|
||||
"ursa-optional": "~0.9.9",
|
||||
"webcrypto-shim": "github:dignifiedquire/webcrypto-shim#master"
|
||||
},
|
||||
"devDependencies": {
|
||||
"aegir": "^15.2.0",
|
||||
"aegir": "^17.1.1",
|
||||
"benchmark": "^2.1.4",
|
||||
"chai": "^4.1.2",
|
||||
"chai": "^4.2.0",
|
||||
"chai-string": "^1.5.0",
|
||||
"dirty-chai": "^2.0.1"
|
||||
},
|
||||
@@ -70,6 +70,7 @@
|
||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||
"Greenkeeper <support@greenkeeper.io>",
|
||||
"Jack Kleeman <jackkleeman@gmail.com>",
|
||||
"Jacob Heun <jacobheun@gmail.com>",
|
||||
"Joao Santos <jrmsantos15@gmail.com>",
|
||||
"Maciej Krüger <mkg20001@gmail.com>",
|
||||
"Richard Littauer <richard.littauer@gmail.com>",
|
||||
|
@@ -1,10 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const asm = require('asmcrypto.js')
|
||||
const setImmediate = require('async/setImmediate')
|
||||
const nextTick = require('async/nextTick')
|
||||
|
||||
exports.create = function (key, iv, callback) {
|
||||
const done = (err, res) => setImmediate(() => callback(err, res))
|
||||
const done = (err, res) => nextTick(() => callback(err, res))
|
||||
|
||||
if (key.length !== 16 && key.length !== 32) {
|
||||
return done(new Error('Invalid key length'))
|
||||
@@ -21,7 +21,7 @@ exports.create = function (key, iv, callback) {
|
||||
|
||||
const res = {
|
||||
encrypt (data, cb) {
|
||||
const done = (err, res) => setImmediate(() => cb(err, res))
|
||||
const done = (err, res) => nextTick(() => cb(err, res))
|
||||
|
||||
let res
|
||||
try {
|
||||
@@ -36,7 +36,7 @@ exports.create = function (key, iv, callback) {
|
||||
},
|
||||
|
||||
decrypt (data, cb) {
|
||||
const done = (err, res) => setImmediate(() => cb(err, res))
|
||||
const done = (err, res) => nextTick(() => cb(err, res))
|
||||
|
||||
let res
|
||||
try {
|
||||
|
@@ -12,7 +12,7 @@ const hashTypes = {
|
||||
}
|
||||
|
||||
const sign = (key, data, cb) => {
|
||||
nodeify(crypto.subtle.sign({name: 'HMAC'}, key, data)
|
||||
nodeify(crypto.subtle.sign({ name: 'HMAC' }, key, data)
|
||||
.then((raw) => Buffer.from(raw)), cb)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ exports.create = function (hashType, secret, callback) {
|
||||
secret,
|
||||
{
|
||||
name: 'HMAC',
|
||||
hash: {name: hash}
|
||||
hash: { name: hash }
|
||||
},
|
||||
false,
|
||||
['sign']
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
const crypto = require('crypto')
|
||||
const lengths = require('./lengths')
|
||||
const nextTick = require('async/nextTick')
|
||||
|
||||
exports.create = function (hash, secret, callback) {
|
||||
const res = {
|
||||
@@ -10,7 +11,7 @@ exports.create = function (hash, secret, callback) {
|
||||
|
||||
hmac.update(data)
|
||||
|
||||
setImmediate(() => {
|
||||
nextTick(() => {
|
||||
cb(null, hmac.digest())
|
||||
})
|
||||
},
|
||||
|
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
const crypto = require('crypto')
|
||||
const setImmediate = require('async/setImmediate')
|
||||
const nextTick = require('async/nextTick')
|
||||
|
||||
const curves = {
|
||||
'P-256': 'prime256v1',
|
||||
@@ -16,7 +16,7 @@ exports.generateEphmeralKeyPair = function (curve, callback) {
|
||||
const ecdh = crypto.createECDH(curves[curve])
|
||||
ecdh.generateKeys()
|
||||
|
||||
setImmediate(() => callback(null, {
|
||||
nextTick(() => callback(null, {
|
||||
key: ecdh.getPublicKey(),
|
||||
genSharedKey (theirPub, forcePrivate, cb) {
|
||||
if (typeof forcePrivate === 'function') {
|
||||
@@ -35,7 +35,7 @@ exports.generateEphmeralKeyPair = function (curve, callback) {
|
||||
return cb(err)
|
||||
}
|
||||
|
||||
setImmediate(() => cb(null, secret))
|
||||
nextTick(() => cb(null, secret))
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
'use strict'
|
||||
|
||||
const nacl = require('tweetnacl')
|
||||
const setImmediate = require('async/setImmediate')
|
||||
const nextTick = require('async/nextTick')
|
||||
|
||||
exports.publicKeyLength = nacl.sign.publicKeyLength
|
||||
exports.privateKeyLength = nacl.sign.secretKeyLength
|
||||
|
||||
exports.generateKey = function (callback) {
|
||||
setImmediate(() => {
|
||||
nextTick(() => {
|
||||
let result
|
||||
try {
|
||||
result = nacl.sign.keyPair()
|
||||
@@ -20,7 +20,7 @@ exports.generateKey = function (callback) {
|
||||
|
||||
// seed should be a 32 byte uint8array
|
||||
exports.generateKeyFromSeed = function (seed, callback) {
|
||||
setImmediate(() => {
|
||||
nextTick(() => {
|
||||
let result
|
||||
try {
|
||||
result = nacl.sign.keyPair.fromSeed(seed)
|
||||
@@ -32,13 +32,13 @@ exports.generateKeyFromSeed = function (seed, callback) {
|
||||
}
|
||||
|
||||
exports.hashAndSign = function (key, msg, callback) {
|
||||
setImmediate(() => {
|
||||
nextTick(() => {
|
||||
callback(null, Buffer.from(nacl.sign.detached(msg, key)))
|
||||
})
|
||||
}
|
||||
|
||||
exports.hashAndVerify = function (key, sig, msg, callback) {
|
||||
setImmediate(() => {
|
||||
nextTick(() => {
|
||||
let result
|
||||
try {
|
||||
result = nacl.sign.detached.verify(msg, sig, key)
|
||||
|
@@ -12,7 +12,7 @@ exports.generateKey = function (bits, callback) {
|
||||
name: 'RSASSA-PKCS1-v1_5',
|
||||
modulusLength: bits,
|
||||
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
||||
hash: {name: 'SHA-256'}
|
||||
hash: { name: 'SHA-256' }
|
||||
},
|
||||
true,
|
||||
['sign', 'verify']
|
||||
@@ -31,7 +31,7 @@ exports.unmarshalPrivateKey = function (key, callback) {
|
||||
key,
|
||||
{
|
||||
name: 'RSASSA-PKCS1-v1_5',
|
||||
hash: {name: 'SHA-256'}
|
||||
hash: { name: 'SHA-256' }
|
||||
},
|
||||
true,
|
||||
['sign']
|
||||
@@ -59,13 +59,13 @@ exports.hashAndSign = function (key, msg, callback) {
|
||||
key,
|
||||
{
|
||||
name: 'RSASSA-PKCS1-v1_5',
|
||||
hash: {name: 'SHA-256'}
|
||||
hash: { name: 'SHA-256' }
|
||||
},
|
||||
false,
|
||||
['sign']
|
||||
).then((privateKey) => {
|
||||
return webcrypto.subtle.sign(
|
||||
{name: 'RSASSA-PKCS1-v1_5'},
|
||||
{ name: 'RSASSA-PKCS1-v1_5' },
|
||||
privateKey,
|
||||
Uint8Array.from(msg)
|
||||
)
|
||||
@@ -78,13 +78,13 @@ exports.hashAndVerify = function (key, sig, msg, callback) {
|
||||
key,
|
||||
{
|
||||
name: 'RSASSA-PKCS1-v1_5',
|
||||
hash: {name: 'SHA-256'}
|
||||
hash: { name: 'SHA-256' }
|
||||
},
|
||||
false,
|
||||
['verify']
|
||||
).then((publicKey) => {
|
||||
return webcrypto.subtle.verify(
|
||||
{name: 'RSASSA-PKCS1-v1_5'},
|
||||
{ name: 'RSASSA-PKCS1-v1_5' },
|
||||
publicKey,
|
||||
sig,
|
||||
msg
|
||||
@@ -109,7 +109,7 @@ function derivePublicFromPrivate (jwKey) {
|
||||
},
|
||||
{
|
||||
name: 'RSASSA-PKCS1-v1_5',
|
||||
hash: {name: 'SHA-256'}
|
||||
hash: { name: 'SHA-256' }
|
||||
},
|
||||
true,
|
||||
['verify']
|
||||
|
@@ -3,11 +3,11 @@
|
||||
const multihashing = require('multihashing-async')
|
||||
const protobuf = require('protons')
|
||||
const bs58 = require('bs58')
|
||||
const nextTick = require('async/nextTick')
|
||||
|
||||
const crypto = require('./rsa')
|
||||
const pbm = protobuf(require('./keys.proto'))
|
||||
const forge = require('node-forge')
|
||||
const setImmediate = require('async/setImmediate')
|
||||
|
||||
class RsaPublicKey {
|
||||
constructor (key) {
|
||||
@@ -129,7 +129,7 @@ class RsaPrivateKey {
|
||||
|
||||
ensure(callback)
|
||||
|
||||
setImmediate(() => {
|
||||
nextTick(() => {
|
||||
let err = null
|
||||
let pem = null
|
||||
try {
|
||||
|
@@ -1,6 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const crypto = require('crypto')
|
||||
const nextTick = require('async/nextTick')
|
||||
|
||||
let keypair
|
||||
try {
|
||||
if (process.env.LP2P_FORCE_CRYPTO_LIB === 'keypair') {
|
||||
@@ -8,7 +10,7 @@ try {
|
||||
}
|
||||
|
||||
const ursa = require('ursa-optional') // throws if not compiled
|
||||
keypair = ({bits}) => {
|
||||
keypair = ({ bits }) => {
|
||||
const key = ursa.generatePrivateKey(bits)
|
||||
return {
|
||||
private: key.toPrivatePem(),
|
||||
@@ -22,14 +24,13 @@ try {
|
||||
|
||||
keypair = require('keypair')
|
||||
}
|
||||
const setImmediate = require('async/setImmediate')
|
||||
const pemToJwk = require('pem-jwk').pem2jwk
|
||||
const jwkToPem = require('pem-jwk').jwk2pem
|
||||
|
||||
exports.utils = require('./rsa-utils')
|
||||
|
||||
exports.generateKey = function (bits, callback) {
|
||||
setImmediate(() => {
|
||||
nextTick(() => {
|
||||
let result
|
||||
try {
|
||||
const key = keypair({ bits: bits })
|
||||
@@ -47,7 +48,7 @@ exports.generateKey = function (bits, callback) {
|
||||
|
||||
// Takes a jwk key
|
||||
exports.unmarshalPrivateKey = function (key, callback) {
|
||||
setImmediate(() => {
|
||||
nextTick(() => {
|
||||
if (!key) {
|
||||
return callback(new Error('Key is invalid'))
|
||||
}
|
||||
@@ -67,7 +68,7 @@ exports.getRandomValues = function (arr) {
|
||||
}
|
||||
|
||||
exports.hashAndSign = function (key, msg, callback) {
|
||||
setImmediate(() => {
|
||||
nextTick(() => {
|
||||
let result
|
||||
try {
|
||||
const sign = crypto.createSign('RSA-SHA256')
|
||||
@@ -83,7 +84,7 @@ exports.hashAndSign = function (key, msg, callback) {
|
||||
}
|
||||
|
||||
exports.hashAndVerify = function (key, sig, msg, callback) {
|
||||
setImmediate(() => {
|
||||
nextTick(() => {
|
||||
let result
|
||||
try {
|
||||
const verify = crypto.createVerify('RSA-SHA256')
|
||||
|
Reference in New Issue
Block a user