Skip to content

Commit f4fb0f2

Browse files
committed
allow joining a copay wallet from the GUI (rought)
1 parent 9271719 commit f4fb0f2

File tree

8 files changed

+176
-130
lines changed

8 files changed

+176
-130
lines changed

configure.ac

+2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,10 @@ AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
293293
AM_CONDITIONAL([ENABLE_DAEMON],[test x$enable_daemon = xyes])
294294
AC_SUBST(BOOST_LIBS)
295295

296+
oldVars = ${ac_configure_args};
296297
ac_configure_args="--with-daemon=no --with-gui=no --enable-wallet=no --with-libs=yes --enable-tests=no --enable-static=yes"
297298
AC_CONFIG_SUBDIRS([vendor/bitcoin])
299+
ac_configure_args = ${oldVars}
298300

299301
AC_PROG_CXX
300302
AC_CONFIG_FILES([Makefile src/Makefile])

src/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dbb_cli_LDADD = libunival.a libdbb.a $(CRYPTO_LIBS)
2929
if ENABLE_DBB_APP
3030
bin_PROGRAMS += dbb-app
3131

32+
dbb_app_CONFIG_INCLUDES=-I$(builddir)/config
3233
dbb_app_SOURCES = dbb_app.cpp util.h util.cpp
3334
dbb_app_CPPFLAGS = -fPIC $(AM_CPPFLAGS)
3435
dbb_app_CFLAGS =
@@ -64,7 +65,7 @@ $(dbb_app_OBJECTS) $(dbb_app_OBJECTS) : | $(QT_MOC)
6465
dbb_app_SOURCES += qt/dbbgui.h $(DBB_GUI_H) qt/dbbgui.cpp qt/qrc_dbbgui.cpp $(QT_MOC_CPP) $(QT_MOC) $(QT_FORMS_UI) $(DBB_GUI_CPP)
6566
dbb_app_CPPFLAGS += $(QT_INCLUDES) $(QT_DBUS_INCLUDES)
6667
dbb_app_LDFLAGS += $(QT_LDFLAGS)
67-
dbb_app_LDADD += $(QT_LIBS) $(QT_DBUS_LIBS) ../vendor/bitcoin/src/libbitcoin_common.a ../vendor/bitcoin/src/libbitcoin_util.a ../vendor/bitcoin/src/crypto/libbitcoin_crypto.a ../vendor/bitcoin/src/univalue/libbitcoin_univalue.a ../vendor/bitcoin/src/secp256k1/libsecp256k1.la $(BOOST_LIBS)
68+
dbb_app_LDADD += $(QT_LIBS) $(QT_DBUS_LIBS) ../vendor/bitcoin/src/libbitcoin_common.a ../vendor/bitcoin/src/libbitcoin_util.a ../vendor/bitcoin/src/crypto/libbitcoin_crypto.a ../vendor/bitcoin/src/univalue/libbitcoin_univalue.a ../vendor/bitcoin/src/secp256k1/libsecp256k1.la $(BOOST_LIBS) -lcurl
6869

6970
CLEAN_QT = $(QT_MOC_CPP) $(QT_FORMS_H)
7071

src/dbb_app.cpp

+6-88
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
#include <event2/keyvalq_struct.h>
5858
#include <sys/signal.h>
5959

