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 2.0.0 to 2.0.1

dist/typedoc-urls.json

1

dist/src/keys/rsa-browser.d.ts

@@ -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

@@ -99,2 +99,12 @@ import { CodeError } from '@libp2p/interface/errors';

}
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;

@@ -11,2 +11,3 @@ import { CodeError } from '@libp2p/interface/errors';

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);

@@ -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

@@ -58,2 +58,12 @@ import crypto from 'crypto';

}
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

2

package.json
{
"name": "@libp2p/crypto",
"version": "2.0.0",
"version": "2.0.1",
"description": "Crypto primitives for libp2p",

@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT",

@@ -158,1 +158,11 @@ import { CodeError } from '@libp2p/interface/errors'

}
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
}

@@ -13,2 +13,4 @@ import { CodeError } from '@libp2p/interface/errors'

export const MAX_KEY_SIZE = 8192
export class RsaPublicKey {

@@ -139,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)

@@ -146,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)

@@ -151,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)

@@ -157,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)
}

@@ -70,1 +70,11 @@ import crypto from 'crypto'

}
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
}

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

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