Skip to content

refactor: comply with tx3 sdk spec#25

Merged
scarmuega merged 5 commits into
mainfrom
spec-refactor
Apr 16, 2026
Merged

refactor: comply with tx3 sdk spec#25
scarmuega merged 5 commits into
mainfrom
spec-refactor

Conversation

@scarmuega
Copy link
Copy Markdown
Contributor

No description provided.

scarmuega and others added 5 commits April 15, 2026 21:28
Clean-slate rewrite of tx3-sdk toward full parity with docs/sdk-spec.md.
This checkpoint contains the scaffold, tooling swap, and the complete
core/ module; phases 3-11 (trp, tii, signer, facade, tests, docs) land
in follow-up commits.

Phase 0 — crypto library decision
- Locked @stricahq/bip32ed25519 v1.1.2 for CardanoSigner after
  confirming cardano-crypto.js is Emscripten→WASM. @StricaHQ is pure
  JS, Apache-2.0, used by Typhon Wallet, implements the same
  ed25519-bip32 V2 derivation as the Rust SDK.

Phase 1 — scaffold & tooling
- package.json bumped 0.7.0 → 1.0.0
- New deps: @noble/curves, @noble/hashes, @scure/bip39,
  @stricahq/bip32ed25519 (kept bech32). New devDeps: tsup, undici.
- Four-entry exports map: `.`, `./trp`, `./tii`, `./signer`.
- Replaced hand-rolled rollup.config.mjs with tsup.config.ts
  (multi-entry ESM+CJS+dts, preserveModules off, target es2022).
- jest.config.js refreshed, dropped orphaned tests/setup.ts ref.
- Workspace lockfile regenerated (77 new packages).
- Deleted old src/index.ts, src/trp/{args,client,index,types}.ts,
  tests/{args,client,setup}.ts, rollup.config.mjs.

Phase 2 — core/ module
- core/errors.ts: Tx3Error abstract root + ArgValueError.
  (ArgValueError flattened one level above the plan's
  ResolutionError parent to keep core/ from cycling into facade/.)
- core/bytes.ts: BytesEnvelope with canonical `contentType` field
  matching rust-sdk/sdk/src/core.rs; hex/base64 helpers.
- core/args.ts: ArgValue discriminated union + toJson/fromJson with
  bidirectional UtxoSet support (fixes the asymmetry in 0.7.0),
  i128 range check, bech32 address decoding. The stray console.log
  from the old args.ts is gone by construction.
- core/index.ts: export * re-exports.
- `npx tsc --noEmit` passes clean.

Progress + resume protocol documented in the "Progress & resume"
section at the top of ~/.claude/plans/enchanted-stirring-sun.md.
The next Claude session starts Phase 3 (trp/ module) — see the plan
file for the authoritative next-step breakdown and sanity checks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Phase 3 of 11. Writes src/trp/{spec,errors,client,index}.ts against
the rewrite plan and adds TirEnvelope/TirEncoding/ArgMap/EnvMap to
src/core/tir.ts (prerequisite for the TRP wire types).

- spec.ts mirrors rust-sdk/sdk/src/trp/spec.rs 1:1 on wire field
  names. TxStage is a snake_case string union; WitnessType is 'vkey';
  TxWitness uses `type` (not `witnessType`) to match the wire.
- errors.ts introduces TrpError as an abstract Tx3Error subclass plus
  the 13 concrete subclasses from the plan. Diagnostic-carrying ones
  hold the structured payload, not just a message.
- client.ts renames Client → TrpClient, drops the 0.7.0 `envArgs`
  ClientOptions field, and returns SubmitResponse (was void). JSON-RPC
  error mapping: -32000..-32003 → typed subclasses; fetch TypeError
  → NetworkError; non-2xx → HttpError; JSON parse failure →
  DeserializationError; missing `result` → MalformedResponseError.
- tsc --noEmit clean.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Port rust-sdk/sdk/src/tii/{mod,spec}.rs line-for-line:
- Protocol.fromJson/fromString/fromFile with Node-only fromFile via
  dynamic node:fs/promises import.
- Invocation with setArg/withArg/setArgs/withArgs (lowercase keys),
  params()/unspecifiedParams()/intoResolveRequest().
- ParamType discriminated union + fromJsonSchema (\$ref Bytes/Address/
  UtxoRef, type:integer/boolean; other cases throw InvalidParamTypeError
  to match Rust's strict behavior).
- paramsFromSchema walks properties and recurses.
- TiiError subclass tree: InvalidJsonError, UnknownTxError,
  UnknownProfileError, InvalidParamsSchemaError, InvalidParamTypeError.
- intoResolveRequest omits env (flattened into args at profile-merge
  time, matching the Rust comment at tii/mod.rs:563-566).

Type-checks clean via \`tsc --noEmit\`. Tests land in Phase 5.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…1.0.0

Complete the web-sdk rewrite (Phases 5-9): add Signer interface with
Ed25519Signer (@noble/curves) and CardanoSigner (@stricahq/bip32ed25519),
full facade module (Tx3Client, TxBuilder, ResolvedTx, SignedTx, SubmittedTx,
PollConfig, Party), discriminated error hierarchy, and §4 re-exports.

92 tests across 5 suites (core/args, tii/protocol, trp/client, signer/ed25519,
facade/integration). Type-check clean, tsup build passes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@scarmuega scarmuega merged commit b5f02f7 into main Apr 16, 2026
1 check passed
@scarmuega scarmuega deleted the spec-refactor branch April 16, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant