From 7a1a53e8c0ed5225744f71902fd8c76ec3a5c308 Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Fri, 5 Jan 2024 14:59:01 +0000 Subject: [PATCH] add another test for special torus wallet flow --- .../KukaiCryptoSwiftTests/KeyPairTests.swift | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Tests/KukaiCryptoSwiftTests/KeyPairTests.swift b/Tests/KukaiCryptoSwiftTests/KeyPairTests.swift index da6a4b0..04fa5e4 100644 --- a/Tests/KukaiCryptoSwiftTests/KeyPairTests.swift +++ b/Tests/KukaiCryptoSwiftTests/KeyPairTests.swift @@ -38,6 +38,27 @@ final class KeyPairTests: XCTestCase { XCTAssert(keyPair2?.publicKey.verify(message: watermarkedBytes, signature: signature2, hex: signatureHex2) == true) } + func testRegularTZ2() throws { + let messageToSign = "something very interesting that needs to be signed".bytes + let watermarkedBytes = messageToSign.addOperationWatermarkAndHash() ?? [] + + let privetKeyBytes: [UInt8] = [125, 133, 194, 84, 250, 98, 79, 41, 174, 84, 233, 129, 41, 85, 148, 33, 44, 186, 87, 103, 235, 213, 247, 99, 133, 29, 151, 197, 91, 106, 136, 214] + let base58encodedKey = Base58Check.encode(message: privetKeyBytes, prefix: Prefix.Keys.Secp256k1.secret) + + if let privateKey = PrivateKey(base58encodedKey, signingCurve: .secp256k1), let pubKey = KeyPair.secp256k1PublicKey(fromPrivateKeyBytes: privateKey.bytes) { + let tempAddress = pubKey.publicKeyHash + + let signature = privateKey.sign(bytes: watermarkedBytes) ?? [] + let signatureHex = signature.hexString + + XCTAssert(tempAddress == "tz2HpbGQcmU3UyusJ78Sbqeg9fYteamSMDGo", tempAddress ?? "-") + XCTAssert(signatureHex == "2c9f14f18a21867fd2fe3130ad3aaeca7cb1c9421d78d32537173b98b25ed07d054837a878c7e9fe2d237b42c90e5aa2a63a58774833221707cc303a2121b3e7", signatureHex) + + } else { + XCTFail("Failed to create private key or public key") + } + } + func testHD() throws { let messageToSign = "something very interesting that needs to be signed".bytes let watermarkedBytes = messageToSign.addOperationWatermarkAndHash() ?? []