-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MitulSonagara:master' into phone
- Loading branch information
Showing
8 changed files
with
130 additions
and
26 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
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
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
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,35 @@ | ||
"use client" | ||
|
||
import { savePrivateKey } from "@/lib/indexedDB"; | ||
import { IGenerateKeyWorker } from "@/types/comlinkWorkerTypes"; | ||
import axios from "axios"; | ||
import { wrap } from "comlink"; | ||
|
||
export default async function checkAndSaveKeys() { | ||
|
||
|
||
try { | ||
console.log("HITTING!") | ||
const worker = new Worker( | ||
new URL("../workers/crypto.ts", import.meta.url), | ||
{ | ||
type: "module", | ||
} | ||
); | ||
|
||
const { generateKeyPair } = wrap<IGenerateKeyWorker>(worker); | ||
|
||
const { publicKey, privateKey } = await generateKeyPair(); | ||
worker.terminate(); | ||
|
||
await savePrivateKey(privateKey); | ||
// Send public key to server to store it | ||
const response = await axios.post("/api/savePublicKey", { publicKey }); | ||
return true; | ||
|
||
} catch (error) { | ||
console.error("Error auto generating keys:", error); | ||
|
||
return false; | ||
} | ||
} |