First, set up the WalletService:
import { WalletService, Crypto } from '@handcash/sdk';
const walletService = new WalletService({
appId: '<YOUR-APP-ID>',
appSecret: '<YOUR-APP-SECRET>',
});
Step 1: Email Verification
Request and verify an email code:
const email = 'user@example.com';
const requestId = await walletService.requestSignUpEmailCode(email);
const verificationCode = '01234567';
const keyPair = Crypto.generateAuthenticationKeyPair();
await walletService.verifyEmailCode(requestId, verificationCode, keyPair.publicKey);
Step 2: Create and Access Wallet
Create the wallet, store the authentication key, and access the new wallet:
const handle = 'userInputAlias';
const isAvailableHandle = await walletService.isAliasAvailable(handle);
if (!isAvailableHandle) {
throw new Error('Handle is not available');
}
await walletService.createWalletAccount(keyPair.publicKey, email, handle);
await storeAuthenticationKey(keyPair.privateKey);
const account = walletService.getWalletAccountFromAuthToken(keyPair.privateKey);
Get access to an existing wallet
import { WalletService, Crypto } from '@handcash/sdk';
const walletService = new WalletService({
appId: '<YOUR-APP-ID>',
appSecret: '<YOUR-APP-SECRET>',
});
const requestId = await walletService.requestSignInEmailCode(email);
const verificationCode = '01234567';
const keyPair = Crypto.generateAuthenticationKeyPair();
await walletService.verifyEmailCode(requestId, verificationCode, keyPair.publicKey);
await storeAuthenticationkey(keyPair.privateKey);
const account = walletService.getWalletAccountFromAuthToken(keyPair.privateKey);
Sequence Diagram
The following sequence diagram illustrates the wallet creation process:
This diagram provides a visual representation of the interaction between the User, your App, and Handcash during the wallet creation process.