@kheopskit/core 6.0.1 → 6.0.3
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/CHANGELOG.md +14 -0
- package/dist/{config-Bb-Zz8J1.d.ts → config-Csp5p0-Z.d.ts} +2 -2
- package/dist/{config-C-Xk2AP_.d.mts → config-qMsgD8tJ.d.mts} +2 -2
- package/dist/ethereum.d.mts +1 -1
- package/dist/ethereum.d.ts +1 -1
- package/dist/ethereum.js +57 -8
- package/dist/ethereum.js.map +1 -1
- package/dist/ethereum.mjs +58 -9
- package/dist/ethereum.mjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{instance-BJVnjk4r.mjs → instance--1tqj7s5.mjs} +2 -2
- package/dist/{instance-BJVnjk4r.mjs.map → instance--1tqj7s5.mjs.map} +1 -1
- package/dist/{instance-aPJrTyvW.js → instance-4DgSj55G.js} +2 -2
- package/dist/{instance-aPJrTyvW.js.map → instance-4DgSj55G.js.map} +1 -1
- package/dist/{instance-1BgEld17.d.ts → instance-CrdktIu7.d.ts} +2 -2
- package/dist/{instance-DDvZiq1L.d.mts → instance-Gv9IDCIY.d.mts} +2 -2
- package/dist/internal.d.mts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +1 -1
- package/dist/internal.mjs +1 -1
- package/dist/{platformAccounts-C1sFv82e.mjs → platformAccounts-3jM3W1fB.mjs} +4 -3
- package/dist/{platformAccounts-C1sFv82e.mjs.map → platformAccounts-3jM3W1fB.mjs.map} +1 -1
- package/dist/{platformAccounts-CqMSpl3X.js → platformAccounts-BcLoaZZb.js} +4 -3
- package/dist/{platformAccounts-CqMSpl3X.js.map → platformAccounts-BcLoaZZb.js.map} +1 -1
- package/dist/polkadot.d.mts +1 -1
- package/dist/polkadot.d.ts +1 -1
- package/dist/polkadot.js +6 -4
- package/dist/polkadot.js.map +1 -1
- package/dist/polkadot.mjs +6 -4
- package/dist/polkadot.mjs.map +1 -1
- package/dist/solana.d.mts +1 -1
- package/dist/solana.d.ts +1 -1
- package/dist/solana.js +1 -1
- package/dist/solana.mjs +1 -1
- package/dist/testing.d.mts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/{types-BGeGUtxz.d.mts → types-C9aw2FEm.d.mts} +2 -1
- package/dist/{types-BGeGUtxz.d.ts → types-C9aw2FEm.d.ts} +2 -1
- package/dist/types-DaRMgleZ.js.map +1 -1
- package/dist/types-DcpmEGhO.mjs.map +1 -1
- package/dist/walletconnect.d.mts +1 -1
- package/dist/walletconnect.d.ts +1 -1
- package/dist/walletconnect.js +2 -2
- package/dist/walletconnect.js.map +1 -1
- package/dist/walletconnect.mjs +2 -2
- package/dist/walletconnect.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as WalletAccountId, c as KheopskitConfig, d as KheopskitStore, k as WalletId, l as KheopskitPlatform, s as ConnectOptions, t as AccountOf, u as KheopskitState } from "./types-
|
|
1
|
+
import { N as WalletAccountId, c as KheopskitConfig, d as KheopskitStore, k as WalletId, l as KheopskitPlatform, s as ConnectOptions, t as AccountOf, u as KheopskitState } from "./types-C9aw2FEm.js";
|
|
2
2
|
import { Observable } from "rxjs";
|
|
3
3
|
//#region src/utils/getCachedObservable.d.ts
|
|
4
4
|
/**
|
|
@@ -106,4 +106,4 @@ declare const kheopskitInternals: (kit: Kheopskit<readonly KheopskitPlatform[]>)
|
|
|
106
106
|
declare const createKheopskit: <const P extends readonly [KheopskitPlatform, ...KheopskitPlatform[]]>(config: CreateKheopskitConfig<P>, options?: CreateKheopskitOptions) => Kheopskit<P>;
|
|
107
107
|
//#endregion
|
|
108
108
|
export { createKheopskit as a, clearAllCachedObservables as c, createInstance as i, clearCachedObservable as l, CreateKheopskitOptions as n, kheopskitInternals as o, Kheopskit as r, WalletActions as s, CreateKheopskitConfig as t, clearCachedObservablesByPrefix as u };
|
|
109
|
-
//# sourceMappingURL=instance-
|
|
109
|
+
//# sourceMappingURL=instance-CrdktIu7.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { N as WalletAccountId, c as KheopskitConfig, d as KheopskitStore, k as WalletId, l as KheopskitPlatform, s as ConnectOptions, t as AccountOf, u as KheopskitState } from "./types-
|
|
1
|
+
import { N as WalletAccountId, c as KheopskitConfig, d as KheopskitStore, k as WalletId, l as KheopskitPlatform, s as ConnectOptions, t as AccountOf, u as KheopskitState } from "./types-C9aw2FEm.mjs";
|
|
2
2
|
import { Observable } from "rxjs";
|
|
3
3
|
//#region src/utils/getCachedObservable.d.ts
|
|
4
4
|
/**
|
|
@@ -106,4 +106,4 @@ declare const kheopskitInternals: (kit: Kheopskit<readonly KheopskitPlatform[]>)
|
|
|
106
106
|
declare const createKheopskit: <const P extends readonly [KheopskitPlatform, ...KheopskitPlatform[]]>(config: CreateKheopskitConfig<P>, options?: CreateKheopskitOptions) => Kheopskit<P>;
|
|
107
107
|
//#endregion
|
|
108
108
|
export { createKheopskit as a, clearAllCachedObservables as c, createInstance as i, clearCachedObservable as l, CreateKheopskitOptions as n, kheopskitInternals as o, Kheopskit as r, WalletActions as s, CreateKheopskitConfig as t, clearCachedObservablesByPrefix as u };
|
|
109
|
-
//# sourceMappingURL=instance-
|
|
109
|
+
//# sourceMappingURL=instance-Gv9IDCIY.d.mts.map
|
package/dist/internal.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as getSafeLocalStorage } from "./storage-D3AwNgqc.mjs";
|
|
2
|
-
import { a as CachedAccount, b as WalletConnectWallet, i as BaseWalletAccount, o as CachedWallet, r as BaseWallet } from "./types-
|
|
3
|
-
import { i as createInstance, l as clearCachedObservable, o as kheopskitInternals, s as WalletActions, u as clearCachedObservablesByPrefix } from "./instance-
|
|
2
|
+
import { a as CachedAccount, b as WalletConnectWallet, i as BaseWalletAccount, o as CachedWallet, r as BaseWallet } from "./types-C9aw2FEm.mjs";
|
|
3
|
+
import { i as createInstance, l as clearCachedObservable, o as kheopskitInternals, s as WalletActions, u as clearCachedObservablesByPrefix } from "./instance-Gv9IDCIY.mjs";
|
|
4
4
|
//#region src/utils/hydrateState.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Converts a wallet to a CachedWallet for storage.
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as getSafeLocalStorage } from "./storage-D3AwNgqc.js";
|
|
2
|
-
import { a as CachedAccount, b as WalletConnectWallet, i as BaseWalletAccount, o as CachedWallet, r as BaseWallet } from "./types-
|
|
3
|
-
import { i as createInstance, l as clearCachedObservable, o as kheopskitInternals, s as WalletActions, u as clearCachedObservablesByPrefix } from "./instance-
|
|
2
|
+
import { a as CachedAccount, b as WalletConnectWallet, i as BaseWalletAccount, o as CachedWallet, r as BaseWallet } from "./types-C9aw2FEm.js";
|
|
3
|
+
import { i as createInstance, l as clearCachedObservable, o as kheopskitInternals, s as WalletActions, u as clearCachedObservablesByPrefix } from "./instance-CrdktIu7.js";
|
|
4
4
|
//#region src/utils/hydrateState.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Converts a wallet to a CachedWallet for storage.
|
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-DaRMgleZ.js");
|
|
3
|
-
const require_instance = require("./instance-
|
|
3
|
+
const require_instance = require("./instance-4DgSj55G.js");
|
|
4
4
|
exports.clearCachedObservable = require_types.clearCachedObservable;
|
|
5
5
|
exports.clearCachedObservablesByPrefix = require_types.clearCachedObservablesByPrefix;
|
|
6
6
|
exports.createInstance = require_instance.createInstance;
|
package/dist/internal.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { l as clearCachedObservable, u as clearCachedObservablesByPrefix } from "./types-DcpmEGhO.mjs";
|
|
2
|
-
import { c as getSafeLocalStorage, l as serializeAccount, r as kheopskitInternals, s as setCachedIcons, t as createInstance, u as serializeWallet } from "./instance
|
|
2
|
+
import { c as getSafeLocalStorage, l as serializeAccount, r as kheopskitInternals, s as setCachedIcons, t as createInstance, u as serializeWallet } from "./instance--1tqj7s5.mjs";
|
|
3
3
|
export { clearCachedObservable, clearCachedObservablesByPrefix, createInstance, getSafeLocalStorage, kheopskitInternals, serializeAccount, serializeWallet, setCachedIcons };
|
|
@@ -221,9 +221,10 @@ const createPlatformAccounts$ = ({ wallets$, getInjectedAccounts$, getWalletConn
|
|
|
221
221
|
};
|
|
222
222
|
/**
|
|
223
223
|
* CAIP-10 account strings ("<namespace>:<chainRef>:<address>") the live
|
|
224
|
-
* WalletConnect session carries for a namespace
|
|
224
|
+
* WalletConnect session carries for a namespace, limited to the entries
|
|
225
|
+
* granting `method` when one is given.
|
|
225
226
|
*/
|
|
226
|
-
const getSessionCaip10s = (session, namespace) => Object.values(session.namespaces).flatMap((ns) => ns.accounts ?? []).filter((account) => account.startsWith(`${namespace}:`));
|
|
227
|
+
const getSessionCaip10s = (session, namespace, method) => Object.values(session.namespaces).filter((ns) => !method || ns.methods?.includes(method)).flatMap((ns) => ns.accounts ?? []).filter((account) => account.startsWith(`${namespace}:`));
|
|
227
228
|
/**
|
|
228
229
|
* Unique addresses from CAIP-10 account strings (one entry per chain, so the
|
|
229
230
|
* same address repeats — dedupe).
|
|
@@ -260,4 +261,4 @@ const getWalletConnectSessionAccounts$ = (options) => {
|
|
|
260
261
|
//#endregion
|
|
261
262
|
export { getWalletConnectSessionAccounts$ as a, isValidAddress as c, isEthereumAddress as d, getSessionCaip10s as i, isSs58Address as l, framesOf as n, getWalletAccountId as o, getCaip10Addresses as r, parseWalletAccountId as s, createPlatformAccounts$ as t, isSolanaAddress as u };
|
|
262
263
|
|
|
263
|
-
//# sourceMappingURL=platformAccounts-
|
|
264
|
+
//# sourceMappingURL=platformAccounts-3jM3W1fB.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformAccounts-C1sFv82e.mjs","names":[],"sources":["../src/utils/isEthereumAddress.ts","../src/utils/isSolanaAddress.ts","../src/utils/isSs58Address.ts","../src/utils/isValidAddress.ts","../src/utils/WalletAccountId.ts","../src/api/platformAccounts.ts"],"sourcesContent":["import { keccak_256 } from \"@noble/hashes/sha3.js\";\n\nconst HEX_ADDRESS = /^0x[0-9a-fA-F]{40}$/;\nconst encoder = new TextEncoder();\n\n/**\n * Verifies the EIP-55 mixed-case checksum of an Ethereum address.\n * Dependency-free (keccak via @noble/hashes) so core stays decoupled from viem.\n */\nconst isChecksumValid = (address: string): boolean => {\n\tconst hex = address.slice(2);\n\tconst hash = keccak_256(encoder.encode(hex.toLowerCase()));\n\tfor (let i = 0; i < 40; i++) {\n\t\tconst char = hex.charAt(i);\n\t\tconst isLetter =\n\t\t\t(char >= \"a\" && char <= \"f\") || (char >= \"A\" && char <= \"F\");\n\t\tif (!isLetter) continue;\n\t\tconst byte = hash[i >> 1] ?? 0;\n\t\tconst nibble = i % 2 === 0 ? byte >> 4 : byte & 0x0f;\n\t\tconst isUpper = char <= \"F\";\n\t\tif (isUpper !== nibble >= 8) return false;\n\t}\n\treturn true;\n};\n\n/**\n * Returns true if `address` is a valid Ethereum address.\n *\n * Mirrors viem's `isAddress` (strict): the shape must be `0x` + 40 hex, and a\n * mixed-case address must pass the EIP-55 checksum. All-lowercase addresses are\n * accepted as non-checksummed.\n */\nexport const isEthereumAddress = (address: string): boolean => {\n\tif (!HEX_ADDRESS.test(address)) return false;\n\tif (address === address.toLowerCase()) return true;\n\treturn isChecksumValid(address);\n};\n","import { base58 } from \"@scure/base\";\n\n/**\n * Returns true if the value is a valid Solana address: a base58-encoded\n * 32-byte ed25519 public key.\n *\n * Solana addresses carry no checksum, so this is a pure base58 + length check.\n * Dependency-free (base58 via @scure/base) so core stays decoupled from\n * @solana/kit.\n */\nexport const isSolanaAddress = (address: string): boolean => {\n\tif (!address) return false;\n\ttry {\n\t\treturn base58.decode(address).length === 32;\n\t} catch {\n\t\treturn false;\n\t}\n};\n","import { blake2b } from \"@noble/hashes/blake2.js\";\nimport { base58 } from \"@scure/base\";\n\n// The \"SS58PRE\" prefix used in the SS58 checksum preimage.\nconst SS58PRE = new Uint8Array([0x53, 0x53, 0x35, 0x38, 0x50, 0x52, 0x45]);\n\n/**\n * Returns true if `address` is a valid SS58-encoded 32-byte account id (the\n * only form Substrate wallets inject), verifying the blake2b-512 checksum.\n *\n * Dependency-free (base58 via @scure/base, blake2b via @noble/hashes) so core\n * stays decoupled from polkadot-api.\n */\nexport const isSs58Address = (address: string): boolean => {\n\tif (!address) return false;\n\n\tlet decoded: Uint8Array;\n\ttry {\n\t\tdecoded = base58.decode(address);\n\t} catch {\n\t\treturn false;\n\t}\n\n\t// First byte encodes the network prefix; the high bit is reserved/invalid.\n\tconst firstByte = decoded[0];\n\tif (firstByte === undefined || firstByte & 0b1000_0000) return false;\n\t// The 0b0100_0000 bit marks a 2-byte prefix.\n\tconst prefixLength = firstByte & 0b0100_0000 ? 2 : 1;\n\n\t// AccountId32 layout: prefix + 32-byte pubkey + 2-byte checksum.\n\tif (decoded.length !== prefixLength + 32 + 2) return false;\n\n\tconst body = decoded.subarray(0, decoded.length - 2);\n\tconst preimage = new Uint8Array(SS58PRE.length + body.length);\n\tpreimage.set(SS58PRE);\n\tpreimage.set(body, SS58PRE.length);\n\tconst hash = blake2b(preimage, { dkLen: 64 });\n\n\treturn (\n\t\tdecoded[decoded.length - 2] === hash[0] &&\n\t\tdecoded[decoded.length - 1] === hash[1]\n\t);\n};\n","import { isEthereumAddress } from \"./isEthereumAddress\";\nimport { isSolanaAddress } from \"./isSolanaAddress\";\nimport { isSs58Address } from \"./isSs58Address\";\n\nexport const isValidAddress = (address: string): boolean => {\n\tif (address.startsWith(\"0x\")) return isEthereumAddress(address);\n\t// SS58 (checksummed) and Solana (base58, no checksum) are disjoint: a\n\t// 32-byte Solana pubkey fails SS58 decoding, and an SS58 address decodes to\n\t// more than 32 bytes so it fails the Solana length check.\n\treturn isSs58Address(address) || isSolanaAddress(address);\n};\n","import { isValidAddress } from \"./isValidAddress\";\n\nexport type WalletAccountId = string;\n\nexport const getWalletAccountId = (\n\twalletId: string,\n\taddress: string,\n): WalletAccountId => {\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn `${walletId}::${address}`;\n};\n\nexport const parseWalletAccountId = (accountId: string) => {\n\tif (!accountId) throw new Error(\"Invalid walletAccountId\");\n\tconst [walletId, address] = accountId.split(\"::\");\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!address || !isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn { walletId, address };\n};\n","import {\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tof,\n\tSubscription,\n\tshareReplay,\n} from \"rxjs\";\nimport { getCachedObservable$ } from \"../utils/getCachedObservable\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\n\nexport type LiveWalletConnectWallet = Exclude<\n\tWalletConnectWallet,\n\t{ isPlaceholder: true }\n>;\n\nexport type PlatformAccountsOptions<\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n> = {\n\t/** This platform's wallets plus the shared WalletConnect connector. */\n\twallets$: Observable<(TWallet | WalletConnectWallet)[]>;\n\t/** Account stream for one connected injected wallet. */\n\tgetInjectedAccounts$: (wallet: TWallet) => Observable<TAccount[]>;\n\t/** Account stream for the WalletConnect connector. */\n\tgetWalletConnectAccounts$: (\n\t\twallet: LiveWalletConnectWallet,\n\t) => Observable<TAccount[]>;\n\t/** Optional post-flatten transform (e.g. Polkadot's `accountTypes` filter). */\n\tmapAccounts?: (accounts: TAccount[]) => TAccount[];\n\t/**\n\t * Signature of the account fields that should trigger a re-emission.\n\t * Defaults to the account id; platforms add mutable fields (Ethereum\n\t * `chainId`, Solana `chains`).\n\t */\n\taccountChangeKey?: (account: TAccount) => string;\n};\n\n/** The account list plus the connected wallets whose stream has answered, an empty list included. */\nexport type PlatformAccountsFrame<TAccount> = {\n\taccounts: TAccount[];\n\tanswered: WalletId[];\n};\n\nexport type PlatformAccounts$<TAccount> = Observable<TAccount[]> & {\n\tframes$: Observable<PlatformAccountsFrame<TAccount>>;\n};\n\nconst isPlatformAccounts$ = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): accounts$ is PlatformAccounts$<TAccount> => \"frames$\" in accounts$;\n\n/** A plugin not built on `createPlatformAccounts$` reports no answered wallet. */\nexport const framesOf = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): Observable<PlatformAccountsFrame<TAccount>> =>\n\tisPlatformAccounts$(accounts$)\n\t\t? accounts$.frames$\n\t\t: accounts$.pipe(map((accounts) => ({ accounts, answered: [] })));\n\nconst idsEqual = (a: WalletId[], b: WalletId[]) =>\n\ta.length === b.length && a.every((id, i) => id === b[i]);\n\ntype WalletConnection<TAccount> = {\n\tkey: string;\n\taccounts: TAccount[];\n\tanswered: boolean;\n\tcompleted: boolean;\n\tsubscription: Subscription;\n};\n\nconst sessionKey = (wallet: WalletConnectWallet): string =>\n\t`${wallet.id}|${wallet.platforms.join(\",\")}`;\n\nconst connectionKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\tisWalletConnectWallet(wallet) ? sessionKey(wallet) : wallet.id;\n\n/** Shared engine behind every platform's `getAccounts$`. */\nexport const createPlatformAccounts$ = <\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n>({\n\twallets$,\n\tgetInjectedAccounts$,\n\tgetWalletConnectAccounts$,\n\tmapAccounts,\n\taccountChangeKey = (account) => account.id,\n}: PlatformAccountsOptions<TWallet, TAccount>): PlatformAccounts$<TAccount> => {\n\ttype Frame = PlatformAccountsFrame<TAccount>;\n\tconst nameAndChangeKey = (account: TAccount) =>\n\t\t`${account.name ?? \"\"}|${accountChangeKey(account)}`;\n\tconst accountsListEqual = (a: TAccount[], b: TAccount[]) =>\n\t\ta.length === b.length &&\n\t\ta.every((account, i) => {\n\t\t\tconst other = b[i];\n\t\t\treturn !!other && nameAndChangeKey(account) === nameAndChangeKey(other);\n\t\t});\n\tconst accountsOf = (wallet: TWallet | LiveWalletConnectWallet) =>\n\t\tisWalletConnectWallet(wallet)\n\t\t\t? getWalletConnectAccounts$(wallet)\n\t\t\t: getInjectedAccounts$(wallet);\n\n\tconst frames$ = new Observable<Frame>((subscriber) => {\n\t\tconst connections = new Map<WalletId, WalletConnection<TAccount>>();\n\t\tlet connectedIds: WalletId[] = [];\n\t\tlet walletsCompleted = false;\n\t\tlet emitted = false;\n\n\t\tconst awaitingFirstAnswers = () =>\n\t\t\t!emitted &&\n\t\t\t[...connections.values()].some((connection) => !connection.answered);\n\n\t\tconst accountsListed = () =>\n\t\t\tconnectedIds.flatMap((id) => connections.get(id)?.accounts ?? []);\n\t\tconst walletsAnswered = () =>\n\t\t\tconnectedIds.filter((id) => connections.get(id)?.answered);\n\n\t\tconst emit = () => {\n\t\t\tif (awaitingFirstAnswers()) return;\n\t\t\temitted = true;\n\t\t\tsubscriber.next({\n\t\t\t\taccounts: accountsListed(),\n\t\t\t\tanswered: walletsAnswered(),\n\t\t\t});\n\t\t};\n\n\t\tconst completeIfDone = () => {\n\t\t\tif (\n\t\t\t\twalletsCompleted &&\n\t\t\t\t[...connections.values()].every((connection) => connection.completed)\n\t\t\t)\n\t\t\t\tsubscriber.complete();\n\t\t};\n\n\t\tconst reconcile = (wallets: (TWallet | WalletConnectWallet)[]) => {\n\t\t\tconst connected = wallets.filter(\n\t\t\t\t(wallet): wallet is TWallet | LiveWalletConnectWallet =>\n\t\t\t\t\twallet.isConnected && !wallet.isPlaceholder,\n\t\t\t);\n\t\t\tconst keys = new Map(\n\t\t\t\tconnected.map((w) => [w.id, connectionKey(w)] as const),\n\t\t\t);\n\t\t\tfor (const [id, connection] of connections) {\n\t\t\t\tif (keys.get(id) === connection.key) continue;\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t\t\tconnections.delete(id);\n\t\t\t}\n\t\t\tconnectedIds = connected.map((wallet) => wallet.id);\n\t\t\tconst opened = connected\n\t\t\t\t.filter((wallet) => !connections.has(wallet.id))\n\t\t\t\t.map((wallet) => {\n\t\t\t\t\tconst connection: WalletConnection<TAccount> = {\n\t\t\t\t\t\tkey: connectionKey(wallet),\n\t\t\t\t\t\taccounts: [],\n\t\t\t\t\t\tanswered: false,\n\t\t\t\t\t\tcompleted: false,\n\t\t\t\t\t\tsubscription: new Subscription(),\n\t\t\t\t\t};\n\t\t\t\t\tconnections.set(wallet.id, connection);\n\t\t\t\t\treturn { wallet, connection };\n\t\t\t\t});\n\t\t\tfor (const { wallet, connection } of opened) {\n\t\t\t\tconnection.subscription.add(\n\t\t\t\t\taccountsOf(wallet).subscribe({\n\t\t\t\t\t\tnext: (accounts) => {\n\t\t\t\t\t\t\tconnection.accounts = accounts;\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror: (error) => {\n\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t`[kheopskit] Could not list the accounts of ${wallet.id}`,\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconnection.accounts = [];\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t\tcompleteIfDone();\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcomplete: () => {\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\tcompleteIfDone();\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\temit();\n\t\t};\n\n\t\tconst sub = wallets$.subscribe({\n\t\t\tnext: reconcile,\n\t\t\terror: (error) => subscriber.error(error),\n\t\t\tcomplete: () => {\n\t\t\t\twalletsCompleted = true;\n\t\t\t\tcompleteIfDone();\n\t\t\t},\n\t\t});\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t\tfor (const connection of connections.values())\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tmap((frame) =>\n\t\t\tmapAccounts ? { ...frame, accounts: mapAccounts(frame.accounts) } : frame,\n\t\t),\n\t\tdistinctUntilChanged(\n\t\t\t(a, b) =>\n\t\t\t\taccountsListEqual(a.accounts, b.accounts) &&\n\t\t\t\tidsEqual(a.answered, b.answered),\n\t\t),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\tconst accounts$ = frames$.pipe(\n\t\tmap((frame) => frame.accounts),\n\t\tdistinctUntilChanged(accountsListEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\treturn Object.assign(accounts$, { frames$ });\n};\n\n/**\n * CAIP-10 account strings (\"<namespace>:<chainRef>:<address>\") the live\n * WalletConnect session carries for a namespace.\n */\nexport const getSessionCaip10s = (\n\tsession: NonNullable<WalletConnectProvider[\"session\"]>,\n\tnamespace: string,\n): string[] =>\n\tObject.values(session.namespaces)\n\t\t.flatMap((ns) => ns.accounts ?? [])\n\t\t.filter((account) => account.startsWith(`${namespace}:`));\n\n/**\n * Unique addresses from CAIP-10 account strings (one entry per chain, so the\n * same address repeats — dedupe).\n */\nexport const getCaip10Addresses = (caip10s: string[]): string[] => [\n\t...new Set(\n\t\tcaip10s\n\t\t\t.map((account) => account.split(\":\")[2])\n\t\t\t.filter((address): address is string => !!address),\n\t),\n];\n\n/**\n * Shared shape of the Polkadot/Solana WalletConnect account streams: no-op\n * unless the session carries the platform's namespace, then a cached\n * observable that rebuilds the account list from the session on\n * `session_update` / `accountsChanged`.\n *\n * AppKit's `getAccount(namespace).allAccounts` is always empty for namespaces\n * without a native AppKit adapter — the WalletConnect session is the source of\n * truth, hence the session-driven rebuild.\n */\nexport const getWalletConnectSessionAccounts$ = <\n\tTAccount extends BaseWalletAccount,\n>(options: {\n\twallet: LiveWalletConnectWallet;\n\tplatform: WalletPlatform;\n\t/** WalletConnect namespace, e.g. \"polkadot\" | \"solana\" | \"eip155\". */\n\tnamespace: string;\n\t/** Cache key for {@link getCachedObservable$} — must be reconnect-safe. */\n\tcacheKey: string;\n\t/** Build the account list from the live session. */\n\tbuildAccounts: (provider: WalletConnectProvider) => TAccount[];\n}): Observable<TAccount[]> => {\n\tconst { wallet, platform, namespace, cacheKey, buildAccounts } = options;\n\tconst provider = wallet.appKit.getProvider(namespace);\n\n\tif (!wallet.platforms.includes(platform) || !provider?.session) return of([]);\n\n\treturn getCachedObservable$(cacheKey, () =>\n\t\tnew Observable<TAccount[]>((subscriber) => {\n\t\t\tsubscriber.next(buildAccounts(provider));\n\n\t\t\t// Re-derive when the WalletConnect session's accounts change, mirroring\n\t\t\t// the injected paths' change subscriptions.\n\t\t\tconst reemit = () => subscriber.next(buildAccounts(provider));\n\t\t\tprovider.on(\"session_update\", reemit);\n\t\t\tprovider.on(\"accountsChanged\", reemit);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"session_update\", reemit);\n\t\t\t\tprovider.off(\"accountsChanged\", reemit);\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n"],"mappings":";;;;;;AAEA,MAAM,cAAc;AACpB,MAAM,UAAU,IAAI,YAAY;;;;;AAMhC,MAAM,mBAAmB,YAA6B;CACrD,MAAM,MAAM,QAAQ,MAAM,CAAC;CAC3B,MAAM,OAAO,WAAW,QAAQ,OAAO,IAAI,YAAY,CAAC,CAAC;CACzD,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK;EAC5B,MAAM,OAAO,IAAI,OAAO,CAAC;EAGzB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/utils/isValidAddress.ts","../src/utils/WalletAccountId.ts","../src/api/platformAccounts.ts"],"sourcesContent":["import { keccak_256 } from \"@noble/hashes/sha3.js\";\n\nconst HEX_ADDRESS = /^0x[0-9a-fA-F]{40}$/;\nconst encoder = new TextEncoder();\n\n/**\n * Verifies the EIP-55 mixed-case checksum of an Ethereum address.\n * Dependency-free (keccak via @noble/hashes) so core stays decoupled from viem.\n */\nconst isChecksumValid = (address: string): boolean => {\n\tconst hex = address.slice(2);\n\tconst hash = keccak_256(encoder.encode(hex.toLowerCase()));\n\tfor (let i = 0; i < 40; i++) {\n\t\tconst char = hex.charAt(i);\n\t\tconst isLetter =\n\t\t\t(char >= \"a\" && char <= \"f\") || (char >= \"A\" && char <= \"F\");\n\t\tif (!isLetter) continue;\n\t\tconst byte = hash[i >> 1] ?? 0;\n\t\tconst nibble = i % 2 === 0 ? byte >> 4 : byte & 0x0f;\n\t\tconst isUpper = char <= \"F\";\n\t\tif (isUpper !== nibble >= 8) return false;\n\t}\n\treturn true;\n};\n\n/**\n * Returns true if `address` is a valid Ethereum address.\n *\n * Mirrors viem's `isAddress` (strict): the shape must be `0x` + 40 hex, and a\n * mixed-case address must pass the EIP-55 checksum. All-lowercase addresses are\n * accepted as non-checksummed.\n */\nexport const isEthereumAddress = (address: string): boolean => {\n\tif (!HEX_ADDRESS.test(address)) return false;\n\tif (address === address.toLowerCase()) return true;\n\treturn isChecksumValid(address);\n};\n","import { base58 } from \"@scure/base\";\n\n/**\n * Returns true if the value is a valid Solana address: a base58-encoded\n * 32-byte ed25519 public key.\n *\n * Solana addresses carry no checksum, so this is a pure base58 + length check.\n * Dependency-free (base58 via @scure/base) so core stays decoupled from\n * @solana/kit.\n */\nexport const isSolanaAddress = (address: string): boolean => {\n\tif (!address) return false;\n\ttry {\n\t\treturn base58.decode(address).length === 32;\n\t} catch {\n\t\treturn false;\n\t}\n};\n","import { blake2b } from \"@noble/hashes/blake2.js\";\nimport { base58 } from \"@scure/base\";\n\n// The \"SS58PRE\" prefix used in the SS58 checksum preimage.\nconst SS58PRE = new Uint8Array([0x53, 0x53, 0x35, 0x38, 0x50, 0x52, 0x45]);\n\n/**\n * Returns true if `address` is a valid SS58-encoded 32-byte account id (the\n * only form Substrate wallets inject), verifying the blake2b-512 checksum.\n *\n * Dependency-free (base58 via @scure/base, blake2b via @noble/hashes) so core\n * stays decoupled from polkadot-api.\n */\nexport const isSs58Address = (address: string): boolean => {\n\tif (!address) return false;\n\n\tlet decoded: Uint8Array;\n\ttry {\n\t\tdecoded = base58.decode(address);\n\t} catch {\n\t\treturn false;\n\t}\n\n\t// First byte encodes the network prefix; the high bit is reserved/invalid.\n\tconst firstByte = decoded[0];\n\tif (firstByte === undefined || firstByte & 0b1000_0000) return false;\n\t// The 0b0100_0000 bit marks a 2-byte prefix.\n\tconst prefixLength = firstByte & 0b0100_0000 ? 2 : 1;\n\n\t// AccountId32 layout: prefix + 32-byte pubkey + 2-byte checksum.\n\tif (decoded.length !== prefixLength + 32 + 2) return false;\n\n\tconst body = decoded.subarray(0, decoded.length - 2);\n\tconst preimage = new Uint8Array(SS58PRE.length + body.length);\n\tpreimage.set(SS58PRE);\n\tpreimage.set(body, SS58PRE.length);\n\tconst hash = blake2b(preimage, { dkLen: 64 });\n\n\treturn (\n\t\tdecoded[decoded.length - 2] === hash[0] &&\n\t\tdecoded[decoded.length - 1] === hash[1]\n\t);\n};\n","import { isEthereumAddress } from \"./isEthereumAddress\";\nimport { isSolanaAddress } from \"./isSolanaAddress\";\nimport { isSs58Address } from \"./isSs58Address\";\n\nexport const isValidAddress = (address: string): boolean => {\n\tif (address.startsWith(\"0x\")) return isEthereumAddress(address);\n\t// SS58 (checksummed) and Solana (base58, no checksum) are disjoint: a\n\t// 32-byte Solana pubkey fails SS58 decoding, and an SS58 address decodes to\n\t// more than 32 bytes so it fails the Solana length check.\n\treturn isSs58Address(address) || isSolanaAddress(address);\n};\n","import { isValidAddress } from \"./isValidAddress\";\n\nexport type WalletAccountId = string;\n\nexport const getWalletAccountId = (\n\twalletId: string,\n\taddress: string,\n): WalletAccountId => {\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn `${walletId}::${address}`;\n};\n\nexport const parseWalletAccountId = (accountId: string) => {\n\tif (!accountId) throw new Error(\"Invalid walletAccountId\");\n\tconst [walletId, address] = accountId.split(\"::\");\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!address || !isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn { walletId, address };\n};\n","import {\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tof,\n\tSubscription,\n\tshareReplay,\n} from \"rxjs\";\nimport { getCachedObservable$ } from \"../utils/getCachedObservable\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\n\nexport type LiveWalletConnectWallet = Exclude<\n\tWalletConnectWallet,\n\t{ isPlaceholder: true }\n>;\n\nexport type PlatformAccountsOptions<\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n> = {\n\t/** This platform's wallets plus the shared WalletConnect connector. */\n\twallets$: Observable<(TWallet | WalletConnectWallet)[]>;\n\t/** Account stream for one connected injected wallet. */\n\tgetInjectedAccounts$: (wallet: TWallet) => Observable<TAccount[]>;\n\t/** Account stream for the WalletConnect connector. */\n\tgetWalletConnectAccounts$: (\n\t\twallet: LiveWalletConnectWallet,\n\t) => Observable<TAccount[]>;\n\t/** Optional post-flatten transform (e.g. Polkadot's `accountTypes` filter). */\n\tmapAccounts?: (accounts: TAccount[]) => TAccount[];\n\t/**\n\t * Signature of the account fields that should trigger a re-emission.\n\t * Defaults to the account id; platforms add mutable fields (Ethereum\n\t * `chainId`, Solana `chains`).\n\t */\n\taccountChangeKey?: (account: TAccount) => string;\n};\n\n/** The account list plus the connected wallets whose stream has answered, an empty list included. */\nexport type PlatformAccountsFrame<TAccount> = {\n\taccounts: TAccount[];\n\tanswered: WalletId[];\n};\n\nexport type PlatformAccounts$<TAccount> = Observable<TAccount[]> & {\n\tframes$: Observable<PlatformAccountsFrame<TAccount>>;\n};\n\nconst isPlatformAccounts$ = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): accounts$ is PlatformAccounts$<TAccount> => \"frames$\" in accounts$;\n\n/** A plugin not built on `createPlatformAccounts$` reports no answered wallet. */\nexport const framesOf = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): Observable<PlatformAccountsFrame<TAccount>> =>\n\tisPlatformAccounts$(accounts$)\n\t\t? accounts$.frames$\n\t\t: accounts$.pipe(map((accounts) => ({ accounts, answered: [] })));\n\nconst idsEqual = (a: WalletId[], b: WalletId[]) =>\n\ta.length === b.length && a.every((id, i) => id === b[i]);\n\ntype WalletConnection<TAccount> = {\n\tkey: string;\n\taccounts: TAccount[];\n\tanswered: boolean;\n\tcompleted: boolean;\n\tsubscription: Subscription;\n};\n\nconst sessionKey = (wallet: WalletConnectWallet): string =>\n\t`${wallet.id}|${wallet.platforms.join(\",\")}`;\n\nconst connectionKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\tisWalletConnectWallet(wallet) ? sessionKey(wallet) : wallet.id;\n\n/** Shared engine behind every platform's `getAccounts$`. */\nexport const createPlatformAccounts$ = <\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n>({\n\twallets$,\n\tgetInjectedAccounts$,\n\tgetWalletConnectAccounts$,\n\tmapAccounts,\n\taccountChangeKey = (account) => account.id,\n}: PlatformAccountsOptions<TWallet, TAccount>): PlatformAccounts$<TAccount> => {\n\ttype Frame = PlatformAccountsFrame<TAccount>;\n\tconst nameAndChangeKey = (account: TAccount) =>\n\t\t`${account.name ?? \"\"}|${accountChangeKey(account)}`;\n\tconst accountsListEqual = (a: TAccount[], b: TAccount[]) =>\n\t\ta.length === b.length &&\n\t\ta.every((account, i) => {\n\t\t\tconst other = b[i];\n\t\t\treturn !!other && nameAndChangeKey(account) === nameAndChangeKey(other);\n\t\t});\n\tconst accountsOf = (wallet: TWallet | LiveWalletConnectWallet) =>\n\t\tisWalletConnectWallet(wallet)\n\t\t\t? getWalletConnectAccounts$(wallet)\n\t\t\t: getInjectedAccounts$(wallet);\n\n\tconst frames$ = new Observable<Frame>((subscriber) => {\n\t\tconst connections = new Map<WalletId, WalletConnection<TAccount>>();\n\t\tlet connectedIds: WalletId[] = [];\n\t\tlet walletsCompleted = false;\n\t\tlet emitted = false;\n\n\t\tconst awaitingFirstAnswers = () =>\n\t\t\t!emitted &&\n\t\t\t[...connections.values()].some((connection) => !connection.answered);\n\n\t\tconst accountsListed = () =>\n\t\t\tconnectedIds.flatMap((id) => connections.get(id)?.accounts ?? []);\n\t\tconst walletsAnswered = () =>\n\t\t\tconnectedIds.filter((id) => connections.get(id)?.answered);\n\n\t\tconst emit = () => {\n\t\t\tif (awaitingFirstAnswers()) return;\n\t\t\temitted = true;\n\t\t\tsubscriber.next({\n\t\t\t\taccounts: accountsListed(),\n\t\t\t\tanswered: walletsAnswered(),\n\t\t\t});\n\t\t};\n\n\t\tconst completeIfDone = () => {\n\t\t\tif (\n\t\t\t\twalletsCompleted &&\n\t\t\t\t[...connections.values()].every((connection) => connection.completed)\n\t\t\t)\n\t\t\t\tsubscriber.complete();\n\t\t};\n\n\t\tconst reconcile = (wallets: (TWallet | WalletConnectWallet)[]) => {\n\t\t\tconst connected = wallets.filter(\n\t\t\t\t(wallet): wallet is TWallet | LiveWalletConnectWallet =>\n\t\t\t\t\twallet.isConnected && !wallet.isPlaceholder,\n\t\t\t);\n\t\t\tconst keys = new Map(\n\t\t\t\tconnected.map((w) => [w.id, connectionKey(w)] as const),\n\t\t\t);\n\t\t\tfor (const [id, connection] of connections) {\n\t\t\t\tif (keys.get(id) === connection.key) continue;\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t\t\tconnections.delete(id);\n\t\t\t}\n\t\t\tconnectedIds = connected.map((wallet) => wallet.id);\n\t\t\tconst opened = connected\n\t\t\t\t.filter((wallet) => !connections.has(wallet.id))\n\t\t\t\t.map((wallet) => {\n\t\t\t\t\tconst connection: WalletConnection<TAccount> = {\n\t\t\t\t\t\tkey: connectionKey(wallet),\n\t\t\t\t\t\taccounts: [],\n\t\t\t\t\t\tanswered: false,\n\t\t\t\t\t\tcompleted: false,\n\t\t\t\t\t\tsubscription: new Subscription(),\n\t\t\t\t\t};\n\t\t\t\t\tconnections.set(wallet.id, connection);\n\t\t\t\t\treturn { wallet, connection };\n\t\t\t\t});\n\t\t\tfor (const { wallet, connection } of opened) {\n\t\t\t\tconnection.subscription.add(\n\t\t\t\t\taccountsOf(wallet).subscribe({\n\t\t\t\t\t\tnext: (accounts) => {\n\t\t\t\t\t\t\tconnection.accounts = accounts;\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror: (error) => {\n\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t`[kheopskit] Could not list the accounts of ${wallet.id}`,\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconnection.accounts = [];\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t\tcompleteIfDone();\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcomplete: () => {\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\tcompleteIfDone();\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\temit();\n\t\t};\n\n\t\tconst sub = wallets$.subscribe({\n\t\t\tnext: reconcile,\n\t\t\terror: (error) => subscriber.error(error),\n\t\t\tcomplete: () => {\n\t\t\t\twalletsCompleted = true;\n\t\t\t\tcompleteIfDone();\n\t\t\t},\n\t\t});\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t\tfor (const connection of connections.values())\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tmap((frame) =>\n\t\t\tmapAccounts ? { ...frame, accounts: mapAccounts(frame.accounts) } : frame,\n\t\t),\n\t\tdistinctUntilChanged(\n\t\t\t(a, b) =>\n\t\t\t\taccountsListEqual(a.accounts, b.accounts) &&\n\t\t\t\tidsEqual(a.answered, b.answered),\n\t\t),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\tconst accounts$ = frames$.pipe(\n\t\tmap((frame) => frame.accounts),\n\t\tdistinctUntilChanged(accountsListEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\treturn Object.assign(accounts$, { frames$ });\n};\n\n/**\n * CAIP-10 account strings (\"<namespace>:<chainRef>:<address>\") the live\n * WalletConnect session carries for a namespace, limited to the entries\n * granting `method` when one is given.\n */\nexport const getSessionCaip10s = (\n\tsession: NonNullable<WalletConnectProvider[\"session\"]>,\n\tnamespace: string,\n\tmethod?: string,\n): string[] =>\n\tObject.values(session.namespaces)\n\t\t.filter((ns) => !method || ns.methods?.includes(method))\n\t\t.flatMap((ns) => ns.accounts ?? [])\n\t\t.filter((account) => account.startsWith(`${namespace}:`));\n\n/**\n * Unique addresses from CAIP-10 account strings (one entry per chain, so the\n * same address repeats — dedupe).\n */\nexport const getCaip10Addresses = (caip10s: string[]): string[] => [\n\t...new Set(\n\t\tcaip10s\n\t\t\t.map((account) => account.split(\":\")[2])\n\t\t\t.filter((address): address is string => !!address),\n\t),\n];\n\n/**\n * Shared shape of the Polkadot/Solana WalletConnect account streams: no-op\n * unless the session carries the platform's namespace, then a cached\n * observable that rebuilds the account list from the session on\n * `session_update` / `accountsChanged`.\n *\n * AppKit's `getAccount(namespace).allAccounts` is always empty for namespaces\n * without a native AppKit adapter — the WalletConnect session is the source of\n * truth, hence the session-driven rebuild.\n */\nexport const getWalletConnectSessionAccounts$ = <\n\tTAccount extends BaseWalletAccount,\n>(options: {\n\twallet: LiveWalletConnectWallet;\n\tplatform: WalletPlatform;\n\t/** WalletConnect namespace, e.g. \"polkadot\" | \"solana\" | \"eip155\". */\n\tnamespace: string;\n\t/** Cache key for {@link getCachedObservable$} — must be reconnect-safe. */\n\tcacheKey: string;\n\t/** Build the account list from the live session. */\n\tbuildAccounts: (provider: WalletConnectProvider) => TAccount[];\n}): Observable<TAccount[]> => {\n\tconst { wallet, platform, namespace, cacheKey, buildAccounts } = options;\n\tconst provider = wallet.appKit.getProvider(namespace);\n\n\tif (!wallet.platforms.includes(platform) || !provider?.session) return of([]);\n\n\treturn getCachedObservable$(cacheKey, () =>\n\t\tnew Observable<TAccount[]>((subscriber) => {\n\t\t\tsubscriber.next(buildAccounts(provider));\n\n\t\t\t// Re-derive when the WalletConnect session's accounts change, mirroring\n\t\t\t// the injected paths' change subscriptions.\n\t\t\tconst reemit = () => subscriber.next(buildAccounts(provider));\n\t\t\tprovider.on(\"session_update\", reemit);\n\t\t\tprovider.on(\"accountsChanged\", reemit);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"session_update\", reemit);\n\t\t\t\tprovider.off(\"accountsChanged\", reemit);\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n"],"mappings":";;;;;;AAEA,MAAM,cAAc;AACpB,MAAM,UAAU,IAAI,YAAY;;;;;AAMhC,MAAM,mBAAmB,YAA6B;CACrD,MAAM,MAAM,QAAQ,MAAM,CAAC;CAC3B,MAAM,OAAO,WAAW,QAAQ,OAAO,IAAI,YAAY,CAAC,CAAC;CACzD,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK;EAC5B,MAAM,OAAO,IAAI,OAAO,CAAC;EAGzB,IAAI,EADF,QAAQ,OAAO,QAAQ,OAAS,QAAQ,OAAO,QAAQ,MAC1C;EACf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P-10 account strings ("<namespace>:<chainRef>:<address>") the live
|
|
224
|
-
* WalletConnect session carries for a namespace
|
|
224
|
+
* WalletConnect session carries for a namespace, limited to the entries
|
|
225
|
+
* granting `method` when one is given.
|
|
225
226
|
*/
|
|
226
|
-
const getSessionCaip10s = (session, namespace) => Object.values(session.namespaces).flatMap((ns) => ns.accounts ?? []).filter((account) => account.startsWith(`${namespace}:`));
|
|
227
|
+
const getSessionCaip10s = (session, namespace, method) => Object.values(session.namespaces).filter((ns) => !method || ns.methods?.includes(method)).flatMap((ns) => ns.accounts ?? []).filter((account) => account.startsWith(`${namespace}:`));
|
|
227
228
|
/**
|
|
228
229
|
* Unique addresses from CAIP-10 account strings (one entry per chain, so the
|
|
229
230
|
* same address repeats — dedupe).
|
|
@@ -325,4 +326,4 @@ Object.defineProperty(exports, "parseWalletAccountId", {
|
|
|
325
326
|
}
|
|
326
327
|
});
|
|
327
328
|
|
|
328
|
-
//# sourceMappingURL=platformAccounts-
|
|
329
|
+
//# sourceMappingURL=platformAccounts-BcLoaZZb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformAccounts-CqMSpl3X.js","names":["keccak_256","base58","base58","blake2b","map","isWalletConnectWallet","Observable","Subscription","distinctUntilChanged","shareReplay","of","getCachedObservable$"],"sources":["../src/utils/isEthereumAddress.ts","../src/utils/isSolanaAddress.ts","../src/utils/isSs58Address.ts","../src/utils/isValidAddress.ts","../src/utils/WalletAccountId.ts","../src/api/platformAccounts.ts"],"sourcesContent":["import { keccak_256 } from \"@noble/hashes/sha3.js\";\n\nconst HEX_ADDRESS = /^0x[0-9a-fA-F]{40}$/;\nconst encoder = new TextEncoder();\n\n/**\n * Verifies the EIP-55 mixed-case checksum of an Ethereum address.\n * Dependency-free (keccak via @noble/hashes) so core stays decoupled from viem.\n */\nconst isChecksumValid = (address: string): boolean => {\n\tconst hex = address.slice(2);\n\tconst hash = keccak_256(encoder.encode(hex.toLowerCase()));\n\tfor (let i = 0; i < 40; i++) {\n\t\tconst char = hex.charAt(i);\n\t\tconst isLetter =\n\t\t\t(char >= \"a\" && char <= \"f\") || (char >= \"A\" && char <= \"F\");\n\t\tif (!isLetter) continue;\n\t\tconst byte = hash[i >> 1] ?? 0;\n\t\tconst nibble = i % 2 === 0 ? byte >> 4 : byte & 0x0f;\n\t\tconst isUpper = char <= \"F\";\n\t\tif (isUpper !== nibble >= 8) return false;\n\t}\n\treturn true;\n};\n\n/**\n * Returns true if `address` is a valid Ethereum address.\n *\n * Mirrors viem's `isAddress` (strict): the shape must be `0x` + 40 hex, and a\n * mixed-case address must pass the EIP-55 checksum. All-lowercase addresses are\n * accepted as non-checksummed.\n */\nexport const isEthereumAddress = (address: string): boolean => {\n\tif (!HEX_ADDRESS.test(address)) return false;\n\tif (address === address.toLowerCase()) return true;\n\treturn isChecksumValid(address);\n};\n","import { base58 } from \"@scure/base\";\n\n/**\n * Returns true if the value is a valid Solana address: a base58-encoded\n * 32-byte ed25519 public key.\n *\n * Solana addresses carry no checksum, so this is a pure base58 + length check.\n * Dependency-free (base58 via @scure/base) so core stays decoupled from\n * @solana/kit.\n */\nexport const isSolanaAddress = (address: string): boolean => {\n\tif (!address) return false;\n\ttry {\n\t\treturn base58.decode(address).length === 32;\n\t} catch {\n\t\treturn false;\n\t}\n};\n","import { blake2b } from \"@noble/hashes/blake2.js\";\nimport { base58 } from \"@scure/base\";\n\n// The \"SS58PRE\" prefix used in the SS58 checksum preimage.\nconst SS58PRE = new Uint8Array([0x53, 0x53, 0x35, 0x38, 0x50, 0x52, 0x45]);\n\n/**\n * Returns true if `address` is a valid SS58-encoded 32-byte account id (the\n * only form Substrate wallets inject), verifying the blake2b-512 checksum.\n *\n * Dependency-free (base58 via @scure/base, blake2b via @noble/hashes) so core\n * stays decoupled from polkadot-api.\n */\nexport const isSs58Address = (address: string): boolean => {\n\tif (!address) return false;\n\n\tlet decoded: Uint8Array;\n\ttry {\n\t\tdecoded = base58.decode(address);\n\t} catch {\n\t\treturn false;\n\t}\n\n\t// First byte encodes the network prefix; the high bit is reserved/invalid.\n\tconst firstByte = decoded[0];\n\tif (firstByte === undefined || firstByte & 0b1000_0000) return false;\n\t// The 0b0100_0000 bit marks a 2-byte prefix.\n\tconst prefixLength = firstByte & 0b0100_0000 ? 2 : 1;\n\n\t// AccountId32 layout: prefix + 32-byte pubkey + 2-byte checksum.\n\tif (decoded.length !== prefixLength + 32 + 2) return false;\n\n\tconst body = decoded.subarray(0, decoded.length - 2);\n\tconst preimage = new Uint8Array(SS58PRE.length + body.length);\n\tpreimage.set(SS58PRE);\n\tpreimage.set(body, SS58PRE.length);\n\tconst hash = blake2b(preimage, { dkLen: 64 });\n\n\treturn (\n\t\tdecoded[decoded.length - 2] === hash[0] &&\n\t\tdecoded[decoded.length - 1] === hash[1]\n\t);\n};\n","import { isEthereumAddress } from \"./isEthereumAddress\";\nimport { isSolanaAddress } from \"./isSolanaAddress\";\nimport { isSs58Address } from \"./isSs58Address\";\n\nexport const isValidAddress = (address: string): boolean => {\n\tif (address.startsWith(\"0x\")) return isEthereumAddress(address);\n\t// SS58 (checksummed) and Solana (base58, no checksum) are disjoint: a\n\t// 32-byte Solana pubkey fails SS58 decoding, and an SS58 address decodes to\n\t// more than 32 bytes so it fails the Solana length check.\n\treturn isSs58Address(address) || isSolanaAddress(address);\n};\n","import { isValidAddress } from \"./isValidAddress\";\n\nexport type WalletAccountId = string;\n\nexport const getWalletAccountId = (\n\twalletId: string,\n\taddress: string,\n): WalletAccountId => {\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn `${walletId}::${address}`;\n};\n\nexport const parseWalletAccountId = (accountId: string) => {\n\tif (!accountId) throw new Error(\"Invalid walletAccountId\");\n\tconst [walletId, address] = accountId.split(\"::\");\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!address || !isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn { walletId, address };\n};\n","import {\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tof,\n\tSubscription,\n\tshareReplay,\n} from \"rxjs\";\nimport { getCachedObservable$ } from \"../utils/getCachedObservable\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\n\nexport type LiveWalletConnectWallet = Exclude<\n\tWalletConnectWallet,\n\t{ isPlaceholder: true }\n>;\n\nexport type PlatformAccountsOptions<\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n> = {\n\t/** This platform's wallets plus the shared WalletConnect connector. */\n\twallets$: Observable<(TWallet | WalletConnectWallet)[]>;\n\t/** Account stream for one connected injected wallet. */\n\tgetInjectedAccounts$: (wallet: TWallet) => Observable<TAccount[]>;\n\t/** Account stream for the WalletConnect connector. */\n\tgetWalletConnectAccounts$: (\n\t\twallet: LiveWalletConnectWallet,\n\t) => Observable<TAccount[]>;\n\t/** Optional post-flatten transform (e.g. Polkadot's `accountTypes` filter). */\n\tmapAccounts?: (accounts: TAccount[]) => TAccount[];\n\t/**\n\t * Signature of the account fields that should trigger a re-emission.\n\t * Defaults to the account id; platforms add mutable fields (Ethereum\n\t * `chainId`, Solana `chains`).\n\t */\n\taccountChangeKey?: (account: TAccount) => string;\n};\n\n/** The account list plus the connected wallets whose stream has answered, an empty list included. */\nexport type PlatformAccountsFrame<TAccount> = {\n\taccounts: TAccount[];\n\tanswered: WalletId[];\n};\n\nexport type PlatformAccounts$<TAccount> = Observable<TAccount[]> & {\n\tframes$: Observable<PlatformAccountsFrame<TAccount>>;\n};\n\nconst isPlatformAccounts$ = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): accounts$ is PlatformAccounts$<TAccount> => \"frames$\" in accounts$;\n\n/** A plugin not built on `createPlatformAccounts$` reports no answered wallet. */\nexport const framesOf = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): Observable<PlatformAccountsFrame<TAccount>> =>\n\tisPlatformAccounts$(accounts$)\n\t\t? accounts$.frames$\n\t\t: accounts$.pipe(map((accounts) => ({ accounts, answered: [] })));\n\nconst idsEqual = (a: WalletId[], b: WalletId[]) =>\n\ta.length === b.length && a.every((id, i) => id === b[i]);\n\ntype WalletConnection<TAccount> = {\n\tkey: string;\n\taccounts: TAccount[];\n\tanswered: boolean;\n\tcompleted: boolean;\n\tsubscription: Subscription;\n};\n\nconst sessionKey = (wallet: WalletConnectWallet): string =>\n\t`${wallet.id}|${wallet.platforms.join(\",\")}`;\n\nconst connectionKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\tisWalletConnectWallet(wallet) ? sessionKey(wallet) : wallet.id;\n\n/** Shared engine behind every platform's `getAccounts$`. */\nexport const createPlatformAccounts$ = <\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n>({\n\twallets$,\n\tgetInjectedAccounts$,\n\tgetWalletConnectAccounts$,\n\tmapAccounts,\n\taccountChangeKey = (account) => account.id,\n}: PlatformAccountsOptions<TWallet, TAccount>): PlatformAccounts$<TAccount> => {\n\ttype Frame = PlatformAccountsFrame<TAccount>;\n\tconst nameAndChangeKey = (account: TAccount) =>\n\t\t`${account.name ?? \"\"}|${accountChangeKey(account)}`;\n\tconst accountsListEqual = (a: TAccount[], b: TAccount[]) =>\n\t\ta.length === b.length &&\n\t\ta.every((account, i) => {\n\t\t\tconst other = b[i];\n\t\t\treturn !!other && nameAndChangeKey(account) === nameAndChangeKey(other);\n\t\t});\n\tconst accountsOf = (wallet: TWallet | LiveWalletConnectWallet) =>\n\t\tisWalletConnectWallet(wallet)\n\t\t\t? getWalletConnectAccounts$(wallet)\n\t\t\t: getInjectedAccounts$(wallet);\n\n\tconst frames$ = new Observable<Frame>((subscriber) => {\n\t\tconst connections = new Map<WalletId, WalletConnection<TAccount>>();\n\t\tlet connectedIds: WalletId[] = [];\n\t\tlet walletsCompleted = false;\n\t\tlet emitted = false;\n\n\t\tconst awaitingFirstAnswers = () =>\n\t\t\t!emitted &&\n\t\t\t[...connections.values()].some((connection) => !connection.answered);\n\n\t\tconst accountsListed = () =>\n\t\t\tconnectedIds.flatMap((id) => connections.get(id)?.accounts ?? []);\n\t\tconst walletsAnswered = () =>\n\t\t\tconnectedIds.filter((id) => connections.get(id)?.answered);\n\n\t\tconst emit = () => {\n\t\t\tif (awaitingFirstAnswers()) return;\n\t\t\temitted = true;\n\t\t\tsubscriber.next({\n\t\t\t\taccounts: accountsListed(),\n\t\t\t\tanswered: walletsAnswered(),\n\t\t\t});\n\t\t};\n\n\t\tconst completeIfDone = () => {\n\t\t\tif (\n\t\t\t\twalletsCompleted &&\n\t\t\t\t[...connections.values()].every((connection) => connection.completed)\n\t\t\t)\n\t\t\t\tsubscriber.complete();\n\t\t};\n\n\t\tconst reconcile = (wallets: (TWallet | WalletConnectWallet)[]) => {\n\t\t\tconst connected = wallets.filter(\n\t\t\t\t(wallet): wallet is TWallet | LiveWalletConnectWallet =>\n\t\t\t\t\twallet.isConnected && !wallet.isPlaceholder,\n\t\t\t);\n\t\t\tconst keys = new Map(\n\t\t\t\tconnected.map((w) => [w.id, connectionKey(w)] as const),\n\t\t\t);\n\t\t\tfor (const [id, connection] of connections) {\n\t\t\t\tif (keys.get(id) === connection.key) continue;\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t\t\tconnections.delete(id);\n\t\t\t}\n\t\t\tconnectedIds = connected.map((wallet) => wallet.id);\n\t\t\tconst opened = connected\n\t\t\t\t.filter((wallet) => !connections.has(wallet.id))\n\t\t\t\t.map((wallet) => {\n\t\t\t\t\tconst connection: WalletConnection<TAccount> = {\n\t\t\t\t\t\tkey: connectionKey(wallet),\n\t\t\t\t\t\taccounts: [],\n\t\t\t\t\t\tanswered: false,\n\t\t\t\t\t\tcompleted: false,\n\t\t\t\t\t\tsubscription: new Subscription(),\n\t\t\t\t\t};\n\t\t\t\t\tconnections.set(wallet.id, connection);\n\t\t\t\t\treturn { wallet, connection };\n\t\t\t\t});\n\t\t\tfor (const { wallet, connection } of opened) {\n\t\t\t\tconnection.subscription.add(\n\t\t\t\t\taccountsOf(wallet).subscribe({\n\t\t\t\t\t\tnext: (accounts) => {\n\t\t\t\t\t\t\tconnection.accounts = accounts;\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror: (error) => {\n\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t`[kheopskit] Could not list the accounts of ${wallet.id}`,\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconnection.accounts = [];\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t\tcompleteIfDone();\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcomplete: () => {\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\tcompleteIfDone();\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\temit();\n\t\t};\n\n\t\tconst sub = wallets$.subscribe({\n\t\t\tnext: reconcile,\n\t\t\terror: (error) => subscriber.error(error),\n\t\t\tcomplete: () => {\n\t\t\t\twalletsCompleted = true;\n\t\t\t\tcompleteIfDone();\n\t\t\t},\n\t\t});\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t\tfor (const connection of connections.values())\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tmap((frame) =>\n\t\t\tmapAccounts ? { ...frame, accounts: mapAccounts(frame.accounts) } : frame,\n\t\t),\n\t\tdistinctUntilChanged(\n\t\t\t(a, b) =>\n\t\t\t\taccountsListEqual(a.accounts, b.accounts) &&\n\t\t\t\tidsEqual(a.answered, b.answered),\n\t\t),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\tconst accounts$ = frames$.pipe(\n\t\tmap((frame) => frame.accounts),\n\t\tdistinctUntilChanged(accountsListEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\treturn Object.assign(accounts$, { frames$ });\n};\n\n/**\n * CAIP-10 account strings (\"<namespace>:<chainRef>:<address>\") the live\n * WalletConnect session carries for a namespace.\n */\nexport const getSessionCaip10s = (\n\tsession: NonNullable<WalletConnectProvider[\"session\"]>,\n\tnamespace: string,\n): string[] =>\n\tObject.values(session.namespaces)\n\t\t.flatMap((ns) => ns.accounts ?? [])\n\t\t.filter((account) => account.startsWith(`${namespace}:`));\n\n/**\n * Unique addresses from CAIP-10 account strings (one entry per chain, so the\n * same address repeats — dedupe).\n */\nexport const getCaip10Addresses = (caip10s: string[]): string[] => [\n\t...new Set(\n\t\tcaip10s\n\t\t\t.map((account) => account.split(\":\")[2])\n\t\t\t.filter((address): address is string => !!address),\n\t),\n];\n\n/**\n * Shared shape of the Polkadot/Solana WalletConnect account streams: no-op\n * unless the session carries the platform's namespace, then a cached\n * observable that rebuilds the account list from the session on\n * `session_update` / `accountsChanged`.\n *\n * AppKit's `getAccount(namespace).allAccounts` is always empty for namespaces\n * without a native AppKit adapter — the WalletConnect session is the source of\n * truth, hence the session-driven rebuild.\n */\nexport const getWalletConnectSessionAccounts$ = <\n\tTAccount extends BaseWalletAccount,\n>(options: {\n\twallet: LiveWalletConnectWallet;\n\tplatform: WalletPlatform;\n\t/** WalletConnect namespace, e.g. \"polkadot\" | \"solana\" | \"eip155\". */\n\tnamespace: string;\n\t/** Cache key for {@link getCachedObservable$} — must be reconnect-safe. */\n\tcacheKey: string;\n\t/** Build the account list from the live session. */\n\tbuildAccounts: (provider: WalletConnectProvider) => TAccount[];\n}): Observable<TAccount[]> => {\n\tconst { wallet, platform, namespace, cacheKey, buildAccounts } = options;\n\tconst provider = wallet.appKit.getProvider(namespace);\n\n\tif (!wallet.platforms.includes(platform) || !provider?.session) return of([]);\n\n\treturn getCachedObservable$(cacheKey, () =>\n\t\tnew Observable<TAccount[]>((subscriber) => {\n\t\t\tsubscriber.next(buildAccounts(provider));\n\n\t\t\t// Re-derive when the WalletConnect session's accounts change, mirroring\n\t\t\t// the injected paths' change subscriptions.\n\t\t\tconst reemit = () => subscriber.next(buildAccounts(provider));\n\t\t\tprovider.on(\"session_update\", reemit);\n\t\t\tprovider.on(\"accountsChanged\", reemit);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"session_update\", reemit);\n\t\t\t\tprovider.off(\"accountsChanged\", reemit);\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n"],"mappings":";;;;;;AAEA,MAAM,cAAc;AACpB,MAAM,UAAU,IAAI,YAAY;;;;;AAMhC,MAAM,mBAAmB,YAA6B;CACrD,MAAM,MAAM,QAAQ,MAAM,CAAC;CAC3B,MAAM,QAAA,GAAOA,sBAAAA,WAAAA,CAAW,QAAQ,OAAO,IAAI,YAAY,CAAC,CAAC;CACzD,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK;EAC5B,MAAM,OAAO,IAAI,OAAO,CAAC;EAGzB,IAAI,EADF,QAAQ,OAAO,QAAQ,OAAS,QAAQ,OAAO,QAAQ,MAC1C;EACf,MAAM,OAAO,KAAK,KAAK,MAAM;EAC7B,MAAM,SAAS,IAAI,MAAM,IAAI,QAAQ,IAAI,OAAO;EAEhD,IADgB,QAAQ,QACR,UAAU,GAAG,OAAO;CACrC;CACA,OAAO;AACR;;;;;;;;AASA,MAAa,qBAAqB,YAA6B;CAC9D,IAAI,CAAC,YAAY,KAAK,OAAO,GAAG,OAAO;CACvC,IAAI,YAAY,QAAQ,YAAY,GAAG,OAAO;CAC9C,OAAO,gBAAgB,OAAO;AAC/B;;;;;;;;;;;AC1BA,MAAa,mBAAmB,YAA6B;CAC5D,IAAI,CAAC,SAAS,OAAO;CACrB,IAAI;EACH,O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,GAAG,YAAY,CAAC,CAAC,CAAC,CAClC,QAAQ,YAAY,QAAQ,WAAW,GAAG,UAAU,EAAE,CAAC;;;;;AAM1D,MAAa,sBAAsB,YAAgC,CAClE,GAAG,IAAI,IACN,QACE,KAAK,YAAY,QAAQ,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,CACvC,QAAQ,YAA+B,CAAC,CAAC,OAAO,CACnD,CACD;;;;;;;;;;;AAYA,MAAa,oCAEX,YAS4B;CAC7B,MAAM,EAAE,QAAQ,UAAU,WAAW,UAAU,kBAAkB;CACjE,MAAM,WAAW,OAAO,OAAO,YAAY,SAAS;CAEpD,IAAI,CAAC,OAAO,UAAU,SAAS,QAAQ,KAAK,CAAC,UAAU,SAAS,QAAA,GAAOC,KAAAA,GAAAA,CAAG,CAAC,CAAC;CAE5E,OAAOC,cAAAA,qBAAqB,gBAC3B,IAAIL,KAAAA,YAAwB,eAAe;EAC1C,WAAW,KAAK,cAAc,QAAQ,CAAC;EAIvC,MAAM,eAAe,WAAW,KAAK,cAAc,QAAQ,CAAC;EAC5D,SAAS,GAAG,kBAAkB,MAAM;EACpC,SAAS,GAAG,mBAAmB,MAAM;EAErC,aAAa;GACZ,SAAS,IAAI,kBAAkB,MAAM;GACrC,SAAS,IAAI,mBAAmB,MAAM;EACvC;CACD,CAAC,CAAC,CAAC,MAAA,GAAKG,KAAAA,YAAAA,CAAY;EAAE,UAAU;EAAM,YAAY;CAAE,CAAC,CAAC,CACvD;AACD"}
|
|
1
|
+
{"version":3,"file":"platformAccounts-BcLoaZZb.js","names":["keccak_256","base58","base58","blake2b","map","isWalletConnectWallet","Observable","Subscription","distinctUntilChanged","shareReplay","of","getCachedObservable$"],"sources":["../src/utils/isEthereumAddress.ts","../src/utils/isSolanaAddress.ts","../src/utils/isSs58Address.ts","../src/utils/isValidAddress.ts","../src/utils/WalletAccountId.ts","../src/api/platformAccounts.ts"],"sourcesContent":["import { keccak_256 } from \"@noble/hashes/sha3.js\";\n\nconst HEX_ADDRESS = /^0x[0-9a-fA-F]{40}$/;\nconst encoder = new TextEncoder();\n\n/**\n * Verifies the EIP-55 mixed-case checksum of an Ethereum address.\n * Dependency-free (keccak via @noble/hashes) so core stays decoupled from viem.\n */\nconst isChecksumValid = (address: string): boolean => {\n\tconst hex = address.slice(2);\n\tconst hash = keccak_256(encoder.encode(hex.toLowerCase()));\n\tfor (let i = 0; i < 40; i++) {\n\t\tconst char = hex.charAt(i);\n\t\tconst isLetter =\n\t\t\t(char >= \"a\" && char <= \"f\") || (char >= \"A\" && char <= \"F\");\n\t\tif (!isLetter) continue;\n\t\tconst byte = hash[i >> 1] ?? 0;\n\t\tconst nibble = i % 2 === 0 ? byte >> 4 : byte & 0x0f;\n\t\tconst isUpper = char <= \"F\";\n\t\tif (isUpper !== nibble >= 8) return false;\n\t}\n\treturn true;\n};\n\n/**\n * Returns true if `address` is a valid Ethereum address.\n *\n * Mirrors viem's `isAddress` (strict): the shape must be `0x` + 40 hex, and a\n * mixed-case address must pass the EIP-55 checksum. All-lowercase addresses are\n * accepted as non-checksummed.\n */\nexport const isEthereumAddress = (address: string): boolean => {\n\tif (!HEX_ADDRESS.test(address)) return false;\n\tif (address === address.toLowerCase()) return true;\n\treturn isChecksumValid(address);\n};\n","import { base58 } from \"@scure/base\";\n\n/**\n * Returns true if the value is a valid Solana address: a base58-encoded\n * 32-byte ed25519 public key.\n *\n * Solana addresses carry no checksum, so this is a pure base58 + length check.\n * Dependency-free (base58 via @scure/base) so core stays decoupled from\n * @solana/kit.\n */\nexport const isSolanaAddress = (address: string): boolean => {\n\tif (!address) return false;\n\ttry {\n\t\treturn base58.decode(address).length === 32;\n\t} catch {\n\t\treturn false;\n\t}\n};\n","import { blake2b } from \"@noble/hashes/blake2.js\";\nimport { base58 } from \"@scure/base\";\n\n// The \"SS58PRE\" prefix used in the SS58 checksum preimage.\nconst SS58PRE = new Uint8Array([0x53, 0x53, 0x35, 0x38, 0x50, 0x52, 0x45]);\n\n/**\n * Returns true if `address` is a valid SS58-encoded 32-byte account id (the\n * only form Substrate wallets inject), verifying the blake2b-512 checksum.\n *\n * Dependency-free (base58 via @scure/base, blake2b via @noble/hashes) so core\n * stays decoupled from polkadot-api.\n */\nexport const isSs58Address = (address: string): boolean => {\n\tif (!address) return false;\n\n\tlet decoded: Uint8Array;\n\ttry {\n\t\tdecoded = base58.decode(address);\n\t} catch {\n\t\treturn false;\n\t}\n\n\t// First byte encodes the network prefix; the high bit is reserved/invalid.\n\tconst firstByte = decoded[0];\n\tif (firstByte === undefined || firstByte & 0b1000_0000) return false;\n\t// The 0b0100_0000 bit marks a 2-byte prefix.\n\tconst prefixLength = firstByte & 0b0100_0000 ? 2 : 1;\n\n\t// AccountId32 layout: prefix + 32-byte pubkey + 2-byte checksum.\n\tif (decoded.length !== prefixLength + 32 + 2) return false;\n\n\tconst body = decoded.subarray(0, decoded.length - 2);\n\tconst preimage = new Uint8Array(SS58PRE.length + body.length);\n\tpreimage.set(SS58PRE);\n\tpreimage.set(body, SS58PRE.length);\n\tconst hash = blake2b(preimage, { dkLen: 64 });\n\n\treturn (\n\t\tdecoded[decoded.length - 2] === hash[0] &&\n\t\tdecoded[decoded.length - 1] === hash[1]\n\t);\n};\n","import { isEthereumAddress } from \"./isEthereumAddress\";\nimport { isSolanaAddress } from \"./isSolanaAddress\";\nimport { isSs58Address } from \"./isSs58Address\";\n\nexport const isValidAddress = (address: string): boolean => {\n\tif (address.startsWith(\"0x\")) return isEthereumAddress(address);\n\t// SS58 (checksummed) and Solana (base58, no checksum) are disjoint: a\n\t// 32-byte Solana pubkey fails SS58 decoding, and an SS58 address decodes to\n\t// more than 32 bytes so it fails the Solana length check.\n\treturn isSs58Address(address) || isSolanaAddress(address);\n};\n","import { isValidAddress } from \"./isValidAddress\";\n\nexport type WalletAccountId = string;\n\nexport const getWalletAccountId = (\n\twalletId: string,\n\taddress: string,\n): WalletAccountId => {\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn `${walletId}::${address}`;\n};\n\nexport const parseWalletAccountId = (accountId: string) => {\n\tif (!accountId) throw new Error(\"Invalid walletAccountId\");\n\tconst [walletId, address] = accountId.split(\"::\");\n\tif (!walletId) throw new Error(\"Missing walletId\");\n\tif (!address || !isValidAddress(address)) throw new Error(\"Invalid address\");\n\treturn { walletId, address };\n};\n","import {\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tof,\n\tSubscription,\n\tshareReplay,\n} from \"rxjs\";\nimport { getCachedObservable$ } from \"../utils/getCachedObservable\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport type {\n\tBaseWallet,\n\tBaseWalletAccount,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n\tWalletPlatform,\n} from \"./types\";\nimport { isWalletConnectWallet } from \"./types\";\n\nexport type LiveWalletConnectWallet = Exclude<\n\tWalletConnectWallet,\n\t{ isPlaceholder: true }\n>;\n\nexport type PlatformAccountsOptions<\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n> = {\n\t/** This platform's wallets plus the shared WalletConnect connector. */\n\twallets$: Observable<(TWallet | WalletConnectWallet)[]>;\n\t/** Account stream for one connected injected wallet. */\n\tgetInjectedAccounts$: (wallet: TWallet) => Observable<TAccount[]>;\n\t/** Account stream for the WalletConnect connector. */\n\tgetWalletConnectAccounts$: (\n\t\twallet: LiveWalletConnectWallet,\n\t) => Observable<TAccount[]>;\n\t/** Optional post-flatten transform (e.g. Polkadot's `accountTypes` filter). */\n\tmapAccounts?: (accounts: TAccount[]) => TAccount[];\n\t/**\n\t * Signature of the account fields that should trigger a re-emission.\n\t * Defaults to the account id; platforms add mutable fields (Ethereum\n\t * `chainId`, Solana `chains`).\n\t */\n\taccountChangeKey?: (account: TAccount) => string;\n};\n\n/** The account list plus the connected wallets whose stream has answered, an empty list included. */\nexport type PlatformAccountsFrame<TAccount> = {\n\taccounts: TAccount[];\n\tanswered: WalletId[];\n};\n\nexport type PlatformAccounts$<TAccount> = Observable<TAccount[]> & {\n\tframes$: Observable<PlatformAccountsFrame<TAccount>>;\n};\n\nconst isPlatformAccounts$ = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): accounts$ is PlatformAccounts$<TAccount> => \"frames$\" in accounts$;\n\n/** A plugin not built on `createPlatformAccounts$` reports no answered wallet. */\nexport const framesOf = <TAccount extends BaseWalletAccount>(\n\taccounts$: Observable<TAccount[]>,\n): Observable<PlatformAccountsFrame<TAccount>> =>\n\tisPlatformAccounts$(accounts$)\n\t\t? accounts$.frames$\n\t\t: accounts$.pipe(map((accounts) => ({ accounts, answered: [] })));\n\nconst idsEqual = (a: WalletId[], b: WalletId[]) =>\n\ta.length === b.length && a.every((id, i) => id === b[i]);\n\ntype WalletConnection<TAccount> = {\n\tkey: string;\n\taccounts: TAccount[];\n\tanswered: boolean;\n\tcompleted: boolean;\n\tsubscription: Subscription;\n};\n\nconst sessionKey = (wallet: WalletConnectWallet): string =>\n\t`${wallet.id}|${wallet.platforms.join(\",\")}`;\n\nconst connectionKey = (wallet: BaseWallet | WalletConnectWallet): string =>\n\tisWalletConnectWallet(wallet) ? sessionKey(wallet) : wallet.id;\n\n/** Shared engine behind every platform's `getAccounts$`. */\nexport const createPlatformAccounts$ = <\n\tTWallet extends BaseWallet,\n\tTAccount extends BaseWalletAccount,\n>({\n\twallets$,\n\tgetInjectedAccounts$,\n\tgetWalletConnectAccounts$,\n\tmapAccounts,\n\taccountChangeKey = (account) => account.id,\n}: PlatformAccountsOptions<TWallet, TAccount>): PlatformAccounts$<TAccount> => {\n\ttype Frame = PlatformAccountsFrame<TAccount>;\n\tconst nameAndChangeKey = (account: TAccount) =>\n\t\t`${account.name ?? \"\"}|${accountChangeKey(account)}`;\n\tconst accountsListEqual = (a: TAccount[], b: TAccount[]) =>\n\t\ta.length === b.length &&\n\t\ta.every((account, i) => {\n\t\t\tconst other = b[i];\n\t\t\treturn !!other && nameAndChangeKey(account) === nameAndChangeKey(other);\n\t\t});\n\tconst accountsOf = (wallet: TWallet | LiveWalletConnectWallet) =>\n\t\tisWalletConnectWallet(wallet)\n\t\t\t? getWalletConnectAccounts$(wallet)\n\t\t\t: getInjectedAccounts$(wallet);\n\n\tconst frames$ = new Observable<Frame>((subscriber) => {\n\t\tconst connections = new Map<WalletId, WalletConnection<TAccount>>();\n\t\tlet connectedIds: WalletId[] = [];\n\t\tlet walletsCompleted = false;\n\t\tlet emitted = false;\n\n\t\tconst awaitingFirstAnswers = () =>\n\t\t\t!emitted &&\n\t\t\t[...connections.values()].some((connection) => !connection.answered);\n\n\t\tconst accountsListed = () =>\n\t\t\tconnectedIds.flatMap((id) => connections.get(id)?.accounts ?? []);\n\t\tconst walletsAnswered = () =>\n\t\t\tconnectedIds.filter((id) => connections.get(id)?.answered);\n\n\t\tconst emit = () => {\n\t\t\tif (awaitingFirstAnswers()) return;\n\t\t\temitted = true;\n\t\t\tsubscriber.next({\n\t\t\t\taccounts: accountsListed(),\n\t\t\t\tanswered: walletsAnswered(),\n\t\t\t});\n\t\t};\n\n\t\tconst completeIfDone = () => {\n\t\t\tif (\n\t\t\t\twalletsCompleted &&\n\t\t\t\t[...connections.values()].every((connection) => connection.completed)\n\t\t\t)\n\t\t\t\tsubscriber.complete();\n\t\t};\n\n\t\tconst reconcile = (wallets: (TWallet | WalletConnectWallet)[]) => {\n\t\t\tconst connected = wallets.filter(\n\t\t\t\t(wallet): wallet is TWallet | LiveWalletConnectWallet =>\n\t\t\t\t\twallet.isConnected && !wallet.isPlaceholder,\n\t\t\t);\n\t\t\tconst keys = new Map(\n\t\t\t\tconnected.map((w) => [w.id, connectionKey(w)] as const),\n\t\t\t);\n\t\t\tfor (const [id, connection] of connections) {\n\t\t\t\tif (keys.get(id) === connection.key) continue;\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t\t\tconnections.delete(id);\n\t\t\t}\n\t\t\tconnectedIds = connected.map((wallet) => wallet.id);\n\t\t\tconst opened = connected\n\t\t\t\t.filter((wallet) => !connections.has(wallet.id))\n\t\t\t\t.map((wallet) => {\n\t\t\t\t\tconst connection: WalletConnection<TAccount> = {\n\t\t\t\t\t\tkey: connectionKey(wallet),\n\t\t\t\t\t\taccounts: [],\n\t\t\t\t\t\tanswered: false,\n\t\t\t\t\t\tcompleted: false,\n\t\t\t\t\t\tsubscription: new Subscription(),\n\t\t\t\t\t};\n\t\t\t\t\tconnections.set(wallet.id, connection);\n\t\t\t\t\treturn { wallet, connection };\n\t\t\t\t});\n\t\t\tfor (const { wallet, connection } of opened) {\n\t\t\t\tconnection.subscription.add(\n\t\t\t\t\taccountsOf(wallet).subscribe({\n\t\t\t\t\t\tnext: (accounts) => {\n\t\t\t\t\t\t\tconnection.accounts = accounts;\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror: (error) => {\n\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t`[kheopskit] Could not list the accounts of ${wallet.id}`,\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconnection.accounts = [];\n\t\t\t\t\t\t\tconnection.answered = true;\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\temit();\n\t\t\t\t\t\t\tcompleteIfDone();\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcomplete: () => {\n\t\t\t\t\t\t\tconnection.completed = true;\n\t\t\t\t\t\t\tcompleteIfDone();\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\temit();\n\t\t};\n\n\t\tconst sub = wallets$.subscribe({\n\t\t\tnext: reconcile,\n\t\t\terror: (error) => subscriber.error(error),\n\t\t\tcomplete: () => {\n\t\t\t\twalletsCompleted = true;\n\t\t\t\tcompleteIfDone();\n\t\t\t},\n\t\t});\n\n\t\treturn () => {\n\t\t\tsub.unsubscribe();\n\t\t\tfor (const connection of connections.values())\n\t\t\t\tconnection.subscription.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tmap((frame) =>\n\t\t\tmapAccounts ? { ...frame, accounts: mapAccounts(frame.accounts) } : frame,\n\t\t),\n\t\tdistinctUntilChanged(\n\t\t\t(a, b) =>\n\t\t\t\taccountsListEqual(a.accounts, b.accounts) &&\n\t\t\t\tidsEqual(a.answered, b.answered),\n\t\t),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\tconst accounts$ = frames$.pipe(\n\t\tmap((frame) => frame.accounts),\n\t\tdistinctUntilChanged(accountsListEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n\treturn Object.assign(accounts$, { frames$ });\n};\n\n/**\n * CAIP-10 account strings (\"<namespace>:<chainRef>:<address>\") the live\n * WalletConnect session carries for a namespace, limited to the entries\n * granting `method` when one is given.\n */\nexport const getSessionCaip10s = (\n\tsession: NonNullable<WalletConnectProvider[\"session\"]>,\n\tnamespace: string,\n\tmethod?: string,\n): string[] =>\n\tObject.values(session.namespaces)\n\t\t.filter((ns) => !method || ns.methods?.includes(method))\n\t\t.flatMap((ns) => ns.accounts ?? [])\n\t\t.filter((account) => account.startsWith(`${namespace}:`));\n\n/**\n * Unique addresses from CAIP-10 account strings (one entry per chain, so the\n * same address repeats — dedupe).\n */\nexport const getCaip10Addresses = (caip10s: string[]): string[] => [\n\t...new Set(\n\t\tcaip10s\n\t\t\t.map((account) => account.split(\":\")[2])\n\t\t\t.filter((address): address is string => !!address),\n\t),\n];\n\n/**\n * Shared shape of the Polkadot/Solana WalletConnect account streams: no-op\n * unless the session carries the platform's namespace, then a cached\n * observable that rebuilds the account list from the session on\n * `session_update` / `accountsChanged`.\n *\n * AppKit's `getAccount(namespace).allAccounts` is always empty for namespaces\n * without a native AppKit adapter — the WalletConnect session is the source of\n * truth, hence the session-driven rebuild.\n */\nexport const getWalletConnectSessionAccounts$ = <\n\tTAccount extends BaseWalletAccount,\n>(options: {\n\twallet: LiveWalletConnectWallet;\n\tplatform: WalletPlatform;\n\t/** WalletConnect namespace, e.g. \"polkadot\" | \"solana\" | \"eip155\". */\n\tnamespace: string;\n\t/** Cache key for {@link getCachedObservable$} — must be reconnect-safe. */\n\tcacheKey: string;\n\t/** Build the account list from the live session. */\n\tbuildAccounts: (provider: WalletConnectProvider) => TAccount[];\n}): Observable<TAccount[]> => {\n\tconst { wallet, platform, namespace, cacheKey, buildAccounts } = options;\n\tconst provider = wallet.appKit.getProvider(namespace);\n\n\tif (!wallet.platforms.includes(platform) || !provider?.session) return of([]);\n\n\treturn getCachedObservable$(cacheKey, () =>\n\t\tnew Observable<TAccount[]>((subscriber) => {\n\t\t\tsubscriber.next(buildAccounts(provider));\n\n\t\t\t// Re-derive when the WalletConnect session's accounts change, mirroring\n\t\t\t// the injected paths' change subscriptions.\n\t\t\tconst reemit = () => subscriber.next(buildAccounts(provider));\n\t\t\tprovider.on(\"session_update\", reemit);\n\t\t\tprovider.on(\"accountsChanged\", reemit);\n\n\t\t\treturn () => {\n\t\t\t\tprovider.off(\"session_update\", reemit);\n\t\t\t\tprovider.off(\"accountsChanged\", reemit);\n\t\t\t};\n\t\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 })),\n\t);\n};\n"],"mappings":";;;;;;AAEA,MAAM,cAAc;AACpB,MAAM,UAAU,IAAI,YAAY;;;;;AAMhC,MAAM,mBAAmB,YAA6B;CACrD,MAAM,MAAM,QAAQ,MAAM,CAAC;CAC3B,MAAM,QAAA,GAAOA,sBAAAA,WAAAA,CAAW,QAAQ,OAAO,IAAI,YAAY,CAAC,CAAC;CACzD,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK;EAC5B,MAAM,OAAO,IAAI,OAAO,CAAC;EAGzB,IAAI,EADF,QAAQ,OAAO,QAAQ,OAAS,QAAQ,OAAO,QAAQ,MAC1C;EACf,MAAM,OAAO,KAAK,KAAK,MAAM;EAC7B,MAAM,SAAS,IAAI,MAAM,IAAI,QAAQ,IAAI,OAAO;EA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AAAA,YAAAA,CAAY;EAAE,UAAU;EAAM,YAAY;CAAE,CAAC,CAAC,CACvD;AACD"}
|
package/dist/polkadot.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as isWalletConnectWallet, N as WalletAccountId, T as isInjectedWallet, b as WalletConnectWallet, g as PolkadotAccountType, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, p as Placeholder, r as BaseWallet } from "./types-
|
|
1
|
+
import { E as isWalletConnectWallet, N as WalletAccountId, T as isInjectedWallet, b as WalletConnectWallet, g as PolkadotAccountType, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, p as Placeholder, r as BaseWallet } from "./types-C9aw2FEm.mjs";
|
|
2
2
|
import { InjectedPolkadotAccount, SignPayload } from "polkadot-api/pjs-signer";
|
|
3
3
|
//#region src/utils/isSs58Address.d.ts
|
|
4
4
|
/**
|
package/dist/polkadot.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as isWalletConnectWallet, N as WalletAccountId, T as isInjectedWallet, b as WalletConnectWallet, g as PolkadotAccountType, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, p as Placeholder, r as BaseWallet } from "./types-
|
|
1
|
+
import { E as isWalletConnectWallet, N as WalletAccountId, T as isInjectedWallet, b as WalletConnectWallet, g as PolkadotAccountType, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, p as Placeholder, r as BaseWallet } from "./types-C9aw2FEm.js";
|
|
2
2
|
import { InjectedPolkadotAccount, SignPayload } from "polkadot-api/pjs-signer";
|
|
3
3
|
//#region src/utils/isSs58Address.d.ts
|
|
4
4
|
/**
|
package/dist/polkadot.js
CHANGED
|
@@ -22,7 +22,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
24
|
const require_types = require("./types-DaRMgleZ.js");
|
|
25
|
-
const require_platformAccounts = require("./platformAccounts-
|
|
25
|
+
const require_platformAccounts = require("./platformAccounts-BcLoaZZb.js");
|
|
26
26
|
const require_errors = require("./errors-B6Z21vkI.js");
|
|
27
27
|
const require_polkadotExtensions = require("./polkadotExtensions-y4J9UzYl.js");
|
|
28
28
|
const require_registryReads = require("./registryReads-BelydyRc.js");
|
|
@@ -167,13 +167,15 @@ const getPjsSignerField = () => {
|
|
|
167
167
|
};
|
|
168
168
|
const requestSignMessage = (appKit, provider, address, message) => {
|
|
169
169
|
if (!provider.session) throw new require_errors.KheopskitError("NO_SESSION", "No session found");
|
|
170
|
-
const
|
|
171
|
-
|
|
170
|
+
const method = "polkadot_signMessage";
|
|
171
|
+
const approvedChainIds = require_platformAccounts.getSessionCaip10s(provider.session, "polkadot", method).filter((caip10) => caip10.split(":")[2] === address).map((caip10) => caip10.split(":").slice(0, 2).join(":"));
|
|
172
|
+
const chainId = appKit.getCaipNetworks("polkadot").map((network) => network.caipNetworkId).find((id) => id !== void 0 && approvedChainIds.includes(id)) ?? approvedChainIds[0];
|
|
173
|
+
if (!chainId) throw new require_errors.KheopskitError("NO_SESSION", `No polkadot chain in the WalletConnect session grants ${method} to ${address}`);
|
|
172
174
|
return provider.client.request({
|
|
173
175
|
topic: provider.session.topic,
|
|
174
176
|
chainId,
|
|
175
177
|
request: {
|
|
176
|
-
method
|
|
178
|
+
method,
|
|
177
179
|
params: {
|
|
178
180
|
address,
|
|
179
181
|
message
|
package/dist/polkadot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polkadot.js","names":["getInjectedExtensions","getWalletId","createRegistryReads$","createInjectedWallets$","map","distinctUntilChanged","isEqual","parseWalletId","isRefusalMessage","POLKADOT_EXTENSIONS","hex","of","Observable","getWalletAccountId","pjs","KheopskitError","getWalletConnectSessionAccounts$","getCaip10Addresses","getSessionCaip10s","createPlatformAccounts$"],"sources":["../src/api/polkadot/wallets.ts","../src/api/polkadot/accounts.ts","../src/api/polkadot/plugin.ts"],"sourcesContent":["import { isEqual } from \"lodash-es\";\nimport { getInjectedExtensions } from \"polkadot-api/pjs-signer\";\nimport { distinctUntilChanged, map, type Observable } from \"rxjs\";\nimport { POLKADOT_EXTENSIONS } from \"../../utils/polkadotExtensions\";\nimport { createRegistryReads$ } from \"../../utils/registryReads\";\nimport {\n\tgetWalletId,\n\tparseWalletId,\n\ttype WalletId,\n} from \"../../utils/WalletId\";\nimport { isRefusalMessage } from \"../errors\";\nimport { createInjectedWallets$ } from \"../injectedWallets\";\nimport type { KheopskitStore } from \"../store\";\nimport type { KheopskitConfig } from \"../types\";\nimport type {\n\tPolkadotInjected,\n\tPolkadotInjectedAccount,\n\tPolkadotInjectedWallet,\n} from \"./types\";\n\ntype EnableResult = {\n\taccounts?: Partial<PolkadotInjected[\"accounts\"]>;\n\tsigner?: Partial<PolkadotInjected[\"signer\"]>;\n\tmetadata?: unknown;\n\tprovider?: unknown;\n};\n\ntype InjectedWeb3Window = {\n\tinjectedWeb3?: Record<\n\t\tstring,\n\t\t| { enable(appName: string): Promise<EnableResult | null | undefined> }\n\t\t| undefined\n\t>;\n};\n\nconst isPolkadotInjected = (\n\tinjected: EnableResult | null | undefined,\n): injected is PolkadotInjected =>\n\ttypeof injected?.accounts?.get === \"function\" &&\n\ttypeof injected.accounts.subscribe === \"function\" &&\n\ttypeof injected.signer?.signPayload === \"function\" &&\n\ttypeof injected.signer.signRaw === \"function\";\n\n/**\n * The list each extension last reported: read when its connect was granted,\n * so the emission that first shows the wallet connected already lists it, and\n * updated by every `subscribe` callback, so an accounts stream that restarts\n * resumes from the current list rather than the connect-time one.\n */\nexport const latestAccounts = new WeakMap<\n\tPolkadotInjected,\n\tPolkadotInjectedAccount[]\n>();\n\ntype InjectedWeb3Entry = NonNullable<\n\tNonNullable<InjectedWeb3Window[\"injectedWeb3\"]>[string]\n>;\n\n/**\n * The connect each extension is still answering. An extension keeps its\n * prompt open after kheopskit abandons the attempt, and a second `enable()`\n * meanwhile fails (polkadot-js: \"Pending authorisation request already\n * exists\") or resolves unauthorised (Talisman), so a new attempt joins this\n * one instead.\n */\nconst pendingConnects = new WeakMap<\n\tInjectedWeb3Entry,\n\tPromise<PolkadotInjected>\n>();\n\nconst enableExtension = async (\n\tidentifier: string,\n\tentry: InjectedWeb3Entry,\n\tappName: string,\n) => {\n\tconst injected = await entry.enable(appName);\n\tif (!isPolkadotInjected(injected))\n\t\tthrow new Error(`Unsupported extension: \"${identifier}\"`);\n\tlatestAccounts.set(injected, await injected.accounts.get());\n\treturn injected;\n};\n\nconst connectExtension = (\n\tidentifier: string,\n\tappName: string,\n): Promise<PolkadotInjected> => {\n\tconst entry = (globalThis as InjectedWeb3Window).injectedWeb3?.[identifier];\n\tif (!entry)\n\t\treturn Promise.reject(new Error(`Unavailable extension: \"${identifier}\"`));\n\tconst pending = pendingConnects.get(entry);\n\tif (pending) return pending;\n\tconst connecting = enableExtension(identifier, entry, appName);\n\tpendingConnects.set(entry, connecting);\n\tconst settle = () => pendingConnects.delete(entry);\n\tconnecting.then(settle, settle);\n\treturn connecting;\n};\n\nconst getInjectedWalletsIds = () =>\n\ttypeof window === \"undefined\"\n\t\t? []\n\t\t: getInjectedExtensions().map((name) => getWalletId(\"polkadot\", name));\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\tregistryReads$: Observable<void> = createRegistryReads$(),\n) =>\n\tcreateInjectedWallets$<WalletId, PolkadotInjectedWallet, PolkadotInjected>(\n\t\tstore,\n\t\t{\n\t\t\tsources$: registryReads$.pipe(\n\t\t\t\tmap(getInjectedWalletsIds),\n\t\t\t\tdistinctUntilChanged<WalletId[]>(isEqual),\n\t\t\t),\n\t\t\tgetWalletId: (walletId) => walletId,\n\t\t\tconnect: (walletId) =>\n\t\t\t\tconnectExtension(\n\t\t\t\t\tparseWalletId(walletId).identifier,\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\tisUserRejection: isRefusalMessage,\n\t\t\tbuildWallet: ({\n\t\t\t\twalletId,\n\t\t\t\thandle,\n\t\t\t\tstatus,\n\t\t\t\terror,\n\t\t\t\tisConnected,\n\t\t\t\tconnect,\n\t\t\t\tdisconnect,\n\t\t\t}) => {\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\tstatus,\n\t\t\t\t\terror,\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 { hex } from \"@scure/base\";\nimport type {\n\tKeypairType,\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\ttype LiveWalletConnectWallet,\n} from \"../platformAccounts\";\nimport type {\n\tAppKitInstance,\n\tPolkadotAccountType,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n} from \"../types\";\nimport type {\n\tPolkadotAccount,\n\tPolkadotInjected,\n\tPolkadotInjectedAccount,\n\tPolkadotInjectedWallet,\n\tPolkadotSignRawType,\n\tPolkadotWallet,\n} from \"./types\";\nimport { latestAccounts } from \"./wallets\";\n\ntype RawSignature = `0x${string}`;\n\nconst encodeRawData = (\n\tdata: string | Uint8Array,\n\ttype?: PolkadotSignRawType,\n): { data: string; type: PolkadotSignRawType } =>\n\ttypeof data === \"string\"\n\t\t? { data, type: type ?? \"payload\" }\n\t\t: { data: `0x${hex.encode(data)}`, type: type ?? \"bytes\" };\n\n/**\n * pjs-signer's signature-type map knows ed25519, sr25519 and ecdsa only, so an\n * `ethereum` type would get a 64-byte mock signature where ecdsa needs 65.\n */\nconst toSignerType = (type: PolkadotAccountType): KeypairType =>\n\ttype === \"ethereum\" ? \"ecdsa\" : type;\n\nconst getInjectedWalletAccounts$ = (\n\twallet: PolkadotInjectedWallet,\n): Observable<PolkadotAccount[]> => {\n\tconst injected = wallet.extension;\n\tif (!wallet.isConnected || !injected) return of([]);\n\n\treturn new Observable<PolkadotAccount[]>((subscriber) => {\n\t\tconst signPayload = injected.signer.signPayload.bind(injected.signer);\n\t\tconst signRaw = injected.signer.signRaw.bind(injected.signer);\n\t\tconst createTransaction = injected.signer.createTransaction?.bind(\n\t\t\tinjected.signer,\n\t\t);\n\t\tconst { field, factory, getAccountTxCreator } = getPjsSignerField();\n\t\tconst createSigner = (address: string, type: KeypairType) =>\n\t\t\tcreateTransaction && getAccountTxCreator\n\t\t\t\t? getAccountTxCreator(address, createTransaction, signRaw, type)\n\t\t\t\t: factory(address, signPayload, signRaw, type);\n\n\t\tconst toAccount = (account: PolkadotInjectedAccount): PolkadotAccount => {\n\t\t\tconst { address } = account;\n\t\t\tconst type = account.type ?? \"sr25519\";\n\t\t\treturn {\n\t\t\t\t...account,\n\t\t\t\tid: getWalletAccountId(wallet.id, address),\n\t\t\t\ttype,\n\t\t\t\tplatform: \"polkadot\",\n\t\t\t\twalletName: wallet.name,\n\t\t\t\twalletId: wallet.id,\n\t\t\t\t[field]: createSigner(address, toSignerType(type)),\n\t\t\t\tsignRaw: async (data, options) =>\n\t\t\t\t\t(await signRaw({ address, ...encodeRawData(data, options?.type) }))\n\t\t\t\t\t\t.signature,\n\t\t\t} as Exclude<PolkadotAccount, { isPlaceholder: true }>;\n\t\t};\n\n\t\tconst toAccounts = (accounts: PolkadotInjectedAccount[]) =>\n\t\t\taccounts.flatMap((account) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn [toAccount(account)];\n\t\t\t\t} catch {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t});\n\n\t\tconst emit = (accounts: PolkadotInjectedAccount[]) => {\n\t\t\tlatestAccounts.set(injected, accounts);\n\t\t\tsubscriber.next(toAccounts(accounts));\n\t\t};\n\n\t\temit(latestAccounts.get(injected) ?? []);\n\t\treturn injected.accounts.subscribe(emit);\n\t});\n};\n\n/**\n * polkadot-api v2's `getPolkadotSignerFromPjs` takes three parameters and\n * ignores the fourth at runtime.\n */\ntype PjsSignerFactory = (\n\taddress: string,\n\tsignPayload: SignPayload,\n\tsignRaw: SignRaw,\n\ttype?: KeypairType,\n) => unknown;\n\ntype PjsSignerModule = {\n\tgetTxCreatorFromPjs?: PjsSignerFactory;\n\tgetPolkadotSignerFromPjs?: PjsSignerFactory;\n\tgetAccountTxCreator?: (\n\t\taddress: string,\n\t\tcreateTransaction: NonNullable<\n\t\t\tPolkadotInjected[\"signer\"][\"createTransaction\"]\n\t\t>,\n\t\tsignRaw: SignRaw,\n\t\ttype: KeypairType,\n\t) => unknown;\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. Newer v3 releases\n * add `getAccountTxCreator`, which lets the wallet build the transaction.\n */\nconst getPjsSignerField = (): {\n\tfield: \"txCreator\" | \"polkadotSigner\";\n\tfactory: PjsSignerFactory;\n\tgetAccountTxCreator?: PjsSignerModule[\"getAccountTxCreator\"];\n} => {\n\tconst module = pjs as PjsSignerModule;\n\tif (module.getTxCreatorFromPjs)\n\t\treturn {\n\t\t\tfield: \"txCreator\",\n\t\t\tfactory: module.getTxCreatorFromPjs,\n\t\t\tgetAccountTxCreator: module.getAccountTxCreator,\n\t\t};\n\tif (module.getPolkadotSignerFromPjs)\n\t\treturn {\n\t\t\tfield: \"polkadotSigner\",\n\t\t\tfactory: module.getPolkadotSignerFromPjs,\n\t\t};\n\tthrow new KheopskitError(\n\t\t\"UNSUPPORTED_VERSION\",\n\t\t\"Unsupported polkadot-api/pjs-signer version\",\n\t);\n};\n\nconst requestSignMessage = (\n\tappKit: AppKitInstance,\n\tprovider: WalletConnectProvider,\n\taddress: string,\n\tmessage: string,\n) => {\n\tif (!provider.session)\n\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\tconst chainId = appKit.getCaipNetworks(\"polkadot\")[0]?.caipNetworkId;\n\tif (!chainId)\n\t\tthrow new KheopskitError(\n\t\t\t\"NO_SESSION\",\n\t\t\t\"No CAIP network available for polkadot\",\n\t\t);\n\n\treturn provider.client.request<{ signature: RawSignature }>({\n\t\ttopic: provider.session.topic,\n\t\tchainId,\n\t\trequest: {\n\t\t\tmethod: \"polkadot_signMessage\",\n\t\t\tparams: { address, message },\n\t\t},\n\t});\n};\n\nconst getAppKitPolkadotSigning = (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 signMessage = (message: string) =>\n\t\trequestSignMessage(appKit, provider, address, message);\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 ({ data }) => ({\n\t\t\tid: 0,\n\t\t\tsignature: (await signMessage(data)).signature,\n\t\t}),\n\t\t\"sr25519\",\n\t);\n\n\tconst signRaw: PolkadotAccount[\"signRaw\"] = async (data) =>\n\t\t(await signMessage(encodeRawData(data).data)).signature;\n\n\treturn { [field]: signer, signRaw };\n};\n\nconst getWalletConnectAccounts$ = (\n\twallet: LiveWalletConnectWallet,\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...getAppKitPolkadotSigning(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] polkadot({ accountTypes }) 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 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 `createKheopskit({ 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, ctx.registryReads$),\n\t\tgetAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),\n\t\tacceptsCachedAccount: (cached) =>\n\t\t\taccountTypes.includes(cached.polkadotAccountType ?? \"sr25519\"),\n\t};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,sBACL,aAEA,OAAO,UAAU,UAAU,QAAQ,cACnC,OAAO,SAAS,SAAS,cAAc,cACvC,OAAO,SAAS,QAAQ,gBAAgB,cACxC,OAAO,SAAS,OAAO,YAAY;;;;;;;AAQpC,MAAa,iCAAiB,IAAI,QAGhC;;;;;;;;AAaF,MAAM,kCAAkB,IAAI,QAG1B;AAEF,MAAM,kBAAkB,OACvB,YACA,OACA,YACI;CACJ,MAAM,WAAW,MAAM,MAAM,OAAO,OAAO;CAC3C,IAAI,CAAC,mBAAmB,QAAQ,GAC/B,MAAM,IAAI,MAAM,2BAA2B,WAAW,EAAE;CACzD,eAAe,IAAI,UAAU,MAAM,SAAS,SAAS,IAAI,CAAC;CAC1D,OAAO;AACR;AAEA,MAAM,oBACL,YACA,YAC+B;CAC/B,MAAM,QAAS,WAAkC,eAAe;CAChE,IAAI,CAAC,OACJ,OAAO,QAAQ,uBAAO,IAAI,MAAM,2BAA2B,WAAW,EAAE,CAAC;CAC1E,MAAM,UAAU,gBAAgB,IAAI,KAAK;CACzC,IAAI,SAAS,OAAO;CACpB,MAAM,aAAa,gBAAgB,YAAY,OAAO,OAAO;CAC7D,gBAAgB,IAAI,O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,YAAY;EACvE,uBAAuB,WACtB,aAAa,SAAS,OAAO,uBAAuB,SAAS;CAC/D;AACD"}
|
|
1
|
+
{"version":3,"file":"polkadot.js","names":["getInjectedExtensions","getWalletId","createRegistryReads$","createInjectedWallets$","map","distinctUntilChanged","isEqual","parseWalletId","isRefusalMessage","POLKADOT_EXTENSIONS","hex","of","Observable","getWalletAccountId","pjs","KheopskitError","getSessionCaip10s","getWalletConnectSessionAccounts$","getCaip10Addresses","createPlatformAccounts$"],"sources":["../src/api/polkadot/wallets.ts","../src/api/polkadot/accounts.ts","../src/api/polkadot/plugin.ts"],"sourcesContent":["import { isEqual } from \"lodash-es\";\nimport { getInjectedExtensions } from \"polkadot-api/pjs-signer\";\nimport { distinctUntilChanged, map, type Observable } from \"rxjs\";\nimport { POLKADOT_EXTENSIONS } from \"../../utils/polkadotExtensions\";\nimport { createRegistryReads$ } from \"../../utils/registryReads\";\nimport {\n\tgetWalletId,\n\tparseWalletId,\n\ttype WalletId,\n} from \"../../utils/WalletId\";\nimport { isRefusalMessage } from \"../errors\";\nimport { createInjectedWallets$ } from \"../injectedWallets\";\nimport type { KheopskitStore } from \"../store\";\nimport type { KheopskitConfig } from \"../types\";\nimport type {\n\tPolkadotInjected,\n\tPolkadotInjectedAccount,\n\tPolkadotInjectedWallet,\n} from \"./types\";\n\ntype EnableResult = {\n\taccounts?: Partial<PolkadotInjected[\"accounts\"]>;\n\tsigner?: Partial<PolkadotInjected[\"signer\"]>;\n\tmetadata?: unknown;\n\tprovider?: unknown;\n};\n\ntype InjectedWeb3Window = {\n\tinjectedWeb3?: Record<\n\t\tstring,\n\t\t| { enable(appName: string): Promise<EnableResult | null | undefined> }\n\t\t| undefined\n\t>;\n};\n\nconst isPolkadotInjected = (\n\tinjected: EnableResult | null | undefined,\n): injected is PolkadotInjected =>\n\ttypeof injected?.accounts?.get === \"function\" &&\n\ttypeof injected.accounts.subscribe === \"function\" &&\n\ttypeof injected.signer?.signPayload === \"function\" &&\n\ttypeof injected.signer.signRaw === \"function\";\n\n/**\n * The list each extension last reported: read when its connect was granted,\n * so the emission that first shows the wallet connected already lists it, and\n * updated by every `subscribe` callback, so an accounts stream that restarts\n * resumes from the current list rather than the connect-time one.\n */\nexport const latestAccounts = new WeakMap<\n\tPolkadotInjected,\n\tPolkadotInjectedAccount[]\n>();\n\ntype InjectedWeb3Entry = NonNullable<\n\tNonNullable<InjectedWeb3Window[\"injectedWeb3\"]>[string]\n>;\n\n/**\n * The connect each extension is still answering. An extension keeps its\n * prompt open after kheopskit abandons the attempt, and a second `enable()`\n * meanwhile fails (polkadot-js: \"Pending authorisation request already\n * exists\") or resolves unauthorised (Talisman), so a new attempt joins this\n * one instead.\n */\nconst pendingConnects = new WeakMap<\n\tInjectedWeb3Entry,\n\tPromise<PolkadotInjected>\n>();\n\nconst enableExtension = async (\n\tidentifier: string,\n\tentry: InjectedWeb3Entry,\n\tappName: string,\n) => {\n\tconst injected = await entry.enable(appName);\n\tif (!isPolkadotInjected(injected))\n\t\tthrow new Error(`Unsupported extension: \"${identifier}\"`);\n\tlatestAccounts.set(injected, await injected.accounts.get());\n\treturn injected;\n};\n\nconst connectExtension = (\n\tidentifier: string,\n\tappName: string,\n): Promise<PolkadotInjected> => {\n\tconst entry = (globalThis as InjectedWeb3Window).injectedWeb3?.[identifier];\n\tif (!entry)\n\t\treturn Promise.reject(new Error(`Unavailable extension: \"${identifier}\"`));\n\tconst pending = pendingConnects.get(entry);\n\tif (pending) return pending;\n\tconst connecting = enableExtension(identifier, entry, appName);\n\tpendingConnects.set(entry, connecting);\n\tconst settle = () => pendingConnects.delete(entry);\n\tconnecting.then(settle, settle);\n\treturn connecting;\n};\n\nconst getInjectedWalletsIds = () =>\n\ttypeof window === \"undefined\"\n\t\t? []\n\t\t: getInjectedExtensions().map((name) => getWalletId(\"polkadot\", name));\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\tregistryReads$: Observable<void> = createRegistryReads$(),\n) =>\n\tcreateInjectedWallets$<WalletId, PolkadotInjectedWallet, PolkadotInjected>(\n\t\tstore,\n\t\t{\n\t\t\tsources$: registryReads$.pipe(\n\t\t\t\tmap(getInjectedWalletsIds),\n\t\t\t\tdistinctUntilChanged<WalletId[]>(isEqual),\n\t\t\t),\n\t\t\tgetWalletId: (walletId) => walletId,\n\t\t\tconnect: (walletId) =>\n\t\t\t\tconnectExtension(\n\t\t\t\t\tparseWalletId(walletId).identifier,\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\tisUserRejection: isRefusalMessage,\n\t\t\tbuildWallet: ({\n\t\t\t\twalletId,\n\t\t\t\thandle,\n\t\t\t\tstatus,\n\t\t\t\terror,\n\t\t\t\tisConnected,\n\t\t\t\tconnect,\n\t\t\t\tdisconnect,\n\t\t\t}) => {\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\tstatus,\n\t\t\t\t\terror,\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 { hex } from \"@scure/base\";\nimport type {\n\tKeypairType,\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\ttype LiveWalletConnectWallet,\n} from \"../platformAccounts\";\nimport type {\n\tAppKitInstance,\n\tPolkadotAccountType,\n\tWalletConnectProvider,\n\tWalletConnectWallet,\n} from \"../types\";\nimport type {\n\tPolkadotAccount,\n\tPolkadotInjected,\n\tPolkadotInjectedAccount,\n\tPolkadotInjectedWallet,\n\tPolkadotSignRawType,\n\tPolkadotWallet,\n} from \"./types\";\nimport { latestAccounts } from \"./wallets\";\n\ntype RawSignature = `0x${string}`;\n\nconst encodeRawData = (\n\tdata: string | Uint8Array,\n\ttype?: PolkadotSignRawType,\n): { data: string; type: PolkadotSignRawType } =>\n\ttypeof data === \"string\"\n\t\t? { data, type: type ?? \"payload\" }\n\t\t: { data: `0x${hex.encode(data)}`, type: type ?? \"bytes\" };\n\n/**\n * pjs-signer's signature-type map knows ed25519, sr25519 and ecdsa only, so an\n * `ethereum` type would get a 64-byte mock signature where ecdsa needs 65.\n */\nconst toSignerType = (type: PolkadotAccountType): KeypairType =>\n\ttype === \"ethereum\" ? \"ecdsa\" : type;\n\nconst getInjectedWalletAccounts$ = (\n\twallet: PolkadotInjectedWallet,\n): Observable<PolkadotAccount[]> => {\n\tconst injected = wallet.extension;\n\tif (!wallet.isConnected || !injected) return of([]);\n\n\treturn new Observable<PolkadotAccount[]>((subscriber) => {\n\t\tconst signPayload = injected.signer.signPayload.bind(injected.signer);\n\t\tconst signRaw = injected.signer.signRaw.bind(injected.signer);\n\t\tconst createTransaction = injected.signer.createTransaction?.bind(\n\t\t\tinjected.signer,\n\t\t);\n\t\tconst { field, factory, getAccountTxCreator } = getPjsSignerField();\n\t\tconst createSigner = (address: string, type: KeypairType) =>\n\t\t\tcreateTransaction && getAccountTxCreator\n\t\t\t\t? getAccountTxCreator(address, createTransaction, signRaw, type)\n\t\t\t\t: factory(address, signPayload, signRaw, type);\n\n\t\tconst toAccount = (account: PolkadotInjectedAccount): PolkadotAccount => {\n\t\t\tconst { address } = account;\n\t\t\tconst type = account.type ?? \"sr25519\";\n\t\t\treturn {\n\t\t\t\t...account,\n\t\t\t\tid: getWalletAccountId(wallet.id, address),\n\t\t\t\ttype,\n\t\t\t\tplatform: \"polkadot\",\n\t\t\t\twalletName: wallet.name,\n\t\t\t\twalletId: wallet.id,\n\t\t\t\t[field]: createSigner(address, toSignerType(type)),\n\t\t\t\tsignRaw: async (data, options) =>\n\t\t\t\t\t(await signRaw({ address, ...encodeRawData(data, options?.type) }))\n\t\t\t\t\t\t.signature,\n\t\t\t} as Exclude<PolkadotAccount, { isPlaceholder: true }>;\n\t\t};\n\n\t\tconst toAccounts = (accounts: PolkadotInjectedAccount[]) =>\n\t\t\taccounts.flatMap((account) => {\n\t\t\t\ttry {\n\t\t\t\t\treturn [toAccount(account)];\n\t\t\t\t} catch {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t});\n\n\t\tconst emit = (accounts: PolkadotInjectedAccount[]) => {\n\t\t\tlatestAccounts.set(injected, accounts);\n\t\t\tsubscriber.next(toAccounts(accounts));\n\t\t};\n\n\t\temit(latestAccounts.get(injected) ?? []);\n\t\treturn injected.accounts.subscribe(emit);\n\t});\n};\n\n/**\n * polkadot-api v2's `getPolkadotSignerFromPjs` takes three parameters and\n * ignores the fourth at runtime.\n */\ntype PjsSignerFactory = (\n\taddress: string,\n\tsignPayload: SignPayload,\n\tsignRaw: SignRaw,\n\ttype?: KeypairType,\n) => unknown;\n\ntype PjsSignerModule = {\n\tgetTxCreatorFromPjs?: PjsSignerFactory;\n\tgetPolkadotSignerFromPjs?: PjsSignerFactory;\n\tgetAccountTxCreator?: (\n\t\taddress: string,\n\t\tcreateTransaction: NonNullable<\n\t\t\tPolkadotInjected[\"signer\"][\"createTransaction\"]\n\t\t>,\n\t\tsignRaw: SignRaw,\n\t\ttype: KeypairType,\n\t) => unknown;\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. Newer v3 releases\n * add `getAccountTxCreator`, which lets the wallet build the transaction.\n */\nconst getPjsSignerField = (): {\n\tfield: \"txCreator\" | \"polkadotSigner\";\n\tfactory: PjsSignerFactory;\n\tgetAccountTxCreator?: PjsSignerModule[\"getAccountTxCreator\"];\n} => {\n\tconst module = pjs as PjsSignerModule;\n\tif (module.getTxCreatorFromPjs)\n\t\treturn {\n\t\t\tfield: \"txCreator\",\n\t\t\tfactory: module.getTxCreatorFromPjs,\n\t\t\tgetAccountTxCreator: module.getAccountTxCreator,\n\t\t};\n\tif (module.getPolkadotSignerFromPjs)\n\t\treturn {\n\t\t\tfield: \"polkadotSigner\",\n\t\t\tfactory: module.getPolkadotSignerFromPjs,\n\t\t};\n\tthrow new KheopskitError(\n\t\t\"UNSUPPORTED_VERSION\",\n\t\t\"Unsupported polkadot-api/pjs-signer version\",\n\t);\n};\n\nconst requestSignMessage = (\n\tappKit: AppKitInstance,\n\tprovider: WalletConnectProvider,\n\taddress: string,\n\tmessage: string,\n) => {\n\tif (!provider.session)\n\t\tthrow new KheopskitError(\"NO_SESSION\", \"No session found\");\n\tconst method = \"polkadot_signMessage\";\n\tconst approvedChainIds = getSessionCaip10s(\n\t\tprovider.session,\n\t\t\"polkadot\",\n\t\tmethod,\n\t)\n\t\t.filter((caip10) => caip10.split(\":\")[2] === address)\n\t\t.map((caip10) => caip10.split(\":\").slice(0, 2).join(\":\"));\n\tconst chainId =\n\t\tappKit\n\t\t\t.getCaipNetworks(\"polkadot\")\n\t\t\t.map((network) => network.caipNetworkId)\n\t\t\t.find((id) => id !== undefined && approvedChainIds.includes(id)) ??\n\t\tapprovedChainIds[0];\n\tif (!chainId)\n\t\tthrow new KheopskitError(\n\t\t\t\"NO_SESSION\",\n\t\t\t`No polkadot chain in the WalletConnect session grants ${method} to ${address}`,\n\t\t);\n\n\treturn provider.client.request<{ signature: RawSignature }>({\n\t\ttopic: provider.session.topic,\n\t\tchainId,\n\t\trequest: {\n\t\t\tmethod,\n\t\t\tparams: { address, message },\n\t\t},\n\t});\n};\n\nconst getAppKitPolkadotSigning = (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 signMessage = (message: string) =>\n\t\trequestSignMessage(appKit, provider, address, message);\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 ({ data }) => ({\n\t\t\tid: 0,\n\t\t\tsignature: (await signMessage(data)).signature,\n\t\t}),\n\t\t\"sr25519\",\n\t);\n\n\tconst signRaw: PolkadotAccount[\"signRaw\"] = async (data) =>\n\t\t(await signMessage(encodeRawData(data).data)).signature;\n\n\treturn { [field]: signer, signRaw };\n};\n\nconst getWalletConnectAccounts$ = (\n\twallet: LiveWalletConnectWallet,\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...getAppKitPolkadotSigning(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] polkadot({ accountTypes }) 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 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 `createKheopskit({ 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, ctx.registryReads$),\n\t\tgetAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),\n\t\tacceptsCachedAccount: (cached) =>\n\t\t\taccountTypes.includes(cached.polkadotAccountType ?? \"sr25519\"),\n\t};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,sBACL,aAEA,OAAO,UAAU,UAAU,QAAQ,cACnC,OAAO,SAAS,SAAS,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S,OAAO,CAAC;EAMtB,OAJkBC,yBAAAA,mBACjBF,yBAAAA,kBAAkB,SAAS,UAAU,CAGvB,CAAC,CAAC,KACf,aACC;GACA,IAAIH,yBAAAA,mBAAmB,OAAO,IAAI,OAAO;GACzC,UAAU;GACV,YAAY,OAAO;GACnB,UAAU,OAAO;GACjB;GACA,GAAG,yBAAyB,OAAO,QAAQ,OAAO;GAClD,aAAa;GACb,MAAM,GAAG,OAAO,KAAK;GAGrB,MAAM;EACP,EACF;CACD;AACD,CAAC;AAEF,MAAa,wBACZ,kBACA,yBACI;CACJ,IAAI,qBAAqB,WAAW,GACnC,QAAQ,KACP,8FACD;CAGD,OAAOM,yBAAAA,wBAAwB;EAC9B,UAAU;EACV,sBAAsB;EACtB;EACA,cAAc,aACb,SAAS,QAAQ,YAAY,qBAAqB,SAAS,QAAQ,IAAI,CAAC;CAC1E,CAAC;AACF;;;ACxRA,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,QAAQ,IAAI,cAAc;EAC9D,eAAe,aAAa,qBAAqB,UAAU,YAAY;EACvE,uBAAuB,WACtB,aAAa,SAAS,OAAO,uBAAuB,SAAS;CAC/D;AACD"}
|
package/dist/polkadot.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as getWalletId, n as isWalletConnectWallet, o as parseWalletId, t as isInjectedWallet } from "./types-DcpmEGhO.mjs";
|
|
2
|
-
import { a as getWalletConnectSessionAccounts$, i as getSessionCaip10s, l as isSs58Address, o as getWalletAccountId, r as getCaip10Addresses, t as createPlatformAccounts$ } from "./platformAccounts-
|
|
2
|
+
import { a as getWalletConnectSessionAccounts$, i as getSessionCaip10s, l as isSs58Address, o as getWalletAccountId, r as getCaip10Addresses, t as createPlatformAccounts$ } from "./platformAccounts-3jM3W1fB.mjs";
|
|
3
3
|
import { a as isRefusalMessage, t as KheopskitError } from "./errors-DszTFbnO.mjs";
|
|
4
4
|
import { t as POLKADOT_EXTENSIONS } from "./polkadotExtensions-BoVKhNU_.mjs";
|
|
5
5
|
import { n as createRegistryReads$ } from "./registryReads-cdob5BUy.mjs";
|
|
@@ -144,13 +144,15 @@ const getPjsSignerField = () => {
|
|
|
144
144
|
};
|
|
145
145
|
const requestSignMessage = (appKit, provider, address, message) => {
|
|
146
146
|
if (!provider.session) throw new KheopskitError("NO_SESSION", "No session found");
|
|
147
|
-
const
|
|
148
|
-
|
|
147
|
+
const method = "polkadot_signMessage";
|
|
148
|
+
const approvedChainIds = getSessionCaip10s(provider.session, "polkadot", method).filter((caip10) => caip10.split(":")[2] === address).map((caip10) => caip10.split(":").slice(0, 2).join(":"));
|
|
149
|
+
const chainId = appKit.getCaipNetworks("polkadot").map((network) => network.caipNetworkId).find((id) => id !== void 0 && approvedChainIds.includes(id)) ?? approvedChainIds[0];
|
|
150
|
+
if (!chainId) throw new KheopskitError("NO_SESSION", `No polkadot chain in the WalletConnect session grants ${method} to ${address}`);
|
|
149
151
|
return provider.client.request({
|
|
150
152
|
topic: provider.session.topic,
|
|
151
153
|
chainId,
|
|
152
154
|
request: {
|
|
153
|
-
method
|
|
155
|
+
method,
|
|
154
156
|
params: {
|
|
155
157
|
address,
|
|
156
158
|
message
|