|
1 | 1 | --- |
2 | | -title: External wallets |
| 2 | +title: Ecency wallets |
3 | 3 | --- |
4 | 4 |
|
5 | 5 | import { Code } from "@astrojs/starlight/components"; |
6 | 6 | import { Aside } from "@astrojs/starlight/components"; |
7 | 7 |
|
8 | | -Any user in a Ecency system can create/import external tokens to account. It helps different clients and Ecency to operate with these tokens, show overview or detailed view etc. |
| 8 | +Ecency wallets replaces the older Ecency SDK experience and focuses purely on |
| 9 | +wallet-related operations across the Ecency website and mobile app. The new |
| 10 | +`@ecency/wallets` package gives us a single, dedicated layer for creating and |
| 11 | +managing wallets while keeping the rest of the Ecency stack lightweight. |
9 | 12 |
|
10 | | -### Storage |
| 13 | +## Standard seed phrase, multi-chain addresses |
11 | 14 |
|
12 | | -Each token's public information is storing in two places: |
| 15 | +We utilize a blockchain-standard seed phrase to derive wallet addresses across |
| 16 | +different blockchains. A single mnemonic can be used to: |
13 | 17 |
|
14 | | -1. **Private Ecency API** – uses for Ecency only purposes, strong-safe place; |
15 | | -2. **Profile metadata** – can be used in any Hive client, weak-safe place, could be overrided by any client. |
| 18 | +1. Generate addresses for multiple supported chains without asking the user to |
| 19 | + juggle several keys. |
| 20 | +2. Keep derivation compatible with common wallet tooling, so the same seed can |
| 21 | + be recovered in other BIP39-style wallets. |
| 22 | +3. Sync addresses between web and mobile clients while still letting each |
| 23 | + client enforce its own encryption and secure storage policies. |
16 | 24 |
|
17 | | -### Create a wallet |
| 25 | +<Aside type="note"> |
| 26 | + The seed phrase never leaves the client. When a wallet needs to be backed up |
| 27 | + or restored, the mnemonic is provided by the user, and derived addresses are |
| 28 | + synced to Ecency services only after local encryption is applied. |
| 29 | +</Aside> |
| 30 | + |
| 31 | +## What `@ecency/wallets` handles |
| 32 | + |
| 33 | +`@ecency/wallets` is scoped to wallet functionality so the rest of the Ecency |
| 34 | +codebase can stay focused on social and content features. The package is |
| 35 | +responsible for: |
| 36 | + |
| 37 | +- Generating or importing the mnemonic that seeds all derived addresses. |
| 38 | +- Deriving per-chain addresses from the same seed phrase, so Ecency can surface |
| 39 | + balances and transactions for multiple blockchains. |
| 40 | +- Publishing public wallet metadata to Ecency services when users choose to |
| 41 | + make their addresses available. |
18 | 42 |
|
19 | | -To create a wallet SDK provides mutations and automatically set it to query. No need to handle it automatically. |
| 43 | +## Example: derive addresses from a mnemonic |
| 44 | + |
| 45 | +The snippet below shows the general flow for creating a mnemonic and deriving a |
| 46 | +set of addresses. The exact API surface may evolve, but the key steps—create or |
| 47 | +import a seed, derive addresses for requested chains, and persist only the |
| 48 | +public details—remain the same. |
20 | 49 |
|
21 | 50 | export const exampleCode = ` |
22 | | -import { useWalletCreate, EcencyWalletCurrency } from '@ecency/sdk'; |
| 51 | +import { createWalletClient } from '@ecency/wallets'; |
| 52 | +
|
| 53 | +// Create a client for wallet-only operations in web or mobile apps |
| 54 | +const walletClient = createWalletClient(); |
23 | 55 |
|
24 | | -const username = 'demo.com'; |
25 | | -const currency = EcencyWalletCurrency.BTC; |
| 56 | +// Either generate or import a mnemonic |
| 57 | +const mnemonic = await walletClient.createMnemonic(); |
26 | 58 |
|
27 | | -const { mutateAsync: createWallet } = useWalletCreate(username, currency); |
| 59 | +// Derive addresses for the chains you need to display in Ecency |
| 60 | +const addresses = await walletClient.deriveAddresses({ |
| 61 | + mnemonic, |
| 62 | + chains: ['hive', 'bitcoin', 'ethereum'], |
| 63 | +}); |
28 | 64 |
|
29 | | -// Wallets contains all wallets in a Record<EcencyWalletCurrency, {...}> format |
30 | | -const { data: wallets } = useQuery({ queryKey: ["ecency-wallets", "wallets", username] }) |
| 65 | +// Store only public addresses with Ecency services; keep the mnemonic local |
| 66 | +await walletClient.publishPublicWallets({ addresses }); |
31 | 67 | `; |
32 | | -export const fileName = "create-wallet.ts"; |
| 68 | +export const fileName = "wallets.ts"; |
33 | 69 |
|
34 | 70 | <Code code={exampleCode} lang="ts" title={fileName} /> |
35 | | - |
36 | | -<Aside type="caution"> |
37 | | - Created wallets exists only in current session. Wallets haven't published |
38 | | - anywhere on this step. Saving to private API or metadata are different |
39 | | - mutations. |
40 | | -</Aside> |
|
0 commit comments