@waku/rln 0.1.1 → 0.1.2-6454446
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 +26 -2
- package/bundle/assets/rln_wasm_bg-a503e304.wasm +0 -0
- package/bundle/index.js +58406 -10987
- package/dist/codec.d.ts +7 -4
- package/dist/codec.js +15 -5
- package/dist/codec.js.map +1 -1
- package/dist/{constants.d.ts → contract/constants.d.ts} +2 -2
- package/dist/contract/constants.js +67 -0
- package/dist/contract/constants.js.map +1 -0
- package/dist/contract/index.d.ts +2 -0
- package/dist/contract/index.js +3 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/rln_contract.d.ts +46 -0
- package/dist/contract/rln_contract.js +213 -0
- package/dist/contract/rln_contract.js.map +1 -0
- package/dist/create.d.ts +2 -0
- package/dist/create.js +8 -0
- package/dist/create.js.map +1 -0
- package/dist/identity.d.ts +9 -0
- package/dist/identity.js +24 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.js +9 -12
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.d.ts +4 -0
- package/dist/keystore/cipher.js +28 -0
- package/dist/keystore/cipher.js.map +1 -0
- package/dist/keystore/credential_validation_generated.d.ts +8 -0
- package/dist/keystore/credential_validation_generated.js +121 -0
- package/dist/keystore/credential_validation_generated.js.map +1 -0
- package/dist/keystore/index.d.ts +4 -0
- package/dist/keystore/index.js +3 -0
- package/dist/keystore/index.js.map +1 -0
- package/dist/keystore/keystore.d.ts +50 -0
- package/dist/keystore/keystore.js +205 -0
- package/dist/keystore/keystore.js.map +1 -0
- package/dist/keystore/keystore_validation_generated.d.ts +8 -0
- package/dist/keystore/keystore_validation_generated.js +75 -0
- package/dist/keystore/keystore_validation_generated.js.map +1 -0
- package/dist/keystore/schema_validator.d.ts +2 -0
- package/dist/keystore/schema_validator.js +18 -0
- package/dist/keystore/schema_validator.js.map +1 -0
- package/dist/keystore/types.d.ts +29 -0
- package/dist/keystore/types.js +2 -0
- package/dist/keystore/types.js.map +1 -0
- package/dist/message.d.ts +2 -1
- package/dist/message.js +10 -4
- package/dist/message.js.map +1 -1
- package/dist/proof.d.ts +21 -0
- package/dist/proof.js +49 -0
- package/dist/proof.js.map +1 -0
- package/dist/resources/verification_key.d.ts +9 -9
- package/dist/resources/witness_calculator.js.map +1 -0
- package/dist/rln.d.ts +55 -46
- package/dist/rln.js +136 -183
- package/dist/rln.js.map +1 -1
- package/dist/root_tracker.js +5 -2
- package/dist/root_tracker.js.map +1 -1
- package/dist/utils/bytes.d.ts +20 -0
- package/dist/utils/bytes.js +64 -0
- package/dist/utils/bytes.js.map +1 -0
- package/dist/utils/epoch.js.map +1 -0
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +13 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/metamask.d.ts +2 -0
- package/dist/utils/metamask.js +12 -0
- package/dist/utils/metamask.js.map +1 -0
- package/dist/zerokit.d.ts +19 -0
- package/dist/zerokit.js +105 -0
- package/dist/zerokit.js.map +1 -0
- package/package.json +38 -28
- package/src/codec.ts +18 -9
- package/src/create.ts +9 -0
- package/src/identity.ts +27 -0
- package/src/index.ts +16 -18
- package/src/message.ts +9 -5
- package/src/proof.ts +67 -0
- package/src/rln.ts +220 -270
- package/src/root_tracker.ts +4 -1
- package/src/zerokit.ts +181 -0
- package/bundle/assets/rln_wasm_bg-6f96f821.wasm +0 -0
- package/dist/.tsbuildinfo +0 -1
- package/dist/byte_utils.d.ts +0 -1
- package/dist/byte_utils.js +0 -24
- package/dist/byte_utils.js.map +0 -1
- package/dist/constants.js +0 -14
- package/dist/constants.js.map +0 -1
- package/dist/epoch.js.map +0 -1
- package/dist/rln_contract.d.ts +0 -34
- package/dist/rln_contract.js +0 -159
- package/dist/rln_contract.js.map +0 -1
- package/dist/witness_calculator.js.map +0 -1
- package/src/byte_utils.ts +0 -39
- package/src/constants.ts +0 -14
- package/src/epoch.ts +0 -30
- package/src/rln_contract.ts +0 -268
- package/src/witness_calculator.d.ts +0 -8
- package/src/witness_calculator.js +0 -335
- /package/dist/{witness_calculator.d.ts → resources/witness_calculator.d.ts} +0 -0
- /package/dist/{witness_calculator.js → resources/witness_calculator.js} +0 -0
- /package/dist/{epoch.d.ts → utils/epoch.d.ts} +0 -0
- /package/dist/{epoch.js → utils/epoch.js} +0 -0
package/src/identity.ts
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
import { buildBigIntFromUint8Array } from "./utils/index.js";
|
2
|
+
|
3
|
+
export class IdentityCredential {
|
4
|
+
constructor(
|
5
|
+
public readonly IDTrapdoor: Uint8Array,
|
6
|
+
public readonly IDNullifier: Uint8Array,
|
7
|
+
public readonly IDSecretHash: Uint8Array,
|
8
|
+
public readonly IDCommitment: Uint8Array,
|
9
|
+
public readonly IDCommitmentBigInt: bigint
|
10
|
+
) {}
|
11
|
+
|
12
|
+
static fromBytes(memKeys: Uint8Array): IdentityCredential {
|
13
|
+
const idTrapdoor = memKeys.subarray(0, 32);
|
14
|
+
const idNullifier = memKeys.subarray(32, 64);
|
15
|
+
const idSecretHash = memKeys.subarray(64, 96);
|
16
|
+
const idCommitment = memKeys.subarray(96);
|
17
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment);
|
18
|
+
|
19
|
+
return new IdentityCredential(
|
20
|
+
idTrapdoor,
|
21
|
+
idNullifier,
|
22
|
+
idSecretHash,
|
23
|
+
idCommitment,
|
24
|
+
idCommitmentBigInt
|
25
|
+
);
|
26
|
+
}
|
27
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,32 +1,30 @@
|
|
1
1
|
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
2
|
-
import { RLN_ABI, SEPOLIA_CONTRACT } from "./constants.js";
|
3
2
|
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
} from "./
|
9
|
-
import {
|
3
|
+
RLN_REGISTRY_ABI,
|
4
|
+
RLN_STORAGE_ABI,
|
5
|
+
SEPOLIA_CONTRACT
|
6
|
+
} from "./contract/index.js";
|
7
|
+
import { RLNContract } from "./contract/index.js";
|
8
|
+
import { createRLN } from "./create.js";
|
9
|
+
import { IdentityCredential } from "./identity.js";
|
10
|
+
import { Keystore } from "./keystore/index.js";
|
11
|
+
import { Proof } from "./proof.js";
|
12
|
+
import { RLNInstance } from "./rln.js";
|
10
13
|
import { MerkleRootTracker } from "./root_tracker.js";
|
11
|
-
|
12
|
-
// reexport the create function, dynamically imported from rln.ts
|
13
|
-
export async function create(): Promise<RLNInstance> {
|
14
|
-
// A dependency graph that contains any wasm must all be imported
|
15
|
-
// asynchronously. This file does the single async import, so
|
16
|
-
// that no one else needs to worry about it again.
|
17
|
-
const rlnModule = await import("./rln.js");
|
18
|
-
return await rlnModule.create();
|
19
|
-
}
|
14
|
+
import { extractMetaMaskSigner } from "./utils/index.js";
|
20
15
|
|
21
16
|
export {
|
17
|
+
createRLN,
|
18
|
+
Keystore,
|
22
19
|
RLNInstance,
|
23
20
|
IdentityCredential,
|
24
21
|
Proof,
|
25
|
-
ProofMetadata,
|
26
22
|
RLNEncoder,
|
27
23
|
RLNDecoder,
|
28
24
|
MerkleRootTracker,
|
29
25
|
RLNContract,
|
30
|
-
|
26
|
+
RLN_STORAGE_ABI,
|
27
|
+
RLN_REGISTRY_ABI,
|
31
28
|
SEPOLIA_CONTRACT,
|
29
|
+
extractMetaMaskSigner
|
32
30
|
};
|
package/src/message.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import type {
|
2
2
|
IDecodedMessage,
|
3
3
|
IMessage,
|
4
|
-
IRateLimitProof
|
4
|
+
IRateLimitProof
|
5
5
|
} from "@waku/interfaces";
|
6
6
|
import * as utils from "@waku/utils/bytes";
|
7
7
|
|
8
|
-
import { epochBytesToInt } from "./epoch.js";
|
9
8
|
import { RLNInstance } from "./rln.js";
|
9
|
+
import { epochBytesToInt } from "./utils/index.js";
|
10
10
|
|
11
11
|
export function toRLNSignal(contentTopic: string, msg: IMessage): Uint8Array {
|
12
12
|
const contentTopicBytes = utils.utf8ToBytes(contentTopic ?? "");
|
@@ -14,7 +14,7 @@ export function toRLNSignal(contentTopic: string, msg: IMessage): Uint8Array {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
|
17
|
-
public
|
17
|
+
public pubsubTopic = "";
|
18
18
|
|
19
19
|
constructor(
|
20
20
|
public rlnInstance: RLNInstance,
|
@@ -24,7 +24,7 @@ export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
|
|
24
24
|
|
25
25
|
public verify(roots: Uint8Array[]): boolean | undefined {
|
26
26
|
return this.rateLimitProof
|
27
|
-
? this.rlnInstance.verifyWithRoots(
|
27
|
+
? this.rlnInstance.zerokit.verifyWithRoots(
|
28
28
|
this.rateLimitProof,
|
29
29
|
toRLNSignal(this.msg.contentTopic, this.msg),
|
30
30
|
...roots
|
@@ -34,7 +34,7 @@ export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
|
|
34
34
|
|
35
35
|
public verifyNoRoot(): boolean | undefined {
|
36
36
|
return this.rateLimitProof
|
37
|
-
? this.rlnInstance.verifyWithNoRoot(
|
37
|
+
? this.rlnInstance.zerokit.verifyWithNoRoot(
|
38
38
|
this.rateLimitProof,
|
39
39
|
toRLNSignal(this.msg.contentTopic, this.msg)
|
40
40
|
) // this.rlnInstance.verifyRLNProof once issue status-im/nwaku#1248 is fixed
|
@@ -57,6 +57,10 @@ export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
|
|
57
57
|
return this.msg.ephemeral;
|
58
58
|
}
|
59
59
|
|
60
|
+
get meta(): Uint8Array | undefined {
|
61
|
+
return this.msg.meta;
|
62
|
+
}
|
63
|
+
|
60
64
|
get epoch(): number | undefined {
|
61
65
|
const bytes = this.msg.rateLimitProof?.epoch;
|
62
66
|
if (!bytes) return;
|
package/src/proof.ts
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
import type { IRateLimitProof } from "@waku/interfaces";
|
2
|
+
|
3
|
+
import { concatenate, poseidonHash } from "./utils/index.js";
|
4
|
+
|
5
|
+
const proofOffset = 128;
|
6
|
+
const rootOffset = proofOffset + 32;
|
7
|
+
const epochOffset = rootOffset + 32;
|
8
|
+
const shareXOffset = epochOffset + 32;
|
9
|
+
const shareYOffset = shareXOffset + 32;
|
10
|
+
const nullifierOffset = shareYOffset + 32;
|
11
|
+
const rlnIdentifierOffset = nullifierOffset + 32;
|
12
|
+
|
13
|
+
class ProofMetadata {
|
14
|
+
constructor(
|
15
|
+
public readonly nullifier: Uint8Array,
|
16
|
+
public readonly shareX: Uint8Array,
|
17
|
+
public readonly shareY: Uint8Array,
|
18
|
+
public readonly externalNullifier: Uint8Array
|
19
|
+
) {}
|
20
|
+
}
|
21
|
+
|
22
|
+
export class Proof implements IRateLimitProof {
|
23
|
+
readonly proof: Uint8Array;
|
24
|
+
readonly merkleRoot: Uint8Array;
|
25
|
+
readonly epoch: Uint8Array;
|
26
|
+
readonly shareX: Uint8Array;
|
27
|
+
readonly shareY: Uint8Array;
|
28
|
+
readonly nullifier: Uint8Array;
|
29
|
+
readonly rlnIdentifier: Uint8Array;
|
30
|
+
|
31
|
+
constructor(proofBytes: Uint8Array) {
|
32
|
+
if (proofBytes.length < rlnIdentifierOffset) throw "invalid proof";
|
33
|
+
// parse the proof as proof<128> | share_y<32> | nullifier<32> | root<32> | epoch<32> | share_x<32> | rln_identifier<32>
|
34
|
+
this.proof = proofBytes.subarray(0, proofOffset);
|
35
|
+
this.merkleRoot = proofBytes.subarray(proofOffset, rootOffset);
|
36
|
+
this.epoch = proofBytes.subarray(rootOffset, epochOffset);
|
37
|
+
this.shareX = proofBytes.subarray(epochOffset, shareXOffset);
|
38
|
+
this.shareY = proofBytes.subarray(shareXOffset, shareYOffset);
|
39
|
+
this.nullifier = proofBytes.subarray(shareYOffset, nullifierOffset);
|
40
|
+
this.rlnIdentifier = proofBytes.subarray(
|
41
|
+
nullifierOffset,
|
42
|
+
rlnIdentifierOffset
|
43
|
+
);
|
44
|
+
}
|
45
|
+
|
46
|
+
extractMetadata(): ProofMetadata {
|
47
|
+
const externalNullifier = poseidonHash(this.epoch, this.rlnIdentifier);
|
48
|
+
return new ProofMetadata(
|
49
|
+
this.nullifier,
|
50
|
+
this.shareX,
|
51
|
+
this.shareY,
|
52
|
+
externalNullifier
|
53
|
+
);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
export function proofToBytes(p: IRateLimitProof): Uint8Array {
|
58
|
+
return concatenate(
|
59
|
+
p.proof,
|
60
|
+
p.merkleRoot,
|
61
|
+
p.epoch,
|
62
|
+
p.shareX,
|
63
|
+
p.shareY,
|
64
|
+
p.nullifier,
|
65
|
+
p.rlnIdentifier
|
66
|
+
);
|
67
|
+
}
|