Git Product home page Git Product logo

beacon-ios-sdk's Introduction

Beacon iOS SDK

release

Connect Wallets with dApps on Tezos

Beacon is an implementation of the wallet interaction standard tzip-10 which describes the connection of a dApp with a wallet.

About

The Beacon iOS SDK provides iOS developers with tools useful for setting up communication between native wallets supporting Tezos and dApps that implement beacon-sdk.

Installation

See the below guides to learn how to add Beacon into your project.

SPM

To add Beacon iOS SDK with the Swift Package Manager, add the Beacon iOS SDK package dependency:

Xcode

Open the Add Package Dependency window (as described in the official guide) and enter the Beacon iOS SDK GitHub repository URL:

https://github.com/airgap-it/beacon-ios-sdk

Package.swift file

Add the following dependency in your Package.swift file:

.package(url: "https://github.com/airgap-it/beacon-ios-sdk", from: "3.0.0")

Project Overview

The project is divided into the following targets:

  • BeaconCore - common and base code for other targets
  • BeaconClientWallet - the Beacon implementation for wallets
  • BeaconBlockchainTezos - a set of messages, utility functions and other components specific for Tezos
  • BeaconBlockchainSubstrate - a set of messages, utility functions and other components specific for Substrate
  • BeaconTransportP2PMatrix - Beacon P2P implementation which uses Matrix network for the communication
  • BeaconSDKDemo - an example application

Examples

The snippets below show how to quickly setup listening for incoming Beacon messages.

For more examples please see our demo app (WIP).

Create a Beacon client and listen for incoming messages

import BeaconCore
import BeaconBlockchainSubstrate
import BeaconBlockchainTezos
import BeaconClientWallet
import BeaconTransportP2PMatrix

class BeaconController {
    private var client: Beacon.WalletClient?
    
    ...
    
    func startBeacon() {
        Beacon.WalletClient.create(
            with: Beacon.Client.Configuration(
                name: "My App",
                blockchains: [Tezos.factory, Substrate.factory],
                connections: [.p2p(.init(client: try Transport.P2P.Matrix.factory()))]
            )
        ) { result in
            switch result {
            case let .success(client):
                self.client = client
                self.listenForBeaconMessages()
            case let .failure(error):
                /* handle error */
            }
        }
    }
    
    func listenForBeaconMessages() {
        client?.connect { result in
            switch result {
            case .success(_):
                self.client?.listen { request in 
                    /* process messages */ 
                }
            case let .failure(error):
                /* handle error */
            }
        }
    }
}

Migration

See the below guides to learn how to migrate your existing code to new Beacon iOS SDK versions.

From <v3.0.0

As of v3.0.0, Beacon iOS SDK has been further split into new packages and has become more generic in terms of supported blockchains and transports. This means that in some parts the values that had been previously set by default now must be configured manually or that various structures have changed their location or definition. To make sure your existing Beacon integration will be set up the same way as it used to be before v3.0.0 do the following:

  1. Replace the old Beacon.Client with the new Beacon.WalletClient (BeaocnClientWallet) and configure it with Tezos blockchain (BeaconBlockchainTezos) and Transport.P2P.Matrix transport (BeaconTransportP2PMatrix).
import BeaconCore
import BeaconBlockchainTezos
import BeaconClientWallet
import BeaconTransportP2PMatrix

/* <v3.0.0: Beacon.Client.create(with: Beacon.Client.Configuration(name: "My App")) { ... } */
Beacon.WalletClient.create(
    with: Beacon.Client.Configuration(
        name: "My App",
        blockchains: [Tezos.factory],
        connections: [.p2p(.init(client: try Transport.P2P.Matrix.factory()))]
    )
) { /* ... */ }
  1. Adjust the message handling code.
/* <v3.0.0:
 * beaconClient.listen { result in
 *     switch result {
 *     case let .success(beaconRequest):
 *         switch beaconRequest {
 *         case let .permission(permission):
 *             ...
 *         case let .operation(operation):
 *             ...
 *         case let .signPayload(signPayload):
 *             ...
 *         case let .broadcast(broadcast):
 *             ...
 *         }
 *    ...
 *    }
 * }
 */

beaconClient.listen { (result: Result<BeaconRequest<Tezos>, Beacon.Error>) in
    switch result {
    case let .success(beaconRequest):
        switch beaconRequest {
        case let .permission(content):
            /* ... */
        case let .blockchain(blockchain):
            switch blockchain {
            case let .operation(operation):
                /* ... */
            case let .signPayload(signPayload):
                /* ... */
            case let .broadcast(broadcast):
                /* ... */
            }
        }
    }
    /* ... */
}
/* <v3.0.0
 * let response = Beacon.Response.Operation(from: operationRequest, transactionHash: transactionHash)
 * beaconClient.respond(with: .operation(response)) { ... }
 */

let response = OperationTezosResponse(
    from: operationRequest, //: OperationTezosRequest 
    transactionHash: transactionHash
)
beaconClient.respond(
    with: BeaconResponse<Tezos>.blockchain(
        .operation(response)
    )
) { /* ... */ }
/* let errorResponse = Beacon.Response.Error(from: broadcastRequest, errorType: .broadcastError)
 * beaconClient.respond(with: BeaconResponse<Tezos>.error(errorResponse)) { ... }
 */
 
let errorResponse = ErrorBeaconResponse<Tezos>(from: broadcastRequest, errorType: .blockchain(.broadcastError))
beaconClient.respond(with: BeaconResponse<Tezos>.error(errorResponse)) { /* ... */ }

Related Projects

Beacon SDK - an SDK for web developers (dApp & wallet)

Beacon Android SDK - an SDK for Android developers (wallet)

beacon-ios-sdk's People

Contributors

godenzim avatar jsamol avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.