@dynamic-labs/global-wallet-client 4.9.7 → 4.9.9
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 +19 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +7 -6
- package/src/core.d.ts +4 -0
- package/src/lib/actions/connectAction/createConnectAction.cjs +3 -1
- package/src/lib/actions/connectAction/createConnectAction.js +4 -2
- package/src/lib/createGlobalWalletClient.cjs +10 -4
- package/src/lib/createGlobalWalletClient.js +10 -4
- package/src/lib/errors/DisconnectError.cjs +19 -0
- package/src/lib/errors/DisconnectError.d.ts +5 -0
- package/src/lib/errors/DisconnectError.js +15 -0
- package/src/lib/errors/PopupClosedError.cjs +12 -0
- package/src/lib/errors/PopupClosedError.d.ts +3 -0
- package/src/lib/errors/PopupClosedError.js +8 -0
- package/src/lib/errors/UnknownError.cjs +12 -0
- package/src/lib/errors/UnknownError.d.ts +3 -0
- package/src/lib/errors/UnknownError.js +8 -0
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.cjs +13 -7
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.js +13 -7
- package/src/lib/functions/createEncryptedMessageEncoder/createEncryptedMessageEncoder.cjs +19 -0
- package/src/lib/functions/createEncryptedMessageEncoder/createEncryptedMessageEncoder.d.ts +3 -0
- package/src/lib/functions/createEncryptedMessageEncoder/createEncryptedMessageEncoder.js +15 -0
- package/src/lib/functions/createEncryptedMessageEncoder/index.d.ts +1 -0
- package/src/lib/functions/createPopupMessageClient/createPopupMessageClient.cjs +74 -0
- package/src/lib/functions/createPopupMessageClient/createPopupMessageClient.d.ts +14 -0
- package/src/lib/functions/createPopupMessageClient/createPopupMessageClient.js +70 -0
- package/src/lib/functions/createPopupMessageClient/index.d.ts +1 -0
- package/src/lib/functions/createPopupOpener/createPopupOpener.cjs +110 -42
- package/src/lib/functions/createPopupOpener/createPopupOpener.d.ts +2 -1
- package/src/lib/functions/createPopupOpener/createPopupOpener.js +111 -43
- package/src/lib/functions/createPopupOpener/utils/mapErrorFromPopup.cjs +25 -0
- package/src/lib/functions/createPopupOpener/utils/mapErrorFromPopup.d.ts +4 -0
- package/src/lib/functions/createPopupOpener/utils/mapErrorFromPopup.js +21 -0
- package/src/lib/solana/errors/UserRejectedRequestError.cjs +13 -0
- package/src/lib/solana/errors/UserRejectedRequestError.d.ts +4 -0
- package/src/lib/solana/errors/UserRejectedRequestError.js +9 -0
- package/src/lib/solana/functions/convertErrorToStandard/convertErrorToStandard.cjs +17 -0
- package/src/lib/solana/functions/convertErrorToStandard/convertErrorToStandard.d.ts +1 -0
- package/src/lib/solana/functions/convertErrorToStandard/convertErrorToStandard.js +13 -0
- package/src/lib/solana/functions/convertErrorToStandard/index.d.ts +1 -0
- package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/createSolanaSignAndSendTransactionFeature.cjs +5 -2
- package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/createSolanaSignAndSendTransactionFeature.js +5 -2
- package/src/lib/solana/functions/createSolanaSignMessageFeature/createSolanaSignMessageFeature.cjs +5 -2
- package/src/lib/solana/functions/createSolanaSignMessageFeature/createSolanaSignMessageFeature.js +5 -2
- package/src/lib/solana/functions/createSolanaSignTransactionFeature/createSolanaSignTransactionFeature.cjs +5 -2
- package/src/lib/solana/functions/createSolanaSignTransactionFeature/createSolanaSignTransactionFeature.js +5 -2
- package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.cjs +2 -1
- package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.js +2 -1
- package/src/lib/store/createClientStore.cjs +23 -1
- package/src/lib/store/createClientStore.d.ts +14 -0
- package/src/lib/store/createClientStore.js +23 -1
- package/src/lib/types/GlobalWalletPopupMessages.d.ts +16 -0
- package/src/lib/constants/logger.cjs +0 -10
- package/src/lib/constants/logger.js +0 -6
- package/src/lib/functions/mergeAndEncryptParams/index.d.ts +0 -1
- package/src/lib/functions/mergeAndEncryptParams/mergeAndEncryptParams.cjs +0 -23
- package/src/lib/functions/mergeAndEncryptParams/mergeAndEncryptParams.d.ts +0 -2
- package/src/lib/functions/mergeAndEncryptParams/mergeAndEncryptParams.js +0 -19
- package/src/lib/functions/mergeURLSearchParams/index.d.ts +0 -1
- package/src/lib/functions/mergeURLSearchParams/mergeURLSearchParams.cjs +0 -17
- package/src/lib/functions/mergeURLSearchParams/mergeURLSearchParams.d.ts +0 -6
- package/src/lib/functions/mergeURLSearchParams/mergeURLSearchParams.js +0 -13
- package/src/lib/functions/waitForPopupResponse/index.d.ts +0 -1
- package/src/lib/functions/waitForPopupResponse/waitForPopupResponse.cjs +0 -55
- package/src/lib/functions/waitForPopupResponse/waitForPopupResponse.d.ts +0 -9
- package/src/lib/functions/waitForPopupResponse/waitForPopupResponse.js +0 -51
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.9.9](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.8...v4.9.9) (2025-03-26)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* **global-wallet-client:** properly clean up the popup state when popup is closed ([#8379](https://github.com/dynamic-labs/dynamic-auth/issues/8379)) ([782963f](https://github.com/dynamic-labs/dynamic-auth/commit/782963f87fcb2658b921ff6cc6f22c63be9714fb))
|
|
8
|
+
* hanging promises when a starknet wallet is connected but locked ([#8376](https://github.com/dynamic-labs/dynamic-auth/issues/8376)) ([a753939](https://github.com/dynamic-labs/dynamic-auth/commit/a7539395d4653be49f000ae51d15347a176b5b6c))
|
|
9
|
+
* token balance list should respect sort from backend ([#8383](https://github.com/dynamic-labs/dynamic-auth/issues/8383)) ([1c3bef4](https://github.com/dynamic-labs/dynamic-auth/commit/1c3bef47dbfd319e2444368a4a503b0839b5ad4b))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* add message auth code to global wallet ([#8354](https://github.com/dynamic-labs/dynamic-auth/issues/8354)) ([c847bf8](https://github.com/dynamic-labs/dynamic-auth/commit/c847bf8d66db54534348622255997f30f4309542))
|
|
13
|
+
|
|
14
|
+
### [4.9.8](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.7...v4.9.8) (2025-03-24)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* unlink wallets when using 7702 account ([#8367](https://github.com/dynamic-labs/dynamic-auth/issues/8367)) ([f5acf05](https://github.com/dynamic-labs/dynamic-auth/commit/f5acf05ef31b8f411f3b0cd0e90e919e71f4ad50))
|
|
20
|
+
|
|
2
21
|
### [4.9.7](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.6...v4.9.7) (2025-03-21)
|
|
3
22
|
|
|
4
23
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/global-wallet-client",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.9",
|
|
4
4
|
"description": "Core package for building Dynamic's Global Wallet",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,11 +39,12 @@
|
|
|
39
39
|
},
|
|
40
40
|
"homepage": "https://www.dynamic.xyz/",
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@dynamic-labs/assert-package-version": "4.9.
|
|
43
|
-
"@dynamic-labs/logger": "4.9.
|
|
44
|
-
"@dynamic-labs/
|
|
45
|
-
"@dynamic-labs/
|
|
46
|
-
"@dynamic-labs/
|
|
42
|
+
"@dynamic-labs/assert-package-version": "4.9.9",
|
|
43
|
+
"@dynamic-labs/logger": "4.9.9",
|
|
44
|
+
"@dynamic-labs/message-transport": "4.9.9",
|
|
45
|
+
"@dynamic-labs/store": "4.9.9",
|
|
46
|
+
"@dynamic-labs/types": "4.9.9",
|
|
47
|
+
"@dynamic-labs/utils": "4.9.9",
|
|
47
48
|
"eventemitter3": "5.0.1"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
package/src/core.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createPopupMessageClient, type PopupMessageClient, } from './lib/functions/createPopupMessageClient';
|
|
2
|
+
export { createEncryptedMessageEncoder } from './lib/functions/createEncryptedMessageEncoder';
|
|
3
|
+
export type { GlobalWalletPopupMessages } from './lib/types/GlobalWalletPopupMessages';
|
|
4
|
+
export { DisconnectError } from './lib/errors/DisconnectError';
|
|
@@ -18,7 +18,9 @@ const createConnectAction = ({ store, openPopup, onConnect }) => (_a) => _tslib.
|
|
|
18
18
|
});
|
|
19
19
|
const { encryptedMessage, expiresAt, iv, providerPublicKey } = data;
|
|
20
20
|
const sharedSecret = yield utils.deriveSharedSecret(keyPair.privateKey, yield utils.convertPublicKeyHexToCryptoKey(providerPublicKey));
|
|
21
|
-
const
|
|
21
|
+
const { sessionAuthCode } = store;
|
|
22
|
+
utils.assertDefined(sessionAuthCode, 'Session auth code is required');
|
|
23
|
+
const message = yield utils.decryptMessage(sharedSecret, encryptedMessage, iv, sessionAuthCode);
|
|
22
24
|
const { ethereum, solana, wallets } = JSON.parse(message);
|
|
23
25
|
store.setInitialConnectionState({
|
|
24
26
|
connection: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
|
-
import { createKeyPair, convertPublicKeyCryptoKeyToHex, deriveSharedSecret, convertPublicKeyHexToCryptoKey, decryptMessage } from '@dynamic-labs/utils';
|
|
3
|
+
import { createKeyPair, convertPublicKeyCryptoKeyToHex, deriveSharedSecret, convertPublicKeyHexToCryptoKey, assertDefined, decryptMessage } from '@dynamic-labs/utils';
|
|
4
4
|
|
|
5
5
|
const createConnectAction = ({ store, openPopup, onConnect }) => (_a) => __awaiter(void 0, [_a], void 0, function* ({ chain }) {
|
|
6
6
|
store.clear();
|
|
@@ -14,7 +14,9 @@ const createConnectAction = ({ store, openPopup, onConnect }) => (_a) => __await
|
|
|
14
14
|
});
|
|
15
15
|
const { encryptedMessage, expiresAt, iv, providerPublicKey } = data;
|
|
16
16
|
const sharedSecret = yield deriveSharedSecret(keyPair.privateKey, yield convertPublicKeyHexToCryptoKey(providerPublicKey));
|
|
17
|
-
const
|
|
17
|
+
const { sessionAuthCode } = store;
|
|
18
|
+
assertDefined(sessionAuthCode, 'Session auth code is required');
|
|
19
|
+
const message = yield decryptMessage(sharedSecret, encryptedMessage, iv, sessionAuthCode);
|
|
18
20
|
const { ethereum, solana, wallets } = JSON.parse(message);
|
|
19
21
|
store.setInitialConnectionState({
|
|
20
22
|
connection: {
|
|
@@ -14,6 +14,7 @@ var createSolanaModule = require('./functions/createSolanaModule/createSolanaMod
|
|
|
14
14
|
var addVersionPostfixToUrl = require('./functions/addVersionPostfixToUrl/addVersionPostfixToUrl.cjs');
|
|
15
15
|
var isSSR = require('./functions/isSSR/isSSR.cjs');
|
|
16
16
|
var fakeStorage = require('./constants/fakeStorage/fakeStorage.cjs');
|
|
17
|
+
var DisconnectError = require('./errors/DisconnectError.cjs');
|
|
17
18
|
|
|
18
19
|
const createGlobalWalletClient = ({ environmentId, popup: popupInfo, developmentOptions: { postfixPopupUrlWithVersion = true } = {}, }) => {
|
|
19
20
|
const eventEmitter = createClientEventEmitter.createClientEventEmitter();
|
|
@@ -23,8 +24,17 @@ const createGlobalWalletClient = ({ environmentId, popup: popupInfo, development
|
|
|
23
24
|
const popupUrl = postfixPopupUrlWithVersion
|
|
24
25
|
? addVersionPostfixToUrl.addVersionPostfixToUrl(_package.version, popupInfo.url)
|
|
25
26
|
: popupInfo.url;
|
|
27
|
+
const disconnect = createDisconnectAction.createDisconnectAction({
|
|
28
|
+
onDisconnect: () => eventEmitter.emit('disconnect'),
|
|
29
|
+
store,
|
|
30
|
+
});
|
|
26
31
|
const openPopup = createPopupOpener.createPopupOpener({
|
|
27
32
|
environmentId,
|
|
33
|
+
onError: (error) => {
|
|
34
|
+
if (error instanceof DisconnectError.DisconnectError) {
|
|
35
|
+
disconnect();
|
|
36
|
+
}
|
|
37
|
+
},
|
|
28
38
|
popupHeight: popupInfo.height,
|
|
29
39
|
popupUrl,
|
|
30
40
|
popupWidth: popupInfo.width,
|
|
@@ -35,10 +45,6 @@ const createGlobalWalletClient = ({ environmentId, popup: popupInfo, development
|
|
|
35
45
|
openPopup,
|
|
36
46
|
store,
|
|
37
47
|
});
|
|
38
|
-
const disconnect = createDisconnectAction.createDisconnectAction({
|
|
39
|
-
onDisconnect: () => eventEmitter.emit('disconnect'),
|
|
40
|
-
store,
|
|
41
|
-
});
|
|
42
48
|
return {
|
|
43
49
|
connect,
|
|
44
50
|
disconnect,
|
|
@@ -10,6 +10,7 @@ import { createSolanaModule } from './functions/createSolanaModule/createSolanaM
|
|
|
10
10
|
import { addVersionPostfixToUrl } from './functions/addVersionPostfixToUrl/addVersionPostfixToUrl.js';
|
|
11
11
|
import { isSSR } from './functions/isSSR/isSSR.js';
|
|
12
12
|
import { fakeStorage } from './constants/fakeStorage/fakeStorage.js';
|
|
13
|
+
import { DisconnectError } from './errors/DisconnectError.js';
|
|
13
14
|
|
|
14
15
|
const createGlobalWalletClient = ({ environmentId, popup: popupInfo, developmentOptions: { postfixPopupUrlWithVersion = true } = {}, }) => {
|
|
15
16
|
const eventEmitter = createClientEventEmitter();
|
|
@@ -19,8 +20,17 @@ const createGlobalWalletClient = ({ environmentId, popup: popupInfo, development
|
|
|
19
20
|
const popupUrl = postfixPopupUrlWithVersion
|
|
20
21
|
? addVersionPostfixToUrl(version, popupInfo.url)
|
|
21
22
|
: popupInfo.url;
|
|
23
|
+
const disconnect = createDisconnectAction({
|
|
24
|
+
onDisconnect: () => eventEmitter.emit('disconnect'),
|
|
25
|
+
store,
|
|
26
|
+
});
|
|
22
27
|
const openPopup = createPopupOpener({
|
|
23
28
|
environmentId,
|
|
29
|
+
onError: (error) => {
|
|
30
|
+
if (error instanceof DisconnectError) {
|
|
31
|
+
disconnect();
|
|
32
|
+
}
|
|
33
|
+
},
|
|
24
34
|
popupHeight: popupInfo.height,
|
|
25
35
|
popupUrl,
|
|
26
36
|
popupWidth: popupInfo.width,
|
|
@@ -31,10 +41,6 @@ const createGlobalWalletClient = ({ environmentId, popup: popupInfo, development
|
|
|
31
41
|
openPopup,
|
|
32
42
|
store,
|
|
33
43
|
});
|
|
34
|
-
const disconnect = createDisconnectAction({
|
|
35
|
-
onDisconnect: () => eventEmitter.emit('disconnect'),
|
|
36
|
-
store,
|
|
37
|
-
});
|
|
38
44
|
return {
|
|
39
45
|
connect,
|
|
40
46
|
disconnect,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
class DisconnectError extends Error {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(DisconnectError.MESSAGE);
|
|
9
|
+
}
|
|
10
|
+
static isDisconnectError(error) {
|
|
11
|
+
if (!error || !Object.prototype.hasOwnProperty.call(error, 'message')) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return error.message === DisconnectError.MESSAGE;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
DisconnectError.MESSAGE = 'Global wallet was disconnected';
|
|
18
|
+
|
|
19
|
+
exports.DisconnectError = DisconnectError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
class DisconnectError extends Error {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(DisconnectError.MESSAGE);
|
|
5
|
+
}
|
|
6
|
+
static isDisconnectError(error) {
|
|
7
|
+
if (!error || !Object.prototype.hasOwnProperty.call(error, 'message')) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return error.message === DisconnectError.MESSAGE;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
DisconnectError.MESSAGE = 'Global wallet was disconnected';
|
|
14
|
+
|
|
15
|
+
export { DisconnectError };
|
|
@@ -7,6 +7,8 @@ var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
|
7
7
|
var viem = require('viem');
|
|
8
8
|
var eventemitter3 = require('eventemitter3');
|
|
9
9
|
var isNetworkSupported = require('../isNetworkSupported/isNetworkSupported.cjs');
|
|
10
|
+
var PopupClosedError = require('../../../errors/PopupClosedError.cjs');
|
|
11
|
+
var DisconnectError = require('../../../errors/DisconnectError.cjs');
|
|
10
12
|
|
|
11
13
|
const createEIP1193Provider = (client) => {
|
|
12
14
|
const eventEmitter = new eventemitter3.EventEmitter();
|
|
@@ -66,7 +68,10 @@ const handleEthRequestAccounts = (client) => {
|
|
|
66
68
|
if (isConnected(client)) {
|
|
67
69
|
return getConnectedAddresses(client);
|
|
68
70
|
}
|
|
69
|
-
return client
|
|
71
|
+
return client
|
|
72
|
+
.connect({ chain: 'evm' })
|
|
73
|
+
.then(({ address }) => [address])
|
|
74
|
+
.catch(mapErrorToStandard);
|
|
70
75
|
};
|
|
71
76
|
const handleWalletRevokePermissions = (client) => {
|
|
72
77
|
client.disconnect();
|
|
@@ -108,13 +113,14 @@ const handleMethodInPopup = (_a) => _tslib.__awaiter(void 0, [_a], void 0, funct
|
|
|
108
113
|
},
|
|
109
114
|
pathname: 'eth-request',
|
|
110
115
|
})
|
|
111
|
-
.catch(
|
|
112
|
-
if (err.message === 'Popup closed') {
|
|
113
|
-
throw new viem.UserRejectedRequestError(err);
|
|
114
|
-
}
|
|
115
|
-
throw err;
|
|
116
|
-
});
|
|
116
|
+
.catch(mapErrorToStandard);
|
|
117
117
|
return data;
|
|
118
118
|
});
|
|
119
|
+
const mapErrorToStandard = (error) => {
|
|
120
|
+
if (error instanceof PopupClosedError.PopupClosedError || error instanceof DisconnectError.DisconnectError) {
|
|
121
|
+
throw new viem.UserRejectedRequestError(error);
|
|
122
|
+
}
|
|
123
|
+
throw error;
|
|
124
|
+
};
|
|
119
125
|
|
|
120
126
|
exports.createEIP1193Provider = createEIP1193Provider;
|
|
@@ -3,6 +3,8 @@ import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
|
3
3
|
import { toHex, ProviderDisconnectedError, UnsupportedProviderMethodError, SwitchChainError, fromHex, UserRejectedRequestError } from 'viem';
|
|
4
4
|
import { EventEmitter } from 'eventemitter3';
|
|
5
5
|
import { isNetworkSupported } from '../isNetworkSupported/isNetworkSupported.js';
|
|
6
|
+
import { PopupClosedError } from '../../../errors/PopupClosedError.js';
|
|
7
|
+
import { DisconnectError } from '../../../errors/DisconnectError.js';
|
|
6
8
|
|
|
7
9
|
const createEIP1193Provider = (client) => {
|
|
8
10
|
const eventEmitter = new EventEmitter();
|
|
@@ -62,7 +64,10 @@ const handleEthRequestAccounts = (client) => {
|
|
|
62
64
|
if (isConnected(client)) {
|
|
63
65
|
return getConnectedAddresses(client);
|
|
64
66
|
}
|
|
65
|
-
return client
|
|
67
|
+
return client
|
|
68
|
+
.connect({ chain: 'evm' })
|
|
69
|
+
.then(({ address }) => [address])
|
|
70
|
+
.catch(mapErrorToStandard);
|
|
66
71
|
};
|
|
67
72
|
const handleWalletRevokePermissions = (client) => {
|
|
68
73
|
client.disconnect();
|
|
@@ -104,13 +109,14 @@ const handleMethodInPopup = (_a) => __awaiter(void 0, [_a], void 0, function* ({
|
|
|
104
109
|
},
|
|
105
110
|
pathname: 'eth-request',
|
|
106
111
|
})
|
|
107
|
-
.catch(
|
|
108
|
-
if (err.message === 'Popup closed') {
|
|
109
|
-
throw new UserRejectedRequestError(err);
|
|
110
|
-
}
|
|
111
|
-
throw err;
|
|
112
|
-
});
|
|
112
|
+
.catch(mapErrorToStandard);
|
|
113
113
|
return data;
|
|
114
114
|
});
|
|
115
|
+
const mapErrorToStandard = (error) => {
|
|
116
|
+
if (error instanceof PopupClosedError || error instanceof DisconnectError) {
|
|
117
|
+
throw new UserRejectedRequestError(error);
|
|
118
|
+
}
|
|
119
|
+
throw error;
|
|
120
|
+
};
|
|
115
121
|
|
|
116
122
|
export { createEIP1193Provider };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
|
|
9
|
+
const createEncryptedMessageEncoder = (activeConnection, additionalData) => ({
|
|
10
|
+
decode: (data) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
utils.assertDefined(data.encryptedMessage, 'Encrypted message is not defined');
|
|
12
|
+
utils.assertDefined(data.iv, 'IV is not defined');
|
|
13
|
+
const decryptedData = yield utils.decryptMessage(activeConnection.sharedSecret, data.encryptedMessage, data.iv, additionalData);
|
|
14
|
+
return JSON.parse(decryptedData);
|
|
15
|
+
}),
|
|
16
|
+
encode: (message) => utils.encryptMessage(activeConnection.sharedSecret, JSON.stringify(message), additionalData),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
exports.createEncryptedMessageEncoder = createEncryptedMessageEncoder;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
|
+
import { assertDefined, decryptMessage, encryptMessage } from '@dynamic-labs/utils';
|
|
4
|
+
|
|
5
|
+
const createEncryptedMessageEncoder = (activeConnection, additionalData) => ({
|
|
6
|
+
decode: (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
7
|
+
assertDefined(data.encryptedMessage, 'Encrypted message is not defined');
|
|
8
|
+
assertDefined(data.iv, 'IV is not defined');
|
|
9
|
+
const decryptedData = yield decryptMessage(activeConnection.sharedSecret, data.encryptedMessage, data.iv, additionalData);
|
|
10
|
+
return JSON.parse(decryptedData);
|
|
11
|
+
}),
|
|
12
|
+
encode: (message) => encryptMessage(activeConnection.sharedSecret, JSON.stringify(message), additionalData),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export { createEncryptedMessageEncoder };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createEncryptedMessageEncoder } from './createEncryptedMessageEncoder';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
|
|
9
|
+
const createPopupMessageClient = (popupWindow, targetOrigin, messageEncoder) => {
|
|
10
|
+
const listenForMessage = (messageName, callback) => {
|
|
11
|
+
const handleOnWindowEvent = (event) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
if (event.origin !== targetOrigin)
|
|
13
|
+
return;
|
|
14
|
+
let parsedMessage = null;
|
|
15
|
+
try {
|
|
16
|
+
parsedMessage = JSON.parse(event.data);
|
|
17
|
+
if (messageEncoder) {
|
|
18
|
+
parsedMessage = yield messageEncoder.decode(parsedMessage);
|
|
19
|
+
}
|
|
20
|
+
parsedMessage =
|
|
21
|
+
parseDataFromWindowEvent(parsedMessage);
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (parsedMessage.name !== messageName)
|
|
27
|
+
return;
|
|
28
|
+
callback(...parsedMessage.args);
|
|
29
|
+
});
|
|
30
|
+
window.addEventListener('message', handleOnWindowEvent);
|
|
31
|
+
return () => {
|
|
32
|
+
window.removeEventListener('message', handleOnWindowEvent);
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const waitForMessage = (messageName, timeout) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
const deferred = new utils.DeferredPromise();
|
|
37
|
+
const timeoutId = timeout
|
|
38
|
+
? setTimeout(() => {
|
|
39
|
+
deferred.reject(new Error(`Timeout waiting for message: ${messageName}`));
|
|
40
|
+
}, timeout)
|
|
41
|
+
: undefined;
|
|
42
|
+
const cleanup = listenForMessage(messageName, (...args) => deferred.resolve(args));
|
|
43
|
+
return deferred.promise.finally(() => {
|
|
44
|
+
cleanup === null || cleanup === void 0 ? void 0 : cleanup();
|
|
45
|
+
clearTimeout(timeoutId);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
const postMessage = (messageName,
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
...args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
+
var _a;
|
|
52
|
+
const message = {
|
|
53
|
+
args,
|
|
54
|
+
name: messageName,
|
|
55
|
+
};
|
|
56
|
+
const messageToPost = (_a = (yield (messageEncoder === null || messageEncoder === void 0 ? void 0 : messageEncoder.encode(message)))) !== null && _a !== void 0 ? _a : message;
|
|
57
|
+
popupWindow.postMessage(JSON.stringify(messageToPost), targetOrigin);
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
listenForMessage,
|
|
61
|
+
postMessage,
|
|
62
|
+
waitForMessage,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const parseDataFromWindowEvent = (data) => {
|
|
66
|
+
utils.assertDefined(data.name, 'Name is required');
|
|
67
|
+
utils.assertDefined(data.args, 'Args is required');
|
|
68
|
+
return {
|
|
69
|
+
args: data.args,
|
|
70
|
+
name: data.name,
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
exports.createPopupMessageClient = createPopupMessageClient;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type RawMessage = {
|
|
2
|
+
name: string;
|
|
3
|
+
args: unknown[];
|
|
4
|
+
};
|
|
5
|
+
export type MessageEncoder = {
|
|
6
|
+
encode: (message: RawMessage) => Promise<any>;
|
|
7
|
+
decode: (data: any) => Promise<RawMessage>;
|
|
8
|
+
};
|
|
9
|
+
export declare const createPopupMessageClient: <T extends Record<string, (...args: any[]) => void>>(popupWindow: Window, targetOrigin: string, messageEncoder?: MessageEncoder) => {
|
|
10
|
+
listenForMessage: <TMessageName extends keyof T = keyof T>(messageName: TMessageName, callback: (...args: Parameters<T[TMessageName]>) => void) => VoidFunction;
|
|
11
|
+
postMessage: <TMessageName_1 extends keyof T = keyof T>(messageName: TMessageName_1, ...args: Parameters<T[TMessageName_1]>) => Promise<void>;
|
|
12
|
+
waitForMessage: <TMessageName_2 extends keyof T = keyof T>(messageName: TMessageName_2, timeout?: number) => Promise<Parameters<T[TMessageName_2]>>;
|
|
13
|
+
};
|
|
14
|
+
export type PopupMessageClient<TMessage extends Record<string, (...args: any[]) => void>> = ReturnType<typeof createPopupMessageClient<TMessage>>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
3
|
+
import { DeferredPromise, assertDefined } from '@dynamic-labs/utils';
|
|
4
|
+
|
|
5
|
+
const createPopupMessageClient = (popupWindow, targetOrigin, messageEncoder) => {
|
|
6
|
+
const listenForMessage = (messageName, callback) => {
|
|
7
|
+
const handleOnWindowEvent = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8
|
+
if (event.origin !== targetOrigin)
|
|
9
|
+
return;
|
|
10
|
+
let parsedMessage = null;
|
|
11
|
+
try {
|
|
12
|
+
parsedMessage = JSON.parse(event.data);
|
|
13
|
+
if (messageEncoder) {
|
|
14
|
+
parsedMessage = yield messageEncoder.decode(parsedMessage);
|
|
15
|
+
}
|
|
16
|
+
parsedMessage =
|
|
17
|
+
parseDataFromWindowEvent(parsedMessage);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (parsedMessage.name !== messageName)
|
|
23
|
+
return;
|
|
24
|
+
callback(...parsedMessage.args);
|
|
25
|
+
});
|
|
26
|
+
window.addEventListener('message', handleOnWindowEvent);
|
|
27
|
+
return () => {
|
|
28
|
+
window.removeEventListener('message', handleOnWindowEvent);
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
const waitForMessage = (messageName, timeout) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const deferred = new DeferredPromise();
|
|
33
|
+
const timeoutId = timeout
|
|
34
|
+
? setTimeout(() => {
|
|
35
|
+
deferred.reject(new Error(`Timeout waiting for message: ${messageName}`));
|
|
36
|
+
}, timeout)
|
|
37
|
+
: undefined;
|
|
38
|
+
const cleanup = listenForMessage(messageName, (...args) => deferred.resolve(args));
|
|
39
|
+
return deferred.promise.finally(() => {
|
|
40
|
+
cleanup === null || cleanup === void 0 ? void 0 : cleanup();
|
|
41
|
+
clearTimeout(timeoutId);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
const postMessage = (messageName,
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
...args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
var _a;
|
|
48
|
+
const message = {
|
|
49
|
+
args,
|
|
50
|
+
name: messageName,
|
|
51
|
+
};
|
|
52
|
+
const messageToPost = (_a = (yield (messageEncoder === null || messageEncoder === void 0 ? void 0 : messageEncoder.encode(message)))) !== null && _a !== void 0 ? _a : message;
|
|
53
|
+
popupWindow.postMessage(JSON.stringify(messageToPost), targetOrigin);
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
listenForMessage,
|
|
57
|
+
postMessage,
|
|
58
|
+
waitForMessage,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const parseDataFromWindowEvent = (data) => {
|
|
62
|
+
assertDefined(data.name, 'Name is required');
|
|
63
|
+
assertDefined(data.args, 'Args is required');
|
|
64
|
+
return {
|
|
65
|
+
args: data.args,
|
|
66
|
+
name: data.name,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { createPopupMessageClient };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createPopupMessageClient, type MessageEncoder, type PopupMessageClient, type RawMessage, } from './createPopupMessageClient';
|