{"id":13732508,"url":"https://github.com/trustwallet/TrustSDK-iOS","last_synced_at":"2025-05-08T07:30:49.837Z","repository":{"id":51255185,"uuid":"132824615","full_name":"trustwallet/TrustSDK-iOS","owner":"trustwallet","description":"No longer maintained. https://community.trustwallet.com/t/trustsdk-is-discontinued/213116","archived":true,"fork":false,"pushed_at":"2021-05-18T23:50:27.000Z","size":9710,"stargazers_count":231,"open_issues_count":0,"forks_count":96,"subscribers_count":45,"default_branch":"master","last_synced_at":"2025-04-17T02:49:33.859Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trustwallet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-09T23:49:46.000Z","updated_at":"2024-10-25T22:10:17.000Z","dependencies_parsed_at":"2022-09-04T22:23:41.028Z","dependency_job_id":null,"html_url":"https://github.com/trustwallet/TrustSDK-iOS","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trustwallet%2FTrustSDK-iOS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trustwallet%2FTrustSDK-iOS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trustwallet%2FTrustSDK-iOS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trustwallet%2FTrustSDK-iOS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trustwallet","download_url":"https://codeload.github.com/trustwallet/TrustSDK-iOS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253020694,"owners_count":21841622,"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":[],"created_at":"2024-08-03T02:02:00.229Z","updated_at":"2025-05-08T07:30:49.087Z","avatar_url":"https://github.com/trustwallet.png","language":"Swift","readme":"# TrustSDK\n\n[![Version](https://img.shields.io/cocoapods/v/TrustSDK.svg?style=flat)](https://cocoapods.org/pods/TrustSDK)\n[![License](https://img.shields.io/cocoapods/l/TrustSDK.svg?style=flat)](https://cocoapods.org/pods/TrustSDK)\n[![Platform](https://img.shields.io/cocoapods/p/TrustSDK.svg?style=flat)](https://cocoapods.org/pods/TrustSDK)\n![TrustSDK CI](https://github.com/trustwallet/TrustSDK-iOS/workflows/TrustSDK%20CI/badge.svg)\n\n## Getting Started\n\nThe TrustSDK lets you sign Ethereum transactions and messages so that you can bulid a native DApp without having to worry about keys or wallets. Follw these instructions to integrate TrustSDK in your native DApp.\n\n## Demo\n\n![Sign Message and Transaction](docs/demo.gif)\n\n\n## Installation\n\nTrustSDK is available through [CocoaPods](https://cocoapods.org). To install it, simply add the following line to your Podfile:\n\n```ruby\npod 'TrustSDK'\n```\n\nRun `pod install`.\n\n## Configuration\n\nFollow the next steps to configure `TrustSDK` in your app.\n\n### Schema Configuration\n\nOpen Xcode an click on your project. Go to the 'Info' tab and expand the 'URL Types' group. Click on the **+** button to add a new scheme. Enter a custom scheme name in **'URL Scemes'**.\n\n![Adding a scheme](docs/scheme.png)\n\n### Initialization\n\nOpen `AppDelegate.swift` file and initialize TrustSDK in`application(_:didFinishLaunchingWithOptions:)` method:\n\n```swift\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -\u003e Bool {\n    TrustSDK.initialize(with: TrustSDK.Configuration(scheme: \"trustexample\"))\n    return true\n}\n```\n\n### Handling Callbacks\n\nLet `TrustSDK` capture deeplink responses by calling TrustSDK in `application(_:open:options:)` method:\n\n```swift\nfunc application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -\u003e Bool {\n  return TrustSDK.application(app, open: url, options: options)\n}\n```\n\n## API\n\nTo use TrustSDK you have to import `TrustSDK` and `TrustWalletCore` modules.\n\n### Sign Transaction\n\nTrustSDK comes with an easy to use generic API to sign transactions. Each blockchain accept a `SigningInput` object and respond with a `SigningOutput` that can be broadcasted directly to the node. Each input and output object is a Swift implementation of wallet-core's [ protobuf messages](https://github.com/trustwallet/wallet-core/tree/master/src/proto). To sign an Ethereum transaction you have the following `SigningInput`:\n\n```swift\nlet input = EthereumSigningInput.with {\n    $0.toAddress = \"0x3D60643Bf82b928602bce34EE426a7d392157b69\"\n    $0.chainID = BigInt(\"1\").serialize()!\n    $0.nonce = BigInt(\"464\").serialize()!\n    $0.gasPrice = BigInt(\"11500000000\").serialize()!\n    $0.gasLimit = BigInt(\"21000\").serialize()!\n    $0.amount = BigInt(\"1000000000000000\").serialize()!\n}\n```\n\n \u003e TrustSDK comes with some handy extensions to handle `Data` and `BigInt` serialization with ease.\n\nOnce you have the input defined, you just have to call the blockchain signer to sign the transaction:\n\n```swift\nTrustSDK.signers.ethereum.sign(input: input) { result in\n  switch result {\n  case .success(let output):\n      // Handle the signing output\n  case .failure(let error):\n      // Handle failres like user rejections\n  }\n}\n```\n\n### Sign Messages\n\nTo request signing message, you have to encode or hash your message in hex-encoded format first, and then call `sign(message:)` from `TrustSDK.signers`, below is an Ethereum example message:\n\n```swift\nlet data = Data(\"Some message\".utf8)\nlet message = Data(\"\\u{19}Ethereum Signed Message:\\n\\(data.count)\".utf8) + data\nlet hash = message.sha3(.keccak256)\nTrustSDK.signers.ethereum.sign(message: hash) { result in\n    switch result {\n    case .success(let signature):\n        // Handle the signature\n    case .failure(let error):\n        // Handle failure\n    }\n}\n```\n\n### Get Addresses\n\nTo get users addresses, you just need to call `getAccounts(for:)` directly from `TrustSDK` and pass an array of `CoinType`:\n\n```swift\nTrustSDK.getAccounts(for: [.ethereum, .bitcoin]) { result in\n    switch result {\n    case .success(let addresses):\n        // Handle the address array\n    case .failure(let error):\n        // Handle failure\n    }\n}\n```\n\n## Wallet Developers\nIf your wallet already uses `TrustWalletCore` and want to integrate with `TrustSDK` you just need to follow the steps below:\n\n\n### Install WalletSDK\n\nAdd the following line to your Podfile:\n\n\n```ruby\npod 'TrustSDK/Wallet'\n```\n\nRun `pod install`.\n\n### Handling TrustSDK Commands\n\nImport `TrustSDK` and implement `WalletSDKRequestHandler.handle(request:callback:)`. Commands must handled asyncronously, once\nfinished, your implementation have to call the `callback` parameter with the command's response.\n\n\n```swift\nclass WalletSDKRequestHandlerImplementation: WalletSDKRequestHandler {\n  func handle(request: WalletSDK.Request, callback: @escaping ((WalletSDK.Response) -\u003e Void)) {\n    switch request.command {\n    case .getAccounts(let coins):\n      // Handle get accoutns command\n      let accounts = ...\n      callback(.accounts(accounts))\n    case .sign(let coin, let input):\n      // Handle sign command\n      let output = ...\n      callback(.sign(coin: coin, output: output))\n    }    \n    // You can respond with a failure response in case of exception\n    callback(.failure(.unknown))\n  }\n}\n```\n\nOn your app initialization method, set the handler implemention `WalletSDK.handler` then let `WalletSDK` handle deeplinks by calling it in `application(_:open:options:)` method:\n\n```swift\nfunc application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -\u003e Bool {\n  return WalletSDK.application(app, open: url, options: options)\n}\n```\n\nIf you have your app already handles deeplinks, or you have to parse `WalletSDK.Request` struct by yourself and dispatch is \nusing `WalletSDK.dispatch(request:)` method.\n\n### Supporting Your Wallet\n\nOnce you have `WalletSDK` configured for your wallet, tell dApp developers to set the`walletApp` attribute in `TrustSDK.Configureation` with your wallet's `scheme` and `installURL`:\n\n```swift\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -\u003e Bool {\n    let wallet = WalletApp(\n      scheme: \"walletscheme\",\n      installURL: URL(string: \"https://apps.apple.com/app/walletapp\")!\n    )\n    TrustSDK.initialize(with: TrustSDK.Configuration(scheme: \"trustexample\", walletApp: wallet))\n    return true\n}\n```\n\n## Example\n\nTrust SDK includes an example project with the above code. To run the example project clone the repo and run pod install from the `Example` directory. Open `TrustSDK.xcworkspace` and run. Make sure that you have Trust Wallet installed on the device or simulator to test the full callback flow.\n\n## Author\n\n* Leone Parise\n* Viktor Radchenko\n\n## License\n\nTrustSDK is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":["Swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrustwallet%2FTrustSDK-iOS","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrustwallet%2FTrustSDK-iOS","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrustwallet%2FTrustSDK-iOS/lists"}