-
Notifications
You must be signed in to change notification settings - Fork 34
/
sr25519_provider.hpp
68 lines (56 loc) · 2.06 KB
/
sr25519_provider.hpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "crypto/bip39/bip39_types.hpp"
#include "crypto/sr25519_types.hpp"
namespace kagome::crypto {
/**
* sr25519 provider error codes
*/
enum class Sr25519ProviderError : uint8_t {
SIGN_UNKNOWN_ERROR = 1, // unknown error occured during call to `sign`
// method of bound function
VERIFY_UNKNOWN_ERROR // unknown error occured during call to `verify`
// method of bound function
};
class Sr25519Provider {
public:
using Keypair = Sr25519Keypair;
using PublicKey = Sr25519PublicKey;
using PrivateKey = Sr25519SecretKey;
using Seed = Sr25519Seed;
using Junctions = std::span<const bip39::RawJunction>;
virtual ~Sr25519Provider() = default;
/**
* Generate random keypair from seed
*/
virtual outcome::result<Sr25519Keypair> generateKeypair(
const Sr25519Seed &seed, Junctions junctions) const = 0;
/**
* Sign message \param msg using \param keypair. If computed value is less
* than \param threshold then return optional containing this value and
* proof. Otherwise none returned
* @param keypair pair of public and secret sr25519 keys
* @param message bytes to be signed
* @return signed message
*/
virtual outcome::result<Sr25519Signature> sign(
const Sr25519Keypair &keypair, common::BufferView message) const = 0;
/**
* Verifies that \param message was derived using \param public_key on
* \param signature
*/
virtual outcome::result<bool> verify(
const Sr25519Signature &signature,
common::BufferView message,
const Sr25519PublicKey &public_key) const = 0;
virtual outcome::result<bool> verify_deprecated(
const Sr25519Signature &signature,
common::BufferView message,
const Sr25519PublicKey &public_key) const = 0;
};
} // namespace kagome::crypto
OUTCOME_HPP_DECLARE_ERROR(kagome::crypto, Sr25519ProviderError)