Add asset id in signing (#4009)
* add assetId to SignerOptions * pull assetId into extrinsic signing * set assetId to optional AnyNumber throughout * add logging of extrinsic options * add assetId to _injectSignature & add getters * re-add import * longer doc comments
This commit is contained in:
@@ -45,6 +45,7 @@ export interface SignerOptions {
|
||||
nonce: AnyNumber | Codec;
|
||||
signer?: Signer;
|
||||
tip?: AnyNumber;
|
||||
assetId?: AnyNumber;
|
||||
}
|
||||
|
||||
export type AddressOrPair = IKeyringPair | string | AccountId | Address;
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
|
||||
import type { SignOptions } from '@polkadot/keyring/types';
|
||||
import type { ExtrinsicEra } from '../../interfaces/extrinsics';
|
||||
import type { Balance, Hash, Index } from '../../interfaces/runtime';
|
||||
import type { AssetId, Balance, Hash, Index } from '../../interfaces/runtime';
|
||||
import type { ExtrinsicPayloadValue, IKeyringPair, Registry } from '../../types';
|
||||
|
||||
import { Compact } from '../../codec/Compact';
|
||||
import { Enum } from '../../codec/Enum';
|
||||
import { Option } from '../../codec/Option';
|
||||
import { Struct } from '../../codec/Struct';
|
||||
import { Bytes } from '../../primitive/Bytes';
|
||||
import { u32 } from '../../primitive/U32';
|
||||
@@ -92,6 +93,14 @@ export class GenericExtrinsicPayloadV4 extends Struct {
|
||||
return this.get('transactionVersion') as u32;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description
|
||||
* The (optional) asset id for this signature for chains that support transaction fees in assets
|
||||
*/
|
||||
public get assetId (): Option<AssetId> {
|
||||
return this.get('assetId') as Option<AssetId>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Sign the payload with the keypair
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { EcdsaSignature, Ed25519Signature, ExtrinsicEra, ExtrinsicSignature, Sr25519Signature } from '../../interfaces/extrinsics';
|
||||
import type { Address, Balance, Call, Index } from '../../interfaces/runtime';
|
||||
import type { Address, AssetId, Balance, Call, Index } from '../../interfaces/runtime';
|
||||
import type { ExtrinsicPayloadValue, IExtrinsicSignature, IKeyringPair, Registry, SignatureOptions } from '../../types';
|
||||
import type { ExtrinsicSignatureOptions } from '../types';
|
||||
|
||||
@@ -10,6 +10,7 @@ import { assert, isU8a, stringify, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { Compact } from '../../codec/Compact';
|
||||
import { Enum } from '../../codec/Enum';
|
||||
import { Option } from '../../codec/Option';
|
||||
import { Struct } from '../../codec/Struct';
|
||||
import { EMPTY_U8A, IMMORTAL_ERA } from '../constants';
|
||||
import { GenericExtrinsicPayloadV4 } from './ExtrinsicPayload';
|
||||
@@ -114,12 +115,21 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
|
||||
return this.get('tip') as Compact<Balance>;
|
||||
}
|
||||
|
||||
protected _injectSignature (signer: Address, signature: ExtrinsicSignature, { era, nonce, tip }: GenericExtrinsicPayloadV4): IExtrinsicSignature {
|
||||
/**
|
||||
* @description
|
||||
* The (optional) asset id for this signature for chains that support transaction fees in assets
|
||||
*/
|
||||
public get assetId (): Option<AssetId> {
|
||||
return this.get('assetId') as Option<AssetId>;
|
||||
}
|
||||
|
||||
protected _injectSignature (signer: Address, signature: ExtrinsicSignature, { assetId, era, nonce, tip }: GenericExtrinsicPayloadV4): IExtrinsicSignature {
|
||||
this.set('era', era);
|
||||
this.set('nonce', nonce);
|
||||
this.set('signer', signer);
|
||||
this.set('signature', signature);
|
||||
this.set('tip', tip);
|
||||
this.set('assetId', assetId);
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -138,8 +148,9 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
|
||||
/**
|
||||
* @description Creates a payload from the supplied options
|
||||
*/
|
||||
public createPayload (method: Call, { blockHash, era, genesisHash, nonce, runtimeVersion: { specVersion, transactionVersion }, tip }: SignatureOptions): GenericExtrinsicPayloadV4 {
|
||||
public createPayload (method: Call, { assetId, blockHash, era, genesisHash, nonce, runtimeVersion: { specVersion, transactionVersion }, tip }: SignatureOptions): GenericExtrinsicPayloadV4 {
|
||||
return new GenericExtrinsicPayloadV4(this.registry, {
|
||||
assetId,
|
||||
blockHash,
|
||||
era: era || IMMORTAL_ERA,
|
||||
genesisHash,
|
||||
|
||||
@@ -159,6 +159,7 @@ export interface SignatureOptions {
|
||||
signedExtensions?: string[];
|
||||
signer?: Signer;
|
||||
tip?: AnyNumber;
|
||||
assetId?: AnyNumber;
|
||||
}
|
||||
|
||||
interface ExtrinsicSignatureBase {
|
||||
@@ -179,6 +180,7 @@ export interface ExtrinsicPayloadValue {
|
||||
specVersion: AnyNumber;
|
||||
tip: AnyNumber;
|
||||
transactionVersion: AnyNumber;
|
||||
assetId?: AnyNumber;
|
||||
}
|
||||
|
||||
export interface IExtrinsicSignature extends ExtrinsicSignatureBase, Codec {
|
||||
|
||||
Reference in New Issue
Block a user