@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.mjs
CHANGED
|
@@ -105,6 +105,7 @@ var hydrateAccount = (cached) => {
|
|
|
105
105
|
return {
|
|
106
106
|
id: cached.id,
|
|
107
107
|
platform: "polkadot",
|
|
108
|
+
type: cached.polkadotAccountType ?? "sr25519",
|
|
108
109
|
address: cached.address,
|
|
109
110
|
name: cached.name,
|
|
110
111
|
walletId: cached.walletId,
|
|
@@ -143,6 +144,7 @@ var serializeAccount = (account) => ({
|
|
|
143
144
|
address: account.address,
|
|
144
145
|
name: "name" in account ? account.name : void 0,
|
|
145
146
|
chainId: account.platform === "ethereum" ? account.chainId : void 0,
|
|
147
|
+
polkadotAccountType: account.platform === "polkadot" ? account.type : void 0,
|
|
146
148
|
walletId: account.walletId,
|
|
147
149
|
walletName: account.walletName
|
|
148
150
|
});
|
|
@@ -432,12 +434,28 @@ var DEFAULT_STORAGE_KEY = "kheopskit";
|
|
|
432
434
|
var DEFAULT_CONFIG = {
|
|
433
435
|
autoReconnect: true,
|
|
434
436
|
platforms: ["polkadot"],
|
|
437
|
+
polkadotAccountTypes: ["sr25519", "ed25519", "ecdsa"],
|
|
435
438
|
debug: false,
|
|
436
439
|
storageKey: DEFAULT_STORAGE_KEY,
|
|
437
440
|
hydrationGracePeriod: 500
|
|
438
441
|
};
|
|
442
|
+
var VALID_POLKADOT_ACCOUNT_TYPES = /* @__PURE__ */ new Set([
|
|
443
|
+
"sr25519",
|
|
444
|
+
"ed25519",
|
|
445
|
+
"ecdsa",
|
|
446
|
+
"ethereum"
|
|
447
|
+
]);
|
|
439
448
|
var resolveConfig = (config) => {
|
|
440
|
-
|
|
449
|
+
const resolved = Object.assign({}, DEFAULT_CONFIG, config);
|
|
450
|
+
const invalid = resolved.polkadotAccountTypes.filter(
|
|
451
|
+
(t) => !VALID_POLKADOT_ACCOUNT_TYPES.has(t)
|
|
452
|
+
);
|
|
453
|
+
if (invalid.length > 0) {
|
|
454
|
+
console.warn(
|
|
455
|
+
`[kheopskit] Unknown polkadotAccountTypes: ${JSON.stringify(invalid)}. Valid values: "sr25519", "ed25519", "ecdsa", "ethereum".`
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
return resolved;
|
|
441
459
|
};
|
|
442
460
|
|
|
443
461
|
// src/api/kheopskit.ts
|
|
@@ -892,6 +910,7 @@ var getInjectedWalletAccounts$2 = (wallet) => {
|
|
|
892
910
|
const getAccount = (account) => ({
|
|
893
911
|
id: getWalletAccountId(wallet.id, account.address),
|
|
894
912
|
...account,
|
|
913
|
+
type: account.type ?? "sr25519",
|
|
895
914
|
platform: "polkadot",
|
|
896
915
|
walletName: wallet.name,
|
|
897
916
|
walletId: wallet.id
|
|
@@ -961,12 +980,19 @@ var getAppKitAccounts$2 = (wallet) => {
|
|
|
961
980
|
polkadotSigner: getAppKitPolkadotSigner(wallet.appKit, acc.address),
|
|
962
981
|
genesisHash: null,
|
|
963
982
|
name: `${wallet.name} Polkadot`,
|
|
983
|
+
// WalletConnect (Reown AppKit) doesn't expose account key type;
|
|
984
|
+
// default to sr25519, which is the most common Polkadot key type.
|
|
964
985
|
type: "sr25519"
|
|
965
986
|
})
|
|
966
987
|
)
|
|
967
988
|
);
|
|
968
989
|
};
|
|
969
|
-
var getPolkadotAccounts$ = (polkadotWallets
|
|
990
|
+
var getPolkadotAccounts$ = (polkadotWallets$, polkadotAccountTypes) => new Observable4((subscriber) => {
|
|
991
|
+
if (polkadotAccountTypes.length === 0) {
|
|
992
|
+
console.warn(
|
|
993
|
+
"[kheopskit] config.polkadotAccountTypes is empty; all Polkadot accounts will be filtered out."
|
|
994
|
+
);
|
|
995
|
+
}
|
|
970
996
|
const sub = polkadotWallets$.pipe(
|
|
971
997
|
map4((wallets) => wallets.filter((w) => w.isConnected)),
|
|
972
998
|
switchMap3(
|
|
@@ -975,7 +1001,9 @@ var getPolkadotAccounts$ = (polkadotWallets$) => new Observable4((subscriber) =>
|
|
|
975
1001
|
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$2)
|
|
976
1002
|
]) : of3([])
|
|
977
1003
|
),
|
|
978
|
-
map4(
|
|
1004
|
+
map4(
|
|
1005
|
+
(accounts) => accounts.flat().filter((account) => polkadotAccountTypes.includes(account.type))
|
|
1006
|
+
),
|
|
979
1007
|
distinctUntilChanged3(isSameAccountsList2)
|
|
980
1008
|
).subscribe(subscriber);
|
|
981
1009
|
return () => {
|
|
@@ -997,7 +1025,8 @@ var getAccounts$ = (config, wallets) => {
|
|
|
997
1025
|
return getPolkadotAccounts$(
|
|
998
1026
|
wallets.pipe(
|
|
999
1027
|
map5((w) => w.filter((w2) => w2.platform === "polkadot"))
|
|
1000
|
-
)
|
|
1028
|
+
),
|
|
1029
|
+
config.polkadotAccountTypes
|
|
1001
1030
|
);
|
|
1002
1031
|
case "ethereum":
|
|
1003
1032
|
return getEthereumAccounts$(
|
|
@@ -1021,6 +1050,34 @@ var getAccounts$ = (config, wallets) => {
|
|
|
1021
1050
|
// src/api/store.ts
|
|
1022
1051
|
import { uniq } from "lodash-es";
|
|
1023
1052
|
var DEFAULT_SETTINGS = {};
|
|
1053
|
+
var toCompactPolkadotAccountType = (type) => {
|
|
1054
|
+
switch (type) {
|
|
1055
|
+
case "sr25519":
|
|
1056
|
+
return 0;
|
|
1057
|
+
case "ed25519":
|
|
1058
|
+
return 1;
|
|
1059
|
+
case "ecdsa":
|
|
1060
|
+
return 2;
|
|
1061
|
+
case "ethereum":
|
|
1062
|
+
return 3;
|
|
1063
|
+
default:
|
|
1064
|
+
return null;
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
var fromCompactPolkadotAccountType = (type) => {
|
|
1068
|
+
switch (type) {
|
|
1069
|
+
case 0:
|
|
1070
|
+
return "sr25519";
|
|
1071
|
+
case 1:
|
|
1072
|
+
return "ed25519";
|
|
1073
|
+
case 2:
|
|
1074
|
+
return "ecdsa";
|
|
1075
|
+
case 3:
|
|
1076
|
+
return "ethereum";
|
|
1077
|
+
default:
|
|
1078
|
+
return void 0;
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1024
1081
|
var createKheopskitStore = (options = {}) => {
|
|
1025
1082
|
const { ssrCookies, storageKey = DEFAULT_STORAGE_KEY } = options;
|
|
1026
1083
|
const storage = ssrCookies !== void 0 ? createCompactCookieStorage(ssrCookies) : safeLocalStorage;
|
|
@@ -1097,7 +1154,8 @@ var toCompactStore = (data) => {
|
|
|
1097
1154
|
account.walletId,
|
|
1098
1155
|
account.address,
|
|
1099
1156
|
account.name ?? null,
|
|
1100
|
-
account.chainId ?? null
|
|
1157
|
+
account.chainId ?? null,
|
|
1158
|
+
toCompactPolkadotAccountType(account.polkadotAccountType)
|
|
1101
1159
|
]
|
|
1102
1160
|
);
|
|
1103
1161
|
return {
|
|
@@ -1122,7 +1180,7 @@ var fromCompactStore = (data) => {
|
|
|
1122
1180
|
};
|
|
1123
1181
|
});
|
|
1124
1182
|
const accounts = (data.a ?? []).map((item) => {
|
|
1125
|
-
const [walletId, address, name, chainId] = item;
|
|
1183
|
+
const [walletId, address, name, chainId, polkadotAccountType] = item;
|
|
1126
1184
|
const { platform } = parseWalletId(walletId);
|
|
1127
1185
|
return {
|
|
1128
1186
|
id: getWalletAccountId(walletId, address),
|
|
@@ -1130,6 +1188,7 @@ var fromCompactStore = (data) => {
|
|
|
1130
1188
|
address,
|
|
1131
1189
|
name: name ?? void 0,
|
|
1132
1190
|
chainId: chainId ?? void 0,
|
|
1191
|
+
polkadotAccountType: platform === "polkadot" ? fromCompactPolkadotAccountType(polkadotAccountType) : void 0,
|
|
1133
1192
|
walletId,
|
|
1134
1193
|
walletName: walletNameMap.get(walletId) ?? walletId
|
|
1135
1194
|
};
|
|
@@ -1488,7 +1547,9 @@ var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
|
1488
1547
|
}
|
|
1489
1548
|
return wallet;
|
|
1490
1549
|
});
|
|
1491
|
-
const cachedAccounts = cachedState.accounts.map(hydrateAccount)
|
|
1550
|
+
const cachedAccounts = cachedState.accounts.map(hydrateAccount).filter(
|
|
1551
|
+
(account) => account.platform !== "polkadot" || kc.polkadotAccountTypes.includes(account.type)
|
|
1552
|
+
);
|
|
1492
1553
|
if (kc.debug && cachedWallets.length > 0) {
|
|
1493
1554
|
console.debug("[kheopskit] hydrating from cache:", {
|
|
1494
1555
|
wallets: cachedWallets.length,
|