Skip to content

Commit

Permalink
[#40] Support for verifying TEX address charset
Browse files Browse the repository at this point in the history
closes #40
  • Loading branch information
pacu committed Mar 4, 2024
1 parent 44994a2 commit 72595e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Sources/zcash-swift-payment-uri/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ enum Parser {
"="
CharacterSet.qchar.eraseToAnyParser()
}

/// Parser that reads any character included in the Base58 charset.
static let transparentEncodingCharsetParser = CharacterSet.base58.eraseToAnyParser()

/// Parser that splits a sapling address human readable and Bech32 parts and verifies that
/// HRP is any of the accepted networks (main, test, regtest) and that the supposedly Bech32
Expand All @@ -127,6 +124,21 @@ enum Parser {
CharacterSet.bech32.eraseToAnyParser()
}

static let texEncodingCharsetParser = Parse {
OneOf {
"tex1"
"textest1"
}
CharacterSet.bech32.eraseToAnyParser()
}

static let transparentEncodingCharsetParser = Parse {
OneOf {
texEncodingCharsetParser
CharacterSet.base58.eraseToAnyParser()
}
}

/// maps a parsed Query Parameter key and value into an `IndexedParameter`
/// providing validation of Query keys and values. An address validation can be provided.
static func zcashParameter(
Expand Down Expand Up @@ -408,7 +420,7 @@ extension Parser {
case "u":
return (try? Parser.unifiedEncodingCharsetParser.parse(address)) != nil
case "t":
return (try? CharacterSet.base58.eraseToAnyParser().parse(address)) != nil
return (try? Parser.transparentEncodingCharsetParser.parse(address)) != nil
default:
return false
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/zcash-swift-payment-uriTests/ParsingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -944,5 +944,11 @@ final class ParsingTests: XCTestCase {
}
}
}

func testThatTEXAddressCharsetIsValidated() throws {
let tex = "tex1s2rt77ggv6q989lr49rkgzmh5slsksa9khdgte"

XCTAssertNotNil(RecipientAddress(value: tex, validating: Parser.onlyCharsetValidation))
}
}

0 comments on commit 72595e6

Please sign in to comment.