@getpara/react-native-wallet 0.1.0

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 (57) hide show
  1. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  2. package/android/.gradle/8.9/checksums/md5-checksums.bin +0 -0
  3. package/android/.gradle/8.9/checksums/sha1-checksums.bin +0 -0
  4. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  5. package/android/.gradle/8.9/executionHistory/executionHistory.lock +0 -0
  6. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  7. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  8. package/android/.gradle/8.9/gc.properties +0 -0
  9. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  10. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  11. package/android/.gradle/vcs-1/gc.properties +0 -0
  12. package/android/build.gradle +76 -0
  13. package/android/gradle.properties +5 -0
  14. package/android/src/main/AndroidManifest.xml +4 -0
  15. package/android/src/main/java/com/para/reactnativewallet/ParaSignerModule.java +294 -0
  16. package/android/src/main/java/com/para/reactnativewallet/ParaSignerPackage.java +30 -0
  17. package/capsule-react-native-wallet.podspec +36 -0
  18. package/dist/AsyncStorage.d.ts +10 -0
  19. package/dist/AsyncStorage.js +41 -0
  20. package/dist/KeychainStorage.d.ts +10 -0
  21. package/dist/KeychainStorage.js +72 -0
  22. package/dist/config.d.ts +7 -0
  23. package/dist/config.js +61 -0
  24. package/dist/index.d.ts +2 -0
  25. package/dist/index.js +2 -0
  26. package/dist/react-native/ParaMobile.d.ts +49 -0
  27. package/dist/react-native/ParaMobile.js +237 -0
  28. package/dist/react-native/ReactNativeUtils.d.ts +50 -0
  29. package/dist/react-native/ReactNativeUtils.js +171 -0
  30. package/dist/shim.d.ts +1 -0
  31. package/dist/shim.js +49 -0
  32. package/ios/ParaSignerModule.h +12 -0
  33. package/ios/ParaSignerModule.m +411 -0
  34. package/ios/ReactNativeWallet.xcodeproj/project.pbxproj +269 -0
  35. package/package.json +63 -0
  36. package/signer.xcframework/Info.plist +44 -0
  37. package/signer.xcframework/ios-arm64/Signer.framework/Headers/Signer.h +13 -0
  38. package/signer.xcframework/ios-arm64/Signer.framework/Headers/Signer.objc.h +300 -0
  39. package/signer.xcframework/ios-arm64/Signer.framework/Headers/Universe.objc.h +29 -0
  40. package/signer.xcframework/ios-arm64/Signer.framework/Headers/ref.h +35 -0
  41. package/signer.xcframework/ios-arm64/Signer.framework/Info.plist +18 -0
  42. package/signer.xcframework/ios-arm64/Signer.framework/Modules/module.modulemap +8 -0
  43. package/signer.xcframework/ios-arm64/Signer.framework/Signer +0 -0
  44. package/signer.xcframework/ios-arm64_x86_64-simulator/Signer.framework/Headers/Signer.h +13 -0
  45. package/signer.xcframework/ios-arm64_x86_64-simulator/Signer.framework/Headers/Signer.objc.h +300 -0
  46. package/signer.xcframework/ios-arm64_x86_64-simulator/Signer.framework/Headers/Universe.objc.h +29 -0
  47. package/signer.xcframework/ios-arm64_x86_64-simulator/Signer.framework/Headers/ref.h +35 -0
  48. package/signer.xcframework/ios-arm64_x86_64-simulator/Signer.framework/Info.plist +18 -0
  49. package/signer.xcframework/ios-arm64_x86_64-simulator/Signer.framework/Modules/module.modulemap +8 -0
  50. package/signer.xcframework/ios-arm64_x86_64-simulator/Signer.framework/Signer +0 -0
  51. package/src/AsyncStorage.ts +30 -0
  52. package/src/KeychainStorage.ts +61 -0
  53. package/src/config.ts +70 -0
  54. package/src/index.tsx +2 -0
  55. package/src/react-native/ParaMobile.ts +294 -0
  56. package/src/react-native/ReactNativeUtils.ts +266 -0
  57. package/src/shim.js +59 -0
