From ec0d211c364211552b272005a5129b5025c8335f Mon Sep 17 00:00:00 2001 From: anquii <50277099+anquii@users.noreply.github.com> Date: Mon, 25 Jul 2022 12:36:14 +0100 Subject: [PATCH] Added tests --- Package.resolved | 8 +- Package.swift | 6 +- README.md | 13 +- Tests/BLSCTTests/AddressCoderTests.swift | 40 ++++++ .../Data/AddressCoderTestData.swift | 86 ++++++++++++ .../Data/PrivateBLSKeysTestData.swift | 38 +++++ .../Data/PrivateBLSMasterKeyTestData.swift | 22 +++ .../PrivateBLSSpendKeyCoderTestData.swift | 22 +++ .../Data/PrivateBLSViewKeyCoderTestData.swift | 22 +++ .../Data/PublicBLSKeysTestData.swift | 130 ++++++++++++++++++ .../Helpers/AddressCoderTestVector.swift | 5 + .../PrivateBLSKeyCoderTestVector.swift | 4 + .../Helpers/PrivateBLSKeysTestVector.swift | 8 ++ .../PrivateBLSMasterKeyTestVector.swift | 4 + ...ublicBLSKeysTestVector+DerivatedKeys.swift | 8 ++ .../Helpers/PublicBLSKeysTestVector.swift | 6 + .../PrivateBLSChildKeyDerivatorTests.swift | 65 +++++++++ .../PrivateBLSKeysDerivatorTests.swift | 40 ++++++ .../PrivateBLSMasterKeyDerivatorTests.swift | 28 ++++ .../PrivateBLSSpendKeyCoderTests.swift | 37 +++++ .../PrivateBLSViewKeyCoderTests.swift | 37 +++++ .../PublicBLSKeysDerivatorTests.swift | 38 +++++ 22 files changed, 659 insertions(+), 8 deletions(-) create mode 100644 Tests/BLSCTTests/AddressCoderTests.swift create mode 100644 Tests/BLSCTTests/Data/AddressCoderTestData.swift create mode 100644 Tests/BLSCTTests/Data/PrivateBLSKeysTestData.swift create mode 100644 Tests/BLSCTTests/Data/PrivateBLSMasterKeyTestData.swift create mode 100644 Tests/BLSCTTests/Data/PrivateBLSSpendKeyCoderTestData.swift create mode 100644 Tests/BLSCTTests/Data/PrivateBLSViewKeyCoderTestData.swift create mode 100644 Tests/BLSCTTests/Data/PublicBLSKeysTestData.swift create mode 100644 Tests/BLSCTTests/Helpers/AddressCoderTestVector.swift create mode 100644 Tests/BLSCTTests/Helpers/PrivateBLSKeyCoderTestVector.swift create mode 100644 Tests/BLSCTTests/Helpers/PrivateBLSKeysTestVector.swift create mode 100644 Tests/BLSCTTests/Helpers/PrivateBLSMasterKeyTestVector.swift create mode 100644 Tests/BLSCTTests/Helpers/PublicBLSKeysTestVector+DerivatedKeys.swift create mode 100644 Tests/BLSCTTests/Helpers/PublicBLSKeysTestVector.swift create mode 100644 Tests/BLSCTTests/PrivateBLSChildKeyDerivatorTests.swift create mode 100644 Tests/BLSCTTests/PrivateBLSKeysDerivatorTests.swift create mode 100644 Tests/BLSCTTests/PrivateBLSMasterKeyDerivatorTests.swift create mode 100644 Tests/BLSCTTests/PrivateBLSSpendKeyCoderTests.swift create mode 100644 Tests/BLSCTTests/PrivateBLSViewKeyCoderTests.swift create mode 100644 Tests/BLSCTTests/PublicBLSKeysDerivatorTests.swift diff --git a/Package.resolved b/Package.resolved index a996ab0..03250e1 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/anquii/Base58.git", "state": { "branch": null, - "revision": "520bbd9f8800e101f93453d1429881b6b4cb7a38", - "version": "1.0.0" + "revision": "7e4a1e4e6813c750ed2f9e80a0494c608eebb2ca", + "version": "1.0.1" } }, { @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/anquii/Base58Check.git", "state": { "branch": null, - "revision": "133f9d4e4f1d47002e8d6ae85152ab57f4098e92", - "version": "1.0.0" + "revision": "f35a770ff7f3fd553cc44057f492c0107cc7b481", + "version": "1.0.1" } }, { diff --git a/Package.swift b/Package.swift index 1704c0c..d065853 100644 --- a/Package.swift +++ b/Package.swift @@ -17,15 +17,15 @@ let package = Package( dependencies: [ .package( url: "https://github.com/anquii/Base58Check.git", - .upToNextMajor(from: "1.0.0") + .exact("1.0.1") ), .package( url: "https://github.com/attaswift/BigInt.git", - .upToNextMajor(from: "5.3.0") + .exact("5.3.0") ), .package( url: "https://github.com/anquii/CryptoSwiftWrapper.git", - .upToNextMajor(from: "1.4.3") + .exact("1.4.3") ), .package( url: "https://github.com/anquii/MCLSwiftWrapper.git", diff --git a/README.md b/README.md index 8692ff1..065d03d 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ An implementation of [BLSCT](https://docs.navcoin.org/blsct) in Swift. BLSCT is Add the following line to your `Package.swift` file: ```swift -.package(url: "https://github.com/anquii/BLSCT.git", from: "1.0.0") +.package(url: "https://github.com/anquii/BLSCT.git", from: "0.1.0") ``` ...or integrate with Xcode via `File -> Swift Packages -> Add Package Dependency...` using the URL of the repository. @@ -48,3 +48,14 @@ Find out more by exploring the public API, and by looking through the [tests](Te ## License `BLSCT` is licensed under the terms of the MIT license. See the [LICENSE](LICENSE) file for more information. + +## Donations + +If you've found this software useful, please consider making a small contribution to one of these crypto addresses: + +``` +XNAV: xNTYqoQDzsiB5Cff9Wpt65AgZxYkt1GFy7KwuDafqRU2bcAZqoZUW4Q9TZ9QRHSy8cPsM5ALkJasizJCmqSNP9CosxrF2RbKHuDz5uJVUBcKJfvnb3RZaWygr8Bhuqbpc3DsgfB3ayc +XMR: 49jzT7Amu9BCvc5q3PGiUzWXEBQTLQw68a2KvBFTMs7SHjeWgrSKgxs69ycFWQupyw9fpR6tdT8Hp5h3KksrBG9m4c8aXiG +BTC: bc1q7hehfmnq67x5k7vz0cnc75qyflkqtxe2avjkyw +ETH (ERC-20) & BNB (BEP-20): 0xe08e383B4042749dE5Df57d48c57A690DC322b8d +``` diff --git a/Tests/BLSCTTests/AddressCoderTests.swift b/Tests/BLSCTTests/AddressCoderTests.swift new file mode 100644 index 0000000..c9f22a3 --- /dev/null +++ b/Tests/BLSCTTests/AddressCoderTests.swift @@ -0,0 +1,40 @@ +import Foundation +import XCTest +import BLSCT + +final class AddressCoderTests: XCTestCase { + private let jsonDecoder = JSONDecoder() + private var testVectors: [AddressCoderTestVector]! + + override func setUpWithError() throws { + testVectors = try jsonDecoder.decode([AddressCoderTestVector].self, from: addressCoderTestData) + } + + private func sut() -> AddressCoder { + .init() + } + + func testGivenPublicBLSKeys_WhenEncode_ThenEqualVectorAddress() { + let sut = self.sut() + + for testVector in testVectors { + let publicBLSViewKey = Data(hex: testVector.hexEncodedPublicBLSViewKey) + let publicBLSSpendKey = Data(hex: testVector.hexEncodedPublicBLSSpendKey) + let address = sut.address(publicBLSViewKey: publicBLSViewKey, publicBLSSpendKey: publicBLSSpendKey) + XCTAssertEqual(address.count, 139) + XCTAssertEqual(address, testVector.address) + } + } + + func testGivenAddress_WhenDecode_ThenEqualVectorKeys() throws { + let sut = self.sut() + + for testVector in testVectors { + let publicKeys = try sut.publicBLSKeys(address: testVector.address) + XCTAssertEqual(publicKeys.publicBLSViewKey.count, 48) + XCTAssertEqual(publicKeys.publicBLSSpendKey.count, 48) + XCTAssertEqual(publicKeys.publicBLSViewKey.toHexString(), testVector.hexEncodedPublicBLSViewKey) + XCTAssertEqual(publicKeys.publicBLSSpendKey.toHexString(), testVector.hexEncodedPublicBLSSpendKey) + } + } +} diff --git a/Tests/BLSCTTests/Data/AddressCoderTestData.swift b/Tests/BLSCTTests/Data/AddressCoderTestData.swift new file mode 100644 index 0000000..9a6836a --- /dev/null +++ b/Tests/BLSCTTests/Data/AddressCoderTestData.swift @@ -0,0 +1,86 @@ +let addressCoderTestData = + """ + [ + { + "hexEncodedPublicBLSViewKey": "aff0c2dde21df8f0a7ba7285b179fe500778e4cd19c64b5572490d86211dbb64817655dc5e348827d061f8dc88c00186", + "hexEncodedPublicBLSSpendKey": "a17bc42b7a5f3776d38d2dc29c9746374290fe47413e45bab4172ae0bd1a288c0641bedca79ba0dc36c842d2e8af4e93", + "address": "xNVM1yykP9cSc737VCMzP8kWR77gPn1iujPitHRm6urfrVRDLbNinxsRTZb3CCsYCD3Uqj3RCQubEYaHj3XKmGMbFTDctT2JVJ6CCazXomPmoiPGB3qf8rfKp7NEyzKupjeSD4CfkKS" + }, + { + "hexEncodedPublicBLSViewKey": "90b69b9b87865ef6cd0c456711aa13c80d65046eee69473415b60a945c001e8324449949952175c3402622b1c3031659", + "hexEncodedPublicBLSSpendKey": "a37f432bca6a210867fcc93230db4d769a283ef85854a357bc5607c340ed2e3be98195073abb5f17de8a4bf458253311", + "address": "xNU8dNaLPMaFU7uw9MWc3yWq4cnhDRhvE2os8fS2QdokzVGhhiLBWtMpB1ffDfXbjfiqhDS3gSisrAhiWSqMAVkRiqTGBQaEzyaSd8eNa7UdyMCqhy4Sf1khDNfR3ABnoXjZJR5eyds" + }, + { + "hexEncodedPublicBLSViewKey": "b88ab03a64ed626661a939d29b5c153c7c3b1e40b6c60e475ee8fc7acb73bd0dd113859cf0256fdff8018c0659da7e12", + "hexEncodedPublicBLSSpendKey": "a32e0640de22a136cc4ceb408e341c90ba040d7ff3893445a9a32fa9b90129b2f2975b2a4770896e4b4a94181ad36ab3", + "address": "xNVgQWKn4sUFt2rsUaNvgUH3j851tSigC4UqVdRasH59uiY7G1ehsx4kVJHUQXc4gTfY3su2ENg5WphzowCJ8asGhzjM37T33smsmUBUvyzRCHo59ufoSnTArun9YjzWadd7bHqxTRw" + }, + { + "hexEncodedPublicBLSViewKey": "9018a31b070bc32a09a0984a2221caab49edbf684e5f4f6f77691cdb17ec0d645bf303dcab09b8e6c7ae6af7b37dd03a", + "hexEncodedPublicBLSSpendKey": "ad439a0cdf15cd36fa8498fdf6e995e198ef3a8279a214a3aae10bb71dbcbed6a59279b60dc825409a685b252497ddd2", + "address": "xNU7EhPiqBxmJwgxFwsAK2a99bM1AftGuMB6aWecA17UQFU2AqLjXtvJ7bwqBfC12NAaEiWvuu2Pq2a3WTsxBxVhCtUAzoiBdkb2XTYEzirZrLLWhvDtQ25D18Gg5dTgynkbUwYLxkR" + }, + { + "hexEncodedPublicBLSViewKey": "8fcb202936603bc80bc1668a826a22ee32e4322de98cda11b89f07573828ef9ea6391ab03e1978a444768e552168b267", + "hexEncodedPublicBLSSpendKey": "b060aafd63da3e7d5858f7f2bef697580172af7f59acd939bbd26bbc355a1682ed147db9edd538d3c80c4695b2f40bbf", + "address": "xNU6Z7TV6MuXNH83nWYxMpa1PkbSbVzkL73Hm5S8ePvFrpFK44L3gdyey5SXjjecv9jgvzFahCvnZGiLfw7R3B5oj3aTZDt3XXdi6BX994BbFUQ36TNjuEMoFxdBtczv1A1dMepNF2y" + }, + { + "hexEncodedPublicBLSViewKey": "92480141671026f39007da5cfec977ac757eabaaff4e28b03aacaff80e86d4385c0877304d325af363c814cfb974613c", + "hexEncodedPublicBLSSpendKey": "a5122654f2ef4f7602cab1e477f09eee7642b375b7ca72b5d82699f978457efc6999ebc3e3b98f6ddb2d1d120e48906a", + "address": "xNUCANBmqz6fLjk9YamdFAhnm7LuZ4hpvCUagVuVmHtFCcLK95NhDEKzGZuFJaLLp4XCDvyPw2eL4rjgNLLN4zBwS2WEEL9HyrDeMhhjhbWUDoK684JzrxAhmYuNyEDKgsygdLLc7TR" + }, + { + "hexEncodedPublicBLSViewKey": "afe7e91fea48e99e0bdcca4a2fb2bdaa00bb23a2db9e82e0527408e45fa436b436ceea4d020f73ec9e3e2160d8adcc20", + "hexEncodedPublicBLSSpendKey": "84a649e41e20d1e0e23685ca42bf2ac30740206bc7f516de13632694655b7deb34db95f1365c9247c804c4698a1af701", + "address": "xNVLwTpZA79gs625KEnW7UeKLVyyrsvydqvqwNFYQVSMXhxv9NfwA6wygF5wtSU839CAXhvaqMaqfn7wqGYNPG2KGyNZqFjir14vX82dUAS9AJsTdq9jZRnMjzr3WVGudA7aUnS3N48" + }, + { + "hexEncodedPublicBLSViewKey": "933cf2c13f5c5071eb5f2fd980b69addee5e8821f8ff17c3d1af8f44fef5d7eaba100b4cf1e94eace3ce175bc6ad1ca2", + "hexEncodedPublicBLSSpendKey": "a7eb11946de0244cc9f1224d060bc52912b86926423756730314cc47ee3c8c2251a1ac5e9efdd379c908a262ff8e6417", + "address": "xNUEKTYoepDgMqjzB5KU4y5oc23vBibJJ8JzjUXoxDF3veHNRLmWugyHhYxp7kbAjsoZ9THyE8r55Eqvp1kTxTaNQrtefHqjkyQ5tNDWdeBEnitpak4jZp3Z3KonFjbbYN7KgXiFbuJ" + }, + { + "hexEncodedPublicBLSViewKey": "8a26396587274046649afbb9b95042e94901bc379b9b5dc39d17ded7a02f9a8bfd8a9e60e2c2c3e83578ab6c6ae9b101", + "hexEncodedPublicBLSSpendKey": "aaf434b56f9795916c6c64ee9933840fadf52c3351ae74c150f450b3b804df52878d7052683d373636cd5c8e83c458c5", + "address": "xNTsqCecJLg7zoi9BXvTQTWKY7whTCnxgmbb9HrRXdZ1gyeTEjwD4HLujcP48y1QHvKgVwhdGvYzDYAiBr7LRLXaKq5h1Dxhvpd7UhEzarnj5VjTFgob6DDQ7uyyUgPCGY232b7eJoh" + }, + { + "hexEncodedPublicBLSViewKey": "890d4e789b81926974fe4c903c22e6a884735819dcd63b77f3e5fa79bb88ea2e955a0e4fb499a1c0d737f0f32429e301", + "hexEncodedPublicBLSSpendKey": "ad44bdb8bc4ba79bffbca430549904ed5d6dfda973fbe146b5576d60abe86d5de4e041791d8602728a932174d613e6a8", + "address": "xNTqMjhwPzcjwgB8t16kpPeBucfgJyBnHcnGuMDVYnqtddcpVTT6cSySwAKfpCrUxam5cpyzbXNjHiS23FeTX7yFFpmMjzT3VgsaytkzeBYEXGP2wgY4dYpCWqz3DvU3wA4ccU2L1iX" + }, + { + "hexEncodedPublicBLSViewKey": "b340237751831ff4be8266138a475386233adf2e660d89738a262b4ffd5e1d3d4ef9ac2a81cda680353799abbe34a6ff", + "hexEncodedPublicBLSSpendKey": "81e25c4409383a49e258124fb738b051b7b19fa9bb70f9b1c4e0f34cd7992bda2442d5066cfbcf1c61aa95cb05ba1d54", + "address": "xNVUUjnHrrjQnHzkVADrWHjdMKF99nqLyYwDGsECxmFqd9mHozQcG2qo7Byx5yLZtKGMeQVbcvctdGcjTUd7SZKgQqxHPwT6or7iRrdRVFYXZauU77SLj7796WxjopGgbtHUgyb9ZYB" + }, + { + "hexEncodedPublicBLSViewKey": "8c2334af55448e8a18b0d5100d4c0e15be781d095db126c83ee20df4afe7a14c491515d5b8a9a167fb3cedaeb734fe66", + "hexEncodedPublicBLSSpendKey": "aff4a5b5d7511498df1e0983ed1debb32d6c600123d06b0ff72161ea2df3bb55fc5cf0d7410f5189f6290cdd47a6ecfe", + "address": "xNTxK8yYjrKQAxWuWF46ATMb71waCZykMKgWjnUdvTn992SGBy8ZhWVujbqqe5voXqYrDjx7Ua3FhWyJnzF9cMZ1jN3vFWDgabGfqUE3hA9unBCQRfNBVehXs6CeeEW27YLVvxExxw2" + }, + { + "hexEncodedPublicBLSViewKey": "83772435fc7eeb60076b4da79a5903aff0c506c61174f54621313d6b0bc422b247f29827662bc4a5843148732fd63db9", + "hexEncodedPublicBLSSpendKey": "b2c786f06cd5ff019491249346a2865db362196376b5c1f072390f37e5c41d19c0201ab1ae56502b913b85af67f7eee3", + "address": "xNTcmMQ17yhkhGX1hg2eHnegNSQqbznoUjqiSQ17UYpcZnuSCMykCPmpaYQcccFPHVx6Dtn2Y2UeSCw8Z1C7CaK7rbKb8XEpjDYz2GswsyGhtgxuyvXRK7DCDaJRLr3Txe18qm9WxBG" + }, + { + "hexEncodedPublicBLSViewKey": "b918f0ec7512bd9e0ff25e7d9c4cabb467b5ac47b3e59cdef6d0bc2f0c72f6abb21d2c4608b8dd2f9b21420666c492ca", + "hexEncodedPublicBLSSpendKey": "94c10c5670686989466b641a88ac28131876173502e75a8ef1f50816fe8d3e22bb87fd7976887e0335d3cdc24f22bf0b", + "address": "xNVhf9vz1uF6TMoLKBvQdt1VfPnBwZq54v55gdURRmGzE2KHWBbZXiJBp28hgGtmT7BLtuxDJGccTPFGPtqQjsxrxRvDgpfqx664kRMzQqpurfr7TRgqzBG54hJuHXP2g8ZFZFuSH7f" + }, + { + "hexEncodedPublicBLSViewKey": "aa4b94053fa36086d0e9d574e198c1d8facd10a31a8cb427f5e2d825d9ce534496a085a8b15cfd52b9d9b1859274ec52", + "hexEncodedPublicBLSSpendKey": "a8388f52d42c44c4e6014578aa1ef396ca3efe3645244d4f0ccc5619223b3ff1e3d6a2490f80f4bedfc01a54e6a9ec4c", + "address": "xNV8Hvq8yGWfhM9nJyMqNGp7EFV5FSvJ3R7YHnxTaDQa8Zw8v93CNSnp3D9Hprh31TwQM3KXr2mXszcYTPTFT2Cb8a1fJmSK8axh5WtNawTbJ4GmYD6AY8KoyWX5qAPmaTB6UU7uDZ9" + }, + { + "hexEncodedPublicBLSViewKey": "ac69a4fcfc1da57eb1082e73a79acc73fcdf3ada7963ef015f7cd782fd26a621a765b4408c8374ee22cb6787e2470da3", + "hexEncodedPublicBLSSpendKey": "b0aa91c25ed02fca2838105def44764264cdbbc2d8f0eb3f32b1722efc7197c810f2c5f6fa3b9c93c4c953be3a5ded81", + "address": "xNVD4m9LozPqwoH5rCEH2N8JpY1FoRNJLomyXkeh1Z4aBSfQGZSaRR4fa21FXc8qE5Hxpb1bzngnySnFrujuB14m2wp2bBHg9KyUmTsQov5Heh3AeuBvWC1m6trp6xM8LECgnW2YkKy" + } + ] + """ + .data(using: .utf8)! diff --git a/Tests/BLSCTTests/Data/PrivateBLSKeysTestData.swift b/Tests/BLSCTTests/Data/PrivateBLSKeysTestData.swift new file mode 100644 index 0000000..1199907 --- /dev/null +++ b/Tests/BLSCTTests/Data/PrivateBLSKeysTestData.swift @@ -0,0 +1,38 @@ +let privateBLSKeysTestData = + """ + [ + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi", + "hexEncodedPrivateBLSChildKey": "081dacecca37bcb9061ece1d97844d1c46b8089ce63e3911161e56f02a54226f", + "hexEncodedPrivateBLSTransactionKey": "57de5f4e4e2b1c32f1b8f1fd3430ac1d1147e36d2729be2e6a2b13cab3251e5e", + "hexEncodedPrivateBLSBlindingKey": "45a6eda9f9131f1ddf9db479debfb7d9e70f2b460b18b0ee14af9e5495b9fb3a", + "hexEncodedPrivateBLSViewKey": "4bf686517b7fadd436294c5ead4b7fe0c64baef0ea93d8859059ad79f4281013", + "hexEncodedPrivateBLSSpendKey": "1f378e73042bd6da28cdecbfda30b7718dc2f6e2a46e2ef3e42bb5a4658dad7a" + }, + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U", + "hexEncodedPrivateBLSChildKey": "658cf89e7a75c1258135ef6a672b0cc9a7e00630796f764ac8599e3f9aa3453f", + "hexEncodedPrivateBLSTransactionKey": "1cc664da6090334e4dca3f523c377c5d3307bdf09ba6915c75785c6b776c4575", + "hexEncodedPrivateBLSBlindingKey": "43dcb6bbdea116eb9cda305929a627e9729cab7eec7085b5c9a9fb2c66c6b597", + "hexEncodedPrivateBLSViewKey": "3af779d95b1e5259b4f4342530c041a903f6d3aa6d56b7e5f143980072931aa0", + "hexEncodedPrivateBLSSpendKey": "051d2862b5cea181362a22f63f36a170d08d3850ff381cd07303741c9ae42fc1" + }, + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K25QhxbucbDDuQ4naNntJRi4KUfWT7xo4EKsHt2QJDu7KXp1A3u7Bi1j8ph3EGsZ9Xvz9dGuVrtHHs7pXeTzjuxBrCmmhgC6", + "hexEncodedPrivateBLSChildKey": "6c25a57b6dd3312207daa6e37639d6aa9476cc1e20e1e1a05acbfb5e893e25cb", + "hexEncodedPrivateBLSTransactionKey": "68d15caaecf8f59dae42300aa2f577a12a7b59fefa1bae4071ebb9638cbe03df", + "hexEncodedPrivateBLSBlindingKey": "06785bb75c7f2d4690dcd80f19a105d43e105f5487ff21f723154df9f82915f6", + "hexEncodedPrivateBLSViewKey": "36f5f6f357f3788ec0076514c924f473a95853c1c40dd1923ff44854f4f91fe7", + "hexEncodedPrivateBLSSpendKey": "21ab3667aae235d13c25f889825059c2491885b2dbceb321c4926d509e87184c" + }, + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K48vGoLGRPxgo2JNkJ3J3fqkirQC2zVdk5Dgd5w14S7fRDyHH4dWNHUgkvsvNDCkvAwcSHNAQwhwgNMgZhLtQC63zxwhQmRv", + "hexEncodedPrivateBLSChildKey": "6ae03ce15c8ebb83cf4548b4b2c2405aa33a04001f31f59e5209e068ebaedea6", + "hexEncodedPrivateBLSTransactionKey": "10514c2793e6d519da3580416ed345332f33978c4f32c31162168fb8a6697b91", + "hexEncodedPrivateBLSBlindingKey": "22808f7cceb43b73602ec3d71f7d49f8526f47c1203fa9d767a53690c6f4454c", + "hexEncodedPrivateBLSViewKey": "006fb8584162c699a8e14c7dd6028be2b6e972be1f76d86c2816f02e82046283", + "hexEncodedPrivateBLSSpendKey": "32181fa1c2d421d08a0e25dfdeaff8cb22f4f0b9d1cd02c33cb2a7f0ccc79b38" + } + ] + """ + .data(using: .utf8)! diff --git a/Tests/BLSCTTests/Data/PrivateBLSMasterKeyTestData.swift b/Tests/BLSCTTests/Data/PrivateBLSMasterKeyTestData.swift new file mode 100644 index 0000000..0628d92 --- /dev/null +++ b/Tests/BLSCTTests/Data/PrivateBLSMasterKeyTestData.swift @@ -0,0 +1,22 @@ +let privateBLSMasterKeyTestData = + """ + [ + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi", + "hexEncodedPrivateBLSMasterKey": "00be8cacc5eba3f5fc74c495467054bfa37f75e5f66ca274472156d59dbeb249" + }, + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U", + "hexEncodedPrivateBLSMasterKey": "59e8fed087cce9fae04b9fd20f706308e7341064b276a0dc7a1a1ee269278148" + }, + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K25QhxbucbDDuQ4naNntJRi4KUfWT7xo4EKsHt2QJDu7KXp1A3u7Bi1j8ph3EGsZ9Xvz9dGuVrtHHs7pXeTzjuxBrCmmhgC6", + "hexEncodedPrivateBLSMasterKey": "6ede82a09c34e9b42179cedae9974c39275c4ff6404fde8895bae3f42afae448" + }, + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K48vGoLGRPxgo2JNkJ3J3fqkirQC2zVdk5Dgd5w14S7fRDyHH4dWNHUgkvsvNDCkvAwcSHNAQwhwgNMgZhLtQC63zxwhQmRv", + "hexEncodedPrivateBLSMasterKey": "62f85deb5076888f9b8bdde51c28ad192af43a9c1992926f8105ccd791820aac" + } + ] + """ + .data(using: .utf8)! diff --git a/Tests/BLSCTTests/Data/PrivateBLSSpendKeyCoderTestData.swift b/Tests/BLSCTTests/Data/PrivateBLSSpendKeyCoderTestData.swift new file mode 100644 index 0000000..936cb84 --- /dev/null +++ b/Tests/BLSCTTests/Data/PrivateBLSSpendKeyCoderTestData.swift @@ -0,0 +1,22 @@ +let privateBLSSpendKeyCoderTestData = + """ + [ + { + "hexEncodedPrivateBLSKey": "1f378e73042bd6da28cdecbfda30b7718dc2f6e2a46e2ef3e42bb5a4658dad7a", + "base58CheckEncodedPrivateBLSKey": "PVoxYTRamJ2Gs9GqSZRCT4VPYA6cEDzk3wRrRTAs4DFgoiMHkaZe" + }, + { + "hexEncodedPrivateBLSKey": "051d2862b5cea181362a22f63f36a170d08d3850ff381cd07303741c9ae42fc1", + "base58CheckEncodedPrivateBLSKey": "PVom3gp7qtcGLCbCBRDa41wGhbFAgvBNCFtRUzcrKfvY2T1AWW6b" + }, + { + "hexEncodedPrivateBLSKey": "21ab3667aae235d13c25f889825059c2491885b2dbceb321c4926d509e87184c", + "base58CheckEncodedPrivateBLSKey": "PVoyd5pPWPcWQtVFMmobzBVaLDdYzPS5JHfBHMLEk1w4HwBGTkUv" + }, + { + "hexEncodedPrivateBLSKey": "32181fa1c2d421d08a0e25dfdeaff8cb22f4f0b9d1cd02c33cb2a7f0ccc79b38", + "base58CheckEncodedPrivateBLSKey": "PVp6redGbCFT6wYKWr18ahcNV6ao45P2SW825LMyhNa2Kajo6uJG" + } + ] + """ + .data(using: .utf8)! diff --git a/Tests/BLSCTTests/Data/PrivateBLSViewKeyCoderTestData.swift b/Tests/BLSCTTests/Data/PrivateBLSViewKeyCoderTestData.swift new file mode 100644 index 0000000..1c21291 --- /dev/null +++ b/Tests/BLSCTTests/Data/PrivateBLSViewKeyCoderTestData.swift @@ -0,0 +1,22 @@ +let privateBLSViewKeyCoderTestData = + """ + [ + { + "hexEncodedPrivateBLSKey": "4bf686517b7fadd436294c5ead4b7fe0c64baef0ea93d8859059ad79f4281013", + "base58CheckEncodedPrivateBLSKey": "PSddXfzLKn6SvZktqN4yHmhK6pWPgQRn7ojndXCEgzr7rrkMQ9VM" + }, + { + "hexEncodedPrivateBLSKey": "3af779d95b1e5259b4f4342530c041a903f6d3aa6d56b7e5f143980072931aa0", + "base58CheckEncodedPrivateBLSKey": "PSdW3XSwQ7u2fL3JBmrpKddRQMMb7CgZHBWfY6yPhqSLbcS78R3k" + }, + { + "hexEncodedPrivateBLSKey": "36f5f6f357f3788ec0076514c924f473a95853c1c40dd1923ff44854f4f91fe7", + "base58CheckEncodedPrivateBLSKey": "PSdUHCaBu9mwkF8VKVF2n7Qm6hTpERhQg7czECQ7Q6xCmaiqN4YM" + }, + { + "hexEncodedPrivateBLSKey": "006fb8584162c699a8e14c7dd6028be2b6e972be1f76d86c2816f02e82046283", + "base58CheckEncodedPrivateBLSKey": "PSd4GSvzwD3QjoZsAhxG8GqW1QbftP4htjtqezDatUpTda8qtX5V" + } + ] + """ + .data(using: .utf8)! diff --git a/Tests/BLSCTTests/Data/PublicBLSKeysTestData.swift b/Tests/BLSCTTests/Data/PublicBLSKeysTestData.swift new file mode 100644 index 0000000..b196426 --- /dev/null +++ b/Tests/BLSCTTests/Data/PublicBLSKeysTestData.swift @@ -0,0 +1,130 @@ +let publicBLSKeysTestData = + """ + [ + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi", + "hexEncodedPrivateBLSViewKey": "4bf686517b7fadd436294c5ead4b7fe0c64baef0ea93d8859059ad79f4281013", + "hexEncodedPrivateBLSSpendKey": "1f378e73042bd6da28cdecbfda30b7718dc2f6e2a46e2ef3e42bb5a4658dad7a", + "derivatedKeys": [ + { + "accountIndex": 0, + "subAddressIndex": 0, + "hexEncodedPublicBLSViewKey": "aff0c2dde21df8f0a7ba7285b179fe500778e4cd19c64b5572490d86211dbb64817655dc5e348827d061f8dc88c00186", + "hexEncodedPublicBLSSpendKey": "a17bc42b7a5f3776d38d2dc29c9746374290fe47413e45bab4172ae0bd1a288c0641bedca79ba0dc36c842d2e8af4e93" + }, + { + "accountIndex": 0, + "subAddressIndex": 1, + "hexEncodedPublicBLSViewKey": "90b69b9b87865ef6cd0c456711aa13c80d65046eee69473415b60a945c001e8324449949952175c3402622b1c3031659", + "hexEncodedPublicBLSSpendKey": "a37f432bca6a210867fcc93230db4d769a283ef85854a357bc5607c340ed2e3be98195073abb5f17de8a4bf458253311" + }, + { + "accountIndex": 1, + "subAddressIndex": 0, + "hexEncodedPublicBLSViewKey": "b88ab03a64ed626661a939d29b5c153c7c3b1e40b6c60e475ee8fc7acb73bd0dd113859cf0256fdff8018c0659da7e12", + "hexEncodedPublicBLSSpendKey": "a32e0640de22a136cc4ceb408e341c90ba040d7ff3893445a9a32fa9b90129b2f2975b2a4770896e4b4a94181ad36ab3" + }, + { + "accountIndex": 1, + "subAddressIndex": 1, + "hexEncodedPublicBLSViewKey": "9018a31b070bc32a09a0984a2221caab49edbf684e5f4f6f77691cdb17ec0d645bf303dcab09b8e6c7ae6af7b37dd03a", + "hexEncodedPublicBLSSpendKey": "ad439a0cdf15cd36fa8498fdf6e995e198ef3a8279a214a3aae10bb71dbcbed6a59279b60dc825409a685b252497ddd2" + } + ] + }, + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U", + "hexEncodedPrivateBLSViewKey": "3af779d95b1e5259b4f4342530c041a903f6d3aa6d56b7e5f143980072931aa0", + "hexEncodedPrivateBLSSpendKey": "051d2862b5cea181362a22f63f36a170d08d3850ff381cd07303741c9ae42fc1", + "derivatedKeys": [ + { + "accountIndex": 0, + "subAddressIndex": 0, + "hexEncodedPublicBLSViewKey": "8fcb202936603bc80bc1668a826a22ee32e4322de98cda11b89f07573828ef9ea6391ab03e1978a444768e552168b267", + "hexEncodedPublicBLSSpendKey": "b060aafd63da3e7d5858f7f2bef697580172af7f59acd939bbd26bbc355a1682ed147db9edd538d3c80c4695b2f40bbf" + }, + { + "accountIndex": 0, + "subAddressIndex": 1, + "hexEncodedPublicBLSViewKey": "92480141671026f39007da5cfec977ac757eabaaff4e28b03aacaff80e86d4385c0877304d325af363c814cfb974613c", + "hexEncodedPublicBLSSpendKey": "a5122654f2ef4f7602cab1e477f09eee7642b375b7ca72b5d82699f978457efc6999ebc3e3b98f6ddb2d1d120e48906a" + }, + { + "accountIndex": 1, + "subAddressIndex": 0, + "hexEncodedPublicBLSViewKey": "afe7e91fea48e99e0bdcca4a2fb2bdaa00bb23a2db9e82e0527408e45fa436b436ceea4d020f73ec9e3e2160d8adcc20", + "hexEncodedPublicBLSSpendKey": "84a649e41e20d1e0e23685ca42bf2ac30740206bc7f516de13632694655b7deb34db95f1365c9247c804c4698a1af701" + }, + { + "accountIndex": 1, + "subAddressIndex": 1, + "hexEncodedPublicBLSViewKey": "933cf2c13f5c5071eb5f2fd980b69addee5e8821f8ff17c3d1af8f44fef5d7eaba100b4cf1e94eace3ce175bc6ad1ca2", + "hexEncodedPublicBLSSpendKey": "a7eb11946de0244cc9f1224d060bc52912b86926423756730314cc47ee3c8c2251a1ac5e9efdd379c908a262ff8e6417" + } + ] + }, + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K25QhxbucbDDuQ4naNntJRi4KUfWT7xo4EKsHt2QJDu7KXp1A3u7Bi1j8ph3EGsZ9Xvz9dGuVrtHHs7pXeTzjuxBrCmmhgC6", + "hexEncodedPrivateBLSViewKey": "36f5f6f357f3788ec0076514c924f473a95853c1c40dd1923ff44854f4f91fe7", + "hexEncodedPrivateBLSSpendKey": "21ab3667aae235d13c25f889825059c2491885b2dbceb321c4926d509e87184c", + "derivatedKeys": [ + { + "accountIndex": 0, + "subAddressIndex": 0, + "hexEncodedPublicBLSViewKey": "8a26396587274046649afbb9b95042e94901bc379b9b5dc39d17ded7a02f9a8bfd8a9e60e2c2c3e83578ab6c6ae9b101", + "hexEncodedPublicBLSSpendKey": "aaf434b56f9795916c6c64ee9933840fadf52c3351ae74c150f450b3b804df52878d7052683d373636cd5c8e83c458c5" + }, + { + "accountIndex": 0, + "subAddressIndex": 1, + "hexEncodedPublicBLSViewKey": "890d4e789b81926974fe4c903c22e6a884735819dcd63b77f3e5fa79bb88ea2e955a0e4fb499a1c0d737f0f32429e301", + "hexEncodedPublicBLSSpendKey": "ad44bdb8bc4ba79bffbca430549904ed5d6dfda973fbe146b5576d60abe86d5de4e041791d8602728a932174d613e6a8" + }, + { + "accountIndex": 1, + "subAddressIndex": 0, + "hexEncodedPublicBLSViewKey": "b340237751831ff4be8266138a475386233adf2e660d89738a262b4ffd5e1d3d4ef9ac2a81cda680353799abbe34a6ff", + "hexEncodedPublicBLSSpendKey": "81e25c4409383a49e258124fb738b051b7b19fa9bb70f9b1c4e0f34cd7992bda2442d5066cfbcf1c61aa95cb05ba1d54" + }, + { + "accountIndex": 1, + "subAddressIndex": 1, + "hexEncodedPublicBLSViewKey": "8c2334af55448e8a18b0d5100d4c0e15be781d095db126c83ee20df4afe7a14c491515d5b8a9a167fb3cedaeb734fe66", + "hexEncodedPublicBLSSpendKey": "aff4a5b5d7511498df1e0983ed1debb32d6c600123d06b0ff72161ea2df3bb55fc5cf0d7410f5189f6290cdd47a6ecfe" + } + ] + }, + { + "base58CheckEncodedPrivateMasterKey": "xprv9s21ZrQH143K48vGoLGRPxgo2JNkJ3J3fqkirQC2zVdk5Dgd5w14S7fRDyHH4dWNHUgkvsvNDCkvAwcSHNAQwhwgNMgZhLtQC63zxwhQmRv", + "hexEncodedPrivateBLSViewKey": "006fb8584162c699a8e14c7dd6028be2b6e972be1f76d86c2816f02e82046283", + "hexEncodedPrivateBLSSpendKey": "32181fa1c2d421d08a0e25dfdeaff8cb22f4f0b9d1cd02c33cb2a7f0ccc79b38", + "derivatedKeys": [ + { + "accountIndex": 0, + "subAddressIndex": 0, + "hexEncodedPublicBLSViewKey": "83772435fc7eeb60076b4da79a5903aff0c506c61174f54621313d6b0bc422b247f29827662bc4a5843148732fd63db9", + "hexEncodedPublicBLSSpendKey": "b2c786f06cd5ff019491249346a2865db362196376b5c1f072390f37e5c41d19c0201ab1ae56502b913b85af67f7eee3" + }, + { + "accountIndex": 0, + "subAddressIndex": 1, + "hexEncodedPublicBLSViewKey": "b918f0ec7512bd9e0ff25e7d9c4cabb467b5ac47b3e59cdef6d0bc2f0c72f6abb21d2c4608b8dd2f9b21420666c492ca", + "hexEncodedPublicBLSSpendKey": "94c10c5670686989466b641a88ac28131876173502e75a8ef1f50816fe8d3e22bb87fd7976887e0335d3cdc24f22bf0b" + }, + { + "accountIndex": 1, + "subAddressIndex": 0, + "hexEncodedPublicBLSViewKey": "aa4b94053fa36086d0e9d574e198c1d8facd10a31a8cb427f5e2d825d9ce534496a085a8b15cfd52b9d9b1859274ec52", + "hexEncodedPublicBLSSpendKey": "a8388f52d42c44c4e6014578aa1ef396ca3efe3645244d4f0ccc5619223b3ff1e3d6a2490f80f4bedfc01a54e6a9ec4c" + }, + { + "accountIndex": 1, + "subAddressIndex": 1, + "hexEncodedPublicBLSViewKey": "ac69a4fcfc1da57eb1082e73a79acc73fcdf3ada7963ef015f7cd782fd26a621a765b4408c8374ee22cb6787e2470da3", + "hexEncodedPublicBLSSpendKey": "b0aa91c25ed02fca2838105def44764264cdbbc2d8f0eb3f32b1722efc7197c810f2c5f6fa3b9c93c4c953be3a5ded81" + } + ] + } + ] + """ + .data(using: .utf8)! diff --git a/Tests/BLSCTTests/Helpers/AddressCoderTestVector.swift b/Tests/BLSCTTests/Helpers/AddressCoderTestVector.swift new file mode 100644 index 0000000..2ee351c --- /dev/null +++ b/Tests/BLSCTTests/Helpers/AddressCoderTestVector.swift @@ -0,0 +1,5 @@ +struct AddressCoderTestVector: Decodable { + let hexEncodedPublicBLSViewKey: String + let hexEncodedPublicBLSSpendKey: String + let address: String +} diff --git a/Tests/BLSCTTests/Helpers/PrivateBLSKeyCoderTestVector.swift b/Tests/BLSCTTests/Helpers/PrivateBLSKeyCoderTestVector.swift new file mode 100644 index 0000000..54099bc --- /dev/null +++ b/Tests/BLSCTTests/Helpers/PrivateBLSKeyCoderTestVector.swift @@ -0,0 +1,4 @@ +struct PrivateBLSKeyCoderTestVector: Decodable { + let hexEncodedPrivateBLSKey: String + let base58CheckEncodedPrivateBLSKey: String +} diff --git a/Tests/BLSCTTests/Helpers/PrivateBLSKeysTestVector.swift b/Tests/BLSCTTests/Helpers/PrivateBLSKeysTestVector.swift new file mode 100644 index 0000000..344bf5c --- /dev/null +++ b/Tests/BLSCTTests/Helpers/PrivateBLSKeysTestVector.swift @@ -0,0 +1,8 @@ +struct PrivateBLSKeysTestVector: Decodable { + let base58CheckEncodedPrivateMasterKey: String + let hexEncodedPrivateBLSChildKey: String + let hexEncodedPrivateBLSTransactionKey: String + let hexEncodedPrivateBLSBlindingKey: String + let hexEncodedPrivateBLSViewKey: String + let hexEncodedPrivateBLSSpendKey: String +} diff --git a/Tests/BLSCTTests/Helpers/PrivateBLSMasterKeyTestVector.swift b/Tests/BLSCTTests/Helpers/PrivateBLSMasterKeyTestVector.swift new file mode 100644 index 0000000..dc79233 --- /dev/null +++ b/Tests/BLSCTTests/Helpers/PrivateBLSMasterKeyTestVector.swift @@ -0,0 +1,4 @@ +struct PrivateBLSMasterKeyTestVector: Decodable { + let base58CheckEncodedPrivateMasterKey: String + let hexEncodedPrivateBLSMasterKey: String +} diff --git a/Tests/BLSCTTests/Helpers/PublicBLSKeysTestVector+DerivatedKeys.swift b/Tests/BLSCTTests/Helpers/PublicBLSKeysTestVector+DerivatedKeys.swift new file mode 100644 index 0000000..29c38d0 --- /dev/null +++ b/Tests/BLSCTTests/Helpers/PublicBLSKeysTestVector+DerivatedKeys.swift @@ -0,0 +1,8 @@ +extension PublicBLSKeysTestVector { + struct DerivatedKeys: Decodable { + let accountIndex: UInt64 + let subAddressIndex: UInt64 + let hexEncodedPublicBLSViewKey: String + let hexEncodedPublicBLSSpendKey: String + } +} diff --git a/Tests/BLSCTTests/Helpers/PublicBLSKeysTestVector.swift b/Tests/BLSCTTests/Helpers/PublicBLSKeysTestVector.swift new file mode 100644 index 0000000..bf914f3 --- /dev/null +++ b/Tests/BLSCTTests/Helpers/PublicBLSKeysTestVector.swift @@ -0,0 +1,6 @@ +struct PublicBLSKeysTestVector: Decodable { + let base58CheckEncodedPrivateMasterKey: String + let hexEncodedPrivateBLSViewKey: String + let hexEncodedPrivateBLSSpendKey: String + let derivatedKeys: [DerivatedKeys] +} diff --git a/Tests/BLSCTTests/PrivateBLSChildKeyDerivatorTests.swift b/Tests/BLSCTTests/PrivateBLSChildKeyDerivatorTests.swift new file mode 100644 index 0000000..07abb82 --- /dev/null +++ b/Tests/BLSCTTests/PrivateBLSChildKeyDerivatorTests.swift @@ -0,0 +1,65 @@ +import Foundation +import XCTest +import BLSCT + +final class PrivateBLSChildKeyDerivatorTests: XCTestCase { + private let privateBLSKeyDerivator = PrivateBLSKeyDerivator() + private var privateBLSMasterKeyDerivator: PrivateBLSMasterKeyDerivating! + private let keyIndexHardener = KeyIndexHardener() + private let jsonDecoder = JSONDecoder() + private var testVectors: [PrivateBLSKeysTestVector]! + + override func setUpWithError() throws { + privateBLSMasterKeyDerivator = PrivateBLSMasterKeyDerivator(privateBLSKeyDerivator: privateBLSKeyDerivator) + testVectors = try jsonDecoder.decode([PrivateBLSKeysTestVector].self, from: privateBLSKeysTestData) + } + + private func sut() throws -> PrivateBLSChildKeyDerivator { + try .init(privateBLSKeyDerivator: privateBLSKeyDerivator) + } + + func testGivenPrivateParentBLSKey_WhenDerivatePrivateBLSChildKey_ThenEqualVectorKey() throws { + let sut = try self.sut() + + for testVector in testVectors { + let privateBLSMasterKey = try privateBLSMasterKeyDerivator.privateKey( + base58CheckEncodedPrivateMasterKey: testVector.base58CheckEncodedPrivateMasterKey + ) + let privateBLSChildKeyIndex = try keyIndexHardener.hardenedIndex(normalIndex: 130) + let privateBLSChildKey = try sut.privateKey( + privateBLSParentKey: privateBLSMasterKey, + index: privateBLSChildKeyIndex + ) + let privateBLSTransactionKeyIndex = try keyIndexHardener.hardenedIndex(normalIndex: 0) + let privateBLSTransactionKey = try sut.privateKey( + privateBLSParentKey: privateBLSChildKey, + index: privateBLSTransactionKeyIndex + ) + let privateBLSBlindingKeyIndex = try keyIndexHardener.hardenedIndex(normalIndex: 1) + let privateBLSBlindingKey = try sut.privateKey( + privateBLSParentKey: privateBLSChildKey, + index: privateBLSBlindingKeyIndex + ) + let privateBLSViewKeyIndex = try keyIndexHardener.hardenedIndex(normalIndex: 0) + let privateBLSViewKey = try sut.privateKey( + privateBLSParentKey: privateBLSTransactionKey, + index: privateBLSViewKeyIndex + ) + let privateBLSSpendKeyIndex = try keyIndexHardener.hardenedIndex(normalIndex: 1) + let privateBLSSpendKey = try sut.privateKey( + privateBLSParentKey: privateBLSTransactionKey, + index: privateBLSSpendKeyIndex + ) + XCTAssertEqual(privateBLSChildKey.count, 32) + XCTAssertEqual(privateBLSTransactionKey.count, 32) + XCTAssertEqual(privateBLSBlindingKey.count, 32) + XCTAssertEqual(privateBLSViewKey.count, 32) + XCTAssertEqual(privateBLSSpendKey.count, 32) + XCTAssertEqual(privateBLSChildKey.toHexString(), testVector.hexEncodedPrivateBLSChildKey) + XCTAssertEqual(privateBLSTransactionKey.toHexString(), testVector.hexEncodedPrivateBLSTransactionKey) + XCTAssertEqual(privateBLSBlindingKey.toHexString(), testVector.hexEncodedPrivateBLSBlindingKey) + XCTAssertEqual(privateBLSViewKey.toHexString(), testVector.hexEncodedPrivateBLSViewKey) + XCTAssertEqual(privateBLSSpendKey.toHexString(), testVector.hexEncodedPrivateBLSSpendKey) + } + } +} diff --git a/Tests/BLSCTTests/PrivateBLSKeysDerivatorTests.swift b/Tests/BLSCTTests/PrivateBLSKeysDerivatorTests.swift new file mode 100644 index 0000000..66c38d0 --- /dev/null +++ b/Tests/BLSCTTests/PrivateBLSKeysDerivatorTests.swift @@ -0,0 +1,40 @@ +import Foundation +import XCTest +import BLSCT + +final class PrivateBLSKeysDerivatorTests: XCTestCase { + private let privateBLSKeyDerivator = PrivateBLSKeyDerivator() + private var privateBLSMasterKeyDerivator: PrivateBLSMasterKeyDerivating! + private var privateBLSChildKeyDerivator: PrivateBLSChildKeyDerivating! + private let jsonDecoder = JSONDecoder() + private var testVectors: [PrivateBLSKeysTestVector]! + + override func setUpWithError() throws { + privateBLSMasterKeyDerivator = PrivateBLSMasterKeyDerivator(privateBLSKeyDerivator: privateBLSKeyDerivator) + privateBLSChildKeyDerivator = try PrivateBLSChildKeyDerivator(privateBLSKeyDerivator: privateBLSKeyDerivator) + testVectors = try jsonDecoder.decode([PrivateBLSKeysTestVector].self, from: privateBLSKeysTestData) + } + + private func sut() -> PrivateBLSKeysDerivator { + .init( + privateBLSMasterKeyDerivator: privateBLSMasterKeyDerivator, + privateBLSChildKeyDerivator: privateBLSChildKeyDerivator + ) + } + + func testGivenBase58CheckEncodedPrivateMasterKey_WhenDerivatePrivateBLSKeys_ThenEqualVectorKeys() throws { + let sut = self.sut() + + for testVector in testVectors { + let privateKeys = try sut.privateKeys( + base58CheckEncodedPrivateMasterKey: testVector.base58CheckEncodedPrivateMasterKey + ) + XCTAssertEqual(privateKeys.privateBLSViewKey.count, 32) + XCTAssertEqual(privateKeys.privateBLSSpendKey.count, 32) + XCTAssertEqual(privateKeys.privateBLSBlindingKey.count, 32) + XCTAssertEqual(privateKeys.privateBLSViewKey.toHexString(), testVector.hexEncodedPrivateBLSViewKey) + XCTAssertEqual(privateKeys.privateBLSSpendKey.toHexString(), testVector.hexEncodedPrivateBLSSpendKey) + XCTAssertEqual(privateKeys.privateBLSBlindingKey.toHexString(), testVector.hexEncodedPrivateBLSBlindingKey) + } + } +} diff --git a/Tests/BLSCTTests/PrivateBLSMasterKeyDerivatorTests.swift b/Tests/BLSCTTests/PrivateBLSMasterKeyDerivatorTests.swift new file mode 100644 index 0000000..2be2de4 --- /dev/null +++ b/Tests/BLSCTTests/PrivateBLSMasterKeyDerivatorTests.swift @@ -0,0 +1,28 @@ +import Foundation +import XCTest +import BLSCT + +final class PrivateBLSMasterKeyDerivatorTests: XCTestCase { + private let jsonDecoder = JSONDecoder() + private var testVectors: [PrivateBLSMasterKeyTestVector]! + + override func setUpWithError() throws { + testVectors = try jsonDecoder.decode([PrivateBLSMasterKeyTestVector].self, from: privateBLSMasterKeyTestData) + } + + private func sut() -> PrivateBLSMasterKeyDerivator { + .init() + } + + func testGivenBase58CheckEncodedPrivateMasterKey_WhenDerivatePrivateBLSMasterKey_ThenEqualVectorKey() throws { + let sut = self.sut() + + for testVector in testVectors { + let privateBLSMasterKey = try sut.privateKey( + base58CheckEncodedPrivateMasterKey: testVector.base58CheckEncodedPrivateMasterKey + ) + XCTAssertEqual(privateBLSMasterKey.count, 32) + XCTAssertEqual(privateBLSMasterKey.toHexString(), testVector.hexEncodedPrivateBLSMasterKey) + } + } +} diff --git a/Tests/BLSCTTests/PrivateBLSSpendKeyCoderTests.swift b/Tests/BLSCTTests/PrivateBLSSpendKeyCoderTests.swift new file mode 100644 index 0000000..55224ff --- /dev/null +++ b/Tests/BLSCTTests/PrivateBLSSpendKeyCoderTests.swift @@ -0,0 +1,37 @@ +import Foundation +import XCTest +import BLSCT + +final class PrivateBLSSpendKeyCoderTests: XCTestCase { + private let jsonDecoder = JSONDecoder() + private var testVectors: [PrivateBLSKeyCoderTestVector]! + + override func setUpWithError() throws { + testVectors = try jsonDecoder.decode([PrivateBLSKeyCoderTestVector].self, from: privateBLSSpendKeyCoderTestData) + } + + private func sut() -> PrivateBLSSpendKeyCoder { + .init() + } + + func testGivenPrivateBLSSpendKey_WhenEncode_ThenEqualVectorKey() { + let sut = self.sut() + + for testVector in testVectors { + let privateBLSKey = Data(hex: testVector.hexEncodedPrivateBLSKey) + let base58CheckEncodedPrivateBLSKey = sut.base58CheckEncodedPrivateKey(privateBLSSpendKey: privateBLSKey) + XCTAssertEqual(base58CheckEncodedPrivateBLSKey.count, 52) + XCTAssertEqual(base58CheckEncodedPrivateBLSKey, testVector.base58CheckEncodedPrivateBLSKey) + } + } + + func testGivenBase58CheckEncodedPrivateBLSSpendKey_WhenDecode_ThenEqualVectorKey() throws { + let sut = self.sut() + + for testVector in testVectors { + let privateBLSKey = try sut.privateKey(base58CheckEncodedPrivateBLSSpendKey: testVector.base58CheckEncodedPrivateBLSKey) + XCTAssertEqual(privateBLSKey.count, 32) + XCTAssertEqual(privateBLSKey.toHexString(), testVector.hexEncodedPrivateBLSKey) + } + } +} diff --git a/Tests/BLSCTTests/PrivateBLSViewKeyCoderTests.swift b/Tests/BLSCTTests/PrivateBLSViewKeyCoderTests.swift new file mode 100644 index 0000000..945d8ba --- /dev/null +++ b/Tests/BLSCTTests/PrivateBLSViewKeyCoderTests.swift @@ -0,0 +1,37 @@ +import Foundation +import XCTest +import BLSCT + +final class PrivateBLSViewKeyCoderTests: XCTestCase { + private let jsonDecoder = JSONDecoder() + private var testVectors: [PrivateBLSKeyCoderTestVector]! + + override func setUpWithError() throws { + testVectors = try jsonDecoder.decode([PrivateBLSKeyCoderTestVector].self, from: privateBLSViewKeyCoderTestData) + } + + private func sut() -> PrivateBLSViewKeyCoder { + .init() + } + + func testGivenPrivateBLSViewKey_WhenEncode_ThenEqualVectorKey() { + let sut = self.sut() + + for testVector in testVectors { + let privateBLSKey = Data(hex: testVector.hexEncodedPrivateBLSKey) + let base58CheckEncodedPrivateBLSKey = sut.base58CheckEncodedPrivateKey(privateBLSViewKey: privateBLSKey) + XCTAssertEqual(base58CheckEncodedPrivateBLSKey.count, 52) + XCTAssertEqual(base58CheckEncodedPrivateBLSKey, testVector.base58CheckEncodedPrivateBLSKey) + } + } + + func testGivenBase58CheckEncodedPrivateBLSViewKey_WhenDecode_ThenEqualVectorKey() throws { + let sut = self.sut() + + for testVector in testVectors { + let privateBLSKey = try sut.privateKey(base58CheckEncodedPrivateBLSViewKey: testVector.base58CheckEncodedPrivateBLSKey) + XCTAssertEqual(privateBLSKey.count, 32) + XCTAssertEqual(privateBLSKey.toHexString(), testVector.hexEncodedPrivateBLSKey) + } + } +} diff --git a/Tests/BLSCTTests/PublicBLSKeysDerivatorTests.swift b/Tests/BLSCTTests/PublicBLSKeysDerivatorTests.swift new file mode 100644 index 0000000..0c2b161 --- /dev/null +++ b/Tests/BLSCTTests/PublicBLSKeysDerivatorTests.swift @@ -0,0 +1,38 @@ +import Foundation +import XCTest +import BLSCT + +final class PublicBLSKeysDerivatorTests: XCTestCase { + private let jsonDecoder = JSONDecoder() + private var testVectors: [PublicBLSKeysTestVector]! + + override func setUpWithError() throws { + testVectors = try jsonDecoder.decode([PublicBLSKeysTestVector].self, from: publicBLSKeysTestData) + } + + private func sut(privateBLSViewKey: Data, privateBLSSpendKey: Data) throws -> PublicBLSKeysDerivator { + try .init(privateBLSViewKey: privateBLSViewKey, privateBLSSpendKey: privateBLSSpendKey) + } + + func testGivenPrivateBLSViewKey_AndPrivateBLSSpendKey_WhenDerivatePublicBLSKeys_ThenEqualVectorKeys() throws { + for testVector in testVectors { + let privateBLSViewKey = Data(hex: testVector.hexEncodedPrivateBLSViewKey) + let privateBLSSpendKey = Data(hex: testVector.hexEncodedPrivateBLSSpendKey) + + for derivatedKeys in testVector.derivatedKeys { + let sut = try self.sut( + privateBLSViewKey: privateBLSViewKey, + privateBLSSpendKey: privateBLSSpendKey + ) + let publicKeys = try sut.publicKeys( + accountIndex: derivatedKeys.accountIndex, + subAddressIndex: derivatedKeys.subAddressIndex + ) + XCTAssertEqual(publicKeys.publicBLSViewKey.count, 48) + XCTAssertEqual(publicKeys.publicBLSSpendKey.count, 48) + XCTAssertEqual(publicKeys.publicBLSViewKey.toHexString(), derivatedKeys.hexEncodedPublicBLSViewKey) + XCTAssertEqual(publicKeys.publicBLSSpendKey.toHexString(), derivatedKeys.hexEncodedPublicBLSSpendKey) + } + } + } +}