@reclaimprotocol/inapp-rn-sdk 0.1.7 → 0.2.1

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 (42) hide show
  1. package/InappRnSdk.podspec +1 -1
  2. package/README.md +10 -6
  3. package/android/build.gradle +3 -3
  4. package/android/generated/java/com/reclaimprotocol/inapp_rn_sdk/NativeInappRnSdkSpec.java +16 -0
  5. package/android/generated/jni/RNInappRnSdkSpec-generated.cpp +14 -0
  6. package/android/generated/jni/react/renderer/components/RNInappRnSdkSpec/RNInappRnSdkSpecJSI-generated.cpp +15 -0
  7. package/android/generated/jni/react/renderer/components/RNInappRnSdkSpec/RNInappRnSdkSpecJSI.h +192 -20
  8. package/android/src/main/java/com/reclaimprotocol/inapp_rn_sdk/InappRnSdkModule.kt +99 -20
  9. package/ios/InappRnSdk.mm +35 -8
  10. package/ios/generated/RNInappRnSdkSpec/RNInappRnSdkSpec-generated.mm +24 -0
  11. package/ios/generated/RNInappRnSdkSpec/RNInappRnSdkSpec.h +18 -6
  12. package/ios/generated/RNInappRnSdkSpecJSI-generated.cpp +15 -0
  13. package/ios/generated/RNInappRnSdkSpecJSI.h +192 -20
  14. package/ios/inapp_rn_sdk/Api.swift +73 -7
  15. package/lib/commonjs/ReclaimVerificationPlatformChannel.js +120 -36
  16. package/lib/commonjs/ReclaimVerificationPlatformChannel.js.map +1 -1
  17. package/lib/commonjs/index.js +11 -2
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/specs/NativeInappRnSdk.js +1 -0
  20. package/lib/commonjs/specs/NativeInappRnSdk.js.map +1 -1
  21. package/lib/module/ReclaimVerificationPlatformChannel.js +117 -34
  22. package/lib/module/ReclaimVerificationPlatformChannel.js.map +1 -1
  23. package/lib/module/index.js +7 -4
  24. package/lib/module/index.js.map +1 -1
  25. package/lib/module/specs/NativeInappRnSdk.js +2 -0
  26. package/lib/module/specs/NativeInappRnSdk.js.map +1 -1
  27. package/lib/typescript/commonjs/src/ReclaimVerificationPlatformChannel.d.ts +29 -4
  28. package/lib/typescript/commonjs/src/ReclaimVerificationPlatformChannel.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/src/index.d.ts +4 -3
  30. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  31. package/lib/typescript/commonjs/src/specs/NativeInappRnSdk.d.ts +22 -4
  32. package/lib/typescript/commonjs/src/specs/NativeInappRnSdk.d.ts.map +1 -1
  33. package/lib/typescript/module/src/ReclaimVerificationPlatformChannel.d.ts +29 -4
  34. package/lib/typescript/module/src/ReclaimVerificationPlatformChannel.d.ts.map +1 -1
  35. package/lib/typescript/module/src/index.d.ts +4 -3
  36. package/lib/typescript/module/src/index.d.ts.map +1 -1
  37. package/lib/typescript/module/src/specs/NativeInappRnSdk.d.ts +22 -4
  38. package/lib/typescript/module/src/specs/NativeInappRnSdk.d.ts.map +1 -1
  39. package/package.json +1 -1
  40. package/src/ReclaimVerificationPlatformChannel.ts +149 -41
  41. package/src/index.ts +8 -4
  42. package/src/specs/NativeInappRnSdk.ts +32 -6
