From 2408a7f9ed4421a078eb4c55eb902847a39859a7 Mon Sep 17 00:00:00 2001
From: Firekeeper <0xFirekeeper@gmail.com>
Date: Tue, 13 Aug 2024 06:25:49 +0300
Subject: [PATCH] Docs - .NET 1.4.0 // Unity 5.0.0-beta.3 (#4071)
---
apps/portal/src/app/dotnet/sidebar.tsx | 5 +-
apps/portal/src/app/dotnet/utils/page.mdx | 438 ++++++++++++++++++
.../wallets/providers/in-app-wallet/page.mdx | 96 +++-
.../src/app/unity/v5/contracts/page.mdx | 6 +-
.../src/app/unity/v5/thirdwebmanager/page.mdx | 4 +-
.../unity/v5/wallets/in-app-wallet/page.mdx | 69 +++
6 files changed, 605 insertions(+), 13 deletions(-)
create mode 100644 apps/portal/src/app/dotnet/utils/page.mdx
diff --git a/apps/portal/src/app/dotnet/sidebar.tsx b/apps/portal/src/app/dotnet/sidebar.tsx
index 803766b3d0d..362bb000f64 100644
--- a/apps/portal/src/app/dotnet/sidebar.tsx
+++ b/apps/portal/src/app/dotnet/sidebar.tsx
@@ -229,7 +229,10 @@ export const sidebar: SideBar = {
{
name: "Blockchain API",
isCollapsible: false,
- links: [contracts, transactions],
+ links: [contracts, transactions, {
+ name: "Common Utils",
+ href: "/dotnet/utils",
+ }],
},
{ separator: true },
{
diff --git a/apps/portal/src/app/dotnet/utils/page.mdx b/apps/portal/src/app/dotnet/utils/page.mdx
new file mode 100644
index 00000000000..eb020e6e719
--- /dev/null
+++ b/apps/portal/src/app/dotnet/utils/page.mdx
@@ -0,0 +1,438 @@
+import { Details, createMetadata } from "@doc";
+
+export const metadata = createMetadata({
+ title: "Common Utils | Thirdweb .NET SDK",
+ description: "Useful utilities offered by thirdweb.",
+});
+
+## Constants.ADDRESS_ZERO
+
+A `string` representing the zero address `0x0000000000000000000000000000000000000000`.
+
+Useful for passing the zero address to various functions.
+
+## Constants.NATIVE_TOKEN_ADDRESS
+
+A `string` representing the native token address `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`.
+
+Useful for passing the native token address to various functions.
+
+## FetchThirdwebChainDataAsync
+
+Fetches chain data for a specified chain ID using a Thirdweb client.
+
+```csharp
+var chainData = await Utils.FetchThirdwebChainDataAsync(client, chainId);
+```
+
+
+
+### client
+
+A `ThirdwebClient` object representing the client to use for fetching chain data.
+
+### chainId
+
+A `BigInteger` representing the chain ID to fetch data for.
+
+
+
+
+
+### chainData
+
+A `ThirdwebChainData` object containing the fetched chain data such as native token name, symbol, decimals, etc.
+
+
+
+## HexConcat
+
+Concatenates the given hex strings into a single hex string.
+
+```csharp
+var concatenatedHex = Utils.HexConcat("0x1234", "0x5678");
+```
+
+
+
+### hexStrings
+
+An array of hexadecimal `string` values to concatenate.
+
+
+
+
+
+### concatenatedHex
+
+The concatenated hexadecimal `string`.
+
+
+
+## HashPrefixedMessage
+
+Hashes the given message bytes with a prefixed message for Ethereum signing.
+
+```csharp
+var hashedMessage = messageBytes.HashPrefixedMessage();
+```
+
+
+
+### messageBytes
+
+A `byte[]` representing the message to hash.
+
+
+
+
+
+### hashedMessage
+
+A `byte[]` representing the hashed message.
+
+
+
+## HashMessage
+
+Hashes the given message using SHA3 Keccak hashing.
+
+```csharp
+var hashedMessage = message.HashMessage();
+```
+
+
+
+### message
+
+A `string` representing the message to hash.
+
+
+
+
+
+### hashedMessage
+
+A `string` representing the hashed message in hexadecimal format.
+
+
+
+## BytesToHex
+
+Converts a byte array to a hexadecimal string.
+
+```csharp
+var hexString = byteArray.BytesToHex();
+```
+
+
+
+### bytes
+
+A `byte[]` representing the byte array to convert.
+
+
+
+
+
+### hexString
+
+A `string` representing the converted hexadecimal string.
+
+
+
+## HexToBytes
+
+Converts a hexadecimal string to a byte array.
+
+```csharp
+var byteArray = hexString.HexToBytes();
+```
+
+
+
+### hex
+
+A `string` representing the hexadecimal string to convert.
+
+
+
+
+
+### byteArray
+
+A `byte[]` representing the converted byte array.
+
+
+
+## StringToHex
+
+Converts a regular string to a hexadecimal string.
+
+```csharp
+var hexString = "Hello".StringToHex();
+```
+
+
+
+### str
+
+A `string` representing the regular string to convert.
+
+
+
+
+
+### hexString
+
+A `string` representing the converted hexadecimal string.
+
+
+
+## GetUnixTimeStampNow
+
+Gets the current Unix timestamp in seconds.
+
+```csharp
+var timestampNow = Utils.GetUnixTimeStampNow();
+```
+
+
+
+### timestampNow
+
+A `long` representing the current Unix timestamp.
+
+
+
+## GetUnixTimeStampIn10Years
+
+Gets the Unix timestamp for 10 years from now.
+
+```csharp
+var timestampIn10Years = Utils.GetUnixTimeStampIn10Years();
+```
+
+
+
+### timestampIn10Years
+
+A `long` representing the Unix timestamp 10 years from now.
+
+
+
+## ReplaceIPFS
+
+Replaces an IPFS URI with a specified gateway.
+
+```csharp
+var gatewayUri = ipfsUri.ReplaceIPFS("https://ipfs.io/ipfs/");
+```
+
+
+
+### uri
+
+A `string` representing the IPFS URI to replace.
+
+### gateway
+
+A `string` representing the gateway to use. Default is `Constants.FALLBACK_IPFS_GATEWAY`.
+
+
+
+
+
+### gatewayUri
+
+A `string` representing the replaced URI with the specified gateway.
+
+
+
+## ToWei
+
+Converts Ether values to Wei.
+
+```csharp
+var weiValue = ethValue.ToWei();
+```
+
+
+
+### eth
+
+A `string` representing the Ether value to convert.
+
+
+
+
+
+### weiValue
+
+A `string` representing the converted Wei value.
+
+
+
+## ToEth
+
+Converts Wei values to Ether.
+
+```csharp
+var ethValue = weiValue.ToEth();
+```
+
+
+
+### wei
+
+A `string` representing the Wei value to convert.
+
+### decimalsToDisplay
+
+An `int` specifying the number of decimals to display. Default is `4`.
+
+### addCommas
+
+A `bool` indicating whether to add commas to the output. Default is `false`.
+
+
+
+
+
+### ethValue
+
+A `string` representing the converted Ether value.
+
+
+
+## GenerateSIWE
+
+Generates a Sign-In With Ethereum (SIWE) message.
+
+```csharp
+var siweMessage = Utils.GenerateSIWE(loginPayloadData);
+```
+
+
+
+### loginPayloadData
+
+A `LoginPayloadData` object containing the payload data for generating the SIWE message.
+
+
+
+
+
+### siweMessage
+
+A `string` representing the generated SIWE message.
+
+
+
+## IsZkSync
+
+Checks if a given chain ID corresponds to zkSync.
+
+```csharp
+var isZkSync = Utils.IsZkSync(chainId);
+```
+
+
+
+### chainId
+
+A `BigInteger` representing the chain ID to check.
+
+
+
+
+
+### isZkSync
+
+A `bool` indicating whether the chain ID corresponds to zkSync.
+
+
+
+## ToChecksumAddress
+
+Converts an Ethereum address to its checksum format.
+
+```csharp
+var checksummedAddress = address.ToChecksumAddress();
+```
+
+
+
+### address
+
+A `string` representing the Ethereum address to convert.
+
+
+
+
+
+### checksummedAddress
+
+A `string` representing the checksummed Ethereum address.
+
+
+
+## AdjustDecimals
+
+Adjusts the decimal places of a value.
+
+```csharp
+var adjustedValue = value.AdjustDecimals(18, 6);
+```
+
+
+
+### value
+
+A `BigInteger` representing the value to adjust.
+
+### fromDecimals
+
+An `int` specifying the original number of decimals.
+
+### toDecimals
+
+An `int` specifying the target number of decimals.
+
+
+
+
+
+### adjustedValue
+
+A `BigInteger` representing the value adjusted to the new decimals.
+
+
+
+## ToJsonExternalWalletFriendly
+
+Converts typed data into a JSON string suitable for external wallet interaction.
+
+```csharp
+var jsonString = Utils.ToJsonExternalWalletFriendly(typedData, message);
+```
+
+
+
+### typedData
+
+A `TypedData` object representing the typed data to convert.
+
+### message
+
+A `TMessage` object representing the message to include in the JSON.
+
+
+
+
+
+### jsonString
+
+A `string` representing the JSON formatted data.
+
+
diff --git a/apps/portal/src/app/dotnet/wallets/providers/in-app-wallet/page.mdx b/apps/portal/src/app/dotnet/wallets/providers/in-app-wallet/page.mdx
index 367e3e224c0..a3591700e6c 100644
--- a/apps/portal/src/app/dotnet/wallets/providers/in-app-wallet/page.mdx
+++ b/apps/portal/src/app/dotnet/wallets/providers/in-app-wallet/page.mdx
@@ -13,12 +13,48 @@ Create an instance of `InAppWallet` using a user's email, phone number or OAuth.
## Usage
```csharp
-// Email version
+// Email
var wallet = await InAppWallet.Create(client: client, email: "userEmail");
-// Phone number version
+// Phone
var wallet = await InAppWallet.Create(client: client, phoneNumber: "+1234567890");
// Google, Apple, Facebook, etc.
-var wallet = await InAppWallet.Create(client: client, authprovider: AuthProvider.Google);
+var wallet = await InAppWallet.Create(client: client, authProvider: AuthProvider.Google);
+// SIWE
+var wallet = await InAppWallet.Create(client: client, authProvider: AuthProvider.Siwe, siweSigner: anyExternalWallet);
+// Custom Auth - JWT
+var wallet = await InAppWallet.Create(client: client, authProvider: AuthProvider.JWT);
+// Custom Auth - AuthEndpoint
+var wallet = await InAppWallet.Create(client: client, authProvider: AuthProvider.AuthEndpoint);
+
+// Session resuming supported for all methods
+var isConnected = await wallet.IsConnected();
+
+// If not connected, initiate login flow based on the auth provider you are using
+
+// Email & Phone (OTP)
+await wallet.SendOTP(); // and fetch the otp
+var (address, canRetry) = await wallet.LoginWithOtp("userEnteredOTP");
+
+// Socials (OAuth)
+var address = await wallet.LoginWithOauth(
+ // Windows console app example, adaptable to any runtime
+ isMobile: false,
+ browserOpenAction: (url) =>
+ {
+ var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
+ _ = Process.Start(psi);
+ },
+ mobileRedirectScheme: "myBundleId://"
+);
+
+// SIWE (Wallet)
+var address = await siweWallet.LoginWithSiwe(chainId: 1);
+
+// Custom Auth (JWT)
+var address = await wallet.LoginWithCustomAuth(jwt: "myjwt", encryptionkey: "myencryptionkey");
+
+// Custom Auth (AuthEndpoint)
+var address = await wallet.LoginWithAuthEndpoint(payload: "mypayload", encryptionkey: "myencryptionkey");
```
@@ -38,7 +74,7 @@ The user's email address. Required if `phoneNumber` is not provided.
The user's phone number. Required if `email` is not provided.
-### authprovider (optional)
+### authProvider (optional)
The OAuth provider to use for authentication. Supported values are `AuthProvider.Google`, `AuthProvider.Apple`, `AuthProvider.Facebook`.
@@ -66,10 +102,10 @@ The OTP authentication flow involves sending an OTP to the user's email or phone
await wallet.SendOTP();
```
-**Submit OTP:** Once the user receives the OTP, they submit it back to the application, which then calls SubmitOTP on the InAppWallet instance to verify the OTP and complete the login process.
+**Submit OTP:** Once the user receives the OTP, they submit it back to the application, which then calls LoginWithOtp on the InAppWallet instance to verify the OTP and complete the login process.
```csharp
-var (address, canRetry) = await wallet.SubmitOTP("userEnteredOTP");
+var (address, canRetry) = await wallet.LoginWithOtp("userEnteredOTP");
if (address != null) {
// Login successful
} else if (canRetry) {
@@ -91,12 +127,12 @@ if (!await inAppWallet.IsConnected())
await inAppWallet.SendOTP();
Console.WriteLine("Please submit the OTP.");
var otp = Console.ReadLine();
- (var inAppWalletAddress, var canRetry) = await inAppWallet.SubmitOTP(otp);
+ (var inAppWalletAddress, var canRetry) = await inAppWallet.LoginWithOtp(otp);
if (inAppWalletAddress == null && canRetry)
{
Console.WriteLine("Please submit the OTP again.");
otp = Console.ReadLine();
- (inAppWalletAddress, _) = await inAppWallet.SubmitOTP(otp);
+ (inAppWalletAddress, _) = await inAppWallet.LoginWithOtp(otp);
}
if (inAppWalletAddress == null)
{
@@ -175,7 +211,7 @@ Here's an example of creating an `InAppWallet` using OAuth.
```csharp
// Create InAppWallet wallet as signer to unlock web2 auth
-var inAppWallet = await InAppWallet.Create(client: client, authprovider: AuthProvider.Google);
+var inAppWallet = await InAppWallet.Create(client: client, authProvider: AuthProvider.Google);
// Resume session (if `InAppWallet` wallet was not logged in)
if (!await inAppWallet.IsConnected())
@@ -198,3 +234,45 @@ if (!await inAppWallet.IsConnected())
```
**Note:** The `LoginWithOauth` API allows for custom browser handling, making it suitable for various application types and platforms.
+
+## Unified Identity - Account Linking
+
+InAppWallet supports linking multiple authentication methods to a single user account. This feature enables users to access their account using different authentication methods, such as email, phone, or OAuth, without creating separate accounts for each method.
+
+### Linking Accounts
+
+```csharp
+var inAppWalletMain = await InAppWallet.Create(client: client, authProvider: AuthProvider.Google);
+if (!await inAppWalletMain.IsConnected())
+{
+ _ = await inAppWalletMain.LoginWithOauth(
+ isMobile: false,
+ (url) =>
+ {
+ var psi = new ProcessStartInfo { FileName = url, UseShellExecute = true };
+ _ = Process.Start(psi);
+ },
+ "thirdweb://",
+ new InAppWalletBrowser()
+ );
+}
+Console.WriteLine($"Main InAppWallet address: {await inAppWalletMain.GetAddress()}");
+
+// Prepare Telegram
+var socialWallet = await InAppWallet.Create(client: client, authProvider: AuthProvider.Telegram);
+// Link Telegram
+_ = await inAppWalletMain.LinkAccount(walletToLink: socialWallet,);
+
+// Prepare Phone
+var phoneWallet = await InAppWallet.Create(client: client, phoneNumber: "+1234567890");
+_ = await phoneWallet.SendOTP();
+var otp = Console.ReadLine();
+// Link Phone
+_ = await inAppWalletMain.LinkAccount(walletToLink: phoneWallet, otp: otp);
+```
+
+### Getting Linked Accounts
+
+```csharp
+List linkedAccounts = await inAppWalletMain.GetLinkedAccounts();
+```
diff --git a/apps/portal/src/app/unity/v5/contracts/page.mdx b/apps/portal/src/app/unity/v5/contracts/page.mdx
index 18b01c3f7b9..587165ea5c7 100644
--- a/apps/portal/src/app/unity/v5/contracts/page.mdx
+++ b/apps/portal/src/app/unity/v5/contracts/page.mdx
@@ -14,7 +14,11 @@ export const metadata = createMetadata({
### Instantiating a ThirdwebContract
```csharp
-var contract = await ThirdwebManager.Instance.GetContract(address: "contract-address", chainId: 1, abi: "optional-abi");
+var contract = await ThirdwebManager.Instance.GetContract(
+ address: "contract-address",
+ chainId: 1,
+ abi: "optional-abi"
+);
```
That's it! You can now interact with the contract using the `ThirdwebContract`.
diff --git a/apps/portal/src/app/unity/v5/thirdwebmanager/page.mdx b/apps/portal/src/app/unity/v5/thirdwebmanager/page.mdx
index 8c8640d0a87..f91346b2dcb 100644
--- a/apps/portal/src/app/unity/v5/thirdwebmanager/page.mdx
+++ b/apps/portal/src/app/unity/v5/thirdwebmanager/page.mdx
@@ -69,9 +69,9 @@ The `InAppWalletModal` prefab is a simple and customizable OTP verification moda
It will be automatically activated when connecting to an `InAppWallet` provider.
-### WalletConnectWallet
+### WalletConnectModal
-The `WalletConnectWallet` prefab is an out-of-the-box WalletConnect modal that can be used to connect to 400+ wallets.
+The `WalletConnectModal` prefab is an out-of-the-box WalletConnect modal that can be used to connect to 400+ wallets.
It will be automatically activated when connecting to a `WalletConnect` provider.
diff --git a/apps/portal/src/app/unity/v5/wallets/in-app-wallet/page.mdx b/apps/portal/src/app/unity/v5/wallets/in-app-wallet/page.mdx
index 17881597f85..e830aa8058e 100644
--- a/apps/portal/src/app/unity/v5/wallets/in-app-wallet/page.mdx
+++ b/apps/portal/src/app/unity/v5/wallets/in-app-wallet/page.mdx
@@ -13,6 +13,16 @@ export const metadata = createMetadata({
It makes for a fantastic [SmartWallet](/unity/wallets/account-abstraction) admin/signer and will make sure your users can have the same wallet address across all your games, apps and blockchains.
+## Login Methods
+
+In-App Wallets support a variety of login methods:
+- Email (OTP Login)
+- Phone (OTP Login)
+- Socials (Google, Apple, Facebook, Telegram, Farcaster, etc.)
+- SIWE (Sign-In with Ethereum)
+- Custom Auth (OIDC Compatible)
+- Custom Auth (Generic Auth Endpoint)
+
### Login with Email
```csharp
@@ -55,6 +65,65 @@ var wallet = await ThirdwebManager.Instance.ConnectWallet(options);
Will open a native browser or oauth session to authenticate the user and redirect back to the game.
+### Login with SIWE
+
+```csharp
+var inAppWalletOptions = new InAppWalletOptions(authprovider: AuthProvider.Siwe, siweSigner: anyExternalWallet);
+var options = new WalletOptions(
+ provider: WalletProvider.InAppWallet,
+ chainId: 1,
+ inAppWalletOptions: inAppWalletOptions
+);
+var wallet = await ThirdwebManager.Instance.ConnectWallet(options);
+```
+
+Will use the external wallet to sign a message and login to the InAppWallet.
+
+### Login with Custom Auth - OIDC Compatible
+
+```csharp
+var inAppWalletOptions = new InAppWalletOptions(authprovider: AuthProvider.JWT, jwtOrPayload: "myjwt", encryptionKey: "myencryptionkey");
+var options = new WalletOptions(
+ provider: WalletProvider.InAppWallet,
+ chainId: 1,
+ inAppWalletOptions: inAppWalletOptions
+);
+var wallet = await ThirdwebManager.Instance.ConnectWallet(options);
+```
+
+### Login with Custom Auth - Generic Auth Endpoint
+
+```csharp
+var inAppWalletOptions = new InAppWalletOptions(authprovider: AuthProvider.AuthEndpoint, jwtOrPayload: "mypayload", encryptionKey: "myencryptionkey");
+var options = new WalletOptions(
+ provider: WalletProvider.InAppWallet,
+ chainId: 1,
+ inAppWalletOptions: inAppWalletOptions
+);
+var wallet = await ThirdwebManager.Instance.ConnectWallet(options);
+```
+
+## Account Linking
+
+InAppWallets support linking multiple authentication methods to a single wallet, for instance linking Google to your Email-based In-App-Wallet. This is useful to have a unified identity across platforms.
+
+```csharp
+// Your main InAppWallet account, already authenticated and connected
+InAppWallet mainInAppWallet = ...
+
+// An InAppWallet with a new auth provider to be linked to the main account, not connected
+InAppWallet walletToLink = await InAppWallet.Create(client: Client, authProvider: AuthProvider.Telegram);
+
+// Link Account - Headless version
+var linkedAccounts = await mainInAppWallet.LinkAccount(walletToLink: walletToLink);
+
+// Link Account - Unity wrapper version
+var linkedAccounts = await ThirdwebManager.Instance.LinkAccount(mainInAppWallet, walletToLink);
+
+// You can also fetch linked accounts at any time
+List linkedAccounts = await mainInAppWallet.GetLinkedAccounts();
+```
+