diff --git a/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-eth-wallet-auth-method.mjs b/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-eth-wallet-auth-method.mjs index ddbab8feec..0ac17ae8f2 100644 --- a/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-eth-wallet-auth-method.mjs +++ b/e2e-nodejs/group-pkp-session-sigs/test-pkp-sign-with-session-sigs-eth-wallet-auth-method.mjs @@ -4,7 +4,7 @@ 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'; +import LITCONFIG from '../../lit.config.json' assert { type: 'json' }; // 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. @@ -12,11 +12,9 @@ const TO_SIGN = ethers.utils.arrayify(ethers.utils.keccak256([1, 2, 3, 4, 5])); export async function main() { // ==================== Setup ==================== - const sessionKeyPair = client.getSessionKey(); 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 authMethods: [ { authMethodType: 1, @@ -39,27 +37,18 @@ 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, - }); - - console.log('sessionSigs:', sessionSigs); - - const pkpSignRes = await client?.pkpSign({ - toSign: TO_SIGN, - pubKey: globalThis.LitCI.AUTH_METHOD_PKP_INFO.publicKey, - sessionSigs: sessionSigs, - }); - const pkpWallet = new PKPEthersWallet({ pkpPubKey: globalThis.LitCI.AUTH_METHOD_PKP_INFO.publicKey, - controllerSessionSigs: sessionSigs, - controllerAuthMethods: [], + rpc: LITCONFIG.CHRONICLE_RPC, + litNetwork: globalThis.LitCI.network, + authContext: { + client: client, + getSessionSigsProps: { + chain: 'ethereum', + resourceAbilityRequests: resourceAbilities, + authNeededCallback, + }, + }, }); await pkpWallet.init(); @@ -67,40 +56,22 @@ export async function main() { const signature = await pkpWallet.signMessage(TO_SIGN); // ==================== Post-Validation ==================== + // check if the given signature is a valid signature using ethers + const isValid = ethers.utils.verifyMessage( + TO_SIGN, + signature, + pkpWallet.address + ); - 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) { + if (!isValid) { return fail( - 'Failed to sign data with sessionSigs generated by eth wallet auth method' + `it should use sessionSigs generated by eth wallet auth method to sign data. Signature is ${signature} and pkpWallet.address is ${pkpWallet.address}` ); } // ==================== Success ==================== return success( - `it should use sessionSigs generated by eth wallet auth method to sign data. Signature is ${signature} and pkpSignRes is ${JSON.stringify( - pkpSignRes - )}` + `it should use sessionSigs generated by eth wallet auth method to sign data. Signature is ${signature} and pkpWallet.address is ${pkpWallet.address} and isValid is ${isValid}` ); } await testThis({ name: path.basename(import.meta.url), fn: main }); diff --git a/packages/pkp-base/src/lib/pkp-base.ts b/packages/pkp-base/src/lib/pkp-base.ts index 5943e4e806..ce968b9929 100644 --- a/packages/pkp-base/src/lib/pkp-base.ts +++ b/packages/pkp-base/src/lib/pkp-base.ts @@ -216,6 +216,20 @@ export class PKPBase { ].filter(Boolean).length; if (providedAuthentications !== 1) { + + // log which authentications has the user provided + if (this.controllerAuthSig) { + logError('controllerAuthSig is provided'); + } + + if (this.controllerSessionSigs) { + logError('controllerSessionSigs is provided'); + } + + if (this.authContext) { + logError('authContext is provided'); + } + this.throwError( 'Multiple authentications are defined, can only use one at a time' );