mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-08-09 19:43:16 +00:00
* chore: idCommitmentBigInt validates against contract Q * chore: fix linting * chore: add log * chore: rename Q and make sync * fix: test * chore: remove stubbed contract test * chore: hardcode default constant for Q * use non deprecated sha256 * chore: use full 32 bytes for bigint * chore: all storage in LE, but smart contract interactions in BE * chore: remove references to idCOmmitmentBigInt in Identity * chore: don't fetch Q from contract * chore: ByteUtils as a class * chore: store Identity in BE, convert during Keystore * chore: add IDCommitmentBigInt part of Identity * chore: minor improvements * chore: switch idTrapdoor to LE * chore: add logs * chore: rename `DEFAULT_Q` to `RLN_Q` * chore: rm spec test * chore: improve modulo logging * fix(tests): add IDCommitmentBigInt
36 lines
993 B
TypeScript
36 lines
993 B
TypeScript
import { BytesUtils } from "./utils/bytes.js";
|
|
|
|
export class IdentityCredential {
|
|
public IDCommitmentBigInt: bigint;
|
|
/**
|
|
* All variables are in little-endian format
|
|
*/
|
|
public constructor(
|
|
public readonly IDTrapdoor: Uint8Array,
|
|
public readonly IDNullifier: Uint8Array,
|
|
public readonly IDSecretHash: Uint8Array,
|
|
public readonly IDCommitment: Uint8Array
|
|
) {
|
|
this.IDCommitmentBigInt =
|
|
BytesUtils.buildBigIntFromUint8ArrayBE(IDCommitment);
|
|
}
|
|
|
|
public static fromBytes(memKeys: Uint8Array): IdentityCredential {
|
|
if (memKeys.length < 128) {
|
|
throw new Error("Invalid memKeys length - must be at least 128 bytes");
|
|
}
|
|
|
|
const idTrapdoor = memKeys.subarray(0, 32);
|
|
const idNullifier = memKeys.subarray(32, 64);
|
|
const idSecretHash = memKeys.subarray(64, 96);
|
|
const idCommitment = memKeys.subarray(96, 128);
|
|
|
|
return new IdentityCredential(
|
|
idTrapdoor,
|
|
idNullifier,
|
|
idSecretHash,
|
|
idCommitment
|
|
);
|
|
}
|
|
}
|