-
Notifications
You must be signed in to change notification settings - Fork 13
Validate unsigned -> pallet::authorize #194
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
Open
antkve
wants to merge
30
commits into
main
Choose a base branch
from
ak-validate-unsigned
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
8e3e520
Removed deprecated ValidateUnsigned
antkve aa5574a
Fixed name
antkve 0c7c14b
Removed auth contexts and simplified
antkve 1c022bd
Fixed preimage test to reflect consume-at-dispatch
antkve 8f2e817
Format
antkve ca6dd6e
Clippy fix
antkve 42d021f
Added preimage test
antkve e1cd9f5
Moved preimage test to subxt
antkve 5de03b6
Fixed merge
antkve a785122
Fixed merge again
antkve 6ac2154
Format
antkve 27d797d
Fixed duplicate just
antkve a6549f4
Fix test + verify preimage data
antkve 6e5751d
Fix compilation
antkve c5edd6f
Format yet again
antkve d889e16
Test fix
antkve 8272287
Fixed compilation
antkve 15c767d
fix: feeless_if
franciscoaguirre df3382f
Merge branch 'main' into ak-validate-unsigned
franciscoaguirre a328ebd
Fixed integration test
antkve 18970e2
Benchmark fix?
antkve 7a3348d
Use GitHub Actions matrix for integration tests (#238)
x3c41a 45f7951
Format
antkve 1de7bb1
Merge branch 'main' into ak-validate-unsigned-2
antkve 304758d
Merge branch 'main' into ak-validate-unsigned
antkve 12644e5
Cleaned up and removed providecidconfig from tests
antkve a92f6e1
General tx with papi
antkve 655bc31
Fixed test
antkve 36e437c
Merge branch 'main' into ak-validate-unsigned
bkontur 723db18
Updated general TX script to recommended generalSigner syntax
antkve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** | ||
| * General transaction signer for #[pallet::authorize] calls. | ||
| * | ||
| * With #[pallet::authorize] replacing ValidateUnsigned, unsigned transactions must be | ||
| * submitted as "general" extrinsics (Preamble::General) rather than "bare" extrinsics | ||
| * (Preamble::Bare). General extrinsics include the transaction extension pipeline but | ||
| * no signature, allowing AuthorizeCall to process the call's authorization logic. | ||
| * | ||
| * This uses a custom PolkadotSigner that constructs v5 general transactions using the | ||
| * runtime metadata to properly encode extension data, rather than hardcoding defaults. | ||
| * | ||
| * See: https://github.com/polkadot-api/polkadot-api/issues/760 | ||
| */ | ||
|
|
||
| import { | ||
| compact, | ||
| decAnyMetadata, | ||
| extrinsicFormat, | ||
| unifyMetadata, | ||
| } from "@polkadot-api/substrate-bindings" | ||
| import { mergeUint8 } from "polkadot-api/utils" | ||
|
|
||
| const EXTENSION_VERSION = 0; | ||
|
|
||
| /** | ||
| * Create a PolkadotSigner that produces v5 general transactions (unsigned with extensions). | ||
| * | ||
| * Usage: | ||
| * const signer = createGeneralSigner(); | ||
| * await tx.signSubmitAndWatch(signer).subscribe(...); | ||
| * | ||
| * @returns {import("polkadot-api").PolkadotSigner} | ||
| */ | ||
| export function createGeneralSigner() { | ||
| return { | ||
| publicKey: new Uint8Array(32), | ||
| signBytes() { | ||
| throw new Error("Unsupported: generalSigner does not support signBytes") | ||
| }, | ||
| async signTx(callData, signedExtensions, metadata) { | ||
| const decMeta = unifyMetadata(decAnyMetadata(metadata)) | ||
|
|
||
| const extra = decMeta.extrinsic.signedExtensions[EXTENSION_VERSION].map( | ||
| ({ identifier }) => { | ||
| const signedExtension = signedExtensions[identifier] | ||
| if (!signedExtension) | ||
| throw new Error(`Missing ${identifier} signed extension`) | ||
| return signedExtension.value | ||
| }, | ||
| ) | ||
|
|
||
| const preResult = mergeUint8([ | ||
| extrinsicFormat.enc({ | ||
| version: 5, | ||
| type: "general", | ||
| }), | ||
| new Uint8Array([EXTENSION_VERSION]), | ||
| ...extra, | ||
| callData, | ||
| ]) | ||
|
|
||
| return mergeUint8([compact.enc(preResult.length), preResult]) | ||
| }, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@antkve very good job, here, I am trying to push this for PAPI: polkadot-api/polkadot-api#760 (comment)