@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.
@@ -1,4 +1,3 @@
1
- import { TokenPubkey, TokenPubkeyAnnouncement } from "@buildonspark/lrc20-sdk";
2
1
  import {
3
2
  NetworkError,
4
3
  SparkWallet,
@@ -57,62 +56,16 @@ export class IssuerSparkWallet extends SparkWallet {
57
56
  options,
58
57
  }: SparkWalletProps) {
59
58
  const wallet = new IssuerSparkWallet(options, signer);
59
+ wallet.initializeTracer(wallet);
60
60
 
61
61
  const initResponse = await wallet.initWallet(mnemonicOrSeed, accountNumber);
62
62
 
63
- if (isNode) {
64
- wallet.wrapIssuerSparkWalletWithTracing();
65
- }
66
-
67
63
  return {
68
64
  wallet,
69
65
  ...initResponse,
70
66
  };
71
67
  }
72
68
 
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
69
  protected constructor(configOptions?: ConfigOptions, signer?: SparkSigner) {
117
70
  super(configOptions, signer);
118
71
  this.issuerTokenTransactionService = new IssuerTokenTransactionService(
@@ -123,6 +76,7 @@ export class IssuerSparkWallet extends SparkWallet {
123
76
  this.config,
124
77
  this.connectionManager,
125
78
  );
79
+ this.wrapIssuerSparkWalletMethodsWithTracing();
126
80
  }
127
81
 
128
82
  /**
@@ -187,7 +141,7 @@ export class IssuerSparkWallet extends SparkWallet {
187
141
  });
188
142
  if (response.tokenMetadata.length === 0) {
189
143
  throw new ValidationError(
190
- "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.",
144
+ "Token metadata not found - If a token has not yet been created, please create it first. Try again in a few seconds.",
191
145
  {
192
146
  field: "tokenMetadata",
193
147
  value: response.tokenMetadata,
@@ -226,7 +180,7 @@ export class IssuerSparkWallet extends SparkWallet {
226
180
  * @returns The bech32m encoded token identifier for the issuer's token
227
181
  * @throws {NetworkError} If the token identifier cannot be retrieved
228
182
  */
229
- public async getIssuerTokenIdentifier(): Promise<Bech32mTokenIdentifier | null> {
183
+ public async getIssuerTokenIdentifier(): Promise<Bech32mTokenIdentifier> {
230
184
  const tokenMetadata = await this.getIssuerTokenMetadata();
231
185
 
232
186
  return encodeBech32mTokenIdentifier({
@@ -329,11 +283,8 @@ export class IssuerSparkWallet extends SparkWallet {
329
283
  identityPublicKey: BURN_ADDRESS,
330
284
  network: this.config.getNetworkType(),
331
285
  });
332
- const issuerTokenIdentifier: Bech32mTokenIdentifier | null =
286
+ const issuerTokenIdentifier: Bech32mTokenIdentifier =
333
287
  await this.getIssuerTokenIdentifier();
334
- if (issuerTokenIdentifier === null) {
335
- throw new ValidationError("Issuer token identifier not found");
336
- }
337
288
 
338
289
  return await this.transferTokens({
339
290
  tokenIdentifier: issuerTokenIdentifier,
@@ -358,13 +309,6 @@ export class IssuerSparkWallet extends SparkWallet {
358
309
  );
359
310
 
360
311
  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
312
 
369
313
  const rawTokenIdentifier = decodeBech32mTokenIdentifier(
370
314
  issuerTokenIdentifier,
@@ -400,13 +344,6 @@ export class IssuerSparkWallet extends SparkWallet {
400
344
  );
401
345
 
402
346
  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
347
 
411
348
  const rawTokenIdentifier = decodeBech32mTokenIdentifier(
412
349
  issuerTokenIdentifier,
@@ -433,69 +370,44 @@ export class IssuerSparkWallet extends SparkWallet {
433
370
  throw new NotImplementedError("Token distribution is not yet supported");
434
371
  }
435
372
 
436
- /**
437
- * Announces a new token on the L1 (Bitcoin) network.
438
- * @param tokenName - The name of the token
439
- * @param tokenTicker - The ticker symbol for the token
440
- * @param decimals - The number of decimal places for the token
441
- * @param maxSupply - The maximum supply of the token
442
- * @param isFreezable - Whether the token can be frozen
443
- * @param feeRateSatsPerVb - The fee rate in satoshis per virtual byte (default: 4.0)
444
- * @returns The transaction ID of the announcement
445
- * @throws {ValidationError} If decimals is not a safe integer
446
- * @throws {NetworkError} If the announcement transaction cannot be broadcast
447
- */
448
- public async announceTokenL1(
449
- tokenName: string,
450
- tokenTicker: string,
451
- decimals: number,
452
- maxSupply: bigint,
453
- isFreezable: boolean,
454
- feeRateSatsPerVb: number = 4.0,
455
- ): Promise<string> {
456
- validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply);
373
+ protected getTraceName(methodName: string) {
374
+ return `IssuerSparkWallet.${methodName}`;
375
+ }
457
376
 
458
- if (!Number.isSafeInteger(decimals)) {
459
- throw new ValidationError("Decimals must be less than 2^53", {
460
- field: "decimals",
461
- value: decimals,
462
- expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER,
463
- });
377
+ private wrapPublicIssuerSparkWalletMethodWithOtelSpan<
378
+ M extends keyof IssuerSparkWallet,
379
+ >(methodName: M) {
380
+ const original = this[methodName];
381
+
382
+ if (typeof original !== "function") {
383
+ throw new Error(
384
+ `Method ${methodName} is not a function on IssuerSparkWallet.`,
385
+ );
464
386
  }
465
387
 
466
- await this.lrc20Wallet!.syncWallet();
388
+ const wrapped = this.wrapWithOtelSpan(
389
+ this.getTraceName(methodName),
390
+ original.bind(this) as (...args: unknown[]) => Promise<unknown>,
391
+ ) as IssuerSparkWallet[M];
467
392
 
468
- const tokenPublicKey = new TokenPubkey(this.lrc20Wallet!.pubkey);
393
+ (this as IssuerSparkWallet)[methodName] = wrapped;
394
+ }
469
395
 
470
- const announcement = new TokenPubkeyAnnouncement(
471
- tokenPublicKey,
472
- tokenName,
473
- tokenTicker,
474
- decimals,
475
- maxSupply,
476
- isFreezable,
396
+ private wrapIssuerSparkWalletMethodsWithTracing() {
397
+ const methods = [
398
+ "getIssuerTokenBalance",
399
+ "getIssuerTokenMetadata",
400
+ "getIssuerTokenIdentifier",
401
+ "createToken",
402
+ "mintTokens",
403
+ "burnTokens",
404
+ "freezeTokens",
405
+ "unfreezeTokens",
406
+ "getIssuerTokenDistribution",
407
+ ] as const;
408
+
409
+ methods.forEach((m) =>
410
+ this.wrapPublicIssuerSparkWalletMethodWithOtelSpan(m),
477
411
  );
478
-
479
- try {
480
- const tx = await this.lrc20Wallet!.prepareAnnouncement(
481
- announcement,
482
- feeRateSatsPerVb,
483
- );
484
-
485
- const txId = await this.lrc20Wallet!.broadcastRawBtcTransaction(
486
- tx.bitcoin_tx.toHex(),
487
- );
488
-
489
- return txId;
490
- } catch (error) {
491
- throw new NetworkError(
492
- "Failed to broadcast announcement transaction on L1",
493
- {
494
- operation: "broadcastRawBtcTransaction",
495
- errorCount: 1,
496
- errors: error instanceof Error ? error.message : String(error),
497
- },
498
- );
499
- }
500
412
  }
501
413
  }