To interact with Keeper Wallet in your iOS app, complete the following steps:
For more information on using Swift implementation of WalletConnect, see their docs.
pod repo update
pod init
Add pod to your Podfile:
pod 'WalletConnectSwiftV2'
pod install
.Paste the repo GitHub url:
https://github.com/WalletConnect/WalletConnectSwiftV2
let RELAY_URL = "relay.walletconnect.com"
let PROJECT_ID = "YOUR_PROJECT_ID"
Networking.configure(
relayHost: RELAY_URL,
projectId: PROJECT_ID,
socketFactory: SocketFactory()
)
Describe your app and define its appearance in Keeper Wallet when a user is prompted to connect or sign a transaction/order/message.
let metadata = AppMetadata(name: "YOUR_APP_NAME",
description: "YOUR_APP_DESC",
url: "YOUR_WEBSITE",
icons: ["YOUR_IMAGE_URLS"]
)
Pair.configure(metadata: metadata)
Send a request to WalletConnect to get a pairing URI for Keeper Wallet.
let methods: Set<String> = [
"waves_signTransaction",
"waves_signTransactionPackage",
"waves_signOrder",
"waves_signMessage",
"waves_signTypedData"
]
// Set the chain ID: 'W' for Mainnet or 'T' for Testnet
let blockchains: Set<Blockchain> = [Blockchain("waves:T")!]
let namespaces: [String: ProposalNamespace] = [
"waves": ProposalNamespace(chains: blockchains, methods: methods, events: [])
]
let uri = try! await Pair.instance.create()
try! await Sign.instance.connect(
requiredNamespaces: namespaces,
topic: uri.topic
)
Here’s how it works:
To call Keeper Wallet, use the universal link. For the callback, a universal link or a custom URL scheme must be defined for your app.
let callback = "YOUR_LINK_OR_SCHEME"
var params: [String] = [];
let urlEncode = uri.absoluteString.addingPercentEncoding(withAllowedCharacters: .alphanumerics)
params.append("wcurl=\(urlEncode!)")
params.append("callback=\(callback)")
let query = params.joined(separator: "&")
let url = URL(string: "https://link.keeper-wallet.app/auth?\(query)")
UIApplication.shared.open(url)
The result of connecting comes to the listener:
Sign.instance.sessionSettlePublisher
.receive(on: DispatchQueue.main)
.sink { [unowned self] (session: Session) in
// Result handler
// print(session) to display the result in the console
}.store(in: &publishers)
Here is how it works:
Example:
let method = "waves_signTransaction"
let invokeJson = { YOUR_TX_PARAMS }
let requestParams = AnyCodable([invokeJson])
let request = Request(topic: currentSession!.topic, method: method, params: requestParams, chainId: blockchains.first!)
try! await Sign.instance.request(params: request)
let method = "waves_signOrder"
let orderJson = { YOUR_ORDER_PARAMS }
let requestParams = AnyCodable([orderJson])
let request = Request(topic: currentSession!.topic, method: method, params: requestParams, chainId: blockchains.first!)
try! await Sign.instance.request(params: request)
let method = "waves_signMessage"
let message = "YOUR_MESSAGE"
let requestParams = AnyCodable([message])
let request = Request(topic: currentSession!.topic, method: method, params: requestParams, chainId: blockchains.first!)
try! await Sign.instance.request(params: request)
Specify topic
and callback
in the request.
let callback = "YOUR_LINK_OR_SCHEME"
var params: [String] = [];
params.append("topic=\(topic)")
params.append("callback=\(callback)")
let query = params.joined(separator: "&")
let url = URL(string: "https://link.keeper-wallet.app/wakeup?\(query)")
UIApplication.shared.open(url)
The result of signing the request comes to the listener:
Sign.instance.sessionResponsePublisher
.receive(on: DispatchQueue.main)
.sink { [unowned self] (response: Response) in
// Result handler
// print(response) to display the result in the console
}.store(in: &publishers)