# Setup SM Wallet

### **Prerequisite**&#x20;

Docker Compose&#x20;

\
**Step 1: Cloning the Repository**

Clone the repository to your local system using the following command:

```bash
git clone https://github.com/krypc-code/kc-wallet-kms.git
```

**Step 2: Setting Up the Environment**

After cloning the repository, navigate to the **`test`** folder:

```bash
cd test
```

Launch the HashiCorp Vault service using Docker Compose:

```bash
sudo docker-compose -f docker-compose-vault.yaml up -d
```

**Vault Initialization Steps:**

1. **Access the Vault UI:**

   * Start the Vault server.
   * Open a web browser and navigate to [http://127.0.0.1:8200](http://127.0.0.1:8200/).<br>

   <figure><img src="https://4251437152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAdRxsyBAvpzSSN2VFowk%2Fuploads%2FASp8U4lozpk3VfObVPLl%2Finitialize.png?alt=media&#x26;token=42d1450e-16c5-439f-9129-b7b3d7088744" alt=""><figcaption></figcaption></figure>
2. **Set Keyshare and Key Threshold:**
   * In the Vault UI, locate the settings for key sharing.
   * Set the number of key shares (e.g., 5) and the key threshold (e.g., 3).
   * These values determine the number of key parts required to unseal the vault.
3. **Generate Key Pairs:**

   * Click on the "Initialize" button in the Vault UI.
   * This action triggers the generation of a set of key and root token pairs.<br>

   <figure><img src="https://4251437152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAdRxsyBAvpzSSN2VFowk%2Fuploads%2FPfhQhKEAxo2rbhdegIRM%2Fimage.png?alt=media&#x26;token=5114d50c-9f4d-46ec-9d64-ff87eb2f48e8" alt=""><figcaption></figcaption></figure>
4. **Download and Save Keys:**

   * After initialization, download the generated keys.
   * Save the downloaded keys securely on your local machine.<br>

   <figure><img src="https://4251437152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAdRxsyBAvpzSSN2VFowk%2Fuploads%2FAz5hVPO3zxuMkR9vlEuV%2Fimage.png?alt=media&#x26;token=8bf9221b-5c21-43dd-8f54-3afe05a9ddb0" alt=""><figcaption></figcaption></figure>
5. **Provide Unseal Keys:**
   * Open the downloaded key file and find the **`keys_base64`** values.
   * Depending on the threshold set earlier, gather the required number of **`keys_base64`** values.
   * These keys will be used to unseal the vault.
6. **Unseal the Vault:**

   * In the Vault UI, locate the "Unseal" section.
   * Paste the collected **`keys_base64`** values into the designated fields, based on the threshold.
   * Click "Continue" to unseal the vault.

   <figure><img src="https://4251437152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAdRxsyBAvpzSSN2VFowk%2Fuploads%2FKaiEcsKZrKS1jhNYZ46C%2Fimage.png?alt=media&#x26;token=3fbbaca1-105a-4da7-ac74-3b369404f687" alt=""><figcaption></figcaption></figure>
7. **Provide Root Token:**

   * In the Vault UI, find the field to input the root token.
   * Enter the root token obtained during the initialization process.

   <figure><img src="https://4251437152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAdRxsyBAvpzSSN2VFowk%2Fuploads%2F6Q4WZvy7mSUxOphN0jvj%2Fimage.png?alt=media&#x26;token=c5989928-0e81-4aa4-a615-2f57285a7db1" alt=""><figcaption></figcaption></figure>
8. **Sign In to Vault:**

   * Click on the "Sign In" or "Log In" button in the Vault UI.
   * If the root token is valid, you will gain access to the Vault.

   <figure><img src="https://4251437152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAdRxsyBAvpzSSN2VFowk%2Fuploads%2FnniU6bliGXXi7eOeKkFo%2Fimage.png?alt=media&#x26;token=594d3dff-0f5d-48d4-93db-0404244bce17" alt=""><figcaption></figcaption></figure>
9. **Create New Engine:**

   * Create a new secret engine by selecting KV on the options screen.

   <figure><img src="https://4251437152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAdRxsyBAvpzSSN2VFowk%2Fuploads%2F9ZQryTUtHm4u7VjuMDRB%2Fimage.png?alt=media&#x26;token=a01121d2-b375-4911-97bb-33f037428f0f" alt=""><figcaption></figcaption></figure>
10. **Secret As Path:**

    * Create a new path with the value "secret" in the path parameter.

    <figure><img src="https://4251437152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAdRxsyBAvpzSSN2VFowk%2Fuploads%2Fs9Xb25uaRIqBaO6jtccB%2Fimage.png?alt=media&#x26;token=056da093-0e25-4276-9991-773ee4173e39" alt=""><figcaption></figcaption></figure>
11. **Vault Initialization Complete:**
    * At this point, your Vault is initialized and accessible.

Make sure to keep the downloaded keys and root token secure.

Once the Vault service is running and initialized successfully, update the environment variables in the **`config.yaml`** file as follows:

```yaml
"VAULT_URL": "http://127.0.0.1:8200",
"VAULT_TOKEN": "hvs.xxxxxxxxxxxxxxxxx",
"AUTH_TOKEN": "abd3789a-xxxx-xxxx-xxxx-ed65a2c2e7f6",
"SUBSCRIPTION_ID": "XXXXXXXXXX",
"PROXY_URL": "https://api.krypcore.com/api/v0",
"ENDPOINT": "https://polygon-mumbai-dev-node.krypcore.com/api/v0/rpc?apiKey=1ddc4575-xxxx-xxxx-xxxx-9d8a7a4086aa&token=abd3789a-xxxx-xxxx-xxxx-ed65a2c2e7f6",
"WALLET_INSTANCE_ID": "XXX_XX_XX_2023721",
"SCHEDULER_DURATION": "10"
```

you can retrieve the actual values of the&#x20;

auth token, subscription ID from krypcore dashboard.

vault\_token is the root token of the vault.&#x20;

Proxy\_url: "<https://api.krypcore.com/api/v0>" is production url which is need to be used.

endpoint url from manage dapps in mydapps.

wallet\_instance\_id from mydapps.

**Step 3: Running the Service**

Once you've configured the environment variables, come to parent directory

```
cd ...
```

Run the self-managed wallet service using the following command:

```bash
sudo run main.go
```

That's it! You should now have the Self-Managed Wallet service running on your local environment.
