@waku/rln 0.1.5-861a776.0 → 0.1.5-a8ff776.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 (47) hide show
  1. package/bundle/index.js +0 -2
  2. package/bundle/packages/rln/dist/contract/constants.js +1 -1
  3. package/bundle/packages/rln/dist/contract/rln_contract.js +8 -8
  4. package/bundle/packages/rln/dist/identity.js +0 -9
  5. package/bundle/packages/rln/dist/keystore/keystore.js +25 -15
  6. package/bundle/packages/rln/dist/rln.js +4 -4
  7. package/dist/.tsbuildinfo +1 -1
  8. package/dist/contract/constants.d.ts +1 -1
  9. package/dist/contract/constants.js +1 -1
  10. package/dist/contract/constants.js.map +1 -1
  11. package/dist/contract/rln_contract.js +8 -8
  12. package/dist/contract/rln_contract.js.map +1 -1
  13. package/dist/identity.d.ts +0 -1
  14. package/dist/identity.js +0 -9
  15. package/dist/identity.js.map +1 -1
  16. package/dist/index.d.ts +1 -3
  17. package/dist/index.js +1 -3
  18. package/dist/index.js.map +1 -1
  19. package/dist/keystore/keystore.d.ts +1 -0
  20. package/dist/keystore/keystore.js +25 -15
  21. package/dist/keystore/keystore.js.map +1 -1
  22. package/dist/keystore/types.d.ts +1 -1
  23. package/dist/rln.js +4 -4
  24. package/dist/rln.js.map +1 -1
  25. package/package.json +1 -1
  26. package/src/contract/constants.ts +1 -1
  27. package/src/contract/rln_contract.ts +8 -8
  28. package/src/identity.ts +0 -10
  29. package/src/index.ts +0 -4
  30. package/src/keystore/keystore.ts +43 -27
  31. package/src/keystore/types.ts +1 -1
  32. package/src/rln.ts +4 -4
  33. package/bundle/packages/rln/dist/contract/rln_light_contract.js +0 -477
  34. package/bundle/packages/rln/dist/rln_light.js +0 -149
  35. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +0 -43
  36. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +0 -116
  37. package/bundle/packages/rln/node_modules/@noble/hashes/esm/hmac.js +0 -79
  38. package/bundle/packages/rln/node_modules/@noble/hashes/esm/sha256.js +0 -126
  39. package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +0 -43
  40. package/dist/contract/rln_light_contract.d.ts +0 -124
  41. package/dist/contract/rln_light_contract.js +0 -460
  42. package/dist/contract/rln_light_contract.js.map +0 -1
  43. package/dist/rln_light.d.ts +0 -64
  44. package/dist/rln_light.js +0 -144
  45. package/dist/rln_light.js.map +0 -1
  46. package/src/contract/rln_light_contract.ts +0 -725
  47. package/src/rln_light.ts +0 -235
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()).toString();
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,CAAC;AAE1B,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC;AAEnC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,IAAI,CAAC;QACH,OAA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