Skip to content

Commit

Permalink
Merge pull request #494 from docknetwork/fix-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
cykoder authored Dec 17, 2024
2 parents cbfbf0d + df9e3cc commit 0ea93bb
Show file tree
Hide file tree
Showing 21 changed files with 119 additions and 27 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.5

### Patch Changes

- Updated dependencies
- @docknetwork/dock-blockchain-modules@0.11.0
- @docknetwork/credential-sdk@0.19.0
- @docknetwork/dock-blockchain-api@0.8.5

## 0.6.4

### 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.4",
"version": "0.6.5",
"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.18.0",
"@docknetwork/dock-blockchain-api": "0.8.4",
"@docknetwork/dock-blockchain-modules": "0.10.0"
"@docknetwork/credential-sdk": "0.19.0",
"@docknetwork/dock-blockchain-api": "0.8.5",
"@docknetwork/dock-blockchain-modules": "0.11.0"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "root",
"version": "0.19.0",
"version": "0.21.0",
"private": true,
"workspaces": [
"packages/*",
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.4

### Patch Changes

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

## 0.14.3

### 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.3",
"version": "0.14.4",
"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.18.0"
"@docknetwork/credential-sdk": "0.19.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.13.1

### Patch Changes

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

## 0.13.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.13.0",
"version": "0.13.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.18.0"
"@docknetwork/credential-sdk": "0.19.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.3",
"@docknetwork/cheqd-blockchain-api": "0.14.4",
"@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 @@ -94,7 +94,10 @@ export default function injectPublicKeys(klass) {

return new PublicKeyMap(
await Promise.all(
metas.map(({ id }) => this.getPublicKey(did, id, includeParams)),
metas.map(async ({ id }) => [
id,
await this.getPublicKey(did, id, includeParams),
]),
),
);
}
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.19.0

### Minor Changes

- Fix unresolved imports

## 0.18.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.18.0",
"version": "0.19.0",
"license": "MIT",
"type": "module",
"files": [
Expand Down
12 changes: 8 additions & 4 deletions packages/credential-sdk/src/modules/multi-api/accumulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,25 @@ export default class MultiApiAccumulatorModule extends injectModuleRouter(
);
}

