@dynamic-labs/spark 4.40.0 → 4.40.1

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 CHANGED
@@ -1,4 +1,10 @@
1
1
 
2
+ ### [4.40.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.40.0...v4.40.1) (2025-10-24)
3
+
4
+ ### Bug Fixes
5
+
6
+ * add support for Keplr in-app browser redirect for cosmos chain ([#9770](https://github.com/dynamic-labs/dynamic-auth/issues/9770)) ([35652f3](https://github.com/dynamic-labs/dynamic-auth/commit/35652f3167a4e768f5d4c634ab1b4f127fd5076a))
7
+
2
8
  ## [4.40.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.39.0...v4.40.0) (2025-10-22)
3
9
 
4
10
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.40.0";
6
+ var version = "4.40.1";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.40.0";
2
+ var version = "4.40.1";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/spark",
3
- "version": "4.40.0",
3
+ "version": "4.40.1",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -18,11 +18,12 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
- "@dynamic-labs/assert-package-version": "4.40.0",
22
- "@dynamic-labs/types": "4.40.0",
23
- "@dynamic-labs/utils": "4.40.0",
24
- "@dynamic-labs/wallet-book": "4.40.0",
25
- "@dynamic-labs/wallet-connector-core": "4.40.0"
21
+ "@dynamic-labs/assert-package-version": "4.40.1",
22
+ "sats-connect": "4.2.0",
23
+ "@dynamic-labs/types": "4.40.1",
24
+ "@dynamic-labs/utils": "4.40.1",
25
+ "@dynamic-labs/wallet-book": "4.40.1",
26
+ "@dynamic-labs/wallet-connector-core": "4.40.1"
26
27
  },
27
28
  "peerDependencies": {}
28
29
  }
