forked from trustwallet/wallet-core
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTWTezosMessageSigner.h
51 lines (42 loc) · 2.04 KB
/
TWTezosMessageSigner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: Apache-2.0
//
// Copyright © 2017 Trust Wallet.
#pragma once
#include "TWBase.h"
#include "TWData.h"
#include "TWString.h"
#include "TWPrivateKey.h"
#include "TWPublicKey.h"
TW_EXTERN_C_BEGIN
/// Tezos message signing, verification and utilities.
TW_EXPORT_STRUCT
struct TWTezosMessageSigner;
/// Implement format input as described in https://tezostaquito.io/docs/signing/
///
/// \param message message to format e.g: Hello, World
/// \param dAppUrl the app url, e.g: testUrl
/// \returns the formatted message as a string
TW_EXPORT_STATIC_METHOD
TWString* _Nonnull TWTezosMessageSignerFormatMessage(TWString* _Nonnull message, TWString* _Nonnull url);
/// Implement input to payload as described in: https://tezostaquito.io/docs/signing/
///
/// \param message formatted message to be turned into an hex payload
/// \return the hexpayload of the formated message as a hex string
TW_EXPORT_STATIC_METHOD
TWString* _Nonnull TWTezosMessageSignerInputToPayload(TWString* _Nonnull message);
/// Sign a message as described in https://tezostaquito.io/docs/signing/
///
/// \param privateKey: the private key used for signing
/// \param message: A custom message payload (hex) which is input to the signing.
/// \returns the signature, Hex-encoded. On invalid input empty string is returned. Returned object needs to be deleted after use.
TW_EXPORT_STATIC_METHOD
TWString* _Nonnull TWTezosMessageSignerSignMessage(const struct TWPrivateKey* _Nonnull privateKey, TWString* _Nonnull message);
/// Verify signature for a message as described in https://tezostaquito.io/docs/signing/
///
/// \param pubKey: pubKey that will verify the message from the signature
/// \param message: the message signed as a payload (hex)
/// \param signature: in Base58-encoded form.
/// \returns false on any invalid input (does not throw), true if the message can be verified from the signature
TW_EXPORT_STATIC_METHOD
bool TWTezosMessageSignerVerifyMessage(const struct TWPublicKey* _Nonnull pubKey, TWString* _Nonnull message, TWString* _Nonnull signature);
TW_EXTERN_C_END