pakstr 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/android-template/app/src/main/AndroidManifest.xml +17 -0
  2. package/android-template/app/src/main/java/com/pakstr/app/LocalServer.kt +80 -21
  3. package/android-template/app/src/main/java/com/pakstr/app/MainActivity.kt +46 -9
  4. package/android-template/app/src/main/java/com/pakstr/app/RuntimeConfig.kt +81 -37
  5. package/android-template/app/src/main/java/com/pakstr/app/ShellRuntime.kt +99 -8
  6. package/android-template/app/src/main/java/com/pakstr/app/WebViewController.kt +145 -20
  7. package/android-template/app/src/main/java/com/pakstr/app/crypto/Bip340Verifier.kt +0 -5
  8. package/android-template/app/src/main/java/com/pakstr/app/debug/AppDebugLogger.kt +275 -3
  9. package/android-template/app/src/main/java/com/pakstr/app/debug/DebugConfig.kt +11 -0
  10. package/android-template/app/src/main/java/com/pakstr/app/debug/DebugConfigLoader.kt +36 -0
  11. package/android-template/app/src/main/java/com/pakstr/app/debug/DebugConfigProvider.kt +24 -0
  12. package/android-template/app/src/main/java/com/pakstr/app/debug/DebugLogStorage.kt +107 -0
  13. package/android-template/app/src/main/java/com/pakstr/app/debug/DebugReportExporter.kt +139 -0
  14. package/android-template/app/src/main/java/com/pakstr/app/debug/DebugReportShare.kt +52 -0
  15. package/android-template/app/src/main/java/com/pakstr/app/debug/DebugRuntimeOverride.kt +29 -0
  16. package/android-template/app/src/main/java/com/pakstr/app/debug/DeveloperToolsManager.kt +34 -0
  17. package/android-template/app/src/main/java/com/pakstr/app/signer/AmberSigner.kt +1 -10
  18. package/android-template/app/src/main/java/com/pakstr/app/signer/NostrBridge.kt +163 -11
  19. package/android-template/app/src/main/java/com/pakstr/app/signer/SignerManager.kt +71 -0
  20. package/android-template/app/src/main/res/xml/file_paths.xml +9 -0
  21. package/dist/runners/LocalGradleRunner.js +12 -2
  22. package/dist/runtime/runtimeConfig.js +6 -1
  23. package/package.json +1 -1
