New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@libp2p/crypto

Package Overview
Dependencies
Maintainers
6
Versions
599
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/crypto - npm Package Compare versions

Comparing version 2.0.2-32212959 to 2.0.2-02b89323

8

package.json
{
"name": "@libp2p/crypto",
"version": "2.0.2-32212959",
"version": "2.0.2-02b89323",
"description": "Crypto primitives for libp2p",

@@ -88,3 +88,3 @@ "license": "Apache-2.0 OR MIT",

"dependencies": {
"@libp2p/interface": "0.1.1-32212959",
"@libp2p/interface": "0.1.1-02b89323",
"@noble/curves": "^1.1.0",

@@ -96,7 +96,7 @@ "@noble/hashes": "^1.3.1",

"uint8arraylist": "^2.4.3",
"uint8arrays": "^4.0.4"
"uint8arrays": "^4.0.6"
},
"devDependencies": {
"@types/mocha": "^10.0.0",
"aegir": "^40.0.1",
"aegir": "^40.0.8",
"benchmark": "^2.1.4",

@@ -103,0 +103,0 @@ "protons": "^7.0.2"

@@ -9,3 +9,3 @@ import { cipherMode } from './cipher-mode.js'

export async function create (key: Uint8Array, iv: Uint8Array): Promise<AESCipher> { // eslint-disable-line require-await
export async function create (key: Uint8Array, iv: Uint8Array): Promise<AESCipher> {
const mode = cipherMode(key)

@@ -16,7 +16,7 @@ const cipher = ciphers.createCipheriv(mode, key, iv)

const res: AESCipher = {
async encrypt (data) { // eslint-disable-line require-await
async encrypt (data) {
return cipher.update(data)
},
async decrypt (data) { // eslint-disable-line require-await
async decrypt (data) {
return decipher.update(data)

@@ -23,0 +23,0 @@ }

@@ -35,3 +35,3 @@ import { concat } from 'uint8arrays/concat'

*/
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> {
const salt = crypto.getRandomValues(new Uint8Array(saltLength))

@@ -38,0 +38,0 @@ const nonce = crypto.getRandomValues(new Uint8Array(nonceLength))

@@ -17,3 +17,3 @@ import crypto from 'crypto'

async function encryptWithKey (data: Uint8Array, key: Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
async function encryptWithKey (data: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
const nonce = crypto.randomBytes(nonceLength)

@@ -35,3 +35,3 @@

*/
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> {
// Generate a 128-bit salt using a CSPRNG.

@@ -58,3 +58,3 @@ const salt = crypto.randomBytes(saltLength)

*/
async function decryptWithKey (ciphertextAndNonce: Uint8Array, key: Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
async function decryptWithKey (ciphertextAndNonce: Uint8Array, key: Uint8Array): Promise<Uint8Array> {
// Create Uint8Arrays of nonce, ciphertext and tag.

@@ -83,3 +83,3 @@ const nonce = ciphertextAndNonce.subarray(0, nonceLength)

*/
async function decrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
async function decrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> {
// Create Uint8Arrays of salt and ciphertextAndNonce.

@@ -86,0 +86,0 @@ const salt = data.subarray(0, saltLength)

@@ -30,3 +30,3 @@ import webcrypto from '../webcrypto.js'

return {
async digest (data: Uint8Array) { // eslint-disable-line require-await
async digest (data: Uint8Array) {
return sign(key, data)

@@ -33,0 +33,0 @@ },

@@ -11,3 +11,3 @@ import crypto from 'crypto'

const res = {
async digest (data: Uint8Array) { // eslint-disable-line require-await
async digest (data: Uint8Array) {
const hmac = crypto.createHmac(hash.toLowerCase(), secret)

@@ -14,0 +14,0 @@ hmac.update(data)

@@ -14,3 +14,3 @@ import crypto from 'crypto'

export async function generateEphmeralKeyPair (curve: string): Promise<ECDHKey> { // eslint-disable-line require-await
export async function generateEphmeralKeyPair (curve: string): Promise<ECDHKey> {
if (curve !== 'P-256' && curve !== 'P-384' && curve !== 'P-521') {

@@ -26,3 +26,3 @@ throw new CodeError(`Unknown curve: ${curve}. Must be ${names}`, 'ERR_INVALID_CURVE')

async genSharedKey (theirPub: Uint8Array, forcePrivate?: ECDHKeyPair): Promise<Uint8Array> { // eslint-disable-line require-await
async genSharedKey (theirPub: Uint8Array, forcePrivate?: ECDHKeyPair): Promise<Uint8Array> {
if (forcePrivate != null) {

@@ -29,0 +29,0 @@ ecdh.setPrivateKey(forcePrivate.private)

@@ -18,3 +18,3 @@ import { CodeError } from '@libp2p/interface/errors'

async verify (data: Uint8Array, sig: Uint8Array): Promise<boolean> { // eslint-disable-line require-await
async verify (data: Uint8Array, sig: Uint8Array): Promise<boolean> {
return crypto.hashAndVerify(this._key, sig, data)

@@ -56,3 +56,3 @@ }

async sign (message: Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
async sign (message: Uint8Array): Promise<Uint8Array> {
return crypto.hashAndSign(this._key, message)

@@ -59,0 +59,0 @@ }

@@ -44,3 +44,3 @@ import 'node-forge/lib/asn1.js'

// Generates a keypair of the given type and bitsize
export async function generateKeyPair (type: KeyTypes, bits?: number): Promise<PrivateKey> { // eslint-disable-line require-await
export async function generateKeyPair (type: KeyTypes, bits?: number): Promise<PrivateKey> {
return typeToKey(type).generateKeyPair(bits ?? 2048)

@@ -51,3 +51,3 @@ }

// seed is a 32 byte uint8array
export async function generateKeyPairFromSeed (type: KeyTypes, seed: Uint8Array, bits?: number): Promise<PrivateKey> { // eslint-disable-line require-await
export async function generateKeyPairFromSeed (type: KeyTypes, seed: Uint8Array, bits?: number): Promise<PrivateKey> {
if (type.toLowerCase() !== 'ed25519') {

@@ -87,3 +87,3 @@ throw new CodeError('Seed key derivation is unimplemented for RSA or secp256k1', 'ERR_UNSUPPORTED_KEY_DERIVATION_TYPE')

// representative object
export async function unmarshalPrivateKey (buf: Uint8Array): Promise<PrivateKey> { // eslint-disable-line require-await
export async function unmarshalPrivateKey (buf: Uint8Array): Promise<PrivateKey> {
const decoded = keysPBM.PrivateKey.decode(buf)

@@ -116,3 +116,3 @@ const data = decoded.Data ?? new Uint8Array()

*/
export async function importKey (encryptedKey: string, password: string): Promise<PrivateKey> { // eslint-disable-line require-await
export async function importKey (encryptedKey: string, password: string): Promise<PrivateKey> {
try {

@@ -119,0 +119,0 @@ const key = await importer(encryptedKey, password)

@@ -22,3 +22,3 @@ import { CodeError } from '@libp2p/interface/errors'

async verify (data: Uint8Array, sig: Uint8Array): Promise<boolean> { // eslint-disable-line require-await
async verify (data: Uint8Array, sig: Uint8Array): Promise<boolean> {
return crypto.hashAndVerify(this._key, sig, data)

@@ -66,3 +66,3 @@ }

async sign (message: Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
async sign (message: Uint8Array): Promise<Uint8Array> {
return crypto.hashAndSign(this._key, message)

@@ -119,3 +119,3 @@ }

*/
async export (password: string, format = 'pkcs-8'): Promise<Multibase<'m'>> { // eslint-disable-line require-await
async export (password: string, format = 'pkcs-8'): Promise<Multibase<'m'>> {
if (format === 'pkcs-8') {

@@ -122,0 +122,0 @@ const buffer = new forge.util.ByteBuffer(this.marshal())

@@ -12,3 +12,3 @@ import crypto from 'crypto'

export async function generateKey (bits: number): Promise<JWKKeyPair> { // eslint-disable-line require-await
export async function generateKey (bits: number): Promise<JWKKeyPair> {
// @ts-expect-error node types are missing jwk as a format

@@ -30,3 +30,3 @@ const key = await keypair('rsa', {

// Takes a jwk key
export async function unmarshalPrivateKey (key: JsonWebKey): Promise<JWKKeyPair> { // eslint-disable-line require-await
export async function unmarshalPrivateKey (key: JsonWebKey): Promise<JWKKeyPair> {
if (key == null) {

@@ -54,3 +54,3 @@ throw new CodeError('Missing key parameter', 'ERR_MISSING_KEY')

export async function hashAndVerify (key: JsonWebKey, sig: Uint8Array, msg: Uint8Array): Promise<boolean> { // eslint-disable-line require-await
export async function hashAndVerify (key: JsonWebKey, sig: Uint8Array, msg: Uint8Array): Promise<boolean> {
return crypto.createVerify('RSA-SHA256')

@@ -57,0 +57,0 @@ .update(msg)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc