@cartridge/controller 0.5.4 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.turbo/turbo-build$colon$deps.log +39 -36
  2. package/.turbo/turbo-build.log +40 -37
  3. package/dist/account.d.ts +2 -2
  4. package/dist/account.js.map +1 -1
  5. package/dist/controller.d.ts +3 -3
  6. package/dist/controller.js +41 -12
  7. package/dist/controller.js.map +1 -1
  8. package/dist/iframe/base.d.ts +2 -2
  9. package/dist/iframe/base.js +13 -1
  10. package/dist/iframe/base.js.map +1 -1
  11. package/dist/iframe/index.d.ts +2 -2
  12. package/dist/iframe/index.js +20 -4
  13. package/dist/iframe/index.js.map +1 -1
  14. package/dist/iframe/keychain.d.ts +2 -2
  15. package/dist/iframe/keychain.js +13 -1
  16. package/dist/iframe/keychain.js.map +1 -1
  17. package/dist/iframe/profile.d.ts +2 -2
  18. package/dist/iframe/profile.js +20 -4
  19. package/dist/iframe/profile.js.map +1 -1
  20. package/dist/index.d-BbTUPBeO.d.ts +68 -0
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +8656 -14
  23. package/dist/index.js.map +1 -1
  24. package/dist/provider.d.ts +2 -2
  25. package/dist/session/account.d.ts +2 -2
  26. package/dist/session/account.js.map +1 -1
  27. package/dist/session/index.d.ts +2 -2
  28. package/dist/session/index.js.map +1 -1
  29. package/dist/session/provider.d.ts +2 -2
  30. package/dist/session/provider.js.map +1 -1
  31. package/dist/telegram/provider.d.ts +2 -2
  32. package/dist/telegram/provider.js.map +1 -1
  33. package/dist/{types-1WsOoNO2.d.ts → types-BReKRAuh.d.ts} +11 -5
  34. package/dist/types.d.ts +2 -2
  35. package/dist/types.js.map +1 -1
  36. package/dist/utils.d.ts +4 -2
  37. package/dist/utils.js +1 -0
  38. package/dist/utils.js.map +1 -1
  39. package/package.json +3 -4
  40. package/src/controller.ts +20 -7
  41. package/src/iframe/base.ts +17 -2
  42. package/src/iframe/profile.ts +9 -3
  43. package/src/types.ts +5 -2
  44. package/src/utils.ts +1 -1
@@ -1,5 +1,5 @@
1
1
 
2
- > @cartridge/controller@0.5.4 build:deps /home/runner/work/controller/controller/packages/controller
2
+ > @cartridge/controller@0.5.6 build:deps /home/runner/work/controller/controller/packages/controller
3
3
  > tsup --dts-resolve
4
4
 
5
5
  CLI Building entry: src/account.ts, src/constants.ts, src/controller.ts, src/errors.ts, src/icon.ts, src/index.ts, src/lookup.ts, src/provider.ts, src/types.ts, src/utils.ts, src/iframe/base.ts, src/iframe/index.ts, src/iframe/keychain.ts, src/iframe/profile.ts, src/session/account.ts, src/session/backend.ts, src/session/index.ts, src/session/provider.ts, src/telegram/backend.ts, src/telegram/provider.ts
@@ -10,46 +10,46 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  ESM dist/account.js 2.81 KB
13
- ESM dist/iframe/base.js 3.39 KB
13
+ ESM dist/iframe/base.js 3.64 KB
14
14
  ESM dist/session/account.js 2.25 KB
15
15
  ESM dist/telegram/backend.js 1.27 KB
16
16
  ESM dist/constants.js 247.00 B
17
- ESM dist/controller.js 32.23 KB
17
+ ESM dist/controller.js 33.08 KB
18
18
  ESM dist/errors.js 271.00 B
19
19
  ESM dist/icon.js 15.15 KB
20
- ESM dist/index.js 36.44 KB
21
20
  ESM dist/lookup.js 1.59 KB
22
21
  ESM dist/provider.js 19.16 KB
23
22
  ESM dist/types.js 437.00 B
24
- ESM dist/utils.js 2.75 KB
25
- ESM dist/iframe/index.js 4.81 KB
26
- ESM dist/iframe/keychain.js 3.86 KB
27
- ESM dist/iframe/profile.js 4.34 KB
23
+ ESM dist/utils.js 2.77 KB
24
+ ESM dist/iframe/index.js 5.16 KB
25
+ ESM dist/iframe/keychain.js 4.12 KB
26
+ ESM dist/iframe/profile.js 4.69 KB
28
27
  ESM dist/session/backend.js 1.18 KB
29
28
  ESM dist/session/index.js 24.95 KB
30
29
  ESM dist/session/provider.js 24.35 KB
31
30
  ESM dist/telegram/provider.js 23.91 KB
