fix(rln): update types to match nwaku (#2339)

* chore: update types to match nwaku

* chore: add userMessageLimit // not in spec
This commit is contained in:
Danish Arora 2025-04-10 14:42:57 +05:30 committed by GitHub
parent 4adf8706c3
commit 28f28d0d36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 16 deletions

View File

@ -546,7 +546,7 @@ export class RLNBaseContract {
membership: {
address,
treeIndex: membershipId,
chainId: network.chainId,
chainId: network.chainId.toString(),
rateLimit: decodedData.membershipRateLimit.toNumber()
}
};
@ -640,7 +640,7 @@ export class RLNBaseContract {
membership: {
address,
treeIndex: membershipId,
chainId: network.chainId,
chainId: network.chainId.toString(),
rateLimit: decodedData.membershipRateLimit.toNumber()
}
};

View File

@ -155,7 +155,7 @@ export class RLNCredentialsManager {
LINEA_CONTRACT.address;
if (address === LINEA_CONTRACT.address) {
chainId = LINEA_CONTRACT.chainId;
chainId = LINEA_CONTRACT.chainId.toString();
log.info(`Using Linea contract with chainId: ${chainId}`);
}
@ -163,7 +163,7 @@ export class RLNCredentialsManager {
const currentChainId = await signer.getChainId();
log.info(`Current chain ID: ${currentChainId}`);
if (chainId && chainId !== currentChainId) {
if (chainId && chainId !== currentChainId.toString()) {
log.error(
`Chain ID mismatch: contract=${chainId}, current=${currentChainId}`
);
@ -236,7 +236,7 @@ export class RLNCredentialsManager {
const chainId = credentials.membership.chainId;
const network = await this.contract.provider.getNetwork();
const currentChainId = network.chainId;
if (chainId !== currentChainId) {
if (chainId !== currentChainId.toString()) {
throw Error(
`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`
);

View File

@ -275,7 +275,7 @@ export class Keystore {
treeIndex: _.get(obj, "treeIndex"),
chainId: _.get(obj, "membershipContract.chainId"),
address: _.get(obj, "membershipContract.address"),
rateLimit: _.get(obj, "membershipContract.rateLimit")
rateLimit: _.get(obj, "userMessageLimit")
}
};
} catch (err) {
@ -284,11 +284,18 @@ export class Keystore {
}
}
private static fromArraylikeToBytes(obj: {
[key: number]: number;
}): Uint8Array {
const bytes = [];
private static fromArraylikeToBytes(
obj:
| number[]
| {
[key: number]: number;
}
): Uint8Array {
if (Array.isArray(obj)) {
return new Uint8Array(obj);
}
const bytes = [];
let index = 0;
let lastElement = obj[index];
@ -316,15 +323,16 @@ export class Keystore {
JSON.stringify({
treeIndex: options.membership.treeIndex,
identityCredential: {
idCommitment: options.identity.IDCommitment,
idNullifier: options.identity.IDNullifier,
idSecretHash: options.identity.IDSecretHash,
idTrapdoor: options.identity.IDTrapdoor
idCommitment: Array.from(options.identity.IDCommitment),
idNullifier: Array.from(options.identity.IDNullifier),
idSecretHash: Array.from(options.identity.IDSecretHash),
idTrapdoor: Array.from(options.identity.IDTrapdoor)
},
membershipContract: {
chainId: options.membership.chainId,
address: options.membership.address
}
},
userMessageLimit: options.membership.rateLimit
})
);
}

View File

@ -8,7 +8,7 @@ export type Password = string | Uint8Array;
// see reference
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
export type MembershipInfo = {
chainId: number;
chainId: string;
address: string;
treeIndex: number;
rateLimit: number;