-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// GetEntropyCommand.swift | ||
// TangemSdk | ||
// | ||
// Created by Alexander Osokin on 27.03.2023. | ||
// Copyright © 2023 Tangem AG. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Deserialized response from the Tangem card after `GetEntropyCommand`. | ||
@available(iOS 13.0, *) | ||
public struct GetEntropyResponse: JSONStringConvertible { | ||
/// Unique Tangem card ID number. | ||
public let cardId: String | ||
/// Random bytes | ||
public let data: Data | ||
} | ||
|
||
/// Generate OTP on the card. | ||
@available(iOS 13.0, *) | ||
public class GetEntropyCommand: Command { | ||
public var preflightReadMode: PreflightReadMode { .readCardOnly } | ||
|
||
public init() {} | ||
|
||
deinit { | ||
Log.debug("GetEntropyCommand deinit") | ||
} | ||
|
||
func performPreCheck(_ card: Card) -> TangemSdkError? { | ||
// guard card.firmwareVersion >= .isExternalWalletsAllowed else { | ||
// return TangemSdkError.walletNotFound | ||
// } | ||
|
||
return nil | ||
} | ||
|
||
func serialize(with environment: SessionEnvironment) throws -> CommandApdu { | ||
let tlvBuilder = try createTlvBuilder(legacyMode: environment.legacyMode) | ||
.append(.pin, value: environment.accessCode.value) | ||
.append(.cardId, value: environment.card?.cardId) | ||
|
||
return CommandApdu(.getEntropy, tlv: tlvBuilder.serialize()) | ||
} | ||
|
||
func deserialize(with environment: SessionEnvironment, from apdu: ResponseApdu) throws -> GetEntropyResponse { | ||
guard let tlv = apdu.getTlvData(encryptionKey: environment.encryptionKey) else { | ||
throw TangemSdkError.deserializeApduFailed | ||
} | ||
|
||
let decoder = TlvDecoder(tlv: tlv) | ||
|
||
return GetEntropyResponse(cardId: try decoder.decode(.cardId), | ||
data: try decoder.decode(.issuerData)) | ||
} | ||
} |