Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmaayan committed Apr 2, 2024
1 parent 4520ccd commit 714c990
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/core/crypto/ed25519.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { CKDPriv, deriveKey, HARDENED_OFFSET, isValidHardenedPath, mnemonicToSee
import { PrivateKey } from "./privateKey";
import { AccountPublicKey, VerifySignatureArgs } from "./publicKey";
import { Signature } from "./signature";
import { convertMessage } from "./utils";
import { convertSigningMessage } from "./utils";

/**
* Represents the public key of an Ed25519 key pair.
Expand Down Expand Up @@ -61,7 +61,7 @@ export class Ed25519PublicKey extends AccountPublicKey {
if (!(signature instanceof Ed25519Signature)) {
return false;
}
const messageToVerify = convertMessage(message);
const messageToVerify = convertSigningMessage(message);
const messageBytes = Hex.fromHexInput(messageToVerify).toUint8Array();
const signatureBytes = signature.toUint8Array();
const publicKeyBytes = this.key.toUint8Array();
Expand Down Expand Up @@ -214,11 +214,11 @@ export class Ed25519PrivateKey extends Serializable implements PrivateKey {
/**
* Sign the given message with the private key.
*
* @param message a message as a Hex string or Uint8Array
* @param message a message as a string or Uint8Array
* @returns Signature
*/
sign(message: HexInput): Ed25519Signature {
const messageToSign = convertMessage(message);
const messageToSign = convertSigningMessage(message);
const messageBytes = Hex.fromHexInput(messageToSign).toUint8Array();
const signatureBytes = nacl.sign.detached(messageBytes, this.signingKeyPair.secretKey);
return new Ed25519Signature(signatureBytes);
Expand Down
8 changes: 4 additions & 4 deletions src/core/crypto/secp256k1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { isValidBIP44Path, mnemonicToSeed } from "./hdKey";
import { PrivateKey } from "./privateKey";
import { PublicKey, VerifySignatureArgs } from "./publicKey";
import { Signature } from "./signature";
import { convertMessage } from "./utils";
import { convertSigningMessage } from "./utils";

/**
* Represents the Secp256k1 ecdsa public key
Expand Down Expand Up @@ -47,7 +47,7 @@ export class Secp256k1PublicKey extends PublicKey {
if (!(signature instanceof Secp256k1Signature)) {
return false;
}
const messageToVerify = convertMessage(message);
const messageToVerify = convertSigningMessage(message);
const messageBytes = Hex.fromHexInput(messageToVerify).toUint8Array();
const messageSha3Bytes = sha3_256(messageBytes);
const signatureBytes = signature.toUint8Array();
Expand Down Expand Up @@ -166,11 +166,11 @@ export class Secp256k1PrivateKey extends Serializable implements PrivateKey {
/**
* Sign the given message with the private key.
*
* @param message in HexInput format
* @param message a message as a string or Uint8Array
* @returns Signature
*/
sign(message: HexInput): Secp256k1Signature {
const messageToSign = convertMessage(message);
const messageToSign = convertSigningMessage(message);
const messageBytes = Hex.fromHexInput(messageToSign);
const messageHashBytes = sha3_256(messageBytes.toUint8Array());
const signature = secp256k1.sign(messageHashBytes, this.key.toUint8Array());
Expand Down
4 changes: 2 additions & 2 deletions src/core/crypto/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { Hex } from "../hex";
*
* @param message a message as a string or Uint8Array
*
* @returns a valid HexInput - Hex string or Uint8Array
* @returns a valid HexInput - string or Uint8Array
*/
export const convertMessage = (message: HexInput): HexInput => {
export const convertSigningMessage = (message: HexInput): HexInput => {
// if message is of type string, verify it is a valid Hex string
if (typeof message === "string") {
const isValid = Hex.isValid(message);
Expand Down

0 comments on commit 714c990

Please sign in to comment.