@zlattice/lattice-js
Version:
Lattice blockchain TypeScript SDK with dual module support (CJS + ESM)
29 lines • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCrypto = createCrypto;
const constants_1 = require("../common/constants.js");
const crypto_secp256k1_1 = require("./crypto-secp256k1.js");
const crypto_sm2p256v1_1 = require("./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
*/
function createCrypto(curve) {
if (cryptoServiceMap.has(curve)) {
return cryptoServiceMap.get(curve);
}
switch (curve) {
case constants_1.Curves.Secp256k1:
cryptoServiceMap.set(curve, new crypto_secp256k1_1.NIST());
return cryptoServiceMap.get(curve);
case constants_1.Curves.Sm2p256v1:
cryptoServiceMap.set(curve, new crypto_sm2p256v1_1.GM());
return cryptoServiceMap.get(curve);
default:
throw new Error(`Unsupported curve: ${curve}`);
}
}
//# sourceMappingURL=crypto.js.map