import { CeramicClient } from "@ceramicnetwork/http-client"; import { TileDocument } from "@ceramicnetwork/stream-tile"; import { getResolver } from "key-did-resolver"; import { DID } from "dids"; import { encodeDIDWithLit, Secp256k1ProviderWithLit } from "key-did-provider-secp256k1-with-lit"; const litActionCode = ` const go = async () => { // this requests a signature share from the Lit Node // the signature share will be automatically returned in the HTTP response from the node // all the params (toSign, publicKey, sigName) are passed in from the LitJsSdk.executeJs() function const sigShare = await LitActions.ethPersonalSignMessageEcdsa({ message, publicKey , sigName }); }; go(); `; export async function testCredential() { // const ceramic = new CeramicClient("http://localhost:7007"); const ceramicNetwork = process.env?.REACT_APP_CERAMIC_NETWORK ?? "https://ceramic-clay.3boxlabs.com"; const ceramic = new CeramicClient(ceramicNetwork); const encodedDID = await encodeDIDWithLit({ pkpPublicKey: "03335a328020ea4f89344356b8cd90ae754d8d98e6295073f79ce6c6bdac0c5c86", }); const provider = new Secp256k1ProviderWithLit({ did: encodedDID, ipfsId: "QmcZ2MuxkNrMbNKAVtK37tEmKJ8zwvFudin3rBEcHyhqJc", }); const did = new DID({provider, resolver: getResolver()}); // -- authenticate await did.authenticate(); ceramic.did = did; console.log("DID:", did); // -- write to ceramic stream const doc = await TileDocument.create(ceramic, "Hola hola ¿Cómo estás?"); console.log("Doc/StreamID:", doc.id.toString()); // -- read a ceramic stream var loadDoc = await TileDocument.load(ceramic, doc.id.toString()); console.log("Specific doc:", loadDoc.content); // // -- update the ceramic stream // await loadDoc.update("Buon giorno, como stai?"); // console.log("updating doc complete"); // // console.log("sleeping for ceramic to have time to update"); // await new Promise((resolve) => setTimeout(resolve, 10000)); // // // -- read it again and confirm it got wrote // var loadDocAfter = await TileDocument.load(ceramic, doc.id.toString()); // console.log("updated doc:", loadDocAfter.content); return loadDoc.content; }