@@ -12,32 +12,32 @@ import { asBytes, asBytesCls, asUint8Array, conactUint8Arrays } from '../util'
1212import type { StubBytesCompat , StubUint64Compat } from './primitives'
1313import { Bytes , BytesCls , Uint64Cls } from './primitives'
1414
15- export const sha256 = ( a : StubBytesCompat ) : bytes => {
15+ export const sha256 = ( a : StubBytesCompat ) : bytes < 32 > => {
1616 const bytesA = BytesCls . fromCompat ( a )
1717 const hashArray = js_sha256 . sha256 . create ( ) . update ( bytesA . asUint8Array ( ) ) . digest ( )
1818 const hashBytes = BytesCls . fromCompat ( new Uint8Array ( hashArray ) )
19- return hashBytes . asAlgoTs ( )
19+ return hashBytes . asAlgoTs ( ) . toFixed ( { length : 32 } )
2020}
2121
22- export const sha3_256 = ( a : StubBytesCompat ) : bytes => {
22+ export const sha3_256 = ( a : StubBytesCompat ) : bytes < 32 > => {
2323 const bytesA = BytesCls . fromCompat ( a )
2424 const hashArray = js_sha3 . sha3_256 . create ( ) . update ( bytesA . asUint8Array ( ) ) . digest ( )
2525 const hashBytes = BytesCls . fromCompat ( new Uint8Array ( hashArray ) )
26- return hashBytes . asAlgoTs ( )
26+ return hashBytes . asAlgoTs ( ) . toFixed ( { length : 32 } )
2727}
2828
29- export const keccak256 = ( a : StubBytesCompat ) : bytes => {
29+ export const keccak256 = ( a : StubBytesCompat ) : bytes < 32 > => {
3030 const bytesA = BytesCls . fromCompat ( a )
3131 const hashArray = js_sha3 . keccak256 . create ( ) . update ( bytesA . asUint8Array ( ) ) . digest ( )
3232 const hashBytes = BytesCls . fromCompat ( new Uint8Array ( hashArray ) )
33- return hashBytes . asAlgoTs ( )
33+ return hashBytes . asAlgoTs ( ) . toFixed ( { length : 32 } )
3434}
3535
36- export const sha512_256 = ( a : StubBytesCompat ) : bytes => {
36+ export const sha512_256 = ( a : StubBytesCompat ) : bytes < 32 > => {
3737 const bytesA = BytesCls . fromCompat ( a )
3838 const hashArray = js_sha512 . sha512_256 . create ( ) . update ( bytesA . asUint8Array ( ) ) . digest ( )
3939 const hashBytes = BytesCls . fromCompat ( new Uint8Array ( hashArray ) )
40- return hashBytes . asAlgoTs ( )
40+ return hashBytes . asAlgoTs ( ) . toFixed ( { length : 32 } )
4141}
4242
4343export const ed25519verifyBare = ( a : StubBytesCompat , b : StubBytesCompat , c : StubBytesCompat ) : boolean => {
@@ -88,7 +88,7 @@ export const ecdsaPkRecover = (
8888 b : StubUint64Compat ,
8989 c : StubBytesCompat ,
9090 d : StubBytesCompat ,
91- ) : readonly [ bytes , bytes ] => {
91+ ) : readonly [ bytes < 32 > , bytes < 32 > ] => {
9292 if ( v !== Ecdsa . Secp256k1 ) {
9393 throw new InternalError ( `Unsupported ECDSA curve: ${ v } ` )
9494 }
@@ -106,10 +106,10 @@ export const ecdsaPkRecover = (
106106
107107 const x = pubKey . getX ( ) . toArray ( 'be' )
108108 const y = pubKey . getY ( ) . toArray ( 'be' )
109- return [ Bytes ( x ) , Bytes ( y ) ]
109+ return [ Bytes ( x ) . toFixed ( { length : 32 } ) , Bytes ( y ) . toFixed ( { length : 32 } ) ]
110110}
111111
112- export const ecdsaPkDecompress = ( v : Ecdsa , a : StubBytesCompat ) : readonly [ bytes , bytes ] => {
112+ export const ecdsaPkDecompress = ( v : Ecdsa , a : StubBytesCompat ) : readonly [ bytes < 32 > , bytes < 32 > ] => {
113113 const bytesA = BytesCls . fromCompat ( a )
114114
115115 const ecdsa = new elliptic . ec ( curveMap [ v ] )
@@ -118,10 +118,10 @@ export const ecdsaPkDecompress = (v: Ecdsa, a: StubBytesCompat): readonly [bytes
118118
119119 const x = pubKey . getX ( ) . toArray ( 'be' )
120120 const y = pubKey . getY ( ) . toArray ( 'be' )
121- return [ Bytes ( new Uint8Array ( x ) ) , Bytes ( new Uint8Array ( y ) ) ]
121+ return [ Bytes ( new Uint8Array ( x ) ) . toFixed ( { length : 32 } ) , Bytes ( new Uint8Array ( y ) ) . toFixed ( { length : 32 } ) ]
122122}
123123
124- export const vrfVerify = ( _s : VrfVerify , _a : StubBytesCompat , _b : StubBytesCompat , _c : StubBytesCompat ) : readonly [ bytes , boolean ] => {
124+ export const vrfVerify = ( _s : VrfVerify , _a : StubBytesCompat , _b : StubBytesCompat , _c : StubBytesCompat ) : readonly [ bytes < 64 > , boolean ] => {
125125 throw new NotImplementedError ( 'vrfVerify' )
126126}
127127
0 commit comments