Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

libp2p-crypto

Package Overview
Dependencies
Maintainers
5
Versions
67
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 0.19.6 to 0.19.7

12

package.json
{
"name": "libp2p-crypto",
"version": "0.19.6",
"version": "0.19.7",
"description": "Crypto primitives for libp2p",

@@ -46,12 +46,12 @@ "main": "src/index.js",

"keypair": "^1.0.1",
"multiformats": "^9.1.2",
"multiformats": "^9.4.5",
"node-forge": "^0.10.0",
"pem-jwk": "^2.0.0",
"protobufjs": "^6.10.2",
"protobufjs": "^6.11.2",
"secp256k1": "^4.0.0",
"uint8arrays": "^2.1.4",
"uint8arrays": "^3.0.0",
"ursa-optional": "^0.10.1"
},
"devDependencies": {
"@types/mocha": "^8.0.1",
"@types/mocha": "^9.0.0",
"aegir": "^33.0.0",

@@ -83,4 +83,4 @@ "benchmark": "^2.1.4",

"Maciej Krüger <mkg20001@gmail.com>",
"Vasco Santos <vasco.santos@moxy.studio>",
"dignifiedquire <dignifiedquire@users.noreply.github.com>",
"Vasco Santos <vasco.santos@moxy.studio>",
"dryajov <dryajov@gmail.com>",

@@ -87,0 +87,0 @@ "Alan Shaw <alan.shaw@protocol.ai>",

@@ -5,4 +5,4 @@ 'use strict'

const forge = require('node-forge/lib/forge')
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayFromString = require('uint8arrays/from-string')
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')

@@ -9,0 +9,0 @@ module.exports = {

'use strict'
const concat = require('uint8arrays/concat')
const fromString = require('uint8arrays/from-string')
const { concat } = require('uint8arrays/concat')
const { fromString } = require('uint8arrays/from-string')

@@ -6,0 +6,0 @@ const webcrypto = require('../webcrypto')

'use strict'
const crypto = require('crypto')
const uint8ArrayConcat = require('uint8arrays/concat')
const uint8ArrayFromString = require('uint8arrays/from-string')
const { concat: uint8ArrayConcat } = require('uint8arrays/concat')
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')

@@ -7,0 +7,0 @@ // Based off of code from https://github.com/luke-park/SecureCompatibleEncryptionExamples

/**
* Supported key types.
*/
export type KeyType = "Ed25519" | "RSA" | "secp256k1";
export type KeyType = 'Ed25519' | 'RSA' | 'secp256k1'

@@ -10,3 +10,3 @@ /**

*/
export type HashType = "SHA1" | "SHA256" | "SHA512";
export type HashType = 'SHA1' | 'SHA256' | 'SHA512'

@@ -16,3 +16,3 @@ /**

*/
export type CurveType = "P-256" | "P-384" | "P-521";
export type CurveType = 'P-256' | 'P-384' | 'P-521'

@@ -22,3 +22,3 @@ /**

*/
export type CipherType = "AES-128" | "AES-256" | "Blowfish";
export type CipherType = 'AES-128' | 'AES-256' | 'Blowfish'

@@ -35,11 +35,12 @@ /**

interface Cipher {
encrypt(data: Uint8Array): Promise<Uint8Array>;
decrypt(data: Uint8Array): Promise<Uint8Array>;
encrypt(data: Uint8Array): Promise<Uint8Array>
decrypt(data: Uint8Array): Promise<Uint8Array>
}
/**
* Create a new AES Cipher.
* @param key The key, if length 16 then AES 128 is used. For length 32, AES 256 is used.
* @param iv Must have length 16.
*
* @param key - The key, if length 16 then AES 128 is used. For length 32, AES 256 is used.
* @param iv - Must have length 16.
*/
function create(key: Uint8Array, iv: Uint8Array): Promise<Cipher>;
function create (key: Uint8Array, iv: Uint8Array): Promise<Cipher>
}

@@ -58,4 +59,4 @@

interface Digest {
digest(data: Uint8Array): Promise<Uint8Array>;
length: 20 | 32 | 64 | number;
digest(data: Uint8Array): Promise<Uint8Array>
length: 20 | 32 | 64 | number
}

@@ -65,6 +66,6 @@ /**

*/
function create(
hash: "SHA1" | "SHA256" | "SHA512" | string,
function create (
hash: 'SHA1' | 'SHA256' | 'SHA512' | string,
secret: Uint8Array
): Promise<Digest>;
): Promise<Digest>
}

