@buildonspark/issuer-sdk 0.0.75 → 0.0.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @buildonspark/issuer-sdk
2
2
 
3
+ ## 0.0.76
4
+
5
+ ### Patch Changes
6
+
7
+ - - Update parsing of spark address from fallback_adress to route_hints
8
+ - Update sdk checks on transactions
9
+ - Add token features
10
+ - Improve stability and cleanup
11
+ - Updated dependencies
12
+ - @buildonspark/spark-sdk@0.1.45
13
+
3
14
  ## 0.0.75
4
15
 
5
16
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -43,7 +43,7 @@ var import_lrc20_sdk = require("@buildonspark/lrc20-sdk");
43
43
  var import_spark_sdk3 = require("@buildonspark/spark-sdk");
44
44
  var import_core = require("@lightsparkdev/core");
45
45
  var import_address = require("@buildonspark/spark-sdk/address");
46
- var import_utils6 = require("@noble/curves/abstract/utils");
46
+ var import_utils5 = require("@noble/curves/abstract/utils");
47
47
 
48
48
  // src/services/freeze.ts
49
49
  var import_utils2 = require("@buildonspark/spark-sdk/utils");
@@ -189,8 +189,7 @@ var IssuerTokenTransactionService = class extends import_token_transactions.Toke
189
189
  tokenInputs: {
190
190
  $case: "mintInput",
191
191
  mintInput: {
192
- issuerPublicKey: tokenPublicKey,
193
- issuerProvidedTimestamp: Date.now()
192
+ issuerPublicKey: tokenPublicKey
194
193
  }
195
194
  },
196
195
  tokenOutputs: [
@@ -200,113 +199,15 @@ var IssuerTokenTransactionService = class extends import_token_transactions.Toke
200
199
  tokenAmount: (0, import_utils4.numberToBytesBE)(tokenAmount, 16)
201
200
  }
202
201
  ],
202
+ clientCreatedTimestamp: /* @__PURE__ */ new Date(),
203
203
  sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys(),
204
204
  expiryTime: void 0
205
205
  };
206
206
  }
207
207
  };
208
208
 
