@waku/rln 0.1.5-5e19700.0 → 0.1.5-ea6daae.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.
Files changed (125) hide show
  1. package/README.md +0 -5
  2. package/bundle/_virtual/index2.js +1 -1
  3. package/bundle/_virtual/utils.js +2 -2
  4. package/bundle/_virtual/utils2.js +2 -2
  5. package/bundle/index.js +1 -3
  6. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/checksum.js +3 -3
  7. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/cipher.js +4 -4
  8. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/class.js +7 -7
  9. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/functional.js +7 -7
  10. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/index.js +6 -6
  11. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/kdf.js +5 -5
  12. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/password.js +1 -1
  13. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1 -1
  14. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/schema-validation.js +2 -2
  15. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/types.js +1 -1
  16. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_assert.js +1 -1
  17. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_sha2.js +3 -3
  18. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_u64.js +1 -1
  19. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/cryptoBrowser.js +1 -1
  20. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/hmac.js +3 -3
  21. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/pbkdf2.js +4 -4
  22. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/scrypt.js +5 -5
  23. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/sha256.js +3 -3
  24. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/sha512.js +4 -4
  25. package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/utils.js +2 -2
  26. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +3 -3
  27. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +7 -7
  28. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +3 -3
  29. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +3 -3
  30. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +3 -3
  31. package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +7 -7
  32. package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +1 -1
  33. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +1 -1
  34. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +1 -1
  35. package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +1 -1
  36. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +1 -1
  37. package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +1 -1
  38. package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +1 -1
  39. package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +1 -1
  40. package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +1 -1
  41. package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +1 -1
  42. package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +19 -1
  43. package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +1 -1
  44. package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +1 -1
  45. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +1 -1
  46. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +58 -10
  47. package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +1 -1
  48. package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +1 -1
  49. package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +1 -1
  50. package/bundle/node_modules/{@ethersproject/keccak256/node_modules/js-sha3 → js-sha3}/src/sha3.js +2 -2
  51. package/bundle/packages/rln/dist/contract/abi.js +248 -502
  52. package/bundle/packages/rln/dist/contract/constants.js +4 -4
  53. package/bundle/packages/rln/dist/contract/rln_contract.js +36 -120
  54. package/bundle/packages/rln/dist/keystore/cipher.js +3 -3
  55. package/bundle/packages/rln/dist/keystore/keystore.js +2 -3
  56. package/bundle/packages/rln/dist/rln.js +6 -6
  57. package/dist/.tsbuildinfo +1 -1
  58. package/dist/contract/abi.d.ts +17 -21
  59. package/dist/contract/abi.js +248 -502
  60. package/dist/contract/abi.js.map +1 -1
  61. package/dist/contract/constants.d.ts +18 -22
  62. package/dist/contract/constants.js +3 -3
  63. package/dist/contract/constants.js.map +1 -1
  64. package/dist/contract/rln_contract.d.ts +3 -10
  65. package/dist/contract/rln_contract.js +36 -120
  66. package/dist/contract/rln_contract.js.map +1 -1
  67. package/dist/index.d.ts +2 -5
  68. package/dist/index.js +2 -4
  69. package/dist/index.js.map +1 -1
  70. package/dist/keystore/keystore.js +1 -2
  71. package/dist/keystore/keystore.js.map +1 -1
  72. package/dist/keystore/types.d.ts +0 -1
  73. package/dist/rln.d.ts +1 -1
  74. package/dist/rln.js +6 -6
  75. package/dist/rln.js.map +1 -1
  76. package/package.json +1 -1
  77. package/src/contract/abi.ts +248 -502
  78. package/src/contract/constants.ts +3 -3
  79. package/src/contract/rln_contract.ts +46 -158
  80. package/src/index.ts +2 -17
  81. package/src/keystore/keystore.ts +1 -2
  82. package/src/keystore/types.ts +0 -1
  83. package/src/rln.ts +7 -7
  84. package/bundle/packages/rln/dist/contract/rln_light_contract.js +0 -473
  85. package/bundle/packages/rln/dist/rln_light.js +0 -149
  86. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +0 -43
  87. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +0 -116
  88. package/bundle/packages/rln/node_modules/@noble/hashes/esm/hmac.js +0 -79
  89. package/bundle/packages/rln/node_modules/@noble/hashes/esm/sha256.js +0 -126
  90. package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +0 -43
  91. package/dist/codec.test-utils.d.ts +0 -36
  92. package/dist/codec.test-utils.js +0 -56
  93. package/dist/codec.test-utils.js.map +0 -1
  94. package/dist/contract/rln_light_contract.d.ts +0 -124
  95. package/dist/contract/rln_light_contract.js +0 -456
  96. package/dist/contract/rln_light_contract.js.map +0 -1
  97. package/dist/contract/test-setup.d.ts +0 -26
  98. package/dist/contract/test-setup.js +0 -56
  99. package/dist/contract/test-setup.js.map +0 -1
  100. package/dist/contract/test-utils.d.ts +0 -39
  101. package/dist/contract/test-utils.js +0 -118
  102. package/dist/contract/test-utils.js.map +0 -1
  103. package/dist/rln_light.d.ts +0 -64
  104. package/dist/rln_light.js +0 -144
  105. package/dist/rln_light.js.map +0 -1
  106. package/src/codec.test-utils.ts +0 -80
  107. package/src/contract/rln_light_contract.ts +0 -718
  108. package/src/contract/test-setup.ts +0 -86
  109. package/src/contract/test-utils.ts +0 -179
  110. package/src/rln_light.ts +0 -235
  111. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +0 -0
  112. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +0 -0
  113. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +0 -0
  114. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +0 -0
  115. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +0 -0
  116. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +0 -0
  117. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +0 -0
  118. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +0 -0
  119. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +0 -0
  120. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +0 -0
  121. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +0 -0
  122. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +0 -0
  123. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +0 -0
  124. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +0 -0
  125. /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +0 -0
