From fa0d17a71c96a9f6c0e33c5a0f2080382889f985 Mon Sep 17 00:00:00 2001 From: FedericoAmura Date: Fri, 16 Feb 2024 11:31:59 -0300 Subject: [PATCH] fix and clean test using new session cache interface to sign using PKPEthersWallet --- ...p-sign-with-session-sigs-session-cache.mjs | 60 +++++++------------ 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-session-cache.mjs b/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-session-cache.mjs index 1c921cf85a..c89ea49eb9 100644 --- a/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-session-cache.mjs +++ b/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-session-cache.mjs @@ -5,21 +5,28 @@ import { client } from '../00-setup.mjs'; import { LitAbility, LitActionResource } from '@lit-protocol/auth-helpers'; import { ethers } from 'ethers'; import { PKPEthersWallet } from '@lit-protocol/pkp-ethers'; -import { uint8arrayFromString } from '@lit-protocol/uint8arrays'; // NOTE: you need to hash data before you send it in. // If you send something that isn't 32 bytes, the nodes will return an error. -const TO_SIGN = ethers.utils.arrayify(ethers.utils.keccak256([1, 2, 3, 4, 5])); +// PKPEthersWallet::signMessage does this for you before passing it to the lit client. +const message = [1, 2, 3, 4, 5]; +// const TO_SIGN = ethers.utils.arrayify(ethers.utils.keccak256(message)); export async function main() { // ==================== Setup ==================== const sessionKeyPair = client.getSessionKey(); - const resourceAbilities = []; + const resourceAbilities = [ + { + resource: new LitActionResource('*'), + ability: LitAbility.LitActionExecution, + // ability: LitAbility.PKPSigning, + }, + ]; const authNeededCallback = async (params) => { const response = await client.signSessionKey({ statement: params.statement, - // authSig: globalThis.LitCI.CONTROLLER_AUTHSIG, // When this is empty or undefined, it will fail + // authSig: globalThis.LitCI.CONTROLLER_AUTHSIG, authMethods: [ { authMethodType: 1, @@ -38,31 +45,32 @@ export async function main() { // ==================== Test Logic ==================== - const sessionSigs = await client.getSessionSigs({ - chain: 'ethereum', - expiration: new Date(Date.now() + 60_000 * 60).toISOString(), - resourceAbilityRequests: resourceAbilities, - sessionKey: sessionKeyPair, - authNeededCallback, - }); + // const sessionSigs = await client.getSessionSigs({ + // chain: 'ethereum', + // expiration: new Date(Date.now() + 60_000 * 60).toISOString(), + // resourceAbilityRequests: resourceAbilities, + // sessionKey: sessionKeyPair, + // authNeededCallback, + // }); - console.log('sessionSigs:', sessionSigs); + // console.log('sessionSigs:', sessionSigs); // const pkpSignRes = await client?.pkpSign({ // toSign: TO_SIGN, // pubKey: globalThis.LitCI.AUTH_METHOD_PKP_INFO.publicKey, // sessionSigs: sessionSigs, // }); + // console.log(`====================== ${JSON.stringify(pkpSignRes)}`); const pkpWallet = new PKPEthersWallet({ - pkpPubKey: globalThis.LitCI.PKP_INFO.publicKey, + pkpPubKey: globalThis.LitCI.AUTH_METHOD_PKP_INFO.publicKey, rpc: LITCONFIG.CHRONICLE_RPC, litNetwork: globalThis.LitCI.network, authContext: { client, getSessionSigsProps: { chain: 'ethereum', - // expiration: new Date(Date.now() + 60_000 * 60).toISOString(), + expiration: new Date(Date.now() + 60_000 * 60).toISOString(), resourceAbilityRequests: resourceAbilities, sessionKey: sessionKeyPair, authNeededCallback, @@ -71,32 +79,10 @@ export async function main() { }); await pkpWallet.init(); - const signature = await pkpWallet.signMessage(TO_SIGN); + const signature = await pkpWallet.signMessage(message); // ==================== Post-Validation ==================== - // if (!pkpSignRes) { - // return fail( - // 'Failed to sign data with sessionSigs generated by eth wallet auth method' - // ); - // } - - // let missingKeys = []; - - // if (pkpSignRes) { - // ['r', 's', 'recid', 'signature', 'publicKey', 'dataSigned'].forEach( - // (key) => { - // if (pkpSignRes[key] === undefined) { - // missingKeys.push(key); - // } - // } - // ); - // } - - // if (missingKeys.length > 0) { - // return fail(`Missing keys: ${missingKeys.join(', ')}`); - // } - if (!signature) { return fail('Failed to sign data with sessionSigs generated previously'); }