-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenc.ts
29 lines (25 loc) · 934 Bytes
/
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
import { encrypt as encryptEcies, decrypt as decryptEcies } 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 interface Address {
addressLine1: string,
addressLine2: string,
city: string,
countryCode: string,
postalOrZip: string,
name: string
}