@cartridge/controller 0.5.6 → 0.5.8

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 (43) hide show
  1. package/.turbo/turbo-build$colon$deps.log +31 -31
  2. package/.turbo/turbo-build.log +31 -31
  3. package/dist/account.d.ts +2 -2
  4. package/dist/account.js +2 -2
  5. package/dist/account.js.map +1 -1
  6. package/dist/controller.d.ts +7 -2
  7. package/dist/controller.js +140 -29
  8. package/dist/controller.js.map +1 -1
  9. package/dist/iframe/base.d.ts +1 -1
  10. package/dist/iframe/index.d.ts +1 -1
  11. package/dist/iframe/keychain.d.ts +1 -1
  12. package/dist/iframe/profile.d.ts +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +174 -47
  15. package/dist/index.js.map +1 -1
  16. package/dist/provider.d.ts +5 -6
  17. package/dist/provider.js +74 -19
  18. package/dist/provider.js.map +1 -1
  19. package/dist/session/account.d.ts +1 -1
  20. package/dist/session/account.js.map +1 -1
  21. package/dist/session/index.d.ts +1 -1
  22. package/dist/session/index.js +84 -22
  23. package/dist/session/index.js.map +1 -1
  24. package/dist/session/provider.d.ts +4 -3
  25. package/dist/session/provider.js +84 -22
  26. package/dist/session/provider.js.map +1 -1
  27. package/dist/telegram/backend.d.ts +1 -1
  28. package/dist/telegram/backend.js.map +1 -1
  29. package/dist/telegram/provider.d.ts +4 -3
  30. package/dist/telegram/provider.js +84 -24
  31. package/dist/telegram/provider.js.map +1 -1
  32. package/dist/{types-BReKRAuh.d.ts → types-CVnDQVqD.d.ts} +10 -11
  33. package/dist/types.d.ts +1 -1
  34. package/dist/types.js.map +1 -1
  35. package/package.json +3 -3
  36. package/src/account.ts +2 -1
  37. package/src/controller.ts +84 -9
  38. package/src/provider.ts +39 -24
  39. package/src/session/provider.ts +14 -4
  40. package/src/telegram/backend.ts +1 -1
  41. package/src/telegram/provider.ts +14 -5
  42. package/src/types.ts +11 -12
  43. package/tsconfig.json +2 -3
@@ -5,6 +5,7 @@ import { KEYCHAIN_URL } from "../constants";
5
5
  import BaseProvider from "../provider";
6
6
  import { toWasmPolicies } from "../utils";
7
7
  import { SessionPolicies } from "@cartridge/presets";
8
+ import { AddStarknetChainParameters } from "@starknet-io/types-js";
8
9
 
