Skip to content

Commit cf9dd82

Browse files
build(deps): bump @noble/curves from 1.8.1 to 2.0.1 (#3096)
* build(deps): bump @noble/curves from 1.8.1 to 2.0.1 Bumps [@noble/curves](https://github.com/paulmillr/noble-curves) from 1.8.1 to 2.0.1. - [Release notes](https://github.com/paulmillr/noble-curves/releases) - [Commits](paulmillr/noble-curves@1.8.1...2.0.1) --- updated-dependencies: - dependency-name: "@noble/curves" dependency-version: 2.0.1 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * account for breaking changes --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Raj Patel <rajp@ripple.com>
1 parent fe4f3ab commit cf9dd82

7 files changed

Lines changed: 34 additions & 41 deletions

File tree

package-lock.json

Lines changed: 1 addition & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ripple-keypairs/eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ module.exports = [
6767
'no-shadow': 'off',
6868
'multiline-comment-style': 'off',
6969
'@typescript-eslint/no-require-imports': 'off',
70+
'import/extensions': 'off',
7071
},
7172
},
7273
]

packages/ripple-keypairs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"test": "test"
2020
},
2121
"dependencies": {
22-
"@noble/curves": "^1.9.0",
22+
"@noble/curves": "^2.0.1",
2323
"@xrplf/isomorphic": "^1.0.1",
2424
"ripple-address-codec": "^5.0.0"
2525
},

packages/ripple-keypairs/src/signing-schemes/ed25519/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ed25519 as nobleEd25519 } from '@noble/curves/ed25519'
2-
import { bytesToHex } from '@xrplf/isomorphic/utils'
1+
import { ed25519 as nobleEd25519 } from '@noble/curves/ed25519.js'
2+
import { bytesToHex, hexToBytes } from '@xrplf/isomorphic/utils'
33

44
import type { HexString, SigningScheme } from '../../types'
55
import assert from '../../utils/assert'
@@ -25,7 +25,9 @@ const ed25519: SigningScheme = {
2525
privateKey.length === 66,
2626
'private key must be 33 bytes including prefix',
2727
)
28-
return bytesToHex(nobleEd25519.sign(message, privateKey.slice(2)))
28+
return bytesToHex(
29+
nobleEd25519.sign(message, hexToBytes(privateKey.slice(2))),
30+
)
2931
},
3032

