-
Notifications
You must be signed in to change notification settings - Fork 5
/
models.ts
45 lines (39 loc) · 963 Bytes
/
models.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
import { curve } from 'elliptic'
import BN = require('bn.js')
//eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface CurvePoint extends curve.short.ShortPoint {}
export interface SystemParameters {
p: BN // prime
n: BN // prime factor: p = 2*n+1
g: CurvePoint // generator
}
export interface SystemParametersSerialized {
p: string
n: string
g: string
}
export interface KeyPair {
h: CurvePoint
sk: BN
}
export interface Cipher {
a: CurvePoint
b: CurvePoint
r?: BN
}
// TODO: test me
export const instanceOfSystemParametersSerialized = (
object: any
): object is SystemParametersSerialized => {
/*const test = (field: string, type: string): boolean => {
return field in object && typeof object[field] === type
}*/
return (
'p' in object &&
typeof object.p === 'string' &&
'n' in object &&
typeof object.n === 'string' &&
'g' in object &&
typeof object.g === 'string'
)
}