Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(helpers): add validateP2PKHMessage function #427

Merged
merged 7 commits into from
Sep 30, 2022

Conversation

IronLu233
Copy link
Contributor

@IronLu233 IronLu233 commented Sep 25, 2022

Description

Fixes #397
provide a validateP2PKHMessage method to check diget == hash(tx | witness), this helps the user to verify that a transaction is tampered.

Usage

const rawTx = /* some create transaction operation */;
const tx = prepareSigningEntries(rawTx);
const txMessageDigest = prepareSigningEntries.signingEntries.get(0).message;
// ------- this process may modify transaction message digest
// return the validate result
validateP2PKHMessage(txMessageDigest, tx,  hashContentExceptRawTx);

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactor (non-breaking change)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation or Website
  • Example
  • Other

How Has This Been Tested?

  • Test simple validation
  • Test multiple lock args
  • Test extra custom witnesses
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@vercel
Copy link

vercel bot commented Sep 25, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
lumos-website ✅ Ready (Inspect) Visit Preview Sep 30, 2022 at 7:47AM (UTC)

@codecov
Copy link

codecov bot commented Sep 25, 2022

Codecov Report

Merging #427 (a3a71ee) into develop (009577a) will increase coverage by 0.11%.
The diff coverage is 97.18%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #427      +/-   ##
===========================================
+ Coverage    82.28%   82.39%   +0.11%     
===========================================
  Files           95       97       +2     
  Lines        19701    19831     +130     
  Branches      1863     1867       +4     
===========================================
+ Hits         16210    16340     +130     
+ Misses        3437     3436       -1     
- Partials        54       55       +1     
Impacted Files Coverage Δ
packages/helpers/src/validate.ts 96.00% <96.00%> (ø)
packages/base/src/utils.js 68.61% <100.00%> (+0.94%) ⬆️
packages/common-scripts/src/helper.ts 83.33% <100.00%> (+0.52%) ⬆️
packages/codec/src/bytes.ts 97.08% <0.00%> (ø)
packages/lumos/src/index.ts 100.00% <0.00%> (ø)
packages/rpc/src/method.ts 97.59% <0.00%> (+0.29%) ⬆️
packages/rpc/src/index.ts 72.67% <0.00%> (+0.55%) ⬆️
packages/helpers/src/index.ts 88.84% <0.00%> (+0.64%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 009577a...a3a71ee. Read the comment docs.

packages/helpers/src/validate.ts Outdated Show resolved Hide resolved
packages/helpers/src/validate.ts Outdated Show resolved Hide resolved
packages/helpers/src/validate.ts Outdated Show resolved Hide resolved
@IronLu233 IronLu233 changed the title feat(base): add validate transaction function feat(base): add validateP2PKHMessage function Sep 27, 2022
@homura
Copy link
Collaborator

homura commented Sep 27, 2022

This PR is a fix for #397, can you please describe clearly the purpose of this PR?

Copy link
Contributor

@PainterPuppets PainterPuppets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the first parameter is optional, then if a parameter is added later it will become breakchange

/**
* @param outLength the length of the output hash in bytes. default is `32`
*/
constructor(outLength?: number);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interface CKBHasherOptions {
    outLength?: number;
}
constructor(options?: CKBHasherOptions);

packages/base/src/utils.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@homura homura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@homura homura changed the title feat(base): add validateP2PKHMessage function feat(helpers): add validateP2PKHMessage function Sep 30, 2022
@homura homura merged commit 73fc3a1 into ckb-js:develop Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[idea] Transaction validator for P2PKH signing message
4 participants