Skip to content

Commit

Permalink
Merge pull request #352 from nova-wallet/develop
Browse files Browse the repository at this point in the history
v3.5.0
  • Loading branch information
ERussel committed Aug 12, 2022
2 parents 4eb9bb8 + 86bc4c9 commit 4848266
Show file tree
Hide file tree
Showing 241 changed files with 5,592 additions and 1,541 deletions.
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ platform :ios, '13.0'
abstract_target 'novawalletAll' do
use_frameworks!

pod 'SubstrateSdk', :git => 'https://github.com/nova-wallet/substrate-sdk-ios.git', :tag => '1.2.0'
pod 'SubstrateSdk', :git => 'https://github.com/nova-wallet/substrate-sdk-ios.git', :tag => '1.3.0'
pod 'SwiftLint'
pod 'R.swift', :inhibit_warnings => true
pod 'SoraKeystore', '~> 1.0.0'
Expand All @@ -26,7 +26,7 @@ abstract_target 'novawalletAll' do
inherit! :search_paths

pod 'Cuckoo'
pod 'SubstrateSdk', :git => 'https://github.com/nova-wallet/substrate-sdk-ios.git', :tag => '1.2.0'
pod 'SubstrateSdk', :git => 'https://github.com/nova-wallet/substrate-sdk-ios.git', :tag => '1.3.0'
pod 'SoraFoundation', '~> 1.0.0'
pod 'R.swift', :inhibit_warnings => true
pod 'FireMock', :inhibit_warnings => true
Expand Down
12 changes: 6 additions & 6 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ PODS:
- SoraUI/Skrull (1.11.1)
- Sourcery (1.4.1)
- Starscream (4.0.5)
- SubstrateSdk (1.2.0):
- SubstrateSdk (1.3.0):
- BigInt (~> 5.0)
- IrohaCrypto/ed25519 (~> 0.9.0)
- IrohaCrypto/Scrypt (~> 0.9.0)
Expand Down Expand Up @@ -137,7 +137,7 @@ DEPENDENCIES:
- SoraUI (from `https://github.com/ERussel/UIkit-iOS.git`, tag `1.11.1`)
- Sourcery (~> 1.4)
- Starscream (from `https://github.com/ERussel/Starscream.git`, tag `4.0.5`)
- SubstrateSdk (from `https://github.com/nova-wallet/substrate-sdk-ios.git`, tag `1.2.0`)
- SubstrateSdk (from `https://github.com/nova-wallet/substrate-sdk-ios.git`, tag `1.3.0`)
- SVGKit (from `https://github.com/SVGKit/SVGKit.git`, tag `3.0.0`)
- SwiftFormat/CLI (~> 0.47.13)
- SwiftLint
Expand Down Expand Up @@ -182,7 +182,7 @@ EXTERNAL SOURCES:
:tag: 4.0.5
SubstrateSdk:
:git: https://github.com/nova-wallet/substrate-sdk-ios.git
:tag: 1.2.0
:tag: 1.3.0
SVGKit:
:git: https://github.com/SVGKit/SVGKit.git
:tag: 3.0.0
Expand All @@ -201,7 +201,7 @@ CHECKOUT OPTIONS:
:tag: 4.0.5
SubstrateSdk:
:git: https://github.com/nova-wallet/substrate-sdk-ios.git
:tag: 1.2.0
:tag: 1.3.0
SVGKit:
:git: https://github.com/SVGKit/SVGKit.git
:tag: 3.0.0
Expand Down Expand Up @@ -231,7 +231,7 @@ SPEC CHECKSUMS:
SoraUI: e5ceb2cffe40145e589aa464e2e0a8d054011e0b
Sourcery: db66600e8b285c427701821598d07cf3c7e6c476
Starscream: 8cc648110705c09a15f0de84352c7f9595b7cb05
SubstrateSdk: 80def02673c07145109cdb4a5a724566ab12482c
SubstrateSdk: 46a442c9b42c8e22b144ad1cb24127415bfd6f68
SVGKit: 132b010efbf57ec345309fe4a7f627c0a40c5d63
SwiftFormat: 73573b89257437c550b03d934889725fbf8f75e5
SwiftLint: 99f82d07b837b942dd563c668de129a03fc3fb52
Expand All @@ -240,6 +240,6 @@ SPEC CHECKSUMS:
TweetNacl: 3abf4d1d2082b0114e7a67410e300892448951e6
xxHash-Swift: 30bd6a7507b3b7348a277c49b1cb6346c2905ec7

