Skip to content

Commit

Permalink
Merge pull request #7 from peaqnetwork/feature/rbac-new-changes
Browse files Browse the repository at this point in the history
update(code): new changes of rbac is done
  • Loading branch information
rohanranjan250613 authored Aug 22, 2023
2 parents 44592b8 + 7cfc52d commit c86d991
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "peaq network <[email protected]>",
"name": "@peaq-network/sdk",
"version": "0.4.0",
"version": "0.4.4",
"description": "peaq network sdk",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/modules/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class Base {
protected async _newSignTx(option: SignTransction): Promise<PeaqEvent[]> {
return new Promise<PeaqEvent[]>(async (resolve, reject) => {
const { extrinsics, nonce, address, statusCallback } = option;
const api = await this._getApi();
const api = this._getApi();
let subscribed = false;

try {
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/src/modules/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Options, SDKMetadata } from '../../types';

import { Base } from '../base';
import { Did } from '../did';
import { RBAC } from "../rbac";

/**
* Main class for interacting with the SDK.
Expand All @@ -16,6 +17,7 @@ export class Main extends Base {
protected override _api: ApiPromise;
private _metadata: SDKMetadata;
public did: Did;
public rbac: RBAC;

constructor(options: Options) {
super();
Expand All @@ -24,6 +26,7 @@ export class Main extends Base {
this._metadata = {};

this.did = new Did(this._api, this._metadata);
this.rbac = new RBAC(this._api, this._metadata);
}

/**
Expand Down
17 changes: 10 additions & 7 deletions packages/sdk/src/modules/rbac/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ export class RBAC extends Base {
* @returns A promise that resolves when the role is created.
*/

public async createRole(options: CreateNewRole) {
public async createRole(options: CreateNewRole): Promise<{
roleId: string;
}> {
try {
const { roleName, roleId = '', address = '', seed = '' } = options;
if (!roleName) throw new Error('Name is required');
Expand All @@ -207,8 +209,7 @@ export class RBAC extends Base {
extrinsics: addRoleExtrinsics,
});
return {
hash: addRoleExtrinsics.hash as unknown as CodecHash,
roleId: roleId || convertedRoleId,
roleId: roleId || generatedRoleId,
};
} catch (error) {
throw new Error(`Error occurred while creating roles: ${error}`);
Expand All @@ -221,7 +222,9 @@ export class RBAC extends Base {
* @returns A promise that resolves when the group is created.
*/

public async createNewGroup(options: CreateNewGroup) {
public async createNewGroup(options: CreateNewGroup): Promise<{
groupId: string;
}> {
try {
const { groupName, groupId = '', address = '', seed = '' } = options;
if (!groupName) throw new Error('Name is required');
Expand All @@ -242,7 +245,6 @@ export class RBAC extends Base {
extrinsics: addGroupExtrinsics,
});
return {
hash: addGroupExtrinsics.hash as unknown as CodecHash,
groupId: groupId || generatedGroupId,
};
} catch (error) {
Expand All @@ -256,7 +258,9 @@ export class RBAC extends Base {
* @returns A promise that resolves when the permission is created.
*/

public async createPermission(options: CreateNewPermission) {
public async createPermission(options: CreateNewPermission): Promise<{
permissionId: string;
}> {
try {
const {
permissionName,
Expand Down Expand Up @@ -284,7 +288,6 @@ export class RBAC extends Base {
extrinsics: addPermissionExtrinsics,
});
return {
hash: addPermissionExtrinsics.hash as unknown as CodecHash,
permissionId: permissionId || generatedPermissionId,
};
} catch (error) {
Expand Down
4 changes: 0 additions & 4 deletions packages/sdk/src/modules/rbac/rbac.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('RBAC', () => {
roleName: name,
address: alice.address,
});
expect(result.hash).toBeDefined();
expect(typeof result.roleId).toBe('string');
});

Expand All @@ -44,7 +43,6 @@ describe('RBAC', () => {
address: alice.address,
roleId: 'bcmnxbncvbnxvcnbvxnbcvnxbvchvchvxchgvchgvxcnbv',
});
expect(result.hash).toBeDefined();
expect(typeof result.roleId).toBe('string');
});

Expand Down Expand Up @@ -97,7 +95,6 @@ describe('RBAC', () => {
address: alice.address,
});
groupId = result.groupId;
expect(result.hash).toBeDefined();
expect(typeof result.groupId).toBe('string');
}, 30000);

Expand Down Expand Up @@ -159,7 +156,6 @@ describe('RBAC', () => {
permissionName: permissionName,
});
permissionId = result.permissionId;
expect(result.hash).toBeDefined();
expect(typeof result.permissionId).toBe('string');
}, 30000);

Expand Down

0 comments on commit c86d991

Please sign in to comment.