@@ -0,0 +1,36 @@
1
+ package com.pakstr.app.debug
2
+
3
+ import org.json.JSONObject
4
+
5
+ object DebugConfigLoader {
6
+
7
+ fun load(
8
+ manifest: JSONObject
9
+ ): DebugConfig {
10
+
11
+ val debug =
12
+ manifest.optJSONObject("debug")
13
+ ?: return DebugConfig()
14
+
15
+ return DebugConfig(
16
+
17
+ enabled =
18
+ debug.optBoolean(
19
+ "enabled",
20
+ false
21
+ ),
22
+
23
+ networkLogs =
24
+ debug.optBoolean(
25
+ "networkLogs",
26
+ false
27
+ ),
28
+
29
+ webViewLogs =
30
+ debug.optBoolean(
31
+ "webViewLogs",
32
+ false
33
+ )
34
+ )
35
+ }
36
+ }
@@ -0,0 +1,24 @@
1
+ package com.pakstr.app.debug
2
+
3
+ object DebugConfigProvider {
4
+
5
+ private var manifestConfig =
6
+ DebugConfig()
7
+
8
+ fun initialize(
9
+ config: DebugConfig
10
+ ) {
11
+
12
+ manifestConfig = config
13
+
14
+ }
15
+
16
+ fun current():
17
+ DebugConfig {
18
+
19
+ return DebugRuntimeOverride.get()
20
+ ?: manifestConfig
21
+
22
+ }
23
+
24
+ }
@@ -0,0 +1,107 @@
1
+ package com.pakstr.app.debug
2
+
3
+ import android.content.Context
4
+ import java.io.File
5
+
6
+ object DebugLogStorage {
7
+
8
+ private const val FILE_NAME =
9
+ "pakstr-debug.log"
10
+
11
+ private const val MAX_FILE_SIZE =
12
+ 1024 * 1024 // 1 MB
13
+
14
+ fun append(
15
+ context: Context,
16
+ entry: String
17
+ ) {
18
+
19
+ try {
20
+
21
+ val file =
22
+ getFile(context)
23
+
24
+
25
+ rotateIfNeeded(file)
26
+
27
+
28
+ file.appendText(
29
+ entry + "\n"
30
+ )
31
+
32
+ } catch (_: Exception) {
33
+
34
+ // Logging must never crash the app
35
+
36
+ }
37
+ }
38
+
39
+ fun read(
40
+ context: Context
41
+ ): String {
42
+
43
+ return try {
44
+
45
+ val file =
46
+ getFile(context)
47
+
48
+
49
+ if (file.exists()) {
50
+
51
+ file.readText()
52
+
53
+ } else {
54
+
55
+ ""
56
+
57
+ }
58
+
59
+ } catch (_: Exception) {
60
+
61
+ ""
62
+
63
+ }
64
+ }
65
+
66
+ fun clear(
67
+ context: Context
68
+ ) {
69
+
70
+ try {
71
+
72
+ getFile(context)
73
+ .delete()
74
+
75
+ } catch (_: Exception) {
76
+
77
+ }
78
+ }
79
+
80
+ private fun rotateIfNeeded(
81
+ file: File
82
+ ) {
83
+
84
+ if (!file.exists()) {
85
+ return
86
+ }
87
+
88
+
89
+ if (file.length() >= MAX_FILE_SIZE) {
90
+
91
+ file.writeText("")
92
+
93
+ }
94
+
95
+ }
96
+
97
+ private fun getFile(
98
+ context: Context
99
+ ): File {
100
+
101
+ return File(
102
+ context.cacheDir,
103
+ FILE_NAME
104
+ )
105
+
106
+ }
107
+ }
@@ -0,0 +1,139 @@
1
+ package com.pakstr.app.debug
2
+
3
+ import android.content.Context
4
+ import android.os.Build
5
+ import com.pakstr.app.BuildConfig
6
+ import com.pakstr.app.RuntimeConfig
7
+ import java.io.File
8
+
9
+ object DebugReportExporter {
10
+
11
+ private const val MAX_SIZE_BYTES =
12
+ 1024 * 1024 // 1 MB
13
+
14
+
15
+ fun export(
16
+ context: Context
17
+ ): File {
18
+
19
+ var report =
20
+ buildReport(context)
21
+
22
+ val bytes =
23
+ report.toByteArray(Charsets.UTF_8)
24
+
25
+
26
+ if (bytes.size > MAX_SIZE_BYTES) {
27
+
28
+ report =
29
+ String(
30
+ bytes
31
+ .takeLast(MAX_SIZE_BYTES)
32
+ .toByteArray(),
33
+ Charsets.UTF_8
34
+ )
35
+ }
36
+
37
+
38
+ val file =
39
+ File(
40
+ context.cacheDir,
41
+ "pakstr-debug-report.txt"
42
+ )
43
+
44
+
45
+ file.writeText(report)
46
+
47
+ return file
48
+ }
49
+
50
+
51
+ private fun buildReport(
52
+ context: Context
53
+ ): String {
54
+
55
+ val debugEnabled =
56
+ RuntimeConfig.debugEnabled(context)
57
+
58
+
59
+ val rawLogs =
60
+ if (debugEnabled) {
61
+
62
+ DebugLogStorage.read(context)
63
+
64
+ } else {
65
+
66
+ DebugLogStorage.read(context)
67
+ .lines()
68
+ .filter {
69
+ it.contains("[ERROR]")
70
+ }
71
+ .joinToString("\n")
72
+ }
73
+
74
+
75
+ val logs =
76
+ sanitize(rawLogs)
77
+
78
+
79
+ return """
80
+ Pakstr Debug Report
81
+ ===================
82
+
83
+ Application:
84
+ ${BuildConfig.APPLICATION_ID}
85
+
86
+ Version:
87
+ ${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})
88
+
89
+ Device:
90
+ ${Build.MANUFACTURER} ${Build.MODEL}
91
+
92
+ Android:
93
+ ${Build.VERSION.RELEASE}
94
+
95
+ Debug:
96
+ $debugEnabled
97
+
98
+ API Enabled:
99
+ ${RuntimeConfig.apiEnabled(context)}
100
+
101
+ Logs:
102
+ -------------------
103
+ $logs
104
+
105
+ """.trimIndent()
106
+ }
107
+
108
+
109
+ private fun sanitize(
110
+ text: String
111
+ ): String {
112
+
113
+ return text
114
+ .replace(
115
+ Regex("(?i)authorization:\\s*.*"),
116
+ "authorization: ***"
117
+ )
118
+ .replace(
119
+ Regex("(?i)bearer\\s+[a-zA-Z0-9._-]+"),
120
+ "Bearer ***"
121
+ )
122
+ .replace(
123
+ Regex("(?i)token=.*"),
124
+ "token=***"
125
+ )
126
+ .replace(
127
+ Regex("(?i)password=.*"),
128
+ "password=***"
129
+ )
130
+ .replace(
131
+ Regex("(?i)private.?key=.*"),
132
+ "privateKey=***"
133
+ )
134
+ .replace(
135
+ Regex("(?i)nsec[a-zA-Z0-9]+"),
136
+ "nsec***"
137
+ )
138
+ }
139
+ }
@@ -0,0 +1,52 @@
1
+ package com.pakstr.app.debug
2
+
3
+ import android.content.Context
4
+ import android.content.Intent
5
+ import androidx.core.content.FileProvider
6
+ import java.io.File
7
+
8
+ object DebugReportShare {
9
+
10
+ fun share(
11
+ context: Context
12
+ ) {
13
+
14
+ val report =
15
+ DebugReportExporter.export(
16
+ context
17
+ )
18
+
19
+ val uri =
20
+ FileProvider.getUriForFile(
21
+ context,
22
+ "${context.packageName}.fileprovider",
23
+ report
24
+ )
25
+
26
+ val intent =
27
+ Intent(
28
+ Intent.ACTION_SEND
29
+ ).apply {
30
+
31
+ type =
32
+ "text/plain"
33
+
34
+ putExtra(
35
+ Intent.EXTRA_STREAM,
36
+ uri
37
+ )
38
+
39
+ addFlags(
40
+ Intent.FLAG_GRANT_READ_URI_PERMISSION
41
+ )
42
+ }
43
+
44
+
45
+ context.startActivity(
46
+ Intent.createChooser(
47
+ intent,
48
+ "Share Pakstr Debug Report"
49
+ )
50
+ )
51
+ }
52
+ }
@@ -0,0 +1,29 @@
1
+ package com.pakstr.app.debug
2
+
3
+ object DebugRuntimeOverride {
4
+
5
+ private var overrideConfig: DebugConfig? = null
6
+
7
+
8
+ fun set(
9
+ config: DebugConfig
10
+ ) {
11
+
12
+ overrideConfig = config
13
+
14
+ }
15
+
16
+
17
+ fun clear() {
18
+
19
+ overrideConfig = null
20
+
21
+ }
22
+
23
+
24
+ fun get(): DebugConfig? {
25
+
26
+ return overrideConfig
27
+
28
+ }
29
+ }
@@ -0,0 +1,34 @@
1
+ package com.pakstr.app.debug
2
+ object DeveloperToolsManager {
3
+
4
+ fun enableDebug() {
5
+
6
+ DebugRuntimeOverride.set(
7
+
8
+ DebugConfig(
9
+
10
+ enabled = true,
11
+
12
+ networkLogs = true,
13
+
14
+ webViewLogs = true,
15
+
16
+ )
17
+ )
18
+
19
+ }
20
+
21
+ fun disableDebug() {
22
+
23
+ DebugRuntimeOverride.clear()
24
+
25
+ }
26
+
27
+ fun isEnabled(): Boolean {
28
+
29
+ return DebugRuntimeOverride.get()
30
+ ?.enabled
31
+ ?: false
32
+
33
+ }
34
+ }
@@ -146,11 +146,6 @@ class AmberSigner(
146
146
 
147
147
  suspendCancellableCoroutine { continuation ->
148
148
 
149
- AppDebugLogger.log(
150
- "AMBER",
151
- "Signing event request"
152
- )
153
-
154
149
  pendingCallback = { signature ->
155
150
 
156
151
  if (signature.isEmpty()) {
@@ -491,11 +486,7 @@ class AmberSigner(
491
486
  ?: result.data?.getStringExtra("content")
492
487
 
493
488
  ?: ""
494
- AppDebugLogger.log(
495
- "AMBER",
496
- "Operation completed"
497
- )
498
-
489
+
499
490
  callback?.invoke(value)
500
491
  }
501
492