# Developing

## Prerequisites

- Node.js >= 24.6.0 (see `.nvmrc`)
- A GitHub account with access to the `KagamiDigital` organisation

## Registry setup

`salt-sdk` depends on `@kagamidigital/salt-signer-sdk`, hosted on GitHub Packages. Authenticate once before installing:

```bash
npm login --registry=https://npm.pkg.github.com
```

Use your GitHub username and a **classic** personal access token with `read:packages` scope as the password. To create one: [github.com/settings/tokens](https://github.com/settings/tokens) → "Generate new token (classic)" → check `read:packages`. Fine-grained PATs do not support GitHub Packages. This writes credentials to `~/.npmrc` and is a one-time setup per machine.

## Install and build

```bash
npm ci
npm run build
```

## Tests

```bash
npm test          # unit tests
npm run test:e2e  # end-to-end tests
```

E2E tests use real services and can create persistent records and send
transactions. Configure `.env` from `.env.sample`. `VITE_SALT_E2E_ENV` selects
the backend; `VITE_SALT_E2E_DOMAIN` is its registered SIWE domain. Fixture IDs in
`test/e2e/lib/env.ts` are defaults: the optional `VITE_SALT_E2E_ORGANISATION_*`,
`VITE_SALT_E2E_ACCOUNT_*` and `VITE_SALT_E2E_ROBO_ID` variables override them for
your database. Keep the account ID, public key, name and organisation consistent.

## Live child account E2E

```bash
npm run test:e2e -- test/e2e/childTransactions.e2e.test.ts
```

This test imports the real SDK and requires:

- Arbitrum Sepolia (chain ID `421614`); other chains are refused before funding.
- The matching `kagami-node`, websocket relay and MongoDB running. For the
  `localhost` target, the API and relay default to ports `4200` and `5000`.
- An existing, fully backed-up root fixture. User 1 must be an organisation
  owner and a root signer; its required Robo Guardians must be online against
  the same backend, relay, tenant and registry.
- Test keys 1 and 2 in `.env`. User 1 funds the child and pays any quoted Salt
  fees; user 2 supplies the recipient address. The root's policies must allow
  user 1's one-wei transfer to user 2.
- Robo Guardians built with the updated SDK. For local development, rebuild
  `salt-sdk`, link it as `@kagamidigital/salt-sdk-mirror` in `salt-robo`, rebuild
  the daemon and restart it. Merely rebuilding the SDK does not update an
  already bundled/running Guardian.

The transaction test creates a fresh child and tops up its native balance to
`0.0001` test ETH. It also tops up the root to that balance if needed. It mines
two one-wei child transfers and one root transfer, and rejects another child
proposal with a temporary `denied_proposers` policy. It removes only that policy
in `finally`.

The message test creates another child, checks its default
`denied_message_proposers` policy refuses a message, deletes that policy with a
sealed edit, then signs a personal message and typed data and verifies both
against the child's address. It needs no funds.

Each run leaves its children, records and remaining test ETH behind; there is
no child deletion API.

Assertions check on-chain senders and receipts, signature recovery, backend
policy results and account history, rejection without advancing the child's
nonce, root independence, and unchanged child ID, path and key. No SDK join
callback or Guardian is mocked, and no additional Robo test dependencies are
needed. A local backend must have its migrations applied (`npm run migrate` in
`kagami-node`).

A pass against a locally linked SDK verifies that combination only, not a
published mirror. Before deployment, publish the SDK and its mirror, update
Robo's pinned dependency and lockfile, rebuild it, and rerun this suite against
the matching backend.
