Skip to content

Commit

Permalink
Use @noble/curves for x25519 implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Oct 30, 2023
1 parent 352e0d1 commit fd07215
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Changed
- **BREAKING**: Require node >= 18.
- Use `@noble/ed25519` to provide X25519 implementation. This lib
- Use `@noble/curves` to provide X25519 implementation. This lib
is often used in other libs that are combined with this one and
it has been through a comprehensive security audit. Additional
benefits include speed and tree-shaking capabilities.
Expand Down
8 changes: 4 additions & 4 deletions lib/algorithms/x25519-helper-browser.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*!
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2019-2023 Digital Bazaar, Inc. All rights reserved.
*/
import * as base64url from 'base64url-universal';
import crypto from '../crypto.js';
import {curve25519} from '@noble/ed25519';
import {x25519} from '@noble/curves/ed25519';

export async function generateEphemeralKeyPair() {
// generate X25519 ephemeral public key
const privateKey = await crypto.getRandomValues(new Uint8Array(32));
const publicKey = curve25519.scalarMultBase(privateKey);
const publicKey = x25519.scalarMultBase(privateKey);
return {
privateKey,
publicKey,
Expand All @@ -22,5 +22,5 @@ export async function generateEphemeralKeyPair() {

export async function deriveSecret({privateKey, remotePublicKey}) {
// `scalarMult` takes secret key as param 1, public key as param 2
return curve25519.scalarMult(privateKey, remotePublicKey);
return x25519.scalarMult(privateKey, remotePublicKey);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"lint": "eslint ."
},
"dependencies": {
"@noble/ed25519": "^1.6.1",
"@noble/curves": "^1.2.0",
"@stablelib/chacha": "^1.0.1",
"@stablelib/chacha20poly1305": "^1.0.1",
"base58-universal": "^2.0.0",
Expand Down

0 comments on commit fd07215

Please sign in to comment.