spb/os-vault Public
Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.
Swift 96%
Shell 3.4%
Makefile 0.6%
1import WalletCoreC2import Foundation3// SPDX-License-Identifier: Apache-2.04//5// Copyright © 2017 Trust Wallet.6//7// This is a GENERATED FILE, changes made here WILL BE LOST.8//910import Foundation1112/// Bitcoin message signing and verification.13///14/// Bitcoin Core and some other wallets support a message signing & verification format, to create a proof (a signature)15/// that someone has access to the private keys of a specific address.16/// This feature currently works on old legacy addresses only.17public struct BitcoinMessageSigner {1819 /// Sign a message.20 ///21 /// - Parameter privateKey:: the private key used for signing22 /// - Parameter address:: the address that matches the privateKey, must be a legacy address (P2PKH)23 /// - Parameter message:: A custom message which is input to the signing.24 /// - Note: Address is derived assuming compressed public key format.25 /// - Returns:s the signature, Base64-encoded. On invalid input empty string is returned. Returned object needs to be deleteed after use.26 public static func signMessage(privateKey: PrivateKey, address: String, message: String) -> String {27 let addressString = TWStringCreateWithNSString(address)28 defer {29 TWStringDelete(addressString)30 }31 let messageString = TWStringCreateWithNSString(message)32 defer {33 TWStringDelete(messageString)34 }35 return TWStringNSString(TWBitcoinMessageSignerSignMessage(privateKey.rawValue, addressString, messageString))36 }3738 /// Verify signature for a message.39 ///40 /// - Parameter address:: address to use, only legacy is supported41 /// - Parameter message:: the message signed (without prefix)42 /// - Parameter signature:: in Base64-encoded form.43 /// - Returns:s false on any invalid input (does not throw).44 public static func verifyMessage(address: String, message: String, signature: String) -> Bool {45 let addressString = TWStringCreateWithNSString(address)46 defer {47 TWStringDelete(addressString)48 }49 let messageString = TWStringCreateWithNSString(message)50 defer {51 TWStringDelete(messageString)52 }53 let signatureString = TWStringCreateWithNSString(signature)54 defer {55 TWStringDelete(signatureString)56 }57 return TWBitcoinMessageSignerVerifyMessage(addressString, messageString, signatureString)58 }596061 init() {62 }636465}66