createPermission(permissionName, permissionId, address, seed)

Used to create a new permission within the RBAC (Role-Based Access Control) system.

ParameterTypeEVMSubstrateDescription
permissionNamestringRequiredRequiredName of the permission to be created.
permissionIdstringOptionalOptionalID of the permission (32 bytes). If not supplied one will be generated for you.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.

Create Permission Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const EVM_PRIVATE = process.env["EVM_PRIVATE"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const permissionName = "peaq-permission-1";
const permission = await sdk.rbac.createPermission({
    permissionName: permissionName
});

// Send using Sdk function
const receipt = await Sdk.sendEvmTx({
  tx: permission.tx,
  baseUrl: HTTPS_BASE_URL,
  seed: EVM_PRIVATE
});

// log to see the generated id
console.log(permission.permissionId);
The EVM tx returns in a different form than what was used throughout the sdk. The purpose of this is to show the permission-id that was autogenerated if it was not manually set. That way you are able to take note of the permission-id for that permission-name set.

fetchPermission(owner, permissionId, wssBaseUrl)

Fetch a permission at the given permissionId and address.

ParameterTypeEVMSubstrateDescription
ownerstringRequiredRequiredAddress representing the owner of the permission
permissionIdstringRequiredRequiredID of the permission to be fetched.
wssBaseUrlstringRequiredN/AWSS URL used to query RBAC storage.

Fetch Group Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

// example of a previously created permission id
const permissionId = "31bc8f97-c587-4784-a725-b6c73eed";

const response = await sdk.rbac.fetchPermission({
    owner: EVM_ADDRESS,
    permissionId: permissionId,
    wssBaseUrl: WSS_BASE_URL
});

fetchPermissions(owner, wssBaseUrl)

Used to fetch all the permissions associated with the passed owner address

ParameterTypeEVMSubstrateDescription
ownerstringRequiredRequiredAddress representing the owner of all the fetched permissions.
wssBaseUrlstringRequiredN/AWSS URL used to query RBAC storage.

Fetch Permissions Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const response = await sdk.rbac.fetchPermissions({
    owner: EVM_ADDRESS,
    wssBaseUrl: WSS_BASE_URL
});

updatePermission(permissionName, permissionId, address, seed)

Allows the owner to update the permission name.

ParameterTypeEVMSubstrateDescription
permissionNamestringRequiredRequiredUpdated permission name.
permissionIdstringRequiredRequiredID of the permission (32 bytes) to be updated.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.

Update Permission Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];
const EVM_PRIVATE = process.env["EVM_PRIVATE"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

// new permission name that will be set
const permissionName = "peaq-permission-new";

// example of a previously created permission id
const permissionId = "31bc8f97-c587-4784-a725-b6c73eed";

// build the evm tx
const tx = await sdk.rbac.updatePermission({
    permissionName: permissionName,
    permissionId: permissionId
});

// send using Sdk function
const receipt = await Sdk.sendEvmTx({
  tx: tx,
  baseUrl: HTTPS_BASE_URL,
  seed: EVM_PRIVATE
});

// fetch permission to confirm the name change
const response = await sdk.rbac.fetchPermission({
    owner: EVM_ADDRESS,
    permissionId: permissionId,
    wssBaseUrl: WSS_BASE_URL
});

disablePermission(permissionId, address, seed)

Disables a permission within a permission management system.

ParameterTypeEVMSubstrateDescription
permissionIdstringRequiredRequiredThe unique identifier (ID) of the permission to be disabled.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.

Disable Permission Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];
const EVM_PRIVATE = process.env["EVM_PRIVATE"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

// permission id to disable
const permissionId = "31bc8f97-c587-4784-a725-b6c73eed";

// build the evm tx
const tx = await sdk.rbac.disablePermission({
    permissionId: permissionId
});

// send using Sdk function
const receipt = await Sdk.sendEvmTx({
  tx: tx,
  baseUrl: HTTPS_BASE_URL,
  seed: EVM_PRIVATE
});

// Fetch permission to confirm it has been changed to disabled
const response = await sdk.rbac.fetchPermission({
    owner: EVM_ADDRESS,
    permissionId: permissionId,
    wssBaseUrl: WSS_BASE_URL
});

assignPermissionToRole(permissionId, roleId, address, seed)

This function allows to assign a permission to a role in a permission management system.

ParameterTypeEVMSubstrateDescription
permissionIdstringRequiredRequiredID of the permission to be assigned to the role.
roleIdstringRequiredRequiredID of the role to which the permission will be assigned.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.

Assign Permission to Role Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const EVM_PRIVATE = process.env["EVM_PRIVATE"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const permissionId = "31bc8f97-c587-4784-a725-b6c73eed";
const roleId = "b68a5589-1284-49e9-8276-0359a429";

// build the evm tx
const tx = await sdk.rbac.assignPermissionToRole({
    permissionId: permissionId,
    roleId: roleId
});

// send using Sdk function
const receipt = await Sdk.sendEvmTx({
  tx: tx,
  baseUrl: HTTPS_BASE_URL,
  seed: EVM_PRIVATE
});

fetchRolePermissions(owner, roleId, wssBaseUrl)

Designed to retrieve permissions associated with a specific role.

ParameterTypeEVMSubstrateDescription
ownerstringRequiredRequiredAddress of the owner of the roles.
roleIdstringRequiredRequiredID of the role for whom permissions are to be fetched.
wssBaseUrlstringRequiredN/AWSS URL used to query RBAC storage.

Fetch Role Permissions Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const roleId = "b68a5589-1284-49e9-8276-0359a429";

const response = await sdk.rbac.fetchRolePermissions({
    owner: EVM_ADDRESS,
    roleId: roleId,
    wssBaseUrl: WSS_BASE_URL
});

unassignPermissionToRole(permissionId, roleId, address, seed)

This function allows to unassign a permission from a role in a permission management system.

ParameterTypeEVMSubstrateDescription
permissionIdstringRequiredRequiredID of the permission to be unassigned.
roleIdstringRequiredRequiredID of the role from which to unassign the permission.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.

Unassign Permission from Role Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];
const EVM_PRIVATE = process.env["EVM_PRIVATE"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const permissionId = "31bc8f97-c587-4784-a725-b6c73eed";
const roleId = "b68a5589-1284-49e9-8276-0359a429";

const tx = await sdk.rbac.unassignPermissionToRole({
    permissionId: permissionId,
    roleId: roleId
});

// send using Sdk function
const receipt = await Sdk.sendEvmTx({
  tx: tx,
  baseUrl: HTTPS_BASE_URL,
  seed: EVM_PRIVATE
});

// fetch to see it has been unassigned
const response = await sdk.rbac.fetchRolePermissions({
    owner: EVM_ADDRESS,
    roleId: roleId,
    wssBaseUrl: WSS_BASE_URL
});

fetchUserPermission(owner, userId, wssBaseUrl)

Fetches the permissions associated with a user.

ParameterTypeEVMSubstrateDescription
ownerstringRequiredRequiredAddress of the owner of the permissions.
userIdstringRequiredRequiredID of the user for whom you want to fetch permissions.
wssBaseUrlstringRequiredN/AWSS URL used to query RBAC storage.

In order to fetch a user permission the following flow must take place:

  1. Create permission
  2. Create role
  3. Assign permission to role
  4. Assign role to user
  5. Fetch user permissions

The following code shows this flow.

Fetch User Permissions Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];
const EVM_PRIVATE = process.env["EVM_PRIVATE"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM 
});

