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

@chainsafe/bls

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chainsafe/bls - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

CHANGELOG.md

2

lib/helpers/utils.d.ts

@@ -8,4 +8,4 @@ /// <reference types="node" />

*/
export declare function padLeft(source: Buffer, length: number): Buffer;
export declare function padLeft(source: Uint8Array, length: number): Buffer;
export declare const EMPTY_PUBLIC_KEY: Buffer;
export declare const EMPTY_SIGNATURE: Buffer;

@@ -24,3 +24,3 @@ "use strict";

const result = Buffer.alloc(length, 0);
source.copy(result, length - source.length);
result.set(source, length - source.length);
return result;

@@ -27,0 +27,0 @@ }

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

/// <reference types="node" />
import { Keypair } from "./keypair";

@@ -5,3 +6,2 @@ import { PrivateKey } from "./privateKey";

import { Signature } from "./signature";
import { BLSPubkey, BLSSecretKey, BLSSignature, Domain, bytes32 } from "@chainsafe/eth2.0-types";
export { Keypair, PrivateKey, PublicKey, Signature };

@@ -17,3 +17,3 @@ export { init as initBLS } from "./context";

*/
export declare function generatePublicKey(secretKey: BLSSecretKey): BLSPubkey;
export declare function generatePublicKey(secretKey: Uint8Array): Buffer;
/**

@@ -25,3 +25,3 @@ * Signs given message using secret key.

*/
export declare function sign(secretKey: BLSSecretKey, messageHash: bytes32, domain: Domain): BLSSignature;
export declare function sign(secretKey: Uint8Array, messageHash: Uint8Array, domain: Uint8Array): Buffer;
/**

@@ -31,3 +31,3 @@ * Compines all given signature into one.

*/
export declare function aggregateSignatures(signatures: BLSSignature[]): BLSSignature;
export declare function aggregateSignatures(signatures: Uint8Array[]): Buffer;
/**

@@ -37,3 +37,3 @@ * Combines all given public keys into single one

*/
export declare function aggregatePubkeys(publicKeys: BLSPubkey[]): BLSPubkey;
export declare function aggregatePubkeys(publicKeys: Uint8Array[]): Buffer;
/**

@@ -46,3 +46,3 @@ * Verifies if signature is message signed with given public key.

*/
export declare function verify(publicKey: BLSPubkey, messageHash: bytes32, signature: BLSSignature, domain: Domain): boolean;
export declare function verify(publicKey: Uint8Array, messageHash: Uint8Array, signature: Uint8Array, domain: Uint8Array): boolean;
/**

@@ -55,3 +55,3 @@ * Verifies if signature is list of message signed with corresponding public key.

*/
export declare function verifyMultiple(publicKeys: BLSPubkey[], messageHashes: bytes32[], signature: BLSSignature, domain: Domain): boolean;
export declare function verifyMultiple(publicKeys: Uint8Array[], messageHashes: Uint8Array[], signature: Uint8Array, domain: Uint8Array): boolean;
declare const _default: {

@@ -58,0 +58,0 @@ generateKeyPair: typeof generateKeyPair;

@@ -61,5 +61,10 @@ "use strict";

function toBuffer(input) {
return Buffer.from(input.buffer, input.byteOffset, input.length);
}
/**
* Generates new secret and public key
*/
function generateKeyPair() {

@@ -76,3 +81,3 @@ return _keypair.Keypair.generate();

(0, _assert.default)(secretKey, "secretKey is null or undefined");
const keypair = new _keypair.Keypair(_privateKey.PrivateKey.fromBytes(secretKey));
const keypair = new _keypair.Keypair(_privateKey.PrivateKey.fromBytes(toBuffer(secretKey)));
return keypair.publicKey.toBytesCompressed();

@@ -93,5 +98,5 @@ }

const privateKey = _privateKey.PrivateKey.fromBytes(secretKey);
const privateKey = _privateKey.PrivateKey.fromBytes(toBuffer(secretKey));
return privateKey.signMessage(messageHash, domain).toBytesCompressed();
return privateKey.signMessage(toBuffer(messageHash), toBuffer(domain)).toBytesCompressed();
}

