chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
58 lines • 2.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SeedableWallet = void 0;
const HDWallet_1 = require("./HDWallet/HDWallet");
const Wallet_1 = require("../Wallet");
const WalletEncryption_1 = require("../entities/WalletEncryption/WalletEncryption");
const Encrypted_1 = require("../entities/WalletEncryption/Encrypted");
const Utils_1 = require("../../Utils/Utils");
class SeedableWallet extends HDWallet_1.HDWallet {
walletEncryption;
walletUniqueId;
constructor(apiClient, secret, askForPassword) {
const currencyProviders = {
getPublicKeyProvider: async (currencyInfo) => {
const derivationPath = this.getDerivationPath(currencyInfo);
return this.deriveFromPathUsingCache.bind(this, derivationPath);
},
getPrivateKeyProvider: async (currencyInfo) => {
const derivationPath = this.getDerivationPath(currencyInfo);
const seed = await this.getSeed();
return seed.getPrivateKey.bind(seed, derivationPath);
}
};
super(apiClient, currencyProviders);
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;
}
supportedCurrencies = Wallet_1.Currencies;
}
exports.SeedableWallet = SeedableWallet;
//# sourceMappingURL=SeedableWallet.js.map