Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sessions): session permissions storage API #242

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
176 changes: 176 additions & 0 deletions docs/specs/servers/blockchain/blockchain-permissions-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Blockchain API Sessions and Permissions

This API is **unstable**, not yet production ready and can be changed at any time.
geekbrother marked this conversation as resolved.
Show resolved Hide resolved

## Sessions permissions storage

### Get permissions list for account

Used to get account list of active sessions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need either a new endpoint for revoked sessions, or including a field in the pci that includes the "status" ; else we cannot displayed previously revoked sessions on the ui


`GET /v1/sessions/{address}?projectId={projectId}`

* `address` - CAIP-10 address format.
* `projectId` - Required. The project identifier.

#### Success response body:

```typescript
{
pci: string[]
}
```

* `pci` - List of sessions PCIs for this account.
geekbrother marked this conversation as resolved.
Show resolved Hide resolved

#### Response error codes:

* `400 Bad request` - Wrong requested address format.

### Get permission by PCI

Used to get permission by PCI

`GET /v1/sessions/{address}/{pci}?projectId={projectId}`

* `address` - CAIP-10 address format.
* `pci` - Permission identifier.
* `projectId` - Required. The project identifier.

#### Success response body:

```typescript
{
"permissionType": string,
"data": string,
"required": boolean,
"onChainValidated": boolean
}
```

#### Response error codes:

* `400 Bad request` - Wrong requested address format or PCI not found.

## Add a new permission

Creating a new permission session for the account

`POST /v1/sessions/{address}?projectId={projectId}`

* `address` - CAIP-10 address format.
* `projectId` - Required. The project identifier.

### Request body:

The POST request body should be in JSON format and following schema:

```typescript
{
permission:
{
"permissionType": string,
"data": string,
"required": boolean,
"onChainValidated": boolean
}
}
```

Comment on lines +80 to +93

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request body should have permission struct defined in ERC7715 + extra field onChainValidated if needed but not sure how will Dapp/Client know this( onChainValidated ) information.

#### Success response body:

Response will contain a new generated key and PCI of the new permission.

```typescript
{
pci: string,
key: string
}
```

* `pci` - New unique permission controller identifier.
* `key` - Generated signing (private) ECDSA P256 key in DER, SEC1 format encoded by Base64.
geekbrother marked this conversation as resolved.
Show resolved Hide resolved

#### Response error codes:

* `400 Bad request` - Wrong format in request.

## Updating permissions context

Updating permissions context for the certain permission idenitifier.

`POST /v1/sessions/{address}/context?projectId={projectId}`

* `address` - CAIP-10 address format.
* `projectId` - Required. The project identifier.

### Request body:

The POST request body should be in JSON format and following schema:

```typescript
{
pci: string,
signature: string,
context: {
{
geekbrother marked this conversation as resolved.
Show resolved Hide resolved
signer: {
permissionType: string,
ids: [string]
geekbrother marked this conversation as resolved.
Show resolved Hide resolved
},
expiry: number,
signerData: {
userOpBuilder: string
},
factory: string,
factoryData: string,
permissionsContext: string
}
}
}
```

* `pci` - PCI to revoke.
* `signature` - Signature of canonicalized JSON `context` object signed by the key provided during the permission creation. The signature must be provided as DER, SEC1 and encoded in Base64 format.
* `context` - Permissions context object to update.

#### Success response body:

* `200 Ok` - Successfully updated.

#### Response error codes:

* `400 Bad request` - Wrong format in request.
* `401 Unauthorized` - Wrong signature.

## Revoke permission

Revoking a permission from account sessions.

`POST /v1/sessions/{address}/revoke?projectId={projectId}`

* `address` - CAIP-10 address format.
* `projectId` - Required. The project identifier.

### Request body:

The POST request body should be in JSON format and following schema:

```typescript
{
pci: string,
signature: string,
}
```

* `pci` - PCI to revoke.
* `signature` - Signature of signed `pci` field by the key provided during the permission creation. The signature must be provided as DER, SEC1 and encoded in Base64 format.

#### Success response body:

* `200 Ok` - Successfully revoked.

#### Response error codes:

* `400 Bad request` - Wrong format in request.
* `401 Unauthorized` - Wrong signature.