@www.hyperlinks.space/program-kit 1.2.3 → 1.2.91881

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 (37) hide show
  1. package/README.md +5 -5
  2. package/app/_layout.tsx +5 -6
  3. package/app/index.tsx +1 -1
  4. package/assets/images/PreviewImage.png +0 -0
  5. package/database/start.ts +1 -3
  6. package/docs/build_and_install.md +6 -6
  7. package/docs/npm-release.md +46 -0
  8. package/docs/releases.md +5 -5
  9. package/docs/releases_github_actions.md +5 -5
  10. package/docs/security_plan_raw.md +4 -4
  11. package/docs/security_raw.md +2 -2
  12. package/docs/timing_raw.md +7 -7
  13. package/docs/update.md +11 -11
  14. package/docs/wallet_telegram_standalone_multichain_proposal.md +192 -0
  15. package/docs/wallets_hosting_architecture.md +1 -1
  16. package/fullREADME.md +101 -81
  17. package/npmReadMe.md +5 -5
  18. package/package.json +2 -2
  19. package/scripts/load-env.ts +1 -3
  20. package/scripts/test-api-base.ts +1 -1
  21. package/tsconfig.json +1 -1
  22. package/windows/build.cjs +1 -1
  23. package/windows/cleanup-legacy-appdata-installs.ps1 +1 -1
  24. package/windows/product-brand.cjs +1 -1
  25. package/app/components/GlobalBottomBar.tsx +0 -447
  26. package/app/components/GlobalBottomBarWeb.tsx +0 -362
  27. package/app/components/GlobalLogoBar.tsx +0 -108
  28. package/app/components/GlobalLogoBarFallback.tsx +0 -66
  29. package/app/components/GlobalLogoBarWithFallback.tsx +0 -24
  30. package/app/components/HyperlinksSpaceLogo.tsx +0 -29
  31. package/app/components/Telegram.tsx +0 -648
  32. package/app/components/telegramWebApp.ts +0 -359
  33. package/app/fonts.ts +0 -12
  34. package/app/theme.ts +0 -117
  35. package/docs/backlogs/medium_term_backlog.md +0 -26
  36. package/docs/backlogs/short_term_backlog.md +0 -39
  37. package/eslint.config.js +0 -10
package/README.md CHANGED
@@ -1,17 +1,18 @@
1
1
  # Program Kit
2
2
 
3
- Program Kit is a production-ready cross-platform starter published from `app/`.
3
+ Program Kit is a production-ready cross-platform starter published from repository root.
4
4
  It is built around React Native + Expo and is designed to be quickly tested, scaled,
5
5
  and deployed across popular platforms.
6
6
 
7
7
  ## What You Get
8
8
 
9
9
  - Expo + React Native app foundation
10
- - Telegram bot support (webhook + local bot scripts)
10
+ - Telegram bot support (webhook + local bot scripts) with AI functionality
11
11
  - Telegram Mini App-ready client structure
12
- - Android and iOS workflow scripts
12
+ - Android and iOS clients
13
13
  - Windows desktop packaging (`.exe`) with Electron Builder
14
14
  - CI-oriented release workflow and deployment helpers
15
+ - OpenAI functionality and Swap.Coffee for blockchain data retrievement
15
16
 
16
17
  ## Install
17
18
 
@@ -38,7 +39,7 @@ npm install
38
39
  npm run start
39
40
  ```
40
41
 
41
- Then open the project `README.md` for full setup details (env vars, bot setup, build
42
+ Then open the project **`fullREADME.md`** for details (env vars, bot setup, build
42
43
  and release commands).
43
44
 
44
45
  ## Release Channels
@@ -50,4 +51,3 @@ and release commands).
50
51
 
51
52
  - Published directly from the `app/` folder.
52
53
  - Package tarball is filtered to include only required project files.
53
- - **`fullREADME.md`** in the package is the full in-repo developer guide (Expo setup, scripts, and the rest of the project readme).
package/app/_layout.tsx CHANGED
@@ -2,12 +2,11 @@ import "../global.css";
2
2
  import { View, StyleSheet, Platform, KeyboardAvoidingView, AppState, Alert } from "react-native";
3
3
  import { Stack } from "expo-router";
4
4
  import * as Updates from "expo-updates";
5
- import { TelegramProvider } from "./components/Telegram";
6
- import { GlobalLogoBarWithFallback } from "./components/GlobalLogoBarWithFallback";
7
- import { GlobalBottomBar } from "./components/GlobalBottomBar";
8
- import { GlobalBottomBarWeb } from "./components/GlobalBottomBarWeb";
9
- import { useColors } from "./theme";
10
- import { useTelegram } from "./components/Telegram";
5
+ import { TelegramProvider, useTelegram } from "../ui/components/Telegram";
6
+ import { GlobalLogoBarWithFallback } from "../ui/components/GlobalLogoBarWithFallback";
7
+ import { GlobalBottomBar } from "../ui/components/GlobalBottomBar";
8
+ import { GlobalBottomBarWeb } from "../ui/components/GlobalBottomBarWeb";
9
+ import { useColors } from "../ui/theme";
11
10
  import { useEffect, useRef } from "react";
12
11
 
13
12
  /**
package/app/index.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Text, View } from "react-native";
2
- import { useTelegram } from "./components/Telegram";
2
+ import { useTelegram } from "../ui/components/Telegram";
3
3
 
4
4
  export default function Index() {
5
5
  const { status, telegramUsername, error, debug } = useTelegram();
Binary file
package/database/start.ts CHANGED
@@ -5,9 +5,7 @@ import path from "path";
5
5
  // In Vercel Lambdas these files don't exist, so these calls are harmless no-ops.
6
6
  const cwd = process.cwd();
7
7
  dotenv.config({ path: path.join(cwd, ".env") });
8
- dotenv.config({ path: path.join(cwd, "app", ".env") });
9
8
  dotenv.config({ path: path.join(cwd, ".env.local") });
10
- dotenv.config({ path: path.join(cwd, "app", ".env.local") });
11
9
  import { neon } from "@neondatabase/serverless";
12
10
 
13
11
  const connectionString = process.env.DATABASE_URL;
@@ -15,7 +13,7 @@ const connectionString = process.env.DATABASE_URL;
15
13
  if (!connectionString) {
16
14
  // Fail fast on the server side so misconfiguration is obvious in logs.
17
15
  throw new Error(
18
- "DATABASE_URL is not set. Configure it in ./app/.env for the current Neon branch.",
16
+ "DATABASE_URL is not set. Configure it in ./.env for the current Neon branch.",
19
17
  );
20
18
  }
21
19
 
@@ -5,14 +5,14 @@ This doc describes the Windows Electron build and install flow and how to speed
5
5
  Exe creating example:
6
6
 
7
7
  ```
