Skip to content

Commit

Permalink
fix access
Browse files Browse the repository at this point in the history
  • Loading branch information
qiweiii committed Jul 22, 2024
1 parent 0993f84 commit 80990f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
24 changes: 13 additions & 11 deletions Utils/Sources/Utils/Bandersnatch.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bandersnatch_vrfs
import Foundation

enum BandersnatchError: Error {
public enum BandersnatchError: Error {
case createSecretFailed
case deserializePubKeyFailed
case generatePubKeyFailed
Expand Down Expand Up @@ -50,11 +50,11 @@ extension CPublic {
}
}

struct Bandersnatch {
public struct Bandersnatch {
public let secret: Data96
public let publicKey: Data32

init(seed: Data) throws {
public init(seed: Data) throws {
let seedBytes = [UInt8](seed)
let secretPtr = secret_new_from_seed(seedBytes, UInt(seed.count))
guard let secretPtr else {
Expand All @@ -72,11 +72,11 @@ struct Bandersnatch {
}
}

class Prover {
public class Prover {
private var prover: OpaquePointer

/// init with a set of bandersnatch public keys and provider index
init(ring: [Data32], proverIdx: UInt) throws {
public init(ring: [Data32], proverIdx: UInt) throws {
var success = false
let cPublicArr = try ring.map { try CPublic(data32: $0) }
prover = prover_new(cPublicArr, UInt(ring.count), proverIdx, &success)
Expand All @@ -92,7 +92,7 @@ class Prover {
/// Anonymous VRF signature.
///
/// Used for tickets submission.
func ringVRFSign(vrfInputData: Data, auxData: Data) throws -> Data784 {
public func ringVRFSign(vrfInputData: Data, auxData: Data) throws -> Data784 {
var output = [UInt8](repeating: 0, count: 784)
let success = prover_ring_vrf_sign(
&output, prover, [UInt8](vrfInputData), UInt(vrfInputData.count), [UInt8](auxData),
Expand All @@ -108,7 +108,7 @@ class Prover {
///
/// Used for ticket claiming during block production.
/// Not used with Safrole test vectors.
func ietfVRFSign(vrfInputData: Data, auxData: Data) throws -> Data96 {
public func ietfVRFSign(vrfInputData: Data, auxData: Data) throws -> Data96 {
var output = [UInt8](repeating: 0, count: 96)
let success = prover_ietf_vrf_sign(
&output, prover, [UInt8](vrfInputData), UInt(vrfInputData.count), [UInt8](auxData),
Expand All @@ -121,10 +121,10 @@ class Prover {
}
}

class Verifier {
public class Verifier {
private var verifier: OpaquePointer

init(ring: [Data32]) throws {
public init(ring: [Data32]) throws {
var success = false
let cPublicArr = try ring.map { try CPublic(data32: $0) }
verifier = verifier_new(cPublicArr, UInt(ring.count), &success)
Expand All @@ -142,7 +142,7 @@ class Verifier {
/// Used for tickets verification.
///
/// On success returns the VRF output hash.
func ringVRFVerify(vrfInputData: Data, auxData: Data, signature: Data) -> Result<
public func ringVRFVerify(vrfInputData: Data, auxData: Data, signature: Data) -> Result<
Data32, BandersnatchError
> {
var output = [UInt8](repeating: 0, count: 32)
Expand All @@ -162,7 +162,9 @@ class Verifier {
/// Not used with Safrole test vectors.
///
/// On success returns the VRF output hash.
func ietfVRFVerify(vrfInputData: Data, auxData: Data, signature: Data, signerKeyIndex: UInt)
public func ietfVRFVerify(
vrfInputData: Data, auxData: Data, signature: Data, signerKeyIndex: UInt
)
-> Result<Data32, BandersnatchError>
{
var output = [UInt8](repeating: 0, count: 32)
Expand Down
5 changes: 0 additions & 5 deletions Utils/Tests/UtilsTests/BandersnatchTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ import Testing
"b342bf8f6fa69c745daad2e99c92929b1da2b840f67e5e8015ac22dd1076343ea95c5bb4b69c197bfdc1b7d2f484fe455fb19bba7e8d17fcaf309ba5814bf54f3a74d75b408da8d3b99bf07f7cde373e4fd757061b1c99e0aac4847f1e393e892b566c14a7f8643a5d976ced0a18d12e32c660d59c66c271332138269cb0fe9c2462d5b3c1a6e9f5ed330ff0d70f64218010ff337b0b69b531f916c67ec564097cd842306df1b4b44534c95ff4efb73b17a14476057fdf8678683b251dc78b0b94712179345c794b6bd99aa54b564933651aee88c93b648e91a613c87bc3f445fff571452241e03e7d03151600a6ee259051a23086b408adec7c112dd94bd8123cf0bed88fddac46b7f891f34c29f13bf883771725aa234d398b13c39fd2a871894f1b1e2dbc7fffbc9c65c49d1e9fd5ee0da133bef363d4ebebe63de2b50328b5d7e020303499d55c07cae617091e33a1ee72ba1b65f940852e93e2905fdf577adcf62be9c74ebda9af59d3f11bece8996773f392a2b35693a45a5a042d88a3dc816b689fe596762d4ea7c6024da713304f56dc928be6e8048c651766952b6c40d0f48afc067ca7cbd77763a2d4f11e88e16033b3343f39bf519fe734db8a139d148ccead4331817d46cf469befa64ae153b5923869144dfa669da36171c20e1f757ed5231fa5a08827d83f7b478ddfb44c9bceb5c6c920b8761ff1e3edb03de48fb55884351f0ac5a7a1805b9b6c49c0529deb97e994deaf2dfd008825e8704cdc04b621f316b505fde26ab71b31af7becbc1154f9979e43e135d35720b93b367bedbe6c6182bb6ed99051f28a3ad6d348ba5b178e3ea0ec0bb4a03fe36604a9eeb609857f8334d3b4b34867361ed2ff9163acd9a27fa20303abe9fc29f2d6c921a8ee779f7f77d940b48bc4fce70a58eed83a206fb7db4c1c7ebe7658603495bb40f6a581dd9e235ba0583165b1569052f8fb4a3e604f2dd74ad84531c6b96723c867b06b6fdd1c4ba150cf9080aa6bbf44cc29041090973d56913b9dc755960371568ef1cf03f127fe8eca209db5d18829f5bfb5826f98833e3f42472b47fad995a9a8bb0e41a1df45ead20285a8"
let signatureBytes = Data(fromHexString: signatureHex)!

// prover
// let prover = try Prover(ring: ringData, proverIdx: 1)
// let proverSign = try prover.ringVRFSign(vrfInputData: vrfInputData, auxData: auxData)
// #expect(proverSign.data == signatureBytes)

// verifier
let verifier = try Verifier(ring: ringData)
let verifyRes = verifier.ringVRFVerify(
Expand Down

0 comments on commit 80990f0

Please sign in to comment.