@@ -107,3 +112,3 @@ /**

return signatures.map(signature => {
return _signature.Signature.fromCompressedBytes(signature);
return _signature.Signature.fromCompressedBytes(toBuffer(signature));
}).reduce((previousValue, currentValue) => {

@@ -126,9 +131,3 @@ return previousValue.add(currentValue);

return publicKeys.map(_publicKey.PublicKey.fromBytes).reduce((agg, pubKey) => {
if (agg) {
return agg.add(pubKey);
} else {
return pubKey;
}
}).toBytesCompressed();
return publicKeys.map(p => _publicKey.PublicKey.fromBytes(toBuffer(p))).reduce((agg, pubKey) => agg.add(pubKey)).toBytesCompressed();
}

@@ -151,3 +150,3 @@ /**

try {
return _publicKey.PublicKey.fromBytes(publicKey).verifyMessage(_signature.Signature.fromCompressedBytes(signature), messageHash, domain);
return _publicKey.PublicKey.fromBytes(toBuffer(publicKey)).verifyMessage(_signature.Signature.fromCompressedBytes(toBuffer(signature)), toBuffer(messageHash), toBuffer(domain));
} catch (e) {

@@ -177,3 +176,3 @@ return false;

try {
return _signature.Signature.fromCompressedBytes(signature).verifyMultiple(publicKeys.map(key => _publicKey.PublicKey.fromBytes(key)), messageHashes, domain);
return _signature.Signature.fromCompressedBytes(toBuffer(signature)).verifyMultiple(publicKeys.map(key => _publicKey.PublicKey.fromBytes(toBuffer(key))), messageHashes.map(m => toBuffer(m)), toBuffer(domain));
} catch (e) {

@@ -180,0 +179,0 @@ return false;

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

import { BLSSecretKey, Domain, bytes32 } from "@chainsafe/eth2.0-types";
/// <reference types="node" />
import { SecretKeyType } from "@chainsafe/eth2-bls-wasm";

@@ -13,6 +13,6 @@ import { PublicKey } from "./publicKey";

getValue(): SecretKeyType;
signMessage(message: bytes32, domain: Domain): Signature;
signMessage(message: Uint8Array, domain: Uint8Array): Signature;
toPublicKey(): PublicKey;
toBytes(): BLSSecretKey;
toBytes(): Buffer;
toHexString(): string;
}

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

/// <reference types="node" />
import { PrivateKey } from "./privateKey";
import { BLSPubkey, Domain, bytes32 } from "@chainsafe/eth2.0-types";
import { PublicKeyType } from "@chainsafe/eth2-bls-wasm";

@@ -9,10 +9,10 @@ import { Signature } from "./signature";

static fromPrivateKey(privateKey: PrivateKey): PublicKey;
static fromBytes(bytes: BLSPubkey): PublicKey;
static fromBytes(bytes: Uint8Array): PublicKey;
static fromHex(value: string): PublicKey;
static fromPublicKeyType(value: PublicKeyType): PublicKey;
add(other: PublicKey): PublicKey;
verifyMessage(signature: Signature, messageHash: bytes32, domain: Domain): boolean;
toBytesCompressed(): BLSPubkey;
verifyMessage(signature: Signature, messageHash: Uint8Array, domain: Uint8Array): boolean;
toBytesCompressed(): Buffer;
toHexString(): string;
getValue(): PublicKeyType;
}

@@ -35,3 +35,3 @@ "use strict";

if (!bytes.equals(_utils.EMPTY_PUBLIC_KEY)) {
if (!_utils.EMPTY_PUBLIC_KEY.equals(bytes)) {
publicKey.deserialize(bytes);

@@ -38,0 +38,0 @@ }

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

import { BLSSignature, Domain, bytes32 } from "@chainsafe/eth2.0-types";
/// <reference types="node" />
import { SignatureType } from "@chainsafe/eth2-bls-wasm";

@@ -7,10 +7,10 @@ import { PublicKey } from "./publicKey";

protected constructor(value: SignatureType);
static fromCompressedBytes(value: BLSSignature): Signature;
static fromCompressedBytes(value: Uint8Array): Signature;
static fromValue(signature: SignatureType): Signature;
add(other: Signature): Signature;
getValue(): SignatureType;
verify(publicKey: PublicKey, message: bytes32, domain: Domain): boolean;
verifyMultiple(publicKeys: PublicKey[], messages: bytes32[], domain: Domain): boolean;
toBytesCompressed(): BLSSignature;
verify(publicKey: PublicKey, message: Uint8Array, domain: Uint8Array): boolean;
verifyMultiple(publicKeys: PublicKey[], messages: Uint8Array[], domain: Uint8Array): boolean;
toBytesCompressed(): Buffer;
toHex(): string;
}

@@ -32,3 +32,3 @@ "use strict";

if (!value.equals(_utils.EMPTY_SIGNATURE)) {
if (!_utils.EMPTY_SIGNATURE.equals(value)) {
signature.deserialize(value);

@@ -35,0 +35,0 @@ }

{
"name": "@chainsafe/bls",
"version": "0.2.2",
"version": "0.3.0",
"description": "Implementation of bls signature verification for ethereum 2.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"homepage": "https://github.com/chainsafe/lodestar",
"homepage": "https://github.com/chainsafe/bls",
"author": "ChainSafe Systems",

@@ -26,3 +26,3 @@ "license": "Apache-2.0",

"build-lib": "babel src -x .ts -d lib",
"build-types": "tsc --declaration --project tsconfig.build.json --incremental --outDir lib --emitDeclarationOnly",
"build-types": "tsc --declaration --incremental --outDir lib --emitDeclarationOnly",
"build-web": "webpack --mode production --entry ./lib/web.js --output ./dist/bls.min.js",

@@ -44,9 +44,21 @@ "check-types": "tsc --noEmit",

"@chainsafe/eth2-bls-wasm": "^0.2.1",
"@chainsafe/eth2.0-types": "^0.2.1",
"assert": "^1.4.1"
},
"devDependencies": {
"@chainsafe/benchmark-utils": "^0.1.0",
"js-sha256": "^0.9.0",
"js-yaml": "^3.13.1",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/preset-typescript": "^7.8.3",
"@babel/register": "^7.8.3",
"@chainsafe/as-sha256": "^0.2.0",
"@types/chai": "^4.2.9",
"@types/mocha": "^7.0.1",
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint-plugin-import": "^2.20.1",
"karma": "^4.4.1",

@@ -59,3 +71,7 @@ "karma-chai": "^0.1.0",

"karma-webpack": "^4.0.2",
"mocha": "^7.0.1",
"nyc": "^15.0.0",
"ts-loader": "^6.2.1",
"ts-node": "^8.6.2",
"typescript": "^3.7.5",
"webpack": "^4.30.0",

@@ -62,0 +78,0 @@ "webpack-cli": "^3.3.2"

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