@libp2p/crypto
Advanced tools
Comparing version 2.0.1 to 2.0.2-123ded59
@@ -1,2 +0,2 @@ | ||
import * as ed from '@noble/ed25519'; | ||
import { ed25519 as ed } from '@noble/curves/ed25519'; | ||
const PUBLIC_KEY_BYTE_LENGTH = 32; | ||
@@ -10,3 +10,3 @@ const PRIVATE_KEY_BYTE_LENGTH = 64; // private key is actually 32 bytes but for historical reasons we concat private and public keys | ||
const privateKeyRaw = ed.utils.randomPrivateKey(); | ||
const publicKey = await ed.getPublicKey(privateKeyRaw); | ||
const publicKey = ed.getPublicKey(privateKeyRaw); | ||
// concatenated the public key to the private key | ||
@@ -31,3 +31,3 @@ const privateKey = concatKeys(privateKeyRaw, publicKey); | ||
const privateKeyRaw = seed; | ||
const publicKey = await ed.getPublicKey(privateKeyRaw); | ||
const publicKey = ed.getPublicKey(privateKeyRaw); | ||
const privateKey = concatKeys(privateKeyRaw, publicKey); | ||
@@ -34,0 +34,0 @@ return { |
import { CodeError } from '@libp2p/interface/errors'; | ||
import * as secp from '@noble/secp256k1'; | ||
import { secp256k1 as secp } from '@noble/curves/secp256k1'; | ||
import { sha256 } from 'multiformats/hashes/sha2'; | ||
@@ -15,3 +15,4 @@ const PRIVATE_KEY_BYTE_LENGTH = 32; | ||
try { | ||
return await secp.sign(digest, key); | ||
const signature = secp.sign(digest, key); | ||
return signature.toDERRawBytes(); | ||
} | ||
@@ -35,7 +36,7 @@ catch (err) { | ||
export function compressPublicKey(key) { | ||
const point = secp.Point.fromHex(key).toRawBytes(true); | ||
const point = secp.ProjectivePoint.fromHex(key).toRawBytes(true); | ||
return point; | ||
} | ||
export function decompressPublicKey(key) { | ||
const point = secp.Point.fromHex(key).toRawBytes(false); | ||
const point = secp.ProjectivePoint.fromHex(key).toRawBytes(false); | ||
return point; | ||
@@ -53,3 +54,3 @@ } | ||
try { | ||
secp.Point.fromHex(key); | ||
secp.ProjectivePoint.fromHex(key); | ||
} | ||
@@ -56,0 +57,0 @@ catch (err) { |
import { CodeError } from '@libp2p/interface/errors'; | ||
import { utils } from '@noble/secp256k1'; | ||
import { randomBytes as randB } from '@noble/hashes/utils'; | ||
export default function randomBytes(length) { | ||
@@ -7,4 +7,4 @@ if (isNaN(length) || length <= 0) { | ||
} | ||
return utils.randomBytes(length); | ||
return randB(length); | ||
} | ||
//# sourceMappingURL=random-bytes.js.map |
{ | ||
"name": "@libp2p/crypto", | ||
"version": "2.0.1", | ||
"version": "2.0.2-123ded59", | ||
"description": "Crypto primitives for libp2p", | ||
@@ -88,5 +88,5 @@ "license": "Apache-2.0 OR MIT", | ||
"dependencies": { | ||
"@libp2p/interface": "^0.1.0", | ||
"@noble/ed25519": "^1.6.0", | ||
"@noble/secp256k1": "^1.5.4", | ||
"@libp2p/interface": "0.1.1-123ded59", | ||
"@noble/curves": "^1.1.0", | ||
"@noble/hashes": "^1.3.1", | ||
"multiformats": "^12.0.1", | ||
@@ -93,0 +93,0 @@ "node-forge": "^1.1.0", |
@@ -1,2 +0,2 @@ | ||
import * as ed from '@noble/ed25519' | ||
import { ed25519 as ed } from '@noble/curves/ed25519' | ||
import type { Uint8ArrayKeyPair } from './interface' | ||
@@ -14,3 +14,3 @@ | ||
const privateKeyRaw = ed.utils.randomPrivateKey() | ||
const publicKey = await ed.getPublicKey(privateKeyRaw) | ||
const publicKey = ed.getPublicKey(privateKeyRaw) | ||
@@ -38,3 +38,3 @@ // concatenated the public key to the private key | ||
const privateKeyRaw = seed | ||
const publicKey = await ed.getPublicKey(privateKeyRaw) | ||
const publicKey = ed.getPublicKey(privateKeyRaw) | ||
@@ -41,0 +41,0 @@ const privateKey = concatKeys(privateKeyRaw, publicKey) |
import { CodeError } from '@libp2p/interface/errors' | ||
import * as secp from '@noble/secp256k1' | ||
import { secp256k1 as secp } from '@noble/curves/secp256k1' | ||
import { sha256 } from 'multiformats/hashes/sha2' | ||
@@ -19,3 +19,4 @@ | ||
try { | ||
return await secp.sign(digest, key) | ||
const signature = secp.sign(digest, key) | ||
return signature.toDERRawBytes() | ||
} catch (err) { | ||
@@ -39,3 +40,3 @@ throw new CodeError(String(err), 'ERR_INVALID_INPUT') | ||
export function compressPublicKey (key: Uint8Array): Uint8Array { | ||
const point = secp.Point.fromHex(key).toRawBytes(true) | ||
const point = secp.ProjectivePoint.fromHex(key).toRawBytes(true) | ||
return point | ||
@@ -45,3 +46,3 @@ } | ||
export function decompressPublicKey (key: Uint8Array): Uint8Array { | ||
const point = secp.Point.fromHex(key).toRawBytes(false) | ||
const point = secp.ProjectivePoint.fromHex(key).toRawBytes(false) | ||
return point | ||
@@ -60,3 +61,3 @@ } | ||
try { | ||
secp.Point.fromHex(key) | ||
secp.ProjectivePoint.fromHex(key) | ||
} catch (err) { | ||
@@ -63,0 +64,0 @@ throw new CodeError(String(err), 'ERR_INVALID_PUBLIC_KEY') |
import { CodeError } from '@libp2p/interface/errors' | ||
import { utils } from '@noble/secp256k1' | ||
import { randomBytes as randB } from '@noble/hashes/utils' | ||
@@ -8,3 +8,3 @@ export default function randomBytes (length: number): Uint8Array { | ||
} | ||
return utils.randomBytes(length) | ||
return randB(length) | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
496061
4864
175
1
+ Added@noble/curves@^1.1.0
+ Added@noble/hashes@^1.3.1
+ Added@libp2p/interface@0.1.1-123ded59(transitive)
+ Added@noble/curves@1.7.0(transitive)
+ Added@noble/hashes@1.6.01.6.1(transitive)
- Removed@noble/ed25519@^1.6.0
- Removed@noble/secp256k1@^1.5.4
- Removed@libp2p/interface@0.1.6(transitive)
- Removed@noble/ed25519@1.7.3(transitive)
- Removed@noble/secp256k1@1.7.1(transitive)
- Removedrace-signal@1.1.0(transitive)