@buildonspark/issuer-sdk 0.0.41 → 0.0.43

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.cjs CHANGED
@@ -345,6 +345,11 @@ var BURN_ADDRESS = "02".repeat(33);
345
345
  var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.SparkWallet {
346
346
  issuerTokenTransactionService;
347
347
  tokenFreezeService;
348
+ /**
349
+ * Initializes a new IssuerSparkWallet instance.
350
+ * @param options - Configuration options for the wallet
351
+ * @returns An object containing the initialized wallet and initialization response
352
+ */
348
353
  static async initialize(options) {
349
354
  const wallet = new _IssuerSparkWallet(options.options);
350
355
  const initResponse = await wallet.initWallet(options.mnemonicOrSeed);
@@ -364,6 +369,10 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
364
369
  this.connectionManager
365
370
  );
366
371
  }
372
+ /**
373
+ * Gets the token balance for the issuer's token.
374
+ * @returns An object containing the token balance as a bigint
375
+ */
367
376
  async getIssuerTokenBalance() {
368
377
  const publicKey = await super.getIdentityPublicKey();
369
378
  const balanceObj = await this.getBalance();
@@ -376,6 +385,11 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
376
385
  balance: balanceObj.tokenBalances.get(publicKey).balance
377
386
  };
378
387
  }
388
+ /**
389
+ * Retrieves information about the issuer's token.
390
+ * @returns An object containing token information including public key, name, symbol, decimals, max supply, and freeze status
391
+ * @throws {NetworkError} If the token info cannot be retrieved
392
+ */
379
393
  async getIssuerTokenInfo() {
380
394
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
381
395
  try {
@@ -399,6 +413,11 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
399
413
  });
400
414
  }
401
415
  }
416
+ /**
417
+ * Mints new tokens
418
+ * @param tokenAmount - The amount of tokens to mint
419
+ * @returns The transaction ID of the mint operation
420
+ */
402
421
  async mintTokens(tokenAmount) {
403
422
  var tokenPublicKey = await super.getIdentityPublicKey();
404
423
  const tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
@@ -409,6 +428,12 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
409
428
  tokenTransaction
410
429
  );
411
430
  }
431
+ /**
432
+ * Burns issuer's tokens
433
+ * @param tokenAmount - The amount of tokens to burn
434
+ * @param selectedOutputs - Optional array of outputs to use for the burn operation
435
+ * @returns The transaction ID of the burn operation
436
+ */
412
437
  async burnTokens(tokenAmount, selectedOutputs) {
413
438
  const burnAddress = (0, import_address.encodeSparkAddress)({
414
439
  identityPublicKey: BURN_ADDRESS,
@@ -421,6 +446,11 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
421
446
  selectedOutputs
422
447
  });
423
448
  }
449
+ /**
450
+ * Freezes tokens associated with a specific Spark address.
451
+ * @param sparkAddress - The Spark address whose tokens should be frozen
452
+ * @returns An object containing the IDs of impacted outputs and the total amount of frozen tokens
453
+ */
424
454
  async freezeTokens(sparkAddress) {
425
455
  await this.syncTokenOutputs();
426
456
  const tokenPublicKey = await super.getIdentityPublicKey();
@@ -438,6 +468,11 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
438
468
  impactedTokenAmount: tokenAmount
439
469
  };
440
470
  }
471
+ /**
472
+ * Unfreezes previously frozen tokens associated with a specific Spark address.
473
+ * @param sparkAddress - The Spark address whose tokens should be unfrozen
474
+ * @returns An object containing the IDs of impacted outputs and the total amount of unfrozen tokens
475
+ */
441
476
  async unfreezeTokens(sparkAddress) {
442
477
  await this.syncTokenOutputs();
443
478
  const tokenPublicKey = await super.getIdentityPublicKey();
@@ -455,7 +490,25 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
455
490
  impactedTokenAmount: tokenAmount
456
491
  };
457
492
  }
493
+ /**
494
+ * Retrieves the activity history for the issuer's token.
495
+ * @param pageSize - The number of transactions to return per page (default: 100)
496
+ * @param cursor - Optional cursor for pagination
497
+ * @param operationTypes - Optional array of operation types to filter by
498
+ * @param beforeTimestamp - Optional timestamp to filter transactions before
499
+ * @param afterTimestamp - Optional timestamp to filter transactions after
500
+ * @returns An object containing the token activity data
501
+ * @throws {ValidationError} If pageSize is not a safe integer
502
+ * @throws {NetworkError} If the activity data cannot be retrieved
503
+ */
458
504
  async getIssuerTokenActivity(pageSize = 100, cursor, operationTypes, beforeTimestamp, afterTimestamp) {
505
+ if (!Number.isSafeInteger(pageSize)) {
506
+ throw new import_spark_sdk3.ValidationError("pageSize must be less than 2^53", {
507
+ field: "pageSize",
508
+ value: pageSize,
509
+ expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER
510
+ });
511
+ }
459
512
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
460
513
  try {
461
514
  const transactions = await lrc20Client.listTransactions({
@@ -475,10 +528,33 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
475
528
  });
476
529
  }
477
530
  }
