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