32
- ESM dist/account.js.map 8.81 KB
33
- ESM dist/iframe/base.js.map 6.58 KB
34
- ESM dist/session/account.js.map 11.10 KB
31
+ ESM dist/index.js 256.75 KB
32
+ ESM dist/account.js.map 8.82 KB
33
+ ESM dist/iframe/base.js.map 7.08 KB
34
+ ESM dist/session/account.js.map 11.19 KB
35
35
  ESM dist/telegram/backend.js.map 1.98 KB
36
36
  ESM dist/constants.js.map 315.00 B
37
- ESM dist/controller.js.map 52.09 KB
37
+ ESM dist/controller.js.map 53.64 KB
38
38
  ESM dist/errors.js.map 385.00 B
39
39
  ESM dist/icon.js.map 15.20 KB
40
- ESM dist/index.js.map 61.84 KB
41
40
  ESM dist/lookup.js.map 3.49 KB
42
- ESM dist/types.js.map 4.66 KB
43
41
  ESM dist/provider.js.map 22.49 KB
44
- ESM dist/utils.js.map 5.64 KB
45
- ESM dist/iframe/index.js.map 9.77 KB
46
- ESM dist/iframe/keychain.js.map 7.78 KB
47
- ESM dist/iframe/profile.js.map 8.77 KB
42
+ ESM dist/types.js.map 4.75 KB
43
+ ESM dist/utils.js.map 5.65 KB
44
+ ESM dist/iframe/index.js.map 10.47 KB
45
+ ESM dist/iframe/keychain.js.map 8.27 KB
46
+ ESM dist/iframe/profile.js.map 9.47 KB
48
47
  ESM dist/session/backend.js.map 2.88 KB
49
- ESM dist/session/index.js.map 40.10 KB
50
- ESM dist/session/provider.js.map 35.18 KB
48
+ ESM dist/session/index.js.map 40.19 KB
49
+ ESM dist/session/provider.js.map 35.19 KB
51
50
  ESM dist/telegram/provider.js.map 34.36 KB
52
- ESM ⚡️ Build success in 84ms
51
+ ESM dist/index.js.map 386.34 KB
52
+ ESM ⚡️ Build success in 115ms
53
53
  DTS Build start
54
54
  ../tsconfig/base.json(6,25): error TS6046: Argument for '--moduleResolution' option must be: 'node', 'classic', 'node16', 'nodenext'.
55
55
 
@@ -91,25 +91,28 @@
91
91
 
92
92
  ../tsconfig/base.json(6,25): error TS6046: Argument for '--moduleResolution' option must be: 'node', 'classic', 'node16', 'nodenext'.
93
93
 
94
- DTS ⚡️ Build success in 7689ms
95
- DTS dist/index.d.ts 907.00 B
96
- DTS dist/session/index.d.ts 735.00 B
97
- DTS dist/account.d.ts 1.62 KB
94
+ ../tsconfig/base.json(6,25): error TS6046: Argument for '--moduleResolution' option must be: 'node', 'classic', 'node16', 'nodenext'.
95
+
96
+ DTS ⚡️ Build success in 8658ms
97
+ DTS dist/index.d.ts 1.29 KB
98
+ DTS dist/session/index.d.ts 739.00 B
99
+ DTS dist/account.d.ts 1.63 KB
98
100
  DTS dist/constants.d.ts 215.00 B
99
101
  DTS dist/icon.d.ts 15.11 KB
100
- DTS dist/controller.d.ts 1.07 KB
102
+ DTS dist/controller.d.ts 1.11 KB
101
103
  DTS dist/lookup.d.ts 216.00 B
102
- DTS dist/utils.d.ts 610.00 B
104
+ DTS dist/utils.d.ts 725.00 B
103
105
  DTS dist/session/account.d.ts 1.83 KB
104
106
  DTS dist/session/backend.d.ts 2.29 KB
105
107
  DTS dist/errors.d.ts 100.00 B
106
- DTS dist/session/provider.d.ts 971.00 B
108
+ DTS dist/session/provider.d.ts 980.00 B
107
109
  DTS dist/telegram/backend.d.ts 1.27 KB
108
- DTS dist/telegram/provider.d.ts 831.00 B
109
- DTS dist/provider.d.ts 772.00 B
110
- DTS dist/iframe/base.d.ts 180.00 B
111
- DTS dist/iframe/keychain.d.ts 168.00 B
112
- DTS dist/iframe/profile.d.ts 194.00 B
113
- DTS dist/iframe/index.d.ts 248.00 B
114
- DTS dist/types.d.ts 602.00 B
115
- DTS dist/types-1WsOoNO2.d.ts 6.01 KB
110
+ DTS dist/telegram/provider.d.ts 840.00 B
111
+ DTS dist/provider.d.ts 775.00 B
112
+ DTS dist/iframe/base.d.ts 184.00 B
113
+ DTS dist/iframe/keychain.d.ts 172.00 B
114
+ DTS dist/iframe/profile.d.ts 198.00 B
115
+ DTS dist/iframe/index.d.ts 252.00 B
116
+ DTS dist/types.d.ts 605.00 B
117
+ DTS dist/index.d-BbTUPBeO.d.ts 2.15 KB
118
+ DTS dist/types-BReKRAuh.d.ts 6.22 KB
@@ -1,9 +1,9 @@
1
1
 
