@buildonspark/issuer-sdk 0.0.84 → 0.0.85
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 +14 -0
- package/dist/chunk-HOLMXKFE.js +663 -0
- package/dist/index.cjs +61 -64
- package/dist/index.d.cts +8 -156
- package/dist/index.d.ts +8 -156
- package/dist/index.js +13 -669
- package/dist/index.node.cjs +708 -0
- package/dist/index.node.d.cts +14 -0
- package/dist/index.node.d.ts +14 -0
- package/dist/index.node.js +34 -0
- package/dist/issuer-spark-wallet-BFzkv4X5.d.cts +164 -0
- package/dist/issuer-spark-wallet-BFzkv4X5.d.ts +164 -0
- package/package.json +23 -5
- package/src/index.node.ts +2 -0
- package/src/index.ts +1 -1
- package/src/issuer-wallet/issuer-spark-wallet.browser.ts +33 -0
- package/src/issuer-wallet/issuer-spark-wallet.node.ts +33 -0
- package/src/issuer-wallet/issuer-spark-wallet.ts +46 -66
- package/src/tests/integration/spark.test.ts +405 -323
- package/src/tests/stress/transfers.test.ts +12 -19
- package/src/tests/utils/issuer-test-wallet.ts +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { I as IssuerSparkWallet } from './issuer-spark-wallet-BFzkv4X5.cjs';
|
|
2
|
+
export { a as IssuerTokenMetadata, T as TokenDistribution } from './issuer-spark-wallet-BFzkv4X5.cjs';
|
|
3
|
+
import { SparkWalletProps } from '@buildonspark/spark-sdk';
|
|
4
|
+
import '@buildonspark/spark-sdk/proto/spark';
|
|
5
|
+
|
|
6
|
+
declare class IssuerSparkWalletNodeJS extends IssuerSparkWallet {
|
|
7
|
+
static initialize({ mnemonicOrSeed, accountNumber, signer, options, }: SparkWalletProps): Promise<{
|
|
8
|
+
mnemonic?: string | undefined;
|
|
9
|
+
wallet: IssuerSparkWalletNodeJS;
|
|
10
|
+
}>;
|
|
11
|
+
protected initializeTracerEnv({ spanProcessors, traceUrls, }: Parameters<IssuerSparkWallet["initializeTracerEnv"]>[0]): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { IssuerSparkWalletNodeJS as IssuerSparkWallet };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { I as IssuerSparkWallet } from './issuer-spark-wallet-BFzkv4X5.js';
|
|
2
|
+
export { a as IssuerTokenMetadata, T as TokenDistribution } from './issuer-spark-wallet-BFzkv4X5.js';
|
|
3
|
+
import { SparkWalletProps } from '@buildonspark/spark-sdk';
|
|
4
|
+
import '@buildonspark/spark-sdk/proto/spark';
|
|
5
|
+
|
|
6
|
+
declare class IssuerSparkWalletNodeJS extends IssuerSparkWallet {
|
|
7
|
+
static initialize({ mnemonicOrSeed, accountNumber, signer, options, }: SparkWalletProps): Promise<{
|
|
8
|
+
mnemonic?: string | undefined;
|
|
9
|
+
wallet: IssuerSparkWalletNodeJS;
|
|
10
|
+
}>;
|
|
11
|
+
protected initializeTracerEnv({ spanProcessors, traceUrls, }: Parameters<IssuerSparkWallet["initializeTracerEnv"]>[0]): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { IssuerSparkWalletNodeJS as IssuerSparkWallet };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IssuerSparkWallet
|
|
3
|
+
} from "./chunk-HOLMXKFE.js";
|
|
4
|
+
import "./chunk-7B4B24XF.js";
|
|
5
|
+
|
|
6
|
+
// src/issuer-wallet/issuer-spark-wallet.node.ts
|
|
7
|
+
import {
|
|
8
|
+
initializeTracerEnv as initializeTracerEnvNodeJS
|
|
9
|
+
} from "@buildonspark/spark-sdk";
|
|
10
|
+
var IssuerSparkWalletNodeJS = class _IssuerSparkWalletNodeJS extends IssuerSparkWallet {
|
|
11
|
+
static async initialize({
|
|
12
|
+
mnemonicOrSeed,
|
|
13
|
+
accountNumber,
|
|
14
|
+
signer,
|
|
15
|
+
options
|
|
16
|
+
}) {
|
|
17
|
+
const wallet = new _IssuerSparkWalletNodeJS(options, signer);
|
|
18
|
+
wallet.initializeTracer(wallet);
|
|
19
|
+
const initResponse = await wallet.initWallet(mnemonicOrSeed, accountNumber);
|
|
20
|
+
return {
|
|
21
|
+
wallet,
|
|
22
|
+
...initResponse
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
initializeTracerEnv({
|
|
26
|
+
spanProcessors,
|
|
27
|
+
traceUrls
|
|
28
|
+
}) {
|
|
29
|
+
initializeTracerEnvNodeJS({ spanProcessors, traceUrls });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
IssuerSparkWalletNodeJS as IssuerSparkWallet
|
|
34
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { SparkWallet, SparkWalletProps, ConfigOptions, SparkSigner, Bech32mTokenIdentifier } from '@buildonspark/spark-sdk';
|
|
2
|
+
import { OutputWithPreviousTransactionData } from '@buildonspark/spark-sdk/proto/spark';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Token metadata containing essential information about issuer's token.
|
|
6
|
+
* This is the wallet's internal representation with JavaScript-friendly types.
|
|
7
|
+
*
|
|
8
|
+
* rawTokenIdentifier: This is the raw binary token identifier - This is used to encode the human readable token identifier.
|
|
9
|
+
*
|
|
10
|
+
* tokenPublicKey: This is the hex-encoded public key of the token issuer - Same as issuerPublicKey.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const tokenMetadata: IssuerTokenMetadata = {
|
|
15
|
+
* rawTokenIdentifier: new Uint8Array([1, 2, 3]),
|
|
16
|
+
* tokenPublicKey: "0348fbb...",
|
|
17
|
+
* tokenName: "SparkToken",
|
|
18
|
+
* tokenTicker: "SPK",
|
|
19
|
+
* decimals: 8,
|
|
20
|
+
* maxSupply: 1000000n
|
|
21
|
+
* isFreezable: true
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
type IssuerTokenMetadata = {
|
|
26
|
+
/** Raw binary token identifier - This is used to encode the human readable token identifier */
|
|
27
|
+
rawTokenIdentifier: Uint8Array;
|
|
28
|
+
/** Public key of the token issuer - Same as issuerPublicKey */
|
|
29
|
+
tokenPublicKey: string;
|
|
30
|
+
/** Human-readable name of the token (e.g., SparkToken)*/
|
|
31
|
+
tokenName: string;
|
|
32
|
+
/** Short ticker symbol for the token (e.g., "SPK") */
|
|
33
|
+
tokenTicker: string;
|
|
34
|
+
/** Number of decimal places for token amounts */
|
|
35
|
+
decimals: number;
|
|
36
|
+
/** Maximum supply of tokens that can ever be minted */
|
|
37
|
+
maxSupply: bigint;
|
|
38
|
+
/** Whether the token is freezable */
|
|
39
|
+
isFreezable: boolean;
|
|
40
|
+
};
|
|
41
|
+
interface TokenDistribution {
|
|
42
|
+
totalCirculatingSupply: bigint;
|
|
43
|
+
totalIssued: bigint;
|
|
44
|
+
totalBurned: bigint;
|
|
45
|
+
numHoldingAddress: number;
|
|
46
|
+
numConfirmedTransactions: bigint;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Represents a Spark wallet with minting capabilities.
|
|
51
|
+
* This class extends the base SparkWallet with additional functionality for token minting,
|
|
52
|
+
* burning, and freezing operations.
|
|
53
|
+
*/
|
|
54
|
+
declare class IssuerSparkWallet extends SparkWallet {
|
|
55
|
+
private issuerTokenTransactionService;
|
|
56
|
+
private tokenFreezeService;
|
|
57
|
+
protected tracerId: string;
|
|
58
|
+
/**
|
|
59
|
+
* Initializes a new IssuerSparkWallet instance.
|
|
60
|
+
* @param options - Configuration options for the wallet
|
|
61
|
+
* @returns An object containing the initialized wallet and initialization response
|
|
62
|
+
*/
|
|
63
|
+
static initialize({ mnemonicOrSeed, accountNumber, signer, options, }: SparkWalletProps): Promise<{
|
|
64
|
+
mnemonic?: string | undefined;
|
|
65
|
+
wallet: IssuerSparkWallet;
|
|
66
|
+
}>;
|
|
67
|
+
protected constructor(configOptions?: ConfigOptions, signer?: SparkSigner);
|
|
68
|
+
/**
|
|
69
|
+
* Gets the token balance for the issuer's token.
|
|
70
|
+
* @returns An object containing the token balance as a bigint
|
|
71
|
+
*/
|
|
72
|
+
getIssuerTokenBalance(): Promise<{
|
|
73
|
+
tokenIdentifier: Bech32mTokenIdentifier | undefined;
|
|
74
|
+
balance: bigint;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves information about the issuer's token.
|
|
78
|
+
* @returns An object containing token information including public key, name, symbol, decimals, max supply, and freeze status
|
|
79
|
+
* @throws {NetworkError} If the token metadata cannot be retrieved
|
|
80
|
+
*/
|
|
81
|
+
getIssuerTokenMetadata(): Promise<IssuerTokenMetadata>;
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves the bech32m encoded token identifier for the issuer's token.
|
|
84
|
+
* @returns The bech32m encoded token identifier for the issuer's token
|
|
85
|
+
* @throws {NetworkError} If the token identifier cannot be retrieved
|
|
86
|
+
*/
|
|
87
|
+
getIssuerTokenIdentifier(): Promise<Bech32mTokenIdentifier>;
|
|
88
|
+
/**
|
|
89
|
+
* Create a new token on Spark.
|
|
90
|
+
*
|
|
91
|
+
* @param params - Object containing token creation parameters.
|
|
92
|
+
* @param params.tokenName - The name of the token.
|
|
93
|
+
* @param params.tokenTicker - The ticker symbol for the token.
|
|
94
|
+
* @param params.decimals - The number of decimal places for the token.
|
|
95
|
+
* @param params.isFreezable - Whether the token can be frozen.
|
|
96
|
+
* @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
|
|
97
|
+
*
|
|
98
|
+
* @returns The transaction ID of the announcement.
|
|
99
|
+
*
|
|
100
|
+
* @throws {ValidationError} If `decimals` is not a safe integer or other validation fails.
|
|
101
|
+
* @throws {NetworkError} If the announcement transaction cannot be broadcast.
|
|
102
|
+
*/
|
|
103
|
+
createToken({ tokenName, tokenTicker, decimals, isFreezable, maxSupply, }: {
|
|
104
|
+
tokenName: string;
|
|
105
|
+
tokenTicker: string;
|
|
106
|
+
decimals: number;
|
|
107
|
+
isFreezable: boolean;
|
|
108
|
+
maxSupply?: bigint;
|
|
109
|
+
}): Promise<string>;
|
|
110
|
+
/**
|
|
111
|
+
* Mints new tokens
|
|
112
|
+
* @param tokenAmount - The amount of tokens to mint
|
|
113
|
+
* @returns The transaction ID of the mint operation
|
|
114
|
+
*/
|
|
115
|
+
mintTokens(tokenAmount: bigint): Promise<string>;
|
|
116
|
+
/**
|
|
117
|
+
* Burns issuer's tokens
|
|
118
|
+
* @param tokenAmount - The amount of tokens to burn
|
|
119
|
+
* @param selectedOutputs - Optional array of outputs to use for the burn operation
|
|
120
|
+
* @returns The transaction ID of the burn operation
|
|
121
|
+
*/
|
|
122
|
+
burnTokens(tokenAmount: bigint, selectedOutputs?: OutputWithPreviousTransactionData[]): Promise<string>;
|
|
123
|
+
/**
|
|
124
|
+
* Freezes tokens associated with a specific Spark address.
|
|
125
|
+
* @param sparkAddress - The Spark address whose tokens should be frozen
|
|
126
|
+
* @returns An object containing the IDs of impacted outputs and the total amount of frozen tokens
|
|
127
|
+
*/
|
|
128
|
+
freezeTokens(sparkAddress: string): Promise<{
|
|
129
|
+
impactedOutputIds: string[];
|
|
130
|
+
impactedTokenAmount: bigint;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Unfreezes previously frozen tokens associated with a specific Spark address.
|
|
134
|
+
* @param sparkAddress - The Spark address whose tokens should be unfrozen
|
|
135
|
+
* @returns An object containing the IDs of impacted outputs and the total amount of unfrozen tokens
|
|
136
|
+
*/
|
|
137
|
+
unfreezeTokens(sparkAddress: string): Promise<{
|
|
138
|
+
impactedOutputIds: string[];
|
|
139
|
+
impactedTokenAmount: bigint;
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Retrieves the distribution information for the issuer's token.
|
|
143
|
+
* @throws {NotImplementedError} This feature is not yet supported
|
|
144
|
+
*/
|
|
145
|
+
getIssuerTokenDistribution(): Promise<TokenDistribution>;
|
|
146
|
+
/**
|
|
147
|
+
* Announces a new token on the L1 (Bitcoin) network.
|
|
148
|
+
* @param tokenName - The name of the token
|
|
149
|
+
* @param tokenTicker - The ticker symbol for the token
|
|
150
|
+
* @param decimals - The number of decimal places for the token
|
|
151
|
+
* @param maxSupply - The maximum supply of the token
|
|
152
|
+
* @param isFreezable - Whether the token can be frozen
|
|
153
|
+
* @param feeRateSatsPerVb - The fee rate in satoshis per virtual byte (default: 4.0)
|
|
154
|
+
* @returns The transaction ID of the announcement
|
|
155
|
+
* @throws {ValidationError} If decimals is not a safe integer
|
|
156
|
+
* @throws {NetworkError} If the announcement transaction cannot be broadcast
|
|
157
|
+
*/
|
|
158
|
+
announceTokenL1(tokenName: string, tokenTicker: string, decimals: number, maxSupply: bigint, isFreezable: boolean, feeRateSatsPerVb?: number): Promise<string>;
|
|
159
|
+
protected getTraceName(methodName: string): string;
|
|
160
|
+
private wrapPublicIssuerSparkWalletMethodWithOtelSpan;
|
|
161
|
+
private wrapIssuerSparkWalletMethodsWithTracing;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export { IssuerSparkWallet as I, type TokenDistribution as T, type IssuerTokenMetadata as a };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { SparkWallet, SparkWalletProps, ConfigOptions, SparkSigner, Bech32mTokenIdentifier } from '@buildonspark/spark-sdk';
|
|
2
|
+
import { OutputWithPreviousTransactionData } from '@buildonspark/spark-sdk/proto/spark';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Token metadata containing essential information about issuer's token.
|
|
6
|
+
* This is the wallet's internal representation with JavaScript-friendly types.
|
|
7
|
+
*
|
|
8
|
+
* rawTokenIdentifier: This is the raw binary token identifier - This is used to encode the human readable token identifier.
|
|
9
|
+
*
|
|
10
|
+
* tokenPublicKey: This is the hex-encoded public key of the token issuer - Same as issuerPublicKey.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const tokenMetadata: IssuerTokenMetadata = {
|
|
15
|
+
* rawTokenIdentifier: new Uint8Array([1, 2, 3]),
|
|
16
|
+
* tokenPublicKey: "0348fbb...",
|
|
17
|
+
* tokenName: "SparkToken",
|
|
18
|
+
* tokenTicker: "SPK",
|
|
19
|
+
* decimals: 8,
|
|
20
|
+
* maxSupply: 1000000n
|
|
21
|
+
* isFreezable: true
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
type IssuerTokenMetadata = {
|
|
26
|
+
/** Raw binary token identifier - This is used to encode the human readable token identifier */
|
|
27
|
+
rawTokenIdentifier: Uint8Array;
|
|
28
|
+
/** Public key of the token issuer - Same as issuerPublicKey */
|
|
29
|
+
tokenPublicKey: string;
|
|
30
|
+
/** Human-readable name of the token (e.g., SparkToken)*/
|
|
31
|
+
tokenName: string;
|
|
32
|
+
/** Short ticker symbol for the token (e.g., "SPK") */
|
|
33
|
+
tokenTicker: string;
|
|
34
|
+
/** Number of decimal places for token amounts */
|
|
35
|
+
decimals: number;
|
|
36
|
+
/** Maximum supply of tokens that can ever be minted */
|
|
37
|
+
maxSupply: bigint;
|
|
38
|
+
/** Whether the token is freezable */
|
|
39
|
+
isFreezable: boolean;
|
|
40
|
+
};
|
|
41
|
+
interface TokenDistribution {
|
|
42
|
+
totalCirculatingSupply: bigint;
|
|
43
|
+
totalIssued: bigint;
|
|
44
|
+
totalBurned: bigint;
|
|
45
|
+
numHoldingAddress: number;
|
|
46
|
+
numConfirmedTransactions: bigint;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Represents a Spark wallet with minting capabilities.
|
|
51
|
+
* This class extends the base SparkWallet with additional functionality for token minting,
|
|
52
|
+
* burning, and freezing operations.
|
|
53
|
+
*/
|
|
54
|
+
declare class IssuerSparkWallet extends SparkWallet {
|
|
55
|
+
private issuerTokenTransactionService;
|
|
56
|
+
private tokenFreezeService;
|
|
57
|
+
protected tracerId: string;
|
|
58
|
+
/**
|
|
59
|
+
* Initializes a new IssuerSparkWallet instance.
|
|
60
|
+
* @param options - Configuration options for the wallet
|
|
61
|
+
* @returns An object containing the initialized wallet and initialization response
|
|
62
|
+
*/
|
|
63
|
+
static initialize({ mnemonicOrSeed, accountNumber, signer, options, }: SparkWalletProps): Promise<{
|
|
64
|
+
mnemonic?: string | undefined;
|
|
65
|
+
wallet: IssuerSparkWallet;
|
|
66
|
+
}>;
|
|
67
|
+
protected constructor(configOptions?: ConfigOptions, signer?: SparkSigner);
|
|
68
|
+
/**
|
|
69
|
+
* Gets the token balance for the issuer's token.
|
|
70
|
+
* @returns An object containing the token balance as a bigint
|
|
71
|
+
*/
|
|
72
|
+
getIssuerTokenBalance(): Promise<{
|
|
73
|
+
tokenIdentifier: Bech32mTokenIdentifier | undefined;
|
|
74
|
+
balance: bigint;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves information about the issuer's token.
|
|
78
|
+
* @returns An object containing token information including public key, name, symbol, decimals, max supply, and freeze status
|
|
79
|
+
* @throws {NetworkError} If the token metadata cannot be retrieved
|
|
80
|
+
*/
|
|
81
|
+
getIssuerTokenMetadata(): Promise<IssuerTokenMetadata>;
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves the bech32m encoded token identifier for the issuer's token.
|
|
84
|
+
* @returns The bech32m encoded token identifier for the issuer's token
|
|
85
|
+
* @throws {NetworkError} If the token identifier cannot be retrieved
|
|
86
|
+
*/
|
|
87
|
+
getIssuerTokenIdentifier(): Promise<Bech32mTokenIdentifier>;
|
|
88
|
+
/**
|
|
89
|
+
* Create a new token on Spark.
|
|
90
|
+
*
|
|
91
|
+
* @param params - Object containing token creation parameters.
|
|
92
|
+
* @param params.tokenName - The name of the token.
|
|
93
|
+
* @param params.tokenTicker - The ticker symbol for the token.
|
|
94
|
+
* @param params.decimals - The number of decimal places for the token.
|
|
95
|
+
* @param params.isFreezable - Whether the token can be frozen.
|
|
96
|
+
* @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
|
|
97
|
+
*
|
|
98
|
+
* @returns The transaction ID of the announcement.
|
|
99
|
+
*
|
|
100
|
+
* @throws {ValidationError} If `decimals` is not a safe integer or other validation fails.
|
|
101
|
+
* @throws {NetworkError} If the announcement transaction cannot be broadcast.
|
|
102
|
+
*/
|
|
103
|
+
createToken({ tokenName, tokenTicker, decimals, isFreezable, maxSupply, }: {
|
|
104
|
+
tokenName: string;
|
|
105
|
+
tokenTicker: string;
|
|
106
|
+
decimals: number;
|
|
107
|
+
isFreezable: boolean;
|
|
108
|
+
maxSupply?: bigint;
|
|
109
|
+
}): Promise<string>;
|
|
110
|
+
/**
|
|
111
|
+
* Mints new tokens
|
|
112
|
+
* @param tokenAmount - The amount of tokens to mint
|
|
113
|
+
* @returns The transaction ID of the mint operation
|
|
114
|
+
*/
|
|
115
|
+
mintTokens(tokenAmount: bigint): Promise<string>;
|
|
116
|
+
/**
|
|
117
|
+
* Burns issuer's tokens
|
|
118
|
+
* @param tokenAmount - The amount of tokens to burn
|
|
119
|
+
* @param selectedOutputs - Optional array of outputs to use for the burn operation
|
|
120
|
+
* @returns The transaction ID of the burn operation
|
|
121
|
+
*/
|
|
122
|
+
burnTokens(tokenAmount: bigint, selectedOutputs?: OutputWithPreviousTransactionData[]): Promise<string>;
|
|
123
|
+
/**
|
|
124
|
+
* Freezes tokens associated with a specific Spark address.
|
|
125
|
+
* @param sparkAddress - The Spark address whose tokens should be frozen
|
|
126
|
+
* @returns An object containing the IDs of impacted outputs and the total amount of frozen tokens
|
|
127
|
+
*/
|
|
128
|
+
freezeTokens(sparkAddress: string): Promise<{
|
|
129
|
+
impactedOutputIds: string[];
|
|
130
|
+
impactedTokenAmount: bigint;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Unfreezes previously frozen tokens associated with a specific Spark address.
|
|
134
|
+
* @param sparkAddress - The Spark address whose tokens should be unfrozen
|
|
135
|
+
* @returns An object containing the IDs of impacted outputs and the total amount of unfrozen tokens
|
|
136
|
+
*/
|
|
137
|
+
unfreezeTokens(sparkAddress: string): Promise<{
|
|
138
|
+
impactedOutputIds: string[];
|
|
139
|
+
impactedTokenAmount: bigint;
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Retrieves the distribution information for the issuer's token.
|
|
143
|
+
* @throws {NotImplementedError} This feature is not yet supported
|
|
144
|
+
*/
|
|
145
|
+
getIssuerTokenDistribution(): Promise<TokenDistribution>;
|
|
146
|
+
/**
|
|
147
|
+
* Announces a new token on the L1 (Bitcoin) network.
|
|
148
|
+
* @param tokenName - The name of the token
|
|
149
|
+
* @param tokenTicker - The ticker symbol for the token
|
|
150
|
+
* @param decimals - The number of decimal places for the token
|
|
151
|
+
* @param maxSupply - The maximum supply of the token
|
|
152
|
+
* @param isFreezable - Whether the token can be frozen
|
|
153
|
+
* @param feeRateSatsPerVb - The fee rate in satoshis per virtual byte (default: 4.0)
|
|
154
|
+
* @returns The transaction ID of the announcement
|
|
155
|
+
* @throws {ValidationError} If decimals is not a safe integer
|
|
156
|
+
* @throws {NetworkError} If the announcement transaction cannot be broadcast
|
|
157
|
+
*/
|
|
158
|
+
announceTokenL1(tokenName: string, tokenTicker: string, decimals: number, maxSupply: bigint, isFreezable: boolean, feeRateSatsPerVb?: number): Promise<string>;
|
|
159
|
+
protected getTraceName(methodName: string): string;
|
|
160
|
+
private wrapPublicIssuerSparkWalletMethodWithOtelSpan;
|
|
161
|
+
private wrapIssuerSparkWalletMethodsWithTracing;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export { IssuerSparkWallet as I, type TokenDistribution as T, type IssuerTokenMetadata as a };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildonspark/issuer-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.85",
|
|
4
4
|
"description": "Spark Issuer SDK for token issuance",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -9,8 +9,26 @@
|
|
|
9
9
|
"homepage": "https://github.com/buildonspark/spark",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"import":
|
|
13
|
-
|
|
12
|
+
"import": {
|
|
13
|
+
"node": {
|
|
14
|
+
"types": "./dist/index.node.d.ts",
|
|
15
|
+
"default": "./dist/index.node.js"
|
|
16
|
+
},
|
|
17
|
+
"default": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"require": {
|
|
23
|
+
"node": {
|
|
24
|
+
"types": "./dist/index.node.d.cts",
|
|
25
|
+
"default": "./dist/index.node.cjs"
|
|
26
|
+
},
|
|
27
|
+
"default": {
|
|
28
|
+
"types": "./dist/index.d.cts",
|
|
29
|
+
"default": "./dist/index.cjs"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
14
32
|
},
|
|
15
33
|
"./proto/spark": {
|
|
16
34
|
"import": "./dist/proto/spark.js",
|
|
@@ -54,8 +72,8 @@
|
|
|
54
72
|
"types": "tsc"
|
|
55
73
|
},
|
|
56
74
|
"dependencies": {
|
|
57
|
-
"@buildonspark/lrc20-sdk": "0.0.
|
|
58
|
-
"@buildonspark/spark-sdk": "0.2.
|
|
75
|
+
"@buildonspark/lrc20-sdk": "0.0.61",
|
|
76
|
+
"@buildonspark/spark-sdk": "0.2.6",
|
|
59
77
|
"@lightsparkdev/core": "^1.4.2",
|
|
60
78
|
"@noble/curves": "^1.8.0",
|
|
61
79
|
"@scure/btc-signer": "^1.5.0",
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { IssuerSparkWalletBrowser as IssuerSparkWallet } from "./issuer-wallet/issuer-spark-wallet.browser.js";
|
|
2
2
|
export * from "./issuer-wallet/types.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IssuerSparkWallet as BaseIssuerSparkWallet } from "./issuer-spark-wallet.js";
|
|
2
|
+
import {
|
|
3
|
+
initializeTracerEnv as initializeTracerEnvBrowser,
|
|
4
|
+
type SparkWalletProps,
|
|
5
|
+
} from "@buildonspark/spark-sdk";
|
|
6
|
+
|
|
7
|
+
export class IssuerSparkWalletBrowser extends BaseIssuerSparkWallet {
|
|
8
|
+
public static async initialize({
|
|
9
|
+
mnemonicOrSeed,
|
|
10
|
+
accountNumber,
|
|
11
|
+
signer,
|
|
12
|
+
options,
|
|
13
|
+
}: SparkWalletProps) {
|
|
14
|
+
const wallet = new IssuerSparkWalletBrowser(options, signer);
|
|
15
|
+
wallet.initializeTracer(wallet);
|
|
16
|
+
|
|
17
|
+
const initResponse = await wallet.initWallet(mnemonicOrSeed, accountNumber);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
wallet,
|
|
21
|
+
...initResponse,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected initializeTracerEnv({
|
|
26
|
+
spanProcessors,
|
|
27
|
+
traceUrls,
|
|
28
|
+
}: Parameters<BaseIssuerSparkWallet["initializeTracerEnv"]>[0]) {
|
|
29
|
+
initializeTracerEnvBrowser({ spanProcessors, traceUrls });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { IssuerSparkWalletBrowser as IssuerSparkWallet };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IssuerSparkWallet as BaseIssuerSparkWallet } from "./issuer-spark-wallet.js";
|
|
2
|
+
import {
|
|
3
|
+
initializeTracerEnv as initializeTracerEnvNodeJS,
|
|
4
|
+
type SparkWalletProps,
|
|
5
|
+
} from "@buildonspark/spark-sdk";
|
|
6
|
+
|
|
7
|
+
export class IssuerSparkWalletNodeJS extends BaseIssuerSparkWallet {
|
|
8
|
+
public static async initialize({
|
|
9
|
+
mnemonicOrSeed,
|
|
10
|
+
accountNumber,
|
|
11
|
+
signer,
|
|
12
|
+
options,
|
|
13
|
+
}: SparkWalletProps) {
|
|
14
|
+
const wallet = new IssuerSparkWalletNodeJS(options, signer);
|
|
15
|
+
wallet.initializeTracer(wallet);
|
|
16
|
+
|
|
17
|
+
const initResponse = await wallet.initWallet(mnemonicOrSeed, accountNumber);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
wallet,
|
|
21
|
+
...initResponse,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected initializeTracerEnv({
|
|
26
|
+
spanProcessors,
|
|
27
|
+
traceUrls,
|
|
28
|
+
}: Parameters<BaseIssuerSparkWallet["initializeTracerEnv"]>[0]) {
|
|
29
|
+
initializeTracerEnvNodeJS({ spanProcessors, traceUrls });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { IssuerSparkWalletNodeJS as IssuerSparkWallet };
|
|
@@ -57,62 +57,16 @@ export class IssuerSparkWallet extends SparkWallet {
|
|
|
57
57
|
options,
|
|
58
58
|
}: SparkWalletProps) {
|
|
59
59
|
const wallet = new IssuerSparkWallet(options, signer);
|
|
60
|
+
wallet.initializeTracer(wallet);
|
|
60
61
|
|
|
61
62
|
const initResponse = await wallet.initWallet(mnemonicOrSeed, accountNumber);
|
|
62
63
|
|
|
63
|
-
if (isNode) {
|
|
64
|
-
wallet.wrapIssuerSparkWalletWithTracing();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
64
|
return {
|
|
68
65
|
wallet,
|
|
69
66
|
...initResponse,
|
|
70
67
|
};
|
|
71
68
|
}
|
|
72
69
|
|
|
73
|
-
private wrapIssuerSparkWalletWithTracing() {
|
|
74
|
-
this.getIssuerTokenBalance = this.wrapWithOtelSpan(
|
|
75
|
-
"SparkIssuerWallet.getIssuerTokenBalance",
|
|
76
|
-
this.getIssuerTokenBalance.bind(this),
|
|
77
|
-
);
|
|
78
|
-
this.getIssuerTokenMetadata = this.wrapWithOtelSpan(
|
|
79
|
-
"SparkIssuerWallet.getIssuerTokenMetadata",
|
|
80
|
-
this.getIssuerTokenMetadata.bind(this),
|
|
81
|
-
);
|
|
82
|
-
this.getIssuerTokenIdentifier = this.wrapWithOtelSpan(
|
|
83
|
-
"SparkIssuerWallet.getIssuerTokenIdentifier",
|
|
84
|
-
this.getIssuerTokenIdentifier.bind(this),
|
|
85
|
-
);
|
|
86
|
-
this.createToken = this.wrapWithOtelSpan(
|
|
87
|
-
"SparkIssuerWallet.createToken",
|
|
88
|
-
this.createToken.bind(this),
|
|
89
|
-
);
|
|
90
|
-
this.mintTokens = this.wrapWithOtelSpan(
|
|
91
|
-
"SparkIssuerWallet.mintTokens",
|
|
92
|
-
this.mintTokens.bind(this),
|
|
93
|
-
);
|
|
94
|
-
this.burnTokens = this.wrapWithOtelSpan(
|
|
95
|
-
"SparkIssuerWallet.burnTokens",
|
|
96
|
-
this.burnTokens.bind(this),
|
|
97
|
-
);
|
|
98
|
-
this.freezeTokens = this.wrapWithOtelSpan(
|
|
99
|
-
"SparkIssuerWallet.freezeTokens",
|
|
100
|
-
this.freezeTokens.bind(this),
|
|
101
|
-
);
|
|
102
|
-
this.unfreezeTokens = this.wrapWithOtelSpan(
|
|
103
|
-
"SparkIssuerWallet.unfreezeTokens",
|
|
104
|
-
this.unfreezeTokens.bind(this),
|
|
105
|
-
);
|
|
106
|
-
this.getIssuerTokenDistribution = this.wrapWithOtelSpan(
|
|
107
|
-
"SparkIssuerWallet.getIssuerTokenDistribution",
|
|
108
|
-
this.getIssuerTokenDistribution.bind(this),
|
|
109
|
-
);
|
|
110
|
-
this.announceTokenL1 = this.wrapWithOtelSpan(
|
|
111
|
-
"SparkIssuerWallet.announceTokenL1",
|
|
112
|
-
this.announceTokenL1.bind(this),
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
70
|
protected constructor(configOptions?: ConfigOptions, signer?: SparkSigner) {
|
|
117
71
|
super(configOptions, signer);
|
|
118
72
|
this.issuerTokenTransactionService = new IssuerTokenTransactionService(
|
|
@@ -123,6 +77,7 @@ export class IssuerSparkWallet extends SparkWallet {
|
|
|
123
77
|
this.config,
|
|
124
78
|
this.connectionManager,
|
|
125
79
|
);
|
|
80
|
+
this.wrapIssuerSparkWalletMethodsWithTracing();
|
|
126
81
|
}
|
|
127
82
|
|
|
128
83
|
/**
|
|
@@ -226,7 +181,7 @@ export class IssuerSparkWallet extends SparkWallet {
|
|
|
226
181
|
* @returns The bech32m encoded token identifier for the issuer's token
|
|
227
182
|
* @throws {NetworkError} If the token identifier cannot be retrieved
|
|
228
183
|
*/
|
|
229
|
-
public async getIssuerTokenIdentifier(): Promise<Bech32mTokenIdentifier
|
|
184
|
+
public async getIssuerTokenIdentifier(): Promise<Bech32mTokenIdentifier> {
|
|
230
185
|
const tokenMetadata = await this.getIssuerTokenMetadata();
|
|
231
186
|
|
|
232
187
|
return encodeBech32mTokenIdentifier({
|
|
@@ -329,11 +284,8 @@ export class IssuerSparkWallet extends SparkWallet {
|
|
|
329
284
|
identityPublicKey: BURN_ADDRESS,
|
|
330
285
|
network: this.config.getNetworkType(),
|
|
331
286
|
});
|
|
332
|
-
const issuerTokenIdentifier: Bech32mTokenIdentifier
|
|
287
|
+
const issuerTokenIdentifier: Bech32mTokenIdentifier =
|
|
333
288
|
await this.getIssuerTokenIdentifier();
|
|
334
|
-
if (issuerTokenIdentifier === null) {
|
|
335
|
-
throw new ValidationError("Issuer token identifier not found");
|
|
336
|
-
}
|
|
337
289
|
|
|
338
290
|
return await this.transferTokens({
|
|
339
291
|
tokenIdentifier: issuerTokenIdentifier,
|
|
@@ -358,13 +310,6 @@ export class IssuerSparkWallet extends SparkWallet {
|
|
|
358
310
|
);
|
|
359
311
|
|
|
360
312
|
const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
|
|
361
|
-
if (issuerTokenIdentifier === null) {
|
|
362
|
-
throw new ValidationError("Issuer token identifier not found", {
|
|
363
|
-
field: "issuerTokenIdentifier",
|
|
364
|
-
value: issuerTokenIdentifier,
|
|
365
|
-
expected: "non-null token identifier",
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
313
|
|
|
369
314
|
const rawTokenIdentifier = decodeBech32mTokenIdentifier(
|
|
370
315
|
issuerTokenIdentifier,
|
|
@@ -400,13 +345,6 @@ export class IssuerSparkWallet extends SparkWallet {
|
|
|
400
345
|
);
|
|
401
346
|
|
|
402
347
|
const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
|
|
403
|
-
if (issuerTokenIdentifier === null) {
|
|
404
|
-
throw new ValidationError("Issuer token identifier not found", {
|
|
405
|
-
field: "issuerTokenIdentifier",
|
|
406
|
-
value: issuerTokenIdentifier,
|
|
407
|
-
expected: "non-null token identifier",
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
348
|
|
|
411
349
|
const rawTokenIdentifier = decodeBech32mTokenIdentifier(
|
|
412
350
|
issuerTokenIdentifier,
|
|
@@ -498,4 +436,46 @@ export class IssuerSparkWallet extends SparkWallet {
|
|
|
498
436
|
);
|
|
499
437
|
}
|
|
500
438
|
}
|
|
439
|
+
|
|
440
|
+
protected getTraceName(methodName: string) {
|
|
441
|
+
return `IssuerSparkWallet.${methodName}`;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private wrapPublicIssuerSparkWalletMethodWithOtelSpan<
|
|
445
|
+
M extends keyof IssuerSparkWallet,
|
|
446
|
+
>(methodName: M) {
|
|
447
|
+
const original = this[methodName];
|
|
448
|
+
|
|
449
|
+
if (typeof original !== "function") {
|
|
450
|
+
throw new Error(
|
|
451
|
+
`Method ${methodName} is not a function on IssuerSparkWallet.`,
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const wrapped = this.wrapWithOtelSpan(
|
|
456
|
+
this.getTraceName(methodName),
|
|
457
|
+
original.bind(this) as (...args: unknown[]) => Promise<unknown>,
|
|
458
|
+
) as IssuerSparkWallet[M];
|
|
459
|
+
|
|
460
|
+
(this as IssuerSparkWallet)[methodName] = wrapped;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
private wrapIssuerSparkWalletMethodsWithTracing() {
|
|
464
|
+
const methods = [
|
|
465
|
+
"getIssuerTokenBalance",
|
|
466
|
+
"getIssuerTokenMetadata",
|
|
467
|
+
"getIssuerTokenIdentifier",
|
|
468
|
+
"createToken",
|
|
469
|
+
"mintTokens",
|
|
470
|
+
"burnTokens",
|
|
471
|
+
"freezeTokens",
|
|
472
|
+
"unfreezeTokens",
|
|
473
|
+
"getIssuerTokenDistribution",
|
|
474
|
+
"announceTokenL1",
|
|
475
|
+
] as const;
|
|
476
|
+
|
|
477
|
+
methods.forEach((m) =>
|
|
478
|
+
this.wrapPublicIssuerSparkWalletMethodWithOtelSpan(m),
|
|
479
|
+
);
|
|
480
|
+
}
|
|
501
481
|
}
|