@waku/core 0.0.1 → 0.0.3

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 (134) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/bundle/{index-691c0be6.js → index-a67d7136.js} +1 -1
  3. package/bundle/{index-0a4bdddc.js → index-f7e049ad.js} +1 -1
  4. package/bundle/index.js +24853 -3555
  5. package/bundle/lib/peer_discovery_static_list.js +18 -4
  6. package/bundle/lib/predefined_bootstrap_nodes.js +1 -1
  7. package/bundle/lib/wait_for_remote_peer.js +2 -3
  8. package/bundle/lib/waku_message/topic_only_message.js +2 -3
  9. package/bundle/lib/waku_message/version_0.js +317 -4
  10. package/bundle/{message-e2db79d7.js → message-049c8b67.js} +861 -2
  11. package/bundle/{topic_only_message-34f36fa6.js → topic_only_message-5ad3a869.js} +1 -1
  12. package/dist/index.d.ts +0 -3
  13. package/dist/index.js +0 -3
  14. package/dist/index.js.map +1 -1
  15. package/dist/lib/waku_filter/index.d.ts +2 -2
  16. package/dist/lib/waku_filter/index.js.map +1 -1
  17. package/dist/lib/waku_message/version_0.d.ts +3 -2
  18. package/dist/lib/waku_message/version_0.js +2 -1
  19. package/dist/lib/waku_message/version_0.js.map +1 -1
  20. package/dist/lib/waku_relay/index.d.ts +4 -3
  21. package/dist/lib/waku_relay/index.js.map +1 -1
  22. package/dist/lib/waku_store/index.d.ts +4 -4
  23. package/package.json +4 -123
  24. package/src/index.ts +0 -10
  25. package/src/lib/waku_filter/index.ts +4 -3
  26. package/src/lib/waku_message/version_0.ts +5 -3
  27. package/src/lib/waku_relay/index.ts +4 -3
  28. package/src/lib/waku_store/index.ts +5 -5
  29. package/bundle/crypto-8551d579.js +0 -2585
  30. package/bundle/crypto-b00764b7.js +0 -1772
  31. package/bundle/enr-564d4a51.js +0 -20785
  32. package/bundle/enr-9fc5eed8.js +0 -20786
  33. package/bundle/enr-f6e82a53.js +0 -20785
  34. package/bundle/events-fcbda4dc.js +0 -76
  35. package/bundle/index-02d21809.js +0 -20
  36. package/bundle/index-2ae915be.js +0 -1854
  37. package/bundle/index-a013a259.js +0 -20
  38. package/bundle/index-ba42b4fc.js +0 -862
  39. package/bundle/lib/enr.js +0 -8
  40. package/bundle/lib/peer_discovery_dns.js +0 -5018
  41. package/bundle/lib/utils.js +0 -1
  42. package/bundle/lib/waku_message/version_1.js +0 -463
  43. package/bundle/multiaddr_to_peer_info-c406b1e1.js +0 -19
  44. package/bundle/multiaddr_to_peer_info-fd1de516.js +0 -19
  45. package/bundle/utils-9a3221f2.js +0 -815
  46. package/bundle/version_0-e6fe440c.js +0 -317
  47. package/dist/lib/crypto.d.ts +0 -34
  48. package/dist/lib/crypto.js +0 -79
  49. package/dist/lib/crypto.js.map +0 -1
  50. package/dist/lib/enr/constants.d.ts +0 -4
  51. package/dist/lib/enr/constants.js +0 -8
  52. package/dist/lib/enr/constants.js.map +0 -1
  53. package/dist/lib/enr/enr.d.ts +0 -90
  54. package/dist/lib/enr/enr.js +0 -432
  55. package/dist/lib/enr/enr.js.map +0 -1
  56. package/dist/lib/enr/index.d.ts +0 -5
  57. package/dist/lib/enr/index.js +0 -6
  58. package/dist/lib/enr/index.js.map +0 -1
  59. package/dist/lib/enr/keypair/index.d.ts +0 -8
  60. package/dist/lib/enr/keypair/index.js +0 -53
  61. package/dist/lib/enr/keypair/index.js.map +0 -1
  62. package/dist/lib/enr/keypair/secp256k1.d.ts +0 -13
  63. package/dist/lib/enr/keypair/secp256k1.js +0 -57
  64. package/dist/lib/enr/keypair/secp256k1.js.map +0 -1
  65. package/dist/lib/enr/keypair/types.d.ts +0 -13
  66. package/dist/lib/enr/keypair/types.js +0 -7
  67. package/dist/lib/enr/keypair/types.js.map +0 -1
  68. package/dist/lib/enr/multiaddr_from_fields.d.ts +0 -2
  69. package/dist/lib/enr/multiaddr_from_fields.js +0 -8
  70. package/dist/lib/enr/multiaddr_from_fields.js.map +0 -1
  71. package/dist/lib/enr/multiaddrs_codec.d.ts +0 -3
  72. package/dist/lib/enr/multiaddrs_codec.js +0 -32
  73. package/dist/lib/enr/multiaddrs_codec.js.map +0 -1
  74. package/dist/lib/enr/types.d.ts +0 -8
  75. package/dist/lib/enr/types.js +0 -3
  76. package/dist/lib/enr/types.js.map +0 -1
  77. package/dist/lib/enr/v4.d.ts +0 -3
  78. package/dist/lib/enr/v4.js +0 -14
  79. package/dist/lib/enr/v4.js.map +0 -1
  80. package/dist/lib/enr/waku2_codec.d.ts +0 -8
  81. package/dist/lib/enr/waku2_codec.js +0 -36
  82. package/dist/lib/enr/waku2_codec.js.map +0 -1
  83. package/dist/lib/peer_discovery_dns/dns.d.ts +0 -48
  84. package/dist/lib/peer_discovery_dns/dns.js +0 -158
  85. package/dist/lib/peer_discovery_dns/dns.js.map +0 -1
  86. package/dist/lib/peer_discovery_dns/dns_over_https.d.ts +0 -32
  87. package/dist/lib/peer_discovery_dns/dns_over_https.js +0 -87
  88. package/dist/lib/peer_discovery_dns/dns_over_https.js.map +0 -1
  89. package/dist/lib/peer_discovery_dns/enrtree.d.ts +0 -33
  90. package/dist/lib/peer_discovery_dns/enrtree.js +0 -76
  91. package/dist/lib/peer_discovery_dns/enrtree.js.map +0 -1
  92. package/dist/lib/peer_discovery_dns/fetch_nodes.d.ts +0 -14
  93. package/dist/lib/peer_discovery_dns/fetch_nodes.js +0 -133
  94. package/dist/lib/peer_discovery_dns/fetch_nodes.js.map +0 -1
  95. package/dist/lib/peer_discovery_dns/index.d.ts +0 -30
  96. package/dist/lib/peer_discovery_dns/index.js +0 -54
  97. package/dist/lib/peer_discovery_dns/index.js.map +0 -1
  98. package/dist/lib/utils.d.ts +0 -22
  99. package/dist/lib/utils.js +0 -40
  100. package/dist/lib/utils.js.map +0 -1
  101. package/dist/lib/waku_message/constants.d.ts +0 -12
  102. package/dist/lib/waku_message/constants.js +0 -10
  103. package/dist/lib/waku_message/constants.js.map +0 -1
  104. package/dist/lib/waku_message/ecies.d.ts +0 -17
  105. package/dist/lib/waku_message/ecies.js +0 -126
  106. package/dist/lib/waku_message/ecies.js.map +0 -1
  107. package/dist/lib/waku_message/symmetric.d.ts +0 -3
  108. package/dist/lib/waku_message/symmetric.js +0 -18
  109. package/dist/lib/waku_message/symmetric.js.map +0 -1
  110. package/dist/lib/waku_message/version_1.d.ts +0 -93
  111. package/dist/lib/waku_message/version_1.js +0 -325
  112. package/dist/lib/waku_message/version_1.js.map +0 -1
  113. package/src/lib/crypto.ts +0 -100
  114. package/src/lib/enr/constants.ts +0 -10
  115. package/src/lib/enr/enr.ts +0 -516
  116. package/src/lib/enr/index.ts +0 -5
  117. package/src/lib/enr/keypair/index.ts +0 -76
  118. package/src/lib/enr/keypair/secp256k1.ts +0 -69
  119. package/src/lib/enr/keypair/types.ts +0 -14
  120. package/src/lib/enr/multiaddr_from_fields.ts +0 -18
  121. package/src/lib/enr/multiaddrs_codec.ts +0 -50
  122. package/src/lib/enr/types.ts +0 -11
  123. package/src/lib/enr/v4.ts +0 -22
  124. package/src/lib/enr/waku2_codec.ts +0 -39
  125. package/src/lib/peer_discovery_dns/dns.ts +0 -223
  126. package/src/lib/peer_discovery_dns/dns_over_https.ts +0 -98
  127. package/src/lib/peer_discovery_dns/enrtree.ts +0 -123
  128. package/src/lib/peer_discovery_dns/fetch_nodes.ts +0 -180
  129. package/src/lib/peer_discovery_dns/index.ts +0 -84
  130. package/src/lib/utils.ts +0 -50
  131. package/src/lib/waku_message/constants.ts +0 -10
  132. package/src/lib/waku_message/ecies.ts +0 -194
  133. package/src/lib/waku_message/symmetric.ts +0 -33
  134. package/src/lib/waku_message/version_1.ts +0 -457
