1 | import { Enum, Struct } from '@polkadot/types-codec';
|
2 | import { objectSpread } from '@polkadot/util';
|
3 | import { sign } from '../util.js';
|
4 | /**
|
5 | * @name GenericExtrinsicPayloadV4
|
6 | * @description
|
7 | * A signing payload for an [[Extrinsic]]. For the final encoding, it is
|
8 | * variable length based on the contents included
|
9 | */
|
10 | export class GenericExtrinsicPayloadV4 extends Struct {
|
11 | constructor(registry, value) {
|
12 | super(registry, objectSpread({ method: 'Bytes' }, registry.getSignedExtensionTypes(), registry.getSignedExtensionExtra()), value);
|
13 | // Do detection for the type of extrinsic, in the case of MultiSignature
|
14 | // this is an enum, in the case of AnySignature, this is a Hash only
|
15 | // (which may be 64 or 65 bytes)
|
16 | this.__internal__signOptions = {
|
17 | withType: registry.createTypeUnsafe('ExtrinsicSignature', []) instanceof Enum
|
18 | };
|
19 | }
|
20 | /**
|
21 | * @description Returns a breakdown of the hex encoding for this Codec
|
22 | */
|
23 | inspect() {
|
24 | return super.inspect({ method: true });
|
25 | }
|
26 | /**
|
27 | * @description The block [[BlockHash]] the signature applies to (mortal/immortal)
|
28 | */
|
29 | get blockHash() {
|
30 | return this.getT('blockHash');
|
31 | }
|
32 | /**
|
33 | * @description The [[ExtrinsicEra]]
|
34 | */
|
35 | get era() {
|
36 | return this.getT('era');
|
37 | }
|
38 | /**
|
39 | * @description The genesis [[BlockHash]] the signature applies to (mortal/immortal)
|
40 | */
|
41 | get genesisHash() {
|
42 | return this.getT('genesisHash');
|
43 | }
|
44 | /**
|
45 | * @description The [[Bytes]] contained in the payload
|
46 | */
|
47 | get method() {
|
48 | return this.getT('method');
|
49 | }
|
50 | /**
|
51 | * @description The [[Index]]
|
52 | */
|
53 | get nonce() {
|
54 | return this.getT('nonce');
|
55 | }
|
56 | /**
|
57 | * @description The specVersion for this signature
|
58 | */
|
59 | get specVersion() {
|
60 | return this.getT('specVersion');
|
61 | }
|
62 | /**
|
63 | * @description The tip [[Balance]]
|
64 | */
|
65 | get tip() {
|
66 | return this.getT('tip');
|
67 | }
|
68 | /**
|
69 | * @description The transactionVersion for this signature
|
70 | */
|
71 | get transactionVersion() {
|
72 | return this.getT('transactionVersion');
|
73 | }
|
74 | /**
|
75 | * @description The (optional) asset id for this signature for chains that support transaction fees in assets
|
76 | */
|
77 | get assetId() {
|
78 | return this.getT('assetId');
|
79 | }
|
80 | /**
|
81 | * @description Sign the payload with the keypair
|
82 | */
|
83 | sign(signerPair) {
|
84 | // NOTE The `toU8a({ method: true })` argument is absolutely critical, we
|
85 | // don't want the method (Bytes) to have the length prefix included. This
|
86 | // means that the data-as-signed is un-decodable, but is also doesn't need
|
87 | // the extra information, only the pure data (and is not decoded) ...
|
88 | // The same applies to V1..V3, if we have a V5, carry this comment
|
89 | return sign(this.registry, signerPair, this.toU8a({ method: true }), this.__internal__signOptions);
|
90 | }
|
91 | }
|