@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.
Files changed (36) hide show
  1. package/CHANGELOG.md +6064 -0
  2. package/LICENSE +21 -0
  3. package/README.md +267 -0
  4. package/_virtual/_tslib.cjs +36 -0
  5. package/_virtual/_tslib.js +32 -0
  6. package/package.cjs +8 -0
  7. package/package.js +4 -0
  8. package/package.json +28 -0
  9. package/src/connectors/MagicEdenSparkConnector/MagicEdenSparkConnector.cjs +57 -0
  10. package/src/connectors/MagicEdenSparkConnector/MagicEdenSparkConnector.d.ts +29 -0
  11. package/src/connectors/MagicEdenSparkConnector/MagicEdenSparkConnector.js +53 -0
  12. package/src/connectors/MagicEdenSparkConnector/index.d.ts +1 -0
  13. package/src/connectors/SparkWalletConnector/SparkWalletConnector.cjs +247 -0
  14. package/src/connectors/SparkWalletConnector/SparkWalletConnector.d.ts +128 -0
  15. package/src/connectors/SparkWalletConnector/SparkWalletConnector.js +243 -0
  16. package/src/connectors/SparkWalletConnector/index.d.ts +1 -0
  17. package/src/connectors/index.d.ts +2 -0
  18. package/src/index.cjs +19 -0
  19. package/src/index.d.ts +6 -0
  20. package/src/index.js +13 -0
  21. package/src/types.d.ts +146 -0
  22. package/src/utils/address.cjs +27 -0
  23. package/src/utils/address.d.ts +12 -0
  24. package/src/utils/address.js +23 -0
  25. package/src/utils/connection.d.ts +9 -0
  26. package/src/utils/provider.cjs +23 -0
  27. package/src/utils/provider.d.ts +19 -0
  28. package/src/utils/provider.js +19 -0
  29. package/src/wallet/SparkWallet.cjs +42 -0
  30. package/src/wallet/SparkWallet.d.ts +20 -0
  31. package/src/wallet/SparkWallet.js +38 -0
  32. package/src/wallet/index.d.ts +2 -0
  33. package/src/wallet/isSparkWallet/index.d.ts +1 -0
  34. package/src/wallet/isSparkWallet/isSparkWallet.cjs +8 -0
  35. package/src/wallet/isSparkWallet/isSparkWallet.d.ts +3 -0
  36. package/src/wallet/isSparkWallet/isSparkWallet.js +4 -0
