pakstr 0.3.4 → 0.5.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.
- package/android-template/app/build.gradle.kts +71 -4
- package/android-template/app/proguard-rules.pro +21 -18
- package/android-template/app/src/main/AndroidManifest.xml +17 -0
- package/android-template/app/src/main/java/com/pakstr/app/ApplicationClass.kt +14 -0
- package/android-template/app/src/main/java/com/pakstr/app/LocalServer.kt +80 -21
- package/android-template/app/src/main/java/com/pakstr/app/MainActivity.kt +61 -11
- package/android-template/app/src/main/java/com/pakstr/app/RuntimeConfig.kt +81 -37
- package/android-template/app/src/main/java/com/pakstr/app/ShellRuntime.kt +100 -9
- package/android-template/app/src/main/java/com/pakstr/app/WebViewController.kt +280 -20
- package/android-template/app/src/main/java/com/pakstr/app/crypto/Bip340Verifier.kt +0 -5
- package/android-template/app/src/main/java/com/pakstr/app/debug/AppDebugLogger.kt +348 -3
- package/android-template/app/src/main/java/com/pakstr/app/debug/CrashHandler.kt +32 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/DebugConfig.kt +11 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/DebugConfigLoader.kt +36 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/DebugConfigProvider.kt +29 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/DebugLogStorage.kt +139 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/DebugPreferences.kt +85 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/DebugReportExporter.kt +149 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/DebugReportShare.kt +52 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/DebugRuntimeOverride.kt +55 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/DebugSession.kt +16 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/DeveloperToolsManager.kt +63 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/WebViewDebugManager.kt +30 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/logging/PakstrLog.kt +16 -0
- package/android-template/app/src/main/java/com/pakstr/app/debug/logging/PakstrLogger.kt +154 -0
- package/android-template/app/src/main/java/com/pakstr/app/signer/AmberSigner.kt +1 -10
- package/android-template/app/src/main/java/com/pakstr/app/signer/NostrBridge.kt +163 -11
- package/android-template/app/src/main/java/com/pakstr/app/signer/SignerManager.kt +71 -0
- package/android-template/app/src/main/res/xml/file_paths.xml +9 -0
- package/android-template/gradle/libs.versions.toml +1 -0
- package/android-template/gradle.properties +2 -1
- package/dist/runners/LocalGradleRunner.js +12 -2
- package/dist/runtime/runtimeConfig.js +6 -1
- package/package.json +1 -1
|
@@ -0,0 +1,149 @@
|
|
|
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-${DebugSession.sessionId}.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
|
+
DebugLogStorage.read(context)
|
|
61
|
+
.joinToString("\n")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
val logs =
|
|
65
|
+
sanitize(rawLogs)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
return """
|
|
69
|
+
Pakstr Debug Report
|
|
70
|
+
===================
|
|
71
|
+
|
|
72
|
+
Session:
|
|
73
|
+
-------------------
|
|
74
|
+
ID:
|
|
75
|
+
${DebugSession.sessionId}
|
|
76
|
+
|
|
77
|
+
Started:
|
|
78
|
+
${java.util.Date(DebugSession.startedAt)}
|
|
79
|
+
|
|
80
|
+
Uptime:
|
|
81
|
+
${DebugSession.uptime()} ms
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
Application:
|
|
85
|
+
-------------------
|
|
86
|
+
${BuildConfig.APPLICATION_ID}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
Version:
|
|
90
|
+
${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
Device:
|
|
94
|
+
${Build.MANUFACTURER} ${Build.MODEL}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
Android:
|
|
98
|
+
${Build.VERSION.RELEASE}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
Debug:
|
|
102
|
+
$debugEnabled
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
API Enabled:
|
|
106
|
+
${RuntimeConfig.apiEnabled(context)}
|
|
107
|
+
|
|
108
|
+
WebView Debug:
|
|
109
|
+
${BuildConfig.DEBUG || RuntimeConfig.debugEnabled(context)}
|
|
110
|
+
|
|
111
|
+
Logs:
|
|
112
|
+
-------------------
|
|
113
|
+
$logs
|
|
114
|
+
|
|
115
|
+
""".trimIndent()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
private fun sanitize(
|
|
120
|
+
text: String
|
|
121
|
+
): String {
|
|
122
|
+
|
|
123
|
+
return text
|
|
124
|
+
.replace(
|
|
125
|
+
Regex("(?i)authorization:\\s*.*"),
|
|
126
|
+
"authorization: ***"
|
|
127
|
+
)
|
|
128
|
+
.replace(
|
|
129
|
+
Regex("(?i)bearer\\s+[a-zA-Z0-9._-]+"),
|
|
130
|
+
"Bearer ***"
|
|
131
|
+
)
|
|
132
|
+
.replace(
|
|
133
|
+
Regex("(?i)token=.*"),
|
|
134
|
+
"token=***"
|
|
135
|
+
)
|
|
136
|
+
.replace(
|
|
137
|
+
Regex("(?i)password=.*"),
|
|
138
|
+
"password=***"
|
|
139
|
+
)
|
|
140
|
+
.replace(
|
|
141
|
+
Regex("(?i)private.?key=.*"),
|
|
142
|
+
"privateKey=***"
|
|
143
|
+
)
|
|
144
|
+
.replace(
|
|
145
|
+
Regex("(?i)nsec[a-zA-Z0-9]+"),
|
|
146
|
+
"nsec***"
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -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,55 @@
|
|
|
1
|
+
package com.pakstr.app.debug
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
object DebugRuntimeOverride {
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
private var overrideConfig:
|
|
10
|
+
DebugConfig? = null
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
fun set(
|
|
14
|
+
context: Context,
|
|
15
|
+
config: DebugConfig
|
|
16
|
+
) {
|
|
17
|
+
|
|
18
|
+
overrideConfig = config
|
|
19
|
+
|
|
20
|
+
DebugPreferences.save(
|
|
21
|
+
context,
|
|
22
|
+
config
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
fun clear(
|
|
28
|
+
context: Context
|
|
29
|
+
) {
|
|
30
|
+
|
|
31
|
+
overrideConfig = null
|
|
32
|
+
|
|
33
|
+
DebugPreferences.clear(
|
|
34
|
+
context
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
fun get(
|
|
40
|
+
context: Context
|
|
41
|
+
): DebugConfig? {
|
|
42
|
+
|
|
43
|
+
if (overrideConfig == null) {
|
|
44
|
+
|
|
45
|
+
val saved =
|
|
46
|
+
DebugPreferences.load(context)
|
|
47
|
+
|
|
48
|
+
if (saved.enabled) {
|
|
49
|
+
overrideConfig = saved
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return overrideConfig
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package com.pakstr.app.debug
|
|
2
|
+
|
|
3
|
+
import java.util.UUID
|
|
4
|
+
|
|
5
|
+
object DebugSession {
|
|
6
|
+
|
|
7
|
+
val sessionId: String =
|
|
8
|
+
UUID.randomUUID().toString()
|
|
9
|
+
|
|
10
|
+
val startedAt: Long =
|
|
11
|
+
System.currentTimeMillis()
|
|
12
|
+
|
|
13
|
+
fun uptime(): Long {
|
|
14
|
+
return System.currentTimeMillis() - startedAt
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
package com.pakstr.app.debug
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
object DeveloperToolsManager {
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
fun enableDebug(
|
|
10
|
+
context: Context
|
|
11
|
+
) {
|
|
12
|
+
|
|
13
|
+
val config = DebugConfig(
|
|
14
|
+
|
|
15
|
+
enabled = true,
|
|
16
|
+
|
|
17
|
+
networkLogs = true,
|
|
18
|
+
|
|
19
|
+
webViewLogs = true
|
|
20
|
+
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
DebugRuntimeOverride.set(context,
|
|
26
|
+
config
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
DebugPreferences.save(
|
|
30
|
+
context,
|
|
31
|
+
config
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
fun disableDebug(
|
|
38
|
+
context: Context
|
|
39
|
+
) {
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
DebugRuntimeOverride.clear(context)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
DebugPreferences.clear(
|
|
46
|
+
context
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
fun isEnabled(
|
|
53
|
+
context: Context
|
|
54
|
+
): Boolean {
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
return DebugPreferences
|
|
58
|
+
.load(context)
|
|
59
|
+
.enabled
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package com.pakstr.app.debug
|
|
2
|
+
|
|
3
|
+
import android.R.attr.enabled
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.webkit.WebView
|
|
6
|
+
import com.pakstr.app.BuildConfig
|
|
7
|
+
import com.pakstr.app.RuntimeConfig
|
|
8
|
+
|
|
9
|
+
object WebViewDebugManager {
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
fun enable(
|
|
13
|
+
context: Context
|
|
14
|
+
) {
|
|
15
|
+
|
|
16
|
+
WebView.setWebContentsDebuggingEnabled(
|
|
17
|
+
BuildConfig.DEBUG ||
|
|
18
|
+
RuntimeConfig.debugEnabled(context)
|
|
19
|
+
)
|
|
20
|
+
AppDebugLogger.log(
|
|
21
|
+
|
|
22
|
+
context,
|
|
23
|
+
|
|
24
|
+
"WEBVIEW",
|
|
25
|
+
|
|
26
|
+
"WebView debugging enabled: $enabled"
|
|
27
|
+
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
package com.pakstr.app.debug.logging
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.pakstr.app.debug.logging.PakstrLog
|
|
5
|
+
import java.text.SimpleDateFormat
|
|
6
|
+
import java.util.Date
|
|
7
|
+
import java.util.Locale
|
|
8
|
+
|
|
9
|
+
object PakstrLogger {
|
|
10
|
+
|
|
11
|
+
private const val MAX_LOGS = 1000
|
|
12
|
+
|
|
13
|
+
private val logs =
|
|
14
|
+
mutableListOf<PakstrLog>()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
fun d(
|
|
18
|
+
tag: String,
|
|
19
|
+
message: String
|
|
20
|
+
) {
|
|
21
|
+
add(
|
|
22
|
+
PakstrLog.Level.DEBUG,
|
|
23
|
+
tag,
|
|
24
|
+
message
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
Log.d(
|
|
28
|
+
"PakstrDebug",
|
|
29
|
+
"[$tag] $message"
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
fun i(
|
|
35
|
+
tag: String,
|
|
36
|
+
message: String
|
|
37
|
+
) {
|
|
38
|
+
add(
|
|
39
|
+
PakstrLog.Level.INFO,
|
|
40
|
+
tag,
|
|
41
|
+
message
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
Log.i(
|
|
45
|
+
"PakstrDebug",
|
|
46
|
+
"[$tag] $message"
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
fun w(
|
|
52
|
+
tag: String,
|
|
53
|
+
message: String
|
|
54
|
+
) {
|
|
55
|
+
add(
|
|
56
|
+
PakstrLog.Level.WARN,
|
|
57
|
+
tag,
|
|
58
|
+
message
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
Log.w(
|
|
62
|
+
"PakstrDebug",
|
|
63
|
+
"[$tag] $message"
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
fun e(
|
|
69
|
+
tag: String,
|
|
70
|
+
message: String,
|
|
71
|
+
throwable: Throwable? = null
|
|
72
|
+
) {
|
|
73
|
+
|
|
74
|
+
add(
|
|
75
|
+
PakstrLog.Level.ERROR,
|
|
76
|
+
tag,
|
|
77
|
+
message
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
Log.e(
|
|
81
|
+
"PakstrDebug",
|
|
82
|
+
"[$tag] $message",
|
|
83
|
+
throwable
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
fun getLogs(): List<PakstrLog> {
|
|
89
|
+
return logs.toList()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
fun clear() {
|
|
94
|
+
logs.clear()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
private fun add(
|
|
99
|
+
level: PakstrLog.Level,
|
|
100
|
+
tag: String,
|
|
101
|
+
message: String
|
|
102
|
+
) {
|
|
103
|
+
|
|
104
|
+
logs.add(
|
|
105
|
+
PakstrLog(
|
|
106
|
+
timestamp =
|
|
107
|
+
System.currentTimeMillis(),
|
|
108
|
+
level = level,
|
|
109
|
+
tag = tag,
|
|
110
|
+
message = message
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
if (logs.size > MAX_LOGS) {
|
|
116
|
+
logs.removeFirst()
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
fun exportText(): String {
|
|
122
|
+
|
|
123
|
+
val formatter =
|
|
124
|
+
SimpleDateFormat(
|
|
125
|
+
"yyyy-MM-dd HH:mm:ss",
|
|
126
|
+
Locale.US
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
return buildString {
|
|
130
|
+
|
|
131
|
+
appendLine(
|
|
132
|
+
"Pakstr Debug Report"
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
appendLine(
|
|
136
|
+
"=================="
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
appendLine()
|
|
140
|
+
|
|
141
|
+
logs.forEach {
|
|
142
|
+
|
|
143
|
+
appendLine(
|
|
144
|
+
"${formatter.format(
|
|
145
|
+
Date(it.timestamp)
|
|
146
|
+
)} " +
|
|
147
|
+
"[${it.level}] " +
|
|
148
|
+
"[${it.tag}] " +
|
|
149
|
+
it.message
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -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
|
-
|
|
495
|
-
"AMBER",
|
|
496
|
-
"Operation completed"
|
|
497
|
-
)
|
|
498
|
-
|
|
489
|
+
|
|
499
490
|
callback?.invoke(value)
|
|
500
491
|
}
|
|
501
492
|
|