209
- // src/utils/type-mappers.ts
210
- var import_utils5 = require("@noble/curves/abstract/utils");
211
- var import_lrc20 = require("@buildonspark/spark-sdk/proto/lrc20");
212
- function convertToTokenActivity(rawTransactions) {
213
- const response = {
214
- transactions: rawTransactions.transactions.map((transaction) => {
215
- if (!transaction.transaction) {
216
- return { transaction: void 0 };
217
- }
218
- if (transaction.transaction.$case === "onChain") {
219
- const onChain = transaction.transaction.onChain;
220
- return {
221
- transaction: {
222
- $case: "onChain",
223
- onChain: {
224
- operationType: getEnumName(import_lrc20.OperationType, onChain.operationType),
225
- transactionHash: (0, import_utils5.bytesToHex)(onChain.transactionHash),
226
- rawtx: (0, import_utils5.bytesToHex)(onChain.rawtx),
227
- status: getEnumName(import_lrc20.OnChainTransactionStatus, onChain.status),
228
- inputs: onChain.inputs.map((input) => ({
229
- rawTx: (0, import_utils5.bytesToHex)(input.rawTx),
230
- vout: input.vout,
231
- amountSats: input.amountSats,
232
- tokenPublicKey: input.tokenPublicKey,
233
- tokenAmount: input.tokenAmount ? (0, import_utils5.bytesToNumberBE)(input.tokenAmount).toString() : void 0
234
- })),
235
- outputs: onChain.outputs.map((output) => ({
236
- rawTx: (0, import_utils5.bytesToHex)(output.rawTx),
237
- vout: output.vout,
238
- amountSats: output.amountSats,
239
- tokenPublicKey: output.tokenPublicKey,
240
- tokenAmount: output.tokenAmount ? (0, import_utils5.bytesToNumberBE)(output.tokenAmount).toString() : void 0
241
- })),
242
- broadcastedAt: onChain.broadcastedAt,
243
- confirmedAt: onChain.confirmedAt
244
- }
245
- }
246
- };
247
- } else if (transaction.transaction.$case === "spark") {
248
- const spark = transaction.transaction.spark;
249
- return {
250
- transaction: {
251
- $case: "spark",
252
- spark: {
253
- operationType: getEnumName(import_lrc20.OperationType, spark.operationType),
254
- transactionHash: (0, import_utils5.bytesToHex)(spark.transactionHash),
255
- status: getEnumName(import_lrc20.SparkTransactionStatus, spark.status),
256
- confirmedAt: spark.confirmedAt,
257
- leavesToCreate: spark.leavesToCreate.map((leaf) => ({
258
- tokenPublicKey: (0, import_utils5.bytesToHex)(leaf.tokenPublicKey),
259
- id: leaf.id,
260
- ownerPublicKey: (0, import_utils5.bytesToHex)(leaf.ownerPublicKey),
261
- revocationPublicKey: (0, import_utils5.bytesToHex)(leaf.revocationPublicKey),
262
- withdrawalBondSats: leaf.withdrawalBondSats,
263
- withdrawalLocktime: leaf.withdrawalLocktime,
264
- tokenAmount: (0, import_utils5.bytesToNumberBE)(leaf.tokenAmount).toString(),
265
- createTxHash: (0, import_utils5.bytesToHex)(leaf.createTxHash),
266
- createTxVoutIndex: leaf.createTxVoutIndex,
267
- spendTxHash: leaf.spendTxHash ? (0, import_utils5.bytesToHex)(leaf.spendTxHash) : void 0,
268
- spendTxVoutIndex: leaf.spendTxVoutIndex,
269
- isFrozen: leaf.isFrozen
270
- })),
271
- leavesToSpend: spark.leavesToSpend.map((leaf) => ({
272
- tokenPublicKey: (0, import_utils5.bytesToHex)(leaf.tokenPublicKey),
273
- id: leaf.id,
274
- ownerPublicKey: (0, import_utils5.bytesToHex)(leaf.ownerPublicKey),
275
- revocationPublicKey: (0, import_utils5.bytesToHex)(leaf.revocationPublicKey),
276
- withdrawalBondSats: leaf.withdrawalBondSats,
277
- withdrawalLocktime: leaf.withdrawalLocktime,
278
- tokenAmount: (0, import_utils5.bytesToNumberBE)(leaf.tokenAmount).toString(),
279
- createTxHash: (0, import_utils5.bytesToHex)(leaf.createTxHash),
280
- createTxVoutIndex: leaf.createTxVoutIndex,
281
- spendTxHash: leaf.spendTxHash ? (0, import_utils5.bytesToHex)(leaf.spendTxHash) : void 0,
282
- spendTxVoutIndex: leaf.spendTxVoutIndex,
283
- isFrozen: leaf.isFrozen
284
- })),
285
- sparkOperatorIdentityPublicKeys: spark.sparkOperatorIdentityPublicKeys.map(
286
- (key) => (0, import_utils5.bytesToHex)(key)
287
- )
288
- }
289
- }
290
- };
291
- }
292
- return { transaction: void 0 };
293
- }),
294
- nextCursor: rawTransactions.nextCursor ? {
295
- lastTransactionHash: (0, import_utils5.bytesToHex)(
296
- rawTransactions.nextCursor.lastTransactionHash
297
- ),
298
- layer: getEnumName(import_lrc20.Layer, rawTransactions.nextCursor.layer)
299
- } : void 0
300
- };
301
- return response;
302
- }
303
- function getEnumName(enumObj, value) {
304
- return enumObj[value];
305
- }
306
-
307
209
  // src/issuer-wallet/issuer-spark-wallet.ts
308
210
  var import_spark_sdk4 = require("@buildonspark/spark-sdk");
309
- var import_lrc202 = require("@buildonspark/spark-sdk/proto/lrc20");
310
211
  var BURN_ADDRESS = "02".repeat(33);
311
212
  var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.SparkWallet {
312
213
  issuerTokenTransactionService;
@@ -358,10 +259,6 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
358
259
  "SparkIssuerWallet.unfreezeTokens",
359
260
  this.unfreezeTokens.bind(this)
360
261
  );
