// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; contract TokenAuthorization { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); uint256 private _totalSupply; constructor(uint256 initialSupply) { _totalSupply = initialSupply; _balances[msg.sender] = initialSupply; } function totalSupply() external view returns (uint256) { return _totalSupply; } function balanceOf(address account) external view returns (uint256) { return _balances[account]; } function transfer(address to, uint256 amount) external returns (bool) { require(to != address(0), "Invalid recipient"); require(amount <= _balances[msg.sender], "Insufficient balance"); _balances[msg.sender] -= amount; _balances[to] += amount; emit Transfer(msg.sender, to, amount); return true; } function approve(address spender, uint256 amount) external returns (bool) { _allowances[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } function allowance(address owner, address spender) external view returns (uint256) { return _allowances[owner][spender]; } function transferFrom(address from, address to, uint256 amount) external returns (bool) { require(to != address(0), "Invalid recipient"); require(amount <= _balances[from], "Insufficient balance"); require(amount <= _allowances[from][msg.sender], "Insufficient allowance"); _balances[from] -= amount; _balances[to] += amount; _allowances[from][msg.sender] -= amount; emit Transfer(from, to, amount); return true; } }