From e0077391d2899fae8d463545dff1f67053d64d69 Mon Sep 17 00:00:00 2001 From: vmidyllic <74898029+vmidyllic@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:05:42 +0300 Subject: [PATCH 1/5] update profile nonce, so it can be number or string --- src/iden3comm/types/packer.ts | 2 +- src/identity/common.ts | 4 ++-- src/identity/identity-wallet.ts | 10 +++++----- src/proof/proof-service.ts | 1 - src/proof/provers/inputs-generator.ts | 4 ++-- src/storage/entities/identity.ts | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/iden3comm/types/packer.ts b/src/iden3comm/types/packer.ts index ab1dccf7..db4ca2a6 100644 --- a/src/iden3comm/types/packer.ts +++ b/src/iden3comm/types/packer.ts @@ -60,7 +60,7 @@ export type PackerParams = { export type ZKPPackerParams = PackerParams & { senderDID: DID; /** @deprecated */ - profileNonce?: number; + profileNonce?: number | string; provingMethodAlg: ProvingMethodAlg; }; diff --git a/src/identity/common.ts b/src/identity/common.ts index 5992585b..541c6aee 100644 --- a/src/identity/common.ts +++ b/src/identity/common.ts @@ -45,10 +45,10 @@ export const defineMerklizedRootPosition = ( * Returns profile DID based on did and profile nonce * * @param {DID} [did] - did from which profile will be derived - * @param {number} [profileNonce] - profile nonce + * @param {number | string} [profileNonce] - profile nonce * @returns {DID} */ -export const generateProfileDID = (did: DID, profileNonce?: number): DID => { +export const generateProfileDID = (did: DID, profileNonce?: number | string): DID => { const id = DID.idFromDID(did); const profile = Id.profileId(id, BigInt(profileNonce ?? 0)); return DID.parseFromId(profile); diff --git a/src/identity/identity-wallet.ts b/src/identity/identity-wallet.ts index 980cbb57..fd779f3d 100644 --- a/src/identity/identity-wallet.ts +++ b/src/identity/identity-wallet.ts @@ -169,11 +169,11 @@ export interface IIdentityWallet { * Creates profile based on genesis identifier * * @param {DID} did - identity to derive profile from - * @param {number} nonce - unique integer number to generate a profile + * @param {number |string} nonce - unique integer number to generate a profile * @param {string} verifier - verifier identity/alias in a string from * @returns `Promise` - profile did */ - createProfile(did: DID, nonce: number, verifier: string): Promise; + createProfile(did: DID, nonce: number | string, verifier: string): Promise; /** * Generates a new key @@ -387,7 +387,7 @@ export interface IIdentityWallet { * @param {DID} did - profile that has been derived or genesis identity * @returns `{Promise<{nonce:number, genesisIdentifier: DID}>}` */ - getGenesisDIDMetadata(did: DID): Promise<{ nonce: number; genesisDID: DID }>; + getGenesisDIDMetadata(did: DID): Promise<{ nonce: number | string; genesisDID: DID }>; /** * @@ -786,7 +786,7 @@ export class IdentityWallet implements IIdentityWallet { } /** {@inheritDoc IIdentityWallet.getGenesisDIDMetadata} */ - async getGenesisDIDMetadata(did: DID): Promise<{ nonce: number; genesisDID: DID }> { + async getGenesisDIDMetadata(did: DID): Promise<{ nonce: number | string; genesisDID: DID }> { // check if it is a genesis identity const identity = await this._storage.identity.getIdentity(did.string()); @@ -802,7 +802,7 @@ export class IdentityWallet implements IIdentityWallet { } /** {@inheritDoc IIdentityWallet.createProfile} */ - async createProfile(did: DID, nonce: number, verifier: string): Promise { + async createProfile(did: DID, nonce: number | string, verifier: string): Promise { const profileDID = generateProfileDID(did, nonce); const identityProfiles = await this._storage.identity.getProfilesByGenesisIdentifier( diff --git a/src/proof/proof-service.ts b/src/proof/proof-service.ts index 91ec1719..02719bd1 100644 --- a/src/proof/proof-service.ts +++ b/src/proof/proof-service.ts @@ -126,7 +126,6 @@ export interface IProofService { * * @param {Uint8Array} hash - challenge that will be signed * @param {DID} did - identity that will generate a proof - * @param {Number} profileNonce - identity that will generate a proof * @param {CircuitId} circuitId - circuit id for authentication * @returns `Promise` */ diff --git a/src/proof/provers/inputs-generator.ts b/src/proof/provers/inputs-generator.ts index 37bbf9f3..20cd7874 100644 --- a/src/proof/provers/inputs-generator.ts +++ b/src/proof/provers/inputs-generator.ts @@ -40,8 +40,8 @@ import { import { isEthereumIdentity } from '../../utils'; export type DIDProfileMetadata = { - authProfileNonce: number; - credentialSubjectProfileNonce: number; + authProfileNonce: number | string; + credentialSubjectProfileNonce: number | string; }; export type ProofGenerationOptions = { diff --git a/src/storage/entities/identity.ts b/src/storage/entities/identity.ts index 2b9f3505..1412a814 100644 --- a/src/storage/entities/identity.ts +++ b/src/storage/entities/identity.ts @@ -11,7 +11,7 @@ export type Identity = { /** Profile structure that can be used for profiles storage */ export type Profile = { id: string; - nonce: number; + nonce: number | string; genesisIdentifier: string; verifier: string; }; From 67a4be27511f6fbed740bbbf55467cbc85a2d769 Mon Sep 17 00:00:00 2001 From: vmidyllic <74898029+vmidyllic@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:05:52 +0300 Subject: [PATCH 2/5] 1.19.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a24fccbe..f6f18f7f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.18.4", + "version": "1.19.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@0xpolygonid/js-sdk", - "version": "1.18.4", + "version": "1.19.0", "license": "MIT or Apache-2.0", "dependencies": { "@noble/curves": "^1.4.0", diff --git a/package.json b/package.json index c55a9976..da23f5c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.18.4", + "version": "1.19.0", "description": "SDK to work with Polygon ID", "main": "dist/node/cjs/index.js", "module": "dist/node/esm/index.js", From d15f79a37f82e120fb5ad097ed7a3451846fe45b Mon Sep 17 00:00:00 2001 From: vmidyllic <74898029+vmidyllic@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:24:13 +0300 Subject: [PATCH 3/5] add validation check --- src/identity/common.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/identity/common.ts b/src/identity/common.ts index 541c6aee..cbb398d0 100644 --- a/src/identity/common.ts +++ b/src/identity/common.ts @@ -50,6 +50,20 @@ export const defineMerklizedRootPosition = ( */ export const generateProfileDID = (did: DID, profileNonce?: number | string): DID => { const id = DID.idFromDID(did); - const profile = Id.profileId(id, BigInt(profileNonce ?? 0)); + + profileNonce = profileNonce ?? 0; + + if (!isBigInt(profileNonce)) { + throw new Error('profile must be number or decimal string'); + } + const profile = Id.profileId(id, BigInt(profileNonce)); return DID.parseFromId(profile); }; + +const isBigInt = (x: number | string): boolean => { + try { + return BigInt(x).toString() === x.toString(); + } catch (error) { + return false; // conversion to BigInt failed, surely it is not a BigInt + } +}; From bd6fbf6829b4e695339d386554ade9f2b33fdbef Mon Sep 17 00:00:00 2001 From: vmidyllic <74898029+vmidyllic@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:57:42 +0300 Subject: [PATCH 4/5] fix ignored catch --- src/identity/common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/identity/common.ts b/src/identity/common.ts index cbb398d0..550f33f3 100644 --- a/src/identity/common.ts +++ b/src/identity/common.ts @@ -63,7 +63,7 @@ export const generateProfileDID = (did: DID, profileNonce?: number | string): DI const isBigInt = (x: number | string): boolean => { try { return BigInt(x).toString() === x.toString(); - } catch (error) { + } catch { return false; // conversion to BigInt failed, surely it is not a BigInt } }; From 61492244a5946ba4214a69ca2b0b62cb7cba5994 Mon Sep 17 00:00:00 2001 From: vmidyllic <74898029+vmidyllic@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:57:53 +0300 Subject: [PATCH 5/5] fix --- src/identity/common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/identity/common.ts b/src/identity/common.ts index 550f33f3..f47ac2f7 100644 --- a/src/identity/common.ts +++ b/src/identity/common.ts @@ -63,7 +63,7 @@ export const generateProfileDID = (did: DID, profileNonce?: number | string): DI const isBigInt = (x: number | string): boolean => { try { return BigInt(x).toString() === x.toString(); - } catch { + } catch { return false; // conversion to BigInt failed, surely it is not a BigInt } };