Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix: migrate BIP39Mnemonic to BIP39 #35

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ on:
jobs:
build:

runs-on: macos-12
runs-on: macos-13

steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14.0'
xcode-version: '15.0'
- uses: actions/checkout@v2
- name: Build
run: xcodebuild -scheme LibAuk build -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 13'
Expand Down
22 changes: 10 additions & 12 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
// swift-tools-version:5.5
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "LibAuk",
platforms: [.iOS("15.0")],
platforms: [.iOS("16.0")],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "LibAuk",
targets: ["LibAuk"]),
],
dependencies: [
.package(name: "Web3.swift", url: "https://github.com/bitmark-inc/Web3.swift.git", .branch("master")),
.package(url: "https://github.com/BlockchainCommons/URKit.git", .exact("7.5.0")),
.package(name: "Web3.swift", url: "https://github.com/bitmark-inc/Web3.swift.git", branch: "migrate_secp256"),
.package(url: "https://github.com/BlockchainCommons/URKit.git", from: "14.0.2"),
.package(url: "https://github.com/keefertaylor/Base58Swift.git", from: "2.1.0"),
.package(name: "KukaiCoreSwift", url: "https://github.com/autonomy-system/kukai-core-swift.git", .branch("main")),
.package(name: "TweetNacl", url: "https://github.com/bitmark-inc/tweetnacl-swiftwrap", branch: "master")
.package(name: "KukaiCoreSwift", url: "https://github.com/autonomy-system/kukai-core-swift.git", branch: "migrate_secp256"),
.package(name: "TweetNacl", url: "https://github.com/bitmark-inc/tweetnacl-swiftwrap", branch: "master"),
.package(url: "https://github.com/BlockchainCommons/BCSwiftFoundation.git", branch: "master")
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
Expand All @@ -27,19 +28,16 @@ let package = Package(
.target(
name: "LibAuk",
dependencies: [
.target(name: "LibWally"),
.product(name: "Web3", package: "Web3.swift"),
.product(name: "URKit", package: "URKit"),
.product(name: "KukaiCoreSwift", package: "KukaiCoreSwift"),
.product(name: "Base58Swift", package: "Base58Swift"),
.product(name: "KukaiCoreSwift", package: "KukaiCoreSwift"),
.product(name: "TweetNacl", package: "TweetNacl"),
.product(name: "BCFoundation", package: "BCSwiftFoundation")
]),
.testTarget(
name: "LibAukTests",
dependencies: ["LibAuk"]),
.binaryTarget(
name: "LibWally",
path: "Frameworks/LibWally.xcframework")
dependencies: ["LibAuk"])
],
swiftLanguageVersions: [.v5]
)
12 changes: 6 additions & 6 deletions Sources/LibAuk/LibAuk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation
import Combine
import LibWally
import BCFoundation

public class LibAuk {

Expand All @@ -33,15 +33,15 @@ public class LibAuk {
}

public func calculateEthFirstAddress(words: [String], passphrase: String) -> AnyPublisher<String, Error> {
Future<BIP39Mnemonic, Error> { promise in
Future<BIP39, Error> { promise in
guard let entropy = Keys.entropy(words),
let mnemonic = Keys.mnemonic(entropy) else {
let bip39 = Keys.mnemonic(entropy) else {
promise(.failure(LibAukError.invalidMnemonicError))
return
}
promise(.success(mnemonic))
}.tryMap({ mnemonic in
let ethPrivateKey = try Keys.ethereumPrivateKey(mnemonic: mnemonic, passphrase: passphrase)
promise(.success(bip39))
}.tryMap({ bip39 in
let ethPrivateKey = try Keys.ethereumPrivateKey(bip39: bip39, passphrase: passphrase)
return ethPrivateKey.address.hex(eip55: true)
})
.eraseToAnyPublisher()
Expand Down
11 changes: 7 additions & 4 deletions Sources/LibAuk/Model/Seed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import URKit
import OrderedCollections

public class Seed: Codable {
public let data: Data
Expand All @@ -20,6 +21,7 @@ public class Seed: Codable {
self.creationDate = creationDate
self.passphrase = passphrase
}
/*

func cbor(nameLimit: Int? = nil, noteLimit: Int? = nil) -> CBOR {
var a: [OrderedMap.Entry] = [
Expand Down Expand Up @@ -82,13 +84,13 @@ public class Seed: Codable {
while let element = iterator.next() {
let (indexElement, valueElement) = element

guard case let CBOR.unsignedInt(index) = indexElement else {
guard case let CBOR.unsigned(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 {
guard case let CBOR.bytes(data) = valueElement else {
throw LibAukError.other(reason: "ur:crypto-seed: CBOR doesn't contain data field.")
}
seedData = data
Expand All @@ -98,12 +100,12 @@ public class Seed: Codable {
}
creationDate = d
case 3:
guard case let CBOR.utf8String(s) = valueElement else {
guard case let CBOR.text(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 {
guard case let CBOR.text(s) = valueElement else {
throw LibAukError.other(reason: "ur:crypto-seed: Passphrase field doesn't contain a string.")
}
passphrase = s
Expand All @@ -115,4 +117,5 @@ public class Seed: Codable {

self.init(data: seedData!, name: name, creationDate: creationDate, passphrase: passphrase)
}
*/
}
Loading
Loading