# Methods

This can be used after initializing the Wepin PIN Pad Library.

## &#x20;generateRegistrationPINBlock

```kotlin
wepinPin.generateRegistrationPINBlock()
```

To display the PIN pad screen to receive the PIN required for wallet creation and user registration, process the entered PIN to create a PIN Block.

### **Parameters**

* `<void>`

### **Return value**

* `CompletableFuture` \<RegistrationPinBlock>
  * `uvd` \<EncUVD>

    * `b64Data` \<String> \
      Data encrypted with the original key of `b64SKey`.
    * `b64SKey` \<String> \
      The key used to generate `b64Data`.
    * `seqNum` \<Int> **optional** \
      A value used to verify that PIN Blocks are used in sequential order.&#x20;

  * `hint` \<EncPinHint>

    * `data` \<string> \
      &#x20;The encrypted value of the PIN hint.
    * `length` \<string>\
      The length of the PIN hint.
    * `version` \<number>&#x20;

    &#x20;      The version of the PIN hint.

### **Example**

{% tabs %}
{% tab title="Java" %}

```java
wepinPin.generateRegistrationPINBlock().whenComplete((res, err) -> {
    if (err == null) {
        RegistrationPinBlock registerPin = new RegistrationPinBlock(res.getUvd(), res.getHint());
        // You need to make a Wepin RESTful API request using the received data.
    } else {
        System.out.println(err);
    }
});

```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
wepinPin.generateRegistrationPINBlock().whenComplete { res, err ->
    if (err == null) {
        registerPin = RegistrationPinBlock(uvd = res!!.uvd, hint = res!!.hint)
        // You need to make a Wepin RESTful API request using the received data.
    } else {
      println(err)
    }
}
```

{% endtab %}
{% endtabs %}

## generateAuthPINBlock

```kotlin
wepinPin.generateAuthPINBlock(3)
```

To display the PIN pad screen to receive the PIN required for user authentication and process the entered PIN to create a PIN Block. If the user has enabled 2FA (OTP), display a screen to receive the OTP code and process it as well.

### **Parameters**

* `count` \<Int> **optional**&#x20;

  The number of PIN Blocks to be generated. The default value is 1.

### **Return value**

* `Promise` \<AuthPinBlock>
  * `uvdList` List\<EncUVD> \
    A list of encrypted PIN Blocks.
    * \<EncUVD>
      * `b64Data` \<String> \
        Data encrypted with the original key of `b64SKey`.
      * `b64SKey` \<String> \
        The key used to generate `b64Data`.
      * `seqNum` \<Int> **optional** \
        A value used to verify that PIN Blocks are used in sequential order. In a Multi Tx request, PIN Blocks must be used strictly in the received order (1, 2, 3...).
  * `otp` \<String> **optional** \
    The OTP code entered by the user if they have enabled 2FA (OTP).

### **Example**

{% tabs %}
{% tab title="Java" %}

```java
wepinPin.generateAuthPINBlock(3).whenComplete((res, err) -> {
    if (err == null) {
        AuthPinBlock authPin = new AuthPinBlock(res.getUvdList(), res.getOtp());
        // You need to make a Wepin RESTful API request using the received data.
    } else {
        System.out.println(err);
    }
});

```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
wepinPin.generateAuthPINBlock(3).whenComplete { res, err ->
    if (err == null) {
        authPin = AuthPinBlock(uvdList = res!!.uvdList, otp = res!!.otp)
        // You need to make a Wepin RESTful API request using the received data.
    } else {
      println(err)
    }
}
```

{% endtab %}
{% endtabs %}

## generateChangePINBlock

```kotlin
wepinPin.generateChangePINBlock()
```

To display the PIN pad screen to receive the PIN required for the user to change their PIN and process the entered PIN to create a PIN Block. If the user has enabled 2FA (OTP), display a screen to receive the OTP code and process it as well.

### **Parameters**

* `<void>`

### **Return Value**

* `CompletableFuture` \<ChangePinBlock>
  * `uvd` \<EncUVD>
    * `b64Data` \<String> \
      Data encrypted with the original key of `b64SKey`.
    * `b64SKey` \<String> \
      The key used to generate `b64Data`.
    * `seqNum` \<Int> **optional** \
      A value used to verify that PIN Blocks are used in sequential order.&#x20;
  * `newUVD` \<EncUVD>
    * `b64Data` \<String> \
      Data encrypted with the original key of `b64SKey`.
    * `b64SKey` \<String> \
      The key used to generate `b64Data`.
    * `seqNum` \<Int> **optional** \
      A value used to verify that PIN Blocks are used in sequential order.&#x20;
  * `hint` \<EncPinHint>

    * `data` \<string> \
      &#x20;The encrypted value of the PIN hint.
    * `length` \<string>\
      The length of the PIN hint.
    * `version` \<number>&#x20;

    &#x20;      The version of the PIN hint.
  * `otp` \<String> **optional** \
    The OTP code entered by the user if they have enabled 2FA (OTP).

### **Example**

{% tabs %}
{% tab title="Java" %}

```java
wepinPin.generateChangePINBlock().whenComplete((res, err) -> {
    if (err == null) {
        ChangePinBlock changePin = new ChangePinBlock(res.getUvd(), res.getNewUVD(), res.getHint(), res.getOtp());
        // You need to make a Wepin RESTful API request using the received data.
    } else {
        System.out.println(err);
    }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
wepinPin.generateChangePINBlock().whenComplete { res, err ->
    if (err == null) {
        changePin = ChangePinBlock(uvd = res!!.uvd, newUVD = res.newUVD, hint = res.hint, otp = res.otp)
        // You need to make a Wepin RESTful API request using the received data.
    } else {
      println(err)
    }
}
```

