@@ -56,13 +56,13 @@ export class VMInstance {
5656 }
5757
5858 public allocate ( size : number ) : Region {
59- let { allocate, memory } = this . exports ;
59+ let { allocate, memory} = this . exports ;
6060 let regPtr = allocate ( size ) ;
6161 return new Region ( memory , regPtr ) ;
6262 }
6363
6464 public deallocate ( region : Region ) : void {
65- let { deallocate } = this . exports ;
65+ let { deallocate} = this . exports ;
6666 deallocate ( region . ptr ) ;
6767 }
6868
@@ -95,35 +95,35 @@ export class VMInstance {
9595 }
9696
9797 public instantiate ( env : Env , info : MessageInfo , msg : object ) : Region {
98- let { instantiate } = this . exports ;
98+ let { instantiate} = this . exports ;
9999 let args = [ env , info , msg ] . map ( ( x ) => this . allocate_json ( x ) . ptr ) ;
100100 let result = instantiate ( ...args ) ;
101101 return this . region ( result ) ;
102102 }
103103
104104 public execute ( env : Env , info : MessageInfo , msg : object ) : Region {
105- let { execute } = this . exports ;
105+ let { execute} = this . exports ;
106106 let args = [ env , info , msg ] . map ( ( x ) => this . allocate_json ( x ) . ptr ) ;
107107 let result = execute ( ...args ) ;
108108 return this . region ( result ) ;
109109 }
110110
111111 public query ( env : Env , msg : object ) : Region {
112- let { query } = this . exports ;
112+ let { query} = this . exports ;
113113 let args = [ env , msg ] . map ( ( x ) => this . allocate_json ( x ) . ptr ) ;
114114 let result = query ( ...args ) ;
115115 return this . region ( result ) ;
116116 }
117117
118118 public migrate ( env : Env , msg : object ) : Region {
119- let { migrate } = this . exports ;
119+ let { migrate} = this . exports ;
120120 let args = [ env , msg ] . map ( ( x ) => this . allocate_json ( x ) . ptr ) ;
121121 let result = migrate ( ...args ) ;
122122 return this . region ( result ) ;
123123 }
124124
125125 public reply ( env : Env , msg : object ) : Region {
126- let { reply } = this . exports ;
126+ let { reply} = this . exports ;
127127 let args = [ env , msg ] . map ( ( x ) => this . allocate_json ( x ) . ptr ) ;
128128 let result = reply ( ...args ) ;
129129 return this . region ( result ) ;
@@ -174,9 +174,9 @@ export class VMInstance {
174174 }
175175
176176 secp256k1_verify (
177- hash_ptr : number ,
178- signature_ptr : number ,
179- pubkey_ptr : number
177+ hash_ptr : number ,
178+ signature_ptr : number ,
179+ pubkey_ptr : number
180180 ) : number {
181181 let hash = this . region ( hash_ptr ) ;
182182 let signature = this . region ( signature_ptr ) ;
@@ -185,19 +185,19 @@ export class VMInstance {
185185 }
186186
187187 secp256k1_recover_pubkey (
188- hash_ptr : number ,
189- signature_ptr : number ,
190- recover_param : number
191- ) : Uint8Array {
188+ hash_ptr : number ,
189+ signature_ptr : number ,
190+ recover_param : number
191+ ) : bigint {
192192 let hash = this . region ( hash_ptr ) ;
193193 let signature = this . region ( signature_ptr ) ;
194- return this . do_secp256k1_recover_pubkey ( hash , signature , recover_param ) ;
194+ return BigInt ( this . do_secp256k1_recover_pubkey ( hash , signature , recover_param ) . ptr ) ;
195195 }
196196
197197 ed25519_verify (
198- message_ptr : number ,
199- signature_ptr : number ,
200- pubkey_ptr : number
198+ message_ptr : number ,
199+ signature_ptr : number ,
200+ pubkey_ptr : number
201201 ) : number {
202202 let message = this . region ( message_ptr ) ;
203203 let signature = this . region ( signature_ptr ) ;
@@ -206,9 +206,9 @@ export class VMInstance {
206206 }
207207
208208 ed25519_batch_verify (
209- messages_ptr : number ,
210- signatures_ptr : number ,
211- public_keys_ptr : number
209+ messages_ptr : number ,
210+ signatures_ptr : number ,
211+ public_keys_ptr : number
212212 ) : number {
213213 let messages = this . region ( messages_ptr ) ;
214214 let signatures = this . region ( signatures_ptr ) ;
@@ -284,12 +284,12 @@ export class VMInstance {
284284 }
285285
286286 return this . allocate_bytes ( new Uint8Array (
287- [
288- ...record . key ,
289- ...toByteArray ( record . key . length , 4 ) ,
290- ...record . value ,
291- ...toByteArray ( record . value . length , 4 )
292- ] ) ) ;
287+ [
288+ ...record . key ,
289+ ...toByteArray ( record . key . length , 4 ) ,
290+ ...record . value ,
291+ ...toByteArray ( record . value . length , 4 )
292+ ] ) ) ;
293293 }
294294
295295 do_addr_humanize ( source : Region , destination : Region ) : Region {
@@ -329,7 +329,7 @@ export class VMInstance {
329329 }
330330
331331 const canonical = this . bech32 . fromWords (
332- this . bech32 . decode ( source . str ) . words
332+ this . bech32 . decode ( source . str ) . words
333333 ) ;
334334
335335 if ( canonical . length === 0 ) {
@@ -338,8 +338,8 @@ export class VMInstance {
338338
339339 // TODO: Change prefix to be configurable per environment
340340 const human = this . bech32 . encode (
341- this . PREFIX ,
342- this . bech32 . toWords ( canonical )
341+ this . PREFIX ,
342+ this . bech32 . toWords ( canonical )
343343 ) ;
344344 if ( human !== source . str ) {
345345 throw new Error ( 'Invalid address.' ) ;
@@ -351,12 +351,12 @@ export class VMInstance {
351351 // Returns 0 on verification success, 1 on verification failure
352352 do_secp256k1_verify ( hash : Region , signature : Region , pubkey : Region ) : number {
353353 console . log (
354- `signature length: ${ signature . str . length } , pubkey length: ${ pubkey . str . length } , message length: ${ hash . str . length } `
354+ `signature length: ${ signature . str . length } , pubkey length: ${ pubkey . str . length } , message length: ${ hash . str . length } `
355355 ) ;
356356 const isValidSignature = ecdsaVerify (
357- signature . data ,
358- hash . data ,
359- pubkey . data
357+ signature . data ,
358+ hash . data ,
359+ pubkey . data
360360 ) ;
361361
362362 if ( isValidSignature ) {
@@ -367,19 +367,20 @@ export class VMInstance {
367367 }
368368
369369 do_secp256k1_recover_pubkey (
370- hash : Region ,
371- signature : Region ,
372- recover_param : number
373- ) : Uint8Array {
374- return ecdsaRecover ( signature . data , recover_param , hash . data , false ) ;
370+ msgHash : Region ,
371+ signature : Region ,
372+ recover_param : number
373+ ) : Region {
374+ const pub = ecdsaRecover ( signature . data , recover_param , msgHash . data , false ) ;
375+ return this . allocate_bytes ( pub ) ;
375376 }
376377
377378 // Verifies a message against a signature with a public key, using the ed25519 EdDSA scheme.
378379 // Returns 0 on verification success, 1 on verification failure
379380 do_ed25519_verify (
380- message : Region ,
381- signature : Region ,
382- pubkey : Region
381+ message : Region ,
382+ signature : Region ,
383+ pubkey : Region
383384 ) : number {
384385 const sig = Buffer . from ( signature . data ) . toString ( 'hex' ) ;
385386 const pub = Buffer . from ( pubkey . data ) . toString ( 'hex' ) ;
@@ -400,9 +401,9 @@ export class VMInstance {
400401 // using the ed25519 EdDSA scheme.
401402 // Returns 0 on verification success (all batches verify correctly), 1 on verification failure
402403 do_ed25519_batch_verify (
403- messages_ptr : Region ,
404- signatures_ptr : Region ,
405- public_keys_ptr : Region
404+ messages_ptr : Region ,
405+ signatures_ptr : Region ,
406+ public_keys_ptr : Region
406407 ) : number {
407408 let messages = decodeSections ( messages_ptr . data ) ;
408409 let signatures = decodeSections ( signatures_ptr . data ) ;
0 commit comments