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 jt.signer = [mySigners, &env](Env&, JTx& jtx) {
73 jtx[sfSigningPubKey.getJsonName()] = "";
75 try
76 {
77 st = parse(jtx.jv);
78 }
79 catch (parse_error const&)
80 {
81 env.test.log << pretty(jtx.jv) << std::endl;
82 Rethrow();
83 }
84 auto& js = jtx[sfSigners.getJsonName()];
85 for (std::size_t i = 0; i < mySigners.size(); ++i)
86 {
87 auto const& e = mySigners[i];
88 auto& jo = js[i][sfSigner.getJsonName()];
89 jo[jss::Account] = e.acct.human();
90 jo[jss::SigningPubKey] = strHex(e.sig.pk().slice());
91
92 Serializer ss{buildMultiSigningData(*st, e.acct.id())};
93 auto const sig = ripple::sign(
94 *publicKeyType(e.sig.pk().slice()), e.sig.sk(), ss.slice());
95 jo[sfTxnSignature.getJsonName()] =
96 strHex(Slice{sig.data(), sig.size()});
97 }
98 };
99}
100
101} // namespace jtx
102} // namespace test
103} // namespace ripple
Represents a JSON value.
Definition: json_value.h:150
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
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)
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
T size(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