From b3f6e45696a261da379483ee38e39316b63e1e2b Mon Sep 17 00:00:00 2001 From: lash Date: Sun, 26 Mar 2023 12:04:31 +0100 Subject: [PATCH] Add Digest interface --- doc/texinfo/chrono.sol.texi | 15 +++++++++++++++ doc/texinfo/digest.sol.texi | 17 +++++++++++++++++ doc/texinfo/expire.sol.texi | 2 ++ doc/texinfo/locator.sol.texi | 2 ++ doc/texinfo/msg.sol.texi | 2 ++ doc/texinfo/multihash.sol.texi | 25 ------------------------- doc/texinfo/overview.texi | 4 ++-- doc/texinfo/seal.sol.texi | 31 +++++++++++++++++++++++++++++++ doc/texinfo/writer.sol.texi | 2 ++ solidity/AccountsIndexMutable.sol | 27 +++++++++++++++++++++++++++ solidity/Chrono.sol | 11 +++++++++++ solidity/Digest.sol | 23 +++++++++++++++++++++++ solidity/ERC5007.sol | 15 +++++++++++++++ solidity/ERC5192.sol | 17 +++++++++++++++++ solidity/Locator.sol | 2 +- solidity/MultiHash.sol | 6 ++++-- 16 files changed, 171 insertions(+), 30 deletions(-) create mode 100644 doc/texinfo/chrono.sol.texi create mode 100644 doc/texinfo/digest.sol.texi delete mode 100644 doc/texinfo/multihash.sol.texi create mode 100644 doc/texinfo/seal.sol.texi create mode 100644 solidity/AccountsIndexMutable.sol create mode 100644 solidity/Chrono.sol create mode 100644 solidity/Digest.sol create mode 100644 solidity/ERC5007.sol create mode 100644 solidity/ERC5192.sol diff --git a/doc/texinfo/chrono.sol.texi b/doc/texinfo/chrono.sol.texi new file mode 100644 index 0000000..6d47a49 --- /dev/null +++ b/doc/texinfo/chrono.sol.texi @@ -0,0 +1,15 @@ +@subsection Chrono + +Define a creation time for a resource. + +Complements @code{ERC5007}. + + +@table @dfn +@item ERC165 Interface identifier +@include ../../build/Chrono.interface +@item Solidity interface definition +@include ../../build/contract_Chrono.texi +@item Example implementation +@uref{https://git.defalsify.org/eth-erc721} (BadgeToken contract) +@end table diff --git a/doc/texinfo/digest.sol.texi b/doc/texinfo/digest.sol.texi new file mode 100644 index 0000000..9447986 --- /dev/null +++ b/doc/texinfo/digest.sol.texi @@ -0,0 +1,17 @@ +@subsection Digest + +Allows encoding of digests according to a specific encoding scheme. + +Primary use-case is the abstraction of self-describing @uref{https://multiformats.io/multihash/,Multhash} encoding. + +A default encoding @emph{must} always be defined, and the encoding of a valid digest @emph{must} succeed with the default encoding. + + +@table @dfn +@item ERC165 Interface identifier +@include ../../build/Digest.interface +@item Solidity interface definition +@include ../../build/contract_Digest.texi +@item Example implementation +@uref{git://holbrook.no/eth-event-msg.git} +@end table diff --git a/doc/texinfo/expire.sol.texi b/doc/texinfo/expire.sol.texi index d4a57f7..9ecacda 100644 --- a/doc/texinfo/expire.sol.texi +++ b/doc/texinfo/expire.sol.texi @@ -10,4 +10,6 @@ A contract defining an expiry @emph{must not} allow changing the expiration time @include ../../build/Expire.interface @item Solidity interface definition @include ../../build/contract_Expire.texi +@item Example implementation +@uref{https://git.grassecon.net/cicnet/erc20-demurrage-token.git} @end table diff --git a/doc/texinfo/locator.sol.texi b/doc/texinfo/locator.sol.texi index 0cdaa93..5e88a33 100644 --- a/doc/texinfo/locator.sol.texi +++ b/doc/texinfo/locator.sol.texi @@ -13,6 +13,8 @@ Furthermore, it @emph{should} be possible to refer to a resource by a fully-qua @include ../../build/Locator.interface @item Solidity interface definition @include ../../build/contract_Locator.texi +@item Example implementation +@uref{git://holbrook.no/eth-event-msg.git} @end table diff --git a/doc/texinfo/msg.sol.texi b/doc/texinfo/msg.sol.texi index 787b383..aaa7e33 100644 --- a/doc/texinfo/msg.sol.texi +++ b/doc/texinfo/msg.sol.texi @@ -12,4 +12,6 @@ The interface complements @code{Locator} and @code{MultiHash} to generate locat @include ../../build/Msg.interface @item Solidity interface definition @include ../../build/contract_Msg.texi +@item Example implementation +@uref{git://holbrook.no/eth-event-msg.git} @end table diff --git a/doc/texinfo/multihash.sol.texi b/doc/texinfo/multihash.sol.texi deleted file mode 100644 index f48643f..0000000 --- a/doc/texinfo/multihash.sol.texi +++ /dev/null @@ -1,25 +0,0 @@ -@subsection Multihash - -A complement to @code{Locator}, enabling validation and generation of multihashes for multicodecs that have been registered to the contract. - - -@table @dfn -@item ERC165 Interface identifier -@include ../../build/MultiHash.interface -@item Solidity interface definition -@include ../../build/contract_MultiHash.texi -@end table - - -@subsubsection Using @code{Multihash} with @code{Locator} - -Given the data @code{foo}, the digest algorithm @code{sha256} (multihash prefix @code{1220}) and a base url @code{https://contentgateway.grassecon.net}, the result of the methods may be as follows: - -@table @code -@item toURI(sha256(foo)) --> @code{"sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"} -@item toURL(sha256(foo)) --> @code{"https://contentgateway.grassecon.net/12202c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"} -@item tokenURI(toUint(sha256(foo))) --> @code{"https://contentgateway.grassecon.net/12202c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"} -@end table diff --git a/doc/texinfo/overview.texi b/doc/texinfo/overview.texi index fa91764..9833f65 100644 --- a/doc/texinfo/overview.texi +++ b/doc/texinfo/overview.texi @@ -50,6 +50,8 @@ The following well-known solidity interfaces are partially implemented in CIC na @include declarator.sol.texi +@include digest.sol.texi + @include expire.sol.texi @include faucet.sol.texi @@ -60,8 +62,6 @@ The following well-known solidity interfaces are partially implemented in CIC na @include msg.sol.texi -@include multihash.sol.texi - @include registry.sol.texi @include seal.sol.texi diff --git a/doc/texinfo/seal.sol.texi b/doc/texinfo/seal.sol.texi new file mode 100644 index 0000000..de03540 --- /dev/null +++ b/doc/texinfo/seal.sol.texi @@ -0,0 +1,31 @@ +@subsection Seal + +Some smart contract parameters may need to be mutable over part of a smart contract's lifetime. + +This interface provides a method to explicitly signal when certain parameters have been rendered immutable. + +The value of @code{sealState()} @emph{must not} decrease, and must not exceed @code{maxSealState}. + +@code{maxSealState} is used to define that @emph{all mutable parameters} have been rendered immutable. The practical implications of this will vary between contracts. + +The implementer is encouraged to use simple, descriptive names in the source code to describe the applicable seal states. + +Use cases of sealing include: + +@itemize +@item +Whether more tokens can be minted +@item +Allow ownership of a contract to be transferred +@item +The expiry time of a token (see @code{Expire}) +@end itemize + +@table @dfn +@item ERC165 Interface identifier +@include ../../build/Seal.interface +@item Solidity interface definition +@include ../../build/contract_Seal.texi +@item Example implementation +@uref{https://git.grassecon.net/cicnet/erc20-demurrage-token.git} +@end table diff --git a/doc/texinfo/writer.sol.texi b/doc/texinfo/writer.sol.texi index 25d0756..50eb3ab 100644 --- a/doc/texinfo/writer.sol.texi +++ b/doc/texinfo/writer.sol.texi @@ -24,4 +24,6 @@ Edit access control lists. @include ../../build/Writer.interface @item Solidity interface definition @include ../../build/contract_Writer.texi +@item Example implementation +@uref{https://git.grassecon.net/cicnet/erc20-demurrage-token.git} @end table diff --git a/solidity/AccountsIndexMutable.sol b/solidity/AccountsIndexMutable.sol new file mode 100644 index 0000000..fb4f9cb --- /dev/null +++ b/solidity/AccountsIndexMutable.sol @@ -0,0 +1,27 @@ +pragma solidity >=0.6.12; + +// Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 +// SPDX-License-Identifier: AGPL-3.0-or-later +// File-version: 1 + +// Extends the AccountsIndex contract to enable account removal and deactivation. + +interface IAccountsIndexMutable { + // Active status of address changed, and by whom changed. + event AddressActive(address indexed _account, bool _active); + + // Address removed from store, and by whom removed. + event AddressRemoved(address _account); + + // Remove an entry from the index. Reduces the entry count. + function remove(address) external returns (bool); + + // Deactivate account but keep in index. Does not affect entry count. + function deactivate(address) external returns (bool); + + // Activate previously deactivated account. Does not affect entry count. + function activate(address) external returns (bool); + + // Check if account exists and is active; + function isActive(address) external view returns (bool); +} diff --git a/solidity/Chrono.sol b/solidity/Chrono.sol new file mode 100644 index 0000000..b6a6351 --- /dev/null +++ b/solidity/Chrono.sol @@ -0,0 +1,11 @@ +pragma solidity >=0.6.12; + +// Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 +// SPDX-License-Identifier: AGPL-3.0-or-later +// File-version: 1 + +interface IChrono { + // Returns the timestamp of when a resource corresponding to _idx was first created. + // int64 chosen as return value for simpler interoperability with ERC5007. + function createTime(uint256 _idx) external returns(int64); +} diff --git a/solidity/Digest.sol b/solidity/Digest.sol new file mode 100644 index 0000000..6fcd8fe --- /dev/null +++ b/solidity/Digest.sol @@ -0,0 +1,23 @@ +pragma solidity >=0.6.12; + +// Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 +// SPDX-License-Identifier: AGPL-3.0-or-later +// File-version: 1 + +interface IDigest { + // Returns the default digest encoding used by the contract instance. + function defaultDigestEncoding() external view returns (uint256 _encoding); + + // Check if the given encoding has been implemented in the contract instance. + function haveDigestEncoding(uint256 _codec) external view returns(bool); + + // Verify and encode the given digest for a specific hashing algorithm. + // Returns a zero-length byte array if digest is invalid. + // Must succeed if called with the defaultDigestEncoding and a valid digest. + function encodeDigest(bytes memory _data, uint256 _encoding) external view returns (bytes memory); + + // Encodes the digest using the default digest encoding. + // Returns a zero-length byte array if digest is invalid. + // Must succeed with a valid digest. + function encodeDigest(bytes memory _data) external view returns (bytes memory); +} diff --git a/solidity/ERC5007.sol b/solidity/ERC5007.sol new file mode 100644 index 0000000..1faeef1 --- /dev/null +++ b/solidity/ERC5007.sol @@ -0,0 +1,15 @@ +pragma solidity >=0.6.12; + +// Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 +// SPDX-License-Identifier: AGPL-3.0-or-later +// File-version: 4 + +// This is a representation of an officially approved Ethereum Improvement Proposal, written by Anders (@0xanders), Lance (@LanceSnow), Shrug . +// It was released under the CC0 license. +// The proposal source used as reference was a Markdown file with the following digest: +// - sha256:ec5a3d25822e616e032ef27faeb9a7191147a7b18064d95807df20fbc6b69870 + +interface IERC5007 { + function startTime(uint256 tokenId) external view returns (int64); + function endTime(uint256 tokenId) external view returns (int64); +} diff --git a/solidity/ERC5192.sol b/solidity/ERC5192.sol new file mode 100644 index 0000000..166557f --- /dev/null +++ b/solidity/ERC5192.sol @@ -0,0 +1,17 @@ +pragma solidity >=0.6.12; + +// Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 +// SPDX-License-Identifier: AGPL-3.0-or-later +// File-version: 4 + +// This is a representation of an officially approved Ethereum Improvement Proposal, written by Tim Daubenschütz (@TimDaub), Anders (@0xanders). +// It was released under the CC0 license. +// The proposal source used as reference was a Markdown file with the following digest: +// - sha256:c746922587ede699bd1560be0c0db5599104a25c976077d20706ec05340b3b7a + +interface IERC5192 { + event Locked(uint256 tokenId); + event Unlocked(uint256 tokenId); + + function locked(uint256 tokenId) external view returns (bool); +} diff --git a/solidity/Locator.sol b/solidity/Locator.sol index a7bf079..544026c 100644 --- a/solidity/Locator.sol +++ b/solidity/Locator.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.12; // Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 // SPDX-License-Identifier: AGPL-3.0-or-later -// File-version: 3 +// File-version: 4 interface ILocator { // URI that may or may not point to a specific resource location. diff --git a/solidity/MultiHash.sol b/solidity/MultiHash.sol index 2b76211..09d1593 100644 --- a/solidity/MultiHash.sol +++ b/solidity/MultiHash.sol @@ -15,8 +15,10 @@ interface IMultiHash { } // All registered multicodecs - function multiCodec(uint256 _codec) external view returns(MultiHash memory); + function digestCodec(uint256 _codec) external view returns(MultiHash memory); + + function haveDigestEncoding(uint256 _codec) external view returns(bool); // Generate a multihash from the given digest and current selected multicodec - function toMultiHash(uint256 _codec, bytes memory _digest) external view returns(bytes memory); + function encodeDigest(uint256 _codec, bytes memory _digest) external view returns(bytes memory); }