@buildonspark/issuer-sdk 0.0.77 → 0.0.78

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/src/types.ts DELETED
@@ -1,85 +0,0 @@
1
- export type TokenActivityResponse = {
2
- transactions: Transaction[];
3
- nextCursor?: ListAllTokenTransactionsCursor | undefined;
4
- };
5
-
6
- export interface Transaction {
7
- transaction?:
8
- | {
9
- $case: "onChain";
10
- onChain: OnChainTransaction;
11
- }
12
- | {
13
- $case: "spark";
14
- spark: SparkTransaction;
15
- }
16
- | undefined;
17
- }
18
-
19
- export interface TokenPubKeyInfoResponse {
20
- announcement: {
21
- tokenPubkey: {
22
- pubkey: string;
23
- };
24
- name: string;
25
- symbol: string;
26
- decimal: number;
27
- maxSupply: bigint;
28
- isFreezable: boolean;
29
- } | null;
30
- totalSupply: bigint;
31
- }
32
-
33
- export interface OnChainTokenOutput {
34
- rawTx: string;
35
- vout: number;
36
- amountSats: number;
37
- tokenPublicKey?: string | undefined;
38
- tokenAmount?: string | undefined;
39
- }
40
- export interface OnChainTransaction {
41
- operationType: string;
42
- transactionHash: string;
43
- rawtx: string;
44
- status: string;
45
- inputs: OnChainTokenOutput[];
46
- outputs: OnChainTokenOutput[];
47
- broadcastedAt: Date | undefined;
48
- confirmedAt: Date | undefined;
49
- }
50
- export interface SparkTransaction {
51
- operationType: string;
52
- transactionHash: string;
53
- status: string;
54
- confirmedAt: Date | undefined;
55
- leavesToCreate: SparkLeaf[];
56
- leavesToSpend: SparkLeaf[];
57
- sparkOperatorIdentityPublicKeys: string[];
58
- }
59
- export interface SparkLeaf {
60
- tokenPublicKey: string;
61
- id: string;
62
- ownerPublicKey: string;
63
- revocationPublicKey: string;
64
- withdrawalBondSats: number;
65
- withdrawalLocktime: number;
66
- tokenAmount: string;
67
- createTxHash: string;
68
- createTxVoutIndex: number;
69
- spendTxHash?: string | undefined;
70
- spendTxVoutIndex?: number | undefined;
71
- isFrozen?: boolean | undefined;
72
- }
73
-
74
- export interface ListAllTokenTransactionsCursor {
75
- lastTransactionHash: string;
76
- layer: string;
77
- }
78
-
79
- export interface TokenDistribution {
80
- totalCirculatingSupply: bigint;
81
- totalIssued: bigint;
82
- totalBurned: bigint;
83
- numHoldingAddress: number;
84
- numConfirmedTransactions: bigint;
85
- }
@@ -1,148 +0,0 @@
1
- import { TokenPubkeyInfo } from "@buildonspark/lrc20-sdk";
2
- import { TokenActivityResponse, TokenPubKeyInfoResponse } from "../types.js";
3
- import { bytesToHex, bytesToNumberBE } from "@noble/curves/abstract/utils";
4
- import {
5
- ListAllTokenTransactionsResponse,
6
- OperationType,
7
- OnChainTransactionStatus,
8
- SparkTransactionStatus,
9
- Layer,
10
- } from "@buildonspark/spark-sdk/proto/lrc20";
11
-
12
- export function convertToTokenPubKeyInfoResponse(
13
- tokenPubkeyInfo: TokenPubkeyInfo,
14
- ): TokenPubKeyInfoResponse {
15
- return {
16
- announcement: tokenPubkeyInfo?.announcement
17
- ? {
18
- tokenPubkey: {
19
- pubkey: bytesToHex(tokenPubkeyInfo.announcement.tokenPubkey.pubkey),
20
- },
21
- name: tokenPubkeyInfo.announcement.name,
22
- symbol: tokenPubkeyInfo.announcement.symbol,
23
- decimal: tokenPubkeyInfo.announcement.decimal,
24
- maxSupply: tokenPubkeyInfo.announcement.maxSupply,
25
- isFreezable: tokenPubkeyInfo.announcement.isFreezable,
26
- }
27
- : null,
28
- totalSupply: tokenPubkeyInfo?.totalSupply ?? "0",
29
- };
30
- }
31
-
32
- /**
33
- * Converts a ListAllTokenTransactionsResponse to a TokenActivityResponse
34
- * Main purpose is to convert Uint8Arrays to hex strings
35
- * @param rawTransactions - The ListAllTokenTransactionsResponse to convert
36
- * @returns The converted TokenActivityResponse
37
- */
38
- export function convertToTokenActivity(
39
- rawTransactions: ListAllTokenTransactionsResponse,
40
- ): TokenActivityResponse {
41
- const response: TokenActivityResponse = {
42
- transactions: rawTransactions.transactions.map((transaction) => {
43
- if (!transaction.transaction) {
44
- return { transaction: undefined };
45
- }
46
-
47
- if (transaction.transaction.$case === "onChain") {
48
- const onChain = transaction.transaction.onChain;
49
- return {
50
- transaction: {
51
- $case: "onChain",
52
- onChain: {
53
- operationType: getEnumName(OperationType, onChain.operationType),
54
- transactionHash: bytesToHex(onChain.transactionHash),
55
- rawtx: bytesToHex(onChain.rawtx),
56
- status: getEnumName(OnChainTransactionStatus, onChain.status),
57
- inputs: onChain.inputs.map((input) => ({
58
- rawTx: bytesToHex(input.rawTx),
59
- vout: input.vout,
60
- amountSats: input.amountSats,
61
- tokenPublicKey: input.tokenPublicKey,
62
- tokenAmount: input.tokenAmount
63
- ? bytesToNumberBE(input.tokenAmount).toString()
64
- : undefined,
65
- })),
66
- outputs: onChain.outputs.map((output) => ({
67
- rawTx: bytesToHex(output.rawTx),
68
- vout: output.vout,
69
- amountSats: output.amountSats,
70
- tokenPublicKey: output.tokenPublicKey,
71
- tokenAmount: output.tokenAmount
72
- ? bytesToNumberBE(output.tokenAmount).toString()
73
- : undefined,
74
- })),
75
- broadcastedAt: onChain.broadcastedAt,
76
- confirmedAt: onChain.confirmedAt,
77
- },
78
- },
79
- };
80
- } else if (transaction.transaction.$case === "spark") {
81
- const spark = transaction.transaction.spark;
82
- return {
83
- transaction: {
84
- $case: "spark",
85
- spark: {
86
- operationType: getEnumName(OperationType, spark.operationType),
87
- transactionHash: bytesToHex(spark.transactionHash),
88
- status: getEnumName(SparkTransactionStatus, spark.status),
89
- confirmedAt: spark.confirmedAt,
90
- leavesToCreate: spark.leavesToCreate.map((leaf) => ({
91
- tokenPublicKey: bytesToHex(leaf.tokenPublicKey),
92
- id: leaf.id,
93
- ownerPublicKey: bytesToHex(leaf.ownerPublicKey),
94
- revocationPublicKey: bytesToHex(leaf.revocationPublicKey),
95
- withdrawalBondSats: leaf.withdrawalBondSats,
96
- withdrawalLocktime: leaf.withdrawalLocktime,
97
- tokenAmount: bytesToNumberBE(leaf.tokenAmount).toString(),
98
- createTxHash: bytesToHex(leaf.createTxHash),
99
- createTxVoutIndex: leaf.createTxVoutIndex,
100
- spendTxHash: leaf.spendTxHash
101
- ? bytesToHex(leaf.spendTxHash)
102
- : undefined,
103
- spendTxVoutIndex: leaf.spendTxVoutIndex,
104
- isFrozen: leaf.isFrozen,
105
- })),
106
- leavesToSpend: spark.leavesToSpend.map((leaf) => ({
107
- tokenPublicKey: bytesToHex(leaf.tokenPublicKey),
108
- id: leaf.id,
109
- ownerPublicKey: bytesToHex(leaf.ownerPublicKey),
110
- revocationPublicKey: bytesToHex(leaf.revocationPublicKey),
111
- withdrawalBondSats: leaf.withdrawalBondSats,
112
- withdrawalLocktime: leaf.withdrawalLocktime,
113
- tokenAmount: bytesToNumberBE(leaf.tokenAmount).toString(),
114
- createTxHash: bytesToHex(leaf.createTxHash),
115
- createTxVoutIndex: leaf.createTxVoutIndex,
116
- spendTxHash: leaf.spendTxHash
117
- ? bytesToHex(leaf.spendTxHash)
118
- : undefined,
119
- spendTxVoutIndex: leaf.spendTxVoutIndex,
120
- isFrozen: leaf.isFrozen,
121
- })),
122
- sparkOperatorIdentityPublicKeys:
123
- spark.sparkOperatorIdentityPublicKeys.map((key) =>
124
- bytesToHex(key),
125
- ),
126
- },
127
- },
128
- };
129
- }
130
-
131
- return { transaction: undefined };
132
- }),
133
- nextCursor: rawTransactions.nextCursor
134
- ? {
135
- lastTransactionHash: bytesToHex(
136
- rawTransactions.nextCursor.lastTransactionHash,
137
- ),
138
- layer: getEnumName(Layer, rawTransactions.nextCursor.layer),
139
- }
140
- : undefined,
141
- };
142
-
143
- return response;
144
- }
145
-
146
- export function getEnumName(enumObj: any, value: number): string {
147
- return enumObj[value];
148
- }