2
- > @cartridge/controller@0.5.4 build /home/runner/work/controller/controller/packages/controller
2
+ > @cartridge/controller@0.5.6 build /home/runner/work/controller/controller/packages/controller
3
3
  > pnpm build:deps
4
4
 
5
5
 
6
- > @cartridge/controller@0.5.4 build:deps /home/runner/work/controller/controller/packages/controller
6
+ > @cartridge/controller@0.5.6 build:deps /home/runner/work/controller/controller/packages/controller
7
7
  > tsup --dts-resolve
8
8
 
9
9
  CLI Building entry: src/account.ts, src/constants.ts, src/controller.ts, src/errors.ts, src/icon.ts, src/index.ts, src/lookup.ts, src/provider.ts, src/types.ts, src/utils.ts, src/iframe/base.ts, src/iframe/index.ts, src/iframe/keychain.ts, src/iframe/profile.ts, src/session/account.ts, src/session/backend.ts, src/session/index.ts, src/session/provider.ts, src/telegram/backend.ts, src/telegram/provider.ts
@@ -15,45 +15,45 @@
15
15
  ESM Build start
16
16
  ESM dist/account.js 2.81 KB
17
17
  ESM dist/constants.js 247.00 B
18
- ESM dist/controller.js 32.23 KB
18
+ ESM dist/controller.js 33.08 KB
19
19
  ESM dist/errors.js 271.00 B
20
20
  ESM dist/icon.js 15.15 KB
21
- ESM dist/index.js 36.44 KB
21
+ ESM dist/index.js 256.75 KB
22
22
  ESM dist/lookup.js 1.59 KB
23
23
  ESM dist/provider.js 19.16 KB
24
24
  ESM dist/types.js 437.00 B
25
- ESM dist/utils.js 2.75 KB
26
- ESM dist/iframe/base.js 3.39 KB
27
- ESM dist/iframe/index.js 4.81 KB
28
- ESM dist/iframe/keychain.js 3.86 KB
29
- ESM dist/iframe/profile.js 4.34 KB
25
+ ESM dist/utils.js 2.77 KB
26
+ ESM dist/iframe/base.js 3.64 KB
27
+ ESM dist/iframe/index.js 5.16 KB
28
+ ESM dist/iframe/keychain.js 4.12 KB
29
+ ESM dist/iframe/profile.js 4.69 KB
30
30
  ESM dist/session/account.js 2.25 KB
31
31
  ESM dist/session/backend.js 1.18 KB
32
32
  ESM dist/session/index.js 24.95 KB
33
33
  ESM dist/session/provider.js 24.35 KB
34
34
  ESM dist/telegram/backend.js 1.27 KB
35
35
  ESM dist/telegram/provider.js 23.91 KB
36
- ESM dist/account.js.map 8.81 KB
36
+ ESM dist/account.js.map 8.82 KB
37
37
  ESM dist/constants.js.map 315.00 B
38
- ESM dist/controller.js.map 52.09 KB
38
+ ESM dist/controller.js.map 53.64 KB
39
39
  ESM dist/errors.js.map 385.00 B
40
40
  ESM dist/icon.js.map 15.20 KB
41
- ESM dist/index.js.map 61.84 KB
41
+ ESM dist/index.js.map 386.34 KB
42
42
  ESM dist/lookup.js.map 3.49 KB
43
43
  ESM dist/provider.js.map 22.49 KB
44
- ESM dist/types.js.map 4.66 KB
45
- ESM dist/utils.js.map 5.64 KB
46
- ESM dist/iframe/base.js.map 6.58 KB
47
- ESM dist/iframe/index.js.map 9.77 KB
48
- ESM dist/iframe/keychain.js.map 7.78 KB
49
- ESM dist/iframe/profile.js.map 8.77 KB
50
- ESM dist/session/account.js.map 11.10 KB
44
+ ESM dist/types.js.map 4.75 KB
45
+ ESM dist/utils.js.map 5.65 KB
46
+ ESM dist/iframe/base.js.map 7.08 KB
47
+ ESM dist/iframe/index.js.map 10.47 KB
48
+ ESM dist/iframe/keychain.js.map 8.27 KB
49
+ ESM dist/iframe/profile.js.map 9.47 KB
50
+ ESM dist/session/account.js.map 11.19 KB
51
51
  ESM dist/session/backend.js.map 2.88 KB
52
- ESM dist/session/index.js.map 40.10 KB
53
- ESM dist/session/provider.js.map 35.18 KB
52
+ ESM dist/session/index.js.map 40.19 KB
53
+ ESM dist/session/provider.js.map 35.19 KB
54
54
  ESM dist/telegram/backend.js.map 1.98 KB
