@dynamic-labs/web-extension 4.0.0-alpha.16
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/CHANGELOG.md +4303 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.cjs +8 -0
- package/package.js +4 -0
- package/package.json +39 -0
- package/src/index.cjs +12 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +6 -0
- package/src/lib/WebExtension/WebExtension.cjs +39 -0
- package/src/lib/WebExtension/WebExtension.d.ts +7 -0
- package/src/lib/WebExtension/WebExtension.js +35 -0
- package/src/lib/WebExtension/index.d.ts +1 -0
- package/src/lib/utils/addHostOriginToUrl/addHostOriginToUrl.cjs +20 -0
- package/src/lib/utils/addHostOriginToUrl/addHostOriginToUrl.d.ts +1 -0
- package/src/lib/utils/addHostOriginToUrl/addHostOriginToUrl.js +16 -0
- package/src/lib/utils/addHostOriginToUrl/index.d.ts +1 -0
- package/src/lib/utils/connectIFrameToMessageTransport/connectIFrameToMessageTransport.cjs +53 -0
- package/src/lib/utils/connectIFrameToMessageTransport/connectIFrameToMessageTransport.d.ts +2 -0
- package/src/lib/utils/connectIFrameToMessageTransport/connectIFrameToMessageTransport.js +49 -0
- package/src/lib/utils/connectIFrameToMessageTransport/index.d.ts +1 -0
- package/src/lib/utils/getIFrameController/getIFrameController.cjs +39 -0
- package/src/lib/utils/getIFrameController/getIFrameController.d.ts +6 -0
- package/src/lib/utils/getIFrameController/getIFrameController.js +35 -0
- package/src/lib/utils/getIFrameController/index.d.ts +1 -0
- package/src/lib/utils/logger.cjs +10 -0
- package/src/lib/utils/logger.d.ts +2 -0
- package/src/lib/utils/logger.js +6 -0
- package/src/lib/utils/setupIFrameVisibilityState/index.d.ts +1 -0
- package/src/lib/utils/setupIFrameVisibilityState/setupIFrameVisibilityState.cjs +20 -0
- package/src/lib/utils/setupIFrameVisibilityState/setupIFrameVisibilityState.d.ts +3 -0
- package/src/lib/utils/setupIFrameVisibilityState/setupIFrameVisibilityState.js +16 -0
- package/src/lib/utils/setupPasskeyHandler/index.d.ts +1 -0
- package/src/lib/utils/setupPasskeyHandler/setupPasskeyHandler.cjs +47 -0
- package/src/lib/utils/setupPasskeyHandler/setupPasskeyHandler.d.ts +2 -0
- package/src/lib/utils/setupPasskeyHandler/setupPasskeyHandler.js +43 -0
- package/src/lib/utils/setupPlatformHandler/index.d.ts +1 -0
- package/src/lib/utils/setupPlatformHandler/setupPlatformHandler.cjs +16 -0
- package/src/lib/utils/setupPlatformHandler/setupPlatformHandler.d.ts +2 -0
- package/src/lib/utils/setupPlatformHandler/setupPlatformHandler.js +12 -0
- package/src/lib/utils/setupSocialHandler/index.d.ts +1 -0
- package/src/lib/utils/setupSocialHandler/setupSocialHandler.cjs +25 -0
- package/src/lib/utils/setupSocialHandler/setupSocialHandler.d.ts +2 -0
- package/src/lib/utils/setupSocialHandler/setupSocialHandler.js +21 -0
- package/src/lib/utils/setupStorage/index.d.ts +1 -0
- package/src/lib/utils/setupStorage/setupStorage.cjs +22 -0
- package/src/lib/utils/setupStorage/setupStorage.d.ts +2 -0
- package/src/lib/utils/setupStorage/setupStorage.js +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Dynamic Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
|
|
21
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
32
|
+
var e = new Error(message);
|
|
33
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.__awaiter = __awaiter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/******************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
|
|
17
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
|
+
var e = new Error(message);
|
|
29
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { __awaiter };
|
package/package.cjs
ADDED
package/package.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs/web-extension",
|
|
3
|
+
"version": "4.0.0-alpha.16",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
|
|
7
|
+
"directory": "packages/web-extension"
|
|
8
|
+
},
|
|
9
|
+
"description": "Core package for utilizing Dynamic's sdk",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/dynamic-labs/DynamicAuth/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/dynamic-labs/DynamicAuth/main/packages/web-extension#readme",
|
|
14
|
+
"author": "Dynamic Labs, Inc.",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"main": "./src/index.cjs",
|
|
17
|
+
"module": "./src/index.js",
|
|
18
|
+
"types": "./src/index.d.ts",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./src/index.d.ts",
|
|
23
|
+
"import": "./src/index.js",
|
|
24
|
+
"require": "./src/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@dynamic-labs/sdk-api-core": "0.0.555",
|
|
30
|
+
"@turnkey/webauthn-stamper": "0.5.0",
|
|
31
|
+
"@dynamic-labs/assert-package-version": "4.0.0-alpha.16",
|
|
32
|
+
"@dynamic-labs/client": "4.0.0-alpha.16",
|
|
33
|
+
"@dynamic-labs/logger": "4.0.0-alpha.16",
|
|
34
|
+
"@dynamic-labs/message-transport": "4.0.0-alpha.16",
|
|
35
|
+
"@dynamic-labs/utils": "4.0.0-alpha.16",
|
|
36
|
+
"@dynamic-labs/webauthn": "4.0.0-alpha.16"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {}
|
|
39
|
+
}
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
|
+
var _package = require('../package.cjs');
|
|
8
|
+
var WebExtension = require('./lib/WebExtension/WebExtension.cjs');
|
|
9
|
+
|
|
10
|
+
assertPackageVersion.assertPackageVersion('@dynamic-labs/web-extension', _package.version);
|
|
11
|
+
|
|
12
|
+
exports.WebExtension = WebExtension.WebExtension;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WebExtension } from './lib/WebExtension';
|
package/src/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _package = require('../../../package.cjs');
|
|
7
|
+
var getIFrameController = require('../utils/getIFrameController/getIFrameController.cjs');
|
|
8
|
+
var connectIFrameToMessageTransport = require('../utils/connectIFrameToMessageTransport/connectIFrameToMessageTransport.cjs');
|
|
9
|
+
var setupIFrameVisibilityState = require('../utils/setupIFrameVisibilityState/setupIFrameVisibilityState.cjs');
|
|
10
|
+
var setupStorage = require('../utils/setupStorage/setupStorage.cjs');
|
|
11
|
+
var addHostOriginToUrl = require('../utils/addHostOriginToUrl/addHostOriginToUrl.cjs');
|
|
12
|
+
var setupPlatformHandler = require('../utils/setupPlatformHandler/setupPlatformHandler.cjs');
|
|
13
|
+
var setupSocialHandler = require('../utils/setupSocialHandler/setupSocialHandler.cjs');
|
|
14
|
+
var setupPasskeyHandler = require('../utils/setupPasskeyHandler/setupPasskeyHandler.cjs');
|
|
15
|
+
|
|
16
|
+
const defaultIFrameUrl = `https://webview.dynamicauth.com/${_package.version}`;
|
|
17
|
+
const WebExtension = ({ iFrameUrl = defaultIFrameUrl, } = {}) => (_, core) => {
|
|
18
|
+
/**
|
|
19
|
+
* Should not run this extension on react-native or SSR
|
|
20
|
+
*/
|
|
21
|
+
if (typeof window === 'undefined' || typeof window.location === 'undefined')
|
|
22
|
+
return {};
|
|
23
|
+
core.manifest.setPlatform('browser');
|
|
24
|
+
core.manifest.setRedirectUrl(window.location.href);
|
|
25
|
+
core.manifest.setAppOrigin(window.location.origin);
|
|
26
|
+
const iFrameId = 'dynamic_browser_extension';
|
|
27
|
+
const iFrameUrlWithHostOrigin = addHostOriginToUrl.addHostOriginToUrl(iFrameUrl, window.location.origin);
|
|
28
|
+
const iFrameController = getIFrameController.getIFrameController(iFrameId, iFrameUrlWithHostOrigin);
|
|
29
|
+
iFrameController.hide();
|
|
30
|
+
connectIFrameToMessageTransport.connectIFrameToMessageTransport(iFrameController.iframe, core.messageTransport);
|
|
31
|
+
setupIFrameVisibilityState.setupIFrameVisibilityState(iFrameController, core.messageTransport);
|
|
32
|
+
setupStorage.setupStorage(core.messageTransport);
|
|
33
|
+
setupPlatformHandler.setupPlatformHandler(core.messageTransport);
|
|
34
|
+
setupSocialHandler.setupSocialHandler(core.messageTransport);
|
|
35
|
+
setupPasskeyHandler.setupPasskeyHandler(core);
|
|
36
|
+
return {};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.WebExtension = WebExtension;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { version } from '../../../package.js';
|
|
3
|
+
import { getIFrameController } from '../utils/getIFrameController/getIFrameController.js';
|
|
4
|
+
import { connectIFrameToMessageTransport } from '../utils/connectIFrameToMessageTransport/connectIFrameToMessageTransport.js';
|
|
5
|
+
import { setupIFrameVisibilityState } from '../utils/setupIFrameVisibilityState/setupIFrameVisibilityState.js';
|
|
6
|
+
import { setupStorage } from '../utils/setupStorage/setupStorage.js';
|
|
7
|
+
import { addHostOriginToUrl } from '../utils/addHostOriginToUrl/addHostOriginToUrl.js';
|
|
8
|
+
import { setupPlatformHandler } from '../utils/setupPlatformHandler/setupPlatformHandler.js';
|
|
9
|
+
import { setupSocialHandler } from '../utils/setupSocialHandler/setupSocialHandler.js';
|
|
10
|
+
import { setupPasskeyHandler } from '../utils/setupPasskeyHandler/setupPasskeyHandler.js';
|
|
11
|
+
|
|
12
|
+
const defaultIFrameUrl = `https://webview.dynamicauth.com/${version}`;
|
|
13
|
+
const WebExtension = ({ iFrameUrl = defaultIFrameUrl, } = {}) => (_, core) => {
|
|
14
|
+
/**
|
|
15
|
+
* Should not run this extension on react-native or SSR
|
|
16
|
+
*/
|
|
17
|
+
if (typeof window === 'undefined' || typeof window.location === 'undefined')
|
|
18
|
+
return {};
|
|
19
|
+
core.manifest.setPlatform('browser');
|
|
20
|
+
core.manifest.setRedirectUrl(window.location.href);
|
|
21
|
+
core.manifest.setAppOrigin(window.location.origin);
|
|
22
|
+
const iFrameId = 'dynamic_browser_extension';
|
|
23
|
+
const iFrameUrlWithHostOrigin = addHostOriginToUrl(iFrameUrl, window.location.origin);
|
|
24
|
+
const iFrameController = getIFrameController(iFrameId, iFrameUrlWithHostOrigin);
|
|
25
|
+
iFrameController.hide();
|
|
26
|
+
connectIFrameToMessageTransport(iFrameController.iframe, core.messageTransport);
|
|
27
|
+
setupIFrameVisibilityState(iFrameController, core.messageTransport);
|
|
28
|
+
setupStorage(core.messageTransport);
|
|
29
|
+
setupPlatformHandler(core.messageTransport);
|
|
30
|
+
setupSocialHandler(core.messageTransport);
|
|
31
|
+
setupPasskeyHandler(core);
|
|
32
|
+
return {};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { WebExtension };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WebExtension } from './WebExtension';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const addHostOriginToUrl = (url, hostOrigin) => {
|
|
7
|
+
if (url.startsWith('http://') || url.startsWith('https://')) {
|
|
8
|
+
const urlObj = new URL(url);
|
|
9
|
+
urlObj.searchParams.set('hostOrigin', hostOrigin);
|
|
10
|
+
return urlObj.toString();
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
const [path, existingSearch] = url.split('?');
|
|
14
|
+
const searchParams = new URLSearchParams(existingSearch);
|
|
15
|
+
searchParams.set('hostOrigin', hostOrigin);
|
|
16
|
+
return `${path}?${searchParams.toString()}`;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.addHostOriginToUrl = addHostOriginToUrl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const addHostOriginToUrl: (url: string, hostOrigin: string) => string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const addHostOriginToUrl = (url, hostOrigin) => {
|
|
3
|
+
if (url.startsWith('http://') || url.startsWith('https://')) {
|
|
4
|
+
const urlObj = new URL(url);
|
|
5
|
+
urlObj.searchParams.set('hostOrigin', hostOrigin);
|
|
6
|
+
return urlObj.toString();
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
const [path, existingSearch] = url.split('?');
|
|
10
|
+
const searchParams = new URLSearchParams(existingSearch);
|
|
11
|
+
searchParams.set('hostOrigin', hostOrigin);
|
|
12
|
+
return `${path}?${searchParams.toString()}`;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { addHostOriginToUrl };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { addHostOriginToUrl } from './addHostOriginToUrl';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var messageTransport = require('@dynamic-labs/message-transport');
|
|
7
|
+
var logger = require('../logger.cjs');
|
|
8
|
+
|
|
9
|
+
const connectIFrameToMessageTransport = (iframe, messageTransport$1) => {
|
|
10
|
+
const sendMessageToWebView = (message) => {
|
|
11
|
+
/**
|
|
12
|
+
* Only forward messages to the webview
|
|
13
|
+
* that where created by the client/host
|
|
14
|
+
*/
|
|
15
|
+
if (message.origin === 'host' && iframe.contentWindow) {
|
|
16
|
+
iframe.contentWindow.postMessage(JSON.stringify(message), '*');
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Handle incoming message from iframe
|
|
21
|
+
* This handler will actually receive any message from the window
|
|
22
|
+
* so we have to filter and validate the message to ensure
|
|
23
|
+
* it is coming from the dynamic webview iframe
|
|
24
|
+
*/
|
|
25
|
+
const handleEvent = (event) => {
|
|
26
|
+
if (event.source !== iframe.contentWindow) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let parsedData = null;
|
|
30
|
+
try {
|
|
31
|
+
parsedData = JSON.parse(event.data);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
logger.logger.debug('Error parsing data from WebExtension iFrame event', err);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const message = messageTransport.parseMessageTransportData(parsedData);
|
|
38
|
+
if (!message) {
|
|
39
|
+
logger.logger.debug('Error validating event data schema from WebExtension iFrame event', parsedData);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Only forward messages from the created by the webview
|
|
44
|
+
*/
|
|
45
|
+
if (message.origin === 'webview') {
|
|
46
|
+
messageTransport$1.emit(message);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
window.addEventListener('message', handleEvent);
|
|
50
|
+
messageTransport$1.on(sendMessageToWebView);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.connectIFrameToMessageTransport = connectIFrameToMessageTransport;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { parseMessageTransportData } from '@dynamic-labs/message-transport';
|
|
3
|
+
import { logger } from '../logger.js';
|
|
4
|
+
|
|
5
|
+
const connectIFrameToMessageTransport = (iframe, messageTransport) => {
|
|
6
|
+
const sendMessageToWebView = (message) => {
|
|
7
|
+
/**
|
|
8
|
+
* Only forward messages to the webview
|
|
9
|
+
* that where created by the client/host
|
|
10
|
+
*/
|
|
11
|
+
if (message.origin === 'host' && iframe.contentWindow) {
|
|
12
|
+
iframe.contentWindow.postMessage(JSON.stringify(message), '*');
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Handle incoming message from iframe
|
|
17
|
+
* This handler will actually receive any message from the window
|
|
18
|
+
* so we have to filter and validate the message to ensure
|
|
19
|
+
* it is coming from the dynamic webview iframe
|
|
20
|
+
*/
|
|
21
|
+
const handleEvent = (event) => {
|
|
22
|
+
if (event.source !== iframe.contentWindow) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let parsedData = null;
|
|
26
|
+
try {
|
|
27
|
+
parsedData = JSON.parse(event.data);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
logger.debug('Error parsing data from WebExtension iFrame event', err);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const message = parseMessageTransportData(parsedData);
|
|
34
|
+
if (!message) {
|
|
35
|
+
logger.debug('Error validating event data schema from WebExtension iFrame event', parsedData);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Only forward messages from the created by the webview
|
|
40
|
+
*/
|
|
41
|
+
if (message.origin === 'webview') {
|
|
42
|
+
messageTransport.emit(message);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
window.addEventListener('message', handleEvent);
|
|
46
|
+
messageTransport.on(sendMessageToWebView);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { connectIFrameToMessageTransport };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { connectIFrameToMessageTransport } from './connectIFrameToMessageTransport';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const getIFrameController = (id, iFrameUrl) => {
|
|
7
|
+
let iframe = document.getElementById(id);
|
|
8
|
+
if (!iframe) {
|
|
9
|
+
iframe = document.createElement('iframe');
|
|
10
|
+
iframe.id = id;
|
|
11
|
+
iframe.src = iFrameUrl;
|
|
12
|
+
document.body.appendChild(iframe);
|
|
13
|
+
}
|
|
14
|
+
const show = () => {
|
|
15
|
+
iframe.style.position = 'fixed';
|
|
16
|
+
iframe.style.top = '0';
|
|
17
|
+
iframe.style.left = '0';
|
|
18
|
+
iframe.style.width = '100%';
|
|
19
|
+
iframe.style.height = '100%';
|
|
20
|
+
iframe.style.zIndex = '999999';
|
|
21
|
+
iframe.style.border = 'none';
|
|
22
|
+
};
|
|
23
|
+
const hide = () => {
|
|
24
|
+
iframe.style.position = 'fixed';
|
|
25
|
+
iframe.style.top = '0';
|
|
26
|
+
iframe.style.left = '0';
|
|
27
|
+
iframe.style.width = '0';
|
|
28
|
+
iframe.style.height = '0';
|
|
29
|
+
iframe.style.zIndex = '-1';
|
|
30
|
+
iframe.style.border = 'none';
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
hide,
|
|
34
|
+
iframe,
|
|
35
|
+
show,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.getIFrameController = getIFrameController;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const getIFrameController = (id, iFrameUrl) => {
|
|
3
|
+
let iframe = document.getElementById(id);
|
|
4
|
+
if (!iframe) {
|
|
5
|
+
iframe = document.createElement('iframe');
|
|
6
|
+
iframe.id = id;
|
|
7
|
+
iframe.src = iFrameUrl;
|
|
8
|
+
document.body.appendChild(iframe);
|
|
9
|
+
}
|
|
10
|
+
const show = () => {
|
|
11
|
+
iframe.style.position = 'fixed';
|
|
12
|
+
iframe.style.top = '0';
|
|
13
|
+
iframe.style.left = '0';
|
|
14
|
+
iframe.style.width = '100%';
|
|
15
|
+
iframe.style.height = '100%';
|
|
16
|
+
iframe.style.zIndex = '999999';
|
|
17
|
+
iframe.style.border = 'none';
|
|
18
|
+
};
|
|
19
|
+
const hide = () => {
|
|
20
|
+
iframe.style.position = 'fixed';
|
|
21
|
+
iframe.style.top = '0';
|
|
22
|
+
iframe.style.left = '0';
|
|
23
|
+
iframe.style.width = '0';
|
|
24
|
+
iframe.style.height = '0';
|
|
25
|
+
iframe.style.zIndex = '-1';
|
|
26
|
+
iframe.style.border = 'none';
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
hide,
|
|
30
|
+
iframe,
|
|
31
|
+
show,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { getIFrameController };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getIFrameController, type IFrameController, } from './getIFrameController';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { setupIFrameVisibilityState } from './setupIFrameVisibilityState';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var messageTransport = require('@dynamic-labs/message-transport');
|
|
7
|
+
|
|
8
|
+
const setupIFrameVisibilityState = (iFrameController, messageTransport$1) => {
|
|
9
|
+
const visibilityRequestChannel = messageTransport.createRequestChannel(messageTransport$1);
|
|
10
|
+
visibilityRequestChannel.handle('setVisibility', (isVisible) => {
|
|
11
|
+
if (isVisible) {
|
|
12
|
+
iFrameController.show();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
iFrameController.hide();
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.setupIFrameVisibilityState = setupIFrameVisibilityState;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { MessageTransportWithDefaultOrigin } from '@dynamic-labs/message-transport';
|
|
2
|
+
import { IFrameController } from '../getIFrameController';
|
|
3
|
+
export declare const setupIFrameVisibilityState: (iFrameController: IFrameController, messageTransport: MessageTransportWithDefaultOrigin) => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { createRequestChannel } from '@dynamic-labs/message-transport';
|
|
3
|
+
|
|
4
|
+
const setupIFrameVisibilityState = (iFrameController, messageTransport) => {
|
|
5
|
+
const visibilityRequestChannel = createRequestChannel(messageTransport);
|
|
6
|
+
visibilityRequestChannel.handle('setVisibility', (isVisible) => {
|
|
7
|
+
if (isVisible) {
|
|
8
|
+
iFrameController.show();
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
iFrameController.hide();
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { setupIFrameVisibilityState };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { setupPasskeyHandler } from './setupPasskeyHandler';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var webauthnStamper = require('@turnkey/webauthn-stamper');
|
|
8
|
+
var messageTransport = require('@dynamic-labs/message-transport');
|
|
9
|
+
var webauthn = require('@dynamic-labs/webauthn');
|
|
10
|
+
var logger = require('../logger.cjs');
|
|
11
|
+
|
|
12
|
+
const setupPasskeyHandler = (core) => {
|
|
13
|
+
const passkeysRequestChannel = messageTransport.createRequestChannel(core.messageTransport);
|
|
14
|
+
passkeysRequestChannel.handle('createPasskey', (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ publicKey }) {
|
|
15
|
+
try {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
const attestation = yield webauthn.createWebauthnCredential(publicKey);
|
|
18
|
+
return {
|
|
19
|
+
attestation: {
|
|
20
|
+
attestationObject: attestation.response.attestationObject,
|
|
21
|
+
clientDataJson: attestation.response.clientDataJSON,
|
|
22
|
+
credentialId: attestation.rawId,
|
|
23
|
+
transports: [],
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
logger.logger.error(err);
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
passkeysRequestChannel.handle('passkeyStamp', (rpId, payload) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
try {
|
|
34
|
+
const stamper = new webauthnStamper.WebauthnStamper({
|
|
35
|
+
rpId,
|
|
36
|
+
});
|
|
37
|
+
const stamped = yield stamper.stamp(payload);
|
|
38
|
+
return stamped;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
logger.logger.error(err);
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.setupPasskeyHandler = setupPasskeyHandler;
|