@@ -31,16 +31,38 @@ async function buttonClick() {
31
31
const sessionSigs = await getSessionSigs ( litNodeClient , ethersSigner ) ;
32
32
console . log ( "Got Session Signatures!" ) ;
33
33
34
+ const pkpPublicKey = await getPkpPublicKey ( ethersSigner ) ;
35
+
34
36
const litActionSignatures = await litNodeClient . executeJs ( {
35
37
sessionSigs,
36
38
code : litActionCode ,
37
39
jsParams : {
38
40
url : "https://api.weather.gov/gridpoints/TOP/31,80/forecast" ,
39
- publicKey : await getPkpPublicKey ( ) ,
41
+ publicKey : pkpPublicKey ,
40
42
sigName : "sig" ,
41
43
} ,
42
44
} ) ;
43
45
console . log ( "litActionSignatures: " , litActionSignatures ) ;
46
+
47
+ // verify the signature
48
+ console . log ( "Verifying signature..." ) ;
49
+ const sig = litActionSignatures . signatures . sig . signature ;
50
+ const messageSigned = JSON . stringify (
51
+ litActionSignatures . response . messageSigned
52
+ ) ;
53
+ // calculate the hash of the message
54
+ // just like in the lit action
55
+ const messageHash = ethers . utils . arrayify (
56
+ ethers . utils . keccak256 ( ethers . utils . toUtf8Bytes ( messageSigned ) )
57
+ ) ;
58
+ const verified = ethers . utils . recoverPublicKey ( messageHash , sig ) ;
59
+ console . log ( "verified: " , verified ) ;
60
+ console . log ( "sessionSigs.publicKey: " , "0x" + pkpPublicKey ) ;
61
+ if ( verified === "0x" + pkpPublicKey ) {
62
+ console . log ( "Signature verified!" ) ;
63
+ } else {
64
+ console . log ( "Signature verification failed!" ) ;
65
+ }
44
66
} catch ( error ) {
45
67
console . error ( error ) ;
46
68
} finally {
0 commit comments