@xyo-network/xl1-wrappers 1.12.4 → 1.12.6

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.
Files changed (39) hide show
  1. package/dist/neutral/Address.d.ts +10 -0
  2. package/dist/neutral/Address.d.ts.map +1 -0
  3. package/dist/neutral/AddressState.d.ts +8 -0
  4. package/dist/neutral/AddressState.d.ts.map +1 -0
  5. package/dist/neutral/BlockWindow.d.ts +32 -0
  6. package/dist/neutral/BlockWindow.d.ts.map +1 -0
  7. package/dist/neutral/BlockWindowBalanceCache.d.ts +12 -0
  8. package/dist/neutral/BlockWindowBalanceCache.d.ts.map +1 -0
  9. package/dist/neutral/amount/ShiftedBigInt.d.ts +16 -0
  10. package/dist/neutral/amount/ShiftedBigInt.d.ts.map +1 -0
  11. package/dist/neutral/amount/Xl1Amount.d.ts +34 -0
  12. package/dist/neutral/amount/Xl1Amount.d.ts.map +1 -0
  13. package/dist/neutral/amount/index.d.ts +5 -0
  14. package/dist/neutral/amount/index.d.ts.map +1 -0
  15. package/dist/neutral/amount/splitOnDecimal.d.ts +2 -0
  16. package/dist/neutral/amount/splitOnDecimal.d.ts.map +1 -0
  17. package/dist/neutral/amount/splitOnDecimalToString.d.ts +2 -0
  18. package/dist/neutral/amount/splitOnDecimalToString.d.ts.map +1 -0
  19. package/dist/neutral/chain/chain.d.ts +7 -0
  20. package/dist/neutral/chain/chain.d.ts.map +1 -0
  21. package/dist/neutral/chain/index.d.ts +2 -0
  22. package/dist/neutral/chain/index.d.ts.map +1 -0
  23. package/dist/neutral/index.d.ts +2 -0
  24. package/dist/neutral/index.d.ts.map +1 -1
  25. package/dist/neutral/index.mjs +166 -3
  26. package/dist/neutral/index.mjs.map +1 -1
  27. package/package.json +4 -3
  28. package/src/Address.ts +22 -0
  29. package/src/AddressState.ts +18 -0
  30. package/src/BlockWindow.ts +43 -0
  31. package/src/BlockWindowBalanceCache.ts +20 -0
  32. package/src/amount/ShiftedBigInt.ts +72 -0
  33. package/src/amount/Xl1Amount.ts +114 -0
  34. package/src/amount/index.ts +4 -0
  35. package/src/amount/splitOnDecimal.ts +5 -0
  36. package/src/amount/splitOnDecimalToString.ts +37 -0
  37. package/src/chain/chain.ts +10 -0
  38. package/src/chain/index.ts +1 -0
  39. package/src/index.ts +2 -0
@@ -0,0 +1,10 @@
1
+ import { type Address } from '@xylabs/hex';
2
+ import type { Promisable } from '@xylabs/promise';
3
+ import type { AddressInstance } from '@xyo-network/xl1-protocol-sdk';
4
+ import { BaseWrapper } from './Base.ts';
5
+ export declare class AddressWrapper extends BaseWrapper<Address> implements AddressInstance {
6
+ get address(): Address;
7
+ static validateValue(address: unknown): Promisable<Error[]>;
8
+ validate(): Promise<Error[]>;
9
+ }
10
+ //# sourceMappingURL=Address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Address.d.ts","sourceRoot":"","sources":["../../src/Address.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAEb,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,qBAAa,cAAe,SAAQ,WAAW,CAAC,OAAO,CAAE,YAAW,eAAe;IACjF,IAAI,OAAO,IAAI,OAAO,CAErB;WAEe,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;IAIrD,QAAQ,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;CAG5C"}
@@ -0,0 +1,8 @@
1
+ import type { Promisable } from '@xylabs/promise';
2
+ import type { AddressStateInstance, BlockWindowInstance, XL1AmountInstance } from '@xyo-network/xl1-protocol-sdk';
3
+ import { AddressWrapper } from './Address.ts';
4
+ export declare class AddressStateWrapper extends AddressWrapper implements AddressStateInstance {
5
+ get blockWindow(): BlockWindowInstance;
6
+ balance(): Promisable<[XL1AmountInstance, BlockWindowInstance]>;
7
+ }
8
+ //# sourceMappingURL=AddressState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddressState.d.ts","sourceRoot":"","sources":["../../src/AddressState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,qBAAa,mBAAoB,SAAQ,cAAe,YAAW,oBAAoB;IACrF,IAAI,WAAW,IAAI,mBAAmB,CAErC;IAED,OAAO,IAAI,UAAU,CAAC,CAAC,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;CAGhE"}
@@ -0,0 +1,32 @@
1
+ import type { Hash } from '@xylabs/hex';
2
+ import type { Promisable } from '@xylabs/promise';
3
+ import type { HydratedBlock } from '@xyo-network/xl1-protocol';
4
+ import type { BlockWindowInstance } from '@xyo-network/xl1-protocol-sdk';
5
+ export interface HydratedBlockRangeStore extends BlockWindowInstance {
6
+ first(): Promisable<HydratedBlock>;
7
+ fromHash(hash: Hash): Promisable<HydratedBlock>;
8
+ fromNumber(number: number): Promisable<HydratedBlock>;
9
+ last(): Promisable<HydratedBlock>;
10
+ next(): Promisable<HydratedBlock>;
11
+ next(count: number): Promisable<HydratedBlock[]>;
12
+ prev(): Promisable<HydratedBlock>;
13
+ prev(count: number): Promisable<HydratedBlock[]>;
14
+ }
15
+ export declare class BlockWindowWrapper implements BlockWindowInstance {
16
+ private _store;
17
+ constructor(store: HydratedBlockRangeStore);
18
+ get count(): number;
19
+ get numberRange(): [number, number];
20
+ get range(): [import("@xylabs/typeof").Brand<import("@xylabs/typeof").Brand<Lowercase<string>, {
21
+ readonly __hex: true;
22
+ }>, {
23
+ readonly __hash: true;
24
+ }>, import("@xylabs/typeof").Brand<import("@xylabs/typeof").Brand<Lowercase<string>, {
25
+ readonly __hex: true;
26
+ }>, {
27
+ readonly __hash: true;
28
+ }>];
29
+ static validate(_store: HydratedBlockRangeStore): Promisable<Error[]>;
30
+ validate(): Promise<Error[]>;
31
+ }
32
+ //# sourceMappingURL=BlockWindow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlockWindow.d.ts","sourceRoot":"","sources":["../../src/BlockWindow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAExE,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;IAClE,KAAK,IAAI,UAAU,CAAC,aAAa,CAAC,CAAA;IAClC,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU,CAAC,aAAa,CAAC,CAAA;IAC/C,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,aAAa,CAAC,CAAA;IACrD,IAAI,IAAI,UAAU,CAAC,aAAa,CAAC,CAAA;IACjC,IAAI,IAAI,UAAU,CAAC,aAAa,CAAC,CAAA;IACjC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,aAAa,EAAE,CAAC,CAAA;IAChD,IAAI,IAAI,UAAU,CAAC,aAAa,CAAC,CAAA;IACjC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,aAAa,EAAE,CAAC,CAAA;CACjD;AAED,qBAAa,kBAAmB,YAAW,mBAAmB;IAC5D,OAAO,CAAC,MAAM,CAAyB;gBAE3B,KAAK,EAAE,uBAAuB;IAI1C,IAAI,KAAK,WAER;IAED,IAAI,WAAW,qBAEd;IAED,IAAI,KAAK;;;;;;;;QAER;IAED,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,uBAAuB,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;IAI/D,QAAQ,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;CAGnC"}
@@ -0,0 +1,12 @@
1
+ import type { Address } from '@xylabs/hex';
2
+ import type { Promisable } from '@xylabs/promise';
3
+ import type { HydratedBlockRangeStore } from './BlockWindow.ts';
4
+ export interface BlockWindowBalanceCacheInstance {
5
+ balance(address: Address): Promisable<bigint>;
6
+ }
7
+ export declare class BlockWindowBalanceCache implements BlockWindowBalanceCacheInstance {
8
+ private _store;
9
+ constructor(store: HydratedBlockRangeStore);
10
+ balance(_address: Address): Promisable<bigint>;
11
+ }
12
+ //# sourceMappingURL=BlockWindowBalanceCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlockWindowBalanceCache.d.ts","sourceRoot":"","sources":["../../src/BlockWindowBalanceCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAE/D,MAAM,WAAW,+BAA+B;IAC9C,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;CAC9C;AAED,qBAAa,uBAAwB,YAAW,+BAA+B;IAC7E,OAAO,CAAC,MAAM,CAAyB;gBAE3B,KAAK,EAAE,uBAAuB;IAI1C,OAAO,CAAC,QAAQ,EAAE,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC;CAG/C"}
@@ -0,0 +1,16 @@
1
+ import type { ShiftedBigIntConfig } from '@xyo-network/xl1-protocol-sdk';
2
+ export declare class ShiftedBigInt {
3
+ static readonly defaultConfig: ShiftedBigIntConfig;
4
+ config: ShiftedBigIntConfig;
5
+ value: bigint;
6
+ constructor(value: bigint | ShiftedBigInt, config?: Partial<ShiftedBigIntConfig>);
7
+ get locale(): Intl.LocalesArgument;
8
+ get maxCharacters(): number;
9
+ get maxDecimal(): number;
10
+ get minDecimals(): number;
11
+ get places(): number;
12
+ toFullString(): string;
13
+ toShortString(): string;
14
+ toString(): string;
15
+ }
16
+ //# sourceMappingURL=ShiftedBigInt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShiftedBigInt.d.ts","sourceRoot":"","sources":["../../../src/amount/ShiftedBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAIxE,qBAAa,aAAa;IACxB,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,mBAAmB,CAMjD;IAED,MAAM,EAAE,mBAAmB,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;gBAGX,KAAK,EAAE,MAAM,GAAG,aAAa,EAC7B,MAAM,GAAE,OAAO,CAAC,mBAAmB,CAAM;IAQ3C,IAAI,MAAM,IAAI,IAAI,CAAC,eAAe,CAEjC;IAED,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,YAAY,IAAI,MAAM;IAWtB,aAAa,IAAI,MAAM;IAWvB,QAAQ,IAAI,MAAM;CAGnB"}
@@ -0,0 +1,34 @@
1
+ import { AttoXL1, FemtoXL1, MicroXL1, MilliXL1, NanoXL1, PicoXL1 } from '@xyo-network/xl1-protocol';
2
+ import type { ShiftedBigIntConfig } from '@xyo-network/xl1-protocol-sdk';
3
+ export interface XL1AmountInstance {
4
+ value: AttoXL1;
5
+ to(places: bigint | number): bigint;
6
+ milli: MilliXL1;
7
+ micro: MicroXL1;
8
+ nano: NanoXL1;
9
+ pico: PicoXL1;
10
+ femto: FemtoXL1;
11
+ atto: AttoXL1;
12
+ toString(places: number, config: Partial<ShiftedBigIntConfig>): string;
13
+ }
14
+ export declare class XL1Amount implements XL1AmountInstance {
15
+ value: AttoXL1;
16
+ private locale;
17
+ constructor(value: bigint, locale?: Intl.LocalesArgument);
18
+ static from(value: bigint, places?: bigint): XL1Amount;
19
+ static fromMilli(value: MilliXL1): XL1Amount;
20
+ static fromMicro(value: MicroXL1): XL1Amount;
21
+ static fromNano(value: NanoXL1): XL1Amount;
22
+ static fromPico(value: PicoXL1): XL1Amount;
23
+ static fromFemto(value: FemtoXL1): XL1Amount;
24
+ static fromAtto(value: AttoXL1): XL1Amount;
25
+ to(places?: number | bigint): bigint;
26
+ get milli(): MilliXL1;
27
+ get micro(): MicroXL1;
28
+ get nano(): NanoXL1;
29
+ get pico(): PicoXL1;
30
+ get femto(): FemtoXL1;
31
+ get atto(): AttoXL1;
32
+ toString(places?: number, config?: Partial<ShiftedBigIntConfig>): string;
33
+ }
34
+ //# sourceMappingURL=Xl1Amount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Xl1Amount.d.ts","sourceRoot":"","sources":["../../../src/amount/Xl1Amount.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAExD,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAOxE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,OAAO,CAAA;IAEd,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;IAEnC,KAAK,EAAE,QAAQ,CAAA;IAEf,KAAK,EAAE,QAAQ,CAAA;IAEf,IAAI,EAAE,OAAO,CAAA;IAEb,IAAI,EAAE,OAAO,CAAA;IAEb,KAAK,EAAE,QAAQ,CAAA;IAEf,IAAI,EAAE,OAAO,CAAA;IAEb,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAA;CACvE;AAED,qBAAa,SAAU,YAAW,iBAAiB;IACjD,KAAK,EAAE,OAAO,CAAA;IACd,OAAO,CAAC,MAAM,CAAsB;gBAExB,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,IAAI,CAAC,eAAyB;IAKjE,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAuB;IAK1D,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ;IAIhC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ;IAIhC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO;IAI9B,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO;IAI9B,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ;IAIhC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO;IAI9B,EAAE,CAAC,MAAM,GAAE,MAAM,GAAG,MAAuB;IAI3C,IAAI,KAAK,aAER;IAED,IAAI,KAAK,aAER;IAED,IAAI,IAAI,YAEP;IAED,IAAI,IAAI,YAEP;IAED,IAAI,KAAK,aAER;IAED,IAAI,IAAI,YAEP;IAED,QAAQ,CAAC,MAAM,GAAE,MAA+B,EAAE,MAAM,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAAG,MAAM;CAcrG"}
@@ -0,0 +1,5 @@
1
+ export * from './ShiftedBigInt.ts';
2
+ export * from './splitOnDecimal.ts';
3
+ export * from './splitOnDecimalToString.ts';
4
+ export * from './Xl1Amount.ts';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/amount/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,gBAAgB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const splitOnDecimal: (value: bigint, places?: number) => [bigint, bigint];
2
+ //# sourceMappingURL=splitOnDecimal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitOnDecimal.d.ts","sourceRoot":"","sources":["../../../src/amount/splitOnDecimal.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,eAAW,KAAG,CAAC,MAAM,EAAE,MAAM,CAI1E,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const splitOnDecimalToString: (value: bigint, places?: number, maxDecimal?: number, maxCharacters?: number, minDecimals?: number, locale?: Intl.LocalesArgument) => string;
2
+ //# sourceMappingURL=splitOnDecimalToString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitOnDecimalToString.d.ts","sourceRoot":"","sources":["../../../src/amount/splitOnDecimalToString.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,GACjC,OAAO,MAAM,EACb,eAAW,EACX,mBAAmB,EACnB,sBAAiB,EACjB,oBAAe,EACf,SAAQ,IAAI,CAAC,eAAyB,KACrC,MA2BF,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { Address } from '@xylabs/hex';
2
+ import type { BaseWrapperConfig } from '../Base.ts';
3
+ import { BaseWrapper } from '../Base.ts';
4
+ export declare class ChainWrapper extends BaseWrapper<Address, BaseWrapperConfig<Address>> {
5
+ get id(): Address;
6
+ }
7
+ //# sourceMappingURL=chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../src/chain/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,qBAAa,YAAa,SAAQ,WAAW,CAAC,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAChF,IAAI,EAAE,IAAI,OAAO,CAEhB;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from './chain.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/chain/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
@@ -1,4 +1,6 @@
1
+ export * from './amount/index.ts';
1
2
  export * from './Base.ts';
3
+ export * from './chain/index.ts';
2
4
  export * from './Fees.ts';
3
5
  export * from './lib/index.ts';
4
6
  export * from './Signature.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA"}
@@ -1,6 +1,154 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
+ // src/amount/splitOnDecimal.ts
5
+ var splitOnDecimal = /* @__PURE__ */ __name((value, places = 18) => {
6
+ const whole = value / BigInt(10 ** places);
7
+ const decimal = value % BigInt(10 ** places);
8
+ return [
9
+ whole,
10
+ decimal
11
+ ];
12
+ }, "splitOnDecimal");
13
+
14
+ // src/amount/splitOnDecimalToString.ts
15
+ var splitOnDecimalToString = /* @__PURE__ */ __name((value, places = 18, maxDecimal = places, maxCharacters = 9, minDecimals = 1, locale = "en-US") => {
16
+ const [whole, decimal] = splitOnDecimal(value, places);
17
+ if (whole === 0n && decimal < 10 ** maxDecimal && decimal !== 0n) return "< 0.".padEnd(maxDecimal + 5, "0") + "1";
18
+ const wholeCharacters = whole.toString(10).length;
19
+ const calcMaxDecimalCharacters = maxCharacters === -1 ? places : wholeCharacters > maxCharacters ? 0 : maxCharacters - wholeCharacters;
20
+ const maxDecimalCharacters = Math.min(maxDecimal, calcMaxDecimalCharacters);
21
+ const formattedWhole = new Intl.NumberFormat(locale, {
22
+ maximumFractionDigits: 0,
23
+ useGrouping: true
24
+ }).format(whole);
25
+ const decimalSeparator = new Intl.NumberFormat(locale).formatToParts(1.1).find((part) => part.type === "decimal")?.value ?? ".";
26
+ let paddedDecimal = decimal.toString().padStart(places, "0").slice(0, maxDecimalCharacters);
27
+ while (paddedDecimal.length > minDecimals && paddedDecimal.endsWith("0")) {
28
+ paddedDecimal = paddedDecimal.slice(0, -1);
29
+ }
30
+ return `${formattedWhole}${paddedDecimal.length > 0 ? decimalSeparator : ""}${paddedDecimal}`;
31
+ }, "splitOnDecimalToString");
32
+
33
+ // src/amount/ShiftedBigInt.ts
34
+ var ShiftedBigInt = class _ShiftedBigInt {
35
+ static {
36
+ __name(this, "ShiftedBigInt");
37
+ }
38
+ static defaultConfig = {
39
+ places: 18,
40
+ maxDecimal: 18,
41
+ maxCharacters: 9,
42
+ minDecimals: 1,
43
+ locale: "en-US"
44
+ };
45
+ config;
46
+ value;
47
+ constructor(value, config = {}) {
48
+ this.value = typeof value === "bigint" ? value : value.value;
49
+ this.config = {
50
+ ..._ShiftedBigInt.defaultConfig,
51
+ ...typeof value === "bigint" ? {} : value.config,
52
+ ...config
53
+ };
54
+ }
55
+ get locale() {
56
+ return this.config.locale ?? "en-US";
57
+ }
58
+ get maxCharacters() {
59
+ return this.config.maxCharacters ?? 9;
60
+ }
61
+ get maxDecimal() {
62
+ return this.config.maxDecimal ?? this.places;
63
+ }
64
+ get minDecimals() {
65
+ return this.config.minDecimals ?? 1;
66
+ }
67
+ get places() {
68
+ return this.config.places ?? 18;
69
+ }
70
+ toFullString() {
71
+ return splitOnDecimalToString(this.value, this.places, this.places, Infinity, this.places, this.locale);
72
+ }
73
+ toShortString() {
74
+ return splitOnDecimalToString(this.value, this.places, this.maxDecimal, this.maxCharacters, this.minDecimals, this.locale);
75
+ }
76
+ toString() {
77
+ return this.toFullString();
78
+ }
79
+ };
80
+
81
+ // src/amount/Xl1Amount.ts
82
+ import { assertEx } from "@xylabs/assert";
83
+ import { AttoXL1, FemtoXL1, MicroXL1, MilliXL1, NanoXL1, PicoXL1, XL1Places } from "@xyo-network/xl1-protocol";
84
+ var MAX_XL1_AMOUNT = 2n ** BigInt(256) - 1n;
85
+ var allowedPlaces = Object.values(XL1Places);
86
+ var XL1Amount = class _XL1Amount {
87
+ static {
88
+ __name(this, "XL1Amount");
89
+ }
90
+ value;
91
+ locale;
92
+ constructor(value, locale = "en-US") {
93
+ this.locale = locale;
94
+ this.value = AttoXL1(value > MAX_XL1_AMOUNT ? MAX_XL1_AMOUNT : value < 0n ? 0n : value);
95
+ }
96
+ static from(value, places = XL1Places.atto) {
97
+ assertEx(allowedPlaces.includes(places), () => `Invalid conversion places (${places} not in ${allowedPlaces})`);
98
+ return new _XL1Amount(value * 10n ** BigInt(places));
99
+ }
100
+ static fromMilli(value) {
101
+ return this.from(value, XL1Places.milli);
102
+ }
103
+ static fromMicro(value) {
104
+ return this.from(value, XL1Places.micro);
105
+ }
106
+ static fromNano(value) {
107
+ return this.from(value, XL1Places.nano);
108
+ }
109
+ static fromPico(value) {
110
+ return this.from(value, XL1Places.pico);
111
+ }
112
+ static fromFemto(value) {
113
+ return this.from(value, XL1Places.femto);
114
+ }
115
+ static fromAtto(value) {
116
+ return this.from(value, XL1Places.atto);
117
+ }
118
+ to(places = XL1Places.atto) {
119
+ return this.value / 10n ** BigInt(places);
120
+ }
121
+ get milli() {
122
+ return MilliXL1(this.to(XL1Places.micro));
123
+ }
124
+ get micro() {
125
+ return MicroXL1(this.to(XL1Places.micro));
126
+ }
127
+ get nano() {
128
+ return NanoXL1(this.to(XL1Places.nano));
129
+ }
130
+ get pico() {
131
+ return PicoXL1(this.to(XL1Places.pico));
132
+ }
133
+ get femto() {
134
+ return FemtoXL1(this.to(XL1Places.femto));
135
+ }
136
+ get atto() {
137
+ return AttoXL1(this.to(XL1Places.atto));
138
+ }
139
+ toString(places = Number(XL1Places.atto), config = {}) {
140
+ assertEx(allowedPlaces.includes(BigInt(places)), () => `Invalid conversion places (${places} not in ${allowedPlaces})`);
141
+ return new ShiftedBigInt(this.value, {
142
+ places,
143
+ locale: this.locale,
144
+ maxDecimal: places,
145
+ minDecimals: 0,
146
+ maxCharacters: places,
147
+ ...config
148
+ }).toShortString();
149
+ }
150
+ };
151
+
4
152
  // src/Base.ts
5
153
  var BaseWrapper = class {
6
154
  static {
@@ -35,11 +183,21 @@ var BaseWrapper = class {
35
183
  }
36
184
  };
37
185
 
186
+ // src/chain/chain.ts
187
+ var ChainWrapper = class extends BaseWrapper {
188
+ static {
189
+ __name(this, "ChainWrapper");
190
+ }
191
+ get id() {
192
+ return this.value;
193
+ }
194
+ };
195
+
38
196
  // src/Fees.ts
39
197
  import { hexToBigInt } from "@xylabs/hex";
40
- import { AttoXL1 } from "@xyo-network/xl1-protocol";
198
+ import { AttoXL1 as AttoXL12 } from "@xyo-network/xl1-protocol";
41
199
  function parseHexOrBigInt(value) {
42
- return AttoXL1(typeof value === "bigint" ? value : hexToBigInt(value));
200
+ return AttoXL12(typeof value === "bigint" ? value : hexToBigInt(value));
43
201
  }
44
202
  __name(parseHexOrBigInt, "parseHexOrBigInt");
45
203
  var FeesWrapper = class _FeesWrapper {
@@ -249,9 +407,14 @@ var HydratedTransactionWrapper = class _HydratedTransactionWrapper {
249
407
  };
250
408
  export {
251
409
  BaseWrapper,
410
+ ChainWrapper,
252
411
  FeesWrapper,
253
412
  HydratedTransactionWrapper,
413
+ ShiftedBigInt,
254
414
  SignatureWrapper,
255
- createSignatureWrappers
415
+ XL1Amount,
416
+ createSignatureWrappers,
417
+ splitOnDecimal,
418
+ splitOnDecimalToString
256
419
  };
257
420
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Base.ts","../../src/Fees.ts","../../src/lib/createSignatureWrappers.ts","../../src/Signature.ts","../../src/transaction/HydratedTransaction.ts"],"sourcesContent":["import type { PromisableArray } from '@xylabs/promise'\nimport type { XyoConnectionProvider } from '@xyo-network/xl1-protocol'\n\nexport interface BaseWrapperConfig<T> {\n provider: XyoConnectionProvider\n value: T\n}\n\nexport class BaseWrapper<T, C extends BaseWrapperConfig<T> = BaseWrapperConfig<T>> {\n protected readonly config: Partial<C>\n protected readonly value: T\n protected constructor(value: T, config: Partial<C> = {}) {\n this.config = config\n this.value = value\n }\n\n get provider(): XyoConnectionProvider | undefined {\n return this.config.provider\n }\n\n static async create<T, C extends BaseWrapperConfig<T> = BaseWrapperConfig<T>>(value: T, config: Partial<C> = {}) {\n if ((await this.validateValue(value)).length > 0) {\n throw new Error(`Invalid value for ${this.constructor.name}: ${value}`)\n }\n if ((await this.validateConfig(config)).length > 0) {\n throw new Error(`Invalid config for ${this.constructor.name}: ${config}`)\n }\n return new this<T>(value, config)\n }\n\n static validateConfig(_config: unknown): PromisableArray<Error> {\n return []\n }\n\n static validateValue(_value: unknown): PromisableArray<Error> {\n return []\n }\n\n validate(): PromisableArray<Error> {\n return []\n }\n}\n","import type { Hex } from '@xylabs/hex'\nimport { hexToBigInt } from '@xylabs/hex'\nimport type { Promisable } from '@xylabs/promise'\nimport type { TransactionFeesBigInt, TransactionFeesHex } from '@xyo-network/xl1-protocol'\nimport { AttoXL1 } from '@xyo-network/xl1-protocol'\nimport type { TransactionFeesInstance } from '@xyo-network/xl1-protocol-sdk'\n\nfunction parseHexOrBigInt(value: Hex | bigint) {\n return AttoXL1((typeof value === 'bigint' ? value : hexToBigInt(value)))\n}\n\nexport class FeesWrapper implements TransactionFeesInstance {\n base: AttoXL1\n gasLimit: AttoXL1\n gasPrice: AttoXL1\n priority: AttoXL1\n\n constructor({\n base, gasLimit, gasPrice, priority,\n }: TransactionFeesHex | TransactionFeesBigInt) {\n this.base = parseHexOrBigInt(base)\n this.gasLimit = parseHexOrBigInt(gasLimit)\n this.gasPrice = parseHexOrBigInt(gasPrice)\n this.priority = parseHexOrBigInt(priority)\n }\n\n static validate({\n base, gasLimit, gasPrice, priority,\n }: TransactionFeesHex | TransactionFeesBigInt): Promisable<Error[]> {\n const errors: Error[] = []\n const baseValue = parseHexOrBigInt(base)\n const gasLimitValue = parseHexOrBigInt(gasLimit)\n const gasPriceValue = parseHexOrBigInt(gasPrice)\n const priorityValue = parseHexOrBigInt(priority)\n if (baseValue <= 0n) {\n errors.push(new Error('Base fee cannot be negative or zero'))\n }\n if (gasLimitValue < 0n) {\n errors.push(new Error('Gas limit cannot be negative'))\n }\n if (gasPriceValue < 0n) {\n errors.push(new Error('Gas price cannot be negative'))\n }\n if (priorityValue < 0n) {\n errors.push(new Error('Priority cannot be negative'))\n }\n return errors\n }\n\n async validate(): Promise<Error[]> {\n return await FeesWrapper.validate({\n base: this.base, gasLimit: this.gasLimit, gasPrice: this.gasPrice, priority: this.priority,\n })\n }\n}\n","import type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { SignatureInstance } from '@xyo-network/xl1-protocol-sdk'\n\nimport { SignatureWrapper } from '../Signature.ts'\n\nexport const createSignatureWrappers = async (bw: BoundWitness): Promise<SignatureInstance[]> => {\n const signatures: SignatureInstance[] = []\n const hash = await PayloadBuilder.dataHash(bw)\n for (let i = 0; i < bw.$signatures.length; i++) {\n signatures.push(\n new SignatureWrapper(bw.$signatures[i], bw.addresses[i], hash),\n )\n }\n return signatures\n}\n","import { toArrayBuffer } from '@xylabs/arraybuffer'\nimport type {\n Address, Hash, Hex,\n} from '@xylabs/hex'\nimport { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'\nimport type { SignatureInstance } from '@xyo-network/xl1-protocol-sdk'\n\nexport class SignatureWrapper implements SignatureInstance {\n address: Address\n hash: Hash\n signature: Hex\n\n constructor(signature: Hex, address: Address, hash: Hash) {\n this.signature = signature\n this.address = address\n this.hash = hash\n }\n\n static async validate(hash: Hash, address: Address, signature: Hex): Promise<Error[]> {\n return await BoundWitnessValidator.validateSignature(toArrayBuffer(hash), toArrayBuffer(address), toArrayBuffer(signature))\n }\n\n async validate(): Promise<Error[]> {\n return await SignatureWrapper.validate(this.hash, this.address, this.signature)\n }\n}\n","import type { Hash, Hex } from '@xylabs/hex'\nimport { hexToBigInt } from '@xylabs/hex'\nimport { isDefined } from '@xylabs/typeof'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type {\n Payload, Schema, WithHashStorageMeta,\n WithStorageMeta,\n} from '@xyo-network/payload-model'\nimport type {\n AllowedBlockPayload, HydratedTransactionWithStorageMeta, Transfer,\n} from '@xyo-network/xl1-protocol'\nimport { isTransfer, XYO_ZERO_ADDRESS } from '@xyo-network/xl1-protocol'\nimport type {\n HydratedTransactionInstance, SignatureInstance,\n TransactionFeesInstance,\n} from '@xyo-network/xl1-protocol-sdk'\nimport {\n transactionRequiredGas, tryExtractElevatedHashes, tryExtractElevatedHashesFromScript,\n} from '@xyo-network/xl1-protocol-sdk'\nimport { validateTransaction } from '@xyo-network/xl1-validation'\n\nimport { FeesWrapper } from '../Fees.ts'\nimport { createSignatureWrappers } from '../lib/index.ts'\n\nconst sumTransfers = (payload: Transfer) => {\n let total = 0n\n for (let i of Object.values(payload.transfers)) {\n total += hexToBigInt(i ?? '00' as Hex)\n }\n return total\n}\n\nexport class HydratedTransactionWrapper<T extends HydratedTransactionWithStorageMeta> implements HydratedTransactionInstance<[T[0],\n T[1][number][]]> {\n data: T\n fees: TransactionFeesInstance\n\n protected payloadsCache: WithStorageMeta<Payload>[] = []\n\n private _signatureCache: SignatureInstance[] = []\n\n protected constructor(data: T) {\n this.data = data\n this.fees = new FeesWrapper(\n this.boundWitness.fees,\n )\n }\n\n get boundWitness(): T[0] {\n return this.data[0]\n }\n\n get elevatedPayloadCount(): number {\n const { script } = this.data[0]\n return script ? tryExtractElevatedHashesFromScript(script).length : 0\n }\n\n get elevatedPayloads(): WithStorageMeta<AllowedBlockPayload>[] {\n return tryExtractElevatedHashes(this.data)\n }\n\n get externalPayloads(): Record<Hash, Schema | Payload> {\n const allPayloads = this.payloads\n const external: Record<Hash, Schema | Payload> = {}\n for (let i = 0; i < this.boundWitness.payload_hashes.length; i++) {\n const payloadHash = this.boundWitness.payload_hashes[i]\n const payload = allPayloads.find(p => p._hash === payloadHash)\n external[payloadHash] = isDefined(payload) ? payload : this.boundWitness.payload_schemas[i]\n }\n return external\n }\n\n get from() {\n return this.data[0].from\n }\n\n get payloadCount(): number {\n return this.payloadsCache.length\n }\n\n get payloads(): WithHashStorageMeta<WithStorageMeta<T[1][number]>>[] {\n return [...this.payloadsCache]\n }\n\n get privateExternalPayloads(): Record<Hash, Schema> {\n const allPayloads = this.payloads\n const missing: Record<Hash, Schema> = {}\n for (let i = 0; i < this.boundWitness.payload_hashes.length; i++) {\n const payloadHash = this.boundWitness.payload_hashes[i]\n if (!allPayloads.some(p => p._hash === payloadHash)) {\n missing[payloadHash] = this.boundWitness.payload_schemas[i]\n }\n }\n return missing\n }\n\n // list all the payloads that are included in the transaction and are not elevated and found in the hydration\n get publicExternalPayloads(): Payload[] {\n const allPayloads = this.payloads\n const elevatedPayloads = this.elevatedPayloads\n return allPayloads.filter(p => !elevatedPayloads.some(ep => ep._hash === p._hash))\n }\n\n get signatureCount(): number {\n return this._signatureCache.length\n }\n\n get signatures(): SignatureInstance[] {\n return [...this._signatureCache]\n }\n\n static async parse<T extends HydratedTransactionWithStorageMeta>(transaction: T, validate = false): Promise<HydratedTransactionInstance<[T[0],\n T[1][number][]]>> {\n const wrapper = new HydratedTransactionWrapper<T>(\n transaction,\n )\n const parsed = await wrapper.parse()\n if (validate) {\n const errors = await wrapper.validate()\n if (errors.length > 0) {\n throw new Error(`Block validation failed: ${errors.join(', ')}`)\n }\n }\n return parsed\n }\n\n elevatedPayload(index: number): WithHashStorageMeta<AllowedBlockPayload & T[1][number]> | undefined {\n return this.elevatedPayloads.at(index)\n }\n\n gasRequired(): bigint {\n return transactionRequiredGas(this.data)\n }\n\n payload(index: number): WithStorageMeta<Payload> | undefined {\n return this.payloads.at(index)\n }\n\n reward(): bigint {\n return this.payloadsCache.reduce((acc: bigint, payload) => acc + (\n isTransfer(payload)\n ? payload.from === XYO_ZERO_ADDRESS\n ? sumTransfers(payload)\n : 0n\n : 0n), 0n)\n }\n\n signature(index: number): SignatureInstance | undefined {\n return this._signatureCache[index]\n }\n\n async validate(): Promise<Error[]> {\n const errors: Error[] = []\n errors.push(\n ...(await Promise.all(this._signatureCache.map(signature => signature.validate()))).flat(),\n ...(await validateTransaction(this.data)),\n )\n return errors\n }\n\n protected async parse(validate = false): Promise<HydratedTransactionInstance<[WithHashStorageMeta<T[0]>, WithHashStorageMeta<T[1][number]>[]]>> {\n const transactionPayloads = await PayloadBuilder.addStorageMeta(this.data[1])\n this._signatureCache = await createSignatureWrappers(this.data[0])\n for (const payload of transactionPayloads) {\n this.payloadsCache.push(payload)\n }\n if (validate) {\n await this.validate()\n }\n return this\n }\n}\n"],"mappings":";;;;AAQO,IAAMA,cAAN,MAAMA;EAAb,OAAaA;;;EACQC;EACAC;EACnB,YAAsBA,OAAUD,SAAqB,CAAC,GAAG;AACvD,SAAKA,SAASA;AACd,SAAKC,QAAQA;EACf;EAEA,IAAIC,WAA8C;AAChD,WAAO,KAAKF,OAAOE;EACrB;EAEA,aAAaC,OAAiEF,OAAUD,SAAqB,CAAC,GAAG;AAC/G,SAAK,MAAM,KAAKI,cAAcH,KAAAA,GAAQI,SAAS,GAAG;AAChD,YAAM,IAAIC,MAAM,qBAAqB,KAAK,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AAAA;EAC1B;EAEAI,SAAiB;AACf,WAAO,KAAK5C,cAAc6C,OAAO,CAACC,KAAaxD,YAAYwD,OACzDC,WAAWzD,OAAAA,IACPA,QAAQ+B,SAAS2B,mBACf3D,aAAaC,OAAAA,IACb,KACF,KAAK,EAAE;EACf;EAEA2D,UAAUT,OAA8C;AACtD,WAAO,KAAKvC,gBAAgBuC,KAAAA;EAC9B;EAEA,MAAMP,WAA6B;AACjC,UAAMG,SAAkB,CAAA;AACxBA,WAAOc,KAAI,IACL,MAAMC,QAAQC,IAAI,KAAKnD,gBAAgBoD,IAAIJ,CAAAA,cAAaA,UAAUhB,SAAQ,CAAA,CAAA,GAAMqB,KAAI,GAAA,GACpF,MAAMC,oBAAoB,KAAKzD,IAAI,CAAA;AAEzC,WAAOsC;EACT;EAEA,MAAgBL,MAAME,WAAW,OAA+G;AAC9I,UAAMuB,sBAAsB,MAAMC,gBAAeC,eAAe,KAAK5D,KAAK,CAAA,CAAE;AAC5E,SAAKG,kBAAkB,MAAM0D,wBAAwB,KAAK7D,KAAK,CAAA,CAAE;AACjE,eAAWR,WAAWkE,qBAAqB;AACzC,WAAKxD,cAAckD,KAAK5D,OAAAA;IAC1B;AACA,QAAI2C,UAAU;AACZ,YAAM,KAAKA,SAAQ;IACrB;AACA,WAAO;EACT;AACF;","names":["BaseWrapper","config","value","provider","create","validateValue","length","Error","name","validateConfig","_config","_value","validate","hexToBigInt","AttoXL1","parseHexOrBigInt","value","AttoXL1","hexToBigInt","FeesWrapper","base","gasLimit","gasPrice","priority","validate","errors","baseValue","gasLimitValue","gasPriceValue","priorityValue","push","Error","PayloadBuilder","toArrayBuffer","BoundWitnessValidator","SignatureWrapper","address","hash","signature","validate","BoundWitnessValidator","validateSignature","toArrayBuffer","createSignatureWrappers","bw","signatures","hash","PayloadBuilder","dataHash","i","$signatures","length","push","SignatureWrapper","addresses","hexToBigInt","isDefined","PayloadBuilder","isTransfer","XYO_ZERO_ADDRESS","transactionRequiredGas","tryExtractElevatedHashes","tryExtractElevatedHashesFromScript","validateTransaction","sumTransfers","payload","total","i","Object","values","transfers","hexToBigInt","HydratedTransactionWrapper","data","fees","payloadsCache","_signatureCache","FeesWrapper","boundWitness","elevatedPayloadCount","script","tryExtractElevatedHashesFromScript","length","elevatedPayloads","tryExtractElevatedHashes","externalPayloads","allPayloads","payloads","external","payload_hashes","payloadHash","find","p","_hash","isDefined","payload_schemas","from","payloadCount","privateExternalPayloads","missing","some","publicExternalPayloads","filter","ep","signatureCount","signatures","parse","transaction","validate","wrapper","parsed","errors","Error","join","elevatedPayload","index","at","gasRequired","transactionRequiredGas","reward","reduce","acc","isTransfer","XYO_ZERO_ADDRESS","signature","push","Promise","all","map","flat","validateTransaction","transactionPayloads","PayloadBuilder","addStorageMeta","createSignatureWrappers"]}
1
+ {"version":3,"sources":["../../src/amount/splitOnDecimal.ts","../../src/amount/splitOnDecimalToString.ts","../../src/amount/ShiftedBigInt.ts","../../src/amount/Xl1Amount.ts","../../src/Base.ts","../../src/chain/chain.ts","../../src/Fees.ts","../../src/lib/createSignatureWrappers.ts","../../src/Signature.ts","../../src/transaction/HydratedTransaction.ts"],"sourcesContent":["export const splitOnDecimal = (value: bigint, places = 18): [bigint, bigint] => {\n const whole = value / BigInt(10 ** places)\n const decimal = value % BigInt(10 ** places)\n return [whole, decimal]\n}\n","import { splitOnDecimal } from './splitOnDecimal.ts'\n\nexport const splitOnDecimalToString = (\n value: bigint,\n places = 18,\n maxDecimal = places,\n maxCharacters = 9,\n minDecimals = 1,\n locale: Intl.LocalesArgument = 'en-US',\n): string => {\n const [whole, decimal] = splitOnDecimal(value, places)\n if (whole === 0n && decimal < 10 ** maxDecimal && decimal !== 0n) return '< 0.'.padEnd(maxDecimal + 5, '0') + '1'\n\n const wholeCharacters = whole.toString(10).length\n const calcMaxDecimalCharacters = maxCharacters === -1 ? places : wholeCharacters > maxCharacters ? 0 : maxCharacters - wholeCharacters\n const maxDecimalCharacters = Math.min(maxDecimal, calcMaxDecimalCharacters)\n\n // Format whole number with thousand separators according to locale\n const formattedWhole = new Intl.NumberFormat(locale, {\n maximumFractionDigits: 0,\n useGrouping: true,\n }).format(whole)\n\n // Get decimal separator for the locale\n const decimalSeparator = new Intl.NumberFormat(locale)\n .formatToParts(1.1)\n .find(part => part.type === 'decimal')?.value ?? '.'\n\n // Pad decimal part to correct number of places\n let paddedDecimal = decimal.toString().padStart(places, '0').slice(0, maxDecimalCharacters)\n // remove unneeded trailing zeros (honoring minDecimals)\n while (paddedDecimal.length > minDecimals && paddedDecimal.endsWith('0')) {\n paddedDecimal = paddedDecimal.slice(0, -1)\n }\n\n return `${formattedWhole}${paddedDecimal.length > 0 ? decimalSeparator : ''}${paddedDecimal}`\n}\n","import type { ShiftedBigIntConfig } from '@xyo-network/xl1-protocol-sdk'\n\nimport { splitOnDecimalToString } from './splitOnDecimalToString.ts'\n\nexport class ShiftedBigInt {\n static readonly defaultConfig: ShiftedBigIntConfig = {\n places: 18,\n maxDecimal: 18,\n maxCharacters: 9,\n minDecimals: 1,\n locale: 'en-US',\n }\n\n config: ShiftedBigIntConfig\n value: bigint\n\n constructor(\n value: bigint | ShiftedBigInt,\n config: Partial<ShiftedBigIntConfig> = {},\n ) {\n this.value = typeof value === 'bigint' ? value : value.value\n this.config = {\n ...ShiftedBigInt.defaultConfig, ...(typeof value === 'bigint' ? {} : value.config), ...config,\n }\n }\n\n get locale(): Intl.LocalesArgument {\n return this.config.locale ?? 'en-US'\n }\n\n get maxCharacters(): number {\n return this.config.maxCharacters ?? 9\n }\n\n get maxDecimal(): number {\n return this.config.maxDecimal ?? this.places\n }\n\n get minDecimals(): number {\n return this.config.minDecimals ?? 1\n }\n\n get places(): number {\n return this.config.places ?? 18\n }\n\n toFullString(): string {\n return splitOnDecimalToString(\n this.value,\n this.places,\n this.places,\n Infinity,\n this.places,\n this.locale,\n )\n }\n\n toShortString(): string {\n return splitOnDecimalToString(\n this.value,\n this.places,\n this.maxDecimal,\n this.maxCharacters,\n this.minDecimals,\n this.locale,\n )\n }\n\n toString(): string {\n return this.toFullString()\n }\n}\n","/* eslint-disable @typescript-eslint/member-ordering */\nimport { assertEx } from '@xylabs/assert'\nimport {\n AttoXL1, FemtoXL1, MicroXL1, MilliXL1, NanoXL1, PicoXL1,\n XL1Places,\n} from '@xyo-network/xl1-protocol'\nimport type { ShiftedBigIntConfig } from '@xyo-network/xl1-protocol-sdk'\n\nimport { ShiftedBigInt } from './ShiftedBigInt.ts'\n\nconst MAX_XL1_AMOUNT = 2n ** BigInt(256) - 1n\nconst allowedPlaces = Object.values(XL1Places)\n\nexport interface XL1AmountInstance {\n value: AttoXL1\n\n to(places: bigint | number): bigint\n\n milli: MilliXL1\n\n micro: MicroXL1\n\n nano: NanoXL1\n\n pico: PicoXL1\n\n femto: FemtoXL1\n\n atto: AttoXL1\n\n toString(places: number, config: Partial<ShiftedBigIntConfig>): string\n}\n\nexport class XL1Amount implements XL1AmountInstance {\n value: AttoXL1\n private locale: Intl.LocalesArgument\n\n constructor(value: bigint, locale: Intl.LocalesArgument = 'en-US') {\n this.locale = locale\n this.value = AttoXL1(value > MAX_XL1_AMOUNT ? MAX_XL1_AMOUNT : value < 0n ? 0n : value)\n }\n\n static from(value: bigint, places: bigint = XL1Places.atto) {\n assertEx(allowedPlaces.includes(places), () => `Invalid conversion places (${places} not in ${allowedPlaces})`)\n return new XL1Amount(value * 10n ** BigInt(places))\n }\n\n static fromMilli(value: MilliXL1) {\n return this.from(value, XL1Places.milli)\n }\n\n static fromMicro(value: MicroXL1) {\n return this.from(value, XL1Places.micro)\n }\n\n static fromNano(value: NanoXL1) {\n return this.from(value, XL1Places.nano)\n }\n\n static fromPico(value: PicoXL1) {\n return this.from(value, XL1Places.pico)\n }\n\n static fromFemto(value: FemtoXL1) {\n return this.from(value, XL1Places.femto)\n }\n\n static fromAtto(value: AttoXL1) {\n return this.from(value, XL1Places.atto)\n }\n\n to(places: number | bigint = XL1Places.atto) {\n return this.value / 10n ** BigInt(places)\n }\n\n get milli() {\n return MilliXL1(this.to(XL1Places.micro))\n }\n\n get micro() {\n return MicroXL1(this.to(XL1Places.micro))\n }\n\n get nano() {\n return NanoXL1(this.to(XL1Places.nano))\n }\n\n get pico() {\n return PicoXL1(this.to(XL1Places.pico))\n }\n\n get femto() {\n return FemtoXL1(this.to(XL1Places.femto))\n }\n\n get atto() {\n return AttoXL1(this.to(XL1Places.atto))\n }\n\n toString(places: number = Number(XL1Places.atto), config: Partial<ShiftedBigIntConfig> = {}): string {\n assertEx(allowedPlaces.includes(BigInt(places)), () => `Invalid conversion places (${places} not in ${allowedPlaces})`)\n return new ShiftedBigInt(\n this.value,\n {\n places,\n locale: this.locale,\n maxDecimal: places,\n minDecimals: 0,\n maxCharacters: places,\n ...config,\n },\n ).toShortString()\n }\n}\n","import type { PromisableArray } from '@xylabs/promise'\nimport type { XyoConnectionProvider } from '@xyo-network/xl1-protocol'\n\nexport interface BaseWrapperConfig<T> {\n provider: XyoConnectionProvider\n value: T\n}\n\nexport class BaseWrapper<T, C extends BaseWrapperConfig<T> = BaseWrapperConfig<T>> {\n protected readonly config: Partial<C>\n protected readonly value: T\n protected constructor(value: T, config: Partial<C> = {}) {\n this.config = config\n this.value = value\n }\n\n get provider(): XyoConnectionProvider | undefined {\n return this.config.provider\n }\n\n static async create<T, C extends BaseWrapperConfig<T> = BaseWrapperConfig<T>>(value: T, config: Partial<C> = {}) {\n if ((await this.validateValue(value)).length > 0) {\n throw new Error(`Invalid value for ${this.constructor.name}: ${value}`)\n }\n if ((await this.validateConfig(config)).length > 0) {\n throw new Error(`Invalid config for ${this.constructor.name}: ${config}`)\n }\n return new this<T>(value, config)\n }\n\n static validateConfig(_config: unknown): PromisableArray<Error> {\n return []\n }\n\n static validateValue(_value: unknown): PromisableArray<Error> {\n return []\n }\n\n validate(): PromisableArray<Error> {\n return []\n }\n}\n","import type { Address } from '@xylabs/hex'\n\nimport type { BaseWrapperConfig } from '../Base.ts'\nimport { BaseWrapper } from '../Base.ts'\n\nexport class ChainWrapper extends BaseWrapper<Address, BaseWrapperConfig<Address>> {\n get id(): Address {\n return this.value\n }\n}\n","import type { Hex } from '@xylabs/hex'\nimport { hexToBigInt } from '@xylabs/hex'\nimport type { Promisable } from '@xylabs/promise'\nimport type { TransactionFeesBigInt, TransactionFeesHex } from '@xyo-network/xl1-protocol'\nimport { AttoXL1 } from '@xyo-network/xl1-protocol'\nimport type { TransactionFeesInstance } from '@xyo-network/xl1-protocol-sdk'\n\nfunction parseHexOrBigInt(value: Hex | bigint) {\n return AttoXL1((typeof value === 'bigint' ? value : hexToBigInt(value)))\n}\n\nexport class FeesWrapper implements TransactionFeesInstance {\n base: AttoXL1\n gasLimit: AttoXL1\n gasPrice: AttoXL1\n priority: AttoXL1\n\n constructor({\n base, gasLimit, gasPrice, priority,\n }: TransactionFeesHex | TransactionFeesBigInt) {\n this.base = parseHexOrBigInt(base)\n this.gasLimit = parseHexOrBigInt(gasLimit)\n this.gasPrice = parseHexOrBigInt(gasPrice)\n this.priority = parseHexOrBigInt(priority)\n }\n\n static validate({\n base, gasLimit, gasPrice, priority,\n }: TransactionFeesHex | TransactionFeesBigInt): Promisable<Error[]> {\n const errors: Error[] = []\n const baseValue = parseHexOrBigInt(base)\n const gasLimitValue = parseHexOrBigInt(gasLimit)\n const gasPriceValue = parseHexOrBigInt(gasPrice)\n const priorityValue = parseHexOrBigInt(priority)\n if (baseValue <= 0n) {\n errors.push(new Error('Base fee cannot be negative or zero'))\n }\n if (gasLimitValue < 0n) {\n errors.push(new Error('Gas limit cannot be negative'))\n }\n if (gasPriceValue < 0n) {\n errors.push(new Error('Gas price cannot be negative'))\n }\n if (priorityValue < 0n) {\n errors.push(new Error('Priority cannot be negative'))\n }\n return errors\n }\n\n async validate(): Promise<Error[]> {\n return await FeesWrapper.validate({\n base: this.base, gasLimit: this.gasLimit, gasPrice: this.gasPrice, priority: this.priority,\n })\n }\n}\n","import type { BoundWitness } from '@xyo-network/boundwitness-model'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type { SignatureInstance } from '@xyo-network/xl1-protocol-sdk'\n\nimport { SignatureWrapper } from '../Signature.ts'\n\nexport const createSignatureWrappers = async (bw: BoundWitness): Promise<SignatureInstance[]> => {\n const signatures: SignatureInstance[] = []\n const hash = await PayloadBuilder.dataHash(bw)\n for (let i = 0; i < bw.$signatures.length; i++) {\n signatures.push(\n new SignatureWrapper(bw.$signatures[i], bw.addresses[i], hash),\n )\n }\n return signatures\n}\n","import { toArrayBuffer } from '@xylabs/arraybuffer'\nimport type {\n Address, Hash, Hex,\n} from '@xylabs/hex'\nimport { BoundWitnessValidator } from '@xyo-network/boundwitness-validator'\nimport type { SignatureInstance } from '@xyo-network/xl1-protocol-sdk'\n\nexport class SignatureWrapper implements SignatureInstance {\n address: Address\n hash: Hash\n signature: Hex\n\n constructor(signature: Hex, address: Address, hash: Hash) {\n this.signature = signature\n this.address = address\n this.hash = hash\n }\n\n static async validate(hash: Hash, address: Address, signature: Hex): Promise<Error[]> {\n return await BoundWitnessValidator.validateSignature(toArrayBuffer(hash), toArrayBuffer(address), toArrayBuffer(signature))\n }\n\n async validate(): Promise<Error[]> {\n return await SignatureWrapper.validate(this.hash, this.address, this.signature)\n }\n}\n","import type { Hash, Hex } from '@xylabs/hex'\nimport { hexToBigInt } from '@xylabs/hex'\nimport { isDefined } from '@xylabs/typeof'\nimport { PayloadBuilder } from '@xyo-network/payload-builder'\nimport type {\n Payload, Schema, WithHashStorageMeta,\n WithStorageMeta,\n} from '@xyo-network/payload-model'\nimport type {\n AllowedBlockPayload, HydratedTransactionWithStorageMeta, Transfer,\n} from '@xyo-network/xl1-protocol'\nimport { isTransfer, XYO_ZERO_ADDRESS } from '@xyo-network/xl1-protocol'\nimport type {\n HydratedTransactionInstance, SignatureInstance,\n TransactionFeesInstance,\n} from '@xyo-network/xl1-protocol-sdk'\nimport {\n transactionRequiredGas, tryExtractElevatedHashes, tryExtractElevatedHashesFromScript,\n} from '@xyo-network/xl1-protocol-sdk'\nimport { validateTransaction } from '@xyo-network/xl1-validation'\n\nimport { FeesWrapper } from '../Fees.ts'\nimport { createSignatureWrappers } from '../lib/index.ts'\n\nconst sumTransfers = (payload: Transfer) => {\n let total = 0n\n for (let i of Object.values(payload.transfers)) {\n total += hexToBigInt(i ?? '00' as Hex)\n }\n return total\n}\n\nexport class HydratedTransactionWrapper<T extends HydratedTransactionWithStorageMeta> implements HydratedTransactionInstance<[T[0],\n T[1][number][]]> {\n data: T\n fees: TransactionFeesInstance\n\n protected payloadsCache: WithStorageMeta<Payload>[] = []\n\n private _signatureCache: SignatureInstance[] = []\n\n protected constructor(data: T) {\n this.data = data\n this.fees = new FeesWrapper(\n this.boundWitness.fees,\n )\n }\n\n get boundWitness(): T[0] {\n return this.data[0]\n }\n\n get elevatedPayloadCount(): number {\n const { script } = this.data[0]\n return script ? tryExtractElevatedHashesFromScript(script).length : 0\n }\n\n get elevatedPayloads(): WithStorageMeta<AllowedBlockPayload>[] {\n return tryExtractElevatedHashes(this.data)\n }\n\n get externalPayloads(): Record<Hash, Schema | Payload> {\n const allPayloads = this.payloads\n const external: Record<Hash, Schema | Payload> = {}\n for (let i = 0; i < this.boundWitness.payload_hashes.length; i++) {\n const payloadHash = this.boundWitness.payload_hashes[i]\n const payload = allPayloads.find(p => p._hash === payloadHash)\n external[payloadHash] = isDefined(payload) ? payload : this.boundWitness.payload_schemas[i]\n }\n return external\n }\n\n get from() {\n return this.data[0].from\n }\n\n get payloadCount(): number {\n return this.payloadsCache.length\n }\n\n get payloads(): WithHashStorageMeta<WithStorageMeta<T[1][number]>>[] {\n return [...this.payloadsCache]\n }\n\n get privateExternalPayloads(): Record<Hash, Schema> {\n const allPayloads = this.payloads\n const missing: Record<Hash, Schema> = {}\n for (let i = 0; i < this.boundWitness.payload_hashes.length; i++) {\n const payloadHash = this.boundWitness.payload_hashes[i]\n if (!allPayloads.some(p => p._hash === payloadHash)) {\n missing[payloadHash] = this.boundWitness.payload_schemas[i]\n }\n }\n return missing\n }\n\n // list all the payloads that are included in the transaction and are not elevated and found in the hydration\n get publicExternalPayloads(): Payload[] {\n const allPayloads = this.payloads\n const elevatedPayloads = this.elevatedPayloads\n return allPayloads.filter(p => !elevatedPayloads.some(ep => ep._hash === p._hash))\n }\n\n get signatureCount(): number {\n return this._signatureCache.length\n }\n\n get signatures(): SignatureInstance[] {\n return [...this._signatureCache]\n }\n\n static async parse<T extends HydratedTransactionWithStorageMeta>(transaction: T, validate = false): Promise<HydratedTransactionInstance<[T[0],\n T[1][number][]]>> {\n const wrapper = new HydratedTransactionWrapper<T>(\n transaction,\n )\n const parsed = await wrapper.parse()\n if (validate) {\n const errors = await wrapper.validate()\n if (errors.length > 0) {\n throw new Error(`Block validation failed: ${errors.join(', ')}`)\n }\n }\n return parsed\n }\n\n elevatedPayload(index: number): WithHashStorageMeta<AllowedBlockPayload & T[1][number]> | undefined {\n return this.elevatedPayloads.at(index)\n }\n\n gasRequired(): bigint {\n return transactionRequiredGas(this.data)\n }\n\n payload(index: number): WithStorageMeta<Payload> | undefined {\n return this.payloads.at(index)\n }\n\n reward(): bigint {\n return this.payloadsCache.reduce((acc: bigint, payload) => acc + (\n isTransfer(payload)\n ? payload.from === XYO_ZERO_ADDRESS\n ? sumTransfers(payload)\n : 0n\n : 0n), 0n)\n }\n\n signature(index: number): SignatureInstance | undefined {\n return this._signatureCache[index]\n }\n\n async validate(): Promise<Error[]> {\n const errors: Error[] = []\n errors.push(\n ...(await Promise.all(this._signatureCache.map(signature => signature.validate()))).flat(),\n ...(await validateTransaction(this.data)),\n )\n return errors\n }\n\n protected async parse(validate = false): Promise<HydratedTransactionInstance<[WithHashStorageMeta<T[0]>, WithHashStorageMeta<T[1][number]>[]]>> {\n const transactionPayloads = await PayloadBuilder.addStorageMeta(this.data[1])\n this._signatureCache = await createSignatureWrappers(this.data[0])\n for (const payload of transactionPayloads) {\n this.payloadsCache.push(payload)\n }\n if (validate) {\n await this.validate()\n }\n return this\n }\n}\n"],"mappings":";;;;AAAO,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BAAgBoD,IAAIJ,CAAAA,cAAaA,UAAUhB,SAAQ,CAAA,CAAA,GAAMqB,KAAI,GAAA,GACpF,MAAMC,oBAAoB,KAAKzD,IAAI,CAAA;AAEzC,WAAOsC;EACT;EAEA,MAAgBL,MAAME,WAAW,OAA+G;AAC9I,UAAMuB,sBAAsB,MAAMC,gBAAeC,eAAe,KAAK5D,KAAK,CAAA,CAAE;AAC5E,SAAKG,kBAAkB,MAAM0D,wBAAwB,KAAK7D,KAAK,CAAA,CAAE;AACjE,eAAWR,WAAWkE,qBAAqB;AACzC,WAAKxD,cAAckD,KAAK5D,OAAAA;IAC1B;AACA,QAAI2C,UAAU;AACZ,YAAM,KAAKA,SAAQ;IACrB;AACA,WAAO;EACT;AACF;","names":["splitOnDecimal","value","places","whole","BigInt","decimal","splitOnDecimalToString","value","places","maxDecimal","maxCharacters","minDecimals","locale","whole","decimal","splitOnDecimal","padEnd","wholeCharacters","toString","length","calcMaxDecimalCharacters","maxDecimalCharacters","Math","min","formattedWhole","Intl","NumberFormat","maximumFractionDigits","useGrouping","format","decimalSeparator","formatToParts","find","part","type","paddedDecimal","padStart","slice","endsWith","ShiftedBigInt","defaultConfig","places","maxDecimal","maxCharacters","minDecimals","locale","config","value","toFullString","splitOnDecimalToString","Infinity","toShortString","toString","assertEx","AttoXL1","FemtoXL1","MicroXL1","MilliXL1","NanoXL1","PicoXL1","XL1Places","MAX_XL1_AMOUNT","BigInt","allowedPlaces","Object","values","XL1Places","XL1Amount","value","locale","AttoXL1","from","places","atto","assertEx","includes","fromMilli","milli","fromMicro","micro","fromNano","nano","fromPico","pico","fromFemto","femto","fromAtto","to","MilliXL1","MicroXL1","NanoXL1","PicoXL1","FemtoXL1","toString","Number","config","ShiftedBigInt","maxDecimal","minDecimals","maxCharacters","toShortString","BaseWrapper","config","value","provider","create","validateValue","length","Error","name","validateConfig","_config","_value","validate","ChainWrapper","BaseWrapper","id","value","hexToBigInt","AttoXL1","parseHexOrBigInt","value","AttoXL1","hexToBigInt","FeesWrapper","base","gasLimit","gasPrice","priority","validate","errors","baseValue","gasLimitValue","gasPriceValue","priorityValue","push","Error","PayloadBuilder","toArrayBuffer","BoundWitnessValidator","SignatureWrapper","address","hash","signature","validate","BoundWitnessValidator","validateSignature","toArrayBuffer","createSignatureWrappers","bw","signatures","hash","PayloadBuilder","dataHash","i","$signatures","length","push","SignatureWrapper","addresses","hexToBigInt","isDefined","PayloadBuilder","isTransfer","XYO_ZERO_ADDRESS","transactionRequiredGas","tryExtractElevatedHashes","tryExtractElevatedHashesFromScript","validateTransaction","sumTransfers","payload","total","i","Object","values","transfers","hexToBigInt","HydratedTransactionWrapper","data","fees","payloadsCache","_signatureCache","FeesWrapper","boundWitness","elevatedPayloadCount","script","tryExtractElevatedHashesFromScript","length","elevatedPayloads","tryExtractElevatedHashes","externalPayloads","allPayloads","payloads","external","payload_hashes","payloadHash","find","p","_hash","isDefined","payload_schemas","from","payloadCount","privateExternalPayloads","missing","some","publicExternalPayloads","filter","ep","signatureCount","signatures","parse","transaction","validate","wrapper","parsed","errors","Error","join","elevatedPayload","index","at","gasRequired","transactionRequiredGas","reward","reduce","acc","isTransfer","XYO_ZERO_ADDRESS","signature","push","Promise","all","map","flat","validateTransaction","transactionPayloads","PayloadBuilder","addStorageMeta","createSignatureWrappers"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json.schemastore.org/package.json",
3
3
  "name": "@xyo-network/xl1-wrappers",
4
- "version": "1.12.4",
4
+ "version": "1.12.6",
5
5
  "description": "XYO Layer One SDK Wrappers",
6
6
  "homepage": "https://xylabs.com",
7
7
  "bugs": {
@@ -37,6 +37,7 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@xylabs/arraybuffer": "~5.0.10",
40
+ "@xylabs/assert": "~5.0.10",
40
41
  "@xylabs/hex": "~5.0.10",
41
42
  "@xylabs/promise": "~5.0.10",
42
43
  "@xylabs/typeof": "~5.0.10",
@@ -45,8 +46,8 @@
45
46
  "@xyo-network/payload-builder": "~5.0.7",
46
47
  "@xyo-network/payload-model": "~5.0.7",
47
48
  "@xyo-network/xl1-protocol": "~1.10.15",
48
- "@xyo-network/xl1-protocol-sdk": "~1.12.4",
49
- "@xyo-network/xl1-validation": "~1.12.4"
49
+ "@xyo-network/xl1-protocol-sdk": "~1.12.6",
50
+ "@xyo-network/xl1-validation": "~1.12.6"
50
51
  },
51
52
  "devDependencies": {
52
53
  "@types/node": "~24.3.0",
package/src/Address.ts ADDED
@@ -0,0 +1,22 @@
1
+ import {
2
+ type Address,
3
+ isAddress,
4
+ } from '@xylabs/hex'
5
+ import type { Promisable } from '@xylabs/promise'
6
+ import type { AddressInstance } from '@xyo-network/xl1-protocol-sdk'
7
+
8
+ import { BaseWrapper } from './Base.ts'
9
+
10
+ export class AddressWrapper extends BaseWrapper<Address> implements AddressInstance {
11
+ get address(): Address {
12
+ return this.value
13
+ }
14
+
15
+ static override validateValue(address: unknown): Promisable<Error[]> {
16
+ return isAddress(address) ? [] : [new Error('Invalid address')]
17
+ }
18
+
19
+ override async validate(): Promise<Error[]> {
20
+ return await AddressWrapper.validateValue(this.address)
21
+ }
22
+ }
@@ -0,0 +1,18 @@
1
+ import type { Promisable } from '@xylabs/promise'
2
+ import type {
3
+ AddressStateInstance,
4
+ BlockWindowInstance,
5
+ XL1AmountInstance,
6
+ } from '@xyo-network/xl1-protocol-sdk'
7
+
8
+ import { AddressWrapper } from './Address.ts'
9
+
10
+ export class AddressStateWrapper extends AddressWrapper implements AddressStateInstance {
11
+ get blockWindow(): BlockWindowInstance {
12
+ throw new Error('Method not implemented.')
13
+ }
14
+
15
+ balance(): Promisable<[XL1AmountInstance, BlockWindowInstance]> {
16
+ throw new Error('Method not implemented.')
17
+ }
18
+ }
@@ -0,0 +1,43 @@
1
+ import type { Hash } from '@xylabs/hex'
2
+ import type { Promisable } from '@xylabs/promise'
3
+ import type { HydratedBlock } from '@xyo-network/xl1-protocol'
4
+ import type { BlockWindowInstance } from '@xyo-network/xl1-protocol-sdk'
5
+
6
+ export interface HydratedBlockRangeStore extends BlockWindowInstance {
7
+ first(): Promisable<HydratedBlock>
8
+ fromHash(hash: Hash): Promisable<HydratedBlock>
9
+ fromNumber(number: number): Promisable<HydratedBlock>
10
+ last(): Promisable<HydratedBlock>
11
+ next(): Promisable<HydratedBlock>
12
+ next(count: number): Promisable<HydratedBlock[]>
13
+ prev(): Promisable<HydratedBlock>
14
+ prev(count: number): Promisable<HydratedBlock[]>
15
+ }
16
+
17
+ export class BlockWindowWrapper implements BlockWindowInstance {
18
+ private _store: HydratedBlockRangeStore
19
+
20
+ constructor(store: HydratedBlockRangeStore) {
21
+ this._store = store
22
+ }
23
+
24
+ get count() {
25
+ return this._store.count
26
+ }
27
+
28
+ get numberRange() {
29
+ return this._store.numberRange
30
+ }
31
+
32
+ get range() {
33
+ return this._store.range
34
+ }
35
+
36
+ static validate(_store: HydratedBlockRangeStore): Promisable<Error[]> {
37
+ return [] // TODO: Implement validation logic
38
+ }
39
+
40
+ async validate(): Promise<Error[]> {
41
+ return await BlockWindowWrapper.validate(this._store)
42
+ }
43
+ }
@@ -0,0 +1,20 @@
1
+ import type { Address } from '@xylabs/hex'
2
+ import type { Promisable } from '@xylabs/promise'
3
+
4
+ import type { HydratedBlockRangeStore } from './BlockWindow.ts'
5
+
6
+ export interface BlockWindowBalanceCacheInstance {
7
+ balance(address: Address): Promisable<bigint>
8
+ }
9
+
10
+ export class BlockWindowBalanceCache implements BlockWindowBalanceCacheInstance {
11
+ private _store: HydratedBlockRangeStore
12
+
13
+ constructor(store: HydratedBlockRangeStore) {
14
+ this._store = store
15
+ }
16
+
17
+ balance(_address: Address): Promisable<bigint> {
18
+ throw new Error('Method not implemented.')
19
+ }
20
+ }
@@ -0,0 +1,72 @@
1
+ import type { ShiftedBigIntConfig } from '@xyo-network/xl1-protocol-sdk'
2
+
3
+ import { splitOnDecimalToString } from './splitOnDecimalToString.ts'
4
+
5
+ export class ShiftedBigInt {
6
+ static readonly defaultConfig: ShiftedBigIntConfig = {
7
+ places: 18,
8
+ maxDecimal: 18,
9
+ maxCharacters: 9,
10
+ minDecimals: 1,
11
+ locale: 'en-US',
12
+ }
13
+
14
+ config: ShiftedBigIntConfig
15
+ value: bigint
16
+
17
+ constructor(
18
+ value: bigint | ShiftedBigInt,
19
+ config: Partial<ShiftedBigIntConfig> = {},
20
+ ) {
21
+ this.value = typeof value === 'bigint' ? value : value.value
22
+ this.config = {
23
+ ...ShiftedBigInt.defaultConfig, ...(typeof value === 'bigint' ? {} : value.config), ...config,
24
+ }
25
+ }
26
+
27
+ get locale(): Intl.LocalesArgument {
28
+ return this.config.locale ?? 'en-US'
29
+ }
30
+
31
+ get maxCharacters(): number {
32
+ return this.config.maxCharacters ?? 9
33
+ }
34
+
35
+ get maxDecimal(): number {
36
+ return this.config.maxDecimal ?? this.places
37
+ }
38
+
39
+ get minDecimals(): number {
40
+ return this.config.minDecimals ?? 1
41
+ }
42
+
43
+ get places(): number {
44
+ return this.config.places ?? 18
45
+ }
46
+
47
+ toFullString(): string {
48
+ return splitOnDecimalToString(
49
+ this.value,
50
+ this.places,
51
+ this.places,
52
+ Infinity,
53
+ this.places,
54
+ this.locale,
55
+ )
56
+ }
57
+
58
+ toShortString(): string {
59
+ return splitOnDecimalToString(
60
+ this.value,
61
+ this.places,
62
+ this.maxDecimal,
63
+ this.maxCharacters,
64
+ this.minDecimals,
65
+ this.locale,
66
+ )
67
+ }
68
+
69
+ toString(): string {
70
+ return this.toFullString()
71
+ }
72
+ }
@@ -0,0 +1,114 @@
1
+ /* eslint-disable @typescript-eslint/member-ordering */
2
+ import { assertEx } from '@xylabs/assert'
3
+ import {
4
+ AttoXL1, FemtoXL1, MicroXL1, MilliXL1, NanoXL1, PicoXL1,
5
+ XL1Places,
6
+ } from '@xyo-network/xl1-protocol'
7
+ import type { ShiftedBigIntConfig } from '@xyo-network/xl1-protocol-sdk'
8
+
9
+ import { ShiftedBigInt } from './ShiftedBigInt.ts'
10
+
11
+ const MAX_XL1_AMOUNT = 2n ** BigInt(256) - 1n
12
+ const allowedPlaces = Object.values(XL1Places)
13
+
14
+ export interface XL1AmountInstance {
15
+ value: AttoXL1
16
+
17
+ to(places: bigint | number): bigint
18
+
19
+ milli: MilliXL1
20
+
21
+ micro: MicroXL1
22
+
23
+ nano: NanoXL1
24
+
25
+ pico: PicoXL1
26
+
27
+ femto: FemtoXL1
28
+
29
+ atto: AttoXL1
30
+
31
+ toString(places: number, config: Partial<ShiftedBigIntConfig>): string
32
+ }
33
+
34
+ export class XL1Amount implements XL1AmountInstance {
35
+ value: AttoXL1
36
+ private locale: Intl.LocalesArgument
37
+
38
+ constructor(value: bigint, locale: Intl.LocalesArgument = 'en-US') {
39
+ this.locale = locale
40
+ this.value = AttoXL1(value > MAX_XL1_AMOUNT ? MAX_XL1_AMOUNT : value < 0n ? 0n : value)
41
+ }
42
+
43
+ static from(value: bigint, places: bigint = XL1Places.atto) {
44
+ assertEx(allowedPlaces.includes(places), () => `Invalid conversion places (${places} not in ${allowedPlaces})`)
45
+ return new XL1Amount(value * 10n ** BigInt(places))
46
+ }
47
+
48
+ static fromMilli(value: MilliXL1) {
49
+ return this.from(value, XL1Places.milli)
50
+ }
51
+
52
+ static fromMicro(value: MicroXL1) {
53
+ return this.from(value, XL1Places.micro)
54
+ }
55
+
56
+ static fromNano(value: NanoXL1) {
57
+ return this.from(value, XL1Places.nano)
58
+ }
59
+
60
+ static fromPico(value: PicoXL1) {
61
+ return this.from(value, XL1Places.pico)
62
+ }
63
+
64
+ static fromFemto(value: FemtoXL1) {
65
+ return this.from(value, XL1Places.femto)
66
+ }
67
+
68
+ static fromAtto(value: AttoXL1) {
69
+ return this.from(value, XL1Places.atto)
70
+ }
71
+
72
+ to(places: number | bigint = XL1Places.atto) {
73
+ return this.value / 10n ** BigInt(places)
74
+ }
75
+
76
+ get milli() {
77
+ return MilliXL1(this.to(XL1Places.micro))
78
+ }
79
+
80
+ get micro() {
81
+ return MicroXL1(this.to(XL1Places.micro))
82
+ }
83
+
84
+ get nano() {
85
+ return NanoXL1(this.to(XL1Places.nano))
86
+ }
87
+
88
+ get pico() {
89
+ return PicoXL1(this.to(XL1Places.pico))
90
+ }
91
+
92
+ get femto() {
93
+ return FemtoXL1(this.to(XL1Places.femto))
94
+ }
95
+
96
+ get atto() {
97
+ return AttoXL1(this.to(XL1Places.atto))
98
+ }
99
+
100
+ toString(places: number = Number(XL1Places.atto), config: Partial<ShiftedBigIntConfig> = {}): string {
101
+ assertEx(allowedPlaces.includes(BigInt(places)), () => `Invalid conversion places (${places} not in ${allowedPlaces})`)
102
+ return new ShiftedBigInt(
103
+ this.value,
104
+ {
105
+ places,
106
+ locale: this.locale,
107
+ maxDecimal: places,
108
+ minDecimals: 0,
109
+ maxCharacters: places,
110
+ ...config,
111
+ },
112
+ ).toShortString()
113
+ }
114
+ }
@@ -0,0 +1,4 @@
1
+ export * from './ShiftedBigInt.ts'
2
+ export * from './splitOnDecimal.ts'
3
+ export * from './splitOnDecimalToString.ts'
4
+ export * from './Xl1Amount.ts'
@@ -0,0 +1,5 @@
1
+ export const splitOnDecimal = (value: bigint, places = 18): [bigint, bigint] => {
2
+ const whole = value / BigInt(10 ** places)
3
+ const decimal = value % BigInt(10 ** places)
4
+ return [whole, decimal]
5
+ }
@@ -0,0 +1,37 @@
1
+ import { splitOnDecimal } from './splitOnDecimal.ts'
2
+
3
+ export const splitOnDecimalToString = (
4
+ value: bigint,
5
+ places = 18,
6
+ maxDecimal = places,
7
+ maxCharacters = 9,
8
+ minDecimals = 1,
9
+ locale: Intl.LocalesArgument = 'en-US',
10
+ ): string => {
11
+ const [whole, decimal] = splitOnDecimal(value, places)
12
+ if (whole === 0n && decimal < 10 ** maxDecimal && decimal !== 0n) return '< 0.'.padEnd(maxDecimal + 5, '0') + '1'
13
+
14
+ const wholeCharacters = whole.toString(10).length
15
+ const calcMaxDecimalCharacters = maxCharacters === -1 ? places : wholeCharacters > maxCharacters ? 0 : maxCharacters - wholeCharacters
16
+ const maxDecimalCharacters = Math.min(maxDecimal, calcMaxDecimalCharacters)
17
+
18
+ // Format whole number with thousand separators according to locale
19
+ const formattedWhole = new Intl.NumberFormat(locale, {
20
+ maximumFractionDigits: 0,
21
+ useGrouping: true,
22
+ }).format(whole)
23
+
24
+ // Get decimal separator for the locale
25
+ const decimalSeparator = new Intl.NumberFormat(locale)
26
+ .formatToParts(1.1)
27
+ .find(part => part.type === 'decimal')?.value ?? '.'
28
+
29
+ // Pad decimal part to correct number of places
30
+ let paddedDecimal = decimal.toString().padStart(places, '0').slice(0, maxDecimalCharacters)
31
+ // remove unneeded trailing zeros (honoring minDecimals)
32
+ while (paddedDecimal.length > minDecimals && paddedDecimal.endsWith('0')) {
33
+ paddedDecimal = paddedDecimal.slice(0, -1)
34
+ }
35
+
36
+ return `${formattedWhole}${paddedDecimal.length > 0 ? decimalSeparator : ''}${paddedDecimal}`
37
+ }
@@ -0,0 +1,10 @@
1
+ import type { Address } from '@xylabs/hex'
2
+
3
+ import type { BaseWrapperConfig } from '../Base.ts'
4
+ import { BaseWrapper } from '../Base.ts'
5
+
6
+ export class ChainWrapper extends BaseWrapper<Address, BaseWrapperConfig<Address>> {
7
+ get id(): Address {
8
+ return this.value
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ export * from './chain.ts'
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
+ export * from './amount/index.ts'
1
2
  export * from './Base.ts'
3
+ export * from './chain/index.ts'
2
4
  export * from './Fees.ts'
3
5
  export * from './lib/index.ts'
4
6
  export * from './Signature.ts'