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

@stablelib/ed25519

Package Overview
Dependencies
Maintainers
0
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stablelib/ed25519 - npm Package Compare versions

Comparing version 1.0.3 to 2.0.0

typedoc.json

3

ed25519.ts

@@ -8,3 +8,4 @@ // Copyright (C) 2016 Dmitry Chestnykh

import { randomBytes, RandomSource } from "@stablelib/random";
import type { RandomSource } from "@stablelib/random";
import { randomBytes } from "@stablelib/random";
import { hash, SHA512 } from "@stablelib/sha512";

@@ -11,0 +12,0 @@ import { wipe } from "@stablelib/wipe";

@@ -1,17 +0,15 @@

"use strict";
// Copyright (C) 2016 Dmitry Chestnykh
// MIT License. See LICENSE file for details.
Object.defineProperty(exports, "__esModule", { value: true });
const ed25519_1 = require("./ed25519");
const benchmark_1 = require("@stablelib/benchmark");
const k = (0, ed25519_1.generateKeyPair)();
import { sign, verify, generateKeyPairFromSeed, generateKeyPair } from "./ed25519";
import { benchmark, report } from "@stablelib/benchmark";
const k = generateKeyPair();
const buf = new Uint8Array(256);
const seed = k.secretKey.subarray(0, 32);
const sig = (0, ed25519_1.sign)(k.secretKey, buf);
const sig = sign(k.secretKey, buf);
const badsig = new Uint8Array(sig);
badsig[0] = 1;
(0, benchmark_1.report)("ed25519.generateKeyPairFromSeed", (0, benchmark_1.benchmark)(() => (0, ed25519_1.generateKeyPairFromSeed)(seed)));
(0, benchmark_1.report)("ed25519.sign", (0, benchmark_1.benchmark)(() => (0, ed25519_1.sign)(k.secretKey, buf)));
(0, benchmark_1.report)("ed25519.verify", (0, benchmark_1.benchmark)(() => (0, ed25519_1.verify)(k.publicKey, buf, sig)));
(0, benchmark_1.report)("ed25519.verify (bad)", (0, benchmark_1.benchmark)(() => (0, ed25519_1.verify)(k.publicKey, buf, badsig)));
report("ed25519.generateKeyPairFromSeed", benchmark(() => generateKeyPairFromSeed(seed)));
report("ed25519.sign", benchmark(() => sign(k.secretKey, buf)));
report("ed25519.verify", benchmark(() => verify(k.publicKey, buf, sig)));
report("ed25519.verify (bad)", benchmark(() => verify(k.publicKey, buf, badsig)));
//# sourceMappingURL=ed25519.bench.js.map
/**
* Package ed25519 implements Ed25519 public-key signature algorithm.
*/
import { RandomSource } from "@stablelib/random";
import type { RandomSource } from "@stablelib/random";
export declare const SIGNATURE_LENGTH = 64;

@@ -6,0 +6,0 @@ export declare const PUBLIC_KEY_LENGTH = 32;

@@ -1,16 +0,10 @@

"use strict";
// Copyright (C) 2016 Dmitry Chestnykh
// MIT License. See LICENSE file for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertSecretKeyToX25519 = exports.convertPublicKeyToX25519 = exports.verify = exports.sign = exports.extractPublicKeyFromSecretKey = exports.generateKeyPair = exports.generateKeyPairFromSeed = exports.SEED_LENGTH = exports.SECRET_KEY_LENGTH = exports.PUBLIC_KEY_LENGTH = exports.SIGNATURE_LENGTH = void 0;
/**
* Package ed25519 implements Ed25519 public-key signature algorithm.
*/
const random_1 = require("@stablelib/random");
const sha512_1 = require("@stablelib/sha512");
const wipe_1 = require("@stablelib/wipe");
exports.SIGNATURE_LENGTH = 64;
exports.PUBLIC_KEY_LENGTH = 32;
exports.SECRET_KEY_LENGTH = 64;
exports.SEED_LENGTH = 32;
import { randomBytes } from "@stablelib/random";
import { hash, SHA512 } from "@stablelib/sha512";
import { wipe } from "@stablelib/wipe";
export const SIGNATURE_LENGTH = 64;
export const PUBLIC_KEY_LENGTH = 32;
export const SECRET_KEY_LENGTH = 64;
export const SEED_LENGTH = 32;
// Returns new zero-filled 16-element GF (Float64Array).

@@ -638,7 +632,7 @@ // If passed an array of numbers, prefills the returned

