@waku/core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/CHANGELOG.md +614 -0
  2. package/README.md +56 -0
  3. package/bundle/browser-1e1a2f27.js +722 -0
  4. package/bundle/crypto-8551d579.js +2585 -0
  5. package/bundle/crypto-b00764b7.js +1772 -0
  6. package/bundle/enr-564d4a51.js +20785 -0
  7. package/bundle/enr-9fc5eed8.js +20786 -0
  8. package/bundle/enr-f6e82a53.js +20785 -0
  9. package/bundle/events-158407bb.js +1929 -0
  10. package/bundle/events-fcbda4dc.js +76 -0
  11. package/bundle/index-02d21809.js +20 -0
  12. package/bundle/index-0a4bdddc.js +2976 -0
  13. package/bundle/index-2ae915be.js +1854 -0
  14. package/bundle/index-64ce43f0.js +69 -0
  15. package/bundle/index-691c0be6.js +4059 -0
  16. package/bundle/index-a013a259.js +20 -0
  17. package/bundle/index-ba42b4fc.js +862 -0
  18. package/bundle/index.js +13428 -0
  19. package/bundle/lib/enr.js +8 -0
  20. package/bundle/lib/peer_discovery_dns.js +5018 -0
  21. package/bundle/lib/peer_discovery_static_list.js +75 -0
  22. package/bundle/lib/predefined_bootstrap_nodes.js +59 -0
  23. package/bundle/lib/utils.js +1 -0
  24. package/bundle/lib/wait_for_remote_peer.js +327 -0
  25. package/bundle/lib/waku_message/topic_only_message.js +4 -0
  26. package/bundle/lib/waku_message/version_0.js +4 -0
  27. package/bundle/lib/waku_message/version_1.js +463 -0
  28. package/bundle/message-e2db79d7.js +8393 -0
  29. package/bundle/multiaddr_to_peer_info-c406b1e1.js +19 -0
  30. package/bundle/multiaddr_to_peer_info-fd1de516.js +19 -0
  31. package/bundle/random_subset-75d1c511.js +26 -0
  32. package/bundle/topic_only_message-34f36fa6.js +82 -0
  33. package/bundle/utils-9a3221f2.js +815 -0
  34. package/bundle/version_0-e6fe440c.js +317 -0
  35. package/dist/index.d.ts +16 -0
  36. package/dist/index.js +17 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/lib/constants.d.ts +4 -0
  39. package/dist/lib/constants.js +5 -0
  40. package/dist/lib/constants.js.map +1 -0
  41. package/dist/lib/crypto.d.ts +34 -0
  42. package/dist/lib/crypto.js +79 -0
  43. package/dist/lib/crypto.js.map +1 -0
  44. package/dist/lib/enr/constants.d.ts +4 -0
  45. package/dist/lib/enr/constants.js +8 -0
  46. package/dist/lib/enr/constants.js.map +1 -0
  47. package/dist/lib/enr/enr.d.ts +90 -0
  48. package/dist/lib/enr/enr.js +432 -0
  49. package/dist/lib/enr/enr.js.map +1 -0
  50. package/dist/lib/enr/index.d.ts +5 -0
  51. package/dist/lib/enr/index.js +6 -0
  52. package/dist/lib/enr/index.js.map +1 -0
  53. package/dist/lib/enr/keypair/index.d.ts +8 -0
  54. package/dist/lib/enr/keypair/index.js +53 -0
  55. package/dist/lib/enr/keypair/index.js.map +1 -0
  56. package/dist/lib/enr/keypair/secp256k1.d.ts +13 -0
  57. package/dist/lib/enr/keypair/secp256k1.js +57 -0
  58. package/dist/lib/enr/keypair/secp256k1.js.map +1 -0
  59. package/dist/lib/enr/keypair/types.d.ts +13 -0
  60. package/dist/lib/enr/keypair/types.js +7 -0
  61. package/dist/lib/enr/keypair/types.js.map +1 -0
  62. package/dist/lib/enr/multiaddr_from_fields.d.ts +2 -0
  63. package/dist/lib/enr/multiaddr_from_fields.js +8 -0
  64. package/dist/lib/enr/multiaddr_from_fields.js.map +1 -0
  65. package/dist/lib/enr/multiaddrs_codec.d.ts +3 -0
  66. package/dist/lib/enr/multiaddrs_codec.js +32 -0
  67. package/dist/lib/enr/multiaddrs_codec.js.map +1 -0
  68. package/dist/lib/enr/types.d.ts +8 -0
  69. package/dist/lib/enr/types.js +3 -0
  70. package/dist/lib/enr/types.js.map +1 -0
  71. package/dist/lib/enr/v4.d.ts +3 -0
  72. package/dist/lib/enr/v4.js +14 -0
  73. package/dist/lib/enr/v4.js.map +1 -0
  74. package/dist/lib/enr/waku2_codec.d.ts +8 -0
  75. package/dist/lib/enr/waku2_codec.js +36 -0
  76. package/dist/lib/enr/waku2_codec.js.map +1 -0
  77. package/dist/lib/group_by.d.ts +3 -0
  78. package/dist/lib/group_by.js +13 -0
  79. package/dist/lib/group_by.js.map +1 -0
  80. package/dist/lib/multiaddr_to_peer_info.d.ts +3 -0
  81. package/dist/lib/multiaddr_to_peer_info.js +15 -0
  82. package/dist/lib/multiaddr_to_peer_info.js.map +1 -0
  83. package/dist/lib/peer_discovery_dns/dns.d.ts +48 -0
  84. package/dist/lib/peer_discovery_dns/dns.js +158 -0
  85. package/dist/lib/peer_discovery_dns/dns.js.map +1 -0
  86. package/dist/lib/peer_discovery_dns/dns_over_https.d.ts +32 -0
  87. package/dist/lib/peer_discovery_dns/dns_over_https.js +87 -0
  88. package/dist/lib/peer_discovery_dns/dns_over_https.js.map +1 -0
  89. package/dist/lib/peer_discovery_dns/enrtree.d.ts +33 -0
  90. package/dist/lib/peer_discovery_dns/enrtree.js +76 -0
  91. package/dist/lib/peer_discovery_dns/enrtree.js.map +1 -0
  92. package/dist/lib/peer_discovery_dns/fetch_nodes.d.ts +14 -0
  93. package/dist/lib/peer_discovery_dns/fetch_nodes.js +133 -0
  94. package/dist/lib/peer_discovery_dns/fetch_nodes.js.map +1 -0
  95. package/dist/lib/peer_discovery_dns/index.d.ts +30 -0
  96. package/dist/lib/peer_discovery_dns/index.js +54 -0
  97. package/dist/lib/peer_discovery_dns/index.js.map +1 -0
  98. package/dist/lib/peer_discovery_static_list.d.ts +44 -0
  99. package/dist/lib/peer_discovery_static_list.js +72 -0
  100. package/dist/lib/peer_discovery_static_list.js.map +1 -0
  101. package/dist/lib/predefined_bootstrap_nodes.d.ts +35 -0
  102. package/dist/lib/predefined_bootstrap_nodes.js +56 -0
  103. package/dist/lib/predefined_bootstrap_nodes.js.map +1 -0
  104. package/dist/lib/push_or_init_map.d.ts +1 -0
  105. package/dist/lib/push_or_init_map.js +9 -0
  106. package/dist/lib/push_or_init_map.js.map +1 -0
  107. package/dist/lib/random_subset.d.ts +4 -0
  108. package/dist/lib/random_subset.js +25 -0
  109. package/dist/lib/random_subset.js.map +1 -0
  110. package/dist/lib/select_connection.d.ts +2 -0
  111. package/dist/lib/select_connection.js +19 -0
  112. package/dist/lib/select_connection.js.map +1 -0
  113. package/dist/lib/select_peer.d.ts +15 -0
  114. package/dist/lib/select_peer.js +59 -0
  115. package/dist/lib/select_peer.js.map +1 -0
  116. package/dist/lib/to_proto_message.d.ts +3 -0
  117. package/dist/lib/to_proto_message.js +11 -0
  118. package/dist/lib/to_proto_message.js.map +1 -0
  119. package/dist/lib/utils.d.ts +22 -0
  120. package/dist/lib/utils.js +40 -0
  121. package/dist/lib/utils.js.map +1 -0
  122. package/dist/lib/wait_for_remote_peer.d.ts +22 -0
  123. package/dist/lib/wait_for_remote_peer.js +113 -0
  124. package/dist/lib/wait_for_remote_peer.js.map +1 -0
  125. package/dist/lib/waku.d.ts +61 -0
  126. package/dist/lib/waku.js +174 -0
  127. package/dist/lib/waku.js.map +1 -0
  128. package/dist/lib/waku_filter/filter_rpc.d.ts +25 -0
  129. package/dist/lib/waku_filter/filter_rpc.js +44 -0
  130. package/dist/lib/waku_filter/filter_rpc.js.map +1 -0
  131. package/dist/lib/waku_filter/index.d.ts +50 -0
  132. package/dist/lib/waku_filter/index.js +181 -0
  133. package/dist/lib/waku_filter/index.js.map +1 -0
  134. package/dist/lib/waku_light_push/index.d.ts +38 -0
  135. package/dist/lib/waku_light_push/index.js +83 -0
  136. package/dist/lib/waku_light_push/index.js.map +1 -0
  137. package/dist/lib/waku_light_push/push_rpc.d.ts +11 -0
  138. package/dist/lib/waku_light_push/push_rpc.js +31 -0
  139. package/dist/lib/waku_light_push/push_rpc.js.map +1 -0
  140. package/dist/lib/waku_message/constants.d.ts +12 -0
  141. package/dist/lib/waku_message/constants.js +10 -0
  142. package/dist/lib/waku_message/constants.js.map +1 -0
  143. package/dist/lib/waku_message/ecies.d.ts +17 -0
  144. package/dist/lib/waku_message/ecies.js +126 -0
  145. package/dist/lib/waku_message/ecies.js.map +1 -0
  146. package/dist/lib/waku_message/symmetric.d.ts +3 -0
  147. package/dist/lib/waku_message/symmetric.js +18 -0
  148. package/dist/lib/waku_message/symmetric.js.map +1 -0
  149. package/dist/lib/waku_message/topic_only_message.d.ts +15 -0
  150. package/dist/lib/waku_message/topic_only_message.js +31 -0
  151. package/dist/lib/waku_message/topic_only_message.js.map +1 -0
  152. package/dist/lib/waku_message/version_0.d.ts +26 -0
  153. package/dist/lib/waku_message/version_0.js +96 -0
  154. package/dist/lib/waku_message/version_0.js.map +1 -0
  155. package/dist/lib/waku_message/version_1.d.ts +93 -0
  156. package/dist/lib/waku_message/version_1.js +325 -0
  157. package/dist/lib/waku_message/version_1.js.map +1 -0
  158. package/dist/lib/waku_relay/constants.d.ts +63 -0
  159. package/dist/lib/waku_relay/constants.js +67 -0
  160. package/dist/lib/waku_relay/constants.js.map +1 -0
  161. package/dist/lib/waku_relay/index.d.ts +65 -0
  162. package/dist/lib/waku_relay/index.js +111 -0
  163. package/dist/lib/waku_relay/index.js.map +1 -0
  164. package/dist/lib/waku_store/history_rpc.d.ts +27 -0
  165. package/dist/lib/waku_store/history_rpc.js +71 -0
  166. package/dist/lib/waku_store/history_rpc.js.map +1 -0
  167. package/dist/lib/waku_store/index.d.ts +126 -0
  168. package/dist/lib/waku_store/index.js +218 -0
  169. package/dist/lib/waku_store/index.js.map +1 -0
  170. package/dist/proto/filter.d.ts +65 -0
  171. package/dist/proto/filter.js +425 -0
  172. package/dist/proto/filter.js.map +1 -0
  173. package/dist/proto/light_push.d.ts +57 -0
  174. package/dist/proto/light_push.js +369 -0
  175. package/dist/proto/light_push.js.map +1 -0
  176. package/dist/proto/message.d.ts +29 -0
  177. package/dist/proto/message.js +215 -0
  178. package/dist/proto/message.js.map +1 -0
  179. package/dist/proto/store.d.ts +104 -0
  180. package/dist/proto/store.js +602 -0
  181. package/dist/proto/store.js.map +1 -0
  182. package/dist/proto/topic_only_message.d.ts +10 -0
  183. package/dist/proto/topic_only_message.js +46 -0
  184. package/dist/proto/topic_only_message.js.map +1 -0
  185. package/package.json +292 -0
  186. package/src/index.ts +33 -0
  187. package/src/lib/constants.ts +4 -0
  188. package/src/lib/crypto.ts +100 -0
  189. package/src/lib/enr/constants.ts +10 -0
  190. package/src/lib/enr/enr.ts +516 -0
  191. package/src/lib/enr/index.ts +5 -0
  192. package/src/lib/enr/keypair/index.ts +76 -0
  193. package/src/lib/enr/keypair/secp256k1.ts +69 -0
  194. package/src/lib/enr/keypair/types.ts +14 -0
  195. package/src/lib/enr/multiaddr_from_fields.ts +18 -0
  196. package/src/lib/enr/multiaddrs_codec.ts +50 -0
  197. package/src/lib/enr/types.ts +11 -0
  198. package/src/lib/enr/v4.ts +22 -0
  199. package/src/lib/enr/waku2_codec.ts +39 -0
  200. package/src/lib/group_by.ts +14 -0
  201. package/src/lib/multiaddr_to_peer_info.ts +17 -0
  202. package/src/lib/peer_discovery_dns/dns.ts +223 -0
  203. package/src/lib/peer_discovery_dns/dns_over_https.ts +98 -0
  204. package/src/lib/peer_discovery_dns/enrtree.ts +123 -0
  205. package/src/lib/peer_discovery_dns/fetch_nodes.ts +180 -0
  206. package/src/lib/peer_discovery_dns/index.ts +84 -0
  207. package/src/lib/peer_discovery_static_list.ts +118 -0
  208. package/src/lib/predefined_bootstrap_nodes.ts +72 -0
  209. package/src/lib/push_or_init_map.ts +13 -0
  210. package/src/lib/random_subset.ts +30 -0
  211. package/src/lib/select_connection.ts +24 -0
  212. package/src/lib/select_peer.ts +77 -0
  213. package/src/lib/to_proto_message.ts +15 -0
  214. package/src/lib/utils.ts +50 -0
  215. package/src/lib/wait_for_remote_peer.ts +151 -0
  216. package/src/lib/waku.ts +258 -0
  217. package/src/lib/waku_filter/filter_rpc.ts +57 -0
  218. package/src/lib/waku_filter/index.ts +291 -0
  219. package/src/lib/waku_light_push/index.ts +137 -0
  220. package/src/lib/waku_light_push/push_rpc.ts +39 -0
  221. package/src/lib/waku_message/constants.ts +10 -0
  222. package/src/lib/waku_message/ecies.ts +194 -0
  223. package/src/lib/waku_message/symmetric.ts +33 -0
  224. package/src/lib/waku_message/topic_only_message.ts +40 -0
  225. package/src/lib/waku_message/version_0.ts +121 -0
  226. package/src/lib/waku_message/version_1.ts +457 -0
  227. package/src/lib/waku_relay/constants.ts +77 -0
  228. package/src/lib/waku_relay/index.ts +189 -0
  229. package/src/lib/waku_store/history_rpc.ts +94 -0
  230. package/src/lib/waku_store/index.ts +372 -0
  231. package/src/proto/filter.ts +602 -0
  232. package/src/proto/light_push.ts +526 -0
  233. package/src/proto/message.ts +304 -0
  234. package/src/proto/store.ts +844 -0
  235. package/src/proto/topic_only_message.ts +67 -0
