@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/dist/index.js CHANGED
@@ -13,8 +13,8 @@ import {
13
13
  encodeSparkAddress
14
14
  } from "@buildonspark/spark-sdk/address";
15
15
  import {
16
- bytesToHex as bytesToHex2,
17
- bytesToNumberBE as bytesToNumberBE2,
16
+ bytesToHex,
17
+ bytesToNumberBE,
18
18
  hexToBytes as hexToBytes2
19
19
  } from "@noble/curves/abstract/utils";
20
20
 
@@ -162,8 +162,7 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
162
162
  tokenInputs: {
163
163
  $case: "mintInput",
164
164
  mintInput: {
165
- issuerPublicKey: tokenPublicKey,
166
- issuerProvidedTimestamp: Date.now()
165
+ issuerPublicKey: tokenPublicKey
167
166
  }
168
167
  },
169
168
  tokenOutputs: [
@@ -173,121 +172,15 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
173
172
  tokenAmount: numberToBytesBE(tokenAmount, 16)
174
173
  }
175
174
  ],
175
+ clientCreatedTimestamp: /* @__PURE__ */ new Date(),
176
176
  sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys(),
177
177
  expiryTime: void 0
178
178
  };
179
179
  }
180
180
  };
181
181
 
182
- // src/utils/type-mappers.ts
183
- import { bytesToHex, bytesToNumberBE } from "@noble/curves/abstract/utils";
184
- import {
185
- OperationType,
186
- OnChainTransactionStatus,
187
- SparkTransactionStatus,
188
- Layer
189
- } from "@buildonspark/spark-sdk/proto/lrc20";
190
- function convertToTokenActivity(rawTransactions) {
191
- const response = {
192
- transactions: rawTransactions.transactions.map((transaction) => {
193
- if (!transaction.transaction) {
194
- return { transaction: void 0 };
195
- }
196
- if (transaction.transaction.$case === "onChain") {
197
- const onChain = transaction.transaction.onChain;
198
- return {
199
- transaction: {
200
- $case: "onChain",
201
- onChain: {
202
- operationType: getEnumName(OperationType, onChain.operationType),
203
- transactionHash: bytesToHex(onChain.transactionHash),
204
- rawtx: bytesToHex(onChain.rawtx),
205
- status: getEnumName(OnChainTransactionStatus, onChain.status),
206
- inputs: onChain.inputs.map((input) => ({
207
- rawTx: bytesToHex(input.rawTx),
208
- vout: input.vout,
209
- amountSats: input.amountSats,
210
- tokenPublicKey: input.tokenPublicKey,
211
- tokenAmount: input.tokenAmount ? bytesToNumberBE(input.tokenAmount).toString() : void 0
212
- })),
213
- outputs: onChain.outputs.map((output) => ({
214
- rawTx: bytesToHex(output.rawTx),
215
- vout: output.vout,
216
- amountSats: output.amountSats,
217
- tokenPublicKey: output.tokenPublicKey,
218
- tokenAmount: output.tokenAmount ? bytesToNumberBE(output.tokenAmount).toString() : void 0
219
- })),
220
- broadcastedAt: onChain.broadcastedAt,
221
- confirmedAt: onChain.confirmedAt
222
- }
223
- }
224
- };
225
- } else if (transaction.transaction.$case === "spark") {
226
- const spark = transaction.transaction.spark;
227
- return {
228
- transaction: {
229
- $case: "spark",
230
- spark: {
231
- operationType: getEnumName(OperationType, spark.operationType),
232
- transactionHash: bytesToHex(spark.transactionHash),
233
- status: getEnumName(SparkTransactionStatus, spark.status),
234
- confirmedAt: spark.confirmedAt,
235
- leavesToCreate: spark.leavesToCreate.map((leaf) => ({
236
- tokenPublicKey: bytesToHex(leaf.tokenPublicKey),
237
- id: leaf.id,
238
- ownerPublicKey: bytesToHex(leaf.ownerPublicKey),
239
- revocationPublicKey: bytesToHex(leaf.revocationPublicKey),
240
- withdrawalBondSats: leaf.withdrawalBondSats,
241
- withdrawalLocktime: leaf.withdrawalLocktime,
242
- tokenAmount: bytesToNumberBE(leaf.tokenAmount).toString(),
243
- createTxHash: bytesToHex(leaf.createTxHash),
244
- createTxVoutIndex: leaf.createTxVoutIndex,
245
- spendTxHash: leaf.spendTxHash ? bytesToHex(leaf.spendTxHash) : void 0,
246
- spendTxVoutIndex: leaf.spendTxVoutIndex,
247
- isFrozen: leaf.isFrozen
248
- })),
249
- leavesToSpend: spark.leavesToSpend.map((leaf) => ({
250
- tokenPublicKey: bytesToHex(leaf.tokenPublicKey),
251
- id: leaf.id,
252
- ownerPublicKey: bytesToHex(leaf.ownerPublicKey),
253
- revocationPublicKey: bytesToHex(leaf.revocationPublicKey),
254
- withdrawalBondSats: leaf.withdrawalBondSats,
255
- withdrawalLocktime: leaf.withdrawalLocktime,
256
- tokenAmount: bytesToNumberBE(leaf.tokenAmount).toString(),
257
- createTxHash: bytesToHex(leaf.createTxHash),
258
- createTxVoutIndex: leaf.createTxVoutIndex,
259
- spendTxHash: leaf.spendTxHash ? bytesToHex(leaf.spendTxHash) : void 0,
260
- spendTxVoutIndex: leaf.spendTxVoutIndex,
261
- isFrozen: leaf.isFrozen
262
- })),
263
- sparkOperatorIdentityPublicKeys: spark.sparkOperatorIdentityPublicKeys.map(
264
- (key) => bytesToHex(key)
265
- )
266
- }
267
- }
268
- };
269
- }
270
- return { transaction: void 0 };
271
- }),
272
- nextCursor: rawTransactions.nextCursor ? {
273
- lastTransactionHash: bytesToHex(
274
- rawTransactions.nextCursor.lastTransactionHash
275
- ),
276
- layer: getEnumName(Layer, rawTransactions.nextCursor.layer)
277
- } : void 0
278
- };
279
- return response;
280
- }
281
- function getEnumName(enumObj, value) {
282
- return enumObj[value];
283
- }
284
-
285
182
  // src/issuer-wallet/issuer-spark-wallet.ts
