@dynamic-labs/spark 4.30.0
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 +6064 -0
- package/LICENSE +21 -0
- package/README.md +267 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.cjs +8 -0
- package/package.js +4 -0
- package/package.json +28 -0
- package/src/connectors/MagicEdenSparkConnector/MagicEdenSparkConnector.cjs +57 -0
- package/src/connectors/MagicEdenSparkConnector/MagicEdenSparkConnector.d.ts +29 -0
- package/src/connectors/MagicEdenSparkConnector/MagicEdenSparkConnector.js +53 -0
- package/src/connectors/MagicEdenSparkConnector/index.d.ts +1 -0
- package/src/connectors/SparkWalletConnector/SparkWalletConnector.cjs +247 -0
- package/src/connectors/SparkWalletConnector/SparkWalletConnector.d.ts +128 -0
- package/src/connectors/SparkWalletConnector/SparkWalletConnector.js +243 -0
- package/src/connectors/SparkWalletConnector/index.d.ts +1 -0
- package/src/connectors/index.d.ts +2 -0
- package/src/index.cjs +19 -0
- package/src/index.d.ts +6 -0
- package/src/index.js +13 -0
- package/src/types.d.ts +146 -0
- package/src/utils/address.cjs +27 -0
- package/src/utils/address.d.ts +12 -0
- package/src/utils/address.js +23 -0
- package/src/utils/connection.d.ts +9 -0
- package/src/utils/provider.cjs +23 -0
- package/src/utils/provider.d.ts +19 -0
- package/src/utils/provider.js +19 -0
- package/src/wallet/SparkWallet.cjs +42 -0
- package/src/wallet/SparkWallet.d.ts +20 -0
- package/src/wallet/SparkWallet.js +38 -0
- package/src/wallet/index.d.ts +2 -0
- package/src/wallet/isSparkWallet/index.d.ts +1 -0
- package/src/wallet/isSparkWallet/isSparkWallet.cjs +8 -0
- package/src/wallet/isSparkWallet/isSparkWallet.d.ts +3 -0
- package/src/wallet/isSparkWallet/isSparkWallet.js +4 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
var provider = require('../../utils/provider.cjs');
|
|
9
|
+
var address = require('../../utils/address.cjs');
|
|
10
|
+
var SparkWallet = require('../../wallet/SparkWallet.cjs');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Abstract base class for all Spark wallet connectors.
|
|
14
|
+
*
|
|
15
|
+
* Provides complete Dynamic SDK wallet connector implementation for Spark wallets.
|
|
16
|
+
* Concrete connectors only need to implement `getProvider()`.
|
|
17
|
+
*/
|
|
18
|
+
class SparkWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new Spark wallet connector
|
|
21
|
+
* @param opts - Configuration options
|
|
22
|
+
*/
|
|
23
|
+
constructor(opts) {
|
|
24
|
+
super(opts);
|
|
25
|
+
/** The wallet class to instantiate */
|
|
26
|
+
this.ChainWallet = SparkWallet.SparkWallet;
|
|
27
|
+
/** Human-readable connector name */
|
|
28
|
+
this.name = 'Spark';
|
|
29
|
+
/** Unique identifier for this connector type */
|
|
30
|
+
this.overrideKey = 'injectedspark';
|
|
31
|
+
/** The blockchain this connector supports */
|
|
32
|
+
this.connectedChain = 'SPARK';
|
|
33
|
+
/** All supported blockchain types */
|
|
34
|
+
this.supportedChains = ['SPARK'];
|
|
35
|
+
this.sparkNetworks = opts.sparkNetworks || [];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Establishes a connection to the Spark wallet
|
|
39
|
+
* @throws {Error} If no Spark provider is available
|
|
40
|
+
*/
|
|
41
|
+
connect() {
|
|
42
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const provider$1 = provider.assertProvider(this.getProvider(), 'Spark');
|
|
44
|
+
if (provider$1.connect) {
|
|
45
|
+
yield provider$1.connect();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Ends the current wallet session
|
|
51
|
+
*/
|
|
52
|
+
endSession() {
|
|
53
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
try {
|
|
55
|
+
const provider$1 = provider.assertProvider(this.getProvider(), 'Spark');
|
|
56
|
+
if (provider$1 === null || provider$1 === void 0 ? void 0 : provider$1.disconnect) {
|
|
57
|
+
yield provider$1.disconnect();
|
|
58
|
+
}
|
|
59
|
+
this.emit('disconnect');
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
walletConnectorCore.logger.error('Failed to disconnect Spark wallet:', error);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves the current wallet address
|
|
68
|
+
* @returns The wallet address as a string, or undefined if unavailable
|
|
69
|
+
*/
|
|
70
|
+
getAddress() {
|
|
71
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
try {
|
|
73
|
+
const provider$1 = provider.assertProvider(this.getProvider(), 'Spark');
|
|
74
|
+
if (provider$1.getAddress) {
|
|
75
|
+
const addressResult = yield provider$1.getAddress();
|
|
76
|
+
const address$1 = address.extractAddress(addressResult);
|
|
77
|
+
if (address$1) {
|
|
78
|
+
return address$1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
throw new Error('No address available from Spark provider');
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
walletConnectorCore.logger.error('Failed to get Spark address:', error);
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Gets the current network chain ID
|
|
91
|
+
* @returns The network chain ID as a string (defaults to mainnet '301')
|
|
92
|
+
*/
|
|
93
|
+
getNetwork() {
|
|
94
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
// MagicEden and XVerse are only supporting mainnet at the moment
|
|
96
|
+
// This should be expanded is anyone ever supports testnet or regtest
|
|
97
|
+
// We can detect netowrk using addresses in the future if we want
|
|
98
|
+
return '301';
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns all enabled Spark networks for this connector
|
|
103
|
+
* @returns Array of GenericNetwork configurations
|
|
104
|
+
*/
|
|
105
|
+
getEnabledNetworks() {
|
|
106
|
+
return this.sparkNetworks;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Attempts to switch to a different network
|
|
110
|
+
* @note Spark wallets do not support dynamic network switching
|
|
111
|
+
*/
|
|
112
|
+
switchNetwork() {
|
|
113
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
walletConnectorCore.logger.warn('Spark wallet does not support dynamic network switching');
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets block explorer URLs for the current network
|
|
119
|
+
* @returns Array of block explorer URLs (defaults to mempool.space)
|
|
120
|
+
*/
|
|
121
|
+
getBlockExplorerUrlsForCurrentNetwork() {
|
|
122
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
try {
|
|
124
|
+
const chainId = yield this.getNetwork();
|
|
125
|
+
const networkConfig = this.sparkNetworks.find((n) => n.chainId === chainId);
|
|
126
|
+
return (networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.blockExplorerUrls) || ['https://mempool.space/'];
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
walletConnectorCore.logger.warn('Failed to get block explorer URLs, using default:', error);
|
|
130
|
+
return ['https://mempool.space/'];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Signs a message using the connected wallet
|
|
136
|
+
* @param message - The message to sign or signing request object
|
|
137
|
+
* @returns The signature as a string, or undefined if signing fails
|
|
138
|
+
*/
|
|
139
|
+
signMessage(message) {
|
|
140
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
var _a;
|
|
142
|
+
try {
|
|
143
|
+
if (!message) {
|
|
144
|
+
throw new Error('Message is required for signing');
|
|
145
|
+
}
|
|
146
|
+
const provider$1 = provider.assertProvider(this.getProvider(), 'Spark');
|
|
147
|
+
if (!provider$1.signMessage) {
|
|
148
|
+
throw new Error('Message signing not supported by Spark provider');
|
|
149
|
+
}
|
|
150
|
+
// Extract message and isTaproot with defaults
|
|
151
|
+
const messageToSign = typeof message === 'string' ? message : message.message;
|
|
152
|
+
const isTaproot = typeof message === 'object' ? (_a = message.isTaproot) !== null && _a !== void 0 ? _a : false : false;
|
|
153
|
+
const result = yield provider$1.signMessage({
|
|
154
|
+
isTaproot,
|
|
155
|
+
message: messageToSign,
|
|
156
|
+
});
|
|
157
|
+
// Handle different return formats
|
|
158
|
+
if (result && typeof result === 'object' && 'signature' in result) {
|
|
159
|
+
return result.signature;
|
|
160
|
+
}
|
|
161
|
+
if (typeof result === 'string') {
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
throw new Error('Unexpected signature format from provider');
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
walletConnectorCore.logger.error('Failed to sign message with Spark wallet:', error);
|
|
168
|
+
throw new Error(`Failed to sign message with Spark wallet: ${error instanceof Error ? error.message : String(error)}`);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Signs a message using Taproot protocol
|
|
174
|
+
* @param message - The message to sign
|
|
175
|
+
* @returns Promise resolving to signature result
|
|
176
|
+
*/
|
|
177
|
+
signMessageWithTaproot(message) {
|
|
178
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
return this.signMessage({
|
|
180
|
+
isTaproot: true, // Always use Taproot for this method
|
|
181
|
+
message: message,
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Transfers Bitcoin to another Spark address
|
|
187
|
+
* @param params - Transfer parameters
|
|
188
|
+
* @returns Promise resolving to transaction hash
|
|
189
|
+
*/
|
|
190
|
+
transferBitcoin(params) {
|
|
191
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
try {
|
|
193
|
+
const provider$1 = provider.assertProvider(this.getProvider(), 'Spark');
|
|
194
|
+
if (!provider$1.transferBitcoin) {
|
|
195
|
+
throw new Error('Bitcoin transfer not supported by Spark provider');
|
|
196
|
+
}
|
|
197
|
+
const txHash = yield provider$1.transferBitcoin(params);
|
|
198
|
+
return txHash;
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
walletConnectorCore.logger.error('Failed to transfer Bitcoin using Spark wallet:', error);
|
|
202
|
+
throw new Error(`Failed to transfer Bitcoin using Spark wallet: ${error instanceof Error ? error.message : String(error)}`);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Transfers tokens to another Spark address
|
|
208
|
+
* @param params - Transfer parameters
|
|
209
|
+
* @returns Promise resolving to transaction hash
|
|
210
|
+
*/
|
|
211
|
+
transferTokens(params) {
|
|
212
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
try {
|
|
214
|
+
const provider$1 = provider.assertProvider(this.getProvider(), 'Spark');
|
|
215
|
+
if (!provider$1.transferTokens) {
|
|
216
|
+
throw new Error('Token transfer not supported by Spark provider');
|
|
217
|
+
}
|
|
218
|
+
const txHash = yield provider$1.transferTokens(params);
|
|
219
|
+
return txHash;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
walletConnectorCore.logger.error('Failed to transfer tokens using Spark wallet:', error);
|
|
223
|
+
throw new Error(`Failed to transfer tokens using Spark wallet: ${error instanceof Error ? error.message : String(error)}`);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Proves ownership of a wallet address by signing a message
|
|
229
|
+
* @param address - The address to prove ownership of
|
|
230
|
+
* @param messageToSign - The message to sign for authentication
|
|
231
|
+
* @returns The signature as a string, or undefined if authentication fails
|
|
232
|
+
*/
|
|
233
|
+
proveOwnership(_address, messageToSign) {
|
|
234
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
return this.signMessage(messageToSign);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Checks if the Spark wallet is installed in the browser
|
|
240
|
+
* @returns True if a provider is available, false otherwise
|
|
241
|
+
*/
|
|
242
|
+
isInstalledOnBrowser() {
|
|
243
|
+
return Boolean(this.getProvider());
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
exports.SparkWalletConnector = SparkWalletConnector;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
2
|
+
import { Chain, WalletConnectorBase, WalletMetadata } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { GenericNetwork } from '@dynamic-labs/types';
|
|
4
|
+
import type { ISparkProvider } from '../../types';
|
|
5
|
+
import { SparkWallet } from '../../wallet/SparkWallet';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for Spark wallet connectors
|
|
8
|
+
*/
|
|
9
|
+
export type SparkWalletConnectorOpts = {
|
|
10
|
+
/** Wallet book schema for metadata */
|
|
11
|
+
walletBook: WalletBookSchema;
|
|
12
|
+
/** Optional wallet metadata */
|
|
13
|
+
metadata?: WalletMetadata;
|
|
14
|
+
/** Custom Spark networks configuration */
|
|
15
|
+
sparkNetworks?: GenericNetwork[];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Abstract base class for all Spark wallet connectors.
|
|
19
|
+
*
|
|
20
|
+
* Provides complete Dynamic SDK wallet connector implementation for Spark wallets.
|
|
21
|
+
* Concrete connectors only need to implement `getProvider()`.
|
|
22
|
+
*/
|
|
23
|
+
export declare abstract class SparkWalletConnector extends WalletConnectorBase<typeof SparkWallet> {
|
|
24
|
+
/** The wallet class to instantiate */
|
|
25
|
+
ChainWallet: typeof SparkWallet;
|
|
26
|
+
/** Human-readable connector name */
|
|
27
|
+
name: string;
|
|
28
|
+
/** Unique identifier for this connector type */
|
|
29
|
+
overrideKey: string;
|
|
30
|
+
/** The blockchain this connector supports */
|
|
31
|
+
connectedChain: Chain;
|
|
32
|
+
/** All supported blockchain types */
|
|
33
|
+
supportedChains: Chain[];
|
|
34
|
+
/** Available Spark networks for this connector */
|
|
35
|
+
protected sparkNetworks: GenericNetwork[];
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new Spark wallet connector
|
|
38
|
+
* @param opts - Configuration options
|
|
39
|
+
*/
|
|
40
|
+
constructor(opts: SparkWalletConnectorOpts);
|
|
41
|
+
/**
|
|
42
|
+
* Establishes a connection to the Spark wallet
|
|
43
|
+
* @throws {Error} If no Spark provider is available
|
|
44
|
+
*/
|
|
45
|
+
connect(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Ends the current wallet session
|
|
48
|
+
*/
|
|
49
|
+
endSession(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves the current wallet address
|
|
52
|
+
* @returns The wallet address as a string, or undefined if unavailable
|
|
53
|
+
*/
|
|
54
|
+
getAddress(): Promise<string | undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* Gets the current network chain ID
|
|
57
|
+
* @returns The network chain ID as a string (defaults to mainnet '301')
|
|
58
|
+
*/
|
|
59
|
+
getNetwork(): Promise<string | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Returns all enabled Spark networks for this connector
|
|
62
|
+
* @returns Array of GenericNetwork configurations
|
|
63
|
+
*/
|
|
64
|
+
getEnabledNetworks(): GenericNetwork[];
|
|
65
|
+
/**
|
|
66
|
+
* Attempts to switch to a different network
|
|
67
|
+
* @note Spark wallets do not support dynamic network switching
|
|
68
|
+
*/
|
|
69
|
+
switchNetwork(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Gets block explorer URLs for the current network
|
|
72
|
+
* @returns Array of block explorer URLs (defaults to mempool.space)
|
|
73
|
+
*/
|
|
74
|
+
getBlockExplorerUrlsForCurrentNetwork(): Promise<string[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Signs a message using the connected wallet
|
|
77
|
+
* @param message - The message to sign or signing request object
|
|
78
|
+
* @returns The signature as a string, or undefined if signing fails
|
|
79
|
+
*/
|
|
80
|
+
signMessage(message: string | {
|
|
81
|
+
message: string;
|
|
82
|
+
isTaproot?: boolean;
|
|
83
|
+
}): Promise<string | undefined>;
|
|
84
|
+
/**
|
|
85
|
+
* Signs a message using Taproot protocol
|
|
86
|
+
* @param message - The message to sign
|
|
87
|
+
* @returns Promise resolving to signature result
|
|
88
|
+
*/
|
|
89
|
+
signMessageWithTaproot(message: string): Promise<string | undefined>;
|
|
90
|
+
/**
|
|
91
|
+
* Transfers Bitcoin to another Spark address
|
|
92
|
+
* @param params - Transfer parameters
|
|
93
|
+
* @returns Promise resolving to transaction hash
|
|
94
|
+
*/
|
|
95
|
+
transferBitcoin(params: {
|
|
96
|
+
receiverSparkAddress: string;
|
|
97
|
+
amountSats: bigint;
|
|
98
|
+
isTaproot?: boolean;
|
|
99
|
+
}): Promise<string | undefined>;
|
|
100
|
+
/**
|
|
101
|
+
* Transfers tokens to another Spark address
|
|
102
|
+
* @param params - Transfer parameters
|
|
103
|
+
* @returns Promise resolving to transaction hash
|
|
104
|
+
*/
|
|
105
|
+
transferTokens(params: {
|
|
106
|
+
tokenPublicKey: string;
|
|
107
|
+
receiverSparkAddress: string;
|
|
108
|
+
tokenAmount: number;
|
|
109
|
+
isTaproot?: boolean;
|
|
110
|
+
}): Promise<string | undefined>;
|
|
111
|
+
/**
|
|
112
|
+
* Proves ownership of a wallet address by signing a message
|
|
113
|
+
* @param address - The address to prove ownership of
|
|
114
|
+
* @param messageToSign - The message to sign for authentication
|
|
115
|
+
* @returns The signature as a string, or undefined if authentication fails
|
|
116
|
+
*/
|
|
117
|
+
proveOwnership(_address: string, messageToSign: string): Promise<string | undefined>;
|
|
118
|
+
/**
|
|
119
|
+
* Checks if the Spark wallet is installed in the browser
|
|
120
|
+
* @returns True if a provider is available, false otherwise
|
|
121
|
+
*/
|
|
122
|
+
isInstalledOnBrowser(): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Abstract method that concrete connectors must implement
|
|
125
|
+
* @returns The Spark provider instance, or undefined if not available
|
|
126
|
+
*/
|
|
127
|
+
abstract getProvider(): ISparkProvider | undefined;
|
|
128
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { WalletConnectorBase, logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { assertProvider } from '../../utils/provider.js';
|
|
5
|
+
import { extractAddress } from '../../utils/address.js';
|
|
6
|
+
import { SparkWallet } from '../../wallet/SparkWallet.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Abstract base class for all Spark wallet connectors.
|
|
10
|
+
*
|
|
11
|
+
* Provides complete Dynamic SDK wallet connector implementation for Spark wallets.
|
|
12
|
+
* Concrete connectors only need to implement `getProvider()`.
|
|
13
|
+
*/
|
|
14
|
+
class SparkWalletConnector extends WalletConnectorBase {
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new Spark wallet connector
|
|
17
|
+
* @param opts - Configuration options
|
|
18
|
+
*/
|
|
19
|
+
constructor(opts) {
|
|
20
|
+
super(opts);
|
|
21
|
+
/** The wallet class to instantiate */
|
|
22
|
+
this.ChainWallet = SparkWallet;
|
|
23
|
+
/** Human-readable connector name */
|
|
24
|
+
this.name = 'Spark';
|
|
25
|
+
/** Unique identifier for this connector type */
|
|
26
|
+
this.overrideKey = 'injectedspark';
|
|
27
|
+
/** The blockchain this connector supports */
|
|
28
|
+
this.connectedChain = 'SPARK';
|
|
29
|
+
/** All supported blockchain types */
|
|
30
|
+
this.supportedChains = ['SPARK'];
|
|
31
|
+
this.sparkNetworks = opts.sparkNetworks || [];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Establishes a connection to the Spark wallet
|
|
35
|
+
* @throws {Error} If no Spark provider is available
|
|
36
|
+
*/
|
|
37
|
+
connect() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const provider = assertProvider(this.getProvider(), 'Spark');
|
|
40
|
+
if (provider.connect) {
|
|
41
|
+
yield provider.connect();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Ends the current wallet session
|
|
47
|
+
*/
|
|
48
|
+
endSession() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
try {
|
|
51
|
+
const provider = assertProvider(this.getProvider(), 'Spark');
|
|
52
|
+
if (provider === null || provider === void 0 ? void 0 : provider.disconnect) {
|
|
53
|
+
yield provider.disconnect();
|
|
54
|
+
}
|
|
55
|
+
this.emit('disconnect');
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger.error('Failed to disconnect Spark wallet:', error);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves the current wallet address
|
|
64
|
+
* @returns The wallet address as a string, or undefined if unavailable
|
|
65
|
+
*/
|
|
66
|
+
getAddress() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
try {
|
|
69
|
+
const provider = assertProvider(this.getProvider(), 'Spark');
|
|
70
|
+
if (provider.getAddress) {
|
|
71
|
+
const addressResult = yield provider.getAddress();
|
|
72
|
+
const address = extractAddress(addressResult);
|
|
73
|
+
if (address) {
|
|
74
|
+
return address;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
throw new Error('No address available from Spark provider');
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
logger.error('Failed to get Spark address:', error);
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets the current network chain ID
|
|
87
|
+
* @returns The network chain ID as a string (defaults to mainnet '301')
|
|
88
|
+
*/
|
|
89
|
+
getNetwork() {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
// MagicEden and XVerse are only supporting mainnet at the moment
|
|
92
|
+
// This should be expanded is anyone ever supports testnet or regtest
|
|
93
|
+
// We can detect netowrk using addresses in the future if we want
|
|
94
|
+
return '301';
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns all enabled Spark networks for this connector
|
|
99
|
+
* @returns Array of GenericNetwork configurations
|
|
100
|
+
*/
|
|
101
|
+
getEnabledNetworks() {
|
|
102
|
+
return this.sparkNetworks;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Attempts to switch to a different network
|
|
106
|
+
* @note Spark wallets do not support dynamic network switching
|
|
107
|
+
*/
|
|
108
|
+
switchNetwork() {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
logger.warn('Spark wallet does not support dynamic network switching');
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Gets block explorer URLs for the current network
|
|
115
|
+
* @returns Array of block explorer URLs (defaults to mempool.space)
|
|
116
|
+
*/
|
|
117
|
+
getBlockExplorerUrlsForCurrentNetwork() {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
try {
|
|
120
|
+
const chainId = yield this.getNetwork();
|
|
121
|
+
const networkConfig = this.sparkNetworks.find((n) => n.chainId === chainId);
|
|
122
|
+
return (networkConfig === null || networkConfig === void 0 ? void 0 : networkConfig.blockExplorerUrls) || ['https://mempool.space/'];
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
logger.warn('Failed to get block explorer URLs, using default:', error);
|
|
126
|
+
return ['https://mempool.space/'];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Signs a message using the connected wallet
|
|
132
|
+
* @param message - The message to sign or signing request object
|
|
133
|
+
* @returns The signature as a string, or undefined if signing fails
|
|
134
|
+
*/
|
|
135
|
+
signMessage(message) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
var _a;
|
|
138
|
+
try {
|
|
139
|
+
if (!message) {
|
|
140
|
+
throw new Error('Message is required for signing');
|
|
141
|
+
}
|
|
142
|
+
const provider = assertProvider(this.getProvider(), 'Spark');
|
|
143
|
+
if (!provider.signMessage) {
|
|
144
|
+
throw new Error('Message signing not supported by Spark provider');
|
|
145
|
+
}
|
|
146
|
+
// Extract message and isTaproot with defaults
|
|
147
|
+
const messageToSign = typeof message === 'string' ? message : message.message;
|
|
148
|
+
const isTaproot = typeof message === 'object' ? (_a = message.isTaproot) !== null && _a !== void 0 ? _a : false : false;
|
|
149
|
+
const result = yield provider.signMessage({
|
|
150
|
+
isTaproot,
|
|
151
|
+
message: messageToSign,
|
|
152
|
+
});
|
|
153
|
+
// Handle different return formats
|
|
154
|
+
if (result && typeof result === 'object' && 'signature' in result) {
|
|
155
|
+
return result.signature;
|
|
156
|
+
}
|
|
157
|
+
if (typeof result === 'string') {
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
throw new Error('Unexpected signature format from provider');
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
logger.error('Failed to sign message with Spark wallet:', error);
|
|
164
|
+
throw new Error(`Failed to sign message with Spark wallet: ${error instanceof Error ? error.message : String(error)}`);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Signs a message using Taproot protocol
|
|
170
|
+
* @param message - The message to sign
|
|
171
|
+
* @returns Promise resolving to signature result
|
|
172
|
+
*/
|
|
173
|
+
signMessageWithTaproot(message) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
return this.signMessage({
|
|
176
|
+
isTaproot: true, // Always use Taproot for this method
|
|
177
|
+
message: message,
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Transfers Bitcoin to another Spark address
|
|
183
|
+
* @param params - Transfer parameters
|
|
184
|
+
* @returns Promise resolving to transaction hash
|
|
185
|
+
*/
|
|
186
|
+
transferBitcoin(params) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
try {
|
|
189
|
+
const provider = assertProvider(this.getProvider(), 'Spark');
|
|
190
|
+
if (!provider.transferBitcoin) {
|
|
191
|
+
throw new Error('Bitcoin transfer not supported by Spark provider');
|
|
192
|
+
}
|
|
193
|
+
const txHash = yield provider.transferBitcoin(params);
|
|
194
|
+
return txHash;
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
logger.error('Failed to transfer Bitcoin using Spark wallet:', error);
|
|
198
|
+
throw new Error(`Failed to transfer Bitcoin using Spark wallet: ${error instanceof Error ? error.message : String(error)}`);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Transfers tokens to another Spark address
|
|
204
|
+
* @param params - Transfer parameters
|
|
205
|
+
* @returns Promise resolving to transaction hash
|
|
206
|
+
*/
|
|
207
|
+
transferTokens(params) {
|
|
208
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
try {
|
|
210
|
+
const provider = assertProvider(this.getProvider(), 'Spark');
|
|
211
|
+
if (!provider.transferTokens) {
|
|
212
|
+
throw new Error('Token transfer not supported by Spark provider');
|
|
213
|
+
}
|
|
214
|
+
const txHash = yield provider.transferTokens(params);
|
|
215
|
+
return txHash;
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
logger.error('Failed to transfer tokens using Spark wallet:', error);
|
|
219
|
+
throw new Error(`Failed to transfer tokens using Spark wallet: ${error instanceof Error ? error.message : String(error)}`);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Proves ownership of a wallet address by signing a message
|
|
225
|
+
* @param address - The address to prove ownership of
|
|
226
|
+
* @param messageToSign - The message to sign for authentication
|
|
227
|
+
* @returns The signature as a string, or undefined if authentication fails
|
|
228
|
+
*/
|
|
229
|
+
proveOwnership(_address, messageToSign) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
return this.signMessage(messageToSign);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Checks if the Spark wallet is installed in the browser
|
|
236
|
+
* @returns True if a provider is available, false otherwise
|
|
237
|
+
*/
|
|
238
|
+
isInstalledOnBrowser() {
|
|
239
|
+
return Boolean(this.getProvider());
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export { SparkWalletConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SparkWalletConnector';
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
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');
|
|
12
|
+
var isSparkWallet = require('./wallet/isSparkWallet/isSparkWallet.cjs');
|
|
13
|
+
|
|
14
|
+
assertPackageVersion.assertPackageVersion('@dynamic-labs/spark', _package.version);
|
|
15
|
+
const SparkWalletConnectors = () => [MagicEdenSparkConnector.MagicEdenSparkConnector];
|
|
16
|
+
|
|
17
|
+
exports.SparkWallet = SparkWallet.SparkWallet;
|
|
18
|
+
exports.isSparkWallet = isSparkWallet.isSparkWallet;
|
|
19
|
+
exports.SparkWalletConnectors = SparkWalletConnectors;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MagicEdenSparkConnector } from './connectors';
|
|
2
|
+
export { type ISparkProvider } from './types';
|
|
3
|
+
export { type SparkWalletConnector } from './connectors/SparkWalletConnector';
|
|
4
|
+
export { isSparkWallet } from './wallet/isSparkWallet';
|
|
5
|
+
export { SparkWallet } from './wallet/SparkWallet';
|
|
6
|
+
export declare const SparkWalletConnectors: () => (typeof MagicEdenSparkConnector)[];
|
package/src/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
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';
|
|
8
|
+
export { isSparkWallet } from './wallet/isSparkWallet/isSparkWallet.js';
|
|
9
|
+
|
|
10
|
+
assertPackageVersion('@dynamic-labs/spark', version);
|
|
11
|
+
const SparkWalletConnectors = () => [MagicEdenSparkConnector];
|
|
12
|
+
|
|
13
|
+
export { SparkWalletConnectors };
|