Verona 백서

Verona

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 54쪽 중 14쪽

hould see a list like: ``` List of devices attached emulator-5554 device ``` **Note:** If no devices are listed, try restarting ADB: ```bash adb kill-server adb start-server ``` ### 3. Path Handling Errors in `react-native-libsodium` (Windows) **Error Symptoms:** * Build fails due to invalid escape sequences (`\A`, `\b`, etc.). * Common when project paths include backslashes (e.g., `D:\Application\...`). **Root Cause:**\ CMake interprets `\\` in Windows-style paths as escape sequences. This causes malformed paths when building native dependencies. **Solution:**\ Manually modify the `CMakeLists.txt` file in the `react-native-libsodium` dependency: **File Path:** ``` node_modules/react-native-libsodium/android/CMakeLists.txt ``` **Fix:**\ Add the following lines to convert `NODE_MODULES_DIR` into a valid CMake path: ```cmake file(TO_CMAKE_PATH "${NODE_MODULES_DIR}" SAFE_NODE_MODULES_DIR) set(JSI_CPP_PATH "${SAFE_NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp") ``` Then replace references to `NODE_MODULES_DIR` with `SAFE_NODE_MODULES_DIR`. For example: ```javascript # set the base libsodium build directory set(LIBSODIUM_BUILD_DIR ${CMAKE_CURRENT_LIST_DIR}/../libsodium/build) # set the libsodium build directory depending on the target abi if (${ANDROID_ABI} STREQUAL arm64-v8a) set(LIBSODIUM_BUILD_DIR ${LIBSODIUM_BUILD_DIR}/libsodium-android-armv8-a+crypto) elseif(${ANDROID_ABI} STREQUAL armeabi-v7a) set(LIBSODIUM_BUILD_DIR ${LIBSODIUM_BUILD_DIR}/libsodium-android-armv7-a) elseif(${ANDROID_ABI} STREQUAL x86) set(LIBSODIUM_BUILD_DIR ${LIBSODIUM_BUILD_DIR}/libsodium-android-i686) else() set(LIBSODIUM_BUILD_DIR ${LIBSODIUM_BUILD_DIR}/libsodium-android-westmere) endif() add_library(sodium SHARED IMPORTED) include_directories( ${LIBSODIUM_BUILD_DIR}/include/ ) set_target_properties( sodium PROPERTIES IMPORTED_LOCATION ${LIBSODIUM_BUILD_DIR}/lib/libsodium.so ) # --- BEGIN MODIFICATION --- # Convert NODE_MODULES_DIR to a CMake-friendly path file(TO_CMAKE_PATH "${NODE_MODULES_DIR}" SAFE_NODE_MODULES_DIR) # Construct the JSI CPP path using the safe path and forward slashes set(JSI_CPP_PATH "${SAFE_NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp") # here we define a library target called "libsodium" # which will be built from the listed source files add_library(libsodium SHARED "${JSI_CPP_PATH}" # Use the corrected path variable ../cpp/react-native-libsodium.cpp ../cpp/react-native-libsodium.h cpp-adapter.cpp ) # --- END MODIFICATION --- # link the sodium lib with our "libsodium" library target defined earlier target_link_libraries(libsodium sodium) ``` **After saving the file:**\ Clean and rebuild your Android project: ```bash cd android ./gradlew clean cd .. npx expo run:android ``` **Recommended Tip:**\ Avoid placing your project in folders with capital letters or special characters (e.g., `D:\Application\Verona`) to reduce CMake path issues. ### 4. ADB Shows Duplicate or Ghost Devices **Symptoms:** * Android Studio’s AVD only lists one emulator, but `adb devices` shows multiple. * Build errors or confusion about which emulator is active. **Cause:** * Stale ADB device entries from previously deleted or corrupted emulator instances. **Fix:**\ Restart the ADB server: ```bash adb kill-server adb start-server adb devices ``` If this doesn't resolve it: * Delete all unused emulators from **Android Studio → Device Manager**. * Recreate new AVDs to avoid misconfigured devices. ### Extra Tips for Smooth Builds * Always use **Node.js LTS versions** for React Native projects (avoid experimental versions like v23). * Run `npx expo doctor` or `npx react-native doctor` regularly to diagnose config issues. * Keep your Expo CLI and dependencies up to date: ```bash npm install -g expo-cli npm outdated ``` ### Still Stuck? If you continue to encounter issues: * Run the command with `--verbose` or `--stacktrace` to get detailed logs. # OAuth2 App Development This guide provides a comprehensive walkthrough for integrating Verona into your application by OAuth2 authentication. This guide provides a comprehensive walkthrough for integrating Verona into your application by OAuth2 authentication. By following this guide, you'll enable secure and efficient user authentication, leveraging the OAuth2 protocol to provide a Web2-style experience with blockchain capabilities. A fully functional demo of OAuth2 integration is available in the [Verona OAuth2 App Demo](https://github.com/burnt-labs/xion-oauth2-app-demo) repository. ## 1. Understanding OAuth2 and Its Benefits OAuth 2.0 is an industry-standard protocol for authorization, designed to provide specific authorization flows for web applications, desktop applications, mobile phones, and living room devices. The specification and its extensions are being developed within the IETF OAuth Working Group. For more information about OAuth 2.0, visit [oauth.net/2/](https://oauth.net/2/). **Benefits of OAuth2 Integration with Verona:** * **No Wallet Management**: Eliminates the complexity of wallet installation, seed phrase management, and transaction signing for end users * **Web2 User Experience**: Users can authenticate using familiar Web2 methods (social logins, email, passkeys) without needing to manage blockchain wallets or private keys * **Secure Token-Based Authentication**: Uses industry-standard OAuth2 tokens for secure API access without exposing user credentials * **Gasless Transactions**: Leverages Treasury contracts to enable gasless transactions, removing the need for users to hold native tokens * **Delegated Authorization**: Allows applications to execute transactions on behalf of users with explicit permissions * **Scalability**: Facilitates integration with multiple services and platforms, promoting interoperability Verona OAuth2 currently supports the **Authorization Code flow** with **PKCE (Proof Key for Code Exchange)** for enhanced security. This flow is recommended for both public and confidential clients. {% hint style="info" %} **OAuth2 flow support**: Verona OAuth2 supports the **Authorization Code** flow (with PKCE for public clients). The token endpoint also supports **`grant_type=refresh_token`**: after a successful code exchange, the JSON response may include a `refresh_token` you can use to obtain new access tokens without sending the user through the login screen again. Access token lifetime is typically on the order of one day; refresh token lifetime is longer (see `expires_in` on each response). If you do not store or use `refresh_token`, fall back to re-running the authorization flow when the access token expires. {% endhint %} ## 2. Prerequisites - Treasury Contract Setup Before integrating OAuth2 with Verona Auth, you must first deploy and configure a **Treasury Contract**. The Treasury contract manages gasless transactions and permission grants, which are essential for the OAuth2 flow. For detailed instructions on deploying a Treasury contract, refer to the [Treasury Contracts Documentation](/en/build-on-verona/accounts/getting-started/treasury-contracts). ### 2.1. Critical Treasury Configuration Requirements When configuring your Treasury contract, there are two **critical requirements** for OAuth2 integration: #### 2.1.1. Redirect URI Configuration The on-chain Treasury parameter **`redirect_url`** is the **single source of truth** for your OAuth2 client's redirect URI. When you create or sync an OAuth2 client, the service copies `redirect_url` into the client's allowed redirect URIs. You cannot set redirect URIs independently through the Developer Portal or client-management API. Your application's **`redirect_uri`** authorization parameter **must exactly match** the Treasury `redirect_url` (scheme, host, path, and trailing slash). This is where users are redirected after successful authentication. The OAuth2 authorization endpoint **fails closed** on mismatch: if `redirect_uri` does not equal the bound Treasury's current `redirect_url`, authorization is rejected even if an older stored value differed. Fix the Treasury on-chain first, sync the client (see [§3.4](#3.4.-updating-redirect-uri-or-branding)), then use the updated URI in your app. <figure><img src="https://3630978198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB5Z5ijJgMx0GJO3l1Il9%2Fuploads%2FpkqObbHWunoRXvo12Zd9%2Fimage.png?alt=media&amp;token=7977fd5a-dbc3-4a52-b4de-9766d433144b" alt=""><figcaption><p>Treasury contract configuration showing redirect URI</p></figcaption></figure> **Example:** * If your OAuth2 app uses `http://localhost:3000/callback` as the `redirect_uri` * Your Treasury contract's `redirect_url` must also be set to `http://localhost:3000/callback` * Set `redirect_url` on the Treasury **before** creating the OAuth2 client #### 2.1.2. OAuth2 App Toggle You **MUST enable the "IS OAUTH2 APP" toggle** in the Treasury contract's Update Params section. This setting indicates that the Treasury contract is being used for OAuth2 authentication. <figure><img src="https://3630978198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB5Z5ijJgMx0GJO3l1Il9%2Fuploads%2F1crFi6FUs5YVlK9wykgF%2FOAuth2-0.png?alt=media&amp;token=ce114393-f868-4fda-9f9f-a835fe97d381" alt="" width="375"><figcaption><p>Update Params dialog showing the IS OAUTH2 APP toggle</p></figcaption></figure> **To enable the OAuth2 toggle:** 1. Navigate to your Treasury contract in the [Developer Portal (testnet)](https://dev.testnet.burnt.com/) or [Developer Portal (mainnet)](https://dev.burnt.com/). Use the portal that matches your target network. 2. Click the **"Update Params"** button 3. Enable the **"IS OAUTH2 APP"** toggle switch 4. Save the changes {% hint style="warning" %} **OAuth2 Toggle Required**: Without enabling the "IS OAUTH2 APP" toggle, users will see redirect URI mismatch warnings when attempting to authenticate, even if the redirect URIs match correctly. {% endhint %} #### 2.1.3. Treasury Permissions and OAuth2 Transactions The permissions (grant configs) you define in your Treasury contract determine which types of transactions can be executed through the OAuth2 API. **Only message types that are explicitly authorized in your Treasury contract's permissions can be used in OAuth2 transaction requests.** For example: * If your Treasury only has permission for `MsgSend` (token transfers), you can only send tokens via OAuth2 Protected API * If your Treasury has permission for `MsgExecuteContract`, you can execute smart contract calls via OAuth2 Protected API * You can configure multiple permissions to allow different transaction types For more information on configuring Treasury permissions, see the [Treasury Contracts Documentation](/en/build-on-verona/accounts/getting-started/treasury-contracts). ## 3. Creating OAuth2 Clients Once your Treasury contract is configured, you can create OAuth2 clients from the **Developer Portal**. The Developer Portal allows you to manage OAuth2 clients that will authenticate users and access protected APIs. ### 3.1. Accessing OAuth2 Client Management * **Testnet**: <https://dev.testnet.burnt.com/oauth2-clients> * **Mainnet**: <https://dev.burnt.com/oauth2-clients> <figure><img src="https://3630978198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB5Z5ijJgMx0GJO3l1Il9%2Fuploads%2Fgit-blob-7786d20f642434e58d77cb44dca6c776cc0a89e8%2Fverona-portal.png?alt=media" alt="" width="375"><figcaption><p>Developer Portal login screen</p></figcaption></figure> To access the Developer Portal, click **"Connect with Verona"** and authenticate using your Verona Meta Account. After authentication, you'll be redirected to the OAuth2 Clients Dashboard. #### Manager login requirement (challenge + verify) Managing OAuth2 clients calls the manager API with a **Session JWT**. That session is minted only via **`POST /auth/challenge`** then **`POST /auth/verify`** (unsigned “sdk-session” minting is disabled). The portal signs the challenge with an authenticator registered on your Meta Account. **Your manager Meta Account must include at least one authenticator that can complete challenge + verify**, for example: * **EthWallet** (recommended) — MetaMask or another Ethereum wallet that can `personal_sign` the challenge; use the same address registered as the EthWallet authenticator * **Secp256K1** — a Cosmos wallet (for example Keplr / Leap) registered as a Secp256K1 authenticator * **JWT** — a fresh identity-provider JWT that matches an on-chain JWT authenticator (when your login path supplies one) If the account only has authenticators that cannot prove ownership this way (for example passkey-only today), client management will fail after Connect. Add an **EthWallet** authenticator to the Meta Account, then retry. {% hint style="warning" %} **Manager vs end-user login**: End users of *your* OAuth2 app can still sign in with the Web2 / social / passkey flows you configure. The EthWallet (or equivalent) requirement applies to **you as the OAuth2 client administrator** managing clients in the Developer Portal (and to any script that calls the manager API with a session from challenge + verify). {% endhint %} {% hint style="info" %} Use the **testnet** portal while developing and the **mainnet** portal for production OAuth2 clients. Your app must use the OAuth2 server URL, discovery endpoints, and protected API base URL for the same network as your Treasury contract. {% endhint %} ### 3.2. Creating a New OAuth2 Client 1. **Navigate to the Dashboard** After logging in, you'll see the OAuth2 Clients Dashboard showing all your created clients. <figure><img src="https://3630978198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB5Z5ijJgMx0GJO3l1Il9%2Fuploads%2Fgit-blob-e23011140cfc6ccba6beb6738fff96821b25a20d%2Fverona-oauth2-1.png?alt=media" alt=""><figcaption><p>OAuth2 Clients Dashboard with Create Client button</p></figcaption></figure> 2. **Click "Create Client"** Click the **"Create Client"** button located in the top right corner of the dashboard. 3. **Configure Client Settings** The client creation form will appear. <figure><img src="https://3630978198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB5Z5ijJgMx0GJO3l1Il9%2Fuploads%2Fgit-blob-5f07cc656a2191104415b570013f37825de2ae34%2Fverona-oauth2-2.png?alt=media" alt="" width="375"><figcaption><p>OAuth2 Client creation form</p></figcaption></figure> **You need to complete the following fields:** * **Treasury Address**: Select a Treasury contract from your existing deployments or enter a new Treasury address. The Treasury must already have **`redirect_url`** and **`icon_url`** configured on-chain (via **Update Params** in the Developer Portal). You must be a Treasury admin to bind it. * **Client Name** (optional): A descriptive name for your application. If not provided, the client name defaults to untitled. The portal may suggest a name from the Treasury `display_url`. **Treasury-derived values (read-only at create):** After you select a Treasury, the form shows **Treasury Information** copied from on-chain params. You do not enter these separately: * **Redirect URI** ← Treasury `redirect_url` * **Logo URI** ← Treasury `icon_url` * **Client URI** (homepage) ← Treasury `display_url` (optional on-chain) **Default Configuration:** * By default, clients are created as **Public Clients with PKCE** enabled, which is suitable for frontend applications. 4. **Advanced Options - Confidential Client** If you're building a backend application and need a **Confidential Client**, click to expand the **"Advanced Options"** section. <figure><img src="https://3630978198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB5Z5ijJgMx0GJO3l1Il9%2Fuploads%2FhupEGljwwFqZX9fV09VC%2FOAuth2-4.png?alt=media&amp;token=76501807-b328-4081-ad83-3d5f92497c1a" alt="" width="375"><figcaption><p>Advanced Options showing Confidential Client selection</p></figcaption></figure> In the Advanced Options: * **Token Endpoint Auth Method**: Select **"Client Secret Post (Confidential Client)"** to create a confidential client * You can also configure optional fields like Policy URI, Terms of Service URI, and JWKS URI 5. **Create the Client** Click the **"Create Client"** button to create your OAuth2 client. 6. **Save Client Credentials** If you created a **Confidential Client**, a dialog will appear showing your **Client ID** and **Client Secret**. <figure><img src="https://3630978198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB5Z5ijJgMx0GJO3l1Il9%2Fuploads%2FnGmLqwSPhAqN15kUxtvN%2FOAuth2-5.png?alt=media&amp;token=efcd039b-b4bb-48ae-b9e6-f33d4c71be11" alt="" width="375"><figcaption><p>Client Secret display dialog - save this immediately</p></figcaption></figure> {% hint style="warning" %} **Important: Save Your Client Secret**: For Confidential Clients, the Client Secret is displayed **only once** during client creation. You must copy and save it securely immediately. If you lose the Client Secret, you'll need to create a new client. {% endhint %} ### 3.3. Understanding Client Types #### 3.3.1. Type 1: Public Client **Use Case**: Frontend applications (React, Vue, Angular, etc.) running in the browser **Characteristics:** * No `client_secret` required * **Must use PKCE** (Proof Key for Code Exchange) for security * Token exchange happens in the browser * Suitable for Single Page Applications (SPAs) and mobile apps **Security**: PKCE provides security equivalent to using a client secret, making it safe for public clients. #### 3.3.2. Type 2: Confidential Client **Use Case**: Backend applications (Node.js, Python, etc.) with server-side token exchange **Characteristics:** * Requires `client_secret` for authentication * Token exchange happens on the server * More secure for backend applications * Can optionally use PKCE in addition to client\_secret **Security**: The `client_secret` is stored securely on the server and never exposed to the client. ### 3.4. Updating Redirect URI or Branding Redirect URI, logo, and client (homepage) URI are **not editable** on the OAuth2 client record. They always follow the bound Treasury's on-chain params (`redirect_url`, `icon_url`, `display_url`). **To change redirect URI or branding:** 1. **Update the Treasury on-chain first** — In the [Developer Portal (testnet)](https://dev.testnet.burnt.com/) or [Developer Portal (mainnet)](https://dev.burnt.com/), open your Treasury contract, click **Update Params**, and set `redirect_url`, `icon_url`, and/or `display_url` as needed. Keep **IS OAUTH2 APP** enabled. 2. **Sync the OAuth2 client** — After the on-chain update confirms, open the client in the OAuth2 Clients dashboard and click **Sync from Treasury** (available on client details and while editing). 3. **Update your application** — Use the new `redirect_url` value as the `redirect_uri` in authorization and token requests. {% hint style="info" %} Client metadata you **can** still edit in the portal (name, policy URI, terms of service URI, JWKS URI, contacts, managers) does not include redirect, logo, or client URI. Those fields only change through Treasury on-chain updates followed by **Sync from Treasury**. {% endhint %} ## 4. OAuth2 Integration Examples This section provides practical examples for integrating OAuth2 into your application. We'll cover the standard OAuth2 flow and provide complete examples for both frontend (Public Client) and backend (Confidential Client) implementations. ### 4.1 Standard OAuth2 Flow The OAuth2 Authorization Code flow with PKCE follows these standard steps: 1. **Discovery**: Fetch OAuth2 server metadata 2. **Authorization**: Redirect user to authorization endpoint 3. **Callback**: Handle authorization code 4. **Token Exchange**: Exchange authorization code for access token 5. **API Access**: Use access token for protected
프로젝트로 돌아가기