@kheopskit/core 5.2.0 → 5.3.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 (46) hide show
  1. package/README.md +1 -0
  2. package/dist/{errors-Caq2csKx.mjs → errors-BLFP1dQI.mjs} +5 -5
  3. package/dist/{errors-Caq2csKx.mjs.map → errors-BLFP1dQI.mjs.map} +1 -1
  4. package/dist/{errors-DPw6pc2H.js → errors-DYWVPHrR.js} +5 -5
  5. package/dist/errors-DYWVPHrR.js.map +1 -0
  6. package/dist/ethereum.d.mts +4 -4
  7. package/dist/ethereum.d.ts +4 -4
  8. package/dist/ethereum.js +2 -2
  9. package/dist/ethereum.js.map +1 -1
  10. package/dist/ethereum.mjs +2 -2
  11. package/dist/{iconCache-CicUSbR1.js → iconCache-DUtkJlaX.js} +2 -2
  12. package/dist/{iconCache-CicUSbR1.js.map → iconCache-DUtkJlaX.js.map} +1 -1
  13. package/dist/{iconCache-Cml-6Rft.mjs → iconCache-pP2ES4pJ.mjs} +2 -2
  14. package/dist/{iconCache-Cml-6Rft.mjs.map → iconCache-pP2ES4pJ.mjs.map} +1 -1
  15. package/dist/index.d.mts +12 -12
  16. package/dist/index.d.ts +12 -12
  17. package/dist/index.js +4 -3
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +4 -3
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/{injectedWallets-B1MCxAE9.js → injectedWallets-BqR-_aAy.js} +2 -2
  22. package/dist/injectedWallets-BqR-_aAy.js.map +1 -0
  23. package/dist/{injectedWallets-B3Vysfvr.mjs → injectedWallets-Uz4hPuoW.mjs} +2 -2
  24. package/dist/{injectedWallets-B3Vysfvr.mjs.map → injectedWallets-Uz4hPuoW.mjs.map} +1 -1
  25. package/dist/internal.d.mts +6 -6
  26. package/dist/internal.d.ts +6 -6
  27. package/dist/internal.js +1 -1
  28. package/dist/internal.mjs +1 -1
  29. package/dist/polkadot.d.mts +4 -4
  30. package/dist/polkadot.d.ts +4 -4
  31. package/dist/polkadot.js +6 -6
  32. package/dist/polkadot.js.map +1 -1
  33. package/dist/polkadot.mjs +5 -5
  34. package/dist/polkadot.mjs.map +1 -1
  35. package/dist/solana.d.mts +7 -7
  36. package/dist/solana.d.ts +7 -7
  37. package/dist/solana.js +2 -2
  38. package/dist/solana.js.map +1 -1
  39. package/dist/solana.mjs +2 -2
  40. package/dist/{types-Cb-vuEru.d.ts → types-AxUDtkR-.d.mts} +9 -1
  41. package/dist/{types-Cb-vuEru.d.mts → types-AxUDtkR-.d.ts} +9 -1
  42. package/dist/types-DKU-SNio.js.map +1 -1
  43. package/dist/types-jnifAAA0.mjs.map +1 -1
  44. package/package.json +8 -8
  45. package/dist/errors-DPw6pc2H.js.map +0 -1
  46. package/dist/injectedWallets-B1MCxAE9.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { _ as WalletConnectWallet, a as CachedAccount, i as BaseWalletAccount, o as CachedWallet, r as BaseWallet } from "./types-Cb-vuEru.mjs";
1
+ import { _ as WalletConnectWallet, a as CachedAccount, i as BaseWalletAccount, o as CachedWallet, r as BaseWallet } from "./types-AxUDtkR-.mjs";
2
2
  import { n as clearCachedObservable, r as clearCachedObservablesByPrefix } from "./getCachedObservable-LUq9IfEx.mjs";
3
3
  //#region src/utils/storage.d.ts
