@zilliqa-js/crypto
Advanced tools
Comparing version 3.3.2 to 3.3.3
/// <reference types="node" /> | ||
import * as schnorr from './schnorr'; | ||
declare const Signature: any; | ||
import { Signature } from './signature'; | ||
/** | ||
@@ -5,0 +5,0 @@ * sign |
@@ -9,3 +9,3 @@ import elliptic, { ec } from 'elliptic'; | ||
import scrypt from 'scrypt-js'; | ||
import uuid from 'uuid'; | ||
import { v4 } from 'uuid'; | ||
@@ -44,3 +44,4 @@ // Copyright (C) 2018 Zilliqa | ||
((_a = self.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'DedicatedWorkerGlobalScope'; | ||
var isNodeEnv = typeof ((_b = process === null || process === void 0 ? void 0 : process.versions) === null || _b === void 0 ? void 0 : _b.node) === 'string'; | ||
var isNodeEnv = typeof process !== 'undefined' && | ||
typeof ((_b = process === null || process === void 0 ? void 0 : process.versions) === null || _b === void 0 ? void 0 : _b.node) === 'string'; | ||
var crypto = undefined; | ||
@@ -67,4 +68,14 @@ if (isBrowserEnv || isWebWorkerEnv) { | ||
else 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 | ||
// For node enviroment, use sodium-native because we prefer kernel CSPRNG. | ||
// References: | ||
// - https://paragonie.com/blog/2016/05/how-generate-secure-random-numbers-in-various-programming-languages#nodejs-csprng | ||
// - https://github.com/nodejs/node/issues/5798 | ||
// | ||
// This logic should run only in node env. Otherwise, it will throw an error 'require is not defined'. | ||
// | ||
// Consider using createRequire when typescipt 4.5 is available. | ||
// https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta | ||
// https://nodejs.org/api/module.html#modulecreaterequirefilename | ||
// | ||
// eslint-disable-next-line | ||
var sodium = require('sodium-native'); | ||
@@ -76,8 +87,3 @@ sodium.randombytes_buf(b); | ||
} | ||
var randBz = new Uint8Array(b.buffer, b.byteOffset, b.byteLength / Uint8Array.BYTES_PER_ELEMENT); | ||
var randStr = ''; | ||
for (var i = 0; i < bytes$$1; i++) { | ||
randStr += ('00' + randBz[i].toString(16)).slice(-2); | ||
} | ||
return randStr; | ||
return b.toString('hex'); | ||
}; | ||
@@ -278,2 +284,18 @@ | ||
// Copyright (C) 2018 Zilliqa | ||
// This replaces `elliptic/lib/elliptic/ec/signature`. | ||
// Q. Why do we replace `elliptic/lib/elliptic/ec/signature` with this? | ||
// A. At the moment, Signature() in 'elliptic' is not exposed. | ||
var Signature = /** @class */ (function () { | ||
function Signature(options) { | ||
var isValid = options.r && options.s; | ||
if (!isValid) { | ||
throw new Error('Signature without r or s'); | ||
} | ||
this.r = new BN(options.r, 16); | ||
this.s = new BN(options.s, 16); | ||
} | ||
return Signature; | ||
}()); | ||
// Copyright (C) 2018 Zilliqa | ||
// This code is taken from https://github.com/sipa/bech32/tree/bdc264f84014c234e908d72026b7b780122be11f/ref/javascript | ||
@@ -827,3 +849,3 @@ // Copyright (c) 2017 Pieter Wuille | ||
}, | ||
id: uuid.v4({ random: bytes.hexToIntArray(randomBytes(16)) }), | ||
id: v4({ random: bytes.hexToIntArray(randomBytes(16)) }), | ||
version: 3, | ||
@@ -878,25 +900,2 @@ })]; | ||
// Copyright (C) 2018 Zilliqa | ||
// This is a workaround. We need to improve it. | ||
var Signature = require('elliptic/lib/elliptic/ec/signature'); | ||
// Q. Why do we use require() here? | ||
// A. At the moment, Signature() in 'elliptic' is can only be imported | ||
// from 'elliptic/lib/elliptic/ec/signature'. If we use ES6 import syntax, | ||
// TS will try to generate d.ts from 'elliptic/lib/elliptic/ec/signature' | ||
// causing an error with 'Could not find a declaration file for module ...' message. | ||
// Therefore, we use require() here. | ||
// | ||
// Q. Why don't we use `ec.Signature` type for 'Signature()'? | ||
// A. `Signature()` is a function while @types/elliptic defines it as following | ||
// | ||
// class Signature { | ||
// r: BN; | ||
// s: BN; | ||
// recoveryParam: number | null; | ||
// constructor(options: SignatureInput, enc?: string); | ||
// toDER(enc?: string | null): any; // ? | ||
// } | ||
// | ||
// With the above `ec.Signature` type, `new Signature()` will throw an error | ||
// since it doesn't have constructor(). | ||
// Therefore, we keep the type of Signature() as any. | ||
/** | ||
@@ -903,0 +902,0 @@ * sign |
@@ -23,26 +23,4 @@ "use strict"; | ||
exports.schnorr = schnorr; | ||
// This is a workaround. We need to improve it. | ||
var Signature = require('elliptic/lib/elliptic/ec/signature'); | ||
exports.Signature = Signature; | ||
// Q. Why do we use require() here? | ||
// A. At the moment, Signature() in 'elliptic' is can only be imported | ||
// from 'elliptic/lib/elliptic/ec/signature'. If we use ES6 import syntax, | ||
// TS will try to generate d.ts from 'elliptic/lib/elliptic/ec/signature' | ||
// causing an error with 'Could not find a declaration file for module ...' message. | ||
// Therefore, we use require() here. | ||
// | ||
// Q. Why don't we use `ec.Signature` type for 'Signature()'? | ||
// A. `Signature()` is a function while @types/elliptic defines it as following | ||
// | ||
// class Signature { | ||
// r: BN; | ||
// s: BN; | ||
// recoveryParam: number | null; | ||
// constructor(options: SignatureInput, enc?: string); | ||
// toDER(enc?: string | null): any; // ? | ||
// } | ||
// | ||
// With the above `ec.Signature` type, `new Signature()` will throw an error | ||
// since it doesn't have constructor(). | ||
// Therefore, we keep the type of Signature() as any. | ||
var signature_1 = require("./signature"); | ||
Object.defineProperty(exports, "Signature", { enumerable: true, get: function () { return signature_1.Signature; } }); | ||
/** | ||
@@ -49,0 +27,0 @@ * sign |
@@ -12,3 +12,2 @@ (function (global, factory) { | ||
scrypt = scrypt && scrypt.hasOwnProperty('default') ? scrypt['default'] : scrypt; | ||
uuid = uuid && uuid.hasOwnProperty('default') ? uuid['default'] : uuid; | ||
@@ -47,3 +46,4 @@ // Copyright (C) 2018 Zilliqa | ||
((_a = self.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'DedicatedWorkerGlobalScope'; | ||
var isNodeEnv = typeof ((_b = process === null || process === void 0 ? void 0 : process.versions) === null || _b === void 0 ? void 0 : _b.node) === 'string'; | ||
var isNodeEnv = typeof process !== 'undefined' && | ||
typeof ((_b = process === null || process === void 0 ? void 0 : process.versions) === null || _b === void 0 ? void 0 : _b.node) === 'string'; | ||
var crypto = undefined; | ||
@@ -70,4 +70,14 @@ if (isBrowserEnv || isWebWorkerEnv) { | ||
else 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 | ||
// For node enviroment, use sodium-native because we prefer kernel CSPRNG. | ||
// References: | ||
// - https://paragonie.com/blog/2016/05/how-generate-secure-random-numbers-in-various-programming-languages#nodejs-csprng | ||
// - https://github.com/nodejs/node/issues/5798 | ||
// | ||
// This logic should run only in node env. Otherwise, it will throw an error 'require is not defined'. | ||
// | ||
// Consider using createRequire when typescipt 4.5 is available. | ||
// https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta | ||
// https://nodejs.org/api/module.html#modulecreaterequirefilename | ||
// | ||
// eslint-disable-next-line | ||
var sodium = require('sodium-native'); | ||
@@ -79,8 +89,3 @@ sodium.randombytes_buf(b); | ||
} | ||
var randBz = new Uint8Array(b.buffer, b.byteOffset, b.byteLength / Uint8Array.BYTES_PER_ELEMENT); | ||
var randStr = ''; | ||
for (var i = 0; i < bytes; i++) { | ||
randStr += ('00' + randBz[i].toString(16)).slice(-2); | ||
} | ||
return randStr; | ||
return b.toString('hex'); | ||
}; | ||
@@ -281,2 +286,18 @@ | ||
// Copyright (C) 2018 Zilliqa | ||
// This replaces `elliptic/lib/elliptic/ec/signature`. | ||
// Q. Why do we replace `elliptic/lib/elliptic/ec/signature` with this? | ||
// A. At the moment, Signature() in 'elliptic' is not exposed. | ||
var Signature = /** @class */ (function () { | ||
function Signature(options) { | ||
var isValid = options.r && options.s; | ||
if (!isValid) { | ||
throw new Error('Signature without r or s'); | ||
} | ||
this.r = new util.BN(options.r, 16); | ||
this.s = new util.BN(options.s, 16); | ||
} | ||
return Signature; | ||
}()); | ||
// Copyright (C) 2018 Zilliqa | ||
// This code is taken from https://github.com/sipa/bech32/tree/bdc264f84014c234e908d72026b7b780122be11f/ref/javascript | ||
@@ -880,25 +901,2 @@ // Copyright (c) 2017 Pieter Wuille | ||
// Copyright (C) 2018 Zilliqa | ||
// This is a workaround. We need to improve it. | ||
var Signature = require('elliptic/lib/elliptic/ec/signature'); | ||
// Q. Why do we use require() here? | ||
// A. At the moment, Signature() in 'elliptic' is can only be imported | ||
// from 'elliptic/lib/elliptic/ec/signature'. If we use ES6 import syntax, | ||
// TS will try to generate d.ts from 'elliptic/lib/elliptic/ec/signature' | ||
// causing an error with 'Could not find a declaration file for module ...' message. | ||
// Therefore, we use require() here. | ||
// | ||
// Q. Why don't we use `ec.Signature` type for 'Signature()'? | ||
// A. `Signature()` is a function while @types/elliptic defines it as following | ||
// | ||
// class Signature { | ||
// r: BN; | ||
// s: BN; | ||
// recoveryParam: number | null; | ||
// constructor(options: SignatureInput, enc?: string); | ||
// toDER(enc?: string | null): any; // ? | ||
// } | ||
// | ||
// With the above `ec.Signature` type, `new Signature()` will throw an error | ||
// since it doesn't have constructor(). | ||
// Therefore, we keep the type of Signature() as any. | ||
/** | ||
@@ -905,0 +903,0 @@ * sign |
@@ -25,3 +25,3 @@ "use strict"; | ||
var scrypt_js_1 = (0, tslib_1.__importDefault)(require("scrypt-js")); | ||
var uuid_1 = (0, tslib_1.__importDefault)(require("uuid")); | ||
var uuid_1 = require("uuid"); | ||
var util_1 = require("@zilliqa-js/util"); | ||
@@ -118,3 +118,3 @@ var random_1 = require("./random"); | ||
}, | ||
id: uuid_1.default.v4({ random: util_1.bytes.hexToIntArray((0, random_1.randomBytes)(16)) }), | ||
id: (0, uuid_1.v4)({ random: util_1.bytes.hexToIntArray((0, random_1.randomBytes)(16)) }), | ||
version: 3, | ||
@@ -121,0 +121,0 @@ })]; |
@@ -36,3 +36,4 @@ "use strict"; | ||
((_a = self.constructor) === null || _a === void 0 ? void 0 : _a.name) === 'DedicatedWorkerGlobalScope'; | ||
var isNodeEnv = typeof ((_b = process === null || process === void 0 ? void 0 : process.versions) === null || _b === void 0 ? void 0 : _b.node) === 'string'; | ||
var isNodeEnv = typeof process !== 'undefined' && | ||
typeof ((_b = process === null || process === void 0 ? void 0 : process.versions) === null || _b === void 0 ? void 0 : _b.node) === 'string'; | ||
var crypto = undefined; | ||
@@ -59,4 +60,14 @@ if (isBrowserEnv || isWebWorkerEnv) { | ||
else 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 | ||
// For node enviroment, use sodium-native because we prefer kernel CSPRNG. | ||
// References: | ||
// - https://paragonie.com/blog/2016/05/how-generate-secure-random-numbers-in-various-programming-languages#nodejs-csprng | ||
// - https://github.com/nodejs/node/issues/5798 | ||
// | ||
// This logic should run only in node env. Otherwise, it will throw an error 'require is not defined'. | ||
// | ||
// Consider using createRequire when typescipt 4.5 is available. | ||
// https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta | ||
// https://nodejs.org/api/module.html#modulecreaterequirefilename | ||
// | ||
// eslint-disable-next-line | ||
var sodium = require('sodium-native'); | ||
@@ -68,10 +79,5 @@ sodium.randombytes_buf(b); | ||
} | ||
var randBz = new Uint8Array(b.buffer, b.byteOffset, b.byteLength / Uint8Array.BYTES_PER_ELEMENT); | ||
var randStr = ''; | ||
for (var i = 0; i < bytes; i++) { | ||
randStr += ('00' + randBz[i].toString(16)).slice(-2); | ||
} | ||
return randStr; | ||
return b.toString('hex'); | ||
}; | ||
exports.randomBytes = randomBytes; | ||
//# sourceMappingURL=random.js.map |
/// <reference types="node" /> | ||
import { ec } from 'elliptic'; | ||
import { BN } from '@zilliqa-js/util'; | ||
@@ -28,3 +27,3 @@ import { Signature } from '.'; | ||
*/ | ||
export declare const sign: (msg: Buffer, privKey: Buffer, pubKey: Buffer) => ec.Signature; | ||
export declare const sign: (msg: Buffer, privKey: Buffer, pubKey: Buffer) => Signature; | ||
/** | ||
@@ -40,3 +39,3 @@ * trySign | ||
*/ | ||
export declare const trySign: (msg: Buffer, k: BN, privKey: BN, pubKey: Buffer) => ec.Signature | null; | ||
export declare const trySign: (msg: Buffer, k: BN, privKey: BN, pubKey: Buffer) => Signature | null; | ||
/** | ||
@@ -57,4 +56,4 @@ * Verify signature. | ||
*/ | ||
export declare const verify: (msg: Buffer, signature: ec.Signature, key: Buffer) => boolean; | ||
export declare const toSignature: (serialised: string) => ec.Signature; | ||
export declare const verify: (msg: Buffer, signature: Signature, key: Buffer) => boolean; | ||
export declare const toSignature: (serialised: string) => Signature; | ||
//# sourceMappingURL=schnorr.d.ts.map |
{ | ||
"name": "@zilliqa-js/crypto", | ||
"version": "3.3.2", | ||
"version": "3.3.3", | ||
"description": "Core crypto utilities for signing/verification/hashing Zilliqa transactions.", | ||
@@ -29,3 +29,4 @@ "author": "Ian Tan (https://github.com/iantanwx)", | ||
"@types/elliptic": "^6.4.13", | ||
"@zilliqa-js/util": "^3.3.2", | ||
"@types/uuid": "8.3.1", | ||
"@zilliqa-js/util": "^3.3.3", | ||
"aes-js": "^3.1.1", | ||
@@ -42,3 +43,3 @@ "bsert": "^0.0.4", | ||
"tslib": "2.3.1", | ||
"uuid": "^3.3.2" | ||
"uuid": "8.3.2" | ||
}, | ||
@@ -53,3 +54,3 @@ "files": [ | ||
], | ||
"gitHead": "06e45274da871723b039e80ee26bc1714c550266" | ||
"gitHead": "c0aab06f22ac07da9fc5f9f049fc8bfaa6a4d56f" | ||
} |
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
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
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
306975
39
3230
15
+ Added@types/uuid@8.3.1
+ Added@types/uuid@8.3.1(transitive)
+ Addeduuid@8.3.2(transitive)
- Removeduuid@3.4.0(transitive)
Updated@zilliqa-js/util@^3.3.3
Updateduuid@8.3.2