@cartridge/controller 0.6.0 → 0.7.1

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 (100) hide show
  1. package/.turbo/turbo-build$colon$deps.log +52 -76
  2. package/.turbo/turbo-build.log +53 -77
  3. package/dist/controller.cjs +860 -0
  4. package/dist/controller.cjs.map +1 -0
  5. package/dist/controller.d.cts +33 -0
  6. package/dist/controller.d.ts +4 -4
  7. package/dist/controller.js +84 -68
  8. package/dist/controller.js.map +1 -1
  9. package/dist/index.cjs +2200 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +17 -0
  12. package/dist/index.d.ts +12 -7
  13. package/dist/index.js +161 -7601
  14. package/dist/index.js.map +1 -1
  15. package/dist/lookup.cjs +59 -0
  16. package/dist/lookup.cjs.map +1 -0
  17. package/dist/lookup.d.cts +4 -0
  18. package/dist/lookup.js +7 -7
  19. package/dist/lookup.js.map +1 -1
  20. package/dist/{provider.js → node/index.cjs} +499 -25
  21. package/dist/node/index.cjs.map +1 -0
  22. package/dist/node/index.d.cts +56 -0
  23. package/dist/node/index.d.ts +56 -0
  24. package/dist/{telegram/provider.js → node/index.js} +354 -135
  25. package/dist/node/index.js.map +1 -0
  26. package/dist/{policies.d.ts → policies-DD1aPjQ4.d.cts} +6 -4
  27. package/dist/policies-DD1aPjQ4.d.ts +21 -0
  28. package/dist/{types-CVnDQVqD.d.ts → provider-ap1C1ypF.d.cts} +27 -10
  29. package/dist/provider-ap1C1ypF.d.ts +201 -0
  30. package/dist/session/{provider.js → index.cjs} +82 -73
  31. package/dist/session/index.cjs.map +1 -0
  32. package/dist/session/{provider.d.ts → index.d.cts} +6 -3
  33. package/dist/session/index.d.ts +37 -8
  34. package/dist/session/index.js +47 -64
  35. package/dist/session/index.js.map +1 -1
  36. package/package.json +35 -16
  37. package/src/controller.ts +43 -15
  38. package/src/iframe/base.ts +1 -11
  39. package/src/node/account.ts +72 -0
  40. package/src/node/backend.ts +159 -0
  41. package/src/node/index.ts +4 -0
  42. package/src/node/provider.ts +178 -0
  43. package/src/node/server.ts +89 -0
  44. package/src/session/account.ts +1 -1
  45. package/src/session/provider.ts +0 -16
  46. package/src/types.ts +3 -6
  47. package/tsconfig.json +2 -1
  48. package/dist/__tests__/parseChainId.test.d.ts +0 -2
  49. package/dist/__tests__/parseChainId.test.js +0 -89
  50. package/dist/__tests__/parseChainId.test.js.map +0 -1
  51. package/dist/account.d.ts +0 -38
  52. package/dist/account.js +0 -110
  53. package/dist/account.js.map +0 -1
  54. package/dist/constants.d.ts +0 -5
  55. package/dist/constants.js +0 -10
  56. package/dist/constants.js.map +0 -1
  57. package/dist/errors.d.ts +0 -5
  58. package/dist/errors.js +0 -11
  59. package/dist/errors.js.map +0 -1
  60. package/dist/icon.d.ts +0 -3
  61. package/dist/icon.js +0 -6
  62. package/dist/icon.js.map +0 -1
  63. package/dist/iframe/base.d.ts +0 -5
  64. package/dist/iframe/base.js +0 -126
  65. package/dist/iframe/base.js.map +0 -1
  66. package/dist/iframe/index.d.ts +0 -5
  67. package/dist/iframe/index.js +0 -188
  68. package/dist/iframe/index.js.map +0 -1
  69. package/dist/iframe/keychain.d.ts +0 -5
  70. package/dist/iframe/keychain.js +0 -147
  71. package/dist/iframe/keychain.js.map +0 -1
  72. package/dist/iframe/profile.d.ts +0 -5
  73. package/dist/iframe/profile.js +0 -167
  74. package/dist/iframe/profile.js.map +0 -1
  75. package/dist/index.d-BbTUPBeO.d.ts +0 -68
  76. package/dist/mutex.d.ts +0 -14
  77. package/dist/mutex.js +0 -22
  78. package/dist/mutex.js.map +0 -1
  79. package/dist/policies.js +0 -26
  80. package/dist/policies.js.map +0 -1
  81. package/dist/provider.d.ts +0 -24
  82. package/dist/provider.js.map +0 -1
  83. package/dist/session/account.d.ts +0 -37
  84. package/dist/session/account.js +0 -94
  85. package/dist/session/account.js.map +0 -1
  86. package/dist/session/backend.d.ts +0 -60
  87. package/dist/session/backend.js +0 -39
  88. package/dist/session/backend.js.map +0 -1
  89. package/dist/session/provider.js.map +0 -1
  90. package/dist/telegram/backend.d.ts +0 -33
  91. package/dist/telegram/backend.js +0 -40
  92. package/dist/telegram/backend.js.map +0 -1
  93. package/dist/telegram/provider.d.ts +0 -27
  94. package/dist/telegram/provider.js.map +0 -1
  95. package/dist/types.d.ts +0 -5
  96. package/dist/types.js +0 -13
  97. package/dist/types.js.map +0 -1
  98. package/dist/utils.d.ts +0 -19
  99. package/dist/utils.js +0 -141
  100. package/dist/utils.js.map +0 -1
