Skip to content

Commit

Permalink
Merge pull request #38 from soramitsu/develop
Browse files Browse the repository at this point in the history
v0.11.0
  • Loading branch information
ERussel authored Jul 1, 2021
2 parents 3a09366 + b2d11b0 commit a780e2b
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 45 deletions.
2 changes: 2 additions & 0 deletions Example/FearlessUtils.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@
"${BUILT_PRODUCTS_DIR}/IrohaCrypto/IrohaCrypto.framework",
"${BUILT_PRODUCTS_DIR}/TweetNacl/TweetNacl.framework",
"${BUILT_PRODUCTS_DIR}/scrypt.c/scrypt.framework",
"${BUILT_PRODUCTS_DIR}/secp256k1.c/secp256k1.framework",
"${BUILT_PRODUCTS_DIR}/xxHash-Swift/xxHash_Swift.framework",
);
name = "[CP] Embed Pods Frameworks";
Expand All @@ -714,6 +715,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/IrohaCrypto.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TweetNacl.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/scrypt.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/secp256k1.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/xxHash_Swift.framework",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
36 changes: 22 additions & 14 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
PODS:
- BigInt (5.0.0)
- FearlessUtils (0.9.0):
- FearlessUtils (0.11.0):
- BigInt (~> 5.0)
- IrohaCrypto/ed25519 (~> 0.7.0)
- IrohaCrypto/Scrypt (~> 0.7.0)
- IrohaCrypto/secp256k1 (~> 0.7.0)
- IrohaCrypto/sr25519 (~> 0.7.0)
- IrohaCrypto/ed25519 (~> 0.8.0)
- IrohaCrypto/Scrypt (~> 0.8.0)
- IrohaCrypto/secp256k1 (~> 0.8.0)
- IrohaCrypto/sr25519 (~> 0.8.0)
- IrohaCrypto/ss58 (~> 0.8.0)
- TweetNacl (~> 1.0.0)
- xxHash-Swift (~> 1.0.0)
- IrohaCrypto/BIP39 (0.7.2):
- IrohaCrypto/BIP39 (0.8.0):
- IrohaCrypto/Common
- IrohaCrypto/blake2 (0.7.2)
- IrohaCrypto/Common (0.7.2)
- IrohaCrypto/ed25519 (0.7.2):
- IrohaCrypto/blake2 (0.8.0)
- IrohaCrypto/Common (0.8.0)
- IrohaCrypto/ed25519 (0.8.0):
- IrohaCrypto/Common
- IrohaCrypto/Scrypt (0.7.2):
- IrohaCrypto/Scrypt (0.8.0):
- IrohaCrypto/Common
- scrypt.c (~> 0.1)
- IrohaCrypto/secp256k1 (0.7.2):
- IrohaCrypto/secp256k1 (0.8.0):
- IrohaCrypto/Common
- IrohaCrypto/sr25519 (0.7.2):
- secp256k1.c (~> 0.1)
- IrohaCrypto/sr25519 (0.8.0):
- IrohaCrypto/BIP39
- IrohaCrypto/blake2
- IrohaCrypto/Common
- IrohaCrypto/ss58 (0.8.0):
- IrohaCrypto/blake2
- IrohaCrypto/Common
- scrypt.c (0.1.1)
- secp256k1.c (0.1.2)
- SwiftLint (0.42.0)
- TweetNacl (1.0.2)
- xxHash-Swift (1.0.13)
Expand All @@ -37,6 +43,7 @@ SPEC REPOS:
- BigInt
- IrohaCrypto
- scrypt.c
- secp256k1.c
- SwiftLint
- TweetNacl
- xxHash-Swift
Expand All @@ -47,9 +54,10 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8
FearlessUtils: 8c05cb6cf737943f343e6a1fb4be2ac6fafebb9d
IrohaCrypto: bddf15865c4df189b9c5273ba9c675afae8b7f4c
FearlessUtils: 9a5933f8b1a519bfc6baf21d6d23a2be92d638aa
IrohaCrypto: bef5e0fdbbfe587657d5de9a8961d7cb1f995a7e
scrypt.c: b42ae06183251329d2b2c620c226fb541a4a3592
secp256k1.c: db47b726585d80f027423682eb369729e61b3b20
SwiftLint: 4fa9579c63416865179bc416f0a92d55f009600d
TweetNacl: 3abf4d1d2082b0114e7a67410e300892448951e6
xxHash-Swift: 30bd6a7507b3b7348a277c49b1cb6346c2905ec7
Expand Down
11 changes: 6 additions & 5 deletions FearlessUtils.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'FearlessUtils'
s.version = '0.10.0'
s.version = '0.11.0'
s.summary = 'Utility library that implements clients specific logic to interact with substrate based networks'