@@ -0,0 +1,261 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var satsConnect = require('sats-connect');
8
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
+ var SparkWalletConnector = require('../SparkWalletConnector/SparkWalletConnector.cjs');
10
+
11
+ /**
12
+ * Spark wallet connector implementation using sats-connect library.
13
+ *
14
+ * This connector enables integration with any wallet that supports the
15
+ * sats-connect Spark methods, providing a standardized interface for
16
+ * Spark Bitcoin operations including address management, balance queries,
17
+ * message signing, and token transfers.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const connector = new SparkSatsConnectConnector({
22
+ * walletBook,
23
+ * sparkNetworks
24
+ * });
25
+ *
26
+ * await connector.connect();
27
+ * const address = await connector.getAddress();
28
+ * const balance = await connector.getBalance();
29
+ * ```
30
+ */
31
+ class SparkSatsConnectConnector extends SparkWalletConnector.SparkWalletConnector {
32
+ /**
33
+ * Creates a new Spark Sats Connect connector
34
+ * @param opts - Configuration options
35
+ */
36
+ constructor(opts) {
37
+ super(opts);
38
+ /** Human-readable connector name */
39
+ this.name = 'Spark Sats Connect';
40
+ }
41
+ /**
42
+ * Returns undefined since sats-connect uses a request-based API
43
+ * rather than a window provider pattern.
44
+ *
45
+ * The connector methods directly call sats-connect's request function
46
+ * instead of delegating to a provider object.
47
+ *
48
+ * @returns undefined as no provider object is needed
49
+ */
50
+ getProvider() {
51
+ // sats-connect doesn't use a window provider pattern like other wallets.
52
+ // Instead, it uses a direct request() API that works across all wallets
53
+ // that implement the sats-connect protocol.
54
+ return undefined;
55
+ }
56
+ /**
57
+ * Retrieves the current wallet address using sats-connect.
58
+ *
59
+ * Requests the Spark address from the connected wallet using the
60
+ * spark_getAddresses method.
61
+ *
62
+ * @returns The wallet address as a string, or undefined if unavailable
63
+ * @throws Error if the user cancels the request
64
+ */
65
+ getAddress() {
66
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
67
+ var _a;
68
+ try {
69
+ const response = yield satsConnect.request('spark_getAddresses', {});
70
+ if (response.status !== 'success') {
71
+ throw response.error;
72
+ }
73
+ // Find the Spark address from the returned addresses
74
+ const sparkAddress = (_a = response.result.addresses) === null || _a === void 0 ? void 0 : _a.find((addr) => addr.purpose === satsConnect.AddressPurpose.Spark);
75
+ if (!sparkAddress) {
76
+ throw new Error('No Spark address found in response');
77
+ }
78
+ return sparkAddress.address;
79
+ }
80
+ catch (error) {
81
+ walletConnectorCore.logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to get address', error);
82
+ throw error;
83
+ }
84
+ });
85
+ }
86
+ /**
87
+ * Retrieves the public key for the Spark address.
88
+ *
89
+ * @returns The public key as a hex string
90
+ * @throws Error if the request fails
91
+ */
92
+ getPublicKey() {
93
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
94
+ var _a;
95
+ try {
96
+ const response = yield satsConnect.request('spark_getAddresses', {});
97
+ if (response.status !== 'success') {
98
+ throw response.error;
99
+ }
100
+ const sparkAddress = (_a = response.result.addresses) === null || _a === void 0 ? void 0 : _a.find((addr) => addr.purpose === satsConnect.AddressPurpose.Spark);
101
+ if (!(sparkAddress === null || sparkAddress === void 0 ? void 0 : sparkAddress.publicKey)) {
102
+ throw new Error('No Spark public key found in response');
103
+ }
104
+ return sparkAddress.publicKey;
105
+ }
106
+ catch (error) {
107
+ walletConnectorCore.logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to get public key', error);
108
+ throw error;
109
+ }
110
+ });
111
+ }
112
+ /**
113
+ * Retrieves the wallet balance using sats-connect.
114
+ *
115
+ * Gets the Spark Bitcoin balance in BTC (converted from satoshis).
116
+ *
117
+ * TODO: Add support for returning token balances in addition to BTC balance.
118
+ * The spark_getBalance method returns tokenBalances which we currently ignore.
119
+ *
120
+ * @returns The balance as a string in BTC, or undefined if unavailable
121
+ * @throws Error if the request fails
122
+ */
123
+ getBalance() {
124
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
125
+ try {
126
+ const response = yield satsConnect.request('spark_getBalance', undefined);
127
+ if (response.status !== 'success') {
128
+ throw response.error;
129
+ }
130
+ // Convert satoshis to BTC using BigInt arithmetic to maintain precision
131
+ const balanceInSats = BigInt(response.result.balance);
132
+ const satoshisPerBtc = BigInt(100000000);
133
+ // Calculate whole BTC and remainder satoshis
134
+ const wholeBtc = balanceInSats / satoshisPerBtc;
135
+ const remainderSats = balanceInSats % satoshisPerBtc;
136
+ if (remainderSats === BigInt(0)) {
137
+ return wholeBtc.toString();
138
+ }
139
+ const remainderStr = remainderSats.toString().padStart(8, '0');
140
+ let trimmedRemainder = remainderStr;
141
+ while (trimmedRemainder.endsWith('0') && trimmedRemainder.length > 1) {
142
+ trimmedRemainder = trimmedRemainder.slice(0, -1);
143
+ }
144
+ return trimmedRemainder
145
+ ? `${wholeBtc}.${trimmedRemainder}`
146
+ : wholeBtc.toString();
147
+ }
148
+ catch (error) {
149
+ walletConnectorCore.logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to get balance', error);
150
+ throw error;
151
+ }
152
+ });
153
+ }
154
+ /**
155
+ * Signs a message using sats-connect spark_signMessage method.
156
+ *
157
+ * @param message - The message to sign or signing request object
158
+ * @returns The signature as a string, or undefined if signing fails
159
+ * @throws Error if the request fails or user cancels
160
+ */
161
+ signMessage(message) {
162
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
163
+ try {
164
+ // Extract message string from input
165
+ const messageToSign = typeof message === 'string' ? message : message.message;
166
+ if (!messageToSign) {
167
+ throw new Error('Message is required for signing');
168
+ }
169
+ const response = yield satsConnect.request('spark_signMessage', {
170
+ message: messageToSign,
171
+ });
172
+ if (response.status !== 'success') {
173
+ throw response.error;
174
+ }
175
+ // Return the signature from the response
176
+ return response.result.signature;
177
+ }
178
+ catch (error) {
179
+ walletConnectorCore.logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to sign message', error);
180
+ throw error;
181
+ }
182
+ });
183
+ }
184
+ /**
185
+ * Transfers Bitcoin to another Spark address using sats-connect.
186
+ *
187
+ * @param params - Transfer parameters
188
+ * @param params.receiverSparkAddress - The recipient's Spark address
189
+ * @param params.amountSats - Amount to transfer in satoshis
190
+ * @param params.isTaproot - Whether to use Taproot (currently ignored for sats-connect)
191
+ * @returns The transaction ID/hash
192
+ * @throws Error if the transfer fails or user cancels
193
+ */
194
+ transferBitcoin(params) {
195
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
196
+ try {
197
+ const response = yield satsConnect.request('spark_transfer', {
198
+ amountSats: params.amountSats,
199
+ receiverSparkAddress: params.receiverSparkAddress,
200
+ });
201
+ if (response.status !== 'success') {
202
+ throw response.error;
203
+ }
204
+ return response.result.id;
205
+ }
206
+ catch (error) {
207
+ walletConnectorCore.logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to transfer Bitcoin', error);
208
+ throw error;
209
+ }
210
+ });
211
+ }
212
+ /**
213
+ * Transfers tokens to another Spark address using sats-connect.
214
+ *
215
+ * @param params - Transfer parameters
216
+ * @param params.tokenPublicKey - The token's identifier (bech32m format)
217
+ * @param params.receiverSparkAddress - The recipient's Spark address
218
+ * @param params.tokenAmount - Amount of tokens to transfer
219
+ * @param params.isTaproot - Whether to use Taproot (currently ignored for sats-connect)
220
+ * @returns The transaction ID/hash
221
+ * @throws Error if the transfer fails or user cancels
222
+ */
223
+ transferTokens(params) {
224
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
225
+ try {
226
+ const response = yield satsConnect.request('spark_transferToken', {
227
+ receiverSparkAddress: params.receiverSparkAddress,
228
+ tokenAmount: params.tokenAmount,
229
+ tokenIdentifier: params.tokenPublicKey,
230
+ });
231
+ if (response.status !== 'success') {
232
+ throw response.error;
233
+ }
234
+ return response.result.id;
235
+ }
236
+ catch (error) {
237
+ walletConnectorCore.logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to transfer tokens', error);
238
+ throw error;
239
+ }
240
+ });
241
+ }
242
+ /**
243
+ * Checks if the Spark wallet is installed in the browser.
244
+ *
245
+ * For sats-connect, we check if the library is available since it
246
+ * doesn't rely on a window provider pattern.
247
+ *
248
+ * @returns True if sats-connect is available
249
+ */
250
+ isInstalledOnBrowser() {
251
+ try {
252
+ // Check if sats-connect request function is available
253
+ return typeof satsConnect.request === 'function';
254
+ }
255
+ catch (_a) {
256
+ return false;
257
+ }
258
+ }
259
+ }
260
+
261
+ exports.SparkSatsConnectConnector = SparkSatsConnectConnector;
@@ -0,0 +1,122 @@
1
+ import { SparkWalletConnector, SparkWalletConnectorOpts } from '../SparkWalletConnector';
2
+ import type { ISparkProvider } from '../../types';
3
+ /**
4
+ * Spark wallet connector implementation using sats-connect library.
5
+ *
6
+ * This connector enables integration with any wallet that supports the
7
+ * sats-connect Spark methods, providing a standardized interface for
8
+ * Spark Bitcoin operations including address management, balance queries,
9
+ * message signing, and token transfers.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const connector = new SparkSatsConnectConnector({
14
+ * walletBook,
15
+ * sparkNetworks
16
+ * });
17
+ *
18
+ * await connector.connect();
19
+ * const address = await connector.getAddress();
20
+ * const balance = await connector.getBalance();
21
+ * ```
22
+ */
23
+ export declare class SparkSatsConnectConnector extends SparkWalletConnector {
24
+ /** Human-readable connector name */
25
+ name: string;
26
+ /**
27
+ * Creates a new Spark Sats Connect connector
28
+ * @param opts - Configuration options
29
+ */
30
+ constructor(opts: SparkWalletConnectorOpts);
31
+ /**
32
+ * Returns undefined since sats-connect uses a request-based API
33
+ * rather than a window provider pattern.
34
+ *
35
+ * The connector methods directly call sats-connect's request function
36
+ * instead of delegating to a provider object.
37
+ *
38
+ * @returns undefined as no provider object is needed
39
+ */
40
+ getProvider(): ISparkProvider | undefined;
41
+ /**
42
+ * Retrieves the current wallet address using sats-connect.
43
+ *
44
+ * Requests the Spark address from the connected wallet using the
45
+ * spark_getAddresses method.
46
+ *
47
+ * @returns The wallet address as a string, or undefined if unavailable
48
+ * @throws Error if the user cancels the request
49
+ */
50
+ getAddress(): Promise<string | undefined>;
51
+ /**
52
+ * Retrieves the public key for the Spark address.
53
+ *
54
+ * @returns The public key as a hex string
55
+ * @throws Error if the request fails
56
+ */
57
+ private getPublicKey;
58
+ /**
59
+ * Retrieves the wallet balance using sats-connect.
60
+ *
61
+ * Gets the Spark Bitcoin balance in BTC (converted from satoshis).
62
+ *
63
+ * TODO: Add support for returning token balances in addition to BTC balance.
64
+ * The spark_getBalance method returns tokenBalances which we currently ignore.
65
+ *
66
+ * @returns The balance as a string in BTC, or undefined if unavailable
67
+ * @throws Error if the request fails
68
+ */
69
+ getBalance(): Promise<string | undefined>;
70
+ /**
71
+ * Signs a message using sats-connect spark_signMessage method.
72
+ *
73
+ * @param message - The message to sign or signing request object
74
+ * @returns The signature as a string, or undefined if signing fails
75
+ * @throws Error if the request fails or user cancels
76
+ */
77
+ signMessage(message: string | {
78
+ message: string;
79
+ isTaproot?: boolean;
80
+ }): Promise<string | undefined>;
81
+ /**
82
+ * Transfers Bitcoin to another Spark address using sats-connect.
83
+ *
84
+ * @param params - Transfer parameters
85
+ * @param params.receiverSparkAddress - The recipient's Spark address
86
+ * @param params.amountSats - Amount to transfer in satoshis
87
+ * @param params.isTaproot - Whether to use Taproot (currently ignored for sats-connect)
88
+ * @returns The transaction ID/hash
89
+ * @throws Error if the transfer fails or user cancels
90
+ */
91
+ transferBitcoin(params: {
92
+ receiverSparkAddress: string;
93
+ amountSats: string | number;
94
+ isTaproot?: boolean;
95
+ }): Promise<string | undefined>;
96
+ /**
97
+ * Transfers tokens to another Spark address using sats-connect.
98
+ *
99
+ * @param params - Transfer parameters
100
+ * @param params.tokenPublicKey - The token's identifier (bech32m format)
101
+ * @param params.receiverSparkAddress - The recipient's Spark address
102
+ * @param params.tokenAmount - Amount of tokens to transfer
103
+ * @param params.isTaproot - Whether to use Taproot (currently ignored for sats-connect)
104
+ * @returns The transaction ID/hash
105
+ * @throws Error if the transfer fails or user cancels
106
+ */
107
+ transferTokens(params: {
108
+ tokenPublicKey: string;
109
+ receiverSparkAddress: string;
110
+ tokenAmount: number;
111
+ isTaproot?: boolean;
112
+ }): Promise<string | undefined>;
113
+ /**
114
+ * Checks if the Spark wallet is installed in the browser.
115
+ *
116
+ * For sats-connect, we check if the library is available since it
117
+ * doesn't rely on a window provider pattern.
118
+ *
119
+ * @returns True if sats-connect is available
120
+ */
121
+ isInstalledOnBrowser(): boolean;
122
+ }
@@ -0,0 +1,257 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../_virtual/_tslib.js';
3
+ import { request, AddressPurpose } from 'sats-connect';
4
+ import { logger } from '@dynamic-labs/wallet-connector-core';
5
+ import { SparkWalletConnector } from '../SparkWalletConnector/SparkWalletConnector.js';
6
+
7
+ /**
8
+ * Spark wallet connector implementation using sats-connect library.
9
+ *
10
+ * This connector enables integration with any wallet that supports the
11
+ * sats-connect Spark methods, providing a standardized interface for
12
+ * Spark Bitcoin operations including address management, balance queries,
13
+ * message signing, and token transfers.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const connector = new SparkSatsConnectConnector({
18
+ * walletBook,
19
+ * sparkNetworks
20
+ * });
21
+ *
22
+ * await connector.connect();
23
+ * const address = await connector.getAddress();
24
+ * const balance = await connector.getBalance();
25
+ * ```
26
+ */
27
+ class SparkSatsConnectConnector extends SparkWalletConnector {
28
+ /**
29
+ * Creates a new Spark Sats Connect connector
30
+ * @param opts - Configuration options
31
+ */
32
+ constructor(opts) {
33
+ super(opts);
34
+ /** Human-readable connector name */
35
+ this.name = 'Spark Sats Connect';
36
+ }
37
+ /**
38
+ * Returns undefined since sats-connect uses a request-based API
39
+ * rather than a window provider pattern.
40
+ *
41
+ * The connector methods directly call sats-connect's request function
42
+ * instead of delegating to a provider object.
43
+ *
44
+ * @returns undefined as no provider object is needed
45
+ */
46
+ getProvider() {
47
+ // sats-connect doesn't use a window provider pattern like other wallets.
48
+ // Instead, it uses a direct request() API that works across all wallets
49
+ // that implement the sats-connect protocol.
50
+ return undefined;
51
+ }
52
+ /**
53
+ * Retrieves the current wallet address using sats-connect.
54
+ *
55
+ * Requests the Spark address from the connected wallet using the
56
+ * spark_getAddresses method.
57
+ *
58
+ * @returns The wallet address as a string, or undefined if unavailable
59
+ * @throws Error if the user cancels the request
60
+ */
61
+ getAddress() {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ var _a;
64
+ try {
65
+ const response = yield request('spark_getAddresses', {});
66
+ if (response.status !== 'success') {
67
+ throw response.error;
68
+ }
69
+ // Find the Spark address from the returned addresses
70
+ const sparkAddress = (_a = response.result.addresses) === null || _a === void 0 ? void 0 : _a.find((addr) => addr.purpose === AddressPurpose.Spark);
71
+ if (!sparkAddress) {
72
+ throw new Error('No Spark address found in response');
73
+ }
74
+ return sparkAddress.address;
75
+ }
76
+ catch (error) {
77
+ logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to get address', error);
78
+ throw error;
79
+ }
80
+ });
81
+ }
82
+ /**
83
+ * Retrieves the public key for the Spark address.
84
+ *
85
+ * @returns The public key as a hex string
86
+ * @throws Error if the request fails
87
+ */
88
+ getPublicKey() {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ var _a;
91
+ try {
92
+ const response = yield request('spark_getAddresses', {});
93
+ if (response.status !== 'success') {
94
+ throw response.error;
95
+ }
96
+ const sparkAddress = (_a = response.result.addresses) === null || _a === void 0 ? void 0 : _a.find((addr) => addr.purpose === AddressPurpose.Spark);
97
+ if (!(sparkAddress === null || sparkAddress === void 0 ? void 0 : sparkAddress.publicKey)) {
98
+ throw new Error('No Spark public key found in response');
99
+ }
100
+ return sparkAddress.publicKey;
101
+ }
102
+ catch (error) {
103
+ logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to get public key', error);
104
+ throw error;
105
+ }
106
+ });
107
+ }
108
+ /**
109
+ * Retrieves the wallet balance using sats-connect.
110
+ *
111
+ * Gets the Spark Bitcoin balance in BTC (converted from satoshis).
112
+ *
113
+ * TODO: Add support for returning token balances in addition to BTC balance.
114
+ * The spark_getBalance method returns tokenBalances which we currently ignore.
115
+ *
116
+ * @returns The balance as a string in BTC, or undefined if unavailable
117
+ * @throws Error if the request fails
118
+ */
119
+ getBalance() {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ try {
122
+ const response = yield request('spark_getBalance', undefined);
123
+ if (response.status !== 'success') {
124
+ throw response.error;
125
+ }
126
+ // Convert satoshis to BTC using BigInt arithmetic to maintain precision
127
+ const balanceInSats = BigInt(response.result.balance);
128
+ const satoshisPerBtc = BigInt(100000000);
129
+ // Calculate whole BTC and remainder satoshis
130
+ const wholeBtc = balanceInSats / satoshisPerBtc;
131
+ const remainderSats = balanceInSats % satoshisPerBtc;
132
+ if (remainderSats === BigInt(0)) {
133
+ return wholeBtc.toString();
134
+ }
135
+ const remainderStr = remainderSats.toString().padStart(8, '0');
136
+ let trimmedRemainder = remainderStr;
137
+ while (trimmedRemainder.endsWith('0') && trimmedRemainder.length > 1) {
138
+ trimmedRemainder = trimmedRemainder.slice(0, -1);
139
+ }
140
+ return trimmedRemainder
141
+ ? `${wholeBtc}.${trimmedRemainder}`
142
+ : wholeBtc.toString();
143
+ }
144
+ catch (error) {
145
+ logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to get balance', error);
146
+ throw error;
147
+ }
148
+ });
149
+ }
150
+ /**
151
+ * Signs a message using sats-connect spark_signMessage method.
152
+ *
153
+ * @param message - The message to sign or signing request object
154
+ * @returns The signature as a string, or undefined if signing fails
155
+ * @throws Error if the request fails or user cancels
156
+ */
157
+ signMessage(message) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ try {
160
+ // Extract message string from input
161
+ const messageToSign = typeof message === 'string' ? message : message.message;
162
+ if (!messageToSign) {
163
+ throw new Error('Message is required for signing');
164
+ }
165
+ const response = yield request('spark_signMessage', {
166
+ message: messageToSign,
167
+ });
168
+ if (response.status !== 'success') {
169
+ throw response.error;
170
+ }
171
+ // Return the signature from the response
172
+ return response.result.signature;
173
+ }
174
+ catch (error) {
175
+ logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to sign message', error);
176
+ throw error;
177
+ }
178
+ });
179
+ }
180
+ /**
181
+ * Transfers Bitcoin to another Spark address using sats-connect.
182
+ *
183
+ * @param params - Transfer parameters
184
+ * @param params.receiverSparkAddress - The recipient's Spark address
185
+ * @param params.amountSats - Amount to transfer in satoshis
186
+ * @param params.isTaproot - Whether to use Taproot (currently ignored for sats-connect)
187
+ * @returns The transaction ID/hash
188
+ * @throws Error if the transfer fails or user cancels
189
+ */
190
+ transferBitcoin(params) {
191
+ return __awaiter(this, void 0, void 0, function* () {
192
+ try {
193
+ const response = yield request('spark_transfer', {
194
+ amountSats: params.amountSats,
195
+ receiverSparkAddress: params.receiverSparkAddress,
196
+ });
197
+ if (response.status !== 'success') {
198
+ throw response.error;
199
+ }
200
+ return response.result.id;
201
+ }
202
+ catch (error) {
203
+ logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to transfer Bitcoin', error);
204
+ throw error;
205
+ }
206
+ });
207
+ }
208
+ /**
209
+ * Transfers tokens to another Spark address using sats-connect.
210
+ *
211
+ * @param params - Transfer parameters
212
+ * @param params.tokenPublicKey - The token's identifier (bech32m format)
213
+ * @param params.receiverSparkAddress - The recipient's Spark address
214
+ * @param params.tokenAmount - Amount of tokens to transfer
215
+ * @param params.isTaproot - Whether to use Taproot (currently ignored for sats-connect)
216
+ * @returns The transaction ID/hash
217
+ * @throws Error if the transfer fails or user cancels
218
+ */
219
+ transferTokens(params) {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ try {
222
+ const response = yield request('spark_transferToken', {
223
+ receiverSparkAddress: params.receiverSparkAddress,
224
+ tokenAmount: params.tokenAmount,
225
+ tokenIdentifier: params.tokenPublicKey,
226
+ });
227
+ if (response.status !== 'success') {
228
+ throw response.error;
229
+ }
230
+ return response.result.id;
231
+ }
232
+ catch (error) {
233
+ logger.error('===SPARK=== [SparkSatsConnectConnector] Failed to transfer tokens', error);
234
+ throw error;
235
+ }
236
+ });
237
+ }
238
+ /**
239
+ * Checks if the Spark wallet is installed in the browser.
240
+ *
241
+ * For sats-connect, we check if the library is available since it
242
+ * doesn't rely on a window provider pattern.
243
+ *
244
+ * @returns True if sats-connect is available
245
+ */
246
+ isInstalledOnBrowser() {
247
+ try {
248
+ // Check if sats-connect request function is available
249
+ return typeof request === 'function';
250
+ }
251
+ catch (_a) {
252
+ return false;
253
+ }
254
+ }
255
+ }
256
+
257
+ export { SparkSatsConnectConnector };
@@ -0,0 +1 @@
1
+ export { SparkSatsConnectConnector } from './SparkSatsConnectConnector';
@@ -1,2 +1,3 @@
1
- export * from './SparkWalletConnector';
2
1
  export * from './MagicEdenSparkConnector';