8
- cd /d C:\1\1\1\1\1\HyperlinksSpaceProgram\app
8
+ cd /d C:\1\1\1\1\1\HyperlinksSpaceProgram
9
9
  npm run build:win:verbose
10
10
  ```
11
11
 
12
12
  Exe bash run example:
13
13
 
14
14
  ```
15
- powershell -NoProfile -Command "Start-Process -FilePath 'C:/1/1/1/1/1/HyperlinksSpaceBot/app/releases/builder/build_03252026_1449/HyperlinksSpaceProgramInstaller_03252026_1449.exe'"
15
+ powershell -NoProfile -Command "Start-Process -FilePath 'C:/1/1/1/1/1/HyperlinksSpaceBot/releases/builder/build_03252026_1449/HyperlinksSpaceProgramInstaller_03252026_1449.exe'"
16
16
  ```
17
17
 
18
18
  ---
@@ -33,7 +33,7 @@ powershell -NoProfile -Command "Start-Process -FilePath 'C:/1/1/1/1/1/Hyperlinks
33
33
 
34
34
  | Goal | What to do |
35
35
  |------|------------|
36
- | **Skip Expo when only Electron changed** | Use `npm run pack:win` when `dist/` is already up to date (no app/Expo changes). Saves the full Expo/Metro run (often 30–60+ s). |
36
+ | **Skip Expo when only Electron changed** | Use `npm run pack:win` when `dist/` is already up to date (no Expo app changes). Saves the full Expo/Metro run (often 30–60+ s). |
37
37
  | **Skip native rebuild** | In `package.json` → `build`, add `"npmRebuild": false`. The packaged app only runs the web bundle; native rebuild can often be skipped. Try it; if the app runs, keep it. Saves time every build. |
38
38
  | **Avoid building the installer when iterating** | Use `npm run build:win:dir` when you only need the unpacked app (e.g. quick runs from `release/win-unpacked/app.exe`). Skips NSIS and clean; faster and no “file locked” risk. |
39
39
  | **Keep caches** | Don’t clear Metro/Expo cache unless needed. Electron and electron-builder caches (e.g. under `%LOCALAPPDATA%\electron-builder\Cache`) are reused; leave them. |
@@ -43,7 +43,7 @@ powershell -NoProfile -Command "Start-Process -FilePath 'C:/1/1/1/1/1/Hyperlinks
43
43
  ### Rebuilding only what changed
44
44
 
45
45
  - **Caches:** Expo/Metro and electron-builder already use caches. A full `build:win` reuses cached transforms and packed files where nothing changed, so rebuilds are partly incremental by default.
46
- - **Skip the web build when only Electron changed:** If you only changed `windows/build.cjs` or other files in `windows/`, the icon, or `package.json` build config (not the React/app code), run **`npm run pack:win`** instead of `build:win`. That runs only electron-builder + clean and reuses the existing `dist/`. Ensure `dist/` is up to date (run `npm run build` once, or after any app/Expo changes).
46
+ - **Skip the web build when only Electron changed:** If you only changed `windows/build.cjs` or other files in `windows/`, the icon, or `package.json` build config (not the React app code), run **`npm run pack:win`** instead of `build:win`. That runs only electron-builder + clean and reuses the existing `dist/`. Ensure `dist/` is up to date (run `npm run build` once, or after any Expo app changes).
47
47
 
48
48
  ---
49
49
 
@@ -89,8 +89,8 @@ User runs **`HyperlinksSpaceProgramInstaller.exe`**. NSIS extracts the app (e.g.
89
89
 
90
90
  ## 5. File layout after build
91
91
 
92
- - **After `build:win` or `pack:win`:** `app/releases/builder/build_MMDDYYYY_HHMM/HyperlinksSpaceProgramInstaller_<stamp>.exe` and `app/releases/builder/build_MMDDYYYY_HHMM/dev/` (portable zip, yml, win-unpacked, blockmap, builder-debug.yml, builder-effective-config.yaml).
93
- - **After `build:win:dir`:** `app/release/win-unpacked/` (run `app.exe` from there).
92
+ - **After `build:win` or `pack:win`:** `releases/builder/build_MMDDYYYY_HHMM/HyperlinksSpaceProgramInstaller_<stamp>.exe` and `releases/builder/build_MMDDYYYY_HHMM/dev/` (portable zip, yml, win-unpacked, blockmap, builder-debug.yml, builder-effective-config.yaml).
93
+ - **After `build:win:dir`:** `release/win-unpacked/` (run `app.exe` from there).
94
94
  - **Build inputs:** `dist/` (Expo export), `windows/` (build.cjs, app-shell.html, preload-log.cjs), `assets/icon.ico`, and files listed under `build.files` in `package.json`.
95
95
 
96
96
  ---
@@ -0,0 +1,46 @@
1
+ # Milestone snapshot package (npm)
2
+
3
+ This repository includes a publishable snapshot package for fast developer bootstrap:
4
+
5
+ - package source: repository root (published directly)
6
+ - **npmjs (public):** `@www.hyperlinks.space/program-kit` — manage org and tokens: [www.hyperlinks.space on npm](https://www.npmjs.com/settings/www.hyperlinks.space/packages)
7
+ - **GitHub Packages:** `@hyperlinksspace/program-kit` (same version; GitHub requires the package scope to match this repo's owner)
8
+
9
+ ## Verify publish payload locally
10
+
11
+ The npm package page uses `README.md` from the published tarball, not `npmReadMe.md`. The published package also includes **`fullREADME.md`**, a copy of the developer readme (saved before the npm readme replaces `README.md`). Match CI before `npm pack`, then restore:
12
+
13
+ ```bash
14
+ cp README.md fullREADME.md
15
+ cp npmReadMe.md README.md
16
+ npm pack --dry-run
17
+ git checkout -- README.md
18
+ rm -f fullREADME.md
19
+ ```
20
+
21
+ ## Install snapshot as a developer
22
+
23
+ ```bash
24
+ npx @www.hyperlinks.space/program-kit ./my-hsp-app
25
+ ```
26
+
27
+ The CLI materializes the bundled package payload into your target folder, then you run:
28
+
29
+ ```bash
30
+ cd my-hsp-app
31
+ npm install
32
+ ```
33
+
34
+ ## Release channels
35
+
36
+ - `latest`: immutable stable snapshots (tag workflow `snapshot-vX.Y.Z`)
37
+ - `next`: rolling snapshots from manual workflow dispatch
38
+
39
+ In the output, you'll find options to open the app in:
40
+
41
+ - [a development build](https://docs.expo.dev/develop/development-builds/introduction/)
42
+ - [an Android emulator](https://docs.expo.dev/workflow/android-studio-emulator/)
43
+ - [an iOS simulator](https://docs.expo.dev/workflow/ios-simulator/)
44
+ - [Expo Go](https://expo.dev/go), a limited sandbox for trying out app development with Expo
45
+
46
+ You can start developing by editing the files inside the **app** directory. This project uses [file-based routing](https://docs.expo.dev/router/introduction).
package/docs/releases.md CHANGED
@@ -12,7 +12,7 @@ This document defines the production plan for release detection, deduped GitHub
12
12
  ## Source of Truth
13
13
 
14
14
  - The **GitHub Release tag** is the release identity (`release_id`), for example `build_03252026_1929`.
15
- - Locally, `windows/cleanup.cjs` moves the built installer to `app/releases/builder/build_MMDDYYYY_HHMM/HyperlinksSpaceProgramInstaller_<stamp>.exe` (other artifacts under `dev/`). In CI you can set `RELEASE_BUILD_ID` to match a chosen tag, or leave it unset so the folder name comes from build time.
15
+ - Locally, `windows/cleanup.cjs` moves the built installer to `releases/builder/build_MMDDYYYY_HHMM/HyperlinksSpaceProgramInstaller_<stamp>.exe` (other artifacts under `dev/`). In CI you can set `RELEASE_BUILD_ID` to match a chosen tag, or leave it unset so the folder name comes from build time.
16
16
 
17
17
  ## Workflow Trigger
18
18
 
@@ -51,7 +51,7 @@ Recommended extra safety:
51
51
 
52
52
  ## Endpoint Contract
53
53
 
54
- - Webhook endpoint path: `app/api/releases.ts`
54
+ - Webhook endpoint path: `api/releases.ts`
55
55
  - Route URL: `POST /api/releases`
56
56
  - Purpose: accept release-published events from GitHub Actions and fan out update notifications to app clients.
57
57
 
@@ -89,7 +89,7 @@ If auth fails:
89
89
  }
90
90
  ```
