@buildonspark/issuer-sdk 0.0.39 → 0.0.41

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
@@ -35,18 +35,23 @@ if (typeof global === "undefined") {
35
35
 
36
36
  // src/issuer-spark-wallet.ts
37
37
  var import_lrc20_sdk2 = require("@buildonspark/lrc20-sdk");
38
- var import_spark_sdk = require("@buildonspark/spark-sdk");
38
+ var import_spark_sdk3 = require("@buildonspark/spark-sdk");
39
39
  var import_address = require("@buildonspark/spark-sdk/address");
40
- var import_utils5 = require("@noble/curves/abstract/utils");
40
+ var import_utils6 = require("@noble/curves/abstract/utils");
41
41
 
42
42
  // src/services/freeze.ts
43
43
  var import_utils2 = require("@buildonspark/spark-sdk/utils");
44
44
 
45
45
  // src/utils/token-hashing.ts
46
46
  var import_utils = require("@scure/btc-signer/utils");
47
+ var import_spark_sdk = require("@buildonspark/spark-sdk");
47
48
  function hashFreezeTokensPayload(payload) {
48
49
  if (!payload) {
49
- throw new Error("freeze tokens payload cannot be nil");
50
+ throw new import_spark_sdk.ValidationError("Freeze tokens payload cannot be nil", {
51
+ field: "payload",
52
+ value: payload,
53
+ expected: "valid freeze tokens payload"
54
+ });
50
55
  }
51
56
  let allHashes = [];
52
57
  const ownerPubKeyHash = import_utils.sha256.create();
@@ -87,6 +92,8 @@ function hashFreezeTokensPayload(payload) {
87
92
  }
88
93
 
89
94
  // src/services/freeze.ts
95
+ var import_spark_sdk2 = require("@buildonspark/spark-sdk");
96
+ var import_utils3 = require("@noble/curves/abstract/utils");
90
97
  var TokenFreezeService = class {
91
98
  config;
92
99
  connectionManager;
@@ -111,18 +118,30 @@ var TokenFreezeService = class {
111
118
  tokenPublicKey,
112
119
  shouldUnfreeze,
113
120
  issuerProvidedTimestamp,
114
- operatorIdentityPublicKey: operator.identityPublicKey
121
+ operatorIdentityPublicKey: (0, import_utils3.hexToBytes)(operator.identityPublicKey)
115
122
  };
116
123
  const hashedPayload = hashFreezeTokensPayload(freezeTokensPayload);
117
124
  const issuerSignature = await this.config.signer.signMessageWithIdentityKey(hashedPayload);
118
- const response = await internalSparkClient.freeze_tokens({
119
- freezeTokensPayload,
120
- issuerSignature
121
- });
122
- return {
123
- identifier,
124
- response
125
- };
125
+ try {
126
+ const response = await internalSparkClient.freeze_tokens({
127
+ freezeTokensPayload,
128
+ issuerSignature
129
+ });
130
+ return {
131
+ identifier,
132
+ response
133
+ };
134
+ } catch (error) {
135
+ throw new import_spark_sdk2.NetworkError(
136
+ "Failed to send a freeze/unfreeze operation",
137
+ {
138
+ operation: "freeze_tokens",
139
+ errorCount: 1,
140
+ errors: error instanceof Error ? error.message : String(error)
141
+ },
142
+ error instanceof Error ? error : void 0
143
+ );
144
+ }
126
145
  })
127
146
  );
128
147
  const successfulResponses = (0, import_utils2.collectResponses)(freezeResponses);
