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

Allow external signers to modify the payload #6030

Merged
merged 5 commits into from
Nov 19, 2024
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
6 changes: 5 additions & 1 deletion packages/api/src/submittable/createClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas

#signViaSigner = async (address: Address | string | Uint8Array, options: SignatureOptions, header: Header | null): Promise<SignerInfo> => {
const signer = options.signer || api.signer;
const allowCallDataAlteration = options.allowCallDataAlteration ?? true;

if (!signer) {
throw new Error('No signer specified, either via api.setSigner or via sign options. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.');
Expand Down Expand Up @@ -367,7 +368,10 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
throw new Error(`When using the signedTransaction field, the transaction must be signed. Recieved isSigned: ${ext.isSigned}`);
}

this.#validateSignedTransaction(payload, ext);
if (!allowCallDataAlteration) {
this.#validateSignedTransaction(payload, ext);
}

// This is only used for signAsync - signAndSend does not need to adjust the super payload or
// add the signature.
super.addSignature(address, result.signature, newSignerPayload.toPayload());
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/types/extrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export interface IExtrinsicEra extends Codec {
}

export interface SignatureOptions {
allowCallDataAlteration?: boolean;
blockHash: Uint8Array | string;
era?: IExtrinsicEra;
genesisHash: Uint8Array | string;
Expand Down