91
91
 
92
- ## Endpoint Behavior (`app/api/releases.ts`)
92
+ ## Endpoint Behavior (`api/releases.ts`)
93
93
 
94
94
  1. Accept only `POST`.
95
95
  2. Validate auth token/signature.
@@ -184,7 +184,7 @@ Client behavior:
184
184
 
185
185
  ## Rollout Plan
186
186
 
187
- 1. Deploy `app/api/releases.ts` in staging.
187
+ 1. Deploy `api/releases.ts` in staging.
188
188
  2. Run workflow in dry-run mode to validate folder parsing and dedupe checks.
189
189
  3. Enable real release creation for test folder.
190
190
  4. Enable webhook call to staging endpoint.
@@ -193,7 +193,7 @@ Client behavior:
193
193
 
194
194
  ## Acceptance Criteria
195
195
 
196
- - A new `app/releases/builder/build_.../` folder produces exactly one GitHub Release.
196
+ - A new `releases/builder/build_.../` folder produces exactly one GitHub Release.
197
197
  - Re-running workflow for the same `release_id` does not create duplicates.
198
198
  - Webhook is called only for newly created releases.
199
199
  - `POST /api/releases` rejects unauthorized requests.
@@ -12,7 +12,7 @@ This document defines the production plan for release detection, deduped GitHub
12
12
  ## Source of Truth
13
13
 
14
14
  - The **GitHub Release tag** is the release identity (`release_id`), for example `build_03252026_1929`.
