Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PublicKey] Fix isOnCurve index out of range crash, add isOnCurve helper #103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions Sources/SolanaSwift/Models/PublicKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public struct PublicKey: Codable, Equatable, CustomStringConvertible, Hashable {
public var description: String {
base58EncodedString
}

public var isOnCurve: Bool {
Self.isOnCurve(publicKey: base58EncodedString).toBool()
}

public func short(numOfSymbolsRevealed: Int = 4) -> String {
let pubkey = base58EncodedString
Expand Down Expand Up @@ -172,6 +176,10 @@ public extension PublicKey {
}

static func isOnCurve(publicKeyBytes: Data) -> Int {
guard !publicKeyBytes.bytes.isEmpty else {
return 0
}

var r = [[Int64]](repeating: NaclLowLevel.gf(), count: 4)

var t = NaclLowLevel.gf(),
Expand Down