Skip to content

Commit 82d19b6

Browse files
committed
more docs
Signed-off-by: lovesh <lovesh.bond@gmail.com>
1 parent 59dd589 commit 82d19b6

32 files changed

+635
-314
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v1
1414
- uses: actions/setup-node@v1
15+
- run: yarn install
1516

1617
- name: Build docs
1718
run: yarn typedoc

src/accumulator/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ export * from './IAccumulatorState';
66
export * from './IInitialElementsStore';
77
export * from './kb-universal-accumulator';
88
export * from './kb-acccumulator-witness';
9-
export { VBWitnessUpdateInfo, KBUniversalMembershipWitnessUpdateInfo, KBUniversalNonMembershipWitnessUpdateInfo } from './witness-update-info';
9+
export {
10+
VBWitnessUpdateInfo,
11+
KBUniversalMembershipWitnessUpdateInfo,
12+
KBUniversalNonMembershipWitnessUpdateInfo
13+
} from './witness-update-info';

src/accumulator/kb-universal-accumulator.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,7 @@ export class KBUniversalAccumulator extends Accumulator<KBUniversalAccumulatorVa
260260
): KBUniversalMembershipWitnessUpdateInfo {
261261
const sk = this.getSecretKey(secretKey);
262262
return new KBUniversalMembershipWitnessUpdateInfo(
263-
publicInfoForKBUniversalMemWitnessUpdate(
264-
this.value.asInternalType,
265-
additions,
266-
removals,
267-
sk.value
268-
)
263+
publicInfoForKBUniversalMemWitnessUpdate(this.value.asInternalType, additions, removals, sk.value)
269264
);
270265
}
271266

@@ -276,12 +271,7 @@ export class KBUniversalAccumulator extends Accumulator<KBUniversalAccumulatorVa
276271
): KBUniversalNonMembershipWitnessUpdateInfo {
277272
const sk = this.getSecretKey(secretKey);
278273
return new KBUniversalNonMembershipWitnessUpdateInfo(
279-
publicInfoForKBUniversalNonMemWitnessUpdate(
280-
this.value.asInternalType,
281-
additions,
282-
removals,
283-
sk.value
284-
)
274+
publicInfoForKBUniversalNonMemWitnessUpdate(this.value.asInternalType, additions, removals, sk.value)
285275
);
286276
}
287277

@@ -291,11 +281,7 @@ export class KBUniversalAccumulator extends Accumulator<KBUniversalAccumulatorVa
291281
): KBUniversalNonMembershipWitnessUpdateInfo {
292282
const sk = this.getSecretKey(secretKey);
293283
return new KBUniversalNonMembershipWitnessUpdateInfo(
294-
publicInfoForKBUniversalNonMemWitnessUpdateOnDomainExtension(
295-
this.value.asInternalType,
296-
newElements,
297-
sk.value
298-
)
284+
publicInfoForKBUniversalNonMemWitnessUpdateOnDomainExtension(this.value.asInternalType, newElements, sk.value)
299285
);
300286
}
301287

@@ -306,7 +292,7 @@ export class KBUniversalAccumulator extends Accumulator<KBUniversalAccumulatorVa
306292
): [KBUniversalMembershipWitnessUpdateInfo, KBUniversalNonMembershipWitnessUpdateInfo] {
307293
const sk = this.getSecretKey(secretKey);
308294
const [m, nm] = publicInfoForBothKBUniversalWitnessUpdate(this.value.asInternalType, additions, removals, sk.value);
309-
return [new KBUniversalMembershipWitnessUpdateInfo(m), new KBUniversalNonMembershipWitnessUpdateInfo(nm)]
295+
return [new KBUniversalMembershipWitnessUpdateInfo(m), new KBUniversalNonMembershipWitnessUpdateInfo(nm)];
310296
}
311297

312298
protected async checkBeforeAdd(element: Uint8Array, state?: IKBUniversalAccumulatorState) {

src/accumulator/params-and-keys.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ export class AccumulatorParamsForKeyedVerification extends BytearrayWrapper {
132132
}
133133

134134
export class AccumulatorPublicKeyForKeyedVerification extends BytearrayWrapper {
135-
static generate(secretKey: AccumulatorSecretKey, params: AccumulatorParamsForKeyedVerification): AccumulatorPublicKeyForKeyedVerification {
136-
return new AccumulatorPublicKeyForKeyedVerification(generateAccumulatorPublicKeyForKeyedVerification(secretKey.value, params.value));
135+
static generate(
136+
secretKey: AccumulatorSecretKey,
137+
params: AccumulatorParamsForKeyedVerification
138+
): AccumulatorPublicKeyForKeyedVerification {
139+
return new AccumulatorPublicKeyForKeyedVerification(
140+
generateAccumulatorPublicKeyForKeyedVerification(secretKey.value, params.value)
141+
);
137142
}
138143
}

src/accumulator/witness-update-info.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
publicInfoForWitnessUpdate,
33
publicInfoForKBUniversalMemWitnessUpdate,
4-
publicInfoForKBUniversalNonMemWitnessUpdate, publicInfoForKBUniversalNonMemWitnessUpdateOnDomainExtension
4+
publicInfoForKBUniversalNonMemWitnessUpdate,
5+
publicInfoForKBUniversalNonMemWitnessUpdateOnDomainExtension
56
} from 'crypto-wasm-new';
67
import { BytearrayWrapper } from '../bytearray-wrapper';
78
import { fromLeToBigInt, jsonObjToUint8Array } from '../util';
@@ -42,6 +43,9 @@ export class VBWitnessUpdateInfo extends WitnessUpdateInfo {
4243
}
4344
}
4445

