Skip to content

Commit

Permalink
removed C code. Switched to dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych committed May 20, 2021
1 parent 47cbd24 commit 1aa2bb9
Show file tree
Hide file tree
Showing 15 changed files with 14 additions and 2,133 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ playground.xcworkspace
# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
Packages/
Package.pins
Package.resolved
*.xcodeproj
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
Expand Down
4 changes: 3 additions & 1 deletion Bip39.swift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Bip39.swift'
s.version = '0.1.0'
s.version = '0.1.1'
s.summary = 'Cross-platform BIP39 mnemonic implementation for Swift.'

s.description = <<-DESC
Expand All @@ -23,6 +23,8 @@ Cross-platform BIP39 mnemonic implementation for Swift. Supports all Apple platf
s.module_name = 'Bip39'

s.source_files = 'Sources/Bip39/**/*.swift'

s.dependency 'UncommonCrypto', '~> 0.1.0'

s.test_spec 'Tests' do |test_spec|
test_spec.platforms = {:ios => '9.0', :osx => '10.10', :tvos => '9.0'}
Expand Down
19 changes: 4 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,15 @@ var package = Package(
name: "Bip39",
targets: ["Bip39"]),
],
dependencies: [],
dependencies: [
.package(url: "https://github.com/tesseract-one/UncommonCrypto.swift.git", from: "0.1.0")
],
targets: [
.target(
name: "Bip39",
dependencies: []),
dependencies: ["UncommonCrypto"]),
.testTarget(
name: "Bip39Tests",
dependencies: ["Bip39"]),
]
)

#if !canImport(CommonCrypto)
package.targets.append(
.target(
name: "CBip39Crypto",
dependencies: [],
cSettings: [
.define("SHA2_UNROLL_TRANSFORM")
]
)
)
package.targets.first(where: { $0.name == "Bip39" })!.dependencies.append("CBip39Crypto")
#endif
5 changes: 3 additions & 2 deletions Sources/Bip39/Mnemonic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import UncommonCrypto

public struct Mnemonic: Equatable, Hashable {
public enum Error: Swift.Error {
Expand Down Expand Up @@ -43,7 +44,7 @@ public struct Mnemonic: Equatable, Hashable {
public func seed(password: String = "", wordlist: Wordlist = .english) -> [UInt8] {
let mnemonic = Array(self.mnemonic(wordlist: wordlist).joined(separator: " ").utf8)
let salt = Array(("mnemonic" + password).utf8)
return try! PBKDF2.sha512(password: mnemonic, salt: salt)
return try! PBKDF2.derive(type: .sha512, password: mnemonic, salt: salt)
}

// Check is mnemonic phrase valid
Expand Down Expand Up @@ -123,7 +124,7 @@ public struct Mnemonic: Equatable, Hashable {
}

let size = entropy.count / 4 // Calculate checksum size.
let hash = SHA256.hash(entropy)
let hash = SHA2.hash(type: .sha256, bytes: entropy)
return (hash[0] >> (8 - size), size)
}
}
65 changes: 0 additions & 65 deletions Sources/Bip39/PBKDF2.swift

This file was deleted.

36 changes: 0 additions & 36 deletions Sources/Bip39/SHA256.swift

This file was deleted.

56 changes: 0 additions & 56 deletions Sources/Bip39/SecureRandom.swift

This file was deleted.

Loading

0 comments on commit 1aa2bb9

Please sign in to comment.