@@ -76,7 +77,7 @@

export interface PublicKey {
readonly bytes: Uint8Array;
verify(data: Uint8Array, sig: Uint8Array): Promise<boolean>;
marshal(): Uint8Array;
equals(key: PublicKey): boolean;
hash(): Promise<Uint8Array>;
readonly bytes: Uint8Array
verify: (data: Uint8Array, sig: Uint8Array) => Promise<boolean>
marshal: () => Uint8Array
equals: (key: PublicKey) => boolean
hash: () => Promise<Uint8Array>
}

@@ -88,8 +89,8 @@

export interface PrivateKey {
readonly public: PublicKey;
readonly bytes: Uint8Array;
sign(data: Uint8Array): Promise<Uint8Array>;
marshal(): Uint8Array;
equals(key: PrivateKey): boolean;
hash(): Promise<Uint8Array>;
readonly public: PublicKey
readonly bytes: Uint8Array
sign: (data: Uint8Array) => Promise<Uint8Array>
marshal: () => Uint8Array
equals: (key: PrivateKey) => boolean
hash: () => Promise<Uint8Array>
/**

@@ -102,19 +103,19 @@ * Gets the ID of the key.

*/
id(): Promise<string>;
id: () => Promise<string>
/**
* Exports the password protected key in the format specified.
*/
export(password: string, format?: "pkcs-8" | string): Promise<string>;
export: (password: string, format?: 'pkcs-8' | string) => Promise<string>
}
export interface Keystretcher {
(res: Uint8Array): Keystretcher;
iv: Uint8Array;
cipherKey: Uint8Array;
macKey: Uint8Array;
(res: Uint8Array): Keystretcher
iv: Uint8Array
cipherKey: Uint8Array
macKey: Uint8Array
}
export interface StretchPair {
k1: Keystretcher;
k2: Keystretcher;
k1: Keystretcher
k2: Keystretcher
}

@@ -133,32 +134,32 @@

