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

StatusListCredential module for cheqd #487

Merged
merged 24 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
# @docknetwork/sdk-examples

## 0.6.0

### Minor Changes

- `StatusListCredential` module for `cheqd`, misc tweaks

### Patch Changes

- Updated dependencies
- @docknetwork/[email protected]
- @docknetwork/[email protected]
- @docknetwork/[email protected]


## 0.5.2

### Patch Changes

- Updated dependencies
- @docknetwork/[email protected]
- @docknetwork/[email protected]
- @docknetwork/[email protected]

- Audit fixes and RDF lib upgrade
- Updated dependencies
- @docknetwork/[email protected]
Expand Down
8 changes: 4 additions & 4 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@docknetwork/sdk-examples",
"private": true,
"type": "module",
"version": "0.5.2",
"version": "0.6.0",
"scripts": {
"bbs-dock-example": "babel-node ./bbs-dock.js",
"claim-deduction-example": "babel-node ./claim-deduction.js",
Expand All @@ -19,9 +19,9 @@
"lint": "eslint \"*.js\""
},
"dependencies": {
"@docknetwork/credential-sdk": "0.13.0",
"@docknetwork/dock-blockchain-api": "0.6.2",
"@docknetwork/dock-blockchain-modules": "0.8.1"
"@docknetwork/credential-sdk": "0.14.0",
"@docknetwork/dock-blockchain-api": "0.8.0",
"@docknetwork/dock-blockchain-modules": "0.9.0"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "root",
"version": "0.14.0",
"version": "0.16.0",
"private": true,
"workspaces": [
"packages/*",
Expand Down
19 changes: 19 additions & 0 deletions packages/cheqd-blockchain-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# @docknetwork/cheqd-blockchain-api

## 0.13.0

### Minor Changes

- `StatusListCredential` module for `cheqd`, misc tweaks

### Patch Changes

- Updated dependencies
- @docknetwork/[email protected]

## 0.12.0

### Minor Changes

- Small refactoring of the `did/document`

### Patch Changes

## 0.11.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/cheqd-blockchain-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/cheqd-blockchain-api",
"version": "0.11.1",
"version": "0.13.0",
"license": "MIT",
"main": "./dist/esm/index.js",
"type": "module",
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"@cheqd/sdk": "cjs",
"@docknetwork/credential-sdk": "0.13.0"
"@docknetwork/credential-sdk": "0.14.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand Down
15 changes: 9 additions & 6 deletions packages/cheqd-blockchain-api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
MsgCreateResourcePayload,
protobufPackage as resourceProtobufPackage,
} from '@cheqd/ts-proto/cheqd/resource/v2/index.js';
import { DIDRef, NamespaceDid } from '@docknetwork/credential-sdk/types';
import { DidRef, NamespaceDid } from '@docknetwork/credential-sdk/types';
import { TypedEnum } from '@docknetwork/credential-sdk/types/generic';

export class CheqdAPI extends AbstractApiProvider {
Expand Down Expand Up @@ -88,12 +88,14 @@ export class CheqdAPI extends AbstractApiProvider {
}

/**
* @returns {void}
* @returns {Promise<this>}
*/
async disconnect() {
this.ensureInitialized();

delete this.sdk;

return this;
}

/**
Expand Down Expand Up @@ -177,20 +179,21 @@ export class CheqdAPI extends AbstractApiProvider {

supportsIdentifier(id) {
this.ensureInitialized();
const { network } = this.sdk.options;

if (id instanceof NamespaceDid) {
if (id.isCheqd) {
if (id.asCheqd.isTestnet) {
return this.sdk.options.network === CheqdNetwork.Testnet;
return network === CheqdNetwork.Testnet;
} else if (id.asCheqd.isMainnet) {
return this.sdk.options.network === CheqdNetwork.Mainnet;
return network === CheqdNetwork.Mainnet;
}
}
} else if (id instanceof DIDRef) {
} else if (id instanceof DidRef) {
return this.supportsIdentifier(id[0]);
} else if (id instanceof TypedEnum) {
return this.supportsIdentifier(id.value);
} else if (id?.constructor?.Qualifier?.includes('cheqd:')) {
} else if (id?.constructor?.Qualifier?.includes(`cheqd:${network}:`)) {
return true;
}

Expand Down
12 changes: 12 additions & 0 deletions packages/cheqd-blockchain-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# @docknetwork/cheqd-blockchain-modules

## 0.11.0

### Minor Changes

- `StatusListCredential` module for `cheqd`, misc tweaks

### Patch Changes

- Updated dependencies
- @docknetwork/[email protected]

## 0.10.1

### Patch Changes

- Audit fixes and RDF lib upgrade

- Updated dependencies
- @docknetwork/[email protected]

Expand Down
6 changes: 3 additions & 3 deletions packages/cheqd-blockchain-modules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/cheqd-blockchain-modules",
"version": "0.10.1",
"version": "0.11.0",
"type": "module",
"license": "MIT",
"main": "./dist/esm/index.js",
Expand Down Expand Up @@ -33,7 +33,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.13.0"
"@docknetwork/credential-sdk": "0.14.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand All @@ -42,7 +42,7 @@
"@babel/plugin-syntax-import-attributes": "^7.25.6",
"@babel/plugin-transform-modules-commonjs": "^7.24.1",
"@babel/preset-env": "^7.24.3",
"@docknetwork/cheqd-blockchain-api": "0.11.1",
"@docknetwork/cheqd-blockchain-api": "0.13.0",
"@rollup/plugin-alias": "^4.0.2",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/cheqd-blockchain-modules/src/attest/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const methods = {
export default class CheqdInternalAttestModule extends createInternalCheqdModule(
methods,
) {
static Prop = 'resource';

static MsgNames = {
setClaim: 'MsgCreateResource',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { TypedUUID } from '@docknetwork/credential-sdk/types/generic';
import { CheqdPayloadWithTypeUrl } from './payload';

/**
* Creates DID method transaction builder.
* Creates DID transaction constructor.
*/
export const createDIDMethodTx = (fnName) => {
const createDIDMethodTx = (fnName) => {
const obj = {
async [fnName](...args) {
const { root } = this;
Expand Down Expand Up @@ -43,7 +43,7 @@ export const createDIDMethodTx = (fnName) => {
/**
* Creates a call.
*/
export const createCall = (fnName) => {
const createCall = (fnName) => {
const obj = {
async [fnName](...args) {
const { root } = this;
Expand All @@ -58,19 +58,21 @@ export const createCall = (fnName) => {
return obj[fnName];
};

/**
* Creates a transaction builder for account method with the given name.
*/
export const createAccountTx = (fnName) => {
const obj = {
async [fnName](...args) {
return await this.root.rawTx[fnName](
...this.root.payload[fnName].apply(this.root, args),
);
},
};
const filterNoResourceError = async (promise, placeholder) => {
try {
return await promise;
} catch (err) {
const strErr = String(err);

if (
!strErr.includes('DID Doc not found')
&& !strErr.includes('not found: unknown request')
) {
throw err;
}
}

return obj[fnName];
return placeholder;
};

class Root {
Expand All @@ -80,7 +82,7 @@ class Root {
}

/* eslint-disable sonarjs/cognitive-complexity */
export function createInternalCheqdModule(
export default function createInternalCheqdModule(
methods = Object.create(null),
baseClass = class CheqdModuleBaseClass {},
) {
Expand All @@ -89,27 +91,8 @@ export function createInternalCheqdModule(
class RootModule extends (baseClass.RootModule ?? Root) {}
class RootSender extends (baseClass.RootSender ?? Root) {}

const filterNoResourceError = async (promise, placeholder) => {
try {
return await promise;
} catch (err) {
const strErr = String(err);

if (
!strErr.includes('DID Doc not found')
&& !strErr.includes('not found: unknown request')
) {
throw err;
}
}

return placeholder;
};

const obj = {
[name]: class extends baseClass {
static Prop;

static RootPayload = RootPayload;

static RootModule = RootModule;
Expand Down Expand Up @@ -185,10 +168,6 @@ export function createInternalCheqdModule(
return meta[0] ?? null;
}

get query() {
return this.apiProvider.sdk.querier[this.constructor.Prop];
}

get tx() {
return new RootModule(this);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cheqd-blockchain-modules/src/common/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './builders';
export { default as createInternalCheqdModule } from './create-internal-cheqd-module';
export * from './payload';
export { default as injectCheqd } from './inject-cheqd';
export { default as CheqdApiProvider } from './cheqd-api-provider';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
u8aToString,
} from '@docknetwork/credential-sdk/utils';
import { CheqdParamsId } from '@docknetwork/credential-sdk/types';
import { createInternalCheqdModule } from './builders';
import createInternalCheqdModule from './create-internal-cheqd-module';
import { CheqdCreateResource } from './payload';

const methods = {
Expand Down
4 changes: 2 additions & 2 deletions packages/cheqd-blockchain-modules/src/common/payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export class CheqdPayloadAndSignatures extends TypedStruct {

export class CheqdPayloadWithTypeUrl extends TypedStruct {
static Classes = {
typeUrl: TypedString,
typeUrl: class TypeURL extends TypedString {},
value: CheqdPayloadAndSignatures,
};
}

export class CheqdCreateResource extends TypedStruct {
static Classes = {
collectionId: TypedUUID,
collectionId: class CollectionID extends TypedUUID {},
id: class ResourceId extends TypedUUID {},
version: class Version extends TypedString {},
alsoKnownAs: class AlsoKnownAs extends TypedArray {
Expand Down
4 changes: 1 addition & 3 deletions packages/cheqd-blockchain-modules/src/did/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ const methods = {
};

export class CheqdDIDModuleInternal extends createInternalCheqdModule(methods) {
static Prop = 'did';

static MsgNames = {
createDidDocument: 'MsgCreateDidDoc',
updateDidDocument: 'MsgUpdateDidDoc',
deactivateDidDocument: 'MsgDeactivateDidDoc',
};

async getDidDocumentWithMetadata(did) {
return await this.query.didDoc(String(CheqdDid.from(did)));
return await this.apiProvider.sdk.querier.did.didDoc(String(CheqdDid.from(did)));
}
}
Loading
Loading