@@ -2,7 +2,7 @@ import { isBoolean, isNil } from 'lodash';
22import { Dispatch , useCallback , useEffect , useMemo , useState } from 'react' ;
33import { clipboard } from 'electron' ;
44import useAsync from 'react-use/lib/useAsync' ;
5- import { ProConfig , ProProof } from 'libsession_util_nodejs' ;
5+ import { ProConfig , type ProProof } from 'libsession_util_nodejs' ;
66import { getAppDispatch } from '../../../state/dispatch' ;
77import {
88 getDataFeatureFlag ,
@@ -44,6 +44,8 @@ import {
4444 useProBackendProDetails ,
4545 useProBackendRefetch ,
4646} from '../../../state/selectors/proBackendData' ;
47+ import ProBackendAPI from '../../../session/apis/pro_backend_api/ProBackendAPI' ;
48+ import { getProMasterKeyHex } from '../../../session/utils/User' ;
4749
4850type FeatureFlagToggleType = {
4951 forceUpdate : ( ) => void ;
@@ -728,13 +730,10 @@ function ProConfigForm({
728730 forceUpdate : ( ) => Promise < void > ;
729731} ) {
730732 const hasProConfig = ! proConfig || typeof proConfig === 'object' ;
731- const [ error , setError ] = useState < Error | null > ( ) ;
732733 const [ rotatingPrivKeyInput , setRotatingPrivKeyInput ] = useState < string > (
733734 proConfig ?. rotatingPrivKeyHex ?? ''
734735 ) ;
735- const [ rotatingPubKeyInput , setRotatingPubKeyInput ] = useState < string > (
736- proConfig ?. proProof . rotatingPubkeyHex ?? ''
737- ) ;
736+
738737 const [ expiryInput , setExpiryInput ] = useState < string > (
739738 proConfig ?. proProof . expiryMs . toString ( ) ?? ''
740739 ) ;
@@ -746,105 +745,18 @@ function ProConfigForm({
746745 proConfig ?. proProof . version . toString ( ) ?? ''
747746 ) ;
748747
749- const [ configDumpValue , setConfigDumpValue ] = useState < string > (
750- hasProConfig ? JSON . stringify ( proConfig ) : ''
751- ) ;
752-
753- const setProProof = useCallback (
754- async ( config : Parameters < typeof UserConfigWrapperActions . setProConfig > [ 0 ] ) => {
755- try {
756- await UserConfigWrapperActions . setProConfig ( config ) ;
757- } catch ( e ) {
758- window ?. log ?. error ( e ) ;
759- setError ( e ) ;
760- }
761- } ,
762- [ ]
763- ) ;
764-
765- const save = useCallback ( async ( ) => {
766- const proProof = {
767- rotatingPubkeyHex : rotatingPubKeyInput ,
768- expiryMs : Number ( expiryInput ) ,
769- signatureHex : sigInput ,
770- genIndexHashB64 : genHashInput ,
771- version : Number ( versionInput ) ,
772- } satisfies ProProof ;
773- const rotatingSeedHex = await UserUtils . getProRotatingSeedHex ( ) ;
774- await setProProof ( {
775- proProof,
776- rotatingSeedHex,
777- } ) ;
778- } , [ setProProof , rotatingPubKeyInput , expiryInput , sigInput , genHashInput , versionInput ] ) ;
779-
780- const copy = useCallback ( ( ) => {
781- const json = JSON . stringify ( proConfig ) ;
782- clipboard . writeText ( json ) ;
783- ToastUtils . pushToastSuccess ( 'flag-dumper-toast-copy' , 'Copied to clipboard' ) ;
784- } , [ proConfig ] ) ;
785-
786- const setConfig = useCallback ( async ( ) => {
787- try {
788- const parsed = JSON . parse ( configDumpValue ) as ProConfig ;
789-
790- // Update all the input fields with the pasted config
791- setRotatingPrivKeyInput ( parsed . rotatingPrivKeyHex ?? '' ) ;
792- setRotatingPubKeyInput ( parsed . proProof . rotatingPubkeyHex ?? '' ) ;
793- setExpiryInput ( parsed . proProof . expiryMs . toString ( ) ?? '' ) ;
794- setSigInput ( parsed . proProof . signatureHex ?? '' ) ;
795- setGenHashInput ( parsed . proProof . genIndexHashB64 ?? '' ) ;
796- setVersionInput ( parsed . proProof . version . toString ( ) ?? '' ) ;
797-
798- ToastUtils . pushToastSuccess ( 'flag-dumper-toast-paste' , 'Pasted from clipboard' ) ;
799- await forceUpdate ( ) ;
800- } catch ( e ) {
801- window ?. log ?. error ( e ) ;
802- ToastUtils . pushToastError ( 'flag-dumper-toast-paste-error' , `Failed to paste: ${ e ?. message } ` ) ;
803- }
804- } , [ configDumpValue , forceUpdate ] ) ;
805-
806748 const removeConfig = useCallback ( async ( ) => {
807749 await UserConfigWrapperActions . removeProConfig ( ) ;
808750 setRotatingPrivKeyInput ( '' ) ;
809- setRotatingPubKeyInput ( '' ) ;
810751 setExpiryInput ( '' ) ;
811752 setSigInput ( '' ) ;
812753 setGenHashInput ( '' ) ;
813754 setVersionInput ( '' ) ;
814- setConfigDumpValue ( '' ) ;
815755 await forceUpdate ( ) ;
816756 } , [ forceUpdate ] ) ;
817757
818758 return (
819759 < div style = { { width : '100%' } } >
820- < h2 > Pro Config Dumper</ h2 >
821- < DebugButton onClick = { copy } disabled = { ! hasProConfig } >
822- Copy Config Dump
823- </ DebugButton >
824- < DebugButton onClick = { setConfig } disabled = { ! configDumpValue ?. length } >
825- Set Config Dump
826- </ DebugButton >
827- < label
828- style = { {
829- display : 'block' ,
830- color : 'var(--text-primary-color)' ,
831- } }
832- >
833- Config Dump
834- </ label >
835- < textarea
836- style = { {
837- width : '100%' ,
838- minWidth : '100px' ,
839- padding : 'var(--margins-xs) var(--margins-sm)' ,
840- backgroundColor : 'var(--background-primary-color)' ,
841- color : 'var(--text-primary-color)' ,
842- border : 'var(--default-borders)' ,
843- borderRadius : 'var(--border-radius)' ,
844- } }
845- onChange = { e => setConfigDumpValue ( e . target . value ) }
846- defaultValue = { configDumpValue }
847- />
848760 < h2 > Pro Config</ h2 >
849761 < DebugButton
850762 onClick = { removeConfig }
@@ -858,17 +770,10 @@ function ProConfigForm({
858770 value = { rotatingPrivKeyInput }
859771 setValue = { setRotatingPrivKeyInput }
860772 />
861- < DebugInput
862- label = "Rotating Public Key"
863- value = { rotatingPubKeyInput }
864- setValue = { setRotatingPubKeyInput }
865- />
866773 < DebugInput label = "Expiry Timestamp (ms)" value = { expiryInput } setValue = { setExpiryInput } />
867774 < DebugInput label = "Signature" value = { sigInput } setValue = { setSigInput } />
868775 < DebugInput label = "Gen Hash" value = { genHashInput } setValue = { setGenHashInput } />
869776 < DebugInput label = "Version" value = { versionInput } setValue = { setVersionInput } />
870- < DebugButton onClick = { save } > Set Pro Config</ DebugButton >
871- { error ?. message ? error . message : null }
872777 </ div >
873778 ) ;
874779}
@@ -991,25 +896,70 @@ export const ProDebugSection = ({
991896 < DebugMenuSection title = "Session Pro" >
992897 < FlagToggle forceUpdate = { forceUpdate } flag = "proAvailable" label = "Pro Beta Released" />
993898 { proAvailable ? (
994- < DebugButton buttonColor = { SessionButtonColor . Danger } onClick = { resetPro } >
995- Reset All Pro State
996- </ DebugButton >
997- ) : null }
998- { proAvailable ? (
999- < DebugButton onClick = { ( ) => setPage ( DEBUG_MENU_PAGE . Pro ) } > Pro Playground</ DebugButton >
1000- ) : null }
1001- { proAvailable ? (
1002- < DebugButton
1003- onClick = { ( ) => {
1004- if ( ! proAvailable ) {
1005- return ;
1006- }
1007- dispatch ( proBackendDataActions . refreshGetProDetailsFromProBackend ( { } ) as any ) ;
1008- } }
1009- >
1010- Refresh Pro Details
1011- </ DebugButton >
899+ < >
900+ < DebugButton buttonColor = { SessionButtonColor . Danger } onClick = { resetPro } >
901+ Reset All Pro State
902+ </ DebugButton >
903+ < DebugButton onClick = { ( ) => setPage ( DEBUG_MENU_PAGE . Pro ) } > Pro Playground</ DebugButton >
904+ < DebugButton
905+ onClick = { ( ) => {
906+ if ( ! proAvailable ) {
907+ return ;
908+ }
909+ dispatch ( proBackendDataActions . refreshGetProDetailsFromProBackend ( { } ) as any ) ;
910+ } }
911+ >
912+ Refresh Pro Details
913+ </ DebugButton >
914+ < DebugButton
915+ onClick = { async ( ) => {
916+ const masterPrivKeyHex = await getProMasterKeyHex ( ) ;
917+ const rotatingPrivKeyHex = await UserUtils . getProRotatingPrivateKeyHex ( ) ;
918+ const rotatingSeedHex = await UserUtils . getProRotatingSeedHex ( ) ;
919+ const response = await ProBackendAPI . generateProProof ( {
920+ masterPrivKeyHex,
921+ rotatingPrivKeyHex,
922+ } ) ;
923+ if ( getFeatureFlag ( 'debugServerRequests' ) ) {
924+ window ?. log ?. debug ( 'getProProof response: ' , response ) ;
925+ }
926+ if ( response ?. status_code === 200 ) {
927+ const proProof : ProProof = {
928+ expiryMs : response . result . expiry_unix_ts_ms ,
929+ genIndexHashB64 : response . result . gen_index_hash_b64 ,
930+ rotatingPubkeyHex : response . result . rotating_pkey_hex ,
931+ version : response . result . version ,
932+ signatureHex : response . result . sig_hex ,
933+ } ;
934+ await UserConfigWrapperActions . setProConfig ( { proProof, rotatingSeedHex } ) ;
935+ }
936+ } }
937+ >
938+ Get Pro Proof
939+ </ DebugButton >
940+ < DebugButton
941+ onClick = { async ( ) => {
942+ const masterPrivKeyHex = await getProMasterKeyHex ( ) ;
943+ const response = await ProBackendAPI . getProDetails ( { masterPrivKeyHex } ) ;
944+ if ( getFeatureFlag ( 'debugServerRequests' ) ) {
945+ window ?. log ?. debug ( 'Pro Details: ' , response ) ;
946+ }
947+ } }
948+ >
949+ Get Pro Details
950+ </ DebugButton >
951+ < DebugButton
952+ hide = { ! proAvailable }
953+ onClick = { async ( ) => {
954+ const response = await ProBackendAPI . getRevocationList ( { ticket : 0 } ) ;
955+ window ?. log ?. debug ( 'Pro Revocation List: ' , response ) ;
956+ } }
957+ >
958+ Get Pro Revocation List (from ticket 0)
959+ </ DebugButton >
960+ </ >
1012961 ) : null }
962+
1013963 < FlagToggle
1014964 forceUpdate = { forceUpdate }
1015965 flag = "useTestProBackend"
@@ -1049,6 +999,7 @@ export const ProDebugSection = ({
1049999 options = { [
10501000 { label : 'Google Play' , value : ProPaymentProvider . GooglePlayStore } ,
10511001 { label : 'iOS App Store' , value : ProPaymentProvider . iOSAppStore } ,
1002+ { label : 'Rangeproof' , value : ProPaymentProvider . Rangeproof } ,
10521003 ] }
10531004 forceUpdate = { forceUpdate }
10541005 unsetOption = { { label : 'Select originating platform' , value : null } }
0 commit comments