import { CeramicClient } from "@ceramicnetwork/http-client"; import { Presentation, Proof, Credential } from "./interfaces"; import { encodeDIDWithLit, Secp256k1ProviderWithLit } from "key-did-provider-secp256k1-with-lit"; import { DID } from "dids"; import { getResolver } from "key-did-resolver"; import { TileDocument } from "@ceramicnetwork/stream-tile"; import { signMessageWithLit } from "./helpers/litHelpers"; // this code will be run on the node 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(); `; const proof = { // signature suite "type": "ECSDASignature", // timestamp "created": "2017-06-18T21:19:10Z", // purpose of proof "proofPurpose": "assertionMethod", // issuer public key "verificationMethod": "", // digital signature "jws": "" } export default async function generatePresentation(presentation: Presentation, credential: Credential[], issuer: string): Promise { let proofHolder = proof; let fullPresentation: Presentation = presentation; let jsResult; let encodedDID: string; let doc; let docId: string; console.log('$$$$$$$ -> props', {presentation, credential, proof, issuer}) // append credential(s) to it fullPresentation['verifiableCredential'] = [...credential]; fullPresentation['issuer'] = issuer; // sign message with old credential included in presentation const {dataSigned, encodedSig} = await signMessageWithLit(fullPresentation, litActionCode, issuer); const ceramicNetwork = process.env?.REACT_APP_CERAMIC_NETWORK ?? "https://ceramic-clay.3boxlabs.com"; const ceramic = new CeramicClient(ceramicNetwork); // append `proof` object with new signatures proofHolder.verificationMethod = dataSigned; proofHolder.jws = encodedSig; fullPresentation['proof'] = proofHolder as Proof; // start of creating DID for recipient // try { encodedDID = await encodeDIDWithLit({ pkpPublicKey: issuer }); // } catch (err) { // return err; // } console.log('$$$$$$ -> encodedDID', encodedDID) const provider = new Secp256k1ProviderWithLit({ did: encodedDID, ipfsId: "QmcZ2MuxkNrMbNKAVtK37tEmKJ8zwvFudin3rBEcHyhqJc", }); const did = new DID({provider, resolver: getResolver()}); // -- authenticate // try { await did.authenticate(); ceramic.did = did; // } catch (err) { // return err; // } // try { // -- write to ceramic stream doc = await TileDocument.create(ceramic, fullPresentation); docId = doc.id.toString(); console.log('$$$$$$ -> doc', docId) // } catch (err) { // return err; // } return { presentation: fullPresentation, docId } }