@metamask-previews/authenticated-user-storage 0.0.0-preview-8e9c439
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 +15 -0
- package/LICENSE +20 -0
- package/README.md +135 -0
- package/dist/authenticated-user-storage-method-action-types.cjs +7 -0
- package/dist/authenticated-user-storage-method-action-types.cjs.map +1 -0
- package/dist/authenticated-user-storage-method-action-types.d.cts +58 -0
- package/dist/authenticated-user-storage-method-action-types.d.cts.map +1 -0
- package/dist/authenticated-user-storage-method-action-types.d.mts +58 -0
- package/dist/authenticated-user-storage-method-action-types.d.mts.map +1 -0
- package/dist/authenticated-user-storage-method-action-types.mjs +6 -0
- package/dist/authenticated-user-storage-method-action-types.mjs.map +1 -0
- package/dist/authenticated-user-storage.cjs +218 -0
- package/dist/authenticated-user-storage.cjs.map +1 -0
- package/dist/authenticated-user-storage.d.cts +123 -0
- package/dist/authenticated-user-storage.d.cts.map +1 -0
- package/dist/authenticated-user-storage.d.mts +123 -0
- package/dist/authenticated-user-storage.d.mts.map +1 -0
- package/dist/authenticated-user-storage.mjs +213 -0
- package/dist/authenticated-user-storage.mjs.map +1 -0
- package/dist/env.cjs +24 -0
- package/dist/env.cjs.map +1 -0
- package/dist/env.d.cts +10 -0
- package/dist/env.d.cts.map +1 -0
- package/dist/env.d.mts +10 -0
- package/dist/env.d.mts.map +1 -0
- package/dist/env.mjs +20 -0
- package/dist/env.mjs.map +1 -0
- package/dist/index.cjs +9 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +90 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +90 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/dist/validators.cjs +91 -0
- package/dist/validators.cjs.map +1 -0
- package/dist/validators.d.cts +16 -0
- package/dist/validators.d.cts.map +1 -0
- package/dist/validators.d.mts +16 -0
- package/dist/validators.d.mts.map +1 -0
- package/dist/validators.mjs +86 -0
- package/dist/validators.mjs.map +1 -0
- package/package.json +78 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAChC,yCAAqC;AAgBtC,OAAO,EAAE,oBAAoB,EAAE,kBAAc","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage';\nexport type {\n AuthenticatedUserStorageActions,\n AuthenticatedUserStorageCacheUpdatedEvent,\n AuthenticatedUserStorageEvents,\n AuthenticatedUserStorageGranularCacheUpdatedEvent,\n AuthenticatedUserStorageInvalidateQueriesAction,\n AuthenticatedUserStorageMessenger,\n} from './authenticated-user-storage';\nexport type {\n AuthenticatedUserStorageServiceListDelegationsAction,\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceRevokeDelegationAction,\n AuthenticatedUserStorageServiceGetNotificationPreferencesAction,\n AuthenticatedUserStorageServicePutNotificationPreferencesAction,\n} from './authenticated-user-storage-method-action-types';\nexport { getUserStorageApiUrl } from './env';\nexport type { Environment } from './env';\nexport type {\n Caveat,\n SignedDelegation,\n DelegationMetadata,\n DelegationSubmission,\n DelegationResponse,\n WalletActivityAccount,\n WalletActivityPreference,\n MarketingPreference,\n PerpsWatchlistExchange,\n PerpsWatchlistMarkets,\n PerpsPreference,\n SocialAIPreference,\n NotificationPreferences,\n ClientType,\n} from './types';\n"]}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n// ---------------------------------------------------------------------------\n// Delegations\n// ---------------------------------------------------------------------------\n\n/** A single caveat attached to a delegation. */\nexport type Caveat = {\n /** Address of the caveat enforcer contract (0x-prefixed). */\n enforcer: Hex;\n /** ABI-encoded caveat terms (0x-prefixed). */\n terms: Hex;\n /** ABI-encoded caveat arguments (0x-prefixed). */\n args: Hex;\n};\n\n/** An EIP-712 signed delegation. */\nexport type SignedDelegation = {\n /** Address the delegation is granted to (0x-prefixed). */\n delegate: Hex;\n /** Address granting the delegation (0x-prefixed). */\n delegator: Hex;\n /** Root authority or parent delegation hash (0x-prefixed). */\n authority: Hex;\n /** Caveats restricting how the delegation may be used. */\n caveats: Caveat[];\n /** Unique salt to prevent replay (0x-prefixed). */\n salt: Hex;\n /** EIP-712 signature over the delegation (0x-prefixed). */\n signature: Hex;\n};\n\n/** Metadata associated with a delegation. */\nexport type DelegationMetadata = {\n /** Keccak-256 hash uniquely identifying the delegation (0x-prefixed). */\n delegationHash: Hex;\n /** Chain ID in hex format (0x-prefixed). */\n chainIdHex: Hex;\n /** Token allowance in hex format (0x-prefixed). */\n allowance: Hex;\n /** Symbol of the token (e.g. \"USDC\"). */\n tokenSymbol: string;\n /** Token contract address (0x-prefixed). */\n tokenAddress: Hex;\n /** Type of delegation. */\n type: string;\n};\n\n/** Request body for submitting a new delegation. */\nexport type DelegationSubmission = {\n signedDelegation: SignedDelegation;\n metadata: DelegationMetadata;\n};\n\n/** A stored delegation record returned by the API. */\nexport type DelegationResponse = {\n signedDelegation: SignedDelegation;\n metadata: DelegationMetadata;\n};\n\n// ---------------------------------------------------------------------------\n// Preferences\n// ---------------------------------------------------------------------------\n\n/** Wallet activity tracking for a single address. */\nexport type WalletActivityAccount = {\n /** Wallet address to track activity for (0x-prefixed). */\n address: Hex;\n enabled: boolean;\n};\n\nexport type WalletActivityPreference = {\n enabled: boolean;\n accounts: WalletActivityAccount[];\n};\n\nexport type MarketingPreference = {\n enabled: boolean;\n};\n\nexport type PerpsWatchlistExchange = {\n testnet: string[];\n mainnet: string[];\n};\n\nexport type PerpsWatchlistMarkets = {\n hyperliquid: PerpsWatchlistExchange;\n myx: PerpsWatchlistExchange;\n};\n\nexport type PerpsPreference = {\n enabled: boolean;\n watchlistMarkets?: PerpsWatchlistMarkets;\n};\n\nexport type SocialAIPreference = {\n enabled: boolean;\n txAmountLimit?: number;\n traderProfileIds: string[];\n};\n\n/** Notification preferences for the authenticated user. */\nexport type NotificationPreferences = {\n walletActivity: WalletActivityPreference;\n marketing: MarketingPreference;\n perps: PerpsPreference;\n socialAI: SocialAIPreference;\n};\n\n// ---------------------------------------------------------------------------\n// Shared\n// ---------------------------------------------------------------------------\n\n/** The type of client making the request. */\nexport type ClientType = 'extension' | 'mobile' | 'portfolio';\n"]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
/** A single caveat attached to a delegation. */
|
|
3
|
+
export type Caveat = {
|
|
4
|
+
/** Address of the caveat enforcer contract (0x-prefixed). */
|
|
5
|
+
enforcer: Hex;
|
|
6
|
+
/** ABI-encoded caveat terms (0x-prefixed). */
|
|
7
|
+
terms: Hex;
|
|
8
|
+
/** ABI-encoded caveat arguments (0x-prefixed). */
|
|
9
|
+
args: Hex;
|
|
10
|
+
};
|
|
11
|
+
/** An EIP-712 signed delegation. */
|
|
12
|
+
export type SignedDelegation = {
|
|
13
|
+
/** Address the delegation is granted to (0x-prefixed). */
|
|
14
|
+
delegate: Hex;
|
|
15
|
+
/** Address granting the delegation (0x-prefixed). */
|
|
16
|
+
delegator: Hex;
|
|
17
|
+
/** Root authority or parent delegation hash (0x-prefixed). */
|
|
18
|
+
authority: Hex;
|
|
19
|
+
/** Caveats restricting how the delegation may be used. */
|
|
20
|
+
caveats: Caveat[];
|
|
21
|
+
/** Unique salt to prevent replay (0x-prefixed). */
|
|
22
|
+
salt: Hex;
|
|
23
|
+
/** EIP-712 signature over the delegation (0x-prefixed). */
|
|
24
|
+
signature: Hex;
|
|
25
|
+
};
|
|
26
|
+
/** Metadata associated with a delegation. */
|
|
27
|
+
export type DelegationMetadata = {
|
|
28
|
+
/** Keccak-256 hash uniquely identifying the delegation (0x-prefixed). */
|
|
29
|
+
delegationHash: Hex;
|
|
30
|
+
/** Chain ID in hex format (0x-prefixed). */
|
|
31
|
+
chainIdHex: Hex;
|
|
32
|
+
/** Token allowance in hex format (0x-prefixed). */
|
|
33
|
+
allowance: Hex;
|
|
34
|
+
/** Symbol of the token (e.g. "USDC"). */
|
|
35
|
+
tokenSymbol: string;
|
|
36
|
+
/** Token contract address (0x-prefixed). */
|
|
37
|
+
tokenAddress: Hex;
|
|
38
|
+
/** Type of delegation. */
|
|
39
|
+
type: string;
|
|
40
|
+
};
|
|
41
|
+
/** Request body for submitting a new delegation. */
|
|
42
|
+
export type DelegationSubmission = {
|
|
43
|
+
signedDelegation: SignedDelegation;
|
|
44
|
+
metadata: DelegationMetadata;
|
|
45
|
+
};
|
|
46
|
+
/** A stored delegation record returned by the API. */
|
|
47
|
+
export type DelegationResponse = {
|
|
48
|
+
signedDelegation: SignedDelegation;
|
|
49
|
+
metadata: DelegationMetadata;
|
|
50
|
+
};
|
|
51
|
+
/** Wallet activity tracking for a single address. */
|
|
52
|
+
export type WalletActivityAccount = {
|
|
53
|
+
/** Wallet address to track activity for (0x-prefixed). */
|
|
54
|
+
address: Hex;
|
|
55
|
+
enabled: boolean;
|
|
56
|
+
};
|
|
57
|
+
export type WalletActivityPreference = {
|
|
58
|
+
enabled: boolean;
|
|
59
|
+
accounts: WalletActivityAccount[];
|
|
60
|
+
};
|
|
61
|
+
export type MarketingPreference = {
|
|
62
|
+
enabled: boolean;
|
|
63
|
+
};
|
|
64
|
+
export type PerpsWatchlistExchange = {
|
|
65
|
+
testnet: string[];
|
|
66
|
+
mainnet: string[];
|
|
67
|
+
};
|
|
68
|
+
export type PerpsWatchlistMarkets = {
|
|
69
|
+
hyperliquid: PerpsWatchlistExchange;
|
|
70
|
+
myx: PerpsWatchlistExchange;
|
|
71
|
+
};
|
|
72
|
+
export type PerpsPreference = {
|
|
73
|
+
enabled: boolean;
|
|
74
|
+
watchlistMarkets?: PerpsWatchlistMarkets;
|
|
75
|
+
};
|
|
76
|
+
export type SocialAIPreference = {
|
|
77
|
+
enabled: boolean;
|
|
78
|
+
txAmountLimit?: number;
|
|
79
|
+
traderProfileIds: string[];
|
|
80
|
+
};
|
|
81
|
+
/** Notification preferences for the authenticated user. */
|
|
82
|
+
export type NotificationPreferences = {
|
|
83
|
+
walletActivity: WalletActivityPreference;
|
|
84
|
+
marketing: MarketingPreference;
|
|
85
|
+
perps: PerpsPreference;
|
|
86
|
+
socialAI: SocialAIPreference;
|
|
87
|
+
};
|
|
88
|
+
/** The type of client making the request. */
|
|
89
|
+
export type ClientType = 'extension' | 'mobile' | 'portfolio';
|
|
90
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAM3C,gDAAgD;AAChD,MAAM,MAAM,MAAM,GAAG;IACnB,6DAA6D;IAC7D,QAAQ,EAAE,GAAG,CAAC;IACd,8CAA8C;IAC9C,KAAK,EAAE,GAAG,CAAC;IACX,kDAAkD;IAClD,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;AAEF,oCAAoC;AACpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,0DAA0D;IAC1D,QAAQ,EAAE,GAAG,CAAC;IACd,qDAAqD;IACrD,SAAS,EAAE,GAAG,CAAC;IACf,8DAA8D;IAC9D,SAAS,EAAE,GAAG,CAAC;IACf,0DAA0D;IAC1D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,mDAAmD;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AAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,2DAA2D;AAC3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,cAAc,EAAE,wBAAwB,CAAC;IACzC,SAAS,EAAE,mBAAmB,CAAC;IAC/B,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,kBAAkB,CAAC;CAC9B,CAAC;AAMF,6CAA6C;AAC7C,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
/** A single caveat attached to a delegation. */
|
|
3
|
+
export type Caveat = {
|
|
4
|
+
/** Address of the caveat enforcer contract (0x-prefixed). */
|
|
5
|
+
enforcer: Hex;
|
|
6
|
+
/** ABI-encoded caveat terms (0x-prefixed). */
|
|
7
|
+
terms: Hex;
|
|
8
|
+
/** ABI-encoded caveat arguments (0x-prefixed). */
|
|
9
|
+
args: Hex;
|
|
10
|
+
};
|
|
11
|
+
/** An EIP-712 signed delegation. */
|
|
12
|
+
export type SignedDelegation = {
|
|
13
|
+
/** Address the delegation is granted to (0x-prefixed). */
|
|
14
|
+
delegate: Hex;
|
|
15
|
+
/** Address granting the delegation (0x-prefixed). */
|
|
16
|
+
delegator: Hex;
|
|
17
|
+
/** Root authority or parent delegation hash (0x-prefixed). */
|
|
18
|
+
authority: Hex;
|
|
19
|
+
/** Caveats restricting how the delegation may be used. */
|
|
20
|
+
caveats: Caveat[];
|
|
21
|
+
/** Unique salt to prevent replay (0x-prefixed). */
|
|
22
|
+
salt: Hex;
|
|
23
|
+
/** EIP-712 signature over the delegation (0x-prefixed). */
|
|
24
|
+
signature: Hex;
|
|
25
|
+
};
|
|
26
|
+
/** Metadata associated with a delegation. */
|
|
27
|
+
export type DelegationMetadata = {
|
|
28
|
+
/** Keccak-256 hash uniquely identifying the delegation (0x-prefixed). */
|
|
29
|
+
delegationHash: Hex;
|
|
30
|
+
/** Chain ID in hex format (0x-prefixed). */
|
|
31
|
+
chainIdHex: Hex;
|
|
32
|
+
/** Token allowance in hex format (0x-prefixed). */
|
|
33
|
+
allowance: Hex;
|
|
34
|
+
/** Symbol of the token (e.g. "USDC"). */
|
|
35
|
+
tokenSymbol: string;
|
|
36
|
+
/** Token contract address (0x-prefixed). */
|
|
37
|
+
tokenAddress: Hex;
|
|
38
|
+
/** Type of delegation. */
|
|
39
|
+
type: string;
|
|
40
|
+
};
|
|
41
|
+
/** Request body for submitting a new delegation. */
|
|
42
|
+
export type DelegationSubmission = {
|
|
43
|
+
signedDelegation: SignedDelegation;
|
|
44
|
+
metadata: DelegationMetadata;
|
|
45
|
+
};
|
|
46
|
+
/** A stored delegation record returned by the API. */
|
|
47
|
+
export type DelegationResponse = {
|
|
48
|
+
signedDelegation: SignedDelegation;
|
|
49
|
+
metadata: DelegationMetadata;
|
|
50
|
+
};
|
|
51
|
+
/** Wallet activity tracking for a single address. */
|
|
52
|
+
export type WalletActivityAccount = {
|
|
53
|
+
/** Wallet address to track activity for (0x-prefixed). */
|
|
54
|
+
address: Hex;
|
|
55
|
+
enabled: boolean;
|
|
56
|
+
};
|
|
57
|
+
export type WalletActivityPreference = {
|
|
58
|
+
enabled: boolean;
|
|
59
|
+
accounts: WalletActivityAccount[];
|
|
60
|
+
};
|
|
61
|
+
export type MarketingPreference = {
|
|
62
|
+
enabled: boolean;
|
|
63
|
+
};
|
|
64
|
+
export type PerpsWatchlistExchange = {
|
|
65
|
+
testnet: string[];
|
|
66
|
+
mainnet: string[];
|
|
67
|
+
};
|
|
68
|
+
export type PerpsWatchlistMarkets = {
|
|
69
|
+
hyperliquid: PerpsWatchlistExchange;
|
|
70
|
+
myx: PerpsWatchlistExchange;
|
|
71
|
+
};
|
|
72
|
+
export type PerpsPreference = {
|
|
73
|
+
enabled: boolean;
|
|
74
|
+
watchlistMarkets?: PerpsWatchlistMarkets;
|
|
75
|
+
};
|
|
76
|
+
export type SocialAIPreference = {
|
|
77
|
+
enabled: boolean;
|
|
78
|
+
txAmountLimit?: number;
|
|
79
|
+
traderProfileIds: string[];
|
|
80
|
+
};
|
|
81
|
+
/** Notification preferences for the authenticated user. */
|
|
82
|
+
export type NotificationPreferences = {
|
|
83
|
+
walletActivity: WalletActivityPreference;
|
|
84
|
+
marketing: MarketingPreference;
|
|
85
|
+
perps: PerpsPreference;
|
|
86
|
+
socialAI: SocialAIPreference;
|
|
87
|
+
};
|
|
88
|
+
/** The type of client making the request. */
|
|
89
|
+
export type ClientType = 'extension' | 'mobile' | 'portfolio';
|
|
90
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAM3C,gDAAgD;AAChD,MAAM,MAAM,MAAM,GAAG;IACnB,6DAA6D;IAC7D,QAAQ,EAAE,GAAG,CAAC;IACd,8CAA8C;IAC9C,KAAK,EAAE,GAAG,CAAC;IACX,kDAAkD;IAClD,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;AAEF,oCAAoC;AACpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,0DAA0D;IAC1D,QAAQ,EAAE,GAAG,CAAC;IACd,qDAAqD;IACrD,SAAS,EAAE,GAAG,CAAC;IACf,8DAA8D;IAC9D,SAAS,EAAE,GAAG,CAAC;IACf,0DAA0D;IAC1D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,mDAAmD;IACnD,IAAI,EAAE,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AAG;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,2DAA2D;AAC3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,cAAc,EAAE,wBAAwB,CAAC;IACzC,SAAS,EAAE,mBAAmB,CAAC;IAC/B,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,kBAAkB,CAAC;CAC9B,CAAC;AAMF,6CAA6C;AAC7C,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC"}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n// ---------------------------------------------------------------------------\n// Delegations\n// ---------------------------------------------------------------------------\n\n/** A single caveat attached to a delegation. */\nexport type Caveat = {\n /** Address of the caveat enforcer contract (0x-prefixed). */\n enforcer: Hex;\n /** ABI-encoded caveat terms (0x-prefixed). */\n terms: Hex;\n /** ABI-encoded caveat arguments (0x-prefixed). */\n args: Hex;\n};\n\n/** An EIP-712 signed delegation. */\nexport type SignedDelegation = {\n /** Address the delegation is granted to (0x-prefixed). */\n delegate: Hex;\n /** Address granting the delegation (0x-prefixed). */\n delegator: Hex;\n /** Root authority or parent delegation hash (0x-prefixed). */\n authority: Hex;\n /** Caveats restricting how the delegation may be used. */\n caveats: Caveat[];\n /** Unique salt to prevent replay (0x-prefixed). */\n salt: Hex;\n /** EIP-712 signature over the delegation (0x-prefixed). */\n signature: Hex;\n};\n\n/** Metadata associated with a delegation. */\nexport type DelegationMetadata = {\n /** Keccak-256 hash uniquely identifying the delegation (0x-prefixed). */\n delegationHash: Hex;\n /** Chain ID in hex format (0x-prefixed). */\n chainIdHex: Hex;\n /** Token allowance in hex format (0x-prefixed). */\n allowance: Hex;\n /** Symbol of the token (e.g. \"USDC\"). */\n tokenSymbol: string;\n /** Token contract address (0x-prefixed). */\n tokenAddress: Hex;\n /** Type of delegation. */\n type: string;\n};\n\n/** Request body for submitting a new delegation. */\nexport type DelegationSubmission = {\n signedDelegation: SignedDelegation;\n metadata: DelegationMetadata;\n};\n\n/** A stored delegation record returned by the API. */\nexport type DelegationResponse = {\n signedDelegation: SignedDelegation;\n metadata: DelegationMetadata;\n};\n\n// ---------------------------------------------------------------------------\n// Preferences\n// ---------------------------------------------------------------------------\n\n/** Wallet activity tracking for a single address. */\nexport type WalletActivityAccount = {\n /** Wallet address to track activity for (0x-prefixed). */\n address: Hex;\n enabled: boolean;\n};\n\nexport type WalletActivityPreference = {\n enabled: boolean;\n accounts: WalletActivityAccount[];\n};\n\nexport type MarketingPreference = {\n enabled: boolean;\n};\n\nexport type PerpsWatchlistExchange = {\n testnet: string[];\n mainnet: string[];\n};\n\nexport type PerpsWatchlistMarkets = {\n hyperliquid: PerpsWatchlistExchange;\n myx: PerpsWatchlistExchange;\n};\n\nexport type PerpsPreference = {\n enabled: boolean;\n watchlistMarkets?: PerpsWatchlistMarkets;\n};\n\nexport type SocialAIPreference = {\n enabled: boolean;\n txAmountLimit?: number;\n traderProfileIds: string[];\n};\n\n/** Notification preferences for the authenticated user. */\nexport type NotificationPreferences = {\n walletActivity: WalletActivityPreference;\n marketing: MarketingPreference;\n perps: PerpsPreference;\n socialAI: SocialAIPreference;\n};\n\n// ---------------------------------------------------------------------------\n// Shared\n// ---------------------------------------------------------------------------\n\n/** The type of client making the request. */\nexport type ClientType = 'extension' | 'mobile' | 'portfolio';\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertNotificationPreferences = exports.assertDelegationResponseArray = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
/**
|
|
6
|
+
* Matches a 0x-prefixed hex string with zero or more hex digits.
|
|
7
|
+
* Unlike `StrictHexStruct` from `@metamask/utils` (which requires at least
|
|
8
|
+
* one digit after the prefix), this also accepts `"0x"` — the standard
|
|
9
|
+
* encoding for empty bytes that the delegation API returns.
|
|
10
|
+
*/
|
|
11
|
+
const HexDataStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), /^0x[0-9a-f]*$/iu);
|
|
12
|
+
const CaveatSchema = (0, superstruct_1.type)({
|
|
13
|
+
enforcer: HexDataStruct,
|
|
14
|
+
terms: HexDataStruct,
|
|
15
|
+
args: HexDataStruct,
|
|
16
|
+
});
|
|
17
|
+
const SignedDelegationSchema = (0, superstruct_1.type)({
|
|
18
|
+
delegate: HexDataStruct,
|
|
19
|
+
delegator: HexDataStruct,
|
|
20
|
+
authority: HexDataStruct,
|
|
21
|
+
caveats: (0, superstruct_1.array)(CaveatSchema),
|
|
22
|
+
salt: HexDataStruct,
|
|
23
|
+
signature: HexDataStruct,
|
|
24
|
+
});
|
|
25
|
+
const DelegationMetadataSchema = (0, superstruct_1.type)({
|
|
26
|
+
delegationHash: HexDataStruct,
|
|
27
|
+
chainIdHex: HexDataStruct,
|
|
28
|
+
allowance: HexDataStruct,
|
|
29
|
+
tokenSymbol: (0, superstruct_1.string)(),
|
|
30
|
+
tokenAddress: HexDataStruct,
|
|
31
|
+
type: (0, superstruct_1.string)(),
|
|
32
|
+
});
|
|
33
|
+
const DelegationResponseSchema = (0, superstruct_1.type)({
|
|
34
|
+
signedDelegation: SignedDelegationSchema,
|
|
35
|
+
metadata: DelegationMetadataSchema,
|
|
36
|
+
});
|
|
37
|
+
const WalletActivityAccountSchema = (0, superstruct_1.type)({
|
|
38
|
+
address: HexDataStruct,
|
|
39
|
+
enabled: (0, superstruct_1.boolean)(),
|
|
40
|
+
});
|
|
41
|
+
const WalletActivityPreferenceSchema = (0, superstruct_1.type)({
|
|
42
|
+
enabled: (0, superstruct_1.boolean)(),
|
|
43
|
+
accounts: (0, superstruct_1.array)(WalletActivityAccountSchema),
|
|
44
|
+
});
|
|
45
|
+
const MarketingPreferenceSchema = (0, superstruct_1.type)({
|
|
46
|
+
enabled: (0, superstruct_1.boolean)(),
|
|
47
|
+
});
|
|
48
|
+
const PerpsWatchlistExchangeSchema = (0, superstruct_1.type)({
|
|
49
|
+
testnet: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
|
50
|
+
mainnet: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
|
51
|
+
});
|
|
52
|
+
const PerpsWatchlistMarketsSchema = (0, superstruct_1.type)({
|
|
53
|
+
hyperliquid: PerpsWatchlistExchangeSchema,
|
|
54
|
+
myx: PerpsWatchlistExchangeSchema,
|
|
55
|
+
});
|
|
56
|
+
const PerpsPreferenceSchema = (0, superstruct_1.type)({
|
|
57
|
+
enabled: (0, superstruct_1.boolean)(),
|
|
58
|
+
watchlistMarkets: (0, superstruct_1.optional)(PerpsWatchlistMarketsSchema),
|
|
59
|
+
});
|
|
60
|
+
const SocialAIPreferenceSchema = (0, superstruct_1.type)({
|
|
61
|
+
enabled: (0, superstruct_1.boolean)(),
|
|
62
|
+
txAmountLimit: (0, superstruct_1.optional)((0, superstruct_1.number)()),
|
|
63
|
+
traderProfileIds: (0, superstruct_1.array)((0, superstruct_1.string)()),
|
|
64
|
+
});
|
|
65
|
+
const NotificationPreferencesSchema = (0, superstruct_1.type)({
|
|
66
|
+
walletActivity: WalletActivityPreferenceSchema,
|
|
67
|
+
marketing: MarketingPreferenceSchema,
|
|
68
|
+
perps: PerpsPreferenceSchema,
|
|
69
|
+
socialAI: SocialAIPreferenceSchema,
|
|
70
|
+
});
|
|
71
|
+
/**
|
|
72
|
+
* Asserts that the given value is a valid `DelegationResponse[]`.
|
|
73
|
+
*
|
|
74
|
+
* @param data - The unknown value to validate.
|
|
75
|
+
* @throws If the value does not match the expected schema.
|
|
76
|
+
*/
|
|
77
|
+
function assertDelegationResponseArray(data) {
|
|
78
|
+
(0, superstruct_1.assert)(data, (0, superstruct_1.array)(DelegationResponseSchema));
|
|
79
|
+
}
|
|
80
|
+
exports.assertDelegationResponseArray = assertDelegationResponseArray;
|
|
81
|
+
/**
|
|
82
|
+
* Asserts that the given value is a valid `NotificationPreferences`.
|
|
83
|
+
*
|
|
84
|
+
* @param data - The unknown value to validate.
|
|
85
|
+
* @throws If the value does not match the expected schema.
|
|
86
|
+
*/
|
|
87
|
+
function assertNotificationPreferences(data) {
|
|
88
|
+
(0, superstruct_1.assert)(data, NotificationPreferencesSchema);
|
|
89
|
+
}
|
|
90
|
+
exports.assertNotificationPreferences = assertNotificationPreferences;
|
|
91
|
+
//# sourceMappingURL=validators.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.cjs","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";;;AAAA,uDAS+B;AAI/B;;;;;GAKG;AACH,MAAM,aAAa,GAAG,IAAA,qBAAO,EAAC,IAAA,oBAAM,GAAE,EAAE,iBAAiB,CAAC,CAAC;AAE3D,MAAM,YAAY,GAAG,IAAA,kBAAI,EAAC;IACxB,QAAQ,EAAE,aAAa;IACvB,KAAK,EAAE,aAAa;IACpB,IAAI,EAAE,aAAa;CACpB,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,IAAA,kBAAI,EAAC;IAClC,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,aAAa;IACxB,SAAS,EAAE,aAAa;IACxB,OAAO,EAAE,IAAA,mBAAK,EAAC,YAAY,CAAC;IAC5B,IAAI,EAAE,aAAa;IACnB,SAAS,EAAE,aAAa;CACzB,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,IAAA,kBAAI,EAAC;IACpC,cAAc,EAAE,aAAa;IAC7B,UAAU,EAAE,aAAa;IACzB,SAAS,EAAE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AC;IACjC,gBAAgB,EAAE,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC;CAClC,CAAC,CAAC;AAEH,MAAM,6BAA6B,GAAG,IAAA,kBAAI,EAAC;IACzC,cAAc,EAAE,8BAA8B;IAC9C,SAAS,EAAE,yBAAyB;IACpC,KAAK,EAAE,qBAAqB;IAC5B,QAAQ,EAAE,wBAAwB;CACnC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAgB,6BAA6B,CAC3C,IAAa;IAEb,IAAA,oBAAM,EAAC,IAAI,EAAE,IAAA,mBAAK,EAAC,wBAAwB,CAAC,CAAC,CAAC;AAChD,CAAC;AAJD,sEAIC;AAED;;;;;GAKG;AACH,SAAgB,6BAA6B,CAC3C,IAAa;IAEb,IAAA,oBAAM,EAAC,IAAI,EAAE,6BAA6B,CAAC,CAAC;AAC9C,CAAC;AAJD,sEAIC","sourcesContent":["import {\n array,\n assert,\n boolean,\n number,\n optional,\n pattern,\n string,\n type,\n} from '@metamask/superstruct';\n\nimport type { DelegationResponse, NotificationPreferences } from './types';\n\n/**\n * Matches a 0x-prefixed hex string with zero or more hex digits.\n * Unlike `StrictHexStruct` from `@metamask/utils` (which requires at least\n * one digit after the prefix), this also accepts `\"0x\"` — the standard\n * encoding for empty bytes that the delegation API returns.\n */\nconst HexDataStruct = pattern(string(), /^0x[0-9a-f]*$/iu);\n\nconst CaveatSchema = type({\n enforcer: HexDataStruct,\n terms: HexDataStruct,\n args: HexDataStruct,\n});\n\nconst SignedDelegationSchema = type({\n delegate: HexDataStruct,\n delegator: HexDataStruct,\n authority: HexDataStruct,\n caveats: array(CaveatSchema),\n salt: HexDataStruct,\n signature: HexDataStruct,\n});\n\nconst DelegationMetadataSchema = type({\n delegationHash: HexDataStruct,\n chainIdHex: HexDataStruct,\n allowance: HexDataStruct,\n tokenSymbol: string(),\n tokenAddress: HexDataStruct,\n type: string(),\n});\n\nconst DelegationResponseSchema = type({\n signedDelegation: SignedDelegationSchema,\n metadata: DelegationMetadataSchema,\n});\n\nconst WalletActivityAccountSchema = type({\n address: HexDataStruct,\n enabled: boolean(),\n});\n\nconst WalletActivityPreferenceSchema = type({\n enabled: boolean(),\n accounts: array(WalletActivityAccountSchema),\n});\n\nconst MarketingPreferenceSchema = type({\n enabled: boolean(),\n});\n\nconst PerpsWatchlistExchangeSchema = type({\n testnet: array(string()),\n mainnet: array(string()),\n});\n\nconst PerpsWatchlistMarketsSchema = type({\n hyperliquid: PerpsWatchlistExchangeSchema,\n myx: PerpsWatchlistExchangeSchema,\n});\n\nconst PerpsPreferenceSchema = type({\n enabled: boolean(),\n watchlistMarkets: optional(PerpsWatchlistMarketsSchema),\n});\n\nconst SocialAIPreferenceSchema = type({\n enabled: boolean(),\n txAmountLimit: optional(number()),\n traderProfileIds: array(string()),\n});\n\nconst NotificationPreferencesSchema = type({\n walletActivity: WalletActivityPreferenceSchema,\n marketing: MarketingPreferenceSchema,\n perps: PerpsPreferenceSchema,\n socialAI: SocialAIPreferenceSchema,\n});\n\n/**\n * Asserts that the given value is a valid `DelegationResponse[]`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertDelegationResponseArray(\n data: unknown,\n): asserts data is DelegationResponse[] {\n assert(data, array(DelegationResponseSchema));\n}\n\n/**\n * Asserts that the given value is a valid `NotificationPreferences`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertNotificationPreferences(\n data: unknown,\n): asserts data is NotificationPreferences {\n assert(data, NotificationPreferencesSchema);\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DelegationResponse, NotificationPreferences } from "./types.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Asserts that the given value is a valid `DelegationResponse[]`.
|
|
4
|
+
*
|
|
5
|
+
* @param data - The unknown value to validate.
|
|
6
|
+
* @throws If the value does not match the expected schema.
|
|
7
|
+
*/
|
|
8
|
+
export declare function assertDelegationResponseArray(data: unknown): asserts data is DelegationResponse[];
|
|
9
|
+
/**
|
|
10
|
+
* Asserts that the given value is a valid `NotificationPreferences`.
|
|
11
|
+
*
|
|
12
|
+
* @param data - The unknown value to validate.
|
|
13
|
+
* @throws If the value does not match the expected schema.
|
|
14
|
+
*/
|
|
15
|
+
export declare function assertNotificationPreferences(data: unknown): asserts data is NotificationPreferences;
|
|
16
|
+
//# sourceMappingURL=validators.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.cts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,oBAAgB;AAiF3E;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,kBAAkB,EAAE,CAEtC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,uBAAuB,CAEzC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DelegationResponse, NotificationPreferences } from "./types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Asserts that the given value is a valid `DelegationResponse[]`.
|
|
4
|
+
*
|
|
5
|
+
* @param data - The unknown value to validate.
|
|
6
|
+
* @throws If the value does not match the expected schema.
|
|
7
|
+
*/
|
|
8
|
+
export declare function assertDelegationResponseArray(data: unknown): asserts data is DelegationResponse[];
|
|
9
|
+
/**
|
|
10
|
+
* Asserts that the given value is a valid `NotificationPreferences`.
|
|
11
|
+
*
|
|
12
|
+
* @param data - The unknown value to validate.
|
|
13
|
+
* @throws If the value does not match the expected schema.
|
|
14
|
+
*/
|
|
15
|
+
export declare function assertNotificationPreferences(data: unknown): asserts data is NotificationPreferences;
|
|
16
|
+
//# sourceMappingURL=validators.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.mts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,oBAAgB;AAiF3E;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,kBAAkB,EAAE,CAEtC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,uBAAuB,CAEzC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { array, assert, boolean, number, optional, pattern, string, type } from "@metamask/superstruct";
|
|
2
|
+
/**
|
|
3
|
+
* Matches a 0x-prefixed hex string with zero or more hex digits.
|
|
4
|
+
* Unlike `StrictHexStruct` from `@metamask/utils` (which requires at least
|
|
5
|
+
* one digit after the prefix), this also accepts `"0x"` — the standard
|
|
6
|
+
* encoding for empty bytes that the delegation API returns.
|
|
7
|
+
*/
|
|
8
|
+
const HexDataStruct = pattern(string(), /^0x[0-9a-f]*$/iu);
|
|
9
|
+
const CaveatSchema = type({
|
|
10
|
+
enforcer: HexDataStruct,
|
|
11
|
+
terms: HexDataStruct,
|
|
12
|
+
args: HexDataStruct,
|
|
13
|
+
});
|
|
14
|
+
const SignedDelegationSchema = type({
|
|
15
|
+
delegate: HexDataStruct,
|
|
16
|
+
delegator: HexDataStruct,
|
|
17
|
+
authority: HexDataStruct,
|
|
18
|
+
caveats: array(CaveatSchema),
|
|
19
|
+
salt: HexDataStruct,
|
|
20
|
+
signature: HexDataStruct,
|
|
21
|
+
});
|
|
22
|
+
const DelegationMetadataSchema = type({
|
|
23
|
+
delegationHash: HexDataStruct,
|
|
24
|
+
chainIdHex: HexDataStruct,
|
|
25
|
+
allowance: HexDataStruct,
|
|
26
|
+
tokenSymbol: string(),
|
|
27
|
+
tokenAddress: HexDataStruct,
|
|
28
|
+
type: string(),
|
|
29
|
+
});
|
|
30
|
+
const DelegationResponseSchema = type({
|
|
31
|
+
signedDelegation: SignedDelegationSchema,
|
|
32
|
+
metadata: DelegationMetadataSchema,
|
|
33
|
+
});
|
|
34
|
+
const WalletActivityAccountSchema = type({
|
|
35
|
+
address: HexDataStruct,
|
|
36
|
+
enabled: boolean(),
|
|
37
|
+
});
|
|
38
|
+
const WalletActivityPreferenceSchema = type({
|
|
39
|
+
enabled: boolean(),
|
|
40
|
+
accounts: array(WalletActivityAccountSchema),
|
|
41
|
+
});
|
|
42
|
+
const MarketingPreferenceSchema = type({
|
|
43
|
+
enabled: boolean(),
|
|
44
|
+
});
|
|
45
|
+
const PerpsWatchlistExchangeSchema = type({
|
|
46
|
+
testnet: array(string()),
|
|
47
|
+
mainnet: array(string()),
|
|
48
|
+
});
|
|
49
|
+
const PerpsWatchlistMarketsSchema = type({
|
|
50
|
+
hyperliquid: PerpsWatchlistExchangeSchema,
|
|
51
|
+
myx: PerpsWatchlistExchangeSchema,
|
|
52
|
+
});
|
|
53
|
+
const PerpsPreferenceSchema = type({
|
|
54
|
+
enabled: boolean(),
|
|
55
|
+
watchlistMarkets: optional(PerpsWatchlistMarketsSchema),
|
|
56
|
+
});
|
|
57
|
+
const SocialAIPreferenceSchema = type({
|
|
58
|
+
enabled: boolean(),
|
|
59
|
+
txAmountLimit: optional(number()),
|
|
60
|
+
traderProfileIds: array(string()),
|
|
61
|
+
});
|
|
62
|
+
const NotificationPreferencesSchema = type({
|
|
63
|
+
walletActivity: WalletActivityPreferenceSchema,
|
|
64
|
+
marketing: MarketingPreferenceSchema,
|
|
65
|
+
perps: PerpsPreferenceSchema,
|
|
66
|
+
socialAI: SocialAIPreferenceSchema,
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Asserts that the given value is a valid `DelegationResponse[]`.
|
|
70
|
+
*
|
|
71
|
+
* @param data - The unknown value to validate.
|
|
72
|
+
* @throws If the value does not match the expected schema.
|
|
73
|
+
*/
|
|
74
|
+
export function assertDelegationResponseArray(data) {
|
|
75
|
+
assert(data, array(DelegationResponseSchema));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Asserts that the given value is a valid `NotificationPreferences`.
|
|
79
|
+
*
|
|
80
|
+
* @param data - The unknown value to validate.
|
|
81
|
+
* @throws If the value does not match the expected schema.
|
|
82
|
+
*/
|
|
83
|
+
export function assertNotificationPreferences(data) {
|
|
84
|
+
assert(data, NotificationPreferencesSchema);
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=validators.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.mjs","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,EACR,OAAO,EACP,MAAM,EACN,IAAI,EACL,8BAA8B;AAI/B;;;;;GAKG;AACH,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAAC,CAAC;AAE3D,MAAM,YAAY,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,aAAa;IACvB,KAAK,EAAE,aAAa;IACpB,IAAI,EAAE,aAAa;CACpB,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,IAAI,CAAC;IAClC,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,aAAa;IACxB,SAAS,EAAE,aAAa;IACxB,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC;IAC5B,IAAI,EAAE,aAAa;IACnB,SAAS,EAAE,aAAa;CACzB,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,IAAI,CAAC;IACpC,cAAc,EAAE,aAAa;IAC7B,UAAU,EAAE,aAAa;IACzB,SAAS,EAAE,aAAa;IACxB,WAAW,EAAE,MAAM,EAAE;IACrB,YAAY,EAAE,aAAa;IAC3B,IAAI,EAAE,MAAM,EAAE;CACf,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,IAAI,CAAC;IACpC,gBAAgB,E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CAAC,wBAAwB,CAAC,CAAC,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAC3C,IAAa;IAEb,MAAM,CAAC,IAAI,EAAE,6BAA6B,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["import {\n array,\n assert,\n boolean,\n number,\n optional,\n pattern,\n string,\n type,\n} from '@metamask/superstruct';\n\nimport type { DelegationResponse, NotificationPreferences } from './types';\n\n/**\n * Matches a 0x-prefixed hex string with zero or more hex digits.\n * Unlike `StrictHexStruct` from `@metamask/utils` (which requires at least\n * one digit after the prefix), this also accepts `\"0x\"` — the standard\n * encoding for empty bytes that the delegation API returns.\n */\nconst HexDataStruct = pattern(string(), /^0x[0-9a-f]*$/iu);\n\nconst CaveatSchema = type({\n enforcer: HexDataStruct,\n terms: HexDataStruct,\n args: HexDataStruct,\n});\n\nconst SignedDelegationSchema = type({\n delegate: HexDataStruct,\n delegator: HexDataStruct,\n authority: HexDataStruct,\n caveats: array(CaveatSchema),\n salt: HexDataStruct,\n signature: HexDataStruct,\n});\n\nconst DelegationMetadataSchema = type({\n delegationHash: HexDataStruct,\n chainIdHex: HexDataStruct,\n allowance: HexDataStruct,\n tokenSymbol: string(),\n tokenAddress: HexDataStruct,\n type: string(),\n});\n\nconst DelegationResponseSchema = type({\n signedDelegation: SignedDelegationSchema,\n metadata: DelegationMetadataSchema,\n});\n\nconst WalletActivityAccountSchema = type({\n address: HexDataStruct,\n enabled: boolean(),\n});\n\nconst WalletActivityPreferenceSchema = type({\n enabled: boolean(),\n accounts: array(WalletActivityAccountSchema),\n});\n\nconst MarketingPreferenceSchema = type({\n enabled: boolean(),\n});\n\nconst PerpsWatchlistExchangeSchema = type({\n testnet: array(string()),\n mainnet: array(string()),\n});\n\nconst PerpsWatchlistMarketsSchema = type({\n hyperliquid: PerpsWatchlistExchangeSchema,\n myx: PerpsWatchlistExchangeSchema,\n});\n\nconst PerpsPreferenceSchema = type({\n enabled: boolean(),\n watchlistMarkets: optional(PerpsWatchlistMarketsSchema),\n});\n\nconst SocialAIPreferenceSchema = type({\n enabled: boolean(),\n txAmountLimit: optional(number()),\n traderProfileIds: array(string()),\n});\n\nconst NotificationPreferencesSchema = type({\n walletActivity: WalletActivityPreferenceSchema,\n marketing: MarketingPreferenceSchema,\n perps: PerpsPreferenceSchema,\n socialAI: SocialAIPreferenceSchema,\n});\n\n/**\n * Asserts that the given value is a valid `DelegationResponse[]`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertDelegationResponseArray(\n data: unknown,\n): asserts data is DelegationResponse[] {\n assert(data, array(DelegationResponseSchema));\n}\n\n/**\n * Asserts that the given value is a valid `NotificationPreferences`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertNotificationPreferences(\n data: unknown,\n): asserts data is NotificationPreferences {\n assert(data, NotificationPreferencesSchema);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metamask-previews/authenticated-user-storage",
|
|
3
|
+
"version": "0.0.0-preview-8e9c439",
|
|
4
|
+
"description": "SDK for authenticated (non-encrypted) user storage endpoints",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Ethereum",
|
|
7
|
+
"MetaMask"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/authenticated-user-storage#readme",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/MetaMask/core/issues"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/MetaMask/core.git"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"main": "./dist/index.cjs",
|
|
23
|
+
"types": "./dist/index.d.cts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": {
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"default": "./dist/index.mjs"
|
|
29
|
+
},
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./dist/index.d.cts",
|
|
32
|
+
"default": "./dist/index.cjs"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"registry": "https://registry.npmjs.org/"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
43
|
+
"build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
|
|
44
|
+
"build:docs": "typedoc",
|
|
45
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/authenticated-user-storage",
|
|
46
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/authenticated-user-storage",
|
|
47
|
+
"messenger-action-types:check": "tsx ../../packages/messenger-cli/src/cli.ts --check",
|
|
48
|
+
"messenger-action-types:generate": "tsx ../../packages/messenger-cli/src/cli.ts --generate",
|
|
49
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
50
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
51
|
+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
52
|
+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
53
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@metamask/base-data-service": "^0.1.1",
|
|
57
|
+
"@metamask/controller-utils": "^11.20.0",
|
|
58
|
+
"@metamask/messenger": "^1.1.1",
|
|
59
|
+
"@metamask/superstruct": "^3.1.0",
|
|
60
|
+
"@metamask/utils": "^11.9.0"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@metamask/auto-changelog": "^6.1.0",
|
|
64
|
+
"@ts-bridge/cli": "^0.6.4",
|
|
65
|
+
"@types/jest": "^29.5.14",
|
|
66
|
+
"deepmerge": "^4.2.2",
|
|
67
|
+
"jest": "^29.7.0",
|
|
68
|
+
"nock": "^13.3.1",
|
|
69
|
+
"ts-jest": "^29.2.5",
|
|
70
|
+
"tsx": "^4.20.5",
|
|
71
|
+
"typedoc": "^0.25.13",
|
|
72
|
+
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
73
|
+
"typescript": "~5.3.3"
|
|
74
|
+
},
|
|
75
|
+
"engines": {
|
|
76
|
+
"node": "^18.18 || >=20"
|
|
77
|
+
}
|
|
78
|
+
}
|