# Solace Protocol

Bringing Access Control & Sessions to Web3

## Feature Highlights

### Ephemeral (Session) keys

Using the Solace's Ephemeral Keys, provide your users with an easy web2 like user journey. \
Request permissions once & never bother you user again.

### Access Control

Using Solace, you can provide institution grade access control at a wallet level. Your clients can have an audited treasury management system with various wallets having audited & controlled access to the treasury.

{% hint style="info" %}
This feature is heavily under development and not recommended for production
{% endhint %}

### Gas free transactions

Help your users transact gas free or pay gas in ERC-20 tokens

### Customized transaction messaging & easy integration

Register your contracts using the Solace Contract Connect Dashboard and integrate them in your Front end app with 1 line of code. No more front-end ABI & Provider management.


# Web (Alpha Version)


# 🙏 Setting Up

### Installation

```bash
npm install @solacelabs/solace-connect
```

### Usage

#### Importing the SDK

Firstly, import the SDK into your project using the following line of code:

```typescript
import { SolaceConnect } from '@solacelabs/solace-connect';
```

```
```


# 💳 Connecting/Creating a Wallet

### Initialize SolaceConnect

You can initialize the SolaceConnect by providing the project id, JSON-RPC provider and optionally a mode. The mode could be 'local' or not provided.

```typescript
const solaceConnect = new SolaceConnect(projectId, provider, mode);
```

#### Connect to Solace Wallet

Establish a connection with the Solace Wallet using the connect method:

```typescript
solaceConnect.connect().then((solaceAddress) => {
  console.log("Connected to Solace Wallet: " + solaceAddress);
}).catch((err) => {
  console.error("Failed to connect: ", err);
});
```

#### Check Connection

You can check if the SDK is connected to the Solace Wallet with the `isConnected` method:

```typescript
const isConnected = solaceConnect.isConnected();
console.log("Is connected: " + isConnected);
```


# 🗝️ Session Key Usage

### Request Signing Permission

You can request permissions for function signing with the `requestSigningPermission` method:

```typescript
const data = {
  privateKey: 'YOUR_NEW_PRIVATE_EPHEMERAL_KEY',
  permissions: [ /* permissions array */ ],
  id: 'YOUR_ID'
};
solaceConnect.requestSigningPermission(data).then((signers) => {
  console.log("Received signers: ", signers);
}).catch((err) => {
  console.error("Failed to request signing permission: ", err);
});
```

### Attach Session

You can attach a session to the Solace Connect instance using the `attachSession` method:

```typescript
solaceConnect.attachSession('YOUR_JWT_TOKEN');
```

### Get Session Token

You can retrieve the current session token using the `getSessionToken` method:

```typescript
solaceConnect.getSessionToken().then((sessionToken) => {
  console.log("Session token: " + sessionToken);
}).catch((err) => {
  console.error("Failed to get session token: ", err);
});
```

### Get Solace Signer

You can retrieve a SolaceSigner instance using the `getSolaceSigner` method:

```typescript
const ephemeralSigner = { /* your ephemeral signer object */ };
solaceConnect.getSolaceSigner(ephemeralSigner).then((signer) => {
  console.log("Received SolaceSigner: ", signer);
}).catch((err) => {
  console.error("Failed to get SolaceSigner: ", err);
});
```


# React Native (Alpha Version)


# 🙏 Setting Up

### Installation

```bash
npm install react-native-keychain react-native-rsa-native
npm install @solacelabs/solace-connect
```

### Usage

#### Importing the SDK

Firstly, import the SDK into your project using the following line of code:

```typescript
import { SolaceConnect } from '@solacelabs/solace-connect';
```

```
```


# ⛓️ Connecting using Solace Connect

### Initialize SolaceConnect

You can initialize the SolaceConnect by providing the project id, JSON-RPC provider and optionally a mode. The mode could be 'local' or not provided.

```typescript
const solaceConnect = new SolaceConnect(projectId, provider, mode);
```

#### Connect to Solace Wallet

Establish a connection with the Solace Wallet using the connect method:

```typescript
solaceConnect.connect().then((solaceAddress) => {
  console.log("Connected to Solace Wallet: " + solaceAddress);
}).catch((err) => {
  console.error("Failed to connect: ", err);
});
```

#### Check Connection

You can check if the SDK is connected to the Solace Wallet with the `isConnected` method:

```typescript
const isConnected = solaceConnect.isConnected();
console.log("Is connected: " + isConnected);
```


# 🔑 Session Key Usage

### Request Signing Permission

You can request permissions for function signing with the `requestSigningPermission` method:

```typescript
const data = {
  privateKey: 'YOUR_NEW_PRIVATE_EPHEMERAL_KEY',
  permissions: [ /* permissions array */ ],
  id: 'YOUR_ID'
};
solaceConnect.requestSigningPermission(data).then((signers) => {
  console.log("Received signers: ", signers);
}).catch((err) => {
  console.error("Failed to request signing permission: ", err);
});
```

### Attach Session

You can attach a session to the Solace Connect instance using the `attachSession` method:

```typescript
solaceConnect.attachSession('YOUR_JWT_TOKEN');
```

### Get Session Token

You can retrieve the current session token using the `getSessionToken` method:

```typescript
solaceConnect.getSessionToken().then((sessionToken) => {
  console.log("Session token: " + sessionToken);
}).catch((err) => {
  console.error("Failed to get session token: ", err);
});
```

