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.$.$hyoo_crus_auth.current($hyoo_crus_auth.from(this.key_import()!)) 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 pack = $mol_base64_decode( serial ) const closed = pack.slice( 0, this.key_size() ) const salt = $mol_crypto_hash( pack.slice( this.key_size() ) ).slice( 0, 16 ) const pass = this.password() const secret = $mol_wire_sync( this.$.$mol_crypto_secret ).pass( pass, salt ) const opened = $mol_wire_sync( secret ).decrypt( closed, salt ) return $mol_charset_decode( opened ) } catch( error ) { $mol_fail_log( error ) return null } } @$mol_action @ $mol_mem key_export() { const pass = this.password() // const recall = $mol_charset_encode( this.recall() ) const recall = $mol_charset_encode( "" ) const salt = $mol_crypto_hash( recall ).slice( 0, 16 ) const secret = $mol_wire_sync( this.$.$mol_crypto_secret ).pass( pass, salt ) const open = this.$.$mol_charset_encode( this.$.$hyoo_crus_auth.current().toString() ) const closed = new Uint8Array( $mol_wire_sync( secret ).encrypt( open, salt ) ) const pack = new Uint8Array( this.key_size() + recall.byteLength ) pack.set( closed, 0 ) pack.set( recall, this.key_size() ) return this.$.$mol_base64_encode( pack ) } } }