Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update profile nonce, so it can be number or string #268

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/iden3comm/types/packer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export type PackerParams = {
export type ZKPPackerParams = PackerParams & {
senderDID: DID;
/** @deprecated */
profileNonce?: number;
profileNonce?: number | string;
provingMethodAlg: ProvingMethodAlg;
};

Expand Down
20 changes: 17 additions & 3 deletions src/identity/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,25 @@ 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));

profileNonce = profileNonce ?? 0;
Kolezhniuk marked this conversation as resolved.
Show resolved Hide resolved

if (!isBigInt(profileNonce)) {
throw new Error('profile must be number or decimal string');
}
const profile = Id.profileId(id, BigInt(profileNonce));
Kolezhniuk marked this conversation as resolved.
Show resolved Hide resolved
return DID.parseFromId(profile);
};

const isBigInt = (x: number | string): boolean => {
try {
return BigInt(x).toString() === x.toString();
} catch {
return false; // conversion to BigInt failed, surely it is not a BigInt
}
};
10 changes: 5 additions & 5 deletions src/identity/identity-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DID>` - profile did
*/
createProfile(did: DID, nonce: number, verifier: string): Promise<DID>;
createProfile(did: DID, nonce: number | string, verifier: string): Promise<DID>;

/**
* Generates a new key
Expand Down Expand Up @@ -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 }>;

/**
*
Expand Down Expand Up @@ -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());

Expand All @@ -802,7 +802,7 @@ export class IdentityWallet implements IIdentityWallet {
}

/** {@inheritDoc IIdentityWallet.createProfile} */
async createProfile(did: DID, nonce: number, verifier: string): Promise<DID> {
async createProfile(did: DID, nonce: number | string, verifier: string): Promise<DID> {
const profileDID = generateProfileDID(did, nonce);

const identityProfiles = await this._storage.identity.getProfilesByGenesisIdentifier(
Expand Down
1 change: 0 additions & 1 deletion src/proof/proof-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uint8Array>`
*/
Expand Down
4 changes: 2 additions & 2 deletions src/proof/provers/inputs-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/storage/entities/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};