55
55
  ESM dist/telegram/provider.js.map 34.36 KB
56
- ESM ⚡️ Build success in 101ms
56
+ ESM ⚡️ Build success in 185ms
57
57
  DTS Build start
58
58
  ../tsconfig/base.json(6,25): error TS6046: Argument for '--moduleResolution' option must be: 'node', 'classic', 'node16', 'nodenext'.
59
59
 
@@ -95,25 +95,28 @@
95
95
 
96
96
  ../tsconfig/base.json(6,25): error TS6046: Argument for '--moduleResolution' option must be: 'node', 'classic', 'node16', 'nodenext'.
97
97
 
98
- DTS ⚡️ Build success in 7518ms
99
- DTS dist/index.d.ts 907.00 B
100
- DTS dist/session/index.d.ts 735.00 B
101
- DTS dist/account.d.ts 1.62 KB
98
+ ../tsconfig/base.json(6,25): error TS6046: Argument for '--moduleResolution' option must be: 'node', 'classic', 'node16', 'nodenext'.
99
+
100
+ DTS ⚡️ Build success in 8311ms
101
+ DTS dist/index.d.ts 1.29 KB
102
+ DTS dist/session/index.d.ts 739.00 B
103
+ DTS dist/account.d.ts 1.63 KB
102
104
  DTS dist/constants.d.ts 215.00 B
103
105
  DTS dist/icon.d.ts 15.11 KB
104
- DTS dist/controller.d.ts 1.07 KB
106
+ DTS dist/controller.d.ts 1.11 KB
105
107
  DTS dist/lookup.d.ts 216.00 B
106
- DTS dist/utils.d.ts 610.00 B
108
+ DTS dist/utils.d.ts 725.00 B
107
109
  DTS dist/session/account.d.ts 1.83 KB
108
110
  DTS dist/session/backend.d.ts 2.29 KB
109
111
  DTS dist/errors.d.ts 100.00 B
110
- DTS dist/session/provider.d.ts 971.00 B
112
+ DTS dist/session/provider.d.ts 980.00 B
111
113
  DTS dist/telegram/backend.d.ts 1.27 KB
112
- DTS dist/telegram/provider.d.ts 831.00 B
113
- DTS dist/provider.d.ts 772.00 B
114
- DTS dist/iframe/base.d.ts 180.00 B
115
- DTS dist/iframe/keychain.d.ts 168.00 B
116
- DTS dist/iframe/profile.d.ts 194.00 B
117
- DTS dist/iframe/index.d.ts 248.00 B
118
- DTS dist/types.d.ts 602.00 B
119
- DTS dist/types-1WsOoNO2.d.ts 6.01 KB
114
+ DTS dist/telegram/provider.d.ts 840.00 B
115
+ DTS dist/provider.d.ts 775.00 B
116
+ DTS dist/iframe/base.d.ts 184.00 B
117
+ DTS dist/iframe/keychain.d.ts 172.00 B
118
+ DTS dist/iframe/profile.d.ts 198.00 B
119
+ DTS dist/iframe/index.d.ts 252.00 B
120
+ DTS dist/types.d.ts 605.00 B
121
+ DTS dist/index.d-BbTUPBeO.d.ts 2.15 KB
122
+ DTS dist/types-BReKRAuh.d.ts 6.22 KB
package/dist/account.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { WalletAccount, AllowArray, Call, InvokeFunctionResponse, TypedData } from 'starknet';
2
2
  import { SPEC } from '@starknet-io/types-js';
3
- import { K as Keychain, j as KeychainOptions, M as Modal } from './types-1WsOoNO2.js';
3
+ import { K as Keychain, j as KeychainOptions, M as Modal } from './types-BReKRAuh.js';
4
4
  import { AsyncMethodReturns } from '@cartridge/penpal';
5
5
  import BaseProvider from './provider.js';
6
- import '@cartridge/presets';
6
+ import './index.d-BbTUPBeO.js';
7
7
 