60+
#include "config/_dbb-config.h"
61+
6062
#ifdef DBB_ENABLE_QT
6163
#include <QApplication>
6264
#include <QPushButton>
@@ -178,7 +180,6 @@ int main(int argc, char** argv)
178180
//check devices
179181
if (!DBB::isConnectionOpen())
180182
{
181-
printf("no connection\n");
182183
if (DBB::openConnection())
183184
{
184185
#ifdef DBB_ENABLE_QT
@@ -198,93 +199,9 @@ int main(int argc, char** argv)
198199
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
199200
}
200201
});
201-
202-
202+
203203
ECC_Start();
204-
205-
BitPayWalletClient client;
206-
207-
std::string myName = "test";
208-
209-
printf("start seed\n");
210-
client.seed();
211-
printf("seed done\n");
212-
std::string requestPubKey;
213-
if (!client.GetRequestPubKey(requestPubKey))
214-
printf("Retriving request key failed!\n");
215-
216-
std::string copayerHash;
217-
client.GetCopayerHash(myName, copayerHash);
218-
printf("---copayer hash: %s\n", copayerHash.c_str());
219-
CKey aKey = client.GetNewKey();
220-
assert(aKey.VerifyPubKey(aKey.GetPubKey()) == 1);
221-
222-
BitpayWalletInvitation invitation;
223-
if (!client.ParseWalletInvitation("MJRiJFPTE8cJtQ2YBHtasnL3vNy8NF4BRLBNLemcBCMg55DmEWeY9FaXGrQEBjRd1ZsoZ9hVfgL", invitation))
224-
printf("parse invitation failed!\n");
225-
226-
std::string copayerSignature;
227-
client.GetCopayerSignature(copayerHash, invitation.walletPrivKey, copayerSignature);
228-
printf("copayerSignature %s\n", copayerSignature.c_str());
229-
printf("walletid: %s\n", invitation.walletID.c_str());
230-
printf("network: %s\n", invitation.network.c_str());
231-
232-
UniValue jsonArgs(UniValue::VOBJ);
233-
jsonArgs.push_back(Pair("walletId", invitation.walletID));
234-
jsonArgs.push_back(Pair("name", myName));
235-
jsonArgs.push_back(Pair("xPubKey", client.GetXPubKey()));
236-
jsonArgs.push_back(Pair("requestPubKey", requestPubKey));
237-
jsonArgs.push_back(Pair("isTemporaryRequestKey", false));
238-
jsonArgs.push_back(Pair("copayerSignature", copayerSignature));
239-
240-
std::string json = jsonArgs.write();
241-
printf("JSON: %s", json.c_str());
242-
243-
std::string method = "post";
244-
std::string url = "/v1/wallets/"+invitation.walletID+"/copayers";
245-
246-
std::string xSignature = client.SignRequest(method, url, json);
247-
std::string xIdentity = requestPubKey;
248-
std::string postUrl = "https://bws.bitpay.com/bws/api";
249-
250-
std::string header = "\n\ncurl -X POST -H \"Content-Type: application/json\" -d '"+json+"' --header \"x-identity: "+xIdentity+"\" --header \"x-signature: "+xSignature+"\" -v "+postUrl+url+"\n\n";
251-
printf("header: %s", header.c_str());
252-
253-
ECC_Stop();
254-
255-
// unsigned char vchPub[65];
256-
// int clen = 65;
257-
// secp256k1_pubkey_t pubkey;
258-
// assert(secp256k1_ec_seckey_verify(secp256k1_context, vch) == 1);
259-
// int ret = secp256k1_ec_pubkey_create(secp256k1_context, &pubkey, vch);
260-
// unsigned char pubkeyc[65];
261-
// int pubkeyclen = 65;
262-
// secp256k1_ec_pubkey_serialize(secp256k1_context, pubkeyc, &pubkeyclen, &pubkey, true);
263-
264-
// std::string hexStr = HexStr(pubkeyc, pubkeyc+pubkeyclen, false);
265-
//
266-
// secp256k1_pubkey_t pubkeyNew;
267-
// std::vector<unsigned char> vPubKey = ParseHex(hexStr);
268-
// int suc = secp256k1_ec_pubkey_parse(secp256k1_context, &pubkeyNew, &vPubKey[0], vPubKey.size());
269-
270-
271-
272-
//var message = [method.toLowerCase(), url, JSON.stringify(args)].join('|');
273-
// std::string requestString = "get|/v1/wallets/?r=62416|{}";
274-
// unsigned char hashD[32];
275-
// doubleSha256((char*)requestString.c_str(), hashD);
276-
// secp256k1_ecdsa_signature_t signature;
277-
// suc = secp256k1_ecdsa_sign(secp256k1_context, hashD, &signature, vch, NULL, NULL);
278-
//
279-
// unsigned char sig[74];
280-
// int siglen = 74;
281-
// suc = secp256k1_ecdsa_signature_serialize_der(secp256k1_context, sig, &siglen, &signature);
282-
// std::string hexStrDER = HexStr(sig, sig+siglen, false);
283-
//
284-
//
285-
// std::string header = "\n\ncurl --header \"x-identity: "+hexStr+"\" --header \"x-signature: "+hexStrDER+"\" -v https://bws.bitpay.com/bws/api/v1/wallets/\n\n";
286-
// printf("header: %s", header.c_str());
287-
204+
288205
#ifdef DBB_ENABLE_QT
289206
#if QT_VERSION > 0x050100
290207
// Generate high-dpi pixmaps
@@ -295,7 +212,7 @@ int main(int argc, char** argv)
295212
std::thread httpThread([&]() {
296213
event_base_dispatch(base);
297214
});
298-
215+
299216
QApplication app(argc, argv);
300217

301218
widget = new DBBDaemonGui(0);
@@ -306,5 +223,6 @@ int main(int argc, char** argv)
306223
event_base_dispatch(base);
307224
#endif
308225

226+
ECC_Stop();
309227
exit(1);
310228
}

0 commit comments

Comments
 (0)