@subwallet/extension-base 1.2.10-0 → 1.2.11-0

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.
Files changed (41) hide show
  1. package/background/KoniTypes.d.ts +19 -0
  2. package/background/types.d.ts +42 -0
  3. package/cjs/koni/background/handlers/Extension.js +47 -15
  4. package/cjs/koni/background/handlers/State.js +3 -1
  5. package/cjs/packageInfo.js +1 -1
  6. package/cjs/services/balance-service/helpers/subscribe/index.js +8 -4
  7. package/cjs/services/chain-service/handler/SubstrateApi.js +20 -14
  8. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +31 -16
  9. package/cjs/services/migration-service/scripts/ClearMetadataDatabase.js +19 -0
  10. package/cjs/services/migration-service/scripts/MigrateLedgerAccountV2.js +51 -0
  11. package/cjs/services/migration-service/scripts/index.js +5 -1
  12. package/cjs/services/transaction-service/index.js +15 -4
  13. package/cjs/types/index.js +22 -11
  14. package/cjs/types/metadata.js +1 -0
  15. package/cjs/utils/index.js +12 -0
  16. package/cjs/utils/metadata.js +48 -0
  17. package/cjs/utils/registry.js +4 -3
  18. package/koni/background/handlers/Extension.js +48 -16
  19. package/koni/background/handlers/State.d.ts +2 -0
  20. package/koni/background/handlers/State.js +3 -1
  21. package/package.json +26 -5
  22. package/packageInfo.js +1 -1
  23. package/services/balance-service/helpers/subscribe/index.js +8 -4
  24. package/services/chain-service/handler/SubstrateApi.js +20 -14
  25. package/services/chain-service/handler/SubstrateChainHandler.js +31 -16
  26. package/services/migration-service/scripts/ClearMetadataDatabase.d.ts +4 -0
  27. package/services/migration-service/scripts/ClearMetadataDatabase.js +11 -0
  28. package/services/migration-service/scripts/MigrateLedgerAccountV2.d.ts +4 -0
  29. package/services/migration-service/scripts/MigrateLedgerAccountV2.js +42 -0
  30. package/services/migration-service/scripts/index.js +5 -1
  31. package/services/transaction-service/index.js +16 -5
  32. package/types/index.d.ts +2 -1
  33. package/types/index.js +2 -1
  34. package/types/metadata.d.ts +6 -0
  35. package/types/metadata.js +1 -0
  36. package/utils/index.d.ts +1 -0
  37. package/utils/index.js +1 -0
  38. package/utils/metadata.d.ts +3 -0
  39. package/utils/metadata.js +39 -0
  40. package/utils/registry.d.ts +2 -2
  41. package/utils/registry.js +4 -3
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,6 @@
1
+ export interface ResponseShortenMetadata {
2
+ txMetadata: string;
3
+ }
4
+ export interface ResponseMetadataHash {
5
+ metadataHash: string;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
package/utils/index.d.ts CHANGED
@@ -51,6 +51,7 @@ export * from './fetchEvmChainInfo';
51
51
  export * from './fetchStaticData';
52
52
  export * from './gear';
53
53
  export * from './lazy';
54
+ export * from './metadata';
54
55
  export * from './number';
55
56
  export * from './object';
56
57
  export * from './promise';
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,3 @@
1
+ export declare const _isRuntimeUpdated: (signedExtensions: string[]) => boolean;
2
+ export declare const getMetadataHash: (chain: string) => Promise<string>;
3
+ export declare const getShortMetadata: (chain: string, blob: string) => Promise<string>;
@@ -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
+ };
@@ -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
- import { HexString } from '@polkadot/util/types';
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, rawMetadata) => {
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,