Skip to content

Commit daec50b

Browse files
authored
Merge pull request #103 from sergeyshalnov/main
[PublicKey] Fix `isOnCurve` index out of range crash, add `isOnCurve` helper
2 parents c885f1a + b3ad041 commit daec50b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/SolanaSwift/Models/PublicKey.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public struct PublicKey: Codable, Equatable, CustomStringConvertible, Hashable {
5050
public var description: String {
5151
base58EncodedString
5252
}
53+
54+
public var isOnCurve: Bool {
55+
Self.isOnCurve(publicKey: base58EncodedString).toBool()
56+
}
5357

5458
public func short(numOfSymbolsRevealed: Int = 4) -> String {
5559
let pubkey = base58EncodedString
@@ -172,6 +176,10 @@ public extension PublicKey {
172176
}
173177

174178
static func isOnCurve(publicKeyBytes: Data) -> Int {
179+
guard !publicKeyBytes.bytes.isEmpty else {
180+
return 0
181+
}
182+
175183
var r = [[Int64]](repeating: NaclLowLevel.gf(), count: 4)
176184

177185
var t = NaclLowLevel.gf(),

0 commit comments

Comments
 (0)