@openlv/session 0.0.1-beta.5 → 0.0.1-beta.7
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/base.d.ts +16 -4
- package/dist/base.js +102 -50
- package/dist/base.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.test.js +1 -1
- package/dist/index.test.js.map +1 -1
- package/dist/utils/log.js +4 -1
- package/dist/utils/log.js.map +1 -1
- package/package.json +8 -4
- package/dist/types.d.ts +0 -56
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
package/dist/base.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { type SessionHandshakeParameters, type SessionLinkParameters } from "@openlv/core";
|
|
2
|
-
import type
|
|
2
|
+
import { type CreateSignalLayerFn, type SignalingLayer, type SignalState } from "@openlv/signaling";
|
|
3
|
+
import { type TransportLayer } from "@openlv/transport";
|
|
3
4
|
import { EventEmitter } from "eventemitter3";
|
|
4
5
|
import type { SessionEvents } from "./events.js";
|
|
5
|
-
export
|
|
6
|
+
export declare const SESSION_STATE: {
|
|
7
|
+
readonly CREATED: "created";
|
|
8
|
+
readonly SIGNALING: "signaling";
|
|
9
|
+
readonly READY: "ready";
|
|
10
|
+
readonly CONNECTED: "connected";
|
|
11
|
+
readonly DISCONNECTED: "disconnected";
|
|
12
|
+
};
|
|
13
|
+
export type SessionState = (typeof SESSION_STATE)[keyof typeof SESSION_STATE];
|
|
6
14
|
export type SessionStateObject = {
|
|
7
|
-
status:
|
|
15
|
+
status: SessionState;
|
|
8
16
|
signaling?: {
|
|
9
|
-
state:
|
|
17
|
+
state: SignalState;
|
|
10
18
|
};
|
|
11
19
|
};
|
|
12
20
|
/**
|
|
@@ -22,6 +30,10 @@ export type Session = {
|
|
|
22
30
|
close(): Promise<void>;
|
|
23
31
|
send(message: object, timeout?: number): Promise<unknown>;
|
|
24
32
|
emitter: EventEmitter<SessionEvents>;
|
|
33
|
+
_internal: {
|
|
34
|
+
signal: SignalingLayer;
|
|
35
|
+
transport: TransportLayer;
|
|
36
|
+
};
|
|
25
37
|
};
|
|
26
38
|
/**
|
|
27
39
|
* OpenLV Session
|
package/dist/base.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { decodeConnectionURL, OPENLV_PROTOCOL_VERSION, } from "@openlv/core";
|
|
2
2
|
import { deriveSymmetricKey, generateHandshakeKey, generateSessionId, initEncryptionKeys, initHash, parseEncryptionKey, } from "@openlv/core/encryption";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { SIGNAL_STATE, } from "@openlv/signaling";
|
|
4
|
+
import { dynamicSignalingLayer } from "@openlv/signaling/dynamic";
|
|
5
|
+
import { TRANSPORT_STATE, } from "@openlv/transport";
|
|
6
|
+
import { webrtc } from "@openlv/transport/webrtc";
|
|
5
7
|
import { EventEmitter } from "eventemitter3";
|
|
6
8
|
import { log } from "./utils/log.js";
|
|
9
|
+
export const SESSION_STATE = {
|
|
10
|
+
CREATED: "created",
|
|
11
|
+
SIGNALING: "signaling",
|
|
12
|
+
READY: "ready",
|
|
13
|
+
CONNECTED: "connected",
|
|
14
|
+
DISCONNECTED: "disconnected",
|
|
15
|
+
};
|
|
7
16
|
/**
|
|
8
17
|
* OpenLV Session
|
|
9
18
|
*
|
|
@@ -15,15 +24,19 @@ export const createSession = async (initParameters, signalLayer, onMessage) => {
|
|
|
15
24
|
const sessionId = "sessionId" in initParameters
|
|
16
25
|
? initParameters.sessionId
|
|
17
26
|
: generateSessionId();
|
|
18
|
-
const { encryptionKey, decryptionKey } = await initEncryptionKeys(initParameters);
|
|
27
|
+
const { encryptionKey, decryptionKey: { decrypt }, } = await initEncryptionKeys(initParameters);
|
|
19
28
|
let relyingPublicKey;
|
|
20
29
|
const handshakeKey = "k" in initParameters
|
|
21
30
|
? await deriveSymmetricKey(initParameters.k)
|
|
22
31
|
: await generateHandshakeKey();
|
|
23
32
|
const { hash, isHost } = await initHash("h" in initParameters ? initParameters.h : undefined, encryptionKey);
|
|
24
|
-
let status =
|
|
33
|
+
let status = SESSION_STATE.CREATED;
|
|
25
34
|
const protocol = initParameters.p;
|
|
26
35
|
const server = initParameters.s;
|
|
36
|
+
const updateStatus = (newStatus) => {
|
|
37
|
+
status = newStatus;
|
|
38
|
+
emitter.emit("state_change", { status, signaling: signal.getState() });
|
|
39
|
+
};
|
|
27
40
|
const signaling = await signalLayer({
|
|
28
41
|
topic: sessionId,
|
|
29
42
|
url: server,
|
|
@@ -40,14 +53,7 @@ export const createSession = async (initParameters, signalLayer, onMessage) => {
|
|
|
40
53
|
log(`encrypting to ${relyingPublicKey.toString()}`, message);
|
|
41
54
|
return await relyingPublicKey.encrypt(message);
|
|
42
55
|
},
|
|
43
|
-
|
|
44
|
-
if (!decryptionKey) {
|
|
45
|
-
throw new Error("Decryption key not found");
|
|
46
|
-
}
|
|
47
|
-
const response = await decryptionKey.decrypt(message);
|
|
48
|
-
log("decrypted message", response);
|
|
49
|
-
return response;
|
|
50
|
-
},
|
|
56
|
+
decrypt,
|
|
51
57
|
publicKey: encryptionKey,
|
|
52
58
|
k: handshakeKey,
|
|
53
59
|
async rpDiscovered(rpKey) {
|
|
@@ -57,54 +63,97 @@ export const createSession = async (initParameters, signalLayer, onMessage) => {
|
|
|
57
63
|
},
|
|
58
64
|
isHost,
|
|
59
65
|
});
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
const transport = webrtc({ isHost })({
|
|
67
|
+
encrypt(message) {
|
|
68
|
+
if (!relyingPublicKey) {
|
|
69
|
+
throw new Error("Relying party public key not found");
|
|
70
|
+
}
|
|
71
|
+
return relyingPublicKey?.encrypt(message);
|
|
72
|
+
},
|
|
73
|
+
decrypt,
|
|
74
|
+
isHost,
|
|
75
|
+
onmessage: async (message) => {
|
|
76
|
+
console.log("Session: received message from transport", message);
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
if (message["type"] === "request") {
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
const data = await onMessage(message["payload"]);
|
|
81
|
+
const response = {
|
|
82
|
+
type: "response",
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
messageId: message["messageId"],
|
|
85
|
+
payload: data,
|
|
86
|
+
};
|
|
87
|
+
await transport.send(response);
|
|
88
|
+
}
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
if (message["type"] === "response") {
|
|
91
|
+
messages.emit("message", message);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
async subsend(message) {
|
|
95
|
+
console.log("Session: sending trans msg to signal", message);
|
|
96
|
+
const sessionMessage = {
|
|
97
|
+
type: "request",
|
|
98
|
+
messageId: crypto.randomUUID(),
|
|
99
|
+
payload: message,
|
|
100
|
+
};
|
|
101
|
+
await signal.send(sessionMessage);
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
transport.emitter.on("state_change", (state) => {
|
|
105
|
+
log("transport state change", state);
|
|
106
|
+
if (state === TRANSPORT_STATE.CONNECTED) {
|
|
107
|
+
updateStatus(SESSION_STATE.CONNECTED);
|
|
108
|
+
}
|
|
66
109
|
});
|
|
110
|
+
const startTransport = async () => {
|
|
111
|
+
await transport.setup();
|
|
112
|
+
};
|
|
67
113
|
// let transport: TransportLayer | undefined;
|
|
114
|
+
const onSignalMessage = async (message) => {
|
|
115
|
+
log("Session: received message from signaling", message);
|
|
116
|
+
const sessionMsg = message;
|
|
117
|
+
if (sessionMsg.type === "response") {
|
|
118
|
+
log("Session: received data message", sessionMsg.payload);
|
|
119
|
+
messages.emit("message", sessionMsg);
|
|
120
|
+
}
|
|
121
|
+
if (sessionMsg.type === "request") {
|
|
122
|
+
log("Session: received request message", sessionMsg.payload);
|
|
123
|
+
transport.handle(sessionMsg.payload);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
68
126
|
return {
|
|
69
127
|
connect: async () => {
|
|
70
|
-
updateStatus(
|
|
128
|
+
updateStatus(SESSION_STATE.SIGNALING);
|
|
71
129
|
log("connecting to session, isHost:", isHost);
|
|
72
130
|
// TODO: implement
|
|
73
131
|
log("connecting to session");
|
|
74
|
-
|
|
75
|
-
signal.
|
|
76
|
-
log("Session: received message from signaling", message);
|
|
77
|
-
const sessionMsg = message;
|
|
78
|
-
if (sessionMsg.type === "response") {
|
|
79
|
-
log("Session: received data message", sessionMsg.payload);
|
|
80
|
-
messages.emit("message", sessionMsg);
|
|
81
|
-
}
|
|
82
|
-
if (sessionMsg.type === "request") {
|
|
83
|
-
log("Session: received request message", sessionMsg.payload);
|
|
84
|
-
const payload = await onMessage(sessionMsg.payload);
|
|
85
|
-
const responseMessage = {
|
|
86
|
-
type: "response",
|
|
87
|
-
messageId: sessionMsg.messageId,
|
|
88
|
-
payload,
|
|
89
|
-
};
|
|
90
|
-
await signal.send(responseMessage);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
signal.emitter.on("state_change", (state) => {
|
|
132
|
+
signal.on("message", onSignalMessage);
|
|
133
|
+
signal.on("state_change", (state) => {
|
|
94
134
|
log("signal state change", state);
|
|
95
|
-
if (state ===
|
|
135
|
+
if (state === SIGNAL_STATE.READY) {
|
|
136
|
+
updateStatus(SESSION_STATE.READY);
|
|
137
|
+
}
|
|
138
|
+
if (state === SIGNAL_STATE.ENCRYPTED) {
|
|
96
139
|
// for now cuz we just use signaling call this a full connection
|
|
97
|
-
updateStatus("connected");
|
|
140
|
+
// updateStatus("connected");
|
|
141
|
+
startTransport();
|
|
98
142
|
}
|
|
99
143
|
});
|
|
144
|
+
await signal.setup();
|
|
100
145
|
},
|
|
101
146
|
async close() {
|
|
102
147
|
log("session teardown");
|
|
103
148
|
await signal?.teardown();
|
|
104
|
-
updateStatus(
|
|
149
|
+
updateStatus(SESSION_STATE.DISCONNECTED);
|
|
105
150
|
},
|
|
106
151
|
getState() {
|
|
107
|
-
return {
|
|
152
|
+
return {
|
|
153
|
+
status,
|
|
154
|
+
signaling: signal.getState(),
|
|
155
|
+
// transport: transport.getState(),
|
|
156
|
+
};
|
|
108
157
|
},
|
|
109
158
|
getHandshakeParameters() {
|
|
110
159
|
return {
|
|
@@ -119,14 +168,15 @@ export const createSession = async (initParameters, signalLayer, onMessage) => {
|
|
|
119
168
|
waitForLink: async () => {
|
|
120
169
|
return new Promise((resolve) => {
|
|
121
170
|
emitter.on("state_change", (state) => {
|
|
122
|
-
if (state?.status ===
|
|
171
|
+
if (state?.status === SESSION_STATE.CONNECTED) {
|
|
123
172
|
resolve();
|
|
124
173
|
}
|
|
125
174
|
});
|
|
126
175
|
});
|
|
127
176
|
},
|
|
128
177
|
async send(message, timeout = 5000) {
|
|
129
|
-
const ready = signal.getState().state ===
|
|
178
|
+
const ready = signal.getState().state === SIGNAL_STATE.ENCRYPTED;
|
|
179
|
+
// const transportReady = transport.getState() === TRANSPORT_STATE.CONNECTED;
|
|
130
180
|
if (!ready) {
|
|
131
181
|
throw new Error("Session not ready");
|
|
132
182
|
}
|
|
@@ -137,7 +187,8 @@ export const createSession = async (initParameters, signalLayer, onMessage) => {
|
|
|
137
187
|
payload: message,
|
|
138
188
|
};
|
|
139
189
|
// for now use signaling
|
|
140
|
-
await signal.send(sessionMessage);
|
|
190
|
+
// await signal.send(sessionMessage);
|
|
191
|
+
await transport.send(sessionMessage);
|
|
141
192
|
return Promise.race([
|
|
142
193
|
new Promise((resolve) => {
|
|
143
194
|
messages.on("message", (message) => {
|
|
@@ -153,6 +204,10 @@ export const createSession = async (initParameters, signalLayer, onMessage) => {
|
|
|
153
204
|
}),
|
|
154
205
|
]);
|
|
155
206
|
},
|
|
207
|
+
_internal: {
|
|
208
|
+
signal,
|
|
209
|
+
transport,
|
|
210
|
+
},
|
|
156
211
|
emitter,
|
|
157
212
|
};
|
|
158
213
|
};
|
|
@@ -161,10 +216,7 @@ export const createSession = async (initParameters, signalLayer, onMessage) => {
|
|
|
161
216
|
*/
|
|
162
217
|
export const connectSession = async (connectionUrl, onMessage) => {
|
|
163
218
|
const initParameters = decodeConnectionURL(connectionUrl);
|
|
164
|
-
const signaling =
|
|
165
|
-
mqtt: mqtt,
|
|
166
|
-
ntfy: ntfy,
|
|
167
|
-
}[initParameters.p];
|
|
219
|
+
const signaling = await dynamicSignalingLayer(initParameters.p);
|
|
168
220
|
if (!signaling) {
|
|
169
221
|
throw new Error(`Invalid signaling protocol: ${initParameters.p}`);
|
|
170
222
|
}
|
package/dist/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GAGxB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAElB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,QAAQ,EACR,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GAGxB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,kBAAkB,EAElB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,QAAQ,EACR,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,YAAY,GAGb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EACL,eAAe,GAGhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI7C,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAErC,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,OAAO;IACd,SAAS,EA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 @@
|
|
|
6
6
|
* without relying on centralized infrastructure.
|
|
7
7
|
*/
|
|
8
8
|
export * from "./base.js";
|
|
9
|
-
export type { ConnectionEvents, ConnectionPhase, ConnectionState, DAppInfo, ErrorHandler, EthereumMethod, EthereumRequest, JsonRpcError, JsonRpcRequest, JsonRpcResponse, MessageHandler, PhaseHandler, SessionConfig, WalletInfo, } from "./types.js";
|
package/dist/index.test.js
CHANGED
|
@@ -29,7 +29,7 @@ describe("Session", () => {
|
|
|
29
29
|
});
|
|
30
30
|
console.log(sessionB.getState());
|
|
31
31
|
await sessionB.connect();
|
|
32
|
-
await
|
|
32
|
+
await Promise.all([sessionA.waitForLink(), sessionB.waitForLink()]);
|
|
33
33
|
//
|
|
34
34
|
console.log("A", sessionA.getState());
|
|
35
35
|
console.log("B", sessionB.getState());
|
package/dist/index.test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1D,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,IAAI,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;QACpD,MAAM,QAAQ,GAAG,MAAM,aAAa,CAClC;YACE,SAAS,EAAE,kBAAkB;YAC7B,CAAC,EAAE,MAAM;YACT,CAAC,EAAE,kBAAkB;SACtB,EACD,IAAI,EACJ,KAAK,EAAE,OAAO,EAAE,EAAE;YAChB,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,OAAO,CAAC,CAAC;YAElD,OAAO,EAAE,MAAM,EA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AAE,OAAO,EAAE,EAAE;YAClE,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,OAAO,CAAC,CAAC;YAElD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjC,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;QAEzB,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QAEpE,EAAE;QACF,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEtC,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAEvD,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAElC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/utils/log.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export const log = (...x) => console.log("
|
|
1
|
+
export const log = (...x) => console.log("[session]",
|
|
2
|
+
// "color: orange; font-weight: bold",
|
|
3
|
+
// "color: inherit; font-weight: normal",
|
|
4
|
+
...x);
|
|
2
5
|
//# sourceMappingURL=log.js.map
|
package/dist/utils/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/utils/log.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,CAAiC,EAAE,EAAE,CAC1D,OAAO,CAAC,GAAG,CACT,
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/utils/log.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,CAAiC,EAAE,EAAE,CAC1D,OAAO,CAAC,GAAG,CACT,WAAW;AACX,sCAAsC;AACtC,yCAAyC;AACzC,GAAG,CAAC,CACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openlv/session",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.7",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"open-lavatory"
|
|
6
6
|
],
|
|
@@ -42,10 +42,13 @@
|
|
|
42
42
|
"eventemitter3": "^5.0.1",
|
|
43
43
|
"globals": "^16.2.0",
|
|
44
44
|
"ts-pattern": "^5",
|
|
45
|
-
"@openlv/core": "0.0.1-beta.
|
|
46
|
-
"@openlv/signaling": "0.0.1-beta.
|
|
45
|
+
"@openlv/core": "0.0.1-beta.7",
|
|
46
|
+
"@openlv/signaling": "0.0.1-beta.6",
|
|
47
|
+
"@openlv/transport": "0.0.1-beta.5"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
50
|
+
"@vitest/browser-playwright": "^4.0.8",
|
|
51
|
+
"playwright": "^1.56.1",
|
|
49
52
|
"typescript": "^5",
|
|
50
53
|
"vitest": "^4"
|
|
51
54
|
},
|
|
@@ -60,6 +63,7 @@
|
|
|
60
63
|
},
|
|
61
64
|
"scripts": {
|
|
62
65
|
"build": "tsc",
|
|
63
|
-
"test": "vitest"
|
|
66
|
+
"test": "vitest",
|
|
67
|
+
"test:install": "playwright install --with-deps"
|
|
64
68
|
}
|
|
65
69
|
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Open Lavatory Protocol Types
|
|
3
|
-
* Includes JSON-RPC types for Ethereum wallet connectivity
|
|
4
|
-
*/
|
|
5
|
-
export type ConnectionState = "disconnected" | "mqtt-connecting" | "mqtt-connected" | "pairing" | "key-exchange" | "webrtc-negotiating" | "webrtc-connected";
|
|
6
|
-
export type ConnectionPhase = {
|
|
7
|
-
state: ConnectionState;
|
|
8
|
-
description: string;
|
|
9
|
-
timestamp: number;
|
|
10
|
-
};
|
|
11
|
-
export type SessionConfig = {
|
|
12
|
-
mqttUrl?: string;
|
|
13
|
-
protocol?: "mqtt" | "waku" | "nostr";
|
|
14
|
-
};
|
|
15
|
-
export interface JsonRpcRequest {
|
|
16
|
-
jsonrpc: "2.0";
|
|
17
|
-
id: string | number;
|
|
18
|
-
method: string;
|
|
19
|
-
params?: any[];
|
|
20
|
-
}
|
|
21
|
-
export interface JsonRpcResponse {
|
|
22
|
-
jsonrpc: "2.0";
|
|
23
|
-
id: string | number;
|
|
24
|
-
result?: any;
|
|
25
|
-
error?: JsonRpcError;
|
|
26
|
-
}
|
|
27
|
-
export interface JsonRpcError {
|
|
28
|
-
code: number;
|
|
29
|
-
message: string;
|
|
30
|
-
data?: any;
|
|
31
|
-
}
|
|
32
|
-
export type EthereumMethod = "eth_requestAccounts" | "eth_accounts" | "eth_chainId" | "eth_getBalance" | "eth_blockNumber" | "eth_sendTransaction" | "eth_signTransaction" | "eth_sign" | "personal_sign" | "eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "wallet_switchEthereumChain" | "wallet_addEthereumChain";
|
|
33
|
-
export interface EthereumRequest extends JsonRpcRequest {
|
|
34
|
-
method: EthereumMethod;
|
|
35
|
-
}
|
|
36
|
-
export type EthereumResponse = JsonRpcResponse;
|
|
37
|
-
export interface WalletInfo {
|
|
38
|
-
name: string;
|
|
39
|
-
version: string;
|
|
40
|
-
icon?: string;
|
|
41
|
-
}
|
|
42
|
-
export interface DAppInfo {
|
|
43
|
-
name: string;
|
|
44
|
-
url: string;
|
|
45
|
-
icon?: string;
|
|
46
|
-
}
|
|
47
|
-
export type MessageHandler = (request: JsonRpcRequest) => Promise<any> | any;
|
|
48
|
-
export type PhaseHandler = (phase: ConnectionPhase) => void;
|
|
49
|
-
export type ErrorHandler = (error: Error) => void;
|
|
50
|
-
export interface ConnectionEvents {
|
|
51
|
-
onPhaseChange?: PhaseHandler;
|
|
52
|
-
onMessage?: MessageHandler;
|
|
53
|
-
onError?: ErrorHandler;
|
|
54
|
-
onConnect?: () => void;
|
|
55
|
-
onDisconnect?: () => void;
|
|
56
|
-
}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|