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