@@ -9,7 +9,7 @@ import { VerificationKey } from '../../proof-system/verification-key.js';
99import { Bool } from '../../provable/bool.js' ;
1010import { Field } from '../../provable/field.js' ;
1111import { UInt32 , UInt64 , Int64 , Sign } from '../../provable/int.js' ;
12- import { PublicKey , PrivateKey } from '../../provable/crypto/signature.js' ;
12+ import { PrivateKey } from '../../provable/crypto/signature.js' ;
1313import {
1414 Actions as V1Actions ,
1515 Events as V1Events ,
@@ -24,6 +24,19 @@ import { jsLayout as layoutV1 } from '../../../bindings/mina-transaction/gen/v1/
2424import { expect } from 'expect' ;
2525
2626import { ZkappConstants } from '../v1/constants.js' ;
27+ import {
28+ testV1V2ClassEquivalence ,
29+ testV1V2ValueEquivalence ,
30+ testV2Encoding ,
31+ } from './test/utils.js' ;
32+ import {
33+ Signature ,
34+ signFieldElement ,
35+ zkAppBodyPrefix ,
36+ } from '../../../mina-signer/src/signature.js' ;
37+
38+ import { Types } from '../../../bindings/mina-transaction/v1/types.js' ;
39+ import { packToFields , hashWithPrefix } from '../../../lib/provable/crypto/poseidon.js' ;
2740
2841function testHashEquality ( v1 : TypesV1 . AccountUpdate , v2 : Authorized ) {
2942 expect ( TypesV1 . AccountUpdate . toInput ( v1 ) ) . toEqual ( v2 . toInput ( ) ) ;
@@ -425,54 +438,39 @@ const v2AccountUpdate: Authorized = new Authorized(
425438{
426439 // TODO: the fact that all these extra type-annotation are required means we didn't encode this
427440 // type well for typescript's poor type inference
428- // testV2Encoding<Authorized>(Authorized, v2AccountUpdate);
429- /*
441+ testV2Encoding < Authorized > ( Authorized , v2AccountUpdate ) ;
442+
430443 testV1V2ClassEquivalence < number , TypesV1 . AccountUpdate , Authorized > (
431444 V1AccountUpdate ,
432445 Authorized ,
433446 0
434447 ) ;
435- */
436- testHashEquality ( V1AccountUpdate . empty ( ) , Authorized . empty ( ) ) ;
437448
438- /*
449+ testHashEquality ( V1AccountUpdate . empty ( ) , Authorized . empty ( ) ) ;
439450 testV1V2ValueEquivalence < number , TypesV1 . AccountUpdate , Authorized > (
440451 V1AccountUpdate ,
441452 Authorized ,
442453 v1AccountUpdate ,
443454 v2AccountUpdate ,
444455 2
445456 ) ;
446- */
457+
447458 testHashEquality ( v1AccountUpdate , v2AccountUpdate ) ;
448459}
449460
450461// signature test
451462{
452- const v2Update = v2AccountUpdate . toAccountUpdate ( ) ;
453-
454- const v2UpdateSigned = await v2Update . authorize ( {
455- networkId : 'testnet' ,
456- async getPrivateKey ( pk : PublicKey ) : Promise < PrivateKey > {
457- if ( pk !== publicKey ) throw new Error ( ) ;
458- return privateKey ;
459- } ,
460- accountUpdateForestCommitment : BigInt ( 0 ) ,
461- fullTransactionCommitment : BigInt ( 0 ) ,
462- } ) ;
463-
464- // TODO: We need to actually ensure the signatures match the old implementation, but the old
465- // interface makes this test annoying to implement, so skipping for right now.
466- console . log ( `signature = ${ JSON . stringify ( v2UpdateSigned . authorization . signature ) } ` ) ;
463+ let v1Hash = hashWithPrefix (
464+ zkAppBodyPrefix ( 'testnet' ) ,
465+ packToFields ( Types . AccountUpdate . toInput ( v1AccountUpdate ) )
466+ ) ;
467+ let v1Signature = signFieldElement ( v1Hash . toBigInt ( ) , privateKey . toBigInt ( ) , 'testnet' ) ;
467468
468- /*
469- // HACK
470- const v1Update = {...v2AccountUpdate} as unknown as V1AccountUpdateImpl;
471- Object.setPrototypeOf(v1Update, V1AccountUpdateImpl.prototype);
469+ const v2Update = v2AccountUpdate . toAccountUpdate ( ) ;
470+ let v2Hash = v2Update . commit ( 'testnet' ) . accountUpdateCommitment . toBigInt ( ) ;
471+ let v2Signature = signFieldElement ( v2Hash , privateKey . toBigInt ( ) , 'testnet' ) ;
472472
473- expect(v2UpdateSigned.authorization.signature)
474- .toEqual(v1Update.authorization.signature);
475- */
473+ expect ( Signature . toBase58 ( v1Signature ) ) . toEqual ( Signature . toBase58 ( v2Signature ) ) ;
476474}
477475
478476console . log ( '\n:)' ) ;
0 commit comments