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
23#include <xrpl/basics/contract.h>
24#include <xrpl/protocol/Sign.h>
25#include <xrpl/protocol/jss.h>
26
27#include <optional>
28
29namespace ripple {
30namespace test {
31namespace jtx {
32
35 Account const& account,
36 std::uint32_t quorum,
37 std::vector<signer> const& v)
38{
39 Json::Value jv;
40 jv[jss::Account] = account.human();
41 jv[jss::TransactionType] = jss::SignerListSet;
42 jv[sfSignerQuorum.getJsonName()] = quorum;
43 auto& ja = jv[sfSignerEntries.getJsonName()];
44 for (std::size_t i = 0; i < v.size(); ++i)
45 {
46 auto const& e = v[i];
47 auto& je = ja[i][sfSignerEntry.getJsonName()];
48 je[jss::Account] = e.account.human();
49 je[sfSignerWeight.getJsonName()] = e.weight;
50 if (e.tag)
51 je[sfWalletLocator.getJsonName()] = to_string(*e.tag);
52 }
53 return jv;
54}
55
57signers(Account const& account, none_t)
58{
59 Json::Value jv;
60 jv[jss::Account] = account.human();
61 jv[jss::TransactionType] = jss::SignerListSet;
62 jv[sfSignerQuorum.getJsonName()] = 0;
63 return jv;
64}
65
66//------------------------------------------------------------------------------
67
68msig::msig(std::vector<msig::Reg> signers_) : signers(std::move(signers_))
69{
70 // Signatures must be applied in sorted order.
72 signers.begin(),
73 signers.end(),
74 [](msig::Reg const& lhs, msig::Reg const& rhs) {
75 return lhs.acct.id() < rhs.acct.id();
76 });
77}
78
79void
80msig::operator()(Env& env, JTx& jt) const
81{
82 auto const mySigners = signers;
83 jt.signer = [mySigners, &env](Env&, JTx& jtx) {
84 jtx[sfSigningPubKey.getJsonName()] = "";
86 try
87 {
88 st = parse(jtx.jv);
89 }
90 catch (parse_error const&)
91 {
92 env.test.log << pretty(jtx.jv) << std::endl;
93 Rethrow();
94 }
95 auto& js = jtx[sfSigners.getJsonName()];
96 for (std::size_t i = 0; i < mySigners.size(); ++i)
97 {
98 auto const& e = mySigners[i];
99 auto& jo = js[i][sfSigner.getJsonName()];
100 jo[jss::Account] = e.acct.human();
101 jo[jss::SigningPubKey] = strHex(e.sig.pk().slice());
102
103 Serializer ss{buildMultiSigningData(*st, e.acct.id())};
104 auto const sig = ripple::sign(
105 *publicKeyType(e.sig.pk().slice()), e.sig.sk(), ss.slice());
106 jo[sfTxnSignature.getJsonName()] =
107 strHex(Slice{sig.data(), sig.size()});
108 }
109 };
110}
111
112} // namespace jtx
113} // namespace test
114} // namespace ripple
Represents a JSON value.
Definition: json_value.h:148
log_os< char > log
Logging output stream.
Definition: suite.h:152
An immutable linear range of bytes.
Definition: Slice.h:46
Immutable cryptographic account descriptor.
Definition: Account.h:39
A transaction testing environment.
Definition: Env.h:120
beast::unit_test::suite & test
Definition: Env.h:122
void operator()(Env &, JTx &jt) const
Definition: multisign.cpp:80
msig(std::vector< Reg > signers_)
Definition: multisign.cpp:68
std::vector< Reg > signers
Definition: multisign.h:98
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:34
STObject parse(Json::Value const &jv)
Convert JSON to STObject.
Definition: utility.cpp:38
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:96
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
Definition: SecretKey.cpp:256
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Definition: PublicKey.cpp:223
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:630
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:45
std::function< void(Env &, JTx &)> signer
Definition: JTx.h:57
Thrown when parse fails.
Definition: utility.h:39