|
| 1 | +# Identus TypeScript SDK — Agent Instructions |
| 2 | + |
| 3 | +## Developer Commands |
| 4 | + |
| 5 | +| Command | What it does | |
| 6 | +|---------|-------------| |
| 7 | +| `yarn build` | Full build via `build.sh` (cleans first, then builds in dependency order) | |
| 8 | +| `yarn test` | Run all package tests (`npx nx run-many --target=test`) | |
| 9 | +| `yarn lint` | ESLint across all packages (`npx nx run-many --target=lint`) | |
| 10 | +| `yarn lint:fix` | ESLint with `--fix` across all packages | |
| 11 | +| `yarn lint:text` | markdownlint-cli2 + yamllint + editorconfig-checker | |
| 12 | +| `yarn lint:text:fix` | markdownlint-cli2 with `--fix` | |
| 13 | +| `yarn clean` | Removes generated dirs, build dirs, and resets Nx cache | |
| 14 | +| `yarn clean:generated` | Removes all `generated/` folders (WASM bindings only — protobuf `.ts` output in `packages/lib/protos/src/` is overwritten on rebuild, not deleted by this command) | |
| 15 | +| `yarn clean:build` | Removes all `build/` folders | |
| 16 | +| `yarn clean:reset` | Resets Nx cache (`npx nx reset`) | |
| 17 | +| `yarn coverage` | Vitest coverage across all workspace projects (`packages/lib/*`, `shared/*`, `wasm/*`) via root `vitest.config.js` | |
| 18 | +| `yarn coverage:nx` | Coverage across all Nx packages via `nx run-many` (includes typecheck dependency) | |
| 19 | +| `yarn docs` | TypeDoc generation across packages | |
| 20 | + |
| 21 | +## Single-Package Commands |
| 22 | + |
| 23 | +Nx projects are addressed by their `package.json` `name`. Key project names: |
| 24 | + |
| 25 | +- `@hyperledger/identus-protos` — protobuf definitions (`packages/lib/protos`) |
| 26 | +- `@hyperledger/identus-domain` — shared domain types (`packages/shared/domain`) |
| 27 | +- `@hyperledger/identus-anoncreds` — AnonCreds WASM wrapper (`packages/wasm/anoncreds`) |
| 28 | +- `@hyperledger/identus-didcomm` — DIDComm WASM wrapper (`packages/wasm/didcomm`) |
| 29 | +- `@hyperledger/identus-jwe` — JWE WASM wrapper (`packages/wasm/jwe`) |
| 30 | +- `@hyperledger/identus-sdk` — main SDK (`packages/lib/sdk`) |
| 31 | + |
| 32 | +```bash |
| 33 | +npx nx test @hyperledger/identus-sdk # test one package |
| 34 | +npx nx build @hyperledger/identus-domain # build one package |
| 35 | +npx nx lint @hyperledger/identus-anoncreds # lint one package |
| 36 | +npx nx test-watch @hyperledger/identus-sdk # vitest watch mode |
| 37 | +npx nx coverage @hyperledger/identus-sdk # coverage for one package |
| 38 | +npx nx docs @hyperledger/identus-sdk # TypeDoc for SDK |
| 39 | +``` |
| 40 | + |
| 41 | +The `--tui false` flag disables Nx interactive UI in CI/terminals where TUI fails. |
| 42 | + |
| 43 | +## Build Order & Prerequisites |
| 44 | + |
| 45 | +**Required toolchain (all must be installed before building):** |
| 46 | + |
| 47 | +1. **Node.js** — LTS version (20 recommended) |
| 48 | +2. **Rust nightly + cargo** — required to compile WASM crates |
| 49 | +3. **wasm-pack** — builds Rust → WASM with JS bindings (`curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh`) |
| 50 | +4. **protobuf-compiler** (`protoc`) — compiles `.proto` files to TypeScript |
| 51 | + |
| 52 | +**First-time build — submodules must be initialized first:** |
| 53 | + |
| 54 | +```bash |
| 55 | +bash externals/run.sh -x update # git submodule update --init --recursive, then builds WASM |
| 56 | +``` |
| 57 | + |
| 58 | +**Build sequence** (as coded in `build.sh`): |
| 59 | + |
| 60 | +1. `yarn clean` + `npx nx reset` |
| 61 | +2. `@hyperledger/identus-protos:build` (runs `protoc` then `tsup`) |
| 62 | +3. `@hyperledger/identus-domain:build` |
| 63 | +4. `@hyperledger/identus-anoncreds:build` (depends on `externals` target) |
| 64 | +5. `@hyperledger/identus-didcomm:build` (depends on `externals` target) |
| 65 | +6. `@hyperledger/identus-jwe:build` (depends on `externals` target) |
| 66 | +7. `@hyperledger/identus-sdk:build` |
| 67 | + |
| 68 | +WASM packages have an `externals` Nx target that runs `externals/run.sh -x update` if the submodule commit has changed. The build target depends on `externals` implicitly. |
| 69 | + |
| 70 | +## Monorepo Structure |
| 71 | + |
| 72 | +Yarn 4 workspaces + Nx. Three workspace groups: |
| 73 | + |
| 74 | +``` |
| 75 | +packages/ |
| 76 | +├── lib/ |
| 77 | +│ ├── protos/ — @hyperledger/identus-protos (protobuf definitions) |
| 78 | +│ └── sdk/ — @hyperledger/identus-sdk (main SDK) |
| 79 | +├── shared/ |
| 80 | +│ └── domain/ — @hyperledger/identus-domain (shared types/interfaces) |
| 81 | +└── wasm/ |
| 82 | + ├── anoncreds/ — @hyperledger/identus-anoncreds (AnonCreds WASM wrapper) |
| 83 | + ├── config/ — Nx/Vitest shared WASM config (scope:config tag) |
| 84 | + ├── didcomm/ — @hyperledger/identus-didcomm (DIDComm WASM wrapper) |
| 85 | + └── jwe/ — @hyperledger/identus-jwe (JWE WASM wrapper) |
| 86 | +
|
| 87 | +externals/ |
| 88 | +├── anoncreds/ — Git submodule: Rust AnonCreds crate source |
| 89 | +├── didcomm/ — Git submodule: Rust DIDComm crate source |
| 90 | +├── run.sh — Submodule check/build/update script (-x check|build|update) |
| 91 | +└── *.commit — Tracks last-built submodule commit hashes |
| 92 | +``` |
| 93 | + |
| 94 | +## Package Architecture |
| 95 | + |
| 96 | +The main SDK (`packages/lib/sdk`) contains the Identus building blocks: |
| 97 | + |
| 98 | +- **Apollo** (`src/apollo/`) — Cryptographic operations (key generation, signing, etc.) |
| 99 | +- **Castor** (`src/castor/`) — DID creation, management, and resolution |
| 100 | +- **Mercury** (`src/mercury/`) — DIDComm V2 message handling |
| 101 | +- **Pluto** (`src/pluto/`) — Storage interface (portable, storage-agnostic) |
| 102 | +- **Agent** (`src/edge-agent/`) — Edge agent using all building blocks; implements DIDComm V2 protocols |
| 103 | +- **Pollux** (`src/pollux/`) — Verifiable credentials logic |
| 104 | +- **Plugins** (`src/plugins/`) — Optional: anoncreds, didcomm, oidc, dif, oea |
| 105 | + |
| 106 | +The SDK exports sub-path entry points: `@hyperledger/identus-sdk/plugins/anoncreds`, `/plugins/didcomm`, `/plugins/oidc`, `/plugins/dif`, `/plugins/oea`. |
| 107 | + |
| 108 | +## Generated Code |
| 109 | + |
| 110 | +**Never edit generated files.** They are overwritten on next build. |
| 111 | + |
| 112 | +- `packages/wasm/anoncreds/generated/` — WASM bindings from `wasm-pack build` on the AnonCreds Rust crate |
| 113 | +- `packages/wasm/didcomm/generated/` — WASM bindings from `wasm-pack build` on the DIDComm Rust crate |
| 114 | +- `packages/wasm/jwe/generated/` — WASM bindings from `wasm-pack build` on the JWE Rust crate |
| 115 | +- `packages/lib/protos/src/*.ts` — TypeScript output from `protoc` (invoked via `npm run protos` inside the protos package) |
| 116 | + |
| 117 | +Clean all generated code: `yarn clean:generated` (finds and removes all `generated/` directories). |
| 118 | + |
| 119 | +## Build Artifacts |
| 120 | + |
| 121 | +- `packages/*/build/` — compiled JS + type declarations from `tsup` |
| 122 | +- `.nx/` — Nx computation cache (deleted by `yarn clean:reset` / `npx nx reset`) |
| 123 | +- `coverage/` — Vitest coverage output |
| 124 | + |
| 125 | +## Testing |
| 126 | + |
| 127 | +- **Unit tests**: Vitest config per package (`vitest.config.js`). Tests live in `packages/*/tests/`. |
| 128 | +- **SDK tests** use `jsdom` environment (not Node) and load WASM via a custom Vite plugin (`WasmPlugin` in `packages/lib/sdk/vitest.config.js`) that reads `.wasm` files and exports them as base64. |
| 129 | +- **Test aliases** resolve `@hyperledger/identus-*-wasm` to local `packages/wasm/*/generated/` dirs. |
| 130 | +- **testTimeout**: 12 seconds for SDK tests. |
| 131 | +- **E2E tests**: `integration-tests/e2e-tests/` — requires running Cloud Agent and Mediator. Run via `./integration-tests/e2e-tests/run.sh` or `npm run test:sdk` from within the e2e-tests directory. Requires `.env` configuration (see `integration-tests/e2e-tests/README.md`). |
| 132 | + |
| 133 | +## Linting |
| 134 | + |
| 135 | +- **ESLint**: flat config (`eslint.base.mjs`) with type-checked rules from `typescript-eslint`. Errors for async safety (`no-floating-promises`, `no-misused-promises`); warnings for `any` usage. Namespace declarations allowed (`@typescript-eslint/no-namespace: off`). |
| 136 | +- **Excluded from ESLint**: `**/dist/**`, `**/build/**`, `**/node_modules/**`, `**/coverage/**`, `**/*.d.ts`, `**/generated/**`, `externals/**`, `src/castor/protos/**` |
| 137 | +- **Text lint** (`yarn lint:text`): markdownlint-cli2, yamllint, editorconfig-checker |
| 138 | +- **Lint fix**: `yarn lint:fix` (ESLint), `yarn lint:text:fix` (markdownlint only) |
| 139 | + |
| 140 | +## Release |
| 141 | + |
| 142 | +- Nx manages independent per-project releases (`projectsRelationship: "independent"` in `nx.json`) |
| 143 | +- `release.sh` runs as the `preVersionCommand` — generates TypeDoc (`yarn docs`) and stages the output (`git add docs`) before versioning |
| 144 | +- Conventional commits required for changelog generation |
| 145 | +- Tag pattern: `{projectName}@{version}` |
| 146 | +- GitHub releases created automatically by Nx |
0 commit comments