UNPKG

@zlattice/lattice-js

Version:

Lattice blockchain TypeScript SDK with dual module support (CJS + ESM)

26 lines 878 B
import { Curves } from "../common/constants.js"; import { NIST } from "./crypto-secp256k1.js"; import { GM } from "./crypto-sm2p256v1.js"; const cryptoServiceMap = new Map(); /** * Create a new crypto service instance based on the curve * * @param curve The curve, like `Curves.Secp256k1` or `Curves.Sm2p256v1` * @returns The crypto service */ export function createCrypto(curve) { if (cryptoServiceMap.has(curve)) { return cryptoServiceMap.get(curve); } switch (curve) { case Curves.Secp256k1: cryptoServiceMap.set(curve, new NIST()); return cryptoServiceMap.get(curve); case Curves.Sm2p256v1: cryptoServiceMap.set(curve, new GM()); return cryptoServiceMap.get(curve); default: throw new Error(`Unsupported curve: ${curve}`); } } //# sourceMappingURL=crypto.js.map