@fedimint/react-native 0.0.0-canary-ecde932b329972ca4c9b8b6c8a28f709edb957c0
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.
- package/LICENSE +21 -0
- package/README.md +175 -0
- package/app.plugin.js +2 -0
- package/lib/commonjs/ReactNativeTransport.js +81 -0
- package/lib/commonjs/ReactNativeTransport.js.map +1 -0
- package/lib/commonjs/index.js +44 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/ReactNativeTransport.js +76 -0
- package/lib/module/ReactNativeTransport.js.map +1 -0
- package/lib/module/index.js +30 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/commonjs/ReactNativeTransport.d.ts +8 -0
- package/lib/typescript/commonjs/ReactNativeTransport.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +23 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/module/ReactNativeTransport.d.ts +8 -0
- package/lib/typescript/module/ReactNativeTransport.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +23 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/package.json +70 -0
- package/src/ReactNativeTransport.ts +102 -0
- package/src/index.ts +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 fedimint
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# @fedimint/react-native
|
|
2
|
+
|
|
3
|
+
React Native SDK for Fedimint - the easiest way to integrate Fedimint into your React Native app.
|
|
4
|
+
|
|
5
|
+
## Implementation Options
|
|
6
|
+
|
|
7
|
+
Depending on your project setup, you can use the SDK with or without Expo. Choose the option below that fits your environment.
|
|
8
|
+
|
|
9
|
+
### Option 1: Without Expo (Bare React Native)
|
|
10
|
+
|
|
11
|
+
#### Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @fedimint/react-native
|
|
15
|
+
# or
|
|
16
|
+
yarn add @fedimint/react-native
|
|
17
|
+
# or
|
|
18
|
+
pnpm add @fedimint/react-native
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
You'll also need `react-native-fs` for database storage:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install react-native-fs
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### Usage
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import WalletDirector from '@fedimint/react-native'
|
|
31
|
+
import RNFS from 'react-native-fs'
|
|
32
|
+
|
|
33
|
+
// Create a wallet director with a database path
|
|
34
|
+
const dbPath = `${RNFS.DocumentDirectoryPath}/fedimint_db`
|
|
35
|
+
const director = new WalletDirector(dbPath)
|
|
36
|
+
|
|
37
|
+
// Generate a mnemonic
|
|
38
|
+
const words = await director.generateMnemonic()
|
|
39
|
+
console.log('Mnemonic:', words.join(' '))
|
|
40
|
+
|
|
41
|
+
// Create a wallet and join a federation
|
|
42
|
+
const wallet = await director.createWallet()
|
|
43
|
+
await wallet.joinFederation(inviteCode)
|
|
44
|
+
|
|
45
|
+
// Use wallet methods
|
|
46
|
+
const balance = await wallet.balance.getBalance()
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Option 2: With Expo
|
|
50
|
+
|
|
51
|
+
#### Installation
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npx expo install @fedimint/react-native expo-file-system
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For Expo managed workflow (SDK 52+), add the plugin to your `app.json`:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"expo": {
|
|
62
|
+
"plugins": ["@fedimint/react-native"]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Then build with EAS or a custom dev client:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
npx expo prebuild
|
|
71
|
+
npx expo run:ios
|
|
72
|
+
# or
|
|
73
|
+
npx expo run:android
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Note:** Expo Go is not supported. You must use a custom dev client.
|
|
77
|
+
|
|
78
|
+
#### Usage
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import WalletDirector from '@fedimint/react-native'
|
|
82
|
+
import { Paths } from 'expo-file-system'
|
|
83
|
+
|
|
84
|
+
// Prepare Database Path
|
|
85
|
+
const dbUriPath = Paths.document.uri // e.g. file:///data/...
|
|
86
|
+
// Strip the file:// scheme to get the plain filesystem path for Rust
|
|
87
|
+
const dbPath = dbUriPath + 'fedimint_db'
|
|
88
|
+
const rustPath = dbPath.replace(/^file:\/\//, '')
|
|
89
|
+
|
|
90
|
+
// Create a wallet director with a database path
|
|
91
|
+
const director = new WalletDirector(rustPath)
|
|
92
|
+
|
|
93
|
+
// Generate a mnemonic
|
|
94
|
+
const words = await director.generateMnemonic()
|
|
95
|
+
console.log('Mnemonic:', words.join(' '))
|
|
96
|
+
|
|
97
|
+
// Create a wallet and join a federation
|
|
98
|
+
const wallet = await director.createWallet()
|
|
99
|
+
await wallet.joinFederation(inviteCode)
|
|
100
|
+
|
|
101
|
+
// Use wallet methods
|
|
102
|
+
const balance = await wallet.balance.getBalance()
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Plugin Options
|
|
106
|
+
|
|
107
|
+
This is required for Expo managed workflow.
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"expo": {
|
|
112
|
+
"plugins": [
|
|
113
|
+
[
|
|
114
|
+
"@fedimint/react-native",
|
|
115
|
+
{
|
|
116
|
+
"skipBinaryDownload": false
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Building from Source
|
|
125
|
+
|
|
126
|
+
You can choose to build the SDK from scratch (recompile from source) and skip the automatic binary download during installation by:
|
|
127
|
+
|
|
128
|
+
1. **Using an environment variable:**
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
FEDIMINT_SKIP_BINARY_DOWNLOAD=true npm install @fedimint/react-native
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
2. **Using the Expo plugin option** (for Expo projects):
|
|
135
|
+
Set `"skipBinaryDownload": true` in the plugin options above.
|
|
136
|
+
|
|
137
|
+
This is useful when you want to handle binary downloads manually or are building from source.
|
|
138
|
+
|
|
139
|
+
## Requirements
|
|
140
|
+
|
|
141
|
+
| React Native | Support |
|
|
142
|
+
| --------------- | -------------- |
|
|
143
|
+
| 0.78.x - 0.82.x | ✅ Supported |
|
|
144
|
+
| 0.83.x | ✅ Recommended |
|
|
145
|
+
|
|
146
|
+
| Platform | Minimum Version |
|
|
147
|
+
| -------- | -------------------- |
|
|
148
|
+
| Android | API 24 (Android 7.0) |
|
|
149
|
+
| iOS | 15.0 |
|
|
150
|
+
|
|
151
|
+
| Expo SDK | Support |
|
|
152
|
+
| -------- | ---------------- |
|
|
153
|
+
| 52+ | ✅ With plugins |
|
|
154
|
+
| Expo Go | ❌ Not supported |
|
|
155
|
+
|
|
156
|
+
## Exports
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// Default export - simplified WalletDirector
|
|
160
|
+
import WalletDirector from '@fedimint/react-native'
|
|
161
|
+
|
|
162
|
+
// Named exports for advanced usage
|
|
163
|
+
import {
|
|
164
|
+
WalletDirector, // Class with built-in transport
|
|
165
|
+
ReactNativeTransport, // Transport layer (for custom setups)
|
|
166
|
+
TransportClient, // Low-level client
|
|
167
|
+
} from '@fedimint/react-native'
|
|
168
|
+
|
|
169
|
+
// Types
|
|
170
|
+
import type { FedimintWallet } from '@fedimint/react-native'
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ReactNativeTransport = void 0;
|
|
7
|
+
var _types = require("@fedimint/types");
|
|
8
|
+
var _reactNativeBindings = require("@fedimint/react-native-bindings");
|
|
9
|
+
class ReactNativeTransport extends _types.Transport {
|
|
10
|
+
logger = console;
|
|
11
|
+
constructor(dbPath) {
|
|
12
|
+
super();
|
|
13
|
+
if (!dbPath) {
|
|
14
|
+
throw new Error('ReactNativeTransport requires a dbPath');
|
|
15
|
+
}
|
|
16
|
+
this.rpcHandler = new _reactNativeBindings.RpcHandler(dbPath);
|
|
17
|
+
}
|
|
18
|
+
async postMessage(message) {
|
|
19
|
+
console.log('ReactNativeTransport postMessage received:', JSON.stringify(message));
|
|
20
|
+
const {
|
|
21
|
+
type,
|
|
22
|
+
payload,
|
|
23
|
+
requestId
|
|
24
|
+
} = message;
|
|
25
|
+
try {
|
|
26
|
+
// Handle init - just respond with success since we initialized in constructor
|
|
27
|
+
if (type === 'init') {
|
|
28
|
+
this.messageHandler({
|
|
29
|
+
type: 'data',
|
|
30
|
+
request_id: message.requestId,
|
|
31
|
+
data: true
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (type === 'set_mnemonic' || type === 'generate_mnemonic' || type === 'get_mnemonic' || type === 'join_federation' || type === 'open_client' || type === 'close_client' || type === 'client_rpc' || type === 'cancel_rpc' || type === 'parse_invite_code' || type === 'parse_bolt11_invoice' || type === 'preview_federation' || type === 'parse_oob_notes' || type === 'has_mnemonic_set') {
|
|
36
|
+
const rustRequest = {
|
|
37
|
+
type: type,
|
|
38
|
+
request_id: requestId,
|
|
39
|
+
payload: payload ?? null
|
|
40
|
+
};
|
|
41
|
+
const json = JSON.stringify(rustRequest);
|
|
42
|
+
console.log('ReactNativeTransport sending RPC:', json);
|
|
43
|
+
const responseStr = await new Promise((resolve, reject) => {
|
|
44
|
+
try {
|
|
45
|
+
const callback = {
|
|
46
|
+
onResponse: response => {
|
|
47
|
+
resolve(response);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
this.rpcHandler.rpc(json, callback);
|
|
51
|
+
} catch (e) {
|
|
52
|
+
reject(e);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
console.log('ReactNativeTransport RPC raw response:', responseStr);
|
|
56
|
+
const response = JSON.parse(responseStr);
|
|
57
|
+
console.log('ReactNativeTransport RPC parsed response:', JSON.stringify(response));
|
|
58
|
+
if (response.type === 'error') {
|
|
59
|
+
throw new Error(response.error || 'Unknown RPC error');
|
|
60
|
+
}
|
|
61
|
+
this.messageHandler(response);
|
|
62
|
+
} else if (type === 'cleanup') {
|
|
63
|
+
console.log('cleanup message received');
|
|
64
|
+
this.rpcHandler.uniffiDestroy();
|
|
65
|
+
} else {
|
|
66
|
+
this.logger.error('Unknown message type', type);
|
|
67
|
+
this.errorHandler('Unknown message type');
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
this.logger.error('RPC Error', error);
|
|
71
|
+
this.messageHandler({
|
|
72
|
+
type: 'error',
|
|
73
|
+
error: error instanceof Error ? error.message : String(error),
|
|
74
|
+
request_id: requestId
|
|
75
|
+
});
|
|
76
|
+
this.errorHandler(error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.ReactNativeTransport = ReactNativeTransport;
|
|
81
|
+
//# sourceMappingURL=ReactNativeTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_types","require","_reactNativeBindings","ReactNativeTransport","Transport","logger","console","constructor","dbPath","Error","rpcHandler","RpcHandler","postMessage","message","log","JSON","stringify","type","payload","requestId","messageHandler","request_id","data","rustRequest","json","responseStr","Promise","resolve","reject","callback","onResponse","response","rpc","e","parse","error","uniffiDestroy","errorHandler","String","exports"],"sourceRoot":"../../src","sources":["ReactNativeTransport.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAMA,IAAAC,oBAAA,GAAAD,OAAA;AAEO,MAAME,oBAAoB,SAASC,gBAAS,CAAC;EAClDC,MAAM,GAAoBC,OAAO;EAGjCC,WAAWA,CAACC,MAAc,EAAE;IAC1B,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,MAAM,EAAE;MACX,MAAM,IAAIC,KAAK,CAAC,wCAAwC,CAAC;IAC3D;IACA,IAAI,CAACC,UAAU,GAAG,IAAIC,+BAAU,CAACH,MAAM,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A","ignoreList":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ReactNativeTransport", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _ReactNativeTransport.ReactNativeTransport;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "TransportClient", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _core.TransportClient;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
exports.default = exports.WalletDirector = void 0;
|
|
19
|
+
var _ReactNativeTransport = require("./ReactNativeTransport.js");
|
|
20
|
+
var _core = require("@fedimint/core");
|
|
21
|
+
/**
|
|
22
|
+
* WalletDirector for React Native.
|
|
23
|
+
* Automatically uses ReactNativeTransport under the hood.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import WalletDirector from '@fedimint/react-native';
|
|
28
|
+
* import RNFS from 'react-native-fs';
|
|
29
|
+
*
|
|
30
|
+
* const dbPath = `${RNFS.DocumentDirectoryPath}/fedimint_db`;
|
|
31
|
+
* const director = new WalletDirector(dbPath);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
class WalletDirector extends _core.WalletDirector {
|
|
35
|
+
constructor(dbPath, lazy = false) {
|
|
36
|
+
const transport = new _ReactNativeTransport.ReactNativeTransport(dbPath);
|
|
37
|
+
super(transport, dbPath, lazy);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Default export for simple usage: import WalletDirector from '@fedimint/react-native'
|
|
42
|
+
exports.WalletDirector = WalletDirector;
|
|
43
|
+
var _default = exports.default = WalletDirector; // Named exports for advanced users
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_ReactNativeTransport","require","_core","WalletDirector","BaseWalletDirector","constructor","dbPath","lazy","transport","ReactNativeTransport","exports","_default","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,cAAc,SAASC,oBAAkB,CAAC;EACrDC,WAAWA,CAACC,MAAc,EAAEC,IAAa,GAAG,KAAK,EAAE;IACjD,MAAMC,SAAS,GAAG,IAAIC,0CAAoB,CAACH,MAAM,CAAC;IAClD,KAAK,CAACE,SAAS,EAAEF,MAAM,EAAEC,IAAI,CAAC;EAChC;AACF;;AAEA;AAAAG,OAAA,CAAAP,cAAA,GAAAA,cAAA;AAAA,IAAAQ,QAAA,GAAAD,OAAA,CAAAE,OAAA,GACeT,cAAc,EAE7B","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Transport } from '@fedimint/types';
|
|
4
|
+
import { RpcHandler } from '@fedimint/react-native-bindings';
|
|
5
|
+
export class ReactNativeTransport extends Transport {
|
|
6
|
+
logger = console;
|
|
7
|
+
constructor(dbPath) {
|
|
8
|
+
super();
|
|
9
|
+
if (!dbPath) {
|
|
10
|
+
throw new Error('ReactNativeTransport requires a dbPath');
|
|
11
|
+
}
|
|
12
|
+
this.rpcHandler = new RpcHandler(dbPath);
|
|
13
|
+
}
|
|
14
|
+
async postMessage(message) {
|
|
15
|
+
console.log('ReactNativeTransport postMessage received:', JSON.stringify(message));
|
|
16
|
+
const {
|
|
17
|
+
type,
|
|
18
|
+
payload,
|
|
19
|
+
requestId
|
|
20
|
+
} = message;
|
|
21
|
+
try {
|
|
22
|
+
// Handle init - just respond with success since we initialized in constructor
|
|
23
|
+
if (type === 'init') {
|
|
24
|
+
this.messageHandler({
|
|
25
|
+
type: 'data',
|
|
26
|
+
request_id: message.requestId,
|
|
27
|
+
data: true
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (type === 'set_mnemonic' || type === 'generate_mnemonic' || type === 'get_mnemonic' || type === 'join_federation' || type === 'open_client' || type === 'close_client' || type === 'client_rpc' || type === 'cancel_rpc' || type === 'parse_invite_code' || type === 'parse_bolt11_invoice' || type === 'preview_federation' || type === 'parse_oob_notes' || type === 'has_mnemonic_set') {
|
|
32
|
+
const rustRequest = {
|
|
33
|
+
type: type,
|
|
34
|
+
request_id: requestId,
|
|
35
|
+
payload: payload ?? null
|
|
36
|
+
};
|
|
37
|
+
const json = JSON.stringify(rustRequest);
|
|
38
|
+
console.log('ReactNativeTransport sending RPC:', json);
|
|
39
|
+
const responseStr = await new Promise((resolve, reject) => {
|
|
40
|
+
try {
|
|
41
|
+
const callback = {
|
|
42
|
+
onResponse: response => {
|
|
43
|
+
resolve(response);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
this.rpcHandler.rpc(json, callback);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
reject(e);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
console.log('ReactNativeTransport RPC raw response:', responseStr);
|
|
52
|
+
const response = JSON.parse(responseStr);
|
|
53
|
+
console.log('ReactNativeTransport RPC parsed response:', JSON.stringify(response));
|
|
54
|
+
if (response.type === 'error') {
|
|
55
|
+
throw new Error(response.error || 'Unknown RPC error');
|
|
56
|
+
}
|
|
57
|
+
this.messageHandler(response);
|
|
58
|
+
} else if (type === 'cleanup') {
|
|
59
|
+
console.log('cleanup message received');
|
|
60
|
+
this.rpcHandler.uniffiDestroy();
|
|
61
|
+
} else {
|
|
62
|
+
this.logger.error('Unknown message type', type);
|
|
63
|
+
this.errorHandler('Unknown message type');
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
this.logger.error('RPC Error', error);
|
|
67
|
+
this.messageHandler({
|
|
68
|
+
type: 'error',
|
|
69
|
+
error: error instanceof Error ? error.message : String(error),
|
|
70
|
+
request_id: requestId
|
|
71
|
+
});
|
|
72
|
+
this.errorHandler(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=ReactNativeTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Transport","RpcHandler","ReactNativeTransport","logger","console","constructor","dbPath","Error","rpcHandler","postMessage","message","log","JSON","stringify","type","payload","requestId","messageHandler","request_id","data","rustRequest","json","responseStr","Promise","resolve","reject","callback","onResponse","response","rpc","e","parse","error","uniffiDestroy","errorHandler","String"],"sourceRoot":"../../src","sources":["ReactNativeTransport.ts"],"mappings":";;AAAA,SACEA,SAAS,QAGJ,iBAAiB;AAExB,SAASC,UAAU,QAAQ,iCAAiC;AAE5D,OAAO,MAAMC,oBAAoB,SAASF,SAAS,CAAC;EAClDG,MAAM,GAAoBC,OAAO;EAGjCC,WAAWA,CAACC,MAAc,EAAE;IAC1B,KAAK,CAAC,CAAC;IACP,IAAI,CAACA,MAAM,EAAE;MACX,MAAM,IAAIC,KAAK,CAAC,wCAAwC,CAAC;IAC3D;IACA,IAAI,CAACC,UAAU,GAAG,IAAIP,UAAU,CAACK,MAAM,CAAC;EAC1C;EAEA,MAAMG,WAAWA,CAACC,OAAyB,EAAiB;IAC1DN,OAAO,CAACO,GAAG,CACT,4CAA4C,EAC5CC,IAAI,CAACC,SAAS,CAACH,OAAO,CACxB,CAAC;IACD,MAAM;MAAEI,IAAI;MAAEC,OAAO;MAAEC;IAAU,CAAC,GAAGN,OAAO;IAC5C,IAAI;MACF;MACA,IAAII,IAAI,KAAK,MAAM,EAAE;QACnB,IAAI,CAACG,cAAc,CAAC;UAClBH,IAAI,EAAE,MAAM;UACZI,U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S,CAACe,QAAQ,CACzB,CAAC;QACD,IAAIA,QAAQ,CAACd,IAAI,KAAK,OAAO,EAAE;UAC7B,MAAM,IAAIP,KAAK,CAACqB,QAAQ,CAACI,KAAK,IAAI,mBAAmB,CAAC;QACxD;QAEA,IAAI,CAACf,cAAc,CAACW,QAAQ,CAAC;MAC/B,CAAC,MAAM,IAAId,IAAI,KAAK,SAAS,EAAE;QAC7BV,OAAO,CAACO,GAAG,CAAC,0BAA0B,CAAC;QACvC,IAAI,CAACH,UAAU,CAACyB,aAAa,CAAC,CAAC;MACjC,CAAC,MAAM;QACL,IAAI,CAAC9B,MAAM,CAAC6B,KAAK,CAAC,sBAAsB,EAAElB,IAAI,CAAC;QAC/C,IAAI,CAACoB,YAAY,CAAC,sBAAsB,CAAC;MAC3C;IACF,CAAC,CAAC,OAAOF,KAAK,EAAE;MACd,IAAI,CAAC7B,MAAM,CAAC6B,KAAK,CAAC,WAAW,EAAEA,KAAK,CAAC;MACrC,IAAI,CAACf,cAAc,CAAC;QAClBH,IAAI,EAAE,OAAO;QACbkB,KAAK,EAAEA,KAAK,YAAYzB,KAAK,GAAGyB,KAAK,CAACtB,OAAO,GAAGyB,MAAM,CAACH,KAAK,CAAC;QAC7Dd,UAAU,EAAEF;MACd,CAAC,CAAC;MACF,IAAI,CAACkB,YAAY,CAACF,KAAK,CAAC;IAC1B;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { ReactNativeTransport } from "./ReactNativeTransport.js";
|
|
4
|
+
import { WalletDirector as BaseWalletDirector, TransportClient } from '@fedimint/core';
|
|
5
|
+
/**
|
|
6
|
+
* WalletDirector for React Native.
|
|
7
|
+
* Automatically uses ReactNativeTransport under the hood.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import WalletDirector from '@fedimint/react-native';
|
|
12
|
+
* import RNFS from 'react-native-fs';
|
|
13
|
+
*
|
|
14
|
+
* const dbPath = `${RNFS.DocumentDirectoryPath}/fedimint_db`;
|
|
15
|
+
* const director = new WalletDirector(dbPath);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class WalletDirector extends BaseWalletDirector {
|
|
19
|
+
constructor(dbPath, lazy = false) {
|
|
20
|
+
const transport = new ReactNativeTransport(dbPath);
|
|
21
|
+
super(transport, dbPath, lazy);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Default export for simple usage: import WalletDirector from '@fedimint/react-native'
|
|
26
|
+
export default WalletDirector;
|
|
27
|
+
|
|
28
|
+
// Named exports for advanced users
|
|
29
|
+
export { ReactNativeTransport, TransportClient };
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ReactNativeTransport","WalletDirector","BaseWalletDirector","TransportClient","constructor","dbPath","lazy","transport"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,oBAAoB,QAAQ,2BAAwB;AAC7D,SACEC,cAAc,IAAIC,kBAAkB,EACpCC,eAAe,QACV,gBAAgB;AAGvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMF,cAAc,SAASC,kBAAkB,CAAC;EACrDE,WAAWA,CAACC,MAAc,EAAEC,IAAa,GAAG,KAAK,EAAE;IACjD,MAAMC,SAAS,GAAG,IAAIP,oBAAoB,CAACK,MAAM,CAAC;IAClD,KAAK,CAACE,SAAS,EAAEF,MAAM,EAAEC,IAAI,CAAC;EAChC;AACF;;AAEA;AACA,eAAeL,cAAc;;AAE7B;AACA,SAASD,oBAAoB,EAAEG,eAAe","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Transport, type TransportLogger, type TransportRequest } from '@fedimint/types';
|
|
2
|
+
export declare class ReactNativeTransport extends Transport {
|
|
3
|
+
logger: TransportLogger;
|
|
4
|
+
private rpcHandler;
|
|
5
|
+
constructor(dbPath: string);
|
|
6
|
+
postMessage(message: TransportRequest): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=ReactNativeTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactNativeTransport.d.ts","sourceRoot":"","sources":["../../../src/ReactNativeTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAA;AAIxB,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,MAAM,EAAE,eAAe,CAAU;IACjC,OAAO,CAAC,UAAU,CAAY;gBAElB,MAAM,EAAE,MAAM;IAQpB,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAiF5D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReactNativeTransport } from './ReactNativeTransport';
|
|
2
|
+
import { WalletDirector as BaseWalletDirector, TransportClient } from '@fedimint/core';
|
|
3
|
+
import type { FedimintWallet } from '@fedimint/core';
|
|
4
|
+
/**
|
|
5
|
+
* WalletDirector for React Native.
|
|
6
|
+
* Automatically uses ReactNativeTransport under the hood.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import WalletDirector from '@fedimint/react-native';
|
|
11
|
+
* import RNFS from 'react-native-fs';
|
|
12
|
+
*
|
|
13
|
+
* const dbPath = `${RNFS.DocumentDirectoryPath}/fedimint_db`;
|
|
14
|
+
* const director = new WalletDirector(dbPath);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class WalletDirector extends BaseWalletDirector {
|
|
18
|
+
constructor(dbPath: string, lazy?: boolean);
|
|
19
|
+
}
|
|
20
|
+
export default WalletDirector;
|
|
21
|
+
export { ReactNativeTransport, TransportClient };
|
|
22
|
+
export type { FedimintWallet };
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EACL,cAAc,IAAI,kBAAkB,EACpC,eAAe,EAChB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAe,SAAQ,kBAAkB;gBACxC,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,OAAe;CAIlD;AAGD,eAAe,cAAc,CAAA;AAG7B,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,CAAA;AAChD,YAAY,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Transport, type TransportLogger, type TransportRequest } from '@fedimint/types';
|
|
2
|
+
export declare class ReactNativeTransport extends Transport {
|
|
3
|
+
logger: TransportLogger;
|
|
4
|
+
private rpcHandler;
|
|
5
|
+
constructor(dbPath: string);
|
|
6
|
+
postMessage(message: TransportRequest): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=ReactNativeTransport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactNativeTransport.d.ts","sourceRoot":"","sources":["../../../src/ReactNativeTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAA;AAIxB,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,MAAM,EAAE,eAAe,CAAU;IACjC,OAAO,CAAC,UAAU,CAAY;gBAElB,MAAM,EAAE,MAAM;IAQpB,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAiF5D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReactNativeTransport } from './ReactNativeTransport';
|
|
2
|
+
import { WalletDirector as BaseWalletDirector, TransportClient } from '@fedimint/core';
|
|
3
|
+
import type { FedimintWallet } from '@fedimint/core';
|
|
4
|
+
/**
|
|
5
|
+
* WalletDirector for React Native.
|
|
6
|
+
* Automatically uses ReactNativeTransport under the hood.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import WalletDirector from '@fedimint/react-native';
|
|
11
|
+
* import RNFS from 'react-native-fs';
|
|
12
|
+
*
|
|
13
|
+
* const dbPath = `${RNFS.DocumentDirectoryPath}/fedimint_db`;
|
|
14
|
+
* const director = new WalletDirector(dbPath);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class WalletDirector extends BaseWalletDirector {
|
|
18
|
+
constructor(dbPath: string, lazy?: boolean);
|
|
19
|
+
}
|
|
20
|
+
export default WalletDirector;
|
|
21
|
+
export { ReactNativeTransport, TransportClient };
|
|
22
|
+
export type { FedimintWallet };
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EACL,cAAc,IAAI,kBAAkB,EACpC,eAAe,EAChB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAe,SAAQ,kBAAkB;gBACxC,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,OAAe;CAIlD;AAGD,eAAe,cAAc,CAAA;AAG7B,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,CAAA;AAChD,YAAY,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fedimint/react-native",
|
|
3
|
+
"description": "React Native SDKfor the Fedimint client",
|
|
4
|
+
"version": "0.0.0-canary-ecde932b329972ca4c9b8b6c8a28f709edb957c0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/fedimint/fedimint-sdk.git",
|
|
8
|
+
"directory": "packages/react-native"
|
|
9
|
+
},
|
|
10
|
+
"main": "./lib/commonjs/index.js",
|
|
11
|
+
"module": "./lib/module/index.js",
|
|
12
|
+
"types": "./lib/typescript/commonjs/index.d.ts",
|
|
13
|
+
"react-native": "./src/index.ts",
|
|
14
|
+
"source": "./src/index.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"source": "./src/index.ts",
|
|
18
|
+
"types": "./lib/typescript/commonjs/index.d.ts",
|
|
19
|
+
"default": "./lib/module/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./app.plugin.js": "./app.plugin.js",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"src",
|
|
26
|
+
"lib",
|
|
27
|
+
"app.plugin.js"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@fedimint/types": "0.0.0-canary-ecde932b329972ca4c9b8b6c8a28f709edb957c0",
|
|
31
|
+
"@fedimint/core": "0.0.0-canary-ecde932b329972ca4c9b8b6c8a28f709edb957c0",
|
|
32
|
+
"@fedimint/react-native-bindings": "0.0.0-canary-ecde932b329972ca4c9b8b6c8a28f709edb957c0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"react": ">=18.0.0",
|
|
36
|
+
"react-native": ">=0.78.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@expo/config-plugins": "^54.0.4",
|
|
40
|
+
"@types/node": "^22.19.11",
|
|
41
|
+
"expo-module-scripts": "^5.0.8",
|
|
42
|
+
"react-native-builder-bob": "^0.40.18",
|
|
43
|
+
"typescript": "^5.9.3"
|
|
44
|
+
},
|
|
45
|
+
"react-native-builder-bob": {
|
|
46
|
+
"source": "src",
|
|
47
|
+
"output": "lib",
|
|
48
|
+
"targets": [
|
|
49
|
+
[
|
|
50
|
+
"commonjs",
|
|
51
|
+
{
|
|
52
|
+
"esm": true
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
"module",
|
|
57
|
+
{
|
|
58
|
+
"esm": true
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"typescript"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "bob build",
|
|
66
|
+
"clean": "rm -rf lib tsconfig.tsbuildinfo",
|
|
67
|
+
"clean:deep": "pnpm run clean && rm -rf node_modules",
|
|
68
|
+
"typecheck": "tsc --noEmit"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Transport,
|
|
3
|
+
type TransportLogger,
|
|
4
|
+
type TransportRequest,
|
|
5
|
+
} from '@fedimint/types'
|
|
6
|
+
|
|
7
|
+
import { RpcHandler } from '@fedimint/react-native-bindings'
|
|
8
|
+
|
|
9
|
+
export class ReactNativeTransport extends Transport {
|
|
10
|
+
logger: TransportLogger = console
|
|
11
|
+
private rpcHandler: RpcHandler
|
|
12
|
+
|
|
13
|
+
constructor(dbPath: string) {
|
|
14
|
+
super()
|
|
15
|
+
if (!dbPath) {
|
|
16
|
+
throw new Error('ReactNativeTransport requires a dbPath')
|
|
17
|
+
}
|
|
18
|
+
this.rpcHandler = new RpcHandler(dbPath)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async postMessage(message: TransportRequest): Promise<void> {
|
|
22
|
+
console.log(
|
|
23
|
+
'ReactNativeTransport postMessage received:',
|
|
24
|
+
JSON.stringify(message),
|
|
25
|
+
)
|
|
26
|
+
const { type, payload, requestId } = message
|
|
27
|
+
try {
|
|
28
|
+
// Handle init - just respond with success since we initialized in constructor
|
|
29
|
+
if (type === 'init') {
|
|
30
|
+
this.messageHandler({
|
|
31
|
+
type: 'data',
|
|
32
|
+
request_id: message.requestId,
|
|
33
|
+
data: true,
|
|
34
|
+
})
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (
|
|
39
|
+
type === 'set_mnemonic' ||
|
|
40
|
+
type === 'generate_mnemonic' ||
|
|
41
|
+
type === 'get_mnemonic' ||
|
|
42
|
+
type === 'join_federation' ||
|
|
43
|
+
type === 'open_client' ||
|
|
44
|
+
type === 'close_client' ||
|
|
45
|
+
type === 'client_rpc' ||
|
|
46
|
+
type === 'cancel_rpc' ||
|
|
47
|
+
type === 'parse_invite_code' ||
|
|
48
|
+
type === 'parse_bolt11_invoice' ||
|
|
49
|
+
type === 'preview_federation' ||
|
|
50
|
+
type === 'parse_oob_notes' ||
|
|
51
|
+
type === 'has_mnemonic_set'
|
|
52
|
+
) {
|
|
53
|
+
const rustRequest = {
|
|
54
|
+
type: type,
|
|
55
|
+
request_id: requestId,
|
|
56
|
+
payload: payload ?? null,
|
|
57
|
+
}
|
|
58
|
+
const json = JSON.stringify(rustRequest)
|
|
59
|
+
console.log('ReactNativeTransport sending RPC:', json)
|
|
60
|
+
|
|
61
|
+
const responseStr = await new Promise<string>((resolve, reject) => {
|
|
62
|
+
try {
|
|
63
|
+
const callback = {
|
|
64
|
+
onResponse: (response: string) => {
|
|
65
|
+
resolve(response)
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
this.rpcHandler.rpc(json, callback)
|
|
69
|
+
} catch (e) {
|
|
70
|
+
reject(e)
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
console.log('ReactNativeTransport RPC raw response:', responseStr)
|
|
74
|
+
|
|
75
|
+
const response = JSON.parse(responseStr)
|
|
76
|
+
console.log(
|
|
77
|
+
'ReactNativeTransport RPC parsed response:',
|
|
78
|
+
JSON.stringify(response),
|
|
79
|
+
)
|
|
80
|
+
if (response.type === 'error') {
|
|
81
|
+
throw new Error(response.error || 'Unknown RPC error')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this.messageHandler(response)
|
|
85
|
+
} else if (type === 'cleanup') {
|
|
86
|
+
console.log('cleanup message received')
|
|
87
|
+
this.rpcHandler.uniffiDestroy()
|
|
88
|
+
} else {
|
|
89
|
+
this.logger.error('Unknown message type', type)
|
|
90
|
+
this.errorHandler('Unknown message type')
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
this.logger.error('RPC Error', error)
|
|
94
|
+
this.messageHandler({
|
|
95
|
+
type: 'error',
|
|
96
|
+
error: error instanceof Error ? error.message : String(error),
|
|
97
|
+
request_id: requestId,
|
|
98
|
+
})
|
|
99
|
+
this.errorHandler(error)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ReactNativeTransport } from './ReactNativeTransport'
|
|
2
|
+
import {
|
|
3
|
+
WalletDirector as BaseWalletDirector,
|
|
4
|
+
TransportClient,
|
|
5
|
+
} from '@fedimint/core'
|
|
6
|
+
import type { FedimintWallet } from '@fedimint/core'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* WalletDirector for React Native.
|
|
10
|
+
* Automatically uses ReactNativeTransport under the hood.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import WalletDirector from '@fedimint/react-native';
|
|
15
|
+
* import RNFS from 'react-native-fs';
|
|
16
|
+
*
|
|
17
|
+
* const dbPath = `${RNFS.DocumentDirectoryPath}/fedimint_db`;
|
|
18
|
+
* const director = new WalletDirector(dbPath);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class WalletDirector extends BaseWalletDirector {
|
|
22
|
+
constructor(dbPath: string, lazy: boolean = false) {
|
|
23
|
+
const transport = new ReactNativeTransport(dbPath)
|
|
24
|
+
super(transport, dbPath, lazy)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Default export for simple usage: import WalletDirector from '@fedimint/react-native'
|
|
29
|
+
export default WalletDirector
|
|
30
|
+
|
|
31
|
+
// Named exports for advanced users
|
|
32
|
+
export { ReactNativeTransport, TransportClient }
|
|
33
|
+
export type { FedimintWallet }
|