Skip to content

Commit 1cd9516

Browse files
committed
fix: convert bigint to string when serializing membership
1 parent a88dd8c commit 1cd9516

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

packages/rln/src/keystore/keystore.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,15 @@ export class Keystore {
160160
}
161161

162162
public toString(): string {
163-
return JSON.stringify(this.data);
163+
// Custom replacer function to handle BigInt serialization
164+
const bigIntReplacer = (_key: string, value: unknown): unknown => {
165+
if (typeof value === "bigint") {
166+
return value.toString();
167+
}
168+
return value;
169+
};
170+
171+
return JSON.stringify(this.data, bigIntReplacer);
164172
}
165173

166174
public toObject(): NwakuKeystore {
@@ -327,21 +335,32 @@ export class Keystore {
327335
const { IDCommitment, IDNullifier, IDSecretHash, IDTrapdoor } =
328336
options.identity;
329337

338+
// Custom replacer function to handle BigInt serialization
339+
const bigIntReplacer = (_key: string, value: unknown): unknown => {
340+
if (typeof value === "bigint") {
341+
return value.toString();
342+
}
343+
return value;
344+
};
345+
330346
return utf8ToBytes(
331-
JSON.stringify({
332-
treeIndex: options.membership.treeIndex,
333-
identityCredential: {
334-
idCommitment: Array.from(IDCommitment),
335-
idNullifier: Array.from(IDNullifier),
336-
idSecretHash: Array.from(IDSecretHash),
337-
idTrapdoor: Array.from(IDTrapdoor)
338-
},
339-
membershipContract: {
340-
chainId: options.membership.chainId,
341-
address: options.membership.address
347+
JSON.stringify(
348+
{
349+
treeIndex: options.membership.treeIndex,
350+
identityCredential: {
351+
idCommitment: Array.from(IDCommitment),
352+
idNullifier: Array.from(IDNullifier),
353+
idSecretHash: Array.from(IDSecretHash),
354+
idTrapdoor: Array.from(IDTrapdoor)
355+
},
356+
membershipContract: {
357+
chainId: options.membership.chainId,
358+
address: options.membership.address
359+
},
360+
userMessageLimit: options.membership.rateLimit
342361
},
343-
userMessageLimit: options.membership.rateLimit
344-
})
362+
bigIntReplacer
363+
)
345364
);
346365
}
347366
}

0 commit comments

Comments
 (0)