@onekeyfe/onekey-nostr-provider 1.1.51 → 1.1.53
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/ProviderNostr.d.ts +4 -2
- package/dist/ProviderNostr.js +30 -12
- package/dist/cjs/ProviderNostr.js +30 -12
- package/dist/types.d.ts +1 -1
- package/package.json +6 -6
package/dist/ProviderNostr.d.ts
CHANGED
|
@@ -4,9 +4,11 @@ import { IProviderNostr, NostrProviderEventsMap, Event, IRelay } from "./types";
|
|
|
4
4
|
declare class ProviderNostr extends ProviderNostrBase implements IProviderNostr {
|
|
5
5
|
private states;
|
|
6
6
|
constructor(props: IInpageProviderConfig);
|
|
7
|
-
|
|
8
|
-
private
|
|
7
|
+
private _registerEvents;
|
|
8
|
+
private _handleDisconnected;
|
|
9
|
+
private _handleAccountChange;
|
|
9
10
|
on<E extends keyof NostrProviderEventsMap>(event: E, listener: NostrProviderEventsMap[E]): this;
|
|
11
|
+
off<E extends keyof NostrProviderEventsMap>(event: E, listener: NostrProviderEventsMap[E]): this;
|
|
10
12
|
emit<E extends keyof NostrProviderEventsMap>(event: E, ...args: Parameters<NostrProviderEventsMap[E]>): boolean;
|
|
11
13
|
private _callBridge;
|
|
12
14
|
enable(): Promise<boolean>;
|
package/dist/ProviderNostr.js
CHANGED
|
@@ -8,6 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { ProviderNostrBase } from "./ProviderNostrBase";
|
|
11
|
+
function isWalletEventMethodMatch(method, name) {
|
|
12
|
+
return method === `metamask_${name}` || method === `wallet_events_${name}`;
|
|
13
|
+
}
|
|
14
|
+
const PROVIDER_EVENTS = {
|
|
15
|
+
'connect': 'connect',
|
|
16
|
+
'disconnect': 'disconnect',
|
|
17
|
+
'accountChanged': 'accountChanged',
|
|
18
|
+
'message_low_level': 'message_low_level',
|
|
19
|
+
};
|
|
11
20
|
class ProviderNostr extends ProviderNostrBase {
|
|
12
21
|
constructor(props) {
|
|
13
22
|
super(props);
|
|
@@ -25,25 +34,34 @@ class ProviderNostr extends ProviderNostrBase {
|
|
|
25
34
|
return result;
|
|
26
35
|
}),
|
|
27
36
|
};
|
|
37
|
+
this._registerEvents();
|
|
28
38
|
}
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
_registerEvents() {
|
|
40
|
+
window.addEventListener('onekey_bridge_disconnect', () => {
|
|
41
|
+
this._handleDisconnected();
|
|
42
|
+
});
|
|
43
|
+
this.on(PROVIDER_EVENTS.message_low_level, (payload) => {
|
|
44
|
+
const { method } = payload;
|
|
45
|
+
if (isWalletEventMethodMatch(method, PROVIDER_EVENTS.accountChanged)) {
|
|
46
|
+
this._handleAccountChange();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
31
49
|
}
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
throw new Error(message);
|
|
37
|
-
}
|
|
38
|
-
if (this.states.executing) {
|
|
39
|
-
const message = `window.webln call already executing`;
|
|
40
|
-
alert(message);
|
|
41
|
-
throw new Error(message);
|
|
50
|
+
_handleDisconnected(options = { emit: true }) {
|
|
51
|
+
if (options.emit && this.isConnectionStatusChanged('disconnected')) {
|
|
52
|
+
this.emit('disconnect');
|
|
53
|
+
this.emit('accountChanged');
|
|
42
54
|
}
|
|
43
55
|
}
|
|
56
|
+
_handleAccountChange() {
|
|
57
|
+
this.emit('accountChanged');
|
|
58
|
+
}
|
|
44
59
|
on(event, listener) {
|
|
45
60
|
return super.on(event, listener);
|
|
46
61
|
}
|
|
62
|
+
off(event, listener) {
|
|
63
|
+
return super.off(event, listener);
|
|
64
|
+
}
|
|
47
65
|
emit(event, ...args) {
|
|
48
66
|
return super.emit(event, ...args);
|
|
49
67
|
}
|
|
@@ -11,6 +11,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ProviderNostr = void 0;
|
|
13
13
|
const ProviderNostrBase_1 = require("./ProviderNostrBase");
|
|
14
|
+
function isWalletEventMethodMatch(method, name) {
|
|
15
|
+
return method === `metamask_${name}` || method === `wallet_events_${name}`;
|
|
16
|
+
}
|
|
17
|
+
const PROVIDER_EVENTS = {
|
|
18
|
+
'connect': 'connect',
|
|
19
|
+
'disconnect': 'disconnect',
|
|
20
|
+
'accountChanged': 'accountChanged',
|
|
21
|
+
'message_low_level': 'message_low_level',
|
|
22
|
+
};
|
|
14
23
|
class ProviderNostr extends ProviderNostrBase_1.ProviderNostrBase {
|
|
15
24
|
constructor(props) {
|
|
16
25
|
super(props);
|
|
@@ -28,25 +37,34 @@ class ProviderNostr extends ProviderNostrBase_1.ProviderNostrBase {
|
|
|
28
37
|
return result;
|
|
29
38
|
}),
|
|
30
39
|
};
|
|
40
|
+
this._registerEvents();
|
|
31
41
|
}
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
_registerEvents() {
|
|
43
|
+
window.addEventListener('onekey_bridge_disconnect', () => {
|
|
44
|
+
this._handleDisconnected();
|
|
45
|
+
});
|
|
46
|
+
this.on(PROVIDER_EVENTS.message_low_level, (payload) => {
|
|
47
|
+
const { method } = payload;
|
|
48
|
+
if (isWalletEventMethodMatch(method, PROVIDER_EVENTS.accountChanged)) {
|
|
49
|
+
this._handleAccountChange();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
34
52
|
}
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
throw new Error(message);
|
|
40
|
-
}
|
|
41
|
-
if (this.states.executing) {
|
|
42
|
-
const message = `window.webln call already executing`;
|
|
43
|
-
alert(message);
|
|
44
|
-
throw new Error(message);
|
|
53
|
+
_handleDisconnected(options = { emit: true }) {
|
|
54
|
+
if (options.emit && this.isConnectionStatusChanged('disconnected')) {
|
|
55
|
+
this.emit('disconnect');
|
|
56
|
+
this.emit('accountChanged');
|
|
45
57
|
}
|
|
46
58
|
}
|
|
59
|
+
_handleAccountChange() {
|
|
60
|
+
this.emit('accountChanged');
|
|
61
|
+
}
|
|
47
62
|
on(event, listener) {
|
|
48
63
|
return super.on(event, listener);
|
|
49
64
|
}
|
|
65
|
+
off(event, listener) {
|
|
66
|
+
return super.off(event, listener);
|
|
67
|
+
}
|
|
50
68
|
emit(event, ...args) {
|
|
51
69
|
return super.emit(event, ...args);
|
|
52
70
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ declare const PROVIDER_EVENTS: {
|
|
|
64
64
|
export declare type NostrProviderEventsMap = {
|
|
65
65
|
[PROVIDER_EVENTS.connect]: (account: string) => void;
|
|
66
66
|
[PROVIDER_EVENTS.disconnect]: () => void;
|
|
67
|
-
[PROVIDER_EVENTS.accountChanged]: (
|
|
67
|
+
[PROVIDER_EVENTS.accountChanged]: () => void;
|
|
68
68
|
[PROVIDER_EVENTS.message_low_level]: (payload: IJsonRpcRequest) => void;
|
|
69
69
|
};
|
|
70
70
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/onekey-nostr-provider",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.53",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"start": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@onekeyfe/cross-inpage-provider-core": "1.1.
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-errors": "1.1.
|
|
33
|
-
"@onekeyfe/cross-inpage-provider-types": "1.1.
|
|
34
|
-
"@onekeyfe/extension-bridge-injected": "1.1.
|
|
31
|
+
"@onekeyfe/cross-inpage-provider-core": "1.1.53",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-errors": "1.1.53",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-types": "1.1.53",
|
|
34
|
+
"@onekeyfe/extension-bridge-injected": "1.1.53"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "33ed7e15f71c3efd6e957765dde80d22085a91a3"
|
|
37
37
|
}
|