🖥️Sample Code
Demo Application
Importing Classes
Start by importing the necessary classes from the SDK in your JavaScript file:
import Wallet from 'didpass-wallet-sdk';
Creating a Wallet Instance
Create a new instance of the Wallet class using the create
static method. Provide the authServerBaseUrl
and a storage instance implementing the IStorage
interface:
const authServerBaseUrl: string = "YOUR_AUTH_SERVER_BASE_URL";
const storage: IStorage = // Your implementation of the IStorage interface
const wallet: Wallet = Wallet.create(authServerBaseUrl, storage);
Here is an example implementation of IStorage written in React Native
import { IStorage } from 'didpass-wallet-sdk';
class SecureStorage implements IStorage {
async get<T>(key: string): Promise<T | null> {
const result = await SecureStore.getItemAsync(key);
if (result) {
return JSON.parse(result) as T;
} else {
return null;
}
}
async set<T>(key: string, value: T): Promise<void> {
await SecureStore.setItemAsync(key, JSON.stringify(value));
}
async remove(key: string): Promise<void> {
await SecureStore.deleteItemAsync(key);
}
}
Wallet Creation
Creates a new ethereum wallet.
const result = await wallet.walletManagement.createWallet({
deviceId: deviceId,
token
});
Wallet Import
Handle to bring your wallet you already have.
const result = await wallet.walletManagement.importWallet({
deviceId,
token,
mnemonic
});
Wallet Recovery
Handle to recover your lost a wallet by recovering it.
const result = await wallet.walletManagement.recoverWallet({
deviceId,
token,
spk,
shares
});
Wallet Deletion
Handle deletion of your existing wallet.
await wallet.walletManagement.deleteWallet({
deviceId,
token
spk
});
With the Wallet instance created, you have access to various functionalities.
Last updated