> For the complete documentation index, see [llms.txt](https://docs.wepin.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wepin.io/widget-integration/react-native-sdk/pin-pad-library/methods.md).

# 메서드

## login

`login` 변수는 다양한 인증 방법을 포함한 위핀 로그인 라이브러리로, 사용자가 여러 방식으로 로그인할 수 있도록 합니다. 이메일 및 비밀번호 로그인, OAuth 프로바이더 로그인, ID Token 또는 Access Token을 사용한 로그인 등을 지원합니다. 각 메서드에 대한 자세한 정보는 공식 라이브러리 문서  [Login Library 가이드](/widget-integration/react-native-sdk/login-library.md)에서 확인할 수 있습니다.

#### **Available Methods**

* `loginWithOauthProvider`
* `signUpWithEmailAndPassword`
* `loginWithEmailAndPassword`
* `loginWithIdToken`
* `loginWithAccessToken`
* `getRefreshFirebaseToken`
* `loginWepin`
* `getCurrentWepinUser`
* `logout`
* `getSignForLogin`

이 메서드들은 다양한 로그인 시나리오를 지원하며, 필요에 맞는 적절한 방법을 선택할 수 있습니다.

#### **Example**

```javascript
// Login using an OAuth provider
const oauthResult = await wepinPin.login.loginWithOauthProvider({
  provider: 'google',
  clientId: 'your-client-id',
});

// Sign up and log in using email and password
const signUpResult = await wepinPin.login.signUpWithEmailAndPassword(
  'example@example.com',
  'password123'
);

// Log in to Wepin
const wepinLoginResult = await wepinPin.login.loginWepin(signUpResult);

// Get the currently logged-in user
const currentUser = await wepinPin.login.getCurrentWepinUser();

// Logout
await wepinPin.login.logout();
```

## generateRegistrationPINBlock

```javascript
await wepinPin.generateRegistrationPINBlock();
```

사용자의 지갑 생성 및 회원가입을 위해 필요한 PIN을 입력 받을 수 있는 핀 패드 화면을 띄우고 입력받은 PIN을 처리하여 PIN Block을 생성합니다.

#### **Parameters**

* None

#### **Return value**

* Promise\<RegistrationPinBlock>
  * `uvd` \<EncUVD> - 암호화된 PIN
    * `b64Data` \<string> - b64SKey의 원본키로 암호화된 데이터
    * `b64SKey` \<string> - b64Data를 생성할때 사용하는 키
    * `seqNum` \<number> **optional** - **P**IN Block 사용 시 순서대로 사용되었는지 확인하기 위한 값
  * `hint` \<EncPinHint>&#x20;
    * `data` \<string> - PIN 힌트를 암호화한 값
    * `length` \<string> - PIN 힌트의 길이
    * `version` \<number> - PIN 힌트의 버전

#### **Example**

```javascript
const pinBlock = await wepinPin.generateRegistrationPINBlock();

// You need to make a Wepin RESTful API request using the received data.
fetch('https://sdk.wepin.io/v1/app/register', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    // Add authentication headers
  },
  body: JSON.stringify({
    // Add other required fields
    UVD: pinBlock.uvd,
    hint: pinBlock.hint,
  }),
});
```

## generateAuthPINBlock

```javascript
await wepinPin.generateAuthPINBlock(count?);
```

사용자 인증에 필요한 PIN을 입력 받을 수 있는 핀 패드 화면을 띄우고 입력받은 PIN을 처리하여 PIN Block을 생성합니다.

사용자가 2FA(OTP)를 활성화한 경우에는, OTP 코드를 입력받을 수 있는 화면도 띄우고 처리합니다.

#### **Parameters**

* `count` \<number> **optional** - 생성하려는 PIN Block의 개수. 기본값은 `1` 입니다.

#### **Return value**

* Promise\<AuthPinBlock>
  * `uvdList` \<EncUVD\[]> - 암호화된 PIN Block의 리스트
    * `b64Data` \<string> - b64SKey의 원본 키로 암호화된 데이터
    * `b64SKey` \<string> - b64Data 를 생성할 때 사용하는 키
    * `seqNum` \<number> **optional** - **P**IN Block 사용 시 순서대로 사용되었는지 확인하기 위한 값. Multi Tx 요청 시, 반드시 받은 PIN Block의 순서대로 사용해야 합니다.(1,2,3...)
  * `otp` \<string> **optional** - 사용자가 2FA(OTP) 를 활성화한 경우, 입력받은 OTP 코드

#### **Example**

```javascript
const pinBlock = await wepinPin.generateAuthPINBlock(3);

// Sort seqNum of uvd in ascending order from 1 because you need to write it in order starting from 1
pinBlock.uvdList.sort((a, b) => (a.seqNum ?? 0) - (b.seqNum ?? 0));

const resArray = [];
for (const encUVD of pinBlock.uvdList) {
  const response = await fetch('https://sdk.wepin.io/v1/tx/sign', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      // Add authentication headers
    },
    body: JSON.stringify({
      userId: await getUserId(),
      walletId: await getWalletId(),
      accountId: (await getEthereumAccount()).accountId,
      type: 'msg_sign',
      txData: {
        data: '0x0',
      },
      pin: encUVD,
      otpCode: {
        code: pinBlock.otp,
      },
    }),
  });
  resArray.push(response);
}
```

## generateChangePINBlock

```javascript
await wepinPin.generateChangePINBlock();
```

사용자 PIN 변경을 위해 PIN을 입력 받을 수 있는 핀 패드 화면을 띄우고 입력받은 PIN을 처리하여 PIN Block을 생성합니다.

사용자가 2FA(OTP)를 활성화한 경우에는, OTP 코드를 입력받을 수 있는 화면도 띄우고 처리합니다.

#### **Parameters**

* None

#### **Return value**

* Promise\<ChangePinBlock>
  * `uvd` \<EncUVD>  - 사용자의 암호화된 기존 PIN
    * `b64Data` \<string> - b64SKey의 원본키로 암호화된 데이터
    * `b64SKey` \<string> - b64Data 를 생성할때 사용하는 키
    * `seqNum` \<number> **optional** -**P**IN Block 사용 시 순서대로 사용되었는지 확인하기 위한 값
  * `newUVD` \<EncUVD> - 사용자의 암호화된 새로운 PIN
    * `b64Data` \<string> - b64SKey의 원본 키로 암호화된 데이터
    * `b64SKey` \<string> - b64Data 를 생성할 때 사용하는 키
    * `seqNum` \<number> **optional** - **P**IN Block 사용 시 순서대로 사용되었는지 확인하기 위한 값are used in order
  * `hint` \<EncPinHint>&#x20;
    * `data` \<string> - PIN 힌트를 암호화한 값
    * `length` \<string> - PIN 힌트의 길이
    * `version` \<number> - PIN 힌트의 버전
  * `otp` \<string> **optional** - 사용자가 2FA(OTP) 를 활성화한 경우, 입력받은 OTP 코드

#### **Example**

```javascript
const pinBlock = await wepinPin.generateChangePINBlock();

const response = await fetch('https://sdk.wepin.io/v1/wallet/pin/change', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    // Add authentication headers
  },
  body: JSON.stringify({
    userId: await getUserId(),
    walletId: await getWalletId(),
    UVD: pinBlock.uvd,
    newUVD: pinBlock.newUVD,
    hint: pinBlock.hint,
    otpCode: {
      code: pinBlock.otp,
    },
  }),
});
```

## generateAuthOTPCode

```javascript
await wepinPin.generateAuthOTPCode();
```

사용자로부터 OTP 코드를 입력받을 수 있는 화면을 띄우고 처리합니다.

#### **arameters**

* None

#### **Return value**

* Promise\<AuthOTP>
  * `code` \<string> - 입력받은 OTP 코드

#### **Example**

```javascript
let res = await getWepinSignMessage(pinBlocks.uvdList, pinBlock.otp);
if (res.body[0].message === 'OTP_MISMATCH_WRONG_CODE') {
  const otp = await wepinPin.generateAuthOTPCode();
  res = await getWepinSignMessage(pinBlocks.uvdList, otp.code);
}
```

## finalize

```javascript
await wepinWidget.getStatus();
```

&#x20;Wepin PIN Pad SDK 사용을 종료합니다.

#### **Parameters**

* None

#### **Return value**

* Promise\<void>

#### **Example**

```javascript
await wepinPin.finalize();
```

## WepinError

이 섹션에서는 Wepin SDK 기능을 사용하는 동안 발생할 수 있는 다양한 오류 코드에 대한 설명을 제공합니다.\
각 오류 코드는 특정 문제에 대응하며, 이를 이해하면 디버깅 및 오류 처리를 보다 효과적으로 수행할 수 있습니다.

| Error Code                   | Description                                                                               |
| ---------------------------- | ----------------------------------------------------------------------------------------- |
| `ApiRequestError`            | There was an error while making the API request.                                          |
| `InvalidParameters`          | One or more parameters provided are invalid or missing.                                   |
| `NotInitialized`             | The Wepin SDK has not been properly initialized.                                          |
| `InvalidAppKey`              | The Wepin app key is invalid.                                                             |
| `InvalidLoginProvider`       | The login provider specified is not supported or is invalid.                              |
| `InvalidToken`               | The token does not exist.                                                                 |
| `InvalidLoginSession`        | The login session information does not exist.                                             |
| `UserCancelled`              | The user has cancelled the operation.                                                     |
| `UnknownError`               | An unknown error has occurred, and the cause is not identified.                           |
| `NotConnectedInternet`       | The system is unable to detect an active internet connection.                             |
| `FailedLogin`                | The login attempt has failed due to incorrect credentials or other issues.                |
| `AlreadyLogout`              | The user is already logged out, so the logout operation cannot be performed again.        |
| `AlreadyInitialized`         | The Wepin SDK is already initialized.                                                     |
| `InvalidEmailDomain`         | The provided email address's domain is not allowed or recognized by the system.           |
| `FailedSendEmail`            | The system encountered an error while sending an email.                                   |
| `RequiredEmailVerified`      | Email verification is required to proceed with the requested operation.                   |
| `IncorrectEmailForm`         | The provided email address does not match the expected format.                            |
| `IncorrectPasswordForm`      | The provided password does not meet the required format or criteria.                      |
| `NotInitializedNetwork`      | The network or connection required for the operation has not been properly initialized.   |
| `RequiredSignupEmail`        | The user needs to sign up with an email address to proceed.                               |
| `FailedEmailVerified`        | The Wepin SDK encountered an issue while attempting to verify the provided email address. |
| `FailedPasswordStateSetting` | Failed to set the password state.                                                         |
| `FailedPasswordSetting`      | The Wepin SDK failed to set the password.                                                 |
| `ExistedEmail`               | The provided email address is already registered in Wepin.                                |
| `NotActivity`                | The Context is not an activity.                                                           |