// Generates key pair from secret 32-byte seed.
function generateKeyPairFromSeed(seed) {
if (seed.length !== exports.SEED_LENGTH) {
throw new Error(`ed25519: seed must be ${exports.SEED_LENGTH} bytes`);
export function generateKeyPairFromSeed(seed) {
if (seed.length !== SEED_LENGTH) {
throw new Error(`ed25519: seed must be ${SEED_LENGTH} bytes`);
}
const d = (0, sha512_1.hash)(seed);
const d = hash(seed);
d[0] &= 248;

@@ -659,17 +653,14 @@ d[31] &= 127;

}
exports.generateKeyPairFromSeed = generateKeyPairFromSeed;
function generateKeyPair(prng) {
const seed = (0, random_1.randomBytes)(32, prng);
export function generateKeyPair(prng) {
const seed = randomBytes(32, prng);
const result = generateKeyPairFromSeed(seed);
(0, wipe_1.wipe)(seed);
wipe(seed);
return result;
}
exports.generateKeyPair = generateKeyPair;
function extractPublicKeyFromSecretKey(secretKey) {
if (secretKey.length !== exports.SECRET_KEY_LENGTH) {
throw new Error(`ed25519: secret key must be ${exports.SECRET_KEY_LENGTH} bytes`);
export function extractPublicKeyFromSecretKey(secretKey) {
if (secretKey.length !== SECRET_KEY_LENGTH) {
throw new Error(`ed25519: secret key must be ${SECRET_KEY_LENGTH} bytes`);
}
return new Uint8Array(secretKey.subarray(32));
}
exports.extractPublicKeyFromSecretKey = extractPublicKeyFromSecretKey;
const L = new Float64Array([

@@ -719,6 +710,6 @@ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2,

// Returns 64-byte signature of the message under the 64-byte secret key.
function sign(secretKey, message) {
export function sign(secretKey, message) {
const x = new Float64Array(64);
const p = [gf(), gf(), gf(), gf()];
const d = (0, sha512_1.hash)(secretKey.subarray(0, 32));
const d = hash(secretKey.subarray(0, 32));
d[0] &= 248;

@@ -729,3 +720,3 @@ d[31] &= 127;

signature.set(d.subarray(32), 32);
const hs = new sha512_1.SHA512();
const hs = new SHA512();
hs.update(signature.subarray(32));

@@ -755,3 +746,2 @@ hs.update(message);

}
exports.sign = sign;
function unpackneg(r, p) {

@@ -791,8 +781,8 @@ const t = gf(), chk = gf(), num = gf(), den = gf(), den2 = gf(), den4 = gf(), den6 = gf();

}
function verify(publicKey, message, signature) {
export function verify(publicKey, message, signature) {
const t = new Uint8Array(32);
const p = [gf(), gf(), gf(), gf()];
const q = [gf(), gf(), gf(), gf()];
if (signature.length !== exports.SIGNATURE_LENGTH) {
throw new Error(`ed25519: signature must be ${exports.SIGNATURE_LENGTH} bytes`);
if (signature.length !== SIGNATURE_LENGTH) {
throw new Error(`ed25519: signature must be ${SIGNATURE_LENGTH} bytes`);
}

@@ -802,3 +792,3 @@ if (unpackneg(q, publicKey)) {

}
const hs = new sha512_1.SHA512();
const hs = new SHA512();
hs.update(signature.subarray(0, 32));

@@ -818,3 +808,2 @@ hs.update(publicKey);

}
exports.verify = verify;
/**

@@ -825,3 +814,3 @@ * Convert Ed25519 public key to X25519 public key.

*/
function convertPublicKeyToX25519(publicKey) {
export function convertPublicKeyToX25519(publicKey) {
let q = [gf(), gf(), gf(), gf()];

@@ -843,8 +832,7 @@ if (unpackneg(q, publicKey)) {

}
exports.convertPublicKeyToX25519 = convertPublicKeyToX25519;
/**
* Convert Ed25519 secret (private) key to X25519 secret key.
*/
function convertSecretKeyToX25519(secretKey) {
const d = (0, sha512_1.hash)(secretKey.subarray(0, 32));
export function convertSecretKeyToX25519(secretKey) {
const d = hash(secretKey.subarray(0, 32));
d[0] &= 248;

@@ -854,6 +842,5 @@ d[31] &= 127;

const o = new Uint8Array(d.subarray(0, 32));
(0, wipe_1.wipe)(d);
wipe(d);
return o;
}
exports.convertSecretKeyToX25519 = convertSecretKeyToX25519;
//# sourceMappingURL=ed25519.js.map
{
"name": "@stablelib/ed25519",
"version": "1.0.3",
"version": "2.0.0",
"description": "Ed25519 public-key signature (EdDSA with Curve25519)",
"main": "./lib/ed25519.js",
"type": "module",
"typings": "./lib/ed25519.d.ts",

@@ -18,15 +19,15 @@ "author": "Dmitry Chestnykh",

"build": "tsc",
"test": "jasmine JASMINE_CONFIG_PATH=../../configs/jasmine.json",
"test": "vitest run",
"bench": "node ./lib/ed25519.bench.js"
},
"dependencies": {
"@stablelib/random": "^1.0.2",
"@stablelib/sha512": "^1.0.1",
"@stablelib/wipe": "^1.0.1"
"@stablelib/random": "^2.0.0",
"@stablelib/sha512": "^2.0.0",
"@stablelib/wipe": "^2.0.0"
},
"devDependencies": {
"@stablelib/base64": "^1.0.1",
"@stablelib/benchmark": "^1.0.1"
"@stablelib/base64": "^2.0.0",
"@stablelib/benchmark": "^2.0.0"
},
"gitHead": "a402dc74f45c6a93a777a0e2840ce50ba68c3010"
"gitHead": "ecfe9109b3c05419fd3ffc16da6c8255b08ad64f"
}

Sorry, the diff of this file is too big to display

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 too big to display

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