Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
chore: update deps (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored Apr 11, 2021
1 parent a05e870 commit 867b511
Show file tree
Hide file tree
Showing 16 changed files with 463 additions and 76 deletions.
3 changes: 0 additions & 3 deletions .aegir.js

This file was deleted.

12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
language: node_js

cache: npm

branches:
only:
- master
- /^release\/.*$/

stages:
- check
- test
- cov

node_js:
- '10'
- '12'
- 'lts/*'
- 'node'

os:
- linux
Expand All @@ -23,7 +27,7 @@ jobs:
include:
- stage: check
script:
- npx aegir build --bundlesize
- npx aegir build --no-types
- npx aegir dep-check
- npm run lint

Expand Down
31 changes: 18 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
],
"scripts": {
"lint": "aegir lint",
"build": "aegir build",
"build-proto": "pbjs --wrap commonjs --target static-module src/keys/keys.proto > src/keys/keys.proto.js",
"build": "npm run build:proto && aegir build --no-types",
"build:proto": "pbjs -t static-module -w commonjs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/keys/keys.js ./src/keys/keys.proto",
"test": "aegir test",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser -t webworker",
Expand All @@ -39,36 +39,41 @@
],
"license": "MIT",
"dependencies": {
"err-code": "^2.0.0",
"err-code": "^3.0.1",
"is-typedarray": "^1.0.0",
"iso-random-stream": "^1.1.0",
"iso-random-stream": "^2.0.0",
"keypair": "^1.0.1",
"multibase": "^3.0.0",
"multicodec": "^2.0.0",
"multibase": "^4.0.3",
"multicodec": "^3.0.1",
"multihashes": "^4.0.2",
"multihashing-async": "^2.0.1",
"multihashing-async": "^2.1.2",
"node-forge": "^0.10.0",
"pem-jwk": "^2.0.0",
"protons": "^2.0.0",
"protobufjs": "^6.10.2",
"secp256k1": "^4.0.0",
"uint8arrays": "^1.1.0",
"uint8arrays": "^2.1.4",
"ursa-optional": "^0.10.1"
},
"devDependencies": {
"@types/chai": "^4.2.12",
"@types/chai-string": "^1.4.2",
"@types/dirty-chai": "^2.0.2",
"@types/mocha": "^8.0.1",
"aegir": "^25.0.0",
"aegir": "^33.0.0",
"benchmark": "^2.1.4",
"chai": "^4.2.0",
"chai-string": "^1.5.0",
"dirty-chai": "^2.0.1",
"sinon": "^9.0.0"
"sinon": "^10.0.0",
"util": "^0.12.3"
},
"aegir": {
"build": {
"bundlesizeMax": "118kB"
}
},
"engines": {
"node": ">=10.0.0",
"npm": ">=6.0.0"
"node": ">=12.0.0"
},
"repository": {
"type": "git",
Expand Down
16 changes: 8 additions & 8 deletions src/ciphers/aes-gcm.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const webcrypto = require('../webcrypto')
*
* @param {object} [options]
* @param {string} [options.algorithm=AES-GCM]
* @param {Number} [options.nonceLength=12]
* @param {Number} [options.keyLength=16]
* @param {number} [options.nonceLength=12]
* @param {number} [options.keyLength=16]
* @param {string} [options.digest=sha256]
* @param {Number} [options.saltLength=16]
* @param {Number} [options.iterations=32767]
* @param {number} [options.saltLength=16]
* @param {number} [options.iterations=32767]
* @returns {*}
*/
function create ({
Expand All @@ -33,8 +33,8 @@ function create ({
* Uses the provided password to derive a pbkdf2 key. The key
* will then be used to encrypt the data.
*
* @param {Uint8Array} data The data to decrypt
* @param {string} password A plain password
* @param {Uint8Array} data - The data to decrypt
* @param {string} password - A plain password
* @returns {Promise<Uint8Array>}
*/
async function encrypt (data, password) { // eslint-disable-line require-await
Expand All @@ -58,8 +58,8 @@ function create ({
* this decryption cipher must be the same as those used to create
* the encryption cipher.
*
* @param {Uint8Array} data The data to decrypt
* @param {string} password A plain password
* @param {Uint8Array} data - The data to decrypt
* @param {string} password - A plain password
* @returns {Promise<Uint8Array>}
*/
async function decrypt (data, password) {
Expand Down
20 changes: 10 additions & 10 deletions src/ciphers/aes-gcm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
/**
*
* @param {object} [options]
* @param {Number} [options.algorithmTagLength=16]
* @param {Number} [options.nonceLength=12]
* @param {Number} [options.keyLength=16]
* @param {number} [options.algorithmTagLength=16]
* @param {number} [options.nonceLength=12]
* @param {number} [options.keyLength=16]
* @param {string} [options.digest=sha256]
* @param {Number} [options.saltLength=16]
* @param {Number} [options.iterations=32767]
* @param {number} [options.saltLength=16]
* @param {number} [options.iterations=32767]
* @returns {*}
*/
function create ({
Expand Down Expand Up @@ -49,8 +49,8 @@ function create ({
* Uses the provided password to derive a pbkdf2 key. The key
* will then be used to encrypt the data.
*
* @param {Uint8Array} data The data to decrypt
* @param {string|Uint8Array} password A plain password
* @param {Uint8Array} data - The data to decrypt
* @param {string|Uint8Array} password - A plain password
* @returns {Promise<Uint8Array>}
*/
async function encrypt (data, password) { // eslint-disable-line require-await
Expand All @@ -76,7 +76,7 @@ function create ({
* the encryption cipher.
*
* @private
* @param {Uint8Array} ciphertextAndNonce The data to decrypt
* @param {Uint8Array} ciphertextAndNonce - The data to decrypt
* @param {Uint8Array} key
* @returns {Promise<Uint8Array>}
*/
Expand All @@ -100,8 +100,8 @@ function create ({
* this decryption cipher must be the same as those used to create
* the encryption cipher.
*
* @param {Uint8Array} data The data to decrypt
* @param {string|Uint8Array} password A plain password
* @param {Uint8Array} data - The data to decrypt
* @param {string|Uint8Array} password - A plain password
*/
async function decrypt (data, password) { // eslint-disable-line require-await
// Create Uint8Arrays of salt and ciphertextAndNonce.
Expand Down
9 changes: 4 additions & 5 deletions src/keys/ed25519-class.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use strict'

const sha = require('multihashing-async/src/sha')
const protobuf = require('protons')
const errcode = require('err-code')
const uint8ArrayEquals = require('uint8arrays/equals')
const mh = require('multihashes')
const crypto = require('./ed25519')
const pbm = protobuf(require('./keys.proto'))
const pbm = require('./keys')
const exporter = require('./exporter')

class Ed25519PublicKey {
Expand All @@ -26,7 +25,7 @@ class Ed25519PublicKey {
return pbm.PublicKey.encode({
Type: pbm.KeyType.Ed25519,
Data: this.marshal()
})
}).finish()
}

equals (key) {
Expand Down Expand Up @@ -62,7 +61,7 @@ class Ed25519PrivateKey {
return pbm.PrivateKey.encode({
Type: pbm.KeyType.Ed25519,
Data: this.marshal()
})
}).finish()
}

equals (key) {
Expand All @@ -80,7 +79,7 @@ class Ed25519PrivateKey {
* The public key is a protobuf encoding containing a type and the DER encoding
* of the PKCS SubjectPublicKeyInfo.
*
* @returns {Promise<String>}
* @returns {Promise<string>}
*/
async id () {
const encoding = mh.encode(this.public.bytes, 'identity')
Expand Down
2 changes: 1 addition & 1 deletion src/keys/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
* The PrivateKey is encrypted via a password derived PBKDF2 key
* leveraging the aes-gcm cipher algorithm.
*
* @param {Uint8Array} privateKey The PrivateKey protobuf
* @param {Uint8Array} privateKey - The PrivateKey protobuf
* @param {string} password
* @returns {Promise<string>} A base64 encoded string
*/
Expand Down
2 changes: 1 addition & 1 deletion src/keys/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
* with the given password. The privateKey must have been exported
* using the same password and underlying cipher (aes-gcm)
*
* @param {string} privateKey A base64 encoded encrypted key
* @param {string} privateKey - A base64 encoded encrypted key
* @param {string} password
* @returns {Promise<Uint8Array>} The private key protobuf
*/
Expand Down
41 changes: 23 additions & 18 deletions src/keys/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const protobuf = require('protons')
const keysPBM = protobuf(require('./keys.proto'))
const keysPBM = require('./keys')
require('node-forge/lib/asn1')
require('node-forge/lib/pbe')
const forge = require('node-forge/lib/forge')
Expand All @@ -10,17 +9,12 @@ const uint8ArrayFromString = require('uint8arrays/from-string')

const importer = require('./importer')

exports = module.exports

const supportedKeys = {
rsa: require('./rsa-class'),
ed25519: require('./ed25519-class'),
secp256k1: require('./secp256k1-class')(keysPBM, require('../random-bytes'))
}

exports.supportedKeys = supportedKeys
exports.keysPBM = keysPBM

const ErrMissingSecp256K1 = {
message: 'secp256k1 support requires libp2p-crypto-secp256k1 package',
code: 'ERR_MISSING_PACKAGE'
Expand All @@ -35,17 +29,14 @@ function typeToKey (type) {
return key
}

exports.keyStretcher = require('./key-stretcher')
exports.generateEphemeralKeyPair = require('./ephemeral-keys')

// Generates a keypair of the given type and bitsize
exports.generateKeyPair = async (type, bits) => { // eslint-disable-line require-await
const generateKeyPair = async (type, bits) => { // eslint-disable-line require-await
return typeToKey(type).generateKeyPair(bits)
}

// Generates a keypair of the given type and bitsize
// seed is a 32 byte uint8array
exports.generateKeyPairFromSeed = async (type, seed, bits) => { // eslint-disable-line require-await
const generateKeyPairFromSeed = async (type, seed, bits) => { // eslint-disable-line require-await
const key = typeToKey(type)
if (type.toLowerCase() !== 'ed25519') {
throw errcode(new Error('Seed key derivation is unimplemented for RSA or secp256k1'), 'ERR_UNSUPPORTED_KEY_DERIVATION_TYPE')
Expand All @@ -55,7 +46,7 @@ exports.generateKeyPairFromSeed = async (type, seed, bits) => { // eslint-disabl

// Converts a protobuf serialized public key into its
// representative object
exports.unmarshalPublicKey = (buf) => {
const unmarshalPublicKey = (buf) => {
const decoded = keysPBM.PublicKey.decode(buf)
const data = decoded.Data

Expand All @@ -76,15 +67,15 @@ exports.unmarshalPublicKey = (buf) => {
}

// Converts a public key object into a protobuf serialized public key
exports.marshalPublicKey = (key, type) => {
const marshalPublicKey = (key, type) => {
type = (type || 'rsa').toLowerCase()
typeToKey(type) // check type
return key.bytes
}

// Converts a protobuf serialized private key into its
// representative object
exports.unmarshalPrivateKey = async (buf) => { // eslint-disable-line require-await
const unmarshalPrivateKey = async (buf) => { // eslint-disable-line require-await
const decoded = keysPBM.PrivateKey.decode(buf)
const data = decoded.Data

Expand All @@ -105,7 +96,7 @@ exports.unmarshalPrivateKey = async (buf) => { // eslint-disable-line require-aw
}

// Converts a private key object into a protobuf serialized private key
exports.marshalPrivateKey = (key, type) => {
const marshalPrivateKey = (key, type) => {
type = (type || 'rsa').toLowerCase()
typeToKey(type) // check type
return key.bytes
Expand All @@ -116,10 +107,10 @@ exports.marshalPrivateKey = (key, type) => {
* @param {string} encryptedKey
* @param {string} password
*/
exports.import = async (encryptedKey, password) => { // eslint-disable-line require-await
const importKey = async (encryptedKey, password) => { // eslint-disable-line require-await
try {
const key = await importer.import(encryptedKey, password)
return exports.unmarshalPrivateKey(key)
return unmarshalPrivateKey(key)
} catch (_) {
// Ignore and try the old pem decrypt
}
Expand All @@ -133,3 +124,17 @@ exports.import = async (encryptedKey, password) => { // eslint-disable-line requ
der = uint8ArrayFromString(der.getBytes(), 'ascii')
return supportedKeys.rsa.unmarshalRsaPrivateKey(der)
}

module.exports = {
supportedKeys,
keysPBM,
keyStretcher: require('./key-stretcher'),
generateEphemeralKeyPair: require('./ephemeral-keys'),
generateKeyPair,
generateKeyPairFromSeed,
unmarshalPublicKey,
marshalPublicKey,
unmarshalPrivateKey,
marshalPrivateKey,
import: importKey
}
Loading

0 comments on commit 867b511

Please sign in to comment.