PODFILE CHECKSUM: 1c01ac8046cf87ecb2dfcca5889a41025c7b3897
PODFILE CHECKSUM: c77a344ca52461c9928594f5bec896982db9f99d

COCOAPODS: 1.11.2
2,090 changes: 1,311 additions & 779 deletions novawallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "iconHardwareWallet.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
12 changes: 12 additions & 0 deletions novawallet/Assets.xcassets/iconParitySigner.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "iconParitySigner.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "iconParitySignerHeader.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "iconParitySigner.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "imageNovaParitySigner.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "imageParitySignerIntegrationHint.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
5 changes: 5 additions & 0 deletions novawallet/Common/Configs/ApplicationConfigs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protocol ApplicationConfigProtocol {
var learnPayoutURL: URL { get }
var learnControllerAccountURL: URL { get }
var learnRecommendedValidatorsURL: URL { get }
var paritySignerTroubleshoutingURL: URL { get }
var canDebugDApp: Bool { get }
var fileCachePath: String { get }
}
Expand Down Expand Up @@ -167,6 +168,10 @@ extension ApplicationConfig: ApplicationConfigProtocol {
URL(string: "https://wiki.polkadot.network/docs/en/maintain-guides-how-to-nominate-polkadot#setting-up-stash-and-controller-keys")!
}

var paritySignerTroubleshoutingURL: URL {
URL(string: "https://github.com/nova-wallet/nova-utils/wiki/Parity-Signer-troubleshooting")!
}

var learnRecommendedValidatorsURL: URL {
URL(string: "https://github.com/nova-wallet/nova-utils/wiki/Recommended-validators-in-Nova-Wallet")!
}
Expand Down
5 changes: 5 additions & 0 deletions novawallet/Common/Crypto/HardwareSigningError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

enum HardwareSigningError: Error {
case signingCancelled
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Foundation
import SubstrateSdk

extension MetaAccountModelType {
var signaturePayloadFormat: ExtrinsicSignaturePayloadFormat {
switch self {
case .secrets, .watchOnly:
return .regular
case .paritySigner:
return .paritySigner
}
}

var supportsSigningRawBytes: Bool {
switch self {
case .secrets, .watchOnly:
return true
case .paritySigner:
return false
}
}
}
11 changes: 11 additions & 0 deletions novawallet/Common/Crypto/NoKeysSigningWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ extension Error {
return true
}
}

var isNotSupportedByParitySigner: Bool {
guard let notSupportedError = self as? NoSigningSupportError else {
return false
}

switch notSupportedError {
case .notSupported:
return true
}
}
}
12 changes: 12 additions & 0 deletions novawallet/Common/Crypto/NoSigningSupportWrapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation
import IrohaCrypto

enum NoSigningSupportError: Error {
case notSupported
}

final class NoSigningSupportWrapper: SigningWrapperProtocol {
func sign(_: Data) throws -> IRSignatureProtocol {
throw NoSigningSupportError.notSupported
}
}
57 changes: 57 additions & 0 deletions novawallet/Common/Crypto/ParitySignerSigningWrapper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import Foundation
import IrohaCrypto

