@dynamic-labs-sdk/wallet-connect 0.1.1 → 0.2.3

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.
Files changed (148) hide show
  1. package/dist/core.cjs.js +552 -0
  2. package/dist/core.cjs.js.map +1 -0
  3. package/dist/core.esm.js +516 -0
  4. package/dist/core.esm.js.map +1 -0
  5. package/dist/createWalletAccountsForWalletConnectWalletProvider/createWalletAccountsForWalletConnectWalletProvider.d.ts.map +1 -0
  6. package/dist/createWalletAccountsForWalletConnectWalletProvider/index.d.ts.map +1 -0
  7. package/{src → dist}/events.d.ts +2 -0
  8. package/dist/events.d.ts.map +1 -0
  9. package/dist/exports/core.d.ts.map +1 -0
  10. package/dist/exports/index.d.ts.map +1 -0
  11. package/dist/importWalletConnectAuthResponse/importWalletConnectAuthResponse.d.ts.map +1 -0
  12. package/dist/importWalletConnectAuthResponse/index.d.ts.map +1 -0
  13. package/dist/importWalletConnectAuthResponse/verifyWalletConnectAuths/index.d.ts.map +1 -0
  14. package/dist/importWalletConnectAuthResponse/verifyWalletConnectAuths/verifyWalletConnectAuths.d.ts.map +1 -0
  15. package/dist/importWalletConnectSession/importWalletConnectSession.d.ts.map +1 -0
  16. package/dist/importWalletConnectSession/index.d.ts.map +1 -0
  17. package/dist/index.cjs.js +17 -0
  18. package/dist/index.cjs.js.map +1 -0
  19. package/dist/index.esm.js +10 -0
  20. package/dist/index.esm.js.map +1 -0
  21. package/dist/initializeWalletConnectExtension/index.d.ts.map +1 -0
  22. package/dist/initializeWalletConnectExtension/initializeWalletConnectExtension.d.ts.map +1 -0
  23. package/dist/isWalletConnectWalletProvider/index.d.ts.map +1 -0
  24. package/dist/isWalletConnectWalletProvider/isWalletConnectWalletProvider.d.ts.map +1 -0
  25. package/dist/isWalletConnectWalletProvider-BNtoAWXb.esm.js +18 -0
  26. package/dist/isWalletConnectWalletProvider-BNtoAWXb.esm.js.map +1 -0
  27. package/dist/isWalletConnectWalletProvider-Caep_Q46.cjs.js +36 -0
  28. package/dist/isWalletConnectWalletProvider-Caep_Q46.cjs.js.map +1 -0
  29. package/dist/namespaceRegistry/getNamespaceRegistry/createNamespaceRegistry/createNamespaceRegistry.d.ts.map +1 -0
  30. package/dist/namespaceRegistry/getNamespaceRegistry/createNamespaceRegistry/index.d.ts.map +1 -0
  31. package/dist/namespaceRegistry/getNamespaceRegistry/getNamespaceRegistry.d.ts +2 -0
  32. package/dist/namespaceRegistry/getNamespaceRegistry/getNamespaceRegistry.d.ts.map +1 -0
  33. package/dist/namespaceRegistry/getNamespaceRegistry/index.d.ts.map +1 -0
  34. package/dist/namespaceRegistry/index.d.ts.map +1 -0
  35. package/dist/namespaceRegistry/namespaceRegistry.types.d.ts.map +1 -0
  36. package/dist/sessionTopicsData/clearTemporarySessions/clearTemporarySessions.d.ts.map +1 -0
  37. package/dist/sessionTopicsData/clearTemporarySessions/index.d.ts.map +1 -0
  38. package/{src → dist}/sessionTopicsData/getSessionTopicsData/getSessionTopicsData.d.ts +3 -1
  39. package/dist/sessionTopicsData/getSessionTopicsData/getSessionTopicsData.d.ts.map +1 -0
  40. package/dist/sessionTopicsData/getSessionTopicsData/index.d.ts.map +1 -0
  41. package/dist/sessionTopicsData/schema.d.ts +4 -0
  42. package/dist/sessionTopicsData/schema.d.ts.map +1 -0
  43. package/dist/sessionTopicsData/sessionTopicsData.types.d.ts.map +1 -0
  44. package/dist/sessionTopicsData/setSessionTopicsData/index.d.ts.map +1 -0
  45. package/{src → dist}/sessionTopicsData/setSessionTopicsData/setSessionTopicsData.d.ts +1 -1
  46. package/dist/sessionTopicsData/setSessionTopicsData/setSessionTopicsData.d.ts.map +1 -0
  47. package/dist/signClient/getSignClient/createSignClient/createSignClient.d.ts.map +1 -0
  48. package/dist/signClient/getSignClient/createSignClient/index.d.ts.map +1 -0
  49. package/dist/signClient/getSignClient/getSignClient.d.ts +2 -0
  50. package/dist/signClient/getSignClient/getSignClient.d.ts.map +1 -0
  51. package/dist/signClient/getSignClient/index.d.ts.map +1 -0
  52. package/dist/splitCaip10Token/index.d.ts.map +1 -0
  53. package/dist/splitCaip10Token/splitCaip10Token.d.ts.map +1 -0
  54. package/dist/syncSessionsToWalletProviders/addMissingWalletProvidersForSessions/addMissingWalletProvidersForSessions.d.ts.map +1 -0
  55. package/dist/syncSessionsToWalletProviders/addMissingWalletProvidersForSessions/index.d.ts.map +1 -0
  56. package/dist/syncSessionsToWalletProviders/index.d.ts.map +1 -0
  57. package/{src → dist}/syncSessionsToWalletProviders/syncSessionsToWalletProviders.d.ts +1 -1
  58. package/dist/syncSessionsToWalletProviders/syncSessionsToWalletProviders.d.ts.map +1 -0
  59. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  60. package/dist/walletConnectWalletProvider.types.d.ts.map +1 -0
  61. package/package.json +27 -15
  62. package/CHANGELOG.md +0 -600
  63. package/core.cjs.d.ts +0 -1
  64. package/core.cjs.js +0 -636
  65. package/core.esm.d.ts +0 -1
  66. package/core.esm.js +0 -609
  67. package/index.cjs.d.ts +0 -1
  68. package/index.cjs.js +0 -13
  69. package/index.esm.d.ts +0 -1
  70. package/index.esm.js +0 -6
  71. package/isWalletConnectWalletProvider.cjs.js +0 -23
  72. package/isWalletConnectWalletProvider.esm.js +0 -19
  73. package/src/createWalletAccountsForWalletConnectWalletProvider/createWalletAccountsForWalletConnectWalletProvider.d.ts.map +0 -1
  74. package/src/createWalletAccountsForWalletConnectWalletProvider/index.d.ts.map +0 -1
  75. package/src/events.d.ts.map +0 -1
  76. package/src/exports/core.d.ts.map +0 -1
  77. package/src/exports/index.d.ts.map +0 -1
  78. package/src/importWalletConnectAuthResponse/importWalletConnectAuthResponse.d.ts.map +0 -1
  79. package/src/importWalletConnectAuthResponse/index.d.ts.map +0 -1
  80. package/src/importWalletConnectAuthResponse/verifyWalletConnectAuths/index.d.ts.map +0 -1
  81. package/src/importWalletConnectAuthResponse/verifyWalletConnectAuths/verifyWalletConnectAuths.d.ts.map +0 -1
  82. package/src/importWalletConnectSession/importWalletConnectSession.d.ts.map +0 -1
  83. package/src/importWalletConnectSession/index.d.ts.map +0 -1
  84. package/src/initializeWalletConnectExtension/index.d.ts.map +0 -1
  85. package/src/initializeWalletConnectExtension/initializeWalletConnectExtension.d.ts.map +0 -1
  86. package/src/isWalletConnectWalletProvider/index.d.ts.map +0 -1
  87. package/src/isWalletConnectWalletProvider/isWalletConnectWalletProvider.d.ts.map +0 -1
  88. package/src/namespaceRegistry/getNamespaceRegistry/createNamespaceRegistry/createNamespaceRegistry.d.ts.map +0 -1
  89. package/src/namespaceRegistry/getNamespaceRegistry/createNamespaceRegistry/index.d.ts.map +0 -1
  90. package/src/namespaceRegistry/getNamespaceRegistry/getNamespaceRegistry.d.ts +0 -2
  91. package/src/namespaceRegistry/getNamespaceRegistry/getNamespaceRegistry.d.ts.map +0 -1
  92. package/src/namespaceRegistry/getNamespaceRegistry/index.d.ts.map +0 -1
  93. package/src/namespaceRegistry/index.d.ts.map +0 -1
  94. package/src/namespaceRegistry/namespaceRegistry.types.d.ts.map +0 -1
  95. package/src/sessionTopicsData/clearTemporarySessions/clearTemporarySessions.d.ts.map +0 -1
  96. package/src/sessionTopicsData/clearTemporarySessions/index.d.ts.map +0 -1
  97. package/src/sessionTopicsData/getSessionTopicsData/getSessionTopicsData.d.ts.map +0 -1
  98. package/src/sessionTopicsData/getSessionTopicsData/index.d.ts.map +0 -1
  99. package/src/sessionTopicsData/schema.d.ts +0 -2
  100. package/src/sessionTopicsData/schema.d.ts.map +0 -1
  101. package/src/sessionTopicsData/sessionTopicsData.types.d.ts.map +0 -1
  102. package/src/sessionTopicsData/setSessionTopicsData/index.d.ts.map +0 -1
  103. package/src/sessionTopicsData/setSessionTopicsData/setSessionTopicsData.d.ts.map +0 -1
  104. package/src/signClient/getSignClient/createSignClient/createSignClient.d.ts.map +0 -1
  105. package/src/signClient/getSignClient/createSignClient/index.d.ts.map +0 -1
  106. package/src/signClient/getSignClient/getSignClient.d.ts +0 -2
  107. package/src/signClient/getSignClient/getSignClient.d.ts.map +0 -1
  108. package/src/signClient/getSignClient/index.d.ts.map +0 -1
  109. package/src/splitCaip10Token/index.d.ts.map +0 -1
  110. package/src/splitCaip10Token/splitCaip10Token.d.ts.map +0 -1
  111. package/src/syncSessionsToWalletProviders/addMissingWalletProvidersForSessions/addMissingWalletProvidersForSessions.d.ts.map +0 -1
  112. package/src/syncSessionsToWalletProviders/addMissingWalletProvidersForSessions/index.d.ts.map +0 -1
  113. package/src/syncSessionsToWalletProviders/index.d.ts.map +0 -1
  114. package/src/syncSessionsToWalletProviders/syncSessionsToWalletProviders.d.ts.map +0 -1
  115. package/src/walletConnectWalletProvider.types.d.ts.map +0 -1
  116. /package/{src → dist}/createWalletAccountsForWalletConnectWalletProvider/createWalletAccountsForWalletConnectWalletProvider.d.ts +0 -0
  117. /package/{src → dist}/createWalletAccountsForWalletConnectWalletProvider/index.d.ts +0 -0
  118. /package/{src → dist}/exports/core.d.ts +0 -0
  119. /package/{src → dist}/exports/index.d.ts +0 -0
  120. /package/{src → dist}/importWalletConnectAuthResponse/importWalletConnectAuthResponse.d.ts +0 -0
  121. /package/{src → dist}/importWalletConnectAuthResponse/index.d.ts +0 -0
  122. /package/{src → dist}/importWalletConnectAuthResponse/verifyWalletConnectAuths/index.d.ts +0 -0
  123. /package/{src → dist}/importWalletConnectAuthResponse/verifyWalletConnectAuths/verifyWalletConnectAuths.d.ts +0 -0
  124. /package/{src → dist}/importWalletConnectSession/importWalletConnectSession.d.ts +0 -0
  125. /package/{src → dist}/importWalletConnectSession/index.d.ts +0 -0
  126. /package/{src → dist}/initializeWalletConnectExtension/index.d.ts +0 -0
  127. /package/{src → dist}/initializeWalletConnectExtension/initializeWalletConnectExtension.d.ts +0 -0
  128. /package/{src → dist}/isWalletConnectWalletProvider/index.d.ts +0 -0
  129. /package/{src → dist}/isWalletConnectWalletProvider/isWalletConnectWalletProvider.d.ts +0 -0
  130. /package/{src → dist}/namespaceRegistry/getNamespaceRegistry/createNamespaceRegistry/createNamespaceRegistry.d.ts +0 -0
  131. /package/{src → dist}/namespaceRegistry/getNamespaceRegistry/createNamespaceRegistry/index.d.ts +0 -0
  132. /package/{src → dist}/namespaceRegistry/getNamespaceRegistry/index.d.ts +0 -0
  133. /package/{src → dist}/namespaceRegistry/index.d.ts +0 -0
  134. /package/{src → dist}/namespaceRegistry/namespaceRegistry.types.d.ts +0 -0
  135. /package/{src → dist}/sessionTopicsData/clearTemporarySessions/clearTemporarySessions.d.ts +0 -0
  136. /package/{src → dist}/sessionTopicsData/clearTemporarySessions/index.d.ts +0 -0
  137. /package/{src → dist}/sessionTopicsData/getSessionTopicsData/index.d.ts +0 -0
  138. /package/{src → dist}/sessionTopicsData/sessionTopicsData.types.d.ts +0 -0
  139. /package/{src → dist}/sessionTopicsData/setSessionTopicsData/index.d.ts +0 -0
  140. /package/{src → dist}/signClient/getSignClient/createSignClient/createSignClient.d.ts +0 -0
  141. /package/{src → dist}/signClient/getSignClient/createSignClient/index.d.ts +0 -0
  142. /package/{src → dist}/signClient/getSignClient/index.d.ts +0 -0
  143. /package/{src → dist}/splitCaip10Token/index.d.ts +0 -0
  144. /package/{src → dist}/splitCaip10Token/splitCaip10Token.d.ts +0 -0
  145. /package/{src → dist}/syncSessionsToWalletProviders/addMissingWalletProvidersForSessions/addMissingWalletProvidersForSessions.d.ts +0 -0
  146. /package/{src → dist}/syncSessionsToWalletProviders/addMissingWalletProvidersForSessions/index.d.ts +0 -0
  147. /package/{src → dist}/syncSessionsToWalletProviders/index.d.ts +0 -0
  148. /package/{src → dist}/walletConnectWalletProvider.types.d.ts +0 -0
