From 6aa4cabdbbec438db8a71f2362ad7c109a646158 Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Mon, 24 Mar 2025 10:55:36 +0530 Subject: [PATCH] update swift sfa docs --- docs/sdk/pnp/ios/usage.mdx | 4 +- docs/sdk/sfa/sfa-ios/initialize.mdx | 16 +- docs/sdk/sfa/sfa-ios/usage.mdx | 180 ++++++++++++++++-- src/common/sdk/sfa/ios/_sfa-ios-cocoapods.mdx | 2 +- src/common/sdk/sfa/ios/_sfa-ios-spm.mdx | 2 +- src/common/versions.ts | 2 +- 6 files changed, 181 insertions(+), 25 deletions(-) diff --git a/docs/sdk/pnp/ios/usage.mdx b/docs/sdk/pnp/ios/usage.mdx index 35347c606..123061d2d 100644 --- a/docs/sdk/pnp/ios/usage.mdx +++ b/docs/sdk/pnp/ios/usage.mdx @@ -423,7 +423,7 @@ do { // focus-start try await web3Auth!.launchWalletServices( chainConfig: ChainConfig( - chainId: "11155111", + chainId: "0xaa36a7", rpcTarget: "https://eth-sepolia.public.blastapi.io" ) ) @@ -467,7 +467,7 @@ do { // focus-start let response = try await self.web3Auth?.request( chainConfig: ChainConfig( - chainId: "11155111", + chainId: "0xaa36a7", rpcTarget: "https://eth-sepolia.public.blastapi.io" ), method: "personal_sign", diff --git a/docs/sdk/sfa/sfa-ios/initialize.mdx b/docs/sdk/sfa/sfa-ios/initialize.mdx index 7863f7a72..0f4f4126a 100644 --- a/docs/sdk/sfa/sfa-ios/initialize.mdx +++ b/docs/sdk/sfa/sfa-ios/initialize.mdx @@ -15,13 +15,15 @@ according to the preference of your project. The `SingleFactoreAuth` constructor takes an object called `Web3AuthOptions` as input. The constructor parameters are listed below -| Parameter | Description | -| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `clientId` | Your Web3Auth Client Id from [Web3Auth Dashboard](https://dashboard.web3auth.io/). | -| `web3AuthNetwork` | The Web3auth network to be used by the SDK. Supported values are `.SAPPHIRE_MAINNET`, `.SAPPHIRE_DEVNET`, `.MAINNET`, `.TESTNET`, `.CYAN`, and `.AQUA` | -| `sessionTime` | Specifies the session duration in seconds. By default, the value is set to 86400 seconds (1 day), with a maximum session duration of up to 30 days. | -| `serverTimeOffset` | Specifies the server time offset in seconds. This parameter is used to adjust the server time to the local time. The default value is 0 seconds. | -| `storageServerUrl?` | Specifies the storage server URL. The default value is `https://session.web3auth.io`. | +| Parameter | Description | +| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `clientId` | Your Web3Auth Client Id from [Web3Auth Dashboard](https://dashboard.web3auth.io/). | +| `web3AuthNetwork` | The Web3auth network to be used by the SDK. Supported values are `.SAPPHIRE_MAINNET`, `.SAPPHIRE_DEVNET`, `.MAINNET`, `.TESTNET`, `.CYAN`, and `.AQUA` | +| `sessionTime` | Specifies the session duration in seconds. By default, the value is set to 86400 seconds (1 day), with a maximum session duration of up to 30 days. | +| `serverTimeOffset` | Specifies the server time offset in seconds. This parameter is used to adjust the server time to the local time. The default value is 0 seconds. | +| `storageServerUrl?` | Specifies the storage server URL. The default value is `https://session.web3auth.io`. | +| `whiteLabel?` | You can pass the white labeling options for Web3Auth. It helps you define your brand app's custom UI, and branding for the Wallet Services and request signature feature. The recommended way to configure the `whiteLabel` is through the Web3Auth Dashboard. [Learn how to configure the `whiteLabel` via Web3Auth Dashboard](/docs/features/whitelabel#new-whitelabeling-via-the-dashboard). | +| `redirectUrl?` | URL that Web3Auth will redirect API responses upon successful `request` method call. Please note, that it's mandatory to configure the `redirectUrl` if you are using the `request` method. Redirect Url shoudl be your bundle identifier. | ## Create instance diff --git a/docs/sdk/sfa/sfa-ios/usage.mdx b/docs/sdk/sfa/sfa-ios/usage.mdx index cf05c9a21..506bf0229 100644 --- a/docs/sdk/sfa/sfa-ios/usage.mdx +++ b/docs/sdk/sfa/sfa-ios/usage.mdx @@ -21,12 +21,14 @@ you'll see an Error message. The SingleFactorAuth instance natively provides the following methods: -| Method | Description | -| ------------------------------------------ | ------------------------------------------------------------ | -| [connect](#login-user) | Use to login user and retrieve private key pair. | -| [logout](#logout-user) | Use to logout existing user. | -| [connected](#check-users-logged-in-status) | Use to check whether the user is logged in or not. | -| [getSessionData](#get-session-data) | This method helps to get the session data for valid session. | +| Method | Description | +| ------------------------------------------ | ------------------------------------------------------------------- | +| [connect](#login-user) | Use to login user and retrieve private key pair. | +| [logout](#logout-user) | Use to logout existing user. | +| [connected](#check-users-logged-in-status) | Use to check whether the user is logged in or not. | +| [getSessionData](#get-session-data) | This method helps to get the session data for valid session. | +| [showWalletUI](#show-wallet-ui) | Use to open templated the wallet UI in WebView. | +| [request](#request-signature) | Use to open templated transaction screens for signing transactions. | ## Login User @@ -162,11 +164,163 @@ if(sessionData != nil) { ### Response -The `SessionData` has the following four functions to retrive the relevant session information. +The `SessionData` has the following four properties to retrive the relevant session information. -| Function Name | Description | -| ------------------ | ------------------------------------------------------------------------- | -| `getPrivateKey` | Retrieves the user's private key. | -| `getPublicAddress` | Retrieves the user's public address. | -| `getUserInfo` | Retrieves the user's information like email, name, verifier id, and more. | -| `getSignatures` | Retrieves the node's signatures that are returned for request. | +| Name | Description | +| --------------- | ------------------------------------------------------------------------- | +| `privateKey` | Retrieves the user's private key. | +| `publicAddress` | Retrieves the user's public address. | +| `userInfo` | Retrieves the user's information like email, name, verifier id, and more. | +| `signatures` | Retrieves the node's signatures that are returned for request. | + +## Show Wallet UI + +The `showWalletUI` method launches a WebView which allows you to use the templated wallet UI +services. The method takes `ChainConfig` as the required input. Wallet Services is currently only +available for EVM chains. + +:::note + +Access to Wallet Services is gated. You can use this feature in `sapphire_devnet` for free. The +minimum [pricing plan](https://web3auth.io/pricing.html) to use this feature in a production +environment is the **Scale Plan**. + +::: + +![Wallet Services](/images/mobile-wallet-services.png) + +### Parameters + + + + + +| Parameter | Description | +| ------------------- | --------------------------------------------------------------------------------------------------------------------------- | +| `chainNamespace` | Custom configuration for your preferred blockchain. As of now only EVM supported. Default value is `ChainNamespace.eip155`. | +| `decimals?` | Number of decimals for the currency ticker. Default value is 18, and accepts `Int` as value. | +| `blockExplorerUrl?` | Blockchain's explorer URL. (eg: `https://etherscan.io`) | +| `chainId` | The chain id of the selected blockchain in hex string format. | +| `displayName?` | Display Name for the chain. | +| `logo?` | Logo for the selected `chainNamespace` & `chainId`. | +| `rpcTarget` | RPC Target URL for the selected `chainNamespace` & `chainId`. | +| `ticker?` | Default currency ticker of the network (e.g: `ETH`) | +| `tickerName?` | Name for currency ticker (e.g: `Ethereum`) | + + + + + +```swift +public enum ChainNamespace: String, Codable { + case eip155 + case solana +} + +public struct ChainConfig: Codable { + public init(chainNamespace: ChainNamespace = ChainNamespace.eip155, decimals: Int? = 18, blockExplorerUrl: String? = nil, chainId: String, displayName: String? = nil, logo: String? = nil, rpcTarget: String, ticker: String? = nil, tickerName: String? = nil) { + self.chainNamespace = chainNamespace + self.decimals = decimals + self.blockExplorerUrl = blockExplorerUrl + self.chainId = chainId + self.displayName = displayName + self.logo = logo + self.rpcTarget = rpcTarget + self.ticker = ticker + self.tickerName = tickerName + } +} +``` + + + + +### Usage + +```swift +do { + try await web3Auth.showWalletUI( + chainConfig: ChainConfig( + chainId: "0xaa36a7", + rpcTarget: "https://eth-sepolia.public.blastapi.io" + ) + ) +} catch { + // Handle error +} +``` + +## Request signature + +The `request` method facilitates the use of templated transaction screens for signing transactions. +The method will return [SignResponse](#signresponse). It can be used to sign transactions for any +EVM chain and screens can be whitelabeled to your branding. + +Please check the list of +[JSON RPC methods](https://docs.metamask.io/wallet/reference/json-rpc-api/), noting that the request +method currently supports only the signing methods. + +:::note + +Please note, to use the `request` method, you need to configure the `redirectUrl` in the +[`Web3AuthOptions`](/docs/sdk/sfa/sfa-ios/initialize#parameters) while initializing the SDK. + +::: + +![Request Method](/images/mobile-request-method.png) + +### Parameters + +| Parameter | Description | +| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `chainConfig` | Defines the chain to be used for signature. | +| `method` | JSON RPC method name in `String`. Currently, the request method only supports the singing methods. | +| `requestParams` | Parameters for the corresponding method. The parameters should be in the list and correct sequence. Take a look at [RPC methods](https://docs.metamask.io/wallet/reference/json-rpc-api/) to know more. | + +### Usage + +```swift +do { + var params = [Any]() + // Message to be signed + params.append("Hello, Web3Auth from iOS!") + // User's EOA address + params.append(address) + + // focus-start + let response = try await web3Auth.request( + chainConfig: ChainConfig( + chainId: "0xaa36a7", + rpcTarget: "https://eth-sepolia.public.blastapi.io" + ), + method: "personal_sign", + requestParams: params + ) + // focus-end + + if response!.success { + print(response!.result!) + } else { + // Handle Error + print(response!.error!) + } + +} catch { + print(error.localizedDescription) + // Handle error +} +``` + +### SignResponse + +| Name | Description | +| --------- | ------------------------------------------------------------- | +| `success` | Determines whether the request was successful or not. | +| `result?` | Holds the signature for the request when `success` is `true`. | +| `error?` | Holds the error for the request when `success` is `false`. | diff --git a/src/common/sdk/sfa/ios/_sfa-ios-cocoapods.mdx b/src/common/sdk/sfa/ios/_sfa-ios-cocoapods.mdx index fa471d20c..9840806dc 100644 --- a/src/common/sdk/sfa/ios/_sfa-ios-cocoapods.mdx +++ b/src/common/sdk/sfa/ios/_sfa-ios-cocoapods.mdx @@ -3,7 +3,7 @@ To install the Web3Auth SingleFactorAuth SDK using Cocoapods, follow the below s 1. Open the Podfile, and add the SingleFactorAuth pod: ```sh -pod 'SingleFactorAuth', '~> 9.0.4' +pod 'SingleFactorAuth', '~> 9.1.0' ``` 2. Once added, use `pod install` command to download the SingleFactorAuth dependency. diff --git a/src/common/sdk/sfa/ios/_sfa-ios-spm.mdx b/src/common/sdk/sfa/ios/_sfa-ios-spm.mdx index ac80cdf6a..71dd4c140 100644 --- a/src/common/sdk/sfa/ios/_sfa-ios-spm.mdx +++ b/src/common/sdk/sfa/ios/_sfa-ios-spm.mdx @@ -6,7 +6,7 @@ https://github.com/Web3Auth/single-factor-auth-swift ``` - From the `Dependency Rule` dropdown, select `Exact Version` and enter `9.0.4` as the version. + From the `Dependency Rule` dropdown, select `Exact Version` and enter `9.1.0` as the version. 1. When finished, Xcode will automatically begin resolving and downloading your dependencies in the background. diff --git a/src/common/versions.ts b/src/common/versions.ts index 56250b2e2..ecfd2dcf1 100644 --- a/src/common/versions.ts +++ b/src/common/versions.ts @@ -8,7 +8,7 @@ export const pnpUnrealVersion = `4.1.x`; export const sfaWebVersion = `9.2.x`; export const sfaAndroidVersion = `4.0.0`; -export const sfaIOSVersion = `9.0.4`; +export const sfaIOSVersion = `9.1.0`; export const sfaRNVersion = `2.0.x`; export const sfaFlutterVersion = `6.0.0`; export const sfaNodeJSVersion = `7.4.x`;