Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Build generated
build/
dist/
DerivedData
.idea/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ extension AddressBundle {

extension AddressBundle {

func account(forAddressIndex: Int, password: String?) async throws -> Account {

func account(forAddressIndex: Int, network: Network, password: String?) async throws -> Account {
// 1. Sanity check
guard canSign == true else { throw WalletError.viewOnly }
guard forAddressIndex < self.addresses.count else { throw WalletError.outOfBounds }
Expand All @@ -105,10 +104,10 @@ extension AddressBundle {
case .keystorePassword:
let bip39 = try await KeystoreV3.load(name: id.uuidString, password: password)
guard let seed = try bip39.seed() else { throw WalletError.seedError }
let wallet = try Wallet<PrivateKeyEth1>(seed: seed)
let wallet = try Wallet<PrivateKeyEth1>(seed: seed, network: network).derive(network, index: UInt32(forAddressIndex))
let account = try Account(privateKey: wallet.privateKey, wallet: id.uuidString, derivationpath: "123") // FIXME: derivationpath
assert(account.addresss.address == addresses[forAddressIndex].addressString)
assertionFailure()
let search = addresses[forAddressIndex].addressString
guard account.address.address == search else { throw WalletError.addressNotFound(search) }
return account
case .viewOnly:
throw WalletError.viewOnly
Expand Down
22 changes: 11 additions & 11 deletions Shared (App and Extension)/UserSettings/UserSettings+Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ extension UserSettings: SafariWalletCoreDelegate {
}

func account(address: String, password: String?) async throws -> Account {
throw WalletError.notImplemented
// guard let bundles = self.addressBundles else { throw WalletError.addressNotFound(address) }
//
// for bundle in bundles {
// for (index, bundleAddress) in bundle.addresses.enumerated() {
// if address == bundleAddress.addressString {
// return try await bundle.account(forAddressIndex: index, password: password)
// }
// }
// }
// throw WalletError.addressNotFound(address)
let bundles = try await AddressBundle.loadAddressBundles(network: .ethereum)

for bundle in bundles {
for (index, bundleAddress) in bundle.addresses.enumerated() {
if address == bundleAddress.addressString {
return try await bundle.account(forAddressIndex: index, network: network, password: password)
}
}
}

throw WalletError.addressNotFound(address)
}

func currentNetwork() -> Network {
Expand Down
3 changes: 3 additions & 0 deletions Shared (App)/Shared (Extension)/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protocol NativeMessageParams: Codable {
enum NativeMessageMethod: String, Decodable {
case eth_getAccounts
case eth_getBalance
case sign
case helloFren
}

Expand All @@ -47,6 +48,8 @@ extension NativeMessage {
params = try container.decode(eth_getAccountsMessageParams.self, forKey: .params)
case .eth_getBalance:
params = try container.decode(eth_getBalanceMessageParams.self, forKey: .params)
case .sign:
params = try container.decode(signMessageParams.self, forKey: .params)
case .helloFren:
params = try container.decode(helloFrenMessageParams.self, forKey: .params)
}
Expand Down
44 changes: 44 additions & 0 deletions Shared (App)/Shared (Extension)/Messages/signMessageParams.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// eth_getBalanceMessageParams.swift
// Wallet
//
// Created by Jamie Rumbelow on 15/01/2022.
//

import Foundation
import SafariWalletCore
import MEWwalletKit

enum SignMethod: String, Codable {
case eth_sign = "eth_sign"
case personal_sign = "personal_sign"
case eth_signTypedData_v3 = "eth_signTypedData_v3"
case eth_signTypedData_v4 = "eth_signTypedData_v4"
}

struct signMessageParams: NativeMessageParams {
let method: SignMethod
let address: Address
let data: String

func execute(with userSettings: UserSettings) async throws -> Any {
let providerAPI = ProviderAPI(delegate: userSettings)
return try await providerAPI.parseMessage(
method: method.rawValue,
params: [self.address.address, self.data]
)
}

private enum CodingKeys: CodingKey {
case method
case address
case data
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
method = try container.decode(SignMethod.self, forKey: .method)
address = try container.decode(Address.self, forKey: .address)
data = try container.decode(String.self, forKey: .data)
}
}
2 changes: 1 addition & 1 deletion Shared (App)/Shared (Extension)/Resources/background.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading