-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add view-wallet script and wallet import documentation #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
68df079
feat: add view-wallet script to inspect existing wallet
thephez b47b866
docs: add importing existing wallet section and derivation path refer…
thephez d7b530d
docs: add claude.md
thephez 2e2c68c
docs: apply review feedback
thephez ce81e15
fix: rethrow non-identity errors in view-wallet identity lookup
thephez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| Tutorial code for [Dash Platform](https://docs.dash.org/platform) demonstrating how to interact with the Dash network using `@dashevo/evo-sdk`. Covers identities, DPNS names, data contracts, and documents. | ||
|
|
||
| ## Commands | ||
|
|
||
| ```bash | ||
| npm test # Read-only tests (~2min, safe to run anytime) | ||
| npm run test:read-write # Write tests (destructive, consumes testnet credits, ~5min) | ||
| npm run test:all # Both suites sequentially | ||
| npm run test:setup # Mocha tests for setupDashClient configuration | ||
|
|
||
| npm run lint # TypeScript type-check all JS files (tsc) | ||
| npm run fmt # Format with Prettier | ||
| ``` | ||
|
|
||
| **Running a single tutorial directly:** | ||
|
|
||
| ```bash | ||
| node connect.mjs | ||
| node 1-Identities-and-Names/identity-retrieve.mjs | ||
| ``` | ||
|
|
||
| **Running a single test file:** | ||
|
|
||
| ```bash | ||
| node --test --test-timeout=120000 test/read-only.test.mjs | ||
| ``` | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Tutorial Structure | ||
|
|
||
| Each tutorial is a standalone `.mjs` ESM file with top-level `await`. The pattern is consistent: | ||
|
|
||
| ```javascript | ||
| import { setupDashClient } from '../setupDashClient.mjs'; | ||
|
|
||
| const { sdk, keyManager } = await setupDashClient(); | ||
|
|
||
| try { | ||
| // Tutorial logic — use sdk and keyManager | ||
| console.log(result.toJSON()); | ||
| } catch (e) { | ||
| console.error('Something went wrong:\n', e.message); | ||
| } | ||
| ``` | ||
|
|
||
| ### `setupDashClient.mjs` | ||
|
|
||
| The central helper (~500 lines) that all tutorials import. It handles: | ||
|
|
||
| - Loading `.env` via `dotenv` | ||
| - BIP39 wallet derivation from `PLATFORM_MNEMONIC` | ||
| - DIP-13 key path derivation | ||
| - SDK instantiation (`createClient(network)`) | ||
| - Key manager setup — returns `{ sdk, keyManager, addressKeyManager }` | ||
|
|
||
| `keyManager.identityId` resolves automatically from the mnemonic. `keyManager.getAuth()` returns the identity, key, and signer needed for signing transactions. | ||
|
|
||
| > **Note:** The in-memory key pattern in `setupDashClient` is for tutorials only — not suitable for production. | ||
|
|
||
| ### Test Framework | ||
|
|
||
| Tests use Node.js built-in test runner. Each test runs a tutorial as a **subprocess** via `test/run-tutorial.mjs` and validates: | ||
|
|
||
| - Exit code is 0 | ||
| - `stdout`/`stderr` match expected regex patterns | ||
| - Process was not killed (no timeout) | ||
|
|
||
| `test/assertions.mjs` provides helpers like `extractId()` and `extractKeyId()` to capture values from output for use in subsequent dependent tests. | ||
|
|
||
| **Read-write tests** maintain a shared state object to pass IDs (contract IDs, document IDs, etc.) between sequential dependent tests. | ||
|
|
||
| ### Derivation Paths | ||
|
|
||
| All key derivation uses standard Dash paths. External wallets/tools must use the same paths for compatibility. | ||
|
|
||
| | Key type | Testnet path | Mainnet path | | ||
| | - | - | - | | ||
| | Platform address (BIP44) | `m/44'/1'/0'/0/i` | `m/44'/5'/0'/0/i` | | ||
| | Identity master key (DIP-13) | `m/9'/1'/5'/0'/0'/0'/0'` | `m/9'/5'/5'/0'/0'/0'/0'` | | ||
| | Identity keys 0–4 (DIP-13) | `m/9'/1'/5'/0'/0'/0'/k'` | `m/9'/5'/5'/0'/0'/0'/k'` | | ||
|
|
||
| Where `i` = address index and `k` = key index (0=MASTER, 1=HIGH auth, 2=CRITICAL auth, 3=TRANSFER, 4=ENCRYPTION). | ||
|
|
||
| No BIP39 passphrase is used. | ||
|
|
||
| ### Environment Variables | ||
|
|
||
| Copy `.env.example` to `.env`. Key variables: | ||
|
|
||
| | Variable | Purpose | | ||
| | - | - | | ||
| | `PLATFORM_MNEMONIC` | BIP39 mnemonic; required for all write operations | | ||
| | `NETWORK` | `testnet` (default) or `mainnet` | | ||
| | `DATA_CONTRACT_ID` | Output of `contract-register-minimal.mjs` | | ||
| | `DOCUMENT_ID` | Output of `document-submit.mjs` | | ||
| | `RECIPIENT_ID` | Identity ID for credit transfers | | ||
| | `RECIPIENT_PLATFORM_ADDRESS` | `tdash1...` address for send-funds | | ||
|
|
||
| Read-only tests skip gracefully when `PLATFORM_MNEMONIC` is unset. | ||
|
|
||
| ### Directory Layout | ||
|
|
||
| - **Root** — shared utilities (`setupDashClient.mjs`, `connect.mjs`, `create-wallet.mjs`, `view-wallet.mjs`, `send-funds.mjs`) | ||
| - **`1-Identities-and-Names/`** — identity registration, top-up, key management, DPNS name registration/lookup | ||
| - **`2-Contracts-and-Documents/`** — data contract variants (minimal, indexed, binary, timestamps, history, NFT), document CRUD, NFT operations | ||
| - **`test/`** — test runner, assertions, read-only and read-write test suites | ||
| - **`docs/`** — HTML/JS interactive tutorial runner (separate from Node tutorials) | ||
|
|
||
| ### Linting / Types | ||
|
|
||
| TypeScript (`tsconfig.json`) checks JS files with `strict: true`, `noUnusedLocals: true`, targeting Node16 modules. ESLint uses `airbnb-base`. Prettier uses single quotes, 2-space tabs, trailing commas. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { | ||
| createClient, | ||
| clientConfig, | ||
| AddressKeyManager, | ||
| IdentityKeyManager, | ||
| } from './setupDashClient.mjs'; | ||
|
|
||
| const { mnemonic, network } = clientConfig; | ||
|
|
||
| if (!mnemonic) { | ||
| console.error('No mnemonic found. Set PLATFORM_MNEMONIC in your .env file.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| try { | ||
| const sdk = await createClient(network); | ||
| const addressKeyManager = await AddressKeyManager.create({ sdk, mnemonic, network }); | ||
| const { bech32m, path } = addressKeyManager.primaryAddress; | ||
|
|
||
| let identityId = 'No identity found for this mnemonic'; | ||
| try { | ||
| const keyManager = await IdentityKeyManager.create({ sdk, mnemonic, network }); | ||
| identityId = keyManager.identityId; | ||
| } catch (e) { | ||
| if (!e.message?.includes('No identity found for the given mnemonic')) throw e; | ||
| } | ||
|
|
||
| // ⚠️ Never log mnemonics in real applications | ||
| console.log('Network: ', network); | ||
| console.log('Mnemonic: ', mnemonic); | ||
|
thephez marked this conversation as resolved.
|
||
| console.log(`First address: ${bech32m} (${path})`); | ||
| console.log('Fund address: ', `https://bridge.thepasta.org/?address=${bech32m}`); | ||
| console.log('Identity ID: ', identityId); | ||
| } catch (e) { | ||
| console.error('Something went wrong:\n', e.message); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.