New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@peerbit/crypto

Package Overview
Dependencies
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@peerbit/crypto - npm Package Compare versions

Comparing version 2.3.1 to 2.3.2

dist/src/from.d.ts

11

dist/benchmark/peer-ids.js
import { deserialize, serialize } from "@dao-xyz/borsh";
import { peerIdFromBytes, peerIdFromKeys } from "@libp2p/peer-id";
import { createEd25519PeerId } from "@libp2p/peer-id-factory";
import { generateKeyPair } from "@libp2p/crypto/keys";
import { peerIdFromPublicKey } from "@libp2p/peer-id";
import B from "benchmark";

@@ -8,5 +8,6 @@ import { Ed25519Keypair, Ed25519PublicKey } from "../src/ed25519.js";

const keypair = await Ed25519Keypair.create();
const peerId = await createEd25519PeerId();
const peerIdPublicKey = await peerIdFromKeys(peerId.publicKey);
const peerId = await generateKeyPair("Ed25519");
const peerIdPublicKey = peerIdFromPublicKey(peerId.publicKey);
const suite = new B.Suite("ed25519");
// TODO this benchmark makes no sense to do anymore since libp2p 2.0.0. What we want to compare is the ser/der perform of libp2p peerid vs peerbit peerid
suite

@@ -20,3 +21,3 @@ .add("PublicSignKey", {

fn: () => {
peerIdFromBytes(peerIdPublicKey.toBytes());
peerIdFromPublicKey(peerIdPublicKey.publicKey);
},

@@ -23,0 +24,0 @@ })

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

import type { Ed25519PeerId, PeerId } from "@libp2p/interface";
import type { PeerId } from "@libp2p/interface";
import { Keypair, PrivateSignKey, PublicSignKey } from "./key.js";

@@ -13,3 +13,3 @@ import { PreHash } from "./prehash.js";

toString(): string;
toPeerId(): Promise<PeerId>;
toPeerId(): PeerId;
static fromPeerId(id: PeerId): Ed25519PublicKey;

@@ -25,3 +25,2 @@ }

keyObject: any;
static fromPeerID(id: PeerId): Ed25519PrivateKey;
}

@@ -39,7 +38,6 @@ export declare class Ed25519Keypair extends Keypair implements Identity {

equals(other: Keypair): boolean;
static fromPeerId(peerId: PeerId | Ed25519PeerId): Ed25519Keypair;
_privateKeyPublicKey: Uint8Array;
get privateKeyPublicKey(): Uint8Array;
toPeerId(): Promise<PeerId>;
toPeerId(): PeerId;
}
//# sourceMappingURL=ed25519.d.ts.map

@@ -12,4 +12,4 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

import { field, fixedArray, variant } from "@dao-xyz/borsh";
import { supportedKeys } from "@libp2p/crypto/keys";
import { peerIdFromKeys } from "@libp2p/peer-id";
import { publicKeyFromRaw } from "@libp2p/crypto/keys";
import { peerIdFromPublicKey } from "@libp2p/peer-id";
import sodium from "libsodium-wrappers";

@@ -43,3 +43,3 @@ import { concat, equals } from "uint8arrays";

toPeerId() {
return peerIdFromKeys(new supportedKeys["ed25519"].Ed25519PublicKey(this.publicKey).bytes);
return peerIdFromPublicKey(publicKeyFromRaw(this.publicKey));
}

