mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-06-25 09:11:41 +00:00
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
This commit is contained in:
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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',
|
||||
|
@ -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(() => {
|
||||
|
Reference in New Issue
Block a user