Skip to content

Commit

Permalink
up 1.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Aug 25, 2021
1 parent 1bc4d2f commit 7e29a44
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
17 changes: 15 additions & 2 deletions Sources/TonClientSwift/Crypto/Crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<TSDKResultOfEncryptionBoxEncrypt, TSDKClientError, TSDKDefault>) -> Void
) {
let method: String = "encryption_box_encrypt"
Expand All @@ -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<TSDKResultOfEncryptionBoxDecrypt, TSDKClientError, TSDKDefault>) -> Void
) {
let method: String = "encryption_box_decrypt"
Expand All @@ -496,4 +498,15 @@ public final class TSDKCryptoModule {
})
}

/// Creates encryption box with specified algorithm
public func create_encryption_box(_ payload: TSDKParamsOfCreateEncryptionBox, _ handler: @escaping (TSDKBindingResponse<TSDKRegisteredEncryptionBox, TSDKClientError, TSDKDefault>) -> Void
) {
let method: String = "create_encryption_box"
binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
var response: TSDKBindingResponse<TSDKRegisteredEncryptionBox, TSDKClientError, TSDKDefault> = .init()
response.update(requestId, params, responseType, finished)
handler(response)
})
}

}
62 changes: 60 additions & 2 deletions Sources/TonClientSwift/Crypto/CryptoTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -851,11 +900,20 @@ 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) {
self.data = data
}
}

public struct TSDKParamsOfCreateEncryptionBox: Codable {
/// Encryption algorithm specifier including cipher parameters (key, IV, etc)
public var algorithm: TSDKEncryptionAlgorithm

public init(algorithm: TSDKEncryptionAlgorithm) {
self.algorithm = algorithm
}
}

2 changes: 1 addition & 1 deletion Sources/TonClientSwift/Tvm/Tvm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<TSDKResultOfRunExecutor, TSDKClientError, TSDKDefault>) -> Void
) {
Expand Down

0 comments on commit 7e29a44

Please sign in to comment.