@dedot/api 0.11.1 → 0.12.1-next.c7fd0a6c.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/client/DedotClient.js +4 -1
- package/cjs/extrinsic/extensions/ExtraSignedExtension.js +6 -0
- package/cjs/extrinsic/extensions/FallbackSignedExtension.js +4 -0
- package/cjs/extrinsic/extensions/SignedExtension.js +4 -1
- package/cjs/extrinsic/extensions/known/ChargeAssetTxPayment.js +14 -0
- package/cjs/extrinsic/extensions/known/ChargeTransactionPayment.js +4 -0
- package/cjs/extrinsic/extensions/known/CheckGenesis.js +3 -0
- package/cjs/extrinsic/extensions/known/CheckMetadataHash.js +12 -0
- package/cjs/extrinsic/extensions/known/CheckMortality.js +6 -0
- package/cjs/extrinsic/extensions/known/CheckNonce.js +4 -0
- package/cjs/extrinsic/extensions/known/CheckSpecVersion.js +4 -0
- package/cjs/extrinsic/extensions/known/CheckTxVersion.js +4 -0
- package/cjs/extrinsic/submittable/BaseSubmittableExtrinsic.js +1 -1
- package/cjs/extrinsic/submittable/index.js +3 -0
- package/cjs/extrinsic/submittable/utils.js +3 -3
- package/cjs/json-rpc/JsonRpcClient.js +8 -8
- package/client/DedotClient.js +4 -1
- package/extrinsic/extensions/ExtraSignedExtension.d.ts +3 -2
- package/extrinsic/extensions/ExtraSignedExtension.js +6 -0
- package/extrinsic/extensions/FallbackSignedExtension.d.ts +2 -1
- package/extrinsic/extensions/FallbackSignedExtension.js +4 -0
- package/extrinsic/extensions/SignedExtension.d.ts +2 -0
- package/extrinsic/extensions/SignedExtension.js +5 -2
- package/extrinsic/extensions/known/ChargeAssetTxPayment.d.ts +1 -0
- package/extrinsic/extensions/known/ChargeAssetTxPayment.js +15 -1
- package/extrinsic/extensions/known/ChargeTransactionPayment.d.ts +1 -0
- package/extrinsic/extensions/known/ChargeTransactionPayment.js +5 -1
- package/extrinsic/extensions/known/CheckGenesis.d.ts +1 -0
- package/extrinsic/extensions/known/CheckGenesis.js +3 -0
- package/extrinsic/extensions/known/CheckMetadataHash.d.ts +1 -0
- package/extrinsic/extensions/known/CheckMetadataHash.js +12 -0
- package/extrinsic/extensions/known/CheckMortality.d.ts +1 -0
- package/extrinsic/extensions/known/CheckMortality.js +7 -1
- package/extrinsic/extensions/known/CheckNonce.d.ts +1 -0
- package/extrinsic/extensions/known/CheckNonce.js +5 -1
- package/extrinsic/extensions/known/CheckSpecVersion.d.ts +1 -0
- package/extrinsic/extensions/known/CheckSpecVersion.js +5 -1
- package/extrinsic/extensions/known/CheckTxVersion.d.ts +1 -0
- package/extrinsic/extensions/known/CheckTxVersion.js +5 -1
- package/extrinsic/submittable/BaseSubmittableExtrinsic.js +2 -2
- package/extrinsic/submittable/index.d.ts +1 -0
- package/extrinsic/submittable/index.js +1 -0
- package/extrinsic/submittable/utils.d.ts +1 -1
- package/extrinsic/submittable/utils.js +1 -1
- package/json-rpc/JsonRpcClient.js +8 -8
- package/package.json +9 -9
|
@@ -124,7 +124,10 @@ class DedotClient// prettier-end-here
|
|
|
124
124
|
await this.chainHead.unfollow();
|
|
125
125
|
}
|
|
126
126
|
onDisconnected = async () => {
|
|
127
|
-
|
|
127
|
+
try {
|
|
128
|
+
this.chainHead.unfollow().catch(utils_1.noop);
|
|
129
|
+
}
|
|
130
|
+
catch { }
|
|
128
131
|
};
|
|
129
132
|
cleanUp() {
|
|
130
133
|
super.cleanUp();
|
|
@@ -37,6 +37,12 @@ class ExtraSignedExtension extends SignedExtension_js_1.SignedExtension {
|
|
|
37
37
|
this.data = this.#signedExtensions.map((se) => se.data);
|
|
38
38
|
this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
|
|
39
39
|
}
|
|
40
|
+
async fromPayload(payload) {
|
|
41
|
+
this.#signedExtensions = this.#getSignedExtensions();
|
|
42
|
+
await Promise.all(this.#signedExtensions.map((se) => se.fromPayload(payload)));
|
|
43
|
+
this.data = this.#signedExtensions.map((se) => se.data);
|
|
44
|
+
this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
|
|
45
|
+
}
|
|
40
46
|
get identifier() {
|
|
41
47
|
return 'ExtraSignedExtension';
|
|
42
48
|
}
|
|
@@ -30,6 +30,10 @@ class FallbackSignedExtension extends SignedExtension_js_1.SignedExtension {
|
|
|
30
30
|
this.data = {};
|
|
31
31
|
this.additionalSigned = [];
|
|
32
32
|
}
|
|
33
|
+
async fromPayload(_) {
|
|
34
|
+
this.data = {};
|
|
35
|
+
this.additionalSigned = [];
|
|
36
|
+
}
|
|
33
37
|
toPayload() {
|
|
34
38
|
return {}; // No payload contribution
|
|
35
39
|
}
|
|
@@ -14,7 +14,10 @@ class SignedExtension {
|
|
|
14
14
|
this.additionalSigned = [];
|
|
15
15
|
}
|
|
16
16
|
async init() {
|
|
17
|
-
|
|
17
|
+
throw new utils_1.DedotError('Unimplemented');
|
|
18
|
+
}
|
|
19
|
+
async fromPayload(payload) {
|
|
20
|
+
throw new utils_1.DedotError('Unimplemented');
|
|
18
21
|
}
|
|
19
22
|
get identifier() {
|
|
20
23
|
return this.signedExtensionDef.ident;
|
|
@@ -14,6 +14,13 @@ class ChargeAssetTxPayment extends SignedExtension_js_1.SignedExtension {
|
|
|
14
14
|
assetId,
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
+
async fromPayload(payload) {
|
|
18
|
+
const { tip, assetId } = payload;
|
|
19
|
+
this.data = {
|
|
20
|
+
tip: (0, utils_1.hexToBn)(tip) || 0n,
|
|
21
|
+
assetId: this.#decodeAssetId(assetId),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
17
24
|
toPayload() {
|
|
18
25
|
const { tip, assetId } = this.data;
|
|
19
26
|
return {
|
|
@@ -28,6 +35,13 @@ class ChargeAssetTxPayment extends SignedExtension_js_1.SignedExtension {
|
|
|
28
35
|
}
|
|
29
36
|
return (0, utils_1.u8aToHex)(this.$AssetId().tryEncode(assetId));
|
|
30
37
|
}
|
|
38
|
+
#decodeAssetId(assetId) {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
if (assetId === null || assetId === undefined || assetId === '' || assetId === '0x') {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return this.$AssetId().tryDecode(assetId);
|
|
44
|
+
}
|
|
31
45
|
$AssetId() {
|
|
32
46
|
const extensionTypeDef = this.registry.findType(this.signedExtensionDef.typeId);
|
|
33
47
|
(0, utils_1.assert)(extensionTypeDef.typeDef.type === 'Struct');
|
|
@@ -7,6 +7,10 @@ class ChargeTransactionPayment extends SignedExtension_js_1.SignedExtension {
|
|
|
7
7
|
async init() {
|
|
8
8
|
this.data = this.payloadOptions.tip || 0n;
|
|
9
9
|
}
|
|
10
|
+
async fromPayload(payload) {
|
|
11
|
+
const { tip } = payload;
|
|
12
|
+
this.data = (0, utils_1.hexToBn)(tip) || 0n;
|
|
13
|
+
}
|
|
10
14
|
toPayload() {
|
|
11
15
|
return {
|
|
12
16
|
tip: (0, utils_1.bnToHex)(this.data),
|
|
@@ -10,6 +10,9 @@ class CheckGenesis extends SignedExtension_js_1.SignedExtension {
|
|
|
10
10
|
async init() {
|
|
11
11
|
this.additionalSigned = (0, utils_1.ensurePresence)(this.client.genesisHash);
|
|
12
12
|
}
|
|
13
|
+
async fromPayload(payload) {
|
|
14
|
+
this.additionalSigned = (0, utils_1.ensurePresence)(payload.genesisHash, 'Genesis hash not found in the payload');
|
|
15
|
+
}
|
|
13
16
|
toPayload() {
|
|
14
17
|
return {
|
|
15
18
|
genesisHash: this.additionalSigned,
|
|
@@ -19,6 +19,18 @@ class CheckMetadataHash extends SignedExtension_js_1.SignedExtension {
|
|
|
19
19
|
this.additionalSigned = undefined;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
async fromPayload(payload) {
|
|
23
|
+
const { mode, metadataHash } = payload;
|
|
24
|
+
if (mode) {
|
|
25
|
+
(0, utils_1.assert)((0, utils_1.isHex)(metadataHash), 'Metadata hash is not a valid hex string');
|
|
26
|
+
this.data = { mode: 'Enabled' };
|
|
27
|
+
this.additionalSigned = metadataHash;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.data = { mode: 'Disabled' };
|
|
31
|
+
this.additionalSigned = undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
22
34
|
toPayload() {
|
|
23
35
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/8dbe4ee80734bba6644c7e5f879a363ce7c0a19f/substrate/frame/metadata-hash-extension/src/lib.rs#L55-L58
|
|
24
36
|
let enabled = this.data.mode === 'Enabled';
|
|
@@ -17,6 +17,12 @@ class CheckMortality extends SignedExtension_js_1.SignedExtension {
|
|
|
17
17
|
this.data = { period: this.#calculateMortalLength(), current: BigInt(this.#signingHeader.number) };
|
|
18
18
|
this.additionalSigned = this.#signingHeader.hash;
|
|
19
19
|
}
|
|
20
|
+
async fromPayload(payload) {
|
|
21
|
+
const { era, blockHash, blockNumber } = payload;
|
|
22
|
+
this.#signingHeader = { hash: blockHash, number: (0, utils_1.hexToNumber)(blockNumber) };
|
|
23
|
+
this.data = this.$Data.tryDecode(era);
|
|
24
|
+
this.additionalSigned = blockHash;
|
|
25
|
+
}
|
|
20
26
|
async #getSigningHeader() {
|
|
21
27
|
if (this.client.rpcVersion === 'v2') {
|
|
22
28
|
return this.#getSigningHeaderRpcV2();
|
|
@@ -10,6 +10,10 @@ class CheckNonce extends SignedExtension_js_1.SignedExtension {
|
|
|
10
10
|
async init() {
|
|
11
11
|
this.data = this.payloadOptions.nonce || (await this.#getNonce());
|
|
12
12
|
}
|
|
13
|
+
async fromPayload(payload) {
|
|
14
|
+
const { nonce } = payload;
|
|
15
|
+
this.data = (0, utils_1.hexToNumber)(nonce);
|
|
16
|
+
}
|
|
13
17
|
async #getNonce() {
|
|
14
18
|
const { signerAddress } = this.options || {};
|
|
15
19
|
(0, utils_1.assert)(signerAddress, 'Signer address not found');
|
|
@@ -10,6 +10,10 @@ class CheckSpecVersion extends SignedExtension_js_1.SignedExtension {
|
|
|
10
10
|
async init() {
|
|
11
11
|
this.additionalSigned = this.client.runtimeVersion.specVersion;
|
|
12
12
|
}
|
|
13
|
+
async fromPayload(payload) {
|
|
14
|
+
const { specVersion } = payload;
|
|
15
|
+
this.additionalSigned = (0, utils_1.hexToNumber)(specVersion);
|
|
16
|
+
}
|
|
13
17
|
toPayload() {
|
|
14
18
|
return {
|
|
15
19
|
specVersion: (0, utils_1.numberToHex)(this.additionalSigned),
|
|
@@ -10,6 +10,10 @@ class CheckTxVersion extends SignedExtension_js_1.SignedExtension {
|
|
|
10
10
|
async init() {
|
|
11
11
|
this.additionalSigned = this.client.runtimeVersion.transactionVersion;
|
|
12
12
|
}
|
|
13
|
+
async fromPayload(payload) {
|
|
14
|
+
const { transactionVersion } = payload;
|
|
15
|
+
this.additionalSigned = (0, utils_1.hexToNumber)(transactionVersion);
|
|
16
|
+
}
|
|
13
17
|
toPayload() {
|
|
14
18
|
return {
|
|
15
19
|
transactionVersion: (0, utils_1.numberToHex)(this.additionalSigned),
|
|
@@ -29,7 +29,7 @@ class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
|
|
|
29
29
|
const signer = this.#getSigner(options);
|
|
30
30
|
let signature, alteredTx;
|
|
31
31
|
if ((0, utils_js_1.isKeyringPair)(fromAccount)) {
|
|
32
|
-
signature = (0, utils_1.u8aToHex)((0, utils_js_1.
|
|
32
|
+
signature = (0, utils_1.u8aToHex)((0, utils_js_1.signRawMessage)(fromAccount, extra.toRawPayload(this.callHex).data));
|
|
33
33
|
}
|
|
34
34
|
else if (signer?.signPayload) {
|
|
35
35
|
const result = await signer.signPayload(extra.toPayload(this.callHex));
|
|
@@ -14,7 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.signRawMessage = void 0;
|
|
17
18
|
__exportStar(require("./errors.js"), exports);
|
|
18
19
|
__exportStar(require("./SubmittableResult.js"), exports);
|
|
19
20
|
__exportStar(require("./SubmittableExtrinsic.js"), exports);
|
|
20
21
|
__exportStar(require("./SubmittableExtrinsicV2.js"), exports);
|
|
22
|
+
var utils_js_1 = require("./utils.js");
|
|
23
|
+
Object.defineProperty(exports, "signRawMessage", { enumerable: true, get: function () { return utils_js_1.signRawMessage; } });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.txDefer = exports.toTxStatus = exports.
|
|
3
|
+
exports.txDefer = exports.toTxStatus = exports.signRawMessage = exports.isKeyringPair = void 0;
|
|
4
4
|
const utils_1 = require("@dedot/utils");
|
|
5
5
|
const errors_js_1 = require("./errors.js");
|
|
6
6
|
function isKeyringPair(account) {
|
|
@@ -12,13 +12,13 @@ exports.isKeyringPair = isKeyringPair;
|
|
|
12
12
|
* @param signerPair
|
|
13
13
|
* @param raw
|
|
14
14
|
*/
|
|
15
|
-
function
|
|
15
|
+
function signRawMessage(signerPair, raw) {
|
|
16
16
|
const u8a = (0, utils_1.hexToU8a)(raw);
|
|
17
17
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/943697fa693a4da6ef481ef93df522accb7d0583/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs#L234-L238
|
|
18
18
|
const toSignRaw = u8a.length > 256 ? (0, utils_1.blake2AsU8a)(u8a, 256) : u8a;
|
|
19
19
|
return signerPair.sign(toSignRaw, { withType: true });
|
|
20
20
|
}
|
|
21
|
-
exports.
|
|
21
|
+
exports.signRawMessage = signRawMessage;
|
|
22
22
|
/**
|
|
23
23
|
* Convert transaction status to transaction event
|
|
24
24
|
*
|
|
@@ -80,21 +80,21 @@ class JsonRpcClient extends utils_1.EventEmitter {
|
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
|
-
#onConnected = async () => {
|
|
83
|
+
#onConnected = async (...args) => {
|
|
84
84
|
// @ts-ignore
|
|
85
|
-
this.emit('connected');
|
|
85
|
+
this.emit('connected', ...args);
|
|
86
86
|
};
|
|
87
|
-
#onDisconnected = async () => {
|
|
87
|
+
#onDisconnected = async (...args) => {
|
|
88
88
|
// @ts-ignore
|
|
89
|
-
this.emit('disconnected');
|
|
89
|
+
this.emit('disconnected', ...args);
|
|
90
90
|
};
|
|
91
|
-
#onReconnecting = async () => {
|
|
91
|
+
#onReconnecting = async (...args) => {
|
|
92
92
|
// @ts-ignore
|
|
93
|
-
this.emit('reconnecting');
|
|
93
|
+
this.emit('reconnecting', ...args);
|
|
94
94
|
};
|
|
95
|
-
#onError = async (
|
|
95
|
+
#onError = async (...args) => {
|
|
96
96
|
// @ts-ignore
|
|
97
|
-
this.emit('error',
|
|
97
|
+
this.emit('error', ...args);
|
|
98
98
|
};
|
|
99
99
|
async disconnect() {
|
|
100
100
|
await this.#provider.disconnect();
|
package/client/DedotClient.js
CHANGED
|
@@ -121,7 +121,10 @@ export class DedotClient// prettier-end-here
|
|
|
121
121
|
await this.chainHead.unfollow();
|
|
122
122
|
}
|
|
123
123
|
onDisconnected = async () => {
|
|
124
|
-
|
|
124
|
+
try {
|
|
125
|
+
this.chainHead.unfollow().catch(noop);
|
|
126
|
+
}
|
|
127
|
+
catch { }
|
|
125
128
|
};
|
|
126
129
|
cleanUp() {
|
|
127
130
|
super.cleanUp();
|
|
@@ -5,6 +5,7 @@ import { SignedExtension } from './SignedExtension.js';
|
|
|
5
5
|
export declare class ExtraSignedExtension extends SignedExtension<any[], any[]> {
|
|
6
6
|
#private;
|
|
7
7
|
init(): Promise<void>;
|
|
8
|
+
fromPayload(payload: SignerPayloadJSON): Promise<void>;
|
|
8
9
|
get identifier(): string;
|
|
9
10
|
get $Data(): $.AnyShape;
|
|
10
11
|
get $AdditionalSigned(): $.AnyShape;
|
|
@@ -15,6 +16,6 @@ export declare class ExtraSignedExtension extends SignedExtension<any[], any[]>
|
|
|
15
16
|
* @returns boolean
|
|
16
17
|
*/
|
|
17
18
|
private isRequireNoExternalInputs;
|
|
18
|
-
toPayload(call?: HexString): SignerPayloadJSON;
|
|
19
|
-
toRawPayload(call?: HexString): SignerPayloadRaw;
|
|
19
|
+
toPayload(call?: HexString | string): SignerPayloadJSON;
|
|
20
|
+
toRawPayload(call?: HexString | string): SignerPayloadRaw;
|
|
20
21
|
}
|
|
@@ -11,6 +11,12 @@ export class ExtraSignedExtension extends SignedExtension {
|
|
|
11
11
|
this.data = this.#signedExtensions.map((se) => se.data);
|
|
12
12
|
this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
|
|
13
13
|
}
|
|
14
|
+
async fromPayload(payload) {
|
|
15
|
+
this.#signedExtensions = this.#getSignedExtensions();
|
|
16
|
+
await Promise.all(this.#signedExtensions.map((se) => se.fromPayload(payload)));
|
|
17
|
+
this.data = this.#signedExtensions.map((se) => se.data);
|
|
18
|
+
this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
|
|
19
|
+
}
|
|
14
20
|
get identifier() {
|
|
15
21
|
return 'ExtraSignedExtension';
|
|
16
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PortableRegistry } from '@dedot/codecs';
|
|
2
2
|
import { SignerPayloadJSON } from '@dedot/types';
|
|
3
|
-
import { SignedExtension } from './SignedExtension.js';
|
|
4
3
|
import { ISubstrateClient } from '../../types.js';
|
|
4
|
+
import { SignedExtension } from './SignedExtension.js';
|
|
5
5
|
/**
|
|
6
6
|
* A fallback signed extension that can be used for extensions
|
|
7
7
|
* that don't require external input.
|
|
@@ -21,6 +21,7 @@ export declare class FallbackSignedExtension extends SignedExtension {
|
|
|
21
21
|
constructor(client: ISubstrateClient, options: any, extensionIdent: string);
|
|
22
22
|
get identifier(): string;
|
|
23
23
|
init(): Promise<void>;
|
|
24
|
+
fromPayload(_: SignerPayloadJSON): Promise<void>;
|
|
24
25
|
toPayload(): Partial<SignerPayloadJSON>;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
@@ -27,6 +27,10 @@ export class FallbackSignedExtension extends SignedExtension {
|
|
|
27
27
|
this.data = {};
|
|
28
28
|
this.additionalSigned = [];
|
|
29
29
|
}
|
|
30
|
+
async fromPayload(_) {
|
|
31
|
+
this.data = {};
|
|
32
|
+
this.additionalSigned = [];
|
|
33
|
+
}
|
|
30
34
|
toPayload() {
|
|
31
35
|
return {}; // No payload contribution
|
|
32
36
|
}
|
|
@@ -9,6 +9,7 @@ export interface ISignedExtension {
|
|
|
9
9
|
data: any;
|
|
10
10
|
additionalSigned: any;
|
|
11
11
|
init(): Promise<void>;
|
|
12
|
+
fromPayload(payload: SignerPayloadJSON): Promise<void>;
|
|
12
13
|
registry: PortableRegistry;
|
|
13
14
|
toPayload(...additional: any[]): Partial<SignerPayloadJSON>;
|
|
14
15
|
}
|
|
@@ -24,6 +25,7 @@ export declare abstract class SignedExtension<Data extends any = {}, AdditionalS
|
|
|
24
25
|
additionalSigned: AdditionalSigned;
|
|
25
26
|
constructor(client: ISubstrateClient, options?: SignedExtensionOptions | undefined);
|
|
26
27
|
init(): Promise<void>;
|
|
28
|
+
fromPayload(payload: SignerPayloadJSON): Promise<void>;
|
|
27
29
|
get identifier(): string;
|
|
28
30
|
get $Data(): $.AnyShape;
|
|
29
31
|
get $AdditionalSigned(): $.AnyShape;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ensurePresence } from '@dedot/utils';
|
|
1
|
+
import { DedotError, ensurePresence } from '@dedot/utils';
|
|
2
2
|
export class SignedExtension {
|
|
3
3
|
client;
|
|
4
4
|
options;
|
|
@@ -11,7 +11,10 @@ export class SignedExtension {
|
|
|
11
11
|
this.additionalSigned = [];
|
|
12
12
|
}
|
|
13
13
|
async init() {
|
|
14
|
-
|
|
14
|
+
throw new DedotError('Unimplemented');
|
|
15
|
+
}
|
|
16
|
+
async fromPayload(payload) {
|
|
17
|
+
throw new DedotError('Unimplemented');
|
|
15
18
|
}
|
|
16
19
|
get identifier() {
|
|
17
20
|
return this.signedExtensionDef.ident;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert, bnToHex, u8aToHex } from '@dedot/utils';
|
|
1
|
+
import { assert, bnToHex, hexToBn, u8aToHex } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
/**
|
|
4
4
|
* @name ChargeAssetTxPayment
|
|
@@ -11,6 +11,13 @@ export class ChargeAssetTxPayment extends SignedExtension {
|
|
|
11
11
|
assetId,
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
+
async fromPayload(payload) {
|
|
15
|
+
const { tip, assetId } = payload;
|
|
16
|
+
this.data = {
|
|
17
|
+
tip: hexToBn(tip) || 0n,
|
|
18
|
+
assetId: this.#decodeAssetId(assetId),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
14
21
|
toPayload() {
|
|
15
22
|
const { tip, assetId } = this.data;
|
|
16
23
|
return {
|
|
@@ -25,6 +32,13 @@ export class ChargeAssetTxPayment extends SignedExtension {
|
|
|
25
32
|
}
|
|
26
33
|
return u8aToHex(this.$AssetId().tryEncode(assetId));
|
|
27
34
|
}
|
|
35
|
+
#decodeAssetId(assetId) {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
if (assetId === null || assetId === undefined || assetId === '' || assetId === '0x') {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return this.$AssetId().tryDecode(assetId);
|
|
41
|
+
}
|
|
28
42
|
$AssetId() {
|
|
29
43
|
const extensionTypeDef = this.registry.findType(this.signedExtensionDef.typeId);
|
|
30
44
|
assert(extensionTypeDef.typeDef.type === 'Struct');
|
|
@@ -2,5 +2,6 @@ import { SignerPayloadJSON } from '@dedot/types';
|
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
export declare class ChargeTransactionPayment extends SignedExtension<bigint> {
|
|
4
4
|
init(): Promise<void>;
|
|
5
|
+
fromPayload(payload: SignerPayloadJSON): Promise<void>;
|
|
5
6
|
toPayload(): Partial<SignerPayloadJSON>;
|
|
6
7
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { bnToHex } from '@dedot/utils';
|
|
1
|
+
import { bnToHex, hexToBn } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
export class ChargeTransactionPayment extends SignedExtension {
|
|
4
4
|
async init() {
|
|
5
5
|
this.data = this.payloadOptions.tip || 0n;
|
|
6
6
|
}
|
|
7
|
+
async fromPayload(payload) {
|
|
8
|
+
const { tip } = payload;
|
|
9
|
+
this.data = hexToBn(tip) || 0n;
|
|
10
|
+
}
|
|
7
11
|
toPayload() {
|
|
8
12
|
return {
|
|
9
13
|
tip: bnToHex(this.data),
|
|
@@ -7,6 +7,9 @@ export class CheckGenesis extends SignedExtension {
|
|
|
7
7
|
async init() {
|
|
8
8
|
this.additionalSigned = ensurePresence(this.client.genesisHash);
|
|
9
9
|
}
|
|
10
|
+
async fromPayload(payload) {
|
|
11
|
+
this.additionalSigned = ensurePresence(payload.genesisHash, 'Genesis hash not found in the payload');
|
|
12
|
+
}
|
|
10
13
|
toPayload() {
|
|
11
14
|
return {
|
|
12
15
|
genesisHash: this.additionalSigned,
|
|
@@ -16,6 +16,18 @@ export class CheckMetadataHash extends SignedExtension {
|
|
|
16
16
|
this.additionalSigned = undefined;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
async fromPayload(payload) {
|
|
20
|
+
const { mode, metadataHash } = payload;
|
|
21
|
+
if (mode) {
|
|
22
|
+
assert(isHex(metadataHash), 'Metadata hash is not a valid hex string');
|
|
23
|
+
this.data = { mode: 'Enabled' };
|
|
24
|
+
this.additionalSigned = metadataHash;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.data = { mode: 'Disabled' };
|
|
28
|
+
this.additionalSigned = undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
19
31
|
toPayload() {
|
|
20
32
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/8dbe4ee80734bba6644c7e5f879a363ce7c0a19f/substrate/frame/metadata-hash-extension/src/lib.rs#L55-L58
|
|
21
33
|
let enabled = this.data.mode === 'Enabled';
|
|
@@ -11,5 +11,6 @@ export declare const MORTAL_PERIOD: number;
|
|
|
11
11
|
export declare class CheckMortality extends SignedExtension<EraLike, Hash> {
|
|
12
12
|
#private;
|
|
13
13
|
init(): Promise<void>;
|
|
14
|
+
fromPayload(payload: SignerPayloadJSON): Promise<void>;
|
|
14
15
|
toPayload(): Partial<SignerPayloadJSON>;
|
|
15
16
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert, bnMin, isZeroHex, numberToHex, u8aToHex } from '@dedot/utils';
|
|
1
|
+
import { assert, bnMin, hexToNumber, isZeroHex, numberToHex, u8aToHex } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
export const MAX_FINALITY_LAG = 5;
|
|
4
4
|
export const FALLBACK_MAX_HASH_COUNT = 250;
|
|
@@ -14,6 +14,12 @@ export class CheckMortality extends SignedExtension {
|
|
|
14
14
|
this.data = { period: this.#calculateMortalLength(), current: BigInt(this.#signingHeader.number) };
|
|
15
15
|
this.additionalSigned = this.#signingHeader.hash;
|
|
16
16
|
}
|
|
17
|
+
async fromPayload(payload) {
|
|
18
|
+
const { era, blockHash, blockNumber } = payload;
|
|
19
|
+
this.#signingHeader = { hash: blockHash, number: hexToNumber(blockNumber) };
|
|
20
|
+
this.data = this.$Data.tryDecode(era);
|
|
21
|
+
this.additionalSigned = blockHash;
|
|
22
|
+
}
|
|
17
23
|
async #getSigningHeader() {
|
|
18
24
|
if (this.client.rpcVersion === 'v2') {
|
|
19
25
|
return this.#getSigningHeaderRpcV2();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert, numberToHex } from '@dedot/utils';
|
|
1
|
+
import { assert, hexToNumber, numberToHex } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
/**
|
|
4
4
|
* @description Nonce check and increment to give replay protection for transactions.
|
|
@@ -7,6 +7,10 @@ export class CheckNonce extends SignedExtension {
|
|
|
7
7
|
async init() {
|
|
8
8
|
this.data = this.payloadOptions.nonce || (await this.#getNonce());
|
|
9
9
|
}
|
|
10
|
+
async fromPayload(payload) {
|
|
11
|
+
const { nonce } = payload;
|
|
12
|
+
this.data = hexToNumber(nonce);
|
|
13
|
+
}
|
|
10
14
|
async #getNonce() {
|
|
11
15
|
const { signerAddress } = this.options || {};
|
|
12
16
|
assert(signerAddress, 'Signer address not found');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { numberToHex } from '@dedot/utils';
|
|
1
|
+
import { hexToNumber, numberToHex } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
/**
|
|
4
4
|
* @description Ensure the runtime version registered in the transaction is the same as at present.
|
|
@@ -7,6 +7,10 @@ export class CheckSpecVersion extends SignedExtension {
|
|
|
7
7
|
async init() {
|
|
8
8
|
this.additionalSigned = this.client.runtimeVersion.specVersion;
|
|
9
9
|
}
|
|
10
|
+
async fromPayload(payload) {
|
|
11
|
+
const { specVersion } = payload;
|
|
12
|
+
this.additionalSigned = hexToNumber(specVersion);
|
|
13
|
+
}
|
|
10
14
|
toPayload() {
|
|
11
15
|
return {
|
|
12
16
|
specVersion: numberToHex(this.additionalSigned),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { numberToHex } from '@dedot/utils';
|
|
1
|
+
import { hexToNumber, numberToHex } from '@dedot/utils';
|
|
2
2
|
import { SignedExtension } from '../SignedExtension.js';
|
|
3
3
|
/**
|
|
4
4
|
* @description Ensure the transaction version registered in the transaction is the same as at present.
|
|
@@ -7,6 +7,10 @@ export class CheckTxVersion extends SignedExtension {
|
|
|
7
7
|
async init() {
|
|
8
8
|
this.additionalSigned = this.client.runtimeVersion.transactionVersion;
|
|
9
9
|
}
|
|
10
|
+
async fromPayload(payload) {
|
|
11
|
+
const { transactionVersion } = payload;
|
|
12
|
+
this.additionalSigned = hexToNumber(transactionVersion);
|
|
13
|
+
}
|
|
10
14
|
toPayload() {
|
|
11
15
|
return {
|
|
12
16
|
transactionVersion: numberToHex(this.additionalSigned),
|
|
@@ -2,7 +2,7 @@ import { Extrinsic } from '@dedot/codecs';
|
|
|
2
2
|
import { DedotError, isFunction, toHex, u8aToHex } from '@dedot/utils';
|
|
3
3
|
import { ExtraSignedExtension } from '../extensions/index.js';
|
|
4
4
|
import { fakeSigner } from './fakeSigner.js';
|
|
5
|
-
import { isKeyringPair,
|
|
5
|
+
import { isKeyringPair, signRawMessage, txDefer } from './utils.js';
|
|
6
6
|
export class BaseSubmittableExtrinsic extends Extrinsic {
|
|
7
7
|
client;
|
|
8
8
|
#alterTx;
|
|
@@ -26,7 +26,7 @@ export class BaseSubmittableExtrinsic extends Extrinsic {
|
|
|
26
26
|
const signer = this.#getSigner(options);
|
|
27
27
|
let signature, alteredTx;
|
|
28
28
|
if (isKeyringPair(fromAccount)) {
|
|
29
|
-
signature = u8aToHex(
|
|
29
|
+
signature = u8aToHex(signRawMessage(fromAccount, extra.toRawPayload(this.callHex).data));
|
|
30
30
|
}
|
|
31
31
|
else if (signer?.signPayload) {
|
|
32
32
|
const result = await signer.signPayload(extra.toPayload(this.callHex));
|
|
@@ -7,7 +7,7 @@ export declare function isKeyringPair(account: AddressOrPair): account is IKeyri
|
|
|
7
7
|
* @param signerPair
|
|
8
8
|
* @param raw
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function signRawMessage(signerPair: IKeyringPair, raw: HexString | string): Uint8Array;
|
|
11
11
|
type TxInfo = {
|
|
12
12
|
txIndex: number;
|
|
13
13
|
blockNumber: number;
|
|
@@ -8,7 +8,7 @@ export function isKeyringPair(account) {
|
|
|
8
8
|
* @param signerPair
|
|
9
9
|
* @param raw
|
|
10
10
|
*/
|
|
11
|
-
export function
|
|
11
|
+
export function signRawMessage(signerPair, raw) {
|
|
12
12
|
const u8a = hexToU8a(raw);
|
|
13
13
|
// Ref: https://github.com/paritytech/polkadot-sdk/blob/943697fa693a4da6ef481ef93df522accb7d0583/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs#L234-L238
|
|
14
14
|
const toSignRaw = u8a.length > 256 ? blake2AsU8a(u8a, 256) : u8a;
|
|
@@ -76,21 +76,21 @@ export class JsonRpcClient extends EventEmitter {
|
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
|
-
#onConnected = async () => {
|
|
79
|
+
#onConnected = async (...args) => {
|
|
80
80
|
// @ts-ignore
|
|
81
|
-
this.emit('connected');
|
|
81
|
+
this.emit('connected', ...args);
|
|
82
82
|
};
|
|
83
|
-
#onDisconnected = async () => {
|
|
83
|
+
#onDisconnected = async (...args) => {
|
|
84
84
|
// @ts-ignore
|
|
85
|
-
this.emit('disconnected');
|
|
85
|
+
this.emit('disconnected', ...args);
|
|
86
86
|
};
|
|
87
|
-
#onReconnecting = async () => {
|
|
87
|
+
#onReconnecting = async (...args) => {
|
|
88
88
|
// @ts-ignore
|
|
89
|
-
this.emit('reconnecting');
|
|
89
|
+
this.emit('reconnecting', ...args);
|
|
90
90
|
};
|
|
91
|
-
#onError = async (
|
|
91
|
+
#onError = async (...args) => {
|
|
92
92
|
// @ts-ignore
|
|
93
|
-
this.emit('error',
|
|
93
|
+
this.emit('error', ...args);
|
|
94
94
|
};
|
|
95
95
|
async disconnect() {
|
|
96
96
|
await this.#provider.disconnect();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
|
|
4
4
|
"description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
|
|
5
5
|
"author": "Thang X. Vu <thang@dedot.dev>",
|
|
6
6
|
"homepage": "https://dedot.dev",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"type": "module",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@dedot/codecs": "0.
|
|
17
|
-
"@dedot/providers": "0.
|
|
18
|
-
"@dedot/runtime-specs": "0.
|
|
19
|
-
"@dedot/shape": "0.
|
|
20
|
-
"@dedot/storage": "0.
|
|
21
|
-
"@dedot/types": "0.
|
|
22
|
-
"@dedot/utils": "0.
|
|
16
|
+
"@dedot/codecs": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
|
|
17
|
+
"@dedot/providers": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
|
|
18
|
+
"@dedot/runtime-specs": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
|
|
19
|
+
"@dedot/shape": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
|
|
20
|
+
"@dedot/storage": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
|
|
21
|
+
"@dedot/types": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
|
|
22
|
+
"@dedot/utils": "0.12.1-next.c7fd0a6c.2+c7fd0a6c"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"node": ">=18"
|
|
49
49
|
},
|
|
50
50
|
"license": "Apache-2.0",
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "c7fd0a6c35b80d78cbf6dead68b12b2820f16f0b",
|
|
52
52
|
"module": "./index.js",
|
|
53
53
|
"types": "./index.d.ts"
|
|
54
54
|
}
|