├── _Pods.xcodeproj ├── Examples ├── SPM │ ├── ZKSyncExample │ │ ├── Assets.xcassets │ │ │ ├── Contents.json │ │ │ ├── AccentColor.colorset │ │ │ │ └── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── SceneDelegate.swift │ │ ├── ViewController.swift │ │ ├── AppDelegate.swift │ │ ├── Base.lproj │ │ │ ├── Main.storyboard │ │ │ └── LaunchScreen.storyboard │ │ └── Info.plist │ └── ZKSyncExample.xcodeproj │ │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── swiftpm │ │ │ └── Package.resolved │ │ └── xcshareddata │ │ └── xcschemes │ │ └── ZKSyncExample.xcscheme └── CocoaPods │ ├── Podfile │ ├── ZKSyncExample.xcodeproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ ├── ZKSyncExample.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ ├── ZKSyncExample │ ├── WalletConsumer.swift │ ├── StateSectionHeaderView.swift │ ├── AppDelegate.swift │ ├── ViewControllers │ │ ├── DepositingBalanceTableViewCell.swift │ │ ├── TokenPriceViewController.swift │ │ ├── ContractAddressViewController.swift │ │ ├── DepositViewController.swift │ │ ├── MethodSelectionTableViewController.swift │ │ ├── NetworkSelectionTableViewController.swift │ │ ├── WithdrawViewController.swift │ │ ├── TransferViewController.swift │ │ └── TransactionFeeViewController.swift │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ └── UIAlertController+Extensions.swift │ ├── Tests │ ├── EthSignature.swift │ ├── Info.plist │ ├── AccountState.swift │ ├── Swap.swift │ ├── ForcedExit.swift │ ├── MintNFT.swift │ ├── Withdraw.swift │ ├── Transfer.swift │ ├── WithdrawNFT.swift │ ├── ChangePubKey+ChangePubKeyCREATE2.swift │ ├── ChangePubKey+ChangePubKeyOnchain.swift │ ├── ZkSignerTests.swift │ └── Order.swift │ └── Podfile.lock ├── Dependencies └── ZKSyncCrypto.xcframework │ ├── ios-arm64 │ └── ZKSyncCrypto.framework │ │ ├── Info.plist │ │ ├── ZKSyncCrypto │ │ ├── Modules │ │ ├── ZKSyncCrypto.swiftmodule │ │ │ ├── arm64.swiftdoc │ │ │ ├── arm64-apple-ios.swiftdoc │ │ │ ├── arm64.swiftinterface │ │ │ ├── arm64-apple-ios.swiftinterface │ │ │ ├── arm64.swiftinterface-e │ │ │ └── arm64-apple-ios.swiftinterface-e │ │ └── module.modulemap │ │ └── Headers │ │ └── ZKSyncCrypto.h │ ├── ios-arm64_x86_64-simulator │ └── ZKSyncCrypto.framework │ │ ├── Info.plist │ │ ├── ZKSyncCrypto │ │ ├── Modules │ │ ├── ZKSyncCrypto.swiftmodule │ │ │ ├── arm64.swiftdoc │ │ │ ├── x86_64.swiftdoc │ │ │ ├── arm64-apple-ios-simulator.swiftdoc │ │ │ ├── x86_64-apple-ios-simulator.swiftdoc │ │ │ ├── arm64.swiftinterface │ │ │ ├── x86_64.swiftinterface │ │ │ ├── arm64-apple-ios-simulator.swiftinterface │ │ │ ├── x86_64-apple-ios-simulator.swiftinterface │ │ │ ├── arm64.swiftinterface-e │ │ │ └── x86_64.swiftinterface-e │ │ └── module.modulemap │ │ └── Headers │ │ └── ZKSyncCrypto.h │ └── Info.plist ├── Sources └── ZKSync │ ├── Types.swift │ ├── Model │ ├── Toggle2FAInfo.swift │ ├── EthOpInfo.swift │ ├── Signature.swift │ ├── Block │ │ └── BlockInfo.swift │ ├── Contract │ │ └── ContractAddress.swift │ ├── Token │ │ ├── TokenId.swift │ │ ├── NFT.swift │ │ ├── Token.swift │ │ └── Tokens.swift │ ├── TransactionDetails.swift │ ├── Transactions │ │ ├── ZkSyncTransaction.swift │ │ ├── Batch │ │ │ ├── TransactionSignaturePair.swift │ │ │ └── TransactionBatchRequest.swift │ │ ├── ForcedExit.swift │ │ ├── MintNFT.swift │ │ ├── Swap.swift │ │ ├── Withdraw.swift │ │ ├── WithdrawNFT.swift │ │ ├── ChangePubKey.swift │ │ └── Transfer.swift │ ├── TransactionFee │ │ ├── TransactionFeeRequest.swift │ │ ├── TransactionFee.swift │ │ ├── TransactionTypeAddressPair.swift │ │ ├── TransactionFeeDetails.swift │ │ ├── TransactionType.swift │ │ └── TransactionFeeBatchRequest.swift │ ├── ChainId.swift │ ├── Auth │ │ ├── ChangePubKeyVariant.swift │ │ ├── ChangePubKeyOnchain.swift │ │ ├── Toggle2FA.swift │ │ ├── ChangePubKeyECDSA.swift │ │ └── ChangePubKeyCREATE2.swift │ ├── TimeRange.swift │ ├── AccountState.swift │ └── Swap │ │ └── Order.swift │ ├── Transport │ ├── Error.swift │ ├── TransactionStatus.swift │ ├── Response.swift │ ├── Transport.swift │ └── Request.swift │ ├── Signer │ ├── Ethereum │ │ ├── EthSignerError.swift │ │ ├── EthSignature.swift │ │ └── EthSigner.swift │ └── Utils │ │ └── Bits.swift │ ├── Provider │ ├── DefaultProvider+Toggle2FA.swift │ ├── DefaultProvider+ContractAddress.swift │ ├── DefaultProvider+EthOpInfo.swift │ ├── DefaultProvider+ConfirmationsForEthOpAmount.swift │ ├── DefaultProvider+EthTxForWithdrawal.swift │ ├── DefaultProvider+TransactionDetails.swift │ ├── TransactionFee │ │ ├── TransactionFeeRequest+Encoding.swift │ │ ├── TransactionFeeBatchRequest+Encoding.swift │ │ ├── DefaultProvider+TransactionFee.swift │ │ └── TransactionType+Encoding.swift │ ├── DefaultProvider+TokenPrice.swift │ ├── DefaultProvider+Tokens.swift │ ├── Transactions │ │ ├── TransactionRequest.swift │ │ └── DefaultProvider+Transactions.swift │ ├── DefaultProvider+Accounts.swift │ └── DefaultProvider.swift │ ├── Wallet │ ├── SignedTransaction.swift │ ├── DefaultWallet+Order.swift │ ├── DefaultWallet+MintNFT.swift │ ├── DefaultWallet+Promises.swift │ ├── DefaultWallet+TransferNFT.swift │ ├── DefaultWallet+ForcedExit.swift │ ├── DefaultWallet+Swap.swift │ ├── DefaultWallet+WithdrawNFT.swift │ ├── DefaultWallet+Transfer.swift │ ├── Wallet+DefaultTimeRange.swift │ └── DefaultWallet+Withdraw.swift │ ├── Types │ └── ZKSyncError.swift │ └── Extensions │ ├── BinaryInteger+Extensions.swift │ ├── String+Extensions.swift │ └── BigInt+Extensions.swift ├── .swiftlint.yml ├── .github └── workflows │ ├── release.yaml │ └── test.yaml ├── .gitignore ├── ZKSync.podspec ├── LICENSE ├── Package.swift ├── README.md └── Package.resolved /_Pods.xcodeproj: -------------------------------------------------------------------------------- 1 | /Examples/CocoaPods/Pods/Pods.xcodeproj -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zksync-sdk/zksync-swift/HEAD/Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Info.plist -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/ZKSyncCrypto: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zksync-sdk/zksync-swift/HEAD/Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/ZKSyncCrypto -------------------------------------------------------------------------------- /Sources/ZKSync/Types.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Types.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | 10 | public typealias ZKSyncResult = Result 11 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zksync-sdk/zksync-swift/HEAD/Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Info.plist -------------------------------------------------------------------------------- /Examples/CocoaPods/Podfile: -------------------------------------------------------------------------------- 1 | use_frameworks! 2 | 3 | platform :ios, '11.0' 4 | 5 | target 'ZKSyncExample' do 6 | pod 'ZKSync', :path => '../../' 7 | 8 | target 'ZKSyncExampleTests' do 9 | inherit! :search_paths 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/ZKSyncCrypto: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zksync-sdk/zksync-swift/HEAD/Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/ZKSyncCrypto -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Toggle2FAInfo.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Toggle2FAInfo.swift 3 | // ZKSync 4 | // 5 | // Created by Maxim Makhun on 8/28/21. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Toggle2FAInfo: Decodable { 11 | 12 | var success: Bool 13 | } 14 | -------------------------------------------------------------------------------- /Sources/ZKSync/Transport/Error.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Error.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | 10 | struct JRPCError: Codable { 11 | public let code: Int 12 | public let message: String 13 | } 14 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zksync-sdk/zksync-swift/HEAD/Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64.swiftdoc -------------------------------------------------------------------------------- /Sources/ZKSync/Model/EthOpInfo.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EthOpInfo.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct EthOpInfo: Decodable { 11 | let executed: Bool 12 | let block: BlockInfo 13 | } 14 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Signature.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Signature.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 11/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Signature: Encodable { 11 | let pubKey: String 12 | let signature: String 13 | } 14 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Maxim Makhun on 6/27/21. 6 | // 7 | 8 | import UIKit 9 | 10 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 11 | 12 | var window: UIWindow? 13 | } 14 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64-apple-ios.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zksync-sdk/zksync-swift/HEAD/Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64-apple-ios.swiftdoc -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zksync-sdk/zksync-swift/HEAD/Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64.swiftdoc -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/x86_64.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zksync-sdk/zksync-swift/HEAD/Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/x86_64.swiftdoc -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Block/BlockInfo.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BlockInfo.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct BlockInfo: Decodable { 11 | let blockNumber: Int 12 | let committed: Bool 13 | let verified: Bool 14 | } 15 | -------------------------------------------------------------------------------- /.swiftlint.yml: -------------------------------------------------------------------------------- 1 | included: 2 | - Sources/ZKSync/ 3 | - Examples/CocoaPods/ZKSyncExample 4 | - Examples/SPM/ZKSyncExample 5 | 6 | identifier_name: 7 | allowed_symbols: "_" 8 | min_length: 2 9 | max_length: 50 10 | warning: 30 11 | error: 60 12 | excluded: 13 | - id 14 | - tx 15 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Contract/ContractAddress.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContractAddress.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 06/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct ContractAddress: Codable { 11 | public let mainContract: String 12 | public let govContract: String 13 | } 14 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64-apple-ios-simulator.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zksync-sdk/zksync-swift/HEAD/Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64-apple-ios-simulator.swiftdoc -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/x86_64-apple-ios-simulator.swiftdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zksync-sdk/zksync-swift/HEAD/Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/x86_64-apple-ios-simulator.swiftdoc -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/WalletConsumer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WalletConsumer.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 07/01/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ZKSync 11 | 12 | protocol WalletConsumer { 13 | var wallet: Wallet! { get set } 14 | } 15 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Token/TokenId.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TokenId.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/05/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public protocol TokenId { 12 | 13 | var id: UInt32 { get } 14 | var symbol: String { get } 15 | 16 | func intoDecimal(_ amount: BigUInt) -> Decimal 17 | } 18 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/TransactionDetails.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionDetails.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct TransactionDetails: Decodable { 11 | let executed: Bool 12 | let success: Bool? 13 | let failReason: String? 14 | let block: BlockInfo? 15 | } 16 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Transactions/ZkSyncTransaction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ZkSyncTransaction.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 13/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public class ZkSyncTransaction: Encodable { 11 | 12 | public var type: String { 13 | fatalError("Subclasses mst override 'type' property") 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/TransactionFee/TransactionFeeRequest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionFeeRequest.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 08/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct TransactionFeeRequest { 11 | 12 | var transactionType: TransactionType 13 | var address: String 14 | var tokenIdentifier: String 15 | } 16 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module ZKSyncCrypto { 2 | umbrella header "ZKSyncCrypto.h" 3 | 4 | explicit module ZKCryptoKit { 5 | private header "zks_crypto.h" 6 | } 7 | 8 | export * 9 | } 10 | 11 | module ZKSyncCrypto.Swift { 12 | header "ZKSyncCrypto-Swift.h" 13 | requires objc 14 | } 15 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module ZKSyncCrypto { 2 | umbrella header "ZKSyncCrypto.h" 3 | 4 | explicit module ZKCryptoKit { 5 | private header "zks_crypto.h" 6 | } 7 | 8 | export * 9 | } 10 | 11 | module ZKSyncCrypto.Swift { 12 | header "ZKSyncCrypto-Swift.h" 13 | requires objc 14 | } 15 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/ChainId.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChainId.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 11/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public enum ChainId: Int { 11 | case mainnet = 1 12 | case rinkeby = 4 13 | case ropsten = 3 14 | case goerli = 420 15 | case sepolia = 11155111 16 | case localhost = 9 17 | 18 | public var id: Int { rawValue } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/ZKSync/Signer/Ethereum/EthSignerError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EthSignerError.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 11/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public enum EthSignerError: Error { 11 | case invalidKey 12 | case invalidMessage 13 | case invalidMnemonic 14 | case signingFailed 15 | case invalidTransactionType(String) 16 | case unsupportedOperation 17 | } 18 | -------------------------------------------------------------------------------- /Sources/ZKSync/Transport/TransactionStatus.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionStatus.swift 3 | // ZKSync 4 | // 5 | // Created by Maxim Makhun on 7/14/21. 6 | // 7 | 8 | import Foundation 9 | 10 | /// Enum, which is used by `PollingTransactionReceiptProcessor` to verify in what transaction status 11 | /// it should be waiting for. 12 | public enum TransactionStatus { 13 | case sent 14 | case commited 15 | case verified 16 | } 17 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Auth/ChangePubKeyVariant.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChangePubKeyVariant.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/03/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public enum ChangePubKeyAuthType: String, Encodable { 11 | case onchain 12 | case ECDSA 13 | case CREATE2 14 | } 15 | 16 | public protocol ChangePubKeyVariant: Encodable { 17 | var type: ChangePubKeyAuthType { get } 18 | var bytes: Data { get } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/TransactionFee/TransactionFee.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionFee.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 13/01/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public struct TransactionFee { 12 | 13 | public let feeToken: String 14 | public let fee: BigUInt 15 | 16 | public init(feeToken: String, fee: BigUInt) { 17 | self.feeToken = feeToken 18 | self.fee = fee 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/DefaultProvider+Toggle2FA.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultProvider+Toggle2FA.swift 3 | // ZKSync 4 | // 5 | // Created by Maxim Makhun on 8/25/21. 6 | // 7 | 8 | import Foundation 9 | 10 | extension DefaultProvider { 11 | 12 | public func toggle2FA(toggle2FA: Toggle2FA, completion: @escaping (ZKSyncResult) -> Void) { 13 | self.transport.send(method: "toggle_2fa", params: [toggle2FA], completion: completion) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/EthSignature.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EthSignature.swift 3 | // ZKSyncExampleTests 4 | // 5 | // Created by Maxim Makhun on 9/3/21. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | @testable import ZKSync 10 | 11 | extension EthSignature: Equatable { 12 | 13 | public static func == (lhs: EthSignature, rhs: EthSignature) -> Bool { 14 | return lhs.signature == rhs.signature && 15 | lhs.type == lhs.type 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/StateSectionHeaderView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StateSectionHeaderView.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 07/01/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class StateSectionHeaderView: UITableViewHeaderFooterView { 12 | 13 | @IBOutlet weak var nameLabel: UILabel! 14 | @IBOutlet weak var nonceLabel: UILabel! 15 | @IBOutlet weak var pubKeyHashLabel: UILabel! 16 | } 17 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/DefaultProvider+ContractAddress.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Provider+ContractAddress.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | 10 | extension DefaultProvider { 11 | public func contractAddress(queue: DispatchQueue, completion: @escaping (ZKSyncResult) -> Void) { 12 | transport.send(method: "contract_address", params: [String](), queue: queue, completion: completion) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/DefaultProvider+EthOpInfo.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultProvider+EthOpInfo.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | extension DefaultProvider { 11 | 12 | public func ethOpInfo(priority: Int, 13 | completion: @escaping (ZKSyncResult) -> Void) { 14 | self.transport.send(method: "ethop_info", params: [priority], completion: completion) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Sources/ZKSync/Transport/Response.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Response.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | 10 | struct JRPCResponse: Decodable { 11 | /// The rpc id 12 | public let id: Int 13 | 14 | /// The jsonrpc version. Typically 2.0 15 | public let jsonrpc: String 16 | 17 | /// The result 18 | public let result: T? 19 | 20 | /// The error 21 | public let error: JRPCError? 22 | } 23 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Auth/ChangePubKeyOnchain.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChangePubKeyOnchain.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/03/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct ChangePubKeyOnchain: ChangePubKeyVariant { 11 | 12 | public let type: ChangePubKeyAuthType = .onchain 13 | public let bytes: Data = Data(repeating: 0, count: 32) 14 | 15 | public init() {} 16 | 17 | enum CodingKeys: String, CodingKey { 18 | case type 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Transactions/Batch/TransactionSignaturePair.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionSignaturePair.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct TransactionSignaturePair: Encodable { 11 | 12 | let tx: ZkSyncTransaction 13 | let signature: EthSignature? 14 | 15 | public init(tx: ZkSyncTransaction, signature: EthSignature?) { 16 | self.tx = tx 17 | self.signature = signature 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/DefaultProvider+ConfirmationsForEthOpAmount.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultProvider+ConfirmationsForEthOpAmount.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | extension DefaultProvider { 11 | public func confirmationsForEthOpAmount(completion: @escaping (ZKSyncResult) -> Void) { 12 | transport.send(method: "get_confirmations_for_eth_op_amount", params: [String](), completion: completion) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/DefaultProvider+EthTxForWithdrawal.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultProvider+EthTxForWithdrawal.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 22/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | extension DefaultProvider { 11 | public func ethTxForWithdrawal(withdrawalHash: String, completion: @escaping (ZKSyncResult) -> Void) { 12 | return transport.send(method: "get_eth_tx_for_withdrawal", params: [withdrawalHash], completion: completion) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ZKSyncExample 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import UIKit 9 | 10 | @UIApplicationMain 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | var window: UIWindow? 14 | 15 | func application(_ application: UIApplication, 16 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | return true 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/TransactionFee/TransactionTypeAddressPair.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionTypeAddressPair.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 08/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct TransactionTypeAddressPair { 11 | 12 | let transactionType: TransactionType 13 | let address: String 14 | 15 | public init(transactionType: TransactionType, address: String) { 16 | self.transactionType = transactionType 17 | self.address = address 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/DefaultProvider+TransactionDetails.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultProvider+TransactionDetails.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | extension DefaultProvider { 11 | 12 | public func transactionDetails(txHash: String, 13 | completion: @escaping (ZKSyncResult) -> Void) { 14 | transport.send(method: "tx_info", params: [txHash], completion: completion) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Release Swift library 2 | 3 | on: 4 | push: 5 | tags: 6 | - "*" 7 | 8 | env: 9 | GITHUB_REF: "${{ github.ref }}" 10 | 11 | jobs: 12 | build: 13 | 14 | runs-on: macOS-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v1 18 | 19 | - name: Install Cocoapods 20 | run: gem install cocoapods 21 | 22 | # shortcut version 23 | - uses: michaelhenry/deploy-to-cocoapods-github-action@1.0.9 24 | env: 25 | COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} 26 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/TimeRange.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TimeRange.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/03/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct TimeRange: Decodable { 11 | public var validFrom: UInt64 12 | public var validUntil: UInt64 13 | 14 | public init(validFrom: UInt64, validUntil: UInt64) { 15 | self.validFrom = validFrom 16 | self.validUntil = validUntil 17 | } 18 | 19 | public static var max: TimeRange { TimeRange(validFrom: 0, validUntil: 4294967295) } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/TransactionFee/TransactionFeeDetails.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionFeeDetails.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 08/01/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public struct TransactionFeeDetails: Codable { 12 | 13 | public var gasTxAmount: String? 14 | public var gasPriceWei: String? 15 | public var gasFee: String? 16 | public var zkpFee: String? 17 | public var totalFee: String 18 | 19 | public var totalFeeInteger: BigUInt { BigUInt(totalFee)! } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/ZKSync/Wallet/SignedTransaction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SignedTransaction.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 13/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct SignedTransaction where T: ZkSyncTransaction { 11 | public let transaction: T 12 | public let ethereumSignature: EthSignature? 13 | } 14 | 15 | extension SignedTransaction: Encodable { 16 | 17 | enum CodingKeys: String, CodingKey { 18 | case transaction = "tx" 19 | case ethereumSignature = "signature" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/TransactionFee/TransactionFeeRequest+Encoding.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionFeeRequest+Encoding.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 08/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | extension TransactionFeeRequest: Encodable { 11 | 12 | public func encode(to encoder: Encoder) throws { 13 | var container = encoder.unkeyedContainer() 14 | try container.encode(transactionType) 15 | try container.encode(address) 16 | try container.encode(tokenIdentifier) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Transactions/Batch/TransactionBatchRequest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionBatchRequest.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | struct TransactionBatchRequest: Encodable { 11 | 12 | let txs: [TransactionSignaturePair] 13 | let ethereumSignature: EthSignature? 14 | 15 | func encode(to encoder: Encoder) throws { 16 | var container = encoder.unkeyedContainer() 17 | try container.encode(txs) 18 | try container.encode(ethereumSignature) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Maxim Makhun on 6/27/21. 6 | // 7 | 8 | import UIKit 9 | import ZKSync 10 | import ZKSyncCrypto 11 | 12 | class ViewController: UIViewController { 13 | 14 | override func viewDidLoad() { 15 | super.viewDidLoad() 16 | 17 | // Make sure that `ZKSync` symbols are available. 18 | let _: Wallet? = nil 19 | 20 | // Make sure that `ZKSyncCrypto` symbols are available. 21 | _ = ZKSyncCrypto.generatePrivateKey(seed: Data()) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/DefaultProvider+TokenPrice.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Provider+TokenPrice.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | 10 | extension DefaultProvider { 11 | 12 | public func tokenPrice(token: Token, 13 | completion: @escaping (ZKSyncResult) -> Void) { 14 | transport.send(method: "get_token_price", 15 | params: [token.symbol]) { (result: ZKSyncResult) in 16 | completion(result.map({ Decimal(string: $0)! })) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/TransactionFee/TransactionType.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionType.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 08/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public enum TransactionType: String { 11 | case withdraw 12 | case transfer 13 | case fastWithdraw 14 | case changePubKeyOnchain 15 | case changePubKeyECDSA 16 | case changePubKeyCREATE2 17 | case legacyChangePubKey 18 | case legacyChangePubKeyOnchainAuth 19 | case forcedExit 20 | case swap 21 | case mintNFT 22 | case withdrawNFT 23 | case fastWithdrawNFT 24 | } 25 | -------------------------------------------------------------------------------- /Sources/ZKSync/Signer/Ethereum/EthSignature.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EthSignature.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 09/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct EthSignature: Encodable { 11 | 12 | public enum SignatureType: String, Encodable { 13 | case ethereumSignature = "EthereumSignature" 14 | case EIP1271Signature 15 | } 16 | 17 | let signature: String 18 | let type: SignatureType 19 | 20 | public init(signature: String, type: SignatureType) { 21 | self.signature = signature 22 | self.type = type 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/TransactionFee/TransactionFeeBatchRequest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionFeeBatchRequest.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 08/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct TransactionFeeBatchRequest { 11 | 12 | let transactionsAndAddresses: [TransactionTypeAddressPair] 13 | let tokenIdentifier: String 14 | 15 | public init(transactionsAndAddresses: [TransactionTypeAddressPair], 16 | tokenIdentifier: String) { 17 | self.transactionsAndAddresses = transactionsAndAddresses 18 | self.tokenIdentifier = tokenIdentifier 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/TransactionFee/TransactionFeeBatchRequest+Encoding.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionFeeBatchRequest+Encoding.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 08/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | extension TransactionFeeBatchRequest: Encodable { 11 | 12 | public func encode(to encoder: Encoder) throws { 13 | var container = encoder.unkeyedContainer() 14 | try container.encode(transactionsAndAddresses.map({ $0.transactionType })) 15 | try container.encode(transactionsAndAddresses.map({ $0.address })) 16 | try container.encode(tokenIdentifier) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Headers/ZKSyncCrypto.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZKSyncCrypto.h 3 | // ZKSyncCrypto 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | #import 9 | 10 | //! Project version number for ZKSyncCrypto. 11 | FOUNDATION_EXPORT double ZKSyncCryptoVersionNumber; 12 | 13 | //! Project version string for ZKSyncCrypto. 14 | FOUNDATION_EXPORT const unsigned char ZKSyncCryptoVersionString[]; 15 | 16 | // In this header, you should import all the public headers of your framework using statements like #import 17 | 18 | #import "zks_crypto.h" 19 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Headers/ZKSyncCrypto.h: -------------------------------------------------------------------------------- 1 | // 2 | // ZKSyncCrypto.h 3 | // ZKSyncCrypto 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | #import 9 | 10 | //! Project version number for ZKSyncCrypto. 11 | FOUNDATION_EXPORT double ZKSyncCryptoVersionNumber; 12 | 13 | //! Project version string for ZKSyncCrypto. 14 | FOUNDATION_EXPORT const unsigned char ZKSyncCryptoVersionString[]; 15 | 16 | // In this header, you should import all the public headers of your framework using statements like #import 17 | 18 | #import "zks_crypto.h" 19 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Token/NFT.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NFT.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/05/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public struct NFT: TokenId, Decodable { 12 | 13 | public let id: UInt32 14 | public let symbol: String 15 | let creatorId: UInt32 16 | let contentHash: String 17 | 18 | let creatorAddress: String 19 | 20 | let serialId: UInt32 21 | 22 | let address: String 23 | 24 | public func intoDecimal(_ amount: BigUInt) -> Decimal { 25 | let sourceDecimal = Decimal(string: "\(amount)")! 26 | return sourceDecimal / pow(Decimal(1), 1) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/DefaultProvider+Tokens.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultProvider+Tokens.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 13/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | extension DefaultProvider { 11 | public func tokens(completion: @escaping (ZKSyncResult) -> Void) { 12 | if let tokens = self.tokensCache { 13 | completion(.success(tokens)) 14 | } else { 15 | self.transport.send(method: "tokens", params: [String]()) { (result: TransportResult) in 16 | self.tokensCache = try? result.get() 17 | completion(result) 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Auth/Toggle2FA.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Toggle2FA.swift 3 | // ZKSync 4 | // 5 | // Created by Maxim Makhun on 8/25/21. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct Toggle2FA: Encodable { 11 | 12 | public var enable: Bool 13 | 14 | public var accountId: UInt32 15 | 16 | public var timestamp: Int64 17 | 18 | public var signature: EthSignature 19 | 20 | public init( 21 | enable: Bool, 22 | accountId: UInt32, 23 | timestamp: Int64, 24 | signature: EthSignature 25 | ) { 26 | self.enable = enable 27 | self.accountId = accountId 28 | self.timestamp = timestamp 29 | self.signature = signature 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/ZKSync/Types/ZKSyncError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Error.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | 10 | public enum ZKSyncError: LocalizedError { 11 | case emptyResponse 12 | case invalidStatusCode(code: Int) 13 | 14 | case rpcError(code: Int, message: String) 15 | 16 | public var errorDescription: String? { 17 | switch self { 18 | case .rpcError(let code, let message): 19 | return "\(message) (\(code))" 20 | case .emptyResponse: 21 | return "Response is empty" 22 | case .invalidStatusCode(let code): 23 | return "Invalid status code: \(code)" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | name: Test Swift library 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | push: 8 | branches: 9 | - master 10 | - develop 11 | 12 | jobs: 13 | test: 14 | runs-on: macos-11 15 | 16 | steps: 17 | - uses: actions/checkout@v1 18 | 19 | - name: Install Cocoapods 20 | run: gem install cocoapods 21 | 22 | - name: Install deps 23 | working-directory: ./Examples/CocoaPods 24 | run: pod install 25 | 26 | - name: Run tests 27 | working-directory: ./Examples/CocoaPods 28 | run: xcodebuild -workspace ZKSyncExample.xcworkspace -scheme ZKSyncExample -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 13 Pro Max,OS=15.2' test 29 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/Transactions/TransactionRequest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionRequest.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 13/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | struct TransactionRequest: Encodable { 11 | 12 | let tx: Transaction 13 | let ethereumSignature: EthSignature? 14 | let fastProcessing: Bool 15 | 16 | func encode(to encoder: Encoder) throws { 17 | var container = encoder.unkeyedContainer() 18 | try container.encode(tx) 19 | if let signature = ethereumSignature { 20 | try container.encode(signature) 21 | } else { 22 | try container.encodeNil() 23 | } 24 | try container.encode(fastProcessing) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/ZKSync/Extensions/BinaryInteger+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BinaryInteger+Extensions.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 11/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | extension BinaryInteger { 11 | func bytes() -> Data { 12 | return withUnsafeBytes(of: self) { Data($0) } 13 | } 14 | 15 | } 16 | 17 | extension FixedWidthInteger { 18 | func bytesBE() -> Data { 19 | return self.bigEndian.bytes() 20 | } 21 | } 22 | 23 | extension UInt8 { 24 | var bitReversed: UInt8 { 25 | var byte = self 26 | byte = ((byte & 0xf0) >> 4) | ((byte & 0x0f) << 4) 27 | byte = ((byte & 0xcc) >> 2) | ((byte & 0x33) << 2) 28 | byte = ((byte & 0xaa) >> 1) | ((byte & 0x55) << 1) 29 | return byte 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Auth/ChangePubKeyECDSA.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChangePubKeyECDSA.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/03/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct ChangePubKeyECDSA: ChangePubKeyVariant { 11 | 12 | public let type: ChangePubKeyAuthType = .ECDSA 13 | 14 | public var ethSignature: String? 15 | public var batchHash: String 16 | 17 | public var bytes: Data { 18 | return Data(hex: batchHash) 19 | } 20 | 21 | public init( 22 | ethSignature: String?, 23 | batchHash: String 24 | ) { 25 | self.ethSignature = ethSignature 26 | self.batchHash = batchHash 27 | } 28 | 29 | enum CodingKeys: String, CodingKey { 30 | case type 31 | case ethSignature 32 | case batchHash 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/ViewControllers/DepositingBalanceTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DepositingBalanceTableViewCell.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 08/01/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DepositingBalanceTableViewCell: UITableViewCell { 12 | 13 | @IBOutlet weak var titleLabel: UILabel! 14 | @IBOutlet weak var amountLabel: UILabel! 15 | @IBOutlet weak var blockNumber: UILabel! 16 | override func awakeFromNib() { 17 | super.awakeFromNib() 18 | // Initialization code 19 | } 20 | 21 | override func setSelected(_ selected: Bool, animated: Bool) { 22 | super.setSelected(selected, animated: animated) 23 | 24 | // Configure the view for the selected state 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/ViewControllers/TokenPriceViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TokenPriceViewController.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 07/01/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ZKSync 11 | 12 | class TokenPriceViewController: UIViewController, WalletConsumer { 13 | 14 | var wallet: Wallet! 15 | 16 | @IBOutlet weak var tokenPriceLabel: UILabel! 17 | 18 | @IBAction func getTokenPRice(_ sender: Any) { 19 | wallet.provider.tokenPrice(token: Token.ETH) { (result) in 20 | switch result { 21 | case .success(let price): 22 | self.tokenPriceLabel.text = "\(price)" 23 | case .failure(let error): 24 | print("Error occured: \(error.localizedDescription)") 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Maxim Makhun on 6/27/21. 6 | // 7 | 8 | import UIKit 9 | 10 | @main 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | func application(_ application: UIApplication, 14 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 15 | return true 16 | } 17 | 18 | // MARK: UISceneSession Lifecycle 19 | 20 | func application(_ application: UIApplication, 21 | configurationForConnecting connectingSceneSession: UISceneSession, 22 | options: UIScene.ConnectionOptions) -> UISceneConfiguration { 23 | return UISceneConfiguration(name: "Default Configuration", 24 | sessionRole: connectingSceneSession.role) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/ZKSync/Transport/Transport.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Transport.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | 10 | public typealias TransportResult = Result 11 | 12 | public protocol Transport { 13 | 14 | func send(method: String, 15 | params: Parameters?, 16 | completion: @escaping (TransportResult) -> Void) 17 | 18 | func send(method: String, 19 | params: Parameters?, 20 | queue: DispatchQueue, 21 | completion: @escaping (TransportResult) -> Void) 22 | } 23 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Auth/ChangePubKeyCREATE2.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChangePubKeyCREATE2.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/03/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct ChangePubKeyCREATE2: ChangePubKeyVariant { 11 | 12 | public let type: ChangePubKeyAuthType = .CREATE2 13 | 14 | public var creatorAddress: String 15 | public var saltArg: String 16 | public var codeHash: String 17 | 18 | public let bytes = Data(repeating: 0, count: 32) 19 | 20 | public init( 21 | creatorAddress: String, 22 | saltArg: String, 23 | codeHash: String 24 | ) { 25 | self.creatorAddress = creatorAddress 26 | self.saltArg = saltArg 27 | self.codeHash = codeHash 28 | } 29 | 30 | enum CodingKeys: String, CodingKey { 31 | case type 32 | case creatorAddress 33 | case saltArg 34 | case codeHash 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata/ 15 | *.xccheckout 16 | profile 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | 22 | # Bundler 23 | .bundle 24 | 25 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 26 | # Carthage/Checkouts 27 | 28 | Carthage/Build 29 | 30 | # We recommend against adding the Pods directory to your .gitignore. However 31 | # you should judge for yourself, the pros and cons are mentioned at: 32 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 33 | # 34 | # Note: if you ignore the Pods directory, make sure to uncomment 35 | # `pod install` in .travis.yml 36 | # 37 | Pods/ 38 | 39 | # Swift Package Manager 40 | .build/ 41 | .swiftpm/ -------------------------------------------------------------------------------- /Sources/ZKSync/Model/AccountState.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AccountState.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 06/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public struct AccountState: Decodable { 11 | public struct Balance: Decodable { 12 | public var amount: String 13 | public var expectedAcceptBlock: UInt64 14 | } 15 | 16 | public struct Depositing: Decodable { 17 | public var balances: [String: Balance] 18 | } 19 | 20 | public struct State: Decodable { 21 | public var nonce: UInt32 22 | public var pubKeyHash: String 23 | public var balances: [String: String] 24 | public var nfts: [String: NFT]? 25 | public var mintedNfts: [String: NFT]? 26 | } 27 | 28 | public var address: String 29 | public var id: UInt32? 30 | 31 | public var depositing: Depositing 32 | public var committed: State 33 | public var verified: State 34 | } 35 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/DefaultProvider+Accounts.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Provider+Accounts.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | 10 | extension DefaultProvider { 11 | 12 | public func accountState(address: String, 13 | completion: @escaping (ZKSyncResult) -> Void) { 14 | self.accountState(address: address, 15 | queue: .main, 16 | completion: completion) 17 | } 18 | 19 | public func accountState(address: String, 20 | queue: DispatchQueue, 21 | completion: @escaping (ZKSyncResult) -> Void) { 22 | self.transport.send(method: "account_info", 23 | params: [address], 24 | queue: queue, 25 | completion: completion) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Sources/ZKSync/Transport/Request.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Request.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | 10 | struct JRPCCounter { 11 | static var counter = UInt64(1) 12 | static var lockQueue = DispatchQueue(label: "counterQueue") 13 | static func increment() -> UInt64 { 14 | var nextValue: UInt64 = 0 15 | lockQueue.sync { 16 | nextValue = JRPCCounter.counter 17 | JRPCCounter.counter += 1 18 | } 19 | 20 | return nextValue 21 | } 22 | } 23 | 24 | struct JRPCRequest: Encodable { 25 | /// The rpc id 26 | public let id: UInt64 = JRPCCounter.increment() 27 | 28 | /// The jsonrpc version. Typically 2.0 29 | public let jsonrpc: String = "2.0" 30 | 31 | /// The jsonrpc method to be called 32 | public let method: String 33 | 34 | /// The jsonrpc parameters 35 | public let params: T? 36 | } 37 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/TransactionFee/DefaultProvider+TransactionFee.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Provider+TransactionFee.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | 10 | extension DefaultProvider { 11 | 12 | public func transactionFee(request: TransactionFeeRequest, 13 | completion: @escaping (ZKSyncResult) -> Void) { 14 | self.transport.send(method: "get_tx_fee", 15 | params: request, 16 | completion: completion) 17 | } 18 | 19 | public func transactionFee(request: TransactionFeeBatchRequest, 20 | completion: @escaping (ZKSyncResult) -> Void) { 21 | self.transport.send(method: "get_txs_batch_fee_in_wei", 22 | params: request, 23 | completion: completion) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Token/Token.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Token.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 06/01/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public struct Token: TokenId, Decodable { 12 | 13 | public static let DefaultAddress = "0x0000000000000000000000000000000000000000" 14 | 15 | public let id: UInt32 16 | public let address: String 17 | public let symbol: String 18 | let decimals: Int 19 | 20 | public static var ETH: Token { 21 | return Token(id: 0, 22 | address: Token.DefaultAddress, 23 | symbol: "ETH", 24 | decimals: 18) 25 | } 26 | 27 | public func intoDecimal(_ amount: BigUInt) -> Decimal { 28 | let sourceDecimal = Decimal(string: "\(amount)")! 29 | return sourceDecimal / pow(Decimal(10), decimals) 30 | } 31 | 32 | var isETH: Bool { 33 | return (address == Token.DefaultAddress && symbol == "ETH") 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ZKSync.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'ZKSync' 3 | s.version = '0.0.3' 4 | s.summary = 'Swift SDK for zkSync' 5 | 6 | s.description = <<-DESC 7 | zkSync is a scaling and privacy engine for Ethereum. Its current functionality scope includes low gas transfers of ETH and ERC20 tokens in the Ethereum network. 8 | DESC 9 | 10 | s.homepage = "https://github.com/zksync-sdk/zksync-swift" 11 | s.license = { :type => 'MIT', :file => 'LICENSE' } 12 | 13 | s.author = { "The Matter Labs team" => "hello@matterlabs.dev" } 14 | 15 | s.ios.deployment_target = "11.0" 16 | s.swift_version = '5.0' 17 | 18 | s.source = { :git => "https://github.com/zksync-sdk/zksync-swift.git", :tag => "#{s.version}" } 19 | 20 | s.dependency 'ZKSyncCrypto', '0.0.9-spm' 21 | s.dependency 'Alamofire', '~> 5.0' 22 | s.dependency 'web3swift', '~> 2.5.0' 23 | 24 | s.source_files = 'Sources/ZKSync/**/*' 25 | end 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Matter Labs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "size" : "1024x1024", 46 | "scale" : "1x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/ViewControllers/ContractAddressViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContractAddressViewController.swift 3 | // ZKSyncExample 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import UIKit 9 | import ZKSync 10 | 11 | class ContractAddressViewController: UIViewController, WalletConsumer { 12 | 13 | var wallet: Wallet! 14 | 15 | @IBOutlet weak var mainContractLabel: UILabel! 16 | @IBOutlet weak var govContractLabel: UILabel! 17 | 18 | @IBAction func getContractAddress(_ sender: Any) { 19 | self.wallet.provider.contractAddress { result in 20 | switch result { 21 | case .success(let address): 22 | self.display(contractAddress: address) 23 | case .failure(let error): 24 | self.display(error: error) 25 | } 26 | } 27 | } 28 | 29 | private func display(contractAddress: ContractAddress) { 30 | self.mainContractLabel.text = contractAddress.mainContract 31 | self.govContractLabel.text = contractAddress.govContract 32 | } 33 | 34 | private func display(error: Error) { 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AvailableLibraries 6 | 7 | 8 | LibraryIdentifier 9 | ios-arm64_x86_64-simulator 10 | LibraryPath 11 | ZKSyncCrypto.framework 12 | SupportedArchitectures 13 | 14 | arm64 15 | x86_64 16 | 17 | SupportedPlatform 18 | ios 19 | SupportedPlatformVariant 20 | simulator 21 | 22 | 23 | LibraryIdentifier 24 | ios-arm64 25 | LibraryPath 26 | ZKSyncCrypto.framework 27 | SupportedArchitectures 28 | 29 | arm64 30 | 31 | SupportedPlatform 32 | ios 33 | 34 | 35 | CFBundlePackageType 36 | XFWK 37 | XCFrameworkFormatVersion 38 | 1.0 39 | 40 | 41 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.3 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "ZKSync", 8 | platforms: [ 9 | .iOS(.v13) 10 | ], 11 | products: [ 12 | .library( 13 | name: "ZKSync", 14 | targets: [ 15 | "ZKSync" 16 | ]), 17 | ], 18 | dependencies: [ 19 | .package( 20 | name: "Web3swift", 21 | url: "https://github.com/skywinder/web3swift.git", 22 | from: "2.5.0" 23 | ), 24 | .package( 25 | name: "Alamofire", 26 | url: "https://github.com/Alamofire/Alamofire.git", 27 | from: "5.4.3" 28 | ) 29 | ], 30 | targets: [ 31 | .target( 32 | name: "ZKSync", 33 | dependencies: [ 34 | "ZKSyncCrypto", 35 | .product(name: "web3swift", package: "Web3swift"), 36 | "Alamofire" 37 | ], 38 | path: "Sources/ZKSync"), 39 | .binaryTarget( 40 | name: "ZKSyncCrypto", 41 | path: "Dependencies/ZKSyncCrypto.xcframework"), 42 | ] 43 | ) 44 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZKSync for Swift 2 | 3 | Cryptographical primitives used in zkSync network. 4 | 5 | 6 | ## Requirements 7 | 8 | - iOS 11.0+ 9 | - Xcode 11+ 10 | - Swift 5.0+ 11 | 12 | 13 | ## Installation 14 | 15 | - CocoaPods: `pod 'ZKSync'` 16 | 17 | ## License 18 | 19 | The MIT License (MIT) 20 | 21 | Copyright (c) 2020 Matter Labs 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 24 | 25 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 26 | 27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/AccountState.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AccountState.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Maxim Makhun on 9/3/21. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import ZKSync 11 | 12 | extension AccountState: Equatable { 13 | 14 | public static func == (lhs: AccountState, rhs: AccountState) -> Bool { 15 | return lhs.address == rhs.address && 16 | lhs.id == rhs.id && 17 | lhs.depositing == rhs.depositing && 18 | lhs.committed == rhs.committed && 19 | lhs.verified == rhs.verified 20 | } 21 | } 22 | 23 | extension AccountState.Depositing: Equatable { 24 | 25 | public static func == (lhs: AccountState.Depositing, rhs: AccountState.Depositing) -> Bool { 26 | return lhs.balances == rhs.balances 27 | } 28 | } 29 | 30 | extension AccountState.Balance: Equatable { 31 | 32 | public static func == (lhs: AccountState.Balance, rhs: AccountState.Balance) -> Bool { 33 | return lhs.amount == rhs.amount && 34 | lhs.expectedAcceptBlock == rhs.expectedAcceptBlock 35 | } 36 | } 37 | 38 | extension AccountState.State: Equatable { 39 | 40 | public static func == (lhs: AccountState.State, rhs: AccountState.State) -> Bool { 41 | return lhs.nonce == rhs.nonce && 42 | lhs.pubKeyHash == rhs.pubKeyHash && 43 | lhs.balances == rhs.balances 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/Transactions/DefaultProvider+Transactions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultProvider+Transactions.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 13/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | extension DefaultProvider { 11 | 12 | public func submitTx(_ tx: ZkSyncTransaction, 13 | ethereumSignature: EthSignature?, 14 | fastProcessing: Bool, 15 | completion: @escaping (ZKSyncResult) -> Void) { 16 | let request = TransactionRequest(tx: tx, 17 | ethereumSignature: ethereumSignature, 18 | fastProcessing: fastProcessing) 19 | self.transport.send(method: "tx_submit", 20 | params: request, 21 | completion: completion) 22 | } 23 | 24 | public func submitTxBatch(txs: [TransactionSignaturePair], 25 | ethereumSignature: EthSignature?, 26 | completion: @escaping (ZKSyncResult<[String]>) -> Void) { 27 | let request = TransactionBatchRequest(txs: txs, 28 | ethereumSignature: ethereumSignature) 29 | self.transport.send(method: "submit_txs_batch", 30 | params: request, 31 | completion: completion) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/ZKSync/Wallet/DefaultWallet+Order.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultWallet+Order.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 09/06/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | extension DefaultWallet { 12 | 13 | // swiftlint:disable:next function_parameter_count 14 | public func buildSignedOrder(recepient: String, 15 | sell: Token, 16 | buy: Token, 17 | ratio: (BigUInt, BigUInt), 18 | amount: BigUInt, 19 | nonce: UInt32, 20 | timeRange: TimeRange) throws -> Order { 21 | 22 | guard let accountId = self.accountId else { 23 | throw DefaultWalletError.noAccountId 24 | } 25 | 26 | var order = Order(accountId: accountId, 27 | recepientAddress: recepient, 28 | nonce: nonce, 29 | tokenBuy: buy.id, 30 | tokenSell: sell.id, 31 | ratio: ratio, 32 | amount: amount, 33 | timeRange: timeRange) 34 | let ethSignature = try ethSigner.signOrder(order, tokenSell: sell, tokenBuy: buy) 35 | order.ethereumSignature = ethSignature 36 | 37 | return try self.zkSigner.sign(order: order) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/ZKSync/Signer/Ethereum/EthSigner.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EthSigner.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 06/01/2021. 6 | // 7 | 8 | import Foundation 9 | import web3swift 10 | import BigInt 11 | 12 | public protocol EthSigner { 13 | 14 | // swiftlint:disable:next type_name 15 | associatedtype A: ChangePubKeyVariant 16 | 17 | var address: String { get } 18 | 19 | var ethereumAddress: EthereumAddress { get } 20 | 21 | var keystore: AbstractKeystore { get } 22 | 23 | func signAuth(changePubKey: ChangePubKey) throws -> ChangePubKey 24 | 25 | func signTransaction(transaction: T, 26 | nonce: UInt32, 27 | token: Token, 28 | fee: BigUInt) throws -> EthSignature? 29 | 30 | func signOrder(_ order: Order, 31 | tokenSell: Token, 32 | tokenBuy: Token) throws -> EthSignature 33 | 34 | func sign(message: Data) throws -> EthSignature 35 | 36 | func signBatch(transactions: [ZkSyncTransaction], 37 | nonce: UInt32, 38 | token: Token, 39 | fee: BigUInt) throws -> EthSignature 40 | 41 | func verifySignature(_ signature: EthSignature, 42 | message: Data) throws -> Bool 43 | 44 | func signToggle(_ enable: Bool, 45 | timestamp: Int64) throws -> EthSignature 46 | } 47 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/Swap.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Swap.swift 3 | // ZKSyncExampleTests 4 | // 5 | // Created by Maxim Makhun on 9/3/21. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | @testable import ZKSync 10 | 11 | extension Swap: Equatable { 12 | 13 | static var defaultTX: Swap { 14 | return Swap(submitterId: 5, 15 | submitterAddress: "0xede35562d3555e61120a151b3c8e8e91d83a378a", 16 | nonce: 1, 17 | orders: (Order.defaultOrderA, Order.defaultOrderB), 18 | amounts: (1000000, 2500000), 19 | fee: "123", 20 | feeToken: 3, 21 | signature: Signature(pubKey: "40771354dc314593e071eaf4d0f42ccb1fad6c7006c57464feeb7ab5872b7490", 22 | // swiftlint:disable:next line_length 23 | signature: "c13aabacf96448efb47763554753bfe2acc303a8297c8af59e718d685d422a901a43c42448f95cca632821df1ccb754950196e8444c0acef253c42c1578b5401")) 24 | } 25 | 26 | public static func == (lhs: Swap, rhs: Swap) -> Bool { 27 | return lhs.submitterId == rhs.submitterId && 28 | lhs.submitterAddress == rhs.submitterAddress && 29 | lhs.nonce == rhs.nonce && 30 | lhs.orders == rhs.orders && 31 | lhs.amounts == rhs.amounts && 32 | lhs.fee == rhs.fee && 33 | lhs.feeToken == rhs.feeToken && 34 | lhs.signature?.pubKey == rhs.signature?.pubKey && 35 | lhs.signature?.signature == rhs.signature?.signature 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/ForcedExit.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ForcedExit.swift 3 | // ZKSyncExampleTests 4 | // 5 | // Created by Maxim Makhun on 9/3/21. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | @testable import ZKSync 10 | 11 | extension ForcedExit: Equatable { 12 | 13 | static var defaultTX: ForcedExit { 14 | let forcedExit = ForcedExit(initiatorAccountId: 44, 15 | target: "0x19aa2ed8712072e918632259780e587698ef58df", 16 | token: 0, 17 | fee: "1000000", 18 | nonce: 12, 19 | timeRange: .max) 20 | forcedExit.signature = Signature(pubKey: "40771354dc314593e071eaf4d0f42ccb1fad6c7006c57464feeb7ab5872b7490", 21 | // swiftlint:disable:next line_length 22 | signature: "b1b82f7ac37e2d4bd675e4a5cd5e48d9fad1739282db8a979c3e4d9e39d794915667ee2c125ba24f4fe81ad6d19491eef0be849a823ea6567517b7e207214705") 23 | return forcedExit 24 | } 25 | 26 | public static func == (lhs: ForcedExit, rhs: ForcedExit) -> Bool { 27 | return lhs.initiatorAccountId == rhs.initiatorAccountId && 28 | lhs.target == rhs.target && 29 | lhs.token == rhs.token && 30 | lhs.fee == rhs.fee && 31 | lhs.nonce == rhs.nonce && 32 | lhs.timeRange.validFrom == rhs.timeRange.validFrom && 33 | lhs.timeRange.validUntil == rhs.timeRange.validUntil && 34 | lhs.signature?.pubKey == rhs.signature?.pubKey && 35 | lhs.signature?.signature == rhs.signature?.signature 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/ViewControllers/DepositViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DepositViewController.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 03/02/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ZKSync 11 | import web3swift 12 | import PromiseKit 13 | 14 | class DepositViewController: UIViewController, WalletConsumer { 15 | 16 | var wallet: Wallet! 17 | 18 | @IBOutlet weak var amountTextField: UITextField! 19 | 20 | @IBAction func deposit(_ sender: Any) { 21 | 22 | amountTextField.resignFirstResponder() 23 | 24 | guard let amountText = amountTextField.text, 25 | let amount = Web3.Utils.parseToBigUInt(amountText, units: .eth), 26 | amount > 0 else { 27 | 28 | self.present(UIAlertController.forIncorrectAmount(), animated: true, completion: nil) 29 | return 30 | } 31 | 32 | do { 33 | let ethereumProvider = try self.wallet.createEthereumProvider(web3: Web3.InfuraRinkebyWeb3()) 34 | 35 | firstly { 36 | ethereumProvider.deposit(token: .ETH, 37 | amount: amount, 38 | userAddress: wallet.address) 39 | }.done { (_) in 40 | self.present(UIAlertController.for(message: "Successfully deposited"), animated: true, completion: nil) 41 | }.catch { (error) in 42 | self.present(UIAlertController.for(error: error), animated: true, completion: nil) 43 | } 44 | } catch { 45 | self.present(UIAlertController.for(error: error), animated: true, completion: nil) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/MintNFT.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MintNFT.swift 3 | // ZKSyncExampleTests 4 | // 5 | // Created by Maxim Makhun on 9/3/21. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | @testable import ZKSync 10 | 11 | extension MintNFT: Equatable { 12 | 13 | static var defaultTX: MintNFT { 14 | let mintNFT = MintNFT(creatorId: 44, 15 | creatorAddress: "0xede35562d3555e61120a151b3c8e8e91d83a378a", 16 | contentHash: "0x0000000000000000000000000000000000000000000000000000000000000123", 17 | recipient: "0x19aa2ed8712072e918632259780e587698ef58df", 18 | fee: "1000000", 19 | feeToken: 0, 20 | nonce: 12) 21 | mintNFT.signature = Signature(pubKey: "40771354dc314593e071eaf4d0f42ccb1fad6c7006c57464feeb7ab5872b7490", 22 | // swiftlint:disable:next line_length 23 | signature: "5cf4ef4680d58e23ede08cc2f8dd33123c339788721e307a813cdf82bc0bac1c10bc861c68d0b5328e4cb87b610e4dfdc13ddf8a444a4a2ac374ac3c73dbec05") 24 | return mintNFT 25 | } 26 | 27 | public static func == (lhs: MintNFT, rhs: MintNFT) -> Bool { 28 | return lhs.creatorId == rhs.creatorId && 29 | lhs.creatorAddress == rhs.creatorAddress && 30 | lhs.contentHash == rhs.contentHash && 31 | lhs.recipient == rhs.recipient && 32 | lhs.fee == rhs.fee && 33 | lhs.feeToken == rhs.feeToken && 34 | lhs.nonce == rhs.nonce && 35 | lhs.signature?.pubKey == rhs.signature?.pubKey && 36 | lhs.signature?.signature == rhs.signature?.signature 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Token/Tokens.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Tokens.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 13/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public enum TokensError: Error { 11 | case noTokenWithAddress(String) 12 | } 13 | 14 | public struct Tokens: Decodable { 15 | 16 | private var tokens: [String: Token] 17 | 18 | public func tokenBySymbol(_ symbol: String) -> Token? { 19 | return tokens[symbol] 20 | } 21 | 22 | public func tokenByAddress(_ address: String) throws -> Token { 23 | let record = tokens.first { (_, token) -> Bool in 24 | return token.address == address 25 | } 26 | guard let token = record?.value else { 27 | throw TokensError.noTokenWithAddress(address) 28 | } 29 | return token 30 | } 31 | 32 | public func tokenByTokenIdentifier(_ identifier: String) throws -> Token { 33 | guard let symbol = tokenBySymbol(identifier) else { 34 | return try tokenByAddress(identifier) 35 | } 36 | return symbol 37 | } 38 | 39 | public init(from decoder: Decoder) throws { 40 | tokens = [:] 41 | let container = try decoder.container(keyedBy: DynamicKey.self) 42 | for key in container.allKeys { 43 | tokens[key.stringValue] = try container.decode(Token.self, forKey: key) 44 | } 45 | } 46 | 47 | internal init(tokens: [String: Token]) { 48 | self.tokens = tokens 49 | } 50 | 51 | struct DynamicKey: CodingKey { 52 | var intValue: Int? 53 | init?(intValue: Int) { 54 | return nil 55 | } 56 | var stringValue: String 57 | init?(stringValue: String) { 58 | self.stringValue = stringValue 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Alamofire (5.6.2) 3 | - BigInt (5.2.0) 4 | - CryptoSwift (1.4.3) 5 | - PromiseKit (6.15.3): 6 | - PromiseKit/CorePromise (= 6.15.3) 7 | - PromiseKit/Foundation (= 6.15.3) 8 | - PromiseKit/UIKit (= 6.15.3) 9 | - PromiseKit/CorePromise (6.15.3) 10 | - PromiseKit/Foundation (6.15.3): 11 | - PromiseKit/CorePromise 12 | - PromiseKit/UIKit (6.15.3): 13 | - PromiseKit/CorePromise 14 | - secp256k1.c (0.1.2) 15 | - Starscream (4.0.4) 16 | - web3swift (2.5.1): 17 | - BigInt (~> 5.2.0) 18 | - CryptoSwift (~> 1.4.2) 19 | - PromiseKit (~> 6.15.3) 20 | - secp256k1.c (~> 0.1) 21 | - Starscream (~> 4.0.4) 22 | - ZKSync (0.0.3): 23 | - Alamofire (~> 5.0) 24 | - web3swift (~> 2.5.0) 25 | - ZKSyncCrypto (= 0.0.9-spm) 26 | - ZKSyncCrypto (0.0.9-spm) 27 | 28 | DEPENDENCIES: 29 | - ZKSync (from `../../`) 30 | 31 | SPEC REPOS: 32 | trunk: 33 | - Alamofire 34 | - BigInt 35 | - CryptoSwift 36 | - PromiseKit 37 | - secp256k1.c 38 | - Starscream 39 | - web3swift 40 | - ZKSyncCrypto 41 | 42 | EXTERNAL SOURCES: 43 | ZKSync: 44 | :path: "../../" 45 | 46 | SPEC CHECKSUMS: 47 | Alamofire: d368e1ff8a298e6dde360e35a3e68e6c610e7204 48 | BigInt: f668a80089607f521586bbe29513d708491ef2f7 49 | CryptoSwift: a0799ee936271bd2253a006f1e4523df21845000 50 | PromiseKit: 3b2b6995e51a954c46dbc550ce3da44fbfb563c5 51 | secp256k1.c: db47b726585d80f027423682eb369729e61b3b20 52 | Starscream: 5178aed56b316f13fa3bc55694e583d35dd414d9 53 | web3swift: 1071b71d9ac73147464110404c67901e642f4247 54 | ZKSync: 51baca54847c46220571efdf9fa80099372117ff 55 | ZKSyncCrypto: ff0662eb0cff69ab3e40564a45a07cbcafe1ccf0 56 | 57 | PODFILE CHECKSUM: 19f2bc7b77d611151be6a9850baac7dbb61b1e85 58 | 59 | COCOAPODS: 1.11.3 60 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/UIAlertController+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIAlertController+Extensions.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 03/02/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | extension UIAlertController { 13 | static func `for`(error: Error) -> UIAlertController { 14 | let alert = UIAlertController(title: "Error", 15 | message: (error as NSError).localizedDescription, 16 | preferredStyle: .alert) 17 | alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil)) 18 | return alert 19 | } 20 | 21 | static func `for`(message: String) -> UIAlertController { 22 | let alert = UIAlertController(title: nil, 23 | message: message, 24 | preferredStyle: .alert) 25 | alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil)) 26 | return alert 27 | } 28 | 29 | static func forIncorrectAmount() -> UIAlertController { 30 | let alert = UIAlertController(title: "Error", 31 | message: "Incorrect amount", 32 | preferredStyle: .alert) 33 | alert.addAction(.init(title: "OK", style: .cancel, handler: nil)) 34 | return alert 35 | } 36 | 37 | static func forIncorrectAddress() -> UIAlertController { 38 | let alert = UIAlertController(title: "Error", 39 | message: "Incorrect address", 40 | preferredStyle: .alert) 41 | alert.addAction(.init(title: "OK", style: .cancel, handler: nil)) 42 | return alert 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/Withdraw.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Withdraw.swift 3 | // ZKSyncExampleTests 4 | // 5 | // Created by Maksim Makhun on 9/3/21. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | @testable import ZKSync 10 | 11 | extension Withdraw: Equatable { 12 | 13 | static var defaultTX: Withdraw { 14 | let withdraw = Withdraw(accountId: 44, 15 | from: "0xede35562d3555e61120a151b3c8e8e91d83a378a", 16 | to: "0x19aa2ed8712072e918632259780e587698ef58df", 17 | token: 0, 18 | amount: 1000000000000, 19 | fee: "1000000", 20 | nonce: 12, 21 | timeRange: .max) 22 | withdraw.signature = Signature(pubKey: "40771354dc314593e071eaf4d0f42ccb1fad6c7006c57464feeb7ab5872b7490", 23 | // swiftlint:disable:next line_length 24 | signature: "11dc47fced9e6ffabe33112a4280c02d0c1ffa649ba3843eec256d427b90ed82e495c0cee2138d5a9e20328d31cb97b70d7e2ede0d8d967678803f4b5896f701") 25 | return withdraw 26 | } 27 | 28 | public static func == (lhs: Withdraw, rhs: Withdraw) -> Bool { 29 | return lhs.accountId == rhs.accountId && 30 | lhs.from == rhs.from && 31 | lhs.to == rhs.to && 32 | lhs.token == rhs.token && 33 | lhs.amount == rhs.amount && 34 | lhs.fee == rhs.fee && 35 | lhs.nonce == rhs.nonce && 36 | lhs.timeRange.validFrom == rhs.timeRange.validFrom && 37 | lhs.timeRange.validUntil == rhs.timeRange.validUntil && 38 | lhs.signature?.pubKey == rhs.signature?.pubKey && 39 | lhs.signature?.signature == rhs.signature?.signature 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/Transfer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Transfer.swift 3 | // ZKSyncExampleTests 4 | // 5 | // Created by Maxim Makhun on 9/3/21. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | @testable import ZKSync 10 | 11 | extension Transfer: Equatable { 12 | 13 | static var defaultTX: Transfer { 14 | let defaultTX = Transfer(accountId: 44, 15 | from: "0xede35562d3555e61120a151b3c8e8e91d83a378a", 16 | to: "0x19aa2ed8712072e918632259780e587698ef58df", 17 | token: 0, 18 | amount: 1000000000000, 19 | fee: "1000000", 20 | nonce: 12, 21 | timeRange: .max) 22 | defaultTX.signature = Signature(pubKey: "40771354dc314593e071eaf4d0f42ccb1fad6c7006c57464feeb7ab5872b7490", 23 | // swiftlint:disable:next line_length 24 | signature: "b3211c7e15d31d64619e0c7f65fce8c6e45637b5cfc8711478c5a151e6568d875ec7f48e040225fe3cc7f1e7294625cad6d98b4595d007d36ef62122de16ae01") 25 | return defaultTX 26 | } 27 | 28 | public static func == (lhs: Transfer, rhs: Transfer) -> Bool { 29 | return lhs.accountId == rhs.accountId && 30 | lhs.from == rhs.from && 31 | lhs.to == rhs.to && 32 | lhs.token == rhs.token && 33 | lhs.amount == rhs.amount && 34 | lhs.fee == rhs.fee && 35 | lhs.nonce == rhs.nonce && 36 | lhs.timeRange.validFrom == rhs.timeRange.validFrom && 37 | lhs.timeRange.validUntil == rhs.timeRange.validUntil && 38 | lhs.signature?.pubKey == rhs.signature?.pubKey && 39 | lhs.signature?.signature == rhs.signature?.signature 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "Alamofire", 6 | "repositoryURL": "https://github.com/Alamofire/Alamofire.git", 7 | "state": { 8 | "branch": null, 9 | "revision": "8dd85aee02e39dd280c75eef88ffdb86eed4b07b", 10 | "version": "5.6.2" 11 | } 12 | }, 13 | { 14 | "package": "BigInt", 15 | "repositoryURL": "https://github.com/attaswift/BigInt.git", 16 | "state": { 17 | "branch": null, 18 | "revision": "0ed110f7555c34ff468e72e1686e59721f2b0da6", 19 | "version": "5.3.0" 20 | } 21 | }, 22 | { 23 | "package": "CryptoSwift", 24 | "repositoryURL": "https://github.com/krzyzanowskim/CryptoSwift.git", 25 | "state": { 26 | "branch": null, 27 | "revision": "039f56c5d7960f277087a0be51f5eb04ed0ec073", 28 | "version": "1.5.1" 29 | } 30 | }, 31 | { 32 | "package": "PromiseKit", 33 | "repositoryURL": "https://github.com/mxcl/PromiseKit.git", 34 | "state": { 35 | "branch": null, 36 | "revision": "7b07b214dacecb22ca4b680531c7e981d52483f9", 37 | "version": "6.16.3" 38 | } 39 | }, 40 | { 41 | "package": "Starscream", 42 | "repositoryURL": "https://github.com/daltoniam/Starscream.git", 43 | "state": { 44 | "branch": null, 45 | "revision": "df8d82047f6654d8e4b655d1b1525c64e1059d21", 46 | "version": "4.0.4" 47 | } 48 | }, 49 | { 50 | "package": "Web3swift", 51 | "repositoryURL": "https://github.com/skywinder/web3swift.git", 52 | "state": { 53 | "branch": null, 54 | "revision": "4312a7178e1255c3ef65ac909657d29f6dd81bb6", 55 | "version": "2.6.6" 56 | } 57 | } 58 | ] 59 | }, 60 | "version": 1 61 | } 62 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/WithdrawNFT.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WithdrawNFT.swift 3 | // ZKSyncExampleTests 4 | // 5 | // Created by Maxim Makhun on 9/3/21. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | @testable import ZKSync 10 | 11 | extension WithdrawNFT: Equatable { 12 | 13 | static var defaultTX: WithdrawNFT { 14 | let withdrawNFT = WithdrawNFT(accountId: 44, 15 | from: "0xede35562d3555e61120a151b3c8e8e91d83a378a", 16 | to: "0x19aa2ed8712072e918632259780e587698ef58df", 17 | token: 100000, 18 | feeToken: 0, 19 | fee: "1000000", 20 | nonce: 12, 21 | timeRange: .max) 22 | withdrawNFT.signature = Signature(pubKey: "40771354dc314593e071eaf4d0f42ccb1fad6c7006c57464feeb7ab5872b7490", 23 | // swiftlint:disable:next line_length 24 | signature: "1236180fe01b42c0c3c084d152b0582e714fa19da85900777e811f484a5b3ea434af320f66c7c657a33024d7be22cea44b7406d0af88c097a9d7d6b5d7154d02") 25 | return withdrawNFT 26 | } 27 | 28 | public static func == (lhs: WithdrawNFT, rhs: WithdrawNFT) -> Bool { 29 | return lhs.accountId == rhs.accountId && 30 | lhs.from == rhs.from && 31 | lhs.to == rhs.to && 32 | lhs.token == rhs.token && 33 | lhs.feeToken == rhs.feeToken && 34 | lhs.fee == rhs.fee && 35 | lhs.nonce == rhs.nonce && 36 | lhs.timeRange.validFrom == rhs.timeRange.validFrom && 37 | lhs.timeRange.validUntil == rhs.timeRange.validUntil && 38 | lhs.signature?.pubKey == rhs.signature?.pubKey && 39 | lhs.signature?.signature == rhs.signature?.signature 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/ChangePubKey+ChangePubKeyCREATE2.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChangePubKey.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Maxim Makhun on 9/3/21. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | @testable import ZKSync 10 | 11 | extension ChangePubKey where T == ChangePubKeyCREATE2 { 12 | 13 | static var defaultTX: ChangePubKey { 14 | let changePubKey = ChangePubKey(accountId: 55, 15 | account: "0x880296a3a63ef5a9a06d962cbd204b8b4a828203", 16 | newPkHash: "sync:18e8446d7748f2de52b28345bdbc76160e6b35eb", 17 | feeToken: 0, 18 | fee: "1000000000", 19 | nonce: 13, 20 | timeRange: TimeRange(validFrom: 0, validUntil: 4294967295)) 21 | changePubKey.signature = Signature(pubKey: "40771354dc314593e071eaf4d0f42ccb1fad6c7006c57464feeb7ab5872b7490", 22 | // swiftlint:disable:next line_length 23 | signature: "65b00a17484fd045907e4efc290c4231d19ef8402155156cf6fe85ecf6fa912e763d4210625c9ed79aa31d45f505bd2404ee40015c4e028a1bf03f81dda45b00") 24 | 25 | let creatorAddress = "0x" + [UInt8](repeating: 0, count: 40).toHexString() 26 | let salt = "0x" + [UInt8](repeating: 0, count: 64).toHexString() 27 | let codeHash = "0x" + [UInt8](repeating: 0, count: 64).toHexString() 28 | 29 | changePubKey.ethAuthData = ChangePubKeyCREATE2(creatorAddress: creatorAddress, 30 | saltArg: salt, 31 | codeHash: codeHash) 32 | 33 | return changePubKey 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Sources/ZKSync/Extensions/String+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // String+Extensions.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | extension String { 12 | 13 | func hasHexPrefix() -> Bool { 14 | return self.hasPrefix("0x") 15 | } 16 | 17 | func stripHexPrefix() -> String { 18 | if self.hasPrefix("0x") { 19 | let indexStart = self.index(self.startIndex, offsetBy: 2) 20 | return String(self[indexStart...]) 21 | } 22 | return self 23 | } 24 | 25 | func addHexPrefix() -> String { 26 | if !self.hasPrefix("0x") { 27 | return "0x" + self 28 | } 29 | return self 30 | } 31 | } 32 | 33 | extension String { 34 | 35 | func hasPubKeyHashPrefix() -> Bool { 36 | return self.hasPrefix("sync:") 37 | } 38 | 39 | func stripPubKeyHashPrefix() -> String { 40 | return self.deletingPrefix("sync:") 41 | } 42 | 43 | func addPubKeyHashPrefix() -> String { 44 | if !self.hasPrefix("sync:") { 45 | return "sync:" + self 46 | } 47 | return self 48 | } 49 | } 50 | 51 | extension String { 52 | 53 | func deletingPrefix(_ prefix: String) -> String { 54 | guard self.hasPrefix(prefix) else { return self } 55 | return String(self.dropFirst(prefix.count)) 56 | } 57 | } 58 | 59 | extension String { 60 | 61 | func attaching(fee: BigUInt, with token: TokenId) -> String { 62 | if fee > 0 { 63 | let separator = self.isEmpty ? "" : "\n" 64 | return self + separator + String(format: "Fee: %@ %@", 65 | Utils.format(token.intoDecimal(fee)), 66 | token.symbol) 67 | } else { 68 | return self 69 | } 70 | } 71 | 72 | func attaching(nonce: UInt32) -> String { 73 | return self + String(format: "\nNonce: %d", nonce) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Transactions/ForcedExit.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ForcedExit.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 12/01/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public class ForcedExit: ZkSyncTransaction { 12 | 13 | override public var type: String { "ForcedExit" } 14 | 15 | let initiatorAccountId: UInt32 16 | let target: String 17 | let token: UInt32 18 | let fee: String 19 | let nonce: UInt32 20 | let timeRange: TimeRange 21 | 22 | var signature: Signature? 23 | 24 | var feeInteger: BigUInt { BigUInt(fee)! } 25 | 26 | public init(initiatorAccountId: UInt32, 27 | target: String, 28 | token: UInt32, 29 | fee: String, 30 | nonce: UInt32, 31 | timeRange: TimeRange) { 32 | self.initiatorAccountId = initiatorAccountId 33 | self.target = target 34 | self.token = token 35 | self.fee = fee 36 | self.nonce = nonce 37 | self.timeRange = timeRange 38 | } 39 | 40 | enum CodingKeys: String, CodingKey { 41 | case initiatorAccountId 42 | case target 43 | case token 44 | case fee 45 | case nonce 46 | case type 47 | case signature 48 | case validFrom 49 | case validUntil 50 | } 51 | 52 | public override func encode(to encoder: Encoder) throws { 53 | var container = encoder.container(keyedBy: CodingKeys.self) 54 | try container.encode(initiatorAccountId, forKey: .initiatorAccountId) 55 | try container.encode(target, forKey: .target) 56 | try container.encode(token, forKey: .token) 57 | try container.encode(fee, forKey: .fee) 58 | try container.encode(nonce, forKey: .nonce) 59 | try container.encode(type, forKey: .type) 60 | try container.encode(signature, forKey: .signature) 61 | try container.encode(timeRange.validFrom, forKey: .validFrom) 62 | try container.encode(timeRange.validUntil, forKey: .validUntil) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/ViewControllers/MethodSelectionTableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MethodSelectionTableViewController.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 07/01/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ZKSync 11 | import PromiseKit 12 | import web3swift 13 | 14 | class MethodSelectionTableViewController: UITableViewController, WalletConsumer { 15 | 16 | var wallet: Wallet! 17 | 18 | @IBOutlet weak var addressLabel: UILabel! 19 | @IBOutlet weak var balanceLabel: UILabel! 20 | @IBOutlet weak var ethBalanceLabel: UILabel! 21 | 22 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 23 | if var destination = segue.destination as? WalletConsumer { 24 | destination.wallet = wallet 25 | } 26 | } 27 | 28 | override func viewDidLoad() { 29 | super.viewDidLoad() 30 | 31 | self.wallet.getAccountState { (result) in 32 | self.updateBalances(state: try? result.get()) 33 | } 34 | } 35 | 36 | private func weiToETH(string: String) -> String? { 37 | guard let value = Web3.Utils.parseToBigUInt(string, units: .wei) else { 38 | return nil 39 | } 40 | return Web3.Utils.formatToEthereumUnits(value) 41 | } 42 | 43 | private func updateBalances(state: AccountState?) { 44 | self.addressLabel.text = state?.address 45 | self.balanceLabel.text = weiToETH(string: state?.committed.balances["ETH"] ?? "0") 46 | let provider = try? self.wallet.createEthereumProvider(web3: Web3.InfuraRinkebyWeb3()) 47 | provider?.getBalance().done { (value) in 48 | self.ethBalanceLabel.text = Web3.Utils.formatToEthereumUnits(value) 49 | }.catch { (error) in 50 | self.present(UIAlertController.for(error: error), animated: true, completion: nil) 51 | } 52 | } 53 | 54 | @IBAction func copyAddress(_ sender: Any) { 55 | UIPasteboard.general.string = self.addressLabel.text 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/ZKSync/Extensions/BigInt+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BigInt+Extensions.swift 3 | // ZKSync 4 | // 5 | // Made with ❤️ by Matter Labs on 10/23/20 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | extension BigUInt { 12 | public init(from decoder: Decoder) throws { 13 | var container = try decoder.unkeyedContainer() 14 | 15 | let stringValue = try container.decode(String.self) 16 | 17 | self.init(stringValue.stripHexPrefix(), radix: 16)! 18 | } 19 | 20 | public func encode(to encoder: Encoder) throws { 21 | var container = encoder.unkeyedContainer() 22 | try container.encode(String(self, radix: 16).addHexPrefix()) 23 | } 24 | 25 | static var ten: BigUInt { 26 | return BigUInt(10) 27 | } 28 | 29 | static var two: BigUInt { 30 | return BigUInt(2) 31 | } 32 | 33 | static var one: BigUInt { 34 | return BigUInt(1) 35 | } 36 | 37 | static var zero: BigUInt { 38 | return BigUInt(0) 39 | } 40 | 41 | var isZero: Bool { 42 | return self == BigUInt.zero 43 | } 44 | } 45 | 46 | extension BigInt { 47 | 48 | public func serialize() -> Data { 49 | // This assumes Digit is binary. 50 | precondition(Word.bitWidth % 8 == 0) 51 | 52 | let byteCount = (self.bitWidth + 7) / 8 53 | 54 | guard byteCount > 0 else { return Data() } 55 | 56 | var data = Data(count: byteCount) 57 | data.withUnsafeMutableBytes { buffPtr in 58 | let pointer = buffPtr.bindMemory(to: UInt8.self) 59 | var index = byteCount - 1 60 | for var word in self.words { 61 | for _ in 0 ..< Word.bitWidth / 8 { 62 | pointer[index] = UInt8(word & 0xFF) 63 | word >>= 8 64 | if index == 0 { 65 | assert(word == 0) 66 | break 67 | } 68 | index -= 1 69 | } 70 | } 71 | } 72 | 73 | return data 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/DefaultProvider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultProvider.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 13/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | public class DefaultProvider: Provider { 11 | 12 | let transport: Transport 13 | 14 | internal var tokensCache: Tokens? 15 | 16 | public init(transport: Transport) { 17 | self.transport = transport 18 | } 19 | 20 | public convenience init(chainId: ChainId) { 21 | switch chainId { 22 | case .mainnet: 23 | let url = URL(string: "https://api.zksync.io/jsrpc")! 24 | self.init(transport: HTTPTransport(networkURL: url)) 25 | case .localhost: 26 | let url = URL(string: "http://127.0.0.1:3030")! 27 | self.init(transport: HTTPTransport(networkURL: url)) 28 | case .rinkeby: 29 | let url = URL(string: "https://rinkeby-api.zksync.io/jsrpc")! 30 | self.init(transport: HTTPTransport(networkURL: url)) 31 | case .ropsten: 32 | let url = URL(string: "https://ropsten-api.zksync.io/jsrpc")! 33 | self.init(transport: HTTPTransport(networkURL: url)) 34 | case .goerli: 35 | let url = URL(string: "https://goerli-api.zksync.io/jsrpc")! 36 | self.init(transport: HTTPTransport(networkURL: url)) 37 | case .sepolia: 38 | let url = URL(string: "https://sepolia-api.zksync.io/jsrpc")! 39 | self.init(transport: HTTPTransport(networkURL: url)) 40 | } 41 | } 42 | 43 | public static func betaProvider(chainId: ChainId) -> Provider { 44 | switch chainId { 45 | case .rinkeby: 46 | let url = URL(string: "https://rinkeby-beta-api.zksync.io/jsrpc")! 47 | return DefaultProvider(transport: HTTPTransport(networkURL: url)) 48 | case .ropsten: 49 | let url = URL(string: "https://ropsten-beta-api.zksync.io/jsrpc")! 50 | return DefaultProvider(transport: HTTPTransport(networkURL: url)) 51 | default: 52 | fatalError("Unsupported beta network for given chain id") 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Sources/ZKSync/Provider/TransactionFee/TransactionType+Encoding.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionType+Encoding.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 08/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | extension TransactionType { 11 | 12 | var feeIdentifier: String { 13 | switch self { 14 | case .withdraw, .forcedExit: 15 | return "Withdraw" 16 | case .transfer: 17 | return "Transfer" 18 | case .fastWithdraw: 19 | return "FastWithdraw" 20 | case .legacyChangePubKey, .legacyChangePubKeyOnchainAuth: 21 | return "ChangePubKey" 22 | case .changePubKeyOnchain: 23 | return "Onchain" 24 | case .changePubKeyECDSA: 25 | return "ECDSA" 26 | case .changePubKeyCREATE2: 27 | return "CREATE2" 28 | case .swap: 29 | return "Swap" 30 | case .mintNFT: 31 | return "MintNFT" 32 | case .withdrawNFT: 33 | return "WithdrawNFT" 34 | case .fastWithdrawNFT: 35 | return "FastWithdrawNFT" 36 | } 37 | } 38 | } 39 | 40 | extension TransactionType: Encodable { 41 | 42 | private struct ChangePubKeyIdentifier: Encodable { 43 | let changePubKey: [String: Bool] 44 | 45 | // swiftlint:disable:next nesting 46 | enum CodingKeys: String, CodingKey { 47 | case changePubKey = "ChangePubKey" 48 | } 49 | } 50 | 51 | public func encode(to encoder: Encoder) throws { 52 | var container = encoder.singleValueContainer() 53 | switch self { 54 | case .legacyChangePubKey, .legacyChangePubKeyOnchainAuth: 55 | let value = self == .legacyChangePubKeyOnchainAuth 56 | let identifier = ChangePubKeyIdentifier(changePubKey: ["onchainPubkeyAuth": value]) 57 | try container.encode(identifier) 58 | case .changePubKeyOnchain, .changePubKeyECDSA, .changePubKeyCREATE2: 59 | try container.encode(["ChangePubKey": feeIdentifier]) 60 | default: 61 | try container.encode(feeIdentifier) 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/ViewControllers/NetworkSelectionTableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NetworkSelectionTableViewController.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 06/01/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ZKSync 11 | 12 | class NetworkSelectionTableViewController: UITableViewController { 13 | 14 | var privateKey = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" 15 | 16 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 17 | 18 | var chainId: ChainId = .localhost 19 | switch segue.identifier { 20 | case "MainnetSegue": 21 | chainId = .mainnet 22 | case "RinkebySegue": 23 | chainId = .rinkeby 24 | case "RopsteinSegue": 25 | chainId = .ropsten 26 | default: 27 | break 28 | } 29 | if var destination = segue.destination as? WalletConsumer { 30 | destination.wallet = createWallet(chainId) 31 | } 32 | } 33 | 34 | private func createWallet(_ chainId: ChainId) -> Wallet { 35 | guard let ethSigner = try? DefaultEthSigner(privateKey: self.privateKey) else { 36 | fatalError() 37 | } 38 | 39 | var message = "Access zkSync account.\n\nOnly sign this message for a trusted client!" 40 | 41 | if chainId != .mainnet { 42 | message = "\(message)\nChain ID: \(chainId.id)." 43 | } 44 | 45 | guard let signature = try? ethSigner.sign(message: message.data(using: .utf8)!), 46 | let zkSigner = try? ZkSigner(signature: signature) else { 47 | fatalError() 48 | } 49 | 50 | let provider = DefaultProvider(chainId: chainId) 51 | 52 | guard let wallet = try? DefaultWallet(ethSigner: ethSigner, 53 | zkSigner: zkSigner, 54 | provider: provider) else { 55 | fatalError() 56 | } 57 | 58 | return wallet 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/ChangePubKey+ChangePubKeyOnchain.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChangePubKey.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Maxim Makhun on 9/3/21. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | @testable import ZKSync 10 | 11 | extension ChangePubKey: Equatable where T == ChangePubKeyOnchain { 12 | 13 | static var defaultTX: ChangePubKey { 14 | let changePubKey = ChangePubKey(accountId: 55, 15 | account: "0xede35562d3555e61120a151b3c8e8e91d83a378a", 16 | newPkHash: "sync:18e8446d7748f2de52b28345bdbc76160e6b35eb", 17 | feeToken: 0, 18 | fee: "1000000000", 19 | nonce: 13, 20 | timeRange: TimeRange(validFrom: 0, validUntil: 4294967295)) 21 | changePubKey.signature = Signature(pubKey: "40771354dc314593e071eaf4d0f42ccb1fad6c7006c57464feeb7ab5872b7490", 22 | // swiftlint:disable:next line_length 23 | signature: "85782959384c1728192b0fe9466a4273b6d0e78e913eea894b780e0236fc4c9d673d3833e895bce992fc113a4d16bba47ef73fed9c4fca2af09ed06cd6885802") 24 | changePubKey.ethAuthData = ChangePubKeyOnchain() 25 | 26 | return changePubKey 27 | } 28 | 29 | public static func == (lhs: ChangePubKey, rhs: ChangePubKey) -> Bool { 30 | return lhs.accountId == rhs.accountId && 31 | lhs.account == rhs.account && 32 | lhs.newPkHash == rhs.newPkHash && 33 | lhs.feeToken == rhs.feeToken && 34 | lhs.fee == rhs.fee && 35 | lhs.nonce == rhs.nonce && 36 | lhs.timeRange.validFrom == rhs.timeRange.validFrom && 37 | lhs.timeRange.validUntil == rhs.timeRange.validUntil && 38 | lhs.signature?.pubKey == rhs.signature?.pubKey && 39 | lhs.signature?.signature == rhs.signature?.signature 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Transactions/MintNFT.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MintNFT.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/05/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public class MintNFT: ZkSyncTransaction { 12 | 13 | override public var type: String { "MintNFT" } 14 | 15 | let creatorId: UInt32 16 | let creatorAddress: String 17 | let contentHash: String 18 | let recipient: String 19 | let fee: String 20 | let feeToken: UInt32 21 | let nonce: UInt32 22 | 23 | var signature: Signature? 24 | 25 | var feeInteger: BigUInt { BigUInt(fee)! } 26 | 27 | public init(creatorId: UInt32, 28 | creatorAddress: String, 29 | contentHash: String, 30 | recipient: String, 31 | fee: String, 32 | feeToken: UInt32, 33 | nonce: UInt32, 34 | signature: Signature? = nil) { 35 | self.creatorId = creatorId 36 | self.creatorAddress = creatorAddress 37 | self.contentHash = contentHash 38 | self.recipient = recipient 39 | self.fee = fee 40 | self.feeToken = feeToken 41 | self.nonce = nonce 42 | self.signature = signature 43 | } 44 | 45 | enum CodingKeys: String, CodingKey { 46 | case creatorId 47 | case creatorAddress 48 | case contentHash 49 | case recipient 50 | case fee 51 | case feeToken 52 | case nonce 53 | case signature 54 | case type 55 | } 56 | 57 | public override func encode(to encoder: Encoder) throws { 58 | var container = encoder.container(keyedBy: CodingKeys.self) 59 | try container.encode(creatorId, forKey: .creatorId) 60 | try container.encode(creatorAddress, forKey: .creatorAddress) 61 | try container.encode(contentHash, forKey: .contentHash) 62 | try container.encode(recipient, forKey: .recipient) 63 | try container.encode(fee, forKey: .fee) 64 | try container.encode(feeToken, forKey: .feeToken) 65 | try container.encode(nonce, forKey: .nonce) 66 | try container.encode(signature, forKey: .signature) 67 | try container.encode(type, forKey: .type) 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "pins" : [ 3 | { 4 | "identity" : "alamofire", 5 | "kind" : "remoteSourceControl", 6 | "location" : "https://github.com/Alamofire/Alamofire.git", 7 | "state" : { 8 | "revision" : "d120af1e8638c7da36c8481fd61a66c0c08dc4fc", 9 | "version" : "5.4.4" 10 | } 11 | }, 12 | { 13 | "identity" : "bigint", 14 | "kind" : "remoteSourceControl", 15 | "location" : "https://github.com/attaswift/BigInt.git", 16 | "state" : { 17 | "revision" : "0ed110f7555c34ff468e72e1686e59721f2b0da6", 18 | "version" : "5.3.0" 19 | } 20 | }, 21 | { 22 | "identity" : "cryptoswift", 23 | "kind" : "remoteSourceControl", 24 | "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", 25 | "state" : { 26 | "revision" : "039f56c5d7960f277087a0be51f5eb04ed0ec073", 27 | "version" : "1.5.1" 28 | } 29 | }, 30 | { 31 | "identity" : "promisekit", 32 | "kind" : "remoteSourceControl", 33 | "location" : "https://github.com/mxcl/PromiseKit.git", 34 | "state" : { 35 | "revision" : "7b07b214dacecb22ca4b680531c7e981d52483f9", 36 | "version" : "6.16.3" 37 | } 38 | }, 39 | { 40 | "identity" : "starscream", 41 | "kind" : "remoteSourceControl", 42 | "location" : "https://github.com/daltoniam/Starscream.git", 43 | "state" : { 44 | "revision" : "df8d82047f6654d8e4b655d1b1525c64e1059d21", 45 | "version" : "4.0.4" 46 | } 47 | }, 48 | { 49 | "identity" : "web3swift", 50 | "kind" : "remoteSourceControl", 51 | "location" : "https://github.com/skywinder/web3swift.git", 52 | "state" : { 53 | "revision" : "e269630c161df72b18ab10511382feb91d65d965", 54 | "version" : "2.6.5" 55 | } 56 | }, 57 | { 58 | "identity" : "zksync-swift", 59 | "kind" : "remoteSourceControl", 60 | "location" : "https://github.com/zksync-sdk/zksync-swift.git", 61 | "state" : { 62 | "branch" : "master", 63 | "revision" : "778b14d0c5656aa11b1901c8b5f270568758b0bc" 64 | } 65 | } 66 | ], 67 | "version" : 2 68 | } 69 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Transactions/Swap.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Swap.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 21/05/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public class Swap: ZkSyncTransaction { 12 | 13 | override public var type: String { "Swap" } 14 | 15 | let submitterId: UInt32 16 | let submitterAddress: String 17 | let nonce: UInt32 18 | var orders: (Order, Order) 19 | let amounts: (BigUInt, BigUInt) 20 | let fee: String 21 | let feeToken: UInt32 22 | 23 | var signature: Signature? 24 | var feeInteger: BigUInt { BigUInt(fee)! } 25 | 26 | internal init(submitterId: UInt32, 27 | submitterAddress: String, 28 | nonce: UInt32, 29 | orders: (Order, Order), 30 | amounts: (BigUInt, BigUInt), 31 | fee: String, 32 | feeToken: UInt32, 33 | signature: Signature? = nil) { 34 | self.submitterId = submitterId 35 | self.submitterAddress = submitterAddress 36 | self.nonce = nonce 37 | self.orders = orders 38 | self.amounts = amounts 39 | self.fee = fee 40 | self.feeToken = feeToken 41 | self.signature = signature 42 | } 43 | 44 | enum CodingKeys: String, CodingKey { 45 | case submitterId 46 | case submitterAddress 47 | case nonce 48 | case orders 49 | case amounts 50 | case fee 51 | case feeToken 52 | case signature 53 | case type 54 | } 55 | 56 | public override func encode(to encoder: Encoder) throws { 57 | var container = encoder.container(keyedBy: CodingKeys.self) 58 | try container.encode(submitterId, forKey: .submitterId) 59 | try container.encode(submitterAddress, forKey: .submitterAddress) 60 | try container.encode([orders.0, orders.1], forKey: .orders) 61 | try container.encode([amounts.0, amounts.1], forKey: .amounts) 62 | try container.encode(signature, forKey: .signature) 63 | try container.encode(fee, forKey: .fee) 64 | try container.encode(feeToken, forKey: .feeToken) 65 | try container.encode(nonce, forKey: .nonce) 66 | try container.encode(type, forKey: .type) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/ViewControllers/WithdrawViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WithdrawViewController.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 03/02/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ZKSync 11 | import web3swift 12 | import PromiseKit 13 | 14 | class WithdrawViewController: UIViewController, WalletConsumer { 15 | 16 | var wallet: Wallet! 17 | 18 | @IBOutlet weak var amountTextField: UITextField! 19 | 20 | @IBAction func withdraw(_ sender: Any) { 21 | amountTextField.resignFirstResponder() 22 | 23 | guard let amountText = amountTextField.text, 24 | let amount = Web3.Utils.parseToBigUInt(amountText, units: .eth), 25 | amount > 0 else { 26 | self.showAmountError() 27 | return 28 | } 29 | 30 | firstly { 31 | self.wallet.getAccountStatePromise() 32 | }.then { state in 33 | self.wallet.provider.transactionFeePromise( 34 | for: .withdraw, 35 | address: state.address, 36 | tokenIdentifier: Token.ETH.address).map { ($0, state) } 37 | }.then { (feeDetails, state) -> Promise in 38 | let fee = TransactionFee(feeToken: Token.ETH.address, 39 | fee: feeDetails.totalFeeInteger) 40 | return self.wallet.withdrawPromise(ethAddress: state.address, 41 | amount: amount, 42 | fee: fee, 43 | nonce: state.committed.nonce, 44 | fastProcessing: false, 45 | timeRange: TimeRange(validFrom: 0, validUntil: 4294967295)) 46 | }.done { (_) in 47 | self.present(UIAlertController.for(message: "Successfully withdrawn"), animated: true, completion: nil) 48 | }.catch { (error) in 49 | self.present(UIAlertController.for(error: error), animated: true, completion: nil) 50 | } 51 | } 52 | 53 | func showAmountError() { 54 | self.present(UIAlertController.forIncorrectAmount(), animated: true, completion: nil) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Transactions/Withdraw.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Withdraw.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 12/01/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public class Withdraw: ZkSyncTransaction { 12 | 13 | override public var type: String { "Withdraw" } 14 | 15 | let accountId: UInt32 16 | let from: String 17 | let to: String 18 | let token: UInt32 19 | let amount: BigUInt 20 | let fee: String 21 | let nonce: UInt32 22 | let timeRange: TimeRange 23 | 24 | var signature: Signature? 25 | 26 | var feeInteger: BigUInt { BigUInt(fee)! } 27 | 28 | public init(accountId: UInt32, 29 | from: String, 30 | to: String, 31 | token: UInt32, 32 | amount: BigUInt, 33 | fee: String, 34 | nonce: UInt32, 35 | timeRange: TimeRange) { 36 | self.accountId = accountId 37 | self.from = from 38 | self.to = to 39 | self.token = token 40 | self.amount = amount 41 | self.fee = fee 42 | self.nonce = nonce 43 | self.timeRange = timeRange 44 | } 45 | 46 | enum CodingKeys: String, CodingKey { 47 | case accountId 48 | case from 49 | case to 50 | case token 51 | case amount 52 | case fee 53 | case nonce 54 | case type 55 | case signature 56 | case validFrom 57 | case validUntil 58 | } 59 | 60 | public override func encode(to encoder: Encoder) throws { 61 | var container = encoder.container(keyedBy: CodingKeys.self) 62 | try container.encode(accountId, forKey: .accountId) 63 | try container.encode(from, forKey: .from) 64 | try container.encode(to, forKey: .to) 65 | try container.encode(token, forKey: .token) 66 | try container.encode(fee, forKey: .fee) 67 | try container.encode(nonce, forKey: .nonce) 68 | try container.encode(type, forKey: .type) 69 | try container.encode(signature, forKey: .signature) 70 | try container.encode(amount.description, forKey: .amount) 71 | try container.encode(timeRange.validFrom, forKey: .validFrom) 72 | try container.encode(timeRange.validUntil, forKey: .validUntil) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Transactions/WithdrawNFT.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WithdrawNFT.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/05/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public class WithdrawNFT: ZkSyncTransaction { 12 | 13 | override public var type: String { "WithdrawNFT" } 14 | 15 | let accountId: UInt32 16 | let from: String 17 | let to: String 18 | let token: UInt32 19 | let feeToken: UInt32 20 | let fee: String 21 | let nonce: UInt32 22 | let timeRange: TimeRange 23 | 24 | var signature: Signature? 25 | 26 | var feeInteger: BigUInt { BigUInt(fee)! } 27 | 28 | public init(accountId: UInt32, 29 | from: String, 30 | to: String, 31 | token: UInt32, 32 | feeToken: UInt32, 33 | fee: String, 34 | nonce: UInt32, 35 | timeRange: TimeRange) { 36 | self.accountId = accountId 37 | self.from = from 38 | self.to = to 39 | self.token = token 40 | self.feeToken = feeToken 41 | self.fee = fee 42 | self.nonce = nonce 43 | self.timeRange = timeRange 44 | } 45 | 46 | enum CodingKeys: String, CodingKey { 47 | case accountId 48 | case from 49 | case to 50 | case token 51 | case feeToken 52 | case fee 53 | case nonce 54 | case type 55 | case signature 56 | case validFrom 57 | case validUntil 58 | } 59 | 60 | public override func encode(to encoder: Encoder) throws { 61 | var container = encoder.container(keyedBy: CodingKeys.self) 62 | try container.encode(accountId, forKey: .accountId) 63 | try container.encode(from, forKey: .from) 64 | try container.encode(to, forKey: .to) 65 | try container.encode(token, forKey: .token) 66 | try container.encode(fee, forKey: .fee) 67 | try container.encode(nonce, forKey: .nonce) 68 | try container.encode(type, forKey: .type) 69 | try container.encode(signature, forKey: .signature) 70 | try container.encode(feeToken, forKey: .feeToken) 71 | try container.encode(timeRange.validFrom, forKey: .validFrom) 72 | try container.encode(timeRange.validUntil, forKey: .validUntil) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UIApplicationSupportsIndirectInputEvents 43 | 44 | UILaunchStoryboardName 45 | LaunchScreen 46 | UIMainStoryboardFile 47 | Main 48 | UIRequiredDeviceCapabilities 49 | 50 | armv7 51 | 52 | UISupportedInterfaceOrientations 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationLandscapeLeft 56 | UIInterfaceOrientationLandscapeRight 57 | 58 | UISupportedInterfaceOrientations~ipad 59 | 60 | UIInterfaceOrientationPortrait 61 | UIInterfaceOrientationPortraitUpsideDown 62 | UIInterfaceOrientationLandscapeLeft 63 | UIInterfaceOrientationLandscapeRight 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Swap/Order.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Order.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 21/05/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public struct Order: Encodable { 12 | 13 | let accountId: UInt32 14 | let recepientAddress: String 15 | let nonce: UInt32 16 | let tokenBuy: UInt32 17 | let tokenSell: UInt32 18 | 19 | let ratio: (BigUInt, BigUInt) 20 | 21 | let amount: BigUInt 22 | var signature: Signature? 23 | 24 | let timeRange: TimeRange 25 | 26 | var ethereumSignature: EthSignature? 27 | 28 | public init(accountId: UInt32, 29 | recepientAddress: String, 30 | nonce: UInt32, 31 | tokenBuy: UInt32, 32 | tokenSell: UInt32, 33 | ratio: (BigUInt, BigUInt), 34 | amount: BigUInt, 35 | timeRange: TimeRange) { 36 | self.accountId = accountId 37 | self.recepientAddress = recepientAddress 38 | self.nonce = nonce 39 | self.tokenBuy = tokenBuy 40 | self.tokenSell = tokenSell 41 | self.ratio = ratio 42 | self.amount = amount 43 | self.timeRange = timeRange 44 | } 45 | 46 | enum CodingKeys: String, CodingKey { 47 | case accountId 48 | case recepientAddress = "recepient" 49 | case nonce 50 | case tokenBuy 51 | case tokenSell 52 | case ratio 53 | case amount 54 | case signature 55 | case validFrom 56 | case validUntil 57 | } 58 | 59 | public func encode(to encoder: Encoder) throws { 60 | var container = encoder.container(keyedBy: CodingKeys.self) 61 | 62 | try container.encode(accountId, forKey: .accountId) 63 | try container.encode(recepientAddress, forKey: .recepientAddress) 64 | try container.encode(nonce, forKey: .nonce) 65 | try container.encode(tokenBuy, forKey: .tokenBuy) 66 | try container.encode(tokenSell, forKey: .tokenSell) 67 | try container.encode([ratio.0, ratio.1], forKey: .ratio) 68 | try container.encode(amount, forKey: .amount) 69 | try container.encode(signature, forKey: .signature) 70 | try container.encode(timeRange.validFrom, forKey: .validFrom) 71 | try container.encode(timeRange.validUntil, forKey: .validUntil) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/ViewControllers/TransferViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransferViewController.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 03/02/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ZKSync 11 | import web3swift 12 | import PromiseKit 13 | 14 | class TransferViewController: UIViewController, WalletConsumer { 15 | 16 | var wallet: Wallet! 17 | 18 | @IBOutlet weak var addressTextField: UITextField! 19 | 20 | @IBOutlet weak var amountTextField: UITextField! 21 | 22 | @IBAction func transfer(_ sender: Any) { 23 | amountTextField.resignFirstResponder() 24 | 25 | guard let amountText = amountTextField.text, 26 | let amount = Web3.Utils.parseToBigUInt(amountText, units: .eth), 27 | amount > 0 else { 28 | self.showAmountError() 29 | return 30 | } 31 | 32 | guard let address = addressTextField.text, !address.isEmpty else { 33 | self.showAddressError() 34 | return 35 | } 36 | 37 | firstly { 38 | self.wallet.getAccountStatePromise() 39 | }.then { state in 40 | self.wallet.provider.transactionFeePromise(for: .transfer, 41 | address: address, 42 | tokenIdentifier: Token.ETH.address).map { ($0, state) } 43 | }.then { (feeDetails, _) -> Promise in 44 | let fee = TransactionFee(feeToken: Token.ETH.address, 45 | fee: feeDetails.totalFeeInteger) 46 | return self.wallet.transferPromise(to: address, 47 | amount: amount, 48 | fee: fee, 49 | nonce: nil, 50 | timeRange: TimeRange(validFrom: 0, validUntil: 4294967295)) 51 | }.done { (_) in 52 | self.present(UIAlertController.for(message: "Successfully transferred"), animated: true, completion: nil) 53 | }.catch { (error) in 54 | self.present(UIAlertController.for(error: error), animated: true, completion: nil) 55 | } 56 | } 57 | 58 | func showAmountError() { 59 | self.present(UIAlertController.forIncorrectAmount(), animated: true, completion: nil) 60 | } 61 | 62 | func showAddressError() { 63 | self.present(UIAlertController.forIncorrectAddress(), animated: true, completion: nil) 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Transactions/ChangePubKey.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChangePubKey.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 11/01/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public class ChangePubKey: ZkSyncTransaction { 12 | 13 | override public var type: String { "ChangePubKey" } 14 | 15 | let accountId: UInt32 16 | let account: String 17 | let newPkHash: String 18 | let feeToken: UInt32 19 | let fee: String 20 | let nonce: UInt32 21 | let timeRange: TimeRange 22 | 23 | var signature: Signature? 24 | var ethAuthData: T? 25 | 26 | var feeInteger: BigUInt { BigUInt(fee)! } 27 | 28 | public init(accountId: UInt32, 29 | account: String, 30 | newPkHash: String, 31 | feeToken: UInt32, 32 | fee: String, 33 | nonce: UInt32, 34 | timeRange: TimeRange) { 35 | self.accountId = accountId 36 | self.account = account 37 | self.newPkHash = newPkHash 38 | self.feeToken = feeToken 39 | self.fee = fee 40 | self.nonce = nonce 41 | self.timeRange = timeRange 42 | } 43 | 44 | enum CodingKeys: String, CodingKey { 45 | case accountId 46 | case account 47 | case newPkHash 48 | case feeToken 49 | case fee 50 | case nonce 51 | case type 52 | case signature 53 | case ethAuthData 54 | case validFrom 55 | case validUntil 56 | } 57 | 58 | public override func encode(to encoder: Encoder) throws { 59 | var container = encoder.container(keyedBy: CodingKeys.self) 60 | try container.encode(accountId, forKey: .accountId) 61 | try container.encode(account, forKey: .account) 62 | try container.encode(newPkHash, forKey: .newPkHash) 63 | try container.encode(feeToken, forKey: .feeToken) 64 | try container.encode(fee, forKey: .fee) 65 | try container.encode(nonce, forKey: .nonce) 66 | try container.encode(type, forKey: .type) 67 | try container.encode(signature, forKey: .signature) 68 | try container.encode(ethAuthData, forKey: .ethAuthData) 69 | try container.encode(timeRange.validFrom, forKey: .validFrom) 70 | try container.encode(timeRange.validUntil, forKey: .validUntil) 71 | } 72 | 73 | var description: String { 74 | let mirror = Mirror(reflecting: self) 75 | var objectDescription: String = "" 76 | for attribute in mirror.children { 77 | if let property = attribute.label as String? { 78 | objectDescription += "\(property): \(attribute.value) " 79 | } 80 | } 81 | 82 | return objectDescription 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/ZkSignerTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ZkSignerTests.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 20/01/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import ZKSync 11 | 12 | class ZkSignerTests: XCTestCase { 13 | 14 | static let PrivateKey = "0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" 15 | static let Seed = Data(hex: PrivateKey) 16 | // swiftlint:disable:next line_length 17 | static let Message = Data(hex: "0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f") 18 | static let PubKey = "0x17f3708f5e2b2c39c640def0cf0010fd9dd9219650e389114ea9da47f5874184" 19 | static let PubKeyHash = "sync:4f3015a1d2b93239f9510d8bc2cf49376a78a08e" 20 | static let PubKeyHashEth = "sync:18e8446d7748f2de52b28345bdbc76160e6b35eb" 21 | // swiftlint:disable:next line_length 22 | static let Signature = "5462c3083d92b832d540c9068eed0a0450520f6dd2e4ab169de1a46585b394a4292896a2ebca3c0378378963a6bc1710b64c573598e73de3a33d6cec2f5d7403" 23 | 24 | func testCreationFromSeed() throws { 25 | let signer = try ZkSigner(seed: ZkSignerTests.Seed) 26 | 27 | XCTAssertEqual(signer.publicKey.hexEncodedString().addHexPrefix().lowercased(), 28 | ZkSignerTests.PubKey) 29 | } 30 | 31 | func testCreationFromEthSigner() throws { 32 | var message = "Access zkSync account.\n\nOnly sign this message for a trusted client!" 33 | let chainId: ChainId = .mainnet 34 | 35 | if chainId != .mainnet { 36 | message = "\(message)\nChain ID: \(chainId.id)." 37 | } 38 | 39 | let ethSigner = try DefaultEthSigner(privateKey: ZkSignerTests.PrivateKey) 40 | let signature = try ethSigner.sign(message: message.data(using: .utf8)!) 41 | 42 | let signer = try ZkSigner(signature: signature) 43 | 44 | XCTAssertEqual(signer.publicKeyHash, ZkSignerTests.PubKeyHashEth) 45 | } 46 | 47 | func testSigningMessage() throws { 48 | let signer = try ZkSigner(seed: ZkSignerTests.Seed) 49 | let signature = try signer.sign(message: ZkSignerTests.Message) 50 | 51 | XCTAssertEqual(signature.signature.lowercased(), ZkSignerTests.Signature) 52 | } 53 | 54 | func testPublicKeyGeneration() throws { 55 | let signer = try ZkSigner(seed: ZkSignerTests.Seed) 56 | 57 | XCTAssertEqual(signer.publicKey.hexEncodedString().lowercased(), 58 | ZkSignerTests.PubKey.stripHexPrefix()) 59 | } 60 | 61 | func testPublicKeyHashGeneration() throws { 62 | let signer = try ZkSigner(seed: ZkSignerTests.Seed) 63 | 64 | XCTAssertEqual(signer.publicKeyHash, 65 | ZkSignerTests.PubKeyHash) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Sources/ZKSync/Model/Transactions/Transfer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Transfer.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 12/01/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public class Transfer: ZkSyncTransaction { 12 | 13 | override public var type: String { "Transfer" } 14 | 15 | let accountId: UInt32 16 | let from: String 17 | let to: String 18 | let token: UInt32 19 | let amount: BigUInt 20 | let fee: String 21 | let nonce: UInt32 22 | let timeRange: TimeRange 23 | 24 | var signature: Signature? 25 | 26 | // Ignored when generating JSON 27 | let tokenId: TokenId? 28 | 29 | var feeInteger: BigUInt { BigUInt(fee)! } 30 | 31 | public init(accountId: UInt32, 32 | from: String, 33 | to: String, 34 | token: UInt32, 35 | amount: BigUInt, 36 | fee: String, 37 | nonce: UInt32, 38 | tokenId: TokenId? = nil, 39 | timeRange: TimeRange) { 40 | self.accountId = accountId 41 | self.from = from 42 | self.to = to 43 | self.token = token 44 | self.amount = amount 45 | self.fee = fee 46 | self.nonce = nonce 47 | self.timeRange = timeRange 48 | self.tokenId = tokenId 49 | } 50 | 51 | enum CodingKeys: String, CodingKey { 52 | case accountId 53 | case from 54 | case to 55 | case token 56 | case amount 57 | case fee 58 | case nonce 59 | case type 60 | case signature 61 | case validFrom 62 | case validUntil 63 | } 64 | 65 | public override func encode(to encoder: Encoder) throws { 66 | var container = encoder.container(keyedBy: CodingKeys.self) 67 | try container.encode(accountId, forKey: .accountId) 68 | try container.encode(from, forKey: .from) 69 | try container.encode(to, forKey: .to) 70 | try container.encode(token, forKey: .token) 71 | try container.encode(fee, forKey: .fee) 72 | try container.encode(nonce, forKey: .nonce) 73 | try container.encode(type, forKey: .type) 74 | try container.encode(signature, forKey: .signature) 75 | try container.encode(amount.description, forKey: .amount) 76 | try container.encode(timeRange.validFrom, forKey: .validFrom) 77 | try container.encode(timeRange.validUntil, forKey: .validUntil) 78 | } 79 | 80 | var description: String { 81 | let mirror = Mirror(reflecting: self) 82 | var objectDescription: String = "" 83 | for attribute in mirror.children { 84 | if let property = attribute.label as String? { 85 | objectDescription += "\(property): \(attribute.value) " 86 | } 87 | } 88 | 89 | return objectDescription 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Sources/ZKSync/Wallet/DefaultWallet+MintNFT.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultWallet+MintNFT.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/05/2021. 6 | // 7 | 8 | import Foundation 9 | import PromiseKit 10 | 11 | extension DefaultWallet { 12 | 13 | public func mintNFT(recepient: String, 14 | contentHash: String, 15 | fee: TransactionFee, 16 | nonce: UInt32?, 17 | completion: @escaping (Swift.Result) -> Void) { 18 | firstly { 19 | getNonceAccountIdPair(for: nonce) 20 | }.then { (nonce, accountId) in 21 | self.buildSignedMintNFTTx(recepient: recepient, 22 | contentHash: contentHash, 23 | fee: fee, 24 | accountId: accountId, 25 | nonce: nonce) 26 | }.then { signedTransaction in 27 | self.submitSignedTransaction(signedTransaction.transaction, 28 | ethereumSignature: signedTransaction.ethereumSignature, 29 | fastProcessing: false) 30 | }.pipe { result in 31 | completion(result.result) 32 | } 33 | } 34 | 35 | func buildSignedMintNFTTx(recepient: String, 36 | contentHash: String, 37 | fee: TransactionFee, 38 | accountId: UInt32, 39 | nonce: UInt32) -> Promise> { 40 | return firstly { 41 | self.getTokens() 42 | }.map { tokens in 43 | let token = try tokens.tokenByTokenIdentifier(fee.feeToken) 44 | let mintNFT = MintNFT(creatorId: accountId, 45 | creatorAddress: self.ethSigner.address, 46 | contentHash: contentHash, 47 | recipient: recepient, 48 | fee: fee.fee.description, 49 | feeToken: token.id, 50 | nonce: nonce) 51 | 52 | let ethSignature = try self.ethSigner.signTransaction(transaction: mintNFT, 53 | nonce: nonce, 54 | token: token, 55 | fee: fee.fee) 56 | 57 | let transaction = try self.zkSigner.sign(mintNFT: mintNFT) 58 | let signedTransaction = SignedTransaction(transaction: transaction, 59 | ethereumSignature: ethSignature) 60 | return signedTransaction 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Sources/ZKSync/Wallet/DefaultWallet+Promises.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultWallet+Promises.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | import PromiseKit 10 | 11 | extension DefaultWallet { 12 | 13 | func getNonce() -> Promise { 14 | return Promise { 15 | getNonce(completion: $0.resolve) 16 | } 17 | } 18 | 19 | func getTokens() -> Promise { 20 | return Promise { 21 | provider.tokens(completion: $0.resolve) 22 | } 23 | } 24 | 25 | func submitSignedTransaction(_ transaction: TX, 26 | ethereumSignature: EthSignature?, 27 | fastProcessing: Bool) -> Promise { 28 | return Promise { 29 | provider.submitTx(transaction, 30 | ethereumSignature: ethereumSignature, 31 | fastProcessing: fastProcessing, 32 | completion: $0.resolve) 33 | } 34 | } 35 | 36 | func submitSignedBatch(transactions: [ZkSyncTransaction], 37 | ethereumSignature: EthSignature) -> Promise<[String]> { 38 | return Promise { 39 | self.submitSignedBatch(transactions: transactions, 40 | ethereumSignature: ethereumSignature, 41 | completion: $0.resolve) 42 | } 43 | } 44 | 45 | func getNonceAccountIdPair(for nonce: UInt32?) -> Promise<(UInt32, UInt32)> { 46 | if let nonce = nonce, let accountId = self.accountId { 47 | return Promise.value((nonce, accountId)) 48 | } else { 49 | return getAccountStatePromise().map { state in 50 | guard let id = state.id else { 51 | throw WalletError.accountIdIsNull 52 | } 53 | self.accountId = id 54 | return (nonce ?? state.committed.nonce, id) 55 | } 56 | } 57 | } 58 | } 59 | 60 | extension Swift.Result { 61 | var promiseResult: PromiseKit.Result { 62 | switch self { 63 | case .success(let success): 64 | return .fulfilled(success) 65 | case .failure(let error): 66 | return .rejected(error) 67 | } 68 | } 69 | } 70 | 71 | public extension PromiseKit.Resolver { 72 | func resolve(_ result: Swift.Result) { 73 | self.resolve(result.promiseResult) 74 | } 75 | } 76 | 77 | public extension PromiseKit.Result { 78 | var result: Swift.Result { 79 | switch self { 80 | case .fulfilled(let value): 81 | return .success(value) 82 | case .rejected(let error): 83 | return .failure(error) 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Sources/ZKSync/Wallet/DefaultWallet+TransferNFT.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultWallet+TransferNFT.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/05/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | import PromiseKit 11 | 12 | extension DefaultWallet { 13 | 14 | // swiftlint:disable:next function_parameter_count 15 | public func transferNFT(to: String, 16 | token: NFT, 17 | fee: TransactionFee, 18 | nonce: UInt32?, 19 | timeRange: TimeRange, 20 | completion: @escaping (Swift.Result<[String], Error>) -> Void) { 21 | 22 | firstly { 23 | return self.getNonceAccountIdPair(for: nonce) 24 | }.then { (nonce, accountId) in 25 | return self.getTokens().map { return ($0, nonce, accountId) } 26 | }.then { (tokens, nonce, accountId) -> Promise<[String]> in 27 | 28 | let feeToken = try tokens.tokenByTokenIdentifier(fee.feeToken) 29 | 30 | let transferNFT = Transfer(accountId: accountId, 31 | from: self.ethSigner.address, 32 | to: to, 33 | token: token.id, 34 | amount: .one, 35 | fee: BigUInt.zero.description, 36 | nonce: nonce, 37 | tokenId: token, 38 | timeRange: timeRange) 39 | 40 | let transferFee = Transfer(accountId: accountId, 41 | from: self.ethSigner.address, 42 | to: self.ethSigner.address, 43 | token: feeToken.id, 44 | amount: BigUInt.zero, 45 | fee: fee.fee.description, 46 | nonce: nonce + 1, 47 | tokenId: feeToken, 48 | timeRange: timeRange) 49 | 50 | let ethSignature = try self.ethSigner.signBatch(transactions: [transferNFT, transferFee], 51 | nonce: nonce, 52 | token: feeToken, 53 | fee: fee.fee) 54 | let signedTransactions = [try self.zkSigner.sign(transfer: transferNFT), 55 | try self.zkSigner.sign(transfer: transferFee)] 56 | return self.submitSignedBatch(transactions: signedTransactions, 57 | ethereumSignature: ethSignature) 58 | }.pipe { (result) in 59 | completion(result.result) 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Examples/CocoaPods/Tests/Order.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Order.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Maxim Makhun on 9/3/21. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | @testable import ZKSync 10 | 11 | extension Order: Equatable { 12 | 13 | static var defaultOrder: Order { 14 | var order = Order(accountId: 6, 15 | recepientAddress: "0x823b6a996cea19e0c41e250b20e2e804ea72ccdf", 16 | nonce: 18, 17 | tokenBuy: 2, 18 | tokenSell: 0, 19 | ratio: (1, 2), 20 | amount: 1000000, 21 | timeRange: .max) 22 | // swiftlint:disable:next line_length 23 | order.ethereumSignature = EthSignature(signature: "0x841a4ed62572883b2272a56164eb33f7b0649029ba588a7230928cff698b49383045b47d35dcdee1beb33dd4ca6b944b945314a206f3f2838ddbe389a34fc8cb1c", 24 | type: .ethereumSignature) 25 | 26 | order.signature = Signature(pubKey: "40771354dc314593e071eaf4d0f42ccb1fad6c7006c57464feeb7ab5872b7490", 27 | // swiftlint:disable:next line_length 28 | signature: "b76c83011ea9e14cf679d35b9a7084832a78bf3f975c5b5c3315f80993c227afb7a1cd7e7b8fc225a48d8c9be78335736115890df5bbacfc52ecf47b4e089500") 29 | 30 | return order 31 | } 32 | 33 | static var defaultOrderA: Order { 34 | return Order(accountId: 6, 35 | recepientAddress: "0x823b6a996cea19e0c41e250b20e2e804ea72ccdf", 36 | nonce: 18, 37 | tokenBuy: 2, 38 | tokenSell: 1, 39 | ratio: (1, 2), 40 | amount: 1000000, 41 | timeRange: .max) 42 | } 43 | 44 | static var defaultOrderB: Order { 45 | return Order(accountId: 44, 46 | recepientAddress: "0x63adbb48d1bc2cf54562910ce54b7ca06b87f319", 47 | nonce: 101, 48 | tokenBuy: 1, 49 | tokenSell: 2, 50 | ratio: (3, 1), 51 | amount: 2500000, 52 | timeRange: .max) 53 | } 54 | 55 | public static func == (lhs: Order, rhs: Order) -> Bool { 56 | return lhs.accountId == rhs.accountId && 57 | lhs.recepientAddress == rhs.recepientAddress && 58 | lhs.nonce == rhs.nonce && 59 | lhs.tokenBuy == rhs.tokenBuy && 60 | lhs.tokenSell == rhs.tokenSell && 61 | lhs.ratio == rhs.ratio && 62 | lhs.amount == rhs.amount && 63 | lhs.signature?.pubKey == rhs.signature?.pubKey && 64 | lhs.signature?.signature == rhs.signature?.signature && 65 | lhs.timeRange.validFrom == rhs.timeRange.validFrom && 66 | lhs.timeRange.validUntil == rhs.timeRange.validUntil && 67 | lhs.ethereumSignature == rhs.ethereumSignature 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Sources/ZKSync/Wallet/DefaultWallet+ForcedExit.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultWallet+ForcedExit.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | import PromiseKit 10 | import BigInt 11 | 12 | extension DefaultWallet { 13 | 14 | public func forcedExit(target: String, 15 | fee: TransactionFee, 16 | nonce: UInt32?, 17 | timeRange: TimeRange, 18 | completion: @escaping (Swift.Result) -> Void) { 19 | firstly { 20 | getNonceAccountIdPair(for: nonce) 21 | }.then { (nonce, accountId: UInt32) in 22 | self.buildSignedForcedExitTx(target: target, 23 | tokenIdentifier: fee.feeToken, 24 | fee: fee.fee, 25 | accountId: accountId, 26 | nonce: nonce, 27 | timeRange: timeRange) 28 | }.then { signedTransaction in 29 | self.submitSignedTransaction(signedTransaction.transaction, 30 | ethereumSignature: signedTransaction.ethereumSignature, 31 | fastProcessing: false) 32 | }.pipe { result in 33 | completion(result.result) 34 | } 35 | } 36 | 37 | // swiftlint:disable:next function_parameter_count 38 | public func buildSignedForcedExitTx(target: String, 39 | tokenIdentifier: String, 40 | fee: BigUInt, 41 | accountId: UInt32, 42 | nonce: UInt32, 43 | timeRange: TimeRange) -> Promise> { 44 | return firstly { 45 | getTokens() 46 | }.map { tokens in 47 | let token = try tokens.tokenByTokenIdentifier(tokenIdentifier) 48 | let forcedExit = ForcedExit(initiatorAccountId: accountId, 49 | target: target, 50 | token: token.id, 51 | fee: fee.description, 52 | nonce: nonce, 53 | timeRange: timeRange) 54 | 55 | let ethSignature = try self.ethSigner.signTransaction(transaction: forcedExit, 56 | nonce: nonce, 57 | token: token, 58 | fee: fee) 59 | 60 | let transaction = try self.zkSigner.sign(forcedExit: forcedExit) 61 | let signedTransaction = SignedTransaction(transaction: transaction, 62 | ethereumSignature: ethSignature) 63 | return signedTransaction 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Sources/ZKSync/Wallet/DefaultWallet+Swap.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultWallet+Swap.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 23/05/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | import PromiseKit 11 | 12 | extension DefaultWallet { 13 | 14 | // swiftlint:disable:next function_parameter_count 15 | public func swap(order1: Order, 16 | order2: Order, 17 | amount1: BigUInt, 18 | amount2: BigUInt, 19 | fee: TransactionFee, 20 | nonce: UInt32?, 21 | completion: @escaping (Swift.Result) -> Void) { 22 | firstly { 23 | getNonceAccountIdPair(for: nonce) 24 | }.then { (nonce, accountId) in 25 | self.buildSignedSwapTx(order1: order1, 26 | order2: order2, 27 | amount1: amount1, 28 | amount2: amount2, 29 | fee: fee, 30 | accountId: accountId, 31 | nonce: nonce) 32 | }.then { signedTransaction in 33 | self.submitSignedTransaction(signedTransaction.transaction, 34 | ethereumSignature: signedTransaction.ethereumSignature, 35 | fastProcessing: false) 36 | }.pipe { result in 37 | completion(result.result) 38 | } 39 | } 40 | 41 | // swiftlint:disable:next function_parameter_count 42 | public func buildSignedSwapTx(order1: Order, 43 | order2: Order, 44 | amount1: BigUInt, 45 | amount2: BigUInt, 46 | fee: TransactionFee, 47 | accountId: UInt32, 48 | nonce: UInt32) -> Promise> { 49 | return firstly { 50 | self.getTokens() 51 | }.map { tokens in 52 | let feeToken = try tokens.tokenByTokenIdentifier(fee.feeToken) 53 | let swap = Swap(submitterId: accountId, 54 | submitterAddress: self.ethSigner.address, 55 | nonce: nonce, 56 | orders: (order1, order2), 57 | amounts: (amount1, amount2), 58 | fee: fee.fee.description, 59 | feeToken: feeToken.id) 60 | 61 | let ethSignature = try self.ethSigner.signTransaction(transaction: swap, 62 | nonce: nonce, 63 | token: feeToken, 64 | fee: fee.fee) 65 | 66 | let transaction = try self.zkSigner.sign(swap: swap) 67 | return SignedTransaction(transaction: transaction, 68 | ethereumSignature: ethSignature) 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Examples/SPM/ZKSyncExample.xcodeproj/xcshareddata/xcschemes/ZKSyncExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 45 | 51 | 52 | 53 | 54 | 60 | 62 | 68 | 69 | 70 | 71 | 73 | 74 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64.swiftinterface: -------------------------------------------------------------------------------- 1 | // swift-interface-format-version: 1.0 2 | // swift-compiler-version: Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) 3 | // swift-module-flags: -target arm64-apple-ios13.1 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name ZKSyncCrypto 4 | import Foundation 5 | import Swift 6 | @_exported import ZKSyncCrypto 7 | import _Concurrency 8 | @objc @_inheritsConvenienceInitializers public class ZKSyncCrypto : ObjectiveC.NSObject { 9 | public static func generatePrivateKey(seed: Foundation.Data) -> Swift.Result 10 | public static func getPublicKey(privateKey: ZKPrivateKey) -> Swift.Result 11 | public static func getPublicKeyHash(publicKey: ZKPackedPublicKey) -> Swift.Result 12 | public static func signMessage(privateKey: ZKPrivateKey, message: Swift.String) -> Swift.Result 13 | public static func signMessage(privateKey: ZKPrivateKey, message: Foundation.Data) -> Swift.Result 14 | public static func rescueHashOrders(message: Foundation.Data) -> ZKResqueHash 15 | @objc override dynamic public init() 16 | @objc deinit 17 | } 18 | public class ZKPrimitive { 19 | public init(_ content: Foundation.Data) 20 | convenience public init(_ content: [Swift.UInt8]) 21 | public func data() -> Foundation.Data 22 | public func base64String() -> Swift.String 23 | public func hexEncodedString() -> Swift.String 24 | @objc deinit 25 | } 26 | @_inheritsConvenienceInitializers public class ZKPackedPublicKey : ZKPrimitive { 27 | override public init(_ content: Foundation.Data) 28 | @objc deinit 29 | } 30 | @_inheritsConvenienceInitializers public class ZKPrivateKey : ZKPrimitive { 31 | public class var bytesLength: Swift.Int { 32 | get 33 | } 34 | override public init(_ content: Foundation.Data) 35 | @objc deinit 36 | } 37 | @_inheritsConvenienceInitializers public class ZKPublicHash : ZKPrimitive { 38 | override public init(_ content: Foundation.Data) 39 | @objc deinit 40 | } 41 | @_inheritsConvenienceInitializers public class ZKSignature : ZKPrimitive { 42 | override public init(_ content: Foundation.Data) 43 | @objc deinit 44 | } 45 | @_inheritsConvenienceInitializers public class ZKResqueHash : ZKPrimitive { 46 | override public init(_ content: Foundation.Data) 47 | @objc deinit 48 | } 49 | public enum ZKSyncCryptoError : Swift.Error { 50 | case musigTooLongError 51 | case seedTooShortError 52 | case unsupportedOperation 53 | public static func == (a: ZKSyncCryptoError, b: ZKSyncCryptoError) -> Swift.Bool 54 | public func hash(into hasher: inout Swift.Hasher) 55 | public var hashValue: Swift.Int { 56 | get 57 | } 58 | } 59 | public typealias CLibZksPrivateKey = ZksPrivateKey 60 | public typealias CLibZksPackedPublicKey = ZksPackedPublicKey 61 | public typealias CLibZksPubkeyHash = ZksPubkeyHash 62 | public typealias CLibZksSignature = ZksSignature 63 | public typealias CLibZksResqueHash = ZksResqueHash 64 | extension ZKSyncCryptoError : Swift.Equatable {} 65 | extension ZKSyncCryptoError : Swift.Hashable {} 66 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64-apple-ios.swiftinterface: -------------------------------------------------------------------------------- 1 | // swift-interface-format-version: 1.0 2 | // swift-compiler-version: Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) 3 | // swift-module-flags: -target arm64-apple-ios13.1 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name ZKSyncCrypto 4 | import Foundation 5 | import Swift 6 | @_exported import ZKSyncCrypto 7 | import _Concurrency 8 | @objc @_inheritsConvenienceInitializers public class ZKSyncCrypto : ObjectiveC.NSObject { 9 | public static func generatePrivateKey(seed: Foundation.Data) -> Swift.Result 10 | public static func getPublicKey(privateKey: ZKPrivateKey) -> Swift.Result 11 | public static func getPublicKeyHash(publicKey: ZKPackedPublicKey) -> Swift.Result 12 | public static func signMessage(privateKey: ZKPrivateKey, message: Swift.String) -> Swift.Result 13 | public static func signMessage(privateKey: ZKPrivateKey, message: Foundation.Data) -> Swift.Result 14 | public static func rescueHashOrders(message: Foundation.Data) -> ZKResqueHash 15 | @objc override dynamic public init() 16 | @objc deinit 17 | } 18 | public class ZKPrimitive { 19 | public init(_ content: Foundation.Data) 20 | convenience public init(_ content: [Swift.UInt8]) 21 | public func data() -> Foundation.Data 22 | public func base64String() -> Swift.String 23 | public func hexEncodedString() -> Swift.String 24 | @objc deinit 25 | } 26 | @_inheritsConvenienceInitializers public class ZKPackedPublicKey : ZKPrimitive { 27 | override public init(_ content: Foundation.Data) 28 | @objc deinit 29 | } 30 | @_inheritsConvenienceInitializers public class ZKPrivateKey : ZKPrimitive { 31 | public class var bytesLength: Swift.Int { 32 | get 33 | } 34 | override public init(_ content: Foundation.Data) 35 | @objc deinit 36 | } 37 | @_inheritsConvenienceInitializers public class ZKPublicHash : ZKPrimitive { 38 | override public init(_ content: Foundation.Data) 39 | @objc deinit 40 | } 41 | @_inheritsConvenienceInitializers public class ZKSignature : ZKPrimitive { 42 | override public init(_ content: Foundation.Data) 43 | @objc deinit 44 | } 45 | @_inheritsConvenienceInitializers public class ZKResqueHash : ZKPrimitive { 46 | override public init(_ content: Foundation.Data) 47 | @objc deinit 48 | } 49 | public enum ZKSyncCryptoError : Swift.Error { 50 | case musigTooLongError 51 | case seedTooShortError 52 | case unsupportedOperation 53 | public static func == (a: ZKSyncCryptoError, b: ZKSyncCryptoError) -> Swift.Bool 54 | public func hash(into hasher: inout Swift.Hasher) 55 | public var hashValue: Swift.Int { 56 | get 57 | } 58 | } 59 | public typealias CLibZksPrivateKey = ZksPrivateKey 60 | public typealias CLibZksPackedPublicKey = ZksPackedPublicKey 61 | public typealias CLibZksPubkeyHash = ZksPubkeyHash 62 | public typealias CLibZksSignature = ZksSignature 63 | public typealias CLibZksResqueHash = ZksResqueHash 64 | extension ZKSyncCryptoError : Swift.Equatable {} 65 | extension ZKSyncCryptoError : Swift.Hashable {} 66 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64.swiftinterface: -------------------------------------------------------------------------------- 1 | // swift-interface-format-version: 1.0 2 | // swift-compiler-version: Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) 3 | // swift-module-flags: -target arm64-apple-ios13.1-simulator -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name ZKSyncCrypto 4 | import Foundation 5 | import Swift 6 | @_exported import ZKSyncCrypto 7 | import _Concurrency 8 | @objc @_inheritsConvenienceInitializers public class ZKSyncCrypto : ObjectiveC.NSObject { 9 | public static func generatePrivateKey(seed: Foundation.Data) -> Swift.Result 10 | public static func getPublicKey(privateKey: ZKPrivateKey) -> Swift.Result 11 | public static func getPublicKeyHash(publicKey: ZKPackedPublicKey) -> Swift.Result 12 | public static func signMessage(privateKey: ZKPrivateKey, message: Swift.String) -> Swift.Result 13 | public static func signMessage(privateKey: ZKPrivateKey, message: Foundation.Data) -> Swift.Result 14 | public static func rescueHashOrders(message: Foundation.Data) -> ZKResqueHash 15 | @objc override dynamic public init() 16 | @objc deinit 17 | } 18 | public class ZKPrimitive { 19 | public init(_ content: Foundation.Data) 20 | convenience public init(_ content: [Swift.UInt8]) 21 | public func data() -> Foundation.Data 22 | public func base64String() -> Swift.String 23 | public func hexEncodedString() -> Swift.String 24 | @objc deinit 25 | } 26 | @_inheritsConvenienceInitializers public class ZKPackedPublicKey : ZKPrimitive { 27 | override public init(_ content: Foundation.Data) 28 | @objc deinit 29 | } 30 | @_inheritsConvenienceInitializers public class ZKPrivateKey : ZKPrimitive { 31 | public class var bytesLength: Swift.Int { 32 | get 33 | } 34 | override public init(_ content: Foundation.Data) 35 | @objc deinit 36 | } 37 | @_inheritsConvenienceInitializers public class ZKPublicHash : ZKPrimitive { 38 | override public init(_ content: Foundation.Data) 39 | @objc deinit 40 | } 41 | @_inheritsConvenienceInitializers public class ZKSignature : ZKPrimitive { 42 | override public init(_ content: Foundation.Data) 43 | @objc deinit 44 | } 45 | @_inheritsConvenienceInitializers public class ZKResqueHash : ZKPrimitive { 46 | override public init(_ content: Foundation.Data) 47 | @objc deinit 48 | } 49 | public enum ZKSyncCryptoError : Swift.Error { 50 | case musigTooLongError 51 | case seedTooShortError 52 | case unsupportedOperation 53 | public static func == (a: ZKSyncCryptoError, b: ZKSyncCryptoError) -> Swift.Bool 54 | public func hash(into hasher: inout Swift.Hasher) 55 | public var hashValue: Swift.Int { 56 | get 57 | } 58 | } 59 | public typealias CLibZksPrivateKey = ZksPrivateKey 60 | public typealias CLibZksPackedPublicKey = ZksPackedPublicKey 61 | public typealias CLibZksPubkeyHash = ZksPubkeyHash 62 | public typealias CLibZksSignature = ZksSignature 63 | public typealias CLibZksResqueHash = ZksResqueHash 64 | extension ZKSyncCryptoError : Swift.Equatable {} 65 | extension ZKSyncCryptoError : Swift.Hashable {} 66 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/x86_64.swiftinterface: -------------------------------------------------------------------------------- 1 | // swift-interface-format-version: 1.0 2 | // swift-compiler-version: Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) 3 | // swift-module-flags: -target x86_64-apple-ios13.1-simulator -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name ZKSyncCrypto 4 | import Foundation 5 | import Swift 6 | @_exported import ZKSyncCrypto 7 | import _Concurrency 8 | @objc @_inheritsConvenienceInitializers public class ZKSyncCrypto : ObjectiveC.NSObject { 9 | public static func generatePrivateKey(seed: Foundation.Data) -> Swift.Result 10 | public static func getPublicKey(privateKey: ZKPrivateKey) -> Swift.Result 11 | public static func getPublicKeyHash(publicKey: ZKPackedPublicKey) -> Swift.Result 12 | public static func signMessage(privateKey: ZKPrivateKey, message: Swift.String) -> Swift.Result 13 | public static func signMessage(privateKey: ZKPrivateKey, message: Foundation.Data) -> Swift.Result 14 | public static func rescueHashOrders(message: Foundation.Data) -> ZKResqueHash 15 | @objc override dynamic public init() 16 | @objc deinit 17 | } 18 | public class ZKPrimitive { 19 | public init(_ content: Foundation.Data) 20 | convenience public init(_ content: [Swift.UInt8]) 21 | public func data() -> Foundation.Data 22 | public func base64String() -> Swift.String 23 | public func hexEncodedString() -> Swift.String 24 | @objc deinit 25 | } 26 | @_inheritsConvenienceInitializers public class ZKPackedPublicKey : ZKPrimitive { 27 | override public init(_ content: Foundation.Data) 28 | @objc deinit 29 | } 30 | @_inheritsConvenienceInitializers public class ZKPrivateKey : ZKPrimitive { 31 | public class var bytesLength: Swift.Int { 32 | get 33 | } 34 | override public init(_ content: Foundation.Data) 35 | @objc deinit 36 | } 37 | @_inheritsConvenienceInitializers public class ZKPublicHash : ZKPrimitive { 38 | override public init(_ content: Foundation.Data) 39 | @objc deinit 40 | } 41 | @_inheritsConvenienceInitializers public class ZKSignature : ZKPrimitive { 42 | override public init(_ content: Foundation.Data) 43 | @objc deinit 44 | } 45 | @_inheritsConvenienceInitializers public class ZKResqueHash : ZKPrimitive { 46 | override public init(_ content: Foundation.Data) 47 | @objc deinit 48 | } 49 | public enum ZKSyncCryptoError : Swift.Error { 50 | case musigTooLongError 51 | case seedTooShortError 52 | case unsupportedOperation 53 | public static func == (a: ZKSyncCryptoError, b: ZKSyncCryptoError) -> Swift.Bool 54 | public func hash(into hasher: inout Swift.Hasher) 55 | public var hashValue: Swift.Int { 56 | get 57 | } 58 | } 59 | public typealias CLibZksPrivateKey = ZksPrivateKey 60 | public typealias CLibZksPackedPublicKey = ZksPackedPublicKey 61 | public typealias CLibZksPubkeyHash = ZksPubkeyHash 62 | public typealias CLibZksSignature = ZksSignature 63 | public typealias CLibZksResqueHash = ZksResqueHash 64 | extension ZKSyncCryptoError : Swift.Equatable {} 65 | extension ZKSyncCryptoError : Swift.Hashable {} 66 | -------------------------------------------------------------------------------- /Sources/ZKSync/Wallet/DefaultWallet+WithdrawNFT.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultWallet+WithdrawNFT.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 20/05/2021. 6 | // 7 | 8 | import Foundation 9 | import PromiseKit 10 | 11 | extension DefaultWallet { 12 | 13 | // swiftlint:disable:next function_parameter_count 14 | public func withdrawNFT(to: String, 15 | token: NFT, 16 | fee: TransactionFee, 17 | nonce: UInt32?, 18 | timeRange: TimeRange, 19 | completion: @escaping (Swift.Result) -> Void) { 20 | firstly { 21 | getNonceAccountIdPair(for: nonce) 22 | }.then { (nonce, accountId) in 23 | self.buildSignedWithdrawNFTTx(to: to, 24 | token: token, 25 | fee: fee, 26 | accountId: accountId, 27 | nonce: nonce, 28 | timeRange: timeRange) 29 | }.then { signedTransaction in 30 | self.submitSignedTransaction(signedTransaction.transaction, 31 | ethereumSignature: signedTransaction.ethereumSignature, 32 | fastProcessing: false) 33 | }.pipe { result in 34 | completion(result.result) 35 | } 36 | } 37 | 38 | // swiftlint:disable:next function_parameter_count 39 | func buildSignedWithdrawNFTTx(to: String, 40 | token: NFT, 41 | fee: TransactionFee, 42 | accountId: UInt32, 43 | nonce: UInt32, 44 | timeRange: TimeRange) -> Promise> { 45 | return firstly { 46 | self.getTokens() 47 | }.map { tokens in 48 | let feeToken = try tokens.tokenByTokenIdentifier(fee.feeToken) 49 | let withdrawNFT = WithdrawNFT(accountId: accountId, 50 | from: self.ethSigner.address, 51 | to: to, 52 | token: token.id, 53 | feeToken: feeToken.id, 54 | fee: fee.fee.description, 55 | nonce: nonce, 56 | timeRange: timeRange) 57 | 58 | let ethSignature = try self.ethSigner.signTransaction(transaction: withdrawNFT, 59 | nonce: nonce, 60 | token: feeToken, 61 | fee: fee.fee) 62 | 63 | let transaction = try self.zkSigner.sign(withdrawNFT: withdrawNFT) 64 | let signedTransaction = SignedTransaction(transaction: transaction, 65 | ethereumSignature: ethSignature) 66 | return signedTransaction 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Sources/ZKSync/Signer/Utils/Bits.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Bits.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 11/01/2021. 6 | // 7 | 8 | import Foundation 9 | 10 | enum BitsError: Error { 11 | case incorrectSize 12 | } 13 | 14 | struct Bits: CustomStringConvertible, Sequence, IteratorProtocol { 15 | 16 | private var currentIndex = 0 17 | mutating func next() -> Bool? { 18 | if currentIndex < self.bits.count { 19 | currentIndex += 1 20 | return bits[currentIndex - 1] 21 | } else { 22 | currentIndex = 0 23 | return nil 24 | } 25 | } 26 | 27 | typealias Element = Bool 28 | 29 | private var bits: [Bool] 30 | 31 | init(size: Int) { 32 | self.bits = Array(repeating: false, count: size) 33 | } 34 | 35 | init(bits: [Bool]) { 36 | self.bits = bits 37 | } 38 | 39 | init(dataBEOrder: Data) { 40 | self.init(size: dataBEOrder.count * 8) 41 | dataBEOrder.enumerated().forEach { (index, byte) in 42 | for bit in 0...7 { 43 | bits[index * 8 + bit] = (((byte >> (7 - bit)) & 0x01) == 1) 44 | } 45 | } 46 | } 47 | 48 | var size: Int { 49 | return bits.count 50 | } 51 | 52 | subscript(index: Int) -> Bool { 53 | get { 54 | return bits[index] 55 | } 56 | set(newValue) { 57 | bits[index] = newValue 58 | } 59 | } 60 | 61 | mutating func set(index: Int) { 62 | bits[index] = true 63 | } 64 | 65 | mutating func set(index: Int, value: Int) { 66 | bits[index] = value != 0 67 | } 68 | 69 | var reversed: Bits { 70 | return Bits(bits: bits.reversed()) 71 | } 72 | 73 | var description: String { 74 | return bits.reduce("") { (result, bit) -> String in 75 | var newResult = result.appending("\(bit ? 1 : 0)") 76 | newResult.append(", ") 77 | return newResult 78 | } 79 | } 80 | 81 | static func + (lhs: Bits, rhs: Bits) -> Bits { 82 | let size = lhs.size + rhs.size 83 | let lhsSize = lhs.size 84 | 85 | var bits = Bits(size: size) 86 | 87 | for (index, bit) in lhs.enumerated() { 88 | bits[index] = bit 89 | } 90 | 91 | for (index, bit) in rhs.enumerated() { 92 | bits[index + lhsSize] = bit 93 | } 94 | 95 | return bits 96 | } 97 | 98 | func bytesBEOrder() throws -> Data { 99 | 100 | guard bits.count % 8 == 0 else { 101 | throw BitsError.incorrectSize 102 | } 103 | 104 | let numBytes = bits.count / 8 105 | 106 | var resultBytes = Data(repeating: 0, count: numBytes) 107 | for currentByte in 0.. Swift.Result 10 | public static func getPublicKey(privateKey: ZKPrivateKey) -> Swift.Result 11 | public static func getPublicKeyHash(publicKey: ZKPackedPublicKey) -> Swift.Result 12 | public static func signMessage(privateKey: ZKPrivateKey, message: Swift.String) -> Swift.Result 13 | public static func signMessage(privateKey: ZKPrivateKey, message: Foundation.Data) -> Swift.Result 14 | public static func rescueHashOrders(message: Foundation.Data) -> ZKResqueHash 15 | @objc override dynamic public init() 16 | @objc deinit 17 | } 18 | public class ZKPrimitive { 19 | public init(_ content: Foundation.Data) 20 | convenience public init(_ content: [Swift.UInt8]) 21 | public func data() -> Foundation.Data 22 | public func base64String() -> Swift.String 23 | public func hexEncodedString() -> Swift.String 24 | @objc deinit 25 | } 26 | @_inheritsConvenienceInitializers public class ZKPackedPublicKey : ZKPrimitive { 27 | override public init(_ content: Foundation.Data) 28 | @objc deinit 29 | } 30 | @_inheritsConvenienceInitializers public class ZKPrivateKey : ZKPrimitive { 31 | public class var bytesLength: Swift.Int { 32 | get 33 | } 34 | override public init(_ content: Foundation.Data) 35 | @objc deinit 36 | } 37 | @_inheritsConvenienceInitializers public class ZKPublicHash : ZKPrimitive { 38 | override public init(_ content: Foundation.Data) 39 | @objc deinit 40 | } 41 | @_inheritsConvenienceInitializers public class ZKSignature : ZKPrimitive { 42 | override public init(_ content: Foundation.Data) 43 | @objc deinit 44 | } 45 | @_inheritsConvenienceInitializers public class ZKResqueHash : ZKPrimitive { 46 | override public init(_ content: Foundation.Data) 47 | @objc deinit 48 | } 49 | public enum ZKSyncCryptoError : Swift.Error { 50 | case musigTooLongError 51 | case seedTooShortError 52 | case unsupportedOperation 53 | public static func == (a: ZKSyncCryptoError, b: ZKSyncCryptoError) -> Swift.Bool 54 | public func hash(into hasher: inout Swift.Hasher) 55 | public var hashValue: Swift.Int { 56 | get 57 | } 58 | } 59 | public typealias CLibZksPrivateKey = ZksPrivateKey 60 | public typealias CLibZksPackedPublicKey = ZksPackedPublicKey 61 | public typealias CLibZksPubkeyHash = ZksPubkeyHash 62 | public typealias CLibZksSignature = ZksSignature 63 | public typealias CLibZksResqueHash = ZksResqueHash 64 | extension ZKSyncCryptoError : Swift.Equatable {} 65 | extension ZKSyncCryptoError : Swift.Hashable {} 66 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/x86_64-apple-ios-simulator.swiftinterface: -------------------------------------------------------------------------------- 1 | // swift-interface-format-version: 1.0 2 | // swift-compiler-version: Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) 3 | // swift-module-flags: -target x86_64-apple-ios13.1-simulator -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name ZKSyncCrypto 4 | import Foundation 5 | import Swift 6 | @_exported import ZKSyncCrypto 7 | import _Concurrency 8 | @objc @_inheritsConvenienceInitializers public class ZKSyncCrypto : ObjectiveC.NSObject { 9 | public static func generatePrivateKey(seed: Foundation.Data) -> Swift.Result 10 | public static func getPublicKey(privateKey: ZKPrivateKey) -> Swift.Result 11 | public static func getPublicKeyHash(publicKey: ZKPackedPublicKey) -> Swift.Result 12 | public static func signMessage(privateKey: ZKPrivateKey, message: Swift.String) -> Swift.Result 13 | public static func signMessage(privateKey: ZKPrivateKey, message: Foundation.Data) -> Swift.Result 14 | public static func rescueHashOrders(message: Foundation.Data) -> ZKResqueHash 15 | @objc override dynamic public init() 16 | @objc deinit 17 | } 18 | public class ZKPrimitive { 19 | public init(_ content: Foundation.Data) 20 | convenience public init(_ content: [Swift.UInt8]) 21 | public func data() -> Foundation.Data 22 | public func base64String() -> Swift.String 23 | public func hexEncodedString() -> Swift.String 24 | @objc deinit 25 | } 26 | @_inheritsConvenienceInitializers public class ZKPackedPublicKey : ZKPrimitive { 27 | override public init(_ content: Foundation.Data) 28 | @objc deinit 29 | } 30 | @_inheritsConvenienceInitializers public class ZKPrivateKey : ZKPrimitive { 31 | public class var bytesLength: Swift.Int { 32 | get 33 | } 34 | override public init(_ content: Foundation.Data) 35 | @objc deinit 36 | } 37 | @_inheritsConvenienceInitializers public class ZKPublicHash : ZKPrimitive { 38 | override public init(_ content: Foundation.Data) 39 | @objc deinit 40 | } 41 | @_inheritsConvenienceInitializers public class ZKSignature : ZKPrimitive { 42 | override public init(_ content: Foundation.Data) 43 | @objc deinit 44 | } 45 | @_inheritsConvenienceInitializers public class ZKResqueHash : ZKPrimitive { 46 | override public init(_ content: Foundation.Data) 47 | @objc deinit 48 | } 49 | public enum ZKSyncCryptoError : Swift.Error { 50 | case musigTooLongError 51 | case seedTooShortError 52 | case unsupportedOperation 53 | public static func == (a: ZKSyncCryptoError, b: ZKSyncCryptoError) -> Swift.Bool 54 | public func hash(into hasher: inout Swift.Hasher) 55 | public var hashValue: Swift.Int { 56 | get 57 | } 58 | } 59 | public typealias CLibZksPrivateKey = ZksPrivateKey 60 | public typealias CLibZksPackedPublicKey = ZksPackedPublicKey 61 | public typealias CLibZksPubkeyHash = ZksPubkeyHash 62 | public typealias CLibZksSignature = ZksSignature 63 | public typealias CLibZksResqueHash = ZksResqueHash 64 | extension ZKSyncCryptoError : Swift.Equatable {} 65 | extension ZKSyncCryptoError : Swift.Hashable {} 66 | -------------------------------------------------------------------------------- /Sources/ZKSync/Wallet/DefaultWallet+Transfer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultWallet+Transfer.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | import PromiseKit 10 | import BigInt 11 | 12 | extension DefaultWallet { 13 | 14 | // swiftlint:disable:next function_parameter_count 15 | public func transfer(to: String, 16 | amount: BigUInt, 17 | fee: TransactionFee, 18 | nonce: UInt32?, 19 | timeRange: TimeRange, 20 | completion: @escaping (Swift.Result) -> Void) { 21 | firstly { 22 | getNonceAccountIdPair(for: nonce) 23 | }.then { (nonce, accountId) in 24 | self.buildSignedTransferTx(to: to, 25 | tokenIdentifier: fee.feeToken, 26 | amount: amount, 27 | fee: fee.fee, 28 | accountId: accountId, 29 | nonce: nonce, 30 | timeRange: timeRange) 31 | }.then { signedTransaction in 32 | self.submitSignedTransaction(signedTransaction.transaction, 33 | ethereumSignature: signedTransaction.ethereumSignature, 34 | fastProcessing: false) 35 | }.pipe { result in 36 | completion(result.result) 37 | } 38 | } 39 | 40 | // swiftlint:disable:next function_parameter_count 41 | public func buildSignedTransferTx(to: String, 42 | tokenIdentifier: String, 43 | amount: BigUInt, 44 | fee: BigUInt, 45 | accountId: UInt32, 46 | nonce: UInt32, 47 | timeRange: TimeRange) -> Promise> { 48 | return firstly { 49 | getTokens() 50 | }.map { tokens in 51 | let token = try tokens.tokenByTokenIdentifier(tokenIdentifier) 52 | let transfer = Transfer(accountId: accountId, 53 | from: self.ethSigner.address, 54 | to: to, 55 | token: token.id, 56 | amount: amount, 57 | fee: fee.description, 58 | nonce: nonce, 59 | timeRange: timeRange) 60 | 61 | let ethSignature = try self.ethSigner.signTransaction(transaction: transfer, 62 | nonce: nonce, 63 | token: token, 64 | fee: fee) 65 | 66 | let transaction = try self.zkSigner.sign(transfer: transfer) 67 | let signedTransaction = SignedTransaction(transaction: transaction, 68 | ethereumSignature: ethSignature) 69 | return signedTransaction 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Sources/ZKSync/Wallet/Wallet+DefaultTimeRange.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Wallet+DefaultTimeRange.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 24/03/2021. 6 | // 7 | 8 | import Foundation 9 | import BigInt 10 | 11 | public extension Wallet { 12 | 13 | func setSigningKey(fee: TransactionFee, 14 | nonce: UInt32?, 15 | onchainAuth: Bool, 16 | completion: @escaping (Swift.Result) -> Void) { 17 | self.setSigningKey(fee: fee, 18 | nonce: nonce, 19 | onchainAuth: onchainAuth, 20 | timeRange: .max, 21 | completion: completion) 22 | } 23 | 24 | func transfer(to: String, 25 | amount: BigUInt, 26 | fee: TransactionFee, 27 | nonce: UInt32?, 28 | completion: @escaping (Swift.Result) -> Void) { 29 | self.transfer(to: to, 30 | amount: amount, 31 | fee: fee, 32 | nonce: nonce, 33 | timeRange: .max, 34 | completion: completion) 35 | } 36 | 37 | // swiftlint:disable:next function_parameter_count 38 | func withdraw(ethAddress: String, 39 | amount: BigUInt, 40 | fee: TransactionFee, 41 | nonce: UInt32?, 42 | fastProcessing: Bool, 43 | completion: @escaping (Swift.Result) -> Void) { 44 | self.withdraw(ethAddress: ethAddress, 45 | amount: amount, 46 | fee: fee, 47 | nonce: nonce, 48 | fastProcessing: fastProcessing, 49 | timeRange: .max, 50 | completion: completion) 51 | } 52 | 53 | func forcedExit(target: String, 54 | fee: TransactionFee, 55 | nonce: UInt32?, 56 | completion: @escaping (Swift.Result) -> Void) { 57 | self.forcedExit(target: target, 58 | fee: fee, 59 | nonce: nonce, 60 | timeRange: .max, 61 | completion: completion) 62 | } 63 | 64 | func withdrawNFT(to: String, 65 | token: NFT, 66 | fee: TransactionFee, 67 | nonce: UInt32?, 68 | completion: @escaping (Swift.Result) -> Void) { 69 | self.withdrawNFT(to: to, 70 | token: token, 71 | fee: fee, 72 | nonce: nonce, 73 | timeRange: .max, 74 | completion: completion) 75 | } 76 | 77 | func transferNFT(to: String, 78 | token: NFT, 79 | fee: TransactionFee, 80 | nonce: UInt32?, 81 | completion: @escaping (Swift.Result<[String], Error>) -> Void) { 82 | self.transferNFT(to: to, 83 | token: token, 84 | fee: fee, 85 | nonce: nonce, 86 | timeRange: .max, 87 | completion: completion) 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Sources/ZKSync/Wallet/DefaultWallet+Withdraw.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DefaultWallet+Withdraw.swift 3 | // ZKSync 4 | // 5 | // Created by Eugene Belyakov on 16/01/2021. 6 | // 7 | 8 | import Foundation 9 | import PromiseKit 10 | import BigInt 11 | 12 | extension DefaultWallet { 13 | 14 | // swiftlint:disable:next function_parameter_count 15 | public func withdraw(ethAddress: String, 16 | amount: BigUInt, 17 | fee: TransactionFee, 18 | nonce: UInt32?, 19 | fastProcessing: Bool, 20 | timeRange: TimeRange, 21 | completion: @escaping (Swift.Result) -> Void) { 22 | firstly { 23 | getNonceAccountIdPair(for: nonce) 24 | }.then { (nonce, accountId) in 25 | self.buildSignedWithdrawTx(to: ethAddress, 26 | tokenIdentifier: fee.feeToken, 27 | amount: amount, 28 | fee: fee.fee, 29 | accountId: accountId, 30 | nonce: nonce, 31 | timeRange: timeRange) 32 | }.then { signedTransaction in 33 | self.submitSignedTransaction(signedTransaction.transaction, 34 | ethereumSignature: signedTransaction.ethereumSignature, 35 | fastProcessing: fastProcessing) 36 | }.pipe { result in 37 | completion(result.result) 38 | } 39 | } 40 | 41 | // swiftlint:disable:next function_parameter_count 42 | public func buildSignedWithdrawTx(to: String, 43 | tokenIdentifier: String, 44 | amount: BigUInt, 45 | fee: BigUInt, 46 | accountId: UInt32, 47 | nonce: UInt32, 48 | timeRange: TimeRange) -> Promise> { 49 | return firstly { 50 | self.getTokens() 51 | }.map { tokens in 52 | let token = try tokens.tokenByTokenIdentifier(tokenIdentifier) 53 | let withdraw = Withdraw(accountId: accountId, 54 | from: self.ethSigner.address, 55 | to: to, 56 | token: token.id, 57 | amount: amount, 58 | fee: fee.description, 59 | nonce: nonce, 60 | timeRange: timeRange) 61 | 62 | let ethSignature = try self.ethSigner.signTransaction(transaction: withdraw, 63 | nonce: nonce, 64 | token: token, 65 | fee: fee) 66 | 67 | let transaction = try self.zkSigner.sign(withdraw: withdraw) 68 | let signedTransaction = SignedTransaction(transaction: transaction, 69 | ethereumSignature: ethSignature) 70 | return signedTransaction 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64.swiftinterface-e: -------------------------------------------------------------------------------- 1 | // swift-interface-format-version: 1.0 2 | // swift-compiler-version: Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) 3 | // swift-module-flags: -target arm64-apple-ios13.1 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name ZKSyncCrypto 4 | import Foundation 5 | import Swift 6 | @_exported import ZKSyncCrypto 7 | import _Concurrency 8 | @objc @_inheritsConvenienceInitializers public class ZKSyncCrypto : ObjectiveC.NSObject { 9 | public static func generatePrivateKey(seed: Foundation.Data) -> Swift.Result 10 | public static func getPublicKey(privateKey: ZKSyncCrypto.ZKPrivateKey) -> Swift.Result 11 | public static func getPublicKeyHash(publicKey: ZKSyncCrypto.ZKPackedPublicKey) -> Swift.Result 12 | public static func signMessage(privateKey: ZKSyncCrypto.ZKPrivateKey, message: Swift.String) -> Swift.Result 13 | public static func signMessage(privateKey: ZKSyncCrypto.ZKPrivateKey, message: Foundation.Data) -> Swift.Result 14 | public static func rescueHashOrders(message: Foundation.Data) -> ZKSyncCrypto.ZKResqueHash 15 | @objc override dynamic public init() 16 | @objc deinit 17 | } 18 | public class ZKPrimitive { 19 | public init(_ content: Foundation.Data) 20 | convenience public init(_ content: [Swift.UInt8]) 21 | public func data() -> Foundation.Data 22 | public func base64String() -> Swift.String 23 | public func hexEncodedString() -> Swift.String 24 | @objc deinit 25 | } 26 | @_inheritsConvenienceInitializers public class ZKPackedPublicKey : ZKSyncCrypto.ZKPrimitive { 27 | override public init(_ content: Foundation.Data) 28 | @objc deinit 29 | } 30 | @_inheritsConvenienceInitializers public class ZKPrivateKey : ZKSyncCrypto.ZKPrimitive { 31 | public class var bytesLength: Swift.Int { 32 | get 33 | } 34 | override public init(_ content: Foundation.Data) 35 | @objc deinit 36 | } 37 | @_inheritsConvenienceInitializers public class ZKPublicHash : ZKSyncCrypto.ZKPrimitive { 38 | override public init(_ content: Foundation.Data) 39 | @objc deinit 40 | } 41 | @_inheritsConvenienceInitializers public class ZKSignature : ZKSyncCrypto.ZKPrimitive { 42 | override public init(_ content: Foundation.Data) 43 | @objc deinit 44 | } 45 | @_inheritsConvenienceInitializers public class ZKResqueHash : ZKSyncCrypto.ZKPrimitive { 46 | override public init(_ content: Foundation.Data) 47 | @objc deinit 48 | } 49 | public enum ZKSyncCryptoError : Swift.Error { 50 | case musigTooLongError 51 | case seedTooShortError 52 | case unsupportedOperation 53 | public static func == (a: ZKSyncCrypto.ZKSyncCryptoError, b: ZKSyncCrypto.ZKSyncCryptoError) -> Swift.Bool 54 | public func hash(into hasher: inout Swift.Hasher) 55 | public var hashValue: Swift.Int { 56 | get 57 | } 58 | } 59 | public typealias CLibZksPrivateKey = ZKSyncCrypto.ZksPrivateKey 60 | public typealias CLibZksPackedPublicKey = ZKSyncCrypto.ZksPackedPublicKey 61 | public typealias CLibZksPubkeyHash = ZKSyncCrypto.ZksPubkeyHash 62 | public typealias CLibZksSignature = ZKSyncCrypto.ZksSignature 63 | public typealias CLibZksResqueHash = ZKSyncCrypto.ZksResqueHash 64 | extension ZKSyncCrypto.ZKSyncCryptoError : Swift.Equatable {} 65 | extension ZKSyncCrypto.ZKSyncCryptoError : Swift.Hashable {} 66 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64-apple-ios.swiftinterface-e: -------------------------------------------------------------------------------- 1 | // swift-interface-format-version: 1.0 2 | // swift-compiler-version: Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) 3 | // swift-module-flags: -target arm64-apple-ios13.1 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name ZKSyncCrypto 4 | import Foundation 5 | import Swift 6 | @_exported import ZKSyncCrypto 7 | import _Concurrency 8 | @objc @_inheritsConvenienceInitializers public class ZKSyncCrypto : ObjectiveC.NSObject { 9 | public static func generatePrivateKey(seed: Foundation.Data) -> Swift.Result 10 | public static func getPublicKey(privateKey: ZKSyncCrypto.ZKPrivateKey) -> Swift.Result 11 | public static func getPublicKeyHash(publicKey: ZKSyncCrypto.ZKPackedPublicKey) -> Swift.Result 12 | public static func signMessage(privateKey: ZKSyncCrypto.ZKPrivateKey, message: Swift.String) -> Swift.Result 13 | public static func signMessage(privateKey: ZKSyncCrypto.ZKPrivateKey, message: Foundation.Data) -> Swift.Result 14 | public static func rescueHashOrders(message: Foundation.Data) -> ZKSyncCrypto.ZKResqueHash 15 | @objc override dynamic public init() 16 | @objc deinit 17 | } 18 | public class ZKPrimitive { 19 | public init(_ content: Foundation.Data) 20 | convenience public init(_ content: [Swift.UInt8]) 21 | public func data() -> Foundation.Data 22 | public func base64String() -> Swift.String 23 | public func hexEncodedString() -> Swift.String 24 | @objc deinit 25 | } 26 | @_inheritsConvenienceInitializers public class ZKPackedPublicKey : ZKSyncCrypto.ZKPrimitive { 27 | override public init(_ content: Foundation.Data) 28 | @objc deinit 29 | } 30 | @_inheritsConvenienceInitializers public class ZKPrivateKey : ZKSyncCrypto.ZKPrimitive { 31 | public class var bytesLength: Swift.Int { 32 | get 33 | } 34 | override public init(_ content: Foundation.Data) 35 | @objc deinit 36 | } 37 | @_inheritsConvenienceInitializers public class ZKPublicHash : ZKSyncCrypto.ZKPrimitive { 38 | override public init(_ content: Foundation.Data) 39 | @objc deinit 40 | } 41 | @_inheritsConvenienceInitializers public class ZKSignature : ZKSyncCrypto.ZKPrimitive { 42 | override public init(_ content: Foundation.Data) 43 | @objc deinit 44 | } 45 | @_inheritsConvenienceInitializers public class ZKResqueHash : ZKSyncCrypto.ZKPrimitive { 46 | override public init(_ content: Foundation.Data) 47 | @objc deinit 48 | } 49 | public enum ZKSyncCryptoError : Swift.Error { 50 | case musigTooLongError 51 | case seedTooShortError 52 | case unsupportedOperation 53 | public static func == (a: ZKSyncCrypto.ZKSyncCryptoError, b: ZKSyncCrypto.ZKSyncCryptoError) -> Swift.Bool 54 | public func hash(into hasher: inout Swift.Hasher) 55 | public var hashValue: Swift.Int { 56 | get 57 | } 58 | } 59 | public typealias CLibZksPrivateKey = ZKSyncCrypto.ZksPrivateKey 60 | public typealias CLibZksPackedPublicKey = ZKSyncCrypto.ZksPackedPublicKey 61 | public typealias CLibZksPubkeyHash = ZKSyncCrypto.ZksPubkeyHash 62 | public typealias CLibZksSignature = ZKSyncCrypto.ZksSignature 63 | public typealias CLibZksResqueHash = ZKSyncCrypto.ZksResqueHash 64 | extension ZKSyncCrypto.ZKSyncCryptoError : Swift.Equatable {} 65 | extension ZKSyncCrypto.ZKSyncCryptoError : Swift.Hashable {} 66 | -------------------------------------------------------------------------------- /Examples/CocoaPods/ZKSyncExample/ViewControllers/TransactionFeeViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TransactionFeeViewController.swift 3 | // ZKSyncExample 4 | // 5 | // Created by Eugene Belyakov on 07/01/2021. 6 | // Copyright © 2021 CocoaPods. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ZKSync 11 | 12 | class TransactionFeeViewController: UIViewController, WalletConsumer { 13 | 14 | var wallet: Wallet! 15 | 16 | @IBOutlet weak var titleLabel: UILabel! 17 | @IBOutlet weak var gasTxLabel: UILabel! 18 | @IBOutlet weak var gasPriceLabel: UILabel! 19 | @IBOutlet weak var gasFeeLabel: UILabel! 20 | @IBOutlet weak var zkpFeeLabel: UILabel! 21 | @IBOutlet weak var totalFeeLabel: UILabel! 22 | 23 | @IBAction func fastWithdraw(_ sender: Any) { 24 | wallet.provider.transactionFee(for: .fastWithdraw, 25 | address: wallet.address, 26 | tokenIdentifier: Token.ETH.address) { (result) in 27 | self.titleLabel.text = "Fast Withdraw" 28 | self.processResult(result) 29 | } 30 | } 31 | 32 | @IBAction func withdraw(_ sender: Any) { 33 | wallet.provider.transactionFee(for: .withdraw, 34 | address: wallet.address, 35 | tokenIdentifier: Token.ETH.address) { (result) in 36 | self.titleLabel.text = "Withdraw" 37 | self.processResult(result) 38 | } 39 | } 40 | 41 | @IBAction func forcedExit(_ sender: Any) { 42 | wallet.provider.transactionFee(for: .forcedExit, 43 | address: wallet.address, 44 | tokenIdentifier: Token.ETH.address) { (result) in 45 | self.titleLabel.text = "Forced Exit" 46 | self.processResult(result) 47 | } 48 | } 49 | 50 | @IBAction func changePubKey(_ sender: Any) { 51 | wallet.provider.transactionFee(for: .legacyChangePubKey, 52 | address: wallet.address, 53 | tokenIdentifier: Token.ETH.address) { (result) in 54 | self.titleLabel.text = "Change Pub Key" 55 | self.processResult(result) 56 | } 57 | } 58 | 59 | @IBAction func changePubKeyOnchainAuth(_ sender: Any) { 60 | wallet.provider.transactionFee(for: .fastWithdraw, 61 | address: wallet.address, 62 | tokenIdentifier: Token.ETH.address) { (result) in 63 | self.titleLabel.text = "Change Pub Key Onchain Auth" 64 | self.processResult(result) 65 | } 66 | } 67 | 68 | @IBAction func transfer(_ sender: Any) { 69 | wallet.provider.transactionFee(for: .transfer, 70 | address: "0x4F6071Dbd5818473EEEF6CE563e66bf22618d8c0".lowercased(), 71 | tokenIdentifier: Token.ETH.address) { (result) in 72 | self.titleLabel.text = "Transfer" 73 | self.processResult(result) 74 | } 75 | } 76 | 77 | func processResult(_ result: ZKSyncResult) { 78 | switch result { 79 | case .success(let feeDetails): 80 | gasTxLabel.text = feeDetails.gasTxAmount 81 | gasPriceLabel.text = feeDetails.gasPriceWei 82 | gasFeeLabel.text = feeDetails.gasFee 83 | zkpFeeLabel.text = feeDetails.zkpFee 84 | totalFeeLabel.text = feeDetails.totalFee 85 | default: 86 | break 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/arm64.swiftinterface-e: -------------------------------------------------------------------------------- 1 | // swift-interface-format-version: 1.0 2 | // swift-compiler-version: Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) 3 | // swift-module-flags: -target arm64-apple-ios13.1-simulator -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name ZKSyncCrypto 4 | import Foundation 5 | import Swift 6 | @_exported import ZKSyncCrypto 7 | import _Concurrency 8 | @objc @_inheritsConvenienceInitializers public class ZKSyncCrypto : ObjectiveC.NSObject { 9 | public static func generatePrivateKey(seed: Foundation.Data) -> Swift.Result 10 | public static func getPublicKey(privateKey: ZKSyncCrypto.ZKPrivateKey) -> Swift.Result 11 | public static func getPublicKeyHash(publicKey: ZKSyncCrypto.ZKPackedPublicKey) -> Swift.Result 12 | public static func signMessage(privateKey: ZKSyncCrypto.ZKPrivateKey, message: Swift.String) -> Swift.Result 13 | public static func signMessage(privateKey: ZKSyncCrypto.ZKPrivateKey, message: Foundation.Data) -> Swift.Result 14 | public static func rescueHashOrders(message: Foundation.Data) -> ZKSyncCrypto.ZKResqueHash 15 | @objc override dynamic public init() 16 | @objc deinit 17 | } 18 | public class ZKPrimitive { 19 | public init(_ content: Foundation.Data) 20 | convenience public init(_ content: [Swift.UInt8]) 21 | public func data() -> Foundation.Data 22 | public func base64String() -> Swift.String 23 | public func hexEncodedString() -> Swift.String 24 | @objc deinit 25 | } 26 | @_inheritsConvenienceInitializers public class ZKPackedPublicKey : ZKSyncCrypto.ZKPrimitive { 27 | override public init(_ content: Foundation.Data) 28 | @objc deinit 29 | } 30 | @_inheritsConvenienceInitializers public class ZKPrivateKey : ZKSyncCrypto.ZKPrimitive { 31 | public class var bytesLength: Swift.Int { 32 | get 33 | } 34 | override public init(_ content: Foundation.Data) 35 | @objc deinit 36 | } 37 | @_inheritsConvenienceInitializers public class ZKPublicHash : ZKSyncCrypto.ZKPrimitive { 38 | override public init(_ content: Foundation.Data) 39 | @objc deinit 40 | } 41 | @_inheritsConvenienceInitializers public class ZKSignature : ZKSyncCrypto.ZKPrimitive { 42 | override public init(_ content: Foundation.Data) 43 | @objc deinit 44 | } 45 | @_inheritsConvenienceInitializers public class ZKResqueHash : ZKSyncCrypto.ZKPrimitive { 46 | override public init(_ content: Foundation.Data) 47 | @objc deinit 48 | } 49 | public enum ZKSyncCryptoError : Swift.Error { 50 | case musigTooLongError 51 | case seedTooShortError 52 | case unsupportedOperation 53 | public static func == (a: ZKSyncCrypto.ZKSyncCryptoError, b: ZKSyncCrypto.ZKSyncCryptoError) -> Swift.Bool 54 | public func hash(into hasher: inout Swift.Hasher) 55 | public var hashValue: Swift.Int { 56 | get 57 | } 58 | } 59 | public typealias CLibZksPrivateKey = ZKSyncCrypto.ZksPrivateKey 60 | public typealias CLibZksPackedPublicKey = ZKSyncCrypto.ZksPackedPublicKey 61 | public typealias CLibZksPubkeyHash = ZKSyncCrypto.ZksPubkeyHash 62 | public typealias CLibZksSignature = ZKSyncCrypto.ZksSignature 63 | public typealias CLibZksResqueHash = ZKSyncCrypto.ZksResqueHash 64 | extension ZKSyncCrypto.ZKSyncCryptoError : Swift.Equatable {} 65 | extension ZKSyncCrypto.ZKSyncCryptoError : Swift.Hashable {} 66 | -------------------------------------------------------------------------------- /Dependencies/ZKSyncCrypto.xcframework/ios-arm64_x86_64-simulator/ZKSyncCrypto.framework/Modules/ZKSyncCrypto.swiftmodule/x86_64.swiftinterface-e: -------------------------------------------------------------------------------- 1 | // swift-interface-format-version: 1.0 2 | // swift-compiler-version: Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30) 3 | // swift-module-flags: -target x86_64-apple-ios13.1-simulator -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name ZKSyncCrypto 4 | import Foundation 5 | import Swift 6 | @_exported import ZKSyncCrypto 7 | import _Concurrency 8 | @objc @_inheritsConvenienceInitializers public class ZKSyncCrypto : ObjectiveC.NSObject { 9 | public static func generatePrivateKey(seed: Foundation.Data) -> Swift.Result 10 | public static func getPublicKey(privateKey: ZKSyncCrypto.ZKPrivateKey) -> Swift.Result 11 | public static func getPublicKeyHash(publicKey: ZKSyncCrypto.ZKPackedPublicKey) -> Swift.Result 12 | public static func signMessage(privateKey: ZKSyncCrypto.ZKPrivateKey, message: Swift.String) -> Swift.Result 13 | public static func signMessage(privateKey: ZKSyncCrypto.ZKPrivateKey, message: Foundation.Data) -> Swift.Result 14 | public static func rescueHashOrders(message: Foundation.Data) -> ZKSyncCrypto.ZKResqueHash 15 | @objc override dynamic public init() 16 | @objc deinit 17 | } 18 | public class ZKPrimitive { 19 | public init(_ content: Foundation.Data) 20 | convenience public init(_ content: [Swift.UInt8]) 21 | public func data() -> Foundation.Data 22 | public func base64String() -> Swift.String 23 | public func hexEncodedString() -> Swift.String 24 | @objc deinit 25 | } 26 | @_inheritsConvenienceInitializers public class ZKPackedPublicKey : ZKSyncCrypto.ZKPrimitive { 27 | override public init(_ content: Foundation.Data) 28 | @objc deinit 29 | } 30 | @_inheritsConvenienceInitializers public class ZKPrivateKey : ZKSyncCrypto.ZKPrimitive { 31 | public class var bytesLength: Swift.Int { 32 | get 33 | } 34 | override public init(_ content: Foundation.Data) 35 | @objc deinit 36 | } 37 | @_inheritsConvenienceInitializers public class ZKPublicHash : ZKSyncCrypto.ZKPrimitive { 38 | override public init(_ content: Foundation.Data) 39 | @objc deinit 40 | } 41 | @_inheritsConvenienceInitializers public class ZKSignature : ZKSyncCrypto.ZKPrimitive { 42 | override public init(_ content: Foundation.Data) 43 | @objc deinit 44 | } 45 | @_inheritsConvenienceInitializers public class ZKResqueHash : ZKSyncCrypto.ZKPrimitive { 46 | override public init(_ content: Foundation.Data) 47 | @objc deinit 48 | } 49 | public enum ZKSyncCryptoError : Swift.Error { 50 | case musigTooLongError 51 | case seedTooShortError 52 | case unsupportedOperation 53 | public static func == (a: ZKSyncCrypto.ZKSyncCryptoError, b: ZKSyncCrypto.ZKSyncCryptoError) -> Swift.Bool 54 | public func hash(into hasher: inout Swift.Hasher) 55 | public var hashValue: Swift.Int { 56 | get 57 | } 58 | } 59 | public typealias CLibZksPrivateKey = ZKSyncCrypto.ZksPrivateKey 60 | public typealias CLibZksPackedPublicKey = ZKSyncCrypto.ZksPackedPublicKey 61 | public typealias CLibZksPubkeyHash = ZKSyncCrypto.ZksPubkeyHash 62 | public typealias CLibZksSignature = ZKSyncCrypto.ZksSignature 63 | public typealias CLibZksResqueHash = ZKSyncCrypto.ZksResqueHash 64 | extension ZKSyncCrypto.ZKSyncCryptoError : Swift.Equatable {} 65 | extension ZKSyncCrypto.ZKSyncCryptoError : Swift.Hashable {} 66 | --------------------------------------------------------------------------------