diff --git a/Sources/TonClientSwift/Crypto/Crypto.swift b/Sources/TonClientSwift/Crypto/Crypto.swift index 528c7cf..e787f62 100644 --- a/Sources/TonClientSwift/Crypto/Crypto.swift +++ b/Sources/TonClientSwift/Crypto/Crypto.swift @@ -474,7 +474,8 @@ public final class TSDKCryptoModule { }) } - /// Encrypts data using given encryption box + /// Encrypts data using given encryption box Note. + /// Block cipher algorithms pad data to cipher block size so encrypted data can be longer then original data. Client should store the original data size after encryption and use it afterdecryption to retrieve the original data from decrypted data. public func encryption_box_encrypt(_ payload: TSDKParamsOfEncryptionBoxEncrypt, _ handler: @escaping (TSDKBindingResponse) -> Void ) { let method: String = "encryption_box_encrypt" @@ -485,7 +486,8 @@ public final class TSDKCryptoModule { }) } - /// Decrypts data using given encryption box + /// Decrypts data using given encryption box Note. + /// Block cipher algorithms pad data to cipher block size so encrypted data can be longer then original data. Client should store the original data size after encryption and use it afterdecryption to retrieve the original data from decrypted data. public func encryption_box_decrypt(_ payload: TSDKParamsOfEncryptionBoxDecrypt, _ handler: @escaping (TSDKBindingResponse) -> Void ) { let method: String = "encryption_box_decrypt" @@ -496,4 +498,15 @@ public final class TSDKCryptoModule { }) } + /// Creates encryption box with specified algorithm + public func create_encryption_box(_ payload: TSDKParamsOfCreateEncryptionBox, _ handler: @escaping (TSDKBindingResponse) -> Void + ) { + let method: String = "create_encryption_box" + binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in + var response: TSDKBindingResponse = .init() + response.update(requestId, params, responseType, finished) + handler(response) + }) + } + } diff --git a/Sources/TonClientSwift/Crypto/CryptoTypes.swift b/Sources/TonClientSwift/Crypto/CryptoTypes.swift index a40a7f1..a9eedf9 100644 --- a/Sources/TonClientSwift/Crypto/CryptoTypes.swift +++ b/Sources/TonClientSwift/Crypto/CryptoTypes.swift @@ -24,6 +24,24 @@ public enum TSDKCryptoErrorCode: Int, Codable { case SigningBoxNotRegistered = 121 case InvalidSignature = 122 case EncryptionBoxNotRegistered = 123 + case InvalidIvSize = 124 + case UnsupportedCipherMode = 125 + case CannotCreateCipher = 126 + case EncryptDataError = 127 + case DecryptDataError = 128 + case IvRequired = 129 +} + +public enum TSDKEncryptionAlgorithmEnumTypes: String, Codable { + case AES = "AES" +} + +public enum TSDKCipherMode: String, Codable { + case CBC = "CBC" + case CFB = "CFB" + case CTR = "CTR" + case ECB = "ECB" + case OFB = "OFB" } public enum TSDKParamsOfAppSigningBoxEnumTypes: String, Codable { @@ -66,6 +84,36 @@ public struct TSDKEncryptionBoxInfo: Codable { } } +public struct TSDKEncryptionAlgorithm: Codable { + public var type: TSDKEncryptionAlgorithmEnumTypes + + public init(type: TSDKEncryptionAlgorithmEnumTypes) { + self.type = type + } +} + +public struct TSDKAesParams: Codable { + public var mode: TSDKCipherMode + public var key: String + public var iv: String? + + public init(mode: TSDKCipherMode, key: String, iv: String? = nil) { + self.mode = mode + self.key = key + self.iv = iv + } +} + +public struct TSDKAesInfo: Codable { + public var mode: TSDKCipherMode + public var iv: String? + + public init(mode: TSDKCipherMode, iv: String? = nil) { + self.mode = mode + self.iv = iv + } +} + public struct TSDKParamsOfFactorize: Codable { /// Hexadecimal representation of u64 composite number. public var composite: String @@ -830,7 +878,8 @@ public struct TSDKParamsOfEncryptionBoxEncrypt: Codable { } public struct TSDKResultOfEncryptionBoxEncrypt: Codable { - /// Encrypted data, encoded in Base64 + /// Encrypted data, encoded in Base64. + /// Padded to cipher block size public var data: String public init(data: String) { @@ -851,7 +900,7 @@ public struct TSDKParamsOfEncryptionBoxDecrypt: Codable { } public struct TSDKResultOfEncryptionBoxDecrypt: Codable { - /// Decrypted data, encoded in Base64 + /// Decrypted data, encoded in Base64. public var data: String public init(data: String) { @@ -859,3 +908,12 @@ public struct TSDKResultOfEncryptionBoxDecrypt: Codable { } } +public struct TSDKParamsOfCreateEncryptionBox: Codable { + /// Encryption algorithm specifier including cipher parameters (key, IV, etc) + public var algorithm: TSDKEncryptionAlgorithm + + public init(algorithm: TSDKEncryptionAlgorithm) { + self.algorithm = algorithm + } +} + diff --git a/Sources/TonClientSwift/Tvm/Tvm.swift b/Sources/TonClientSwift/Tvm/Tvm.swift index 5a6b8a1..2b129f7 100644 --- a/Sources/TonClientSwift/Tvm/Tvm.swift +++ b/Sources/TonClientSwift/Tvm/Tvm.swift @@ -22,7 +22,7 @@ public final class TSDKTvmModule { /// Transaction executor requires account BOC (bag of cells) as a parameter. /// To get the account BOC - use `net.query` method to download it from GraphQL API(field `boc` of `account`) or generate it with `abi.encode_account` method. /// Also it requires message BOC. To get the message BOC - use `abi.encode_message` or `abi.encode_internal_message`. - /// If you need this emulation to be as precise as possible (for instance - emulate transactionwith particular lt in particular block or use particular blockchain config,in case you want to download it from a particular key block - then specify `ParamsOfRunExecutor` parameter. + /// If you need this emulation to be as precise as possible (for instance - emulate transactionwith particular lt in particular block or use particular blockchain config,downloaded from a particular key block - then specify `execution_options` parameter. /// If you need to see the aborted transaction as a result, not as an error, set `skip_transaction_check` to `true`. public func run_executor(_ payload: TSDKParamsOfRunExecutor, _ handler: @escaping (TSDKBindingResponse) -> Void ) {