@@ -1,118 +0,0 @@
1
- import { hexToBytes } from "@waku/utils/bytes";
2
- import { expect } from "chai";
3
- import * as ethers from "ethers";
4
- import sinon from "sinon";
5
- import { DEFAULT_RATE_LIMIT, LINEA_CONTRACT } from "./constants.js";
6
- export const mockRateLimits = {
7
- minRate: 20,
8
- maxRate: 600,
9
- maxTotalRate: 1200,
10
- currentTotalRate: 500
11
- };
12
- export function createMockProvider() {
13
- return {
14
- getLogs: () => [],
15
- getBlockNumber: () => Promise.resolve(1000),
16
- getNetwork: () => Promise.resolve({ chainId: 11155111 })
17
- };
18
- }
19
- export function createMockFilters() {
20
- return {
21
- MembershipRegistered: () => ({ address: LINEA_CONTRACT.address }),
22
- MembershipErased: () => ({ address: LINEA_CONTRACT.address }),
23
- MembershipExpired: () => ({ address: LINEA_CONTRACT.address })
24
- };
25
- }
26
- export function createMockRegistryContract(overrides = {}) {
27
- const filters = {
28
- MembershipRegistered: () => ({ address: LINEA_CONTRACT.address }),
29
- MembershipErased: () => ({ address: LINEA_CONTRACT.address }),
30
- MembershipExpired: () => ({ address: LINEA_CONTRACT.address })
31
- };
32
- const baseContract = {
33
- minMembershipRateLimit: () => Promise.resolve(ethers.BigNumber.from(mockRateLimits.minRate)),
34
- maxMembershipRateLimit: () => Promise.resolve(ethers.BigNumber.from(mockRateLimits.maxRate)),
35
- maxTotalRateLimit: () => Promise.resolve(ethers.BigNumber.from(mockRateLimits.maxTotalRate)),
36
- currentTotalRateLimit: () => Promise.resolve(ethers.BigNumber.from(mockRateLimits.currentTotalRate)),
37
- queryFilter: () => [],
38
- provider: createMockProvider(),
39
- filters,
40
- on: () => ({}),
41
- removeAllListeners: () => ({}),
42
- register: () => ({
43
- wait: () => Promise.resolve({
44
- events: [mockRLNRegisteredEvent()]
45
- })
46
- }),
47
- estimateGas: {
48
- register: () => Promise.resolve(ethers.BigNumber.from(100000))
49
- },
50
- functions: {
51
- register: () => Promise.resolve()
52
- },
53
- getMemberIndex: () => Promise.resolve(null),
54
- interface: {
55
- getEvent: (eventName) => ({
56
- name: eventName,
57
- format: () => { }
58
- })
59
- },
60
- address: LINEA_CONTRACT.address
61
- };
62
- // Merge overrides while preserving filters
63
- const merged = {
64
- ...baseContract,
65
- ...overrides,
66
- filters: { ...filters, ...(overrides.filters || {}) }
67
- };
68
- return merged;
69
- }
70
- export function mockRLNRegisteredEvent(idCommitment) {
71
- return {
72
- args: {
73
- idCommitment: idCommitment ||
74
- "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
75
- membershipRateLimit: ethers.BigNumber.from(DEFAULT_RATE_LIMIT),
76
- index: ethers.BigNumber.from(1)
77
- },
78
- event: "MembershipRegistered"
79
- };
80
- }
81
- export function formatIdCommitment(idCommitmentBigInt) {
82
- return "0x" + idCommitmentBigInt.toString(16).padStart(64, "0");
83
- }
84
- export function createRegisterStub(identity) {
85
- return sinon.stub().callsFake(() => ({
86
- wait: () => Promise.resolve({
87
- events: [
88
- {
89
- event: "MembershipRegistered",
90
- args: {
91
- idCommitment: formatIdCommitment(identity.IDCommitmentBigInt),
92
- rateLimit: DEFAULT_RATE_LIMIT,
93
- index: ethers.BigNumber.from(1)
94
- }
95
- }
96
- ]
97
- })
98
- }));
99
- }
100
- export function verifyRegistration(decryptedCredentials, identity, registerStub, insertMemberSpy) {
101
- if (!decryptedCredentials) {
102
- throw new Error("Decrypted credentials should not be undefined");
103
- }
104
- // Verify registration call
105
- expect(registerStub.calledWith(sinon.match.same(identity.IDCommitmentBigInt), sinon.match.same(DEFAULT_RATE_LIMIT), sinon.match.array, sinon.match.object)).to.be.true;
106
- // Verify credential properties
107
- expect(decryptedCredentials).to.have.property("identity");
108
- expect(decryptedCredentials).to.have.property("membership");
109
- expect(decryptedCredentials.membership).to.include({
110
- address: LINEA_CONTRACT.address,
111
- treeIndex: 1
112
- });
113
- // Verify member insertion
114
- const expectedIdCommitment = ethers.utils.zeroPad(hexToBytes(formatIdCommitment(identity.IDCommitmentBigInt)), 32);
115
- expect(insertMemberSpy.callCount).to.equal(1);
116
- expect(insertMemberSpy.getCall(0).args[0]).to.deep.equal(expectedIdCommitment);
117
- }
118
- //# sourceMappingURL=test-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../src/contract/test-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEpE,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,GAAG;IACZ,YAAY,EAAE,IAAI;IAClB,gBAAgB,EAAE,GAAG;CACtB,CAAC;AAcF,MAAM,UAAU,kBAAkB;IAChC,OAAO;QACL,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;QACjB,cAAc,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;QAC3C,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;KACzD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,OAAO;QACL,oBAAoB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,OAAO,EAAE,CAAC;QACjE,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,OAAO,EAAE,CAAC;QAC7D,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,CAAC,OAAO,EAAE,CAAC;KAC/D,C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AAC,OAAO,CAAC;QACjD,OAAO,EAAE,cAAc,CAAC,OAAO;QAC/B,SAAS,EAAE,CAAC;KACb,CAAC,CAAC;IAEH,0BAA0B;IAC1B,MAAM,oBAAoB,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAC/C,UAAU,CAAC,kBAAkB,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,EAC3D,EAAE,CACH,CAAC;IACF,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9C,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CACtD,oBAAoB,CACrB,CAAC;AACJ,CAAC"}
@@ -1,64 +0,0 @@
1
- import { ethers } from "ethers";
2
- import { RLNLightContract } from "./contract/rln_light_contract.js";
3
- import { IdentityCredential } from "./identity.js";
4
- import type { DecryptedCredentials, EncryptedCredentials } from "./keystore/index.js";
5
- import { Password } from "./keystore/types.js";
6
- /**
7
- * Create an instance of RLN
8
- * @returns RLNInstance
9
- */
10
- export declare function create(): Promise<RLNLightInstance>;
11
- type StartRLNOptions = {
12
- /**
13
- * If not set - will extract MetaMask account and get signer from it.
14
- */
15
- signer?: ethers.Signer;
16
- /**
17
- * If not set - will use default SEPOLIA_CONTRACT address.
18
- */
19
- address?: string;
20
- /**
21
- * Credentials to use for generating proofs and connecting to the contract and network.
22
- * If provided used for validating the network chainId and connecting to registry contract.
23
- */
24
- credentials?: EncryptedCredentials | DecryptedCredentials;
25
- /**
26
- * Rate limit for the member.
27
- */
28
- rateLimit?: number;
29
- };
30
- type RegisterMembershipOptions = {
31
- signature: string;
32
- } | {
33
- identity: IdentityCredential;
34
- };
35
- export declare class RLNLightInstance {
36
- private started;
37
- private starting;
38
- private _contract;
39
- private _signer;
40
- private keystore;
41
- private _credentials;
42
- constructor();
43
- get contract(): undefined | RLNLightContract;
44
- get signer(): undefined | ethers.Signer;
45
- start(options?: StartRLNOptions): Promise<void>;
46
- get credentials(): DecryptedCredentials | undefined;
47
- private determineStartOptions;
48
- private static decryptCredentialsIfNeeded;
49
- /**
50
- * Generates an identity credential from a seed string
51
- * This is a pure implementation that doesn't rely on Zerokit
52
- * @param seed A string seed to generate the identity from
53
- * @returns IdentityCredential
54
- */
55
- private generateSeededIdentityCredential;
56
- registerMembership(options: RegisterMembershipOptions): Promise<undefined | DecryptedCredentials>;
57
- /**
58
- * Changes credentials in use by relying on provided Keystore earlier in rln.start
59
- * @param id: string, hash of credentials to select from Keystore
60
- * @param password: string or bytes to use to decrypt credentials from Keystore
61
- */
62
- useCredentials(id: string, password: Password): Promise<void>;
63
- }
64
- export {};
package/dist/rln_light.js DELETED
@@ -1,144 +0,0 @@
1
- import { hmac } from "@noble/hashes/hmac";
2
- import { sha256 } from "@noble/hashes/sha256";
3
- import { Logger } from "@waku/utils";
4
- import { LINEA_CONTRACT } from "./contract/constants.js";
5
- import { RLNLightContract } from "./contract/rln_light_contract.js";
6
- import { IdentityCredential } from "./identity.js";
7
- import { Keystore } from "./keystore/index.js";
8
- import { buildBigIntFromUint8Array, extractMetaMaskSigner } from "./utils/index.js";
9
- const log = new Logger("waku:rln");
10
- /**
11
- * Create an instance of RLN
12
- * @returns RLNInstance
13
- */
14
- export async function create() {
15
- try {
16
- return new RLNLightInstance();
17
- }
18
- catch (error) {
19
- log.error("Failed to initialize RLN:", error);
20
- throw error;
21
- }
22
- }
23
- export class RLNLightInstance {
24
- started = false;
25
- starting = false;
26
- _contract;
27
- _signer;
28
- keystore = Keystore.create();
29
- _credentials;
30
- constructor() { }
31
- get contract() {
32
- return this._contract;
33
- }
34
- get signer() {
35
- return this._signer;
36
- }
37
- async start(options = {}) {
38
- if (this.started || this.starting) {
39
- return;
40
- }
41
- this.starting = true;
42
- try {
43
- const { credentials, keystore } = await RLNLightInstance.decryptCredentialsIfNeeded(options.credentials);
44
- const { signer, address, rateLimit } = await this.determineStartOptions(options, credentials);
45
- if (keystore) {
46
- this.keystore = keystore;
47
- }
48
- this._credentials = credentials;
49
- this._signer = signer;
50
- this._contract = await RLNLightContract.init({
51
- address: address,
52
- signer: signer,
53
- rateLimit: rateLimit
54
- });
55
- this.started = true;
56
- }
57
- finally {
58
- this.starting = false;
59
- }
60
- }
61
- get credentials() {
62
- return this._credentials;
63
- }
64
- async determineStartOptions(options, credentials) {
65
- let chainId = credentials?.membership.chainId;
66
- const address = credentials?.membership.address ||
67
- options.address ||
68
- LINEA_CONTRACT.address;
69
- if (address === LINEA_CONTRACT.address) {
70
- chainId = LINEA_CONTRACT.chainId;
71
- }
72
- const signer = options.signer || (await extractMetaMaskSigner());
73
- const currentChainId = await signer.getChainId();
74
- if (chainId && chainId !== currentChainId) {
75
- throw Error(`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`);
76
- }
77
- return {
78
- signer,
79
- address
80
- };
81
- }
82
- static async decryptCredentialsIfNeeded(credentials) {
83
- if (!credentials) {
84
- return {};
85
- }
86
- if ("identity" in credentials) {
87
- return { credentials };
88
- }
89
- const keystore = Keystore.fromString(credentials.keystore);
90
- if (!keystore) {
91
- return {};
92
- }
93
- const decryptedCredentials = await keystore.readCredential(credentials.id, credentials.password);
94
- return {
95
- keystore,
96
- credentials: decryptedCredentials
97
- };
98
- }
99
- /**
100
- * Generates an identity credential from a seed string
101
- * This is a pure implementation that doesn't rely on Zerokit
102
- * @param seed A string seed to generate the identity from
103
- * @returns IdentityCredential
104
- */
105
- generateSeededIdentityCredential(seed) {
106
- // Convert the seed to bytes
107
- const encoder = new TextEncoder();
108
- const seedBytes = encoder.encode(seed);
109
- // Generate deterministic values using HMAC-SHA256
110
- // We use different context strings for each component to ensure they're different
111
- const idTrapdoor = hmac(sha256, seedBytes, encoder.encode("IDTrapdoor"));
112
- const idNullifier = hmac(sha256, seedBytes, encoder.encode("IDNullifier"));
113
- // Generate IDSecretHash as a hash of IDTrapdoor and IDNullifier
114
- const combinedBytes = new Uint8Array([...idTrapdoor, ...idNullifier]);
115
- const idSecretHash = sha256(combinedBytes);
116
- // Generate IDCommitment as a hash of IDSecretHash
117
- const idCommitment = sha256(idSecretHash);
118
- // Convert IDCommitment to BigInt
119
- const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
120
- return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
121
- }
122
- async registerMembership(options) {
123
- if (!this.contract) {
124
- throw Error("RLN Contract is not initialized.");
125
- }
126
- let identity = "identity" in options && options.identity;
127
- if ("signature" in options) {
128
- identity = this.generateSeededIdentityCredential(options.signature);
129
- }
130
- if (!identity) {
131
- throw Error("Missing signature or identity to register membership.");
132
- }
133
- return this.contract.registerWithIdentity(identity);
134
- }
135
- /**
136
- * Changes credentials in use by relying on provided Keystore earlier in rln.start
137
- * @param id: string, hash of credentials to select from Keystore
138
- * @param password: string or bytes to use to decrypt credentials from Keystore
139
- */
140
- async useCredentials(id, password) {
141
- this._credentials = await this.keystore?.readCredential(id, password);
142
- }
143
- }
144
- //# sourceMappingURL=rln_light.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rln_light.js","sourceRoot":"","sources":["../src/rln_light.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAM/C,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,kBAAkB,CAA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CAAC;IAEM,KAAK,CAAC,kBAAkB,CAC7B,OAAkC;QAElC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAClD,CAAC;QAED,IAAI,QAAQ,GAAG,UAAU,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;QAEzD,IAAI,WAAW,IAAI,OAAO,EAAE,CAAC;YAC3B,QAAQ,GAAG,IAAI,CAAC,gCAAgC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,KAAK,CAAC,uDAAuD,CAAC,CAAC;QACvE,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,cAAc,CAAC,EAAU,EAAE,QAAkB;QACxD,IAAI,CAAC,YAAY,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IACxE,CAAC;CACF"}
@@ -1,80 +0,0 @@
1
- import type { IProtoMessage } from "@waku/interfaces";
2
- import { expect } from "chai";
3
-
4
- import { createRLN } from "./create.js";
5
- import type { IdentityCredential } from "./identity.js";
6
-
7
- export interface TestRLNCodecSetup {
8
- rlnInstance: any;
9
- credential: IdentityCredential;
10
- index: number;
11
- payload: Uint8Array;
12
- }
13
-
14
- export const TEST_CONSTANTS = {
15
- contentTopic: "/test/1/waku-message/utf8",
16
- emptyPubsubTopic: "",
17
- defaultIndex: 0,
18
- defaultPayload: new Uint8Array([1, 2, 3, 4, 5])
19
- } as const;
20
-
21
- export const EMPTY_PROTO_MESSAGE = {
22
- timestamp: undefined,
23
- contentTopic: "",
24
- ephemeral: undefined,
25
- meta: undefined,
26
- rateLimitProof: undefined,
27
- version: undefined
28
- } as const;
29
-
30
- /**
31
- * Creates a basic RLN setup for codec tests
32
- */
33
- export async function createTestRLNCodecSetup(): Promise<TestRLNCodecSetup> {
34
- const rlnInstance = await createRLN();
35
- const credential = rlnInstance.zerokit.generateIdentityCredentials();
36
- rlnInstance.zerokit.insertMember(credential.IDCommitment);
37
-
38
- return {
39
- rlnInstance,
40
- credential,
41
- index: TEST_CONSTANTS.defaultIndex,
42
- payload: TEST_CONSTANTS.defaultPayload
43
- };
44
- }
45
-
46
- /**
47
- * Creates a meta setter function for testing
48
- */
49
- export function createTestMetaSetter(): (
50
- msg: IProtoMessage & { meta: undefined }
51
- ) => Uint8Array {
52
- return (msg: IProtoMessage & { meta: undefined }): Uint8Array => {
53
- const buffer = new ArrayBuffer(4);
54
- const view = new DataView(buffer);
55
- view.setUint32(0, msg.payload.length, false);
56
- return new Uint8Array(buffer);
57
- };
58
- }
59
-
60
- /**
61
- * Verifies common RLN message properties
62
- */
63
- export function verifyRLNMessage(
64
- msg: any,
65
- payload: Uint8Array,
66
- contentTopic: string,
67
- version: number,
68
- rlnInstance: any
69
- ): void {
70
- expect(msg.rateLimitProof).to.not.be.undefined;
71
- expect(msg.verify([rlnInstance.zerokit.getMerkleRoot()])).to.be.true;
72
- expect(msg.verifyNoRoot()).to.be.true;
73
- expect(msg.epoch).to.not.be.undefined;
74
- expect(msg.epoch).to.be.gt(0);
75
-
76
- expect(msg.contentTopic).to.eq(contentTopic);
77
- expect(msg.msg.version).to.eq(version);
78
- expect(msg.payload).to.deep.eq(payload);
79
- expect(msg.timestamp).to.not.be.undefined;
80
- }