forked from priyanshur66/lit-secrets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Devin/1734393518 add example code tab (#7)
* feat: add example code tab to secret displays Co-Authored-By: Chris Cassano <chris@litprotocol.com> * prettier * better example code * include ipfsCid in secretObject --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
- Loading branch information
1 parent
fa12f1d
commit 4d2042c
Showing
4 changed files
with
205 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use client"; | ||
import { useState } from "react"; | ||
|
||
export default function Tabs({ tabs }) { | ||
const [activeTab, setActiveTab] = useState(0); | ||
|
||
return ( | ||
<div> | ||
<div className="border-b border-gray-200"> | ||
<nav className="-mb-px flex" aria-label="Tabs"> | ||
{tabs.map((tab, index) => ( | ||
<button | ||
key={tab.label} | ||
onClick={() => setActiveTab(index)} | ||
className={` | ||
py-2 px-4 border-b-2 font-medium text-sm | ||
${ | ||
activeTab === index | ||
? "border-orange-500 text-orange-600" | ||
: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300" | ||
} | ||
`} | ||
> | ||
{tab.label} | ||
</button> | ||
))} | ||
</nav> | ||
</div> | ||
<div className="mt-4">{tabs[activeTab].content}</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export function generateExampleCode(secretObject) { | ||
return `// Example code for using your encrypted secret | ||
const { encryptedData, dataToEncryptHash, accessControlConditions, litNetwork, ipfsCid } = ${JSON.stringify(secretObject, null, 2)}; | ||
// Initialize Lit client | ||
const client = new LitNodeClient({ litNetwork }); | ||
await client.connect(); | ||
// Auth your user by getting session sigs. This is setup to use metamask as the signer in a browser, but you can use any signer. | ||
// Docs on doing this on the server side are here: https://developer.litprotocol.com/sdk/access-control/quick-start#obtain-asessionsigson-the-server-side | ||
const sessionSigs = await this.litNodeClient.getSessionSigs({ | ||
chain: "ethereum", | ||
resourceAbilityRequests: [ | ||
{ | ||
resource: new LitActionResource("*"), | ||
ability: LIT_ABILITY.LitActionExecution, | ||
}, | ||
], | ||
}); | ||
// Run the lit action, which can use the secret internally | ||
const response = await litNodeClient.executeJs({ | ||
sessionSigs, | ||
ipfsCid, | ||
jsParams: { | ||
encryptedData, | ||
dataToEncryptHash, | ||
accessControlConditions, | ||
} | ||
}); | ||
`; | ||
} |