Skip to content

Commit

Permalink
cheqd payloads (#491)
Browse files Browse the repository at this point in the history
* Fix `toJSON`/`fromJSON` for `cheqd` payloads

* Versions
  • Loading branch information
olegnn authored Dec 6, 2024
1 parent a5389b2 commit 3cc2188
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 41 deletions.
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.6.3

### Patch Changes

- Updated dependencies
- @docknetwork/credential-sdk@0.17.0
- @docknetwork/dock-blockchain-api@0.8.3
- @docknetwork/dock-blockchain-modules@0.9.3

## 0.6.2

### Patch 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.6.2",
"version": "0.6.3",
"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.16.0",
"@docknetwork/dock-blockchain-api": "0.8.2",
"@docknetwork/dock-blockchain-modules": "0.9.2"
"@docknetwork/credential-sdk": "0.17.0",
"@docknetwork/dock-blockchain-api": "0.8.3",
"@docknetwork/dock-blockchain-modules": "0.9.3"
},
"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.14.2

### Patch Changes

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

## 0.14.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.14.1",
"version": "0.14.2",
"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.16.0"
"@docknetwork/credential-sdk": "0.17.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand Down
11 changes: 11 additions & 0 deletions packages/cheqd-blockchain-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @docknetwork/cheqd-blockchain-modules

## 0.12.0

### Minor Changes

- Fix `toJSON`/`fromJSON` for `cheqd` payloads

### Patch Changes

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

## 0.11.2

### Patch 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.11.2",
"version": "0.12.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.16.0"
"@docknetwork/credential-sdk": "0.17.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.14.1",
"@docknetwork/cheqd-blockchain-api": "0.14.2",
"@rollup/plugin-alias": "^4.0.2",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
CheqdDid,
} from '@docknetwork/credential-sdk/types';
import { TypedUUID } from '@docknetwork/credential-sdk/types/generic';
import { CheqdPayloadWithTypeUrl } from './payload';

