@buildonspark/issuer-sdk 0.1.2 → 0.1.4
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 +109 -0
- package/dist/index.browser.d.ts +133 -9
- package/dist/index.browser.js +341 -83
- package/dist/index.node.cjs +348 -90
- package/dist/index.node.d.cts +133 -9
- package/dist/index.node.d.ts +133 -9
- package/dist/index.node.js +341 -83
- package/dist/native/index.react-native.cjs +345 -87
- package/dist/native/index.react-native.d.cts +133 -9
- package/dist/native/index.react-native.d.ts +133 -9
- package/dist/native/index.react-native.js +341 -83
- package/dist/proto/spark.d.cts +1 -1
- package/dist/proto/spark.d.ts +1 -1
- package/package.json +2 -2
- package/src/issuer-wallet/issuer-spark-wallet.ts +528 -58
- package/src/issuer-wallet/types.ts +25 -0
- package/src/tests/integration/multi-token-issuer.test.ts +437 -0
- package/src/tests/integration/nft-creation.test.ts +32 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,114 @@
|
|
|
1
1
|
# @buildonspark/issuer-sdk
|
|
2
2
|
|
|
3
|
+
## 0.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ## Multi-Token Issuance Support
|
|
8
|
+
|
|
9
|
+
Introduces support for issuer wallets to create and manage multiple tokens. Each token is uniquely identified by a bech32m token identifier derived from the token's creation parameters.
|
|
10
|
+
|
|
11
|
+
**Deprecated Methods**
|
|
12
|
+
|
|
13
|
+
The following methods are now marked deprecated and will throw `SparkValidationError` when multiple tokens exist for an issuer. These methods will be removed in a future major version:
|
|
14
|
+
- `getIssuerTokenBalance()` - Use `getIssuerTokenBalances()` instead
|
|
15
|
+
- `getIssuerTokenMetadata()` - Use `getIssuerTokensMetadata()` instead
|
|
16
|
+
- `getIssuerTokenIdentifier()` - Use `getIssuerTokenIdentifiers()` instead
|
|
17
|
+
- `mintTokens(amount)` - Use `mintTokens({ tokenAmount, tokenIdentifier })` instead
|
|
18
|
+
- `burnTokens(amount, selectedOutputs?)` - Use `burnTokens({ tokenAmount, tokenIdentifier, selectedOutputs })` instead
|
|
19
|
+
- `freezeTokens(sparkAddress)` - Use `freezeTokens({ tokenIdentifier, sparkAddress })` instead
|
|
20
|
+
- `unfreezeTokens(sparkAddress)` - Use `unfreezeTokens({ tokenIdentifier, sparkAddress })` instead
|
|
21
|
+
|
|
22
|
+
### New Features
|
|
23
|
+
|
|
24
|
+
**Token Creation with Identifier**
|
|
25
|
+
|
|
26
|
+
`createToken()` now accepts an optional `returnIdentifierForCreate` parameter to return both the transaction hash and token identifier:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
const result = await wallet.createToken({
|
|
30
|
+
tokenName: "MyToken",
|
|
31
|
+
tokenTicker: "MTK",
|
|
32
|
+
decimals: 8,
|
|
33
|
+
maxSupply: 1000000n,
|
|
34
|
+
isFreezable: false,
|
|
35
|
+
returnIdentifierForCreate: true, // Returns TokenCreationDetails
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Return issuer info for all issuer tokens**
|
|
40
|
+
- `getIssuerTokenBalances()` - Returns an array of token balances for all tokens owned by the issuer
|
|
41
|
+
- `getIssuerTokensMetadata()` - Returns an array of metadata for all tokens created by the issuer
|
|
42
|
+
- `getIssuerTokenIdentifiers()` - Returns an array of bech32m token identifiers for all issuer tokens
|
|
43
|
+
|
|
44
|
+
**Method Overloads**
|
|
45
|
+
|
|
46
|
+
All token operation methods now support optional `tokenIdentifier` parameters:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
// Mint tokens for a specific token
|
|
50
|
+
await wallet.mintTokens({
|
|
51
|
+
tokenAmount: 1000n,
|
|
52
|
+
tokenIdentifier: "btkn1..."
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Burn tokens for a specific token
|
|
56
|
+
await wallet.burnTokens({
|
|
57
|
+
tokenAmount: 500n,
|
|
58
|
+
tokenIdentifier: "btkn1...",
|
|
59
|
+
selectedOutputs: [...] // optional
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Freeze tokens for a specific token and address
|
|
63
|
+
await wallet.freezeTokens({
|
|
64
|
+
tokenIdentifier: "btkn1...",
|
|
65
|
+
sparkAddress: "spark1..."
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Unfreeze tokens for a specific token and address
|
|
69
|
+
await wallet.unfreezeTokens({
|
|
70
|
+
tokenIdentifier: "btkn1...",
|
|
71
|
+
sparkAddress: "spark1..."
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Backward Compatibility
|
|
76
|
+
|
|
77
|
+
Legacy method signatures continue to work for issuers with a single token. When multiple tokens are detected, these methods will throw descriptive errors guiding developers to use the new multi-token methods.
|
|
78
|
+
|
|
79
|
+
### Migration Guide
|
|
80
|
+
|
|
81
|
+
**For Single-Token Issuers**
|
|
82
|
+
|
|
83
|
+
Existing code consuming older SDK versions will continue to work.
|
|
84
|
+
|
|
85
|
+
**For Multi-Token Issuers**
|
|
86
|
+
|
|
87
|
+
Update your code to use the new multi-token methods:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
// Before
|
|
91
|
+
await wallet.mintTokens(100n);
|
|
92
|
+
|
|
93
|
+
// After
|
|
94
|
+
const metadata = await wallet.getIssuerTokensMetadata();
|
|
95
|
+
const tokenIdentifier = metadata[1].bech32mTokenIdentifier;
|
|
96
|
+
await wallet.mintTokens({
|
|
97
|
+
tokenAmount: 100n,
|
|
98
|
+
tokenIdentifier: tokenIdentifier,
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- Updated dependencies
|
|
103
|
+
- @buildonspark/spark-sdk@0.5.4
|
|
104
|
+
|
|
105
|
+
## 0.1.3
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- Updated dependencies
|
|
110
|
+
- @buildonspark/spark-sdk@0.5.3
|
|
111
|
+
|
|
3
112
|
## 0.1.2
|
|
4
113
|
|
|
5
114
|
### Patch Changes
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SparkWallet, ConfigOptions, SparkSigner,
|
|
1
|
+
import { Bech32mTokenIdentifier, SparkWallet, ConfigOptions, SparkSigner, WalletConfigService, ConnectionManager } from '@buildonspark/spark-sdk';
|
|
2
2
|
export { AggregateFrostParams, ConfigOptions, DefaultSparkSigner, DerivedHDKey, DummyTx, IKeyPackage, KeyDerivation, KeyDerivationType, KeyPair, SignFrostParams, SigningCommitment, SigningCommitmentWithOptionalNonce, SigningNonce, SparkSigner, SplitSecretWithProofsParams, SubtractSplitAndEncryptParams, SubtractSplitAndEncryptResult, UnsafeStatelessSparkSigner, WalletConfig, WalletConfigService } from '@buildonspark/spark-sdk';
|
|
3
3
|
import { OutputWithPreviousTransactionData } from '@buildonspark/spark-sdk/proto/spark_token';
|
|
4
4
|
|
|
@@ -40,6 +40,8 @@ type IssuerTokenMetadata = {
|
|
|
40
40
|
isFreezable: boolean;
|
|
41
41
|
/** Extra metadata of the token */
|
|
42
42
|
extraMetadata?: Uint8Array;
|
|
43
|
+
/** Bech32m encoded token identifier */
|
|
44
|
+
bech32mTokenIdentifier: Bech32mTokenIdentifier;
|
|
43
45
|
};
|
|
44
46
|
interface TokenDistribution {
|
|
45
47
|
totalCirculatingSupply: bigint;
|
|
@@ -48,6 +50,26 @@ interface TokenDistribution {
|
|
|
48
50
|
numHoldingAddress: number;
|
|
49
51
|
numConfirmedTransactions: bigint;
|
|
50
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Details of a token creation.
|
|
55
|
+
*
|
|
56
|
+
* tokenIdentifier: The Bech32m encoded token identifier.
|
|
57
|
+
* transactionHash: The hash of the transaction that created the token.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const tokenCreationDetails: TokenCreationDetails = {
|
|
62
|
+
* tokenIdentifier: "btkn1...",
|
|
63
|
+
* transactionHash: "1234567890abcdef...",
|
|
64
|
+
* };
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
interface TokenCreationDetails {
|
|
68
|
+
/** Bech32m encoded token identifier */
|
|
69
|
+
tokenIdentifier: Bech32mTokenIdentifier;
|
|
70
|
+
/** Transaction hash of the announcement */
|
|
71
|
+
transactionHash: string;
|
|
72
|
+
}
|
|
51
73
|
|
|
52
74
|
/**
|
|
53
75
|
* Represents a Spark wallet with minting capabilities.
|
|
@@ -65,24 +87,51 @@ declare abstract class IssuerSparkWallet extends SparkWallet {
|
|
|
65
87
|
constructor(configOptions?: ConfigOptions, signer?: SparkSigner);
|
|
66
88
|
/**
|
|
67
89
|
* Gets the token balance for the issuer's token.
|
|
90
|
+
* @deprecated Use getIssuerTokenBalances() instead. This method will be removed in a future version.
|
|
68
91
|
* @returns An object containing the token balance as a bigint
|
|
92
|
+
*
|
|
93
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
69
94
|
*/
|
|
70
95
|
getIssuerTokenBalance(): Promise<{
|
|
71
96
|
tokenIdentifier: Bech32mTokenIdentifier | undefined;
|
|
72
97
|
balance: bigint;
|
|
73
98
|
}>;
|
|
99
|
+
/**
|
|
100
|
+
* Gets the token balances for the tokens that were issued by this user.
|
|
101
|
+
* @returns An array of objects containing the token identifier and balance
|
|
102
|
+
*/
|
|
103
|
+
getIssuerTokenBalances(): Promise<{
|
|
104
|
+
tokenIdentifier: Bech32mTokenIdentifier | undefined;
|
|
105
|
+
balance: bigint;
|
|
106
|
+
}[]>;
|
|
74
107
|
/**
|
|
75
108
|
* Retrieves information about the issuer's token.
|
|
76
|
-
* @
|
|
109
|
+
* @deprecated Use getIssuerTokensMetadata() instead. This method will be removed in a future version.
|
|
110
|
+
* @returns An object containing token information including public key, name, symbol, decimals, max supply, freeze status, and extra metadata
|
|
77
111
|
* @throws {SparkRequestError} If the token metadata cannot be retrieved
|
|
112
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
78
113
|
*/
|
|
79
114
|
getIssuerTokenMetadata(): Promise<IssuerTokenMetadata>;
|
|
115
|
+
/**
|
|
116
|
+
* Retrieves information about the tokens that were issued by this user.
|
|
117
|
+
* @returns An array of objects containing token information including public key, name, symbol, decimals, max supply, freeze status, and extra metadata
|
|
118
|
+
* @throws {SparkRequestError} If the token metadata cannot be retrieved
|
|
119
|
+
*/
|
|
120
|
+
getIssuerTokensMetadata(): Promise<IssuerTokenMetadata[]>;
|
|
80
121
|
/**
|
|
81
122
|
* Retrieves the bech32m encoded token identifier for the issuer's token.
|
|
123
|
+
* @deprecated Use getIssuerTokenIdentifiers() instead. This method will be removed in a future version.
|
|
82
124
|
* @returns The bech32m encoded token identifier for the issuer's token
|
|
83
125
|
* @throws {SparkRequestError} If the token identifier cannot be retrieved
|
|
126
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
84
127
|
*/
|
|
85
128
|
getIssuerTokenIdentifier(): Promise<Bech32mTokenIdentifier>;
|
|
129
|
+
/**
|
|
130
|
+
* Retrieves the bech32m encoded token identifier for the issuer's token.
|
|
131
|
+
* @returns The bech32m encoded token identifier for the issuer's token
|
|
132
|
+
* @throws {SparkRequestError} If the token identifier cannot be retrieved
|
|
133
|
+
*/
|
|
134
|
+
getIssuerTokenIdentifiers(): Promise<Bech32mTokenIdentifier[]>;
|
|
86
135
|
/**
|
|
87
136
|
* Create a new token on Spark.
|
|
88
137
|
*
|
|
@@ -93,51 +142,126 @@ declare abstract class IssuerSparkWallet extends SparkWallet {
|
|
|
93
142
|
* @param params.isFreezable - Whether the token can be frozen.
|
|
94
143
|
* @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
|
|
95
144
|
* @param params.extraMetadata - (Optional) This can be used to store additional bytes data to be associated with a token, like image data.
|
|
96
|
-
*
|
|
97
|
-
* @returns The transaction
|
|
98
|
-
*
|
|
145
|
+
* @param params.returnIdentifierForCreate - (Optional) Whether to return the token identifier in addition to the transaction hash. Defaults to <code>false</code>.
|
|
146
|
+
* @returns The transaction hash of the announcement or TokenCreationDetails if `returnIdentifierForCreate` is true.
|
|
99
147
|
* @throws {SparkValidationError} If `decimals` is not a safe integer or other validation fails.
|
|
100
148
|
* @throws {SparkRequestError} If the announcement transaction cannot be broadcast.
|
|
101
149
|
*/
|
|
102
|
-
createToken(
|
|
150
|
+
createToken(params: {
|
|
103
151
|
tokenName: string;
|
|
104
152
|
tokenTicker: string;
|
|
105
153
|
decimals: number;
|
|
106
154
|
isFreezable: boolean;
|
|
107
155
|
maxSupply?: bigint;
|
|
108
156
|
extraMetadata?: Uint8Array;
|
|
157
|
+
returnIdentifierForCreate?: false;
|
|
109
158
|
}): Promise<string>;
|
|
159
|
+
createToken(params: {
|
|
160
|
+
tokenName: string;
|
|
161
|
+
tokenTicker: string;
|
|
162
|
+
decimals: number;
|
|
163
|
+
isFreezable: boolean;
|
|
164
|
+
maxSupply?: bigint;
|
|
165
|
+
extraMetadata?: Uint8Array;
|
|
166
|
+
returnIdentifierForCreate: true;
|
|
167
|
+
}): Promise<TokenCreationDetails>;
|
|
168
|
+
/**
|
|
169
|
+
* @deprecated Use mintTokens({ tokenAmount, tokenIdentifier }) instead. This method will be removed in a future version.
|
|
170
|
+
* @param amount - The amount of tokens to mint
|
|
171
|
+
* @returns The transaction ID of the mint operation
|
|
172
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
173
|
+
* @throws {SparkValidationError} If no tokens are found for this issuer
|
|
174
|
+
*/
|
|
175
|
+
mintTokens(amount: bigint): Promise<string>;
|
|
110
176
|
/**
|
|
111
177
|
* Mints new tokens
|
|
112
|
-
* @param
|
|
178
|
+
* @param params - Object containing token minting parameters.
|
|
179
|
+
* @param params.tokenAmount - The amount of tokens to mint
|
|
180
|
+
* @param params.tokenIdentifier - The bech32m encoded token identifier
|
|
113
181
|
* @returns The transaction ID of the mint operation
|
|
182
|
+
* @throws {SparkValidationError} If no tokens are found for this issuer
|
|
114
183
|
*/
|
|
115
|
-
mintTokens(tokenAmount
|
|
184
|
+
mintTokens({ tokenAmount, tokenIdentifier, }: {
|
|
185
|
+
tokenAmount: bigint;
|
|
186
|
+
tokenIdentifier?: Bech32mTokenIdentifier;
|
|
187
|
+
}): Promise<string>;
|
|
116
188
|
/**
|
|
117
189
|
* Burns issuer's tokens
|
|
190
|
+
* @deprecated Use burnTokens({ tokenAmount, tokenIdentifier, selectedOutputs }) instead. This method will be removed in a future version.
|
|
118
191
|
* @param tokenAmount - The amount of tokens to burn
|
|
119
192
|
* @param selectedOutputs - Optional array of outputs to use for the burn operation
|
|
120
193
|
* @returns The transaction ID of the burn operation
|
|
194
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
195
|
+
* @throws {SparkValidationError} If no tokens are found for this issuer
|
|
121
196
|
*/
|
|
122
197
|
burnTokens(tokenAmount: bigint, selectedOutputs?: OutputWithPreviousTransactionData[]): Promise<string>;
|
|
198
|
+
/**
|
|
199
|
+
* Burns issuer's tokens
|
|
200
|
+
* @param params - Object containing token burning parameters.
|
|
201
|
+
* @param params.tokenAmount - The amount of tokens to burn
|
|
202
|
+
* @param params.tokenIdentifier - The bech32m encoded token identifier
|
|
203
|
+
* @param params.selectedOutputs - Optional array of outputs to use for the burn operation
|
|
204
|
+
* @returns The transaction ID of the burn operation
|
|
205
|
+
*/
|
|
206
|
+
burnTokens({ tokenAmount, tokenIdentifier, selectedOutputs, }: {
|
|
207
|
+
tokenAmount: bigint;
|
|
208
|
+
tokenIdentifier?: Bech32mTokenIdentifier;
|
|
209
|
+
selectedOutputs?: OutputWithPreviousTransactionData[];
|
|
210
|
+
}): Promise<string>;
|
|
123
211
|
/**
|
|
124
212
|
* Freezes tokens associated with a specific Spark address.
|
|
213
|
+
* @deprecated Use freezeToken({ tokenIdentifier, sparkAddress }) instead. This method will be removed in a future version.
|
|
125
214
|
* @param sparkAddress - The Spark address whose tokens should be frozen
|
|
126
215
|
* @returns An object containing the IDs of impacted outputs and the total amount of frozen tokens
|
|
216
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
217
|
+
* @throws {SparkValidationError} If no tokens are found for this issuer
|
|
127
218
|
*/
|
|
128
219
|
freezeTokens(sparkAddress: string): Promise<{
|
|
129
220
|
impactedOutputIds: string[];
|
|
130
221
|
impactedTokenAmount: bigint;
|
|
131
222
|
}>;
|
|
223
|
+
/**
|
|
224
|
+
* Freezes tokens associated with a specific Spark address.
|
|
225
|
+
* @param params - Object containing token freezing parameters.
|
|
226
|
+
* @param params.tokenIdentifier - The bech32m encoded token identifier
|
|
227
|
+
* @param params.sparkAddress - The Spark address whose tokens should be frozen
|
|
228
|
+
* @returns An object containing the IDs of impacted outputs and the total amount of frozen tokens
|
|
229
|
+
*/
|
|
230
|
+
freezeTokens({ tokenIdentifier, sparkAddress, }: {
|
|
231
|
+
tokenIdentifier: Bech32mTokenIdentifier;
|
|
232
|
+
sparkAddress: string;
|
|
233
|
+
}): Promise<{
|
|
234
|
+
impactedOutputIds: string[];
|
|
235
|
+
impactedTokenAmount: bigint;
|
|
236
|
+
}>;
|
|
132
237
|
/**
|
|
133
238
|
* Unfreezes previously frozen tokens associated with a specific Spark address.
|
|
239
|
+
* @deprecated Use unfreezeToken({ tokenIdentifier, sparkAddress }) instead. This method will be removed in a future version.
|
|
134
240
|
* @param sparkAddress - The Spark address whose tokens should be unfrozen
|
|
135
241
|
* @returns An object containing the IDs of impacted outputs and the total amount of unfrozen tokens
|
|
242
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
243
|
+
* @throws {SparkValidationError} If no tokens are found for this issuer
|
|
136
244
|
*/
|
|
137
245
|
unfreezeTokens(sparkAddress: string): Promise<{
|
|
138
246
|
impactedOutputIds: string[];
|
|
139
247
|
impactedTokenAmount: bigint;
|
|
140
248
|
}>;
|
|
249
|
+
/**
|
|
250
|
+
* Unfreezes previously frozen tokens associated with a specific Spark address.
|
|
251
|
+
* @param params - Object containing token unfreezing parameters.
|
|
252
|
+
* @param params.tokenIdentifier - The bech32m encoded token identifier
|
|
253
|
+
* @param params.sparkAddress - The Spark address whose tokens should be unfrozen
|
|
254
|
+
* @returns An object containing the IDs of impacted outputs and the total amount of unfrozen tokens
|
|
255
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
256
|
+
* @throws {SparkValidationError} If no tokens are found for this issuer
|
|
257
|
+
*/
|
|
258
|
+
unfreezeTokens({ tokenIdentifier, sparkAddress, }: {
|
|
259
|
+
tokenIdentifier: Bech32mTokenIdentifier;
|
|
260
|
+
sparkAddress: string;
|
|
261
|
+
}): Promise<{
|
|
262
|
+
impactedOutputIds: string[];
|
|
263
|
+
impactedTokenAmount: bigint;
|
|
264
|
+
}>;
|
|
141
265
|
/**
|
|
142
266
|
* Retrieves the distribution information for the issuer's token.
|
|
143
267
|
* @throws {SparkError} This feature is not yet supported
|
|
@@ -152,4 +276,4 @@ declare class IssuerSparkWalletBrowser extends IssuerSparkWallet {
|
|
|
152
276
|
protected buildConnectionManager(config: WalletConfigService): ConnectionManager;
|
|
153
277
|
}
|
|
154
278
|
|
|
155
|
-
export { IssuerSparkWalletBrowser as IssuerSparkWallet, type IssuerTokenMetadata, type TokenDistribution };
|
|
279
|
+
export { IssuerSparkWalletBrowser as IssuerSparkWallet, type IssuerTokenMetadata, type TokenCreationDetails, type TokenDistribution };
|