Skip to content

Commit b180349

Browse files
committed
feat: initial commit 🚀
0 parents  commit b180349

29 files changed

+9211
-0
lines changed

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Binaries
2+
*.exe
3+
*.dll
4+
*.so
5+
*.dylib
6+
*.wasm
7+
8+
# Go
9+
go.sum
10+
vendor/
11+
12+
# Node
13+
node_modules/
14+
npm-debug.log*
15+
yarn-debug.log*
16+
yarn-error.log*
17+
18+
# Build outputs
19+
dist/
20+
build/
21+
*.log
22+
23+
# IDE
24+
.vscode/
25+
.idea/
26+
*.swp
27+
*.swo
28+
*~
29+
30+
# OS
31+
.DS_Store
32+
Thumbs.db
33+
34+
# Test coverage
35+
*.test
36+
*.out
37+
coverage/
38+
39+
# Example build
40+
example/dist/
41+
42+
# GoReleaser
43+
dist/

.goreleaser.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
project_name: sshclient-wasm
2+
3+
before:
4+
hooks:
5+
- go mod tidy
6+
- go mod download
7+
8+
builds:
9+
- id: wasm
10+
main: ./main.go
11+
binary: sshclient.wasm
12+
goos:
13+
- js
14+
goarch:
15+
- wasm
16+
env:
17+
- CGO_ENABLED=0
18+
ldflags:
19+
- -s -w
20+
21+
archives:
22+
- id: wasm-archive
23+
format: tar.gz
24+
files:
25+
- sshclient.wasm
26+
- wasm_exec.js
27+
- lib/**/*
28+
- package.json
29+
- README.md
30+
- LICENSE
31+
32+
release:
33+
github:
34+
owner: andrew
35+
name: sshclient-wasm
36+
prerelease: auto
37+
38+
checksum:
39+
name_template: 'checksums.txt'
40+
41+
snapshot:
42+
name_template: "{{ incpatch .Version }}-next"
43+
44+
changelog:
45+
sort: asc
46+
filters:
47+
exclude:
48+
- '^docs:'
49+
- '^test:'

CLAUDE.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Project: sshclient-wasm
2+
3+
This is a Golang project that builds a WASM client for ssh on the browser.
4+
5+
It uses Golang's [golang.org/x/crypto/ssh package](https://pkg.go.dev/golang.org/x/crypto/ssh) which already implements the SSH client protocol. It also works with servers but this project is focused on building a client that can be used in the browser with WebSockets.
6+
7+
The compiler target is WebAssembly. The build is done with GoReleaser.
8+
9+
It should ultimately be an NPM package that can be imported as an ES module for use in frontend projects like Next.js.
10+
11+
## Architecture
12+
13+
The architecture is transport-agnostic, supporting multiple transport protocols including raw WebSockets and AWS IoT Secure Tunneling. The Transport Translation Layer provides a unified interface for different transport implementations.
14+
15+
```mermaid
16+
graph TB
17+
subgraph "Browser Environment"
18+
A["ES Module<br/>(TypeScript)"]
19+
B["Transport Translation Layer"]
20+
C["WASM Layer<br/>(Go SSH Client)"]
21+
22+
A --> B
23+
B <--> C
24+
end
25+
26+
subgraph "Transport Implementations"
27+
D["WebSocket Transport"]
28+
E["AWS IoT Secure Tunnel<br/>Transport"]
29+
F["Custom Transport<br/>(User-defined)"]
30+
31+
B --> D
32+
B --> E
33+
B --> F
34+
end
35+
36+
subgraph "Network Layer"
37+
G["Direct WebSocket<br/>Connection"]
38+
H["AWS IoT<br/>Secure Tunneling"]
39+
I["Custom Protocol<br/>Endpoint"]
40+
41+
D <--> G
42+
E <--> H
43+
F <--> I
44+
end
45+
46+
subgraph "Destination"
47+
J["SSH Server"]
48+
49+
G --> J
50+
H --> J
51+
I --> J
52+
end
53+
54+
style A fill:#0277bd,color:#fff
55+
style B fill:#7b1fa2,color:#fff
56+
style C fill:#ef6c00,color:#fff
57+
style D fill:#388e3c,color:#fff
58+
style E fill:#388e3c,color:#fff
59+
style F fill:#388e3c,color:#fff
60+
style G fill:#d32f2f,color:#fff
61+
style H fill:#d32f2f,color:#fff
62+
style I fill:#d32f2f,color:#fff
63+
style J fill:#424242,color:#fff
64+
```
65+
66+
### Key Components
67+
68+
1. **ES Module (TypeScript)**: The public API that applications import and use
69+
2. **Transport Translation Layer**: Bridges JavaScript transports with WASM, handling bidirectional data flow
70+
3. **WASM Layer**: Go implementation of SSH client protocol using `golang.org/x/crypto/ssh`
71+
4. **Transport Implementations**:
72+
- **WebSocket Transport**: Direct WebSocket connections to SSH servers
73+
- **AWS IoT Secure Tunnel Transport**: Implements AWS IoT protocol with frame encoding/decoding
74+
- **Custom Transport**: User-definable transport for proprietary protocols
75+
5. **Network Layer**: The actual network connection (WebSocket, AWS IoT, etc.)
76+
6. **SSH Server**: The destination SSH server
77+
78+
## Tech Stack
79+
80+
- Languages: Golang, TypeScript
81+
- Frameworks: Next.js, React
82+
- Build Tools: GoReleaser, Vite, Pnpm via Corepack
83+
- Tools: WebSocket
84+
- Testing: Vitest, GoTest
85+
- Platforms: Browser
86+
87+
## Project Structure
88+
89+
- `main.go`: The entry point for the Go compiler.
90+
- `pkg/sshclient/`: The SSH client implementation.
91+
- `lib/`: The TypeScript/JavaScript bindings.
92+
- `examples/`: Example applications.
93+
- `dist/`: The build output.
94+
- `node_modules/`: The Node.js dependencies.
95+
- `pnpm-lock.yaml`: The Pnpm lock file.
96+
- `package.json`: The NPM package configuration.
97+
- `README.md`: The project README.
98+
- `LICENSE`: The project license.
99+
100+
## Development
101+
102+
### Prerequisites
103+
104+
- Go 1.23+
105+
- Node.js 22+
106+
- Pnpm 10+

Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.PHONY: build clean test release dev copy-wasm-support
2+
3+
GOOS = js
4+
GOARCH = wasm
5+
GO_BUILD_FLAGS = -ldflags="-s -w"
6+
7+
build: copy-wasm-support
8+
GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(GO_BUILD_FLAGS) -o dist/sshclient.wasm main.go
9+
mkdir -p public
10+
cp dist/sshclient.wasm public/
11+
cp dist/wasm_exec.js public/
12+
13+
copy-wasm-support:
14+
mkdir -p dist
15+
cp "$$(go env GOROOT)/lib/wasm/wasm_exec.js" dist/
16+
17+
clean:
18+
rm -rf dist/
19+
20+
test:
21+
go test ./...
22+
23+
dev: build
24+
cd example && npm install && npm run dev
25+
26+
release:
27+
goreleaser release --snapshot --clean
28+
29+
npm-build: build
30+
npm run build
31+
32+
npm-publish: npm-build
33+
npm publish

0 commit comments

Comments
 (0)