/**
* Implementation of the signing for Parity Signer makes
* an assumption that signing is called in one of the background threads.
* And one can suspend it (thus blocking the whole operation sending flow) and
* launch signing ui in main thread. The callback with
* the result should unblock signing thread to continue sending operation.
*/
final class ParitySignerSigningWrapper {
let uiPresenter: TransactionSigningPresenting
let metaId: String
let chainId: ChainModel.Id

init(
uiPresenter: TransactionSigningPresenting,
metaId: String,
chainId: ChainModel.Id
) {
self.uiPresenter = uiPresenter
self.metaId = metaId
self.chainId = chainId
}
}

extension ParitySignerSigningWrapper: SigningWrapperProtocol {
func sign(_ originalData: Data) throws -> IRSignatureProtocol {
let semaphore = DispatchSemaphore(value: 0)

var signingResult: TransactionSigningResult?

DispatchQueue.main.async {
self.uiPresenter.presentParitySignerFlow(
for: originalData,
metaId: self.metaId,
chainId: self.chainId
) { result in
signingResult = result

semaphore.signal()
}
}

// block tx sending flow until we get signing result from ui
semaphore.wait()

switch signingResult {
case let .success(signature):
return signature
case let .failure(error):
throw error
case .none:
throw CommonError.undefined
}
}
}
18 changes: 17 additions & 1 deletion novawallet/Common/Crypto/SigningWrapperFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ protocol SigningWrapperFactoryProtocol {
final class SigningWrapperFactory: SigningWrapperFactoryProtocol {
let keystore: KeystoreProtocol

init(keystore: KeystoreProtocol = Keychain()) {
let uiPresenter: TransactionSigningPresenting

init(
uiPresenter: TransactionSigningPresenting = TransactionSigningPresenter(),
keystore: KeystoreProtocol = Keychain()
) {
self.uiPresenter = uiPresenter
self.keystore = keystore
}

Expand All @@ -30,6 +36,12 @@ final class SigningWrapperFactory: SigningWrapperFactoryProtocol {
return SigningWrapper(keystore: keystore, metaId: metaId, accountResponse: accountResponse)
case .watchOnly:
return NoKeysSigningWrapper()
case .paritySigner:
return ParitySignerSigningWrapper(
uiPresenter: uiPresenter,
metaId: metaId,
chainId: accountResponse.chainId
)
}
}

Expand All @@ -41,6 +53,8 @@ final class SigningWrapperFactory: SigningWrapperFactoryProtocol {
return SigningWrapper(keystore: keystore, ethereumAccountResponse: ethereumAccountResponse)
case .watchOnly:
return NoKeysSigningWrapper()
case .paritySigner:
return NoSigningSupportWrapper()
}
}

Expand All @@ -50,6 +64,8 @@ final class SigningWrapperFactory: SigningWrapperFactoryProtocol {
return EthereumSigner(keystore: keystore, ethereumAccountResponse: ethereumAccountResponse)
case .watchOnly:
return NoKeysSigningWrapper()
case .paritySigner:
return NoSigningSupportWrapper()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation

extension TimeInterval {
static let secondsInHour: TimeInterval = 3600
static let secondsInMinute: TimeInterval = 60.0
static let secondsInDay: TimeInterval = 24 * secondsInHour

var milliseconds: Int {
Expand All @@ -13,6 +14,7 @@ extension TimeInterval {
}

var seconds: TimeInterval { self / 1000 }
var minutesFromSeconds: Int { Int(self / Self.secondsInMinute) }
var daysFromSeconds: Int { Int(self / Self.secondsInDay) }
var secondsFromDays: TimeInterval { self * Self.secondsInDay }
var hoursFromSeconds: Int { Int(self / Self.secondsInHour) }
Expand Down
1 change: 1 addition & 0 deletions novawallet/Common/Helpers/AddressConversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extension AccountId {

enum AccountAddressConversionError: Error {
case invalidEthereumAddress
case invalidChainAddress
}

extension AccountAddress {
Expand Down
Loading

0 comments on commit 4848266

Please sign in to comment.