This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add buffer, cleanup, reduce size (#170)
* fix: add buffer, cleanup, reduce size - add buffer related to ipfs/js-ipfs#2924 - remove unnecessary eslint ignore - remove tweelnacl and use node-forge - remove browserify-aes and use node-forge - use multibase to encode b58 - require only sha256 from multihashing - reduce bundle size after all the deps here ipfs/js-ipfs#2924 are merged libp2p-crypto will be able to be bundle with `node: false` 🎉 * fix: reduce bundle size * fix: use new secp * fix: bundle size * chore: update secp Co-Authored-By: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Jacob Heun <jacobheun@gmail.com>
- Loading branch information
1 parent
d3601fa
commit c956d1a
Showing
23 changed files
with
69 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
bundlesize: { maxSize: '155kB' } | ||
bundlesize: { maxSize: '124kB' } | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
'use strict' | ||
|
||
const crypto = require('browserify-aes') | ||
const { Buffer } = require('buffer') | ||
require('node-forge/lib/aes') | ||
const forge = require('node-forge/lib/forge') | ||
|
||
module.exports = { | ||
createCipheriv: crypto.createCipheriv, | ||
createDecipheriv: crypto.createDecipheriv | ||
createCipheriv: (mode, key, iv) => { | ||
const cipher2 = forge.cipher.createCipher('AES-CTR', key.toString('binary')) | ||
cipher2.start({ iv: iv.toString('binary') }) | ||
return { | ||
update: (data) => { | ||
cipher2.update(forge.util.createBuffer(data.toString('binary'))) | ||
return Buffer.from(cipher2.output.getBytes(), 'binary') | ||
} | ||
} | ||
}, | ||
createDecipheriv: (mode, key, iv) => { | ||
const cipher2 = forge.cipher.createDecipher('AES-CTR', key.toString('binary')) | ||
cipher2.start({ iv: iv.toString('binary') }) | ||
return { | ||
update: (data) => { | ||
cipher2.update(forge.util.createBuffer(data.toString('binary'))) | ||
return Buffer.from(cipher2.output.getBytes(), 'binary') | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
'use strict' | ||
|
||
const nacl = require('tweetnacl') | ||
|
||
exports.publicKeyLength = nacl.sign.publicKeyLength | ||
exports.privateKeyLength = nacl.sign.secretKeyLength | ||
require('node-forge/lib/ed25519') | ||
const forge = require('node-forge/lib/forge') | ||
exports.publicKeyLength = forge.pki.ed25519.constants.PUBLIC_KEY_BYTE_LENGTH | ||
exports.privateKeyLength = forge.pki.ed25519.constants.PRIVATE_KEY_BYTE_LENGTH | ||
|
||
exports.generateKey = async function () { // eslint-disable-line require-await | ||
return nacl.sign.keyPair() | ||
return forge.pki.ed25519.generateKeyPair() | ||
} | ||
|
||
// seed should be a 32 byte uint8array | ||
exports.generateKeyFromSeed = async function (seed) { // eslint-disable-line require-await | ||
return nacl.sign.keyPair.fromSeed(seed) | ||
return forge.pki.ed25519.generateKeyPair({ seed }) | ||
} | ||
|
||
exports.hashAndSign = async function (key, msg) { // eslint-disable-line require-await | ||
return Buffer.from(nacl.sign.detached(msg, key)) | ||
return forge.pki.ed25519.sign({ message: msg, privateKey: key }) | ||
// return Buffer.from(nacl.sign.detached(msg, key)) | ||
} | ||
|
||
exports.hashAndVerify = async function (key, sig, msg) { // eslint-disable-line require-await | ||
return nacl.sign.detached.verify(msg, sig, key) | ||
return forge.pki.ed25519.verify({ signature: sig, message: msg, publicKey: key }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
'use strict' | ||
const { Buffer } = require('buffer') | ||
|
||
module.exports = { | ||
curve: 'P-256', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use strict' | ||
|
||
const { Buffer } = require('buffer') | ||
module.exports = [{ | ||
cipher: 'AES-256', | ||
hash: 'SHA256', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters