UNPKG

@bajetech/digitalbits-wallet-sdk

Version:

A library to make it easier to write wallets that interact with the DigitalBits blockchain

46 lines 2.49 kB
import { __assign, __awaiter, __generator, __rest } from "tslib"; import { decrypt, encrypt } from "../helpers/ScryptEncryption"; var NAME = "ScryptEncrypter"; /** * Encrypt keys with scrypt. */ export var ScryptEncrypter = { name: NAME, encryptKey: function (params) { return __awaiter(this, void 0, void 0, function () { var key, password, privateKey, path, extra, publicKey, type, props, _a, encryptedPhrase, salt; return __generator(this, function (_b) { switch (_b.label) { case 0: key = params.key, password = params.password; privateKey = key.privateKey, path = key.path, extra = key.extra, publicKey = key.publicKey, type = key.type, props = __rest(key, ["privateKey", "path", "extra", "publicKey", "type"]); return [4 /*yield*/, encrypt({ password: password, phrase: JSON.stringify({ privateKey: privateKey, path: path, extra: extra, publicKey: publicKey, type: type }), })]; case 1: _a = _b.sent(), encryptedPhrase = _a.encryptedPhrase, salt = _a.salt; return [2 /*return*/, __assign(__assign({}, props), { encryptedBlob: encryptedPhrase, encrypterName: NAME, salt: salt })]; } }); }); }, decryptKey: function (params) { return __awaiter(this, void 0, void 0, function () { var encryptedKey, password, encrypterName, salt, encryptedBlob, props, data, _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: encryptedKey = params.encryptedKey, password = params.password; encrypterName = encryptedKey.encrypterName, salt = encryptedKey.salt, encryptedBlob = encryptedKey.encryptedBlob, props = __rest(encryptedKey, ["encrypterName", "salt", "encryptedBlob"]); _b = (_a = JSON).parse; return [4 /*yield*/, decrypt({ phrase: encryptedBlob, salt: salt, password: password })]; case 1: data = _b.apply(_a, [_c.sent()]); return [2 /*return*/, __assign(__assign({}, props), data)]; } }); }); }, }; //# sourceMappingURL=ScryptEncrypter.js.map