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

@zilliqa-js/crypto

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zilliqa-js/crypto - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1-next.20181109

README.md

2

dist/schnorr.d.ts
/// <reference types="node" />
import BN from 'bn.js';
import DRBG from 'hmac-drbg';
import Signature from './signature';
import { Signature } from './signature';
/**

@@ -6,0 +6,0 @@ * Hash (r | M).

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

var hmac_drbg_1 = tslib_1.__importDefault(require("hmac-drbg"));
var signature_1 = tslib_1.__importDefault(require("./signature"));
var signature_1 = require("./signature");
var curve = elliptic_1.default.ec('secp256k1').curve;

@@ -68,12 +68,16 @@ // Public key is a point (x, y) on the curve.

exports.trySign = function (msg, prv, k, pubKey) {
if (prv.isZero())
if (prv.isZero()) {
throw new Error('Bad private key.');
if (prv.gte(curve.n))
}
if (prv.gte(curve.n)) {
throw new Error('Bad private key.');
}
// 1a. check that k is not 0
if (k.isZero())
if (k.isZero()) {
return null;
}
// 1b. check that k is < the order of the group
if (k.gte(curve.n))
if (k.gte(curve.n)) {
return null;
}
// 2. Compute commitment Q = kG, where g is the base point

@@ -86,6 +90,8 @@ var Q = curve.g.mul(k);

var h = r.clone();
if (h.isZero())
if (h.isZero()) {
return null;
if (h.eq(curve.n))
}
if (h.eq(curve.n)) {
return null;
}
// 4. Compute s = k - r * prv

@@ -97,5 +103,6 @@ // 4a. Compute r * prv

s = s.umod(curve.n);
if (s.isZero())
if (s.isZero()) {
return null;
return new signature_1.default({ r: r, s: s });
}
return new signature_1.Signature({ r: r, s: s });
};

@@ -118,7 +125,9 @@ /**

exports.verify = function (msg, signature, key) {
var sig = new signature_1.default(signature);
if (sig.s.gte(curve.n))
var sig = new signature_1.Signature(signature);
if (sig.s.gte(curve.n)) {
throw new Error('Invalid S value.');
if (sig.r.gt(curve.n))
}
if (sig.r.gt(curve.n)) {
throw new Error('Invalid R value.');
}
var kpub = curve.decodePoint(key);

@@ -130,6 +139,8 @@ var l = kpub.mul(sig.r);

var r1 = exports.hash(compressedQ, key, msg);
if (r1.gte(curve.n))
if (r1.gte(curve.n)) {
throw new Error('Invalid hash.');
if (r1.isZero())
}
if (r1.isZero()) {
throw new Error('Invalid hash.');
}
return r1.eq(sig.r);

@@ -140,3 +151,3 @@ };

var s = serialised.slice(64);
return new signature_1.default({ r: r, s: s });
return new signature_1.Signature({ r: r, s: s });
};

@@ -143,0 +154,0 @@ /**

@@ -15,3 +15,3 @@ import BN from 'bn.js';

}
export default class Signature {
export declare class Signature {
r: BN;

@@ -18,0 +18,0 @@ s: BN;

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

}());
exports.default = Signature;
exports.Signature = Signature;
//# sourceMappingURL=signature.js.map
export declare type KDF = 'pbkdf2' | 'scrypt';
export declare type PBKDF2Params = {
export interface PBKDF2Params {
salt: string;
dklen: number;
c: number;
};
export declare type ScryptParams = {
}
export interface ScryptParams {
salt: string;

@@ -13,3 +13,3 @@ dklen: number;

p: number;
};
}
export declare type KDFParams = PBKDF2Params | ScryptParams;

@@ -16,0 +16,0 @@ export interface KeystoreV3 {

@@ -6,3 +6,2 @@ "use strict";

var hash_js_1 = tslib_1.__importDefault(require("hash.js"));
var NUM_BYTES = 32;
var secp256k1 = elliptic_1.default.ec('secp256k1');

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

{
"name": "@zilliqa-js/crypto",
"version": "0.2.0",
"version": "0.2.1-next.20181109",
"description": "Core crypto utilities for signing/verification/hashing Zilliqa transactions.",
"main": "dist/index.js",
"node": "dist/index.js",
"main": "dist/index.umd.js",
"node": "dist/index.umd.js",
"browser": "dist/index.umd.js",

@@ -21,3 +21,3 @@ "module": "dist/index.esm.js",

"dependencies": {
"@zilliqa-js/util": "^0.2.0",
"@zilliqa-js/util": "^0.2.1-next.20181109",
"aes-js": "^3.1.1",

@@ -34,3 +34,3 @@ "bn.js": "^4.11.8",

},
"gitHead": "c1a04e0c11848b02233410c7f1e09e00db1efd26"
"gitHead": "f2d8ea7d5bc9fccde5975defd69a230eeadf092d"
}

@@ -6,3 +6,3 @@ import assert from 'bsert';

import DRBG from 'hmac-drbg';
import Signature from './signature';
import { Signature } from './signature';

@@ -79,10 +79,18 @@ const curve = elliptic.ec('secp256k1').curve;

): Signature | null => {
if (prv.isZero()) throw new Error('Bad private key.');
if (prv.isZero()) {
throw new Error('Bad private key.');
}
if (prv.gte(curve.n)) throw new Error('Bad private key.');
if (prv.gte(curve.n)) {
throw new Error('Bad private key.');
}
// 1a. check that k is not 0
if (k.isZero()) return null;
if (k.isZero()) {
return null;
}
// 1b. check that k is < the order of the group
if (k.gte(curve.n)) return null;
if (k.gte(curve.n)) {
return null;
}

@@ -98,5 +106,9 @@ // 2. Compute commitment Q = kG, where g is the base point

if (h.isZero()) return null;
if (h.isZero()) {
return null;
}
if (h.eq(curve.n)) return null;
if (h.eq(curve.n)) {
return null;
}

@@ -110,3 +122,5 @@ // 4. Compute s = k - r * prv

if (s.isZero()) return null;
if (s.isZero()) {
return null;
}

@@ -134,5 +148,9 @@ return new Signature({ r, s });

if (sig.s.gte(curve.n)) throw new Error('Invalid S value.');
if (sig.s.gte(curve.n)) {
throw new Error('Invalid S value.');
}
if (sig.r.gt(curve.n)) throw new Error('Invalid R value.');
if (sig.r.gt(curve.n)) {
throw new Error('Invalid R value.');
}

@@ -148,5 +166,9 @@ const kpub = curve.decodePoint(key);

if (r1.gte(curve.n)) throw new Error('Invalid hash.');
if (r1.gte(curve.n)) {
throw new Error('Invalid hash.');
}
if (r1.isZero()) throw new Error('Invalid hash.');
if (r1.isZero()) {
throw new Error('Invalid hash.');
}

@@ -153,0 +175,0 @@ return r1.eq(sig.r);

@@ -17,3 +17,3 @@ import BN from 'bn.js';

export default class Signature {
export class Signature {
r: BN;

@@ -20,0 +20,0 @@ s: BN;

export type KDF = 'pbkdf2' | 'scrypt';
export type PBKDF2Params = {
export interface PBKDF2Params {
salt: string;
dklen: number;
c: number;
};
}
export type ScryptParams = {
export interface ScryptParams {
salt: string;

@@ -15,3 +15,3 @@ dklen: number;

p: number;
};
}

@@ -18,0 +18,0 @@ export type KDFParams = PBKDF2Params | ScryptParams;

import elliptic from 'elliptic';
import hashjs from 'hash.js';
import { randomBytes } from './random';
import * as schnorr from './schnorr';
const NUM_BYTES = 32;
const secp256k1 = elliptic.ec('secp256k1');

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

@@ -8,5 +8,4 @@ import BN from 'bn.js';

import * as crypto from '../src/index';
import * as schnorr from '../src/schnorr';
import Signature from '../src/signature';
import { Signature } from '../src/signature';

@@ -13,0 +12,0 @@ const secp256k1 = elliptic.ec('secp256k1');

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

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