-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
79 lines (71 loc) · 2.15 KB
/
Copy pathindex.js
File metadata and controls
79 lines (71 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import LitJsSdk from "@lit-protocol/lit-node-client";
import { ethers } from "ethers";
import siwe from "siwe";
import fs from 'fs';
import { encryptAndUploadMetadataToIpfs, decryptStringWithIpfs } from "@lit-protocol/encryption";
const privKey = "<YOUR-PRIVATE-KEY>";
const wallet = new ethers.Wallet(privKey);
const client = new LitJsSdk.LitNodeClient();
await client.connect();
const chain = "ethereum";
const accessControlConditions = [
{
contractAddress: "",
standardContractType: "",
chain: "ethereum",
method: "eth_getBalance",
parameters: [":userAddress", "latest"],
returnValueTest: {
comparator: ">=",
value: "0",
},
},
];
const getSiweAuthsig = async () => {
const domain = "localhost";
const origin = "https://localhost/login";
const statement =
"DAshy- This is a test statement. You can put anything you want here.";
const siweMessage = new siwe.SiweMessage({
domain,
address: wallet.address,
statement,
uri: origin,
version: "1",
chainId: "1",
});
const messageToSign = siweMessage.prepareMessage();
const signature = await wallet.signMessage(messageToSign);
const recoveredAddress = ethers.verifyMessage(messageToSign, signature);
const authSig = {
sig: signature,
derivedVia: "web3.eth.personal.sign",
signedMessage: messageToSign,
address: recoveredAddress,
};
return authSig;
}
console.log("1-");
const data = fs.readFileSync("./package.json");
console.log(data);
try {
console.log("Simplified Encryption/Decryption");
const ipfsCid = await encryptAndUploadMetadataToIpfs({
authSig: await getSiweAuthsig(),
accessControlConditions,
chain,
string: "Heyyyyyyy Lit",
// file: new Blob([data]),
litNodeClient: client,
infuraId: 'INFURA-PROJECT-ID',
infuraSecretKey: 'INFURA-SECRET-KEY'
});
// const ipfsCid = 'QmSDfCcsT1QdGPgwJCh4QrLARiCLcx5Fm3bTzp3fmsDVWE';
console.log("ipfsCid");
console.log(ipfsCid);
// Decrypt
const res = await decryptStringWithIpfs({ authSig: await getSiweAuthsig(), ipfsCid, litNodeClient: client });
console.log(res);
} catch(e) {
console.log(e);
}