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

@libp2p/crypto

Package Overview
Dependencies
Maintainers
6
Versions
574
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 1.0.17 to 2.0.0-58421e11

2

dist/src/aes/cipher-mode.js

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
const CIPHER_MODES = {

@@ -3,0 +3,0 @@ 16: 'aes-128-ctr',

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';

@@ -3,0 +3,0 @@ import { equals as uint8ArrayEquals } from 'uint8arrays/equals';

import crypto from 'crypto';
import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
const curves = {

@@ -4,0 +4,0 @@ 'P-256': 'prime256v1',

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
import { base58btc } from 'multiformats/bases/base58';

@@ -3,0 +3,0 @@ import { identity } from 'multiformats/hashes/identity';

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

import * as Secp256k1 from './secp256k1-class.js';
import type { PrivateKey, PublicKey } from '@libp2p/interface-keys';
import type { PrivateKey, PublicKey } from '@libp2p/interface/keys';
export { keyStretcher };

@@ -12,0 +12,0 @@ export { generateEphemeralKeyPair };

import 'node-forge/lib/asn1.js';
import 'node-forge/lib/pbe.js';
import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
// @ts-expect-error types are missing

@@ -5,0 +5,0 @@ import forge from 'node-forge/lib/forge.js';

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';

@@ -3,0 +3,0 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';

@@ -12,2 +12,3 @@ import randomBytes from '../random-bytes.js';

export declare function decrypt(key: JsonWebKey, msg: Uint8Array): Uint8Array;
export declare function keySize(jwk: JsonWebKey): number;
//# sourceMappingURL=rsa-browser.d.ts.map

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';

@@ -99,2 +99,12 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string';

}
export function keySize(jwk) {
if (jwk.kty !== 'RSA') {
throw new CodeError('invalid key type', 'ERR_INVALID_KEY_TYPE');
}
else if (jwk.n == null) {
throw new CodeError('invalid key modulus', 'ERR_INVALID_KEY_MODULUS');
}
const bytes = uint8ArrayFromString(jwk.n, 'base64url');
return bytes.length * 8;
}
//# sourceMappingURL=rsa-browser.js.map
import 'node-forge/lib/sha512.js';
import type { Multibase } from 'multiformats';
export declare const MAX_KEY_SIZE = 8192;
export declare class RsaPublicKey {

@@ -4,0 +5,0 @@ private readonly _key;

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
import { sha256 } from 'multiformats/hashes/sha2';

@@ -11,2 +11,3 @@ // @ts-expect-error types are missing

import * as crypto from './rsa.js';
export const MAX_KEY_SIZE = 8192;
export class RsaPublicKey {

@@ -115,2 +116,5 @@ _key;

const jwk = crypto.utils.pkcs1ToJwk(bytes);
if (crypto.keySize(jwk) > MAX_KEY_SIZE) {
throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE');
}
const keys = await crypto.unmarshalPrivateKey(jwk);

@@ -121,5 +125,11 @@ return new RsaPrivateKey(keys.privateKey, keys.publicKey);

const jwk = crypto.utils.pkixToJwk(bytes);
if (crypto.keySize(jwk) > MAX_KEY_SIZE) {
throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE');
}
return new RsaPublicKey(jwk);
}
export async function fromJwk(jwk) {
if (crypto.keySize(jwk) > MAX_KEY_SIZE) {
throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE');
}
const keys = await crypto.unmarshalPrivateKey(jwk);

@@ -129,2 +139,5 @@ return new RsaPrivateKey(keys.privateKey, keys.publicKey);

export async function generateKeyPair(bits) {
if (bits > MAX_KEY_SIZE) {
throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE');
}
const keys = await crypto.generateKey(bits);

@@ -131,0 +144,0 @@ return new RsaPrivateKey(keys.privateKey, keys.publicKey);

import 'node-forge/lib/asn1.js';
import 'node-forge/lib/rsa.js';
import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
// @ts-expect-error types are missing

@@ -5,0 +5,0 @@ import forge from 'node-forge/lib/forge.js';

@@ -12,2 +12,3 @@ import randomBytes from '../random-bytes.js';

export declare function decrypt(key: JsonWebKey, bytes: Uint8Array): Uint8Array;
export declare function keySize(jwk: JsonWebKey): number;
//# sourceMappingURL=rsa.d.ts.map
import crypto from 'crypto';
import { promisify } from 'util';
import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
import randomBytes from '../random-bytes.js';

@@ -58,2 +58,12 @@ import * as utils from './rsa-utils.js';

}
export function keySize(jwk) {
if (jwk.kty !== 'RSA') {
throw new CodeError('invalid key type', 'ERR_INVALID_KEY_TYPE');
}
else if (jwk.n == null) {
throw new CodeError('invalid key modulus', 'ERR_INVALID_KEY_MODULUS');
}
const modulus = Buffer.from(jwk.n, 'base64');
return modulus.length * 8;
}
//# sourceMappingURL=rsa.js.map

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
import { sha256 } from 'multiformats/hashes/sha2';

@@ -3,0 +3,0 @@ import { equals as uint8ArrayEquals } from 'uint8arrays/equals';

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
import * as secp from '@noble/secp256k1';

@@ -3,0 +3,0 @@ import { sha256 } from 'multiformats/hashes/sha2';

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
// @ts-expect-error types are missing

@@ -3,0 +3,0 @@ import forgePbkdf2 from 'node-forge/lib/pbkdf2.js';

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { CodeError } from '@libp2p/interface/errors';
import { utils } from '@noble/secp256k1';

@@ -3,0 +3,0 @@ export default function randomBytes(length) {

{
"name": "@libp2p/crypto",
"version": "1.0.17",
"version": "2.0.0-58421e11",
"description": "Crypto primitives for libp2p",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/libp2p/js-libp2p-crypto#readme",
"homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/crypto#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/libp2p/js-libp2p-crypto.git"
"url": "git+https://github.com/libp2p/js-libp2p.git"
},
"bugs": {
"url": "https://github.com/libp2p/js-libp2p-crypto/issues"
"url": "https://github.com/libp2p/js-libp2p/issues"
},

@@ -21,6 +21,2 @@ "keywords": [

],
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
},
"type": "module",

@@ -59,6 +55,2 @@ "types": "./dist/src/index.d.ts",

},
"./ciphers": {
"types": "./dist/src/ciphers/index.d.ts",
"import": "./dist/src/ciphers/index.js"
},
"./hmac": {

@@ -82,91 +74,6 @@ "types": "./dist/src/hmac/index.d.ts",

},
"release": {
"branches": [
"master"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"breaking": true,
"release": "major"
},
{
"revert": true,
"release": "patch"
},
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"type": "deps",
"release": "patch"
},
{
"scope": "no-release",
"release": false
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Trivial Changes"
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "deps",
"section": "Dependencies"
},
{
"type": "test",
"section": "Tests"
}
]
}
}
],
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
]
},
"scripts": {
"clean": "aegir clean",
"lint": "aegir lint",
"dep-check": "aegir dep-check -i protons",
"dep-check": "aegir dep-check",
"build": "aegir build",

@@ -178,23 +85,20 @@ "test": "aegir test",

"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
"test:webkit": "bash -c '[ \"${CI}\" == \"true\" ] && playwright install-deps'; aegir test -t browser -- --browser webkit",
"test:webkit": "aegir test -t browser -- --browser webkit",
"test:node": "aegir test -t node --cov",
"test:electron-main": "aegir test -t electron-main",
"release": "aegir release",
"docs": "aegir docs",
"generate": "protons ./src/keys/keys.proto"
},
"dependencies": {
"@libp2p/interface-keys": "^1.0.2",
"@libp2p/interfaces": "^3.2.0",
"@libp2p/interface": "0.1.0-58421e11",
"@noble/ed25519": "^1.6.0",
"@noble/secp256k1": "^1.5.4",
"multiformats": "^11.0.0",
"multiformats": "^12.0.1",
"node-forge": "^1.1.0",
"protons-runtime": "^5.0.0",
"uint8arraylist": "^2.4.3",
"uint8arrays": "^4.0.2"
"uint8arrays": "^4.0.4"
},
"devDependencies": {
"@types/mocha": "^10.0.0",
"aegir": "^39.0.5",
"aegir": "^40.0.1",
"benchmark": "^2.1.4",

@@ -201,0 +105,0 @@ "protons": "^7.0.2"

@@ -5,4 +5,4 @@ # @libp2p/crypto <!-- omit in toc -->

[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-crypto.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-crypto)
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-crypto/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-crypto/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster)

