mirror of
https://github.com/logos-messaging/js-rln.git
synced 2026-01-02 13:43:06 +00:00
decouple utils, remove global variables
This commit is contained in:
parent
e1679b6bd9
commit
603a99b008
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@waku/rln",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@waku/rln",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@chainsafe/bls-keystore": "^3.0.0",
|
||||
|
||||
1
src/contract/index.ts
Normal file
1
src/contract/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export { RLNContract } from "./rln_contract.js";
|
||||
@ -4,17 +4,17 @@ import {
|
||||
RLN_STORAGE_ABI,
|
||||
SEPOLIA_CONTRACT,
|
||||
} from "./constants.js";
|
||||
import { RLNContract } from "./contract/index.js";
|
||||
import { createRLN } from "./create.js";
|
||||
import { Keystore } from "./keystore/index.js";
|
||||
import { extractMetaMaskSigner } from "./metamask.js";
|
||||
import {
|
||||
IdentityCredential,
|
||||
Proof,
|
||||
ProofMetadata,
|
||||
RLNInstance,
|
||||
} from "./rln.js";
|
||||
import { RLNContract } from "./rln_contract.js";
|
||||
import { MerkleRootTracker } from "./root_tracker.js";
|
||||
import { extractMetaMaskSigner } from "./utils/index.js";
|
||||
|
||||
export {
|
||||
createRLN,
|
||||
|
||||
34
src/rln.ts
34
src/rln.ts
@ -13,6 +13,7 @@ import { buildBigIntFromUint8Array, writeUIntLE } from "./byte_utils.js";
|
||||
import type { RLNDecoder, RLNEncoder } from "./codec.js";
|
||||
import { createRLNDecoder, createRLNEncoder } from "./codec.js";
|
||||
import { SEPOLIA_CONTRACT } from "./constants.js";
|
||||
import { RLNContract } from "./contract/index.js";
|
||||
import { dateToEpoch, epochIntToBytes } from "./epoch.js";
|
||||
import { Keystore } from "./keystore/index.js";
|
||||
import type {
|
||||
@ -20,35 +21,11 @@ import type {
|
||||
EncryptedCredentials,
|
||||
} from "./keystore/index.js";
|
||||
import { KeystoreEntity, Password } from "./keystore/types.js";
|
||||
import { extractMetaMaskSigner } from "./metamask.js";
|
||||
import verificationKey from "./resources/verification_key.js";
|
||||
import { RLNContract } from "./rln_contract.js";
|
||||
import { concatenate, extractMetaMaskSigner } from "./utils/index.js";
|
||||
import * as wc from "./witness_calculator.js";
|
||||
import { WitnessCalculator } from "./witness_calculator.js";
|
||||
|
||||
/**
|
||||
* Concatenate Uint8Arrays
|
||||
* @param input
|
||||
* @returns concatenation of all Uint8Array received as input
|
||||
*/
|
||||
function concatenate(...input: Uint8Array[]): Uint8Array {
|
||||
let totalLength = 0;
|
||||
for (const arr of input) {
|
||||
totalLength += arr.length;
|
||||
}
|
||||
const result = new Uint8Array(totalLength);
|
||||
let offset = 0;
|
||||
for (const arr of input) {
|
||||
result.set(arr, offset);
|
||||
offset += arr.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const stringEncoder = new TextEncoder();
|
||||
|
||||
const DEPTH = 20;
|
||||
|
||||
async function loadWitnessCalculator(): Promise<WitnessCalculator> {
|
||||
const url = new URL("./resources/rln.wasm", import.meta.url);
|
||||
const response = await fetch(url);
|
||||
@ -68,10 +45,16 @@ async function loadZkey(): Promise<Uint8Array> {
|
||||
export async function create(): Promise<RLNInstance> {
|
||||
await (init as any)?.();
|
||||
zerokitRLN.init_panic_hook();
|
||||
|
||||
const witnessCalculator = await loadWitnessCalculator();
|
||||
const zkey = await loadZkey();
|
||||
|
||||
const stringEncoder = new TextEncoder();
|
||||
const vkey = stringEncoder.encode(JSON.stringify(verificationKey));
|
||||
|
||||
const DEPTH = 20;
|
||||
const zkRLN = zerokitRLN.newRLN(DEPTH, zkey, vkey);
|
||||
|
||||
return new RLNInstance(zkRLN, witnessCalculator);
|
||||
}
|
||||
|
||||
@ -405,6 +388,7 @@ export class RLNInstance {
|
||||
}
|
||||
|
||||
generateSeededIdentityCredential(seed: string): IdentityCredential {
|
||||
const stringEncoder = new TextEncoder();
|
||||
const seedBytes = stringEncoder.encode(seed);
|
||||
// TODO: rename this function in zerokit rln-wasm
|
||||
const memKeys = zerokitRLN.generateSeededExtendedMembershipKey(
|
||||
|
||||
18
src/utils/bytes.ts
Normal file
18
src/utils/bytes.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Concatenate Uint8Arrays
|
||||
* @param input
|
||||
* @returns concatenation of all Uint8Array received as input
|
||||
*/
|
||||
export function concatenate(...input: Uint8Array[]): Uint8Array {
|
||||
let totalLength = 0;
|
||||
for (const arr of input) {
|
||||
totalLength += arr.length;
|
||||
}
|
||||
const result = new Uint8Array(totalLength);
|
||||
let offset = 0;
|
||||
for (const arr of input) {
|
||||
result.set(arr, offset);
|
||||
offset += arr.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
2
src/utils/index.ts
Normal file
2
src/utils/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export { extractMetaMaskSigner } from "./metamask.js";
|
||||
export { concatenate } from "./bytes.js";
|
||||
Loading…
x
Reference in New Issue
Block a user