Draft Inverse Bloom Filter

This commit is contained in:
Jim Hamill
2025-01-20 07:47:07 +00:00
parent d6a04f4350
commit 1aebc6da42
21 changed files with 1285 additions and 381 deletions
+42 -1
View File
@@ -2,6 +2,22 @@ export type BCHUnits = ['sats', 'bits', 'mBCH', 'BCH'];
/**
* Satoshis Primitive
*
* @example
*
* ```ts
* // Import our primitives
* import { Satoshis } from '@xocash/primitives';
*
* // Create an amount from BCH.
* const sats = Satoshis.fromBCH(0.54321);
*
* // Output as a satoshi number.
* console.log(satoshis.toSats());
*
* // Output as a satoshis bigint.
* console.log(satoshis.toBigInt());
* ```
*/
export class Satoshis {
protected readonly satoshis: bigint;
@@ -81,6 +97,19 @@ export class Satoshis {
return new this(satoshis);
}
/**
* Creates an instance from serialized data.
*
* @remarks This method is UNSAFE and MUST only be used where input is already verified or trusted.
*
* @param bytes - Serialized Primitive Data
*
* @returns A new instance of this primitive.
*/
public static fromRaw(sats: bigint) {
return new this(sats);
}
/**
* Rounds a number to the given number of digits.
*
@@ -89,7 +118,10 @@ export class Satoshis {
*
* @returns {Number} The rounded number.
*/
public static roundToDigits(numberToRound: number, digits: number): number {
protected static roundToDigits(
numberToRound: number,
digits: number,
): number {
// Set the options of the Number Format object.
const options: Intl.NumberFormatOptions = {
style: 'decimal',
@@ -165,4 +197,13 @@ export class Satoshis {
public toBCH(): number {
return Satoshis.roundToDigits(Number(this.satoshis) / 100_000_000, 8);
}
/**
* Converts this primitive to a serializable raw object representation.
*
* @returns Serialzied primitive data.
*/
toRaw() {
return this.satoshis;
}
}