s.homepage = 'https://github.com/soramitsu/fearless-utils-iOS'
Expand All @@ -22,10 +22,11 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64', 'VALID_ARCHS' => 'x86_64 armv7 arm64' }

s.source_files = 'FearlessUtils/Classes/**/*'
s.dependency 'IrohaCrypto/sr25519', '~> 0.7.0'
s.dependency 'IrohaCrypto/ed25519', '~> 0.7.0'
s.dependency 'IrohaCrypto/secp256k1', '~> 0.7.0'
s.dependency 'IrohaCrypto/Scrypt', '~> 0.7.0'
s.dependency 'IrohaCrypto/sr25519', '~> 0.8.0'
s.dependency 'IrohaCrypto/ed25519', '~> 0.8.0'
s.dependency 'IrohaCrypto/secp256k1', '~> 0.8.0'
s.dependency 'IrohaCrypto/Scrypt', '~> 0.8.0'
s.dependency 'IrohaCrypto/ss58', '~> 0.8.0'
s.dependency 'TweetNacl', '~> 1.0.0'
s.dependency 'BigInt', '~> 5.0'
s.dependency 'xxHash-Swift', '~> 1.0.0'
Expand Down
3 changes: 3 additions & 0 deletions FearlessUtils/Classes/Common/ChainType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Foundation

public typealias ChainType = UInt16
8 changes: 3 additions & 5 deletions FearlessUtils/Classes/Icon/PolkadotIconGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@ public class PolkadotIconGenerator: IconGenerating {

let typeValue = try addressFactory.type(fromAddress: address)

guard let addressType = SNAddressType(rawValue: typeValue.uint8Value) else {
throw PolkadotIconGeneratorError.unrecognizedAddress
}
let chainType = typeValue.uint16Value

let accountId = try addressFactory.accountId(fromAddress: address, type: addressType)
let accountId = try addressFactory.accountId(fromAddress: address, type: chainType)

var bytes: [UInt8] = try (accountId as NSData).blake2b(64).map { $0 }

Expand All @@ -95,7 +93,7 @@ public class PolkadotIconGenerator: IconGenerating {
bytes[index] = UInt8((value + 256 - UInt(zero[index])) % 256)
}

return Data(bytes: bytes)
return Data(bytes)
}