8
8
  declare class ControllerAccount extends WalletAccount {
9
9
  address: string;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/account.ts","../src/utils.ts"],"sourcesContent":["import {\n InvokeFunctionResponse,\n TypedData,\n WalletAccount,\n Call,\n AllowArray,\n} from \"starknet\";\n\nimport { SPEC } from \"@starknet-io/types-js\";\n\nimport {\n ConnectError,\n Keychain,\n KeychainOptions,\n Modal,\n ResponseCodes,\n} from \"./types\";\nimport { AsyncMethodReturns } from \"@cartridge/penpal\";\nimport BaseProvider from \"./provider\";\nimport { toArray } from \"./utils\";\n\nclass ControllerAccount extends WalletAccount {\n address: string;\n private keychain: AsyncMethodReturns<Keychain>;\n private modal: Modal;\n private options?: KeychainOptions;\n\n constructor(\n provider: BaseProvider,\n address: string,\n keychain: AsyncMethodReturns<Keychain>,\n options: KeychainOptions,\n modal: Modal,\n ) {\n super({ nodeUrl: provider.rpc.toString() }, provider);\n\n this.address = address;\n this.keychain = keychain;\n this.options = options;\n this.modal = modal;\n }\n\n /**\n * Invoke execute function in account contract\n *\n * @param calls the invocation object or an array of them, containing:\n * - contractAddress - the address of the contract\n * - entrypoint - the entrypoint of the contract\n * - calldata - (defaults to []) the calldata\n * - signature - (defaults to []) the signature\n * @param abis (optional) the abi of the contract for better displaying\n *\n * @returns response from addTransaction\n */\n async execute(calls: AllowArray<Call>): Promise<InvokeFunctionResponse> {\n calls = toArray(calls);\n\n return new Promise(async (resolve, reject) => {\n const sessionExecute = await this.keychain.execute(\n calls,\n undefined,\n undefined,\n false,\n );\n\n // Session call succeeded\n if (sessionExecute.code === ResponseCodes.SUCCESS) {\n resolve(sessionExecute as InvokeFunctionResponse);\n return;\n }\n\n // Propagates session txn error back to caller\n if (this.options?.propagateSessionErrors) {\n reject((sessionExecute as ConnectError).error);\n return;\n }\n\n // Session call or Paymaster flow failed.\n // Session not avaialble, manual flow fallback\n this.modal.open();\n const manualExecute = await this.keychain.execute(\n calls,\n undefined,\n undefined,\n true,\n (sessionExecute as ConnectError).error,\n );\n\n // Manual call succeeded\n if (manualExecute.code === ResponseCodes.SUCCESS) {\n resolve(manualExecute as InvokeFunctionResponse);\n this.modal.close();\n return;\n }\n\n reject((manualExecute as ConnectError).error);\n return;\n });\n }\n\n /**\n * Sign an JSON object for off-chain usage with the starknet private key and return the signature\n * This adds a message prefix so it cant be interchanged with transactions\n *\n * @param json - JSON object to be signed\n * @returns the signature of the JSON object\n * @throws {Error} if the JSON object is not a valid JSON\n */\n async signMessage(typedData: TypedData): Promise<SPEC.SIGNATURE> {\n return new Promise(async (resolve, reject) => {\n const sessionSign = await this.keychain.signMessage(typedData, \"\", true);\n\n // Session sign succeeded\n if (!(\"code\" in sessionSign)) {\n resolve(sessionSign as SPEC.SIGNATURE);\n return;\n }\n\n // Session not avaialble, manual flow fallback\n this.modal.open();\n const manualSign = await this.keychain.signMessage(typedData, \"\", false);\n\n if (!(\"code\" in manualSign)) {\n resolve(manualSign as SPEC.SIGNATURE);\n } else {\n reject((manualSign as ConnectError).error);\n }\n this.modal.close();\n });\n }\n}\n\nexport default ControllerAccount;\n","import {\n addAddressPadding,\n Call,\n CallData,\n getChecksumAddress,\n hash,\n typedData,\n TypedDataRevision,\n} from \"starknet\";\nimport wasm from \"@cartridge/account-wasm/controller\";\nimport { Policies, SessionPolicies } from \"@cartridge/presets\";\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: SessionPolicies): wasm.Policy[] {\n return [\n ...Object.entries(policies.contracts ?? {}).flatMap(\n ([target, { methods }]) =>\n toArray(methods).map((m) => ({\n target,\n method: m.entrypoint,\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 };\n }),\n ];\n}\n\nexport function toArray<T>(val: T | T[]): T[] {\n return Array.isArray(val) ? val : [val];\n}\n\nfunction 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"],"mappings":";AAAA;AAAA,EAGE;AAAA,OAGK;;;ACNP;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA4GA,SAAS,QAAW,KAAmB;AAC5C,SAAO,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG;AACxC;;;ADjGA,IAAM,oBAAN,cAAgC,cAAc;AAAA,EAM5C,YACE,UACA,SACA,UACA,SACA,OACA;AACA,UAAM,EAAE,SAAS,SAAS,IAAI,SAAS,EAAE,GAAG,QAAQ;AAEpD,SAAK,UAAU;AACf,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,QAAQ;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,MAAM,QAAQ,OAA0D;AACtE,YAAQ,QAAQ,KAAK;AAErB,WAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,YAAM,iBAAiB,MAAM,KAAK,SAAS;AAAA,QACzC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAGA,UAAI,eAAe,kCAAgC;AACjD,gBAAQ,cAAwC;AAChD;AAAA,MACF;AAGA,UAAI,KAAK,SAAS,wBAAwB;AACxC,eAAQ,eAAgC,KAAK;AAC7C;AAAA,MACF;AAIA,WAAK,MAAM,KAAK;AAChB,YAAM,gBAAgB,MAAM,KAAK,SAAS;AAAA,QACxC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,eAAgC;AAAA,MACnC;AAGA,UAAI,cAAc,kCAAgC;AAChD,gBAAQ,aAAuC;AAC/C,aAAK,MAAM,MAAM;AACjB;AAAA,MACF;AAEA,aAAQ,cAA+B,KAAK;AAC5C;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,YAAYA,YAA+C;AAC/D,WAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,YAAM,cAAc,MAAM,KAAK,SAAS,YAAYA,YAAW,IAAI,IAAI;AAGvE,UAAI,EAAE,UAAU,cAAc;AAC5B,gBAAQ,WAA6B;AACrC;AAAA,MACF;AAGA,WAAK,MAAM,KAAK;AAChB,YAAM,aAAa,MAAM,KAAK,SAAS,YAAYA,YAAW,IAAI,KAAK;AAEvE,UAAI,EAAE,UAAU,aAAa;AAC3B,gBAAQ,UAA4B;AAAA,MACtC,OAAO;AACL,eAAQ,WAA4B,KAAK;AAAA,MAC3C;AACA,WAAK,MAAM,MAAM;AAAA,IACnB,CAAC;AAAA,EACH;AACF;AAEA,IAAO,kBAAQ;","names":["typedData"]}
