arr00-testing-oz-contracts 0.0.0 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -0
- package/access/AccessControl.sol +206 -0
- package/access/IAccessControl.sol +98 -0
- package/access/Ownable.sol +100 -0
- package/access/Ownable2Step.sol +67 -0
- package/access/extensions/AccessControlDefaultAdminRules.sol +372 -0
- package/access/extensions/AccessControlEnumerable.sol +81 -0
- package/access/extensions/IAccessControlDefaultAdminRules.sol +192 -0
- package/access/extensions/IAccessControlEnumerable.sol +31 -0
- package/access/manager/AccessManaged.sol +118 -0
- package/access/manager/AccessManager.sol +781 -0
- package/access/manager/AuthorityUtils.sol +36 -0
- package/access/manager/IAccessManaged.sol +32 -0
- package/access/manager/IAccessManager.sol +410 -0
- package/access/manager/IAuthority.sol +14 -0
- package/account/Account.sol +151 -0
- package/account/extensions/draft-AccountERC7579.sol +430 -0
- package/account/extensions/draft-AccountERC7579Hooked.sol +113 -0
- package/account/extensions/draft-ERC7821.sol +70 -0
- package/account/paymaster/Paymaster.sol +170 -0
- package/account/paymaster/extensions/PaymasterERC20.sol +394 -0
- package/account/paymaster/extensions/PaymasterERC20Guarantor.sol +190 -0
- package/account/paymaster/extensions/PaymasterERC721Owner.sol +54 -0
- package/account/paymaster/extensions/PaymasterSigner.sol +125 -0
- package/account/utils/EIP7702Utils.sol +25 -0
- package/account/utils/ERC4337Utils.sol +317 -0
- package/account/utils/draft-ERC7579Utils.sol +314 -0
- package/build/contracts/AbstractSigner.json +13 -0
- package/build/contracts/AccessControl.json +239 -0
- package/build/contracts/AccessControlDefaultAdminRules.json +467 -0
- package/build/contracts/AccessControlEnumerable.json +301 -0
- package/build/contracts/AccessManaged.json +104 -0
- package/build/contracts/AccessManager.json +1189 -0
- package/build/contracts/Account.json +150 -0
- package/build/contracts/AccountERC7579.json +515 -0
- package/build/contracts/AccountERC7579Hooked.json +539 -0
- package/build/contracts/Accumulators.json +13 -0
- package/build/contracts/Address.json +25 -0
- package/build/contracts/Arrays.json +13 -0
- package/build/contracts/AuthorityUtils.json +13 -0
- package/build/contracts/Base58.json +25 -0
- package/build/contracts/Base64.json +25 -0
- package/build/contracts/BeaconProxy.json +97 -0
- package/build/contracts/BitMaps.json +13 -0
- package/build/contracts/BlockHeader.json +25 -0
- package/build/contracts/Blockhash.json +13 -0
- package/build/contracts/BridgeERC1155.json +508 -0
- package/build/contracts/BridgeERC20.json +260 -0
- package/build/contracts/BridgeERC721.json +270 -0
- package/build/contracts/BridgeERC7802.json +249 -0
- package/build/contracts/BridgeFungible.json +236 -0
- package/build/contracts/BridgeMultiToken.json +236 -0
- package/build/contracts/BridgeNonFungible.json +212 -0
- package/build/contracts/Bytes.json +13 -0
- package/build/contracts/CAIP10.json +13 -0
- package/build/contracts/CAIP2.json +13 -0
- package/build/contracts/Calldata.json +13 -0
- package/build/contracts/Checkpoints.json +19 -0
- package/build/contracts/CircularBuffer.json +19 -0
- package/build/contracts/Clones.json +19 -0
- package/build/contracts/Comparators.json +13 -0
- package/build/contracts/Context.json +13 -0
- package/build/contracts/Create2.json +19 -0
- package/build/contracts/Create3.json +19 -0
- package/build/contracts/CrosschainLinked.json +145 -0
- package/build/contracts/CrosschainRemoteExecutor.json +199 -0
- package/build/contracts/DoubleEndedQueue.json +13 -0
- package/build/contracts/ECDSA.json +41 -0
- package/build/contracts/EIP712.json +79 -0
- package/build/contracts/EIP7702Utils.json +13 -0
- package/build/contracts/ERC1155.json +428 -0
- package/build/contracts/ERC1155Burnable.json +474 -0
- package/build/contracts/ERC1155Crosschain.json +796 -0
- package/build/contracts/ERC1155Holder.json +111 -0
- package/build/contracts/ERC1155Pausable.json +477 -0
- package/build/contracts/ERC1155Supply.json +479 -0
- package/build/contracts/ERC1155URIStorage.json +428 -0
- package/build/contracts/ERC1155Utils.json +13 -0
- package/build/contracts/ERC1363.json +585 -0
- package/build/contracts/ERC1363Utils.json +36 -0
- package/build/contracts/ERC165.json +33 -0
- package/build/contracts/ERC165Checker.json +13 -0
- package/build/contracts/ERC1967Clones.json +13 -0
- package/build/contracts/ERC1967Proxy.json +84 -0
- package/build/contracts/ERC1967Utils.json +52 -0
- package/build/contracts/ERC20.json +322 -0
- package/build/contracts/ERC20Bridgeable.json +427 -0
- package/build/contracts/ERC20Burnable.json +353 -0
- package/build/contracts/ERC20Capped.json +362 -0
- package/build/contracts/ERC20Crosschain.json +573 -0
- package/build/contracts/ERC20FlashMint.json +432 -0
- package/build/contracts/ERC20Pausable.json +371 -0
- package/build/contracts/ERC20Permit.json +532 -0
- package/build/contracts/ERC20TemporaryApproval.json +346 -0
- package/build/contracts/ERC20TransferAuthorization.json +836 -0
- package/build/contracts/ERC20Votes.json +781 -0
- package/build/contracts/ERC20Wrapper.json +405 -0
- package/build/contracts/ERC2771Context.json +46 -0
- package/build/contracts/ERC2771Forwarder.json +439 -0
- package/build/contracts/ERC2981.json +126 -0
- package/build/contracts/ERC3009.json +668 -0
- package/build/contracts/ERC4337Utils.json +13 -0
- package/build/contracts/ERC4626.json +807 -0
- package/build/contracts/ERC6372Utils.json +19 -0
- package/build/contracts/ERC6909.json +415 -0
- package/build/contracts/ERC6909ContentURI.json +472 -0
- package/build/contracts/ERC6909Metadata.json +529 -0
- package/build/contracts/ERC6909TokenSupply.json +434 -0
- package/build/contracts/ERC721.json +447 -0
- package/build/contracts/ERC721Burnable.json +460 -0
- package/build/contracts/ERC721Consecutive.json +509 -0
- package/build/contracts/ERC721Crosschain.json +674 -0
- package/build/contracts/ERC721Enumerable.json +524 -0
- package/build/contracts/ERC721Holder.json +48 -0
- package/build/contracts/ERC721Pausable.json +496 -0
- package/build/contracts/ERC721Royalty.json +540 -0
- package/build/contracts/ERC721URIStorage.json +479 -0
- package/build/contracts/ERC721Utils.json +13 -0
- package/build/contracts/ERC721Votes.json +835 -0
- package/build/contracts/ERC721Wrapper.json +553 -0
- package/build/contracts/ERC7579Utils.json +119 -0
- package/build/contracts/ERC7739.json +103 -0
- package/build/contracts/ERC7739Utils.json +13 -0
- package/build/contracts/ERC7786Recipient.json +59 -0
- package/build/contracts/ERC7821.json +112 -0
- package/build/contracts/ERC7913P256Verifier.json +43 -0
- package/build/contracts/ERC7913RSAVerifier.json +43 -0
- package/build/contracts/ERC7913WebAuthnVerifier.json +43 -0
- package/build/contracts/EnumerableMap.json +36 -0
- package/build/contracts/EnumerableSet.json +13 -0
- package/build/contracts/Errors.json +51 -0
- package/build/contracts/Governor.json +1381 -0
- package/build/contracts/GovernorCountingFractional.json +1455 -0
- package/build/contracts/GovernorCountingOverridable.json +1612 -0
- package/build/contracts/GovernorCountingSimple.json +1410 -0
- package/build/contracts/GovernorCrosschain.json +1409 -0
- package/build/contracts/GovernorNoncesKeyed.json +1405 -0
- package/build/contracts/GovernorPreventLateQuorum.json +1461 -0
- package/build/contracts/GovernorProposalGuardian.json +1426 -0
- package/build/contracts/GovernorSequentialProposalId.json +1399 -0
- package/build/contracts/GovernorSettings.json +1477 -0
- package/build/contracts/GovernorStorage.json +1506 -0
- package/build/contracts/GovernorSuperQuorum.json +1429 -0
- package/build/contracts/GovernorTimelockAccess.json +1582 -0
- package/build/contracts/GovernorTimelockCompound.json +1449 -0
- package/build/contracts/GovernorTimelockControl.json +1426 -0
- package/build/contracts/GovernorVotes.json +1399 -0
- package/build/contracts/GovernorVotesQuorumFraction.json +1497 -0
- package/build/contracts/GovernorVotesSuperQuorumFraction.json +1657 -0
- package/build/contracts/Hashes.json +13 -0
- package/build/contracts/Heap.json +13 -0
- package/build/contracts/IAccessControl.json +207 -0
- package/build/contracts/IAccessControlDefaultAdminRules.json +406 -0
- package/build/contracts/IAccessControlEnumerable.json +250 -0
- package/build/contracts/IAccessManaged.json +104 -0
- package/build/contracts/IAccessManager.json +1085 -0
- package/build/contracts/IAccount.json +90 -0
- package/build/contracts/IAccountExecute.json +79 -0
- package/build/contracts/IAggregator.json +211 -0
- package/build/contracts/IAuthority.json +43 -0
- package/build/contracts/IBeacon.json +27 -0
- package/build/contracts/ICompoundTimelock.json +427 -0
- package/build/contracts/IERC1155.json +307 -0
- package/build/contracts/IERC1155Errors.json +116 -0
- package/build/contracts/IERC1155MetadataURI.json +326 -0
- package/build/contracts/IERC1155Receiver.json +111 -0
- package/build/contracts/IERC1271.json +38 -0
- package/build/contracts/IERC1363.json +385 -0
- package/build/contracts/IERC1363Receiver.json +48 -0
- package/build/contracts/IERC1363Spender.json +43 -0
- package/build/contracts/IERC165.json +33 -0
- package/build/contracts/IERC1820Implementer.json +38 -0
- package/build/contracts/IERC1820Registry.json +227 -0
- package/build/contracts/IERC1822Proxiable.json +27 -0
- package/build/contracts/IERC1967.json +59 -0
- package/build/contracts/IERC20.json +197 -0
- package/build/contracts/IERC20Errors.json +100 -0
- package/build/contracts/IERC20Metadata.json +236 -0
- package/build/contracts/IERC20Permit.json +89 -0
- package/build/contracts/IERC2309.json +45 -0
- package/build/contracts/IERC2612.json +89 -0
- package/build/contracts/IERC2981.json +62 -0
- package/build/contracts/IERC3009.json +163 -0
- package/build/contracts/IERC3009Cancel.json +66 -0
- package/build/contracts/IERC3156FlashBorrower.json +53 -0
- package/build/contracts/IERC3156FlashLender.json +91 -0
- package/build/contracts/IERC4626.json +626 -0
- package/build/contracts/IERC4906.json +331 -0
- package/build/contracts/IERC5267.json +63 -0
- package/build/contracts/IERC5313.json +27 -0
- package/build/contracts/IERC5805.json +233 -0
- package/build/contracts/IERC6372.json +40 -0
- package/build/contracts/IERC6909.json +319 -0
- package/build/contracts/IERC6909ContentURI.json +351 -0
- package/build/contracts/IERC6909Metadata.json +376 -0
- package/build/contracts/IERC6909TokenSupply.json +338 -0
- package/build/contracts/IERC721.json +299 -0
- package/build/contracts/IERC721Enumerable.json +355 -0
- package/build/contracts/IERC721Errors.json +117 -0
- package/build/contracts/IERC721Metadata.json +344 -0
- package/build/contracts/IERC721Receiver.json +48 -0
- package/build/contracts/IERC7579AccountConfig.json +65 -0
- package/build/contracts/IERC7579Execution.json +56 -0
- package/build/contracts/IERC7579Hook.json +101 -0
- package/build/contracts/IERC7579Module.json +59 -0
- package/build/contracts/IERC7579ModuleConfig.json +127 -0
- package/build/contracts/IERC7579Validator.json +159 -0
- package/build/contracts/IERC7674.json +221 -0
- package/build/contracts/IERC7751.json +40 -0
- package/build/contracts/IERC777.json +405 -0
- package/build/contracts/IERC777Recipient.json +52 -0
- package/build/contracts/IERC777Sender.json +52 -0
- package/build/contracts/IERC7786GatewaySource.json +116 -0
- package/build/contracts/IERC7786Recipient.json +43 -0
- package/build/contracts/IERC7802.json +119 -0
- package/build/contracts/IERC7821.json +51 -0
- package/build/contracts/IERC7913SignatureVerifier.json +43 -0
- package/build/contracts/IEntryPoint.json +305 -0
- package/build/contracts/IEntryPointExtra.json +80 -0
- package/build/contracts/IEntryPointNonces.json +38 -0
- package/build/contracts/IEntryPointStake.json +97 -0
- package/build/contracts/IGovernor.json +1095 -0
- package/build/contracts/IPaymaster.json +123 -0
- package/build/contracts/ITransparentUpgradeableProxy.json +77 -0
- package/build/contracts/IVotes.json +207 -0
- package/build/contracts/Initializable.json +37 -0
- package/build/contracts/InteroperableAddress.json +30 -0
- package/build/contracts/LowLevelCall.json +13 -0
- package/build/contracts/Math.json +13 -0
- package/build/contracts/Memory.json +13 -0
- package/build/contracts/MerkleProof.json +19 -0
- package/build/contracts/MerkleTree.json +35 -0
- package/build/contracts/MessageHashUtils.json +19 -0
- package/build/contracts/MultiSignerERC7913.json +176 -0
- package/build/contracts/MultiSignerERC7913Weighted.json +264 -0
- package/build/contracts/Multicall.json +49 -0
- package/build/contracts/Nonces.json +49 -0
- package/build/contracts/NoncesKeyed.json +73 -0
- package/build/contracts/Ownable.json +88 -0
- package/build/contracts/Ownable2Step.json +127 -0
- package/build/contracts/P256.json +13 -0
- package/build/contracts/Packing.json +19 -0
- package/build/contracts/Panic.json +13 -0
- package/build/contracts/Pausable.json +63 -0
- package/build/contracts/Paymaster.json +147 -0
- package/build/contracts/PaymasterERC20.json +209 -0
- package/build/contracts/PaymasterERC20Guarantor.json +234 -0
- package/build/contracts/PaymasterERC721Owner.json +160 -0
- package/build/contracts/PaymasterSigner.json +212 -0
- package/build/contracts/Proxy.json +18 -0
- package/build/contracts/ProxyAdmin.json +135 -0
- package/build/contracts/RLP.json +19 -0
- package/build/contracts/RSA.json +13 -0
- package/build/contracts/RateLimiter.json +19 -0
- package/build/contracts/ReentrancyGuard.json +19 -0
- package/build/contracts/ReentrancyGuardTransient.json +19 -0
- package/build/contracts/RelayedCall.json +13 -0
- package/build/contracts/SafeCast.json +68 -0
- package/build/contracts/SafeERC20.json +46 -0
- package/build/contracts/ShortStrings.json +30 -0
- package/build/contracts/SignatureChecker.json +13 -0
- package/build/contracts/SignedMath.json +13 -0
- package/build/contracts/SignerECDSA.json +27 -0
- package/build/contracts/SignerEIP7702.json +13 -0
- package/build/contracts/SignerERC7913.json +27 -0
- package/build/contracts/SignerP256.json +48 -0
- package/build/contracts/SignerRSA.json +32 -0
- package/build/contracts/SignerWebAuthn.json +48 -0
- package/build/contracts/SimulateCall.json +13 -0
- package/build/contracts/SlotDerivation.json +13 -0
- package/build/contracts/StorageSlot.json +13 -0
- package/build/contracts/Strings.json +40 -0
- package/build/contracts/Time.json +13 -0
- package/build/contracts/TimelockController.json +1010 -0
- package/build/contracts/TransientSlot.json +13 -0
- package/build/contracts/TransparentUpgradeableProxy.json +131 -0
- package/build/contracts/TrieProof.json +25 -0
- package/build/contracts/UUPSUpgradeable.json +119 -0
- package/build/contracts/UpgradeableBeacon.json +154 -0
- package/build/contracts/VestingWallet.json +364 -0
- package/build/contracts/VestingWalletCliff.json +367 -0
- package/build/contracts/Votes.json +402 -0
- package/build/contracts/VotesExtended.json +450 -0
- package/build/contracts/WebAuthn.json +13 -0
- package/crosschain/CrosschainLinked.sol +114 -0
- package/crosschain/CrosschainRemoteExecutor.sol +99 -0
- package/crosschain/ERC7786Recipient.sol +66 -0
- package/crosschain/bridges/BridgeERC1155.sol +131 -0
- package/crosschain/bridges/BridgeERC20.sol +42 -0
- package/crosschain/bridges/BridgeERC721.sol +62 -0
- package/crosschain/bridges/BridgeERC7802.sol +34 -0
- package/crosschain/bridges/abstract/BridgeFungible.sol +86 -0
- package/crosschain/bridges/abstract/BridgeMultiToken.sol +99 -0
- package/crosschain/bridges/abstract/BridgeNonFungible.sol +79 -0
- package/finance/VestingWallet.sol +160 -0
- package/finance/VestingWalletCliff.sol +55 -0
- package/governance/Governor.sol +825 -0
- package/governance/IGovernor.sol +454 -0
- package/governance/TimelockController.sol +470 -0
- package/governance/extensions/GovernorCountingFractional.sol +190 -0
- package/governance/extensions/GovernorCountingOverridable.sol +226 -0
- package/governance/extensions/GovernorCountingSimple.sol +96 -0
- package/governance/extensions/GovernorCrosschain.sol +31 -0
- package/governance/extensions/GovernorNoncesKeyed.sol +91 -0
- package/governance/extensions/GovernorPreventLateQuorum.sol +119 -0
- package/governance/extensions/GovernorProposalGuardian.sol +59 -0
- package/governance/extensions/GovernorSequentialProposalId.sol +75 -0
- package/governance/extensions/GovernorSettings.sol +106 -0
- package/governance/extensions/GovernorStorage.sol +134 -0
- package/governance/extensions/GovernorSuperQuorum.sol +59 -0
- package/governance/extensions/GovernorTimelockAccess.sol +346 -0
- package/governance/extensions/GovernorTimelockCompound.sol +162 -0
- package/governance/extensions/GovernorTimelockControl.sol +167 -0
- package/governance/extensions/GovernorVotes.sol +64 -0
- package/governance/extensions/GovernorVotesQuorumFraction.sol +113 -0
- package/governance/extensions/GovernorVotesSuperQuorumFraction.sol +135 -0
- package/governance/utils/IVotes.sol +60 -0
- package/governance/utils/Votes.sol +245 -0
- package/governance/utils/VotesExtended.sol +85 -0
- package/interfaces/IERC1155.sol +6 -0
- package/interfaces/IERC1155MetadataURI.sol +6 -0
- package/interfaces/IERC1155Receiver.sol +6 -0
- package/interfaces/IERC1271.sol +17 -0
- package/interfaces/IERC1363.sol +86 -0
- package/interfaces/IERC1363Receiver.sol +32 -0
- package/interfaces/IERC1363Spender.sol +26 -0
- package/interfaces/IERC165.sol +6 -0
- package/interfaces/IERC1820Implementer.sol +20 -0
- package/interfaces/IERC1820Registry.sol +112 -0
- package/interfaces/IERC1967.sol +24 -0
- package/interfaces/IERC20.sol +6 -0
- package/interfaces/IERC20Metadata.sol +6 -0
- package/interfaces/IERC2309.sol +19 -0
- package/interfaces/IERC2612.sol +8 -0
- package/interfaces/IERC2981.sol +26 -0
- package/interfaces/IERC3156.sol +7 -0
- package/interfaces/IERC3156FlashBorrower.sol +27 -0
- package/interfaces/IERC3156FlashLender.sol +41 -0
- package/interfaces/IERC4337.sol +255 -0
- package/interfaces/IERC4626.sol +230 -0
- package/interfaces/IERC4906.sol +20 -0
- package/interfaces/IERC5267.sol +28 -0
- package/interfaces/IERC5313.sol +16 -0
- package/interfaces/IERC5805.sol +9 -0
- package/interfaces/IERC6093.sol +162 -0
- package/interfaces/IERC6372.sol +19 -0
- package/interfaces/IERC6909.sol +131 -0
- package/interfaces/IERC721.sol +6 -0
- package/interfaces/IERC721Enumerable.sol +6 -0
- package/interfaces/IERC721Metadata.sol +6 -0
- package/interfaces/IERC721Receiver.sol +6 -0
- package/interfaces/IERC7751.sol +12 -0
- package/interfaces/IERC777.sol +200 -0
- package/interfaces/IERC777Recipient.sol +35 -0
- package/interfaces/IERC777Sender.sol +35 -0
- package/interfaces/IERC7786.sol +64 -0
- package/interfaces/IERC7913.sol +18 -0
- package/interfaces/draft-IERC1822.sol +20 -0
- package/interfaces/draft-IERC3009.sol +87 -0
- package/interfaces/draft-IERC7579.sol +227 -0
- package/interfaces/draft-IERC7674.sol +17 -0
- package/interfaces/draft-IERC7802.sol +32 -0
- package/interfaces/draft-IERC7821.sol +44 -0
- package/metatx/ERC2771Context.sol +90 -0
- package/metatx/ERC2771Forwarder.sol +376 -0
- package/package.json +29 -1
- package/proxy/Clones.sol +294 -0
- package/proxy/ERC1967/ERC1967Clones.sol +219 -0
- package/proxy/ERC1967/ERC1967Proxy.sol +62 -0
- package/proxy/ERC1967/ERC1967Utils.sol +177 -0
- package/proxy/Proxy.sol +69 -0
- package/proxy/beacon/BeaconProxy.sol +57 -0
- package/proxy/beacon/IBeacon.sol +16 -0
- package/proxy/beacon/UpgradeableBeacon.sol +70 -0
- package/proxy/transparent/ProxyAdmin.sol +45 -0
- package/proxy/transparent/TransparentUpgradeableProxy.sol +118 -0
- package/proxy/utils/Initializable.sol +238 -0
- package/proxy/utils/UUPSUpgradeable.sol +148 -0
- package/token/ERC1155/ERC1155.sol +417 -0
- package/token/ERC1155/IERC1155.sol +123 -0
- package/token/ERC1155/IERC1155Receiver.sol +59 -0
- package/token/ERC1155/extensions/ERC1155Burnable.sol +22 -0
- package/token/ERC1155/extensions/ERC1155Crosschain.sol +87 -0
- package/token/ERC1155/extensions/ERC1155Pausable.sol +38 -0
- package/token/ERC1155/extensions/ERC1155Supply.sol +88 -0
- package/token/ERC1155/extensions/ERC1155URIStorage.sol +58 -0
- package/token/ERC1155/extensions/IERC1155MetadataURI.sol +20 -0
- package/token/ERC1155/utils/ERC1155Holder.sol +42 -0
- package/token/ERC1155/utils/ERC1155Utils.sol +88 -0
- package/token/ERC20/ERC20.sol +305 -0
- package/token/ERC20/IERC20.sol +79 -0
- package/token/ERC20/extensions/ERC1363.sol +135 -0
- package/token/ERC20/extensions/ERC20Burnable.sol +38 -0
- package/token/ERC20/extensions/ERC20Capped.sol +54 -0
- package/token/ERC20/extensions/ERC20Crosschain.sol +39 -0
- package/token/ERC20/extensions/ERC20FlashMint.sol +130 -0
- package/token/ERC20/extensions/ERC20Pausable.sol +33 -0
- package/token/ERC20/extensions/ERC20Permit.sol +77 -0
- package/token/ERC20/extensions/ERC20TransferAuthorization.sol +91 -0
- package/token/ERC20/extensions/ERC20Votes.sol +83 -0
- package/token/ERC20/extensions/ERC20Wrapper.sol +93 -0
- package/token/ERC20/extensions/ERC4626.sol +304 -0
- package/token/ERC20/extensions/IERC20Metadata.sol +26 -0
- package/token/ERC20/extensions/IERC20Permit.sol +90 -0
- package/token/ERC20/extensions/draft-ERC20Bridgeable.sol +51 -0
- package/token/ERC20/extensions/draft-ERC20TemporaryApproval.sol +119 -0
- package/token/ERC20/extensions/draft-ERC3009.sol +152 -0
- package/token/ERC20/utils/ERC1363Utils.sol +95 -0
- package/token/ERC20/utils/SafeERC20.sol +292 -0
- package/token/ERC6909/ERC6909.sol +224 -0
- package/token/ERC6909/extensions/ERC6909ContentURI.sol +59 -0
- package/token/ERC6909/extensions/ERC6909Metadata.sol +83 -0
- package/token/ERC6909/extensions/ERC6909TokenSupply.sol +41 -0
- package/token/ERC721/ERC721.sol +433 -0
- package/token/ERC721/IERC721.sol +135 -0
- package/token/ERC721/IERC721Receiver.sol +28 -0
- package/token/ERC721/extensions/ERC721Burnable.sol +26 -0
- package/token/ERC721/extensions/ERC721Consecutive.sol +176 -0
- package/token/ERC721/extensions/ERC721Crosschain.sol +38 -0
- package/token/ERC721/extensions/ERC721Enumerable.sol +165 -0
- package/token/ERC721/extensions/ERC721Pausable.sol +37 -0
- package/token/ERC721/extensions/ERC721Royalty.sol +26 -0
- package/token/ERC721/extensions/ERC721URIStorage.sol +62 -0
- package/token/ERC721/extensions/ERC721Votes.sol +47 -0
- package/token/ERC721/extensions/ERC721Wrapper.sol +102 -0
- package/token/ERC721/extensions/IERC721Enumerable.sol +29 -0
- package/token/ERC721/extensions/IERC721Metadata.sol +27 -0
- package/token/ERC721/utils/ERC721Holder.sol +26 -0
- package/token/ERC721/utils/ERC721Utils.sol +50 -0
- package/token/common/ERC2981.sol +140 -0
- package/utils/Address.sol +167 -0
- package/utils/Arrays.sol +905 -0
- package/utils/Base58.sol +240 -0
- package/utils/Base64.sol +234 -0
- package/utils/BlockHeader.sol +312 -0
- package/utils/Blockhash.sol +54 -0
- package/utils/Bytes.sol +329 -0
- package/utils/CAIP10.sol +54 -0
- package/utils/CAIP2.sol +51 -0
- package/utils/Calldata.sol +25 -0
- package/utils/Comparators.sol +19 -0
- package/utils/Context.sol +28 -0
- package/utils/Create2.sol +91 -0
- package/utils/Create3.sol +133 -0
- package/utils/ERC6372Utils.sol +53 -0
- package/utils/Errors.sol +34 -0
- package/utils/LowLevelCall.sol +127 -0
- package/utils/Memory.sol +151 -0
- package/utils/Multicall.sol +37 -0
- package/utils/Nonces.sol +47 -0
- package/utils/NoncesKeyed.sol +75 -0
- package/utils/Packing.sol +1656 -0
- package/utils/Panic.sol +57 -0
- package/utils/Pausable.sol +112 -0
- package/utils/RLP.sol +487 -0
- package/utils/RateLimiter.sol +310 -0
- package/utils/ReentrancyGuard.sol +119 -0
- package/utils/ReentrancyGuardTransient.sol +84 -0
- package/utils/RelayedCall.sol +145 -0
- package/utils/ShortStrings.sol +122 -0
- package/utils/SimulateCall.sol +114 -0
- package/utils/SlotDerivation.sol +155 -0
- package/utils/StorageSlot.sol +143 -0
- package/utils/Strings.sol +532 -0
- package/utils/TransientSlot.sol +183 -0
- package/utils/cryptography/ECDSA.sol +284 -0
- package/utils/cryptography/EIP712.sol +168 -0
- package/utils/cryptography/Hashes.sol +31 -0
- package/utils/cryptography/MerkleProof.sol +510 -0
- package/utils/cryptography/MessageHashUtils.sol +228 -0
- package/utils/cryptography/P256.sol +409 -0
- package/utils/cryptography/RSA.sol +159 -0
- package/utils/cryptography/SignatureChecker.sol +199 -0
- package/utils/cryptography/TrieProof.sol +256 -0
- package/utils/cryptography/WebAuthn.sol +269 -0
- package/utils/cryptography/draft-ERC7739Utils.sol +215 -0
- package/utils/cryptography/signers/AbstractSigner.sol +23 -0
- package/utils/cryptography/signers/MultiSignerERC7913.sol +336 -0
- package/utils/cryptography/signers/MultiSignerERC7913Weighted.sol +208 -0
- package/utils/cryptography/signers/SignerECDSA.sol +56 -0
- package/utils/cryptography/signers/SignerEIP7702.sol +25 -0
- package/utils/cryptography/signers/SignerERC7913.sol +63 -0
- package/utils/cryptography/signers/SignerP256.sol +64 -0
- package/utils/cryptography/signers/SignerRSA.sol +65 -0
- package/utils/cryptography/signers/SignerWebAuthn.sol +45 -0
- package/utils/cryptography/signers/draft-ERC7739.sol +99 -0
- package/utils/cryptography/verifiers/ERC7913P256Verifier.sol +29 -0
- package/utils/cryptography/verifiers/ERC7913RSAVerifier.sol +23 -0
- package/utils/cryptography/verifiers/ERC7913WebAuthnVerifier.sol +45 -0
- package/utils/draft-InteroperableAddress.sol +245 -0
- package/utils/introspection/ERC165.sol +25 -0
- package/utils/introspection/ERC165Checker.sol +142 -0
- package/utils/introspection/IERC165.sol +25 -0
- package/utils/math/Math.sol +763 -0
- package/utils/math/SafeCast.sol +1162 -0
- package/utils/math/SignedMath.sol +68 -0
- package/utils/structs/Accumulators.sol +135 -0
- package/utils/structs/BitMaps.sol +61 -0
- package/utils/structs/Checkpoints.sol +881 -0
- package/utils/structs/CircularBuffer.sol +152 -0
- package/utils/structs/DoubleEndedQueue.sol +280 -0
- package/utils/structs/EnumerableMap.sol +1870 -0
- package/utils/structs/EnumerableSet.sol +1177 -0
- package/utils/structs/Heap.sol +259 -0
- package/utils/structs/MerkleTree.sol +267 -0
- package/utils/types/Time.sol +133 -0
- package/vendor/compound/ICompoundTimelock.sol +86 -0
package/utils/Base58.sol
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// OpenZeppelin Contracts (last updated v5.5.0) (utils/Base58.sol)
|
|
3
|
+
|
|
4
|
+
pragma solidity ^0.8.20;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @dev Provides a set of functions to operate with Base58 strings.
|
|
8
|
+
*
|
|
9
|
+
* Base58 is an encoding scheme that converts binary data into a human-readable text format.
|
|
10
|
+
* Similar to {Base64} but specifically designed for better human usability.
|
|
11
|
+
*
|
|
12
|
+
* 1. Human-friendly alphabet: Excludes visually similar characters to reduce human error:
|
|
13
|
+
* * No 0 (zero) vs O (capital o) confusion
|
|
14
|
+
* * No I (capital i) vs l (lowercase L) confusion
|
|
15
|
+
* * No non-alphanumeric characters like + or =
|
|
16
|
+
* 2. URL-safe: Contains only alphanumeric characters, making it safe for URLs without encoding.
|
|
17
|
+
*
|
|
18
|
+
* Initially based on https://github.com/storyicon/base58-solidity/commit/807428e5174e61867e4c606bdb26cba58a8c5cb1[storyicon's implementation] (MIT).
|
|
19
|
+
* Based on the updated and improved https://github.com/Vectorized/solady/blob/208e4f31cfae26e4983eb95c3488a14fdc497ad7/src/utils/Base58.sol[Vectorized version] (MIT).
|
|
20
|
+
*/
|
|
21
|
+
library Base58 {
|
|
22
|
+
/// @dev Unrecognized Base58 character on decoding.
|
|
23
|
+
error InvalidBase58Char(bytes1);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @dev Encode a `bytes` buffer as a Base58 `string`.
|
|
27
|
+
*/
|
|
28
|
+
function encode(bytes memory input) internal pure returns (string memory) {
|
|
29
|
+
return string(_encode(input));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @dev Decode a Base58 `string` into a `bytes` buffer.
|
|
34
|
+
*/
|
|
35
|
+
function decode(string memory input) internal pure returns (bytes memory) {
|
|
36
|
+
return _decode(bytes(input));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function _encode(bytes memory input) private pure returns (bytes memory output) {
|
|
40
|
+
uint256 inputLength = input.length;
|
|
41
|
+
if (inputLength == 0) return "";
|
|
42
|
+
|
|
43
|
+
assembly ("memory-safe") {
|
|
44
|
+
// Count number of zero bytes at the beginning of `input`. These are encoded using the same number of '1's
|
|
45
|
+
// at the beginning of the encoded string.
|
|
46
|
+
let inputLeadingZeros := 0
|
|
47
|
+
for {} lt(byte(0, mload(add(add(input, 0x20), inputLeadingZeros))), lt(inputLeadingZeros, inputLength)) {} {
|
|
48
|
+
inputLeadingZeros := add(inputLeadingZeros, 1)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Start the output offset by an over-estimate of the length.
|
|
52
|
+
// When converting from base-256 (bytes) to base-58, the theoretical length ratio is log(256)/log(58).
|
|
53
|
+
// We use 9886/7239 ≈ 1.3657 as a rational approximation that slightly over-estimates to ensure
|
|
54
|
+
// sufficient memory allocation.
|
|
55
|
+
let outputLengthEstim := add(inputLeadingZeros, div(mul(sub(inputLength, inputLeadingZeros), 9886), 7239))
|
|
56
|
+
|
|
57
|
+
// This is going to be our "scratch" workspace. We leave enough room so that we can store length + encoded output at the FMP location.
|
|
58
|
+
// 0x21 = 0x20 (32 bytes for result length prefix) + 0x1 (safety buffer for division truncation)
|
|
59
|
+
let scratch := add(mload(0x40), add(outputLengthEstim, 0x21))
|
|
60
|
+
|
|
61
|
+
// Chunk input into 31-byte limbs (248 bits) for efficient batch processing.
|
|
62
|
+
// Each limb fits safely in a 256-bit word with 8-bit overflow protection.
|
|
63
|
+
// Memory layout: [output chars] [limb₁(248 bits)][limb₂(248 bits)][limb₃(248 bits)]...
|
|
64
|
+
// ↑ scratch
|
|
65
|
+
// ↑ ptr (moves right)
|
|
66
|
+
let ptr := scratch
|
|
67
|
+
for {
|
|
68
|
+
// Handle partial first limb if input length isn't divisible by 31
|
|
69
|
+
let i := mod(inputLength, 31)
|
|
70
|
+
if i {
|
|
71
|
+
// Right-shift to align partial limb in high bits of 256-bit word
|
|
72
|
+
mstore(ptr, shr(mul(sub(32, i), 8), mload(add(input, 0x20))))
|
|
73
|
+
ptr := add(ptr, 0x20) // next limb
|
|
74
|
+
}
|
|
75
|
+
} lt(i, inputLength) {
|
|
76
|
+
ptr := add(ptr, 0x20) // next limb
|
|
77
|
+
i := add(i, 31) // move in buffer
|
|
78
|
+
} {
|
|
79
|
+
// Load 31 bytes from input, right-shift by 8 bits to leave 1 zero byte on the left.
|
|
80
|
+
mstore(ptr, shr(8, mload(add(add(input, 0x20), i))))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Store the encoding table. This overlaps with the FMP that we are going to reset later anyway.
|
|
84
|
+
// See https://datatracker.ietf.org/doc/html/draft-msporny-base58-03#section-2
|
|
85
|
+
mstore(0x1f, "123456789ABCDEFGHJKLMNPQRSTUVWXY")
|
|
86
|
+
mstore(0x3f, "Zabcdefghijkmnopqrstuvwxyz")
|
|
87
|
+
|
|
88
|
+
// Core Base58 encoding: repeated division by 58 on input limbs
|
|
89
|
+
// Memory layout: [output chars] [limb₁(248 bits)][limb₂(248 bits)][limb₃(248 bits)]...
|
|
90
|
+
// ↑ scratch ↑ ptr
|
|
91
|
+
// ↑ output (moves left)
|
|
92
|
+
// ↑ data (moves right)
|
|
93
|
+
for {
|
|
94
|
+
let data := scratch // Points to first non-zero limb
|
|
95
|
+
output := scratch // Builds result right-to-left from scratch
|
|
96
|
+
} 1 {} {
|
|
97
|
+
// Skip zero limbs at the beginning (limbs become 0 after repeated divisions)
|
|
98
|
+
for {} and(iszero(mload(data)), lt(data, ptr)) {
|
|
99
|
+
data := add(data, 0x20)
|
|
100
|
+
} {}
|
|
101
|
+
// Exit when all limbs are zero (conversion complete)
|
|
102
|
+
if eq(data, ptr) {
|
|
103
|
+
break
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Division by 58 across all remaining limbs
|
|
107
|
+
let carry := 0
|
|
108
|
+
for {
|
|
109
|
+
let i := data
|
|
110
|
+
} lt(i, ptr) {
|
|
111
|
+
i := add(i, 0x20)
|
|
112
|
+
} {
|
|
113
|
+
let acc := add(shl(248, carry), mload(i)) // Combine carry from previous limb with current limb
|
|
114
|
+
mstore(i, div(acc, 58)) // Store quotient back in limb
|
|
115
|
+
carry := mod(acc, 58) // Remainder becomes next carry
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Convert remainder (0-57) to Base58 character and store right-to-left in the output space
|
|
119
|
+
output := sub(output, 1)
|
|
120
|
+
mstore8(output, mload(carry))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Write the input leading zeros at the left of the encoded.
|
|
124
|
+
// This may spill to the left into the "length" of the buffer.
|
|
125
|
+
for {
|
|
126
|
+
let i := 0
|
|
127
|
+
} lt(i, inputLeadingZeros) {} {
|
|
128
|
+
i := add(i, 0x20)
|
|
129
|
+
mstore(sub(output, i), "11111111111111111111111111111111")
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Move output pointer to account for inputLeadingZeros
|
|
133
|
+
output := sub(output, add(inputLeadingZeros, 0x20))
|
|
134
|
+
|
|
135
|
+
// Store length and allocate (reserve) memory up to scratch.
|
|
136
|
+
mstore(output, sub(scratch, add(output, 0x20))) // Overwrite spilled bytes
|
|
137
|
+
mstore(0x40, scratch)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function _decode(bytes memory input) private pure returns (bytes memory output) {
|
|
142
|
+
bytes4 errorSelector = InvalidBase58Char.selector;
|
|
143
|
+
|
|
144
|
+
uint256 inputLength = input.length;
|
|
145
|
+
if (inputLength == 0) return "";
|
|
146
|
+
|
|
147
|
+
assembly ("memory-safe") {
|
|
148
|
+
let inputLeadingZeros := 0 // Number of leading '1' in `input`.
|
|
149
|
+
// Count leading zeros. In base58, zeros are represented using '1' (chr(49)).
|
|
150
|
+
for {} and(
|
|
151
|
+
eq(byte(0, mload(add(add(input, 0x20), inputLeadingZeros))), 49),
|
|
152
|
+
lt(inputLeadingZeros, inputLength)
|
|
153
|
+
) {} {
|
|
154
|
+
inputLeadingZeros := add(inputLeadingZeros, 1)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Estimate the output length using the base conversion ratio.
|
|
158
|
+
// When converting from base-58 to base-256 (bytes), the theoretical length ratio is log(58)/log(256).
|
|
159
|
+
// We use 6115/8351 ≈ 0.7322 as a rational approximation that slightly over-estimates to ensure
|
|
160
|
+
// sufficient memory allocation.
|
|
161
|
+
let outputLengthEstim := add(inputLeadingZeros, div(mul(sub(inputLength, inputLeadingZeros), 6115), 8351))
|
|
162
|
+
|
|
163
|
+
// This is going to be our "scratch" workspace. We leave enough room so that we can store length + decoded output at the FMP location.
|
|
164
|
+
// 0x21 = 0x20 (32 bytes for result length prefix) + 0x1 (safety buffer for division truncation)
|
|
165
|
+
let scratch := add(mload(0x40), add(outputLengthEstim, 0x21))
|
|
166
|
+
|
|
167
|
+
// Store the decoding table for character-to-value lookup. This overlaps with the FMP that we are going to reset later anyway.
|
|
168
|
+
// Maps ASCII characters (minus 49) to their Base58 numeric values (0-57), with 0xff for invalid characters
|
|
169
|
+
mstore(0x2a, 0x30313233343536373839)
|
|
170
|
+
mstore(0x20, 0x1718191a1b1c1d1e1f20ffffffffffff2122232425262728292a2bff2c2d2e2f)
|
|
171
|
+
mstore(0x00, 0x000102030405060708ffffffffffffff090a0b0c0d0e0f10ff1112131415ff16)
|
|
172
|
+
|
|
173
|
+
// Core Base58 decoding: process each character and accumulate into 31-byte limbs
|
|
174
|
+
// Memory layout: [output bytes] [limb₁(248 bits)][limb₂(248 bits)][limb₃(248 bits)]...
|
|
175
|
+
// ↑ scratch
|
|
176
|
+
// ↑ ptr (moves right as limbs are added)
|
|
177
|
+
let ptr := scratch
|
|
178
|
+
let mask := shr(8, not(0))
|
|
179
|
+
for {
|
|
180
|
+
let j := 0
|
|
181
|
+
} lt(j, inputLength) {
|
|
182
|
+
j := add(j, 1)
|
|
183
|
+
} {
|
|
184
|
+
// Decode each character: convert from ASCII to Base58 numeric value (0-57)
|
|
185
|
+
let c := sub(byte(0, mload(add(add(input, 0x20), j))), 49) // Offset from '1' (ASCII 49)
|
|
186
|
+
|
|
187
|
+
// Validate character using bit manipulation: each bit in the bitmask represents a valid character offset
|
|
188
|
+
// 0x3fff7ff03ffbeff01ff has bits set for all valid Base58 characters (excludes 0, O, I, l)
|
|
189
|
+
// shl(c, 1) creates a single bit at position c, AND with bitmask checks if character is valid
|
|
190
|
+
// slither-disable-next-line incorrect-shift
|
|
191
|
+
if iszero(and(shl(c, 1), 0x3fff7ff03ffbeff01ff)) {
|
|
192
|
+
mstore(0, errorSelector)
|
|
193
|
+
mstore(4, shl(248, add(c, 49)))
|
|
194
|
+
revert(0, 0x24)
|
|
195
|
+
}
|
|
196
|
+
let carry := byte(0, mload(c)) // Look up Base58 numeric value from decoding table
|
|
197
|
+
|
|
198
|
+
// Multiplication by 58 and addition across all existing limbs
|
|
199
|
+
for {
|
|
200
|
+
let i := scratch
|
|
201
|
+
} lt(i, ptr) {
|
|
202
|
+
i := add(i, 0x20)
|
|
203
|
+
} {
|
|
204
|
+
let acc := add(carry, mul(58, mload(i))) // Multiply limb by 58 and add carry
|
|
205
|
+
mstore(i, and(mask, acc)) // Store lower 248 bits back in limb
|
|
206
|
+
carry := shr(248, acc) // Upper bits become carry for next limb
|
|
207
|
+
}
|
|
208
|
+
// If carry remains, we need a new limb to store the overflow
|
|
209
|
+
if carry {
|
|
210
|
+
mstore(ptr, carry)
|
|
211
|
+
ptr := add(ptr, 0x20) // Extend limbs array
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Copy and compact the uint248 limbs + remove any zeros at the beginning.
|
|
216
|
+
output := scratch
|
|
217
|
+
for {
|
|
218
|
+
let i := scratch
|
|
219
|
+
} lt(i, ptr) {
|
|
220
|
+
i := add(i, 0x20)
|
|
221
|
+
} {
|
|
222
|
+
output := sub(output, 31)
|
|
223
|
+
mstore(sub(output, 1), mload(i))
|
|
224
|
+
}
|
|
225
|
+
for {} lt(byte(0, mload(output)), lt(output, scratch)) {} {
|
|
226
|
+
output := add(output, 1)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Add the zeros that were encoded in the input (prefix '1's)
|
|
230
|
+
calldatacopy(sub(output, inputLeadingZeros), calldatasize(), inputLeadingZeros)
|
|
231
|
+
|
|
232
|
+
// Move output pointer to account for inputLeadingZeros
|
|
233
|
+
output := sub(output, add(inputLeadingZeros, 0x20))
|
|
234
|
+
|
|
235
|
+
// Store length and allocate (reserve) memory up to scratch.
|
|
236
|
+
mstore(output, sub(scratch, add(output, 0x20)))
|
|
237
|
+
mstore(0x40, scratch)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
package/utils/Base64.sol
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// OpenZeppelin Contracts (last updated v5.6.0) (utils/Base64.sol)
|
|
3
|
+
|
|
4
|
+
pragma solidity ^0.8.20;
|
|
5
|
+
|
|
6
|
+
import {SafeCast} from "./math/SafeCast.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @dev Provides a set of functions to operate with Base64 strings.
|
|
10
|
+
*/
|
|
11
|
+
library Base64 {
|
|
12
|
+
using SafeCast for bool;
|
|
13
|
+
|
|
14
|
+
error InvalidBase64Char(bytes1);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @dev Converts a `bytes` to its Base64 `string` representation.
|
|
18
|
+
*/
|
|
19
|
+
function encode(bytes memory data) internal pure returns (string memory) {
|
|
20
|
+
return string(_encode(data, false));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @dev Converts a `bytes` to its Base64Url `string` representation.
|
|
25
|
+
* Output is not padded with `=` as specified in https://www.rfc-editor.org/rfc/rfc4648[rfc4648].
|
|
26
|
+
*/
|
|
27
|
+
function encodeURL(bytes memory data) internal pure returns (string memory) {
|
|
28
|
+
return string(_encode(data, true));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @dev Converts a Base64 `string` to the `bytes` it represents.
|
|
33
|
+
*
|
|
34
|
+
* * Supports padded and unpadded inputs.
|
|
35
|
+
* * Supports both encoding ({encode} and {encodeURL}) seamlessly.
|
|
36
|
+
* * Reverts with {InvalidBase64Char} if the input contains an invalid character.
|
|
37
|
+
*/
|
|
38
|
+
function decode(string memory data) internal pure returns (bytes memory) {
|
|
39
|
+
return _decode(bytes(data));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @dev Internal table-agnostic encoding
|
|
44
|
+
*
|
|
45
|
+
* Padding is enabled when using the Base64 table, and disabled when using the Base64Url table.
|
|
46
|
+
* See sections 4 and 5 of https://datatracker.ietf.org/doc/html/rfc4648
|
|
47
|
+
*/
|
|
48
|
+
function _encode(bytes memory data, bool urlAndFilenameSafe) private pure returns (bytes memory result) {
|
|
49
|
+
/**
|
|
50
|
+
* Inspired by Brecht Devos (Brechtpd) implementation - MIT license
|
|
51
|
+
* https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol
|
|
52
|
+
*/
|
|
53
|
+
if (data.length == 0) return "";
|
|
54
|
+
|
|
55
|
+
// Padding is enabled by default, but disabled when the "urlAndFilenameSafe" alphabet is used
|
|
56
|
+
//
|
|
57
|
+
// If padding is enabled, the final length should be `bytes` data length divided by 3 rounded up and then
|
|
58
|
+
// multiplied by 4 so that it leaves room for padding the last chunk
|
|
59
|
+
// - `data.length + 2` -> Prepare for division rounding up
|
|
60
|
+
// - `/ 3` -> Number of 3-bytes chunks (rounded up)
|
|
61
|
+
// - `4 *` -> 4 characters for each chunk
|
|
62
|
+
// This is equivalent to: 4 * Math.ceil(data.length / 3)
|
|
63
|
+
//
|
|
64
|
+
// If padding is disabled, the final length should be `bytes` data length multiplied by 4/3 rounded up as
|
|
65
|
+
// opposed to when padding is required to fill the last chunk.
|
|
66
|
+
// - `4 * data.length` -> 4 characters for each chunk
|
|
67
|
+
// - ` + 2` -> Prepare for division rounding up
|
|
68
|
+
// - `/ 3` -> Number of 3-bytes chunks (rounded up)
|
|
69
|
+
// This is equivalent to: Math.ceil((4 * data.length) / 3)
|
|
70
|
+
uint256 resultLength = urlAndFilenameSafe ? (4 * data.length + 2) / 3 : 4 * ((data.length + 2) / 3);
|
|
71
|
+
|
|
72
|
+
assembly ("memory-safe") {
|
|
73
|
+
result := mload(0x40)
|
|
74
|
+
|
|
75
|
+
// Store the encoding table in the scratch space (and fmp ptr) to avoid memory allocation
|
|
76
|
+
//
|
|
77
|
+
// Base64 (ascii) A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 + /
|
|
78
|
+
// Base64 (hex) 4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435363738392b2f
|
|
79
|
+
// Base64Url (ascii) A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 - _
|
|
80
|
+
// Base64Url (hex) 4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a303132333435363738392d5f
|
|
81
|
+
// xor (hex) 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000670
|
|
82
|
+
mstore(0x1f, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef")
|
|
83
|
+
mstore(0x3f, xor("ghijklmnopqrstuvwxyz0123456789+/", mul(urlAndFilenameSafe, 0x670)))
|
|
84
|
+
|
|
85
|
+
// Prepare result pointer, jump over length
|
|
86
|
+
let resultPtr := add(result, 0x20)
|
|
87
|
+
let resultEnd := add(resultPtr, resultLength)
|
|
88
|
+
let dataPtr := data
|
|
89
|
+
let endPtr := add(data, mload(data))
|
|
90
|
+
|
|
91
|
+
// In some cases, the last iteration will read bytes after the end of the data. We cache the value, and
|
|
92
|
+
// set it to zero to make sure no dirty bytes are read in that section.
|
|
93
|
+
let afterPtr := add(endPtr, 0x20)
|
|
94
|
+
let afterCache := mload(afterPtr)
|
|
95
|
+
mstore(afterPtr, 0x00)
|
|
96
|
+
|
|
97
|
+
// Run over the input, 3 bytes at a time
|
|
98
|
+
for {} lt(dataPtr, endPtr) {} {
|
|
99
|
+
// Advance 3 bytes
|
|
100
|
+
dataPtr := add(dataPtr, 3)
|
|
101
|
+
let input := mload(dataPtr)
|
|
102
|
+
|
|
103
|
+
// To write each character, shift the 3 byte (24 bits) chunk
|
|
104
|
+
// 4 times in blocks of 6 bits for each character (18, 12, 6, 0)
|
|
105
|
+
// and apply logical AND with 0x3F to bitmask the least significant 6 bits.
|
|
106
|
+
// Use this as an index into the lookup table, mload an entire word
|
|
107
|
+
// so the desired character is in the least significant byte, and
|
|
108
|
+
// mstore8 this least significant byte into the result and continue.
|
|
109
|
+
mstore8(resultPtr, mload(and(shr(18, input), 0x3F)))
|
|
110
|
+
resultPtr := add(resultPtr, 1) // Advance
|
|
111
|
+
mstore8(resultPtr, mload(and(shr(12, input), 0x3F)))
|
|
112
|
+
resultPtr := add(resultPtr, 1) // Advance
|
|
113
|
+
mstore8(resultPtr, mload(and(shr(6, input), 0x3F)))
|
|
114
|
+
resultPtr := add(resultPtr, 1) // Advance
|
|
115
|
+
mstore8(resultPtr, mload(and(input, 0x3F)))
|
|
116
|
+
resultPtr := add(resultPtr, 1) // Advance
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Reset the value that was cached
|
|
120
|
+
mstore(afterPtr, afterCache)
|
|
121
|
+
|
|
122
|
+
if iszero(urlAndFilenameSafe) {
|
|
123
|
+
// When data `bytes` is not exactly 3 bytes long
|
|
124
|
+
// it is padded with `=` characters at the end
|
|
125
|
+
switch mod(mload(data), 3)
|
|
126
|
+
case 1 {
|
|
127
|
+
mstore8(sub(resultPtr, 1), 0x3d)
|
|
128
|
+
mstore8(sub(resultPtr, 2), 0x3d)
|
|
129
|
+
}
|
|
130
|
+
case 2 {
|
|
131
|
+
mstore8(sub(resultPtr, 1), 0x3d)
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Store result length and update FMP to reserve allocated space
|
|
136
|
+
mstore(result, resultLength)
|
|
137
|
+
mstore(0x40, resultEnd)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @dev Internal decoding
|
|
143
|
+
*/
|
|
144
|
+
function _decode(bytes memory data) private pure returns (bytes memory result) {
|
|
145
|
+
bytes4 errorSelector = InvalidBase64Char.selector;
|
|
146
|
+
|
|
147
|
+
uint256 dataLength = data.length;
|
|
148
|
+
if (dataLength == 0) return "";
|
|
149
|
+
|
|
150
|
+
uint256 resultLength = (dataLength / 4) * 3;
|
|
151
|
+
if (dataLength % 4 == 0) {
|
|
152
|
+
resultLength -= (data[dataLength - 1] == "=").toUint() + (data[dataLength - 2] == "=").toUint();
|
|
153
|
+
} else {
|
|
154
|
+
resultLength += (dataLength % 4) - 1;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
assembly ("memory-safe") {
|
|
158
|
+
result := mload(0x40)
|
|
159
|
+
|
|
160
|
+
// Temporarily store the reverse lookup table between in memory. This spans from 0x00 to 0x50, Using:
|
|
161
|
+
// - all 64bytes of scratch space
|
|
162
|
+
// - part of the FMP (at location 0x40)
|
|
163
|
+
mstore(0x30, 0x2425262728292a2b2c2d2e2f30313233)
|
|
164
|
+
mstore(0x20, 0x0a0b0c0d0e0f10111213141516171819ffffffff3fff1a1b1c1d1e1f20212223)
|
|
165
|
+
mstore(0x00, 0x3eff3eff3f3435363738393a3b3c3dffffff00ffffff00010203040506070809)
|
|
166
|
+
|
|
167
|
+
// Prepare result pointer, jump over length
|
|
168
|
+
let dataPtr := data
|
|
169
|
+
let resultPtr := add(result, 0x20)
|
|
170
|
+
let endPtr := add(resultPtr, resultLength)
|
|
171
|
+
|
|
172
|
+
// In some cases, the last iteration will read bytes after the end of the data. We cache the value, and
|
|
173
|
+
// set it to "==" (fake padding) to make sure no dirty bytes are read in that section.
|
|
174
|
+
let afterPtr := add(add(data, 0x20), dataLength)
|
|
175
|
+
let afterCache := mload(afterPtr)
|
|
176
|
+
mstore(afterPtr, shl(240, 0x3d3d))
|
|
177
|
+
|
|
178
|
+
// loop while not everything is decoded
|
|
179
|
+
for {} lt(resultPtr, endPtr) {} {
|
|
180
|
+
dataPtr := add(dataPtr, 4)
|
|
181
|
+
|
|
182
|
+
// Read a 4 bytes chunk of data
|
|
183
|
+
let input := mload(dataPtr)
|
|
184
|
+
|
|
185
|
+
// Decode each byte in the chunk as a 6 bit block, and align them to form a block of 3 bytes
|
|
186
|
+
let a := sub(byte(28, input), 43)
|
|
187
|
+
// slither-disable-next-line incorrect-shift
|
|
188
|
+
if iszero(and(shl(a, 1), 0xffffffd0ffffffc47ff5)) {
|
|
189
|
+
mstore(0, errorSelector)
|
|
190
|
+
mstore(4, shl(248, add(a, 43)))
|
|
191
|
+
revert(0, 0x24)
|
|
192
|
+
}
|
|
193
|
+
let b := sub(byte(29, input), 43)
|
|
194
|
+
// slither-disable-next-line incorrect-shift
|
|
195
|
+
if iszero(and(shl(b, 1), 0xffffffd0ffffffc47ff5)) {
|
|
196
|
+
mstore(0, errorSelector)
|
|
197
|
+
mstore(4, shl(248, add(b, 43)))
|
|
198
|
+
revert(0, 0x24)
|
|
199
|
+
}
|
|
200
|
+
let c := sub(byte(30, input), 43)
|
|
201
|
+
// slither-disable-next-line incorrect-shift
|
|
202
|
+
if iszero(and(shl(c, 1), 0xffffffd0ffffffc47ff5)) {
|
|
203
|
+
mstore(0, errorSelector)
|
|
204
|
+
mstore(4, shl(248, add(c, 43)))
|
|
205
|
+
revert(0, 0x24)
|
|
206
|
+
}
|
|
207
|
+
let d := sub(byte(31, input), 43)
|
|
208
|
+
// slither-disable-next-line incorrect-shift
|
|
209
|
+
if iszero(and(shl(d, 1), 0xffffffd0ffffffc47ff5)) {
|
|
210
|
+
mstore(0, errorSelector)
|
|
211
|
+
mstore(4, shl(248, add(d, 43)))
|
|
212
|
+
revert(0, 0x24)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
mstore(
|
|
216
|
+
resultPtr,
|
|
217
|
+
or(
|
|
218
|
+
or(shl(250, byte(0, mload(a))), shl(244, byte(0, mload(b)))),
|
|
219
|
+
or(shl(238, byte(0, mload(c))), shl(232, byte(0, mload(d))))
|
|
220
|
+
)
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
resultPtr := add(resultPtr, 3)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Reset the value that was cached
|
|
227
|
+
mstore(afterPtr, afterCache)
|
|
228
|
+
|
|
229
|
+
// Store result length and update FMP to reserve allocated space
|
|
230
|
+
mstore(result, resultLength)
|
|
231
|
+
mstore(0x40, endPtr)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|