@buildonspark/issuer-sdk 0.0.84 → 0.0.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @buildonspark/issuer-sdk
2
2
 
3
+ ## 0.0.86
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @buildonspark/spark-sdk@0.2.7
9
+
10
+ ## 0.0.85
11
+
12
+ ### Patch Changes
13
+
14
+ - -- Opentelemetry improvements
15
+ -- Utility function to decode bech32mtokenidentifiers to raw token identifiers
16
+ -- Add userRequest to transfer in getTransfer() if it exists
17
+ -- Fixes to getIssuerTokenIdentifier() types
18
+ -- Migrates some internal filtering logic to key on token identifiers
19
+ -- Testing improvements
20
+ - Updated dependencies
21
+ - @buildonspark/lrc20-sdk@0.0.61
22
+ - @buildonspark/spark-sdk@0.2.6
23
+
3
24
  ## 0.0.84
4
25
 
5
26
  ### Patch Changes
@@ -0,0 +1,610 @@
1
+ import {
2
+ Buffer
3
+ } from "./chunk-7B4B24XF.js";
4
+
5
+ // src/issuer-wallet/issuer-spark-wallet.ts
6
+ import {
7
+ NetworkError as NetworkError2,
8
+ SparkWallet,
9
+ ValidationError as ValidationError3
10
+ } from "@buildonspark/spark-sdk";
11
+ import {
12
+ decodeSparkAddress,
13
+ encodeSparkAddress
14
+ } from "@buildonspark/spark-sdk";
15
+ import {
16
+ bytesToHex,
17
+ bytesToNumberBE,
18
+ hexToBytes as hexToBytes2
19
+ } from "@noble/curves/abstract/utils";
20
+ import { decodeBech32mTokenIdentifier } from "@buildonspark/spark-sdk";
21
+
22
+ // src/services/freeze.ts
23
+ import {
24
+ NetworkError,
25
+ collectResponses
26
+ } from "@buildonspark/spark-sdk";
27
+
28
+ // src/utils/token-hashing.ts
29
+ import { sha256 } from "@scure/btc-signer/utils";
30
+ import { ValidationError } from "@buildonspark/spark-sdk";
31
+ function hashFreezeTokensPayload(payload) {
32
+ if (!payload) {
33
+ throw new ValidationError("Freeze tokens payload cannot be nil", {
34
+ field: "payload",
35
+ value: payload,
36
+ expected: "valid freeze tokens payload"
37
+ });
38
+ }
39
+ let allHashes = [];
40
+ const versionHashObj = sha256.create();
41
+ const versionBytes = new Uint8Array(4);
42
+ new DataView(versionBytes.buffer).setUint32(
43
+ 0,
44
+ payload.version,
45
+ false
46
+ // false for big-endian
47
+ );
48
+ versionHashObj.update(versionBytes);
49
+ allHashes.push(versionHashObj.digest());
50
+ const ownerPubKeyHash = sha256.create();
51
+ if (payload.ownerPublicKey) {
52
+ ownerPubKeyHash.update(payload.ownerPublicKey);
53
+ }
54
+ allHashes.push(ownerPubKeyHash.digest());
55
+ const tokenIdentifierHash = sha256.create();
56
+ if (payload.tokenIdentifier) {
57
+ tokenIdentifierHash.update(payload.tokenIdentifier);
58
+ }
59
+ allHashes.push(tokenIdentifierHash.digest());
60
+ const shouldUnfreezeHash = sha256.create();
61
+ shouldUnfreezeHash.update(new Uint8Array([payload.shouldUnfreeze ? 1 : 0]));
62
+ allHashes.push(shouldUnfreezeHash.digest());
63
+ const timestampHash = sha256.create();
64
+ if (payload.issuerProvidedTimestamp) {
65
+ const timestampBytes = new Uint8Array(8);
66
+ new DataView(timestampBytes.buffer).setBigUint64(
67
+ 0,
68
+ BigInt(payload.issuerProvidedTimestamp),
69
+ true
70
+ // true for little-endian
71
+ );
72
+ timestampHash.update(timestampBytes);
73
+ }
74
+ allHashes.push(timestampHash.digest());
75
+ const operatorPubKeyHash = sha256.create();
76
+ if (payload.operatorIdentityPublicKey) {
77
+ operatorPubKeyHash.update(payload.operatorIdentityPublicKey);
78
+ }
79
+ allHashes.push(operatorPubKeyHash.digest());
80
+ const finalHash = sha256.create();
81
+ for (const hash of allHashes) {
82
+ finalHash.update(hash);
83
+ }
84
+ return finalHash.digest();
85
+ }
86
+
87
+ // src/services/freeze.ts
88
+ import { hexToBytes } from "@noble/curves/abstract/utils";
89
+ var TokenFreezeService = class {
90
+ config;
91
+ connectionManager;
92
+ constructor(config, connectionManager) {
93
+ this.config = config;
94
+ this.connectionManager = connectionManager;
95
+ }
96
+ async freezeTokens({
97
+ ownerPublicKey,
98
+ tokenIdentifier
99
+ }) {
100
+ return this.freezeOperation(ownerPublicKey, false, tokenIdentifier);
101
+ }
102
+ async unfreezeTokens({
103
+ ownerPublicKey,
104
+ tokenIdentifier
105
+ }) {
106
+ return this.freezeOperation(ownerPublicKey, true, tokenIdentifier);
107
+ }
108
+ async freezeOperation(ownerPublicKey, shouldUnfreeze, tokenIdentifier) {
109
+ const signingOperators = this.config.getSigningOperators();
110
+ const issuerProvidedTimestamp = Date.now();
111
+ const freezeResponses = await Promise.allSettled(
112
+ Object.entries(signingOperators).map(async ([identifier, operator]) => {
113
+ const sparkTokenClient = await this.connectionManager.createSparkTokenClient(operator.address);
114
+ const freezeTokensPayload = {
115
+ version: 1,
116
+ ownerPublicKey,
117
+ tokenIdentifier,
118
+ shouldUnfreeze,
119
+ issuerProvidedTimestamp,
120
+ operatorIdentityPublicKey: hexToBytes(operator.identityPublicKey)
121
+ };
122
+ const hashedPayload = hashFreezeTokensPayload(freezeTokensPayload);
123
+ const issuerSignature = await this.config.signer.signMessageWithIdentityKey(hashedPayload);
124
+ try {
125
+ const response = await sparkTokenClient.freeze_tokens({
126
+ freezeTokensPayload,
127
+ issuerSignature
128
+ });
129
+ return {
130
+ identifier,
131
+ response
132
+ };
133
+ } catch (error) {
134
+ throw new NetworkError(
135
+ `Failed to send a freeze/unfreeze operation to operator: ${operator.address}`,
136
+ {
137
+ operation: "freeze_tokens",
138
+ errorCount: 1,
139
+ errors: error instanceof Error ? error.message : String(error)
140
+ },
141
+ error instanceof Error ? error : void 0
142
+ );
143
+ }
144
+ })
145
+ );
146
+ const successfulResponses = collectResponses(freezeResponses);
147
+ return successfulResponses[0].response;
148
+ }
149
+ };
150
+
151
+ // src/services/token-transactions.ts
152
+ import { TokenTransactionService } from "@buildonspark/spark-sdk";
153
+ import { numberToBytesBE } from "@noble/curves/abstract/utils";
154
+ var IssuerTokenTransactionService = class extends TokenTransactionService {
155
+ constructor(config, connectionManager) {
156
+ super(config, connectionManager);
157
+ }
158
+ async constructMintTokenTransactionV0(tokenPublicKey, tokenAmount) {
159
+ return {
160
+ network: this.config.getNetworkProto(),
161
+ tokenInputs: {
162
+ $case: "mintInput",
163
+ mintInput: {
164
+ issuerPublicKey: tokenPublicKey,
165
+ issuerProvidedTimestamp: Date.now()
166
+ }
167
+ },
168
+ tokenOutputs: [
169
+ {
170
+ ownerPublicKey: tokenPublicKey,
171
+ tokenPublicKey,
172
+ tokenAmount: numberToBytesBE(tokenAmount, 16)
173
+ }
174
+ ],
175
+ sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys()
176
+ };
177
+ }
178
+ async constructMintTokenTransaction(rawTokenIdentifierBytes, issuerTokenPublicKey, tokenAmount) {
179
+ return {
180
+ version: 1,
181
+ network: this.config.getNetworkProto(),
182
+ tokenInputs: {
183
+ $case: "mintInput",
184
+ mintInput: {
185
+ issuerPublicKey: issuerTokenPublicKey,
186
+ tokenIdentifier: rawTokenIdentifierBytes
187
+ }
188
+ },
189
+ tokenOutputs: [
190
+ {
191
+ ownerPublicKey: issuerTokenPublicKey,
192
+ tokenIdentifier: rawTokenIdentifierBytes,
193
+ tokenAmount: numberToBytesBE(tokenAmount, 16)
194
+ }
195
+ ],
196
+ clientCreatedTimestamp: /* @__PURE__ */ new Date(),
197
+ sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys(),
198
+ expiryTime: void 0
199
+ };
200
+ }
201
+ async constructCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable) {
202
+ return {
203
+ version: 1,
204
+ network: this.config.getNetworkProto(),
205
+ tokenInputs: {
206
+ $case: "createInput",
207
+ createInput: {
208
+ issuerPublicKey: tokenPublicKey,
209
+ tokenName,
210
+ tokenTicker,
211
+ decimals,
212
+ maxSupply: numberToBytesBE(maxSupply, 16),
213
+ isFreezable
214
+ }
215
+ },
216
+ tokenOutputs: [],
217
+ clientCreatedTimestamp: /* @__PURE__ */ new Date(),
218
+ sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys(),
219
+ expiryTime: void 0
220
+ };
221
+ }
222
+ };
223
+
224
+ // src/issuer-wallet/issuer-spark-wallet.ts
225
+ import { NotImplementedError } from "@buildonspark/spark-sdk";
226
+
227
+ // src/utils/create-validation.ts
228
+ import { ValidationError as ValidationError2 } from "@buildonspark/spark-sdk";
229
+ function isNfcNormalized(value) {
230
+ return value.normalize("NFC") === value;
231
+ }
232
+ var MIN_NAME_SIZE = 3;
233
+ var MAX_NAME_SIZE = 20;
234
+ var MIN_SYMBOL_SIZE = 3;
235
+ var MAX_SYMBOL_SIZE = 6;
236
+ var MAX_DECIMALS = 255;
237
+ var MAXIMUM_MAX_SUPPLY = (1n << 128n) - 1n;
238
+ function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply) {
239
+ if (!isNfcNormalized(tokenName)) {
240
+ throw new ValidationError2("Token name must be NFC-normalised UTF-8", {
241
+ field: "tokenName",
242
+ value: tokenName,
243
+ expected: "NFC normalised string"
244
+ });
245
+ }
246
+ if (!isNfcNormalized(tokenTicker)) {
247
+ throw new ValidationError2("Token ticker must be NFC-normalised UTF-8", {
248
+ field: "tokenTicker",
249
+ value: tokenTicker,
250
+ expected: "NFC normalised string"
251
+ });
252
+ }
253
+ const nameBytes = Buffer.from(tokenName, "utf-8").length;
254
+ if (nameBytes < MIN_NAME_SIZE || nameBytes > MAX_NAME_SIZE) {
255
+ throw new ValidationError2(
256
+ `Token name must be between ${MIN_NAME_SIZE} and ${MAX_NAME_SIZE} bytes`,
257
+ {
258
+ field: "tokenName",
259
+ value: tokenName,
260
+ actualLength: nameBytes,
261
+ expected: `>=${MIN_NAME_SIZE} and <=${MAX_NAME_SIZE}`
262
+ }
263
+ );
264
+ }
265
+ const tickerBytes = Buffer.from(tokenTicker, "utf-8").length;
266
+ if (tickerBytes < MIN_SYMBOL_SIZE || tickerBytes > MAX_SYMBOL_SIZE) {
267
+ throw new ValidationError2(
268
+ `Token ticker must be between ${MIN_SYMBOL_SIZE} and ${MAX_SYMBOL_SIZE} bytes`,
269
+ {
270
+ field: "tokenTicker",
271
+ value: tokenTicker,
272
+ actualLength: tickerBytes,
273
+ expected: `>=${MIN_SYMBOL_SIZE} and <=${MAX_SYMBOL_SIZE}`
274
+ }
275
+ );
276
+ }
277
+ if (!Number.isSafeInteger(decimals) || decimals < 0 || decimals > MAX_DECIMALS) {
278
+ throw new ValidationError2(
279
+ `Decimals must be an integer between 0 and ${MAX_DECIMALS}`,
280
+ {
281
+ field: "decimals",
282
+ value: decimals,
283
+ expected: `>=0 and <=${MAX_DECIMALS}`
284
+ }
285
+ );
286
+ }
287
+ if (maxSupply < 0n || maxSupply > MAXIMUM_MAX_SUPPLY) {
288
+ throw new ValidationError2(`maxSupply must be between 0 and 2^128-1`, {
289
+ field: "maxSupply",
290
+ value: maxSupply.toString(),
291
+ expected: `>=0 and <=${MAXIMUM_MAX_SUPPLY.toString()}`
292
+ });
293
+ }
294
+ }
295
+
296
+ // src/issuer-wallet/issuer-spark-wallet.ts
297
+ import {
298
+ encodeBech32mTokenIdentifier
299
+ } from "@buildonspark/spark-sdk";
300
+ var BURN_ADDRESS = "02".repeat(33);
301
+ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
302
+ issuerTokenTransactionService;
303
+ tokenFreezeService;
304
+ tracerId = "issuer-sdk";
305
+ /**
306
+ * Initializes a new IssuerSparkWallet instance.
307
+ * @param options - Configuration options for the wallet
308
+ * @returns An object containing the initialized wallet and initialization response
309
+ */
310
+ static async initialize({
311
+ mnemonicOrSeed,
312
+ accountNumber,
313
+ signer,
314
+ options
315
+ }) {
316
+ const wallet = new _IssuerSparkWallet(options, signer);
317
+ wallet.initializeTracer(wallet);
318
+ const initResponse = await wallet.initWallet(mnemonicOrSeed, accountNumber);
319
+ return {
320
+ wallet,
321
+ ...initResponse
322
+ };
323
+ }
324
+ constructor(configOptions, signer) {
325
+ super(configOptions, signer);
326
+ this.issuerTokenTransactionService = new IssuerTokenTransactionService(
327
+ this.config,
328
+ this.connectionManager
329
+ );
330
+ this.tokenFreezeService = new TokenFreezeService(
331
+ this.config,
332
+ this.connectionManager
333
+ );
334
+ this.wrapIssuerSparkWalletMethodsWithTracing();
335
+ }
336
+ /**
337
+ * Gets the token balance for the issuer's token.
338
+ * @returns An object containing the token balance as a bigint
339
+ */
340
+ async getIssuerTokenBalance() {
341
+ const publicKey = await super.getIdentityPublicKey();
342
+ const balanceObj = await this.getBalance();
343
+ const issuerBalance = [...balanceObj.tokenBalances.entries()].find(
344
+ ([, info]) => info.tokenMetadata.tokenPublicKey === publicKey
345
+ );
346
+ if (!balanceObj.tokenBalances || issuerBalance === void 0) {
347
+ return {
348
+ tokenIdentifier: void 0,
349
+ balance: 0n
350
+ };
351
+ }
352
+ return {
353
+ tokenIdentifier: issuerBalance[0] ?? void 0,
354
+ balance: issuerBalance[1].balance
355
+ };
356
+ }
357
+ /**
358
+ * Retrieves information about the issuer's token.
359
+ * @returns An object containing token information including public key, name, symbol, decimals, max supply, and freeze status
360
+ * @throws {NetworkError} If the token metadata cannot be retrieved
361
+ */
362
+ async getIssuerTokenMetadata() {
363
+ const issuerPublicKey = await super.getIdentityPublicKey();
364
+ const tokenMetadata = this.tokenMetadata;
365
+ const cachedIssuerTokenMetadata = [...tokenMetadata.entries()].find(
366
+ ([, metadata]) => bytesToHex(metadata.issuerPublicKey) === issuerPublicKey
367
+ );
368
+ if (cachedIssuerTokenMetadata !== void 0) {
369
+ const metadata = cachedIssuerTokenMetadata[1];
370
+ return {
371
+ tokenPublicKey: bytesToHex(metadata.issuerPublicKey),
372
+ rawTokenIdentifier: metadata.tokenIdentifier,
373
+ tokenName: metadata.tokenName,
374
+ tokenTicker: metadata.tokenTicker,
375
+ decimals: metadata.decimals,
376
+ maxSupply: bytesToNumberBE(metadata.maxSupply),
377
+ isFreezable: metadata.isFreezable
378
+ };
379
+ }
380
+ const sparkTokenClient = await this.connectionManager.createSparkTokenClient(
381
+ this.config.getCoordinatorAddress()
382
+ );
383
+ try {
384
+ const response = await sparkTokenClient.query_token_metadata({
385
+ issuerPublicKeys: Array.of(hexToBytes2(issuerPublicKey))
386
+ });
387
+ if (response.tokenMetadata.length === 0) {
388
+ throw new ValidationError3(
389
+ "Token metadata not found - If a token has not yet been created, please create it first. Try again in a few seconds.",
390
+ {
391
+ field: "tokenMetadata",
392
+ value: response.tokenMetadata,
393
+ expected: "non-empty array",
394
+ actualLength: response.tokenMetadata.length,
395
+ expectedLength: 1
396
+ }
397
+ );
398
+ }
399
+ const metadata = response.tokenMetadata[0];
400
+ const tokenIdentifier = encodeBech32mTokenIdentifier({
401
+ tokenIdentifier: metadata.tokenIdentifier,
402
+ network: this.config.getNetworkType()
403
+ });
404
+ this.tokenMetadata.set(tokenIdentifier, metadata);
405
+ return {
406
+ tokenPublicKey: bytesToHex(metadata.issuerPublicKey),
407
+ rawTokenIdentifier: metadata.tokenIdentifier,
408
+ tokenName: metadata.tokenName,
409
+ tokenTicker: metadata.tokenTicker,
410
+ decimals: metadata.decimals,
411
+ maxSupply: bytesToNumberBE(metadata.maxSupply),
412
+ isFreezable: metadata.isFreezable
413
+ };
414
+ } catch (error) {
415
+ throw new NetworkError2("Failed to fetch token metadata", {
416
+ errorCount: 1,
417
+ errors: error instanceof Error ? error.message : String(error)
418
+ });
419
+ }
420
+ }
421
+ /**
422
+ * Retrieves the bech32m encoded token identifier for the issuer's token.
423
+ * @returns The bech32m encoded token identifier for the issuer's token
424
+ * @throws {NetworkError} If the token identifier cannot be retrieved
425
+ */
426
+ async getIssuerTokenIdentifier() {
427
+ const tokenMetadata = await this.getIssuerTokenMetadata();
428
+ return encodeBech32mTokenIdentifier({
429
+ tokenIdentifier: tokenMetadata.rawTokenIdentifier,
430
+ network: this.config.getNetworkType()
431
+ });
432
+ }
433
+ /**
434
+ * Create a new token on Spark.
435
+ *
436
+ * @param params - Object containing token creation parameters.
437
+ * @param params.tokenName - The name of the token.
438
+ * @param params.tokenTicker - The ticker symbol for the token.
439
+ * @param params.decimals - The number of decimal places for the token.
440
+ * @param params.isFreezable - Whether the token can be frozen.
441
+ * @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
442
+ *
443
+ * @returns The transaction ID of the announcement.
444
+ *
445
+ * @throws {ValidationError} If `decimals` is not a safe integer or other validation fails.
446
+ * @throws {NetworkError} If the announcement transaction cannot be broadcast.
447
+ */
448
+ async createToken({
449
+ tokenName,
450
+ tokenTicker,
451
+ decimals,
452
+ isFreezable,
453
+ maxSupply = 0n
454
+ }) {
455
+ validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply);
456
+ const issuerPublicKey = await super.getIdentityPublicKey();
457
+ const tokenTransaction = await this.issuerTokenTransactionService.constructCreateTokenTransaction(
458
+ hexToBytes2(issuerPublicKey),
459
+ tokenName,
460
+ tokenTicker,
461
+ decimals,
462
+ maxSupply,
463
+ isFreezable
464
+ );
465
+ return await this.issuerTokenTransactionService.broadcastTokenTransaction(
466
+ tokenTransaction
467
+ );
468
+ }
469
+ /**
470
+ * Mints new tokens
471
+ * @param tokenAmount - The amount of tokens to mint
472
+ * @returns The transaction ID of the mint operation
473
+ */
474
+ async mintTokens(tokenAmount) {
475
+ let tokenTransaction;
476
+ const issuerTokenPublicKey = await super.getIdentityPublicKey();
477
+ const issuerTokenPublicKeyBytes = hexToBytes2(issuerTokenPublicKey);
478
+ const tokenMetadata = await this.getIssuerTokenMetadata();
479
+ const rawTokenIdentifier = tokenMetadata.rawTokenIdentifier;
480
+ if (this.config.getTokenTransactionVersion() === "V0") {
481
+ tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransactionV0(
482
+ issuerTokenPublicKeyBytes,
483
+ tokenAmount
484
+ );
485
+ } else {
486
+ tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
487
+ rawTokenIdentifier,
488
+ issuerTokenPublicKeyBytes,
489
+ tokenAmount
490
+ );
491
+ }
492
+ return await this.issuerTokenTransactionService.broadcastTokenTransaction(
493
+ tokenTransaction
494
+ );
495
+ }
496
+ /**
497
+ * Burns issuer's tokens
498
+ * @param tokenAmount - The amount of tokens to burn
499
+ * @param selectedOutputs - Optional array of outputs to use for the burn operation
500
+ * @returns The transaction ID of the burn operation
501
+ */
502
+ async burnTokens(tokenAmount, selectedOutputs) {
503
+ const burnAddress = encodeSparkAddress({
504
+ identityPublicKey: BURN_ADDRESS,
505
+ network: this.config.getNetworkType()
506
+ });
507
+ const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
508
+ return await this.transferTokens({
509
+ tokenIdentifier: issuerTokenIdentifier,
510
+ tokenAmount,
511
+ receiverSparkAddress: burnAddress,
512
+ selectedOutputs
513
+ });
514
+ }
515
+ /**
516
+ * Freezes tokens associated with a specific Spark address.
517
+ * @param sparkAddress - The Spark address whose tokens should be frozen
518
+ * @returns An object containing the IDs of impacted outputs and the total amount of frozen tokens
519
+ */
520
+ async freezeTokens(sparkAddress) {
521
+ await this.syncTokenOutputs();
522
+ const decodedOwnerPubkey = decodeSparkAddress(
523
+ sparkAddress,
524
+ this.config.getNetworkType()
525
+ );
526
+ const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
527
+ const rawTokenIdentifier = decodeBech32mTokenIdentifier(
528
+ issuerTokenIdentifier,
529
+ this.config.getNetworkType()
530
+ ).tokenIdentifier;
531
+ const response = await this.tokenFreezeService.freezeTokens({
532
+ ownerPublicKey: hexToBytes2(decodedOwnerPubkey.identityPublicKey),
533
+ tokenIdentifier: rawTokenIdentifier
534
+ });
535
+ const tokenAmount = bytesToNumberBE(response.impactedTokenAmount);
536
+ return {
537
+ impactedOutputIds: response.impactedOutputIds,
538
+ impactedTokenAmount: tokenAmount
539
+ };
540
+ }
541
+ /**
542
+ * Unfreezes previously frozen tokens associated with a specific Spark address.
543
+ * @param sparkAddress - The Spark address whose tokens should be unfrozen
544
+ * @returns An object containing the IDs of impacted outputs and the total amount of unfrozen tokens
545
+ */
546
+ async unfreezeTokens(sparkAddress) {
547
+ await this.syncTokenOutputs();
548
+ const decodedOwnerPubkey = decodeSparkAddress(
549
+ sparkAddress,
550
+ this.config.getNetworkType()
551
+ );
552
+ const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
553
+ const rawTokenIdentifier = decodeBech32mTokenIdentifier(
554
+ issuerTokenIdentifier,
555
+ this.config.getNetworkType()
556
+ ).tokenIdentifier;
557
+ const response = await this.tokenFreezeService.unfreezeTokens({
558
+ ownerPublicKey: hexToBytes2(decodedOwnerPubkey.identityPublicKey),
559
+ tokenIdentifier: rawTokenIdentifier
560
+ });
561
+ const tokenAmount = bytesToNumberBE(response.impactedTokenAmount);
562
+ return {
563
+ impactedOutputIds: response.impactedOutputIds,
564
+ impactedTokenAmount: tokenAmount
565
+ };
566
+ }
567
+ /**
568
+ * Retrieves the distribution information for the issuer's token.
569
+ * @throws {NotImplementedError} This feature is not yet supported
570
+ */
571
+ async getIssuerTokenDistribution() {
572
+ throw new NotImplementedError("Token distribution is not yet supported");
573
+ }
574
+ getTraceName(methodName) {
575
+ return `IssuerSparkWallet.${methodName}`;
576
+ }
577
+ wrapPublicIssuerSparkWalletMethodWithOtelSpan(methodName) {
578
+ const original = this[methodName];
579
+ if (typeof original !== "function") {
580
+ throw new Error(
581
+ `Method ${methodName} is not a function on IssuerSparkWallet.`
582
+ );
583
+ }
584
+ const wrapped = this.wrapWithOtelSpan(
585
+ this.getTraceName(methodName),
586
+ original.bind(this)
587
+ );
588
+ this[methodName] = wrapped;
589
+ }
590
+ wrapIssuerSparkWalletMethodsWithTracing() {
591
+ const methods = [
592
+ "getIssuerTokenBalance",
593
+ "getIssuerTokenMetadata",
594
+ "getIssuerTokenIdentifier",
595
+ "createToken",
596
+ "mintTokens",
597
+ "burnTokens",
598
+ "freezeTokens",
599
+ "unfreezeTokens",
600
+ "getIssuerTokenDistribution"
601
+ ];
602
+ methods.forEach(
603
+ (m) => this.wrapPublicIssuerSparkWalletMethodWithOtelSpan(m)
604
+ );
605
+ }
606
+ };
607
+
608
+ export {
609
+ IssuerSparkWallet
610
+ };