finished proof of concept jwt LIT-ACC retrieval
This commit is contained in:
parent
4ae46a2a75
commit
8a4ec6cc73
@ -1,12 +1,16 @@
|
||||
<script>
|
||||
import { createJwt } from '$lib/services/createJwt';
|
||||
|
||||
let jwt = '';
|
||||
|
||||
async function handleClick() {
|
||||
jwt = await createJwt();
|
||||
}
|
||||
</script>
|
||||
|
||||
<button on:click={handleClick}>Create JWT</button>
|
||||
<p>{jwt}</p>
|
||||
import { createJwt } from "$lib/services/createJwt";
|
||||
|
||||
let jwt = "";
|
||||
|
||||
async function handleClick() {
|
||||
jwt = await createJwt();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="p-12">
|
||||
<button on:click={handleClick} class="btn variant-filled-primary"
|
||||
>Create JWT</button
|
||||
>
|
||||
<p class="text-xs">{jwt}</p>
|
||||
</div>
|
||||
|
@ -4,7 +4,6 @@
|
||||
import { onMount } from "svelte";
|
||||
import Icon from "@iconify/svelte";
|
||||
import { walletState, signRequest } from "./stores";
|
||||
|
||||
import {
|
||||
signInWithGoogle,
|
||||
startSignIn as startSignInService,
|
||||
|
@ -2,7 +2,6 @@
|
||||
import { createMachine, assign } from 'xstate';
|
||||
import { signInWithGoogle } from '../services/signInWithGoogle';
|
||||
import { createSession } from '../services/createSession';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
const walletMachine = createMachine({
|
||||
id: 'wallet',
|
||||
@ -70,7 +69,6 @@ const walletMachine = createMachine({
|
||||
pkps: (_, event) => event.data.pkps,
|
||||
sessionSigs: (_, event) => event.data.sessionSigs,
|
||||
}),
|
||||
(context) => console.log('Context after creating session:', context), // Debug log
|
||||
],
|
||||
},
|
||||
onError: {
|
||||
|
@ -1,17 +1,27 @@
|
||||
// src/lib/services/createJwt.ts
|
||||
import { createSession } from './createSession';
|
||||
import type { IProvider } from '$lib/IProvider';
|
||||
import { LitNodeClient } from "@lit-protocol/lit-node-client";
|
||||
import type { AccsEVMParams } from "@lit-protocol/types";
|
||||
|
||||
export const createJwt = async (provider: IProvider, authMethod: any, pkps: IRelayPKP[]) => {
|
||||
const { sessionSigs } = await createSession(provider, authMethod, pkps);
|
||||
export const createJwt = async () => {
|
||||
|
||||
const litNodeClient = new LitNodeClient({
|
||||
provider,
|
||||
chain: 'xdai',
|
||||
authSig: sessionSigs,
|
||||
});
|
||||
const litNodeClient = new LitNodeClient({ litNetwork: "serrano" });
|
||||
await litNodeClient.connect();
|
||||
|
||||
const unifiedAccessControlConditions = [
|
||||
const me = JSON.parse(localStorage.getItem('me'));
|
||||
if (!me || !me.sessionSigs) {
|
||||
throw new Error('No sessionSigs found in local storage');
|
||||
}
|
||||
|
||||
const resourceId = {
|
||||
baseUrl: "https://localhost:3000/",
|
||||
path: "/wunderauth",
|
||||
orgId: "°",
|
||||
role: "admin",
|
||||
extraData: "{loggedIn: true}"
|
||||
}
|
||||
|
||||
const sessionSigs = me.sessionSigs;
|
||||
|
||||
const unifiedAccessControlConditions: AccsEVMParams[] = [
|
||||
{
|
||||
conditionType: 'evmBasic',
|
||||
contractAddress: '',
|
||||
@ -21,15 +31,24 @@ export const createJwt = async (provider: IProvider, authMethod: any, pkps: IRel
|
||||
parameters: [':userAddress', 'latest'],
|
||||
returnValueTest: {
|
||||
comparator: '>=',
|
||||
value: '10000000000000',
|
||||
value: '1000000000000',
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const jwt = await litNodeClient.getSignedToken({
|
||||
await litNodeClient.saveSigningCondition({
|
||||
unifiedAccessControlConditions,
|
||||
sessionSigs,
|
||||
resourceId: 'wundergraph-auth', // replace with your resource id
|
||||
resourceId,
|
||||
chain: "litSessionSign",
|
||||
});
|
||||
|
||||
|
||||
const jwt = await litNodeClient.getSignedToken({
|
||||
unifiedAccessControlConditions,
|
||||
chain: 'xdai',
|
||||
sessionSigs,
|
||||
resourceId
|
||||
});
|
||||
|
||||
return jwt;
|
||||
|
@ -12,19 +12,14 @@ export const createSession = async (provider, authMethod, pkps: IRelayPKP[]) =>
|
||||
currentPKP = pkps[0];
|
||||
}
|
||||
|
||||
console.log('Current PKP:', currentPKP); // Debug log
|
||||
|
||||
const sessionSigs = await createLitSession(
|
||||
provider,
|
||||
currentPKP.publicKey,
|
||||
authMethod
|
||||
authMethod,
|
||||
);
|
||||
|
||||
console.log('Session Signatures:', sessionSigs); // Debug log
|
||||
|
||||
return { pkps, sessionSigs };
|
||||
} catch (error) {
|
||||
console.error('Error in createSession:', error); // Debug log
|
||||
throw new Error(`Failed to create session: ${error.message}`);
|
||||
}
|
||||
};
|
5
src/routes/jwt/+page.svelte
Normal file
5
src/routes/jwt/+page.svelte
Normal file
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
import JWT from "$lib/JWT.svelte";
|
||||
</script>
|
||||
|
||||
<JWT />
|
Loading…
Reference in New Issue
Block a user