@@ -1,30 +1,11 @@
1
- // src/telegram/provider.ts
2
- import {
3
- cloudStorage,
4
- miniApp,
5
- openLink,
6
- retrieveLaunchParams
7
- } from "@telegram-apps/sdk";
8
- import { ec, stark } from "starknet";
1
+ import { stark, ec, typedData, TypedDataRevision, hash, WalletAccount, addAddressPadding, CallData } from 'starknet';
2
+ import { CartridgeSessionAccount } from '@cartridge/account-wasm/session';
3
+ import { Permission } from '@starknet-io/types-js';
4
+ import * as fs from 'fs/promises';
5
+ import * as path from 'path';
6
+ import * as http from 'http';
9
7
 
10
- // src/constants.ts
11
- var KEYCHAIN_URL = "https://x.cartridge.gg";
12
-
13
- // src/session/account.ts
14
- import { CartridgeSessionAccount } from "@cartridge/account-wasm/session";
15
- import { WalletAccount } from "starknet";
16
-
17
- // src/utils.ts
18
- import {
19
- addAddressPadding,
20
- CallData,
21
- constants,
22
- getChecksumAddress,
23
- hash,
24
- shortString,
25
- typedData,
26
- TypedDataRevision
27
- } from "starknet";
8
+ // src/node/provider.ts
28
9
  function normalizeCalls(calls) {
29
10
  return toArray(calls).map((call) => {
30
11
  return {
@@ -66,7 +47,25 @@ function toArray(val) {
66
47
  return Array.isArray(val) ? val : [val];
67
48
  }
68
49
 
69
- // src/session/account.ts
50
+ // src/errors.ts
51
+ var NotReadyToConnect = class _NotReadyToConnect extends Error {
52
+ constructor() {
53
+ super("Not ready to connect");
54
+ Object.setPrototypeOf(this, _NotReadyToConnect.prototype);
55
+ }
56
+ };
57
+
58
+ // src/types.ts
59
+ var ResponseCodes = /* @__PURE__ */ ((ResponseCodes2) => {
60
+ ResponseCodes2["SUCCESS"] = "SUCCESS";
61
+ ResponseCodes2["NOT_CONNECTED"] = "NOT_CONNECTED";
62
+ ResponseCodes2["ERROR"] = "ERROR";
63
+ ResponseCodes2["CANCELED"] = "CANCELED";
64
+ ResponseCodes2["USER_INTERACTION_REQUIRED"] = "USER_INTERACTION_REQUIRED";
65
+ return ResponseCodes2;
66
+ })(ResponseCodes || {});
67
+
68
+ // src/node/account.ts
70
69
  var SessionAccount = class extends WalletAccount {
71
70
  controller;
72
71
  constructor(provider, {
@@ -80,7 +79,7 @@ var SessionAccount = class extends WalletAccount {
80
79
  }) {
81
80
  super({ nodeUrl: rpcUrl }, provider);
82
81
  this.address = address;
83
- this.controller = CartridgeSessionAccount.new_as_registered(
82
+ this.controller = CartridgeSessionAccount.newAsRegistered(
84
83
  rpcUrl,
85
84
  privateKey,
86
85
  address,
@@ -100,30 +99,34 @@ var SessionAccount = class extends WalletAccount {
100
99
  * - entrypoint - the entrypoint of the contract
101
100
  * - calldata - (defaults to []) the calldata
102
101
  * - signature - (defaults to []) the signature
103
- * @param abis (optional) the abi of the contract for better displaying
104
102
  *
105
103
  * @returns response from addTransaction
106
104
  */
107
105
  async execute(calls) {
108
- return this.controller.execute(normalizeCalls(calls));
106
+ try {
107
+ const res = await this.controller.executeFromOutside(
108
+ normalizeCalls(calls)
109
+ );
110
+ return res;
111
+ } catch (e) {
112
+ return this.controller.execute(normalizeCalls(calls));
113
+ }
109
114
  }
110
115
  };
111
116
 
112
- // src/provider.ts
113
- import {
114
- Permission
115
- } from "@starknet-io/types-js";
117
+ // src/constants.ts
118
+ var KEYCHAIN_URL = "https://x.cartridge.gg";
116
119
 
117
120
  // package.json
118
121
  var package_default = {
119
122
  name: "@cartridge/controller",
120
- version: "0.6.0",
123
+ version: "0.7.1",
121
124
  description: "Cartridge Controller",
122
125
  module: "dist/index.js",
123
126
  types: "dist/index.d.ts",
124
127
  type: "module",
125
128
  scripts: {
126
- "build:deps": "tsup --dts-resolve",
129
+ "build:deps": "tsup",
127
130
  build: "pnpm build:deps",
128
131
  format: 'prettier --write "src/**/*.ts"',
129
132
  "format:check": 'prettier --check "src/**/*.ts"',
@@ -133,52 +136,71 @@ var package_default = {
133
136
  exports: {
134
137
  ".": {
135
138
  types: "./dist/index.d.ts",
136
- default: "./dist/index.js"
139
+ import: "./dist/index.js",
140
+ require: "./dist/index.cjs"
137
141
  },
138
142
  "./session": {
139
143
  types: "./dist/session/index.d.ts",
140
- default: "./dist/session/index.js"
144
+ import: "./dist/session/index.js",
145
+ require: "./dist/session/index.cjs"
146
+ },
147
+ "./session/node": {
148
+ types: "./dist/node/index.d.ts",
149
+ import: "./dist/node/index.js",
150
+ require: "./dist/node/index.cjs"
141
151
  },
142
152
  "./provider": {
143
153
  types: "./dist/provider/index.d.ts",
144
- default: "./dist/provider/index.js"
154
+ import: "./dist/provider/index.js"
145
155
  },
146
156
  "./types": {
147
157
  types: "./dist/types/index.d.ts",
148
- default: "./dist/types/index.js"
158
+ import: "./dist/types/index.js"
149
159
  }
150
160
  },
151
161
  tsup: {
152
162
  entry: [
153
- "src/**"
163
+ "src/index.ts",
164
+ "src/controller.ts",
165
+ "src/lookup.ts",
166
+ "src/session/index.ts",
167
+ "src/node/index.ts"
154
168
  ],
155
169
  format: [
156
- "esm"
170
+ "esm",
171
+ "cjs"
157
172
  ],
158
173
  splitting: false,
159
174
  sourcemap: true,
160
- clean: true
175
+ clean: true,
176
+ dts: true,
177
+ treeshake: {
178
+ preset: "recommended"
179
+ },
180
+ exports: "named"
161
181
  },
162
182
  peerDependencies: {
163
- starknet: "^6.21.0"
183
+ starknet: "catalog:",
184
+ open: "^10.1.0"
164
185
  },
165
186
  dependencies: {
166
187
  "@cartridge/account-wasm": "workspace:*",
167
- "@cartridge/penpal": "^6.2.3",
168
- "@starknet-io/types-js": "^0.7.7",
188
+ "@cartridge/penpal": "catalog:",
189
+ "@starknet-io/types-js": "catalog:",
169
190
  "@telegram-apps/sdk": "^2.4.0",
170
- base64url: "^3.0.1",
191
+ base64url: "catalog:",
171
192
  "cbor-x": "^1.5.0",
172
- "fast-deep-equal": "^3.1.3",
173
- "query-string": "^7.1.1"
193
+ "fast-deep-equal": "catalog:"
174
194
  },
175
195
  devDependencies: {
176
196
  "@cartridge/tsconfig": "workspace:*",
177
197
  "@types/jest": "^29.5.14",
178
- "@types/node": "^20.6.0",
198
+ "@types/node": "catalog:",
179
199
  jest: "^29.7.0",
200
+ prettier: "catalog:",
180
201
  "ts-jest": "^29.2.5",
181
- typescript: "^5.4.5"
202
+ tsup: "catalog:",
203
+ typescript: "catalog:"
182
204
  }
183
205
  };
184
206
 
@@ -357,77 +379,311 @@ var BaseProvider = class {
357
379
  });
358
380
  }
359
381
  };
382
+ var CallbackServer = class {
383
+ server;
384
+ resolveCallback;
385
+ rejectCallback;
386
+ timeoutId;
387
+ constructor() {
388
+ this.server = http.createServer(this.handleRequest.bind(this));
389
+ this.server.on("error", (error) => {
390
+ console.error("Server error:", error);
391
+ if (this.rejectCallback) {
392
+ this.rejectCallback(error);
393
+ }
394
+ });
395
+ }
396
+ cleanup() {
397
+ if (this.timeoutId) {
398
+ clearTimeout(this.timeoutId);
399
+ }
400
+ this.server.close();
401
+ }
402
+ handleRequest(req, res) {
403
+ if (!req.url?.startsWith("/callback")) {
404
+ res.writeHead(404);
405
+ res.end();
406
+ return;
407
+ }
408
+ const params = new URLSearchParams(req.url.split("?")[1]);
409
+ const session = params.get("startapp");
410
+ if (!session) {
411
+ console.warn("Received callback without session data");
412
+ res.writeHead(400);
413
+ res.end("Missing session data");
414
+ return;
415
+ }
416
+ if (this.resolveCallback) {
417
+ this.resolveCallback(session);
418
+ }
419
+ res.writeHead(200, { "Content-Type": "text/html" });
420
+ res.end(
421
+ "<html><body><script>window.close();</script>Session registered successfully. You can close this window.</body></html>"
422
+ );
423
+ this.cleanup();
424
+ }
425
+ async listen() {
426
+ return new Promise((resolve, reject) => {
427
+ this.server.listen(0, "localhost", () => {
428
+ const address = this.server.address();
429
+ const url = `http://localhost:${address.port}/callback`;
430
+ resolve(url);
431
+ });
432
+ this.server.on("error", reject);
433
+ });
434
+ }
435
+ async waitForCallback() {
436
+ return new Promise((resolve, reject) => {
437
+ this.resolveCallback = resolve;
438
+ this.rejectCallback = reject;
439
+ this.timeoutId = setTimeout(
440
+ () => {
441
+ console.warn("Callback timeout reached");
442
+ reject(new Error("Callback timeout after 5 minutes"));
443
+ this.cleanup();
444
+ },
445
+ 5 * 60 * 1e3
446
+ );
447
+ });
448
+ }
449
+ };
360
450
 
361
- // src/policies.ts
362
- function parsePolicies(policies) {
363
- return {
364
- verified: false,
365
- contracts: policies.contracts ? Object.fromEntries(
366
- Object.entries(policies.contracts).map(([address, contract]) => [
367
- address,
368
- {
369
- ...contract,
370
- methods: contract.methods.map((method) => ({
371
- ...method,
372
- authorized: true
373
- }))
451
+ // src/node/backend.ts
452
+ var NodeBackend = class {
453
+ basePath;
454
+ sessionFile;
455
+ data = {};
456
+ callbackServer;
457
+ constructor(basePath) {
458
+ if (!basePath) {
459
+ throw new Error("basePath is required for NodeBackend");
460
+ }
461
+ this.basePath = basePath;
462
+ this.sessionFile = path.join(this.basePath, "session.json");
463
+ }
464
+ async ensureDirectoryExists() {
465
+ try {
466
+ await fs.access(this.basePath);
467
+ } catch {
468
+ try {
469
+ await fs.mkdir(this.basePath, { recursive: true });
470
+ } catch (error) {
471
+ throw new Error(
472
+ `Failed to create directory ${this.basePath}: ${error.message}`
473
+ );
474
+ }
475
+ }
476
+ }
477
+ async loadData() {
478
+ try {
479
+ const content = await fs.readFile(this.sessionFile, "utf-8");
480
+ const parsed = JSON.parse(content);
481
+ if (typeof parsed !== "object" || parsed === null) {
482
+ throw new Error("Invalid session data format");
483
+ }
484
+ this.data = parsed;
485
+ } catch (error) {
486
+ if (error instanceof Error) {
487
+ if (error.code !== "ENOENT") {
488
+ throw new Error(`Failed to load session data: ${error.message}`);
374
489
  }
375
- ])
376
- ) : void 0,
377
- messages: policies.messages?.map((message) => ({
378
- ...message,
379
- authorized: true
380
- }))
381
- };
382
- }
490
+ }
491
+ this.data = {};
492
+ }
493
+ }
494
+ async saveData() {
495
+ try {
496
+ await this.ensureDirectoryExists();
497
+ await fs.writeFile(
498
+ this.sessionFile,
499
+ JSON.stringify(this.data, null, 2),
500
+ "utf-8"
501
+ );
502
+ } catch (error) {
503
+ if (error instanceof Error) {
504
+ throw new Error(`Failed to save session data: ${error.message}`);
505
+ }
506
+ throw error;
507
+ }
508
+ }
509
+ async get(key) {
510
+ if (!key) {
511
+ throw new Error("Key is required");
512
+ }
513
+ await this.loadData();
514
+ return this.data[key] ? JSON.stringify(this.data[key]) : null;
515
+ }
516
+ async set(key, value) {
517
+ if (!key) {
518
+ throw new Error("Key is required");
519
+ }
520
+ if (!value) {
521
+ throw new Error("Value is required");
522
+ }
523
+ await this.loadData();
524
+ try {
525
+ this.data[key] = JSON.parse(value);
526
+ await this.saveData();
527
+ } catch (error) {
528
+ if (error instanceof Error) {
529
+ throw new Error(`Failed to set ${key}: ${error.message}`);
530
+ }
531
+ throw error;
532
+ }
533
+ }
534
+ async delete(key) {
535
+ if (!key) {
536
+ throw new Error("Key is required");
537
+ }
538
+ await this.loadData();
539
+ delete this.data[key];
540
+ await this.saveData();
541
+ }
542
+ async getRedirectUri() {
543
+ try {
544
+ this.callbackServer = new CallbackServer();
545
+ return await this.callbackServer.listen();
546
+ } catch (error) {
547
+ if (error instanceof Error) {
548
+ throw new Error(`Failed to start callback server: ${error.message}`);
549
+ }
550
+ throw error;
551
+ }
552
+ }
553
+ async waitForCallback() {
554
+ if (!this.callbackServer) {
555
+ throw new Error("Callback server not initialized");
556
+ }
557
+ return await this.callbackServer.waitForCallback();
558
+ }
559
+ openLink(url) {
560
+ if (!url) {
561
+ throw new Error("URL is required");
562
+ }
563
+ console.log(`
564
+ Open url to authorize session: ${url}`);
565
+ }
566
+ };
383
567
 
384
- // src/telegram/provider.ts
385
- var TelegramProvider = class extends BaseProvider {
386
- _tmaUrl;
568
+ // src/node/provider.ts
569
+ var SessionProvider = class extends BaseProvider {
570
+ id = "controller_session";
571
+ name = "Controller Session";
387
572
  _chainId;
573
+ _rpcUrl;
388
574
  _username;
389
575
  _policies;
390
- _rpcUrl;
576
+ _keychainUrl;
577
+ _backend;
391
578
  constructor({
392
579
  rpc,
393
580
  chainId,
394
581
  policies,
395
- tmaUrl
582
+ basePath,
583
+ keychainUrl
396
584
  }) {
397
585
  super();
586
+ this._policies = {
587
+ verified: false,
588
+ contracts: policies.contracts ? Object.fromEntries(
589
+ Object.entries(policies.contracts).map(([address, contract]) => [
590
+ address,
591
+ {
592
+ ...contract,
593
+ methods: contract.methods.map((method) => ({
594
+ ...method,
595
+ authorized: true
596
+ }))
597
+ }
598
+ ])
599
+ ) : undefined,
600
+ messages: policies.messages?.map((message) => ({
601
+ ...message,
602
+ authorized: true
603
+ }))
604
+ };
398
605
  this._rpcUrl = rpc;
399
- this._tmaUrl = tmaUrl;
400
606
  this._chainId = chainId;
401
- this._policies = parsePolicies(policies);
402
- if (typeof window !== "undefined") {
403
- window.starknet_controller = this;
607
+ this._keychainUrl = keychainUrl || KEYCHAIN_URL;
608
+ this._backend = new NodeBackend(basePath);
609
+ }
610
+ async username() {
611
+ const sessionStr = await this._backend.get("session");
612
+ if (sessionStr) {
613
+ const session = JSON.parse(sessionStr);
614
+ return session.username;
404
615
  }
616
+ return undefined;
405
617
  }
406
618
  async probe() {
407
- await this.tryRetrieveFromQueryOrStorage();
408
- return;
619
+ if (this.account) {
620
+ return this.account;
621
+ }
622
+ const [sessionStr, signerStr] = await Promise.all([
623
+ this._backend.get("session"),
624
+ this._backend.get("signer")
625
+ ]);
626
+ if (!sessionStr || !signerStr) {
627
+ return undefined;
628
+ }
629
+ const session = JSON.parse(sessionStr);
630
+ const signer = JSON.parse(signerStr);
631
+ const expirationTime = parseInt(session.expiresAt) * 1e3;
632
+ if (Date.now() >= expirationTime) {
633
+ await this.disconnect();
634
+ return undefined;
635
+ }
636
+ this._username = session.username;
637
+ this.account = new SessionAccount(this, {
638
+ rpcUrl: this._rpcUrl,
639
+ privateKey: signer.privKey,
640
+ address: session.address,
641
+ ownerGuid: session.ownerGuid,
642
+ chainId: this._chainId,
643
+ expiresAt: parseInt(session.expiresAt),
644
+ policies: toWasmPolicies(this._policies)
645
+ });
646
+ return this.account;
409
647
  }
410
648
  async connect() {
411
- await this.tryRetrieveFromQueryOrStorage();
412
649
  if (this.account) {
413
- return;
650
+ return this.account;
651
+ }
652
+ const account = await this.probe();
653
+ if (account) {
654
+ return account;
414
655
  }
415
656
  const pk = stark.randomAddress();
416
657
  const publicKey = ec.starkCurve.getStarkKey(pk);
417
- cloudStorage.setItem(
418
- "sessionSigner",
658
+ await this._backend.set(
659
+ "signer",
419
660
  JSON.stringify({
420
661
  privKey: pk,
421
662
  pubKey: publicKey
422
663
  })
423
664
  );
424
- const url = `${KEYCHAIN_URL}/session?public_key=${publicKey}&redirect_uri=${this._tmaUrl}&redirect_query_name=startapp&policies=${JSON.stringify(
425
- this._policies
426
- )}&rpc_url=${this._rpcUrl}`;
427
- localStorage.setItem("lastUsedConnector", this.id);
428
- openLink(url);
429
- miniApp.close();
430
- return;
665
+ const redirectUri = await this._backend.getRedirectUri();
666
+ const url = `${this._keychainUrl}/session?public_key=${encodeURIComponent(publicKey)}&redirect_uri=${encodeURIComponent(
667
+ redirectUri
668
+ )}&redirect_query_name=startapp&policies=${encodeURIComponent(
669
+ JSON.stringify(this._policies)
670
+ )}&rpc_url=${encodeURIComponent(this._rpcUrl)}`;
671
+ this._backend.openLink(url);
672
+ const sessionData = await this._backend.waitForCallback();
673
+ if (sessionData) {
674
+ const sessionRegistration = JSON.parse(atob(sessionData));
675
+ sessionRegistration.address = sessionRegistration.address.toLowerCase();
676
+ sessionRegistration.ownerGuid = sessionRegistration.ownerGuid.toLowerCase();
677
+ await this._backend.set("session", JSON.stringify(sessionRegistration));
678
+ return this.probe();
679
+ }
680
+ return undefined;
681
+ }
682
+ async disconnect() {
683
+ await this._backend.delete("signer");
684
+ await this._backend.delete("session");
685
+ this.account = undefined;
686
+ this._username = undefined;
431
687
  }
432
688
  switchStarknetChain(_chainId) {
433
689
  throw new Error("switchStarknetChain not implemented");
@@ -435,45 +691,8 @@ var TelegramProvider = class extends BaseProvider {
435
691
  addStarknetChain(_chain) {
436
692
  throw new Error("addStarknetChain not implemented");
437
693
  }
438
- disconnect() {
439
- cloudStorage.deleteItem("sessionSigner");
440
- cloudStorage.deleteItem("session");
441
- this.account = void 0;
442
- this._username = void 0;
443
- return Promise.resolve();
444
- }
445
- async tryRetrieveFromQueryOrStorage() {
446
- const signer = JSON.parse(await cloudStorage.getItem("sessionSigner"));
447
- let sessionRegistration = null;
448
- const launchParams = retrieveLaunchParams();
449
- const session = launchParams.startParam;
450
- if (session) {
451
- sessionRegistration = JSON.parse(atob(session));
452
- cloudStorage.setItem("session", JSON.stringify(sessionRegistration));
453
- }
454
- if (!sessionRegistration) {
455
- const session2 = await cloudStorage.getItem("session");
456
- if (session2) {
457
- sessionRegistration = JSON.parse(session2);
458
- }
459
- }
460
- if (!sessionRegistration) {
461
- return;
462
- }
463
- this._username = sessionRegistration.username;
464
- this.account = new SessionAccount(this, {
465
- rpcUrl: this._rpcUrl,
466
- privateKey: signer.privKey,
467
- address: sessionRegistration.address,
468
- ownerGuid: sessionRegistration.ownerGuid,
469
- chainId: this._chainId,
470
- expiresAt: parseInt(sessionRegistration.expiresAt),
471
- policies: toWasmPolicies(this._policies)
472
- });
473
- return this.account;
474
- }
475
- };
476
- export {
477
- TelegramProvider as default
478
694
  };
479
- //# sourceMappingURL=provider.js.map
695
+
696
+ export { NotReadyToConnect, ResponseCodes, SessionProvider as default };
697
+ //# sourceMappingURL=index.js.map
698
+ //# sourceMappingURL=index.js.map