diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index af1b27cd3..648b064ef 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -3,7 +3,7 @@ on: push: branches: - master - - fix/deploy-docs + jobs: build-and-deploy: runs-on: ubuntu-latest diff --git a/examples/CHANGELOG.md b/examples/CHANGELOG.md index 566a5e030..9a813319b 100644 --- a/examples/CHANGELOG.md +++ b/examples/CHANGELOG.md @@ -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 diff --git a/examples/package.json b/examples/package.json index 341a42f5e..ae3ad5875 100644 --- a/examples/package.json +++ b/examples/package.json @@ -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", @@ -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", diff --git a/packages/cheqd-blockchain-api/CHANGELOG.md b/packages/cheqd-blockchain-api/CHANGELOG.md index 828c4fa47..c9c7cf4ef 100644 --- a/packages/cheqd-blockchain-api/CHANGELOG.md +++ b/packages/cheqd-blockchain-api/CHANGELOG.md @@ -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 diff --git a/packages/cheqd-blockchain-api/package.json b/packages/cheqd-blockchain-api/package.json index d1173be5f..a5daf9d7e 100644 --- a/packages/cheqd-blockchain-api/package.json +++ b/packages/cheqd-blockchain-api/package.json @@ -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", @@ -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", @@ -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" } } diff --git a/packages/cheqd-blockchain-modules/CHANGELOG.md b/packages/cheqd-blockchain-modules/CHANGELOG.md index ef845b0cb..354e05df7 100644 --- a/packages/cheqd-blockchain-modules/CHANGELOG.md +++ b/packages/cheqd-blockchain-modules/CHANGELOG.md @@ -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 diff --git a/packages/cheqd-blockchain-modules/README.md b/packages/cheqd-blockchain-modules/README.md index 9a0582961..5b5ee5771 100644 --- a/packages/cheqd-blockchain-modules/README.md +++ b/packages/cheqd-blockchain-modules/README.md @@ -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 @@ -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 diff --git a/packages/cheqd-blockchain-modules/package.json b/packages/cheqd-blockchain-modules/package.json index db132cc7c..5e3ceb6ea 100644 --- a/packages/cheqd-blockchain-modules/package.json +++ b/packages/cheqd-blockchain-modules/package.json @@ -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", @@ -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", @@ -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", diff --git a/packages/credential-sdk/CHANGELOG.md b/packages/credential-sdk/CHANGELOG.md index 64ebda529..c90e717d0 100644 --- a/packages/credential-sdk/CHANGELOG.md +++ b/packages/credential-sdk/CHANGELOG.md @@ -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 diff --git a/packages/credential-sdk/README.md b/packages/credential-sdk/README.md index 53ffd6f22..c2f610f9d 100644 --- a/packages/credential-sdk/README.md +++ b/packages/credential-sdk/README.md @@ -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). diff --git a/packages/credential-sdk/package.json b/packages/credential-sdk/package.json index 614747a41..b4f0aaa53 100644 --- a/packages/credential-sdk/package.json +++ b/packages/credential-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@docknetwork/credential-sdk", - "version": "0.1.1", + "version": "0.2.0", "license": "MIT", "type": "module", "files": [ diff --git a/packages/credential-sdk/src/types/did/document.js b/packages/credential-sdk/src/types/did/document.js index 5ee61f92b..bf2a24406 100644 --- a/packages/credential-sdk/src/types/did/document.js +++ b/packages/credential-sdk/src/types/did/document.js @@ -7,6 +7,7 @@ import { TypedBytes, TypedEnum, TypedNumber, + TypedSet, TypedString, TypedStruct, TypedTuple, @@ -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; @@ -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(); } diff --git a/packages/credential-sdk/src/utils/generic.js b/packages/credential-sdk/src/utils/generic.js index 9ddeed27c..4d2687e78 100644 --- a/packages/credential-sdk/src/utils/generic.js +++ b/packages/credential-sdk/src/utils/generic.js @@ -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') { diff --git a/packages/dock-blockchain-api/CHANGELOG.md b/packages/dock-blockchain-api/CHANGELOG.md index 9602a8403..9874d03dc 100644 --- a/packages/dock-blockchain-api/CHANGELOG.md +++ b/packages/dock-blockchain-api/CHANGELOG.md @@ -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 diff --git a/packages/dock-blockchain-api/package.json b/packages/dock-blockchain-api/package.json index aef7c6d37..3f32cccf6 100644 --- a/packages/dock-blockchain-api/package.json +++ b/packages/dock-blockchain-api/package.json @@ -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", @@ -63,7 +63,7 @@ "parity-scale-codec": "^0.5.3", "r1csfile": "0.0.41", "ramda": "^0.27.2", - "rollup": "2.78.0", + "rollup": "2.79.2", "rollup-plugin-copy": "^3.4.0", "rollup-plugin-multi-input": "^1.3.2", "rollup-plugin-node-polyfills": "^0.2.1", @@ -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", diff --git a/packages/dock-blockchain-modules/CHANGELOG.md b/packages/dock-blockchain-modules/CHANGELOG.md index f78ccd0f5..e23ee1e96 100644 --- a/packages/dock-blockchain-modules/CHANGELOG.md +++ b/packages/dock-blockchain-modules/CHANGELOG.md @@ -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 diff --git a/packages/dock-blockchain-modules/package.json b/packages/dock-blockchain-modules/package.json index 896ba884c..fbb4f9dd2 100644 --- a/packages/dock-blockchain-modules/package.json +++ b/packages/dock-blockchain-modules/package.json @@ -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", @@ -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", @@ -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", @@ -58,7 +58,7 @@ "jest-environment-node": "^29.7.0", "jsdoc": "^3.6.3", "jsdoc-typeof-plugin": "^1.0.0", - "rollup": "2.78.0", + "rollup": "2.79.2", "rollup-plugin-copy": "^3.4.0", "rollup-plugin-multi-input": "^1.3.2", "rollup-plugin-node-polyfills": "^0.2.1", diff --git a/packages/dock-blockchain-modules/src/did/module.js b/packages/dock-blockchain-modules/src/did/module.js index 91b538079..1c6465cdf 100644 --- a/packages/dock-blockchain-modules/src/did/module.js +++ b/packages/dock-blockchain-modules/src/did/module.js @@ -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, @@ -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 ( diff --git a/tutorials/src/tutorial_blobs_schemas.md b/tutorials/src/tutorial_blobs_schemas.md index f6e7b2905..486a8b414 100644 --- a/tutorials/src/tutorial_blobs_schemas.md +++ b/tutorials/src/tutorial_blobs_schemas.md @@ -32,14 +32,12 @@ It accepts a `blob` object with the struct to store on chain (it can either be a keyPair to sign the payload with). You'll get a signed extrinsic that you can send to the Dock chain: ```javascript -const blobId = randomAsHex(DockBlobIdByteSize); // 32-bytes long hex string to use as the blob's id +const blobId = DockBlobId.random(); // 32-bytes long hex string to use as the blob's id const blobStruct = { id: blobId, blob: blobHexOrArray, // Contents of your blob as a hex string or byte array }; -const result = await dock.blob.new(blobStruct, signerDid, keypair, { - didModule: dock.didModule, -}); +const result = await dock.blob.new(blobStruct, ownerDid, didKeypair); ``` If everything worked properly `result` will indicate a successful transaction. @@ -139,7 +137,7 @@ Writing a Schema to the Dock chain is similar to writing any other Blob. `1` is ```javascript > const formattedBlob = myNewSchema.toBlob(dockDID); -> await myNewSchema.writeToChain(dock, dockDID, keypair); +> await myNewSchema.writeToChain(modules.blob, dockDID, keypair); ``` ### Reading a Schema from the Dock chain @@ -149,7 +147,7 @@ It accepts a string `id` param (a fully-qualified blob id like "blob:dock:0x..." `dockAPI` instance: ```javascript -> const result = await Schema.get(blob.id, dock); +> const result = await Schema.get(blob.id, modules.blob); ``` `result[0]` will be the author of the Schema, and `result[1]` will be the contents of the schema itself. diff --git a/tutorials/src/tutorial_did.md b/tutorials/src/tutorial_did.md index f3d12130c..b572a33c6 100644 --- a/tutorials/src/tutorial_did.md +++ b/tutorials/src/tutorial_did.md @@ -46,7 +46,8 @@ const privateKey = kp.privateKey(); const message = Uint8Array.from([1, 2, 3]); const signature = kp.sign(message); -assert(Ed25519Keypair.verify(message, signature, publicKey)); + +const verified = Ed25519Keypair.verify(message, signature, publicKey); ``` ## Registering a new DID on chain @@ -69,9 +70,9 @@ In most cases, a DID will have its own keys and will control itself, i.e. a self 2. Second, let's get a did key with verication relationship from the did's keypair. The only argument is the verification relationship. A verification relationship can be 1 or more of these `authentication`, `assertion`, `capabilityInvocation` or `keyAgreement` - ```js - const didKey = didKeypair.didKey(); - ``` + ```js + const didKey = didKeypair.didKey(); + ``` 3. Now submit the transaction using a `DockAPI` object and the newly created DID `did` and `didKey`. ```js diff --git a/yarn.lock b/yarn.lock index 4258dc0b7..130f2793b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9902,7 +9902,7 @@ microdata-rdf-streaming-parser@^1.2.0: rdf-data-factory "^1.1.0" relative-to-absolute-iri "^1.0.2" -micromatch@^4.0.2: +micromatch@^4.0.2, micromatch@^4.0.4: version "4.0.8" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.8.tgz#d66fa18f3a47076789320b9b1af32bd86d9fa202" integrity sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA== @@ -9910,14 +9910,6 @@ micromatch@^4.0.2: braces "^3.0.3" picomatch "^2.3.1" -micromatch@^4.0.4: - version "4.0.7" - resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.7.tgz#33e8190d9fe474a9895525f5618eee136d46c2e5" - integrity sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q== - dependencies: - braces "^3.0.3" - picomatch "^2.3.1" - mime-db@1.52.0: version "1.52.0" resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"