@0xpolygonid/js-sdk 1.18.3 → 1.18.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/browser/esm/index.js +23 -22
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +23 -22
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/identity/identity-wallet.js +23 -22
- package/dist/node/esm/identity/identity-wallet.js +23 -22
- package/dist/types/identity/identity-wallet.d.ts +7 -1
- package/package.json +1 -1
|
@@ -176,12 +176,20 @@ class IdentityWallet {
|
|
|
176
176
|
},
|
|
177
177
|
allowedIssuers: [did.string()]
|
|
178
178
|
});
|
|
179
|
-
if
|
|
179
|
+
// if credential exists with the same credential status type we return this credential
|
|
180
|
+
if (credentials.length === 1 &&
|
|
181
|
+
credentials[0].credentialStatus.type === opts.revocationOpts.type) {
|
|
180
182
|
return {
|
|
181
183
|
did,
|
|
182
184
|
credential: credentials[0]
|
|
183
185
|
};
|
|
184
186
|
}
|
|
187
|
+
// otherwise something is already wrong with storage as it has more than 1 credential in it or credential status type of existing credential is different from what user provides - We should remove everything and create new credential.
|
|
188
|
+
// in this way credential status of auth credential can be upgraded
|
|
189
|
+
for (let i = 0; i < credentials.length; i++) {
|
|
190
|
+
await this._credentialWallet.remove(credentials[i].id);
|
|
191
|
+
}
|
|
192
|
+
// otherwise we create a new credential
|
|
185
193
|
const credential = await this.createAuthBJJCredential(did, pubKey, authClaim, currentState, opts.revocationOpts);
|
|
186
194
|
const index = authClaim.hIndex();
|
|
187
195
|
const { proof } = await claimsTree.generateProof(index, ctr);
|
|
@@ -199,10 +207,13 @@ class IdentityWallet {
|
|
|
199
207
|
coreClaim: authClaim
|
|
200
208
|
});
|
|
201
209
|
credential.proof = [mtpProof];
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
210
|
+
// only if user specified that genesis state publishing is not needed we won't do this.
|
|
211
|
+
if (!opts.revocationOpts.genesisPublishingDisabled) {
|
|
212
|
+
await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
|
|
213
|
+
rhsUrl: opts.revocationOpts.id,
|
|
214
|
+
onChain: opts.revocationOpts.onChain
|
|
215
|
+
});
|
|
216
|
+
}
|
|
206
217
|
await this._credentialWallet.save(credential);
|
|
207
218
|
return {
|
|
208
219
|
did,
|
|
@@ -565,23 +576,13 @@ class IdentityWallet {
|
|
|
565
576
|
throw new Error(`there is no registered publisher to save hash is not registered for ${credentialStatusType} is not registered`);
|
|
566
577
|
}
|
|
567
578
|
let nodes = [];
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
else {
|
|
577
|
-
const treeState = await this.getDIDTreeModel(issuerDID);
|
|
578
|
-
nodes = await (0, credentials_1.getNodesRepresentation)(opts?.revokedNonces, {
|
|
579
|
-
revocationTree: treeState.revocationTree,
|
|
580
|
-
claimsTree: treeState.claimsTree,
|
|
581
|
-
state: treeState.state,
|
|
582
|
-
rootsTree: treeState.rootsTree
|
|
583
|
-
}, treeState.state);
|
|
584
|
-
}
|
|
579
|
+
const tree = opts?.treeModel ?? (await this.getDIDTreeModel(issuerDID));
|
|
580
|
+
nodes = await (0, credentials_1.getNodesRepresentation)(opts?.revokedNonces ?? [], {
|
|
581
|
+
revocationTree: tree.revocationTree,
|
|
582
|
+
claimsTree: tree.claimsTree,
|
|
583
|
+
state: tree.state,
|
|
584
|
+
rootsTree: tree.rootsTree
|
|
585
|
+
}, tree.state);
|
|
585
586
|
if (!nodes.length) {
|
|
586
587
|
return;
|
|
587
588
|
}
|
|
@@ -150,12 +150,20 @@ export class IdentityWallet {
|
|
|
150
150
|
},
|
|
151
151
|
allowedIssuers: [did.string()]
|
|
152
152
|
});
|
|
153
|
-
if
|
|
153
|
+
// if credential exists with the same credential status type we return this credential
|
|
154
|
+
if (credentials.length === 1 &&
|
|
155
|
+
credentials[0].credentialStatus.type === opts.revocationOpts.type) {
|
|
154
156
|
return {
|
|
155
157
|
did,
|
|
156
158
|
credential: credentials[0]
|
|
157
159
|
};
|
|
158
160
|
}
|
|
161
|
+
// otherwise something is already wrong with storage as it has more than 1 credential in it or credential status type of existing credential is different from what user provides - We should remove everything and create new credential.
|
|
162
|
+
// in this way credential status of auth credential can be upgraded
|
|
163
|
+
for (let i = 0; i < credentials.length; i++) {
|
|
164
|
+
await this._credentialWallet.remove(credentials[i].id);
|
|
165
|
+
}
|
|
166
|
+
// otherwise we create a new credential
|
|
159
167
|
const credential = await this.createAuthBJJCredential(did, pubKey, authClaim, currentState, opts.revocationOpts);
|
|
160
168
|
const index = authClaim.hIndex();
|
|
161
169
|
const { proof } = await claimsTree.generateProof(index, ctr);
|
|
@@ -173,10 +181,13 @@ export class IdentityWallet {
|
|
|
173
181
|
coreClaim: authClaim
|
|
174
182
|
});
|
|
175
183
|
credential.proof = [mtpProof];
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
184
|
+
// only if user specified that genesis state publishing is not needed we won't do this.
|
|
185
|
+
if (!opts.revocationOpts.genesisPublishingDisabled) {
|
|
186
|
+
await this.publishRevocationInfoByCredentialStatusType(did, opts.revocationOpts.type, {
|
|
187
|
+
rhsUrl: opts.revocationOpts.id,
|
|
188
|
+
onChain: opts.revocationOpts.onChain
|
|
189
|
+
});
|
|
190
|
+
}
|
|
180
191
|
await this._credentialWallet.save(credential);
|
|
181
192
|
return {
|
|
182
193
|
did,
|
|
@@ -539,23 +550,13 @@ export class IdentityWallet {
|
|
|
539
550
|
throw new Error(`there is no registered publisher to save hash is not registered for ${credentialStatusType} is not registered`);
|
|
540
551
|
}
|
|
541
552
|
let nodes = [];
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
550
|
-
else {
|
|
551
|
-
const treeState = await this.getDIDTreeModel(issuerDID);
|
|
552
|
-
nodes = await getNodesRepresentation(opts?.revokedNonces, {
|
|
553
|
-
revocationTree: treeState.revocationTree,
|
|
554
|
-
claimsTree: treeState.claimsTree,
|
|
555
|
-
state: treeState.state,
|
|
556
|
-
rootsTree: treeState.rootsTree
|
|
557
|
-
}, treeState.state);
|
|
558
|
-
}
|
|
553
|
+
const tree = opts?.treeModel ?? (await this.getDIDTreeModel(issuerDID));
|
|
554
|
+
nodes = await getNodesRepresentation(opts?.revokedNonces ?? [], {
|
|
555
|
+
revocationTree: tree.revocationTree,
|
|
556
|
+
claimsTree: tree.claimsTree,
|
|
557
|
+
state: tree.state,
|
|
558
|
+
rootsTree: tree.rootsTree
|
|
559
|
+
}, tree.state);
|
|
559
560
|
if (!nodes.length) {
|
|
560
561
|
return;
|
|
561
562
|
}
|
|
@@ -24,13 +24,19 @@ export type IdentityCreationOptions = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Options for creating Auth BJJ credential
|
|
26
26
|
* seed - seed to generate BJJ key pair
|
|
27
|
-
* revocationOpts
|
|
27
|
+
* revocationOpts
|
|
28
|
+
* nonce - explicit revocation nonce to use
|
|
29
|
+
* onChain - onchain status related option
|
|
30
|
+
* txCallback - defines how the TransactionReceipt is handled
|
|
31
|
+
* publishMode - specifies the work of transaction polling type: sync / async / callback
|
|
32
|
+
* genesisPublishingDisabled - genesis is publishing by default. Set `true` to prevent genesis publishing
|
|
28
33
|
*/
|
|
29
34
|
export type AuthBJJCredentialCreationOptions = {
|
|
30
35
|
revocationOpts: {
|
|
31
36
|
id: string;
|
|
32
37
|
type: CredentialStatusType;
|
|
33
38
|
nonce?: number;
|
|
39
|
+
genesisPublishingDisabled?: boolean;
|
|
34
40
|
onChain?: {
|
|
35
41
|
txCallback?: (tx: TransactionReceipt) => Promise<void>;
|
|
36
42
|
publishMode?: PublishMode;
|