Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# eth_url_parser

## Agent skills

### Issue tracker

Issues are tracked in this repo's GitHub Issues (`LiorAgnin/eth_url_parser`) via the `gh` CLI. See `docs/agents/issue-tracker.md`.

### Triage labels

The five canonical triage labels are used as-is (`needs-triage`, `needs-info`, `ready-for-agent`, `ready-for-human`, `wontfix`). See `docs/agents/triage-labels.md`.

### Domain docs

Single-context: one `CONTEXT.md` + `docs/adr/` at the repo root, created lazily. See `docs/agents/domain.md`.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
## 0.2.0

Strict [EIP-681](https://eips.ethereum.org/EIPS/eip-681) compliance. Fixes
silent precision loss on the money path.

- **Fixed**: amounts are now parsed and formatted with `BigInt` — values above
int64 (~9.22 ETH in wei) no longer lose wei silently through `num.parse`
- **Fixed**: `build` no longer corrupts amounts via lossy
`toStringAsExponential` — trailing zeros compress into an exact exponent
(`2014000000000000000` → `2.014e18`), anything else stays plain decimal
- **Fixed**: addresses are validated as exactly 40 hex digits; non-hex
40-character strings are rejected, and a `0x` payload never falls back to
ENS (hex takes precedence per the spec)
- **Added**: bare ENS targets (`ethereum:vitalik.eth`,
`ethereum:doge-to-the-moon.eth`) parse per the spec grammar
- **Added**: the scientific-notation number grammar is enforced exactly —
the exponent must be ≥ the number of decimals (`1.5e0` is rejected)
- **Breaking**: only the spec-defined `pay-` prefix is accepted; arbitrary
ERC-831 prefixes (`foo-`) now throw
- **Breaking**: all malformed input throws `FormatException` with a
descriptive message (previously a mix of bare `Exception` and raw
`RangeError` on short input)
- **Breaking**: `QueryString.parse` uses strict RFC 3986 percent-decoding;
`+` is a literal plus (the number grammar's sign), not a space
- Validated `chainId` as decimal digits and the `transfer` `address`
parameter as a valid address or ENS name
- **Breaking**: `EthUrlParser` and `QueryString` can no longer be
instantiated — both are static-only utility classes
- 100% dartdoc coverage of the public API, enforced by the
`public_member_api_docs` lint and strict analyzer language checks

## 0.1.0

- **Breaking**: Removed `freezed` and `json_serializable` code generation dependencies
Expand Down
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# eth_url_parser

A Dart library for parsing and building Ethereum URLs according to [ERC-681](https://eips.ethereum.org/EIPS/eip-681) and [ERC-831](https://eips.ethereum.org/EIPS/eip-831).
A Dart library for parsing and building Ethereum URLs according to [ERC-681](https://eips.ethereum.org/EIPS/eip-681).

Translated from the JavaScript [eth-url-parser](https://www.npmjs.com/package/eth-url-parser) package.
Originally translated from the JavaScript [eth-url-parser](https://www.npmjs.com/package/eth-url-parser) package.

## Features

- Strict EIP-681 grammar: only the spec-defined `pay-` prefix, addresses of
exactly 40 hex digits, bare ENS targets (`ethereum:vitalik.eth`)
- Exact amount handling via `BigInt` — no precision loss at any magnitude,
in either direction (parse or build)
- Parse Ethereum URIs into strongly-typed `TransactionRequest` objects
- Build valid Ethereum URIs from `TransactionRequest` objects
- Supports ERC-681 parameters: `value`, `gas`, `gasLimit`, `gasPrice`
- Supports ERC-20 `transfer` function calls
- ENS name resolution support
- Chain ID support
- All malformed input throws `FormatException` with a descriptive message
- No code generation required -- pure Dart

## Installation
Expand All @@ -20,7 +24,7 @@ Add to your `pubspec.yaml`:

```yaml
dependencies:
eth_url_parser: ^0.1.0
eth_url_parser: ^0.2.0
```

## Usage
Expand Down Expand Up @@ -48,13 +52,13 @@ final uri = EthUrlParser.build(
targetAddress: '0x1234DEADBEEF5678ABCD1234DEADBEEF5678ABCD',
functionName: 'transfer',
parameters: {
'address': '0x12345',
'address': '0x8e23ee67d1332ad560396262c48ffbb01f93d052',
'uint256': '1',
},
),
);
print(uri);
// ethereum:0x1234DEADBEEF5678ABCD1234DEADBEEF5678ABCD/transfer?address=0x12345&uint256=1
// ethereum:0x1234DEADBEEF5678ABCD1234DEADBEEF5678ABCD/transfer?address=0x8e23ee67d1332ad560396262c48ffbb01f93d052&uint256=1
```

### The `TransactionRequest` model
Expand All @@ -64,7 +68,7 @@ TransactionRequest(
scheme: 'ethereum', // default
targetAddress: '0x...', // required
functionName: 'transfer', // optional
prefix: 'pay', // optional (ERC-831)
prefix: 'pay', // optional ('pay' is the only EIP-681 prefix)
chainId: 1, // optional
parameters: { // optional
'value': '1000000000000000000',
Expand All @@ -78,8 +82,12 @@ TransactionRequest(
### `EthUrlParser.parse(String uri)`

Parses an Ethereum URI string and returns a `TransactionRequest`.
Throws an `Exception` for invalid URIs.
Throws a `FormatException` for invalid URIs.

### `EthUrlParser.build(TransactionRequest request)`

Builds an Ethereum URI string from a `TransactionRequest` object.
Amounts with at least three trailing zeros are emitted in the exponent
notation the EIP suggests (`2.014e18`); all others stay plain decimal, so
round-trips never lose a wei. Throws a `FormatException` for an invalid
prefix, target address, or amount.
12 changes: 8 additions & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.
analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true

# linter:
# rules:
# - camel_case_types
linter:
rules:
- public_member_api_docs

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
Expand Down
51 changes: 51 additions & 0 deletions docs/agents/domain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Domain Docs

How the engineering skills should consume this repo's domain documentation when exploring the codebase.

## Before exploring, read these

- **`CONTEXT.md`** at the repo root, or
- **`CONTEXT-MAP.md`** at the repo root if it exists — it points at one `CONTEXT.md` per context. Read each one relevant to the topic.
- **`docs/adr/`** — read ADRs that touch the area you're about to work in. In multi-context repos, also check `src/<context>/docs/adr/` for context-scoped decisions.

If any of these files don't exist, **proceed silently**. Don't flag their absence; don't suggest creating them upfront. The `/domain-modeling` skill (reached via `/grill-with-docs` and `/improve-codebase-architecture`) creates them lazily when terms or decisions actually get resolved.

## File structure

Single-context repo (most repos):

```
/
├── CONTEXT.md
├── docs/adr/
│ ├── 0001-event-sourced-orders.md
│ └── 0002-postgres-for-write-model.md
└── src/
```

Multi-context repo (presence of `CONTEXT-MAP.md` at the root):

```
/
├── CONTEXT-MAP.md
├── docs/adr/ ← system-wide decisions
└── src/
├── ordering/
│ ├── CONTEXT.md
│ └── docs/adr/ ← context-specific decisions
└── billing/
├── CONTEXT.md
└── docs/adr/
```

## Use the glossary's vocabulary

When your output names a domain concept (in an issue title, a refactor proposal, a hypothesis, a test name), use the term as defined in `CONTEXT.md`. Don't drift to synonyms the glossary explicitly avoids.

If the concept you need isn't in the glossary yet, that's a signal — either you're inventing language the project doesn't use (reconsider) or there's a real gap (note it for `/domain-modeling`).

## Flag ADR conflicts

If your output contradicts an existing ADR, surface it explicitly rather than silently overriding:

> _Contradicts ADR-0007 (event-sourced orders) — but worth reopening because…_
45 changes: 45 additions & 0 deletions docs/agents/issue-tracker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Issue tracker: GitHub

Issues and specs for this repo live as GitHub issues. Use the `gh` CLI for all operations.

## Conventions

- **Create an issue**: `gh issue create --title "..." --body "..."`. Use a heredoc for multi-line bodies.
- **Read an issue**: `gh issue view <number> --comments`, filtering comments by `jq` and also fetching labels.
- **List issues**: `gh issue list --state open --json number,title,body,labels,comments --jq '[.[] | {number, title, body, labels: [.labels[].name], comments: [.comments[].body]}]'` with appropriate `--label` and `--state` filters.
- **Comment on an issue**: `gh issue comment <number> --body "..."`
- **Apply / remove labels**: `gh issue edit <number> --add-label "..."` / `--remove-label "..."`
- **Close**: `gh issue close <number> --comment "..."`

Infer the repo from `git remote -v` — `gh` does this automatically when run inside a clone.

## Pull requests as a triage surface

**PRs as a request surface: no.** _(Set to `yes` if this repo treats external PRs as feature requests; `/triage` reads this flag.)_

When set to `yes`, PRs run through the same labels and states as issues, using the `gh pr` equivalents:

- **Read a PR**: `gh pr view <number> --comments` and `gh pr diff <number>` for the diff.
- **List external PRs for triage**: `gh pr list --state open --json number,title,body,labels,author,authorAssociation,comments` then keep only `authorAssociation` of `CONTRIBUTOR`, `FIRST_TIME_CONTRIBUTOR`, or `NONE` (drop `OWNER`/`MEMBER`/`COLLABORATOR`).
- **Comment / label / close**: `gh pr comment`, `gh pr edit --add-label`/`--remove-label`, `gh pr close`.

GitHub shares one number space across issues and PRs, so a bare `#42` may be either — resolve with `gh pr view 42` and fall back to `gh issue view 42`.

## When a skill says "publish to the issue tracker"

Create a GitHub issue.

## When a skill says "fetch the relevant ticket"

Run `gh issue view <number> --comments`.

## Wayfinding operations

Used by `/wayfinder`. The **map** is a single issue with **child** issues as tickets.

- **Map**: a single issue labelled `wayfinder:map`, holding the Notes / Decisions-so-far / Fog body. `gh issue create --label wayfinder:map`.
- **Child ticket**: an issue linked to the map as a GitHub sub-issue (`gh api` on the sub-issues endpoint). Where sub-issues aren't enabled, add the child to a task list in the map body and put `Part of #<map>` at the top of the child body. Labels: `wayfinder:<type>` (`research`/`prototype`/`grilling`/`task`). Once claimed, the ticket is assigned to the driving dev.
- **Blocking**: GitHub's **native issue dependencies** — the canonical, UI-visible representation. Add an edge with `gh api --method POST repos/<owner>/<repo>/issues/<child>/dependencies/blocked_by -F issue_id=<blocker-db-id>`, where `<blocker-db-id>` is the blocker's numeric **database id** (`gh api repos/<owner>/<repo>/issues/<n> --jq .id`, _not_ the `#number` or `node_id`). GitHub reports `issue_dependencies_summary.blocked_by` (open blockers only — the live gate). Where dependencies aren't available, fall back to a `Blocked by: #<n>, #<n>` line at the top of the child body. A ticket is unblocked when every blocker is closed.
- **Frontier query**: list the map's open children (`gh issue list --state open`, scoped to the map's sub-issues / task list), drop any with an open blocker (`issue_dependencies_summary.blocked_by > 0`, or an open issue in the `Blocked by` line) or an assignee; first in map order wins.
- **Claim**: `gh issue edit <n> --add-assignee @me` — the session's first write.
- **Resolve**: `gh issue comment <n> --body "<answer>"`, then `gh issue close <n>`, then append a context pointer (gist + link) to the map's Decisions-so-far.
15 changes: 15 additions & 0 deletions docs/agents/triage-labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Triage Labels

The skills speak in terms of five canonical triage roles. This file maps those roles to the actual label strings used in this repo's issue tracker.

| Label in mattpocock/skills | Label in our tracker | Meaning |
| -------------------------- | -------------------- | ---------------------------------------- |
| `needs-triage` | `needs-triage` | Maintainer needs to evaluate this issue |
| `needs-info` | `needs-info` | Waiting on reporter for more information |
| `ready-for-agent` | `ready-for-agent` | Fully specified, ready for an AFK agent |
| `ready-for-human` | `ready-for-human` | Requires human implementation |
| `wontfix` | `wontfix` | Will not be actioned |

When a skill mentions a role (e.g. "apply the AFK-ready triage label"), use the corresponding label string from this table.

Edit the right-hand column to match whatever vocabulary you actually use.
8 changes: 4 additions & 4 deletions example/eth_url_parser_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ void main() {

// Parse a URL with parameters
final transferRequest = EthUrlParser.parse(
'ethereum:0x1234DEADBEEF5678ABCD1234DEADBEEF5678ABCD/transfer?address=0xABCD&uint256=1',
'ethereum:0x1234DEADBEEF5678ABCD1234DEADBEEF5678ABCD/transfer?address=0x8e23ee67d1332ad560396262c48ffbb01f93d052&uint256=1',
);
print('Function: ${transferRequest.functionName}');
// Function: transfer
print('Parameters: ${transferRequest.parameters}');
// Parameters: {address: 0xABCD, uint256: 1}
// Parameters: {address: 0x8e23ee67d1332ad560396262c48ffbb01f93d052, uint256: 1}

// Build an Ethereum URL from a TransactionRequest
final uri = EthUrlParser.build(
Expand All @@ -24,11 +24,11 @@ void main() {
functionName: 'transfer',
chainId: 1,
parameters: {
'address': '0xABCD',
'address': '0x8e23ee67d1332ad560396262c48ffbb01f93d052',
'uint256': '1',
},
),
);
print('Built URI: $uri');
// Built URI: ethereum:0x1234DEADBEEF5678ABCD1234DEADBEEF5678ABCD@1/transfer?address=0xABCD&uint256=1
// Built URI: ethereum:0x1234DEADBEEF5678ABCD1234DEADBEEF5678ABCD@1/transfer?address=0x8e23ee67d1332ad560396262c48ffbb01f93d052&uint256=1
}
9 changes: 9 additions & 0 deletions lib/eth_url_parser.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/// A Dart library for parsing and building Ethereum URIs according to
/// [EIP-681](https://eips.ethereum.org/EIPS/eip-681).
///
/// Parse a payment URI into a strongly-typed [TransactionRequest] with
/// [EthUrlParser.parse], or build one back into a URI with
/// [EthUrlParser.build]. All amounts are handled exactly via [BigInt] —
/// no wei is ever lost to floating-point precision.
library;

export 'src/models/models.dart';
export 'src/eth_url_parser_base.dart';
Loading
Loading