15
- - Locally and in CI, `windows/cleanup.cjs` places the installer under `app/releases/builder/build_MMDDYYYY_HHMM/HyperlinksSpaceProgramInstaller_<stamp>.exe` (other files under `dev/`). In CI, set `RELEASE_BUILD_ID` to pin the folder/tag, or omit it to use the timestamp from build time.
15
+ - Locally and in CI, `windows/cleanup.cjs` places the installer under `releases/builder/build_MMDDYYYY_HHMM/HyperlinksSpaceProgramInstaller_<stamp>.exe` (other files under `dev/`). In CI, set `RELEASE_BUILD_ID` to pin the folder/tag, or omit it to use the timestamp from build time.
16
16
 
17
17
  ## When You Must Make a New Installer Release
18
18
 
@@ -78,7 +78,7 @@ Recommended extra safety:
78
78
 
79
79
  ## Endpoint Contract
80
80
 
81
- - Webhook endpoint path: `app/api/releases.ts`
81
+ - Webhook endpoint path: `api/releases.ts`
82
82
  - Route URL: `POST /api/releases`
83
83
  - Purpose: accept release-published events from GitHub Actions and fan out update notifications to app clients.
84
84
 
@@ -116,7 +116,7 @@ If auth fails:
116
116
  }
117
117
  ```
118
118
 
119
- ## Endpoint Behavior (`app/api/releases.ts`)
119
+ ## Endpoint Behavior (`api/releases.ts`)
120
120
 
121
121
  1. Accept only `POST`.
122
122
  2. Validate auth token/signature.
@@ -171,7 +171,7 @@ Client behavior:
171
171
 
172
172
  ## Rollout Plan
173
173
 
174
- 1. Deploy `app/api/releases.ts` in staging.
174
+ 1. Deploy `api/releases.ts` in staging.
175
175
  2. Run workflow in dry-run mode to validate folder parsing and dedupe checks.
176
176
  3. Enable real release creation for test folder.
177
177
  4. Enable webhook call to staging endpoint.
@@ -180,7 +180,7 @@ Client behavior:
180
180
 
181
181
  ## Acceptance Criteria
182
182
 
183
- - A new `app/releases/builder/build_.../` folder produces exactly one GitHub Release.
183
+ - A new `releases/builder/build_.../` folder produces exactly one GitHub Release.
184
184
  - Re-running workflow for the same `release_id` does not create duplicates.
185
185
  - Webhook is called only for newly created releases.
186
186
  - `POST /api/releases` rejects unauthorized requests.
@@ -1,6 +1,6 @@
1
1
  # Security Implementation Plan (Telegram-First Wallet)
2
2
 
3
- This file describes a practical implementation plan for the security model defined in `security.md`, focused on the `./app` (Expo / Vercel) codebase and a serverless backend.
3
+ This file describes a practical implementation plan for the security model defined in `security.md`, focused on the repository-root Expo/Vercel codebase and a serverless backend.
4
4
 
5
5
  ---
6
6
 
@@ -13,7 +13,7 @@ This file describes a practical implementation plan for the security model defin
13
13
  - Confirm `telegram-web-app.js` is loaded in the Mini App shell.
14
14
 
15
15
  - **0.2. Serverless backend basics**
16
- - Use existing Vercel project (`./app`) API routes:
16
+ - Use existing Vercel project (repository root) API routes:
17
17
  - Create a shared util for **Telegram initData validation** (WebApp) in `api/_lib/telegram.ts`:
18
18
  - `validateInitData(initData: string): { username: string }`.
19
19
  - Create a shared util for **Telegram Login widget validation** (web/native) in `api/_lib/telegram_login.ts`:
@@ -101,7 +101,7 @@ This file describes a practical implementation plan for the security model defin
101
101
 
102
102
  ## Phase 2 – iOS/Android App Flow (Single App)
103
103
 
104
- (All implemented inside `./app` using Expo Router / React Native.)
104
+ (All implemented in the repository root app using Expo Router / React Native.)
105
105
 
106
106
  - **2.1. Local state**
107
107
  - Add a simple secure storage wrapper (e.g. `expo-secure-store`):
@@ -123,7 +123,7 @@ This file describes a practical implementation plan for the security model defin
123
123
  - Opens a WebView or browser to hosted login page (e.g. `/login/telegram`).
124
124
 
125
125
  - **2.3. Telegram Login for Websites (web page + API)**
126
- - Create a web page (static route in `./app` or separate) that:
126
+ - Create a web page (static route in repository root or separate) that:
127
127
  - Embeds the Telegram Login widget configured for your bot & domain.
128
128
  - On success, posts the payload (via `data-onauth` callback) to `POST /api/login/telegram`.
129
129
  - `POST /api/login/telegram`:
@@ -129,7 +129,7 @@ For platforms outside Telegram (web, desktop app, native mobile app not running
129
129
 
130
130
  ## IV. Android / iOS (Single App, Telegram‑Centric Flow)
131
131
 
132
- We ship **one app** (the current `./app` Expo app) to iOS/Android stores. On mobile, the app acts as a shell that:
132
+ We ship **one app** (the current Expo app at repository root) to iOS/Android stores. On mobile, the app acts as a shell that:
133
133
 
134
134
  - Explains why wallet creation happens in Telegram.
135
135
  - Sends the user into the Telegram Mini App to actually create the wallet.
@@ -212,7 +212,7 @@ For a user who already has a Telegram wallet (created earlier in the Mini App):
212
212
 
213
213
  **Key points of this model**
214
214
 
215
- - There is **one app** (`./app`), not a separate companion; mobile just has a Telegramcentric onboarding path.
215
+ - There is **one app** (repository root), not a separate companion; mobile just has a Telegram-centric onboarding path.
216
216
  - All wallet creation and key material remain in the Telegram Mini App and its SecureStorage/CloudStorage environment.
217
217
  - The iOS/Android app uses:
218
218
  - **Telegram Login for Websites** to learn “who is this user?” (via `username`),
@@ -4,11 +4,11 @@
4
4
 
5
5
  **Important:** The app will not be sent to platforms (store/listing) before it is fully finished. So **MVP launch = full product launch**, and the realistic estimate is **3 months**.
6
6
 
7
- ## Transfer layout to `./app` (TypeScript) — build on new architecture
7
+ ## Transfer layout to repository root (TypeScript) — build on new architecture
8
8
 
9
- The goal is **not** to finish the Flutter app in `front/`. The **Flutter** app in `front/` is the **reference layout** (web pages, flows, structure). The work is to **transfer that layout and flows into `./app` in TypeScript** and make everything work there, with **security plan compliance** (see `docs/security_plan.md`). The production Mini App is the TS app in `./app` (Expo/React), backed by the same repo’s API and DB.
9
+ The goal is **not** to finish the Flutter app in `front/`. The **Flutter** app in `front/` is the **reference layout** (web pages, flows, structure). The work is to **transfer that layout and flows into the repository root app in TypeScript** and make everything work there, with **security plan compliance** (see `docs/security_plan.md`). The production Mini App is the TS app at repository root (Expo/React), backed by the same repo’s API and DB.
10
10
 
11
- ### Pages to implement in `./app` (TS) — from `front/` reference
11
+ ### Pages to implement in repository root (TS) — from `front/` reference
12
12
 
13
13
  - **Bootstrap** – initData auth, config from API, wallet warm-up.
14
14
  - **Main** – home / hub after bootstrap.
@@ -23,7 +23,7 @@ The goal is **not** to finish the Flutter app in `front/`. The **Flutter** app i
23
23
  - **Mnemonics** – mnemonic display/backup (security plan).
24
24
  - **Wallet panel** – wallet panel page.
25
25
 
26
- ### Services / wiring in `./app` (TS)
26
+ ### Services / wiring in repository root (TS)
27
27
 
28
28
  | Concern | Role | Backend / compliance |
29
29
  |--------|------|-----------------------|
@@ -31,7 +31,7 @@ The goal is **not** to finish the Flutter app in `front/`. The **Flutter** app i
31
31
  | **AI** | Chat with AI via same-origin `/api/ai` (or app’s AI route). | Already in `app`; ensure config, keys, and error handling in prod. |
32
32
  | **Wallet** | Mnemonic generation, storage, key derivation (client-side). | Security plan: SecureStorage/CloudStorage, wallet registration (`POST /api/wallet/register`), device auth flow; optional TonConnect later. |
33
33
 
34
- ### API surface (in `./app`)
34
+ ### API surface (in repository root)
35
35
 
36
36
  - **`/api/telegram`** (or init) – initData validation, user upsert.
37
37
  - **`/api/ai`** – AI proxy; used by the TS app.
@@ -56,8 +56,8 @@ Completion order and stages:
56
56
  | Stage | Scope | Estimate | Notes |
57
57
  |-------|--------|----------|--------|
58
58
  | **1** | **Security plan implementation** | **~3 weeks** | Phase 0 (validation, DB), Phase 1 (wallet creation, device auth, register), Phase 2 (pending tx, confirmations). |
59
- | **2** | **App (TS) – pages & UX** | **~3 weeks** | Transfer layout from `front/` and implement all pages in `./app` (send, swap, wallets, apps, AI, get, trade, creators, mnemonics, wallet panel); layout and navigation solid. |
60
- | **3** | **App (TS) – services & wiring** | **~3 weeks** | Auth, AI, and wallet flows in `./app`; backend alignment; errors and edge cases. |
59
+ | **2** | **App (TS) – pages & UX** | **~3 weeks** | Transfer layout from `front/` and implement all pages in repository root app (send, swap, wallets, apps, AI, get, trade, creators, mnemonics, wallet panel); layout and navigation solid. |
60
+ | **3** | **App (TS) – services & wiring** | **~3 weeks** | Auth, AI, and wallet flows in repository root app; backend alignment; errors and edge cases. |
61
61
  | **4** | **Integration, testing, finishing** | **~3 weeks** | E2E, platform checks, store/listing readiness, app/plan and root plan items (formatting, theme, bugs, features). |
62
62
 
63
63
  **MVP launch (full finish, platform-ready):** **~3 months** (12 weeks).
package/docs/update.md CHANGED
@@ -10,7 +10,7 @@ This plan defines how to deliver near-instant updates for the app with minimal u
10
10
  - Target latency: minutes or less after publish.
11
11
  - **Lane B: Binary releases (slow path)**
12
12
  - Use installer/store release only when native/runtime changes are required.
13
- - Triggered through `app/releases/**` and GitHub Release workflow.
13
+ - Triggered through `releases/**` and GitHub Release workflow.
14
14
 
15
15
  Decision rule:
16
16
 
@@ -21,9 +21,9 @@ Decision rule:
21
21
 
22
22
  Already configured:
23
23
 
24
- - `app/app.json` has `updates.url`.
25
- - `app/app.json` has `runtimeVersion.policy = appVersion`.
26
- - `app/eas.json` has channels:
24
+ - `app.json` has `updates.url`.
25
+ - `app.json` has `runtimeVersion.policy = appVersion`.
26
+ - `eas.json` has channels:
27
27
  - preview profile -> `main`
28
28
  - production profile -> `production`
29
29
 
@@ -40,7 +40,7 @@ Implication:
40
40
 
41
41
  For binary-only updates:
42
42
 
43
- 1. `app/releases/builder/build_MMDDYYYY_HHMM/` (or Forge under `app/releases/forge/...`) changes.
43
+ 1. `releases/builder/build_MMDDYYYY_HHMM/` (or Forge under `releases/forge/...`) changes.
44
44
  2. GitHub workflow dedupes and creates Release if new.
45
45
  3. Workflow calls `POST /api/releases` webhook.
46
46
  4. Backend notifies clients that binary update is available.
@@ -64,11 +64,11 @@ Create workflow `.github/workflows/eas-update.yml`:
64
64
  - Optional `workflow_dispatch`
65
65
  - Path filters to avoid unnecessary publishes (example):
66
66
  - include app source and config paths
67
- - exclude `app/releases/**`
67
+ - exclude `releases/**`
68
68
  - Steps:
69
69
  1. checkout
70
70
  2. setup node
71
- 3. install deps (`npm ci` in `app/`)
71
+ 3. install deps (`npm ci` in repository root)
72
72
  4. publish OTA:
73
73
  - branch `main` for preview/internal
74
74
  - branch `production` for production
@@ -80,7 +80,7 @@ Recommended publish command:
80
80
 
81
81
  ### 4.3 Binary Workflow (Already Planned)
82
82
 
83
- Keep `app/releases/**` workflow with dedupe:
83
+ Keep `releases/**` workflow with dedupe:
84
84
 
85
85
  - If release exists, skip.
86
86
  - If new, create GitHub Release and upload assets.
@@ -170,7 +170,7 @@ Phase 3 - Hardening:
170
170
 
171
171
  ### Publish OTA update
172
172
 
173
- From `app/`:
173
+ From repository root:
174
174
 
175
175
  - `npx eas update --branch main --message "fix: ..."`
176
176
  - for production:
@@ -178,7 +178,7 @@ From `app/`:
178
178
 
179
179
  ### Publish binary update
180
180
 
181
- 1. Create `app/releases/builder/build_MMDDYYYY_HHMM/` with installer at root and supporting files under `dev/`.
181
+ 1. Create `releases/builder/build_MMDDYYYY_HHMM/` with installer at root and supporting files under `dev/`.
182
182
  2. Push changes.
183
183
  3. Workflow creates (or skips duplicate) GitHub Release and calls `/api/releases`.
184
184
 
@@ -198,7 +198,7 @@ From `app/`:
198
198
 
199
199
  ## 12) Next Implementation Tasks
200
200
 
201
- 1. Create `app/api/releases.ts` endpoint.
201
+ 1. Create `api/releases.ts` endpoint.
202
202
  2. Add `.github/workflows/eas-update.yml`.
203
203
  3. Add client update service wrapper (`check/fetch/apply` policy).
204
204
  4. Add docs section in `build_and_install.md` linking OTA vs binary rules.
@@ -0,0 +1,192 @@
1
+ # Unified Wallet Model: Telegram, Standalone, Multi-Chain & DLLR (TON)
2
+
3
+ This document proposes a single coherent setup for the tensions between:
4
+
5
+ - A **Telegram-first** experience (Mini App, bot confirmations, CloudStorage-assisted UX).
6
+ - **Standalone operation** when Telegram is unavailable, blocked, or the user simply prefers not to use it.
7
+ - **Non-custodial** custody: keys and mnemonics never held by our servers.
8
+ - **DLLR** and core product flows anchored on **TON**, where issuance and program logic are expected to live.
9
+ - **Multiple chains** where users may hold assets or use bridges, without fragmenting identity or safety.
10
+
11
+ It complements `wallets_hosting_architecture.md`, `security_raw.md`, and `security_plan_raw.md` by resolving “which path wins when” and how they fit together.
12
+
13
+ ---
14
+
15
+ ## 1. Core idea: one logical wallet, three *surfaces*
16
+
17
+ Think in terms of **one user-owned root of trust** (mnemonic for the primary TON wallet, and optional additional key material for other chains), and **three ways to use it**:
18
+
19
+ | Surface | What it is | Best for |
20
+ |--------|------------|----------|
21
+ | **A. Telegram-hosted (TMA)** | Same non-custodial keys; encrypted material split between Telegram `SecureStorage` + `CloudStorage` (ciphertext only), identity via `initData`. | Smoothest UX inside Telegram, bot-driven tx confirmation, push-to-sign. |
22
+ | **B. Unhosted / standalone** | Keys only on device OS keystore / WebCrypto; no Telegram APIs required to open the app or sign. | Telegram outage, privacy preference, store-review-friendly “works without Telegram”. |
23
+ | **C. Connected** | External wallets via **TON Connect** (TON) and, later, analogous **WalletConnect** / chain-specific SDKs for other networks. | Power users, hardware wallets, assets already elsewhere. |
24
+
25
+ **Important:** Surfaces are **not** different custodial models. They differ only in **where keys live** and **which transport** is used for identity and sync. The backend stores **public** data (addresses, `telegram_username` ↔ address mapping when the user opts in), never mnemonics.
26
+
27
+ ---
28
+
29
+ ## 2. Why Telegram alone is not enough (and how we fix it)
30
+
31
+ Telegram can be unreachable (outage, censorship, user choice). A product that *only* creates or signs inside the Mini App forces a hard dependency on Telegram for custody and signing.
32
+
33
+ **Proposal:**
34
+
35
+ 1. **Default recommended path** remains: create primary **TON** wallet in TMA (best onboarding, aligns with bot + DLLR messaging).
36
+ 2. **Mandatory parallel capability:** the same app build supports **Create / Restore wallet locally** (standalone) with **no Telegram account** and **no bot call** for key generation.
37
+ 3. **Linking layer (optional):** if the user *has* Telegram, they can **link** `telegram_username` ↔ `wallet_address` so CloudStorage sync and bot confirmations work. If they never link, they remain fully standalone; DLLR/Ton features still work on-chain by address.
38
+ 4. **Degraded mode:** if Telegram is down but the user already has keys on device, the app runs **full local signing** for TON (and any chain we have implemented client-side). Features that *require* the bot (e.g. push approval via Telegram) show a clear “Unavailable while Telegram is unreachable” with fallback: open pending items in TMA later, or confirm via standalone signing if the flow allows.
39
+
40
+ This matches non-custodial rules: the server never becomes the signing authority.
41
+
42
+ ---
43
+
44
+ ## 3. DLLR on TON as the canonical product wallet
45
+
46
+ **Clarification to remove confusion:**
47
+
48
+ - **Primary app wallet** = **TON** address derived from the user’s main mnemonic (or from a TON Connect wallet they set as default).
49
+ - **DLLR** is treated as a **TON jetton / program** (or locked-state construct per your issuance design). Balances, locks, and allocations are **read and signed on TON**.
50
+ - “Multi-chain” does **not** mean DLLR exists on every chain. It means:
51
+ - **User may connect other addresses** for portfolio view, bridges, or future features.
52
+ - **Product-critical flows** (rewards, locks, compliance hooks tied to DLLR) stay **TON-first**.
53
+
54
+ **UI rule:** always show a clear **“Primary (TON + DLLR)”** section, then **“Other networks”** as secondary, so expectations stay aligned with issuance on TON.
55
+
56
+ ---
57
+
58
+ ## 4. Multi-chain matrix (recommended model)
59
+
60
+ Use a single **wallet registry** in the client and the `wallets` table (as in `security_plan_raw.md`), with explicit `blockchain`, `net`, and `type`:
61
+
62
+ | Type | Example | Custody |
63
+ |------|---------|--------|
64
+ | `internal` | App-generated TON keypair | Non-custodial; keys in device/TMA storage |
65
+ | `tonconnect` | Tonkeeper, MyTonWallet | User’s external wallet; we only hold address + session |
66
+ | `walletconnect` / `evm` / `solana` (future) | MetaMask, Phantom, … | Same: address + connection state |
67
+
68
+ **Telegram-hosted vs unhosted** applies only to **`internal`** wallets:
69
+
70
+ - In TMA, `internal` wallet uses SecureStorage + CloudStorage ciphertext split.
71
+ - In standalone app, `internal` wallet uses only OS secure storage (same cryptography, different storage adapters).
72
+
73
+ **Connected** wallets are **always** “hosted” by the third-party provider, not by Telegram and not by us.
74
+
75
+ ---
76
+
77
+ ## 5. Identity: Telegram as optional glue, not a single gate
78
+
79
+ Today’s docs lean **Telegram-first** for onboarding. The unified model adds:
80
+
81
+ | User state | Can use app? | DLLR / TON actions |
82
+ |------------|--------------|--------------------|
83
+ | Standalone, never linked Telegram | Yes (after local create/restore) | Yes, if keys on device |
84
+ | Telegram user, wallet only in TMA | Yes in TMA; on mobile/web after Telegram Login | Signing in TMA; read-only elsewhere unless mnemonic imported locally (optional advanced) |
85
+ | Linked Telegram + local keys | Yes everywhere | Full: bot confirmations where implemented + local signing fallback |
86
+
87
+ **Backend:**
88
+
89
+ - `users.telegram_username` is **nullable** for standalone-only users, or use a separate **account id** (emailless) keyed by device-chosen identifier only for analytics—not for custody.
90
+ - Linking Telegram is a **deliberate** step: “Connect Telegram for notifications and faster sync.”
91
+
92
+ ---
93
+
94
+ ## 6. First run and subsequent runs (program behavior)
95
+
96
+ This section describes what the **client program** does on **cold start** (first launch or fresh install) versus **later launches** on the same install, for each major surface. It aligns with the state machine in `wallets_hosting_architecture.md` (e.g. `awallet_v1`, deploy status).
97
+
98
+ ### 6.1 Shared startup sequence (all surfaces)
99
+
100
+ 1. **Bootstrap UI shell** — Router loads; global providers start (network, wallet context).
101
+ 2. **Detect environment** — `TMA` (Telegram WebApp present) vs **standalone** (Expo native / open web) vs **web + Telegram Login** (widget session).
102
+ 3. **Resolve wallet presence** — Read local secure storage keys (`awallet_v1` or equivalent): encrypted blob for `internal` wallet, plus any **connected** wallet session handles (TON Connect).
103
+ 4. **Branch:**
104
+ - **No wallet record** → onboarding (Section 6.2).
105
+ - **Wallet record present** → main app (Section 6.3).
106
+
107
+ Balances and DLLR/TON state are **always** refreshed asynchronously after UI is usable (do not block first paint on RPC unless product requires it).
108
+
109
+ ---
110
+
111
+ ### 6.2 First run (no wallet on this install)
112
+
113
+ | Entry | What the user sees | What the program does |
114
+ |--------|--------------------|------------------------|
115
+ | **Telegram Mini App** | Intro → **Create wallet** / **Restore wallet** (optional **Connect Tonkeeper** if offered). | Generates mnemonic locally; stores **wallet master key** in Telegram `SecureStorage`; stores **seed ciphertext** in `CloudStorage`; registers **public** `wallet_address` (+ `telegram_username` from `initData`) with backend. Shows address and QR immediately; may show **Deploying** for SMC/jetton setup; nudges **backup seed**. |
116
+ | **Standalone (native / web, no Telegram)** | Same choice: **Create** / **Restore** / **Connect** external wallet. | Generates or imports keys using **only** OS keystore / WebCrypto; **no** `initData`, **no** CloudStorage unless user later links Telegram. Optional backend call with a **non-Telegram** account id or anonymous mode until linked. |
117
+ | **Store mobile app (Telegram-centric onboarding)** | Per `security_raw.md`: “Create wallet in Telegram” vs “I already have a wallet” + **Log in with Telegram**. | First path deep-links to TMA; second uses **Telegram Login** to fetch **public** linkage (`username` → `wallet_address`) for **read-only** until user imports mnemonic on device (if you add that flow). |
118
+
119
+ **First run, new Telegram device (TMA):** `CloudStorage` may already hold **ciphertext** from another device, but **SecureStorage** is empty → program shows **Authorize this device** and asks for **mnemonic once**, then writes local master key and proceeds as normal.
120
+
121
+ **First run, connected wallet only (TON Connect):** No internal blob; program stores connection session + address; primary balance flows use that address until user adds an `internal` wallet.
122
+
123
+ ---
124
+
125
+ ### 6.3 Subsequent runs (wallet already on this device)
126
+
127
+ | Condition | Program behavior |
128
+ |-----------|------------------|
129
+ | **Encrypted blob + device key present** | **Silent load:** decrypt wallet, navigate to **home / wallet** without asking for seed. Poll `/wallet/status` or chain APIs for **deploy status**, **TON balance**, **DLLR** state. If deploy was **pending**, **retry deploy** in background (same as `wallets_hosting_architecture.md`). |
130
+ | **TMA + CloudStorage ciphertext + SecureStorage OK** | Same silent path; CloudStorage may sync updates from other Telegram clients. |
131
+ | **Standalone + keys in local secure storage** | Same as row 1; **no** Telegram dependency for open or sign. |
132
+ | **User opened “Log in with Telegram” on mobile** | After verified login, app loads **cached** `telegram_username` + **addresses** from API; UI is **read-first** until local signing is enabled (mnemonic import), matching your phased plan. |
133
+ | **Telegram unavailable (outage / blocked)** | If keys exist locally: **full app** for signing and reads that do not need the bot. If keys exist **only** in TMA on a device that cannot open Telegram: user must use **restore** on standalone build or wait for Telegram. Features that need the bot show **degraded / queue** messaging. |
134
+ | **App update** | Same storage keys (`awallet_v1` versioning); run **migration** if blob format bumps. Wallet survives update if paths are stable. |
135
+
136
+ **Subsequent run UX expectations:** back up seed remains **dismissible** until acknowledged; high-value actions may still route through **pending tx + bot confirmation** when Telegram is linked and the flow requires it.
137
+
138
+ ---
139
+
140
+ ### 6.4 Summary table
141
+
142
+ | | First run | Subsequent runs |
143
+ |---|-----------|-----------------|
144
+ | **Typical path** | Onboarding → create / restore / connect | Silent unlock → home → background balance/deploy sync |
145
+ | **Telegram required?** | Only for TMA path or Telegram-login shell | No, if standalone keys exist; yes for TMA-specific features |
146
+ | **Seed prompt** | At creation (show once) or restore; optional “authorize device” on new TMA device | Only if blob missing, storage wiped, or user hits **Restore** |
147
+
148
+ ---
149
+
150
+ ## 7. “Perfect setup” summary (one paragraph)
151
+
152
+ **Ship one Expo app** with three entry modes: (1) **Telegram Mini App** for best-in-class onboarding, CloudStorage-backed ciphertext sync, and bot-mediated confirmations; (2) **standalone** create/restore so the app **always launches** and can sign TON (and DLLR) without Telegram; (3) **TON Connect + future multi-chain connectors** for imported liquidity and power users. Treat **TON + DLLR** as the single source of truth for product economics; treat other chains as **attached accounts**. Keep **mnemonic / keys** only on the client, **ciphertext** in CloudStorage when Telegram is used, and **public addresses + optional Telegram link** on the server. When Telegram is down, **degrade gracefully**: local signing and read paths keep working; Telegram-only steps queue or hide with clear messaging.
153
+
154
+ ---
155
+
156
+ ## 8. Implementation phases (aligned with existing roadmap)
157
+
158
+ 1. **Phase A — Standalone parity (minimum viable resilience)**
159
+ - Unhosted TON create/restore in **Expo web + native** without Telegram.
160
+ - Same `WalletService` abstraction as in `wallets_hosting_architecture.md`; storage backend switches on environment (TMA vs native).
161
+ - Optional “Link Telegram” after the fact.
162
+
163
+ 2. **Phase B — Linking & DB**
164
+ - Nullable Telegram on `users`; `wallets` rows for `internal` + `tonconnect`.
165
+ - Telegram Login only for users who want cross-surface sync.
166
+
167
+ 3. **Phase C — Bot confirmations + queue**
168
+ - Pending tx from any client; confirmation in TMA when available; standalone users complete via **local sign** without bot where the protocol allows.
169
+
170
+ 4. **Phase D — Multi-chain read + selective write**
171
+ - Add connected chains for **display** first; add signing per chain as product requires.
172
+
173
+ ---
174
+
175
+ ## 9. Security notes (unchanged principles)
176
+
177
+ - No mnemonic on server; CloudStorage holds **ciphertext only**; device-bound keys decrypt.
178
+ - Telegram Login proves **identity**, not possession of keys.
179
+ - Standalone users rely on **seed backup** exactly as in self-custody best practice.
180
+ - DLLR issuance rules remain **on-chain** on TON; our app is a **client**, not an issuer.
181
+
182
+ ---
183
+
184
+ ## 10. Open decisions (to refine with product/legal)
185
+
186
+ - Whether standalone users get **full** DLLR program participation or **subset** until KYC/Telegram link (if required by issuance policy).
187
+ - Exact **jetton master** and **wallet v4/v5** choices for DLLR display and deploy flows.
188
+ - Whether **one mnemonic** derives only TON or also other chains (prefer **separate mnemonics** per chain unless using a documented multi-chain HD profile).
189
+
190
+ ---
191
+
192
+ *Proposal doc; iterate with team and adjust table/column names to match the actual migration from `security_plan_raw.md`.*