cool, it works
This commit is contained in:
parent
cdfb5c2be6
commit
56a1b69243
29057
package-lock.json
generated
29057
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
121
src/App.js
121
src/App.js
@ -9,11 +9,25 @@ import PKPHelper from "./abis/PKPHelper.json";
|
|||||||
import PKPNFT from "./abis/PKPNFT.json";
|
import PKPNFT from "./abis/PKPNFT.json";
|
||||||
import ContractAddresses from "./abis/deployed-contracts.json";
|
import ContractAddresses from "./abis/deployed-contracts.json";
|
||||||
|
|
||||||
|
window.LitJsSdk = LitJsSdk;
|
||||||
|
window.ethers = ethers;
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [pkpEthAddress, setPkpEthAddress] = useState(null);
|
const [pkpEthAddress, setPkpEthAddress] = useState(null);
|
||||||
|
const [googleCredentialResponse, setGoogleCredentialResponse] =
|
||||||
|
useState(null);
|
||||||
|
const [pkpPublicKey, setPkpPublicKey] = useState(null);
|
||||||
|
const [status, setStatus] = useState("");
|
||||||
|
|
||||||
const handleLoggedInToGoogle = async (credentialResponse) => {
|
const handleLoggedInToGoogle = async (credentialResponse) => {
|
||||||
|
setStatus("Logged in to Google");
|
||||||
console.log("got this response from google sign in: ", credentialResponse);
|
console.log("got this response from google sign in: ", credentialResponse);
|
||||||
|
setGoogleCredentialResponse(credentialResponse);
|
||||||
|
mintPkp(credentialResponse);
|
||||||
|
};
|
||||||
|
|
||||||
|
const mintPkp = async (credentialResponse) => {
|
||||||
|
setStatus("Minting PKP...");
|
||||||
// mint a PKP for the user
|
// mint a PKP for the user
|
||||||
// A Web3Provider wraps a standard Web3 provider, which is
|
// A Web3Provider wraps a standard Web3 provider, which is
|
||||||
// what MetaMask injects as window.ethereum into each page
|
// what MetaMask injects as window.ethereum into each page
|
||||||
@ -66,26 +80,106 @@ function App() {
|
|||||||
|
|
||||||
console.log("minted PKP with eth address: ", ethAddress);
|
console.log("minted PKP with eth address: ", ethAddress);
|
||||||
const pkpPublicKey = await pkpContract.getPubkey(tokenIdFromEvent);
|
const pkpPublicKey = await pkpContract.getPubkey(tokenIdFromEvent);
|
||||||
|
setPkpPublicKey(pkpPublicKey);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleEncryptThenDecrypt = async () => {
|
||||||
|
setStatus("Encrypting then decrypting...");
|
||||||
|
var unifiedAccessControlConditions = [
|
||||||
|
{
|
||||||
|
conditionType: "evmBasic",
|
||||||
|
contractAddress: "",
|
||||||
|
standardContractType: "",
|
||||||
|
chain: "ethereum",
|
||||||
|
method: "eth_getBalance",
|
||||||
|
parameters: [":userAddress", "latest"],
|
||||||
|
returnValueTest: {
|
||||||
|
comparator: ">=",
|
||||||
|
value: "0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// this will be fired if auth is needed. we can use this to prompt the user to sign in
|
||||||
|
const authNeededCallback = async ({
|
||||||
|
chain,
|
||||||
|
resources,
|
||||||
|
expiration,
|
||||||
|
uri,
|
||||||
|
litNodeClient,
|
||||||
|
}) => {
|
||||||
|
console.log("authNeededCallback fired");
|
||||||
|
const sessionSig = await litNodeClient.signSessionKey({
|
||||||
|
sessionKey: uri,
|
||||||
|
authMethods: [
|
||||||
|
{
|
||||||
|
authMethodType: 6,
|
||||||
|
accessToken: googleCredentialResponse.credential,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
pkpPublicKey,
|
||||||
|
expiration,
|
||||||
|
resources,
|
||||||
|
chain,
|
||||||
|
});
|
||||||
|
console.log("got session sig from node and PKP: ", sessionSig);
|
||||||
|
return sessionSig;
|
||||||
|
};
|
||||||
|
|
||||||
// get the user a session with it
|
// get the user a session with it
|
||||||
const litNodeClient = new LitJsSdk.LitNodeClient();
|
const litNodeClient = new LitJsSdk.LitNodeClient();
|
||||||
await litNodeClient.connect();
|
await litNodeClient.connect();
|
||||||
|
|
||||||
const fakeSessionKey = "lit:session:0x1234567890";
|
const sessionSigs = await litNodeClient.getSessionSigs({
|
||||||
const sessionSig = await litNodeClient.signSessionKey({
|
expiration: new Date(Date.now() + 1000 * 60 * 60 * 24).toISOString(), // 24 hours
|
||||||
sessionKey: fakeSessionKey,
|
chain: "ethereum",
|
||||||
authMethods: [
|
resources: [`litEncryptionCondition://*`],
|
||||||
{
|
switchChain: false,
|
||||||
authMethodType: 6,
|
authNeededCallback,
|
||||||
accessToken: credentialResponse.credential,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
pkpPublicKey,
|
|
||||||
});
|
});
|
||||||
console.log("sessionSig: ", sessionSig);
|
console.log("sessionSigs before saving encryption key: ", sessionSigs);
|
||||||
|
|
||||||
|
const { encryptedZip, symmetricKey } = await LitJsSdk.zipAndEncryptString(
|
||||||
|
"this is a secret message"
|
||||||
|
);
|
||||||
|
|
||||||
|
const encryptedSymmetricKey = await litNodeClient.saveEncryptionKey({
|
||||||
|
unifiedAccessControlConditions,
|
||||||
|
symmetricKey,
|
||||||
|
sessionSigs,
|
||||||
|
});
|
||||||
|
|
||||||
|
const hashOfKey = await LitJsSdk.hashEncryptionKey({
|
||||||
|
encryptedSymmetricKey,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("encrypted symmetric key", encryptedSymmetricKey);
|
||||||
|
|
||||||
|
const retrievedSymmKey = await litNodeClient.getEncryptionKey({
|
||||||
|
unifiedAccessControlConditions,
|
||||||
|
toDecrypt: LitJsSdk.uint8arrayToString(encryptedSymmetricKey, "base16"),
|
||||||
|
sessionSigs,
|
||||||
|
});
|
||||||
|
|
||||||
|
const decryptedFiles = await LitJsSdk.decryptZip(
|
||||||
|
encryptedZip,
|
||||||
|
retrievedSymmKey
|
||||||
|
);
|
||||||
|
const decryptedString = await decryptedFiles["string.txt"].async("text");
|
||||||
|
console.log("decrypted string", decryptedString);
|
||||||
|
|
||||||
|
setStatus("Success!");
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
|
<div style={{ height: 50 }} />
|
||||||
|
<h1>{status}</h1>
|
||||||
|
<div style={{ height: 100 }} />
|
||||||
|
<h3>
|
||||||
|
Step 1: log in with Google. You will mint a PKP and obtain a session
|
||||||
|
sig.
|
||||||
|
</h3>
|
||||||
<GoogleLogin
|
<GoogleLogin
|
||||||
onSuccess={handleLoggedInToGoogle}
|
onSuccess={handleLoggedInToGoogle}
|
||||||
onError={() => {
|
onError={() => {
|
||||||
@ -95,6 +189,11 @@ function App() {
|
|||||||
/>
|
/>
|
||||||
<div style={{ height: 100 }} />
|
<div style={{ height: 100 }} />
|
||||||
{pkpEthAddress && <div>PKP Eth Address: {pkpEthAddress}</div>}
|
{pkpEthAddress && <div>PKP Eth Address: {pkpEthAddress}</div>}
|
||||||
|
<div style={{ height: 100 }} />
|
||||||
|
<h3>Step 2: Use Lit</h3>
|
||||||
|
<button onClick={handleEncryptThenDecrypt}>
|
||||||
|
Encrypt then Decrypt with Lit
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
"version": "v1",
|
"version": "v1",
|
||||||
"packages": {
|
"packages": {
|
||||||
"lit-js-sdk": {
|
"lit-js-sdk": {
|
||||||
"signature": "24bc7659933f393b3330aee609498caf",
|
"signature": "c71561d0d1f9e965d7937ed22756007f",
|
||||||
"file": true,
|
"file": true
|
||||||
"replaced": "^1.1.234"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6885,7 +6885,7 @@ lit-connect-modal@^0.1.10:
|
|||||||
micromodal "^0.4.10"
|
micromodal "^0.4.10"
|
||||||
|
|
||||||
"lit-js-sdk@file:.yalc/lit-js-sdk":
|
"lit-js-sdk@file:.yalc/lit-js-sdk":
|
||||||
version "1.2.25"
|
version "1.2.29"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@ethersproject/bytes" "^5.5.0"
|
"@ethersproject/bytes" "^5.5.0"
|
||||||
"@ethersproject/contracts" "^5.2.0"
|
"@ethersproject/contracts" "^5.2.0"
|
||||||
@ -7229,9 +7229,9 @@ node-fetch@2.6.7:
|
|||||||
whatwg-url "^5.0.0"
|
whatwg-url "^5.0.0"
|
||||||
|
|
||||||
node-fetch@^3.2.3:
|
node-fetch@^3.2.3:
|
||||||
version "3.2.10"
|
version "3.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.2.10.tgz#e8347f94b54ae18b57c9c049ef641cef398a85c8"
|
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.0.tgz#37e71db4ecc257057af828d523a7243d651d91e4"
|
||||||
integrity sha512-MhuzNwdURnZ1Cp4XTazr69K0BTizsBroX7Zx3UgDSVcZYKF/6p0CBe4EUb/hLqmzVhl0UpYfgRljQ4yxE+iCxA==
|
integrity sha512-BKwRP/O0UvoMKp7GNdwPlObhYGB5DQqwhEDQlNKuoqwVYSxkSZCSbHjnFFmUEtwSKRPU4kNK8PbDYYitwaE3QA==
|
||||||
dependencies:
|
dependencies:
|
||||||
data-uri-to-buffer "^4.0.0"
|
data-uri-to-buffer "^4.0.0"
|
||||||
fetch-blob "^3.1.4"
|
fetch-blob "^3.1.4"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user