@multiversx/sdk-web-wallet-cross-window-provider 0.0.28-alpha.3 → 0.0.28-alpha.4
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/out/{types/CrossWindowProvider → CrossWindowProvider}/CrossWindowProvider.d.ts +5 -5
- package/out/CrossWindowProvider/CrossWindowProvider.js +75 -71
- package/out/CrossWindowProvider/CrossWindowProvider.js.map +1 -1
- package/out/{types/CrossWindowProvider → CrossWindowProvider}/WindowManager.d.ts +2 -2
- package/out/CrossWindowProvider/WindowManager.js +35 -31
- package/out/CrossWindowProvider/WindowManager.js.map +1 -1
- package/out/CrossWindowProvider/index.js +17 -1
- package/out/CrossWindowProvider/index.js.map +1 -1
- package/out/CrossWindowProvider/tests/Cancel.test.js +9 -7
- package/out/CrossWindowProvider/tests/Cancel.test.js.map +1 -1
- package/out/CrossWindowProvider/tests/Init.test.js +7 -5
- package/out/CrossWindowProvider/tests/Init.test.js.map +1 -1
- package/out/CrossWindowProvider/tests/Login.test.js +9 -7
- package/out/CrossWindowProvider/tests/Login.test.js.map +1 -1
- package/out/CrossWindowProvider/tests/Logout.test.js +10 -8
- package/out/CrossWindowProvider/tests/Logout.test.js.map +1 -1
- package/out/CrossWindowProvider/tests/SignMessage.test.js +11 -9
- package/out/CrossWindowProvider/tests/SignMessage.test.js.map +1 -1
- package/out/CrossWindowProvider/tests/SignTransaction.test.js +10 -8
- package/out/CrossWindowProvider/tests/SignTransaction.test.js.map +1 -1
- package/out/CrossWindowProvider/tests/windowManager.test.js +17 -15
- package/out/CrossWindowProvider/tests/windowManager.test.js.map +1 -1
- package/out/IframeProvider/IframeManager.js +7 -2
- package/out/IframeProvider/IframeManager.js.map +1 -1
- package/out/{types/IframeProvider → IframeProvider}/IframeProvider.d.ts +4 -4
- package/out/IframeProvider/IframeProvider.js +13 -4
- package/out/IframeProvider/IframeProvider.js.map +1 -1
- package/out/IframeProvider/index.js +17 -1
- package/out/IframeProvider/index.js.map +1 -1
- package/out/constants.js +14 -11
- package/out/constants.js.map +1 -1
- package/out/{types/errors.d.ts → errors.d.ts} +3 -0
- package/out/errors.js +30 -12
- package/out/errors.js.map +1 -1
- package/out/index.js +20 -4
- package/out/index.js.map +1 -1
- package/out/test-utils/createMockTransaction.js +11 -6
- package/out/test-utils/createMockTransaction.js.map +1 -1
- package/out/test-utils/getWalletWindowMock.js +5 -1
- package/out/test-utils/getWalletWindowMock.js.map +1 -1
- package/out/test-utils/index.js +19 -3
- package/out/test-utils/index.js.map +1 -1
- package/out/test-utils/mockWindowManager.js +6 -2
- package/out/test-utils/mockWindowManager.js.map +1 -1
- package/out/{types/types.d.ts → types.d.ts} +9 -0
- package/out/types.js +9 -6
- package/out/types.js.map +1 -1
- package/package.json +1 -1
- /package/out/{types/CrossWindowProvider → CrossWindowProvider}/index.d.ts +0 -0
- /package/out/{types/CrossWindowProvider → CrossWindowProvider}/tests/Cancel.test.d.ts +0 -0
- /package/out/{types/CrossWindowProvider → CrossWindowProvider}/tests/Init.test.d.ts +0 -0
- /package/out/{types/CrossWindowProvider → CrossWindowProvider}/tests/Login.test.d.ts +0 -0
- /package/out/{types/CrossWindowProvider → CrossWindowProvider}/tests/Logout.test.d.ts +0 -0
- /package/out/{types/CrossWindowProvider → CrossWindowProvider}/tests/SignMessage.test.d.ts +0 -0
- /package/out/{types/CrossWindowProvider → CrossWindowProvider}/tests/SignTransaction.test.d.ts +0 -0
- /package/out/{types/CrossWindowProvider → CrossWindowProvider}/tests/windowManager.test.d.ts +0 -0
- /package/out/{types/IframeProvider → IframeProvider}/IframeManager.d.ts +0 -0
- /package/out/{types/IframeProvider → IframeProvider}/index.d.ts +0 -0
- /package/out/{types/constants.d.ts → constants.d.ts} +0 -0
- /package/out/{types/index.d.ts → index.d.ts} +0 -0
- /package/out/{types/test-utils → test-utils}/createMockTransaction.d.ts +0 -0
- /package/out/{types/test-utils → test-utils}/getWalletWindowMock.d.ts +0 -0
- /package/out/{types/test-utils → test-utils}/index.d.ts +0 -0
- /package/out/{types/test-utils → test-utils}/mockWindowManager.d.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SignableMessage, Transaction } from
|
|
2
|
-
import { IframeManager } from
|
|
3
|
-
import { CrossWindowProviderRequestEnums } from
|
|
4
|
-
import { WindowManager } from
|
|
1
|
+
import { SignableMessage, Transaction } from "@multiversx/sdk-core";
|
|
2
|
+
import { IframeManager } from "../IframeProvider/IframeManager";
|
|
3
|
+
import { CrossWindowProviderRequestEnums } from "../types";
|
|
4
|
+
import { WindowManager } from "./WindowManager";
|
|
5
5
|
export interface ICrossWindowWalletAccount {
|
|
6
6
|
address: string;
|
|
7
7
|
signature?: string;
|
|
@@ -41,6 +41,6 @@ export declare class CrossWindowProvider {
|
|
|
41
41
|
}>;
|
|
42
42
|
guardTransactions(transactions: Transaction[]): Promise<Transaction[]>;
|
|
43
43
|
signMessage(message: SignableMessage): Promise<SignableMessage>;
|
|
44
|
-
cancelAction(): Promise<import("../types").PostMessageReturnType<CrossWindowProviderRequestEnums.cancelAction
|
|
44
|
+
cancelAction(): Promise<import("../types").PostMessageReturnType<CrossWindowProviderRequestEnums.cancelAction>> | undefined;
|
|
45
45
|
clearInstance(): void;
|
|
46
46
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,34 +8,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CrossWindowProvider = void 0;
|
|
13
|
+
const sdk_core_1 = require("@multiversx/sdk-core");
|
|
14
|
+
const loader_1 = require("@multiversx/sdk-dapp-ui/loader");
|
|
15
|
+
const errors_1 = require("../errors");
|
|
16
|
+
const types_1 = require("../types");
|
|
17
|
+
const WindowManager_1 = require("./WindowManager");
|
|
15
18
|
class CrossWindowProvider {
|
|
16
19
|
setShouldShowConsentPopup(shouldShow) {
|
|
17
20
|
this._shouldShowConsentPopup = shouldShow;
|
|
18
21
|
}
|
|
19
22
|
constructor() {
|
|
20
|
-
this.account = { address:
|
|
23
|
+
this.account = { address: "" };
|
|
21
24
|
this.initialized = false;
|
|
22
25
|
this.windowManager = null;
|
|
23
26
|
this.accessToken = undefined;
|
|
24
27
|
this._shouldShowConsentPopup = false;
|
|
25
28
|
if (CrossWindowProvider._instance) {
|
|
26
|
-
throw new ErrInstantiationFailed();
|
|
29
|
+
throw new errors_1.ErrInstantiationFailed();
|
|
27
30
|
}
|
|
28
|
-
defineCustomElements();
|
|
31
|
+
(0, loader_1.defineCustomElements)();
|
|
29
32
|
CrossWindowProvider._instance = this;
|
|
30
33
|
}
|
|
31
34
|
ensureConnected() {
|
|
32
35
|
if (!this.account.address) {
|
|
33
|
-
throw new ErrAccountNotConnected();
|
|
36
|
+
throw new errors_1.ErrAccountNotConnected();
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
disconnect() {
|
|
37
|
-
this.account = { address:
|
|
40
|
+
this.account = { address: "" };
|
|
38
41
|
}
|
|
39
42
|
static getInstance() {
|
|
40
43
|
if (!CrossWindowProvider._instance) {
|
|
@@ -44,21 +47,21 @@ class CrossWindowProvider {
|
|
|
44
47
|
}
|
|
45
48
|
setAddress(address) {
|
|
46
49
|
if (!CrossWindowProvider._instance) {
|
|
47
|
-
throw new ErrInstantiationFailed();
|
|
50
|
+
throw new errors_1.ErrInstantiationFailed();
|
|
48
51
|
}
|
|
49
52
|
this.account.address = address;
|
|
50
53
|
return CrossWindowProvider._instance;
|
|
51
54
|
}
|
|
52
55
|
setWalletUrl(url) {
|
|
53
56
|
if (!CrossWindowProvider._instance || !this.windowManager) {
|
|
54
|
-
throw new ErrInstantiationFailed();
|
|
57
|
+
throw new errors_1.ErrInstantiationFailed();
|
|
55
58
|
}
|
|
56
59
|
this.windowManager.setWalletUrl(url);
|
|
57
60
|
return CrossWindowProvider._instance;
|
|
58
61
|
}
|
|
59
62
|
init() {
|
|
60
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
this.windowManager = WindowManager.getInstance();
|
|
64
|
+
this.windowManager = WindowManager_1.WindowManager.getInstance();
|
|
62
65
|
this.initialized = yield this.windowManager.init();
|
|
63
66
|
return this.initialized;
|
|
64
67
|
});
|
|
@@ -66,7 +69,7 @@ class CrossWindowProvider {
|
|
|
66
69
|
login(options = {}) {
|
|
67
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
71
|
if (!this.initialized) {
|
|
69
|
-
throw new ErrProviderNotInitialized();
|
|
72
|
+
throw new errors_1.ErrProviderNotInitialized();
|
|
70
73
|
}
|
|
71
74
|
const isRelogin = yield this.isConnected();
|
|
72
75
|
if (isRelogin) {
|
|
@@ -75,27 +78,27 @@ class CrossWindowProvider {
|
|
|
75
78
|
address,
|
|
76
79
|
signature,
|
|
77
80
|
multisig,
|
|
78
|
-
impersonate
|
|
81
|
+
impersonate,
|
|
79
82
|
};
|
|
80
83
|
}
|
|
81
84
|
this.accessToken = options.token;
|
|
82
85
|
if (!this.windowManager) {
|
|
83
|
-
throw new ErrInstantiationFailed();
|
|
86
|
+
throw new errors_1.ErrInstantiationFailed();
|
|
84
87
|
}
|
|
85
|
-
const { popup, popupConsentResponse } = yield this.openPopupConsent(
|
|
88
|
+
const { popup, popupConsentResponse } = yield this.openPopupConsent("login");
|
|
86
89
|
if (!popupConsentResponse) {
|
|
87
90
|
popup === null || popup === void 0 ? void 0 : popup.remove();
|
|
88
|
-
throw new ErrCouldNotLogin();
|
|
91
|
+
throw new errors_1.ErrCouldNotLogin();
|
|
89
92
|
}
|
|
90
93
|
popup === null || popup === void 0 ? void 0 : popup.remove();
|
|
91
|
-
const { payload: { data, error } } = yield this.windowManager.postMessage({
|
|
92
|
-
type: CrossWindowProviderRequestEnums.loginRequest,
|
|
94
|
+
const { payload: { data, error }, } = yield this.windowManager.postMessage({
|
|
95
|
+
type: types_1.CrossWindowProviderRequestEnums.loginRequest,
|
|
93
96
|
payload: {
|
|
94
|
-
token: this.accessToken
|
|
95
|
-
}
|
|
97
|
+
token: this.accessToken,
|
|
98
|
+
},
|
|
96
99
|
});
|
|
97
100
|
if (error || !data) {
|
|
98
|
-
throw new ErrCouldNotLogin();
|
|
101
|
+
throw new errors_1.ErrCouldNotLogin();
|
|
99
102
|
}
|
|
100
103
|
this.account.address = data.address;
|
|
101
104
|
this.account.signature = data.signature;
|
|
@@ -105,19 +108,19 @@ class CrossWindowProvider {
|
|
|
105
108
|
address: this.account.address,
|
|
106
109
|
signature: this.account.signature,
|
|
107
110
|
multisig: this.account.multisig,
|
|
108
|
-
impersonate: this.account.impersonate
|
|
111
|
+
impersonate: this.account.impersonate,
|
|
109
112
|
};
|
|
110
113
|
});
|
|
111
114
|
}
|
|
112
115
|
logout() {
|
|
113
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
const { popup, popupConsentResponse } = yield this.openPopupConsent(
|
|
117
|
+
const { popup, popupConsentResponse } = yield this.openPopupConsent("logout");
|
|
115
118
|
if (!popupConsentResponse) {
|
|
116
119
|
popup === null || popup === void 0 ? void 0 : popup.remove();
|
|
117
120
|
}
|
|
118
121
|
popup === null || popup === void 0 ? void 0 : popup.remove();
|
|
119
122
|
if (!this.initialized || !this.windowManager) {
|
|
120
|
-
throw new ErrProviderNotInitialized();
|
|
123
|
+
throw new errors_1.ErrProviderNotInitialized();
|
|
121
124
|
}
|
|
122
125
|
this.ensureConnected();
|
|
123
126
|
const connectionClosed = yield this.windowManager.closeConnection();
|
|
@@ -130,9 +133,9 @@ class CrossWindowProvider {
|
|
|
130
133
|
var _a, _b;
|
|
131
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
135
|
if (!this.initialized) {
|
|
133
|
-
throw new ErrProviderNotInitialized();
|
|
136
|
+
throw new errors_1.ErrProviderNotInitialized();
|
|
134
137
|
}
|
|
135
|
-
return (_b = (_a = this.account) === null || _a === void 0 ? void 0 : _a.address) !== null && _b !== void 0 ? _b :
|
|
138
|
+
return (_b = (_a = this.account) === null || _a === void 0 ? void 0 : _a.address) !== null && _b !== void 0 ? _b : "";
|
|
136
139
|
});
|
|
137
140
|
}
|
|
138
141
|
isInitialized() {
|
|
@@ -148,7 +151,7 @@ class CrossWindowProvider {
|
|
|
148
151
|
this.ensureConnected();
|
|
149
152
|
const signedTransactions = yield this.signTransactions([transaction]);
|
|
150
153
|
if (signedTransactions.length != 1) {
|
|
151
|
-
throw new ErrCannotSignSingleTransaction();
|
|
154
|
+
throw new errors_1.ErrCannotSignSingleTransaction();
|
|
152
155
|
}
|
|
153
156
|
return signedTransactions[0];
|
|
154
157
|
});
|
|
@@ -156,43 +159,44 @@ class CrossWindowProvider {
|
|
|
156
159
|
signTransactions(transactions) {
|
|
157
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
161
|
this.ensureConnected();
|
|
159
|
-
const { popup, popupConsentResponse } = yield this.openPopupConsent(
|
|
162
|
+
const { popup, popupConsentResponse } = yield this.openPopupConsent("sign transactions");
|
|
160
163
|
if (!popupConsentResponse) {
|
|
161
164
|
popup === null || popup === void 0 ? void 0 : popup.remove();
|
|
162
|
-
throw new ErrTransactionCancelled();
|
|
165
|
+
throw new errors_1.ErrTransactionCancelled();
|
|
163
166
|
}
|
|
164
167
|
popup === null || popup === void 0 ? void 0 : popup.remove();
|
|
165
168
|
if (!this.windowManager) {
|
|
166
|
-
throw new ErrInstantiationFailed();
|
|
169
|
+
throw new errors_1.ErrInstantiationFailed();
|
|
167
170
|
}
|
|
168
|
-
const { type, payload: { data: signedPlainTransactions, error } } = yield this.windowManager.postMessage({
|
|
169
|
-
type: CrossWindowProviderRequestEnums.signTransactionsRequest,
|
|
170
|
-
payload: transactions.map((tx) => tx.toPlainObject())
|
|
171
|
+
const { type, payload: { data: signedPlainTransactions, error }, } = yield this.windowManager.postMessage({
|
|
172
|
+
type: types_1.CrossWindowProviderRequestEnums.signTransactionsRequest,
|
|
173
|
+
payload: transactions.map((tx) => tx.toPlainObject()),
|
|
171
174
|
});
|
|
172
175
|
if (error || !signedPlainTransactions) {
|
|
173
|
-
throw new ErrCouldNotSignTransactions();
|
|
176
|
+
throw new errors_1.ErrCouldNotSignTransactions();
|
|
174
177
|
}
|
|
175
|
-
if (type === CrossWindowProviderResponseEnums.cancelResponse) {
|
|
176
|
-
throw new ErrTransactionCancelled();
|
|
178
|
+
if (type === types_1.CrossWindowProviderResponseEnums.cancelResponse) {
|
|
179
|
+
throw new errors_1.ErrTransactionCancelled();
|
|
177
180
|
}
|
|
178
181
|
const hasTransactions = (signedPlainTransactions === null || signedPlainTransactions === void 0 ? void 0 : signedPlainTransactions.length) > 0;
|
|
179
182
|
if (!hasTransactions) {
|
|
180
|
-
throw new ErrCouldNotSignTransactions();
|
|
183
|
+
throw new errors_1.ErrCouldNotSignTransactions();
|
|
181
184
|
}
|
|
182
|
-
return signedPlainTransactions.map((tx) => Transaction.fromPlainObject(tx));
|
|
185
|
+
return signedPlainTransactions.map((tx) => sdk_core_1.Transaction.fromPlainObject(tx));
|
|
183
186
|
});
|
|
184
187
|
}
|
|
185
188
|
openPopupConsent(action) {
|
|
189
|
+
var _a;
|
|
186
190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
191
|
if (!this._shouldShowConsentPopup) {
|
|
188
192
|
return { popupConsentResponse: true };
|
|
189
193
|
}
|
|
190
|
-
const popup = document.createElement(
|
|
194
|
+
const popup = document.createElement("open-popup-notification");
|
|
191
195
|
popup.action = action;
|
|
192
|
-
popup.walletAddress = this.windowManager.walletUrl;
|
|
196
|
+
popup.walletAddress = ((_a = this.windowManager) === null || _a === void 0 ? void 0 : _a.walletUrl) || "";
|
|
193
197
|
document.body.appendChild(popup);
|
|
194
198
|
const popupConsentResponse = yield new Promise((resolve) => {
|
|
195
|
-
popup.addEventListener(
|
|
199
|
+
popup.addEventListener("popupConsent", (event) => {
|
|
196
200
|
resolve(event.detail);
|
|
197
201
|
});
|
|
198
202
|
});
|
|
@@ -203,70 +207,70 @@ class CrossWindowProvider {
|
|
|
203
207
|
guardTransactions(transactions) {
|
|
204
208
|
return __awaiter(this, void 0, void 0, function* () {
|
|
205
209
|
this.ensureConnected();
|
|
206
|
-
const { popup, popupConsentResponse } = yield this.openPopupConsent(
|
|
210
|
+
const { popup, popupConsentResponse } = yield this.openPopupConsent("sign transactions");
|
|
207
211
|
if (!popupConsentResponse) {
|
|
208
212
|
popup === null || popup === void 0 ? void 0 : popup.remove();
|
|
209
|
-
throw new ErrTransactionCancelled();
|
|
213
|
+
throw new errors_1.ErrTransactionCancelled();
|
|
210
214
|
}
|
|
211
215
|
popup === null || popup === void 0 ? void 0 : popup.remove();
|
|
212
216
|
if (!this.windowManager) {
|
|
213
|
-
throw new ErrInstantiationFailed();
|
|
217
|
+
throw new errors_1.ErrInstantiationFailed();
|
|
214
218
|
}
|
|
215
|
-
const { type, payload: { data: signedPlainTransactions, error } } = yield this.windowManager.postMessage({
|
|
216
|
-
type: CrossWindowProviderRequestEnums.guardTransactionsRequest,
|
|
217
|
-
payload: transactions.map((tx) => tx.toPlainObject())
|
|
219
|
+
const { type, payload: { data: signedPlainTransactions, error }, } = yield this.windowManager.postMessage({
|
|
220
|
+
type: types_1.CrossWindowProviderRequestEnums.guardTransactionsRequest,
|
|
221
|
+
payload: transactions.map((tx) => tx.toPlainObject()),
|
|
218
222
|
});
|
|
219
223
|
if (error || !signedPlainTransactions) {
|
|
220
|
-
throw new ErrCouldNotSignTransactions();
|
|
224
|
+
throw new errors_1.ErrCouldNotSignTransactions();
|
|
221
225
|
}
|
|
222
|
-
if (type === CrossWindowProviderResponseEnums.cancelResponse) {
|
|
223
|
-
throw new ErrTransactionCancelled();
|
|
226
|
+
if (type === types_1.CrossWindowProviderResponseEnums.cancelResponse) {
|
|
227
|
+
throw new errors_1.ErrTransactionCancelled();
|
|
224
228
|
}
|
|
225
229
|
const hasTransactions = (signedPlainTransactions === null || signedPlainTransactions === void 0 ? void 0 : signedPlainTransactions.length) > 0;
|
|
226
230
|
if (!hasTransactions) {
|
|
227
|
-
throw new ErrCouldNotGuardTransactions();
|
|
231
|
+
throw new errors_1.ErrCouldNotGuardTransactions();
|
|
228
232
|
}
|
|
229
|
-
return signedPlainTransactions.map((tx) => Transaction.fromPlainObject(tx));
|
|
233
|
+
return signedPlainTransactions.map((tx) => sdk_core_1.Transaction.fromPlainObject(tx));
|
|
230
234
|
});
|
|
231
235
|
}
|
|
232
236
|
signMessage(message) {
|
|
233
237
|
return __awaiter(this, void 0, void 0, function* () {
|
|
234
238
|
this.ensureConnected();
|
|
235
|
-
const { popup, popupConsentResponse } = yield this.openPopupConsent(
|
|
239
|
+
const { popup, popupConsentResponse } = yield this.openPopupConsent("sign message");
|
|
236
240
|
if (!popupConsentResponse) {
|
|
237
241
|
popup === null || popup === void 0 ? void 0 : popup.remove();
|
|
238
|
-
throw new ErrCouldNotSignMessage();
|
|
242
|
+
throw new errors_1.ErrCouldNotSignMessage();
|
|
239
243
|
}
|
|
240
244
|
popup === null || popup === void 0 ? void 0 : popup.remove();
|
|
241
245
|
if (!this.windowManager) {
|
|
242
|
-
throw new ErrInstantiationFailed();
|
|
246
|
+
throw new errors_1.ErrInstantiationFailed();
|
|
243
247
|
}
|
|
244
|
-
const { payload: { data, error } } = yield this.windowManager.postMessage({
|
|
245
|
-
type: CrossWindowProviderRequestEnums.signMessageRequest,
|
|
248
|
+
const { payload: { data, error }, } = yield this.windowManager.postMessage({
|
|
249
|
+
type: types_1.CrossWindowProviderRequestEnums.signMessageRequest,
|
|
246
250
|
payload: {
|
|
247
|
-
message: message.message.toString()
|
|
248
|
-
}
|
|
251
|
+
message: message.message.toString(),
|
|
252
|
+
},
|
|
249
253
|
});
|
|
250
254
|
if (error || !data) {
|
|
251
|
-
throw new ErrCouldNotSignMessage();
|
|
255
|
+
throw new errors_1.ErrCouldNotSignMessage();
|
|
252
256
|
}
|
|
253
257
|
const { status, signature } = data;
|
|
254
|
-
if (status !== SignMessageStatusEnum.signed) {
|
|
255
|
-
throw new ErrCouldNotSignMessage();
|
|
258
|
+
if (status !== types_1.SignMessageStatusEnum.signed) {
|
|
259
|
+
throw new errors_1.ErrCouldNotSignMessage();
|
|
256
260
|
}
|
|
257
|
-
message.applySignature(Buffer.from(String(signature),
|
|
261
|
+
message.applySignature(Buffer.from(String(signature), "hex"));
|
|
258
262
|
return message;
|
|
259
263
|
});
|
|
260
264
|
}
|
|
261
265
|
cancelAction() {
|
|
262
|
-
var _a;
|
|
263
|
-
const isWalletOpened = this.windowManager.isWalletOpened(CrossWindowProviderRequestEnums.cancelAction);
|
|
266
|
+
var _a, _b;
|
|
267
|
+
const isWalletOpened = (_a = this.windowManager) === null || _a === void 0 ? void 0 : _a.isWalletOpened(types_1.CrossWindowProviderRequestEnums.cancelAction);
|
|
264
268
|
if (!isWalletOpened) {
|
|
265
269
|
return;
|
|
266
270
|
}
|
|
267
|
-
return (
|
|
268
|
-
type: CrossWindowProviderRequestEnums.cancelAction,
|
|
269
|
-
payload: undefined
|
|
271
|
+
return (_b = this.windowManager) === null || _b === void 0 ? void 0 : _b.postMessage({
|
|
272
|
+
type: types_1.CrossWindowProviderRequestEnums.cancelAction,
|
|
273
|
+
payload: undefined,
|
|
270
274
|
});
|
|
271
275
|
}
|
|
272
276
|
clearInstance() {
|
|
@@ -276,5 +280,5 @@ class CrossWindowProvider {
|
|
|
276
280
|
}
|
|
277
281
|
}
|
|
278
282
|
CrossWindowProvider._instance = null;
|
|
279
|
-
|
|
283
|
+
exports.CrossWindowProvider = CrossWindowProvider;
|
|
280
284
|
//# sourceMappingURL=CrossWindowProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrossWindowProvider.js","sourceRoot":"","sources":["../../src/CrossWindowProvider/CrossWindowProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CrossWindowProvider.js","sourceRoot":"","sources":["../../src/CrossWindowProvider/CrossWindowProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAoE;AACpE,2DAAsE;AACtE,sCAUmB;AAEnB,oCAIkB;AAClB,mDAAgD;AAShD,MAAa,mBAAmB;IAQvB,yBAAyB,CAAC,UAAmB;QAClD,IAAI,CAAC,uBAAuB,GAAG,UAAU,CAAC;IAC5C,CAAC;IAED;QAXO,YAAO,GAA8B,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAClD,gBAAW,GAAG,KAAK,CAAC;QACpB,kBAAa,GAAyC,IAAI,CAAC;QAE7D,gBAAW,GAAuB,SAAS,CAAC;QAC1C,4BAAuB,GAAG,KAAK,CAAC;QAOxC,IAAI,mBAAmB,CAAC,SAAS,EAAE;YACjC,MAAM,IAAI,+BAAsB,EAAE,CAAC;SACpC;QACD,IAAA,6BAAoB,GAAE,CAAC;QACvB,mBAAmB,CAAC,SAAS,GAAG,IAAI,CAAC;IACvC,CAAC;IAEO,eAAe;QACrB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YACzB,MAAM,IAAI,+BAAsB,EAAE,CAAC;SACpC;IACH,CAAC;IAEO,UAAU;QAChB,IAAI,CAAC,OAAO,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACjC,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE;YAClC,OAAO,IAAI,mBAAmB,EAAE,CAAC;SAClC;QAED,OAAO,mBAAmB,CAAC,SAAS,CAAC;IACvC,CAAC;IAEM,UAAU,CAAC,OAAe;QAC/B,IAAI,CAAC,mBAAmB,C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AC,WAAW,CAAC;gBACvC,IAAI,EAAE,uCAA+B,CAAC,kBAAkB;gBACxD,OAAO,EAAE;oBACP,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE;iBACpC;aACF,CAAC,CAAC;YAEH,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE;gBAClB,MAAM,IAAI,+BAAsB,EAAE,CAAC;aACpC;YAED,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;YAEnC,IAAI,MAAM,KAAK,6BAAqB,CAAC,MAAM,EAAE;gBAC3C,MAAM,IAAI,+BAAsB,EAAE,CAAC;aACpC;YAED,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;YAE9D,OAAO,OAAO,CAAC;QACjB,CAAC;KAAA;IAED,YAAY;;QACV,MAAM,cAAc,GAAG,MAAA,IAAI,CAAC,aAAa,0CAAE,cAAc,CACvD,uCAA+B,CAAC,YAAY,CAC7C,CAAC;QACF,IAAI,CAAC,cAAc,EAAE;YACnB,OAAO;SACR;QACD,OAAO,MAAA,IAAI,CAAC,aAAa,0CAAE,WAAW,CAAC;YACrC,IAAI,EAAE,uCAA+B,CAAC,YAAY;YAClD,OAAO,EAAE,SAAS;SACnB,CAAC,CAAC;IACL,CAAC;IAEM,aAAa;;QAClB,mBAAmB,CAAC,SAAS,GAAG,IAAI,CAAC;QACrC,MAAA,IAAI,CAAC,aAAa,0CAAE,aAAa,EAAE,CAAC;IACtC,CAAC;;AA/TgB,6BAAS,GAA+B,IAAI,AAAnC,CAAoC;AAJnD,kDAAmB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CrossWindowProviderRequestEnums, CrossWindowProviderResponseEnums, PostMessageParamsType, PostMessageReturnType, ReplyWithPostMessagePayloadType } from
|
|
1
|
+
import { CrossWindowProviderRequestEnums, CrossWindowProviderResponseEnums, PostMessageParamsType, PostMessageReturnType, ReplyWithPostMessagePayloadType } from "../types";
|
|
2
2
|
export declare class WindowManager {
|
|
3
3
|
protected _walletUrl: string;
|
|
4
4
|
private initialized;
|
|
@@ -21,6 +21,6 @@ export declare class WindowManager {
|
|
|
21
21
|
}>;
|
|
22
22
|
closeConnection(): Promise<boolean>;
|
|
23
23
|
isInitialized(): boolean;
|
|
24
|
-
postMessage<T extends CrossWindowProviderRequestEnums>({ type, payload }: PostMessageParamsType<T>): Promise<PostMessageReturnType<T>>;
|
|
24
|
+
postMessage<T extends CrossWindowProviderRequestEnums>({ type, payload, }: PostMessageParamsType<T>): Promise<PostMessageReturnType<T>>;
|
|
25
25
|
clearInstance(): void;
|
|
26
26
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,20 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.WindowManager = void 0;
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
|
+
const errors_1 = require("../errors");
|
|
15
|
+
const types_1 = require("../types");
|
|
13
16
|
class WindowManager {
|
|
14
17
|
constructor() {
|
|
15
18
|
var _a, _b;
|
|
16
|
-
this._walletUrl =
|
|
19
|
+
this._walletUrl = "";
|
|
17
20
|
this.initialized = false;
|
|
18
21
|
this.walletWindow = null;
|
|
19
|
-
(_a = safeWindow.addEventListener) === null || _a === void 0 ? void 0 : _a.call(safeWindow,
|
|
22
|
+
(_a = constants_1.safeWindow.addEventListener) === null || _a === void 0 ? void 0 : _a.call(constants_1.safeWindow, "beforeunload", () => {
|
|
20
23
|
this.closeWalletWindow();
|
|
21
24
|
});
|
|
22
|
-
safeWindow.name = (_b = safeWindow.location) === null || _b === void 0 ? void 0 : _b.origin;
|
|
23
|
-
WindowManager._instance = this;
|
|
25
|
+
constants_1.safeWindow.name = (_b = constants_1.safeWindow.location) === null || _b === void 0 ? void 0 : _b.origin;
|
|
26
|
+
WindowManager._instance = this; // TODO: remove singleton
|
|
24
27
|
}
|
|
25
28
|
get walletUrl() {
|
|
26
29
|
return this._walletUrl;
|
|
@@ -45,7 +48,7 @@ class WindowManager {
|
|
|
45
48
|
var _a, _b;
|
|
46
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
50
|
this.walletWindow =
|
|
48
|
-
(_b = (_a = safeWindow.open) === null || _a === void 0 ? void 0 : _a.call(safeWindow, this._walletUrl, this._walletUrl)) !== null && _b !== void 0 ? _b : null;
|
|
51
|
+
(_b = (_a = constants_1.safeWindow.open) === null || _a === void 0 ? void 0 : _a.call(constants_1.safeWindow, this._walletUrl, this._walletUrl)) !== null && _b !== void 0 ? _b : null;
|
|
49
52
|
});
|
|
50
53
|
}
|
|
51
54
|
closeWalletWindow() {
|
|
@@ -56,7 +59,7 @@ class WindowManager {
|
|
|
56
59
|
this.walletWindow = null;
|
|
57
60
|
}
|
|
58
61
|
isWalletOpened(type) {
|
|
59
|
-
return (type === CrossWindowProviderRequestEnums.cancelAction &&
|
|
62
|
+
return (type === types_1.CrossWindowProviderRequestEnums.cancelAction &&
|
|
60
63
|
Boolean(this.walletWindow));
|
|
61
64
|
}
|
|
62
65
|
handshake(type) {
|
|
@@ -67,12 +70,12 @@ class WindowManager {
|
|
|
67
70
|
}
|
|
68
71
|
this.closeWalletWindow();
|
|
69
72
|
yield this.setWalletWindow();
|
|
70
|
-
const { payload: isWalletReady } = yield this.listenOnce(CrossWindowProviderResponseEnums.handshakeResponse);
|
|
73
|
+
const { payload: isWalletReady } = yield this.listenOnce(types_1.CrossWindowProviderResponseEnums.handshakeResponse);
|
|
71
74
|
if (!isWalletReady) {
|
|
72
|
-
throw new ErrCannotEstablishHandshake();
|
|
75
|
+
throw new errors_1.ErrCannotEstablishHandshake();
|
|
73
76
|
}
|
|
74
77
|
(_a = this.walletWindow) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
75
|
-
type: CrossWindowProviderRequestEnums.finalizeHandshakeRequest
|
|
78
|
+
type: types_1.CrossWindowProviderRequestEnums.finalizeHandshakeRequest,
|
|
76
79
|
}, this._walletUrl);
|
|
77
80
|
this.addHandshakeChangeListener();
|
|
78
81
|
return true;
|
|
@@ -91,43 +94,44 @@ class WindowManager {
|
|
|
91
94
|
return;
|
|
92
95
|
}
|
|
93
96
|
switch (type) {
|
|
94
|
-
case CrossWindowProviderResponseEnums.disconnectResponse:
|
|
95
|
-
case CrossWindowProviderResponseEnums.handshakeResponse:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
case types_1.CrossWindowProviderResponseEnums.disconnectResponse:
|
|
98
|
+
case types_1.CrossWindowProviderResponseEnums.handshakeResponse:
|
|
99
|
+
const payloadData = payload["data"];
|
|
100
|
+
if ((payloadData === true &&
|
|
101
|
+
type === types_1.CrossWindowProviderResponseEnums.disconnectResponse) ||
|
|
102
|
+
(payloadData === false &&
|
|
103
|
+
type === types_1.CrossWindowProviderResponseEnums.handshakeResponse)) {
|
|
100
104
|
this.closeWalletWindow();
|
|
101
105
|
this.onDisconnect();
|
|
102
|
-
(_a = safeWindow.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(safeWindow,
|
|
106
|
+
(_a = constants_1.safeWindow.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(constants_1.safeWindow, "message", eventHandler);
|
|
103
107
|
}
|
|
104
108
|
break;
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
111
|
catch (_b) { }
|
|
108
112
|
};
|
|
109
|
-
(_a = safeWindow.addEventListener) === null || _a === void 0 ? void 0 : _a.call(safeWindow,
|
|
113
|
+
(_a = constants_1.safeWindow.addEventListener) === null || _a === void 0 ? void 0 : _a.call(constants_1.safeWindow, "message", eventHandler);
|
|
110
114
|
});
|
|
111
115
|
}
|
|
112
116
|
listenOnce(action) {
|
|
113
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
118
|
if (!this.walletWindow) {
|
|
115
|
-
throw new ErrWalletWindowNotInstantiated();
|
|
119
|
+
throw new errors_1.ErrWalletWindowNotInstantiated();
|
|
116
120
|
}
|
|
117
121
|
return yield new Promise((resolve) => {
|
|
118
122
|
var _a;
|
|
119
123
|
const walletUrl = this._walletUrl;
|
|
120
|
-
(_a = safeWindow.addEventListener) === null || _a === void 0 ? void 0 : _a.call(safeWindow,
|
|
124
|
+
(_a = constants_1.safeWindow.addEventListener) === null || _a === void 0 ? void 0 : _a.call(constants_1.safeWindow, "message", function eventHandler(event) {
|
|
121
125
|
var _a;
|
|
122
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
127
|
const { type, payload } = event.data;
|
|
124
128
|
const isWalletEvent = event.origin === new URL(walletUrl).origin;
|
|
125
129
|
const isCurrentAction = action === type ||
|
|
126
|
-
type === CrossWindowProviderResponseEnums.cancelResponse;
|
|
130
|
+
type === types_1.CrossWindowProviderResponseEnums.cancelResponse;
|
|
127
131
|
if (!isCurrentAction || !isWalletEvent) {
|
|
128
132
|
return;
|
|
129
133
|
}
|
|
130
|
-
(_a = safeWindow.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(safeWindow,
|
|
134
|
+
(_a = constants_1.safeWindow.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(constants_1.safeWindow, "message", eventHandler);
|
|
131
135
|
resolve({ type, payload });
|
|
132
136
|
});
|
|
133
137
|
});
|
|
@@ -137,11 +141,11 @@ class WindowManager {
|
|
|
137
141
|
closeConnection() {
|
|
138
142
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
143
|
if (!this.initialized) {
|
|
140
|
-
throw new ErrProviderNotInitialized();
|
|
144
|
+
throw new errors_1.ErrProviderNotInitialized();
|
|
141
145
|
}
|
|
142
146
|
yield this.postMessage({
|
|
143
|
-
type: CrossWindowProviderRequestEnums.logoutRequest,
|
|
144
|
-
payload: undefined
|
|
147
|
+
type: types_1.CrossWindowProviderRequestEnums.logoutRequest,
|
|
148
|
+
payload: undefined,
|
|
145
149
|
});
|
|
146
150
|
return true;
|
|
147
151
|
});
|
|
@@ -149,15 +153,15 @@ class WindowManager {
|
|
|
149
153
|
isInitialized() {
|
|
150
154
|
return this.initialized;
|
|
151
155
|
}
|
|
152
|
-
postMessage({ type, payload }) {
|
|
156
|
+
postMessage({ type, payload, }) {
|
|
153
157
|
var _a;
|
|
154
158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
159
|
yield this.handshake(type);
|
|
156
160
|
(_a = this.walletWindow) === null || _a === void 0 ? void 0 : _a.postMessage({
|
|
157
161
|
type,
|
|
158
|
-
payload
|
|
162
|
+
payload,
|
|
159
163
|
}, this._walletUrl);
|
|
160
|
-
const data = yield this.listenOnce(responseTypeMap[type]);
|
|
164
|
+
const data = yield this.listenOnce(constants_1.responseTypeMap[type]);
|
|
161
165
|
this.closeWalletWindow();
|
|
162
166
|
return data;
|
|
163
167
|
});
|
|
@@ -167,5 +171,5 @@ class WindowManager {
|
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
173
|
WindowManager._instance = null;
|
|
170
|
-
|
|
174
|
+
exports.WindowManager = WindowManager;
|
|
171
175
|
//# sourceMappingURL=WindowManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WindowManager.js","sourceRoot":"","sources":["../../src/CrossWindowProvider/WindowManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WindowManager.js","sourceRoot":"","sources":["../../src/CrossWindowProvider/WindowManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA2D;AAC3D,sCA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EK,eAAe;;YACnB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;gBACrB,MAAM,IAAI,kCAAyB,EAAE,CAAC;aACvC;YAED,MAAM,IAAI,CAAC,WAAW,CAAC;gBACrB,IAAI,EAAE,uCAA+B,CAAC,aAAa;gBACnD,OAAO,EAAE,SAAS;aACnB,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;QACd,CAAC;KAAA;IAED,aAAa;QACX,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAEK,WAAW,CAA4C,EAC3D,IAAI,EACJ,OAAO,GACkB;;;YACzB,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAC3B,MAAA,IAAI,CAAC,YAAY,0CAAE,WAAW,CAC5B;gBACE,IAAI;gBACJ,OAAO;aACR,EACD,IAAI,CAAC,UAAU,CAChB,CAAC;YAEF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,2BAAe,CAAC,IAAI,CAAC,CAAC,CAAC;YAE1D,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAEzB,OAAO,IAAI,CAAC;;KACb;IAEM,aAAa;QAClB,aAAa,CAAC,SAAS,GAAG,IAAI,CAAC;IACjC,CAAC;;AApMgB,uBAAS,GAAyB,IAAI,AAA7B,CAA8B;AAH7C,sCAAa"}
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./CrossWindowProvider"), exports);
|
|
2
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/CrossWindowProvider/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/CrossWindowProvider/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC"}
|