1
+ {"version":3,"sources":["../src/account.ts","../src/utils.ts"],"sourcesContent":["import {\n InvokeFunctionResponse,\n TypedData,\n WalletAccount,\n Call,\n AllowArray,\n} from \"starknet\";\n\nimport { SPEC } from \"@starknet-io/types-js\";\n\nimport {\n ConnectError,\n Keychain,\n KeychainOptions,\n Modal,\n ResponseCodes,\n} from \"./types\";\nimport { AsyncMethodReturns } from \"@cartridge/penpal\";\nimport BaseProvider from \"./provider\";\nimport { toArray } from \"./utils\";\n\nclass ControllerAccount extends WalletAccount {\n address: string;\n private keychain: AsyncMethodReturns<Keychain>;\n private modal: Modal;\n private options?: KeychainOptions;\n\n constructor(\n provider: BaseProvider,\n address: string,\n keychain: AsyncMethodReturns<Keychain>,\n options: KeychainOptions,\n modal: Modal,\n ) {\n super({ nodeUrl: provider.rpc.toString() }, provider);\n\n this.address = address;\n this.keychain = keychain;\n this.options = options;\n this.modal = modal;\n }\n\n /**\n * Invoke execute function in account contract\n *\n * @param calls the invocation object or an array of them, containing:\n * - contractAddress - the address of the contract\n * - entrypoint - the entrypoint of the contract\n * - calldata - (defaults to []) the calldata\n * - signature - (defaults to []) the signature\n * @param abis (optional) the abi of the contract for better displaying\n *\n * @returns response from addTransaction\n */\n async execute(calls: AllowArray<Call>): Promise<InvokeFunctionResponse> {\n calls = toArray(calls);\n\n return new Promise(async (resolve, reject) => {\n const sessionExecute = await this.keychain.execute(\n calls,\n undefined,\n undefined,\n false,\n );\n\n // Session call succeeded\n if (sessionExecute.code === ResponseCodes.SUCCESS) {\n resolve(sessionExecute as InvokeFunctionResponse);\n return;\n }\n\n // Propagates session txn error back to caller\n if (this.options?.propagateSessionErrors) {\n reject((sessionExecute as ConnectError).error);\n return;\n }\n\n // Session call or Paymaster flow failed.\n // Session not avaialble, manual flow fallback\n this.modal.open();\n const manualExecute = await this.keychain.execute(\n calls,\n undefined,\n undefined,\n true,\n (sessionExecute as ConnectError).error,\n );\n\n // Manual call succeeded\n if (manualExecute.code === ResponseCodes.SUCCESS) {\n resolve(manualExecute as InvokeFunctionResponse);\n this.modal.close();\n return;\n }\n\n reject((manualExecute as ConnectError).error);\n return;\n });\n }\n\n /**\n * Sign an JSON object for off-chain usage with the starknet private key and return the signature\n * This adds a message prefix so it cant be interchanged with transactions\n *\n * @param json - JSON object to be signed\n * @returns the signature of the JSON object\n * @throws {Error} if the JSON object is not a valid JSON\n */\n async signMessage(typedData: TypedData): Promise<SPEC.SIGNATURE> {\n return new Promise(async (resolve, reject) => {\n const sessionSign = await this.keychain.signMessage(typedData, \"\", true);\n\n // Session sign succeeded\n if (!(\"code\" in sessionSign)) {\n resolve(sessionSign as SPEC.SIGNATURE);\n return;\n }\n\n // Session not avaialble, manual flow fallback\n this.modal.open();\n const manualSign = await this.keychain.signMessage(typedData, \"\", false);\n\n if (!(\"code\" in manualSign)) {\n resolve(manualSign as SPEC.SIGNATURE);\n } else {\n reject((manualSign as ConnectError).error);\n }\n this.modal.close();\n });\n }\n}\n\nexport default ControllerAccount;\n","import {\n addAddressPadding,\n Call,\n CallData,\n getChecksumAddress,\n hash,\n typedData,\n TypedDataRevision,\n} from \"starknet\";\nimport wasm from \"@cartridge/account-wasm/controller\";\nimport { Policies, SessionPolicies } from \"@cartridge/presets\";\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: SessionPolicies): wasm.Policy[] {\n return [\n ...Object.entries(policies.contracts ?? {}).flatMap(\n ([target, { methods }]) =>\n toArray(methods).map((m) => ({\n target,\n method: m.entrypoint,\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 };\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"],"mappings":";AAAA;AAAA,EAGE;AAAA,OAGK;;;ACNP;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA4GA,SAAS,QAAW,KAAmB;AAC5C,SAAO,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG;AACxC;;;ADjGA,IAAM,oBAAN,cAAgC,cAAc;AAAA,EAM5C,YACE,UACA,SACA,UACA,SACA,OACA;AACA,UAAM,EAAE,SAAS,SAAS,IAAI,SAAS,EAAE,GAAG,QAAQ;AAEpD,SAAK,UAAU;AACf,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,QAAQ;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,MAAM,QAAQ,OAA0D;AACtE,YAAQ,QAAQ,KAAK;AAErB,WAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,YAAM,iBAAiB,MAAM,KAAK,SAAS;AAAA,QACzC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAGA,UAAI,eAAe,kCAAgC;AACjD,gBAAQ,cAAwC;AAChD;AAAA,MACF;AAGA,UAAI,KAAK,SAAS,wBAAwB;AACxC,eAAQ,eAAgC,KAAK;AAC7C;AAAA,MACF;AAIA,WAAK,MAAM,KAAK;AAChB,YAAM,gBAAgB,MAAM,KAAK,SAAS;AAAA,QACxC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,eAAgC;AAAA,MACnC;AAGA,UAAI,cAAc,kCAAgC;AAChD,gBAAQ,aAAuC;AAC/C,aAAK,MAAM,MAAM;AACjB;AAAA,MACF;AAEA,aAAQ,cAA+B,KAAK;AAC5C;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,YAAYA,YAA+C;AAC/D,WAAO,IAAI,QAAQ,OAAO,SAAS,WAAW;AAC5C,YAAM,cAAc,MAAM,KAAK,SAAS,YAAYA,YAAW,IAAI,IAAI;AAGvE,UAAI,EAAE,UAAU,cAAc;AAC5B,gBAAQ,WAA6B;AACrC;AAAA,MACF;AAGA,WAAK,MAAM,KAAK;AAChB,YAAM,aAAa,MAAM,KAAK,SAAS,YAAYA,YAAW,IAAI,KAAK;AAEvE,UAAI,EAAE,UAAU,aAAa;AAC3B,gBAAQ,UAA4B;AAAA,MACtC,OAAO;AACL,eAAQ,WAA4B,KAAK;AAAA,MAC3C;AACA,WAAK,MAAM,MAAM;AAAA,IACnB,CAAC;AAAA,EACH;AACF;AAEA,IAAO,kBAAQ;","names":["typedData"]}
@@ -1,7 +1,7 @@
1
- import { g as ControllerOptions, l as ProfileContextTypeVariant } from './types-1WsOoNO2.js';
1
+ import { g as ControllerOptions, l as ProfileContextTypeVariant } from './types-BReKRAuh.js';
2
2
  import BaseProvider from './provider.js';