{% endtab %}
{% endtabs %}

## generateAuthOTP

```kotlin
wepinPin.generateAuthOTPCode()
```

Display a screen to receive the OTP code from the user and process it.

### **Parameters**

* `<void>`

### **Return Value**

* `CompletableFuture` \<AuthOTP>
  * `code` \<String>\
    The entered OTP code.

### **Example**

{% tabs %}
{% tab title="Java" %}

```java
wepinPin.generateAuthOTPCode().whenComplete((res, err) -> {
    if (err == null) {
        AuthOTP authOTPCode = new AuthOTP(res.getCode());
        // You need to make a Wepin RESTful API request using the received data.
    } else {
        System.out.println(err);
    }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
wepinPin.generateAuthOTPCode().whenComplete { res, err ->
    if (err == null) {
        authOTPCode = AuthOTP(res!!.code)
        // You need to make a Wepin RESTful API request using the received data.
    } else {
      println(err)
    }
}
```

{% endtab %}
{% endtabs %}

## finalize

```kotlin
wepinPin.finalize()
```

It terminates the use of the Wepin PIN Pad Library.

### **Parameters**

* `<void>`

### **Return Value**

* `<void>`

### **Example**

{% tabs %}
{% tab title="Java" %}

```java
wepinPin.finalize();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
wepinPin.finalize()
```

{% endtab %}
{% endtabs %}

## login

Starting from **WepinPin v1.1.0**, the `WepinLogin` SDK is integrated into `WepinPin`.\
If you choose **not to use the integrated `WepinLogin` within `WepinPin`** and instead use a separate `WepinLogin` SDK, **make sure both SDKs are using the same version**. Using mismatched versions may cause errors.

The `login` object provides various authentication methods through the Wepin Login library, allowing users to log in using different methods such as **email/password**, **OAuth providers**, or **ID/Access Tokens**.\
For more details on each method, refer to the official [Login Library Guide](/en/widget-integration/android-java-and-kotlin-sdk/login-library.md).

### **Available Methods**

* [`loginWithOauthProvider`](https://docs.wepin.io/widget-integration/ios-swift-sdk/login-library/methods#loginwithoauthprovider)
* [`signUpWithEmailAndPassword`](https://docs.wepin.io/widget-integration/ios-swift-sdk/login-library/methods#signupwithemailandpassword)
* [`loginWithEmailAndPassword`](https://docs.wepin.io/widget-integration/ios-swift-sdk/login-library/methods#loginwithemailandpassword)
* [`loginWithIdToken`](https://docs.wepin.io/widget-integration/ios-swift-sdk/login-library/methods#loginwithidtoken)
* [`loginWithAccessToken`](https://docs.wepin.io/widget-integration/ios-swift-sdk/login-library/methods#loginwithaccesstoken)
* [`getRefreshFirebaseToken`](https://docs.wepin.io/widget-integration/ios-swift-sdk/login-library/methods#getrefreshfirebasetoken)
* [`loginWepin`](https://docs.wepin.io/widget-integration/ios-swift-sdk/login-library/methods#loginwepin)
* [`getCurrentWepinUser`](https://docs.wepin.io/widget-integration/ios-swift-sdk/login-library/methods#getcurrentwepinuser)
* [`logout`](https://docs.wepin.io/widget-integration/ios-swift-sdk/login-library/methods#logoutwepin)

These methods support various login scenarios, allowing you to choose the most appropriate option based on your needs.

**Exception**

* [WepinError](https://docs.wepin.io/widget-integration/flutter-sdk/widget/methods#wepinerror)

**Example**

<pre class="language-kotlin"><code class="lang-kotlin"><strong>// Login with OAuth Provider
</strong>wepinSDK.login.loginWithOauthProvider("google", "your-client-id")
    .thenCompose { authResult ->
        // Login using ID Token
        wepinSDK.login.loginWithIdToken(authResult.idToken)
    }.thenCompose { idTokenResult ->
        // Login to Wepin
        wepinSDK.login.loginWepin(idTokenResult)
    }.thenAccept { user ->
        Log.d("WepinSDK", "Login success! User Information: $user")
    }.exceptionally { e ->
        Log.e("WepinSDK", "Login fail: ${e.message}", e)
        null
    }

// Sign up with email and password
wepinSDK.login.signUpWithEmailAndPassword(
    email = 'example@example.com', 
    password = 'password123'
).thenAccept { signUpResult ->
    Log.d("WepinSDK", "Sign up success! User Information: $user")
}.exceptionally { error ->
    if (error is WepinError) {
    }
}

// Get current logged in user information
var currentUser = wepinSDK.login.getCurrentWepinUser()
    .thenAccept { user ->
        Log.d("WepinSDK", "Current user: $user")
    }.exceptionally { e ->
        Log.e("WepinSDK", "getCurrentWepinUser fail", e)
        null
    }

// logout
wepinSDK.login.logout()
    .thenAccept { result ->
        Log.d("WepinSDK", "Logout result: $result")
    }.exceptionally { e ->
        Log.e("WepinSDK", "Logout fail", e)
        null
    }    
</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wepin.io/en/widget-integration/android-java-and-kotlin-sdk/pin-pad-library/method.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