2
+ export * from './SparkSatsConnectConnector';
3
+ export * from './SparkWalletConnector';
package/src/consts.cjs ADDED
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const SATSCONNECT_FEATURE = 'sats-connect:';
7
+
8
+ exports.SATSCONNECT_FEATURE = SATSCONNECT_FEATURE;
@@ -0,0 +1 @@
1
+ export declare const SATSCONNECT_FEATURE = "sats-connect:";
package/src/consts.js ADDED
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const SATSCONNECT_FEATURE = 'sats-connect:';
3
+
4
+ export { SATSCONNECT_FEATURE };
package/src/index.cjs CHANGED
@@ -5,15 +5,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var assertPackageVersion = require('@dynamic-labs/assert-package-version');
7
7
  var _package = require('../package.cjs');
8
- require('../_virtual/_tslib.cjs');
9
- require('@dynamic-labs/wallet-connector-core');
10
- var SparkWallet = require('./wallet/SparkWallet.cjs');
11
- var MagicEdenSparkConnector = require('./connectors/MagicEdenSparkConnector/MagicEdenSparkConnector.cjs');
8
+ var fetchSatsConnectConnectors = require('./utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.cjs');
12
9
  var isSparkWallet = require('./wallet/isSparkWallet/isSparkWallet.cjs');
