@buildonspark/issuer-sdk 0.1.3 → 0.1.5
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/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
|
@@ -265,6 +265,9 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
|
|
|
265
265
|
}
|
|
266
266
|
};
|
|
267
267
|
|
|
268
|
+
// src/issuer-wallet/issuer-spark-wallet.ts
|
|
269
|
+
import { hashFinalTokenTransaction } from "@buildonspark/spark-sdk";
|
|
270
|
+
|
|
268
271
|
// src/utils/create-validation.ts
|
|
269
272
|
import { SparkValidationError as SparkValidationError2 } from "@buildonspark/spark-sdk";
|
|
270
273
|
function isNfcNormalized(value) {
|
|
@@ -372,49 +375,70 @@ var IssuerSparkWallet = class extends SparkWallet {
|
|
|
372
375
|
}
|
|
373
376
|
/**
|
|
374
377
|
* Gets the token balance for the issuer's token.
|
|
378
|
+
* @deprecated Use getIssuerTokenBalances() instead. This method will be removed in a future version.
|
|
375
379
|
* @returns An object containing the token balance as a bigint
|
|
380
|
+
*
|
|
381
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
376
382
|
*/
|
|
377
383
|
async getIssuerTokenBalance() {
|
|
378
384
|
const publicKey = await super.getIdentityPublicKey();
|
|
379
385
|
const balanceObj = await this.getBalance();
|
|
380
|
-
const issuerBalance = [...balanceObj.tokenBalances.entries()].
|
|
386
|
+
const issuerBalance = [...balanceObj.tokenBalances.entries()].filter(
|
|
381
387
|
([, info]) => info.tokenMetadata.tokenPublicKey === publicKey
|
|
382
388
|
);
|
|
383
|
-
if (
|
|
389
|
+
if (issuerBalance.length > 1) {
|
|
390
|
+
throw new SparkValidationError3(
|
|
391
|
+
"Multiple tokens found for this issuer. Use getIssuerTokenBalances() instead.",
|
|
392
|
+
{
|
|
393
|
+
field: "issuerTokenBalance",
|
|
394
|
+
expected: "single token",
|
|
395
|
+
actual: `${issuerBalance.length} tokens`
|
|
396
|
+
}
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
if (issuerBalance.length === 0) {
|
|
384
400
|
return {
|
|
385
401
|
tokenIdentifier: void 0,
|
|
386
402
|
balance: 0n
|
|
387
403
|
};
|
|
388
404
|
}
|
|
389
405
|
return {
|
|
390
|
-
tokenIdentifier: issuerBalance[0]
|
|
391
|
-
balance: issuerBalance[1].balance
|
|
406
|
+
tokenIdentifier: issuerBalance[0][0],
|
|
407
|
+
balance: issuerBalance[0][1].balance
|
|
392
408
|
};
|
|
393
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Gets the token balances for the tokens that were issued by this user.
|
|
412
|
+
* @returns An array of objects containing the token identifier and balance
|
|
413
|
+
*/
|
|
414
|
+
async getIssuerTokenBalances() {
|
|
415
|
+
const publicKey = await super.getIdentityPublicKey();
|
|
416
|
+
const balanceObj = await this.getBalance();
|
|
417
|
+
const issuerBalance = [...balanceObj.tokenBalances.entries()].filter(
|
|
418
|
+
([, info]) => info.tokenMetadata.tokenPublicKey === publicKey
|
|
419
|
+
);
|
|
420
|
+
if (issuerBalance.length === 0) {
|
|
421
|
+
return [
|
|
422
|
+
{
|
|
423
|
+
tokenIdentifier: void 0,
|
|
424
|
+
balance: 0n
|
|
425
|
+
}
|
|
426
|
+
];
|
|
427
|
+
}
|
|
428
|
+
return issuerBalance.map(([tokenIdentifier, { balance }]) => ({
|
|
429
|
+
tokenIdentifier,
|
|
430
|
+
balance
|
|
431
|
+
}));
|
|
432
|
+
}
|
|
394
433
|
/**
|
|
395
434
|
* Retrieves information about the issuer's token.
|
|
396
|
-
* @
|
|
435
|
+
* @deprecated Use getIssuerTokensMetadata() instead. This method will be removed in a future version.
|
|
436
|
+
* @returns An object containing token information including public key, name, symbol, decimals, max supply, freeze status, and extra metadata
|
|
397
437
|
* @throws {SparkRequestError} If the token metadata cannot be retrieved
|
|
438
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
398
439
|
*/
|
|
399
440
|
async getIssuerTokenMetadata() {
|
|
400
441
|
const issuerPublicKey = await super.getIdentityPublicKey();
|
|
401
|
-
const tokenMetadata = this.tokenMetadata;
|
|
402
|
-
const cachedIssuerTokenMetadata = [...tokenMetadata.entries()].find(
|
|
403
|
-
([, metadata]) => bytesToHex(metadata.issuerPublicKey) === issuerPublicKey
|
|
404
|
-
);
|
|
405
|
-
if (cachedIssuerTokenMetadata !== void 0) {
|
|
406
|
-
const metadata = cachedIssuerTokenMetadata[1];
|
|
407
|
-
return {
|
|
408
|
-
tokenPublicKey: bytesToHex(metadata.issuerPublicKey),
|
|
409
|
-
rawTokenIdentifier: metadata.tokenIdentifier,
|
|
410
|
-
tokenName: metadata.tokenName,
|
|
411
|
-
tokenTicker: metadata.tokenTicker,
|
|
412
|
-
decimals: metadata.decimals,
|
|
413
|
-
maxSupply: bytesToNumberBE(metadata.maxSupply),
|
|
414
|
-
isFreezable: metadata.isFreezable,
|
|
415
|
-
extraMetadata: metadata.extraMetadata ? new Uint8Array(metadata.extraMetadata) : void 0
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
442
|
const sparkTokenClient = await this.connectionManager.createSparkTokenClient(
|
|
419
443
|
this.config.getCoordinatorAddress()
|
|
420
444
|
);
|
|
@@ -434,12 +458,21 @@ var IssuerSparkWallet = class extends SparkWallet {
|
|
|
434
458
|
}
|
|
435
459
|
);
|
|
436
460
|
}
|
|
461
|
+
if (response.tokenMetadata.length > 1) {
|
|
462
|
+
throw new SparkValidationError3(
|
|
463
|
+
"Multiple tokens found for this issuer. Please migrate to getIssuerTokensMetadata() instead.",
|
|
464
|
+
{
|
|
465
|
+
field: "tokenMetadata",
|
|
466
|
+
value: response.tokenMetadata
|
|
467
|
+
}
|
|
468
|
+
);
|
|
469
|
+
}
|
|
437
470
|
const metadata = response.tokenMetadata[0];
|
|
438
|
-
const
|
|
471
|
+
const bech32mTokenIdentifier = encodeBech32mTokenIdentifier({
|
|
439
472
|
tokenIdentifier: metadata.tokenIdentifier,
|
|
440
473
|
network: this.config.getNetworkType()
|
|
441
474
|
});
|
|
442
|
-
this.tokenMetadata.set(
|
|
475
|
+
this.tokenMetadata.set(bech32mTokenIdentifier, metadata);
|
|
443
476
|
return {
|
|
444
477
|
tokenPublicKey: bytesToHex(metadata.issuerPublicKey),
|
|
445
478
|
rawTokenIdentifier: metadata.tokenIdentifier,
|
|
@@ -448,47 +481,110 @@ var IssuerSparkWallet = class extends SparkWallet {
|
|
|
448
481
|
decimals: metadata.decimals,
|
|
449
482
|
maxSupply: bytesToNumberBE(metadata.maxSupply),
|
|
450
483
|
isFreezable: metadata.isFreezable,
|
|
451
|
-
extraMetadata: metadata.extraMetadata
|
|
484
|
+
extraMetadata: metadata.extraMetadata ? new Uint8Array(metadata.extraMetadata) : void 0,
|
|
485
|
+
bech32mTokenIdentifier
|
|
452
486
|
};
|
|
453
487
|
} catch (error) {
|
|
454
488
|
throw new SparkRequestError2("Failed to fetch token metadata", { error });
|
|
455
489
|
}
|
|
456
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* Retrieves information about the tokens that were issued by this user.
|
|
493
|
+
* @returns An array of objects containing token information including public key, name, symbol, decimals, max supply, freeze status, and extra metadata
|
|
494
|
+
* @throws {SparkRequestError} If the token metadata cannot be retrieved
|
|
495
|
+
*/
|
|
496
|
+
async getIssuerTokensMetadata() {
|
|
497
|
+
const issuerPublicKey = await super.getIdentityPublicKey();
|
|
498
|
+
const sparkTokenClient = await this.connectionManager.createSparkTokenClient(
|
|
499
|
+
this.config.getCoordinatorAddress()
|
|
500
|
+
);
|
|
501
|
+
try {
|
|
502
|
+
const response = await sparkTokenClient.query_token_metadata({
|
|
503
|
+
issuerPublicKeys: Array.of(hexToBytes2(issuerPublicKey))
|
|
504
|
+
});
|
|
505
|
+
if (response.tokenMetadata.length === 0) {
|
|
506
|
+
throw new SparkValidationError3(
|
|
507
|
+
"Token metadata not found - If a token has not yet been created, please create it first. Try again in a few seconds.",
|
|
508
|
+
{
|
|
509
|
+
field: "tokenMetadata",
|
|
510
|
+
value: response.tokenMetadata,
|
|
511
|
+
expected: "non-empty array",
|
|
512
|
+
actualLength: response.tokenMetadata.length,
|
|
513
|
+
expectedLength: 1
|
|
514
|
+
}
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
const tokenMetadata = [];
|
|
518
|
+
for (const metadata of response.tokenMetadata) {
|
|
519
|
+
const bech32mTokenIdentifier = encodeBech32mTokenIdentifier({
|
|
520
|
+
tokenIdentifier: metadata.tokenIdentifier,
|
|
521
|
+
network: this.config.getNetworkType()
|
|
522
|
+
});
|
|
523
|
+
this.tokenMetadata.set(bech32mTokenIdentifier, metadata);
|
|
524
|
+
tokenMetadata.push({
|
|
525
|
+
tokenPublicKey: bytesToHex(metadata.issuerPublicKey),
|
|
526
|
+
rawTokenIdentifier: metadata.tokenIdentifier,
|
|
527
|
+
tokenName: metadata.tokenName,
|
|
528
|
+
tokenTicker: metadata.tokenTicker,
|
|
529
|
+
decimals: metadata.decimals,
|
|
530
|
+
maxSupply: bytesToNumberBE(metadata.maxSupply),
|
|
531
|
+
isFreezable: metadata.isFreezable,
|
|
532
|
+
extraMetadata: metadata.extraMetadata ? new Uint8Array(metadata.extraMetadata) : void 0,
|
|
533
|
+
bech32mTokenIdentifier
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
return tokenMetadata;
|
|
537
|
+
} catch (error) {
|
|
538
|
+
throw new SparkRequestError2("Failed to fetch token metadata", { error });
|
|
539
|
+
}
|
|
540
|
+
}
|
|
457
541
|
/**
|
|
458
542
|
* Retrieves the bech32m encoded token identifier for the issuer's token.
|
|
543
|
+
* @deprecated Use getIssuerTokenIdentifiers() instead. This method will be removed in a future version.
|
|
459
544
|
* @returns The bech32m encoded token identifier for the issuer's token
|
|
460
545
|
* @throws {SparkRequestError} If the token identifier cannot be retrieved
|
|
546
|
+
* @throws {SparkValidationError} If multiple tokens are found for this issuer
|
|
461
547
|
*/
|
|
462
548
|
async getIssuerTokenIdentifier() {
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
549
|
+
const tokensMetadata = await this.getIssuerTokensMetadata();
|
|
550
|
+
if (tokensMetadata.length > 1) {
|
|
551
|
+
throw new SparkValidationError3(
|
|
552
|
+
"Multiple tokens found. Use getIssuerTokenIdentifiers() instead.",
|
|
553
|
+
{
|
|
554
|
+
method: "getIssuerTokenIdentifier",
|
|
555
|
+
availableTokens: tokensMetadata.map((t) => ({
|
|
556
|
+
tokenName: t.tokenName,
|
|
557
|
+
tokenTicker: t.tokenTicker,
|
|
558
|
+
bech32mTokenIdentifier: encodeBech32mTokenIdentifier({
|
|
559
|
+
tokenIdentifier: t.rawTokenIdentifier,
|
|
560
|
+
network: this.config.getNetworkType()
|
|
561
|
+
})
|
|
562
|
+
}))
|
|
563
|
+
}
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
if (tokensMetadata.length === 0) {
|
|
567
|
+
throw new SparkValidationError3("No tokens found. Create a token first.");
|
|
568
|
+
}
|
|
569
|
+
return tokensMetadata[0].bech32mTokenIdentifier;
|
|
468
570
|
}
|
|
469
571
|
/**
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
* @
|
|
473
|
-
* @param params.tokenName - The name of the token.
|
|
474
|
-
* @param params.tokenTicker - The ticker symbol for the token.
|
|
475
|
-
* @param params.decimals - The number of decimal places for the token.
|
|
476
|
-
* @param params.isFreezable - Whether the token can be frozen.
|
|
477
|
-
* @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
|
|
478
|
-
* @param params.extraMetadata - (Optional) This can be used to store additional bytes data to be associated with a token, like image data.
|
|
479
|
-
*
|
|
480
|
-
* @returns The transaction ID of the announcement.
|
|
481
|
-
*
|
|
482
|
-
* @throws {SparkValidationError} If `decimals` is not a safe integer or other validation fails.
|
|
483
|
-
* @throws {SparkRequestError} If the announcement transaction cannot be broadcast.
|
|
572
|
+
* Retrieves the bech32m encoded token identifier for the issuer's token.
|
|
573
|
+
* @returns The bech32m encoded token identifier for the issuer's token
|
|
574
|
+
* @throws {SparkRequestError} If the token identifier cannot be retrieved
|
|
484
575
|
*/
|
|
576
|
+
async getIssuerTokenIdentifiers() {
|
|
577
|
+
const tokensMetadata = await this.getIssuerTokensMetadata();
|
|
578
|
+
return tokensMetadata.map((metadata) => metadata.bech32mTokenIdentifier);
|
|
579
|
+
}
|
|
485
580
|
async createToken({
|
|
486
581
|
tokenName,
|
|
487
582
|
tokenTicker,
|
|
488
583
|
decimals,
|
|
489
584
|
isFreezable,
|
|
490
585
|
maxSupply = 0n,
|
|
491
|
-
extraMetadata
|
|
586
|
+
extraMetadata,
|
|
587
|
+
returnIdentifierForCreate = false
|
|
492
588
|
}) {
|
|
493
589
|
validateTokenParameters(
|
|
494
590
|
tokenName,
|
|
@@ -508,9 +604,30 @@ var IssuerSparkWallet = class extends SparkWallet {
|
|
|
508
604
|
isFreezable,
|
|
509
605
|
extraMetadata
|
|
510
606
|
);
|
|
511
|
-
|
|
607
|
+
const { finalTokenTransactionHash, tokenIdentifier } = await this.issuerTokenTransactionService.broadcastTokenTransactionDetailed(
|
|
512
608
|
tokenTransaction
|
|
513
609
|
);
|
|
610
|
+
const txHash = bytesToHex(finalTokenTransactionHash);
|
|
611
|
+
if (returnIdentifierForCreate) {
|
|
612
|
+
if (!tokenIdentifier) {
|
|
613
|
+
throw new SparkRequestError2(
|
|
614
|
+
"Server response missing expected field: tokenIdentifier",
|
|
615
|
+
{
|
|
616
|
+
operation: "broadcast_transaction",
|
|
617
|
+
field: "tokenIdentifier"
|
|
618
|
+
}
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
const bech32mTokenIdentifier = encodeBech32mTokenIdentifier({
|
|
622
|
+
tokenIdentifier,
|
|
623
|
+
network: this.config.getNetworkType()
|
|
624
|
+
});
|
|
625
|
+
return {
|
|
626
|
+
tokenIdentifier: bech32mTokenIdentifier,
|
|
627
|
+
transactionHash: txHash
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
return txHash;
|
|
514
631
|
} else {
|
|
515
632
|
const partialTokenTransaction = await this.issuerTokenTransactionService.constructPartialCreateTokenTransaction(
|
|
516
633
|
hexToBytes2(issuerPublicKey),
|
|
@@ -521,21 +638,75 @@ var IssuerSparkWallet = class extends SparkWallet {
|
|
|
521
638
|
isFreezable,
|
|
522
639
|
extraMetadata
|
|
523
640
|
);
|
|
524
|
-
|
|
641
|
+
const broadcastResponse = await this.issuerTokenTransactionService.broadcastTokenTransactionV3Detailed(
|
|
525
642
|
partialTokenTransaction
|
|
526
643
|
);
|
|
644
|
+
const finalHash = await hashFinalTokenTransaction(
|
|
645
|
+
broadcastResponse.finalTokenTransaction
|
|
646
|
+
);
|
|
647
|
+
const finalTransactionHash = bytesToHex(finalHash);
|
|
648
|
+
if (returnIdentifierForCreate) {
|
|
649
|
+
if (!broadcastResponse.tokenIdentifier) {
|
|
650
|
+
throw new SparkRequestError2(
|
|
651
|
+
"Server response missing expected field: tokenIdentifier",
|
|
652
|
+
{
|
|
653
|
+
operation: "broadcast_transaction",
|
|
654
|
+
field: "tokenIdentifier"
|
|
655
|
+
}
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
const tokenIdentifier = encodeBech32mTokenIdentifier({
|
|
659
|
+
tokenIdentifier: broadcastResponse.tokenIdentifier,
|
|
660
|
+
network: this.config.getNetworkType()
|
|
661
|
+
});
|
|
662
|
+
return {
|
|
663
|
+
tokenIdentifier,
|
|
664
|
+
transactionHash: finalTransactionHash
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
return finalTransactionHash;
|
|
527
668
|
}
|
|
528
669
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
670
|
+
async mintTokens(tokenAmountOrParams) {
|
|
671
|
+
let tokenAmount;
|
|
672
|
+
let bech32mTokenIdentifier;
|
|
673
|
+
if (typeof tokenAmountOrParams === "bigint") {
|
|
674
|
+
tokenAmount = tokenAmountOrParams;
|
|
675
|
+
bech32mTokenIdentifier = void 0;
|
|
676
|
+
} else {
|
|
677
|
+
tokenAmount = tokenAmountOrParams.tokenAmount;
|
|
678
|
+
bech32mTokenIdentifier = tokenAmountOrParams.tokenIdentifier;
|
|
679
|
+
}
|
|
535
680
|
const issuerTokenPublicKey = await super.getIdentityPublicKey();
|
|
536
681
|
const issuerTokenPublicKeyBytes = hexToBytes2(issuerTokenPublicKey);
|
|
537
|
-
const
|
|
538
|
-
|
|
682
|
+
const tokensMetadata = await this.getIssuerTokensMetadata();
|
|
683
|
+
if (bech32mTokenIdentifier === void 0) {
|
|
684
|
+
if (tokensMetadata.length > 1) {
|
|
685
|
+
throw new SparkValidationError3(
|
|
686
|
+
"Multiple tokens found. Please use mintTokens({ tokenAmount, tokenIdentifier }) instead.",
|
|
687
|
+
{
|
|
688
|
+
field: "tokenIdentifier",
|
|
689
|
+
availableTokens: tokensMetadata.map((t) => ({
|
|
690
|
+
tokenName: t.tokenName,
|
|
691
|
+
tokenTicker: t.tokenTicker,
|
|
692
|
+
bech32mTokenIdentifier: encodeBech32mTokenIdentifier({
|
|
693
|
+
tokenIdentifier: t.rawTokenIdentifier,
|
|
694
|
+
network: this.config.getNetworkType()
|
|
695
|
+
})
|
|
696
|
+
}))
|
|
697
|
+
}
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
const encodedTokenIdentifier = encodeBech32mTokenIdentifier({
|
|
701
|
+
tokenIdentifier: tokensMetadata[0].rawTokenIdentifier,
|
|
702
|
+
network: this.config.getNetworkType()
|
|
703
|
+
});
|
|
704
|
+
bech32mTokenIdentifier = encodedTokenIdentifier;
|
|
705
|
+
}
|
|
706
|
+
const rawTokenIdentifier = decodeBech32mTokenIdentifier(
|
|
707
|
+
bech32mTokenIdentifier,
|
|
708
|
+
this.config.getNetworkType()
|
|
709
|
+
).tokenIdentifier;
|
|
539
710
|
if (this.config.getTokenTransactionVersion() === "V2") {
|
|
540
711
|
const tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
|
|
541
712
|
rawTokenIdentifier,
|
|
@@ -556,39 +727,108 @@ var IssuerSparkWallet = class extends SparkWallet {
|
|
|
556
727
|
);
|
|
557
728
|
}
|
|
558
729
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
730
|
+
async burnTokens(tokenAmountOrParams, selectedOutputs) {
|
|
731
|
+
let bech32mTokenIdentifier;
|
|
732
|
+
let tokenAmount;
|
|
733
|
+
let outputs;
|
|
734
|
+
if (typeof tokenAmountOrParams === "bigint") {
|
|
735
|
+
tokenAmount = tokenAmountOrParams;
|
|
736
|
+
outputs = selectedOutputs;
|
|
737
|
+
const tokenIdentifiers = await this.getIssuerTokenIdentifiers();
|
|
738
|
+
if (tokenIdentifiers.length > 1) {
|
|
739
|
+
throw new SparkValidationError3(
|
|
740
|
+
"Multiple tokens found. Use burnTokens({ tokenIdentifier, tokenAmount, selectedOutputs }) to specify which token to burn.",
|
|
741
|
+
{
|
|
742
|
+
field: "tokenIdentifier",
|
|
743
|
+
availableTokens: tokenIdentifiers
|
|
744
|
+
}
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
if (tokenIdentifiers.length === 0) {
|
|
748
|
+
throw new SparkValidationError3(
|
|
749
|
+
"No tokens found. Create a token first."
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
bech32mTokenIdentifier = tokenIdentifiers[0];
|
|
753
|
+
} else {
|
|
754
|
+
tokenAmount = tokenAmountOrParams.tokenAmount;
|
|
755
|
+
outputs = tokenAmountOrParams.selectedOutputs;
|
|
756
|
+
if (tokenAmountOrParams.tokenIdentifier) {
|
|
757
|
+
const tokenIdentifiers = await this.getIssuerTokenIdentifiers();
|
|
758
|
+
const tokenIdentifier = tokenIdentifiers.find(
|
|
759
|
+
(identifier) => identifier === tokenAmountOrParams.tokenIdentifier
|
|
760
|
+
);
|
|
761
|
+
if (!tokenIdentifier) {
|
|
762
|
+
throw new SparkValidationError3("Token not found for this issuer", {
|
|
763
|
+
field: "tokenIdentifier",
|
|
764
|
+
value: tokenAmountOrParams.tokenIdentifier
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
bech32mTokenIdentifier = tokenAmountOrParams.tokenIdentifier;
|
|
768
|
+
} else {
|
|
769
|
+
const tokenIdentifiers = await this.getIssuerTokenIdentifiers();
|
|
770
|
+
if (tokenIdentifiers.length === 0) {
|
|
771
|
+
throw new SparkValidationError3(
|
|
772
|
+
"No tokens found. Create a token first."
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
if (tokenIdentifiers.length > 1) {
|
|
776
|
+
throw new SparkValidationError3(
|
|
777
|
+
"Multiple tokens found. Please specify tokenIdentifier in parameters.",
|
|
778
|
+
{
|
|
779
|
+
field: "tokenIdentifier",
|
|
780
|
+
availableTokens: tokenIdentifiers
|
|
781
|
+
}
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
bech32mTokenIdentifier = tokenIdentifiers[0];
|
|
785
|
+
}
|
|
786
|
+
}
|
|
566
787
|
const burnAddress = encodeSparkAddress({
|
|
567
788
|
identityPublicKey: BURN_ADDRESS,
|
|
568
789
|
network: this.config.getNetworkType()
|
|
569
790
|
});
|
|
570
|
-
const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
|
|
571
791
|
return await this.transferTokens({
|
|
572
|
-
tokenIdentifier:
|
|
792
|
+
tokenIdentifier: bech32mTokenIdentifier,
|
|
573
793
|
tokenAmount,
|
|
574
794
|
receiverSparkAddress: burnAddress,
|
|
575
|
-
selectedOutputs
|
|
795
|
+
selectedOutputs: outputs
|
|
576
796
|
});
|
|
577
797
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
798
|
+
async freezeTokens(sparkAddressOrParams) {
|
|
799
|
+
let bech32mTokenIdentifier;
|
|
800
|
+
let sparkAddress;
|
|
801
|
+
if (typeof sparkAddressOrParams === "string") {
|
|
802
|
+
sparkAddress = sparkAddressOrParams;
|
|
803
|
+
bech32mTokenIdentifier = void 0;
|
|
804
|
+
} else {
|
|
805
|
+
sparkAddress = sparkAddressOrParams.sparkAddress;
|
|
806
|
+
bech32mTokenIdentifier = sparkAddressOrParams.tokenIdentifier;
|
|
807
|
+
}
|
|
585
808
|
const decodedOwnerPubkey = decodeSparkAddress(
|
|
586
809
|
sparkAddress,
|
|
587
810
|
this.config.getNetworkType()
|
|
588
811
|
);
|
|
589
|
-
|
|
812
|
+
if (bech32mTokenIdentifier === void 0) {
|
|
813
|
+
const tokenIdentifiers = await this.getIssuerTokenIdentifiers();
|
|
814
|
+
if (tokenIdentifiers.length === 0) {
|
|
815
|
+
throw new SparkValidationError3(
|
|
816
|
+
"No tokens found. Create a token first."
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
if (tokenIdentifiers.length > 1) {
|
|
820
|
+
throw new SparkValidationError3(
|
|
821
|
+
"Multiple tokens found. Use freezeTokens({ tokenIdentifier, sparkAddress }) instead.",
|
|
822
|
+
{
|
|
823
|
+
field: "tokenIdentifier",
|
|
824
|
+
availableTokens: tokenIdentifiers
|
|
825
|
+
}
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
bech32mTokenIdentifier = tokenIdentifiers[0];
|
|
829
|
+
}
|
|
590
830
|
const rawTokenIdentifier = decodeBech32mTokenIdentifier(
|
|
591
|
-
|
|
831
|
+
bech32mTokenIdentifier,
|
|
592
832
|
this.config.getNetworkType()
|
|
593
833
|
).tokenIdentifier;
|
|
594
834
|
const response = await this.tokenFreezeService.freezeTokens({
|
|
@@ -601,20 +841,35 @@ var IssuerSparkWallet = class extends SparkWallet {
|
|
|
601
841
|
impactedTokenAmount: tokenAmount
|
|
602
842
|
};
|
|
603
843
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
844
|
+
async unfreezeTokens(sparkAddressOrParams) {
|
|
845
|
+
let bech32mTokenIdentifier;
|
|
846
|
+
let sparkAddress;
|
|
847
|
+
if (typeof sparkAddressOrParams === "string") {
|
|
848
|
+
sparkAddress = sparkAddressOrParams;
|
|
849
|
+
bech32mTokenIdentifier = void 0;
|
|
850
|
+
} else {
|
|
851
|
+
sparkAddress = sparkAddressOrParams.sparkAddress;
|
|
852
|
+
bech32mTokenIdentifier = sparkAddressOrParams.tokenIdentifier;
|
|
853
|
+
}
|
|
854
|
+
if (bech32mTokenIdentifier === void 0) {
|
|
855
|
+
const tokenIdentifiers = await this.getIssuerTokenIdentifiers();
|
|
856
|
+
if (tokenIdentifiers.length > 1) {
|
|
857
|
+
throw new SparkValidationError3(
|
|
858
|
+
"Multiple tokens found. Use unfreezeTokens({ tokenIdentifier, sparkAddress }) instead.",
|
|
859
|
+
{
|
|
860
|
+
field: "tokenIdentifier",
|
|
861
|
+
availableTokens: tokenIdentifiers
|
|
862
|
+
}
|
|
863
|
+
);
|
|
864
|
+
}
|
|
865
|
+
bech32mTokenIdentifier = tokenIdentifiers[0];
|
|
866
|
+
}
|
|
611
867
|
const decodedOwnerPubkey = decodeSparkAddress(
|
|
612
868
|
sparkAddress,
|
|
613
869
|
this.config.getNetworkType()
|
|
614
870
|
);
|
|
615
|
-
const issuerTokenIdentifier = await this.getIssuerTokenIdentifier();
|
|
616
871
|
const rawTokenIdentifier = decodeBech32mTokenIdentifier(
|
|
617
|
-
|
|
872
|
+
bech32mTokenIdentifier,
|
|
618
873
|
this.config.getNetworkType()
|
|
619
874
|
).tokenIdentifier;
|
|
620
875
|
const response = await this.tokenFreezeService.unfreezeTokens({
|
|
@@ -660,8 +915,11 @@ var IssuerSparkWallet = class extends SparkWallet {
|
|
|
660
915
|
};
|
|
661
916
|
var PUBLIC_ISSUER_SPARK_WALLET_METHODS = [
|
|
662
917
|
"getIssuerTokenBalance",
|
|
918
|
+
"getIssuerTokenBalances",
|
|
663
919
|
"getIssuerTokenMetadata",
|
|
920
|
+
"getIssuerTokensMetadata",
|
|
664
921
|
"getIssuerTokenIdentifier",
|
|
922
|
+
"getIssuerTokenIdentifiers",
|
|
665
923
|
"createToken",
|
|
666
924
|
"mintTokens",
|
|
667
925
|
"burnTokens",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildonspark/issuer-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Spark Issuer SDK for token issuance",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.browser.js",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"types": "tsc"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@buildonspark/spark-sdk": "0.5.
|
|
79
|
+
"@buildonspark/spark-sdk": "0.5.5",
|
|
80
80
|
"@noble/curves": "^1.8.0",
|
|
81
81
|
"@scure/btc-signer": "^1.5.0",
|
|
82
82
|
"buffer": "^6.0.3"
|