Compare commits

...

15 Commits

Author SHA1 Message Date
dignifiedquire
967594c9a3 chore: release version v0.16.2 2019-09-25 11:50:14 +02:00
dignifiedquire
03893a3795 chore: update contributors 2019-09-25 11:50:14 +02:00
dignifiedquire
50afa4efbc chore(deps): update ursa-optional 2019-09-25 11:44:47 +02:00
Friedel Ziegelmayer
1c54a9b196 Merge pull request #158 from libp2p/v0.16.x-upgrade-node-forge
V0.16.x upgrade node forge
2019-09-25 11:39:07 +02:00
achingbrain
6f2c347895 chore: update aegir so tests run on browsers agin 2019-09-23 10:36:22 +01:00
achingbrain
867982ab92 chore: upgrade node-forge dep 2019-09-23 10:31:35 +01:00
dignifiedquire
7b3625888c chore: release version v0.16.1 2019-02-26 09:28:41 +01:00
dignifiedquire
b7bce77ad5 chore: update contributors 2019-02-26 09:28:41 +01:00
Yusef Napora
c1f867bd9c chore: update badges for consistency across libp2p org 2019-02-26 09:25:15 +01:00
Alberto Elias
e3f02eb6f1 chore: updates libp2p-crypto-secp256k1 2019-02-26 09:24:40 +01:00
Vasco Santos
a0874389a9 chore(ci): use travis
This PR changes Jenkins to travis for CI. In addition, 2 dependencies were missing in the `package.json` and the `dep-check` was not passing.
2019-02-20 20:57:36 +01:00
David Dias
567d68c855 chore: release version v0.16.0 2019-01-08 21:33:49 +01:00
David Dias
af782c5906 chore: update contributors 2019-01-08 21:33:49 +01:00
David Dias
f0593c9e6d chore: update deps 2019-01-08 21:33:02 +01:00
Hugo Dias
8d8294dc3f fix: clean up, bundle size reduction
BREAKING CHANGE: getRandomValues method exported from src/keys/rsa-browser.js and src/keys/rsa.js signature has changed from accepting an array to a number for random byte length
2019-01-08 21:29:42 +01:00
19 changed files with 126 additions and 94 deletions

View File

