-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Berend Sliedrecht <[email protected]>
- Loading branch information
1 parent
a822967
commit 22f24ad
Showing
3 changed files
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { requireNativeModule } from 'expo-modules-core' | ||
import type { SecureEnvironment } from './SecureEnvironment' | ||
|
||
type UnwrapPromiseReturnTypes<T, ExcludedKey extends keyof T = never> = { | ||
[K in keyof T]: K extends ExcludedKey | ||
? T[K] | ||
: T[K] extends (...args: infer A) => Promise<infer R> | infer S | ||
? (...args: A) => Promise<R> extends Promise<infer U> ? U : Promise<R> | S | ||
: T[K] | ||
} | ||
|
||
const nativeExpoSecureEnvironment = requireNativeModule< | ||
UnwrapPromiseReturnTypes<Omit<SecureEnvironment, 'batchGenerateKeyPair'>, 'sign'> & { | ||
supportsSecureEnvironment: () => boolean | ||
} | ||
>('ExpoSecureEnvironment') | ||
|
||
export const expoSecureEnvironment = { | ||
generateKeypair: (keyId: string, biometricsBacked?: boolean): Uint8Array => { | ||
nativeExpoSecureEnvironment.generateKeypair(keyId, biometricsBacked) | ||
const publicKey = expoSecureEnvironment.getPublicBytesForKeyId(keyId) | ||
return publicKey | ||
}, | ||
|
||
batchGenerateKeyPair: (keyIds: Array<string>): Record<string, Uint8Array> => { | ||
for (const keyId of keyIds) { | ||
expoSecureEnvironment.generateKeypair(keyId) | ||
} | ||
|
||
return keyIds | ||
.map((keyId) => ({ | ||
keyId, | ||
publicKey: expoSecureEnvironment.getPublicBytesForKeyId(keyId), | ||
})) | ||
.reduce((prev, curr) => ({ ...prev, [curr.keyId]: curr.publicKey }), {}) | ||
}, | ||
|
||
getPublicBytesForKeyId: (keyId: string): Uint8Array => { | ||
return nativeExpoSecureEnvironment.getPublicBytesForKeyId(keyId) | ||
}, | ||
|
||
sign: (keyId: string, message: Uint8Array, biometricsBacked?: boolean): Promise<Uint8Array> => { | ||
return nativeExpoSecureEnvironment.sign(keyId, message, biometricsBacked) | ||
}, | ||
|
||
supportsSecureEnvironment: () => { | ||
return nativeExpoSecureEnvironment.supportsSecureEnvironment() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters