abitype icon indicating copy to clipboard operation
abitype copied to clipboard

feat(human-readable): parse EIP712 human-readable type signatures

Open Raiden1411 opened this issue 1 year ago β€’ 6 comments

Description

This PR adds support for EIP712 typed data signatures.

Essentially the typed data human readable signature is represented as a struct signature. This however differs from Abi structs, since this will follow the specifications introduced in EIP712.

The new parseTypedData function parses in two contexts. Either if you want to create and resolve the typed data or simply want to create it (the latter is the default behavior).

This also introduces a couple of new types for consumers to use. ParseTypedData, ResolveTypedData, ResolvedTypedData and ResolvedTypedDataToPrimativeTypes.

Examples were created to demonstrate this new pattern and the documentation also reflects these changes.

Additional Information

  • [x] I read the contributing guide
  • [x] I added documentation related to the changes made.
  • [x] I added or updated tests related to the changes made.

Your ENS/address:


PR-Codex overview

This PR adds human-readable EIP-712 parsing utilities and resolves typed data into corresponding Solidity primitive types.

Detailed summary

  • Added parseTypedData function to parse human-readable typed data into EIP-712 typed data.
  • Added MissingNamedParameter error class for missing named parameters in EIP-712 typed data.
  • Updated typings and dependencies.

The following files were skipped due to too many changes: src/utils.ts, src/human-readable/parseTypedData.ts, src/human-readable/runtime/structs.ts, src/human-readable/parseTypedData.test.ts, examples/signTypedData.test-d.ts

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Raiden1411 avatar Jul 12 '23 14:07 Raiden1411

πŸ¦‹ Changeset detected

Latest commit: e917c51786901b40463c80f11ea640ebb7e34ccc

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Jul 12 '23 14:07 changeset-bot[bot]

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
abitype βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Oct 8, 2023 8:56am

vercel[bot] avatar Jul 12 '23 14:07 vercel[bot]

Features

  • parse human readable EIP-712 typed data (021bff1)

Chore

Documentation

  • add parseTypedData to docs. (cc59705)

Bug Fixes

Contributors

Raiden1411

Commit-Lint commands

You can trigger Commit-Lint actions by commenting on this PR:

  • @Commit-Lint merge patch will merge dependabot PR on "patch" versions (X.X.Y - Y change)
  • @Commit-Lint merge minor will merge dependabot PR on "minor" versions (X.Y.Y - Y change)
  • @Commit-Lint merge major will merge dependabot PR on "major" versions (Y.Y.Y - Y change)
  • @Commit-Lint merge disable will desactivate merge dependabot PR
  • @Commit-Lint review will approve dependabot PR
  • @Commit-Lint stop review will stop approve dependabot PR

commit-lint[bot] avatar Jul 12 '23 14:07 commit-lint[bot]

Size Change: +1.5 kB (+3%)

Total Size: 49.9 kB

Filename Size Change
dist/cjs/human-readable/errors/struct.js 423 B +85 B (+25%) 🚨
dist/cjs/human-readable/runtime/structs.js 1.35 kB +319 B (+31%) 🚨
dist/cjs/index.js 792 B +49 B (+7%) πŸ”
dist/esm/human-readable/errors/struct.js 355 B +73 B (+26%) 🚨
dist/esm/human-readable/runtime/structs.js 1.25 kB +298 B (+31%) 🚨
dist/esm/index.js 369 B +24 B (+7%) πŸ”
dist/cjs/human-readable/parseTypedData.js 357 B +357 B (new file) πŸ†•
dist/esm/human-readable/parseTypedData.js 296 B +296 B (new file) πŸ†•
ℹ️ View Unchanged
Filename Size
dist/cjs/abi.js 123 B
dist/cjs/config.js 126 B
dist/cjs/errors.js 577 B
dist/cjs/human-readable/errors/abiItem.js 537 B
dist/cjs/human-readable/errors/abiParameter.js 804 B
dist/cjs/human-readable/errors/signature.js 420 B
dist/cjs/human-readable/errors/splitParameters.js 404 B
dist/cjs/human-readable/formatAbi.js 294 B
dist/cjs/human-readable/formatAbiItem.js 420 B
dist/cjs/human-readable/formatAbiParameter.js 487 B
dist/cjs/human-readable/formatAbiParameters.js 313 B
dist/cjs/human-readable/parseAbi.js 348 B
dist/cjs/human-readable/parseAbiItem.js 439 B
dist/cjs/human-readable/parseAbiParameter.js 470 B
dist/cjs/human-readable/parseAbiParameters.js 527 B
dist/cjs/human-readable/runtime/cache.js 616 B
dist/cjs/human-readable/runtime/signatures.js 782 B
dist/cjs/human-readable/runtime/utils.js 2.13 kB
dist/cjs/human-readable/types/signatures-test-d.js 440 B
dist/cjs/human-readable/types/signatures.js 127 B
dist/cjs/human-readable/types/structs.js 127 B
dist/cjs/human-readable/types/utils.js 124 B
dist/cjs/narrow.js 169 B
dist/cjs/regex.js 362 B
dist/cjs/test.js 597 B
dist/cjs/test/abis.js 5.93 kB
dist/cjs/test/human-readable.js 3.6 kB
dist/cjs/types.js 124 B
dist/cjs/utils.js 124 B
dist/cjs/version.js 148 B
dist/cjs/zod.js 2.08 kB
dist/esm/abi.js 62 B
dist/esm/config.js 65 B
dist/esm/errors.js 524 B
dist/esm/human-readable/errors/abiItem.js 454 B
dist/esm/human-readable/errors/abiParameter.js 674 B
dist/esm/human-readable/errors/signature.js 339 B
dist/esm/human-readable/errors/splitParameters.js 345 B
dist/esm/human-readable/formatAbi.js 214 B
dist/esm/human-readable/formatAbiItem.js 339 B
dist/esm/human-readable/formatAbiParameter.js 405 B
dist/esm/human-readable/formatAbiParameters.js 230 B
dist/esm/human-readable/parseAbi.js 267 B
dist/esm/human-readable/parseAbiItem.js 353 B
dist/esm/human-readable/parseAbiParameter.js 383 B
dist/esm/human-readable/parseAbiParameters.js 436 B
dist/esm/human-readable/runtime/cache.js 554 B
dist/esm/human-readable/runtime/signatures.js 572 B
dist/esm/human-readable/runtime/utils.js 2.04 kB
dist/esm/human-readable/types/signatures-test-d.js 367 B
dist/esm/human-readable/types/signatures.js 69 B
dist/esm/human-readable/types/structs.js 66 B
dist/esm/human-readable/types/utils.js 64 B
dist/esm/narrow.js 97 B
dist/esm/regex.js 284 B
dist/esm/test.js 298 B
dist/esm/test/abis.js 5.8 kB
dist/esm/test/human-readable.js 3.49 kB
dist/esm/types.js 64 B
dist/esm/utils.js 64 B
dist/esm/version.js 82 B
dist/esm/zod.js 1.91 kB

compressed-size-action

github-actions[bot] avatar Jul 12 '23 14:07 github-actions[bot]

Codecov Report

All modified lines are covered by tests :white_check_mark:

Comparison is base (529da5c) 99.90% compared to head (e917c51) 99.91%.

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #166    +/-   ##
========================================
  Coverage   99.90%   99.91%            
========================================
  Files          21       22     +1     
  Lines        2055     2281   +226     
  Branches      325      362    +37     
========================================
+ Hits         2053     2279   +226     
  Misses          2        2            
Files Coverage Ξ”
src/human-readable/errors/struct.ts 100.00% <100.00%> (ΓΈ)
src/human-readable/parseTypedData.ts 100.00% <100.00%> (ΓΈ)
src/human-readable/runtime/structs.ts 100.00% <100.00%> (ΓΈ)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jul 12 '23 14:07 codecov[bot]

@tmm with the restructure do you want me to re-open this PR or do you think that this doesn't make sense in having for abitype?

Raiden1411 avatar Oct 11 '23 17:10 Raiden1411

@Raiden1411 this PR is great work and maybe we'll add it in someday (EIP-712 isn't a burning use-case it seems right now). Going to close out for the time-being.

tmm avatar Aug 06 '24 15:08 tmm