10
+ var SparkWallet = require('./wallet/SparkWallet.cjs');
13
11
 
14
12
  assertPackageVersion.assertPackageVersion('@dynamic-labs/spark', _package.version);
15
- const SparkWalletConnectors = () => [MagicEdenSparkConnector.MagicEdenSparkConnector];
13
+ const SparkWalletConnectors = (props) => [...fetchSatsConnectConnectors.fetchSatsConnectConnectors(props)];
16
14
 
17
- exports.SparkWallet = SparkWallet.SparkWallet;
18
15
  exports.isSparkWallet = isSparkWallet.isSparkWallet;
16
+ exports.SparkWallet = SparkWallet.SparkWallet;
19
17
  exports.SparkWalletConnectors = SparkWalletConnectors;
package/src/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { MagicEdenSparkConnector } from './connectors';
1
+ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
2
2
  export { type ISparkProvider } from './types';
3
3
  export { type SparkWalletConnector } from './connectors/SparkWalletConnector';
4
4
  export { isSparkWallet } from './wallet/isSparkWallet';
5
5
  export { SparkWallet } from './wallet/SparkWallet';
6
- export declare const SparkWalletConnectors: () => (typeof MagicEdenSparkConnector)[];
6
+ export declare const SparkWalletConnectors: (props: {
7
+ walletBook: WalletBookSchema;
8
+ }) => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
package/src/index.js CHANGED
@@ -1,13 +1,11 @@
1
1
  'use client'
