Skip to content

Commit

Permalink
feat: isHexString -> isHex
Browse files Browse the repository at this point in the history
  • Loading branch information
gomesalexandre committed Feb 26, 2024
1 parent 9fc699e commit 7692536
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/hdwallet-coinbase/src/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import { ETHSignedMessage } from "@shapeshiftoss/hdwallet-core";
import { isHexString } from "ethers";
import { isHex } from "viem";

export function describeETHPath(path: core.BIP32Path): core.PathDescription {
return core.describeETHPath(path);
Expand Down Expand Up @@ -86,7 +86,7 @@ export async function ethSignMessage(
address: string
): Promise<core.ETHSignedMessage | null> {
try {
if (!isHexString(msg.message)) throw new Error("data is not an hex string");
if (!isHex(msg.message)) throw new Error("data is not an hex string");
const signedMsg = await ethereum.request({
method: "personal_sign",
params: [msg, address],
Expand Down
5 changes: 3 additions & 2 deletions packages/hdwallet-keepkey/src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as Types from "@keepkey/device-protocol/lib/types_pb";
import { SignTypedDataVersion, TypedDataUtils } from "@metamask/eth-sig-util";
import * as core from "@shapeshiftoss/hdwallet-core";
import * as eip55 from "eip55";
import { getBytes, isBytesLike, isHexString } from "ethers";
import { getBytes, isBytesLike } from "ethers";
import { isHex } from "viem";

import { Transport } from "./transport";
import { toUTF8Array } from "./utils";
Expand Down Expand Up @@ -173,7 +174,7 @@ export async function ethGetAddress(transport: Transport, msg: core.ETHGetAddres

export async function ethSignMessage(transport: Transport, msg: core.ETHSignMessage): Promise<core.ETHSignedMessage> {
const { addressNList, message } = msg;
if (!isHexString(message)) throw new Error("data is not an hex string");
if (!isHex(message)) throw new Error("data is not an hex string");
const m = new Ethereum.EthereumSignMessage();
m.setAddressNList(addressNList);
const messageBytes = getBytes(message);
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-ledger/src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import EthereumTx from "ethereumjs-tx";
// TODO: fix ts-ignore
import * as ethereumUtil from "ethereumjs-util";
import { getBytes, isBytesLike } from "ethers";
import { isHexString } from "ethjs-util";
import { isHex } from "viem";

import { LedgerTransport } from "./transport";
import { compressPublicKey, createXpub, handleError, networksUtil } from "./utils";
Expand Down Expand Up @@ -159,7 +159,7 @@ export async function ethSignMessage(
): Promise<core.ETHSignedMessage> {
const bip32path = core.addressNListToBIP32(msg.addressNList);

if (!isHexString(msg.message)) throw new Error("data is not an hex string");
if (!isHex(msg.message)) throw new Error("data is not an hex string");

// Ledger's inner implementation does a Buffer.from(messageHex, "hex").length on our message
// However, Buffer.from method with the "hex" encoding expects a valid hexadecimal string without the 0x prefix
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import { ETHSignedMessage } from "@shapeshiftoss/hdwallet-core";
import { isHexString } from "ethers";
import { isHex } from "viem";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function ethVerifyMessage(msg: core.ETHVerifyMessage, ethereum: any): Promise<boolean | null> {
Expand Down Expand Up @@ -71,7 +71,7 @@ export async function ethSignMessage(
address: string
): Promise<core.ETHSignedMessage | null> {
try {
if (!isHexString(msg.message)) throw new Error("data is not an hex string");
if (!isHex(msg.message)) throw new Error("data is not an hex string");
const signedMsg = await ethereum.request({
method: "personal_sign",
params: [msg.message, address],
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-metamask/src/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import { ETHSignedMessage } from "@shapeshiftoss/hdwallet-core";
import { isHexString } from "ethers";
import { isHex } from "viem";

export function describeETHPath(path: core.BIP32Path): core.PathDescription {
const pathStr = core.addressNListToBIP32(path);
Expand Down Expand Up @@ -101,7 +101,7 @@ export async function ethSignMessage(
address: string
): Promise<core.ETHSignedMessage | null> {
try {
if (!isHexString(msg.message)) throw new Error("data is not an hex string");
if (!isHex(msg.message)) throw new Error("data is not an hex string");
const signedMsg = await ethereum.request({
method: "personal_sign",
params: [msg.message, address],
Expand Down
5 changes: 3 additions & 2 deletions packages/hdwallet-native/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import type { BytesLike } from "ethers";
import { concat, getBytes, isHexString, toUtf8Bytes } from "ethers";
import { concat, getBytes, toUtf8Bytes } from "ethers";
import { isHex } from "viem";

import { BTCScriptType } from "./bitcoin";
import * as Isolation from "./crypto/isolation";
Expand All @@ -19,7 +20,7 @@ export async function getKeyPair(
}

export function buildMessage(message: BytesLike): Uint8Array {
const messageBytes = typeof message === "string" && !isHexString(message) ? toUtf8Bytes(message) : getBytes(message);
const messageBytes = typeof message === "string" && !isHex(message) ? toUtf8Bytes(message) : getBytes(message);

return getBytes(
concat([toUtf8Bytes("\x19Ethereum Signed Message:\n"), toUtf8Bytes(String(messageBytes.length)), messageBytes])
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-portis/src/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import { isHexString } from "ethers";
import { isHex } from "viem";

export function describeETHPath(path: core.BIP32Path): core.PathDescription {
const pathStr = core.addressNListToBIP32(path);
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function ethSignMessage(
web3: any,
address: string
): Promise<core.ETHSignedMessage> {
if (!isHexString(msg.message)) throw new Error("data is not an hex string");
if (!isHex(msg.message)) throw new Error("data is not an hex string");
const result = await web3.eth.sign(msg.message, address);
return {
address,
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-tallyho/src/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import { isHexString } from "ethers";
import { isHex } from "viem";

export function describeETHPath(path: core.BIP32Path): core.PathDescription {
const pathStr = core.addressNListToBIP32(path);
Expand Down Expand Up @@ -100,7 +100,7 @@ export async function ethSignMessage(
address: string
): Promise<core.ETHSignedMessage | null> {
try {
if (!isHexString(msg.message)) throw new Error("data is not an hex string");
if (!isHex(msg.message)) throw new Error("data is not an hex string");
const signedMsg = await ethereum.request({
method: "personal_sign",
params: [msg.message, address],
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-trezor/src/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Common from "@ethereumjs/common";
import { Transaction } from "@ethereumjs/tx";
import * as core from "@shapeshiftoss/hdwallet-core";
import { isHexString } from "ethers";
import { isHex } from "viem";

import { TrezorTransport } from "./transport";
import { handleError } from "./utils";
Expand Down Expand Up @@ -74,7 +74,7 @@ export async function ethSignMessage(
transport: TrezorTransport,
msg: core.ETHSignMessage
): Promise<core.ETHSignedMessage> {
if (!isHexString(msg.message)) throw new Error("data is not an hex string");
if (!isHex(msg.message)) throw new Error("data is not an hex string");
const res = await transport.call("ethereumSignMessage", {
path: msg.addressNList,
message: msg.message,
Expand Down
5 changes: 3 additions & 2 deletions packages/hdwallet-walletconnect/src/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import { BytesLike, isHexString } from "ethers";
import { BytesLike } from "ethers";
import { isHex } from "viem";

export function describeETHPath(path: core.BIP32Path): core.PathDescription {
const pathStr = core.addressNListToBIP32(path);
Expand Down Expand Up @@ -54,7 +55,7 @@ export async function ethSignMessage(
args: { data: BytesLike; fromAddress: string },
provider: any
): Promise<core.ETHSignedMessage | null> {
if (!isHexString(args.data)) throw new Error("data is not an hex string");
if (!isHex(args.data)) throw new Error("data is not an hex string");
return await provider.wc.signMessage([args.data, args.fromAddress]);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-walletconnectV2/src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
} from "@shapeshiftoss/hdwallet-core";
import { addressNListToBIP32, slip44ByCoin } from "@shapeshiftoss/hdwallet-core";
import EthereumProvider from "@walletconnect/ethereum-provider";
import { isHexString } from "ethers";
import { isHex } from "viem";

const getUnsignedTxFromMessage = (msg: ETHSignTx & { from: string }) => {
const utxBase = {
Expand Down Expand Up @@ -86,7 +86,7 @@ export async function ethSignMessage(
args: { data: string; fromAddress: string },
provider: EthereumProvider
): Promise<ETHSignedMessage | null> {
if (!isHexString(args.data)) throw new Error("data is not an hex string");
if (!isHex(args.data)) throw new Error("data is not an hex string");

const signedMsg: string = await provider.request({
method: "personal_sign",
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-xdefi/src/ethereum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from "@shapeshiftoss/hdwallet-core";
import { ETHSignedMessage } from "@shapeshiftoss/hdwallet-core";
import { isHexString } from "ethers";
import { isHex } from "viem";

export async function ethVerifyMessage(msg: core.ETHVerifyMessage, ethereum: any): Promise<boolean | null> {
const recoveredAddress = await ethereum.request({
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function ethSignMessage(
address: string
): Promise<core.ETHSignedMessage | null> {
try {
if (!isHexString(msg.message)) throw new Error("data is not an hex string");
if (!isHex(msg.message)) throw new Error("data is not an hex string");
const signedMsg = await ethereum.request({
method: "personal_sign",
params: [msg.message, address],
Expand Down

0 comments on commit 7692536

Please sign in to comment.