// 1. Create a permission
const permissionName = "peaq-permission-2";
const txPermission = await sdk.rbac.createPermission({permissionName: permissionName});
await Sdk.sendEvmTx({tx: txPermission.tx, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});

// 2. Create a role
const roleName = "peaq-role-2";
const txRole = await sdk.rbac.createRole({roleName: roleName});
await Sdk.sendEvmTx({tx: txRole.tx, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});

// 3. Assign permission to role
const tx = await sdk.rbac.assignPermissionToRole({permissionId: txPermission.permissionId, roleId: txRole.roleId});
await Sdk.sendEvmTx({tx: tx, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});

// 4. Assign role to user
const userId = "9e8c7866-8435-4b76-8683-709a03c9";
const tx2 = await sdk.rbac.assignRoleToUser({userId: userId, roleId: txRole.roleId});
await Sdk.sendEvmTx({tx: tx2, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});

// 5. Fetch user permissions
const response = await sdk.rbac.fetchUserPermissions({owner: EVM_ADDRESS, userId: userId, wssBaseUrl: WSS_BASE_URL});

fetchGroupPermissions(owner, groupId, wssBaseUrl)

Fetches the permissions associated with a group.

ParameterTypeEVMSubstrateDescription
ownerstringRequiredRequiredAddress of the owner of the permissions.
groupIdstringRequiredRequiredID of the group for whom you want to fetch permissions.
wssBaseUrlstringRequiredN/AWSS URL used to query RBAC storage.

In order to fetch a group permission the following flow must take place:

  1. Create permission
  2. Create role
  3. Assign permission to role
  4. Create group
  5. Assign role to group
  6. Fetch group permissions

The following code shows this flow.

Fetch Group Permissions Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];
const EVM_PRIVATE = process.env["EVM_PRIVATE"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM 
});

// 1. Create a permission
const permissionName = "peaq-permission-2";
const txPermission = await sdk.rbac.createPermission({permissionName: permissionName});
await Sdk.sendEvmTx({tx: txPermission.tx, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});

// 2. Create a role
const roleName = "peaq-role-2";
const txRole = await sdk.rbac.createRole({roleName: roleName});
await Sdk.sendEvmTx({tx: txRole.tx, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});

// 3. Assign permission to role
const tx = await sdk.rbac.assignPermissionToRole({permissionId: txPermission.permissionId, roleId: txRole.roleId});
await Sdk.sendEvmTx({tx: tx, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});

// 4. Create group
const groupName = "peaq-group-2";
const txGroup = await sdk.rbac.createGroup({groupName: groupName});
await Sdk.sendEvmTx({tx: txGroup.tx, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});

// 5. Assign role to group
const tx2 = await sdk.rbac.assignRoleToGroup({groupId: txGroup.groupId, roleId: txRole.roleId});
await Sdk.sendEvmTx({tx: tx2, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});

// 6. Fetch group permissions
const response = await sdk.rbac.fetchGroupPermissions({owner: EVM_ADDRESS, groupId: txGroup.groupId, wssBaseUrl: WSS_BASE_URL});