Skip to content

Commit

Permalink
refactor: Update getAwsKmsAccount and getGcpKmsAccount to use hashMes…
Browse files Browse the repository at this point in the history
…sage from thirdweb/utils (#722)
  • Loading branch information
d4mr authored Oct 10, 2024
1 parent 296f142 commit deb7908
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
13 changes: 2 additions & 11 deletions src/server/utils/wallets/getAwsKmsAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type Address,
} from "thirdweb";
import { serializeTransaction } from "thirdweb/transaction";
import { toBytes } from "thirdweb/utils";
import { hashMessage } from "thirdweb/utils";
import type { Account } from "thirdweb/wallets";
import type {
SignableMessage,
Expand Down Expand Up @@ -78,16 +78,7 @@ export async function getAwsKmsAccount(
}: {
message: SignableMessage;
}): Promise<Hex> {
let messageHash: Hex;
if (typeof message === "string") {
const prefixedMessage = `\x19Ethereum Signed Message:\n${message.length}${message}`;
messageHash = keccak256(toBytes(prefixedMessage));
} else if ("raw" in message) {
messageHash = keccak256(message.raw);
} else {
throw new Error("Invalid message format");
}

const messageHash = hashMessage(message);
const signature = await signer.sign(
Buffer.from(messageHash.slice(2), "hex"),
);
Expand Down
13 changes: 2 additions & 11 deletions src/server/utils/wallets/getGcpKmsAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
keccak256,
} from "thirdweb";
import { serializeTransaction } from "thirdweb/transaction";
import { toBytes } from "thirdweb/utils";
import { hashMessage } from "thirdweb/utils";
import type { Account } from "thirdweb/wallets";
import type {
SignableMessage,
Expand Down Expand Up @@ -98,16 +98,7 @@ export async function getGcpKmsAccount(
}: {
message: SignableMessage;
}): Promise<Hex> {
let messageHash: Hex;
if (typeof message === "string") {
const prefixedMessage = `\x19Ethereum Signed Message:\n${message.length}${message}`;
messageHash = keccak256(toBytes(prefixedMessage));
} else if ("raw" in message) {
messageHash = keccak256(message.raw);
} else {
throw new Error("Invalid message format");
}

const messageHash = hashMessage(message);
const signature = await signer.sign(Bytes.fromString(messageHash));
return signature.bytes.toString() as Hex;
}
Expand Down

0 comments on commit deb7908

Please sign in to comment.