-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
56 lines (46 loc) · 1.71 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {
initVerkleWasm,
getTreeKey as getTreeKeyBase,
getTreeKeyHash as getTreeKeyHashBase,
updateCommitment as updateCommitmentBase,
zeroCommitment as zeroCommitmentBase,
} from './verkleFFIBindings/index.js'
import { Context as VerkleFFI } from './wasm/rust_verkle_wasm.js'
export const loadVerkleCrypto = async (): Promise<VerkleCrypto> => {
await initVerkleWasm()
const verkleFFI = new VerkleFFI()
const getTreeKey = (address: Uint8Array, treeIndex: Uint8Array, subIndex: number): Uint8Array =>
getTreeKeyBase(verkleFFI, address, treeIndex, subIndex)
const getTreeKeyHash = (address: Uint8Array, treeIndexLE: Uint8Array): Uint8Array =>
getTreeKeyHashBase(verkleFFI, address, treeIndexLE)
const updateCommitment = (
commitment: Uint8Array,
commitmentIndex: number,
oldScalarValue: Uint8Array,
newScalarValue: Uint8Array,
): Commitment =>
updateCommitmentBase(verkleFFI, commitment, commitmentIndex, oldScalarValue, newScalarValue)
const zeroCommitment = zeroCommitmentBase()
return {
getTreeKey,
getTreeKeyHash,
updateCommitment,
zeroCommitment,
}
}
export interface VerkleCrypto {
getTreeKey: (address: Uint8Array, treeIndex: Uint8Array, subIndex: number) => Uint8Array
getTreeKeyHash: (address: Uint8Array, treeIndexLE: Uint8Array) => Uint8Array
updateCommitment: (
commitment: Uint8Array,
commitmentIndex: number,
oldScalarValue: Uint8Array,
newScalarValue: Uint8Array
) => Commitment
zeroCommitment: Uint8Array
}
// This is a 32 byte serialized field element
export type Scalar = Uint8Array
// This is a 64 byte serialized point.
// It is 64 bytes because the point is serialized in uncompressed format.
export type Commitment = Uint8Array