@@ -2,13 +2,15 @@ var DashJoin = ('object' === typeof module && exports) || {};
2
2
( function ( window , DashJoin ) {
3
3
'use strict' ;
4
4
5
- // let DashTx = window.DashTx || require('dashtx ');
5
+ let DashP2P = window . DashP2P || require ( 'dashp2p ' ) ;
6
6
7
7
const DENOM_LOWEST = 100001 ;
8
8
const PREDENOM_MIN = DENOM_LOWEST + 193 ;
9
9
const COLLATERAL = 10000 ; // DENOM_LOWEST / 10
10
10
const PAYLOAD_SIZE_MAX = 4 * 1024 * 1024 ;
11
11
12
+ const DSQ_SIZE = 1 ; // 1-byte bool
13
+
12
14
// https://github.com/dashpay/dash/blob/v19.x/src/coinjoin/coinjoin.h#L39
13
15
// const COINJOIN_ENTRY_MAX_SIZE = 9; // real
14
16
// const COINJOIN_ENTRY_MAX_SIZE = 2; // just for testing right now
@@ -27,6 +29,10 @@ var DashJoin = ('object' === typeof module && exports) || {};
27
29
let reverseDenoms = DashJoin . DENOMS . slice ( 0 ) ;
28
30
reverseDenoms . reverse ( ) ;
29
31
32
+ let Packers = { } ;
33
+ let Parsers = { } ;
34
+ let Utils = { } ;
35
+
30
36
// Ask Niles if there's an layman-ish obvious way to do this
31
37
DashJoin . getDenom = function ( sats ) {
32
38
for ( let denom of reverseDenoms ) {
@@ -39,9 +45,39 @@ var DashJoin = ('object' === typeof module && exports) || {};
39
45
return 0 ;
40
46
} ;
41
47
42
- DashJoin . utils = { } ;
48
+ /**
49
+ * Turns on or off DSQ messages (necessary for CoinJoin, but off by default)
50
+ * @param {Object } opts
51
+ * @param {NetworkName } opts.network - "mainnet", "testnet", etc
52
+ * @param {Uint8Array? } [opts.message]
53
+ * @param {Boolean? } [opts.send]
54
+ */
55
+ Packers . senddsq = function ( { network, message = null , send = true } ) {
56
+ // const command = 'senddsq';
57
+ // if (!message) {
58
+ // let dsqSize = DashP2P.sizes.HEADER_SIZE + DSQ_SIZE;
59
+ // message = new Uint8Array(dsqSize);
60
+ // }
61
+
62
+ let payload = new Uint8Array ( 1 ) ;
63
+ if ( send ) {
64
+ payload . set ( [ 0x01 ] , 0 ) ;
65
+ } else {
66
+ payload . set ( [ 0x00 ] , 0 ) ;
67
+ }
43
68
44
- DashJoin . utils . hexToBytes = function ( hex ) {
69
+ // let payload = message.subarray(DashP2P.sizes.HEADER_SIZE);
70
+ // payload.set(sendByte, 0);
71
+ // void DashP2P.packers.message({ network, command, bytes: message });
72
+ // return {
73
+ // message,
74
+ // payload,
75
+ // };
76
+
77
+ return payload ;
78
+ } ;
79
+
80
+ Utils . hexToBytes = function ( hex ) {
45
81
let bufLen = hex . length / 2 ;
46
82
let u8 = new Uint8Array ( bufLen ) ;
47
83
@@ -64,7 +100,7 @@ var DashJoin = ('object' === typeof module && exports) || {};
64
100
return u8 ;
65
101
} ;
66
102
67
- DashJoin . utils . bytesToHex = function ( u8 ) {
103
+ Utils . bytesToHex = function ( u8 ) {
68
104
/** @type {Array<String> } */
69
105
let hex = [ ] ;
70
106
@@ -76,7 +112,7 @@ var DashJoin = ('object' === typeof module && exports) || {};
76
112
return hex . join ( '' ) ;
77
113
} ;
78
114
79
- DashJoin . utils . _evonodeMapToList = function ( evonodesMap ) {
115
+ Utils . _evonodeMapToList = function ( evonodesMap ) {
80
116
console . log ( '[debug] get evonode list...' ) ;
81
117
let evonodes = [ ] ;
82
118
{
@@ -104,7 +140,7 @@ var DashJoin = ('object' === typeof module && exports) || {};
104
140
}
105
141
106
142
// void shuffle(evonodes);
107
- evonodes . sort ( DashJoin . utils . sortMnListById ) ;
143
+ evonodes . sort ( Utils . sortMnListById ) ;
108
144
return evonodes ;
109
145
} ;
110
146
@@ -114,7 +150,7 @@ var DashJoin = ('object' === typeof module && exports) || {};
114
150
* @param {Object } b
115
151
* @param {String } b.id
116
152
*/
117
- DashJoin . utils . sortMnListById = function ( a , b ) {
153
+ Utils . sortMnListById = function ( a , b ) {
118
154
if ( a . id > b . id ) {
119
155
return 1 ;
120
156
}
@@ -124,6 +160,10 @@ var DashJoin = ('object' === typeof module && exports) || {};
124
160
return 0 ;
125
161
} ;
126
162
163
+ DashJoin . packers = Packers ;
164
+ DashJoin . parsers = Parsers ;
165
+ DashJoin . utils = Utils ;
166
+
127
167
//@ts -ignore
128
168
window . DashJoin = DashJoin ;
129
169
} ) ( globalThis . window || { } , DashJoin ) ;
0 commit comments