-
Notifications
You must be signed in to change notification settings - Fork 0
/
EosioSignatureProviderProtocol.swift
113 lines (98 loc) · 4.96 KB
/
EosioSignatureProviderProtocol.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// EosioSignatureProviderProtocol.swift
// EosioSwift
// Created by Todd Bowden on 7/15/18.
// Copyright (c) 2017-2019 block.one and its contributors. All rights reserved.
//
import Foundation
/// The transaction and related information structure sent to a signature provider for signing.
public struct EosioTransactionSignatureRequest: Codable {
/// The serialized transaction as `Data`.
public var serializedTransaction = Data()
/// Serialized context free data
public var serializedContextFreeData = Data()
/// The chain ID as a `String`.
public var chainId = ""
/// An array of public keys identifying the private keys with which the transaction should be signed.
public var publicKeys = [String]()
/// An array of `BinaryAbi`s sent along so that signature providers can display transaction information to the user.
public var abis = [BinaryAbi]()
/// Should the signature provider be allowed to modify the transaction? E.g., adding an assert action. Defaults to `true`.
public var isModificationAllowed = true
/// The structure for `BinaryAbi`s.
public struct BinaryAbi: Codable {
/// The account name for the contract, as a `String`.
public var accountName = ""
/// The binary representation of the ABI as a `String`.
public var abi = ""
/// Initializer for the `BinaryAbi`.
public init() { }
}
/// Initializer for the `EosioTransactionSignatureRequest`.
public init() { }
}
/// The structure for the response from a signature provider to an `EosioTransactionSignatureRequest`.
public struct EosioTransactionSignatureResponse: Codable {
/// The signed transaction, as a `SignedTransaction`.
public var signedTransaction: SignedTransaction?
/// An optional error.
public var error: EosioError?
/// The structure for a `SignedTransaction`.
public struct SignedTransaction: Codable {
/// The serialized transaction, as `Data`. This may be different from the transaction requested if the transaction was modified by the signature provider.
public var serializedTransaction = Data()
/// Serialized context free data. This may be different from the transaction requested if the context free data was modified by the signature provider.
public var serializedContextFreeData = Data()
/// An array of signatures as `String`s.
public var signatures = [String]()
/// Initializer for the `SignedTransaction`.
public init() { }
}
/// Initializer for the `EosioTransactionSignatureResponse`.
public init() { }
/// Initializer for the `EosioTransactionSignatureResponse` when it contains an error.
///
/// - Parameter error: The error as an `EosioError`.
public init(error: EosioError) {
self.error = error
}
}
/// The structure for the response from a signature provider when asked what keys are available for signing.
public struct EosioAvailableKeysResponse: Codable {
/// The keys as `String`s.
public var keys: [String]?
/// An optional error.
public var error: EosioError?
/// Initializer for the `EosioAvailableKeysResponse`.
public init() { }
}
/// The protocol to which signature provider implementations must conform.
public protocol EosioSignatureProviderProtocol {
/// The method signature for transaction signing requests to conforming signature providers.
///
/// - Parameters:
/// - request: The request as an `EosioTransactionSignatureRequest`.
/// - completion: The completion that the signature provider implementation will call in response.
func signTransaction(request: EosioTransactionSignatureRequest, completion: @escaping (EosioTransactionSignatureResponse) -> Void)
/// The method signature for transaction signing requests to conforming signature providers while specifying
/// a prompt to use for biometric validation if desired.
///
/// - Parameters:
/// - request: The request as an `EosioTransactionSignatureRequest`.
/// - prompt: Prompt for biometric authentication, if required.
/// - completion: The completion that the signature provider implementation will call in response.
func signTransaction(request: EosioTransactionSignatureRequest,
prompt: String,
completion: @escaping (EosioTransactionSignatureResponse) -> Void)
/// The method signature for public key requests to conforming signature providers.
///
/// - Parameter completion: The method signature for key requests to conforming signature providers.
func getAvailableKeys(completion: @escaping (EosioAvailableKeysResponse) -> Void)
}
public extension EosioSignatureProviderProtocol {
func signTransaction(request: EosioTransactionSignatureRequest,
prompt: String,
completion: @escaping (EosioTransactionSignatureResponse) -> Void) {
self.signTransaction(request: request, completion: completion)
}
}