361
- this.getIssuerTokenActivity = this.wrapWithOtelSpan(
362
- "SparkIssuerWallet.getIssuerTokenActivity",
363
- this.getIssuerTokenActivity.bind(this)
364
- );
365
262
  this.getIssuerTokenDistribution = this.wrapWithOtelSpan(
366
263
  "SparkIssuerWallet.getIssuerTokenDistribution",
367
264
  this.getIssuerTokenDistribution.bind(this)
@@ -389,13 +286,16 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
389
286
  async getIssuerTokenBalance() {
390
287
  const publicKey = await super.getIdentityPublicKey();
391
288
  const balanceObj = await this.getBalance();
392
- if (!balanceObj.tokenBalances || !balanceObj.tokenBalances.has(publicKey)) {
289
+ const issuerBalance = [...balanceObj.tokenBalances.entries()].find(
290
+ ([, info]) => info.tokenMetadata.tokenPublicKey === publicKey
291
+ );
292
+ if (!balanceObj.tokenBalances || issuerBalance === void 0) {
393
293
  return {
394
294
  balance: 0n
395
295
  };
396
296
  }
397
297
  return {
398
- balance: balanceObj.tokenBalances.get(publicKey).balance
298
+ balance: issuerBalance[1].balance
399
299
  };
400
300
  }
401
301
  /**
@@ -407,17 +307,17 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
407
307
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
408
308
  try {
409
309
  const tokenInfo = await lrc20Client.getTokenPubkeyInfo({
410
- publicKeys: [(0, import_utils6.hexToBytes)(await super.getIdentityPublicKey())]
310
+ publicKeys: [(0, import_utils5.hexToBytes)(await super.getIdentityPublicKey())]
411
311
  });
412
312
  const info = tokenInfo.tokenPubkeyInfos[0];
413
313
  return {
414
- tokenPublicKey: (0, import_utils6.bytesToHex)(info.announcement.publicKey.publicKey),
314
+ tokenPublicKey: (0, import_utils5.bytesToHex)(info.announcement.publicKey.publicKey),
415
315
  tokenName: info.announcement.name,
416
316
  tokenSymbol: info.announcement.symbol,
417
- tokenDecimals: Number((0, import_utils6.bytesToNumberBE)(info.announcement.decimal)),
317
+ tokenDecimals: Number((0, import_utils5.bytesToNumberBE)(info.announcement.decimal)),
418
318
  isFreezable: info.announcement.isFreezable,
419
- maxSupply: (0, import_utils6.bytesToNumberBE)(info.announcement.maxSupply),
420
- totalSupply: (0, import_utils6.bytesToNumberBE)(info.totalSupply)
319
+ maxSupply: (0, import_utils5.bytesToNumberBE)(info.announcement.maxSupply),
320
+ totalSupply: (0, import_utils5.bytesToNumberBE)(info.totalSupply)
421
321
  };
422
322
  } catch (error) {
423
323
  throw new import_spark_sdk3.NetworkError("Failed to get token info", {
@@ -437,12 +337,12 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
437
337
  let tokenTransaction;
438
338
  if (this.config.getTokenTransactionVersion() === "V0") {
439
339
  tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransactionV0(
440
- (0, import_utils6.hexToBytes)(tokenPublicKey),
340
+ (0, import_utils5.hexToBytes)(tokenPublicKey),
441
341
  tokenAmount
442
342
  );
443
343
  } else {
444
344
  tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
445
- (0, import_utils6.hexToBytes)(tokenPublicKey),
345
+ (0, import_utils5.hexToBytes)(tokenPublicKey),
446
346
  tokenAmount
447
347
  );
448
348
  }
@@ -481,10 +381,10 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
481
381
  this.config.getNetworkType()
482
382
  );
483
383
  const response = await this.tokenFreezeService.freezeTokens(
484
- (0, import_utils6.hexToBytes)(decodedOwnerPubkey.identityPublicKey),
485
- (0, import_utils6.hexToBytes)(tokenPublicKey)
384
+ (0, import_utils5.hexToBytes)(decodedOwnerPubkey.identityPublicKey),
385
+ (0, import_utils5.hexToBytes)(tokenPublicKey)
486
386
  );
487
- const tokenAmount = (0, import_utils6.bytesToNumberBE)(response.impactedTokenAmount);
387
+ const tokenAmount = (0, import_utils5.bytesToNumberBE)(response.impactedTokenAmount);
488
388
  return {
489
389
  impactedOutputIds: response.impactedOutputIds,
490
390
  impactedTokenAmount: tokenAmount
@@ -503,105 +403,15 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk3.Spark
503
403
  this.config.getNetworkType()
504
404
  );
505
405
  const response = await this.tokenFreezeService.unfreezeTokens(
506
- (0, import_utils6.hexToBytes)(decodedOwnerPubkey.identityPublicKey),
507
- (0, import_utils6.hexToBytes)(tokenPublicKey)
406
+ (0, import_utils5.hexToBytes)(decodedOwnerPubkey.identityPublicKey),
407
+ (0, import_utils5.hexToBytes)(tokenPublicKey)
508
408
  );
509
- const tokenAmount = (0, import_utils6.bytesToNumberBE)(response.impactedTokenAmount);
409
+ const tokenAmount = (0, import_utils5.bytesToNumberBE)(response.impactedTokenAmount);
510
410
  return {
511
411
  impactedOutputIds: response.impactedOutputIds,
512
412
  impactedTokenAmount: tokenAmount
513
413
  };
514
414
  }
515
- /**
516
- * Retrieves the activity history for the issuer's token.
517
- * @param pageSize - The number of transactions to return per page (default: 100)
518
- * @param cursor - Optional cursor for pagination
519
- * @param operationTypes - Optional array of operation types to filter by
520
- * @param beforeTimestamp - Optional timestamp to filter transactions before
521
- * @param afterTimestamp - Optional timestamp to filter transactions after
522
- * @returns An object containing the token activity data
523
- * @throws {ValidationError} If pageSize is not a safe integer
524
- * @throws {NetworkError} If the activity data cannot be retrieved
525
- */
526
- async getIssuerTokenActivity(pageSize = 100, cursor, operationTypes, beforeTimestamp, afterTimestamp) {
527
- if (!Number.isSafeInteger(pageSize)) {
528
- throw new import_spark_sdk3.ValidationError("pageSize must be less than 2^53", {
529
- field: "pageSize",
530
- value: pageSize,
531
- expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER
532
- });
533
- }
534
- const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
535
- let convertedCursor;
536
- if (cursor) {
537
- const lastTransactionHash = typeof cursor.lastTransactionHash === "string" ? (0, import_utils6.hexToBytes)(cursor.lastTransactionHash) : cursor.lastTransactionHash;
538
- let layer;
539
- if (typeof cursor.layer === "string") {
540
- switch (cursor.layer.toUpperCase()) {
541
- case "L1":
542
- layer = import_lrc202.Layer.L1;
543
- break;
544
- case "Spark":
545
- layer = import_lrc202.Layer.SPARK;
546
- break;
547
- default:
548
- layer = import_lrc202.Layer.UNRECOGNIZED;
549
- }
550
- } else {
551
- layer = cursor.layer;
552
- }
553
- convertedCursor = {
554
- lastTransactionHash,
555
- layer
556
- };
557
- }
558
- let convertedOperationTypes;
559
- if (operationTypes) {
560
- if (typeof operationTypes[0] === "string") {
561
- convertedOperationTypes = operationTypes.map((opType) => {
562
- switch (opType.toUpperCase()) {
563
- case "USER_TRANSFER":
564
- return import_lrc202.OperationType.USER_TRANSFER;
565
- case "USER_BURN":
566
- return import_lrc202.OperationType.USER_BURN;
567
- case "ISSUER_ANNOUNCE":
568
- return import_lrc202.OperationType.ISSUER_ANNOUNCE;
569
- case "ISSUER_MINT":
570
- return import_lrc202.OperationType.ISSUER_MINT;
571
- case "ISSUER_TRANSFER":
572
- return import_lrc202.OperationType.ISSUER_TRANSFER;
573
- case "ISSUER_FREEZE":
574
- return import_lrc202.OperationType.ISSUER_FREEZE;
575
- case "ISSUER_UNFREEZE":
576
- return import_lrc202.OperationType.ISSUER_UNFREEZE;
577
- case "ISSUER_BURN":
578
- return import_lrc202.OperationType.ISSUER_BURN;
579
- default:
580
- return import_lrc202.OperationType.UNRECOGNIZED;
581
- }
582
- });
583
- } else {
584
- convertedOperationTypes = operationTypes;
585
- }
586
- }
587
- try {
588
- const transactions = await lrc20Client.listTransactions({
589
- tokenPublicKey: (0, import_utils6.hexToBytes)(await super.getIdentityPublicKey()),
590
- cursor: convertedCursor,
591
- pageSize,
592
- beforeTimestamp,
593
- afterTimestamp,
594
- operationTypes: convertedOperationTypes
595
- });
596
- return convertToTokenActivity(transactions);
597
- } catch (error) {
598
- throw new import_spark_sdk3.NetworkError("Failed to get token activity", {
599
- operation: "listTransactions",
600
- errorCount: 1,
601
- errors: error instanceof Error ? error.message : String(error)
602
- });
603
- }
604
- }
605
415
  /**
606
416
  * Retrieves the distribution information for the issuer's token.
607
417
  * @throws {NotImplementedError} This feature is not yet supported
package/dist/index.d.cts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { SparkWallet, SparkWalletProps } from '@buildonspark/spark-sdk';
2
2
  import { OutputWithPreviousTransactionData } from '@buildonspark/spark-sdk/proto/spark';
3
3
  import { ConfigOptions } from '@buildonspark/spark-sdk/services/wallet-config';
4
- import { TokenActivityResponse, TokenDistribution } from './types.cjs';
5
- import { Layer, OperationType } from '@buildonspark/spark-sdk/proto/lrc20';
4
+ import { TokenDistribution } from './types.cjs';
6
5
  import { SparkSigner } from '@buildonspark/spark-sdk/signer';
7
6
 
8
7
  type IssuerTokenInfo = {
@@ -78,21 +77,6 @@ declare class IssuerSparkWallet extends SparkWallet {
78
77
  impactedOutputIds: string[];
79
78
  impactedTokenAmount: bigint;
80
79
  }>;
81
- /**
82
- * Retrieves the activity history for the issuer's token.
83
- * @param pageSize - The number of transactions to return per page (default: 100)
84
- * @param cursor - Optional cursor for pagination
85
- * @param operationTypes - Optional array of operation types to filter by
86
- * @param beforeTimestamp - Optional timestamp to filter transactions before
87
- * @param afterTimestamp - Optional timestamp to filter transactions after
88
- * @returns An object containing the token activity data
89
- * @throws {ValidationError} If pageSize is not a safe integer
90
- * @throws {NetworkError} If the activity data cannot be retrieved
91
- */
92
- getIssuerTokenActivity(pageSize?: number, cursor?: {
93
- lastTransactionHash: string | Uint8Array;
94
- layer: string | Layer;
95
- }, operationTypes?: string[] | OperationType[], beforeTimestamp?: Date, afterTimestamp?: Date): Promise<TokenActivityResponse>;
96
80
  /**
97
81
  * Retrieves the distribution information for the issuer's token.
98
82
  * @throws {NotImplementedError} This feature is not yet supported
package/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { SparkWallet, SparkWalletProps } from '@buildonspark/spark-sdk';
2
2
  import { OutputWithPreviousTransactionData } from '@buildonspark/spark-sdk/proto/spark';
3
3
  import { ConfigOptions } from '@buildonspark/spark-sdk/services/wallet-config';
4
- import { TokenActivityResponse, TokenDistribution } from './types.js';
5
- import { Layer, OperationType } from '@buildonspark/spark-sdk/proto/lrc20';
4
+ import { TokenDistribution } from './types.js';
6
5
  import { SparkSigner } from '@buildonspark/spark-sdk/signer';
7
6
 
8
7
  type IssuerTokenInfo = {
@@ -78,21 +77,6 @@ declare class IssuerSparkWallet extends SparkWallet {
78
77
  impactedOutputIds: string[];
79
78
  impactedTokenAmount: bigint;
80
79
  }>;
81
- /**
82
- * Retrieves the activity history for the issuer's token.
83
- * @param pageSize - The number of transactions to return per page (default: 100)
84
- * @param cursor - Optional cursor for pagination
85
- * @param operationTypes - Optional array of operation types to filter by
86
- * @param beforeTimestamp - Optional timestamp to filter transactions before
87
- * @param afterTimestamp - Optional timestamp to filter transactions after
88
- * @returns An object containing the token activity data
89
- * @throws {ValidationError} If pageSize is not a safe integer
90
- * @throws {NetworkError} If the activity data cannot be retrieved
91
- */
92
- getIssuerTokenActivity(pageSize?: number, cursor?: {
93
- lastTransactionHash: string | Uint8Array;
94
- layer: string | Layer;
95
- }, operationTypes?: string[] | OperationType[], beforeTimestamp?: Date, afterTimestamp?: Date): Promise<TokenActivityResponse>;
96
80
  /**
97
81
  * Retrieves the distribution information for the issuer's token.
98
82
  * @throws {NotImplementedError} This feature is not yet supported