/**
* Creates DID transaction constructor.
Expand All @@ -30,7 +29,7 @@ const createDIDMethodTx = (fnName) => {
signatures,
};

return new CheqdPayloadWithTypeUrl(
return new payload.constructor.ResourcePayloadWithTypeUrlAndSignatures(
root.constructor.MsgNames[fnName],
value,
);
Expand Down
64 changes: 51 additions & 13 deletions packages/cheqd-blockchain-modules/src/common/payload.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
import {
VerificationMethodSignature,
CheqdDid,
CheqdDIDDocument,
} from '@docknetwork/credential-sdk/types';
import {
Any,
TypedArray,
TypedString,
TypedStruct,
TypedBytesArray,
TypedUUID,
} from '@docknetwork/credential-sdk/types/generic';

export class CheqdPayloadAndSignatures extends TypedStruct {
static Classes = {
payload: Any,
signatures: class Signatures extends TypedArray {
static Class = VerificationMethodSignature;
const createTypes = (Payload) => {
const payloadWithSigsName = `CheqdPayloadWithSignatures(${Payload.name})`;
const payloadWithTypeUrlAndSigsName = `CheqdPayloadWithTypeUrlAndSignatures(${Payload.name})`;

const obj1 = {
[payloadWithSigsName]: class extends TypedStruct {
static Classes = {
payload: Payload,
signatures: class Signatures extends TypedArray {
static Class = VerificationMethodSignature;
},
};
},
};
}

export class CheqdPayloadWithTypeUrl extends TypedStruct {
static Classes = {
typeUrl: class TypeURL extends TypedString {},
value: CheqdPayloadAndSignatures,
const obj2 = {
[payloadWithTypeUrlAndSigsName]: class extends TypedStruct {
static Classes = {
typeUrl: class TypeURL extends TypedString {},
value: obj1[payloadWithSigsName],
};
},
};
}

// eslint-disable-next-line
Payload.ResourcePayloadWithTypeUrlAndSignatures = obj2[payloadWithTypeUrlAndSigsName];

return [
obj1[payloadWithSigsName],
obj2[payloadWithTypeUrlAndSigsName],
];
};

export class CheqdCreateResource extends TypedStruct {
static Classes = {
Expand All @@ -40,3 +56,25 @@ export class CheqdCreateResource extends TypedStruct {
data: class Data extends TypedBytesArray {},
};
}

export class DeactivateDidDocument extends TypedStruct {
static Classes = {
id: CheqdDid,
versionId: TypedUUID,
};
}

export const [
CheqdCreateResourcePayloadWithSignatures,
CheqdCreateResourcePayloadWithTypeUrlAndSignatures,
] = createTypes(CheqdCreateResource);

export const [
CheqdSetDidDocumentPayloadWithSignatures,
CheqdSetDidDocumentPayloadWithTypeUrlAndSignatures,
] = createTypes(CheqdDIDDocument);

export const [
CheqdDeactivateDidDocumentPayloadWithSignatures,
CheqdDeactivateDidDocumentPayloadWithTypeUrlAndSignatures,
] = createTypes(DeactivateDidDocument);
10 changes: 1 addition & 9 deletions packages/cheqd-blockchain-modules/src/did/internal.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { CheqdDid } from '@docknetwork/credential-sdk/types/did/onchain/typed-did';
import {
TypedUUID,
TypedStruct,
} from '@docknetwork/credential-sdk/types/generic';
import { DIDDocument } from '@docknetwork/credential-sdk/types/did';
import { createInternalCheqdModule } from '../common';
import { createInternalCheqdModule, DeactivateDidDocument } from '../common';

const parseDocument = (document) => DIDDocument.from(document).toCheqd();

class DeactivateDidDocument extends TypedStruct {
static Classes = {
id: CheqdDid,
versionId: TypedUUID,
};
}

const methods = {
createDidDocument: parseDocument,
updateDidDocument: parseDocument,
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.17.0

### Minor Changes

- Fix `toJSON`/`fromJSON` for `cheqd` payloads

## 0.16.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.16.0",
"version": "0.17.0",
"license": "MIT",
"type": "module",
"files": [
Expand Down
4 changes: 2 additions & 2 deletions packages/credential-sdk/src/utils/bytes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { applyToValue } from './interfaces';
import { ensureBytes, ensureString } from './type-helpers';
import { ensureBytes, ensureString, isBytes } from './type-helpers';

/**
* Check if the given input is hexadecimal or not. Optionally checks for the byte size of the hex. Case-insensitive on hex chars
Expand Down Expand Up @@ -125,7 +125,7 @@ export const stringToHex = (str) => u8aToHex(stringToBuffer(str));
export const normalizeToU8a = (bytes) => {
if (bytes instanceof Uint8Array) {
return bytes;
} else if (bytes instanceof Buffer || Array.isArray(bytes)) {
} else if (isBytes(bytes)) {
return u8aToU8a(bytes);
} else if (isHex(bytes)) {
return hexToU8a(bytes);
Expand Down
7 changes: 7 additions & 0 deletions packages/dock-blockchain-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @docknetwork/dock-blockchain-api

## 0.8.3

### Patch Changes

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

## 0.8.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/dock-blockchain-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/dock-blockchain-api",
"version": "0.8.2",
"version": "0.8.3",
"license": "MIT",
"main": "./dist/esm/index.js",
"type": "module",
Expand Down Expand Up @@ -89,7 +89,7 @@
"@polkadot/api": "10.12.4"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.16.0",
"@docknetwork/credential-sdk": "0.17.0",
"@docknetwork/node-types": "^0.17.0",
"@juanelas/base64": "^1.0.5",
"@polkadot/api": "10.12.4",
Expand Down
7 changes: 7 additions & 0 deletions packages/dock-blockchain-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @docknetwork/dock-blockchain-modules

## 0.9.3

### Patch Changes

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

## 0.9.2

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/dock-blockchain-modules/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/dock-blockchain-modules",
"version": "0.9.2",
"version": "0.9.3",
"license": "MIT",
"type": "module",
"main": "./dist/esm/index.js",
Expand Down Expand Up @@ -33,7 +33,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.16.0"
"@docknetwork/credential-sdk": "0.17.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/dock-blockchain-api": "0.8.2",
"@docknetwork/dock-blockchain-api": "0.8.3",
"@rollup/plugin-alias": "^4.0.2",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down

0 comments on commit 3cc2188

Please sign in to comment.