4
4
  type Storage = {
@@ -23,21 +23,21 @@ type SyncableStorage = Storage & {
23
23
  *
24
24
  * Lazily initialized on first access to be SSR-safe.
25
25
  */
26
- declare const getSafeLocalStorage: () => SyncableStorage;
26
+ export declare const getSafeLocalStorage: () => SyncableStorage;
27
27
  //#endregion
28
28
  //#region src/utils/hydrateState.d.ts
29
29
  /**
30
30
  * Converts a wallet to a CachedWallet for storage.
31
31
  * Only extracts the serializable properties needed for hydration.
32
32
  */
33
- declare const serializeWallet: (wallet: BaseWallet | WalletConnectWallet) => CachedWallet;
33
+ export declare const serializeWallet: (wallet: BaseWallet | WalletConnectWallet) => CachedWallet;
34
34
  /**
35
35
  * Converts an account to a CachedAccount for storage.
36
36
  * Only extracts the serializable properties needed for hydration. Platform-only
37
37
  * fields (Ethereum chainId, Polkadot key type) are read defensively so this
38
38
  * stays SDK-free.
39
39
  */
40
- declare const serializeAccount: (account: BaseWalletAccount) => CachedAccount;
40
+ export declare const serializeAccount: (account: BaseWalletAccount) => CachedAccount;
41
41
  //#endregion
42
42
  //#region src/utils/iconCache.d.ts
43
43
  /**
@@ -45,7 +45,7 @@ declare const serializeAccount: (account: BaseWalletAccount) => CachedAccount;
45
45
  * More efficient than calling setCachedIcon multiple times.
46
46
  * @param icons - Map of wallet ID to icon
47
47
  */
48
- declare const setCachedIcons: (icons: Record<string, string>) => void;
48
+ export declare const setCachedIcons: (icons: Record<string, string>) => void;
49
49
  //#endregion
50
- export { clearCachedObservable, clearCachedObservablesByPrefix, getSafeLocalStorage, serializeAccount, serializeWallet, setCachedIcons };
50
+ export { clearCachedObservable, clearCachedObservablesByPrefix };
51
51
  //# sourceMappingURL=internal.d.mts.map
@@ -1,4 +1,4 @@
1
- import { _ as WalletConnectWallet, a as CachedAccount, i as BaseWalletAccount, o as CachedWallet, r as BaseWallet } from "./types-Cb-vuEru.js";
1
+ import { _ as WalletConnectWallet, a as CachedAccount, i as BaseWalletAccount, o as CachedWallet, r as BaseWallet } from "./types-AxUDtkR-.js";
2
2
  import { n as clearCachedObservable, r as clearCachedObservablesByPrefix } from "./getCachedObservable-LUq9IfEx.js";
3
3
  //#region src/utils/storage.d.ts
4
4
  type Storage = {
@@ -23,21 +23,21 @@ type SyncableStorage = Storage & {
23
23
  *
24
24
  * Lazily initialized on first access to be SSR-safe.
25
25
  */
26
- declare const getSafeLocalStorage: () => SyncableStorage;
26
+ export declare const getSafeLocalStorage: () => SyncableStorage;
27
27
  //#endregion
28
28
  //#region src/utils/hydrateState.d.ts
29
29
  /**
30
30
  * Converts a wallet to a CachedWallet for storage.
31
31
  * Only extracts the serializable properties needed for hydration.
32
32
  */
33
- declare const serializeWallet: (wallet: BaseWallet | WalletConnectWallet) => CachedWallet;
33
+ export declare const serializeWallet: (wallet: BaseWallet | WalletConnectWallet) => CachedWallet;
34
34
  /**
35
35
  * Converts an account to a CachedAccount for storage.
36
36
  * Only extracts the serializable properties needed for hydration. Platform-only
37
37
  * fields (Ethereum chainId, Polkadot key type) are read defensively so this
38
38
  * stays SDK-free.
39
39
  */
40
- declare const serializeAccount: (account: BaseWalletAccount) => CachedAccount;
40
+ export declare const serializeAccount: (account: BaseWalletAccount) => CachedAccount;
41
41
  //#endregion
42
42
  //#region src/utils/iconCache.d.ts
43
43
  /**
@@ -45,7 +45,7 @@ declare const serializeAccount: (account: BaseWalletAccount) => CachedAccount;
45
45
  * More efficient than calling setCachedIcon multiple times.
46
46
  * @param icons - Map of wallet ID to icon
47
47
  */
48
- declare const setCachedIcons: (icons: Record<string, string>) => void;
48
+ export declare const setCachedIcons: (icons: Record<string, string>) => void;
49
49
  //#endregion
50
- export { clearCachedObservable, clearCachedObservablesByPrefix, getSafeLocalStorage, serializeAccount, serializeWallet, setCachedIcons };
50
+ export { clearCachedObservable, clearCachedObservablesByPrefix };
51
51
  //# sourceMappingURL=internal.d.ts.map
package/dist/internal.js CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_types = require("./types-DKU-SNio.js");
3
- const require_iconCache = require("./iconCache-CicUSbR1.js");
3
+ const require_iconCache = require("./iconCache-DUtkJlaX.js");
4
4
  exports.clearCachedObservable = require_types.clearCachedObservable;
5
5
  exports.clearCachedObservablesByPrefix = require_types.clearCachedObservablesByPrefix;
6
6
  exports.getSafeLocalStorage = require_iconCache.getSafeLocalStorage;
package/dist/internal.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import { l as clearCachedObservable, u as clearCachedObservablesByPrefix } from "./types-jnifAAA0.mjs";
2
- import { c as serializeAccount, i as getSafeLocalStorage, l as serializeWallet, n as setCachedIcons } from "./iconCache-Cml-6Rft.mjs";
2
+ import { c as serializeAccount, i as getSafeLocalStorage, l as serializeWallet, n as setCachedIcons } from "./iconCache-pP2ES4pJ.mjs";
3
3
  export { clearCachedObservable, clearCachedObservablesByPrefix, getSafeLocalStorage, serializeAccount, serializeWallet, setCachedIcons };
@@ -1,4 +1,4 @@
1
- import { C as WalletId, D as WalletAccountId, S as isWalletConnectWallet, _ as WalletConnectWallet, c as KheopskitPlatform, p as PolkadotAccountType, x as isInjectedWallet } from "./types-Cb-vuEru.mjs";
1
+ import { C as WalletId, D as WalletAccountId, S as isWalletConnectWallet, _ as WalletConnectWallet, c as KheopskitPlatform, p as PolkadotAccountType, x as isInjectedWallet } from "./types-AxUDtkR-.mjs";
2
2
  import { InjectedExtension, InjectedPolkadotAccount } from "polkadot-api/pjs-signer";
3
3
  //#region src/utils/isSs58Address.d.ts
4
4
  /**
@@ -8,7 +8,7 @@ import { InjectedExtension, InjectedPolkadotAccount } from "polkadot-api/pjs-sig
8
8
  * Dependency-free (base58 via @scure/base, blake2b via @noble/hashes) so core
9
9
  * stays decoupled from polkadot-api.
10
10
  */
11
- declare const isSs58Address: (address: string) => boolean;
11
+ export declare const isSs58Address: (address: string) => boolean;
12
12
  //#endregion
13
13
  //#region src/api/polkadot/types.d.ts
14
14
  type PolkadotInjectedWallet = {
@@ -68,7 +68,7 @@ type PolkadotPluginOptions = {
68
68
  * polkadot({ accountTypes: ["sr25519", "ed25519", "ecdsa"] });
69
69
  * ```
70
70
  */
71
- declare const polkadot: (options?: PolkadotPluginOptions) => KheopskitPlatform<"polkadot", PolkadotWallet, PolkadotAccount>;
71
+ export declare const polkadot: (options?: PolkadotPluginOptions) => KheopskitPlatform<"polkadot", PolkadotWallet, PolkadotAccount>;
72
72
  //#endregion
73
- export { type PolkadotAccount, type PolkadotAccountType, type PolkadotInjectedWallet, type PolkadotPluginOptions, type PolkadotWallet, type WalletConnectWallet, isInjectedWallet, isSs58Address, isWalletConnectWallet, polkadot };
73
+ export { type PolkadotAccount, type PolkadotAccountType, type PolkadotInjectedWallet, type PolkadotPluginOptions, type PolkadotWallet, type WalletConnectWallet, isInjectedWallet, isWalletConnectWallet };
74
74
  //# sourceMappingURL=polkadot.d.mts.map
@@ -1,4 +1,4 @@
1
- import { C as WalletId, D as WalletAccountId, S as isWalletConnectWallet, _ as WalletConnectWallet, c as KheopskitPlatform, p as PolkadotAccountType, x as isInjectedWallet } from "./types-Cb-vuEru.js";
1
+ import { C as WalletId, D as WalletAccountId, S as isWalletConnectWallet, _ as WalletConnectWallet, c as KheopskitPlatform, p as PolkadotAccountType, x as isInjectedWallet } from "./types-AxUDtkR-.js";
2
2
  import { InjectedExtension, InjectedPolkadotAccount } from "polkadot-api/pjs-signer";
3
3
  //#region src/utils/isSs58Address.d.ts
4
4
  /**
@@ -8,7 +8,7 @@ import { InjectedExtension, InjectedPolkadotAccount } from "polkadot-api/pjs-sig
8
8
  * Dependency-free (base58 via @scure/base, blake2b via @noble/hashes) so core
9
9
  * stays decoupled from polkadot-api.
10
10
  */
11
- declare const isSs58Address: (address: string) => boolean;
11
+ export declare const isSs58Address: (address: string) => boolean;
12
12
  //#endregion
13
13
  //#region src/api/polkadot/types.d.ts
14
14
  type PolkadotInjectedWallet = {
@@ -68,7 +68,7 @@ type PolkadotPluginOptions = {
68
68
  * polkadot({ accountTypes: ["sr25519", "ed25519", "ecdsa"] });
69
69
  * ```
70
70
  */
71
- declare const polkadot: (options?: PolkadotPluginOptions) => KheopskitPlatform<"polkadot", PolkadotWallet, PolkadotAccount>;
71
+ export declare const polkadot: (options?: PolkadotPluginOptions) => KheopskitPlatform<"polkadot", PolkadotWallet, PolkadotAccount>;
72
72
  //#endregion
73
- export { type PolkadotAccount, type PolkadotAccountType, type PolkadotInjectedWallet, type PolkadotPluginOptions, type PolkadotWallet, type WalletConnectWallet, isInjectedWallet, isSs58Address, isWalletConnectWallet, polkadot };
73
+ export { type PolkadotAccount, type PolkadotAccountType, type PolkadotInjectedWallet, type PolkadotPluginOptions, type PolkadotWallet, type WalletConnectWallet, isInjectedWallet, isWalletConnectWallet };
74
74
  //# sourceMappingURL=polkadot.d.ts.map
package/dist/polkadot.js CHANGED
@@ -16,15 +16,15 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
23
23
  //#endregion
24
24
  const require_types = require("./types-DKU-SNio.js");
25
- const require_errors = require("./errors-DPw6pc2H.js");
25
+ const require_errors = require("./errors-DYWVPHrR.js");
26
26
  const require_polkadotExtensions = require("./polkadotExtensions-y4J9UzYl.js");
27
- const require_injectedWallets = require("./injectedWallets-B1MCxAE9.js");
27
+ const require_injectedWallets = require("./injectedWallets-BqR-_aAy.js");
28
28
  let rxjs = require("rxjs");
29
29
  let lodash_es = require("lodash-es");
30
30
  let polkadot_api_pjs_signer = require("polkadot-api/pjs-signer");
@@ -164,12 +164,12 @@ const createWalletIdsPoller$ = () => {
164
164
  bufferSize: 1
165
165
  }));
166
166
  };
167
- const getPolkadotWallets$ = (store) => require_injectedWallets.createInjectedWallets$(store, {
167
+ const getPolkadotWallets$ = (store, config) => require_injectedWallets.createInjectedWallets$(store, {
168
168
  sources$: createWalletIdsPoller$(),
169
169
  getWalletId: (walletId) => walletId,
170
170
  connect: (walletId) => {
171
171
  const { identifier } = require_types.parseWalletId(walletId);
172
- return (0, polkadot_api_pjs_signer.connectInjectedExtension)(identifier);
172
+ return (0, polkadot_api_pjs_signer.connectInjectedExtension)(identifier, config.appName || config.walletConnect?.metadata.name || window.location.hostname);
173
173
  },
174
174
  buildWallet: ({ walletId, handle, isConnected, connect, disconnect }) => {
175
175
  const { identifier } = require_types.parseWalletId(walletId);
@@ -216,7 +216,7 @@ const polkadot = (options = {}) => {
216
216
  if (invalid.length > 0) console.warn(`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: "sr25519", "ed25519", "ecdsa", "ethereum".`);
217
217
  return {
218
218
  platform: "polkadot",
219
- getWallets$: (ctx) => getPolkadotWallets$(ctx.store),
219
+ getWallets$: (ctx) => getPolkadotWallets$(ctx.store, ctx.config),
220
220
  getAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),
221
221
  acceptsCachedAccount: (cached) => accountTypes.includes(cached.polkadotAccountType ?? "sr25519")
222
222
  };
@@ -1 +1 @@
1
- {"version":3,"file":"polkadot.js","names":["Observable","getWalletAccountId","pjs","KheopskitError","getWalletConnectSessionAccounts$","getCaip10Addresses","getSessionCaip10s","createPlatformAccounts$","getWalletId","Observable","isEqual","createInjectedWallets$","parseWalletId","POLKADOT_EXTENSIONS"],"sources":["../src/api/polkadot/accounts.ts","../src/api/polkadot/wallets.ts","../src/api/polkadot/plugin.ts"],"sourcesContent":["import type {\n\tInjectedExtension,\n\tInjectedPolkadotAccount,\n\tSignPayload,\n\tSignRaw,\n} from \"polkadot-api/pjs-signer\";\nimport * as pjs from \"polkadot-api/pjs-signer\";\nimport { Observable, of } from \"rxjs\";\nimport { getWalletAccountId } from \"../../utils\";\nimport { KheopskitError } from \"../errors\";\nimport {\n\tcreatePlatformAccounts$,\n\tgetCaip10Addresses,\n\tgetSessionCaip10s,\n\tgetWalletConnectSessionAccounts$,\n} from \"../platformAccounts\";\nimport type {\n\tAppKitInstance,\n\tPolkadotAccountType,\n\tWalletConnectWallet,\n} from \"../types\";\nimport type {\n\tPolkadotAccount,\n\tPolkadotInjectedWallet,\n\tPolkadotWallet,\n} from \"./types\";\n\nconst getInjectedWalletAccounts$ = (\n\twallet: PolkadotInjectedWallet,\n): Observable<PolkadotAccount[]> => {\n\tif (!wallet.isConnected) return of([]);\n\n\treturn new Observable<PolkadotAccount[]>((subscriber) => {\n\t\tconst getAccount = (account: InjectedPolkadotAccount): PolkadotAccount => ({\n\t\t\tid: getWalletAccountId(wallet.id, account.address),\n\t\t\t...account,\n\t\t\ttype: account.type ?? \"sr25519\",\n\t\t\tplatform: \"polkadot\",\n\t\t\twalletName: wallet.name,\n\t\t\twalletId: wallet.id,\n\t\t});\n\n\t\tconst extension = wallet.extension as InjectedExtension;\n\n\t\t// subscribe to changes\n\t\tconst unsubscribe = extension.subscribe((accounts) => {\n\t\t\tsubscriber.next(accounts.map(getAccount));\n\t\t});\n\n\t\t// initial value\n\t\tsubscriber.next(extension.getAccounts().map(getAccount));\n\n\t\treturn () => {\n\t\t\treturn unsubscribe();\n\t\t};\n\t});\n};\n\ntype PjsSignerFactory = (\n\taddress: string,\n\tsignPayload: SignPayload,\n\tsignRaw: SignRaw,\n) => unknown;\n\ntype PjsSignerModule = {\n\tgetTxCreatorFromPjs?: PjsSignerFactory;\n\tgetPolkadotSignerFromPjs?: PjsSignerFactory;\n};\n\n/**\n * polkadot-api v3 replaced `polkadotSigner` (PolkadotSigner) with `txCreator`\n * (TxCreator). Which one the app's installed version provides is detected at\n * runtime so a single @kheopskit/core release supports both.\n */\nconst getPjsSignerField = (): {\n\tfield: \"txCreator\" | \"polkadotSigner\";\n\tfactory: PjsSignerFactory;\n} => {\n\tconst { getTxCreatorFromPjs, getPolkadotSignerFromPjs } =\n\t\tpjs as PjsSignerModule;\n\tif (getTxCreatorFromPjs)\n\t\treturn { field: \"txCreator\", factory: getTxCreatorFromPjs };\n\tif (getPolkadotSignerFromPjs)\n\t\treturn { field: \"polkadotSigner\", factory: getPolkadotSignerFromPjs };\n\tthrow new KheopskitError(\n\t\t\"UNSUPPORTED_VERSION\",\n\t\t\"Unsupported polkadot-api/pjs-signer version\",\n\t);\n};\n\nconst getAppKitPolkadotSigner = (appKit: AppKitInstance, address: string) => {\n\tconst provider = appKit.getProvider(\"polkadot\");\n\tif (!provider) throw new KheopskitError(\"NO_PROVIDER\", \"No provider found\");\n\tif (!provider.session)\n\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\n\tconst { field, factory } = getPjsSignerField();\n\n\tconst signer = factory(\n\t\taddress,\n\t\t(transactionPayload) => {\n\t\t\tif (!provider.session)\n\t\t\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\n\t\t\treturn provider.client.request({\n\t\t\t\ttopic: provider.session.topic,\n\t\t\t\tchainId: `polkadot:${transactionPayload.genesisHash.substring(2, 34)}`,\n\t\t\t\trequest: {\n\t\t\t\t\tmethod: \"polkadot_signTransaction\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\ttransactionPayload,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\tasync ({ address, data }) => {\n\t\t\tif (!provider.session)\n\t\t\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\t\t\tconst networks = appKit.getCaipNetworks(\"polkadot\");\n\t\t\tconst chainId = networks[0]?.caipNetworkId;\n\t\t\tif (!chainId)\n\t\t\t\tthrow new KheopskitError(\n\t\t\t\t\t\"NO_SESSION\",\n\t\t\t\t\t\"No CAIP network available for polkadot\",\n\t\t\t\t);\n\n\t\t\treturn provider.client.request({\n\t\t\t\ttopic: provider.session.topic,\n\t\t\t\tchainId,\n\t\t\t\trequest: {\n\t\t\t\t\tmethod: \"polkadot_signMessage\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\tmessage: data,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t);\n\n\treturn { [field]: signer };\n};\n\nconst getWalletConnectAccounts$ = (\n\twallet: WalletConnectWallet,\n): Observable<PolkadotAccount[]> =>\n\tgetWalletConnectSessionAccounts$({\n\t\twallet,\n\t\tplatform: \"polkadot\",\n\t\tnamespace: \"polkadot\",\n\t\tcacheKey: `accounts:${wallet.id}:polkadot:`,\n\t\tbuildAccounts: (provider) => {\n\t\t\tconst session = provider.session;\n\t\t\tif (!session) return [];\n\n\t\t\tconst addresses = getCaip10Addresses(\n\t\t\t\tgetSessionCaip10s(session, \"polkadot\"),\n\t\t\t);\n\n\t\t\treturn addresses.map(\n\t\t\t\t(address) =>\n\t\t\t\t\t({\n\t\t\t\t\t\tid: getWalletAccountId(wallet.id, address),\n\t\t\t\t\t\tplatform: \"polkadot\",\n\t\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\t...getAppKitPolkadotSigner(wallet.appKit, address),\n\t\t\t\t\t\tgenesisHash: null,\n\t\t\t\t\t\tname: `${wallet.name} Polkadot`,\n\t\t\t\t\t\t// WalletConnect (Reown AppKit) doesn't expose account key type;\n\t\t\t\t\t\t// default to sr25519, which is the most common Polkadot key type.\n\t\t\t\t\t\ttype: \"sr25519\",\n\t\t\t\t\t}) as PolkadotAccount,\n\t\t\t);\n\t\t},\n\t});\n\nexport const getPolkadotAccounts$ = (\n\tpolkadotWallets$: Observable<(PolkadotWallet | WalletConnectWallet)[]>,\n\tpolkadotAccountTypes: PolkadotAccountType[],\n) => {\n\tif (polkadotAccountTypes.length === 0) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] config.polkadotAccountTypes is empty; all Polkadot accounts will be filtered out.\",\n\t\t);\n\t}\n\n\treturn createPlatformAccounts$({\n\t\twallets$: polkadotWallets$,\n\t\tgetInjectedAccounts$: getInjectedWalletAccounts$,\n\t\tgetWalletConnectAccounts$,\n\t\tmapAccounts: (accounts) =>\n\t\t\taccounts.filter((account) => polkadotAccountTypes.includes(account.type)),\n\t});\n};\n","import { isEqual } from \"lodash-es\";\nimport {\n\tconnectInjectedExtension,\n\tgetInjectedExtensions,\n\ttype InjectedExtension,\n} from \"polkadot-api/pjs-signer\";\nimport { distinctUntilChanged, Observable, shareReplay } from \"rxjs\";\nimport { POLKADOT_EXTENSIONS } from \"../../utils/polkadotExtensions\";\nimport {\n\tgetWalletId,\n\tparseWalletId,\n\ttype WalletId,\n} from \"../../utils/WalletId\";\nimport { createInjectedWallets$ } from \"../injectedWallets\";\nimport type { KheopskitStore } from \"../store\";\nimport type { PolkadotInjectedWallet } from \"./types\";\n\nconst getInjectedWalletsIds = () =>\n\ttypeof window === \"undefined\"\n\t\t? []\n\t\t: getInjectedExtensions().map((name) => getWalletId(\"polkadot\", name));\n\n// Create a polling observable that starts immediately and polls at intervals\nconst createWalletIdsPoller$ = () => {\n\treturn new Observable<WalletId[]>((subscriber) => {\n\t\t// Emit immediately on subscribe\n\t\tsubscriber.next(getInjectedWalletsIds());\n\n\t\t// Poll at shorter intervals initially, then slow down\n\t\tconst intervals = [100, 200, 300, 500];\n\t\tlet index = 0;\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\n\t\tconst poll = () => {\n\t\t\tsubscriber.next(getInjectedWalletsIds());\n\t\t\tif (index < intervals.length) {\n\t\t\t\tconst delay = intervals[index++];\n\t\t\t\ttimer = setTimeout(poll, delay);\n\t\t\t}\n\t\t};\n\n\t\t// Start polling after first immediate emission\n\t\tif (intervals.length > 0) {\n\t\t\ttimer = setTimeout(poll, intervals[index++] ?? 100);\n\t\t}\n\n\t\treturn () => {\n\t\t\t// Cancel any pending poll so it can't fire after unsubscribe.\n\t\t\tif (timer !== undefined) clearTimeout(timer);\n\t\t};\n\t}).pipe(\n\t\tdistinctUntilChanged<WalletId[]>(isEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n};\n\n// The shared WalletConnect connector is emitted once by core (see\n// `getWallets$`), not per platform — so this returns only injected wallets.\nexport const getPolkadotWallets$ = (store: KheopskitStore) =>\n\tcreateInjectedWallets$<WalletId, PolkadotInjectedWallet, InjectedExtension>(\n\t\tstore,\n\t\t{\n\t\t\tsources$: createWalletIdsPoller$(),\n\t\t\tgetWalletId: (walletId) => walletId,\n\t\t\tconnect: (walletId) => {\n\t\t\t\tconst { identifier } = parseWalletId(walletId);\n\t\t\t\treturn connectInjectedExtension(identifier);\n\t\t\t},\n\t\t\tbuildWallet: ({ walletId, handle, isConnected, connect, disconnect }) => {\n\t\t\t\tconst { identifier } = parseWalletId(walletId);\n\t\t\t\tconst extInfo = POLKADOT_EXTENSIONS[identifier];\n\n\t\t\t\treturn {\n\t\t\t\t\tid: walletId,\n\t\t\t\t\ttype: \"injected\",\n\t\t\t\t\tplatform: \"polkadot\",\n\t\t\t\t\tname: extInfo?.name ?? identifier,\n\t\t\t\t\ticon: extInfo?.icon ?? \"\",\n\t\t\t\t\tsourceId: identifier,\n\t\t\t\t\textension: handle,\n\t\t\t\t\tisConnected,\n\t\t\t\t\tconnect,\n\t\t\t\t\tdisconnect,\n\t\t\t\t};\n\t\t\t},\n\t\t},\n\t);\n","import type {\n\tKheopskitPlatform,\n\tPlatformContext,\n\tPolkadotAccountType,\n} from \"../types\";\nimport { getPolkadotAccounts$ } from \"./accounts\";\nimport type { PolkadotAccount, PolkadotWallet } from \"./types\";\nimport { getPolkadotWallets$ } from \"./wallets\";\n\nconst DEFAULT_ACCOUNT_TYPES: PolkadotAccountType[] = [\n\t\"sr25519\",\n\t\"ed25519\",\n\t\"ecdsa\",\n];\n\nconst VALID_ACCOUNT_TYPES = new Set<string>([\n\t\"sr25519\",\n\t\"ed25519\",\n\t\"ecdsa\",\n\t\"ethereum\",\n]);\n\nexport type PolkadotPluginOptions = {\n\t/**\n\t * Allowed Polkadot account key types. Accounts with other key types are\n\t * filtered out from kheopskit state.\n\t *\n\t * @default [\"sr25519\", \"ed25519\", \"ecdsa\"]\n\t */\n\taccountTypes?: PolkadotAccountType[];\n};\n\n/**\n * Polkadot platform plugin. Pass to `getKheopskit$({ platforms: [polkadot()] })`.\n *\n * @example\n * ```ts\n * import { polkadot } from \"@kheopskit/core/polkadot\";\n * polkadot({ accountTypes: [\"sr25519\", \"ed25519\", \"ecdsa\"] });\n * ```\n */\nexport const polkadot = (\n\toptions: PolkadotPluginOptions = {},\n): KheopskitPlatform<\"polkadot\", PolkadotWallet, PolkadotAccount> => {\n\tconst accountTypes = options.accountTypes ?? DEFAULT_ACCOUNT_TYPES;\n\n\tconst invalid = accountTypes.filter((t) => !VALID_ACCOUNT_TYPES.has(t));\n\tif (invalid.length > 0) {\n\t\tconsole.warn(\n\t\t\t`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: \"sr25519\", \"ed25519\", \"ecdsa\", \"ethereum\".`,\n\t\t);\n\t}\n\n\treturn {\n\t\tplatform: \"polkadot\",\n\t\tgetWallets$: (ctx: PlatformContext) => getPolkadotWallets$(ctx.store),\n\t\tgetAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),\n\t\tacceptsCachedAccount: (cached) =>\n\t\t\taccountTypes.includes(cached.polkadotAccountType ?? \"sr25519\"),\n\t};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,8BACL,WACmC;CACnC,IAAI,CAAC,OAAO,aAAa,QAAA,GAAA,KAAA,GAAA,CAAU,CAAC,CAAC;CAErC,OAAO,IAAIA,KAAAA,YAA+B,eAAe;EACxD,MAAM,cAAc,aAAuD;GAC1E,IAAIC,eAAAA,mBAAmB,OAAO,IAAI,QAAQ,OAAO;GACjD,GAAG;GACH,MAAM,QAAQ,QAAQ;GACtB,UAAU;GACV,YAAY,OAAO;GACnB,UAAU,OAAO;EAClB;EAEA,MAAM,YAAY,OAAO;EAGzB,MAAM,cAAc,UAAU,WAAW,aAAa;GACrD,WAAW,KAAK,SAAS,IAAI,UAAU,CAAC;EACzC,CAAC;EAGD,WAAW,KAAK,UAAU,YAAY,CAAC,CAAC,IAAI,UAAU,CAAC;EAEvD,aAAa;GACZ,OAAO,YAAY;EACpB;CACD,CAAC;AACF;;;;;;AAkBA,MAAM,0BAGD;CACJ,MAAM,EAAE,qBAAqB,6BAC5BC;CACD,IAAI,qBACH,OAAO;EAAE,OAAO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AA,YAAA,CAC5B;EAAE,UAAU;EAAM,YAAY;CAAE,CAAC,CAC9C;AACD;AAIA,MAAa,uBAAuB,UACnCC,wBAAAA,uBACC,OACA;CACC,UAAU,uBAAuB;CACjC,cAAc,aAAa;CAC3B,UAAU,aAAa;EACtB,MAAM,EAAE,eAAeC,cAAAA,cAAc,QAAQ;EAC7C,QAAA,GAAA,wBAAA,yBAAA,CAAgC,UAAU;CAC3C;CACA,cAAc,EAAE,UAAU,QAAQ,aAAa,SAAS,iBAAiB;EACxE,MAAM,EAAE,eAAeA,cAAAA,cAAc,QAAQ;EAC7C,MAAM,UAAUC,2BAAAA,oBAAoB;EAEpC,OAAO;GACN,IAAI;GACJ,MAAM;GACN,UAAU;GACV,MAAM,SAAS,QAAQ;GACvB,MAAM,SAAS,QAAQ;GACvB,UAAU;GACV,WAAW;GACX;GACA;GACA;EACD;CACD;AACD,CACD;;;AC7ED,MAAM,wBAA+C;CACpD;CACA;CACA;AACD;AAEA,MAAM,sCAAsB,IAAI,IAAY;CAC3C;CACA;CACA;CACA;AACD,CAAC;;;;;;;;;;AAqBD,MAAa,YACZ,UAAiC,CAAC,MACkC;CACpE,MAAM,eAAe,QAAQ,gBAAgB;CAE7C,MAAM,UAAU,aAAa,QAAQ,MAAM,CAAC,oBAAoB,IAAI,CAAC,CAAC;CACtE,IAAI,QAAQ,SAAS,GACpB,QAAQ,KACP,8CAA8C,KAAK,UAAU,OAAO,EAAE,2DACvE;CAGD,OAAO;EACN,UAAU;EACV,cAAc,QAAyB,oBAAoB,IAAI,KAAK;EACpE,eAAe,aAAa,qBAAqB,UAAU,YAAY;EACvE,uBAAuB,WACtB,aAAa,SAAS,OAAO,uBAAuB,SAAS;CAC/D;AACD"}
1
+ {"version":3,"file":"polkadot.js","names":["of","Observable","getWalletAccountId","pjs","KheopskitError","getWalletConnectSessionAccounts$","getCaip10Addresses","getSessionCaip10s","createPlatformAccounts$","getInjectedExtensions","getWalletId","Observable","distinctUntilChanged","isEqual","shareReplay","createInjectedWallets$","parseWalletId","connectInjectedExtension","POLKADOT_EXTENSIONS"],"sources":["../src/api/polkadot/accounts.ts","../src/api/polkadot/wallets.ts","../src/api/polkadot/plugin.ts"],"sourcesContent":["import type {\n\tInjectedExtension,\n\tInjectedPolkadotAccount,\n\tSignPayload,\n\tSignRaw,\n} from \"polkadot-api/pjs-signer\";\nimport * as pjs from \"polkadot-api/pjs-signer\";\nimport { Observable, of } from \"rxjs\";\nimport { getWalletAccountId } from \"../../utils\";\nimport { KheopskitError } from \"../errors\";\nimport {\n\tcreatePlatformAccounts$,\n\tgetCaip10Addresses,\n\tgetSessionCaip10s,\n\tgetWalletConnectSessionAccounts$,\n} from \"../platformAccounts\";\nimport type {\n\tAppKitInstance,\n\tPolkadotAccountType,\n\tWalletConnectWallet,\n} from \"../types\";\nimport type {\n\tPolkadotAccount,\n\tPolkadotInjectedWallet,\n\tPolkadotWallet,\n} from \"./types\";\n\nconst getInjectedWalletAccounts$ = (\n\twallet: PolkadotInjectedWallet,\n): Observable<PolkadotAccount[]> => {\n\tif (!wallet.isConnected) return of([]);\n\n\treturn new Observable<PolkadotAccount[]>((subscriber) => {\n\t\tconst getAccount = (account: InjectedPolkadotAccount): PolkadotAccount => ({\n\t\t\tid: getWalletAccountId(wallet.id, account.address),\n\t\t\t...account,\n\t\t\ttype: account.type ?? \"sr25519\",\n\t\t\tplatform: \"polkadot\",\n\t\t\twalletName: wallet.name,\n\t\t\twalletId: wallet.id,\n\t\t});\n\n\t\tconst extension = wallet.extension as InjectedExtension;\n\n\t\t// subscribe to changes\n\t\tconst unsubscribe = extension.subscribe((accounts) => {\n\t\t\tsubscriber.next(accounts.map(getAccount));\n\t\t});\n\n\t\t// initial value\n\t\tsubscriber.next(extension.getAccounts().map(getAccount));\n\n\t\treturn () => {\n\t\t\treturn unsubscribe();\n\t\t};\n\t});\n};\n\ntype PjsSignerFactory = (\n\taddress: string,\n\tsignPayload: SignPayload,\n\tsignRaw: SignRaw,\n) => unknown;\n\ntype PjsSignerModule = {\n\tgetTxCreatorFromPjs?: PjsSignerFactory;\n\tgetPolkadotSignerFromPjs?: PjsSignerFactory;\n};\n\n/**\n * polkadot-api v3 replaced `polkadotSigner` (PolkadotSigner) with `txCreator`\n * (TxCreator). Which one the app's installed version provides is detected at\n * runtime so a single @kheopskit/core release supports both.\n */\nconst getPjsSignerField = (): {\n\tfield: \"txCreator\" | \"polkadotSigner\";\n\tfactory: PjsSignerFactory;\n} => {\n\tconst { getTxCreatorFromPjs, getPolkadotSignerFromPjs } =\n\t\tpjs as PjsSignerModule;\n\tif (getTxCreatorFromPjs)\n\t\treturn { field: \"txCreator\", factory: getTxCreatorFromPjs };\n\tif (getPolkadotSignerFromPjs)\n\t\treturn { field: \"polkadotSigner\", factory: getPolkadotSignerFromPjs };\n\tthrow new KheopskitError(\n\t\t\"UNSUPPORTED_VERSION\",\n\t\t\"Unsupported polkadot-api/pjs-signer version\",\n\t);\n};\n\nconst getAppKitPolkadotSigner = (appKit: AppKitInstance, address: string) => {\n\tconst provider = appKit.getProvider(\"polkadot\");\n\tif (!provider) throw new KheopskitError(\"NO_PROVIDER\", \"No provider found\");\n\tif (!provider.session)\n\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\n\tconst { field, factory } = getPjsSignerField();\n\n\tconst signer = factory(\n\t\taddress,\n\t\t(transactionPayload) => {\n\t\t\tif (!provider.session)\n\t\t\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\n\t\t\treturn provider.client.request({\n\t\t\t\ttopic: provider.session.topic,\n\t\t\t\tchainId: `polkadot:${transactionPayload.genesisHash.substring(2, 34)}`,\n\t\t\t\trequest: {\n\t\t\t\t\tmethod: \"polkadot_signTransaction\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\ttransactionPayload,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\tasync ({ address, data }) => {\n\t\t\tif (!provider.session)\n\t\t\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\t\t\tconst networks = appKit.getCaipNetworks(\"polkadot\");\n\t\t\tconst chainId = networks[0]?.caipNetworkId;\n\t\t\tif (!chainId)\n\t\t\t\tthrow new KheopskitError(\n\t\t\t\t\t\"NO_SESSION\",\n\t\t\t\t\t\"No CAIP network available for polkadot\",\n\t\t\t\t);\n\n\t\t\treturn provider.client.request({\n\t\t\t\ttopic: provider.session.topic,\n\t\t\t\tchainId,\n\t\t\t\trequest: {\n\t\t\t\t\tmethod: \"polkadot_signMessage\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\tmessage: data,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t);\n\n\treturn { [field]: signer };\n};\n\nconst getWalletConnectAccounts$ = (\n\twallet: WalletConnectWallet,\n): Observable<PolkadotAccount[]> =>\n\tgetWalletConnectSessionAccounts$({\n\t\twallet,\n\t\tplatform: \"polkadot\",\n\t\tnamespace: \"polkadot\",\n\t\tcacheKey: `accounts:${wallet.id}:polkadot:`,\n\t\tbuildAccounts: (provider) => {\n\t\t\tconst session = provider.session;\n\t\t\tif (!session) return [];\n\n\t\t\tconst addresses = getCaip10Addresses(\n\t\t\t\tgetSessionCaip10s(session, \"polkadot\"),\n\t\t\t);\n\n\t\t\treturn addresses.map(\n\t\t\t\t(address) =>\n\t\t\t\t\t({\n\t\t\t\t\t\tid: getWalletAccountId(wallet.id, address),\n\t\t\t\t\t\tplatform: \"polkadot\",\n\t\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\t...getAppKitPolkadotSigner(wallet.appKit, address),\n\t\t\t\t\t\tgenesisHash: null,\n\t\t\t\t\t\tname: `${wallet.name} Polkadot`,\n\t\t\t\t\t\t// WalletConnect (Reown AppKit) doesn't expose account key type;\n\t\t\t\t\t\t// default to sr25519, which is the most common Polkadot key type.\n\t\t\t\t\t\ttype: \"sr25519\",\n\t\t\t\t\t}) as PolkadotAccount,\n\t\t\t);\n\t\t},\n\t});\n\nexport const getPolkadotAccounts$ = (\n\tpolkadotWallets$: Observable<(PolkadotWallet | WalletConnectWallet)[]>,\n\tpolkadotAccountTypes: PolkadotAccountType[],\n) => {\n\tif (polkadotAccountTypes.length === 0) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] config.polkadotAccountTypes is empty; all Polkadot accounts will be filtered out.\",\n\t\t);\n\t}\n\n\treturn createPlatformAccounts$({\n\t\twallets$: polkadotWallets$,\n\t\tgetInjectedAccounts$: getInjectedWalletAccounts$,\n\t\tgetWalletConnectAccounts$,\n\t\tmapAccounts: (accounts) =>\n\t\t\taccounts.filter((account) => polkadotAccountTypes.includes(account.type)),\n\t});\n};\n","import { isEqual } from \"lodash-es\";\nimport {\n\tconnectInjectedExtension,\n\tgetInjectedExtensions,\n\ttype InjectedExtension,\n} from \"polkadot-api/pjs-signer\";\nimport { distinctUntilChanged, Observable, shareReplay } from \"rxjs\";\nimport { POLKADOT_EXTENSIONS } from \"../../utils/polkadotExtensions\";\nimport {\n\tgetWalletId,\n\tparseWalletId,\n\ttype WalletId,\n} from \"../../utils/WalletId\";\nimport { createInjectedWallets$ } from \"../injectedWallets\";\nimport type { KheopskitStore } from \"../store\";\nimport type { KheopskitConfig } from \"../types\";\nimport type { PolkadotInjectedWallet } from \"./types\";\n\nconst getInjectedWalletsIds = () =>\n\ttypeof window === \"undefined\"\n\t\t? []\n\t\t: getInjectedExtensions().map((name) => getWalletId(\"polkadot\", name));\n\n// Create a polling observable that starts immediately and polls at intervals\nconst createWalletIdsPoller$ = () => {\n\treturn new Observable<WalletId[]>((subscriber) => {\n\t\t// Emit immediately on subscribe\n\t\tsubscriber.next(getInjectedWalletsIds());\n\n\t\t// Poll at shorter intervals initially, then slow down\n\t\tconst intervals = [100, 200, 300, 500];\n\t\tlet index = 0;\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\n\t\tconst poll = () => {\n\t\t\tsubscriber.next(getInjectedWalletsIds());\n\t\t\tif (index < intervals.length) {\n\t\t\t\tconst delay = intervals[index++];\n\t\t\t\ttimer = setTimeout(poll, delay);\n\t\t\t}\n\t\t};\n\n\t\t// Start polling after first immediate emission\n\t\tif (intervals.length > 0) {\n\t\t\ttimer = setTimeout(poll, intervals[index++] ?? 100);\n\t\t}\n\n\t\treturn () => {\n\t\t\t// Cancel any pending poll so it can't fire after unsubscribe.\n\t\t\tif (timer !== undefined) clearTimeout(timer);\n\t\t};\n\t}).pipe(\n\t\tdistinctUntilChanged<WalletId[]>(isEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n};\n\n// The shared WalletConnect connector is emitted once by core (see\n// `getWallets$`), not per platform — so this returns only injected wallets.\nexport const getPolkadotWallets$ = (\n\tstore: KheopskitStore,\n\tconfig: Pick<KheopskitConfig, \"appName\" | \"walletConnect\">,\n) =>\n\tcreateInjectedWallets$<WalletId, PolkadotInjectedWallet, InjectedExtension>(\n\t\tstore,\n\t\t{\n\t\t\tsources$: createWalletIdsPoller$(),\n\t\t\tgetWalletId: (walletId) => walletId,\n\t\t\tconnect: (walletId) => {\n\t\t\t\tconst { identifier } = parseWalletId(walletId);\n\t\t\t\treturn connectInjectedExtension(\n\t\t\t\t\tidentifier,\n\t\t\t\t\tconfig.appName ||\n\t\t\t\t\t\tconfig.walletConnect?.metadata.name ||\n\t\t\t\t\t\twindow.location.hostname,\n\t\t\t\t);\n\t\t\t},\n\t\t\tbuildWallet: ({ walletId, handle, isConnected, connect, disconnect }) => {\n\t\t\t\tconst { identifier } = parseWalletId(walletId);\n\t\t\t\tconst extInfo = POLKADOT_EXTENSIONS[identifier];\n\n\t\t\t\treturn {\n\t\t\t\t\tid: walletId,\n\t\t\t\t\ttype: \"injected\",\n\t\t\t\t\tplatform: \"polkadot\",\n\t\t\t\t\tname: extInfo?.name ?? identifier,\n\t\t\t\t\ticon: extInfo?.icon ?? \"\",\n\t\t\t\t\tsourceId: identifier,\n\t\t\t\t\textension: handle,\n\t\t\t\t\tisConnected,\n\t\t\t\t\tconnect,\n\t\t\t\t\tdisconnect,\n\t\t\t\t};\n\t\t\t},\n\t\t},\n\t);\n","import type {\n\tKheopskitPlatform,\n\tPlatformContext,\n\tPolkadotAccountType,\n} from \"../types\";\nimport { getPolkadotAccounts$ } from \"./accounts\";\nimport type { PolkadotAccount, PolkadotWallet } from \"./types\";\nimport { getPolkadotWallets$ } from \"./wallets\";\n\nconst DEFAULT_ACCOUNT_TYPES: PolkadotAccountType[] = [\n\t\"sr25519\",\n\t\"ed25519\",\n\t\"ecdsa\",\n];\n\nconst VALID_ACCOUNT_TYPES = new Set<string>([\n\t\"sr25519\",\n\t\"ed25519\",\n\t\"ecdsa\",\n\t\"ethereum\",\n]);\n\nexport type PolkadotPluginOptions = {\n\t/**\n\t * Allowed Polkadot account key types. Accounts with other key types are\n\t * filtered out from kheopskit state.\n\t *\n\t * @default [\"sr25519\", \"ed25519\", \"ecdsa\"]\n\t */\n\taccountTypes?: PolkadotAccountType[];\n};\n\n/**\n * Polkadot platform plugin. Pass to `getKheopskit$({ platforms: [polkadot()] })`.\n *\n * @example\n * ```ts\n * import { polkadot } from \"@kheopskit/core/polkadot\";\n * polkadot({ accountTypes: [\"sr25519\", \"ed25519\", \"ecdsa\"] });\n * ```\n */\nexport const polkadot = (\n\toptions: PolkadotPluginOptions = {},\n): KheopskitPlatform<\"polkadot\", PolkadotWallet, PolkadotAccount> => {\n\tconst accountTypes = options.accountTypes ?? DEFAULT_ACCOUNT_TYPES;\n\n\tconst invalid = accountTypes.filter((t) => !VALID_ACCOUNT_TYPES.has(t));\n\tif (invalid.length > 0) {\n\t\tconsole.warn(\n\t\t\t`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: \"sr25519\", \"ed25519\", \"ecdsa\", \"ethereum\".`,\n\t\t);\n\t}\n\n\treturn {\n\t\tplatform: \"polkadot\",\n\t\tgetWallets$: (ctx: PlatformContext) =>\n\t\t\tgetPolkadotWallets$(ctx.store, ctx.config),\n\t\tgetAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),\n\t\tacceptsCachedAccount: (cached) =>\n\t\t\taccountTypes.includes(cached.polkadotAccountType ?? \"sr25519\"),\n\t};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,8BACL,WACmC;CACnC,IAAI,CAAC,OAAO,aAAa,QAAA,GAAOA,KAAAA,GAAAA,CAAG,CAAC,CAAC;CAErC,OAAO,IAAIC,KAAAA,YAA+B,eAAe;EACxD,MAAM,cAAc,aAAuD;GAC1E,IAAIC,eAAAA,mBAAmB,OAAO,IAAI,QAAQ,OAAO;GACjD,GAAG;GACH,MAAM,QAAQ,QAAQ;GACtB,UAAU;GACV,YAAY,OAAO;GACnB,UAAU,OAAO;EAClB;EAEA,MAAM,YAAY,OAAO;EAGzB,MAAM,cAAc,UAAU,WAAW,aAAa;GACrD,WAAW,KAAK,SAAS,IAAI,UAAU,CAAC;EACzC,CAAC;EAGD,WAAW,KAAK,UAAU,YAAY,CAAC,CAAC,IAAI,UAAU,CAAC;EAEvD,aAAa;GACZ,OAAO,YAAY;EACpB;CACD,CAAC;AACF;;;;;;AAkBA,MAAM,0BAGD;CACJ,MAAM,EAAE,qBAAqB,6BAC5BC;CACD,IAAI,qBACH,OAAO;EAAE,OAAO;EAAa,SAAS;CAAoB;CAC3D,IAAI,0BACH,OAAO;EAAE,OAAO;EAAkB,SAAS;CAAyB;CACrE,MAAM,IAAIC,eAAAA,eACT,uBACA,6CACD;AACD;AAEA,MAAM,2BAA2B,QAAwB,YAAoB;CAC5E,MAAM,WAAW,OAAO,YAAY,UAAU;CAC9C,IAAI,CAAC,UAAU,MAAM,IAAIA,eAAAA,eAAe,eAAe,mBAAmB;CAC1E,IAAI,CAAC,SAAS,SACb,MAAM,IAAIA,eAAAA,eAAe,cAAc,kBAAkB;CAE1D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EAAE,UAAU,QAAQ,aAAa,SAAS,iBAAiB;EACxE,MAAM,EAAE,eAAeD,cAAAA,cAAc,QAAQ;EAC7C,MAAM,UAAUE,2BAAAA,oBAAoB;EAEpC,OAAO;GACN,IAAI;GACJ,MAAM;GACN,UAAU;GACV,MAAM,SAAS,QAAQ;GACvB,MAAM,SAAS,QAAQ;GACvB,UAAU;GACV,WAAW;GACX;GACA;GACA;EACD;CACD;AACD,CACD;;;ACtFD,MAAM,wBAA+C;CACpD;CACA;CACA;AACD;AAEA,MAAM,sCAAsB,IAAI,IAAY;CAC3C;CACA;CACA;CACA;AACD,CAAC;;;;;;;;;;AAqBD,MAAa,YACZ,UAAiC,CAAC,MACkC;CACpE,MAAM,eAAe,QAAQ,gBAAgB;CAE7C,MAAM,UAAU,aAAa,QAAQ,MAAM,CAAC,oBAAoB,IAAI,CAAC,CAAC;CACtE,IAAI,QAAQ,SAAS,GACpB,QAAQ,KACP,8CAA8C,KAAK,UAAU,OAAO,EAAE,2DACvE;CAGD,OAAO;EACN,UAAU;EACV,cAAc,QACb,oBAAoB,IAAI,OAAO,IAAI,MAAM;EAC1C,eAAe,aAAa,qBAAqB,UAAU,YAAY;EACvE,uBAAuB,WACtB,aAAa,SAAS,OAAO,uBAAuB,SAAS;CAC/D;AACD"}
package/dist/polkadot.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { i as getWalletId, n as isWalletConnectWallet, o as parseWalletId, t as isInjectedWallet } from "./types-jnifAAA0.mjs";
2
- import { a as isSs58Address, n as getWalletAccountId, t as KheopskitError } from "./errors-Caq2csKx.mjs";
2
+ import { a as isSs58Address, n as getWalletAccountId, t as KheopskitError } from "./errors-BLFP1dQI.mjs";
3
3
  import { t as POLKADOT_EXTENSIONS } from "./polkadotExtensions-BoVKhNU_.mjs";
4
- import { a as getWalletConnectSessionAccounts$, i as getSessionCaip10s, n as createPlatformAccounts$, r as getCaip10Addresses, t as createInjectedWallets$ } from "./injectedWallets-B3Vysfvr.mjs";
4
+ import { a as getWalletConnectSessionAccounts$, i as getSessionCaip10s, n as createPlatformAccounts$, r as getCaip10Addresses, t as createInjectedWallets$ } from "./injectedWallets-Uz4hPuoW.mjs";
5
5
  import { Observable, distinctUntilChanged, of, shareReplay } from "rxjs";
6
6
  import { isEqual } from "lodash-es";
7
7
  import * as pjs from "polkadot-api/pjs-signer";
@@ -141,12 +141,12 @@ const createWalletIdsPoller$ = () => {
141
141
  bufferSize: 1
142
142
  }));
143
143
  };
144
- const getPolkadotWallets$ = (store) => createInjectedWallets$(store, {
144
+ const getPolkadotWallets$ = (store, config) => createInjectedWallets$(store, {
145
145
  sources$: createWalletIdsPoller$(),
146
146
  getWalletId: (walletId) => walletId,
147
147
  connect: (walletId) => {
148
148
  const { identifier } = parseWalletId(walletId);
149
- return connectInjectedExtension(identifier);
149
+ return connectInjectedExtension(identifier, config.appName || config.walletConnect?.metadata.name || window.location.hostname);
150
150
  },
151
151
  buildWallet: ({ walletId, handle, isConnected, connect, disconnect }) => {
152
152
  const { identifier } = parseWalletId(walletId);
@@ -193,7 +193,7 @@ const polkadot = (options = {}) => {
193
193
  if (invalid.length > 0) console.warn(`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: "sr25519", "ed25519", "ecdsa", "ethereum".`);
194
194
  return {
195
195
  platform: "polkadot",
196
- getWallets$: (ctx) => getPolkadotWallets$(ctx.store),
196
+ getWallets$: (ctx) => getPolkadotWallets$(ctx.store, ctx.config),
197
197
  getAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),
198
198
  acceptsCachedAccount: (cached) => accountTypes.includes(cached.polkadotAccountType ?? "sr25519")
199
199
  };
@@ -1 +1 @@
1
- {"version":3,"file":"polkadot.mjs","names":[],"sources":["../src/api/polkadot/accounts.ts","../src/api/polkadot/wallets.ts","../src/api/polkadot/plugin.ts"],"sourcesContent":["import type {\n\tInjectedExtension,\n\tInjectedPolkadotAccount,\n\tSignPayload,\n\tSignRaw,\n} from \"polkadot-api/pjs-signer\";\nimport * as pjs from \"polkadot-api/pjs-signer\";\nimport { Observable, of } from \"rxjs\";\nimport { getWalletAccountId } from \"../../utils\";\nimport { KheopskitError } from \"../errors\";\nimport {\n\tcreatePlatformAccounts$,\n\tgetCaip10Addresses,\n\tgetSessionCaip10s,\n\tgetWalletConnectSessionAccounts$,\n} from \"../platformAccounts\";\nimport type {\n\tAppKitInstance,\n\tPolkadotAccountType,\n\tWalletConnectWallet,\n} from \"../types\";\nimport type {\n\tPolkadotAccount,\n\tPolkadotInjectedWallet,\n\tPolkadotWallet,\n} from \"./types\";\n\nconst getInjectedWalletAccounts$ = (\n\twallet: PolkadotInjectedWallet,\n): Observable<PolkadotAccount[]> => {\n\tif (!wallet.isConnected) return of([]);\n\n\treturn new Observable<PolkadotAccount[]>((subscriber) => {\n\t\tconst getAccount = (account: InjectedPolkadotAccount): PolkadotAccount => ({\n\t\t\tid: getWalletAccountId(wallet.id, account.address),\n\t\t\t...account,\n\t\t\ttype: account.type ?? \"sr25519\",\n\t\t\tplatform: \"polkadot\",\n\t\t\twalletName: wallet.name,\n\t\t\twalletId: wallet.id,\n\t\t});\n\n\t\tconst extension = wallet.extension as InjectedExtension;\n\n\t\t// subscribe to changes\n\t\tconst unsubscribe = extension.subscribe((accounts) => {\n\t\t\tsubscriber.next(accounts.map(getAccount));\n\t\t});\n\n\t\t// initial value\n\t\tsubscriber.next(extension.getAccounts().map(getAccount));\n\n\t\treturn () => {\n\t\t\treturn unsubscribe();\n\t\t};\n\t});\n};\n\ntype PjsSignerFactory = (\n\taddress: string,\n\tsignPayload: SignPayload,\n\tsignRaw: SignRaw,\n) => unknown;\n\ntype PjsSignerModule = {\n\tgetTxCreatorFromPjs?: PjsSignerFactory;\n\tgetPolkadotSignerFromPjs?: PjsSignerFactory;\n};\n\n/**\n * polkadot-api v3 replaced `polkadotSigner` (PolkadotSigner) with `txCreator`\n * (TxCreator). Which one the app's installed version provides is detected at\n * runtime so a single @kheopskit/core release supports both.\n */\nconst getPjsSignerField = (): {\n\tfield: \"txCreator\" | \"polkadotSigner\";\n\tfactory: PjsSignerFactory;\n} => {\n\tconst { getTxCreatorFromPjs, getPolkadotSignerFromPjs } =\n\t\tpjs as PjsSignerModule;\n\tif (getTxCreatorFromPjs)\n\t\treturn { field: \"txCreator\", factory: getTxCreatorFromPjs };\n\tif (getPolkadotSignerFromPjs)\n\t\treturn { field: \"polkadotSigner\", factory: getPolkadotSignerFromPjs };\n\tthrow new KheopskitError(\n\t\t\"UNSUPPORTED_VERSION\",\n\t\t\"Unsupported polkadot-api/pjs-signer version\",\n\t);\n};\n\nconst getAppKitPolkadotSigner = (appKit: AppKitInstance, address: string) => {\n\tconst provider = appKit.getProvider(\"polkadot\");\n\tif (!provider) throw new KheopskitError(\"NO_PROVIDER\", \"No provider found\");\n\tif (!provider.session)\n\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\n\tconst { field, factory } = getPjsSignerField();\n\n\tconst signer = factory(\n\t\taddress,\n\t\t(transactionPayload) => {\n\t\t\tif (!provider.session)\n\t\t\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\n\t\t\treturn provider.client.request({\n\t\t\t\ttopic: provider.session.topic,\n\t\t\t\tchainId: `polkadot:${transactionPayload.genesisHash.substring(2, 34)}`,\n\t\t\t\trequest: {\n\t\t\t\t\tmethod: \"polkadot_signTransaction\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\ttransactionPayload,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\tasync ({ address, data }) => {\n\t\t\tif (!provider.session)\n\t\t\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\t\t\tconst networks = appKit.getCaipNetworks(\"polkadot\");\n\t\t\tconst chainId = networks[0]?.caipNetworkId;\n\t\t\tif (!chainId)\n\t\t\t\tthrow new KheopskitError(\n\t\t\t\t\t\"NO_SESSION\",\n\t\t\t\t\t\"No CAIP network available for polkadot\",\n\t\t\t\t);\n\n\t\t\treturn provider.client.request({\n\t\t\t\ttopic: provider.session.topic,\n\t\t\t\tchainId,\n\t\t\t\trequest: {\n\t\t\t\t\tmethod: \"polkadot_signMessage\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\tmessage: data,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t);\n\n\treturn { [field]: signer };\n};\n\nconst getWalletConnectAccounts$ = (\n\twallet: WalletConnectWallet,\n): Observable<PolkadotAccount[]> =>\n\tgetWalletConnectSessionAccounts$({\n\t\twallet,\n\t\tplatform: \"polkadot\",\n\t\tnamespace: \"polkadot\",\n\t\tcacheKey: `accounts:${wallet.id}:polkadot:`,\n\t\tbuildAccounts: (provider) => {\n\t\t\tconst session = provider.session;\n\t\t\tif (!session) return [];\n\n\t\t\tconst addresses = getCaip10Addresses(\n\t\t\t\tgetSessionCaip10s(session, \"polkadot\"),\n\t\t\t);\n\n\t\t\treturn addresses.map(\n\t\t\t\t(address) =>\n\t\t\t\t\t({\n\t\t\t\t\t\tid: getWalletAccountId(wallet.id, address),\n\t\t\t\t\t\tplatform: \"polkadot\",\n\t\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\t...getAppKitPolkadotSigner(wallet.appKit, address),\n\t\t\t\t\t\tgenesisHash: null,\n\t\t\t\t\t\tname: `${wallet.name} Polkadot`,\n\t\t\t\t\t\t// WalletConnect (Reown AppKit) doesn't expose account key type;\n\t\t\t\t\t\t// default to sr25519, which is the most common Polkadot key type.\n\t\t\t\t\t\ttype: \"sr25519\",\n\t\t\t\t\t}) as PolkadotAccount,\n\t\t\t);\n\t\t},\n\t});\n\nexport const getPolkadotAccounts$ = (\n\tpolkadotWallets$: Observable<(PolkadotWallet | WalletConnectWallet)[]>,\n\tpolkadotAccountTypes: PolkadotAccountType[],\n) => {\n\tif (polkadotAccountTypes.length === 0) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] config.polkadotAccountTypes is empty; all Polkadot accounts will be filtered out.\",\n\t\t);\n\t}\n\n\treturn createPlatformAccounts$({\n\t\twallets$: polkadotWallets$,\n\t\tgetInjectedAccounts$: getInjectedWalletAccounts$,\n\t\tgetWalletConnectAccounts$,\n\t\tmapAccounts: (accounts) =>\n\t\t\taccounts.filter((account) => polkadotAccountTypes.includes(account.type)),\n\t});\n};\n","import { isEqual } from \"lodash-es\";\nimport {\n\tconnectInjectedExtension,\n\tgetInjectedExtensions,\n\ttype InjectedExtension,\n} from \"polkadot-api/pjs-signer\";\nimport { distinctUntilChanged, Observable, shareReplay } from \"rxjs\";\nimport { POLKADOT_EXTENSIONS } from \"../../utils/polkadotExtensions\";\nimport {\n\tgetWalletId,\n\tparseWalletId,\n\ttype WalletId,\n} from \"../../utils/WalletId\";\nimport { createInjectedWallets$ } from \"../injectedWallets\";\nimport type { KheopskitStore } from \"../store\";\nimport type { PolkadotInjectedWallet } from \"./types\";\n\nconst getInjectedWalletsIds = () =>\n\ttypeof window === \"undefined\"\n\t\t? []\n\t\t: getInjectedExtensions().map((name) => getWalletId(\"polkadot\", name));\n\n// Create a polling observable that starts immediately and polls at intervals\nconst createWalletIdsPoller$ = () => {\n\treturn new Observable<WalletId[]>((subscriber) => {\n\t\t// Emit immediately on subscribe\n\t\tsubscriber.next(getInjectedWalletsIds());\n\n\t\t// Poll at shorter intervals initially, then slow down\n\t\tconst intervals = [100, 200, 300, 500];\n\t\tlet index = 0;\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\n\t\tconst poll = () => {\n\t\t\tsubscriber.next(getInjectedWalletsIds());\n\t\t\tif (index < intervals.length) {\n\t\t\t\tconst delay = intervals[index++];\n\t\t\t\ttimer = setTimeout(poll, delay);\n\t\t\t}\n\t\t};\n\n\t\t// Start polling after first immediate emission\n\t\tif (intervals.length > 0) {\n\t\t\ttimer = setTimeout(poll, intervals[index++] ?? 100);\n\t\t}\n\n\t\treturn () => {\n\t\t\t// Cancel any pending poll so it can't fire after unsubscribe.\n\t\t\tif (timer !== undefined) clearTimeout(timer);\n\t\t};\n\t}).pipe(\n\t\tdistinctUntilChanged<WalletId[]>(isEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n};\n\n// The shared WalletConnect connector is emitted once by core (see\n// `getWallets$`), not per platform — so this returns only injected wallets.\nexport const getPolkadotWallets$ = (store: KheopskitStore) =>\n\tcreateInjectedWallets$<WalletId, PolkadotInjectedWallet, InjectedExtension>(\n\t\tstore,\n\t\t{\n\t\t\tsources$: createWalletIdsPoller$(),\n\t\t\tgetWalletId: (walletId) => walletId,\n\t\t\tconnect: (walletId) => {\n\t\t\t\tconst { identifier } = parseWalletId(walletId);\n\t\t\t\treturn connectInjectedExtension(identifier);\n\t\t\t},\n\t\t\tbuildWallet: ({ walletId, handle, isConnected, connect, disconnect }) => {\n\t\t\t\tconst { identifier } = parseWalletId(walletId);\n\t\t\t\tconst extInfo = POLKADOT_EXTENSIONS[identifier];\n\n\t\t\t\treturn {\n\t\t\t\t\tid: walletId,\n\t\t\t\t\ttype: \"injected\",\n\t\t\t\t\tplatform: \"polkadot\",\n\t\t\t\t\tname: extInfo?.name ?? identifier,\n\t\t\t\t\ticon: extInfo?.icon ?? \"\",\n\t\t\t\t\tsourceId: identifier,\n\t\t\t\t\textension: handle,\n\t\t\t\t\tisConnected,\n\t\t\t\t\tconnect,\n\t\t\t\t\tdisconnect,\n\t\t\t\t};\n\t\t\t},\n\t\t},\n\t);\n","import type {\n\tKheopskitPlatform,\n\tPlatformContext,\n\tPolkadotAccountType,\n} from \"../types\";\nimport { getPolkadotAccounts$ } from \"./accounts\";\nimport type { PolkadotAccount, PolkadotWallet } from \"./types\";\nimport { getPolkadotWallets$ } from \"./wallets\";\n\nconst DEFAULT_ACCOUNT_TYPES: PolkadotAccountType[] = [\n\t\"sr25519\",\n\t\"ed25519\",\n\t\"ecdsa\",\n];\n\nconst VALID_ACCOUNT_TYPES = new Set<string>([\n\t\"sr25519\",\n\t\"ed25519\",\n\t\"ecdsa\",\n\t\"ethereum\",\n]);\n\nexport type PolkadotPluginOptions = {\n\t/**\n\t * Allowed Polkadot account key types. Accounts with other key types are\n\t * filtered out from kheopskit state.\n\t *\n\t * @default [\"sr25519\", \"ed25519\", \"ecdsa\"]\n\t */\n\taccountTypes?: PolkadotAccountType[];\n};\n\n/**\n * Polkadot platform plugin. Pass to `getKheopskit$({ platforms: [polkadot()] })`.\n *\n * @example\n * ```ts\n * import { polkadot } from \"@kheopskit/core/polkadot\";\n * polkadot({ accountTypes: [\"sr25519\", \"ed25519\", \"ecdsa\"] });\n * ```\n */\nexport const polkadot = (\n\toptions: PolkadotPluginOptions = {},\n): KheopskitPlatform<\"polkadot\", PolkadotWallet, PolkadotAccount> => {\n\tconst accountTypes = options.accountTypes ?? DEFAULT_ACCOUNT_TYPES;\n\n\tconst invalid = accountTypes.filter((t) => !VALID_ACCOUNT_TYPES.has(t));\n\tif (invalid.length > 0) {\n\t\tconsole.warn(\n\t\t\t`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: \"sr25519\", \"ed25519\", \"ecdsa\", \"ethereum\".`,\n\t\t);\n\t}\n\n\treturn {\n\t\tplatform: \"polkadot\",\n\t\tgetWallets$: (ctx: PlatformContext) => getPolkadotWallets$(ctx.store),\n\t\tgetAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),\n\t\tacceptsCachedAccount: (cached) =>\n\t\t\taccountTypes.includes(cached.polkadotAccountType ?? \"sr25519\"),\n\t};\n};\n"],"mappings":";;;;;;;;;AA2BA,MAAM,8BACL,WACmC;CACnC,IAAI,CAAC,OAAO,aAAa,OAAO,GAAG,CAAC,CAAC;CAErC,OAAO,IAAI,YAA+B,eAAe;EACxD,MAAM,cAAc,aAAuD;GAC1E,IAAI,mBAAmB,OAAO,IAAI,QAAQ,OAAO;GACjD,GAAG;GACH,MAA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{"version":3,"file":"polkadot.mjs","names":[],"sources":["../src/api/polkadot/accounts.ts","../src/api/polkadot/wallets.ts","../src/api/polkadot/plugin.ts"],"sourcesContent":["import type {\n\tInjectedExtension,\n\tInjectedPolkadotAccount,\n\tSignPayload,\n\tSignRaw,\n} from \"polkadot-api/pjs-signer\";\nimport * as pjs from \"polkadot-api/pjs-signer\";\nimport { Observable, of } from \"rxjs\";\nimport { getWalletAccountId } from \"../../utils\";\nimport { KheopskitError } from \"../errors\";\nimport {\n\tcreatePlatformAccounts$,\n\tgetCaip10Addresses,\n\tgetSessionCaip10s,\n\tgetWalletConnectSessionAccounts$,\n} from \"../platformAccounts\";\nimport type {\n\tAppKitInstance,\n\tPolkadotAccountType,\n\tWalletConnectWallet,\n} from \"../types\";\nimport type {\n\tPolkadotAccount,\n\tPolkadotInjectedWallet,\n\tPolkadotWallet,\n} from \"./types\";\n\nconst getInjectedWalletAccounts$ = (\n\twallet: PolkadotInjectedWallet,\n): Observable<PolkadotAccount[]> => {\n\tif (!wallet.isConnected) return of([]);\n\n\treturn new Observable<PolkadotAccount[]>((subscriber) => {\n\t\tconst getAccount = (account: InjectedPolkadotAccount): PolkadotAccount => ({\n\t\t\tid: getWalletAccountId(wallet.id, account.address),\n\t\t\t...account,\n\t\t\ttype: account.type ?? \"sr25519\",\n\t\t\tplatform: \"polkadot\",\n\t\t\twalletName: wallet.name,\n\t\t\twalletId: wallet.id,\n\t\t});\n\n\t\tconst extension = wallet.extension as InjectedExtension;\n\n\t\t// subscribe to changes\n\t\tconst unsubscribe = extension.subscribe((accounts) => {\n\t\t\tsubscriber.next(accounts.map(getAccount));\n\t\t});\n\n\t\t// initial value\n\t\tsubscriber.next(extension.getAccounts().map(getAccount));\n\n\t\treturn () => {\n\t\t\treturn unsubscribe();\n\t\t};\n\t});\n};\n\ntype PjsSignerFactory = (\n\taddress: string,\n\tsignPayload: SignPayload,\n\tsignRaw: SignRaw,\n) => unknown;\n\ntype PjsSignerModule = {\n\tgetTxCreatorFromPjs?: PjsSignerFactory;\n\tgetPolkadotSignerFromPjs?: PjsSignerFactory;\n};\n\n/**\n * polkadot-api v3 replaced `polkadotSigner` (PolkadotSigner) with `txCreator`\n * (TxCreator). Which one the app's installed version provides is detected at\n * runtime so a single @kheopskit/core release supports both.\n */\nconst getPjsSignerField = (): {\n\tfield: \"txCreator\" | \"polkadotSigner\";\n\tfactory: PjsSignerFactory;\n} => {\n\tconst { getTxCreatorFromPjs, getPolkadotSignerFromPjs } =\n\t\tpjs as PjsSignerModule;\n\tif (getTxCreatorFromPjs)\n\t\treturn { field: \"txCreator\", factory: getTxCreatorFromPjs };\n\tif (getPolkadotSignerFromPjs)\n\t\treturn { field: \"polkadotSigner\", factory: getPolkadotSignerFromPjs };\n\tthrow new KheopskitError(\n\t\t\"UNSUPPORTED_VERSION\",\n\t\t\"Unsupported polkadot-api/pjs-signer version\",\n\t);\n};\n\nconst getAppKitPolkadotSigner = (appKit: AppKitInstance, address: string) => {\n\tconst provider = appKit.getProvider(\"polkadot\");\n\tif (!provider) throw new KheopskitError(\"NO_PROVIDER\", \"No provider found\");\n\tif (!provider.session)\n\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\n\tconst { field, factory } = getPjsSignerField();\n\n\tconst signer = factory(\n\t\taddress,\n\t\t(transactionPayload) => {\n\t\t\tif (!provider.session)\n\t\t\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\n\t\t\treturn provider.client.request({\n\t\t\t\ttopic: provider.session.topic,\n\t\t\t\tchainId: `polkadot:${transactionPayload.genesisHash.substring(2, 34)}`,\n\t\t\t\trequest: {\n\t\t\t\t\tmethod: \"polkadot_signTransaction\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\ttransactionPayload,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t\tasync ({ address, data }) => {\n\t\t\tif (!provider.session)\n\t\t\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\t\t\tconst networks = appKit.getCaipNetworks(\"polkadot\");\n\t\t\tconst chainId = networks[0]?.caipNetworkId;\n\t\t\tif (!chainId)\n\t\t\t\tthrow new KheopskitError(\n\t\t\t\t\t\"NO_SESSION\",\n\t\t\t\t\t\"No CAIP network available for polkadot\",\n\t\t\t\t);\n\n\t\t\treturn provider.client.request({\n\t\t\t\ttopic: provider.session.topic,\n\t\t\t\tchainId,\n\t\t\t\trequest: {\n\t\t\t\t\tmethod: \"polkadot_signMessage\",\n\t\t\t\t\tparams: {\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\tmessage: data,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t);\n\n\treturn { [field]: signer };\n};\n\nconst getWalletConnectAccounts$ = (\n\twallet: WalletConnectWallet,\n): Observable<PolkadotAccount[]> =>\n\tgetWalletConnectSessionAccounts$({\n\t\twallet,\n\t\tplatform: \"polkadot\",\n\t\tnamespace: \"polkadot\",\n\t\tcacheKey: `accounts:${wallet.id}:polkadot:`,\n\t\tbuildAccounts: (provider) => {\n\t\t\tconst session = provider.session;\n\t\t\tif (!session) return [];\n\n\t\t\tconst addresses = getCaip10Addresses(\n\t\t\t\tgetSessionCaip10s(session, \"polkadot\"),\n\t\t\t);\n\n\t\t\treturn addresses.map(\n\t\t\t\t(address) =>\n\t\t\t\t\t({\n\t\t\t\t\t\tid: getWalletAccountId(wallet.id, address),\n\t\t\t\t\t\tplatform: \"polkadot\",\n\t\t\t\t\t\twalletName: wallet.name,\n\t\t\t\t\t\twalletId: wallet.id,\n\t\t\t\t\t\taddress,\n\t\t\t\t\t\t...getAppKitPolkadotSigner(wallet.appKit, address),\n\t\t\t\t\t\tgenesisHash: null,\n\t\t\t\t\t\tname: `${wallet.name} Polkadot`,\n\t\t\t\t\t\t// WalletConnect (Reown AppKit) doesn't expose account key type;\n\t\t\t\t\t\t// default to sr25519, which is the most common Polkadot key type.\n\t\t\t\t\t\ttype: \"sr25519\",\n\t\t\t\t\t}) as PolkadotAccount,\n\t\t\t);\n\t\t},\n\t});\n\nexport const getPolkadotAccounts$ = (\n\tpolkadotWallets$: Observable<(PolkadotWallet | WalletConnectWallet)[]>,\n\tpolkadotAccountTypes: PolkadotAccountType[],\n) => {\n\tif (polkadotAccountTypes.length === 0) {\n\t\tconsole.warn(\n\t\t\t\"[kheopskit] config.polkadotAccountTypes is empty; all Polkadot accounts will be filtered out.\",\n\t\t);\n\t}\n\n\treturn createPlatformAccounts$({\n\t\twallets$: polkadotWallets$,\n\t\tgetInjectedAccounts$: getInjectedWalletAccounts$,\n\t\tgetWalletConnectAccounts$,\n\t\tmapAccounts: (accounts) =>\n\t\t\taccounts.filter((account) => polkadotAccountTypes.includes(account.type)),\n\t});\n};\n","import { isEqual } from \"lodash-es\";\nimport {\n\tconnectInjectedExtension,\n\tgetInjectedExtensions,\n\ttype InjectedExtension,\n} from \"polkadot-api/pjs-signer\";\nimport { distinctUntilChanged, Observable, shareReplay } from \"rxjs\";\nimport { POLKADOT_EXTENSIONS } from \"../../utils/polkadotExtensions\";\nimport {\n\tgetWalletId,\n\tparseWalletId,\n\ttype WalletId,\n} from \"../../utils/WalletId\";\nimport { createInjectedWallets$ } from \"../injectedWallets\";\nimport type { KheopskitStore } from \"../store\";\nimport type { KheopskitConfig } from \"../types\";\nimport type { PolkadotInjectedWallet } from \"./types\";\n\nconst getInjectedWalletsIds = () =>\n\ttypeof window === \"undefined\"\n\t\t? []\n\t\t: getInjectedExtensions().map((name) => getWalletId(\"polkadot\", name));\n\n// Create a polling observable that starts immediately and polls at intervals\nconst createWalletIdsPoller$ = () => {\n\treturn new Observable<WalletId[]>((subscriber) => {\n\t\t// Emit immediately on subscribe\n\t\tsubscriber.next(getInjectedWalletsIds());\n\n\t\t// Poll at shorter intervals initially, then slow down\n\t\tconst intervals = [100, 200, 300, 500];\n\t\tlet index = 0;\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\n\t\tconst poll = () => {\n\t\t\tsubscriber.next(getInjectedWalletsIds());\n\t\t\tif (index < intervals.length) {\n\t\t\t\tconst delay = intervals[index++];\n\t\t\t\ttimer = setTimeout(poll, delay);\n\t\t\t}\n\t\t};\n\n\t\t// Start polling after first immediate emission\n\t\tif (intervals.length > 0) {\n\t\t\ttimer = setTimeout(poll, intervals[index++] ?? 100);\n\t\t}\n\n\t\treturn () => {\n\t\t\t// Cancel any pending poll so it can't fire after unsubscribe.\n\t\t\tif (timer !== undefined) clearTimeout(timer);\n\t\t};\n\t}).pipe(\n\t\tdistinctUntilChanged<WalletId[]>(isEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n};\n\n// The shared WalletConnect connector is emitted once by core (see\n// `getWallets$`), not per platform — so this returns only injected wallets.\nexport const getPolkadotWallets$ = (\n\tstore: KheopskitStore,\n\tconfig: Pick<KheopskitConfig, \"appName\" | \"walletConnect\">,\n) =>\n\tcreateInjectedWallets$<WalletId, PolkadotInjectedWallet, InjectedExtension>(\n\t\tstore,\n\t\t{\n\t\t\tsources$: createWalletIdsPoller$(),\n\t\t\tgetWalletId: (walletId) => walletId,\n\t\t\tconnect: (walletId) => {\n\t\t\t\tconst { identifier } = parseWalletId(walletId);\n\t\t\t\treturn connectInjectedExtension(\n\t\t\t\t\tidentifier,\n\t\t\t\t\tconfig.appName ||\n\t\t\t\t\t\tconfig.walletConnect?.metadata.name ||\n\t\t\t\t\t\twindow.location.hostname,\n\t\t\t\t);\n\t\t\t},\n\t\t\tbuildWallet: ({ walletId, handle, isConnected, connect, disconnect }) => {\n\t\t\t\tconst { identifier } = parseWalletId(walletId);\n\t\t\t\tconst extInfo = POLKADOT_EXTENSIONS[identifier];\n\n\t\t\t\treturn {\n\t\t\t\t\tid: walletId,\n\t\t\t\t\ttype: \"injected\",\n\t\t\t\t\tplatform: \"polkadot\",\n\t\t\t\t\tname: extInfo?.name ?? identifier,\n\t\t\t\t\ticon: extInfo?.icon ?? \"\",\n\t\t\t\t\tsourceId: identifier,\n\t\t\t\t\textension: handle,\n\t\t\t\t\tisConnected,\n\t\t\t\t\tconnect,\n\t\t\t\t\tdisconnect,\n\t\t\t\t};\n\t\t\t},\n\t\t},\n\t);\n","import type {\n\tKheopskitPlatform,\n\tPlatformContext,\n\tPolkadotAccountType,\n} from \"../types\";\nimport { getPolkadotAccounts$ } from \"./accounts\";\nimport type { PolkadotAccount, PolkadotWallet } from \"./types\";\nimport { getPolkadotWallets$ } from \"./wallets\";\n\nconst DEFAULT_ACCOUNT_TYPES: PolkadotAccountType[] = [\n\t\"sr25519\",\n\t\"ed25519\",\n\t\"ecdsa\",\n];\n\nconst VALID_ACCOUNT_TYPES = new Set<string>([\n\t\"sr25519\",\n\t\"ed25519\",\n\t\"ecdsa\",\n\t\"ethereum\",\n]);\n\nexport type PolkadotPluginOptions = {\n\t/**\n\t * Allowed Polkadot account key types. Accounts with other key types are\n\t * filtered out from kheopskit state.\n\t *\n\t * @default [\"sr25519\", \"ed25519\", \"ecdsa\"]\n\t */\n\taccountTypes?: PolkadotAccountType[];\n};\n\n/**\n * Polkadot platform plugin. Pass to `getKheopskit$({ platforms: [polkadot()] })`.\n *\n * @example\n * ```ts\n * import { polkadot } from \"@kheopskit/core/polkadot\";\n * polkadot({ accountTypes: [\"sr25519\", \"ed25519\", \"ecdsa\"] });\n * ```\n */\nexport const polkadot = (\n\toptions: PolkadotPluginOptions = {},\n): KheopskitPlatform<\"polkadot\", PolkadotWallet, PolkadotAccount> => {\n\tconst accountTypes = options.accountTypes ?? DEFAULT_ACCOUNT_TYPES;\n\n\tconst invalid = accountTypes.filter((t) => !VALID_ACCOUNT_TYPES.has(t));\n\tif (invalid.length > 0) {\n\t\tconsole.warn(\n\t\t\t`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: \"sr25519\", \"ed25519\", \"ecdsa\", \"ethereum\".`,\n\t\t);\n\t}\n\n\treturn {\n\t\tplatform: \"polkadot\",\n\t\tgetWallets$: (ctx: PlatformContext) =>\n\t\t\tgetPolkadotWallets$(ctx.store, ctx.config),\n\t\tgetAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),\n\t\tacceptsCachedAccount: (cached) =>\n\t\t\taccountTypes.includes(cached.polkadotAccountType ?? \"sr25519\"),\n\t};\n};\n"],"mappings":";;;;;;;;;AA2BA,MAAM,8BACL,WACmC;CACnC,IAAI,CAAC,OAAO,aAAa,OAAO,GAAG,CAAC,CAAC;CAErC,OAAO,IAAI,YAA+B,eAAe;EACxD,MAAM,cAAc,aAAuD;GAC1E,IAAI,mBAAmB,OAAO,IAAI,QAAQ,OAAO;GACjD,GAAG;GACH,MAAM,QAAQ,QAAQ;GACtB,UAAU;GACV,YAAY,OAAO;GACnB,UAAU,OAAO;EAClB;EAEA,MAAM,YAAY,OAAO;EAGzB,MAAM,cAAc,UAAU,WAAW,aAAa;GACrD,WAAW,KAAK,SAAS,IAAI,UAAU,CAAC;EACzC,CAAC;EAGD,WAAW,KAAK,UAAU,YAAY,CAAC,CAAC,IAAI,UAAU,CAAC;EAEvD,aAAa;GACZ,OAAO,YAAY;EACpB;CACD,CAAC;AACF;;;;;;AAkBA,MAAM,0BAGD;CACJ,MAAM,EAAE,qBAAqB,6BAC5B;CACD,IAAI,qBACH,OAAO;EAAE,OAAO;EAAa,SAAS;CAAoB;CAC3D,IAAI,0BACH,OAAO;EAAE,OAAO;EAAkB,SAAS;CAAyB;CACrE,MAAM,IAAI,eACT,uBACA,6CACD;AACD;AAEA,MAAM,2BAA2B,QAAwB,YAAoB;CAC5E,MAAM,WAAW,OAAO,YAAY,UAAU;CAC9C,IAAI,CAAC,UAAU,MAAM,IAAI,eAAe,eAAe,mBAAmB;CAC1E,IAAI,CAAC,SAAS,SACb,MAAM,IAAI,eAAe,cAAc,kBAAkB;CAE1D,MAAM,EAAE,OAAO,YAAY,kBAAkB;CAE7C,MAAM,SAAS,QACd,UACC,uBAAuB;EACvB,IAAI,CAAC,SAAS,SACb,MAAM,IAAI,eAAe,cA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AAI,IAAY;CAC3C;CACA;CACA;CACA;AACD,CAAC;;;;;;;;;;AAqBD,MAAa,YACZ,UAAiC,CAAC,MACkC;CACpE,MAAM,eAAe,QAAQ,gBAAgB;CAE7C,MAAM,UAAU,aAAa,QAAQ,MAAM,CAAC,oBAAoB,IAAI,CAAC,CAAC;CACtE,IAAI,QAAQ,SAAS,GACpB,QAAQ,KACP,8CAA8C,KAAK,UAAU,OAAO,EAAE,2DACvE;CAGD,OAAO;EACN,UAAU;EACV,cAAc,QACb,oBAAoB,IAAI,OAAO,IAAI,MAAM;EAC1C,eAAe,aAAa,qBAAqB,UAAU,YAAY;EACvE,uBAAuB,WACtB,aAAa,SAAS,OAAO,uBAAuB,SAAS;CAC/D;AACD"}
package/dist/solana.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as WalletId, D as WalletAccountId, S as isWalletConnectWallet, _ as WalletConnectWallet, c as KheopskitPlatform, x as isInjectedWallet } from "./types-Cb-vuEru.mjs";
1
+ import { C as WalletId, D as WalletAccountId, S as isWalletConnectWallet, _ as WalletConnectWallet, c as KheopskitPlatform, x as isInjectedWallet } from "./types-AxUDtkR-.mjs";
2
2
  import { MessageModifyingSigner, TransactionModifyingSigner, TransactionSendingSigner } from "@solana/kit";
3
3
  import { Wallet } from "@wallet-standard/base";
4
4
  //#region src/utils/isSolanaAddress.d.ts
@@ -10,7 +10,7 @@ import { Wallet } from "@wallet-standard/base";
10
10
  * Dependency-free (base58 via @scure/base) so core stays decoupled from
11
11
  * @solana/kit.
12
12
  */
13
- declare const isSolanaAddress: (address: string) => boolean;
13
+ export declare const isSolanaAddress: (address: string) => boolean;
14
14
  //#endregion
15
15
  //#region src/api/solana/chains.d.ts
16
16
  /**
@@ -22,15 +22,15 @@ declare const isSolanaAddress: (address: string) => boolean;
22
22
  * @see https://github.com/anza-xyz/wallet-standard
23
23
  */
24
24
  type SolanaChainId = "solana:mainnet" | "solana:devnet" | "solana:testnet" | "solana:localnet";
25
- declare const DEFAULT_SOLANA_CHAIN: SolanaChainId;
26
- declare const isSolanaChainId: (value: unknown) => value is SolanaChainId;
25
+ export declare const DEFAULT_SOLANA_CHAIN: SolanaChainId;
26
+ export declare const isSolanaChainId: (value: unknown) => value is SolanaChainId;
27
27
  /**
28
28
  * Returns the CAIP-2 chain id for a Solana chain, for use in WalletConnect
29
29
  * requests and when reading WalletConnect session namespaces.
30
30
  *
31
31
  * @throws if the chain has no canonical CAIP-2 id (e.g. localnet)
32
32
  */
33
- declare const getSolanaCaip2: (chain: SolanaChainId) => string;
33
+ export declare const getSolanaCaip2: (chain: SolanaChainId) => string;
34
34
  //#endregion
35
35
  //#region src/api/solana/types.d.ts
36
36
  /**
@@ -94,7 +94,7 @@ type SolanaPluginOptions = {
94
94
  * solana({ chain: "solana:mainnet" });
95
95
  * ```
96
96
  */
97
- declare const solana: (options?: SolanaPluginOptions) => KheopskitPlatform<"solana", SolanaWallet, SolanaAccount>;
97
+ export declare const solana: (options?: SolanaPluginOptions) => KheopskitPlatform<"solana", SolanaWallet, SolanaAccount>;
98
98
  //#endregion
99
- export { DEFAULT_SOLANA_CHAIN, type SolanaAccount, type SolanaChainId, type SolanaInjectedWallet, type SolanaPluginOptions, type SolanaSigner, type SolanaWallet, type WalletConnectWallet, getSolanaCaip2, isInjectedWallet, isSolanaAddress, isSolanaChainId, isWalletConnectWallet, solana };
99
+ export { type SolanaAccount, type SolanaChainId, type SolanaInjectedWallet, type SolanaPluginOptions, type SolanaSigner, type SolanaWallet, type WalletConnectWallet, isInjectedWallet, isWalletConnectWallet };
100
100
  //# sourceMappingURL=solana.d.mts.map
package/dist/solana.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as WalletId, D as WalletAccountId, S as isWalletConnectWallet, _ as WalletConnectWallet, c as KheopskitPlatform, x as isInjectedWallet } from "./types-Cb-vuEru.js";
1
+ import { C as WalletId, D as WalletAccountId, S as isWalletConnectWallet, _ as WalletConnectWallet, c as KheopskitPlatform, x as isInjectedWallet } from "./types-AxUDtkR-.js";
2
2
  import { MessageModifyingSigner, TransactionModifyingSigner, TransactionSendingSigner } from "@solana/kit";
3
3
  import { Wallet } from "@wallet-standard/base";
4
4
  //#region src/utils/isSolanaAddress.d.ts
@@ -10,7 +10,7 @@ import { Wallet } from "@wallet-standard/base";
10
10
  * Dependency-free (base58 via @scure/base) so core stays decoupled from
11
11
  * @solana/kit.
12
12
  */
13
- declare const isSolanaAddress: (address: string) => boolean;
13
+ export declare const isSolanaAddress: (address: string) => boolean;
14
14
  //#endregion
15
15
  //#region src/api/solana/chains.d.ts
16
16
  /**
@@ -22,15 +22,15 @@ declare const isSolanaAddress: (address: string) => boolean;
22
22
  * @see https://github.com/anza-xyz/wallet-standard
23
23
  */
24
24
  type SolanaChainId = "solana:mainnet" | "solana:devnet" | "solana:testnet" | "solana:localnet";
25
- declare const DEFAULT_SOLANA_CHAIN: SolanaChainId;
26
- declare const isSolanaChainId: (value: unknown) => value is SolanaChainId;
25
+ export declare const DEFAULT_SOLANA_CHAIN: SolanaChainId;
26
+ export declare const isSolanaChainId: (value: unknown) => value is SolanaChainId;
27
27
  /**
28
28
  * Returns the CAIP-2 chain id for a Solana chain, for use in WalletConnect
29
29
  * requests and when reading WalletConnect session namespaces.
30
30
  *
31
31
  * @throws if the chain has no canonical CAIP-2 id (e.g. localnet)
32
32
  */
33
- declare const getSolanaCaip2: (chain: SolanaChainId) => string;
33
+ export declare const getSolanaCaip2: (chain: SolanaChainId) => string;
34
34
  //#endregion
35
35
  //#region src/api/solana/types.d.ts
36
36
  /**
@@ -94,7 +94,7 @@ type SolanaPluginOptions = {
94
94
  * solana({ chain: "solana:mainnet" });
95
95
  * ```
96
96
  */
97
- declare const solana: (options?: SolanaPluginOptions) => KheopskitPlatform<"solana", SolanaWallet, SolanaAccount>;
97
+ export declare const solana: (options?: SolanaPluginOptions) => KheopskitPlatform<"solana", SolanaWallet, SolanaAccount>;
98
98
  //#endregion
99
- export { DEFAULT_SOLANA_CHAIN, type SolanaAccount, type SolanaChainId, type SolanaInjectedWallet, type SolanaPluginOptions, type SolanaSigner, type SolanaWallet, type WalletConnectWallet, getSolanaCaip2, isInjectedWallet, isSolanaAddress, isSolanaChainId, isWalletConnectWallet, solana };
99
+ export { type SolanaAccount, type SolanaChainId, type SolanaInjectedWallet, type SolanaPluginOptions, type SolanaSigner, type SolanaWallet, type WalletConnectWallet, isInjectedWallet, isWalletConnectWallet };
100
100
  //# sourceMappingURL=solana.d.ts.map
package/dist/solana.js CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_types = require("./types-DKU-SNio.js");
3
- const require_errors = require("./errors-DPw6pc2H.js");
4
- const require_injectedWallets = require("./injectedWallets-B1MCxAE9.js");
3
+ const require_errors = require("./errors-DYWVPHrR.js");
4
+ const require_injectedWallets = require("./injectedWallets-BqR-_aAy.js");
5
5
  let rxjs = require("rxjs");
6
6
  let _solana_kit = require("@solana/kit");
7
7
  let _wallet_standard_app = require("@wallet-standard/app");