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

Commit 867b511

Browse files
authored
chore: update deps (#187)
1 parent a05e870 commit 867b511

16 files changed

+463
-76
lines changed

.aegir.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

.travis.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
language: node_js
2-
32
cache: npm
43

4+
branches:
5+
only:
6+
- master
7+
- /^release\/.*$/
8+
59
stages:
610
- check
711
- test
812
- cov
913

1014
node_js:
11-
- '10'
12-
- '12'
15+
- 'lts/*'
16+
- 'node'
1317

1418
os:
1519
- linux
@@ -23,7 +27,7 @@ jobs:
2327
include:
2428
- stage: check
2529
script:
26-
- npx aegir build --bundlesize
30+
- npx aegir build --no-types
2731
- npx aegir dep-check
2832
- npm run lint
2933

package.json

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
],
1919
"scripts": {
2020
"lint": "aegir lint",
21-
"build": "aegir build",
22-
"build-proto": "pbjs --wrap commonjs --target static-module src/keys/keys.proto > src/keys/keys.proto.js",
21+
"build": "npm run build:proto && aegir build --no-types",
22+
"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",
2323
"test": "aegir test",
2424
"test:node": "aegir test -t node",
2525
"test:browser": "aegir test -t browser -t webworker",
@@ -39,36 +39,41 @@
3939
],
4040
"license": "MIT",
4141
"dependencies": {
42-
"err-code": "^2.0.0",
42+
"err-code": "^3.0.1",
4343
"is-typedarray": "^1.0.0",
44-
"iso-random-stream": "^1.1.0",
44+
"iso-random-stream": "^2.0.0",
4545
"keypair": "^1.0.1",
46-
"multibase": "^3.0.0",
47-
"multicodec": "^2.0.0",
46+
"multibase": "^4.0.3",
47+
"multicodec": "^3.0.1",
4848
"multihashes": "^4.0.2",
49-
"multihashing-async": "^2.0.1",
49+
"multihashing-async": "^2.1.2",
5050
"node-forge": "^0.10.0",
5151
"pem-jwk": "^2.0.0",
52-
"protons": "^2.0.0",
52+
"protobufjs": "^6.10.2",
5353
"secp256k1": "^4.0.0",
54-
"uint8arrays": "^1.1.0",
54+
"uint8arrays": "^2.1.4",
5555
"ursa-optional": "^0.10.1"
5656
},
5757
"devDependencies": {
5858
"@types/chai": "^4.2.12",
5959
"@types/chai-string": "^1.4.2",
6060
"@types/dirty-chai": "^2.0.2",
6161
"@types/mocha": "^8.0.1",
62-
"aegir": "^25.0.0",
62+
"aegir": "^33.0.0",
6363
"benchmark": "^2.1.4",
6464
"chai": "^4.2.0",
6565
"chai-string": "^1.5.0",
6666
"dirty-chai": "^2.0.1",
67-
"sinon": "^9.0.0"
67+
"sinon": "^10.0.0",
68+
"util": "^0.12.3"
69+
},
70+
"aegir": {
71+
"build": {
72+
"bundlesizeMax": "118kB"
73+
}
6874
},
6975
"engines": {
70-
"node": ">=10.0.0",
71-
"npm": ">=6.0.0"
76+
"node": ">=12.0.0"
7277
},
7378
"repository": {
7479
"type": "git",

src/ciphers/aes-gcm.browser.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const webcrypto = require('../webcrypto')
1111
*
1212
* @param {object} [options]
1313
* @param {string} [options.algorithm=AES-GCM]
14-
* @param {Number} [options.nonceLength=12]
15-
* @param {Number} [options.keyLength=16]
14+
* @param {number} [options.nonceLength=12]
15+
* @param {number} [options.keyLength=16]
1616
* @param {string} [options.digest=sha256]
17-
* @param {Number} [options.saltLength=16]
18-
* @param {Number} [options.iterations=32767]
17+
* @param {number} [options.saltLength=16]
18+
* @param {number} [options.iterations=32767]
1919
* @returns {*}
2020
*/
2121
function create ({
@@ -33,8 +33,8 @@ function create ({
3333
* Uses the provided password to derive a pbkdf2 key. The key
3434
* will then be used to encrypt the data.
3535
*
36-
* @param {Uint8Array} data The data to decrypt
37-
* @param {string} password A plain password
36+
* @param {Uint8Array} data - The data to decrypt
37+
* @param {string} password - A plain password
3838
* @returns {Promise<Uint8Array>}
3939
*/
4040
async function encrypt (data, password) { // eslint-disable-line require-await
@@ -58,8 +58,8 @@ function create ({
5858
* this decryption cipher must be the same as those used to create
5959
* the encryption cipher.
6060
*
61-
* @param {Uint8Array} data The data to decrypt
62-
* @param {string} password A plain password
61+
* @param {Uint8Array} data - The data to decrypt
62+
* @param {string} password - A plain password
6363
* @returns {Promise<Uint8Array>}
6464
*/
6565
async function decrypt (data, password) {

src/ciphers/aes-gcm.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
99
/**
1010
*
1111
* @param {object} [options]
12-
* @param {Number} [options.algorithmTagLength=16]
13-
* @param {Number} [options.nonceLength=12]
14-
* @param {Number} [options.keyLength=16]
12+
* @param {number} [options.algorithmTagLength=16]
13+
* @param {number} [options.nonceLength=12]
14+
* @param {number} [options.keyLength=16]
1515
* @param {string} [options.digest=sha256]
16-
* @param {Number} [options.saltLength=16]
17-
* @param {Number} [options.iterations=32767]
16+
* @param {number} [options.saltLength=16]
17+
* @param {number} [options.iterations=32767]
1818
* @returns {*}
1919
*/
2020
function create ({
@@ -49,8 +49,8 @@ function create ({
4949
* Uses the provided password to derive a pbkdf2 key. The key
5050
* will then be used to encrypt the data.
5151
*
52-
* @param {Uint8Array} data The data to decrypt
53-
* @param {string|Uint8Array} password A plain password
52+
* @param {Uint8Array} data - The data to decrypt
53+
* @param {string|Uint8Array} password - A plain password
5454
* @returns {Promise<Uint8Array>}
5555
*/
5656
async function encrypt (data, password) { // eslint-disable-line require-await
@@ -76,7 +76,7 @@ function create ({
7676
* the encryption cipher.
7777
*
7878
* @private
79-
* @param {Uint8Array} ciphertextAndNonce The data to decrypt
79+
* @param {Uint8Array} ciphertextAndNonce - The data to decrypt
8080
* @param {Uint8Array} key
8181
* @returns {Promise<Uint8Array>}
8282
*/
@@ -100,8 +100,8 @@ function create ({
100100
* this decryption cipher must be the same as those used to create
101101
* the encryption cipher.
102102
*
103-
* @param {Uint8Array} data The data to decrypt
104-
* @param {string|Uint8Array} password A plain password
103+
* @param {Uint8Array} data - The data to decrypt
104+
* @param {string|Uint8Array} password - A plain password
105105
*/
106106
async function decrypt (data, password) { // eslint-disable-line require-await
107107
// Create Uint8Arrays of salt and ciphertextAndNonce.

src/keys/ed25519-class.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
'use strict'
22

33
const sha = require('multihashing-async/src/sha')
4-
const protobuf = require('protons')
54
const errcode = require('err-code')
65
const uint8ArrayEquals = require('uint8arrays/equals')
76
const mh = require('multihashes')
87
const crypto = require('./ed25519')
9-
const pbm = protobuf(require('./keys.proto'))
8+
const pbm = require('./keys')
109
const exporter = require('./exporter')
1110

1211
class Ed25519PublicKey {
@@ -26,7 +25,7 @@ class Ed25519PublicKey {
2625
return pbm.PublicKey.encode({
2726
Type: pbm.KeyType.Ed25519,
2827
Data: this.marshal()
29-
})
28+
}).finish()
3029
}
3130

3231
equals (key) {
@@ -62,7 +61,7 @@ class Ed25519PrivateKey {
6261
return pbm.PrivateKey.encode({
6362
Type: pbm.KeyType.Ed25519,
6463
Data: this.marshal()
65-
})
64+
}).finish()
6665
}
6766

6867
equals (key) {
@@ -80,7 +79,7 @@ class Ed25519PrivateKey {
8079
* The public key is a protobuf encoding containing a type and the DER encoding
8180
* of the PKCS SubjectPublicKeyInfo.
8281
*
83-
* @returns {Promise<String>}
82+
* @returns {Promise<string>}
8483
*/
8584
async id () {
8685
const encoding = mh.encode(this.public.bytes, 'identity')

src/keys/exporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
* The PrivateKey is encrypted via a password derived PBKDF2 key
1010
* leveraging the aes-gcm cipher algorithm.
1111
*
12-
* @param {Uint8Array} privateKey The PrivateKey protobuf
12+
* @param {Uint8Array} privateKey - The PrivateKey protobuf
1313
* @param {string} password
1414
* @returns {Promise<string>} A base64 encoded string
1515
*/

src/keys/importer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
* with the given password. The privateKey must have been exported
1010
* using the same password and underlying cipher (aes-gcm)
1111
*
12-
* @param {string} privateKey A base64 encoded encrypted key
12+
* @param {string} privateKey - A base64 encoded encrypted key
1313
* @param {string} password
1414
* @returns {Promise<Uint8Array>} The private key protobuf
1515
*/

src/keys/index.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

3-
const protobuf = require('protons')
4-
const keysPBM = protobuf(require('./keys.proto'))
3+
const keysPBM = require('./keys')
54
require('node-forge/lib/asn1')
65
require('node-forge/lib/pbe')
76
const forge = require('node-forge/lib/forge')
@@ -10,17 +9,12 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
109

1110
const importer = require('./importer')
1211

13-
exports = module.exports
14-
1512
const supportedKeys = {
1613
rsa: require('./rsa-class'),
1714
ed25519: require('./ed25519-class'),
1815
secp256k1: require('./secp256k1-class')(keysPBM, require('../random-bytes'))
1916
}
2017

21-
exports.supportedKeys = supportedKeys
22-
exports.keysPBM = keysPBM
23-
2418
const ErrMissingSecp256K1 = {
2519
message: 'secp256k1 support requires libp2p-crypto-secp256k1 package',
2620
code: 'ERR_MISSING_PACKAGE'
@@ -35,17 +29,14 @@ function typeToKey (type) {
3529
return key
3630
}
3731

38-
exports.keyStretcher = require('./key-stretcher')
39-
exports.generateEphemeralKeyPair = require('./ephemeral-keys')
40-
4132
// Generates a keypair of the given type and bitsize
42-
exports.generateKeyPair = async (type, bits) => { // eslint-disable-line require-await
33+
const generateKeyPair = async (type, bits) => { // eslint-disable-line require-await
4334
return typeToKey(type).generateKeyPair(bits)
4435
}
4536

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

5647
// Converts a protobuf serialized public key into its
5748
// representative object
58-
exports.unmarshalPublicKey = (buf) => {
49+
const unmarshalPublicKey = (buf) => {
5950
const decoded = keysPBM.PublicKey.decode(buf)
6051
const data = decoded.Data
6152

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

7869
// Converts a public key object into a protobuf serialized public key
79-
exports.marshalPublicKey = (key, type) => {
70+
const marshalPublicKey = (key, type) => {
8071
type = (type || 'rsa').toLowerCase()
8172
typeToKey(type) // check type
8273
return key.bytes
8374
}
8475

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

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

10798
// Converts a private key object into a protobuf serialized private key
108-
exports.marshalPrivateKey = (key, type) => {
99+
const marshalPrivateKey = (key, type) => {
109100
type = (type || 'rsa').toLowerCase()
110101
typeToKey(type) // check type
111102
return key.bytes
@@ -116,10 +107,10 @@ exports.marshalPrivateKey = (key, type) => {
116107
* @param {string} encryptedKey
117108
* @param {string} password
118109
*/
119-
exports.import = async (encryptedKey, password) => { // eslint-disable-line require-await
110+
const importKey = async (encryptedKey, password) => { // eslint-disable-line require-await
120111
try {
121112
const key = await importer.import(encryptedKey, password)
122-
return exports.unmarshalPrivateKey(key)
113+
return unmarshalPrivateKey(key)
123114
} catch (_) {
124115
// Ignore and try the old pem decrypt
125116
}
@@ -133,3 +124,17 @@ exports.import = async (encryptedKey, password) => { // eslint-disable-line requ
133124
der = uint8ArrayFromString(der.getBytes(), 'ascii')
134125
return supportedKeys.rsa.unmarshalRsaPrivateKey(der)
135126
}
127+
128+
module.exports = {
129+
supportedKeys,
130+
keysPBM,
131+
keyStretcher: require('./key-stretcher'),
132+
generateEphemeralKeyPair: require('./ephemeral-keys'),
133+
generateKeyPair,
134+
generateKeyPairFromSeed,
135+
unmarshalPublicKey,
136+
marshalPublicKey,
137+
unmarshalPrivateKey,
138+
marshalPrivateKey,
139+
import: importKey
140+
}

0 commit comments

Comments
 (0)