@bifold/react-native-attestation 2.12.0 → 2.12.2

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.
@@ -269,7 +269,7 @@ RCT_EXPORT_METHOD(appleAttestation:(NSString *)keyId
269
269
  }
270
270
 
271
271
  RCT_EXPORT_METHOD(getAppStoreReceipt:(RCTPromiseResolveBlock)resolve
272
- rejecter:(RCTPromiseRejectBlock)reject) {
272
+ reject:(RCTPromiseRejectBlock)reject) {
273
273
  NSURL *appStoreReceiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
274
274
 
275
275
  if (appStoreReceiptURL && [[NSFileManager defaultManager] fileExistsAtPath:[appStoreReceiptURL path]]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifold/react-native-attestation",
3
- "version": "2.12.0",
3
+ "version": "2.12.2",
4
4
  "description": "Mobile app attestation",
5
5
  "main": "build/commonjs/index.js",
6
6
  "module": "build/module/index.js",
@@ -8,6 +8,7 @@
8
8
  "source": "build/commonjs/index.js",
9
9
  "react-native": "build/commonjs/index.js",
10
10
  "files": [
11
+ "src",
11
12
  "build",
12
13
  "ios",
13
14
  "android",
@@ -0,0 +1,14 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ generateKey(cache: boolean): Promise<string>;
6
+ sha256(stringToHash: string): Promise<Buffer>;
7
+ appleAttestation(keyId: string, challenge: string): Promise<Buffer>;
8
+ appleKeyAttestation(keyId: string, challenge: string): Promise<Buffer>;
9
+ isPlayIntegrityAvailable(): Promise<boolean>;
10
+ googleAttestation(nonce: string): Promise<string>;
11
+ getAppStoreReceipt(): Promise<string | null>;
12
+ }
13
+
14
+ export default TurboModuleRegistry.getEnforcing<Spec>('Attestation');
@@ -0,0 +1 @@
1
+ it.todo('write a test');
package/src/index.ts ADDED
@@ -0,0 +1,103 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ import { Buffer } from 'buffer';
3
+
4
+ import NativeAttestationSpec from './NativeAttestation';
5
+
6
+ const LINKING_ERROR =
7
+ `The package 'react-native-attestation' doesn't seem to be linked. Make sure: \n\n` +
8
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
9
+ '- You rebuilt the app after installing the package\n' +
10
+ '- You are not using Expo Go\n';
11
+
12
+ // @ts-expect-error global.__turboModuleProxy is a global variable injected by TurboModuleProxy
13
+ const isTurboModuleEnabled = global.__turboModuleProxy != null;
14
+
15
+ const AttestationModule = isTurboModuleEnabled
16
+ ? NativeAttestationSpec
17
+ : NativeModules.Attestation;
18
+
19
+ const Attestation = AttestationModule
20
+ ? AttestationModule
21
+ : new Proxy(
22
+ {},
23
+ {
24
+ get() {
25
+ throw new Error(LINKING_ERROR);
26
+ },
27
+ }
28
+ );
29
+
30
+ // TODO: Make available from Android.
31
+ export const sha256 = async (stringToHash: string): Promise<Buffer> => {
32
+ if (Platform.OS !== 'ios') {
33
+ throw new Error('sha256 is only available on iOS');
34
+ }
35
+
36
+ const bytes: Uint8Array = await Attestation.sha256(stringToHash);
37
+ return Buffer.from(bytes);
38
+ };
39
+
40
+ export const generateKey = async (cache: boolean = false): Promise<string> => {
41
+ if (Platform.OS !== 'ios') {
42
+ throw new Error('generateKey is only available on iOS');
43
+ }
44
+
45
+ return Attestation.generateKey(cache);
46
+ };
47
+
48
+ export const appleKeyAttestation = async (
49
+ keyId: string,
50
+ challenge: string
51
+ ): Promise<Buffer> => {
52
+ if (Platform.OS !== 'ios') {
53
+ throw new Error('appleKeyAttestation is only available on iOS');
54
+ }
55
+
56
+ const bytes: Uint8Array = await Attestation.appleKeyAttestation(
57
+ keyId,
58
+ challenge
59
+ );
60
+
61
+ return Buffer.from(bytes);
62
+ };
63
+
64
+ export const appleAttestation = async (
65
+ keyId: string,
66
+ challenge: string
67
+ ): Promise<Buffer> => {
68
+ if (Platform.OS !== 'ios') {
69
+ throw new Error('appleAttestation is only available on iOS');
70
+ }
71
+
72
+ const bytes: Uint8Array = await Attestation.appleAttestation(
73
+ keyId,
74
+ challenge
75
+ );
76
+
77
+ return Buffer.from(bytes);
78
+ };
79
+
80
+ export const googleAttestation = async (nonce: string): Promise<string> => {
81
+ if (Platform.OS !== 'android') {
82
+ throw new Error('googleAttestation is only available on Android');
83
+ }
84
+
85
+ const token: string = await Attestation.googleAttestation(nonce);
86
+ return token;
87
+ };
88
+
89
+ export const isPlayIntegrityAvailable = async (): Promise<boolean> => {
90
+ if (Platform.OS !== 'android') {
91
+ throw new Error('isPlayIntegrityAvailable is only available on Android');
92
+ }
93
+
94
+ return Attestation.isPlayIntegrityAvailable();
95
+ };
96
+
97
+ export const getAppStoreReceipt = async (): Promise<string | null> => {
98
+ if (Platform.OS !== 'ios') {
99
+ throw new Error('getAppStoreReceipt is only available on iOS');
100
+ }
101
+
102
+ return await Attestation.getAppStoreReceipt();
103
+ };