Skip to content

With the Stellar Swift Wallet SDK, building an iOS Stellar-enabled wallet or application is faster and easier than ever.

License

Notifications You must be signed in to change notification settings

Soneso/stellar-swift-wallet-sdk

Repository files navigation

logo

The Stellar Swift Wallet SDK is a library that allows developers to build wallet applications on the Stellar Network faster. It utilizes the classic iOS Stellar SDK to communicate with Stellar Horizon and Anchors.

Installation

Copy the link of the repository (https://github.com/Soneso/stellar-swift-wallet-sdk) and then go to your Xcode project -> right click on your project name -> Add Package Dependencies … Paste the repository link on the Search, choose the package than click on Add Package button. A new screen will shows up, just click Add Package button again. Two new Package dependencies will appear: stellar-wallet-sdk and stellarsdk. The Wallet SDK uses the base iOS Stellar SDK.

After installation add following import statement to your swift file:

import stellar_wallet_sdk

Functionality

The Wallet SDK provides an easy way to communicate with Anchors. It supports:

Furthermore the wallet SDK provides extra functionality on top of the classic iOS Stellar SDK. For interaction with the Stellar Network, the Swift Wallet SDK covers the basics used in a typical wallet flow.

Getting Started

Working with the SDK

Let's start with the main class that provides all SDK functionality. It's advised to have a singleton wallet object shared across the application. Creating a wallet with a default configuration connected to Stellar's Testnet is simple:

let wallet = Wallet.testNet

The wallet instance can be further configured. For example, to connect to the public network:

let wallet = Wallet(stellarConfig: StellarConfig.publicNet)

If you want to find out more about wallet configuration, you can read the details in the documentation under Wallet Configuration.

Stellar Basics

The wallet SDK provides extra functionality on top of the existing Horizon SDK. For interaction with the Stellar network, the wallet SDK covers only the basics used in a typical wallet flow. For more advanced use cases, the underlying Horizon SDK should be used instead.

To interact with the Horizon instance configured in the previous steps, simply do:

let stellar = wallet.stellar

Classic iOS Stellar SDK

The classic Stellar iOS SDK is included as a dependency in the Swift Wallet SDK.

It's very simple to use the iOS Stellar Stellar SDK connecting to the same Horizon instance as a Wallet class. To do so, simply call:

let stellar = wallet.stellar
let server = stellar.server
let responseEnum = try await server.transactions.getTransactions(forAccount: accountId)

But you can also import and use it for example like this:

import stellarsdk

let sdk = StellarSDK.testNet()

let accountId = "GASYKQXV47TPTB6HKXWZNB6IRVPMTQ6M6B27IM5L2LYMNYBX2O53YJAL"
let responseEnum = try await sdk.transactions.getTransactions(forAccount: accountId)

Anchor Basics

Primary use of the Swift Wallet SDK is to provide an easy way to connect to anchors via sets of protocols known as SEPs.

Let's look into connecting to the Stellar test anchor:

let anchor = wallet.anchor(homeDomain: "testanchor.stellar.org")

And the most basic interaction of fetching a SEP-001: Stellar Info File:

let anchorInfo = try await anchor.info

The anchor class also supports SEP-010: Stellar Authentication, SEP-024: Hosted Deposit and Withdrawal features, SEP-012: KYC API and SEP-009: Standard KYC Fields.

You can read more about working with Anchors in the respective doc section.

Recovery

SEP-030 defines the standard way for an individual (e.g., a user or wallet) to regain access to their Stellar account after losing its private key without providing any third party control of the account. During this flow the wallet communicates with one or more recovery signer servers to register the wallet for a later recovery if it's needed.

You can read more about working with Recovery Servers in the respective doc section.

Quotes

SEP-038 defines a way for anchors to provide quotes for the exchange of an off-chain asset and a different on-chain asset, and vice versa.

You can read more about requesting quotes in the respective doc section.

Programmatic Deposit and Withdrawal

The SEP-06 standard defines a way for anchors and wallets to interact on behalf of users. Wallets use this standard to facilitate exchanges between on-chain assets (such as stablecoins) and off-chain assets (such as fiat, or other network assets such as BTC).

You can read more about programmatic deposit and withdrawal in the respective doc section.

URI Scheme to facilitate delegated signing

The SEP-07 standard defines a way for a non-wallet application to construct a URI scheme that represents a specific transaction for an account to sign. The scheme used is web+stellar, followed by a colon. Example: web+stellar:<operation>?<param1>=<value1>&<param2>=<value2>

You can read more about the SDK's SEP-7 support in the respective doc section.

Documentation and Test Cases

Documentation can be found in the docs folder.

We also recommend that you consult the code examples from the test cases, e.g. in the Stellar Tests of the SDK.

About

With the Stellar Swift Wallet SDK, building an iOS Stellar-enabled wallet or application is faster and easier than ever.

Resources

License

Stars

Watchers

Forks

Packages

No packages published