non working LIT jwt
This commit is contained in:
		@@ -159,7 +159,7 @@
 | 
			
		||||
    <div class="mt-4 text-center">
 | 
			
		||||
      <p>{status}</p>
 | 
			
		||||
    </div>
 | 
			
		||||
    {#if activeSession}
 | 
			
		||||
    <!-- {#if activeSession}
 | 
			
		||||
      <div>
 | 
			
		||||
        <h3>Active Session:</h3>
 | 
			
		||||
        <p>Node: {activeSession.node}</p>
 | 
			
		||||
@@ -174,6 +174,6 @@
 | 
			
		||||
          </p>
 | 
			
		||||
        {/each}
 | 
			
		||||
      {/if}
 | 
			
		||||
    {/if}
 | 
			
		||||
    {/if} -->
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
<script lang="ts">
 | 
			
		||||
  import { ethers } from "ethers";
 | 
			
		||||
  import { onMount } from "svelte";
 | 
			
		||||
  // import { fetchBalance, serialize } from "@wagmi/core";
 | 
			
		||||
 | 
			
		||||
  export let messageToSign = {};
 | 
			
		||||
 | 
			
		||||
@@ -23,7 +24,7 @@
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  export async function signMessageWithPKP() {
 | 
			
		||||
  async function signMessageWithPKP() {
 | 
			
		||||
    const userConfirmed = window.confirm(
 | 
			
		||||
      "Do you want to sign the following message?\n\n" +
 | 
			
		||||
        JSON.stringify(messageToSign, null, 2)
 | 
			
		||||
@@ -86,9 +87,45 @@
 | 
			
		||||
      console.error(err);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async function getJWT() {
 | 
			
		||||
    var unifiedAccessControlConditions = [
 | 
			
		||||
      {
 | 
			
		||||
        conditionType: "evmBasic",
 | 
			
		||||
        contractAddress: "",
 | 
			
		||||
        standardContractType: "",
 | 
			
		||||
        chain: "xdai",
 | 
			
		||||
        method: "eth_getBalance",
 | 
			
		||||
        parameters: [":userAddress", "latest"],
 | 
			
		||||
        returnValueTest: {
 | 
			
		||||
          comparator: ">=",
 | 
			
		||||
          value: "10000000000000",
 | 
			
		||||
        },
 | 
			
		||||
      },
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    // Saving signing condition
 | 
			
		||||
    await litNodeClient.saveSigningCondition({
 | 
			
		||||
      unifiedAccessControlConditions,
 | 
			
		||||
      sessionSigs,
 | 
			
		||||
      resourceId: { test: "hello" },
 | 
			
		||||
      chain: "litSessionSign",
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    // Retrieving a signature
 | 
			
		||||
    let jwt = await litNodeClient.getSignedToken({
 | 
			
		||||
      unifiedAccessControlConditions,
 | 
			
		||||
      sessionSigs,
 | 
			
		||||
      resourceId: { test: "hello" },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    alert("JWT: " + jwt);
 | 
			
		||||
  }
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<button on:click={signMessageWithPKP}>Sign Message</button>
 | 
			
		||||
<button on:click={getJWT}>Get JWT</button>
 | 
			
		||||
 | 
			
		||||
{#if messageToSign}
 | 
			
		||||
  <pre>{JSON.stringify(messageToSign)}</pre>
 | 
			
		||||
{/if}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										58
									
								
								src/lib/setupChainProvider.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								src/lib/setupChainProvider.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
import { configureChains, createConfig } from '@wagmi/core';
 | 
			
		||||
import { gnosis } from '@wagmi/core/chains';
 | 
			
		||||
import { publicProvider } from '@wagmi/core/providers/public';
 | 
			
		||||
import { InjectedConnector } from '@wagmi/core/connectors/injected';
 | 
			
		||||
import { jsonRpcProvider } from '@wagmi/core/providers/jsonRpc';
 | 
			
		||||
 | 
			
		||||
// const chronicleChain = {
 | 
			
		||||
// 	id: 175177,
 | 
			
		||||
// 	name: 'Chronicle',
 | 
			
		||||
// 	network: 'chronicle',
 | 
			
		||||
 | 
			
		||||
// 	nativeCurrency: {
 | 
			
		||||
// 		decimals: 18,
 | 
			
		||||
// 		name: 'Chronicle - Lit Protocol Testnet',
 | 
			
		||||
// 		symbol: 'LIT'
 | 
			
		||||
// 	},
 | 
			
		||||
// 	rpcUrls: {
 | 
			
		||||
// 		default: {
 | 
			
		||||
// 			http: ['https://chain-rpc.litprotocol.com/http']
 | 
			
		||||
// 		},
 | 
			
		||||
// 		public: {
 | 
			
		||||
// 			http: ['https://chain-rpc.litprotocol.com/http']
 | 
			
		||||
// 		}
 | 
			
		||||
// 	},
 | 
			
		||||
// 	blockExplorers: {
 | 
			
		||||
// 		default: {
 | 
			
		||||
// 			name: 'Chronicle - Lit Protocol Testnet',
 | 
			
		||||
// 			url: 'https://chain.litprotocol.com'
 | 
			
		||||
// 		}
 | 
			
		||||
// 	},
 | 
			
		||||
// 	testnet: true
 | 
			
		||||
// };
 | 
			
		||||
 | 
			
		||||
export function initChainProvider() {
 | 
			
		||||
	const { chains, publicClient } = configureChains(
 | 
			
		||||
		[gnosis],
 | 
			
		||||
		[
 | 
			
		||||
			jsonRpcProvider({
 | 
			
		||||
				rpc: (chain) => ({ http: chain.rpcUrls.default.http[0] })
 | 
			
		||||
			}),
 | 
			
		||||
			jsonRpcProvider({
 | 
			
		||||
				rpc: () => ({
 | 
			
		||||
					http: `https://rpc.ankr.com/gnosis`,
 | 
			
		||||
					wss: `wss://rpc.gnosischain.com/wss`
 | 
			
		||||
				})
 | 
			
		||||
			}),
 | 
			
		||||
			publicProvider()
 | 
			
		||||
		]
 | 
			
		||||
	);
 | 
			
		||||
	createConfig({
 | 
			
		||||
		autoConnect: true,
 | 
			
		||||
		connectors: [
 | 
			
		||||
			new InjectedConnector({ chains }),
 | 
			
		||||
		],
 | 
			
		||||
		publicClient
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -3,11 +3,17 @@
 | 
			
		||||
  import type { LayoutData } from "./$types";
 | 
			
		||||
  import { client } from "$lib/wundergraph";
 | 
			
		||||
  import Cookies from "js-cookie";
 | 
			
		||||
  import { onMount } from "svelte";
 | 
			
		||||
  import { initChainProvider } from "$lib/setupChainProvider";
 | 
			
		||||
 | 
			
		||||
  export let data: LayoutData;
 | 
			
		||||
 | 
			
		||||
  const token = Cookies.get("token");
 | 
			
		||||
 | 
			
		||||
  onMount(() => {
 | 
			
		||||
    initChainProvider();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  if (token) {
 | 
			
		||||
    client.setAuthorizationToken(token);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user