Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Sources/HDWalletKit/Core/Crypto/Encryption/ECDSA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@ public final class ECDSA {

public func verifySignature(_ sigData: Data, message: Data, publicKeyData: Data) throws -> Bool {
guard let ctx = secp256k1_context_create(UInt32(SECP256K1_CONTEXT_VERIFY)) else { return false }
defer { secp256k1_context_destroy(ctx) }
var pubkey = secp256k1_pubkey()
var signature = secp256k1_ecdsa_signature()
secp256k1_ecdsa_signature_parse_der(ctx, &signature, sigData.bytes, sigData.count)

if (secp256k1_ec_pubkey_parse(ctx, &pubkey, publicKeyData.bytes, publicKeyData.count) != 1) {
secp256k1_ecdsa_signature_parse_der(ctx, &signature, [UInt8](sigData), sigData.count)
if (secp256k1_ec_pubkey_parse(ctx, &pubkey, [UInt8](publicKeyData), publicKeyData.count) != 1) {
return false
};

if (secp256k1_ecdsa_verify(ctx, &signature, message.bytes, &pubkey) != 1) {
if (secp256k1_ecdsa_verify(ctx, &signature, [UInt8](message), &pubkey) != 1) {
return false
};
secp256k1_context_destroy(ctx);
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class EllipticCurveEncrypterSecp256k1 {
/// - privateKey: private key bytes
/// - Returns: public key structure
public func createPublicKey(privateKey: Data) -> secp256k1_pubkey {
let privateKey = privateKey.bytes
let privateKey = [UInt8](privateKey)
var publickKey = secp256k1_pubkey()
_ = SecpResult(secp256k1_ec_pubkey_create(context, &publickKey, privateKey))
return publickKey
Expand Down Expand Up @@ -94,8 +94,8 @@ public class EllipticCurveEncrypterSecp256k1 {
/// - hash: 32-byte (256-bit) hash of a message
/// - Returns: public key structure or nil, if signature invalid
public func publicKey(signature: inout secp256k1_ecdsa_recoverable_signature, hash: Data) -> secp256k1_pubkey? {
let hash = [UInt8](hash)
precondition(hash.count == 32, "Hash must be 32 bytes size")
let hash = hash.bytes
var outPubKey = secp256k1_pubkey()
let status = SecpResult(secp256k1_ecdsa_recover(context, &outPubKey, &signature, hash))
return status == .success ? outPubKey : nil
Expand Down
3 changes: 1 addition & 2 deletions Sources/HDWalletKit/Mnemonic/Mnemonic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public final class Mnemonic {
guard let salt = ("mnemonic" + passphrase).decomposedStringWithCompatibilityMapping.data(using: .utf8) else {
fatalError("Nomalizing salt failed in \(self)")
}

return Crypto.PBKDF2SHA512(password: password.bytes, salt: salt.bytes)
return Crypto.PBKDF2SHA512(password: [UInt8](password), salt: [UInt8](salt))
}
}