Skip to content

Commit e162e53

Browse files
committed
fix typos
1 parent 09ca37c commit e162e53

File tree

16 files changed

+93
-338
lines changed

16 files changed

+93
-338
lines changed

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
fail_fast: true
2+
default_install_hook_types: [pre-commit]
3+
default_stages: [pre-commit]
4+
repos:
5+
- repo: https://github.com/crate-ci/typos
6+
rev: v1.42.3
7+
hooks:
8+
- id: typos
9+
10+
- repo: local
11+
hooks:
12+
- id: lint
13+
name: lint
14+
language: system
15+
types: [file, swift]
16+
entry: swiftformat . --lint
17+
pass_filenames: false
18+
- id: unit tests
19+
name: unit tests
20+
language: system
21+
types: [file, swift]
22+
entry: swift test
23+
pass_filenames: false

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ purge:
1818
make rmsubmod
1919
make clean
2020

21-
submodules: ## Update all sumodules .
21+
submodules: ## Update all submodules .
2222
git submodule update --init
2323

2424
init:

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ _K1_ is Swift wrapper around [libsecp256k1 (bitcoin-core/secp256k1)][lib], offer
1212
Read full documentation [here on SwiftPackageIndex][doc].
1313

1414
## Quick overview
15-
The API of K1 maps almost 1:1 with Apple's [CryptoKit][ck], vendoring a set of keypairs, one per feature. E.g. in CryptoKit you have `Curve25519.KeyAgreement.PrivateKey` and `Curve25519.KeyAgreement.PublicKey` which are seperate for `Curve25519.Signing.PrivateKey` and `Curve25519.Signing.PublicKey`.
15+
The API of K1 maps almost 1:1 with Apple's [CryptoKit][ck], vendoring a set of keypairs, one per feature. E.g. in CryptoKit you have `Curve25519.KeyAgreement.PrivateKey` and `Curve25519.KeyAgreement.PublicKey` which are separate for `Curve25519.Signing.PrivateKey` and `Curve25519.Signing.PublicKey`.
1616

1717
Just like that K1 vendors these key pairs:
1818
- `K1.KeyAgreement.PrivateKey` / `K1.KeyAgreement.PublicKey` for key agreement (ECDH)
@@ -112,7 +112,7 @@ let signature = try alice.signature(forUnhashed: message)
112112

113113
```swift
114114
let hashedMessage: Data = // from somewhere
115-
let publicKey: K1.ECDSA.PublicKey = alice.publcKey
115+
let publicKey: K1.ECDSA.PublicKey = alice.publicKey
116116
let signature: K1.ECDSA.Signature // from above
117117

118118
assert(
@@ -205,12 +205,12 @@ Returning only the `X` coordinate of the point, following [ANSI X9.63][x963] sta
205205
You can retrieve the `X` coordinate as raw data using `withUnsafeBytes` if you need to.
206206

207207
```swift
208-
let ab: CryptoKit.SharedSecret = try alice.sharedSecretFromKeyAgreement(with: bob.publicKey)
209-
let ba: CryptoKit.SharedSecret = try bob.sharedSecretFromKeyAgreement(with: alice.publicKey)
208+
let aliceBob: CryptoKit.SharedSecret = try alice.sharedSecretFromKeyAgreement(with: bob.publicKey)
209+
let bobAlice: CryptoKit.SharedSecret = try bob.sharedSecretFromKeyAgreement(with: alice.publicKey)
210210

211-
assert(ab == ba) // pass
211+
assert(aliceBob == bobAlice) // pass
212212