531
+ /**
532
+ * Retrieves the distribution information for the issuer's token.
533
+ * @throws {NotImplementedError} This feature is not yet supported
534
+ */
478
535
  async getIssuerTokenDistribution() {
479
536
  throw new import_spark_sdk4.NotImplementedError("Token distribution is not yet supported");
480
537
  }
538
+ /**
539
+ * Announces a new token on the L1 (Bitcoin) network.
540
+ * @param tokenName - The name of the token
541
+ * @param tokenTicker - The ticker symbol for the token
542
+ * @param decimals - The number of decimal places for the token
543
+ * @param maxSupply - The maximum supply of the token
544
+ * @param isFreezable - Whether the token can be frozen
545
+ * @param feeRateSatsPerVb - The fee rate in satoshis per virtual byte (default: 4.0)
546
+ * @returns The transaction ID of the announcement
547
+ * @throws {ValidationError} If decimals is not a safe integer
548
+ * @throws {NetworkError} If the announcement transaction cannot be broadcast
549
+ */
481
550
  async announceTokenL1(tokenName, tokenTicker, decimals, maxSupply, isFreezable, feeRateSatsPerVb = 4) {
551
+ if (!Number.isSafeInteger(decimals)) {
552
+ throw new import_spark_sdk3.ValidationError("Decimals must be less than 2^53", {
553
+ field: "decimals",
554
+ value: decimals,
555
+ expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER
556
+ });
557
+ }
482
558
  await this.lrc20Wallet.syncWallet();
483
559
  const tokenPublicKey = new import_lrc20_sdk2.TokenPubkey(this.lrc20Wallet.pubkey);
484
560
  const announcement = new import_lrc20_sdk2.TokenPubkeyAnnouncement(
package/dist/index.d.cts CHANGED
@@ -12,30 +12,97 @@ type IssuerTokenInfo = {
12
12
  maxSupply: bigint;
13
13
  isFreezable: boolean;
14
14
  };
15
+ /**
16
+ * Represents a Spark wallet with minting capabilities.
17
+ * This class extends the base SparkWallet with additional functionality for token minting,
18
+ * burning, and freezing operations.
19
+ */
15
20
  declare class IssuerSparkWallet extends SparkWallet {
16
21
  private issuerTokenTransactionService;
17
22
  private tokenFreezeService;
23
+ /**
24
+ * Initializes a new IssuerSparkWallet instance.
25
+ * @param options - Configuration options for the wallet
26
+ * @returns An object containing the initialized wallet and initialization response
27
+ */
18
28
  static initialize(options: SparkWalletProps): Promise<{
19
29
  mnemonic?: string | undefined;
20
30
  wallet: IssuerSparkWallet;
21
31
  }>;
22
32
  protected constructor(configOptions?: ConfigOptions);
33
+ /**
34
+ * Gets the token balance for the issuer's token.
35
+ * @returns An object containing the token balance as a bigint
36
+ */
23
37
  getIssuerTokenBalance(): Promise<{
24
38
  balance: bigint;
25
39
  }>;
40
+ /**
41
+ * Retrieves information about the issuer's token.
42
+ * @returns An object containing token information including public key, name, symbol, decimals, max supply, and freeze status
43
+ * @throws {NetworkError} If the token info cannot be retrieved
44
+ */
26
45
  getIssuerTokenInfo(): Promise<IssuerTokenInfo | null>;
46
+ /**
47
+ * Mints new tokens
48
+ * @param tokenAmount - The amount of tokens to mint
49
+ * @returns The transaction ID of the mint operation
50
+ */
27
51
  mintTokens(tokenAmount: bigint): Promise<string>;
52
+ /**
53
+ * Burns issuer's tokens
54
+ * @param tokenAmount - The amount of tokens to burn
55
+ * @param selectedOutputs - Optional array of outputs to use for the burn operation
56
+ * @returns The transaction ID of the burn operation
57
+ */
28
58
  burnTokens(tokenAmount: bigint, selectedOutputs?: OutputWithPreviousTransactionData[]): Promise<string>;
59
+ /**
60
+ * Freezes tokens associated with a specific Spark address.
61
+ * @param sparkAddress - The Spark address whose tokens should be frozen
62
+ * @returns An object containing the IDs of impacted outputs and the total amount of frozen tokens
63
+ */
29
64
  freezeTokens(sparkAddress: string): Promise<{
30
65
  impactedOutputIds: string[];
31
66
  impactedTokenAmount: bigint;
32
67
  }>;
68
+ /**
69
+ * Unfreezes previously frozen tokens associated with a specific Spark address.
70
+ * @param sparkAddress - The Spark address whose tokens should be unfrozen
71
+ * @returns An object containing the IDs of impacted outputs and the total amount of unfrozen tokens
72
+ */
33
73
  unfreezeTokens(sparkAddress: string): Promise<{
34
74
  impactedOutputIds: string[];
35
75
  impactedTokenAmount: bigint;
36
76
  }>;
77
+ /**
78
+ * Retrieves the activity history for the issuer's token.
79
+ * @param pageSize - The number of transactions to return per page (default: 100)
80
+ * @param cursor - Optional cursor for pagination
81
+ * @param operationTypes - Optional array of operation types to filter by
82
+ * @param beforeTimestamp - Optional timestamp to filter transactions before
83
+ * @param afterTimestamp - Optional timestamp to filter transactions after
84
+ * @returns An object containing the token activity data
85
+ * @throws {ValidationError} If pageSize is not a safe integer
86
+ * @throws {NetworkError} If the activity data cannot be retrieved
87
+ */
37
88
  getIssuerTokenActivity(pageSize?: number, cursor?: ListAllTokenTransactionsCursor, operationTypes?: OperationType[], beforeTimestamp?: Date, afterTimestamp?: Date): Promise<GetTokenActivityResponse>;
89
+ /**
90
+ * Retrieves the distribution information for the issuer's token.
91
+ * @throws {NotImplementedError} This feature is not yet supported
92
+ */
38
93
  getIssuerTokenDistribution(): Promise<TokenDistribution>;
94
+ /**
95
+ * Announces a new token on the L1 (Bitcoin) network.
96
+ * @param tokenName - The name of the token
97
+ * @param tokenTicker - The ticker symbol for the token
98
+ * @param decimals - The number of decimal places for the token
99
+ * @param maxSupply - The maximum supply of the token
100
+ * @param isFreezable - Whether the token can be frozen
101
+ * @param feeRateSatsPerVb - The fee rate in satoshis per virtual byte (default: 4.0)
102
+ * @returns The transaction ID of the announcement
103
+ * @throws {ValidationError} If decimals is not a safe integer
104
+ * @throws {NetworkError} If the announcement transaction cannot be broadcast
105
+ */
39
106
  announceTokenL1(tokenName: string, tokenTicker: string, decimals: number, maxSupply: bigint, isFreezable: boolean, feeRateSatsPerVb?: number): Promise<string>;
40
107
  }
41
108
 
package/dist/index.d.ts CHANGED
@@ -12,30 +12,97 @@ type IssuerTokenInfo = {
12
12
  maxSupply: bigint;
13
13
  isFreezable: boolean;
14
14
  };
15
+ /**
16
+ * Represents a Spark wallet with minting capabilities.
17
+ * This class extends the base SparkWallet with additional functionality for token minting,
18
+ * burning, and freezing operations.
19
+ */
15
20
  declare class IssuerSparkWallet extends SparkWallet {
16
21
  private issuerTokenTransactionService;
17
22
  private tokenFreezeService;
23
+ /**
24
+ * Initializes a new IssuerSparkWallet instance.
25
+ * @param options - Configuration options for the wallet
26
+ * @returns An object containing the initialized wallet and initialization response
27
+ */
18
28
  static initialize(options: SparkWalletProps): Promise<{
19
29
  mnemonic?: string | undefined;
20
30
  wallet: IssuerSparkWallet;
21
31
  }>;
22
32
  protected constructor(configOptions?: ConfigOptions);
33
+ /**
34
+ * Gets the token balance for the issuer's token.
35
+ * @returns An object containing the token balance as a bigint
36
+ */
23
37
  getIssuerTokenBalance(): Promise<{
24
38
  balance: bigint;
25
39
  }>;
40
+ /**
41
+ * Retrieves information about the issuer's token.
42
+ * @returns An object containing token information including public key, name, symbol, decimals, max supply, and freeze status
43
+ * @throws {NetworkError} If the token info cannot be retrieved
44
+ */
26
45
  getIssuerTokenInfo(): Promise<IssuerTokenInfo | null>;
46
+ /**
47
+ * Mints new tokens
48
+ * @param tokenAmount - The amount of tokens to mint
49
+ * @returns The transaction ID of the mint operation
50
+ */
27
51
  mintTokens(tokenAmount: bigint): Promise<string>;
52
+ /**
53
+ * Burns issuer's tokens
54
+ * @param tokenAmount - The amount of tokens to burn
55
+ * @param selectedOutputs - Optional array of outputs to use for the burn operation
56
+ * @returns The transaction ID of the burn operation
57
+ */
28
58
  burnTokens(tokenAmount: bigint, selectedOutputs?: OutputWithPreviousTransactionData[]): Promise<string>;
59
+ /**
60
+ * Freezes tokens associated with a specific Spark address.
61
+ * @param sparkAddress - The Spark address whose tokens should be frozen
62
+ * @returns An object containing the IDs of impacted outputs and the total amount of frozen tokens
63
+ */
29
64
  freezeTokens(sparkAddress: string): Promise<{
30
65
  impactedOutputIds: string[];
31
66
  impactedTokenAmount: bigint;
32
67
  }>;
68
+ /**
69
+ * Unfreezes previously frozen tokens associated with a specific Spark address.
70
+ * @param sparkAddress - The Spark address whose tokens should be unfrozen
71
+ * @returns An object containing the IDs of impacted outputs and the total amount of unfrozen tokens
72
+ */
33
73
  unfreezeTokens(sparkAddress: string): Promise<{
34
74
  impactedOutputIds: string[];
35
75
  impactedTokenAmount: bigint;
36
76
  }>;
77
+ /**
78
+ * Retrieves the activity history for the issuer's token.
79
+ * @param pageSize - The number of transactions to return per page (default: 100)
80
+ * @param cursor - Optional cursor for pagination
81
+ * @param operationTypes - Optional array of operation types to filter by
82
+ * @param beforeTimestamp - Optional timestamp to filter transactions before
83
+ * @param afterTimestamp - Optional timestamp to filter transactions after
84
+ * @returns An object containing the token activity data
85
+ * @throws {ValidationError} If pageSize is not a safe integer
86
+ * @throws {NetworkError} If the activity data cannot be retrieved
87
+ */
37
88
  getIssuerTokenActivity(pageSize?: number, cursor?: ListAllTokenTransactionsCursor, operationTypes?: OperationType[], beforeTimestamp?: Date, afterTimestamp?: Date): Promise<GetTokenActivityResponse>;
89
+ /**
90
+ * Retrieves the distribution information for the issuer's token.
91
+ * @throws {NotImplementedError} This feature is not yet supported
92
+ */
38
93
  getIssuerTokenDistribution(): Promise<TokenDistribution>;
94
+ /**
95
+ * Announces a new token on the L1 (Bitcoin) network.
96
+ * @param tokenName - The name of the token
97
+ * @param tokenTicker - The ticker symbol for the token
98
+ * @param decimals - The number of decimal places for the token
99
+ * @param maxSupply - The maximum supply of the token
100
+ * @param isFreezable - Whether the token can be frozen
101
+ * @param feeRateSatsPerVb - The fee rate in satoshis per virtual byte (default: 4.0)
102
+ * @returns The transaction ID of the announcement
103
+ * @throws {ValidationError} If decimals is not a safe integer
104
+ * @throws {NetworkError} If the announcement transaction cannot be broadcast
105
+ */
39
106
  announceTokenL1(tokenName: string, tokenTicker: string, decimals: number, maxSupply: bigint, isFreezable: boolean, feeRateSatsPerVb?: number): Promise<string>;
40
107
  }
41
108
 
package/dist/index.js CHANGED
@@ -4,7 +4,8 @@ import "./chunk-GB7N6I5O.js";
4
4
  import { TokenPubkey, TokenPubkeyAnnouncement } from "@buildonspark/lrc20-sdk";
5
5
  import {
6
6
  NetworkError as NetworkError2,
7
- SparkWallet
7
+ SparkWallet,
8
+ ValidationError as ValidationError2
8
9
  } from "@buildonspark/spark-sdk";
9
10
  import {
10
11
  decodeSparkAddress,
@@ -322,6 +323,11 @@ var BURN_ADDRESS = "02".repeat(33);
322
323
  var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
323
324
  issuerTokenTransactionService;
324
325
  tokenFreezeService;
326
+ /**
327
+ * Initializes a new IssuerSparkWallet instance.
328
+ * @param options - Configuration options for the wallet
329
+ * @returns An object containing the initialized wallet and initialization response
330
+ */
325
331
  static async initialize(options) {
326
332
  const wallet = new _IssuerSparkWallet(options.options);
327
333
  const initResponse = await wallet.initWallet(options.mnemonicOrSeed);
@@ -341,6 +347,10 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
341
347
  this.connectionManager
342
348
  );
343
349
  }
350
+ /**
351
+ * Gets the token balance for the issuer's token.
352
+ * @returns An object containing the token balance as a bigint
353
+ */
344
354
  async getIssuerTokenBalance() {
345
355
  const publicKey = await super.getIdentityPublicKey();
346
356
  const balanceObj = await this.getBalance();
@@ -353,6 +363,11 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
353
363
  balance: balanceObj.tokenBalances.get(publicKey).balance
354
364
  };
355
365
  }
366
+ /**
367
+ * Retrieves information about the issuer's token.
368
+ * @returns An object containing token information including public key, name, symbol, decimals, max supply, and freeze status
369
+ * @throws {NetworkError} If the token info cannot be retrieved
370
+ */
356
371
  async getIssuerTokenInfo() {
357
372
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
358
373
  try {
@@ -376,6 +391,11 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
376
391
  });
377
392
  }
