103 lines
No EOL
2.3 KiB
TypeScript
103 lines
No EOL
2.3 KiB
TypeScript
namespace $.$$ {
|
|
export class $hd_canary_app_profile extends $.$hd_canary_app_profile {
|
|
|
|
@ $mol_mem
|
|
content() {
|
|
return [
|
|
this.key_import()
|
|
? this.Import_block()
|
|
: this.Export_block()
|
|
]
|
|
}
|
|
|
|
@ $mol_mem
|
|
export_link() {
|
|
return this.$.$mol_state_arg.link({
|
|
auth: this.key_export(),
|
|
})
|
|
}
|
|
|
|
key_import( next?: string | null ) {
|
|
return this.$.$mol_state_arg.value( 'auth', next ) ?? null
|
|
}
|
|
|
|
@ $mol_mem
|
|
peer_new() {
|
|
return $mol_int62_hash_string( this.$.$mol_crypto_auditor_private_to_public( this.key_new()! ) )
|
|
}
|
|
|
|
@ $mol_action
|
|
import_switch() {
|
|
this.$.$hyoo_crus_auth.current($hyoo_crus_auth.from(this.key_new()!))
|
|
this.password( '' )
|
|
this.key_import( null )
|
|
}
|
|
|
|
|
|
@ $mol_mem
|
|
password_bid() {
|
|
const pass = this.password()
|
|
if( pass.length <= 7 ) return this.bid_pass_long()
|
|
return ''
|
|
}
|
|
export_rows() {
|
|
return [
|
|
this.Expot_bid(),
|
|
this.Export_pass(),
|
|
... this.password_bid() ? [] : [ this.Export_link() ],
|
|
]
|
|
}
|
|
|
|
import_rows() {
|
|
return [
|
|
this.Iport_descr(),
|
|
this.Import_pass(),
|
|
... this.key_new() ? [ this.Import_switch() ] : [],
|
|
]
|
|
}
|
|
|
|
@ $mol_mem
|
|
key_new() {
|
|
|
|
const serial = this.key_import()
|
|
if( !serial ) return null
|
|
|
|
try {
|
|
const password = this.password()
|
|
const app = $mol_crypto_hash( $mol_charset_encode( "hd_canary" ) ) // 20 B
|
|
const secret = $mol_wire_sync( $mol_crypto_sacred_pass )( password, app ) // 16 B
|
|
|
|
const data = $mol_base64_decode( serial )
|
|
const salt = $mol_crypto_hash( app ).slice( 0, 16 )
|
|
|
|
const closed = $mol_wire_sync( secret ).decrypt( data, salt ) // 16x B
|
|
|
|
return $mol_charset_decode( closed )
|
|
} catch( error ) {
|
|
|
|
$mol_fail_log( error )
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@$mol_action
|
|
@ $mol_mem
|
|
key_export() {
|
|
const password = this.password()
|
|
const app = $mol_crypto_hash( $mol_charset_encode( "hd_canary" ) ) // 20 B
|
|
const secret = $mol_wire_sync( $mol_crypto_sacred_pass )( password, app ) // 16 B
|
|
|
|
const data = this.$.$mol_charset_encode( this.$.$hyoo_crus_auth.current().toString() )
|
|
const salt = $mol_crypto_hash( app ).slice( 0, 16 )
|
|
|
|
const closed = $mol_wire_sync( secret ).encrypt( data, salt ) // 16x B
|
|
|
|
return $mol_base64_encode( closed )
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} |