package/src/types.d.ts ADDED
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Global window interface extension for Spark wallet providers
3
+ */
4
+ declare global {
5
+ interface IWindowSpark {
6
+ SparkProvider: ISparkProvider;
7
+ }
8
+ interface Window {
9
+ magicEden?: {
10
+ spark: ISparkProvider;
11
+ };
12
+ }
13
+ }
14
+ /**
15
+ * Interface that all Spark wallet providers must implement.
16
+ *
17
+ * This interface defines the contract that any Spark wallet provider must fulfill
18
+ * to be compatible with the Dynamic SDK. It includes core functionality for
19
+ * connection, authentication, and transactions.
20
+ *
21
+ * ## Design Philosophy
22
+ * This interface is designed to be **flexible and extensible** while maintaining
23
+ * a consistent contract. Different wallet implementations can use different
24
+ * naming conventions and return formats without breaking compatibility.
25
+ *
26
+ * ## Flexibility Features
27
+ * - **Dual Naming Support**: Supports both `sparkAddress`/`address` naming conventions
28
+ * - **Flexible Return Types**: Methods can return different formats (objects, strings, etc.)
29
+ * - **Optional Parameters**: Advanced features like `isTaproot` are optional with sensible defaults
30
+ * - **Extensible**: Additional properties are allowed via `[key: string]: unknown`
31
+ *
32
+ * ## Usage Examples
33
+ * ```typescript
34
+ * // Magic Eden style (sparkAddress naming)
35
+ * const result = await provider.connect();
36
+ * // result can be: string | { sparkAddress: string, sparkTaprootAddress?: string }
37
+ *
38
+ * // Generic style (address naming)
39
+ * const address = await provider.getAddress();
40
+ * // address can be: string | { address: string, taprootAddress?: string }
41
+ *
42
+ * // Simple message signing
43
+ * const signature = await provider.signMessage("Hello World");
44
+ * // Advanced signing with Taproot
45
+ * const signature = await provider.signMessage({ message: "Hello", isTaproot: true });
46
+ * ```
47
+ */
48
+ export interface ISparkProvider {
49
+ /** Whether the wallet is currently connected */
50
+ isConnected: boolean;
51
+ /** The current network chain ID (e.g., '301' for mainnet) */
52
+ chainId?: string;
53
+ /** The current network name (e.g., 'mainnet', 'testnet') */
54
+ network?: string;
55
+ /**
56
+ * Establishes a connection to the wallet
57
+ * @returns Promise resolving to connection result with address information
58
+ */
59
+ connect(): Promise<SparkConnectionResult | string>;
60
+ /**
61
+ * Disconnects from the wallet
62
+ * @returns Promise that resolves when disconnected
63
+ */
64
+ disconnect(): Promise<void>;
65
+ /**
66
+ * Retrieves the current wallet address
67
+ * @returns Promise resolving to address information
68
+ */
69
+ getAddress(): Promise<SparkAddressResult>;
70
+ /**
71
+ * Signs a message for authentication
72
+ * @param message - Message to sign or signing request object
73
+ * @returns Promise resolving to signature result
74
+ */
75
+ signMessage(message: string | SparkSignMessageRequest): Promise<SparkSignatureResult>;
76
+ /**
77
+ * Signs a message using Taproot protocol
78
+ * @param message - Message to sign
79
+ * @returns Promise resolving to signature result
80
+ */
81
+ signMessageWithTaproot(message: string): Promise<SparkSignatureResult>;
82
+ /**
83
+ * Transfers Bitcoin to another Spark address
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 (defaults to false)
88
+ * @returns Promise resolving to transaction hash
89
+ */
90
+ transferBitcoin(params: {
91
+ receiverSparkAddress: string;
92
+ amountSats: bigint;
93
+ isTaproot?: boolean;
94
+ }): Promise<string>;
95
+ /**
96
+ * Transfers tokens to another Spark address
97
+ * @param params - Transfer parameters
98
+ * @param params.tokenPublicKey - The token's public key
99
+ * @param params.receiverSparkAddress - The recipient's Spark address
100
+ * @param params.tokenAmount - Amount of tokens to transfer
101
+ * @param params.isTaproot - Whether to use Taproot (defaults to false)
102
+ * @returns Promise resolving to transaction hash
103
+ */
104
+ transferTokens(params: {
105
+ tokenPublicKey: string;
106
+ receiverSparkAddress: string;
107
+ tokenAmount: number;
108
+ isTaproot?: boolean;
109
+ }): Promise<string>;
110
+ /**
111
+ * Generic RPC method for custom requests
112
+ * @param method - The RPC method name
113
+ * @param params - Optional parameters for the method
114
+ * @returns Promise resolving to the method result
115
+ */
116
+ request(method: string, params?: unknown): Promise<unknown>;
117
+ /** Additional properties that providers may implement */
118
+ [key: string]: unknown;
119
+ }
120
+ /**
121
+ * Result from wallet connection, supporting different naming conventions
122
+ */
123
+ export type SparkConnectionResult = {
124
+ sparkAddress: string;
125
+ sparkTaprootAddress?: string;
126
+ } | {
127
+ address: string;
128
+ taprootAddress?: string;
129
+ };
130
+ /**
131
+ * Result from address retrieval, supporting different formats
132
+ */
133
+ export type SparkAddressResult = SparkConnectionResult | string;
134
+ /**
135
+ * Message signing request, supporting both simple and advanced options
136
+ */
137
+ export type SparkSignMessageRequest = {
138
+ message: string;
139
+ isTaproot?: boolean;
140
+ } | string;
141
+ /**
142
+ * Result from message signing, supporting different return formats
143
+ */
144
+ export type SparkSignatureResult = {
145
+ signature: string;
146
+ } | string;
@@ -0,0 +1,27 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /**
7
+ * Utility functions for address handling
8
+ */
9
+ /**
10
+ * Extracts address from flexible address result formats
11
+ * @param addressResult - The address result from a provider
12
+ * @returns The extracted address string, or undefined if not found
13
+ */
14
+ const extractAddress = (addressResult) => {
15
+ if (!addressResult) {
16
+ return undefined;
17
+ }
18
+ if (typeof addressResult === 'string') {
19
+ return addressResult;
20
+ }
21
+ if (typeof addressResult === 'object') {
22
+ return addressResult.sparkAddress || addressResult.address;
23
+ }
24
+ return undefined;
25
+ };
26
+
27
+ exports.extractAddress = extractAddress;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Utility functions for address handling
3
+ */
4
+ /**
5
+ * Extracts address from flexible address result formats
6
+ * @param addressResult - The address result from a provider
7
+ * @returns The extracted address string, or undefined if not found
8
+ */
9
+ export declare const extractAddress: (addressResult: string | {
10
+ sparkAddress?: string;
11
+ address?: string;
12
+ }) => string | undefined;
@@ -0,0 +1,23 @@
1
+ 'use client'
2
+ /**
3
+ * Utility functions for address handling
4
+ */
5
+ /**
6
+ * Extracts address from flexible address result formats
7
+ * @param addressResult - The address result from a provider
8
+ * @returns The extracted address string, or undefined if not found
9
+ */
10
+ const extractAddress = (addressResult) => {
11
+ if (!addressResult) {
12
+ return undefined;
13
+ }
14
+ if (typeof addressResult === 'string') {
15
+ return addressResult;
16
+ }
17
+ if (typeof addressResult === 'object') {
18
+ return addressResult.sparkAddress || addressResult.address;
19
+ }
20
+ return undefined;
21
+ };
22
+
23
+ export { extractAddress };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Utility functions for connection result processing
3
+ */
4
+ /**
5
+ * Extracts address from connection result objects
6
+ * @param connectResult - The result from a provider's connect() method
7
+ * @returns The extracted address string, or undefined if not found
8
+ */
9
+ export declare const extractConnectionAddress: (connectResult: unknown) => string | undefined;
@@ -0,0 +1,23 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /**
7
+ * Utility functions for provider validation and error handling
8
+ */
9
+ /**
10
+ * Asserts that a provider is available and throws an error if not
11
+ * @param provider - The provider to validate
12
+ * @param providerName - Human-readable name for error messages
13
+ * @returns The validated provider
14
+ * @throws {Error} If provider is not available
15
+ */
16
+ const assertProvider = (provider, providerName) => {
17
+ if (!provider) {
18
+ throw new Error(`${providerName} provider not available`);
19
+ }
20
+ return provider;
21
+ };
22
+
23
+ exports.assertProvider = assertProvider;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Utility functions for provider validation and error handling
3
+ */
4
+ /**
5
+ * Asserts that a provider is available and throws an error if not
6
+ * @param provider - The provider to validate
7
+ * @param providerName - Human-readable name for error messages
8
+ * @returns The validated provider
9
+ * @throws {Error} If provider is not available
10
+ */
11
+ export declare const assertProvider: <T>(provider: T | undefined, providerName: string) => T;
12
+ /**
13
+ * Creates a standardized error message for provider operations
14
+ * @param operation - The operation that failed (e.g., 'connect', 'sign message')
15
+ * @param providerName - The name of the provider
16
+ * @param error - The original error
17
+ * @returns A new Error with formatted message
18
+ */
19
+ export declare const createProviderError: (operation: string, providerName: string, error: unknown) => Error;
@@ -0,0 +1,19 @@
1
+ 'use client'
2
+ /**
3
+ * Utility functions for provider validation and error handling
4
+ */
5
+ /**
6
+ * Asserts that a provider is available and throws an error if not
7
+ * @param provider - The provider to validate
8
+ * @param providerName - Human-readable name for error messages
9
+ * @returns The validated provider
10
+ * @throws {Error} If provider is not available
11
+ */
12
+ const assertProvider = (provider, providerName) => {
13
+ if (!provider) {
14
+ throw new Error(`${providerName} provider not available`);
15
+ }
16
+ return provider;
17
+ };
18
+
19
+ export { assertProvider };
@@ -0,0 +1,42 @@
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
+
9
+ class SparkWallet extends walletConnectorCore.Wallet {
10
+ sendBalance(_a) {
11
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, isTaproot, }) {
12
+ return this.transferBitcoin({
13
+ amount,
14
+ isTaproot,
15
+ toAddress,
16
+ });
17
+ });
18
+ }
19
+ transferBitcoin(_a) {
20
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, isTaproot, }) {
21
+ yield this.sync();
22
+ return this._connector.transferBitcoin({
23
+ amountSats: BigInt(amount),
24
+ isTaproot,
25
+ receiverSparkAddress: toAddress,
26
+ });
27
+ });
28
+ }
29
+ transferTokens(_a) {
30
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ tokenPublicKey, receiverSparkAddress, tokenAmount, isTaproot, }) {
31
+ yield this.sync();
32
+ return this._connector.transferTokens({
33
+ isTaproot,
34
+ receiverSparkAddress,
35
+ tokenAmount,
36
+ tokenPublicKey,
37
+ });
38
+ });
39
+ }
40
+ }
41
+
42
+ exports.SparkWallet = SparkWallet;
@@ -0,0 +1,20 @@
1
+ import { Wallet } from '@dynamic-labs/wallet-connector-core';
2
+ import type { SparkWalletConnector } from '../connectors/SparkWalletConnector';
3
+ export declare class SparkWallet extends Wallet<SparkWalletConnector> {
4
+ sendBalance({ amount, toAddress, isTaproot, }: {
5
+ amount: string;
6
+ toAddress: string;
7
+ isTaproot?: boolean;
8
+ }): Promise<string | undefined>;
9
+ transferBitcoin({ amount, toAddress, isTaproot, }: {
10
+ amount: string;
11
+ toAddress: string;
12
+ isTaproot?: boolean;
13
+ }): Promise<string | undefined>;
14
+ transferTokens({ tokenPublicKey, receiverSparkAddress, tokenAmount, isTaproot, }: {
15
+ tokenPublicKey: string;
16
+ receiverSparkAddress: string;
17
+ tokenAmount: number;
18
+ isTaproot?: boolean;
19
+ }): Promise<string | undefined>;
20
+ }
@@ -0,0 +1,38 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../_virtual/_tslib.js';
3
+ import { Wallet } from '@dynamic-labs/wallet-connector-core';
4
+
5
+ class SparkWallet extends Wallet {
6
+ sendBalance(_a) {
7
+ return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, isTaproot, }) {
8
+ return this.transferBitcoin({
9
+ amount,
10
+ isTaproot,
11
+ toAddress,
12
+ });
13
+ });
14
+ }
15
+ transferBitcoin(_a) {
16
+ return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, isTaproot, }) {
17
+ yield this.sync();
18
+ return this._connector.transferBitcoin({
19
+ amountSats: BigInt(amount),
20
+ isTaproot,
21
+ receiverSparkAddress: toAddress,
22
+ });
23
+ });
24
+ }
25
+ transferTokens(_a) {
26
+ return __awaiter(this, arguments, void 0, function* ({ tokenPublicKey, receiverSparkAddress, tokenAmount, isTaproot, }) {
27
+ yield this.sync();
28
+ return this._connector.transferTokens({
29
+ isTaproot,
30
+ receiverSparkAddress,
31
+ tokenAmount,
32
+ tokenPublicKey,
33
+ });
34
+ });
35
+ }
36
+ }
37
+
38
+ export { SparkWallet };
@@ -0,0 +1,2 @@
1
+ export { SparkWallet } from './SparkWallet';
2
+ export * from './isSparkWallet';
@@ -0,0 +1 @@
1
+ export * from './isSparkWallet';
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const isSparkWallet = (wallet) => wallet.chain === 'SPARK';
7
+
8
+ exports.isSparkWallet = isSparkWallet;
@@ -0,0 +1,3 @@
1
+ import { Wallet } from '@dynamic-labs/wallet-connector-core';
2
+ import type { SparkWalletConnector } from '../../connectors/SparkWalletConnector';
3
+ export declare const isSparkWallet: (wallet: Wallet) => wallet is Wallet<SparkWalletConnector>;
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const isSparkWallet = (wallet) => wallet.chain === 'SPARK';
3
+
4
+ export { isSparkWallet };