Coder Social home page Coder Social logo

wallet-connect-swift's Introduction

WalletConnect

Codacy Badge CI

WalletConnect Swift SDK, implements 1.0.0 websocket based protocol.

Demo video

Requirements

  • iOS 11
  • Xcode 10.2
  • Swift 5

Features

  • Connect and disconnect
  • Approve / Reject / Kill session
  • Approve and reject eth_sign / personal_sign / eth_signTypedData
  • Approve and reject eth_signTransaction / eth_sendTransaction
  • Approve and reject bnb_sign (binance dex orders)
  • session persistent / recovery

Todo:

  • push notification (APNS)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

WalletConnect is available through CocoaPods, Carthage and Swift Package Manager.

CocoaPods

To install it, simply add the following line to your Podfile:

pod 'WalletConnect', git: 'https://github.com/trustwallet/wallet-connect-swift', branch: 'master'

Carthage

Add following line to your Cartfile:

github "trustwallet/wallet-connect-swift"

Swift Package Manager

Add .package(url:_:) to your Package.swift:

dependencies: [
    .package(url: "https://github.com/trustwallet/wallet-connect-swift", .branch("master")),
],

Usage

parse session from scanned QR code:

let string = "wc:..."
guard let session = WCSession.from(string: string) else {
    // invalid session
    return
}
// handle session

configure and handle incoming message:

let interactor = WCInteractor(session: session, meta: clientMeta)
interactor.onSessionRequest = { [weak self] (id, peer) in
    // ask for user consent
}

interactor.onDisconnect = { [weak self] (error) in
    // handle disconnect
}

interactor.eth.onSign = { [weak self] (id, payload) in
    // handle eth_sign, personal_sign, eth_signTypedData
}

interactor.eth.onTransaction = { [weak self] (id, event, transaction) in
    // handle eth_signTransaction / eth_sendTransaction
}

interactor.bnb.onSign = { [weak self] (id, order) in
    // handle bnb_sign
}

approve session

interactor.approveSession(accounts: accounts, chainId: chainId).done {
    print("<== approveSession done")
}.cauterize()

approve request

interactor.approveRequest(id: id, result: result.hexString).done {
    print("<== approveRequest done")
}.cauterize()

approve binance dex orders

interactor?.approveBnbOrder(id: id, signed: signed).done({ confirm in
    print("<== approveBnbOrder", confirm)
}).cauterize()

Author

hewigovens

License

WalletConnect is available under the MIT license. See the LICENSE file for more info.

wallet-connect-swift's People

Contributors

artemgoryunov avatar daihovey avatar flipfloop avatar hewigovens avatar leoneparise avatar pedrouid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.