Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

Wombat

Swift 5 Objective-C

WombatAuth

iOS client SDK for DApps.

Supported Actions

  1. Authorize: Request the account details
  2. Transfer: Request a transfer of funds
  3. Push: Push a transaction
  4. Sign: Request a signature

Installation

You might encounter a problem while submitting your app to the App Store. This is due to a bug in the App Store itself. You can solve it by creating a new Run Script Phase, after the Embed Frameworks phase, in your app’s target’s Build Phases, and copying the script available here.

Add the following 2 snippets into your Info.plist.

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <!-- URL scheme to use when returning from Wombat to your app -->
            <string>wombat.$(PRODUCT_BUNDLE_IDENTIFIER)</string>
        </array>
    </dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
    <!-- URL scheme to use when launching Wombat from your app -->
    <string>wombat</string>
</array>

Cocoapods

Add the following line to your Podfile and run pod install.

pod 'WombatAuth'

Manual

  1. Download the latest version of the framework here.
  2. Add WombatAuth.framework into your Embedded Binaries.
If your project is written in Objective-C
  1. In project's Build Settings set Always Embed Swift Standard Libraries to YES.
  2. Import the library by adding #import <WombatAuth/WombatAuth-Swift.h>.

Usage

Register your app

Make sure your app is registered prior to executing any requests. You can optionally also specify chainID. If omitted, the wallet will use the EOS blockchain as default.

import WombatAuth

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        WombatAuth.shared.registerApp(name: "App's Name", icon: appsIconURL)
        return true
    }
}

Response handler

In order to receive results you need to register an url handler in the AppDelegate:application(_:open:options:).

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
    return WombatAuth.shared.application(open: url) { result in
        switch result {
        case .success(let action, let data):
            switch action {
            case .authorize:
                print(data["accountName"])
                print(data["publicKey"])
            case .pushTransaction:
                print(data["transactionID"])
            case .signData:
                print(data["signature"])
           case .transfer:
               print(data["transactionID"])
           }
       case .error(let action, let error):
           switch error {
           case .unknown(let errorMessage):
               print(errorMessage)
           default:
               break
           }
       case .userCancelled(let action):
           break
       }
    }
}
Objective-C
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    return [WombatAuth.shared openURL:url completionHandler:^(WMResultObj *result) {
        NSString *message = result.message; // "success" or an error message
        NSDictionary *data = result.data; // NSDictionary<NSString *,id>

        switch (result.type) {
            case WMResultTypeSuccess:
                switch (result.action) {
                    case WMActionTypeAuthorize:
                        // data[@"accountName"] - NSString
                        // data[@"publicKey"] - NSString
                        break;
                    case WMActionTypePushTransaction:
                        // data[@"transactionID"] - NSString
                        break;
                    case WMActionTypeSignData:
                        // data[@"signature"] - NSString
                        break;
                    case WMActionTypeTransfer:
                        // data[@"transactionID"] - NSString
                        break;
                    case WMActionTypeUnknown:
                        break;
                }
            case WMResultTypeError:
                break;
            case WMResultTypeUserCancelled:
                break;
        }
    }];
}

Actions

Authorize

WombatAuth.shared.requestAuthorization()

Transfer

let transfer = WMTransfer(
    from: "account_name",
    to: "account_name_2",
    amount: 1,
    precision: 4,
    contract: "eosio.token",
    symbol: "EOS",
    memo: "Some memo"
)

WombatAuth.shared.requestTransfer(transfer)

Push

let transaction = WMTransaction(
    from: "account_name",
    actions: [
        .init(
            account: "eosio.token",
            name: "transfer",
            auth: [.init(actor: "account_name", permission: "owner")],
            data: [
                "from": "account_name",
                "to": "account_name_2",
                "quantity": "1.0000 EOS",
                "memo": "Here you go"
            ]
        )
    ]
)

WombatAuth.shared.pushTransaction(transaction)

Sign

WombatAuth.shared.requestSignature(account: "account_name", data: "Some data")