@@ -0,0 +1,552 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ const require_isWalletConnectWalletProvider = require('./isWalletConnectWalletProvider-Caep_Q46.cjs.js');
29
+ let _dynamic_labs_sdk_assert_package_version = require("@dynamic-labs-sdk/assert-package-version");
30
+ let _walletconnect_utils = require("@walletconnect/utils");
31
+ let _dynamic_labs_sdk_client = require("@dynamic-labs-sdk/client");
32
+ let _dynamic_labs_sdk_client_core = require("@dynamic-labs-sdk/client/core");
33
+ let zod_mini = require("zod/mini");
34
+ zod_mini = __toESM(zod_mini);
35
+ let _walletconnect_sign_client = require("@walletconnect/sign-client");
36
+ _walletconnect_sign_client = __toESM(_walletconnect_sign_client);
37
+ let _dynamic_labs_sdk_api_core = require("@dynamic-labs/sdk-api-core");
38
+
39
+ //#region src/splitCaip10Token/splitCaip10Token.ts
40
+ /**
41
+ * An account in WalletConnect follows the CAIP-10 standard
42
+ * and is formatted as follows:
43
+ *
44
+ * `<namespace>:<chain>:<address>`
45
+ *
46
+ * Where:
47
+ * - `<namespace>` is the namespace key (e.g. "eip155")
48
+ * - `<chain>` is what we refer to as a network ID (e.g. "1")
49
+ * - `<address>` is the address of the account (e.g. "0x1234567890")
50
+ *
51
+ * See docs: https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md
52
+ *
53
+ * @returns An object with the address, namespace key, and network id
54
+ */
55
+ const splitCaip10Token = (caip10Token) => {
56
+ const [namespaceKey, networkId, address] = caip10Token.split(":");
57
+ return {
58
+ address,
59
+ namespaceKey,
60
+ networkId
61
+ };
62
+ };
63
+
64
+ //#endregion
65
+ //#region src/createWalletAccountsForWalletConnectWalletProvider/createWalletAccountsForWalletConnectWalletProvider.ts
66
+ const createWalletAccountsForWalletConnectWalletProvider = ({ walletProvider }) => {
67
+ /**
68
+ * Since each session can have multiple namespaces, we need to find the namespace
69
+ * that corresponds to this specific wallet provider.
70
+ *
71
+ * A WalletConnect namespace is the equivalent of what we refer to as a chain in the SDK,
72
+ * and they have attributed to them the methods, events and networks that are expected
73
+ * to be supported by the wallet application, as well as which accounts are connected.
74
+ */
75
+ const namespace = walletProvider.session.namespaces[walletProvider.namespaceKey];
76
+ (0, _dynamic_labs_sdk_client_core.assertDefined)(namespace, `Namespace key ${walletProvider.namespaceKey} of wallet provider ${walletProvider.key} not found in its session ${walletProvider.topic}`);
77
+ const accountAddresses = (0, _dynamic_labs_sdk_client_core.filterDuplicates)(namespace.accounts.map((account) => splitCaip10Token(account).address));
78
+ const formatAddress = walletProvider.formatWalletAddress ?? (({ address }) => address);
79
+ return accountAddresses.map((address) => ({
80
+ address: formatAddress({ address }),
81
+ chain: walletProvider.chain,
82
+ id: (0, _dynamic_labs_sdk_client_core.formatWalletAccountId)({
83
+ address,
84
+ chain: walletProvider.chain,
85
+ walletProviderKey: walletProvider.key
86
+ }),
87
+ lastSelectedAt: null,
88
+ verifiedCredentialId: null,
89
+ walletProviderKey: walletProvider.key
90
+ }));
91
+ };
92
+
93
+ //#endregion
94
+ //#region src/sessionTopicsData/schema.ts
95
+ const sessionTopicsStorageKeySchema = (0, _dynamic_labs_sdk_client_core.createStorageKeySchema)({
96
+ key: "sessionTopics",
97
+ schema: zod_mini.record(
98
+ /**
99
+ * The session topic that identifies this session.
100
+ */
101
+ zod_mini.string(),
102
+ /**
103
+ * The session data.
104
+ */
105
+ zod_mini.object({ shouldAddToDynamicWalletAccounts: zod_mini.boolean() })
106
+ )
107
+ });
108
+
109
+ //#endregion
110
+ //#region src/sessionTopicsData/setSessionTopicsData/setSessionTopicsData.ts
111
+ /**
112
+ * Sets the session topics data.
113
+ *
114
+ * Read more about it in the sessionTopicsData.types.ts file.
115
+ *
116
+ * @param update - The function to update the session topics data.
117
+ * @param client - The client instance.
118
+ */
119
+ const setSessionTopicsData = async ({ update }, client) => {
120
+ const { storage } = (0, _dynamic_labs_sdk_client_core.getCore)(client);
121
+ const newSessionTopicsData = update(await storage.getItem(sessionTopicsStorageKeySchema) ?? {});
122
+ if (Object.keys(newSessionTopicsData).length === 0) return storage.removeItem(sessionTopicsStorageKeySchema);
123
+ return storage.setItem(sessionTopicsStorageKeySchema, newSessionTopicsData);
124
+ };
125
+
126
+ //#endregion
127
+ //#region src/sessionTopicsData/getSessionTopicsData/getSessionTopicsData.ts
128
+ /**
129
+ * Gets the session topics data.
130
+ *
131
+ * Read more about it in the sessionTopicsData.types.ts file.
132
+ * @param client - The client instance.
133
+ */
134
+ const getSessionTopicsData = async (client) => {
135
+ const { storage } = (0, _dynamic_labs_sdk_client_core.getCore)(client);
136
+ return await storage.getItem(sessionTopicsStorageKeySchema) ?? {};
137
+ };
138
+
139
+ //#endregion
140
+ //#region src/signClient/getSignClient/createSignClient/createSignClient.ts
141
+ const createSignClient = async (client) => {
142
+ const core = (0, _dynamic_labs_sdk_client_core.getCore)(client);
143
+ (0, _dynamic_labs_sdk_client_core.assertDefined)(client.projectSettings, "Project settings not available");
144
+ const generalSettings = client.projectSettings.general;
145
+ (0, _dynamic_labs_sdk_client_core.assertDefined)(generalSettings.displayName, "Please configure an app name in dashboard to use WalletConnect");
146
+ const projectId = client.projectSettings.sdk.walletConnect?.projectId;
147
+ (0, _dynamic_labs_sdk_client_core.assertDefined)(projectId, "Please configure a project ID for WalletConnect in dashboard");
148
+ const customStoragePrefix = `dynamic_${core.environmentId}_walletconnect`;
149
+ const displayName = core.metadata?.name ?? generalSettings.displayName;
150
+ const appLogo = core.metadata?.iconUrl ?? generalSettings.appLogo;
151
+ return _walletconnect_sign_client.default.init({
152
+ customStoragePrefix,
153
+ metadata: {
154
+ description: "",
155
+ icons: appLogo ? [appLogo] : [],
156
+ name: displayName,
157
+ url: ""
158
+ },
159
+ projectId
160
+ });
161
+ };
162
+
163
+ //#endregion
164
+ //#region src/signClient/getSignClient/getSignClient.ts
165
+ const getSignClient = (0, _dynamic_labs_sdk_client_core.createRuntimeServiceAccessKey)("walletConnectSignClient", (client) => createSignClient(client));
166
+
167
+ //#endregion
168
+ //#region src/namespaceRegistry/getNamespaceRegistry/createNamespaceRegistry/createNamespaceRegistry.ts
169
+ const createNamespaceRegistry = () => {
170
+ const walletProviderBuilderMap = /* @__PURE__ */ new Map();
171
+ return {
172
+ getWalletProviderBuilder: (key) => walletProviderBuilderMap.get(key),
173
+ registerNamespace: ({ createWalletProviderFromSession, namespaceKey }) => {
174
+ walletProviderBuilderMap.set(namespaceKey, createWalletProviderFromSession);
175
+ }
176
+ };
177
+ };
178
+
179
+ //#endregion
180
+ //#region src/namespaceRegistry/getNamespaceRegistry/getNamespaceRegistry.ts
181
+ const getNamespaceRegistry = (0, _dynamic_labs_sdk_client_core.createRuntimeServiceAccessKey)("walletConnectNamespaceRegistry", createNamespaceRegistry);
182
+
183
+ //#endregion
184
+ //#region src/syncSessionsToWalletProviders/addMissingWalletProvidersForSessions/addMissingWalletProvidersForSessions.ts
185
+ const addMissingWalletProvidersForSessions = async ({ sessions, allowOverridingWalletProviders }, client) => {
186
+ const namespaceRegistry = getNamespaceRegistry(client);
187
+ const walletProviderRegistry = (0, _dynamic_labs_sdk_client_core.getWalletProviderRegistry)(client);
188
+ const sessionTopicsData = await getSessionTopicsData(client);
189
+ const currentWalletAccounts = (0, _dynamic_labs_sdk_client.getWalletAccounts)(client);
190
+ sessions.sort((sessionA, sessionB) => sessionA.expiry - sessionB.expiry);
191
+ /**
192
+ * All the WC wallet providers that are currently registered
193
+ */
194
+ const currentWalletProviders = walletProviderRegistry.listProviders().filter(require_isWalletConnectWalletProvider.isWalletConnectWalletProvider);
195
+ /**
196
+ * Keep record on which walletProviders are tied to active sessions
197
+ */
198
+ const walletProvidersWithActiveSession = [];
199
+ /**
200
+ * Maps the ID of the created wallet accounts to the wallet accounts themselves.
201
+ */
202
+ const createdWalletAccounts = {};
203
+ /**
204
+ * Keep record on which wallet account IDs were not in the current wallet accounts
205
+ * and are therefore brand new.
206
+ */
207
+ const brandNewWalletAccounts = /* @__PURE__ */ new Set();
208
+ /**
209
+ * Keep record on which wallet account IDs already exist but will have
210
+ * their wallet provider keys overridden to use the new WC wallet provider key.
211
+ *
212
+ * This will only ever be the case for unverified wallet accounts, however. That is
213
+ * because verified wallets will already override the wallet provider key on the verification
214
+ * step, which happens at the call to verifyWalletConnectAuths, which happens before this function.
215
+ */
216
+ const unverifiedWalletAccountsToOverride = /* @__PURE__ */ new Set();
217
+ for (const session of sessions) {
218
+ const namespaceKeys = Object.keys(session.namespaces);
219
+ for (const namespaceKey of namespaceKeys) {
220
+ const existingWalletProvider = currentWalletProviders.find((walletProvider$1) => walletProvider$1.namespaceKey === namespaceKey && walletProvider$1.topic === session.topic);
221
+ if (existingWalletProvider) {
222
+ walletProvidersWithActiveSession.push(existingWalletProvider);
223
+ continue;
224
+ }
225
+ const walletProviderBuilder = namespaceRegistry.getWalletProviderBuilder(namespaceKey);
226
+ /**
227
+ * There being no wallet provider builder for this namespace simply means the customer
228
+ * didn't add an extension for the corresponding chain.
229
+ * For instance, if we get a namespace for Solana but only have an Evm extension,
230
+ * the solana namespace would fall here. No need to throw.
231
+ */
232
+ if (!walletProviderBuilder) continue;
233
+ const walletProvider = await walletProviderBuilder({ session }, client);
234
+ walletProviderRegistry.register({
235
+ priority: _dynamic_labs_sdk_client_core.WalletProviderPriority.WALLET_SDK,
236
+ walletProvider
237
+ });
238
+ walletProvidersWithActiveSession.push(walletProvider);
239
+ if (!sessionTopicsData[session.topic].shouldAddToDynamicWalletAccounts) continue;
240
+ const namespaceWalletAccounts = createWalletAccountsForWalletConnectWalletProvider({ walletProvider });
241
+ if (namespaceWalletAccounts.length === 0) continue;
242
+ for (const createdWalletAccount of namespaceWalletAccounts) {
243
+ if (!currentWalletAccounts.some((existingAccount$1) => existingAccount$1.id === createdWalletAccount.id)) {
244
+ createdWalletAccounts[createdWalletAccount.id] = createdWalletAccount;
245
+ brandNewWalletAccounts.add(createdWalletAccount.id);
246
+ continue;
247
+ }
248
+ const existingAccount = currentWalletAccounts.find((existingAccount$1) => existingAccount$1.id === createdWalletAccount.id);
249
+ if (!(existingAccount && existingAccount.walletProviderKey !== createdWalletAccount.walletProviderKey)) continue;
250
+ const existingWalletIsWalletConnect = (0, _dynamic_labs_sdk_client_core.splitWalletProviderKey)(existingAccount.walletProviderKey).walletProviderType === _dynamic_labs_sdk_api_core.WalletProviderEnum.WalletConnect;
251
+ if (allowOverridingWalletProviders || existingWalletIsWalletConnect) {
252
+ createdWalletAccounts[createdWalletAccount.id] = createdWalletAccount;
253
+ if (existingAccount.verifiedCredentialId)
254
+ /**
255
+ * A verified wallet account only arrives here when its wallet provider key is lacking the suffix,
256
+ * which should be the sessionTopic. So we just need to add its entry to the verifiedCredentialId map.
257
+ */
258
+ (0, _dynamic_labs_sdk_client_core.updateWalletProviderKeysForVerifiedCredentials)({ keysToUpdate: { [existingAccount.verifiedCredentialId]: walletProvider.key } }, client);
259
+ else unverifiedWalletAccountsToOverride.add(createdWalletAccount.id);
260
+ }
261
+ }
262
+ }
263
+ }
264
+ if (unverifiedWalletAccountsToOverride.size === 0 && brandNewWalletAccounts.size === 0) return { walletProvidersWithActiveSession };
265
+ (0, _dynamic_labs_sdk_client_core.setUnverifiedWalletAccounts)({ unverifiedWalletAccountsToUpdate: Object.values(createdWalletAccounts) }, client);
266
+ if (brandNewWalletAccounts.size > 0) for (const walletAccountId of brandNewWalletAccounts) (0, _dynamic_labs_sdk_client_core.createVisit)({ walletAccount: createdWalletAccounts[walletAccountId] }, client);
267
+ (0, _dynamic_labs_sdk_client_core.emitWalletAccountsChangedEvent)(client);
268
+ return { walletProvidersWithActiveSession };
269
+ };
270
+
271
+ //#endregion
272
+ //#region src/syncSessionsToWalletProviders/syncSessionsToWalletProviders.ts
273
+ const doSyncSessionsToWalletProviders = async ({ allowOverridingWalletProviders }, client) => {
274
+ await (0, _dynamic_labs_sdk_client_core.waitForProjectSettings)(client);
275
+ const signClient = await getSignClient(client);
276
+ const walletProviderRegistry = (0, _dynamic_labs_sdk_client_core.getWalletProviderRegistry)(client);
277
+ const sessionTopicsData = await getSessionTopicsData(client);
278
+ const sessions = signClient.session.getAll().filter((session) => {
279
+ if (sessionTopicsData[session.topic]) return true;
280
+ signClient.disconnect({
281
+ reason: _walletconnect_utils.SDK_ERRORS.USER_DISCONNECTED,
282
+ topic: session.topic
283
+ });
284
+ return false;
285
+ });
286
+ /**
287
+ * All the WC wallet providers that are currently registered
288
+ */
289
+ const currentWalletProviders = walletProviderRegistry.listProviders().filter(require_isWalletConnectWalletProvider.isWalletConnectWalletProvider);
290
+ for (const walletProvider of currentWalletProviders) if (!sessions.some((session) => session.topic === walletProvider.topic && walletProvider.namespaceKey in session.namespaces)) walletProviderRegistry.unregister(walletProvider.key);
291
+ const { walletProvidersWithActiveSession: updatedWalletProviders } = await addMissingWalletProvidersForSessions({
292
+ allowOverridingWalletProviders,
293
+ sessions
294
+ }, client);
295
+ const currentWalletAccounts = (0, _dynamic_labs_sdk_client.getWalletAccounts)(client);
296
+ /**
297
+ * Maps which sessions have wallet accounts associated with them
298
+ */
299
+ const sessionTopicHasWalletAccountMap = /* @__PURE__ */ new Map();
300
+ for (const walletProvider of updatedWalletProviders) {
301
+ const sessionTopic = walletProvider.topic;
302
+ if (!sessionTopicHasWalletAccountMap.has(sessionTopic)) sessionTopicHasWalletAccountMap.set(sessionTopic, false);
303
+ if (sessionTopicHasWalletAccountMap.get(sessionTopic)) continue;
304
+ if (currentWalletAccounts.filter((walletAccount) => walletAccount.walletProviderKey === walletProvider.key).length > 0) sessionTopicHasWalletAccountMap.set(sessionTopic, true);
305
+ }
306
+ for (const [sessionTopic, hasWalletAccount] of sessionTopicHasWalletAccountMap) {
307
+ if (hasWalletAccount || !sessionTopicsData[sessionTopic].shouldAddToDynamicWalletAccounts) continue;
308
+ const session = sessions.find((session$1) => session$1.topic === sessionTopic);
309
+ if (session) signClient.disconnect({
310
+ reason: _walletconnect_utils.SDK_ERRORS.USER_DISCONNECTED,
311
+ topic: session.topic
312
+ });
313
+ for (const walletProvider of updatedWalletProviders) if (walletProvider.topic === sessionTopic) walletProviderRegistry.unregister(walletProvider.key);
314
+ }
315
+ const activeSessionTopics = new Set(signClient.session.getAll().map((session) => session.topic));
316
+ await setSessionTopicsData({ update: (sessionTopicsData$1) => {
317
+ return Object.fromEntries(Object.entries(sessionTopicsData$1).filter(([topic]) => activeSessionTopics.has(topic)));
318
+ } }, client);
319
+ };
320
+ const syncSessionsToWalletProviders = async ({ debounceTime = 0, allowOverridingWalletProviders }, client) => {
321
+ return (0, _dynamic_labs_sdk_client_core.getCore)(client).debouncedMutex({
322
+ callback: async () => doSyncSessionsToWalletProviders({ allowOverridingWalletProviders }, client),
323
+ debounceTime,
324
+ lockKey: "wallet-connect-sync-sessions-to-wallet-providers"
325
+ });
326
+ };
327
+
328
+ //#endregion
329
+ //#region src/importWalletConnectSession/importWalletConnectSession.ts
330
+ /**
331
+ * This is a lower level function that is used to connect a WalletConnect session to the Dynamic SDK.
332
+ * It will generate the wallet providers and wallet accounts for all accounts in the session.
333
+ *
334
+ * @param session - The session object created from the approval promise of the signClient.connect method.
335
+ * @param addToDynamicWalletAccounts - Whether to add the wallet accounts to the dynamic's wallet accounts.
336
+ * @param client - The Dynamic client instance. Only required when using multiple Dynamic clients.
337
+ * @returns The wallet accounts.
338
+ */
339
+ const importWalletConnectSession = async ({ addToDynamicWalletAccounts = true, session }, client) => {
340
+ /**
341
+ * You would normally get the session from the signClient.connect method. It takes the optionalNamespaces as an argument.
342
+ *
343
+ * Each chain should build its own "connectWithWalletConnect<chain-name>" function.
344
+ * Understand how to build the optionalNamespaces object:
345
+ *
346
+ * The namespace configurations are used at the time a wallet application receives the connection URI.
347
+ * It will use the configurations we supply to understand which methods, events and networks it should provide.
348
+ *
349
+ * The wallet application will then accept the connection request and, in the session`object, provide its own namespace object
350
+ * in return, which will contain the methods, events and networks it does in fact support, as well as
351
+ * which accounts are available.
352
+ *
353
+ * WalletConnect expects namespaces defined in the following format:
354
+ * ```typescript
355
+ * {
356
+ * <namespaceKey>: {
357
+ * "accounts": ["<account1>", "<account2>", "<account3>", ...],
358
+ * "events": ["accountsChanged", "chainChanged", "disconnected"],
359
+ * "methods": ["personal_sign", "eth_sendTransaction", "eth_accounts", ...],
360
+ * "chains": ["<chain1>", "<chain2>", "<chain3>", ...]
361
+ * },
362
+ * ...
363
+ * }
364
+ * ```
365
+ *
366
+ * Where each account is a CAIP-10 formatted string, for example: "eip155:1:0x1234567890"
367
+ * — see docs: https://chainagnostic.org/CAIPs/caip-10
368
+ *
369
+ * Where each chain is a CAIP-2 formatted string, for example: "eip155:1"
370
+ * — see docs: https://chainagnostic.org/CAIPs/caip-2
371
+ */
372
+ const sessionData = { shouldAddToDynamicWalletAccounts: addToDynamicWalletAccounts };
373
+ await setSessionTopicsData({ update: (sessionTopicsData) => ({
374
+ ...sessionTopicsData,
375
+ [session.topic]: sessionData
376
+ }) }, client);
377
+ /**
378
+ * Once the connection is established, we ensure that all active connections (aka sessions)
379
+ * are synced to our WalletConnect wallet providers.
380
+ * Each session can be uniquely identified by its topic (a random string generated by WalletConnect).
381
+ *
382
+ * Each session may have multiple wallet providers, one for each namespace (aka our SDK chains)
383
+ */
384
+ await syncSessionsToWalletProviders({ allowOverridingWalletProviders: true }, client);
385
+ const sessionWalletProviders = (0, _dynamic_labs_sdk_client_core.getWalletProviders)(client).filter(require_isWalletConnectWalletProvider.isWalletConnectWalletProvider).filter((provider) => provider.topic === session.topic);
386
+ /**
387
+ * Upon setting the session data to NOT externally owned, syncSessionsToWalletProviders will have
388
+ * already created the wallet accounts for each of this session's wallet providers — so all we need
389
+ * to do is retrieve them.
390
+ */
391
+ if (addToDynamicWalletAccounts) {
392
+ const sessionWalletProviderKeys = sessionWalletProviders.map((provider) => provider.key);
393
+ return { walletAccounts: (0, _dynamic_labs_sdk_client.getWalletAccounts)(client).filter((walletAccount) => sessionWalletProviderKeys.includes(walletAccount.walletProviderKey)) };
394
+ }
395
+ return { walletAccounts: sessionWalletProviders.map((walletProvider) => createWalletAccountsForWalletConnectWalletProvider({ walletProvider })).flat() };
396
+ };
397
+
398
+ //#endregion
399
+ //#region src/importWalletConnectAuthResponse/verifyWalletConnectAuths/verifyWalletConnectAuths.ts
400
+ const getAddressFromIss = (iss) => iss.split(":")[4];
401
+ const verifyWalletConnectAuths = async ({ auths, chain, walletDisplayName }, client) => {
402
+ /**
403
+ * The only differences between each auth object will be the signature (auth.s.s)
404
+ * and the iss (auth.p.iss).
405
+ *
406
+ * The iss is comprised of 2 WC fields that are irrelevant to us and then the CAIP-10 token
407
+ * of the address, where the first 2 fields are also split by the ":" character.
408
+ *
409
+ * Usually, there will be multiple auths if the wallet app bundles signatures for multiple
410
+ * networks at once, so the only field that will change among auth iss will be the networkId under iss.
411
+ */
412
+ const visitedAddresses = /* @__PURE__ */ new Set();
413
+ const authsFilteredByAddress = auths.filter((auth) => {
414
+ const address = getAddressFromIss(auth.p.iss);
415
+ if (!address || visitedAddresses.has(address)) return false;
416
+ visitedAddresses.add(address);
417
+ return true;
418
+ });
419
+ let lastResponse = void 0;
420
+ /**
421
+ * WalletConnect's auth object is what they call a "Cacao" object, with data on the SIWE message
422
+ * and the signature itself.
423
+ * By consulting how they implemented their "validateSignedCacao" function,
424
+ * we are able to reconstruct the original message which can be used to verify the signature
425
+ * in our backend.
426
+ */
427
+ for (const auth of authsFilteredByAddress) {
428
+ const publicWalletAddress = getAddressFromIss(auth.p.iss);
429
+ (0, _dynamic_labs_sdk_client_core.assertDefined)(publicWalletAddress, `Unable to get public wallet address from WalletConnect Cacao object iss: ${auth.p.iss}`);
430
+ const messageToSign = (0, _walletconnect_utils.formatMessage)(auth.p, auth.p.iss);
431
+ const signature = auth.s.s;
432
+ lastResponse = await (0, _dynamic_labs_sdk_client_core.verifyMessageSignatureOwnership)({
433
+ chain,
434
+ messageToSign,
435
+ signature,
436
+ walletAddress: publicWalletAddress,
437
+ walletDisplayName,
438
+ walletProviderType: _dynamic_labs_sdk_api_core.WalletProviderEnum.WalletConnect
439
+ }, client);
440
+ }
441
+ if (!lastResponse) return;
442
+ /**
443
+ * Adds the user with the new wallet verified credentials
444
+ * This will add the new verified wallet accounts to the client`s state
445
+ */
446
+ (0, _dynamic_labs_sdk_client_core.updateAuthFromVerifyResponse)({ response: lastResponse }, client);
447
+ };
448
+
449
+ //#endregion
450
+ //#region src/importWalletConnectAuthResponse/importWalletConnectAuthResponse.ts
451
+ /**
452
+ * A low level function that is used to connect a WalletConnect authenticate response to the Dynamic SDK.
453
+ * It will generate the wallet providers and wallet accounts for all accounts in the session.
454
+ *
455
+ * @see WalletConnect's docs on [session authentication](https://docs.reown.com/advanced/api/sign/dapp-usage#session-authenticate-with-recaps)
456
+ * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
457
+ * @returns A promise that resolves to the connected and verified wallet account.
458
+ */
459
+ const importWalletConnectAuthResponse = async ({ authResponse, chain }, client) => {
460
+ const { session, auths } = authResponse;
461
+ /**
462
+ * Some wallets do not support WC's authenticate method (such as Rainbow).
463
+ * For these wallets, the authenticate method will act as a regular connect method.
464
+ * Therefore we must call verify individually.
465
+ */
466
+ if (!auths || auths.length === 0) {
467
+ /**
468
+ * Set addToDynamicWalletAccounts to false to avoid adding the wallet accounts to the dynamic's wallet accounts
469
+ * while we are still verifying them.
470
+ * After verifying, we set addToDynamicWalletAccounts back to true.
471
+ */
472
+ const { walletAccounts: walletAccounts$1 } = await importWalletConnectSession({
473
+ addToDynamicWalletAccounts: false,
474
+ session
475
+ }, client);
476
+ for (const walletAccount of walletAccounts$1) await (0, _dynamic_labs_sdk_client.verifyWalletAccount)({ walletAccount }, client);
477
+ await setSessionTopicsData({ update: (sessionTopicsData) => ({
478
+ ...sessionTopicsData,
479
+ [session.topic]: { shouldAddToDynamicWalletAccounts: true }
480
+ }) }, client);
481
+ return { walletAccounts: walletAccounts$1 };
482
+ }
483
+ /**
484
+ * This reconstructs the message that was signed by the wallet and verifies the signature
485
+ * in the backend. It will update the user with the new verified credentials.
486
+ */
487
+ await verifyWalletConnectAuths({
488
+ auths,
489
+ chain,
490
+ walletDisplayName: session.peer.metadata.name
491
+ }, client);
492
+ const { walletAccounts } = await importWalletConnectSession({
493
+ addToDynamicWalletAccounts: true,
494
+ session
495
+ }, client);
496
+ (0, _dynamic_labs_sdk_client_core.updateWalletProviderKeysForVerifiedCredentials)({ keysToUpdate: Object.fromEntries(walletAccounts.map((walletAccount) => {
497
+ const { verifiedCredentialId } = walletAccount;
498
+ (0, _dynamic_labs_sdk_client_core.assertDefined)(verifiedCredentialId, `Wallet account of ID ${walletAccount.id} still has no verified credential after being verified`);
499
+ return [verifiedCredentialId, walletAccount.walletProviderKey];
500
+ })) }, client);
501
+ return { walletAccounts };
502
+ };
503
+
504
+ //#endregion
505
+ //#region src/sessionTopicsData/clearTemporarySessions/clearTemporarySessions.ts
506
+ /**
507
+ * Clears all temporary sessions and disconnects from them.
508
+ *
509
+ * External sessions are for WC sessions whose accounts are not supposed to be saved in
510
+ * the current dynamic's wallet accounts.
511
+ * Since we don't own the created wallet accounts, we must keep their corresponding WC sessions alive
512
+ * until the page is refreshed or the customer removes the wallet account.
513
+ *
514
+ * @param client - The client instance.
515
+ */
516
+ const clearTemporarySessions = async (client) => {
517
+ const signClient = await getSignClient(client);
518
+ const sessionTopicsData = await getSessionTopicsData(client);
519
+ const temporarySessionTopics = Object.keys(sessionTopicsData).filter((topic) => !sessionTopicsData[topic].shouldAddToDynamicWalletAccounts);
520
+ if (temporarySessionTopics.length === 0) return;
521
+ for (const topic of temporarySessionTopics) await signClient.disconnect({
522
+ reason: _walletconnect_utils.SDK_ERRORS.USER_DISCONNECTED,
523
+ topic
524
+ });
525
+ const newSessionTopicsData = Object.fromEntries(Object.entries(sessionTopicsData).filter(([, { shouldAddToDynamicWalletAccounts: isPermanentSession }]) => isPermanentSession));
526
+ await setSessionTopicsData({ update: () => newSessionTopicsData }, client);
527
+ };
528
+
529
+ //#endregion
530
+ //#region src/initializeWalletConnectExtension/initializeWalletConnectExtension.ts
531
+ const initializeWalletConnectExtension = async (client) => {
532
+ await clearTemporarySessions(client);
533
+ await syncSessionsToWalletProviders({
534
+ allowOverridingWalletProviders: false,
535
+ debounceTime: 200
536
+ }, client);
537
+ };
538
+
539
+ //#endregion
540
+ //#region src/exports/core.ts
541
+ (0, _dynamic_labs_sdk_assert_package_version.assertPackageVersion)(require_isWalletConnectWalletProvider.name, require_isWalletConnectWalletProvider.version);
542
+
543
+ //#endregion
544
+ exports.__toESM = __toESM;
545
+ exports.getNamespaceRegistry = getNamespaceRegistry;
546
+ exports.getSignClient = getSignClient;
547
+ exports.importWalletConnectAuthResponse = importWalletConnectAuthResponse;
548
+ exports.importWalletConnectSession = importWalletConnectSession;
549
+ exports.initializeWalletConnectExtension = initializeWalletConnectExtension;
550
+ exports.splitCaip10Token = splitCaip10Token;
551
+ exports.syncSessionsToWalletProviders = syncSessionsToWalletProviders;
552
+ //# sourceMappingURL=core.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.cjs.js","names":["z","SignClient","isWalletConnectWalletProvider","walletProvidersWithActiveSession: WalletConnectWalletProvider[]","createdWalletAccounts: Record<string, WalletAccount>","walletProvider","WalletProviderPriority","existingAccount","WalletProviderEnum","SDK_ERRORS","isWalletConnectWalletProvider","session","sessionTopicsData","sessionData: SessionTopicsData[string]","isWalletConnectWalletProvider","lastResponse: VerifyResponse | undefined","WalletProviderEnum","walletAccounts","SDK_ERRORS","name","version"],"sources":["../src/splitCaip10Token/splitCaip10Token.ts","../src/createWalletAccountsForWalletConnectWalletProvider/createWalletAccountsForWalletConnectWalletProvider.ts","../src/sessionTopicsData/schema.ts","../src/sessionTopicsData/setSessionTopicsData/setSessionTopicsData.ts","../src/sessionTopicsData/getSessionTopicsData/getSessionTopicsData.ts","../src/signClient/getSignClient/createSignClient/createSignClient.ts","../src/signClient/getSignClient/getSignClient.ts","../src/namespaceRegistry/getNamespaceRegistry/createNamespaceRegistry/createNamespaceRegistry.ts","../src/namespaceRegistry/getNamespaceRegistry/getNamespaceRegistry.ts","../src/syncSessionsToWalletProviders/addMissingWalletProvidersForSessions/addMissingWalletProvidersForSessions.ts","../src/syncSessionsToWalletProviders/syncSessionsToWalletProviders.ts","../src/importWalletConnectSession/importWalletConnectSession.ts","../src/importWalletConnectAuthResponse/verifyWalletConnectAuths/verifyWalletConnectAuths.ts","../src/importWalletConnectAuthResponse/importWalletConnectAuthResponse.ts","../src/sessionTopicsData/clearTemporarySessions/clearTemporarySessions.ts","../src/initializeWalletConnectExtension/initializeWalletConnectExtension.ts","../src/exports/core.ts"],"sourcesContent":["/**\n * An account in WalletConnect follows the CAIP-10 standard\n * and is formatted as follows:\n *\n * `<namespace>:<chain>:<address>`\n *\n * Where:\n * - `<namespace>` is the namespace key (e.g. \"eip155\")\n * - `<chain>` is what we refer to as a network ID (e.g. \"1\")\n * - `<address>` is the address of the account (e.g. \"0x1234567890\")\n *\n * See docs: https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md\n *\n * @returns An object with the address, namespace key, and network id\n */\nexport const splitCaip10Token = (caip10Token: string) => {\n const [namespaceKey, networkId, address] = caip10Token.split(':');\n return { address, namespaceKey, networkId };\n};\n","import { type WalletAccount } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n filterDuplicates,\n formatWalletAccountId,\n} from '@dynamic-labs-sdk/client/core';\n\nimport { splitCaip10Token } from '../splitCaip10Token';\nimport type { WalletConnectWalletProvider } from '../walletConnectWalletProvider.types';\n\ntype CreateWalletAccountsForWalletConnectWalletProviderParams = {\n walletProvider: WalletConnectWalletProvider;\n};\n\nexport const createWalletAccountsForWalletConnectWalletProvider = ({\n walletProvider,\n}: CreateWalletAccountsForWalletConnectWalletProviderParams): WalletAccount[] => {\n /**\n * Since each session can have multiple namespaces, we need to find the namespace\n * that corresponds to this specific wallet provider.\n *\n * A WalletConnect namespace is the equivalent of what we refer to as a chain in the SDK,\n * and they have attributed to them the methods, events and networks that are expected\n * to be supported by the wallet application, as well as which accounts are connected.\n */\n const namespace =\n walletProvider.session.namespaces[walletProvider.namespaceKey];\n\n assertDefined(\n namespace,\n `Namespace key ${walletProvider.namespaceKey} of wallet provider ${walletProvider.key} not found in its session ${walletProvider.topic}`\n );\n\n const accountAddresses = filterDuplicates(\n namespace.accounts.map((account) => splitCaip10Token(account).address)\n );\n\n const formatAddress =\n walletProvider.formatWalletAddress ?? (({ address }) => address);\n\n return accountAddresses.map((address) => ({\n address: formatAddress({ address }),\n chain: walletProvider.chain,\n id: formatWalletAccountId({\n address,\n chain: walletProvider.chain,\n walletProviderKey: walletProvider.key,\n }),\n lastSelectedAt: null,\n verifiedCredentialId: null,\n walletProviderKey: walletProvider.key,\n }));\n};\n","import { createStorageKeySchema } from '@dynamic-labs-sdk/client/core';\nimport * as z from 'zod/mini';\n\nexport const sessionTopicsStorageKeySchema = createStorageKeySchema({\n key: 'sessionTopics',\n schema: z.record(\n /**\n * The session topic that identifies this session.\n */\n z.string(),\n\n /**\n * The session data.\n */\n z.object({\n /**\n * Whether this session's wallet accounts should be added to the dynamic's wallet accounts.\n * When a customer connects a session with addToDynamicWalletAccounts set to false, the resulting session\n * should not produce wallet accounts to be added to the dynamic's wallet accounts.\n * When that happens, we cannot clear them until the page is refreshed or the wallet account is removed\n * by the external owner by calling removeWalletAccount.\n */\n shouldAddToDynamicWalletAccounts: z.boolean(),\n })\n ),\n});\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { getCore } from '@dynamic-labs-sdk/client/core';\n\nimport { sessionTopicsStorageKeySchema } from '../schema';\nimport type { SessionTopicsData } from '../sessionTopicsData.types';\n\ntype SetSessionTopicsDataParams = {\n update: (topics: SessionTopicsData) => SessionTopicsData;\n};\n\n/**\n * Sets the session topics data.\n *\n * Read more about it in the sessionTopicsData.types.ts file.\n *\n * @param update - The function to update the session topics data.\n * @param client - The client instance.\n */\nexport const setSessionTopicsData = async (\n { update }: SetSessionTopicsDataParams,\n client: DynamicClient\n) => {\n const { storage } = getCore(client);\n\n const sessionTopicsData = await storage.getItem(\n sessionTopicsStorageKeySchema\n );\n\n const newSessionTopicsData = update(sessionTopicsData ?? {});\n\n if (Object.keys(newSessionTopicsData).length === 0) {\n return storage.removeItem(sessionTopicsStorageKeySchema);\n }\n\n return storage.setItem(sessionTopicsStorageKeySchema, newSessionTopicsData);\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { getCore } from '@dynamic-labs-sdk/client/core';\n\nimport { sessionTopicsStorageKeySchema } from '../schema';\n\n/**\n * Gets the session topics data.\n *\n * Read more about it in the sessionTopicsData.types.ts file.\n * @param client - The client instance.\n */\nexport const getSessionTopicsData = async (client: DynamicClient) => {\n const { storage } = getCore(client);\n\n const sessionTopicsData = await storage.getItem(\n sessionTopicsStorageKeySchema\n );\n\n return sessionTopicsData ?? {};\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { assertDefined, getCore } from '@dynamic-labs-sdk/client/core';\nimport SignClient from '@walletconnect/sign-client';\n\nexport const createSignClient = async (client: DynamicClient) => {\n const core = getCore(client);\n\n assertDefined(client.projectSettings, 'Project settings not available');\n\n const generalSettings = client.projectSettings.general;\n\n assertDefined(\n generalSettings.displayName,\n 'Please configure an app name in dashboard to use WalletConnect'\n );\n\n const projectId = client.projectSettings.sdk.walletConnect?.projectId;\n\n assertDefined(\n projectId,\n 'Please configure a project ID for WalletConnect in dashboard'\n );\n\n const customStoragePrefix = `dynamic_${core.environmentId}_walletconnect`;\n\n const displayName = core.metadata?.name ?? generalSettings.displayName;\n\n const appLogo = core.metadata?.iconUrl ?? generalSettings.appLogo;\n\n return SignClient.init({\n customStoragePrefix,\n metadata: {\n description: '',\n icons: appLogo ? [appLogo] : [],\n name: displayName,\n url: '',\n },\n projectId,\n });\n};\n","import { createRuntimeServiceAccessKey } from '@dynamic-labs-sdk/client/core';\n\nimport { createSignClient } from './createSignClient';\n\nexport const getSignClient = createRuntimeServiceAccessKey(\n 'walletConnectSignClient',\n (client) => createSignClient(client)\n);\n","import type { WalletProviderBuilder } from '../../../walletConnectWalletProvider.types';\nimport type { NamespaceRegistry } from '../../namespaceRegistry.types';\n\nexport const createNamespaceRegistry = (): NamespaceRegistry => {\n const walletProviderBuilderMap = new Map<string, WalletProviderBuilder>();\n\n return {\n getWalletProviderBuilder: (key) => walletProviderBuilderMap.get(key),\n\n registerNamespace: ({ createWalletProviderFromSession, namespaceKey }) => {\n walletProviderBuilderMap.set(\n namespaceKey,\n createWalletProviderFromSession\n );\n },\n };\n};\n","import { createRuntimeServiceAccessKey } from '@dynamic-labs-sdk/client/core';\n\nimport { createNamespaceRegistry } from './createNamespaceRegistry';\n\nexport const getNamespaceRegistry = createRuntimeServiceAccessKey(\n 'walletConnectNamespaceRegistry',\n createNamespaceRegistry\n);\n","import type { WalletAccount } from '@dynamic-labs-sdk/client';\nimport {\n type DynamicClient,\n getWalletAccounts,\n} from '@dynamic-labs-sdk/client';\nimport {\n WalletProviderPriority,\n createVisit,\n emitWalletAccountsChangedEvent,\n getWalletProviderRegistry,\n setUnverifiedWalletAccounts,\n splitWalletProviderKey,\n updateWalletProviderKeysForVerifiedCredentials,\n} from '@dynamic-labs-sdk/client/core';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\nimport type { SessionTypes } from '@walletconnect/types';\n\nimport { createWalletAccountsForWalletConnectWalletProvider } from '../../createWalletAccountsForWalletConnectWalletProvider';\nimport { isWalletConnectWalletProvider } from '../../isWalletConnectWalletProvider';\nimport { getNamespaceRegistry } from '../../namespaceRegistry';\nimport { getSessionTopicsData } from '../../sessionTopicsData/getSessionTopicsData';\nimport type { WalletConnectWalletProvider } from '../../walletConnectWalletProvider.types';\n\ntype AddMissingWalletProvidersForSessionsParams = {\n allowOverridingWalletProviders: boolean;\n sessions: SessionTypes.Struct[];\n};\n\nexport const addMissingWalletProvidersForSessions = async (\n {\n sessions,\n allowOverridingWalletProviders,\n }: AddMissingWalletProvidersForSessionsParams,\n client: DynamicClient\n): Promise<{\n walletProvidersWithActiveSession: WalletConnectWalletProvider[];\n}> => {\n const namespaceRegistry = getNamespaceRegistry(client);\n const walletProviderRegistry = getWalletProviderRegistry(client);\n const sessionTopicsData = await getSessionTopicsData(client);\n const currentWalletAccounts = getWalletAccounts(client);\n\n // Sort so the oldest sessions are first and the newer sessions will\n // override the older ones' wallet accounts (if there is any overlap).\n sessions.sort((sessionA, sessionB) => sessionA.expiry - sessionB.expiry);\n\n /**\n * All the WC wallet providers that are currently registered\n */\n const currentWalletProviders = walletProviderRegistry\n .listProviders()\n .filter(isWalletConnectWalletProvider);\n\n /**\n * Keep record on which walletProviders are tied to active sessions\n */\n const walletProvidersWithActiveSession: WalletConnectWalletProvider[] = [];\n\n /**\n * Maps the ID of the created wallet accounts to the wallet accounts themselves.\n */\n const createdWalletAccounts: Record<string, WalletAccount> = {};\n\n /**\n * Keep record on which wallet account IDs were not in the current wallet accounts\n * and are therefore brand new.\n */\n const brandNewWalletAccounts = new Set<string>();\n\n /**\n * Keep record on which wallet account IDs already exist but will have\n * their wallet provider keys overridden to use the new WC wallet provider key.\n *\n * This will only ever be the case for unverified wallet accounts, however. That is\n * because verified wallets will already override the wallet provider key on the verification\n * step, which happens at the call to verifyWalletConnectAuths, which happens before this function.\n */\n const unverifiedWalletAccountsToOverride = new Set<string>();\n\n for (const session of sessions) {\n const namespaceKeys = Object.keys(session.namespaces);\n\n for (const namespaceKey of namespaceKeys) {\n const existingWalletProvider = currentWalletProviders.find(\n (walletProvider) =>\n walletProvider.namespaceKey === namespaceKey &&\n walletProvider.topic === session.topic\n );\n\n if (existingWalletProvider) {\n walletProvidersWithActiveSession.push(existingWalletProvider);\n\n continue;\n }\n\n const walletProviderBuilder =\n namespaceRegistry.getWalletProviderBuilder(namespaceKey);\n\n /**\n * There being no wallet provider builder for this namespace simply means the customer\n * didn't add an extension for the corresponding chain.\n * For instance, if we get a namespace for Solana but only have an Evm extension,\n * the solana namespace would fall here. No need to throw.\n */\n if (!walletProviderBuilder) {\n continue;\n }\n\n const walletProvider = await walletProviderBuilder({ session }, client);\n\n walletProviderRegistry.register({\n priority: WalletProviderPriority.WALLET_SDK,\n walletProvider,\n });\n\n walletProvidersWithActiveSession.push(walletProvider);\n\n const sessionData = sessionTopicsData[session.topic];\n\n if (!sessionData.shouldAddToDynamicWalletAccounts) {\n continue;\n }\n\n const namespaceWalletAccounts =\n createWalletAccountsForWalletConnectWalletProvider({\n walletProvider,\n });\n\n if (namespaceWalletAccounts.length === 0) {\n continue;\n }\n\n for (const createdWalletAccount of namespaceWalletAccounts) {\n const isBrandNew = !currentWalletAccounts.some(\n (existingAccount) => existingAccount.id === createdWalletAccount.id\n );\n\n if (isBrandNew) {\n createdWalletAccounts[createdWalletAccount.id] = createdWalletAccount;\n brandNewWalletAccounts.add(createdWalletAccount.id);\n\n continue;\n }\n\n const existingAccount = currentWalletAccounts.find(\n (existingAccount) => existingAccount.id === createdWalletAccount.id\n );\n\n const isOverrideCandidate =\n existingAccount &&\n existingAccount.walletProviderKey !==\n createdWalletAccount.walletProviderKey;\n\n if (!isOverrideCandidate) {\n continue;\n }\n\n // If overriding wallet providers is not allowed, we can still override\n // as long as the wallet account being overridden is also a wallet connect wallet account.\n const existingWalletIsWalletConnect =\n splitWalletProviderKey(existingAccount.walletProviderKey)\n .walletProviderType === WalletProviderEnum.WalletConnect;\n\n if (allowOverridingWalletProviders || existingWalletIsWalletConnect) {\n createdWalletAccounts[createdWalletAccount.id] = createdWalletAccount;\n\n if (existingAccount.verifiedCredentialId) {\n /**\n * A verified wallet account only arrives here when its wallet provider key is lacking the suffix,\n * which should be the sessionTopic. So we just need to add its entry to the verifiedCredentialId map.\n */\n\n updateWalletProviderKeysForVerifiedCredentials(\n {\n keysToUpdate: {\n [existingAccount.verifiedCredentialId]: walletProvider.key,\n },\n },\n client\n );\n } else {\n unverifiedWalletAccountsToOverride.add(createdWalletAccount.id);\n }\n }\n }\n }\n }\n\n if (\n unverifiedWalletAccountsToOverride.size === 0 &&\n brandNewWalletAccounts.size === 0\n ) {\n return { walletProvidersWithActiveSession };\n }\n\n setUnverifiedWalletAccounts(\n {\n unverifiedWalletAccountsToUpdate: Object.values(createdWalletAccounts),\n },\n client\n );\n\n if (brandNewWalletAccounts.size > 0) {\n for (const walletAccountId of brandNewWalletAccounts) {\n void createVisit(\n { walletAccount: createdWalletAccounts[walletAccountId] },\n client\n );\n }\n }\n\n emitWalletAccountsChangedEvent(client);\n\n return { walletProvidersWithActiveSession };\n};\n","import {\n type DynamicClient,\n getWalletAccounts,\n} from '@dynamic-labs-sdk/client';\nimport {\n getCore,\n getWalletProviderRegistry,\n waitForProjectSettings,\n} from '@dynamic-labs-sdk/client/core';\nimport { SDK_ERRORS } from '@walletconnect/utils';\n\nimport { isWalletConnectWalletProvider } from '../isWalletConnectWalletProvider';\nimport { getSessionTopicsData } from '../sessionTopicsData/getSessionTopicsData';\nimport { setSessionTopicsData } from '../sessionTopicsData/setSessionTopicsData';\nimport { getSignClient } from '../signClient/getSignClient';\nimport { addMissingWalletProvidersForSessions } from './addMissingWalletProvidersForSessions';\n\ntype DoSyncSessionsToWalletProvidersParams = {\n allowOverridingWalletProviders: boolean;\n};\n\nconst doSyncSessionsToWalletProviders = async (\n { allowOverridingWalletProviders }: DoSyncSessionsToWalletProvidersParams,\n client: DynamicClient\n) => {\n await waitForProjectSettings(client);\n\n const signClient = await getSignClient(client);\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n const sessionTopicsData = await getSessionTopicsData(client);\n\n const sessions = signClient.session.getAll().filter((session) => {\n if (sessionTopicsData[session.topic]) {\n return true;\n }\n\n // If we don't have data for this session, it is corrupted and we need to disconnect\n void signClient.disconnect({\n reason: SDK_ERRORS.USER_DISCONNECTED,\n topic: session.topic,\n });\n\n return false;\n });\n\n /**\n * All the WC wallet providers that are currently registered\n */\n const currentWalletProviders = walletProviderRegistry\n .listProviders()\n .filter(isWalletConnectWalletProvider);\n\n // Step 1: remove wallet providers whose sessions have been cleared\n for (const walletProvider of currentWalletProviders) {\n const hasSession = sessions.some(\n (session) =>\n session.topic === walletProvider.topic &&\n walletProvider.namespaceKey in session.namespaces\n );\n\n if (!hasSession) {\n walletProviderRegistry.unregister(walletProvider.key);\n }\n }\n\n // Step 2: add wallet providers that are missing for current sessions\n const { walletProvidersWithActiveSession: updatedWalletProviders } =\n await addMissingWalletProvidersForSessions(\n {\n allowOverridingWalletProviders,\n sessions,\n },\n client\n );\n\n // Step 3: identify which sessions have no more associated wallet accounts for clean up\n const currentWalletAccounts = getWalletAccounts(client);\n\n /**\n * Maps which sessions have wallet accounts associated with them\n */\n const sessionTopicHasWalletAccountMap = new Map<string, boolean>();\n\n for (const walletProvider of updatedWalletProviders) {\n const sessionTopic = walletProvider.topic;\n\n if (!sessionTopicHasWalletAccountMap.has(sessionTopic)) {\n sessionTopicHasWalletAccountMap.set(sessionTopic, false);\n }\n\n // Early return if we already know this session has wallet accounts associated with it\n if (sessionTopicHasWalletAccountMap.get(sessionTopic)) {\n continue;\n }\n\n const walletProviderWalletAccounts = currentWalletAccounts.filter(\n (walletAccount) => walletAccount.walletProviderKey === walletProvider.key\n );\n\n if (walletProviderWalletAccounts.length > 0) {\n sessionTopicHasWalletAccountMap.set(sessionTopic, true);\n }\n }\n\n // Step 4: kill sessions and their wallet providers if they have no more wallet accounts\n // Ignore sessions that are NOT marked as shouldAddToDynamicWalletAccounts\n for (const [\n sessionTopic,\n hasWalletAccount,\n ] of sessionTopicHasWalletAccountMap) {\n if (\n hasWalletAccount ||\n !sessionTopicsData[sessionTopic].shouldAddToDynamicWalletAccounts\n ) {\n continue;\n }\n\n const session = sessions.find((session) => session.topic === sessionTopic);\n\n if (session) {\n void signClient.disconnect({\n reason: SDK_ERRORS.USER_DISCONNECTED,\n topic: session.topic,\n });\n }\n\n for (const walletProvider of updatedWalletProviders) {\n if (walletProvider.topic === sessionTopic) {\n walletProviderRegistry.unregister(walletProvider.key);\n }\n }\n }\n\n // Step 5: compile which session topics are active to clean up stale session data\n // We do session.getAll() again here to catch any sessions that might have been disconnected from other steps or even externally.\n const activeSessionTopics = new Set(\n signClient.session.getAll().map((session) => session.topic)\n );\n\n await setSessionTopicsData(\n {\n update: (sessionTopicsData) => {\n return Object.fromEntries(\n Object.entries(sessionTopicsData).filter(([topic]) =>\n activeSessionTopics.has(topic)\n )\n );\n },\n },\n client\n );\n};\n\ntype SyncSessionsToWalletProvidersParams = {\n allowOverridingWalletProviders: boolean;\n debounceTime?: number;\n};\n\nexport const syncSessionsToWalletProviders = async (\n {\n debounceTime = 0,\n allowOverridingWalletProviders,\n }: SyncSessionsToWalletProvidersParams,\n client: DynamicClient\n) => {\n const core = getCore(client);\n\n // This is called on adding WC extensions, which could be many in quick succession, so let's debounce\n // the syncSessionsToWalletProviders call to ensure it only runs once and avoid race conditions.\n return core.debouncedMutex({\n callback: async () =>\n doSyncSessionsToWalletProviders(\n { allowOverridingWalletProviders },\n client\n ),\n debounceTime,\n lockKey: 'wallet-connect-sync-sessions-to-wallet-providers',\n });\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport {\n type WalletAccount,\n getWalletAccounts,\n} from '@dynamic-labs-sdk/client';\nimport { getWalletProviders } from '@dynamic-labs-sdk/client/core';\nimport type { SessionTypes } from '@walletconnect/types';\n\nimport { createWalletAccountsForWalletConnectWalletProvider } from '../createWalletAccountsForWalletConnectWalletProvider';\nimport { isWalletConnectWalletProvider } from '../isWalletConnectWalletProvider';\nimport type { SessionTopicsData } from '../sessionTopicsData/sessionTopicsData.types';\nimport { setSessionTopicsData } from '../sessionTopicsData/setSessionTopicsData';\nimport { syncSessionsToWalletProviders } from '../syncSessionsToWalletProviders';\n\ntype ImportWalletConnectSessionParams = {\n /**\n * Whether this session's wallet accounts should be added to the dynamic's wallet accounts.\n */\n addToDynamicWalletAccounts?: boolean;\n\n /**\n * The session object created from the approval promise of the signClient.connect method.\n */\n session: SessionTypes.Struct;\n};\n\n/**\n * This is a lower level function that is used to connect a WalletConnect session to the Dynamic SDK.\n * It will generate the wallet providers and wallet accounts for all accounts in the session.\n *\n * @param session - The session object created from the approval promise of the signClient.connect method.\n * @param addToDynamicWalletAccounts - Whether to add the wallet accounts to the dynamic's wallet accounts.\n * @param client - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns The wallet accounts.\n */\nexport const importWalletConnectSession = async (\n {\n addToDynamicWalletAccounts = true,\n session,\n }: ImportWalletConnectSessionParams,\n client: DynamicClient\n): Promise<{ walletAccounts: WalletAccount[] }> => {\n /**\n * You would normally get the session from the signClient.connect method. It takes the optionalNamespaces as an argument.\n *\n * Each chain should build its own \"connectWithWalletConnect<chain-name>\" function.\n * Understand how to build the optionalNamespaces object:\n *\n * The namespace configurations are used at the time a wallet application receives the connection URI.\n * It will use the configurations we supply to understand which methods, events and networks it should provide.\n *\n * The wallet application will then accept the connection request and, in the session`object, provide its own namespace object\n * in return, which will contain the methods, events and networks it does in fact support, as well as\n * which accounts are available.\n *\n * WalletConnect expects namespaces defined in the following format:\n * ```typescript\n * {\n * <namespaceKey>: {\n * \"accounts\": [\"<account1>\", \"<account2>\", \"<account3>\", ...],\n * \"events\": [\"accountsChanged\", \"chainChanged\", \"disconnected\"],\n * \"methods\": [\"personal_sign\", \"eth_sendTransaction\", \"eth_accounts\", ...],\n * \"chains\": [\"<chain1>\", \"<chain2>\", \"<chain3>\", ...]\n * },\n * ...\n * }\n * ```\n *\n * Where each account is a CAIP-10 formatted string, for example: \"eip155:1:0x1234567890\"\n * — see docs: https://chainagnostic.org/CAIPs/caip-10\n *\n * Where each chain is a CAIP-2 formatted string, for example: \"eip155:1\"\n * — see docs: https://chainagnostic.org/CAIPs/caip-2\n */\n\n const sessionData: SessionTopicsData[string] = {\n shouldAddToDynamicWalletAccounts: addToDynamicWalletAccounts,\n };\n\n await setSessionTopicsData(\n {\n update: (sessionTopicsData) => ({\n ...sessionTopicsData,\n [session.topic]: sessionData,\n }),\n },\n client\n );\n\n /**\n * Once the connection is established, we ensure that all active connections (aka sessions)\n * are synced to our WalletConnect wallet providers.\n * Each session can be uniquely identified by its topic (a random string generated by WalletConnect).\n *\n * Each session may have multiple wallet providers, one for each namespace (aka our SDK chains)\n */\n await syncSessionsToWalletProviders(\n { allowOverridingWalletProviders: true },\n client\n );\n\n const sessionWalletProviders = getWalletProviders(client)\n .filter(isWalletConnectWalletProvider)\n .filter((provider) => provider.topic === session.topic);\n\n /**\n * Upon setting the session data to NOT externally owned, syncSessionsToWalletProviders will have\n * already created the wallet accounts for each of this session's wallet providers — so all we need\n * to do is retrieve them.\n */\n if (addToDynamicWalletAccounts) {\n const sessionWalletProviderKeys = sessionWalletProviders.map(\n (provider) => provider.key\n );\n\n const walletAccounts = getWalletAccounts(client).filter((walletAccount) =>\n sessionWalletProviderKeys.includes(walletAccount.walletProviderKey)\n );\n\n return { walletAccounts };\n }\n\n /**\n * If we didn't add the wallet accounts to the dynamic's wallet accounts,\n * we never created them at all, so we need to create them now and provide\n * them to the caller, which will become their [external] owner.\n */\n const walletAccounts = sessionWalletProviders\n .map((walletProvider) =>\n createWalletAccountsForWalletConnectWalletProvider({ walletProvider })\n )\n .flat();\n\n return { walletAccounts };\n};\n","import type {\n Chain,\n DynamicClient,\n VerifyResponse,\n} from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n updateAuthFromVerifyResponse,\n verifyMessageSignatureOwnership,\n} from '@dynamic-labs-sdk/client/core';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\nimport type { AuthTypes } from '@walletconnect/types';\nimport { formatMessage } from '@walletconnect/utils';\n\nconst getAddressFromIss = (iss: string) => iss.split(':')[4];\n\ntype VerifyWalletConnectAuthsParams = {\n auths: AuthTypes.Cacao[];\n chain: Chain;\n walletDisplayName: string;\n};\n\nexport const verifyWalletConnectAuths = async (\n { auths, chain, walletDisplayName }: VerifyWalletConnectAuthsParams,\n client: DynamicClient\n) => {\n /**\n * The only differences between each auth object will be the signature (auth.s.s)\n * and the iss (auth.p.iss).\n *\n * The iss is comprised of 2 WC fields that are irrelevant to us and then the CAIP-10 token\n * of the address, where the first 2 fields are also split by the \":\" character.\n *\n * Usually, there will be multiple auths if the wallet app bundles signatures for multiple\n * networks at once, so the only field that will change among auth iss will be the networkId under iss.\n */\n const visitedAddresses = new Set<string>();\n\n const authsFilteredByAddress = auths.filter((auth) => {\n const address = getAddressFromIss(auth.p.iss);\n\n if (!address || visitedAddresses.has(address)) {\n return false;\n }\n\n visitedAddresses.add(address);\n\n return true;\n });\n\n let lastResponse: VerifyResponse | undefined = undefined;\n\n /**\n * WalletConnect's auth object is what they call a \"Cacao\" object, with data on the SIWE message\n * and the signature itself.\n * By consulting how they implemented their \"validateSignedCacao\" function,\n * we are able to reconstruct the original message which can be used to verify the signature\n * in our backend.\n */\n for (const auth of authsFilteredByAddress) {\n const publicWalletAddress = getAddressFromIss(auth.p.iss);\n\n assertDefined(\n publicWalletAddress,\n `Unable to get public wallet address from WalletConnect Cacao object iss: ${auth.p.iss}`\n );\n\n const messageToSign = formatMessage(auth.p, auth.p.iss);\n\n const signature = auth.s.s;\n\n lastResponse = await verifyMessageSignatureOwnership(\n {\n chain,\n messageToSign,\n signature,\n walletAddress: publicWalletAddress,\n walletDisplayName,\n walletProviderType: WalletProviderEnum.WalletConnect,\n },\n client\n );\n }\n\n if (!lastResponse) {\n return;\n }\n\n /**\n * Adds the user with the new wallet verified credentials\n * This will add the new verified wallet accounts to the client`s state\n */\n updateAuthFromVerifyResponse({ response: lastResponse }, client);\n};\n","import type { Chain, DynamicClient } from '@dynamic-labs-sdk/client';\nimport {\n type WalletAccount,\n verifyWalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n updateWalletProviderKeysForVerifiedCredentials,\n} from '@dynamic-labs-sdk/client/core';\nimport type { AuthTypes } from '@walletconnect/types';\n\nimport { importWalletConnectSession } from '../importWalletConnectSession';\nimport { setSessionTopicsData } from '../sessionTopicsData/setSessionTopicsData';\nimport { verifyWalletConnectAuths } from './verifyWalletConnectAuths';\n\ntype ImportWalletConnectAuthResponseParams = {\n /**\n * The response from the WalletConnect authenticate method.\n */\n authResponse: AuthTypes.AuthenticateResponseResult;\n\n /**\n * The chain with which the wallet account is associated.\n */\n chain: Chain;\n};\n\n/**\n * A low level function that is used to connect a WalletConnect authenticate response to the Dynamic SDK.\n * It will generate the wallet providers and wallet accounts for all accounts in the session.\n *\n * @see WalletConnect's docs on [session authentication](https://docs.reown.com/advanced/api/sign/dapp-usage#session-authenticate-with-recaps)\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the connected and verified wallet account.\n */\nexport const importWalletConnectAuthResponse = async (\n { authResponse, chain }: ImportWalletConnectAuthResponseParams,\n client: DynamicClient\n): Promise<{ walletAccounts: WalletAccount[] }> => {\n const { session, auths } = authResponse;\n\n /**\n * Some wallets do not support WC's authenticate method (such as Rainbow).\n * For these wallets, the authenticate method will act as a regular connect method.\n * Therefore we must call verify individually.\n */\n if (!auths || auths.length === 0) {\n /**\n * Set addToDynamicWalletAccounts to false to avoid adding the wallet accounts to the dynamic's wallet accounts\n * while we are still verifying them.\n * After verifying, we set addToDynamicWalletAccounts back to true.\n */\n const { walletAccounts } = await importWalletConnectSession(\n { addToDynamicWalletAccounts: false, session },\n client\n );\n\n // This should not be concurrent because the first will be a verify and the rest will be a link\n for (const walletAccount of walletAccounts) {\n await verifyWalletAccount({ walletAccount }, client);\n }\n\n await setSessionTopicsData(\n {\n update: (sessionTopicsData) => ({\n ...sessionTopicsData,\n [session.topic]: { shouldAddToDynamicWalletAccounts: true },\n }),\n },\n client\n );\n\n return { walletAccounts };\n }\n\n /**\n * This reconstructs the message that was signed by the wallet and verifies the signature\n * in the backend. It will update the user with the new verified credentials.\n */\n await verifyWalletConnectAuths(\n {\n auths,\n chain,\n walletDisplayName: session.peer.metadata.name,\n },\n client\n );\n\n const { walletAccounts } = await importWalletConnectSession(\n { addToDynamicWalletAccounts: true, session },\n client\n );\n\n const verifiedCredentialWalletProviderKeyMap = Object.fromEntries(\n walletAccounts.map((walletAccount) => {\n const { verifiedCredentialId } = walletAccount;\n\n assertDefined(\n verifiedCredentialId,\n `Wallet account of ID ${walletAccount.id} still has no verified credential after being verified`\n );\n\n return [verifiedCredentialId, walletAccount.walletProviderKey] as const;\n })\n );\n\n updateWalletProviderKeysForVerifiedCredentials(\n {\n keysToUpdate: verifiedCredentialWalletProviderKeyMap,\n },\n client\n );\n\n return { walletAccounts };\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { SDK_ERRORS } from '@walletconnect/utils';\n\nimport { getSignClient } from '../../signClient/getSignClient';\nimport { getSessionTopicsData } from '../getSessionTopicsData';\nimport { setSessionTopicsData } from '../setSessionTopicsData';\n\n/**\n * Clears all temporary sessions and disconnects from them.\n *\n * External sessions are for WC sessions whose accounts are not supposed to be saved in\n * the current dynamic's wallet accounts.\n * Since we don't own the created wallet accounts, we must keep their corresponding WC sessions alive\n * until the page is refreshed or the customer removes the wallet account.\n *\n * @param client - The client instance.\n */\nexport const clearTemporarySessions = async (client: DynamicClient) => {\n const signClient = await getSignClient(client);\n\n const sessionTopicsData = await getSessionTopicsData(client);\n\n const temporarySessionTopics = Object.keys(sessionTopicsData).filter(\n (topic) => !sessionTopicsData[topic].shouldAddToDynamicWalletAccounts\n );\n\n if (temporarySessionTopics.length === 0) {\n return;\n }\n\n for (const topic of temporarySessionTopics) {\n await signClient.disconnect({\n reason: SDK_ERRORS.USER_DISCONNECTED,\n topic,\n });\n }\n\n const newSessionTopicsData = Object.fromEntries(\n Object.entries(sessionTopicsData).filter(\n ([, { shouldAddToDynamicWalletAccounts: isPermanentSession }]) =>\n isPermanentSession\n )\n );\n\n await setSessionTopicsData({ update: () => newSessionTopicsData }, client);\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\n\nimport { clearTemporarySessions } from '../sessionTopicsData/clearTemporarySessions';\nimport { syncSessionsToWalletProviders } from '../syncSessionsToWalletProviders';\n\nexport const initializeWalletConnectExtension = async (\n client: DynamicClient\n) => {\n // Clear external session topics that were created in previous browser sessions\n // Read more in the clearTemporarySessions function.\n await clearTemporarySessions(client);\n\n // Add debounce to account for multiple WC extension additions in quick succession\n await syncSessionsToWalletProviders(\n { allowOverridingWalletProviders: false, debounceTime: 200 },\n client\n );\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport { name, version } from '../../package.json';\n\nassertPackageVersion(name, version);\n\nexport { importWalletConnectAuthResponse } from '../importWalletConnectAuthResponse';\nexport { importWalletConnectSession } from '../importWalletConnectSession';\nexport { initializeWalletConnectExtension } from '../initializeWalletConnectExtension';\nexport { getNamespaceRegistry } from '../namespaceRegistry';\nexport type { NamespaceRegistry } from '../namespaceRegistry/namespaceRegistry.types';\nexport { getSignClient } from '../signClient/getSignClient';\nexport { splitCaip10Token } from '../splitCaip10Token';\nexport { syncSessionsToWalletProviders } from '../syncSessionsToWalletProviders';\nexport type { WalletProviderBuilder } from '../walletConnectWalletProvider.types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAa,oBAAoB,gBAAwB;CACvD,MAAM,CAAC,cAAc,WAAW,WAAW,YAAY,MAAM,IAAI;AACjE,QAAO;EAAE;EAAS;EAAc;EAAW;;;;;ACH7C,MAAa,sDAAsD,EACjE,qBAC+E;;;;;;;;;CAS/E,MAAM,YACJ,eAAe,QAAQ,WAAW,e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