@cartridge/controller 0.12.2 → 0.13.3

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/src/policies.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ Approval,
2
3
  ContractPolicy,
3
4
  Method,
4
5
  SessionPolicies,
@@ -14,7 +15,7 @@ export type ParsedSessionPolicies = {
14
15
  export type SessionContracts = Record<
15
16
  string,
16
17
  Omit<ContractPolicy, "methods"> & {
17
- methods: (Method & { authorized?: boolean })[];
18
+ methods: ((Method | Approval) & { authorized?: boolean })[];
18
19
  }
19
20
  >;
20
21
 
@@ -10,6 +10,8 @@ export type ToastPosition =
10
10
  export interface BaseToastOptions {
11
11
  duration?: number; // in milliseconds, 0 means persistent
12
12
  position?: ToastPosition;
13
+ preset?: string;
14
+ safeToClose?: boolean;
13
15
  onClick?: () => void; // Optional click handler for the entire toast
14
16
  }
15
17
 
@@ -40,6 +42,7 @@ export interface AchievementToastOptions extends BaseToastOptions {
40
42
  title: string;
41
43
  subtitle?: string;
42
44
  xpAmount: number;
45
+ progress: number;
43
46
  isDraft?: boolean;
44
47
  }
45
48
 
@@ -53,9 +56,10 @@ export interface QuestToastOptions extends BaseToastOptions {
53
56
  // Marketplace Toast
54
57
  export interface MarketplaceToastOptions extends BaseToastOptions {
55
58
  variant: "marketplace";
56
- itemName: string;
57
- itemImage: string;
58
- action: "purchased" | "sold";
59
+ itemNames: string[];
60
+ itemImages: string[];
61
+ collectionName: string;
62
+ action: "purchased" | "sold" | "sent" | "listed" | "unlisted";
59
63
  }
60
64
 
61
65
  // Union type for all toast variants
@@ -107,8 +107,8 @@ export function createMarketplaceToast(
107
107
 
108
108
  const image = document.createElement("img");
109
109
  image.className = "image";
110
- image.src = sanitizeImageSrc(options.itemImage);
111
- image.alt = options.itemName;
110
+ image.src = sanitizeImageSrc(options.itemImages[0]);
111
+ image.alt = options.itemNames[0];
112
112
  imageContainer.appendChild(image);
113
113
 
114
114
  const content = document.createElement("div");
@@ -117,6 +117,9 @@ export function createMarketplaceToast(
117
117
  const actionText = {
118
118
  purchased: "Purchased!",
119
119
  sold: "Sold!",
120
+ sent: "Sent!",
121
+ listed: "Listed!",
122
+ unlisted: "Unlisted!",
120
123
  };
121
124
 
122
125
  const title = document.createElement("p");
@@ -125,7 +128,7 @@ export function createMarketplaceToast(
125
128
 
126
129
  const itemName = document.createElement("p");
127
130
  itemName.className = "item-name";
128
- itemName.textContent = options.itemName;
131
+ itemName.textContent = options.itemNames[0];
129
132
 
130
133
  content.appendChild(title);
131
134
  content.appendChild(itemName);
package/src/types.ts CHANGED
@@ -273,4 +273,6 @@ export type OpenOptions = {
273
273
  export type StarterpackOptions = {
274
274
  /** The preimage to use */
275
275
  preimage?: string;
276
+ /** Callback fired after the Play button closes the starterpack modal */
277
+ onPurchaseComplete?: () => void;
276
278
  };
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Policy } from "@cartridge/controller-wasm/controller";
1
+ import { Policy, ApprovalPolicy } from "@cartridge/controller-wasm/controller";
2
2
  import { Policies, SessionPolicies } from "@cartridge/presets";
3
3
  import { ChainId } from "@starknet-io/types-js";
4
4
  import {
@@ -89,34 +89,72 @@ export function toSessionPolicies(policies: Policies): SessionPolicies {
89
89
  : policies;
90
90
  }
91
91
 
92
+ /**
93
+ * Converts parsed session policies to WASM-compatible Policy objects.
94
+ *
95
+ * IMPORTANT: Policies are sorted canonically before hashing. Without this,
96
+ * Object.keys/entries reordering can cause identical policies to produce
97
+ * different merkle roots, leading to "session/not-registered" errors.
98
+ * See: https://github.com/cartridge-gg/controller/issues/2357
99
+ */
92
100
  export function toWasmPolicies(policies: ParsedSessionPolicies): Policy[] {
93
101
  return [
94
- ...Object.entries(policies.contracts ?? {}).flatMap(
95
- ([target, { methods }]) =>
96
- toArray(methods).map((m) => ({
97
- target,
98
- method: hash.getSelectorFromName(m.entrypoint),
99
- authorized: m.authorized,
100
- })),
101
- ),
102
- ...(policies.messages ?? []).map((p) => {
103
- const domainHash = typedData.getStructHash(
104
- p.types,
105
- "StarknetDomain",
106
- p.domain,
107
- TypedDataRevision.ACTIVE,
108
- );
109
- const typeHash = typedData.getTypeHash(
110
- p.types,
111
- p.primaryType,
112
- TypedDataRevision.ACTIVE,
113
- );
102
+ ...Object.entries(policies.contracts ?? {})
103
+ .sort(([a], [b]) => a.toLowerCase().localeCompare(b.toLowerCase()))
104
+ .flatMap(([target, { methods }]) =>
105
+ toArray(methods)
106
+ .slice()
107
+ .sort((a, b) => a.entrypoint.localeCompare(b.entrypoint))
108
+ .map((m): Policy => {
109
+ // Check if this is an approve entrypoint with spender and amount
110
+ if (m.entrypoint === "approve") {
111
+ if ("spender" in m && "amount" in m && m.spender && m.amount) {
112
+ const approvalPolicy: ApprovalPolicy = {
113
+ target,
114
+ spender: m.spender,
115
+ amount: String(m.amount),
116
+ };
117
+ return approvalPolicy;
118
+ }
119
+
120
+ // Fall back to CallPolicy with deprecation warning
121
+ console.warn(
122
+ `[DEPRECATED] Approve method without spender and amount fields will be rejected in future versions. ` +
123
+ `Please update your preset or policies to include both 'spender' and 'amount' fields for approve calls on contract ${target}. ` +
124
+ `Example: { entrypoint: "approve", spender: "0x...", amount: "0x..." }`,
125
+ );
126
+ }
127
+
128
+ // For non-approve methods and legacy approve, create a regular CallPolicy
129
+ return {
130
+ target,
131
+ method: hash.getSelectorFromName(m.entrypoint),
132
+ authorized: m.authorized,
133
+ };
134
+ }),
135
+ ),
136
+ ...(policies.messages ?? [])
137
+ .map((p) => {
138
+ const domainHash = typedData.getStructHash(
139
+ p.types,
140
+ "StarknetDomain",
141
+ p.domain,
142
+ TypedDataRevision.ACTIVE,
143
+ );
144
+ const typeHash = typedData.getTypeHash(
145
+ p.types,
146
+ p.primaryType,
147
+ TypedDataRevision.ACTIVE,
148
+ );
114
149
 
115
- return {
116
- scope_hash: hash.computePoseidonHash(domainHash, typeHash),
117
- authorized: p.authorized,
118
- };
119
- }),
150
+ return {
151
+ scope_hash: hash.computePoseidonHash(domainHash, typeHash),
152
+ authorized: p.authorized,
153
+ };
154
+ })
155
+ .sort((a, b) =>
156
+ a.scope_hash.toString().localeCompare(b.scope_hash.toString()),
157
+ ),
120
158
  ];
121
159
  }
122
160
 
@@ -138,17 +176,14 @@ export function humanizeString(str: string): string {
138
176
 
139
177
  export function parseChainId(url: URL): ChainId {
140
178
  const parts = url.pathname.split("/");
179
+ const isCartridgeHost = url.hostname === "api.cartridge.gg";
141
180
 
142
- // Handle localhost URLs by making a synchronous call to getChainId
143
- if (
144
- url.hostname === "localhost" ||
145
- url.hostname === "127.0.0.1" ||
146
- url.hostname === "0.0.0.0"
147
- ) {
181
+ // Handle non-Cartridge hosts by making a synchronous call to getChainId
182
+ if (!isCartridgeHost) {
148
183
  // Check if we're in a browser environment
149
184
  if (typeof XMLHttpRequest === "undefined") {
150
185
  // In Node.js environment (like tests), we can't make synchronous HTTP calls
151
- // For now, we'll use a placeholder chainId for localhost in tests
186
+ // For now, we'll use a placeholder chainId for non-Cartridge hosts in tests
152
187
  console.warn(
153
188
  `Cannot make synchronous HTTP call in Node.js environment for ${url.toString()}`,
154
189
  );
package/LICENSE DELETED
@@ -1,16 +0,0 @@
1
- Copyright Cartridge Gaming Company 2022. All rights reserved.
2
-
3
- You acknowledge and agree that Cartridge Gaming Company (“Cartridge”) (or Cartridge’s licensors) own all legal right, title and interest in and to the work, software, application, source code, documentation and any other documents in this repository (collectively, the “Program”), including any intellectual property rights which subsist in the Program (whether those rights happen to be registered or not, and wherever in the world those rights may exist), whether in source code or any other form.
4
-
5
- Subject to the limited license below, you may not (and you may not permit anyone else to) distribute, publish, copy, modify, merge, combine with another program, create derivative works of, reverse engineer, decompile or otherwise attempt to extract the source code of, the Program or any part thereof, except that you may contribute to this repository.
6
-
7
- You are granted a non-exclusive, non-transferable, non-sublicensable license to distribute, publish, copy, modify, merge, combine with another program or create derivative works of the Program (such resulting program, collectively, the “Resulting Program”) solely for Non-Commercial Use as long as you:
8
- 1. give prominent notice (“Notice”) with each copy of the Resulting Program that the Program is used in the Resulting Program and that the Program is the copyright of Cartridge; and
9
- 2. subject the Resulting Program and any distribution, publication, copy, modification, merger therewith, combination with another program or derivative works thereof to the same Notice requirement and Non-Commercial Use restriction set forth herein.
10
-
11
- “Non-Commercial Use” means each use as described in clauses (1)-(3) below, as reasonably determined by Cartridge in its sole discretion:
12
- 1. personal use for research, personal study, private entertainment, hobby projects or amateur pursuits, in each case without any anticipated commercial application;
13
- 2. use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization or government institution; or
14
- 3. the number of monthly active users of the Resulting Program across all versions thereof and platforms globally do not exceed 10,000 at any time.
15
-
16
- You will not use any trade mark, service mark, trade name, logo of Cartridge or any other company or organization in a way that is likely or intended to cause confusion about the owner or authorized user of such marks, names or logos.
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider-B8OiOgBt.js","sources":["../src/wallets/types.ts","../src/types.ts","../src/utils.ts","../src/constants.ts","../src/errors.ts","../../../node_modules/.pnpm/@starknet-io+types-js@0.8.4/node_modules/@starknet-io/types-js/dist/esm/wallet-api/constants.js","../src/icon.ts","../src/mutex.ts","../src/provider.ts"],"sourcesContent":["export const AUTH_EXTERNAL_WALLETS = [\n \"metamask\",\n \"rabby\",\n \"phantom-evm\",\n] as const;\nexport type AuthExternalWallet = (typeof AUTH_EXTERNAL_WALLETS)[number];\n\nexport const EXTRA_EXTERNAL_WALLETS = [\n \"argent\",\n \"braavos\",\n \"phantom\",\n \"base\",\n] as const;\nexport type ExtraExternalWallet = (typeof EXTRA_EXTERNAL_WALLETS)[number];\n\nexport const EXTERNAL_WALLETS = [\n ...AUTH_EXTERNAL_WALLETS,\n ...EXTRA_EXTERNAL_WALLETS,\n] as const;\n\nexport type ExternalWalletType = (typeof EXTERNAL_WALLETS)[number];\n\nexport type ExternalPlatform =\n | \"starknet\"\n | \"ethereum\"\n | \"solana\"\n | \"base\"\n | \"arbitrum\"\n | \"optimism\";\n\nexport interface ExternalWallet {\n type: ExternalWalletType;\n available: boolean;\n version?: string;\n chainId?: string;\n name?: string;\n platform?: ExternalPlatform;\n connectedAccounts?: string[];\n}\n\nexport interface ExternalWalletResponse<T = unknown> {\n success: boolean;\n wallet: ExternalWalletType;\n result?: T;\n error?: string;\n account?: string;\n}\n\nexport interface WalletAdapter {\n type: ExternalWalletType;\n platform: ExternalPlatform | undefined;\n\n // Methods\n isAvailable(): boolean;\n getInfo(): ExternalWallet;\n getConnectedAccounts(): string[];\n connect(): Promise<ExternalWalletResponse<any>>;\n signMessage?(\n message: string,\n address?: string,\n ): Promise<ExternalWalletResponse<any>>;\n signTypedData?(data: any): Promise<ExternalWalletResponse<any>>;\n sendTransaction(tx: any): Promise<ExternalWalletResponse<any>>;\n getBalance(tokenAddress?: string): Promise<ExternalWalletResponse<any>>;\n switchChain(chainId: string): Promise<boolean>;\n waitForTransaction(\n txHash: string,\n timeoutMs?: number,\n ): Promise<ExternalWalletResponse<any>>;\n disconnect?(): void;\n}\n","import { Policy, SessionPolicies } from \"@cartridge/presets\";\nimport {\n AddInvokeTransactionResult,\n ChainId,\n Signature,\n TypedData,\n} from \"@starknet-io/types-js\";\nimport {\n Abi,\n BigNumberish,\n Call,\n constants,\n InvocationsDetails,\n} from \"starknet\";\nimport { KeychainIFrame } from \"./iframe\";\nimport {\n AUTH_EXTERNAL_WALLETS,\n EXTERNAL_WALLETS,\n ExternalWallet,\n ExternalWalletResponse,\n ExternalWalletType,\n} from \"./wallets/types\";\n\nexport type KeychainSession = {\n chainId: constants.StarknetChainId;\n policies: Policy[];\n maxFee: BigNumberish;\n expiresAt: bigint;\n credentials: {\n authorization: string[];\n privateKey: string;\n };\n};\n\nexport const EMBEDDED_WALLETS = [\n \"google\",\n \"webauthn\",\n \"discord\",\n \"walletconnect\",\n \"password\",\n] as const;\n\nexport type EmbeddedWallet = (typeof EMBEDDED_WALLETS)[number];\n\nexport const ALL_AUTH_OPTIONS = [\n ...EMBEDDED_WALLETS,\n ...EXTERNAL_WALLETS,\n] as const;\n\nexport type AuthOption = (typeof ALL_AUTH_OPTIONS)[number];\n\nexport const IMPLEMENTED_AUTH_OPTIONS = [\n ...EMBEDDED_WALLETS,\n ...AUTH_EXTERNAL_WALLETS,\n];\n\nexport type AuthOptions = (typeof IMPLEMENTED_AUTH_OPTIONS)[number][];\n\nexport enum ResponseCodes {\n SUCCESS = \"SUCCESS\",\n NOT_CONNECTED = \"NOT_CONNECTED\",\n ERROR = \"ERROR\",\n CANCELED = \"CANCELED\",\n USER_INTERACTION_REQUIRED = \"USER_INTERACTION_REQUIRED\",\n}\n\nexport type ConnectError = {\n code: ResponseCodes;\n message: string;\n error?: ControllerError;\n};\n\nexport type ControllerError = {\n code: Number;\n message: string;\n data?: any;\n};\n\nexport type ConnectReply = {\n code: ResponseCodes.SUCCESS;\n address: string;\n policies?: SessionPolicies;\n};\n\nexport type ExecuteReply =\n | (AddInvokeTransactionResult & {\n code: ResponseCodes.SUCCESS;\n })\n | {\n code: ResponseCodes.USER_INTERACTION_REQUIRED;\n };\n\nexport type ProbeReply = {\n code: ResponseCodes.SUCCESS;\n address: string;\n rpcUrl?: string;\n};\n\nexport type DeployReply = {\n code: ResponseCodes.SUCCESS;\n transaction_hash: string;\n};\n\nexport type IFrames = {\n keychain?: KeychainIFrame;\n version?: number;\n};\n\nexport interface LookupRequest {\n usernames?: string[];\n addresses?: string[];\n}\n\nexport interface LookupResult {\n username: string;\n addresses: string[];\n}\n\nexport interface LookupResponse {\n results: LookupResult[];\n}\n\nexport enum FeeSource {\n PAYMASTER = \"PAYMASTER\",\n CREDITS = \"CREDITS\",\n}\n\ntype ContractAddress = string;\ntype CartridgeID = string;\nexport type ControllerAccounts = Record<ContractAddress, CartridgeID>;\n\nexport interface Keychain {\n probe(rpcUrl: string): Promise<ProbeReply | ConnectError>;\n connect(signupOptions?: AuthOptions): Promise<ConnectReply | ConnectError>;\n disconnect(): void;\n\n reset(): void;\n revoke(origin: string): void;\n\n deploy(): Promise<DeployReply | ConnectError>;\n execute(\n calls: Call | Call[],\n abis?: Abi[],\n transactionsDetail?: InvocationsDetails,\n sync?: boolean,\n feeSource?: any,\n error?: ControllerError,\n ): Promise<ExecuteReply | ConnectError>;\n signMessage(\n typedData: TypedData,\n account: string,\n async?: boolean,\n ): Promise<Signature | ConnectError>;\n openSettings(): Promise<void | ConnectError>;\n session(): Promise<KeychainSession>;\n sessions(): Promise<{\n [key: string]: KeychainSession;\n }>;\n delegateAccount(): string;\n username(): string;\n openPurchaseCredits(): void;\n openExecute(calls: Call[]): Promise<void>;\n switchChain(rpcUrl: string): Promise<void>;\n openStarterPack(\n id: string | number,\n options?: StarterpackOptions,\n ): Promise<void>;\n navigate(path: string): Promise<void>;\n\n // External wallet methods\n externalDetectWallets(): Promise<ExternalWallet[]>;\n externalConnectWallet(\n type: ExternalWalletType,\n address?: string,\n ): Promise<ExternalWalletResponse>;\n externalSignMessage(\n type: ExternalWalletType,\n message: string,\n ): Promise<ExternalWalletResponse>;\n externalSignTypedData(\n type: ExternalWalletType,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: any,\n ): Promise<ExternalWalletResponse>;\n externalGetBalance(\n type: ExternalWalletType,\n tokenAddress?: string,\n ): Promise<ExternalWalletResponse>;\n externalSwitchChain(\n type: ExternalWalletType,\n chainId: string,\n ): Promise<boolean>;\n}\n\nexport interface Profile {\n navigate(path: string): void;\n switchChain(rpcUrl: string): Promise<void>;\n}\n\nexport interface Modal {\n open: () => void;\n close: () => void;\n}\n\n/**\n * Options for configuring the controller\n */\nexport type ControllerOptions = ProviderOptions & KeychainOptions;\n\nexport type IFrameOptions = {\n /** The ID of the starter pack to use */\n starterPackId?: string;\n /** The preset to use */\n preset?: string;\n};\n\nexport type Chain = {\n rpcUrl: string;\n};\n\nexport type ProviderOptions = {\n defaultChainId?: ChainId;\n chains?: Chain[];\n};\n\nexport type KeychainOptions = IFrameOptions & {\n policies?: SessionPolicies;\n /** The URL of keychain */\n url?: string;\n /** The origin of keychain */\n origin?: string;\n /** The RPC URL to use (derived from defaultChainId) */\n rpcUrl?: string;\n /** Propagate transaction errors back to caller instead of showing modal */\n propagateSessionErrors?: boolean;\n /** How to display transaction/execution errors to the user ('modal' | 'notification' | 'silent'). Defaults to 'modal'. */\n errorDisplayMode?: \"modal\" | \"notification\" | \"silent\";\n /** The fee source to use for execute from outside */\n feeSource?: FeeSource;\n /** Signup options (the order of the options is reflected in the UI. It's recommended to group socials and wallets together ) */\n signupOptions?: AuthOptions;\n /** When true, manually provided policies will override preset policies. Default is false. */\n shouldOverridePresetPolicies?: boolean;\n /** The project name of Slot instance. */\n slot?: string;\n /** The namespace to use to fetch trophies data from indexer. Will be mandatory once profile page is in production */\n namespace?: string;\n /** The tokens to be listed on Inventory modal */\n tokens?: Tokens;\n /** When true, defer iframe mounting until connect() is called. Reduces initial load and resource fetching. */\n lazyload?: boolean;\n};\n\nexport type ProfileContextTypeVariant =\n | \"inventory\"\n | \"trophies\"\n | \"achievements\"\n | \"quests\"\n | \"leaderboard\"\n | \"activity\";\n\nexport type Token = \"eth\" | \"strk\" | \"lords\" | \"usdc\" | \"usdt\";\n\nexport type Tokens = {\n erc20?: Token[];\n};\n\nexport type OpenOptions = {\n /** The URL to redirect to after authentication (defaults to current page) */\n redirectUrl?: string;\n};\n\nexport type StarterpackOptions = {\n /** The preimage to use */\n preimage?: string;\n};\n","import { Policy } from \"@cartridge/controller-wasm/controller\";\nimport { Policies, SessionPolicies } from \"@cartridge/presets\";\nimport { ChainId } from \"@starknet-io/types-js\";\nimport {\n addAddressPadding,\n Call,\n CallData,\n constants,\n getChecksumAddress,\n hash,\n shortString,\n typedData,\n TypedDataRevision,\n} from \"starknet\";\nimport { ParsedSessionPolicies } from \"./policies\";\n\n// Whitelist of allowed property names to prevent prototype pollution\nconst ALLOWED_PROPERTIES = new Set([\n \"contracts\",\n \"messages\",\n \"target\",\n \"method\",\n \"name\",\n \"description\",\n \"types\",\n \"domain\",\n \"primaryType\",\n]);\n\nfunction validatePropertyName(prop: string): void {\n if (!ALLOWED_PROPERTIES.has(prop)) {\n throw new Error(`Invalid property name: ${prop}`);\n }\n}\n\nfunction safeObjectAccess<T>(obj: any, prop: string): T {\n validatePropertyName(prop);\n return obj[prop];\n}\n\nexport function normalizeCalls(calls: Call | Call[]) {\n return toArray(calls).map((call) => {\n return {\n entrypoint: call.entrypoint,\n contractAddress: addAddressPadding(call.contractAddress),\n calldata: CallData.toHex(call.calldata),\n };\n });\n}\n\nexport function toSessionPolicies(policies: Policies): SessionPolicies {\n return Array.isArray(policies)\n ? policies.reduce<SessionPolicies>(\n (prev, p) => {\n if (safeObjectAccess<string>(p, \"target\")) {\n const target = getChecksumAddress(\n safeObjectAccess<string>(p, \"target\"),\n );\n const entrypoint = safeObjectAccess<string>(p, \"method\");\n const contracts = safeObjectAccess<Record<string, any>>(\n prev,\n \"contracts\",\n );\n const item = {\n name: humanizeString(entrypoint),\n entrypoint: entrypoint,\n description: safeObjectAccess<string>(p, \"description\"),\n };\n\n if (target in contracts) {\n const methods = toArray(contracts[target].methods);\n contracts[target] = {\n methods: [...methods, item],\n };\n } else {\n contracts[target] = {\n methods: [item],\n };\n }\n } else {\n const messages = safeObjectAccess<any[]>(prev, \"messages\");\n messages.push(p);\n }\n\n return prev;\n },\n { contracts: {}, messages: [] },\n )\n : policies;\n}\n\nexport function toWasmPolicies(policies: ParsedSessionPolicies): Policy[] {\n return [\n ...Object.entries(policies.contracts ?? {}).flatMap(\n ([target, { methods }]) =>\n toArray(methods).map((m) => ({\n target,\n method: hash.getSelectorFromName(m.entrypoint),\n authorized: m.authorized,\n })),\n ),\n ...(policies.messages ?? []).map((p) => {\n const domainHash = typedData.getStructHash(\n p.types,\n \"StarknetDomain\",\n p.domain,\n TypedDataRevision.ACTIVE,\n );\n const typeHash = typedData.getTypeHash(\n p.types,\n p.primaryType,\n TypedDataRevision.ACTIVE,\n );\n\n return {\n scope_hash: hash.computePoseidonHash(domainHash, typeHash),\n authorized: p.authorized,\n };\n }),\n ];\n}\n\nexport function toArray<T>(val: T | T[]): T[] {\n return Array.isArray(val) ? val : [val];\n}\n\nexport function humanizeString(str: string): string {\n return (\n str\n // Convert from camelCase or snake_case\n .replace(/([a-z])([A-Z])/g, \"$1 $2\") // camelCase to spaces\n .replace(/_/g, \" \") // snake_case to spaces\n .toLowerCase()\n // Capitalize first letter\n .replace(/^\\w/, (c) => c.toUpperCase())\n );\n}\n\nexport function parseChainId(url: URL): ChainId {\n const parts = url.pathname.split(\"/\");\n\n // Handle localhost URLs by making a synchronous call to getChainId\n if (\n url.hostname === \"localhost\" ||\n url.hostname === \"127.0.0.1\" ||\n url.hostname === \"0.0.0.0\"\n ) {\n // Check if we're in a browser environment\n if (typeof XMLHttpRequest === \"undefined\") {\n // In Node.js environment (like tests), we can't make synchronous HTTP calls\n // For now, we'll use a placeholder chainId for localhost in tests\n console.warn(\n `Cannot make synchronous HTTP call in Node.js environment for ${url.toString()}`,\n );\n return shortString.encodeShortString(\"LOCALHOST\") as ChainId;\n }\n\n // Use a synchronous XMLHttpRequest to get the chain ID\n const xhr = new XMLHttpRequest();\n xhr.open(\"POST\", url.toString(), false); // false makes it synchronous\n xhr.setRequestHeader(\"Content-Type\", \"application/json\");\n\n const requestBody = JSON.stringify({\n jsonrpc: \"2.0\",\n method: \"starknet_chainId\",\n params: [],\n id: 1,\n });\n\n try {\n xhr.send(requestBody);\n\n if (xhr.status === 200) {\n const response = JSON.parse(xhr.responseText);\n if (response.result) {\n return response.result as ChainId;\n }\n }\n\n throw new Error(\n `Failed to get chain ID from ${url.toString()}: ${xhr.status} ${xhr.statusText}`,\n );\n } catch (error) {\n throw new Error(`Failed to connect to ${url.toString()}: ${error}`);\n }\n }\n\n if (parts.includes(\"starknet\")) {\n if (parts.includes(\"mainnet\")) {\n return constants.StarknetChainId.SN_MAIN;\n } else if (parts.includes(\"sepolia\")) {\n return constants.StarknetChainId.SN_SEPOLIA;\n }\n } else if (parts.length >= 3) {\n const projectName = parts[2];\n if (parts.includes(\"katana\")) {\n return shortString.encodeShortString(\n `WP_${projectName.toUpperCase().replace(/-/g, \"_\")}`,\n ) as ChainId;\n } else if (parts.includes(\"mainnet\")) {\n return shortString.encodeShortString(\n `GG_${projectName.toUpperCase().replace(/-/g, \"_\")}`,\n ) as ChainId;\n }\n }\n\n throw new Error(`Chain ${url.toString()} not supported`);\n}\n\nexport function isMobile() {\n return (\n window.matchMedia(\"(max-width: 768px)\").matches ||\n \"ontouchstart\" in window ||\n navigator.maxTouchPoints > 0\n );\n}\n\n// Sanitize image src to prevent XSS\nexport function sanitizeImageSrc(src: string): string {\n // Allow only http/https URLs (absolute)\n try {\n const url = new URL(src, window.location.origin);\n if (url.protocol === \"http:\" || url.protocol === \"https:\") {\n return url.href;\n }\n } catch (_) {\n // If invalid, fall through to fallback src below\n }\n // Fallback image (transparent pixel or default)\n return \"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\";\n}\n","export const KEYCHAIN_URL = \"https://x.cartridge.gg\";\nexport const PROFILE_URL = \"https://profile.cartridge.gg\";\nexport const API_URL = \"https://api.cartridge.gg\";\n","export class NotReadyToConnect extends Error {\n constructor() {\n super(\"Not ready to connect\");\n\n Object.setPrototypeOf(this, NotReadyToConnect.prototype);\n }\n}\n","export const Permission = {\n ACCOUNTS: 'accounts',\n};\n//# sourceMappingURL=constants.js.map","export const icon =\n \"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iODAwIiBoZWlnaHQ9IjgwMCIgdmlld0JveD0iMCAwIDgwMCA4MDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGZpbHRlcj0idXJsKCNmaWx0ZXIwX2RfNTExMl83ODIpIj4KPHBhdGggZD0iTTQ2OS4yMzYgNzBDNDgyLjM5IDcwIDQ5My4wNTMgODAuNjYzIDQ5My4wNTMgOTMuODE2NFYxNDcuMTQ3TDUxNS4zMz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W4yPSJoYXJkQWxwaGEiIG9wZXJhdG9yPSJvdXQiLz4KPGZlQ29sb3JNYXRyaXggdHlwZT0ibWF0cml4IiB2YWx1ZXM9IjAgMCAwIDAgMCAwIDAgMCAwIDAgMCAwIDAgMCAwIDAgMCAwIDAuMjUgMCIvPgo8ZmVCbGVuZCBtb2RlPSJub3JtYWwiIGluMj0iQmFja2dyb3VuZEltYWdlRml4IiByZXN1bHQ9ImVmZmVjdDFfZHJvcFNoYWRvd181MTEyXzc4MiIvPgo8ZmVCbGVuZCBtb2RlPSJub3JtYWwiIGluPSJTb3VyY2VHcmFwaGljIiBpbjI9ImVmZmVjdDFfZHJvcFNoYWRvd181MTEyXzc4MiIgcmVzdWx0PSJzaGFwZSIvPgo8L2ZpbHRlcj4KPC9kZWZzPgo8L3N2Zz4K\";\n","function releaseStub() {}\n\n/**\n * A simple mutual exclusion lock. It allows you to obtain and release a lock,\n * ensuring that only one task can access a critical section at a time.\n */\nexport class Mutex {\n private m_lastPromise: Promise<void> = Promise.resolve();\n\n /**\n * Acquire lock\n * @param [bypass=false] option to skip lock acquisition\n */\n public async obtain(bypass = false): Promise<() => void> {\n let release = releaseStub;\n if (bypass) return release;\n const lastPromise = this.m_lastPromise;\n this.m_lastPromise = new Promise<void>((resolve) => (release = resolve));\n await lastPromise;\n return release;\n }\n}\n","import {\n AddInvokeTransactionParameters,\n AddStarknetChainParameters,\n Permission,\n RequestAccountsParameters,\n RequestFn,\n StarknetWindowObject,\n SwitchStarknetChainParameters,\n TypedData,\n UNEXPECTED_ERROR,\n WalletEventHandlers,\n WalletEventListener,\n WalletEvents,\n} from \"@starknet-io/types-js\";\nimport { WalletAccount } from \"starknet\";\nimport manifest from \"../package.json\";\n\nimport { icon } from \"./icon\";\nimport { Mutex } from \"./mutex\";\n\nconst mutex = new Mutex();\n\nexport default abstract class BaseProvider implements StarknetWindowObject {\n public id = \"controller\";\n public name = \"Controller\";\n public version = manifest.version;\n public icon = icon;\n\n public account?: WalletAccount;\n public subscriptions: WalletEvents[] = [];\n\n private _probePromise: Promise<WalletAccount | undefined> | null = null;\n\n protected async safeProbe(): Promise<WalletAccount | undefined> {\n // If we already have an account, return it\n if (this.account) {\n return this.account;\n }\n\n // If we're already probing, wait for the existing probe\n if (this._probePromise) {\n return this._probePromise;\n }\n\n const release = await mutex.obtain();\n return await new Promise<WalletAccount | undefined>(async (resolve) => {\n try {\n this._probePromise = this.probe();\n const result = await this._probePromise;\n resolve(result);\n } finally {\n this._probePromise = null;\n }\n }).finally(() => {\n release();\n });\n }\n\n request: RequestFn = async (call) => {\n switch (call.type) {\n case \"wallet_getPermissions\":\n await this.safeProbe();\n\n if (this.account) {\n return [Permission.ACCOUNTS];\n }\n\n return [];\n\n case \"wallet_requestAccounts\": {\n if (this.account) {\n return [this.account.address];\n }\n\n const silentMode =\n call.params && (call.params as RequestAccountsParameters).silent_mode;\n\n this.account = await this.safeProbe();\n\n if (!this.account && !silentMode) {\n this.account = await this.connect();\n }\n\n if (this.account) {\n return [this.account.address];\n }\n\n return [];\n }\n\n case \"wallet_watchAsset\":\n throw {\n code: 63,\n message: \"An unexpected error occurred\",\n data: \"wallet_watchAsset not implemented\",\n } as UNEXPECTED_ERROR;\n\n case \"wallet_addStarknetChain\": {\n let params = call.params as AddStarknetChainParameters;\n return this.addStarknetChain(params);\n }\n\n case \"wallet_switchStarknetChain\": {\n let params = call.params as SwitchStarknetChainParameters;\n return this.switchStarknetChain(params.chainId);\n }\n\n case \"wallet_requestChainId\":\n if (!this.account) {\n throw {\n code: 63,\n message: \"An unexpected error occurred\",\n data: \"Account not initialized\",\n } as UNEXPECTED_ERROR;\n }\n\n return await this.account.getChainId();\n\n case \"wallet_deploymentData\":\n throw {\n code: 63,\n message: \"An unexpected error occurred\",\n data: \"wallet_deploymentData not implemented\",\n } as UNEXPECTED_ERROR;\n\n case \"wallet_addInvokeTransaction\":\n if (!this.account) {\n throw {\n code: 63,\n message: \"An unexpected error occurred\",\n data: \"Account not initialized\",\n } as UNEXPECTED_ERROR;\n }\n\n let params = call.params as AddInvokeTransactionParameters;\n return await this.account.execute(\n params.calls.map((call) => ({\n contractAddress: call.contract_address,\n entrypoint: call.entry_point,\n calldata: call.calldata,\n })),\n );\n\n case \"wallet_addDeclareTransaction\":\n throw {\n code: 63,\n message: \"An unexpected error occurred\",\n data: \"wallet_addDeclareTransaction not implemented\",\n } as UNEXPECTED_ERROR;\n\n case \"wallet_signTypedData\": {\n if (!this.account) {\n throw {\n code: 63,\n message: \"An unexpected error occurred\",\n data: \"Account not initialized\",\n } as UNEXPECTED_ERROR;\n }\n\n return await this.account.signMessage(call.params as TypedData);\n }\n\n case \"wallet_supportedSpecs\":\n return [];\n case \"wallet_supportedWalletApi\":\n return [];\n default:\n throw {\n code: 63,\n message: \"An unexpected error occurred\",\n data: `Unknown RPC call type: ${call.type}`,\n } as UNEXPECTED_ERROR;\n }\n };\n\n on: WalletEventListener = <E extends keyof WalletEventHandlers>(\n event: E,\n handler: WalletEventHandlers[E],\n ): void => {\n if (event !== \"accountsChanged\" && event !== \"networkChanged\") {\n throw new Error(`Unknown event: ${event}`);\n }\n this.subscriptions.push({ type: event, handler } as WalletEvents);\n };\n\n off: WalletEventListener = <E extends keyof WalletEventHandlers>(\n event: E,\n handler: WalletEventHandlers[E],\n ): void => {\n if (event !== \"accountsChanged\" && event !== \"networkChanged\") {\n throw new Error(`Unknown event: ${event}`);\n }\n const idx = this.subscriptions.findIndex(\n (sub) => sub.type === event && sub.handler === handler,\n );\n if (idx >= 0) {\n this.subscriptions.splice(idx, 1);\n }\n };\n\n protected emitNetworkChanged(chainId: string) {\n this.subscriptions\n .filter((sub) => sub.type === \"networkChanged\")\n .forEach((sub) => {\n (sub.handler as WalletEventHandlers[\"networkChanged\"])(chainId);\n });\n }\n\n protected emitAccountsChanged(accounts: string[]) {\n this.subscriptions\n .filter((sub) => sub.type === \"accountsChanged\")\n .forEach((sub) => {\n (sub.handler as WalletEventHandlers[\"accountsChanged\"])(accounts);\n });\n }\n\n abstract probe(): Promise<WalletAccount | undefined>;\n abstract connect(): Promise<WalletAccount | undefined>;\n abstract switchStarknetChain(chainId: string): Promise<boolean>;\n abstract addStarknetChain(\n chain: AddStarknetChainParameters,\n ): Promise<boolean>;\n}\n"],"names":["AUTH_EXTERNAL_WALLETS","EXTRA_EXTERNAL_WALLETS","EXTERNAL_WALLETS","EMBEDDED_WALLETS","ALL_AUTH_OPTIONS","IMPLEMENTED_AUTH_OPTIONS","ResponseCodes","FeeSource","ALLOWED_PROPERTIES","validatePropertyName","prop","safeObjectAccess","obj","normalizeCalls","calls","toArray","call","addAddressPadding","CallData","toSessionPolicies","policies","prev","p","target","getChecksumAddress","entrypoint","contracts","item","humanizeString","methods","toWasmPolicies","m","hash","domainHash","typedData","TypedDataRevision","typeHash","val","str","c","parseChainId","url","parts","shortString","xhr","requestBody","response","error","constants","projectName","isMobile","sanitizeImageSrc","src","KEYCHAIN_URL","API_URL","NotReadyToConnect","Permission","icon","releaseStub","Mutex","bypass","release","lastPromise","resolve","mutex","BaseProvider","manifest","result","silentMode","params","event","handler","idx","sub","chainId","accounts"],"mappings":";;;GAAaA,IAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF,GAGaC,IAAyB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAGaC,IAAmB;AAAA,EAC9B,GAAGF;AAAA,EACH,GAAGC;AACL,GCgBaE,IAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAIaC,IAAmB;AAAA,EAC9B,GAAGD;AAAA,EACH,GAAGD;AACL,GAIaG,IAA2B;AAAA,EACtC,GAAGF;AAAA,EACH,GAAGH;AACL;AAIY,IAAAM,sBAAAA,OACVA,EAAA,UAAU,WACVA,EAAA,gBAAgB,iBAChBA,EAAA,QAAQ,SACRA,EAAA,WAAW,YACXA,EAAA,4BAA4B,6BALlBA,IAAAA,KAAA,CAAA,CAAA,GAgEAC,sBAAAA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