46+
/**
47+
* Public info published by the KB universal accumulator manager used to update membership witnesses after several additions and removals.
48+
*/
4549
export class KBUniversalMembershipWitnessUpdateInfo extends WitnessUpdateInfo {
4650
fromJSON(json: string): KBUniversalMembershipWitnessUpdateInfo {
4751
return new KBUniversalMembershipWitnessUpdateInfo(jsonObjToUint8Array(json));
@@ -146,9 +150,11 @@ export class KBUniversalWitnessUpdateInfo {
146150
toBytes(): Uint8Array {
147151
const memLength = this.mem ? this.mem.value.length : 0;
148152
if (memLength > KBUniversalWitnessUpdateInfo.maxLength) {
149-
throw new Error(`Cannot support sizes greater than ${KBUniversalWitnessUpdateInfo.maxLength}`)
153+
throw new Error(`Cannot support sizes greater than ${KBUniversalWitnessUpdateInfo.maxLength}`);
150154
}
151-
const buf = Buffer.allocUnsafe(KBUniversalWitnessUpdateInfo.maxByteSize + memLength + (this.nonMem ? this.nonMem.value.length : 0));
155+
const buf = Buffer.allocUnsafe(
156+
KBUniversalWitnessUpdateInfo.maxByteSize + memLength + (this.nonMem ? this.nonMem.value.length : 0)
157+
);
152158
// Write the byte size of membership witness update info in the first `maxByteSize` bytes in little-endian format
153159
buf.writeUIntLE(memLength, 0, KBUniversalWitnessUpdateInfo.maxByteSize);
154160
const merged = new Uint8Array(buf);
@@ -168,10 +174,18 @@ export class KBUniversalWitnessUpdateInfo {
168174
static fromBytes(bytes: Uint8Array): KBUniversalWitnessUpdateInfo {
169175
const memLength = fromLeToBigInt(bytes, KBUniversalWitnessUpdateInfo.maxByteSize);
170176
if (memLength > KBUniversalWitnessUpdateInfo.maxLength) {
171-
throw new Error(`Cannot support sizes greater than ${KBUniversalWitnessUpdateInfo.maxLength}`)
177+
throw new Error(`Cannot support sizes greater than ${KBUniversalWitnessUpdateInfo.maxLength}`);
172178
}
173179
// Create the update info if non-zero byte size found
174-
const mem = memLength > 0 ? new KBUniversalMembershipWitnessUpdateInfo(bytes.slice(KBUniversalWitnessUpdateInfo.maxByteSize, KBUniversalWitnessUpdateInfo.maxByteSize + Number(memLength))) : undefined;
180+
const mem =
181+
memLength > 0
182+
? new KBUniversalMembershipWitnessUpdateInfo(
183+
bytes.slice(
184+
KBUniversalWitnessUpdateInfo.maxByteSize,
185+
KBUniversalWitnessUpdateInfo.maxByteSize + Number(memLength)
186+
)
187+
)
188+
: undefined;
175189
const nonMemVal = bytes.slice(KBUniversalWitnessUpdateInfo.maxByteSize + Number(memLength));
176190
const nonMem = nonMemVal.length > 0 ? new KBUniversalNonMembershipWitnessUpdateInfo(nonMemVal) : undefined;
177191
return new KBUniversalWitnessUpdateInfo(mem, nonMem);

src/anonymous-credentials/blinded-credential-builder.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { CredentialBuilderCommon } from './credential-builder-common';
33
import { IBlindCredentialRequest } from './presentation-specification';
44
import {
55
BBS_PLUS_SIGNATURE_PARAMS_LABEL_BYTES,
6-
BBS_SIGNATURE_PARAMS_LABEL_BYTES, STATUS_STR,
6+
BBS_SIGNATURE_PARAMS_LABEL_BYTES,
7+
STATUS_STR,
78
BBDT16_MAC_PARAMS_LABEL_BYTES
89
} from './types-and-consts';
910
import { BBSCredential, BBSPlusCredential, BBDT16Credential } from './credential';
@@ -36,9 +37,11 @@ export abstract class BlindedCredentialBuilder extends CredentialBuilderCommon {
3637
let knownAttributes = this.serializeForSigning();
3738
if (this.blindedCredReq.unBlindedAttributes !== undefined) {
3839
if (typeof this.blindedCredReq.unBlindedAttributes !== 'object') {
39-
throw new Error(`Unblinded attributes were supposed to an object but found ${this.blindedCredReq.unBlindedAttributes}`)
40+
throw new Error(
41+
`Unblinded attributes were supposed to an object but found ${this.blindedCredReq.unBlindedAttributes}`
42+
);
4043
}
41-
knownAttributes = {...knownAttributes, ...this.blindedCredReq.unBlindedAttributes};
44+
knownAttributes = { ...knownAttributes, ...this.blindedCredReq.unBlindedAttributes };
4245
}
4346
const encodedAttributes = new Map<number, Uint8Array>();
4447
Object.entries(schema.encoder.encodeMessageObjectAsObjectConstantTime(knownAttributes)).forEach(([name, value]) => {
@@ -50,12 +53,14 @@ export abstract class BlindedCredentialBuilder extends CredentialBuilderCommon {
5053
protected processUnBlindedAttributes() {
5154
if (this.blindedCredReq.unBlindedAttributes !== undefined) {
5255
if (typeof this.blindedCredReq.unBlindedAttributes !== 'object') {
53-
throw new Error(`Unblinded attributes were supposed to an object but found ${this.blindedCredReq.unBlindedAttributes}`)
56+
throw new Error(
57+
`Unblinded attributes were supposed to an object but found ${this.blindedCredReq.unBlindedAttributes}`
58+
);
5459
}
5560
for (const [name, value] of Object.entries(this.blindedCredReq.unBlindedAttributes)) {
5661
if (name === STATUS_STR) {
5762
if (this.credStatus !== undefined) {
58-
throw new Error('credStatus was set by the signer when it was provided in request as well')
63+
throw new Error('credStatus was set by the signer when it was provided in request as well');
5964
}
6065
this.credStatus = value;
6166
} else {

src/anonymous-credentials/blinded-credential-request-builder.ts

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ import {
4444
BlindSignatureType,
4545
BoundCheckParamType,
4646
BoundType,
47-
ID_STR, MEM_CHECK_KV_STR,
48-
MEM_CHECK_STR, NON_MEM_CHECK_KV_STR,
47+
ID_STR,
48+
MEM_CHECK_KV_STR,
49+
MEM_CHECK_STR,
50+
NON_MEM_CHECK_KV_STR,
4951
NON_MEM_CHECK_STR,
5052
PublicKey,
5153
REV_CHECK_STR,
@@ -64,43 +66,67 @@ type Credential = BBSCredential | BBSPlusCredential | PSCredential;
6466
* Creates a request for a blinded credential, i.e. where some of the attributes are not known to the signer
6567
*/
6668
export abstract class BlindedCredentialRequestBuilder<SigParams> extends Versioned {
67-
// NOTE: Follows semver and must be updated accordingly when the logic of this class changes or the
68-
// underlying crypto changes.
69+
/**
70+
* Follows semver and must be updated accordingly when the logic of this class changes or the
71+
* underlying crypto changes.
72+
*/
6973
static VERSION = '0.5.0';
7074

71-
// The schema of the whole (unblinded credential). This should include all attributes, i.e. blinded and unblinded
75+
/**
76+
* The schema of the whole (unblinded credential). This should include all attributes, i.e. blinded and unblinded
77+
*/
7278
_schema?: CredentialSchema;
7379

74-
// The attributes of the credential subject that will be blinded (hidden from the issuer)
80+
/**
81+
* The attributes of the credential subject that will be blinded (hidden from the issuer)
82+
*/
7583
_subjectToBlind?: object | object[];
7684

77-
// The credential status if blinded
85+
/**
86+
* The credential status if blinded
87+
*/
7888
_statusToBlind?: object;
7989

80-
// Any top level attributes to blind
90+
/**
91+
* Any top level attributes to blind
92+
*/
8193
_topLevelAttributesToBlind: Map<string, unknown>;
8294

8395
protected sigParams?: SignatureParams;
8496

85-
// A blinded credential request will contain a presentation that will prove predicates about the credential attributes and blinded attributes.
97+
/**
98+
* A blinded credential request will contain a presentation that will prove predicates about the credential attributes and blinded attributes.
99+
*/
86100
presentationBuilder: PresentationBuilder;
87101

88-
// Equalities between blinded and credential attributes
102+
/**
103+
* Equalities between blinded and credential attributes
104+
*/
89105
attributeEqualities: BlindedAttributeEquality[];
90106

91-
// Attributes proved inequal to a public value in zero knowledge. An attribute can be proven inequal to any number of values
107+
/**
108+
* Attributes proved inequal to a public value in zero knowledge. An attribute can be proven inequal to any number of values
109+
*/
92110
attributeInequalities: Map<string, [IPresentedAttributeInequality, Uint8Array][]>;
93111

94-
// Bounds on blinded attributes
112+
/**
113+
* Bounds on blinded attributes
114+
*/
95115
bounds: Map<string, IPresentedAttributeBound[]>;
96116

97-
// Encryption of blinded attributes
117+
/**
118+
* Encryption of blinded attributes
119+
*/
98120
verifEnc: Map<string, IPresentedAttributeVE[]>;
99121

100-
// Circom predicates on blinded attributes
122+
/**
123+
* Circom predicates on blinded attributes
124+
*/
101125
circomPredicates: IProverCircomPredicate[];
102126

103-
// Pseudonyms on blinded and credential attributes
127+
/**
128+
* Pseudonyms on blinded and credential attributes
129+
*/
104130
boundedPseudonyms: IProverBoundedPseudonymInBlindedCredReq[];
105131

106132
constructor() {
@@ -140,10 +166,12 @@ export abstract class BlindedCredentialRequestBuilder<SigParams> extends Version
140166
* @param memberValue - Only this will be blinded.
141167
* @param revType
142168
*/
143-
statusToBlind(registryId: string, revCheck: string, memberValue: unknown, revType= RevocationStatusProtocol.Vb22) {
169+
statusToBlind(registryId: string, revCheck: string, memberValue: unknown, revType = RevocationStatusProtocol.Vb22) {
144170
if (revType === RevocationStatusProtocol.Vb22) {
145171
if (revCheck !== MEM_CHECK_STR && revCheck !== NON_MEM_CHECK_STR && revCheck !== MEM_CHECK_KV_STR) {
146-
throw new Error(`Revocation check should be either ${MEM_CHECK_STR} or ${NON_MEM_CHECK_STR} or ${MEM_CHECK_KV_STR} but was ${revCheck}`);
172+
throw new Error(
173+
`Revocation check should be either ${MEM_CHECK_STR} or ${NON_MEM_CHECK_STR} or ${MEM_CHECK_KV_STR} but was ${revCheck}`
174+
);
147175
}
148176
}
149177
if (revType == RevocationStatusProtocol.KbUni24) {
@@ -519,9 +547,9 @@ export abstract class BlindedCredentialRequestBuilder<SigParams> extends Version
519547
[STATUS_STR]: {
520548
[TYPE_STR]: this._statusToBlind[TYPE_STR],
521549
[ID_STR]: this._statusToBlind[ID_STR],
522-
[REV_CHECK_STR]: this._statusToBlind[REV_CHECK_STR],
550+
[REV_CHECK_STR]: this._statusToBlind[REV_CHECK_STR]
523551
}
524-
}
552+
};
525553
}
526554

527555
const blindedAttributes = unflatten(attributesWithoutVals) as object;

0 commit comments

Comments
 (0)