@openfort/react-native 0.1.22 → 0.1.23

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.
@@ -38,16 +38,13 @@ export class OpenfortSolanaProvider {
38
38
  async request(args) {
39
39
  switch (args.method) {
40
40
  case 'signMessage': {
41
- // Convert message string to Uint8Array
42
41
  const signature = await this._signMessage(args.params.message);
43
- return { signature: signature };
42
+ return { signature };
44
43
  }
45
44
  case 'signTransaction': {
46
45
  const signedTransaction = await this._signTransaction(args.params.transaction);
47
46
  return { signedTransaction };
48
47
  }
49
- default:
50
- throw new Error(`Unsupported method: ${args.method}`);
51
48
  }
52
49
  }
53
50
  /**
@@ -166,18 +166,18 @@ export function useEmbeddedSolanaWallet(options = {}) {
166
166
  // Extract the message bytes from the transaction
167
167
  // For @solana/kit compiledTransaction, the messageBytes property contains what needs to be signed
168
168
  let messageBytes;
169
- if (transaction.messageBytes) {
169
+ if (transaction instanceof Uint8Array) {
170
+ // Raw bytes
171
+ messageBytes = transaction;
172
+ }
173
+ else if ('messageBytes' in transaction) {
170
174
  // @solana/kit compiled transaction
171
175
  messageBytes = transaction.messageBytes;
172
176
  }
173
- else if (transaction.serializeMessage) {
177
+ else if ('serializeMessage' in transaction) {
174
178
  // @solana/web3.js Transaction
175
179
  messageBytes = transaction.serializeMessage();
176
180
  }
177
- else if (transaction instanceof Uint8Array) {
178
- // Raw bytes
179
- messageBytes = transaction;
180
- }
181
181
  else {
182
182
  throw new OpenfortError('Unsupported transaction format. Expected @solana/kit compiled transaction, @solana/web3.js Transaction, or Uint8Array', OpenfortErrorType.WALLET_ERROR);
183
183
  }
@@ -189,13 +189,12 @@ export function useEmbeddedSolanaWallet(options = {}) {
189
189
  data: Array.from(messageBytes),
190
190
  };
191
191
  // Sign the message bytes (hashMessage: false for Solana - Ed25519 signs raw bytes)
192
- // Note: We cast to any because the iframe will deserialize the Buffer format correctly,
192
+ // Note: We cast to unknown because the iframe will deserialize the Buffer format correctly,
193
193
  // but TypeScript doesn't know about this serialization detail
194
194
  const signatureBase58 = await client.embeddedWallet.signMessage(bufferFormatMessage, {
195
195
  hashMessage: false,
196
196
  });
197
197
  // Return the signature in the expected format
198
- // Different libraries expect different return formats, so we return a flexible object
199
198
  return {
200
199
  signature: signatureBase58,
201
200
  publicKey: account.address,
@@ -1,17 +1,5 @@
1
1
  import type { EmbeddedAccount } from '@openfort/openfort-js';
2
- import type { OpenfortEmbeddedSolanaWalletProvider } from '../../types/wallet';
3
- type SignMessageRequestArguments = {
4
- method: 'signMessage';
5
- params: {
6
- message: string;
7
- };
8
- };
9
- type SignTransactionRequestArguments<T = any> = {
10
- method: 'signTransaction';
11
- params: {
12
- transaction: T;
13
- };
14
- };
2
+ import type { OpenfortEmbeddedSolanaWalletProvider, SignedSolanaTransaction, SolanaSignMessageRequest, SolanaSignTransactionRequest, SolanaTransaction } from '../../types/wallet';
15
3
  /**
16
4
  * Embedded Solana wallet provider implementation for Openfort.
17
5
  *
@@ -38,8 +26,8 @@ export declare class OpenfortSolanaProvider implements OpenfortEmbeddedSolanaWal
38
26
  */
39
27
  constructor(params: {
40
28
  account: EmbeddedAccount;
41
- signTransaction: (transaction: any) => Promise<any>;
42
- signAllTransactions: (transactions: any[]) => Promise<any[]>;
29
+ signTransaction: (transaction: SolanaTransaction) => Promise<SignedSolanaTransaction>;
30
+ signAllTransactions: (transactions: SolanaTransaction[]) => Promise<SignedSolanaTransaction[]>;
43
31
  signMessage: (message: string) => Promise<string>;
44
32
  });
45
33
  /**
@@ -49,20 +37,20 @@ export declare class OpenfortSolanaProvider implements OpenfortEmbeddedSolanaWal
49
37
  /**
50
38
  * Request-based API for wallet operations
51
39
  */
52
- request(args: SignMessageRequestArguments): Promise<{
40
+ request(args: SolanaSignMessageRequest): Promise<{
53
41
  signature: string;
54
42
  }>;
55
- request(args: SignTransactionRequestArguments): Promise<{
56
- signedTransaction: any;
43
+ request(args: SolanaSignTransactionRequest): Promise<{
44
+ signedTransaction: SignedSolanaTransaction;
57
45
  }>;
58
46
  /**
59
47
  * Sign a single transaction (direct method)
60
48
  */
61
- signTransaction(transaction: any): Promise<any>;
49
+ signTransaction(transaction: SolanaTransaction): Promise<SignedSolanaTransaction>;
62
50
  /**
63
51
  * Sign multiple transactions (direct method)
64
52
  */
65
- signAllTransactions(transactions: any[]): Promise<any[]>;
53
+ signAllTransactions(transactions: SolanaTransaction[]): Promise<SignedSolanaTransaction[]>;
66
54
  /**
67
55
  * Sign a message (direct method)
68
56
  */
@@ -72,4 +60,3 @@ export declare class OpenfortSolanaProvider implements OpenfortEmbeddedSolanaWal
72
60
  */
73
61
  toJSON(): string;
74
62
  }
75
- export {};
@@ -8,4 +8,4 @@ export interface UseOpenfort {
8
8
  }
9
9
  export type { AuthSuccessCallback, EmailLoginHookOptions, EmailLoginHookResult, ErrorCallback, GenerateSiweMessage, GenerateSiweMessageResponse, PasswordFlowState, RecoveryFlowState, SiweFlowState, SiweLoginHookOptions, SiweLoginHookResult, } from './auth';
10
10
  export type { LinkWithOAuthInput, LoginWithOAuthInput, OAuthFlowState, UseLoginWithOAuth, } from './oauth';
11
- export type { ConnectedEmbeddedEthereumWallet, ConnectedEmbeddedSolanaWallet, CreateSolanaEmbeddedWalletOpts, EmbeddedEthereumWalletState, EmbeddedSolanaWalletState, OpenfortEmbeddedEthereumWalletProvider, OpenfortEmbeddedSolanaWalletProvider, } from './wallet';
11
+ export type { ConnectedEmbeddedEthereumWallet, ConnectedEmbeddedSolanaWallet, CreateEthereumWalletOptions, CreateEthereumWalletResult, CreateSolanaEmbeddedWalletOpts, CreateSolanaWalletOptions, CreateSolanaWalletResult, EIP1193EventHandler, EIP1193EventName, EIP1193RequestArguments, EmbeddedEthereumWalletState, EmbeddedSolanaWalletState, EthereumWalletActions, OpenfortEmbeddedEthereumWalletProvider, OpenfortEmbeddedSolanaWalletProvider, SetActiveEthereumWalletOptions, SetActiveEthereumWalletResult, SetActiveSolanaWalletOptions, SetActiveSolanaWalletResult, SetRecoveryOptions, SetRecoveryResult, SignedSolanaTransaction, SolanaRequestArguments, SolanaSignMessageRequest, SolanaSignTransactionRequest, SolanaTransaction, SolanaWalletActions, } from './wallet';
@@ -1,25 +1,105 @@
1
- import type { ChainTypeEnum } from '@openfort/openfort-js';
1
+ import type { AccountTypeEnum, ChainTypeEnum, EmbeddedAccount, RecoveryParams } from '@openfort/openfort-js';
2
+ import type { Hex } from './hex';
3
+ import type { OpenfortHookOptions } from './hookOption';
4
+ import type { OpenfortError } from './openfortError';
2
5
  /**
3
- * Ethereum wallet provider interface for EIP-1193 compatible operations
6
+ * JSON-RPC request arguments following EIP-1193 spec
7
+ */
8
+ export type EIP1193RequestArguments = {
9
+ readonly method: string;
10
+ readonly params?: readonly unknown[] | object;
11
+ };
12
+ /**
13
+ * EIP-1193 event names
14
+ */
15
+ export type EIP1193EventName = 'accountsChanged' | 'chainChanged' | 'connect' | 'disconnect' | 'message';
16
+ /**
17
+ * EIP-1193 provider event handler
18
+ */
19
+ export type EIP1193EventHandler = (...args: unknown[]) => void;
20
+ /**
21
+ * Ethereum wallet provider interface following EIP-1193 spec
22
+ *
23
+ * @see https://eips.ethereum.org/EIPS/eip-1193
4
24
  */
5
25
  export interface OpenfortEmbeddedEthereumWalletProvider {
6
- request: (args: {
7
- method: string;
8
- params?: any[];
9
- }) => Promise<any>;
10
- on: (event: string, handler: (...args: any[]) => void) => void;
11
- removeListener: (event: string, handler: (...args: any[]) => void) => void;
12
- [key: string]: any;
26
+ /**
27
+ * Submit a JSON-RPC request to the provider
28
+ */
29
+ request(args: EIP1193RequestArguments): Promise<unknown>;
30
+ /**
31
+ * Subscribe to provider events
32
+ */
33
+ on(event: EIP1193EventName | string, handler: EIP1193EventHandler): void;
34
+ /**
35
+ * Unsubscribe from provider events
36
+ */
37
+ removeListener(event: EIP1193EventName | string, handler: EIP1193EventHandler): void;
13
38
  }
39
+ /**
40
+ * Represents a Solana transaction that can be signed.
41
+ * Supports multiple formats:
42
+ * - @solana/web3.js Transaction (has serializeMessage method)
43
+ * - @solana/kit compiled transaction (has messageBytes property)
44
+ * - Raw Uint8Array
45
+ */
46
+ export type SolanaTransaction = {
47
+ messageBytes: Uint8Array;
48
+ } | {
49
+ serializeMessage(): Uint8Array;
50
+ } | Uint8Array;
51
+ /**
52
+ * Result of signing a Solana transaction
53
+ */
54
+ export type SignedSolanaTransaction = {
55
+ signature: string;
56
+ publicKey: string;
57
+ };
58
+ /**
59
+ * Solana provider request arguments
60
+ */
61
+ export type SolanaSignMessageRequest = {
62
+ method: 'signMessage';
63
+ params: {
64
+ message: string;
65
+ };
66
+ };
67
+ export type SolanaSignTransactionRequest = {
68
+ method: 'signTransaction';
69
+ params: {
70
+ transaction: SolanaTransaction;
71
+ };
72
+ };
73
+ export type SolanaRequestArguments = SolanaSignMessageRequest | SolanaSignTransactionRequest;
14
74
  /**
15
75
  * Solana wallet provider interface
16
76
  */
17
77
  export interface OpenfortEmbeddedSolanaWalletProvider {
18
- signMessage: (message: string) => Promise<string>;
19
- signTransaction: (transaction: any) => Promise<any>;
20
- signAllTransactions: (transactions: any[]) => Promise<any[]>;
21
- publicKey: string;
22
- [key: string]: any;
78
+ /**
79
+ * The public key (address) of the wallet
80
+ */
81
+ readonly publicKey: string;
82
+ /**
83
+ * Sign a message and return the signature
84
+ */
85
+ signMessage(message: string): Promise<string>;
86
+ /**
87
+ * Sign a single transaction
88
+ */
89
+ signTransaction(transaction: SolanaTransaction): Promise<SignedSolanaTransaction>;
90
+ /**
91
+ * Sign multiple transactions
92
+ */
93
+ signAllTransactions(transactions: SolanaTransaction[]): Promise<SignedSolanaTransaction[]>;
94
+ /**
95
+ * Request-based API (similar to EIP-1193 pattern)
96
+ */
97
+ request(args: SolanaSignMessageRequest): Promise<{
98
+ signature: string;
99
+ }>;
100
+ request(args: SolanaSignTransactionRequest): Promise<{
101
+ signedTransaction: SignedSolanaTransaction;
102
+ }>;
23
103
  }
24
104
  /**
25
105
  * Connected Ethereum wallet
@@ -41,6 +121,52 @@ export type ConnectedEmbeddedSolanaWallet = {
41
121
  walletIndex: number;
42
122
  getProvider: () => Promise<OpenfortEmbeddedSolanaWalletProvider>;
43
123
  };
124
+ /**
125
+ * Result of creating an Ethereum wallet
126
+ */
127
+ export type CreateEthereumWalletResult = {
128
+ error?: OpenfortError;
129
+ account?: EmbeddedAccount;
130
+ provider?: OpenfortEmbeddedEthereumWalletProvider;
131
+ };
132
+ /**
133
+ * Options for creating an Ethereum wallet
134
+ */
135
+ export type CreateEthereumWalletOptions = {
136
+ chainId?: number;
137
+ recoveryPassword?: string;
138
+ accountType?: AccountTypeEnum;
139
+ policyId?: string;
140
+ } & OpenfortHookOptions<CreateEthereumWalletResult>;
141
+ /**
142
+ * Result of setting active Ethereum wallet
143
+ */
144
+ export type SetActiveEthereumWalletResult = {
145
+ error?: OpenfortError;
146
+ wallet?: ConnectedEmbeddedEthereumWallet;
147
+ provider?: OpenfortEmbeddedEthereumWalletProvider;
148
+ };
149
+ /**
150
+ * Options for setting active Ethereum wallet
151
+ */
152
+ export type SetActiveEthereumWalletOptions = {
153
+ address: Hex;
154
+ chainId?: number;
155
+ recoveryPassword?: string;
156
+ } & OpenfortHookOptions<SetActiveEthereumWalletResult>;
157
+ /**
158
+ * Result of setting recovery method
159
+ */
160
+ export type SetRecoveryResult = {
161
+ error?: OpenfortError;
162
+ };
163
+ /**
164
+ * Options for setting recovery method
165
+ */
166
+ export type SetRecoveryOptions = {
167
+ previousRecovery: RecoveryParams;
168
+ newRecovery: RecoveryParams;
169
+ } & OpenfortHookOptions<SetRecoveryResult>;
44
170
  /**
45
171
  * Simplified Solana wallet creation options
46
172
  */
@@ -55,112 +181,125 @@ export type CreateSolanaEmbeddedWalletOpts = {
55
181
  */
56
182
  createAdditional?: boolean;
57
183
  };
184
+ /**
185
+ * Result of creating a Solana wallet
186
+ */
187
+ export type CreateSolanaWalletResult = {
188
+ error?: OpenfortError;
189
+ account?: EmbeddedAccount;
190
+ provider?: OpenfortEmbeddedSolanaWalletProvider;
191
+ };
192
+ /**
193
+ * Options for creating a Solana wallet
194
+ */
195
+ export type CreateSolanaWalletOptions = CreateSolanaEmbeddedWalletOpts & OpenfortHookOptions<CreateSolanaWalletResult>;
196
+ /**
197
+ * Result of setting active Solana wallet
198
+ */
199
+ export type SetActiveSolanaWalletResult = {
200
+ error?: OpenfortError;
201
+ wallet?: ConnectedEmbeddedSolanaWallet;
202
+ provider?: OpenfortEmbeddedSolanaWalletProvider;
203
+ };
204
+ /**
205
+ * Options for setting active Solana wallet
206
+ */
207
+ export type SetActiveSolanaWalletOptions = {
208
+ address: string;
209
+ recoveryPassword?: string;
210
+ } & OpenfortHookOptions<SetActiveSolanaWalletResult>;
211
+ /**
212
+ * Common actions available on all Ethereum wallet states
213
+ */
214
+ export interface EthereumWalletActions {
215
+ /**
216
+ * Create a new embedded Ethereum wallet
217
+ */
218
+ create(options?: CreateEthereumWalletOptions): Promise<EmbeddedAccount>;
219
+ /**
220
+ * List of available wallets
221
+ */
222
+ wallets: ConnectedEmbeddedEthereumWallet[];
223
+ /**
224
+ * Set a wallet as active (recover/connect to it)
225
+ */
226
+ setActive(options: SetActiveEthereumWalletOptions): Promise<void>;
227
+ /**
228
+ * Update the recovery method for the wallet
229
+ */
230
+ setRecovery(options: SetRecoveryOptions): Promise<void>;
231
+ /**
232
+ * Export the private key of the active wallet
233
+ */
234
+ exportPrivateKey(): Promise<string>;
235
+ }
236
+ /**
237
+ * Common actions available on all Solana wallet states
238
+ */
239
+ export interface SolanaWalletActions {
240
+ /**
241
+ * Create a new embedded Solana wallet
242
+ */
243
+ create(options?: CreateSolanaWalletOptions): Promise<EmbeddedAccount>;
244
+ /**
245
+ * List of available wallets
246
+ */
247
+ wallets: ConnectedEmbeddedSolanaWallet[];
248
+ /**
249
+ * Set a wallet as active (recover/connect to it)
250
+ */
251
+ setActive(options: SetActiveSolanaWalletOptions): Promise<void>;
252
+ }
58
253
  /**
59
254
  * Ethereum wallet hook return type - discriminated union based on status
60
255
  */
61
- export type EmbeddedEthereumWalletState = {
256
+ export type EmbeddedEthereumWalletState = (EthereumWalletActions & {
62
257
  status: 'disconnected';
63
258
  activeWallet: null;
64
- create: (...args: any[]) => Promise<any>;
65
- wallets: ConnectedEmbeddedEthereumWallet[];
66
- setActive: (...args: any[]) => Promise<void>;
67
- setRecovery: (...args: any[]) => Promise<void>;
68
- exportPrivateKey: (...args: any[]) => Promise<any>;
69
- } | {
259
+ }) | (EthereumWalletActions & {
70
260
  status: 'connecting';
71
261
  activeWallet: ConnectedEmbeddedEthereumWallet;
72
- create: (...args: any[]) => Promise<any>;
73
- wallets: ConnectedEmbeddedEthereumWallet[];
74
- setActive: (...args: any[]) => Promise<void>;
75
- setRecovery: (...args: any[]) => Promise<void>;
76
- exportPrivateKey: (...args: any[]) => Promise<any>;
77
- } | {
262
+ }) | (EthereumWalletActions & {
78
263
  status: 'reconnecting';
79
264
  activeWallet: ConnectedEmbeddedEthereumWallet;
80
- create: (...args: any[]) => Promise<any>;
81
- wallets: ConnectedEmbeddedEthereumWallet[];
82
- setActive: (...args: any[]) => Promise<void>;
83
- setRecovery: (...args: any[]) => Promise<void>;
84
- exportPrivateKey: (...args: any[]) => Promise<any>;
85
- } | {
265
+ }) | (EthereumWalletActions & {
86
266
  status: 'creating';
87
267
  activeWallet: null;
88
- create: (...args: any[]) => Promise<any>;
89
- wallets: ConnectedEmbeddedEthereumWallet[];
90
- setActive: (...args: any[]) => Promise<void>;
91
- setRecovery: (...args: any[]) => Promise<void>;
92
- exportPrivateKey: (...args: any[]) => Promise<any>;
93
- } | {
268
+ }) | (EthereumWalletActions & {
94
269
  status: 'needs-recovery';
95
270
  activeWallet: ConnectedEmbeddedEthereumWallet;
96
- create: (...args: any[]) => Promise<any>;
97
- wallets: ConnectedEmbeddedEthereumWallet[];
98
- setActive: (...args: any[]) => Promise<void>;
99
- setRecovery: (...args: any[]) => Promise<void>;
100
- exportPrivateKey: (...args: any[]) => Promise<any>;
101
- } | {
271
+ }) | (EthereumWalletActions & {
102
272
  status: 'connected';
103
273
  activeWallet: ConnectedEmbeddedEthereumWallet;
104
274
  provider: OpenfortEmbeddedEthereumWalletProvider;
105
- create: (...args: any[]) => Promise<any>;
106
- wallets: ConnectedEmbeddedEthereumWallet[];
107
- setActive: (...args: any[]) => Promise<void>;
108
- setRecovery: (...args: any[]) => Promise<void>;
109
- exportPrivateKey: (...args: any[]) => Promise<any>;
110
- } | {
275
+ }) | (EthereumWalletActions & {
111
276
  status: 'error';
112
277
  activeWallet: ConnectedEmbeddedEthereumWallet | null;
113
278
  error: string;
114
- create: (...args: any[]) => Promise<any>;
115
- wallets: ConnectedEmbeddedEthereumWallet[];
116
- setActive: (...args: any[]) => Promise<void>;
117
- setRecovery: (...args: any[]) => Promise<void>;
118
- exportPrivateKey: (...args: any[]) => Promise<any>;
119
- };
279
+ });
120
280
  /**
121
281
  * Solana wallet hook return type - discriminated union based on status
122
282
  */
123
- export type EmbeddedSolanaWalletState = {
283
+ export type EmbeddedSolanaWalletState = (SolanaWalletActions & {
124
284
  status: 'disconnected';
125
285
  activeWallet: null;
126
- create: (...args: any[]) => Promise<any>;
127
- wallets: ConnectedEmbeddedSolanaWallet[];
128
- setActive: (...args: any[]) => Promise<void>;
129
- } | {
286
+ }) | (SolanaWalletActions & {
130
287
  status: 'connecting';
131
- create: (...args: any[]) => Promise<any>;
132
- wallets: ConnectedEmbeddedSolanaWallet[];
133
- setActive: (...args: any[]) => Promise<void>;
134
- } | {
288
+ }) | (SolanaWalletActions & {
135
289
  status: 'reconnecting';
136
290
  activeWallet: ConnectedEmbeddedSolanaWallet;
137
- create: (...args: any[]) => Promise<any>;
138
- wallets: ConnectedEmbeddedSolanaWallet[];
139
- setActive: (...args: any[]) => Promise<void>;
140
- } | {
291
+ }) | (SolanaWalletActions & {
141
292
  status: 'creating';
142
293
  activeWallet: null;
143
- create: (...args: any[]) => Promise<any>;
144
- wallets: ConnectedEmbeddedSolanaWallet[];
145
- setActive: (...args: any[]) => Promise<void>;
146
- } | {
294
+ }) | (SolanaWalletActions & {
147
295
  status: 'needs-recovery';
148
296
  activeWallet: ConnectedEmbeddedSolanaWallet;
149
- create: (...args: any[]) => Promise<any>;
150
- wallets: ConnectedEmbeddedSolanaWallet[];
151
- setActive: (...args: any[]) => Promise<void>;
152
- } | {
297
+ }) | (SolanaWalletActions & {
153
298
  status: 'connected';
154
299
  activeWallet: ConnectedEmbeddedSolanaWallet;
155
300
  provider: OpenfortEmbeddedSolanaWalletProvider;
156
- create: (...args: any[]) => Promise<any>;
157
- wallets: ConnectedEmbeddedSolanaWallet[];
158
- setActive: (...args: any[]) => Promise<void>;
159
- } | {
301
+ }) | (SolanaWalletActions & {
160
302
  status: 'error';
161
303
  activeWallet: ConnectedEmbeddedSolanaWallet | null;
162
304
  error: string;
163
- create: (...args: any[]) => Promise<any>;
164
- wallets: ConnectedEmbeddedSolanaWallet[];
165
- setActive: (...args: any[]) => Promise<void>;
166
- };
305
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfort/react-native",
3
3
  "main": "dist/index.js",
4
- "version": "0.1.22",
4
+ "version": "0.1.23",
5
5
  "license": "MIT",
6
6
  "description": "React Native SDK for Openfort platform integration",
7
7
  "types": "dist/types/index.d.ts",