File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 binToUtf8 ,
55 vmNumberToBigInt ,
66 isVmNumberError ,
7+ padMinimallyEncodedVmNumber ,
78} from '@bitauth/libauth' ;
89
910export function encodeBool ( bool : boolean ) : Uint8Array {
@@ -26,6 +27,12 @@ export function encodeInt(int: bigint): Uint8Array {
2627 return bigIntToVmNumber ( int ) ;
2728}
2829
30+ export function encodeIntAsFixedBytes ( int : bigint , byteLength : number ) : Uint8Array {
31+ const minimal = encodeInt ( int ) ;
32+ if ( minimal . length > byteLength ) throw new Error ( 'value exceeds the requested byteLength' ) ;
33+ return padMinimallyEncodedVmNumber ( minimal , byteLength ) ;
34+ }
35+
2936export function decodeInt ( encodedInt : Uint8Array , maxLength : number = Infinity ) : bigint {
3037 const options = { maximumVmNumberByteLength : maxLength } ;
3138 const result = vmNumberToBigInt ( encodedInt , options ) ;
You can’t perform that action at this time.
0 commit comments