@coti-io/coti-contracts 0.1.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/.github/workflows/npm-publish.yml +52 -0
- package/CODE_OF_CONDUCT.md +44 -0
- package/CONTRIBUTING.md +101 -0
- package/LICENSE +201 -0
- package/README.md +48 -0
- package/contracts/access/DataPrivacyFramework/DataPrivacyFramework.sol +480 -0
- package/contracts/access/DataPrivacyFramework/README.md +68 -0
- package/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.sol +1139 -0
- package/contracts/mocks/README.md +5 -0
- package/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock.sol +9 -0
- package/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.sol +17 -0
- package/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock.sol +34 -0
- package/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol +431 -0
- package/contracts/mocks/utils/mpc/BitwiseTestsContract.sol +361 -0
- package/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol +307 -0
- package/contracts/mocks/utils/mpc/Comparison2TestsContract.sol +307 -0
- package/contracts/mocks/utils/mpc/MinMaxTestsContract.sol +297 -0
- package/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.sol +185 -0
- package/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.sol +448 -0
- package/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol +81 -0
- package/contracts/mocks/utils/mpc/README.md +486 -0
- package/contracts/mocks/utils/mpc/ShiftTestsContract.sol +311 -0
- package/contracts/mocks/utils/mpc/StringTestsContract.sol +59 -0
- package/contracts/mocks/utils/mpc/TransferScalarTestsContract.sol +271 -0
- package/contracts/mocks/utils/mpc/TransferTestsContract.sol +715 -0
- package/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.sol +25 -0
- package/contracts/onboard/AccountOnboard.sol +21 -0
- package/contracts/onboard/README.md +65 -0
- package/contracts/package.json +11 -0
- package/contracts/token/PrivateERC20/IPrivateERC20.sol +142 -0
- package/contracts/token/PrivateERC20/PrivateERC20.sol +478 -0
- package/contracts/token/PrivateERC20/README.md +104 -0
- package/contracts/token/PrivateERC721/PrivateERC721.sol +458 -0
- package/contracts/token/PrivateERC721/README.md +282 -0
- package/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage.sol +87 -0
- package/contracts/utils/mpc/MpcCore.sol +3215 -0
- package/contracts/utils/mpc/MpcInterface.sol +41 -0
- package/contracts/utils/mpc/README.md +82 -0
- package/hardhat.config.ts +18 -0
- package/package.json +14 -0
- package/test/access/DataPrivacyFramework/DataPrivacyFramework.test.ts +780 -0
- package/test/onboard/AccountOnboard.test.ts +45 -0
- package/test/token/PrivateERC20/PrivateERC20.test.ts +546 -0
- package/test/token/PrivateERC721/PrivateERC721.test.ts +223 -0
- package/test/utils/accounts.ts +55 -0
- package/test/utils/mpc/Precompile.test.ts +113 -0
- package/test/utils/mpc/String.test.ts +227 -0
- package/tsconfig.json +11 -0
- package/typechain-types/@openzeppelin/contracts/index.ts +9 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/IERC4906.ts +462 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +6 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/index.ts +6 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721.ts +393 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721Receiver.ts +110 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/token/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/utils/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/ERC165.ts +94 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/IERC165.ts +94 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/index.ts +5 -0
- package/typechain-types/@openzeppelin/index.ts +5 -0
- package/typechain-types/common.ts +131 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/DataPrivacyFramework.ts +598 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.ts +598 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/extensions/index.ts +4 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/index.ts +6 -0
- package/typechain-types/contracts/access/index.ts +5 -0
- package/typechain-types/contracts/index.ts +13 -0
- package/typechain-types/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock.ts +598 -0
- package/typechain-types/contracts/mocks/access/DataPrivacyFramework/index.ts +4 -0
- package/typechain-types/contracts/mocks/access/index.ts +5 -0
- package/typechain-types/contracts/mocks/index.ts +11 -0
- package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.ts +543 -0
- package/typechain-types/contracts/mocks/token/PrivateERC20/index.ts +4 -0
- package/typechain-types/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock.ts +576 -0
- package/typechain-types/contracts/mocks/token/PrivateERC721/index.ts +4 -0
- package/typechain-types/contracts/mocks/token/index.ts +7 -0
- package/typechain-types/contracts/mocks/utils/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.ts +354 -0
- package/typechain-types/contracts/mocks/utils/mpc/BitwiseTestsContract.ts +340 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract.ts +340 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/index.ts +4 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison2TestsContract.ts +340 -0
- package/typechain-types/contracts/mocks/utils/mpc/MinMaxTestsContract.ts +321 -0
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.ts +199 -0
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.ts +384 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract.ts +218 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/index.ts +4 -0
- package/typechain-types/contracts/mocks/utils/mpc/ShiftTestsContract.ts +339 -0
- package/typechain-types/contracts/mocks/utils/mpc/StringTestsContract.ts +211 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferScalarTestsContract.ts +266 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferTestsContract.ts +288 -0
- package/typechain-types/contracts/mocks/utils/mpc/index.ts +17 -0
- package/typechain-types/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.ts +173 -0
- package/typechain-types/contracts/mocks/wallet/PrivateERC20Wallet/index.ts +4 -0
- package/typechain-types/contracts/mocks/wallet/index.ts +5 -0
- package/typechain-types/contracts/onboard/AccountOnboard.ts +135 -0
- package/typechain-types/contracts/onboard/index.ts +4 -0
- package/typechain-types/contracts/token/PrivateERC20/IPrivateERC20.ts +437 -0
- package/typechain-types/contracts/token/PrivateERC20/PrivateERC20.ts +505 -0
- package/typechain-types/contracts/token/PrivateERC20/index.ts +5 -0
- package/typechain-types/contracts/token/PrivateERC721/PrivateERC721.ts +409 -0
- package/typechain-types/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage.ts +501 -0
- package/typechain-types/contracts/token/PrivateERC721/extensions/index.ts +4 -0
- package/typechain-types/contracts/token/PrivateERC721/index.ts +6 -0
- package/typechain-types/contracts/token/index.ts +7 -0
- package/typechain-types/contracts/utils/index.ts +5 -0
- package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +698 -0
- package/typechain-types/contracts/utils/mpc/MpcInterface.sol/index.ts +4 -0
- package/typechain-types/contracts/utils/mpc/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/index.ts +6 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC4906__factory.ts +339 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors__factory.ts +127 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors__factory.ts +111 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors__factory.ts +128 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +6 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721Receiver__factory.ts +59 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721__factory.ts +307 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/ERC165__factory.ts +41 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.ts +41 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/index.ts +4 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/DataPrivacyFramework__factory.ts +621 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc__factory.ts +621 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/extensions/index.ts +4 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/index.ts +5 -0
- package/typechain-types/factories/contracts/access/index.ts +4 -0
- package/typechain-types/factories/contracts/index.ts +8 -0
- package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +670 -0
- package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/access/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/index.ts +7 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +615 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC20/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +630 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC721/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/token/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +374 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +361 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract__factory.ts +361 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +361 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +337 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +236 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous2TestsContract__factory.ts +432 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract__factory.ts +245 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +374 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +264 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +360 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +441 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +15 -0
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +194 -0
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/wallet/index.ts +4 -0
- package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +104 -0
- package/typechain-types/factories/contracts/onboard/index.ts +4 -0
- package/typechain-types/factories/contracts/token/PrivateERC20/IPrivateERC20__factory.ts +406 -0
- package/typechain-types/factories/contracts/token/PrivateERC20/PrivateERC20__factory.ts +532 -0
- package/typechain-types/factories/contracts/token/PrivateERC20/index.ts +5 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/PrivateERC721__factory.ts +439 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage__factory.ts +512 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/extensions/index.ts +4 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/index.ts +5 -0
- package/typechain-types/factories/contracts/token/index.ts +5 -0
- package/typechain-types/factories/contracts/utils/index.ts +4 -0
- package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +919 -0
- package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/index.ts +4 -0
- package/typechain-types/factories/contracts/utils/mpc/index.ts +4 -0
- package/typechain-types/factories/index.ts +5 -0
- package/typechain-types/hardhat.d.ts +621 -0
- package/typechain-types/index.ts +72 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# PrivateERC721
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`PrivateERC721` is an abstract implementation of the [ERC721 Non-Fungible Token (NFT) Standard](https://eips.ethereum.org/EIPS/eip-721). It includes essential features of the standard, such as token ownership, approval, transfers, and safe transfers. This contract implements key components of the ERC721 standard while maintaining support for token metadata, but without fully implementing the metadata extension.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
- **Solidity Version**: `^0.8.19`
|
|
10
|
+
- **License**: MIT
|
|
11
|
+
- **Dependencies**:
|
|
12
|
+
- OpenZeppelin’s `Context`, `ERC165`, and `IERC721` contracts.
|
|
13
|
+
- `IERC721Receiver` for safe transfer checks.
|
|
14
|
+
- `IERC721Errors` interface for custom errors (related to the draft standard [IERC6093](https://eips.ethereum.org/EIPS/eip-6093)).
|
|
15
|
+
|
|
16
|
+
## Table of Contents
|
|
17
|
+
- [Events](#events)
|
|
18
|
+
- [State Variables](#state-variables)
|
|
19
|
+
- [Constructor](#constructor)
|
|
20
|
+
- [Functions](#functions)
|
|
21
|
+
- [Supports Interface](#supports-interface)
|
|
22
|
+
- [Balance Of](#balance-of)
|
|
23
|
+
- [Owner Of](#owner-of)
|
|
24
|
+
- [Name](#name)
|
|
25
|
+
- [Symbol](#symbol)
|
|
26
|
+
- [Approve](#approve)
|
|
27
|
+
- [Get Approved](#get-approved)
|
|
28
|
+
- [Set Approval For All](#set-approval-for-all)
|
|
29
|
+
- [Is Approved For All](#is-approved-for-all)
|
|
30
|
+
- [Transfer From](#transfer-from)
|
|
31
|
+
- [Safe Transfer From](#safe-transfer-from)
|
|
32
|
+
- [Private/Internal Functions](#privateinternal-functions)
|
|
33
|
+
|
|
34
|
+
## Events
|
|
35
|
+
|
|
36
|
+
## Event: `Transfer`
|
|
37
|
+
|
|
38
|
+
```solidity
|
|
39
|
+
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Description:
|
|
43
|
+
This event is emitted whenever an ERC-721 token is transferred from one address to another. It occurs during both direct token transfers (`transferFrom`) and safe token transfers (`safeTransferFrom`). This event helps external observers, such as dApps and explorers, to track the movement of tokens.
|
|
44
|
+
|
|
45
|
+
### Parameters:
|
|
46
|
+
- **`from`** (`address`): The address of the current owner of the token.
|
|
47
|
+
- **`to`** (`address`): The address that is receiving ownership of the token.
|
|
48
|
+
- **`tokenId`** (`uint256`): The unique identifier (ID) of the token being transferred.
|
|
49
|
+
|
|
50
|
+
### Important Notes:
|
|
51
|
+
- This event is emitted for both `transferFrom` and `safeTransferFrom` operations.
|
|
52
|
+
- If a token is minted, `from` will be the zero address (`address(0)`).
|
|
53
|
+
- If a token is burned, `to` will be the zero address (`address(0)`).
|
|
54
|
+
|
|
55
|
+
## Event: `Approval`
|
|
56
|
+
|
|
57
|
+
```solidity
|
|
58
|
+
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Description:
|
|
62
|
+
The `Approval` event is emitted when an owner grants or revokes permission to another account (the `approved` address) to transfer a specific token. Each ERC-721 token can only have one approved address at a time. The approval is reset when the token is transferred to a new owner.
|
|
63
|
+
|
|
64
|
+
### Parameters:
|
|
65
|
+
- **`owner`** (`address`): The current owner of the token.
|
|
66
|
+
- **`approved`** (`address`): The address that is approved to transfer the token. This can be the zero address (`address(0)`) if no account is approved.
|
|
67
|
+
- **`tokenId`** (`uint256`): The unique identifier (ID) of the token being approved for transfer.
|
|
68
|
+
|
|
69
|
+
### Important Notes:
|
|
70
|
+
- This event is specific to individual tokens, meaning approvals apply to a single `tokenId`.
|
|
71
|
+
- Approving the zero address (`address(0)`) clears the previous approval, effectively revoking approval for that token.
|
|
72
|
+
|
|
73
|
+
## Event: `ApprovalForAll`
|
|
74
|
+
|
|
75
|
+
```solidity
|
|
76
|
+
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Description:
|
|
80
|
+
This event is emitted when an owner enables or disables an operator to manage all of their assets. Operators can transfer or manage any token owned by the `owner`. The event allows for bulk approval of all tokens owned by a single account.
|
|
81
|
+
|
|
82
|
+
### Parameters:
|
|
83
|
+
- **`owner`** (`address`): The address of the token owner.
|
|
84
|
+
- **`operator`** (`address`): The address that is granted or revoked permission to manage all of the owner's tokens.
|
|
85
|
+
- **`approved`** (`bool`): A boolean value indicating whether the operator is approved (`true`) or approval is revoked (`false`).
|
|
86
|
+
|
|
87
|
+
### Important Notes:
|
|
88
|
+
- This event differs from the `Approval` event because it applies to all tokens owned by the `owner`, not a single token.
|
|
89
|
+
- This event is emitted when the `setApprovalForAll` function is called, allowing or revoking an operator’s access to all of the owner's tokens.
|
|
90
|
+
|
|
91
|
+
## State Variables
|
|
92
|
+
|
|
93
|
+
- **_name** (`string`): The name of the token collection.
|
|
94
|
+
- **_symbol** (`string`): The symbol for the token collection.
|
|
95
|
+
- **_owners** (`mapping(uint256 => address)`): Maps a token ID to its owner address.
|
|
96
|
+
- **_balances** (`mapping(address => uint256)`): Maps owner addresses to the number of tokens they own.
|
|
97
|
+
- **_tokenApprovals** (`mapping(uint256 => address)`): Maps a token ID to the approved address for that token.
|
|
98
|
+
- **_operatorApprovals** (`mapping(address => mapping(address => bool))`): Maps an owner to an operator, allowing the operator to manage all tokens owned by that owner.
|
|
99
|
+
|
|
100
|
+
## Constructor
|
|
101
|
+
|
|
102
|
+
```solidity
|
|
103
|
+
constructor(string memory name_, string memory symbol_)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The constructor initializes the contract by setting the name and symbol of the token collection. It accepts the following parameters:
|
|
107
|
+
|
|
108
|
+
- **`name_`**: The name of the token collection.
|
|
109
|
+
- **`symbol_`**: The symbol for the token collection.
|
|
110
|
+
|
|
111
|
+
## Functions
|
|
112
|
+
|
|
113
|
+
### Supports Interface
|
|
114
|
+
|
|
115
|
+
```solidity
|
|
116
|
+
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Implements the `supportsInterface` function to check if the contract implements a specific interface (e.g., `IERC721`).
|
|
120
|
+
|
|
121
|
+
- **`interfaceId`**: The interface identifier to check.
|
|
122
|
+
- **Returns**: `true` if the contract supports the interface, otherwise `false`.
|
|
123
|
+
|
|
124
|
+
### Balance Of
|
|
125
|
+
|
|
126
|
+
```solidity
|
|
127
|
+
function balanceOf(address owner) public view virtual returns (uint256)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Returns the number of tokens owned by the given address.
|
|
131
|
+
|
|
132
|
+
- **`owner`**: The address to query.
|
|
133
|
+
- **Returns**: The number of tokens owned by the address.
|
|
134
|
+
- **Reverts**: `ERC721InvalidOwner` if `owner` is the zero address.
|
|
135
|
+
|
|
136
|
+
### Owner Of
|
|
137
|
+
|
|
138
|
+
```solidity
|
|
139
|
+
function ownerOf(uint256 tokenId) public view virtual returns (address)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Returns the owner of the given `tokenId`.
|
|
143
|
+
|
|
144
|
+
- **`tokenId`**: The ID of the token.
|
|
145
|
+
- **Returns**: The owner address of the `tokenId`.
|
|
146
|
+
- **Reverts**: If the token does not exist.
|
|
147
|
+
|
|
148
|
+
### Name
|
|
149
|
+
|
|
150
|
+
```solidity
|
|
151
|
+
function name() public view virtual returns (string memory)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Returns the name of the token collection.
|
|
155
|
+
|
|
156
|
+
### Symbol
|
|
157
|
+
|
|
158
|
+
```solidity
|
|
159
|
+
function symbol() public view virtual returns (string memory)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Returns the symbol of the token collection.
|
|
163
|
+
|
|
164
|
+
### Approve
|
|
165
|
+
|
|
166
|
+
```solidity
|
|
167
|
+
function approve(address to, uint256 tokenId) public virtual
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Approves the given address (`to`) to transfer the specified token on behalf of the owner.
|
|
171
|
+
|
|
172
|
+
- **`to`**: The address to be approved.
|
|
173
|
+
- **`tokenId`**: The ID of the token to approve.
|
|
174
|
+
|
|
175
|
+
### Get Approved
|
|
176
|
+
|
|
177
|
+
```solidity
|
|
178
|
+
function getApproved(uint256 tokenId) public view virtual returns (address)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Returns the approved address for the given `tokenId`.
|
|
182
|
+
|
|
183
|
+
- **`tokenId`**: The ID of the token to check.
|
|
184
|
+
- **Returns**: The address approved to transfer the `tokenId`.
|
|
185
|
+
|
|
186
|
+
### Set Approval For All
|
|
187
|
+
|
|
188
|
+
```solidity
|
|
189
|
+
function setApprovalForAll(address operator, bool approved) public virtual
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Enables or disables approval for a third-party `operator` to manage all tokens owned by the sender.
|
|
193
|
+
|
|
194
|
+
- **`operator`**: The address of the operator.
|
|
195
|
+
- **`approved`**: `true` to approve, `false` to revoke approval.
|
|
196
|
+
|
|
197
|
+
### Is Approved For All
|
|
198
|
+
|
|
199
|
+
```solidity
|
|
200
|
+
function isApprovedForAll(address owner, address operator) public view virtual returns (bool)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Checks if the `operator` is approved to manage all tokens owned by `owner`.
|
|
204
|
+
|
|
205
|
+
- **`owner`**: The address of the token owner.
|
|
206
|
+
- **`operator`**: The address of the operator.
|
|
207
|
+
- **Returns**: `true` if the operator is approved, otherwise `false`.
|
|
208
|
+
|
|
209
|
+
### Transfer From
|
|
210
|
+
|
|
211
|
+
```solidity
|
|
212
|
+
function transferFrom(address from, address to, uint256 tokenId) public virtual
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Transfers ownership of the `tokenId` from one address to another.
|
|
216
|
+
|
|
217
|
+
- **`from`**: The current owner of the token.
|
|
218
|
+
- **`to`**: The address receiving the token.
|
|
219
|
+
- **`tokenId`**: The ID of the token.
|
|
220
|
+
- **Reverts**: `ERC721InvalidReceiver` if `to` is the zero address or if the sender is not authorized to transfer the token.
|
|
221
|
+
|
|
222
|
+
### Safe Transfer From
|
|
223
|
+
|
|
224
|
+
```solidity
|
|
225
|
+
function safeTransferFrom(address from, address to, uint256 tokenId) public
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Safely transfers a `tokenId` from one address to another, ensuring the receiver can handle ERC721 tokens.
|
|
229
|
+
|
|
230
|
+
- **`from`**: The current owner of the token.
|
|
231
|
+
- **`to`**: The address receiving the token.
|
|
232
|
+
- **`tokenId`**: The ID of the token.
|
|
233
|
+
|
|
234
|
+
### Private/Internal Functions
|
|
235
|
+
|
|
236
|
+
#### `_ownerOf`
|
|
237
|
+
|
|
238
|
+
```solidity
|
|
239
|
+
function _ownerOf(uint256 tokenId) internal view virtual returns (address)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Internal function that returns the owner of the `tokenId`.
|
|
243
|
+
|
|
244
|
+
#### `_isAuthorized`
|
|
245
|
+
|
|
246
|
+
```solidity
|
|
247
|
+
function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool)
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Checks if `spender` is authorized to manage `owner`'s token or the specific `tokenId`.
|
|
251
|
+
|
|
252
|
+
#### `_approve`
|
|
253
|
+
|
|
254
|
+
```solidity
|
|
255
|
+
function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Approves the address `to` to manage the `tokenId`. Optionally emits the `Approval` event.
|
|
259
|
+
|
|
260
|
+
#### `_mint`
|
|
261
|
+
|
|
262
|
+
```solidity
|
|
263
|
+
function _mint(address to, uint256 tokenId) internal
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Mints a new token with the given `tokenId` and transfers it to the address `to`.
|
|
267
|
+
|
|
268
|
+
#### `_burn`
|
|
269
|
+
|
|
270
|
+
```solidity
|
|
271
|
+
function _burn(uint256 tokenId) internal
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Burns (destroys) the token with the given `tokenId`.
|
|
275
|
+
|
|
276
|
+
#### `_checkOnERC721Received`
|
|
277
|
+
|
|
278
|
+
```solidity
|
|
279
|
+
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Private function to invoke the `IERC721Receiver.onERC721Received` on the target address if it's a contract.
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import {PrivateERC721} from "../PrivateERC721.sol";
|
|
6
|
+
import {IERC4906} from "@openzeppelin/contracts/interfaces/IERC4906.sol";
|
|
7
|
+
import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol";
|
|
8
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @dev ERC721 token with storage-based encrypted token URI management.
|
|
12
|
+
*/
|
|
13
|
+
abstract contract PrivateERC721URIStorage is IERC4906, PrivateERC721 {
|
|
14
|
+
|
|
15
|
+
error ERC721URIStorageNonMintedToken(uint256 tokenId);
|
|
16
|
+
|
|
17
|
+
// Interface ID as defined in ERC-4906. This does not correspond to a traditional interface ID as ERC-4906 only
|
|
18
|
+
// defines events and does not include any external function.
|
|
19
|
+
bytes4 private constant ERC4906_INTERFACE_ID = bytes4(0x000000); // TODO: GET INTERFACE ID
|
|
20
|
+
|
|
21
|
+
mapping(uint256 tokenId => utString) private _tokenURIs;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @dev See {IERC165-supportsInterface}
|
|
25
|
+
*/
|
|
26
|
+
function supportsInterface(
|
|
27
|
+
bytes4 interfaceId
|
|
28
|
+
) public view virtual override(PrivateERC721, IERC165) returns (bool) {
|
|
29
|
+
return interfaceId == ERC4906_INTERFACE_ID || super.supportsInterface(interfaceId);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function tokenURI(uint256 tokenId) public view virtual returns (ctString memory) {
|
|
33
|
+
return _tokenURIs[tokenId].userCiphertext;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
function _setTokenURI(
|
|
41
|
+
address to,
|
|
42
|
+
uint256 tokenId,
|
|
43
|
+
itString calldata itTokenURI
|
|
44
|
+
) internal virtual {
|
|
45
|
+
gtString memory gtTokenURI = MpcCore.validateCiphertext(itTokenURI);
|
|
46
|
+
|
|
47
|
+
_setTokenURI(to, tokenId, gtTokenURI, true);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
function _setTokenURI(
|
|
55
|
+
address to,
|
|
56
|
+
uint256 tokenId,
|
|
57
|
+
gtString memory gtTokenURI,
|
|
58
|
+
bool updateCiphertext
|
|
59
|
+
) private {
|
|
60
|
+
if (ownerOf(tokenId) == address(0)) {
|
|
61
|
+
revert ERC721URIStorageNonMintedToken(tokenId);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
utString memory utTokenURI = MpcCore.offBoardCombined(gtTokenURI, to);
|
|
65
|
+
|
|
66
|
+
if (updateCiphertext) {
|
|
67
|
+
_tokenURIs[tokenId] = utTokenURI;
|
|
68
|
+
} else {
|
|
69
|
+
_tokenURIs[tokenId].userCiphertext = utTokenURI.userCiphertext;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function _update(
|
|
74
|
+
address to,
|
|
75
|
+
uint256 tokenId,
|
|
76
|
+
address auth
|
|
77
|
+
) internal virtual override returns (address) {
|
|
78
|
+
gtString memory gtTokenURI = MpcCore.onBoard(_tokenURIs[tokenId].ciphertext);
|
|
79
|
+
|
|
80
|
+
address previousOwner = PrivateERC721._update(to, tokenId, auth);
|
|
81
|
+
|
|
82
|
+
// reencrypt with the new user key
|
|
83
|
+
_setTokenURI(to, tokenId, gtTokenURI, false);
|
|
84
|
+
|
|
85
|
+
return previousOwner;
|
|
86
|
+
}
|
|
87
|
+
}
|