async getPublicKey(did, id) {
async getPublicKey(did, id, includeParams) {
const parsedDid = NamespaceDid.from(did);

return await this.moduleById(parsedDid).getPublicKey(parsedDid, id);
return await this.moduleById(parsedDid).getPublicKey(
parsedDid,
id,
includeParams,
);
}

/**
* Retrieves all accumulator public keys by a DID.
* @param {*} did
* @returns {Promise<Map<*, AccumulatorPublicKey>>}
*/
async getAllPublicKeysByDid(did) {
async getAllPublicKeysByDid(did, includeParams) {
const id = NamespaceDid.from(did);

return await this.moduleById(id).getAllPublicKeysByDid(did);
return await this.moduleById(id).getAllPublicKeysByDid(did, includeParams);
}

async addPublicKeyTx(...args) {
Expand Down
29 changes: 28 additions & 1 deletion packages/credential-sdk/src/modules/tests/accumulator-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
VBMembershipWitness,
} from '../../crypto';
import { AccumulatorType } from '../abstract/accumulator/module';
import { DIDDocument } from '../../types';
import {
DIDDocument,
AccumulatorParams as AccumulatorParamsType,
} from '../../types';
import { Ed25519Keypair, DidKeypair } from '../../keypairs';

// eslint-disable-next-line jest/no-export
Expand Down Expand Up @@ -65,12 +68,36 @@ export default function generateAccumulatorTests(
params1Id = await accumulatorModule.nextParamsId(did);
await accumulatorModule.addParams(params1Id, params1, did, pair);

expect(
(await accumulatorModule.getParams(did, params1Id)).toJSON(),
).toEqual(AccumulatorParamsType.from(params1).toJSON());
expect((await accumulatorModule.getAllParamsByDid(did)).toJSON()).toEqual(
[[params1Id.toJSON(), AccumulatorParamsType.from(params1).toJSON()]],
);

keypair = Accumulator.generateKeypair(params, seedAccum);
const bytes2 = u8aToHex(keypair.publicKey.bytes);
const pk1 = new PublicKey(bytes2, [did, params1Id]);
pk1Id = await accumulatorModule.nextPublicKeyId(did);
await accumulatorModule.addPublicKey(pk1Id, pk1, did, pair);

expect(
(await accumulatorModule.getPublicKey(did, pk1Id)).toJSON(),
).toEqual(pk1.toJSON());
expect(
(await accumulatorModule.getAllPublicKeysByDid(did)).toJSON(),
).toEqual([[pk1Id.toJSON(), pk1.toJSON()]]);

const pk1WithParams = await pk1.withParams(accumulatorModule);
expect(pk1WithParams.params).toBeInstanceOf(AccumulatorParamsType);

expect(
(await accumulatorModule.getPublicKey(did, pk1Id, true)).toJSON(),
).toEqual(pk1WithParams.toJSON());
expect(
(await accumulatorModule.getAllPublicKeysByDid(did, true)).toJSON(),
).toEqual([[pk1Id.toJSON(), pk1WithParams.toJSON()]]);

accumulator = PositiveAccumulator.initialize(params, keypair.secretKey);

for (let i = 1; i <= totalMembers; i++) {
Expand Down
4 changes: 4 additions & 0 deletions packages/credential-sdk/src/types/generic/typed-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class TypedNumber extends withBase(class NumberBase {}) {
throw new Error(
`Invalid number provided: \`${value}\`, parsed as \`${num}\` by \`${this.constructor.name}\``,
);
} else if (!Number.isSafeInteger(num)) {
throw new Error(
`Number must be a safe integer, received: \`${num}\` by \`${this.constructor.name}\``,
);
}

this.value = num;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { TypedNumber, TypedUUID } from '../../generic';

export class DockPublicKeyId extends TypedNumber {}

export class CheqdPublicKeyId extends TypedUUID {}
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@ export class CheqdOffchainSignaturePublicKey extends withProp(

export * from './value';
export * from './ref';
export * from './id';
2 changes: 1 addition & 1 deletion packages/credential-sdk/src/utils/bytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const u8aToHex = (bytes) => `0x${Buffer.from(ensureBytes(bytes)).toString
* @param {number} length
* @returns {Uint8Array}
*/
export const randomAsU8a = (length) => Uint8Array.from({ length }, () => (Math.random() * 255) | 0); // eslint-disable-line no-bitwise
export const randomAsU8a = (length) => Uint8Array.from({ length }, () => Math.floor(Math.random() * 256));

/**
* Creates random hex string of supplied byte length.
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.5

### Patch Changes

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

## 0.8.4

### 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.4",
"version": "0.8.5",
"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.18.0",
"@docknetwork/credential-sdk": "0.19.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.11.0

### Minor Changes

- Fix unresolved imports

### Patch Changes

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

## 0.10.0

### 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.10.0",
"version": "0.11.0",
"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.18.0"
"@docknetwork/credential-sdk": "0.19.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.4",
"@docknetwork/dock-blockchain-api": "0.8.5",
"@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 @@ -5,6 +5,7 @@ import {
DockDidValue,
DockOffchainSignatureParamsRef,
DockParamsId,
DockPublicKeyId,
} from '@docknetwork/credential-sdk/types';
import {
AddOffchainSignatureParams,
Expand Down Expand Up @@ -76,14 +77,14 @@ export default class DockInternalOffchainSignaturesModule extends injectParams(
async keysCounter(did) {
const parsedDid = DockDidOrDidMethodKey.from(did);

const { data: { lastKeyId } } = await this.didModule.getOnchainDidDetail(
parsedDid,
);
const {
data: { lastKeyId },
} = await this.didModule.getOnchainDidDetail(parsedDid);

return lastKeyId;
}

async lastPublicKeyId(did) {
return await this.keysCounter(did);
return DockPublicKeyId.from(await this.keysCounter(did));
}
}

0 comments on commit 0ea93bb

Please sign in to comment.