@dynamic-labs/embedded-wallet-solana 3.0.0-alpha.42 → 3.0.0-alpha.44

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 (29) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/package.cjs +22 -0
  3. package/package.js +17 -0
  4. package/package.json +12 -9
  5. package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.cjs +32 -4
  6. package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.d.ts +1 -0
  7. package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.js +32 -4
  8. package/src/lib/utils/api/api.cjs +38 -0
  9. package/src/lib/utils/api/api.d.ts +4 -0
  10. package/src/lib/utils/api/api.js +32 -0
  11. package/src/lib/utils/api/events/DynamicEvents.cjs +14 -0
  12. package/src/lib/utils/api/events/DynamicEvents.d.ts +6 -0
  13. package/src/lib/utils/api/events/DynamicEvents.js +6 -0
  14. package/src/lib/utils/api/events/auth.d.ts +51 -0
  15. package/src/lib/utils/api/utils/ApiEndpoint.cjs +41 -0
  16. package/src/lib/utils/api/utils/ApiEndpoint.d.ts +7 -0
  17. package/src/lib/utils/api/utils/ApiEndpoint.js +39 -0
  18. package/src/lib/utils/api/utils/LocalStorage.cjs +81 -0
  19. package/src/lib/utils/api/utils/LocalStorage.d.ts +26 -0
  20. package/src/lib/utils/api/utils/LocalStorage.js +75 -0
  21. package/src/lib/utils/api/utils/SdkApi.cjs +35 -0
  22. package/src/lib/utils/api/utils/SdkApi.d.ts +2 -0
  23. package/src/lib/utils/api/utils/SdkApi.js +31 -0
  24. package/src/lib/utils/api/utils/helpers.cjs +88 -0
  25. package/src/lib/utils/api/utils/helpers.d.ts +12 -0
  26. package/src/lib/utils/api/utils/helpers.js +77 -0
  27. package/src/lib/utils/api/utils/version.cjs +12 -0
  28. package/src/lib/utils/api/utils/version.d.ts +2 -0
  29. package/src/lib/utils/api/utils/version.js +7 -0
package/CHANGELOG.md CHANGED
@@ -1,4 +1,34 @@
1
1
 