private func getColorsForData(_ data: Data) throws -> [UIColor] {
Expand Down
4 changes: 2 additions & 2 deletions FearlessUtils/Classes/Keystore/KeystoreCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ enum KeystoreEncodingContent: String {
public struct KeystoreConstants {
public static let nonceLength = 24
public static let encryptionKeyLength = 32
public static let pkcs8Header = Data(bytes: [48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32])
public static let pkcs8Divider = Data(bytes: [161, 35, 3, 33, 0])
public static let pkcs8Header = Data([48, 83, 2, 1, 1, 48, 5, 6, 3, 43, 101, 112, 4, 34, 4, 32])
public static let pkcs8Divider = Data([161, 35, 3, 33, 0])
public static let version = 3
}
2 changes: 1 addition & 1 deletion FearlessUtils/Classes/Keystore/KeystoreInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import IrohaCrypto

public struct KeystoreInfo {
public let address: String?
public let addressType: SNAddressType?
public let chainType: ChainType?
public let cryptoType: CryptoType
public let meta: KeystoreMeta?
}
10 changes: 5 additions & 5 deletions FearlessUtils/Classes/Keystore/KeystoreInfoFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public final class KeystoreInfoFactory: KeystoreInfoFactoryProtocol {
throw KeystoreInfoFactoryError.unsupportedCryptoType
}

let addressType: SNAddressType?
let chainType: ChainType?

if let address = definition.address,
let addressTypeValue = try? SS58AddressFactory().type(fromAddress: address) {
addressType = SNAddressType(rawValue: addressTypeValue.uint8Value)
let chainTypeValue = try? SS58AddressFactory().type(fromAddress: address) {
chainType = chainTypeValue.uint16Value
} else {
addressType = nil
chainType = nil
}

return KeystoreInfo(address: definition.address,
addressType: addressType,
chainType: chainType,
cryptoType: cryptoType,
meta: definition.meta)
}
Expand Down
8 changes: 4 additions & 4 deletions FearlessUtils/Classes/QR/SubstrateQRDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import Foundation
import IrohaCrypto

open class SubstrateQRDecoder: SubstrateQRDecodable {
public let networkType: SNAddressType
public let chainType: ChainType
public let separator: String
public let prefix: String

private lazy var addressFactory = SS58AddressFactory()

public init(networkType: SNAddressType,
public init(chainType: ChainType,
prefix: String = SubstrateQR.prefix,
separator: String = SubstrateQR.fieldsSeparator) {
self.prefix = prefix
self.networkType = networkType
self.chainType = chainType
self.separator = separator
}

Expand All @@ -31,7 +31,7 @@ open class SubstrateQRDecoder: SubstrateQRDecodable {
}

let address = fields[1]
let accountId = try addressFactory.accountId(fromAddress: address, type: networkType)
let accountId = try addressFactory.accountId(fromAddress: address, type: chainType)
let publicKey = try Data(hexString: fields[2])

guard publicKey.matchPublicKeyToAccountId(accountId) else {
Expand Down
9 changes: 9 additions & 0 deletions Tests/Helpers/KeypairDeriviation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ struct KeypairDeriviation: Decodable {
let publicKey: String
let path: String
}

enum KnownChainType: UInt16 {
case polkadotMain = 0
case polkadotSecondary = 1
case kusamaMain = 2
case kusamaSecondary = 3
case soraMain = 69
case genericSubstrate = 42
}
18 changes: 12 additions & 6 deletions Tests/Keystore/KeystoreExtractorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ class KeystoreExtractorTests: XCTestCase {
XCTAssertTrue(verifier.verify(signature, forOriginalData: privateKey.rawData(), using: publicKey))

let addressFactory = SS58AddressFactory()
let address = try addressFactory.address(fromPublicKey: publicKey,
type: .kusamaMain)
let address = try addressFactory.address(
fromAccountId: publicKey.rawData(),
type: KnownChainType.kusamaMain.rawValue
)

XCTAssertEqual(address, keystoreData.address)
} catch {
Expand Down Expand Up @@ -60,8 +62,10 @@ class KeystoreExtractorTests: XCTestCase {
XCTAssertEqual(keypair.publicKey().rawData(), keystoreData.publicKeyData)

let addressFactory = SS58AddressFactory()
let address = try addressFactory.address(fromPublicKey: keypair.publicKey(),
type: .kusamaMain)
let address = try addressFactory.address(
fromAccountId: keypair.publicKey().rawData(),
type: KnownChainType.kusamaMain.rawValue
)

XCTAssertEqual(address, keystoreData.address)
} catch {
Expand Down Expand Up @@ -91,8 +95,10 @@ class KeystoreExtractorTests: XCTestCase {
XCTAssertEqual(keypair.publicKey().rawData(), keystoreData.publicKeyData)

let addressFactory = SS58AddressFactory()
let address = try addressFactory.address(fromPublicKey: keypair.publicKey(),
type: .kusamaMain)
let address = try addressFactory.address(
fromAccountId: keypair.publicKey().rawData(),
type: KnownChainType.kusamaMain.rawValue
)

XCTAssertEqual(address, keystoreData.address)
} catch {
Expand Down
12 changes: 9 additions & 3 deletions Tests/QR/SubstrateQRDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class SubstrateQRDecoderTests: XCTestCase {
rawPublicKey: publicKey,
username: "BVB")

let decodedInfo = try SubstrateQRDecoder(networkType: .genericSubstrate).decode(data: data)
let decodedInfo = try SubstrateQRDecoder(
chainType: KnownChainType.genericSubstrate.rawValue
).decode(data: data)

XCTAssertEqual(decodedInfo, expectedInfo)
}
Expand All @@ -25,7 +27,9 @@ class SubstrateQRDecoderTests: XCTestCase {
rawPublicKey: publicKey,
username: nil)

let decodedInfo = try SubstrateQRDecoder(networkType: .genericSubstrate).decode(data: data)
let decodedInfo = try SubstrateQRDecoder(
chainType: KnownChainType.genericSubstrate.rawValue
).decode(data: data)

XCTAssertEqual(decodedInfo, expectedInfo)
}
Expand All @@ -52,7 +56,9 @@ class SubstrateQRDecoderTests: XCTestCase {

private func perforErrorTest(_ data: Data, expectedError: SubstrateQRDecoderError) {
do {
_ = try SubstrateQRDecoder(networkType: .genericSubstrate).decode(data: data)
_ = try SubstrateQRDecoder(
chainType: KnownChainType.genericSubstrate.rawValue
).decode(data: data)

XCTFail("Exception expected")
} catch {
Expand Down

0 comments on commit a780e2b

Please sign in to comment.