@mocanetwork/airkit 0.5.0 → 1.0.0
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/airkit.cjs.js +1921 -2597
- package/dist/airkit.esm.js +1925 -2413
- package/dist/airkit.umd.js +2104 -0
- package/dist/types/airService.d.ts +17 -12
- package/dist/types/airWalletProvider.d.ts +13 -0
- package/dist/types/common/air/error.d.ts +8 -0
- package/dist/types/common/custom.d.ts +6 -0
- package/dist/types/common/provider/error.d.ts +16 -0
- package/dist/types/common/provider/types.d.ts +24 -0
- package/dist/types/common/realm/error.d.ts +0 -0
- package/dist/types/common/realm/messaging/auth.d.ts +18 -21
- package/dist/types/common/realm/messaging/provider.d.ts +32 -0
- package/dist/types/common/realm/messaging/types.d.ts +52 -63
- package/dist/types/common/realm/partner/config.d.ts +1 -32
- package/dist/types/common/realm/smart-session/types.d.ts +1 -1
- package/dist/types/common/realm/user/types.d.ts +2 -31
- package/dist/types/common/types.d.ts +3 -0
- package/dist/types/common/utils.d.ts +17 -0
- package/dist/types/error.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/interfaces.d.ts +26 -187
- package/dist/types/messageService.d.ts +23 -31
- package/dist/types/utils.d.ts +3 -21
- package/package.json +7 -15
- package/dist/airkit.umd.min.js +0 -2
- package/dist/airkit.umd.min.js.LICENSE.txt +0 -12
- package/dist/lib.cjs/common/src/error.js +0 -25
- package/dist/lib.cjs/common/src/realm/messaging/auth.js +0 -28
- package/dist/lib.cjs/common/src/realm/messaging/types.js +0 -21
- package/dist/lib.cjs/ws-embed/src/PopupHandler.js +0 -64
- package/dist/lib.cjs/ws-embed/src/airService.js +0 -398
- package/dist/lib.cjs/ws-embed/src/baseProvider.js +0 -178
- package/dist/lib.cjs/ws-embed/src/communicationProvider.js +0 -346
- package/dist/lib.cjs/ws-embed/src/embed.js +0 -750
- package/dist/lib.cjs/ws-embed/src/error.js +0 -21
- package/dist/lib.cjs/ws-embed/src/iframeController.js +0 -68
- package/dist/lib.cjs/ws-embed/src/inPageProvider.js +0 -307
- package/dist/lib.cjs/ws-embed/src/index.js +0 -20
- package/dist/lib.cjs/ws-embed/src/interfaces.js +0 -29
- package/dist/lib.cjs/ws-embed/src/isStream.js +0 -20
- package/dist/lib.cjs/ws-embed/src/loglevel.js +0 -7
- package/dist/lib.cjs/ws-embed/src/messageService.js +0 -269
- package/dist/lib.cjs/ws-embed/src/messages.js +0 -22
- package/dist/lib.cjs/ws-embed/src/siteMetadata.js +0 -77
- package/dist/lib.cjs/ws-embed/src/utils.js +0 -95
- package/dist/lib.esm/common/src/error.js +0 -23
- package/dist/lib.esm/common/src/realm/messaging/auth.js +0 -26
- package/dist/lib.esm/common/src/realm/messaging/types.js +0 -19
- package/dist/lib.esm/ws-embed/src/PopupHandler.js +0 -62
- package/dist/lib.esm/ws-embed/src/airService.js +0 -396
- package/dist/lib.esm/ws-embed/src/baseProvider.js +0 -176
- package/dist/lib.esm/ws-embed/src/communicationProvider.js +0 -344
- package/dist/lib.esm/ws-embed/src/embed.js +0 -745
- package/dist/lib.esm/ws-embed/src/error.js +0 -18
- package/dist/lib.esm/ws-embed/src/iframeController.js +0 -66
- package/dist/lib.esm/ws-embed/src/inPageProvider.js +0 -302
- package/dist/lib.esm/ws-embed/src/index.js +0 -5
- package/dist/lib.esm/ws-embed/src/interfaces.js +0 -21
- package/dist/lib.esm/ws-embed/src/isStream.js +0 -15
- package/dist/lib.esm/ws-embed/src/loglevel.js +0 -5
- package/dist/lib.esm/ws-embed/src/messageService.js +0 -267
- package/dist/lib.esm/ws-embed/src/messages.js +0 -20
- package/dist/lib.esm/ws-embed/src/siteMetadata.js +0 -75
- package/dist/lib.esm/ws-embed/src/utils.js +0 -88
- package/dist/types/PopupHandler.d.ts +0 -24
- package/dist/types/baseProvider.d.ts +0 -66
- package/dist/types/communicationProvider.d.ts +0 -82
- package/dist/types/embed.d.ts +0 -55
- package/dist/types/inPageProvider.d.ts +0 -106
- package/dist/types/isStream.d.ts +0 -4
- package/dist/types/messages.d.ts +0 -19
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
-
var dequal = require('fast-deep-equal');
|
|
5
|
-
var rxjs = require('rxjs');
|
|
6
|
-
var auth = require('../../common/src/realm/messaging/auth.js');
|
|
7
|
-
var types = require('../../common/src/realm/messaging/types.js');
|
|
8
|
-
var error = require('./error.js');
|
|
9
|
-
var loglevel = require('./loglevel.js');
|
|
10
|
-
|
|
11
|
-
const REALM_EMBED_MESSAGES = [types.AirMessageTypes.LOGIN_CLAIM_STATE, types.AirMessageTypes.CLOSE_MODAL, types.AirMessageTypes.SERVICE_INITIALIZED, types.AirMessageTypes.SERVICE_INITIALIZED_ERROR, types.AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE, types.AirMessageTypes.EXECUTE_ACTION_RESPONSE, types.AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE, types.AirMessageTypes.GRANT_PERMISSIONS_RESPONSE];
|
|
12
|
-
const AUTH_EMBED_MESSAGES = [auth.AirAuthMessageTypes.LOGIN_RESPONSE, auth.AirAuthMessageTypes.USER_INFO_RESPONSE, auth.AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE, auth.AirAuthMessageTypes.REFRESH_TOKEN_RESPONSE, auth.AirAuthMessageTypes.INITIALIZATION_RESPONSE, auth.AirAuthMessageTypes.LOGOUT_RESPONSE, auth.AirAuthMessageTypes.IFRAME_VISIBILITY_REQUEST, auth.AirAuthMessageTypes.SETUP_WALLET_REQUEST];
|
|
13
|
-
class AirMessageService {
|
|
14
|
-
constructor() {
|
|
15
|
-
_defineProperty(this, "airMessages$", void 0);
|
|
16
|
-
_defineProperty(this, "_loginState$", void 0);
|
|
17
|
-
_defineProperty(this, "_authMessage$", void 0);
|
|
18
|
-
_defineProperty(this, "_authIframe", null);
|
|
19
|
-
_defineProperty(this, "closeAuthMessageListeners", null);
|
|
20
|
-
_defineProperty(this, "closeRealmMessageListeners", null);
|
|
21
|
-
}
|
|
22
|
-
static get instance() {
|
|
23
|
-
if (!AirMessageService._instance) {
|
|
24
|
-
AirMessageService._instance = new AirMessageService();
|
|
25
|
-
}
|
|
26
|
-
return AirMessageService._instance;
|
|
27
|
-
}
|
|
28
|
-
get messages$() {
|
|
29
|
-
return this.airMessages$.asObservable();
|
|
30
|
-
}
|
|
31
|
-
get loginState$() {
|
|
32
|
-
return this._loginState$;
|
|
33
|
-
}
|
|
34
|
-
get authMessage$() {
|
|
35
|
-
return this._authMessage$.asObservable();
|
|
36
|
-
}
|
|
37
|
-
async openAuthObservables({
|
|
38
|
-
authIframeOrigin
|
|
39
|
-
}) {
|
|
40
|
-
this.closeAuthObservables();
|
|
41
|
-
this.setupAuthObservables();
|
|
42
|
-
const handleAuthMessage = async ev => {
|
|
43
|
-
if (ev.origin !== authIframeOrigin || !ev.data || !(ev.data instanceof Object)) return;
|
|
44
|
-
loglevel.debug("Embed auth message received from auth", ev.data);
|
|
45
|
-
if (AUTH_EMBED_MESSAGES.includes(ev.data.type)) {
|
|
46
|
-
this._authMessage$.next(ev.data);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
window.addEventListener("message", handleAuthMessage);
|
|
50
|
-
this.closeAuthMessageListeners = () => {
|
|
51
|
-
window.removeEventListener("message", handleAuthMessage);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
async openRealmObservables({
|
|
55
|
-
walletIframeOrigin
|
|
56
|
-
}) {
|
|
57
|
-
this.closeRealmObservables();
|
|
58
|
-
this.setupRealmObservables();
|
|
59
|
-
const handleMessage = async ev => {
|
|
60
|
-
if (ev.origin !== walletIframeOrigin || !ev.data || !(ev.data instanceof Object)) return;
|
|
61
|
-
// filter out torus and communication provider messages
|
|
62
|
-
if ("target" in ev.data && (ev.data.target === "embed_torus" || ev.data.target === "embed_communication")) return;
|
|
63
|
-
loglevel.debug("Embed realm message received from wallet", ev.data);
|
|
64
|
-
if (REALM_EMBED_MESSAGES.includes(ev.data.type)) {
|
|
65
|
-
this.airMessages$.next(ev.data);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
window.addEventListener("message", handleMessage);
|
|
69
|
-
this.closeRealmMessageListeners = () => {
|
|
70
|
-
window.removeEventListener("message", handleMessage);
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Note: Only use when embed is needed in airAuth
|
|
75
|
-
setupAuthIframe(authIframe) {
|
|
76
|
-
this._authIframe = authIframe;
|
|
77
|
-
}
|
|
78
|
-
setupIframeCommunication(walletIframe) {
|
|
79
|
-
if (!this._authIframe) return;
|
|
80
|
-
const channel = new MessageChannel();
|
|
81
|
-
const authOrigin = new URL(this._authIframe.src).origin;
|
|
82
|
-
this._authIframe.contentWindow.postMessage({
|
|
83
|
-
type: auth.AirAuthMessageTypes.INIT_WALLET_COMMUNICATION
|
|
84
|
-
}, authOrigin, [channel.port1]);
|
|
85
|
-
const walletOrigin = new URL(walletIframe.src).origin;
|
|
86
|
-
walletIframe.contentWindow.postMessage({
|
|
87
|
-
type: types.AirMessageTypes.INIT_AUTH_COMMUNICATION
|
|
88
|
-
}, walletOrigin, [channel.port2]);
|
|
89
|
-
this._authIframe = undefined;
|
|
90
|
-
}
|
|
91
|
-
onInitialized() {
|
|
92
|
-
return rxjs.firstValueFrom(this.messages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.SERVICE_INITIALIZED)));
|
|
93
|
-
}
|
|
94
|
-
sendLoginRequest(walletIframe, payload) {
|
|
95
|
-
const response = rxjs.lastValueFrom(this.loginState$.pipe(rxjs.takeWhile(msg => (!payload.skipClaimFlow || msg.payload.state !== "connected") && msg.payload.state !== "logged_in" && msg.payload.state !== "claim_flow_cancelled", true), rxjs.tap(msg => {
|
|
96
|
-
switch (msg.payload.state) {
|
|
97
|
-
case "claim_flow_cancelled":
|
|
98
|
-
throw new error.RealmEmbedError(msg.payload.errorName, msg.payload.errorMessage);
|
|
99
|
-
}
|
|
100
|
-
})));
|
|
101
|
-
const {
|
|
102
|
-
origin
|
|
103
|
-
} = new URL(walletIframe.src);
|
|
104
|
-
walletIframe.contentWindow.postMessage({
|
|
105
|
-
type: types.AirMessageTypes.LOGIN_REQUEST,
|
|
106
|
-
payload
|
|
107
|
-
}, origin);
|
|
108
|
-
return response;
|
|
109
|
-
}
|
|
110
|
-
sendClaimRequest(walletIframe, options) {
|
|
111
|
-
const response = rxjs.lastValueFrom(rxjs.forkJoin([this.loginState$.pipe(rxjs.takeWhile(msg => !["logged_in", "claim_flow_cancelled"].includes(msg.payload.state), true), rxjs.tap(msg => {
|
|
112
|
-
if (msg.payload.state === "claim_flow_cancelled") {
|
|
113
|
-
throw new error.RealmEmbedError(msg.payload.errorName, msg.payload.errorMessage);
|
|
114
|
-
}
|
|
115
|
-
}), rxjs.last()), this.messages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.CLOSE_MODAL), rxjs.first())]));
|
|
116
|
-
const {
|
|
117
|
-
origin
|
|
118
|
-
} = new URL(walletIframe.src);
|
|
119
|
-
walletIframe.contentWindow.postMessage({
|
|
120
|
-
type: types.AirMessageTypes.CLAIM_REQUEST,
|
|
121
|
-
payload: {
|
|
122
|
-
token: options === null || options === void 0 ? void 0 : options.token,
|
|
123
|
-
claimInBackground: options === null || options === void 0 ? void 0 : options.background
|
|
124
|
-
}
|
|
125
|
-
}, origin);
|
|
126
|
-
return response;
|
|
127
|
-
}
|
|
128
|
-
async sendGrantPermissionRequest(walletIframe, policies) {
|
|
129
|
-
const response = rxjs.firstValueFrom(this.messages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.GRANT_PERMISSIONS_RESPONSE)));
|
|
130
|
-
const {
|
|
131
|
-
origin
|
|
132
|
-
} = new URL(walletIframe.src);
|
|
133
|
-
walletIframe.contentWindow.postMessage({
|
|
134
|
-
type: types.AirMessageTypes.GRANT_PERMISSIONS_REQUEST,
|
|
135
|
-
payload: {
|
|
136
|
-
policies
|
|
137
|
-
}
|
|
138
|
-
}, origin);
|
|
139
|
-
const result = await response;
|
|
140
|
-
if (result.payload.success === false) {
|
|
141
|
-
throw new error.RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
142
|
-
}
|
|
143
|
-
return result.payload.sessionData;
|
|
144
|
-
}
|
|
145
|
-
async sendExecuteActionRequest(walletIframe, params) {
|
|
146
|
-
const response = rxjs.firstValueFrom(this.messages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.EXECUTE_ACTION_RESPONSE)));
|
|
147
|
-
const {
|
|
148
|
-
origin
|
|
149
|
-
} = new URL(walletIframe.src);
|
|
150
|
-
walletIframe.contentWindow.postMessage({
|
|
151
|
-
type: types.AirMessageTypes.EXECUTE_ACTION_REQUEST,
|
|
152
|
-
payload: {
|
|
153
|
-
sessionData: params.sessionData,
|
|
154
|
-
call: {
|
|
155
|
-
to: params.call.to,
|
|
156
|
-
value: params.call.value,
|
|
157
|
-
data: params.call.data
|
|
158
|
-
},
|
|
159
|
-
sessionOwnerPrivateKey: params.sessionOwnerPrivateKey
|
|
160
|
-
}
|
|
161
|
-
}, origin);
|
|
162
|
-
const result = await response;
|
|
163
|
-
if (result.payload.success === false) {
|
|
164
|
-
throw new error.RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
165
|
-
}
|
|
166
|
-
return result.payload.txHash;
|
|
167
|
-
}
|
|
168
|
-
async sendRevokePermissionsRequest(walletIframe, permissionId) {
|
|
169
|
-
const response = rxjs.firstValueFrom(this.messages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.REVOKE_PERMISSIONS_RESPONSE)));
|
|
170
|
-
const {
|
|
171
|
-
origin
|
|
172
|
-
} = new URL(walletIframe.src);
|
|
173
|
-
walletIframe.contentWindow.postMessage({
|
|
174
|
-
type: types.AirMessageTypes.REVOKE_PERMISSIONS_REQUEST,
|
|
175
|
-
payload: {
|
|
176
|
-
permissionId
|
|
177
|
-
}
|
|
178
|
-
}, origin);
|
|
179
|
-
const result = await response;
|
|
180
|
-
if (result.payload.success === false) {
|
|
181
|
-
throw new error.RealmEmbedError(result.payload.errorName, result.payload.errorMessage);
|
|
182
|
-
}
|
|
183
|
-
return result.payload.txHash;
|
|
184
|
-
}
|
|
185
|
-
sendDeploySmartAccountRequest(walletIframe) {
|
|
186
|
-
const response = rxjs.firstValueFrom(this.messages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.DEPLOY_SMART_ACCOUNT_RESPONSE)));
|
|
187
|
-
const {
|
|
188
|
-
origin
|
|
189
|
-
} = new URL(walletIframe.src);
|
|
190
|
-
walletIframe.contentWindow.postMessage({
|
|
191
|
-
type: types.AirMessageTypes.DEPLOY_SMART_ACCOUNT_REQUEST
|
|
192
|
-
}, origin);
|
|
193
|
-
return response;
|
|
194
|
-
}
|
|
195
|
-
async sendUserInfoRequest(authIframe) {
|
|
196
|
-
const response = rxjs.firstValueFrom(this.authMessage$.pipe(rxjs.filter(msg => msg.type === auth.AirAuthMessageTypes.USER_INFO_RESPONSE)));
|
|
197
|
-
const {
|
|
198
|
-
origin
|
|
199
|
-
} = new URL(authIframe.src);
|
|
200
|
-
authIframe.contentWindow.postMessage({
|
|
201
|
-
type: auth.AirAuthMessageTypes.USER_INFO_REQUEST
|
|
202
|
-
}, origin);
|
|
203
|
-
return response;
|
|
204
|
-
}
|
|
205
|
-
async sendPartnerUserInfoRequest(authIframe) {
|
|
206
|
-
const response = rxjs.firstValueFrom(this.authMessage$.pipe(rxjs.filter(msg => msg.type === auth.AirAuthMessageTypes.PARTNER_USER_INFO_RESPONSE)));
|
|
207
|
-
const {
|
|
208
|
-
origin
|
|
209
|
-
} = new URL(authIframe.src);
|
|
210
|
-
authIframe.contentWindow.postMessage({
|
|
211
|
-
type: auth.AirAuthMessageTypes.PARTNER_USER_INFO_REQUEST
|
|
212
|
-
}, origin);
|
|
213
|
-
return response;
|
|
214
|
-
}
|
|
215
|
-
async sendAuthLoginRequest(authIframe, payload) {
|
|
216
|
-
const response = rxjs.firstValueFrom(this.authMessage$.pipe(rxjs.filter(msg => msg.type === auth.AirAuthMessageTypes.LOGIN_RESPONSE)));
|
|
217
|
-
const {
|
|
218
|
-
origin
|
|
219
|
-
} = new URL(authIframe.src);
|
|
220
|
-
authIframe.contentWindow.postMessage({
|
|
221
|
-
type: auth.AirAuthMessageTypes.LOGIN_REQUEST,
|
|
222
|
-
payload
|
|
223
|
-
}, origin);
|
|
224
|
-
return response;
|
|
225
|
-
}
|
|
226
|
-
async logoutAuth(authIframe) {
|
|
227
|
-
const response = rxjs.firstValueFrom(this.authMessage$.pipe(rxjs.filter(msg => msg.type === auth.AirAuthMessageTypes.LOGOUT_RESPONSE)));
|
|
228
|
-
const {
|
|
229
|
-
origin
|
|
230
|
-
} = new URL(authIframe.src);
|
|
231
|
-
authIframe.contentWindow.postMessage({
|
|
232
|
-
type: auth.AirAuthMessageTypes.LOGOUT_REQUEST
|
|
233
|
-
}, origin);
|
|
234
|
-
return response;
|
|
235
|
-
}
|
|
236
|
-
async waitForAuthInitialization() {
|
|
237
|
-
const response = await rxjs.firstValueFrom(this._authMessage$.pipe(rxjs.filter(msg => msg.type === auth.AirAuthMessageTypes.INITIALIZATION_RESPONSE)));
|
|
238
|
-
if (response.payload.success === false) {
|
|
239
|
-
throw new error.RealmEmbedError(response.payload.errorName, response.payload.errorMessage);
|
|
240
|
-
}
|
|
241
|
-
return response.payload;
|
|
242
|
-
}
|
|
243
|
-
async waitForWalletInitialization() {
|
|
244
|
-
const response = await rxjs.firstValueFrom(this.messages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.SERVICE_INITIALIZED || msg.type === types.AirMessageTypes.SERVICE_INITIALIZED_ERROR)));
|
|
245
|
-
if (response.type === types.AirMessageTypes.SERVICE_INITIALIZED_ERROR) {
|
|
246
|
-
throw new error.RealmEmbedError(response.payload.errorName, response.payload.errorMessage);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
closeAuthObservables() {
|
|
250
|
-
if (this._authMessage$ && !this._authMessage$.closed) this._authMessage$.complete();
|
|
251
|
-
if (this.closeAuthMessageListeners) this.closeAuthMessageListeners();
|
|
252
|
-
}
|
|
253
|
-
closeRealmObservables() {
|
|
254
|
-
if (this.airMessages$ && !this.airMessages$.closed) this.airMessages$.complete();
|
|
255
|
-
if (this.closeRealmMessageListeners) this.closeRealmMessageListeners();
|
|
256
|
-
}
|
|
257
|
-
setupAuthObservables() {
|
|
258
|
-
this._authMessage$ = new rxjs.Subject();
|
|
259
|
-
}
|
|
260
|
-
setupRealmObservables() {
|
|
261
|
-
this.airMessages$ = new rxjs.Subject();
|
|
262
|
-
this._loginState$ = this.airMessages$.pipe(rxjs.filter(msg => msg.type === types.AirMessageTypes.LOGIN_CLAIM_STATE), rxjs.distinctUntilChanged(dequal));
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
// eslint-disable-next-line no-use-before-define
|
|
266
|
-
_defineProperty(AirMessageService, "_instance", void 0);
|
|
267
|
-
var AirMessageService$1 = AirMessageService.instance;
|
|
268
|
-
|
|
269
|
-
module.exports = AirMessageService$1;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var messages = {
|
|
4
|
-
errors: {
|
|
5
|
-
disconnected: () => "Web3Auth: Lost connection to Web3Auth.",
|
|
6
|
-
permanentlyDisconnected: () => "Web3Auth: Disconnected from iframe. Page reload required.",
|
|
7
|
-
unsupportedSync: method => `Web3Auth: The Web3Auth Ethereum provider does not support synchronous methods like ${method} without a callback parameter.`,
|
|
8
|
-
invalidDuplexStream: () => "Must provide a Node.js-style duplex stream.",
|
|
9
|
-
invalidOptions: maxEventListeners => `Invalid options. Received: { maxEventListeners: ${maxEventListeners}}`,
|
|
10
|
-
invalidRequestArgs: () => `Expected a single, non-array, object argument.`,
|
|
11
|
-
invalidRequestMethod: () => `'args.method' must be a non-empty string.`,
|
|
12
|
-
invalidRequestParams: () => `'args.params' must be an object or array if provided.`,
|
|
13
|
-
invalidLoggerObject: () => `'args.logger' must be an object if provided.`,
|
|
14
|
-
invalidLoggerMethod: method => `'args.logger' must include required method '${method}'.`
|
|
15
|
-
},
|
|
16
|
-
info: {
|
|
17
|
-
connected: chainId => `Web3Auth: Connected to chain with ID "${chainId}".`
|
|
18
|
-
},
|
|
19
|
-
warnings: {}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
module.exports = messages;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns whether the given image URL exists
|
|
5
|
-
* @param url - the url of the image
|
|
6
|
-
* @returns whether the image exists
|
|
7
|
-
*/
|
|
8
|
-
function imgExists(url) {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
try {
|
|
11
|
-
const img = document.createElement("img");
|
|
12
|
-
img.onload = () => resolve(true);
|
|
13
|
-
img.onerror = () => resolve(false);
|
|
14
|
-
img.src = url;
|
|
15
|
-
} catch (e) {
|
|
16
|
-
reject(e);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Extracts a name for the site from the DOM
|
|
23
|
-
*/
|
|
24
|
-
const getSiteName = window => {
|
|
25
|
-
const {
|
|
26
|
-
document
|
|
27
|
-
} = window;
|
|
28
|
-
const siteName = document.querySelector('head > meta[property="og:site_name"]');
|
|
29
|
-
if (siteName) {
|
|
30
|
-
return siteName.content;
|
|
31
|
-
}
|
|
32
|
-
const metaTitle = document.querySelector('head > meta[name="title"]');
|
|
33
|
-
if (metaTitle) {
|
|
34
|
-
return metaTitle.content;
|
|
35
|
-
}
|
|
36
|
-
if (document.title && document.title.length > 0) {
|
|
37
|
-
return document.title;
|
|
38
|
-
}
|
|
39
|
-
return window.location.hostname;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Extracts an icon for the site from the DOM
|
|
44
|
-
*/
|
|
45
|
-
async function getSiteIcon(window) {
|
|
46
|
-
try {
|
|
47
|
-
const {
|
|
48
|
-
document
|
|
49
|
-
} = window;
|
|
50
|
-
|
|
51
|
-
// Use the site's favicon if it exists
|
|
52
|
-
let icon = document.querySelector('head > link[rel="shortcut icon"]');
|
|
53
|
-
if (icon && (await imgExists(icon.href))) {
|
|
54
|
-
return icon.href;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Search through available icons in no particular order
|
|
58
|
-
icon = Array.from(document.querySelectorAll('head > link[rel="icon"]')).find(_icon => Boolean(_icon.href));
|
|
59
|
-
if (icon && (await imgExists(icon.href))) {
|
|
60
|
-
return icon.href;
|
|
61
|
-
}
|
|
62
|
-
return "";
|
|
63
|
-
} catch (error) {
|
|
64
|
-
return "";
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Gets site metadata and returns it
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
72
|
-
const getSiteMetadata = async () => ({
|
|
73
|
-
name: getSiteName(window),
|
|
74
|
-
icon: await getSiteIcon(window)
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
module.exports = getSiteMetadata;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
4
|
-
var auth = require('@web3auth/auth');
|
|
5
|
-
var interfaces = require('./interfaces.js');
|
|
6
|
-
var loglevel = require('./loglevel.js');
|
|
7
|
-
|
|
8
|
-
const AIR_URLS = {
|
|
9
|
-
[interfaces.EMBED_BUILD_ENV.TESTING]: {
|
|
10
|
-
authUrl: "http://localhost:8100",
|
|
11
|
-
walletUrl: "https://lrc-mocaverse.web3auth.io",
|
|
12
|
-
logLevel: "debug"
|
|
13
|
-
},
|
|
14
|
-
[interfaces.EMBED_BUILD_ENV.DEVELOPMENT]: {
|
|
15
|
-
authUrl: "http://localhost:8100",
|
|
16
|
-
walletUrl: "https://localhost:4050",
|
|
17
|
-
logLevel: "debug"
|
|
18
|
-
},
|
|
19
|
-
[interfaces.EMBED_BUILD_ENV.STAGING]: {
|
|
20
|
-
authUrl: "https://auth.staging.air3.com",
|
|
21
|
-
walletUrl: "https://account.staging.realmnetwork.io",
|
|
22
|
-
logLevel: "info"
|
|
23
|
-
},
|
|
24
|
-
[interfaces.EMBED_BUILD_ENV.PRODUCTION]: {
|
|
25
|
-
authUrl: "https://auth.air3.com",
|
|
26
|
-
walletUrl: "https://account.realmnetwork.io",
|
|
27
|
-
logLevel: "error"
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const htmlToElement = html => {
|
|
31
|
-
const template = window.document.createElement("template");
|
|
32
|
-
const trimmedHtml = html.trim(); // Never return a text node of whitespace as the result
|
|
33
|
-
template.innerHTML = trimmedHtml;
|
|
34
|
-
return template.content.firstChild;
|
|
35
|
-
};
|
|
36
|
-
const isElement = element => element instanceof Element || element instanceof Document;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* json-rpc-engine middleware that logs RPC errors and and validates req.method.
|
|
40
|
-
*
|
|
41
|
-
* @param log - The logging API to use.
|
|
42
|
-
* @returns json-rpc-engine middleware function
|
|
43
|
-
*/
|
|
44
|
-
function createErrorMiddleware() {
|
|
45
|
-
return (req, res, next) => {
|
|
46
|
-
// json-rpc-engine will terminate the request when it notices this error
|
|
47
|
-
if (typeof req.method !== "string" || !req.method) {
|
|
48
|
-
res.error = auth.rpcErrors.invalidRequest({
|
|
49
|
-
message: `The request 'method' must be a non-empty string.`,
|
|
50
|
-
data: _objectSpread(_objectSpread({}, req || {}), {}, {
|
|
51
|
-
cause: `The request 'method' must be a non-empty string.`
|
|
52
|
-
})
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
next(done => {
|
|
56
|
-
const {
|
|
57
|
-
error
|
|
58
|
-
} = res;
|
|
59
|
-
if (!error) {
|
|
60
|
-
return done();
|
|
61
|
-
}
|
|
62
|
-
loglevel.error(`Ws-Embed - RPC Error: ${error.message}`, error);
|
|
63
|
-
return done();
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Logs a stream disconnection error. Emits an 'error' if given an
|
|
70
|
-
* EventEmitter that has listeners for the 'error' event.
|
|
71
|
-
*
|
|
72
|
-
* @param log - The logging API to use.
|
|
73
|
-
* @param remoteLabel - The label of the disconnected stream.
|
|
74
|
-
* @param error - The associated error to log.
|
|
75
|
-
* @param emitter - The logging API to use.
|
|
76
|
-
*/
|
|
77
|
-
function logStreamDisconnectWarning(remoteLabel, error, emitter) {
|
|
78
|
-
let warningMsg = `Web3Auth: Lost connection to "${remoteLabel}".`;
|
|
79
|
-
if (error !== null && error !== void 0 && error.stack) {
|
|
80
|
-
warningMsg += `\n${error.stack}`;
|
|
81
|
-
}
|
|
82
|
-
loglevel.warn(warningMsg);
|
|
83
|
-
if (emitter && emitter.listenerCount("error") > 0) {
|
|
84
|
-
emitter.emit("error", warningMsg);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
const EMITTED_NOTIFICATIONS = ["eth_subscription" // per eth-json-rpc-filters/subscriptionManager
|
|
88
|
-
];
|
|
89
|
-
|
|
90
|
-
exports.AIR_URLS = AIR_URLS;
|
|
91
|
-
exports.EMITTED_NOTIFICATIONS = EMITTED_NOTIFICATIONS;
|
|
92
|
-
exports.createErrorMiddleware = createErrorMiddleware;
|
|
93
|
-
exports.htmlToElement = htmlToElement;
|
|
94
|
-
exports.isElement = isElement;
|
|
95
|
-
exports.logStreamDisconnectWarning = logStreamDisconnectWarning;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
class BaseError extends Error {
|
|
2
|
-
constructor(name, message, options = {}) {
|
|
3
|
-
const {
|
|
4
|
-
cause,
|
|
5
|
-
context
|
|
6
|
-
} = options;
|
|
7
|
-
super(message || name);
|
|
8
|
-
this.name = name;
|
|
9
|
-
this.stack = cause === null || cause === void 0 ? void 0 : cause.stack;
|
|
10
|
-
this.cause = cause;
|
|
11
|
-
this.context = context;
|
|
12
|
-
}
|
|
13
|
-
toJSON() {
|
|
14
|
-
return {
|
|
15
|
-
name: this.name,
|
|
16
|
-
message: this.message,
|
|
17
|
-
context: this.context,
|
|
18
|
-
cause: this.cause
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { BaseError };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const AirAuthMessageTypes = {
|
|
2
|
-
SETUP_COMPLETED: "air_auth_setup_completed",
|
|
3
|
-
LOGIN_REQUEST: "air_auth_login_request",
|
|
4
|
-
LOGIN_RESPONSE: "air_auth_login_response",
|
|
5
|
-
LOGIN_WALLET_RESPONSE: "air_auth_login_wallet_response",
|
|
6
|
-
USER_INFO_REQUEST: "air_auth_user_info_request",
|
|
7
|
-
USER_INFO_RESPONSE: "air_auth_user_info_response",
|
|
8
|
-
PARTNER_USER_INFO_REQUEST: "air_auth_partner_user_info_request",
|
|
9
|
-
PARTNER_USER_INFO_RESPONSE: "air_auth_partner_user_info_response",
|
|
10
|
-
REFRESH_TOKEN_REQUEST: "air_auth_refresh_token_request",
|
|
11
|
-
REFRESH_TOKEN_RESPONSE: "air_auth_refresh_token_response",
|
|
12
|
-
WALLET_TOKEN_REQUEST: "air_auth_wallet_token_request",
|
|
13
|
-
WALLET_TOKEN_RESPONSE: "air_auth_wallet_token_response",
|
|
14
|
-
INITIALIZATION_REQUEST: "air_auth_initialization_request",
|
|
15
|
-
INITIALIZATION_RESPONSE: "air_auth_initialization_response",
|
|
16
|
-
INIT_WALLET_COMMUNICATION: "air_auth_init_wallet_communication",
|
|
17
|
-
IFRAME_VISIBILITY_REQUEST: "air_auth_iframe_visibility_request",
|
|
18
|
-
SETUP_WALLET_REQUEST: "air_auth_setup_wallet_request",
|
|
19
|
-
SETUP_WALLET_RESPONSE: "air_auth_setup_wallet_response",
|
|
20
|
-
SIGN_SIWE_MESSAGE_REQUEST: "air_auth_sign_siwe_message_request",
|
|
21
|
-
SIGN_SIWE_MESSAGE_RESPONSE: "air_auth_sign_siwe_message_response",
|
|
22
|
-
LOGOUT_REQUEST: "air_auth_logout_request",
|
|
23
|
-
LOGOUT_RESPONSE: "air_auth_logout_response"
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export { AirAuthMessageTypes };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const AirMessageTypes = {
|
|
2
|
-
SERVICE_INITIALIZED: "air_service_initialized",
|
|
3
|
-
SERVICE_INITIALIZED_ERROR: "air_service_initialized_error",
|
|
4
|
-
LOGIN_REQUEST: "air_login_request",
|
|
5
|
-
CLAIM_REQUEST: "air_claim_request",
|
|
6
|
-
LOGIN_CLAIM_STATE: "air_login_claim_state",
|
|
7
|
-
CLOSE_MODAL: "air_close_modal",
|
|
8
|
-
INIT_AUTH_COMMUNICATION: "air_init_auth_communication",
|
|
9
|
-
DEPLOY_SMART_ACCOUNT_REQUEST: "air_deploy_smart_account_request",
|
|
10
|
-
DEPLOY_SMART_ACCOUNT_RESPONSE: "air_deploy_smart_account_response",
|
|
11
|
-
GRANT_PERMISSIONS_REQUEST: "air_grant_permissions_request",
|
|
12
|
-
GRANT_PERMISSIONS_RESPONSE: "air_grant_permissions_response",
|
|
13
|
-
EXECUTE_ACTION_REQUEST: "air_execute_action_request",
|
|
14
|
-
EXECUTE_ACTION_RESPONSE: "air_execute_action_response",
|
|
15
|
-
REVOKE_PERMISSIONS_REQUEST: "air_revoke_permissions_request",
|
|
16
|
-
REVOKE_PERMISSIONS_RESPONSE: "air_revoke_permissions_response"
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { AirMessageTypes };
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import { getPopupFeatures, FEATURES_DEFAULT_POPUP_WINDOW } from '@toruslabs/base-controllers';
|
|
3
|
-
import { SafeEventEmitter } from '@web3auth/auth';
|
|
4
|
-
|
|
5
|
-
class PopupHandler extends SafeEventEmitter {
|
|
6
|
-
constructor({
|
|
7
|
-
url,
|
|
8
|
-
target,
|
|
9
|
-
features,
|
|
10
|
-
timeout = 30000
|
|
11
|
-
}) {
|
|
12
|
-
super();
|
|
13
|
-
_defineProperty(this, "url", void 0);
|
|
14
|
-
_defineProperty(this, "target", void 0);
|
|
15
|
-
_defineProperty(this, "features", void 0);
|
|
16
|
-
_defineProperty(this, "window", void 0);
|
|
17
|
-
_defineProperty(this, "windowTimer", void 0);
|
|
18
|
-
_defineProperty(this, "iClosedWindow", void 0);
|
|
19
|
-
_defineProperty(this, "timeout", void 0);
|
|
20
|
-
this.url = url;
|
|
21
|
-
this.target = target || "_blank";
|
|
22
|
-
this.features = features || getPopupFeatures(FEATURES_DEFAULT_POPUP_WINDOW);
|
|
23
|
-
this.window = undefined;
|
|
24
|
-
this.windowTimer = undefined;
|
|
25
|
-
this.iClosedWindow = false;
|
|
26
|
-
this.timeout = timeout;
|
|
27
|
-
this._setupTimer();
|
|
28
|
-
}
|
|
29
|
-
_setupTimer() {
|
|
30
|
-
this.windowTimer = Number(setInterval(() => {
|
|
31
|
-
if (this.window && this.window.closed) {
|
|
32
|
-
clearInterval(this.windowTimer);
|
|
33
|
-
setTimeout(() => {
|
|
34
|
-
if (!this.iClosedWindow) {
|
|
35
|
-
this.emit("close");
|
|
36
|
-
}
|
|
37
|
-
this.iClosedWindow = false;
|
|
38
|
-
this.window = undefined;
|
|
39
|
-
}, this.timeout);
|
|
40
|
-
}
|
|
41
|
-
if (this.window === undefined) clearInterval(this.windowTimer);
|
|
42
|
-
}, 500));
|
|
43
|
-
}
|
|
44
|
-
open() {
|
|
45
|
-
var _this$window;
|
|
46
|
-
this.window = window.open(this.url.href, this.target, this.features);
|
|
47
|
-
if ((_this$window = this.window) !== null && _this$window !== void 0 && _this$window.focus) this.window.focus();
|
|
48
|
-
}
|
|
49
|
-
close() {
|
|
50
|
-
this.iClosedWindow = true;
|
|
51
|
-
if (this.window) this.window.close();
|
|
52
|
-
}
|
|
53
|
-
redirect(locationReplaceOnRedirect) {
|
|
54
|
-
if (locationReplaceOnRedirect) {
|
|
55
|
-
window.location.replace(this.url.href);
|
|
56
|
-
} else {
|
|
57
|
-
window.location.href = this.url.href;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export { PopupHandler as default };
|