@rango-dev/provider-solflare 0.0.0-experimental-936229e8-20251208
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 +130 -0
- package/dist/actions/solana.d.ts +9 -0
- package/dist/constants.d.ts +4 -0
- package/dist/hooks/solana.d.ts +7 -0
- package/dist/mod.d.ts +2 -0
- package/dist/mod.js +2 -0
- package/dist/mod.js.map +7 -0
- package/dist/namespaces/solana.d.ts +3 -0
- package/dist/provider-solflare.build.json +1 -0
- package/dist/provider.d.ts +2 -0
- package/dist/signer.d.ts +3 -0
- package/dist/signers/solana.d.ts +5 -0
- package/dist/types.d.ts +6 -0
- package/dist/utils.d.ts +5 -0
- package/package.json +35 -0
- package/readme.md +19 -0
- package/src/actions/solana.ts +35 -0
- package/src/constants.ts +42 -0
- package/src/hooks/solana.ts +47 -0
- package/src/mod.ts +8 -0
- package/src/namespaces/solana.ts +49 -0
- package/src/provider.ts +22 -0
- package/src/signer.ts +18 -0
- package/src/signers/solana.ts +24 -0
- package/src/types.ts +10 -0
- package/src/utils.ts +41 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# [0.22.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.21.1...provider-solflare@0.22.0) (2025-12-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## [0.21.1](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.21.0...provider-solflare@0.21.1) (2025-11-22)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# [0.19.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.18.0...provider-solflare@0.19.0) (2025-10-29)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# [0.18.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.17.0...provider-solflare@0.18.0) (2025-09-29)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [0.17.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.16.0...provider-solflare@0.17.0) (2025-09-06)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# [0.16.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.15.0...provider-solflare@0.16.0) (2025-08-19)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [0.15.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.14.0...provider-solflare@0.15.0) (2025-08-05)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# [0.14.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.13.0...provider-solflare@0.14.0) (2025-07-22)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Reverts
|
|
33
|
+
|
|
34
|
+
* Revert "chore(release): publish" ([064ce15](https://github.com/rango-exchange/rango-client/commit/064ce157a2f819856f647f83aeb1c0410542e8d7))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# [0.12.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.11.1...provider-solflare@0.12.0) (2025-06-09)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## [0.11.1](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.11.0...provider-solflare@0.11.1) (2025-05-04)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# [0.11.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.10.0...provider-solflare@0.11.0) (2025-04-30)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Bug Fixes
|
|
50
|
+
|
|
51
|
+
* rename pbt to ptb for sui ([3d6d89f](https://github.com/rango-exchange/rango-client/commit/3d6d89f2265766607a15d61e0df92643fb33072b))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### Features
|
|
55
|
+
|
|
56
|
+
* update sui to consider recent api changes ([d764b25](https://github.com/rango-exchange/rango-client/commit/d764b2501df9bb295f63cdbc0b05acd4a3abb4b9))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# [0.10.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.9.0...provider-solflare@0.10.0) (2025-03-11)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# [0.9.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.8.0...provider-solflare@0.9.0) (2025-02-23)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# [0.8.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.7.0...provider-solflare@0.8.0) (2025-01-20)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# [0.7.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.6.0...provider-solflare@0.7.0) (2024-12-30)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# [0.6.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.5.0...provider-solflare@0.6.0) (2024-11-27)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
### Features
|
|
80
|
+
|
|
81
|
+
* add ton connect provider ([2a2dbb7](https://github.com/rango-exchange/rango-client/commit/2a2dbb79022263f19446ced49d298e04d63f927f))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# [0.5.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.4.1...provider-solflare@0.5.0) (2024-11-12)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## [0.4.1](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.4.0...provider-solflare@0.4.1) (2024-10-30)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### Bug Fixes
|
|
93
|
+
|
|
94
|
+
* when host is using cjs, fallback to .default() for solfare sdk ([0aa702a](https://github.com/rango-exchange/rango-client/commit/0aa702ab1bed865a049541e87c4fa3b1a5006c1d))
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# [0.4.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.3.0...provider-solflare@0.4.0) (2024-10-12)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
### Bug Fixes
|
|
102
|
+
|
|
103
|
+
* bump sdk and fix type issues ([d442208](https://github.com/rango-exchange/rango-client/commit/d4422083bf5dd27d5f509ce1db7f9560d05428c8))
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
### Performance Improvements
|
|
107
|
+
|
|
108
|
+
* enable code splitting in build process ([fe5a41e](https://github.com/rango-exchange/rango-client/commit/fe5a41e0e297298de11cd74ca5825544742aa03a))
|
|
109
|
+
* lazy load signer packages ([7b88f18](https://github.com/rango-exchange/rango-client/commit/7b88f1834f7b29b4b81ab6c81a07bb88e8ccf55c))
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
# [0.3.0](https://github.com/rango-exchange/rango-client/compare/provider-solflare@0.2.0...provider-solflare@0.3.0) (2024-09-10)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### Bug Fixes
|
|
117
|
+
|
|
118
|
+
* fix solfare and solfare-snap signers ([896c70b](https://github.com/rango-exchange/rango-client/commit/896c70b8cc8b5e29ec6dfcd98378ef0b3f05698f))
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# 0.2.0 (2024-08-11)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
### Features
|
|
126
|
+
|
|
127
|
+
* integrate solflare wallet ([fb6aaf1](https://github.com/rango-exchange/rango-client/commit/fb6aaf1c255149df18a75a7bfb16fc83c23b85a8))
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context, FunctionWithContext } from '@rango-dev/wallets-core';
|
|
2
|
+
import { type ProviderAPI, type SolanaActions } from '@rango-dev/wallets-core/namespaces/solana';
|
|
3
|
+
declare function connect(instance: () => ProviderAPI): FunctionWithContext<SolanaActions['connect'], Context>;
|
|
4
|
+
declare function canEagerConnect(instance: () => ProviderAPI): () => any;
|
|
5
|
+
export declare const solanaActions: {
|
|
6
|
+
canEagerConnect: typeof canEagerConnect;
|
|
7
|
+
connect: typeof connect;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Subscriber, SubscriberCleanUp } from '@rango-dev/wallets-core';
|
|
2
|
+
import type { ProviderAPI, SolanaActions } from '@rango-dev/wallets-core/namespaces/solana';
|
|
3
|
+
declare function getDisconnectSubscriber(instance: () => ProviderAPI): [Subscriber<SolanaActions>, SubscriberCleanUp<SolanaActions>];
|
|
4
|
+
export declare const solanaHooks: {
|
|
5
|
+
getDisconnectSubscriber: typeof getDisconnectSubscriber;
|
|
6
|
+
};
|
|
7
|
+
export {};
|
package/dist/mod.d.ts
ADDED
package/dist/mod.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var v=Object.defineProperty;var n=(e,o)=>v(e,"name",{value:o,configurable:!0});import{defineVersions as Y}from"@rango-dev/wallets-core/utils";import{ProviderBuilder as R}from"@rango-dev/wallets-core";import"@rango-dev/wallets-core";import{solanaBlockchain as L}from"rango-types";import{LegacyNetworks as x}from"@rango-dev/wallets-core/legacy";import{getNetworkInstance as E}from"@rango-dev/wallets-shared";import{DefaultSignerFactory as C,TransactionType as I}from"rango-types";import{DefaultSolanaSigner as y}from"@rango-dev/signer-solana";import P from"bs58";var i=class extends y{static{n(this,"SolflareSolanaSiger")}constructor(o){super(o)}async signMessage(o){let a=new TextEncoder().encode(o),t=await this.provider.signMessage(a,"utf8");return P.encode(t.signature)}};async function d(e){let o=new C,r=E(e,x.SOLANA);return o.registerSigner(I.SOLANA,new i(r)),o}n(d,"getSigners");import{LegacyNetworks as p}from"@rango-dev/wallets-core/legacy";function c(){let e=new Map,{solflare:o}=window;return o?(e.set(p.SOLANA,o),e):null}n(c,"solflare");function f(){let e=c();if(!e)throw new Error("Solflare Wallet is not injected. Please check your wallet.");return e}n(f,"getInstanceOrThrow");function s(){let o=c()?.get(p.SOLANA);if(!o)throw new Error("Solflare Wallet not injected or Solana not enabled. Please check your wallet.");return o}n(s,"solanaSolflare");var l="solflare",u=1e3,g={name:"Solflare",icon:"https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/solflare/icon.svg",extensions:{chrome:"https://chromewebstore.google.com/detail/solflare-wallet/bhhhlbepdkbapadjdnnojkbgioiodbic",brave:"https://chromewebstore.google.com/detail/solflare-wallet/bhhhlbepdkbapadjdnnojkbgioiodbic",firefox:"https://addons.mozilla.org/en-US/firefox/addon/solflare-wallet/",edge:"https://chromewebstore.google.com/detail/solflare-wallet/bhhhlbepdkbapadjdnnojkbgioiodbic",homepage:"https://solflare.com"},properties:[{name:"namespaces",value:{selection:"multiple",data:[{label:"Solana",value:"Solana",id:"SOLANA",getSupportedChains:e=>L(e)}]}},{name:"signers",value:{getSigners:async()=>d(f())}}]};import{ActionBuilder as j,NamespaceBuilder as D}from"@rango-dev/wallets-core";import{builders as F,standardizeAndThrowError as B}from"@rango-dev/wallets-core/namespaces/common";import{builders as _,hooks as M}from"@rango-dev/wallets-core/namespaces/solana";import{utils as k}from"@rango-dev/wallets-core/namespaces/solana";function T(e){return async()=>{let o=e();if(!await o.connect())throw new Error("Connecting to solana has been failed");return k.formatAccountsToCAIP([o.publicKey.toString()])}}n(T,"connect");function N(e){return()=>{let o=e();if(!o)throw new Error("Trying to eagerly connect to your Solana wallet, but seems its instance is not available.");return o.isConnected}}n(N,"canEagerConnect");var m={canEagerConnect:N,connect:T};function O(e){let o;return[(r,a)=>{let t=e();if(!t)throw new Error("Trying to subscribe to your Solana wallet, but seems its instance is not available.");if(o=n(()=>{r.action("disconnect")},"eventCallback"),t.on("disconnect",o),a instanceof Error)throw a},(r,a)=>{let t=e();return o&&t&&t.removeListener("disconnect",o),a}]}n(O,"getDisconnectSubscriber");var b={getDisconnectSubscriber:O};var[W,S]=M.changeAccountSubscriber(s),[U,w]=b.getDisconnectSubscriber(s),z=_.connect().action(m.connect(s)).before(W).before(U).or(S).or(w).or(B).build(),H=F.disconnect().and(w).after(S).build(),J=new j("canEagerConnect").action(m.canEagerConnect(s)).build(),h=new D("Solana",l).action(z).action(H).action(J).build();var A=n(()=>new R(l).init(function(e){let[,o]=e.state();setTimeout(()=>{c()&&(o("installed",!0),console.debug("[solflare] instance detected.",e))},u)}).config("metadata",g).add("solana",h).build(),"buildProvider");var jo=n(()=>Y().version("1.0.0",A()).build(),"versions");export{jo as versions};
|
|
2
|
+
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/mod.ts", "../src/provider.ts", "../src/constants.ts", "../src/signer.ts", "../src/signers/solana.ts", "../src/utils.ts", "../src/namespaces/solana.ts", "../src/actions/solana.ts", "../src/hooks/solana.ts"],
|
|
4
|
+
"sourcesContent": ["import { defineVersions } from '@rango-dev/wallets-core/utils';\n\nimport { buildProvider } from './provider.js';\n\nconst versions = () =>\n defineVersions().version('1.0.0', buildProvider()).build();\n\nexport { versions };\n", "import { ProviderBuilder } from '@rango-dev/wallets-core';\n\nimport { metadata, SOLFLARE_INJECTION_DELAY, WALLET_ID } from './constants.js';\nimport { solana } from './namespaces/solana.js';\nimport { solflare } from './utils.js';\n\nconst buildProvider = () =>\n new ProviderBuilder(WALLET_ID)\n .init(function (context) {\n const [, setState] = context.state();\n setTimeout(() => {\n if (solflare()) {\n setState('installed', true);\n console.debug('[solflare] instance detected.', context);\n }\n }, SOLFLARE_INJECTION_DELAY);\n })\n .config('metadata', metadata)\n .add('solana', solana)\n .build();\n\nexport { buildProvider };\n", "import { type ProviderMetadata } from '@rango-dev/wallets-core';\nimport { type BlockchainMeta, solanaBlockchain } from 'rango-types';\n\nimport getSigners from './signer.js';\nimport { getInstanceOrThrow } from './utils.js';\n\nexport const WALLET_ID = 'solflare';\nexport const SOLFLARE_INJECTION_DELAY = 1000;\nexport const metadata: ProviderMetadata = {\n name: 'Solflare',\n icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/solflare/icon.svg',\n extensions: {\n chrome:\n 'https://chromewebstore.google.com/detail/solflare-wallet/bhhhlbepdkbapadjdnnojkbgioiodbic',\n brave:\n 'https://chromewebstore.google.com/detail/solflare-wallet/bhhhlbepdkbapadjdnnojkbgioiodbic',\n firefox: 'https://addons.mozilla.org/en-US/firefox/addon/solflare-wallet/',\n edge: 'https://chromewebstore.google.com/detail/solflare-wallet/bhhhlbepdkbapadjdnnojkbgioiodbic',\n homepage: 'https://solflare.com',\n },\n properties: [\n {\n name: 'namespaces',\n value: {\n selection: 'multiple',\n data: [\n {\n label: 'Solana',\n value: 'Solana',\n id: 'SOLANA',\n getSupportedChains: (allBlockchains: BlockchainMeta[]) =>\n solanaBlockchain(allBlockchains),\n },\n ],\n },\n },\n {\n name: 'signers',\n value: { getSigners: async () => getSigners(getInstanceOrThrow()) },\n },\n ],\n};\n", "import type { Provider } from './types.js';\nimport type { SignerFactory } from 'rango-types';\n\nimport { LegacyNetworks } from '@rango-dev/wallets-core/legacy';\nimport { getNetworkInstance } from '@rango-dev/wallets-shared';\nimport { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';\n\nimport { SolflareSolanaSiger } from './signers/solana.js';\n\nexport default async function getSigners(\n provider: Provider\n): Promise<SignerFactory> {\n const signers = new DefaultSignerFactory();\n const solProvider = getNetworkInstance(provider, LegacyNetworks.SOLANA);\n\n signers.registerSigner(TxType.SOLANA, new SolflareSolanaSiger(solProvider));\n return signers;\n}\n", "import {\n DefaultSolanaSigner,\n type SolanaExternalProvider,\n} from '@rango-dev/signer-solana';\nimport base58 from 'bs58';\n\nexport class SolflareSolanaSiger extends DefaultSolanaSigner {\n constructor(provider: SolanaExternalProvider) {\n super(provider);\n }\n\n async signMessage(msg: string): Promise<string> {\n const encoder = new TextEncoder();\n const messageBytes = encoder.encode(msg);\n // Used any instead of Solflare because there is an issue in type of `signTransaction` method of Solflare\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const messageSignature = await (this.provider as any).signMessage(\n messageBytes,\n 'utf8'\n );\n\n return base58.encode(messageSignature.signature);\n }\n}\n", "import type { Provider } from './types.js';\nimport type { ProviderAPI as SolanaProviderApi } from '@rango-dev/wallets-core/namespaces/solana';\n\nimport { LegacyNetworks } from '@rango-dev/wallets-core/legacy';\n\nexport function solflare(): Provider | null {\n const instances: Provider = new Map();\n const { solflare } = window;\n if (!solflare) {\n return null;\n }\n\n instances.set(LegacyNetworks.SOLANA, solflare);\n\n return instances;\n}\n\nexport function getInstanceOrThrow(): Provider {\n const instances = solflare();\n\n if (!instances) {\n throw new Error(\n 'Solflare Wallet is not injected. Please check your wallet.'\n );\n }\n\n return instances;\n}\n\nexport function solanaSolflare(): SolanaProviderApi {\n const instance = solflare();\n const solanaInstance = instance?.get(LegacyNetworks.SOLANA);\n\n if (!solanaInstance) {\n throw new Error(\n 'Solflare Wallet not injected or Solana not enabled. Please check your wallet.'\n );\n }\n\n return solanaInstance;\n}\n", "import type { SolanaActions } from '@rango-dev/wallets-core/namespaces/solana';\n\nimport { ActionBuilder, NamespaceBuilder } from '@rango-dev/wallets-core';\nimport {\n builders as commonBuilders,\n standardizeAndThrowError,\n} from '@rango-dev/wallets-core/namespaces/common';\nimport { builders, hooks } from '@rango-dev/wallets-core/namespaces/solana';\n\nimport { solanaActions } from '../actions/solana.js';\nimport { WALLET_ID } from '../constants.js';\nimport { solanaHooks } from '../hooks/solana.js';\nimport { solanaSolflare } from '../utils.js';\n\nconst [changeAccountSubscriber, changeAccountCleanup] =\n hooks.changeAccountSubscriber(solanaSolflare);\n\nconst [disconnectSubscriber, disconnectCleanUp] =\n solanaHooks.getDisconnectSubscriber(solanaSolflare);\n\nconst connect = builders\n .connect()\n .action(solanaActions.connect(solanaSolflare))\n .before(changeAccountSubscriber)\n .before(disconnectSubscriber)\n .or(changeAccountCleanup)\n .or(disconnectCleanUp)\n .or(standardizeAndThrowError)\n .build();\n\nconst disconnect = commonBuilders\n .disconnect<SolanaActions>()\n .and(disconnectCleanUp)\n .after(changeAccountCleanup)\n .build();\n\nconst canEagerConnect = new ActionBuilder<SolanaActions, 'canEagerConnect'>(\n 'canEagerConnect'\n)\n .action(solanaActions.canEagerConnect(solanaSolflare))\n .build();\n\nconst solana = new NamespaceBuilder<SolanaActions>('Solana', WALLET_ID)\n .action(connect)\n .action(disconnect)\n .action(canEagerConnect)\n .build();\n\nexport { solana };\n", "import type { Context, FunctionWithContext } from '@rango-dev/wallets-core';\n\nimport {\n type ProviderAPI,\n type SolanaActions,\n utils,\n} from '@rango-dev/wallets-core/namespaces/solana';\n\nfunction connect(\n instance: () => ProviderAPI\n): FunctionWithContext<SolanaActions['connect'], Context> {\n return async () => {\n const solanaInstance = instance();\n const isConnected = await solanaInstance.connect();\n\n if (!isConnected) {\n throw new Error('Connecting to solana has been failed');\n }\n\n return utils.formatAccountsToCAIP([solanaInstance.publicKey.toString()]);\n };\n}\nfunction canEagerConnect(instance: () => ProviderAPI) {\n return () => {\n const solanaInstance = instance();\n\n if (!solanaInstance) {\n throw new Error(\n 'Trying to eagerly connect to your Solana wallet, but seems its instance is not available.'\n );\n }\n return solanaInstance.isConnected;\n };\n}\nexport const solanaActions = { canEagerConnect, connect };\n", "import type {\n AnyFunction,\n Subscriber,\n SubscriberCleanUp,\n} from '@rango-dev/wallets-core';\nimport type {\n ProviderAPI,\n SolanaActions,\n} from '@rango-dev/wallets-core/namespaces/solana';\n\nfunction getDisconnectSubscriber(\n instance: () => ProviderAPI\n): [Subscriber<SolanaActions>, SubscriberCleanUp<SolanaActions>] {\n let eventCallback: AnyFunction;\n\n // subscriber can be passed to `or`, it will get the error and should rethrow error to pass the error to next `or` or throw error.\n return [\n (context, err) => {\n const solanaInstance = instance();\n\n if (!solanaInstance) {\n throw new Error(\n 'Trying to subscribe to your Solana wallet, but seems its instance is not available.'\n );\n }\n\n eventCallback = () => {\n context.action('disconnect');\n };\n solanaInstance.on('disconnect', eventCallback);\n\n if (err instanceof Error) {\n throw err;\n }\n },\n (_context, err) => {\n const solanaInstance = instance();\n\n if (eventCallback && solanaInstance) {\n solanaInstance.removeListener('disconnect', eventCallback);\n }\n\n return err;\n },\n ];\n}\nexport const solanaHooks = { getDisconnectSubscriber };\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["defineVersions", "ProviderBuilder", "solanaBlockchain", "LegacyNetworks", "getNetworkInstance", "DefaultSignerFactory", "TxType", "DefaultSolanaSigner", "base58", "SolflareSolanaSiger", "DefaultSolanaSigner", "__name", "provider", "msg", "messageBytes", "messageSignature", "base58", "getSigners", "provider", "signers", "DefaultSignerFactory", "solProvider", "getNetworkInstance", "LegacyNetworks", "TxType", "SolflareSolanaSiger", "__name", "LegacyNetworks", "solflare", "instances", "LegacyNetworks", "__name", "getInstanceOrThrow", "solanaSolflare", "solanaInstance", "WALLET_ID", "SOLFLARE_INJECTION_DELAY", "metadata", "allBlockchains", "solanaBlockchain", "getSigners", "getInstanceOrThrow", "ActionBuilder", "NamespaceBuilder", "commonBuilders", "standardizeAndThrowError", "builders", "hooks", "utils", "connect", "instance", "solanaInstance", "utils", "__name", "canEagerConnect", "solanaActions", "getDisconnectSubscriber", "instance", "eventCallback", "context", "err", "solanaInstance", "__name", "_context", "solanaHooks", "changeAccountSubscriber", "changeAccountCleanup", "hooks", "solanaSolflare", "disconnectSubscriber", "disconnectCleanUp", "solanaHooks", "connect", "builders", "solanaActions", "standardizeAndThrowError", "disconnect", "commonBuilders", "canEagerConnect", "ActionBuilder", "solana", "NamespaceBuilder", "WALLET_ID", "buildProvider", "__name", "ProviderBuilder", "WALLET_ID", "context", "setState", "solflare", "SOLFLARE_INJECTION_DELAY", "metadata", "solana", "versions", "__name", "defineVersions", "buildProvider"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"src/signers/solana.ts":{"bytes":751,"imports":[{"path":"@rango-dev/signer-solana","kind":"import-statement","external":true},{"path":"bs58","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/signer.ts":{"bytes":676,"imports":[{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signers/solana.ts","kind":"import-statement","original":"./signers/solana.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/utils.ts":{"bytes":988,"imports":[{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/constants.ts":{"bytes":1414,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"src/signer.ts","kind":"import-statement","original":"./signer.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"}],"format":"esm"},"src/actions/solana.ts":{"bytes":980,"imports":[{"path":"@rango-dev/wallets-core/namespaces/solana","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/hooks/solana.ts":{"bytes":1220,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/namespaces/solana.ts":{"bytes":1489,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/solana","kind":"import-statement","external":true},{"path":"src/actions/solana.ts","kind":"import-statement","original":"../actions/solana.js"},{"path":"src/constants.ts","kind":"import-statement","original":"../constants.js"},{"path":"src/hooks/solana.ts","kind":"import-statement","original":"../hooks/solana.js"},{"path":"src/utils.ts","kind":"import-statement","original":"../utils.js"}],"format":"esm"},"src/provider.ts":{"bytes":677,"imports":[{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"src/constants.ts","kind":"import-statement","original":"./constants.js"},{"path":"src/namespaces/solana.ts","kind":"import-statement","original":"./namespaces/solana.js"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/mod.ts":{"bytes":220,"imports":[{"path":"@rango-dev/wallets-core/utils","kind":"import-statement","external":true},{"path":"src/provider.ts","kind":"import-statement","original":"./provider.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"dist/mod.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":13825},"dist/mod.js":{"imports":[{"path":"@rango-dev/wallets-core/utils","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-shared","kind":"import-statement","external":true},{"path":"rango-types","kind":"import-statement","external":true},{"path":"@rango-dev/signer-solana","kind":"import-statement","external":true},{"path":"bs58","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/legacy","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/common","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/solana","kind":"import-statement","external":true},{"path":"@rango-dev/wallets-core/namespaces/solana","kind":"import-statement","external":true}],"exports":["versions"],"entryPoint":"src/mod.ts","inputs":{"src/mod.ts":{"bytesInOutput":121},"src/provider.ts":{"bytesInOutput":272},"src/constants.ts":{"bytesInOutput":821},"src/signer.ts":{"bytesInOutput":310},"src/signers/solana.ts":{"bytesInOutput":296},"src/utils.ts":{"bytesInOutput":477},"src/namespaces/solana.ts":{"bytesInOutput":574},"src/actions/solana.ts":{"bytesInOutput":488},"src/hooks/solana.ts":{"bytesInOutput":389}},"bytes":3883}}}
|
package/dist/signer.d.ts
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
|
|
2
|
+
import type { ProviderAPI as SolanaProviderApi } from '@rango-dev/wallets-core/namespaces/solana';
|
|
3
|
+
export type ProviderObject = {
|
|
4
|
+
[LegacyNetworks.SOLANA]: SolanaProviderApi;
|
|
5
|
+
};
|
|
6
|
+
export type Provider = Map<keyof ProviderObject, ProviderObject[keyof ProviderObject]>;
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Provider } from './types.js';
|
|
2
|
+
import type { ProviderAPI as SolanaProviderApi } from '@rango-dev/wallets-core/namespaces/solana';
|
|
3
|
+
export declare function solflare(): Provider | null;
|
|
4
|
+
export declare function getInstanceOrThrow(): Provider;
|
|
5
|
+
export declare function solanaSolflare(): SolanaProviderApi;
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rango-dev/provider-solflare",
|
|
3
|
+
"version": "0.0.0-experimental-936229e8-20251208",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"source": "./src/mod.ts",
|
|
7
|
+
"main": "./dist/mod.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./dist/mod.js"
|
|
10
|
+
},
|
|
11
|
+
"typings": "dist/mod.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"src"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "node ../../scripts/build/command.mjs --path wallets/provider-solflare --inputs src/mod.ts",
|
|
18
|
+
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
|
|
19
|
+
"clean": "rimraf dist",
|
|
20
|
+
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
|
|
21
|
+
"lint": "eslint \"**/*.{ts,tsx}\""
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@rango-dev/signer-solana": "^0.46.1",
|
|
25
|
+
"@rango-dev/wallets-core": "^0.0.0-experimental-936229e8-20251208",
|
|
26
|
+
"@rango-dev/wallets-shared": "^0.0.0-experimental-936229e8-20251208",
|
|
27
|
+
"@solana/web3.js": "^1.91.4",
|
|
28
|
+
"@solflare-wallet/sdk": "^1.4.2",
|
|
29
|
+
"bs58": "^5.0.0",
|
|
30
|
+
"rango-types": "^0.1.89"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Solflare
|
|
2
|
+
|
|
3
|
+
Solflare integration for hub.
|
|
4
|
+
[Homepage](https://solflare.com/) | [Docs](https://docs.solflare.com/)
|
|
5
|
+
|
|
6
|
+
More about implementation status can be found [here](../readme.md).
|
|
7
|
+
|
|
8
|
+
## Implementation notes/limitations
|
|
9
|
+
|
|
10
|
+
### Feature
|
|
11
|
+
|
|
12
|
+
#### ⚠️ Switch Account
|
|
13
|
+
|
|
14
|
+
When the user switches to an account that **does not have prior permissions** granted to the dApp,
|
|
15
|
+
Solflare **automatically disconnects** the current session.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
More wallet information can be found in [readme.md](../readme.md).
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Context, FunctionWithContext } from '@rango-dev/wallets-core';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type ProviderAPI,
|
|
5
|
+
type SolanaActions,
|
|
6
|
+
utils,
|
|
7
|
+
} from '@rango-dev/wallets-core/namespaces/solana';
|
|
8
|
+
|
|
9
|
+
function connect(
|
|
10
|
+
instance: () => ProviderAPI
|
|
11
|
+
): FunctionWithContext<SolanaActions['connect'], Context> {
|
|
12
|
+
return async () => {
|
|
13
|
+
const solanaInstance = instance();
|
|
14
|
+
const isConnected = await solanaInstance.connect();
|
|
15
|
+
|
|
16
|
+
if (!isConnected) {
|
|
17
|
+
throw new Error('Connecting to solana has been failed');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return utils.formatAccountsToCAIP([solanaInstance.publicKey.toString()]);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function canEagerConnect(instance: () => ProviderAPI) {
|
|
24
|
+
return () => {
|
|
25
|
+
const solanaInstance = instance();
|
|
26
|
+
|
|
27
|
+
if (!solanaInstance) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
'Trying to eagerly connect to your Solana wallet, but seems its instance is not available.'
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return solanaInstance.isConnected;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export const solanaActions = { canEagerConnect, connect };
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ProviderMetadata } from '@rango-dev/wallets-core';
|
|
2
|
+
import { type BlockchainMeta, solanaBlockchain } from 'rango-types';
|
|
3
|
+
|
|
4
|
+
import getSigners from './signer.js';
|
|
5
|
+
import { getInstanceOrThrow } from './utils.js';
|
|
6
|
+
|
|
7
|
+
export const WALLET_ID = 'solflare';
|
|
8
|
+
export const SOLFLARE_INJECTION_DELAY = 1000;
|
|
9
|
+
export const metadata: ProviderMetadata = {
|
|
10
|
+
name: 'Solflare',
|
|
11
|
+
icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/solflare/icon.svg',
|
|
12
|
+
extensions: {
|
|
13
|
+
chrome:
|
|
14
|
+
'https://chromewebstore.google.com/detail/solflare-wallet/bhhhlbepdkbapadjdnnojkbgioiodbic',
|
|
15
|
+
brave:
|
|
16
|
+
'https://chromewebstore.google.com/detail/solflare-wallet/bhhhlbepdkbapadjdnnojkbgioiodbic',
|
|
17
|
+
firefox: 'https://addons.mozilla.org/en-US/firefox/addon/solflare-wallet/',
|
|
18
|
+
edge: 'https://chromewebstore.google.com/detail/solflare-wallet/bhhhlbepdkbapadjdnnojkbgioiodbic',
|
|
19
|
+
homepage: 'https://solflare.com',
|
|
20
|
+
},
|
|
21
|
+
properties: [
|
|
22
|
+
{
|
|
23
|
+
name: 'namespaces',
|
|
24
|
+
value: {
|
|
25
|
+
selection: 'multiple',
|
|
26
|
+
data: [
|
|
27
|
+
{
|
|
28
|
+
label: 'Solana',
|
|
29
|
+
value: 'Solana',
|
|
30
|
+
id: 'SOLANA',
|
|
31
|
+
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
|
|
32
|
+
solanaBlockchain(allBlockchains),
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'signers',
|
|
39
|
+
value: { getSigners: async () => getSigners(getInstanceOrThrow()) },
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnyFunction,
|
|
3
|
+
Subscriber,
|
|
4
|
+
SubscriberCleanUp,
|
|
5
|
+
} from '@rango-dev/wallets-core';
|
|
6
|
+
import type {
|
|
7
|
+
ProviderAPI,
|
|
8
|
+
SolanaActions,
|
|
9
|
+
} from '@rango-dev/wallets-core/namespaces/solana';
|
|
10
|
+
|
|
11
|
+
function getDisconnectSubscriber(
|
|
12
|
+
instance: () => ProviderAPI
|
|
13
|
+
): [Subscriber<SolanaActions>, SubscriberCleanUp<SolanaActions>] {
|
|
14
|
+
let eventCallback: AnyFunction;
|
|
15
|
+
|
|
16
|
+
// subscriber can be passed to `or`, it will get the error and should rethrow error to pass the error to next `or` or throw error.
|
|
17
|
+
return [
|
|
18
|
+
(context, err) => {
|
|
19
|
+
const solanaInstance = instance();
|
|
20
|
+
|
|
21
|
+
if (!solanaInstance) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
'Trying to subscribe to your Solana wallet, but seems its instance is not available.'
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
eventCallback = () => {
|
|
28
|
+
context.action('disconnect');
|
|
29
|
+
};
|
|
30
|
+
solanaInstance.on('disconnect', eventCallback);
|
|
31
|
+
|
|
32
|
+
if (err instanceof Error) {
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
(_context, err) => {
|
|
37
|
+
const solanaInstance = instance();
|
|
38
|
+
|
|
39
|
+
if (eventCallback && solanaInstance) {
|
|
40
|
+
solanaInstance.removeListener('disconnect', eventCallback);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return err;
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
export const solanaHooks = { getDisconnectSubscriber };
|
package/src/mod.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { SolanaActions } from '@rango-dev/wallets-core/namespaces/solana';
|
|
2
|
+
|
|
3
|
+
import { ActionBuilder, NamespaceBuilder } from '@rango-dev/wallets-core';
|
|
4
|
+
import {
|
|
5
|
+
builders as commonBuilders,
|
|
6
|
+
standardizeAndThrowError,
|
|
7
|
+
} from '@rango-dev/wallets-core/namespaces/common';
|
|
8
|
+
import { builders, hooks } from '@rango-dev/wallets-core/namespaces/solana';
|
|
9
|
+
|
|
10
|
+
import { solanaActions } from '../actions/solana.js';
|
|
11
|
+
import { WALLET_ID } from '../constants.js';
|
|
12
|
+
import { solanaHooks } from '../hooks/solana.js';
|
|
13
|
+
import { solanaSolflare } from '../utils.js';
|
|
14
|
+
|
|
15
|
+
const [changeAccountSubscriber, changeAccountCleanup] =
|
|
16
|
+
hooks.changeAccountSubscriber(solanaSolflare);
|
|
17
|
+
|
|
18
|
+
const [disconnectSubscriber, disconnectCleanUp] =
|
|
19
|
+
solanaHooks.getDisconnectSubscriber(solanaSolflare);
|
|
20
|
+
|
|
21
|
+
const connect = builders
|
|
22
|
+
.connect()
|
|
23
|
+
.action(solanaActions.connect(solanaSolflare))
|
|
24
|
+
.before(changeAccountSubscriber)
|
|
25
|
+
.before(disconnectSubscriber)
|
|
26
|
+
.or(changeAccountCleanup)
|
|
27
|
+
.or(disconnectCleanUp)
|
|
28
|
+
.or(standardizeAndThrowError)
|
|
29
|
+
.build();
|
|
30
|
+
|
|
31
|
+
const disconnect = commonBuilders
|
|
32
|
+
.disconnect<SolanaActions>()
|
|
33
|
+
.and(disconnectCleanUp)
|
|
34
|
+
.after(changeAccountCleanup)
|
|
35
|
+
.build();
|
|
36
|
+
|
|
37
|
+
const canEagerConnect = new ActionBuilder<SolanaActions, 'canEagerConnect'>(
|
|
38
|
+
'canEagerConnect'
|
|
39
|
+
)
|
|
40
|
+
.action(solanaActions.canEagerConnect(solanaSolflare))
|
|
41
|
+
.build();
|
|
42
|
+
|
|
43
|
+
const solana = new NamespaceBuilder<SolanaActions>('Solana', WALLET_ID)
|
|
44
|
+
.action(connect)
|
|
45
|
+
.action(disconnect)
|
|
46
|
+
.action(canEagerConnect)
|
|
47
|
+
.build();
|
|
48
|
+
|
|
49
|
+
export { solana };
|
package/src/provider.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ProviderBuilder } from '@rango-dev/wallets-core';
|
|
2
|
+
|
|
3
|
+
import { metadata, SOLFLARE_INJECTION_DELAY, WALLET_ID } from './constants.js';
|
|
4
|
+
import { solana } from './namespaces/solana.js';
|
|
5
|
+
import { solflare } from './utils.js';
|
|
6
|
+
|
|
7
|
+
const buildProvider = () =>
|
|
8
|
+
new ProviderBuilder(WALLET_ID)
|
|
9
|
+
.init(function (context) {
|
|
10
|
+
const [, setState] = context.state();
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
if (solflare()) {
|
|
13
|
+
setState('installed', true);
|
|
14
|
+
console.debug('[solflare] instance detected.', context);
|
|
15
|
+
}
|
|
16
|
+
}, SOLFLARE_INJECTION_DELAY);
|
|
17
|
+
})
|
|
18
|
+
.config('metadata', metadata)
|
|
19
|
+
.add('solana', solana)
|
|
20
|
+
.build();
|
|
21
|
+
|
|
22
|
+
export { buildProvider };
|
package/src/signer.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Provider } from './types.js';
|
|
2
|
+
import type { SignerFactory } from 'rango-types';
|
|
3
|
+
|
|
4
|
+
import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
|
|
5
|
+
import { getNetworkInstance } from '@rango-dev/wallets-shared';
|
|
6
|
+
import { DefaultSignerFactory, TransactionType as TxType } from 'rango-types';
|
|
7
|
+
|
|
8
|
+
import { SolflareSolanaSiger } from './signers/solana.js';
|
|
9
|
+
|
|
10
|
+
export default async function getSigners(
|
|
11
|
+
provider: Provider
|
|
12
|
+
): Promise<SignerFactory> {
|
|
13
|
+
const signers = new DefaultSignerFactory();
|
|
14
|
+
const solProvider = getNetworkInstance(provider, LegacyNetworks.SOLANA);
|
|
15
|
+
|
|
16
|
+
signers.registerSigner(TxType.SOLANA, new SolflareSolanaSiger(solProvider));
|
|
17
|
+
return signers;
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DefaultSolanaSigner,
|
|
3
|
+
type SolanaExternalProvider,
|
|
4
|
+
} from '@rango-dev/signer-solana';
|
|
5
|
+
import base58 from 'bs58';
|
|
6
|
+
|
|
7
|
+
export class SolflareSolanaSiger extends DefaultSolanaSigner {
|
|
8
|
+
constructor(provider: SolanaExternalProvider) {
|
|
9
|
+
super(provider);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async signMessage(msg: string): Promise<string> {
|
|
13
|
+
const encoder = new TextEncoder();
|
|
14
|
+
const messageBytes = encoder.encode(msg);
|
|
15
|
+
// Used any instead of Solflare because there is an issue in type of `signTransaction` method of Solflare
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
const messageSignature = await (this.provider as any).signMessage(
|
|
18
|
+
messageBytes,
|
|
19
|
+
'utf8'
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return base58.encode(messageSignature.signature);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
|
|
2
|
+
import type { ProviderAPI as SolanaProviderApi } from '@rango-dev/wallets-core/namespaces/solana';
|
|
3
|
+
|
|
4
|
+
export type ProviderObject = {
|
|
5
|
+
[LegacyNetworks.SOLANA]: SolanaProviderApi;
|
|
6
|
+
};
|
|
7
|
+
export type Provider = Map<
|
|
8
|
+
keyof ProviderObject,
|
|
9
|
+
ProviderObject[keyof ProviderObject]
|
|
10
|
+
>;
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Provider } from './types.js';
|
|
2
|
+
import type { ProviderAPI as SolanaProviderApi } from '@rango-dev/wallets-core/namespaces/solana';
|
|
3
|
+
|
|
4
|
+
import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
|
|
5
|
+
|
|
6
|
+
export function solflare(): Provider | null {
|
|
7
|
+
const instances: Provider = new Map();
|
|
8
|
+
const { solflare } = window;
|
|
9
|
+
if (!solflare) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
instances.set(LegacyNetworks.SOLANA, solflare);
|
|
14
|
+
|
|
15
|
+
return instances;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getInstanceOrThrow(): Provider {
|
|
19
|
+
const instances = solflare();
|
|
20
|
+
|
|
21
|
+
if (!instances) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
'Solflare Wallet is not injected. Please check your wallet.'
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return instances;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function solanaSolflare(): SolanaProviderApi {
|
|
31
|
+
const instance = solflare();
|
|
32
|
+
const solanaInstance = instance?.get(LegacyNetworks.SOLANA);
|
|
33
|
+
|
|
34
|
+
if (!solanaInstance) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
'Solflare Wallet not injected or Solana not enabled. Please check your wallet.'
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return solanaInstance;
|
|
41
|
+
}
|