@alephium/web3-wallet
Version:
Simple wallets for Alephium
52 lines • 2.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NodeWallet = void 0;
const web3_1 = require("@alephium/web3");
class NodeWallet extends web3_1.SignerProviderWithMultipleAccounts {
constructor(walletName, nodeProvider, explorerProvider) {
super();
this.walletName = walletName;
this.nodeProvider = nodeProvider ?? web3_1.web3.getCurrentNodeProvider();
this.explorerProvider = explorerProvider ?? web3_1.web3.getCurrentExplorerProvider();
}
async setSelectedAccount(address) {
await this.nodeProvider.wallets.postWalletsWalletNameChangeActiveAddress(this.walletName, { address: address });
}
async getAccounts() {
const walletAddresses = await this.nodeProvider.wallets.getWalletsWalletNameAddresses(this.walletName);
const accounts = walletAddresses.addresses.map((acc) => ({
keyType: 'default',
publicKey: acc.publicKey,
address: acc.address,
group: acc.group
}));
return accounts;
}
async unsafeGetSelectedAccount() {
const response = await this.nodeProvider.wallets.getWalletsWalletNameAddresses(this.walletName);
const selectedAddressInfo = response.addresses.find((info) => info.address === response.activeAddress);
return {
keyType: 'default',
address: selectedAddressInfo.address,
group: (0, web3_1.groupOfAddress)(selectedAddressInfo.address),
publicKey: selectedAddressInfo.publicKey
};
}
async signRaw(signerAddress, hexString) {
const provider = this.nodeProvider;
const currentActiveAddressResponse = await provider.wallets.getWalletsWalletNameAddresses(this.walletName);
const { activeAddress } = currentActiveAddressResponse;
await provider.wallets.postWalletsWalletNameChangeActiveAddress(this.walletName, { address: signerAddress });
const { signature } = await provider.wallets.postWalletsWalletNameSign(this.walletName, { data: hexString });
await provider.wallets.postWalletsWalletNameChangeActiveAddress(this.walletName, { address: activeAddress });
return signature;
}
async unlock(password) {
return await this.nodeProvider.wallets.postWalletsWalletNameUnlock(this.walletName, { password });
}
async lock() {
return await this.nodeProvider.wallets.postWalletsWalletNameLock(this.walletName);
}
}
exports.NodeWallet = NodeWallet;
//# sourceMappingURL=node-wallet.js.map