@reclaimprotocol/inapp-rn-sdk 0.2.1 → 0.3.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 (56) hide show
  1. package/InappRnSdk.podspec +1 -1
  2. package/README.md +8 -6
  3. package/android/build.gradle +3 -3
  4. package/android/generated/java/com/reclaimprotocol/inapp_rn_sdk/NativeInappRnSdkSpec.java +13 -5
  5. package/android/generated/jni/RNInappRnSdkSpec-generated.cpp +11 -4
  6. package/android/generated/jni/react/renderer/components/RNInappRnSdkSpec/RNInappRnSdkSpecJSI-generated.cpp +10 -3
  7. package/android/generated/jni/react/renderer/components/RNInappRnSdkSpec/RNInappRnSdkSpecJSI.h +168 -12
  8. package/android/src/main/java/com/reclaimprotocol/inapp_rn_sdk/InappRnSdkModule.kt +49 -8
  9. package/ios/InappRnSdk.mm +33 -6
  10. package/ios/generated/RNInappRnSdkSpec/RNInappRnSdkSpec-generated.mm +32 -8
  11. package/ios/generated/RNInappRnSdkSpec/RNInappRnSdkSpec.h +53 -3
  12. package/ios/generated/RNInappRnSdkSpecJSI-generated.cpp +10 -3
  13. package/ios/generated/RNInappRnSdkSpecJSI.h +168 -12
  14. package/ios/inapp_rn_sdk/Api.swift +71 -20
  15. package/lib/commonjs/index.js +126 -30
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/{ReclaimVerificationPlatformChannel.js → platform.js} +48 -106
  18. package/lib/commonjs/platform.js.map +1 -0
  19. package/lib/commonjs/specs/NativeInappRnSdk.js.map +1 -1
  20. package/lib/module/index.js +127 -13
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/{ReclaimVerificationPlatformChannel.js → platform.js} +46 -103
  23. package/lib/module/platform.js.map +1 -0
  24. package/lib/module/specs/NativeInappRnSdk.js.map +1 -1
  25. package/lib/typescript/commonjs/src/index.d.ts +140 -8
  26. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/src/platform.d.ts +18 -0
  28. package/lib/typescript/commonjs/src/platform.d.ts.map +1 -0
  29. package/lib/typescript/commonjs/src/specs/NativeInappRnSdk.d.ts +18 -2
  30. package/lib/typescript/commonjs/src/specs/NativeInappRnSdk.d.ts.map +1 -1
  31. package/lib/typescript/module/src/index.d.ts +140 -8
  32. package/lib/typescript/module/src/index.d.ts.map +1 -1
  33. package/lib/typescript/module/src/platform.d.ts +18 -0
  34. package/lib/typescript/module/src/platform.d.ts.map +1 -0
  35. package/lib/typescript/module/src/specs/NativeInappRnSdk.d.ts +18 -2
  36. package/lib/typescript/module/src/specs/NativeInappRnSdk.d.ts.map +1 -1
  37. package/package.json +2 -1
  38. package/src/index.ts +260 -18
  39. package/src/platform.ts +218 -0
  40. package/src/specs/NativeInappRnSdk.ts +21 -2
  41. package/lib/commonjs/ReclaimVerificationPlatformChannel.js.map +0 -1
  42. package/lib/commonjs/types/proof.js +0 -16
  43. package/lib/commonjs/types/proof.js.map +0 -1
  44. package/lib/module/ReclaimVerificationPlatformChannel.js.map +0 -1
  45. package/lib/module/types/proof.js +0 -12
  46. package/lib/module/types/proof.js.map +0 -1
  47. package/lib/typescript/commonjs/src/ReclaimVerificationPlatformChannel.d.ts +0 -107
  48. package/lib/typescript/commonjs/src/ReclaimVerificationPlatformChannel.d.ts.map +0 -1
  49. package/lib/typescript/commonjs/src/types/proof.d.ts +0 -33
  50. package/lib/typescript/commonjs/src/types/proof.d.ts.map +0 -1
  51. package/lib/typescript/module/src/ReclaimVerificationPlatformChannel.d.ts +0 -107
  52. package/lib/typescript/module/src/ReclaimVerificationPlatformChannel.d.ts.map +0 -1
  53. package/lib/typescript/module/src/types/proof.d.ts +0 -33
  54. package/lib/typescript/module/src/types/proof.d.ts.map +0 -1
  55. package/src/ReclaimVerificationPlatformChannel.ts +0 -363
  56. package/src/types/proof.ts +0 -44
