@0xpolygonid/js-sdk 1.18.3 → 1.19.0
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 +37 -24
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/umd/index.js +37 -24
- package/dist/browser/umd/index.js.map +1 -1
- package/dist/node/cjs/identity/common.js +14 -2
- package/dist/node/cjs/identity/identity-wallet.js +23 -22
- package/dist/node/esm/identity/common.js +14 -2
- package/dist/node/esm/identity/identity-wallet.js +23 -22
- package/dist/types/iden3comm/types/packer.d.ts +1 -1
- package/dist/types/identity/common.d.ts +2 -2
- package/dist/types/identity/identity-wallet.d.ts +12 -6
- package/dist/types/proof/proof-service.d.ts +0 -1
- package/dist/types/proof/provers/inputs-generator.d.ts +2 -2
- package/dist/types/storage/entities/identity.d.ts +1 -1
- package/package.json +1 -1
|
@@ -41,12 +41,24 @@ exports.defineMerklizedRootPosition = defineMerklizedRootPosition;
|
|
|
41
41
|
* Returns profile DID based on did and profile nonce
|
|
42
42
|
*
|
|
43
43
|
* @param {DID} [did] - did from which profile will be derived
|
|
44
|
-
* @param {number} [profileNonce] - profile nonce
|
|
44
|
+
* @param {number | string} [profileNonce] - profile nonce
|
|
45
45
|
* @returns {DID}
|
|
46
46
|
*/
|
|
47
47
|
const generateProfileDID = (did, profileNonce) => {
|
|
48
48
|
const id = js_iden3_core_1.DID.idFromDID(did);
|
|
49
|
-
|
|
49
|
+
profileNonce = profileNonce ?? 0;
|
|
50
|
+
if (!isBigInt(profileNonce)) {
|
|
51
|
+
throw new Error('profile must be number or decimal string');
|
|
52
|
+
}
|
|
53
|
+
const profile = js_iden3_core_1.Id.profileId(id, BigInt(profileNonce));
|
|
50
54
|
return js_iden3_core_1.DID.parseFromId(profile);
|
|
51
55
|
};
|
|
52
56
|
exports.generateProfileDID = generateProfileDID;
|
|
57
|
+
const isBigInt = (x) => {
|
|
58
|
+
try {
|
|
59
|
+
return BigInt(x).toString() === x.toString();
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false; // conversion to BigInt failed, surely it is not a BigInt
|
|
63
|
+
}
|
|
64
|
+
};
|
|
@@ -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
|
}
|
|
@@ -36,11 +36,23 @@ export const defineMerklizedRootPosition = (metadata, position) => {
|
|
|
36
36
|
* Returns profile DID based on did and profile nonce
|
|
37
37
|
*
|
|
38
38
|
* @param {DID} [did] - did from which profile will be derived
|
|
39
|
-
* @param {number} [profileNonce] - profile nonce
|
|
39
|
+
* @param {number | string} [profileNonce] - profile nonce
|
|
40
40
|
* @returns {DID}
|
|
41
41
|
*/
|
|
42
42
|
export const generateProfileDID = (did, profileNonce) => {
|
|
43
43
|
const id = DID.idFromDID(did);
|
|
44
|
-
|
|
44
|
+
profileNonce = profileNonce ?? 0;
|
|
45
|
+
if (!isBigInt(profileNonce)) {
|
|
46
|
+
throw new Error('profile must be number or decimal string');
|
|
47
|
+
}
|
|
48
|
+
const profile = Id.profileId(id, BigInt(profileNonce));
|
|
45
49
|
return DID.parseFromId(profile);
|
|
46
50
|
};
|
|
51
|
+
const isBigInt = (x) => {
|
|
52
|
+
try {
|
|
53
|
+
return BigInt(x).toString() === x.toString();
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return false; // conversion to BigInt failed, surely it is not a BigInt
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -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
|
}
|
|
@@ -20,7 +20,7 @@ export declare const defineMerklizedRootPosition: (metadata?: SchemaMetadata, po
|
|
|
20
20
|
* Returns profile DID based on did and profile nonce
|
|
21
21
|
*
|
|
22
22
|
* @param {DID} [did] - did from which profile will be derived
|
|
23
|
-
* @param {number} [profileNonce] - profile nonce
|
|
23
|
+
* @param {number | string} [profileNonce] - profile nonce
|
|
24
24
|
* @returns {DID}
|
|
25
25
|
*/
|
|
26
|
-
export declare const generateProfileDID: (did: DID, profileNonce?: number) => DID;
|
|
26
|
+
export declare const generateProfileDID: (did: DID, profileNonce?: number | string) => DID;
|
|
@@ -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;
|
|
@@ -109,11 +115,11 @@ export interface IIdentityWallet {
|
|
|
109
115
|
* Creates profile based on genesis identifier
|
|
110
116
|
*
|
|
111
117
|
* @param {DID} did - identity to derive profile from
|
|
112
|
-
* @param {number} nonce - unique integer number to generate a profile
|
|
118
|
+
* @param {number |string} nonce - unique integer number to generate a profile
|
|
113
119
|
* @param {string} verifier - verifier identity/alias in a string from
|
|
114
120
|
* @returns `Promise<DID>` - profile did
|
|
115
121
|
*/
|
|
116
|
-
createProfile(did: DID, nonce: number, verifier: string): Promise<DID>;
|
|
122
|
+
createProfile(did: DID, nonce: number | string, verifier: string): Promise<DID>;
|
|
117
123
|
/**
|
|
118
124
|
* Generates a new key
|
|
119
125
|
*
|
|
@@ -271,7 +277,7 @@ export interface IIdentityWallet {
|
|
|
271
277
|
* @returns `{Promise<{nonce:number, genesisIdentifier: DID}>}`
|
|
272
278
|
*/
|
|
273
279
|
getGenesisDIDMetadata(did: DID): Promise<{
|
|
274
|
-
nonce: number;
|
|
280
|
+
nonce: number | string;
|
|
275
281
|
genesisDID: DID;
|
|
276
282
|
}>;
|
|
277
283
|
/**
|
|
@@ -388,11 +394,11 @@ export declare class IdentityWallet implements IIdentityWallet {
|
|
|
388
394
|
}>;
|
|
389
395
|
/** {@inheritDoc IIdentityWallet.getGenesisDIDMetadata} */
|
|
390
396
|
getGenesisDIDMetadata(did: DID): Promise<{
|
|
391
|
-
nonce: number;
|
|
397
|
+
nonce: number | string;
|
|
392
398
|
genesisDID: DID;
|
|
393
399
|
}>;
|
|
394
400
|
/** {@inheritDoc IIdentityWallet.createProfile} */
|
|
395
|
-
createProfile(did: DID, nonce: number, verifier: string): Promise<DID>;
|
|
401
|
+
createProfile(did: DID, nonce: number | string, verifier: string): Promise<DID>;
|
|
396
402
|
/**
|
|
397
403
|
*
|
|
398
404
|
* gets profile identity by genesis identifiers
|
|
@@ -69,7 +69,6 @@ export interface IProofService {
|
|
|
69
69
|
*
|
|
70
70
|
* @param {Uint8Array} hash - challenge that will be signed
|
|
71
71
|
* @param {DID} did - identity that will generate a proof
|
|
72
|
-
* @param {Number} profileNonce - identity that will generate a proof
|
|
73
72
|
* @param {CircuitId} circuitId - circuit id for authentication
|
|
74
73
|
* @returns `Promise<Uint8Array>`
|
|
75
74
|
*/
|
|
@@ -7,8 +7,8 @@ import { IIdentityWallet } from '../../identity';
|
|
|
7
7
|
import { IStateStorage } from '../../storage';
|
|
8
8
|
import { ICredentialWallet } from '../../credentials';
|
|
9
9
|
export type DIDProfileMetadata = {
|
|
10
|
-
authProfileNonce: number;
|
|
11
|
-
credentialSubjectProfileNonce: number;
|
|
10
|
+
authProfileNonce: number | string;
|
|
11
|
+
credentialSubjectProfileNonce: number | string;
|
|
12
12
|
};
|
|
13
13
|
export type ProofGenerationOptions = {
|
|
14
14
|
skipRevocation: boolean;
|