Skip to content

Commit 486d3bd

Browse files
committed
fix linting
1 parent 9b4b95c commit 486d3bd

50 files changed

Lines changed: 282 additions & 80 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.swiftlint.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
disabled_rules:
2+
- trailing_comma
3+
4+
excluded:
5+
- .build
6+
- scripts/update-libsecp/.build
7+
- Tests/K1Tests/TestCases/

Sources/K1/K1.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import Foundation
22

3+
// swiftlint:disable type_name
4+
35
/// The Elliptic Curve `secp256k1`
46
public enum K1 {
57
// The namespace for all structs and operations vendored by this library.
68
}
9+
10+
// swiftlint:enable type_name

Sources/K1/K1/ECDH/KeyAgreement.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import Foundation
33

44
// MARK: - K1.KeyAgreement
55
extension K1 {
6-
/// A mechanism used to create a shared secret between two users by performing `secp256k1` elliptic curve Diffie Hellman (ECDH) key exchange.
6+
/// A mechanism used to create a shared secret between two users by
7+
/// performing `secp256k1` elliptic curve Diffie Hellman (ECDH) key exchange.
78
public enum KeyAgreement {
89
// Just a namespace
910
}

Sources/K1/K1/ECDSA/ECDSA.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// MARK: - K1.ECDSA
22
extension K1 {
3-
/// A mechanism used to create or verify a cryptographic signature using the `secp256k1` elliptic curve digital signature algorithm (ECDSA), signatures that do not offer recovery of the public key.
3+
/// A mechanism used to create or verify a cryptographic signature using
4+
/// the `secp256k1` elliptic curve digital signature algorithm (ECDSA),
5+
/// signatures that do not offer recovery of the public key.
46
public enum ECDSA {}
57
}
68

@@ -23,6 +25,8 @@ extension K1.ECDSA.ValidationOptions {
2325
malleabilityStrictness: .rejected
2426
)
2527

28+
// swiftlint:disable line_length
29+
2630
/// Whether or not to consider malleable signatures valid.
2731
///
2832
/// [more]: https://github.com/bitcoin-core/secp256k1/blob/2e5e4b67dfb67950563c5f0ab2a62e25eb1f35c5/include/secp256k1.h#L510-L550
@@ -33,6 +37,8 @@ extension K1.ECDSA.ValidationOptions {
3337
/// Accepts malleable signatures valid.
3438
case accepted
3539
}
40+
41+
// swiftlint:enable line_length
3642
}
3743

3844
// MARK: - K1.ECDSA.SigningOptions

