-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Allow to pass TON Connect session manager using config #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c84215a
Allow to pass TON Connect session manager using config
ProudOfZiggy b645d25
Remove redundant function parameters
ProudOfZiggy e0fe595
Clean up
ProudOfZiggy 04d6b25
Merge remote-tracking branch 'origin' into feature/configurable-sessi…
TrueCarry 4e2f3cc
Clean up
ProudOfZiggy c4436e3
Additionally store domain in session
ProudOfZiggy 768e45d
Make all methods of session manager interface async
ProudOfZiggy d30cb97
Clean up
ProudOfZiggy 38dfdb2
Allow to pass Session manager using iOS bridge
ProudOfZiggy 692c1ff
Fix
ProudOfZiggy 89deb02
Merge branch 'main' into feature/configurable-session-manager
ProudOfZiggy a3eb205
Fix
ProudOfZiggy 8063ad6
Remove _ symbol in parameter name
ProudOfZiggy f07e695
Merge branch 'main' into feature/configurable-session-manager
ProudOfZiggy b53f900
-
ProudOfZiggy 1d13dca
Improvements for better error handling and future migration purposes
ProudOfZiggy 4f903e6
Migration
ProudOfZiggy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
packages/walletkit-ios-bridge/src/SwiftTONConnectSessionsManager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /** | ||
| * Copyright (c) TonTech. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| */ | ||
|
|
||
| import type { TONConnectSessionManager, TONConnectSession, DAppInfo, Wallet, WalletId } from '@ton/walletkit'; | ||
|
|
||
| /** | ||
| * Swift adapter for TONConnect session management. | ||
| * Delegates all session operations to the Swift implementation. | ||
| */ | ||
| export class SwiftTONConnectSessionsManager implements TONConnectSessionManager { | ||
| private swiftSessionsManager: TONConnectSessionManager; | ||
|
|
||
| constructor(swiftSessionsManager: TONConnectSessionManager) { | ||
| this.swiftSessionsManager = swiftSessionsManager; | ||
| } | ||
|
|
||
| async initialize(): Promise<void> { | ||
| /* | ||
| No initialization needed for Swift implementation. | ||
| This method needed to comply with the TONConnectSessionManager interface. | ||
| Such compliance is needed for backward compability with existing codebase. | ||
| */ | ||
| } | ||
|
|
||
| async createSession( | ||
| sessionId: string, | ||
| dAppInfo: DAppInfo, | ||
| wallet: Wallet, | ||
| isJsBridge: boolean, | ||
| ): Promise<TONConnectSession> { | ||
| return await this.swiftSessionsManager.createSession(sessionId, dAppInfo, wallet, isJsBridge); | ||
| } | ||
|
|
||
| async getSession(sessionId: string): Promise<TONConnectSession | undefined> { | ||
| return await this.swiftSessionsManager.getSession(sessionId); | ||
| } | ||
|
|
||
| async getSessionByDomain(domain: string): Promise<TONConnectSession | undefined> { | ||
| return await this.swiftSessionsManager.getSessionByDomain(domain); | ||
| } | ||
|
|
||
| async getSessions(): Promise<TONConnectSession[]> { | ||
| return await this.swiftSessionsManager.getSessions(); | ||
| } | ||
|
|
||
| async getSessionsForWallet(walletId: WalletId): Promise<TONConnectSession[]> { | ||
| return await this.swiftSessionsManager.getSessionsForWallet(walletId); | ||
| } | ||
|
|
||
| async removeSession(sessionId: string): Promise<void> { | ||
| await this.swiftSessionsManager.removeSession(sessionId); | ||
| } | ||
|
|
||
| async removeSessionsForWallet(walletId: WalletId): Promise<void> { | ||
| await this.swiftSessionsManager.removeSessionsForWallet(walletId); | ||
| } | ||
|
|
||
| async clearSessions(): Promise<void> { | ||
| await this.swiftSessionsManager.clearSessions(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
packages/walletkit/src/api/interfaces/TONConnectSessionManager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /** | ||
| * Copyright (c) TonTech. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| */ | ||
|
|
||
| // TONConnect Session Manager abstraction for Dependency Inversion | ||
|
|
||
| import type { DAppInfo, TONConnectSession } from '../models'; | ||
| import type { WalletId } from '../../utils/walletId'; | ||
| import type { Wallet } from '.'; | ||
|
|
||
| /** | ||
| * Abstraction for session management in TONConnect protocol. | ||
| * Provides interface for session CRUD operations and lifecycle management. | ||
| */ | ||
| export interface TONConnectSessionManager { | ||
| /** | ||
| * Initialize the session manager | ||
| * Needed for backward compatibility with existing codebase | ||
| * Used to ensure that sessions are reloaded fro mstorage to local cache in browser extension | ||
| * */ | ||
| initialize(): Promise<void>; | ||
|
|
||
| /** | ||
| * Create a new session | ||
| * @param sessionId - Unique session identifier | ||
| * @param dAppInfo - Information about the dApp (name, url, iconUrl, description) | ||
| * @param wallet - The wallet to associate with this session | ||
| * @param options - Additional options for session creation | ||
| */ | ||
| createSession( | ||
| sessionId: string, | ||
| dAppInfo: DAppInfo, | ||
| wallet: Wallet, | ||
| isJsBridge: boolean, | ||
| ): Promise<TONConnectSession>; | ||
|
|
||
| /** | ||
| * Get session by ID | ||
| * @param sessionId - The session ID to retrieve | ||
| */ | ||
| getSession(sessionId: string): Promise<TONConnectSession | undefined>; | ||
|
|
||
| /** | ||
| * Get session by domain | ||
| * @param domain - The domain to search for | ||
| */ | ||
| getSessionByDomain(domain: string): Promise<TONConnectSession | undefined>; | ||
|
|
||
| /** | ||
| * Get all sessions as array | ||
| */ | ||
| getSessions(): Promise<TONConnectSession[]>; | ||
|
|
||
| /** | ||
| * Get sessions for specific wallet by wallet ID | ||
| * @param walletId - The wallet ID to filter by | ||
| */ | ||
| getSessionsForWallet(walletId: WalletId): Promise<TONConnectSession[]>; | ||
|
|
||
| /** | ||
| * Remove session by ID | ||
| * @param sessionId - The session ID to remove | ||
| */ | ||
| removeSession(sessionId: string): Promise<void>; | ||
|
|
||
| /** | ||
| * Remove all sessions for a wallet by wallet ID | ||
| * @param walletId - Wallet ID string | ||
| */ | ||
| removeSessionsForWallet(walletId: WalletId): Promise<void>; | ||
|
|
||
| /** | ||
| * Clear all sessions | ||
| */ | ||
| clearSessions(): Promise<void>; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/walletkit/src/api/models/bridge/TONConnectSession.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * Copyright (c) TonTech. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| * | ||
| */ | ||
|
|
||
| import type { UserFriendlyAddress, WalletId } from '../../..'; | ||
|
|
||
| export interface TONConnectSession { | ||
| sessionId: string; | ||
|
|
||
| walletId: WalletId; | ||
| walletAddress: UserFriendlyAddress; | ||
| createdAt: string; // date | ||
| lastActivityAt: string; // date | ||
| privateKey: string; | ||
| publicKey: string; | ||
| domain: string; | ||
|
|
||
| /** | ||
| * Display name of the dApp | ||
| */ | ||
| dAppName?: string; | ||
|
|
||
| /** | ||
| * Brief description of the dApp's purpose | ||
| */ | ||
| dAppDescription?: string; | ||
|
|
||
| /** | ||
| * Main website URL of the dApp | ||
| * @format url | ||
| */ | ||
| dAppUrl?: string; | ||
|
|
||
| /** | ||
| * Icon/logo URL of the dApp | ||
| * @format url | ||
| */ | ||
| dAppIconUrl?: string; | ||
|
|
||
| // Bridge type indicator (needed to determine how to send disconnect events) | ||
| isJsBridge?: boolean; // true if session was created via JS Bridge, false/undefined for HTTP Bridge | ||
|
|
||
| schemaVersion: number; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.