UNPKG

chaingate

Version:

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

58 lines 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SeedableWallet = void 0; const HDWallet_1 = require("./HDWallet/HDWallet"); const WalletEncryption_1 = require("../entities/WalletEncryption/WalletEncryption"); const Encrypted_1 = require("../entities/WalletEncryption/Encrypted"); const Utils_1 = require("../../InternalUtils/Utils"); const CurrencyModules_1 = require("../../Currencies/CurrencyModules"); class SeedableWallet extends HDWallet_1.HDWallet { supportedCurrencies = CurrencyModules_1.AllCurrencies; walletEncryption; walletUniqueId; constructor(client, markets, secret, askForPassword) { const transports = { getPublicKeyProvider: async (currencyId) => { const derivationPath = this.getDerivationPath(currencyId); return this.deriveFromPathUsingCache.bind(this, derivationPath); }, getPrivateKeyProvider: async (currencyId) => { const derivationPath = this.getDerivationPath(currencyId); const seed = await this.getSeed(); return seed.getPrivateKey.bind(seed, derivationPath); }, }; super(client, transports, markets); this.walletEncryption = new WalletEncryption_1.WalletEncryption(secret instanceof Encrypted_1.Encrypted ? secret : secret.raw, askForPassword); } async deriveFromPath(derivationPath) { const seed = await this.getSeed(); return seed.getExtendedPublicKey(derivationPath); } async internalSerialize(walletType) { const secret = this.walletEncryption.getSecret(); if (!(secret instanceof Encrypted_1.Encrypted)) throw new WalletEncryption_1.WalletIsNotEncrypted(); const publicKeysStr = (0, Utils_1.transformMap)(this.derivationResults, (e) => e.xpub); return { format: 'ChainGate Serialize Wallet Format Version 2', walletUniqueId: await this.getWalletUniqueId(), walletType: walletType, secret: { iterations: secret.iterations, dkLen: secret.dkLen, nonce: (0, Utils_1.bytesToHex)(secret.nonce, false), salt: (0, Utils_1.bytesToHex)(secret.salt, false), data: (0, Utils_1.bytesToHex)(secret.data, false), cipher: secret.cipher, }, publicKeys: (0, Utils_1.mapToRecord)(publicKeysStr), derivationPaths: (0, Utils_1.mapToRecord)(this.derivationPaths), }; } async getWalletUniqueId() { return this.walletUniqueId; } } exports.SeedableWallet = SeedableWallet; //# sourceMappingURL=SeedableWallet.js.map