Skip to content

Commit

Permalink
IOS-3219 Rename external wallet to keys import
Browse files Browse the repository at this point in the history
  • Loading branch information
tureck1y committed Mar 29, 2023
1 parent 162e9fd commit 922c2e0
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Example/TangemSdkExample/Developer/StaticData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension AppModel {
"disableFiles": false,
"allowHDWallets": true,
"allowBackup": true,
"allowExternalWallets": true,
"allowKeysImport": true,
"NDEF": [],
"cardData": {
"date": "2021-03-15",
Expand Down
8 changes: 4 additions & 4 deletions TangemSdk/TangemSdk/Common/Card/CardSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public extension Card {
public let isHDWalletAllowed: Bool
/// Is allowed to create backup
public let isBackupAllowed: Bool
/// Is allowed to create or import external wallets. COS. v6.10+
public let isExternalWalletsAllowed: Bool
/// Is allowed to import keys. COS. v6.10+
public let isKeysImportAllowed: Bool
/// Is allowed to delete wallet. COS before v4
@SkipEncoding
var isPermanentWallet: Bool
Expand Down Expand Up @@ -73,7 +73,7 @@ extension Card.Settings {
self.isHDWalletAllowed = mask.contains(.allowHDWallets)
self.isFilesAllowed = !mask.contains(.disableFiles)
self.isBackupAllowed = mask.contains(.allowBackup)
self.isExternalWalletsAllowed = mask.contains(.allowExternalWallets)
self.isKeysImportAllowed = mask.contains(.allowKeysImport)

var encryptionModes: [EncryptionMode] = [.strong]
if mask.contains(.allowFastEncryption) {
Expand Down Expand Up @@ -148,7 +148,7 @@ extension CardSettingsMask {
static let isReusable = CardSettingsMask(rawValue: 0x0001)
static let allowHDWallets = CardSettingsMask(rawValue: 0x00200000)
static let allowBackup = CardSettingsMask(rawValue: 0x00400000)
static let allowExternalWallets = CardSettingsMask(rawValue: 0x00800000)
static let allowKeysImport = CardSettingsMask(rawValue: 0x00800000)
}

//MARK:- CardSettingsMask OptionSetCodable conformance
Expand Down
4 changes: 2 additions & 2 deletions TangemSdk/TangemSdk/Common/Card/FirmwareVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public extension FirmwareVersion { //todo: move all doubleValue checks to consta
static let backupAvailable = FirmwareVersion(major: 4, minor: 39)
/// Wallet ownership confirmation available
static let walletOwnershipConfirmationAvailable = FirmwareVersion(major: 2, minor: 1)
/// External wallets support
static let isExternalWalletsAvailable = FirmwareVersion(major: 6, minor: 10)
/// Keys import support
static let keysImportAvailable = FirmwareVersion(major: 6, minor: 10)
/// Tmp range for visa cards
static let visaRange = 5.25...5.30
}
Expand Down
18 changes: 9 additions & 9 deletions TangemSdk/TangemSdk/Common/Card/Wallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public extension Card {
public let index: Int
/// Proof for BLS Proof of possession scheme (POP)
public let proof: Data?
/// Does this wallet has an external copy. E.g. seed phrase
public let isExternal: Bool
/// Has this key been imported to a card. E.g. from seed phrase
public let isImported: Bool
/// Does this wallet has a backup
public var hasBackup: Bool
/// Derived keys according to `Config.defaultDerivationPaths`
Expand Down Expand Up @@ -61,27 +61,27 @@ extension Card.Wallet {
case backuped = 0x82
/// Wallet was purged and can't be recreated or used for signing, but backup data read and wallet can be usable on backup card
case backupedAndPurged = 0x83
/// Wallet was loaded externally
case external = 0x42
/// Wallet was loaded externally and backuped
case backupedExternal = 0xC2
/// Wallet was imported
case imported = 0x42
/// Wallet was imported and backuped
case backupedImported = 0xC2
}
}

@available(iOS 13.0, *)
extension Card.Wallet.Status {
var isBackuped: Bool {
switch self {
case .backuped, .backupedAndPurged, .backupedExternal:
case .backuped, .backupedAndPurged, .backupedImported:
return true
default:
return false
}
}

var isExternal: Bool {
var isImported: Bool {
switch self {
case .external, .backupedExternal:
case .imported, .backupedImported:
return true
default:
return false
Expand Down
4 changes: 2 additions & 2 deletions TangemSdk/TangemSdk/Common/Core/TangemSdkError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public enum TangemSdkError: Error, LocalizedError, Encodable {
//MARK: Settings
case filesDisabled
case hdWalletDisabled
case externalWalletsDisabled
case keysImportDisabled

case resetPinNoCardToReset
case resetPinWrongCard(internalCode: Int? = nil)
Expand Down Expand Up @@ -402,7 +402,7 @@ public enum TangemSdkError: Error, LocalizedError, Encodable {

case .filesDisabled: return 42002
case .hdWalletDisabled: return 42003
case .externalWalletsDisabled: return 42004
case .keysImportDisabled: return 42004

// MARK: 5xxxx Errors
// SDK error. Errors, that occurred in the upper level of SDK, like device restrictions, user canceled the operation or SDK is busy and can’t open the new session right now.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct CardDeserializer {
remainingSignatures: remainingSignatures,
index: 0,
proof: nil,
isExternal: false,
isImported: false,
hasBackup: false)

wallets.append(wallet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class WalletDeserializer {
remainingSignatures: nil,
index: try decoder.decode(.walletIndex),
proof: try decoder.decode(.proof),
isExternal: status.isExternal,
isImported: status.isImported,
hasBackup: status.isBackuped)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public struct CardConfig: Decodable {
let disableFiles: Bool?
let allowHDWallets: Bool? //TODO: add precheck to specific commands
let allowBackup: Bool?
let allowExternalWallets: Bool?
let allowKeysImport: Bool?
let createWallet: Int
let cardData: CardConfigData
let ndefRecords: [NdefRecord]
Expand All @@ -69,7 +69,7 @@ public struct CardConfig: Decodable {
useActivation, useBlock, allowSelectBlockchain, skipSecurityDelayIfValidatedByIssuer, skipSecurityDelayIfValidatedByLinkedTerminal, disableIssuerData,
disableUserData, disableFiles, createWallet, cardData, walletsCount,
useDynamicNDEF, useOneCommandAtTime, protectIssuerDataAgainstReplay,
disablePrecomputedNDEF, allowHDWallets, allowBackup, isReusable, allowExternalWallets
disablePrecomputedNDEF, allowHDWallets, allowBackup, isReusable, allowKeysImport
case pin = "PIN"
case pin2 = "PIN2"
case pin3 = "PIN3"
Expand Down Expand Up @@ -173,8 +173,8 @@ public struct CardConfig: Decodable {
builder.add(.allowBackup)
}

if allowExternalWallets ?? false {
builder.add(.allowExternalWallets)
if allowKeysImport ?? false {
builder.add(.allowKeysImport)
}

return builder.build()
Expand Down
24 changes: 12 additions & 12 deletions TangemSdk/TangemSdk/Operations/Wallet/CreateWalletCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class CreateWalletCommand: Command {
var walletIndex: Int = 0

private let curve: EllipticCurve
private let externalKey: ExtendedPrivateKey?
private let keyToImport: ExtendedPrivateKey?
private let signingMethod = SigningMethod.signHash

/// Default initializer
Expand All @@ -41,9 +41,9 @@ final class CreateWalletCommand: Command {
init(curve: EllipticCurve, seed: Data?) throws {
self.curve = curve
if let seed {
self.externalKey = try BIP32().makeMasterKey(from: seed, curve: curve)
self.keyToImport = try BIP32().makeMasterKey(from: seed, curve: curve)
} else {
self.externalKey = nil
self.keyToImport = nil
}
}

Expand All @@ -68,18 +68,18 @@ final class CreateWalletCommand: Command {
}
}

if externalKey != nil {
if card.firmwareVersion < .isExternalWalletsAvailable {
if keyToImport != nil {
if card.firmwareVersion < .keysImportAvailable {
return TangemSdkError.notSupportedFirmwareVersion
}

if !card.settings.isExternalWalletsAllowed {
return TangemSdkError.externalWalletsDisabled
if !card.settings.isKeysImportAllowed {
return TangemSdkError.keysImportDisabled
}

do {
// This check will fail for compressed secp256r1 keys
if let extendedKey = try externalKey?.makePublicKey(for: curve),
if let extendedKey = try keyToImport?.makePublicKey(for: curve),
card.wallets[extendedKey.publicKey] != nil {
return TangemSdkError.walletAlreadyCreated
}
Expand Down Expand Up @@ -144,9 +144,9 @@ final class CreateWalletCommand: Command {
.append(.walletIndex, value: walletIndex)
}

if let externalKey {
try tlvBuilder.append(.walletPrivateKey, value: externalKey.privateKey)
try tlvBuilder.append(.walletHDChain, value: externalKey.chainCode)
if let keyToImport {
try tlvBuilder.append(.walletPrivateKey, value: keyToImport.privateKey)
try tlvBuilder.append(.walletHDChain, value: keyToImport.chainCode)
}

return CommandApdu(.createWallet, tlv: tlvBuilder.serialize())
Expand Down Expand Up @@ -197,7 +197,7 @@ final class CreateWalletCommand: Command {
remainingSignatures: remainingSignatures,
index: index,
proof: nil,
isExternal: false,
isImported: false,
hasBackup: false)
}

Expand Down
6 changes: 3 additions & 3 deletions TangemSdk/TangemSdkTests/BIP32Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class BIP32Tests: XCTestCase {

// MARK: - Test that keys uploaded to a card are equal to locally computed

func testExternalWalletSecp256k1() throws {
func testKeyImportSecp256k1() throws {
let mnemonicString = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
let mnemonic = try Mnemonic(with: mnemonicString)
let seed = try mnemonic.generateSeed()
Expand All @@ -149,7 +149,7 @@ class BIP32Tests: XCTestCase {
XCTAssertEqual(pubKey.chainCode.hexString, chainCodeFromCard)
}

func testExternalWalletEd25519() throws {
func testKeyImportEd25519() throws {
let mnemonicString = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
let mnemonic = try Mnemonic(with: mnemonicString)
let seed = try mnemonic.generateSeed()
Expand All @@ -163,7 +163,7 @@ class BIP32Tests: XCTestCase {
}

@available(iOS 16.0, *)
func testExternalWalletSecp256r1() throws {
func testKeyImportSecp256r1() throws {
let mnemonicString = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
let mnemonic = try Mnemonic(with: mnemonicString)
let seed = try mnemonic.generateSeed()
Expand Down
2 changes: 1 addition & 1 deletion TangemSdk/TangemSdkTests/JSONRPCTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class JSONRPCTests: XCTestCase {
remainingSignatures: 100,
index: 1,
proof: nil,
isExternal: false,
isImported: false,
hasBackup: false))
testMethod(name: "CreateWallet", result: result)
}
Expand Down
8 changes: 4 additions & 4 deletions TangemSdk/TangemSdkTests/Jsons/Card.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"isHDWalletAllowed" : true,
"isFilesAllowed" : true,
"isBackupAllowed" : true,
"isExternalWalletsAllowed" : true
"isKeysImportAllowed" : true
},
"issuer" : {
"name" : "TANGEM AG",
Expand Down Expand Up @@ -61,7 +61,7 @@
},
"index" : 0,
"hasBackup" : false,
"isExternal": false,
"isImported": false,
"derivedKeys" : []
},
{
Expand All @@ -73,7 +73,7 @@
},
"index" : 1,
"hasBackup" : false,
"isExternal": false,
"isImported": false,
"derivedKeys" : []
},
{
Expand All @@ -85,7 +85,7 @@
},
"index" : 2,
"hasBackup" : false,
"isExternal": false,
"isImported": false,
"derivedKeys" : []
}
],
Expand Down
2 changes: 1 addition & 1 deletion TangemSdk/TangemSdkTests/Jsons/CreateWallet.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"remainingSignatures": 100,
"index": 1,
"hasBackup" : false,
"isExternal": false,
"isImported": false,
"derivedKeys" : []
}
},
Expand Down

0 comments on commit 922c2e0

Please sign in to comment.