noble-secp256k1
Advanced tools
Comparing version 1.2.9 to 1.2.10
40
index.js
@@ -786,3 +786,3 @@ "use strict"; | ||
this.s = s; | ||
if (r === 0n || s === 0n || r >= CURVE.P || s >= CURVE.n) | ||
if (r <= 0n || s <= 0n || r >= CURVE.P || s >= CURVE.n) | ||
throw new Error('Invalid signature'); | ||
@@ -857,2 +857,12 @@ } | ||
Point.BASE._setWindowSize(8); | ||
const crypto = (() => { | ||
const webCrypto = typeof self === 'object' && 'crypto' in self ? self.crypto : undefined; | ||
const nodeRequire = typeof module !== 'undefined' && | ||
typeof module.require === 'function' && | ||
module.require.bind(module); | ||
return { | ||
node: nodeRequire && !webCrypto ? nodeRequire('crypto') : undefined, | ||
web: webCrypto, | ||
}; | ||
})(); | ||
exports.utils = { | ||
@@ -869,7 +879,7 @@ isValidPrivateKey(privateKey) { | ||
randomBytes: (bytesLength = 32) => { | ||
if (typeof self == 'object' && 'crypto' in self) { | ||
return self.crypto.getRandomValues(new Uint8Array(bytesLength)); | ||
if (crypto.web) { | ||
return crypto.web.getRandomValues(new Uint8Array(bytesLength)); | ||
} | ||
else if (typeof process === 'object' && 'node' in process.versions) { | ||
const { randomBytes } = require('crypto'); | ||
else if (crypto.node) { | ||
const { randomBytes } = crypto.node; | ||
return new Uint8Array(randomBytes(bytesLength).buffer); | ||
@@ -886,3 +896,3 @@ } | ||
const num = bytesToNumber(b32); | ||
if (num > 1n && num < CURVE.n) | ||
if (isWithinCurveOrder(num) && num !== 1n) | ||
return b32; | ||
@@ -893,8 +903,8 @@ } | ||
sha256: async (message) => { | ||
if (typeof self == 'object' && 'crypto' in self) { | ||
const buffer = await self.crypto.subtle.digest('SHA-256', message.buffer); | ||
if (crypto.web) { | ||
const buffer = await crypto.web.subtle.digest('SHA-256', message.buffer); | ||
return new Uint8Array(buffer); | ||
} | ||
else if (typeof process === 'object' && 'node' in process.versions) { | ||
const { createHash } = require('crypto'); | ||
else if (crypto.node) { | ||
const { createHash } = crypto.node; | ||
return Uint8Array.from(createHash('sha256').update(message).digest()); | ||
@@ -907,10 +917,10 @@ } | ||
hmacSha256: async (key, ...messages) => { | ||
if (typeof self == 'object' && 'crypto' in self) { | ||
const ckey = await self.crypto.subtle.importKey('raw', key, { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']); | ||
if (crypto.web) { | ||
const ckey = await crypto.web.subtle.importKey('raw', key, { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']); | ||
const message = concatBytes(...messages); | ||
const buffer = await self.crypto.subtle.sign('HMAC', ckey, message); | ||
const buffer = await crypto.web.subtle.sign('HMAC', ckey, message); | ||
return new Uint8Array(buffer); | ||
} | ||
else if (typeof process === 'object' && 'node' in process.versions) { | ||
const { createHmac } = require('crypto'); | ||
else if (crypto.node) { | ||
const { createHmac } = crypto.node; | ||
const hash = createHmac('sha256', key); | ||
@@ -917,0 +927,0 @@ for (let message of messages) { |
{ | ||
"name": "noble-secp256k1", | ||
"version": "1.2.9", | ||
"version": "1.2.10", | ||
"description": "Fastest JS implementation of secp256k1. Independently audited, high-security, 0-dependency ECDSA & Schnorr signatures", | ||
@@ -37,10 +37,10 @@ "main": "index.js", | ||
"@rollup/plugin-node-resolve": "^13.0.0", | ||
"@types/jest": "^26.0.22", | ||
"@types/jest": "^27", | ||
"@types/node": "^16.3.3", | ||
"fast-check": "^2.14.0", | ||
"jest": "^26.6.3", | ||
"jest": "^27", | ||
"micro-bmark": "^0.1.3", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.53.2", | ||
"ts-jest": "^26.5.4", | ||
"ts-jest": "^27", | ||
"typescript": "~4.3.5" | ||
@@ -47,0 +47,0 @@ }, |
@@ -21,3 +21,3 @@ # noble-secp256k1 ![Node CI](https://github.com/paulmillr/noble-secp256k1/workflows/Node%20CI/badge.svg) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) | ||
[bls12-381](https://github.com/paulmillr/noble-bls12-381), | ||
[ripemd160](https://github.com/paulmillr/noble-ripemd160) | ||
[hashes](https://github.com/paulmillr/noble-hashes) | ||
@@ -24,0 +24,0 @@ ## Usage |
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
53575
1040