Skip to content

Commit db24797

Browse files
committed
Enable using multiple nonces and messages
1 parent 168c316 commit db24797

21 files changed

+774
-422
lines changed

Diff for: external/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if(CFD_DLC_TARGET_VERSION)
1313
set(CFD_DLC_TARGET_TAG ${CFD_DLC_TARGET_VERSION})
1414
message(STATUS "[external project debug] cfd dlc target=${CFD_DLC_TARGET_VERSION}")
1515
else()
16-
set(CFD_DLC_TARGET_TAG "v0.0.6")
16+
set(CFD_DLC_TARGET_TAG "v0.0.7")
1717
endif()
1818
if(CFD_DLC_TARGET_URL)
1919
set(CFD_DLC_TARGET_REP ${CFD_DLC_TARGET_URL})

Diff for: include/cfddlcjs/cfddlcjs_struct.h

+54-43
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ struct AdaptorPairStruct {
4444
std::set<std::string> ignore_items; //!< using on JSON mapping convert.
4545
};
4646

47+
// ------------------------------------------------------------------------
48+
// MessagesStruct
49+
// ------------------------------------------------------------------------
50+
/**
51+
* @brief MessagesStruct struct
52+
*/
53+
struct MessagesStruct {
54+
std::vector<std::string> messages; //!< messages // NOLINT
55+
std::set<std::string> ignore_items; //!< using on JSON mapping convert.
56+
};
57+
4758
// ------------------------------------------------------------------------
4859
// AddSignatureToFundTransactionRequestStruct
4960
// ------------------------------------------------------------------------
@@ -137,16 +148,16 @@ struct CreateCetResponseStruct {
137148
* @brief CreateCetAdaptorSignatureRequestStruct struct
138149
*/
139150
struct CreateCetAdaptorSignatureRequestStruct {
140-
std::string cet_hex = ""; //!< cet_hex // NOLINT
141-
std::string privkey = ""; //!< privkey // NOLINT
142-
std::string fund_tx_id = ""; //!< fund_tx_id // NOLINT
143-
uint32_t fund_vout = 0; //!< fund_vout // NOLINT
144-
std::string local_fund_pubkey = ""; //!< local_fund_pubkey // NOLINT
145-
std::string remote_fund_pubkey = ""; //!< remote_fund_pubkey // NOLINT
146-
std::string oracle_pubkey = ""; //!< oracle_pubkey // NOLINT
147-
std::string oracle_r_value = ""; //!< oracle_r_value // NOLINT
148-
uint64_t fund_input_amount = 0; //!< fund_input_amount // NOLINT
149-
std::string message = ""; //!< message // NOLINT
151+
std::string cet_hex = ""; //!< cet_hex // NOLINT
152+
std::string privkey = ""; //!< privkey // NOLINT
153+
std::string fund_tx_id = ""; //!< fund_tx_id // NOLINT
154+
uint32_t fund_vout = 0; //!< fund_vout // NOLINT
155+
std::string local_fund_pubkey = ""; //!< local_fund_pubkey // NOLINT
156+
std::string remote_fund_pubkey = ""; //!< remote_fund_pubkey // NOLINT
157+
std::string oracle_pubkey = ""; //!< oracle_pubkey // NOLINT
158+
std::vector<std::string> oracle_r_values; //!< oracle_r_values // NOLINT
159+
uint64_t fund_input_amount = 0; //!< fund_input_amount // NOLINT
160+
std::vector<std::string> messages; //!< messages // NOLINT
150161
std::set<std::string> ignore_items; //!< using on JSON mapping convert.
151162
};
152163

@@ -170,16 +181,16 @@ struct CreateCetAdaptorSignatureResponseStruct {
170181
* @brief CreateCetAdaptorSignaturesRequestStruct struct
171182
*/
172183
struct CreateCetAdaptorSignaturesRequestStruct {
173-
std::vector<std::string> cets_hex; //!< cets_hex // NOLINT
174-
std::string privkey = ""; //!< privkey // NOLINT
175-
std::string fund_tx_id = ""; //!< fund_tx_id // NOLINT
176-
uint32_t fund_vout = 0; //!< fund_vout // NOLINT
177-
std::string local_fund_pubkey = ""; //!< local_fund_pubkey // NOLINT
178-
std::string remote_fund_pubkey = ""; //!< remote_fund_pubkey // NOLINT
179-
std::string oracle_pubkey = ""; //!< oracle_pubkey // NOLINT
180-
std::string oracle_r_value = ""; //!< oracle_r_value // NOLINT
181-
uint64_t fund_input_amount = 0; //!< fund_input_amount // NOLINT
182-
std::vector<std::string> messages; //!< messages // NOLINT
184+
std::vector<std::string> cets_hex; //!< cets_hex // NOLINT
185+
std::string privkey = ""; //!< privkey // NOLINT
186+
std::string fund_tx_id = ""; //!< fund_tx_id // NOLINT
187+
uint32_t fund_vout = 0; //!< fund_vout // NOLINT
188+
std::string local_fund_pubkey = ""; //!< local_fund_pubkey // NOLINT
189+
std::string remote_fund_pubkey = ""; //!< remote_fund_pubkey // NOLINT
190+
std::string oracle_pubkey = ""; //!< oracle_pubkey // NOLINT
191+
std::vector<std::string> oracle_r_values; //!< oracle_r_values // NOLINT
192+
uint64_t fund_input_amount = 0; //!< fund_input_amount // NOLINT
193+
std::vector<MessagesStruct> messages_list; //!< messages_list // NOLINT
183194
std::set<std::string> ignore_items; //!< using on JSON mapping convert.
184195
};
185196

@@ -412,15 +423,15 @@ struct GetRawRefundTxSignatureResponseStruct {
412423
* @brief SignCetRequestStruct struct
413424
*/
414425
struct SignCetRequestStruct {
415-
std::string cet_hex = ""; //!< cet_hex // NOLINT
416-
std::string fund_privkey = ""; //!< fund_privkey // NOLINT
417-
std::string fund_tx_id = ""; //!< fund_tx_id // NOLINT
418-
uint32_t fund_vout = 0; //!< fund_vout // NOLINT
419-
std::string local_fund_pubkey = ""; //!< local_fund_pubkey // NOLINT
420-
std::string remote_fund_pubkey = ""; //!< remote_fund_pubkey // NOLINT
421-
uint64_t fund_input_amount = 0; //!< fund_input_amount // NOLINT
422-
std::string adaptor_signature = ""; //!< adaptor_signature // NOLINT
423-
std::string oracle_signature = ""; //!< oracle_signature // NOLINT
426+
std::string cet_hex = ""; //!< cet_hex // NOLINT
427+
std::string fund_privkey = ""; //!< fund_privkey // NOLINT
428+
std::string fund_tx_id = ""; //!< fund_tx_id // NOLINT
429+
uint32_t fund_vout = 0; //!< fund_vout // NOLINT
430+
std::string local_fund_pubkey = ""; //!< local_fund_pubkey // NOLINT
431+
std::string remote_fund_pubkey = ""; //!< remote_fund_pubkey // NOLINT
432+
uint64_t fund_input_amount = 0; //!< fund_input_amount // NOLINT
433+
std::string adaptor_signature = ""; //!< adaptor_signature // NOLINT
434+
std::vector<std::string> oracle_signatures; //!< oracle_signatures // NOLINT
424435
std::set<std::string> ignore_items; //!< using on JSON mapping convert.
425436
};
426437

@@ -470,18 +481,18 @@ struct SignFundTransactionResponseStruct {
470481
* @brief VerifyCetAdaptorSignatureRequestStruct struct
471482
*/
472483
struct VerifyCetAdaptorSignatureRequestStruct {
473-
std::string cet_hex = ""; //!< cet_hex // NOLINT
474-
std::string adaptor_signature = ""; //!< adaptor_signature // NOLINT
475-
std::string adaptor_proof = ""; //!< adaptor_proof // NOLINT
476-
std::string message = ""; //!< message // NOLINT
477-
std::string local_fund_pubkey = ""; //!< local_fund_pubkey // NOLINT
478-
std::string remote_fund_pubkey = ""; //!< remote_fund_pubkey // NOLINT
479-
std::string oracle_pubkey = ""; //!< oracle_pubkey // NOLINT
480-
std::string oracle_r_value = ""; //!< oracle_r_value // NOLINT
481-
std::string fund_tx_id = ""; //!< fund_tx_id // NOLINT
482-
uint32_t fund_vout = 0; //!< fund_vout // NOLINT
483-
uint64_t fund_input_amount = 0; //!< fund_input_amount // NOLINT
484-
bool verify_remote = true; //!< verify_remote // NOLINT
484+
std::string cet_hex = ""; //!< cet_hex // NOLINT
485+
std::string adaptor_signature = ""; //!< adaptor_signature // NOLINT
486+
std::string adaptor_proof = ""; //!< adaptor_proof // NOLINT
487+
std::vector<std::string> messages; //!< messages // NOLINT
488+
std::string local_fund_pubkey = ""; //!< local_fund_pubkey // NOLINT
489+
std::string remote_fund_pubkey = ""; //!< remote_fund_pubkey // NOLINT
490+
std::string oracle_pubkey = ""; //!< oracle_pubkey // NOLINT
491+
std::vector<std::string> oracle_r_values; //!< oracle_r_values // NOLINT
492+
std::string fund_tx_id = ""; //!< fund_tx_id // NOLINT
493+
uint32_t fund_vout = 0; //!< fund_vout // NOLINT
494+
uint64_t fund_input_amount = 0; //!< fund_input_amount // NOLINT
495+
bool verify_remote = true; //!< verify_remote // NOLINT
485496
std::set<std::string> ignore_items; //!< using on JSON mapping convert.
486497
};
487498

@@ -506,11 +517,11 @@ struct VerifyCetAdaptorSignatureResponseStruct {
506517
struct VerifyCetAdaptorSignaturesRequestStruct {
507518
std::vector<std::string> cets_hex; //!< cets_hex // NOLINT
508519
std::vector<AdaptorPairStruct> adaptor_pairs; //!< adaptor_pairs // NOLINT
509-
std::vector<std::string> messages; //!< messages // NOLINT
520+
std::vector<MessagesStruct> messages_list; //!< messages_list // NOLINT
510521
std::string local_fund_pubkey = ""; //!< local_fund_pubkey // NOLINT
511522
std::string remote_fund_pubkey = ""; //!< remote_fund_pubkey // NOLINT
512523
std::string oracle_pubkey = ""; //!< oracle_pubkey // NOLINT
513-
std::string oracle_r_value = ""; //!< oracle_r_value // NOLINT
524+
std::vector<std::string> oracle_r_values; //!< oracle_r_values // NOLINT
514525
std::string fund_tx_id = ""; //!< fund_tx_id // NOLINT
515526
uint32_t fund_vout = 0; //!< fund_vout // NOLINT
516527
uint64_t fund_input_amount = 0; //!< fund_input_amount // NOLINT

Diff for: include/cfddlcjs/cfddlcjs_transactions.h

+11
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@
1616

1717
#include "cfdcore/cfdcore_hdwallet.h"
1818
#include "cfdcore/cfdcore_key.h"
19+
#include "cfdcore/cfdcore_schnorrsig.h"
1920
#include "cfddlcjs/cfddlcjs_struct.h"
2021

2122
namespace cfd {
2223
namespace dlc {
2324
namespace js {
2425
namespace api {
2526

27+
using cfd::core::ByteData256;
2628
using cfd::core::ExtPrivkey;
2729
using cfd::core::ExtPubkey;
2830
using cfd::core::Privkey;
2931
using cfd::core::Pubkey;
32+
using cfd::core::SchnorrPubkey;
33+
using cfd::core::SchnorrSignature;
3034

3135
class DlcTransactionsApi {
3236
public:
@@ -66,6 +70,13 @@ class DlcTransactionsApi {
6670
private:
6771
DlcTransactionsApi();
6872
static std::vector<Pubkey> ParsePubkeys(std::vector<std::string> input);
73+
static std::vector<SchnorrPubkey> ParseSchnorrPubkeys(
74+
std::vector<std::string> input);
75+
static std::vector<SchnorrSignature> ParseSchnorrSignatures(
76+
std::vector<std::string> input);
77+
static std::vector<ByteData256> HashMessages(std::vector<std::string> input);
78+
static std::vector<std::vector<ByteData256>> HashMessages(
79+
std::vector<MessagesStruct> input);
6980
};
7081

7182
} // namespace api

Diff for: index.d.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export interface CreateCetAdaptorSignatureRequest {
4242
localFundPubkey: string;
4343
remoteFundPubkey: string;
4444
oraclePubkey: string;
45-
oracleRValue: string;
45+
oracleRValues: string[];
4646
fundInputAmount: bigint | number;
47-
message: string;
47+
messages: string[];
4848
}
4949

5050
export interface CreateCetAdaptorSignatureResponse {
@@ -61,9 +61,9 @@ export interface CreateCetAdaptorSignaturesRequest {
6161
localFundPubkey: string;
6262
remoteFundPubkey: string;
6363
oraclePubkey: string;
64-
oracleRValue: string;
64+
oracleRValues: string[];
6565
fundInputAmount: bigint | number;
66-
messages: string[];
66+
messagesList: Messages[];
6767
}
6868

6969
export interface CreateCetAdaptorSignaturesResponse {
@@ -187,6 +187,10 @@ export interface InnerErrorResponse {
187187
message: string;
188188
}
189189

190+
export interface Messages {
191+
messages: string[];
192+
}
193+
190194
export interface PayoutRequest {
191195
local: bigint | number;
192196
remote: bigint | number;
@@ -202,7 +206,7 @@ export interface SignCetRequest {
202206
remoteFundPubkey: string;
203207
fundInputAmount: bigint | number;
204208
adaptorSignature: string;
205-
oracleSignature: string;
209+
oracleSignatures: string[];
206210
}
207211

208212
export interface SignCetResponse {
@@ -244,11 +248,11 @@ export interface VerifyCetAdaptorSignatureRequest {
244248
cetHex: string;
245249
adaptorSignature: string;
246250
adaptorProof: string;
247-
message: string;
251+
messages: string[];
248252
localFundPubkey: string;
249253
remoteFundPubkey: string;
250254
oraclePubkey: string;
251-
oracleRValue: string;
255+
oracleRValues: string[];
252256
fundTxId: string;
253257
fundVout?: number;
254258
fundInputAmount: bigint | number;
@@ -263,11 +267,11 @@ export interface VerifyCetAdaptorSignatureResponse {
263267
export interface VerifyCetAdaptorSignaturesRequest {
264268
cetsHex: string[];
265269
adaptorPairs: AdaptorPair[];
266-
messages: string[];
270+
messagesList: Messages[];
267271
localFundPubkey: string;
268272
remoteFundPubkey: string;
269273
oraclePubkey: string;
270-
oracleRValue: string;
274+
oracleRValues: string[];
271275
fundTxId: string;
272276
fundVout?: number;
273277
fundInputAmount: bigint | number;

Diff for: integration_tests/__tests__/dlctests.spec.ts

+21-16
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ describe("dlc tests", () => {
2121

2222
await testHelper.Initialize();
2323

24-
const oracleSignature = CfdUtils.SchnorrSign(
25-
testHelper.winMessage,
26-
testHelper.oracleKey,
27-
testHelper.oracleKValue
24+
const oracleSignatures = testHelper.winMessages.map((m, i) =>
25+
CfdUtils.SchnorrSign(
26+
m,
27+
testHelper.oracleKey,
28+
testHelper.oracleKValues[i]
29+
)
2830
);
2931

3032
expect(
31-
CfdUtils.SchnorrVerify(
32-
testHelper.winMessage,
33-
oracleSignature,
34-
testHelper.oraclePubkey
33+
oracleSignatures.every((s, i) =>
34+
CfdUtils.SchnorrVerify(
35+
testHelper.winMessages[i],
36+
s,
37+
testHelper.oraclePubkey
38+
)
3539
)
3640
).toBeTruthy();
3741

@@ -45,7 +49,7 @@ describe("dlc tests", () => {
4549
dlctxs.cetsHex,
4650
testHelper.aliceFundPrivkey,
4751
testHelper.oraclePubkey,
48-
testHelper.oracleRValue,
52+
testHelper.oracleRValues,
4953
testHelper.messages,
5054
fundTx.txid,
5155
0,
@@ -59,7 +63,7 @@ describe("dlc tests", () => {
5963
localAdaptorPairs,
6064
testHelper.messages,
6165
testHelper.oraclePubkey,
62-
testHelper.oracleRValue,
66+
testHelper.oracleRValues,
6367
testHelper.aliceFundPubkey,
6468
testHelper.bobFundPubkey,
6569
fundTxId,
@@ -73,7 +77,7 @@ describe("dlc tests", () => {
7377
dlctxs.cetsHex,
7478
testHelper.bobFundPrivkey,
7579
testHelper.oraclePubkey,
76-
testHelper.oracleRValue,
80+
testHelper.oracleRValues,
7781
testHelper.messages,
7882
fundTx.txid,
7983
0,
@@ -87,7 +91,7 @@ describe("dlc tests", () => {
8791
remoteAdaptorPairs,
8892
testHelper.messages,
8993
testHelper.oraclePubkey,
90-
testHelper.oracleRValue,
94+
testHelper.oracleRValues,
9195
testHelper.aliceFundPubkey,
9296
testHelper.bobFundPubkey,
9397
fundTxId,
@@ -143,10 +147,9 @@ describe("dlc tests", () => {
143147
fundInputAmount,
144148
remoteAdaptorPairs[0].signature,
145149
testHelper.aliceFundPrivkey,
146-
oracleSignature,
150+
oracleSignatures,
147151
testHelper.aliceFundPubkey,
148-
testHelper.bobFundPubkey,
149-
true
152+
testHelper.bobFundPubkey
150153
);
151154
const cet = CfdUtils.DecodeRawTransaction(cetHex);
152155

@@ -197,7 +200,9 @@ describe("dlc tests", () => {
197200
testHelper.bobInputPrv
198201
);
199202

200-
const fundTxId = await testHelper.aliceWallet.sendRawTransaction(fundTxHex);
203+
const fundTxId = await testHelper.aliceWallet.sendRawTransaction(
204+
fundTxHex
205+
);
201206

202207
const fundTx = CfdUtils.DecodeRawTransaction(fundTxHex);
203208

Diff for: integration_tests/__tests__/test_helper.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ export class DlcTestHelper {
99
readonly bobWallet;
1010
readonly oracleKey =
1111
"85e9cf11bd33a4ccc6abf6c5078e2a7e44aff9c456934976cb86cffe3e1e13dc";
12-
readonly oracleKValue =
13-
"8864177b5ec22563e9b325c11726a270d259b7adc16a2051d9d9256eede64c79";
12+
readonly oracleKValues = [
13+
"8864177b5ec22563e9b325c11726a270d259b7adc16a2051d9d9256eede64c79",
14+
"9e1bc6dc95ce931903cc2df67640cf6cca94ddd96aab0b847780d644e46cfae3",
15+
];
1416
readonly oraclePubkey = CfdUtils.GetSchnorrPubkeyFromPrivkey(this.oracleKey);
15-
readonly oracleRValue = CfdUtils.GetSchnorrPubkeyFromPrivkey(
16-
this.oracleKValue
17+
readonly oracleRValues = this.oracleKValues.map((x) =>
18+
CfdUtils.GetSchnorrPubkeyFromPrivkey(x)
1719
);
1820

19-
readonly winMessage = "WIN";
20-
readonly loseMessage = "LOSE";
21-
readonly messages = [this.winMessage, this.loseMessage];
21+
readonly winMessages = ["1", "0"];
22+
readonly loseMessages = ["0", "1"];
23+
readonly messages = [this.winMessages, this.loseMessages];
2224
readonly winAmount = 9990000;
2325
readonly loseAmount = 10000;
2426
readonly collateral = (this.winAmount + this.loseAmount) / 2;

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cfd-dlc-js",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "cfd-dlc node.js api",
55
"domain": "p2pderivatives",
66
"main": "index.js",

0 commit comments

Comments
 (0)