Changeset 2649870
- Timestamp:
- 12/28/2021 09:14:44 AM (4 years ago)
- Location:
- dao-login
- Files:
-
- 10 added
- 16 deleted
- 4 edited
- 1 copied
-
tags/0.2.1 (copied) (copied from dao-login/trunk)
-
tags/0.2.1/composer.json (added)
-
tags/0.2.1/composer.lock (added)
-
tags/0.2.1/dao-login.php (modified) (9 diffs)
-
tags/0.2.1/dao-permissions.php (added)
-
tags/0.2.1/members-only.php (added)
-
tags/0.2.1/readme.txt (modified) (3 diffs)
-
tags/0.2.1/vendor/kornrunner/keccak/.gitignore (deleted)
-
tags/0.2.1/vendor/kornrunner/keccak/README.md (deleted)
-
tags/0.2.1/vendor/simplito/bigint-wrapper-php/README.md (deleted)
-
tags/0.2.1/vendor/simplito/bn-php/.gitignore (deleted)
-
tags/0.2.1/vendor/simplito/bn-php/README.md (deleted)
-
tags/0.2.1/vendor/simplito/elliptic-php/.gitignore (deleted)
-
tags/0.2.1/vendor/simplito/elliptic-php/README.md (deleted)
-
tags/0.2.1/vendor/symfony/polyfill-mbstring/README.md (deleted)
-
tags/0.2.1/web3.php (added)
-
trunk/composer.json (added)
-
trunk/composer.lock (added)
-
trunk/dao-login.php (modified) (9 diffs)
-
trunk/dao-permissions.php (added)
-
trunk/members-only.php (added)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/vendor/kornrunner/keccak/.gitignore (deleted)
-
trunk/vendor/kornrunner/keccak/README.md (deleted)
-
trunk/vendor/simplito/bigint-wrapper-php/README.md (deleted)
-
trunk/vendor/simplito/bn-php/.gitignore (deleted)
-
trunk/vendor/simplito/bn-php/README.md (deleted)
-
trunk/vendor/simplito/elliptic-php/.gitignore (deleted)
-
trunk/vendor/simplito/elliptic-php/README.md (deleted)
-
trunk/vendor/symfony/polyfill-mbstring/README.md (deleted)
-
trunk/web3.php (added)
Legend:
- Unmodified
- Added
- Removed
-
dao-login/tags/0.2.1/dao-login.php
r2635441 r2649870 1 1 <?php 2 2 namespace Artpi\WPDAO; 3 4 use Elliptic\EC;5 use kornrunner\Keccak;6 use WP_Error;7 3 8 4 /** 9 5 * Plugin Name: DAO Login 10 6 * Description: Make your site web3-ready: Log in with Ethereum or create users based on governance tokens. 11 * Version: 0. 1.27 * Version: 0.2.1 12 8 * Author: Artur Piszek (artpi) 13 9 * Author URI: https://piszek.com … … 19 15 */ 20 16 17 require_once __DIR__ . '/dao-permissions.php'; 18 require_once __DIR__ . '/members-only.php'; 19 require_once __DIR__ . '/web3.php'; 20 21 register_activation_hook( __FILE__, __NAMESPACE__ . '\add_roles_on_plugin_activation' ); 22 23 class DaoLogin { 24 public static $settings; 25 public static $web3; 26 27 public static function init() { 28 self::$settings = new Settings(); 29 self::$web3 = new Web3( self::$settings ); 30 } 31 } 32 add_action( 'init', __NAMESPACE__ . '\DaoLogin::init' ); 21 33 22 34 add_action( … … 28 40 array( 29 41 'methods' => 'GET', 30 'callback' => __NAMESPACE__ . '\ generate_message',42 'callback' => __NAMESPACE__ . '\Web3::generate_message', 31 43 'arguments' => array( 32 44 'address' => array( … … 40 52 ); 41 53 42 function generate_message( $request ) {43 $nonce = wp_create_nonce( 'eth_login' );44 $uri = get_site_url();45 $domain = parse_url( $uri, PHP_URL_HOST );46 $statement = esc_attr__( 'Log In with your Ethereum wallet', 'dao-login' ); // TBD47 $version = 1; // Per https://github.com/ethereum/EIPs/blob/9a9c5d0abdaf5ce5c5dd6dc88c6d8db1b130e95b/EIPS/eip-4361.md#example-message-to-be-signed48 $issued_at = gmdate( 'Y-m-d\TH:i:s\Z' );49 50 // This is copy-pasted from https://github.com/ethereum/EIPs/blob/9a9c5d0abdaf5ce5c5dd6dc88c6d8db1b130e95b/EIPS/eip-4361.md#informal-message-template51 $message = "{$domain} wants you to sign in with your Ethereum account:52 {$request['address']}53 54 {$statement}55 56 URI: {$uri}57 Version: {$version}58 Nonce: {$nonce}59 Issued At: {$issued_at}60 ";61 // This attempt will auto expire in 5 minutes. This way, we'll save the message server-side to check after the login attempt.62 set_transient( 'wp_dao_message_' . $request['address'], $message, 60 * 5 );63 return array(64 'address' => $request['address'],65 'message' => $message,66 'nonce' => $nonce,67 );68 }69 54 70 55 /** … … 86 71 return $user; 87 72 } 88 $nonce = sanitize_title( $_POST['eth_login_nonce'] );73 $nonce = sanitize_title( $_POST['eth_login_nonce'] ); 89 74 $address = sanitize_title( $_POST['eth_login_address'] ); 90 75 // We stored the message in the DB before sending it to the client. … … 98 83 99 84 // Now let's check the signature. 100 if ( ! verify_signature( $message, $signature, $address ) ) {85 if ( ! Web3::verify_signature( $message, $signature, $address ) ) { 101 86 return new \WP_Error( 'eth_login_sig', esc_attr__( 'ETH Signature doesent match!', 'dao-login' ) ); 102 87 } … … 112 97 ) 113 98 ); 114 $users = $user_query->get_results();99 $users = $user_query->get_results(); 115 100 if ( isset( $users[0] ) ) { 116 101 return $users[0]; 102 } elseif ( DaoLogin::$settings->is_registering_enabled() ) { 103 // Allow registering through the API. 104 $balances = DaoLogin::$web3->get_token_balances( $address, DaoLogin::$settings->get_token_list() ); 105 $role = balances_to_role( DaoLogin::$settings->get_tokens_array(), $balances ); 106 if ( $role ) { 107 $user_id = wp_create_user( $address, wp_generate_password(), "{$address}@ethmail.cc" ); 108 add_user_meta( $user_id, 'eth_address', $address, true ); 109 $user = get_user_by( 'ID', $user_id ); 110 $user->set_role( $role ); 111 return $user; 112 } else { 113 return new \WP_Error( 'eth_login_insufficient_funds', esc_attr__( 'Insufficient tokens to register on this site.', 'dao-login' ) ); 114 } 117 115 } else { 118 116 return new \WP_Error( 'eth_login_nouser', esc_attr__( 'No user connected to this Ethereum wallet.', 'dao-login' ) ); … … 124 122 125 123 126 /** 127 * This will verify Ethereum signed message according to the specification. 128 * From https://github.com/simplito/elliptic-php#verifying-ethereum-signature 129 */ 130 function verify_signature( $message, $signature, $address) {131 require_once __DIR__ . '/vendor/autoload.php';132 $msglen = strlen( $message );133 $hash = Keccak::hash( "\x19Ethereum Signed Message:\n{$msglen}{$message}", 256 );134 $sign = [135 'r' => substr( $signature, 2, 64 ),136 's' => substr( $signature, 66, 64 ),137 ];138 $recid = ord( hex2bin( substr( $signature, 130, 2 ) ) ) - 27;139 if ( $recid != ( $recid & 1 ) ) {140 return false;124 function balances_to_role( $tokens, $balances ) { 125 $roles = wp_roles()->roles; 126 // I am assuming roles are going down with the order of importance. 127 foreach ( $roles as $role_id => $role ) { 128 foreach ( $tokens as $token_id => $token ) { 129 foreach ( $balances as $balance ) { 130 if ( 131 $balance->contractAddress === $token_id && 132 ! empty( $token[ "role_{$role_id}" ] ) && 133 $balance->tokenBalance >= $token[ "role_{$role_id}" ] 134 ) { 135 return $role_id; 136 } 137 } 138 } 141 139 } 142 143 $ec = new EC( 'secp256k1' ); 144 $pubkey = $ec->recoverPubKey( $hash, $sign, $recid ); 145 146 return $address == pub_key_address( $pubkey ); 140 return false; 147 141 } 148 142 149 function pub_key_address( $pubkey ) {150 return '0x' . substr( Keccak::hash( substr( hex2bin( $pubkey->encode( 'hex' ) ), 1 ), 256 ), 24 );151 }152 143 153 144 … … 184 175 add_action( 'personal_options_update', __NAMESPACE__ . '\save_profile_fields' ); 185 176 add_action( 'edit_user_profile_update', __NAMESPACE__ . '\save_profile_fields' ); 177 -
dao-login/tags/0.2.1/readme.txt
r2635441 r2649870 1 1 === DAO Login === 2 2 Contributors: artpi 3 Tags: signin, web3, ethereum, login, sso 3 Tags: signin, web3, ethereum, login, sso, nft, dao 4 4 Requires at least: 5.3.1 5 5 Tested up to: 5.8.2 6 Stable tag: 0. 1.26 Stable tag: 0.2.1 7 7 Requires PHP: 7.0.0 8 8 License: GPL-2.0-or-later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 Enable signin with Ethereum on your site. 11 Enable signin with Ethereum on your site and allow users to register based on Governance tokens, NFT, and token balance. 12 [Demo site here](https://wpdao.artpi.net/) 12 13 13 14 == Description == 14 15 15 This plugin enables "Sign-In with Ethereum" protocol on your WordPress site. Your users will be able to log in with their wallets - you never have to send them the password! 16 Enable cryptographically secure login option now! 16 DAO Login is a plugin that connects your site login system web3: 17 17 18 - [More about sign-in with Ethereum protocol](https://login.xyz/) 19 - [A video of this plugin in action](https://twitter.com/artpi/status/1462143739686699018) 18 - Existing users can log in with their Ethereum Wallets using the [Sign in with Ethereum](https://login.xyz) 19 - New users can create accounts based on their token balances 20 - You can designate members-only areas for token holders 21 - Works with existing WordPress user roles and other plugins. You can create a private forum, private store, DAO blog, etc. 20 22 21 Future plans include: 22 - Importing .eth username from ENS 23 - Creating users based on them having a certain amount of governance tokens for a DAO, or a specific NFT 24 - Disabling password / email options so that your users are 100% secured by private/public key pairs. 23 24 = Automatic onboarding = 25 26 DAO Login connects WordPress user roles to the token balances. 27 28 Whenever somebody logs in with Ethereum on your site for the first time, the plugin checks their token balances on the Ethereum mainnet (or test network or L2 of your choosing). 29 30 For any user role, you can specify the minimum amount of a token the user needs to have in order to create an account. 31 32 Your token can be a DAO Governance token, NFT, coin, or any other contract. 33 34 If you need a site for your DAO, just spin up a WordPress, install this plugin, and connect it to your governance structure. You don’t need to know the email address of anybody. 35 36 = Built-in “Members only” area = 37 38 DAO Login introduces a new “DAO Member” user role. You can mark posts or pages as “DAO Member only” and they will automatically be accessible only for users with this role, or higher. 39 40 If you want to provide a secret page, resource manual, or a perk for your DAO, NFT, or other token holders – it’s a few seconds with this plugin. 41 42 This opens a world of possibilities for your Airdrop. 43 44 = Power of WordPress in web3 = 45 46 WordPress plugins offer every functionality under the sun. By connecting user roles to tokens, you can create: 47 48 - Private forums with bbPress 49 - Private swag store with WooCommerce 50 - Private courses with Sensei 25 51 26 52 == Installation == … … 28 54 1. Upload the plugin files to the `/wp-content/plugins/dao-login` directory, or install the plugin through the WordPress plugins screen directly. 29 55 1. Activate the plugin through the 'Plugins' screen in WordPress 30 1. Now you can add Ethereum wallet addresses in the users screen (`/wp-admin/users.php`), in the "WP DAO" section 56 1. In order to allow token holders to register on your site, you have to select contract addresses in the settings page (`/wp-admin/options-general.php?page=dao-login`) 57 1. You can also add Ethereum wallet addresses in the users screen (`/wp-admin/users.php`), in the "WP DAO" section 31 58 1. Every user that has that field filled out, can log in with their wallet 59 32 60 33 61 … … 42 70 = 0.1.1 = 43 71 * Fix security issues pointed out in WordPress security review 72 = 0.2.1 = 73 * Add an option to create users using the account balance 74 * A simple members-only area 44 75 76 -
dao-login/trunk/dao-login.php
r2635441 r2649870 1 1 <?php 2 2 namespace Artpi\WPDAO; 3 4 use Elliptic\EC;5 use kornrunner\Keccak;6 use WP_Error;7 3 8 4 /** 9 5 * Plugin Name: DAO Login 10 6 * Description: Make your site web3-ready: Log in with Ethereum or create users based on governance tokens. 11 * Version: 0. 1.27 * Version: 0.2.1 12 8 * Author: Artur Piszek (artpi) 13 9 * Author URI: https://piszek.com … … 19 15 */ 20 16 17 require_once __DIR__ . '/dao-permissions.php'; 18 require_once __DIR__ . '/members-only.php'; 19 require_once __DIR__ . '/web3.php'; 20 21 register_activation_hook( __FILE__, __NAMESPACE__ . '\add_roles_on_plugin_activation' ); 22 23 class DaoLogin { 24 public static $settings; 25 public static $web3; 26 27 public static function init() { 28 self::$settings = new Settings(); 29 self::$web3 = new Web3( self::$settings ); 30 } 31 } 32 add_action( 'init', __NAMESPACE__ . '\DaoLogin::init' ); 21 33 22 34 add_action( … … 28 40 array( 29 41 'methods' => 'GET', 30 'callback' => __NAMESPACE__ . '\ generate_message',42 'callback' => __NAMESPACE__ . '\Web3::generate_message', 31 43 'arguments' => array( 32 44 'address' => array( … … 40 52 ); 41 53 42 function generate_message( $request ) {43 $nonce = wp_create_nonce( 'eth_login' );44 $uri = get_site_url();45 $domain = parse_url( $uri, PHP_URL_HOST );46 $statement = esc_attr__( 'Log In with your Ethereum wallet', 'dao-login' ); // TBD47 $version = 1; // Per https://github.com/ethereum/EIPs/blob/9a9c5d0abdaf5ce5c5dd6dc88c6d8db1b130e95b/EIPS/eip-4361.md#example-message-to-be-signed48 $issued_at = gmdate( 'Y-m-d\TH:i:s\Z' );49 50 // This is copy-pasted from https://github.com/ethereum/EIPs/blob/9a9c5d0abdaf5ce5c5dd6dc88c6d8db1b130e95b/EIPS/eip-4361.md#informal-message-template51 $message = "{$domain} wants you to sign in with your Ethereum account:52 {$request['address']}53 54 {$statement}55 56 URI: {$uri}57 Version: {$version}58 Nonce: {$nonce}59 Issued At: {$issued_at}60 ";61 // This attempt will auto expire in 5 minutes. This way, we'll save the message server-side to check after the login attempt.62 set_transient( 'wp_dao_message_' . $request['address'], $message, 60 * 5 );63 return array(64 'address' => $request['address'],65 'message' => $message,66 'nonce' => $nonce,67 );68 }69 54 70 55 /** … … 86 71 return $user; 87 72 } 88 $nonce = sanitize_title( $_POST['eth_login_nonce'] );73 $nonce = sanitize_title( $_POST['eth_login_nonce'] ); 89 74 $address = sanitize_title( $_POST['eth_login_address'] ); 90 75 // We stored the message in the DB before sending it to the client. … … 98 83 99 84 // Now let's check the signature. 100 if ( ! verify_signature( $message, $signature, $address ) ) {85 if ( ! Web3::verify_signature( $message, $signature, $address ) ) { 101 86 return new \WP_Error( 'eth_login_sig', esc_attr__( 'ETH Signature doesent match!', 'dao-login' ) ); 102 87 } … … 112 97 ) 113 98 ); 114 $users = $user_query->get_results();99 $users = $user_query->get_results(); 115 100 if ( isset( $users[0] ) ) { 116 101 return $users[0]; 102 } elseif ( DaoLogin::$settings->is_registering_enabled() ) { 103 // Allow registering through the API. 104 $balances = DaoLogin::$web3->get_token_balances( $address, DaoLogin::$settings->get_token_list() ); 105 $role = balances_to_role( DaoLogin::$settings->get_tokens_array(), $balances ); 106 if ( $role ) { 107 $user_id = wp_create_user( $address, wp_generate_password(), "{$address}@ethmail.cc" ); 108 add_user_meta( $user_id, 'eth_address', $address, true ); 109 $user = get_user_by( 'ID', $user_id ); 110 $user->set_role( $role ); 111 return $user; 112 } else { 113 return new \WP_Error( 'eth_login_insufficient_funds', esc_attr__( 'Insufficient tokens to register on this site.', 'dao-login' ) ); 114 } 117 115 } else { 118 116 return new \WP_Error( 'eth_login_nouser', esc_attr__( 'No user connected to this Ethereum wallet.', 'dao-login' ) ); … … 124 122 125 123 126 /** 127 * This will verify Ethereum signed message according to the specification. 128 * From https://github.com/simplito/elliptic-php#verifying-ethereum-signature 129 */ 130 function verify_signature( $message, $signature, $address) {131 require_once __DIR__ . '/vendor/autoload.php';132 $msglen = strlen( $message );133 $hash = Keccak::hash( "\x19Ethereum Signed Message:\n{$msglen}{$message}", 256 );134 $sign = [135 'r' => substr( $signature, 2, 64 ),136 's' => substr( $signature, 66, 64 ),137 ];138 $recid = ord( hex2bin( substr( $signature, 130, 2 ) ) ) - 27;139 if ( $recid != ( $recid & 1 ) ) {140 return false;124 function balances_to_role( $tokens, $balances ) { 125 $roles = wp_roles()->roles; 126 // I am assuming roles are going down with the order of importance. 127 foreach ( $roles as $role_id => $role ) { 128 foreach ( $tokens as $token_id => $token ) { 129 foreach ( $balances as $balance ) { 130 if ( 131 $balance->contractAddress === $token_id && 132 ! empty( $token[ "role_{$role_id}" ] ) && 133 $balance->tokenBalance >= $token[ "role_{$role_id}" ] 134 ) { 135 return $role_id; 136 } 137 } 138 } 141 139 } 142 143 $ec = new EC( 'secp256k1' ); 144 $pubkey = $ec->recoverPubKey( $hash, $sign, $recid ); 145 146 return $address == pub_key_address( $pubkey ); 140 return false; 147 141 } 148 142 149 function pub_key_address( $pubkey ) {150 return '0x' . substr( Keccak::hash( substr( hex2bin( $pubkey->encode( 'hex' ) ), 1 ), 256 ), 24 );151 }152 143 153 144 … … 184 175 add_action( 'personal_options_update', __NAMESPACE__ . '\save_profile_fields' ); 185 176 add_action( 'edit_user_profile_update', __NAMESPACE__ . '\save_profile_fields' ); 177 -
dao-login/trunk/readme.txt
r2635441 r2649870 1 1 === DAO Login === 2 2 Contributors: artpi 3 Tags: signin, web3, ethereum, login, sso 3 Tags: signin, web3, ethereum, login, sso, nft, dao 4 4 Requires at least: 5.3.1 5 5 Tested up to: 5.8.2 6 Stable tag: 0. 1.26 Stable tag: 0.2.1 7 7 Requires PHP: 7.0.0 8 8 License: GPL-2.0-or-later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 Enable signin with Ethereum on your site. 11 Enable signin with Ethereum on your site and allow users to register based on Governance tokens, NFT, and token balance. 12 [Demo site here](https://wpdao.artpi.net/) 12 13 13 14 == Description == 14 15 15 This plugin enables "Sign-In with Ethereum" protocol on your WordPress site. Your users will be able to log in with their wallets - you never have to send them the password! 16 Enable cryptographically secure login option now! 16 DAO Login is a plugin that connects your site login system web3: 17 17 18 - [More about sign-in with Ethereum protocol](https://login.xyz/) 19 - [A video of this plugin in action](https://twitter.com/artpi/status/1462143739686699018) 18 - Existing users can log in with their Ethereum Wallets using the [Sign in with Ethereum](https://login.xyz) 19 - New users can create accounts based on their token balances 20 - You can designate members-only areas for token holders 21 - Works with existing WordPress user roles and other plugins. You can create a private forum, private store, DAO blog, etc. 20 22 21 Future plans include: 22 - Importing .eth username from ENS 23 - Creating users based on them having a certain amount of governance tokens for a DAO, or a specific NFT 24 - Disabling password / email options so that your users are 100% secured by private/public key pairs. 23 24 = Automatic onboarding = 25 26 DAO Login connects WordPress user roles to the token balances. 27 28 Whenever somebody logs in with Ethereum on your site for the first time, the plugin checks their token balances on the Ethereum mainnet (or test network or L2 of your choosing). 29 30 For any user role, you can specify the minimum amount of a token the user needs to have in order to create an account. 31 32 Your token can be a DAO Governance token, NFT, coin, or any other contract. 33 34 If you need a site for your DAO, just spin up a WordPress, install this plugin, and connect it to your governance structure. You don’t need to know the email address of anybody. 35 36 = Built-in “Members only” area = 37 38 DAO Login introduces a new “DAO Member” user role. You can mark posts or pages as “DAO Member only” and they will automatically be accessible only for users with this role, or higher. 39 40 If you want to provide a secret page, resource manual, or a perk for your DAO, NFT, or other token holders – it’s a few seconds with this plugin. 41 42 This opens a world of possibilities for your Airdrop. 43 44 = Power of WordPress in web3 = 45 46 WordPress plugins offer every functionality under the sun. By connecting user roles to tokens, you can create: 47 48 - Private forums with bbPress 49 - Private swag store with WooCommerce 50 - Private courses with Sensei 25 51 26 52 == Installation == … … 28 54 1. Upload the plugin files to the `/wp-content/plugins/dao-login` directory, or install the plugin through the WordPress plugins screen directly. 29 55 1. Activate the plugin through the 'Plugins' screen in WordPress 30 1. Now you can add Ethereum wallet addresses in the users screen (`/wp-admin/users.php`), in the "WP DAO" section 56 1. In order to allow token holders to register on your site, you have to select contract addresses in the settings page (`/wp-admin/options-general.php?page=dao-login`) 57 1. You can also add Ethereum wallet addresses in the users screen (`/wp-admin/users.php`), in the "WP DAO" section 31 58 1. Every user that has that field filled out, can log in with their wallet 59 32 60 33 61 … … 42 70 = 0.1.1 = 43 71 * Fix security issues pointed out in WordPress security review 72 = 0.2.1 = 73 * Add an option to create users using the account balance 74 * A simple members-only area 44 75 76
Note: See TracChangeset
for help on using the changeset viewer.