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

@zilliqa-js/crypto

Package Overview
Dependencies
Maintainers
3
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 3.0.0 to 3.1.0

4

dist/bech32.js

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.fromBech32Address = exports.toBech32Address = exports.convertBits = exports.HRP = exports.decode = exports.encode = void 0;
var util_1 = require("@zilliqa-js/util");

@@ -46,3 +47,2 @@ var util_2 = require("./util");

var chk = 1;
// tslint:disable-next-line
for (var p = 0; p < values.length; ++p) {

@@ -91,3 +91,2 @@ var top_1 = chk >> 25;

var ret = hrp + '1';
// tslint:disable-next-line
for (var p = 0; p < combined.length; ++p) {

@@ -158,3 +157,2 @@ ret += CHARSET.charAt(combined[p]);

var maxv = (1 << toWidth) - 1;
// tslint:disable-next-line
for (var p = 0; p < data.length; ++p) {

@@ -161,0 +159,0 @@ var value = data[p];

@@ -36,17 +36,33 @@ import { BN, validation, bytes } from '@zilliqa-js/util';

var randomBytes = function (bytes$$1) {
var randBz;
if (typeof window !== 'undefined' &&
window.crypto &&
window.crypto.getRandomValues) {
randBz = window.crypto.getRandomValues(new Uint8Array(bytes$$1));
var _a;
var b = Buffer.allocUnsafe(bytes$$1);
var n = b.byteLength;
var crypto = global.crypto;
if (crypto === undefined) {
// @ts-ignore
// for IE 11
crypto = global.msCrypto;
}
else if (typeof require !== 'undefined') {
var b = Buffer.allocUnsafe(bytes$$1);
var isNodeEnv = typeof ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) === 'string';
if (isNodeEnv) {
// For node enviroment, use sodium-native
// https://paragonie.com/blog/2016/05/how-generate-secure-random-numbers-in-various-programming-languages#nodejs-csprng
var sodium = require('sodium-native');
sodium.randombytes_buf(b);
randBz = new Uint8Array(b.buffer, b.byteOffset, b.byteLength / Uint8Array.BYTES_PER_ELEMENT);
}
else if (crypto && crypto.getRandomValues) {
// For browser or web worker enviroment, use window.crypto.getRandomValues()
// https://paragonie.com/blog/2016/05/how-generate-secure-random-numbers-in-various-programming-languages#js-csprng
// limit of getRandomValues()
// The requested length exceeds 65536 bytes.
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues#exceptions
var MAX_BYTES = 65536;
for (var i = 0; i < n; i += MAX_BYTES) {
crypto.getRandomValues(new Uint8Array(b.buffer, i + b.byteOffset, Math.min(n - i, MAX_BYTES)));
}
}
else {
throw new Error('Unable to generate safe random numbers.');
throw new Error('No secure random number generator available');
}
var randBz = new Uint8Array(b.buffer, b.byteOffset, b.byteLength / Uint8Array.BYTES_PER_ELEMENT);
var randStr = '';

@@ -285,3 +301,2 @@ for (var i = 0; i < bytes$$1; i++) {

var chk = 1;
// tslint:disable-next-line
for (var p = 0; p < values.length; ++p) {

@@ -330,3 +345,2 @@ var top_1 = chk >> 25;

var ret = hrp + '1';
// tslint:disable-next-line
for (var p = 0; p < combined.length; ++p) {

@@ -397,3 +411,2 @@ ret += CHARSET.charAt(combined[p]);

var maxv = (1 << toWidth) - 1;
// tslint:disable-next-line
for (var p = 0; p < data.length; ++p) {

@@ -481,7 +494,3 @@ var value = data[p];

var pub = keyPair.getPublic(true, 'hex');
return toChecksumAddress(hashjs
.sha256()
.update(pub, 'hex')
.digest('hex')
.slice(24));
return toChecksumAddress(hashjs.sha256().update(pub, 'hex').digest('hex').slice(24));
};

@@ -567,7 +576,3 @@ /**

var normalized = publicKey.toLowerCase().replace('0x', '');
return toChecksumAddress(hashjs
.sha256()
.update(normalized, 'hex')
.digest('hex')
.slice(24));
return toChecksumAddress(hashjs.sha256().update(normalized, 'hex').digest('hex').slice(24));
};

@@ -587,6 +592,3 @@ /**

address = address.toLowerCase().replace('0x', '');
var hash = hashjs
.sha256()
.update(address, 'hex')
.digest('hex');
var hash = hashjs.sha256().update(address, 'hex').digest('hex');
var v = new BN(hash, 'hex', 'be');

@@ -741,21 +743,22 @@ var ret = '0x';

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -930,2 +933,19 @@ });

// Copyright (C) 2018 Zilliqa
//
// This file is part of Zilliqa-Javascript-Library.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// Copyright (C) 2018 Zilliqa
/**

@@ -932,0 +952,0 @@ * sign

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.schnorr = exports.sign = void 0;
var tslib_1 = require("tslib");

@@ -45,4 +46,5 @@ var schnorr = tslib_1.__importStar(require("./schnorr"));

tslib_1.__exportStar(require("./random"), exports);
tslib_1.__exportStar(require("./types"), exports);
tslib_1.__exportStar(require("./signature"), exports);
tslib_1.__exportStar(require("./bech32"), exports);
//# sourceMappingURL=index.js.map

@@ -40,17 +40,33 @@ (function (global, factory) {

var randomBytes = function (bytes) {
var randBz;
if (typeof window !== 'undefined' &&
window.crypto &&
window.crypto.getRandomValues) {
randBz = window.crypto.getRandomValues(new Uint8Array(bytes));
var _a;
var b = Buffer.allocUnsafe(bytes);
var n = b.byteLength;
var crypto = global.crypto;
if (crypto === undefined) {
// @ts-ignore
// for IE 11
crypto = global.msCrypto;
}
else if (typeof require !== 'undefined') {
var b = Buffer.allocUnsafe(bytes);
var isNodeEnv = typeof ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) === 'string';
if (isNodeEnv) {
// For node enviroment, use sodium-native
// https://paragonie.com/blog/2016/05/how-generate-secure-random-numbers-in-various-programming-languages#nodejs-csprng
var sodium = require('sodium-native');
sodium.randombytes_buf(b);
randBz = new Uint8Array(b.buffer, b.byteOffset, b.byteLength / Uint8Array.BYTES_PER_ELEMENT);
}
else if (crypto && crypto.getRandomValues) {
// For browser or web worker enviroment, use window.crypto.getRandomValues()
// https://paragonie.com/blog/2016/05/how-generate-secure-random-numbers-in-various-programming-languages#js-csprng
// limit of getRandomValues()
// The requested length exceeds 65536 bytes.
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues#exceptions
var MAX_BYTES = 65536;
for (var i = 0; i < n; i += MAX_BYTES) {
crypto.getRandomValues(new Uint8Array(b.buffer, i + b.byteOffset, Math.min(n - i, MAX_BYTES)));
}
}
else {
throw new Error('Unable to generate safe random numbers.');
throw new Error('No secure random number generator available');
}
var randBz = new Uint8Array(b.buffer, b.byteOffset, b.byteLength / Uint8Array.BYTES_PER_ELEMENT);
var randStr = '';

@@ -289,3 +305,2 @@ for (var i = 0; i < bytes; i++) {

var chk = 1;
// tslint:disable-next-line
for (var p = 0; p < values.length; ++p) {

@@ -334,3 +349,2 @@ var top_1 = chk >> 25;

var ret = hrp + '1';
// tslint:disable-next-line
for (var p = 0; p < combined.length; ++p) {

@@ -401,3 +415,2 @@ ret += CHARSET.charAt(combined[p]);

var maxv = (1 << toWidth) - 1;
// tslint:disable-next-line
for (var p = 0; p < data.length; ++p) {

@@ -485,7 +498,3 @@ var value = data[p];

var pub = keyPair.getPublic(true, 'hex');
return toChecksumAddress(hashjs
.sha256()
.update(pub, 'hex')
.digest('hex')
.slice(24));
return toChecksumAddress(hashjs.sha256().update(pub, 'hex').digest('hex').slice(24));
};

@@ -571,7 +580,3 @@ /**

var normalized = publicKey.toLowerCase().replace('0x', '');
return toChecksumAddress(hashjs
.sha256()
.update(normalized, 'hex')
.digest('hex')
.slice(24));
return toChecksumAddress(hashjs.sha256().update(normalized, 'hex').digest('hex').slice(24));
};

@@ -591,6 +596,3 @@ /**

address = address.toLowerCase().replace('0x', '');
var hash = hashjs
.sha256()
.update(address, 'hex')
.digest('hex');
var hash = hashjs.sha256().update(address, 'hex').digest('hex');
var v = new util.BN(hash, 'hex', 'be');

@@ -745,21 +747,22 @@ var ret = '0x';

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());

@@ -934,2 +937,19 @@ });

// Copyright (C) 2018 Zilliqa
//
// This file is part of Zilliqa-Javascript-Library.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// Copyright (C) 2018 Zilliqa
/**

@@ -936,0 +956,0 @@ * sign

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.decryptPrivateKey = exports.encryptPrivateKey = void 0;
var tslib_1 = require("tslib");

@@ -21,0 +22,0 @@ var aes_js_1 = tslib_1.__importDefault(require("aes-js"));

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.randomBytes = void 0;
/**

@@ -30,17 +31,33 @@ * randomBytes

exports.randomBytes = function (bytes) {
var randBz;
if (typeof window !== 'undefined' &&
window.crypto &&
window.crypto.getRandomValues) {
randBz = window.crypto.getRandomValues(new Uint8Array(bytes));
var _a;
var b = Buffer.allocUnsafe(bytes);
var n = b.byteLength;
var crypto = global.crypto;
if (crypto === undefined) {
// @ts-ignore
// for IE 11
crypto = global.msCrypto;
}
else if (typeof require !== 'undefined') {
var b = Buffer.allocUnsafe(bytes);
var isNodeEnv = typeof ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) === 'string';
if (isNodeEnv) {
// For node enviroment, use sodium-native
// https://paragonie.com/blog/2016/05/how-generate-secure-random-numbers-in-various-programming-languages#nodejs-csprng
var sodium = require('sodium-native');
sodium.randombytes_buf(b);
randBz = new Uint8Array(b.buffer, b.byteOffset, b.byteLength / Uint8Array.BYTES_PER_ELEMENT);
}
else if (crypto && crypto.getRandomValues) {
// For browser or web worker enviroment, use window.crypto.getRandomValues()
// https://paragonie.com/blog/2016/05/how-generate-secure-random-numbers-in-various-programming-languages#js-csprng
// limit of getRandomValues()
// The requested length exceeds 65536 bytes.
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues#exceptions
var MAX_BYTES = 65536;
for (var i = 0; i < n; i += MAX_BYTES) {
crypto.getRandomValues(new Uint8Array(b.buffer, i + b.byteOffset, Math.min(n - i, MAX_BYTES)));
}
}
else {
throw new Error('Unable to generate safe random numbers.');
throw new Error('No secure random number generator available');
}
var randBz = new Uint8Array(b.buffer, b.byteOffset, b.byteLength / Uint8Array.BYTES_PER_ELEMENT);
var randStr = '';

@@ -47,0 +64,0 @@ for (var i = 0; i < bytes; i++) {

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

/// <reference types="node" />
/// <reference types="bn.js" />
/// <reference types="node" />
import { BN } from '@zilliqa-js/util';

@@ -4,0 +4,0 @@ import { Signature } from './signature';

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.toSignature = exports.verify = exports.trySign = exports.sign = exports.hash = exports.generatePrivateKey = void 0;
var tslib_1 = require("tslib");

@@ -21,0 +22,0 @@ var elliptic_1 = tslib_1.__importDefault(require("elliptic"));

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.Signature = void 0;
var util_1 = require("@zilliqa-js/util");

@@ -21,0 +22,0 @@ var Signature = /** @class */ (function () {

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizePrivateKey = exports.verifyPrivateKey = exports.decodeBase58 = exports.encodeBase58 = exports.normaliseAddress = exports.isValidChecksumAddress = exports.toChecksumAddress = exports.getAddressFromPublicKey = exports.compressPublicKey = exports.getAccountFrom0xPrivateKey = exports.getPubKeyFromPrivateKey = exports.getAddressFromPrivateKey = void 0;
var tslib_1 = require("tslib");

@@ -39,7 +40,3 @@ var elliptic_1 = tslib_1.__importDefault(require("elliptic"));

var pub = keyPair.getPublic(true, 'hex');
return exports.toChecksumAddress(hash_js_1.default
.sha256()
.update(pub, 'hex')
.digest('hex')
.slice(24));
return exports.toChecksumAddress(hash_js_1.default.sha256().update(pub, 'hex').digest('hex').slice(24));
};

@@ -125,7 +122,3 @@ /**

var normalized = publicKey.toLowerCase().replace('0x', '');
return exports.toChecksumAddress(hash_js_1.default
.sha256()
.update(normalized, 'hex')
.digest('hex')
.slice(24));
return exports.toChecksumAddress(hash_js_1.default.sha256().update(normalized, 'hex').digest('hex').slice(24));
};

@@ -145,6 +138,3 @@ /**

address = address.toLowerCase().replace('0x', '');
var hash = hash_js_1.default
.sha256()
.update(address, 'hex')
.digest('hex');
var hash = hash_js_1.default.sha256().update(address, 'hex').digest('hex');
var v = new util_1.BN(hash, 'hex', 'be');

@@ -151,0 +141,0 @@ var ret = '0x';

{
"name": "@zilliqa-js/crypto",
"version": "3.0.0",
"version": "3.1.0",
"description": "Core crypto utilities for signing/verification/hashing Zilliqa transactions.",

@@ -28,3 +28,3 @@ "author": "Ian Tan (https://github.com/iantanwx)",

"dependencies": {
"@zilliqa-js/util": "3.0.0",
"@zilliqa-js/util": "3.1.0",
"aes-js": "^3.1.1",

@@ -39,6 +39,14 @@ "bsert": "^0.0.4",

"scryptsy": "^2.1.0",
"sodium-native": "^3.2.0",
"sodium-native": "^3.2.1",
"uuid": "^3.3.2"
},
"gitHead": "832bcaf3a930a7257e009481c0c76dc27e39450a"
"files": [
"dist",
"node_modules",
"package.json",
"LICENSE",
"CHANGELOG.md",
"README.md"
],
"gitHead": "5812a8d2199d8f4ff584dfd343b91cac3ee0dbbc"
}
# @zilliqa-js/crypto
> Cryptographic abstractions for working with Zilliqa's crypto primitives

@@ -8,4 +9,7 @@

Safely generates bytes using [`Window.crypto`](https://developer.mozilla.org/en-US/docs/Web/API/Window/crypto) in the browser or the built-in `crypto` in node.
Safely generates random bytes.
- For browser and web worker environment, we use [window.crypto.getRandomValues()](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues)
- For node environment, we use [sodium-native](https://github.com/sodium-friends/sodium-native)
**Parameters**

@@ -31,3 +35,2 @@

### `getPubKeyFromPrivateKey(privateKey: string): string`

@@ -45,3 +48,2 @@

### `getAddressFromPrivateKey(privateKey: string): string`

@@ -59,3 +61,2 @@

### `compressPublicKey(publicKey: string): string`

@@ -113,3 +114,2 @@

### `encryptPrivateKey(kdf: KDF, privateKey: string, passphrase: string): Promise<string>`

@@ -116,0 +116,0 @@

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