Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
olegnn committed Nov 5, 2024
1 parent d40e35b commit f4cde36
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 257 deletions.
69 changes: 38 additions & 31 deletions packages/credential-sdk/src/modules/abstract/accumulator/module.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -56,7 +63,7 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys {
publicKey,
targetDid,
didKeypair,
params,
params
);
}

Expand All @@ -73,7 +80,7 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys {
removeKeyId,
targetDid,
didKeypair,
params,
params
);
}

Expand All @@ -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
);
}

Expand All @@ -120,17 +127,17 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys {
publicKeyRef,
maxSize,
didKeypair,
params,
params
) {
return await this.signAndSend(
await this.addUniversalAccumulatorTx(
id,
accumulated,
publicKeyRef,
maxSize,
didKeypair,
didKeypair
),
params,
params
);
}

Expand All @@ -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
);
}

Expand All @@ -176,7 +183,7 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys {
newAccumulated,
{ additions, removals, witnessUpdateInfo },
didKeypair,
params,
params
) {
return await this.signAndSend(
await this.updateAccumulatorTx(
Expand All @@ -187,9 +194,9 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys {
removals,
witnessUpdateInfo,
},
didKeypair,
didKeypair
),
params,
params
);
}

Expand All @@ -202,7 +209,7 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys {
async removeAccumulator(id, didKeypair, params) {
return await this.signAndSend(
await this.removeAccumulatorTx(id, didKeypair),
params,
params
);
}

Expand All @@ -217,7 +224,7 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys {
* @returns {Promise<Accumulator|null>}
*/
async getAccumulator(id, _includeKey = false, _includeKeyParams = false) {
throw new Error('Unimplemented');
throw new Error("Unimplemented");
}

/**
Expand All @@ -232,19 +239,19 @@ class AbstractAccumulatorModule extends AbstractWithParamsAndPublicKeys {
* @returns {Promise<void>}
*/
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
);
3 changes: 2 additions & 1 deletion packages/credential-sdk/src/modules/abstract/common/index.js
Original file line number Diff line number Diff line change
@@ -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";
155 changes: 79 additions & 76 deletions packages/credential-sdk/src/modules/abstract/common/with-params.js
Original file line number Diff line number Diff line change
@@ -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<Params>}
*/
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<Map<Id, Params>>}
*/
async getAllParamsByDid(_did) {
throw new Error("Unimplemented");
}
/**
* Retrieves params by a DID and unique identifier.
* @param {*} did
* @param {*} id
* @returns {Promise<Params>}
*/
async getParams(_did, _id) {
throw new Error("Unimplemented");
}

/**
* Retrieves latest params identifier used by the supplied DID.
* @param {*} did
* @returns {Promise<Id>}
*/
async lastParamsId(_targetDid) {
throw new Error("Unimplemented");
}
/**
* Retrieves all params by a DID
* @param {*} did
* @returns {Promise<Map<Id, Params>>}
*/
async getAllParamsByDid(_did) {
throw new Error("Unimplemented");
}

/**
* Retrieves next params identifier that can be used by the supplied DID.
* @param {*} did
* @returns {Promise<Id>}
*/
async nextParamsId(_targetDid) {
throw new Error("Unimplemented");
}
}
/**
* Retrieves latest params identifier used by the supplied DID.
* @param {*} did
* @returns {Promise<Id>}
*/
async lastParamsId(_targetDid) {
throw new Error("Unimplemented");
}

/**
* Retrieves next params identifier that can be used by the supplied DID.
* @param {*} did
* @returns {Promise<Id>}
*/
async nextParamsId(_targetDid) {
throw new Error("Unimplemented");
}
},
};

/**
* Abstract logic allowing to operate with public keys and parameters.
Expand All @@ -100,6 +103,6 @@ export default function withParams(klass) {
"lastParamsId",
"nextParamsId",
],
withExtendedStaticProperties(["Params"], AbstractWithParams)
withExtendedStaticProperties(["Params"], obj[name])
);
}
Loading

0 comments on commit f4cde36

Please sign in to comment.