@@ -5,14 +5,16 @@ import {
55 serializeTypedData ,
66 stringify ,
77 validateTypedData ,
8+ verifyMessage ,
9+ hashMessage ,
810} from "viem" ;
911import { isInsufficientFundsError } from "../../analytics/track/helpers.js" ;
1012import {
1113 trackInsufficientFundsError ,
1214 trackTransaction ,
1315} from "../../analytics/track/transaction.js" ;
1416import type { Chain } from "../../chains/types.js" ;
15- import { getCachedChain , getChainMetadata } from "../../chains/utils.js" ;
17+ import { defineChain , getCachedChain , getChainMetadata } from "../../chains/utils.js" ;
1618import type { ThirdwebClient } from "../../client/client.js" ;
1719import { getAddress } from "../../utils/address.js" ;
1820import {
@@ -34,6 +36,8 @@ import { normalizeChainId } from "../utils/normalizeChainId.js";
3436import type { WalletEmitter } from "../wallet-emitter.js" ;
3537import type { WalletId } from "../wallet-types.js" ;
3638import { injectedProvider } from "./mipdStore.js" ;
39+ import { verifyEip1271Signature } from "../../auth/verify-hash.js" ;
40+ import { getContract } from "../../contract/contract.js" ;
3741
3842// TODO: save the provider in data
3943export function getInjectedProvider ( walletId : WalletId ) {
@@ -250,6 +254,11 @@ function createAccount({
250254 throw new Error ( "Provider not setup" ) ;
251255 }
252256
257+ console . log ( "signMessage" , {
258+ message,
259+ address : account . address ,
260+ } ) ;
261+
253262 const messageToSign = ( ( ) => {
254263 if ( typeof message === "string" ) {
255264 return stringToHex ( message ) ;
@@ -260,10 +269,32 @@ function createAccount({
260269 return message . raw ;
261270 } ) ( ) ;
262271
263- return await provider . request ( {
272+ const signature = await provider . request ( {
264273 method : "personal_sign" ,
265274 params : [ messageToSign , getAddress ( account . address ) ] ,
266275 } ) ;
276+ console . log ( "signature" , {
277+ messageToSign,
278+ address : account . address ,
279+ signature,
280+ } ) ;
281+ const isValid = await verifyEip1271Signature ( {
282+ contract : getContract ( {
283+ address : account . address ,
284+ chain : defineChain ( 50104 ) ,
285+ client : client ,
286+ } ) ,
287+ hash : hashMessage ( stringToHex ( message as string ) ) ,
288+ signature : signature as Hex ,
289+ } ) ;
290+ console . log ( "isValid 1271" , isValid ) ;
291+ const viemValidSignature = await verifyMessage ( {
292+ message,
293+ signature,
294+ address : account . address ,
295+ } ) ;
296+ console . log ( "valid signature from viem" , viemValidSignature ) ;
297+ return signature as Hex ;
267298 } ,
268299 async signTypedData ( typedData ) {
269300 if ( ! provider || ! account . address ) {
0 commit comments