@@ -0,0 +1,317 @@
1
+ import { d as debug } from './browser-1e1a2f27.js';
2
+ import { m as message$1, e as encodeMessage, d as decodeMessage } from './message-e2db79d7.js';
3
+
4
+ /* eslint-disable import/export */
5
+ var RateLimitProof;
6
+ (function (RateLimitProof) {
7
+ let _codec;
8
+ RateLimitProof.codec = () => {
9
+ if (_codec == null) {
10
+ _codec = message$1((obj, writer, opts = {}) => {
11
+ if (opts.lengthDelimited !== false) {
12
+ writer.fork();
13
+ }
14
+ if (obj.proof != null) {
15
+ writer.uint32(10);
16
+ writer.bytes(obj.proof);
17
+ }
18
+ else {
19
+ throw new Error('Protocol error: required field "proof" was not found in object');
20
+ }
21
+ if (obj.merkleRoot != null) {
22
+ writer.uint32(18);
23
+ writer.bytes(obj.merkleRoot);
24
+ }
25
+ else {
26
+ throw new Error('Protocol error: required field "merkleRoot" was not found in object');
27
+ }
28
+ if (obj.epoch != null) {
29
+ writer.uint32(26);
30
+ writer.bytes(obj.epoch);
31
+ }
32
+ else {
33
+ throw new Error('Protocol error: required field "epoch" was not found in object');
34
+ }
35
+ if (obj.shareX != null) {
36
+ writer.uint32(34);
37
+ writer.bytes(obj.shareX);
38
+ }
39
+ else {
40
+ throw new Error('Protocol error: required field "shareX" was not found in object');
41
+ }
42
+ if (obj.shareY != null) {
43
+ writer.uint32(42);
44
+ writer.bytes(obj.shareY);
45
+ }
46
+ else {
47
+ throw new Error('Protocol error: required field "shareY" was not found in object');
48
+ }
49
+ if (obj.nullifier != null) {
50
+ writer.uint32(50);
51
+ writer.bytes(obj.nullifier);
52
+ }
53
+ else {
54
+ throw new Error('Protocol error: required field "nullifier" was not found in object');
55
+ }
56
+ if (obj.rlnIdentifier != null) {
57
+ writer.uint32(58);
58
+ writer.bytes(obj.rlnIdentifier);
59
+ }
60
+ else {
61
+ throw new Error('Protocol error: required field "rlnIdentifier" was not found in object');
62
+ }
63
+ if (opts.lengthDelimited !== false) {
64
+ writer.ldelim();
65
+ }
66
+ }, (reader, length) => {
67
+ const obj = {
68
+ proof: new Uint8Array(0),
69
+ merkleRoot: new Uint8Array(0),
70
+ epoch: new Uint8Array(0),
71
+ shareX: new Uint8Array(0),
72
+ shareY: new Uint8Array(0),
73
+ nullifier: new Uint8Array(0),
74
+ rlnIdentifier: new Uint8Array(0),
75
+ };
76
+ const end = length == null ? reader.len : reader.pos + length;
77
+ while (reader.pos < end) {
78
+ const tag = reader.uint32();
79
+ switch (tag >>> 3) {
80
+ case 1:
81
+ obj.proof = reader.bytes();
82
+ break;
83
+ case 2:
84
+ obj.merkleRoot = reader.bytes();
85
+ break;
86
+ case 3:
87
+ obj.epoch = reader.bytes();
88
+ break;
89
+ case 4:
90
+ obj.shareX = reader.bytes();
91
+ break;
92
+ case 5:
93
+ obj.shareY = reader.bytes();
94
+ break;
95
+ case 6:
96
+ obj.nullifier = reader.bytes();
97
+ break;
98
+ case 7:
99
+ obj.rlnIdentifier = reader.bytes();
100
+ break;
101
+ default:
102
+ reader.skipType(tag & 7);
103
+ break;
104
+ }
105
+ }
106
+ if (obj.proof == null) {
107
+ throw new Error('Protocol error: value for required field "proof" was not found in protobuf');
108
+ }
109
+ if (obj.merkleRoot == null) {
110
+ throw new Error('Protocol error: value for required field "merkleRoot" was not found in protobuf');
111
+ }
112
+ if (obj.epoch == null) {
113
+ throw new Error('Protocol error: value for required field "epoch" was not found in protobuf');
114
+ }
115
+ if (obj.shareX == null) {
116
+ throw new Error('Protocol error: value for required field "shareX" was not found in protobuf');
117
+ }
118
+ if (obj.shareY == null) {
119
+ throw new Error('Protocol error: value for required field "shareY" was not found in protobuf');
120
+ }
121
+ if (obj.nullifier == null) {
122
+ throw new Error('Protocol error: value for required field "nullifier" was not found in protobuf');
123
+ }
124
+ if (obj.rlnIdentifier == null) {
125
+ throw new Error('Protocol error: value for required field "rlnIdentifier" was not found in protobuf');
126
+ }
127
+ return obj;
128
+ });
129
+ }
130
+ return _codec;
131
+ };
132
+ RateLimitProof.encode = (obj) => {
133
+ return encodeMessage(obj, RateLimitProof.codec());
134
+ };
135
+ RateLimitProof.decode = (buf) => {
136
+ return decodeMessage(buf, RateLimitProof.codec());
137
+ };
138
+ })(RateLimitProof || (RateLimitProof = {}));
139
+ var WakuMessage;
140
+ (function (WakuMessage) {
141
+ let _codec;
142
+ WakuMessage.codec = () => {
143
+ if (_codec == null) {
144
+ _codec = message$1((obj, writer, opts = {}) => {
145
+ if (opts.lengthDelimited !== false) {
146
+ writer.fork();
147
+ }
148
+ if (obj.payload != null) {
149
+ writer.uint32(10);
150
+ writer.bytes(obj.payload);
151
+ }
152
+ if (obj.contentTopic != null) {
153
+ writer.uint32(18);
154
+ writer.string(obj.contentTopic);
155
+ }
156
+ if (obj.version != null) {
157
+ writer.uint32(24);
158
+ writer.uint32(obj.version);
159
+ }
160
+ if (obj.timestampDeprecated != null) {
161
+ writer.uint32(33);
162
+ writer.double(obj.timestampDeprecated);
163
+ }
164
+ if (obj.timestamp != null) {
165
+ writer.uint32(80);
166
+ writer.sint64(obj.timestamp);
167
+ }
168
+ if (obj.rateLimitProof != null) {
169
+ writer.uint32(170);
170
+ RateLimitProof.codec().encode(obj.rateLimitProof, writer);
171
+ }
172
+ if (opts.lengthDelimited !== false) {
173
+ writer.ldelim();
174
+ }
175
+ }, (reader, length) => {
176
+ const obj = {};
177
+ const end = length == null ? reader.len : reader.pos + length;
178
+ while (reader.pos < end) {
179
+ const tag = reader.uint32();
180
+ switch (tag >>> 3) {
181
+ case 1:
182
+ obj.payload = reader.bytes();
183
+ break;
184
+ case 2:
185
+ obj.contentTopic = reader.string();
186
+ break;
187
+ case 3:
188
+ obj.version = reader.uint32();
189
+ break;
190
+ case 4:
191
+ obj.timestampDeprecated = reader.double();
192
+ break;
193
+ case 10:
194
+ obj.timestamp = reader.sint64();
195
+ break;
196
+ case 21:
197
+ obj.rateLimitProof = RateLimitProof.codec().decode(reader, reader.uint32());
198
+ break;
199
+ default:
200
+ reader.skipType(tag & 7);
201
+ break;
202
+ }
203
+ }
204
+ return obj;
205
+ });
206
+ }
207
+ return _codec;
208
+ };
209
+ WakuMessage.encode = (obj) => {
210
+ return encodeMessage(obj, WakuMessage.codec());
211
+ };
212
+ WakuMessage.decode = (buf) => {
213
+ return decodeMessage(buf, WakuMessage.codec());
214
+ };
215
+ })(WakuMessage || (WakuMessage = {}));
216
+
217
+ var message = /*#__PURE__*/Object.freeze({
218
+ __proto__: null,
219
+ get RateLimitProof () { return RateLimitProof; },
220
+ get WakuMessage () { return WakuMessage; }
221
+ });
222
+
223
+ const log = debug("waku:message:version-0");
224
+ const OneMillion = BigInt(1000000);
225
+ const Version = 0;
226
+ class MessageV0 {
227
+ constructor(proto) {
228
+ this.proto = proto;
229
+ }
230
+ get _rawPayload() {
231
+ if (this.proto.payload) {
232
+ return new Uint8Array(this.proto.payload);
233
+ }
234
+ return;
235
+ }
236
+ get payload() {
237
+ return this._rawPayload;
238
+ }
239
+ get contentTopic() {
240
+ return this.proto.contentTopic;
241
+ }
242
+ get _rawTimestamp() {
243
+ return this.proto.timestamp;
244
+ }
245
+ get timestamp() {
246
+ // In the case we receive a value that is bigger than JS's max number,
247
+ // we catch the error and return undefined.
248
+ try {
249
+ if (this.proto.timestamp) {
250
+ // nanoseconds 10^-9 to milliseconds 10^-3
251
+ const timestamp = this.proto.timestamp / OneMillion;
252
+ return new Date(Number(timestamp));
253
+ }
254
+ if (this.proto.timestampDeprecated) {
255
+ return new Date(this.proto.timestampDeprecated * 1000);
256
+ }
257
+ }
258
+ catch (e) {
259
+ return;
260
+ }
261
+ return;
262
+ }
263
+ get version() {
264
+ // https://github.com/status-im/js-waku/issues/921
265
+ return this.proto.version ?? 0;
266
+ }
267
+ get rateLimitProof() {
268
+ return this.proto.rateLimitProof;
269
+ }
270
+ }
271
+ class EncoderV0 {
272
+ constructor(contentTopic) {
273
+ this.contentTopic = contentTopic;
274
+ }
275
+ async toWire(message$1) {
276
+ return WakuMessage.encode(await this.toProtoObj(message$1));
277
+ }
278
+ async toProtoObj(message) {
279
+ const timestamp = message.timestamp ?? new Date();
280
+ return {
281
+ payload: message.payload,
282
+ version: Version,
283
+ contentTopic: message.contentTopic ?? this.contentTopic,
284
+ timestamp: BigInt(timestamp.valueOf()) * OneMillion,
285
+ rateLimitProof: message.rateLimitProof,
286
+ };
287
+ }
288
+ }
289
+ class DecoderV0 {
290
+ constructor(contentTopic) {
291
+ this.contentTopic = contentTopic;
292
+ }
293
+ fromWireToProtoObj(bytes) {
294
+ const protoMessage = WakuMessage.decode(bytes);
295
+ log("Message decoded", protoMessage);
296
+ return Promise.resolve({
297
+ payload: protoMessage.payload ?? undefined,
298
+ contentTopic: protoMessage.contentTopic ?? undefined,
299
+ version: protoMessage.version ?? undefined,
300
+ timestamp: protoMessage.timestamp ?? undefined,
301
+ rateLimitProof: protoMessage.rateLimitProof ?? undefined,
302
+ });
303
+ }
304
+ async fromProtoObj(proto) {
305
+ // https://github.com/status-im/js-waku/issues/921
306
+ if (proto.version === undefined) {
307
+ proto.version = 0;
308
+ }
309
+ if (proto.version !== Version) {
310
+ log("Failed to decode due to incorrect version, expected:", Version, ", actual:", proto.version);
311
+ return Promise.resolve(undefined);
312
+ }
313
+ return new MessageV0(proto);
314
+ }
315
+ }
316
+
317
+ export { DecoderV0 as D, EncoderV0 as E, MessageV0 as M, Version as V, WakuMessage as W, message as m };
@@ -0,0 +1,16 @@
1
+ export { DefaultPubSubTopic } from "./lib/constants";
2
+ export { generatePrivateKey, generateSymmetricKey, getPublicKey, } from "./lib/crypto";
3
+ export * as enr from "./lib/enr";
4
+ export * as utils from "./lib/utils";
5
+ export * as proto_message from "./proto/message";
6
+ export * as proto_topic_only_message from "./proto/topic_only_message";
7
+ export * as waku from "./lib/waku";
8
+ export { WakuNode } from "./lib/waku";
9
+ export * as waku_filter from "./lib/waku_filter";
10
+ export { WakuFilter } from "./lib/waku_filter";
11
+ export * as waku_light_push from "./lib/waku_light_push";
12
+ export { WakuLightPush, LightPushCodec, PushResponse, } from "./lib/waku_light_push";
13
+ export * as waku_relay from "./lib/waku_relay";
14
+ export { WakuRelay } from "./lib/waku_relay";
15
+ export * as waku_store from "./lib/waku_store";
16
+ export { PageDirection, WakuStore, StoreCodec } from "./lib/waku_store";
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ export { DefaultPubSubTopic } from "./lib/constants.js";
2
+ export { generatePrivateKey, generateSymmetricKey, getPublicKey, } from "./lib/crypto.js";
3
+ export * as enr from "./lib/enr/index.js";
4
+ export * as utils from "./lib/utils.js";
5
+ export * as proto_message from "./proto/message.js";
6
+ export * as proto_topic_only_message from "./proto/topic_only_message.js";
7
+ export * as waku from "./lib/waku.js";
8
+ export { WakuNode } from "./lib/waku.js";
9
+ export * as waku_filter from "./lib/waku_filter/index.js";
10
+ export { WakuFilter } from "./lib/waku_filter/index.js";
11
+ export * as waku_light_push from "./lib/waku_light_push/index.js";
12
+ export { WakuLightPush, LightPushCodec, PushResponse, } from "./lib/waku_light_push/index.js";
13
+ export * as waku_relay from "./lib/waku_relay/index.js";
14
+ export { WakuRelay } from "./lib/waku_relay/index.js";
15
+ export * as waku_store from "./lib/waku_store/index.js";
16
+ export { PageDirection, WakuStore, StoreCodec } from "./lib/waku_store/index.js";
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,GACb,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,GAAG,MAAM,WAAW,CAAC;AAEjC,OAAO,KAAK,KAAK,MAAM,aAAa,CAAC;AAErC,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,wBAAwB,MAAM,4BAA4B,CAAC;AAEvE,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,aAAa,EACb,cAAc,EACd,YAAY,GACb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * DefaultPubSubTopic is the default gossipsub topic to use for Waku.
3
+ */
4
+ export declare const DefaultPubSubTopic = "/waku/2/default-waku/proto";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * DefaultPubSubTopic is the default gossipsub topic to use for Waku.
3
+ */
4
+ export const DefaultPubSubTopic = "/waku/2/default-waku/proto";
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/lib/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,4BAA4B,CAAC"}
@@ -0,0 +1,34 @@
1
+ import * as secp from "@noble/secp256k1";
2
+ export declare function getSubtle(): SubtleCrypto;
3
+ export declare const randomBytes: (bytesLength?: number | undefined) => Uint8Array;
4
+ export declare const sha256: (...messages: Uint8Array[]) => Promise<Uint8Array>;
5
+ /**
6
+ * Generate a new private key to be used for asymmetric encryption.
7
+ *
8
+ * Use {@link getPublicKey} to get the corresponding Public Key.
9
+ */
10
+ export declare function generatePrivateKey(): Uint8Array;
11
+ /**
12
+ * Generate a new symmetric key to be used for symmetric encryption.
13
+ */
14
+ export declare function generateSymmetricKey(): Uint8Array;
15
+ /**
16
+ * Return the public key for the given private key, to be used for asymmetric
17
+ * encryption.
18
+ */
19
+ export declare const getPublicKey: typeof secp.getPublicKey;
20
+ /**
21
+ * ECDSA Sign a message with the given private key.
22
+ *
23
+ * @param message The message to sign, usually a hash.
24
+ * @param privateKey The ECDSA private key to use to sign the message.
25
+ *
26
+ * @returns The signature and the recovery id concatenated.
27
+ */
28
+ export declare function sign(message: Uint8Array, privateKey: Uint8Array): Promise<Uint8Array>;
29
+ export declare function keccak256(input: Uint8Array): Uint8Array;
30
+ export declare function compressPublicKey(publicKey: Uint8Array): Uint8Array;
31
+ /**
32
+ * Verify an ECDSA signature.
33
+ */
34
+ export declare function verifySignature(signature: Uint8Array, message: Uint8Array | string, publicKey: Uint8Array): boolean;
@@ -0,0 +1,79 @@
1
+ import nodeCrypto from "crypto";
2
+ import * as secp from "@noble/secp256k1";
3
+ import sha3 from "js-sha3";
4
+ import { concat } from "./utils.js";
5
+ import { Asymmetric, Symmetric } from "./waku_message/constants.js";
6
+ const crypto = {
7
+ node: nodeCrypto,
8
+ web: typeof self === "object" && "crypto" in self ? self.crypto : undefined,
9
+ };
10
+ export function getSubtle() {
11
+ if (crypto.web) {
12
+ return crypto.web.subtle;
13
+ }
14
+ else if (crypto.node) {
15
+ return crypto.node.webcrypto.subtle;
16
+ }
17
+ else {
18
+ throw new Error("The environment doesn't have Crypto Subtle API (if in the browser, be sure to use to be in a secure context, ie, https)");
19
+ }
20
+ }
21
+ export const randomBytes = secp.utils.randomBytes;
22
+ export const sha256 = secp.utils.sha256;
23
+ /**
24
+ * Generate a new private key to be used for asymmetric encryption.
25
+ *
26
+ * Use {@link getPublicKey} to get the corresponding Public Key.
27
+ */
28
+ export function generatePrivateKey() {
29
+ return randomBytes(Asymmetric.keySize);
30
+ }
31
+ /**
32
+ * Generate a new symmetric key to be used for symmetric encryption.
33
+ */
34
+ export function generateSymmetricKey() {
35
+ return randomBytes(Symmetric.keySize);
36
+ }
37
+ /**
38
+ * Return the public key for the given private key, to be used for asymmetric
39
+ * encryption.
40
+ */
41
+ export const getPublicKey = secp.getPublicKey;
42
+ /**
43
+ * ECDSA Sign a message with the given private key.
44
+ *
45
+ * @param message The message to sign, usually a hash.
46
+ * @param privateKey The ECDSA private key to use to sign the message.
47
+ *
48
+ * @returns The signature and the recovery id concatenated.
49
+ */
50
+ export async function sign(message, privateKey) {
51
+ const [signature, recoveryId] = await secp.sign(message, privateKey, {
52
+ recovered: true,
53
+ der: false,
54
+ });
55
+ return concat([signature, new Uint8Array([recoveryId])], signature.length + 1);
56
+ }
57
+ export function keccak256(input) {
58
+ return new Uint8Array(sha3.keccak256.arrayBuffer(input));
59
+ }
60
+ export function compressPublicKey(publicKey) {
61
+ if (publicKey.length === 64) {
62
+ publicKey = concat([new Uint8Array([4]), publicKey], 65);
63
+ }
64
+ const point = secp.Point.fromHex(publicKey);
65
+ return point.toRawBytes(true);
66
+ }
67
+ /**
68
+ * Verify an ECDSA signature.
69
+ */
70
+ export function verifySignature(signature, message, publicKey) {
71
+ try {
72
+ const _signature = secp.Signature.fromCompact(signature.slice(0, 64));
73
+ return secp.verify(_signature, message, publicKey);
74
+ }
75
+ catch {
76
+ return false;
77
+ }
78
+ }
79
+ //# sourceMappingURL=crypto.js.map
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}
@@ -0,0 +1,4 @@
1
+ export declare const MAX_RECORD_SIZE = 300;
2
+ export declare const ERR_INVALID_ID = "Invalid record id";
3
+ export declare const ERR_NO_SIGNATURE = "No valid signature found";
4
+ export declare const MULTIADDR_LENGTH_SIZE = 2;
@@ -0,0 +1,8 @@
1
+ // Maximum encoded size of an ENR
2
+ export const MAX_RECORD_SIZE = 300;
3
+ export const ERR_INVALID_ID = "Invalid record id";
4
+ export const ERR_NO_SIGNATURE = "No valid signature found";
5
+ // The maximum length of byte size of a multiaddr to encode in the `multiaddr` field
6
+ // The size is a big endian 16-bit unsigned integer
7
+ export const MULTIADDR_LENGTH_SIZE = 2;
8
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/enr/constants.ts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC;AAEnC,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AAE3D,oFAAoF;AACpF,mDAAmD;AACnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC"}
@@ -0,0 +1,90 @@
1
+ import type { PeerId } from "@libp2p/interface-peer-id";
2
+ import { Multiaddr } from "@multiformats/multiaddr";
3
+ import { IKeypair, KeypairType } from "./keypair";
4
+ import { ENRKey, ENRValue, NodeId, SequenceNumber } from "./types";
5
+ import { Waku2 } from "./waku2_codec";
6
+ export declare class ENR extends Map<ENRKey, ENRValue> {
7
+ static readonly RECORD_PREFIX = "enr:";
8
+ seq: SequenceNumber;
9
+ signature: Uint8Array | null;
10
+ peerId?: PeerId;
11
+ private constructor();
12
+ static create(kvs?: Record<ENRKey, ENRValue>, seq?: SequenceNumber, signature?: Uint8Array | null): Promise<ENR>;
13
+ static createV4(publicKey: Uint8Array, kvs?: Record<ENRKey, ENRValue>): Promise<ENR>;
14
+ static createFromPeerId(peerId: PeerId, kvs?: Record<ENRKey, ENRValue>): Promise<ENR>;
15
+ static decodeFromValues(decoded: Uint8Array[]): Promise<ENR>;
16
+ static decode(encoded: Uint8Array): Promise<ENR>;
17
+ static decodeTxt(encoded: string): Promise<ENR>;
18
+ set(k: ENRKey, v: ENRValue): this;
19
+ get id(): string;
20
+ get keypairType(): KeypairType;
21
+ get publicKey(): Uint8Array | undefined;
22
+ get keypair(): IKeypair | undefined;
23
+ get nodeId(): NodeId | undefined;
24
+ get ip(): string | undefined;
25
+ set ip(ip: string | undefined);
26
+ get tcp(): number | undefined;
27
+ set tcp(port: number | undefined);
28
+ get udp(): number | undefined;
29
+ set udp(port: number | undefined);
30
+ get ip6(): string | undefined;
31
+ set ip6(ip: string | undefined);
32
+ get tcp6(): number | undefined;
33
+ set tcp6(port: number | undefined);
34
+ get udp6(): number | undefined;
35
+ set udp6(port: number | undefined);
36
+ /**
37
+ * Get the `multiaddrs` field from ENR.
38
+ *
39
+ * This field is used to store multiaddresses that cannot be stored with the current ENR pre-defined keys.
40
+ * These can be a multiaddresses that include encapsulation (e.g. wss) or do not use `ip4` nor `ip6` for the host
41
+ * address (e.g. `dns4`, `dnsaddr`, etc)..
42
+ *
43
+ * If the peer information only contains information that can be represented with the ENR pre-defined keys
44
+ * (ip, tcp, etc) then the usage of { @link getLocationMultiaddr } should be preferred.
45
+ *
46
+ * The multiaddresses stored in this field are expected to be location multiaddresses, ie, peer id less.
47
+ */
48
+ get multiaddrs(): Multiaddr[] | undefined;
49
+ /**
50
+ * Set the `multiaddrs` field on the ENR.
51
+ *
52
+ * This field is used to store multiaddresses that cannot be stored with the current ENR pre-defined keys.
53
+ * These can be a multiaddresses that include encapsulation (e.g. wss) or do not use `ip4` nor `ip6` for the host
54
+ * address (e.g. `dns4`, `dnsaddr`, etc)..
55
+ *
56
+ * If the peer information only contains information that can be represented with the ENR pre-defined keys
57
+ * (ip, tcp, etc) then the usage of { @link setLocationMultiaddr } should be preferred.
58
+ * The multiaddresses stored in this field must be location multiaddresses,
59
+ * ie, without a peer id.
60
+ */
61
+ set multiaddrs(multiaddrs: Multiaddr[] | undefined);
62
+ getLocationMultiaddr(protocol: "udp" | "udp4" | "udp6" | "tcp" | "tcp4" | "tcp6"): Multiaddr | undefined;
63
+ setLocationMultiaddr(multiaddr: Multiaddr): void;
64
+ /**
65
+ * Returns the full multiaddr from the ENR fields matching the provided
66
+ * `protocol` parameter.
67
+ * To return full multiaddrs from the `multiaddrs` ENR field,
68
+ * use { @link ENR.getFullMultiaddrs }.
69
+ *
70
+ * @param protocol
71
+ */
72
+ getFullMultiaddr(protocol: "udp" | "udp4" | "udp6" | "tcp" | "tcp4" | "tcp6"): Multiaddr | undefined;
73
+ /**
74
+ * Returns the full multiaddrs from the `multiaddrs` ENR field.
75
+ */
76
+ getFullMultiaddrs(): Multiaddr[];
77
+ /**
78
+ * Get the `waku2` field from ENR.
79
+ */
80
+ get waku2(): Waku2 | undefined;
81
+ /**
82
+ * Set the `waku2` field on the ENR.
83
+ */
84
+ set waku2(waku2: Waku2 | undefined);
85
+ verify(data: Uint8Array, signature: Uint8Array): boolean;
86
+ sign(data: Uint8Array, privateKey: Uint8Array): Promise<Uint8Array>;
87
+ encodeToValues(privateKey?: Uint8Array): Promise<(ENRKey | ENRValue | number[])[]>;
88
+ encode(privateKey?: Uint8Array): Promise<Uint8Array>;
89
+ encodeTxt(privateKey?: Uint8Array): Promise<string>;
90
+ }