213-
ab.withUnsafeBytes {
213+
aliceBob.withUnsafeBytes {
214214
assert(Data($0).count == 32) // pass
215215
}
216216
```
@@ -220,11 +220,11 @@ ab.withUnsafeBytes {
220220
Using `libsecp256k1` default behaviour, returning a SHA-256 hash of the **compressed** point, embedded in a [`CryptoKit.SharedSecret`][ckss], which is useful since you can use `CryptoKit` key derivation functions.
221221

222222
```swift
223-
let ab: CryptoKit.SharedSecret = try alice.ecdh(with: bob.publicKey)
224-
let ba: CryptoKit.SharedSecret = try bob.ecdh(with: alice.publicKey)
225-
assert(ab == ba) // pass
223+
let aliceBob: CryptoKit.SharedSecret = try alice.ecdh(with: bob.publicKey)
224+
let bobAlice: CryptoKit.SharedSecret = try bob.ecdh(with: alice.publicKey)
225+
assert(aliceBob == bobAlice) // pass
226226

227-
ab.withUnsafeBytes {
227+
aliceBob.withUnsafeBytes {
228228
assert(Data($0).count == 32) // pass
229229
}
230230
```
@@ -234,11 +234,11 @@ ab.withUnsafeBytes {
234234
Returns an entire uncompressed EC point, without hashing it. Might be useful if you wanna construct your own cryptographic functions, e.g. some custom ECIES.
235235

236236
```swift
237-
let ab: Data = try alice.ecdhPoint(with: bob.publicKey)
238-
let ba: Data = try bob.ecdhPoint(with: alice.publicKey)
239-
assert(ab == ba) // pass
237+
let aliceBob: Data = try alice.ecdhPoint(with: bob.publicKey)
238+
let bobAlice: Data = try bob.ecdhPoint(with: alice.publicKey)
239+
assert(aliceBob == bobAlice) // pass
240240

241-
assert(ab.count == 65) // pass
241+
assert(aliceBob.count == 65) // pass
242242
```
243243

244244

Sources/K1/K1/ECDSA/ECDSA.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension K1.ECDSA.ValidationOptions {
4545
extension K1.ECDSA {
4646
/// Additional parameters used during signing, affects the signature produced.
4747
public struct SigningOptions: Sendable, Hashable {
48-
/// Behavior of nonce generation used durring signing.
48+
/// Behavior of nonce generation used during signing.
4949
public let nonceFunction: NonceFunction
5050

5151
public init(nonceFunction: NonceFunction) {
@@ -58,7 +58,7 @@ extension K1.ECDSA.SigningOptions {
5858
/// The default behavior used during ECDSA signing.
5959
public static let `default`: Self = .init(nonceFunction: .deterministic())
6060

61-
/// Behavior of nonce generation used durring signing.
61+
/// Behavior of nonce generation used during signing.
6262
public enum NonceFunction: Sendable, Hashable {
6363
/// Use securely generate random data as nonce during ECDSA signing.
6464
case random

Sources/K1/Support/Misc/K1+Error.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ extension K1.Error: CustomDebugStringConvertible {
134134
case .ecdsaSignatureParseDER:
135135
return "ECDSA signature parse DER"
136136
case .ecdsaSignatureSerializeCompact:
137-
return "ECDSA signature serialzie compact"
137+
return "ECDSA signature serialize compact"
138138
case .ecdsaSignatureSerializeDER:
139139
return "ECDSA signature serialize DER"
140140
case .recoverableSignatureParseCompact:

Sources/K1/Support/ThirdyParty/swift-crypto/ASN1/ASN1.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ extension ArraySlice where Element == UInt8 {
639639
let requiredBits = UInt.bitWidth - length.leadingZeroBitCount
640640
switch requiredBits {
641641
case 0...7:
642-
// For 0 to 7 bits, the long form is unnacceptable and we require the short.
642+
// For 0 to 7 bits, the long form is unacceptable and we require the short.
643643
throw CryptoKitASN1Error.unsupportedFieldLength
644644
case 8...:
645645
// For 8 or more bits, fieldLength should be the minimum required.

Tests/K1Tests/TestCases/APITest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ final class APITest: XCTestCase {
9494
func testECDH() throws {
9595
let alice = K1.KeyAgreement.PrivateKey()
9696
let bob = K1.KeyAgreement.PrivateKey()
97-
let ab = try alice.sharedSecretFromKeyAgreement(with: bob.publicKey)
98-
let ba = try bob.sharedSecretFromKeyAgreement(with: alice.publicKey)
99-
XCTAssertEqual(ab, ba)
97+
let aliceBob = try alice.sharedSecretFromKeyAgreement(with: bob.publicKey)
98+
let bobAlice = try bob.sharedSecretFromKeyAgreement(with: alice.publicKey)
99+
XCTAssertEqual(aliceBob, bobAlice)
100100
}
101101
}

Tests/K1Tests/TestCases/ECDH/ECDHTests.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@ final class ECDHTests: XCTestCase {
88
let alice = K1.KeyAgreement.PrivateKey()
99
let bob = K1.KeyAgreement.PrivateKey()
1010
XCTAssertNotEqual(alice, bob)
11-
let ab = try alice.sharedSecretFromKeyAgreement(with: bob.publicKey)
12-
let ba = try bob.sharedSecretFromKeyAgreement(with: alice.publicKey)
13-
ab.withUnsafeBytes {
11+
let aliceBob = try alice.sharedSecretFromKeyAgreement(with: bob.publicKey)
12+
let bobAlice = try bob.sharedSecretFromKeyAgreement(with: alice.publicKey)
13+
aliceBob.withUnsafeBytes {
1414
XCTAssertEqual(Data($0).count, 32)
1515
}
16-
XCTAssertEqual(ab, ba, "Alice and Bob should be able to agree on the same secret")
16+
XCTAssertEqual(aliceBob, bobAlice, "Alice and Bob should be able to agree on the same secret")
1717
}
1818

1919
func testECDHLibsecp256k1() throws {
2020
let alice = K1.KeyAgreement.PrivateKey()
2121
let bob = K1.KeyAgreement.PrivateKey()
2222
XCTAssertNotEqual(alice, bob)
23-
let ab = try alice.ecdh(with: bob.publicKey)
24-
let ba = try bob.ecdh(with: alice.publicKey)
25-
ab.withUnsafeBytes {
23+
let aliceBob = try alice.ecdh(with: bob.publicKey)
24+
let bobAlice = try bob.ecdh(with: alice.publicKey)
25+
aliceBob.withUnsafeBytes {
2626
XCTAssertEqual(Data($0).count, 32)
2727
}
28-
XCTAssertEqual(ab, ba, "Alice and Bob should be able to agree on the same secret")
28+
XCTAssertEqual(aliceBob, bobAlice, "Alice and Bob should be able to agree on the same secret")
2929
}
3030

3131
func testECDHPoint() throws {
3232
let alice = K1.KeyAgreement.PrivateKey()
3333
let bob = K1.KeyAgreement.PrivateKey()
3434
XCTAssertNotEqual(alice, bob)
35-
let ab = try alice.ecdhPoint(with: bob.publicKey)
36-
let ba = try bob.ecdhPoint(with: alice.publicKey)
37-
XCTAssertEqual(ab, ba, "Alice and Bob should be able to agree on the same secret")
38-
XCTAssertEqual(ab.count, 65)
35+
let aliceBob = try alice.ecdhPoint(with: bob.publicKey)
36+
let bobAlice = try bob.ecdhPoint(with: alice.publicKey)
37+
XCTAssertEqual(aliceBob, bobAlice, "Alice and Bob should be able to agree on the same secret")
38+
XCTAssertEqual(aliceBob.count, 65)
3939
}
4040

4141
/// Test vectors from: https://crypto.stackexchange.com/q/57695
@@ -57,10 +57,10 @@ final class ECDHTests: XCTestCase {
5757
func testECDHCustom() throws {
5858
let alice = try K1.KeyAgreement.PrivateKey(rawRepresentation: Data(repeating: 0xAA, count: 32))
5959
let bob = try K1.KeyAgreement.PrivateKey(rawRepresentation: Data(repeating: 0xBB, count: 32))
60-
let ab = try alice.ecdhPoint(with: bob.publicKey)
61-
let ba = try bob.ecdhPoint(with: alice.publicKey)
62-
XCTAssertEqual(ab, ba, "Alice and Bob should be able to agree on the same secret")
63-
XCTAssertEqual(ab.hex, "041d3e7279da3f845c4246087cdd3dd42bea3dea7245ceaf75609d8eb0a4e89c4e8e7a7c012045a2eae87463012468d7aae911b8a1140e240c828c96d9b19bd8e7")
60+
let aliceBob = try alice.ecdhPoint(with: bob.publicKey)
61+
let bobAlice = try bob.ecdhPoint(with: alice.publicKey)
62+
XCTAssertEqual(aliceBob, bobAlice, "Alice and Bob should be able to agree on the same secret")
63+
XCTAssertEqual(aliceBob.hex, "041d3e7279da3f845c4246087cdd3dd42bea3dea7245ceaf75609d8eb0a4e89c4e8e7a7c012045a2eae87463012468d7aae911b8a1140e240c828c96d9b19bd8e7")
6464
}
6565
}
6666

Tests/K1Tests/TestCases/ECDH/TwoVariantsOfECDHWithKDFTests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,44 +74,44 @@ extension TwoVariantsOfECDHWithKDFTests {
7474
for outcome in vector.outcomes {
7575
switch outcome.ecdhVariant {
7676
case .asn1X963:
77-
let sharedSecretAB = try alice.sharedSecretFromKeyAgreement(with: bob.publicKey)
78-
let sharedSecretBA = try bob.sharedSecretFromKeyAgreement(with: alice.publicKey)
77+
let aliceBob = try alice.sharedSecretFromKeyAgreement(with: bob.publicKey)
78+
let bobAlice = try bob.sharedSecretFromKeyAgreement(with: alice.publicKey)
7979

80-
XCTAssertEqual(sharedSecretAB, sharedSecretBA)
81-
sharedSecretAB.withUnsafeBytes {
80+
XCTAssertEqual(aliceBob, bobAlice)
81+
aliceBob.withUnsafeBytes {
8282
XCTAssertEqual(Data($0).hex, outcome.ecdhSharedKey, "Wrong ECDH secret, mismatched expected from vector.")
8383
}
8484

8585
for derivedKeys in outcome.derivedKeys {
8686
let info = try XCTUnwrap(derivedKeys.info.data(using: .utf8))
8787
let salt = try Data(hex: derivedKeys.salt)
88-
let x963 = sharedSecretBA.x963DerivedSymmetricKey(using: hash, sharedInfo: info, outputByteCount: outputByteCount)
88+
let x963 = bobAlice.x963DerivedSymmetricKey(using: hash, sharedInfo: info, outputByteCount: outputByteCount)
8989
x963.withUnsafeBytes {
9090
XCTAssertEqual(Data($0).hex, derivedKeys.x963, "Wrong X963 KDF result, mismatched expected from vector.")
9191
}
92-
let hkdf = sharedSecretBA.hkdfDerivedSymmetricKey(using: hash, salt: salt, sharedInfo: info, outputByteCount: outputByteCount)
92+
let hkdf = bobAlice.hkdfDerivedSymmetricKey(using: hash, salt: salt, sharedInfo: info, outputByteCount: outputByteCount)
9393
hkdf.withUnsafeBytes {
9494
XCTAssertEqual(Data($0).hex, derivedKeys.hkdf, "Wrong HKDF result, mismatched expected from vector.")
9595
}
9696
}
9797

9898
case .libsecp256k1:
99-
let sharedSecretAB = try alice.ecdh(with: bob.publicKey)
100-
let sharedSecretBA = try bob.ecdh(with: alice.publicKey)
99+
let aliceBob = try alice.ecdh(with: bob.publicKey)
100+
let bobAlice = try bob.ecdh(with: alice.publicKey)
101101

102-
XCTAssertEqual(sharedSecretAB, sharedSecretBA)
103-
sharedSecretAB.withUnsafeBytes {
102+
XCTAssertEqual(aliceBob, bobAlice)
103+
aliceBob.withUnsafeBytes {
104104
XCTAssertEqual(Data($0).hex, outcome.ecdhSharedKey, "Wrong ECDH secret, mismatched expected from vector.")
105105
}
106106

107107
for derivedKeys in outcome.derivedKeys {
108108
let info = try XCTUnwrap(derivedKeys.info.data(using: .utf8))
109109
let salt = try Data(hex: derivedKeys.salt)
110-
let x963 = sharedSecretAB.x963DerivedSymmetricKey(using: hash, sharedInfo: info, outputByteCount: outputByteCount)
110+
let x963 = aliceBob.x963DerivedSymmetricKey(using: hash, sharedInfo: info, outputByteCount: outputByteCount)
111111
x963.withUnsafeBytes {
112112
XCTAssertEqual(Data($0).hex, derivedKeys.x963, "Wrong X963 KDF result, mismatched expected from vector.")
113113
}
114-
let hkdf = sharedSecretAB.hkdfDerivedSymmetricKey(using: hash, salt: salt, sharedInfo: info, outputByteCount: outputByteCount)
114+
let hkdf = aliceBob.hkdfDerivedSymmetricKey(using: hash, salt: salt, sharedInfo: info, outputByteCount: outputByteCount)
115115
hkdf.withUnsafeBytes {
116116
XCTAssertEqual(Data($0).hex, derivedKeys.hkdf, "Wrong HKDF result, mismatched expected from vector.")
117117
}

Tests/K1Tests/TestCases/Performance/PerformanceTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ final class PerformanceTests: XCTestCase {
6969
let bobPrivateKey = K1.KeyAgreement.PrivateKey()
7070
let bobPublicKey = bobPrivateKey.publicKey
7171

72-
var ab = try alicePrivateKey.sharedSecretFromKeyAgreement(with: bobPublicKey)
73-
var ba = try bobPrivateKey.sharedSecretFromKeyAgreement(with: alicePublicKey)
74-
XCTAssertEqual(ab, ba)
75-
ab = try alicePrivateKey.ecdh(with: bobPublicKey)
76-
ba = try bobPrivateKey.ecdh(with: alicePublicKey)
77-
XCTAssertEqual(ab, ba)
72+
var aliceBob = try alicePrivateKey.sharedSecretFromKeyAgreement(with: bobPublicKey)
73+
var bobAlice = try bobPrivateKey.sharedSecretFromKeyAgreement(with: alicePublicKey)
74+
XCTAssertEqual(aliceBob, bobAlice)
75+
aliceBob = try alicePrivateKey.ecdh(with: bobPublicKey)
76+
bobAlice = try bobPrivateKey.ecdh(with: alicePublicKey)
77+
XCTAssertEqual(aliceBob, bobAlice)
7878
}
7979
} catch {
8080
XCTFail("abort")

0 commit comments

Comments
 (0)