3133
verify(
@@ -39,10 +41,10 @@ const ed25519: SigningScheme = {
3941
'public key must be 33 bytes including prefix',
4042
)
4143
return nobleEd25519.verify(
42-
signature,
44+
hexToBytes(signature),
4345
message,
4446
// Remove the 0xED prefix
45-
publicKey.slice(2),
47+
hexToBytes(publicKey.slice(2)),
4648
// By default, set zip215 to false for compatibility reasons.
4749
// ZIP 215 is a stricter Ed25519 signature verification scheme.
4850
// However, setting it to false adheres to the more commonly used

packages/ripple-keypairs/src/signing-schemes/secp256k1/index.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { numberToBytesBE } from '@noble/curves/abstract/utils'
2-
import { secp256k1 as nobleSecp256k1 } from '@noble/curves/secp256k1'
1+
import { numberToBytesBE } from '@noble/curves/utils.js'
2+
import { secp256k1 as nobleSecp256k1 } from '@noble/curves/secp256k1.js'
33
import { bytesToHex, hexToBytes } from '@xrplf/isomorphic/utils'
44

55
import type {
@@ -26,7 +26,9 @@ const secp256k1: SigningScheme = {
2626
const privateKey =
2727
SECP256K1_PREFIX + bytesToHex(numberToBytesBE(derived, 32))
2828

29-
const publicKey = bytesToHex(nobleSecp256k1.getPublicKey(derived, true))
29+
const publicKey = bytesToHex(
30+
nobleSecp256k1.getPublicKey(numberToBytesBE(derived, 32), true),
31+
)
3032
return { privateKey, publicKey }
3133
},
3234

@@ -40,27 +42,31 @@ const secp256k1: SigningScheme = {
4042
)
4143
const normedPrivateKey =
4244
privateKey.length === 66 ? privateKey.slice(2) : privateKey
43-
return nobleSecp256k1
44-
.sign(Sha512.half(message), normedPrivateKey, {
45+
return bytesToHex(
46+
nobleSecp256k1.sign(Sha512.half(message), hexToBytes(normedPrivateKey), {
4547
// "Canonical" signatures
4648
lowS: true,
4749
// Would fail tests if signatures aren't deterministic
4850
extraEntropy: undefined,
49-
})
50-
.toDERHex()
51-
.toUpperCase()
51+
format: 'der',
52+
// We pass a pre-hashed message (Sha512Half), so disable secp256k1's
53+
// default SHA-256 prehashing (added as default in @noble/curves 2.0.0)
54+
prehash: false,
55+
}),
56+
).toUpperCase()
5257
},
5358

5459
verify(
5560
message: Uint8Array,
5661
signature: HexString,
5762
publicKey: HexString,
5863
): boolean {
59-
const decoded = nobleSecp256k1.Signature.fromDER(signature)
64+
const decoded = nobleSecp256k1.Signature.fromHex(signature, 'der')
6065
return nobleSecp256k1.verify(
61-
decoded.toCompactRawBytes(),
66+
decoded.toBytes('compact'),
6267
Sha512.half(message),
6368
hexToBytes(publicKey),
69+
{ prehash: false },
6470
)
6571
},
6672
}

packages/ripple-keypairs/src/signing-schemes/secp256k1/utils.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { secp256k1 } from '@noble/curves/secp256k1'
1+
import { secp256k1 } from '@noble/curves/secp256k1.js'
22

33
import Sha512 from '../../utils/Sha512'
44

55
const ZERO = BigInt(0)
66

77
function deriveScalar(bytes: Uint8Array, discrim?: number): bigint {
8-
const order = secp256k1.CURVE.n
8+
const order = secp256k1.Point.CURVE().n
99
for (let i = 0; i <= 0xffff_ffff; i++) {
1010
// We hash the bytes to find a 256-bit number, looping until we are sure it
1111
// is less than the order of the curve.
@@ -49,7 +49,7 @@ export function derivePrivateKey(
4949
} = {},
5050
): bigint {
5151
const root = opts.validator
52-
const order = secp256k1.CURVE.n
52+
const order = secp256k1.Point.CURVE().n
5353

5454
// This private generator represents the `root` private key, and is what's
5555
// used by validators for signing when a keypair is generated from a seed.
@@ -58,18 +58,17 @@ export function derivePrivateKey(
5858
// As returned by validation_create for a given seed
5959
return privateGen
6060
}
61-
const publicGen =
62-
secp256k1.ProjectivePoint.BASE.multiply(privateGen).toRawBytes(true)
61+
const publicGen = secp256k1.Point.BASE.multiply(privateGen).toBytes(true)
6362
// A seed can generate many keypairs as a function of the seed and a uint32.
6463
// Almost everyone just uses the first account, `0`.
6564
const accountIndex = opts.accountIndex || 0
6665
return (deriveScalar(publicGen, accountIndex) + privateGen) % order
6766
}
6867

6968
export function accountPublicFromPublicGenerator(publicGenBytes: Uint8Array) {
70-
const rootPubPoint = secp256k1.ProjectivePoint.fromHex(publicGenBytes)
69+
const rootPubPoint = secp256k1.Point.fromBytes(publicGenBytes)
7170
const scalar = deriveScalar(publicGenBytes, 0)
72-
const point = secp256k1.ProjectivePoint.BASE.multiply(scalar)
71+
const point = secp256k1.Point.BASE.multiply(scalar)
7372
const offset = rootPubPoint.add(point)
74-
return offset.toRawBytes(true)
73+
return offset.toBytes(true)
7574
}

packages/ripple-keypairs/src/utils/Sha512.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { sha512 } from '@xrplf/isomorphic/sha512'
2-
import { bytesToNumberBE } from '@noble/curves/abstract/utils'
2+
import { bytesToNumberBE } from '@noble/curves/utils.js'
33

44
type Input = Uint8Array | number[] | string
55

0 commit comments

Comments
 (0)