9
10
  interface SessionRegistration {
10
11
  username: string;
@@ -26,14 +27,15 @@ export default class SessionProvider extends BaseProvider {
26
27
  public name = "Controller Session";
27
28
 
28
29
  protected _chainId: string;
29
-
30
+ protected _rpcUrl: string;
30
31
  protected _username?: string;
31
32
  protected _redirectUrl: string;
32
33
  protected _policies: SessionPolicies;
33
34
 
34
35
  constructor({ rpc, chainId, policies, redirectUrl }: SessionOptions) {
35
- super({ rpc });
36
+ super();
36
37
 
38
+ this._rpcUrl = rpc;
37
39
  this._chainId = chainId;
38
40
  this._redirectUrl = redirectUrl;
39
41
  this._policies = policies;
@@ -76,7 +78,7 @@ export default class SessionProvider extends BaseProvider {
76
78
  this._redirectUrl
77
79
  }&redirect_query_name=startapp&policies=${JSON.stringify(
78
80
  this._policies,
79
- )}&rpc_url=${this.rpc}`;
81
+ )}&rpc_url=${this._rpcUrl}`;
80
82
 
81
83
  localStorage.setItem("lastUsedConnector", this.id);
82
84
  window.open(url, "_blank");
@@ -84,6 +86,14 @@ export default class SessionProvider extends BaseProvider {
84
86
  return;
85
87
  }
86
88
 
89
+ switchStarknetChain(_chainId: string): Promise<boolean> {
90
+ throw new Error("switchStarknetChain not implemented");
91
+ }
92
+
93
+ addStarknetChain(_chain: AddStarknetChainParameters): Promise<boolean> {
94
+ throw new Error("addStarknetChain not implemented");
95
+ }
96
+
87
97
  disconnect(): Promise<void> {
88
98
  localStorage.removeItem("sessionSigner");
89
99
  localStorage.removeItem("session");
@@ -127,7 +137,7 @@ export default class SessionProvider extends BaseProvider {
127
137
 
128
138
  this._username = sessionRegistration.username;
129
139
  this.account = new SessionAccount(this, {
130
- rpcUrl: this.rpc.toString(),
140
+ rpcUrl: this._rpcUrl,
131
141
  privateKey: signer.privKey,
132
142
  address: sessionRegistration.address,
133
143
  ownerGuid: sessionRegistration.ownerGuid,
@@ -1,5 +1,5 @@
1
1
  import { cloudStorage, openLink } from "@telegram-apps/sdk";
2
- import { UnifiedBackend } from "src/session/backend";
2
+ import { UnifiedBackend } from "../session/backend";
3
3
 
4
4
  /**
5
5
  * Implements the UnifiedBackend interface for Telegram storage operations.
@@ -11,6 +11,7 @@ import SessionAccount from "../session/account";
11
11
  import BaseProvider from "../provider";
12
12
  import { toWasmPolicies } from "../utils";
13
13
  import { SessionPolicies } from "@cartridge/presets";
14
+ import { AddStarknetChainParameters } from "@starknet-io/types-js";
14
15
 
15
16
  interface SessionRegistration {
16
17
  username: string;
@@ -25,6 +26,7 @@ export default class TelegramProvider extends BaseProvider {
25
26
  protected _chainId: string;
26
27
  protected _username?: string;
27
28
  protected _policies: SessionPolicies;
29
+ private _rpcUrl: string;
28
30
 
29
31
  constructor({
30
32
  rpc,
@@ -37,10 +39,9 @@ export default class TelegramProvider extends BaseProvider {
37
39
  policies: SessionPolicies;
38
40
  tmaUrl: string;
39
41
  }) {
40
- super({
41
- rpc,
42
- });
42
+ super();
43
43
 
44
+ this._rpcUrl = rpc;
44
45
  this._tmaUrl = tmaUrl;
45
46
  this._chainId = chainId;
46
47
  this._policies = policies;
@@ -77,7 +78,7 @@ export default class TelegramProvider extends BaseProvider {
77
78
  this._tmaUrl
78
79
  }&redirect_query_name=startapp&policies=${JSON.stringify(
79
80
  this._policies,
80
- )}&rpc_url=${this.rpc}`;
81
+ )}&rpc_url=${this._rpcUrl}`;
81
82
 
82
83
  localStorage.setItem("lastUsedConnector", this.id);
83
84
  openLink(url);
@@ -86,6 +87,14 @@ export default class TelegramProvider extends BaseProvider {
86
87
  return;
87
88
  }
88
89
 
90
+ switchStarknetChain(_chainId: string): Promise<boolean> {
91
+ throw new Error("switchStarknetChain not implemented");
92
+ }
93
+
94
+ addStarknetChain(_chain: AddStarknetChainParameters): Promise<boolean> {
95
+ throw new Error("addStarknetChain not implemented");
96
+ }
97
+
89
98
  disconnect(): Promise<void> {
90
99
  cloudStorage.deleteItem("sessionSigner");
91
100
  cloudStorage.deleteItem("session");
@@ -118,7 +127,7 @@ export default class TelegramProvider extends BaseProvider {
118
127
 
119
128
  this._username = sessionRegistration.username;
120
129
  this.account = new SessionAccount(this, {
121
- rpcUrl: this.rpc.toString(),
130
+ rpcUrl: this._rpcUrl,
122
131
  privateKey: signer.privKey,
123
132
  address: sessionRegistration.address,
124
133
  ownerGuid: sessionRegistration.ownerGuid,
package/src/types.ts CHANGED
@@ -7,16 +7,12 @@ import {
7
7
  } from "starknet";
8
8
  import {
9
9
  AddInvokeTransactionResult,
10
+ ChainId,
10
11
  Signature,
11
12
  TypedData,
12
13
  } from "@starknet-io/types-js";
13
14
  import { KeychainIFrame, ProfileIFrame } from "./iframe";
14
- import {
15
- ColorMode,
16
- Policies,
17
- Policy,
18
- SessionPolicies,
19
- } from "@cartridge/presets";
15
+ import { ColorMode, Policy, SessionPolicies } from "@cartridge/presets";
20
16
 
21
17
  export type Session = {
22
18
  chainId: constants.StarknetChainId;
@@ -100,7 +96,7 @@ export type ControllerAccounts = Record<ContractAddress, CartridgeID>;
100
96
  export interface Keychain {
101
97
  probe(rpcUrl: string): Promise<ProbeReply | ConnectError>;
102
98
  connect(
103
- policies: Policies,
99
+ policies: SessionPolicies,
104
100
  rpcUrl: string,
105
101
  ): Promise<ConnectReply | ConnectError>;
106
102
  disconnect(): void;
@@ -134,6 +130,7 @@ export interface Keychain {
134
130
  openPurchaseCredits(): void;
135
131
  openExecute(calls: Call[]): Promise<void>;
136
132
  }
133
+
137
134
  export interface Profile {
138
135
  navigate(path: string): void;
139
136
  }
@@ -161,13 +158,17 @@ export type IFrameOptions = {
161
158
  colorMode?: ColorMode;
162
159
  };
163
160
 
161
+ export type Chain = {
162
+ rpcUrl: string;
163
+ };
164
+
164
165
  export type ProviderOptions = {
165
- /** The URL of the RPC */
166
- rpc: string;
166
+ defaultChainId: ChainId;
167
+ chains: Chain[];
167
168
  };
168
169
 
169
170
  export type KeychainOptions = IFrameOptions & {
170
- policies?: Policies;
171
+ policies?: SessionPolicies;
171
172
  /** The URL of keychain */
172
173
  url?: string;
173
174
  /** The origin of keychain */
@@ -193,8 +194,6 @@ export type ProfileContextTypeVariant =
193
194
  | "achievements"
194
195
  | "activity";
195
196
 
196
- export type Prefund = { address: string; min: string };
197
-
198
197
  export type Tokens = {
199
198
  erc20?: string[];
200
199
  };
package/tsconfig.json CHANGED
@@ -2,12 +2,11 @@
2
2
  "$schema": "https://json.schemastore.org/tsconfig",
3
3
  "extends": "@cartridge/tsconfig/base.json",
4
4
  "compilerOptions": {
5
- "baseUrl": ".",
6
- "rootDir": "./src",
5
+ "rootDir": ".",
7
6
  "outDir": "./dist",
8
7
  "composite": false,
9
8
  "incremental": false,
10
9
  "moduleResolution": "node"
11
10
  },
12
- "include": ["src/**/*"]
11
+ "include": ["src/**/*", "package.json"]
13
12
  }