@@ -56,13 +56,13 @@ export class VMInstance {
56
56
}
57
57
58
58
public allocate ( size : number ) : Region {
59
- let { allocate, memory } = this . exports ;
59
+ let { allocate, memory} = this . exports ;
60
60
let regPtr = allocate ( size ) ;
61
61
return new Region ( memory , regPtr ) ;
62
62
}
63
63
64
64
public deallocate ( region : Region ) : void {
65
- let { deallocate } = this . exports ;
65
+ let { deallocate} = this . exports ;
66
66
deallocate ( region . ptr ) ;
67
67
}
68
68
@@ -95,35 +95,35 @@ export class VMInstance {
95
95
}
96
96
97
97
public instantiate ( env : Env , info : MessageInfo , msg : object ) : Region {
98
- let { instantiate } = this . exports ;
98
+ let { instantiate} = this . exports ;
99
99
let args = [ env , info , msg ] . map ( ( x ) => this . allocate_json ( x ) . ptr ) ;
100
100
let result = instantiate ( ...args ) ;
101
101
return this . region ( result ) ;
102
102
}
103
103
104
104
public execute ( env : Env , info : MessageInfo , msg : object ) : Region {
105
- let { execute } = this . exports ;
105
+ let { execute} = this . exports ;
106
106
let args = [ env , info , msg ] . map ( ( x ) => this . allocate_json ( x ) . ptr ) ;
107
107
let result = execute ( ...args ) ;
108
108
return this . region ( result ) ;
109
109
}
110
110
111
111
public query ( env : Env , msg : object ) : Region {
112
- let { query } = this . exports ;
112
+ let { query} = this . exports ;
113
113
let args = [ env , msg ] . map ( ( x ) => this . allocate_json ( x ) . ptr ) ;
114
114
let result = query ( ...args ) ;
115
115
return this . region ( result ) ;
116
116
}
117
117
118
118
public migrate ( env : Env , msg : object ) : Region {
119
- let { migrate } = this . exports ;
119
+ let { migrate} = this . exports ;
120
120
let args = [ env , msg ] . map ( ( x ) => this . allocate_json ( x ) . ptr ) ;
121
121
let result = migrate ( ...args ) ;
122
122
return this . region ( result ) ;
123
123
}
124
124
125
125
public reply ( env : Env , msg : object ) : Region {
126
- let { reply } = this . exports ;
126
+ let { reply} = this . exports ;
127
127
let args = [ env , msg ] . map ( ( x ) => this . allocate_json ( x ) . ptr ) ;
128
128
let result = reply ( ...args ) ;
129
129
return this . region ( result ) ;
@@ -174,9 +174,9 @@ export class VMInstance {
174
174
}
175
175
176
176
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
180
180
) : number {
181
181
let hash = this . region ( hash_ptr ) ;
182
182
let signature = this . region ( signature_ptr ) ;
@@ -185,19 +185,19 @@ export class VMInstance {
185
185
}
186
186
187
187
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 {
192
192
let hash = this . region ( hash_ptr ) ;
193
193
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 ) ;
195
195
}
196
196
197
197
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
201
201
) : number {
202
202
let message = this . region ( message_ptr ) ;
203
203
let signature = this . region ( signature_ptr ) ;
@@ -206,9 +206,9 @@ export class VMInstance {
206
206
}
207
207
208
208
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
212
212
) : number {
213
213
let messages = this . region ( messages_ptr ) ;
214
214
let signatures = this . region ( signatures_ptr ) ;
@@ -284,12 +284,12 @@ export class VMInstance {
284
284
}
285
285
286
286
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
+ ] ) ) ;
293
293
}
294
294
295
295
do_addr_humanize ( source : Region , destination : Region ) : Region {
@@ -329,7 +329,7 @@ export class VMInstance {
329
329
}
330
330
331
331
const canonical = this . bech32 . fromWords (
332
- this . bech32 . decode ( source . str ) . words
332
+ this . bech32 . decode ( source . str ) . words
333
333
) ;
334
334
335
335
if ( canonical . length === 0 ) {
@@ -338,8 +338,8 @@ export class VMInstance {
338
338
339
339
// TODO: Change prefix to be configurable per environment
340
340
const human = this . bech32 . encode (
341
- this . PREFIX ,
342
- this . bech32 . toWords ( canonical )
341
+ this . PREFIX ,
342
+ this . bech32 . toWords ( canonical )
343
343
) ;
344
344
if ( human !== source . str ) {
345
345
throw new Error ( 'Invalid address.' ) ;
@@ -351,12 +351,12 @@ export class VMInstance {
351
351
// Returns 0 on verification success, 1 on verification failure
352
352
do_secp256k1_verify ( hash : Region , signature : Region , pubkey : Region ) : number {
353
353
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 } `
355
355
) ;
356
356
const isValidSignature = ecdsaVerify (
357
- signature . data ,
358
- hash . data ,
359
- pubkey . data
357
+ signature . data ,
358
+ hash . data ,
359
+ pubkey . data
360
360
) ;
361
361
362
362
if ( isValidSignature ) {
@@ -367,19 +367,20 @@ export class VMInstance {
367
367
}
368
368
369
369
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 ) ;
375
376
}
376
377
377
378
// Verifies a message against a signature with a public key, using the ed25519 EdDSA scheme.
378
379
// Returns 0 on verification success, 1 on verification failure
379
380
do_ed25519_verify (
380
- message : Region ,
381
- signature : Region ,
382
- pubkey : Region
381
+ message : Region ,
382
+ signature : Region ,
383
+ pubkey : Region
383
384
) : number {
384
385
const sig = Buffer . from ( signature . data ) . toString ( 'hex' ) ;
385
386
const pub = Buffer . from ( pubkey . data ) . toString ( 'hex' ) ;
@@ -400,9 +401,9 @@ export class VMInstance {
400
401
// using the ed25519 EdDSA scheme.
401
402
// Returns 0 on verification success (all batches verify correctly), 1 on verification failure
402
403
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
406
407
) : number {
407
408
let messages = decodeSections ( messages_ptr . data ) ;
408
409
let signatures = decodeSections ( signatures_ptr . data ) ;
0 commit comments