112 lines
No EOL
2.4 KiB
TypeScript
112 lines
No EOL
2.4 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
|
|
auth_title() {
|
|
return this.key_import()
|
|
? "Войти в профиль"
|
|
: "Поделиться профилем"
|
|
}
|
|
|
|
@ $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 $hyoo_crus_auth.from(this.key_new()!).peer()
|
|
}
|
|
|
|
@ $mol_mem
|
|
current_peer() {
|
|
return this.$.$hyoo_crus_auth.current().peer()
|
|
}
|
|
|
|
@ $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_url_decode( serial )
|
|
const salt = $mol_crypto_hash( app ).slice( 0, 16 )
|
|
|
|
const closed = $mol_wire_sync( secret ).decrypt( data, salt ) // 16x B
|
|
return 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 salt = $mol_crypto_hash( app ).slice( 0, 16 )
|
|
const closed = $mol_wire_sync( secret ).encrypt( this.$.$hyoo_crus_auth.current(), salt ) // 16x B
|
|
|
|
return $mol_base64_url_encode( closed )
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} |