286
183
  import { NotImplementedError } from "@buildonspark/spark-sdk";
287
- import {
288
- Layer as Layer2,
289
- OperationType as OperationType2
290
- } from "@buildonspark/spark-sdk/proto/lrc20";
291
184
  var BURN_ADDRESS = "02".repeat(33);
292
185
  var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
293
186
  issuerTokenTransactionService;
@@ -339,10 +232,6 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
339
232
  "SparkIssuerWallet.unfreezeTokens",
340
233
  this.unfreezeTokens.bind(this)
341
234
  );
342
- this.getIssuerTokenActivity = this.wrapWithOtelSpan(
343
- "SparkIssuerWallet.getIssuerTokenActivity",
344
- this.getIssuerTokenActivity.bind(this)
345
- );
346
235
  this.getIssuerTokenDistribution = this.wrapWithOtelSpan(
347
236
  "SparkIssuerWallet.getIssuerTokenDistribution",
348
237
  this.getIssuerTokenDistribution.bind(this)
@@ -370,13 +259,16 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
370
259
  async getIssuerTokenBalance() {
371
260
  const publicKey = await super.getIdentityPublicKey();
372
261
  const balanceObj = await this.getBalance();
373
- if (!balanceObj.tokenBalances || !balanceObj.tokenBalances.has(publicKey)) {
262
+ const issuerBalance = [...balanceObj.tokenBalances.entries()].find(
263
+ ([, info]) => info.tokenMetadata.tokenPublicKey === publicKey
264
+ );
265
+ if (!balanceObj.tokenBalances || issuerBalance === void 0) {
374
266
  return {
375
267
  balance: 0n
376
268
  };
377
269
  }
378
270
  return {
379
- balance: balanceObj.tokenBalances.get(publicKey).balance
271
+ balance: issuerBalance[1].balance
380
272
  };
381
273
  }
382
274
  /**
@@ -392,13 +284,13 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
392
284
  });
393
285
  const info = tokenInfo.tokenPubkeyInfos[0];
394
286
  return {
395
- tokenPublicKey: bytesToHex2(info.announcement.publicKey.publicKey),
287
+ tokenPublicKey: bytesToHex(info.announcement.publicKey.publicKey),
396
288
  tokenName: info.announcement.name,
397
289
  tokenSymbol: info.announcement.symbol,
398
- tokenDecimals: Number(bytesToNumberBE2(info.announcement.decimal)),
290
+ tokenDecimals: Number(bytesToNumberBE(info.announcement.decimal)),
399
291
  isFreezable: info.announcement.isFreezable,
400
- maxSupply: bytesToNumberBE2(info.announcement.maxSupply),
401
- totalSupply: bytesToNumberBE2(info.totalSupply)
292
+ maxSupply: bytesToNumberBE(info.announcement.maxSupply),
293
+ totalSupply: bytesToNumberBE(info.totalSupply)
402
294
  };
403
295
  } catch (error) {
404
296
  throw new NetworkError2("Failed to get token info", {
@@ -465,7 +357,7 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
465
357
  hexToBytes2(decodedOwnerPubkey.identityPublicKey),
466
358
  hexToBytes2(tokenPublicKey)
467
359
  );
468
- const tokenAmount = bytesToNumberBE2(response.impactedTokenAmount);
360
+ const tokenAmount = bytesToNumberBE(response.impactedTokenAmount);
469
361
  return {
470
362
  impactedOutputIds: response.impactedOutputIds,
471
363
  impactedTokenAmount: tokenAmount
@@ -487,102 +379,12 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
487
379
  hexToBytes2(decodedOwnerPubkey.identityPublicKey),
488
380
  hexToBytes2(tokenPublicKey)
489
381
  );
490
- const tokenAmount = bytesToNumberBE2(response.impactedTokenAmount);
382
+ const tokenAmount = bytesToNumberBE(response.impactedTokenAmount);
491
383
  return {
492
384
  impactedOutputIds: response.impactedOutputIds,
493
385
  impactedTokenAmount: tokenAmount
494
386
  };
495
387
  }
496
- /**
497
- * Retrieves the activity history for the issuer's token.
498
- * @param pageSize - The number of transactions to return per page (default: 100)
499
- * @param cursor - Optional cursor for pagination
500
- * @param operationTypes - Optional array of operation types to filter by
501
- * @param beforeTimestamp - Optional timestamp to filter transactions before
502
- * @param afterTimestamp - Optional timestamp to filter transactions after
503
- * @returns An object containing the token activity data
504
- * @throws {ValidationError} If pageSize is not a safe integer
505
- * @throws {NetworkError} If the activity data cannot be retrieved
506
- */
507
- async getIssuerTokenActivity(pageSize = 100, cursor, operationTypes, beforeTimestamp, afterTimestamp) {
508
- if (!Number.isSafeInteger(pageSize)) {
509
- throw new ValidationError2("pageSize must be less than 2^53", {
510
- field: "pageSize",
511
- value: pageSize,
512
- expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER
513
- });
514
- }
515
- const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
516
- let convertedCursor;
517
- if (cursor) {
518
- const lastTransactionHash = typeof cursor.lastTransactionHash === "string" ? hexToBytes2(cursor.lastTransactionHash) : cursor.lastTransactionHash;
519
- let layer;
520
- if (typeof cursor.layer === "string") {
521
- switch (cursor.layer.toUpperCase()) {
522
- case "L1":
523
- layer = Layer2.L1;
524
- break;
525
- case "Spark":
526
- layer = Layer2.SPARK;
527
- break;
528
- default:
529
- layer = Layer2.UNRECOGNIZED;
530
- }
531
- } else {
532
- layer = cursor.layer;
533
- }
534
- convertedCursor = {
535
- lastTransactionHash,
536
- layer
537
- };
538
- }
539
- let convertedOperationTypes;
540
- if (operationTypes) {
541
- if (typeof operationTypes[0] === "string") {
542
- convertedOperationTypes = operationTypes.map((opType) => {
543
- switch (opType.toUpperCase()) {
544
- case "USER_TRANSFER":
545
- return OperationType2.USER_TRANSFER;
546
- case "USER_BURN":
547
- return OperationType2.USER_BURN;
548
- case "ISSUER_ANNOUNCE":
549
- return OperationType2.ISSUER_ANNOUNCE;
550
- case "ISSUER_MINT":
551
- return OperationType2.ISSUER_MINT;
552
- case "ISSUER_TRANSFER":
553
- return OperationType2.ISSUER_TRANSFER;
554
- case "ISSUER_FREEZE":
555
- return OperationType2.ISSUER_FREEZE;
556
- case "ISSUER_UNFREEZE":
557
- return OperationType2.ISSUER_UNFREEZE;
558
- case "ISSUER_BURN":
559
- return OperationType2.ISSUER_BURN;
560
- default:
561
- return OperationType2.UNRECOGNIZED;
562
- }
563
- });
564
- } else {
565
- convertedOperationTypes = operationTypes;
566
- }
567
- }
568
- try {
569
- const transactions = await lrc20Client.listTransactions({
570
- tokenPublicKey: hexToBytes2(await super.getIdentityPublicKey()),
571
- cursor: convertedCursor,
572
- pageSize,
573
- beforeTimestamp,
574
- afterTimestamp,
575
- operationTypes: convertedOperationTypes
576
- });
577
- return convertToTokenActivity(transactions);
578
- } catch (error) {
579
- throw new NetworkError2("Failed to get token activity", {
580
- operation: "listTransactions",
581
- errorCount: 1,
582
- errors: error instanceof Error ? error.message : String(error)
583
- });
584
- }
585
- }
586
388
  /**
587
389
  * Retrieves the distribution information for the issuer's token.
588
390
  * @throws {NotImplementedError} This feature is not yet supported
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@buildonspark/issuer-sdk",
3
- "version": "0.0.75",
3
+ "version": "0.0.76",
4
4
  "description": "Spark Issuer SDK for token issuance",
5
5
  "license": "Apache-2.0",
6
6
  "module": "./dist/index.js",
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@buildonspark/lrc20-sdk": "0.0.58",
66
- "@buildonspark/spark-sdk": "0.1.44",
66
+ "@buildonspark/spark-sdk": "0.1.45",
67
67
  "@lightsparkdev/core": "^1.4.2",
68
68
  "@noble/curves": "^1.8.0",
69
69
  "@scure/btc-signer": "^1.5.0",
@@ -105,10 +105,6 @@ export class IssuerSparkWallet extends SparkWallet {
105
105
  "SparkIssuerWallet.unfreezeTokens",
106
106
  this.unfreezeTokens.bind(this),
107
107
  );
108
- this.getIssuerTokenActivity = this.wrapWithOtelSpan(
109
- "SparkIssuerWallet.getIssuerTokenActivity",
110
- this.getIssuerTokenActivity.bind(this),
111
- );
112
108
  this.getIssuerTokenDistribution = this.wrapWithOtelSpan(
113
109
  "SparkIssuerWallet.getIssuerTokenDistribution",
114
110
  this.getIssuerTokenDistribution.bind(this),
@@ -140,14 +136,17 @@ export class IssuerSparkWallet extends SparkWallet {
140
136
  }> {
141
137
  const publicKey = await super.getIdentityPublicKey();
142
138
  const balanceObj = await this.getBalance();
139
+ const issuerBalance = [...balanceObj.tokenBalances.entries()].find(
140
+ ([, info]) => info.tokenMetadata.tokenPublicKey === publicKey,
141
+ ); // [tokenIdentifier, { balance, tokenMetadata }]
143
142
 
144
- if (!balanceObj.tokenBalances || !balanceObj.tokenBalances.has(publicKey)) {
143
+ if (!balanceObj.tokenBalances || issuerBalance === undefined) {
145
144
  return {
146
145
  balance: 0n,
147
146
  };
148
147
  }
149
148
  return {
150
- balance: balanceObj.tokenBalances.get(publicKey)!.balance,
149
+ balance: issuerBalance[1].balance,
151
150
  };
152
151
  }
153
152
 
@@ -287,118 +286,6 @@ export class IssuerSparkWallet extends SparkWallet {
287
286
  };
288
287
  }
289
288
 
290
- /**
291
- * Retrieves the activity history for the issuer's token.
292
- * @param pageSize - The number of transactions to return per page (default: 100)
293
- * @param cursor - Optional cursor for pagination
294
- * @param operationTypes - Optional array of operation types to filter by
295
- * @param beforeTimestamp - Optional timestamp to filter transactions before
296
- * @param afterTimestamp - Optional timestamp to filter transactions after
297
- * @returns An object containing the token activity data
298
- * @throws {ValidationError} If pageSize is not a safe integer
299
- * @throws {NetworkError} If the activity data cannot be retrieved
300
- */
301
- public async getIssuerTokenActivity(
302
- pageSize: number = 100,
303
- cursor?: {
304
- lastTransactionHash: string | Uint8Array;
305
- layer: string | Layer;
306
- },
307
- operationTypes?: string[] | OperationType[],
308
- beforeTimestamp?: Date,
309
- afterTimestamp?: Date,
310
- ): Promise<TokenActivityResponse> {
311
- if (!Number.isSafeInteger(pageSize)) {
312
- throw new ValidationError("pageSize must be less than 2^53", {
313
- field: "pageSize",
314
- value: pageSize,
315
- expected: "smaller or equal to " + Number.MAX_SAFE_INTEGER,
316
- });
317
- }
318
-
319
- const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
320
-
321
- // Convert cursor to proper ListAllTokenTransactionsCursor format
322
- let convertedCursor: ListAllTokenTransactionsCursor | undefined;
323
- if (cursor) {
324
- const lastTransactionHash =
325
- typeof cursor.lastTransactionHash === "string"
326
- ? hexToBytes(cursor.lastTransactionHash)
327
- : cursor.lastTransactionHash;
328
-
329
- let layer: Layer;
330
- if (typeof cursor.layer === "string") {
331
- switch (cursor.layer.toUpperCase()) {
332
- case "L1":
333
- layer = Layer.L1;
334
- break;
335
- case "Spark":
336
- layer = Layer.SPARK;
337
- break;
338
- default:
339
- layer = Layer.UNRECOGNIZED;
340
- }
341
- } else {
342
- layer = cursor.layer;
343
- }
344
-
345
- convertedCursor = {
346
- lastTransactionHash,
347
- layer,
348
- };
349
- }
350
-
351
- // Convert operationTypes to proper OperationType[] format
352
- let convertedOperationTypes: OperationType[] | undefined;
353
- if (operationTypes) {
354
- if (typeof operationTypes[0] === "string") {
355
- convertedOperationTypes = (operationTypes as string[]).map((opType) => {
356
- switch (opType.toUpperCase()) {
357
- case "USER_TRANSFER":
358
- return OperationType.USER_TRANSFER;
359
- case "USER_BURN":
360
- return OperationType.USER_BURN;
361
- case "ISSUER_ANNOUNCE":
362
- return OperationType.ISSUER_ANNOUNCE;
363
- case "ISSUER_MINT":
364
- return OperationType.ISSUER_MINT;
365
- case "ISSUER_TRANSFER":
366
- return OperationType.ISSUER_TRANSFER;
367
- case "ISSUER_FREEZE":
368
- return OperationType.ISSUER_FREEZE;
369
- case "ISSUER_UNFREEZE":
370
- return OperationType.ISSUER_UNFREEZE;
371
- case "ISSUER_BURN":
372
- return OperationType.ISSUER_BURN;
373
- default:
374
- return OperationType.UNRECOGNIZED;
375
- }
376
- });
377
- } else {
378
- convertedOperationTypes = operationTypes as OperationType[];
379
- }
380
- }
381
-
382
- try {
383
- const transactions = await lrc20Client.listTransactions({
384
- tokenPublicKey: hexToBytes(await super.getIdentityPublicKey()),
385
- cursor: convertedCursor,
386
- pageSize,
387
- beforeTimestamp,
388
- afterTimestamp,
389
- operationTypes: convertedOperationTypes,
390
- });
391
-
392
- return convertToTokenActivity(transactions);
393
- } catch (error) {
394
- throw new NetworkError("Failed to get token activity", {
395
- operation: "listTransactions",
396
- errorCount: 1,
397
- errors: error instanceof Error ? error.message : String(error),
398
- });
399
- }
400
- }
401
-
402
289
  /**
403
290
  * Retrieves the distribution information for the issuer's token.
404
291
  * @throws {NotImplementedError} This feature is not yet supported
@@ -49,7 +49,6 @@ export class IssuerTokenTransactionService extends TokenTransactionService {
49
49
  $case: "mintInput",
50
50
  mintInput: {
51
51
  issuerPublicKey: tokenPublicKey,
52
- issuerProvidedTimestamp: Date.now(),
53
52
  },
54
53
  },
55
54
  tokenOutputs: [
@@ -59,6 +58,7 @@ export class IssuerTokenTransactionService extends TokenTransactionService {
59
58
  tokenAmount: numberToBytesBE(tokenAmount, 16),
60
59
  },
61
60
  ],
61
+ clientCreatedTimestamp: new Date(),
62
62
  sparkOperatorIdentityPublicKeys:
63
63
  super.collectOperatorIdentityPublicKeys(),
64
64
  expiryTime: undefined,