login 변수는 다양한 인증 방법을 포함한 위핀 로그인 라이브러리로, 사용자가 여러 방식으로 로그인할 수 있도록 합니다. 이메일 및 비밀번호 로그인, OAuth 프로바이더 로그인, ID Token 또는 Access Token을 사용한 로그인 등을 지원합니다. 각 메서드에 대한 자세한 정보는 공식 라이브러리 문서 Login Library 가이드에서 확인할 수 있습니다.
Available Methods
loginWithOauthProvider
signUpWithEmailAndPassword
loginWithEmailAndPassword
loginWithIdToken
loginWithAccessToken
getRefreshFirebaseToken
loginWepin
getCurrentWepinUser
logout
getSignForLogin
이 메서드들은 다양한 로그인 시나리오를 지원하며, 필요에 맞는 적절한 방법을 선택할 수 있습니다.
Example
// Login using an OAuth providerconstoauthResult=awaitwepinPin.login.loginWithOauthProvider({provider:'google',clientId:'your-client-id',});// Sign up and log in using email and passwordconstsignUpResult=awaitwepinPin.login.signUpWithEmailAndPassword('[email protected]','password123');// Log in to WepinconstwepinLoginResult=awaitwepinPin.login.loginWepin(signUpResult);// Get the currently logged-in userconstcurrentUser=awaitwepinPin.login.getCurrentWepinUser();// LogoutawaitwepinPin.login.logout();
generateRegistrationPINBlock
사용자의 지갑 생성 및 회원가입을 위해 필요한 PIN을 입력 받을 수 있는 핀 패드 화면을 띄우고 입력받은 PIN을 처리하여 PIN Block을 생성합니다.
Parameters
None
Return value
Promise<RegistrationPinBlock>
uvd <EncUVD> - 암호화된 PIN
b64Data <string> - b64SKey의 원본키로 암호화된 데이터
b64SKey <string> - b64Data를 생성할때 사용하는 키
seqNum <number> optional - PIN Block 사용 시 순서대로 사용되었는지 확인하기 위한 값
hint <EncPinHint>
data <string> - PIN 힌트를 암호화한 값
length <string> - PIN 힌트의 길이
version <number> - PIN 힌트의 버전
Example
generateAuthPINBlock
사용자 인증에 필요한 PIN을 입력 받을 수 있는 핀 패드 화면을 띄우고 입력받은 PIN을 처리하여 PIN Block을 생성합니다.
사용자가 2FA(OTP)를 활성화한 경우에는, OTP 코드를 입력받을 수 있는 화면도 띄우고 처리합니다.
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,
}),
});
await wepinPin.generateAuthPINBlock(count?);
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);
}