@wizardconnect/core 0.1.0 → 0.1.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.
- package/dist/connection-manager.d.ts +18 -29
- package/dist/connection-manager.js +142 -144
- package/dist/connection-manager.js.map +1 -1
- package/dist/dapp-relay.d.ts +16 -19
- package/dist/dapp-relay.js +100 -116
- package/dist/dapp-relay.js.map +1 -1
- package/dist/index.d.ts +4 -24
- package/dist/index.js +6 -15
- package/dist/index.js.map +1 -1
- package/dist/key-exchange.d.ts +17 -23
- package/dist/key-exchange.js +124 -144
- package/dist/key-exchange.js.map +1 -1
- package/dist/log.d.ts +3 -3
- package/dist/log.js +11 -8
- package/dist/log.js.map +1 -1
- package/dist/message-queue.d.ts +12 -12
- package/dist/message-queue.js +53 -52
- package/dist/message-queue.js.map +1 -1
- package/dist/primitives.js +14 -11
- package/dist/primitives.js.map +1 -1
- package/dist/protocols/base.d.ts +22 -28
- package/dist/protocols/base.js +25 -28
- package/dist/protocols/base.js.map +1 -1
- package/dist/protocols/hdwalletv1.d.ts +25 -31
- package/dist/protocols/hdwalletv1.js +47 -57
- package/dist/protocols/hdwalletv1.js.map +1 -1
- package/dist/relay-client.d.ts +32 -32
- package/dist/relay-client.js +242 -291
- package/dist/relay-client.js.map +1 -1
- package/dist/relay-handler.d.ts +13 -22
- package/dist/relay-handler.js +107 -117
- package/dist/relay-handler.js.map +1 -1
- package/dist/utilnostr.d.ts +1 -3
- package/dist/utilnostr.js +9 -10
- package/dist/utilnostr.js.map +1 -1
- package/dist/wallet-relay.d.ts +11 -14
- package/dist/wallet-relay.js +58 -64
- package/dist/wallet-relay.js.map +1 -1
- package/package.json +8 -3
|
@@ -1,45 +1,34 @@
|
|
|
1
1
|
import { LogScope } from "./log.js";
|
|
2
2
|
import { EventEmitter } from "eventemitter3";
|
|
3
3
|
export interface VisibilityChangeContext<TClient> {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
client: TClient;
|
|
5
|
+
state: "hidden" | "visible";
|
|
6
|
+
setPaused: (_value: boolean) => void;
|
|
7
|
+
isPaused: () => boolean;
|
|
8
|
+
startConnectionLoop: () => void;
|
|
9
9
|
}
|
|
10
|
-
export interface ConnectionManagerOptions<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
scope?: LogScope;
|
|
17
|
-
onVisibilityChange?: (
|
|
18
|
-
_context: VisibilityChangeContext<TClient>,
|
|
19
|
-
) => void | Promise<void>;
|
|
10
|
+
export interface ConnectionManagerOptions<TClient extends ConnectionClient = ConnectionClient> {
|
|
11
|
+
reconnectInterval?: number;
|
|
12
|
+
maxReconnectAttempts?: number;
|
|
13
|
+
enableVisibilityHandling?: boolean;
|
|
14
|
+
scope?: LogScope;
|
|
15
|
+
onVisibilityChange?: (_context: VisibilityChangeContext<TClient>) => void | Promise<void>;
|
|
20
16
|
}
|
|
21
17
|
export interface ConnectionClient extends EventEmitter {
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
connect(): Promise<void>;
|
|
19
|
+
disconnect(..._args: any[]): Promise<void | boolean>;
|
|
24
20
|
}
|
|
25
21
|
export interface ConnectionManagerResult {
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
cleanup: () => Promise<void>;
|
|
23
|
+
startConnectionLoop: () => void;
|
|
28
24
|
}
|
|
29
|
-
export declare const createConnectionManager: <
|
|
30
|
-
TClient extends ConnectionClient,
|
|
31
|
-
>(
|
|
32
|
-
client: TClient,
|
|
33
|
-
callbacks: {
|
|
25
|
+
export declare const createConnectionManager: <TClient extends ConnectionClient>(client: TClient, callbacks: {
|
|
34
26
|
onConnected: (_client: TClient) => void;
|
|
35
27
|
onReconnecting: (_client: TClient, _reason: string | null) => void;
|
|
36
28
|
onDisconnected: (_client: TClient) => void;
|
|
37
29
|
onError?: (_client: TClient, _error: any) => void;
|
|
38
|
-
|
|
39
|
-
events: {
|
|
30
|
+
}, events: {
|
|
40
31
|
connected: string;
|
|
41
32
|
disconnected: string;
|
|
42
33
|
error?: string;
|
|
43
|
-
|
|
44
|
-
options?: ConnectionManagerOptions<TClient>,
|
|
45
|
-
) => ConnectionManagerResult;
|
|
34
|
+
}, options?: ConnectionManagerOptions<TClient>) => ConnectionManagerResult;
|
|
@@ -1,157 +1,155 @@
|
|
|
1
|
+
// Copyright (C) 2026 Whiterun LLC,
|
|
2
|
+
// This software is licensed under the GNU Lesser General Public License (LGPL), version 3.0 or later.
|
|
3
|
+
// A copy of the license can be found in the LICENSE file or at https://www.gnu.org/licenses/lgpl-3.0.html
|
|
1
4
|
import { debug, Scope } from "./log.js";
|
|
2
5
|
async function sleep(ms) {
|
|
3
|
-
|
|
6
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
7
|
}
|
|
5
|
-
export const createConnectionManager = (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const onError = (err) => {
|
|
36
|
-
const errorMsg = err?.message || String(err);
|
|
37
|
-
debug(scope, "Error event received", errorMsg);
|
|
38
|
-
triggerReconnect(errorMsg);
|
|
39
|
-
if (callbacks.onError) {
|
|
40
|
-
callbacks.onError(client, err);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
client.on(events.disconnected, onDisconnected);
|
|
44
|
-
if (events.error) {
|
|
45
|
-
client.on(events.error, onError);
|
|
46
|
-
}
|
|
47
|
-
const setupVisibilityHandling = () => {
|
|
48
|
-
if (typeof document === "undefined") {
|
|
49
|
-
return;
|
|
8
|
+
export const createConnectionManager = (client, callbacks, events, options = {}) => {
|
|
9
|
+
const { reconnectInterval = 5000, maxReconnectAttempts = Infinity, enableVisibilityHandling = true, scope = Scope.Network, onVisibilityChange, } = options;
|
|
10
|
+
let isPaused = false;
|
|
11
|
+
let reconnectLoop = null;
|
|
12
|
+
let visibilityChangeHandler = null;
|
|
13
|
+
const triggerReconnect = (reason) => {
|
|
14
|
+
if (!isPaused) {
|
|
15
|
+
callbacks.onReconnecting(client, reason);
|
|
16
|
+
reconnectLoop = null;
|
|
17
|
+
startConnectionLoop();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const onConnected = () => callbacks.onConnected(client);
|
|
21
|
+
client.on(events.connected, onConnected);
|
|
22
|
+
const onDisconnected = (...args) => {
|
|
23
|
+
const err = args[0] instanceof Error ? args[0].message : null;
|
|
24
|
+
debug(scope, "Disconnected event received", err);
|
|
25
|
+
triggerReconnect(err);
|
|
26
|
+
};
|
|
27
|
+
const onError = (err) => {
|
|
28
|
+
const errorMsg = err?.message || String(err);
|
|
29
|
+
debug(scope, "Error event received", errorMsg);
|
|
30
|
+
triggerReconnect(errorMsg);
|
|
31
|
+
if (callbacks.onError) {
|
|
32
|
+
callbacks.onError(client, err);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
client.on(events.disconnected, onDisconnected);
|
|
36
|
+
if (events.error) {
|
|
37
|
+
client.on(events.error, onError);
|
|
50
38
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
39
|
+
const setupVisibilityHandling = () => {
|
|
40
|
+
if (typeof document === "undefined") {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
visibilityChangeHandler = () => {
|
|
44
|
+
const state = document.visibilityState;
|
|
45
|
+
if (onVisibilityChange) {
|
|
46
|
+
const context = {
|
|
47
|
+
client,
|
|
48
|
+
state,
|
|
49
|
+
setPaused: (value) => {
|
|
50
|
+
isPaused = value;
|
|
51
|
+
},
|
|
52
|
+
isPaused: () => isPaused,
|
|
53
|
+
startConnectionLoop,
|
|
54
|
+
};
|
|
55
|
+
(async () => {
|
|
56
|
+
try {
|
|
57
|
+
await onVisibilityChange(context);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
debug(scope, "Error in custom visibility change handler:", err);
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (state === "hidden") {
|
|
66
|
+
isPaused = true;
|
|
67
|
+
(async () => {
|
|
68
|
+
try {
|
|
69
|
+
await client.disconnect();
|
|
70
|
+
callbacks.onDisconnected(client);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
debug(scope, "Error disconnecting on visibility change:", err);
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
}
|
|
77
|
+
else if (state === "visible") {
|
|
78
|
+
if (isPaused) {
|
|
79
|
+
isPaused = false;
|
|
80
|
+
startConnectionLoop();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
62
83
|
};
|
|
63
|
-
(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
})();
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (state === "hidden") {
|
|
73
|
-
isPaused = true;
|
|
74
|
-
(async () => {
|
|
75
|
-
try {
|
|
76
|
-
await client.disconnect();
|
|
77
|
-
callbacks.onDisconnected(client);
|
|
78
|
-
} catch (err) {
|
|
79
|
-
debug(scope, "Error disconnecting on visibility change:", err);
|
|
80
|
-
}
|
|
81
|
-
})();
|
|
82
|
-
} else if (state === "visible") {
|
|
83
|
-
if (isPaused) {
|
|
84
|
-
isPaused = false;
|
|
85
|
-
startConnectionLoop();
|
|
84
|
+
document.addEventListener("visibilitychange", visibilityChangeHandler);
|
|
85
|
+
};
|
|
86
|
+
const startConnectionLoop = () => {
|
|
87
|
+
if (reconnectLoop) {
|
|
88
|
+
return;
|
|
86
89
|
}
|
|
87
|
-
|
|
90
|
+
reconnectLoop = (async () => {
|
|
91
|
+
let reconnectAttempts = 0;
|
|
92
|
+
let wasConnected = false;
|
|
93
|
+
while (true) {
|
|
94
|
+
if (isPaused) {
|
|
95
|
+
await sleep(1000);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
await client.connect();
|
|
100
|
+
// onConnected is fired via the "connection" event emitted inside client.connect()
|
|
101
|
+
// — do NOT call callbacks.onConnected here too, that would double-fire it.
|
|
102
|
+
reconnectAttempts = 0;
|
|
103
|
+
wasConnected = true;
|
|
104
|
+
reconnectLoop = null;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
reconnectAttempts++;
|
|
109
|
+
if (wasConnected || reconnectAttempts === 1) {
|
|
110
|
+
callbacks.onReconnecting(client, `${e}`);
|
|
111
|
+
wasConnected = false;
|
|
112
|
+
}
|
|
113
|
+
if (reconnectAttempts > maxReconnectAttempts) {
|
|
114
|
+
callbacks.onDisconnected(client);
|
|
115
|
+
reconnectLoop = null;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
await client.disconnect();
|
|
120
|
+
}
|
|
121
|
+
catch (disconnectError) {
|
|
122
|
+
debug(scope, "Failed to disconnect client", disconnectError);
|
|
123
|
+
}
|
|
124
|
+
await sleep(reconnectInterval);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
})();
|
|
88
128
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const startConnectionLoop = () => {
|
|
92
|
-
if (reconnectLoop) {
|
|
93
|
-
return;
|
|
129
|
+
if (enableVisibilityHandling) {
|
|
130
|
+
setupVisibilityHandling();
|
|
94
131
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (isPaused) {
|
|
100
|
-
await sleep(1000);
|
|
101
|
-
continue;
|
|
132
|
+
const cleanup = async () => {
|
|
133
|
+
isPaused = true;
|
|
134
|
+
if (typeof document !== "undefined" && visibilityChangeHandler !== null) {
|
|
135
|
+
document.removeEventListener("visibilitychange", visibilityChangeHandler);
|
|
102
136
|
}
|
|
137
|
+
client.off(events.connected, onConnected);
|
|
138
|
+
client.off(events.disconnected, onDisconnected);
|
|
139
|
+
if (events.error) {
|
|
140
|
+
client.off(events.error, onError);
|
|
141
|
+
}
|
|
142
|
+
callbacks.onDisconnected(client);
|
|
103
143
|
try {
|
|
104
|
-
await client.connect();
|
|
105
|
-
// onConnected is fired via the "connection" event emitted inside client.connect()
|
|
106
|
-
// — do NOT call callbacks.onConnected here too, that would double-fire it.
|
|
107
|
-
reconnectAttempts = 0;
|
|
108
|
-
wasConnected = true;
|
|
109
|
-
reconnectLoop = null;
|
|
110
|
-
return;
|
|
111
|
-
} catch (e) {
|
|
112
|
-
reconnectAttempts++;
|
|
113
|
-
if (wasConnected || reconnectAttempts === 1) {
|
|
114
|
-
callbacks.onReconnecting(client, `${e}`);
|
|
115
|
-
wasConnected = false;
|
|
116
|
-
}
|
|
117
|
-
if (reconnectAttempts > maxReconnectAttempts) {
|
|
118
|
-
callbacks.onDisconnected(client);
|
|
119
|
-
reconnectLoop = null;
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
144
|
await client.disconnect();
|
|
124
|
-
} catch (disconnectError) {
|
|
125
|
-
debug(scope, "Failed to disconnect client", disconnectError);
|
|
126
|
-
}
|
|
127
|
-
await sleep(reconnectInterval);
|
|
128
145
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (typeof document !== "undefined" && visibilityChangeHandler !== null) {
|
|
138
|
-
document.removeEventListener("visibilitychange", visibilityChangeHandler);
|
|
139
|
-
}
|
|
140
|
-
client.off(events.connected, onConnected);
|
|
141
|
-
client.off(events.disconnected, onDisconnected);
|
|
142
|
-
if (events.error) {
|
|
143
|
-
client.off(events.error, onError);
|
|
144
|
-
}
|
|
145
|
-
callbacks.onDisconnected(client);
|
|
146
|
-
try {
|
|
147
|
-
await client.disconnect();
|
|
148
|
-
} catch (e) {
|
|
149
|
-
debug(scope, "Failed to disconnect client during cleanup", e);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
return {
|
|
153
|
-
cleanup,
|
|
154
|
-
startConnectionLoop,
|
|
155
|
-
};
|
|
146
|
+
catch (e) {
|
|
147
|
+
debug(scope, "Failed to disconnect client during cleanup", e);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
cleanup,
|
|
152
|
+
startConnectionLoop,
|
|
153
|
+
};
|
|
156
154
|
};
|
|
157
|
-
//# sourceMappingURL=connection-manager.js.map
|
|
155
|
+
//# sourceMappingURL=connection-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-manager.js","sourceRoot":"","sources":["../src/connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAY,MAAM,UAAU,CAAC;AAGlD,KAAK,UAAU,KAAK,CAAC,EAAU;IAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAgCD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,MAAe,EACf,SAKC,EACD,MAIC,EACD,UAA6C,EAAE,EACtB,EAAE;IAC3B,MAAM,EACJ,iBAAiB,GAAG,IAAI,EACxB,oBAAoB,GAAG,QAAQ,EAC/B,wBAAwB,GAAG,IAAI,EAC/B,KAAK,GAAG,KA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AAC,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC1C,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;QAChD,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACpC,CAAC;QAED,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAEjC,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QAC5B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,KAAK,CAAC,KAAK,EAAE,4CAA4C,EAAE,CAAC,CAAC,CAAC;QAChE,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,OAAO;QACP,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/dapp-relay.d.ts
CHANGED
|
@@ -3,25 +3,22 @@ import { RelayStatusCallback } from "./relay-handler.js";
|
|
|
3
3
|
import { KeyExchangeCredentials } from "./key-exchange.js";
|
|
4
4
|
import { EventEmitter } from "eventemitter3";
|
|
5
5
|
export interface DappRelayOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
explicitRelayUrls?: string[];
|
|
7
|
+
reconnectInterval?: number;
|
|
8
|
+
maxReconnectAttempts?: number;
|
|
9
|
+
existingCredentials?: {
|
|
10
|
+
privateKey: string;
|
|
11
|
+
secret: string;
|
|
12
|
+
};
|
|
13
13
|
}
|
|
14
14
|
export interface DappRelayResult {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
client: RelayClient;
|
|
16
|
+
uri: string;
|
|
17
|
+
qrUri: string;
|
|
18
|
+
credentials: KeyExchangeCredentials;
|
|
19
|
+
events: EventEmitter<{
|
|
20
|
+
keyexchangecomplete: [walletPublicKey: Uint8Array];
|
|
21
|
+
}>;
|
|
22
|
+
cleanup: () => void;
|
|
23
23
|
}
|
|
24
|
-
export declare function initiateDappRelay(
|
|
25
|
-
statusCallback: RelayStatusCallback,
|
|
26
|
-
options?: DappRelayOptions,
|
|
27
|
-
): DappRelayResult;
|
|
24
|
+
export declare function initiateDappRelay(statusCallback: RelayStatusCallback, options?: DappRelayOptions): DappRelayResult;
|
package/dist/dapp-relay.js
CHANGED
|
@@ -1,129 +1,113 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright (C) 2026 Whiterun LLC,
|
|
2
|
+
// This software is licensed under the GNU Lesser General Public License (LGPL), version 3.0 or later.
|
|
3
|
+
// A copy of the license can be found in the LICENSE file or at https://www.gnu.org/licenses/lgpl-3.0.html
|
|
4
|
+
import { initiateRelay, } from "./relay-handler.js";
|
|
2
5
|
import { RelayMsgAction } from "./protocols/hdwalletv1.js";
|
|
3
|
-
import {
|
|
4
|
-
generateKeyExchangeCredentials,
|
|
5
|
-
encodeKeyExchangeURI,
|
|
6
|
-
DEFAULT_RELAY_HOSTNAME,
|
|
7
|
-
DEFAULT_RELAY_PORT,
|
|
8
|
-
DEFAULT_RELAY_PROTOCOL,
|
|
9
|
-
} from "./key-exchange.js";
|
|
6
|
+
import { generateKeyExchangeCredentials, encodeKeyExchangeURI, DEFAULT_RELAY_HOSTNAME, DEFAULT_RELAY_PORT, DEFAULT_RELAY_PROTOCOL, } from "./key-exchange.js";
|
|
10
7
|
import { hexToBin, binToHex } from "@bitauth/libauth";
|
|
11
8
|
import { EventEmitter } from "eventemitter3";
|
|
12
9
|
import { deriveNostrPublicKey } from "./utilnostr.js";
|
|
13
10
|
import { error as logError, warn, Scope } from "./log.js";
|
|
14
11
|
export function initiateDappRelay(statusCallback, options = {}) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} else {
|
|
31
|
-
credentials = generateKeyExchangeCredentials();
|
|
32
|
-
dappPrivateKey = hexToBin(credentials.privateKey);
|
|
33
|
-
}
|
|
34
|
-
let uriOptions = {};
|
|
35
|
-
if (options.explicitRelayUrls && options.explicitRelayUrls.length > 0) {
|
|
36
|
-
const relayUrl = options.explicitRelayUrls[0];
|
|
37
|
-
const hostMatch = relayUrl.match(/^wss?:\/\/([^:/]+)/);
|
|
38
|
-
const portMatch = relayUrl.match(/:(\d+)/);
|
|
39
|
-
if (hostMatch) {
|
|
40
|
-
uriOptions.hostname = hostMatch[1];
|
|
12
|
+
const events = new EventEmitter();
|
|
13
|
+
let credentials;
|
|
14
|
+
let dappPrivateKey;
|
|
15
|
+
if (options.existingCredentials) {
|
|
16
|
+
const privateKeyHex = options.existingCredentials.privateKey;
|
|
17
|
+
if (privateKeyHex.length !== 64) {
|
|
18
|
+
throw new Error("Private key must be 64 hex characters (32 bytes)");
|
|
19
|
+
}
|
|
20
|
+
dappPrivateKey = hexToBin(privateKeyHex);
|
|
21
|
+
const dappPublicKeyHex = deriveNostrPublicKey(dappPrivateKey);
|
|
22
|
+
credentials = {
|
|
23
|
+
privateKey: privateKeyHex,
|
|
24
|
+
publicKey: dappPublicKeyHex,
|
|
25
|
+
secret: options.existingCredentials.secret,
|
|
26
|
+
};
|
|
41
27
|
}
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
else {
|
|
29
|
+
credentials = generateKeyExchangeCredentials();
|
|
30
|
+
dappPrivateKey = hexToBin(credentials.privateKey);
|
|
44
31
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
32
|
+
let uriOptions = {};
|
|
33
|
+
if (options.explicitRelayUrls && options.explicitRelayUrls.length > 0) {
|
|
34
|
+
const relayUrl = options.explicitRelayUrls[0];
|
|
35
|
+
const hostMatch = relayUrl.match(/^wss?:\/\/([^:/]+)/);
|
|
36
|
+
const portMatch = relayUrl.match(/:(\d+)/);
|
|
37
|
+
if (hostMatch) {
|
|
38
|
+
uriOptions.hostname = hostMatch[1];
|
|
39
|
+
}
|
|
40
|
+
if (portMatch) {
|
|
41
|
+
uriOptions.port = parseInt(portMatch[1], 10);
|
|
42
|
+
}
|
|
43
|
+
if (relayUrl.startsWith("wss://")) {
|
|
44
|
+
uriOptions.protocol = "wss";
|
|
45
|
+
}
|
|
46
|
+
else if (relayUrl.startsWith("ws://")) {
|
|
47
|
+
uriOptions.protocol = "ws";
|
|
48
|
+
}
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
50
|
+
const { uri, qrUri } = encodeKeyExchangeURI(credentials.publicKey, credentials.secret, uriOptions);
|
|
51
|
+
let relayClient = null;
|
|
52
|
+
let keyExchanged = false;
|
|
53
|
+
let walletPublicKeyNostr = null;
|
|
54
|
+
const wrappedCallback = (payload) => {
|
|
55
|
+
if (!relayClient) {
|
|
56
|
+
relayClient = payload.client;
|
|
57
|
+
relayClient.on("message", async (message) => {
|
|
58
|
+
if (message.action === RelayMsgAction.WalletReady) {
|
|
59
|
+
const walletReady = message;
|
|
60
|
+
if (walletReady.secret !== credentials.secret) {
|
|
61
|
+
if (!keyExchanged) {
|
|
62
|
+
logError(Scope.Relay, "Key exchange failed: secret mismatch");
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const receivedWalletKey = hexToBin(walletReady.public_key);
|
|
67
|
+
if (receivedWalletKey.length !== 32) {
|
|
68
|
+
logError(Scope.Relay, "Invalid wallet public key length");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (keyExchanged && walletPublicKeyNostr) {
|
|
72
|
+
if (binToHex(receivedWalletKey) !== binToHex(walletPublicKeyNostr)) {
|
|
73
|
+
warn(Scope.Relay, "Different wallet connected (different public key)");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
walletPublicKeyNostr = receivedWalletKey;
|
|
77
|
+
relayClient.setPairedPublicKey(receivedWalletKey);
|
|
78
|
+
if (!keyExchanged) {
|
|
79
|
+
keyExchanged = true;
|
|
80
|
+
events.emit("keyexchangecomplete", receivedWalletKey);
|
|
81
|
+
}
|
|
82
|
+
// NOTE: do NOT return — message also propagates to DappConnectionManager's listener
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (payload.status.status === "connected") {
|
|
87
|
+
if (walletPublicKeyNostr && relayClient) {
|
|
88
|
+
relayClient.setPairedPublicKey(walletPublicKeyNostr);
|
|
89
|
+
keyExchanged = true;
|
|
84
90
|
}
|
|
85
|
-
}
|
|
86
|
-
walletPublicKeyNostr = receivedWalletKey;
|
|
87
|
-
relayClient.setPairedPublicKey(receivedWalletKey);
|
|
88
|
-
if (!keyExchanged) {
|
|
89
|
-
keyExchanged = true;
|
|
90
|
-
events.emit("keyexchangecomplete", receivedWalletKey);
|
|
91
|
-
}
|
|
92
|
-
// NOTE: do NOT return — message also propagates to DappConnectionManager's listener
|
|
93
91
|
}
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
statusCallback(payload);
|
|
103
|
-
};
|
|
104
|
-
const relayUrls =
|
|
105
|
-
options.explicitRelayUrls && options.explicitRelayUrls.length > 0
|
|
106
|
-
? options.explicitRelayUrls
|
|
107
|
-
: [
|
|
108
|
-
`${DEFAULT_RELAY_PROTOCOL}://${DEFAULT_RELAY_HOSTNAME}:${DEFAULT_RELAY_PORT}`,
|
|
92
|
+
statusCallback(payload);
|
|
93
|
+
};
|
|
94
|
+
const relayUrls = options.explicitRelayUrls && options.explicitRelayUrls.length > 0
|
|
95
|
+
? options.explicitRelayUrls
|
|
96
|
+
: [
|
|
97
|
+
`${DEFAULT_RELAY_PROTOCOL}://${DEFAULT_RELAY_HOSTNAME}:${DEFAULT_RELAY_PORT}`,
|
|
109
98
|
];
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
qrUri,
|
|
124
|
-
credentials,
|
|
125
|
-
events,
|
|
126
|
-
cleanup,
|
|
127
|
-
};
|
|
99
|
+
const cleanup = initiateRelay(wrappedCallback, dappPrivateKey, new Uint8Array(33), {
|
|
100
|
+
explicitRelayUrls: relayUrls,
|
|
101
|
+
reconnectInterval: options.reconnectInterval,
|
|
102
|
+
maxReconnectAttempts: options.maxReconnectAttempts,
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
client: relayClient,
|
|
106
|
+
uri,
|
|
107
|
+
qrUri,
|
|
108
|
+
credentials,
|
|
109
|
+
events,
|
|
110
|
+
cleanup,
|
|
111
|
+
};
|
|
128
112
|
}
|
|
129
|
-
//# sourceMappingURL=dapp-relay.js.map
|
|
113
|
+
//# sourceMappingURL=dapp-relay.js.map
|