From 916c899c9636cdcc3b7925c94c8b0554d75f4112 Mon Sep 17 00:00:00 2001 From: Anh Nguyen <anhnguyen@bitmark.com> Date: Thu, 5 Dec 2024 15:06:17 +0700 Subject: [PATCH] update function to get the recovery phrases on ios --- ios/Runner.xcodeproj/project.pbxproj | 66 ++++++++++- ios/Runner/Info.plist | 4 +- ios/Runner/Runner.entitlements | 12 +- ios/Runner/SystemChannelHandler 2.swift | 144 ------------------------ ios/Runner/SystemChannelHandler.swift | 94 ++++++++++++++++ ios/Runner/model/Mnemonic.swift | 128 +++++++++++++++++++++ ios/Runner/model/Seed.swift | 97 +++------------- ios/Runner/model/WordList.swift | 5 + 8 files changed, 315 insertions(+), 235 deletions(-) delete mode 100644 ios/Runner/SystemChannelHandler 2.swift create mode 100644 ios/Runner/model/Mnemonic.swift create mode 100644 ios/Runner/model/WordList.swift diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 673c65a8d..71b5e9b81 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -8,15 +8,22 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; - 311A34F7898F4222918AC04D /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC4511D74C969E513EB211D8 /* Pods_Runner.framework */; }; 312F145516427F1A4582CB54 /* Pods_RunnerTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0A797A66DE40EFF1F7CF4147 /* Pods_RunnerTests.framework */; }; 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 58B2C4F12CFDBC0900FD14C5 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 58B2C4F02CFDBBF300FD14C5 /* libsqlite3.tbd */; }; + 58B371652D014747005A2188 /* SystemChannelHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B371642D014747005A2188 /* SystemChannelHandler.swift */; }; + 58B371662D014747005A2188 /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B371612D014747005A2188 /* Keychain.swift */; }; + 58B371672D014747005A2188 /* Constant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B371602D014747005A2188 /* Constant.swift */; }; + 58B371682D014747005A2188 /* Seed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B371622D014747005A2188 /* Seed.swift */; }; + 58B3716C2D0150D9005A2188 /* Mnemonic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B3716A2D0150D9005A2188 /* Mnemonic.swift */; }; + 58B3716D2D0150D9005A2188 /* WordList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B3716B2D0150D9005A2188 /* WordList.swift */; }; + 58B3716F2D0153EB005A2188 /* URKit in Frameworks */ = {isa = PBXBuildFile; productRef = 58B3716E2D0153EB005A2188 /* URKit */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; + D7E06ED089DD033803E83AAA /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FC4511D74C969E513EB211D8 /* Pods_Runner.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -59,6 +66,12 @@ 3FE978493BF46AE4D925F1BB /* Pods-Runner.release-production.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release-production.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release-production.xcconfig"; sourceTree = "<group>"; }; 589279912CFFF88E00AB2134 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; }; 58B2C4F02CFDBBF300FD14C5 /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; }; + 58B371602D014747005A2188 /* Constant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constant.swift; sourceTree = "<group>"; }; + 58B371612D014747005A2188 /* Keychain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keychain.swift; sourceTree = "<group>"; }; + 58B371622D014747005A2188 /* Seed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Seed.swift; sourceTree = "<group>"; }; + 58B371642D014747005A2188 /* SystemChannelHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemChannelHandler.swift; sourceTree = "<group>"; }; + 58B3716A2D0150D9005A2188 /* Mnemonic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mnemonic.swift; sourceTree = "<group>"; }; + 58B3716B2D0150D9005A2188 /* WordList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordList.swift; sourceTree = "<group>"; }; 63225193030D5CB7FE6DAD45 /* Pods-RunnerTests.profile-development.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.profile-development.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.profile-development.xcconfig"; sourceTree = "<group>"; }; 6AC1725E1120EFFC8F58222D /* Pods-RunnerTests.release-production.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release-production.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release-production.xcconfig"; sourceTree = "<group>"; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; }; @@ -87,8 +100,9 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 58B3716F2D0153EB005A2188 /* URKit in Frameworks */, 58B2C4F12CFDBC0900FD14C5 /* libsqlite3.tbd in Frameworks */, - 311A34F7898F4222918AC04D /* Pods_Runner.framework in Frameworks */, + D7E06ED089DD033803E83AAA /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -111,6 +125,16 @@ path = RunnerTests; sourceTree = "<group>"; }; + 58B371632D014747005A2188 /* model */ = { + isa = PBXGroup; + children = ( + 58B3716A2D0150D9005A2188 /* Mnemonic.swift */, + 58B3716B2D0150D9005A2188 /* WordList.swift */, + 58B371622D014747005A2188 /* Seed.swift */, + ); + path = model; + sourceTree = "<group>"; + }; 84A508EBE35873B63D6554AF /* Frameworks */ = { isa = PBXGroup; children = ( @@ -156,6 +180,10 @@ 97C146F01CF9000F007C117D /* Runner */ = { isa = PBXGroup; children = ( + 58B371602D014747005A2188 /* Constant.swift */, + 58B371612D014747005A2188 /* Keychain.swift */, + 58B371632D014747005A2188 /* model */, + 58B371642D014747005A2188 /* SystemChannelHandler.swift */, 589279912CFFF88E00AB2134 /* Runner.entitlements */, 97C146FA1CF9000F007C117D /* Main.storyboard */, 97C146FD1CF9000F007C117D /* Assets.xcassets */, @@ -268,6 +296,9 @@ Base, ); mainGroup = 97C146E51CF9000F007C117D; + packageReferences = ( + 58B371692D014CEC005A2188 /* XCRemoteSwiftPackageReference "URKit" */, + ); productRefGroup = 97C146EF1CF9000F007C117D /* Products */; projectDirPath = ""; projectRoot = ""; @@ -358,7 +389,7 @@ 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; alwaysOutOfDate = 1; - buildActionMask = 2147483647; + buildActionMask = 8; files = ( ); inputPaths = ( @@ -366,9 +397,9 @@ name = "Run Script"; outputPaths = ( ); - runOnlyForDeploymentPostprocessing = 0; + runOnlyForDeploymentPostprocessing = 1; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n"; }; B6F5A593638686EE4924B19A /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; @@ -425,7 +456,13 @@ buildActionMask = 2147483647; files = ( 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, + 58B3716C2D0150D9005A2188 /* Mnemonic.swift in Sources */, + 58B3716D2D0150D9005A2188 /* WordList.swift in Sources */, 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, + 58B371652D014747005A2188 /* SystemChannelHandler.swift in Sources */, + 58B371662D014747005A2188 /* Keychain.swift in Sources */, + 58B371672D014747005A2188 /* Constant.swift in Sources */, + 58B371682D014747005A2188 /* Seed.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1414,6 +1451,25 @@ defaultConfigurationName = "Release-production"; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 58B371692D014CEC005A2188 /* XCRemoteSwiftPackageReference "URKit" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/BlockchainCommons/URKit"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 15.0.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 58B3716E2D0153EB005A2188 /* URKit */ = { + isa = XCSwiftPackageProductDependency; + package = 58B371692D014CEC005A2188 /* XCRemoteSwiftPackageReference "URKit" */; + productName = URKit; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 97C146E61CF9000F007C117D /* Project object */; } diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 7ef9b2d2e..5f16968e2 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -31,6 +31,8 @@ <string>$(FLUTTER_BUILD_NUMBER)</string> <key>LSRequiresIPhoneOS</key> <true/> + <key>NSCameraUsageDescription</key> + <string>QR code scanning requires camera access.</string> <key>UIApplicationSupportsIndirectInputEvents</key> <true/> <key>UIBackgroundModes</key> @@ -57,7 +59,5 @@ </array> <key>UIViewControllerBasedStatusBarAppearance</key> <false/> - <key>NSCameraUsageDescription</key> - <string>QR code scanning requires camera access.</string> </dict> </plist> diff --git a/ios/Runner/Runner.entitlements b/ios/Runner/Runner.entitlements index dec9fd5c1..d7c8601d5 100644 --- a/ios/Runner/Runner.entitlements +++ b/ios/Runner/Runner.entitlements @@ -4,10 +4,16 @@ <dict> <key>com.apple.developer.associated-domains</key> <array> + <string>webcredentials:feralfile.com</string> + <string>webcredentials:accounts.feralfile.com</string> <string>webcredentials:accounts.dev.feralfile.com</string> - <string>feralfile-app.test-app.link</string> - <string>applinks:feralfile-app-alternate.app.link</string> - <string>feralfile-app-alternate.test-app.link</string> + </array> + <key>com.apple.security.application-groups</key> + <array/> + <key>keychain-access-groups</key> + <array> + <string>$(AppIdentifierPrefix)com.bitmark.autonomywallet.keychain</string> + <string>$(AppIdentifierPrefix)com.bitmark.autonomy-wallet.inhouse.keychain</string> </array> </dict> </plist> diff --git a/ios/Runner/SystemChannelHandler 2.swift b/ios/Runner/SystemChannelHandler 2.swift deleted file mode 100644 index 495948363..000000000 --- a/ios/Runner/SystemChannelHandler 2.swift +++ /dev/null @@ -1,144 +0,0 @@ -// -// SPDX-License-Identifier: BSD-2-Clause-Patent -// Copyright © 2022 Bitmark. All rights reserved. -// Use of this source code is governed by the BSD-2-Clause Plus Patent License -// that can be found in the LICENSE file. -// - -import Foundation -import Flutter -import Combine - -class SystemChannelHandler: NSObject { - - static let shared = SystemChannelHandler() - private var cancelBag = Set<AnyCancellable>() - - func exportMnemonicForAllPersonaUUIDs(call: FlutterMethodCall, result: @escaping FlutterResult) { - do { - // Fetch all mnemonics mapped to persona UUIDs - let mnemonicMap = try exportMnemonicForAllPersonaUUIDs() - - // Convert the result into a format Flutter can handle (e.g., a dictionary of String keys and array of strings) - var resultMap: [String: Any] = [:] - for (uuid, mnemonicWords) in mnemonicMap { - resultMap[uuid] = mnemonicWords - } - - // Send the result back to Flutter - result(resultMap) - } catch { - // Handle any errors that occur and send the error message back to Flutter - result(FlutterError(code: "EXPORT_MNEMONIC_ERROR", - message: "Failed to export mnemonics: \(error.localizedDescription)", - details: nil)) - } - } - -// func removeKeychainItems(call: FlutterMethodCall, result: @escaping FlutterResult) { -// let args = call.arguments as! [String: Any] -// let account = args["account"] as? String -// let service = args["service"] as? String -// let secClass = args["secClass"] as! CFTypeRef -// removeKeychainItems(account: account, service: service, secClass: secClass) -// result(nil) -// } - -// private func removeKeychainItems(account: String? = nil, service: String? = nil, secClass: CFTypeRef = kSecClassGenericPassword) { -// var query: [String: Any] = [ -// kSecClass as String: secClass, -// kSecReturnData as String: kCFBooleanTrue, -// kSecReturnAttributes as String : kCFBooleanTrue, -// ] -// -// if let account = account { -// query[kSecAttrAccount as String] = account -// } -// -// if let service = service { -// query[kSecAttrService as String] = service -// } -// -// let status = SecItemDelete(query as CFDictionary) -// -// if status == errSecSuccess { -// logger.info("Keychain item(s) removed successfully.") -// } else if status == errSecItemNotFound { -// logger.info("Keychain item(s) not found.") -// } else { -// if let error: String = SecCopyErrorMessageString(status, nil) as String? { -// logger.error(error) -// } -// -// logger.error("Error removing keychain item(s): \(status)") -// } -// } - - func exportMnemonicForAllPersonaUUIDs() throws -> [String: [String]] { - // define map: key is uuid, value is list from passphrase at index 0, the next are mnenmonic words - var mnemonicMap = [String: [String]]() - - - // querry all keychain items - let query: NSDictionary = [ - kSecClass: kSecClassGenericPassword, - kSecAttrSynchronizable: kCFBooleanTrue, - kSecReturnData: kCFBooleanTrue, - kSecAttrAccessible as String: kSecAttrAccessibleAfterFirstUnlock, - kSecReturnAttributes as String : kCFBooleanTrue, - kSecMatchLimit as String: kSecMatchLimitAll, - kSecAttrAccessGroup as String: Constant.keychainGroup, - ] - - var dataTypeRef: AnyObject? - let status = withUnsafeMutablePointer(to: &dataTypeRef) { - SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0)) - } - guard status == noErr else { - throw LibAukError.other(reason: "Keychain query failed with status: \(status)") - } - - guard let array = dataTypeRef as? Array<Dictionary<String, Any>> else { - return [] - } - - for item in array { - // filter seed keychain by check if have `seed` in key: personna.uuid_seed - if let key = item[kSecAttrAccount as String] as? String, key.contains("seed") { - - // get uuid - let personaUUIDString = key - .replacingOccurrences(of: "persona.", with: "") - .replacingOccurrences(of: "_seed", with: "") - - if let data = item[kSecValueData as String] as? Data, - let dataString = String(data: data, encoding: .utf8), - let seed = try? Seed(urString: dataString) { - var mnemonicWords = [seed.passphrase ?? ""] - mnemonicWords.append(contentsOf: Keys.mnemonic(seed.data)) - mnemonicMap[personaUUIDString] = mnemonicWords - } - } - } - - - return mnenmonicMap - } - - private func buildKeyAttr(prefix: String?, key: String) -> String { - if let prefix = prefix { - return "\(prefix)_\(key)" - } else { - return key - } - } -} - - -class Key { - static func mnemonic(_ entropy: Data) -> BIP39Mnemonic? { - let bip39entropy = BIP39Mnemonic.Entropy(entropy) - - return try? BIP39Mnemonic(entropy: bip39entropy) - } -} diff --git a/ios/Runner/SystemChannelHandler.swift b/ios/Runner/SystemChannelHandler.swift index e69de29bb..456861bcb 100644 --- a/ios/Runner/SystemChannelHandler.swift +++ b/ios/Runner/SystemChannelHandler.swift @@ -0,0 +1,94 @@ +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// Copyright © 2022 Bitmark. All rights reserved. +// Use of this source code is governed by the BSD-2-Clause Plus Patent License +// that can be found in the LICENSE file. +// + +import Foundation +import Flutter +import Combine + +class SystemChannelHandler: NSObject { + + static let shared = SystemChannelHandler() + private var cancelBag = Set<AnyCancellable>() + + func exportMnemonicForAllPersonaUUIDs(call: FlutterMethodCall, result: @escaping FlutterResult) { + do { + // Fetch all mnemonics mapped to persona UUIDs + let mnemonicMap = try exportMnemonicForAllPersonaUUIDs() + + // Convert the result into a format Flutter can handle (e.g., a dictionary of String keys and array of strings) + var resultMap: [String: Any] = [:] + for (uuid, mnemonicWords) in mnemonicMap { + resultMap[uuid] = mnemonicWords + } + + // Send the result back to Flutter + result(resultMap) + } catch { + // Handle any errors that occur and send the error message back to Flutter + result(FlutterError(code: "EXPORT_MNEMONIC_ERROR", + message: "Failed to export mnemonics: \(error.localizedDescription)", + details: nil)) + } + } + + + func exportMnemonicForAllPersonaUUIDs() throws -> [String: [String]] { + // define map: key is uuid, value is list from passphrase at index 0, the next are mnenmonic words + var mnemonicMap = [String: [String]]() + + // querry all keychain items + let query: NSDictionary = [ + kSecClass: kSecClassGenericPassword, + kSecAttrSynchronizable: kCFBooleanTrue, + kSecReturnData: kCFBooleanTrue, + kSecAttrAccessible as String: kSecAttrAccessibleAfterFirstUnlock, + kSecReturnAttributes as String : kCFBooleanTrue, + kSecMatchLimit as String: kSecMatchLimitAll, + kSecAttrAccessGroup as String: Constant.keychainGroup, + ] + + var dataTypeRef: AnyObject? + let status = withUnsafeMutablePointer(to: &dataTypeRef) { + SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0)) + } + guard status == noErr else { + throw LibAukError.other(reason: "Keychain query failed with status: \(status)") + } + + guard let array = dataTypeRef as? Array<Dictionary<String, Any>> else { + return [:] + } + + for item in array { + // filter seed keychain by check if have `seed` in key: personna.uuid_seed + if let key = item[kSecAttrAccount as String] as? String, key.contains("seed") { + + // get uuid + let personaUUIDString = key + .replacingOccurrences(of: "persona.", with: "") + .replacingOccurrences(of: "_seed", with: "") + + if let data = item[kSecValueData as String] as? Data, + let dataString = String(data: data, encoding: .utf8), + let seed = try? Seed(urString: dataString), + let mnemonicWords = try? Mnemonic.toMnemonic([UInt8](seed.data)){ + mnemonicMap[personaUUIDString] = mnemonicWords + } + } + } + + return mnemonicMap + } + + private func buildKeyAttr(prefix: String?, key: String) -> String { + if let prefix = prefix { + return "\(prefix)_\(key)" + } else { + return key + } + } +} diff --git a/ios/Runner/model/Mnemonic.swift b/ios/Runner/model/Mnemonic.swift new file mode 100644 index 000000000..4a7aa78d0 --- /dev/null +++ b/ios/Runner/model/Mnemonic.swift @@ -0,0 +1,128 @@ +// +// Mnemonic.swift +// +// See BIP39 specification for more info: +// https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki +// +// Created by Liu Pengpeng on 2019/10/10. +// + +import Foundation +import CryptoKit + +public class Mnemonic { + public enum Error: Swift.Error { + case invalidMnemonic + case invalidEntropy + } + + public let phrase: [String] + let passphrase: String + + public init(strength: Int = 128, wordlist: [String] = Wordlists.english) { + precondition(strength % 32 == 0, "Invalid entropy") + + // 1.Random Bytes + var bytes = [UInt8](repeating: 0, count: strength / 8) + _ = SecRandomCopyBytes(kSecRandomDefault, bytes.count, &bytes) + + // 2.Entropy -> Mnemonic + let entropyBits = String(bytes.flatMap { ("00000000" + String($0, radix:2)).suffix(8) }) + let checksumBits = Mnemonic.deriveChecksumBits(bytes) + let bits = entropyBits + checksumBits + + var phrase = [String]() + for i in 0..<(bits.count / 11) { + let wi = Int(bits[bits.index(bits.startIndex, offsetBy: i * 11)..<bits.index(bits.startIndex, offsetBy: (i + 1) * 11)], radix: 2)! + phrase.append(String(wordlist[wi])) + } + + self.phrase = phrase + self.passphrase = "" + } + + public init(phrase: [String], passphrase: String = "") throws { + if (!Mnemonic.isValid(phrase: phrase)) { + throw Error.invalidMnemonic + } + self.phrase = phrase + self.passphrase = passphrase + } + + public init(entropy: [UInt8], wordlist: [String] = Wordlists.english) throws { + self.phrase = try Mnemonic.toMnemonic(entropy, wordlist: wordlist) + self.passphrase = "" + } + + // Entropy -> Mnemonic + public static func toMnemonic(_ bytes: [UInt8], wordlist: [String] = Wordlists.english) throws -> [String] { + let entropyBits = String(bytes.flatMap { ("00000000" + String($0, radix:2)).suffix(8) }) + let checksumBits = Mnemonic.deriveChecksumBits(bytes) + let bits = entropyBits + checksumBits + + var phrase = [String]() + for i in 0..<(bits.count / 11) { + let wi = Int(bits[bits.index(bits.startIndex, offsetBy: i * 11)..<bits.index(bits.startIndex, offsetBy: (i + 1) * 11)], radix: 2)! + phrase.append(String(wordlist[wi])) + } + return phrase + } + + // Mnemonic -> Entropy + public static func toEntropy(_ phrase: [String], wordlist: [String] = Wordlists.english) throws -> [UInt8] { + let bits = phrase.map { (word) -> String in + let index = wordlist.firstIndex(of: word)! + var str = String(index, radix:2) + while str.count < 11 { + str = "0" + str + } + return str + }.joined(separator: "") + + let dividerIndex = Int(Double(bits.count / 33).rounded(.down) * 32) + let entropyBits = String(bits.prefix(dividerIndex)) + let checksumBits = String(bits.suffix(bits.count - dividerIndex)) + + let regex = try! NSRegularExpression(pattern: "[01]{1,8}", options: .caseInsensitive) + let entropyBytes = regex.matches(in: entropyBits, options: [], range: NSRange(location: 0, length: entropyBits.count)).map { + UInt8(strtoul(String(entropyBits[Range($0.range, in: entropyBits)!]), nil, 2)) + } + if (checksumBits != Mnemonic.deriveChecksumBits(entropyBytes)) { + throw Error.invalidMnemonic + } + return entropyBytes + } + + public static func isValid(phrase: [String], wordlist: [String] = Wordlists.english) -> Bool { + var bits = "" + for word in phrase { + guard let i = wordlist.firstIndex(of: word) else { return false } + bits += ("00000000000" + String(i, radix: 2)).suffix(11) + } + + let dividerIndex = bits.count / 33 * 32 + let entropyBits = String(bits.prefix(dividerIndex)) + let checksumBits = String(bits.suffix(bits.count - dividerIndex)) + + let regex = try! NSRegularExpression(pattern: "[01]{1,8}", options: .caseInsensitive) + let entropyBytes = regex.matches(in: entropyBits, options: [], range: NSRange(location: 0, length: entropyBits.count)).map { + UInt8(strtoul(String(entropyBits[Range($0.range, in: entropyBits)!]), nil, 2)) + } + return checksumBits == deriveChecksumBits(entropyBytes) + } + + public static func deriveChecksumBits(_ bytes: [UInt8]) -> String { + let ENT = bytes.count * 8; + let CS = ENT / 32 + + let hash = SHA256.hash(data: bytes) + let hashbits = String(hash.flatMap { ("00000000" + String($0, radix:2)).suffix(8) }) + return String(hashbits.prefix(CS)) + } +} + +extension Mnemonic: Equatable { + public static func == (lhs: Mnemonic, rhs: Mnemonic) -> Bool { + return lhs.phrase == rhs.phrase && lhs.passphrase == rhs.passphrase + } +} \ No newline at end of file diff --git a/ios/Runner/model/Seed.swift b/ios/Runner/model/Seed.swift index 46f718ccc..c4ce89a6a 100644 --- a/ios/Runner/model/Seed.swift +++ b/ios/Runner/model/Seed.swift @@ -21,99 +21,34 @@ public class Seed: Codable { self.passphrase = passphrase } - func cbor(nameLimit: Int? = nil, noteLimit: Int? = nil) -> CBOR { - var a: [OrderedMap.Entry] = [ - .init(key: 1, value: CBOR.data(data)) - ] - - if let creationDate = creationDate { - a.append(.init(key: 2, value: CBOR.date(creationDate))) - } - - if !name.isEmpty { - a.append(.init(key: 3, value: CBOR.utf8String(name))) + convenience init(urString: String) throws { + guard let ur = try? UR(urString: urString) else { + throw LibAukError.other(reason: "ur:crypto-seed: Invalid UR data.") } - if let passphrase = passphrase, !passphrase.isEmpty { - a.append(.init(key: 4, value: CBOR.utf8String(passphrase))) + guard let cbor = try? CBOR(ur.cbor) else { + throw LibAukError.other(reason: "ur:crypto-seed: Invalid CBOR data.") } - return CBOR.orderedMap(OrderedMap(a)) - } - - public var ur: UR { - try! UR(type: "crypto-seed", cbor: cbor()) - } - - public var urString: String { - UREncoder.encode(ur) - } - - convenience init(urString: String) throws { - let ur = try URDecoder.decode(urString) - try self.init(ur: ur) - } - - convenience init(ur: UR) throws { - guard ur.type == "crypto-seed" else { - throw LibAukError.other(reason: "Unexpected UR type.") - } - try self.init(cborData: ur.cbor) - } - - convenience init(cborData: Data) throws { - guard let cbor = try? CBOR(cborData) else { - throw LibAukError.other(reason: "ur:crypto-seed: Invalid CBOR.") - } - try self.init(cbor: cbor) - } - - convenience init(cbor: CBOR) throws { - guard case let CBOR.orderedMap(orderedMap) = cbor else { + guard case .map(let map) = cbor else { throw LibAukError.other(reason: "ur:crypto-seed: CBOR doesn't contain a map.") } - - let iterator = orderedMap.makeIterator() + + // Loop through the map to find the first bytes data var seedData: Data? - var creationDate: Date? = nil - var name: String = "" - var passphrase: String = "" - - while let element = iterator.next() { - let (indexElement, valueElement) = element - - guard case let CBOR.unsignedInt(index) = indexElement else { - throw LibAukError.other(reason: "ur:crypto-seed: CBOR contains invalid keys.") - } - - switch index { - case 1: - guard case let CBOR.data(data) = valueElement else { - throw LibAukError.other(reason: "ur:crypto-seed: CBOR doesn't contain data field.") - } + for (_, value) in map { + if case .bytes(let data) = value { seedData = data - case 2: - guard case let CBOR.date(d) = valueElement else { - throw LibAukError.other(reason: "ur:crypto-seed: CreationDate field doesn't contain a date.") - } - creationDate = d - case 3: - guard case let CBOR.utf8String(s) = valueElement else { - throw LibAukError.other(reason: "ur:crypto-seed: Name field doesn't contain a string.") - } - name = s - case 4: - guard case let CBOR.utf8String(s) = valueElement else { - throw LibAukError.other(reason: "ur:crypto-seed: Passphrase field doesn't contain a string.") - } - passphrase = s - default: - throw LibAukError.other(reason: "ur:crypto-seed: CBOR contains invalid keys.") + break } } + // Verify we found valid seed data + guard let finalSeedData = seedData else { + throw LibAukError.other(reason: "ur:crypto-seed: Missing or invalid seed data.") + } - self.init(data: seedData!, name: name, creationDate: creationDate, passphrase: passphrase) + self.init(data: finalSeedData, name: "") } } diff --git a/ios/Runner/model/WordList.swift b/ios/Runner/model/WordList.swift new file mode 100644 index 000000000..7eb6e7b19 --- /dev/null +++ b/ios/Runner/model/WordList.swift @@ -0,0 +1,5 @@ +import Foundation + +public struct Wordlists { + public static let english = ["abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract", "absurd", "abuse", "access", "accident", "account", "accuse", "achieve", "acid", "acoustic", "acquire", "across", "act", "action", "actor", "actress", "actual", "adapt", "add", "addict", "address", "adjust", "admit", "adult", "advance", "advice", "aerobic", "affair", "afford", "afraid", "again", "age", "agent", "agree", "ahead", "aim", "air", "airport", "aisle", "alarm", "album", "alcohol", "alert", "alien", "all", "alley", "allow", "almost", "alone", "alpha", "already", "also", "alter", "always", "amateur", "amazing", "among", "amount", "amused", "analyst", "anchor", "ancient", "anger", "angle", "angry", "animal", "ankle", "announce", "annual", "another", "answer", "antenna", "antique", "anxiety", "any", "apart", "apology", "appear", "apple", "approve", "april", "arch", "arctic", "area", "arena", "argue", "arm", "armed", "armor", "army", "around", "arrange", "arrest", "arrive", "arrow", "art", "artefact", "artist", "artwork", "ask", "aspect", "assault", "asset", "assist", "assume", "asthma", "athlete", "atom", "attack", "attend", "attitude", "attract", "auction", "audit", "august", "aunt", "author", "auto", "autumn", "average", "avocado", "avoid", "awake", "aware", "away", "awesome", "awful", "awkward", "axis", "baby", "bachelor", "bacon", "badge", "bag", "balance", "balcony", "ball", "bamboo", "banana", "banner", "bar", "barely", "bargain", "barrel", "base", "basic", "basket", "battle", "beach", "bean", "beauty", "because", "become", "beef", "before", "begin", "behave", "behind", "believe", "below", "belt", "bench", "benefit", "best", "betray", "better", "between", "beyond", "bicycle", "bid", "bike", "bind", "biology", "bird", "birth", "bitter", "black", "blade", "blame", "blanket", "blast", "bleak", "bless", "blind", "blood", "blossom", "blouse", "blue", "blur", "blush", "board", "boat", "body", "boil", "bomb", "bone", "bonus", "book", "boost", "border", "boring", "borrow", "boss", "bottom", "bounce", "box", "boy", "bracket", "brain", "brand", "brass", "brave", "bread", "breeze", "brick", "bridge", "brief", "bright", "bring", "brisk", "broccoli", "broken", "bronze", "broom", "brother", "brown", "brush", "bubble", "buddy", "budget", "buffalo", "build", "bulb", "bulk", "bullet", "bundle", "bunker", "burden", "burger", "burst", "bus", "business", "busy", "butter", "buyer", "buzz", "cabbage", "cabin", "cable", "cactus", "cage", "cake", "call", "calm", "camera", "camp", "can", "canal", "cancel", "candy", "cannon", "canoe", "canvas", "canyon", "capable", "capital", "captain", "car", "carbon", "card", "cargo", "carpet", "carry", "cart", "case", "cash", "casino", "castle", "casual", "cat", "catalog", "catch", "category", "cattle", "caught", "cause", "caution", "cave", "ceiling", "celery", "cement", "census", "century", "cereal", "certain", "chair", "chalk", "champion", "change", "chaos", "chapter", "charge", "chase", "chat", "cheap", "check", "cheese", "chef", "cherry", "chest", "chicken", "chief", "child", "chimney", "choice", "choose", "chronic", "chuckle", "chunk", "churn", "cigar", "cinnamon", "circle", "citizen", "city", "civil", "claim", "clap", "clarify", "claw", "clay", "clean", "clerk", "clever", "click", "client", "cliff", "climb", "clinic", "clip", "clock", "clog", "close", "cloth", "cloud", "clown", "club", "clump", "cluster", "clutch", "coach", "coast", "coconut", "code", "coffee", "coil", "coin", "collect", "color", "column", "combine", "come", "comfort", "comic", "common", "company", "concert", "conduct", "confirm", "congress", "connect", "consider", "control", "convince", "cook", "cool", "copper", "copy", "coral", "core", "corn", "correct", "cost", "cotton", "couch", "country", "couple", "course", "cousin", "cover", "coyote", "crack", "cradle", "craft", "cram", "crane", "crash", "crater", "crawl", "crazy", "cream", "credit", "creek", "crew", "cricket", "crime", "crisp", "critic", "crop", "cross", "crouch", "crowd", "crucial", "cruel", "cruise", "crumble", "crunch", "crush", "cry", "crystal", "cube", "culture", "cup", "cupboard", "curious", "current", "curtain", "curve", "cushion", "custom", "cute", "cycle", "dad", "damage", "damp", "dance", "danger", "daring", "dash", "daughter", "dawn", "day", "deal", "debate", "debris", "decade", "december", "decide", "decline", "decorate", "decrease", "deer", "defense", "define", "defy", "degree", "delay", "deliver", "demand", "demise", "denial", "dentist", "deny", "depart", "depend", "deposit", "depth", "deputy", "derive", "describe", "desert", "design", "desk", "despair", "destroy", "detail", "detect", "develop", "device", "devote", "diagram", "dial", "diamond", "diary", "dice", "diesel", "diet", "differ", "digital", "dignity", "dilemma", "dinner", "dinosaur", "direct", "dirt", "disagree", "discover", "disease", "dish", "dismiss", "disorder", "display", "distance", "divert", "divide", "divorce", "dizzy", "doctor", "document", "dog", "doll", "dolphin", "domain", "donate", "donkey", "donor", "door", "dose", "double", "dove", "draft", "dragon", "drama", "drastic", "draw", "dream", "dress", "drift", "drill", "drink", "drip", "drive", "drop", "drum", "dry", "duck", "dumb", "dune", "during", "dust", "dutch", "duty", "dwarf", "dynamic", "eager", "eagle", "early", "earn", "earth", "easily", "east", "easy", "echo", "ecology", "economy", "edge", "edit", "educate", "effort", "egg", "eight", "either", "elbow", "elder", "electric", "elegant", "element", "elephant", "elevator", "elite", "else", "embark", "embody", "embrace", "emerge", "emotion", "employ", "empower", "empty", "enable", "enact", "end", "endless", "endorse", "enemy", "energy", "enforce", "engage", "engine", "enhance", "enjoy", "enlist", "enough", "enrich", "enroll", "ensure", "enter", "entire", "entry", "envelope", "episode", "equal", "equip", "era", "erase", "erode", "erosion", "error", "erupt", "escape", "essay", "essence", "estate", "eternal", "ethics", "evidence", "evil", "evoke", "evolve", "exact", "example", "excess", "exchange", "excite", "exclude", "excuse", "execute", "exercise", "exhaust", "exhibit", "exile", "exist", "exit", "exotic", "expand", "expect", "expire", "explain", "expose", "express", "extend", "extra", "eye", "eyebrow", "fabric", "face", "faculty", "fade", "faint", "faith", "fall", "false", "fame", "family", "famous", "fan", "fancy", "fantasy", "farm", "fashion", "fat", "fatal", "father", "fatigue", "fault", "favorite", "feature", "february", "federal", "fee", "feed", "feel", "female", "fence", "festival", "fetch", "fever", "few", "fiber", "fiction", "field", "figure", "file", "film", "filter", "final", "find", "fine", "finger", "finish", "fire", "firm", "first", "fiscal", "fish", "fit", "fitness", "fix", "flag", "flame", "flash", "flat", "flavor", "flee", "flight", "flip", "float", "flock", "floor", "flower", "fluid", "flush", "fly", "foam", "focus", "fog", "foil", "fold", "follow", "food", "foot", "force", "forest", "forget", "fork", "fortune", "forum", "forward", "fossil", "foster", "found", "fox", "fragile", "frame", "frequent", "fresh", "friend", "fringe", "frog", "front", "frost", "frown", "frozen", "fruit", "fuel", "fun", "funny", "furnace", "fury", "future", "gadget", "gain", "galaxy", "gallery", "game", "gap", "garage", "garbage", "garden", "garlic", "garment", "gas", "gasp", "gate", "gather", "gauge", "gaze", "general", "genius", "genre", "gentle", "genuine", "gesture", "ghost", "giant", "gift", "giggle", "ginger", "giraffe", "girl", "give", "glad", "glance", "glare", "glass", "glide", "glimpse", "globe", "gloom", "glory", "glove", "glow", "glue", "goat", "goddess", "gold", "good", "goose", "gorilla", "gospel", "gossip", "govern", "gown", "grab", "grace", "grain", "grant", "grape", "grass", "gravity", "great", "green", "grid", "grief", "grit", "grocery", "group", "grow", "grunt", "guard", "guess", "guide", "guilt", "guitar", "gun", "gym", "habit", "hair", "half", "hammer", "hamster", "hand", "happy", "harbor", "hard", "harsh", "harvest", "hat", "have", "hawk", "hazard", "head", "health", "heart", "heavy", "hedgehog", "height", "hello", "helmet", "help", "hen", "hero", "hidden", "high", "hill", "hint", "hip", "hire", "history", "hobby", "hockey", "hold", "hole", "holiday", "hollow", "home", "honey", "hood", "hope", "horn", "horror", "horse", "hospital", "host", "hotel", "hour", "hover", "hub", "huge", "human", "humble", "humor", "hundred", "hungry", "hunt", "hurdle", "hurry", "hurt", "husband", "hybrid", "ice", "icon", "idea", "identify", "idle", "ignore", "ill", "illegal", "illness", "image", "imitate", "immense", "immune", "impact", "impose", "improve", "impulse", "inch", "include", "income", "increase", "index", "indicate", "indoor", "industry", "infant", "inflict", "inform", "inhale", "inherit", "initial", "inject", "injury", "inmate", "inner", "innocent", "input", "inquiry", "insane", "insect", "inside", "inspire", "install", "intact", "interest", "into", "invest", "invite", "involve", "iron", "island", "isolate", "issue", "item", "ivory", "jacket", "jaguar", "jar", "jazz", "jealous", "jeans", "jelly", "jewel", "job", "join", "joke", "journey", "joy", "judge", "juice", "jump", "jungle", "junior", "junk", "just", "kangaroo", "keen", "keep", "ketchup", "key", "kick", "kid", "kidney", "kind", "kingdom", "kiss", "kit", "kitchen", "kite", "kitten", "kiwi", "knee", "knife", "knock", "know", "lab", "label", "labor", "ladder", "lady", "lake", "lamp", "language", "laptop", "large", "later", "latin", "laugh", "laundry", "lava", "law", "lawn", "lawsuit", "layer", "lazy", "leader", "leaf", "learn", "leave", "lecture", "left", "leg", "legal", "legend", "leisure", "lemon", "lend", "length", "lens", "leopard", "lesson", "letter", "level", "liar", "liberty", "library", "license", "life", "lift", "light", "like", "limb", "limit", "link", "lion", "liquid", "list", "little", "live", "lizard", "load", "loan", "lobster", "local", "lock", "logic", "lonely", "long", "loop", "lottery", "loud", "lounge", "love", "loyal", "lucky", "luggage", "lumber", "lunar", "lunch", "luxury", "lyrics", "machine", "mad", "magic", "magnet", "maid", "mail", "main", "major", "make", "mammal", "man", "manage", "mandate", "mango", "mansion", "manual", "maple", "marble", "march", "margin", "marine", "market", "marriage", "mask", "mass", "master", "match", "material", "math", "matrix", "matter", "maximum", "maze", "meadow", "mean", "measure", "meat", "mechanic", "medal", "media", "melody", "melt", "member", "memory", "mention", "menu", "mercy", "merge", "merit", "merry", "mesh", "message", "metal", "method", "middle", "midnight", "milk", "million", "mimic", "mind", "minimum", "minor", "minute", "miracle", "mirror", "misery", "miss", "mistake", "mix", "mixed", "mixture", "mobile", "model", "modify", "mom", "moment", "monitor", "monkey", "monster", "month", "moon", "moral", "more", "morning", "mosquito", "mother", "motion", "motor", "mountain", "mouse", "move", "movie", "much", "muffin", "mule", "multiply", "muscle", "museum", "mushroom", "music", "must", "mutual", "myself", "mystery", "myth", "naive", "name", "napkin", "narrow", "nasty", "nation", "nature", "near", "neck", "need", "negative", "neglect", "neither", "nephew", "nerve", "nest", "net", "network", "neutral", "never", "news", "next", "nice", "night", "noble", "noise", "nominee", "noodle", "normal", "north", "nose", "notable", "note", "nothing", "notice", "novel", "now", "nuclear", "number", "nurse", "nut", "oak", "obey", "object", "oblige", "obscure", "observe", "obtain", "obvious", "occur", "ocean", "october", "odor", "off", "offer", "office", "often", "oil", "okay", "old", "olive", "olympic", "omit", "once", "one", "onion", "online", "only", "open", "opera", "opinion", "oppose", "option", "orange", "orbit", "orchard", "order", "ordinary", "organ", "orient", "original", "orphan", "ostrich", "other", "outdoor", "outer", "output", "outside", "oval", "oven", "over", "own", "owner", "oxygen", "oyster", "ozone", "pact", "paddle", "page", "pair", "palace", "palm", "panda", "panel", "panic", "panther", "paper", "parade", "parent", "park", "parrot", "party", "pass", "patch", "path", "patient", "patrol", "pattern", "pause", "pave", "payment", "peace", "peanut", "pear", "peasant", "pelican", "pen", "penalty", "pencil", "people", "pepper", "perfect", "permit", "person", "pet", "phone", "photo", "phrase", "physical", "piano", "picnic", "picture", "piece", "pig", "pigeon", "pill", "pilot", "pink", "pioneer", "pipe", "pistol", "pitch", "pizza", "place", "planet", "plastic", "plate", "play", "please", "pledge", "pluck", "plug", "plunge", "poem", "poet", "point", "polar", "pole", "police", "pond", "pony", "pool", "popular", "portion", "position", "possible", "post", "potato", "pottery", "poverty", "powder", "power", "practice", "praise", "predict", "prefer", "prepare", "present", "pretty", "prevent", "price", "pride", "primary", "print", "priority", "prison", "private", "prize", "problem", "process", "produce", "profit", "program", "project", "promote", "proof", "property", "prosper", "protect", "proud", "provide", "public", "pudding", "pull", "pulp", "pulse", "pumpkin", "punch", "pupil", "puppy", "purchase", "purity", "purpose", "purse", "push", "put", "puzzle", "pyramid", "quality", "quantum", "quarter", "question", "quick", "quit", "quiz", "quote", "rabbit", "raccoon", "race", "rack", "radar", "radio", "rail", "rain", "raise", "rally", "ramp", "ranch", "random", "range", "rapid", "rare", "rate", "rather", "raven", "raw", "razor", "ready", "real", "reason", "rebel", "rebuild", "recall", "receive", "recipe", "record", "recycle", "reduce", "reflect", "reform", "refuse", "region", "regret", "regular", "reject", "relax", "release", "relief", "rely", "remain", "remember", "remind", "remove", "render", "renew", "rent", "reopen", "repair", "repeat", "replace", "report", "require", "rescue", "resemble", "resist", "resource", "response", "result", "retire", "retreat", "return", "reunion", "reveal", "review", "reward", "rhythm", "rib", "ribbon", "rice", "rich", "ride", "ridge", "rifle", "right", "rigid", "ring", "riot", "ripple", "risk", "ritual", "rival", "river", "road", "roast", "robot", "robust", "rocket", "romance", "roof", "rookie", "room", "rose", "rotate", "rough", "round", "route", "royal", "rubber", "rude", "rug", "rule", "run", "runway", "rural", "sad", "saddle", "sadness", "safe", "sail", "salad", "salmon", "salon", "salt", "salute", "same", "sample", "sand", "satisfy", "satoshi", "sauce", "sausage", "save", "say", "scale", "scan", "scare", "scatter", "scene", "scheme", "school", "science", "scissors", "scorpion", "scout", "scrap", "screen", "script", "scrub", "sea", "search", "season", "seat", "second", "secret", "section", "security", "seed", "seek", "segment", "select", "sell", "seminar", "senior", "sense", "sentence", "series", "service", "session", "settle", "setup", "seven", "shadow", "shaft", "shallow", "share", "shed", "shell", "sheriff", "shield", "shift", "shine", "ship", "shiver", "shock", "shoe", "shoot", "shop", "short", "shoulder", "shove", "shrimp", "shrug", "shuffle", "shy", "sibling", "sick", "side", "siege", "sight", "sign", "silent", "silk", "silly", "silver", "similar", "simple", "since", "sing", "siren", "sister", "situate", "six", "size", "skate", "sketch", "ski", "skill", "skin", "skirt", "skull", "slab", "slam", "sleep", "slender", "slice", "slide", "slight", "slim", "slogan", "slot", "slow", "slush", "small", "smart", "smile", "smoke", "smooth", "snack", "snake", "snap", "sniff", "snow", "soap", "soccer", "social", "sock", "soda", "soft", "solar", "soldier", "solid", "solution", "solve", "someone", "song", "soon", "sorry", "sort", "soul", "sound", "soup", "source", "south", "space", "spare", "spatial", "spawn", "speak", "special", "speed", "spell", "spend", "sphere", "spice", "spider", "spike", "spin", "spirit", "split", "spoil", "sponsor", "spoon", "sport", "spot", "spray", "spread", "spring", "spy", "square", "squeeze", "squirrel", "stable", "stadium", "staff", "stage", "stairs", "stamp", "stand", "start", "state", "stay", "steak", "steel", "stem", "step", "stereo", "stick", "still", "sting", "stock", "stomach", "stone", "stool", "story", "stove", "strategy", "street", "strike", "strong", "struggle", "student", "stuff", "stumble", "style", "subject", "submit", "subway", "success", "such", "sudden", "suffer", "sugar", "suggest", "suit", "summer", "sun", "sunny", "sunset", "super", "supply", "supreme", "sure", "surface", "surge", "surprise", "surround", "survey", "suspect", "sustain", "swallow", "swamp", "swap", "swarm", "swear", "sweet", "swift", "swim", "swing", "switch", "sword", "symbol", "symptom", "syrup", "system", "table", "tackle", "tag", "tail", "talent", "talk", "tank", "tape", "target", "task", "taste", "tattoo", "taxi", "teach", "team", "tell", "ten", "tenant", "tennis", "tent", "term", "test", "text", "thank", "that", "theme", "then", "theory", "there", "they", "thing", "this", "thought", "three", "thrive", "throw", "thumb", "thunder", "ticket", "tide", "tiger", "tilt", "timber", "time", "tiny", "tip", "tired", "tissue", "title", "toast", "tobacco", "today", "toddler", "toe", "together", "toilet", "token", "tomato", "tomorrow", "tone", "tongue", "tonight", "tool", "tooth", "top", "topic", "topple", "torch", "tornado", "tortoise", "toss", "total", "tourist", "toward", "tower", "town", "toy", "track", "trade", "traffic", "tragic", "train", "transfer", "trap", "trash", "travel", "tray", "treat", "tree", "trend", "trial", "tribe", "trick", "trigger", "trim", "trip", "trophy", "trouble", "truck", "true", "truly", "trumpet", "trust", "truth", "try", "tube", "tuition", "tumble", "tuna", "tunnel", "turkey", "turn", "turtle", "twelve", "twenty", "twice", "twin", "twist", "two", "type", "typical", "ugly", "umbrella", "unable", "unaware", "uncle", "uncover", "under", "undo", "unfair", "unfold", "unhappy", "uniform", "unique", "unit", "universe", "unknown", "unlock", "until", "unusual", "unveil", "update", "upgrade", "uphold", "upon", "upper", "upset", "urban", "urge", "usage", "use", "used", "useful", "useless", "usual", "utility", "vacant", "vacuum", "vague", "valid", "valley", "valve", "van", "vanish", "vapor", "various", "vast", "vault", "vehicle", "velvet", "vendor", "venture", "venue", "verb", "verify", "version", "very", "vessel", "veteran", "viable", "vibrant", "vicious", "victory", "video", "view", "village", "vintage", "violin", "virtual", "virus", "visa", "visit", "visual", "vital", "vivid", "vocal", "voice", "void", "volcano", "volume", "vote", "voyage", "wage", "wagon", "wait", "walk", "wall", "walnut", "want", "warfare", "warm", "warrior", "wash", "wasp", "waste", "water", "wave", "way", "wealth", "weapon", "wear", "weasel", "weather", "web", "wedding", "weekend", "weird", "welcome", "west", "wet", "whale", "what", "wheat", "wheel", "when", "where", "whip", "whisper", "wide", "width", "wife", "wild", "will", "win", "window", "wine", "wing", "wink", "winner", "winter", "wire", "wisdom", "wise", "wish", "witness", "wolf", "woman", "wonder", "wood", "wool", "word", "work", "world", "worry", "worth", "wrap", "wreck", "wrestle", "wrist", "write", "wrong", "yard", "year", "yellow", "you", "young", "youth", "zebra", "zero", "zone", "zoo"] +}