2
+ ## [3.0.0-alpha.44](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.43...v3.0.0-alpha.44) (2024-08-15)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * populate wallet new isPrimary flag ([#6597](https://github.com/dynamic-labs/DynamicAuth/issues/6597)) ([7809f81](https://github.com/dynamic-labs/DynamicAuth/commit/7809f81c9743b8bf7bc27dc34cf45923cf9baf99))
8
+ * twitter should no longer rely polling for oauth flow ([#6603](https://github.com/dynamic-labs/DynamicAuth/issues/6603)) ([09aea8b](https://github.com/dynamic-labs/DynamicAuth/commit/09aea8b3f197c25dcfb5bc72049b90859df246f3))
9
+
10
+ ## [3.0.0-alpha.43](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.42...v3.0.0-alpha.43) (2024-08-15)
11
+
12
+
13
+ ### ⚠ BREAKING CHANGES
14
+
15
+ * removes walletConnector from dynamic context (#6579)
16
+ * removed deprecated props from user profile (#6589)
17
+
18
+ ### Features
19
+
20
+ * optimize solana embedded transactions ([#6582](https://github.com/dynamic-labs/DynamicAuth/issues/6582)) ([419aff9](https://github.com/dynamic-labs/DynamicAuth/commit/419aff96d312892d7db520e94ecc6956b8de771d))
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * check if wallet is connected using normalized addresses ([#6594](https://github.com/dynamic-labs/DynamicAuth/issues/6594)) ([44aabae](https://github.com/dynamic-labs/DynamicAuth/commit/44aabae8ee72261bf0f7e308ed4adf0f42760ed2))
26
+ * minor sdk ui updates ([#6590](https://github.com/dynamic-labs/DynamicAuth/issues/6590)) ([8619e40](https://github.com/dynamic-labs/DynamicAuth/commit/8619e40e1afff8d68357138f3b5b9b89989140fd))
27
+
28
+
29
+ * removed deprecated props from user profile ([#6589](https://github.com/dynamic-labs/DynamicAuth/issues/6589)) ([b621da8](https://github.com/dynamic-labs/DynamicAuth/commit/b621da8a0703eb8228a5b10131af2717f314fd2e))
30
+ * removes walletConnector from dynamic context ([#6579](https://github.com/dynamic-labs/DynamicAuth/issues/6579)) ([51d69fe](https://github.com/dynamic-labs/DynamicAuth/commit/51d69feebab71158ad2aa69f11001623a0aaa80a))
31
+
2
32
  ## [3.0.0-alpha.42](https://github.com/dynamic-labs/DynamicAuth/compare/v3.0.0-alpha.41...v3.0.0-alpha.42) (2024-08-14)
3
33
 
4
34
 
package/package.cjs ADDED
@@ -0,0 +1,22 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var version = "3.0.0-alpha.44";
7
+ var dependencies = {
8
+ "@dynamic-labs/sdk-api-core": "0.0.516",
9
+ "@dynamic-labs/utils": "3.0.0-alpha.44",
10
+ "@dynamic-labs/logger": "3.0.0-alpha.44",
11
+ "@dynamic-labs/types": "3.0.0-alpha.44",
12
+ eventemitter3: "5.0.1",
13
+ "@solana/spl-token": "0.4.6",
14
+ "@solana/web3.js": "1.92.1",
15
+ "@turnkey/http": "2.7.1",
16
+ "@turnkey/iframe-stamper": "2.0.0",
17
+ "@turnkey/solana": "0.3.1",
18
+ "@turnkey/webauthn-stamper": "0.5.0"
19
+ };
20
+
21
+ exports.dependencies = dependencies;
22
+ exports.version = version;
package/package.js ADDED
@@ -0,0 +1,17 @@
1
+ 'use client'
2
+ var version = "3.0.0-alpha.44";
3
+ var dependencies = {
4
+ "@dynamic-labs/sdk-api-core": "0.0.516",
5
+ "@dynamic-labs/utils": "3.0.0-alpha.44",
6
+ "@dynamic-labs/logger": "3.0.0-alpha.44",
7
+ "@dynamic-labs/types": "3.0.0-alpha.44",
8
+ eventemitter3: "5.0.1",
9
+ "@solana/spl-token": "0.4.6",
10
+ "@solana/web3.js": "1.92.1",
11
+ "@turnkey/http": "2.7.1",
12
+ "@turnkey/iframe-stamper": "2.0.0",
13
+ "@turnkey/solana": "0.3.1",
14
+ "@turnkey/webauthn-stamper": "0.5.0"
15
+ };
16
+
17
+ export { dependencies, version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/embedded-wallet-solana",
3
- "version": "3.0.0-alpha.42",
3
+ "version": "3.0.0-alpha.44",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/dynamic-labs/dynamic-auth.git",
@@ -27,20 +27,23 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@dynamic-labs/sdk-api-core": "0.0.516",
30
+ "@dynamic-labs/utils": "3.0.0-alpha.44",
31
+ "@dynamic-labs/logger": "3.0.0-alpha.44",
32
+ "@dynamic-labs/types": "3.0.0-alpha.44",
33
+ "eventemitter3": "5.0.1",
30
34
  "@solana/spl-token": "0.4.6",
31
35
  "@solana/web3.js": "1.92.1",
32
36
  "@turnkey/http": "2.7.1",
33
37
  "@turnkey/iframe-stamper": "2.0.0",
34
38
  "@turnkey/solana": "0.3.1",
35
39
  "@turnkey/webauthn-stamper": "0.5.0",
36
- "@dynamic-labs/embedded-wallet": "3.0.0-alpha.42",
37
- "@dynamic-labs/rpc-provider-solana": "3.0.0-alpha.42",
38
- "@dynamic-labs/rpc-providers": "3.0.0-alpha.42",
39
- "@dynamic-labs/solana-utils": "3.0.0-alpha.42",
40
- "@dynamic-labs/types": "3.0.0-alpha.42",
41
- "@dynamic-labs/utils": "3.0.0-alpha.42",
42
- "@dynamic-labs/wallet-book": "3.0.0-alpha.42",
43
- "@dynamic-labs/wallet-connector-core": "3.0.0-alpha.42",
40
+ "@dynamic-labs/embedded-wallet": "3.0.0-alpha.44",
41
+ "@dynamic-labs/rpc-provider-solana": "3.0.0-alpha.44",
42
+ "@dynamic-labs/rpc-providers": "3.0.0-alpha.44",
43
+ "@dynamic-labs/solana-utils": "3.0.0-alpha.44",
44
+ "@dynamic-labs/wallet-book": "3.0.0-alpha.44",
45
+ "@dynamic-labs/wallet-connector-core": "3.0.0-alpha.44",
46
+ "react-dom": "18.2.0",
44
47
  "viem": "2.9.25"
45
48
  },
46
49
  "peerDependencies": {}
@@ -16,6 +16,7 @@ var embeddedWallet = require('@dynamic-labs/embedded-wallet');
16
16
  var createSolanaConnection = require('../utils/createSolanaConnection/createSolanaConnection.cjs');
17
17
  var getGenesisHashLSKey = require('../utils/getGenesisHashLSKey/getGenesisHashLSKey.cjs');
18
18
  var transactionDecoder = require('../utils/transactionDecoder/transactionDecoder.cjs');
19
+ var api = require('../utils/api/api.cjs');
19
20
  var TurnkeySolanaSigner = require('./TurnkeySolanaSigner.cjs');
20
21
 
21
22
  class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnectorBase {
@@ -26,6 +27,23 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
26
27
  this.connectedChain = 'SOL';
27
28
  this.supportedChains = ['SOL'];
28
29
  this.verifiedCredentialChain = 'solana';
30
+ this.getEnvId = () => {
31
+ const dynamicNonce = localStorage.getItem('dynamic_nonce');
32
+ if (dynamicNonce) {
33
+ const parsed = JSON.parse(dynamicNonce);
34
+ if (parsed && parsed.environmentId) {
35
+ return parsed.environmentId;
36
+ }
37
+ }
38
+ const dynamicNonceDemo = localStorage.getItem('dynamic_nonce_demo');
39
+ if (dynamicNonceDemo) {
40
+ const parsed = JSON.parse(dynamicNonceDemo);
41
+ if (parsed && parsed.environmentId) {
42
+ return parsed.environmentId;
43
+ }
44
+ }
45
+ throw new Error('Failed to get environment id');
46
+ };
29
47
  this.stampCreateWalletAccountRequest = (_b) => _tslib.__awaiter(this, [_b], void 0, function* ({ request, }) {
30
48
  const turnkeyClient = this.getTurnkeyClient();
31
49
  return turnkeyClient.stampCreateWalletAccounts(request);
@@ -289,16 +307,26 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
289
307
  }
290
308
  signAndSendTransaction(transaction, options) {
291
309
  return _tslib.__awaiter(this, void 0, void 0, function* () {
310
+ var _a;
292
311
  if (!this.turnkeyAddress)
293
312
  throw new utils.DynamicError('Solana wallet not found');
294
- const transactionsData = yield transactionDecoder.decodeTransaction(transaction, this.getConnection(), this.turnkeyAddress);
313
+ let optimizedTransaction = transaction;
314
+ try {
315
+ if ((yield this.getNetwork()) === 'mainnet') {
316
+ optimizedTransaction = (yield api.optimizeSolanaTransaction(this.getEnvId(), transaction, (_a = this.turnkeyAddress) !== null && _a !== void 0 ? _a : ''));
317
+ }
318
+ }
319
+ catch (e) {
320
+ embeddedWallet.logger.warn('Failed to optimize transaction', e);
321
+ }
322
+ const transactionsData = yield transactionDecoder.decodeTransaction(optimizedTransaction, this.getConnection(), this.turnkeyAddress);
295
323
  if (!(transactionsData === null || transactionsData === void 0 ? void 0 : transactionsData.length)) {
296
324
  throw new utils.DynamicError('Incorrectly formatted transaction instructions');
297
325
  }
298
326
  let spent;
299
327
  let insufficientFunds = false;
300
328
  try {
301
- spent = yield transactionDecoder.getTotalSolanaSpend(transaction, this.getConnection(), this.turnkeyAddress);
329
+ spent = yield transactionDecoder.getTotalSolanaSpend(optimizedTransaction, this.getConnection(), this.turnkeyAddress);
302
330
  }
303
331
  catch (e) {
304
332
  if (e.message === 'Insufficient funds') {
@@ -309,8 +337,8 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
309
337
  const uiTransaction = new solanaUtils.SolanaUiTransaction({
310
338
  connection: this.getConnection(),
311
339
  from: this.turnkeyAddress,
312
- onSubmit: () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSignAndSendTransaction(transaction, options); }),
313
- originalTransaction: transaction,
340
+ onSubmit: () => _tslib.__awaiter(this, void 0, void 0, function* () { return this.internalSignAndSendTransaction(optimizedTransaction, options); }),
341
+ originalTransaction: optimizedTransaction,
314
342
  });
315
343
  uiTransaction.to = to;
316
344
  uiTransaction.value = spent;
@@ -43,6 +43,7 @@ export declare class TurnkeySolanaWalletConnector extends TurnkeyWalletConnector
43
43
  getSigner(): Promise<TurnkeySolanaSigner | undefined>;
44
44
  getBalance(address: string): Promise<string | undefined>;
45
45
  signUint8ArrayMessage(encodedMessage: Uint8Array): Promise<Uint8Array>;
46
+ getEnvId: () => any;
46
47
  signMessage(messageToSign: string): Promise<string | undefined>;
47
48
  signTransaction<T extends Transaction | VersionedTransaction>(transaction: T): Promise<T>;
48
49
  internalSignAndSendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, options?: SendOptions): Promise<string>;
@@ -12,6 +12,7 @@ import { TurnkeyWalletConnectorBase, findTurnkeyVerifiedCredential, PasskeyServi
12
12
  import { createSolanaConnection } from '../utils/createSolanaConnection/createSolanaConnection.js';
13
13
  import { getGenesisHashLSKey } from '../utils/getGenesisHashLSKey/getGenesisHashLSKey.js';
14
14
  import { decodeTransaction, getTotalSolanaSpend, summarizeTransactionDecodedData } from '../utils/transactionDecoder/transactionDecoder.js';
15
+ import { optimizeSolanaTransaction } from '../utils/api/api.js';
15
16
  import { TurnkeySolanaSigner } from './TurnkeySolanaSigner.js';
16
17
 
17
18
  class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase {
@@ -22,6 +23,23 @@ class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase {
22
23
  this.connectedChain = 'SOL';
23
24
  this.supportedChains = ['SOL'];
24
25
  this.verifiedCredentialChain = 'solana';
26
+ this.getEnvId = () => {
27
+ const dynamicNonce = localStorage.getItem('dynamic_nonce');
28
+ if (dynamicNonce) {
29
+ const parsed = JSON.parse(dynamicNonce);
30
+ if (parsed && parsed.environmentId) {
31
+ return parsed.environmentId;
32
+ }
33
+ }
34
+ const dynamicNonceDemo = localStorage.getItem('dynamic_nonce_demo');
35
+ if (dynamicNonceDemo) {
36
+ const parsed = JSON.parse(dynamicNonceDemo);
37
+ if (parsed && parsed.environmentId) {
38
+ return parsed.environmentId;
39
+ }
40
+ }
41
+ throw new Error('Failed to get environment id');
42
+ };
25
43
  this.stampCreateWalletAccountRequest = (_b) => __awaiter(this, [_b], void 0, function* ({ request, }) {
26
44
  const turnkeyClient = this.getTurnkeyClient();
27
45
  return turnkeyClient.stampCreateWalletAccounts(request);
@@ -285,16 +303,26 @@ class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase {
285
303
  }
286
304
  signAndSendTransaction(transaction, options) {
287
305
  return __awaiter(this, void 0, void 0, function* () {
306
+ var _a;
288
307
  if (!this.turnkeyAddress)
289
308
  throw new DynamicError('Solana wallet not found');
290
- const transactionsData = yield decodeTransaction(transaction, this.getConnection(), this.turnkeyAddress);
309
+ let optimizedTransaction = transaction;
310
+ try {
311
+ if ((yield this.getNetwork()) === 'mainnet') {
312
+ optimizedTransaction = (yield optimizeSolanaTransaction(this.getEnvId(), transaction, (_a = this.turnkeyAddress) !== null && _a !== void 0 ? _a : ''));
313
+ }
314
+ }
315
+ catch (e) {
316
+ logger.warn('Failed to optimize transaction', e);
317
+ }
318
+ const transactionsData = yield decodeTransaction(optimizedTransaction, this.getConnection(), this.turnkeyAddress);
291
319
  if (!(transactionsData === null || transactionsData === void 0 ? void 0 : transactionsData.length)) {
292
320
  throw new DynamicError('Incorrectly formatted transaction instructions');
293
321
  }
294
322
  let spent;
295
323
  let insufficientFunds = false;
296
324
  try {
297
- spent = yield getTotalSolanaSpend(transaction, this.getConnection(), this.turnkeyAddress);
325
+ spent = yield getTotalSolanaSpend(optimizedTransaction, this.getConnection(), this.turnkeyAddress);
298
326
  }
299
327
  catch (e) {
300
328
  if (e.message === 'Insufficient funds') {
@@ -305,8 +333,8 @@ class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase {
305
333
  const uiTransaction = new SolanaUiTransaction({
306
334
  connection: this.getConnection(),
307
335
  from: this.turnkeyAddress,
308
- onSubmit: () => __awaiter(this, void 0, void 0, function* () { return this.internalSignAndSendTransaction(transaction, options); }),
309
- originalTransaction: transaction,
336
+ onSubmit: () => __awaiter(this, void 0, void 0, function* () { return this.internalSignAndSendTransaction(optimizedTransaction, options); }),
337
+ originalTransaction: optimizedTransaction,
310
338
  });
311
339
  uiTransaction.to = to;
312
340
  uiTransaction.value = spent;
@@ -0,0 +1,38 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../_virtual/_tslib.cjs');
7
+ var web3_js = require('@solana/web3.js');
8
+ var SdkApi = require('./utils/SdkApi.cjs');
9
+
10
+ const serializeTransaction = (transaction) => {
11
+ if (transaction instanceof web3_js.VersionedTransaction) {
12
+ return Buffer.from(transaction.serialize()).toString('base64');
13
+ }
14
+ else {
15
+ return Buffer.from(transaction.serialize({ verifySignatures: false })).toString('base64');
16
+ }
17
+ };
18
+ const deserializeTransaction = (serializedTransaction) => {
19
+ const transactionBuffer = Buffer.from(serializedTransaction, 'base64');
20
+ return web3_js.VersionedTransaction.deserialize(transactionBuffer);
21
+ };
22
+ const optimizeSolanaTransaction = (environmentId, transaction, address) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
23
+ const serializedTransaction = serializeTransaction(transaction);
24
+ const request = {
25
+ environmentId,
26
+ solanaTransactionOptimizationRequest: {
27
+ address,
28
+ transaction: serializedTransaction,
29
+ },
30
+ };
31
+ const response = yield SdkApi.sdkApi().optimizeTransaction(request);
32
+ const optimizedTransaction = deserializeTransaction(response.transaction);
33
+ return optimizedTransaction;
34
+ });
35
+
36
+ exports.deserializeTransaction = deserializeTransaction;
37
+ exports.optimizeSolanaTransaction = optimizeSolanaTransaction;
38
+ exports.serializeTransaction = serializeTransaction;
@@ -0,0 +1,4 @@
1
+ import { Transaction, VersionedTransaction } from '@solana/web3.js';
2
+ export declare const serializeTransaction: (transaction: Transaction | VersionedTransaction) => string;
3
+ export declare const deserializeTransaction: (serializedTransaction: string) => VersionedTransaction;
4
+ export declare const optimizeSolanaTransaction: (environmentId: string, transaction: Transaction | VersionedTransaction, address: string) => Promise<VersionedTransaction>;
@@ -0,0 +1,32 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../../_virtual/_tslib.js';
3
+ import { VersionedTransaction } from '@solana/web3.js';
4
+ import { sdkApi } from './utils/SdkApi.js';
5
+
6
+ const serializeTransaction = (transaction) => {
7
+ if (transaction instanceof VersionedTransaction) {
8
+ return Buffer.from(transaction.serialize()).toString('base64');
9
+ }
10
+ else {
11
+ return Buffer.from(transaction.serialize({ verifySignatures: false })).toString('base64');
12
+ }
13
+ };
14
+ const deserializeTransaction = (serializedTransaction) => {
15
+ const transactionBuffer = Buffer.from(serializedTransaction, 'base64');
16
+ return VersionedTransaction.deserialize(transactionBuffer);
17
+ };
18
+ const optimizeSolanaTransaction = (environmentId, transaction, address) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const serializedTransaction = serializeTransaction(transaction);
20
+ const request = {
21
+ environmentId,
22
+ solanaTransactionOptimizationRequest: {
23
+ address,
24
+ transaction: serializedTransaction,
25
+ },
26
+ };
27
+ const response = yield sdkApi().optimizeTransaction(request);
28
+ const optimizedTransaction = deserializeTransaction(response.transaction);
29
+ return optimizedTransaction;
30
+ });
31
+
32
+ export { deserializeTransaction, optimizeSolanaTransaction, serializeTransaction };
@@ -0,0 +1,14 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var EventEmitter = require('eventemitter3');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
11
+
12
+ const dynamicEvents = new EventEmitter__default["default"]();
13
+
14
+ exports.dynamicEvents = dynamicEvents;
@@ -0,0 +1,6 @@
1
+ import EventEmitter from 'eventemitter3';
2
+ import { AuthEvents } from './auth';
3
+ /** Maps internal event names to their listeners */
4
+ export type DynamicEvents = AuthEvents;
5
+ export declare const dynamicEvents: EventEmitter<AuthEvents, any>;
6
+ export type DynamicEventEmitter = typeof dynamicEvents;
@@ -0,0 +1,6 @@
1
+ 'use client'
2
+ import EventEmitter from 'eventemitter3';
3
+
4
+ const dynamicEvents = new EventEmitter();
5
+
6
+ export { dynamicEvents };
@@ -0,0 +1,51 @@
1
+ import { AuthMethod, AuthOptions } from '@dynamic-labs/types';
2
+ /**
3
+ * Maps auth methods to what property will be displayed under the "option" property of the event.
4
+ *
5
+ * Users will be able to access this data through the AuthOptions[K] type injection as well,
6
+ * but with the "option" property they will also have a standard way to access the auth method target.
7
+ */
8
+ type AuthEventPayloadOptionMap = {
9
+ wallet: AuthOptions['wallet']['connectorName'];
10
+ sms: AuthOptions['sms']['phone'];
11
+ email: AuthOptions['email']['email'];
12
+ social: AuthOptions['social']['provider'];
13
+ externalAuth: AuthOptions['externalAuth']['externalUserId'];
14
+ };
15
+ /** Payload of auth events that provide insight into which auth method was selected */
16
+ export type AuthEventPayload = {
17
+ [K in AuthMethod]: {
18
+ type: K;
19
+ option: AuthEventPayloadOptionMap[K];
20
+ } & AuthOptions[K];
21
+ }[AuthMethod];
22
+ export type AuthEvents = {
23
+ /**
24
+ * Informs an auth attempt failed.
25
+ * In general triggered when an error occurs or when user cancels out.
26
+ * For email/sms, specifically happens when users cancels the OTP verification.
27
+ */
28
+ authFailure: (method: AuthEventPayload,
29
+ /** Will be 'user-cancelled' when cancelled, or the error when there is an error */
30
+ reason: 'user-cancelled' | {
31
+ error: unknown;
32
+ }) => void;
33
+ /** Informs an auth attempt initialized, and provides insight into which auth option it is */
34
+ authInit: (method: AuthEventPayload) => void;
35
+ logout: () => void;
36
+ /** This event is used to trigger logout to be called, DO NOT listen to it. Listen to "logout" instead */
37
+ triggerLogout: () => void;
38
+ /**
39
+ * Emitted when the user succesfully completes an MFA challenge
40
+ */
41
+ mfaCompletionSuccess: (args: {
42
+ mfaToken?: string;
43
+ }) => void;
44
+ /**
45
+ * Emitted when there is an error verifiyng the MFA challenge
46
+ */
47
+ mfaCompletionFailure: (args: {
48
+ error: unknown;
49
+ }) => void;
50
+ };
51
+ export {};
@@ -0,0 +1,41 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
5
+
6
+ /* eslint-disable no-underscore-dangle */
7
+ class ApiEndpoint {
8
+ }
9
+ ApiEndpoint.getBaseUrl = () => {
10
+ if (!ApiEndpoint.__defined__) {
11
+ throw new Error('ApiEndpoint Base URL has not been initialized');
12
+ }
13
+ return ApiEndpoint.__baseUrl__;
14
+ };
15
+ ApiEndpoint.setBaseUrl = (baseUrlInput) => {
16
+ if (!ApiEndpoint.__defined__) {
17
+ if (!baseUrlInput) {
18
+ /**
19
+ * If the baseUrl is not provided, use the default baseUrl from the sdk-api package
20
+ */
21
+ ApiEndpoint.__baseUrl__ = new sdkApiCore.Configuration().basePath;
22
+ }
23
+ else {
24
+ ApiEndpoint.__baseUrl__ = baseUrlInput;
25
+ }
26
+ ApiEndpoint.__defined__ = true;
27
+ }
28
+ else if (!baseUrlInput && ApiEndpoint.__defined__) {
29
+ /**
30
+ * If for some reason (usually in local development), the setBaseUrl is called multiple times with undefined
31
+ * And we already have it defined, let's just assume it's a no-op
32
+ */
33
+ return;
34
+ }
35
+ else if (ApiEndpoint.__baseUrl__ !== baseUrlInput) {
36
+ throw new Error(`ApiEndpoint baseUrl is already set to ${ApiEndpoint.__baseUrl__}, cannot change it to ${baseUrlInput}`);
37
+ }
38
+ Object.freeze(ApiEndpoint);
39
+ };
40
+
41
+ module.exports = ApiEndpoint;
@@ -0,0 +1,7 @@
1
+ declare class ApiEndpoint {
2
+ private static __baseUrl__;
3
+ private static __defined__;
4
+ static getBaseUrl: () => string | undefined;
5
+ static setBaseUrl: (baseUrlInput?: string) => void;
6
+ }
7
+ export default ApiEndpoint;
@@ -0,0 +1,39 @@
1
+ 'use client'
2
+ import { Configuration } from '@dynamic-labs/sdk-api-core';
3
+
4
+ /* eslint-disable no-underscore-dangle */
5
+ class ApiEndpoint {
6
+ }
7
+ ApiEndpoint.getBaseUrl = () => {
8
+ if (!ApiEndpoint.__defined__) {
9
+ throw new Error('ApiEndpoint Base URL has not been initialized');
10
+ }
11
+ return ApiEndpoint.__baseUrl__;
12
+ };
13
+ ApiEndpoint.setBaseUrl = (baseUrlInput) => {
14
+ if (!ApiEndpoint.__defined__) {
15
+ if (!baseUrlInput) {
16
+ /**
17
+ * If the baseUrl is not provided, use the default baseUrl from the sdk-api package
18
+ */
19
+ ApiEndpoint.__baseUrl__ = new Configuration().basePath;
20
+ }
21
+ else {
22
+ ApiEndpoint.__baseUrl__ = baseUrlInput;
23
+ }
24
+ ApiEndpoint.__defined__ = true;
25
+ }
26
+ else if (!baseUrlInput && ApiEndpoint.__defined__) {
27
+ /**
28
+ * If for some reason (usually in local development), the setBaseUrl is called multiple times with undefined
29
+ * And we already have it defined, let's just assume it's a no-op
30
+ */
31
+ return;
32
+ }
33
+ else if (ApiEndpoint.__baseUrl__ !== baseUrlInput) {
34
+ throw new Error(`ApiEndpoint baseUrl is already set to ${ApiEndpoint.__baseUrl__}, cannot change it to ${baseUrlInput}`);
35
+ }
36
+ Object.freeze(ApiEndpoint);
37
+ };
38
+
39
+ export { ApiEndpoint as default };
@@ -0,0 +1,81 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var DynamicEvents = require('../events/DynamicEvents.cjs');
7
+ var helpers = require('./helpers.cjs');
8
+
9
+ const AUTH_TOKEN = 'dynamic_authentication_token';
10
+ class LocalStorage {
11
+ static getDynamicLSKey(key) {
12
+ return `${key}${LocalStorage.getSuffix()}`;
13
+ }
14
+ static validateRequest(key, fromAuxiliaryAuthFunctions) {
15
+ if (key === AUTH_TOKEN && !fromAuxiliaryAuthFunctions) {
16
+ throw new Error('You cannot access AUTH_TOKEN through localStorage. Use getAuthToken/ storeAuthToken helper functions instead');
17
+ }
18
+ }
19
+ static setSuffix(localStorageSuffix) {
20
+ if (!LocalStorage.__suffix__) {
21
+ const suffix = (localStorageSuffix && `_${localStorageSuffix}`) || '';
22
+ LocalStorage.__suffix__ = suffix;
23
+ }
24
+ }
25
+ /**
26
+ *
27
+ * @param key
28
+ * @param getAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
29
+ * @returns
30
+ */
31
+ static getFromLS(key, getAuth = false) {
32
+ if (typeof window === 'undefined') {
33
+ return undefined;
34
+ }
35
+ LocalStorage.validateRequest(key, getAuth);
36
+ const value = window.localStorage.getItem(LocalStorage.getDynamicLSKey(key));
37
+ if (!value) {
38
+ return undefined;
39
+ }
40
+ try {
41
+ return JSON.parse(value);
42
+ }
43
+ catch (error) {
44
+ helpers.logger.debug(`Error while parsing ${key} from local storage`, { value });
45
+ LocalStorage.removeFromLS(key);
46
+ DynamicEvents.dynamicEvents.emit('triggerLogout');
47
+ }
48
+ return undefined;
49
+ }
50
+ static removeFromLS(key) {
51
+ if (typeof window === 'undefined') {
52
+ return undefined;
53
+ }
54
+ return window.localStorage.removeItem(LocalStorage.getDynamicLSKey(key));
55
+ }
56
+ /**
57
+ *
58
+ * @param key
59
+ * @param value
60
+ * @param storeAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
61
+ * @returns
62
+ */
63
+ static setToLS(key, value, storeAuth = false) {
64
+ if (typeof window === 'undefined') {
65
+ return;
66
+ }
67
+ LocalStorage.validateRequest(key, storeAuth);
68
+ window.localStorage.setItem(LocalStorage.getDynamicLSKey(key), JSON.stringify(value));
69
+ }
70
+ static getKeys() {
71
+ if (typeof window === 'undefined') {
72
+ return [];
73
+ }
74
+ return Object.keys(window.localStorage);
75
+ }
76
+ }
77
+ LocalStorage.getSuffix = () => LocalStorage.__suffix__ || '';
78
+
79
+ exports.AUTH_TOKEN = AUTH_TOKEN;
80
+ exports.LocalStorage = LocalStorage;
81
+ exports["default"] = LocalStorage;
@@ -0,0 +1,26 @@
1
+ export declare const AUTH_TOKEN = "dynamic_authentication_token";
2
+ export declare class LocalStorage {
3
+ private static __suffix__;
4
+ static getSuffix: () => string;
5
+ private static getDynamicLSKey;
6
+ private static validateRequest;
7
+ static setSuffix(localStorageSuffix?: string): void;
8
+ /**
9
+ *
10
+ * @param key
11
+ * @param getAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
12
+ * @returns
13
+ */
14
+ static getFromLS<T = any>(key: string, getAuth?: boolean): T | undefined;
15
+ static removeFromLS(key: string): void;
16
+ /**
17
+ *
18
+ * @param key
19
+ * @param value
20
+ * @param storeAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
21
+ * @returns
22
+ */
23
+ static setToLS<T = any>(key: string, value: T, storeAuth?: boolean): void;
24
+ static getKeys(): string[];
25
+ }
26
+ export default LocalStorage;
@@ -0,0 +1,75 @@
1
+ 'use client'
2
+ import { dynamicEvents } from '../events/DynamicEvents.js';
3
+ import { logger } from './helpers.js';
4
+
5
+ const AUTH_TOKEN = 'dynamic_authentication_token';
6
+ class LocalStorage {
7
+ static getDynamicLSKey(key) {
8
+ return `${key}${LocalStorage.getSuffix()}`;
9
+ }
10
+ static validateRequest(key, fromAuxiliaryAuthFunctions) {
11
+ if (key === AUTH_TOKEN && !fromAuxiliaryAuthFunctions) {
12
+ throw new Error('You cannot access AUTH_TOKEN through localStorage. Use getAuthToken/ storeAuthToken helper functions instead');
13
+ }
14
+ }
15
+ static setSuffix(localStorageSuffix) {
16
+ if (!LocalStorage.__suffix__) {
17
+ const suffix = (localStorageSuffix && `_${localStorageSuffix}`) || '';
18
+ LocalStorage.__suffix__ = suffix;
19
+ }
20
+ }
21
+ /**
22
+ *
23
+ * @param key
24
+ * @param getAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
25
+ * @returns
26
+ */
27
+ static getFromLS(key, getAuth = false) {
28
+ if (typeof window === 'undefined') {
29
+ return undefined;
30
+ }
31
+ LocalStorage.validateRequest(key, getAuth);
32
+ const value = window.localStorage.getItem(LocalStorage.getDynamicLSKey(key));
33
+ if (!value) {
34
+ return undefined;
35
+ }
36
+ try {
37
+ return JSON.parse(value);
38
+ }
39
+ catch (error) {
40
+ logger.debug(`Error while parsing ${key} from local storage`, { value });
41
+ LocalStorage.removeFromLS(key);
42
+ dynamicEvents.emit('triggerLogout');
43
+ }
44
+ return undefined;
45
+ }
46
+ static removeFromLS(key) {
47
+ if (typeof window === 'undefined') {
48
+ return undefined;
49
+ }
50
+ return window.localStorage.removeItem(LocalStorage.getDynamicLSKey(key));
51
+ }
52
+ /**
53
+ *
54
+ * @param key
55
+ * @param value
56
+ * @param storeAuth - verifies if the request to get AUTH_TOKEN is comming from getAuthToken and not directly
57
+ * @returns
58
+ */
59
+ static setToLS(key, value, storeAuth = false) {
60
+ if (typeof window === 'undefined') {
61
+ return;
62
+ }
63
+ LocalStorage.validateRequest(key, storeAuth);
64
+ window.localStorage.setItem(LocalStorage.getDynamicLSKey(key), JSON.stringify(value));
65
+ }
66
+ static getKeys() {
67
+ if (typeof window === 'undefined') {
68
+ return [];
69
+ }
70
+ return Object.keys(window.localStorage);
71
+ }
72
+ }
73
+ LocalStorage.getSuffix = () => LocalStorage.__suffix__ || '';
74
+
75
+ export { AUTH_TOKEN, LocalStorage, LocalStorage as default };
@@ -0,0 +1,35 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
7
+ var utils = require('@dynamic-labs/utils');
8
+ var helpers = require('./helpers.cjs');
9
+ var ApiEndpoint = require('./ApiEndpoint.cjs');
10
+ var version = require('./version.cjs');
11
+
12
+ const sdkApi = () => {
13
+ const baseUrl = process.env.API_BASE_URL ||
14
+ process.env.NX_API_BASE_URL ||
15
+ 'https://app.dynamic-preprod.xyz/api/v0';
16
+ ApiEndpoint.setBaseUrl(baseUrl);
17
+ const settings = {
18
+ basePath: ApiEndpoint.getBaseUrl(),
19
+ headers: {
20
+ 'Content-Type': 'application/json',
21
+ },
22
+ };
23
+ const minJwt = helpers.getMinAuthToken();
24
+ if (minJwt) {
25
+ settings.headers.Authorization = `Bearer ${minJwt}`;
26
+ }
27
+ const credentials = helpers.isCookieEnabled()
28
+ ? 'include'
29
+ : undefined;
30
+ settings.headers['x-dyn-version'] = `WalletKit/${version.VERSION}`;
31
+ settings.headers['x-dyn-api-version'] = `API/${version.API_VERSION}`;
32
+ return new sdkApiCore.SDKApi(new sdkApiCore.Configuration(Object.assign(Object.assign({}, settings), { credentials, fetchApi: utils.FetchService.fetch })));
33
+ };
34
+
35
+ exports.sdkApi = sdkApi;
@@ -0,0 +1,2 @@
1
+ import { SDKApi } from '@dynamic-labs/sdk-api-core';
2
+ export declare const sdkApi: () => SDKApi;
@@ -0,0 +1,31 @@
1
+ 'use client'
2
+ import { SDKApi, Configuration } from '@dynamic-labs/sdk-api-core';
3
+ import { FetchService } from '@dynamic-labs/utils';
4
+ import { getMinAuthToken, isCookieEnabled } from './helpers.js';
5
+ import ApiEndpoint from './ApiEndpoint.js';
6
+ import { VERSION, API_VERSION } from './version.js';
7
+
8
+ const sdkApi = () => {
9
+ const baseUrl = process.env.API_BASE_URL ||
10
+ process.env.NX_API_BASE_URL ||
11
+ 'https://app.dynamic-preprod.xyz/api/v0';
12
+ ApiEndpoint.setBaseUrl(baseUrl);
13
+ const settings = {
14
+ basePath: ApiEndpoint.getBaseUrl(),
15
+ headers: {
16
+ 'Content-Type': 'application/json',
17
+ },
18
+ };
19
+ const minJwt = getMinAuthToken();
20
+ if (minJwt) {
21
+ settings.headers.Authorization = `Bearer ${minJwt}`;
22
+ }
23
+ const credentials = isCookieEnabled()
24
+ ? 'include'
25
+ : undefined;
26
+ settings.headers['x-dyn-version'] = `WalletKit/${VERSION}`;
27
+ settings.headers['x-dyn-api-version'] = `API/${API_VERSION}`;
28
+ return new SDKApi(new Configuration(Object.assign(Object.assign({}, settings), { credentials, fetchApi: FetchService.fetch })));
29
+ };
30
+
31
+ export { sdkApi };
@@ -0,0 +1,88 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
7
+ var logger$1 = require('@dynamic-labs/logger');
8
+ var LocalStorage = require('./LocalStorage.cjs');
9
+
10
+ const logger = new logger$1.Logger('DynamicSDK');
11
+ const AUTH_MIN_TOKEN = 'dynamic_min_authentication_token';
12
+ const AUTH_MIN_TOKEN_DEMO = 'dynamic_min_authentication_token_demo';
13
+ const isCookieEnabled = () => {
14
+ var _a, _b, _c, _d;
15
+ let securitySettings = (_a = LocalStorage.LocalStorage.getFromLS('dynamic_store')) !== null && _a !== void 0 ? _a : LocalStorage.LocalStorage.getFromLS('dynamic_store_demo');
16
+ securitySettings = (_b = securitySettings === null || securitySettings === void 0 ? void 0 : securitySettings.settings) === null || _b === void 0 ? void 0 : _b.security;
17
+ if (!securitySettings)
18
+ return false;
19
+ // client uses Dynamic cookies
20
+ const dynamicCookiesEnabled = (((_c = securitySettings.auth) === null || _c === void 0 ? void 0 : _c.storage) || []).includes(sdkApiCore.AuthStorageEnum.Cookie);
21
+ // BYO JWT client puts their non-Dynamic JWT in a cookie
22
+ const byoJwtCookieEnabled = Boolean((_d = securitySettings.externalAuth) === null || _d === void 0 ? void 0 : _d.cookieName);
23
+ // should return true for both of these scenarios
24
+ // because we also need to do `credentials: true` in api.ts when
25
+ // a byo jwt client sets their named cookie for their jwt and
26
+ // needs to send it to our backend
27
+ return dynamicCookiesEnabled || byoJwtCookieEnabled;
28
+ };
29
+ const parseToken = (token) => {
30
+ var _a;
31
+ if (!token)
32
+ return undefined;
33
+ const base64 = (_a = token.split('.')[1]) === null || _a === void 0 ? void 0 : _a.replace(/-/g, '+').replace(/_/g, '/');
34
+ const jsonPayload = base64 &&
35
+ decodeURIComponent(atob(base64)
36
+ .split('')
37
+ .map((c) => `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`)
38
+ .join(''));
39
+ return JSON.parse(jsonPayload);
40
+ };
41
+ const decodeMinJwt = (token) => {
42
+ try {
43
+ const json = parseToken(token);
44
+ if (!json)
45
+ return undefined;
46
+ return sdkApiCore.MinifiedDynamicJwtFromJSON(json);
47
+ }
48
+ catch (e) {
49
+ logger.error(e);
50
+ return undefined;
51
+ }
52
+ };
53
+ const getMinAuthToken = () => {
54
+ var _a;
55
+ if (typeof window === 'undefined')
56
+ return undefined;
57
+ const token = (_a = LocalStorage.LocalStorage.getFromLS(AUTH_MIN_TOKEN, true)) !== null && _a !== void 0 ? _a : LocalStorage.LocalStorage.getFromLS(AUTH_MIN_TOKEN_DEMO, true);
58
+ if (!token || isMinAuthTokenExpired(token))
59
+ return undefined;
60
+ return token;
61
+ };
62
+ const isMinAuthTokenExpired = (token) => {
63
+ const decoded = decodeMinJwt(token);
64
+ return isTokenExpired(decoded);
65
+ };
66
+ const isTokenExpired = (decoded) => {
67
+ if (!decoded) {
68
+ return true;
69
+ }
70
+ if (!decoded.exp) {
71
+ return true;
72
+ }
73
+ const expirationTime = new Date(decoded.exp * 1000).getTime();
74
+ const currentTime = new Date().getTime();
75
+ if (currentTime >= expirationTime) {
76
+ return true;
77
+ }
78
+ return false;
79
+ };
80
+
81
+ exports.AUTH_MIN_TOKEN = AUTH_MIN_TOKEN;
82
+ exports.AUTH_MIN_TOKEN_DEMO = AUTH_MIN_TOKEN_DEMO;
83
+ exports.decodeMinJwt = decodeMinJwt;
84
+ exports.getMinAuthToken = getMinAuthToken;
85
+ exports.isCookieEnabled = isCookieEnabled;
86
+ exports.isMinAuthTokenExpired = isMinAuthTokenExpired;
87
+ exports.logger = logger;
88
+ exports.parseToken = parseToken;
@@ -0,0 +1,12 @@
1
+ import { MinifiedDynamicJwt } from '@dynamic-labs/sdk-api-core';
2
+ import { Logger } from '@dynamic-labs/logger';
3
+ export declare const logger: Logger;
4
+ export declare const AUTH_MIN_TOKEN = "dynamic_min_authentication_token";
5
+ export declare const AUTH_MIN_TOKEN_DEMO = "dynamic_min_authentication_token_demo";
6
+ export declare const DYNAMIC_STORE_DEMO = "dynamic_store_demo";
7
+ export declare const DYNAMIC_STORE = "dynamic_store";
8
+ export declare const isCookieEnabled: () => any;
9
+ export declare const parseToken: (token: string | null | undefined) => any;
10
+ export declare const decodeMinJwt: (token: string | null | undefined) => Omit<MinifiedDynamicJwt, 'jwt'> | undefined;
11
+ export declare const getMinAuthToken: () => any;
12
+ export declare const isMinAuthTokenExpired: (token: string) => boolean;
@@ -0,0 +1,77 @@
1
+ 'use client'
2
+ import { AuthStorageEnum, MinifiedDynamicJwtFromJSON } from '@dynamic-labs/sdk-api-core';
3
+ import { Logger } from '@dynamic-labs/logger';
4
+ import { LocalStorage } from './LocalStorage.js';
5
+
6
+ const logger = new Logger('DynamicSDK');
7
+ const AUTH_MIN_TOKEN = 'dynamic_min_authentication_token';
8
+ const AUTH_MIN_TOKEN_DEMO = 'dynamic_min_authentication_token_demo';
9
+ const isCookieEnabled = () => {
10
+ var _a, _b, _c, _d;
11
+ let securitySettings = (_a = LocalStorage.getFromLS('dynamic_store')) !== null && _a !== void 0 ? _a : LocalStorage.getFromLS('dynamic_store_demo');
12
+ securitySettings = (_b = securitySettings === null || securitySettings === void 0 ? void 0 : securitySettings.settings) === null || _b === void 0 ? void 0 : _b.security;
13
+ if (!securitySettings)
14
+ return false;
15
+ // client uses Dynamic cookies
16
+ const dynamicCookiesEnabled = (((_c = securitySettings.auth) === null || _c === void 0 ? void 0 : _c.storage) || []).includes(AuthStorageEnum.Cookie);
17
+ // BYO JWT client puts their non-Dynamic JWT in a cookie
18
+ const byoJwtCookieEnabled = Boolean((_d = securitySettings.externalAuth) === null || _d === void 0 ? void 0 : _d.cookieName);
19
+ // should return true for both of these scenarios
20
+ // because we also need to do `credentials: true` in api.ts when
21
+ // a byo jwt client sets their named cookie for their jwt and
22
+ // needs to send it to our backend
23
+ return dynamicCookiesEnabled || byoJwtCookieEnabled;
24
+ };
25
+ const parseToken = (token) => {
26
+ var _a;
27
+ if (!token)
28
+ return undefined;
29
+ const base64 = (_a = token.split('.')[1]) === null || _a === void 0 ? void 0 : _a.replace(/-/g, '+').replace(/_/g, '/');
30
+ const jsonPayload = base64 &&
31
+ decodeURIComponent(atob(base64)
32
+ .split('')
33
+ .map((c) => `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`)
34
+ .join(''));
35
+ return JSON.parse(jsonPayload);
36
+ };
37
+ const decodeMinJwt = (token) => {
38
+ try {
39
+ const json = parseToken(token);
40
+ if (!json)
41
+ return undefined;
42
+ return MinifiedDynamicJwtFromJSON(json);
43
+ }
44
+ catch (e) {
45
+ logger.error(e);
46
+ return undefined;
47
+ }
48
+ };
49
+ const getMinAuthToken = () => {
50
+ var _a;
51
+ if (typeof window === 'undefined')
52
+ return undefined;
53
+ const token = (_a = LocalStorage.getFromLS(AUTH_MIN_TOKEN, true)) !== null && _a !== void 0 ? _a : LocalStorage.getFromLS(AUTH_MIN_TOKEN_DEMO, true);
54
+ if (!token || isMinAuthTokenExpired(token))
55
+ return undefined;
56
+ return token;
57
+ };
58
+ const isMinAuthTokenExpired = (token) => {
59
+ const decoded = decodeMinJwt(token);
60
+ return isTokenExpired(decoded);
61
+ };
62
+ const isTokenExpired = (decoded) => {
63
+ if (!decoded) {
64
+ return true;
65
+ }
66
+ if (!decoded.exp) {
67
+ return true;
68
+ }
69
+ const expirationTime = new Date(decoded.exp * 1000).getTime();
70
+ const currentTime = new Date().getTime();
71
+ if (currentTime >= expirationTime) {
72
+ return true;
73
+ }
74
+ return false;
75
+ };
76
+
77
+ export { AUTH_MIN_TOKEN, AUTH_MIN_TOKEN_DEMO, decodeMinJwt, getMinAuthToken, isCookieEnabled, isMinAuthTokenExpired, logger, parseToken };
@@ -0,0 +1,12 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _package = require('../../../../../package.cjs');
7
+
8
+ const VERSION = _package.version;
9
+ const API_VERSION = _package.dependencies['@dynamic-labs/sdk-api-core'];
10
+
11
+ exports.API_VERSION = API_VERSION;
12
+ exports.VERSION = VERSION;
@@ -0,0 +1,2 @@
1
+ export declare const VERSION: string;
2
+ export declare const API_VERSION: string;
@@ -0,0 +1,7 @@
1
+ 'use client'
2
+ import { version, dependencies } from '../../../../../package.js';
3
+
4
+ const VERSION = version;
5
+ const API_VERSION = dependencies['@dynamic-labs/sdk-api-core'];
6
+
7
+ export { API_VERSION, VERSION };