Skip to content
LogoLogo

External Wallet Authentication

Connect wallets via the Sign in With Ethereum (SIWE) standard. This authentication method is designed for users who prefer to authenticate using their external wallets. Openfort's Unity integration facilitates a secure and direct authentication process using these wallets.

Initialize SIWE authentication

To start the SIWE (Sign in With Ethereum) process:

Usage

func InitializeSIWE(string walletAddress) async
{
    do
    {
        let result = try await OFSDK.shared.initSIWE(params: OFInitSIWEParams(address: walletAddress));
        print("SIWE initialization successful");
    }
    catch
    {
        print("Error initializing SIWE: \(error.localizedDescription)");
    }
}

Getting signature

func signMessage(_ message: String) async throws -> String {
    let result = try await OFSDK.shared.signMessage(params: OFSignMessageParams(message: message))
    return result ?? ""
}

Verify SIWE signature

After getting the signature from the wallet, verify it to authenticate the user:

struct WalletConnectorInfo: Identifiable {
    let id: String
    let name: String
    let iconName: String
    let type: WalletConnector
}

enum WalletConnector: String, CaseIterable, Identifiable {
    case metaMask, coinbase, walletConnect
    var id: String { rawValue }
}

func authenticateOrLink(signature: String, message: String, wallet: WalletConnectorInfo) async throws {
        let response = try await OFSDK.shared.authenticateWithSIWE(params: OFAuthenticateWithSIWEParams(signature: signature, message: message, walletClientType: wallet.name, connectorType: wallet.type.rawValue))
    }
}

Parameters

struct OFAuthenticateWithSIWEParams: OFCodableSendable {
    public let signature: String
    public let message: String
    public let walletClientType: String
    public let connectorType: String
}

Returns

struct OFAuthorizationResponse: OFAuthorizationResponseProtocol, OFCodableSendable {
    public let token: String?
    public let refreshToken: String?
    public let player: OFAuthPlayerResponse?
    public let action: String?
}

Throws

{
    method: method,
    success: false,
    error: error
}