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.16 to 1.0.17-3dfc236e

2

dist/src/aes/ciphers-browser.js
import 'node-forge/lib/aes.js';
// @ts-expect-error types are missing
import forge from 'node-forge/lib/forge.js';
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
export function createCipheriv(mode, key, iv) {

@@ -7,0 +7,0 @@ const cipher2 = forge.cipher.createCipher('AES-CTR', uint8ArrayToString(key, 'ascii'));

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

import { cipherMode } from './cipher-mode.js';
import * as ciphers from './ciphers.js';
import { cipherMode } from './cipher-mode.js';
export async function create(key, iv) {

@@ -4,0 +4,0 @@ const mode = cipherMode(key);

@@ -75,3 +75,3 @@ import crypto from 'crypto';

// Decrypt and return result.
return await decryptWithKey(ciphertextAndNonce, key);
return decryptWithKey(ciphertextAndNonce, key);
}

@@ -78,0 +78,0 @@ const cipher = {

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

async digest(data) {
return await sign(key, data);
return sign(key, data);
},

@@ -23,0 +23,0 @@ length: lengths[hashType]

@@ -0,6 +1,6 @@

import * as aes from './aes/index.js';
import * as hmac from './hmac/index.js';
import * as aes from './aes/index.js';
import * as keys from './keys/index.js';
import pbkdf2 from './pbkdf2.js';
import randomBytes from './random-bytes.js';
import pbkdf2 from './pbkdf2.js';
export { aes };

@@ -7,0 +7,0 @@ export { hmac };

@@ -0,6 +1,6 @@

import * as aes from './aes/index.js';
import * as hmac from './hmac/index.js';
import * as aes from './aes/index.js';
import * as keys from './keys/index.js';
import pbkdf2 from './pbkdf2.js';
import randomBytes from './random-bytes.js';
import pbkdf2 from './pbkdf2.js';
export { aes };

@@ -7,0 +7,0 @@ export { hmac };

import { CodeError } from '@libp2p/interfaces/errors';
import webcrypto from '../webcrypto.js';
import { base64urlToBuffer } from '../util.js';
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
import { base64urlToBuffer } from '../util.js';
import webcrypto from '../webcrypto.js';
const bits = {

@@ -8,0 +8,0 @@ 'P-256': 256,

@@ -39,6 +39,6 @@ import * as ed from '@noble/ed25519';

const privateKeyRaw = privateKey.subarray(0, KEYS_BYTE_LENGTH);
return await ed.sign(msg, privateKeyRaw);
return ed.sign(msg, privateKeyRaw);
}
export async function hashAndVerify(publicKey, sig, msg) {
return await ed.verify(sig, msg, publicKey);
return ed.verify(sig, msg, publicKey);
}

@@ -45,0 +45,0 @@ function concatKeys(privateKeyRaw, publicKey) {

import { CodeError } from '@libp2p/interfaces/errors';
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
import { sha256 } from 'multiformats/hashes/sha2';
import { base58btc } from 'multiformats/bases/base58';
import { identity } from 'multiformats/hashes/identity';
import { sha256 } from 'multiformats/hashes/sha2';
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
import * as crypto from './ed25519.js';
import { exporter } from './exporter.js';
import * as pbm from './keys.js';
import { exporter } from './exporter.js';
export class Ed25519PublicKey {
_key;
constructor(key) {

@@ -14,3 +15,3 @@ this._key = ensureKey(key, crypto.publicKeyLength);

async verify(data, sig) {
return await crypto.hashAndVerify(this._key, sig, data);
return crypto.hashAndVerify(this._key, sig, data);
}

@@ -35,2 +36,4 @@ marshal() {

export class Ed25519PrivateKey {
_key;
_publicKey;
// key - 64 byte Uint8Array containing private key

@@ -43,3 +46,3 @@ // publicKey - 32 byte Uint8Array containing public key

async sign(message) {
return await crypto.hashAndSign(this._key, message);
return crypto.hashAndSign(this._key, message);
}

@@ -83,3 +86,3 @@ get public() {

if (format === 'libp2p-key') {
return await exporter(this.bytes, password);
return exporter(this.bytes, password);
}

@@ -86,0 +89,0 @@ else {

import crypto from 'crypto';
import { promisify } from 'util';
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string';
import { toString as uint8arrayToString } from 'uint8arrays/to-string';
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string';
const keypair = promisify(crypto.generateKeyPair);

@@ -6,0 +6,0 @@ const PUBLIC_KEY_BYTE_LENGTH = 32;

@@ -11,4 +11,4 @@ import { base64 } from 'multiformats/bases/base64';

const cipher = ciphers.create();
return await cipher.decrypt(encryptedKey, password);
return cipher.decrypt(encryptedKey, password);
}
//# sourceMappingURL=importer.js.map

@@ -1,8 +0,8 @@

import * as keysPBM from './keys.js';
import 'node-forge/lib/asn1.js';
import 'node-forge/lib/pbe.js';
import * as Ed25519 from './ed25519-class.js';
import generateEphemeralKeyPair from './ephemeral-keys.js';
import { keyStretcher } from './key-stretcher.js';
import generateEphemeralKeyPair from './ephemeral-keys.js';
import * as keysPBM from './keys.js';
import * as RSA from './rsa-class.js';
import * as Ed25519 from './ed25519-class.js';
import * as Secp256k1 from './secp256k1-class.js';

@@ -9,0 +9,0 @@ import type { PrivateKey, PublicKey } from '@libp2p/interface-keys';

@@ -1,13 +0,13 @@

import * as keysPBM from './keys.js';
import 'node-forge/lib/asn1.js';
import 'node-forge/lib/pbe.js';
import { CodeError } from '@libp2p/interfaces/errors';
// @ts-expect-error types are missing
import forge from 'node-forge/lib/forge.js';
import { CodeError } from '@libp2p/interfaces/errors';
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
import { keyStretcher } from './key-stretcher.js';
import * as Ed25519 from './ed25519-class.js';
import generateEphemeralKeyPair from './ephemeral-keys.js';
import { importer } from './importer.js';
import { keyStretcher } from './key-stretcher.js';
import * as keysPBM from './keys.js';
import * as RSA from './rsa-class.js';
import * as Ed25519 from './ed25519-class.js';
import * as Secp256k1 from './secp256k1-class.js';

@@ -35,3 +35,3 @@ export { keyStretcher };

export async function generateKeyPair(type, bits) {
return await typeToKey(type).generateKeyPair(bits ?? 2048);
return typeToKey(type).generateKeyPair(bits ?? 2048);
}

@@ -44,3 +44,3 @@ // Generates a keypair of the given type and bitsize

}
return await Ed25519.generateKeyPairFromSeed(seed);
return Ed25519.generateKeyPairFromSeed(seed);
}

@@ -76,3 +76,3 @@ // Converts a protobuf serialized public key into its

case keysPBM.KeyType.RSA:
return await supportedKeys.rsa.unmarshalRsaPrivateKey(data);
return supportedKeys.rsa.unmarshalRsaPrivateKey(data);
case keysPBM.KeyType.Ed25519:

@@ -112,4 +112,4 @@ return supportedKeys.ed25519.unmarshalEd25519PrivateKey(data);

der = uint8ArrayFromString(der.getBytes(), 'ascii');
return await supportedKeys.rsa.unmarshalRsaPrivateKey(der);
return supportedKeys.rsa.unmarshalRsaPrivateKey(der);
}
//# sourceMappingURL=index.js.map

@@ -0,8 +1,8 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
import randomBytes from '../random-bytes.js';
import webcrypto from '../webcrypto.js';
import randomBytes from '../random-bytes.js';
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
import { jwk2pub, jwk2priv } from './jwk2pem.js';
import * as utils from './rsa-utils.js';
import { jwk2pub, jwk2priv } from './jwk2pem.js';
import { CodeError } from '@libp2p/interfaces/errors';
export { utils };

@@ -55,3 +55,3 @@ export async function generateKey(bits) {

}, false, ['verify']);
return await webcrypto.get().subtle.verify({ name: 'RSASSA-PKCS1-v1_5' }, publicKey, sig, msg);
return webcrypto.get().subtle.verify({ name: 'RSASSA-PKCS1-v1_5' }, publicKey, sig, msg);
}

@@ -62,3 +62,3 @@ async function exportKey(pair) {

}
return await Promise.all([
return Promise.all([
webcrypto.get().subtle.exportKey('jwk', pair.privateKey),

@@ -69,3 +69,3 @@ webcrypto.get().subtle.exportKey('jwk', pair.publicKey)

async function derivePublicFromPrivate(jwKey) {
return await webcrypto.get().subtle.importKey('jwk', {
return webcrypto.get().subtle.importKey('jwk', {
kty: jwKey.kty,

@@ -72,0 +72,0 @@ n: jwKey.n,

@@ -0,12 +1,13 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { sha256 } from 'multiformats/hashes/sha2';
import { CodeError } from '@libp2p/interfaces/errors';
// @ts-expect-error types are missing
import forge from 'node-forge/lib/forge.js';
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
import 'node-forge/lib/sha512.js';
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
import 'node-forge/lib/sha512.js';
// @ts-expect-error types are missing
import forge from 'node-forge/lib/forge.js';
import { exporter } from './exporter.js';
import * as pbm from './keys.js';
import * as crypto from './rsa.js';
import * as pbm from './keys.js';
import { exporter } from './exporter.js';
export class RsaPublicKey {
_key;
constructor(key) {

@@ -16,3 +17,3 @@ this._key = key;

async verify(data, sig) {
return await crypto.hashAndVerify(this._key, sig, data);
return crypto.hashAndVerify(this._key, sig, data);
}

@@ -40,2 +41,4 @@ marshal() {

export class RsaPrivateKey {
_key;
_publicKey;
constructor(key, publicKey) {

@@ -49,3 +52,3 @@ this._key = key;

async sign(message) {
return await crypto.hashAndSign(this._key, message);
return crypto.hashAndSign(this._key, message);
}

@@ -105,3 +108,3 @@ get public() {

else if (format === 'libp2p-key') {
return await exporter(this.bytes, password);
return exporter(this.bytes, password);
}

@@ -108,0 +111,0 @@ else {

import 'node-forge/lib/asn1.js';
import 'node-forge/lib/rsa.js';
import { CodeError } from '@libp2p/interfaces/errors';
// @ts-expect-error types are missing
import forge from 'node-forge/lib/forge.js';
import { bigIntegerToUintBase64url, base64urlToBigInteger } from './../util.js';
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
import { CodeError } from '@libp2p/interfaces/errors';
import { bigIntegerToUintBase64url, base64urlToBigInteger } from './../util.js';
// Convert a PKCS#1 in ASN1 DER format to a JWK key

@@ -10,0 +10,0 @@ export function pkcs1ToJwk(bytes) {

@@ -0,9 +1,10 @@

import { CodeError } from '@libp2p/interfaces/errors';
import { sha256 } from 'multiformats/hashes/sha2';
import { CodeError } from '@libp2p/interfaces/errors';
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
import * as crypto from './secp256k1.js';
import { exporter } from './exporter.js';
import * as keysProtobuf from './keys.js';
import * as crypto from './secp256k1.js';
export class Secp256k1PublicKey {
_key;
constructor(key) {

@@ -14,3 +15,3 @@ crypto.validatePublicKey(key);

async verify(data, sig) {
return await crypto.hashAndVerify(this._key, sig, data);
return crypto.hashAndVerify(this._key, sig, data);
}

@@ -35,2 +36,4 @@ marshal() {

export class Secp256k1PrivateKey {
_key;
_publicKey;
constructor(key, publicKey) {

@@ -43,3 +46,3 @@ this._key = key;

async sign(message) {
return await crypto.hashAndSign(this._key, message);
return crypto.hashAndSign(this._key, message);
}

@@ -81,3 +84,3 @@ get public() {

if (format === 'libp2p-key') {
return await exporter(this.bytes, password);
return exporter(this.bytes, password);
}

@@ -84,0 +87,0 @@ else {

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

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

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

import forgeUtil from 'node-forge/lib/util.js';
import { CodeError } from '@libp2p/interfaces/errors';
/**

@@ -8,0 +8,0 @@ * Maps an IPFS hash name to its node-forge equivalent.

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

import { CodeError } from '@libp2p/interfaces/errors';
import { utils } from '@noble/secp256k1';
import { CodeError } from '@libp2p/interfaces/errors';
export default function randomBytes(length) {

@@ -4,0 +4,0 @@ if (isNaN(length) || length <= 0) {

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

import forge from 'node-forge/lib/forge.js';
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
export function bigIntegerToUintBase64url(num, len) {

@@ -10,0 +10,0 @@ // Call `.abs()` to convert to unsigned

{
"name": "@libp2p/crypto",
"version": "1.0.16",
"version": "1.0.17-3dfc236e",
"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",

@@ -81,87 +77,2 @@ "types": "./dist/src/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": {

@@ -180,23 +91,20 @@ "clean": "aegir clean",

"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-keys": "1.0.8-3dfc236e",
"@libp2p/interfaces": "3.3.2-3dfc236e",
"@noble/ed25519": "^1.6.0",
"@noble/secp256k1": "^1.5.4",
"multiformats": "^11.0.0",
"multiformats": "^11.0.2",
"node-forge": "^1.1.0",
"protons-runtime": "^5.0.0",
"uint8arraylist": "^2.4.3",
"uint8arrays": "^4.0.2"
"uint8arrays": "^4.0.3"
},
"devDependencies": {
"@types/mocha": "^10.0.0",
"aegir": "^38.1.2",
"aegir": "^39.0.10",
"benchmark": "^2.1.4",
"protons": "^7.0.2",
"util": "^0.12.5"
"protons": "^7.0.2"
},

@@ -210,3 +118,6 @@ "browser": {

"./dist/src/keys/rsa.js": "./dist/src/keys/rsa-browser.js"
},
"typedoc": {
"entryPoint": "./src/index.ts"
}
}

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

@@ -5,4 +5,4 @@

import forge from 'node-forge/lib/forge.js'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'

@@ -9,0 +9,0 @@ export interface Cipher {

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

import { cipherMode } from './cipher-mode.js'
import * as ciphers from './ciphers.js'
import { cipherMode } from './cipher-mode.js'

@@ -4,0 +4,0 @@ export interface AESCipher {

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

} else {
// Derive a key using PBKDF2.
// Derive a key using PBKDF2.
const deriveParams = { name: 'PBKDF2', salt, iterations, hash: { name: digest } }

@@ -58,0 +58,0 @@ const rawKey = await crypto.subtle.importKey('raw', password, { name: 'PBKDF2' }, false, ['deriveKey'])

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

// Decrypt and return result.
return await decryptWithKey(ciphertextAndNonce, key)
return decryptWithKey(ciphertextAndNonce, key)
}

@@ -96,0 +96,0 @@

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

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

@@ -34,0 +34,0 @@ length: lengths[hashType]

@@ -0,6 +1,6 @@

import * as aes from './aes/index.js'
import * as hmac from './hmac/index.js'
import * as aes from './aes/index.js'
import * as keys from './keys/index.js'
import pbkdf2 from './pbkdf2.js'
import randomBytes from './random-bytes.js'
import pbkdf2 from './pbkdf2.js'

@@ -7,0 +7,0 @@ export { aes }

import { CodeError } from '@libp2p/interfaces/errors'
import webcrypto from '../webcrypto.js'
import { base64urlToBuffer } from '../util.js'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { base64urlToBuffer } from '../util.js'
import webcrypto from '../webcrypto.js'
import type { ECDHKey, ECDHKeyPair, JWKEncodedPrivateKey, JWKEncodedPublicKey } from './interface.js'

@@ -8,0 +8,0 @@

@@ -50,7 +50,7 @@ import * as ed from '@noble/ed25519'

return await ed.sign(msg, privateKeyRaw)
return ed.sign(msg, privateKeyRaw)
}
export async function hashAndVerify (publicKey: Uint8Array, sig: Uint8Array, msg: Uint8Array): Promise<boolean> {
return await ed.verify(sig, msg, publicKey)
return ed.verify(sig, msg, publicKey)
}

@@ -57,0 +57,0 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { sha256 } from 'multiformats/hashes/sha2'
import { base58btc } from 'multiformats/bases/base58'
import { identity } from 'multiformats/hashes/identity'
import { sha256 } from 'multiformats/hashes/sha2'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import * as crypto from './ed25519.js'
import { exporter } from './exporter.js'
import * as pbm from './keys.js'
import { exporter } from './exporter.js'
import type { Multibase } from 'multiformats'

@@ -19,3 +19,3 @@

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

@@ -57,3 +57,3 @@

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

@@ -105,3 +105,3 @@

if (format === 'libp2p-key') {
return await exporter(this.bytes, password)
return exporter(this.bytes, password)
} else {

@@ -108,0 +108,0 @@ throw new CodeError(`export format '${format}' is not supported`, 'ERR_INVALID_EXPORT_FORMAT')

import crypto from 'crypto'
import { promisify } from 'util'
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
import { toString as uint8arrayToString } from 'uint8arrays/to-string'
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
import type { Uint8ArrayKeyPair } from './interface.js'

@@ -6,0 +6,0 @@

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

import type { Multibase } from 'multiformats'
import { base64 } from 'multiformats/bases/base64'
import * as ciphers from '../ciphers/aes-gcm.js'
import type { Multibase } from 'multiformats'

@@ -5,0 +5,0 @@ /**

@@ -12,3 +12,3 @@ import { base64 } from 'multiformats/bases/base64'

const cipher = ciphers.create()
return await cipher.decrypt(encryptedKey, password)
return cipher.decrypt(encryptedKey, password)
}

@@ -1,13 +0,13 @@

import * as keysPBM from './keys.js'
import 'node-forge/lib/asn1.js'
import 'node-forge/lib/pbe.js'
import { CodeError } from '@libp2p/interfaces/errors'
// @ts-expect-error types are missing
import forge from 'node-forge/lib/forge.js'
import { CodeError } from '@libp2p/interfaces/errors'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { keyStretcher } from './key-stretcher.js'
import * as Ed25519 from './ed25519-class.js'
import generateEphemeralKeyPair from './ephemeral-keys.js'
import { importer } from './importer.js'
import { keyStretcher } from './key-stretcher.js'
import * as keysPBM from './keys.js'
import * as RSA from './rsa-class.js'
import * as Ed25519 from './ed25519-class.js'
import * as Secp256k1 from './secp256k1-class.js'

@@ -45,3 +45,3 @@ import type { PrivateKey, PublicKey } from '@libp2p/interface-keys'

export async function generateKeyPair (type: KeyTypes, bits?: number): Promise<PrivateKey> { // eslint-disable-line require-await
return await typeToKey(type).generateKeyPair(bits ?? 2048)
return typeToKey(type).generateKeyPair(bits ?? 2048)
}

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

return await Ed25519.generateKeyPairFromSeed(seed)
return Ed25519.generateKeyPairFromSeed(seed)
}

@@ -93,3 +93,3 @@

case keysPBM.KeyType.RSA:
return await supportedKeys.rsa.unmarshalRsaPrivateKey(data)
return supportedKeys.rsa.unmarshalRsaPrivateKey(data)
case keysPBM.KeyType.Ed25519:

@@ -131,3 +131,3 @@ return supportedKeys.ed25519.unmarshalEd25519PrivateKey(data)

der = uint8ArrayFromString(der.getBytes(), 'ascii')
return await supportedKeys.rsa.unmarshalRsaPrivateKey(der)
return supportedKeys.rsa.unmarshalRsaPrivateKey(der)
}

@@ -0,8 +1,8 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import randomBytes from '../random-bytes.js'
import webcrypto from '../webcrypto.js'
import randomBytes from '../random-bytes.js'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { jwk2pub, jwk2priv } from './jwk2pem.js'
import * as utils from './rsa-utils.js'
import { jwk2pub, jwk2priv } from './jwk2pem.js'
import { CodeError } from '@libp2p/interfaces/errors'
import type { JWKKeyPair } from './interface.js'

@@ -96,3 +96,3 @@

return await webcrypto.get().subtle.verify(
return webcrypto.get().subtle.verify(
{ name: 'RSASSA-PKCS1-v1_5' },

@@ -110,3 +110,3 @@ publicKey,

return await Promise.all([
return Promise.all([
webcrypto.get().subtle.exportKey('jwk', pair.privateKey),

@@ -118,3 +118,3 @@ webcrypto.get().subtle.exportKey('jwk', pair.publicKey)

async function derivePublicFromPrivate (jwKey: JsonWebKey): Promise<CryptoKey> {
return await webcrypto.get().subtle.importKey(
return webcrypto.get().subtle.importKey(
'jwk',

@@ -121,0 +121,0 @@ {

import { CodeError } from '@libp2p/interfaces/errors'
import { sha256 } from 'multiformats/hashes/sha2'
import { CodeError } from '@libp2p/interfaces/errors'
// @ts-expect-error types are missing
import forge from 'node-forge/lib/forge.js'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import 'node-forge/lib/sha512.js'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import 'node-forge/lib/sha512.js'
// @ts-expect-error types are missing
import forge from 'node-forge/lib/forge.js'
import { exporter } from './exporter.js'
import * as pbm from './keys.js'
import * as crypto from './rsa.js'
import * as pbm from './keys.js'
import { exporter } from './exporter.js'
import type { Multibase } from 'multiformats'

@@ -22,3 +22,3 @@

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

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

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

@@ -132,3 +132,3 @@

} else if (format === 'libp2p-key') {
return await exporter(this.bytes, password)
return exporter(this.bytes, password)
} else {

@@ -135,0 +135,0 @@ throw new CodeError(`export format '${format}' is not supported`, 'ERR_INVALID_EXPORT_FORMAT')

import 'node-forge/lib/asn1.js'
import 'node-forge/lib/rsa.js'
import { CodeError } from '@libp2p/interfaces/errors'
// @ts-expect-error types are missing
import forge from 'node-forge/lib/forge.js'
import { bigIntegerToUintBase64url, base64urlToBigInteger } from './../util.js'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { CodeError } from '@libp2p/interfaces/errors'
import { bigIntegerToUintBase64url, base64urlToBigInteger } from './../util.js'

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

@@ -0,8 +1,8 @@

import { CodeError } from '@libp2p/interfaces/errors'
import { sha256 } from 'multiformats/hashes/sha2'
import { CodeError } from '@libp2p/interfaces/errors'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import * as crypto from './secp256k1.js'
import { exporter } from './exporter.js'
import * as keysProtobuf from './keys.js'
import * as crypto from './secp256k1.js'
import type { Multibase } from 'multiformats'

@@ -19,3 +19,3 @@

async verify (data: Uint8Array, sig: Uint8Array): Promise<boolean> {
return await crypto.hashAndVerify(this._key, sig, data)
return crypto.hashAndVerify(this._key, sig, data)
}

@@ -57,3 +57,3 @@

async sign (message: Uint8Array): Promise<Uint8Array> {
return await crypto.hashAndSign(this._key, message)
return crypto.hashAndSign(this._key, message)
}

@@ -103,3 +103,3 @@

if (format === 'libp2p-key') {
return await exporter(this.bytes, password)
return exporter(this.bytes, password)
} else {

@@ -106,0 +106,0 @@ throw new CodeError(`export format '${format}' is not supported`, 'ERR_INVALID_EXPORT_FORMAT')

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

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

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

import forgeUtil from 'node-forge/lib/util.js'
import { CodeError } from '@libp2p/interfaces/errors'

@@ -8,0 +8,0 @@ /**

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

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

@@ -4,0 +4,0 @@ export default function randomBytes (length: number): Uint8Array {

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

import forge from 'node-forge/lib/forge.js'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'

@@ -10,0 +10,0 @@ export function bigIntegerToUintBase64url (num: { abs: () => any }, len?: number): string {

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

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