@0xpolygonid/js-sdk 1.18.4 → 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.
@@ -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
- const profile = js_iden3_core_1.Id.profileId(id, BigInt(profileNonce ?? 0));
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
+ };
@@ -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
- const profile = Id.profileId(id, BigInt(profileNonce ?? 0));
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
+ };
@@ -50,7 +50,7 @@ export type PackerParams = {
50
50
  export type ZKPPackerParams = PackerParams & {
51
51
  senderDID: DID;
52
52
  /** @deprecated */
53
- profileNonce?: number;
53
+ profileNonce?: number | string;
54
54
  provingMethodAlg: ProvingMethodAlg;
55
55
  };
56
56
  /**
@@ -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;
@@ -115,11 +115,11 @@ export interface IIdentityWallet {
115
115
  * Creates profile based on genesis identifier
116
116
  *
117
117
  * @param {DID} did - identity to derive profile from
118
- * @param {number} nonce - unique integer number to generate a profile
118
+ * @param {number |string} nonce - unique integer number to generate a profile
119
119
  * @param {string} verifier - verifier identity/alias in a string from
120
120
  * @returns `Promise<DID>` - profile did
121
121
  */
122
- createProfile(did: DID, nonce: number, verifier: string): Promise<DID>;
122
+ createProfile(did: DID, nonce: number | string, verifier: string): Promise<DID>;
123
123
  /**
124
124
  * Generates a new key
125
125
  *
@@ -277,7 +277,7 @@ export interface IIdentityWallet {
277
277
  * @returns `{Promise<{nonce:number, genesisIdentifier: DID}>}`
278
278
  */
279
279
  getGenesisDIDMetadata(did: DID): Promise<{
280
- nonce: number;
280
+ nonce: number | string;
281
281
  genesisDID: DID;
282
282
  }>;
283
283
  /**
@@ -394,11 +394,11 @@ export declare class IdentityWallet implements IIdentityWallet {
394
394
  }>;
395
395
  /** {@inheritDoc IIdentityWallet.getGenesisDIDMetadata} */
396
396
  getGenesisDIDMetadata(did: DID): Promise<{
397
- nonce: number;
397
+ nonce: number | string;
398
398
  genesisDID: DID;
399
399
  }>;
400
400
  /** {@inheritDoc IIdentityWallet.createProfile} */
401
- createProfile(did: DID, nonce: number, verifier: string): Promise<DID>;
401
+ createProfile(did: DID, nonce: number | string, verifier: string): Promise<DID>;
402
402
  /**
403
403
  *
404
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;
@@ -9,7 +9,7 @@ export type Identity = {
9
9
  /** Profile structure that can be used for profiles storage */
10
10
  export type Profile = {
11
11
  id: string;
12
- nonce: number;
12
+ nonce: number | string;
13
13
  genesisIdentifier: string;
14
14
  verifier: string;
15
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xpolygonid/js-sdk",
3
- "version": "1.18.4",
3
+ "version": "1.19.0",
4
4
  "description": "SDK to work with Polygon ID",
5
5
  "main": "dist/node/cjs/index.js",
6
6
  "module": "dist/node/esm/index.js",