@buildonspark/issuer-sdk 0.0.84 → 0.0.86

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.
@@ -0,0 +1,655 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.node.ts
21
+ var index_node_exports = {};
22
+ __export(index_node_exports, {
23
+ IssuerSparkWallet: () => IssuerSparkWalletNodeJS
24
+ });
25
+ module.exports = __toCommonJS(index_node_exports);
26
+
27
+ // buffer.js
28
+ var import_buffer = require("buffer");
29
+ if (typeof globalThis.Buffer === "undefined") {
30
+ globalThis.Buffer = import_buffer.Buffer;
31
+ }
32
+ if (typeof window !== "undefined") {
33
+ if (typeof window.global === "undefined") {
34
+ window.global = window;
35
+ }
36
+ if (typeof window.globalThis === "undefined") {
37
+ window.globalThis = window;
38
+ }
39
+ }
40
+
41
+ // src/issuer-wallet/issuer-spark-wallet.ts
42
+ var import_spark_sdk5 = require("@buildonspark/spark-sdk");
43
+ var import_spark_sdk6 = require("@buildonspark/spark-sdk");
44
+ var import_utils4 = require("@noble/curves/abstract/utils");
45
+ var import_spark_sdk7 = require("@buildonspark/spark-sdk");
46
+
47
+ // src/services/freeze.ts
48
+ var import_spark_sdk2 = require("@buildonspark/spark-sdk");
49
+
50
+ // src/utils/token-hashing.ts
51
+ var import_utils = require("@scure/btc-signer/utils");
52
+ var import_spark_sdk = require("@buildonspark/spark-sdk");
53
+ function hashFreezeTokensPayload(payload) {
54
+ if (!payload) {
55
+ throw new import_spark_sdk.ValidationError("Freeze tokens payload cannot be nil", {
56
+ field: "payload",
57
+ value: payload,
58
+ expected: "valid freeze tokens payload"
59
+ });
60
+ }
61
+ let allHashes = [];
62
+ const versionHashObj = import_utils.sha256.create();
63
+ const versionBytes = new Uint8Array(4);
64
+ new DataView(versionBytes.buffer).setUint32(
65
+ 0,
66
+ payload.version,
67
+ false
68
+ // false for big-endian
69
+ );
70
+ versionHashObj.update(versionBytes);
71
+ allHashes.push(versionHashObj.digest());
72
+ const ownerPubKeyHash = import_utils.sha256.create();
73
+ if (payload.ownerPublicKey) {
74
+ ownerPubKeyHash.update(payload.ownerPublicKey);
75
+ }
76
+ allHashes.push(ownerPubKeyHash.digest());
77
+ const tokenIdentifierHash = import_utils.sha256.create();
78
+ if (payload.tokenIdentifier) {
79
+ tokenIdentifierHash.update(payload.tokenIdentifier);
80
+ }
81
+ allHashes.push(tokenIdentifierHash.digest());
82
+ const shouldUnfreezeHash = import_utils.sha256.create();
83
+ shouldUnfreezeHash.update(new Uint8Array([payload.shouldUnfreeze ? 1 : 0]));
84
+ allHashes.push(shouldUnfreezeHash.digest());
85
+ const timestampHash = import_utils.sha256.create();
86
+ if (payload.issuerProvidedTimestamp) {
87
+ const timestampBytes = new Uint8Array(8);
88
+ new DataView(timestampBytes.buffer).setBigUint64(
89
+ 0,
90
+ BigInt(payload.issuerProvidedTimestamp),
91
+ true
92
+ // true for little-endian
93
+ );
94
+ timestampHash.update(timestampBytes);
95
+ }
96
+ allHashes.push(timestampHash.digest());
97
+ const operatorPubKeyHash = import_utils.sha256.create();
98
+ if (payload.operatorIdentityPublicKey) {
99
+ operatorPubKeyHash.update(payload.operatorIdentityPublicKey);
100
+ }
101
+ allHashes.push(operatorPubKeyHash.digest());
102
+ const finalHash = import_utils.sha256.create();
103
+ for (const hash of allHashes) {
104
+ finalHash.update(hash);
105
+ }
106
+ return finalHash.digest();
107
+ }
108
+
109
+ // src/services/freeze.ts
110
+ var import_utils2 = require("@noble/curves/abstract/utils");
111
+ var TokenFreezeService = class {
112
+ config;
113
+ connectionManager;
114
+ constructor(config, connectionManager) {
115
+ this.config = config;
116
+ this.connectionManager = connectionManager;
117
+ }
118
+ async freezeTokens({
119
+ ownerPublicKey,
120
+ tokenIdentifier
121
+ }) {
122
+ return this.freezeOperation(ownerPublicKey, false, tokenIdentifier);
123
+ }
124
+ async unfreezeTokens({
125
+ ownerPublicKey,
126
+ tokenIdentifier
127
+ }) {
128
+ return this.freezeOperation(ownerPublicKey, true, tokenIdentifier);
129
+ }
130
+ async freezeOperation(ownerPublicKey, shouldUnfreeze, tokenIdentifier) {
131
+ const signingOperators = this.config.getSigningOperators();
132
+ const issuerProvidedTimestamp = Date.now();
133
+ const freezeResponses = await Promise.allSettled(
134
+ Object.entries(signingOperators).map(async ([identifier, operator]) => {
135
+ const sparkTokenClient = await this.connectionManager.createSparkTokenClient(operator.address);
136
+ const freezeTokensPayload = {
137
+ version: 1,
138
+ ownerPublicKey,
139
+ tokenIdentifier,
140
+ shouldUnfreeze,
141
+ issuerProvidedTimestamp,
142
+ operatorIdentityPublicKey: (0, import_utils2.hexToBytes)(operator.identityPublicKey)
143
+ };
144
+ const hashedPayload = hashFreezeTokensPayload(freezeTokensPayload);
145
+ const issuerSignature = await this.config.signer.signMessageWithIdentityKey(hashedPayload);
146
+ try {
147
+ const response = await sparkTokenClient.freeze_tokens({
148
+ freezeTokensPayload,
149
+ issuerSignature
150
+ });
151
+ return {
152
+ identifier,
153
+ response
154
+ };
155
+ } catch (error) {
156
+ throw new import_spark_sdk2.NetworkError(
157
+ `Failed to send a freeze/unfreeze operation to operator: ${operator.address}`,
158
+ {
159
+ operation: "freeze_tokens",
160
+ errorCount: 1,
161
+ errors: error instanceof Error ? error.message : String(error)
162
+ },
163
+ error instanceof Error ? error : void 0
164
+ );
165
+ }
166
+ })
167
+ );
168
+ const successfulResponses = (0, import_spark_sdk2.collectResponses)(freezeResponses);
169
+ return successfulResponses[0].response;
170
+ }
171
+ };
172
+
173
+ // src/services/token-transactions.ts
174
+ var import_spark_sdk3 = require("@buildonspark/spark-sdk");
175
+ var import_utils3 = require("@noble/curves/abstract/utils");
176
+ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransactionService {
177
+ constructor(config, connectionManager) {
178
+ super(config, connectionManager);
179
+ }
180
+ async constructMintTokenTransactionV0(tokenPublicKey, tokenAmount) {
181
+ return {
182
+ network: this.config.getNetworkProto(),
183
+ tokenInputs: {
184
+ $case: "mintInput",
185
+ mintInput: {
186
+ issuerPublicKey: tokenPublicKey,
187
+ issuerProvidedTimestamp: Date.now()
188
+ }
189
+ },
190
+ tokenOutputs: [
191
+ {
192
+ ownerPublicKey: tokenPublicKey,
193
+ tokenPublicKey,
194
+ tokenAmount: (0, import_utils3.numberToBytesBE)(tokenAmount, 16)
195
+ }
196
+ ],
197
+ sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys()
198
+ };
199
+ }
200
+ async constructMintTokenTransaction(rawTokenIdentifierBytes, issuerTokenPublicKey, tokenAmount) {
201
+ return {
202
+ version: 1,
203
+ network: this.config.getNetworkProto(),
204
+ tokenInputs: {
205
+ $case: "mintInput",
206
+ mintInput: {
207
+ issuerPublicKey: issuerTokenPublicKey,
208
+ tokenIdentifier: rawTokenIdentifierBytes
209
+ }
210
+ },
211
+ tokenOutputs: [
212
+ {
213
+ ownerPublicKey: issuerTokenPublicKey,
214
+ tokenIdentifier: rawTokenIdentifierBytes,
215
+ tokenAmount: (0, import_utils3.numberToBytesBE)(tokenAmount, 16)
216
+ }
217
+ ],
218
+ clientCreatedTimestamp: /* @__PURE__ */ new Date(),
219
+ sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys(),
220
+ expiryTime: void 0
221
+ };
222
+ }
223
+ async constructCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable) {
224
+ return {
225
+ version: 1,
226
+ network: this.config.getNetworkProto(),
227
+ tokenInputs: {
228
+ $case: "createInput",
229
+ createInput: {
230
+ issuerPublicKey: tokenPublicKey,
231
+ tokenName,
232
+ tokenTicker,
233
+ decimals,
234
+ maxSupply: (0, import_utils3.numberToBytesBE)(maxSupply, 16),
235
+ isFreezable
236
+ }
237
+ },
238
+ tokenOutputs: [],
239
+ clientCreatedTimestamp: /* @__PURE__ */ new Date(),
240
+ sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys(),
241
+ expiryTime: void 0
242
+ };
243
+ }
244
+ };
245
+
246
+ // src/issuer-wallet/issuer-spark-wallet.ts
247
+ var import_spark_sdk8 = require("@buildonspark/spark-sdk");
248
+
249
+ // src/utils/create-validation.ts
250
+ var import_spark_sdk4 = require("@buildonspark/spark-sdk");
251
+ function isNfcNormalized(value) {
252
+ return value.normalize("NFC") === value;
253
+ }
254
+ var MIN_NAME_SIZE = 3;
255
+ var MAX_NAME_SIZE = 20;
256
+ var MIN_SYMBOL_SIZE = 3;
257
+ var MAX_SYMBOL_SIZE = 6;
258
+ var MAX_DECIMALS = 255;
259
+ var MAXIMUM_MAX_SUPPLY = (1n << 128n) - 1n;
260
+ function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply) {
261
+ if (!isNfcNormalized(tokenName)) {
262
+ throw new import_spark_sdk4.ValidationError("Token name must be NFC-normalised UTF-8", {
263
+ field: "tokenName",
264
+ value: tokenName,
265
+ expected: "NFC normalised string"
266
+ });
267
+ }
268
+ if (!isNfcNormalized(tokenTicker)) {
269
+ throw new import_spark_sdk4.ValidationError("Token ticker must be NFC-normalised UTF-8", {
270
+ field: "tokenTicker",
271
+ value: tokenTicker,
272
+ expected: "NFC normalised string"
273
+ });
274
+ }
275
+ const nameBytes = import_buffer.Buffer.from(tokenName, "utf-8").length;
276
+ if (nameBytes < MIN_NAME_SIZE || nameBytes > MAX_NAME_SIZE) {
277
+ throw new import_spark_sdk4.ValidationError(
278
+ `Token name must be between ${MIN_NAME_SIZE} and ${MAX_NAME_SIZE} bytes`,
279
+ {
280
+ field: "tokenName",
281
+ value: tokenName,
282
+ actualLength: nameBytes,
283
+ expected: `>=${MIN_NAME_SIZE} and <=${MAX_NAME_SIZE}`
284
+ }
285
+ );
286
+ }
287
+ const tickerBytes = import_buffer.Buffer.from(tokenTicker, "utf-8").length;
288
+ if (tickerBytes < MIN_SYMBOL_SIZE || tickerBytes > MAX_SYMBOL_SIZE) {
289
+ throw new import_spark_sdk4.ValidationError(
290
+ `Token ticker must be between ${MIN_SYMBOL_SIZE} and ${MAX_SYMBOL_SIZE} bytes`,
291
+ {
292
+ field: "tokenTicker",
293
+ value: tokenTicker,
294
+ actualLength: tickerBytes,
295
+ expected: `>=${MIN_SYMBOL_SIZE} and <=${MAX_SYMBOL_SIZE}`
296
+ }
297
+ );
298
+ }
299
+ if (!Number.isSafeInteger(decimals) || decimals < 0 || decimals > MAX_DECIMALS) {
300
+ throw new import_spark_sdk4.ValidationError(
301
+ `Decimals must be an integer between 0 and ${MAX_DECIMALS}`,
302
+ {
303
+ field: "decimals",
304
+ value: decimals,
305
+ expected: `>=0 and <=${MAX_DECIMALS}`
306
+ }
307
+ );
308
+ }
309
+ if (maxSupply < 0n || maxSupply > MAXIMUM_MAX_SUPPLY) {
310
+ throw new import_spark_sdk4.ValidationError(`maxSupply must be between 0 and 2^128-1`, {
311
+ field: "maxSupply",
312
+ value: maxSupply.toString(),
313
+ expected: `>=0 and <=${MAXIMUM_MAX_SUPPLY.toString()}`
314
+ });
315
+ }
316
+ }
317
+
318
+ // src/issuer-wallet/issuer-spark-wallet.ts
319
+ var import_spark_sdk9 = require("@buildonspark/spark-sdk");
320
+ var BURN_ADDRESS = "02".repeat(33);
321
+ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk5.SparkWallet {
322
+ issuerTokenTransactionService;
323
+ tokenFreezeService;
324
+ tracerId = "issuer-sdk";
325
+ /**
326
+ * Initializes a new IssuerSparkWallet instance.
327
+ * @param options - Configuration options for the wallet
328
+ * @returns An object containing the initialized wallet and initialization response
329
+ */
330
+ static async initialize({
331
+ mnemonicOrSeed,
332
+ accountNumber,
333
+ signer,
334
+ options
335
+ }) {
336
+ const wallet = new _IssuerSparkWallet(options, signer);
337
+ wallet.initializeTracer(wallet);
338
+ const initResponse = await wallet.initWallet(mnemonicOrSeed, accountNumber);
339
+ return {
340
+ wallet,
341
+ ...initResponse
342
+ };
343
+ }
344
+ constructor(configOptions, signer) {
345
+ super(configOptions, signer);
346
+ this.issuerTokenTransactionService = new IssuerTokenTransactionService(
347
+ this.config,
348
+ this.connectionManager
349
+ );
350
+ this.tokenFreezeService = new TokenFreezeService(
351
+ this.config,
352
+ this.connectionManager
353
+ );
354
+ this.wrapIssuerSparkWalletMethodsWithTracing();
355
+ }
356
+ /**
357
+ * Gets the token balance for the issuer's token.
358
+ * @returns An object containing the token balance as a bigint
359
+ */
360
+ async getIssuerTokenBalance() {
361
+ const publicKey = await super.getIdentityPublicKey();
362
+ const balanceObj = await this.getBalance();
363
+ const issuerBalance = [...balanceObj.tokenBalances.entries()].find(
364
+ ([, info]) => info.tokenMetadata.tokenPublicKey === publicKey
365
+ );
366
+ if (!balanceObj.tokenBalances || issuerBalance === void 0) {
367
+ return {
368
+ tokenIdentifier: void 0,
369
+ balance: 0n
370
+ };
371
+ }
372
+ return {
373
+ tokenIdentifier: issuerBalance[0] ?? void 0,
374
+ balance: issuerBalance[1].balance
375
+ };
376
+ }
377
+ /**
378
+ * Retrieves information about the issuer's token.
379
+ * @returns An object containing token information including public key, name, symbol, decimals, max supply, and freeze status
380
+ * @throws {NetworkError} If the token metadata cannot be retrieved
381
+ */
382
+ async getIssuerTokenMetadata() {
383
+ const issuerPublicKey = await super.getIdentityPublicKey();
384
+ const tokenMetadata = this.tokenMetadata;
385
+ const cachedIssuerTokenMetadata = [...tokenMetadata.entries()].find(
386
+ ([, metadata]) => (0, import_utils4.bytesToHex)(metadata.issuerPublicKey) === issuerPublicKey
387
+ );
388
+ if (cachedIssuerTokenMetadata !== void 0) {
389
+ const metadata = cachedIssuerTokenMetadata[1];
390
+ return {
391
+ tokenPublicKey: (0, import_utils4.bytesToHex)(metadata.issuerPublicKey),
392
+ rawTokenIdentifier: metadata.tokenIdentifier,
393
+ tokenName: metadata.tokenName,
394
+ tokenTicker: metadata.tokenTicker,
395
+ decimals: metadata.decimals,
396
+ maxSupply: (0, import_utils4.bytesToNumberBE)(metadata.maxSupply),
397
+ isFreezable: metadata.isFreezable
398
+ };
399
+ }
400
+ const sparkTokenClient = await this.connectionManager.createSparkTokenClient(
401
+ this.config.getCoordinatorAddress()
402
+ );
403
+ try {
404
+ const response = await sparkTokenClient.query_token_metadata({
405
+ issuerPublicKeys: Array.of((0, import_utils4.hexToBytes)(issuerPublicKey))
406
+ });
407
+ if (response.tokenMetadata.length === 0) {
408
+ throw new import_spark_sdk5.ValidationError(
409
+ "Token metadata not found - If a token has not yet been created, please create it first. Try again in a few seconds.",
410
+ {
411
+ field: "tokenMetadata",
412
+ value: response.tokenMetadata,
413
+ expected: "non-empty array",
414
+ actualLength: response.tokenMetadata.length,
415
+ expectedLength: 1
416
+ }
417
+ );
418
+ }
419
+ const metadata = response.tokenMetadata[0];
420
+ const tokenIdentifier = (0, import_spark_sdk9.encodeBech32mTokenIdentifier)({
421
+ tokenIdentifier: metadata.tokenIdentifier,
422
+ network: this.config.getNetworkType()
423
+ });
424
+ this.tokenMetadata.set(tokenIdentifier, metadata);
425
+ return {
426
+ tokenPublicKey: (0, import_utils4.bytesToHex)(metadata.issuerPublicKey),
427
+ rawTokenIdentifier: metadata.tokenIdentifier,
428
+ tokenName: metadata.tokenName,
429
+ tokenTicker: metadata.tokenTicker,
430
+ decimals: metadata.decimals,
431
+ maxSupply: (0, import_utils4.bytesToNumberBE)(metadata.maxSupply),
432
+ isFreezable: metadata.isFreezable
433
+ };
434
+ } catch (error) {
435
+ throw new import_spark_sdk5.NetworkError("Failed to fetch token metadata", {
436
+ errorCount: 1,
437
+ errors: error instanceof Error ? error.message : String(error)
438
+ });
439
+ }
440
+ }
441
+ /**
442
+ * Retrieves the bech32m encoded token identifier for the issuer's token.
443
+ * @returns The bech32m encoded token identifier for the issuer's token
444
+ * @throws {NetworkError} If the token identifier cannot be retrieved
445
+ */
446
+ async getIssuerTokenIdentifier() {
447
+ const tokenMetadata = await this.getIssuerTokenMetadata();
448
+ return (0, import_spark_sdk9.encodeBech32mTokenIdentifier)({
449
+ tokenIdentifier: tokenMetadata.rawTokenIdentifier,
450
+ network: this.config.getNetworkType()
451
+ });
452
+ }
453
+ /**
454
+ * Create a new token on Spark.
455
+ *
456
+ * @param params - Object containing token creation parameters.
457
+ * @param params.tokenName - The name of the token.
458
+ * @param params.tokenTicker - The ticker symbol for the token.
459
+ * @param params.decimals - The number of decimal places for the token.
460
+ * @param params.isFreezable - Whether the token can be frozen.
461
+ * @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
462
+ *
463
+ * @returns The transaction ID of the announcement.
464
+ *
465
+ * @throws {ValidationError} If `decimals` is not a safe integer or other validation fails.
466
+ * @throws {NetworkError} If the announcement transaction cannot be broadcast.
467
+ */
468
+ async createToken({
469
+ tokenName,
470
+ tokenTicker,
471
+ decimals,
472
+ isFreezable,
473
+ maxSupply = 0n
474
+ }) {
475
+ validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply);
476
+ const issuerPublicKey = await super.getIdentityPublicKey();
477
+ const tokenTransaction = await this.issuerTokenTransactionService.constructCreateTokenTransaction(
478
+ (0, import_utils4.hexToBytes)(issuerPublicKey),
479
+ tokenName,
480
+ tokenTicker,
481
+ decimals,
482
+ maxSupply,
483
+ isFreezable
484
+ );
485
+ return await this.issuerTokenTransactionService.broadcastTokenTransaction(
486
+ tokenTransaction
487
+ );
488
+ }
489
+ /**
490
+ * Mints new tokens
491
+ * @param tokenAmount - The amount of tokens to mint
492
+ * @returns The transaction ID of the mint operation
493
+ */
494
+ async mintTokens(tokenAmount) {
495
+ let tokenTransaction;
496
+ const issuerTokenPublicKey = await super.getIdentityPublicKey();
497
+ const issuerTokenPublicKeyBytes = (0, import_utils4.hexToBytes)(issuerTokenPublicKey);
498
+ const tokenMetadata = await this.getIssuerTokenMetadata();
499
+ const rawTokenIdentifier = tokenMetadata.rawTokenIdentifier;
500
+ if (this.config.getTokenTransactionVersion() === "V0") {
501
+ tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransactionV0(
502
+ issuerTokenPublicKeyBytes,
503
+ tokenAmount
504
+ );
505
+ } else {
506
+ tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
507
+ rawTokenIdentifier,
508
+ issuerTokenPublicKeyBytes,
509
+ tokenAmount
510
+ );
511
+ }
512
+ return await this.issuerTokenTransactionService.broadcastTokenTransaction(
513
+ tokenTransaction
514
+ );
515
+ }
516
+ /**
517
+ * Burns issuer's tokens
518
+ * @param tokenAmount - The amount of tokens to burn
519
+ * @param selectedOutputs - Optional array of outputs to use for the burn operation
520
+ * @returns The transaction ID of the burn operation
521
+ */
522
+ async burnTokens(tokenAmount, selectedOutputs) {
523
+ const burnAddress = (0, import_spark_sdk6.encodeSparkAddress)({
524
+ identityPublicKey: BURN_ADDRESS,
525
+ network: this.config.getNetworkType()
526
+ });
527
+ const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
528
+ return await this.transferTokens({
529
+ tokenIdentifier: issuerTokenIdentifier,
530
+ tokenAmount,
531
+ receiverSparkAddress: burnAddress,
532
+ selectedOutputs
533
+ });
534
+ }
535
+ /**
536
+ * Freezes tokens associated with a specific Spark address.
537
+ * @param sparkAddress - The Spark address whose tokens should be frozen
538
+ * @returns An object containing the IDs of impacted outputs and the total amount of frozen tokens
539
+ */
540
+ async freezeTokens(sparkAddress) {
541
+ await this.syncTokenOutputs();
542
+ const decodedOwnerPubkey = (0, import_spark_sdk6.decodeSparkAddress)(
543
+ sparkAddress,
544
+ this.config.getNetworkType()
545
+ );
546
+ const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
547
+ const rawTokenIdentifier = (0, import_spark_sdk7.decodeBech32mTokenIdentifier)(
548
+ issuerTokenIdentifier,
549
+ this.config.getNetworkType()
550
+ ).tokenIdentifier;
551
+ const response = await this.tokenFreezeService.freezeTokens({
552
+ ownerPublicKey: (0, import_utils4.hexToBytes)(decodedOwnerPubkey.identityPublicKey),
553
+ tokenIdentifier: rawTokenIdentifier
554
+ });
555
+ const tokenAmount = (0, import_utils4.bytesToNumberBE)(response.impactedTokenAmount);
556
+ return {
557
+ impactedOutputIds: response.impactedOutputIds,
558
+ impactedTokenAmount: tokenAmount
559
+ };
560
+ }
561
+ /**
562
+ * Unfreezes previously frozen tokens associated with a specific Spark address.
563
+ * @param sparkAddress - The Spark address whose tokens should be unfrozen
564
+ * @returns An object containing the IDs of impacted outputs and the total amount of unfrozen tokens
565
+ */
566
+ async unfreezeTokens(sparkAddress) {
567
+ await this.syncTokenOutputs();
568
+ const decodedOwnerPubkey = (0, import_spark_sdk6.decodeSparkAddress)(
569
+ sparkAddress,
570
+ this.config.getNetworkType()
571
+ );
572
+ const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
573
+ const rawTokenIdentifier = (0, import_spark_sdk7.decodeBech32mTokenIdentifier)(
574
+ issuerTokenIdentifier,
575
+ this.config.getNetworkType()
576
+ ).tokenIdentifier;
577
+ const response = await this.tokenFreezeService.unfreezeTokens({
578
+ ownerPublicKey: (0, import_utils4.hexToBytes)(decodedOwnerPubkey.identityPublicKey),
579
+ tokenIdentifier: rawTokenIdentifier
580
+ });
581
+ const tokenAmount = (0, import_utils4.bytesToNumberBE)(response.impactedTokenAmount);
582
+ return {
583
+ impactedOutputIds: response.impactedOutputIds,
584
+ impactedTokenAmount: tokenAmount
585
+ };
586
+ }
587
+ /**
588
+ * Retrieves the distribution information for the issuer's token.
589
+ * @throws {NotImplementedError} This feature is not yet supported
590
+ */
591
+ async getIssuerTokenDistribution() {
592
+ throw new import_spark_sdk8.NotImplementedError("Token distribution is not yet supported");
593
+ }
594
+ getTraceName(methodName) {
595
+ return `IssuerSparkWallet.${methodName}`;
596
+ }
597
+ wrapPublicIssuerSparkWalletMethodWithOtelSpan(methodName) {
598
+ const original = this[methodName];
599
+ if (typeof original !== "function") {
600
+ throw new Error(
601
+ `Method ${methodName} is not a function on IssuerSparkWallet.`
602
+ );
603
+ }
604
+ const wrapped = this.wrapWithOtelSpan(
605
+ this.getTraceName(methodName),
606
+ original.bind(this)
607
+ );
608
+ this[methodName] = wrapped;
609
+ }
610
+ wrapIssuerSparkWalletMethodsWithTracing() {
611
+ const methods = [
612
+ "getIssuerTokenBalance",
613
+ "getIssuerTokenMetadata",
614
+ "getIssuerTokenIdentifier",
615
+ "createToken",
616
+ "mintTokens",
617
+ "burnTokens",
618
+ "freezeTokens",
619
+ "unfreezeTokens",
620
+ "getIssuerTokenDistribution"
621
+ ];
622
+ methods.forEach(
623
+ (m) => this.wrapPublicIssuerSparkWalletMethodWithOtelSpan(m)
624
+ );
625
+ }
626
+ };
627
+
628
+ // src/issuer-wallet/issuer-spark-wallet.node.ts
629
+ var import_spark_sdk10 = require("@buildonspark/spark-sdk");
630
+ var IssuerSparkWalletNodeJS = class _IssuerSparkWalletNodeJS extends IssuerSparkWallet {
631
+ static async initialize({
632
+ mnemonicOrSeed,
633
+ accountNumber,
634
+ signer,
635
+ options
636
+ }) {
637
+ const wallet = new _IssuerSparkWalletNodeJS(options, signer);
638
+ wallet.initializeTracer(wallet);
639
+ const initResponse = await wallet.initWallet(mnemonicOrSeed, accountNumber);
640
+ return {
641
+ wallet,
642
+ ...initResponse
643
+ };
644
+ }
645
+ initializeTracerEnv({
646
+ spanProcessors,
647
+ traceUrls
648
+ }) {
649
+ (0, import_spark_sdk10.initializeTracerEnv)({ spanProcessors, traceUrls });
650
+ }
651
+ };
652
+ // Annotate the CommonJS export names for ESM import in node:
653
+ 0 && (module.exports = {
654
+ IssuerSparkWallet
655
+ });
@@ -0,0 +1,14 @@
1
+ import { I as IssuerSparkWallet } from './issuer-spark-wallet-Bho-WrkK.cjs';
2
+ export { a as IssuerTokenMetadata, T as TokenDistribution } from './issuer-spark-wallet-Bho-WrkK.cjs';
3
+ import { SparkWalletProps } from '@buildonspark/spark-sdk';
4
+ import '@buildonspark/spark-sdk/proto/spark';
5
+
6
+ declare class IssuerSparkWalletNodeJS extends IssuerSparkWallet {
7
+ static initialize({ mnemonicOrSeed, accountNumber, signer, options, }: SparkWalletProps): Promise<{
8
+ mnemonic?: string | undefined;
9
+ wallet: IssuerSparkWalletNodeJS;
10
+ }>;
11
+ protected initializeTracerEnv({ spanProcessors, traceUrls, }: Parameters<IssuerSparkWallet["initializeTracerEnv"]>[0]): void;
12
+ }
13
+
14
+ export { IssuerSparkWalletNodeJS as IssuerSparkWallet };
@@ -0,0 +1,14 @@
1
+ import { I as IssuerSparkWallet } from './issuer-spark-wallet-Bho-WrkK.js';
2
+ export { a as IssuerTokenMetadata, T as TokenDistribution } from './issuer-spark-wallet-Bho-WrkK.js';
3
+ import { SparkWalletProps } from '@buildonspark/spark-sdk';
4
+ import '@buildonspark/spark-sdk/proto/spark';
5
+
6
+ declare class IssuerSparkWalletNodeJS extends IssuerSparkWallet {
7
+ static initialize({ mnemonicOrSeed, accountNumber, signer, options, }: SparkWalletProps): Promise<{
8
+ mnemonic?: string | undefined;
9
+ wallet: IssuerSparkWalletNodeJS;
10
+ }>;
11
+ protected initializeTracerEnv({ spanProcessors, traceUrls, }: Parameters<IssuerSparkWallet["initializeTracerEnv"]>[0]): void;
12
+ }
13
+
14
+ export { IssuerSparkWalletNodeJS as IssuerSparkWallet };