UNPKG

did-sdk-dev

Version:
43 lines 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var constant_1 = require("../common/constant"); var icbsc_js_1 = require("icbsc.js"); var crypto = (function () { function crypto() { this.newKey = function () { var keyPair = icbsc_js_1.Numeric.newHexKey(); keyPair.type = constant_1.constant.publicKey.type; return keyPair; }; this.sign = function (msgStr, hexPriKey, type) { if (type === void 0) { type = icbsc_js_1.Numeric.KeyType.sm2; } var msgByte = icbsc_js_1.Utils.parseUtf8StringToHex(msgStr); var privateKey = icbsc_js_1.Numeric.HexToKey(type, hexPriKey, true); return icbsc_js_1.Crypto.sm2.doSignature(msgByte, privateKey.getKey(), { hash: true }); }; this.verify = function (msgStr, signHex, hexPubKey, type) { if (type === void 0) { type = icbsc_js_1.Numeric.KeyType.sm2; } var msgByte = icbsc_js_1.Utils.parseUtf8StringToHex(msgStr); var publicKey = icbsc_js_1.Numeric.HexToKey(type, hexPubKey, false); return icbsc_js_1.Crypto.sm2.doVerifySignature(msgByte, signHex, publicKey.getKey(), { hash: true }); }; this.keyToChainKey = function (hexKey, isPrivate, type) { if (type === void 0) { type = icbsc_js_1.Numeric.KeyType.sm2; } return icbsc_js_1.Numeric.HexToKey(type, hexKey, isPrivate).toString(); }; this.encrypt = function (msgStr, hexPubKey, type) { if (type === void 0) { type = icbsc_js_1.Numeric.KeyType.sm2; } var msgByte = icbsc_js_1.Utils.parseUtf8StringToHex(msgStr); var publicKey = icbsc_js_1.Numeric.HexToKey(type, hexPubKey, false); return icbsc_js_1.Crypto.sm2.doEncrypt(msgByte, publicKey.toString()); }; this.decrypt = function (msg, hexPriKey, type) { if (type === void 0) { type = icbsc_js_1.Numeric.KeyType.sm2; } var privateKey = icbsc_js_1.Numeric.HexToKey(type, hexPriKey, true); return icbsc_js_1.Crypto.sm2.doDecrypt(msg, privateKey.toString()); }; } return crypto; }()); exports.crypto = crypto; //# sourceMappingURL=index.js.map