@@ -320,3 +320,3 @@ > Crypto primitives for libp2p

- <https://libp2p.github.io/js-libp2p-crypto>
- <https://libp2p.github.io/js-libp2p/modules/_libp2p_crypto.html>

@@ -323,0 +323,0 @@ ## License

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'

@@ -3,0 +3,0 @@ const CIPHER_MODES = {

@@ -1,2 +0,1 @@

import 'node-forge/lib/aes.js'

@@ -3,0 +2,0 @@ // @ts-expect-error types are missing

@@ -1,2 +0,1 @@

export interface CreateOptions {

@@ -3,0 +2,0 @@ algorithm?: string

@@ -1,2 +0,1 @@

export default {

@@ -3,0 +2,0 @@ SHA1: 20,

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'

@@ -3,0 +3,0 @@ import { equals as uint8ArrayEquals } from 'uint8arrays/equals'

import crypto from 'crypto'
import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import type { ECDHKey, ECDHKeyPair } from './interface.js'

@@ -4,0 +4,0 @@

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import { base58btc } from 'multiformats/bases/base58'

@@ -3,0 +3,0 @@ import { identity } from 'multiformats/hashes/identity'

import 'node-forge/lib/asn1.js'
import 'node-forge/lib/pbe.js'
import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
// @ts-expect-error types are missing

@@ -14,3 +14,3 @@ import forge from 'node-forge/lib/forge.js'

import * as Secp256k1 from './secp256k1-class.js'
import type { PrivateKey, PublicKey } from '@libp2p/interface-keys'
import type { PrivateKey, PublicKey } from '@libp2p/interface/keys'

@@ -17,0 +17,0 @@ export { keyStretcher }

@@ -1,2 +0,1 @@

export interface JWKKeyPair {

@@ -24,3 +23,3 @@ privateKey: JsonWebKey

export interface JWKEncodedPrivateKey extends JWKEncodedPublicKey { d: string}
export interface JWKEncodedPrivateKey extends JWKEncodedPublicKey { d: string }

@@ -27,0 +26,0 @@ export interface EnhancedKey {

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'

@@ -3,0 +3,0 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'

@@ -158,1 +158,11 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string'

}
export function keySize (jwk: JsonWebKey): number {
if (jwk.kty !== 'RSA') {
throw new CodeError('invalid key type', 'ERR_INVALID_KEY_TYPE')
} else if (jwk.n == null) {
throw new CodeError('invalid key modulus', 'ERR_INVALID_KEY_MODULUS')
}
const bytes = uint8ArrayFromString(jwk.n, 'base64url')
return bytes.length * 8
}

@@ -1,3 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import { sha256 } from 'multiformats/hashes/sha2'

@@ -14,2 +13,4 @@ // @ts-expect-error types are missing

export const MAX_KEY_SIZE = 8192
export class RsaPublicKey {

@@ -140,3 +141,9 @@ private readonly _key: JsonWebKey

const jwk = crypto.utils.pkcs1ToJwk(bytes)
if (crypto.keySize(jwk) > MAX_KEY_SIZE) {
throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE')
}
const keys = await crypto.unmarshalPrivateKey(jwk)
return new RsaPrivateKey(keys.privateKey, keys.publicKey)

@@ -147,2 +154,7 @@ }

const jwk = crypto.utils.pkixToJwk(bytes)
if (crypto.keySize(jwk) > MAX_KEY_SIZE) {
throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE')
}
return new RsaPublicKey(jwk)

@@ -152,3 +164,8 @@ }

export async function fromJwk (jwk: JsonWebKey): Promise<RsaPrivateKey> {
if (crypto.keySize(jwk) > MAX_KEY_SIZE) {
throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE')
}
const keys = await crypto.unmarshalPrivateKey(jwk)
return new RsaPrivateKey(keys.privateKey, keys.publicKey)

@@ -158,4 +175,9 @@ }

export async function generateKeyPair (bits: number): Promise<RsaPrivateKey> {
if (bits > MAX_KEY_SIZE) {
throw new CodeError('key size is too large', 'ERR_KEY_SIZE_TOO_LARGE')
}
const keys = await crypto.generateKey(bits)
return new RsaPrivateKey(keys.privateKey, keys.publicKey)
}
import 'node-forge/lib/asn1.js'
import 'node-forge/lib/rsa.js'
import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
// @ts-expect-error types are missing

@@ -5,0 +5,0 @@ import forge from 'node-forge/lib/forge.js'

import crypto from 'crypto'
import { promisify } from 'util'
import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import randomBytes from '../random-bytes.js'

@@ -70,1 +70,11 @@ import * as utils from './rsa-utils.js'

}
export function keySize (jwk: JsonWebKey): number {
if (jwk.kty !== 'RSA') {
throw new CodeError('invalid key type', 'ERR_INVALID_KEY_TYPE')
} else if (jwk.n == null) {
throw new CodeError('invalid key modulus', 'ERR_INVALID_KEY_MODULUS')
}
const modulus = Buffer.from(jwk.n, 'base64')
return modulus.length * 8
}

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import { sha256 } from 'multiformats/hashes/sha2'

@@ -3,0 +3,0 @@ import { equals as uint8ArrayEquals } from 'uint8arrays/equals'

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import * as secp from '@noble/secp256k1'

@@ -3,0 +3,0 @@ import { sha256 } from 'multiformats/hashes/sha2'

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
// @ts-expect-error types are missing

@@ -3,0 +3,0 @@ import forgePbkdf2 from 'node-forge/lib/pbkdf2.js'

@@ -1,2 +0,2 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { CodeError } from '@libp2p/interface/errors'
import { utils } from '@noble/secp256k1'

@@ -3,0 +3,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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