crypto.js — svelte Source File
Architecture documentation for crypto.js, a javascript file in the svelte codebase. 1 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR 3cae8e56_c0fb_4ba6_0874_ffdf0dfa134c["crypto.js"] c9866d91_a204_fa55_a9e3_6bcc6aaaec1e["esm-env"] 3cae8e56_c0fb_4ba6_0874_ffdf0dfa134c --> c9866d91_a204_fa55_a9e3_6bcc6aaaec1e fa4ffc74_bd09_5a41_973b_d02f0d2719e7["crypto.test.ts"] fa4ffc74_bd09_5a41_973b_d02f0d2719e7 --> 3cae8e56_c0fb_4ba6_0874_ffdf0dfa134c 25166256_49ce_81f2_0877_fdbc689bed91["renderer.js"] 25166256_49ce_81f2_0877_fdbc689bed91 --> 3cae8e56_c0fb_4ba6_0874_ffdf0dfa134c style 3cae8e56_c0fb_4ba6_0874_ffdf0dfa134c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { BROWSER } from 'esm-env';
let text_encoder;
// TODO - remove this and use global `crypto` when we drop Node 18
let crypto;
/** @param {string} data */
export async function sha256(data) {
text_encoder ??= new TextEncoder();
// @ts-expect-error
crypto ??= globalThis.crypto?.subtle?.digest
? globalThis.crypto
: // @ts-ignore - we don't install node types in the prod build
// don't use 'node:crypto' because static analysers will think we rely on node when we don't
(await import(/* @vite-ignore */ 'node:' + 'crypto')).webcrypto;
const hash_buffer = await crypto.subtle.digest('SHA-256', text_encoder.encode(data));
return base64_encode(hash_buffer);
}
/**
* @param {Uint8Array} bytes
* @returns {string}
*/
export function base64_encode(bytes) {
// Using `Buffer` is faster than iterating
// @ts-ignore
if (!BROWSER && globalThis.Buffer) {
// @ts-ignore
return globalThis.Buffer.from(bytes).toString('base64');
}
let binary = '';
for (let i = 0; i < bytes.length; i++) {
binary += String.fromCharCode(bytes[i]);
}
return btoa(binary);
}
Domain
Subdomains
Functions
Dependencies
- esm-env
Imported By
Source
Frequently Asked Questions
What does crypto.js do?
crypto.js is a source file in the svelte codebase, written in javascript. It belongs to the ServerRuntime domain, Serialization subdomain.
What functions are defined in crypto.js?
crypto.js defines 2 function(s): base64_encode, sha256.
What does crypto.js depend on?
crypto.js imports 1 module(s): esm-env.
What files import crypto.js?
crypto.js is imported by 2 file(s): crypto.test.ts, renderer.js.
Where is crypto.js in the architecture?
crypto.js is located at packages/svelte/src/internal/server/crypto.js (domain: ServerRuntime, subdomain: Serialization, directory: packages/svelte/src/internal/server).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free