Skip to content

Commit 686315b

Browse files
committedFeb 11, 2024
fix: remove deprecated Buffer usage, add ethereumjs util dependency and fix class import
1 parent 53af8d8 commit 686315b

File tree

4 files changed

+120
-18
lines changed

4 files changed

+120
-18
lines changed
 

‎package-lock.json

+100
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"postinstall": "npm run build",
2121
"test": "npx vitest run"
2222
},
23+
"dependencies": {
24+
"@ethereumjs/util": "^9.0.2"
25+
},
2326
"devDependencies": {
2427
"@typescript-eslint/eslint-plugin": "^6.7.3",
2528
"@typescript-eslint/parser": "^6.7.3",

‎src/js/tests/ffi.spec.ts

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { bytesToHex } from '@ethereumjs/util'
12
import { beforeAll, describe, expect, test } from 'vitest'
23

3-
import { ContextWrapper } from '../verkleFFIBindings/index'
4+
import { Context } from '../verkleFFIBindings/index'
45

56
describe('bindings', () => {
6-
let context: ContextWrapper
7+
let context: Context
78
beforeAll(() => {
8-
context = ContextWrapper._default()
9+
context = Context._default()
910
})
1011

1112
test('getTreeKey', () => {
@@ -27,9 +28,9 @@ describe('bindings', () => {
2728
const sub_index = 0
2829

2930
const key = context.getTreeKey(address, tree_index_le, sub_index)
30-
const key_hex = Buffer.from(key).toString('hex')
31+
const key_hex = bytesToHex(key)
3132

32-
const expected = '76a014d14e338c57342cda5187775c6b75e7f0ef292e81b176c7a5a700273700'
33+
const expected = '0x76a014d14e338c57342cda5187775c6b75e7f0ef292e81b176c7a5a700273700'
3334

3435
expect(key_hex).toBe(expected)
3536
})
@@ -44,9 +45,9 @@ describe('bindings', () => {
4445
const scalars = [scalar, scalar]
4546
const commitment = context.commitToScalars(scalars)
4647

47-
const commitment_hex = Buffer.from(commitment).toString('hex')
48+
const commitment_hex = bytesToHex(commitment)
4849
const expected =
49-
'6fb3421d850da8e8b8d1b9c1cc30876ef23d9df72c8792e6d569a9861089f02abdf89e2c671fe0bff820e815f6f20453fdbc83ec5415e3ade8c745179e31d25c'
50+
'0x6fb3421d850da8e8b8d1b9c1cc30876ef23d9df72c8792e6d569a9861089f02abdf89e2c671fe0bff820e815f6f20453fdbc83ec5415e3ade8c745179e31d25c'
5051

5152
expect(commitment_hex).toBe(expected)
5253
})
@@ -60,9 +61,9 @@ describe('bindings', () => {
6061
const commitment = context.commitToScalars([scalar])
6162

6263
const commitmentHash = context.hashCommitment(commitment)
63-
const commitmentHashHex = Buffer.from(commitmentHash).toString('hex')
64+
const commitmentHashHex = bytesToHex(commitmentHash)
6465

65-
const expected = '31e94bef2c0160ed1f3dd9caacbed356939c2e440c4ddb336d832dcab6384e19'
66+
const expected = '0x31e94bef2c0160ed1f3dd9caacbed356939c2e440c4ddb336d832dcab6384e19'
6667

6768
expect(commitmentHashHex).toBe(expected)
6869
})
@@ -80,9 +81,9 @@ describe('bindings', () => {
8081

8182
for (let i = 0; i < hashes.length; i++) {
8283
const expectedHash = context.hashCommitment(commitments[i])
83-
const expectedHashHex = Buffer.from(expectedHash).toString('hex')
84+
const expectedHashHex = bytesToHex(expectedHash)
8485

85-
const commitmentHashHex = Buffer.from(hashes[i]).toString('hex')
86+
const commitmentHashHex = bytesToHex(hashes[i])
8687

8788
expect(commitmentHashHex).toBe(expectedHashHex)
8889
}
@@ -97,9 +98,9 @@ describe('bindings', () => {
9798
const commitment = context.commitToScalars([scalar])
9899

99100
const commitmentHash = context.deprecateSerializeCommitment(commitment)
100-
const commitmentHashHex = Buffer.from(commitmentHash).toString('hex')
101+
const commitmentHashHex = bytesToHex(commitmentHash)
101102

102-
const expected = '6d40cf3d3097cb19b0ff686a068d53fb1250cc98bbd33766cf2cce00acb8b0a6'
103+
const expected = '0x6d40cf3d3097cb19b0ff686a068d53fb1250cc98bbd33766cf2cce00acb8b0a6'
103104

104105
expect(commitmentHashHex).toBe(expected)
105106
})
@@ -120,15 +121,15 @@ describe('bindings', () => {
120121
])
121122

122123
const expected = context.scalarMulIndex(newScalarValue, commitmentIndex)
123-
const expectedHex = Buffer.from(expected).toString('hex')
124+
const expectedHex = bytesToHex(expected)
124125

125126
const updatedCommitment = context.updateCommitment(
126127
commitment,
127128
commitmentIndex,
128129
oldScalarValue,
129130
newScalarValue,
130131
)
131-
const updatedCommitmentHex = Buffer.from(updatedCommitment).toString('hex')
132+
const updatedCommitmentHex = bytesToHex(updatedCommitment)
132133

133134
expect(updatedCommitmentHex).toBe(expectedHex)
134135
})

‎src/js/verkleFFIBindings/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ContextWrapper, zeroCommitment } from '../../../dist/cjs/wasm/rust_verkle_wasm'
1+
import { ContextWrapper as Context, zeroCommitment } from '../../../dist/cjs/wasm/rust_verkle_wasm'
22

33
// This is a 32 byte serialized field element
44
type Scalar = Uint8Array
@@ -7,8 +7,6 @@ type Scalar = Uint8Array
77
// It is 64 bytes because the point is serialized in uncompressed format.
88
type Commitment = Uint8Array
99

10-
type Context = ContextWrapper
11-
1210
export {
1311
Scalar,
1412
Commitment,

0 commit comments

Comments
 (0)