11import type { biguint , BigUintCompat , bytes , BytesCompat , uint64 , Uint64Compat } from '@algorandfoundation/algorand-typescript'
2- import {
3- base64ToUint8Array ,
4- bigIntToUint8Array ,
5- hexToUint8Array ,
6- uint8ArrayToBigInt ,
7- uint8ArrayToHex ,
8- uint8ArrayToUtf8 ,
9- utf8ToUint8Array ,
10- } from '../encoding-util'
2+ import { encodingUtil } from '@algorandfoundation/puya-ts'
113import { avmError , AvmError , avmInvariant , CodeError , InternalError } from '../errors'
124import { nameOfType } from '../typescript-helpers'
135import { base32ToUint8Array } from './base-32'
@@ -309,7 +301,7 @@ export class Uint64Cls extends AlgoTsPrimitiveCls {
309301 }
310302
311303 toBytes ( ) : BytesCls {
312- return new BytesCls ( bigIntToUint8Array ( this . #value, 8 ) )
304+ return new BytesCls ( encodingUtil . bigIntToUint8Array ( this . #value, 8 ) )
313305 }
314306
315307 asAlgoTs ( ) : uint64 {
@@ -348,7 +340,7 @@ export class BigUintCls extends AlgoTsPrimitiveCls {
348340 }
349341
350342 toBytes ( ) : BytesCls {
351- return new BytesCls ( bigIntToUint8Array ( this . #value) )
343+ return new BytesCls ( encodingUtil . bigIntToUint8Array ( this . #value) )
352344 }
353345
354346 asAlgoTs ( ) : biguint {
@@ -435,7 +427,7 @@ export class BytesCls extends AlgoTsPrimitiveCls {
435427 checkBytes ( this . #v)
436428 // Add an enumerable property for debugging code to show
437429 Object . defineProperty ( this , 'bytes' , {
438- value : uint8ArrayToHex ( this . #v) ,
430+ value : encodingUtil . uint8ArrayToHex ( this . #v) ,
439431 writable : false ,
440432 enumerable : true ,
441433 } )
@@ -507,7 +499,7 @@ export class BytesCls extends AlgoTsPrimitiveCls {
507499 }
508500
509501 valueOf ( ) : string {
510- return uint8ArrayToHex ( this . #v)
502+ return encodingUtil . uint8ArrayToHex ( this . #v)
511503 }
512504
513505 static [ Symbol . hasInstance ] ( x : unknown ) : x is BytesCls {
@@ -516,7 +508,7 @@ export class BytesCls extends AlgoTsPrimitiveCls {
516508
517509 static fromCompat ( v : StubBytesCompat | Uint8Array | undefined ) : BytesCls {
518510 if ( v === undefined ) return new BytesCls ( new Uint8Array ( ) )
519- if ( typeof v === 'string' ) return new BytesCls ( utf8ToUint8Array ( v ) )
511+ if ( typeof v === 'string' ) return new BytesCls ( encodingUtil . utf8ToUint8Array ( v ) )
520512 if ( v instanceof BytesCls ) return v
521513 if ( v instanceof Uint8Array ) return new BytesCls ( v )
522514 throw new InternalError ( `Cannot convert ${ nameOfType ( v ) } to bytes` )
@@ -535,27 +527,27 @@ export class BytesCls extends AlgoTsPrimitiveCls {
535527 }
536528
537529 static fromHex ( hex : string ) : BytesCls {
538- return new BytesCls ( hexToUint8Array ( hex ) )
530+ return new BytesCls ( encodingUtil . hexToUint8Array ( hex ) )
539531 }
540532
541533 static fromBase64 ( b64 : string ) : BytesCls {
542- return new BytesCls ( base64ToUint8Array ( b64 ) )
534+ return new BytesCls ( encodingUtil . base64ToUint8Array ( b64 ) )
543535 }
544536
545537 static fromBase32 ( b32 : string ) : BytesCls {
546538 return new BytesCls ( base32ToUint8Array ( b32 ) )
547539 }
548540
549541 toUint64 ( ) : Uint64Cls {
550- return new Uint64Cls ( uint8ArrayToBigInt ( this . #v) )
542+ return new Uint64Cls ( encodingUtil . uint8ArrayToBigInt ( this . #v) )
551543 }
552544
553545 toBigUint ( ) : BigUintCls {
554- return new BigUintCls ( uint8ArrayToBigInt ( this . #v) )
546+ return new BigUintCls ( encodingUtil . uint8ArrayToBigInt ( this . #v) )
555547 }
556548
557549 toString ( ) : string {
558- return uint8ArrayToUtf8 ( this . #v)
550+ return encodingUtil . uint8ArrayToUtf8 ( this . #v)
559551 }
560552
561553 asAlgoTs ( ) : bytes {
0 commit comments