@subwallet/extension-base 1.2.10-0 → 1.2.11-1
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/background/KoniTypes.d.ts +19 -0
- package/background/types.d.ts +42 -0
- package/cjs/koni/background/handlers/Extension.js +48 -20
- package/cjs/koni/background/handlers/State.js +3 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/index.js +8 -4
- package/cjs/services/chain-service/handler/SubstrateApi.js +20 -14
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +31 -16
- package/cjs/services/migration-service/scripts/ClearMetadataDatabase.js +19 -0
- package/cjs/services/migration-service/scripts/MigrateLedgerAccountV2.js +51 -0
- package/cjs/services/migration-service/scripts/index.js +5 -1
- package/cjs/services/transaction-service/index.js +15 -4
- package/cjs/types/index.js +22 -11
- package/cjs/types/metadata.js +1 -0
- package/cjs/utils/index.js +12 -0
- package/cjs/utils/metadata.js +48 -0
- package/cjs/utils/registry.js +4 -3
- package/koni/background/handlers/Extension.js +49 -21
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +3 -1
- package/package.json +26 -5
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/index.js +8 -4
- package/services/chain-service/handler/SubstrateApi.js +20 -14
- package/services/chain-service/handler/SubstrateChainHandler.js +31 -16
- package/services/migration-service/scripts/ClearMetadataDatabase.d.ts +4 -0
- package/services/migration-service/scripts/ClearMetadataDatabase.js +11 -0
- package/services/migration-service/scripts/MigrateLedgerAccountV2.d.ts +4 -0
- package/services/migration-service/scripts/MigrateLedgerAccountV2.js +42 -0
- package/services/migration-service/scripts/index.js +5 -1
- package/services/transaction-service/index.js +16 -5
- package/types/index.d.ts +2 -1
- package/types/index.js +2 -1
- package/types/metadata.d.ts +6 -0
- package/types/metadata.js +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/metadata.d.ts +3 -0
- package/utils/metadata.js +39 -0
- package/utils/registry.d.ts +2 -2
- package/utils/registry.js +4 -3
|
@@ -14,7 +14,7 @@ import { getBaseTransactionInfo, getTransactionId, isSubstrateTransaction } from
|
|
|
14
14
|
import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
|
|
15
15
|
import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
16
16
|
import { YieldPoolType } from '@subwallet/extension-base/types';
|
|
17
|
-
import { anyNumberToBN, reformatAddress } from '@subwallet/extension-base/utils';
|
|
17
|
+
import { _isRuntimeUpdated, anyNumberToBN, getMetadataHash, reformatAddress } from '@subwallet/extension-base/utils';
|
|
18
18
|
import { mergeTransactionAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
|
|
19
19
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
20
20
|
import { BN_ZERO } from '@subwallet/extension-base/utils/number';
|
|
@@ -189,7 +189,7 @@ export default class TransactionService {
|
|
|
189
189
|
}
|
|
190
190
|
async sendTransaction(transaction) {
|
|
191
191
|
// Send Transaction
|
|
192
|
-
const emitter = transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) :
|
|
192
|
+
const emitter = await (transaction.chainType === 'substrate' ? this.signAndSendSubstrateTransaction(transaction) : this.signAndSendEvmTransaction(transaction));
|
|
193
193
|
const {
|
|
194
194
|
eventsHandler
|
|
195
195
|
} = transaction;
|
|
@@ -1010,7 +1010,7 @@ export default class TransactionService {
|
|
|
1010
1010
|
}
|
|
1011
1011
|
return emitter;
|
|
1012
1012
|
}
|
|
1013
|
-
signAndSendSubstrateTransaction({
|
|
1013
|
+
async signAndSendSubstrateTransaction({
|
|
1014
1014
|
address,
|
|
1015
1015
|
chain,
|
|
1016
1016
|
id,
|
|
@@ -1024,7 +1024,10 @@ export default class TransactionService {
|
|
|
1024
1024
|
warnings: [],
|
|
1025
1025
|
extrinsicHash: id
|
|
1026
1026
|
};
|
|
1027
|
-
transaction
|
|
1027
|
+
const extrinsic = transaction;
|
|
1028
|
+
const registry = extrinsic.registry;
|
|
1029
|
+
const signedExtensions = registry.signedExtensions;
|
|
1030
|
+
const signerOption = {
|
|
1028
1031
|
signer: {
|
|
1029
1032
|
signPayload: async payload => {
|
|
1030
1033
|
const signing = await this.state.requestService.signInternalTransaction(id, address, url || EXTENSION_REQUEST_URL, payload);
|
|
@@ -1034,7 +1037,15 @@ export default class TransactionService {
|
|
|
1034
1037
|
};
|
|
1035
1038
|
}
|
|
1036
1039
|
}
|
|
1037
|
-
}
|
|
1040
|
+
};
|
|
1041
|
+
if (_isRuntimeUpdated(signedExtensions)) {
|
|
1042
|
+
try {
|
|
1043
|
+
const metadataHash = await getMetadataHash(chain);
|
|
1044
|
+
signerOption.mode = 1;
|
|
1045
|
+
signerOption.metadataHash = `0x${metadataHash}`;
|
|
1046
|
+
} catch (e) {}
|
|
1047
|
+
}
|
|
1048
|
+
extrinsic.signAsync(address, signerOption).then(async rs => {
|
|
1038
1049
|
// Emit signed event
|
|
1039
1050
|
emitter.emit('signed', eventData);
|
|
1040
1051
|
|
package/types/index.d.ts
CHANGED
|
@@ -11,8 +11,9 @@ export interface Message extends MessageEvent {
|
|
|
11
11
|
export * from './balance';
|
|
12
12
|
export * from './buy';
|
|
13
13
|
export * from './campaigns';
|
|
14
|
+
export * from './common';
|
|
14
15
|
export * from './fee';
|
|
16
|
+
export * from './metadata';
|
|
15
17
|
export * from './ordinal';
|
|
16
18
|
export * from './transaction';
|
|
17
19
|
export * from './yield';
|
|
18
|
-
export * from './common';
|
package/types/index.js
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
export * from "./balance/index.js";
|
|
5
5
|
export * from "./buy.js";
|
|
6
6
|
export * from "./campaigns/index.js";
|
|
7
|
+
export * from "./common/index.js";
|
|
7
8
|
export * from "./fee/index.js";
|
|
9
|
+
export * from "./metadata.js";
|
|
8
10
|
export * from "./ordinal.js";
|
|
9
11
|
export * from "./transaction.js";
|
|
10
12
|
export * from "./yield/index.js";
|
|
11
|
-
export * from "./common/index.js";
|
|
12
13
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -353,6 +353,7 @@ export * from "./fetchEvmChainInfo.js";
|
|
|
353
353
|
export * from "./fetchStaticData.js";
|
|
354
354
|
export * from "./gear/index.js";
|
|
355
355
|
export * from "./lazy.js";
|
|
356
|
+
export * from "./metadata.js";
|
|
356
357
|
export * from "./number.js";
|
|
357
358
|
export * from "./object.js";
|
|
358
359
|
export * from "./promise.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
const LEDGER_API_URL = 'https://ledger-api.subwallet.app';
|
|
5
|
+
const createUrl = path => `${LEDGER_API_URL}/${path}`;
|
|
6
|
+
export const _isRuntimeUpdated = signedExtensions => {
|
|
7
|
+
return signedExtensions.includes('CheckMetadataHash');
|
|
8
|
+
};
|
|
9
|
+
export const getMetadataHash = async chain => {
|
|
10
|
+
const data = {
|
|
11
|
+
id: chain
|
|
12
|
+
};
|
|
13
|
+
const resp = await fetch(createUrl('node/metadata/hash'), {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json'
|
|
17
|
+
},
|
|
18
|
+
body: JSON.stringify(data)
|
|
19
|
+
});
|
|
20
|
+
const rs = await resp.json();
|
|
21
|
+
return rs.metadataHash;
|
|
22
|
+
};
|
|
23
|
+
export const getShortMetadata = async (chain, blob) => {
|
|
24
|
+
const data = {
|
|
25
|
+
chain: {
|
|
26
|
+
id: chain
|
|
27
|
+
},
|
|
28
|
+
txBlob: blob
|
|
29
|
+
};
|
|
30
|
+
const resp = await fetch(createUrl('transaction/metadata'), {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json'
|
|
34
|
+
},
|
|
35
|
+
body: JSON.stringify(data)
|
|
36
|
+
});
|
|
37
|
+
const rs = await resp.json();
|
|
38
|
+
return rs.txMetadata;
|
|
39
|
+
};
|
package/utils/registry.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { ResponseFindRawMetadata } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
3
|
import { Registry } from '@polkadot/types/types';
|
|
3
|
-
|
|
4
|
-
export declare const createRegistry: (chain: _ChainInfo, rawMetadata: HexString) => Registry;
|
|
4
|
+
export declare const createRegistry: (chain: _ChainInfo, data: ResponseFindRawMetadata) => Registry;
|
package/utils/registry.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
import { _getChainNativeTokenBasicInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
5
|
import { Metadata, TypeRegistry } from '@polkadot/types';
|
|
6
|
-
export const createRegistry = (chain,
|
|
6
|
+
export const createRegistry = (chain, data) => {
|
|
7
7
|
var _chain$substrateInfo;
|
|
8
8
|
const registry = new TypeRegistry();
|
|
9
|
-
const metadata = new Metadata(registry, rawMetadata);
|
|
10
|
-
registry.setMetadata(metadata);
|
|
9
|
+
const metadata = new Metadata(registry, data.rawMetadata);
|
|
11
10
|
const tokenInfo = _getChainNativeTokenBasicInfo(chain);
|
|
11
|
+
registry.register(data.types);
|
|
12
|
+
registry.setMetadata(metadata, undefined, data.userExtensions);
|
|
12
13
|
registry.setChainProperties(registry.createType('ChainProperties', {
|
|
13
14
|
ss58Format: ((_chain$substrateInfo = chain.substrateInfo) === null || _chain$substrateInfo === void 0 ? void 0 : _chain$substrateInfo.addressPrefix) || 42,
|
|
14
15
|
tokenDecimals: tokenInfo.decimals,
|