@dynamic-labs/utils 4.0.0-alpha.9 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +483 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +5 -5
- package/src/bufferToBase64/index.d.ts +1 -0
- package/src/eip6963/eip6963Provider.cjs +15 -4
- package/src/eip6963/eip6963Provider.d.ts +8 -3
- package/src/eip6963/eip6963Provider.js +14 -5
- package/src/encryption/convertPublicKeyCryptoKeyToHex/convertPublicKeyCryptoKeyToHex.cjs +31 -0
- package/src/encryption/convertPublicKeyCryptoKeyToHex/convertPublicKeyCryptoKeyToHex.d.ts +11 -0
- package/src/encryption/convertPublicKeyCryptoKeyToHex/convertPublicKeyCryptoKeyToHex.js +27 -0
- package/src/encryption/convertPublicKeyCryptoKeyToHex/index.d.ts +1 -0
- package/src/encryption/convertPublicKeyHexToCryptoKey/convertPublicKeyHexToCryptoKey.cjs +35 -0
- package/src/encryption/convertPublicKeyHexToCryptoKey/convertPublicKeyHexToCryptoKey.d.ts +8 -0
- package/src/encryption/convertPublicKeyHexToCryptoKey/convertPublicKeyHexToCryptoKey.js +31 -0
- package/src/encryption/convertPublicKeyHexToCryptoKey/index.d.ts +1 -0
- package/src/encryption/createKeyPair/createKeyPair.cjs +27 -0
- package/src/encryption/createKeyPair/createKeyPair.d.ts +9 -0
- package/src/encryption/createKeyPair/createKeyPair.js +23 -0
- package/src/encryption/createKeyPair/index.d.ts +1 -0
- package/src/encryption/decryptMessage/decryptMessage.cjs +48 -0
- package/src/encryption/decryptMessage/decryptMessage.d.ts +9 -0
- package/src/encryption/decryptMessage/decryptMessage.js +44 -0
- package/src/encryption/decryptMessage/index.d.ts +1 -0
- package/src/encryption/deriveSharedSecret/deriveSharedSecret.cjs +28 -0
- package/src/encryption/deriveSharedSecret/deriveSharedSecret.d.ts +10 -0
- package/src/encryption/deriveSharedSecret/deriveSharedSecret.js +24 -0
- package/src/encryption/deriveSharedSecret/index.d.ts +1 -0
- package/src/encryption/encryptMessage/encryptMessage.cjs +42 -0
- package/src/encryption/encryptMessage/encryptMessage.d.ts +13 -0
- package/src/encryption/encryptMessage/encryptMessage.js +38 -0
- package/src/encryption/encryptMessage/index.d.ts +1 -0
- package/src/encryption/index.d.ts +7 -0
- package/src/encryption/isEncryptedMessage/index.d.ts +1 -0
- package/src/encryption/isEncryptedMessage/isEncryptedMessage.cjs +28 -0
- package/src/encryption/isEncryptedMessage/isEncryptedMessage.d.ts +7 -0
- package/src/encryption/isEncryptedMessage/isEncryptedMessage.js +24 -0
- package/src/eventTimeline/eventTimeline.cjs +41 -0
- package/src/eventTimeline/eventTimeline.d.ts +18 -0
- package/src/eventTimeline/eventTimeline.js +37 -0
- package/src/eventTimeline/index.d.ts +1 -0
- package/src/getProvidersFromWindow/index.d.ts +1 -0
- package/src/handleMobileWalletRedirect/handleMobileWalletRedirect.cjs +1 -1
- package/src/handleMobileWalletRedirect/handleMobileWalletRedirect.js +1 -1
- package/src/index.cjs +85 -49
- package/src/index.d.ts +33 -24
- package/src/index.js +41 -25
- package/src/isInIframe/index.d.ts +1 -0
- package/src/isInIframe/isInIframe.cjs +8 -0
- package/src/isInIframe/isInIframe.d.ts +1 -0
- package/src/isInIframe/isInIframe.js +4 -0
- package/src/isLedgerAddressViaVerifiedCredentials/index.d.ts +1 -0
- package/src/isMobile/index.d.ts +1 -0
- package/src/isString/index.d.ts +1 -0
- package/src/isString/isString.cjs +8 -0
- package/src/isString/isString.d.ts +1 -0
- package/src/isString/isString.js +4 -0
- package/src/last/index.d.ts +1 -0
- package/src/localStorageAsync/index.d.ts +1 -0
- package/src/{localStorageAsync.cjs → localStorageAsync/localStorageAsync.cjs} +1 -1
- package/src/{localStorageAsync.js → localStorageAsync/localStorageAsync.js} +1 -1
- package/src/parseChainId/index.d.ts +1 -0
- package/src/parseIntSafe/index.d.ts +1 -0
- package/src/parseIntSafe/parseIntSafe.cjs +23 -0
- package/src/parseIntSafe/parseIntSafe.d.ts +1 -0
- package/src/parseIntSafe/parseIntSafe.js +19 -0
- package/src/parseNetworks/index.d.ts +1 -0
- package/src/{parseEvmNetworks.cjs → parseNetworks/parseNetworks.cjs} +3 -1
- package/src/parseNetworks/parseNetworks.d.ts +3 -0
- package/src/{parseEvmNetworks.js → parseNetworks/parseNetworks.js} +3 -2
- package/src/retryableFn/index.d.ts +1 -0
- package/src/{retryableFn.cjs → retryableFn/retryableFn.cjs} +3 -18
- package/src/{retryableFn.d.ts → retryableFn/retryableFn.d.ts} +0 -3
- package/src/{retryableFn.js → retryableFn/retryableFn.js} +3 -18
- package/src/sanitizeName/index.d.ts +1 -0
- package/src/sanitizeName/sanitizeName.cjs +8 -0
- package/src/sanitizeName/sanitizeName.d.ts +1 -0
- package/src/sanitizeName/sanitizeName.js +4 -0
- package/src/services/Oauth2Service/Oauth2Service.d.ts +0 -1
- package/src/services/Oauth2Service/createWindowOauth2Service/createWindowOauth2Service.cjs +9 -1
- package/src/services/Oauth2Service/createWindowOauth2Service/createWindowOauth2Service.js +9 -1
- package/src/services/StorageService/StorageService.d.ts +1 -1
- package/src/services/StorageService/applyPostfixToStorageService/applyPostfixToStorageService.cjs +11 -0
- package/src/services/StorageService/applyPostfixToStorageService/applyPostfixToStorageService.d.ts +7 -0
- package/src/services/StorageService/applyPostfixToStorageService/applyPostfixToStorageService.js +7 -0
- package/src/services/StorageService/applyPostfixToStorageService/index.d.ts +1 -0
- package/src/services/StorageService/createStorageService/createStorageService.cjs +4 -5
- package/src/services/StorageService/createStorageService/createStorageService.d.ts +1 -2
- package/src/services/StorageService/createStorageService/createStorageService.js +4 -5
- package/src/services/StorageService/index.d.ts +1 -0
- package/src/services/StorageService/types.d.ts +1 -1
- package/src/solToLamports/index.d.ts +1 -0
- package/src/solToLamports/solToLamports.cjs +11 -0
- package/src/solToLamports/solToLamports.d.ts +1 -0
- package/src/solToLamports/solToLamports.js +7 -0
- package/src/uint8ArrayToBase64/index.d.ts +1 -0
- package/src/uint8ArrayToBase64/uint8ArrayToBase64.cjs +32 -0
- package/src/uint8ArrayToBase64/uint8ArrayToBase64.d.ts +24 -0
- package/src/uint8ArrayToBase64/uint8ArrayToBase64.js +27 -0
- package/src/parseEvmNetworks.d.ts +0 -2
- /package/src/{bufferPolyfill.cjs → bufferToBase64/bufferPolyfill.cjs} +0 -0
- /package/src/{bufferPolyfill.d.ts → bufferToBase64/bufferPolyfill.d.ts} +0 -0
- /package/src/{bufferPolyfill.js → bufferToBase64/bufferPolyfill.js} +0 -0
- /package/src/{bufferToBase64.cjs → bufferToBase64/bufferToBase64.cjs} +0 -0
- /package/src/{bufferToBase64.d.ts → bufferToBase64/bufferToBase64.d.ts} +0 -0
- /package/src/{bufferToBase64.js → bufferToBase64/bufferToBase64.js} +0 -0
- /package/src/{getProvidersFromWindow.cjs → getProvidersFromWindow/getProvidersFromWindow.cjs} +0 -0
- /package/src/{getProvidersFromWindow.d.ts → getProvidersFromWindow/getProvidersFromWindow.d.ts} +0 -0
- /package/src/{getProvidersFromWindow.js → getProvidersFromWindow/getProvidersFromWindow.js} +0 -0
- /package/src/{isLedgerAddressViaVerifiedCredentials.cjs → isLedgerAddressViaVerifiedCredentials/isLedgerAddressViaVerifiedCredentials.cjs} +0 -0
- /package/src/{isLedgerAddressViaVerifiedCredentials.d.ts → isLedgerAddressViaVerifiedCredentials/isLedgerAddressViaVerifiedCredentials.d.ts} +0 -0
- /package/src/{isLedgerAddressViaVerifiedCredentials.js → isLedgerAddressViaVerifiedCredentials/isLedgerAddressViaVerifiedCredentials.js} +0 -0
- /package/src/{isMobile.cjs → isMobile/isMobile.cjs} +0 -0
- /package/src/{isMobile.d.ts → isMobile/isMobile.d.ts} +0 -0
- /package/src/{isMobile.js → isMobile/isMobile.js} +0 -0
- /package/src/{last.cjs → last/last.cjs} +0 -0
- /package/src/{last.d.ts → last/last.d.ts} +0 -0
- /package/src/{last.js → last/last.js} +0 -0
- /package/src/{localStorageAsync.d.ts → localStorageAsync/localStorageAsync.d.ts} +0 -0
- /package/src/{parseChainId.cjs → parseChainId/parseChainId.cjs} +0 -0
- /package/src/{parseChainId.d.ts → parseChainId/parseChainId.d.ts} +0 -0
- /package/src/{parseChainId.js → parseChainId/parseChainId.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { parseChainId } from '
|
|
2
|
+
import { parseChainId } from '../parseChainId/parseChainId.js';
|
|
3
3
|
|
|
4
4
|
const parseEvmNetworks = (networks) => {
|
|
5
5
|
const clone = networks.slice();
|
|
@@ -9,5 +9,6 @@ const parseEvmNetworks = (networks) => {
|
|
|
9
9
|
return network;
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
+
const parseCosmosNetworks = (networks) => parseEvmNetworks(networks);
|
|
12
13
|
|
|
13
|
-
export { parseEvmNetworks };
|
|
14
|
+
export { parseCosmosNetworks, parseEvmNetworks };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './retryableFn';
|
|
@@ -3,19 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var _tslib = require('
|
|
7
|
-
var sleep = require('
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
var sleep = require('../sleep/sleep.cjs');
|
|
8
8
|
|
|
9
9
|
const FALLBACK_UNDEFINED = 'FALLBACK_UNDEFINED';
|
|
10
10
|
const retryableFn = (fn_1, ...args_1) => _tslib.__awaiter(void 0, [fn_1, ...args_1], void 0, function* (fn, options = {}) {
|
|
11
|
-
const { maxRetries = 3, currentRetry = 0, timeoutMs = 100, fallbackValue = new Error('Max retries reached'), retryStrategy = 'timeout-only', retryIntervalMs = 0,
|
|
12
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('Configured retryableFn with options: ', {
|
|
13
|
-
currentRetry,
|
|
14
|
-
fallbackValue,
|
|
15
|
-
maxRetries,
|
|
16
|
-
retryStrategy,
|
|
17
|
-
timeoutMs,
|
|
18
|
-
});
|
|
11
|
+
const { maxRetries = 3, currentRetry = 0, timeoutMs = 100, fallbackValue = new Error('Max retries reached'), retryStrategy = 'timeout-only', retryIntervalMs = 0, } = options;
|
|
19
12
|
const timeoutPromise = new Promise((_, reject) => {
|
|
20
13
|
setTimeout(() => {
|
|
21
14
|
reject(new Error('Timeout'));
|
|
@@ -26,9 +19,7 @@ const retryableFn = (fn_1, ...args_1) => _tslib.__awaiter(void 0, [fn_1, ...args
|
|
|
26
19
|
return result;
|
|
27
20
|
}
|
|
28
21
|
catch (err) {
|
|
29
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn caught error: ', err);
|
|
30
22
|
if (currentRetry >= maxRetries) {
|
|
31
|
-
logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning/throwing fallback value', err, fallbackValue);
|
|
32
23
|
if (fallbackValue instanceof Error) {
|
|
33
24
|
throw fallbackValue;
|
|
34
25
|
}
|
|
@@ -41,18 +32,13 @@ const retryableFn = (fn_1, ...args_1) => _tslib.__awaiter(void 0, [fn_1, ...args
|
|
|
41
32
|
const shouldRetry = retryStrategy === 'timeout-and-rejection' ||
|
|
42
33
|
(retryStrategy === 'timeout-only' && isTimeout) ||
|
|
43
34
|
(retryStrategy === 'rejection-only' && !isTimeout);
|
|
44
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn shouldRetry: ', shouldRetry);
|
|
45
35
|
if (!shouldRetry) {
|
|
46
36
|
if (fallbackValue instanceof Error) {
|
|
47
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn throwing fallbackValue error: ', fallbackValue);
|
|
48
37
|
throw err;
|
|
49
38
|
}
|
|
50
39
|
else if (fallbackValue === FALLBACK_UNDEFINED) {
|
|
51
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning undefined');
|
|
52
40
|
return undefined;
|
|
53
41
|
}
|
|
54
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning fallbackValue: ', fallbackValue);
|
|
55
|
-
logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning fallback value', err);
|
|
56
42
|
return fallbackValue;
|
|
57
43
|
}
|
|
58
44
|
if (retryIntervalMs)
|
|
@@ -60,7 +46,6 @@ const retryableFn = (fn_1, ...args_1) => _tslib.__awaiter(void 0, [fn_1, ...args
|
|
|
60
46
|
return retryableFn(fn, {
|
|
61
47
|
currentRetry: currentRetry + 1,
|
|
62
48
|
fallbackValue,
|
|
63
|
-
logger,
|
|
64
49
|
maxRetries,
|
|
65
50
|
retryIntervalMs,
|
|
66
51
|
retryStrategy,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Logger } from '@dynamic-labs/logger';
|
|
2
1
|
export declare const FALLBACK_UNDEFINED = "FALLBACK_UNDEFINED";
|
|
3
2
|
export type RetryableFnOptions<T> = {
|
|
4
3
|
/** Maximum number of retry attempts before returning fallbackValue */
|
|
@@ -11,8 +10,6 @@ export type RetryableFnOptions<T> = {
|
|
|
11
10
|
fallbackValue?: T | Error | typeof FALLBACK_UNDEFINED;
|
|
12
11
|
/** Configure whether the fn should be retried only on timeout, only on rejection, or both */
|
|
13
12
|
retryStrategy?: 'timeout-only' | 'rejection-only' | 'timeout-and-rejection';
|
|
14
|
-
/** Set the logger to be used */
|
|
15
|
-
logger?: Logger | typeof console;
|
|
16
13
|
/** Ms to wait before a retry */
|
|
17
14
|
retryIntervalMs?: number;
|
|
18
15
|
};
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { __awaiter } from '
|
|
3
|
-
import { sleep } from '
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
import { sleep } from '../sleep/sleep.js';
|
|
4
4
|
|
|
5
5
|
const FALLBACK_UNDEFINED = 'FALLBACK_UNDEFINED';
|
|
6
6
|
const retryableFn = (fn_1, ...args_1) => __awaiter(void 0, [fn_1, ...args_1], void 0, function* (fn, options = {}) {
|
|
7
|
-
const { maxRetries = 3, currentRetry = 0, timeoutMs = 100, fallbackValue = new Error('Max retries reached'), retryStrategy = 'timeout-only', retryIntervalMs = 0,
|
|
8
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('Configured retryableFn with options: ', {
|
|
9
|
-
currentRetry,
|
|
10
|
-
fallbackValue,
|
|
11
|
-
maxRetries,
|
|
12
|
-
retryStrategy,
|
|
13
|
-
timeoutMs,
|
|
14
|
-
});
|
|
7
|
+
const { maxRetries = 3, currentRetry = 0, timeoutMs = 100, fallbackValue = new Error('Max retries reached'), retryStrategy = 'timeout-only', retryIntervalMs = 0, } = options;
|
|
15
8
|
const timeoutPromise = new Promise((_, reject) => {
|
|
16
9
|
setTimeout(() => {
|
|
17
10
|
reject(new Error('Timeout'));
|
|
@@ -22,9 +15,7 @@ const retryableFn = (fn_1, ...args_1) => __awaiter(void 0, [fn_1, ...args_1], vo
|
|
|
22
15
|
return result;
|
|
23
16
|
}
|
|
24
17
|
catch (err) {
|
|
25
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn caught error: ', err);
|
|
26
18
|
if (currentRetry >= maxRetries) {
|
|
27
|
-
logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning/throwing fallback value', err, fallbackValue);
|
|
28
19
|
if (fallbackValue instanceof Error) {
|
|
29
20
|
throw fallbackValue;
|
|
30
21
|
}
|
|
@@ -37,18 +28,13 @@ const retryableFn = (fn_1, ...args_1) => __awaiter(void 0, [fn_1, ...args_1], vo
|
|
|
37
28
|
const shouldRetry = retryStrategy === 'timeout-and-rejection' ||
|
|
38
29
|
(retryStrategy === 'timeout-only' && isTimeout) ||
|
|
39
30
|
(retryStrategy === 'rejection-only' && !isTimeout);
|
|
40
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn shouldRetry: ', shouldRetry);
|
|
41
31
|
if (!shouldRetry) {
|
|
42
32
|
if (fallbackValue instanceof Error) {
|
|
43
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn throwing fallbackValue error: ', fallbackValue);
|
|
44
33
|
throw err;
|
|
45
34
|
}
|
|
46
35
|
else if (fallbackValue === FALLBACK_UNDEFINED) {
|
|
47
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning undefined');
|
|
48
36
|
return undefined;
|
|
49
37
|
}
|
|
50
|
-
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning fallbackValue: ', fallbackValue);
|
|
51
|
-
logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning fallback value', err);
|
|
52
38
|
return fallbackValue;
|
|
53
39
|
}
|
|
54
40
|
if (retryIntervalMs)
|
|
@@ -56,7 +42,6 @@ const retryableFn = (fn_1, ...args_1) => __awaiter(void 0, [fn_1, ...args_1], vo
|
|
|
56
42
|
return retryableFn(fn, {
|
|
57
43
|
currentRetry: currentRetry + 1,
|
|
58
44
|
fallbackValue,
|
|
59
|
-
logger,
|
|
60
45
|
maxRetries,
|
|
61
46
|
retryIntervalMs,
|
|
62
47
|
retryStrategy,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { sanitizeName } from './sanitizeName';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sanitizeName: (name: string) => string;
|
|
@@ -7,7 +7,7 @@ var _tslib = require('../../../../_virtual/_tslib.cjs');
|
|
|
7
7
|
var types = require('@dynamic-labs/types');
|
|
8
8
|
var logger = require('../../../logger/logger.cjs');
|
|
9
9
|
var connectWithAppleId = require('../utils/connectWithAppleId/connectWithAppleId.cjs');
|
|
10
|
-
var isMobile = require('../../../isMobile.cjs');
|
|
10
|
+
var isMobile = require('../../../isMobile/isMobile.cjs');
|
|
11
11
|
|
|
12
12
|
let authWindowInterval;
|
|
13
13
|
const createWindowOauth2Service = () => ({
|
|
@@ -46,6 +46,14 @@ const createWindowOauth2Service = () => ({
|
|
|
46
46
|
clearInterval(authWindowInterval);
|
|
47
47
|
const providersWaitingOauthMessage = {};
|
|
48
48
|
const authWindow = window.open('', '_blank', 'width=500,height=600');
|
|
49
|
+
if (authWindow === null || typeof authWindow === 'undefined') {
|
|
50
|
+
// Pop-ups are blocked
|
|
51
|
+
typedReject({
|
|
52
|
+
code: types.SocialOAuthErrorCode.OAUTH_WINDOW_BLOCKED,
|
|
53
|
+
message: 'Please allow popups and try again.',
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
49
57
|
const clearListeners = () => {
|
|
50
58
|
window.removeEventListener('message', handleWindowMessage);
|
|
51
59
|
providersWaitingOauthMessage[provider] = false;
|
|
@@ -3,7 +3,7 @@ import { __awaiter } from '../../../../_virtual/_tslib.js';
|
|
|
3
3
|
import { ProviderEnum, SocialOAuthErrorCode } from '@dynamic-labs/types';
|
|
4
4
|
import { logger } from '../../../logger/logger.js';
|
|
5
5
|
import { connectWithAppleId } from '../utils/connectWithAppleId/connectWithAppleId.js';
|
|
6
|
-
import { isSafariBrowser, isIOS } from '../../../isMobile.js';
|
|
6
|
+
import { isSafariBrowser, isIOS } from '../../../isMobile/isMobile.js';
|
|
7
7
|
|
|
8
8
|
let authWindowInterval;
|
|
9
9
|
const createWindowOauth2Service = () => ({
|
|
@@ -42,6 +42,14 @@ const createWindowOauth2Service = () => ({
|
|
|
42
42
|
clearInterval(authWindowInterval);
|
|
43
43
|
const providersWaitingOauthMessage = {};
|
|
44
44
|
const authWindow = window.open('', '_blank', 'width=500,height=600');
|
|
45
|
+
if (authWindow === null || typeof authWindow === 'undefined') {
|
|
46
|
+
// Pop-ups are blocked
|
|
47
|
+
typedReject({
|
|
48
|
+
code: SocialOAuthErrorCode.OAUTH_WINDOW_BLOCKED,
|
|
49
|
+
message: 'Please allow popups and try again.',
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
45
53
|
const clearListeners = () => {
|
|
46
54
|
window.removeEventListener('message', handleWindowMessage);
|
|
47
55
|
providersWaitingOauthMessage[provider] = false;
|
|
@@ -20,7 +20,7 @@ export declare class StorageService {
|
|
|
20
20
|
static registerSourceStorage(source: StorageSource, implementation: IStorageService): void;
|
|
21
21
|
static getSourceStorage(source: StorageSource): IStorageService | undefined;
|
|
22
22
|
static resolveStorage(options?: StorageOptions): IStorageService;
|
|
23
|
-
static getItem<T = string>(key: string, options?: StorageOptions): T |
|
|
23
|
+
static getItem<T = string>(key: string, options?: StorageOptions): T | null;
|
|
24
24
|
static setItem<T>(key: string, value: T, options?: StorageOptions): void;
|
|
25
25
|
static removeItem(key: string, options?: StorageOptions): void;
|
|
26
26
|
static getKeys(options?: StorageOptions): string[];
|
package/src/services/StorageService/applyPostfixToStorageService/applyPostfixToStorageService.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const applyPostfixToStorageService = ({ storage, postfix, }) => {
|
|
7
|
+
const getKeyWithPostfix = (key) => postfix ? `${key}_${postfix}` : key;
|
|
8
|
+
return Object.assign(Object.assign({}, storage), { getItem: (key) => storage.getItem(getKeyWithPostfix(key)), removeItem: (key) => storage.removeItem(getKeyWithPostfix(key)), setItem: (key, data) => storage.setItem(getKeyWithPostfix(key), data) });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
exports.applyPostfixToStorageService = applyPostfixToStorageService;
|
package/src/services/StorageService/applyPostfixToStorageService/applyPostfixToStorageService.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IStorageService } from '../types';
|
|
2
|
+
type ApplyPostfixToStorageServiceProps<T extends IStorageService> = {
|
|
3
|
+
storage: T;
|
|
4
|
+
postfix: string | undefined;
|
|
5
|
+
};
|
|
6
|
+
export declare const applyPostfixToStorageService: <T extends IStorageService>({ storage, postfix, }: ApplyPostfixToStorageServiceProps<T>) => T;
|
|
7
|
+
export {};
|
package/src/services/StorageService/applyPostfixToStorageService/applyPostfixToStorageService.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const applyPostfixToStorageService = ({ storage, postfix, }) => {
|
|
3
|
+
const getKeyWithPostfix = (key) => postfix ? `${key}_${postfix}` : key;
|
|
4
|
+
return Object.assign(Object.assign({}, storage), { getItem: (key) => storage.getItem(getKeyWithPostfix(key)), removeItem: (key) => storage.removeItem(getKeyWithPostfix(key)), setItem: (key, data) => storage.setItem(getKeyWithPostfix(key), data) });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export { applyPostfixToStorageService };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { applyPostfixToStorageService } from './applyPostfixToStorageService';
|
|
@@ -6,13 +6,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var logger = require('../../../logger/logger.cjs');
|
|
7
7
|
var StorageService = require('../StorageService.cjs');
|
|
8
8
|
|
|
9
|
-
const createStorageService = ({
|
|
10
|
-
const getKey = (key) => (postfix ? `${key}_${postfix}` : key);
|
|
9
|
+
const createStorageService = ({ storage, }) => {
|
|
11
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
11
|
const packValue = (value) => JSON.stringify(value);
|
|
13
12
|
const unpackValue = (value) => JSON.parse(value);
|
|
14
13
|
const getItem = (key) => {
|
|
15
|
-
const value = storage.getItem(
|
|
14
|
+
const value = storage.getItem(key);
|
|
16
15
|
if (!value) {
|
|
17
16
|
return undefined;
|
|
18
17
|
}
|
|
@@ -29,10 +28,10 @@ const createStorageService = ({ postfix, storage, }) => {
|
|
|
29
28
|
return undefined;
|
|
30
29
|
};
|
|
31
30
|
const setItem = (key, value) => {
|
|
32
|
-
storage.setItem(
|
|
31
|
+
storage.setItem(key, packValue(value));
|
|
33
32
|
};
|
|
34
33
|
const removeItem = (key) => {
|
|
35
|
-
storage.removeItem(
|
|
34
|
+
storage.removeItem(key);
|
|
36
35
|
};
|
|
37
36
|
const getKeys = () => Object.keys(storage);
|
|
38
37
|
return {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { IStorageService } from '../types';
|
|
2
2
|
type CreateStorageServiceProps = {
|
|
3
|
-
postfix?: string;
|
|
4
3
|
storage: Storage;
|
|
5
4
|
};
|
|
6
|
-
export declare const createStorageService: ({
|
|
5
|
+
export declare const createStorageService: ({ storage, }: CreateStorageServiceProps) => IStorageService;
|
|
7
6
|
export {};
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
import { logger } from '../../../logger/logger.js';
|
|
3
3
|
import { StorageService } from '../StorageService.js';
|
|
4
4
|
|
|
5
|
-
const createStorageService = ({
|
|
6
|
-
const getKey = (key) => (postfix ? `${key}_${postfix}` : key);
|
|
5
|
+
const createStorageService = ({ storage, }) => {
|
|
7
6
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
7
|
const packValue = (value) => JSON.stringify(value);
|
|
9
8
|
const unpackValue = (value) => JSON.parse(value);
|
|
10
9
|
const getItem = (key) => {
|
|
11
|
-
const value = storage.getItem(
|
|
10
|
+
const value = storage.getItem(key);
|
|
12
11
|
if (!value) {
|
|
13
12
|
return undefined;
|
|
14
13
|
}
|
|
@@ -25,10 +24,10 @@ const createStorageService = ({ postfix, storage, }) => {
|
|
|
25
24
|
return undefined;
|
|
26
25
|
};
|
|
27
26
|
const setItem = (key, value) => {
|
|
28
|
-
storage.setItem(
|
|
27
|
+
storage.setItem(key, packValue(value));
|
|
29
28
|
};
|
|
30
29
|
const removeItem = (key) => {
|
|
31
|
-
storage.removeItem(
|
|
30
|
+
storage.removeItem(key);
|
|
32
31
|
};
|
|
33
32
|
const getKeys = () => Object.keys(storage);
|
|
34
33
|
return {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { solToLamports } from './solToLamports';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const solToLamports = (solAmount) => {
|
|
7
|
+
const lamportsPerSol = 1000000000; // 1 SOL = 1,000,000,000 Lamports
|
|
8
|
+
return solAmount * lamportsPerSol;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
exports.solToLamports = solToLamports;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const solToLamports: (solAmount: number) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { uint8ArrayToBase64, uint8ArrayFromBase64 } from './uint8ArrayToBase64';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Converts a Uint8Array to a base64 encoded string
|
|
8
|
+
* @param buf - The Uint8Array to convert
|
|
9
|
+
* @returns The base64 encoded string representation of the input buffer
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const originalData = new Uint8Array([72, 101, 108, 108, 111]); // "Hello"
|
|
13
|
+
* const base64 = uint8ArrayToBase64(originalData); // "SGVsbG8="
|
|
14
|
+
* const restored = uint8ArrayFromBase64(base64); // Uint8Array [72, 101, 108, 108, 111]
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
const uint8ArrayToBase64 = (buf) => Buffer.from(buf).toString('base64');
|
|
18
|
+
/**
|
|
19
|
+
* Converts a base64 encoded string back to a Uint8Array
|
|
20
|
+
* @param base64 - The base64 encoded string to convert
|
|
21
|
+
* @returns The Uint8Array representation of the input base64 string
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const base64String = "SGVsbG8="; // "Hello" encoded in base64
|
|
25
|
+
* const uint8Array = uint8ArrayFromBase64(base64String); // Uint8Array [72, 101, 108, 108, 111]
|
|
26
|
+
* const backToBase64 = uint8ArrayToBase64(uint8Array); // "SGVsbG8="
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const uint8ArrayFromBase64 = (base64) => Uint8Array.from(Buffer.from(base64, 'base64'));
|
|
30
|
+
|
|
31
|
+
exports.uint8ArrayFromBase64 = uint8ArrayFromBase64;
|
|
32
|
+
exports.uint8ArrayToBase64 = uint8ArrayToBase64;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a Uint8Array to a base64 encoded string
|
|
3
|
+
* @param buf - The Uint8Array to convert
|
|
4
|
+
* @returns The base64 encoded string representation of the input buffer
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const originalData = new Uint8Array([72, 101, 108, 108, 111]); // "Hello"
|
|
8
|
+
* const base64 = uint8ArrayToBase64(originalData); // "SGVsbG8="
|
|
9
|
+
* const restored = uint8ArrayFromBase64(base64); // Uint8Array [72, 101, 108, 108, 111]
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const uint8ArrayToBase64: (buf: Uint8Array) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a base64 encoded string back to a Uint8Array
|
|
15
|
+
* @param base64 - The base64 encoded string to convert
|
|
16
|
+
* @returns The Uint8Array representation of the input base64 string
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const base64String = "SGVsbG8="; // "Hello" encoded in base64
|
|
20
|
+
* const uint8Array = uint8ArrayFromBase64(base64String); // Uint8Array [72, 101, 108, 108, 111]
|
|
21
|
+
* const backToBase64 = uint8ArrayToBase64(uint8Array); // "SGVsbG8="
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const uint8ArrayFromBase64: (base64: string) => Uint8Array;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/**
|
|
3
|
+
* Converts a Uint8Array to a base64 encoded string
|
|
4
|
+
* @param buf - The Uint8Array to convert
|
|
5
|
+
* @returns The base64 encoded string representation of the input buffer
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const originalData = new Uint8Array([72, 101, 108, 108, 111]); // "Hello"
|
|
9
|
+
* const base64 = uint8ArrayToBase64(originalData); // "SGVsbG8="
|
|
10
|
+
* const restored = uint8ArrayFromBase64(base64); // Uint8Array [72, 101, 108, 108, 111]
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
const uint8ArrayToBase64 = (buf) => Buffer.from(buf).toString('base64');
|
|
14
|
+
/**
|
|
15
|
+
* Converts a base64 encoded string back to a Uint8Array
|
|
16
|
+
* @param base64 - The base64 encoded string to convert
|
|
17
|
+
* @returns The Uint8Array representation of the input base64 string
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const base64String = "SGVsbG8="; // "Hello" encoded in base64
|
|
21
|
+
* const uint8Array = uint8ArrayFromBase64(base64String); // Uint8Array [72, 101, 108, 108, 111]
|
|
22
|
+
* const backToBase64 = uint8ArrayToBase64(uint8Array); // "SGVsbG8="
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const uint8ArrayFromBase64 = (base64) => Uint8Array.from(Buffer.from(base64, 'base64'));
|
|
26
|
+
|
|
27
|
+
export { uint8ArrayFromBase64, uint8ArrayToBase64 };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/{getProvidersFromWindow.cjs → getProvidersFromWindow/getProvidersFromWindow.cjs}
RENAMED
|
File without changes
|
/package/src/{getProvidersFromWindow.d.ts → getProvidersFromWindow/getProvidersFromWindow.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|