-
Notifications
You must be signed in to change notification settings - Fork 1
/
enc.ts
33 lines (28 loc) · 1 KB
/
enc.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
import { encrypt as encryptEcies, decrypt as decryptEcies, PrivateKey } from 'eciesjs';
export function encrypt(data: string, pubkey: string): string {
return encryptEcies(pubkey, Buffer.from(data)).toString('hex');
}
export function encryptAddress(address: address, pubkey: string): address {
return {
addressLine1: encrypt(address.addressLine1, pubkey),
addressLine2: encrypt(address.addressLine2, pubkey),
city: encrypt(address.city, pubkey),
countryCode: encrypt(address.countryCode, pubkey),
postalOrZip: encrypt(address.postalOrZip, pubkey),
name: encrypt(address.name, pubkey)
}
}
export function decrypt(data: string, seckey: string): string {
return decryptEcies(seckey, Buffer.from(data)).toString();
}
export function genPrivateKey(): PrivateKey {
return new PrivateKey();
}
export interface address {
addressLine1: string,
addressLine2: string,
city: string,
countryCode: string,
postalOrZip: string,
name: string
}