Skip to content
Open
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
35 changes: 26 additions & 9 deletions Sources/HdWalletKit/HDExtendedKeyVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,33 @@ public enum HDExtendedKeyVersion: UInt32, CaseIterable {
case Ltub = 0x019da462
case Mtpv = 0x01b26792
case Mtub = 0x01b26ef6
case vprv = 0x045f18bc
case vpub = 0x045f1cf6
case tpub = 0x043587cf
case tprv = 0x04358394

public init(purpose: Purpose, coinType: ExtendedKeyCoinType, isPrivate: Bool = true) throws {
public init(purpose: Purpose, coinType: ExtendedKeyCoinType, isPrivate: Bool = true, isTestNet: Bool) throws {
switch purpose {
case .bip44:
switch coinType {
case .bitcoin: self = isPrivate ? .xprv : .xpub
case .litecoin: self = isPrivate ? .Ltpv : .Ltub
if isTestNet {
self = isPrivate ? .tprv : .tpub
} else {
switch coinType {
case .bitcoin: self = isPrivate ? .xprv : .xpub
case .litecoin: self = isPrivate ? .Ltpv : .Ltub
}
}
case .bip49:
switch coinType {
case .bitcoin: self = isPrivate ? .yprv : .ypub
case .litecoin: self = isPrivate ? .Mtpv : .Mtub
}
case .bip84:
self = isPrivate ? .zprv : .zpub
if isTestNet {
self = isPrivate ? .vprv : .vpub
} else {
self = isPrivate ? .zprv : .zpub
}
case .bip86:
self = isPrivate ? .xprv : .xpub
}
Expand All @@ -52,22 +64,26 @@ public enum HDExtendedKeyVersion: UInt32, CaseIterable {
case .Ltub: return "Ltub"
case .Mtpv: return "Mtpv"
case .Mtub: return "Mtub"
case .vprv: return "vprv"
case .vpub: return "vpub"
case .tprv: return "tprv"
case .tpub: return "tpub"
}
}

public var purposes: [Purpose] {
switch self {
case .xprv, .xpub: return [.bip44, .bip86]
case .Ltpv, .Ltub: return [.bip44]
case .Ltpv, .Ltub, .tprv, .tpub: return [.bip44]
case .yprv, .ypub, .Mtpv, .Mtub: return [.bip49]
case .zprv, .zpub: return [.bip84]
case .zprv, .zpub, .vprv, .vpub: return [.bip84]
}
}

public var coinTypes: [ExtendedKeyCoinType] {
switch self {
case .xprv, .xpub, .zprv, .zpub: return [.bitcoin, .litecoin]
case .yprv, .ypub: return [.bitcoin]
case .yprv, .ypub, .vprv, .vpub, .tprv, .tpub: return [.bitcoin]
case .Ltpv, .Ltub, .Mtpv, .Mtub: return [.litecoin]
}
}
Expand All @@ -79,13 +95,14 @@ public enum HDExtendedKeyVersion: UInt32, CaseIterable {
case .zprv: return .zpub
case .Ltpv: return .Ltub
case .Mtpv: return .Mtub
case .vprv: return .vpub
default: return self
}
}

public var isPublic: Bool {
switch self {
case .xpub, .ypub, .zpub, .Ltub, .Mtub: return true
case .xpub, .ypub, .zpub, .Ltub, .Mtub, .vpub, .tpub: return true
default: return false
}
}
Expand Down