Skip to content

Commit

Permalink
Improve docs + force DIDDocument to check for duplicates (#456)
Browse files Browse the repository at this point in the history
* Improve docs + force `DIDDocument` to check for duplicates

* Tweaks

* Remove EVM reference

* Fix docs workflow
  • Loading branch information
olegnn authored Oct 10, 2024
1 parent fb1ed60 commit ae839eb
Show file tree
Hide file tree
Showing 22 changed files with 279 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- master
- fix/deploy-docs

jobs:
build-and-deploy:
runs-on: ubuntu-latest
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.1.2

### Patch Changes

- Updated dependencies
- @docknetwork/dock-blockchain-modules@0.2.0
- @docknetwork/credential-sdk@0.2.0
- @docknetwork/dock-blockchain-api@0.1.2

## 0.1.1

### 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.1.1",
"version": "0.1.2",
"scripts": {
"bbs-dock-example": "babel-node --loader=./loader.mjs ./bbs-dock.js",
"claim-deduction-example": "babel-node --loader=./loader.mjs ./claim-deduction.js",
Expand All @@ -19,9 +19,9 @@
"lint": "eslint \"*.js\""
},
"dependencies": {
"@docknetwork/credential-sdk": "0.1.1",
"@docknetwork/dock-blockchain-api": "0.1.1",
"@docknetwork/dock-blockchain-modules": "0.1.1"
"@docknetwork/credential-sdk": "0.2.0",
"@docknetwork/dock-blockchain-api": "0.1.2",
"@docknetwork/dock-blockchain-modules": "0.2.0"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/cheqd-blockchain-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @docknetwork/cheqd-blockchain-api

## 0.1.2

### Patch Changes

- Change `DIDDocument` modification behaviour to throw error on attempt to add key/service/controller with duplicate id.

## 0.1.1

### Minor Changes
Expand Down
11 changes: 4 additions & 7 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.1.1",
"version": "0.1.2",
"license": "MIT",
"main": "./dist/esm/index.js",
"type": "module",
Expand All @@ -27,6 +27,9 @@
"engines": {
"node": ">=20.0.0"
},
"dependencies": {
"@cheqd/sdk": "^4.0.4"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
"@babel/core": "^7.24.3",
Expand Down Expand Up @@ -78,11 +81,5 @@
"watch": "rollup -c -w",
"docs": "rm -rf out && mkdir out && touch out/.nojekyll && jsdoc src -r -c ../../.jsdoc -d out/reference",
"type-check": "tsc --allowJs --checkJs --noEmit --moduleResolution node --resolveJsonModule --target ES6 --skipLibCheck true --allowSyntheticDefaultImports true"
},
"resolutions": {
"@polkadot/api": "10.12.4"
},
"dependencies": {
"@cheqd/sdk": "^4.0.4"
}
}
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.2.0

### Minor Changes

- Change `DIDDocument` modification behaviour to throw error on attempt to add key/service/controller with duplicate id.

### Patch Changes

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

## 0.1.1

### Minor Changes
Expand Down
9 changes: 2 additions & 7 deletions packages/cheqd-blockchain-modules/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# @docknetwork/cheqd-blockchain-modules

A JavaScript library created for managing credential SDK components such as DIDs and accumulators etc on the Cheqd blockchain.
# Cheqd Blockchain Modules

## Setup

Expand Down Expand Up @@ -76,9 +74,6 @@ expect((await attestModule.getDocument(did)).attests.toJSON()).toEqual(iri);
- Accumulator
- Anchor
- Blob
- OffchainSignatures
- BBS
- BBSPlus
- PS
- OffchainSignatures params (BBS/BBSPlus/PS)
- StatusListCredential
- TrustRegistry
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.1.1",
"version": "0.2.0",
"type": "module",
"license": "MIT",
"main": "./dist/esm/index.js",
Expand Down Expand Up @@ -28,7 +28,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.1.1"
"@docknetwork/credential-sdk": "0.2.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand All @@ -37,7 +37,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.1.1",
"@docknetwork/cheqd-blockchain-api": "0.1.2",
"@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.2.0

### Minor Changes

- Change `DIDDocument` modification behaviour to throw error on attempt to add key/service/controller with duplicate id.

## 0.1.1

### Minor Changes
Expand Down
50 changes: 49 additions & 1 deletion packages/credential-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,56 @@ Detailed documentation and API reference are provided at the [Dock Network Docum

Contributions to the @docknetwork/credential-sdk are welcome. Please feel free to open issues or submit pull requests to improve the SDK or add new features.

## Types Overview

The Credential SDK provides a flexible and extensible set of typed structures that facilitate working with complex data types. These types are designed to provide enhanced type safety, ensure consistent data handling, and simplify JSON and API integration. This includes support for versatile data representations such as Enums, Tuples, Strings, and Arrays, all of which come with utility methods for manipulation and comparison.

### Available Types

- **TypedString**: Represents string data. Internally managed as `Array` to handle binary data conversion seamlessly. Provides various methods for equality check and conversion between hexadecimal and string representations.

- **TypedNumber**: Ensures reliable number handling by enforcing numerical checks during instantiation. Supports conversion from different inputs and API structures, offering consistent JSON integration.

- **TypedEnum**: Facilitates the representation of enumeration types with extensible variants. Ensures strict type conformity when dealing with potential multiple representations of a single conceptual state.

- **TypedArray**: Provides abstraction over JavaScript arrays, allowing for uniform handling of a single item type. Equipped with methods that maintain type integrity while offering array operations like `push`, `unshift`, and `equality check`.

- **TypedMap**: Extends the Map structure, offering consistent key/value type management and conversion capabilities. Includes support for serialization to JSON and deserialization from API responses.

- **TypedUUID**: Specially tailored for handling UUIDs, including validation, parsing, and generation of random UUIDs.

- **TypedStruct**: Represents structured, dictionary-like data with predefined keys and types, facilitating robust data manipulation and JSON compatibility.

- **TypedTuple**: Enforces a fixed-size collection of elements, each having a specified type. Essential for maintaining order and type checks in tuple-based data structures.

- **Any**: Acts as a catch-all, capable of holding any value or object. It is useful in scenarios where type flexibility is essential, such as interfacing with dynamic data sources or when type restrictions are not suitable.

- **Null**: Acts as a `null` allowing to have some field initialized to `null`.

### Utility Mixins

- **withBase**: A foundational mixin that adds basic methods like `from`, `toJSON`, and equality checks to a class.

- **withCatchNull**: Ensures that `from` and `to` methods gracefully handle `null` or undefined values, safeguarding against unexpected errors.

- **withEq**: Provides enhanced equality checking, allowing deep comparison among complex objects.

- **withFrom**: Facilitates custom instantiation logic for classes, particularly useful when dealing with various input forms that require specialized initialization.

- **withQualifier**: Extends classes to handle prefixed string identifiers and encoding, suitable for scenarios involving qualified identifiers (e.g., DID systems).

- **option**: Allows to pass `null` to `from` method returning `null` in this case.

- **withNullIfNotAVariant**: A class decorator for types extending `TypedEnum`. It ensures that instantiation from JSON or API data returns `null` if the provided value doesn't match any defined variant type. This mixin helps enforce strict type conformity.

- **withProp**: Extends classes derived from `TypedStruct` or `TypedEnum` by adding or overriding properties. It facilitates dynamic property management, allowing for seamless integration of new fields or modifications without altering base classes.

- **withQualifier**: Adds functionality for dealing with qualified strings, such as those used in decentralized identifiers (DIDs). This mixin supports operations involving strings with specific prefixes or encoding requirements.

- **withoutProp**: Complements `withProp` by removing properties from classes that extend `TypedStruct` or `TypedEnum`. It is useful for deprecating or cleaning up obsolete properties.

## License

This SDK is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.

For any questions or issues, please refer to our [GitHub repository](https://github.com/docknetwork/credential-sdk) or [contact us](https://dock.io/contact).
For any questions or issues, please refer to our [GitHub repository](https://github.com/docknetwork/credential-sdk).
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.1.1",
"version": "0.2.0",
"license": "MIT",
"type": "module",
"files": [
Expand Down
28 changes: 17 additions & 11 deletions packages/credential-sdk/src/types/did/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TypedBytes,
TypedEnum,
TypedNumber,
TypedSet,
TypedString,
TypedStruct,
TypedTuple,
Expand Down Expand Up @@ -574,12 +575,18 @@ export class DIDDocument extends TypedStruct {
}

addController(controller) {
if (this.controller.some((ctrl) => ctrl.eq(controller))) {
throw new Error(`Controller \`${controller}\` already exists`);
}
this.controller.push(controller);

return this;
}

addServiceEndpoint(id, serviceEndpoint) {
if (this.service.some((service) => service.id.eq(id))) {
throw new Error(`Service endpoint with id \`${id}\` already exists`);
}
this.service.push(Service.fromServiceEndpoint(id, serviceEndpoint));

return this;
Expand Down Expand Up @@ -632,31 +639,30 @@ export class DIDDocument extends TypedStruct {
assertionMethod,
keyAgreement,
capabilityInvocation,
capabilityDelegation,
} = this;

if (capabilityDelegation && capabilityDelegation.length > 0) {
throw new Error('Capability delegation is not supported');
class VerificationMethodRefOrKeySet extends TypedSet {
static Class = VerificationMethodRefOrKey;
}

const auth = new Set([...authentication].map(String));
const assertion = new Set([...assertionMethod].map(String));
const keyAgr = new Set([...keyAgreement].map(String));
const capInv = new Set([...capabilityInvocation].map(String));
const auth = new VerificationMethodRefOrKeySet(authentication);
const assertion = new VerificationMethodRefOrKeySet(assertionMethod);
const keyAgr = new VerificationMethodRefOrKeySet(keyAgreement);
const capInv = new VerificationMethodRefOrKeySet(capabilityInvocation);

const keys = [...verificationMethod]
.map((method) => {
const verRels = new VerificationRelationship();
if (auth.has(String(method.id))) {
if (auth.has(method.id)) {
verRels.setAuthentication();
}
if (assertion.has(String(method.id))) {
if (assertion.has(method.id)) {
verRels.setAssertion();
}
if (keyAgr.has(String(method.id))) {
if (keyAgr.has(method.id)) {
verRels.setKeyAgreement();
}
if (capInv.has(String(method.id))) {
if (capInv.has(method.id)) {
verRels.setCapabilityInvocation();
}

Expand Down
2 changes: 2 additions & 0 deletions packages/credential-sdk/src/utils/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ const Ignore = new Set([
'find',
'findIndex',
'splice',
'some',
'find',
]);
for (const member of Object.getOwnPropertyNames(Array.prototype)) {
if (!Ignore.has(member) && typeof Array.prototype[member] === 'function') {
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.1.2

### Patch Changes

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

## 0.1.1

### Minor 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.1.1",
"version": "0.1.2",
"license": "MIT",
"main": "./dist/esm/index.js",
"type": "module",
Expand Down Expand Up @@ -84,7 +84,7 @@
"@polkadot/api": "10.12.4"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.1.1",
"@docknetwork/credential-sdk": "0.2.0",
"@docknetwork/node-types": "^0.17.0",
"@juanelas/base64": "^1.0.5",
"@polkadot/api": "10.12.4",
Expand Down
11 changes: 11 additions & 0 deletions packages/dock-blockchain-modules/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @docknetwork/dock-blockchain-modules

## 0.2.0

### Minor Changes

- Change `DIDDocument` modification behaviour to throw error on attempt to add key/service/controller with duplicate id.

### Patch Changes

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

## 0.1.1

### Minor 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.1.1",
"version": "0.2.0",
"license": "MIT",
"type": "module",
"main": "./dist/esm/index.js",
Expand Down Expand Up @@ -28,7 +28,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@docknetwork/credential-sdk": "0.1.1"
"@docknetwork/credential-sdk": "0.2.0"
},
"devDependencies": {
"@babel/cli": "^7.24.1",
Expand All @@ -37,7 +37,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.1.1",
"@docknetwork/dock-blockchain-api": "0.1.2",
"@rollup/plugin-alias": "^4.0.2",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
Loading

0 comments on commit ae839eb

Please sign in to comment.