3
3
  import { WalletAccount } from 'starknet';
4
- import { Policy } from '@cartridge/presets';
4
+ import { i as Policy } from './index.d-BbTUPBeO.js';
5
5
  import '@starknet-io/types-js';
6
6
  import '@cartridge/penpal';
7
7
 
@@ -20,7 +20,7 @@ declare class ControllerProvider extends BaseProvider {
20
20
  username(): Promise<string> | undefined;
21
21
  fetchControllers(contractAddresses: string[]): Promise<Record<string, string>>;
22
22
  openPurchaseCredits(): void;
23
- private openExecute;
23
+ openExecute(calls: any): Promise<boolean | undefined>;
24
24
  delegateAccount(): Promise<string | null>;
25
25
  private waitForKeychain;
26
26
  }
@@ -105,6 +105,7 @@ var IFrame = class {
105
105
  constructor({
106
106
  id,
107
107
  url,
108
+ preset,
108
109
  theme,
109
110
  colorMode,
110
111
  onClose,
@@ -115,7 +116,10 @@ var IFrame = class {
115
116
  return;
116
117
  }
117
118
  if (theme) {
118
- url.searchParams.set("theme", encodeURIComponent(theme));
119
+ url.searchParams.set("theme", theme);
120
+ }
121
+ if (preset) {
122
+ url.searchParams.set("preset", preset);
119
123
  }
120
124
  if (colorMode) {
121
125
  url.searchParams.set("colorMode", colorMode);
@@ -191,6 +195,14 @@ var IFrame = class {
191
195
  this.container.style.visibility = "hidden";
192
196
  this.container.style.opacity = "0";
193
197
  }
198
+ sendBackward() {
199
+ if (!this.container) return;
200
+ this.container.style.zIndex = "9999";
201
+ }
202
+ sendForward() {
203
+ if (!this.container) return;
204
+ this.container.style.zIndex = "10000";
205
+ }
194
206
  resize() {
195
207
  if (!this.iframe) return;
196
208
  this.iframe.style.userSelect = "none";
@@ -233,20 +245,24 @@ var ProfileIFrame = class extends IFrame {
233
245
  constructor({
234
246
  profileUrl,
235
247
  rpcUrl,
236
- namespace,
237
- slot,
248
+ version,
238
249
  username,
250
+ slot,
251
+ namespace,
239
252
  tokens,
240
253
  ...iframeOptions
241
254
  }) {
242
255
  const _profileUrl = (profileUrl || PROFILE_URL).replace(/\/$/, "");
243
- const _url = new URL(
256
+ let _url = new URL(
244
257
  slot ? namespace ? `${_profileUrl}/account/${username}/slot/${slot}?ps=${encodeURIComponent(
245
258
  slot
246
259
  )}&ns=${encodeURIComponent(namespace)}` : `${_profileUrl}/account/${username}/slot/${slot}?ps=${encodeURIComponent(
247
260
  slot
248
261
  )}` : `${_profileUrl}/account/${username}`
249
262
  );
263
+ if (version) {
264
+ _url.searchParams.set("v", encodeURIComponent(version));
265
+ }
250
266
  _url.searchParams.set("rpcUrl", encodeURIComponent(rpcUrl));
251
267
  if (tokens?.erc20) {
252
268
  _url.searchParams.set(
@@ -454,12 +470,13 @@ var ControllerProvider = class extends BaseProvider {
454
470
  this.profile = profile;
455
471
  },
456
472
  methods: {
457
- openSettings: this.openSettings.bind(this),
458
- openPurchaseCredits: this.openPurchaseCredits.bind(this),
459
- openExecute: this.openExecute.bind(this)
473
+ openSettings: () => this.openSettings.bind(this),
474
+ openPurchaseCredits: () => this.openPurchaseCredits.bind(this),
475
+ openExecute: () => this.openExecute.bind(this)
460
476
  },
461
477
  rpcUrl: this.rpc.toString(),
462
- username
478
+ username,
479
+ version: this.version
463
480
  });
464
481
  }
465
482
  return this.account;
@@ -533,10 +550,15 @@ var ControllerProvider = class extends BaseProvider {
533
550
  console.error(new NotReadyToConnect().message);
534
551
  return null;
535
552
  }
536
- this.iframes.profile?.close();
553
+ if (this.iframes.profile?.sendBackward) {
554
+ this.iframes.profile?.sendBackward();
555
+ } else {
556
+ this.iframes.profile?.close();
557
+ }
537
558
  this.iframes.keychain.open();
538
559
  const res = await this.keychain.openSettings();
539
560
  this.iframes.keychain.close();
561
+ this.iframes.profile?.sendForward?.();
540
562
  if (res && res.code === "NOT_CONNECTED" /* NOT_CONNECTED */) {
541
563
  return false;
542
564
  }
@@ -575,7 +597,7 @@ var ControllerProvider = class extends BaseProvider {
575
597
  this.iframes.keychain.open();
576
598
  this.keychain.openPurchaseCredits();
577
599
  }
578
- openExecute(calls) {
600
+ async openExecute(calls) {
579
601
  if (!this.keychain || !this.iframes.keychain) {
580
602
  console.error(new NotReadyToConnect().message);
581
603
  return;
@@ -584,9 +606,16 @@ var ControllerProvider = class extends BaseProvider {
584
606
  console.error("Profile is not ready");
585
607
  return;
586
608
  }
587
- this.iframes.profile.close();
609
+ if (this.iframes.profile?.sendBackward) {
610
+ this.iframes.profile?.sendBackward();
611
+ } else {
612
+ this.iframes.profile?.close();
613
+ }
588
614
  this.iframes.keychain.open();
589
- this.keychain.execute(calls);
615
+ const res = await this.keychain.execute(calls, void 0, void 0, true);
616
+ this.iframes.keychain.close();
617
+ this.iframes.profile?.sendForward?.();
618
+ return !(res && res.code === "NOT_CONNECTED" /* NOT_CONNECTED */);
590
619
  }
591
620
  async delegateAccount() {
592
621
  if (!this.keychain) {