Sources/K1/K1/ECDSA/ECDSASignatureNonRecoverable.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extension K1.ECDSA {
77
/// A `secp256k1` elliptic curve digital signature algorithm (ECDSA) signature,
88
/// from which users can recover a public key with the message that was signed.
99
public struct Signature: Sendable, Hashable, ContiguousBytes {
10+
// swiftlint:disable:next nesting
1011
typealias Wrapped = FFI.ECDSA.Wrapped
1112
let wrapped: Wrapped
1213

Sources/K1/K1/ECDSA/ECDSASignatureRecoverable.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import Foundation
44

55
// MARK: - K1.ECDSAWithKeyRecovery
66
extension K1 {
7-
/// A mechanism used to create or verify a cryptographic signature using the `secp256k1` elliptic curve digital signature algorithm (ECDSA), signatures that do offers recovery of the public key.
7+
/// A mechanism used to create or verify a cryptographic signature using
8+
/// the `secp256k1` elliptic curve digital signature algorithm (ECDSA),
9+
/// signatures that do offers recovery of the public key.
810
public enum ECDSAWithKeyRecovery {
911
// Just a namespace
1012
}
@@ -15,6 +17,7 @@ extension K1.ECDSAWithKeyRecovery {
1517
/// A `secp256k1` elliptic curve digital signature algorithm (ECDSA) signature,
1618
/// from which users **cannot** recover the public key, not without the `RecoveryID`.
1719
public struct Signature: Sendable, Hashable, ContiguousBytes {
20+
// swiftlint:disable:next nesting
1821
typealias Wrapped = FFI.ECDSAWithKeyRecovery.Wrapped
1922
let wrapped: Wrapped
2023

@@ -60,6 +63,7 @@ extension K1.ECDSAWithKeyRecovery.Signature {
6063

6164
/// Compact aka `IEEE P1363` aka `R||S` and `V` (`RecoveryID`).
6265
public func compact() throws -> Compact {
66+
// swiftlint:disable:next identifier_name
6367
let (rs, recid) = try FFI.ECDSAWithKeyRecovery.serializeCompact(
6468
wrapped
6569
)
@@ -138,10 +142,12 @@ extension K1.ECDSAWithKeyRecovery.Signature.Compact {
138142
case vrs
139143
}
140144

145+
// swiftlint:disable:next identifier_name
141146
private var v: Data {
142147
recoveryID.vData
143148
}
144149

150+
// swiftlint:disable:next identifier_name
145151
private var rs: Data {
146152
compact
147153
}

Sources/K1/K1/ECDSA/RecoveryID.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import Foundation
33
// MARK: - K1.ECDSAWithKeyRecovery.Signature.RecoveryID
44
extension K1.ECDSAWithKeyRecovery.Signature {
55
public enum RecoveryID: UInt8, Sendable, Hashable, Codable {
6+
// swiftlint:disable identifier_name
67
case _0 = 0
78
case _1 = 1
89
case _2 = 2
910
case _3 = 3
11+
// swiftlint:enable identifier_name
1012

1113
var recid: Int32 {
1214
Int32(rawValue)
@@ -16,6 +18,7 @@ extension K1.ECDSAWithKeyRecovery.Signature {
1618

1719
extension K1.ECDSAWithKeyRecovery.Signature.RecoveryID {
1820
public init(byte: UInt8) throws {
21+
// swiftlint:disable:next identifier_name
1922
guard let self_ = Self(rawValue: byte) else {
2023
throw K1.Error.invalidParameter
2124
}

Sources/K1/K1/Keys/Keys.generated.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import Foundation
66

7+
// swiftlint:disable all
8+
79
extension K1.KeyAgreement {
810
// MARK: KeyAgreement + PrivateKey
911
/// A `secp256k1` private key used for key agreement.
@@ -201,25 +203,25 @@ extension K1.KeyAgreement {
201203
}
202204

203205
// MARK: Group Operations
204-
206+
205207
/// Adds two public keys (points) on the secp256k1 curve
206208
public static func + (lhs: Self, rhs: Self) throws -> Self {
207209
try Self(impl: lhs.impl + rhs.impl)
208210
}
209-
211+
210212
/// Subtracts two public keys (points) on the secp256k1 curve
211213
public static func - (lhs: Self, rhs: Self) throws -> Self {
212214
try Self(impl: lhs.impl - rhs.impl)
213215
}
214-
216+
215217
/// Negates a public key (point) on the secp256k1 curve
216218
public func negate() throws -> Self {
217219
try Self(impl: impl.negate())
218220
}
219-
221+
220222
/// Combines multiple public keys (points) on the secp256k1 curve
221223
public static func sum(keys: [Self]) throws -> Self {
222-
let impls = keys.map { $0.impl }
224+
let impls = keys.map(\.impl)
223225
return try Self(impl: K1._PublicKeyImplementation.sum(keys: impls))
224226
}
225227
}
@@ -442,7 +444,7 @@ extension K1.Schnorr {
442444

443445
/// Combines multiple public keys (points) on the secp256k1 curve
444446
public static func sum(keys: [Self]) throws -> Self {
445-
let impls = keys.map { $0.impl }
447+
let impls = keys.map(\.impl)
446448
return try Self(impl: K1._PublicKeyImplementation.sum(keys: impls))
447449
}
448450
}
@@ -665,7 +667,7 @@ extension K1.ECDSA {
665667

666668
/// Combines multiple public keys (points) on the secp256k1 curve
667669
public static func sum(keys: [Self]) throws -> Self {
668-
let impls = keys.map { $0.impl }
670+
let impls = keys.map(\.impl)
669671
return try Self(impl: K1._PublicKeyImplementation.sum(keys: impls))
670672
}
671673
}
@@ -888,7 +890,7 @@ extension K1.ECDSAWithKeyRecovery {
888890

889891
/// Combines multiple public keys (points) on the secp256k1 curve
890892
public static func sum(keys: [Self]) throws -> Self {
891-
let impls = keys.map { $0.impl }
893+
let impls = keys.map(\.impl)
892894
return try Self(impl: K1._PublicKeyImplementation.sum(keys: impls))
893895
}
894896
}
@@ -917,3 +919,5 @@ extension K1.ECDSAWithKeyRecovery.PrivateKey: _K1PrivateKeyProtocol {}
917919

918920
// MARK: - K1.ECDSAWithKeyRecovery.PublicKey + _K1PublicKeyProtocol
919921
extension K1.ECDSAWithKeyRecovery.PublicKey: _K1PublicKeyProtocol {}
922+
923+
// swiftlint:enable all

Sources/K1/K1/Keys/Keys.swift.gyb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import Foundation
66

7+
// swiftlint:disable all
8+
79
%{
810
LIST_KEY_FOR_FEATURE_WITH_DOCS = [
911
{
@@ -278,5 +280,7 @@ extension K1.${FEATURE}.PrivateKey: _K1PrivateKeyProtocol {}
278280
extension K1.${FEATURE}.PublicKey: _K1PublicKeyProtocol {}
279281
% end
280282

283+
// swiftlint:enable all
284+
281285
% end
282286

Sources/K1/K1/Keys/PrivateKeyImplementation.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import CryptoKit
22
import Foundation
33

44
// MARK: - _K1KeyExportable
5+
// swiftlint:disable:next type_name
56
protocol _K1KeyExportable {
67
var rawRepresentation: Data { get }
78
var derRepresentation: Data { get }
@@ -10,16 +11,19 @@ protocol _K1KeyExportable {
1011
}
1112

1213
// MARK: - _K1KeyImportable
14+
// swiftlint:disable:next type_name
1315
protocol _K1KeyImportable {
1416
init(rawRepresentation: some ContiguousBytes) throws
1517
init(derRepresentation: some RandomAccessCollection<UInt8>) throws
1618
init(pemRepresentation: String) throws
1719
init(x963Representation: some ContiguousBytes) throws
1820
}
1921

22+
// swiftlint:disable:next type_name
2023
typealias _K1KeyPortable = _K1KeyExportable & _K1KeyImportable
2124

2225
// MARK: - _K1PrivateKeyProtocol
26+
// swiftlint:disable:next type_name
2327
protocol _K1PrivateKeyProtocol: _K1KeyPortable {
2428
associatedtype PublicKey: _K1PublicKeyProtocol
2529
var publicKey: PublicKey { get }
@@ -28,7 +32,9 @@ protocol _K1PrivateKeyProtocol: _K1KeyPortable {
2832

2933
// MARK: - K1._PrivateKeyImplementation
3034
extension K1 {
35+
// swiftlint:disable:next type_name
3136
struct _PrivateKeyImplementation: Sendable, Hashable, _K1PrivateKeyProtocol {
37+
// swiftlint:disable:next nesting
3238
typealias Wrapped = FFI.PrivateKey.Wrapped
3339
let wrapped: Wrapped
3440

@@ -122,6 +128,7 @@ extension K1._PrivateKeyImplementation {
122128
var serializer = ASN1.Serializer()
123129

124130
// Serializing these keys can't throw
131+
// swiftlint:disable:next force_try
125132
try! serializer.serialize(pkey)
126133
return Data(serializer.serializedBytes)
127134
}

0 commit comments

Comments
 (0)