Skip to content

Commit b266b30

Browse files
authored
Merge pull request #30 from algorandfoundation/fix/cjs-import
fix: update import elliptic statement to avoid having to inline node modules
2 parents bfc897d + 312986a commit b266b30

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/impl/crypto.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { arc4, bytes, Bytes, Ecdsa, gtxn, internal, VrfVerify } from '@algorandfoundation/algorand-typescript'
2-
import { ec } from 'elliptic'
2+
import elliptic from 'elliptic'
33
import { sha256 as js_sha256 } from 'js-sha256'
44
import { keccak256 as js_keccak256, sha3_256 as js_sha3_256 } from 'js-sha3'
55
import { sha512_256 as js_sha512_256 } from 'js-sha512'
@@ -84,7 +84,7 @@ export const ecdsaVerify = (
8484
.concat(pubkeyXBytes)
8585
.concat(pubkeyYBytes)
8686

87-
const ecdsa = new ec(curveMap[v])
87+
const ecdsa = new elliptic.ec(curveMap[v])
8888
const keyPair = ecdsa.keyFromPublic(publicKey.asUint8Array())
8989
return keyPair.verify(dataBytes.asUint8Array(), { r: sigRBytes.asUint8Array(), s: sigSBytes.asUint8Array() })
9090
}
@@ -104,7 +104,7 @@ export const ecdsaPkRecover = (
104104
const sBytes = internal.primitives.BytesCls.fromCompat(d)
105105
const recoveryId = internal.primitives.Uint64Cls.fromCompat(b)
106106

107-
const ecdsa = new ec(curveMap[v])
107+
const ecdsa = new elliptic.ec(curveMap[v])
108108
const pubKey = ecdsa.recoverPubKey(
109109
dataBytes.asUint8Array(),
110110
{ r: rBytes.asUint8Array(), s: sBytes.asUint8Array() },
@@ -119,7 +119,7 @@ export const ecdsaPkRecover = (
119119
export const ecdsaPkDecompress = (v: Ecdsa, a: internal.primitives.StubBytesCompat): readonly [bytes, bytes] => {
120120
const bytesA = internal.primitives.BytesCls.fromCompat(a)
121121

122-
const ecdsa = new ec(curveMap[v])
122+
const ecdsa = new elliptic.ec(curveMap[v])
123123
const keyPair = ecdsa.keyFromPublic(bytesA.asUint8Array())
124124
const pubKey = keyPair.getPublic()
125125

tests/crypto-op-codes.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AlgoAmount } from '@algorandfoundation/algokit-utils/types/amount'
22
import { AppSpec } from '@algorandfoundation/algokit-utils/types/app-spec'
33
import { Bytes, Ec, Ecdsa, internal, uint64, VrfVerify } from '@algorandfoundation/algorand-typescript'
4-
import { ec } from 'elliptic'
4+
import elliptic from 'elliptic'
55
import { keccak256 as js_keccak256 } from 'js-sha3'
66
import { sha512_256 as js_sha512_256 } from 'js-sha512'
77
import nacl from 'tweetnacl'
@@ -234,7 +234,7 @@ describe('crypto op codes', async () => {
234234
it('should be able to decompress k1 public key', async () => {
235235
const v = Ecdsa.Secp256k1
236236
const testData = generateEcdsaTestData(v)
237-
const ecdsa = new ec(curveMap[v])
237+
const ecdsa = new elliptic.ec(curveMap[v])
238238
const keyPair = ecdsa.keyFromPublic(testData.pubkeyX.concat(testData.pubkeyY).asUint8Array())
239239
const pubKeyArray = new Uint8Array(keyPair.getPublic(true, 'array'))
240240
const avmResult = await getAvmResult<uint64[][]>(
@@ -298,7 +298,7 @@ describe('crypto op codes', async () => {
298298
})
299299

300300
const generateEcdsaTestData = (v: Ecdsa) => {
301-
const ecdsa = new ec(curveMap[v])
301+
const ecdsa = new elliptic.ec(curveMap[v])
302302
const keyPair = ecdsa.genKeyPair()
303303
const pk = keyPair.getPublic('array')
304304
const data = internal.primitives.BytesCls.fromCompat('test data for ecdsa')

0 commit comments

Comments
 (0)