UNPKG

chaingate

Version:

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

45 lines 2.19 kB
import { Seed } from '../../entities/Secret/implementations/Seed'; import { SeedableWallet } from '../../abstract/SeedableWallet'; import { Encrypted } from '../../entities/WalletEncryption/Encrypted'; import { hexToBytes, recordToMap, transformMap } from '../../../InternalUtils/Utils'; import { ExtendedPublicKey } from '../../entities/Secret/implementations/ExtendedPublicKey'; export class SeedWallet extends SeedableWallet { constructor(context, secret, askForPassword) { super(context, secret, askForPassword); } async serializeInternal() { return await this.internalSerialize('seed'); } async getSeed() { return new Seed(await this.walletEncryption.getSecretDecrypted()); } static async new(context, seed, warnAboutUnencrypted, encrypt) { const newSeed = new 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({ iterations: exported.secret.iterations, dkLen: exported.secret.dkLen, nonce: hexToBytes(exported.secret.nonce), salt: hexToBytes(exported.secret.salt), data: 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 = recordToMap(exported.derivationPaths); const derivationResultsStr = recordToMap(exported.publicKeys); wallet.derivationResults = transformMap(derivationResultsStr, (t) => new ExtendedPublicKey(t)); return wallet; } } //# sourceMappingURL=SeedWallet.js.map