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
68void
69msig::operator()(Env& env, JTx& jt) const
70{
71 auto const mySigners = signers;
72 auto callback = [subField = subField, mySigners, &env](Env&, JTx& jtx) {
73 // Where to put the signature. Supports sfCounterPartySignature.
74 auto& sigObject = subField ? jtx[*subField] : jtx.jv;
75
76 // The signing pub key is only required at the top level.
77 if (!subField)
78 sigObject[sfSigningPubKey] = "";
79 else if (sigObject.isNull())
80 sigObject = Json::Value(Json::objectValue);
82 try
83 {
84 st = parse(jtx.jv);
85 }
86 catch (parse_error const&)
87 {
88 env.test.log << pretty(jtx.jv) << std::endl;
89 Rethrow();
90 }
91 auto& js = sigObject[sfSigners];
92 for (std::size_t i = 0; i < mySigners.size(); ++i)
93 {
94 auto const& e = mySigners[i];
95 auto& jo = js[i][sfSigner.getJsonName()];
96 jo[jss::Account] = e.acct.human();
97 jo[jss::SigningPubKey] = strHex(e.sig.pk().slice());
98
99 Serializer ss{buildMultiSigningData(*st, e.acct.id())};
100 auto const sig = ripple::sign(
101 *publicKeyType(e.sig.pk().slice()), e.sig.sk(), ss.slice());
102 jo[sfTxnSignature.getJsonName()] =
103 strHex(Slice{sig.data(), sig.size()});
104 }
105 };
106 if (!subField)
107 jt.mainSigners.emplace_back(callback);
108 else
109 jt.postSigners.emplace_back(callback);
110}
111
112} // namespace jtx
113} // namespace test
114} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
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:121
beast::unit_test::suite & test
Definition Env.h:123
SField const *const subField
Alternative transaction object field in which to place the signer list.
Definition multisign.h:74
void operator()(Env &, JTx &jt) const
Definition multisign.cpp:69
std::vector< Reg > signers
Definition multisign.h:69
Set the regular signature on a JTx.
Definition sig.h:35
T endl(T... args)
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:45
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:25
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.
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
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
T size(T... args)
Execution context for applying a JSON transaction.
Definition JTx.h:45
std::vector< std::function< void(Env &, JTx &)> > postSigners
Definition JTx.h:61
std::vector< std::function< void(Env &, JTx &)> > mainSigners
Definition JTx.h:58
Thrown when parse fails.
Definition utility.h:39