pushwave-client 0.2.2 → 0.2.4
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/dist/attestation/getApplicationAttestation.d.ts +9 -2
- package/dist/attestation/getApplicationAttestation.js +7 -7
- package/dist/registerPushWave.js +2 -8
- package/package.json +1 -1
- package/react-native.config.js +1 -1
- package/src/attestation/getApplicationAttestation.ts +17 -9
- package/src/registerPushWave.ts +5 -12
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
export interface AndroidAttestationPayload {
|
|
2
|
+
status: "ok";
|
|
3
|
+
platform: "android";
|
|
2
4
|
nonce: string;
|
|
3
5
|
timestamp: number;
|
|
4
6
|
integrityToken: string;
|
|
5
7
|
}
|
|
6
8
|
export interface IosAttestationPayload {
|
|
9
|
+
status: "ok";
|
|
10
|
+
platform: "ios";
|
|
7
11
|
nonce: string;
|
|
8
12
|
timestamp: number;
|
|
9
13
|
deviceCheckToken: string;
|
|
10
14
|
}
|
|
11
15
|
export interface DisabledAttestation {
|
|
12
|
-
|
|
16
|
+
status: "disabled";
|
|
13
17
|
reason: string;
|
|
14
18
|
}
|
|
15
|
-
export
|
|
19
|
+
export interface SkippedAttestation {
|
|
20
|
+
status: "skipped";
|
|
21
|
+
}
|
|
22
|
+
export type ApplicationAttestation = AndroidAttestationPayload | IosAttestationPayload | DisabledAttestation | SkippedAttestation;
|
|
16
23
|
export default function getApplicationAttestation(apiKey: string): Promise<ApplicationAttestation>;
|
|
@@ -6,7 +6,7 @@ const react_native_1 = require("react-native");
|
|
|
6
6
|
const native_1 = require("./native");
|
|
7
7
|
async function getApplicationAttestation(apiKey) {
|
|
8
8
|
if (!requiresAttestation(apiKey))
|
|
9
|
-
return
|
|
9
|
+
return { status: "skipped" };
|
|
10
10
|
const { nonce, timestamp } = createNonce();
|
|
11
11
|
try {
|
|
12
12
|
if (react_native_1.Platform.OS === "android")
|
|
@@ -16,9 +16,9 @@ async function getApplicationAttestation(apiKey) {
|
|
|
16
16
|
}
|
|
17
17
|
catch (err) {
|
|
18
18
|
const reason = err?.message ?? "attestation-error";
|
|
19
|
-
return {
|
|
19
|
+
return { status: "disabled", reason };
|
|
20
20
|
}
|
|
21
|
-
return {
|
|
21
|
+
return { status: "disabled", reason: "platform-unsupported" };
|
|
22
22
|
}
|
|
23
23
|
function requiresAttestation(apiKey) {
|
|
24
24
|
return apiKey.startsWith("pw_pub_");
|
|
@@ -43,14 +43,14 @@ function base64UrlEncode(input) {
|
|
|
43
43
|
async function getAndroidSignature(nonce, timestamp) {
|
|
44
44
|
const integrityToken = await (0, native_1.getAndroidIntegrityToken)(nonce);
|
|
45
45
|
if (!integrityToken) {
|
|
46
|
-
return {
|
|
46
|
+
return { status: "disabled", reason: "play-integrity-unavailable" };
|
|
47
47
|
}
|
|
48
|
-
return { nonce, timestamp, integrityToken };
|
|
48
|
+
return { status: "ok", platform: "android", nonce, timestamp, integrityToken };
|
|
49
49
|
}
|
|
50
50
|
async function getIosDeviceCheck(nonce, timestamp) {
|
|
51
51
|
const deviceCheckToken = await (0, native_1.getDeviceCheckToken)(nonce);
|
|
52
52
|
if (!deviceCheckToken) {
|
|
53
|
-
return {
|
|
53
|
+
return { status: "disabled", reason: "devicecheck-unavailable" };
|
|
54
54
|
}
|
|
55
|
-
return { nonce, timestamp, deviceCheckToken };
|
|
55
|
+
return { status: "ok", platform: "ios", nonce, timestamp, deviceCheckToken };
|
|
56
56
|
}
|
package/dist/registerPushWave.js
CHANGED
|
@@ -25,14 +25,8 @@ async function registerPushWave({ apiKey }) {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
const appAttestation = await (0, getApplicationAttestation_1.default)(apiKey);
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
pwLogger_1.PWLogger.error(message);
|
|
31
|
-
return {
|
|
32
|
-
success: false,
|
|
33
|
-
message: `[PushWaveClient] Error: ` + message
|
|
34
|
-
};
|
|
35
|
-
}
|
|
28
|
+
if (appAttestation.status === "disabled")
|
|
29
|
+
pwLogger_1.PWLogger.warn(`(${react_native_1.Platform.OS}) could not get attestation: ${appAttestation.reason}`);
|
|
36
30
|
const path = "/v1/expo-tokens";
|
|
37
31
|
const options = {
|
|
38
32
|
apiKey: apiKey,
|
package/package.json
CHANGED
package/react-native.config.js
CHANGED
|
@@ -6,7 +6,7 @@ module.exports = {
|
|
|
6
6
|
},
|
|
7
7
|
android: {
|
|
8
8
|
sourceDir: "android",
|
|
9
|
-
packageImportPath: "import com.pushwaveclient.PushwaveAttestationPackage",
|
|
9
|
+
packageImportPath: "import com.pushwaveclient.PushwaveAttestationPackage;",
|
|
10
10
|
packageInstance: "new PushwaveAttestationPackage()",
|
|
11
11
|
},
|
|
12
12
|
},
|
|
@@ -3,30 +3,38 @@ import { Platform } from "react-native";
|
|
|
3
3
|
import { getAndroidIntegrityToken, getDeviceCheckToken } from "./native";
|
|
4
4
|
|
|
5
5
|
export interface AndroidAttestationPayload {
|
|
6
|
+
status: "ok";
|
|
7
|
+
platform: "android";
|
|
6
8
|
nonce: string;
|
|
7
9
|
timestamp: number;
|
|
8
10
|
integrityToken: string;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
export interface IosAttestationPayload {
|
|
14
|
+
status: "ok";
|
|
15
|
+
platform: "ios";
|
|
12
16
|
nonce: string;
|
|
13
17
|
timestamp: number;
|
|
14
18
|
deviceCheckToken: string;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
export interface DisabledAttestation {
|
|
18
|
-
|
|
22
|
+
status: "disabled";
|
|
19
23
|
reason: string;
|
|
20
24
|
}
|
|
21
25
|
|
|
26
|
+
export interface SkippedAttestation {
|
|
27
|
+
status: "skipped";
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
export type ApplicationAttestation =
|
|
23
31
|
| AndroidAttestationPayload
|
|
24
32
|
| IosAttestationPayload
|
|
25
33
|
| DisabledAttestation
|
|
26
|
-
|
|
|
34
|
+
| SkippedAttestation;
|
|
27
35
|
|
|
28
36
|
export default async function getApplicationAttestation(apiKey: string): Promise<ApplicationAttestation> {
|
|
29
|
-
if (!requiresAttestation(apiKey)) return
|
|
37
|
+
if (!requiresAttestation(apiKey)) return { status: "skipped" };
|
|
30
38
|
|
|
31
39
|
const { nonce, timestamp } = createNonce();
|
|
32
40
|
|
|
@@ -35,10 +43,10 @@ export default async function getApplicationAttestation(apiKey: string): Promise
|
|
|
35
43
|
if (Platform.OS === "ios") return await getIosDeviceCheck(nonce, timestamp);
|
|
36
44
|
} catch (err) {
|
|
37
45
|
const reason = (err as Error)?.message ?? "attestation-error";
|
|
38
|
-
return {
|
|
46
|
+
return { status: "disabled", reason };
|
|
39
47
|
}
|
|
40
48
|
|
|
41
|
-
return {
|
|
49
|
+
return { status: "disabled", reason: "platform-unsupported" };
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
function requiresAttestation(apiKey: string) {
|
|
@@ -72,10 +80,10 @@ async function getAndroidSignature(
|
|
|
72
80
|
const integrityToken = await getAndroidIntegrityToken(nonce);
|
|
73
81
|
|
|
74
82
|
if (!integrityToken) {
|
|
75
|
-
return {
|
|
83
|
+
return { status: "disabled", reason: "play-integrity-unavailable" };
|
|
76
84
|
}
|
|
77
85
|
|
|
78
|
-
return { nonce, timestamp, integrityToken };
|
|
86
|
+
return { status: "ok", platform: "android", nonce, timestamp, integrityToken };
|
|
79
87
|
}
|
|
80
88
|
|
|
81
89
|
async function getIosDeviceCheck(
|
|
@@ -85,8 +93,8 @@ async function getIosDeviceCheck(
|
|
|
85
93
|
const deviceCheckToken = await getDeviceCheckToken(nonce);
|
|
86
94
|
|
|
87
95
|
if (!deviceCheckToken) {
|
|
88
|
-
return {
|
|
96
|
+
return { status: "disabled", reason: "devicecheck-unavailable" };
|
|
89
97
|
}
|
|
90
98
|
|
|
91
|
-
return { nonce, timestamp, deviceCheckToken };
|
|
99
|
+
return { status: "ok", platform: "ios", nonce, timestamp, deviceCheckToken };
|
|
92
100
|
}
|
package/src/registerPushWave.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface RegisterPushWaveOptions {
|
|
|
19
19
|
expoToken: string;
|
|
20
20
|
platform: string;
|
|
21
21
|
appAttestation?: any;
|
|
22
|
+
environment: "development" | "production"
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export default async function registerPushWave(
|
|
@@ -46,17 +47,8 @@ export default async function registerPushWave(
|
|
|
46
47
|
|
|
47
48
|
const appAttestation = await getApplicationAttestation(apiKey);
|
|
48
49
|
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
const message = `could not get ${Platform.OS} attestation.`;
|
|
52
|
-
|
|
53
|
-
PWLogger.error(message);
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
success: false,
|
|
57
|
-
message: `[PushWaveClient] Error: ` + message
|
|
58
|
-
}
|
|
59
|
-
}
|
|
50
|
+
if (appAttestation.status === "disabled")
|
|
51
|
+
PWLogger.warn(`(${Platform.OS}) could not get attestation: ${appAttestation.reason}`);
|
|
60
52
|
|
|
61
53
|
const path = "/v1/expo-tokens"
|
|
62
54
|
|
|
@@ -64,7 +56,8 @@ export default async function registerPushWave(
|
|
|
64
56
|
apiKey: apiKey,
|
|
65
57
|
expoToken: expoToken,
|
|
66
58
|
platform: Platform.OS,
|
|
67
|
-
appAttestation: appAttestation
|
|
59
|
+
appAttestation: appAttestation,
|
|
60
|
+
environment: __DEV__ ? "development" : "production"
|
|
68
61
|
}
|
|
69
62
|
|
|
70
63
|
try {
|