Skip to content

Commit

Permalink
fix(ios): remove double auth issue (#3)
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht authored Aug 3, 2024
1 parent a0c0f8f commit dadf4e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ios/ExpoSecureEnvironmentModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class ExpoSecureEnvironmentModule: Module {
}

AsyncFunction("sign") {
(id: String, message: Data, biometricsBacked: Bool) async throws -> Data in
return try await SecureEnvironment.sign(id, message, biometricsBacked)
(id: String, message: Data) async throws -> Data in
return try await SecureEnvironment.sign(id, message)
}
}
}
12 changes: 1 addition & 11 deletions ios/SecureEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,8 @@ struct SecureEnvironment {
return compressPublicKey(data)
}

static func sign(_ keyId: String, _ message: Data, _ biometricsBacked: Bool) async throws -> Data
static func sign(_ keyId: String, _ message: Data) async throws -> Data
{
if biometricsBacked {
let status = try await LAContext().evaluatePolicy(
.deviceOwnerAuthenticationWithBiometrics,
localizedReason: "Access signer key to sign a message")

guard status else {
throw SecureEnvironmentError.BiometricAuthenticationFailed
}
}

let key = try getKeyFromKeychainById(keyId)
var error: Unmanaged<CFError>?
guard
Expand Down
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ export async function sign(
message: Uint8Array,
biometricsBacked: boolean = true
): Promise<Uint8Array> {
const signature = await ExpoSecureEnvironmentModule.sign(keyId, message, biometricsBacked);
const signature =
Platform.OS === "ios"
? await ExpoSecureEnvironmentModule.sign(keyId, message)
: await ExpoSecureEnvironmentModule.sign(
keyId,
message,
biometricsBacked,
biometricsBacked
);

const { r, s } = AsnParser.parse(signature, ECDSASigValue);
const newR = new Uint8Array(r.byteLength === 33 ? r.slice(1) : r);
Expand Down

0 comments on commit dadf4e6

Please sign in to comment.