Skip to content

Commit

Permalink
IOS-4687 Considering leading quotes invalid -- /m/'3/0
Browse files Browse the repository at this point in the history
  • Loading branch information
megakoko committed Sep 26, 2023
1 parent 28573e2 commit d6e7b05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ public struct DerivationPath: Equatable, Hashable {

let isHardened: Bool
let cleanedPathItem: String
if pathItem.hasPrefix(BIP32.Constants.hardenedSymbol) {
if pathItem.hasSuffix(BIP32.Constants.hardenedSymbol) {
isHardened = true
cleanedPathItem = String(pathItem.dropFirst(1))
} else if pathItem.hasSuffix(BIP32.Constants.hardenedSymbol) {
isHardened = true
cleanedPathItem = String(pathItem.dropLast(1))
cleanedPathItem = String(pathItem.dropLast())
} else {
isHardened = false
cleanedPathItem = pathItem
Expand Down
8 changes: 4 additions & 4 deletions TangemSdk/TangemSdkTests/HDWalletTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ class HDWalletTests: XCTestCase {
let derivationPath1 = try? DerivationPath(rawPath: "m/44'/0'/0'/1/0")
let derivationPath2 = try? DerivationPath(rawPath: "M/44'/0'/0'/1/0")
let derivationPath3 = DerivationPath(nodes: [.hardened(44), .hardened(0), .hardened(0), .nonHardened(1), .nonHardened(0)])
let derivationPath4 = try? DerivationPath(rawPath: "m/'44/'0/'0/1/0")
let derivationPath5 = try? DerivationPath(rawPath: "m/'44/’0/’0/1/0") // alternative quotes
let derivationPath6 = try? DerivationPath(rawPath: "m'/44'/0'/0'/1/0") // m with a quotation mark
let derivationPath4 = try? DerivationPath(rawPath: "m/44'/0’/0’/1/0") // alternative quotes
let derivationPath5 = try? DerivationPath(rawPath: "m'/44'/0'/0'/1/0") // m with a quotation mark
XCTAssertNotNil(derivationPath)
XCTAssertNotNil(derivationPath1)
XCTAssertNotNil(derivationPath2)
Expand All @@ -54,7 +53,6 @@ class HDWalletTests: XCTestCase {
XCTAssertEqual(derivationPath?.nodes, derivationPath3.nodes)
XCTAssertEqual(derivationPath?.nodes, derivationPath4?.nodes)
XCTAssertEqual(derivationPath?.nodes, derivationPath5?.nodes)
XCTAssertEqual(derivationPath?.nodes, derivationPath6?.nodes)

XCTAssertEqual(derivationPath?.nodes[0], DerivationNode.hardened(44))
XCTAssertEqual(derivationPath?.nodes[1], DerivationNode.hardened(0))
Expand All @@ -76,6 +74,8 @@ class HDWalletTests: XCTestCase {
XCTAssertNil(derivationPathWrong5)
let derivationPathWrong6 = try? DerivationPath(rawPath: "m/44'/0'/0'//1/0")
XCTAssertNil(derivationPathWrong6)
let derivationPathWrong7 = try? DerivationPath(rawPath: "m/'44/’0/’0/1/0")
XCTAssertNil(derivationPathWrong7)

let derivationPathNormalized = try! DerivationPath(rawPath: "m/44'/0'/0/1'/1/5/5'/9/9'")
let derivationPathNotNormalized = try! DerivationPath(rawPath: "m/044'/00'/00/001'/001/00005/00005'/00000000000000000000000000009/00000000000000000000000000009'")
Expand Down

0 comments on commit d6e7b05

Please sign in to comment.