@@ -132,7 +151,7 @@ var TokenFreezeService = class {
132
151
 
133
152
  // src/services/token-transactions.ts
134
153
  var import_token_transactions = require("@buildonspark/spark-sdk/token-transactions");
135
- var import_utils3 = require("@noble/curves/abstract/utils");
154
+ var import_utils4 = require("@noble/curves/abstract/utils");
136
155
  var IssuerTokenTransactionService = class extends import_token_transactions.TokenTransactionService {
137
156
  constructor(config, connectionManager) {
138
157
  super(config, connectionManager);
@@ -151,7 +170,7 @@ var IssuerTokenTransactionService = class extends import_token_transactions.Toke
151
170
  {
152
171
  ownerPublicKey: tokenPublicKey,
153
172
  tokenPublicKey,
154
- tokenAmount: (0, import_utils3.numberToBytesBE)(tokenAmount, 16)
173
+ tokenAmount: (0, import_utils4.numberToBytesBE)(tokenAmount, 16)
155
174
  }
156
175
  ],
157
176
  sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys()
@@ -160,7 +179,7 @@ var IssuerTokenTransactionService = class extends import_token_transactions.Toke
160
179
  };
161
180
 
162
181
  // src/utils/type-mappers.ts
163
- var import_utils4 = require("@noble/curves/abstract/utils");
182
+ var import_utils5 = require("@noble/curves/abstract/utils");
164
183
 
165
184
  // src/utils/enum-mappers.ts
166
185
  var import_lrc20_sdk = require("@buildonspark/lrc20-sdk");
@@ -241,22 +260,22 @@ function convertTokenActivityToHexEncoded(rawTransactions) {
241
260
  $case: "onChain",
242
261
  onChain: {
243
262
  operationType: mapOperationType(onChain.operationType),
244
- transactionHash: (0, import_utils4.bytesToHex)(onChain.transactionHash),
245
- rawtx: (0, import_utils4.bytesToHex)(onChain.rawtx),
263
+ transactionHash: (0, import_utils5.bytesToHex)(onChain.transactionHash),
264
+ rawtx: (0, import_utils5.bytesToHex)(onChain.rawtx),
246
265
  status: mapOnChainTransactionStatus(onChain.status),
247
266
  inputs: onChain.inputs.map((input) => ({
248
- rawTx: (0, import_utils4.bytesToHex)(input.rawTx),
267
+ rawTx: (0, import_utils5.bytesToHex)(input.rawTx),
249
268
  vout: input.vout,
250
269
  amountSats: input.amountSats,
251
270
  tokenPublicKey: input.tokenPublicKey,
252
- tokenAmount: input.tokenAmount ? (0, import_utils4.bytesToNumberBE)(input.tokenAmount).toString() : void 0
271
+ tokenAmount: input.tokenAmount ? (0, import_utils5.bytesToNumberBE)(input.tokenAmount).toString() : void 0
253
272
  })),
254
273
  outputs: onChain.outputs.map((output) => ({
255
- rawTx: (0, import_utils4.bytesToHex)(output.rawTx),
274
+ rawTx: (0, import_utils5.bytesToHex)(output.rawTx),
256
275
  vout: output.vout,
257
276
  amountSats: output.amountSats,
258
277
  tokenPublicKey: output.tokenPublicKey,
259
- tokenAmount: output.tokenAmount ? (0, import_utils4.bytesToNumberBE)(output.tokenAmount).toString() : void 0
278
+ tokenAmount: output.tokenAmount ? (0, import_utils5.bytesToNumberBE)(output.tokenAmount).toString() : void 0
260
279
  })),
261
280
  broadcastedAt: onChain.broadcastedAt,
262
281
  confirmedAt: onChain.confirmedAt
@@ -270,39 +289,39 @@ function convertTokenActivityToHexEncoded(rawTransactions) {
270
289
  $case: "spark",
271
290
  spark: {
272
291
  operationType: mapOperationType(spark.operationType),
273
- transactionHash: (0, import_utils4.bytesToHex)(spark.transactionHash),
292
+ transactionHash: (0, import_utils5.bytesToHex)(spark.transactionHash),
274
293
  status: mapSparkTransactionStatus(spark.status),
275
294
  confirmedAt: spark.confirmedAt,
276
295
  leavesToCreate: spark.leavesToCreate.map((leaf) => ({
277
- tokenPublicKey: (0, import_utils4.bytesToHex)(leaf.tokenPublicKey),
296
+ tokenPublicKey: (0, import_utils5.bytesToHex)(leaf.tokenPublicKey),
278
297
  id: leaf.id,
279
- ownerPublicKey: (0, import_utils4.bytesToHex)(leaf.ownerPublicKey),
280
- revocationPublicKey: (0, import_utils4.bytesToHex)(leaf.revocationPublicKey),
298
+ ownerPublicKey: (0, import_utils5.bytesToHex)(leaf.ownerPublicKey),
299
+ revocationPublicKey: (0, import_utils5.bytesToHex)(leaf.revocationPublicKey),
281
300
  withdrawalBondSats: leaf.withdrawalBondSats,
282
301
  withdrawalLocktime: leaf.withdrawalLocktime,
283
- tokenAmount: (0, import_utils4.bytesToNumberBE)(leaf.tokenAmount).toString(),
284
- createTxHash: (0, import_utils4.bytesToHex)(leaf.createTxHash),
302
+ tokenAmount: (0, import_utils5.bytesToNumberBE)(leaf.tokenAmount).toString(),
303
+ createTxHash: (0, import_utils5.bytesToHex)(leaf.createTxHash),
285
304
  createTxVoutIndex: leaf.createTxVoutIndex,
286
- spendTxHash: leaf.spendTxHash ? (0, import_utils4.bytesToHex)(leaf.spendTxHash) : void 0,
305
+ spendTxHash: leaf.spendTxHash ? (0, import_utils5.bytesToHex)(leaf.spendTxHash) : void 0,
287
306
  spendTxVoutIndex: leaf.spendTxVoutIndex,
288
307
  isFrozen: leaf.isFrozen
289
308
  })),
290
309
  leavesToSpend: spark.leavesToSpend.map((leaf) => ({
291
- tokenPublicKey: (0, import_utils4.bytesToHex)(leaf.tokenPublicKey),
310
+ tokenPublicKey: (0, import_utils5.bytesToHex)(leaf.tokenPublicKey),
292
311
  id: leaf.id,
293
- ownerPublicKey: (0, import_utils4.bytesToHex)(leaf.ownerPublicKey),
294
- revocationPublicKey: (0, import_utils4.bytesToHex)(leaf.revocationPublicKey),
312
+ ownerPublicKey: (0, import_utils5.bytesToHex)(leaf.ownerPublicKey),
313
+ revocationPublicKey: (0, import_utils5.bytesToHex)(leaf.revocationPublicKey),
295
314
  withdrawalBondSats: leaf.withdrawalBondSats,
296
315
  withdrawalLocktime: leaf.withdrawalLocktime,
297
- tokenAmount: (0, import_utils4.bytesToNumberBE)(leaf.tokenAmount).toString(),
298
- createTxHash: (0, import_utils4.bytesToHex)(leaf.createTxHash),
316
+ tokenAmount: (0, import_utils5.bytesToNumberBE)(leaf.tokenAmount).toString(),
317
+ createTxHash: (0, import_utils5.bytesToHex)(leaf.createTxHash),
299
318
  createTxVoutIndex: leaf.createTxVoutIndex,
300
- spendTxHash: leaf.spendTxHash ? (0, import_utils4.bytesToHex)(leaf.spendTxHash) : void 0,
319
+ spendTxHash: leaf.spendTxHash ? (0, import_utils5.bytesToHex)(leaf.spendTxHash) : void 0,
301
320
  spendTxVoutIndex: leaf.spendTxVoutIndex,
302
321
  isFrozen: leaf.isFrozen
303
322
  })),
304
323
  sparkOperatorIdentityPublicKeys: spark.sparkOperatorIdentityPublicKeys.map(
305
- (key) => (0, import_utils4.bytesToHex)(key)
324
+ (key) => (0, import_utils5.bytesToHex)(key)
306
325
  )
307
326
  }
308
327
  }
@@ -311,7 +330,7 @@ function convertTokenActivityToHexEncoded(rawTransactions) {
311
330
  return { transaction: void 0 };
312
331
  }),
313
332
  nextCursor: rawTransactions.nextCursor ? {
314
- lastTransactionHash: (0, import_utils4.bytesToHex)(
333
+ lastTransactionHash: (0, import_utils5.bytesToHex)(
315
334
  rawTransactions.nextCursor.lastTransactionHash
316
335
  ),
317
336
  layer: mapLayer(rawTransactions.nextCursor.layer)
@@ -321,8 +340,9 @@ function convertTokenActivityToHexEncoded(rawTransactions) {
321
340
  }
322
341
 
323
342
  // src/issuer-spark-wallet.ts
343
+ var import_spark_sdk4 = require("@buildonspark/spark-sdk");
324
344
  var BURN_ADDRESS = "02".repeat(33);
325
- var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk.SparkWallet {
345
+ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.SparkWallet {
326
346
  issuerTokenTransactionService;
327
347
  tokenFreezeService;
328
348
  static async initialize(options) {
@@ -358,23 +378,31 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk.SparkW
358
378
  }
359
379
  async getIssuerTokenInfo() {
360
380
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
361
- const tokenInfo = await lrc20Client.getTokenPubkeyInfo({
362
- publicKeys: [(0, import_utils5.hexToBytes)(await super.getIdentityPublicKey())]
363
- });
364
- const info = tokenInfo.tokenPubkeyInfos[0];
365
- return {
366
- tokenPublicKey: (0, import_utils5.bytesToHex)(info.announcement.publicKey.publicKey),
367
- tokenName: info.announcement.name,
368
- tokenSymbol: info.announcement.symbol,
369
- tokenDecimals: Number((0, import_utils5.bytesToNumberBE)(info.announcement.decimal)),
370
- isFreezable: info.announcement.isFreezable,
371
- maxSupply: (0, import_utils5.bytesToNumberBE)(info.announcement.maxSupply)
372
- };
381
+ try {
382
+ const tokenInfo = await lrc20Client.getTokenPubkeyInfo({
383
+ publicKeys: [(0, import_utils6.hexToBytes)(await super.getIdentityPublicKey())]
384
+ });
385
+ const info = tokenInfo.tokenPubkeyInfos[0];
386
+ return {
387
+ tokenPublicKey: (0, import_utils6.bytesToHex)(info.announcement.publicKey.publicKey),
388
+ tokenName: info.announcement.name,
389
+ tokenSymbol: info.announcement.symbol,
390
+ tokenDecimals: Number((0, import_utils6.bytesToNumberBE)(info.announcement.decimal)),
391
+ isFreezable: info.announcement.isFreezable,
392
+ maxSupply: (0, import_utils6.bytesToNumberBE)(info.announcement.maxSupply)
393
+ };
394
+ } catch (error) {
395
+ throw new import_spark_sdk3.NetworkError("Failed to get token info", {
396
+ operation: "getIssuerTokenInfo",
397
+ errorCount: 1,
398
+ errors: error instanceof Error ? error.message : String(error)
399
+ });
400
+ }
373
401
  }
374
402
  async mintTokens(tokenAmount) {
375
403
  var tokenPublicKey = await super.getIdentityPublicKey();
376
404
  const tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
377
- (0, import_utils5.hexToBytes)(tokenPublicKey),
405
+ (0, import_utils6.hexToBytes)(tokenPublicKey),
378
406
  tokenAmount
379
407
  );
380
408
  return await this.issuerTokenTransactionService.broadcastTokenTransaction(
@@ -401,10 +429,10 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk.SparkW
401
429
  this.config.getNetworkType()
402
430
  );
403
431
  const response = await this.tokenFreezeService.freezeTokens(
404
- (0, import_utils5.hexToBytes)(decodedOwnerPubkey),
405
- (0, import_utils5.hexToBytes)(tokenPublicKey)
432
+ (0, import_utils6.hexToBytes)(decodedOwnerPubkey),
433
+ (0, import_utils6.hexToBytes)(tokenPublicKey)
406
434
  );
407
- const tokenAmount = (0, import_utils5.bytesToNumberBE)(response.impactedTokenAmount);
435
+ const tokenAmount = (0, import_utils6.bytesToNumberBE)(response.impactedTokenAmount);
408
436
  return {
409
437
  impactedOutputIds: response.impactedOutputIds,
410
438
  impactedTokenAmount: tokenAmount
@@ -418,10 +446,10 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk.SparkW
418
446
  this.config.getNetworkType()
419
447
  );
420
448
  const response = await this.tokenFreezeService.unfreezeTokens(
421
- (0, import_utils5.hexToBytes)(decodedOwnerPubkey),
422
- (0, import_utils5.hexToBytes)(tokenPublicKey)
449
+ (0, import_utils6.hexToBytes)(decodedOwnerPubkey),
450
+ (0, import_utils6.hexToBytes)(tokenPublicKey)
423
451
  );
424
- const tokenAmount = (0, import_utils5.bytesToNumberBE)(response.impactedTokenAmount);
452
+ const tokenAmount = (0, import_utils6.bytesToNumberBE)(response.impactedTokenAmount);
425
453
  return {
426
454
  impactedOutputIds: response.impactedOutputIds,
427
455
  impactedTokenAmount: tokenAmount
@@ -429,27 +457,28 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk.SparkW
429
457
  }
430
458
  async getIssuerTokenActivity(pageSize = 100, cursor, operationTypes, beforeTimestamp, afterTimestamp) {
431
459
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
432
- const transactions = await lrc20Client.listTransactions({
433
- tokenPublicKey: (0, import_utils5.hexToBytes)(await super.getIdentityPublicKey()),
434
- cursor,
435
- pageSize,
436
- beforeTimestamp,
437
- afterTimestamp,
438
- operationTypes
439
- });
440
- return convertTokenActivityToHexEncoded(transactions);
460
+ try {
461
+ const transactions = await lrc20Client.listTransactions({
462
+ tokenPublicKey: (0, import_utils6.hexToBytes)(await super.getIdentityPublicKey()),
463
+ cursor,
464
+ pageSize,
465
+ beforeTimestamp,
466
+ afterTimestamp,
467
+ operationTypes
468
+ });
469
+ return convertTokenActivityToHexEncoded(transactions);
470
+ } catch (error) {
471
+ throw new import_spark_sdk3.NetworkError("Failed to get token activity", {
472
+ operation: "listTransactions",
473
+ errorCount: 1,
474
+ errors: error instanceof Error ? error.message : String(error)
475
+ });
476
+ }
441
477
  }
442
478
  async getIssuerTokenDistribution() {
443
- throw new Error("Not implemented");
479
+ throw new import_spark_sdk4.NotImplementedError("Token distribution is not yet supported");
444
480
  }
445
- async announceTokenL1({
446
- tokenName,
447
- tokenTicker,
448
- decimals,
449
- maxSupply,
450
- isFreezable,
451
- feeRateSatsPerVb = 2
452
- }) {
481
+ async announceTokenL1(tokenName, tokenTicker, decimals, maxSupply, isFreezable, feeRateSatsPerVb = 4) {
453
482
  await this.lrc20Wallet.syncWallet();
454
483
  const tokenPublicKey = new import_lrc20_sdk2.TokenPubkey(this.lrc20Wallet.pubkey);
455
484
  const announcement = new import_lrc20_sdk2.TokenPubkeyAnnouncement(
@@ -460,13 +489,24 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk.SparkW
460
489
  maxSupply,
461
490
  isFreezable
462
491
  );
463
- const tx = await this.lrc20Wallet.prepareAnnouncement(
464
- announcement,
465
- feeRateSatsPerVb
466
- );
467
- return await this.lrc20Wallet.broadcastRawBtcTransaction(
468
- tx.bitcoin_tx.toHex()
469
- );
492
+ try {
493
+ const tx = await this.lrc20Wallet.prepareAnnouncement(
494
+ announcement,
495
+ feeRateSatsPerVb
496
+ );
497
+ return await this.lrc20Wallet.broadcastRawBtcTransaction(
498
+ tx.bitcoin_tx.toHex()
499
+ );
500
+ } catch (error) {
501
+ throw new import_spark_sdk3.NetworkError(
502
+ "Failed to broadcast announcement transaction on L1",
503
+ {
504
+ operation: "broadcastRawBtcTransaction",
505
+ errorCount: 1,
506
+ errors: error instanceof Error ? error.message : String(error)
507
+ }
508
+ );
509
+ }
470
510
  }
471
511
  };
472
512
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.cts CHANGED
@@ -36,14 +36,7 @@ declare class IssuerSparkWallet extends SparkWallet {
36
36
  }>;
37
37
  getIssuerTokenActivity(pageSize?: number, cursor?: ListAllTokenTransactionsCursor, operationTypes?: OperationType[], beforeTimestamp?: Date, afterTimestamp?: Date): Promise<GetTokenActivityResponse>;
38
38
  getIssuerTokenDistribution(): Promise<TokenDistribution>;
39
- announceTokenL1({ tokenName, tokenTicker, decimals, maxSupply, isFreezable, feeRateSatsPerVb, }: {
40
- tokenName: any;
41
- tokenTicker: any;
42
- decimals: any;
43
- maxSupply: any;
44
- isFreezable: any;
45
- feeRateSatsPerVb?: number | undefined;
46
- }): Promise<string>;
39
+ announceTokenL1(tokenName: string, tokenTicker: string, decimals: number, maxSupply: bigint, isFreezable: boolean, feeRateSatsPerVb?: number): Promise<string>;
47
40
  }
48
41
 
49
42
  export { IssuerSparkWallet, type IssuerTokenInfo };
package/dist/index.d.ts CHANGED
@@ -36,14 +36,7 @@ declare class IssuerSparkWallet extends SparkWallet {
36
36
  }>;
37
37
  getIssuerTokenActivity(pageSize?: number, cursor?: ListAllTokenTransactionsCursor, operationTypes?: OperationType[], beforeTimestamp?: Date, afterTimestamp?: Date): Promise<GetTokenActivityResponse>;
38
38
  getIssuerTokenDistribution(): Promise<TokenDistribution>;
39
- announceTokenL1({ tokenName, tokenTicker, decimals, maxSupply, isFreezable, feeRateSatsPerVb, }: {
40
- tokenName: any;
41
- tokenTicker: any;
42
- decimals: any;
43
- maxSupply: any;
44
- isFreezable: any;
45
- feeRateSatsPerVb?: number | undefined;
46
- }): Promise<string>;
39
+ announceTokenL1(tokenName: string, tokenTicker: string, decimals: number, maxSupply: bigint, isFreezable: boolean, feeRateSatsPerVb?: number): Promise<string>;
47
40
  }
48
41
 
49
42
  export { IssuerSparkWallet, type IssuerTokenInfo };
package/dist/index.js CHANGED
@@ -2,7 +2,10 @@ import "./chunk-GB7N6I5O.js";
2
2
 
3
3
  // src/issuer-spark-wallet.ts
4
4
  import { TokenPubkey, TokenPubkeyAnnouncement } from "@buildonspark/lrc20-sdk";
5
- import { SparkWallet } from "@buildonspark/spark-sdk";
5
+ import {
6
+ NetworkError as NetworkError2,
7
+ SparkWallet
8
+ } from "@buildonspark/spark-sdk";
6
9
  import {
7
10
  decodeSparkAddress,
8
11
  encodeSparkAddress
@@ -10,7 +13,7 @@ import {
10
13
  import {
11
14
  bytesToHex as bytesToHex2,
12
15
  bytesToNumberBE as bytesToNumberBE2,
13
- hexToBytes
16
+ hexToBytes as hexToBytes2
14
17
  } from "@noble/curves/abstract/utils";
15
18
 
16
19
  // src/services/freeze.ts
@@ -18,9 +21,14 @@ import { collectResponses } from "@buildonspark/spark-sdk/utils";
18
21
 
19
22
  // src/utils/token-hashing.ts
20
23
  import { sha256 } from "@scure/btc-signer/utils";
24
+ import { ValidationError } from "@buildonspark/spark-sdk";
21
25
  function hashFreezeTokensPayload(payload) {
22
26
  if (!payload) {
23
- throw new Error("freeze tokens payload cannot be nil");
27
+ throw new ValidationError("Freeze tokens payload cannot be nil", {
28
+ field: "payload",
29
+ value: payload,
30
+ expected: "valid freeze tokens payload"
31
+ });
24
32
  }
25
33
  let allHashes = [];
26
34
  const ownerPubKeyHash = sha256.create();
@@ -61,6 +69,8 @@ function hashFreezeTokensPayload(payload) {
61
69
  }
62
70
 
63
71
  // src/services/freeze.ts
72
+ import { NetworkError } from "@buildonspark/spark-sdk";
73
+ import { hexToBytes } from "@noble/curves/abstract/utils";
64
74
  var TokenFreezeService = class {
65
75
  config;
66
76
  connectionManager;
@@ -85,18 +95,30 @@ var TokenFreezeService = class {
85
95
  tokenPublicKey,
86
96
  shouldUnfreeze,
87
97
  issuerProvidedTimestamp,
88
- operatorIdentityPublicKey: operator.identityPublicKey
98
+ operatorIdentityPublicKey: hexToBytes(operator.identityPublicKey)
89
99
  };
90
100
  const hashedPayload = hashFreezeTokensPayload(freezeTokensPayload);
91
101
  const issuerSignature = await this.config.signer.signMessageWithIdentityKey(hashedPayload);
92
- const response = await internalSparkClient.freeze_tokens({
93
- freezeTokensPayload,
94
- issuerSignature
95
- });
96
- return {
97
- identifier,
98
- response
99
- };
102
+ try {
103
+ const response = await internalSparkClient.freeze_tokens({
104
+ freezeTokensPayload,
105
+ issuerSignature
106
+ });
107
+ return {
108
+ identifier,
109
+ response
110
+ };
111
+ } catch (error) {
112
+ throw new NetworkError(
113
+ "Failed to send a freeze/unfreeze operation",
114
+ {
115
+ operation: "freeze_tokens",
116
+ errorCount: 1,
117
+ errors: error instanceof Error ? error.message : String(error)
118
+ },
119
+ error instanceof Error ? error : void 0
120
+ );
121
+ }
100
122
  })
101
123
  );
102
124
  const successfulResponses = collectResponses(freezeResponses);
@@ -295,6 +317,7 @@ function convertTokenActivityToHexEncoded(rawTransactions) {
295
317
  }
296
318
 
297
319
  // src/issuer-spark-wallet.ts
320
+ import { NotImplementedError } from "@buildonspark/spark-sdk";
298
321
  var BURN_ADDRESS = "02".repeat(33);
299
322
  var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
300
323
  issuerTokenTransactionService;
@@ -332,23 +355,31 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
332
355
  }
333
356
  async getIssuerTokenInfo() {
334
357
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
335
- const tokenInfo = await lrc20Client.getTokenPubkeyInfo({
336
- publicKeys: [hexToBytes(await super.getIdentityPublicKey())]
337
- });
338
- const info = tokenInfo.tokenPubkeyInfos[0];
339
- return {
340
- tokenPublicKey: bytesToHex2(info.announcement.publicKey.publicKey),
341
- tokenName: info.announcement.name,
342
- tokenSymbol: info.announcement.symbol,
343
- tokenDecimals: Number(bytesToNumberBE2(info.announcement.decimal)),
344
- isFreezable: info.announcement.isFreezable,
345
- maxSupply: bytesToNumberBE2(info.announcement.maxSupply)
346
- };
358
+ try {
359
+ const tokenInfo = await lrc20Client.getTokenPubkeyInfo({
360
+ publicKeys: [hexToBytes2(await super.getIdentityPublicKey())]
361
+ });
362
+ const info = tokenInfo.tokenPubkeyInfos[0];
363
+ return {
364
+ tokenPublicKey: bytesToHex2(info.announcement.publicKey.publicKey),
365
+ tokenName: info.announcement.name,
366
+ tokenSymbol: info.announcement.symbol,
367
+ tokenDecimals: Number(bytesToNumberBE2(info.announcement.decimal)),
368
+ isFreezable: info.announcement.isFreezable,
369
+ maxSupply: bytesToNumberBE2(info.announcement.maxSupply)
370
+ };
371
+ } catch (error) {
372
+ throw new NetworkError2("Failed to get token info", {
373
+ operation: "getIssuerTokenInfo",
374
+ errorCount: 1,
375
+ errors: error instanceof Error ? error.message : String(error)
376
+ });
377
+ }
347
378
  }
348
379
  async mintTokens(tokenAmount) {
349
380
  var tokenPublicKey = await super.getIdentityPublicKey();
350
381
  const tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
351
- hexToBytes(tokenPublicKey),
382
+ hexToBytes2(tokenPublicKey),
352
383
  tokenAmount
353
384
  );
354
385
  return await this.issuerTokenTransactionService.broadcastTokenTransaction(
@@ -375,8 +406,8 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
375
406
  this.config.getNetworkType()
376
407
  );
377
408
  const response = await this.tokenFreezeService.freezeTokens(
378
- hexToBytes(decodedOwnerPubkey),
379
- hexToBytes(tokenPublicKey)
409
+ hexToBytes2(decodedOwnerPubkey),
410
+ hexToBytes2(tokenPublicKey)
380
411
  );
381
412
  const tokenAmount = bytesToNumberBE2(response.impactedTokenAmount);
382
413
  return {
@@ -392,8 +423,8 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
392
423
  this.config.getNetworkType()
393
424
  );
394
425
  const response = await this.tokenFreezeService.unfreezeTokens(
395
- hexToBytes(decodedOwnerPubkey),
396
- hexToBytes(tokenPublicKey)
426
+ hexToBytes2(decodedOwnerPubkey),
427
+ hexToBytes2(tokenPublicKey)
397
428
  );
398
429
  const tokenAmount = bytesToNumberBE2(response.impactedTokenAmount);
399
430
  return {
@@ -403,27 +434,28 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
403
434
  }
404
435
  async getIssuerTokenActivity(pageSize = 100, cursor, operationTypes, beforeTimestamp, afterTimestamp) {
405
436
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
406
- const transactions = await lrc20Client.listTransactions({
407
- tokenPublicKey: hexToBytes(await super.getIdentityPublicKey()),
408
- cursor,
409
- pageSize,
410
- beforeTimestamp,
411
- afterTimestamp,
412
- operationTypes
413
- });
414
- return convertTokenActivityToHexEncoded(transactions);
437
+ try {
438
+ const transactions = await lrc20Client.listTransactions({
439
+ tokenPublicKey: hexToBytes2(await super.getIdentityPublicKey()),
440
+ cursor,
441
+ pageSize,
442
+ beforeTimestamp,
443
+ afterTimestamp,
444
+ operationTypes
445
+ });
446
+ return convertTokenActivityToHexEncoded(transactions);
447
+ } catch (error) {
448
+ throw new NetworkError2("Failed to get token activity", {
449
+ operation: "listTransactions",
450
+ errorCount: 1,
451
+ errors: error instanceof Error ? error.message : String(error)
452
+ });
453
+ }
415
454
  }
416
455
  async getIssuerTokenDistribution() {
417
- throw new Error("Not implemented");
456
+ throw new NotImplementedError("Token distribution is not yet supported");
418
457
  }
419
- async announceTokenL1({
420
- tokenName,
421
- tokenTicker,
422
- decimals,
423
- maxSupply,
424
- isFreezable,
425
- feeRateSatsPerVb = 2
426
- }) {
458
+ async announceTokenL1(tokenName, tokenTicker, decimals, maxSupply, isFreezable, feeRateSatsPerVb = 4) {
427
459
  await this.lrc20Wallet.syncWallet();
428
460
  const tokenPublicKey = new TokenPubkey(this.lrc20Wallet.pubkey);
429
461
  const announcement = new TokenPubkeyAnnouncement(
@@ -434,13 +466,24 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
434
466
  maxSupply,
435
467
  isFreezable
436
468
  );
437
- const tx = await this.lrc20Wallet.prepareAnnouncement(
438
- announcement,
439
- feeRateSatsPerVb
440
- );
441
- return await this.lrc20Wallet.broadcastRawBtcTransaction(
442
- tx.bitcoin_tx.toHex()
443
- );
469
+ try {
470
+ const tx = await this.lrc20Wallet.prepareAnnouncement(
471
+ announcement,
472
+ feeRateSatsPerVb
473
+ );
474
+ return await this.lrc20Wallet.broadcastRawBtcTransaction(
475
+ tx.bitcoin_tx.toHex()
476
+ );
477
+ } catch (error) {
478
+ throw new NetworkError2(
479
+ "Failed to broadcast announcement transaction on L1",
480
+ {
481
+ operation: "broadcastRawBtcTransaction",
482
+ errorCount: 1,
483
+ errors: error instanceof Error ? error.message : String(error)
484
+ }
485
+ );
486
+ }
444
487
  }
445
488
  };
446
489
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buildonspark/issuer-sdk",
3
- "version": "0.0.39",
3
+ "version": "0.0.41",
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.36",
58
- "@buildonspark/spark-sdk": "0.1.8",
57
+ "@buildonspark/lrc20-sdk": "0.0.38",
58
+ "@buildonspark/spark-sdk": "0.1.10",
59
59
  "@noble/curves": "^1.8.0",
60
60
  "@scure/btc-signer": "^1.5.0",
61
61
  "bitcoinjs-lib": "^6.1.5",