Currently (2023.11.23) this package...
- is written in Javascript
- uses KMS for encryption and decryption
- responsible for proceeding the creation/recover of wallets
- responsible for storing users' private data to the private area
# using npm
$ npm i dekey-v2-wallet-core
# using yarn
$ yarn add dekey-v2-wallet-core
-
YOU MUST LOGIN TO GOOGLE FIRST in order to get an access token and an ID token.
-
Also, you must use Dekey v2 OAuth client for Google login.
// Example of using getKeyshare()
import { Dekey, createDekeyInstance, IDekeyConfig, DekeyOutput } from 'dekey-v2-wallet-core';
const DEKEY_CONFIG: IDekeyConfig = {
aws: {
kmsKeyId: import.meta.env.VITE_AWS_KMS_KEY_ID,
region: import.meta.env.VITE_AWS_REGION,
identityPoolId: import.meta.env.VITE_AWS_COGNITO_IDENTITY_POOL_ID,
userPoolId: import.meta.env.VITE_AWS_COGNITO_USER_POOL_ID,
tokenProvider: import.meta.env.VITE_AWS_TOKEN_PROVIDER,
credentialProvider: import.meta.env.VITE_AWS_CREDENTIAL_PROVIDER,
roleArn: import.meta.env.VITE_AWS_ROLE_ARN,
cognitoSyncDataset: import.meta.env.VITE_AWS_COGNITO_SYNC_DATASET,
},
aesSource: '',
workerFileBasePath,
appServer: {
appServerAddressProtocol: import.meta.env.VITE_APP_SERVER_ADDRESS_PROTOCOL,
appServerAddress: import.meta.env.VITE_APP_SERVER_ADDRESS,
},
mpc: {
enableMPCTLS: import.meta.env.VITE_APP_MPC_TLS,
}
};
const idToken = 'fhB7d...nql', // Google ID token
const accessToken = '9ejsk...fhk', // Google access token
const payloadOfIdToken = JSON.parse(atob(idToken.split('.')[1]));
// Different user is logged in so the data on local stroage is needed to be cleared.
if (userId !== getUserIdFromLocal()) {
// Different user is logged in so the data on local stroage is needed to be cleared.
clearLocalData();
}
// If there is a wallet address stored in Local storage already
const walletAddress = getWalletAddressFromLocal();
if (walletAddress) {
return {
walletAddress
};
}
const dekey = Dekey.createDekeyInstance(dekeyConfig);
const result = await dekey.getKeyshare({
idToken,
accessToken,
setProcess: (completed) => {
console.log(completed)
} // this is optional
})
const { sid: walletAddress } = result;
return {
walletAddress
};
-
This method will proceed KG/RG and store the keyshare backup and the private key. It also saves the keyshare(=pvenc) on the browser local storage.
-
workerFileBasePath
must point wherempc_worker.mjs
is located.
import { Dekey } from 'dekey-v2-wallet-core';
const dekey = Dekey.createDekeyInstance(dekeyConfig);
const { r, s, vsource } = await dekey.sign(
messageHash,
setProcess: (completed) => {
console.log(completed)
}
)