SPB Git

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%
2.3 KB · 68 lines swift
Raw Blame History
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 Foundation111213public final class MessageSigner {1415    /// Signs an arbitrary message to prove ownership of an address for off-chain services.16    /// 17    /// - Parameter coin: The given coin type to sign the message for.18    /// - Parameter input: The serialized data of a signing input (e.g. TW.Ethereum.Proto.MessageSigningInput).19    /// - Returns: The serialized data of a `SigningOutput` proto object. (e.g. TW.Ethereum.Proto.MessageSigningOutput).20    public static func sign(coin: CoinType, input: Data) -> Data? {21        let inputData = TWDataCreateWithNSData(input)22        defer {23            TWDataDelete(inputData)24        }25        guard let result = TWMessageSignerSign(TWCoinType(rawValue: coin.rawValue), inputData) else {26            return nil27        }28        return TWDataNSData(result)29    }3031    /// Verifies a signature for a message.32    /// 33    /// - Parameter coin: The given coin type to sign the message for.34    /// - Parameter input: The serialized data of a verifying input (e.g. TW.Ethereum.Proto.MessageVerifyingInput).35    /// - Returns: whether the signature is valid.36    public static func verify(coin: CoinType, input: Data) -> Bool {37        let inputData = TWDataCreateWithNSData(input)38        defer {39            TWDataDelete(inputData)40        }41        return TWMessageSignerVerify(TWCoinType(rawValue: coin.rawValue), inputData)42    }4344    /// Computes preimage hashes of a message.45    /// 46    /// - Parameter coin: The given coin type to sign the message for.47    /// - Parameter input: The serialized data of a signing input (e.g. TW.Ethereum.Proto.MessageSigningInput).48    /// - Returns: The serialized data of TW.TxCompiler.PreSigningOutput.49    public static func preImageHashes(coin: CoinType, input: Data) -> Data? {50        let inputData = TWDataCreateWithNSData(input)51        defer {52            TWDataDelete(inputData)53        }54        guard let result = TWMessageSignerPreImageHashes(TWCoinType(rawValue: coin.rawValue), inputData) else {55            return nil56        }57        return TWDataNSData(result)58    }5960    let rawValue: OpaquePointer6162    init(rawValue: OpaquePointer) {63        self.rawValue = rawValue64    }656667}68