add pkp public key to session sig requests
This commit is contained in:
parent
81a70959af
commit
162494dfd8
42
src/App.tsx
42
src/App.tsx
@ -147,18 +147,18 @@ function App() {
|
|||||||
const {
|
const {
|
||||||
encryptedString,
|
encryptedString,
|
||||||
encryptedSymmetricKey,
|
encryptedSymmetricKey,
|
||||||
authenticatedPkpPublicKey,
|
|
||||||
} = await handleStoreEncryptionConditionNodes(
|
} = await handleStoreEncryptionConditionNodes(
|
||||||
setStatus,
|
setStatus,
|
||||||
googleCredentialResponse
|
googleCredentialResponse,
|
||||||
|
registeredPkpPublicKey
|
||||||
);
|
);
|
||||||
setEncryptedString(encryptedString);
|
setEncryptedString(encryptedString);
|
||||||
setEncryptedSymmetricKey(encryptedSymmetricKey);
|
setEncryptedSymmetricKey(encryptedSymmetricKey);
|
||||||
setAuthenticatedPkpPublicKey(
|
setAuthenticatedPkpPublicKey(
|
||||||
authenticatedPkpPublicKey
|
registeredPkpPublicKey
|
||||||
);
|
);
|
||||||
setAuthenticatedPkpEthAddress(
|
setAuthenticatedPkpEthAddress(
|
||||||
publicKeyToAddress(authenticatedPkpPublicKey)
|
publicKeyToAddress(registeredPkpPublicKey)
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@ -444,11 +444,11 @@ async function pollRequestUntilTerminalState(
|
|||||||
|
|
||||||
async function handleStoreEncryptionConditionNodes(
|
async function handleStoreEncryptionConditionNodes(
|
||||||
setStatusFn: (status: string) => void,
|
setStatusFn: (status: string) => void,
|
||||||
googleCredentialResponse: any
|
googleCredentialResponse: any,
|
||||||
|
requestedPkpPublicKey: string
|
||||||
): Promise<{
|
): Promise<{
|
||||||
encryptedSymmetricKey: Uint8Array;
|
encryptedSymmetricKey: Uint8Array;
|
||||||
encryptedString: Blob;
|
encryptedString: Blob;
|
||||||
authenticatedPkpPublicKey: string;
|
|
||||||
}> {
|
}> {
|
||||||
setStatusFn("Storing encryption condition with the network...");
|
setStatusFn("Storing encryption condition with the network...");
|
||||||
|
|
||||||
@ -466,16 +466,17 @@ async function handleStoreEncryptionConditionNodes(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// get the session sigs
|
// get the session sigs
|
||||||
const { sessionSigs, authenticatedPkpPublicKey } = await getSessionSigs(
|
const { sessionSigs } = await getSessionSigs(
|
||||||
litNodeClient,
|
litNodeClient,
|
||||||
encryptedSymmetricKey,
|
encryptedSymmetricKey,
|
||||||
litNodeClient.generateAuthMethodForGoogleJWT(
|
litNodeClient.generateAuthMethodForGoogleJWT(
|
||||||
googleCredentialResponse.credential
|
googleCredentialResponse.credential
|
||||||
)
|
),
|
||||||
|
requestedPkpPublicKey
|
||||||
);
|
);
|
||||||
|
|
||||||
const pkpEthAddress = publicKeyToAddress(authenticatedPkpPublicKey);
|
const pkpEthAddress = publicKeyToAddress(requestedPkpPublicKey);
|
||||||
|
|
||||||
const unifiedAccessControlConditions = getUnifiedAccessControlConditions(
|
const unifiedAccessControlConditions = getUnifiedAccessControlConditions(
|
||||||
pkpEthAddress
|
pkpEthAddress
|
||||||
);
|
);
|
||||||
@ -498,20 +499,17 @@ async function handleStoreEncryptionConditionNodes(
|
|||||||
return {
|
return {
|
||||||
encryptedSymmetricKey,
|
encryptedSymmetricKey,
|
||||||
encryptedString,
|
encryptedString,
|
||||||
authenticatedPkpPublicKey,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSessionSigs(
|
async function getSessionSigs(
|
||||||
litNodeClient: LitJsSdk.LitNodeClient,
|
litNodeClient: LitJsSdk.LitNodeClient,
|
||||||
encryptedSymmetricKey: Uint8Array,
|
encryptedSymmetricKey: Uint8Array,
|
||||||
authMethod: LitJsSdk_types.AuthMethod
|
authMethod: LitJsSdk_types.AuthMethod,
|
||||||
|
requestedPkpPublicKey: string
|
||||||
): Promise<{
|
): Promise<{
|
||||||
sessionSigs: LitJsSdk_types.SessionSigsMap;
|
sessionSigs: LitJsSdk_types.SessionSigsMap;
|
||||||
authenticatedPkpPublicKey: string;
|
|
||||||
}> {
|
}> {
|
||||||
let authenticatedPkpPublicKey: string;
|
|
||||||
|
|
||||||
// this will be fired if auth is needed. we can use this to prompt the user to sign in
|
// this will be fired if auth is needed. we can use this to prompt the user to sign in
|
||||||
const authNeededCallback: AuthCallback = async ({
|
const authNeededCallback: AuthCallback = async ({
|
||||||
resources,
|
resources,
|
||||||
@ -525,6 +523,7 @@ async function getSessionSigs(
|
|||||||
|
|
||||||
// Get AuthSig
|
// Get AuthSig
|
||||||
const { authSig, pkpPublicKey } = await litNodeClient.signSessionKey({
|
const { authSig, pkpPublicKey } = await litNodeClient.signSessionKey({
|
||||||
|
pkpPublicKey: requestedPkpPublicKey,
|
||||||
authMethods,
|
authMethods,
|
||||||
statement,
|
statement,
|
||||||
expiration:
|
expiration:
|
||||||
@ -537,8 +536,6 @@ async function getSessionSigs(
|
|||||||
pkpPublicKey,
|
pkpPublicKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
authenticatedPkpPublicKey = pkpPublicKey;
|
|
||||||
|
|
||||||
return authSig;
|
return authSig;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -567,11 +564,9 @@ async function getSessionSigs(
|
|||||||
authNeededCallback,
|
authNeededCallback,
|
||||||
});
|
});
|
||||||
console.log("sessionSigs: ", sessionSigs);
|
console.log("sessionSigs: ", sessionSigs);
|
||||||
console.log("authenticatedPkpPublicKey: ", authenticatedPkpPublicKey!);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sessionSigs,
|
sessionSigs
|
||||||
authenticatedPkpPublicKey: authenticatedPkpPublicKey!,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -676,7 +671,8 @@ async function handleRetrieveSymmetricKeyNodes(
|
|||||||
encryptedSymmetricKey,
|
encryptedSymmetricKey,
|
||||||
litNodeClient.generateAuthMethodForGoogleJWT(
|
litNodeClient.generateAuthMethodForGoogleJWT(
|
||||||
googleCredentialResponse.credential
|
googleCredentialResponse.credential
|
||||||
)
|
),
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// get the ACC
|
// get the ACC
|
||||||
@ -702,7 +698,7 @@ async function handleRetrieveSymmetricKeyNodes(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function publicKeyToAddress(publicKey: string) {
|
function publicKeyToAddress(publicKey: string) {
|
||||||
return utils.computeAddress(`0x${publicKey}`);
|
return utils.computeAddress(`${publicKey}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function hashBytes({ bytes }: { bytes: Uint8Array }): Promise<string> {
|
async function hashBytes({ bytes }: { bytes: Uint8Array }): Promise<string> {
|
||||||
|
Loading…
Reference in New Issue
Block a user