diff --git a/packages/credential-sdk/src/modules/abstract/accumulator/module.js b/packages/credential-sdk/src/modules/abstract/accumulator/module.js index 8b08a23e1..c8591f1f4 100644 --- a/packages/credential-sdk/src/modules/abstract/accumulator/module.js +++ b/packages/credential-sdk/src/modules/abstract/accumulator/module.js @@ -1,10 +1,15 @@ /* eslint-disable camelcase */ -import { KBUniversalAccumulatorValue } from '@docknetwork/crypto-wasm-ts'; -import { normalizeToHex, normalizeToU8a } from '../../../utils/bytes'; -import { AbstractWithParamsAndPublicKeys } from '../common'; -import { AccumulatorParams, AccumulatorPublicKey } from '../../../types'; -import { withExtendedPrototypeProperties } from '../../../utils'; +import { KBUniversalAccumulatorValue } from "@docknetwork/crypto-wasm-ts"; +import { normalizeToHex, normalizeToU8a } from "../../../utils/bytes"; +import { + AbstractBaseModule, + AbstractWithParamsAndPublicKeys, + withParams, + withPublicKeys, +} from "../common"; +import { AccumulatorParams, AccumulatorPublicKey } from "../../../types"; +import { withExtendedPrototypeProperties } from "../../../utils"; export const AccumulatorType = { VBPos: 0, @@ -13,7 +18,9 @@ export const AccumulatorType = { }; /** Class to manage accumulators on chain */ -class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { +class AbstractAccumulatorModule extends withParams( + withPublicKeys(AbstractBaseModule) +) { static Params = AccumulatorParams; static PublicKey = AccumulatorPublicKey; @@ -56,7 +63,7 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { publicKey, targetDid, didKeypair, - params, + params ); } @@ -73,7 +80,7 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { removeKeyId, targetDid, didKeypair, - params, + params ); } @@ -91,16 +98,16 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { accumulated, publicKeyRef, didKeypair, - params, + params ) { return await this.signAndSend( await this.addPositiveAccumulatorTx( id, accumulated, publicKeyRef, - didKeypair, + didKeypair ), - params, + params ); } @@ -120,7 +127,7 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { publicKeyRef, maxSize, didKeypair, - params, + params ) { return await this.signAndSend( await this.addUniversalAccumulatorTx( @@ -128,9 +135,9 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { accumulated, publicKeyRef, maxSize, - didKeypair, + didKeypair ), - params, + params ); } @@ -148,16 +155,16 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { accumulated, publicKeyRef, didKeypair, - params, + params ) { return await this.signAndSend( await this.addKBUniversalAccumulatorTx( id, accumulated, publicKeyRef, - didKeypair, + didKeypair ), - params, + params ); } @@ -176,7 +183,7 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { newAccumulated, { additions, removals, witnessUpdateInfo }, didKeypair, - params, + params ) { return await this.signAndSend( await this.updateAccumulatorTx( @@ -187,9 +194,9 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { removals, witnessUpdateInfo, }, - didKeypair, + didKeypair ), - params, + params ); } @@ -202,7 +209,7 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { async removeAccumulator(id, didKeypair, params) { return await this.signAndSend( await this.removeAccumulatorTx(id, didKeypair), - params, + params ); } @@ -217,7 +224,7 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { * @returns {Promise} */ async getAccumulator(id, _includeKey = false, _includeKeyParams = false) { - throw new Error('Unimplemented'); + throw new Error("Unimplemented"); } /** @@ -232,19 +239,19 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys { * @returns {Promise} */ async updateWitness(_accumulatorId, _member, _witness, _from, _to) { - throw new Error('Unimplemented'); + throw new Error("Unimplemented"); } } export default withExtendedPrototypeProperties( [ - 'getAccumulator', - 'addPositiveAccumulatorTx', - 'addUniversalAccumulatorTx', - 'addKBUniversalAccumulatorTx', - 'updateAccumulatorTx', - 'removeAccumulatorTx', - 'updateWitness', + "getAccumulator", + "addPositiveAccumulatorTx", + "addUniversalAccumulatorTx", + "addKBUniversalAccumulatorTx", + "updateAccumulatorTx", + "removeAccumulatorTx", + "updateWitness", ], - AbstractAccumulatorModule, + AbstractAccumulatorModule ); diff --git a/packages/credential-sdk/src/modules/abstract/common/index.js b/packages/credential-sdk/src/modules/abstract/common/index.js index 3e1e70d2e..5fc4c3c2c 100644 --- a/packages/credential-sdk/src/modules/abstract/common/index.js +++ b/packages/credential-sdk/src/modules/abstract/common/index.js @@ -1,4 +1,5 @@ export { default as ApiProvider } from "./api-provider"; export { default as AbstractBaseModule } from "./base-module"; export { default as AbstractWithParams } from "./with-params"; -export { default as AbstractWithParamsAndPublicKeys } from "./with-params-and-public-keys"; +export { default as withParams } from "./with-params"; +export { default as withPublicKeys } from "./with-public-keys"; diff --git a/packages/credential-sdk/src/modules/abstract/common/with-params.js b/packages/credential-sdk/src/modules/abstract/common/with-params.js index 5fbde5f77..a5fd2a73b 100644 --- a/packages/credential-sdk/src/modules/abstract/common/with-params.js +++ b/packages/credential-sdk/src/modules/abstract/common/with-params.js @@ -1,92 +1,95 @@ -import AbstractBaseModule from "./base-module"; import { withExtendedPrototypeProperties, withExtendedStaticProperties, } from "../../../utils"; export default function withParams(klass) { - class AbstractWithParams extends klass { - /** - * Create object to add new parameters on chain - * @param prepareAddPublicKey - * @param curveType - * @param label - * @returns {{}} - */ - static prepareAddParameters(...args) { - const { Params } = this; + const name = `withParams(${klass.name})`; - return new Params(...args); - } + const obj = { + [name]: class extends klass { + /** + * Create object to add new parameters on chain + * @param prepareAddPublicKey + * @param curveType + * @param label + * @returns {{}} + */ + static prepareAddParameters(...args) { + const { Params } = this; - /** - * Add new params assiociated with the supplied DID. - * @param id - Unique identifier of the new params to be added. - * @param param - The params assiociated with the supplied DID to add. - * @param targetDid - * @param keyPair - Signer's keypair - * @param params - * @returns {Promise<*>} - */ - async addParams(id, param, targetDid, didKeypair, params) { - return await this.signAndSend( - await this.addParamsTx(id, param, targetDid, didKeypair), - params - ); - } + return new Params(...args); + } - /** - * Remove existing BBS+ params. - * @param id - Identifier of the parameters to be removed. - * @param targetDid - Target DID associated with the params - * @param keyPair - Signer's keypair + /** + * Add new params assiociated with the supplied DID. + * @param id - Unique identifier of the new params to be added. + * @param params - The params assiociated with the supplied DID to add. + * @param targetDid + * @param keyPair - Signer's keypair + * @param params + * @returns {Promise<*>} + */ + async addParams(id, params, targetDid, didKeypair, txParams) { + return await this.signAndSend( + await this.addParamsTx(id, params, targetDid, didKeypair), + txParams + ); + } - * @returns {Promise<*>} - */ - async removeParams(id, targetDid, didKeypair, params) { - return await this.signAndSend( - await this.removeParamsTx(id, targetDid, didKeypair), - params - ); - } + /** + * Remove existing BBS+ params. + * @param id - Identifier of the parameters to be removed. + * @param targetDid - Target DID associated with the params + * @param keyPair - Signer's keypair - /** - * Retrieves params by a DID and unique identifier. - * @param {*} did - * @param {*} id - * @returns {Promise} - */ - async getParams(_did, _id) { - throw new Error("Unimplemented"); - } + * @returns {Promise<*>} + */ + async removeParams(id, targetDid, didKeypair, params) { + return await this.signAndSend( + await this.removeParamsTx(id, targetDid, didKeypair), + params + ); + } - /** - * Retrieves all params by a DID - * @param {*} did - * @returns {Promise>} - */ - async getAllParamsByDid(_did) { - throw new Error("Unimplemented"); - } + /** + * Retrieves params by a DID and unique identifier. + * @param {*} did + * @param {*} id + * @returns {Promise} + */ + async getParams(_did, _id) { + throw new Error("Unimplemented"); + } - /** - * Retrieves latest params identifier used by the supplied DID. - * @param {*} did - * @returns {Promise} - */ - async lastParamsId(_targetDid) { - throw new Error("Unimplemented"); - } + /** + * Retrieves all params by a DID + * @param {*} did + * @returns {Promise>} + */ + async getAllParamsByDid(_did) { + throw new Error("Unimplemented"); + } - /** - * Retrieves next params identifier that can be used by the supplied DID. - * @param {*} did - * @returns {Promise} - */ - async nextParamsId(_targetDid) { - throw new Error("Unimplemented"); - } - } + /** + * Retrieves latest params identifier used by the supplied DID. + * @param {*} did + * @returns {Promise} + */ + async lastParamsId(_targetDid) { + throw new Error("Unimplemented"); + } + + /** + * Retrieves next params identifier that can be used by the supplied DID. + * @param {*} did + * @returns {Promise} + */ + async nextParamsId(_targetDid) { + throw new Error("Unimplemented"); + } + }, + }; /** * Abstract logic allowing to operate with public keys and parameters. @@ -100,6 +103,6 @@ export default function withParams(klass) { "lastParamsId", "nextParamsId", ], - withExtendedStaticProperties(["Params"], AbstractWithParams) + withExtendedStaticProperties(["Params"], obj[name]) ); } diff --git a/packages/credential-sdk/src/modules/abstract/common/with-public-keys.js b/packages/credential-sdk/src/modules/abstract/common/with-public-keys.js index d2d30fdb1..3d7f0ad86 100644 --- a/packages/credential-sdk/src/modules/abstract/common/with-public-keys.js +++ b/packages/credential-sdk/src/modules/abstract/common/with-public-keys.js @@ -1,87 +1,92 @@ import { withExtendedStaticProperties } from "../../../utils"; export default function withPublicKeys(klass) { - class AbstractWithParamsAndPublicKeys extends klass { - /** - * Create object to add new public key on chain - * @param bytes - * @param curveType - * @param paramsRef - Provide if this public key was created using params present on chain. - * @returns {{}} - */ - static prepareAddPublicKey(...args) { - const { PublicKey } = this; + const name = `withPublicKeys(${klass.name})`; - return new PublicKey(...args); - } + const obj = { + [name]: class extends klass { + /** + * Create object to add new public key on chain + * @param bytes + * @param curveType + * @param paramsRef - Provide if this public key was created using params present on chain. + * @returns {{}} + */ + static prepareAddPublicKey(...args) { + const { PublicKey } = this; - /** - * Add a public key - * @param publicKey - public key to add. - * @param targetDid - The DID to which key is being added - * @param signerDid - The DID that is adding the key by signing the payload because it controls `targetDid` - * @param signingKeyRef - Signer's signingKeyRef - * @returns {Promise<*>} - */ - async addPublicKey(id, publicKey, targetDid, didKeypair, params) { - return await this.signAndSend( - await this.addPublicKeyTx(id, publicKey, targetDid, didKeypair), - params - ); - } + return new PublicKey(...args); + } - /** - * Remove public key - * @param removeKeyId - Identifier of the public key to be removed. - * @param targetDid - The DID from which key is being removed - * @param signerDid - The DID that is removing the key by signing the payload because it controls `targetDid` - * @param signingKeyRef - Signer's signing key reference - * @returns {Promise<*>} - */ - async removePublicKey(id, targetDid, didKeypair, params) { - return await this.signAndSend( - await this.removePublicKeyTx(id, targetDid, didKeypair), - params - ); - } + /** + * Add a public key + * @param id - public key id. + * @param publicKey - public key to add. + * @param targetDid - The DID to which key is being added + * @param signerDid - The DID that is adding the key by signing the payload because it controls `targetDid` + * @param signingKeyRef - Signer's signingKeyRef + * @returns {Promise<*>} + */ + async addPublicKey(id, publicKey, targetDid, didKeypair, params) { + return await this.signAndSend( + await this.addPublicKeyTx(id, publicKey, targetDid, didKeypair), + params + ); + } - /** - * Retrieves public key by a DID and unique identifier. - * @param {*} did - * @param {*} id - * @returns {Promise} - */ - async getPublicKey(_did, _id, _includeParams = false) { - throw new Error("Unimplemented"); - } + /** + * Remove public key + * @param id - Identifier of the public key to be removed. + * @param targetDid - The DID from which key is being removed + * @param signerDid - The DID that is removing the key by signing the payload because it controls `targetDid` + * @param signingKeyRef - Signer's signing key reference + * @returns {Promise<*>} + */ + async removePublicKey(id, targetDid, didKeypair, params) { + return await this.signAndSend( + await this.removePublicKeyTx(id, targetDid, didKeypair), + params + ); + } - /** - * Retrieves all public keys by a DID - * @param {*} did - * @returns {Promise>} - */ - async getAllPublicKeysByDid(_did, _includeParams = false) { - throw new Error("Unimplemented"); - } + /** + * Retrieves public key by a DID and unique identifier. + * @param {*} did + * @param {*} id + * @returns {Promise} + */ + async getPublicKey(_did, _id, _includeParams = false) { + throw new Error("Unimplemented"); + } - /** - * Retrieves latest public key identifier used by the supplied DID. - * @param {*} did - * @returns {Promise} - */ - async lastPublicKeyId(_targetDid) { - throw new Error("Unimplemented"); - } + /** + * Retrieves all public keys by a DID + * @param {*} did + * @returns {Promise>} + */ + async getAllPublicKeysByDid(_did, _includeParams = false) { + throw new Error("Unimplemented"); + } - /** - * Retrieves next public key identifier that can be used by the supplied DID. - * @param {*} did - * @returns {Promise} - */ - async nextPublicKeyId(_targetDid) { - throw new Error("Unimplemented"); - } - } + /** + * Retrieves latest public key identifier used by the supplied DID. + * @param {*} did + * @returns {Promise} + */ + async lastPublicKeyId(_targetDid) { + throw new Error("Unimplemented"); + } + + /** + * Retrieves next public key identifier that can be used by the supplied DID. + * @param {*} did + * @returns {Promise} + */ + async nextPublicKeyId(_targetDid) { + throw new Error("Unimplemented"); + } + }, + }; /** * Abstract logic allowing to operate with public keys and parameters. @@ -95,6 +100,6 @@ export default function withPublicKeys(klass) { "lastPublicKeyId", "nextPublicKeyId", ], - withExtendedStaticProperties(["PublicKey"], AbstractWithParamsAndPublicKeys) + withExtendedStaticProperties(["PublicKey"], obj[name]) ); } diff --git a/packages/credential-sdk/src/modules/tests/offchain-signatures-module.js b/packages/credential-sdk/src/modules/tests/offchain-signatures-module.js new file mode 100644 index 000000000..2566d1b0c --- /dev/null +++ b/packages/credential-sdk/src/modules/tests/offchain-signatures-module.js @@ -0,0 +1,85 @@ +import { DidKeypair, Ed25519Keypair } from "../../keypairs"; +import { NoBlobError } from "../abstract/blob/errors"; +import { DIDDocument } from "../../types"; +import { itIf } from "./common"; +import { BlobResolver } from "../../resolver/blob"; +import { stringToU8a } from "../../utils"; + +// eslint-disable-next-line jest/no-export +export default function generateBlobModuleTests( + { did: didModule, offchainSignatures }, + { DID, BlobId }, + filter = () => true +) { + const test = itIf(filter); + + describe(`Using ${didModule.constructor.name} and ${offchainSignatures.constructor.name}`, () => { + test("Generates a `DIDDocument` with `OffchainPublicKey` and creates a `OffchainParameters` owned by this DID", async () => { + const did = DID.random(); + + const keyPair = Ed25519Keypair.random(); + const didKeypair = new DidKeypair([did, 1], keyPair); + + const document = DIDDocument.create(did, [didKeypair.didKey()]); + + await didModule.createDocument(document, didKeypair); + + const blob1 = { + id: BlobId.random(did), + blob: "abcdef", + }; + + await blobModule.new(blob1, didKeypair); + + const written1 = await blobModule.get(blob1.id); + + expect(written1[0].eq(did)).toBe(true); + expect(written1[1].toUTF8String()).toEqual(blob1.blob); + + const blob2 = { + id: BlobId.random(did), + blob: { + example: "content", + }, + }; + await blobModule.new(blob2, didKeypair); + + const written2 = await blobModule.get(blob2.id); + expect(written2[0].eq(did)).toBe(true); + expect(written2[1].toObject()).toEqual(blob2.blob); + + await expect(() => blobModule.new(blob2, didKeypair)).rejects.toThrow(); + }); + + test("Throws an error on missing `Blob`", async () => { + const id = BlobId.random(DID.random()); + + await expect(() => blobModule.get(id)).rejects.toThrow( + new NoBlobError(id) + ); + }); + + test("`BlobResolver`", async () => { + const resolver = new BlobResolver(blobModule); + const did = DID.random(); + + const keyPair = Ed25519Keypair.random(); + const didKeypair = new DidKeypair([did, 1], keyPair); + + const document = DIDDocument.create(did, [didKeypair.didKey()]); + + await didModule.createDocument(document, didKeypair); + + const blob1 = { + id: BlobId.random(did), + blob: "abcdef", + }; + + await blobModule.new(blob1, didKeypair); + expect(await resolver.resolve(String(blob1.id))).toEqual([ + String(did), + stringToU8a(blob1.blob), + ]); + }); + }); +} diff --git a/packages/dock-blockchain-modules/src/accumulator/internal.js b/packages/dock-blockchain-modules/src/accumulator/internal.js index c437d39a2..ac6af2615 100644 --- a/packages/dock-blockchain-modules/src/accumulator/internal.js +++ b/packages/dock-blockchain-modules/src/accumulator/internal.js @@ -1,13 +1,17 @@ -import { DockDidOrDidMethodKey } from '@docknetwork/credential-sdk/types/did/onchain'; +import { DockDidOrDidMethodKey } from "@docknetwork/credential-sdk/types/did/onchain"; import { DockAccumulatorCounters, AccumulatorParams, AccumulatorPublicKey, DockAccumulatorId, -} from '@docknetwork/credential-sdk/types'; -import { inclusiveRange, u8aToHex } from '@docknetwork/credential-sdk/utils'; -import { VBWitnessUpdateInfo } from '@docknetwork/credential-sdk/crypto'; -import { ParamsAndPublicKeys, createInternalDockModule } from '../common'; +} from "@docknetwork/credential-sdk/types"; +import { inclusiveRange, u8aToHex } from "@docknetwork/credential-sdk/utils"; +import { VBWitnessUpdateInfo } from "@docknetwork/credential-sdk/crypto"; +import { + injectParams, + injectPublicKeys, + createInternalDockModule, +} from "../common"; import { AddAccumulator, AddAccumulatorParams, @@ -16,43 +20,44 @@ import { RemoveAccumulatorParams, RemoveAccumulatorPublicKey, UpdateAccumulator, -} from './actions'; +} from "./actions"; const didMethods = { - addAccumulator: (id, accumulator, _, nonce) => new AddAccumulator(id, accumulator, nonce), + addAccumulator: (id, accumulator, _, nonce) => + new AddAccumulator(id, accumulator, nonce), updateAccumulator: ( id, newAccumulated, { additions, removals, witnessUpdateInfo }, _, - nonce, - ) => new UpdateAccumulator( - id, - newAccumulated, - additions, - removals, - witnessUpdateInfo, - nonce, - ), + nonce + ) => + new UpdateAccumulator( + id, + newAccumulated, + additions, + removals, + witnessUpdateInfo, + nonce + ), removeAccumulator: (id, _, nonce) => new RemoveAccumulator(id, nonce), }; -export default class DockInternalAccumulatorModule extends createInternalDockModule( - { didMethods }, - ParamsAndPublicKeys, +export default class DockInternalAccumulatorModule extends injectParams( + injectPublicKeys(createInternalDockModule({ didMethods })) ) { - static Prop = 'accumulator'; + static Prop = "accumulator"; static MethodNameOverrides = { - addPublicKey: 'AddAccumulatorPublicKey', - removePublicKey: 'RemoveAccumulatorPublicKey', - addParams: 'AddAccumulatorParams', - removeParams: 'RemoveAccumulatorParams', + addPublicKey: "AddAccumulatorPublicKey", + removePublicKey: "RemoveAccumulatorPublicKey", + addParams: "AddAccumulatorParams", + removeParams: "RemoveAccumulatorParams", }; - static ParamsQuery = 'accumulatorParams'; + static ParamsQuery = "accumulatorParams"; - static PublicKeyQuery = 'accumulatorKeys'; + static PublicKeyQuery = "accumulatorKeys"; static PublicKey = AccumulatorPublicKey; @@ -69,7 +74,7 @@ export default class DockInternalAccumulatorModule extends createInternalDockMod async counters(did) { return DockAccumulatorCounters.from( - await this.query.accumulatorOwnerCounters(DockDidOrDidMethodKey.from(did)), + await this.query.accumulatorOwnerCounters(DockDidOrDidMethodKey.from(did)) ); } @@ -98,7 +103,7 @@ export default class DockInternalAccumulatorModule extends createInternalDockMod witness, startBlock, endBlock = undefined, - batchSize = 10, + batchSize = 10 ) { if (endBlock === undefined) { const accum = await this.getAccumulator(accumulatorId, false); @@ -108,38 +113,39 @@ export default class DockInternalAccumulatorModule extends createInternalDockMod } // If endBlock < startBlock, it won't throw an error but won't fetch any updates and witness won't be updated. console.debug( - `Will start updating witness from block ${startBlock} to ${endBlock}`, + `Will start updating witness from block ${startBlock} to ${endBlock}` ); let current = startBlock; while (current <= endBlock) { - const till = current + batchSize <= endBlock ? current + batchSize : endBlock; + const till = + current + batchSize <= endBlock ? current + batchSize : endBlock; // Get updates from blocks [current, current + 1, current + 2, ..., till] // eslint-disable-next-line no-await-in-loop const updates = await this.getUpdatesFromBlocks( accumulatorId, - inclusiveRange(current, till, 1), + inclusiveRange(current, till, 1) ); for (const update of updates) { const additions = [...(update.additions ?? [])].map( - (value) => value.bytes, + (value) => value.bytes ); const removals = [...(update.removals ?? [])].map( - (value) => value.bytes, + (value) => value.bytes ); console.debug( - `Found ${additions?.length} additions and ${removals?.length} removals in block no ${current}`, + `Found ${additions?.length} additions and ${removals?.length} removals in block no ${current}` ); const queriedWitnessInfo = new VBWitnessUpdateInfo( - update.witnessUpdateInfo.bytes, + update.witnessUpdateInfo.bytes ); witness.updateUsingPublicInfoPostBatchUpdate( member, additions, removals, - queriedWitnessInfo, + queriedWitnessInfo ); } current = till + 1; @@ -155,8 +161,8 @@ export default class DockInternalAccumulatorModule extends createInternalDockMod */ static parseEventAsAccumulatorUpdate(event) { if ( - event.section === 'accumulator' - && event.method === 'AccumulatorUpdated' + event.section === "accumulator" && + event.method === "AccumulatorUpdated" ) { return [u8aToHex(event.data[0]), u8aToHex(event.data[1])]; } @@ -174,7 +180,7 @@ export default class DockInternalAccumulatorModule extends createInternalDockMod async getUpdatesFromBlock(accumulatorId, blockNoOrBlockHash) { const extrinsics = await this.apiProvider.getAllExtrinsicsFromBlock( blockNoOrBlockHash, - false, + false ); return extrinsics @@ -194,8 +200,8 @@ export default class DockInternalAccumulatorModule extends createInternalDockMod // NOTE: polkadot-js doesn't allow to fetch more than one block in 1 RPC call. const extrinsics = await Promise.all( blockNosOrBlockHashes.map( - async (b) => await this.apiProvider.getAllExtrinsicsFromBlock(b, false), - ), + async (b) => await this.apiProvider.getAllExtrinsicsFromBlock(b, false) + ) ); return extrinsics @@ -215,12 +221,12 @@ export default class DockInternalAccumulatorModule extends createInternalDockMod const accId = DockAccumulatorId.from(accumulatorId); if ( - ext.method - && ext.method.section === 'accumulator' - && ext.method.method === 'updateAccumulator' + ext.method && + ext.method.section === "accumulator" && + ext.method.method === "updateAccumulator" ) { const update = UpdateAccumulator.from( - this.apiProvider.api.createType('UpdateAccumulator', ext.method.args[0]), + this.apiProvider.api.createType("UpdateAccumulator", ext.method.args[0]) ); if (update.id.eq(accId.asDock)) { diff --git a/packages/dock-blockchain-modules/src/accumulator/module.js b/packages/dock-blockchain-modules/src/accumulator/module.js index 36765fef4..17881c36c 100644 --- a/packages/dock-blockchain-modules/src/accumulator/module.js +++ b/packages/dock-blockchain-modules/src/accumulator/module.js @@ -10,11 +10,11 @@ import { DockAccumulatorPublicKey, DockAccumulatorParamsRef, DockAccumulatorIdIdent, -} from '@docknetwork/credential-sdk/types'; -import { option, withProp } from '@docknetwork/credential-sdk/types/generic'; -import { AbstractAccumulatorModule } from '@docknetwork/credential-sdk/modules/abstract/accumulator'; -import DockInternalAccumulatorModule from './internal'; -import { withParamsAndPublicKeys } from '../common'; +} from "@docknetwork/credential-sdk/types"; +import { option, withProp } from "@docknetwork/credential-sdk/types/generic"; +import { AbstractAccumulatorModule } from "@docknetwork/credential-sdk/modules/abstract/accumulator"; +import DockInternalAccumulatorModule from "./internal"; +import { injectDock, withParams, withPublicKeys } from "../common"; export const AccumulatorType = { VBPos: 0, @@ -23,8 +23,8 @@ export const AccumulatorType = { }; /** Class to manage accumulators on chain */ -export default class DockAccumulatorModule extends withParamsAndPublicKeys( - AbstractAccumulatorModule, +export default class DockAccumulatorModule extends withParams( + withPublicKeys(injectDock(AbstractAccumulatorModule)) ) { static DockOnly = DockInternalAccumulatorModule; @@ -72,9 +72,9 @@ export default class DockAccumulatorModule extends withParamsAndPublicKeys( return await this.dockOnly.tx.addAccumulator( id, new DockPositiveAccumulator( - new DockAccumulatorCommon(accumulated, publicKeyRef), + new DockAccumulatorCommon(accumulated, publicKeyRef) ), - didKeypair, + didKeypair ); } @@ -94,17 +94,17 @@ export default class DockAccumulatorModule extends withParamsAndPublicKeys( accumulated, publicKeyRef, maxSize, - didKeypair, + didKeypair ) { return await this.dockOnly.tx.addAccumulator( id, new DockUniversalAccumulator( new DockUniversalAccumulator.Class( new DockAccumulatorCommon(accumulated, publicKeyRef), - maxSize, - ), + maxSize + ) ), - didKeypair, + didKeypair ); } @@ -122,9 +122,9 @@ export default class DockAccumulatorModule extends withParamsAndPublicKeys( return await this.dockOnly.tx.addAccumulator( id, new DockKBUniversalAccumulator( - new DockAccumulatorCommon(accumulated, publicKeyRef), + new DockAccumulatorCommon(accumulated, publicKeyRef) ), - didKeypair, + didKeypair ); } @@ -143,7 +143,7 @@ export default class DockAccumulatorModule extends withParamsAndPublicKeys( id, newAccumulated, { additions, removals, witnessUpdateInfo }, - didKeypair, + didKeypair ) { return await this.dockOnly.tx.updateAccumulator( id, @@ -153,7 +153,7 @@ export default class DockAccumulatorModule extends withParamsAndPublicKeys( removals, witnessUpdateInfo, }, - didKeypair, + didKeypair ); } @@ -180,14 +180,14 @@ export default class DockAccumulatorModule extends withParamsAndPublicKeys( */ async getAccumulator(id, includePublicKey = false, includeParams = false) { const PublicKey = includeParams - ? withProp(DockAccumulatorPublicKey, 'params', option(AccumulatorParams)) + ? withProp(DockAccumulatorPublicKey, "params", option(AccumulatorParams)) : DockAccumulatorPublicKey; const Accumulator = includePublicKey - ? withProp(DockAccumulatorWithUpdateInfo, 'publicKey', option(PublicKey)) + ? withProp(DockAccumulatorWithUpdateInfo, "publicKey", option(PublicKey)) : DockAccumulatorWithUpdateInfo; const acc = option(Accumulator).from( - await this.dockOnly.query.accumulators(DockAccumulatorIdIdent.from(id)), + await this.dockOnly.query.accumulators(DockAccumulatorIdIdent.from(id)) ); if (acc == null) { @@ -218,7 +218,7 @@ export default class DockAccumulatorModule extends withParamsAndPublicKeys( member, witness, start, - end, + end ); } } diff --git a/packages/dock-blockchain-modules/src/common/index.js b/packages/dock-blockchain-modules/src/common/index.js index 778f0d33b..3dc1a6283 100644 --- a/packages/dock-blockchain-modules/src/common/index.js +++ b/packages/dock-blockchain-modules/src/common/index.js @@ -1,4 +1,6 @@ -export * from './builders'; -export { default as injectDock } from './inject-dock'; -export { default as withParamsAndPublicKeys } from './with-params-and-public-keys'; -export { default as ParamsAndPublicKeys } from './params-and-public-keys'; +export * from "./builders"; +export { default as injectDock } from "./inject-dock"; +export { default as withParams } from "./with-params"; +export { default as withPublicKeys } from "./with-public-keys"; +export { default as injectParams } from "./inject-params"; +export { default as injectPublicKeys } from "./inject-public-keys"; diff --git a/packages/dock-blockchain-modules/src/common/with-params.js b/packages/dock-blockchain-modules/src/common/with-params.js index 7fe32266e..2e2cb439e 100644 --- a/packages/dock-blockchain-modules/src/common/with-params.js +++ b/packages/dock-blockchain-modules/src/common/with-params.js @@ -1,4 +1,4 @@ -import { withExtendedStaticProperties } from "@docknetwork/credential-sdk/utils/inheritance"; +import { withExtendedStaticProperties } from "@docknetwork/credential-sdk/utils"; import injectDock from "./inject-dock"; /** @@ -9,7 +9,7 @@ export default function withParams(klass) { const name = `withParams(${klass.name})`; const obj = { - [name]: class extends injectDock(klass) { + [name]: class extends klass { /** * Add new signature params. * @param param - The signature params to add. diff --git a/packages/dock-blockchain-modules/src/common/with-public-keys.js b/packages/dock-blockchain-modules/src/common/with-public-keys.js index a61e328fa..13cf8e34c 100644 --- a/packages/dock-blockchain-modules/src/common/with-public-keys.js +++ b/packages/dock-blockchain-modules/src/common/with-public-keys.js @@ -12,7 +12,7 @@ export default function withPublicKeys(klass) { const name = `withPublicKeys(${klass.name})`; const obj = { - [name]: class extends injectDock(klass) { + [name]: class extends klass { /** * Add a public key * @param publicKey - public key to add. diff --git a/packages/dock-blockchain-modules/src/offchain-signatures/module.js b/packages/dock-blockchain-modules/src/offchain-signatures/module.js index c8c1bbe3d..0452e08fb 100644 --- a/packages/dock-blockchain-modules/src/offchain-signatures/module.js +++ b/packages/dock-blockchain-modules/src/offchain-signatures/module.js @@ -4,10 +4,11 @@ import { AbstractOffchainSignaturesModule } from "@docknetwork/credential-sdk/mo import { DockOffchainSignatureParamsRef } from "@docknetwork/credential-sdk/types"; import DockInternalOffchainSignaturesModule from "./internal"; import withParams from "../common/with-params"; +import { injectDock } from "../common"; /** Class to write offchain signature parameters and keys on chain */ export default class DockOffchainSignaturesModule extends withParams( - AbstractOffchainSignaturesModule + injectDock(AbstractOffchainSignaturesModule) ) { static DockOnly = DockInternalOffchainSignaturesModule;