Skip to content

Commit

Permalink
Updated dependency graph
Browse files Browse the repository at this point in the history
  • Loading branch information
anquii committed Dec 2, 2023
1 parent 31292ae commit 4aa455e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
11 changes: 10 additions & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/anquii/BigIntExtensions.git",
"state" : {
"revision" : "cc15789436c93fdd40adfb52212da32353fb8ccd",
"revision" : "1d960373cc9817e0949ab7c7d7719b62bcaf09c7",
"version" : "0.1.0"
}
},
{
"identity" : "binaryextensions",
"kind" : "remoteSourceControl",
"location" : "https://github.com/anquii/BinaryExtensions.git",
"state" : {
"revision" : "ab9c034ab6d6a578fa0e574ef8c1b8d117b8bfc9",
"version" : "0.1.1"
}
}
],
"version" : 2
Expand Down
5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/attaswift/BigInt.git", exact: "5.3.0"),
.package(url: "https://github.com/anquii/BigIntExtensions.git", exact: "0.1.0")
.package(url: "https://github.com/anquii/BigIntExtensions.git", exact: "0.1.0"),
.package(url: "https://github.com/anquii/BinaryExtensions.git", exact: "0.1.1")
],
targets: [
.target(name: "ERC2333", dependencies: ["BigInt"]),
.target(name: "ERC2333", dependencies: ["BigInt", "BinaryExtensions"]),
.testTarget(name: "ERC2333Tests", dependencies: ["ERC2333", "BigIntExtensions"])
]
)
3 changes: 2 additions & 1 deletion Sources/ERC2333/CompressedPublicLamportKeyDerivator.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Foundation
import BinaryExtensions
import CryptoKit

struct CompressedPublicLamportKeyDerivator {
static func publicKey(privateParentKey: Data, index: UInt32) -> Data {
let salt = Data(index.bytes)
let salt = Data(index.bigEndian.bytes)
let privateKey1 = PrivateLamportKeyDerivator.privateKey(privateParentKey: privateParentKey, salt: salt)
let privateKey2 = PrivateLamportKeyDerivator.privateKey(privateParentKey: Data(privateParentKey.map { ~$0 }), salt: salt)
let publicKey = PublicLamportKeyDerivator.publicKey(privateKey: privateKey1 + privateKey2).reduce(Data(), +)
Expand Down
7 changes: 0 additions & 7 deletions Sources/ERC2333/FixedWidthInteger+Extension.swift

This file was deleted.

5 changes: 3 additions & 2 deletions Sources/ERC2333/PrivateKeyDerivator.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import CryptoKit
import BigInt
import BinaryExtensions
import CryptoKit

struct PrivateKeyDerivator {
private static let outputByteCount = UInt16(48)
Expand All @@ -16,7 +17,7 @@ struct PrivateKeyDerivator {
.deriveKey(
inputKeyMaterial: inputKeyMaterial,
salt: salt,
info: outputByteCount.bytes,
info: outputByteCount.bigEndian.bytes,
outputByteCount: Int(outputByteCount)
)
.withUnsafeBytes { Data($0) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ final class CompressedPublicLamportKeyDerivatorTests: XCTestCase {
func testGivenVectorPrivateParentKey_WhenDerivateCompressedPublicLamportKey_ThenEqualVectorKey() {
let privateParentKey = Data(unsignedInteger: BigUInt("6083874454709270928345386274498605044986640685124978867557563392430687146096"))
let compressedPublicLamportKey = CompressedPublicLamportKeyDerivator.publicKey(privateParentKey: privateParentKey, index: 0)
XCTAssertEqual(BigUInt(compressedPublicLamportKey), BigUInt(hex: "0xdd635d27d1d52b9a49df9e5c0c622360a4dd17cba7db4e89bce3cb048fb721a5"))
XCTAssertEqual(BigUInt(compressedPublicLamportKey), BigUInt(hexEncodedString: "0xdd635d27d1d52b9a49df9e5c0c622360a4dd17cba7db4e89bce3cb048fb721a5"))
}
}
5 changes: 3 additions & 2 deletions Tests/ERC2333Tests/PrivateLamportKeyDerivatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import XCTest
import Foundation
import BigInt
import BigIntExtensions
import BinaryExtensions
@testable import ERC2333

final class PrivateLamportKeyDerivatorTests: XCTestCase {
Expand Down Expand Up @@ -525,10 +526,10 @@ final class PrivateLamportKeyDerivatorTests: XCTestCase {
let privateKey1 = PrivateLamportKeyDerivator.privateKey(privateParentKey: privateParentKey, salt: salt)
let privateKey2 = PrivateLamportKeyDerivator.privateKey(privateParentKey: Data(privateParentKey.map { ~$0 }), salt: salt)
for (index, data) in privateKey1.enumerated() {
XCTAssertEqual(BigUInt(data), BigUInt(hex: hexEncodedPrivateKey1[index]))
XCTAssertEqual(BigUInt(data), BigUInt(hexEncodedString: hexEncodedPrivateKey1[index]))
}
for (index, data) in privateKey2.enumerated() {
XCTAssertEqual(BigUInt(data), BigUInt(hex: hexEncodedPrivateKey2[index]))
XCTAssertEqual(BigUInt(data), BigUInt(hexEncodedString: hexEncodedPrivateKey2[index]))
}
}
}
2 changes: 1 addition & 1 deletion Tests/ERC2333Tests/PrivateMasterKeyDerivatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class PrivateMasterKeyDerivatorTests: XCTestCase {
]
let sut = self.sut()
for (index, hexEncodedSeed) in hexEncodedSeeds.enumerated() {
let seed = Data(unsignedInteger: BigUInt(hex: hexEncodedSeed)!, minimumLength: 32)
let seed = Data(unsignedInteger: BigUInt(hexEncodedString: hexEncodedSeed)!, minimumLength: 32)
let privateMasterKey = sut.privateKey(seed: seed)
XCTAssertEqual(BigUInt(privateMasterKey), BigUInt(privateMasterKeys[index]))
}
Expand Down

0 comments on commit 4aa455e

Please sign in to comment.