378
393
  }
394
+ /**
395
+ * Mints new tokens
396
+ * @param tokenAmount - The amount of tokens to mint
397
+ * @returns The transaction ID of the mint operation
398
+ */
379
399
  async mintTokens(tokenAmount) {
380
400
  var tokenPublicKey = await super.getIdentityPublicKey();
381
401
  const tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
@@ -386,6 +406,12 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
386
406
  tokenTransaction
387
407
  );
388
408
  }
409
+ /**
410
+ * Burns issuer's tokens
411
+ * @param tokenAmount - The amount of tokens to burn
412
+ * @param selectedOutputs - Optional array of outputs to use for the burn operation
413
+ * @returns The transaction ID of the burn operation
414
+ */
389
415
  async burnTokens(tokenAmount, selectedOutputs) {
390
416
  const burnAddress = encodeSparkAddress({
391
417
  identityPublicKey: BURN_ADDRESS,
@@ -398,6 +424,11 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
398
424
  selectedOutputs
399
425
  });
400
426
  }
427
+ /**
428
+ * Freezes tokens associated with a specific Spark address.
429
+ * @param sparkAddress - The Spark address whose tokens should be frozen
430
+ * @returns An object containing the IDs of impacted outputs and the total amount of frozen tokens
431
+ */
401
432
  async freezeTokens(sparkAddress) {
402
433
  await this.syncTokenOutputs();
403
434
  const tokenPublicKey = await super.getIdentityPublicKey();
@@ -415,6 +446,11 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
415
446
  impactedTokenAmount: tokenAmount
416
447
  };
