Swiftpack.co - airgap-it/beacon-ios-sdk as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
airgap-it/beacon-ios-sdk 3.0.0
The beacon sdk allows iOS developers of dApps and wallets on Tezos to implement the wallet interaction standard tzip-10.
⭐️ 4
🕓 1 week ago
iOS
.package(url: "https://github.com/airgap-it/beacon-ios-sdk.git", from: "3.0.0")

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 wallet implementation of Beacon
  • BeaconBlockchainTezos - a seto of messages, utility functions and other components specific for Tezos
  • 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 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],
                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)

GitHub

link
Stars: 4
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Related Packages

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics