ERC-1319 Smart contract package registry (Smart Contract Package Registry Interface)
Stagnant · Other · created 2018-08-13
Defines a common interface for registering and querying smart contract packages in a registry, allowing code manifests to be looked up by package name and version, similar to npm.
Why it is needed
To reuse smart contract code, a package must be registered somewhere and be discoverable by name and version. Without a common registry interface, the shape of the release method or query methods would differ from registry to registry, locking installation tools like ethpm into a specific registry implementation. At the time, the EthPM package registry existed only as a single centralized project, and without a standard, even if multiple registries emerged they would be incompatible with each other, making it difficult to grow into a decentralized multi-registry ecosystem linked through the ENS namespace. Additionally, if the method of generating a releaseId from a package name and version string differs by registry, a tool would have to first fetch the registry's entire list of releases just to look up the manifest for a specific version, which is inefficient.
What to implement
function release(string packageName, string version, string manifestURI) public returns (bytes32 releaseId);: Takes a package name, version, and manifest URI, registers a new release, and returns the releaseId.event VersionRelease(string packageName, string version, string manifestURI): This is the event that must be emitted when release is called successfully.function getAllPackageIds(uint offset, uint limit) public view returns ( bytes32[] packageIds, uint pointer );: Queries the list of all package ids in the registry, divided by offset and limit.function getPackageName(bytes32 packageId) public view returns (string packageName);: Queries the unique package name corresponding to a package id.function getReleaseId(string packageName, string version) public view returns (bytes32 releaseId);: Queries the releaseId of a release already registered under a given package name and version.function getAllReleaseIds(string packageName, uint offset, uint limit) public view returns ( bytes32[] releaseIds, uint pointer );: Queries the list of all releaseIds for a given package, divided by offset and limit.function getReleaseData(bytes32 releaseId) public view returns ( string packageName, string version, string manifestURI );: Queries the package name, version, and manifest URI by releaseId.function generateReleaseId(string packageName, string version) public view returns (bytes32 releaseId);: Precomputes the releaseId the registry would generate for a release call, from a package name and version.function numPackageIds() public view returns (uint totalCount);: Returns the total number of unique packages in the registry.function numReleaseIds(string packageName) public view returns (uint totalCount);: Returns the total number of unique releases belonging to a given package name.
In depth
Structure of registries, packages, and releases
A registry is a contract that manages a collection of packages, and a package is a collection of releases. A package is identified within a registry by a unique string name and a unique bytes32 packageId. A release is identified by a unique bytes32 releaseId for a given pair of package name and version string, and the releaseId maps to a data set that includes a manifestURI string. The manifestURI points to the location of the EIP-1123 package manifest.
release write API
The write API consists of a single release method. Passing the package name, version, and manifestURI pointing to the manifest location to the registry returns a releaseId. When release is called successfully, the registry must emit a VersionRelease event, which carries packageName, version, and manifestURI.
Read API and pagination
The read API consists of getAllPackageIds, getPackageName, getReleaseId, getAllReleaseIds, getReleaseData, generateReleaseId, numPackageIds, and numReleaseIds, allowing tools to extract all data from the registry. Because getAllPackageIds and getAllReleaseIds can return large result sets, they support pagination via offset and limit, and return a pointer indicating where the next query should start.
How releaseId is generated
The concrete method for generating a releaseId is left to the implementation, but a common approach is to hash the package name and version string with keccak256. The registry must expose this id generation logic through the public read API generateReleaseId, so that tools can map string-based lookups directly to the registry's unique identifiers.
Conditions on manifestURI
manifestURI must be a URI conforming to RFC3986, and must additionally include the content hash specified in EIP-1123. IPFS and Swarm URIs satisfy this definition, and pointing to content hosted on GitHub via a SHA-1 hash is given as an example as well.
Relationship to EIP-1123 and extensibility
This proposal is a companion to EIP-1123, the package manifest standard, where the manifest holds information about the contents of a release and the location of its code assets. Registries may offer additional, more complex read APIs such as semver range or latest lookups, and in that case use of EIP-165 and EIP-926 is recommended. However, the registry EthPM actually operated at the time implemented only one of the method signatures described in the specification, and so did not comply with this standard.
Proposal status
This proposal is in Stagnant status, meaning it has stalled with no further discussion or revision.