Skip to content

Commit

Permalink
Merge pull request #30 from peaqnetwork/fix/1208238364944982_generate…
Browse files Browse the repository at this point in the history
…-did-hash-offline

Fix/1208238364944982 Generate Did Hash Offline
  • Loading branch information
jpgundrum authored Sep 6, 2024
2 parents 176489d + 34037a3 commit 4c554e5
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 142 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "peaq-network",
"version": "0.6.3",
"version": "0.6.4",
"license": "MIT",
"scripts": {
"prepare": "ts-patch install -s"
Expand Down
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.6.3",
"version": "0.6.4",
"description": "peaq network sdk",
"license": "Apache-2.0",
"repository": {
Expand Down
244 changes: 119 additions & 125 deletions packages/sdk/src/modules/did/did.spec.ts

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions packages/sdk/src/modules/did/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Service = {
data?: string;
}

interface GenerateDidOptions {
export interface GenerateDidOptions {
address: Address;
customDocumentFields?: CustomDocumentFields;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ interface RemoveDidOptions {
seed?: string;
}

interface GenerateDidResult {
export interface GenerateDidResult {
value: string;
}

Expand Down Expand Up @@ -155,7 +155,7 @@ export class Did extends Base {
* Creates a new DID by adding a new attribute to the PEAQ DID registry.
*
* @param options - The options for creating the DID.
* @returns block_hash - Hash that is searchable on a block explorer to see transaction.
* @returns CreateDidResult - Contains the block_hash of the executed transaction and unsubscribe() to terminate event listening.
*/
public async create(
options: CreateDidOptions,
Expand Down Expand Up @@ -245,6 +245,12 @@ export class Did extends Base {
}
}

/**
* Updates a previously created DID Document and overwrites the previously set data.
*
* @param options: UpdateDidOptions = {address: Address, customDocumentFields?: CustomDocumentFields}
* @returns UpdateDidResult - Contains log information, block_hash of the executed transaction and unsubscribe() to terminate event listening.
*/
public async update(options: UpdateDidOptions,
statusCallback?: (result: ISubmittableResult) => void | Promise<void>
): Promise<UpdateDidResult | null> {
Expand Down Expand Up @@ -298,7 +304,13 @@ export class Did extends Base {
}
}

// TODO add custom errors

/**
* Removes a previously created DID Document.
*
* @param options: UpdateDidOptions = {address: Address, customDocumentFields?: CustomDocumentFields}
* @returns RemoveDidResult - Contains log information, block_hash of the executed transaction and unsubscribe() to terminate event listening.
*/
public async remove(options: RemoveDidOptions,
statusCallback?: (result: ISubmittableResult) => void | Promise<void>
): Promise<RemoveDidResult | null> {
Expand Down
18 changes: 10 additions & 8 deletions packages/sdk/src/modules/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import { unsubscribeRuntimeVersion } from '../../utils';
import type { Options, SDKMetadata } from '../../types';

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


/**
* Main class for interacting with the SDK.
*/
export class Main extends Base {
private readonly _options: Options;
protected override _api: ApiPromise;
private _metadata: SDKMetadata;

public did: Did;
public rbac: RBAC;

Expand Down Expand Up @@ -43,15 +45,15 @@ export class Main extends Base {
}

/**
* Creates a new offline instance of the SDK to use the generate function.
* Generates a hash of the DID Document without connecting to the chain.
*
* @param None
* @returns The created offline instance of the SDK.
* @param GenerateDidOptions - The options for generating a DID.
* @returns The hash value of the generated DID document
*/
public static async createOfflineInstance(): Promise<Main> {
const sdk = new Main({});
return sdk;
}
public static async generateDidDocument(options: GenerateDidOptions): Promise<GenerateDidResult> {
const did = new Did();
return did.generate(options);
}

/**
* Connects the SDK to the network.
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "peaq network <[email protected]>",
"name": "@peaq-network/types",
"version": "0.6.3",
"version": "0.6.4",
"license": "Apache-2.0",
"description": "Typescript definitions for the peaq network",
"repository": {
Expand Down

0 comments on commit 4c554e5

Please sign in to comment.