@@ -12,32 +12,32 @@ import { asBytes, asBytesCls, asUint8Array, conactUint8Arrays } from '../util'
12
12
import type { StubBytesCompat , StubUint64Compat } from './primitives'
13
13
import { Bytes , BytesCls , Uint64Cls } from './primitives'
14
14
15
- export const sha256 = ( a : StubBytesCompat ) : bytes => {
15
+ export const sha256 = ( a : StubBytesCompat ) : bytes < 32 > => {
16
16
const bytesA = BytesCls . fromCompat ( a )
17
17
const hashArray = js_sha256 . sha256 . create ( ) . update ( bytesA . asUint8Array ( ) ) . digest ( )
18
18
const hashBytes = BytesCls . fromCompat ( new Uint8Array ( hashArray ) )
19
- return hashBytes . asAlgoTs ( )
19
+ return hashBytes . asAlgoTs ( ) . toFixed ( { length : 32 } )
20
20
}
21
21
22
- export const sha3_256 = ( a : StubBytesCompat ) : bytes => {
22
+ export const sha3_256 = ( a : StubBytesCompat ) : bytes < 32 > => {
23
23
const bytesA = BytesCls . fromCompat ( a )
24
24
const hashArray = js_sha3 . sha3_256 . create ( ) . update ( bytesA . asUint8Array ( ) ) . digest ( )
25
25
const hashBytes = BytesCls . fromCompat ( new Uint8Array ( hashArray ) )
26
- return hashBytes . asAlgoTs ( )
26
+ return hashBytes . asAlgoTs ( ) . toFixed ( { length : 32 } )
27
27
}
28
28
29
- export const keccak256 = ( a : StubBytesCompat ) : bytes => {
29
+ export const keccak256 = ( a : StubBytesCompat ) : bytes < 32 > => {
30
30
const bytesA = BytesCls . fromCompat ( a )
31
31
const hashArray = js_sha3 . keccak256 . create ( ) . update ( bytesA . asUint8Array ( ) ) . digest ( )
32
32
const hashBytes = BytesCls . fromCompat ( new Uint8Array ( hashArray ) )
33
- return hashBytes . asAlgoTs ( )
33
+ return hashBytes . asAlgoTs ( ) . toFixed ( { length : 32 } )
34
34
}
35
35
36
- export const sha512_256 = ( a : StubBytesCompat ) : bytes => {
36
+ export const sha512_256 = ( a : StubBytesCompat ) : bytes < 32 > => {
37
37
const bytesA = BytesCls . fromCompat ( a )
38
38
const hashArray = js_sha512 . sha512_256 . create ( ) . update ( bytesA . asUint8Array ( ) ) . digest ( )
39
39
const hashBytes = BytesCls . fromCompat ( new Uint8Array ( hashArray ) )
40
- return hashBytes . asAlgoTs ( )
40
+ return hashBytes . asAlgoTs ( ) . toFixed ( { length : 32 } )
41
41
}
42
42
43
43
export const ed25519verifyBare = ( a : StubBytesCompat , b : StubBytesCompat , c : StubBytesCompat ) : boolean => {
@@ -88,7 +88,7 @@ export const ecdsaPkRecover = (
88
88
b : StubUint64Compat ,
89
89
c : StubBytesCompat ,
90
90
d : StubBytesCompat ,
91
- ) : readonly [ bytes , bytes ] => {
91
+ ) : readonly [ bytes < 32 > , bytes < 32 > ] => {
92
92
if ( v !== Ecdsa . Secp256k1 ) {
93
93
throw new InternalError ( `Unsupported ECDSA curve: ${ v } ` )
94
94
}
@@ -106,10 +106,10 @@ export const ecdsaPkRecover = (
106
106
107
107
const x = pubKey . getX ( ) . toArray ( 'be' )
108
108
const y = pubKey . getY ( ) . toArray ( 'be' )
109
- return [ Bytes ( x ) , Bytes ( y ) ]
109
+ return [ Bytes ( x ) . toFixed ( { length : 32 } ) , Bytes ( y ) . toFixed ( { length : 32 } ) ]
110
110
}
111
111
112
- export const ecdsaPkDecompress = ( v : Ecdsa , a : StubBytesCompat ) : readonly [ bytes , bytes ] => {
112
+ export const ecdsaPkDecompress = ( v : Ecdsa , a : StubBytesCompat ) : readonly [ bytes < 32 > , bytes < 32 > ] => {
113
113
const bytesA = BytesCls . fromCompat ( a )
114
114
115
115
const ecdsa = new elliptic . ec ( curveMap [ v ] )
@@ -118,10 +118,10 @@ export const ecdsaPkDecompress = (v: Ecdsa, a: StubBytesCompat): readonly [bytes
118
118
119
119
const x = pubKey . getX ( ) . toArray ( 'be' )
120
120
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 } ) ]
122
122
}
123
123
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 ] => {
125
125
throw new NotImplementedError ( 'vrfVerify' )
126
126
}
127
127
0 commit comments