Add serialization
This commit is contained in:
+10
-3
@@ -1,7 +1,7 @@
|
||||
import logger from 'log'
|
||||
import {DHusage, ecdh} from './kdf'
|
||||
import SecretWrap from './secret-wrap'
|
||||
import {pubkey_fromString, pubkey_toString, Usage} from './misc'
|
||||
import * as misc from './misc'
|
||||
import * as consts from './const'
|
||||
|
||||
const log = logger('crypto:private-wrap')
|
||||
@@ -32,7 +32,7 @@ export default class PrivateWrap {
|
||||
|
||||
public async toString(): Promise<string> {
|
||||
log.trace('toString')
|
||||
const pubkey = await pubkey_toString(this.pubkey)
|
||||
const pubkey = await PrivateWrap.pubkey_toString(this.pubkey)
|
||||
const box = this.box.toString()
|
||||
return `${pubkey}.${box}`
|
||||
}
|
||||
@@ -42,11 +42,18 @@ export default class PrivateWrap {
|
||||
const parts = data.split('.')
|
||||
if (parts.length < 2) return null
|
||||
|
||||
const pubkey = await pubkey_fromString(parts[0], Usage.ecdh)
|
||||
const pubkey = await PrivateWrap.pubkey_fromString(parts[0])
|
||||
if (pubkey === null) return null
|
||||
const box = SecretWrap.fromString(parts.slice(1).join('.'))
|
||||
if (box === null) return null
|
||||
|
||||
return new PrivateWrap(box, pubkey)
|
||||
}
|
||||
|
||||
public static pubkey_toString(pubkey: CryptoKey): Promise<string> {
|
||||
return misc.pubkey_toString(pubkey)
|
||||
}
|
||||
public static pubkey_fromString(pubkey: string): Promise<CryptoKey | null> {
|
||||
return misc.pubkey_fromString(pubkey, misc.Usage.ecdh)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user