mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
Types update, ZKIdentity serialize and deserialize improvements
Former-commit-id: 5bf94b96f6a662a0e7a2511919b4812151c675d5 [formerly 341607693c]
Former-commit-id: 3c8f4d259930b4b7ea4fd4ea390ca1cc73102a76
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@libsem/identity",
|
||||
"version": "1.0.17",
|
||||
"version": "1.0.18",
|
||||
"description": "Library for managing identites for Semaphore and Rln protocols.",
|
||||
"main": "dist/index.node.js",
|
||||
"types": "dist/types/index.d.ts",
|
||||
@@ -18,7 +18,7 @@
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@libsem/types": "^1.0.5",
|
||||
"@libsem/types": "^1.0.6",
|
||||
"bigint-conversion": "^2.1.12",
|
||||
"circomlibjs": "^0.0.8",
|
||||
"crypto": "^1.0.1",
|
||||
|
||||
@@ -33,23 +33,27 @@ class ZkIdentity {
|
||||
this.identityTrapdoor = identityTrapdoor
|
||||
this.identityNullifier = identityNullifier
|
||||
} else if (strategy === Strategy.SERIALIZED) {
|
||||
const { identityNullifier, identityTrapdoor } = metadata as SerializedIdentity
|
||||
const { identityNullifier, identityTrapdoor, secret } = metadata as SerializedIdentity
|
||||
this.identityNullifier = bigintConversion.hexToBigint(identityNullifier)
|
||||
this.identityTrapdoor = bigintConversion.hexToBigint(identityTrapdoor)
|
||||
this.secret = secret.map(item => bigintConversion.hexToBigint(item));
|
||||
|
||||
} else throw new Error("provided strategy is not supported")
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unserializes identity
|
||||
* Unserialize serialized identity
|
||||
* @param serialisedIdentity
|
||||
* @returns
|
||||
*/
|
||||
static genFromSerialized(serialisedIdentity: string): ZkIdentity {
|
||||
const data = JSON.parse(serialisedIdentity)
|
||||
if (data.length !== 2) throw new Error("Format is wrong")
|
||||
if(!('identityNullifier' in data) || !('identityTrapdoor' in data) || !('secret' in data)) throw new Error("Wrong input identity");
|
||||
return new ZkIdentity(Strategy.SERIALIZED, {
|
||||
identityNullifier: data[0],
|
||||
identityTrapdoor: data[1]
|
||||
identityNullifier: data['identityNullifier'],
|
||||
identityTrapdoor: data['identityTrapdoor'],
|
||||
secret: data['secret']
|
||||
})
|
||||
}
|
||||
/**
|
||||
@@ -111,13 +115,16 @@ class ZkIdentity {
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes identity
|
||||
* @param identity to serialize
|
||||
* @returns serialized identity
|
||||
* Serializes the `identityNullifier`, `identityTrapdoor` and `secret` from the identity
|
||||
* @returns stringified serialized identity
|
||||
*/
|
||||
serializeIdentity(): string {
|
||||
const data = [this.identityNullifier.toString(16), this.identityTrapdoor.toString(16)]
|
||||
return JSON.stringify(data)
|
||||
serializeIdentity(): string {
|
||||
const data: SerializedIdentity = {
|
||||
identityNullifier: this.identityNullifier.toString(16),
|
||||
identityTrapdoor: this.identityTrapdoor.toString(16),
|
||||
secret: this.secret.map(item => item.toString(16))
|
||||
}
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@libsem/types",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"description": "Common type definitions for Semaphore modules.",
|
||||
"main": "src/index.ts",
|
||||
"types": "dist/index.d.ts",
|
||||
|
||||
@@ -22,4 +22,8 @@ export interface MerkleProof {
|
||||
pathElements: Array<any>
|
||||
}
|
||||
|
||||
export type SerializedIdentity = { identityNullifier: string, identityTrapdoor: string };
|
||||
export declare type SerializedIdentity = {
|
||||
identityNullifier: string;
|
||||
identityTrapdoor: string;
|
||||
secret: string[];
|
||||
};
|
||||
Reference in New Issue
Block a user