-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from xmtp/rygine/crypto
- Loading branch information
Showing
11 changed files
with
111 additions
and
42 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,5 @@ | ||
--- | ||
"@xmtp/frames-client": patch | ||
--- | ||
|
||
Updated crypto imports, build, and exports |
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 @@ | ||
export const { crypto } = window; |
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 |
---|---|---|
@@ -1,24 +1 @@ | ||
let cachedCrypto: Crypto | undefined; | ||
|
||
async function getCrypto(): Promise<Crypto> { | ||
if (typeof crypto !== "undefined") { | ||
return crypto; | ||
} | ||
|
||
if (typeof cachedCrypto !== "undefined") { | ||
return cachedCrypto; | ||
} | ||
|
||
if (typeof window !== "undefined" && window.crypto) { | ||
return window.crypto; | ||
} | ||
|
||
cachedCrypto = (await import("crypto")).webcrypto as Crypto; | ||
|
||
return cachedCrypto; | ||
} | ||
|
||
export async function sha256(data: Uint8Array): Promise<Uint8Array> { | ||
const digest = await (await getCrypto()).subtle.digest("SHA-256", data); | ||
return new Uint8Array(digest); | ||
} | ||
export { webcrypto as crypto } from "node:crypto"; |
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,6 @@ | ||
import { crypto } from "./crypto"; | ||
|
||
export async function sha256(data: Uint8Array): Promise<Uint8Array> { | ||
const digest = await crypto.subtle.digest("SHA-256", data); | ||
return new Uint8Array(digest); | ||
} |
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 was deleted.
Oops, something went wrong.
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