Skip to content

Commit

Permalink
feat: remove libraries dependencies and use interfaces instead
Browse files Browse the repository at this point in the history
  • Loading branch information
yum0e committed Jul 27, 2023
1 parent aee373d commit 89edd94
Show file tree
Hide file tree
Showing 15 changed files with 449 additions and 1,606 deletions.
29 changes: 15 additions & 14 deletions src/SismoConnectLib.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {RequestBuilder, SismoConnectRequest, SismoConnectResponse, SismoConnectConfig} from "./utils/RequestBuilder.sol";
import {AuthRequestBuilder, AuthRequest, Auth, VerifiedAuth, AuthType} from "./utils/AuthRequestBuilder.sol";
import {ClaimRequestBuilder, ClaimRequest, Claim, VerifiedClaim, ClaimType} from "./utils/ClaimRequestBuilder.sol";
import {SignatureBuilder, SignatureRequest, Signature} from "./utils/SignatureBuilder.sol";
import {VaultConfig} from "./utils/Structs.sol";
import {ISismoConnectVerifier, SismoConnectVerifiedResult} from "./interfaces/ISismoConnectVerifier.sol";
import {IAddressesProvider} from "./interfaces/IAddressesProvider.sol";
import {ISismoConnectVerifier, SismoConnectVerifiedResult} from "./interfaces/ISismoConnectVerifier.sol";
import {IAuthRequestBuilder, AuthRequest, AuthType} from "./interfaces/IAuthRequestBuilder.sol";
import {IClaimRequestBuilder, ClaimRequest, ClaimType} from "./interfaces/IClaimRequestBuilder.sol";
import {ISignatureBuilder, SignatureRequest} from "./interfaces/ISignatureBuilder.sol";
import {IRequestBuilder, AuthRequest, ClaimRequest, SignatureRequest, SismoConnectRequest} from "./interfaces/IRequestBuilder.sol";

import {Auth, VerifiedAuth, Claim, VerifiedClaim, Signature, SismoConnectResponse, SismoConnectConfig, VaultConfig} from "./utils/Structs.sol";
import {SismoConnectHelper} from "./utils/SismoConnectHelper.sol";

contract SismoConnect {
Expand All @@ -19,10 +20,10 @@ contract SismoConnect {
ISismoConnectVerifier immutable _sismoConnectVerifier;

// external libraries
AuthRequestBuilder immutable _authRequestBuilder;
ClaimRequestBuilder immutable _claimRequestBuilder;
SignatureBuilder immutable _signatureBuilder;
RequestBuilder immutable _requestBuilder;
IAuthRequestBuilder immutable _authRequestBuilder;
IClaimRequestBuilder immutable _claimRequestBuilder;
ISignatureBuilder immutable _signatureBuilder;
IRequestBuilder immutable _requestBuilder;

// config
bytes16 public immutable APP_ID;
Expand All @@ -36,16 +37,16 @@ contract SismoConnect {
ADDRESSES_PROVIDER_V2.get(string("sismoConnectVerifier-v1.2"))
);
// external libraries
_authRequestBuilder = AuthRequestBuilder(
_authRequestBuilder = IAuthRequestBuilder(
ADDRESSES_PROVIDER_V2.get(string("authRequestBuilder-v1.1"))
);
_claimRequestBuilder = ClaimRequestBuilder(
_claimRequestBuilder = IClaimRequestBuilder(
ADDRESSES_PROVIDER_V2.get(string("claimRequestBuilder-v1.1"))
);
_signatureBuilder = SignatureBuilder(
_signatureBuilder = ISignatureBuilder(
ADDRESSES_PROVIDER_V2.get(string("signatureBuilder-v1.1"))
);
_requestBuilder = RequestBuilder(ADDRESSES_PROVIDER_V2.get(string("requestBuilder-v1.1")));
_requestBuilder = IRequestBuilder(ADDRESSES_PROVIDER_V2.get(string("requestBuilder-v1.1")));
}

// public function because it needs to be used by this contract and can be used by other contracts
Expand Down
94 changes: 94 additions & 0 deletions src/interfaces/IAuthRequestBuilder.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {AuthRequest, AuthType} from "../utils/Structs.sol";

interface IAuthRequestBuilder {
error InvalidUserIdAndIsSelectableByUserAuthType();
error InvalidUserIdAndAuthType();

function build(
AuthType authType,
bool isAnon,
uint256 userId,
bool isOptional,
bool isSelectableByUser,
bytes memory extraData
) external pure returns (AuthRequest memory);

function build(
AuthType authType,
bool isAnon,
uint256 userId,
bytes memory extraData
) external pure returns (AuthRequest memory);

function build(AuthType authType) external pure returns (AuthRequest memory);

function build(AuthType authType, bool isAnon) external pure returns (AuthRequest memory);

function build(AuthType authType, uint256 userId) external pure returns (AuthRequest memory);

function build(
AuthType authType,
bytes memory extraData
) external pure returns (AuthRequest memory);

function build(
AuthType authType,
bool isAnon,
uint256 userId
) external pure returns (AuthRequest memory);

function build(
AuthType authType,
bool isAnon,
bytes memory extraData
) external pure returns (AuthRequest memory);

function build(
AuthType authType,
uint256 userId,
bytes memory extraData
) external pure returns (AuthRequest memory);

// allow dev to choose for isOptional
// the user is ask to choose isSelectableByUser to avoid the function signature collision
// between build(AuthType authType, bool isOptional) and build(AuthType authType, bool isAnon)

function build(
AuthType authType,
bool isOptional,
bool isSelectableByUser
) external pure returns (AuthRequest memory);

function build(
AuthType authType,
bool isOptional,
bool isSelectableByUser,
uint256 userId
) external pure returns (AuthRequest memory);

// the user is ask to choose isSelectableByUser to avoid the function signature collision
// between build(AuthType authType, bool isAnon, bool isOptional) and build(AuthType authType, bool isOptional, bool isSelectableByUser)

function build(
AuthType authType,
bool isAnon,
bool isOptional,
bool isSelectableByUser
) external pure returns (AuthRequest memory);

function build(
AuthType authType,
uint256 userId,
bool isOptional
) external pure returns (AuthRequest memory);

function build(
AuthType authType,
bool isAnon,
uint256 userId,
bool isOptional
) external pure returns (AuthRequest memory);
}
14 changes: 7 additions & 7 deletions src/interfaces/IBaseVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ pragma solidity ^0.8.17;
import {SismoConnectProof, VerifiedAuth, VerifiedClaim} from "../utils/Structs.sol";

interface IBaseVerifier {
function verify(
bytes16 appId,
bytes16 namespace,
bool isImpersonationMode,
bytes memory signedMessage,
SismoConnectProof memory sismoConnectProof
) external returns (VerifiedAuth memory, VerifiedClaim memory);
function verify(
bytes16 appId,
bytes16 namespace,
bool isImpersonationMode,
bytes memory signedMessage,
SismoConnectProof memory sismoConnectProof
) external view returns (VerifiedAuth memory, VerifiedClaim memory);
}
170 changes: 170 additions & 0 deletions src/interfaces/IClaimRequestBuilder.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import {ClaimRequest, ClaimType} from "../utils/Structs.sol";

interface IClaimRequestBuilder {
function build(
bytes16 groupId,
bytes16 groupTimestamp,
uint256 value,
ClaimType claimType,
bool isOptional,
bool isSelectableByUser,
bytes memory extraData
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp,
uint256 value,
ClaimType claimType,
bytes memory extraData
) external pure returns (ClaimRequest memory);

function build(bytes16 groupId) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp
) external pure returns (ClaimRequest memory);

function build(bytes16 groupId, uint256 value) external pure returns (ClaimRequest memory);

function build(bytes16 groupId, ClaimType claimType) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes memory extraData
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp,
uint256 value
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp,
ClaimType claimType
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp,
bytes memory extraData
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
uint256 value,
ClaimType claimType
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
uint256 value,
bytes memory extraData
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
ClaimType claimType,
bytes memory extraData
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp,
uint256 value,
ClaimType claimType
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp,
uint256 value,
bytes memory extraData
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp,
ClaimType claimType,
bytes memory extraData
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
uint256 value,
ClaimType claimType,
bytes memory extraData
) external pure returns (ClaimRequest memory);

// allow dev to choose for isOptional
// we force to also set isSelectableByUser
// otherwise function signatures would be colliding
// between build(bytes16 groupId, bool isOptional) and build(bytes16 groupId, bool isSelectableByUser)
// we keep this logic for all function signature combinations

function build(
bytes16 groupId,
bool isOptional,
bool isSelectableByUser
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp,
bool isOptional,
bool isSelectableByUser
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
uint256 value,
bool isOptional,
bool isSelectableByUser
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
ClaimType claimType,
bool isOptional,
bool isSelectableByUser
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp,
uint256 value,
bool isOptional,
bool isSelectableByUser
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp,
ClaimType claimType,
bool isOptional,
bool isSelectableByUser
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
uint256 value,
ClaimType claimType,
bool isOptional,
bool isSelectableByUser
) external pure returns (ClaimRequest memory);

function build(
bytes16 groupId,
bytes16 groupTimestamp,
uint256 value,
ClaimType claimType,
bool isOptional,
bool isSelectableByUser
) external pure returns (ClaimRequest memory);
}
Loading

0 comments on commit 89edd94

Please sign in to comment.