UNPKG

tidecloak-js

Version:

TideCloak client side JS SDK

31 lines (30 loc) 1.47 kB
import { sign, signAsync, signNonDeterministicAsync, verifyAsync } from "../../../Ed25519.js"; import BaseScheme from "../BaseScheme.js"; import { SchemeType } from "../SchemeRegistry.js"; import { Ed25519PrivateComponent, Ed25519PublicComponent, Ed25519SeedComponent } from "./Ed25519Components.js"; export default class Ed25519Scheme extends BaseScheme{ static get Name() { return "Ed25519Scheme"; } /** * WITHOUT DETERMINISM. Prefix is generated via randomisation. * @returns */ static GetSigningFunction = () => { const signingFunc = (msg, component) => { if(msg instanceof Uint8Array && component instanceof Ed25519PrivateComponent){ return signNonDeterministicAsync(msg, component.priv); } throw Error("Mismatch of expected types (Uint8Array, Ed25519PrivateComponent)"); } return signingFunc; } static GetVerifyingFunction = () => { const verifyingFunc = async (msg, signature, component) => { if(msg instanceof Uint8Array && signature instanceof Uint8Array && component instanceof Ed25519PublicComponent){ const valid = await verifyAsync(signature, msg, component.rawBytes); if(!valid) throw Error("Signature validation failed"); } else throw Error("Mismatch of expected types (Uint8Array, Uint8Array, Ed25519PublicComponent)"); } return verifyingFunc; } }