pda-explorer-react 0.1.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/README.md +159 -0
- package/dist/components/AccountNode.d.ts +17 -0
- package/dist/components/PdaExplorer.d.ts +29 -0
- package/dist/components/PdaGraph.d.ts +18 -0
- package/dist/components/SeedPanel.d.ts +11 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/index.cjs +48 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +11957 -0
- package/dist/styles.css +1 -0
- package/dist/types/graph.d.ts +29 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/schema.d.ts +84 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# PDA Explorer
|
|
2
|
+
|
|
3
|
+
Interactive visualization tool for Solana Program Derived Address (PDA) hierarchies.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Why?
|
|
8
|
+
|
|
9
|
+
Solana's PDA model can be challenging to reason about:
|
|
10
|
+
|
|
11
|
+
- PDAs form hierarchical trees where child addresses depend on parent data
|
|
12
|
+
- Relationships are implicit in seed derivation patterns
|
|
13
|
+
- Discovery requires knowing the exact seed structure
|
|
14
|
+
|
|
15
|
+
PDA Explorer makes these relationships **visual and interactive**, helping developers understand their program's account model.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @pda-explorer/react
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { PdaExplorer } from "@pda-explorer/react";
|
|
27
|
+
import "@pda-explorer/react/styles.css";
|
|
28
|
+
|
|
29
|
+
// Define your program's PDA schema
|
|
30
|
+
const mySchema = {
|
|
31
|
+
programName: "My Program",
|
|
32
|
+
programId: "MyProgram111111111111111111111111111111111",
|
|
33
|
+
accounts: {
|
|
34
|
+
UserAccount: {
|
|
35
|
+
id: "UserAccount",
|
|
36
|
+
name: "User Account",
|
|
37
|
+
seeds: [
|
|
38
|
+
{ name: "prefix", type: "literal", value: "user" },
|
|
39
|
+
{ name: "authority", type: "pubkey", source: "User's wallet" },
|
|
40
|
+
],
|
|
41
|
+
parent: null,
|
|
42
|
+
children: ["UserData"],
|
|
43
|
+
description: "Main user account",
|
|
44
|
+
color: "#8B5CF6",
|
|
45
|
+
},
|
|
46
|
+
UserData: {
|
|
47
|
+
id: "UserData",
|
|
48
|
+
name: "User Data",
|
|
49
|
+
seeds: [
|
|
50
|
+
{ name: "prefix", type: "literal", value: "data" },
|
|
51
|
+
{ name: "user", type: "pubkey", source: "UserAccount PDA" },
|
|
52
|
+
{ name: "index", type: "u64", source: "Data index" },
|
|
53
|
+
],
|
|
54
|
+
parent: "UserAccount",
|
|
55
|
+
children: [],
|
|
56
|
+
description: "User's data entries",
|
|
57
|
+
color: "#10B981",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function App() {
|
|
63
|
+
return (
|
|
64
|
+
<PdaExplorer
|
|
65
|
+
schema={mySchema}
|
|
66
|
+
height={600}
|
|
67
|
+
showLegend={true}
|
|
68
|
+
showPanel={true}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Schema Format
|
|
75
|
+
|
|
76
|
+
### PdaSchema
|
|
77
|
+
|
|
78
|
+
| Field | Type | Description |
|
|
79
|
+
| ------------- | ------------------------------- | ------------------------------ |
|
|
80
|
+
| `programName` | `string` | Display name of your program |
|
|
81
|
+
| `programId` | `string?` | Base58 program ID |
|
|
82
|
+
| `description` | `string?` | Program description |
|
|
83
|
+
| `accounts` | `Record<string, PdaAccountType>` | Account type definitions |
|
|
84
|
+
|
|
85
|
+
### PdaAccountType
|
|
86
|
+
|
|
87
|
+
| Field | Type | Description |
|
|
88
|
+
| ------------------- | ----------------- | ---------------------------------------- |
|
|
89
|
+
| `id` | `string` | Unique identifier |
|
|
90
|
+
| `name` | `string` | Display name |
|
|
91
|
+
| `seeds` | `SeedComponent[]` | Seed derivation pattern |
|
|
92
|
+
| `parent` | `string \| null` | Parent account ID (null for root) |
|
|
93
|
+
| `children` | `string[]` | Child account IDs |
|
|
94
|
+
| `description` | `string` | What this account stores |
|
|
95
|
+
| `color` | `string` | Hex color for visualization |
|
|
96
|
+
| `deriveFunctionName`| `string?` | Name of derive function (for reference) |
|
|
97
|
+
|
|
98
|
+
### SeedComponent
|
|
99
|
+
|
|
100
|
+
| Field | Type | Description |
|
|
101
|
+
| -------- | ---------- | ---------------------------------------- |
|
|
102
|
+
| `name` | `string` | Seed name (for display) |
|
|
103
|
+
| `type` | `SeedType` | `literal`, `pubkey`, `u8`-`u64` |
|
|
104
|
+
| `value` | `string?` | For literal seeds: the string value |
|
|
105
|
+
| `source` | `string?` | Human-readable description of data source|
|
|
106
|
+
|
|
107
|
+
## Component Props
|
|
108
|
+
|
|
109
|
+
### PdaExplorer
|
|
110
|
+
|
|
111
|
+
| Prop | Type | Default | Description |
|
|
112
|
+
| ------------- | ------------------- | -------------------------- | ------------------------------- |
|
|
113
|
+
| `schema` | `PdaSchema` | required | The PDA schema to visualize |
|
|
114
|
+
| `title` | `string?` | `{programName} PDA Explorer`| Custom title |
|
|
115
|
+
| `description` | `string?` | Schema description | Custom description |
|
|
116
|
+
| `showLegend` | `boolean` | `true` | Show quick-select legend |
|
|
117
|
+
| `showPanel` | `boolean` | `true` | Show seed details panel |
|
|
118
|
+
| `panelWidth` | `number \| string` | `320` | Panel width |
|
|
119
|
+
| `height` | `number \| string` | `600` | Component height |
|
|
120
|
+
| `className` | `string` | `""` | Additional CSS classes |
|
|
121
|
+
|
|
122
|
+
## Exports
|
|
123
|
+
|
|
124
|
+
### Components
|
|
125
|
+
|
|
126
|
+
- `PdaExplorer` - Main visualization component
|
|
127
|
+
- `PdaGraph` - Graph canvas (for custom layouts)
|
|
128
|
+
- `SeedPanel` - Seed details panel (for custom layouts)
|
|
129
|
+
- `AccountNode` - Individual node component
|
|
130
|
+
|
|
131
|
+
### Types
|
|
132
|
+
|
|
133
|
+
- `PdaSchema`, `PdaAccountType`, `SeedComponent`, `SeedType`
|
|
134
|
+
- `PdaNode`, `PdaNodeData`, `PdaEdge`, `PdaEdgeData`
|
|
135
|
+
|
|
136
|
+
### Helpers
|
|
137
|
+
|
|
138
|
+
- `getRootAccounts(schema)` - Get root-level accounts
|
|
139
|
+
- `getChildren(schema, id)` - Get children of an account
|
|
140
|
+
- `getParent(schema, id)` - Get parent of an account
|
|
141
|
+
- `formatSeedPattern(account)` - Format seeds as `["prefix", pubkey, u64_le]`
|
|
142
|
+
- `validateSchema(schema)` - Validate schema for errors
|
|
143
|
+
|
|
144
|
+
## Development
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
# Install dependencies
|
|
148
|
+
npm install
|
|
149
|
+
|
|
150
|
+
# Run demo app
|
|
151
|
+
npm run dev
|
|
152
|
+
|
|
153
|
+
# Build library
|
|
154
|
+
npm run build
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PdaNodeData } from '../types';
|
|
2
|
+
|
|
3
|
+
interface AccountNodeProps {
|
|
4
|
+
data: PdaNodeData;
|
|
5
|
+
selected?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Custom node component for PDA accounts in the graph
|
|
9
|
+
*
|
|
10
|
+
* Displays:
|
|
11
|
+
* - Account name with color-coded background
|
|
12
|
+
* - Seed count badge
|
|
13
|
+
* - Connection handles for edges
|
|
14
|
+
*/
|
|
15
|
+
declare function AccountNodeComponent({ data, selected }: AccountNodeProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare const AccountNode: import('react').MemoExoticComponent<typeof AccountNodeComponent>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PdaSchema } from '../types';
|
|
2
|
+
|
|
3
|
+
export interface PdaExplorerProps {
|
|
4
|
+
/** The PDA schema to visualize */
|
|
5
|
+
schema: PdaSchema;
|
|
6
|
+
/** Optional title override (defaults to schema.programName) */
|
|
7
|
+
title?: string;
|
|
8
|
+
/** Optional description override */
|
|
9
|
+
description?: string;
|
|
10
|
+
/** Show the legend/quick select bar (default: true) */
|
|
11
|
+
showLegend?: boolean;
|
|
12
|
+
/** Show the seed details panel (default: true) */
|
|
13
|
+
showPanel?: boolean;
|
|
14
|
+
/** Panel width in pixels or CSS value (default: 320) */
|
|
15
|
+
panelWidth?: number | string;
|
|
16
|
+
/** Custom class name for the container */
|
|
17
|
+
className?: string;
|
|
18
|
+
/** Height of the explorer (default: 600px) */
|
|
19
|
+
height?: number | string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* PDA Explorer - Interactive visualization of a Solana program's account model
|
|
23
|
+
*
|
|
24
|
+
* Shows all PDA account types with their:
|
|
25
|
+
* - Hierarchical relationships (parent-child)
|
|
26
|
+
* - Seed derivation patterns
|
|
27
|
+
* - Derive function references
|
|
28
|
+
*/
|
|
29
|
+
export declare function PdaExplorer({ schema, title, description, showLegend, showPanel, panelWidth, className, height, }: PdaExplorerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PdaSchema } from '../types';
|
|
2
|
+
|
|
3
|
+
interface PdaGraphProps {
|
|
4
|
+
schema: PdaSchema;
|
|
5
|
+
onNodeSelect: (nodeId: string | null) => void;
|
|
6
|
+
selectedNodeId: string | null;
|
|
7
|
+
/** Edge color (default: #6B7280) */
|
|
8
|
+
edgeColor?: string;
|
|
9
|
+
/** Show minimap (default: true) */
|
|
10
|
+
showMinimap?: boolean;
|
|
11
|
+
/** Show controls (default: true) */
|
|
12
|
+
showControls?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Main graph visualization component using React Flow
|
|
16
|
+
*/
|
|
17
|
+
export declare function PdaGraph({ schema, onNodeSelect, selectedNodeId, edgeColor, showMinimap, showControls, }: PdaGraphProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PdaSchema, PdaAccountType } from '../types';
|
|
2
|
+
|
|
3
|
+
interface SeedPanelProps {
|
|
4
|
+
schema: PdaSchema;
|
|
5
|
+
account: PdaAccountType | null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Side panel showing seed derivation details for a selected account
|
|
9
|
+
*/
|
|
10
|
+
export declare function SeedPanel({ schema, account }: SeedPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|