{"id":13453449,"url":"https://github.com/ProChain/SwiftyEOS","last_synced_at":"2025-03-24T01:31:30.225Z","repository":{"id":105870763,"uuid":"130690639","full_name":"ProChain/SwiftyEOS","owner":"ProChain","description":"SwiftyEOS is an open-source framework for interacting with EOS, written in Swift. Can be used on iOS and macOS.","archived":false,"fork":false,"pushed_at":"2019-04-18T08:35:09.000Z","size":307,"stargazers_count":93,"open_issues_count":15,"forks_count":23,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-01-24T03:41:42.280Z","etag":null,"topics":["blockchain","cryptocurrency","eos","eos-ios","eos-objective-c","eos-sdk","eos-swift","swift"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ProChain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-04-23T12:06:58.000Z","updated_at":"2024-01-24T03:41:42.281Z","dependencies_parsed_at":"2023-04-22T13:04:17.254Z","dependency_job_id":null,"html_url":"https://github.com/ProChain/SwiftyEOS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProChain%2FSwiftyEOS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProChain%2FSwiftyEOS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProChain%2FSwiftyEOS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ProChain%2FSwiftyEOS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ProChain","download_url":"https://codeload.github.com/ProChain/SwiftyEOS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245194232,"owners_count":20575726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","cryptocurrency","eos","eos-ios","eos-objective-c","eos-sdk","eos-swift","swift"],"created_at":"2024-07-31T08:00:40.186Z","updated_at":"2025-03-24T01:31:29.042Z","avatar_url":"https://github.com/ProChain.png","language":"C","funding_links":[],"categories":["Language Support","Developers"],"sub_categories":["Swift","Libraries and Frameworks"],"readme":"# SwiftyEOS\n\n[![Build Status](https://travis-ci.org/ProChain/SwiftyEOS.svg?branch=master)](https://travis-ci.org/ProChain/SwiftyEOS)\n\nSwiftyEOS is an open-source framework for interacting with [EOS](https://github.com/EOSIO/eos), written in Swift.\n\n## Features\n\n- EOS key pairs generation\n- Private key import \n- Signature hash\n- Basic RPC API(chain/history) query client\n- Transaction(EOS token transfer)\n- Helper class for handling offline wallet on iOS\n- Encrypt/decrypt importing private key on iOS\n\n## How to use it\n\n1. Copy the `Libraries` and `Sources` folders into your project, without `main.swift`.\n2. Delete `Sources/Utils/iOS` if not targeted to iOS platform.\n3. Add `Libraries/include` into Header Search Path.\n4. Set `Libraries/include/Bridging-Header.h` as Objective-C Bridging Header. If you've got your own bridging header , copy all the `import` content in that file and paste into your own one.\n5. Compile and pray.\n\n## Key Pairs Generation\n\nSwiftyEOS now support secp256k1 key pairs.\n\n\u003e There are bugs around secp256r1 key pairs generation but I cannot figure out why. Unit tests created from `cleos create key --r1` wouldn't pass. You may not consider secp256r1 as an option since the `cleos wallet` command cannot import those keys, either.\n\n### Generate a random key pair:\n\n```swift\nlet (pk, pub) = generateRandomKeyPair(enclave: .Secp256k1)\n```\n\nEasy, right?\n\n```swift\nprint(\"private key: \\(pk!.wif())\")\nprint(\"public key : \\(pub!.wif())\")\n\n// private key: PVT_K1_5HxrYTdZX89zodtJhTzCk87MfNZAkiBRfFvSX8kacYjtwaDpTkL\n// public key : PUB_K1_4yDYdmcVcXxAxeNsUWRG7x9FKQE4HbJZdzgZFv1AYxk6oSVcLd\n```\n\nThe `PVT_K1_` and the `PUB_K1_` prefixes are the parts of standard key presentations. But old styles are also supported in EOS system and SwiftyEOS:\n\n```swift\nprint(\"private key: \\(pk!.rawPrivateKey())\")\nprint(\"public key : \\(pub!.rawPublicKey())\")\n\n// private key: 5HxrYTdZX89zodtJhTzCk87MfNZAkiBRfFvSX8kacYjtwaDpTkL\n// public key : EOS4yDYdmcVcXxAxeNsUWRG7x9FKQE4HbJZdzgZFv1AYxk6oSVcLd\n```\n\n### Import existing key:\n\n```swift\nlet importedPk = try PrivateKey(keyString: \"5HxrYTdZX89zodtJhTzCk87MfNZAkiBRfFvSX8kacYjtwaDpTkL\")\nlet importedPub = PublicKey(privateKey: importedPk!)\n```\n\nWith delimiter and prefix:\n\n```swift\nlet importedPk = try PrivateKey(keyString: \"PVT_K1_5HxrYTdZX89zodtJhTzCk87MfNZAkiBRfFvSX8kacYjtwaDpTkL\")\nlet importedPub = PublicKey(privateKey: importedPk!)\n```\n\n## RPC API\n\n```swift\nEOSRPC.sharedInstance.chainInfo { (chainInfo, error) in\n    if error == nil {\n        print(\"Success: \\(chainInfo!)\")\n    } else {\n        print(\"Error: \\(error!.localizedDescription)\")\n    }\n}\n```\n\nCurrently we have some basic rpc endpoints, you can find it at `Sources/SwiftyEOS/Network`\n\n## iOS Key Store\n\nWe have helpers for iOS offline wallet management at `SEWallet.swift`.\n\nWith `SEWallet.swift` you can easily store AES encrypted key info into file system. The default location is app's sandbox Library.\n\n\u003e Multiple wallets management is not supported yet.\n\n### Create new wallet on iOS\n\nIn Objective-C:\n\n```objective-c\n[SEKeystoreService.sharedInstance newAccountWithPasscode:passcode succeed:^(SELocalAccount *account) {\n} failed:^(NSError *error) {\n        \n}];\n```\n\n### Retrieve saved wallet\n\n```objective-c\n[SELocalAccount currentAccount];\n```\n\nIt will return nil if there's no saved wallet.\n\n## Transactions\n\nTransaction behaviors are not **fully** supported yet, but you still can have a try with sample code at `main.swift`.\n\nThe related documents will be provided once the whole function is done. \n\n1. Currency transfer (2018.08.15)\n2. Push general transactions (2018.08.16)\n3. On-device(offline) wallet lock \u0026 unlock on iOS (2018.08.17)\n4. Stake/unstake cpu/net (2018.08.28)\n5. Buy/sell ram (2018.08.28)\n6. Create account (2018.10)\n7. Push transaction with params list (2018.11.05)\n8. Create/import key pairs with mnemonic\n\n### Transfer Currency\n\n```swift\nvar transfer = Transfer()\ntransfer.from = \"agoodaccount\"\ntransfer.to = \"gq3dinztgage\"\ntransfer.quantity = \"1.0000 EOS\"\ntransfer.memo = \"eureka\"\n\nCurrency.transferCurrency(transfer: transfer, code: \"eosio.token\", privateKey: importedPk!, completion: { (result, error) in\n    if error != nil {\n        if error is RPCErrorResponse {\n            print(\"\\((error as! RPCErrorResponse).errorDescription())\")\n        } else {\n            print(\"other error: \\(String(describing: error?.localizedDescription))\")\n        }\n    } else {\n        print(\"done.\")\n    }\n})\n```\n\n### Push General Transactions\n\nIn Swift:\n\n```swift\nlet account = \"raoji\"\nlet asset = \"1.0000 EPRA\"\n\nlet data = \"{\\\"hey\\\": {\\\"account\\\":\\\"\" + account  + \"\\\", \\\"quantity\\\":\\\"\" + asset + \"\\\"}}\"\nlet abi = try! AbiJson(code: \"prabox1\", action: \"withdraw\", json: data)\n\nTransactionUtil.pushTransaction(abi: abi, account: account, privateKey: importedPk!, completion: { (result, error) in\n    if error != nil {\n        if (error! as NSError).code == RPCErrorResponse.ErrorCode {\n            print(\"\\(((error! as NSError).userInfo[RPCErrorResponse.ErrorKey] as! RPCErrorResponse).errorDescription())\")\n        } else {\n            print(\"other error: \\(String(describing: error?.localizedDescription))\")\n        }\n    } else {\n        print(\"Ok. Txid: \\(result!.transactionId)\")\n    }\n})\n```\n\nAnd also in Objective-C:\n\n```objective-c\nAbiJson *your_abi;\n[TransactionUtil pushTransactionWithAbi:your_abi\n                                account:@\"your_account\"\n                               pkString:@\"your_private_key\"\n                             completion:^(TransactionResult *result, NSError *error) {\n        \n}];\n```\n\n### On-device(offline) Wallet Lock \u0026 Unlock on iOS\n\nWe added `lock` and `timedUnlock` functions to `SELocalAccount`.\n\n### Cpu/net/ram operations\n\nThere's a `ResourceUtil.swift` file with `ResourceUtil` class including, within which are several methods:\n\n- `stakeResource`\n- `unstakeResource`\n- `buyRam`\n- `sellRam`\n\nStake resource:\n\n```swift\nResourceUtil.stakeResource(account: \"raoji\", net: 1.0, cpu: 1.0, pkString: \"5HsaHvRCPrjU3yhapB5rLRyuKHuFTsziidA13Uw6WnQTeJAG3t4\", completion: { (result, error) in\n})\n```\n\n### Mnemonic\n\nCreate a new key pair:\n\n```swift\nlet (pk, pub, mn) = generateRandomKeyPair(enclave: .Secp256k1)\n```\n\nImport existing mnemonic:\n\n```swift\nlet (pk, mn) = PrivateKey(enclave: .Secp256k1, mnemonicString: \"your words here\")\n```\n\nAnd we do have iOS helper API with mnemonic for key manangement in `SEWallet.swift`. Creating and importing mnemonic is possible now, with `SEKeystoreService` class(or `SEKeystore` deep level API if you're store it on yourself):\n\n```swift\nSEKeystoreService.sharedInstance.newAccountAndMnemonic(passcode: \"your pass here\", succeed: { (account, mnemonic) in\n\n}) { (error) in\n\n}\n```\n\nWe're using `NSObject` inhereiting class for all top level API, so calling in Objective-C is the same way without providing additional bridging files.\n\nAnd in `SEWallet.swift` file there are helper methods for iOS, too.\n\n## Thanks\n\nInspired by: \n - https://github.com/EOSIO/eos\n - https://github.com/EOSIO/fc\n - https://github.com/bitcoin/bitcoin\n - https://github.com/bitcoin/libbase58\n - https://github.com/OracleChain/chainkit\n - https://github.com/OracleChain/PocketEOS-IOS\n\nBuilt with:\n - https://github.com/kmackay/micro-ecc\n - https://github.com/Flight-School/AnyCodable\n\nContributers:\n - https://github.com/croath\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FProChain%2FSwiftyEOS","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FProChain%2FSwiftyEOS","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FProChain%2FSwiftyEOS/lists"}