@onekeyfe/onekey-webln-provider 1.1.32 → 1.1.34
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/ProviderWebln.d.ts +3 -3
- package/dist/ProviderWebln.js +90 -32
- package/dist/cjs/ProviderWebln.js +90 -32
- package/package.json +6 -6
package/dist/ProviderWebln.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { IInpageProviderConfig } from "@onekeyfe/cross-inpage-provider-core";
|
|
|
2
2
|
import { ProviderWeblnBase } from "./ProviderWeblnBase";
|
|
3
3
|
import { WeblnProviderEventsMap, GetInfoResponse, IProviderWebln, RequestInvoiceArgs, RequestInvoiceResponse } from "./types";
|
|
4
4
|
declare class ProviderWebln extends ProviderWeblnBase implements IProviderWebln {
|
|
5
|
-
|
|
6
|
-
isEnabled: boolean;
|
|
7
|
-
executing: boolean;
|
|
5
|
+
private states;
|
|
8
6
|
constructor(props: IInpageProviderConfig);
|
|
7
|
+
setExecuting(executing: boolean): void;
|
|
8
|
+
private checkEnabled;
|
|
9
9
|
on<E extends keyof WeblnProviderEventsMap>(event: E, listener: WeblnProviderEventsMap[E]): this;
|
|
10
10
|
emit<E extends keyof WeblnProviderEventsMap>(event: E, ...args: Parameters<WeblnProviderEventsMap[E]>): boolean;
|
|
11
11
|
private _callBridge;
|
package/dist/ProviderWebln.js
CHANGED
|
@@ -11,11 +11,27 @@ import { ProviderWeblnBase } from "./ProviderWeblnBase";
|
|
|
11
11
|
class ProviderWebln extends ProviderWeblnBase {
|
|
12
12
|
constructor(props) {
|
|
13
13
|
super(props);
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
this.states = {
|
|
15
|
+
enabled: false,
|
|
16
|
+
executing: false
|
|
17
|
+
};
|
|
17
18
|
this.handlerLnurl();
|
|
18
19
|
}
|
|
20
|
+
setExecuting(executing) {
|
|
21
|
+
this.states.executing = executing;
|
|
22
|
+
}
|
|
23
|
+
checkEnabled(method) {
|
|
24
|
+
if (!this.states.enabled) {
|
|
25
|
+
const message = `Please allow the connection request of webln before calling the ${method} method`;
|
|
26
|
+
alert(message);
|
|
27
|
+
throw new Error(message);
|
|
28
|
+
}
|
|
29
|
+
if (this.states.executing) {
|
|
30
|
+
const message = `window.webln call already executing`;
|
|
31
|
+
alert(message);
|
|
32
|
+
throw new Error(message);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
19
35
|
on(event, listener) {
|
|
20
36
|
return super.on(event, listener);
|
|
21
37
|
}
|
|
@@ -27,70 +43,112 @@ class ProviderWebln extends ProviderWeblnBase {
|
|
|
27
43
|
}
|
|
28
44
|
enable() {
|
|
29
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
-
if (this.enabled) {
|
|
46
|
+
if (this.states.enabled) {
|
|
31
47
|
return { enabled: true };
|
|
32
48
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
if (this.states.executing) {
|
|
50
|
+
const message = `window.webln call already executing`;
|
|
51
|
+
alert(message);
|
|
52
|
+
throw new Error(message);
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
this.setExecuting(true);
|
|
56
|
+
const result = yield this._callBridge({ method: "enable" });
|
|
57
|
+
if (typeof result.enabled === "boolean") {
|
|
58
|
+
this.states.enabled = true;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
this.setExecuting(false);
|
|
37
64
|
}
|
|
38
|
-
return result;
|
|
39
65
|
});
|
|
40
66
|
}
|
|
41
67
|
getInfo() {
|
|
42
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
|
|
44
|
-
|
|
69
|
+
this.checkEnabled('getInfo');
|
|
70
|
+
try {
|
|
71
|
+
this.setExecuting(true);
|
|
72
|
+
const response = yield this._callBridge({ method: "getInfo" });
|
|
73
|
+
return response;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
this.setExecuting(false);
|
|
45
77
|
}
|
|
46
|
-
return this._callBridge({ method: "getInfo" });
|
|
47
78
|
});
|
|
48
79
|
}
|
|
49
80
|
makeInvoice(args) {
|
|
50
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
|
|
52
|
-
|
|
82
|
+
this.checkEnabled('makeInvoice');
|
|
83
|
+
try {
|
|
84
|
+
this.setExecuting(true);
|
|
85
|
+
const response = yield this._callBridge({ method: "makeInvoice", params: args });
|
|
86
|
+
return response;
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
this.setExecuting(false);
|
|
53
90
|
}
|
|
54
|
-
return this._callBridge({ method: "makeInvoice", params: args });
|
|
55
91
|
});
|
|
56
92
|
}
|
|
57
93
|
sendPayment(paymentRequest) {
|
|
58
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
|
|
60
|
-
|
|
95
|
+
this.checkEnabled('sendPayment');
|
|
96
|
+
try {
|
|
97
|
+
this.setExecuting(true);
|
|
98
|
+
const response = yield this._callBridge({ method: "sendPayment", params: paymentRequest });
|
|
99
|
+
return response;
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
this.setExecuting(false);
|
|
61
103
|
}
|
|
62
|
-
return this._callBridge({ method: "sendPayment", params: paymentRequest });
|
|
63
104
|
});
|
|
64
105
|
}
|
|
65
106
|
signMessage(message) {
|
|
66
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
|
|
68
|
-
|
|
108
|
+
this.checkEnabled('signMessage');
|
|
109
|
+
try {
|
|
110
|
+
this.setExecuting(true);
|
|
111
|
+
const response = yield this._callBridge({ method: "signMessage", params: message });
|
|
112
|
+
return response;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
this.setExecuting(false);
|
|
69
116
|
}
|
|
70
|
-
return this._callBridge({ method: "signMessage", params: message });
|
|
71
117
|
});
|
|
72
118
|
}
|
|
73
119
|
verifyMessage(signature, message) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
this.checkEnabled('verifyMessage');
|
|
122
|
+
try {
|
|
123
|
+
this.setExecuting(true);
|
|
124
|
+
const response = yield this._callBridge({
|
|
125
|
+
method: "verifyMessage",
|
|
126
|
+
params: { signature, message },
|
|
127
|
+
});
|
|
128
|
+
return response;
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
this.setExecuting(false);
|
|
132
|
+
}
|
|
80
133
|
});
|
|
81
134
|
}
|
|
82
135
|
getBalance() {
|
|
83
|
-
if (!this.enabled) {
|
|
136
|
+
if (!this.states.enabled) {
|
|
84
137
|
throw new Error("Please allow the connection request of webln before calling the getBalance method");
|
|
85
138
|
}
|
|
86
139
|
return this._callBridge({ method: "getBalance", params: undefined });
|
|
87
140
|
}
|
|
88
141
|
lnurl(lnurlString) {
|
|
89
142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
|
|
91
|
-
|
|
143
|
+
this.checkEnabled('lnurl');
|
|
144
|
+
try {
|
|
145
|
+
this.setExecuting(true);
|
|
146
|
+
const response = yield this._callBridge({ method: "lnurl", params: lnurlString });
|
|
147
|
+
return response;
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
this.setExecuting(false);
|
|
92
151
|
}
|
|
93
|
-
return this._callBridge({ method: "lnurl", params: lnurlString });
|
|
94
152
|
});
|
|
95
153
|
}
|
|
96
154
|
handlerLnurl() {
|
|
@@ -145,7 +203,7 @@ class ProviderWebln extends ProviderWeblnBase {
|
|
|
145
203
|
return window.webln.sendPayment(paymentRequest);
|
|
146
204
|
}
|
|
147
205
|
});
|
|
148
|
-
});
|
|
206
|
+
}, { capture: true });
|
|
149
207
|
}
|
|
150
208
|
}
|
|
151
209
|
}
|
|
@@ -14,11 +14,27 @@ const ProviderWeblnBase_1 = require("./ProviderWeblnBase");
|
|
|
14
14
|
class ProviderWebln extends ProviderWeblnBase_1.ProviderWeblnBase {
|
|
15
15
|
constructor(props) {
|
|
16
16
|
super(props);
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
this.states = {
|
|
18
|
+
enabled: false,
|
|
19
|
+
executing: false
|
|
20
|
+
};
|
|
20
21
|
this.handlerLnurl();
|
|
21
22
|
}
|
|
23
|
+
setExecuting(executing) {
|
|
24
|
+
this.states.executing = executing;
|
|
25
|
+
}
|
|
26
|
+
checkEnabled(method) {
|
|
27
|
+
if (!this.states.enabled) {
|
|
28
|
+
const message = `Please allow the connection request of webln before calling the ${method} method`;
|
|
29
|
+
alert(message);
|
|
30
|
+
throw new Error(message);
|
|
31
|
+
}
|
|
32
|
+
if (this.states.executing) {
|
|
33
|
+
const message = `window.webln call already executing`;
|
|
34
|
+
alert(message);
|
|
35
|
+
throw new Error(message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
22
38
|
on(event, listener) {
|
|
23
39
|
return super.on(event, listener);
|
|
24
40
|
}
|
|
@@ -30,70 +46,112 @@ class ProviderWebln extends ProviderWeblnBase_1.ProviderWeblnBase {
|
|
|
30
46
|
}
|
|
31
47
|
enable() {
|
|
32
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
if (this.enabled) {
|
|
49
|
+
if (this.states.enabled) {
|
|
34
50
|
return { enabled: true };
|
|
35
51
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
if (this.states.executing) {
|
|
53
|
+
const message = `window.webln call already executing`;
|
|
54
|
+
alert(message);
|
|
55
|
+
throw new Error(message);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
this.setExecuting(true);
|
|
59
|
+
const result = yield this._callBridge({ method: "enable" });
|
|
60
|
+
if (typeof result.enabled === "boolean") {
|
|
61
|
+
this.states.enabled = true;
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
this.setExecuting(false);
|
|
40
67
|
}
|
|
41
|
-
return result;
|
|
42
68
|
});
|
|
43
69
|
}
|
|
44
70
|
getInfo() {
|
|
45
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
this.checkEnabled('getInfo');
|
|
73
|
+
try {
|
|
74
|
+
this.setExecuting(true);
|
|
75
|
+
const response = yield this._callBridge({ method: "getInfo" });
|
|
76
|
+
return response;
|
|
77
|
+
}
|
|
78
|
+
finally {
|
|
79
|
+
this.setExecuting(false);
|
|
48
80
|
}
|
|
49
|
-
return this._callBridge({ method: "getInfo" });
|
|
50
81
|
});
|
|
51
82
|
}
|
|
52
83
|
makeInvoice(args) {
|
|
53
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
|
|
55
|
-
|
|
85
|
+
this.checkEnabled('makeInvoice');
|
|
86
|
+
try {
|
|
87
|
+
this.setExecuting(true);
|
|
88
|
+
const response = yield this._callBridge({ method: "makeInvoice", params: args });
|
|
89
|
+
return response;
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
this.setExecuting(false);
|
|
56
93
|
}
|
|
57
|
-
return this._callBridge({ method: "makeInvoice", params: args });
|
|
58
94
|
});
|
|
59
95
|
}
|
|
60
96
|
sendPayment(paymentRequest) {
|
|
61
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
-
|
|
63
|
-
|
|
98
|
+
this.checkEnabled('sendPayment');
|
|
99
|
+
try {
|
|
100
|
+
this.setExecuting(true);
|
|
101
|
+
const response = yield this._callBridge({ method: "sendPayment", params: paymentRequest });
|
|
102
|
+
return response;
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
this.setExecuting(false);
|
|
64
106
|
}
|
|
65
|
-
return this._callBridge({ method: "sendPayment", params: paymentRequest });
|
|
66
107
|
});
|
|
67
108
|
}
|
|
68
109
|
signMessage(message) {
|
|
69
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
|
|
71
|
-
|
|
111
|
+
this.checkEnabled('signMessage');
|
|
112
|
+
try {
|
|
113
|
+
this.setExecuting(true);
|
|
114
|
+
const response = yield this._callBridge({ method: "signMessage", params: message });
|
|
115
|
+
return response;
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
this.setExecuting(false);
|
|
72
119
|
}
|
|
73
|
-
return this._callBridge({ method: "signMessage", params: message });
|
|
74
120
|
});
|
|
75
121
|
}
|
|
76
122
|
verifyMessage(signature, message) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
this.checkEnabled('verifyMessage');
|
|
125
|
+
try {
|
|
126
|
+
this.setExecuting(true);
|
|
127
|
+
const response = yield this._callBridge({
|
|
128
|
+
method: "verifyMessage",
|
|
129
|
+
params: { signature, message },
|
|
130
|
+
});
|
|
131
|
+
return response;
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
this.setExecuting(false);
|
|
135
|
+
}
|
|
83
136
|
});
|
|
84
137
|
}
|
|
85
138
|
getBalance() {
|
|
86
|
-
if (!this.enabled) {
|
|
139
|
+
if (!this.states.enabled) {
|
|
87
140
|
throw new Error("Please allow the connection request of webln before calling the getBalance method");
|
|
88
141
|
}
|
|
89
142
|
return this._callBridge({ method: "getBalance", params: undefined });
|
|
90
143
|
}
|
|
91
144
|
lnurl(lnurlString) {
|
|
92
145
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
|
|
94
|
-
|
|
146
|
+
this.checkEnabled('lnurl');
|
|
147
|
+
try {
|
|
148
|
+
this.setExecuting(true);
|
|
149
|
+
const response = yield this._callBridge({ method: "lnurl", params: lnurlString });
|
|
150
|
+
return response;
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
this.setExecuting(false);
|
|
95
154
|
}
|
|
96
|
-
return this._callBridge({ method: "lnurl", params: lnurlString });
|
|
97
155
|
});
|
|
98
156
|
}
|
|
99
157
|
handlerLnurl() {
|
|
@@ -148,7 +206,7 @@ class ProviderWebln extends ProviderWeblnBase_1.ProviderWeblnBase {
|
|
|
148
206
|
return window.webln.sendPayment(paymentRequest);
|
|
149
207
|
}
|
|
150
208
|
});
|
|
151
|
-
});
|
|
209
|
+
}, { capture: true });
|
|
152
210
|
}
|
|
153
211
|
}
|
|
154
212
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/onekey-webln-provider",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.34",
|
|
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.34",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-errors": "1.1.34",
|
|
33
|
+
"@onekeyfe/cross-inpage-provider-types": "1.1.34",
|
|
34
|
+
"@onekeyfe/extension-bridge-injected": "1.1.34"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "108e2c3664514eb40dedd5eca497cfd96a47cd82"
|
|
37
37
|
}
|