chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
32 lines • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EvmWallet = void 0;
const ethers_1 = require("ethers");
const Utils_1 = require("../../../../InternalUtils/Utils");
const EvmTransaction_1 = require("./EvmTransaction");
const CurrencyWallet_1 = require("../../CurrencyWallet");
class EvmWallet extends CurrencyWallet_1.CurrencyWallet {
constructor(utils, transports) {
super(utils, transports);
}
async getAddress() {
const publicKey = await (await this.transports.getPublicKeyProvider(this.utils.currencyInfo.id))();
return ethers_1.ethers.computeAddress((0, Utils_1.bytesToHex)(publicKey.raw, true));
}
async getBalance() {
return this.utils.addressBalance(await this.getAddress());
}
async createTransfer(toAddress, amount) {
return this.prepareSmartContractTransaction(toAddress, amount, null);
}
async prepareSmartContractTransaction(smartContractAddress, amount, data) {
const privateKeyProvider = await this.transports.getPrivateKeyProvider(this.utils.currencyInfo.id);
return new EvmTransaction_1.EvmTransaction(this.utils, await this.getAddress(), smartContractAddress, amount, data, privateKeyProvider);
}
async signMessage(message) {
const signer = new ethers_1.ethers.Wallet(new ethers_1.SigningKey((await this.getPrivateKey()).raw));
return await signer.signMessage(message);
}
}
exports.EvmWallet = EvmWallet;
//# sourceMappingURL=EvmWallet.js.map