@kheopskit/core 0.1.2 → 1.0.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.
- package/dist/index.d.mts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +68 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
package/dist/index.d.mts
CHANGED
|
@@ -48,6 +48,13 @@ type WalletId = string;
|
|
|
48
48
|
type KheopskitConfig = {
|
|
49
49
|
autoReconnect: boolean;
|
|
50
50
|
platforms: WalletPlatform[];
|
|
51
|
+
/**
|
|
52
|
+
* Allowed Polkadot account key types.
|
|
53
|
+
* Accounts with other key types are filtered out from kheopskit state.
|
|
54
|
+
*
|
|
55
|
+
* @default ["sr25519", "ed25519", "ecdsa"]
|
|
56
|
+
*/
|
|
57
|
+
polkadotAccountTypes: PolkadotAccountType[];
|
|
51
58
|
walletConnect?: {
|
|
52
59
|
projectId: string;
|
|
53
60
|
metadata: Metadata;
|
|
@@ -137,7 +144,9 @@ type EthereumAppKitWallet = {
|
|
|
137
144
|
type EthereumWallet = EthereumInjectedWallet | EthereumAppKitWallet;
|
|
138
145
|
type Wallet = PolkadotWallet | EthereumWallet;
|
|
139
146
|
type WalletPlatform = Wallet["platform"];
|
|
140
|
-
type
|
|
147
|
+
type PolkadotAccountType = "sr25519" | "ed25519" | "ecdsa" | "ethereum";
|
|
148
|
+
type PolkadotAccount = Omit<InjectedPolkadotAccount, "type"> & {
|
|
149
|
+
type: PolkadotAccountType;
|
|
141
150
|
id: WalletAccountId;
|
|
142
151
|
platform: "polkadot";
|
|
143
152
|
walletName: string;
|
|
@@ -178,6 +187,8 @@ type CachedAccount = {
|
|
|
178
187
|
name?: string;
|
|
179
188
|
/** Cached chain ID for Ethereum accounts. */
|
|
180
189
|
chainId?: number;
|
|
190
|
+
/** Cached key type for Polkadot accounts. */
|
|
191
|
+
polkadotAccountType?: PolkadotAccountType;
|
|
181
192
|
walletId: WalletId;
|
|
182
193
|
walletName: string;
|
|
183
194
|
};
|
|
@@ -279,4 +290,4 @@ type KheopskitState = {
|
|
|
279
290
|
};
|
|
280
291
|
declare const getKheopskit$: (config?: Partial<KheopskitConfig>, ssrCookies?: string, existingStore?: ReturnType<typeof createKheopskitStore>) => Observable<KheopskitState>;
|
|
281
292
|
|
|
282
|
-
export { type CachedAccount, type CachedWallet, DEFAULT_STORAGE_KEY, type EthereumAccount, type EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, type KheopskitConfig, type KheopskitState, type PolkadotAccount, type PolkadotAppKitWallet, type PolkadotInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, clearAllCachedObservables, clearCachedObservable, createKheopskitStore, getCachedIcon, getDefaultStore, getKheopskit$, getSafeLocalStorage, hydrateAccount, hydrateWallet, resetAppKitCache, resolveConfig };
|
|
293
|
+
export { type CachedAccount, type CachedWallet, DEFAULT_STORAGE_KEY, type EthereumAccount, type EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, type KheopskitConfig, type KheopskitState, type PolkadotAccount, type PolkadotAccountType, type PolkadotAppKitWallet, type PolkadotInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, clearAllCachedObservables, clearCachedObservable, createKheopskitStore, getCachedIcon, getDefaultStore, getKheopskit$, getSafeLocalStorage, hydrateAccount, hydrateWallet, resetAppKitCache, resolveConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -48,6 +48,13 @@ type WalletId = string;
|
|
|
48
48
|
type KheopskitConfig = {
|
|
49
49
|
autoReconnect: boolean;
|
|
50
50
|
platforms: WalletPlatform[];
|
|
51
|
+
/**
|
|
52
|
+
* Allowed Polkadot account key types.
|
|
53
|
+
* Accounts with other key types are filtered out from kheopskit state.
|
|
54
|
+
*
|
|
55
|
+
* @default ["sr25519", "ed25519", "ecdsa"]
|
|
56
|
+
*/
|
|
57
|
+
polkadotAccountTypes: PolkadotAccountType[];
|
|
51
58
|
walletConnect?: {
|
|
52
59
|
projectId: string;
|
|
53
60
|
metadata: Metadata;
|
|
@@ -137,7 +144,9 @@ type EthereumAppKitWallet = {
|
|
|
137
144
|
type EthereumWallet = EthereumInjectedWallet | EthereumAppKitWallet;
|
|
138
145
|
type Wallet = PolkadotWallet | EthereumWallet;
|
|
139
146
|
type WalletPlatform = Wallet["platform"];
|
|
140
|
-
type
|
|
147
|
+
type PolkadotAccountType = "sr25519" | "ed25519" | "ecdsa" | "ethereum";
|
|
148
|
+
type PolkadotAccount = Omit<InjectedPolkadotAccount, "type"> & {
|
|
149
|
+
type: PolkadotAccountType;
|
|
141
150
|
id: WalletAccountId;
|
|
142
151
|
platform: "polkadot";
|
|
143
152
|
walletName: string;
|
|
@@ -178,6 +187,8 @@ type CachedAccount = {
|
|
|
178
187
|
name?: string;
|
|
179
188
|
/** Cached chain ID for Ethereum accounts. */
|
|
180
189
|
chainId?: number;
|
|
190
|
+
/** Cached key type for Polkadot accounts. */
|
|
191
|
+
polkadotAccountType?: PolkadotAccountType;
|
|
181
192
|
walletId: WalletId;
|
|
182
193
|
walletName: string;
|
|
183
194
|
};
|
|
@@ -279,4 +290,4 @@ type KheopskitState = {
|
|
|
279
290
|
};
|
|
280
291
|
declare const getKheopskit$: (config?: Partial<KheopskitConfig>, ssrCookies?: string, existingStore?: ReturnType<typeof createKheopskitStore>) => Observable<KheopskitState>;
|
|
281
292
|
|
|
282
|
-
export { type CachedAccount, type CachedWallet, DEFAULT_STORAGE_KEY, type EthereumAccount, type EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, type KheopskitConfig, type KheopskitState, type PolkadotAccount, type PolkadotAppKitWallet, type PolkadotInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, clearAllCachedObservables, clearCachedObservable, createKheopskitStore, getCachedIcon, getDefaultStore, getKheopskit$, getSafeLocalStorage, hydrateAccount, hydrateWallet, resetAppKitCache, resolveConfig };
|
|
293
|
+
export { type CachedAccount, type CachedWallet, DEFAULT_STORAGE_KEY, type EthereumAccount, type EthereumAppKitWallet, type EthereumInjectedWallet, type EthereumWallet, type KheopskitConfig, type KheopskitState, type PolkadotAccount, type PolkadotAccountType, type PolkadotAppKitWallet, type PolkadotInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, clearAllCachedObservables, clearCachedObservable, createKheopskitStore, getCachedIcon, getDefaultStore, getKheopskit$, getSafeLocalStorage, hydrateAccount, hydrateWallet, resetAppKitCache, resolveConfig };
|
package/dist/index.js
CHANGED
|
@@ -152,6 +152,7 @@ var hydrateAccount = (cached) => {
|
|
|
152
152
|
return {
|
|
153
153
|
id: cached.id,
|
|
154
154
|
platform: "polkadot",
|
|
155
|
+
type: cached.polkadotAccountType ?? "sr25519",
|
|
155
156
|
address: cached.address,
|
|
156
157
|
name: cached.name,
|
|
157
158
|
walletId: cached.walletId,
|
|
@@ -190,6 +191,7 @@ var serializeAccount = (account) => ({
|
|
|
190
191
|
address: account.address,
|
|
191
192
|
name: "name" in account ? account.name : void 0,
|
|
192
193
|
chainId: account.platform === "ethereum" ? account.chainId : void 0,
|
|
194
|
+
polkadotAccountType: account.platform === "polkadot" ? account.type : void 0,
|
|
193
195
|
walletId: account.walletId,
|
|
194
196
|
walletName: account.walletName
|
|
195
197
|
});
|
|
@@ -469,12 +471,28 @@ var DEFAULT_STORAGE_KEY = "kheopskit";
|
|
|
469
471
|
var DEFAULT_CONFIG = {
|
|
470
472
|
autoReconnect: true,
|
|
471
473
|
platforms: ["polkadot"],
|
|
474
|
+
polkadotAccountTypes: ["sr25519", "ed25519", "ecdsa"],
|
|
472
475
|
debug: false,
|
|
473
476
|
storageKey: DEFAULT_STORAGE_KEY,
|
|
474
477
|
hydrationGracePeriod: 500
|
|
475
478
|
};
|
|
479
|
+
var VALID_POLKADOT_ACCOUNT_TYPES = /* @__PURE__ */ new Set([
|
|
480
|
+
"sr25519",
|
|
481
|
+
"ed25519",
|
|
482
|
+
"ecdsa",
|
|
483
|
+
"ethereum"
|
|
484
|
+
]);
|
|
476
485
|
var resolveConfig = (config) => {
|
|
477
|
-
|
|
486
|
+
const resolved = Object.assign({}, DEFAULT_CONFIG, config);
|
|
487
|
+
const invalid = resolved.polkadotAccountTypes.filter(
|
|
488
|
+
(t) => !VALID_POLKADOT_ACCOUNT_TYPES.has(t)
|
|
489
|
+
);
|
|
490
|
+
if (invalid.length > 0) {
|
|
491
|
+
console.warn(
|
|
492
|
+
`[kheopskit] Unknown polkadotAccountTypes: ${JSON.stringify(invalid)}. Valid values: "sr25519", "ed25519", "ecdsa", "ethereum".`
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
return resolved;
|
|
478
496
|
};
|
|
479
497
|
|
|
480
498
|
// src/api/kheopskit.ts
|
|
@@ -886,6 +904,7 @@ var getInjectedWalletAccounts$2 = (wallet) => {
|
|
|
886
904
|
const getAccount = (account) => ({
|
|
887
905
|
id: getWalletAccountId(wallet.id, account.address),
|
|
888
906
|
...account,
|
|
907
|
+
type: account.type ?? "sr25519",
|
|
889
908
|
platform: "polkadot",
|
|
890
909
|
walletName: wallet.name,
|
|
891
910
|
walletId: wallet.id
|
|
@@ -955,12 +974,19 @@ var getAppKitAccounts$2 = (wallet) => {
|
|
|
955
974
|
polkadotSigner: getAppKitPolkadotSigner(wallet.appKit, acc.address),
|
|
956
975
|
genesisHash: null,
|
|
957
976
|
name: `${wallet.name} Polkadot`,
|
|
977
|
+
// WalletConnect (Reown AppKit) doesn't expose account key type;
|
|
978
|
+
// default to sr25519, which is the most common Polkadot key type.
|
|
958
979
|
type: "sr25519"
|
|
959
980
|
})
|
|
960
981
|
)
|
|
961
982
|
);
|
|
962
983
|
};
|
|
963
|
-
var getPolkadotAccounts$ = (polkadotWallets
|
|
984
|
+
var getPolkadotAccounts$ = (polkadotWallets$, polkadotAccountTypes) => new import_rxjs6.Observable((subscriber) => {
|
|
985
|
+
if (polkadotAccountTypes.length === 0) {
|
|
986
|
+
console.warn(
|
|
987
|
+
"[kheopskit] config.polkadotAccountTypes is empty; all Polkadot accounts will be filtered out."
|
|
988
|
+
);
|
|
989
|
+
}
|
|
964
990
|
const sub = polkadotWallets$.pipe(
|
|
965
991
|
(0, import_rxjs6.map)((wallets) => wallets.filter((w) => w.isConnected)),
|
|
966
992
|
(0, import_rxjs6.switchMap)(
|
|
@@ -969,7 +995,9 @@ var getPolkadotAccounts$ = (polkadotWallets$) => new import_rxjs6.Observable((su
|
|
|
969
995
|
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$2)
|
|
970
996
|
]) : (0, import_rxjs6.of)([])
|
|
971
997
|
),
|
|
972
|
-
(0, import_rxjs6.map)(
|
|
998
|
+
(0, import_rxjs6.map)(
|
|
999
|
+
(accounts) => accounts.flat().filter((account) => polkadotAccountTypes.includes(account.type))
|
|
1000
|
+
),
|
|
973
1001
|
(0, import_rxjs6.distinctUntilChanged)(isSameAccountsList2)
|
|
974
1002
|
).subscribe(subscriber);
|
|
975
1003
|
return () => {
|
|
@@ -991,7 +1019,8 @@ var getAccounts$ = (config, wallets) => {
|
|
|
991
1019
|
return getPolkadotAccounts$(
|
|
992
1020
|
wallets.pipe(
|
|
993
1021
|
(0, import_rxjs7.map)((w) => w.filter((w2) => w2.platform === "polkadot"))
|
|
994
|
-
)
|
|
1022
|
+
),
|
|
1023
|
+
config.polkadotAccountTypes
|
|
995
1024
|
);
|
|
996
1025
|
case "ethereum":
|
|
997
1026
|
return getEthereumAccounts$(
|
|
@@ -1015,6 +1044,34 @@ var getAccounts$ = (config, wallets) => {
|
|
|
1015
1044
|
// src/api/store.ts
|
|
1016
1045
|
var import_lodash_es = require("lodash-es");
|
|
1017
1046
|
var DEFAULT_SETTINGS = {};
|
|
1047
|
+
var toCompactPolkadotAccountType = (type) => {
|
|
1048
|
+
switch (type) {
|
|
1049
|
+
case "sr25519":
|
|
1050
|
+
return 0;
|
|
1051
|
+
case "ed25519":
|
|
1052
|
+
return 1;
|
|
1053
|
+
case "ecdsa":
|
|
1054
|
+
return 2;
|
|
1055
|
+
case "ethereum":
|
|
1056
|
+
return 3;
|
|
1057
|
+
default:
|
|
1058
|
+
return null;
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
var fromCompactPolkadotAccountType = (type) => {
|
|
1062
|
+
switch (type) {
|
|
1063
|
+
case 0:
|
|
1064
|
+
return "sr25519";
|
|
1065
|
+
case 1:
|
|
1066
|
+
return "ed25519";
|
|
1067
|
+
case 2:
|
|
1068
|
+
return "ecdsa";
|
|
1069
|
+
case 3:
|
|
1070
|
+
return "ethereum";
|
|
1071
|
+
default:
|
|
1072
|
+
return void 0;
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1018
1075
|
var createKheopskitStore = (options = {}) => {
|
|
1019
1076
|
const { ssrCookies, storageKey = DEFAULT_STORAGE_KEY } = options;
|
|
1020
1077
|
const storage = ssrCookies !== void 0 ? createCompactCookieStorage(ssrCookies) : safeLocalStorage;
|
|
@@ -1091,7 +1148,8 @@ var toCompactStore = (data) => {
|
|
|
1091
1148
|
account.walletId,
|
|
1092
1149
|
account.address,
|
|
1093
1150
|
account.name ?? null,
|
|
1094
|
-
account.chainId ?? null
|
|
1151
|
+
account.chainId ?? null,
|
|
1152
|
+
toCompactPolkadotAccountType(account.polkadotAccountType)
|
|
1095
1153
|
]
|
|
1096
1154
|
);
|
|
1097
1155
|
return {
|
|
@@ -1116,7 +1174,7 @@ var fromCompactStore = (data) => {
|
|
|
1116
1174
|
};
|
|
1117
1175
|
});
|
|
1118
1176
|
const accounts = (data.a ?? []).map((item) => {
|
|
1119
|
-
const [walletId, address, name, chainId] = item;
|
|
1177
|
+
const [walletId, address, name, chainId, polkadotAccountType] = item;
|
|
1120
1178
|
const { platform } = parseWalletId(walletId);
|
|
1121
1179
|
return {
|
|
1122
1180
|
id: getWalletAccountId(walletId, address),
|
|
@@ -1124,6 +1182,7 @@ var fromCompactStore = (data) => {
|
|
|
1124
1182
|
address,
|
|
1125
1183
|
name: name ?? void 0,
|
|
1126
1184
|
chainId: chainId ?? void 0,
|
|
1185
|
+
polkadotAccountType: platform === "polkadot" ? fromCompactPolkadotAccountType(polkadotAccountType) : void 0,
|
|
1127
1186
|
walletId,
|
|
1128
1187
|
walletName: walletNameMap.get(walletId) ?? walletId
|
|
1129
1188
|
};
|
|
@@ -1453,7 +1512,9 @@ var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
|
1453
1512
|
}
|
|
1454
1513
|
return wallet;
|
|
1455
1514
|
});
|
|
1456
|
-
const cachedAccounts = cachedState.accounts.map(hydrateAccount)
|
|
1515
|
+
const cachedAccounts = cachedState.accounts.map(hydrateAccount).filter(
|
|
1516
|
+
(account) => account.platform !== "polkadot" || kc.polkadotAccountTypes.includes(account.type)
|
|
1517
|
+
);
|
|
1457
1518
|
if (kc.debug && cachedWallets.length > 0) {
|
|
1458
1519
|
console.debug("[kheopskit] hydrating from cache:", {
|
|
1459
1520
|
wallets: cachedWallets.length,
|