Skip to content

Conversation

@tim-hm
Copy link
Collaborator

@tim-hm tim-hm commented Nov 14, 2025

No description provided.

Changes:
- Add time constants (ONE_MINUTE_MS, ONE_HOUR_MS, FOUR_WEEKS_MS, DEFAULT_MAX_LIFETIME_MS)
- Add `expiresIn()` method to builder for ergonomic expiration setting
- Add `maxLifetime()` method to customize maximum token lifetime
- Add validation in `sign()` to require expiration and enforce lifetime caps
- Fix time unit bug: convert milliseconds to seconds in payload (exp, nbf)
- Cap chained token lifetimes by parent's remaining validity
- Update NilauthClient to set expiration on internal tokens
- Update documentation and all tests to use new expiration API

Security improvements:
- Prevents tokens from being created without expiration dates
- Enforces maximum lifetime of 4 weeks by default
- Child tokens cannot outlive their parents
- Provides clear error messages when lifetime constraints are violated

BREAKING CHANGE: All tokens must now specify an expiration via `expiresAt()` or `expiresIn()`. Tokens without expiration will be rejected during the build process.
@github-actions
Copy link

github-actions bot commented Nov 14, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 80.83% 713 / 882
🔵 Statements 80.87% 723 / 894
🔵 Functions 86.2% 175 / 203
🔵 Branches 72.75% 283 / 389
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/constants.ts 100% 100% 100% 100%
src/core/signer.ts 88% 84.37% 93.33% 88% 53-54, 122-125, 134-137
src/core/did/ethr.ts 85.71% 80% 83.33% 85.71% 38, 55
src/nuc/builder.ts 89.36% 78.84% 92% 89.36% 138-157, 378, 463, 583-585, 597, 633-635, 647
src/nuc/codec.ts 96.42% 90% 100% 96.42% 113-120
src/nuc/header.ts 100% 100% 100% 100%
src/services/nilauth/client.ts 74.02% 54.54% 85.71% 74.02% 59-85, 176-198, 324, 365
src/services/nilauth/types.ts 100% 100% 100% 100%
src/services/payer/grpc-compat.ts 93.33% 55.55% 66.66% 93.33% 50
src/services/payer/gen/tx_pb.ts 100% 100% 100% 100%
src/validator/signatures.ts 90.32% 72.72% 100% 93.33% 69, 93, 108
src/validator/validator.ts 81.25% 65.71% 100% 81.01% 184-185, 202-203, 237-251, 277-281, 305-306
tests/helpers/assertions.ts 55% 50% 60% 55% 26-29, 48-51, 68-77
tests/helpers/signers.ts 100% 50% 100% 100%
tests/integration/nuc-rs-compat.ts 100% 100% 100% 100%
Generated in workflow #325 for commit 7b485ce by the Vitest Coverage Report Action

Changes:
- Add `Validator.parse()` that decodes and validates tokens in a single operation
- Rename `Codec.decodeBase64Url` to `Codec._unsafeDecodeBase64Url` and log warning on invocation
- Update all internal code to use `_unsafeDecodeBase64Url` where only structure inspection is needed
- Update documentation and examples
- Update tests to use appropriate methods based on context

BREAKING CHANGE: `Codec.decodeBase64Url` has been renamed to `Codec._unsafeDecodeBase64Url` and is now marked as internal. The new `Validator.parse()` method should be used instead for all token parsing and validation.
@tim-hm tim-hm force-pushed the feat/require-expiry branch from 2be4086 to 2799d0a Compare November 14, 2025 14:57
Consolidate Web3 dependencies to viem:
- Remove ethers dependency entirely in favor of viem for all Ethereum operations
- Update signature validation in did:ethr to use viem's hashMessage and recoverAddress
- Update EIP-712 signing to use viem's SignTypedDataParameters and hashTypedData
- Migrate all tests from ethers.Wallet to viem's privateKeyToAccount
- Update helper functions to work with viem's PrivateKeyAccount type

Align tests with public API:
- Refactor tests to use Validator.parse instead of internal validateNucSignature
- Make validation functions async to support viem's async signature recovery
- Update Validator.parse and Validator.validate to return Promises
- Update test assertion helpers (assertSuccess, assertFailure) to be async
- Add assertValidParse helper function for cleaner test code

Decouple test environment from .env files:
- Remove dotenv dependency from test setup
- Define service URLs as constants derived from docker-compose.yml port mappings
- Set process.env values directly from constants for better clarity and maintainability
The bytesToHex function from `@noble/hashes/utils` returns hex strings without the 0x prefix, eg `aaaa...`, but viem's `recoverAddress` expects hex strings with the 0x prefix, eg, `0xaaaa...`.
Tsdown simplifies build processes with a zero-config bundling and better integration with modern tooling.

Changes:
- Replace `tsup` with `tsdown`
- Remove @arethetypeswrong/cli (attw) - no longer needed
- Remove attw validation step from CI workflow
@tim-hm tim-hm force-pushed the feat/require-expiry branch from 2799d0a to 0e06b51 Compare November 14, 2025 15:02
@tim-hm tim-hm force-pushed the feat/require-expiry branch from 0e06b51 to 7b485ce Compare November 14, 2025 15:05
@tim-hm tim-hm merged commit bae994b into main Nov 14, 2025
4 checks passed
@tim-hm tim-hm deleted the feat/require-expiry branch November 14, 2025 15:09
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.

2 participants