417
448
  }
449
+ /**
450
+ * Unfreezes previously frozen tokens associated with a specific Spark address.
451
+ * @param sparkAddress - The Spark address whose tokens should be unfrozen
452
+ * @returns An object containing the IDs of impacted outputs and the total amount of unfrozen tokens
453
+ */
418
454
  async unfreezeTokens(sparkAddress) {
419
455
  await this.syncTokenOutputs();
420
456
  const tokenPublicKey = await super.getIdentityPublicKey();
@@ -432,7 +468,25 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
432
468
  impactedTokenAmount: tokenAmount
433
469
  };
434
470
  }
471
+ /**
472
+ * Retrieves the activity history for the issuer's token.
473
+ * @param pageSize - The number of transactions to return per page (default: 100)
474
+ * @param cursor - Optional cursor for pagination
475
+ * @param operationTypes - Optional array of operation types to filter by
476
+ * @param beforeTimestamp - Optional timestamp to filter transactions before
477
+ * @param afterTimestamp - Optional timestamp to filter transactions after
478
+ * @returns An object containing the token activity data
479
+ * @throws {ValidationError} If pageSize is not a safe integer
480
+ * @throws {NetworkError} If the activity data cannot be retrieved
481
+ */
435
482
  async getIssuerTokenActivity(pageSize = 100, cursor, operationTypes, beforeTimestamp, afterTimestamp) {
483
+ if (!Number.isSafeInteger(pageSize)) {
484
+ throw new ValidationError2("pageSize must be less than 2^53", {
485
+ field: "pageSize",
486
+ value: pageSize,
487
+ expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER
488
+ });
489
+ }
436
490
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
437
491
  try {
438
492
  const transactions = await lrc20Client.listTransactions({
@@ -452,10 +506,33 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
452
506
  });
453
507
  }
454
508
  }
509
+ /**
510
+ * Retrieves the distribution information for the issuer's token.
511
+ * @throws {NotImplementedError} This feature is not yet supported
512
+ */
455
513
  async getIssuerTokenDistribution() {
456
514
  throw new NotImplementedError("Token distribution is not yet supported");
457
515
  }
516
+ /**
517
+ * Announces a new token on the L1 (Bitcoin) network.
518
+ * @param tokenName - The name of the token
519
+ * @param tokenTicker - The ticker symbol for the token
520
+ * @param decimals - The number of decimal places for the token
521
+ * @param maxSupply - The maximum supply of the token
522
+ * @param isFreezable - Whether the token can be frozen
523
+ * @param feeRateSatsPerVb - The fee rate in satoshis per virtual byte (default: 4.0)
524
+ * @returns The transaction ID of the announcement
525
+ * @throws {ValidationError} If decimals is not a safe integer
526
+ * @throws {NetworkError} If the announcement transaction cannot be broadcast
527
+ */
458
528
  async announceTokenL1(tokenName, tokenTicker, decimals, maxSupply, isFreezable, feeRateSatsPerVb = 4) {
529
+ if (!Number.isSafeInteger(decimals)) {
530
+ throw new ValidationError2("Decimals must be less than 2^53", {
531
+ field: "decimals",
532
+ value: decimals,
533
+ expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER
534
+ });
535
+ }
459
536
  await this.lrc20Wallet.syncWallet();
460
537
  const tokenPublicKey = new TokenPubkey(this.lrc20Wallet.pubkey);
461
538
  const announcement = new TokenPubkeyAnnouncement(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buildonspark/issuer-sdk",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "description": "Spark Issuer SDK for token issuance",
5
5
  "license": "Apache-2.0",
6
6
  "module": "./dist/index.js",
@@ -54,8 +54,8 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@bufbuild/protobuf": "^2.2.5",
57
- "@buildonspark/lrc20-sdk": "0.0.38",
58
- "@buildonspark/spark-sdk": "0.1.10",
57
+ "@buildonspark/lrc20-sdk": "0.0.40",
58
+ "@buildonspark/spark-sdk": "0.1.12",
59
59
  "@noble/curves": "^1.8.0",
60
60
  "@scure/btc-signer": "^1.5.0",
61
61
  "bitcoinjs-lib": "^6.1.5",
@@ -7,6 +7,7 @@ import {
7
7
  NetworkError,
8
8
  SparkWallet,
9
9
  SparkWalletProps,
10
+ ValidationError,
10
11
  } from "@buildonspark/spark-sdk";
11
12
  import {
12
13
  decodeSparkAddress,
@@ -36,10 +37,20 @@ export type IssuerTokenInfo = {
36
37
  isFreezable: boolean;
37
38
  };
38
39
 
40
+ /**
41
+ * Represents a Spark wallet with minting capabilities.
42
+ * This class extends the base SparkWallet with additional functionality for token minting,
43
+ * burning, and freezing operations.
44
+ */
39
45
  export class IssuerSparkWallet extends SparkWallet {
40
46
  private issuerTokenTransactionService: IssuerTokenTransactionService;
41
47
  private tokenFreezeService: TokenFreezeService;
42
48
 
49
+ /**
50
+ * Initializes a new IssuerSparkWallet instance.
51
+ * @param options - Configuration options for the wallet
52
+ * @returns An object containing the initialized wallet and initialization response
53
+ */
43
54
  public static async initialize(options: SparkWalletProps) {
44
55
  const wallet = new IssuerSparkWallet(options.options);
45
56
 
@@ -62,6 +73,10 @@ export class IssuerSparkWallet extends SparkWallet {
62
73
  );
63
74
  }
64
75
 
76
+ /**
77
+ * Gets the token balance for the issuer's token.
78
+ * @returns An object containing the token balance as a bigint
79
+ */
65
80
  public async getIssuerTokenBalance(): Promise<{
66
81
  balance: bigint;
67
82
  }> {
@@ -78,6 +93,11 @@ export class IssuerSparkWallet extends SparkWallet {
78
93
  };
79
94
  }
80
95
 
96
+ /**
97
+ * Retrieves information about the issuer's token.
98
+ * @returns An object containing token information including public key, name, symbol, decimals, max supply, and freeze status
99
+ * @throws {NetworkError} If the token info cannot be retrieved
100
+ */
81
101
  public async getIssuerTokenInfo(): Promise<IssuerTokenInfo | null> {
82
102
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
83
103
 
@@ -104,6 +124,11 @@ export class IssuerSparkWallet extends SparkWallet {
104
124
  }
105
125
  }
106
126
 
127
+ /**
128
+ * Mints new tokens
129
+ * @param tokenAmount - The amount of tokens to mint
130
+ * @returns The transaction ID of the mint operation
131
+ */
107
132
  public async mintTokens(tokenAmount: bigint): Promise<string> {
108
133
  var tokenPublicKey = await super.getIdentityPublicKey();
109
134
 
@@ -118,6 +143,12 @@ export class IssuerSparkWallet extends SparkWallet {
118
143
  );
119
144
  }
120
145
 
146
+ /**
147
+ * Burns issuer's tokens
148
+ * @param tokenAmount - The amount of tokens to burn
149
+ * @param selectedOutputs - Optional array of outputs to use for the burn operation
150
+ * @returns The transaction ID of the burn operation
151
+ */
121
152
  public async burnTokens(
122
153
  tokenAmount: bigint,
123
154
  selectedOutputs?: OutputWithPreviousTransactionData[],
@@ -134,6 +165,11 @@ export class IssuerSparkWallet extends SparkWallet {
134
165
  });
135
166
  }
136
167
 
168
+ /**
169
+ * Freezes tokens associated with a specific Spark address.
170
+ * @param sparkAddress - The Spark address whose tokens should be frozen
171
+ * @returns An object containing the IDs of impacted outputs and the total amount of frozen tokens
172
+ */
137
173
  public async freezeTokens(
138
174
  sparkAddress: string,
139
175
  ): Promise<{ impactedOutputIds: string[]; impactedTokenAmount: bigint }> {
@@ -157,6 +193,11 @@ export class IssuerSparkWallet extends SparkWallet {
157
193
  };
158
194
  }
159
195
 
196
+ /**
197
+ * Unfreezes previously frozen tokens associated with a specific Spark address.
198
+ * @param sparkAddress - The Spark address whose tokens should be unfrozen
199
+ * @returns An object containing the IDs of impacted outputs and the total amount of unfrozen tokens
200
+ */
160
201
  public async unfreezeTokens(
161
202
  sparkAddress: string,
162
203
  ): Promise<{ impactedOutputIds: string[]; impactedTokenAmount: bigint }> {
@@ -178,6 +219,17 @@ export class IssuerSparkWallet extends SparkWallet {
178
219
  };
179
220
  }
180
221
 
222
+ /**
223
+ * Retrieves the activity history for the issuer's token.
224
+ * @param pageSize - The number of transactions to return per page (default: 100)
225
+ * @param cursor - Optional cursor for pagination
226
+ * @param operationTypes - Optional array of operation types to filter by
227
+ * @param beforeTimestamp - Optional timestamp to filter transactions before
228
+ * @param afterTimestamp - Optional timestamp to filter transactions after
229
+ * @returns An object containing the token activity data
230
+ * @throws {ValidationError} If pageSize is not a safe integer
231
+ * @throws {NetworkError} If the activity data cannot be retrieved
232
+ */
181
233
  public async getIssuerTokenActivity(
182
234
  pageSize: number = 100,
183
235
  cursor?: ListAllTokenTransactionsCursor,
@@ -185,6 +237,14 @@ export class IssuerSparkWallet extends SparkWallet {
185
237
  beforeTimestamp?: Date,
186
238
  afterTimestamp?: Date,
187
239
  ): Promise<GetTokenActivityResponse> {
240
+ if (!Number.isSafeInteger(pageSize)) {
241
+ throw new ValidationError("pageSize must be less than 2^53", {
242
+ field: "pageSize",
243
+ value: pageSize,
244
+ expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER,
245
+ });
246
+ }
247
+
188
248
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
189
249
 
190
250
  try {
@@ -207,10 +267,26 @@ export class IssuerSparkWallet extends SparkWallet {
207
267
  }
208
268
  }
209
269
 
270
+ /**
271
+ * Retrieves the distribution information for the issuer's token.
272
+ * @throws {NotImplementedError} This feature is not yet supported
273
+ */
210
274
  public async getIssuerTokenDistribution(): Promise<TokenDistribution> {
211
275
  throw new NotImplementedError("Token distribution is not yet supported");
212
276
  }
213
277
 
278
+ /**
279
+ * Announces a new token on the L1 (Bitcoin) network.
280
+ * @param tokenName - The name of the token
281
+ * @param tokenTicker - The ticker symbol for the token
282
+ * @param decimals - The number of decimal places for the token
283
+ * @param maxSupply - The maximum supply of the token
284
+ * @param isFreezable - Whether the token can be frozen
285
+ * @param feeRateSatsPerVb - The fee rate in satoshis per virtual byte (default: 4.0)
286
+ * @returns The transaction ID of the announcement
287
+ * @throws {ValidationError} If decimals is not a safe integer
288
+ * @throws {NetworkError} If the announcement transaction cannot be broadcast
289
+ */
214
290
  public async announceTokenL1(
215
291
  tokenName: string,
216
292
  tokenTicker: string,
@@ -219,8 +295,15 @@ export class IssuerSparkWallet extends SparkWallet {
219
295
  isFreezable: boolean,
220
296
  feeRateSatsPerVb: number = 4.0,
221
297
  ): Promise<string> {
222
- await this.lrc20Wallet!.syncWallet();
298
+ if (!Number.isSafeInteger(decimals)) {
299
+ throw new ValidationError("Decimals must be less than 2^53", {
300
+ field: "decimals",
301
+ value: decimals,
302
+ expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER,
303
+ });
304
+ }
223
305
 
306
+ await this.lrc20Wallet!.syncWallet();
224
307
  const tokenPublicKey = new TokenPubkey(this.lrc20Wallet!.pubkey);
225
308
 
226
309
  const announcement = new TokenPubkeyAnnouncement(
@@ -30,13 +30,34 @@ describe("token integration tests", () => {
30
30
  },
31
31
  );
32
32
 
33
+ brokenTestFn(
34
+ "should fail when announce decimal is greater than 2^53",
35
+ async () => {
36
+ const tokenAmount: bigint = 1000n;
37
+ const { wallet } = await IssuerSparkWalletTesting.initialize({
38
+ options: LOCAL_WALLET_CONFIG_ECDSA,
39
+ });
40
+
41
+ await expect(
42
+ await fundAndAnnounce(
43
+ wallet,
44
+ tokenAmount,
45
+ 2 ** 53,
46
+ "TestToken",
47
+ "TT1",
48
+ false,
49
+ ),
50
+ ).rejects.toThrow();
51
+ },
52
+ );
53
+
33
54
  brokenTestFn("should fail when minting more than max supply", async () => {
34
55
  const tokenAmount: bigint = 1000n;
35
56
  const { wallet } = await IssuerSparkWalletTesting.initialize({
36
57
  options: LOCAL_WALLET_CONFIG_SCHNORR,
37
58
  });
38
59
 
39
- await fundAndAnnounce(wallet, 2n, "MaxSupplyToken", "MST");
60
+ await fundAndAnnounce(wallet, 2n, 0, "MaxSupplyToken", "MST");
40
61
  await expect(wallet.mintTokens(tokenAmount)).rejects.toThrow();
41
62
  });
42
63
 
@@ -50,7 +71,7 @@ describe("token integration tests", () => {
50
71
  options: LOCAL_WALLET_CONFIG_SCHNORR,
51
72
  });
52
73
 
53
- await fundAndAnnounce(wallet, 100000n, tokenName, tokenSymbol);
74
+ await fundAndAnnounce(wallet, 100000n, 0, tokenName, tokenSymbol);
54
75
 
55
76
  const publicKeyInfo = await wallet.getIssuerTokenInfo();
56
77
 
@@ -95,7 +116,13 @@ describe("token integration tests", () => {
95
116
  },
96
117
  );
97
118
 
98
- await fundAndAnnounce(issuerWallet, 100000n, "ECDSATransferToken", "ETT");
119
+ await fundAndAnnounce(
120
+ issuerWallet,
121
+ 100000n,
122
+ 0,
123
+ "ECDSATransferToken",
124
+ "ETT",
125
+ );
99
126
 
100
127
  await issuerWallet.mintTokens(tokenAmount);
101
128
  await issuerWallet.transferTokens({
@@ -128,7 +155,7 @@ describe("token integration tests", () => {
128
155
  options: LOCAL_WALLET_CONFIG_ECDSA,
129
156
  });
130
157
 
131
- await fundAndAnnounce(issuerWallet, 100000n, "MonitoringToken", "MOT");
158
+ await fundAndAnnounce(issuerWallet, 100000n, 0, "MonitoringToken", "MOT");
132
159
 
133
160
  await issuerWallet.mintTokens(tokenAmount);
134
161
  await issuerWallet.transferTokens({
@@ -175,6 +202,7 @@ describe("token integration tests", () => {
175
202
  await fundAndAnnounce(
176
203
  issuerWallet,
177
204
  100000n,
205
+ 0,
178
206
  "SchnorrTransferToken",
179
207
  "STT",
180
208
  );
@@ -207,7 +235,13 @@ describe("token integration tests", () => {
207
235
  options: LOCAL_WALLET_CONFIG_ECDSA,
208
236
  });
209
237
 
210
- await fundAndAnnounce(issuerWallet, 100000n, "ECDSAFreezeToken", "EFT");
238
+ await fundAndAnnounce(
239
+ issuerWallet,
240
+ 100000n,
241
+ 0,
242
+ "ECDSAFreezeToken",
243
+ "EFT",
244
+ );
211
245
  await issuerWallet.mintTokens(tokenAmount);
212
246
 
213
247
  // Check issuer balance after minting
@@ -261,7 +295,13 @@ describe("token integration tests", () => {
261
295
  options: LOCAL_WALLET_CONFIG_SCHNORR,
262
296
  });
263
297
 
264
- await fundAndAnnounce(issuerWallet, 100000n, "SchnorrFreezeToken", "SFT");
298
+ await fundAndAnnounce(
299
+ issuerWallet,
300
+ 100000n,
301
+ 0,
302
+ "SchnorrFreezeToken",
303
+ "SFT",
304
+ );
265
305
 
266
306
  await issuerWallet.mintTokens(tokenAmount);
267
307
 
@@ -315,7 +355,7 @@ describe("token integration tests", () => {
315
355
  options: LOCAL_WALLET_CONFIG_ECDSA,
316
356
  });
317
357
 
318
- await fundAndAnnounce(issuerWallet, 100000n, "ECDSABurnToken", "EBT");
358
+ await fundAndAnnounce(issuerWallet, 100000n, 0, "ECDSABurnToken", "EBT");
319
359
  await issuerWallet.mintTokens(tokenAmount);
320
360
 
321
361
  const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
@@ -340,7 +380,13 @@ describe("token integration tests", () => {
340
380
  options: LOCAL_WALLET_CONFIG_SCHNORR,
341
381
  });
342
382
 
343
- await fundAndAnnounce(issuerWallet, 100000n, "SchnorrBurnToken", "SBT");
383
+ await fundAndAnnounce(
384
+ issuerWallet,
385
+ 100000n,
386
+ 0,
387
+ "SchnorrBurnToken",
388
+ "SBT",
389
+ );
344
390
  await issuerWallet.mintTokens(tokenAmount);
345
391
 
346
392
  const issuerTokenBalance = (await issuerWallet.getIssuerTokenBalance())
@@ -373,8 +419,10 @@ describe("token integration tests", () => {
373
419
  await fundAndAnnounce(
374
420
  issuerWallet,
375
421
  100000n,
422
+ 0,
376
423
  "ECDSAFullCycleToken",
377
424
  "EFCT",
425
+ false,
378
426
  );
379
427
  await issuerWallet.mintTokens(tokenAmount);
380
428
 
@@ -445,6 +493,7 @@ describe("token integration tests", () => {
445
493
  await fundAndAnnounce(
446
494
  issuerWallet,
447
495
  100000n,
496
+ 0,
448
497
  "SchnorrFullCycleToken",
449
498
  "SFCT",
450
499
  );
@@ -506,8 +555,10 @@ describe("token integration tests", () => {
506
555
  async function fundAndAnnounce(
507
556
  wallet: IssuerSparkWallet,
508
557
  maxSupply: bigint = 100000n,
558
+ decimals: number = 0,
509
559
  tokenName: string = "TestToken1",
510
560
  tokenSymbol: string = "TT1",
561
+ isFreezable: boolean = false,
511
562
  ) {
512
563
  // Faucet funds to the Issuer wallet because announcing a token
513
564
  // requires ownership of an L1 UTXO.
@@ -522,9 +573,9 @@ async function fundAndAnnounce(
522
573
  const response = await wallet.announceTokenL1(
523
574
  tokenName,
524
575
  tokenSymbol,
525
- 0,
576
+ decimals,
526
577
  maxSupply,
527
- false,
578
+ isFreezable,
528
579
  );
529
580
  console.log("Announce token response:", response);
530
581
  } catch (error: any) {