export namespace keys {
export {};
export {}
export namespace supportedKeys {
namespace rsa {
class RsaPublicKey implements PublicKey {
constructor(key: Uint8Array);
readonly bytes: Uint8Array;
verify(data: Uint8Array, sig: Uint8Array): Promise<boolean>;
marshal(): Uint8Array;
encrypt(bytes: Uint8Array): Uint8Array;
equals(key: PublicKey): boolean;
hash(): Promise<Uint8Array>;
constructor (key: Uint8Array);
readonly bytes: Uint8Array
verify (data: Uint8Array, sig: Uint8Array): Promise<boolean>;
marshal (): Uint8Array;
encrypt (bytes: Uint8Array): Uint8Array;
equals (key: PublicKey): boolean;
hash (): Promise<Uint8Array>;
}
class RsaPrivateKey implements PrivateKey {
constructor(key: any, publicKey: Uint8Array);
readonly public: RsaPublicKey;
readonly bytes: Uint8Array;
genSecret(): Uint8Array;
sign(data: Uint8Array): Promise<Uint8Array>;
decrypt(bytes: Uint8Array): Uint8Array;
marshal(): Uint8Array;
equals(key: PrivateKey): boolean;
hash(): Promise<Uint8Array>;
id(): Promise<string>;
export(password: string, format?: string): Promise<string>;
constructor (key: any, publicKey: Uint8Array);
readonly public: RsaPublicKey
readonly bytes: Uint8Array
genSecret (): Uint8Array;
sign (data: Uint8Array): Promise<Uint8Array>;
decrypt (bytes: Uint8Array): Uint8Array;
marshal (): Uint8Array;
equals (key: PrivateKey): boolean;
hash (): Promise<Uint8Array>;
id (): Promise<string>;
export (password: string, format?: string): Promise<string>;
}
function unmarshalRsaPublicKey(buf: Uint8Array): RsaPublicKey;
function unmarshalRsaPrivateKey(buf: Uint8Array): Promise<RsaPrivateKey>;
function generateKeyPair(bits: number): Promise<RsaPrivateKey>;
function fromJwk(jwk: Uint8Array): Promise<RsaPrivateKey>;
function unmarshalRsaPublicKey (buf: Uint8Array): RsaPublicKey
function unmarshalRsaPrivateKey (buf: Uint8Array): Promise<RsaPrivateKey>
function generateKeyPair (bits: number): Promise<RsaPrivateKey>
function fromJwk (jwk: Uint8Array): Promise<RsaPrivateKey>
}

@@ -168,31 +169,31 @@

class Ed25519PublicKey implements PublicKey {
constructor(key: Uint8Array);
readonly bytes: Uint8Array;
verify(data: Uint8Array, sig: Uint8Array): Promise<boolean>;
marshal(): Uint8Array;
encrypt(bytes: Uint8Array): Uint8Array;
equals(key: PublicKey): boolean;
hash(): Promise<Uint8Array>;
constructor (key: Uint8Array);
readonly bytes: Uint8Array
verify (data: Uint8Array, sig: Uint8Array): Promise<boolean>;
marshal (): Uint8Array;
encrypt (bytes: Uint8Array): Uint8Array;
equals (key: PublicKey): boolean;
hash (): Promise<Uint8Array>;
}
class Ed25519PrivateKey implements PrivateKey {
constructor(key: Uint8Array, publicKey: Uint8Array);
readonly public: Ed25519PublicKey;
readonly bytes: Uint8Array;
sign(data: Uint8Array): Promise<Uint8Array>;
marshal(): Uint8Array;
equals(key: PrivateKey): boolean;
hash(): Promise<Uint8Array>;
id(): Promise<string>;
export(password: string, format?: string): Promise<string>;
constructor (key: Uint8Array, publicKey: Uint8Array);
readonly public: Ed25519PublicKey
readonly bytes: Uint8Array
sign (data: Uint8Array): Promise<Uint8Array>;
marshal (): Uint8Array;
equals (key: PrivateKey): boolean;
hash (): Promise<Uint8Array>;
id (): Promise<string>;
export (password: string, format?: string): Promise<string>;
}
function unmarshalEd25519PrivateKey(
function unmarshalEd25519PrivateKey (
buf: Uint8Array
): Promise<Ed25519PrivateKey>;
function unmarshalEd25519PublicKey(buf: Uint8Array): Ed25519PublicKey;
function generateKeyPair(): Promise<Ed25519PrivateKey>;
function generateKeyPairFromSeed(
): Promise<Ed25519PrivateKey>
function unmarshalEd25519PublicKey (buf: Uint8Array): Ed25519PublicKey
function generateKeyPair (): Promise<Ed25519PrivateKey>
function generateKeyPairFromSeed (
seed: Uint8Array
): Promise<Ed25519PrivateKey>;
): Promise<Ed25519PrivateKey>
}

@@ -202,69 +203,71 @@

class Secp256k1PublicKey implements PublicKey {
constructor(key: Uint8Array);
readonly bytes: Uint8Array;
verify(data: Uint8Array, sig: Uint8Array): Promise<boolean>;
marshal(): Uint8Array;
encrypt(bytes: Uint8Array): Uint8Array;
equals(key: PublicKey): boolean;
hash(): Promise<Uint8Array>;
constructor (key: Uint8Array);
readonly bytes: Uint8Array
verify (data: Uint8Array, sig: Uint8Array): Promise<boolean>;
marshal (): Uint8Array;
encrypt (bytes: Uint8Array): Uint8Array;
equals (key: PublicKey): boolean;
hash (): Promise<Uint8Array>;
}
class Secp256k1PrivateKey implements PrivateKey {
constructor(key: Uint8Array, publicKey: Uint8Array);
readonly public: Secp256k1PublicKey;
readonly bytes: Uint8Array;
sign(data: Uint8Array): Promise<Uint8Array>;
marshal(): Uint8Array;
equals(key: PrivateKey): boolean;
hash(): Promise<Uint8Array>;
id(): Promise<string>;
export(password: string, format?: string): Promise<string>;
constructor (key: Uint8Array, publicKey: Uint8Array);
readonly public: Secp256k1PublicKey
readonly bytes: Uint8Array
sign (data: Uint8Array): Promise<Uint8Array>;
marshal (): Uint8Array;
equals (key: PrivateKey): boolean;
hash (): Promise<Uint8Array>;
id (): Promise<string>;
export (password: string, format?: string): Promise<string>;
}
function unmarshalSecp256k1PrivateKey(
function unmarshalSecp256k1PrivateKey (
bytes: Uint8Array
): Promise<Secp256k1PrivateKey>;
function unmarshalSecp256k1PublicKey(bytes: Uint8Array): Secp256k1PublicKey;
function generateKeyPair(): Promise<Secp256k1PrivateKey>;
): Promise<Secp256k1PrivateKey>
function unmarshalSecp256k1PublicKey (bytes: Uint8Array): Secp256k1PublicKey
function generateKeyPair (): Promise<Secp256k1PrivateKey>
}
}
export const keysPBM: any;
export const keysPBM: any
/**
* Generates a keypair of the given type and bitsize.
* @param type One of the supported key types.
* @param bits Number of bits. Minimum of 1024.
*
* @param type - One of the supported key types.
* @param bits - Number of bits. Minimum of 1024.
*/
export function generateKeyPair(
export function generateKeyPair (
type: KeyType | string,
bits: number
): Promise<PrivateKey>;
export function generateKeyPair(
type: "Ed25519"
): Promise<keys.supportedKeys.ed25519.Ed25519PrivateKey>;
export function generateKeyPair(
type: "RSA",
): Promise<PrivateKey>
export function generateKeyPair (
type: 'Ed25519'
): Promise<keys.supportedKeys.ed25519.Ed25519PrivateKey>
export function generateKeyPair (
type: 'RSA',
bits: number
): Promise<keys.supportedKeys.rsa.RsaPrivateKey>;
export function generateKeyPair(
type: "secp256k1"
): Promise<keys.supportedKeys.secp256k1.Secp256k1PrivateKey>;
): Promise<keys.supportedKeys.rsa.RsaPrivateKey>
export function generateKeyPair (
type: 'secp256k1'
): Promise<keys.supportedKeys.secp256k1.Secp256k1PrivateKey>
/**
* Generates a keypair of the given type and bitsize.
* @param type One of the supported key types. Currently only 'Ed25519' is supported.
* @param seed A 32 byte uint8array.
* @param bits Number of bits. Minimum of 1024.
*
* @param type - One of the supported key types. Currently only 'Ed25519' is supported.
* @param seed - A 32 byte uint8array.
* @param bits - Number of bits. Minimum of 1024.
*/
export function generateKeyPairFromSeed(
export function generateKeyPairFromSeed (
type: KeyType | string,
seed: Uint8Array,
bits: number
): Promise<PrivateKey>;
export function generateKeyPairFromSeed(
type: "Ed25519",
): Promise<PrivateKey>
export function generateKeyPairFromSeed (
type: 'Ed25519',
seed: Uint8Array,
bits: number
): Promise<keys.supportedKeys.ed25519.Ed25519PrivateKey>;
): Promise<keys.supportedKeys.ed25519.Ed25519PrivateKey>

