Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/interfaces/IPackageManifest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title IPackageManifest
/// @notice Interface for EthPM v3 Package Manifest structure based on EIP-2678
interface IPackageManifest {
/// @notice Package Meta Object from EIP-2678
struct PackageMeta {
string[] authors; // Human readable names
string license; // SPDX format
string description; // Additional detail
string[] keywords; // Relevant keywords
mapping(string => string) links; // URIs (website, docs, repo)
}

/// @notice Compiler Information Object from EIP-2678
struct CompilerInfo {
string name; // Compiler name (e.g., "solc")
string version; // Semver or commit hash format
}

/// @notice Contract Instance Object from EIP-2678
struct ContractInstance {
string contractType; // Reference to Contract Type
address instanceAddress; // Deployed address
}

/// @notice Link Reference Object from EIP-2678
struct LinkReference {
uint256[] offsets; // Start positions in bytecode (0-indexed)
uint256 length; // Length in bytes
string name; // Identifier for linking
}

/// @notice Link Value Object from EIP-2678
struct LinkValue {
uint256[] offsets; // Locations where value was written
string valueType; // "literal" or "reference"
string value; // Value to write when linking
}
}
26 changes: 26 additions & 0 deletions src/interfaces/IPackageRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title IPackageRegistry
/// @notice Interface for EthPM v3 Package Registry based on EIP-2678
/// @dev Defines functions for publishing and retrieving packages
interface IPackageRegistry {
/// @notice Publish a package to the registry
/// @param name Package name (lowercase, numbers, hyphens only)
/// @param version Package version
/// @param manifestURI Content-addressable URI (e.g., ipfs://)
function publish(string calldata name, string calldata version, string calldata manifestURI) external;

/// @notice Get package manifest URI
/// @param name Package name
/// @param version Package version
/// @return manifestURI The content-addressable URI of the package manifest
function getPackageURI(string calldata name, string calldata version) external view returns (string memory);

/// @notice Check if package version exists
/// @param name Package name
/// @param version Package version
/// @return exists True if package exists
function packageExists(string calldata name, string calldata version) external view returns (bool);
}

48 changes: 48 additions & 0 deletions test/interfaces/IPackageRegistry.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "forge-std/Test.sol";
import "../../src/interfaces/IPackageRegistry.sol";

contract MockPackageRegistry is IPackageRegistry {
mapping(bytes32 => string) private packages;

function publish(string calldata name, string calldata version, string calldata manifestURI) external {
bytes32 key = keccak256(abi.encodePacked(name, version));
packages[key] = manifestURI;
}

function getPackageURI(string calldata name, string calldata version) external view returns (string memory) {
bytes32 key = keccak256(abi.encodePacked(name, version));
return packages[key];
}

function packageExists(string calldata name, string calldata version) external view returns (bool) {
bytes32 key = keccak256(abi.encodePacked(name, version));
return bytes(packages[key]).length > 0;
}
}

contract IPackageRegistryTest is Test {
MockPackageRegistry registry;

function setUp() public {
registry = new MockPackageRegistry();
}

function testPublishPackage() public {
registry.publish("safe-math-lib", "1.0.0", "ipfs://QmTest123");
assertTrue(registry.packageExists("safe-math-lib", "1.0.0"));
}

function testGetPackageURI() public {
string memory manifestURI = "ipfs://QmTest123";
registry.publish("wallet", "2.1.0", manifestURI);

assertEq(registry.getPackageURI("wallet", "2.1.0"), manifestURI);
}

function testPackageNotExists() public {
assertFalse(registry.packageExists("nonexistent", "1.0.0"));
}
}
Loading