Skip to content

Commit

Permalink
Make signAlogo and hashAlgo index public
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcmz committed Jan 3, 2022
1 parent 27ea8a1 commit 8a0a716
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
10 changes: 5 additions & 5 deletions Sources/Flow/Models/FlowAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ extension Flow {
}
}

init(code: Int) {
public init(code: Int) {
self = SignatureAlgorithm.allCases.first { $0.code == code } ?? .unknown
}

init(cadence index: Int) {
public init(index: Int) {
self = SignatureAlgorithm.allCases.first { $0.index == index } ?? .unknown
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ extension Flow {
}
}

var index: Int {
public var index: Int {
switch self {
case .unknown:
return 0
Expand All @@ -171,11 +171,11 @@ extension Flow {
}
}

init(code: Int) {
public init(code: Int) {
self = HashAlgorithm.allCases.first { $0.code == code } ?? .unknown
}

init(cadence index: Int) {
public init(cadence index: Int) {
self = HashAlgorithm.allCases.first { $0.index == index } ?? .unknown
}
}
Expand Down
9 changes: 8 additions & 1 deletion Sources/Flow/Models/FlowSigner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@ public protocol FlowSigner {
var address: Flow.Address { get set }

/// The index of the public key
var keyIndex: Int { get set }
var hashAlgo: Flow.HashAlgorithm { get set }

/// The index of the public key
var signatureAlgo: Flow.SignatureAlgorithm { get set }

// The index of the public key
var keyIndex: Int { get set }

/// Sign the data with account private key
/// - parameters:
/// - signableData: The data to be signed
/// - returns: The signed data
func sign(signableData: Data) throws -> Data

// TODO: - Add async sign method
// func signAsync(signableData: Data) -> Future<Data, Error>
}

Expand Down
6 changes: 5 additions & 1 deletion Tests/FlowAccessAPIOnTestnetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ final class FlowAccessAPIOnTestnetTests: XCTestCase {

func testCanCreateAccount() throws {
// Example in Testnet

// Admin key
let address = addressC
let signer = [ECDSA_P256_Signer(address: address, keyIndex: 0, privateKey: privateKeyC)]

// User publick key
let accountKey = Flow.AccountKey(publicKey: Flow.PublicKey(hex: privateKeyA.publicKey.rawRepresentation.hexValue),
signAlgo: .ECDSA_P256,
hashAlgo: .SHA2_256,
weight: 1000)

var unsignedTx = try! flow.buildTransaction {
cadence {
"""
Expand Down
4 changes: 2 additions & 2 deletions Tests/P256Signer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import Foundation
struct ECDSA_P256_Signer: FlowSigner {
var address: Flow.Address
var keyIndex: Int
var hash: Flow.HashAlgorithm = .SHA2_256
var signature: Flow.SignatureAlgorithm = .ECDSA_P256
var hashAlgo: Flow.HashAlgorithm = .SHA2_256
var signatureAlgo: Flow.SignatureAlgorithm = .ECDSA_P256

var privateKey: P256.Signing.PrivateKey

Expand Down

0 comments on commit 8a0a716

Please sign in to comment.