Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
GhenadieVP committed Aug 15, 2023
1 parent 2ec9000 commit 1247230
Show file tree
Hide file tree
Showing 43 changed files with 102 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ extension FactorSourcesClient: DependencyKey {
public static let liveValue = Self.live()
}

internal func signingFactors(
func signingFactors(
for entities: some Collection<EntityPotentiallyVirtual>,
from allFactorSources: IdentifiedArrayOf<FactorSource>,
signingPurpose: SigningPurpose
Expand Down
6 changes: 3 additions & 3 deletions Sources/Clients/FaucetClient/FaucetClient+Live.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,16 @@ private extension UserDefaultsClient {

// MARK: - EpochForWhenLastUsedByAccountAddress
// internal for tests
internal struct EpochForWhenLastUsedByAccountAddress: Codable, Hashable, Sendable {
struct EpochForWhenLastUsedByAccountAddress: Codable, Hashable, Sendable {
struct EpochForAccount: Codable, Sendable, Hashable, Identifiable {
typealias ID = AccountAddress
var id: ID { accountAddress }
let accountAddress: AccountAddress
var epoch: Epoch
}

internal var epochForAccounts: IdentifiedArrayOf<EpochForAccount>
internal init(epochForAccounts: IdentifiedArrayOf<EpochForAccount> = .init()) {
var epochForAccounts: IdentifiedArrayOf<EpochForAccount>
init(epochForAccounts: IdentifiedArrayOf<EpochForAccount> = .init()) {
self.epochForAccounts = epochForAccounts
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ extension GatewayAPIClient: TestDependencyKey {
.init(
getNetworkName: { _ in .init("Nebunet") },
getEpoch: { .init(rawValue: 123) },
getEntityDetails: unimplemented("\(Self.self).getEntityDetails"),
getEntityMetadata: unimplemented("\(Self.self).getEntityMetadata"),
getEntityFungiblesPage: unimplemented("\(Self.self).getEntityFungiblesPage"),
getEntityFungibleResourceVaultsPage: unimplemented("\(Self.self).getEntityFungibleResourceVaultsPage"),
getEntityNonFungiblesPage: unimplemented("\(Self.self).getEntityNonFungiblesPage"),
getEntityNonFungibleResourceVaultsPage: unimplemented("\(Self.self).getEntityNonFungibleResourceVaultsPage"),
getEntityNonFungibleIdsPage: unimplemented("\(Self.self).getEntityNonFungibleIdsPage"),
getNonFungibleData: unimplemented("\(Self.self).getNonFungibleData"),
getEntityDetails: unimplemented("\(self).getEntityDetails"),
getEntityMetadata: unimplemented("\(self).getEntityMetadata"),
getEntityFungiblesPage: unimplemented("\(self).getEntityFungiblesPage"),
getEntityFungibleResourceVaultsPage: unimplemented("\(self).getEntityFungibleResourceVaultsPage"),
getEntityNonFungiblesPage: unimplemented("\(self).getEntityNonFungiblesPage"),
getEntityNonFungibleResourceVaultsPage: unimplemented("\(self).getEntityNonFungibleResourceVaultsPage"),
getEntityNonFungibleIdsPage: unimplemented("\(self).getEntityNonFungibleIdsPage"),
getNonFungibleData: unimplemented("\(self).getNonFungibleData"),
submitTransaction: { _ in
.init(duplicate: submittedTXIsDoubleSpend)
},
Expand All @@ -51,7 +51,7 @@ extension GatewayAPIClient: TestDependencyKey {
errorMessage: nil
)
},
transactionPreview: unimplemented("\(Self.self).transactionPreview")
transactionPreview: unimplemented("\(self).transactionPreview")
)
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Clients/ProfileStore/ProfileStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,11 @@ extension ProfileStore.ProfileState {
extension ProfileStore {
#if !canImport(UIKit)
/// used by tests
internal static let macOSDeviceNameFallback: DeviceFactorSource.Hint.Name = "macOS"
internal static let macOSDeviceModelFallback: DeviceFactorSource.Hint.Model = "macOS"
static let macOSDeviceNameFallback: DeviceFactorSource.Hint.Name = "macOS"
static let macOSDeviceModelFallback: DeviceFactorSource.Hint.Model = "macOS"
#endif

internal static func deviceDescription(
static func deviceDescription(
name: String,
model: DeviceFactorSource.Hint.Model
) -> NonEmptyString {
Expand Down Expand Up @@ -501,9 +501,9 @@ extension ProfileStore {
case let .success(.some(existing)):
return .persisted(existing)
case .success(.none):
return await .ephemeral(.init(profile: Self.newEphemeralProfile(), loadFailure: nil))
return await .ephemeral(.init(profile: newEphemeralProfile(), loadFailure: nil))
case let .failure(loadFailure):
return await .ephemeral(.init(profile: Self.newEphemeralProfile(), loadFailure: loadFailure))
return await .ephemeral(.init(profile: newEphemeralProfile(), loadFailure: loadFailure))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension P2P.Dapp.Response.WalletInteractionSuccessResponse {
}

/// for tests
internal static func withoutProofOfOwnership(accounts: [P2P.Dapp.Response.WalletAccount]) -> Self {
static func withoutProofOfOwnership(accounts: [P2P.Dapp.Response.WalletAccount]) -> Self {
Self(withoutProofOfOwnership: accounts)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Prelude

extension BIP39 {
internal static func languageFromWords(_ wordsNonChecked: [String]) -> Language? {
static func languageFromWords(_ wordsNonChecked: [String]) -> Language? {
let words = wordsNonChecked.compactMap {
NonEmptyString(rawValue: $0)
}
return BIP39.languageFromWords(words)
}

internal static func languageFromWords(_ words: [NonEmptyString]) -> Language? {
static func languageFromWords(_ words: [NonEmptyString]) -> Language? {
for langauge in Language.allCases {
let wordlist = BIP39.wordList(for: langauge)
if wordlist.containsAllWords(in: words) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Cryptography/Mnemonic/BIP39/BIP39+Checksum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import Prelude

extension BIP39 {
@discardableResult
internal static func validateChecksumOf(
static func validateChecksumOf(
mnemonicWords: [BIP39.Word],
language: BIP39.Language
) throws -> [NonEmptyString] {
try validateChecksumOf(mnemonicWords: mnemonicWords.map(\.word), language: language)
}

@discardableResult
internal static func validateChecksumOf(
static func validateChecksumOf(
mnemonicWords: [NonEmptyString],
language: BIP39.Language
) throws -> [NonEmptyString] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CryptoKit
import Prelude

extension BIP39 {
internal static func mapEntropyToWords(
static func mapEntropyToWords(
entropy: Entropy,
language: Language
) throws -> [NonEmptyString] {
Expand All @@ -19,21 +19,21 @@ extension BIP39 {

let mnemonicWords = wordlist.words(at: indices)

return try Self.validateChecksumOf(
return try validateChecksumOf(
mnemonicWords: mnemonicWords,
language: language
)
}

internal static func mapWordsToEntropyBitArray(
static func mapWordsToEntropyBitArray(
words mnemonicWords: some Collection<BIP39.Word>,
language: Language
) throws -> BitArray {
try mapWordsToEntropyBitArray(words: mnemonicWords.map(\.word), language: language)
}

/// This is not mapping exactly to the entropy because the mnemonic words contains a checksummed word.
internal static func mapWordsToEntropyBitArray(
static func mapWordsToEntropyBitArray(
words mnemonicWords: [NonEmptyString],
language: Language
) throws -> BitArray {
Expand Down
12 changes: 6 additions & 6 deletions Sources/Cryptography/Mnemonic/BIP39/BIP39+WordCount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,29 @@ extension BIP39.WordCount {
// MARK: - Internal

extension BIP39.WordCount {
internal static let checksumBitsPerWord = 3
static let checksumBitsPerWord = 3

internal var byteCount: Int {
var byteCount: Int {
let byteCount = Self.entropyInBitsFrom(wordCount: wordCount) / .bitsPerByte
return byteCount
}

internal static func wordCountFrom(entropyInBits: Int) -> Int {
static func wordCountFrom(entropyInBits: Int) -> Int {
Int(ceil(Double(entropyInBits) / Double(BIP39.WordList.sizeLog2)))
}

internal static func entropyInBitsFrom(wordCount: Int) -> Int {
static func entropyInBitsFrom(wordCount: Int) -> Int {
let ent = wordCount * BIP39.WordList.sizeLog2
let cs = checksumLengthInBits(wordCount: wordCount)
let bits = ent - cs
return bits
}

internal static func checksumLengthInBits(wordCount: Int) -> Int {
static func checksumLengthInBits(wordCount: Int) -> Int {
wordCount / BIP39.WordCount.checksumBitsPerWord
}

internal var checksumLengthInBits: Int {
var checksumLengthInBits: Int {
Self.checksumLengthInBits(wordCount: wordCount)
}
}
12 changes: 6 additions & 6 deletions Sources/Cryptography/Mnemonic/BIP39/BIP39+WordList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extension BIP39 {
}

extension BIP39.WordList {
internal func words(at indices: [Word.Index]) -> [Word] {
func words(at indices: [Word.Index]) -> [Word] {
indices.map { index in
guard let word = self.indexToWord[index] else {
fatalError("Incorrect implementation, should always be able to located word at index. Index was: \(index), language: \(language)")
Expand All @@ -67,7 +67,7 @@ extension BIP39.WordList {
}
}

internal func indices(of words: [NonEmptyString]) -> [Word.Index] {
func indices(of words: [NonEmptyString]) -> [Word.Index] {
words.map { wordString in
guard let index = self.wordToIndex[wordString] else {
fatalError("Incorrect implementation, should always be able to located index of word. Word was: \(wordString), language: \(language)")
Expand All @@ -76,7 +76,7 @@ extension BIP39.WordList {
}
}

internal func bip39Words(from wordStrings: [NonEmptyString]) -> NonEmptyArray<Word>? {
func bip39Words(from wordStrings: [NonEmptyString]) -> NonEmptyArray<Word>? {
guard !wordStrings.isEmpty else { return nil }
var words: [Word] = []
for wordString in wordStrings {
Expand Down Expand Up @@ -157,7 +157,7 @@ extension BIP39.WordList {
)
}

internal func containsAllWords(in words: [NonEmptyString]) -> Bool {
func containsAllWords(in words: [NonEmptyString]) -> Bool {
bip39Words(from: words) != nil
}
}
Expand All @@ -169,8 +169,8 @@ extension NonEmpty<OrderedSet<BIP39.Word>> {
}

extension BIP39.WordList {
internal static let size = 2048
static let size = 2048

/// `2^11 => 2048`
internal static let sizeLog2 = 11
static let sizeLog2 = 11
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension BIP39 {
}

fileprivate static func makeWordList(for language: Language) -> WordList {
let words = Self.words(for: language)
let words = words(for: language)
return try! WordList(words: words, language: language)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Cryptography/SLIP10/Helpers/Base58/Encoding.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

// MARK: - Encoding
internal protocol Encoding {
protocol Encoding {
static var baseAlphabets: String { get }
static var zeroAlphabet: Character { get }
static var base: Int { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import Prelude
// MARK: - HD.ExtendedKey
extension HD {
public struct ExtendedKey<Curve>: Equatable where Curve: SLIP10CurveProtocol {
internal let key: Key
let key: Key

public let derivationPath: HD.Path

public let chainCode: ChainCode
public let fingerprint: Fingerprint

internal init(
init(
derivationPath: HD.Path,
key: Key,
chainCode: ChainCode,
Expand All @@ -27,7 +27,7 @@ extension HD {

// MARK: - HD.ExtendedKey.Key
extension HD.ExtendedKey {
internal enum Key: Equatable {
enum Key: Equatable {
case privateKey(Curve.PrivateKey)
case publicKeyOnly(Curve.PublicKey)

Expand Down Expand Up @@ -84,7 +84,7 @@ extension HD.ExtendedKey {
}

extension HD.ExtendedKey {
internal func keyAsData(forceSelectPublicKey: Bool) -> Data {
func keyAsData(forceSelectPublicKey: Bool) -> Data {
var serializedBytes: Data
switch (forceSelectPublicKey, key) {
case (false, let .privateKey(privateKey)):
Expand All @@ -102,13 +102,13 @@ extension HD.ExtendedKey {
return serializedBytes
}

internal func keyAsScalar(forceSelectPublicKey: Bool) -> BigUInt {
func keyAsScalar(forceSelectPublicKey: Bool) -> BigUInt {
BigUInt(keyAsData(forceSelectPublicKey: forceSelectPublicKey))
}
}

// MARK: - KeyToDerive
internal enum KeyToDerive: Equatable {
enum KeyToDerive: Equatable {
case derivePublicKeyOnly
case derivePrivateKey

Expand All @@ -120,7 +120,7 @@ internal enum KeyToDerive: Equatable {
}
}

internal func serializeByPrependingByteToReachKeyLength(
func serializeByPrependingByteToReachKeyLength(
scalar: BigUInt,
keyLength targetBytecount: Int = 32,
prependingByte byteToPrepend: UInt8 = 0x00
Expand Down Expand Up @@ -200,7 +200,7 @@ extension HD.ExtendedKey {
}

extension HD.ExtendedKey {
internal func selecting(keyToDerive: KeyToDerive) throws -> Self {
func selecting(keyToDerive: KeyToDerive) throws -> Self {
let key: Key = try {
switch keyToDerive {
case .derivePublicKeyOnly:
Expand Down Expand Up @@ -262,7 +262,7 @@ extension HD.ExtendedKey {
}
}

internal func keyAndChainCode<Curve: SLIP10CurveProtocol>(
func keyAndChainCode<Curve: SLIP10CurveProtocol>(
curve: Curve.Type,
hmacKeyData: Data,
s: @autoclosure () throws -> Data,
Expand Down
4 changes: 2 additions & 2 deletions Sources/Cryptography/SLIP10/SLIP10/HD+Root.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension HD.Root {
}

extension HD.Root {
internal func deriveKey<Curve>(
func deriveKey<Curve>(
path: HD.Path.Full,
keyToDerive: KeyToDerive
) throws -> HD.ExtendedKey<Curve> {
Expand All @@ -41,7 +41,7 @@ extension HD.Root {
)
}

internal func deriveKey<Curve>(
func deriveKey<Curve>(
path: HD.Path.Full,
curve: Curve.Type,
keyToDerive: KeyToDerive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ extension HD.Path.Component {

public static func inferredDepth(string: String) throws -> Self {
switch string {
case Self.rootPrivateKey:
case rootPrivateKey:
return .root(onlyPublic: false)
case Self.rootOnlyPublicKey:
case rootOnlyPublicKey:
return .root(onlyPublic: true)
default:
return try .child(HD.Path.Component.Child(
Expand Down
4 changes: 2 additions & 2 deletions Sources/Cryptography/SLIP10/SLIP10/SLIP10CurveProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extension SLIP10CurveProtocol {
Self.isCurve25519
}

public static var curveSeed: String { Self.curve.curveSeed }
public static var curveOrder: BigUInt { Self.curve.curveOrder }
public static var curveSeed: String { curve.curveSeed }
public static var curveOrder: BigUInt { curve.curveOrder }
public var curve: SLIP10.Curve { Self.curve }
}
2 changes: 1 addition & 1 deletion Sources/EngineKit/NetworkID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extension NetworkID {
}

public static func all(but excluded: NetworkID) -> AllCases {
var allBut = Self.allCases
var allBut = allCases
allBut.removeAll(where: { $0 == excluded })
return allBut
}
Expand Down
Loading

0 comments on commit 1247230

Please sign in to comment.