@kheopskit/core 6.0.0-rc.1 → 6.0.0-rc.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 +18 -0
- package/MIGRATING_TO_V6.md +52 -40
- package/README.md +64 -45
- package/dist/ethereum.d.mts +2 -1
- package/dist/ethereum.d.ts +2 -1
- package/dist/ethereum.js +1 -1
- package/dist/ethereum.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +34 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -24
- package/dist/index.mjs.map +1 -1
- package/dist/{injectedWallets-48L-AL1I.mjs → injectedWallets-5GL1Jder.mjs} +2 -2
- package/dist/{injectedWallets-48L-AL1I.mjs.map → injectedWallets-5GL1Jder.mjs.map} +1 -1
- package/dist/{injectedWallets-Dy8YGKL-.js → injectedWallets-BQBgS-f0.js} +2 -2
- package/dist/{injectedWallets-Dy8YGKL-.js.map → injectedWallets-BQBgS-f0.js.map} +1 -1
- package/dist/internal.d.mts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/polkadot.d.mts +1 -1
- package/dist/polkadot.d.ts +1 -1
- package/dist/polkadot.js +6 -40
- package/dist/polkadot.js.map +1 -1
- package/dist/polkadot.mjs +6 -40
- package/dist/polkadot.mjs.map +1 -1
- package/dist/registryReads-BpHsWLd7.js +38 -0
- package/dist/registryReads-BpHsWLd7.js.map +1 -0
- package/dist/{pageLoad-BZ7o8p5R.mjs → registryReads-BvtznSo3.mjs} +12 -3
- package/dist/registryReads-BvtznSo3.mjs.map +1 -0
- package/dist/solana.d.mts +2 -1
- package/dist/solana.d.ts +2 -1
- package/dist/solana.js +2 -1
- package/dist/solana.js.map +1 -1
- package/dist/solana.mjs +2 -1
- package/dist/solana.mjs.map +1 -1
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/types-BWHvNFlN.js.map +1 -1
- package/dist/{types-lkMXVJNG.d.ts → types-C3I3w0jb.d.mts} +47 -32
- package/dist/{types-lkMXVJNG.d.mts → types-C3I3w0jb.d.ts} +47 -32
- package/dist/types-Yor672md.mjs.map +1 -1
- package/dist/walletconnect.d.mts +1 -1
- package/dist/walletconnect.d.ts +1 -1
- package/package.json +1 -1
- package/dist/pageLoad-BZ7o8p5R.mjs.map +0 -1
- package/dist/pageLoad-D1wLeuFG.js +0 -28
- package/dist/pageLoad-D1wLeuFG.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectedWallets-Dy8YGKL-.js","names":["abortedError","Observable","BehaviorSubject","toConnectError","combineLatest","tap","map","distinctUntilChanged","shareReplay"],"sources":["../src/api/injectedWallets.ts"],"sourcesContent":["import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tshareReplay,\n\ttap,\n} from \"rxjs\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport { abortedError, type KheopskitError, toConnectError } from \"./errors\";\nimport type { KheopskitStore } from \"./store\";\nimport type { BaseWallet, ConnectOptions, WalletStatus } from \"./types\";\n\n/**\n * Compare two wallet arrays by their relevant properties (not functions).\n * Shared by every platform's injected-wallets stream.\n */\nconst walletsEqual = <\n\tW extends Pick<BaseWallet, \"id\" | \"status\" | \"error\" | \"name\">,\n>(\n\ta: W[],\n\tb: W[],\n): boolean => {\n\tif (a.length !== b.length) return false;\n\treturn a.every(\n\t\t(w, i) =>\n\t\t\tw.id === b[i]?.id &&\n\t\t\tw.status === b[i]?.status &&\n\t\t\tw.error === b[i]?.error &&\n\t\t\tw.name === b[i]?.name,\n\t);\n};\n\n/**\n * The platform-specific surface of an injected-wallets stream. Everything else\n * — the connect/disconnect state machine, the connected-ids bookkeeping, the\n * store persistence, change detection and sharing — is owned by\n * {@link createInjectedWallets$}.\n *\n * @typeParam TSource - a wallet as the platform's registry reports it\n * @typeParam TWallet - the platform's wallet type\n * @typeParam THandle - live connection handle retained while connected\n */\nexport type InjectedWalletsAdapter<\n\tTSource,\n\tTWallet extends BaseWallet,\n\tTHandle = void,\n> = {\n\t/** Live registry of the platform's injected wallets (emits `[]` during SSR). */\n\tsources$: Observable<readonly TSource[]>;\n\t/** Stable wallet id for a registry entry. */\n\tgetWalletId: (source: TSource) => WalletId;\n\t/**\n\t * Platform connect call. The resolved value is retained as the wallet's\n\t * live handle until disconnect.\n\t */\n\tconnect: (source: TSource, walletId: WalletId) => Promise<THandle>;\n\t/** `true` maps the platform's rejection to `USER_REJECTED`; absent means never. */\n\tisUserRejection?: (error: unknown) => boolean;\n\treleaseAbandonedHandle?: (handle: THandle, walletId: WalletId) => void;\n\t/**\n\t * Optional platform disconnect call, awaited before local state clears so a\n\t * failed disconnect rejects without desyncing the connected list.\n\t */\n\tdisconnect?: (source: TSource, walletId: WalletId) => Promise<void>;\n\t/**\n\t * Runs after a disconnect fully applied — the place to drop cached account\n\t * observables so a later reconnect rebuilds them against a fresh handle.\n\t */\n\tonDisconnected?: (walletId: WalletId) => void;\n\t/** Build the platform wallet object for one registry entry. */\n\tbuildWallet: (args: {\n\t\tsource: TSource;\n\t\twalletId: WalletId;\n\t\t/** Live connection handle; `undefined` while disconnected. */\n\t\thandle: THandle | undefined;\n\t\tstatus: WalletStatus;\n\t\terror: KheopskitError | undefined;\n\t\tisConnected: boolean;\n\t\tconnect: (options?: ConnectOptions) => Promise<void>;\n\t\tdisconnect: () => Promise<void>;\n\t}) => TWallet;\n};\n\ntype Connecting = {\n\tstatus: \"connecting\";\n\tpromise: Promise<void>;\n\tanchored: boolean;\n\twaiting: number;\n\tanswered: boolean;\n\tabort: () => void;\n};\n\ntype Connection<THandle> =\n\t| Connecting\n\t| { status: \"connected\"; handle: THandle; disconnecting?: Promise<void> }\n\t| { status: \"disconnected\"; error: KheopskitError };\n\nconst join = (\n\tconnecting: Connecting,\n\twalletId: WalletId,\n\tsignal: AbortSignal | undefined,\n): Promise<void> => {\n\tif (!signal) {\n\t\tconnecting.anchored = true;\n\t\treturn connecting.promise;\n\t}\n\tconnecting.waiting++;\n\treturn new Promise<void>((resolve, reject) => {\n\t\tconst leave = () => {\n\t\t\tif (connecting.answered) return;\n\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\tconnecting.waiting--;\n\t\t\tif (!connecting.anchored && connecting.waiting === 0) connecting.abort();\n\t\t};\n\t\tsignal.addEventListener(\"abort\", leave, { once: true });\n\t\tconnecting.promise\n\t\t\t.then(resolve, reject)\n\t\t\t.finally(() => signal.removeEventListener(\"abort\", leave));\n\t});\n};\n\n/**\n * The shared engine behind every platform's injected-wallets stream: tracks\n * each wallet's connection (pending attempt or live handle), shares one\n * in-flight connect per wallet, persists connected ids to the store for\n * auto-reconnect, and re-emits the wallet list whenever the registry or\n * connection state changes.\n */\nexport const createInjectedWallets$ = <\n\tTSource,\n\tTWallet extends BaseWallet,\n\tTHandle = void,\n>(\n\tstore: KheopskitStore,\n\tadapter: InjectedWalletsAdapter<TSource, TWallet, THandle>,\n): Observable<TWallet[]> =>\n\tnew Observable<TWallet[]>((subscriber) => {\n\t\tconst connections$ = new BehaviorSubject<\n\t\t\tReadonlyMap<WalletId, Connection<THandle>>\n\t\t>(new Map());\n\t\tconst teardown = new AbortController();\n\t\tlet present = new Set<WalletId>();\n\n\t\tconst abortConnectsOfSourcesThatLeft = (sources: readonly TSource[]) => {\n\t\t\tpresent = new Set(sources.map((source) => adapter.getWalletId(source)));\n\t\t\tfor (const [walletId, connection] of connections$.value)\n\t\t\t\tif (connection.status === \"connecting\" && !present.has(walletId))\n\t\t\t\t\tconnection.abort();\n\t\t};\n\n\t\tconst setConnection = (\n\t\t\twalletId: WalletId,\n\t\t\tconnection: Connection<THandle> | undefined,\n\t\t) => {\n\t\t\tconst next = new Map(connections$.value);\n\t\t\tif (connection) next.set(walletId, connection);\n\t\t\telse next.delete(walletId);\n\t\t\tconnections$.next(next);\n\t\t};\n\n\t\tconst startConnect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> => {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst promise = new Promise<void>((resolve, reject) => {\n\t\t\t\tcontroller.signal.addEventListener(\n\t\t\t\t\t\"abort\",\n\t\t\t\t\t() => {\n\t\t\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\t},\n\t\t\t\t\t{ once: true },\n\t\t\t\t);\n\t\t\t\tnew Promise<THandle>((res) =>\n\t\t\t\t\tres(adapter.connect(source, walletId)),\n\t\t\t\t).then(\n\t\t\t\t\t(handle) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) {\n\t\t\t\t\t\t\tadapter.releaseAbandonedHandle?.(handle, walletId);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetConnection(walletId, { status: \"connected\", handle });\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t},\n\t\t\t\t\t(error) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) return;\n\t\t\t\t\t\tconst connectError = toConnectError(\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\twalletId,\n\t\t\t\t\t\t\tadapter.isUserRejection ?? (() => false),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"disconnected\",\n\t\t\t\t\t\t\terror: connectError,\n\t\t\t\t\t\t});\n\t\t\t\t\t\treject(connectError);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t\tconst connecting: Connecting = {\n\t\t\t\tstatus: \"connecting\",\n\t\t\t\tpromise,\n\t\t\t\tanchored: false,\n\t\t\t\twaiting: 0,\n\t\t\t\tanswered: false,\n\t\t\t\tabort: () => {\n\t\t\t\t\tif (connections$.value.get(walletId) === connecting)\n\t\t\t\t\t\tcontroller.abort();\n\t\t\t\t},\n\t\t\t};\n\t\t\tsetConnection(walletId, connecting);\n\t\t\treturn join(connecting, walletId, signal);\n\t\t};\n\n\t\tconst untilSettled = (\n\t\t\tdisconnecting: Promise<void>,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> =>\n\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\tconst signals = signal ? [teardown.signal, signal] : [teardown.signal];\n\t\t\t\tconst settle = () => {\n\t\t\t\t\tfor (const s of signals) s.removeEventListener(\"abort\", settle);\n\t\t\t\t\tif (signals.some((s) => s.aborted))\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\telse resolve();\n\t\t\t\t};\n\t\t\t\tif (signals.some((s) => s.aborted)) return settle();\n\t\t\t\tfor (const s of signals)\n\t\t\t\t\ts.addEventListener(\"abort\", settle, { once: true });\n\t\t\t\tdisconnecting.then(settle, settle);\n\t\t\t});\n\n\t\tconst connect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\toptions?: ConnectOptions,\n\t\t): Promise<void> => {\n\t\t\tif (teardown.signal.aborted || !present.has(walletId))\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tif (current?.status === \"connected\") {\n\t\t\t\tif (!current.disconnecting) return Promise.resolve();\n\t\t\t\treturn untilSettled(\n\t\t\t\t\tcurrent.disconnecting,\n\t\t\t\t\twalletId,\n\t\t\t\t\toptions?.signal,\n\t\t\t\t).then(() => connect(source, walletId, options));\n\t\t\t}\n\t\t\tif (options?.signal?.aborted)\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tif (current?.status === \"connecting\")\n\t\t\t\treturn join(current, walletId, options?.signal);\n\t\t\treturn startConnect(source, walletId, options?.signal);\n\t\t};\n\n\t\tconst disconnect = (source: TSource, walletId: WalletId): Promise<void> => {\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tif (!current || current.status === \"disconnected\")\n\t\t\t\treturn Promise.resolve();\n\t\t\tif (current.status === \"connecting\") {\n\t\t\t\tcurrent.abort();\n\t\t\t\treturn Promise.resolve();\n\t\t\t}\n\t\t\tif (current.disconnecting) return current.disconnecting;\n\n\t\t\tstore.forgetWallet(walletId);\n\t\t\tconst disconnecting = (async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait adapter.disconnect?.(source, walletId);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!teardown.signal.aborted) {\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"connected\",\n\t\t\t\t\t\t\thandle: current.handle,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tif (teardown.signal.aborted) return;\n\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\tadapter.onDisconnected?.(walletId);\n\t\t\t})();\n\t\t\tsetConnection(walletId, { ...current, disconnecting });\n\t\t\treturn disconnecting;\n\t\t};\n\n\t\tconst sub = combineLatest([adapter.sources$, connections$])\n\t\t\t.pipe(\n\t\t\t\ttap(([sources]) => abortConnectsOfSourcesThatLeft(sources)),\n\t\t\t\tmap(([sources, connections]) =>\n\t\t\t\t\tsources.map((source): TWallet => {\n\t\t\t\t\t\tconst walletId = adapter.getWalletId(source);\n\t\t\t\t\t\tconst connection = connections.get(walletId);\n\t\t\t\t\t\tconst connected =\n\t\t\t\t\t\t\tconnection?.status === \"connected\" ? connection : undefined;\n\t\t\t\t\t\treturn adapter.buildWallet({\n\t\t\t\t\t\t\tsource,\n\t\t\t\t\t\t\twalletId,\n\t\t\t\t\t\t\thandle: connected?.handle,\n\t\t\t\t\t\t\tstatus: connection?.status ?? \"disconnected\",\n\t\t\t\t\t\t\terror:\n\t\t\t\t\t\t\t\tconnection?.status === \"disconnected\"\n\t\t\t\t\t\t\t\t\t? connection.error\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\tisConnected: connected !== undefined,\n\t\t\t\t\t\t\tconnect: (options) => connect(source, walletId, options),\n\t\t\t\t\t\t\tdisconnect: () => disconnect(source, walletId),\n\t\t\t\t\t\t});\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\tdistinctUntilChanged(walletsEqual),\n\t\t\t)\n\t\t\t.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tteardown.abort();\n\t\t\tfor (const connection of connections$.value.values())\n\t\t\t\tif (connection.status === \"connecting\") connection.abort();\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n"],"mappings":";;;;;;;AAkBA,MAAM,gBAGL,GACA,MACa;CACb,IAAI,EAAE,WAAW,EAAE,QAAQ,OAAO;CAClC,OAAO,EAAE,OACP,GAAG,MACH,EAAE,OAAO,EAAE,EAAE,EAAE,MACf,EAAE,WAAW,EAAE,EAAE,EAAE,UACnB,EAAE,UAAU,EAAE,EAAE,EAAE,SAClB,EAAE,SAAS,EAAE,EAAE,EAAE,IACnB;AACD;AAmEA,MAAM,QACL,YACA,UACA,WACmB;CACnB,IAAI,CAAC,QAAQ;EACZ,WAAW,WAAW;EACtB,OAAO,WAAW;CACnB;CACA,WAAW;CACX,OAAO,IAAI,SAAe,SAAS,WAAW;EAC7C,MAAM,cAAc;GACnB,IAAI,WAAW,UAAU;GACzB,OAAOA,cAAAA,aAAa,UAAU,SAAS,CAAC;GACxC,WAAW;GACX,IAAI,CAAC,WAAW,YAAY,WAAW,YAAY,GAAG,WAAW,MAAM;EACxE;EACA,OAAO,iBAAiB,SAAS,OAAO,EAAE,MAAM,KAAK,CAAC;EACtD,WAAW,QACT,KAAK,SAAS,MAAM,CAAC,CACrB,cAAc,OAAO,oBAAoB,SAAS,KAAK,CAAC;CAC3D,CAAC;AACF;;;;;;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QAAQ,WAAW;GACnB,QAAQ,YAAY,UAAU;GAC9B,OACC,YAAY,WAAW,iBACpB,WAAW,QACX,KAAA;GACJ,aAAa,cAAc,KAAA;GAC3B,UAAU,YAAY,QAAQ,QAAQ,UAAU,OAAO;GACvD,kBAAkB,WAAW,QAAQ,QAAQ;EAC9C,CAAC;CACF,CAAC,CACF,IAAA,GACAC,KAAAA,qBAAAA,CAAqB,YAAY,CAClC,CAAC,CACA,UAAU,UAAU;CAEtB,aAAa;EACZ,SAAS,MAAM;EACf,KAAK,MAAM,cAAc,aAAa,MAAM,OAAO,GAClD,IAAI,WAAW,WAAW,cAAc,WAAW,MAAM;EAC1D,IAAI,YAAY;CACjB;AACD,CAAC,CAAC,CAAC,MAAA,GAAKC,KAAAA,YAAAA,CAAY;CAAE,UAAU;CAAM,YAAY;AAAE,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"injectedWallets-BQBgS-f0.js","names":["abortedError","Observable","BehaviorSubject","toConnectError","combineLatest","tap","map","distinctUntilChanged","shareReplay"],"sources":["../src/api/injectedWallets.ts"],"sourcesContent":["import {\n\tBehaviorSubject,\n\tcombineLatest,\n\tdistinctUntilChanged,\n\tmap,\n\tObservable,\n\tshareReplay,\n\ttap,\n} from \"rxjs\";\nimport type { WalletId } from \"../utils/WalletId\";\nimport { abortedError, type KheopskitError, toConnectError } from \"./errors\";\nimport type { KheopskitStore } from \"./store\";\nimport type { BaseWallet, ConnectOptions, WalletStatus } from \"./types\";\n\n/**\n * Compare two wallet arrays by their relevant properties (not functions).\n * Shared by every platform's injected-wallets stream.\n */\nconst walletsEqual = <\n\tW extends Pick<BaseWallet, \"id\" | \"status\" | \"error\" | \"name\">,\n>(\n\ta: W[],\n\tb: W[],\n): boolean => {\n\tif (a.length !== b.length) return false;\n\treturn a.every(\n\t\t(w, i) =>\n\t\t\tw.id === b[i]?.id &&\n\t\t\tw.status === b[i]?.status &&\n\t\t\tw.error === b[i]?.error &&\n\t\t\tw.name === b[i]?.name,\n\t);\n};\n\n/**\n * The platform-specific surface of an injected-wallets stream. Everything else\n * — the connect/disconnect state machine, the connected-ids bookkeeping, the\n * store persistence, change detection and sharing — is owned by\n * {@link createInjectedWallets$}.\n *\n * @typeParam TSource - a wallet as the platform's registry reports it\n * @typeParam TWallet - the platform's wallet type\n * @typeParam THandle - live connection handle retained while connected\n */\nexport type InjectedWalletsAdapter<\n\tTSource,\n\tTWallet extends BaseWallet,\n\tTHandle = void,\n> = {\n\t/** Live registry of the platform's injected wallets (emits `[]` during SSR). */\n\tsources$: Observable<readonly TSource[]>;\n\t/** Stable wallet id for a registry entry. */\n\tgetWalletId: (source: TSource) => WalletId;\n\t/**\n\t * Platform connect call. The resolved value is retained as the wallet's\n\t * live handle until disconnect.\n\t */\n\tconnect: (source: TSource, walletId: WalletId) => Promise<THandle>;\n\t/** `true` maps the platform's rejection to `USER_REJECTED`; absent means never. */\n\tisUserRejection?: (error: unknown) => boolean;\n\treleaseAbandonedHandle?: (handle: THandle, walletId: WalletId) => void;\n\t/**\n\t * Optional platform disconnect call, awaited before local state clears so a\n\t * failed disconnect rejects without desyncing the connected list.\n\t */\n\tdisconnect?: (source: TSource, walletId: WalletId) => Promise<void>;\n\t/**\n\t * Runs after a disconnect fully applied — the place to drop cached account\n\t * observables so a later reconnect rebuilds them against a fresh handle.\n\t */\n\tonDisconnected?: (walletId: WalletId) => void;\n\t/** Build the platform wallet object for one registry entry. */\n\tbuildWallet: (args: {\n\t\tsource: TSource;\n\t\twalletId: WalletId;\n\t\t/** Live connection handle; `undefined` while disconnected. */\n\t\thandle: THandle | undefined;\n\t\tstatus: WalletStatus;\n\t\terror: KheopskitError | undefined;\n\t\tisConnected: boolean;\n\t\tconnect: (options?: ConnectOptions) => Promise<void>;\n\t\tdisconnect: () => Promise<void>;\n\t}) => TWallet;\n};\n\ntype Connecting = {\n\tstatus: \"connecting\";\n\tpromise: Promise<void>;\n\tanchored: boolean;\n\twaiting: number;\n\tanswered: boolean;\n\tabort: () => void;\n};\n\ntype Connection<THandle> =\n\t| Connecting\n\t| { status: \"connected\"; handle: THandle; disconnecting?: Promise<void> }\n\t| { status: \"disconnected\"; error: KheopskitError };\n\nconst join = (\n\tconnecting: Connecting,\n\twalletId: WalletId,\n\tsignal: AbortSignal | undefined,\n): Promise<void> => {\n\tif (!signal) {\n\t\tconnecting.anchored = true;\n\t\treturn connecting.promise;\n\t}\n\tconnecting.waiting++;\n\treturn new Promise<void>((resolve, reject) => {\n\t\tconst leave = () => {\n\t\t\tif (connecting.answered) return;\n\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\tconnecting.waiting--;\n\t\t\tif (!connecting.anchored && connecting.waiting === 0) connecting.abort();\n\t\t};\n\t\tsignal.addEventListener(\"abort\", leave, { once: true });\n\t\tconnecting.promise\n\t\t\t.then(resolve, reject)\n\t\t\t.finally(() => signal.removeEventListener(\"abort\", leave));\n\t});\n};\n\n/**\n * The shared engine behind every platform's injected-wallets stream: tracks\n * each wallet's connection (pending attempt or live handle), shares one\n * in-flight connect per wallet, persists connected ids to the store for\n * auto-reconnect, and re-emits the wallet list whenever the registry or\n * connection state changes.\n */\nexport const createInjectedWallets$ = <\n\tTSource,\n\tTWallet extends BaseWallet,\n\tTHandle = void,\n>(\n\tstore: KheopskitStore,\n\tadapter: InjectedWalletsAdapter<TSource, TWallet, THandle>,\n): Observable<TWallet[]> =>\n\tnew Observable<TWallet[]>((subscriber) => {\n\t\tconst connections$ = new BehaviorSubject<\n\t\t\tReadonlyMap<WalletId, Connection<THandle>>\n\t\t>(new Map());\n\t\tconst teardown = new AbortController();\n\t\tlet present = new Set<WalletId>();\n\n\t\tconst abortConnectsOfSourcesThatLeft = (sources: readonly TSource[]) => {\n\t\t\tpresent = new Set(sources.map((source) => adapter.getWalletId(source)));\n\t\t\tfor (const [walletId, connection] of connections$.value)\n\t\t\t\tif (connection.status === \"connecting\" && !present.has(walletId))\n\t\t\t\t\tconnection.abort();\n\t\t};\n\n\t\tconst setConnection = (\n\t\t\twalletId: WalletId,\n\t\t\tconnection: Connection<THandle> | undefined,\n\t\t) => {\n\t\t\tconst next = new Map(connections$.value);\n\t\t\tif (connection) next.set(walletId, connection);\n\t\t\telse next.delete(walletId);\n\t\t\tconnections$.next(next);\n\t\t};\n\n\t\tconst startConnect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> => {\n\t\t\tconst controller = new AbortController();\n\t\t\tconst promise = new Promise<void>((resolve, reject) => {\n\t\t\t\tcontroller.signal.addEventListener(\n\t\t\t\t\t\"abort\",\n\t\t\t\t\t() => {\n\t\t\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\t},\n\t\t\t\t\t{ once: true },\n\t\t\t\t);\n\t\t\t\tnew Promise<THandle>((res) =>\n\t\t\t\t\tres(adapter.connect(source, walletId)),\n\t\t\t\t).then(\n\t\t\t\t\t(handle) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) {\n\t\t\t\t\t\t\tadapter.releaseAbandonedHandle?.(handle, walletId);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsetConnection(walletId, { status: \"connected\", handle });\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t},\n\t\t\t\t\t(error) => {\n\t\t\t\t\t\tconnecting.answered = true;\n\t\t\t\t\t\tif (controller.signal.aborted) return;\n\t\t\t\t\t\tconst connectError = toConnectError(\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\twalletId,\n\t\t\t\t\t\t\tadapter.isUserRejection ?? (() => false),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"disconnected\",\n\t\t\t\t\t\t\terror: connectError,\n\t\t\t\t\t\t});\n\t\t\t\t\t\treject(connectError);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t});\n\t\t\tconst connecting: Connecting = {\n\t\t\t\tstatus: \"connecting\",\n\t\t\t\tpromise,\n\t\t\t\tanchored: false,\n\t\t\t\twaiting: 0,\n\t\t\t\tanswered: false,\n\t\t\t\tabort: () => {\n\t\t\t\t\tif (connections$.value.get(walletId) === connecting)\n\t\t\t\t\t\tcontroller.abort();\n\t\t\t\t},\n\t\t\t};\n\t\t\tsetConnection(walletId, connecting);\n\t\t\treturn join(connecting, walletId, signal);\n\t\t};\n\n\t\tconst untilSettled = (\n\t\t\tdisconnecting: Promise<void>,\n\t\t\twalletId: WalletId,\n\t\t\tsignal: AbortSignal | undefined,\n\t\t): Promise<void> =>\n\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\tconst signals = signal ? [teardown.signal, signal] : [teardown.signal];\n\t\t\t\tconst settle = () => {\n\t\t\t\t\tfor (const s of signals) s.removeEventListener(\"abort\", settle);\n\t\t\t\t\tif (signals.some((s) => s.aborted))\n\t\t\t\t\t\treject(abortedError(walletId, \"connect\"));\n\t\t\t\t\telse resolve();\n\t\t\t\t};\n\t\t\t\tif (signals.some((s) => s.aborted)) return settle();\n\t\t\t\tfor (const s of signals)\n\t\t\t\t\ts.addEventListener(\"abort\", settle, { once: true });\n\t\t\t\tdisconnecting.then(settle, settle);\n\t\t\t});\n\n\t\tconst connect = (\n\t\t\tsource: TSource,\n\t\t\twalletId: WalletId,\n\t\t\toptions?: ConnectOptions,\n\t\t): Promise<void> => {\n\t\t\tif (teardown.signal.aborted || !present.has(walletId))\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tif (current?.status === \"connected\") {\n\t\t\t\tif (!current.disconnecting) return Promise.resolve();\n\t\t\t\treturn untilSettled(\n\t\t\t\t\tcurrent.disconnecting,\n\t\t\t\t\twalletId,\n\t\t\t\t\toptions?.signal,\n\t\t\t\t).then(() => connect(source, walletId, options));\n\t\t\t}\n\t\t\tif (options?.signal?.aborted)\n\t\t\t\treturn Promise.reject(abortedError(walletId, \"connect\"));\n\t\t\tif (current?.status === \"connecting\")\n\t\t\t\treturn join(current, walletId, options?.signal);\n\t\t\treturn startConnect(source, walletId, options?.signal);\n\t\t};\n\n\t\tconst disconnect = (source: TSource, walletId: WalletId): Promise<void> => {\n\t\t\tconst current = connections$.value.get(walletId);\n\t\t\tstore.forgetWallet(walletId);\n\t\t\tif (!current || current.status === \"disconnected\")\n\t\t\t\treturn Promise.resolve();\n\t\t\tif (current.status === \"connecting\") {\n\t\t\t\tcurrent.abort();\n\t\t\t\treturn Promise.resolve();\n\t\t\t}\n\t\t\tif (current.disconnecting) return current.disconnecting;\n\n\t\t\tconst disconnecting = (async () => {\n\t\t\t\ttry {\n\t\t\t\t\tawait adapter.disconnect?.(source, walletId);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!teardown.signal.aborted) {\n\t\t\t\t\t\tsetConnection(walletId, {\n\t\t\t\t\t\t\tstatus: \"connected\",\n\t\t\t\t\t\t\thandle: current.handle,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tstore.rememberWallet(walletId);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tif (teardown.signal.aborted) return;\n\t\t\t\tsetConnection(walletId, undefined);\n\t\t\t\tadapter.onDisconnected?.(walletId);\n\t\t\t})();\n\t\t\tsetConnection(walletId, { ...current, disconnecting });\n\t\t\treturn disconnecting;\n\t\t};\n\n\t\tconst sub = combineLatest([adapter.sources$, connections$])\n\t\t\t.pipe(\n\t\t\t\ttap(([sources]) => abortConnectsOfSourcesThatLeft(sources)),\n\t\t\t\tmap(([sources, connections]) =>\n\t\t\t\t\tsources.map((source): TWallet => {\n\t\t\t\t\t\tconst walletId = adapter.getWalletId(source);\n\t\t\t\t\t\tconst connection = connections.get(walletId);\n\t\t\t\t\t\tconst connected =\n\t\t\t\t\t\t\tconnection?.status === \"connected\" ? connection : undefined;\n\t\t\t\t\t\treturn adapter.buildWallet({\n\t\t\t\t\t\t\tsource,\n\t\t\t\t\t\t\twalletId,\n\t\t\t\t\t\t\thandle: connected?.handle,\n\t\t\t\t\t\t\tstatus: connection?.status ?? \"disconnected\",\n\t\t\t\t\t\t\terror:\n\t\t\t\t\t\t\t\tconnection?.status === \"disconnected\"\n\t\t\t\t\t\t\t\t\t? connection.error\n\t\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t\tisConnected: connected !== undefined,\n\t\t\t\t\t\t\tconnect: (options) => connect(source, walletId, options),\n\t\t\t\t\t\t\tdisconnect: () => disconnect(source, walletId),\n\t\t\t\t\t\t});\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\tdistinctUntilChanged(walletsEqual),\n\t\t\t)\n\t\t\t.subscribe(subscriber);\n\n\t\treturn () => {\n\t\t\tteardown.abort();\n\t\t\tfor (const connection of connections$.value.values())\n\t\t\t\tif (connection.status === \"connecting\") connection.abort();\n\t\t\tsub.unsubscribe();\n\t\t};\n\t}).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n"],"mappings":";;;;;;;AAkBA,MAAM,gBAGL,GACA,MACa;CACb,IAAI,EAAE,WAAW,EAAE,QAAQ,OAAO;CAClC,OAAO,EAAE,OACP,GAAG,MACH,EAAE,OAAO,EAAE,EAAE,EAAE,MACf,EAAE,WAAW,EAAE,EAAE,EAAE,UACnB,EAAE,UAAU,EAAE,EAAE,EAAE,SAClB,EAAE,SAAS,EAAE,EAAE,EAAE,IACnB;AACD;AAmEA,MAAM,QACL,YACA,UACA,WACmB;CACnB,IAAI,CAAC,QAAQ;EACZ,WAAW,WAAW;EACtB,OAAO,WAAW;CACnB;CACA,WAAW;CACX,OAAO,IAAI,SAAe,SAAS,WAAW;EAC7C,MAAM,cAAc;GACnB,IAAI,WAAW,UAAU;GACzB,OAAOA,cAAAA,aAAa,UAAU,SAAS,CAAC;GACxC,WAAW;GACX,IAAI,CAAC,WAAW,YAAY,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C,SAAS,iBACd,QAAQ,KAAK,WAAoB;EAChC,MAAM,WAAW,QAAQ,YAAY,MAAM;EAC3C,MAAM,aAAa,YAAY,IAAI,QAAQ;EAC3C,MAAM,YACL,YAAY,WAAW,cAAc,aAAa,KAAA;EACnD,OAAO,QAAQ,YAAY;GAC1B;GACA;GACA,QAAQ,WAAW;GACnB,QAAQ,YAAY,UAAU;GAC9B,OACC,YAAY,WAAW,iBACpB,WAAW,QACX,KAAA;GACJ,aAAa,cAAc,KAAA;GAC3B,UAAU,YAAY,QAAQ,QAAQ,UAAU,OAAO;GACvD,kBAAkB,WAAW,QAAQ,QAAQ;EAC9C,CAAC;CACF,CAAC,CACF,IAAA,GACAC,KAAAA,qBAAAA,CAAqB,YAAY,CAClC,CAAC,CACA,UAAU,UAAU;CAEtB,aAAa;EACZ,SAAS,MAAM;EACf,KAAK,MAAM,cAAc,aAAa,MAAM,OAAO,GAClD,IAAI,WAAW,WAAW,cAAc,WAAW,MAAM;EAC1D,IAAI,YAAY;CACjB;AACD,CAAC,CAAC,CAAC,MAAA,GAAKC,KAAAA,YAAAA,CAAY;CAAE,UAAU;CAAM,YAAY;AAAE,CAAC,CAAC"}
|
package/dist/internal.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-
|
|
2
|
+
import { a as CachedAccount, b as WalletConnectWallet, i as BaseWalletAccount, o as CachedWallet, r as BaseWallet } from "./types-C3I3w0jb.mjs";
|
|
3
3
|
import { n as clearCachedObservable, r as clearCachedObservablesByPrefix } from "./getCachedObservable-LUq9IfEx.mjs";
|
|
4
4
|
//#region src/utils/hydrateState.d.ts
|
|
5
5
|
/**
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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-
|
|
2
|
+
import { a as CachedAccount, b as WalletConnectWallet, i as BaseWalletAccount, o as CachedWallet, r as BaseWallet } from "./types-C3I3w0jb.js";
|
|
3
3
|
import { n as clearCachedObservable, r as clearCachedObservablesByPrefix } from "./getCachedObservable-LUq9IfEx.js";
|
|
4
4
|
//#region src/utils/hydrateState.d.ts
|
|
5
5
|
/**
|
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-C3I3w0jb.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-C3I3w0jb.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
|
@@ -24,11 +24,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
const require_types = require("./types-BWHvNFlN.js");
|
|
25
25
|
const require_platformAccounts = require("./platformAccounts-BjIeRcFN.js");
|
|
26
26
|
const require_polkadotExtensions = require("./polkadotExtensions-y4J9UzYl.js");
|
|
27
|
-
const
|
|
28
|
-
const require_injectedWallets = require("./injectedWallets-
|
|
27
|
+
const require_registryReads = require("./registryReads-BpHsWLd7.js");
|
|
28
|
+
const require_injectedWallets = require("./injectedWallets-BQBgS-f0.js");
|
|
29
29
|
let _scure_base = require("@scure/base");
|
|
30
|
-
let rxjs = require("rxjs");
|
|
31
30
|
let lodash_es = require("lodash-es");
|
|
31
|
+
let rxjs = require("rxjs");
|
|
32
32
|
let polkadot_api_pjs_signer = require("polkadot-api/pjs-signer");
|
|
33
33
|
polkadot_api_pjs_signer = __toESM(polkadot_api_pjs_signer);
|
|
34
34
|
//#region src/api/polkadot/wallets.ts
|
|
@@ -66,42 +66,8 @@ const connectExtension = (identifier, appName) => {
|
|
|
66
66
|
return connecting;
|
|
67
67
|
};
|
|
68
68
|
const getInjectedWalletsIds = () => typeof window === "undefined" ? [] : (0, polkadot_api_pjs_signer.getInjectedExtensions)().map((name) => require_types.getWalletId("polkadot", name));
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
subscriber.next(getInjectedWalletsIds());
|
|
72
|
-
const intervals = [
|
|
73
|
-
100,
|
|
74
|
-
200,
|
|
75
|
-
300,
|
|
76
|
-
500
|
|
77
|
-
];
|
|
78
|
-
let index = 0;
|
|
79
|
-
let timer;
|
|
80
|
-
const poll = () => {
|
|
81
|
-
subscriber.next(getInjectedWalletsIds());
|
|
82
|
-
if (index < intervals.length) {
|
|
83
|
-
const delay = intervals[index++];
|
|
84
|
-
timer = setTimeout(poll, delay);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
if (intervals.length > 0) timer = setTimeout(poll, intervals[index++] ?? 100);
|
|
88
|
-
let loadTimer;
|
|
89
|
-
const loadSub = require_pageLoad.pageLoaded$.pipe((0, rxjs.skip)(1)).subscribe(() => {
|
|
90
|
-
loadTimer = setTimeout(() => subscriber.next(getInjectedWalletsIds()), 100);
|
|
91
|
-
subscriber.next(getInjectedWalletsIds());
|
|
92
|
-
});
|
|
93
|
-
return () => {
|
|
94
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
95
|
-
clearTimeout(loadTimer);
|
|
96
|
-
loadSub.unsubscribe();
|
|
97
|
-
};
|
|
98
|
-
}).pipe((0, rxjs.distinctUntilChanged)(lodash_es.isEqual), (0, rxjs.shareReplay)({
|
|
99
|
-
refCount: true,
|
|
100
|
-
bufferSize: 1
|
|
101
|
-
}));
|
|
102
|
-
};
|
|
103
|
-
const getPolkadotWallets$ = (store, config) => require_injectedWallets.createInjectedWallets$(store, {
|
|
104
|
-
sources$: createWalletIdsPoller$(),
|
|
69
|
+
const getPolkadotWallets$ = (store, config, registryReads$ = require_registryReads.createRegistryReads$()) => require_injectedWallets.createInjectedWallets$(store, {
|
|
70
|
+
sources$: registryReads$.pipe((0, rxjs.map)(getInjectedWalletsIds), (0, rxjs.distinctUntilChanged)(lodash_es.isEqual)),
|
|
105
71
|
getWalletId: (walletId) => walletId,
|
|
106
72
|
connect: (walletId) => connectExtension(require_types.parseWalletId(walletId).identifier, config.appName || config.walletConnect?.metadata.name || window.location.hostname),
|
|
107
73
|
isUserRejection: require_types.isRefusalMessage,
|
|
@@ -297,7 +263,7 @@ const polkadot = (options = {}) => {
|
|
|
297
263
|
if (invalid.length > 0) console.warn(`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: "sr25519", "ed25519", "ecdsa", "ethereum".`);
|
|
298
264
|
return {
|
|
299
265
|
platform: "polkadot",
|
|
300
|
-
getWallets$: (ctx) => getPolkadotWallets$(ctx.store, ctx.config),
|
|
266
|
+
getWallets$: (ctx) => getPolkadotWallets$(ctx.store, ctx.config, ctx.registryReads$),
|
|
301
267
|
getAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),
|
|
302
268
|
acceptsCachedAccount: (cached) => accountTypes.includes(cached.polkadotAccountType ?? "sr25519")
|
|
303
269
|
};
|
package/dist/polkadot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polkadot.js","names":["getInjectedExtensions","getWalletId","Observable","pageLoaded$","skip","distinctUntilChanged","isEqual","shareReplay","createInjectedWallets$","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, Observable, shareReplay, skip } from \"rxjs\";\nimport { pageLoaded$ } from \"../../utils/pageLoad\";\nimport { POLKADOT_EXTENSIONS } from \"../../utils/polkadotExtensions\";\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// Create a polling observable that starts immediately and polls at intervals\nconst createWalletIdsPoller$ = () => {\n\treturn new Observable<WalletId[]>((subscriber) => {\n\t\t// Emit immediately on subscribe\n\t\tsubscriber.next(getInjectedWalletsIds());\n\n\t\t// Poll at shorter intervals initially, then slow down\n\t\tconst intervals = [100, 200, 300, 500];\n\t\tlet index = 0;\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\n\t\tconst poll = () => {\n\t\t\tsubscriber.next(getInjectedWalletsIds());\n\t\t\tif (index < intervals.length) {\n\t\t\t\tconst delay = intervals[index++];\n\t\t\t\ttimer = setTimeout(poll, delay);\n\t\t\t}\n\t\t};\n\n\t\t// Start polling after first immediate emission\n\t\tif (intervals.length > 0) {\n\t\t\ttimer = setTimeout(poll, intervals[index++] ?? 100);\n\t\t}\n\n\t\tlet loadTimer: ReturnType<typeof setTimeout> | undefined;\n\t\tconst loadSub = pageLoaded$.pipe(skip(1)).subscribe(() => {\n\t\t\tloadTimer = setTimeout(\n\t\t\t\t() => subscriber.next(getInjectedWalletsIds()),\n\t\t\t\t100,\n\t\t\t);\n\t\t\tsubscriber.next(getInjectedWalletsIds());\n\t\t});\n\n\t\treturn () => {\n\t\t\t// Cancel any pending poll so it can't fire after unsubscribe.\n\t\t\tif (timer !== undefined) clearTimeout(timer);\n\t\t\tclearTimeout(loadTimer);\n\t\t\tloadSub.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tdistinctUntilChanged<WalletId[]>(isEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n};\n\n// The shared WalletConnect connector is emitted once by core (see\n// `getWallets$`), not per platform — so this returns only injected wallets.\nexport const getPolkadotWallets$ = (\n\tstore: KheopskitStore,\n\tconfig: Pick<KheopskitConfig, \"appName\" | \"walletConnect\">,\n) =>\n\tcreateInjectedWallets$<WalletId, PolkadotInjectedWallet, PolkadotInjected>(\n\t\tstore,\n\t\t{\n\t\t\tsources$: createWalletIdsPoller$(),\n\t\t\tgetWalletId: (walletId) => walletId,\n\t\t\tconnect: (walletId) =>\n\t\t\t\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\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 { field, factory } = getPjsSignerField();\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]: factory(address, signPayload, signRaw, 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};\n\n/**\n * polkadot-api v3 replaced `polkadotSigner` (PolkadotSigner) with `txCreator`\n * (TxCreator). Which one the app's installed version provides is detected at\n * runtime so a single @kheopskit/core release supports both.\n */\nconst getPjsSignerField = (): {\n\tfield: \"txCreator\" | \"polkadotSigner\";\n\tfactory: PjsSignerFactory;\n} => {\n\tconst module = pjs as PjsSignerModule;\n\tif (module.getTxCreatorFromPjs)\n\t\treturn { field: \"txCreator\", factory: module.getTxCreatorFromPjs };\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 `getKheopskit$({ platforms: [polkadot()] })`.\n *\n * @example\n * ```ts\n * import { polkadot } from \"@kheopskit/core/polkadot\";\n * polkadot({ accountTypes: [\"sr25519\", \"ed25519\", \"ecdsa\"] });\n * ```\n */\nexport const polkadot = (\n\toptions: PolkadotPluginOptions = {},\n): KheopskitPlatform<\"polkadot\", PolkadotWallet, PolkadotAccount> => {\n\tconst accountTypes = options.accountTypes ?? DEFAULT_ACCOUNT_TYPES;\n\n\tconst invalid = accountTypes.filter((t) => !VALID_ACCOUNT_TYPES.has(t));\n\tif (invalid.length > 0) {\n\t\tconsole.warn(\n\t\t\t`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: \"sr25519\", \"ed25519\", \"ecdsa\", \"ethereum\".`,\n\t\t);\n\t}\n\n\treturn {\n\t\tplatform: \"polkadot\",\n\t\tgetWallets$: (ctx: PlatformContext) =>\n\t\t\tgetPolkadotWallets$(ctx.store, ctx.config),\n\t\tgetAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),\n\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AQ,SAAS,GACpB,QAAQ,KACP,8CAA8C,KAAK,UAAU,OAAO,EAAE,2DACvE;CAGD,OAAO;EACN,UAAU;EACV,cAAc,QACb,oBAAoB,IAAI,OAAO,IAAI,MAAM;EAC1C,eAAe,aAAa,qBAAqB,UAAU,YAAY;EACvE,uBAAuB,WACtB,aAAa,SAAS,OAAO,uBAAuB,SAAS;CAC/D;AACD"}
|
|
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\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 { field, factory } = getPjsSignerField();\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]: factory(address, signPayload, signRaw, 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};\n\n/**\n * polkadot-api v3 replaced `polkadotSigner` (PolkadotSigner) with `txCreator`\n * (TxCreator). Which one the app's installed version provides is detected at\n * runtime so a single @kheopskit/core release supports both.\n */\nconst getPjsSignerField = (): {\n\tfield: \"txCreator\" | \"polkadotSigner\";\n\tfactory: PjsSignerFactory;\n} => {\n\tconst module = pjs as PjsSignerModule;\n\tif (module.getTxCreatorFromPjs)\n\t\treturn { field: \"txCreator\", factory: module.getTxCreatorFromPjs };\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 `getKheopskit$({ platforms: [polkadot()] })`.\n *\n * @example\n * ```ts\n * import { polkadot } from \"@kheopskit/core/polkadot\";\n * polkadot({ accountTypes: [\"sr25519\", \"ed25519\", \"ecdsa\"] });\n * ```\n */\nexport const polkadot = (\n\toptions: PolkadotPluginOptions = {},\n): KheopskitPlatform<\"polkadot\", PolkadotWallet, PolkadotAccount> => {\n\tconst accountTypes = options.accountTypes ?? DEFAULT_ACCOUNT_TYPES;\n\n\tconst invalid = accountTypes.filter((t) => !VALID_ACCOUNT_TYPES.has(t));\n\tif (invalid.length > 0) {\n\t\tconsole.warn(\n\t\t\t`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: \"sr25519\", \"ed25519\", \"ecdsa\", \"ethereum\".`,\n\t\t);\n\t}\n\n\treturn {\n\t\tplatform: \"polkadot\",\n\t\tgetWallets$: (ctx: PlatformContext) =>\n\t\t\tgetPolkadotWallets$(ctx.store, ctx.config, 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,g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, r as KheopskitError, t as isInjectedWallet, u as getWalletId } from "./types-Yor672md.mjs";
|
|
2
2
|
import { a as getWalletConnectSessionAccounts$, i as getSessionCaip10s, l as isSs58Address, o as getWalletAccountId, r as getCaip10Addresses, t as createPlatformAccounts$ } from "./platformAccounts-yyRUrnel.mjs";
|
|
3
3
|
import { t as POLKADOT_EXTENSIONS } from "./polkadotExtensions-BoVKhNU_.mjs";
|
|
4
|
-
import { t as
|
|
5
|
-
import { t as createInjectedWallets$ } from "./injectedWallets-
|
|
4
|
+
import { t as createRegistryReads$ } from "./registryReads-BvtznSo3.mjs";
|
|
5
|
+
import { t as createInjectedWallets$ } from "./injectedWallets-5GL1Jder.mjs";
|
|
6
6
|
import { hex } from "@scure/base";
|
|
7
|
-
import { Observable, distinctUntilChanged, of, shareReplay, skip } from "rxjs";
|
|
8
7
|
import { isEqual } from "lodash-es";
|
|
8
|
+
import { Observable, distinctUntilChanged, map, of } from "rxjs";
|
|
9
9
|
import * as pjs from "polkadot-api/pjs-signer";
|
|
10
10
|
import { getInjectedExtensions } from "polkadot-api/pjs-signer";
|
|
11
11
|
//#region src/api/polkadot/wallets.ts
|
|
@@ -43,42 +43,8 @@ const connectExtension = (identifier, appName) => {
|
|
|
43
43
|
return connecting;
|
|
44
44
|
};
|
|
45
45
|
const getInjectedWalletsIds = () => typeof window === "undefined" ? [] : getInjectedExtensions().map((name) => getWalletId("polkadot", name));
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
subscriber.next(getInjectedWalletsIds());
|
|
49
|
-
const intervals = [
|
|
50
|
-
100,
|
|
51
|
-
200,
|
|
52
|
-
300,
|
|
53
|
-
500
|
|
54
|
-
];
|
|
55
|
-
let index = 0;
|
|
56
|
-
let timer;
|
|
57
|
-
const poll = () => {
|
|
58
|
-
subscriber.next(getInjectedWalletsIds());
|
|
59
|
-
if (index < intervals.length) {
|
|
60
|
-
const delay = intervals[index++];
|
|
61
|
-
timer = setTimeout(poll, delay);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
if (intervals.length > 0) timer = setTimeout(poll, intervals[index++] ?? 100);
|
|
65
|
-
let loadTimer;
|
|
66
|
-
const loadSub = pageLoaded$.pipe(skip(1)).subscribe(() => {
|
|
67
|
-
loadTimer = setTimeout(() => subscriber.next(getInjectedWalletsIds()), 100);
|
|
68
|
-
subscriber.next(getInjectedWalletsIds());
|
|
69
|
-
});
|
|
70
|
-
return () => {
|
|
71
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
72
|
-
clearTimeout(loadTimer);
|
|
73
|
-
loadSub.unsubscribe();
|
|
74
|
-
};
|
|
75
|
-
}).pipe(distinctUntilChanged(isEqual), shareReplay({
|
|
76
|
-
refCount: true,
|
|
77
|
-
bufferSize: 1
|
|
78
|
-
}));
|
|
79
|
-
};
|
|
80
|
-
const getPolkadotWallets$ = (store, config) => createInjectedWallets$(store, {
|
|
81
|
-
sources$: createWalletIdsPoller$(),
|
|
46
|
+
const getPolkadotWallets$ = (store, config, registryReads$ = createRegistryReads$()) => createInjectedWallets$(store, {
|
|
47
|
+
sources$: registryReads$.pipe(map(getInjectedWalletsIds), distinctUntilChanged(isEqual)),
|
|
82
48
|
getWalletId: (walletId) => walletId,
|
|
83
49
|
connect: (walletId) => connectExtension(parseWalletId(walletId).identifier, config.appName || config.walletConnect?.metadata.name || window.location.hostname),
|
|
84
50
|
isUserRejection: isRefusalMessage,
|
|
@@ -274,7 +240,7 @@ const polkadot = (options = {}) => {
|
|
|
274
240
|
if (invalid.length > 0) console.warn(`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: "sr25519", "ed25519", "ecdsa", "ethereum".`);
|
|
275
241
|
return {
|
|
276
242
|
platform: "polkadot",
|
|
277
|
-
getWallets$: (ctx) => getPolkadotWallets$(ctx.store, ctx.config),
|
|
243
|
+
getWallets$: (ctx) => getPolkadotWallets$(ctx.store, ctx.config, ctx.registryReads$),
|
|
278
244
|
getAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),
|
|
279
245
|
acceptsCachedAccount: (cached) => accountTypes.includes(cached.polkadotAccountType ?? "sr25519")
|
|
280
246
|
};
|
package/dist/polkadot.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polkadot.mjs","names":[],"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, Observable, shareReplay, skip } from \"rxjs\";\nimport { pageLoaded$ } from \"../../utils/pageLoad\";\nimport { POLKADOT_EXTENSIONS } from \"../../utils/polkadotExtensions\";\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// Create a polling observable that starts immediately and polls at intervals\nconst createWalletIdsPoller$ = () => {\n\treturn new Observable<WalletId[]>((subscriber) => {\n\t\t// Emit immediately on subscribe\n\t\tsubscriber.next(getInjectedWalletsIds());\n\n\t\t// Poll at shorter intervals initially, then slow down\n\t\tconst intervals = [100, 200, 300, 500];\n\t\tlet index = 0;\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\n\t\tconst poll = () => {\n\t\t\tsubscriber.next(getInjectedWalletsIds());\n\t\t\tif (index < intervals.length) {\n\t\t\t\tconst delay = intervals[index++];\n\t\t\t\ttimer = setTimeout(poll, delay);\n\t\t\t}\n\t\t};\n\n\t\t// Start polling after first immediate emission\n\t\tif (intervals.length > 0) {\n\t\t\ttimer = setTimeout(poll, intervals[index++] ?? 100);\n\t\t}\n\n\t\tlet loadTimer: ReturnType<typeof setTimeout> | undefined;\n\t\tconst loadSub = pageLoaded$.pipe(skip(1)).subscribe(() => {\n\t\t\tloadTimer = setTimeout(\n\t\t\t\t() => subscriber.next(getInjectedWalletsIds()),\n\t\t\t\t100,\n\t\t\t);\n\t\t\tsubscriber.next(getInjectedWalletsIds());\n\t\t});\n\n\t\treturn () => {\n\t\t\t// Cancel any pending poll so it can't fire after unsubscribe.\n\t\t\tif (timer !== undefined) clearTimeout(timer);\n\t\t\tclearTimeout(loadTimer);\n\t\t\tloadSub.unsubscribe();\n\t\t};\n\t}).pipe(\n\t\tdistinctUntilChanged<WalletId[]>(isEqual),\n\t\tshareReplay({ refCount: true, bufferSize: 1 }),\n\t);\n};\n\n// The shared WalletConnect connector is emitted once by core (see\n// `getWallets$`), not per platform — so this returns only injected wallets.\nexport const getPolkadotWallets$ = (\n\tstore: KheopskitStore,\n\tconfig: Pick<KheopskitConfig, \"appName\" | \"walletConnect\">,\n) =>\n\tcreateInjectedWallets$<WalletId, PolkadotInjectedWallet, PolkadotInjected>(\n\t\tstore,\n\t\t{\n\t\t\tsources$: createWalletIdsPoller$(),\n\t\t\tgetWalletId: (walletId) => walletId,\n\t\t\tconnect: (walletId) =>\n\t\t\t\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\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 { field, factory } = getPjsSignerField();\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]: factory(address, signPayload, signRaw, 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};\n\n/**\n * polkadot-api v3 replaced `polkadotSigner` (PolkadotSigner) with `txCreator`\n * (TxCreator). Which one the app's installed version provides is detected at\n * runtime so a single @kheopskit/core release supports both.\n */\nconst getPjsSignerField = (): {\n\tfield: \"txCreator\" | \"polkadotSigner\";\n\tfactory: PjsSignerFactory;\n} => {\n\tconst module = pjs as PjsSignerModule;\n\tif (module.getTxCreatorFromPjs)\n\t\treturn { field: \"txCreator\", factory: module.getTxCreatorFromPjs };\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 `getKheopskit$({ platforms: [polkadot()] })`.\n *\n * @example\n * ```ts\n * import { polkadot } from \"@kheopskit/core/polkadot\";\n * polkadot({ accountTypes: [\"sr25519\", \"ed25519\", \"ecdsa\"] });\n * ```\n */\nexport const polkadot = (\n\toptions: PolkadotPluginOptions = {},\n): KheopskitPlatform<\"polkadot\", PolkadotWallet, PolkadotAccount> => {\n\tconst accountTypes = options.accountTypes ?? DEFAULT_ACCOUNT_TYPES;\n\n\tconst invalid = accountTypes.filter((t) => !VALID_ACCOUNT_TYPES.has(t));\n\tif (invalid.length > 0) {\n\t\tconsole.warn(\n\t\t\t`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: \"sr25519\", \"ed25519\", \"ecdsa\", \"ethereum\".`,\n\t\t);\n\t}\n\n\treturn {\n\t\tplatform: \"polkadot\",\n\t\tgetWallets$: (ctx: PlatformContext) =>\n\t\t\tgetPolkadotWallets$(ctx.store, ctx.config),\n\t\tgetAccounts$: (wallets$) => getPolkadotAccounts$(wallets$, accountTypes),\n\t\tacceptsCachedAccount: (cached) =>\n\t\t\taccountTypes.includes(cached.polkadotAccountType ?? \"sr25519\"),\n\t};\n};\n"],"mappings":";;;;;;;;;;;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,MA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AO;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,OAAO,wBAAwB;EAC9B,UAAU;EACV,sBAAsB;EACtB;EACA,cAAc,aACb,SAAS,QAAQ,YAAY,qBAAqB,SAAS,QAAQ,IAAI,CAAC;CAC1E,CAAC;AACF;;;ACrPA,MAAM,wBAA+C;CACpD;CACA;CACA;AACD;AAEA,MAAM,sCAAsB,IAAI,IAAY;CAC3C;CACA;CACA;CACA;AACD,CAAC;;;;;;;;;;AAqBD,MAAa,YACZ,UAAiC,CAAC,MACkC;CACpE,MAAM,eAAe,QAAQ,gBAAgB;CAE7C,MAAM,UAAU,aAAa,QAAQ,MAAM,CAAC,oBAAoB,IAAI,CAAC,CAAC;CACtE,IAAI,QAAQ,SAAS,GACpB,QAAQ,KACP,8CAA8C,KAAK,UAAU,OAAO,EAAE,2DACvE;CAGD,OAAO;EACN,UAAU;EACV,cAAc,QACb,oBAAoB,IAAI,OAAO,IAAI,MAAM;EAC1C,eAAe,aAAa,qBAAqB,UAAU,YAAY;EACvE,uBAAuB,WACtB,aAAa,SAAS,OAAO,uBAAuB,SAAS;CAC/D;AACD"}
|
|
1
|
+
{"version":3,"file":"polkadot.mjs","names":[],"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\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 { field, factory } = getPjsSignerField();\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]: factory(address, signPayload, signRaw, 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};\n\n/**\n * polkadot-api v3 replaced `polkadotSigner` (PolkadotSigner) with `txCreator`\n * (TxCreator). Which one the app's installed version provides is detected at\n * runtime so a single @kheopskit/core release supports both.\n */\nconst getPjsSignerField = (): {\n\tfield: \"txCreator\" | \"polkadotSigner\";\n\tfactory: PjsSignerFactory;\n} => {\n\tconst module = pjs as PjsSignerModule;\n\tif (module.getTxCreatorFromPjs)\n\t\treturn { field: \"txCreator\", factory: module.getTxCreatorFromPjs };\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 `getKheopskit$({ platforms: [polkadot()] })`.\n *\n * @example\n * ```ts\n * import { polkadot } from \"@kheopskit/core/polkadot\";\n * polkadot({ accountTypes: [\"sr25519\", \"ed25519\", \"ecdsa\"] });\n * ```\n */\nexport const polkadot = (\n\toptions: PolkadotPluginOptions = {},\n): KheopskitPlatform<\"polkadot\", PolkadotWallet, PolkadotAccount> => {\n\tconst accountTypes = options.accountTypes ?? DEFAULT_ACCOUNT_TYPES;\n\n\tconst invalid = accountTypes.filter((t) => !VALID_ACCOUNT_TYPES.has(t));\n\tif (invalid.length > 0) {\n\t\tconsole.warn(\n\t\t\t`[kheopskit] Unknown polkadot accountTypes: ${JSON.stringify(invalid)}. Valid values: \"sr25519\", \"ed25519\", \"ecdsa\", \"ethereum\".`,\n\t\t);\n\t}\n\n\treturn {\n\t\tplatform: \"polkadot\",\n\t\tgetWallets$: (ctx: PlatformContext) =>\n\t\t\tgetPolkadotWallets$(ctx.store, ctx.config, 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,IA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@
|
|
|
1
|
+
let rxjs = require("rxjs");
|
|
2
|
+
//#region src/utils/pageLoad.ts
|
|
3
|
+
const pageLoaded$ = new rxjs.Observable((subscriber) => {
|
|
4
|
+
if (typeof document === "undefined") {
|
|
5
|
+
subscriber.next(false);
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (document.readyState === "complete") {
|
|
9
|
+
subscriber.next(true);
|
|
10
|
+
subscriber.complete();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
subscriber.next(false);
|
|
14
|
+
const onLoad = () => {
|
|
15
|
+
subscriber.next(true);
|
|
16
|
+
subscriber.complete();
|
|
17
|
+
};
|
|
18
|
+
window.addEventListener("load", onLoad, { once: true });
|
|
19
|
+
return () => window.removeEventListener("load", onLoad);
|
|
20
|
+
});
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/utils/registryReads.ts
|
|
23
|
+
const tail$ = (0, rxjs.merge)((0, rxjs.of)(void 0), ...[
|
|
24
|
+
100,
|
|
25
|
+
300,
|
|
26
|
+
600,
|
|
27
|
+
1100
|
|
28
|
+
].map((ms) => (0, rxjs.timer)(ms))).pipe((0, rxjs.map)(() => void 0));
|
|
29
|
+
const createRegistryReads$ = () => typeof window === "undefined" ? (0, rxjs.concat)((0, rxjs.of)(void 0), rxjs.NEVER) : pageLoaded$.pipe((0, rxjs.switchMap)(() => tail$));
|
|
30
|
+
//#endregion
|
|
31
|
+
Object.defineProperty(exports, "createRegistryReads$", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function() {
|
|
34
|
+
return createRegistryReads$;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=registryReads-BpHsWLd7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registryReads-BpHsWLd7.js","names":["Observable","merge","of","timer","map","concat","NEVER","switchMap"],"sources":["../src/utils/pageLoad.ts","../src/utils/registryReads.ts"],"sourcesContent":["import { Observable } from \"rxjs\";\n\nexport const pageLoaded$ = new Observable<boolean>((subscriber) => {\n\tif (typeof document === \"undefined\") {\n\t\tsubscriber.next(false);\n\t\treturn;\n\t}\n\n\tif (document.readyState === \"complete\") {\n\t\tsubscriber.next(true);\n\t\tsubscriber.complete();\n\t\treturn;\n\t}\n\n\tsubscriber.next(false);\n\n\tconst onLoad = () => {\n\t\tsubscriber.next(true);\n\t\tsubscriber.complete();\n\t};\n\twindow.addEventListener(\"load\", onLoad, { once: true });\n\n\treturn () => window.removeEventListener(\"load\", onLoad);\n});\n","import {\n\tconcat,\n\tmap,\n\tmerge,\n\tNEVER,\n\ttype Observable,\n\tof,\n\tswitchMap,\n\ttimer,\n} from \"rxjs\";\nimport { pageLoaded$ } from \"./pageLoad\";\n\nconst READ_TAIL_MS = [100, 300, 600, 1100];\n\nconst tail$: Observable<void> = merge(\n\tof(undefined),\n\t...READ_TAIL_MS.map((ms) => timer(ms)),\n).pipe(map(() => undefined));\n\nexport const createRegistryReads$ = (): Observable<void> =>\n\ttypeof window === \"undefined\"\n\t\t? concat(of(undefined), NEVER)\n\t\t: pageLoaded$.pipe(switchMap(() => tail$));\n"],"mappings":";;AAEA,MAAa,cAAc,IAAIA,KAAAA,YAAqB,eAAe;CAClE,IAAI,OAAO,aAAa,aAAa;EACpC,WAAW,KAAK,KAAK;EACrB;CACD;CAEA,IAAI,SAAS,eAAe,YAAY;EACvC,WAAW,KAAK,IAAI;EACpB,WAAW,SAAS;EACpB;CACD;CAEA,WAAW,KAAK,KAAK;CAErB,MAAM,eAAe;EACpB,WAAW,KAAK,IAAI;EACpB,WAAW,SAAS;CACrB;CACA,OAAO,iBAAiB,QAAQ,QAAQ,EAAE,MAAM,KAAK,CAAC;CAEtD,aAAa,OAAO,oBAAoB,QAAQ,MAAM;AACvD,CAAC;;;ACTD,MAAM,SAAA,GAA0BC,KAAAA,MAAAA,EAAAA,GAC/BC,KAAAA,GAAAA,CAAG,KAAA,CAAS,GACZ,GAAG;CAJkB;CAAK;CAAK;CAAK;AAItB,CAAC,CAAC,KAAK,QAAA,GAAOC,KAAAA,MAAAA,CAAM,EAAE,CAAC,CACtC,CAAC,CAAC,MAAA,GAAKC,KAAAA,IAAAA,OAAU,KAAA,CAAS,CAAC;AAE3B,MAAa,6BACZ,OAAO,WAAW,eAAA,GACfC,KAAAA,OAAAA,EAAAA,GAAOH,KAAAA,GAAAA,CAAG,KAAA,CAAS,GAAGI,KAAAA,KAAK,IAC3B,YAAY,MAAA,GAAKC,KAAAA,UAAAA,OAAgB,KAAK,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
1
|
+
import { NEVER, Observable, concat, map, merge, of, switchMap, timer } from "rxjs";
|
|
2
2
|
//#region src/utils/pageLoad.ts
|
|
3
3
|
const pageLoaded$ = new Observable((subscriber) => {
|
|
4
4
|
if (typeof document === "undefined") {
|
|
@@ -19,6 +19,15 @@ const pageLoaded$ = new Observable((subscriber) => {
|
|
|
19
19
|
return () => window.removeEventListener("load", onLoad);
|
|
20
20
|
});
|
|
21
21
|
//#endregion
|
|
22
|
-
|
|
22
|
+
//#region src/utils/registryReads.ts
|
|
23
|
+
const tail$ = merge(of(void 0), ...[
|
|
24
|
+
100,
|
|
25
|
+
300,
|
|
26
|
+
600,
|
|
27
|
+
1100
|
|
28
|
+
].map((ms) => timer(ms))).pipe(map(() => void 0));
|
|
29
|
+
const createRegistryReads$ = () => typeof window === "undefined" ? concat(of(void 0), NEVER) : pageLoaded$.pipe(switchMap(() => tail$));
|
|
30
|
+
//#endregion
|
|
31
|
+
export { createRegistryReads$ as t };
|
|
23
32
|
|
|
24
|
-
//# sourceMappingURL=
|
|
33
|
+
//# sourceMappingURL=registryReads-BvtznSo3.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registryReads-BvtznSo3.mjs","names":[],"sources":["../src/utils/pageLoad.ts","../src/utils/registryReads.ts"],"sourcesContent":["import { Observable } from \"rxjs\";\n\nexport const pageLoaded$ = new Observable<boolean>((subscriber) => {\n\tif (typeof document === \"undefined\") {\n\t\tsubscriber.next(false);\n\t\treturn;\n\t}\n\n\tif (document.readyState === \"complete\") {\n\t\tsubscriber.next(true);\n\t\tsubscriber.complete();\n\t\treturn;\n\t}\n\n\tsubscriber.next(false);\n\n\tconst onLoad = () => {\n\t\tsubscriber.next(true);\n\t\tsubscriber.complete();\n\t};\n\twindow.addEventListener(\"load\", onLoad, { once: true });\n\n\treturn () => window.removeEventListener(\"load\", onLoad);\n});\n","import {\n\tconcat,\n\tmap,\n\tmerge,\n\tNEVER,\n\ttype Observable,\n\tof,\n\tswitchMap,\n\ttimer,\n} from \"rxjs\";\nimport { pageLoaded$ } from \"./pageLoad\";\n\nconst READ_TAIL_MS = [100, 300, 600, 1100];\n\nconst tail$: Observable<void> = merge(\n\tof(undefined),\n\t...READ_TAIL_MS.map((ms) => timer(ms)),\n).pipe(map(() => undefined));\n\nexport const createRegistryReads$ = (): Observable<void> =>\n\ttypeof window === \"undefined\"\n\t\t? concat(of(undefined), NEVER)\n\t\t: pageLoaded$.pipe(switchMap(() => tail$));\n"],"mappings":";;AAEA,MAAa,cAAc,IAAI,YAAqB,eAAe;CAClE,IAAI,OAAO,aAAa,aAAa;EACpC,WAAW,KAAK,KAAK;EACrB;CACD;CAEA,IAAI,SAAS,eAAe,YAAY;EACvC,WAAW,KAAK,IAAI;EACpB,WAAW,SAAS;EACpB;CACD;CAEA,WAAW,KAAK,KAAK;CAErB,MAAM,eAAe;EACpB,WAAW,KAAK,IAAI;EACpB,WAAW,SAAS;CACrB;CACA,OAAO,iBAAiB,QAAQ,QAAQ,EAAE,MAAM,KAAK,CAAC;CAEtD,aAAa,OAAO,oBAAoB,QAAQ,MAAM;AACvD,CAAC;;;ACTD,MAAM,QAA0B,MAC/B,GAAG,KAAA,CAAS,GACZ,GAAG;CAJkB;CAAK;CAAK;CAAK;AAItB,CAAC,CAAC,KAAK,OAAO,MAAM,EAAE,CAAC,CACtC,CAAC,CAAC,KAAK,UAAU,KAAA,CAAS,CAAC;AAE3B,MAAa,6BACZ,OAAO,WAAW,cACf,OAAO,GAAG,KAAA,CAAS,GAAG,KAAK,IAC3B,YAAY,KAAK,gBAAgB,KAAK,CAAC"}
|
package/dist/solana.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as isWalletConnectWallet, N as WalletAccountId, T as isInjectedWallet, b as WalletConnectWallet, 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, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, p as Placeholder, r as BaseWallet } from "./types-C3I3w0jb.mjs";
|
|
2
2
|
import { MessageModifyingSigner, TransactionModifyingSigner, TransactionSendingSigner } from "@solana/kit";
|
|
3
3
|
import { Wallet } from "@wallet-standard/base";
|
|
4
4
|
//#region src/utils/isSolanaAddress.d.ts
|
|
@@ -76,6 +76,7 @@ type LiveSolanaAccount = {
|
|
|
76
76
|
signer: SolanaSigner;
|
|
77
77
|
/** Returns a signer bound to an arbitrary cluster. */
|
|
78
78
|
getSigner: (chain: SolanaChainId) => SolanaSigner;
|
|
79
|
+
name?: string;
|
|
79
80
|
walletName: string;
|
|
80
81
|
walletId: WalletId;
|
|
81
82
|
};
|
package/dist/solana.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as isWalletConnectWallet, N as WalletAccountId, T as isInjectedWallet, b as WalletConnectWallet, 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, k as WalletId, l as KheopskitPlatform, m as PlaceholderWallet, p as Placeholder, r as BaseWallet } from "./types-C3I3w0jb.js";
|
|
2
2
|
import { MessageModifyingSigner, TransactionModifyingSigner, TransactionSendingSigner } from "@solana/kit";
|
|
3
3
|
import { Wallet } from "@wallet-standard/base";
|
|
4
4
|
//#region src/utils/isSolanaAddress.d.ts
|
|
@@ -76,6 +76,7 @@ type LiveSolanaAccount = {
|
|
|
76
76
|
signer: SolanaSigner;
|
|
77
77
|
/** Returns a signer bound to an arbitrary cluster. */
|
|
78
78
|
getSigner: (chain: SolanaChainId) => SolanaSigner;
|
|
79
|
+
name?: string;
|
|
79
80
|
walletName: string;
|
|
80
81
|
walletId: WalletId;
|
|
81
82
|
};
|
package/dist/solana.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_types = require("./types-BWHvNFlN.js");
|
|
3
3
|
const require_platformAccounts = require("./platformAccounts-BjIeRcFN.js");
|
|
4
|
-
const require_injectedWallets = require("./injectedWallets-
|
|
4
|
+
const require_injectedWallets = require("./injectedWallets-BQBgS-f0.js");
|
|
5
5
|
let rxjs = require("rxjs");
|
|
6
6
|
let _solana_kit = require("@solana/kit");
|
|
7
7
|
let _wallet_standard_app = require("@wallet-standard/app");
|
|
@@ -206,6 +206,7 @@ const getInjectedWalletAccounts$ = (wallet, chain) => {
|
|
|
206
206
|
chains: wallet.chains,
|
|
207
207
|
signer: createInjectedSolanaSigner(standardWallet, account, chain),
|
|
208
208
|
getSigner: (c) => createInjectedSolanaSigner(standardWallet, account, c),
|
|
209
|
+
name: account.label,
|
|
209
210
|
walletName: wallet.name,
|
|
210
211
|
walletId: wallet.id
|
|
211
212
|
}));
|