2
2
  import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
3
3
  import { version } from '../package.js';
4
- import '../_virtual/_tslib.js';
5
- import '@dynamic-labs/wallet-connector-core';
6
- export { SparkWallet } from './wallet/SparkWallet.js';
7
- import { MagicEdenSparkConnector } from './connectors/MagicEdenSparkConnector/MagicEdenSparkConnector.js';
4
+ import { fetchSatsConnectConnectors } from './utils/fetchSatsConnectConnectors/fetchSatsConnectConnectors.js';
8
5
  export { isSparkWallet } from './wallet/isSparkWallet/isSparkWallet.js';
6
+ export { SparkWallet } from './wallet/SparkWallet.js';
9
7
 
10
8
  assertPackageVersion('@dynamic-labs/spark', version);
11
- const SparkWalletConnectors = () => [MagicEdenSparkConnector];
9
+ const SparkWalletConnectors = (props) => [...fetchSatsConnectConnectors(props)];
12
10
 
13
11
  export { SparkWalletConnectors };
@@ -0,0 +1,65 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var SparkSatsConnectConnector = require('../../connectors/SparkSatsConnectConnector/SparkSatsConnectConnector.cjs');
7
+ var consts = require('../../consts.cjs');
8
+
9
+ /**
10
+ * Checks if a wallet configuration supports sats-connect for Spark chain.
11
+ *
12
+ * A wallet is considered valid if it has:
13
+ * - An injected config for the 'spark' chain
14
+ * - The sats-connect feature included in wallet standard features
15
+ * - A valid provider ID
16
+ *
17
+ * @param wallet - The wallet configuration to check
18
+ * @returns true if the wallet supports sats-connect on Spark, false otherwise
19
+ */
20
+ const isValidSatsConnectWallet = (wallet) => {
21
+ var _a;
22
+ return Boolean((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => {
23
+ var _a, _b;
24
+ return config.chain === 'spark' &&
25
+ Array.isArray((_a = config.walletStandard) === null || _a === void 0 ? void 0 : _a.features) &&
26
+ config.walletStandard.features.includes(consts.SATSCONNECT_FEATURE) &&
27
+ ((_b = config.walletStandard) === null || _b === void 0 ? void 0 : _b.providerId);
28
+ }));
29
+ };
30
+ /**
31
+ * Fetches all Spark wallet connectors that support sats-connect from the wallet book.
32
+ *
33
+ * This function scans the wallet book for wallets with Spark chain configuration
34
+ * and sats-connect support, creating connector classes for each matching wallet.
35
+ *
36
+ * @param walletBook - The wallet book schema containing all wallet configurations
37
+ * @returns Array of wallet connector constructors for sats-connect enabled Spark wallets
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const sparkConnectors = fetchSatsConnectConnectors({ walletBook });
42
+ * // Returns connectors for wallets like Xverse Spark
43
+ * ```
44
+ */
45
+ const fetchSatsConnectConnectors = ({ walletBook, }) => {
46
+ var _a;
47
+ return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
48
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
+ .filter(([_, wallet]) => isValidSatsConnectWallet(wallet))
50
+ .map(([key, wallet]) => {
51
+ const { shortName } = wallet;
52
+ const name = shortName || wallet.name;
53
+ return class extends SparkSatsConnectConnector.SparkSatsConnectConnector {
54
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
+ constructor(props) {
56
+ super(Object.assign(Object.assign({}, props), { overrideKey: key, walletData: wallet }));
57
+ this.name = name;
58
+ this.overrideKey = key;
59
+ }
60
+ };
61
+ });
62
+ };
63
+
64
+ exports.fetchSatsConnectConnectors = fetchSatsConnectConnectors;
65
+ exports.isValidSatsConnectWallet = isValidSatsConnectWallet;
@@ -0,0 +1,32 @@
1
+ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
2
+ import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
3
+ /**
4
+ * Checks if a wallet configuration supports sats-connect for Spark chain.
5
+ *
6
+ * A wallet is considered valid if it has:
7
+ * - An injected config for the 'spark' chain
8
+ * - The sats-connect feature included in wallet standard features
9
+ * - A valid provider ID
10
+ *
11
+ * @param wallet - The wallet configuration to check
12
+ * @returns true if the wallet supports sats-connect on Spark, false otherwise
13
+ */
14
+ export declare const isValidSatsConnectWallet: (wallet: WalletBookSchema['wallets'][string]) => boolean;
15
+ /**
16
+ * Fetches all Spark wallet connectors that support sats-connect from the wallet book.
17
+ *
18
+ * This function scans the wallet book for wallets with Spark chain configuration
19
+ * and sats-connect support, creating connector classes for each matching wallet.
20
+ *
21
+ * @param walletBook - The wallet book schema containing all wallet configurations
22
+ * @returns Array of wallet connector constructors for sats-connect enabled Spark wallets
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const sparkConnectors = fetchSatsConnectConnectors({ walletBook });
27
+ * // Returns connectors for wallets like Xverse Spark
28
+ * ```
29
+ */
30
+ export declare const fetchSatsConnectConnectors: ({ walletBook, }: {
31
+ walletBook: WalletBookSchema;
32
+ }) => WalletConnectorConstructor[];
@@ -0,0 +1,60 @@
1
+ 'use client'
2
+ import { SparkSatsConnectConnector } from '../../connectors/SparkSatsConnectConnector/SparkSatsConnectConnector.js';
3
+ import { SATSCONNECT_FEATURE } from '../../consts.js';
4
+
5
+ /**
6
+ * Checks if a wallet configuration supports sats-connect for Spark chain.
7
+ *
8
+ * A wallet is considered valid if it has:
9
+ * - An injected config for the 'spark' chain
10
+ * - The sats-connect feature included in wallet standard features
11
+ * - A valid provider ID
12
+ *
13
+ * @param wallet - The wallet configuration to check
14
+ * @returns true if the wallet supports sats-connect on Spark, false otherwise
15
+ */
16
+ const isValidSatsConnectWallet = (wallet) => {
17
+ var _a;
18
+ return Boolean((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => {
19
+ var _a, _b;
20
+ return config.chain === 'spark' &&
21
+ Array.isArray((_a = config.walletStandard) === null || _a === void 0 ? void 0 : _a.features) &&
22
+ config.walletStandard.features.includes(SATSCONNECT_FEATURE) &&
23
+ ((_b = config.walletStandard) === null || _b === void 0 ? void 0 : _b.providerId);
24
+ }));
25
+ };
26
+ /**
27
+ * Fetches all Spark wallet connectors that support sats-connect from the wallet book.
28
+ *
29
+ * This function scans the wallet book for wallets with Spark chain configuration
30
+ * and sats-connect support, creating connector classes for each matching wallet.
31
+ *
32
+ * @param walletBook - The wallet book schema containing all wallet configurations
33
+ * @returns Array of wallet connector constructors for sats-connect enabled Spark wallets
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const sparkConnectors = fetchSatsConnectConnectors({ walletBook });
38
+ * // Returns connectors for wallets like Xverse Spark
39
+ * ```
40
+ */
41
+ const fetchSatsConnectConnectors = ({ walletBook, }) => {
42
+ var _a;
43
+ return Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
44
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
45
+ .filter(([_, wallet]) => isValidSatsConnectWallet(wallet))
46
+ .map(([key, wallet]) => {
47
+ const { shortName } = wallet;
48
+ const name = shortName || wallet.name;
49
+ return class extends SparkSatsConnectConnector {
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ constructor(props) {
52
+ super(Object.assign(Object.assign({}, props), { overrideKey: key, walletData: wallet }));
53
+ this.name = name;
54
+ this.overrideKey = key;
55
+ }
56
+ };
57
+ });
58
+ };
59
+
60
+ export { fetchSatsConnectConnectors, isValidSatsConnectWallet };
@@ -0,0 +1 @@
1
+ export { fetchSatsConnectConnectors } from './fetchSatsConnectConnectors';
@@ -1,57 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var _tslib = require('../../../_virtual/_tslib.cjs');
7
- var walletBook = require('@dynamic-labs/wallet-book');
8
- var utils = require('@dynamic-labs/utils');
9
- var SparkWalletConnector = require('../SparkWalletConnector/SparkWalletConnector.cjs');
10
-
11
- /**
12
- * Magic Eden Spark wallet connector implementation.
13
- *
14
- * Handles Magic Eden's specific interface requirements while leveraging
15
- * the base class's flexible type handling.
16
- */
17
- class MagicEdenSparkConnector extends SparkWalletConnector.SparkWalletConnector {
18
- /**
19
- * Creates a new Magic Eden Spark connector
20
- * @param opts - Configuration options
21
- */
22
- constructor(opts) {
23
- super(opts);
24
- /** Human-readable connector name */
25
- this.name = 'Magic Eden Spark';
26
- /** Unique identifier for this connector type */
27
- this.overrideKey = 'magicedenspark';
28
- }
29
- /**
30
- * Returns the Magic Eden Spark provider from the window object
31
- * @returns The SparkProvider instance, or undefined if not available
32
- */
33
- getProvider() {
34
- const providers = utils.getProvidersFromWindow('magicEden.spark');
35
- return providers[0];
36
- }
37
- /**
38
- * Retrieves the wallet address with Magic Eden specific error handling
39
- * @returns The wallet address as a string, or undefined if unavailable
40
- */
41
- getAddress() {
42
- const _super = Object.create(null, {
43
- getAddress: { get: () => super.getAddress }
44
- });
45
- return _tslib.__awaiter(this, void 0, void 0, function* () {
46
- try {
47
- return yield _super.getAddress.call(this);
48
- }
49
- catch (error) {
50
- walletBook.logger.warn('Failed to get address from Magic Eden Spark wallet:', error);
51
- return undefined;
52
- }
53
- });
54
- }
55
- }
56
-
57
- exports.MagicEdenSparkConnector = MagicEdenSparkConnector;
@@ -1,53 +0,0 @@
1
- 'use client'
2
- import { __awaiter } from '../../../_virtual/_tslib.js';
3
- import { logger } from '@dynamic-labs/wallet-book';
4
- import { getProvidersFromWindow } from '@dynamic-labs/utils';
5
- import { SparkWalletConnector } from '../SparkWalletConnector/SparkWalletConnector.js';
6
-
7
- /**
8
- * Magic Eden Spark wallet connector implementation.
9
- *
10
- * Handles Magic Eden's specific interface requirements while leveraging
11
- * the base class's flexible type handling.
12
- */
13
- class MagicEdenSparkConnector extends SparkWalletConnector {
14
- /**
15
- * Creates a new Magic Eden Spark connector
16
- * @param opts - Configuration options
17
- */
18
- constructor(opts) {
19
- super(opts);
20
- /** Human-readable connector name */
21
- this.name = 'Magic Eden Spark';
22
- /** Unique identifier for this connector type */
23
- this.overrideKey = 'magicedenspark';
24
- }
25
- /**
26
- * Returns the Magic Eden Spark provider from the window object
27
- * @returns The SparkProvider instance, or undefined if not available
28
- */
29
- getProvider() {
30
- const providers = getProvidersFromWindow('magicEden.spark');
31
- return providers[0];
32
- }
33
- /**
34
- * Retrieves the wallet address with Magic Eden specific error handling
35
- * @returns The wallet address as a string, or undefined if unavailable
36
- */
37
- getAddress() {
38
- const _super = Object.create(null, {
39
- getAddress: { get: () => super.getAddress }
40
- });
41
- return __awaiter(this, void 0, void 0, function* () {
42
- try {
43
- return yield _super.getAddress.call(this);
44
- }
45
- catch (error) {
46
- logger.warn('Failed to get address from Magic Eden Spark wallet:', error);
47
- return undefined;
48
- }
49
- });
50
- }
51
- }
52
-
53
- export { MagicEdenSparkConnector };