Skip to content

Commit

Permalink
Use newest DID document format for cheqd mainnet (#515)
Browse files Browse the repository at this point in the history
* Use newest DID document format for `cheqd` `mainnet`

* Deduplicate

* Fix imports
  • Loading branch information
olegnn authored Feb 4, 2025
1 parent b1aaa4c commit 4309c47
Show file tree
Hide file tree
Showing 24 changed files with 202 additions and 349 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cheqd-sdk-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
env:
CHEQD_MNEMONIC: "steak come surprise obvious remain black trouble measure design volume retreat float coach amused match album moment radio stuff crack orphan ranch dose endorse"
CHEQD_IMAGE_TAG: 3.1.4
CHEQD_IMAGE_TAG: 3.1.5
CHEQD_NETWORK: "testnet"
steps:
- uses: actions/checkout@v2
Expand All @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
env:
CHEQD_MNEMONIC: "steak come surprise obvious remain black trouble measure design volume retreat float coach amused match album moment radio stuff crack orphan ranch dose endorse"
CHEQD_IMAGE_TAG: 3.0.2
CHEQD_IMAGE_TAG: 3.1.5
CHEQD_NETWORK: "mainnet"
steps:
- uses: actions/checkout@v2
Expand Down
9 changes: 9 additions & 0 deletions examples/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @docknetwork/sdk-examples

## 0.17.1

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.36.0
- @docknetwork/dock-blockchain-api@0.19.1
- @docknetwork/dock-blockchain-modules@0.24.1

## 0.17.0

### Minor Changes
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.17.0",
"version": "0.17.1",
"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.35.0",
"@docknetwork/dock-blockchain-api": "0.19.0",
"@docknetwork/dock-blockchain-modules": "0.24.0"
"@docknetwork/credential-sdk": "0.36.0",
"@docknetwork/dock-blockchain-api": "0.19.1",
"@docknetwork/dock-blockchain-modules": "0.24.1"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
Expand Down
7 changes: 7 additions & 0 deletions packages/cheqd-blockchain-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @docknetwork/cheqd-blockchain-api

## 0.28.1

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.36.0

## 0.28.0

### Minor 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.28.0",
"version": "0.28.1",
"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.35.0"
"@docknetwork/credential-sdk": "0.36.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand Down
7 changes: 7 additions & 0 deletions packages/cheqd-blockchain-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @docknetwork/cheqd-blockchain-modules

## 0.27.1

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.36.0

## 0.27.0

### Minor Changes
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.27.0",
"version": "0.27.1",
"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.35.0"
"@docknetwork/credential-sdk": "0.36.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.28.0",
"@docknetwork/cheqd-blockchain-api": "0.28.1",
"@rollup/plugin-alias": "^4.0.2",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/credential-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @docknetwork/credential-sdk

## 0.36.0

### Minor Changes

- Use newest DID document format for `cheqd` `mainnet`

## 0.35.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/credential-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/credential-sdk",
"version": "0.35.0",
"version": "0.36.0",
"license": "MIT",
"type": "module",
"files": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { valueBytes } from '../../utils';
import { CheqdMainnetDid, CheqdTestnetDid, DidRef } from '../did';
import { CheqdDidRef, CheqdMainnetDid, CheqdTestnetDid } from '../did';
import {
TypedBytes,
TypedEnum,
Expand Down Expand Up @@ -66,66 +66,22 @@ export class DockAccumulatorId extends AccumulatorId {
}
}

export class CheqdAccumulatorIdValue extends withQualifier(DidRef) {
export class CheqdAccumulatorIdValue extends CheqdDidRef {
static Qualifier = 'accumulator:cheqd:';

static Ident = withFromDockId(
TypedUUID,
DockAccumulatorId,
'accumulator:cheqd:',
);

static cheqdDid(did) {
return did.value;
}

static fromUnqualifiedString(str) {
const lastColon = str.lastIndexOf(':');
const did = `did:cheqd:${str.slice(0, lastColon)}`;
const id = str.slice(lastColon + 1);

return new this(did, id);
}

toJSON() {
return String(this);
}

toEncodedString() {
const { did, value, constructor } = this;
const { cheqdDid } = constructor;

let prefix = '';
if (cheqdDid(did) instanceof CheqdTestnetDid) {
prefix = 'testnet';
} else if (cheqdDid(did) instanceof CheqdMainnetDid) {
prefix = 'mainnet';
} else {
throw new Error(
`Can't determine DID type: \`${cheqdDid(did)}\`, instance of \`${
cheqdDid(did).constructor.name
}\``,
);
}

return `${prefix}:${did.toEncodedString()}:${value}`;
}
}

export class CheqdTestnetAccumulatorIdValue extends CheqdAccumulatorIdValue {
static Did = CheqdTestnetDid;

static cheqdDid(did) {
return did;
}
}

export class CheqdMainnetAccumulatorIdValue extends CheqdAccumulatorIdValue {
static Did = CheqdMainnetDid;

static cheqdDid(did) {
return did;
}
}

export class CheqdAccumulatorId extends AccumulatorId {
Expand Down
2 changes: 1 addition & 1 deletion packages/credential-sdk/src/types/accumulator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export * from './params';
export * from './public-key';
export * from './accumulator';
export * from './counters';
export * from './accumulator-id';
export * from './id';
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import withFromDockId, {
patchWithFromDock,
} from '../generic/with-from-dock-id';
import { CheqdBlobQualifier, DockBlobQualifier } from './const';
import { CheqdMainnetDid, CheqdTestnetDid, DidRef } from '../did';
import { CheqdDidRef, CheqdMainnetDid, CheqdTestnetDid } from '../did';
import dockDidById from '../../utils/dock-did-by-id';

export class BlobId extends withFrom(
Expand Down Expand Up @@ -59,58 +59,18 @@ export class DockBlobId extends BlobId {
}
}

export class CheqdBlobIdValue extends withQualifier(DidRef) {
export class CheqdBlobIdValue extends CheqdDidRef {
static Qualifier = CheqdBlobQualifier;

static Ident = withFromDockId(TypedUUID, DockBlobId, 'blob:cheqd:');

static fromUnqualifiedString(str) {
const lastColon = str.lastIndexOf(':');
const did = `did:cheqd:${str.slice(0, lastColon)}`;
const id = str.slice(lastColon + 1);

return new this(did, id);
}

static cheqdDid(did) {
return did.value;
}

toEncodedString() {
const { did, value, constructor } = this;
const cheqdDid = constructor.cheqdDid(did);

let prefix = '';
if (cheqdDid instanceof CheqdTestnetDid) {
prefix = 'testnet';
} else if (cheqdDid instanceof CheqdMainnetDid) {
prefix = 'mainnet';
} else {
throw new Error(
`Can't determine DID type: \`${cheqdDid(did)}\`, instance of \`${
cheqdDid(did).constructor.name
}\``,
);
}

return `${prefix}:${did.toEncodedString()}:${value}`;
}
}

export class CheqdTestnetBlobIdValue extends CheqdBlobIdValue {
static Did = CheqdTestnetDid;

static cheqdDid(did) {
return did;
}
}

export class CheqdMainnetBlobIdValue extends CheqdBlobIdValue {
static Did = CheqdMainnetDid;

static cheqdDid(did) {
return did;
}
}

export class CheqdBlobId extends BlobId {
Expand Down
16 changes: 12 additions & 4 deletions packages/credential-sdk/src/types/blob/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TypedStruct, withProp } from '../generic';
import { BlobId, CheqdBlobIdValue, DockBlobIdValue } from './blob-id';
import { BlobId, CheqdBlobIdValue, DockBlobIdValue } from './id';
import Blob from './blob';

export * from './blob-id';
export * from './id';
export { default as Blob } from './blob';

export class BlobWithId extends TypedStruct {
Expand All @@ -12,5 +12,13 @@ export class BlobWithId extends TypedStruct {
};
}

export class CheqdBlobWithId extends withProp(BlobWithId, 'id', CheqdBlobIdValue) {}
export class DockBlobWithId extends withProp(BlobWithId, 'id', DockBlobIdValue) {}
export class CheqdBlobWithId extends withProp(
BlobWithId,
'id',
CheqdBlobIdValue,
) {}
export class DockBlobWithId extends withProp(
BlobWithId,
'id',
DockBlobIdValue,
) {}
Loading

0 comments on commit 4309c47

Please sign in to comment.