-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upgrade to @noble/curves (#947)
* chore: update @farcaster/core to use @noble/curves * chore: update hubble to use @noble/curves * add changeset new file: .changeset/eleven-lies-wait.md * preserve async interface * update changeset
- Loading branch information
Showing
11 changed files
with
46 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@farcaster/core': minor | ||
'@farcaster/hubble': patch | ||
'@farcaster/hub-nodejs': patch | ||
'@farcaster/hub-web': patch | ||
--- | ||
|
||
replace @noble/ed25519 with faster and more secure @noble/curves |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,23 @@ | ||
import * as ed from '@noble/ed25519'; | ||
import { sha512 } from '@noble/hashes/sha512'; | ||
import { ResultAsync } from 'neverthrow'; | ||
import { ed25519 } from '@noble/curves/ed25519'; | ||
import { Result } from 'neverthrow'; | ||
import { HubAsyncResult, HubError } from '../errors'; | ||
|
||
/** Setup ed to hash synchronously */ | ||
ed.utils.sha512Sync = (...m) => sha512(ed.utils.concatBytes(...m)); | ||
|
||
export const getPublicKeySync = (privateKey: Uint8Array): Uint8Array => { | ||
return ed.sync.getPublicKey(privateKey); | ||
}; | ||
const safeGetPublicKey = Result.fromThrowable(ed25519.getPublicKey, (err) => new HubError('bad_request', err as Error)); | ||
const safeSign = Result.fromThrowable(ed25519.sign, (err) => new HubError('bad_request', err as Error)); | ||
const safeVerify = Result.fromThrowable(ed25519.verify, (err) => new HubError('bad_request', err as Error)); | ||
|
||
export const getPublicKey = async (privateKey: Uint8Array): HubAsyncResult<Uint8Array> => { | ||
return ResultAsync.fromPromise(ed.getPublicKey(privateKey), (err) => new HubError('bad_request', err as Error)); | ||
return safeGetPublicKey(privateKey); | ||
}; | ||
|
||
export const signMessageHash = async (hash: Uint8Array, privateKey: Uint8Array): HubAsyncResult<Uint8Array> => { | ||
return ResultAsync.fromPromise(ed.sign(hash, privateKey), (err) => new HubError('bad_request', err as Error)); | ||
return safeSign(hash, privateKey); | ||
}; | ||
|
||
export const verifyMessageHashSignature = async ( | ||
signature: Uint8Array, | ||
hash: Uint8Array, | ||
publicKey: Uint8Array | ||
): HubAsyncResult<boolean> => { | ||
return ResultAsync.fromPromise( | ||
ed.verify(signature, hash, publicKey), | ||
(err) => new HubError('bad_request', err as Error) | ||
); | ||
return safeVerify(signature, hash, publicKey); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters