UNPKG

gnablib

Version:

A lean, zero dependency library to provide a useful base for your project.

2 lines 1.29 kB
/*! Copyright 2024-2025 the gnablib contributors MPL-1.1 */ import{sLen as t}from"../../safe/safe.js";import{AInt as r}from"./_AInt.js";export class U256 extends r{constructor(t,r,n="U256"){super(t,r,8,n)}static fromInt(t){return new U256(r._fromInt(8,t),0)}static fromI32s(...t){const n=r._fromSet(8,t);return new U256(n,0)}static fromBytesBE(t,r=0){return new U256(this._fromBytesBE(32,t,r),0)}static mount(r,n=0){return t("arr",r).atLeast(n+8).throwNot(),new U256(r,n)}clone(){return new U256(this._arr.slice(this._pos,this._pos+8),0)}lShift(t){const r=this.clone();return r._lShiftEq(t),r}rShift(t){const r=this.clone();return r._rShiftEq(t),r}lRot(t){const r=this.clone();return r._lRotEq(t),r}rRot(t){const r=this.clone();return r._lRotEq(256-t),r}xor(t){const r=this.clone();return r._xorEq(t),r}or(t){const r=this.clone();return r._orEq(t),r}and(t){const r=this.clone();return r._andEq(t),r}not(){const t=this.clone();return t._notEq(),t}add(t){const r=this.clone();return r._addEq(t),r}sub(t){const r=this.clone();return r._subEq(t),r}mul(t){const r=this._mul(t);return new U256(r,0)}eq(t){return super.eq(t)}gt(t){return super.gt(t)}gte(t){return super.gte(t)}lt(t){return super.lt(t)}lte(t){return super.lte(t)}static get zero(){return n}}const n=U256.mount(new Uint32Array(8),0);