Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/frol/near-connect-ios/llms.txt

Use this file to discover all available pages before exploring further.

MessageSignResult contains the signed message data returned by the wallet after successfully signing an off-chain message using the NEP-413 standard.

Properties

accountId
String?
required
The NEAR account ID that signed the message. This identifies which account’s key was used for signing.
publicKey
String?
required
The public key used to sign the message. This can be used to verify the signature.
signature
String?
required
The signature string in JSON format containing the signed message payload according to NEP-413. This includes the message, recipient, nonce, and cryptographic signature.

Usage

MessageSignResult is returned by:
  • signMessage(message:recipient:nonce:)
  • Optionally included in SignInWithMessageResult from connectAndSignMessage(message:recipient:nonce:)

Example: Signing a Message

do {
    let result = try await walletManager.signMessage(
        message: "Welcome to my dApp!",
        recipient: "myapp.testnet",
        nonce: nil // Auto-generated if nil
    )
    
    if let accountId = result.accountId {
        print("Message signed by: \(accountId)")
    }
    
    if let signature = result.signature {
        print("Signature: \(signature)")
        // Send signature to your backend for verification
    }
} catch {
    print("Message signing failed: \(error)")
}

Example: Verifying Authentication

func authenticateUser() async {
    do {
        let nonce = Data(repeating: 0, count: 32) // Use a unique nonce
        let result = try await walletManager.signMessage(
            message: "Sign in to MyApp",
            recipient: "myapp.testnet",
            nonce: nonce
        )
        
        guard let signature = result.signature,
              let accountId = result.accountId else {
            print("Missing signature data")
            return
        }
        
        // Send to backend for verification
        try await verifySignature(
            accountId: accountId,
            signature: signature,
            nonce: nonce
        )
        
        print("User authenticated successfully!")
    } catch {
        print("Authentication failed: \(error)")
    }
}

Notes

  • All properties are optional because different wallets may return different levels of detail
  • The signature field is a JSON string following the NEP-413 message signing standard
  • The signature can be verified on your backend to authenticate users without blockchain transactions
  • Use a unique nonce for each signing request to prevent replay attacks
  • Message signing is gas-free since it doesn’t interact with the blockchain

Build docs developers (and LLMs) love