@dynamic-labs-sdk/client 1.7.0 → 1.8.1
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/android/build.gradle +231 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +7 -0
- package/android/gradle.properties +8 -0
- package/android/gradlew +251 -0
- package/android/gradlew.bat +94 -0
- package/android/settings.gradle +30 -0
- package/android/src/main/java/xyz/dynamic/client/DynamicClientPackage.kt +52 -0
- package/android/src/main/java/xyz/dynamic/client/keychain/KeyStoreKeyManager.kt +147 -0
- package/android/src/main/java/xyz/dynamic/client/keychain/KeychainModule.kt +85 -0
- package/android/src/main/java/xyz/dynamic/client/manifest/ReactNativeManifestModule.kt +25 -0
- package/android/src/main/java/xyz/dynamic/client/webview/DynamicWebViewClient.kt +83 -0
- package/android/src/main/java/xyz/dynamic/client/webview/DynamicWebViewHost.kt +518 -0
- package/android/src/main/java/xyz/dynamic/client/webview/DynamicWebViewModule.kt +147 -0
- package/android/src/test/java/xyz/dynamic/client/keychain/KeyStoreKeyManagerTest.kt +288 -0
- package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewClientTest.kt +196 -0
- package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewHostOpenTest.kt +347 -0
- package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewHostTest.kt +171 -0
- package/android/src/test/java/xyz/dynamic/client/webview/DynamicWebViewModuleTest.kt +191 -0
- package/dist/{InvalidParamError-Crwntjl7.native.esm.js → InvalidParamError-BKnC9rcJ.esm.js} +441 -10
- package/dist/InvalidParamError-BKnC9rcJ.esm.js.map +1 -0
- package/dist/{InvalidParamError-fQLJaGBW.esm.js → InvalidParamError-Btv8VGSa.native.esm.js} +3 -3
- package/dist/InvalidParamError-Btv8VGSa.native.esm.js.map +1 -0
- package/dist/{InvalidParamError-CTssOe86.cjs → InvalidParamError-DGBih-LJ.cjs} +550 -4
- package/dist/InvalidParamError-DGBih-LJ.cjs.map +1 -0
- package/dist/{NotWaasWalletAccountError-DF_S7gqo.esm.js → NotWaasWalletAccountError-CHr72wTH.esm.js} +3 -3
- package/dist/{NotWaasWalletAccountError-DF_S7gqo.esm.js.map → NotWaasWalletAccountError-CHr72wTH.esm.js.map} +1 -1
- package/dist/{NotWaasWalletAccountError-BJLGGYmU.native.esm.js → NotWaasWalletAccountError-CRmyVoB3.native.esm.js} +3 -3
- package/dist/{NotWaasWalletAccountError-BJLGGYmU.native.esm.js.map → NotWaasWalletAccountError-CRmyVoB3.native.esm.js.map} +1 -1
- package/dist/{NotWaasWalletAccountError-2RaDipZu.cjs → NotWaasWalletAccountError-i1FozGep.cjs} +3 -3
- package/dist/{NotWaasWalletAccountError-2RaDipZu.cjs.map → NotWaasWalletAccountError-i1FozGep.cjs.map} +1 -1
- package/dist/core.cjs +23 -23
- package/dist/core.cjs.map +1 -1
- package/dist/core.esm.js +5 -5
- package/dist/core.native.esm.js +7 -7
- package/dist/core.native.esm.js.map +1 -1
- package/dist/errors/WebViewLoadFailedError.d.ts +1 -1
- package/dist/errors/WebViewLoadFailedError.d.ts.map +1 -1
- package/dist/exports/index.d.ts +2 -0
- package/dist/exports/index.d.ts.map +1 -1
- package/dist/{getNetworkProviderFromNetworkId-C1p9Rrg3.cjs → getNetworkProviderFromNetworkId-BdgI7g5U.cjs} +11 -317
- package/dist/getNetworkProviderFromNetworkId-BdgI7g5U.cjs.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-BCSmILlH.native.esm.js → getNetworkProviderFromNetworkId-Bm41knUq.native.esm.js} +6 -6
- package/dist/getNetworkProviderFromNetworkId-Bm41knUq.native.esm.js.map +1 -0
- package/dist/{getNetworkProviderFromNetworkId-BWhaD23J.esm.js → getNetworkProviderFromNetworkId-CRuh5pgc.esm.js} +4 -242
- package/dist/getNetworkProviderFromNetworkId-CRuh5pgc.esm.js.map +1 -0
- package/dist/{getSignedSessionId-CxxYNC_8.cjs → getSignedSessionId-Cwmt4BkY.cjs} +3 -3
- package/dist/{getSignedSessionId-CxxYNC_8.cjs.map → getSignedSessionId-Cwmt4BkY.cjs.map} +1 -1
- package/dist/{getSignedSessionId-c7dS4PQ9.esm.js → getSignedSessionId-D2w_IRdt.esm.js} +3 -3
- package/dist/{getSignedSessionId-c7dS4PQ9.esm.js.map → getSignedSessionId-D2w_IRdt.esm.js.map} +1 -1
- package/dist/{getSignedSessionId-DPOXdh6y.native.esm.js → getSignedSessionId-S6CBWkOn.native.esm.js} +3 -3
- package/dist/{getSignedSessionId-DPOXdh6y.native.esm.js.map → getSignedSessionId-S6CBWkOn.native.esm.js.map} +1 -1
- package/dist/getVerifiedCredentialForWalletAccount-CDuP1kaI.cjs +347 -0
- package/dist/getVerifiedCredentialForWalletAccount-CDuP1kaI.cjs.map +1 -0
- package/dist/{getVerifiedCredentialForWalletAccount-Cahp763h.esm.js → getVerifiedCredentialForWalletAccount-D33r7Drd.native.esm.js} +2 -2
- package/dist/{getVerifiedCredentialForWalletAccount-DuNbORNW.native.esm.js.map → getVerifiedCredentialForWalletAccount-D33r7Drd.native.esm.js.map} +1 -1
- package/dist/getVerifiedCredentialForWalletAccount-QwfkKHfr.esm.js +269 -0
- package/dist/getVerifiedCredentialForWalletAccount-QwfkKHfr.esm.js.map +1 -0
- package/dist/index.cjs +67 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +5 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.native.esm.js +5 -5
- package/dist/index.native.esm.js.map +1 -1
- package/dist/isMfaRequiredForAction-5p3i98-Z.esm.js +318 -0
- package/dist/isMfaRequiredForAction-5p3i98-Z.esm.js.map +1 -0
- package/dist/{isMfaRequiredForAction-D8G5PBAd.native.esm.js → isMfaRequiredForAction-cmElIVof.native.esm.js} +2 -2
- package/dist/{isMfaRequiredForAction-D8G5PBAd.native.esm.js.map → isMfaRequiredForAction-cmElIVof.native.esm.js.map} +1 -1
- package/dist/isMfaRequiredForAction-z74isCQ7.cjs +405 -0
- package/dist/isMfaRequiredForAction-z74isCQ7.cjs.map +1 -0
- package/dist/modules/waas/createWaasClient/createWaasClient.d.ts.map +1 -1
- package/dist/modules/waas/createWaasClient/translateNativeOpenError.d.ts.map +1 -1
- package/dist/modules/wallets/walletProvider/events/onWalletProviderEvent/onWalletProviderEvent.d.ts +1 -2
- package/dist/modules/wallets/walletProvider/events/onWalletProviderEvent/onWalletProviderEvent.d.ts.map +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/waas.cjs +9 -9
- package/dist/waas.cjs.map +1 -1
- package/dist/waas.esm.js +3 -3
- package/dist/waas.native.esm.js +3 -3
- package/dist/waasCore.cjs +8 -5
- package/dist/waasCore.cjs.map +1 -1
- package/dist/waasCore.esm.js +8 -4
- package/dist/waasCore.esm.js.map +1 -1
- package/dist/waasCore.native.esm.js +9 -8
- package/dist/waasCore.native.esm.js.map +1 -1
- package/dynamic-labs-sdk-client.podspec +27 -0
- package/ios/DynamicClientKeychain.h +4 -0
- package/ios/DynamicClientKeychain.mm +101 -0
- package/ios/DynamicClientManifest.h +4 -0
- package/ios/DynamicClientManifest.mm +45 -0
- package/ios/DynamicClientWebView.h +5 -0
- package/ios/DynamicClientWebView.mm +143 -0
- package/ios/DynamicWebViewImpl.swift +603 -0
- package/ios/LiveSecKeyAPI.swift +86 -0
- package/ios/ReactNativeManifestImpl.swift +20 -0
- package/ios/SecKeyAPI.swift +57 -0
- package/ios/SecureEnclaveKeyManager.swift +191 -0
- package/package.json +14 -5
- package/react-native.config.cjs +14 -0
- package/src/turboModules/NativeDynamicWebView.native.spec.ts +61 -0
- package/src/turboModules/NativeDynamicWebView.ts +40 -0
- package/src/turboModules/NativeKeychain.native.spec.ts +47 -0
- package/src/turboModules/NativeKeychain.ts +19 -0
- package/src/turboModules/NativeReactNativeManifest.native.spec.ts +55 -0
- package/src/turboModules/NativeReactNativeManifest.ts +28 -0
- package/dist/InvalidParamError-CTssOe86.cjs.map +0 -1
- package/dist/InvalidParamError-Crwntjl7.native.esm.js.map +0 -1
- package/dist/InvalidParamError-fQLJaGBW.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-BCSmILlH.native.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-BWhaD23J.esm.js.map +0 -1
- package/dist/getNetworkProviderFromNetworkId-C1p9Rrg3.cjs.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-Cahp763h.esm.js.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-Di8dM5Wx.cjs +0 -887
- package/dist/getVerifiedCredentialForWalletAccount-Di8dM5Wx.cjs.map +0 -1
- package/dist/getVerifiedCredentialForWalletAccount-DuNbORNW.native.esm.js +0 -701
- package/dist/isMfaRequiredForAction-BjRvPrU6.esm.js +0 -79
- package/dist/isMfaRequiredForAction-BjRvPrU6.esm.js.map +0 -1
- package/dist/isMfaRequiredForAction-hlhj0qAC.cjs +0 -96
- package/dist/isMfaRequiredForAction-hlhj0qAC.cjs.map +0 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
package xyz.dynamic.client.webview
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import android.net.Uri
|
|
5
|
+
import android.os.Looper
|
|
6
|
+
import android.webkit.WebView
|
|
7
|
+
import androidx.webkit.JavaScriptReplyProxy
|
|
8
|
+
import androidx.webkit.WebMessageCompat
|
|
9
|
+
import androidx.webkit.WebViewCompat
|
|
10
|
+
import androidx.webkit.WebViewFeature
|
|
11
|
+
import com.facebook.react.bridge.Arguments
|
|
12
|
+
import com.facebook.react.bridge.JavaOnlyArray
|
|
13
|
+
import com.facebook.react.bridge.JavaOnlyMap
|
|
14
|
+
import com.facebook.react.bridge.Promise
|
|
15
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
16
|
+
import com.facebook.react.bridge.ReadableType
|
|
17
|
+
import com.facebook.react.bridge.WritableMap
|
|
18
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
|
|
19
|
+
import io.mockk.CapturingSlot
|
|
20
|
+
import io.mockk.Runs
|
|
21
|
+
import io.mockk.every
|
|
22
|
+
import io.mockk.just
|
|
23
|
+
import io.mockk.mockk
|
|
24
|
+
import io.mockk.mockkStatic
|
|
25
|
+
import io.mockk.slot
|
|
26
|
+
import io.mockk.unmockkAll
|
|
27
|
+
import io.mockk.verify
|
|
28
|
+
import org.junit.After
|
|
29
|
+
import org.junit.Assert.assertEquals
|
|
30
|
+
import org.junit.Before
|
|
31
|
+
import org.junit.Test
|
|
32
|
+
import org.junit.runner.RunWith
|
|
33
|
+
import org.robolectric.Robolectric
|
|
34
|
+
import org.robolectric.RobolectricTestRunner
|
|
35
|
+
import org.robolectric.Shadows.shadowOf
|
|
36
|
+
import org.robolectric.annotation.Config
|
|
37
|
+
|
|
38
|
+
// The androidx.webkit + Arguments statics are mocked (they delegate to the
|
|
39
|
+
// device WebView / JNI). A real Robolectric Activity backs WebView construction
|
|
40
|
+
// so open() reaches the live-host state needed to exercise invalidate().
|
|
41
|
+
@RunWith(RobolectricTestRunner::class)
|
|
42
|
+
@Config(sdk = [35])
|
|
43
|
+
class DynamicWebViewModuleTest {
|
|
44
|
+
|
|
45
|
+
private lateinit var activity: Activity
|
|
46
|
+
private lateinit var reactContext: ReactApplicationContext
|
|
47
|
+
private lateinit var module: DynamicWebViewModule
|
|
48
|
+
private lateinit var eventEmitter: RCTDeviceEventEmitter
|
|
49
|
+
private lateinit var webSlot: CapturingSlot<WebView>
|
|
50
|
+
private lateinit var listenerSlot: CapturingSlot<WebViewCompat.WebMessageListener>
|
|
51
|
+
|
|
52
|
+
@Before
|
|
53
|
+
fun setUp() {
|
|
54
|
+
activity = Robolectric.buildActivity(Activity::class.java).setup().get()
|
|
55
|
+
reactContext = mockk(relaxed = true)
|
|
56
|
+
every { reactContext.currentActivity } returns activity
|
|
57
|
+
every { reactContext.runOnUiQueueThread(any()) } answers { firstArg<Runnable>().run() }
|
|
58
|
+
|
|
59
|
+
eventEmitter = mockk(relaxed = true)
|
|
60
|
+
every {
|
|
61
|
+
reactContext.getJSModule(RCTDeviceEventEmitter::class.java)
|
|
62
|
+
} returns eventEmitter
|
|
63
|
+
|
|
64
|
+
mockkStatic(Arguments::class)
|
|
65
|
+
every { Arguments.createMap() } answers { JavaOnlyMap() }
|
|
66
|
+
every { Arguments.createArray() } answers { JavaOnlyArray() }
|
|
67
|
+
|
|
68
|
+
mockkStatic(WebViewFeature::class)
|
|
69
|
+
every { WebViewFeature.isFeatureSupported(any()) } returns false
|
|
70
|
+
every {
|
|
71
|
+
WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)
|
|
72
|
+
} returns true
|
|
73
|
+
|
|
74
|
+
mockkStatic(WebViewCompat::class)
|
|
75
|
+
webSlot = slot()
|
|
76
|
+
listenerSlot = slot()
|
|
77
|
+
every {
|
|
78
|
+
WebViewCompat.addWebMessageListener(
|
|
79
|
+
capture(webSlot),
|
|
80
|
+
any(),
|
|
81
|
+
any(),
|
|
82
|
+
capture(listenerSlot),
|
|
83
|
+
)
|
|
84
|
+
} just Runs
|
|
85
|
+
every {
|
|
86
|
+
WebViewCompat.addDocumentStartJavaScript(any(), any(), any())
|
|
87
|
+
} returns mockk(relaxed = true)
|
|
88
|
+
every { WebViewCompat.setProfile(any(), any()) } just Runs
|
|
89
|
+
|
|
90
|
+
module = DynamicWebViewModule(reactContext)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@After
|
|
94
|
+
fun tearDown() {
|
|
95
|
+
unmockkAll()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private fun idleMain() = shadowOf(Looper.getMainLooper()).idle()
|
|
99
|
+
|
|
100
|
+
// region invalidate (#12 — ConcurrentModificationException)
|
|
101
|
+
|
|
102
|
+
@Test
|
|
103
|
+
fun invalidate_closesEveryActiveHostWithoutConcurrentModification() {
|
|
104
|
+
val p1 = mockk<Promise>(relaxed = true)
|
|
105
|
+
val p2 = mockk<Promise>(relaxed = true)
|
|
106
|
+
|
|
107
|
+
module.open("a", "https://app.dynamicauth.com/x", p1)
|
|
108
|
+
module.open("b", "https://app.dynamicauth.com/y", p2)
|
|
109
|
+
idleMain() // run the posted opens → two live hosts
|
|
110
|
+
|
|
111
|
+
module.invalidate()
|
|
112
|
+
idleMain() // run the posted close-all; the .toList() snapshot avoids CME
|
|
113
|
+
|
|
114
|
+
// Both hosts torn down (cancelled) proves the iteration completed across
|
|
115
|
+
// >1 host — without the snapshot this throws ConcurrentModificationException.
|
|
116
|
+
verify { p1.reject("webview_cancelled", any<String>(), any<WritableMap>()) }
|
|
117
|
+
verify { p2.reject("webview_cancelled", any<String>(), any<WritableMap>()) }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// endregion
|
|
121
|
+
|
|
122
|
+
// region emitMessage payload mapping (#13 — array payloads)
|
|
123
|
+
|
|
124
|
+
@Test
|
|
125
|
+
fun putBridgeData_mapsArrayPayloadOntoDataField() {
|
|
126
|
+
val target = JavaOnlyMap()
|
|
127
|
+
putBridgeData(target, JavaOnlyArray().apply { pushString("x") })
|
|
128
|
+
assertEquals(ReadableType.Array, target.getType("data"))
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@Test
|
|
132
|
+
fun putBridgeData_mapsMapStringNullAndUnknownFallthrough() {
|
|
133
|
+
val map = JavaOnlyMap()
|
|
134
|
+
|
|
135
|
+
putBridgeData(map, JavaOnlyMap())
|
|
136
|
+
assertEquals(ReadableType.Map, map.getType("data"))
|
|
137
|
+
|
|
138
|
+
putBridgeData(map, "s")
|
|
139
|
+
assertEquals(ReadableType.String, map.getType("data"))
|
|
140
|
+
|
|
141
|
+
putBridgeData(map, null)
|
|
142
|
+
assertEquals(ReadableType.Null, map.getType("data"))
|
|
143
|
+
|
|
144
|
+
putBridgeData(map, 42)
|
|
145
|
+
assertEquals(ReadableType.Null, map.getType("data"))
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// endregion
|
|
149
|
+
|
|
150
|
+
// region pre-listener event buffering (F4 — handshake not dropped)
|
|
151
|
+
|
|
152
|
+
// Drives a bridge message into the host's WebMessageListener so it flows
|
|
153
|
+
// through onBridgeMessage -> onMessage -> module.emitMessage.
|
|
154
|
+
private fun deliverBridgeMessage(payload: String) {
|
|
155
|
+
listenerSlot.captured.onPostMessage(
|
|
156
|
+
webSlot.captured,
|
|
157
|
+
mockk<WebMessageCompat> { every { data } returns payload },
|
|
158
|
+
Uri.parse("https://app.dynamicauth.com"),
|
|
159
|
+
true,
|
|
160
|
+
mockk<JavaScriptReplyProxy>(relaxed = true),
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@Test
|
|
165
|
+
fun emitMessage_buffersBeforeFirstListenerThenFlushesOnSubscribe() {
|
|
166
|
+
module.open("a", "https://app.dynamicauth.com/x", mockk(relaxed = true))
|
|
167
|
+
idleMain()
|
|
168
|
+
|
|
169
|
+
// Handshake arrives before any JS listener subscribed → must be buffered,
|
|
170
|
+
// not emitted (RCTDeviceEventEmitter.emit would otherwise drop it).
|
|
171
|
+
deliverBridgeMessage("{\"type\":\"iframe-ready\"}")
|
|
172
|
+
verify(exactly = 0) { eventEmitter.emit(any(), any()) }
|
|
173
|
+
|
|
174
|
+
// First subscriber attaches → buffered event flushes.
|
|
175
|
+
module.addListener(DynamicWebViewModule.MESSAGE_EVENT_NAME)
|
|
176
|
+
verify { eventEmitter.emit(DynamicWebViewModule.MESSAGE_EVENT_NAME, any()) }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@Test
|
|
180
|
+
fun emitMessage_emitsDirectlyAfterListenerAttached() {
|
|
181
|
+
module.open("a", "https://app.dynamicauth.com/x", mockk(relaxed = true))
|
|
182
|
+
idleMain()
|
|
183
|
+
module.addListener(DynamicWebViewModule.MESSAGE_EVENT_NAME)
|
|
184
|
+
|
|
185
|
+
deliverBridgeMessage("{\"type\":\"sign\"}")
|
|
186
|
+
|
|
187
|
+
verify { eventEmitter.emit(DynamicWebViewModule.MESSAGE_EVENT_NAME, any()) }
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// endregion
|
|
191
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AuthStorageEnum, Configuration, SDKApi, isDeviceNonceSignatureRequiredForUrl } from "@dynamic-labs/sdk-api-core";
|
|
1
|
+
import { AuthStorageEnum, Configuration, JwtVerifiedCredentialFormatEnum, SDKApi, WalletProviderEnum, isDeviceNonceSignatureRequiredForUrl } from "@dynamic-labs/sdk-api-core";
|
|
2
2
|
|
|
3
3
|
//#region package.json
|
|
4
4
|
var name = "@dynamic-labs-sdk/client";
|
|
5
|
-
var version = "1.
|
|
5
|
+
var version = "1.8.1";
|
|
6
6
|
var dependencies = {
|
|
7
7
|
"@dynamic-labs-sdk/assert-package-version": "workspace:*",
|
|
8
|
-
"@dynamic-labs-wallet/browser-wallet-client": "1.0.
|
|
8
|
+
"@dynamic-labs-wallet/browser-wallet-client": "1.0.16",
|
|
9
9
|
"@dynamic-labs-wallet/forward-mpc-client": "0.10.1",
|
|
10
10
|
"@dynamic-labs/sdk-api-core": "catalog:",
|
|
11
11
|
"@simplewebauthn/browser": "13.1.0",
|
|
@@ -139,15 +139,14 @@ const DYNAMIC_SDK_SESSION_ID_HEADER = "x-dyn-session-id";
|
|
|
139
139
|
const CLIENT_SDK_NAME = "ClientSDK";
|
|
140
140
|
|
|
141
141
|
//#endregion
|
|
142
|
-
//#region src/utils/randomString/randomString.
|
|
142
|
+
//#region src/utils/randomString/randomString.ts
|
|
143
143
|
const DEFAULT_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
144
144
|
/** @not-instrumented */
|
|
145
145
|
const randomString = ({ chars = DEFAULT_CHARS, length }) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
*/
|
|
146
|
+
const bytes = new Uint8Array(length);
|
|
147
|
+
crypto.getRandomValues(bytes);
|
|
149
148
|
let result = "";
|
|
150
|
-
for (let i = 0; i < length; i++) result += chars[
|
|
149
|
+
for (let i = 0; i < length; i++) result += chars[bytes[i] % chars.length];
|
|
151
150
|
return result;
|
|
152
151
|
};
|
|
153
152
|
|
|
@@ -1017,6 +1016,152 @@ const fetchAndStoreNonces = async (client) => {
|
|
|
1017
1016
|
});
|
|
1018
1017
|
};
|
|
1019
1018
|
|
|
1019
|
+
//#endregion
|
|
1020
|
+
//#region src/utils/setCookie/setCookie.ts
|
|
1021
|
+
/**
|
|
1022
|
+
* Sefelly sets the cookie in the browser.
|
|
1023
|
+
* @not-instrumented
|
|
1024
|
+
*/
|
|
1025
|
+
const setCookie = (cookie) => {
|
|
1026
|
+
document.cookie = cookie;
|
|
1027
|
+
};
|
|
1028
|
+
|
|
1029
|
+
//#endregion
|
|
1030
|
+
//#region src/modules/clientEvents/clientEvents.ts
|
|
1031
|
+
/**
|
|
1032
|
+
* Adds an event listener for Dynamic client events.
|
|
1033
|
+
*
|
|
1034
|
+
* This function allows you to listen for various events emitted by the Dynamic client,
|
|
1035
|
+
* such as authentication state changes, wallet connections, and more.
|
|
1036
|
+
*
|
|
1037
|
+
* @param params.event - The event name to listen for.
|
|
1038
|
+
* @param params.listener - The callback function to execute when the event is fired.
|
|
1039
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1040
|
+
* @returns A function that can be called to remove the listener.
|
|
1041
|
+
* @not-instrumented
|
|
1042
|
+
*/
|
|
1043
|
+
const onEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
1044
|
+
const { eventEmitter } = getCore(client);
|
|
1045
|
+
eventEmitter.on(event, listener);
|
|
1046
|
+
return () => {
|
|
1047
|
+
eventEmitter.off(event, listener);
|
|
1048
|
+
};
|
|
1049
|
+
};
|
|
1050
|
+
/**
|
|
1051
|
+
* Removes an event listener from Dynamic client events.
|
|
1052
|
+
*
|
|
1053
|
+
* This function unsubscribes a previously registered event listener
|
|
1054
|
+
* from the specified Dynamic client event.
|
|
1055
|
+
*
|
|
1056
|
+
* @param params.event - The event name to remove the listener from.
|
|
1057
|
+
* @param params.listener - The callback function to remove.
|
|
1058
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1059
|
+
* @not-instrumented
|
|
1060
|
+
*/
|
|
1061
|
+
const offEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
1062
|
+
const { eventEmitter } = getCore(client);
|
|
1063
|
+
eventEmitter.off(event, listener);
|
|
1064
|
+
};
|
|
1065
|
+
/**
|
|
1066
|
+
* Adds a one-time event listener for Dynamic client events.
|
|
1067
|
+
*
|
|
1068
|
+
* This function listens for an event that will automatically remove itself
|
|
1069
|
+
* after being triggered once.
|
|
1070
|
+
*
|
|
1071
|
+
* @param params.event - The event name to listen for.
|
|
1072
|
+
* @param params.listener - The callback function to execute when the event is fired.
|
|
1073
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1074
|
+
* @returns A function that can be called to remove the listener before it fires.
|
|
1075
|
+
* @not-instrumented
|
|
1076
|
+
*/
|
|
1077
|
+
const onceEvent = ({ event, listener }, client = getDefaultClient()) => {
|
|
1078
|
+
const { eventEmitter } = getCore(client);
|
|
1079
|
+
eventEmitter.once(event, listener);
|
|
1080
|
+
return () => {
|
|
1081
|
+
eventEmitter.off(event, listener);
|
|
1082
|
+
};
|
|
1083
|
+
};
|
|
1084
|
+
/**
|
|
1085
|
+
* Emits a Dynamic client event.
|
|
1086
|
+
*
|
|
1087
|
+
* This function triggers an event that will be received by all registered
|
|
1088
|
+
* listeners for the specified event type.
|
|
1089
|
+
*
|
|
1090
|
+
* @param params.event - The event name to emit.
|
|
1091
|
+
* @param params.args - The arguments to pass to event listeners.
|
|
1092
|
+
* @param client - The Dynamic client instance.
|
|
1093
|
+
* @not-instrumented
|
|
1094
|
+
*/
|
|
1095
|
+
const emitEvent = ({ event, args }, client) => {
|
|
1096
|
+
const { eventEmitter } = getCore(client);
|
|
1097
|
+
eventEmitter.emit(event, args);
|
|
1098
|
+
};
|
|
1099
|
+
|
|
1100
|
+
//#endregion
|
|
1101
|
+
//#region src/errors/InvalidWalletProviderKeyError.ts
|
|
1102
|
+
var InvalidWalletProviderKeyError = class extends BaseError {
|
|
1103
|
+
constructor(value) {
|
|
1104
|
+
super({
|
|
1105
|
+
cause: null,
|
|
1106
|
+
code: "invalid_wallet_provider_key",
|
|
1107
|
+
docsUrl: null,
|
|
1108
|
+
name: "InvalidWalletProviderKeyError",
|
|
1109
|
+
shortMessage: `Invalid wallet provider key: ${value}. Key must be in the format of <normalizedWalletNameWithChain>:<walletProviderType>[:<suffix>]`
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1114
|
+
//#endregion
|
|
1115
|
+
//#region src/modules/wallets/walletProvider/splitWalletProviderKey/splitWalletProviderKey.ts
|
|
1116
|
+
/** @not-instrumented */
|
|
1117
|
+
const splitWalletProviderKey = (walletProviderKey) => {
|
|
1118
|
+
const [normalizedWalletNameWithChain, walletProviderType, suffix, ...rest] = walletProviderKey.split(":");
|
|
1119
|
+
if (!normalizedWalletNameWithChain || !Object.values(WalletProviderEnum).includes(walletProviderType) || rest.length > 0) throw new InvalidWalletProviderKeyError(walletProviderKey);
|
|
1120
|
+
return {
|
|
1121
|
+
normalizedWalletNameWithChain,
|
|
1122
|
+
suffix,
|
|
1123
|
+
walletProviderType
|
|
1124
|
+
};
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
//#endregion
|
|
1128
|
+
//#region src/modules/wallets/utils/normalizeAddress/normalizeAddress.ts
|
|
1129
|
+
/** @not-instrumented */
|
|
1130
|
+
const normalizeAddress = ({ address, chain }) => {
|
|
1131
|
+
let normalizedAddress = address;
|
|
1132
|
+
if (normalizedAddress?.startsWith("0x")) normalizedAddress = normalizedAddress.slice(2);
|
|
1133
|
+
normalizedAddress = ["EVM", "FLOW"].includes(chain) ? normalizedAddress?.toLowerCase() : normalizedAddress;
|
|
1134
|
+
return normalizedAddress;
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
//#endregion
|
|
1138
|
+
//#region src/modules/wallets/utils/formatWalletAccountId/formatWalletAccountId.ts
|
|
1139
|
+
/** @not-instrumented */
|
|
1140
|
+
const formatWalletAccountId = ({ address, chain, walletProviderKey }) => {
|
|
1141
|
+
const { normalizedWalletNameWithChain } = splitWalletProviderKey(walletProviderKey);
|
|
1142
|
+
return `${normalizedWalletNameWithChain}:${normalizeAddress({
|
|
1143
|
+
address,
|
|
1144
|
+
chain
|
|
1145
|
+
})}`;
|
|
1146
|
+
};
|
|
1147
|
+
|
|
1148
|
+
//#endregion
|
|
1149
|
+
//#region src/modules/wallets/utils/convertUnverifiedWalletAccountToWalletAccount/convertUnverifiedWalletAccountToWalletAccount.ts
|
|
1150
|
+
/** @not-instrumented */
|
|
1151
|
+
const convertUnverifiedWalletAccountToWalletAccount = ({ unverifiedWalletAccount }) => ({
|
|
1152
|
+
address: unverifiedWalletAccount.address,
|
|
1153
|
+
addressesWithTypes: unverifiedWalletAccount.addressesWithTypes,
|
|
1154
|
+
chain: unverifiedWalletAccount.chain,
|
|
1155
|
+
id: formatWalletAccountId({
|
|
1156
|
+
address: unverifiedWalletAccount.address,
|
|
1157
|
+
chain: unverifiedWalletAccount.chain,
|
|
1158
|
+
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
1159
|
+
}),
|
|
1160
|
+
lastSelectedAt: unverifiedWalletAccount.lastSelectedAt,
|
|
1161
|
+
verifiedCredentialId: null,
|
|
1162
|
+
walletProviderKey: unverifiedWalletAccount.walletProviderKey
|
|
1163
|
+
});
|
|
1164
|
+
|
|
1020
1165
|
//#endregion
|
|
1021
1166
|
//#region src/modules/wallets/constants.ts
|
|
1022
1167
|
const CHAINS_INFO_MAP = {
|
|
@@ -1120,6 +1265,292 @@ const getChainFromVerifiedCredentialChain = (verifiedCredentialChain) => {
|
|
|
1120
1265
|
return chain;
|
|
1121
1266
|
};
|
|
1122
1267
|
|
|
1268
|
+
//#endregion
|
|
1269
|
+
//#region src/modules/wallets/utils/normalizeWalletNameWithChain/normalizeWalletNameWithChain.ts
|
|
1270
|
+
/**
|
|
1271
|
+
* Format the raw wallet name and chain to get the value we can use for
|
|
1272
|
+
* verified credentials' `walletName` field.
|
|
1273
|
+
* @not-instrumented
|
|
1274
|
+
*/
|
|
1275
|
+
const normalizeWalletNameWithChain = ({ displayName, chain }) => {
|
|
1276
|
+
const sanitizedWalletName = displayName.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
|
|
1277
|
+
const chainLowered = chain.toLocaleLowerCase();
|
|
1278
|
+
if (sanitizedWalletName.endsWith(chainLowered)) return sanitizedWalletName;
|
|
1279
|
+
return `${sanitizedWalletName}${chainLowered}`;
|
|
1280
|
+
};
|
|
1281
|
+
|
|
1282
|
+
//#endregion
|
|
1283
|
+
//#region src/modules/wallets/utils/formatWalletProviderKey/formatWalletProviderKey.ts
|
|
1284
|
+
/**
|
|
1285
|
+
* Assembles the wallet provider key from the wallet name, chain, and wallet provider type.
|
|
1286
|
+
*
|
|
1287
|
+
* The suffix is optional and can be used to add a uniquely identifying string to the key, which
|
|
1288
|
+
* might be necessary for some wallet providers (like Wallet Connect).
|
|
1289
|
+
*
|
|
1290
|
+
* IMPORTANT: Do NOT add a suffix unless absolutely necessary, as it will cause the wallet account
|
|
1291
|
+
* to not be able to find its wallet provider when connecting to a new device (it won't be possible
|
|
1292
|
+
* to determine the full key just from the Verified Credential data).
|
|
1293
|
+
* @not-instrumented
|
|
1294
|
+
*/
|
|
1295
|
+
const formatWalletProviderKey = ({ suffix, chain, displayName, walletProviderType }) => {
|
|
1296
|
+
return `${normalizeWalletNameWithChain({
|
|
1297
|
+
chain,
|
|
1298
|
+
displayName
|
|
1299
|
+
})}:${walletProviderType}${suffix ? `:${suffix}` : ""}`;
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
//#endregion
|
|
1303
|
+
//#region src/modules/wallets/walletProvider/walletProviderKeyMap/getWalletProviderKeyFromVerifiedCredential/getWalletProviderKeyFromVerifiedCredential.ts
|
|
1304
|
+
/** @not-instrumented */
|
|
1305
|
+
const getWalletProviderKeyFromVerifiedCredential = ({ verifiedCredential }, client) => {
|
|
1306
|
+
const { walletProviderKeyMap } = getCore(client).state.get();
|
|
1307
|
+
const storedWalletProviderKey = walletProviderKeyMap[verifiedCredential.id];
|
|
1308
|
+
if (storedWalletProviderKey) return { walletProviderKey: storedWalletProviderKey };
|
|
1309
|
+
/**
|
|
1310
|
+
* We fallback to comprising the wallet provider key from walletName and walletProvider.
|
|
1311
|
+
*
|
|
1312
|
+
* Some wallet provider types (like Wallet Connect) also use a special suffix for their wallet provider
|
|
1313
|
+
* keys, so this won't be enough for them.
|
|
1314
|
+
* Therefore, for those specific wallet providers, the wallet account will remain without a wallet provider
|
|
1315
|
+
* and will require reconnection.
|
|
1316
|
+
* Read walletProvider.types.ts for more info.
|
|
1317
|
+
*/
|
|
1318
|
+
assertDefined(verifiedCredential.walletName, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletName`);
|
|
1319
|
+
assertDefined(verifiedCredential.walletProvider, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing walletProvider`);
|
|
1320
|
+
assertDefined(verifiedCredential.chain, `Failed to get wallet provider for verified credential with ID ${verifiedCredential.id}: missing chain`);
|
|
1321
|
+
return { walletProviderKey: formatWalletProviderKey({
|
|
1322
|
+
chain: getChainFromVerifiedCredentialChain(verifiedCredential.chain),
|
|
1323
|
+
displayName: verifiedCredential.walletName,
|
|
1324
|
+
walletProviderType: verifiedCredential.walletProvider
|
|
1325
|
+
}) };
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
//#endregion
|
|
1329
|
+
//#region src/modules/wallets/utils/convertVerifiedCredentialToWalletAccount/convertVerifiedCredentialToWalletAccount.ts
|
|
1330
|
+
/** @not-instrumented */
|
|
1331
|
+
const convertVerifiedCredentialToWalletAccount = ({ verifiedCredential }, client) => {
|
|
1332
|
+
assertDefined(verifiedCredential.address, "Missing address in verified credential");
|
|
1333
|
+
assertDefined(verifiedCredential.chain, "Missing chain in verified credential");
|
|
1334
|
+
const chain = getChainFromVerifiedCredentialChain(verifiedCredential.chain);
|
|
1335
|
+
const { walletProviderKey } = getWalletProviderKeyFromVerifiedCredential({ verifiedCredential }, client);
|
|
1336
|
+
const walletAccountId = formatWalletAccountId({
|
|
1337
|
+
address: verifiedCredential.address,
|
|
1338
|
+
chain,
|
|
1339
|
+
walletProviderKey
|
|
1340
|
+
});
|
|
1341
|
+
return {
|
|
1342
|
+
address: verifiedCredential.address,
|
|
1343
|
+
addressesWithTypes: verifiedCredential.walletAdditionalAddresses,
|
|
1344
|
+
chain,
|
|
1345
|
+
hardwareWalletVendor: verifiedCredential.walletProperties?.hardwareWallet,
|
|
1346
|
+
id: walletAccountId,
|
|
1347
|
+
lastSelectedAt: verifiedCredential.lastSelectedAt ?? null,
|
|
1348
|
+
verifiedCredentialId: verifiedCredential.id,
|
|
1349
|
+
walletProviderKey
|
|
1350
|
+
};
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1353
|
+
//#endregion
|
|
1354
|
+
//#region src/modules/wallets/getWalletAccounts/getWalletAccountsFromState/getWalletAccountsFromState.ts
|
|
1355
|
+
/** @not-instrumented */
|
|
1356
|
+
const getWalletAccountsFromState = ({ unverifiedWalletAccounts, user }, client) => {
|
|
1357
|
+
const walletAccountsMap = /* @__PURE__ */ new Map();
|
|
1358
|
+
/**
|
|
1359
|
+
* Handle the unverified wallet accounts before the user verified credentials
|
|
1360
|
+
* so the later verified wallet accounts can override the unverified wallet accounts
|
|
1361
|
+
*/
|
|
1362
|
+
unverifiedWalletAccounts.forEach((unverifiedWalletAccount) => {
|
|
1363
|
+
const walletAccount = convertUnverifiedWalletAccountToWalletAccount({ unverifiedWalletAccount });
|
|
1364
|
+
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
1365
|
+
});
|
|
1366
|
+
(user?.verifiedCredentials ?? []).filter((verified) => verified.format === JwtVerifiedCredentialFormatEnum.Blockchain).forEach((verifiedWalletAccount) => {
|
|
1367
|
+
const walletAccount = convertVerifiedCredentialToWalletAccount({ verifiedCredential: verifiedWalletAccount }, client);
|
|
1368
|
+
walletAccountsMap.set(walletAccount.id, walletAccount);
|
|
1369
|
+
});
|
|
1370
|
+
return Array.from(walletAccountsMap.values());
|
|
1371
|
+
};
|
|
1372
|
+
|
|
1373
|
+
//#endregion
|
|
1374
|
+
//#region src/modules/wallets/getWalletAccounts/getWalletAccounts.ts
|
|
1375
|
+
/**
|
|
1376
|
+
* Retrieves all wallet accounts associated with the current session.
|
|
1377
|
+
*
|
|
1378
|
+
* This function returns both verified and unverified wallet accounts,
|
|
1379
|
+
* combining data from user credentials and local unverified accounts.
|
|
1380
|
+
* You can differentiate between verified and unverified wallet accounts by
|
|
1381
|
+
* checking the `verifiedCredentialId` property.
|
|
1382
|
+
*
|
|
1383
|
+
* @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.
|
|
1384
|
+
* @returns An array of wallet accounts associated with the session.
|
|
1385
|
+
* @not-instrumented
|
|
1386
|
+
*/
|
|
1387
|
+
const getWalletAccounts = (client = getDefaultClient()) => {
|
|
1388
|
+
const { unverifiedWalletAccounts, user } = getCore(client).state.get();
|
|
1389
|
+
return getWalletAccountsFromState({
|
|
1390
|
+
unverifiedWalletAccounts,
|
|
1391
|
+
user
|
|
1392
|
+
}, client);
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1395
|
+
//#endregion
|
|
1396
|
+
//#region src/errors/NoWalletProviderFoundError.ts
|
|
1397
|
+
var NoWalletProviderFoundError = class extends BaseError {
|
|
1398
|
+
constructor({ walletProviderKey }) {
|
|
1399
|
+
super({
|
|
1400
|
+
cause: null,
|
|
1401
|
+
code: "no_wallet_provider_found_error",
|
|
1402
|
+
docsUrl: null,
|
|
1403
|
+
name: "NoWalletProviderFoundError",
|
|
1404
|
+
shortMessage: `No wallet provider found with key: ${walletProviderKey}`
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
1408
|
+
|
|
1409
|
+
//#endregion
|
|
1410
|
+
//#region src/services/runtimeServices/createRuntimeServiceAccessKey/createRuntimeServiceAccessKey.ts
|
|
1411
|
+
/**
|
|
1412
|
+
* Creates a service accessor function that manages service instantiation and caching.
|
|
1413
|
+
* The returned function will either retrieve an existing service from the registry or
|
|
1414
|
+
* create a new one using the provided builder function.
|
|
1415
|
+
*
|
|
1416
|
+
* @template - The type of service to be created/accessed
|
|
1417
|
+
* @param key - Unique identifier for the service in the registry
|
|
1418
|
+
* @param builder - Function that creates the service instance when called with a DynamicClient
|
|
1419
|
+
* @not-instrumented
|
|
1420
|
+
*/
|
|
1421
|
+
const createRuntimeServiceAccessKey = (key, builder) => (client) => {
|
|
1422
|
+
const { runtimeServices } = getCore(client);
|
|
1423
|
+
const currentService = runtimeServices.getByKey(key);
|
|
1424
|
+
if (currentService) return currentService;
|
|
1425
|
+
const service = builder(client);
|
|
1426
|
+
runtimeServices.register(key, service);
|
|
1427
|
+
return service;
|
|
1428
|
+
};
|
|
1429
|
+
|
|
1430
|
+
//#endregion
|
|
1431
|
+
//#region src/modules/wallets/walletProviderRegistry/createWalletProviderRegistry/createWalletProviderRegistry.ts
|
|
1432
|
+
/**
|
|
1433
|
+
* Creates a new wallet provider registry that manages wallet providers with priority-based registration.
|
|
1434
|
+
*
|
|
1435
|
+
* @returns The wallet provider registry instance
|
|
1436
|
+
*
|
|
1437
|
+
* @example
|
|
1438
|
+
* ```typescript
|
|
1439
|
+
* const registry = createWalletProviderRegistry();
|
|
1440
|
+
*
|
|
1441
|
+
* registry.register({
|
|
1442
|
+
* priority: WalletProviderPriority.WALLET_SDK,
|
|
1443
|
+
* walletProvider: myWalletProvider
|
|
1444
|
+
* });
|
|
1445
|
+
*
|
|
1446
|
+
* const provider = registry.getByKey('my-wallet-key');
|
|
1447
|
+
* const providers = registry.listProviders();
|
|
1448
|
+
* ```
|
|
1449
|
+
* @not-instrumented
|
|
1450
|
+
*/
|
|
1451
|
+
const createWalletProviderRegistry = (client) => {
|
|
1452
|
+
const registry = /* @__PURE__ */ new Map();
|
|
1453
|
+
return {
|
|
1454
|
+
getByKey: (key) => registry.get(key)?.walletProvider,
|
|
1455
|
+
listProviderEntries: () => Array.from(registry.values()),
|
|
1456
|
+
listProviders: () => Array.from(registry.values()).map((v) => v.walletProvider),
|
|
1457
|
+
register: (args) => {
|
|
1458
|
+
const existingEntry = registry.get(args.walletProvider.key);
|
|
1459
|
+
if (existingEntry) {
|
|
1460
|
+
if (existingEntry.priority < args.priority) {
|
|
1461
|
+
registry.set(args.walletProvider.key, args);
|
|
1462
|
+
emitEvent({
|
|
1463
|
+
args: { walletProviderKey: args.walletProvider.key },
|
|
1464
|
+
event: "walletProviderChanged"
|
|
1465
|
+
}, client);
|
|
1466
|
+
}
|
|
1467
|
+
} else {
|
|
1468
|
+
registry.set(args.walletProvider.key, args);
|
|
1469
|
+
emitEvent({
|
|
1470
|
+
args: { walletProvider: args.walletProvider },
|
|
1471
|
+
event: "walletProviderRegistered"
|
|
1472
|
+
}, client);
|
|
1473
|
+
emitEvent({
|
|
1474
|
+
args: { walletProviderKey: args.walletProvider.key },
|
|
1475
|
+
event: "walletProviderChanged"
|
|
1476
|
+
}, client);
|
|
1477
|
+
}
|
|
1478
|
+
},
|
|
1479
|
+
unregister: (key) => {
|
|
1480
|
+
registry.delete(key);
|
|
1481
|
+
emitEvent({
|
|
1482
|
+
args: { walletProviderKey: key },
|
|
1483
|
+
event: "walletProviderUnregistered"
|
|
1484
|
+
}, client);
|
|
1485
|
+
}
|
|
1486
|
+
};
|
|
1487
|
+
};
|
|
1488
|
+
|
|
1489
|
+
//#endregion
|
|
1490
|
+
//#region src/modules/wallets/walletProviderRegistry/getWalletProviderRegistry/getWalletProviderRegistry.ts
|
|
1491
|
+
/**
|
|
1492
|
+
* This function provides access to a shared instance of the wallet provider registry.
|
|
1493
|
+
*
|
|
1494
|
+
* It ensures that the same registry instance is used throughout the client to maintaining
|
|
1495
|
+
* consistency of registered wallet providers across different parts of the codebase.
|
|
1496
|
+
*
|
|
1497
|
+
* @returns The wallet provider registry instance
|
|
1498
|
+
*
|
|
1499
|
+
* @example
|
|
1500
|
+
* ```typescript
|
|
1501
|
+
* // Get the registry instance
|
|
1502
|
+
* const registry = getWalletProviderRegistry();
|
|
1503
|
+
*
|
|
1504
|
+
* // Register a wallet provider
|
|
1505
|
+
* registry.register({
|
|
1506
|
+
* priority: WalletProviderPriority.WALLET_SDK,
|
|
1507
|
+
* walletProvider: myWalletProvider
|
|
1508
|
+
* });
|
|
1509
|
+
*
|
|
1510
|
+
* // Retrieve a specific provider
|
|
1511
|
+
* const provider = registry.getByKey('metamaskevm');
|
|
1512
|
+
* ```
|
|
1513
|
+
*/
|
|
1514
|
+
const getWalletProviderRegistry = createRuntimeServiceAccessKey("walletProviderRegistry", (client) => createWalletProviderRegistry(client));
|
|
1515
|
+
|
|
1516
|
+
//#endregion
|
|
1517
|
+
//#region src/modules/wallets/walletProviderRegistry/walletProviderRegistry.types.ts
|
|
1518
|
+
let WalletProviderPriority = /* @__PURE__ */ function(WalletProviderPriority$1) {
|
|
1519
|
+
/**
|
|
1520
|
+
* Highest priority should be used by wallet providers that implement
|
|
1521
|
+
* the most reliable wallet integration.
|
|
1522
|
+
* example: The SDK provided by the wallet provider.
|
|
1523
|
+
*/
|
|
1524
|
+
WalletProviderPriority$1[WalletProviderPriority$1["WALLET_SDK"] = 100] = "WALLET_SDK";
|
|
1525
|
+
/**
|
|
1526
|
+
* Medium priority should be used by wallet providers that implement
|
|
1527
|
+
* a wallet integration via some reliable standard.
|
|
1528
|
+
* example: A wallet provider that uses EIP6963 announcement.
|
|
1529
|
+
*/
|
|
1530
|
+
WalletProviderPriority$1[WalletProviderPriority$1["WALLET_SELF_ANNOUNCEMENT_STANDARD"] = 50] = "WALLET_SELF_ANNOUNCEMENT_STANDARD";
|
|
1531
|
+
/**
|
|
1532
|
+
* Low priority should be used by wallet providers that implement
|
|
1533
|
+
* a wallet integration on a less reliable standard.
|
|
1534
|
+
* example: A wallet provider that uses window.ethereum, where the
|
|
1535
|
+
* window key can be overridden by other extensions.
|
|
1536
|
+
*/
|
|
1537
|
+
WalletProviderPriority$1[WalletProviderPriority$1["WINDOW_INJECT"] = 20] = "WINDOW_INJECT";
|
|
1538
|
+
return WalletProviderPriority$1;
|
|
1539
|
+
}({});
|
|
1540
|
+
|
|
1541
|
+
//#endregion
|
|
1542
|
+
//#region src/modules/wallets/utils/getWalletProviderFromWalletAccount/getWalletProviderFromWalletAccount.ts
|
|
1543
|
+
/** @not-instrumented */
|
|
1544
|
+
const getWalletProviderFromWalletAccount = ({ walletAccount }, client) => {
|
|
1545
|
+
const walletProvider = getWalletProviderRegistry(client).getByKey(walletAccount.walletProviderKey);
|
|
1546
|
+
if (!walletProvider) throw new NoWalletProviderFoundError({ walletProviderKey: walletAccount.walletProviderKey });
|
|
1547
|
+
return walletProvider;
|
|
1548
|
+
};
|
|
1549
|
+
|
|
1550
|
+
//#endregion
|
|
1551
|
+
//#region src/modules/auth/consts.ts
|
|
1552
|
+
const DYNAMIC_AUTH_COOKIE_NAME = "DYNAMIC_JWT_TOKEN";
|
|
1553
|
+
|
|
1123
1554
|
//#endregion
|
|
1124
1555
|
//#region src/constants.ts
|
|
1125
1556
|
const SDK_API_CORE_VERSION = dependencies["@dynamic-labs/sdk-api-core"];
|
|
@@ -1150,5 +1581,5 @@ var InvalidParamError = class extends BaseError {
|
|
|
1150
1581
|
};
|
|
1151
1582
|
|
|
1152
1583
|
//#endregion
|
|
1153
|
-
export {
|
|
1154
|
-
//# sourceMappingURL=InvalidParamError-
|
|
1584
|
+
export { DYNAMIC_SDK_API_VERSION as $, UnauthorizedError as A, APIError as B, emitEvent as C, setCookie as D, onceEvent as E, SandboxMaximumThresholdReachedError as F, __getElevatedAccessToken_wrapped as G, isCookieEnabled as H, MfaRateLimitedError as I, DEFAULT_PII_FIELDS as J, instrumentFunction as K, MfaInvalidOtpError as L, getHeadersForNonceSignedByDeviceSigners as M, getDeviceSigner as N, fetchAndStoreNonces as O, getNonce as P, CLIENT_SDK_NAME as Q, LinkCredentialError as R, InvalidWalletProviderKeyError as S, onEvent as T, assertDefined as U, getSessionKeys as V, ValueMustBeDefinedError as W, extractSessionId as X, getUserAgent as Y, randomString as Z, getChainFromVerifiedCredentialChain as _, DYNAMIC_ICONIC_SPRITE_URL as a, getCore as at, normalizeAddress as b, getWalletProviderFromWalletAccount as c, createRuntimeServiceAccessKey as d, NONCE_POOL_SIZE as et, NoWalletProviderFoundError as f, normalizeWalletNameWithChain as g, formatWalletProviderKey as h, DYNAMIC_WAAS_METADATA as i, BaseError as it, createDeviceSignatureHeadersMiddleware as j, createApiClient as k, WalletProviderPriority as l, getWalletAccountsFromState as m, DEFAULT_WAAS_BASE_API_URL as n, setDefaultClient as nt, SDK_API_CORE_VERSION as o, name as ot, getWalletAccounts as p, scrubParameters as q, DEFAULT_WAAS_BASE_MPC_RELAY_API_URL as r, ClientNotFoundError as rt, DYNAMIC_AUTH_COOKIE_NAME as s, version as st, InvalidParamError as t, getDefaultClient as tt, getWalletProviderRegistry as u, CHAINS_INFO_MAP as v, offEvent as w, splitWalletProviderKey as x, formatWalletAccountId as y, InvalidExternalAuthError as z };
|
|
1585
|
+
//# sourceMappingURL=InvalidParamError-BKnC9rcJ.esm.js.map
|