@buildonspark/issuer-sdk 0.0.30 → 0.0.31

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