Skip to content

Conversation

@hieu-w
Copy link
Contributor

@hieu-w hieu-w commented Jan 28, 2026

Motivation and Context

Jira Link:

Description

  • Replace elliptic by @noble/curves ver 2
  • Remove Buffer

How has this been tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project. (run lint)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My code requires a db migration.

Note

High Risk
Replaces the core ECC implementation used for ECDSA/ECDH/ECIES and changes binary types from Buffer to Uint8Array, which can affect cryptographic correctness and downstream integrations despite added compatibility tests.

Overview
Migrates the cryptography backend from elliptic to @noble/curves (secp256k1) and switches the public API to use Uint8Array end-to-end (including Ecies fields), removing Buffer-centric helpers.

Updates ECDSA/ECDH/ECIES implementations and validation: sign/verify now use noble DER signatures, derive now returns an unpadded shared secret with leading zeros stripped (with derivePadded preserved for fixed 32-byte output), and decrypt retries MAC verification using the padded derivation for backward compatibility.

Refreshes docs and tests accordingly, adds a node-only backward_compatibility.spec.ts that compares outputs against an aliased old package (eccrypto-old), removes browser Buffer setup, and adjusts browser test config to exclude the compatibility suite. Dependencies are updated to add @noble/curves and remove elliptic from runtime deps.

Written by Cursor Bugbot for commit 30804ed. This will update automatically on new commits. Configure here.

@hieu-w hieu-w force-pushed the feat/noble-curve-replacement branch from 8feec72 to be75748 Compare January 28, 2026 15:24
@hieu-w hieu-w self-assigned this Jan 28, 2026
@hieu-w hieu-w force-pushed the feat/noble-curve-replacement branch from 1ac76a6 to c6f6dce Compare January 29, 2026 04:44
This reverts commit 55af097.
Copy link

@ieow ieow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

opts?: { iv?: Buffer; ephemPrivateKey?: Buffer; padding?: boolean }
publicKeyTo: Uint8Array,
msg: Uint8Array,
opts?: { iv?: Uint8Array; ephemPrivateKey?: Uint8Array }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove the option of padding?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as @ieow confirm we dont need the encryption with padded, the standard is unpadded

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should follow the standard for asymmetric encryption here

we have the fallback to unpadded in the decryption.
we also need to double check the server have the similar fallback

src/index.ts Outdated
// that used elliptic's BN.toArray() which didn't include leading zeros.
// Use derivePadded() if you need a fixed 32-byte output.
const sharedSecret = secp256k1.getSharedSecret(privateKeyA, publicKeyB);
const Px = sharedSecret.subarray(sharedSecret.length - 32);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sharedSecret is always 33 bytes. you can just slice the first byte to get Px.
Can u try this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated, use subArray instead slice, for better performance, slice need one copy.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@ieow ieow mentioned this pull request Feb 2, 2026
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants