-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feat/oauth-mvp' into feat/oauth-…
…mvp-test
- Loading branch information
Showing
47 changed files
with
5,273 additions
and
2,061 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,7 @@ book | |
|
||
# Vs code settings | ||
.vscode | ||
|
||
# Oauth-sdk | ||
packages/oauth-sdk/.env | ||
packages/oauth-sdk/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import "forge-std/Script.sol"; | ||
import "forge-std/console.sol"; | ||
import "../src/utils/OauthCore.sol"; | ||
|
||
contract Deploy is Script { | ||
function run() external { | ||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
if (deployerPrivateKey == 0) { | ||
console.log("PRIVATE_KEY env var not set"); | ||
return; | ||
} | ||
|
||
address oauthCore = vm.envAddress("OAUTH_CORE"); | ||
if (oauthCore == address(0)) { | ||
console.log("OAUTH_CORE env var not set. Deploy OAUTH_CORE and set env var"); | ||
return; | ||
} | ||
|
||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
OauthCore oauthCoreImpl = new OauthCore(); | ||
|
||
OauthCore oauthCoreProxy = OauthCore(payable(address(oauthCore))); | ||
oauthCoreProxy.upgradeTo(address(oauthCoreImpl)); | ||
|
||
// If you want to call some v2 function, refer to the following steps | ||
// | ||
// TokenRegistryV2 tokenRegistryV2 = TokenRegistryV2(address(tokenRegistry)); | ||
// address usdc = tokenRegistry.getTokenAddress(0, "USDC"); | ||
|
||
vm.stopBroadcast(); | ||
|
||
console.log("OauthCore implementation deployed at: %s", address(oauthCoreImpl)); | ||
console.log("---- DONE ----"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.9; | ||
|
||
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol"; | ||
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
import {Extension} from "../interfaces/Extension.sol"; | ||
import {EmailWalletCore} from "../EmailWalletCore.sol"; | ||
import {Wallet} from "../Wallet.sol"; | ||
import "../interfaces/Types.sol"; | ||
import {StringUtils} from "../libraries/StringUtils.sol"; | ||
import {IOauth} from "../interfaces/IOauth.sol"; | ||
import {TokenRegistry} from "../utils/TokenRegistry.sol"; | ||
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; | ||
|
||
abstract contract OauthExtensionBase is Extension, Initializable, UUPSUpgradeable, OwnableUpgradeable { | ||
using StringUtils for *; | ||
|
||
EmailWalletCore public core; | ||
|
||
modifier onlyCore() { | ||
require((msg.sender == address(core)) || (msg.sender == address(core.unclaimsHandler())), "invalid sender"); | ||
_; | ||
} | ||
|
||
constructor() { | ||
_disableInitializers(); | ||
} | ||
|
||
function initialize(address coreAddr) public virtual initializer { | ||
__Ownable_init(); | ||
core = EmailWalletCore(payable(coreAddr)); | ||
} | ||
|
||
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} | ||
|
||
function _decomposeTo3Bits(uint8 idx) internal pure returns (bool[3] memory) { | ||
bool[3] memory bits; | ||
bits[0] = (idx & 4) != 0; | ||
bits[1] = (idx & 2) != 0; | ||
bits[2] = (idx & 1) != 0; | ||
return bits; | ||
} | ||
|
||
function _parseSigninSubjectParams( | ||
uint8 templateIndex, | ||
bytes[] memory subjectParams | ||
) internal view returns (uint256 nonce, uint256 expiry, TokenAllowance[] memory tokenAllowances) { | ||
bool[3] memory bits = _decomposeTo3Bits(templateIndex); | ||
nonce = abi.decode(subjectParams[1], (uint256)); | ||
uint256 lastSubjectParamIdx = 2; | ||
uint8 numTokenAllowances = 2 * uint8(bits[1] ? 1 : 0) + uint8(bits[2] ? 1 : 0); | ||
tokenAllowances = new TokenAllowance[](numTokenAllowances); | ||
if (bits[0]) { | ||
expiry = abi.decode(subjectParams[lastSubjectParamIdx], (uint256)); | ||
lastSubjectParamIdx++; | ||
} else { | ||
expiry = type(uint256).max; | ||
} | ||
uint256 tokenAmount; | ||
string memory tokenName; | ||
TokenRegistry tokenRegistry = core.tokenRegistry(); | ||
for (uint8 i = 0; i < numTokenAllowances; i++) { | ||
(tokenAmount, tokenName) = abi.decode(subjectParams[lastSubjectParamIdx], (uint256, string)); | ||
require(tokenAmount > 0, "invalid tokenAmount"); | ||
tokenAllowances[i] = TokenAllowance({ | ||
tokenAddr: tokenRegistry.getTokenAddress(tokenName), | ||
amount: tokenAmount | ||
}); | ||
lastSubjectParamIdx++; | ||
} | ||
require(lastSubjectParamIdx == subjectParams.length, "invalid subjectParams length"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.