crypto
Import:
import { createHash } from "node:crypto";
Example:
import { createHash } from "node:crypto";
export function main(): void {
const hash = createHash("sha256").update("hello").digest("hex");
console.log(hash);
}
Keys
Key creation and signing helpers use KeyObject for parsed key material:
import { createPrivateKey, createPublicKey, sign, verify } from "node:crypto";
export function verifyMessage(privatePem: string, message: byte[]): boolean {
const privateKey = createPrivateKey(privatePem);
const publicKey = createPublicKey(privateKey);
const signature = sign("sha256", message, privateKey);
return verify("sha256", message, publicKey, signature);
}
This keeps repeated signing and verification paths typed around key objects
instead of untyped unknown values.
This is a package import, not ambient behavior. Keep the model explicit:
@tsonic/jsgives you the JS world@tsonic/nodejsgives you Node-style modules likenode:crypto