@@ -1,363 +0,0 @@
1
- import type { EventSubscription } from "react-native";
2
- import NativeReclaimInappModule from "./specs/NativeInappRnSdk";
3
- import * as NativeReclaimInappModuleTypes from "./specs/NativeInappRnSdk";
4
- import { ReclaimResult, type ReclaimVerificationResponse } from "./types/proof";
5
- export type { ReclaimVerificationResponse, ReclaimResult } from "./types/proof";
6
-
7
- /**
8
- * This namespace provides types involved in initiating and managing the verification process
9
- * for proving claims about user data through various providers.
10
- */
11
- export namespace ReclaimVerificationApi {
12
- /**
13
- * Represents user's session information for a verification attempt.
14
- * This data class contains the necessary data to identify and validate a verification session.
15
- */
16
- export type SessionInformation = NativeReclaimInappModuleTypes.SessionInformation;
17
-
18
- /**
19
- * Represents a request for a verification attempt.
20
- *
21
- * You can create a request using the [ReclaimVerification.Request] constructor or the [ReclaimVerification.Request.fromManifestMetaData] factory method.
22
- */
23
- export type Request = NativeReclaimInappModuleTypes.Request;
24
-
25
- /**
26
- * Contains the proof and response data after verification
27
- */
28
- export type Response = ReclaimVerificationResponse;
29
-
30
- export namespace Overrides {
31
- export interface ProviderInformation {
32
- url?: string;
33
- jsonString?: string;
34
- callback?: (request: NativeReclaimInappModuleTypes.ProviderInformationRequest) => Promise<string>;
35
- }
36
- export type FeatureOptions = NativeReclaimInappModuleTypes.FeatureOptions;
37
- export interface LogConsumer {
38
- /**
39
- * Handler for consuming logs exported from the SDK.
40
- * Defaults to false.
41
- */
42
- onLogs?: (logJsonString: String, cancel: () => void) => void;
43
-
44
- /**
45
- * When enabled, logs are sent to reclaim that can be used to help you.
46
- * Defaults to true.
47
- */
48
- canSdkCollectTelemetry?: boolean;
49
-
50
- /**
51
- * Defaults to enabled when not in release mode.
52
- */
53
- canSdkPrintLogs?: boolean;
54
- }
55
- export interface SessionManagement {
56
- onLog: (event: NativeReclaimInappModuleTypes.SessionLogEvent) => void;
57
- onSessionCreateRequest: (event: NativeReclaimInappModuleTypes.SessionCreateRequestEvent) => Promise<boolean>;
58
- onSessionUpdateRequest: (event: NativeReclaimInappModuleTypes.SessionUpdateRequestEvent) => Promise<boolean>;
59
- };
60
- export type ReclaimAppInfo = NativeReclaimInappModuleTypes.ReclaimAppInfo;
61
- }
62
-
63
- export type OverrideConfig = {
64
- provider?: Overrides.ProviderInformation,
65
- featureOptions?: Overrides.FeatureOptions,
66
- logConsumer?: Overrides.LogConsumer,
67
- sessionManagement?: Overrides.SessionManagement,
68
- appInfo?: Overrides.ReclaimAppInfo,
69
- capabilityAccessToken?: string
70
- }
71
-
72
- export enum ExceptionType {
73
- Cancelled = "Cancelled",
74
- Dismissed = "Dismissed",
75
- SessionExpired = "SessionExpired",
76
- Failed = "Failed",
77
- }
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
-
102
- export class ReclaimVerificationException extends Error {
103
- readonly innerError: Error
104
- readonly type: ExceptionType
105
- readonly sessionId: string
106
- readonly "didSubmitManualVerification": boolean
107
- readonly "reason": string
108
-
109
- constructor(
110
- message: string,
111
- innerError: Error,
112
- type: ExceptionType,
113
- sessionId: string,
114
- didSubmitManualVerification: boolean,
115
- reason: string
116
- ) {
117
- super(message);
118
- this.innerError = innerError;
119
- this.type = type;
120
- this.sessionId = sessionId;
121
- this.didSubmitManualVerification = didSubmitManualVerification;
122
- this.reason = reason;
123
- }
124
-
125
- private static fromTypeName(name: string): ExceptionType {
126
- switch (name) {
127
- case "cancelled":
128
- case "org.reclaimprotocol.inapp_sdk.ReclaimVerification.ReclaimVerificationException.Cancelled":
129
- return ExceptionType.Cancelled;
130
- case "dismissed":
131
- case "org.reclaimprotocol.inapp_sdk.ReclaimVerification.ReclaimVerificationException.Dismissed":
132
- return ExceptionType.Dismissed;
133
- case "sessionExpired":
134
- case "org.reclaimprotocol.inapp_sdk.ReclaimVerification.ReclaimVerificationException.SessionExpired":
135
- return ExceptionType.SessionExpired;
136
- case "failed":
137
- case "org.reclaimprotocol.inapp_sdk.ReclaimVerification.ReclaimVerificationException.Failed":
138
- return ExceptionType.Failed;
139
- }
140
- return ExceptionType.Failed;
141
- }
142
-
143
- static fromError(error: Error, sessionIdHint: string): ReclaimVerificationException {
144
- if ('userInfo' in error) {
145
- // From native, we send information about error in userInfo
146
- let userInfo = error.userInfo as any;
147
- if (userInfo) {
148
- let type = ReclaimVerificationApi.ReclaimVerificationException.fromTypeName(userInfo.errorType);
149
- let maybeSessionId = userInfo?.sessionId
150
- return new ReclaimVerificationException(
151
- error.message,
152
- error,
153
- type,
154
- (typeof maybeSessionId === 'string' && maybeSessionId)
155
- ? maybeSessionId : sessionIdHint,
156
- userInfo?.didSubmitManualVerification ?? false,
157
- userInfo?.reason ?? ""
158
- );
159
- }
160
- }
161
- return new ReclaimVerificationException(
162
- error.message,
163
- error,
164
- ReclaimVerificationApi.ExceptionType.Failed,
165
- sessionIdHint,
166
- false,
167
- ""
168
- );
169
- }
170
-
171
- static isReclaimVerificationException(error: Error): error is ReclaimVerificationException {
172
- return error instanceof ReclaimVerificationException
173
- }
174
- }
175
- }
176
-
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> {
191
- try {
192
- const response = await NativeReclaimInappModule.startVerification(request);
193
- return {
194
- ...response,
195
- proofs: ReclaimResult.asProofs(response.proofs),
196
- }
197
- } catch (error) {
198
- console.info({
199
- error
200
- })
201
- if (error instanceof Error) {
202
- throw ReclaimVerificationApi.ReclaimVerificationException.fromError(error, request.session?.sessionId ?? "");
203
- }
204
- throw error
205
- }
206
- }
207
-
208
- override async startVerificationFromUrl(requestUrl: string): Promise<ReclaimVerificationApi.Response> {
209
- try {
210
- const response = await NativeReclaimInappModule.startVerificationFromUrl(requestUrl);
211
- return {
212
- ...response,
213
- proofs: ReclaimResult.asProofs(response.proofs),
214
- }
215
- } catch (error) {
216
- console.info({
217
- error
218
- })
219
- if (error instanceof Error) {
220
- throw ReclaimVerificationApi.ReclaimVerificationException.fromError(error, "");
221
- }
222
- throw error
223
- }
224
- }
225
-
226
- override async ping(): Promise<boolean> {
227
- return await NativeReclaimInappModule.ping();
228
- }
229
-
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
- }
238
-
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({
255
- provider,
256
- featureOptions,
257
- logConsumer,
258
- sessionManagement,
259
- appInfo,
260
- capabilityAccessToken
261
- }: ReclaimVerificationApi.OverrideConfig) {
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;
283
- }
284
-
285
- const onLogsListener = logConsumer?.onLogs;
286
- let logConsumerRequest = !logConsumer ? undefined : {
287
- enableLogHandler: !!onLogsListener,
288
- canSdkCollectTelemetry: logConsumer?.canSdkCollectTelemetry,
289
- canSdkPrintLogs: logConsumer?.canSdkPrintLogs
290
- }
291
- if (onLogsListener) {
292
- this.disposeLogListener();
293
- const cancel = () => {
294
- this.previousLogSubscription?.remove();
295
- this.previousLogSubscription = null;
296
- };
297
- this.previousLogSubscription = NativeReclaimInappModule.onLogs((arg) => {
298
- onLogsListener(arg, cancel);
299
- })
300
- }
301
-
302
- let sessionManagementRequest = !sessionManagement ? undefined : {
303
- // A handler is provided, so we don't let SDK manage sessions
304
- enableSdkSessionManagement: false
305
- }
306
- if (sessionManagement) {
307
- this.disposeSessionManagement();
308
- let sessionCreateSubscription = NativeReclaimInappModule.onSessionCreateRequest(async (event) => {
309
- const replyId = event.replyId;
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
- }
317
- });
318
- let sessionUpdateSubscription = NativeReclaimInappModule.onSessionUpdateRequest(async (event) => {
319
- const replyId = event.replyId;
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
- }
327
- });
328
- let sessionLogsSubscription = NativeReclaimInappModule.onSessionLogs((event) => {
329
- try {
330
- sessionManagement.onLog(event);
331
- } catch (error) {
332
- console.error(error);
333
- }
334
- });
335
- const cancel = () => {
336
- sessionCreateSubscription.remove()
337
- sessionUpdateSubscription.remove()
338
- sessionLogsSubscription.remove()
339
- }
340
- this.previousSessionManagementCancelCallback = cancel;
341
- }
342
-
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
- }
355
- }
356
-
357
- override async clearAllOverrides() {
358
- this.disposeProviderRequestListener();
359
- this.disposeLogListener();
360
- this.disposeSessionManagement();
361
- return NativeReclaimInappModule.clearAllOverrides();
362
- }
363
- }
@@ -1,44 +0,0 @@
1
- import * as NativeReclaimInappModuleTypes from "./../specs/NativeInappRnSdk";
2
-
3
- export interface ReclaimVerificationResponse extends NativeReclaimInappModuleTypes.Response {
4
- proofs: ReclaimResult.Proof[];
5
- }
6
-
7
- export namespace ReclaimResult {
8
- export interface Proof {
9
- identifier: string;
10
- signatures: string[];
11
- /**
12
- * A data associated with this [Proof].
13
- * The data type of this object is dynamic and can be any JSON serializable Javascript object.
14
- */
15
- publicData?: any | null;
16
- witnesses: WitnessData[];
17
- claimData: ProviderClaimData;
18
- }
19
-
20
- export const isProof = (value: Record<string, any>): value is Proof => {
21
- return typeof value === 'object' && value !== null && 'identifier' in value && 'signatures' in value && 'witnesses' in value;
22
- }
23
-
24
- export const asProofs = (proofs: Record<string, any>[]): Proof[] => {
25
- return proofs.filter(isProof);
26
- }
27
-
28
- export interface ProviderClaimData {
29
- owner: string;
30
- provider: string;
31
- /// int
32
- timestampS: number;
33
- /// int
34
- epoch: number;
35
- context: string;
36
- identifier: string;
37
- parameters: string;
38
- }
39
-
40
- export interface WitnessData {
41
- id: string;
42
- url: string;
43
- }
44
- }