rippled
Loading...
Searching...
No Matches
multisign.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/jtx/multisign.h>
21#include <test/jtx/utility.h>
22#include <xrpl/basics/contract.h>
23#include <xrpl/protocol/HashPrefix.h>
24#include <xrpl/protocol/Sign.h>
25#include <xrpl/protocol/UintTypes.h>
26#include <xrpl/protocol/jss.h>
27#include <optional>
28#include <sstream>
29
30namespace ripple {
31namespace test {
32namespace jtx {
33
36 Account const& account,
37 std::uint32_t quorum,
38 std::vector<signer> const& v)
39{
40 Json::Value jv;
41 jv[jss::Account] = account.human();
42 jv[jss::TransactionType] = jss::SignerListSet;
43 jv[sfSignerQuorum.getJsonName()] = quorum;
44 auto& ja = jv[sfSignerEntries.getJsonName()];
45 for (std::size_t i = 0; i < v.size(); ++i)
46 {
47 auto const& e = v[i];
48 auto& je = ja[i][sfSignerEntry.getJsonName()];
49 je[jss::Account] = e.account.human();
50 je[sfSignerWeight.getJsonName()] = e.weight;
51 if (e.tag)
52 je[sfWalletLocator.getJsonName()] = to_string(*e.tag);
53 }
54 return jv;
55}
56
58signers(Account const& account, none_t)
59{
60 Json::Value jv;
61 jv[jss::Account] = account.human();
62 jv[jss::TransactionType] = jss::SignerListSet;
63 jv[sfSignerQuorum.getJsonName()] = 0;
64 return jv;
65}
66
67//------------------------------------------------------------------------------
68
69msig::msig(std::vector<msig::Reg> signers_) : signers(std::move(signers_))
70{
71 // Signatures must be applied in sorted order.
73 signers.begin(),
74 signers.end(),
75 [](msig::Reg const& lhs, msig::Reg const& rhs) {
76 return lhs.acct.id() < rhs.acct.id();
77 });
78}
79
80void
81msig::operator()(Env& env, JTx& jt) const
82{
83 auto const mySigners = signers;
84 jt.signer = [mySigners, &env](Env&, JTx& jtx) {
85 jtx[sfSigningPubKey.getJsonName()] = "";
87 try
88 {
89 st = parse(jtx.jv);
90 }
91 catch (parse_error const&)
92 {
93 env.test.log << pretty(jtx.jv) << std::endl;
94 Rethrow();
95 }
96 auto& js = jtx[sfSigners.getJsonName()];
97 for (std::size_t i = 0; i < mySigners.size(); ++i)
98 {
99 auto const& e = mySigners[i];
100 auto& jo = js[i][sfSigner.getJsonName()];
101 jo[jss::Account] = e.acct.human();
102 jo[jss::SigningPubKey] = strHex(e.sig.pk().slice());
103
104 Serializer ss{buildMultiSigningData(*st, e.acct.id())};
105 auto const sig = ripple::sign(
106 *publicKeyType(e.sig.pk().slice()), e.sig.sk(), ss.slice());
107 jo[sfTxnSignature.getJsonName()] =
108 strHex(Slice{sig.data(), sig.size()});
109 }
110 };
111}
112
113} // namespace jtx
114} // namespace test
115} // namespace ripple
Represents a JSON value.
Definition: json_value.h:147
log_os< char > log
Logging output stream.
Definition: suite.h:150
An immutable linear range of bytes.
Definition: Slice.h:45
Immutable cryptographic account descriptor.
Definition: Account.h:38
A transaction testing environment.
Definition: Env.h:117
beast::unit_test::suite & test
Definition: Env.h:119
void operator()(Env &, JTx &jt) const
Definition: multisign.cpp:81
msig(std::vector< Reg > signers_)
Definition: multisign.cpp:69
std::vector< Reg > signers
Definition: multisign.h:97
Set the regular signature on a JTx.
Definition: sig.h:35
T endl(T... args)
Json::Value signers(Account const &account, std::uint32_t quorum, std::vector< signer > const &v)
Definition: multisign.cpp:35
STObject parse(Json::Value const &jv)
Convert JSON to STObject.
Definition: utility.cpp:37
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
Serializer buildMultiSigningData(STObject const &obj, AccountID const &signingID)
Return a Serializer suitable for computing a multisigning TxnSignature.
Definition: Sign.cpp:87
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
Definition: SecretKey.cpp:238
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition: PublicKey.cpp:207
std::string strHex(FwdIt begin, FwdIt end)
Definition: strHex.h:30
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:629
void Rethrow()
Rethrow the exception currently being handled.
Definition: contract.h:48
STL namespace.
T size(T... args)
T sort(T... args)
Execution context for applying a JSON transaction.
Definition: JTx.h:44
std::function< void(Env &, JTx &)> signer
Definition: JTx.h:55
Thrown when parse fails.
Definition: utility.h:36