@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.
@@ -3,7 +3,11 @@ import {
3
3
  ListAllTokenTransactionsCursor,
4
4
  OperationType,
5
5
  } from "@buildonspark/lrc20-sdk/proto/rpc/v1/types";
6
- import { SparkWallet, SparkWalletProps } from "@buildonspark/spark-sdk";
6
+ import {
7
+ NetworkError,
8
+ SparkWallet,
9
+ SparkWalletProps,
10
+ } from "@buildonspark/spark-sdk";
7
11
  import {
8
12
  decodeSparkAddress,
9
13
  encodeSparkAddress,
@@ -19,6 +23,7 @@ import { TokenFreezeService } from "./services/freeze.js";
19
23
  import { IssuerTokenTransactionService } from "./services/token-transactions.js";
20
24
  import { GetTokenActivityResponse, TokenDistribution } from "./types.js";
21
25
  import { convertTokenActivityToHexEncoded } from "./utils/type-mappers.js";
26
+ import { NotImplementedError } from "@buildonspark/spark-sdk";
22
27
 
23
28
  const BURN_ADDRESS = "02".repeat(33);
24
29
 
@@ -76,19 +81,27 @@ export class IssuerSparkWallet extends SparkWallet {
76
81
  public async getIssuerTokenInfo(): Promise<IssuerTokenInfo | null> {
77
82
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
78
83
 
79
- const tokenInfo = await lrc20Client.getTokenPubkeyInfo({
80
- publicKeys: [hexToBytes(await super.getIdentityPublicKey())],
81
- });
84
+ try {
85
+ const tokenInfo = await lrc20Client.getTokenPubkeyInfo({
86
+ publicKeys: [hexToBytes(await super.getIdentityPublicKey())],
87
+ });
82
88
 
83
- const info = tokenInfo.tokenPubkeyInfos[0];
84
- return {
85
- tokenPublicKey: bytesToHex(info.announcement!.publicKey!.publicKey),
86
- tokenName: info.announcement!.name,
87
- tokenSymbol: info.announcement!.symbol,
88
- tokenDecimals: Number(bytesToNumberBE(info.announcement!.decimal)),
89
- isFreezable: info.announcement!.isFreezable,
90
- maxSupply: bytesToNumberBE(info.announcement!.maxSupply),
91
- };
89
+ const info = tokenInfo.tokenPubkeyInfos[0];
90
+ return {
91
+ tokenPublicKey: bytesToHex(info.announcement!.publicKey!.publicKey),
92
+ tokenName: info.announcement!.name,
93
+ tokenSymbol: info.announcement!.symbol,
94
+ tokenDecimals: Number(bytesToNumberBE(info.announcement!.decimal)),
95
+ isFreezable: info.announcement!.isFreezable,
96
+ maxSupply: bytesToNumberBE(info.announcement!.maxSupply),
97
+ };
98
+ } catch (error) {
99
+ throw new NetworkError("Failed to get token info", {
100
+ operation: "getIssuerTokenInfo",
101
+ errorCount: 1,
102
+ errors: error instanceof Error ? error.message : String(error),
103
+ });
104
+ }
92
105
  }
93
106
 
94
107
  public async mintTokens(tokenAmount: bigint): Promise<string> {
@@ -174,30 +187,38 @@ export class IssuerSparkWallet extends SparkWallet {
174
187
  ): Promise<GetTokenActivityResponse> {
175
188
  const lrc20Client = await this.lrc20ConnectionManager.createLrc20Client();
176
189
 
177
- const transactions = await lrc20Client.listTransactions({
178
- tokenPublicKey: hexToBytes(await super.getIdentityPublicKey()),
179
- cursor,
180
- pageSize,
181
- beforeTimestamp,
182
- afterTimestamp,
183
- operationTypes,
184
- });
185
-
186
- return convertTokenActivityToHexEncoded(transactions);
190
+ try {
191
+ const transactions = await lrc20Client.listTransactions({
192
+ tokenPublicKey: hexToBytes(await super.getIdentityPublicKey()),
193
+ cursor,
194
+ pageSize,
195
+ beforeTimestamp,
196
+ afterTimestamp,
197
+ operationTypes,
198
+ });
199
+
200
+ return convertTokenActivityToHexEncoded(transactions);
201
+ } catch (error) {
202
+ throw new NetworkError("Failed to get token activity", {
203
+ operation: "listTransactions",
204
+ errorCount: 1,
205
+ errors: error instanceof Error ? error.message : String(error),
206
+ });
207
+ }
187
208
  }
188
209
 
189
210
  public async getIssuerTokenDistribution(): Promise<TokenDistribution> {
190
- throw new Error("Not implemented");
211
+ throw new NotImplementedError("Token distribution is not yet supported");
191
212
  }
192
213
 
193
- public async announceTokenL1({
194
- tokenName,
195
- tokenTicker,
196
- decimals,
197
- maxSupply,
198
- isFreezable,
199
- feeRateSatsPerVb = 2.0,
200
- }): Promise<string> {
214
+ public async announceTokenL1(
215
+ tokenName: string,
216
+ tokenTicker: string,
217
+ decimals: number,
218
+ maxSupply: bigint,
219
+ isFreezable: boolean,
220
+ feeRateSatsPerVb: number = 4.0,
221
+ ): Promise<string> {
201
222
  await this.lrc20Wallet!.syncWallet();
202
223
 
203
224
  const tokenPublicKey = new TokenPubkey(this.lrc20Wallet!.pubkey);
@@ -211,13 +232,24 @@ export class IssuerSparkWallet extends SparkWallet {
211
232
  isFreezable,
212
233
  );
213
234
 
214
- const tx = await this.lrc20Wallet!.prepareAnnouncement(
215
- announcement,
216
- feeRateSatsPerVb,
217
- );
235
+ try {
236
+ const tx = await this.lrc20Wallet!.prepareAnnouncement(
237
+ announcement,
238
+ feeRateSatsPerVb,
239
+ );
218
240
 
219
- return await this.lrc20Wallet!.broadcastRawBtcTransaction(
220
- tx.bitcoin_tx.toHex(),
221
- );
241
+ return await this.lrc20Wallet!.broadcastRawBtcTransaction(
242
+ tx.bitcoin_tx.toHex(),
243
+ );
244
+ } catch (error) {
245
+ throw new NetworkError(
246
+ "Failed to broadcast announcement transaction on L1",
247
+ {
248
+ operation: "broadcastRawBtcTransaction",
249
+ errorCount: 1,
250
+ errors: error instanceof Error ? error.message : String(error),
251
+ },
252
+ );
253
+ }
222
254
  }
223
255
  }
@@ -6,6 +6,8 @@ import {
6
6
  } from "@buildonspark/spark-sdk/proto/spark";
7
7
  import { collectResponses } from "@buildonspark/spark-sdk/utils";
8
8
  import { hashFreezeTokensPayload } from "../utils/token-hashing.js";
9
+ import { NetworkError } from "@buildonspark/spark-sdk";
10
+ import { hexToBytes } from "@noble/curves/abstract/utils";
9
11
 
10
12
  export class TokenFreezeService {
11
13
  private readonly config: WalletConfigService;
@@ -52,7 +54,7 @@ export class TokenFreezeService {
52
54
  tokenPublicKey,
53
55
  shouldUnfreeze,
54
56
  issuerProvidedTimestamp,
55
- operatorIdentityPublicKey: operator.identityPublicKey,
57
+ operatorIdentityPublicKey: hexToBytes(operator.identityPublicKey),
56
58
  };
57
59
 
58
60
  const hashedPayload: Uint8Array =
@@ -61,14 +63,27 @@ export class TokenFreezeService {
61
63
  const issuerSignature =
62
64
  await this.config.signer.signMessageWithIdentityKey(hashedPayload);
63
65
 
64
- const response = await internalSparkClient.freeze_tokens({
65
- freezeTokensPayload,
66
- issuerSignature,
67
- });
68
- return {
69
- identifier,
70
- response,
71
- };
66
+ try {
67
+ const response = await internalSparkClient.freeze_tokens({
68
+ freezeTokensPayload,
69
+ issuerSignature,
70
+ });
71
+
72
+ return {
73
+ identifier,
74
+ response,
75
+ };
76
+ } catch (error) {
77
+ throw new NetworkError(
78
+ "Failed to send a freeze/unfreeze operation",
79
+ {
80
+ operation: "freeze_tokens",
81
+ errorCount: 1,
82
+ errors: error instanceof Error ? error.message : String(error),
83
+ },
84
+ error instanceof Error ? error : undefined,
85
+ );
86
+ }
72
87
  }),
73
88
  );
74
89