@pgchain/blockchain-libs
Version:
PGWallet Blockchain Libs
30 lines • 1.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WalletController = void 0;
class WalletController {
constructor(storage) {
this.storage = storage;
}
async getWalletIds() {
return (await this.storage.get(['WALLET_IDS']))[0] || [];
}
async getWallets() {
const walletIds = await this.getWalletIds();
return await this.storage.get(walletIds.map((id) => `WALLET_${id}`));
}
async createWallet() {
const walletIds = await this.getWalletIds();
const lastId = walletIds.length > 0 ? walletIds[walletIds.length - 1] : -1;
const id = lastId + 1;
const wallet = {
id,
createdTime: Date.now(),
modifiedTime: Date.now(),
};
await this.storage.set(`WALLET_${id}`, wallet);
await this.storage.set('WALLET_IDS', [...walletIds, id]);
return wallet;
}
}
exports.WalletController = WalletController;
//# sourceMappingURL=index.js.map