@buildonspark/issuer-sdk 0.1.2 → 0.1.4
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 +109 -0
- package/dist/index.browser.d.ts +133 -9
- package/dist/index.browser.js +341 -83
- package/dist/index.node.cjs +348 -90
- package/dist/index.node.d.cts +133 -9
- package/dist/index.node.d.ts +133 -9
- package/dist/index.node.js +341 -83
- package/dist/native/index.react-native.cjs +345 -87
- package/dist/native/index.react-native.d.cts +133 -9
- package/dist/native/index.react-native.d.ts +133 -9
- package/dist/native/index.react-native.js +341 -83
- package/dist/proto/spark.d.cts +1 -1
- package/dist/proto/spark.d.ts +1 -1
- package/package.json +2 -2
- package/src/issuer-wallet/issuer-spark-wallet.ts +528 -58
- package/src/issuer-wallet/types.ts +25 -0
- package/src/tests/integration/multi-token-issuer.test.ts +437 -0
- package/src/tests/integration/nft-creation.test.ts +32 -17
package/dist/index.node.cjs
CHANGED
|
@@ -20,10 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.node.ts
|
|
21
21
|
var index_node_exports = {};
|
|
22
22
|
__export(index_node_exports, {
|
|
23
|
-
DefaultSparkSigner: () =>
|
|
23
|
+
DefaultSparkSigner: () => import_spark_sdk8.DefaultSparkSigner,
|
|
24
24
|
IssuerSparkWallet: () => IssuerSparkWalletNodeJS,
|
|
25
|
-
UnsafeStatelessSparkSigner: () =>
|
|
26
|
-
WalletConfig: () =>
|
|
25
|
+
UnsafeStatelessSparkSigner: () => import_spark_sdk8.UnsafeStatelessSparkSigner,
|
|
26
|
+
WalletConfig: () => import_spark_sdk9.WalletConfig
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(index_node_exports);
|
|
29
29
|
|
|
@@ -275,6 +275,9 @@ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransac
|
|
|
275
275
|
}
|
|
276
276
|
};
|
|
277
277
|
|
|
278
|
+
// src/issuer-wallet/issuer-spark-wallet.ts
|
|
279
|
+
var import_spark_sdk6 = require("@buildonspark/spark-sdk");
|
|
280
|
+
|
|
278
281
|
// src/utils/create-validation.ts
|
|
279
282
|
var import_spark_sdk4 = require("@buildonspark/spark-sdk");
|
|
280
283
|
function isNfcNormalized(value) {
|
|
@@ -382,49 +385,70 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
|
|
|
382
385
|
}
|
|
383
386
|
/**
|
|
384
387
|
* Gets the token balance for the issuer's token.
|
|
388
|
+
* @deprecated Use getIssuerTokenBalances() instead. This method will be removed in a future version.
|
|
385
389
|
* @returns An object containing the token balance as a bigint
|
|
390
|
+
*
|
|
391
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
386
392
|
*/
|
|
387
393
|
async getIssuerTokenBalance() {
|
|
388
394
|
const publicKey = await super.getIdentityPublicKey();
|
|
389
395
|
const balanceObj = await this.getBalance();
|
|
390
|
-
const issuerBalance = [...balanceObj.tokenBalances.entries()].
|
|
396
|
+
const issuerBalance = [...balanceObj.tokenBalances.entries()].filter(
|
|
391
397
|
([, info]) => info.tokenMetadata.tokenPublicKey === publicKey
|
|
392
398
|
);
|
|
393
|
-
if (
|
|
399
|
+
if (issuerBalance.length > 1) {
|
|
400
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
401
|
+
"Multiple tokens found for this issuer. Use getIssuerTokenBalances() instead.",
|
|
402
|
+
{
|
|
403
|
+
field: "issuerTokenBalance",
|
|
404
|
+
expected: "single token",
|
|
405
|
+
actual: `${issuerBalance.length} tokens`
|
|
406
|
+
}
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
if (issuerBalance.length === 0) {
|
|
394
410
|
return {
|
|
395
411
|
tokenIdentifier: void 0,
|
|
396
412
|
balance: 0n
|
|
397
413
|
};
|
|
398
414
|
}
|
|
399
415
|
return {
|
|
400
|
-
tokenIdentifier: issuerBalance[0]
|
|
401
|
-
balance: issuerBalance[1].balance
|
|
416
|
+
tokenIdentifier: issuerBalance[0][0],
|
|
417
|
+
balance: issuerBalance[0][1].balance
|
|
402
418
|
};
|
|
403
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* Gets the token balances for the tokens that were issued by this user.
|
|
422
|
+
* @returns An array of objects containing the token identifier and balance
|
|
423
|
+
*/
|
|
424
|
+
async getIssuerTokenBalances() {
|
|
425
|
+
const publicKey = await super.getIdentityPublicKey();
|
|
426
|
+
const balanceObj = await this.getBalance();
|
|
427
|
+
const issuerBalance = [...balanceObj.tokenBalances.entries()].filter(
|
|
428
|
+
([, info]) => info.tokenMetadata.tokenPublicKey === publicKey
|
|
429
|
+
);
|
|
430
|
+
if (issuerBalance.length === 0) {
|
|
431
|
+
return [
|
|
432
|
+
{
|
|
433
|
+
tokenIdentifier: void 0,
|
|
434
|
+
balance: 0n
|
|
435
|
+
}
|
|
436
|
+
];
|
|
437
|
+
}
|
|
438
|
+
return issuerBalance.map(([tokenIdentifier, { balance }]) => ({
|
|
439
|
+
tokenIdentifier,
|
|
440
|
+
balance
|
|
441
|
+
}));
|
|
442
|
+
}
|
|
404
443
|
/**
|
|
405
444
|
* Retrieves information about the issuer's token.
|
|
406
|
-
* @
|
|
445
|
+
* @deprecated Use getIssuerTokensMetadata() instead. This method will be removed in a future version.
|
|
446
|
+
* @returns An object containing token information including public key, name, symbol, decimals, max supply, freeze status, and extra metadata
|
|
407
447
|
* @throws {SparkRequestError} If the token metadata cannot be retrieved
|
|
448
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
408
449
|
*/
|
|
409
450
|
async getIssuerTokenMetadata() {
|
|
410
451
|
const issuerPublicKey = await super.getIdentityPublicKey();
|
|
411
|
-
const tokenMetadata = this.tokenMetadata;
|
|
412
|
-
const cachedIssuerTokenMetadata = [...tokenMetadata.entries()].find(
|
|
413
|
-
([, metadata]) => (0, import_utils4.bytesToHex)(metadata.issuerPublicKey) === issuerPublicKey
|
|
414
|
-
);
|
|
415
|
-
if (cachedIssuerTokenMetadata !== void 0) {
|
|
416
|
-
const metadata = cachedIssuerTokenMetadata[1];
|
|
417
|
-
return {
|
|
418
|
-
tokenPublicKey: (0, import_utils4.bytesToHex)(metadata.issuerPublicKey),
|
|
419
|
-
rawTokenIdentifier: metadata.tokenIdentifier,
|
|
420
|
-
tokenName: metadata.tokenName,
|
|
421
|
-
tokenTicker: metadata.tokenTicker,
|
|
422
|
-
decimals: metadata.decimals,
|
|
423
|
-
maxSupply: (0, import_utils4.bytesToNumberBE)(metadata.maxSupply),
|
|
424
|
-
isFreezable: metadata.isFreezable,
|
|
425
|
-
extraMetadata: metadata.extraMetadata ? new Uint8Array(metadata.extraMetadata) : void 0
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
452
|
const sparkTokenClient = await this.connectionManager.createSparkTokenClient(
|
|
429
453
|
this.config.getCoordinatorAddress()
|
|
430
454
|
);
|
|
@@ -444,12 +468,21 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
|
|
|
444
468
|
}
|
|
445
469
|
);
|
|
446
470
|
}
|
|
471
|
+
if (response.tokenMetadata.length > 1) {
|
|
472
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
473
|
+
"Multiple tokens found for this issuer. Please migrate to getIssuerTokensMetadata() instead.",
|
|
474
|
+
{
|
|
475
|
+
field: "tokenMetadata",
|
|
476
|
+
value: response.tokenMetadata
|
|
477
|
+
}
|
|
478
|
+
);
|
|
479
|
+
}
|
|
447
480
|
const metadata = response.tokenMetadata[0];
|
|
448
|
-
const
|
|
481
|
+
const bech32mTokenIdentifier = (0, import_spark_sdk5.encodeBech32mTokenIdentifier)({
|
|
449
482
|
tokenIdentifier: metadata.tokenIdentifier,
|
|
450
483
|
network: this.config.getNetworkType()
|
|
451
484
|
});
|
|
452
|
-
this.tokenMetadata.set(
|
|
485
|
+
this.tokenMetadata.set(bech32mTokenIdentifier, metadata);
|
|
453
486
|
return {
|
|
454
487
|
tokenPublicKey: (0, import_utils4.bytesToHex)(metadata.issuerPublicKey),
|
|
455
488
|
rawTokenIdentifier: metadata.tokenIdentifier,
|
|
@@ -458,47 +491,110 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
|
|
|
458
491
|
decimals: metadata.decimals,
|
|
459
492
|
maxSupply: (0, import_utils4.bytesToNumberBE)(metadata.maxSupply),
|
|
460
493
|
isFreezable: metadata.isFreezable,
|
|
461
|
-
extraMetadata: metadata.extraMetadata
|
|
494
|
+
extraMetadata: metadata.extraMetadata ? new Uint8Array(metadata.extraMetadata) : void 0,
|
|
495
|
+
bech32mTokenIdentifier
|
|
462
496
|
};
|
|
463
497
|
} catch (error) {
|
|
464
498
|
throw new import_spark_sdk5.SparkRequestError("Failed to fetch token metadata", { error });
|
|
465
499
|
}
|
|
466
500
|
}
|
|
501
|
+
/**
|
|
502
|
+
* Retrieves information about the tokens that were issued by this user.
|
|
503
|
+
* @returns An array of objects containing token information including public key, name, symbol, decimals, max supply, freeze status, and extra metadata
|
|
504
|
+
* @throws {SparkRequestError} If the token metadata cannot be retrieved
|
|
505
|
+
*/
|
|
506
|
+
async getIssuerTokensMetadata() {
|
|
507
|
+
const issuerPublicKey = await super.getIdentityPublicKey();
|
|
508
|
+
const sparkTokenClient = await this.connectionManager.createSparkTokenClient(
|
|
509
|
+
this.config.getCoordinatorAddress()
|
|
510
|
+
);
|
|
511
|
+
try {
|
|
512
|
+
const response = await sparkTokenClient.query_token_metadata({
|
|
513
|
+
issuerPublicKeys: Array.of((0, import_utils4.hexToBytes)(issuerPublicKey))
|
|
514
|
+
});
|
|
515
|
+
if (response.tokenMetadata.length === 0) {
|
|
516
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
517
|
+
"Token metadata not found - If a token has not yet been created, please create it first. Try again in a few seconds.",
|
|
518
|
+
{
|
|
519
|
+
field: "tokenMetadata",
|
|
520
|
+
value: response.tokenMetadata,
|
|
521
|
+
expected: "non-empty array",
|
|
522
|
+
actualLength: response.tokenMetadata.length,
|
|
523
|
+
expectedLength: 1
|
|
524
|
+
}
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
const tokenMetadata = [];
|
|
528
|
+
for (const metadata of response.tokenMetadata) {
|
|
529
|
+
const bech32mTokenIdentifier = (0, import_spark_sdk5.encodeBech32mTokenIdentifier)({
|
|
530
|
+
tokenIdentifier: metadata.tokenIdentifier,
|
|
531
|
+
network: this.config.getNetworkType()
|
|
532
|
+
});
|
|
533
|
+
this.tokenMetadata.set(bech32mTokenIdentifier, metadata);
|
|
534
|
+
tokenMetadata.push({
|
|
535
|
+
tokenPublicKey: (0, import_utils4.bytesToHex)(metadata.issuerPublicKey),
|
|
536
|
+
rawTokenIdentifier: metadata.tokenIdentifier,
|
|
537
|
+
tokenName: metadata.tokenName,
|
|
538
|
+
tokenTicker: metadata.tokenTicker,
|
|
539
|
+
decimals: metadata.decimals,
|
|
540
|
+
maxSupply: (0, import_utils4.bytesToNumberBE)(metadata.maxSupply),
|
|
541
|
+
isFreezable: metadata.isFreezable,
|
|
542
|
+
extraMetadata: metadata.extraMetadata ? new Uint8Array(metadata.extraMetadata) : void 0,
|
|
543
|
+
bech32mTokenIdentifier
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
return tokenMetadata;
|
|
547
|
+
} catch (error) {
|
|
548
|
+
throw new import_spark_sdk5.SparkRequestError("Failed to fetch token metadata", { error });
|
|
549
|
+
}
|
|
550
|
+
}
|
|
467
551
|
/**
|
|
468
552
|
* Retrieves the bech32m encoded token identifier for the issuer's token.
|
|
553
|
+
* @deprecated Use getIssuerTokenIdentifiers() instead. This method will be removed in a future version.
|
|
469
554
|
* @returns The bech32m encoded token identifier for the issuer's token
|
|
470
555
|
* @throws {SparkRequestError} If the token identifier cannot be retrieved
|
|
556
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
471
557
|
*/
|
|
472
558
|
async getIssuerTokenIdentifier() {
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
559
|
+
const tokensMetadata = await this.getIssuerTokensMetadata();
|
|
560
|
+
if (tokensMetadata.length > 1) {
|
|
561
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
562
|
+
"Multiple tokens found. Use getIssuerTokenIdentifiers() instead.",
|
|
563
|
+
{
|
|
564
|
+
method: "getIssuerTokenIdentifier",
|
|
565
|
+
availableTokens: tokensMetadata.map((t) => ({
|
|
566
|
+
tokenName: t.tokenName,
|
|
567
|
+
tokenTicker: t.tokenTicker,
|
|
568
|
+
bech32mTokenIdentifier: (0, import_spark_sdk5.encodeBech32mTokenIdentifier)({
|
|
569
|
+
tokenIdentifier: t.rawTokenIdentifier,
|
|
570
|
+
network: this.config.getNetworkType()
|
|
571
|
+
})
|
|
572
|
+
}))
|
|
573
|
+
}
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
if (tokensMetadata.length === 0) {
|
|
577
|
+
throw new import_spark_sdk5.SparkValidationError("No tokens found. Create a token first.");
|
|
578
|
+
}
|
|
579
|
+
return tokensMetadata[0].bech32mTokenIdentifier;
|
|
478
580
|
}
|
|
479
581
|
/**
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
* @
|
|
483
|
-
* @param params.tokenName - The name of the token.
|
|
484
|
-
* @param params.tokenTicker - The ticker symbol for the token.
|
|
485
|
-
* @param params.decimals - The number of decimal places for the token.
|
|
486
|
-
* @param params.isFreezable - Whether the token can be frozen.
|
|
487
|
-
* @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
|
|
488
|
-
* @param params.extraMetadata - (Optional) This can be used to store additional bytes data to be associated with a token, like image data.
|
|
489
|
-
*
|
|
490
|
-
* @returns The transaction ID of the announcement.
|
|
491
|
-
*
|
|
492
|
-
* @throws {SparkValidationError} If `decimals` is not a safe integer or other validation fails.
|
|
493
|
-
* @throws {SparkRequestError} If the announcement transaction cannot be broadcast.
|
|
582
|
+
* Retrieves the bech32m encoded token identifier for the issuer's token.
|
|
583
|
+
* @returns The bech32m encoded token identifier for the issuer's token
|
|
584
|
+
* @throws {SparkRequestError} If the token identifier cannot be retrieved
|
|
494
585
|
*/
|
|
586
|
+
async getIssuerTokenIdentifiers() {
|
|
587
|
+
const tokensMetadata = await this.getIssuerTokensMetadata();
|
|
588
|
+
return tokensMetadata.map((metadata) => metadata.bech32mTokenIdentifier);
|
|
589
|
+
}
|
|
495
590
|
async createToken({
|
|
496
591
|
tokenName,
|
|
497
592
|
tokenTicker,
|
|
498
593
|
decimals,
|
|
499
594
|
isFreezable,
|
|
500
595
|
maxSupply = 0n,
|
|
501
|
-
extraMetadata
|
|
596
|
+
extraMetadata,
|
|
597
|
+
returnIdentifierForCreate = false
|
|
502
598
|
}) {
|
|
503
599
|
validateTokenParameters(
|
|
504
600
|
tokenName,
|
|
@@ -518,9 +614,30 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
|
|
|
518
614
|
isFreezable,
|
|
519
615
|
extraMetadata
|
|
520
616
|
);
|
|
521
|
-
|
|
617
|
+
const { finalTokenTransactionHash, tokenIdentifier } = await this.issuerTokenTransactionService.broadcastTokenTransactionDetailed(
|
|
522
618
|
tokenTransaction
|
|
523
619
|
);
|
|
620
|
+
const txHash = (0, import_utils4.bytesToHex)(finalTokenTransactionHash);
|
|
621
|
+
if (returnIdentifierForCreate) {
|
|
622
|
+
if (!tokenIdentifier) {
|
|
623
|
+
throw new import_spark_sdk5.SparkRequestError(
|
|
624
|
+
"Server response missing expected field: tokenIdentifier",
|
|
625
|
+
{
|
|
626
|
+
operation: "broadcast_transaction",
|
|
627
|
+
field: "tokenIdentifier"
|
|
628
|
+
}
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
const bech32mTokenIdentifier = (0, import_spark_sdk5.encodeBech32mTokenIdentifier)({
|
|
632
|
+
tokenIdentifier,
|
|
633
|
+
network: this.config.getNetworkType()
|
|
634
|
+
});
|
|
635
|
+
return {
|
|
636
|
+
tokenIdentifier: bech32mTokenIdentifier,
|
|
637
|
+
transactionHash: txHash
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
return txHash;
|
|
524
641
|
} else {
|
|
525
642
|
const partialTokenTransaction = await this.issuerTokenTransactionService.constructPartialCreateTokenTransaction(
|
|
526
643
|
(0, import_utils4.hexToBytes)(issuerPublicKey),
|
|
@@ -531,21 +648,75 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
|
|
|
531
648
|
isFreezable,
|
|
532
649
|
extraMetadata
|
|
533
650
|
);
|
|
534
|
-
|
|
651
|
+
const broadcastResponse = await this.issuerTokenTransactionService.broadcastTokenTransactionV3Detailed(
|
|
535
652
|
partialTokenTransaction
|
|
536
653
|
);
|
|
654
|
+
const finalHash = await (0, import_spark_sdk6.hashFinalTokenTransaction)(
|
|
655
|
+
broadcastResponse.finalTokenTransaction
|
|
656
|
+
);
|
|
657
|
+
const finalTransactionHash = (0, import_utils4.bytesToHex)(finalHash);
|
|
658
|
+
if (returnIdentifierForCreate) {
|
|
659
|
+
if (!broadcastResponse.tokenIdentifier) {
|
|
660
|
+
throw new import_spark_sdk5.SparkRequestError(
|
|
661
|
+
"Server response missing expected field: tokenIdentifier",
|
|
662
|
+
{
|
|
663
|
+
operation: "broadcast_transaction",
|
|
664
|
+
field: "tokenIdentifier"
|
|
665
|
+
}
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
const tokenIdentifier = (0, import_spark_sdk5.encodeBech32mTokenIdentifier)({
|
|
669
|
+
tokenIdentifier: broadcastResponse.tokenIdentifier,
|
|
670
|
+
network: this.config.getNetworkType()
|
|
671
|
+
});
|
|
672
|
+
return {
|
|
673
|
+
tokenIdentifier,
|
|
674
|
+
transactionHash: finalTransactionHash
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
return finalTransactionHash;
|
|
537
678
|
}
|
|
538
679
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
680
|
+
async mintTokens(tokenAmountOrParams) {
|
|
681
|
+
let tokenAmount;
|
|
682
|
+
let bech32mTokenIdentifier;
|
|
683
|
+
if (typeof tokenAmountOrParams === "bigint") {
|
|
684
|
+
tokenAmount = tokenAmountOrParams;
|
|
685
|
+
bech32mTokenIdentifier = void 0;
|
|
686
|
+
} else {
|
|
687
|
+
tokenAmount = tokenAmountOrParams.tokenAmount;
|
|
688
|
+
bech32mTokenIdentifier = tokenAmountOrParams.tokenIdentifier;
|
|
689
|
+
}
|
|
545
690
|
const issuerTokenPublicKey = await super.getIdentityPublicKey();
|
|
546
691
|
const issuerTokenPublicKeyBytes = (0, import_utils4.hexToBytes)(issuerTokenPublicKey);
|
|
547
|
-
const
|
|
548
|
-
|
|
692
|
+
const tokensMetadata = await this.getIssuerTokensMetadata();
|
|
693
|
+
if (bech32mTokenIdentifier === void 0) {
|
|
694
|
+
if (tokensMetadata.length > 1) {
|
|
695
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
696
|
+
"Multiple tokens found. Please use mintTokens({ tokenAmount, tokenIdentifier }) instead.",
|
|
697
|
+
{
|
|
698
|
+
field: "tokenIdentifier",
|
|
699
|
+
availableTokens: tokensMetadata.map((t) => ({
|
|
700
|
+
tokenName: t.tokenName,
|
|
701
|
+
tokenTicker: t.tokenTicker,
|
|
702
|
+
bech32mTokenIdentifier: (0, import_spark_sdk5.encodeBech32mTokenIdentifier)({
|
|
703
|
+
tokenIdentifier: t.rawTokenIdentifier,
|
|
704
|
+
network: this.config.getNetworkType()
|
|
705
|
+
})
|
|
706
|
+
}))
|
|
707
|
+
}
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
const encodedTokenIdentifier = (0, import_spark_sdk5.encodeBech32mTokenIdentifier)({
|
|
711
|
+
tokenIdentifier: tokensMetadata[0].rawTokenIdentifier,
|
|
712
|
+
network: this.config.getNetworkType()
|
|
713
|
+
});
|
|
714
|
+
bech32mTokenIdentifier = encodedTokenIdentifier;
|
|
715
|
+
}
|
|
716
|
+
const rawTokenIdentifier = (0, import_spark_sdk5.decodeBech32mTokenIdentifier)(
|
|
717
|
+
bech32mTokenIdentifier,
|
|
718
|
+
this.config.getNetworkType()
|
|
719
|
+
).tokenIdentifier;
|
|
549
720
|
if (this.config.getTokenTransactionVersion() === "V2") {
|
|
550
721
|
const tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
|
|
551
722
|
rawTokenIdentifier,
|
|
@@ -566,39 +737,108 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
|
|
|
566
737
|
);
|
|
567
738
|
}
|
|
568
739
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
740
|
+
async burnTokens(tokenAmountOrParams, selectedOutputs) {
|
|
741
|
+
let bech32mTokenIdentifier;
|
|
742
|
+
let tokenAmount;
|
|
743
|
+
let outputs;
|
|
744
|
+
if (typeof tokenAmountOrParams === "bigint") {
|
|
745
|
+
tokenAmount = tokenAmountOrParams;
|
|
746
|
+
outputs = selectedOutputs;
|
|
747
|
+
const tokenIdentifiers = await this.getIssuerTokenIdentifiers();
|
|
748
|
+
if (tokenIdentifiers.length > 1) {
|
|
749
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
750
|
+
"Multiple tokens found. Use burnTokens({ tokenIdentifier, tokenAmount, selectedOutputs }) to specify which token to burn.",
|
|
751
|
+
{
|
|
752
|
+
field: "tokenIdentifier",
|
|
753
|
+
availableTokens: tokenIdentifiers
|
|
754
|
+
}
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
if (tokenIdentifiers.length === 0) {
|
|
758
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
759
|
+
"No tokens found. Create a token first."
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
bech32mTokenIdentifier = tokenIdentifiers[0];
|
|
763
|
+
} else {
|
|
764
|
+
tokenAmount = tokenAmountOrParams.tokenAmount;
|
|
765
|
+
outputs = tokenAmountOrParams.selectedOutputs;
|
|
766
|
+
if (tokenAmountOrParams.tokenIdentifier) {
|
|
767
|
+
const tokenIdentifiers = await this.getIssuerTokenIdentifiers();
|
|
768
|
+
const tokenIdentifier = tokenIdentifiers.find(
|
|
769
|
+
(identifier) => identifier === tokenAmountOrParams.tokenIdentifier
|
|
770
|
+
);
|
|
771
|
+
if (!tokenIdentifier) {
|
|
772
|
+
throw new import_spark_sdk5.SparkValidationError("Token not found for this issuer", {
|
|
773
|
+
field: "tokenIdentifier",
|
|
774
|
+
value: tokenAmountOrParams.tokenIdentifier
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
bech32mTokenIdentifier = tokenAmountOrParams.tokenIdentifier;
|
|
778
|
+
} else {
|
|
779
|
+
const tokenIdentifiers = await this.getIssuerTokenIdentifiers();
|
|
780
|
+
if (tokenIdentifiers.length === 0) {
|
|
781
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
782
|
+
"No tokens found. Create a token first."
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
if (tokenIdentifiers.length > 1) {
|
|
786
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
787
|
+
"Multiple tokens found. Please specify tokenIdentifier in parameters.",
|
|
788
|
+
{
|
|
789
|
+
field: "tokenIdentifier",
|
|
790
|
+
availableTokens: tokenIdentifiers
|
|
791
|
+
}
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
bech32mTokenIdentifier = tokenIdentifiers[0];
|
|
795
|
+
}
|
|
796
|
+
}
|
|
576
797
|
const burnAddress = (0, import_spark_sdk5.encodeSparkAddress)({
|
|
577
798
|
identityPublicKey: BURN_ADDRESS,
|
|
578
799
|
network: this.config.getNetworkType()
|
|
579
800
|
});
|
|
580
|
-
const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
|
|
581
801
|
return await this.transferTokens({
|
|
582
|
-
tokenIdentifier:
|
|
802
|
+
tokenIdentifier: bech32mTokenIdentifier,
|
|
583
803
|
tokenAmount,
|
|
584
804
|
receiverSparkAddress: burnAddress,
|
|
585
|
-
selectedOutputs
|
|
805
|
+
selectedOutputs: outputs
|
|
586
806
|
});
|
|
587
807
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
808
|
+
async freezeTokens(sparkAddressOrParams) {
|
|
809
|
+
let bech32mTokenIdentifier;
|
|
810
|
+
let sparkAddress;
|
|
811
|
+
if (typeof sparkAddressOrParams === "string") {
|
|
812
|
+
sparkAddress = sparkAddressOrParams;
|
|
813
|
+
bech32mTokenIdentifier = void 0;
|
|
814
|
+
} else {
|
|
815
|
+
sparkAddress = sparkAddressOrParams.sparkAddress;
|
|
816
|
+
bech32mTokenIdentifier = sparkAddressOrParams.tokenIdentifier;
|
|
817
|
+
}
|
|
595
818
|
const decodedOwnerPubkey = (0, import_spark_sdk5.decodeSparkAddress)(
|
|
596
819
|
sparkAddress,
|
|
597
820
|
this.config.getNetworkType()
|
|
598
821
|
);
|
|
599
|
-
|
|
822
|
+
if (bech32mTokenIdentifier === void 0) {
|
|
823
|
+
const tokenIdentifiers = await this.getIssuerTokenIdentifiers();
|
|
824
|
+
if (tokenIdentifiers.length === 0) {
|
|
825
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
826
|
+
"No tokens found. Create a token first."
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
if (tokenIdentifiers.length > 1) {
|
|
830
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
831
|
+
"Multiple tokens found. Use freezeTokens({ tokenIdentifier, sparkAddress }) instead.",
|
|
832
|
+
{
|
|
833
|
+
field: "tokenIdentifier",
|
|
834
|
+
availableTokens: tokenIdentifiers
|
|
835
|
+
}
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
bech32mTokenIdentifier = tokenIdentifiers[0];
|
|
839
|
+
}
|
|
600
840
|
const rawTokenIdentifier = (0, import_spark_sdk5.decodeBech32mTokenIdentifier)(
|
|
601
|
-
|
|
841
|
+
bech32mTokenIdentifier,
|
|
602
842
|
this.config.getNetworkType()
|
|
603
843
|
).tokenIdentifier;
|
|
604
844
|
const response = await this.tokenFreezeService.freezeTokens({
|
|
@@ -611,20 +851,35 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
|
|
|
611
851
|
impactedTokenAmount: tokenAmount
|
|
612
852
|
};
|
|
613
853
|
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
854
|
+
async unfreezeTokens(sparkAddressOrParams) {
|
|
855
|
+
let bech32mTokenIdentifier;
|
|
856
|
+
let sparkAddress;
|
|
857
|
+
if (typeof sparkAddressOrParams === "string") {
|
|
858
|
+
sparkAddress = sparkAddressOrParams;
|
|
859
|
+
bech32mTokenIdentifier = void 0;
|
|
860
|
+
} else {
|
|
861
|
+
sparkAddress = sparkAddressOrParams.sparkAddress;
|
|
862
|
+
bech32mTokenIdentifier = sparkAddressOrParams.tokenIdentifier;
|
|
863
|
+
}
|
|
864
|
+
if (bech32mTokenIdentifier === void 0) {
|
|
865
|
+
const tokenIdentifiers = await this.getIssuerTokenIdentifiers();
|
|
866
|
+
if (tokenIdentifiers.length > 1) {
|
|
867
|
+
throw new import_spark_sdk5.SparkValidationError(
|
|
868
|
+
"Multiple tokens found. Use unfreezeTokens({ tokenIdentifier, sparkAddress }) instead.",
|
|
869
|
+
{
|
|
870
|
+
field: "tokenIdentifier",
|
|
871
|
+
availableTokens: tokenIdentifiers
|
|
872
|
+
}
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
bech32mTokenIdentifier = tokenIdentifiers[0];
|
|
876
|
+
}
|
|
621
877
|
const decodedOwnerPubkey = (0, import_spark_sdk5.decodeSparkAddress)(
|
|
622
878
|
sparkAddress,
|
|
623
879
|
this.config.getNetworkType()
|
|
624
880
|
);
|
|
625
|
-
const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
|
|
626
881
|
const rawTokenIdentifier = (0, import_spark_sdk5.decodeBech32mTokenIdentifier)(
|
|
627
|
-
|
|
882
|
+
bech32mTokenIdentifier,
|
|
628
883
|
this.config.getNetworkType()
|
|
629
884
|
).tokenIdentifier;
|
|
630
885
|
const response = await this.tokenFreezeService.unfreezeTokens({
|
|
@@ -670,8 +925,11 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
|
|
|
670
925
|
};
|
|
671
926
|
var PUBLIC_ISSUER_SPARK_WALLET_METHODS = [
|
|
672
927
|
"getIssuerTokenBalance",
|
|
928
|
+
"getIssuerTokenBalances",
|
|
673
929
|
"getIssuerTokenMetadata",
|
|
930
|
+
"getIssuerTokensMetadata",
|
|
674
931
|
"getIssuerTokenIdentifier",
|
|
932
|
+
"getIssuerTokenIdentifiers",
|
|
675
933
|
"createToken",
|
|
676
934
|
"mintTokens",
|
|
677
935
|
"burnTokens",
|
|
@@ -681,22 +939,22 @@ var PUBLIC_ISSUER_SPARK_WALLET_METHODS = [
|
|
|
681
939
|
];
|
|
682
940
|
|
|
683
941
|
// src/issuer-wallet/issuer-spark-wallet.node.ts
|
|
684
|
-
var
|
|
942
|
+
var import_spark_sdk7 = require("@buildonspark/spark-sdk");
|
|
685
943
|
var IssuerSparkWalletNodeJS = class extends IssuerSparkWallet {
|
|
686
944
|
buildConnectionManager(config) {
|
|
687
|
-
return new
|
|
945
|
+
return new import_spark_sdk7.ConnectionManager(config);
|
|
688
946
|
}
|
|
689
947
|
initializeTracerEnv({
|
|
690
948
|
spanProcessors,
|
|
691
949
|
traceUrls
|
|
692
950
|
}) {
|
|
693
|
-
(0,
|
|
951
|
+
(0, import_spark_sdk7.initializeTracerEnv)({ spanProcessors, traceUrls });
|
|
694
952
|
}
|
|
695
953
|
};
|
|
696
954
|
|
|
697
955
|
// src/index-shared.ts
|
|
698
|
-
var import_spark_sdk7 = require("@buildonspark/spark-sdk");
|
|
699
956
|
var import_spark_sdk8 = require("@buildonspark/spark-sdk");
|
|
957
|
+
var import_spark_sdk9 = require("@buildonspark/spark-sdk");
|
|
700
958
|
// Annotate the CommonJS export names for ESM import in node:
|
|
701
959
|
0 && (module.exports = {
|
|
702
960
|
DefaultSparkSigner,
|