@@ -1,34 +0,0 @@
**/node_modules/
**/*.log
test/repo-tests*
# Logs
logs
*.log
coverage
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
build
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
test

44
.travis.yml Normal file
View File

@@ -0,0 +1,44 @@
language: node_js
cache: npm
stages:
- check
- test
- cov
node_js:
- '10'
os:
- linux
- osx
- windows
script: npx nyc -s npm run test:node -- --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov
jobs:
include:
- stage: check
script:
- npx aegir commitlint --travis
- npx aegir dep-check
- npm run lint
- stage: test
name: chrome
addons:
chrome: stable
script:
- npx aegir test -t browser
- stage: test
name: firefox
addons:
firefox: latest
script:
- npx aegir test -t browser -- --browsers FirefoxHeadless
notifications:
email: false

View File

@@ -1,3 +1,28 @@
<a name="0.16.2"></a>
## [0.16.2](https://github.com/libp2p/js-libp2p-crypto/compare/v0.16.1...v0.16.2) (2019-09-25)
<a name="0.16.1"></a>
## [0.16.1](https://github.com/libp2p/js-libp2p-crypto/compare/v0.16.0...v0.16.1) (2019-02-26)
<a name="0.16.0"></a>
# [0.16.0](https://github.com/libp2p/js-libp2p-crypto/compare/v0.15.0...v0.16.0) (2019-01-08)
### Bug Fixes
* clean up, bundle size reduction ([8d8294d](https://github.com/libp2p/js-libp2p-crypto/commit/8d8294d))
### BREAKING CHANGES
* getRandomValues method exported from src/keys/rsa-browser.js and src/keys/rsa.js signature has changed from accepting an array to a number for random byte length
<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)

View File

@@ -1,9 +1,8 @@
# js-libp2p-crypto
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-crypto/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-crypto?branch=master)
[![Travis CI](https://travis-ci.org/libp2p/js-libp2p-crypto.svg?branch=master)](https://travis-ci.org/libp2p/js-libp2p-crypto)
[![Circle CI](https://circleci.com/gh/libp2p/js-libp2p-crypto.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-crypto)
@@ -62,7 +61,7 @@ This uses `CTR` mode.
- `key: Buffer` The key, if length `16` then `AES 128` is used. For length `32`, `AES 256` is used.
- `iv: Buffer` Must have length `16`.
- `callback: Function`
- `callback: Function`
##### `decrypt(data, callback)`
@@ -109,7 +108,7 @@ async function main () {
if (!err) {
console.log(decryptedBuffer)
// prints: <Buffer 42 f1 67 d9 2e 42 d0 32 9e b1 f8 3c>
console.log(decryptedBuffer.toString('utf-8'))
// prints: Hello, world!
}

2
ci/Jenkinsfile vendored
View File

@@ -1,2 +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.
javascript()

View File

@@ -1,6 +1,6 @@
{
"name": "libp2p-crypto",
"version": "0.15.0",
"version": "0.16.2",
"description": "Crypto primitives for libp2p",
"main": "src/index.js",
"leadMaintainer": "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
@@ -10,6 +10,10 @@
"./src/aes/ciphers.js": "./src/aes/ciphers-browser.js",
"./src/keys/rsa.js": "./src/keys/rsa-browser.js"
},
"files": [
"src",
"dist"
],
"scripts": {
"lint": "aegir lint",
"build": "aegir build",
@@ -20,7 +24,8 @@
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"coverage": "aegir coverage --ignore src/keys/keys.proto.js"
"coverage": "aegir coverage --ignore src/keys/keys.proto.js",
"size": "bundlesize -f dist/index.min.js -s 139kB"
},
"keywords": [
"IPFS",
@@ -30,31 +35,34 @@
],
"license": "MIT",
"dependencies": {
"asmcrypto.js": "^2.3.2",
"asn1.js": "^5.0.1",
"async": "^2.6.1",
"bn.js": "^4.11.8",
"browserify-aes": "^1.2.0",
"bs58": "^4.0.1",
"iso-random-stream": "^1.1.0",
"keypair": "^1.0.1",
"libp2p-crypto-secp256k1": "~0.2.2",
"libp2p-crypto-secp256k1": "~0.3.0",
"multihashing-async": "~0.5.1",
"node-forge": "~0.7.6",
"pem-jwk": "^1.5.1",
"node-forge": "^0.8.5",
"pem-jwk": "^2.0.0",
"protons": "^1.0.1",
"rsa-pem-to-jwk": "^1.1.3",
"tweetnacl": "^1.0.0",
"ursa-optional": "~0.9.9",
"webcrypto-shim": "github:dignifiedquire/webcrypto-shim#master"
"ursa-optional": "~0.10.0"
},
"devDependencies": {
"aegir": "^17.1.1",
"aegir": "^20.0.0",
"benchmark": "^2.1.4",
"bundlesize": "^0.18.0",
"chai": "^4.2.0",
"chai-string": "^1.5.0",
"dirty-chai": "^2.0.1"
},
"engines": {
"node": ">=6.0.0",
"npm": ">=3.0.0"
"node": ">=10.0.0",
"npm": ">=6.0.0"
},
"repository": {
"type": "git",
@@ -65,10 +73,12 @@
},
"homepage": "https://github.com/libp2p/js-libp2p-crypto",
"contributors": [
"Alberto Elias <hi@albertoelias.me>",
"David Dias <daviddias.p@gmail.com>",
"Dmitriy Ryajov <dryajov@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Greenkeeper <support@greenkeeper.io>",
"Hugo Dias <hugomrdias@gmail.com>",
"Jack Kleeman <jackkleeman@gmail.com>",
"Jacob Heun <jacobheun@gmail.com>",
"Joao Santos <jrmsantos15@gmail.com>",
@@ -76,8 +86,11 @@
"Richard Littauer <richard.littauer@gmail.com>",
"Richard Schneider <makaretu@gmail.com>",
"Tom Swindell <t.swindell@rubyx.co.uk>",
"Vasco Santos <vasco.santos@ua.pt>",
"Victor Bjelkholm <victorbjelkholm@gmail.com>",
"Yusef Napora <yusef@napora.org>",
"achingbrain <alex@achingbrain.net>",
"dignifiedquire <dignifiedquire@users.noreply.github.com>",
"greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com>",
"nikuda <nikuda@gmail.com>"
]

View File

@@ -2,7 +2,7 @@
const nodeify = require('../nodeify')
const crypto = require('../webcrypto.js')()
const crypto = require('../webcrypto')
const lengths = require('./lengths')
const hashTypes = {

View File

@@ -1,6 +1,6 @@
'use strict'
const webcrypto = require('../webcrypto.js')()
const webcrypto = require('../webcrypto')
const nodeify = require('../nodeify')
const BN = require('asn1.js').bignum

View File

@@ -2,7 +2,10 @@
const protobuf = require('protons')
const keysPBM = protobuf(require('./keys.proto'))
const forge = require('node-forge')
require('node-forge/lib/asn1')
require('node-forge/lib/rsa')
require('node-forge/lib/pbe')
const forge = require('node-forge/lib/forge')
exports = module.exports
@@ -25,7 +28,7 @@ exports.generateEphemeralKeyPair = require('./ephemeral-keys')
// Generates a keypair of the given type and bitsize
exports.generateKeyPair = (type, bits, cb) => {
let key = supportedKeys[type.toLowerCase()]
const key = supportedKeys[type.toLowerCase()]
if (!key) {
return cb(new Error('invalid or unsupported key type'))
@@ -37,7 +40,7 @@ exports.generateKeyPair = (type, bits, cb) => {
// Generates a keypair of the given type and bitsize
// seed is a 32 byte uint8array
exports.generateKeyPairFromSeed = (type, seed, bits, cb) => {
let key = supportedKeys[type.toLowerCase()]
const key = supportedKeys[type.toLowerCase()]
if (!key) {
return cb(new Error('invalid or unsupported key type'))
}

View File

@@ -47,7 +47,7 @@ module.exports = (cipherType, hash, secret, callback) => {
return callback(err)
}
let result = []
const result = []
let j = 0
whilst(

View File

@@ -1,8 +1,8 @@
'use strict'
const nodeify = require('../nodeify')
const webcrypto = require('../webcrypto.js')()
const webcrypto = require('../webcrypto')
const randomBytes = require('../random-bytes')
exports.utils = require('./rsa-utils')
@@ -49,9 +49,7 @@ exports.unmarshalPrivateKey = function (key, callback) {
})), callback)
}
exports.getRandomValues = function (arr) {
return Buffer.from(webcrypto.getRandomValues(arr))
}
exports.getRandomValues = randomBytes
exports.hashAndSign = function (key, msg, callback) {
nodeify(webcrypto.subtle.importKey(

View File

@@ -7,7 +7,9 @@ const nextTick = require('async/nextTick')
const crypto = require('./rsa')
const pbm = protobuf(require('./keys.proto'))
const forge = require('node-forge')
require('node-forge/lib/sha512')
require('node-forge/lib/pbe')
const forge = require('node-forge/lib/forge')
class RsaPublicKey {
constructor (key) {
@@ -53,7 +55,7 @@ class RsaPrivateKey {
}
genSecret () {
return crypto.getRandomValues(new Uint8Array(16))
return crypto.getRandomValues(16)
}
sign (message, callback) {
@@ -136,7 +138,6 @@ class RsaPrivateKey {
const buffer = new forge.util.ByteBuffer(this.marshal())
const asn1 = forge.asn1.fromDer(buffer)
const privateKey = forge.pki.privateKeyFromAsn1(asn1)
if (format === 'pkcs-8') {
const options = {
algorithm: 'aes256',

View File

@@ -1,6 +1,7 @@
'use strict'
const crypto = require('crypto')
const randomBytes = require('../random-bytes')
const nextTick = require('async/nextTick')
let keypair
@@ -63,9 +64,7 @@ exports.unmarshalPrivateKey = function (key, callback) {
})
}
exports.getRandomValues = function (arr) {
return crypto.randomBytes(arr.length)
}
exports.getRandomValues = randomBytes
exports.hashAndSign = function (key, msg, callback) {
nextTick(() => {

View File

@@ -1,6 +1,7 @@
'use strict'
const forge = require('node-forge')
const forgePbkdf2 = require('node-forge/lib/pbkdf2')
const forgeUtil = require('node-forge/lib/util')
/**
* Maps an IPFS hash name to its node-forge equivalent.
@@ -30,13 +31,13 @@ function pbkdf2 (password, salt, iterations, keySize, hash) {
if (!hasher) {
throw new Error(`Hash '${hash}' is unknown or not supported`)
}
const dek = forge.pkcs5.pbkdf2(
const dek = forgePbkdf2(
password,
salt,
iterations,
keySize,
hasher)
return forge.util.encode64(dek)
return forgeUtil.encode64(dek)
}
module.exports = pbkdf2

View File

@@ -1,13 +1,9 @@
'use strict'
const randomBytes = require('iso-random-stream/src/random')
const rsa = require('./keys/rsa')
function randomBytes (number) {
module.exports = function (number) {
if (!number || typeof number !== 'number') {
throw new Error('first argument must be a Number bigger than 0')
}
return rsa.getRandomValues(new Uint8Array(number))
return randomBytes(number)
}
module.exports = randomBytes

View File

@@ -6,7 +6,7 @@ const BN = require('asn1.js').bignum
// Adapted from https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-41#appendix-C
exports.toBase64 = function toBase64 (bn, len) {
// if len is defined then the bytes are leading-0 padded to the length
let s = bn.toArrayLike(Buffer, 'be', len).toString('base64')
const s = bn.toArrayLike(Buffer, 'be', len).toString('base64')
return s
.replace(/(=*)$/, '') // Remove any trailing '='s

View File

@@ -2,15 +2,4 @@
'use strict'
module.exports = () => {
// This is only a shim for interfaces, not for functionality
if (typeof self !== 'undefined') {
require('webcrypto-shim')(self)
if (self.crypto) {
return self.crypto
}
}
throw new Error('Please use an environment with crypto support')
}
module.exports = self.crypto || self.msCrypto

View File

@@ -19,7 +19,7 @@ function doTests (fncName, fnc, num, skipBuffersAndStrings) {
// skip this garbage because it's a buffer or a string and we were told do do that
return
}
let args = []
const args = []
for (let i = 0; i < num; i++) {
args.push(garbage)
}

View File

@@ -24,7 +24,7 @@ describe('Util', () => {
})
it('toBase64 zero padding', (done) => {
let bnpad = new BN('ff', 16)
const bnpad = new BN('ff', 16)
expect(util.toBase64(bnpad, 2)).to.eql('AP8')
done()
})