@@ -1,133 +0,0 @@
1
- import debug from "debug";
2
- const log = debug("waku:discovery:fetch_nodes");
3
- /**
4
- * Fetch nodes using passed [[getNode]] until all wanted capabilities are
5
- * fulfilled or the number of [[getNode]] call exceeds the sum of
6
- * [[wantedNodeCapabilityCount]] plus [[errorTolerance]].
7
- */
8
- export async function fetchNodesUntilCapabilitiesFulfilled(wantedNodeCapabilityCount, errorTolerance, getNode) {
9
- const wanted = {
10
- relay: wantedNodeCapabilityCount.relay ?? 0,
11
- store: wantedNodeCapabilityCount.store ?? 0,
12
- filter: wantedNodeCapabilityCount.filter ?? 0,
13
- lightPush: wantedNodeCapabilityCount.lightPush ?? 0,
14
- };
15
- const maxSearches = wanted.relay + wanted.store + wanted.filter + wanted.lightPush;
16
- const actual = {
17
- relay: 0,
18
- store: 0,
19
- filter: 0,
20
- lightPush: 0,
21
- };
22
- let totalSearches = 0;
23
- const peers = [];
24
- while (!isSatisfied(wanted, actual) &&
25
- totalSearches < maxSearches + errorTolerance) {
26
- const peer = await getNode();
27
- if (peer && isNewPeer(peer, peers)) {
28
- // ENRs without a waku2 key are ignored.
29
- if (peer.waku2) {
30
- if (helpsSatisfyCapabilities(peer.waku2, wanted, actual)) {
31
- addCapabilities(peer.waku2, actual);
32
- peers.push(peer);
33
- }
34
- }
35
- log(`got new peer candidate from DNS address=${peer.nodeId}@${peer.ip}`);
36
- }
37
- totalSearches++;
38
- }
39
- return peers;
40
- }
41
- /**
42
- * Fetch nodes using passed [[getNode]] until all wanted capabilities are
43
- * fulfilled or the number of [[getNode]] call exceeds the sum of
44
- * [[wantedNodeCapabilityCount]] plus [[errorTolerance]].
45
- */
46
- export async function* yieldNodesUntilCapabilitiesFulfilled(wantedNodeCapabilityCount, errorTolerance, getNode) {
47
- const wanted = {
48
- relay: wantedNodeCapabilityCount.relay ?? 0,
49
- store: wantedNodeCapabilityCount.store ?? 0,
50
- filter: wantedNodeCapabilityCount.filter ?? 0,
51
- lightPush: wantedNodeCapabilityCount.lightPush ?? 0,
52
- };
53
- const maxSearches = wanted.relay + wanted.store + wanted.filter + wanted.lightPush;
54
- const actual = {
55
- relay: 0,
56
- store: 0,
57
- filter: 0,
58
- lightPush: 0,
59
- };
60
- let totalSearches = 0;
61
- const peerNodeIds = new Set();
62
- while (!isSatisfied(wanted, actual) &&
63
- totalSearches < maxSearches + errorTolerance) {
64
- const peer = await getNode();
65
- if (peer && peer.nodeId && !peerNodeIds.has(peer.nodeId)) {
66
- peerNodeIds.add(peer.nodeId);
67
- // ENRs without a waku2 key are ignored.
68
- if (peer.waku2) {
69
- if (helpsSatisfyCapabilities(peer.waku2, wanted, actual)) {
70
- addCapabilities(peer.waku2, actual);
71
- yield peer;
72
- }
73
- }
74
- log(`got new peer candidate from DNS address=${peer.nodeId}@${peer.ip}`);
75
- }
76
- totalSearches++;
77
- }
78
- }
79
- function isSatisfied(wanted, actual) {
80
- return (actual.relay >= wanted.relay &&
81
- actual.store >= wanted.store &&
82
- actual.filter >= wanted.filter &&
83
- actual.lightPush >= wanted.lightPush);
84
- }
85
- function isNewPeer(peer, peers) {
86
- if (!peer.nodeId)
87
- return false;
88
- for (const existingPeer of peers) {
89
- if (peer.nodeId === existingPeer.nodeId) {
90
- return false;
91
- }
92
- }
93
- return true;
94
- }
95
- function addCapabilities(node, total) {
96
- if (node.relay)
97
- total.relay += 1;
98
- if (node.store)
99
- total.store += 1;
100
- if (node.filter)
101
- total.filter += 1;
102
- if (node.lightPush)
103
- total.lightPush += 1;
104
- }
105
- /**
106
- * Checks if the proposed ENR [[node]] helps satisfy the [[wanted]] capabilities,
107
- * considering the [[actual]] capabilities of nodes retrieved so far..
108
- *
109
- * @throws If the function is called when the wanted capabilities are already fulfilled.
110
- */
111
- function helpsSatisfyCapabilities(node, wanted, actual) {
112
- if (isSatisfied(wanted, actual)) {
113
- throw "Internal Error: Waku2 wanted capabilities are already fulfilled";
114
- }
115
- const missing = missingCapabilities(wanted, actual);
116
- return ((missing.relay && node.relay) ||
117
- (missing.store && node.store) ||
118
- (missing.filter && node.filter) ||
119
- (missing.lightPush && node.lightPush));
120
- }
121
- /**
122
- * Return a [[Waku2]] Object for which capabilities are set to true if they are
123
- * [[wanted]] yet missing from [[actual]].
124
- */
125
- function missingCapabilities(wanted, actual) {
126
- return {
127
- relay: actual.relay < wanted.relay,
128
- store: actual.store < wanted.store,
129
- filter: actual.filter < wanted.filter,
130
- lightPush: actual.lightPush < wanted.lightPush,
131
- };
132
- }
133
- //# sourceMappingURL=fetch_nodes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch_nodes.js","sourceRoot":"","sources":["../../../src/lib/peer_discovery_dns/fetch_nodes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,MAAM,GAAG,GAAG,KAAK,CAAC,4BAA4B,CAAC,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,oCAAoC,CACxD,yBAAuD,EACvD,cAAsB,EACtB,OAAkC;IAElC,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,yBAAyB,CAAC,KAAK,IAAI,CAAC;QAC3C,KAAK,EAAE,yBAAyB,CAAC,KAAK,IAAI,CAAC;QAC3C,MAAM,EAAE,yBAAyB,CAAC,MAAM,IAAI,CAAC;QAC7C,SAAS,EAAE,yBAAyB,CAAC,SAAS,IAAI,CAAC;KACpD,CAAC;IAEF,MAAM,WAAW,GACf,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;IAEjE,MAAM,MAAM,GAAG;QACb,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,SAAS,EAAE,CAAC;KACb,CAAC;IAEF,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,MAAM,KAAK,GAAU,EAAE,CAAC;IAExB,OACE,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC;QAC5B,aAAa,GAAG,WAAW,GAAG,cAAc,EAC5C;QACA,MAAM,IAAI,GAAG,MAAM,OAAO,EAAE,CAAC;QAC7B,IAAI,IAAI,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE;YAClC,wCAAwC;YACxC,IAAI,IAAI,CAAC,KAAK,EAAE;gBACd,IAAI,wBAAwB,CAAC,IAAI,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,MAAM,IAAI,CAAC,CAAC;IACnC,IAAI,IAAI,CAAC,SAAS;QAAE,KAAK,CAAC,SAAS,IAAI,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;GAKG;AACH,SAAS,wBAAwB,CAC/B,IAAW,EACX,MAA2B,EAC3B,MAA2B;IAE3B,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;QAC/B,MAAM,iEAAiE,CAAC;KACzE;IAED,MAAM,OAAO,GAAG,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEpD,OAAO,CACL,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;QAC7B,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;QAC7B,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;QAC/B,CAAC,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC,CACtC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAC1B,MAA2B,EAC3B,MAA2B;IAE3B,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK;QAClC,KAAK,EAAE,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK;QAClC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM;QACrC,SAAS,EAAE,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS;KAC/C,CAAC;AACJ,CAAC"}
@@ -1,30 +0,0 @@
1
- import type { PeerDiscovery, PeerDiscoveryEvents } from "@libp2p/interface-peer-discovery";
2
- import { symbol } from "@libp2p/interface-peer-discovery";
3
- import { EventEmitter } from "@libp2p/interfaces/events";
4
- import { NodeCapabilityCount } from "./dns";
5
- /**
6
- * Parse options and expose function to return bootstrap peer addresses.
7
- *
8
- * @throws if an invalid combination of options is passed, see [[BootstrapOptions]] for details.
9
- */
10
- export declare class PeerDiscoveryDns extends EventEmitter<PeerDiscoveryEvents> implements PeerDiscovery {
11
- private readonly nextPeer;
12
- private _started;
13
- /**
14
- * @param enrUrl An EIP-1459 ENR Tree URL. For example:
15
- * "enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.nodes.vac.dev"
16
- * @param wantedNodeCapabilityCount Specifies what node capabilities
17
- * (protocol) must be returned.
18
- */
19
- constructor(enrUrl: string, wantedNodeCapabilityCount: Partial<NodeCapabilityCount>);
20
- /**
21
- * Start discovery process
22
- */
23
- start(): Promise<void>;
24
- /**
25
- * Stop emitting events
26
- */
27
- stop(): void;
28
- get [symbol](): true;
29
- get [Symbol.toStringTag](): string;
30
- }
@@ -1,54 +0,0 @@
1
- import { symbol } from "@libp2p/interface-peer-discovery";
2
- import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events";
3
- import debug from "debug";
4
- import { multiaddrsToPeerInfo } from "../multiaddr_to_peer_info.js";
5
- import { DnsNodeDiscovery } from "./dns.js";
6
- const log = debug("waku:peer-discovery-dns");
7
- /**
8
- * Parse options and expose function to return bootstrap peer addresses.
9
- *
10
- * @throws if an invalid combination of options is passed, see [[BootstrapOptions]] for details.
11
- */
12
- export class PeerDiscoveryDns extends EventEmitter {
13
- /**
14
- * @param enrUrl An EIP-1459 ENR Tree URL. For example:
15
- * "enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.nodes.vac.dev"
16
- * @param wantedNodeCapabilityCount Specifies what node capabilities
17
- * (protocol) must be returned.
18
- */
19
- constructor(enrUrl, wantedNodeCapabilityCount) {
20
- super();
21
- this._started = false;
22
- log("Use following EIP-1459 ENR Tree URL: ", enrUrl);
23
- const dns = DnsNodeDiscovery.dnsOverHttp();
24
- this.nextPeer = dns.getNextPeer.bind({}, [enrUrl], wantedNodeCapabilityCount);
25
- }
26
- /**
27
- * Start discovery process
28
- */
29
- async start() {
30
- log("Starting peer discovery via dns");
31
- this._started = true;
32
- for await (const peer of this.nextPeer()) {
33
- if (!this._started)
34
- return;
35
- const peerInfos = multiaddrsToPeerInfo(peer.getFullMultiaddrs());
36
- peerInfos.forEach((peerInfo) => {
37
- this.dispatchEvent(new CustomEvent("peer", { detail: peerInfo }));
38
- });
39
- }
40
- }
41
- /**
42
- * Stop emitting events
43
- */
44
- stop() {
45
- this._started = false;
46
- }
47
- get [symbol]() {
48
- return true;
49
- }
50
- get [Symbol.toStringTag]() {
51
- return "@waku/bootstrap";
52
- }
53
- }
54
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/peer_discovery_dns/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAuB,MAAM,OAAO,CAAC;AAE9D,MAAM,GAAG,GAAG,KAAK,CAAC,yBAAyB,CAAC,CAAC;AAE7C;;;;GAIG;AACH,MAAM,OAAO,gBACX,SAAQ,YAAiC;IAMzC;;;;;OAKG;IACH,YACE,MAAc,EACd,yBAAuD;QAEvD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,GAAG,CAAC,uCAAuC,EAAE,MAAM,CAAC,CAAC;QAErD,MAAM,GAAG,GAAG,gBAAgB,CAAC,WAAW,EAAE,CAAC;QAE3C,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,WAAW,CAAC,IAAI,CAClC,EAAE,EACF,CAAC,MAAM,CAAC,EACR,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,GAAG,CAAC,iCAAiC,CAAC,CAAC;QAEvC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE;YACxC,IAAI,CAAC,IAAI,CAAC,QAAQ;gBAAE,OAAO;YAC3B,MAAM,SAAS,GAAG,oBAAoB,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;YACjE,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBAC7B,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAW,MAAM,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CACxD,CAAC;YACJ,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED;;OAEG;IACH,IAAI;QACF,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACxB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF"}
@@ -1,22 +0,0 @@
1
- /**
2
- * Convert input to a byte array.
3
- *
4
- * Handles both `0x` prefixed and non-prefixed strings.
5
- */
6
- export declare function hexToBytes(hex: string | Uint8Array): Uint8Array;
7
- /**
8
- * Convert byte array to hex string (no `0x` prefix).
9
- */
10
- export declare const bytesToHex: (bytes: Uint8Array) => string;
11
- /**
12
- * Decode byte array to utf-8 string.
13
- */
14
- export declare const bytesToUtf8: (b: Uint8Array) => string;
15
- /**
16
- * Encode utf-8 string to byte array.
17
- */
18
- export declare const utf8ToBytes: (s: string) => Uint8Array;
19
- /**
20
- * Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
21
- */
22
- export declare function concat(byteArrays: Uint8Array[], totalLength?: number): Uint8Array;
package/dist/lib/utils.js DELETED
@@ -1,40 +0,0 @@
1
- import { fromString } from "uint8arrays/from-string";
2
- import { toString } from "uint8arrays/to-string";
3
- /**
4
- * Convert input to a byte array.
5
- *
6
- * Handles both `0x` prefixed and non-prefixed strings.
7
- */
8
- export function hexToBytes(hex) {
9
- if (typeof hex === "string") {
10
- const _hex = hex.replace(/^0x/i, "");
11
- return fromString(_hex.toLowerCase(), "base16");
12
- }
13
- return hex;
14
- }
15
- /**
16
- * Convert byte array to hex string (no `0x` prefix).
17
- */
18
- export const bytesToHex = (bytes) => toString(bytes, "base16");
19
- /**
20
- * Decode byte array to utf-8 string.
21
- */
22
- export const bytesToUtf8 = (b) => toString(b, "utf8");
23
- /**
24
- * Encode utf-8 string to byte array.
25
- */
26
- export const utf8ToBytes = (s) => fromString(s, "utf8");
27
- /**
28
- * Concatenate using Uint8Arrays as `Buffer` has a different behavior with `DataView`
29
- */
30
- export function concat(byteArrays, totalLength) {
31
- const len = totalLength ?? byteArrays.reduce((acc, curr) => acc + curr.length, 0);
32
- const res = new Uint8Array(len);
33
- let offset = 0;
34
- for (const bytes of byteArrays) {
35
- res.set(bytes, offset);
36
- offset += bytes.length;
37
- }
38
- return res;
39
- }
40
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAwB;IACjD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACrC,OAAO,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAC;KACjD;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAiB,EAAU,EAAE,CACtD,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAE5B;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAa,EAAU,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAE1E;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAS,EAAc,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAE5E;;GAEG;AACH,MAAM,UAAU,MAAM,CACpB,UAAwB,EACxB,WAAoB;IAEpB,MAAM,GAAG,GACP,WAAW,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACxE,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAEhC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE;QAC9B,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;KACxB;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,12 +0,0 @@
1
- export declare const Symmetric: {
2
- keySize: number;
3
- ivSize: number;
4
- tagSize: number;
5
- algorithm: {
6
- name: string;
7
- length: number;
8
- };
9
- };
10
- export declare const Asymmetric: {
11
- keySize: number;
12
- };
@@ -1,10 +0,0 @@
1
- export const Symmetric = {
2
- keySize: 32,
3
- ivSize: 12,
4
- tagSize: 16,
5
- algorithm: { name: "AES-GCM", length: 128 },
6
- };
7
- export const Asymmetric = {
8
- keySize: 32,
9
- };
10
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/waku_message/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,OAAO,EAAE,EAAE;IACX,MAAM,EAAE,EAAE;IACV,OAAO,EAAE,EAAE;IACX,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE;CAC5C,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,OAAO,EAAE,EAAE;CACZ,CAAC"}
@@ -1,17 +0,0 @@
1
- /**
2
- * Encrypt message for given recipient's public key.
3
- *
4
- * @param publicKeyTo Recipient's public key (65 bytes)
5
- * @param msg The message being encrypted
6
- * @return A promise that resolves with the ECIES structure serialized
7
- */
8
- export declare function encrypt(publicKeyTo: Uint8Array, msg: Uint8Array): Promise<Uint8Array>;
9
- /**
10
- * Decrypt message using given private key.
11
- *
12
- * @param privateKey A 32-byte private key of recipient of the message
13
- * @param encrypted ECIES serialized structure (result of ECIES encryption)
14
- * @returns The clear text
15
- * @throws Error If decryption fails
16
- */
17
- export declare function decrypt(privateKey: Uint8Array, encrypted: Uint8Array): Promise<Uint8Array>;
@@ -1,126 +0,0 @@
1
- import * as secp from "@noble/secp256k1";
2
- import { getSubtle, randomBytes, sha256 } from "../crypto.js";
3
- import { concat, hexToBytes } from "../utils.js";
4
- /**
5
- * HKDF as implemented in go-ethereum.
6
- */
7
- function kdf(secret, outputLength) {
8
- let ctr = 1;
9
- let written = 0;
10
- let willBeResult = Promise.resolve(new Uint8Array());
11
- while (written < outputLength) {
12
- const counters = new Uint8Array([ctr >> 24, ctr >> 16, ctr >> 8, ctr]);
13
- const countersSecret = concat([counters, secret], counters.length + secret.length);
14
- const willBeHashResult = sha256(countersSecret);
15
- willBeResult = willBeResult.then((result) => willBeHashResult.then((hashResult) => {
16
- const _hashResult = new Uint8Array(hashResult);
17
- return concat([result, _hashResult], result.length + _hashResult.length);
18
- }));
19
- written += 32;
20
- ctr += 1;
21
- }
22
- return willBeResult;
23
- }
24
- function aesCtrEncrypt(counter, key, data) {
25
- return getSubtle()
26
- .importKey("raw", key, "AES-CTR", false, ["encrypt"])
27
- .then((cryptoKey) => getSubtle().encrypt({ name: "AES-CTR", counter: counter, length: 128 }, cryptoKey, data))
28
- .then((bytes) => new Uint8Array(bytes));
29
- }
30
- function aesCtrDecrypt(counter, key, data) {
31
- return getSubtle()
32
- .importKey("raw", key, "AES-CTR", false, ["decrypt"])
33
- .then((cryptoKey) => getSubtle().decrypt({ name: "AES-CTR", counter: counter, length: 128 }, cryptoKey, data))
34
- .then((bytes) => new Uint8Array(bytes));
35
- }
36
- function hmacSha256Sign(key, msg) {
37
- const algorithm = { name: "HMAC", hash: { name: "SHA-256" } };
38
- return getSubtle()
39
- .importKey("raw", key, algorithm, false, ["sign"])
40
- .then((cryptoKey) => getSubtle().sign(algorithm, cryptoKey, msg))
41
- .then((bytes) => new Uint8Array(bytes));
42
- }
43
- function hmacSha256Verify(key, msg, sig) {
44
- const algorithm = { name: "HMAC", hash: { name: "SHA-256" } };
45
- const _key = getSubtle().importKey("raw", key, algorithm, false, ["verify"]);
46
- return _key.then((cryptoKey) => getSubtle().verify(algorithm, cryptoKey, sig, msg));
47
- }
48
- /**
49
- * Derive shared secret for given private and public keys.
50
- *
51
- * @param privateKeyA Sender's private key (32 bytes)
52
- * @param publicKeyB Recipient's public key (65 bytes)
53
- * @returns A promise that resolves with the derived shared secret (Px, 32 bytes)
54
- * @throws Error If arguments are invalid
55
- */
56
- function derive(privateKeyA, publicKeyB) {
57
- if (privateKeyA.length !== 32) {
58
- throw new Error(`Bad private key, it should be 32 bytes but it's actually ${privateKeyA.length} bytes long`);
59
- }
60
- else if (publicKeyB.length !== 65) {
61
- throw new Error(`Bad public key, it should be 65 bytes but it's actually ${publicKeyB.length} bytes long`);
62
- }
63
- else if (publicKeyB[0] !== 4) {
64
- throw new Error("Bad public key, a valid public key would begin with 4");
65
- }
66
- else {
67
- const px = secp.getSharedSecret(privateKeyA, publicKeyB, true);
68
- // Remove the compression prefix
69
- return new Uint8Array(hexToBytes(px).slice(1));
70
- }
71
- }
72
- /**
73
- * Encrypt message for given recipient's public key.
74
- *
75
- * @param publicKeyTo Recipient's public key (65 bytes)
76
- * @param msg The message being encrypted
77
- * @return A promise that resolves with the ECIES structure serialized
78
- */
79
- export async function encrypt(publicKeyTo, msg) {
80
- const ephemPrivateKey = randomBytes(32);
81
- const sharedPx = await derive(ephemPrivateKey, publicKeyTo);
82
- const hash = await kdf(sharedPx, 32);
83
- const iv = randomBytes(16);
84
- const encryptionKey = hash.slice(0, 16);
85
- const cipherText = await aesCtrEncrypt(iv, encryptionKey, msg);
86
- const ivCipherText = concat([iv, cipherText], iv.length + cipherText.length);
87
- const macKey = await sha256(hash.slice(16));
88
- const hmac = await hmacSha256Sign(macKey, ivCipherText);
89
- const ephemPublicKey = secp.getPublicKey(ephemPrivateKey, false);
90
- return concat([ephemPublicKey, ivCipherText, hmac], ephemPublicKey.length + ivCipherText.length + hmac.length);
91
- }
92
- const metaLength = 1 + 64 + 16 + 32;
93
- /**
94
- * Decrypt message using given private key.
95
- *
96
- * @param privateKey A 32-byte private key of recipient of the message
97
- * @param encrypted ECIES serialized structure (result of ECIES encryption)
98
- * @returns The clear text
99
- * @throws Error If decryption fails
100
- */
101
- export async function decrypt(privateKey, encrypted) {
102
- if (encrypted.length <= metaLength) {
103
- throw new Error(`Invalid Ciphertext. Data is too small. It should ba at least ${metaLength} bytes`);
104
- }
105
- else if (encrypted[0] !== 4) {
106
- throw new Error(`Not a valid ciphertext. It should begin with 4 but actually begin with ${encrypted[0]}`);
107
- }
108
- else {
109
- // deserialize
110
- const ephemPublicKey = encrypted.slice(0, 65);
111
- const cipherTextLength = encrypted.length - metaLength;
112
- const iv = encrypted.slice(65, 65 + 16);
113
- const cipherAndIv = encrypted.slice(65, 65 + 16 + cipherTextLength);
114
- const ciphertext = cipherAndIv.slice(16);
115
- const msgMac = encrypted.slice(65 + 16 + cipherTextLength);
116
- // check HMAC
117
- const px = derive(privateKey, ephemPublicKey);
118
- const hash = await kdf(px, 32);
119
- const [encryptionKey, macKey] = await sha256(hash.slice(16)).then((macKey) => [hash.slice(0, 16), macKey]);
120
- if (!(await hmacSha256Verify(macKey, cipherAndIv, msgMac))) {
121
- throw new Error("Incorrect MAC");
122
- }
123
- return aesCtrDecrypt(iv, encryptionKey, ciphertext);
124
- }
125
- }
126
- //# sourceMappingURL=ecies.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ecies.js","sourceRoot":"","sources":["../../../src/lib/waku_message/ecies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC9C;;GAEG;AACH,SAAS,GAAG,CAAC,MAAkB,EAAE,YAAoB;IACnD,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC;IACrD,OAAO,OAAO,GAAG,YAAY,EAAE;QAC7B,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QACvE,MAAM,cAAc,GAAG,MAAM,CAC3B,CAAC,QAAQ,EAAE,MAAM,CAAC,EAClB,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAChC,CAAC;QACF,MAAM,gBAAgB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;QAChD,YAAY,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAC1C,gBAAgB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;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,EAAE,CAAC,CAAC;QAC/B,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAC/D,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,CACxC,CAAC;QAEF,IAAI,CAAC,CAAC,MAAM,gBAAgB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC,EAAE;YAC1D,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;SAClC;QAED,OAAO,aAAa,CAAC,EAAE,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;KACrD;AACH,CAAC"}
@@ -1,3 +0,0 @@
1
- export declare function encrypt(iv: Uint8Array, key: Uint8Array, clearText: Uint8Array): Promise<Uint8Array>;
2
- export declare function decrypt(iv: Uint8Array, key: Uint8Array, cipherText: Uint8Array): Promise<Uint8Array>;
3
- export declare function generateIv(): Uint8Array;
@@ -1,18 +0,0 @@
1
- import { getSubtle, randomBytes } from "../crypto.js";
2
- import { Symmetric } from "./constants.js";
3
- export async function encrypt(iv, key, clearText) {
4
- return getSubtle()
5
- .importKey("raw", key, Symmetric.algorithm, false, ["encrypt"])
6
- .then((cryptoKey) => getSubtle().encrypt({ iv, ...Symmetric.algorithm }, cryptoKey, clearText))
7
- .then((cipher) => new Uint8Array(cipher));
8
- }
9
- export async function decrypt(iv, key, cipherText) {
10
- return getSubtle()
11
- .importKey("raw", key, Symmetric.algorithm, false, ["decrypt"])
12
- .then((cryptoKey) => getSubtle().decrypt({ iv, ...Symmetric.algorithm }, cryptoKey, cipherText))
13
- .then((clear) => new Uint8Array(clear));
14
- }
15
- export function generateIv() {
16
- return randomBytes(Symmetric.ivSize);
17
- }
18
- //# sourceMappingURL=symmetric.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"symmetric.js","sour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age } from "@waku/interfaces";
2
- import * as proto from "../../proto/message";
3
- import { DecoderV0, MessageV0 } from "./version_0";
4
- export declare const Version = 1;
5
- export declare type Signature = {
6
- signature: Uint8Array;
7
- publicKey: Uint8Array | undefined;
8
- };
9
- export declare class MessageV1 extends MessageV0 implements Message {
10
- signature?: Uint8Array | undefined;
11
- signaturePublicKey?: Uint8Array | undefined;
12
- private readonly _decodedPayload;
13
- constructor(proto: proto.WakuMessage, decodedPayload: Uint8Array, signature?: Uint8Array | undefined, signaturePublicKey?: Uint8Array | undefined);
14
- get payload(): Uint8Array;
15
- }
16
- export declare class AsymEncoder implements Encoder {
17
- contentTopic: string;
18
- private publicKey;
19
- private sigPrivKey?;
20
- constructor(contentTopic: string, publicKey: Uint8Array, sigPrivKey?: Uint8Array | undefined);
21
- toWire(message: Partial<Message>): Promise<Uint8Array | undefined>;
22
- toProtoObj(message: Partial<Message>): Promise<ProtoMessage | undefined>;
23
- }
24
- export declare class SymEncoder implements Encoder {
25
- contentTopic: string;
26
- private symKey;
27
- private sigPrivKey?;
28
- constructor(contentTopic: string, symKey: Uint8Array, sigPrivKey?: Uint8Array | undefined);
29
- toWire(message: Partial<Message>): Promise<Uint8Array | undefined>;
30
- toProtoObj(message: Partial<Message>): Promise<ProtoMessage | undefined>;
31
- }
32
- export declare class AsymDecoder extends DecoderV0 implements Decoder<MessageV1> {
33
- private privateKey;
34
- constructor(contentTopic: string, privateKey: Uint8Array);
35
- fromProtoObj(protoMessage: ProtoMessage): Promise<MessageV1 | undefined>;
36
- }
37
- export declare class SymDecoder extends DecoderV0 implements Decoder<MessageV1> {
38
- private symKey;
39
- constructor(contentTopic: string, symKey: Uint8Array);
40
- fromProtoObj(protoMessage: ProtoMessage): Promise<MessageV1 | undefined>;
41
- }
42
- /**
43
- * Proceed with Asymmetric encryption of the data as per [26/WAKU-PAYLOAD](https://rfc.vac.dev/spec/26/).
44
- * The data MUST be flags | payload-length | payload | [signature].
45
- * The returned result can be set to `WakuMessage.payload`.
46
- *
47
- * @internal
48
- */
49
- export declare function encryptAsymmetric(data: Uint8Array, publicKey: Uint8Array | string): Promise<Uint8Array>;
50
- /**
51
- * Proceed with Asymmetric decryption of the data as per [26/WAKU-PAYLOAD](https://rfc.vac.dev/spec/26/).
52
- * The returned data is expected to be `flags | payload-length | payload | [signature]`.
53
- *
54
- * @internal
55
- */
56
- export declare function decryptAsymmetric(payload: Uint8Array, privKey: Uint8Array): Promise<Uint8Array>;
57
- /**
58
- * Proceed with Symmetric encryption of the data as per [26/WAKU-PAYLOAD](https://rfc.vac.dev/spec/26/).
59
- *
60
- * @param data The data to encrypt, expected to be `flags | payload-length | payload | [signature]`.
61
- * @param key The key to use for encryption.
62
- * @returns The decrypted data, `cipherText | tag | iv` and can be set to `WakuMessage.payload`.
63
- *
64
- * @internal
65
- */
66
- export declare function encryptSymmetric(data: Uint8Array, key: Uint8Array | string): Promise<Uint8Array>;
67
- /**
68
- * Proceed with Symmetric decryption of the data as per [26/WAKU-PAYLOAD](https://rfc.vac.dev/spec/26/).
69
- *
70
- * @param payload The cipher data, it is expected to be `cipherText | tag | iv`.
71
- * @param key The key to use for decryption.
72
- * @returns The decrypted data, expected to be `flags | payload-length | payload | [signature]`.
73
- *
74
- * @internal
75
- */
76
- export declare function decryptSymmetric(payload: Uint8Array, key: Uint8Array | string): Promise<Uint8Array>;
77
- /**
78
- * Prepare the payload pre-encryption.
79
- *
80
- * @internal
81
- * @returns The encoded payload, ready for encryption using {@link encryptAsymmetric}
82
- * or {@link encryptSymmetric}.
83
- */
84
- export declare function preCipher(messagePayload: Uint8Array, sigPrivKey?: Uint8Array): Promise<Uint8Array>;
85
- /**
86
- * Decode a decrypted payload.
87
- *
88
- * @internal
89
- */
90
- export declare function postCipher(message: Uint8Array): {
91
- payload: Uint8Array;
92
- sig?: Signature;
93
- } | undefined;