@waku/rln 0.1.5-ea6daae.0 → 0.1.5-f39d215.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/bundle/_virtual/index2.js +1 -1
- package/bundle/index.js +3 -1
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +1 -1
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +1 -1
- package/bundle/node_modules/{js-sha3 → @ethersproject/keccak256/node_modules/js-sha3}/src/sha3.js +2 -2
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +1 -19
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +10 -58
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +1 -1
- package/bundle/packages/rln/dist/contract/abi.js +502 -248
- package/bundle/packages/rln/dist/contract/constants.js +4 -4
- package/bundle/packages/rln/dist/contract/rln_contract.js +124 -40
- package/bundle/packages/rln/dist/contract/rln_light_contract.js +477 -0
- package/bundle/packages/rln/dist/identity.js +9 -0
- package/bundle/packages/rln/dist/keystore/cipher.js +3 -3
- package/bundle/packages/rln/dist/keystore/keystore.js +16 -25
- package/bundle/packages/rln/dist/rln.js +8 -8
- package/bundle/packages/rln/dist/rln_light.js +149 -0
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/checksum.js +3 -3
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/cipher.js +4 -4
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/class.js +7 -7
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/functional.js +7 -7
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/index.js +6 -6
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/kdf.js +5 -5
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/password.js +1 -1
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1 -1
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/schema-validation.js +2 -2
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/types.js +1 -1
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +3 -3
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +7 -7
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +3 -3
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +3 -3
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +3 -3
- package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +7 -7
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_assert.js +1 -1
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_sha2.js +3 -3
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_u64.js +1 -1
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/cryptoBrowser.js +1 -1
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +43 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +116 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/hmac.js +79 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/sha256.js +126 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +43 -0
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/hmac.js +3 -3
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/pbkdf2.js +4 -4
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/scrypt.js +5 -5
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/sha256.js +3 -3
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/sha512.js +4 -4
- package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/utils.js +2 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/codec.test-utils.d.ts +36 -0
- package/dist/codec.test-utils.js +56 -0
- package/dist/codec.test-utils.js.map +1 -0
- package/dist/contract/abi.d.ts +21 -17
- package/dist/contract/abi.js +502 -248
- package/dist/contract/abi.js.map +1 -1
- package/dist/contract/constants.d.ts +23 -19
- package/dist/contract/constants.js +3 -3
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +10 -3
- package/dist/contract/rln_contract.js +124 -40
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/contract/rln_light_contract.d.ts +124 -0
- package/dist/contract/rln_light_contract.js +460 -0
- package/dist/contract/rln_light_contract.js.map +1 -0
- package/dist/contract/test-setup.d.ts +26 -0
- package/dist/contract/test-setup.js +56 -0
- package/dist/contract/test-setup.js.map +1 -0
- package/dist/contract/test-utils.d.ts +39 -0
- package/dist/contract/test-utils.js +118 -0
- package/dist/contract/test-utils.js.map +1 -0
- package/dist/identity.d.ts +1 -0
- package/dist/identity.js +9 -0
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.d.ts +0 -1
- package/dist/keystore/keystore.js +15 -24
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/types.d.ts +2 -1
- package/dist/rln.d.ts +1 -1
- package/dist/rln.js +8 -8
- package/dist/rln.js.map +1 -1
- package/dist/rln_light.d.ts +64 -0
- package/dist/rln_light.js +144 -0
- package/dist/rln_light.js.map +1 -0
- package/package.json +1 -1
- package/src/codec.test-utils.ts +80 -0
- package/src/contract/abi.ts +502 -248
- package/src/contract/constants.ts +3 -3
- package/src/contract/rln_contract.ts +162 -50
- package/src/contract/rln_light_contract.ts +725 -0
- package/src/contract/test-setup.ts +86 -0
- package/src/contract/test-utils.ts +179 -0
- package/src/identity.ts +10 -0
- package/src/index.ts +17 -2
- package/src/keystore/keystore.ts +27 -42
- package/src/keystore/types.ts +2 -1
- package/src/rln.ts +9 -9
- package/src/rln_light.ts +235 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +0 -0
- /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +0 -0
@@ -0,0 +1,86 @@
|
|
1
|
+
import { hexToBytes } from "@waku/utils/bytes";
|
2
|
+
import { ethers } from "ethers";
|
3
|
+
import sinon from "sinon";
|
4
|
+
|
5
|
+
import { createRLN } from "../create.js";
|
6
|
+
import type { IdentityCredential } from "../identity.js";
|
7
|
+
|
8
|
+
import { DEFAULT_RATE_LIMIT, LINEA_CONTRACT } from "./constants.js";
|
9
|
+
import { RLNContract } from "./rln_contract.js";
|
10
|
+
|
11
|
+
export interface TestRLNInstance {
|
12
|
+
rlnInstance: any;
|
13
|
+
identity: IdentityCredential;
|
14
|
+
insertMemberSpy: sinon.SinonStub;
|
15
|
+
}
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Creates a test RLN instance with basic setup
|
19
|
+
*/
|
20
|
+
export async function createTestRLNInstance(): Promise<TestRLNInstance> {
|
21
|
+
const rlnInstance = await createRLN();
|
22
|
+
const insertMemberSpy = sinon.stub();
|
23
|
+
rlnInstance.zerokit.insertMember = insertMemberSpy;
|
24
|
+
|
25
|
+
const mockSignature =
|
26
|
+
"0xdeb8a6b00a8e404deb1f52d3aa72ed7f60a2ff4484c737eedaef18a0aacb2dfb4d5d74ac39bb71fa358cf2eb390565a35b026cc6272f2010d4351e17670311c21c";
|
27
|
+
const identity =
|
28
|
+
rlnInstance.zerokit.generateSeededIdentityCredential(mockSignature);
|
29
|
+
|
30
|
+
return {
|
31
|
+
rlnInstance,
|
32
|
+
identity,
|
33
|
+
insertMemberSpy
|
34
|
+
};
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Initializes an RLN contract with the given registry contract
|
39
|
+
*/
|
40
|
+
export async function initializeRLNContract(
|
41
|
+
rlnInstance: any,
|
42
|
+
mockedRegistryContract: ethers.Contract
|
43
|
+
): Promise<RLNContract> {
|
44
|
+
const provider = new ethers.providers.JsonRpcProvider();
|
45
|
+
const voidSigner = new ethers.VoidSigner(LINEA_CONTRACT.address, provider);
|
46
|
+
|
47
|
+
const originalRegister = mockedRegistryContract.register;
|
48
|
+
(mockedRegistryContract as any).register = function (...args: any[]) {
|
49
|
+
const result = originalRegister.apply(this, args);
|
50
|
+
|
51
|
+
if (args[0] && rlnInstance.zerokit) {
|
52
|
+
const idCommitmentBigInt = args[0];
|
53
|
+
const idCommitmentHex =
|
54
|
+
"0x" + idCommitmentBigInt.toString(16).padStart(64, "0");
|
55
|
+
const idCommitment = ethers.utils.zeroPad(
|
56
|
+
hexToBytes(idCommitmentHex),
|
57
|
+
32
|
58
|
+
);
|
59
|
+
rlnInstance.zerokit.insertMember(idCommitment);
|
60
|
+
}
|
61
|
+
|
62
|
+
return result;
|
63
|
+
};
|
64
|
+
|
65
|
+
const contract = await RLNContract.init(rlnInstance, {
|
66
|
+
address: LINEA_CONTRACT.address,
|
67
|
+
signer: voidSigner,
|
68
|
+
rateLimit: DEFAULT_RATE_LIMIT,
|
69
|
+
contract: mockedRegistryContract
|
70
|
+
});
|
71
|
+
|
72
|
+
return contract;
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Common test message data
|
77
|
+
*/
|
78
|
+
export const TEST_DATA = {
|
79
|
+
contentTopic: "/test/1/waku-message/utf8",
|
80
|
+
emptyPubsubTopic: "",
|
81
|
+
testMessage: Uint8Array.from(
|
82
|
+
"Hello World".split("").map((x) => x.charCodeAt(0))
|
83
|
+
),
|
84
|
+
mockSignature:
|
85
|
+
"0xdeb8a6b00a8e404deb1f52d3aa72ed7f60a2ff4484c737eedaef18a0aacb2dfb4d5d74ac39bb71fa358cf2eb390565a35b026cc6272f2010d4351e17670311c21c"
|
86
|
+
} as const;
|
@@ -0,0 +1,179 @@
|
|
1
|
+
import { hexToBytes } from "@waku/utils/bytes";
|
2
|
+
import { expect } from "chai";
|
3
|
+
import * as ethers from "ethers";
|
4
|
+
import sinon from "sinon";
|
5
|
+
|
6
|
+
import type { IdentityCredential } from "../identity.js";
|
7
|
+
|
8
|
+
import { DEFAULT_RATE_LIMIT, LINEA_CONTRACT } from "./constants.js";
|
9
|
+
|
10
|
+
export const mockRateLimits = {
|
11
|
+
minRate: 20,
|
12
|
+
maxRate: 600,
|
13
|
+
maxTotalRate: 1200,
|
14
|
+
currentTotalRate: 500
|
15
|
+
};
|
16
|
+
|
17
|
+
type MockProvider = {
|
18
|
+
getLogs: () => never[];
|
19
|
+
getBlockNumber: () => Promise<number>;
|
20
|
+
getNetwork: () => Promise<{ chainId: number }>;
|
21
|
+
};
|
22
|
+
|
23
|
+
type MockFilters = {
|
24
|
+
MembershipRegistered: () => { address: string };
|
25
|
+
MembershipErased: () => { address: string };
|
26
|
+
MembershipExpired: () => { address: string };
|
27
|
+
};
|
28
|
+
|
29
|
+
export function createMockProvider(): MockProvider {
|
30
|
+
return {
|
31
|
+
getLogs: () => [],
|
32
|
+
getBlockNumber: () => Promise.resolve(1000),
|
33
|
+
getNetwork: () => Promise.resolve({ chainId: 11155111 })
|
34
|
+
};
|
35
|
+
}
|
36
|
+
|
37
|
+
export function createMockFilters(): MockFilters {
|
38
|
+
return {
|
39
|
+
MembershipRegistered: () => ({ address: LINEA_CONTRACT.address }),
|
40
|
+
MembershipErased: () => ({ address: LINEA_CONTRACT.address }),
|
41
|
+
MembershipExpired: () => ({ address: LINEA_CONTRACT.address })
|
42
|
+
};
|
43
|
+
}
|
44
|
+
|
45
|
+
type ContractOverrides = Partial<{
|
46
|
+
filters: Record<string, unknown>;
|
47
|
+
[key: string]: unknown;
|
48
|
+
}>;
|
49
|
+
|
50
|
+
export function createMockRegistryContract(
|
51
|
+
overrides: ContractOverrides = {}
|
52
|
+
): ethers.Contract {
|
53
|
+
const filters = {
|
54
|
+
MembershipRegistered: () => ({ address: LINEA_CONTRACT.address }),
|
55
|
+
MembershipErased: () => ({ address: LINEA_CONTRACT.address }),
|
56
|
+
MembershipExpired: () => ({ address: LINEA_CONTRACT.address })
|
57
|
+
};
|
58
|
+
|
59
|
+
const baseContract = {
|
60
|
+
minMembershipRateLimit: () =>
|
61
|
+
Promise.resolve(ethers.BigNumber.from(mockRateLimits.minRate)),
|
62
|
+
maxMembershipRateLimit: () =>
|
63
|
+
Promise.resolve(ethers.BigNumber.from(mockRateLimits.maxRate)),
|
64
|
+
maxTotalRateLimit: () =>
|
65
|
+
Promise.resolve(ethers.BigNumber.from(mockRateLimits.maxTotalRate)),
|
66
|
+
currentTotalRateLimit: () =>
|
67
|
+
Promise.resolve(ethers.BigNumber.from(mockRateLimits.currentTotalRate)),
|
68
|
+
queryFilter: () => [],
|
69
|
+
provider: createMockProvider(),
|
70
|
+
filters,
|
71
|
+
on: () => ({}),
|
72
|
+
removeAllListeners: () => ({}),
|
73
|
+
register: () => ({
|
74
|
+
wait: () =>
|
75
|
+
Promise.resolve({
|
76
|
+
events: [mockRLNRegisteredEvent()]
|
77
|
+
})
|
78
|
+
}),
|
79
|
+
estimateGas: {
|
80
|
+
register: () => Promise.resolve(ethers.BigNumber.from(100000))
|
81
|
+
},
|
82
|
+
functions: {
|
83
|
+
register: () => Promise.resolve()
|
84
|
+
},
|
85
|
+
getMemberIndex: () => Promise.resolve(null),
|
86
|
+
interface: {
|
87
|
+
getEvent: (eventName: string) => ({
|
88
|
+
name: eventName,
|
89
|
+
format: () => {}
|
90
|
+
})
|
91
|
+
},
|
92
|
+
address: LINEA_CONTRACT.address
|
93
|
+
};
|
94
|
+
|
95
|
+
// Merge overrides while preserving filters
|
96
|
+
const merged = {
|
97
|
+
...baseContract,
|
98
|
+
...overrides,
|
99
|
+
filters: { ...filters, ...(overrides.filters || {}) }
|
100
|
+
};
|
101
|
+
|
102
|
+
return merged as unknown as ethers.Contract;
|
103
|
+
}
|
104
|
+
|
105
|
+
export function mockRLNRegisteredEvent(idCommitment?: string): ethers.Event {
|
106
|
+
return {
|
107
|
+
args: {
|
108
|
+
idCommitment:
|
109
|
+
idCommitment ||
|
110
|
+
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
|
111
|
+
membershipRateLimit: ethers.BigNumber.from(DEFAULT_RATE_LIMIT),
|
112
|
+
index: ethers.BigNumber.from(1)
|
113
|
+
},
|
114
|
+
event: "MembershipRegistered"
|
115
|
+
} as unknown as ethers.Event;
|
116
|
+
}
|
117
|
+
|
118
|
+
export function formatIdCommitment(idCommitmentBigInt: bigint): string {
|
119
|
+
return "0x" + idCommitmentBigInt.toString(16).padStart(64, "0");
|
120
|
+
}
|
121
|
+
|
122
|
+
export function createRegisterStub(
|
123
|
+
identity: IdentityCredential
|
124
|
+
): sinon.SinonStub {
|
125
|
+
return sinon.stub().callsFake(() => ({
|
126
|
+
wait: () =>
|
127
|
+
Promise.resolve({
|
128
|
+
events: [
|
129
|
+
{
|
130
|
+
event: "MembershipRegistered",
|
131
|
+
args: {
|
132
|
+
idCommitment: formatIdCommitment(identity.IDCommitmentBigInt),
|
133
|
+
membershipRateLimit: ethers.BigNumber.from(DEFAULT_RATE_LIMIT),
|
134
|
+
index: ethers.BigNumber.from(1)
|
135
|
+
}
|
136
|
+
}
|
137
|
+
]
|
138
|
+
})
|
139
|
+
}));
|
140
|
+
}
|
141
|
+
|
142
|
+
export function verifyRegistration(
|
143
|
+
decryptedCredentials: any,
|
144
|
+
identity: IdentityCredential,
|
145
|
+
registerStub: sinon.SinonStub,
|
146
|
+
insertMemberSpy: sinon.SinonStub
|
147
|
+
): void {
|
148
|
+
if (!decryptedCredentials) {
|
149
|
+
throw new Error("Decrypted credentials should not be undefined");
|
150
|
+
}
|
151
|
+
|
152
|
+
// Verify registration call
|
153
|
+
expect(
|
154
|
+
registerStub.calledWith(
|
155
|
+
sinon.match.same(identity.IDCommitmentBigInt),
|
156
|
+
sinon.match.same(DEFAULT_RATE_LIMIT),
|
157
|
+
sinon.match.array,
|
158
|
+
sinon.match.object
|
159
|
+
)
|
160
|
+
).to.be.true;
|
161
|
+
|
162
|
+
// Verify credential properties
|
163
|
+
expect(decryptedCredentials).to.have.property("identity");
|
164
|
+
expect(decryptedCredentials).to.have.property("membership");
|
165
|
+
expect(decryptedCredentials.membership).to.include({
|
166
|
+
address: LINEA_CONTRACT.address,
|
167
|
+
treeIndex: 1
|
168
|
+
});
|
169
|
+
|
170
|
+
// Verify member insertion
|
171
|
+
const expectedIdCommitment = ethers.utils.zeroPad(
|
172
|
+
hexToBytes(formatIdCommitment(identity.IDCommitmentBigInt)),
|
173
|
+
32
|
174
|
+
);
|
175
|
+
expect(insertMemberSpy.callCount).to.equal(1);
|
176
|
+
expect(insertMemberSpy.getCall(0).args[0]).to.deep.equal(
|
177
|
+
expectedIdCommitment
|
178
|
+
);
|
179
|
+
}
|
package/src/identity.ts
CHANGED
@@ -28,4 +28,14 @@ export class IdentityCredential {
|
|
28
28
|
idCommitmentBigInt
|
29
29
|
);
|
30
30
|
}
|
31
|
+
|
32
|
+
public toJSON(): Record<string, number[] | string> {
|
33
|
+
return {
|
34
|
+
idTrapdoor: Array.from(this.IDTrapdoor),
|
35
|
+
idNullifier: Array.from(this.IDNullifier),
|
36
|
+
idSecretHash: Array.from(this.IDSecretHash),
|
37
|
+
idCommitment: Array.from(this.IDCommitment),
|
38
|
+
idCommitmentBigInt: this.IDCommitmentBigInt.toString()
|
39
|
+
};
|
40
|
+
}
|
31
41
|
}
|
package/src/index.ts
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
2
2
|
import { RLN_ABI } from "./contract/abi.js";
|
3
|
-
import {
|
3
|
+
import { LINEA_CONTRACT, RLNContract } from "./contract/index.js";
|
4
|
+
import { RLNLightContract } from "./contract/rln_light_contract.js";
|
4
5
|
import { createRLN } from "./create.js";
|
5
6
|
import { IdentityCredential } from "./identity.js";
|
6
7
|
import { Keystore } from "./keystore/index.js";
|
7
8
|
import { Proof } from "./proof.js";
|
8
9
|
import { RLNInstance } from "./rln.js";
|
10
|
+
import { RLNLightInstance } from "./rln_light.js";
|
9
11
|
import { MerkleRootTracker } from "./root_tracker.js";
|
10
12
|
import { extractMetaMaskSigner } from "./utils/index.js";
|
11
13
|
|
12
14
|
export {
|
15
|
+
RLNLightInstance,
|
16
|
+
RLNLightContract,
|
13
17
|
createRLN,
|
14
18
|
Keystore,
|
15
19
|
RLNInstance,
|
@@ -19,7 +23,18 @@ export {
|
|
19
23
|
RLNDecoder,
|
20
24
|
MerkleRootTracker,
|
21
25
|
RLNContract,
|
22
|
-
|
26
|
+
LINEA_CONTRACT,
|
23
27
|
extractMetaMaskSigner,
|
24
28
|
RLN_ABI
|
25
29
|
};
|
30
|
+
|
31
|
+
export type {
|
32
|
+
DecryptedCredentials,
|
33
|
+
EncryptedCredentials,
|
34
|
+
Keccak256Hash,
|
35
|
+
KeystoreEntity,
|
36
|
+
MembershipHash,
|
37
|
+
MembershipInfo,
|
38
|
+
Password,
|
39
|
+
Sha256Hash
|
40
|
+
} from "./keystore/types.js";
|
package/src/keystore/keystore.ts
CHANGED
@@ -14,6 +14,7 @@ import {
|
|
14
14
|
import _ from "lodash";
|
15
15
|
import { v4 as uuidV4 } from "uuid";
|
16
16
|
|
17
|
+
import { IdentityCredential } from "../identity.js";
|
17
18
|
import { buildBigIntFromUint8Array } from "../utils/bytes.js";
|
18
19
|
|
19
20
|
import { decryptEipKeystore, keccak256Checksum } from "./cipher.js";
|
@@ -250,31 +251,32 @@ export class Keystore {
|
|
250
251
|
const str = bytesToUtf8(bytes);
|
251
252
|
const obj = JSON.parse(str);
|
252
253
|
|
253
|
-
//
|
254
|
+
// Get identity fields from named object
|
255
|
+
const { idTrapdoor, idNullifier, idSecretHash, idCommitment } = _.get(
|
256
|
+
obj,
|
257
|
+
"identityCredential",
|
258
|
+
{}
|
259
|
+
);
|
260
|
+
|
261
|
+
const idTrapdoorArray = new Uint8Array(idTrapdoor || []);
|
262
|
+
const idNullifierArray = new Uint8Array(idNullifier || []);
|
263
|
+
const idSecretHashArray = new Uint8Array(idSecretHash || []);
|
264
|
+
const idCommitmentArray = new Uint8Array(idCommitment || []);
|
265
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitmentArray);
|
266
|
+
|
254
267
|
return {
|
255
|
-
identity:
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
IDNullifier: Keystore.fromArraylikeToBytes(
|
263
|
-
_.get(obj, "identityCredential.idNullifier", [])
|
264
|
-
),
|
265
|
-
IDCommitmentBigInt: buildBigIntFromUint8Array(
|
266
|
-
Keystore.fromArraylikeToBytes(
|
267
|
-
_.get(obj, "identityCredential.idCommitment", [])
|
268
|
-
)
|
269
|
-
),
|
270
|
-
IDSecretHash: Keystore.fromArraylikeToBytes(
|
271
|
-
_.get(obj, "identityCredential.idSecretHash", [])
|
272
|
-
)
|
273
|
-
},
|
268
|
+
identity: new IdentityCredential(
|
269
|
+
idTrapdoorArray,
|
270
|
+
idNullifierArray,
|
271
|
+
idSecretHashArray,
|
272
|
+
idCommitmentArray,
|
273
|
+
idCommitmentBigInt
|
274
|
+
),
|
274
275
|
membership: {
|
275
276
|
treeIndex: _.get(obj, "treeIndex"),
|
276
277
|
chainId: _.get(obj, "membershipContract.chainId"),
|
277
|
-
address: _.get(obj, "membershipContract.address")
|
278
|
+
address: _.get(obj, "membershipContract.address"),
|
279
|
+
rateLimit: _.get(obj, "membershipContract.rateLimit")
|
278
280
|
}
|
279
281
|
};
|
280
282
|
} catch (err) {
|
@@ -283,23 +285,6 @@ export class Keystore {
|
|
283
285
|
}
|
284
286
|
}
|
285
287
|
|
286
|
-
private static fromArraylikeToBytes(obj: {
|
287
|
-
[key: number]: number;
|
288
|
-
}): Uint8Array {
|
289
|
-
const bytes = [];
|
290
|
-
|
291
|
-
let index = 0;
|
292
|
-
let lastElement = obj[index];
|
293
|
-
|
294
|
-
while (lastElement !== undefined) {
|
295
|
-
bytes.push(lastElement);
|
296
|
-
index += 1;
|
297
|
-
lastElement = obj[index];
|
298
|
-
}
|
299
|
-
|
300
|
-
return new Uint8Array(bytes);
|
301
|
-
}
|
302
|
-
|
303
288
|
// follows nwaku implementation
|
304
289
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
|
305
290
|
private static computeMembershipHash(info: MembershipInfo): MembershipHash {
|
@@ -315,10 +300,10 @@ export class Keystore {
|
|
315
300
|
JSON.stringify({
|
316
301
|
treeIndex: options.membership.treeIndex,
|
317
302
|
identityCredential: {
|
318
|
-
|
319
|
-
idNullifier: options.identity.IDNullifier,
|
320
|
-
idSecretHash: options.identity.IDSecretHash,
|
321
|
-
|
303
|
+
idTrapdoor: Array.from(options.identity.IDTrapdoor),
|
304
|
+
idNullifier: Array.from(options.identity.IDNullifier),
|
305
|
+
idSecretHash: Array.from(options.identity.IDSecretHash),
|
306
|
+
idCommitment: Array.from(options.identity.IDCommitment)
|
322
307
|
},
|
323
308
|
membershipContract: {
|
324
309
|
chainId: options.membership.chainId,
|
package/src/keystore/types.ts
CHANGED
@@ -8,9 +8,10 @@ export type Password = string | Uint8Array;
|
|
8
8
|
// see reference
|
9
9
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
|
10
10
|
export type MembershipInfo = {
|
11
|
-
chainId:
|
11
|
+
chainId: string;
|
12
12
|
address: string;
|
13
13
|
treeIndex: number;
|
14
|
+
rateLimit: number;
|
14
15
|
};
|
15
16
|
|
16
17
|
export type KeystoreEntity = {
|
package/src/rln.ts
CHANGED
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
type RLNEncoder
|
17
17
|
} from "./codec.js";
|
18
18
|
import { DEFAULT_RATE_LIMIT } from "./contract/constants.js";
|
19
|
-
import {
|
19
|
+
import { LINEA_CONTRACT, RLNContract } from "./contract/index.js";
|
20
20
|
import { IdentityCredential } from "./identity.js";
|
21
21
|
import { Keystore } from "./keystore/index.js";
|
22
22
|
import type {
|
@@ -108,7 +108,7 @@ type StartRLNOptions = {
|
|
108
108
|
*/
|
109
109
|
signer?: ethers.Signer;
|
110
110
|
/**
|
111
|
-
* If not set - will use default
|
111
|
+
* If not set - will use default LINEA_CONTRACT address.
|
112
112
|
*/
|
113
113
|
address?: string;
|
114
114
|
/**
|
@@ -160,7 +160,7 @@ export class RLNInstance {
|
|
160
160
|
try {
|
161
161
|
const { credentials, keystore } =
|
162
162
|
await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
163
|
-
const { signer, address } = await this.determineStartOptions(
|
163
|
+
const { signer, address, rateLimit } = await this.determineStartOptions(
|
164
164
|
options,
|
165
165
|
credentials
|
166
166
|
);
|
@@ -174,7 +174,7 @@ export class RLNInstance {
|
|
174
174
|
this._contract = await RLNContract.init(this, {
|
175
175
|
address: address!,
|
176
176
|
signer: signer!,
|
177
|
-
rateLimit:
|
177
|
+
rateLimit: rateLimit ?? this.zerokit.getRateLimit
|
178
178
|
});
|
179
179
|
this.started = true;
|
180
180
|
} finally {
|
@@ -190,14 +190,14 @@ export class RLNInstance {
|
|
190
190
|
const address =
|
191
191
|
credentials?.membership.address ||
|
192
192
|
options.address ||
|
193
|
-
|
193
|
+
LINEA_CONTRACT.address;
|
194
194
|
|
195
|
-
if (address ===
|
196
|
-
chainId =
|
195
|
+
if (address === LINEA_CONTRACT.address) {
|
196
|
+
chainId = LINEA_CONTRACT.chainId;
|
197
197
|
}
|
198
198
|
|
199
199
|
const signer = options.signer || (await extractMetaMaskSigner());
|
200
|
-
const currentChainId = await signer.getChainId();
|
200
|
+
const currentChainId = (await signer.getChainId()).toString();
|
201
201
|
|
202
202
|
if (chainId && chainId !== currentChainId) {
|
203
203
|
throw Error(
|
@@ -312,7 +312,7 @@ export class RLNInstance {
|
|
312
312
|
|
313
313
|
const chainId = credentials.membership.chainId;
|
314
314
|
const network = await this._contract.provider.getNetwork();
|
315
|
-
const currentChainId = network.chainId;
|
315
|
+
const currentChainId = network.chainId.toString();
|
316
316
|
if (chainId !== currentChainId) {
|
317
317
|
throw Error(
|
318
318
|
`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`
|