### Get Solace Signer

You can retrieve a SolaceSigner instance using the `getSolaceSigner` method:

```typescript
const ephemeralSigner = { /* your ephemeral signer object */ };
solaceConnect.getSolaceSigner(ephemeralSigner).then((signer) => {
  console.log("Received SolaceSigner: ", signer);
}).catch((err) => {
  console.error("Failed to get SolaceSigner: ", err);
});
```


# Adding Contracts

<img src="https://3758551079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1tpK0KGzGtlXCArNaYd%2Fuploads%2FGb7LPX0QhnINAJN5pN2p%2Fimage.png?alt=media&amp;token=39a9f4a4-de59-46c2-8c99-6b9483144c2b" alt="" data-size="original">![](https://3758551079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1tpK0KGzGtlXCArNaYd%2Fuploads%2FE6Q1Z8wmT56vsVXZRde2%2Fimage.png?alt=media\&token=071adc78-e9fe-4073-8161-d822217f571d)

After you've logged into the dashboard, you can add new smart contracts to your project.

Follow these steps to add a contract:

1. Navigate to the top right corner of the dashboard and click on the "Add Contract" button.
2. In the form that appears, fill out the necessary information about your deployed contract:
   * **Contract Name**: Enter a name for your contract. This is for your reference and can be anything that helps you identify the contract in your dashboard.
   * **Contract Address**: Input the address where your contract has been deployed on the blockchain.
   * **ABI (Application Binary Interface)**: Here, you'll need to provide the ABI of your contract. The ABI is a JSON representation of your contract's methods and events that allows the SDK to understand how to interact with your contract.

If you don't have your contract's ABI, follow these steps to generate it:

#### Generating ABI

After you have written your smart contract, compile it using the Solidity compiler (solc). Here is a command line example:

```bash
bashCopy codesolc --abi YourContract.sol -o build
```

This will output a `.json` file in the `build` directory. The ABI will be contained in that file.

You can also use online IDEs like Remix. In Remix, compile your contract and click on ABI in the compilation details. This will copy the ABI to your clipboard.

After obtaining the ABI, paste it into the ABI field in the form.

### Function Types

After you've successfully added the contract, SolaceConnect SDK can understand the different functions available in your contract. It does this by parsing the ABI you provided.

The SolaceConnect SDK makes it easier to interact with these functions by providing you with methods to create transaction requests and signing permissions. Refer to the `requestSigningPermission` method in the SDK to see how to interact with these contract functions.

<br>


# Adding Functions

![](https://3758551079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1tpK0KGzGtlXCArNaYd%2Fuploads%2FAvZGnqhFLPHxgHhugRD9%2Fimage.png?alt=media\&token=266111ee-ac51-4577-b18a-dd0bde01ea4a)![](https://3758551079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1tpK0KGzGtlXCArNaYd%2Fuploads%2FU9EdJi3gqDHHurTKHL5l%2Fimage.png?alt=media\&token=2dfbb39f-1354-4cd4-b9ed-5c11d8f96c3b)![](https://3758551079-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FC1tpK0KGzGtlXCArNaYd%2Fuploads%2FrL2eKUwD7LyM7ExqxUjG%2Fimage.png?alt=media\&token=7d4c5f67-b9ef-4304-ab15-acbcf7e818e0)

Similar to adding contracts, click on the add function button on the top right hand side, Select one of the contracts you previously added, and then select a function from pre-populated list of functions we got from your ABI, which are valid for user signatures and then if you choose to enable access control for these function, provide the values for which you would like your users to sign. Here, the types can be address, string, uint or bytes. \
Keep in mind that for uint, we allow you to input a mix max range, so as long as the value you are putting in matches the range during the function call, the user operation will be carried out successfully. \
if the value put in is out of range, the SDK will throw an error back to you

### Auto-generated Descriptions

After you've selected the function you want to add, SolaceConnect Dashboard will auto-generate a description for this function. This description will be used to describe the operations that your users are granting permission for when they interact with your application.

While the auto-generated description is designed to accurately represent the function's purpose, you have the option to edit it if you wish. This can be helpful if you want to provide more context or use specific terminology that your users might be familiar with.

However, please note that any modifications to the auto-generated description will be evaluated using our AI model (GPT) for appropriateness and accuracy. This is to ensure that the descriptions remain clear, accurate, and user-friendly.

This feature aims to streamline the process of adding new functions and ensures that users are always informed about the permissions they are granting. It also saves you the trouble of coming up with descriptions yourself while ensuring consistency and clarity across all function descriptions.

### Naming Conventions and Function Descriptions

The naming of your contract functions plays a crucial role in auto-generating clear and accurate descriptions. When you are developing your smart contracts, we strongly advise using names that clearly represent what each function does. Not only does this improve the readability of your code, but it also makes the functions' purposes more understandable for the end-users interacting with your application through SolaceConnect.

In the context of SolaceConnect, well-named functions translate into better auto-generated descriptions. These descriptions are pivotal in providing users with a clear understanding of the permissions they are granting. Consequently, users are more likely to feel comfortable interacting with your application when they can easily understand what each function does.

By following good naming practices, you can improve the user experience, enhance the clarity of function permissions, and ultimately increase the trustworthiness of your application.


# How does Solace Work?

TBD


# Solace Wallet Lifecycle


# Meta Transactions


# ERC-4337 & Sessions


