finished proof of concept jwt LIT-ACC retrieval
This commit is contained in:
parent
4ae46a2a75
commit
8a4ec6cc73
@ -1,12 +1,16 @@
|
|||||||
<script>
|
<script>
|
||||||
import { createJwt } from '$lib/services/createJwt';
|
import { createJwt } from "$lib/services/createJwt";
|
||||||
|
|
||||||
let jwt = '';
|
let jwt = "";
|
||||||
|
|
||||||
async function handleClick() {
|
async function handleClick() {
|
||||||
jwt = await createJwt();
|
jwt = await createJwt();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button on:click={handleClick}>Create JWT</button>
|
<div class="p-12">
|
||||||
<p>{jwt}</p>
|
<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 { onMount } from "svelte";
|
||||||
import Icon from "@iconify/svelte";
|
import Icon from "@iconify/svelte";
|
||||||
import { walletState, signRequest } from "./stores";
|
import { walletState, signRequest } from "./stores";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
signInWithGoogle,
|
signInWithGoogle,
|
||||||
startSignIn as startSignInService,
|
startSignIn as startSignInService,
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
import { createMachine, assign } from 'xstate';
|
import { createMachine, assign } from 'xstate';
|
||||||
import { signInWithGoogle } from '../services/signInWithGoogle';
|
import { signInWithGoogle } from '../services/signInWithGoogle';
|
||||||
import { createSession } from '../services/createSession';
|
import { createSession } from '../services/createSession';
|
||||||
import { goto } from '$app/navigation';
|
|
||||||
|
|
||||||
const walletMachine = createMachine({
|
const walletMachine = createMachine({
|
||||||
id: 'wallet',
|
id: 'wallet',
|
||||||
@ -70,7 +69,6 @@ const walletMachine = createMachine({
|
|||||||
pkps: (_, event) => event.data.pkps,
|
pkps: (_, event) => event.data.pkps,
|
||||||
sessionSigs: (_, event) => event.data.sessionSigs,
|
sessionSigs: (_, event) => event.data.sessionSigs,
|
||||||
}),
|
}),
|
||||||
(context) => console.log('Context after creating session:', context), // Debug log
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
onError: {
|
onError: {
|
||||||
|
@ -1,17 +1,27 @@
|
|||||||
// src/lib/services/createJwt.ts
|
import { LitNodeClient } from "@lit-protocol/lit-node-client";
|
||||||
import { createSession } from './createSession';
|
import type { AccsEVMParams } from "@lit-protocol/types";
|
||||||
import type { IProvider } from '$lib/IProvider';
|
|
||||||
|
|
||||||
export const createJwt = async (provider: IProvider, authMethod: any, pkps: IRelayPKP[]) => {
|
export const createJwt = async () => {
|
||||||
const { sessionSigs } = await createSession(provider, authMethod, pkps);
|
|
||||||
|
|
||||||
const litNodeClient = new LitNodeClient({
|
const litNodeClient = new LitNodeClient({ litNetwork: "serrano" });
|
||||||
provider,
|
await litNodeClient.connect();
|
||||||
chain: 'xdai',
|
|
||||||
authSig: sessionSigs,
|
|
||||||
});
|
|
||||||
|
|
||||||
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',
|
conditionType: 'evmBasic',
|
||||||
contractAddress: '',
|
contractAddress: '',
|
||||||
@ -21,15 +31,24 @@ export const createJwt = async (provider: IProvider, authMethod: any, pkps: IRel
|
|||||||
parameters: [':userAddress', 'latest'],
|
parameters: [':userAddress', 'latest'],
|
||||||
returnValueTest: {
|
returnValueTest: {
|
||||||
comparator: '>=',
|
comparator: '>=',
|
||||||
value: '10000000000000',
|
value: '1000000000000',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const jwt = await litNodeClient.getSignedToken({
|
await litNodeClient.saveSigningCondition({
|
||||||
unifiedAccessControlConditions,
|
unifiedAccessControlConditions,
|
||||||
sessionSigs,
|
sessionSigs,
|
||||||
resourceId: 'wundergraph-auth', // replace with your resource id
|
resourceId,
|
||||||
|
chain: "litSessionSign",
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const jwt = await litNodeClient.getSignedToken({
|
||||||
|
unifiedAccessControlConditions,
|
||||||
|
chain: 'xdai',
|
||||||
|
sessionSigs,
|
||||||
|
resourceId
|
||||||
});
|
});
|
||||||
|
|
||||||
return jwt;
|
return jwt;
|
||||||
|
@ -12,19 +12,14 @@ export const createSession = async (provider, authMethod, pkps: IRelayPKP[]) =>
|
|||||||
currentPKP = pkps[0];
|
currentPKP = pkps[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Current PKP:', currentPKP); // Debug log
|
|
||||||
|
|
||||||
const sessionSigs = await createLitSession(
|
const sessionSigs = await createLitSession(
|
||||||
provider,
|
provider,
|
||||||
currentPKP.publicKey,
|
currentPKP.publicKey,
|
||||||
authMethod
|
authMethod,
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('Session Signatures:', sessionSigs); // Debug log
|
|
||||||
|
|
||||||
return { pkps, sessionSigs };
|
return { pkps, sessionSigs };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in createSession:', error); // Debug log
|
|
||||||
throw new Error(`Failed to create session: ${error.message}`);
|
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