-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathwallet.interface.ts
More file actions
167 lines (150 loc) · 5.18 KB
/
Copy pathwallet.interface.ts
File metadata and controls
167 lines (150 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
* WalletAdapter — abstract interface for Stellar wallet integrations.
*
* Implementations: FreighterAdapter, XBullAdapter, AlbedoAdapter,
* LobstrAdapter, RabetAdapter, MockWalletAdapter, plus any custom adapter
* that extends this class.
*
* @see WALLET_ADAPTER.md for the full integrator contract
* (methods, expected errors, and signing flow).
*/
export enum WalletName {
Freighter = 'freighter',
XBull = 'xbull',
Albedo = 'albedo',
LOBSTR = 'lobstr',
Rabet = 'rabet',
Mock = 'mock',
/** Reserved identifier for third-party / in-house adapters */
Custom = 'custom',
}
export interface WalletAdapterOptions {
/** Stellar network passphrase (e.g. Networks.TESTNET) */
networkPassphrase?: string;
}
export interface SignTransactionResult {
/** Signed XDR envelope */
signedXdr: string;
}
/**
* Describes which operations a wallet adapter supports.
* Used to enable adaptive UI behavior based on wallet capabilities.
*
* Keep these flags honest: never advertise a capability whose method
* will throw or no-op.
*/
export interface WalletCapabilities {
/**
* Whether the adapter supports retrieving the user's public key.
* @default true
*/
supportsGetPublicKey: boolean;
/**
* Whether the adapter supports signing Soroban transactions.
* @default true
*/
supportsSignTransaction: boolean;
/**
* Whether the adapter supports signing arbitrary messages (SIWS, etc).
* @default false
*/
supportsSignMessage: boolean;
/**
* Whether the adapter can retrieve the currently selected network.
* @default false
*/
supportsGetNetwork: boolean;
}
/**
* Common interface every wallet adapter must implement.
*
* ### Required methods
* - {@link isAvailable} — environment / extension detection
* - {@link getPublicKey} — return the active `G…` account
* - {@link signTransaction} — sign a base64 transaction envelope XDR
* - {@link getCapabilities} — advertise supported features
*
* ### Optional methods
* - {@link connect} / {@link disconnect} — explicit session lifecycle
* - {@link signMessage} — SIWS / arbitrary message signing (default throws)
* - {@link getNetwork} — selected network passphrase (default `undefined`)
*
* ### Expected errors
* Throw {@link TikkaSdkError} with:
* - `WalletNotInstalled` — bridge / extension missing
* - `WalletNotConnected` — present but not authorized
* - `UserRejected` — user cancelled a prompt
* - `InvalidParams` — bad XDR / network / account
* - `Unknown` — unexpected failure (attach `cause`)
*
* ### Signing flow
* SDK builds unsigned XDR → `signTransaction(xdr, opts?)` →
* adapter returns `{ signedXdr }` → SDK submits to Soroban RPC.
*/
export abstract class WalletAdapter {
/**
* Stable adapter identifier. Prefer a {@link WalletName} value for
* built-ins; custom adapters may use any string (or `WalletName.Custom`).
*/
abstract readonly name: string;
constructor(protected readonly options: WalletAdapterOptions = {}) {}
/**
* Returns true if the wallet is available in the current environment
* (e.g. extension installed, or web-based wallet always available).
*/
abstract isAvailable(): boolean;
/**
* Establishes connection to the wallet (optional).
* Some wallets require explicit connection, others connect implicitly on first use.
*/
async connect?(): Promise<void>;
/**
* Retrieves the user's public key from the wallet.
* May prompt the user for permission.
*
* @throws {TikkaSdkError} `WalletNotInstalled` | `WalletNotConnected` | `UserRejected` | `Unknown`
*/
abstract getPublicKey(): Promise<string>;
/**
* Signs a Soroban transaction XDR and returns the signed envelope.
*
* Prefer `opts.networkPassphrase` when provided; otherwise use
* `this.options.networkPassphrase`. Return the full signed envelope
* without stripping existing signatures.
*
* @param xdr Base64-encoded transaction envelope XDR
* @param opts Optional overrides (network passphrase, account to sign for)
* @throws {TikkaSdkError} `WalletNotInstalled` | `WalletNotConnected` | `UserRejected` | `InvalidParams` | `Unknown`
*/
abstract signTransaction(
xdr: string,
opts?: { networkPassphrase?: string; accountToSign?: string },
): Promise<SignTransactionResult>;
/**
* Signs an arbitrary message (used for SIWS auth flows).
* Not all wallets support this — adapter may throw.
*
* @throws {Error} when unsupported (default implementation)
* @throws {TikkaSdkError} `UserRejected` | `Unknown` when supported but failing
*/
async signMessage(_message: string): Promise<string> {
throw new Error(`${this.name} does not support signMessage`);
}
/**
* Returns the currently selected network from the wallet.
* Not all wallets expose this.
*/
async getNetwork(): Promise<string | undefined> {
return undefined;
}
/**
* Returns the capabilities supported by this wallet adapter.
* Allows UI to adapt dynamically based on wallet features.
*/
abstract getCapabilities(): WalletCapabilities;
/**
* Disconnects the wallet and clears any cached state.
* Optional - adapters can override if they need cleanup.
*/
disconnect?(): void;
}