Skip to content

Commit

Permalink
Improve docs + force DIDDocument to check for duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn committed Oct 10, 2024
1 parent 395f5cc commit b3ff16a
Show file tree
Hide file tree
Showing 19 changed files with 225 additions and 49 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.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
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 VerificationMethodRefSet extends TypedSet {
static Class = VerificationMethodRef;
}

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 VerificationMethodRefSet(authentication);
const assertion = new VerificationMethodRefSet(assertionMethod);
const keyAgr = new VerificationMethodRefSet(keyAgreement);
const capInv = new VerificationMethodRefSet(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
23 changes: 20 additions & 3 deletions packages/dock-blockchain-modules/src/did/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,24 @@ export default class DockDIDModule extends injectDock(AbstractDIDModule) {

const keys = didDocument.didKeys();
const {
controller, service, id, '@context': context,
controller,
service,
id,
'@context': context,
capabilityDelegation,
attests,
} = document;
if (service?.length) {
throw new Error(
'`service` is not supported in the `createDocument` transaction. Use `updateDocument` to add `service` to the existing document.',
);
}
if (context.length !== 1 || context[0].value !== CONTEXT_URI) {
} else if (capabilityDelegation?.length) {
throw new Error('Capability delegation is not supported');
} else if (attests != null) {
throw new Error(
'`attests` are not supported in the `createDocument` transaction. Use `attest` module to attach `attests` to the existing document.',
);
} else if (context.length !== 1 || context[0].value !== CONTEXT_URI) {
throw new Error(
`Context must be equal to \`${[
CONTEXT_URI,
Expand All @@ -63,6 +73,13 @@ export default class DockDIDModule extends injectDock(AbstractDIDModule) {

if (modified.size) {
throw new Error("Can't have modified verificationMethods");
} else if (
nextDocument.attests
&& !nextDocument.attests.eq(currentDocument.attests)
) {
throw new Error(
'`attests` modifications are not supported in the `updateDocument` transaction. Use `attest` module to attach `attests` to the existing document.',
);
}

if (
Expand Down
Loading

0 comments on commit b3ff16a

Please sign in to comment.