Socket
Socket
Sign inDemoInstall

noble-secp256k1

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

noble-secp256k1 - npm Package Compare versions

Comparing version 1.2.11 to 1.2.12

10

index.d.ts

@@ -46,6 +46,12 @@ /*! noble-secp256k1 - MIT License (c) Paul Miller (paulmillr.com) */

constructor(r: bigint, s: bigint);
static fromCompact(hex: Hex): Signature;
static fromDER(hex: Hex): Signature;
static fromHex(hex: Hex): Signature;
assertValidity(): void;
toRawBytes(isCompressed?: boolean): Uint8Array;
toHex(isCompressed?: boolean): string;
toDERRawBytes(isCompressed?: boolean): Uint8Array;
toDERHex(isCompressed?: boolean): string;
toRawBytes(): Uint8Array;
toHex(): string;
toCompactRawBytes(): Uint8Array;
toCompactHex(): string;
}

@@ -52,0 +58,0 @@ export declare const SignResult: typeof Signature;

62

index.js

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

const sig = normalizeSignature(signature);
sig.assertValidity();
const { r, s } = sig;

@@ -358,4 +357,15 @@ if (recovery !== 0 && recovery !== 1) {

}
static fromHex(hex) {
static fromCompact(hex) {
if (typeof hex !== 'string' && !(hex instanceof Uint8Array)) {
throw new TypeError(`Signature.fromCompact: Expected string or Uint8Array`);
}
const str = hex instanceof Uint8Array ? bytesToHex(hex) : hex;
if (str.length !== 128)
throw new Error('Signature.fromCompact: Expected 64-byte hex');
const sig = new Signature(hexToNumber(str.slice(0, 64)), hexToNumber(str.slice(64, 128)));
sig.assertValidity();
return sig;
}
static fromDER(hex) {
if (typeof hex !== 'string' && !(hex instanceof Uint8Array)) {
throw new TypeError(`Signature.fromHex: Expected string or Uint8Array`);

@@ -393,4 +403,9 @@ }

const s = hexToNumber(ss);
return new Signature(r, s);
const sig = new Signature(r, s);
sig.assertValidity();
return sig;
}
static fromHex(hex) {
return this.fromDER(hex);
}
assertValidity() {

@@ -403,6 +418,6 @@ const { r, s } = this;

}
toRawBytes(isCompressed = false) {
return hexToBytes(this.toHex(isCompressed));
toDERRawBytes(isCompressed = false) {
return hexToBytes(this.toDERHex(isCompressed));
}
toHex(isCompressed = false) {
toDERHex(isCompressed = false) {
const sHex = sliceDer(numberToHex(this.s));

@@ -417,2 +432,14 @@ if (isCompressed)

}
toRawBytes() {
return this.toDERRawBytes();
}
toHex() {
return this.toDERHex();
}
toCompactRawBytes() {
return hexToBytes(this.toCompactHex());
}
toCompactHex() {
return pad64(this.r) + pad64(this.s);
}
}

@@ -686,6 +713,18 @@ exports.Signature = Signature;

function normalizePublicKey(publicKey) {
return publicKey instanceof Point ? publicKey : Point.fromHex(publicKey);
if (publicKey instanceof Point) {
publicKey.assertValidity();
return publicKey;
}
else {
return Point.fromHex(publicKey);
}
}
function normalizeSignature(signature) {
return signature instanceof Signature ? signature : Signature.fromHex(signature);
if (signature instanceof Signature) {
signature.assertValidity();
return signature;
}
else {
return Signature.fromDER(signature);
}
}

@@ -741,3 +780,4 @@ function getPublicKey(privateKey, isCompressed = false) {

const sig = new Signature(r, adjustedS);
const hashed = str ? sig.toHex() : sig.toRawBytes();
sig.assertValidity();
const hashed = str ? sig.toDERHex() : sig.toDERRawBytes();
return recovered ? [hashed, recovery] : hashed;

@@ -755,5 +795,5 @@ }

const { n } = CURVE;
const sig = normalizeSignature(signature);
let sig;
try {
sig.assertValidity();
sig = normalizeSignature(signature);
}

@@ -760,0 +800,0 @@ catch (error) {

{
"name": "noble-secp256k1",
"version": "1.2.11",
"version": "1.2.12",
"description": "Fastest JS implementation of secp256k1. Independently audited, high-security, 0-dependency ECDSA & Schnorr signatures",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -108,5 +108,5 @@ # 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)

- `options?: Options` - *optional* object related to signature value and format
- `options?.recovered: boolean = false` - determines whether the recovered bit should be included in the result. In this case, the result would be an array of two items.
- `options?.canonical: boolean = false` - determines whether a signature `s` should be no more than 1/2 prime order
- Returns DER encoded ECDSA signature, as hex uint8a / string and recovered bit if `options.recovered == true`.
- `options?.recovered: boolean = false` - whether the recovered bit should be included in the result. In this case, the result would be an array of two items.
- `options?.canonical: boolean = false` - whether a signature `s` should be no more than 1/2 prime order
- `options?.der: boolean = true` - whether the returned signature should be in DER format. If `false`, it would be in Compact format (32-byte r + 32-byte s)

@@ -247,4 +247,9 @@ The function is asynchronous because we're utilizing built-in HMAC API to not rely on dependencies.

// DER encoded ECDSA signature
static fromHex(hex: Uint8Array | string);
toHex(): string;
static fromDER(hex: Uint8Array | string);
// R, S 32-byte each
static fromCompact(hex: Uint8Array | string);
toDERRawBytes(): Uint8Array;
toDERHex(): string;
toCompactRawBytes(): Uint8Array;
toCompactHex(): string;
}

@@ -251,0 +256,0 @@ ```

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