@waku/rln 0.1.5-ff0222a.0 → 0.1.6-b7e9b08.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/CHANGELOG.md +22 -0
- package/bundle/_virtual/index2.js +1 -1
- package/bundle/index.js +2 -2
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/checksum.js +3 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/cipher.js +4 -4
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/class.js +7 -7
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/functional.js +7 -7
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/index.js +6 -6
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/kdf.js +5 -5
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/password.js +1 -1
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1 -1
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/schema-validation.js +2 -2
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/lib/types.js +1 -1
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_assert.js +1 -1
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_sha2.js +3 -3
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/_u64.js +1 -1
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/cryptoBrowser.js +1 -1
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/hmac.js +3 -3
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/pbkdf2.js +4 -4
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/scrypt.js +5 -5
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/sha256.js +3 -3
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/sha512.js +4 -4
- package/bundle/{packages/rln → node_modules/@chainsafe/bls-keystore}/node_modules/@noble/hashes/utils.js +2 -2
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +3 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +7 -7
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +3 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +3 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +3 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +7 -7
- 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/networks/lib.esm/_version.js +1 -1
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +19 -1
- 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 +58 -10
- 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/node_modules/@noble/hashes/esm/_assert.js +6 -32
- package/bundle/node_modules/@noble/hashes/esm/_md.js +22 -11
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +4 -3
- package/bundle/{packages/rln/node_modules → node_modules}/@noble/hashes/esm/hmac.js +19 -10
- package/bundle/{packages/rln/node_modules/@noble/hashes/esm/sha256.js → node_modules/@noble/hashes/esm/sha2.js} +36 -50
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +5 -102
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +30 -24
- package/bundle/node_modules/@noble/hashes/esm/utils.js +69 -18
- package/bundle/node_modules/bn.js/lib/bn.js +1 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +1 -1
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +3 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +3 -3
- package/bundle/packages/core/dist/lib/filter/filter.js +3 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +3 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +3 -0
- package/bundle/packages/core/dist/lib/store/store.js +3 -3
- package/bundle/packages/proto/dist/generated/sds_message.js +59 -3
- package/bundle/packages/rln/dist/codec.js +3 -3
- package/bundle/packages/rln/dist/contract/constants.js +1 -1
- package/bundle/packages/rln/dist/contract/{rln_light_contract.js → rln_base_contract.js} +180 -180
- package/bundle/packages/rln/dist/contract/rln_contract.js +12 -422
- package/bundle/packages/rln/dist/contract/types.js +9 -0
- package/bundle/packages/rln/dist/create.js +1 -1
- package/bundle/packages/rln/dist/credentials_manager.js +215 -0
- package/bundle/packages/rln/dist/identity.js +0 -9
- package/bundle/packages/rln/dist/keystore/cipher.js +3 -3
- package/bundle/packages/rln/dist/keystore/keystore.js +32 -18
- package/bundle/packages/rln/dist/rln.js +59 -169
- package/bundle/packages/rln/dist/utils/epoch.js +3 -3
- package/bundle/packages/rln/dist/zerokit.js +5 -5
- package/bundle/packages/utils/dist/common/sharding/index.js +4 -4
- package/bundle/packages/utils/node_modules/@waku/interfaces/dist/connection_manager.js +19 -0
- package/bundle/packages/utils/node_modules/@waku/interfaces/dist/health_indicator.js +12 -0
- package/bundle/packages/utils/node_modules/@waku/interfaces/dist/protocols.js +92 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/contract/constants.d.ts +1 -1
- package/dist/contract/constants.js +1 -1
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/{rln_light_contract.d.ts → rln_base_contract.d.ts} +25 -53
- package/dist/contract/{rln_light_contract.js → rln_base_contract.js} +177 -177
- package/dist/contract/rln_base_contract.js.map +1 -0
- package/dist/contract/rln_contract.d.ts +5 -122
- package/dist/contract/rln_contract.js +8 -417
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/contract/types.d.ts +40 -0
- package/dist/contract/types.js +8 -0
- package/dist/contract/types.js.map +1 -0
- package/dist/create.js +1 -1
- package/dist/create.js.map +1 -1
- package/dist/credentials_manager.d.ts +44 -0
- package/dist/credentials_manager.js +197 -0
- package/dist/credentials_manager.js.map +1 -0
- package/dist/identity.d.ts +0 -1
- package/dist/identity.js +0 -9
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/keystore/keystore.d.ts +1 -0
- package/dist/keystore/keystore.js +27 -13
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/rln.d.ts +9 -52
- package/dist/rln.js +54 -163
- package/dist/rln.js.map +1 -1
- package/dist/types.d.ts +27 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/zerokit.d.ts +3 -3
- package/dist/zerokit.js +5 -5
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/constants.ts +1 -1
- package/src/contract/{rln_light_contract.ts → rln_base_contract.ts} +294 -312
- package/src/contract/rln_contract.ts +9 -663
- package/src/contract/types.ts +48 -0
- package/src/create.ts +1 -1
- package/src/credentials_manager.ts +282 -0
- package/src/identity.ts +0 -10
- package/src/index.ts +4 -4
- package/src/keystore/keystore.ts +49 -25
- package/src/rln.ts +67 -258
- package/src/types.ts +31 -0
- package/src/zerokit.ts +3 -3
- package/bundle/packages/rln/dist/rln_light.js +0 -149
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +0 -43
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +0 -116
- package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +0 -43
- package/dist/contract/rln_light_contract.js.map +0 -1
- package/dist/rln_light.d.ts +0 -64
- package/dist/rln_light.js +0 -144
- package/dist/rln_light.js.map +0 -1
- package/src/rln_light.ts +0 -235
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/uuid/dist/esm-browser/native.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/uuid/dist/esm-browser/rng.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/uuid/dist/esm-browser/stringify.js +0 -0
- /package/bundle/{packages/rln/node_modules → node_modules}/uuid/dist/esm-browser/v4.js +0 -0
- /package/bundle/packages/{interfaces → utils/node_modules/@waku/interfaces}/dist/constants.js +0 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
import { ethers } from "ethers";
|
2
|
+
export interface CustomQueryOptions extends FetchMembersOptions {
|
3
|
+
membersFilter: ethers.EventFilter;
|
4
|
+
}
|
5
|
+
export type Member = {
|
6
|
+
idCommitment: string;
|
7
|
+
index: ethers.BigNumber;
|
8
|
+
};
|
9
|
+
export interface RLNContractOptions {
|
10
|
+
signer: ethers.Signer;
|
11
|
+
address: string;
|
12
|
+
rateLimit?: number;
|
13
|
+
}
|
14
|
+
export interface RLNContractInitOptions extends RLNContractOptions {
|
15
|
+
contract?: ethers.Contract;
|
16
|
+
}
|
17
|
+
export interface MembershipRegisteredEvent {
|
18
|
+
idCommitment: string;
|
19
|
+
membershipRateLimit: ethers.BigNumber;
|
20
|
+
index: ethers.BigNumber;
|
21
|
+
}
|
22
|
+
export type FetchMembersOptions = {
|
23
|
+
fromBlock?: number;
|
24
|
+
fetchRange?: number;
|
25
|
+
fetchChunks?: number;
|
26
|
+
};
|
27
|
+
export interface MembershipInfo {
|
28
|
+
index: ethers.BigNumber;
|
29
|
+
idCommitment: string;
|
30
|
+
rateLimit: number;
|
31
|
+
startBlock: number;
|
32
|
+
endBlock: number;
|
33
|
+
state: MembershipState;
|
34
|
+
}
|
35
|
+
export declare enum MembershipState {
|
36
|
+
Active = "Active",
|
37
|
+
GracePeriod = "GracePeriod",
|
38
|
+
Expired = "Expired",
|
39
|
+
ErasedAwaitsWithdrawal = "ErasedAwaitsWithdrawal"
|
40
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export var MembershipState;
|
2
|
+
(function (MembershipState) {
|
3
|
+
MembershipState["Active"] = "Active";
|
4
|
+
MembershipState["GracePeriod"] = "GracePeriod";
|
5
|
+
MembershipState["Expired"] = "Expired";
|
6
|
+
MembershipState["ErasedAwaitsWithdrawal"] = "ErasedAwaitsWithdrawal";
|
7
|
+
})(MembershipState || (MembershipState = {}));
|
8
|
+
//# sourceMappingURL=types.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/contract/types.ts"],"names":[],"mappings":"AA0CA,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,8CAA2B,CAAA;IAC3B,sCAAmB,CAAA;IACnB,oEAAiD,CAAA;AACnD,CAAC,EALW,eAAe,KAAf,eAAe,QAK1B"}
|
package/dist/create.js
CHANGED
@@ -3,6 +3,6 @@ export async function createRLN() {
|
|
3
3
|
// asynchronously. This file does the single async import, so
|
4
4
|
// that no one else needs to worry about it again.
|
5
5
|
const rlnModule = await import("./rln.js");
|
6
|
-
return rlnModule.create();
|
6
|
+
return rlnModule.RLNInstance.create();
|
7
7
|
}
|
8
8
|
//# sourceMappingURL=create.js.map
|
package/dist/create.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,iEAAiE;IACjE,6DAA6D;IAC7D,kDAAkD;IAClD,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;IAC3C,OAAO,SAAS,CAAC,MAAM,EAAE,CAAC;
|
1
|
+
{"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,iEAAiE;IACjE,6DAA6D;IAC7D,kDAAkD;IAClD,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;IAC3C,OAAO,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;AACxC,CAAC"}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { ethers } from "ethers";
|
2
|
+
import { RLNBaseContract } from "./contract/rln_base_contract.js";
|
3
|
+
import { Keystore } from "./keystore/index.js";
|
4
|
+
import type { DecryptedCredentials, EncryptedCredentials } from "./keystore/index.js";
|
5
|
+
import { KeystoreEntity, Password } from "./keystore/types.js";
|
6
|
+
import { RegisterMembershipOptions, StartRLNOptions } from "./types.js";
|
7
|
+
import { Zerokit } from "./zerokit.js";
|
8
|
+
/**
|
9
|
+
* Manages credentials for RLN
|
10
|
+
* This is a lightweight implementation of the RLN contract that doesn't require Zerokit
|
11
|
+
* It is used to register membership and generate identity credentials
|
12
|
+
*/
|
13
|
+
export declare class RLNCredentialsManager {
|
14
|
+
protected started: boolean;
|
15
|
+
protected starting: boolean;
|
16
|
+
contract: undefined | RLNBaseContract;
|
17
|
+
signer: undefined | ethers.Signer;
|
18
|
+
protected keystore: Keystore;
|
19
|
+
credentials: undefined | DecryptedCredentials;
|
20
|
+
zerokit: undefined | Zerokit;
|
21
|
+
constructor(zerokit?: Zerokit);
|
22
|
+
get provider(): undefined | ethers.providers.Provider;
|
23
|
+
start(options?: StartRLNOptions): Promise<void>;
|
24
|
+
registerMembership(options: RegisterMembershipOptions): Promise<undefined | DecryptedCredentials>;
|
25
|
+
/**
|
26
|
+
* Changes credentials in use by relying on provided Keystore earlier in rln.start
|
27
|
+
* @param id: string, hash of credentials to select from Keystore
|
28
|
+
* @param password: string or bytes to use to decrypt credentials from Keystore
|
29
|
+
*/
|
30
|
+
useCredentials(id: string, password: Password): Promise<void>;
|
31
|
+
protected determineStartOptions(options: StartRLNOptions, credentials: KeystoreEntity | undefined): Promise<StartRLNOptions>;
|
32
|
+
protected static decryptCredentialsIfNeeded(credentials?: EncryptedCredentials | DecryptedCredentials): Promise<{
|
33
|
+
credentials?: DecryptedCredentials;
|
34
|
+
keystore?: Keystore;
|
35
|
+
}>;
|
36
|
+
protected verifyCredentialsAgainstContract(credentials: KeystoreEntity): Promise<void>;
|
37
|
+
/**
|
38
|
+
* Generates an identity credential from a seed string
|
39
|
+
* This is a pure implementation that doesn't rely on Zerokit
|
40
|
+
* @param seed A string seed to generate the identity from
|
41
|
+
* @returns IdentityCredential
|
42
|
+
*/
|
43
|
+
private generateSeededIdentityCredential;
|
44
|
+
}
|
@@ -0,0 +1,197 @@
|
|
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 { RLNBaseContract } from "./contract/rln_base_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:credentials");
|
10
|
+
/**
|
11
|
+
* Manages credentials for RLN
|
12
|
+
* This is a lightweight implementation of the RLN contract that doesn't require Zerokit
|
13
|
+
* It is used to register membership and generate identity credentials
|
14
|
+
*/
|
15
|
+
export class RLNCredentialsManager {
|
16
|
+
started = false;
|
17
|
+
starting = false;
|
18
|
+
contract;
|
19
|
+
signer;
|
20
|
+
keystore = Keystore.create();
|
21
|
+
credentials;
|
22
|
+
zerokit;
|
23
|
+
constructor(zerokit) {
|
24
|
+
log.info("RLNCredentialsManager initialized");
|
25
|
+
this.zerokit = zerokit;
|
26
|
+
}
|
27
|
+
get provider() {
|
28
|
+
return this.contract?.provider;
|
29
|
+
}
|
30
|
+
async start(options = {}) {
|
31
|
+
if (this.started || this.starting) {
|
32
|
+
log.info("RLNCredentialsManager already started or starting");
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
log.info("Starting RLNCredentialsManager");
|
36
|
+
this.starting = true;
|
37
|
+
try {
|
38
|
+
const { credentials, keystore } = await RLNCredentialsManager.decryptCredentialsIfNeeded(options.credentials);
|
39
|
+
if (credentials) {
|
40
|
+
log.info("Credentials successfully decrypted");
|
41
|
+
}
|
42
|
+
const { signer, address, rateLimit } = await this.determineStartOptions(options, credentials);
|
43
|
+
log.info(`Using contract address: ${address}`);
|
44
|
+
if (keystore) {
|
45
|
+
this.keystore = keystore;
|
46
|
+
log.info("Using provided keystore");
|
47
|
+
}
|
48
|
+
this.credentials = credentials;
|
49
|
+
this.signer = signer;
|
50
|
+
this.contract = new RLNBaseContract({
|
51
|
+
address: address,
|
52
|
+
signer: signer,
|
53
|
+
rateLimit: rateLimit ?? this.zerokit?.rateLimit
|
54
|
+
});
|
55
|
+
log.info("RLNCredentialsManager successfully started");
|
56
|
+
this.started = true;
|
57
|
+
}
|
58
|
+
catch (error) {
|
59
|
+
log.error("Failed to start RLNCredentialsManager", error);
|
60
|
+
throw error;
|
61
|
+
}
|
62
|
+
finally {
|
63
|
+
this.starting = false;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
async registerMembership(options) {
|
67
|
+
if (!this.contract) {
|
68
|
+
log.error("RLN Contract is not initialized");
|
69
|
+
throw Error("RLN Contract is not initialized.");
|
70
|
+
}
|
71
|
+
log.info("Registering membership");
|
72
|
+
let identity = "identity" in options && options.identity;
|
73
|
+
if ("signature" in options) {
|
74
|
+
log.info("Generating identity from signature");
|
75
|
+
if (this.zerokit) {
|
76
|
+
log.info("Using Zerokit to generate identity");
|
77
|
+
identity = this.zerokit.generateSeededIdentityCredential(options.signature);
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
log.info("Using local implementation to generate identity");
|
81
|
+
identity = this.generateSeededIdentityCredential(options.signature);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
if (!identity) {
|
85
|
+
log.error("Missing signature or identity to register membership");
|
86
|
+
throw Error("Missing signature or identity to register membership.");
|
87
|
+
}
|
88
|
+
log.info("Registering identity with contract");
|
89
|
+
return this.contract.registerWithIdentity(identity);
|
90
|
+
}
|
91
|
+
/**
|
92
|
+
* Changes credentials in use by relying on provided Keystore earlier in rln.start
|
93
|
+
* @param id: string, hash of credentials to select from Keystore
|
94
|
+
* @param password: string or bytes to use to decrypt credentials from Keystore
|
95
|
+
*/
|
96
|
+
async useCredentials(id, password) {
|
97
|
+
log.info(`Attempting to use credentials with ID: ${id}`);
|
98
|
+
this.credentials = await this.keystore?.readCredential(id, password);
|
99
|
+
if (this.credentials) {
|
100
|
+
log.info("Successfully loaded credentials");
|
101
|
+
}
|
102
|
+
else {
|
103
|
+
log.warn("Failed to load credentials");
|
104
|
+
}
|
105
|
+
}
|
106
|
+
async determineStartOptions(options, credentials) {
|
107
|
+
let chainId = credentials?.membership.chainId;
|
108
|
+
const address = credentials?.membership.address ||
|
109
|
+
options.address ||
|
110
|
+
LINEA_CONTRACT.address;
|
111
|
+
if (address === LINEA_CONTRACT.address) {
|
112
|
+
chainId = LINEA_CONTRACT.chainId.toString();
|
113
|
+
log.info(`Using Linea contract with chainId: ${chainId}`);
|
114
|
+
}
|
115
|
+
const signer = options.signer || (await extractMetaMaskSigner());
|
116
|
+
const currentChainId = await signer.getChainId();
|
117
|
+
log.info(`Current chain ID: ${currentChainId}`);
|
118
|
+
if (chainId && chainId !== currentChainId.toString()) {
|
119
|
+
log.error(`Chain ID mismatch: contract=${chainId}, current=${currentChainId}`);
|
120
|
+
throw Error(`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`);
|
121
|
+
}
|
122
|
+
return {
|
123
|
+
signer,
|
124
|
+
address
|
125
|
+
};
|
126
|
+
}
|
127
|
+
static async decryptCredentialsIfNeeded(credentials) {
|
128
|
+
if (!credentials) {
|
129
|
+
log.info("No credentials provided");
|
130
|
+
return {};
|
131
|
+
}
|
132
|
+
if ("identity" in credentials) {
|
133
|
+
log.info("Using already decrypted credentials");
|
134
|
+
return { credentials };
|
135
|
+
}
|
136
|
+
log.info("Attempting to decrypt credentials");
|
137
|
+
const keystore = Keystore.fromString(credentials.keystore);
|
138
|
+
if (!keystore) {
|
139
|
+
log.warn("Failed to create keystore from string");
|
140
|
+
return {};
|
141
|
+
}
|
142
|
+
try {
|
143
|
+
const decryptedCredentials = await keystore.readCredential(credentials.id, credentials.password);
|
144
|
+
log.info(`Successfully decrypted credentials with ID: ${credentials.id}`);
|
145
|
+
return {
|
146
|
+
keystore,
|
147
|
+
credentials: decryptedCredentials
|
148
|
+
};
|
149
|
+
}
|
150
|
+
catch (error) {
|
151
|
+
log.error("Failed to decrypt credentials", error);
|
152
|
+
throw error;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
async verifyCredentialsAgainstContract(credentials) {
|
156
|
+
if (!this.contract) {
|
157
|
+
throw Error("Failed to verify chain coordinates: no contract initialized.");
|
158
|
+
}
|
159
|
+
const registryAddress = credentials.membership.address;
|
160
|
+
const currentRegistryAddress = this.contract.address;
|
161
|
+
if (registryAddress !== currentRegistryAddress) {
|
162
|
+
throw Error(`Failed to verify chain coordinates: credentials contract address=${registryAddress} is not equal to registryContract address=${currentRegistryAddress}`);
|
163
|
+
}
|
164
|
+
const chainId = credentials.membership.chainId;
|
165
|
+
const network = await this.contract.provider.getNetwork();
|
166
|
+
const currentChainId = network.chainId;
|
167
|
+
if (chainId !== currentChainId.toString()) {
|
168
|
+
throw Error(`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`);
|
169
|
+
}
|
170
|
+
}
|
171
|
+
/**
|
172
|
+
* Generates an identity credential from a seed string
|
173
|
+
* This is a pure implementation that doesn't rely on Zerokit
|
174
|
+
* @param seed A string seed to generate the identity from
|
175
|
+
* @returns IdentityCredential
|
176
|
+
*/
|
177
|
+
generateSeededIdentityCredential(seed) {
|
178
|
+
log.info("Generating seeded identity credential");
|
179
|
+
// Convert the seed to bytes
|
180
|
+
const encoder = new TextEncoder();
|
181
|
+
const seedBytes = encoder.encode(seed);
|
182
|
+
// Generate deterministic values using HMAC-SHA256
|
183
|
+
// We use different context strings for each component to ensure they're different
|
184
|
+
const idTrapdoor = hmac(sha256, seedBytes, encoder.encode("IDTrapdoor"));
|
185
|
+
const idNullifier = hmac(sha256, seedBytes, encoder.encode("IDNullifier"));
|
186
|
+
// Generate IDSecretHash as a hash of IDTrapdoor and IDNullifier
|
187
|
+
const combinedBytes = new Uint8Array([...idTrapdoor, ...idNullifier]);
|
188
|
+
const idSecretHash = sha256(combinedBytes);
|
189
|
+
// Generate IDCommitment as a hash of IDSecretHash
|
190
|
+
const idCommitment = sha256(idSecretHash);
|
191
|
+
// Convert IDCommitment to BigInt
|
192
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
|
193
|
+
log.info("Successfully generated identity credential");
|
194
|
+
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
195
|
+
}
|
196
|
+
}
|
197
|
+
//# sourceMappingURL=credentials_manager.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"credentials_manager.js","sourceRoot":"","sources":["../src/credentials_manager.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,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAO/C,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAE3C;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IACtB,OAAO,GAAG,KAAK,CAAC;IAChB,QAAQ,GAAG,KAAK,CAAC;IAEpB,QAAQ,CAA8B;IACtC,MAAM,CAA4B;IAE/B,QAAQ,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;IAChC,WAAW,CAAmC;IAE9C,OAAO,CAAsB;IAEpC,YAAmB,OAAiB;QAClC,GAAG,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;QAC9C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACjC,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,UAA2B,EAAE;QAC9C,IAAI,IAAI,CA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,CAAC;QAE1C,iCAAiC;QACjC,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,YAAY,CAAC,CAAC;QAEnE,GAAG,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;QACvD,OAAO,IAAI,kBAAkB,CAC3B,UAAU,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,kBAAkB,CACnB,CAAC;IACJ,CAAC;CACF"}
|
package/dist/identity.d.ts
CHANGED
@@ -6,5 +6,4 @@ export declare class IdentityCredential {
|
|
6
6
|
readonly IDCommitmentBigInt: bigint;
|
7
7
|
constructor(IDTrapdoor: Uint8Array, IDNullifier: Uint8Array, IDSecretHash: Uint8Array, IDCommitment: Uint8Array, IDCommitmentBigInt: bigint);
|
8
8
|
static fromBytes(memKeys: Uint8Array): IdentityCredential;
|
9
|
-
toJSON(): [number[], number[], number[], number[], string];
|
10
9
|
}
|
package/dist/identity.js
CHANGED
@@ -23,14 +23,5 @@ export class IdentityCredential {
|
|
23
23
|
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
|
24
24
|
return new IdentityCredential(idTrapdoor, idNullifier, idSecretHash, idCommitment, idCommitmentBigInt);
|
25
25
|
}
|
26
|
-
toJSON() {
|
27
|
-
return [
|
28
|
-
Array.from(this.IDTrapdoor),
|
29
|
-
Array.from(this.IDNullifier),
|
30
|
-
Array.from(this.IDSecretHash),
|
31
|
-
Array.from(this.IDCommitment),
|
32
|
-
this.IDCommitmentBigInt.toString()
|
33
|
-
];
|
34
|
-
}
|
35
26
|
}
|
36
27
|
//# sourceMappingURL=identity.js.map
|
package/dist/identity.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAE7D,MAAM,OAAO,kBAAkB;IAEX;IACA;IACA;IACA;IACA;IALlB,YACkB,UAAsB,EACtB,WAAuB,EACv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,GAAZ,YAAY,CAAY;QACxB,uBAAkB,GAAlB,kBAAkB,CAAQ;IACzC,CAAC;IAEG,MAAM,CAAC,SAAS,CAAC,OAAmB;QACzC,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACzE,CAAC;QAED,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC3C,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC7C,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9C,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QAC/C,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QAEvE,OAAO,IAAI,kBAAkB,CAC3B,UAAU,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,kBAAkB,CACnB,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
2
2
|
import { RLN_ABI } from "./contract/abi.js";
|
3
3
|
import { LINEA_CONTRACT, RLNContract } from "./contract/index.js";
|
4
|
-
import {
|
4
|
+
import { RLNBaseContract } from "./contract/rln_base_contract.js";
|
5
5
|
import { createRLN } from "./create.js";
|
6
|
+
import { RLNCredentialsManager } from "./credentials_manager.js";
|
6
7
|
import { IdentityCredential } from "./identity.js";
|
7
8
|
import { Keystore } from "./keystore/index.js";
|
8
9
|
import { Proof } from "./proof.js";
|
9
10
|
import { RLNInstance } from "./rln.js";
|
10
|
-
import { RLNLightInstance } from "./rln_light.js";
|
11
11
|
import { MerkleRootTracker } from "./root_tracker.js";
|
12
12
|
import { extractMetaMaskSigner } from "./utils/index.js";
|
13
|
-
export {
|
13
|
+
export { RLNCredentialsManager, RLNBaseContract, createRLN, Keystore, RLNInstance, IdentityCredential, Proof, RLNEncoder, RLNDecoder, MerkleRootTracker, RLNContract, LINEA_CONTRACT, extractMetaMaskSigner, RLN_ABI };
|
14
14
|
export type { DecryptedCredentials, EncryptedCredentials, Keccak256Hash, KeystoreEntity, MembershipHash, MembershipInfo, Password, Sha256Hash } from "./keystore/types.js";
|
package/dist/index.js
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
2
2
|
import { RLN_ABI } from "./contract/abi.js";
|
3
3
|
import { LINEA_CONTRACT, RLNContract } from "./contract/index.js";
|
4
|
-
import {
|
4
|
+
import { RLNBaseContract } from "./contract/rln_base_contract.js";
|
5
5
|
import { createRLN } from "./create.js";
|
6
|
+
import { RLNCredentialsManager } from "./credentials_manager.js";
|
6
7
|
import { IdentityCredential } from "./identity.js";
|
7
8
|
import { Keystore } from "./keystore/index.js";
|
8
9
|
import { Proof } from "./proof.js";
|
9
10
|
import { RLNInstance } from "./rln.js";
|
10
|
-
import { RLNLightInstance } from "./rln_light.js";
|
11
11
|
import { MerkleRootTracker } from "./root_tracker.js";
|
12
12
|
import { extractMetaMaskSigner } from "./utils/index.js";
|
13
|
-
export {
|
13
|
+
export { RLNCredentialsManager, RLNBaseContract, createRLN, Keystore, RLNInstance, IdentityCredential, Proof, RLNEncoder, RLNDecoder, MerkleRootTracker, RLNContract, LINEA_CONTRACT, extractMetaMaskSigner, RLN_ABI };
|
14
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,SAAS,EACT,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,KAAK,EACL,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,OAAO,EACR,CAAC"}
|
@@ -43,6 +43,7 @@ export declare class Keystore {
|
|
43
43
|
private static fromCredentialToEip;
|
44
44
|
private static fromEipToCredential;
|
45
45
|
private static fromBytesToIdentity;
|
46
|
+
private static fromArraylikeToBytes;
|
46
47
|
private static computeMembershipHash;
|
47
48
|
private static fromIdentityToBytes;
|
48
49
|
}
|
@@ -4,7 +4,6 @@ import { sha256 } from "ethereum-cryptography/sha256";
|
|
4
4
|
import { bytesToHex, bytesToUtf8, utf8ToBytes } from "ethereum-cryptography/utils";
|
5
5
|
import _ from "lodash";
|
6
6
|
import { v4 as uuidV4 } from "uuid";
|
7
|
-
import { IdentityCredential } from "../identity.js";
|
8
7
|
import { buildBigIntFromUint8Array } from "../utils/bytes.js";
|
9
8
|
import { decryptEipKeystore, keccak256Checksum } from "./cipher.js";
|
10
9
|
import { isCredentialValid, isKeystoreValid } from "./schema_validator.js";
|
@@ -148,20 +147,20 @@ export class Keystore {
|
|
148
147
|
try {
|
149
148
|
const str = bytesToUtf8(bytes);
|
150
149
|
const obj = JSON.parse(str);
|
151
|
-
//
|
152
|
-
const { idTrapdoor, idNullifier, idSecretHash, idCommitment } = _.get(obj, "identityCredential", {});
|
153
|
-
const idTrapdoorArray = new Uint8Array(idTrapdoor || []);
|
154
|
-
const idNullifierArray = new Uint8Array(idNullifier || []);
|
155
|
-
const idSecretHashArray = new Uint8Array(idSecretHash || []);
|
156
|
-
const idCommitmentArray = new Uint8Array(idCommitment || []);
|
157
|
-
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitmentArray);
|
150
|
+
// TODO: add runtime validation of nwaku credentials
|
158
151
|
return {
|
159
|
-
identity:
|
152
|
+
identity: {
|
153
|
+
IDCommitment: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", [])),
|
154
|
+
IDTrapdoor: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idTrapdoor", [])),
|
155
|
+
IDNullifier: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idNullifier", [])),
|
156
|
+
IDCommitmentBigInt: buildBigIntFromUint8Array(Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idCommitment", []))),
|
157
|
+
IDSecretHash: Keystore.fromArraylikeToBytes(_.get(obj, "identityCredential.idSecretHash", []))
|
158
|
+
},
|
160
159
|
membership: {
|
161
160
|
treeIndex: _.get(obj, "treeIndex"),
|
162
161
|
chainId: _.get(obj, "membershipContract.chainId"),
|
163
162
|
address: _.get(obj, "membershipContract.address"),
|
164
|
-
rateLimit: _.get(obj, "
|
163
|
+
rateLimit: _.get(obj, "userMessageLimit")
|
165
164
|
}
|
166
165
|
};
|
167
166
|
}
|
@@ -170,6 +169,20 @@ export class Keystore {
|
|
170
169
|
return;
|
171
170
|
}
|
172
171
|
}
|
172
|
+
static fromArraylikeToBytes(obj) {
|
173
|
+
if (Array.isArray(obj)) {
|
174
|
+
return new Uint8Array(obj);
|
175
|
+
}
|
176
|
+
const bytes = [];
|
177
|
+
let index = 0;
|
178
|
+
let lastElement = obj[index];
|
179
|
+
while (lastElement !== undefined) {
|
180
|
+
bytes.push(lastElement);
|
181
|
+
index += 1;
|
182
|
+
lastElement = obj[index];
|
183
|
+
}
|
184
|
+
return new Uint8Array(bytes);
|
185
|
+
}
|
173
186
|
// follows nwaku implementation
|
174
187
|
// https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
|
175
188
|
static computeMembershipHash(info) {
|
@@ -181,15 +194,16 @@ export class Keystore {
|
|
181
194
|
return utf8ToBytes(JSON.stringify({
|
182
195
|
treeIndex: options.membership.treeIndex,
|
183
196
|
identityCredential: {
|
184
|
-
|
197
|
+
idCommitment: Array.from(options.identity.IDCommitment),
|
185
198
|
idNullifier: Array.from(options.identity.IDNullifier),
|
186
199
|
idSecretHash: Array.from(options.identity.IDSecretHash),
|
187
|
-
|
200
|
+
idTrapdoor: Array.from(options.identity.IDTrapdoor)
|
188
201
|
},
|
189
202
|
membershipContract: {
|
190
203
|
chainId: options.membership.chainId,
|
191
204
|
address: options.membership.address
|
192
|
-
}
|
205
|
+
},
|
206
|
+
userMessageLimit: options.membership.rateLimit
|
193
207
|
}));
|
194
208
|
}
|
195
209
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"keystore.js","sourceRoot":"","sources":["../../src/keystore/keystore.ts"],"names":[],"m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AW,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CACvE,CAAC,WAAW,EAAE,CAAC;IAClB,CAAC;IAED,+BAA+B;IAC/B,4HAA4H;IACpH,MAAM,CAAC,mBAAmB,CAAC,OAAuB;QACxD,OAAO,WAAW,CAChB,IAAI,CAAC,SAAS,CAAC;YACb,SAAS,EAAE,OAAO,CAAC,UAAU,CAAC,SAAS;YACvC,kBAAkB,EAAE;gBAClB,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;gBACvD,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;gBACrD,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;gBACvD,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;aACpD;YACD,kBAAkB,EAAE;gBAClB,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO;gBACnC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO;aACpC;YACD,gBAAgB,EAAE,OAAO,CAAC,UAAU,CAAC,SAAS;SAC/C,CAAC,CACH,CAAC;IACJ,CAAC;CACF"}
|
package/dist/rln.d.ts
CHANGED
@@ -1,66 +1,23 @@
|
|
1
1
|
import type { ContentTopic, IDecodedMessage, EncoderOptions as WakuEncoderOptions } from "@waku/interfaces";
|
2
|
-
import { ethers } from "ethers";
|
3
2
|
import { type RLNDecoder, type RLNEncoder } from "./codec.js";
|
4
|
-
import {
|
5
|
-
import { IdentityCredential } from "./identity.js";
|
3
|
+
import { RLNCredentialsManager } from "./credentials_manager.js";
|
6
4
|
import type { DecryptedCredentials, EncryptedCredentials } from "./keystore/index.js";
|
7
|
-
import {
|
5
|
+
import { WitnessCalculator } from "./resources/witness_calculator";
|
8
6
|
import { Zerokit } from "./zerokit.js";
|
9
|
-
/**
|
10
|
-
* Create an instance of RLN
|
11
|
-
* @returns RLNInstance
|
12
|
-
*/
|
13
|
-
export declare function create(): Promise<RLNInstance>;
|
14
|
-
type StartRLNOptions = {
|
15
|
-
/**
|
16
|
-
* If not set - will extract MetaMask account and get signer from it.
|
17
|
-
*/
|
18
|
-
signer?: ethers.Signer;
|
19
|
-
/**
|
20
|
-
* If not set - will use default LINEA_CONTRACT address.
|
21
|
-
*/
|
22
|
-
address?: string;
|
23
|
-
/**
|
24
|
-
* Credentials to use for generating proofs and connecting to the contract and network.
|
25
|
-
* If provided used for validating the network chainId and connecting to registry contract.
|
26
|
-
*/
|
27
|
-
credentials?: EncryptedCredentials | DecryptedCredentials;
|
28
|
-
/**
|
29
|
-
* Rate limit for the member.
|
30
|
-
*/
|
31
|
-
rateLimit?: number;
|
32
|
-
};
|
33
|
-
type RegisterMembershipOptions = {
|
34
|
-
signature: string;
|
35
|
-
} | {
|
36
|
-
identity: IdentityCredential;
|
37
|
-
};
|
38
7
|
type WakuRLNEncoderOptions = WakuEncoderOptions & {
|
39
8
|
credentials: EncryptedCredentials | DecryptedCredentials;
|
40
9
|
};
|
41
|
-
export declare class RLNInstance {
|
10
|
+
export declare class RLNInstance extends RLNCredentialsManager {
|
42
11
|
zerokit: Zerokit;
|
43
|
-
private started;
|
44
|
-
private starting;
|
45
|
-
private _contract;
|
46
|
-
private _signer;
|
47
|
-
private keystore;
|
48
|
-
private _credentials;
|
49
|
-
constructor(zerokit: Zerokit);
|
50
|
-
get contract(): undefined | RLNContract;
|
51
|
-
get signer(): undefined | ethers.Signer;
|
52
|
-
start(options?: StartRLNOptions): Promise<void>;
|
53
|
-
private determineStartOptions;
|
54
|
-
private static decryptCredentialsIfNeeded;
|
55
|
-
registerMembership(options: RegisterMembershipOptions): Promise<undefined | DecryptedCredentials>;
|
56
12
|
/**
|
57
|
-
*
|
58
|
-
* @
|
59
|
-
* @param password: string or bytes to use to decrypt credentials from Keystore
|
13
|
+
* Create an instance of RLN
|
14
|
+
* @returns RLNInstance
|
60
15
|
*/
|
61
|
-
|
16
|
+
static create(): Promise<RLNInstance>;
|
17
|
+
private constructor();
|
62
18
|
createEncoder(options: WakuRLNEncoderOptions): Promise<RLNEncoder>;
|
63
|
-
private verifyCredentialsAgainstContract;
|
64
19
|
createDecoder(contentTopic: ContentTopic): RLNDecoder<IDecodedMessage>;
|
20
|
+
static loadWitnessCalculator(): Promise<WitnessCalculator>;
|
21
|
+
static loadZkey(): Promise<Uint8Array>;
|
65
22
|
}
|
66
23
|
export {};
|