react-native-dpop 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.
- package/Dpop.podspec +20 -0
- package/LICENSE +20 -0
- package/README.md +105 -0
- package/android/build.gradle +67 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/dpop/DPoPKeyStore.kt +168 -0
- package/android/src/main/java/com/dpop/DPoPUtils.kt +208 -0
- package/android/src/main/java/com/dpop/DpopModule.kt +302 -0
- package/android/src/main/java/com/dpop/DpopPackage.kt +31 -0
- package/ios/Dpop.h +5 -0
- package/ios/Dpop.mm +21 -0
- package/lib/module/NativeDpop.js +5 -0
- package/lib/module/NativeDpop.js.map +1 -0
- package/lib/module/index.js +68 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeDpop.d.ts +19 -0
- package/lib/typescript/src/NativeDpop.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +57 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +120 -0
- package/src/NativeDpop.ts +30 -0
- package/src/index.tsx +145 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
+
|
|
5
|
+
export interface Spec extends TurboModule {
|
|
6
|
+
assertHardwareBacked(alias: string | null): Promise<void>;
|
|
7
|
+
calculateThumbprint(alias: string | null): Promise<string>;
|
|
8
|
+
deleteKeyPair(alias: string | null): Promise<void>;
|
|
9
|
+
getKeyInfo(alias: string | null): Promise<UnsafeObject>;
|
|
10
|
+
getPublicKeyDer(alias: string | null): Promise<string>;
|
|
11
|
+
getPublicKeyJwk(alias: string | null): Promise<UnsafeObject>;
|
|
12
|
+
getPublicKeyRaw(alias: string | null): Promise<string>;
|
|
13
|
+
hasKeyPair(alias: string | null): Promise<boolean>;
|
|
14
|
+
isBoundToAlias(proof: string, alias: string | null): Promise<boolean>;
|
|
15
|
+
rotateKeyPair(alias: string | null): Promise<void>;
|
|
16
|
+
signWithDpopPrivateKey(payload: string, alias: string | null): Promise<string>;
|
|
17
|
+
generateProof(
|
|
18
|
+
htu: string,
|
|
19
|
+
htm: string,
|
|
20
|
+
nonce: string | null,
|
|
21
|
+
accessToken: string | null,
|
|
22
|
+
additional: UnsafeObject | null,
|
|
23
|
+
kid: string | null,
|
|
24
|
+
jti: string | null,
|
|
25
|
+
iat: number | null,
|
|
26
|
+
alias: string | null
|
|
27
|
+
): Promise<UnsafeObject>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('Dpop');
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
import Dpop from './NativeDpop';
|
|
3
|
+
|
|
4
|
+
type AdditionalClaims = Record<string, unknown>;
|
|
5
|
+
|
|
6
|
+
export type PublicJwk = {
|
|
7
|
+
kty: 'EC';
|
|
8
|
+
crv: 'P-256';
|
|
9
|
+
x: string;
|
|
10
|
+
y: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type PublicKeyFormat = 'JWK' | 'DER' | 'RAW';
|
|
14
|
+
|
|
15
|
+
export type DPoPKeyInfo = {
|
|
16
|
+
alias: string;
|
|
17
|
+
hasKeyPair: boolean;
|
|
18
|
+
algorithm?: string;
|
|
19
|
+
curve?: string;
|
|
20
|
+
insideSecureHardware?: boolean;
|
|
21
|
+
securityLevel?: number;
|
|
22
|
+
strongBoxAvailable?: boolean;
|
|
23
|
+
strongBoxBacked?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type GenerateProofInput = {
|
|
27
|
+
htu: string;
|
|
28
|
+
htm: string;
|
|
29
|
+
nonce?: string;
|
|
30
|
+
accessToken?: string;
|
|
31
|
+
additional?: AdditionalClaims;
|
|
32
|
+
kid?: string;
|
|
33
|
+
jti?: string;
|
|
34
|
+
iat?: number;
|
|
35
|
+
alias?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type DPoPProofContext = {
|
|
39
|
+
htu: string;
|
|
40
|
+
htm: string;
|
|
41
|
+
nonce: string | null;
|
|
42
|
+
ath: string | null;
|
|
43
|
+
additional: AdditionalClaims | null;
|
|
44
|
+
kid: string | null;
|
|
45
|
+
jti: string;
|
|
46
|
+
iat: number;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
type GenerateProofResult = {
|
|
50
|
+
proof: string;
|
|
51
|
+
proofContext: DPoPProofContext;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const LINKING_ERROR =
|
|
55
|
+
'Dpop module nao encontrado. Verifique se o app Android foi recompilado apos adicionar o modulo nativo.';
|
|
56
|
+
|
|
57
|
+
function requireAndroid() {
|
|
58
|
+
if (Platform.OS !== 'android') {
|
|
59
|
+
throw new Error('react-native-dpop (MVP atual) suporta somente Android.');
|
|
60
|
+
}
|
|
61
|
+
if (!Dpop) {
|
|
62
|
+
throw new Error(LINKING_ERROR);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class DPoP {
|
|
67
|
+
public readonly proof: string;
|
|
68
|
+
public readonly alias?: string;
|
|
69
|
+
public readonly proofContext: DPoPProofContext;
|
|
70
|
+
|
|
71
|
+
private constructor(proof: string, proofContext: DPoPProofContext, alias?: string) {
|
|
72
|
+
this.proof = proof;
|
|
73
|
+
this.proofContext = proofContext;
|
|
74
|
+
this.alias = alias;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public async calculateThumbprint(): Promise<string> {
|
|
78
|
+
requireAndroid();
|
|
79
|
+
return Dpop.calculateThumbprint(this.alias ?? null);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public async getPublicKey(format: PublicKeyFormat): Promise<PublicJwk | string> {
|
|
83
|
+
requireAndroid();
|
|
84
|
+
if (format === 'DER') {
|
|
85
|
+
return Dpop.getPublicKeyDer(this.alias ?? null);
|
|
86
|
+
}
|
|
87
|
+
if (format === 'RAW') {
|
|
88
|
+
return Dpop.getPublicKeyRaw(this.alias ?? null);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return Dpop.getPublicKeyJwk(this.alias ?? null) as Promise<PublicJwk>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public async signWithDpopPrivateKey(payload: string): Promise<string> {
|
|
95
|
+
requireAndroid();
|
|
96
|
+
return Dpop.signWithDpopPrivateKey(payload, this.alias ?? null);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public async isBoundToAlias(alias?: string): Promise<boolean> {
|
|
100
|
+
requireAndroid();
|
|
101
|
+
return Dpop.isBoundToAlias(this.proof, alias ?? this.alias ?? null);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public static async generateProof(input: GenerateProofInput): Promise<DPoP> {
|
|
105
|
+
requireAndroid();
|
|
106
|
+
const result = (await Dpop.generateProof(
|
|
107
|
+
input.htu,
|
|
108
|
+
input.htm,
|
|
109
|
+
input.nonce ?? null,
|
|
110
|
+
input.accessToken ?? null,
|
|
111
|
+
input.additional ?? null,
|
|
112
|
+
input.kid ?? null,
|
|
113
|
+
input.jti ?? null,
|
|
114
|
+
input.iat ?? null,
|
|
115
|
+
input.alias ?? null
|
|
116
|
+
)) as GenerateProofResult;
|
|
117
|
+
|
|
118
|
+
return new DPoP(result.proof, result.proofContext, input.alias);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public static async assertHardwareBacked(alias?: string): Promise<void> {
|
|
122
|
+
requireAndroid();
|
|
123
|
+
await Dpop.assertHardwareBacked(alias ?? null);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public static async deleteKeyPair(alias?: string): Promise<void> {
|
|
127
|
+
requireAndroid();
|
|
128
|
+
await Dpop.deleteKeyPair(alias ?? null);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public static async getKeyInfo(alias?: string): Promise<DPoPKeyInfo> {
|
|
132
|
+
requireAndroid();
|
|
133
|
+
return Dpop.getKeyInfo(alias ?? null) as Promise<DPoPKeyInfo>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public static async hasKeyPair(alias?: string): Promise<boolean> {
|
|
137
|
+
requireAndroid();
|
|
138
|
+
return Dpop.hasKeyPair(alias ?? null);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public static async rotateKeyPair(alias?: string): Promise<void> {
|
|
142
|
+
requireAndroid();
|
|
143
|
+
await Dpop.rotateKeyPair(alias ?? null);
|
|
144
|
+
}
|
|
145
|
+
}
|