diff --git a/src/SecureEnvironment.ts b/src/SecureEnvironment.ts index b736286..486a69d 100644 --- a/src/SecureEnvironment.ts +++ b/src/SecureEnvironment.ts @@ -17,7 +17,7 @@ export interface SecureEnvironment { sign(keyId: string, message: Uint8Array, biometricsBacked?: boolean): Promise } -let isExpoSecureEnvironmentSupported: boolean +export let isExpoSecureEnvironmentSupported: boolean let fallbackSecureEnvironment: SecureEnvironment export const setFallbackSecureEnvironment = (env: SecureEnvironment) => { fallbackSecureEnvironment = env diff --git a/src/index.ts b/src/index.ts index 3edfbe5..0241a0e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,10 +12,15 @@ export async function generateKeypair(id: string, biometricsBacked = true): Prom export async function getPublicBytesForKeyId(keyId: string): Promise { const publicBytes = await getSecureEnvironment().getPublicBytesForKeyId(keyId) + let uncompressedKey = publicBytes - if (Platform.OS === 'android') { + if (Platform.OS === 'android' && publicBytes.length > 65) { + // Try to parse it from the ASN.1 SPKI format const spki = AsnParser.parse(publicBytes, SubjectPublicKeyInfo) - const uncompressedKey = new Uint8Array(spki.subjectPublicKey) + uncompressedKey = new Uint8Array(spki.subjectPublicKey) + } + + if (Platform.OS === 'android') { if (uncompressedKey.length !== 65 || uncompressedKey[0] !== 0x04) { throw new Error('Invalid uncompressed key format') } @@ -31,7 +36,6 @@ export async function getPublicBytesForKeyId(keyId: string): Promise const compressedKey = new Uint8Array(33) compressedKey[0] = prefix compressedKey.set(x, 1) - return compressedKey }