fix: convert bigint to string when serializing membership

This commit is contained in:
Arseniy Klempner 2025-10-27 13:45:59 -07:00
parent 66ba9f0af0
commit a1c8f6e907
No known key found for this signature in database
GPG Key ID: 51653F18863BD24B

View File

@ -160,7 +160,15 @@ export class Keystore {
}
public toString(): string {
return JSON.stringify(this.data);
// Custom replacer function to handle BigInt serialization
const bigIntReplacer = (_key: string, value: unknown): unknown => {
if (typeof value === "bigint") {
return value.toString();
}
return value;
};
return JSON.stringify(this.data, bigIntReplacer);
}
public toObject(): NwakuKeystore {
@ -327,21 +335,32 @@ export class Keystore {
const { IDCommitment, IDNullifier, IDSecretHash, IDTrapdoor } =
options.identity;
// Custom replacer function to handle BigInt serialization
const bigIntReplacer = (_key: string, value: unknown): unknown => {
if (typeof value === "bigint") {
return value.toString();
}
return value;
};
return utf8ToBytes(
JSON.stringify({
treeIndex: options.membership.treeIndex,
identityCredential: {
idCommitment: Array.from(IDCommitment),
idNullifier: Array.from(IDNullifier),
idSecretHash: Array.from(IDSecretHash),
idTrapdoor: Array.from(IDTrapdoor)
JSON.stringify(
{
treeIndex: options.membership.treeIndex,
identityCredential: {
idCommitment: Array.from(IDCommitment),
idNullifier: Array.from(IDNullifier),
idSecretHash: Array.from(IDSecretHash),
idTrapdoor: Array.from(IDTrapdoor)
},
membershipContract: {
chainId: options.membership.chainId,
address: options.membership.address
},
userMessageLimit: options.membership.rateLimit
},
membershipContract: {
chainId: options.membership.chainId,
address: options.membership.address
},
userMessageLimit: options.membership.rateLimit
})
bigIntReplacer
)
);
}
}