@stablelib/ed25519
Advanced tools
Comparing version 0.10.9 to 0.11.0
@@ -851,1 +851,40 @@ // Copyright (C) 2016 Dmitry Chestnykh | ||
} | ||
/** | ||
* Convert Ed25519 public key to X5519 public key. | ||
* | ||
* Throws if given an invalid public key. | ||
*/ | ||
export function convertPublicKeyToX25519(publicKey: Uint8Array): Uint8Array { | ||
let q = [gf(), gf(), gf(), gf()]; | ||
if (unpackneg(q, publicKey)) { | ||
throw new Error("Ed25519: invalid public key"); | ||
} | ||
// Formula: montgomeryX = (edwardsY + 1)*inverse(1 - edwardsY) mod p | ||
let a = gf(); | ||
let b = gf(); | ||
let y = q[1]; | ||
add(a, gf1, y); | ||
sub(b, gf1, y); | ||
inv25519(b, b); | ||
mul(a, a, b); | ||
let z = new Uint8Array(32); | ||
pack25519(z, a); | ||
return z; | ||
} | ||
/** | ||
* Convert Ed25519 secret (private) key to X25519 secret key. | ||
*/ | ||
export function convertSecretKeyToX25519(secretKey: Uint8Array): Uint8Array { | ||
const d = hash(secretKey.subarray(0, 32)); | ||
d[0] &= 248; | ||
d[31] &= 127; | ||
d[31] |= 64; | ||
const o = new Uint8Array(d.subarray(0, 32)); | ||
wipe(d); | ||
return o; | ||
} |
@@ -15,1 +15,11 @@ import { RandomSource } from "@stablelib/random"; | ||
export declare function verify(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): boolean; | ||
/** | ||
* Convert Ed25519 public key to X5519 public key. | ||
* | ||
* Throws if given an invalid public key. | ||
*/ | ||
export declare function convertPublicKeyToX25519(publicKey: Uint8Array): Uint8Array; | ||
/** | ||
* Convert Ed25519 secret (private) key to X25519 secret key. | ||
*/ | ||
export declare function convertSecretKeyToX25519(secretKey: Uint8Array): Uint8Array; |
@@ -808,2 +808,38 @@ "use strict"; | ||
exports.verify = verify; | ||
/** | ||
* Convert Ed25519 public key to X5519 public key. | ||
* | ||
* Throws if given an invalid public key. | ||
*/ | ||
function convertPublicKeyToX25519(publicKey) { | ||
var q = [gf(), gf(), gf(), gf()]; | ||
if (unpackneg(q, publicKey)) { | ||
throw new Error("Ed25519: invalid public key"); | ||
} | ||
// Formula: montgomeryX = (edwardsY + 1)*inverse(1 - edwardsY) mod p | ||
var a = gf(); | ||
var b = gf(); | ||
var y = q[1]; | ||
add(a, gf1, y); | ||
sub(b, gf1, y); | ||
inv25519(b, b); | ||
mul(a, a, b); | ||
var z = new Uint8Array(32); | ||
pack25519(z, a); | ||
return z; | ||
} | ||
exports.convertPublicKeyToX25519 = convertPublicKeyToX25519; | ||
/** | ||
* Convert Ed25519 secret (private) key to X25519 secret key. | ||
*/ | ||
function convertSecretKeyToX25519(secretKey) { | ||
var d = sha512_1.hash(secretKey.subarray(0, 32)); | ||
d[0] &= 248; | ||
d[31] &= 127; | ||
d[31] |= 64; | ||
var o = new Uint8Array(d.subarray(0, 32)); | ||
wipe_1.wipe(d); | ||
return o; | ||
} | ||
exports.convertSecretKeyToX25519 = convertSecretKeyToX25519; | ||
//# sourceMappingURL=ed25519.js.map |
{ | ||
"name": "@stablelib/ed25519", | ||
"version": "0.10.9", | ||
"version": "0.11.0", | ||
"description": "Ed25519 public-key signature (EdDSA with Curve25519)", | ||
@@ -26,3 +26,3 @@ "main": "./lib/ed25519.js", | ||
}, | ||
"gitHead": "cd823c5ca890d18b9abd28aae7af728013e7ef9b" | ||
"gitHead": "bfc2e6b7c9c3f31c7bb3610b8a0c09d3ef3613ca" | ||
} |
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 too big to display
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
2002685
16583