11import { AlgoAmount } from '@algorandfoundation/algokit-utils/types/amount'
22import { AppSpec } from '@algorandfoundation/algokit-utils/types/app-spec'
3- import { Bytes , internal , op as publicOps , uint64 } from '@algorandfoundation/algorand-typescript'
3+ import { Bytes , Ec , Ecdsa , internal , uint64 , VrfVerify } from '@algorandfoundation/algorand-typescript'
44import algosdk from 'algosdk'
55import { ec } from 'elliptic'
66import { keccak256 as js_keccak256 } from 'js-sha3'
@@ -15,8 +15,8 @@ import { asUint8Array, getPaddedBytes } from './util'
1515
1616const MAX_ARG_LEN = 2048
1717const curveMap = {
18- [ internal . opTypes . Ecdsa . Secp256k1 ] : 'secp256k1' ,
19- [ internal . opTypes . Ecdsa . Secp256r1 ] : 'p256' ,
18+ [ Ecdsa . Secp256k1 ] : 'secp256k1' ,
19+ [ Ecdsa . Secp256r1 ] : 'p256' ,
2020}
2121
2222vi . mock ( '../src/impl/crypto' , async ( importOriginal ) => {
@@ -157,7 +157,7 @@ describe('crypto op codes', async () => {
157157 asUint8Array ( pubkeyX ) ,
158158 asUint8Array ( pubkeyY ) ,
159159 )
160- const result = op . ecdsaVerify ( internal . opTypes . Ecdsa . Secp256k1 , messageHash , sigR , sigS , pubkeyX , pubkeyY )
160+ const result = op . ecdsaVerify ( Ecdsa . Secp256k1 , messageHash , sigR , sigS , pubkeyX , pubkeyY )
161161
162162 expect ( result ) . toEqual ( avmResult )
163163 } )
@@ -177,15 +177,15 @@ describe('crypto op codes', async () => {
177177 asUint8Array ( pubkeyX ) ,
178178 asUint8Array ( pubkeyY ) ,
179179 )
180- const result = op . ecdsaVerify ( internal . opTypes . Ecdsa . Secp256r1 , messageHash , sigR , sigS , pubkeyX , pubkeyY )
180+ const result = op . ecdsaVerify ( Ecdsa . Secp256r1 , messageHash , sigR , sigS , pubkeyX , pubkeyY )
181181
182182 expect ( result ) . toEqual ( avmResult )
183183 } )
184184 } )
185185
186186 describe ( 'ecdsaPkRecover' , async ( ) => {
187187 it ( 'should be able to recover k1 public key' , async ( ) => {
188- const testData = generateEcdsaTestData ( internal . opTypes . Ecdsa . Secp256k1 )
188+ const testData = generateEcdsaTestData ( Ecdsa . Secp256k1 )
189189 const a = testData . data
190190 const b = testData . recoveryId
191191 const c = testData . r
@@ -198,14 +198,14 @@ describe('crypto op codes', async () => {
198198 asUint8Array ( c ) ,
199199 asUint8Array ( d ) ,
200200 )
201- const result = op . ecdsaPkRecover ( internal . opTypes . Ecdsa . Secp256k1 , a , b , c , d )
201+ const result = op . ecdsaPkRecover ( Ecdsa . Secp256k1 , a , b , c , d )
202202
203203 expect ( result [ 0 ] ) . toEqual ( avmResult [ 0 ] )
204204 expect ( result [ 1 ] ) . toEqual ( avmResult [ 1 ] )
205205 } )
206206
207207 it ( 'should throw unsupported error when trying to recover r1 public key' , async ( ) => {
208- const testData = generateEcdsaTestData ( internal . opTypes . Ecdsa . Secp256r1 )
208+ const testData = generateEcdsaTestData ( Ecdsa . Secp256r1 )
209209 const a = testData . data
210210 const b = testData . recoveryId
211211 const c = testData . r
@@ -221,13 +221,13 @@ describe('crypto op codes', async () => {
221221 ) ,
222222 ) . rejects . toThrow ( 'unsupported curve' )
223223
224- expect ( ( ) => op . ecdsaPkRecover ( internal . opTypes . Ecdsa . Secp256r1 , a , b , c , d ) ) . toThrow ( 'Unsupported ECDSA curve' )
224+ expect ( ( ) => op . ecdsaPkRecover ( Ecdsa . Secp256r1 , a , b , c , d ) ) . toThrow ( 'Unsupported ECDSA curve' )
225225 } )
226226 } )
227227
228228 describe ( 'ecdsaPkDecompress' , async ( ) => {
229229 it ( 'should be able to decompress k1 public key' , async ( ) => {
230- const v = internal . opTypes . Ecdsa . Secp256k1
230+ const v = Ecdsa . Secp256k1
231231 const testData = generateEcdsaTestData ( v )
232232 const ecdsa = new ec ( curveMap [ v ] )
233233 const keyPair = ecdsa . keyFromPublic ( testData . pubkeyX . concat ( testData . pubkeyY ) . asUint8Array ( ) )
@@ -252,7 +252,7 @@ describe('crypto op codes', async () => {
252252 const c = internal . primitives . BytesCls . fromHex ( '3a2740da7a0788ebb12a52154acbcca1813c128ca0b249e93f8eb6563fee418d' )
253253
254254 it ( 'should throw not available error' , async ( ) => {
255- expect ( ( ) => op . vrfVerify ( internal . opTypes . VrfVerify . VrfAlgorand , a , b , c ) ) . toThrow ( 'vrfVerify is not available in test context' )
255+ expect ( ( ) => op . vrfVerify ( VrfVerify . VrfAlgorand , a , b , c ) ) . toThrow ( 'vrfVerify is not available in test context' )
256256 } )
257257
258258 it ( 'should return mocked result' , async ( ) => {
@@ -265,7 +265,7 @@ describe('crypto op codes', async () => {
265265 )
266266 const mockedVrfVerify = ( op as unknown as { mockedVrfVerify : Mock < typeof op . vrfVerify > } ) . mockedVrfVerify
267267 mockedVrfVerify . mockReturnValue ( [ internal . primitives . BytesCls . fromCompat ( new Uint8Array ( avmResult [ 0 ] ) ) . asAlgoTs ( ) , avmResult [ 1 ] ] )
268- const result = mockedVrfVerify ( publicOps . VrfVerify . VrfAlgorand , a , b , c )
268+ const result = mockedVrfVerify ( VrfVerify . VrfAlgorand , a , b , c )
269269
270270 expect ( asUint8Array ( result [ 0 ] ) ) . toEqual ( new Uint8Array ( avmResult [ 0 ] ) )
271271 expect ( result [ 1 ] ) . toEqual ( avmResult [ 1 ] )
@@ -274,29 +274,25 @@ describe('crypto op codes', async () => {
274274
275275 describe ( 'EllipticCurve' , async ( ) => {
276276 it ( 'should throw not available error' , async ( ) => {
277- expect ( ( ) => op . EllipticCurve . add ( internal . opTypes . Ec . BN254g2 , Bytes ( '' ) , Bytes ( '' ) ) ) . toThrow (
278- 'EllipticCurve.add is not available in test context' ,
279- )
280- expect ( ( ) => op . EllipticCurve . mapTo ( internal . opTypes . Ec . BN254g2 , Bytes ( '' ) ) ) . toThrow (
281- 'EllipticCurve.mapTo is not available in test context' ,
282- )
283- expect ( ( ) => op . EllipticCurve . pairingCheck ( internal . opTypes . Ec . BN254g2 , Bytes ( '' ) , Bytes ( '' ) ) ) . toThrow (
277+ expect ( ( ) => op . EllipticCurve . add ( Ec . BN254g2 , Bytes ( '' ) , Bytes ( '' ) ) ) . toThrow ( 'EllipticCurve.add is not available in test context' )
278+ expect ( ( ) => op . EllipticCurve . mapTo ( Ec . BN254g2 , Bytes ( '' ) ) ) . toThrow ( 'EllipticCurve.mapTo is not available in test context' )
279+ expect ( ( ) => op . EllipticCurve . pairingCheck ( Ec . BN254g2 , Bytes ( '' ) , Bytes ( '' ) ) ) . toThrow (
284280 'EllipticCurve.pairingCheck is not available in test context' ,
285281 )
286- expect ( ( ) => op . EllipticCurve . scalarMul ( internal . opTypes . Ec . BN254g2 , Bytes ( '' ) , Bytes ( '' ) ) ) . toThrow (
282+ expect ( ( ) => op . EllipticCurve . scalarMul ( Ec . BN254g2 , Bytes ( '' ) , Bytes ( '' ) ) ) . toThrow (
287283 'EllipticCurve.scalarMul is not available in test context' ,
288284 )
289- expect ( ( ) => op . EllipticCurve . scalarMulMulti ( internal . opTypes . Ec . BN254g2 , Bytes ( '' ) , Bytes ( '' ) ) ) . toThrow (
285+ expect ( ( ) => op . EllipticCurve . scalarMulMulti ( Ec . BN254g2 , Bytes ( '' ) , Bytes ( '' ) ) ) . toThrow (
290286 'EllipticCurve.scalarMulMulti is not available in test context' ,
291287 )
292- expect ( ( ) => op . EllipticCurve . subgroupCheck ( internal . opTypes . Ec . BN254g2 , Bytes ( '' ) ) ) . toThrow (
288+ expect ( ( ) => op . EllipticCurve . subgroupCheck ( Ec . BN254g2 , Bytes ( '' ) ) ) . toThrow (
293289 'EllipticCurve.subgroupCheck is not available in test context' ,
294290 )
295291 } )
296292 } )
297293} )
298294
299- const generateEcdsaTestData = ( v : internal . opTypes . Ecdsa ) => {
295+ const generateEcdsaTestData = ( v : Ecdsa ) => {
300296 const ecdsa = new ec ( curveMap [ v ] )
301297 const keyPair = ecdsa . genKeyPair ( )
302298 const pk = keyPair . getPublic ( 'array' )
0 commit comments