@@ -274,56 +277,63 @@ /**

* Focuses only on ECDH now, but can be made more general in the future.
* @param curve The curve to use. One of 'P-256', 'P-384', 'P-521' is currently supported.
*
* @param curve - The curve to use. One of 'P-256', 'P-384', 'P-521' is currently supported.
*/
export function generateEphemeralKeyPair(
export function generateEphemeralKeyPair (
curve: CurveType | string
): Promise<{
key: Uint8Array;
genSharedKey: (theirPub: Uint8Array, forcePrivate?: any) => Promise<Uint8Array>;
}>;
key: Uint8Array
genSharedKey: (theirPub: Uint8Array, forcePrivate?: any) => Promise<Uint8Array>
}>
/**
* Generates a set of keys for each party by stretching the shared key.
* @param cipherType The cipher type to use. One of 'AES-128', 'AES-256', or 'Blowfish'
* @param hashType The hash type to use. One of 'SHA1', 'SHA2256', or 'SHA2512'.
* @param secret The shared key secret.
*
* @param cipherType - The cipher type to use. One of 'AES-128', 'AES-256', or 'Blowfish'
* @param hashType - The hash type to use. One of 'SHA1', 'SHA2256', or 'SHA2512'.
* @param secret - The shared key secret.
*/
export function keyStretcher(
export function keyStretcher (
cipherType: CipherType | string,
hashType: HashType | string,
secret: Uint8Array | string
): Promise<StretchPair>;
): Promise<StretchPair>
/**
* Converts a protobuf serialized public key into its representative object.
* @param buf The protobuf serialized public key.
*
* @param buf - The protobuf serialized public key.
*/
export function unmarshalPublicKey(buf: Uint8Array): PublicKey;
export function unmarshalPublicKey (buf: Uint8Array): PublicKey
/**
* Converts a public key object into a protobuf serialized public key.
* @param key An RSA, Ed25519, or Secp256k1 public key object.
* @param type One of the supported key types.
*
* @param key - An RSA, Ed25519, or Secp256k1 public key object.
* @param type - One of the supported key types.
*/
export function marshalPublicKey(key: PublicKey, type?: KeyType | string): Uint8Array;
export function marshalPublicKey (key: PublicKey, type?: KeyType | string): Uint8Array
/**
* Converts a protobuf serialized private key into its representative object.
* @param buf The protobuf serialized private key.
*
* @param buf - The protobuf serialized private key.
*/
export function unmarshalPrivateKey(buf: Uint8Array): Promise<PrivateKey>;
export function unmarshalPrivateKey (buf: Uint8Array): Promise<PrivateKey>
/**
* Converts a private key object into a protobuf serialized private key.
* @param key An RSA, Ed25519, or Secp256k1 private key object.
* @param type One of the supported key types.
*
* @param key - An RSA, Ed25519, or Secp256k1 private key object.
* @param type - One of the supported key types.
*/
export function marshalPrivateKey(key: PrivateKey, type?: KeyType | string): Uint8Array;
export function marshalPrivateKey (key: PrivateKey, type?: KeyType | string): Uint8Array
/**
* Converts a PEM password protected private key into its representative object.
* @param pem Password protected private key in PEM format.
* @param password The password used to protect the key.
*
* @param pem - Password protected private key in PEM format.
* @param password - The password used to protect the key.
*/
function _import(pem: string, password: string, format?: string): Promise<supportedKeys.rsa.RsaPrivateKey>;
export { _import as import };
function _import (pem: string, password: string, format?: string): Promise<supportedKeys.rsa.RsaPrivateKey>
export { _import as import }
}