@@ -64,3 +64,3 @@ /* Don't use keyobject for publicKeys becuse it takes longer time to derive it compare to verifying with sodium

return new Ed25519PublicKey_1({
publicKey: coerce(id.publicKey.slice(4)),
publicKey: coerce(id.publicKey.raw),
});

@@ -99,13 +99,2 @@ }

keyObject; // crypto.KeyObject;
static fromPeerID(id) {
if (!id.privateKey) {
throw new Error("Missing privateKey key");
}
if (id.type === "Ed25519") {
return new Ed25519PrivateKey_1({
privateKey: coerce(id.privateKey.slice(4, 36)),
});
}
throw new Error("Unsupported key type: " + id.type);
}
};

@@ -157,8 +146,2 @@ __decorate([

}
static fromPeerId(peerId) {
return new Ed25519Keypair_1({
privateKey: Ed25519PrivateKey.fromPeerID(peerId),
publicKey: Ed25519PublicKey.fromPeerId(peerId),
});
}
_privateKeyPublicKey; // length 64

@@ -173,4 +156,3 @@ get privateKeyPublicKey() {

toPeerId() {
return peerIdFromKeys(new supportedKeys["ed25519"].Ed25519PublicKey(this.publicKey.publicKey)
.bytes, new supportedKeys["ed25519"].Ed25519PrivateKey(this.privateKeyPublicKey, this.publicKey.publicKey).bytes);
return peerIdFromPublicKey(publicKeyFromRaw(this.publicKey.publicKey));
}

@@ -177,0 +159,0 @@ };

@@ -7,3 +7,3 @@ export * from "./key.js";

export * from "./encryption.js";
export * from "./peerid.js";
export * from "./from.js";
export * from "./utils.js";

@@ -14,4 +14,5 @@ export * from "./hash.js";

export * from "./signer.js";
export * from "./from.js";
declare const ready: Promise<void>;
export { ready };
//# sourceMappingURL=index.d.ts.map

@@ -8,3 +8,3 @@ import libsodium from "libsodium-wrappers";

export * from "./encryption.js";
export * from "./peerid.js";
export * from "./from.js";
export * from "./utils.js";

@@ -15,4 +15,5 @@ export * from "./hash.js";

export * from "./signer.js";
export * from "./from.js";
const ready = libsodium.ready;
export { ready };
//# sourceMappingURL=index.js.map

@@ -12,3 +12,3 @@ import { type PeerId } from "@libp2p/interface";

equals(other: Keypair): boolean;
toPeerId(): Promise<PeerId>;
toPeerId(): PeerId;
}

@@ -21,3 +21,3 @@ export interface PublicSignKey extends Key {

hashcode(): string;
toPeerId(): Promise<PeerId>;
toPeerId(): PeerId;
}

@@ -24,0 +24,0 @@ export interface PrivateSignKey extends Key {

@@ -18,3 +18,3 @@ import { type SignatureLike } from "@ethersproject/bytes";

toString(): string;
toPeerId(): Promise<PeerId>;
toPeerId(): PeerId;
static fromPeerId(id: PeerId): Secp256k1PublicKey;

@@ -29,3 +29,2 @@ }

toString(): string;
static from(id: PeerId): Secp256k1PrivateKey;
}

@@ -43,4 +42,3 @@ export declare class Secp256k1Keypair extends Keypair implements Identity {

equals(other: Keypair): boolean;
static fromPeerId(peerId: PeerId): Secp256k1Keypair;
toPeerId(): Promise<PeerId>;
toPeerId(): PeerId;
}

@@ -47,0 +45,0 @@ export declare const recoverPublicKeyFromSignature: (digest: Uint8Array, signature: SignatureLike) => Uint8Array;

@@ -14,9 +14,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

import { Wallet } from "@ethersproject/wallet";
import { generateKeyPair, supportedKeys } from "@libp2p/crypto/keys";
import { generateKeyPair, publicKeyFromRaw } from "@libp2p/crypto/keys";
import {} from "@libp2p/interface";
import { peerIdFromKeys } from "@libp2p/peer-id";
import { peerIdFromPublicKey } from "@libp2p/peer-id";
import utf8 from "@protobufjs/utf8";
import _ec from "elliptic";
import { equals } from "uint8arrays";
import { coerce } from "./bytes.js";
import { Keypair, PrivateSignKey, PublicSignKey } from "./key.js";

@@ -56,3 +55,3 @@ import { PreHash, prehashFn } from "./prehash.js";

toPeerId() {
return peerIdFromKeys(new supportedKeys["secp256k1"].Secp256k1PublicKey(this.publicKey).bytes);
return peerIdFromPublicKey(publicKeyFromRaw(this.publicKey));
}

@@ -65,3 +64,3 @@ static fromPeerId(id) {

return new Secp256k1PublicKey_1({
publicKey: id.publicKey.slice(4), // computeAddress(!.slice(4)),
publicKey: id.publicKey.raw,
});

@@ -99,13 +98,2 @@ }

}
static from(id) {
if (!id.privateKey) {
throw new Error("Missing privateKey key");
}
if (id.type === "secp256k1") {
return new Secp256k1PrivateKey_1({
privateKey: coerce(id.privateKey.slice(4)),
});
}
throw new Error("Unsupported key type: " + id.type);
}
};

@@ -134,6 +122,6 @@ __decorate([

publicKey: new Secp256k1PublicKey({
publicKey: generated.public.marshal(),
publicKey: generated.publicKey.raw,
}),
privateKey: new Secp256k1PrivateKey({
privateKey: generated.marshal(),
privateKey: generated.raw,
}),

@@ -163,10 +151,4 @@ });

}
static fromPeerId(peerId) {
return new Secp256k1Keypair_1({
privateKey: Secp256k1PrivateKey.from(peerId),
publicKey: Secp256k1PublicKey.fromPeerId(peerId),
});
}
toPeerId() {
return peerIdFromKeys(new supportedKeys["secp256k1"].Secp256k1PublicKey(this.publicKey.publicKey).bytes, new supportedKeys["secp256k1"].Secp256k1PrivateKey(this.privateKey.privateKey, this.publicKey.publicKey).bytes);
return peerIdFromPublicKey(publicKeyFromRaw(this.publicKey.publicKey));
}

@@ -173,0 +155,0 @@ };

@@ -36,5 +36,4 @@ import { type PeerId } from "@libp2p/interface";

static from(ed25119Keypair: Ed25519Keypair): Promise<X25519Keypair>;
static fromPeerId(peerId: PeerId): Promise<X25519Keypair>;
equals(other: Keypair): boolean;
}
//# sourceMappingURL=x25519.d.ts.map

@@ -137,6 +137,2 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

}
static fromPeerId(peerId) {
const ed = Ed25519Keypair.fromPeerId(peerId);
return X25519Keypair_1.from(ed);
}
equals(other) {

@@ -143,0 +139,0 @@ if (other instanceof X25519Keypair_1) {

{
"name": "@peerbit/crypto",
"version": "2.3.1",
"version": "2.3.2",
"description": "Crypto fn",

@@ -65,4 +65,4 @@ "sideEffects": false,

"devDependencies": {
"@types/libsodium-wrappers": "^0.7.10",
"uint8arrays": "^4.0.4",
"@types/libsodium-wrappers": "^0.7.14",
"uint8arrays": "^5.1.0",
"@types/elliptic": "^6.4.18",

@@ -76,6 +76,6 @@ "multiformats": "^13.1.0"

"@ethersproject/wallet": "^5.7.0",
"@libp2p/crypto": "^4.1.9",
"@libp2p/peer-id": "^4.2.4",
"libsodium-wrappers": "^0.7.14"
"@libp2p/crypto": "^5.0.5",
"@libp2p/peer-id": "^5.0.5",
"libsodium-wrappers": "^0.7.15"
}
}
import { field, fixedArray, variant } from "@dao-xyz/borsh";
import { supportedKeys } from "@libp2p/crypto/keys";
import type { Ed25519PeerId, PeerId } from "@libp2p/interface";
import { peerIdFromKeys } from "@libp2p/peer-id";
import { publicKeyFromRaw } from "@libp2p/crypto/keys";
import type { PeerId } from "@libp2p/interface";
import { peerIdFromPublicKey } from "@libp2p/peer-id";
import sodium from "libsodium-wrappers";

@@ -39,6 +39,4 @@ import { concat, equals } from "uint8arrays";

toPeerId(): Promise<PeerId> {
return peerIdFromKeys(
new supportedKeys["ed25519"].Ed25519PublicKey(this.publicKey).bytes,
);
toPeerId(): PeerId {
return peerIdFromPublicKey(publicKeyFromRaw(this.publicKey));
}

@@ -64,3 +62,3 @@

return new Ed25519PublicKey({
publicKey: coerce(id.publicKey.slice(4)),
publicKey: coerce(id.publicKey.raw),
});

@@ -99,14 +97,2 @@ }

keyObject: any; // crypto.KeyObject;
static fromPeerID(id: PeerId) {
if (!id.privateKey) {
throw new Error("Missing privateKey key");
}
if (id.type === "Ed25519") {
return new Ed25519PrivateKey({
privateKey: coerce(id.privateKey.slice(4, 36)),
});
}
throw new Error("Unsupported key type: " + id.type);
}
}

@@ -169,9 +155,2 @@

static fromPeerId(peerId: PeerId | Ed25519PeerId) {
return new Ed25519Keypair({
privateKey: Ed25519PrivateKey.fromPeerID(peerId),
publicKey: Ed25519PublicKey.fromPeerId(peerId),
});
}
_privateKeyPublicKey!: Uint8Array; // length 64

@@ -188,12 +167,5 @@ get privateKeyPublicKey(): Uint8Array {

toPeerId(): Promise<PeerId> {
return peerIdFromKeys(
new supportedKeys["ed25519"].Ed25519PublicKey(this.publicKey.publicKey)
.bytes,
new supportedKeys["ed25519"].Ed25519PrivateKey(
this.privateKeyPublicKey,
this.publicKey.publicKey,
).bytes,
);
toPeerId(): PeerId {
return peerIdFromPublicKey(publicKeyFromRaw(this.publicKey.publicKey));
}
}

@@ -9,3 +9,3 @@ import libsodium from "libsodium-wrappers";

export * from "./encryption.js";
export * from "./peerid.js";
export * from "./from.js";
export * from "./utils.js";

@@ -16,4 +16,5 @@ export * from "./hash.js";

export * from "./signer.js";
export * from "./from.js";
const ready = libsodium.ready;
export { ready };

@@ -22,3 +22,3 @@ import { field, serialize } from "@dao-xyz/borsh";

toPeerId(): Promise<PeerId> {
toPeerId(): PeerId {
throw new Error("Not implemented");

@@ -43,3 +43,3 @@ }

toPeerId(): Promise<PeerId> {
toPeerId(): PeerId {
throw new Error("Not implemented");

@@ -46,0 +46,0 @@ }

@@ -9,9 +9,8 @@ import { field, fixedArray, variant } from "@dao-xyz/borsh";

import { Wallet } from "@ethersproject/wallet";
import { generateKeyPair, supportedKeys } from "@libp2p/crypto/keys";
import { generateKeyPair, publicKeyFromRaw } from "@libp2p/crypto/keys";
import { type PeerId } from "@libp2p/interface";
import { peerIdFromKeys } from "@libp2p/peer-id";
import { peerIdFromPublicKey } from "@libp2p/peer-id";
import utf8 from "@protobufjs/utf8";
import _ec from "elliptic";
import { equals } from "uint8arrays";
import { coerce } from "./bytes.js";
import { Keypair, PrivateSignKey, PublicSignKey } from "./key.js";

@@ -66,6 +65,4 @@ import { PreHash, prehashFn } from "./prehash.js";

toPeerId(): Promise<PeerId> {
return peerIdFromKeys(
new supportedKeys["secp256k1"].Secp256k1PublicKey(this.publicKey).bytes,
);
toPeerId(): PeerId {
return peerIdFromPublicKey(publicKeyFromRaw(this.publicKey));
}

@@ -79,3 +76,3 @@

return new Secp256k1PublicKey({
publicKey: id.publicKey.slice(4), // computeAddress(!.slice(4)),
publicKey: id.publicKey.raw,
});

@@ -111,14 +108,2 @@ }

}
static from(id: PeerId) {
if (!id.privateKey) {
throw new Error("Missing privateKey key");
}
if (id.type === "secp256k1") {
return new Secp256k1PrivateKey({
privateKey: coerce(id.privateKey.slice(4)),
});
}
throw new Error("Unsupported key type: " + id.type);
}
}

@@ -148,6 +133,6 @@

publicKey: new Secp256k1PublicKey({
publicKey: generated.public.marshal(),
publicKey: generated.publicKey.raw,
}),
privateKey: new Secp256k1PrivateKey({
privateKey: generated.marshal(),
privateKey: generated.raw,
}),

@@ -190,20 +175,5 @@ });

static fromPeerId(peerId: PeerId) {
return new Secp256k1Keypair({
privateKey: Secp256k1PrivateKey.from(peerId),
publicKey: Secp256k1PublicKey.fromPeerId(peerId),
});
toPeerId(): PeerId {
return peerIdFromPublicKey(publicKeyFromRaw(this.publicKey.publicKey));
}
toPeerId(): Promise<PeerId> {
return peerIdFromKeys(
new supportedKeys["secp256k1"].Secp256k1PublicKey(
this.publicKey.publicKey,
).bytes,
new supportedKeys["secp256k1"].Secp256k1PrivateKey(
this.privateKey.privateKey,
this.publicKey.publicKey,
).bytes,
);
}
}

@@ -210,0 +180,0 @@

@@ -151,7 +151,2 @@ import { field, fixedArray, variant } from "@dao-xyz/borsh";

static fromPeerId(peerId: PeerId) {
const ed = Ed25519Keypair.fromPeerId(peerId);
return X25519Keypair.from(ed);
}
equals(other: Keypair) {

@@ -158,0 +153,0 @@ if (other instanceof X25519Keypair) {

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