@pollar/solana-wallet-standard-adapter 0.0.0-stage → 0.11.5
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +102 -2
- package/dist/index.d.mts +78 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +115 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,103 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pollar/solana-wallet-standard-adapter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Connect user-controlled Solana wallets (Phantom, Solflare, Backpack, ...) to
|
|
4
|
+
`@pollar/core` through the [Wallet Standard](https://github.com/wallet-standard/wallet-standard),
|
|
5
|
+
the headless substrate that `@solana/wallet-adapter` is built on. No wallet SDK is
|
|
6
|
+
bundled into `@pollar/core`.
|
|
7
|
+
|
|
8
|
+
This is the Solana counterpart to `@pollar/stellar-wallets-kit-adapter`. Login uses
|
|
9
|
+
**SIWS (Sign In With Solana)** via the wallet's native `solana:signIn` feature -
|
|
10
|
+
the Solana analogue of Stellar's SEP-10 challenge.
|
|
11
|
+
|
|
12
|
+
## Solana
|
|
13
|
+
|
|
14
|
+
Pollar runs on Solana end to end for wallets and payments:
|
|
15
|
+
|
|
16
|
+
- **Sign in** with Phantom, Solflare or Backpack (Sign In With Solana, via `@pollar/solana-wallet-standard-adapter`), or
|
|
17
|
+
with email / Google / GitHub to get a **Pollar-managed Solana wallet**, with no seed phrase.
|
|
18
|
+
- **Turnkey co-signed wallets** (mainnet): every signature is a 2-of-2 vote between the user's device and Pollar, and the
|
|
19
|
+
device verifies the transaction, including Solana CCTP burns, before it votes.
|
|
20
|
+
- **Hold, send and receive SOL and SPL tokens** with `sendPayment()` and the drop-in React modals, with **app-sponsored
|
|
21
|
+
fees** and token accounts created for the recipient.
|
|
22
|
+
- **Fiat on/off-ramps to Solana**: Bolivia (BOB, via Stereum + CCTP) and Brazil (BRL via Pix, PagFinance).
|
|
23
|
+
|
|
24
|
+
> **0.11.5** is the adapter's first release on npm, on the SDK's version line. It
|
|
25
|
+
> requires `@pollar/core@^0.11.2`; no adapter changes since 0.11.2.
|
|
26
|
+
>
|
|
27
|
+
> **0.11.2** requires `@pollar/core@^0.11.2` (peer range bump only; no adapter
|
|
28
|
+
> changes).
|
|
29
|
+
>
|
|
30
|
+
> **0.11.1** introduced the adapter. It declares
|
|
31
|
+
> `chain: 'SOLANA'`, which is what routes `login({ provider })` through the SIWS
|
|
32
|
+
> flow instead of Stellar's SEP-10 challenge - end to end, discovery through
|
|
33
|
+
> login.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install @pollar/solana-wallet-standard-adapter @pollar/core
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`@pollar/core` is the only peer dependency. The `@wallet-standard/*` packages and
|
|
42
|
+
`@solana/wallet-standard-features` are real dependencies of this adapter, so you
|
|
43
|
+
do not install them yourself.
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { PollarClient } from '@pollar/core';
|
|
49
|
+
import { solanaWalletStandardAdapters } from '@pollar/solana-wallet-standard-adapter';
|
|
50
|
+
|
|
51
|
+
const client = new PollarClient({
|
|
52
|
+
apiKey: '...',
|
|
53
|
+
walletAdapters: [...solanaWalletStandardAdapters()],
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`solanaWalletStandardAdapters()` discovers every installed Solana wallet and returns one
|
|
58
|
+
adapter each. It is SSR-safe (returns `[]` when `window` is undefined), so build
|
|
59
|
+
the `PollarClient` on the client.
|
|
60
|
+
|
|
61
|
+
### Alongside Stellar wallets
|
|
62
|
+
|
|
63
|
+
`walletAdapters` is one flat list, so Stellar and Solana wallets coexist in it.
|
|
64
|
+
That needs two packages the install command above does not cover -
|
|
65
|
+
`@pollar/stellar-wallets-kit-adapter` and its own peer
|
|
66
|
+
`@creit.tech/stellar-wallets-kit`:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm install @pollar/stellar-wallets-kit-adapter @creit.tech/stellar-wallets-kit
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { PollarClient } from '@pollar/core';
|
|
74
|
+
import { solanaWalletStandardAdapters } from '@pollar/solana-wallet-standard-adapter';
|
|
75
|
+
import { stellarWalletsKitAdapters } from '@pollar/stellar-wallets-kit-adapter';
|
|
76
|
+
import { Networks } from '@creit.tech/stellar-wallets-kit';
|
|
77
|
+
|
|
78
|
+
const client = new PollarClient({
|
|
79
|
+
apiKey: '...',
|
|
80
|
+
walletAdapters: [...stellarWalletsKitAdapters({ network: Networks.PUBLIC }), ...solanaWalletStandardAdapters()],
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Options
|
|
85
|
+
|
|
86
|
+
- `wallets?: string[]` - include only these wallet names (default: all found).
|
|
87
|
+
- `labels?: Record<string, string>` - per-wallet button-label overrides.
|
|
88
|
+
- `groupLabel?: string` - the login-UI gateway label these wallets share
|
|
89
|
+
(default `'Solana Wallet'`).
|
|
90
|
+
|
|
91
|
+
### `SolanaWalletStandardAdapter`
|
|
92
|
+
|
|
93
|
+
The class behind the factory, exported for direct use outside `PollarClient`.
|
|
94
|
+
Beyond the shared `WalletAdapter` contract it carries the Solana-specific
|
|
95
|
+
surface:
|
|
96
|
+
|
|
97
|
+
| Member | Purpose |
|
|
98
|
+
| --------------------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
99
|
+
| `chain` | Always `'SOLANA'` - what routes login through SIWS |
|
|
100
|
+
| `supportsSignIn` | Whether the wallet exposes the native `solana:signIn` feature |
|
|
101
|
+
| `signIn(input)` | SIWS login; throws if the wallet lacks `solana:signIn` (check `supportsSignIn` first, then use `signMessage`) |
|
|
102
|
+
| `signMessage(message)` | Raw message signing |
|
|
103
|
+
| `signSolanaTransaction(tx)` | Signs a Solana transaction (sponsored external transfers) |
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { WalletAdapter, WalletId, WalletAdapterMeta, WalletChain, ConnectWalletResponse, SolanaSignInInput, SolanaSignInOutput, SolanaSignMessageResponse } from '@pollar/core';
|
|
2
|
+
import { Wallet } from '@wallet-standard/base';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a Wallet Standard Solana wallet (Phantom, Solflare, Backpack, ...) so it can
|
|
6
|
+
* back a Pollar external-wallet login. The Wallet Standard is the headless
|
|
7
|
+
* substrate `@solana/wallet-adapter` is built on, so this stays framework-agnostic
|
|
8
|
+
* exactly like `@pollar/stellar-wallets-kit-adapter`.
|
|
9
|
+
*
|
|
10
|
+
* The signing surface is Solana-native, NOT the Stellar `WalletAdapter` shape:
|
|
11
|
+
* login is SIWS (`signIn`, a signed MESSAGE) rather than SEP-10 (a signed
|
|
12
|
+
* transaction), and transactions are serialized Solana messages, not XDR. Once
|
|
13
|
+
* `@pollar/core` grows a chain-aware adapter contract (see the design doc) this
|
|
14
|
+
* slots into `PollarClientConfig.walletAdapters`.
|
|
15
|
+
*/
|
|
16
|
+
declare class SolanaWalletStandardAdapter implements WalletAdapter {
|
|
17
|
+
readonly type: WalletId;
|
|
18
|
+
readonly meta: WalletAdapterMeta;
|
|
19
|
+
readonly custody: "external";
|
|
20
|
+
readonly chain: WalletChain;
|
|
21
|
+
private readonly _wallet;
|
|
22
|
+
private _account;
|
|
23
|
+
constructor(wallet: Wallet, walletId: WalletId, meta: WalletAdapterMeta);
|
|
24
|
+
isAvailable(): Promise<boolean>;
|
|
25
|
+
connect(): Promise<ConnectWalletResponse>;
|
|
26
|
+
disconnect(): Promise<void>;
|
|
27
|
+
getPublicKey(): Promise<string | null>;
|
|
28
|
+
/** Does this wallet expose native SIWS (`solana:signIn`)? If not, use `signMessage`. */
|
|
29
|
+
get supportsSignIn(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* SIWS: sign the server-issued Sign In With Solana input. This is the Solana
|
|
32
|
+
* analogue of the Stellar SEP-10 challenge, but the wallet signs a structured
|
|
33
|
+
* MESSAGE (domain, statement, nonce, ...) rather than a transaction.
|
|
34
|
+
*/
|
|
35
|
+
signIn(input: SolanaSignInInput): Promise<SolanaSignInOutput>;
|
|
36
|
+
/** Raw message signing - the SIWS fallback for wallets without `solana:signIn`. */
|
|
37
|
+
signMessage(message: Uint8Array): Promise<SolanaSignMessageResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Sign a serialized Solana transaction. Used by phase 2 (sponsored external
|
|
40
|
+
* transfers), where Pollar builds a durable-nonce transfer whose fee payer is
|
|
41
|
+
* the app GAS wallet and the user signs their part here.
|
|
42
|
+
*/
|
|
43
|
+
signSolanaTransaction(transaction: Uint8Array, chain?: string): Promise<Uint8Array>;
|
|
44
|
+
private _requireAccount;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface SolanaWalletStandardAdapterOptions {
|
|
48
|
+
/** Subset of wallet names to include. Defaults to every Solana wallet found. */
|
|
49
|
+
wallets?: string[];
|
|
50
|
+
/** Per-wallet button-label overrides, keyed by the wallet's `name`. */
|
|
51
|
+
labels?: Record<string, string>;
|
|
52
|
+
/**
|
|
53
|
+
* Gateway button label these wallets collapse behind in the login UI (applied
|
|
54
|
+
* as each adapter's `meta.group`). Default `'Solana Wallet'` - a distinct group
|
|
55
|
+
* from the Stellar `'Wallet'` gateway, so the two chains render as separate
|
|
56
|
+
* login buttons.
|
|
57
|
+
*/
|
|
58
|
+
groupLabel?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Build one {@link SolanaWalletStandardAdapter} per installed Solana wallet discovered
|
|
62
|
+
* through the Wallet Standard registry, to pass to
|
|
63
|
+
* `PollarClientConfig.walletAdapters` (once `@pollar/core` is chain-aware - see the
|
|
64
|
+
* design doc).
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { solanaWalletStandardAdapters } from '@pollar/solana-wallet-standard-adapter';
|
|
69
|
+
*
|
|
70
|
+
* const client = new PollarClient({
|
|
71
|
+
* apiKey: '...',
|
|
72
|
+
* walletAdapters: [...stellarWalletsKitAdapters({ network }), ...solanaWalletStandardAdapters()],
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
declare function solanaWalletStandardAdapters(options?: SolanaWalletStandardAdapterOptions): SolanaWalletStandardAdapter[];
|
|
77
|
+
|
|
78
|
+
export { SolanaWalletStandardAdapter, type SolanaWalletStandardAdapterOptions, solanaWalletStandardAdapters };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { WalletAdapter, WalletId, WalletAdapterMeta, WalletChain, ConnectWalletResponse, SolanaSignInInput, SolanaSignInOutput, SolanaSignMessageResponse } from '@pollar/core';
|
|
2
|
+
import { Wallet } from '@wallet-standard/base';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a Wallet Standard Solana wallet (Phantom, Solflare, Backpack, ...) so it can
|
|
6
|
+
* back a Pollar external-wallet login. The Wallet Standard is the headless
|
|
7
|
+
* substrate `@solana/wallet-adapter` is built on, so this stays framework-agnostic
|
|
8
|
+
* exactly like `@pollar/stellar-wallets-kit-adapter`.
|
|
9
|
+
*
|
|
10
|
+
* The signing surface is Solana-native, NOT the Stellar `WalletAdapter` shape:
|
|
11
|
+
* login is SIWS (`signIn`, a signed MESSAGE) rather than SEP-10 (a signed
|
|
12
|
+
* transaction), and transactions are serialized Solana messages, not XDR. Once
|
|
13
|
+
* `@pollar/core` grows a chain-aware adapter contract (see the design doc) this
|
|
14
|
+
* slots into `PollarClientConfig.walletAdapters`.
|
|
15
|
+
*/
|
|
16
|
+
declare class SolanaWalletStandardAdapter implements WalletAdapter {
|
|
17
|
+
readonly type: WalletId;
|
|
18
|
+
readonly meta: WalletAdapterMeta;
|
|
19
|
+
readonly custody: "external";
|
|
20
|
+
readonly chain: WalletChain;
|
|
21
|
+
private readonly _wallet;
|
|
22
|
+
private _account;
|
|
23
|
+
constructor(wallet: Wallet, walletId: WalletId, meta: WalletAdapterMeta);
|
|
24
|
+
isAvailable(): Promise<boolean>;
|
|
25
|
+
connect(): Promise<ConnectWalletResponse>;
|
|
26
|
+
disconnect(): Promise<void>;
|
|
27
|
+
getPublicKey(): Promise<string | null>;
|
|
28
|
+
/** Does this wallet expose native SIWS (`solana:signIn`)? If not, use `signMessage`. */
|
|
29
|
+
get supportsSignIn(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* SIWS: sign the server-issued Sign In With Solana input. This is the Solana
|
|
32
|
+
* analogue of the Stellar SEP-10 challenge, but the wallet signs a structured
|
|
33
|
+
* MESSAGE (domain, statement, nonce, ...) rather than a transaction.
|
|
34
|
+
*/
|
|
35
|
+
signIn(input: SolanaSignInInput): Promise<SolanaSignInOutput>;
|
|
36
|
+
/** Raw message signing - the SIWS fallback for wallets without `solana:signIn`. */
|
|
37
|
+
signMessage(message: Uint8Array): Promise<SolanaSignMessageResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Sign a serialized Solana transaction. Used by phase 2 (sponsored external
|
|
40
|
+
* transfers), where Pollar builds a durable-nonce transfer whose fee payer is
|
|
41
|
+
* the app GAS wallet and the user signs their part here.
|
|
42
|
+
*/
|
|
43
|
+
signSolanaTransaction(transaction: Uint8Array, chain?: string): Promise<Uint8Array>;
|
|
44
|
+
private _requireAccount;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface SolanaWalletStandardAdapterOptions {
|
|
48
|
+
/** Subset of wallet names to include. Defaults to every Solana wallet found. */
|
|
49
|
+
wallets?: string[];
|
|
50
|
+
/** Per-wallet button-label overrides, keyed by the wallet's `name`. */
|
|
51
|
+
labels?: Record<string, string>;
|
|
52
|
+
/**
|
|
53
|
+
* Gateway button label these wallets collapse behind in the login UI (applied
|
|
54
|
+
* as each adapter's `meta.group`). Default `'Solana Wallet'` - a distinct group
|
|
55
|
+
* from the Stellar `'Wallet'` gateway, so the two chains render as separate
|
|
56
|
+
* login buttons.
|
|
57
|
+
*/
|
|
58
|
+
groupLabel?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Build one {@link SolanaWalletStandardAdapter} per installed Solana wallet discovered
|
|
62
|
+
* through the Wallet Standard registry, to pass to
|
|
63
|
+
* `PollarClientConfig.walletAdapters` (once `@pollar/core` is chain-aware - see the
|
|
64
|
+
* design doc).
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { solanaWalletStandardAdapters } from '@pollar/solana-wallet-standard-adapter';
|
|
69
|
+
*
|
|
70
|
+
* const client = new PollarClient({
|
|
71
|
+
* apiKey: '...',
|
|
72
|
+
* walletAdapters: [...stellarWalletsKitAdapters({ network }), ...solanaWalletStandardAdapters()],
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
declare function solanaWalletStandardAdapters(options?: SolanaWalletStandardAdapterOptions): SolanaWalletStandardAdapter[];
|
|
77
|
+
|
|
78
|
+
export { SolanaWalletStandardAdapter, type SolanaWalletStandardAdapterOptions, solanaWalletStandardAdapters };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var walletStandardFeatures = require('@solana/wallet-standard-features');
|
|
4
|
+
var features = require('@wallet-standard/features');
|
|
5
|
+
var app = require('@wallet-standard/app');
|
|
6
|
+
|
|
7
|
+
// src/SolanaWalletStandardAdapter.ts
|
|
8
|
+
function isSolanaChain(chain) {
|
|
9
|
+
return chain.startsWith("solana:");
|
|
10
|
+
}
|
|
11
|
+
var SolanaWalletStandardAdapter = class {
|
|
12
|
+
constructor(wallet, walletId, meta) {
|
|
13
|
+
this.custody = "external";
|
|
14
|
+
this.chain = "SOLANA";
|
|
15
|
+
this._account = null;
|
|
16
|
+
this._wallet = wallet;
|
|
17
|
+
this.type = walletId;
|
|
18
|
+
this.meta = meta;
|
|
19
|
+
}
|
|
20
|
+
async isAvailable() {
|
|
21
|
+
return features.StandardConnect in this._wallet.features && this._wallet.chains.some(isSolanaChain);
|
|
22
|
+
}
|
|
23
|
+
async connect() {
|
|
24
|
+
const feature = this._wallet.features[features.StandardConnect];
|
|
25
|
+
if (!feature) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" does not support standard:connect`);
|
|
26
|
+
const { accounts } = await feature.connect();
|
|
27
|
+
const account = accounts.find((a) => a.chains.some(isSolanaChain)) ?? accounts[0];
|
|
28
|
+
if (!account) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" returned no account on connect`);
|
|
29
|
+
this._account = account;
|
|
30
|
+
return { address: account.address };
|
|
31
|
+
}
|
|
32
|
+
async disconnect() {
|
|
33
|
+
try {
|
|
34
|
+
const feature = this._wallet.features[features.StandardDisconnect];
|
|
35
|
+
await feature?.disconnect();
|
|
36
|
+
} finally {
|
|
37
|
+
this._account = null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async getPublicKey() {
|
|
41
|
+
if (this._account) return this._account.address;
|
|
42
|
+
this._account = this._wallet.accounts.find((a) => a.chains.some(isSolanaChain)) ?? null;
|
|
43
|
+
return this._account?.address ?? null;
|
|
44
|
+
}
|
|
45
|
+
/** Does this wallet expose native SIWS (`solana:signIn`)? If not, use `signMessage`. */
|
|
46
|
+
get supportsSignIn() {
|
|
47
|
+
return walletStandardFeatures.SolanaSignIn in this._wallet.features;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* SIWS: sign the server-issued Sign In With Solana input. This is the Solana
|
|
51
|
+
* analogue of the Stellar SEP-10 challenge, but the wallet signs a structured
|
|
52
|
+
* MESSAGE (domain, statement, nonce, ...) rather than a transaction.
|
|
53
|
+
*/
|
|
54
|
+
async signIn(input) {
|
|
55
|
+
const feature = this._wallet.features[walletStandardFeatures.SolanaSignIn];
|
|
56
|
+
if (!feature) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" does not support solana:signIn (SIWS)`);
|
|
57
|
+
const [output] = await feature.signIn(input);
|
|
58
|
+
if (!output) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" returned no SIWS output`);
|
|
59
|
+
this._account = output.account;
|
|
60
|
+
return {
|
|
61
|
+
account: { address: output.account.address, publicKey: Uint8Array.from(output.account.publicKey) },
|
|
62
|
+
signedMessage: Uint8Array.from(output.signedMessage),
|
|
63
|
+
signature: Uint8Array.from(output.signature),
|
|
64
|
+
...output.signatureType ? { signatureType: output.signatureType } : {}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Raw message signing - the SIWS fallback for wallets without `solana:signIn`. */
|
|
68
|
+
async signMessage(message) {
|
|
69
|
+
const account = this._requireAccount();
|
|
70
|
+
const feature = this._wallet.features[walletStandardFeatures.SolanaSignMessage];
|
|
71
|
+
if (!feature) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" does not support solana:signMessage`);
|
|
72
|
+
const [output] = await feature.signMessage({ account, message });
|
|
73
|
+
if (!output) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" returned no signature`);
|
|
74
|
+
return { signature: Uint8Array.from(output.signature), signedMessage: Uint8Array.from(output.signedMessage) };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Sign a serialized Solana transaction. Used by phase 2 (sponsored external
|
|
78
|
+
* transfers), where Pollar builds a durable-nonce transfer whose fee payer is
|
|
79
|
+
* the app GAS wallet and the user signs their part here.
|
|
80
|
+
*/
|
|
81
|
+
async signSolanaTransaction(transaction, chain) {
|
|
82
|
+
const account = this._requireAccount();
|
|
83
|
+
const feature = this._wallet.features[walletStandardFeatures.SolanaSignTransaction];
|
|
84
|
+
if (!feature) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" does not support solana:signTransaction`);
|
|
85
|
+
const solanaChain = chain && chain.startsWith("solana:") ? chain : void 0;
|
|
86
|
+
const [output] = await feature.signTransaction({ account, transaction, ...solanaChain ? { chain: solanaChain } : {} });
|
|
87
|
+
if (!output) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" returned no signed transaction`);
|
|
88
|
+
return Uint8Array.from(output.signedTransaction);
|
|
89
|
+
}
|
|
90
|
+
_requireAccount() {
|
|
91
|
+
if (!this._account) {
|
|
92
|
+
throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" is not connected \u2014 call connect() first`);
|
|
93
|
+
}
|
|
94
|
+
return this._account;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function isSolanaWallet(w) {
|
|
98
|
+
return features.StandardConnect in w.features && w.chains.some((c) => c.startsWith("solana:"));
|
|
99
|
+
}
|
|
100
|
+
function solanaWalletStandardAdapters(options = {}) {
|
|
101
|
+
if (typeof window === "undefined") return [];
|
|
102
|
+
const wanted = options.wallets;
|
|
103
|
+
const group = options.groupLabel ?? "Solana Wallet";
|
|
104
|
+
return app.getWallets().get().filter(isSolanaWallet).filter((w) => !wanted || wanted.includes(w.name)).map((w) => {
|
|
105
|
+
const meta = {
|
|
106
|
+
label: options.labels?.[w.name] ?? w.name,
|
|
107
|
+
iconUrl: w.icon,
|
|
108
|
+
group
|
|
109
|
+
};
|
|
110
|
+
const id = `solana:${w.name}`;
|
|
111
|
+
return new SolanaWalletStandardAdapter(w, id, meta);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
exports.SolanaWalletStandardAdapter = SolanaWalletStandardAdapter;
|
|
116
|
+
exports.solanaWalletStandardAdapters = solanaWalletStandardAdapters;
|
|
117
|
+
//# sourceMappingURL=index.js.map
|
|
118
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/SolanaWalletStandardAdapter.ts","../src/factory.ts"],"names":["StandardConnect","StandardDisconnect","SolanaSignIn","SolanaSignMessage","SolanaSignTransaction","getWallets"],"mappings":";;;;;;;AA6BA,SAAS,cAAc,KAAA,EAAwB;AAC7C,EAAA,OAAO,KAAA,CAAM,WAAW,SAAS,CAAA;AACnC;AAcO,IAAM,8BAAN,MAA2D;AAAA,EAShE,WAAA,CAAY,MAAA,EAAgB,QAAA,EAAoB,IAAA,EAAyB;AANzE,IAAA,IAAA,CAAS,OAAA,GAAU,UAAA;AACnB,IAAA,IAAA,CAAS,KAAA,GAAqB,QAAA;AAG9B,IAAA,IAAA,CAAQ,QAAA,GAAiC,IAAA;AAGvC,IAAA,IAAA,CAAK,OAAA,GAAU,MAAA;AACf,IAAA,IAAA,CAAK,IAAA,GAAO,QAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA,EAEA,MAAM,WAAA,GAAgC;AAIpC,IAAA,OAAOA,wBAAA,IAAmB,KAAK,OAAA,CAAQ,QAAA,IAAY,KAAK,OAAA,CAAQ,MAAA,CAAO,KAAK,aAAa,CAAA;AAAA,EAC3F;AAAA,EAEA,MAAM,OAAA,GAA0C;AAC9C,IAAA,MAAM,OAAA,GAAU,IAAA,CAAK,OAAA,CAAQ,QAAA,CAASA,wBAAe,CAAA;AACrD,IAAA,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,CAAA,+BAAA,EAAkC,IAAA,CAAK,IAAI,CAAA,mCAAA,CAAqC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I,CAAA,8CAAA,CAA2C,CAAA;AAAA,IACxG;AACA,IAAA,OAAO,IAAA,CAAK,QAAA;AAAA,EACd;AACF;ACvIA,SAAS,eAAe,CAAA,EAAoB;AAC1C,EAAA,OAAOJ,wBAAAA,IAAmB,CAAA,CAAE,QAAA,IAAY,CAAA,CAAE,MAAA,CAAO,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,UAAA,CAAW,SAAS,CAAC,CAAA;AACtF;AAkBO,SAAS,4BAAA,CAA6B,OAAA,GAA8C,EAAC,EAAkC;AAK5H,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,OAAO,EAAC;AAE3C,EAAA,MAAM,SAAS,OAAA,CAAQ,OAAA;AACvB,EAAA,MAAM,KAAA,GAAQ,QAAQ,UAAA,IAAc,eAAA;AAEpC,EAAA,OAAOK,cAAA,GACJ,GAAA,EAAI,CACJ,OAAO,cAAc,CAAA,CACrB,OAAO,CAAC,CAAA,KAAM,CAAC,MAAA,IAAU,MAAA,CAAO,SAAS,CAAA,CAAE,IAAI,CAAC,CAAA,CAChD,GAAA,CAAI,CAAC,CAAA,KAAM;AACV,IAAA,MAAM,IAAA,GAA0B;AAAA,MAC9B,OAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,CAAE,IAAI,KAAK,CAAA,CAAE,IAAA;AAAA,MACrC,SAAS,CAAA,CAAE,IAAA;AAAA,MACX;AAAA,KACF;AAGA,IAAA,MAAM,EAAA,GAAe,CAAA,OAAA,EAAU,CAAA,CAAE,IAAI,CAAA,CAAA;AACrC,IAAA,OAAO,IAAI,2BAAA,CAA4B,CAAA,EAAG,EAAA,EAAI,IAAI,CAAA;AAAA,EACpD,CAAC,CAAA;AACL","file":"index.js","sourcesContent":["import type {\n ConnectWalletResponse,\n SolanaSignInInput,\n SolanaSignInOutput,\n SolanaSignMessageResponse,\n WalletAdapter,\n WalletAdapterMeta,\n WalletChain,\n WalletId,\n} from '@pollar/core';\nimport {\n SolanaSignIn,\n SolanaSignMessage,\n SolanaSignTransaction,\n type SolanaSignInFeature,\n type SolanaSignMessageFeature,\n type SolanaSignTransactionFeature,\n} from '@solana/wallet-standard-features';\nimport type { Wallet, WalletAccount } from '@wallet-standard/base';\nimport {\n StandardConnect,\n StandardDisconnect,\n type StandardConnectFeature,\n type StandardDisconnectFeature,\n} from '@wallet-standard/features';\n\n/** A Solana chain identifier as used by the Wallet Standard (e.g. `solana:mainnet`). */\ntype SolanaChainId = `solana:${string}`;\n\nfunction isSolanaChain(chain: string): boolean {\n return chain.startsWith('solana:');\n}\n\n/**\n * Wraps a Wallet Standard Solana wallet (Phantom, Solflare, Backpack, ...) so it can\n * back a Pollar external-wallet login. The Wallet Standard is the headless\n * substrate `@solana/wallet-adapter` is built on, so this stays framework-agnostic\n * exactly like `@pollar/stellar-wallets-kit-adapter`.\n *\n * The signing surface is Solana-native, NOT the Stellar `WalletAdapter` shape:\n * login is SIWS (`signIn`, a signed MESSAGE) rather than SEP-10 (a signed\n * transaction), and transactions are serialized Solana messages, not XDR. Once\n * `@pollar/core` grows a chain-aware adapter contract (see the design doc) this\n * slots into `PollarClientConfig.walletAdapters`.\n */\nexport class SolanaWalletStandardAdapter implements WalletAdapter {\n readonly type: WalletId;\n readonly meta: WalletAdapterMeta;\n readonly custody = 'external' as const;\n readonly chain: WalletChain = 'SOLANA';\n\n private readonly _wallet: Wallet;\n private _account: WalletAccount | null = null;\n\n constructor(wallet: Wallet, walletId: WalletId, meta: WalletAdapterMeta) {\n this._wallet = wallet;\n this.type = walletId;\n this.meta = meta;\n }\n\n async isAvailable(): Promise<boolean> {\n // Registered in the Wallet Standard registry with a Solana chain and the\n // standard connect feature. Discovery already filtered to Solana wallets, so\n // this is a cheap re-check rather than a probe.\n return StandardConnect in this._wallet.features && this._wallet.chains.some(isSolanaChain);\n }\n\n async connect(): Promise<ConnectWalletResponse> {\n const feature = this._wallet.features[StandardConnect] as StandardConnectFeature[typeof StandardConnect] | undefined;\n if (!feature) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" does not support standard:connect`);\n const { accounts } = await feature.connect();\n const account = accounts.find((a) => a.chains.some(isSolanaChain)) ?? accounts[0];\n if (!account) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" returned no account on connect`);\n this._account = account;\n return { address: account.address };\n }\n\n async disconnect(): Promise<void> {\n try {\n const feature = this._wallet.features[StandardDisconnect] as\n | StandardDisconnectFeature[typeof StandardDisconnect]\n | undefined;\n await feature?.disconnect();\n } finally {\n this._account = null;\n }\n }\n\n async getPublicKey(): Promise<string | null> {\n if (this._account) return this._account.address;\n // A wallet reconnected across a reload exposes its accounts without a fresh\n // connect(); adopt the first Solana one so getPublicKey works after resume.\n this._account = this._wallet.accounts.find((a) => a.chains.some(isSolanaChain)) ?? null;\n return this._account?.address ?? null;\n }\n\n /** Does this wallet expose native SIWS (`solana:signIn`)? If not, use `signMessage`. */\n get supportsSignIn(): boolean {\n return SolanaSignIn in this._wallet.features;\n }\n\n /**\n * SIWS: sign the server-issued Sign In With Solana input. This is the Solana\n * analogue of the Stellar SEP-10 challenge, but the wallet signs a structured\n * MESSAGE (domain, statement, nonce, ...) rather than a transaction.\n */\n async signIn(input: SolanaSignInInput): Promise<SolanaSignInOutput> {\n const feature = this._wallet.features[SolanaSignIn] as SolanaSignInFeature[typeof SolanaSignIn] | undefined;\n if (!feature) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" does not support solana:signIn (SIWS)`);\n const [output] = await feature.signIn(input);\n if (!output) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" returned no SIWS output`);\n this._account = output.account;\n // The Wallet Standard hands back readonly byte views; copy into real\n // Uint8Arrays so `@pollar/core` (which base64-encodes them for the server)\n // gets mutable, standard arrays.\n return {\n account: { address: output.account.address, publicKey: Uint8Array.from(output.account.publicKey) },\n signedMessage: Uint8Array.from(output.signedMessage),\n signature: Uint8Array.from(output.signature),\n ...(output.signatureType ? { signatureType: output.signatureType } : {}),\n };\n }\n\n /** Raw message signing - the SIWS fallback for wallets without `solana:signIn`. */\n async signMessage(message: Uint8Array): Promise<SolanaSignMessageResponse> {\n const account = this._requireAccount();\n const feature = this._wallet.features[SolanaSignMessage] as SolanaSignMessageFeature[typeof SolanaSignMessage] | undefined;\n if (!feature) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" does not support solana:signMessage`);\n const [output] = await feature.signMessage({ account, message });\n if (!output) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" returned no signature`);\n return { signature: Uint8Array.from(output.signature), signedMessage: Uint8Array.from(output.signedMessage) };\n }\n\n /**\n * Sign a serialized Solana transaction. Used by phase 2 (sponsored external\n * transfers), where Pollar builds a durable-nonce transfer whose fee payer is\n * the app GAS wallet and the user signs their part here.\n */\n async signSolanaTransaction(transaction: Uint8Array, chain?: string): Promise<Uint8Array> {\n const account = this._requireAccount();\n const feature = this._wallet.features[SolanaSignTransaction] as\n | SolanaSignTransactionFeature[typeof SolanaSignTransaction]\n | undefined;\n if (!feature) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" does not support solana:signTransaction`);\n const solanaChain = chain && chain.startsWith('solana:') ? (chain as SolanaChainId) : undefined;\n const [output] = await feature.signTransaction({ account, transaction, ...(solanaChain ? { chain: solanaChain } : {}) });\n if (!output) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" returned no signed transaction`);\n return Uint8Array.from(output.signedTransaction);\n }\n\n private _requireAccount(): WalletAccount {\n if (!this._account) {\n throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" is not connected — call connect() first`);\n }\n return this._account;\n }\n}\n","import type { WalletAdapterMeta, WalletId } from '@pollar/core';\nimport { getWallets } from '@wallet-standard/app';\nimport type { Wallet } from '@wallet-standard/base';\nimport { StandardConnect } from '@wallet-standard/features';\nimport { SolanaWalletStandardAdapter } from './SolanaWalletStandardAdapter';\n\nexport interface SolanaWalletStandardAdapterOptions {\n /** Subset of wallet names to include. Defaults to every Solana wallet found. */\n wallets?: string[];\n /** Per-wallet button-label overrides, keyed by the wallet's `name`. */\n labels?: Record<string, string>;\n /**\n * Gateway button label these wallets collapse behind in the login UI (applied\n * as each adapter's `meta.group`). Default `'Solana Wallet'` - a distinct group\n * from the Stellar `'Wallet'` gateway, so the two chains render as separate\n * login buttons.\n */\n groupLabel?: string;\n}\n\n/** A wallet is usable here if it advertises a Solana chain and standard connect. */\nfunction isSolanaWallet(w: Wallet): boolean {\n return StandardConnect in w.features && w.chains.some((c) => c.startsWith('solana:'));\n}\n\n/**\n * Build one {@link SolanaWalletStandardAdapter} per installed Solana wallet discovered\n * through the Wallet Standard registry, to pass to\n * `PollarClientConfig.walletAdapters` (once `@pollar/core` is chain-aware - see the\n * design doc).\n *\n * @example\n * ```ts\n * import { solanaWalletStandardAdapters } from '@pollar/solana-wallet-standard-adapter';\n *\n * const client = new PollarClient({\n * apiKey: '...',\n * walletAdapters: [...stellarWalletsKitAdapters({ network }), ...solanaWalletStandardAdapters()],\n * });\n * ```\n */\nexport function solanaWalletStandardAdapters(options: SolanaWalletStandardAdapterOptions = {}): SolanaWalletStandardAdapter[] {\n // SSR guard: wallet extensions register into a browser-global registry, so\n // there is nothing to find server-side. Return [] and let this re-run on the\n // client (build the PollarClient client-side, e.g. behind a mounted flag or\n // `dynamic(..., { ssr: false })`). Mirrors the Stellar adapter factory.\n if (typeof window === 'undefined') return [];\n\n const wanted = options.wallets;\n const group = options.groupLabel ?? 'Solana Wallet';\n\n return getWallets()\n .get()\n .filter(isSolanaWallet)\n .filter((w) => !wanted || wanted.includes(w.name))\n .map((w) => {\n const meta: WalletAdapterMeta = {\n label: options.labels?.[w.name] ?? w.name,\n iconUrl: w.icon,\n group,\n };\n // Namespace the id so a Solana wallet never collides with a Stellar adapter\n // of the same brand name in the shared adapter registry.\n const id: WalletId = `solana:${w.name}`;\n return new SolanaWalletStandardAdapter(w, id, meta);\n });\n}\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { SolanaSignIn, SolanaSignMessage, SolanaSignTransaction } from '@solana/wallet-standard-features';
|
|
2
|
+
import { StandardConnect, StandardDisconnect } from '@wallet-standard/features';
|
|
3
|
+
import { getWallets } from '@wallet-standard/app';
|
|
4
|
+
|
|
5
|
+
// src/SolanaWalletStandardAdapter.ts
|
|
6
|
+
function isSolanaChain(chain) {
|
|
7
|
+
return chain.startsWith("solana:");
|
|
8
|
+
}
|
|
9
|
+
var SolanaWalletStandardAdapter = class {
|
|
10
|
+
constructor(wallet, walletId, meta) {
|
|
11
|
+
this.custody = "external";
|
|
12
|
+
this.chain = "SOLANA";
|
|
13
|
+
this._account = null;
|
|
14
|
+
this._wallet = wallet;
|
|
15
|
+
this.type = walletId;
|
|
16
|
+
this.meta = meta;
|
|
17
|
+
}
|
|
18
|
+
async isAvailable() {
|
|
19
|
+
return StandardConnect in this._wallet.features && this._wallet.chains.some(isSolanaChain);
|
|
20
|
+
}
|
|
21
|
+
async connect() {
|
|
22
|
+
const feature = this._wallet.features[StandardConnect];
|
|
23
|
+
if (!feature) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" does not support standard:connect`);
|
|
24
|
+
const { accounts } = await feature.connect();
|
|
25
|
+
const account = accounts.find((a) => a.chains.some(isSolanaChain)) ?? accounts[0];
|
|
26
|
+
if (!account) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" returned no account on connect`);
|
|
27
|
+
this._account = account;
|
|
28
|
+
return { address: account.address };
|
|
29
|
+
}
|
|
30
|
+
async disconnect() {
|
|
31
|
+
try {
|
|
32
|
+
const feature = this._wallet.features[StandardDisconnect];
|
|
33
|
+
await feature?.disconnect();
|
|
34
|
+
} finally {
|
|
35
|
+
this._account = null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async getPublicKey() {
|
|
39
|
+
if (this._account) return this._account.address;
|
|
40
|
+
this._account = this._wallet.accounts.find((a) => a.chains.some(isSolanaChain)) ?? null;
|
|
41
|
+
return this._account?.address ?? null;
|
|
42
|
+
}
|
|
43
|
+
/** Does this wallet expose native SIWS (`solana:signIn`)? If not, use `signMessage`. */
|
|
44
|
+
get supportsSignIn() {
|
|
45
|
+
return SolanaSignIn in this._wallet.features;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* SIWS: sign the server-issued Sign In With Solana input. This is the Solana
|
|
49
|
+
* analogue of the Stellar SEP-10 challenge, but the wallet signs a structured
|
|
50
|
+
* MESSAGE (domain, statement, nonce, ...) rather than a transaction.
|
|
51
|
+
*/
|
|
52
|
+
async signIn(input) {
|
|
53
|
+
const feature = this._wallet.features[SolanaSignIn];
|
|
54
|
+
if (!feature) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" does not support solana:signIn (SIWS)`);
|
|
55
|
+
const [output] = await feature.signIn(input);
|
|
56
|
+
if (!output) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" returned no SIWS output`);
|
|
57
|
+
this._account = output.account;
|
|
58
|
+
return {
|
|
59
|
+
account: { address: output.account.address, publicKey: Uint8Array.from(output.account.publicKey) },
|
|
60
|
+
signedMessage: Uint8Array.from(output.signedMessage),
|
|
61
|
+
signature: Uint8Array.from(output.signature),
|
|
62
|
+
...output.signatureType ? { signatureType: output.signatureType } : {}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Raw message signing - the SIWS fallback for wallets without `solana:signIn`. */
|
|
66
|
+
async signMessage(message) {
|
|
67
|
+
const account = this._requireAccount();
|
|
68
|
+
const feature = this._wallet.features[SolanaSignMessage];
|
|
69
|
+
if (!feature) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" does not support solana:signMessage`);
|
|
70
|
+
const [output] = await feature.signMessage({ account, message });
|
|
71
|
+
if (!output) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" returned no signature`);
|
|
72
|
+
return { signature: Uint8Array.from(output.signature), signedMessage: Uint8Array.from(output.signedMessage) };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Sign a serialized Solana transaction. Used by phase 2 (sponsored external
|
|
76
|
+
* transfers), where Pollar builds a durable-nonce transfer whose fee payer is
|
|
77
|
+
* the app GAS wallet and the user signs their part here.
|
|
78
|
+
*/
|
|
79
|
+
async signSolanaTransaction(transaction, chain) {
|
|
80
|
+
const account = this._requireAccount();
|
|
81
|
+
const feature = this._wallet.features[SolanaSignTransaction];
|
|
82
|
+
if (!feature) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" does not support solana:signTransaction`);
|
|
83
|
+
const solanaChain = chain && chain.startsWith("solana:") ? chain : void 0;
|
|
84
|
+
const [output] = await feature.signTransaction({ account, transaction, ...solanaChain ? { chain: solanaChain } : {} });
|
|
85
|
+
if (!output) throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" returned no signed transaction`);
|
|
86
|
+
return Uint8Array.from(output.signedTransaction);
|
|
87
|
+
}
|
|
88
|
+
_requireAccount() {
|
|
89
|
+
if (!this._account) {
|
|
90
|
+
throw new Error(`[SolanaWalletStandardAdapter] "${this.type}" is not connected \u2014 call connect() first`);
|
|
91
|
+
}
|
|
92
|
+
return this._account;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
function isSolanaWallet(w) {
|
|
96
|
+
return StandardConnect in w.features && w.chains.some((c) => c.startsWith("solana:"));
|
|
97
|
+
}
|
|
98
|
+
function solanaWalletStandardAdapters(options = {}) {
|
|
99
|
+
if (typeof window === "undefined") return [];
|
|
100
|
+
const wanted = options.wallets;
|
|
101
|
+
const group = options.groupLabel ?? "Solana Wallet";
|
|
102
|
+
return getWallets().get().filter(isSolanaWallet).filter((w) => !wanted || wanted.includes(w.name)).map((w) => {
|
|
103
|
+
const meta = {
|
|
104
|
+
label: options.labels?.[w.name] ?? w.name,
|
|
105
|
+
iconUrl: w.icon,
|
|
106
|
+
group
|
|
107
|
+
};
|
|
108
|
+
const id = `solana:${w.name}`;
|
|
109
|
+
return new SolanaWalletStandardAdapter(w, id, meta);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { SolanaWalletStandardAdapter, solanaWalletStandardAdapters };
|
|
114
|
+
//# sourceMappingURL=index.mjs.map
|
|
115
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/SolanaWalletStandardAdapter.ts","../src/factory.ts"],"names":["StandardConnect"],"mappings":";;;;;AA6BA,SAAS,cAAc,KAAA,EAAwB;AAC7C,EAAA,OAAO,KAAA,CAAM,WAAW,SAAS,CAAA;AACnC;AAcO,IAAM,8BAAN,MAA2D;AAAA,EAShE,WAAA,CAAY,MAAA,EAAgB,QAAA,EAAoB,IAAA,EAAyB;AANzE,IAAA,IAAA,CAAS,OAAA,GAAU,UAAA;AACnB,IAAA,IAAA,CAAS,KAAA,GAAqB,QAAA;AAG9B,IAAA,IAAA,CAAQ,QAAA,GAAiC,IAAA;AAGvC,IAAA,IAAA,CAAK,OAAA,GAAU,MAAA;AACf,IAAA,IAAA,CAAK,IAAA,GAAO,QAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA,EAEA,MAAM,WAAA,GAAgC;AAIpC,IAAA,OAAO,eAAA,IAAmB,KAAK,OAAA,CAAQ,QAAA,IAAY,KAAK,OAAA,CAAQ,MAAA,CAAO,KAAK,aAAa,CAAA;AAAA,EAC3F;AAAA,EAEA,MAAM,OAAA,GAA0C;AAC9C,IAAA,MAAM,OAAA,GAAU,IAAA,CAAK,OAAA,CAAQ,QAAA,CAAS,eAAe,CAAA;AACrD,IAAA,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,CAAA,+BAAA,EAAkC,IAAA,CAAK,IAAI,CAAA,mCAAA,CAAqC,CAAA;AAC9G,IAAA,MAAM,EAAE,QAAA,EAAS,GAAI,MAAM,QAAQ,OAAA,EAAQ;AAC3C,IAAA,MAAM,OAAA,GAAU,QAAA,CAAS,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,MAAA,CAAO,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AAY,CAAA,CAAE,MAAA,CAAO,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,UAAA,CAAW,SAAS,CAAC,CAAA;AACtF;AAkBO,SAAS,4BAAA,CAA6B,OAAA,GAA8C,EAAC,EAAkC;AAK5H,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,OAAO,EAAC;AAE3C,EAAA,MAAM,SAAS,OAAA,CAAQ,OAAA;AACvB,EAAA,MAAM,KAAA,GAAQ,QAAQ,UAAA,IAAc,eAAA;AAEpC,EAAA,OAAO,UAAA,GACJ,GAAA,EAAI,CACJ,OAAO,cAAc,CAAA,CACrB,OAAO,CAAC,CAAA,KAAM,CAAC,MAAA,IAAU,MAAA,CAAO,SAAS,CAAA,CAAE,IAAI,CAAC,CAAA,CAChD,GAAA,CAAI,CAAC,CAAA,KAAM;AACV,IAAA,MAAM,IAAA,GAA0B;AAAA,MAC9B,OAAO,OAAA,CAAQ,MAAA,GAAS,CAAA,CAAE,IAAI,KAAK,CAAA,CAAE,IAAA;AAAA,MACrC,SAAS,CAAA,CAAE,IAAA;AAAA,MACX;AAAA,KACF;AAGA,IAAA,MAAM,EAAA,GAAe,CAAA,OAAA,EAAU,CAAA,CAAE,IAAI,CAAA,CAAA;AACrC,IAAA,OAAO,IAAI,2BAAA,CAA4B,CAAA,EAAG,EAAA,EAAI,IAAI,CAAA;AAAA,EACpD,CAAC,CAAA;AACL","file":"index.mjs","sourcesContent":["import type {\n ConnectWalletResponse,\n SolanaSignInInput,\n SolanaSignInOutput,\n SolanaSignMessageResponse,\n WalletAdapter,\n WalletAdapterMeta,\n WalletChain,\n WalletId,\n} from '@pollar/core';\nimport {\n SolanaSignIn,\n SolanaSignMessage,\n SolanaSignTransaction,\n type SolanaSignInFeature,\n type SolanaSignMessageFeature,\n type SolanaSignTransactionFeature,\n} from '@solana/wallet-standard-features';\nimport type { Wallet, WalletAccount } from '@wallet-standard/base';\nimport {\n StandardConnect,\n StandardDisconnect,\n type StandardConnectFeature,\n type StandardDisconnectFeature,\n} from '@wallet-standard/features';\n\n/** A Solana chain identifier as used by the Wallet Standard (e.g. `solana:mainnet`). */\ntype SolanaChainId = `solana:${string}`;\n\nfunction isSolanaChain(chain: string): boolean {\n return chain.startsWith('solana:');\n}\n\n/**\n * Wraps a Wallet Standard Solana wallet (Phantom, Solflare, Backpack, ...) so it can\n * back a Pollar external-wallet login. The Wallet Standard is the headless\n * substrate `@solana/wallet-adapter` is built on, so this stays framework-agnostic\n * exactly like `@pollar/stellar-wallets-kit-adapter`.\n *\n * The signing surface is Solana-native, NOT the Stellar `WalletAdapter` shape:\n * login is SIWS (`signIn`, a signed MESSAGE) rather than SEP-10 (a signed\n * transaction), and transactions are serialized Solana messages, not XDR. Once\n * `@pollar/core` grows a chain-aware adapter contract (see the design doc) this\n * slots into `PollarClientConfig.walletAdapters`.\n */\nexport class SolanaWalletStandardAdapter implements WalletAdapter {\n readonly type: WalletId;\n readonly meta: WalletAdapterMeta;\n readonly custody = 'external' as const;\n readonly chain: WalletChain = 'SOLANA';\n\n private readonly _wallet: Wallet;\n private _account: WalletAccount | null = null;\n\n constructor(wallet: Wallet, walletId: WalletId, meta: WalletAdapterMeta) {\n this._wallet = wallet;\n this.type = walletId;\n this.meta = meta;\n }\n\n async isAvailable(): Promise<boolean> {\n // Registered in the Wallet Standard registry with a Solana chain and the\n // standard connect feature. Discovery already filtered to Solana wallets, so\n // this is a cheap re-check rather than a probe.\n return StandardConnect in this._wallet.features && this._wallet.chains.some(isSolanaChain);\n }\n\n async connect(): Promise<ConnectWalletResponse> {\n const feature = this._wallet.features[StandardConnect] as StandardConnectFeature[typeof StandardConnect] | undefined;\n if (!feature) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" does not support standard:connect`);\n const { accounts } = await feature.connect();\n const account = accounts.find((a) => a.chains.some(isSolanaChain)) ?? accounts[0];\n if (!account) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" returned no account on connect`);\n this._account = account;\n return { address: account.address };\n }\n\n async disconnect(): Promise<void> {\n try {\n const feature = this._wallet.features[StandardDisconnect] as\n | StandardDisconnectFeature[typeof StandardDisconnect]\n | undefined;\n await feature?.disconnect();\n } finally {\n this._account = null;\n }\n }\n\n async getPublicKey(): Promise<string | null> {\n if (this._account) return this._account.address;\n // A wallet reconnected across a reload exposes its accounts without a fresh\n // connect(); adopt the first Solana one so getPublicKey works after resume.\n this._account = this._wallet.accounts.find((a) => a.chains.some(isSolanaChain)) ?? null;\n return this._account?.address ?? null;\n }\n\n /** Does this wallet expose native SIWS (`solana:signIn`)? If not, use `signMessage`. */\n get supportsSignIn(): boolean {\n return SolanaSignIn in this._wallet.features;\n }\n\n /**\n * SIWS: sign the server-issued Sign In With Solana input. This is the Solana\n * analogue of the Stellar SEP-10 challenge, but the wallet signs a structured\n * MESSAGE (domain, statement, nonce, ...) rather than a transaction.\n */\n async signIn(input: SolanaSignInInput): Promise<SolanaSignInOutput> {\n const feature = this._wallet.features[SolanaSignIn] as SolanaSignInFeature[typeof SolanaSignIn] | undefined;\n if (!feature) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" does not support solana:signIn (SIWS)`);\n const [output] = await feature.signIn(input);\n if (!output) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" returned no SIWS output`);\n this._account = output.account;\n // The Wallet Standard hands back readonly byte views; copy into real\n // Uint8Arrays so `@pollar/core` (which base64-encodes them for the server)\n // gets mutable, standard arrays.\n return {\n account: { address: output.account.address, publicKey: Uint8Array.from(output.account.publicKey) },\n signedMessage: Uint8Array.from(output.signedMessage),\n signature: Uint8Array.from(output.signature),\n ...(output.signatureType ? { signatureType: output.signatureType } : {}),\n };\n }\n\n /** Raw message signing - the SIWS fallback for wallets without `solana:signIn`. */\n async signMessage(message: Uint8Array): Promise<SolanaSignMessageResponse> {\n const account = this._requireAccount();\n const feature = this._wallet.features[SolanaSignMessage] as SolanaSignMessageFeature[typeof SolanaSignMessage] | undefined;\n if (!feature) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" does not support solana:signMessage`);\n const [output] = await feature.signMessage({ account, message });\n if (!output) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" returned no signature`);\n return { signature: Uint8Array.from(output.signature), signedMessage: Uint8Array.from(output.signedMessage) };\n }\n\n /**\n * Sign a serialized Solana transaction. Used by phase 2 (sponsored external\n * transfers), where Pollar builds a durable-nonce transfer whose fee payer is\n * the app GAS wallet and the user signs their part here.\n */\n async signSolanaTransaction(transaction: Uint8Array, chain?: string): Promise<Uint8Array> {\n const account = this._requireAccount();\n const feature = this._wallet.features[SolanaSignTransaction] as\n | SolanaSignTransactionFeature[typeof SolanaSignTransaction]\n | undefined;\n if (!feature) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" does not support solana:signTransaction`);\n const solanaChain = chain && chain.startsWith('solana:') ? (chain as SolanaChainId) : undefined;\n const [output] = await feature.signTransaction({ account, transaction, ...(solanaChain ? { chain: solanaChain } : {}) });\n if (!output) throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" returned no signed transaction`);\n return Uint8Array.from(output.signedTransaction);\n }\n\n private _requireAccount(): WalletAccount {\n if (!this._account) {\n throw new Error(`[SolanaWalletStandardAdapter] \"${this.type}\" is not connected — call connect() first`);\n }\n return this._account;\n }\n}\n","import type { WalletAdapterMeta, WalletId } from '@pollar/core';\nimport { getWallets } from '@wallet-standard/app';\nimport type { Wallet } from '@wallet-standard/base';\nimport { StandardConnect } from '@wallet-standard/features';\nimport { SolanaWalletStandardAdapter } from './SolanaWalletStandardAdapter';\n\nexport interface SolanaWalletStandardAdapterOptions {\n /** Subset of wallet names to include. Defaults to every Solana wallet found. */\n wallets?: string[];\n /** Per-wallet button-label overrides, keyed by the wallet's `name`. */\n labels?: Record<string, string>;\n /**\n * Gateway button label these wallets collapse behind in the login UI (applied\n * as each adapter's `meta.group`). Default `'Solana Wallet'` - a distinct group\n * from the Stellar `'Wallet'` gateway, so the two chains render as separate\n * login buttons.\n */\n groupLabel?: string;\n}\n\n/** A wallet is usable here if it advertises a Solana chain and standard connect. */\nfunction isSolanaWallet(w: Wallet): boolean {\n return StandardConnect in w.features && w.chains.some((c) => c.startsWith('solana:'));\n}\n\n/**\n * Build one {@link SolanaWalletStandardAdapter} per installed Solana wallet discovered\n * through the Wallet Standard registry, to pass to\n * `PollarClientConfig.walletAdapters` (once `@pollar/core` is chain-aware - see the\n * design doc).\n *\n * @example\n * ```ts\n * import { solanaWalletStandardAdapters } from '@pollar/solana-wallet-standard-adapter';\n *\n * const client = new PollarClient({\n * apiKey: '...',\n * walletAdapters: [...stellarWalletsKitAdapters({ network }), ...solanaWalletStandardAdapters()],\n * });\n * ```\n */\nexport function solanaWalletStandardAdapters(options: SolanaWalletStandardAdapterOptions = {}): SolanaWalletStandardAdapter[] {\n // SSR guard: wallet extensions register into a browser-global registry, so\n // there is nothing to find server-side. Return [] and let this re-run on the\n // client (build the PollarClient client-side, e.g. behind a mounted flag or\n // `dynamic(..., { ssr: false })`). Mirrors the Stellar adapter factory.\n if (typeof window === 'undefined') return [];\n\n const wanted = options.wallets;\n const group = options.groupLabel ?? 'Solana Wallet';\n\n return getWallets()\n .get()\n .filter(isSolanaWallet)\n .filter((w) => !wanted || wanted.includes(w.name))\n .map((w) => {\n const meta: WalletAdapterMeta = {\n label: options.labels?.[w.name] ?? w.name,\n iconUrl: w.icon,\n group,\n };\n // Namespace the id so a Solana wallet never collides with a Stellar adapter\n // of the same brand name in the shared adapter registry.\n const id: WalletId = `solana:${w.name}`;\n return new SolanaWalletStandardAdapter(w, id, meta);\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pollar/solana-wallet-standard-adapter",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.11.5",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/pollar-xyz/pollar.git",
|
|
8
|
+
"directory": "packages/solana-wallet-standard-adapter"
|
|
9
|
+
},
|
|
10
|
+
"description": "Solana Wallet Standard adapter for @pollar/core - connect user-controlled Solana wallets (Phantom, Solflare, Backpack, ...) via the Wallet Standard (@wallet-standard/* + @solana/wallet-standard-features), with SIWS login, without bundling any wallet SDK into @pollar/core.",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"module": "./dist/index.mjs",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./dist/index.d.mts",
|
|
18
|
+
"default": "./dist/index.mjs"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"NOTICE"
|
|
29
|
+
],
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup",
|
|
33
|
+
"dev": "tsup --watch",
|
|
34
|
+
"lint": "tsc --noEmit && eslint src",
|
|
35
|
+
"clean": "rm -rf dist"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=20"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@pollar/core": "^0.11.2"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@solana/wallet-standard-features": "^1.4.0",
|
|
45
|
+
"@wallet-standard/app": "^1.1.1",
|
|
46
|
+
"@wallet-standard/base": "^1.1.1",
|
|
47
|
+
"@wallet-standard/features": "^1.1.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@eslint/js": "^10.0.1",
|
|
51
|
+
"@pollar/core": "^0.11.5",
|
|
52
|
+
"eslint": "^10.5.0",
|
|
53
|
+
"tsup": "^8.5.1",
|
|
54
|
+
"typescript": "^6.0.3",
|
|
55
|
+
"typescript-eslint": "^8.61.0"
|
|
56
|
+
}
|
|
57
|
+
}
|