@noble/ed25519
Advanced tools
Comparing version 1.3.3 to 1.4.0
@@ -6,3 +6,2 @@ /*! noble-ed25519 - MIT License (c) Paul Miller (paulmillr.com) */ | ||
const _2n = BigInt(2); | ||
const _8n = BigInt(8); | ||
const _255n = BigInt(255); | ||
@@ -48,2 +47,6 @@ const CURVE = { | ||
static fromRistrettoHash(hash) { | ||
if (typeof hash === 'string') | ||
hash = hexToBytes(hash); | ||
if (hash.length !== 64) | ||
throw new Error('Invalid ristretto hash, need 64 bytes'); | ||
const r1 = bytes255ToNumberLE(hash.slice(0, B32)); | ||
@@ -78,2 +81,6 @@ const R1 = this.calcElligatorRistrettoMap(r1); | ||
static fromRistrettoBytes(bytes) { | ||
if (typeof bytes === 'string') | ||
bytes = hexToBytes(bytes); | ||
if (bytes.length !== 32) | ||
throw new Error('Invalid ristretto hash, need 64 bytes'); | ||
const { a, d } = CURVE; | ||
@@ -382,6 +389,7 @@ const emsg = 'ExtendedPoint.fromRistrettoBytes: Cannot convert bytes to Ristretto Point'; | ||
} | ||
const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0')); | ||
function bytesToHex(uint8a) { | ||
let hex = ''; | ||
for (let i = 0; i < uint8a.length; i++) { | ||
hex += uint8a[i].toString(16).padStart(2, '0'); | ||
hex += hexes[uint8a[i]]; | ||
} | ||
@@ -423,3 +431,3 @@ return hex; | ||
for (let i = 0; i < uint8a.length; i++) { | ||
value += BigInt(uint8a[i]) << (_8n * BigInt(i)); | ||
value += BigInt(uint8a[i]) << (BigInt(8) * BigInt(i)); | ||
} | ||
@@ -592,3 +600,3 @@ return value; | ||
const key = await Point.fromPrivateKey(privateKey); | ||
return typeof privateKey === 'string' ? key.toHex() : key.toRawBytes(); | ||
return key.toRawBytes(); | ||
} | ||
@@ -605,3 +613,3 @@ export async function sign(msgHash, privateKey) { | ||
const sig = new Signature(R, S); | ||
return typeof msgHash === 'string' ? sig.toHex() : sig.toRawBytes(); | ||
return sig.toRawBytes(); | ||
} | ||
@@ -618,3 +626,3 @@ export async function verify(sig, msgHash, publicKey) { | ||
const RPh = ExtendedPoint.fromAffine(sig.r).add(Ph); | ||
return RPh.subtract(Gs).multiplyUnsafe(_8n).equals(ExtendedPoint.ZERO); | ||
return RPh.subtract(Gs).multiplyUnsafe(CURVE.h).equals(ExtendedPoint.ZERO); | ||
} | ||
@@ -637,2 +645,3 @@ Point.BASE._setWindowSize(8); | ||
], | ||
bytesToHex, | ||
randomBytes: (bytesLength = 32) => { | ||
@@ -639,0 +648,0 @@ if (crypto.web) { |
@@ -29,3 +29,3 @@ /*! noble-ed25519 - MIT License (c) Paul Miller (paulmillr.com) */ | ||
private static calcElligatorRistrettoMap; | ||
static fromRistrettoBytes(bytes: Uint8Array): ExtendedPoint; | ||
static fromRistrettoBytes(bytes: Hex): ExtendedPoint; | ||
toRistrettoBytes(): Uint8Array; | ||
@@ -71,9 +71,9 @@ equals(other: ExtendedPoint): boolean; | ||
export { ExtendedPoint, Point, Signature, Signature as SignResult }; | ||
export declare function getPublicKey(privateKey: Uint8Array | bigint | number): Promise<Uint8Array>; | ||
export declare function getPublicKey(privateKey: string): Promise<string>; | ||
export declare function sign(msgHash: Uint8Array, privateKey: Hex): Promise<Uint8Array>; | ||
export declare function sign(msgHash: string, privateKey: Hex): Promise<string>; | ||
declare function bytesToHex(uint8a: Uint8Array): string; | ||
export declare function getPublicKey(privateKey: PrivKey): Promise<Uint8Array>; | ||
export declare function sign(msgHash: Hex, privateKey: Hex): Promise<Uint8Array>; | ||
export declare function verify(sig: SigType, msgHash: Hex, publicKey: PubKey): Promise<boolean>; | ||
export declare const utils: { | ||
TORSION_SUBGROUP: string[]; | ||
bytesToHex: typeof bytesToHex; | ||
randomBytes: (bytesLength?: number) => Uint8Array; | ||
@@ -80,0 +80,0 @@ randomPrivateKey: () => Uint8Array; |
@@ -12,3 +12,2 @@ "use strict"; | ||
const _2n = BigInt(2); | ||
const _8n = BigInt(8); | ||
const _255n = BigInt(255); | ||
@@ -54,2 +53,6 @@ const CURVE = { | ||
static fromRistrettoHash(hash) { | ||
if (typeof hash === 'string') | ||
hash = hexToBytes(hash); | ||
if (hash.length !== 64) | ||
throw new Error('Invalid ristretto hash, need 64 bytes'); | ||
const r1 = bytes255ToNumberLE(hash.slice(0, B32)); | ||
@@ -84,2 +87,6 @@ const R1 = this.calcElligatorRistrettoMap(r1); | ||
static fromRistrettoBytes(bytes) { | ||
if (typeof bytes === 'string') | ||
bytes = hexToBytes(bytes); | ||
if (bytes.length !== 32) | ||
throw new Error('Invalid ristretto hash, need 64 bytes'); | ||
const { a, d } = CURVE; | ||
@@ -391,6 +398,7 @@ const emsg = 'ExtendedPoint.fromRistrettoBytes: Cannot convert bytes to Ristretto Point'; | ||
} | ||
const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0')); | ||
function bytesToHex(uint8a) { | ||
let hex = ''; | ||
for (let i = 0; i < uint8a.length; i++) { | ||
hex += uint8a[i].toString(16).padStart(2, '0'); | ||
hex += hexes[uint8a[i]]; | ||
} | ||
@@ -432,3 +440,3 @@ return hex; | ||
for (let i = 0; i < uint8a.length; i++) { | ||
value += BigInt(uint8a[i]) << (_8n * BigInt(i)); | ||
value += BigInt(uint8a[i]) << (BigInt(8) * BigInt(i)); | ||
} | ||
@@ -601,3 +609,3 @@ return value; | ||
const key = await Point.fromPrivateKey(privateKey); | ||
return typeof privateKey === 'string' ? key.toHex() : key.toRawBytes(); | ||
return key.toRawBytes(); | ||
} | ||
@@ -615,3 +623,3 @@ exports.getPublicKey = getPublicKey; | ||
const sig = new Signature(R, S); | ||
return typeof msgHash === 'string' ? sig.toHex() : sig.toRawBytes(); | ||
return sig.toRawBytes(); | ||
} | ||
@@ -629,3 +637,3 @@ exports.sign = sign; | ||
const RPh = ExtendedPoint.fromAffine(sig.r).add(Ph); | ||
return RPh.subtract(Gs).multiplyUnsafe(_8n).equals(ExtendedPoint.ZERO); | ||
return RPh.subtract(Gs).multiplyUnsafe(CURVE.h).equals(ExtendedPoint.ZERO); | ||
} | ||
@@ -649,2 +657,3 @@ exports.verify = verify; | ||
], | ||
bytesToHex, | ||
randomBytes: (bytesLength = 32) => { | ||
@@ -651,0 +660,0 @@ if (crypto.web) { |
{ | ||
"name": "@noble/ed25519", | ||
"version": "1.3.3", | ||
"version": "1.4.0", | ||
"description": "Fastest JS implementation of ed25519 & ristretto255. Auditable, high-security, 0-dependency pubkey, scalarmult & EDDSA", | ||
@@ -19,3 +19,3 @@ "files": [ | ||
"author": "Paul Miller (https://paulmillr.com)", | ||
"homepage": "https://paulmillr.com/posts/noble-secp256k1-fast-ecc/", | ||
"homepage": "https://paulmillr.com/noble/", | ||
"repository": { | ||
@@ -39,3 +39,3 @@ "type": "git", | ||
"ts-jest": "^27.1.2", | ||
"typescript": "^4.5" | ||
"typescript": "4.5.4" | ||
}, | ||
@@ -42,0 +42,0 @@ "keywords": [ |
@@ -17,3 +17,3 @@ # noble-ed25519 ![Node CI](https://github.com/paulmillr/noble-ed25519/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) | ||
- All releases are signed with PGP keys | ||
- Check out all libraries: | ||
- Check out [homepage](https://paulmillr.com/noble/) & all libraries: | ||
[secp256k1](https://github.com/paulmillr/noble-secp256k1), | ||
@@ -76,5 +76,3 @@ [ed25519](https://github.com/paulmillr/noble-ed25519), | ||
```typescript | ||
function getPublicKey(privateKey: Uint8Array): Promise<Uint8Array>; | ||
function getPublicKey(privateKey: string): Promise<string>; | ||
function getPublicKey(privateKey: bigint): Promise<Uint8Array>; | ||
function getPublicKey(privateKey: Uint8Array | string | bigint): Promise<Uint8Array>; | ||
``` | ||
@@ -84,6 +82,3 @@ - `privateKey: Uint8Array | string | bigint` will be used to generate public key. | ||
integer. The result is another `Point(x, y)` which we will by default encode to hex Uint8Array. | ||
- Returns: | ||
* `Promise<Uint8Array>` if `Uint8Array` was passed | ||
* `Promise<string>` if hex `string` was passed | ||
* Uses **promises**, because ed25519 uses SHA internally; and we're using built-in browser `window.crypto`, which returns `Promise`. | ||
- Returns `Promise<Uint8Array>`. Uses **promises**, because ed25519 uses SHA internally; and we're using built-in browser `window.crypto`, which returns `Promise`. | ||
@@ -96,4 +91,3 @@ - Use `Point.fromPrivateKey(privateKey)` if you want `Point` instance instead | ||
```typescript | ||
function sign(hash: Uint8Array, privateKey: Uint8Array): Promise<Uint8Array>; | ||
function sign(hash: string, privateKey: string): Promise<string>; | ||
function sign(hash: Uint8Array | string, privateKey: Uint8Array | string): Promise<Uint8Array>; | ||
``` | ||
@@ -124,9 +118,9 @@ - `hash: Uint8Array | string` - message hash which would be signed | ||
// The hash-to-group operation applies Elligator twice and adds the results. | ||
ExtendedPoint.fromRistrettoHash(hash: Uint8Array): ExtendedPoint; | ||
ExtendedPoint.fromRistrettoHash(hash: Uint8Array | string): ExtendedPoint; | ||
// Decode a byte-string s_bytes representing a compressed Ristretto point into extended coordinates. | ||
ExtendedPoint.fromRistrettoBytes(bytes: Uint8Array): ExtendedPoint; | ||
ExtendedPoint.fromRistrettoBytes(bytes: Uint8Array | string): ExtendedPoint; | ||
// Encode a Ristretto point represented by the point (X:Y:Z:T) in extended coordinates to Uint8Array. | ||
ExtendedPoint.toRistrettoBytes(): Uint8Array | ||
ExtendedPoint#toRistrettoBytes(): Uint8Array | ||
``` | ||
@@ -198,4 +192,4 @@ | ||
static fromAffine(point: Point): ExtendedPoint; | ||
static fromRistrettoHash(hash: Uint8Array): ExtendedPoint; | ||
static fromRistrettoBytes(bytes: Uint8Array): ExtendedPoint; | ||
static fromRistrettoHash(hash: Uint8Array | string): ExtendedPoint; | ||
static fromRistrettoBytes(bytes: Uint8Array | string): ExtendedPoint; | ||
toRistrettoBytes(): Uint8Array; | ||
@@ -202,0 +196,0 @@ toAffine(): Point; |
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
62779
1435
253