@@ -0,0 +1,300 @@
1
+ // Objective-C API for talking to github.com/capsule-org/go-sdk/signer Go package.
2
+ // gobind -lang=objc github.com/capsule-org/go-sdk/signer
3
+ //
4
+ // File is generated by gobind. Do not edit.
5
+
6
+ #ifndef __Signer_H__
7
+ #define __Signer_H__
8
+
9
+ @import Foundation;
10
+ #include "ref.h"
11
+ #include "Universe.objc.h"
12
+
13
+
14
+ @class SignerDKLSSerializableSigner;
15
+ @class SignerDKLSSigner;
16
+ @class SignerED25519Signer;
17
+ @class SignerSerializableSigner;
18
+ @class SignerSigner;
19
+ @class SignerTransaction;
20
+ @protocol SignerTxData;
21
+
22
+ @interface SignerTxData : NSObject <goSeqRefInterface> {
23
+ }
24
+ @property(strong, readonly) _Nonnull id _ref;
25
+
26
+ - (nonnull instancetype)initWithRef:(_Nonnull id)ref;
27
+ @end
28
+
29
+ /**
30
+ * Flattened Signer that's gone through KEYGEN
31
+ */
32
+ @interface SignerDKLSSerializableSigner : NSObject <goSeqRefInterface> {
33
+ }
34
+ @property(strong, readonly) _Nonnull id _ref;
35
+
36
+ - (nonnull instancetype)initWithRef:(_Nonnull id)ref;
37
+ - (nonnull instancetype)init;
38
+ @property (nonatomic) NSString* _Nonnull walletId;
39
+ @property (nonatomic) NSString* _Nonnull id_;
40
+ @property (nonatomic) NSString* _Nonnull otherId;
41
+ @property (nonatomic) NSString* _Nonnull receiverConfig;
42
+ @property (nonatomic) NSString* _Nonnull senderConfig;
43
+ @property (nonatomic) BOOL isReceiver;
44
+ @property (nonatomic) BOOL disableWebSockets;
45
+ @end
46
+
47
+ @interface SignerDKLSSigner : NSObject <goSeqRefInterface> {
48
+ }
49
+ @property(strong, readonly) _Nonnull id _ref;
50
+
51
+ - (nonnull instancetype)initWithRef:(_Nonnull id)ref;
52
+ - (nonnull instancetype)init;
53
+ - (BOOL)createAccount:(NSString* _Nullable)protocolId useWebSocket:(BOOL)useWebSocket error:(NSError* _Nullable* _Nullable)error;
54
+ - (NSString* _Nonnull)getAddress:(NSError* _Nullable* _Nullable)error;
55
+ - (BOOL)getDisableWebSockets;
56
+ // skipped method DKLSSigner.GetOtherId with unsupported parameter or return types
57
+
58
+ // skipped method DKLSSigner.GetPartyId with unsupported parameter or return types
59
+
60
+ // skipped method DKLSSigner.GetPrivateKey with unsupported parameter or return types
61
+
62
+ - (NSString* _Nonnull)getPublicKey;
63
+ - (NSData* _Nullable)getReceiverConfig:(NSError* _Nullable* _Nullable)error;
64
+ // skipped method DKLSSigner.GetReceiverConfigStruct with unsupported parameter or return types
65
+
66
+ - (NSData* _Nullable)getSenderConfig:(NSError* _Nullable* _Nullable)error;
67
+ // skipped method DKLSSigner.GetSenderConfigStruct with unsupported parameter or return types
68
+
69
+ - (NSString* _Nonnull)getWalletId;
70
+ - (BOOL)refreshAccount:(NSString* _Nullable)protocolId useWebSocket:(BOOL)useWebSocket error:(NSError* _Nullable* _Nullable)error;
71
+ // skipped method DKLSSigner.SendTransaction with unsupported parameter or return types
72
+
73
+ // skipped method DKLSSigner.SetPool with unsupported parameter or return types
74
+
75
+ @end
76
+
77
+ @interface SignerED25519Signer : NSObject <goSeqRefInterface> {
78
+ }
79
+ @property(strong, readonly) _Nonnull id _ref;
80
+
81
+ - (nonnull instancetype)initWithRef:(_Nonnull id)ref;
82
+ - (nonnull instancetype)init;
83
+ // skipped field ED25519Signer.Id with unsupported type: github.com/taurusgroup/frost-ed25519/pkg/frost/party.ID
84
+
85
+ // skipped field ED25519Signer.OtherId with unsupported type: github.com/taurusgroup/frost-ed25519/pkg/frost/party.ID
86
+
87
+ // skipped field ED25519Signer.Output with unsupported type: *github.com/taurusgroup/frost-ed25519/pkg/frost/keygen.Output
88
+
89
+ @property (nonatomic) NSString* _Nonnull walletId;
90
+ @property (nonatomic) NSString* _Nonnull host;
91
+ - (BOOL)createAccount:(NSString* _Nullable)protocolId error:(NSError* _Nullable* _Nullable)error;
92
+ - (NSString* _Nonnull)getAddress;
93
+ // skipped method ED25519Signer.Sign with unsupported parameter or return types
94
+
95
+ @end
96
+
97
+ /**
98
+ * Flattened Signer that's gone through KEYGEN
99
+ */
100
+ @interface SignerSerializableSigner : NSObject <goSeqRefInterface> {
101
+ }
102
+ @property(strong, readonly) _Nonnull id _ref;
103
+
104
+ - (nonnull instancetype)initWithRef:(_Nonnull id)ref;
105
+ - (nonnull instancetype)init;
106
+ @property (nonatomic) NSString* _Nonnull walletId;
107
+ @property (nonatomic) NSString* _Nonnull id_;
108
+ // skipped field SerializableSigner.Ids with unsupported type: []string
109
+
110
+ @property (nonatomic) long threshold;
111
+ // skipped field SerializableSigner.Signers with unsupported type: []string
112
+
113
+ @property (nonatomic) NSString* _Nonnull config;
114
+ @end
115
+
116
+ @interface SignerSigner : NSObject <goSeqRefInterface> {
117
+ }
118
+ @property(strong, readonly) _Nonnull id _ref;
119
+
120
+ - (nonnull instancetype)initWithRef:(_Nonnull id)ref;
121
+ - (nonnull instancetype)init;
122
+ /**
123
+ * *
124
+ * Computes an ECDH shared secret between the user's private key and another user's public key
125
+ * @param account - the address of the account
126
+ * @param publicKey - another user's public key in base64
127
+ * @returns the shared secret
128
+ */
129
+ - (void)computeSharedSecret;
130
+ - (BOOL)createAccount:(NSString* _Nullable)protocolId useWebSocket:(BOOL)useWebSocket error:(NSError* _Nullable* _Nullable)error;
131
+ // skipped method Signer.CreateAccountV2 with unsupported parameter or return types
132
+
133
+ /**
134
+ * *
135
+ * Decrypts an ECIES ciphertext
136
+ * @param account - the address of the account
137
+ * @param ciphertext - the cipher to be decrypted
138
+ * @returns the decrypted text
139
+ */
140
+ - (void)decrypt;
141
+ - (NSString* _Nonnull)getAddress:(NSError* _Nullable* _Nullable)error;
142
+ - (NSData* _Nullable)getConfig:(NSError* _Nullable* _Nullable)error;
143
+ // skipped method Signer.GetPartyId with unsupported parameter or return types
144
+
145
+ // skipped method Signer.GetPartyIds with unsupported parameter or return types
146
+
147
+ - (NSString* _Nonnull)getPublicKey;
148
+ - (long)getThreshold;
149
+ - (NSString* _Nonnull)getWalletId;
150
+ - (BOOL)refreshAccount:(NSString* _Nullable)protocolId useWebSocket:(BOOL)useWebSocket error:(NSError* _Nullable* _Nullable)error;
151
+ // skipped method Signer.SendTransaction with unsupported parameter or return types
152
+
153
+ // skipped method Signer.SetPool with unsupported parameter or return types
154
+
155
+ /**
156
+ * *
157
+ * Sign arbitrary hash
158
+ * @param hashHex - input to sign encoded as a hex string
159
+ * @param signer - Address of the signer (must be unlocked)
160
+ */
161
+ - (void)signHash;
162
+ /**
163
+ * *
164
+ * Retrieve a session token for the account
165
+ *
166
+ */
167
+ - (BOOL)unlockAccount:(NSString* _Nullable)r1Signature error:(NSError* _Nullable* _Nullable)error;
168
+ @end
169
+
170
+ /**
171
+ * Source https://github.com/ethereum/go-ethereum/blob/master/core/types/transaction.go
172
+ */
173
+ @interface SignerTransaction : NSObject <goSeqRefInterface> {
174
+ }
175
+ @property(strong, readonly) _Nonnull id _ref;
176
+
177
+ - (nonnull instancetype)initWithRef:(_Nonnull id)ref;
178
+ - (nonnull instancetype)init;
179
+ @end
180
+
181
+ // skipped const ED25519CapsulePartyId with unsupported type: github.com/taurusgroup/frost-ed25519/pkg/frost/party.ID
182
+
183
+ // skipped const ED25519UserPartyId with unsupported type: github.com/taurusgroup/frost-ed25519/pkg/frost/party.ID
184
+
185
+
186
+ @interface Signer : NSObject
187
+ // skipped variable PARTY_IDS with unsupported type: github.com/taurusgroup/frost-ed25519/pkg/frost/party.IDSlice
188
+
189
+ @end
190
+
191
+ FOUNDATION_EXPORT NSString* _Nonnull SignerCreateAccount(NSString* _Nullable serverUrl, NSString* _Nullable serializedSigner, NSString* _Nullable protocolId);
192
+
193
+ // skipped function CreateProtocol with unsupported parameter or return types
194
+
195
+
196
+ // skipped function CreateWallet with unsupported parameter or return types
197
+
198
+
199
+ FOUNDATION_EXPORT NSString* _Nonnull SignerDKLSCreateAccount(NSString* _Nullable serverUrl, NSString* _Nullable serializedSigner, NSString* _Nullable protocolId);
200
+
201
+ // skipped function DKLSCreateProtocol with unsupported parameter or return types
202
+
203
+
204
+ // skipped function DKLSCreateWallet with unsupported parameter or return types
205
+
206
+
207
+ FOUNDATION_EXPORT SignerDKLSSigner* _Nullable SignerDKLSDeserializeSigner(NSString* _Nullable signerParamsStr, NSString* _Nullable serverUrl, NSError* _Nullable* _Nullable error);
208
+
209
+ FOUNDATION_EXPORT NSString* _Nonnull SignerDKLSGetAddress(NSString* _Nullable serializedSigner);
210
+
211
+ FOUNDATION_EXPORT NSString* _Nonnull SignerDKLSRefresh(NSString* _Nullable serverUrl, NSString* _Nullable serializedSigner, NSString* _Nullable protocolId);
212
+
213
+ /**
214
+ * *
215
+ * Sign a RLP-encoded transaction
216
+ * @param txRLPBase64 - The RLP encoded transaction in base64
217
+ * (base64 is easier to decode in native)
218
+ */
219
+ FOUNDATION_EXPORT NSString* _Nonnull SignerDKLSSendTransaction(NSString* _Nullable serverUrl, NSString* _Nullable serializedSigner, NSString* _Nullable txRLPBase64, NSString* _Nullable protocolId);
220
+
221
+ // skipped function DKLSSerializeSigner with unsupported parameter or return types
222
+
223
+
224
+ // skipped function DKLSSetNetworkClientTransport with unsupported parameter or return types
225
+
226
+
227
+ /**
228
+ * *
229
+ * Sign message
230
+ * @param message - The message encoded in base64
231
+ * (base64 is easier to decode in native)
232
+ */
233
+ FOUNDATION_EXPORT NSString* _Nonnull SignerDKLSSignMessage(NSString* _Nullable serverUrl, NSString* _Nullable serializedSigner, NSString* _Nullable message, NSString* _Nullable protocolId);
234
+
235
+ // skipped function DKLSSignerParamsFromStr with unsupported parameter or return types
236
+
237
+
238
+ FOUNDATION_EXPORT SignerSigner* _Nullable SignerDeserializeSigner(NSString* _Nullable signerParamsStr, NSString* _Nullable serverUrl, NSError* _Nullable* _Nullable error);
239
+
240
+ FOUNDATION_EXPORT NSString* _Nonnull SignerED25519CreateAccount(NSString* _Nullable mpcNetworkWSHost, NSString* _Nullable walletId, NSString* _Nullable protocolId);
241
+
242
+ FOUNDATION_EXPORT SignerED25519Signer* _Nullable SignerED25519DeserializeSigner(NSString* _Nullable serializedSigner, NSError* _Nullable* _Nullable error);
243
+
244
+ // skipped function ED25519NewSigner with unsupported parameter or return types
245
+
246
+
247
+ FOUNDATION_EXPORT NSString* _Nonnull SignerED25519SerializeSigner(SignerED25519Signer* _Nullable s, NSError* _Nullable* _Nullable error);
248
+
249
+ /**
250
+ * *
251
+ * Sign
252
+ * @param message - The bytes to sign encoded in base64
253
+ * (base64 is easier to decode in native)
254
+ */
255
+ FOUNDATION_EXPORT NSString* _Nonnull SignerED25519Sign(NSString* _Nullable serializedSigner, NSString* _Nullable base64BytesToSign, NSString* _Nullable protocolId);
256
+
257
+ FOUNDATION_EXPORT NSString* _Nonnull SignerGetAddress(NSString* _Nullable serializedSigner);
258
+
259
+ // skipped function NewDKLSSigner with unsupported parameter or return types
260
+
261
+
262
+ // skipped function NewSigner with unsupported parameter or return types
263
+
264
+
265
+ FOUNDATION_EXPORT NSString* _Nonnull SignerRefresh(NSString* _Nullable serverUrl, NSString* _Nullable serializedSigner, NSString* _Nullable protocolId);
266
+
267
+ /**
268
+ * *
269
+ * Sign a RLP-encoded transaction
270
+ * @param txRLPBase64 - The RLP encoded transaction in base64
271
+ * (base64 is easier to decode in native)
272
+ */
273
+ FOUNDATION_EXPORT NSString* _Nonnull SignerSendTransaction(NSString* _Nullable serverUrl, NSString* _Nullable serializedSigner, NSString* _Nullable txRLPBase64, NSString* _Nullable protocolId);
274
+
275
+ // skipped function SerializeSigner with unsupported parameter or return types
276
+
277
+
278
+ // skipped function SetNetworkClientTransport with unsupported parameter or return types
279
+
280
+
281
+ /**
282
+ * *
283
+ * Sign message
284
+ * @param message - The message encoded in base64
285
+ * (base64 is easier to decode in native)
286
+ */
287
+ FOUNDATION_EXPORT NSString* _Nonnull SignerSignMessage(NSString* _Nullable serverUrl, NSString* _Nullable serializedSigner, NSString* _Nullable message, NSString* _Nullable protocolId);
288
+
289
+ FOUNDATION_EXPORT SignerSerializableSigner* _Nullable SignerSignerParamsFromStr(NSString* _Nullable signerParamsStr, NSError* _Nullable* _Nullable error);
290
+
291
+ FOUNDATION_EXPORT NSData* _Nullable SignerTransactionBase64ToBytes(NSString* _Nullable tx, NSError* _Nullable* _Nullable error);
292
+
293
+ /**
294
+ * *
295
+ * Retrieve a session token for the account
296
+ *
297
+ */
298
+ FOUNDATION_EXPORT BOOL SignerUnlockAccount(NSString* _Nullable config, NSString* _Nullable r1Signature, NSError* _Nullable* _Nullable error);
299
+
300
+ #endif
@@ -0,0 +1,29 @@
1
+ // Objective-C API for talking to Go package.
2
+ // gobind -lang=objc
3
+ //
4
+ // File is generated by gobind. Do not edit.
5
+
6
+ #ifndef __Universe_H__
7
+ #define __Universe_H__
8
+
9
+ @import Foundation;
10
+ #include "ref.h"
11
+
12
+ @protocol Universeerror;
13
+ @class Universeerror;
14
+
15
+ @protocol Universeerror <NSObject>
16
+ - (NSString* _Nonnull)error;
17
+ @end
18
+
19
+ @class Universeerror;
20
+
21
+ @interface Universeerror : NSError <goSeqRefInterface, Universeerror> {
22
+ }
23
+ @property(strong, readonly) _Nonnull id _ref;
24
+
25
+ - (nonnull instancetype)initWithRef:(_Nonnull id)ref;
26
+ - (NSString* _Nonnull)error;
27
+ @end
28
+
29
+ #endif
@@ -0,0 +1,35 @@
1
+ // Copyright 2015 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ #ifndef __GO_REF_HDR__
6
+ #define __GO_REF_HDR__
7
+
8
+ #include <Foundation/Foundation.h>
9
+
10
+ // GoSeqRef is an object tagged with an integer for passing back and
11
+ // forth across the language boundary. A GoSeqRef may represent either
12
+ // an instance of a Go object, or an Objective-C object passed to Go.
13
+ // The explicit allocation of a GoSeqRef is used to pin a Go object
14
+ // when it is passed to Objective-C. The Go seq package maintains a
15
+ // reference to the Go object in a map keyed by the refnum along with
16
+ // a reference count. When the reference count reaches zero, the Go
17
+ // seq package will clear the corresponding entry in the map.
18
+ @interface GoSeqRef : NSObject {
19
+ }
20
+ @property(readonly) int32_t refnum;
21
+ @property(strong) id obj; // NULL when representing a Go object.
22
+
23
+ // new GoSeqRef object to proxy a Go object. The refnum must be
24
+ // provided from Go side.
25
+ - (instancetype)initWithRefnum:(int32_t)refnum obj:(id)obj;
26
+
27
+ - (int32_t)incNum;
28
+
29
+ @end
30
+
31
+ @protocol goSeqRefInterface
32
+ -(GoSeqRef*) _ref;
33
+ @end
34
+
35
+ #endif
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleExecutable</key>
6
+ <string>Signer</string>
7
+ <key>CFBundleIdentifier</key>
8
+ <string>Signer</string>
9
+ <key>MinimumOSVersion</key>
10
+ <string>100.0</string>
11
+ <key>CFBundleShortVersionString</key>
12
+ <string>0.0.1731108961</string>
13
+ <key>CFBundleVersion</key>
14
+ <string>0.0.1731108961</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>FMWK</string>
17
+ </dict>
18
+ </plist>
@@ -0,0 +1,8 @@
1
+ framework module "Signer" {
2
+ header "ref.h"
3
+ header "Signer.objc.h"
4
+ header "Universe.objc.h"
5
+ header "Signer.h"
6
+
7
+ export *
8
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright (c) Capsule Labs Inc. All rights reserved.
2
+
3
+ import { StorageUtils } from '@getpara/web-sdk';
4
+ import RNAsyncStorage from '@react-native-async-storage/async-storage';
5
+
6
+ /**
7
+ * Implements `StorageUtils` using React Native Async Storage.
8
+ */
9
+ export class AsyncStorage implements StorageUtils {
10
+ async clear(prefix: string): Promise<void> {
11
+ const keys = await RNAsyncStorage.getAllKeys();
12
+ for (const key of keys) {
13
+ if (key.startsWith(prefix)) {
14
+ await RNAsyncStorage.removeItem(key);
15
+ }
16
+ }
17
+ }
18
+
19
+ async get(key: string): Promise<string | null> {
20
+ return RNAsyncStorage.getItem(key);
21
+ }
22
+
23
+ async removeItem(key: string): Promise<void> {
24
+ await RNAsyncStorage.removeItem(key);
25
+ }
26
+
27
+ async set(key: string, value: string): Promise<void> {
28
+ await RNAsyncStorage.setItem(key, value);
29
+ }
30
+ }
@@ -0,0 +1,61 @@
1
+ // Copyright (c) Capsule Labs Inc. All rights reserved.
2
+
3
+ import { StorageUtils } from '@getpara/web-sdk';
4
+ import Keychain from 'react-native-keychain';
5
+
6
+ const USERNAME = '@CAPSULE';
7
+ const KEYCHAIN_USER_CANCELLED_ERRORS = [
8
+ 'user canceled the operation',
9
+ 'error: code: 13, msg: cancel',
10
+ 'error: code: 10, msg: fingerprint operation canceled by the user',
11
+ ];
12
+
13
+ function isUserCancelledError(error: Error) {
14
+ return KEYCHAIN_USER_CANCELLED_ERRORS.some(userCancelledError =>
15
+ error.toString().toLowerCase().includes(userCancelledError),
16
+ );
17
+ }
18
+
19
+ /**
20
+ * Implements `StorageUtils` using React Native `Keychain`.
21
+ */
22
+ export class KeychainStorage implements StorageUtils {
23
+ async get(key: string): Promise<string | null> {
24
+ try {
25
+ const item = await Keychain.getGenericPassword({
26
+ service: key,
27
+ });
28
+ if (!item) {
29
+ return null;
30
+ }
31
+ return item.password;
32
+ } catch (error) {
33
+ if (error instanceof Error && !isUserCancelledError(error)) {
34
+ // triggered when biometry verification fails and user cancels the action
35
+ throw new Error('Error retrieving stored item ' + error.message);
36
+ }
37
+ throw error;
38
+ }
39
+ }
40
+ async set(key: string, value: string): Promise<void> {
41
+ const result = await Keychain.setGenericPassword(USERNAME, value, {
42
+ service: key,
43
+ accessible: Keychain.ACCESSIBLE.AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY,
44
+ securityLevel: Keychain.SECURITY_LEVEL.ANY,
45
+ });
46
+ if (!result) {
47
+ throw new Error('Failed to store key ' + key);
48
+ }
49
+ }
50
+ async removeItem(key: string): Promise<void> {
51
+ await Keychain.resetGenericPassword({ service: key });
52
+ }
53
+ async clear(prefix: string): Promise<void> {
54
+ const services = await Keychain.getAllGenericPasswordServices();
55
+ for (const key of services) {
56
+ if (key && key.startsWith(prefix)) {
57
+ await Keychain.resetGenericPassword({ service: key });
58
+ }
59
+ }
60
+ }
61
+ }
package/src/config.ts ADDED
@@ -0,0 +1,70 @@
1
+ // Copyright (c) Capsule Labs Inc. All rights reserved.
2
+
3
+ import { NativeModules } from 'react-native';
4
+ import { Environment } from '@getpara/web-sdk';
5
+
6
+ function getPortalBaseURL(env: Environment) {
7
+ switch (env) {
8
+ case Environment.DEV:
9
+ return 'http://localhost:3003';
10
+ case Environment.SANDBOX:
11
+ return 'https://app.sandbox.usecapsule.com';
12
+ case Environment.BETA:
13
+ return 'https://app.beta.usecapsule.com';
14
+ case Environment.PROD:
15
+ return 'https://app.usecapsule.com';
16
+ default:
17
+ throw new Error(`env: ${env} not supported`);
18
+ }
19
+ }
20
+
21
+ function getBaseUrl(env: Environment): string {
22
+ switch (env) {
23
+ case Environment.DEV:
24
+ return 'http://localhost:8080/';
25
+ case Environment.SANDBOX:
26
+ return 'https://api.sandbox.getpara.com/';
27
+ case Environment.BETA:
28
+ return 'https://api.beta.getpara.com/';
29
+ case Environment.PROD:
30
+ return 'https://api.getpara.com/';
31
+ default:
32
+ throw new Error(`unsupported env: ${env}`);
33
+ }
34
+ }
35
+
36
+ export function getBaseMPCNetworkWSUrl(env: Environment): string {
37
+ switch (env) {
38
+ case Environment.DEV:
39
+ return `ws://localhost:3000`;
40
+ case Environment.SANDBOX:
41
+ return `wss://mpc-network.sandbox.getpara.com`;
42
+ case Environment.BETA:
43
+ return `wss://mpc-network.beta.getpara.com`;
44
+ case Environment.PROD:
45
+ return `wss://mpc-network.getpara.com`;
46
+ default:
47
+ throw new Error(`unsupported env: ${env}`);
48
+ }
49
+ }
50
+
51
+ export let userManagementServer = getBaseUrl(Environment.BETA);
52
+ export let portalBase = getPortalBaseURL(Environment.BETA);
53
+ export let mpcNetworkWSServer = getBaseMPCNetworkWSUrl(Environment.BETA);
54
+
55
+ export function setEnv(env: Environment) {
56
+ userManagementServer = getBaseUrl(env);
57
+ portalBase = getPortalBaseURL(env);
58
+ mpcNetworkWSServer = getBaseMPCNetworkWSUrl(env);
59
+ init();
60
+ }
61
+
62
+ const { CapsuleSignerModule } = NativeModules;
63
+ export const DEBUG_MODE_ENABLED = false;
64
+
65
+ function init() {
66
+ CapsuleSignerModule.setServerUrl(userManagementServer);
67
+ CapsuleSignerModule.setWsServerUrl(mpcNetworkWSServer);
68
+ }
69
+
70
+ init();
package/src/index.tsx ADDED
@@ -0,0 +1,2 @@
1
+ export * from '@getpara/web-sdk';
2
+ export { ParaMobile } from './react-native/ParaMobile.js';