@@ -28,7 +28,11 @@ export namespace ReclaimVerificationApi {
28
28
  export type Response = ReclaimVerificationResponse;
29
29
 
30
30
  export namespace Overrides {
31
- export type ProviderInformation = NativeReclaimInappModuleTypes.ProviderInformation;
31
+ export interface ProviderInformation {
32
+ url?: string;
33
+ jsonString?: string;
34
+ callback?: (request: NativeReclaimInappModuleTypes.ProviderInformationRequest) => Promise<string>;
35
+ }
32
36
  export type FeatureOptions = NativeReclaimInappModuleTypes.FeatureOptions;
33
37
  export interface LogConsumer {
34
38
  /**
@@ -61,7 +65,8 @@ export namespace ReclaimVerificationApi {
61
65
  featureOptions?: Overrides.FeatureOptions,
62
66
  logConsumer?: Overrides.LogConsumer,
63
67
  sessionManagement?: Overrides.SessionManagement,
64
- appInfo?: Overrides.ReclaimAppInfo
68
+ appInfo?: Overrides.ReclaimAppInfo,
69
+ capabilityAccessToken?: string
65
70
  }
66
71
 
67
72
  export enum ExceptionType {
@@ -71,6 +76,29 @@ export namespace ReclaimVerificationApi {
71
76
  Failed = "Failed",
72
77
  }
73
78
 
79
+ export class ReclaimPlatformException extends Error {
80
+ readonly innerError: Error
81
+ readonly reason?: string
82
+ readonly details?: any
83
+
84
+ constructor(message: string, innerError: Error) {
85
+ super(message);
86
+ this.innerError = innerError;
87
+ this.reason = innerError.message;
88
+ if ('userInfo' in innerError) {
89
+ const details: any = innerError.userInfo
90
+ this.details = details
91
+ if ('message' in details) {
92
+ this.reason = details.message || this.reason
93
+ }
94
+ }
95
+ }
96
+
97
+ static isReclaimPlatformException(error: Error): error is ReclaimPlatformException {
98
+ return error instanceof ReclaimPlatformException
99
+ }
100
+ }
101
+
74
102
  export class ReclaimVerificationException extends Error {
75
103
  readonly innerError: Error
76
104
  readonly type: ExceptionType
@@ -113,21 +141,20 @@ export namespace ReclaimVerificationApi {
113
141
  }
114
142
 
115
143
  static fromError(error: Error, sessionIdHint: string): ReclaimVerificationException {
116
- if (Object.hasOwn(error, 'userInfo')) {
144
+ if ('userInfo' in error) {
117
145
  // From native, we send information about error in userInfo
118
- let unTypedError = (error as unknown as any);
119
- let userInfo = unTypedError.userInfo;
146
+ let userInfo = error.userInfo as any;
120
147
  if (userInfo) {
121
- let type = ReclaimVerificationApi.ReclaimVerificationException.fromTypeName(unTypedError.userInfo.errorType);
122
- let maybeSessionId = unTypedError?.userInfo?.sessionId
148
+ let type = ReclaimVerificationApi.ReclaimVerificationException.fromTypeName(userInfo.errorType);
149
+ let maybeSessionId = userInfo?.sessionId
123
150
  return new ReclaimVerificationException(
124
151
  error.message,
125
152
  error,
126
153
  type,
127
154
  (typeof maybeSessionId === 'string' && maybeSessionId)
128
155
  ? maybeSessionId : sessionIdHint,
129
- unTypedError?.userInfo?.didSubmitManualVerification ?? false,
130
- unTypedError?.userInfo?.reason ?? ""
156
+ userInfo?.didSubmitManualVerification ?? false,
157
+ userInfo?.reason ?? ""
131
158
  );
132
159
  }
133
160
  }
@@ -140,11 +167,27 @@ export namespace ReclaimVerificationApi {
140
167
  ""
141
168
  );
142
169
  }
170
+
171
+ static isReclaimVerificationException(error: Error): error is ReclaimVerificationException {
172
+ return error instanceof ReclaimVerificationException
173
+ }
143
174
  }
144
175
  }
145
176
 
146
- export class ReclaimVerificationPlatformChannel {
147
- async startVerification(request: ReclaimVerificationApi.Request): Promise<ReclaimVerificationApi.Response> {
177
+ export abstract class ReclaimVerificationPlatformChannel {
178
+ abstract startVerification(request: ReclaimVerificationApi.Request): Promise<ReclaimVerificationApi.Response>
179
+
180
+ abstract startVerificationFromUrl(requestUrl: string): Promise<ReclaimVerificationApi.Response>
181
+
182
+ abstract ping(): Promise<boolean>
183
+
184
+ abstract setOverrides(config: ReclaimVerificationApi.OverrideConfig): Promise<void>
185
+
186
+ abstract clearAllOverrides(): Promise<void>
187
+ }
188
+
189
+ export class ReclaimVerificationPlatformChannelImpl extends ReclaimVerificationPlatformChannel {
190
+ override async startVerification(request: ReclaimVerificationApi.Request): Promise<ReclaimVerificationApi.Response> {
148
191
  try {
149
192
  const response = await NativeReclaimInappModule.startVerification(request);
150
193
  return {
@@ -162,7 +205,7 @@ export class ReclaimVerificationPlatformChannel {
162
205
  }
163
206
  }
164
207
 
165
- async startVerificationFromUrl(requestUrl: string): Promise<ReclaimVerificationApi.Response> {
208
+ override async startVerificationFromUrl(requestUrl: string): Promise<ReclaimVerificationApi.Response> {
166
209
  try {
167
210
  const response = await NativeReclaimInappModule.startVerificationFromUrl(requestUrl);
168
211
  return {
@@ -180,35 +223,73 @@ export class ReclaimVerificationPlatformChannel {
180
223
  }
181
224
  }
182
225
 
183
- async ping(): Promise<boolean> {
226
+ override async ping(): Promise<boolean> {
184
227
  return await NativeReclaimInappModule.ping();
185
228
  }
186
229
 
187
- private previousLogSubscription: EventSubscription | null = null;
188
230
  private previousSessionManagementCancelCallback: null | (() => void) = null;
231
+ disposeSessionManagement() {
232
+ let callback = this.previousSessionManagementCancelCallback;
233
+ if (callback != null && callback != undefined) {
234
+ callback();
235
+ }
236
+ this.previousSessionManagementCancelCallback = null;
237
+ }
189
238
 
190
- setOverrides({
239
+ private previousLogSubscription: EventSubscription | null = null;
240
+ disposeLogListener() {
241
+ this.previousLogSubscription?.remove()
242
+ this.previousLogSubscription = null;
243
+ }
244
+
245
+ private previousProviderRequestCancelCallback: null | (() => void) = null;
246
+ private disposeProviderRequestListener() {
247
+ let callback = this.previousProviderRequestCancelCallback;
248
+ if (callback != null && callback != undefined) {
249
+ callback();
250
+ }
251
+ this.previousProviderRequestCancelCallback = null;
252
+ }
253
+
254
+ override async setOverrides({
191
255
  provider,
192
256
  featureOptions,
193
257
  logConsumer,
194
258
  sessionManagement,
195
- appInfo
259
+ appInfo,
260
+ capabilityAccessToken
196
261
  }: ReclaimVerificationApi.OverrideConfig) {
197
- this.previousLogSubscription?.remove()
198
- this.previousLogSubscription = null;
199
- let callback = this.previousSessionManagementCancelCallback;
200
- if (callback != null) {
201
- callback();
262
+ let providerCallback = provider?.callback;
263
+ let providerOverride = !provider ? null : {
264
+ url: provider?.url,
265
+ jsonString: provider?.jsonString,
266
+ canFetchProviderInformationFromHost: !!providerCallback,
267
+ }
268
+ if (providerCallback) {
269
+ this.disposeProviderRequestListener();
270
+ let providerRequestSubscription = NativeReclaimInappModule.onProviderInformationRequest(async (event) => {
271
+ try {
272
+ let result = await providerCallback(event);
273
+ NativeReclaimInappModule.replyWithProviderInformation(event.replyId, result);
274
+ } catch (error) {
275
+ console.error(error);
276
+ NativeReclaimInappModule.replyWithProviderInformation(event.replyId, "");
277
+ }
278
+ });
279
+ const cancel = () => {
280
+ providerRequestSubscription.remove();
281
+ }
282
+ this.previousProviderRequestCancelCallback = cancel;
202
283
  }
203
- this.previousSessionManagementCancelCallback = null;
204
284
 
205
- let logConsumerRequest = logConsumer == null ? undefined : {
206
- enableLogHandler: logConsumer?.onLogs != null,
285
+ const onLogsListener = logConsumer?.onLogs;
286
+ let logConsumerRequest = !logConsumer ? undefined : {
287
+ enableLogHandler: !!onLogsListener,
207
288
  canSdkCollectTelemetry: logConsumer?.canSdkCollectTelemetry,
208
289
  canSdkPrintLogs: logConsumer?.canSdkPrintLogs
209
290
  }
210
- const onLogsListener = logConsumer?.onLogs;
211
- if (onLogsListener != null) {
291
+ if (onLogsListener) {
292
+ this.disposeLogListener();
212
293
  const cancel = () => {
213
294
  this.previousLogSubscription?.remove();
214
295
  this.previousLogSubscription = null;
@@ -218,23 +299,38 @@ export class ReclaimVerificationPlatformChannel {
218
299
  })
219
300
  }
220
301
 
221
- let sessionManagementRequest = sessionManagement == null ? undefined : {
302
+ let sessionManagementRequest = !sessionManagement ? undefined : {
222
303
  // A handler is provided, so we don't let SDK manage sessions
223
304
  enableSdkSessionManagement: false
224
305
  }
225
- if (sessionManagement != null) {
306
+ if (sessionManagement) {
307
+ this.disposeSessionManagement();
226
308
  let sessionCreateSubscription = NativeReclaimInappModule.onSessionCreateRequest(async (event) => {
227
309
  const replyId = event.replyId;
228
- let result = await sessionManagement.onSessionCreateRequest(event);
229
- NativeReclaimInappModule.reply(replyId, result);
310
+ try {
311
+ let result = await sessionManagement.onSessionCreateRequest(event);
312
+ NativeReclaimInappModule.reply(replyId, result);
313
+ } catch (error) {
314
+ console.error(error);
315
+ NativeReclaimInappModule.reply(replyId, false);
316
+ }
230
317
  });
231
318
  let sessionUpdateSubscription = NativeReclaimInappModule.onSessionUpdateRequest(async (event) => {
232
319
  const replyId = event.replyId;
233
- let result = await sessionManagement.onSessionUpdateRequest(event);
234
- NativeReclaimInappModule.reply(replyId, result);
320
+ try {
321
+ let result = await sessionManagement.onSessionUpdateRequest(event);
322
+ NativeReclaimInappModule.reply(replyId, result);
323
+ } catch (error) {
324
+ console.error(error);
325
+ NativeReclaimInappModule.reply(replyId, false);
326
+ }
235
327
  });
236
328
  let sessionLogsSubscription = NativeReclaimInappModule.onSessionLogs((event) => {
237
- sessionManagement.onLog(event);
329
+ try {
330
+ sessionManagement.onLog(event);
331
+ } catch (error) {
332
+ console.error(error);
333
+ }
238
334
  });
239
335
  const cancel = () => {
240
336
  sessionCreateSubscription.remove()
@@ -244,12 +340,24 @@ export class ReclaimVerificationPlatformChannel {
244
340
  this.previousSessionManagementCancelCallback = cancel;
245
341
  }
246
342
 
247
- NativeReclaimInappModule.setOverrides({
248
- provider,
249
- featureOptions,
250
- logConsumer: logConsumerRequest,
251
- sessionManagement: sessionManagementRequest,
252
- appInfo
253
- });
343
+ try {
344
+ return await NativeReclaimInappModule.setOverrides({
345
+ provider: providerOverride,
346
+ featureOptions,
347
+ logConsumer: logConsumerRequest,
348
+ sessionManagement: sessionManagementRequest,
349
+ appInfo,
350
+ capabilityAccessToken
351
+ });
352
+ } catch (error) {
353
+ throw new ReclaimVerificationApi.ReclaimPlatformException("Failed to set overrides", error as Error);
354
+ }
254
355
  }
255
- }
356
+
357
+ override async clearAllOverrides() {
358
+ this.disposeProviderRequestListener();
359
+ this.disposeLogListener();
360
+ this.disposeSessionManagement();
361
+ return NativeReclaimInappModule.clearAllOverrides();
362
+ }
363
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ReclaimVerificationPlatformChannel, type ReclaimVerificationApi } from './ReclaimVerificationPlatformChannel';
2
- export { ReclaimVerificationPlatformChannel, ReclaimVerificationApi } from './ReclaimVerificationPlatformChannel';
1
+ import { type ReclaimVerificationApi, ReclaimVerificationPlatformChannel, ReclaimVerificationPlatformChannelImpl } from './ReclaimVerificationPlatformChannel';
2
+ export { ReclaimVerificationPlatformChannel, ReclaimVerificationApi, ReclaimVerificationPlatformChannelImpl } from './ReclaimVerificationPlatformChannel';
3
3
  export type { ReclaimVerificationApi as ReclaimVerificationApiType, ReclaimResult } from './ReclaimVerificationPlatformChannel';
4
4
 
5
5
  export class ReclaimVerification {
@@ -12,7 +12,7 @@ export class ReclaimVerification {
12
12
  this.channel = channel;
13
13
  } else {
14
14
  if (ReclaimVerification.defaultChannel == null) {
15
- ReclaimVerification.defaultChannel = new ReclaimVerificationPlatformChannel();
15
+ ReclaimVerification.defaultChannel = new ReclaimVerificationPlatformChannelImpl();
16
16
  }
17
17
  this.channel = ReclaimVerification.defaultChannel;
18
18
  }
@@ -27,6 +27,10 @@ export class ReclaimVerification {
27
27
  }
28
28
 
29
29
  public setOverrides(overrides: ReclaimVerificationApi.OverrideConfig) {
30
- this.channel.setOverrides(overrides);
30
+ return this.channel.setOverrides(overrides);
31
+ }
32
+
33
+ public clearAllOverrides() {
34
+ return this.channel.clearAllOverrides();
31
35
  }
32
36
  }
@@ -99,11 +99,6 @@ export interface Request {
99
99
  */
100
100
  parameters?: { [key: string]: string }; // Use index signature for Map
101
101
 
102
- /**
103
- * Whether to hide the landing page of the verification process. When false, shows an introductory page with claims to be proven.
104
- */
105
- hideLanding?: boolean; // Optional
106
-
107
102
  /**
108
103
  * Whether to automatically submit the proof after generation.
109
104
  */
@@ -136,6 +131,7 @@ export interface Response {
136
131
  export interface ProviderInformation {
137
132
  url?: string;
138
133
  jsonString?: string;
134
+ canFetchProviderInformationFromHost: boolean;
139
135
  }
140
136
 
141
137
  /**
@@ -256,6 +252,18 @@ export interface SessionLogEvent {
256
252
  logType: string;
257
253
  }
258
254
 
255
+ /// Identification information of a session.
256
+ export interface ReclaimSessionIdentityUpdate {
257
+ /// The application id.
258
+ appId: string;
259
+
260
+ /// The provider id.
261
+ providerId: string;
262
+
263
+ /// The session id.
264
+ sessionId: string;
265
+ }
266
+
259
267
  export interface SessionCreateRequestEvent {
260
268
  /**
261
269
  * The app ID for the verification attempt
@@ -295,20 +303,38 @@ export interface Overrides {
295
303
  featureOptions?: FeatureOptions | null,
296
304
  logConsumer?: LogConsumer | null,
297
305
  sessionManagement?: SessionManagement | null,
298
- appInfo?: ReclaimAppInfo | null
306
+ appInfo?: ReclaimAppInfo | null,
307
+ capabilityAccessToken?: string | null;
308
+ }
309
+
310
+ export interface ProviderInformationRequest {
311
+ appId: string;
312
+ providerId: string;
313
+ sessionId: string;
314
+ signature: string;
315
+ timestamp: string;
316
+ /**
317
+ * internal
318
+ */
319
+ readonly replyId: string;
299
320
  }
300
321
 
301
322
  export interface Spec extends TurboModule {
302
323
  startVerification(request: Request): Promise<Response>;
303
324
  startVerificationFromUrl(requestUrl: string): Promise<Response>;
304
325
  setOverrides(overrides: Overrides): Promise<void>;
326
+ clearAllOverrides(): Promise<void>;
305
327
  reply(replyId: string, reply: boolean): void;
328
+ replyWithProviderInformation(replyId: string, providerInformation: string): void;
306
329
  ping(): Promise<boolean>;
307
330
 
308
331
  readonly onLogs: EventEmitter<string>
309
332
  readonly onSessionLogs: EventEmitter<SessionLogEvent>
310
333
  readonly onSessionCreateRequest: EventEmitter<SessionCreateRequestEvent>
311
334
  readonly onSessionUpdateRequest: EventEmitter<SessionUpdateRequestEvent>
335
+ // unimplemented
336
+ readonly onSessionIdentityUpdate: EventEmitter<ReclaimSessionIdentityUpdate>
337
+ readonly onProviderInformationRequest: EventEmitter<ProviderInformationRequest>
312
338
  }
313
339
 
314
340
  export default TurboModuleRegistry.getEnforcing<Spec>('InappRnSdk');