Skip to content

Commit

Permalink
1.0.1 - Incluimos método comprobacion NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
diegocidm4 committed Dec 7, 2024
1 parent 9d59f3c commit 81e67e0
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 23 deletions.
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ npx cap sync
* [`signTextDNIe(...)`](#signtextdnie)
* [`signDocumentDNIe(...)`](#signdocumentdnie)
* [`signHashDNIe(...)`](#signhashdnie)
* [`isNFCEnable()`](#isnfcenable)
* [Interfaces](#interfaces)

</docgen-index>
Expand Down Expand Up @@ -68,9 +69,9 @@ readPassport(options: { accessKey: String; paceKeyReference: number; tags: Strin

Lee el eID utilizando la conexión NFC.

| Param | Type | Description |
| ------------- | --------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`options`** | <code>{ accessKey: <a href="#string">String</a>; paceKeyReference: number; tags: String[]; }</code> | - <a href="#array">Array</a> que incluye los parámetros que se le envían al plugin: accessKey (Indica el can o mrz utilizado para establecer la comunicación), paceKeyReference (indica el tipo de clave usada en la conexión, se puede utilizar CAN o MRZ), tags (indica los dataGroups a leer del documento. [] para leer todos) |
| Param | Type | Description |
| ------------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`options`** | <code>{ accessKey: <a href="#string">String</a>; paceKeyReference: number; tags: String[]; }</code> | - <a href="#array">Array</a> que incluye los parámetros que se le envían al plugin: accessKey (Indica el can o mrz utilizado para establecer la comunicación), paceKeyReference (indica el tipo de clave usada en la conexión, se puede utilizar CAN o MRZ), tags (indica los dataGroups a leer del documento. [] para leer todos. En android si no se especifica DG2 no se recupera la foto y si no se especifica DG7 no se recupera la firma, el resto de DGs se recuperan siempre) |

**Returns:** <code>Promise&lt;<a href="#respuestareadpassport">RespuestaReadPassport</a>&gt;</code>

Expand Down Expand Up @@ -128,6 +129,19 @@ Firma el hash pasado como parámetro con el certificado del DNIe pasado como par
--------------------


### isNFCEnable()

```typescript
isNFCEnable() => Promise<RespuestaNFC>
```

Indica si el dispositivo móvil dispone de la tecnología NFC y si esta opción está activada.

**Returns:** <code>Promise&lt;<a href="#respuestanfc">RespuestaNFC</a>&gt;</code>

--------------------


### Interfaces


Expand Down Expand Up @@ -363,4 +377,12 @@ An object that represents a number of any kind. All JavaScript numbers are 64-bi
| **join** | (separator?: string \| undefined) =&gt; string |
| **slice** | (start?: number \| undefined, end?: number \| undefined) =&gt; T[] |


#### RespuestaNFC

| Prop | Type |
| ---------------- | ------------------------------------------- |
| **`disponible`** | <code><a href="#boolean">Boolean</a></code> |
| **`activo`** | <code><a href="#boolean">Boolean</a></code> |

</docgen-api>
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.cqesolutions.io.idniecap;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.nfc.NfcAdapter;
import android.nfc.NfcManager;
import android.util.Base64;

import androidx.activity.result.ActivityResult;
Expand Down Expand Up @@ -362,4 +365,37 @@ public void signHashDNIe(PluginCall call){
call.resolve(ret);

}

@PluginMethod
public void isNFCEnable(PluginCall call){
Boolean disponible = true;
Boolean activo = true;

NfcManager manager = (NfcManager) getActivity().getApplicationContext().getSystemService(Context.NFC_SERVICE);
NfcAdapter adapter = manager.getDefaultAdapter();

if(adapter==null) {
try{
disponible = false;
}
catch (IllegalStateException ignored) {
// There's no way to avoid getting this if saveInstanceState has already been called.
}
}
else if (!adapter.isEnabled()) {
try{
activo = false;
}
catch (IllegalStateException ignored) {
// There's no way to avoid getting this if saveInstanceState has already been called.
}
}


JSObject ret = new JSObject();
ret.put("disponible",disponible);
ret.put("activo", activo);
call.resolve(ret);

}
}
19 changes: 19 additions & 0 deletions ios/Sources/idniecapPlugin/idniecap.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import iDNIe
import CoreNFC

@objc public class idniecap: NSObject {

Expand Down Expand Up @@ -589,4 +590,22 @@ import iDNIe

}

@objc public func isNFCEnable() -> [String: Any] {

guard NFCNDEFReaderSession.readingAvailable else {
var json: [String: Any] = [:]
json["disponible"] = false
json["activo"] = false

return json
}


var json: [String: Any] = [:]
json["disponible"] = true
json["activo"] = true

return json

}
}
9 changes: 7 additions & 2 deletions ios/Sources/idniecapPlugin/idniecapPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class idniecapPlugin: CAPPlugin, CAPBridgedPlugin {
CAPPluginMethod(name: "signTextDNIe", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "signDocumentDNIe", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "signHashDNIe", returnType: CAPPluginReturnPromise),
// CAPPluginMethod(name: "authenticationDNIeOpenSession", returnType: CAPPluginReturnPromise),
// CAPPluginMethod(name: "signChallengeDNIe", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "isNFCEnable", returnType: CAPPluginReturnPromise),
]
private let implementation = idniecap()

Expand Down Expand Up @@ -92,4 +91,10 @@ public class idniecapPlugin: CAPPlugin, CAPBridgedPlugin {

call.resolve(json)
}

@objc func isNFCEnable(_ call: CAPPluginCall) {
let json = implementation.isNFCEnable()

call.resolve(json)
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "idniecap",
"version": "1.0.0",
"version": "1.0.1",
"description": "Librería para el uso del DNIe en ionic. Disponible para android e iOS.",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down
13 changes: 8 additions & 5 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export interface idniecapPlugin {
*/
signHashDNIe(options: {accessKey: String, pin: String, hash: Array<Number>, digest: number, certToUse: String}) : Promise<RespuestaFirma>;

/**
* Indica si el dispositivo móvil dispone de la tecnología NFC y si esta opción está activada.
*/
isNFCEnable() : Promise<RespuestaNFC>;

}

export const PACEHandler = {
Expand Down Expand Up @@ -158,10 +163,8 @@ export interface RespuestaFirma {
error: String | undefined
}

/*
export interface RespuestaAutenticacion {
respueta: Boolean,
error: String | undefined
export interface RespuestaNFC {
disponible: Boolean,
activo: Boolean
}
*/

14 changes: 2 additions & 12 deletions src/web.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WebPlugin } from '@capacitor/core';

import type { EstadoLicencia, idniecapPlugin, MRZKey, RespuestaFirma, RespuestaReadPassport } from './definitions';
import type { EstadoLicencia, idniecapPlugin, MRZKey, RespuestaFirma, RespuestaNFC, RespuestaReadPassport } from './definitions';

export class idniecapWeb extends WebPlugin implements idniecapPlugin {
getMRZKey(options: {passportNumber: String, dateOfBirth: String, dateOfExpiry: String}): Promise<MRZKey> {
Expand Down Expand Up @@ -38,18 +38,8 @@ export class idniecapWeb extends WebPlugin implements idniecapPlugin {
console.log(options);
throw new Error('Method not implemented.');
}
/*
async authenticationDNIeOpenSession(options: {accessKey: String, pin: String}) : Promise<RespuestaAutenticacion>
{
console.log("NOT IMPLEMENTED");
console.log(options);
throw new Error('Method not implemented.');
}

async signChallengeDNIe(options: {hash: Array<Number>, digest: Number, signPadding: String}) : Promise<RespuestaAutenticacion>{
console.log("NOT IMPLEMENTED");
console.log(options);
async isNFCEnable(): Promise<RespuestaNFC> {
throw new Error('Method not implemented.');
}
*/
}

0 comments on commit 81e67e0

Please sign in to comment.