@@ -333,15 +343,17 @@

* Generates a Uint8Array populated by random bytes.
* @param The size of the random bytes Uint8Array.
*
* @param The - size of the random bytes Uint8Array.
*/
export function randomBytes(number: number): Uint8Array;
export function randomBytes (number: number): Uint8Array
/**
* Computes the Password-Based Key Derivation Function 2.
* @param password The password.
* @param salt The salt.
* @param iterations Number of iterations to use.
* @param keySize The size of the output key in bytes.
* @param hash The hash name ('sha1', 'sha2-512, ...)
*
* @param password - The password.
* @param salt - The salt.
* @param iterations - Number of iterations to use.
* @param keySize - The size of the output key in bytes.
* @param hash - The hash name ('sha1', 'sha2-512, ...)
*/
export function pbkdf2(
export function pbkdf2 (
password: string | Uint8Array,

@@ -352,2 +364,2 @@ salt: string | Uint8Array,

hash: string
): Uint8Array;
): Uint8Array

@@ -7,5 +7,5 @@ 'use strict'

const validateCurveType = require('./validate-curve-type')
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayConcat = require('uint8arrays/concat')
const uint8ArrayEquals = require('uint8arrays/equals')
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
const { concat: uint8ArrayConcat } = require('uint8arrays/concat')
const { equals: uint8ArrayEquals } = require('uint8arrays/equals')

