UNPKG

chaingate

Version:

A complete TypeScript library for connecting to and making transactions on different blockchains

49 lines 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SeedWallet = void 0; const Seed_1 = require("../../entities/Secret/implementations/Seed"); const SeedableWallet_1 = require("../../abstract/SeedableWallet"); const Encrypted_1 = require("../../entities/WalletEncryption/Encrypted"); const Utils_1 = require("../../../InternalUtils/Utils"); const ExtendedPublicKey_1 = require("../../entities/Secret/implementations/ExtendedPublicKey"); class SeedWallet extends SeedableWallet_1.SeedableWallet { constructor(context, secret, askForPassword) { super(context, secret, askForPassword); } async serializeInternal() { return await this.internalSerialize('seed'); } async getSeed() { return new Seed_1.Seed(await this.walletEncryption.getSecretDecrypted()); } static async new(context, seed, warnAboutUnencrypted, encrypt) { const newSeed = new Seed_1.Seed(seed); const wallet = new SeedWallet(context, newSeed, encrypt?.askForPassword); wallet.walletUniqueId = newSeed.uniqueId; await wallet.generateAllCurrencyDefaultDerivations(); if (encrypt) await wallet.walletEncryption.encrypt(encrypt.password); wallet.walletEncryption.warnAboutUnencrypted = warnAboutUnencrypted; return wallet; } static async import(context, exported, askForPassword) { const encrypted = new Encrypted_1.Encrypted({ iterations: exported.secret.iterations, dkLen: exported.secret.dkLen, nonce: (0, Utils_1.hexToBytes)(exported.secret.nonce), salt: (0, Utils_1.hexToBytes)(exported.secret.salt), data: (0, Utils_1.hexToBytes)(exported.secret.data), cipher: exported.secret.cipher, }); if (!(exported.walletType == 'seed')) throw new Error('Wallet format error'); const wallet = new SeedWallet(context, encrypted, askForPassword); wallet.walletUniqueId = exported.walletUniqueId; wallet.derivationPaths = (0, Utils_1.recordToMap)(exported.derivationPaths); const derivationResultsStr = (0, Utils_1.recordToMap)(exported.publicKeys); wallet.derivationResults = (0, Utils_1.transformMap)(derivationResultsStr, (t) => new ExtendedPublicKey_1.ExtendedPublicKey(t)); return wallet; } } exports.SeedWallet = SeedWallet; //# sourceMappingURL=SeedWallet.js.map