@dynamic-labs-sdk/solana 0.15.0 → 0.16.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/dist/{addSolanaWalletStandardExtension-Bf8r6-4V.cjs.js → addSolanaWalletStandardExtension-0JyyakfO.cjs.js} +2 -2
- package/dist/{addSolanaWalletStandardExtension-Bf8r6-4V.cjs.js.map → addSolanaWalletStandardExtension-0JyyakfO.cjs.js.map} +1 -1
- package/dist/{addSolanaWalletStandardExtension-BngOUdym.esm.js → addSolanaWalletStandardExtension-CPT-KI29.esm.js} +2 -2
- package/dist/{addSolanaWalletStandardExtension-BngOUdym.esm.js.map → addSolanaWalletStandardExtension-CPT-KI29.esm.js.map} +1 -1
- package/dist/{addWaasSolanaExtension-BYxLx6fj.esm.js → addWaasSolanaExtension-CLhieXpF.esm.js} +4 -2
- package/dist/{addWaasSolanaExtension-BYxLx6fj.esm.js.map → addWaasSolanaExtension-CLhieXpF.esm.js.map} +1 -1
- package/dist/{addWaasSolanaExtension-CSzXRhvr.cjs.js → addWaasSolanaExtension-s5RmA285.cjs.js} +5 -3
- package/dist/{addWaasSolanaExtension-CSzXRhvr.cjs.js.map → addWaasSolanaExtension-s5RmA285.cjs.js.map} +1 -1
- package/dist/index.cjs.js +41 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +43 -42
- package/dist/index.esm.js.map +1 -1
- package/dist/phantomRedirect/addPhantomRedirectSolanaExtension/addPhantomRedirectSolanaExtension.d.ts.map +1 -1
- package/dist/phantomRedirect/completePhantomRedirect/completePhantomRedirect.d.ts.map +1 -1
- package/dist/phantomRedirect/createPhantomRedirectWalletProvider/createPhantomRedirectWalletProvider.d.ts.map +1 -1
- package/dist/phantomRedirect/detectPhantomRedirect/detectPhantomRedirect.d.ts +10 -0
- package/dist/phantomRedirect/detectPhantomRedirect/detectPhantomRedirect.d.ts.map +1 -1
- package/dist/{solanaTransferAmount-C1cnaJBQ.esm.js → solanaTransferAmount-Bd39IUO-.esm.js} +2 -2
- package/dist/{solanaTransferAmount-C1cnaJBQ.esm.js.map → solanaTransferAmount-Bd39IUO-.esm.js.map} +1 -1
- package/dist/{solanaTransferAmount-sL92hrfS.cjs.js → solanaTransferAmount-DQusACZn.cjs.js} +3 -3
- package/dist/{solanaTransferAmount-sL92hrfS.cjs.js.map → solanaTransferAmount-DQusACZn.cjs.js.map} +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/waas/utils/createWalletProviderForWaasSolana/createWalletProviderForWaasSolana.d.ts.map +1 -1
- package/dist/waas.cjs.js +3 -3
- package/dist/waas.esm.js +2 -2
- package/dist/walletStandard.cjs.js +2 -2
- package/dist/walletStandard.esm.js +2 -2
- package/package.json +5 -5
package/dist/index.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { a as isSolanaWalletProvider, c as getSolanaConnection, d as version, i as solanaExecuteCheckoutTransaction, l as registerSolanaNetworkProviderBuilder, n as isSolanaGasSponsorshipEnabled, o as isSolanaWalletAccount, r as NotSolanaProviderError, s as isVersionedTransaction, t as solanaTransferAmount, u as name } from "./solanaTransferAmount-
|
|
2
|
-
import { n as SponsorTransactionError, t as addWaasSolanaExtension } from "./addWaasSolanaExtension-
|
|
3
|
-
import { t as addSolanaWalletStandardExtension } from "./addSolanaWalletStandardExtension-
|
|
1
|
+
import { a as isSolanaWalletProvider, c as getSolanaConnection, d as version, i as solanaExecuteCheckoutTransaction, l as registerSolanaNetworkProviderBuilder, n as isSolanaGasSponsorshipEnabled, o as isSolanaWalletAccount, r as NotSolanaProviderError, s as isVersionedTransaction, t as solanaTransferAmount, u as name } from "./solanaTransferAmount-Bd39IUO-.esm.js";
|
|
2
|
+
import { n as SponsorTransactionError, t as addWaasSolanaExtension } from "./addWaasSolanaExtension-CLhieXpF.esm.js";
|
|
3
|
+
import { t as addSolanaWalletStandardExtension } from "./addSolanaWalletStandardExtension-CPT-KI29.esm.js";
|
|
4
4
|
import { assertPackageVersion } from "@dynamic-labs-sdk/assert-package-version";
|
|
5
|
-
import { MethodNotImplementedError, WalletProviderPriority, assertDefined, createApiClient, createDeferredPromise, createRuntimeServiceAccessKey, createStorageKeySchema, emitEvent, formatWalletProviderGroupKey, formatWalletProviderKey, getActiveNetworkIdFromLastKnownRegistry, getBuffer, getCore, getDefaultClient, getNetworkProviders, getWalletProviderFromWalletAccount, getWalletProviderRegistry, hasExtension, registerExtension } from "@dynamic-labs-sdk/client/core";
|
|
5
|
+
import { MethodNotImplementedError, WalletProviderPriority, assertDefined, createApiClient, createDeferredPromise, createRuntimeServiceAccessKey, createStorageKeySchema, emitEvent, formatWalletProviderGroupKey, formatWalletProviderKey, getActiveNetworkIdFromLastKnownRegistry, getBuffer, getCore, getDefaultClient, getNetworkProviders, getWalletProviderFromWalletAccount, getWalletProviderRegistry, hasExtension, randomString, registerExtension } from "@dynamic-labs-sdk/client/core";
|
|
6
6
|
import { Connection, LAMPORTS_PER_SOL, PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
7
|
-
import { BaseError, FeeEstimationFailedError, InvalidParamError, SimulationFailedError, getActiveNetworkData, getDefaultClient as getDefaultClient$1, onceEvent } from "@dynamic-labs-sdk/client";
|
|
7
|
+
import { BaseError, FeeEstimationFailedError, InvalidParamError, SimulationFailedError, getActiveNetworkData, getDefaultClient as getDefaultClient$1, onEvent, onceEvent } from "@dynamic-labs-sdk/client";
|
|
8
8
|
import { WalletProviderEnum } from "@dynamic-labs/sdk-api-core";
|
|
9
9
|
import bs58 from "bs58";
|
|
10
10
|
import * as z from "zod/mini";
|
|
@@ -459,12 +459,7 @@ const isCloneTab = (client) => !getPhantomOriginTab(client).isOriginTab;
|
|
|
459
459
|
const completeAndEmitPhantomRedirectEvent = async ({ args, event }, client) => {
|
|
460
460
|
const core = getCore(client);
|
|
461
461
|
const cloneTab = isCloneTab(client);
|
|
462
|
-
core.logger.debug("[PHANTOM] completeAndEmitPhantomRedirectEvent: start", {
|
|
463
|
-
event,
|
|
464
|
-
isCloneTab: cloneTab
|
|
465
|
-
});
|
|
466
462
|
await core.storage.removeItem(pendingRequestStorageKeySchema);
|
|
467
|
-
core.logger.debug("[PHANTOM] completeAndEmitPhantomRedirectEvent: emitting event locally", { event });
|
|
468
463
|
emitEvent({
|
|
469
464
|
args,
|
|
470
465
|
event
|
|
@@ -510,13 +505,8 @@ const completeAndEmitPhantomRedirectEvent = async ({ args, event }, client) => {
|
|
|
510
505
|
*/
|
|
511
506
|
const completePhantomRedirect = async ({ url }, client = getDefaultClient()) => {
|
|
512
507
|
const core = getCore(client);
|
|
513
|
-
core.logger.debug("[PHANTOM] completePhantomRedirect: start", { search: url.search });
|
|
514
508
|
const params = parsePhantomRedirectParams({ url });
|
|
515
509
|
const pendingRequest = await core.storage.getItem(pendingRequestStorageKeySchema);
|
|
516
|
-
core.logger.debug("[PHANTOM] completePhantomRedirect: pendingRequest", {
|
|
517
|
-
found: !!pendingRequest,
|
|
518
|
-
method: pendingRequest?.method
|
|
519
|
-
});
|
|
520
510
|
if (!pendingRequest) throw new NoPendingPhantomRequestError();
|
|
521
511
|
if (params.errorCode) {
|
|
522
512
|
const error = new PhantomRedirectRejectedError({
|
|
@@ -723,14 +713,6 @@ const listenForPhantomBroadcast = (listeners, client) => {
|
|
|
723
713
|
//#endregion
|
|
724
714
|
//#region src/phantomRedirect/createPhantomRedirectWalletProvider/createPhantomRedirectWalletProvider.ts
|
|
725
715
|
/**
|
|
726
|
-
* Generates a random alphanumeric string of specified length.
|
|
727
|
-
*/
|
|
728
|
-
const randomString = (length) => {
|
|
729
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
730
|
-
const bytes = crypto.getRandomValues(new Uint8Array(length));
|
|
731
|
-
return Array.from(bytes, (byte) => chars[byte % 62]).join("");
|
|
732
|
-
};
|
|
733
|
-
/**
|
|
734
716
|
* Extracts the dApp URL from a redirect URL.
|
|
735
717
|
*/
|
|
736
718
|
const extractDappUrl = (redirectUrl) => {
|
|
@@ -777,10 +759,6 @@ const createPhantomRedirectWalletProvider = ({ baseRedirectUrl, dynamicClient })
|
|
|
777
759
|
*/
|
|
778
760
|
const setupPhantomListeners = ({ completeEvent, deferredPromise, errorEvent, onComplete, onError }) => {
|
|
779
761
|
getPhantomOriginTab(dynamicClient).isOriginTab = true;
|
|
780
|
-
core.logger.debug("[PHANTOM] setupPhantomListeners: isOriginTab=true, registering listeners", {
|
|
781
|
-
completeEvent,
|
|
782
|
-
errorEvent
|
|
783
|
-
});
|
|
784
762
|
onceEvent({
|
|
785
763
|
event: completeEvent,
|
|
786
764
|
listener: onComplete
|
|
@@ -799,17 +777,15 @@ const createPhantomRedirectWalletProvider = ({ baseRedirectUrl, dynamicClient })
|
|
|
799
777
|
}).catch(() => {});
|
|
800
778
|
};
|
|
801
779
|
const connect = async () => {
|
|
802
|
-
core.logger.debug("[PHANTOM] connect: start");
|
|
803
780
|
const redirectUrl = baseRedirectUrl;
|
|
804
781
|
const { publicKey: dappPublicKey, secretKey: dappSecretKey } = generateNaClKeyPair();
|
|
805
782
|
await setPendingRequest({
|
|
806
783
|
dappPublicKey,
|
|
807
784
|
dappSecretKey,
|
|
808
785
|
method: "connect",
|
|
809
|
-
requestId: randomString(32),
|
|
786
|
+
requestId: randomString({ length: 32 }),
|
|
810
787
|
timestamp: Date.now()
|
|
811
788
|
});
|
|
812
|
-
core.logger.debug("[PHANTOM] connect: pending request stored, setting up listeners");
|
|
813
789
|
const deferredPromise = createDeferredPromise();
|
|
814
790
|
setupPhantomListeners({
|
|
815
791
|
completeEvent: "phantomRedirectConnectionComplete",
|
|
@@ -835,12 +811,8 @@ const createPhantomRedirectWalletProvider = ({ baseRedirectUrl, dynamicClient })
|
|
|
835
811
|
method: "connect",
|
|
836
812
|
redirectUrl
|
|
837
813
|
});
|
|
838
|
-
core.logger.debug("[PHANTOM] connect: opening deeplink", {
|
|
839
|
-
deepLinkUrl: deepLinkUrl.toString(),
|
|
840
|
-
redirectUrl
|
|
841
|
-
});
|
|
814
|
+
core.logger.debug("[PHANTOM] connect: opening deeplink", { redirectUrl });
|
|
842
815
|
await core.openDeeplink(deepLinkUrl.toString());
|
|
843
|
-
core.logger.debug("[PHANTOM] connect: deeplink opened, awaiting deferred promise");
|
|
844
816
|
return deferredPromise.promise;
|
|
845
817
|
};
|
|
846
818
|
const disconnect = async () => {
|
|
@@ -850,7 +822,7 @@ const createPhantomRedirectWalletProvider = ({ baseRedirectUrl, dynamicClient })
|
|
|
850
822
|
payload: { session: session.sessionToken },
|
|
851
823
|
sharedSecret: session.sharedSecret
|
|
852
824
|
});
|
|
853
|
-
const requestId = randomString(32);
|
|
825
|
+
const requestId = randomString({ length: 32 });
|
|
854
826
|
await setPendingRequest({
|
|
855
827
|
dappPublicKey: session.dappPublicKey,
|
|
856
828
|
dappSecretKey: session.dappSecretKey,
|
|
@@ -900,7 +872,7 @@ const createPhantomRedirectWalletProvider = ({ baseRedirectUrl, dynamicClient })
|
|
|
900
872
|
},
|
|
901
873
|
sharedSecret: session.sharedSecret
|
|
902
874
|
});
|
|
903
|
-
const requestId = randomString(32);
|
|
875
|
+
const requestId = randomString({ length: 32 });
|
|
904
876
|
await setPendingRequest({
|
|
905
877
|
dappPublicKey: session.dappPublicKey,
|
|
906
878
|
dappSecretKey: session.dappSecretKey,
|
|
@@ -954,7 +926,7 @@ const createPhantomRedirectWalletProvider = ({ baseRedirectUrl, dynamicClient })
|
|
|
954
926
|
},
|
|
955
927
|
sharedSecret: session.sharedSecret
|
|
956
928
|
});
|
|
957
|
-
const requestId = randomString(32);
|
|
929
|
+
const requestId = randomString({ length: 32 });
|
|
958
930
|
await setPendingRequest({
|
|
959
931
|
dappPublicKey: session.dappPublicKey,
|
|
960
932
|
dappSecretKey: session.dappSecretKey,
|
|
@@ -1009,7 +981,7 @@ const createPhantomRedirectWalletProvider = ({ baseRedirectUrl, dynamicClient })
|
|
|
1009
981
|
},
|
|
1010
982
|
sharedSecret: session.sharedSecret
|
|
1011
983
|
});
|
|
1012
|
-
const requestId = randomString(32);
|
|
984
|
+
const requestId = randomString({ length: 32 });
|
|
1013
985
|
await setPendingRequest({
|
|
1014
986
|
dappPublicKey: session.dappPublicKey,
|
|
1015
987
|
dappSecretKey: session.dappSecretKey,
|
|
@@ -1090,16 +1062,28 @@ const createPhantomRedirectWalletProvider = ({ baseRedirectUrl, dynamicClient })
|
|
|
1090
1062
|
* redirect data from a Phantom wallet deep link operation, and validates
|
|
1091
1063
|
* that there is a corresponding pending request in storage.
|
|
1092
1064
|
*
|
|
1065
|
+
* Most Phantom callbacks include recognizable query parameters:
|
|
1066
|
+
* - **Connect**: `phantom_encryption_public_key`
|
|
1067
|
+
* - **Sign** (signMessage, signTransaction, etc.): `nonce` + `data`
|
|
1068
|
+
* - **Error** (any method): `errorCode`
|
|
1069
|
+
*
|
|
1070
|
+
* **Disconnect is the exception**: on success, Phantom redirects back to the
|
|
1071
|
+
* bare `redirect_link` with NO query parameters at all. To detect this case,
|
|
1072
|
+
* we fall back to checking whether a pending disconnect request exists in
|
|
1073
|
+
* storage.
|
|
1074
|
+
*
|
|
1093
1075
|
* @param params.url - The URL to check for Phantom redirect parameters
|
|
1094
1076
|
* @param client - The Dynamic client instance
|
|
1095
1077
|
* @returns A promise that resolves to true if the URL is a valid Phantom redirect, false otherwise
|
|
1096
1078
|
*/
|
|
1097
1079
|
const detectPhantomRedirect = async ({ url }, client = getDefaultClient()) => {
|
|
1098
1080
|
const core = getCore(client);
|
|
1099
|
-
|
|
1081
|
+
const hasPhantomParams = url.searchParams.has("phantom_encryption_public_key") || url.searchParams.has("errorCode") || url.searchParams.has("nonce") && url.searchParams.has("data");
|
|
1100
1082
|
await core.initTrack.waitForAll();
|
|
1101
1083
|
const pendingRequest = await core.storage.getItem(pendingRequestStorageKeySchema);
|
|
1102
|
-
|
|
1084
|
+
if (!pendingRequest) return false;
|
|
1085
|
+
if (hasPhantomParams) return true;
|
|
1086
|
+
return pendingRequest.method === "disconnect";
|
|
1103
1087
|
};
|
|
1104
1088
|
|
|
1105
1089
|
//#endregion
|
|
@@ -1175,10 +1159,27 @@ const addPhantomRedirectSolanaExtension = async ({ disableAutoRedirectCompletion
|
|
|
1175
1159
|
baseRedirectUrl: `${url.protocol}//${url.host}${url.pathname}`,
|
|
1176
1160
|
dynamicClient: client
|
|
1177
1161
|
});
|
|
1178
|
-
getWalletProviderRegistry(client)
|
|
1162
|
+
const walletProviderRegistry = getWalletProviderRegistry(client);
|
|
1163
|
+
const isConflictingProvider = (provider) => provider.chain === walletProvider.chain && provider.groupKey === walletProvider.groupKey && provider.key !== walletProvider.key;
|
|
1164
|
+
const existingConflict = walletProviderRegistry.listProviders().find(isConflictingProvider);
|
|
1165
|
+
if (existingConflict) {
|
|
1166
|
+
core.logger.debug("[PHANTOM] addPhantomRedirectSolanaExtension: skipping registration, conflicting provider exists", { conflictingKey: existingConflict.key });
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
walletProviderRegistry.register({
|
|
1179
1170
|
priority: WalletProviderPriority.WINDOW_INJECT,
|
|
1180
1171
|
walletProvider
|
|
1181
1172
|
});
|
|
1173
|
+
const removeListener = onEvent({
|
|
1174
|
+
event: "walletProviderRegistered",
|
|
1175
|
+
listener: ({ walletProvider: newProvider }) => {
|
|
1176
|
+
if (isConflictingProvider(newProvider)) {
|
|
1177
|
+
core.logger.debug("[PHANTOM] addPhantomRedirectSolanaExtension: unregistering, conflicting provider registered", { conflictingKey: newProvider.key });
|
|
1178
|
+
walletProviderRegistry.unregister(walletProvider.key);
|
|
1179
|
+
removeListener();
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}, client);
|
|
1182
1183
|
};
|
|
1183
1184
|
|
|
1184
1185
|
//#endregion
|