@@ -12,0 +12,0 @@ const bits = {

'use strict'
const errcode = require('err-code')
const uint8ArrayEquals = require('uint8arrays/equals')
const { equals: uint8ArrayEquals } = require('uint8arrays/equals')
const { sha256 } = require('multiformats/hashes/sha2')

@@ -6,0 +6,0 @@ const { base58btc } = require('multiformats/bases/base58')

@@ -8,3 +8,3 @@ 'use strict'

const errcode = require('err-code')
const uint8ArrayFromString = require('uint8arrays/from-string')
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')

@@ -11,0 +11,0 @@ const importer = require('./importer')

'use strict'
const errcode = require('err-code')
const uint8ArrayConcat = require('uint8arrays/concat')
const uint8ArrayFromString = require('uint8arrays/from-string')
const { concat: uint8ArrayConcat } = require('uint8arrays/concat')
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
const hmac = require('../hmac')

@@ -7,0 +7,0 @@

@@ -5,4 +5,4 @@ 'use strict'

const randomBytes = require('../random-bytes')
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayFromString = require('uint8arrays/from-string')
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')

@@ -9,0 +9,0 @@ exports.utils = require('./rsa-utils')

@@ -5,4 +5,4 @@ 'use strict'

const errcode = require('err-code')
const uint8ArrayEquals = require('uint8arrays/equals')
const uint8ArrayToString = require('uint8arrays/to-string')
const { equals: uint8ArrayEquals } = require('uint8arrays/equals')
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')

@@ -9,0 +9,0 @@ require('node-forge/lib/sha512')

@@ -7,4 +7,4 @@ 'use strict'

const { bigIntegerToUintBase64url, base64urlToBigInteger } = require('./../util')
const uint8ArrayFromString = require('uint8arrays/from-string')
const uint8ArrayToString = require('uint8arrays/to-string')
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')

@@ -11,0 +11,0 @@ // Convert a PKCS#1 in ASN1 DER format to a JWK key

@@ -5,4 +5,4 @@ 'use strict'

const errcode = require('err-code')
const uint8ArrayEquals = require('uint8arrays/equals')
const uint8ArrayToString = require('uint8arrays/to-string')
const { equals: uint8ArrayEquals } = require('uint8arrays/equals')
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')

@@ -9,0 +9,0 @@ const exporter = require('./exporter')

@@ -6,5 +6,5 @@ 'use strict'

const forge = require('node-forge/lib/forge')
const uint8ArrayFromString = require('uint8arrays/from-string')
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayConcat = require('uint8arrays/concat')
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
const { concat: uint8ArrayConcat } = require('uint8arrays/concat')

@@ -11,0 +11,0 @@ exports.bigIntegerToUintBase64url = (num, len) => {

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