@buildonspark/issuer-sdk 0.0.33 → 0.0.35
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/package.json +3 -3
- package/src/examples/example.ts +0 -249
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildonspark/issuer-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"description": "Spark Issuer SDK for token issuance",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@bufbuild/protobuf": "^2.2.5",
|
|
57
|
-
"@buildonspark/lrc20-sdk": "0.0.
|
|
58
|
-
"@buildonspark/spark-sdk": "0.1.
|
|
57
|
+
"@buildonspark/lrc20-sdk": "0.0.32",
|
|
58
|
+
"@buildonspark/spark-sdk": "0.1.4",
|
|
59
59
|
"@noble/curves": "^1.8.0",
|
|
60
60
|
"@scure/btc-signer": "^1.5.0",
|
|
61
61
|
"bitcoinjs-lib": "^6.1.5",
|
package/src/examples/example.ts
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
|
-
import { Network } from "@buildonspark/spark-sdk/utils";
|
|
4
|
-
import readline from "readline";
|
|
5
|
-
import { IssuerWallet } from "../issuer-spark-wallet";
|
|
6
|
-
|
|
7
|
-
// Initialize Issuer Wallet
|
|
8
|
-
const walletMnemonic =
|
|
9
|
-
"cctypical huge dose party penalty decline neglect feel harvest abstract stage winter";
|
|
10
|
-
|
|
11
|
-
async function runCLI() {
|
|
12
|
-
let electrsCredentials = {
|
|
13
|
-
username: "spark-sdk",
|
|
14
|
-
password: "mCMk1JqlBNtetUNy",
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
let lrc20WalletApiConfig = {
|
|
18
|
-
electrsCredentials,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
let wallet = new IssuerWallet(Network.REGTEST);
|
|
22
|
-
const rl = readline.createInterface({
|
|
23
|
-
input: process.stdin,
|
|
24
|
-
output: process.stdout,
|
|
25
|
-
});
|
|
26
|
-
const helpMessage = `
|
|
27
|
-
General commands:
|
|
28
|
-
initwallet [mnemonic | seed] - Create a new wallet from a mnemonic
|
|
29
|
-
getaddresses - Get Spark and L1 addresses for this issuer
|
|
30
|
-
help - Show this help message
|
|
31
|
-
exit/quit - Exit the program
|
|
32
|
-
|
|
33
|
-
L1 commands:
|
|
34
|
-
announce <tokenName> <tokenTicker> <decimals> <maxSupply> <isFreezable> - Announce new token on L1
|
|
35
|
-
<tokenName> - string, from 3 to 20 symbols
|
|
36
|
-
<tokenTicker> - string, from 3 to 6 symbols
|
|
37
|
-
<decimals> - uint8
|
|
38
|
-
<maxSupply> - uint128, set 0 if no restrictions are needed
|
|
39
|
-
<isFreezable> - boolean, true/false
|
|
40
|
-
withdraw [receiverPublicKey] - Unilaterally withdraw tokens to L1
|
|
41
|
-
|
|
42
|
-
Spark commands:
|
|
43
|
-
getbalance - Show current wallet balance
|
|
44
|
-
mint <amount> - Mint new tokens
|
|
45
|
-
transfer <amount> <receiverPubKey> - Transfer tokens to a recipient
|
|
46
|
-
burn <amount> - Burn tokens
|
|
47
|
-
freeze <publicKey> - Freeze tokens at the specified public key
|
|
48
|
-
unfreeze <publicKey> - Unfreeze tokens at the specified public key
|
|
49
|
-
`;
|
|
50
|
-
console.log(helpMessage);
|
|
51
|
-
|
|
52
|
-
while (true) {
|
|
53
|
-
const command = await new Promise<string>((resolve) => {
|
|
54
|
-
rl.question("> ", resolve);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const [firstWord, ...args] = command.split(" ");
|
|
58
|
-
const lowerCommand = firstWord.toLowerCase();
|
|
59
|
-
|
|
60
|
-
if (lowerCommand === "exit" || lowerCommand === "quit") {
|
|
61
|
-
rl.close();
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
switch (lowerCommand) {
|
|
67
|
-
case "help":
|
|
68
|
-
console.log(helpMessage);
|
|
69
|
-
break;
|
|
70
|
-
case "initwallet":
|
|
71
|
-
const result = await wallet.initWallet(
|
|
72
|
-
args.join(" "),
|
|
73
|
-
true,
|
|
74
|
-
lrc20WalletApiConfig,
|
|
75
|
-
);
|
|
76
|
-
console.log(result);
|
|
77
|
-
break;
|
|
78
|
-
case "getaddresses":
|
|
79
|
-
if (!wallet.isSparkInitialized()) {
|
|
80
|
-
console.log("No wallet initialized");
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const tokenPublicKey = await wallet.getTokenPublicKey();
|
|
85
|
-
console.log("Token Public Key:", tokenPublicKey);
|
|
86
|
-
console.log("Spark Address:", tokenPublicKey);
|
|
87
|
-
|
|
88
|
-
if (wallet.isL1Initialized()) {
|
|
89
|
-
console.log("L1 Address:", wallet.getL1FundingAddress());
|
|
90
|
-
|
|
91
|
-
const tokenPublicKeyInfo = await wallet.getIssuerTokenInfo();
|
|
92
|
-
if (tokenPublicKeyInfo) {
|
|
93
|
-
let announcement = tokenPublicKeyInfo.announcement;
|
|
94
|
-
|
|
95
|
-
console.log("TokenInfo:");
|
|
96
|
-
console.log(" Name: ", announcement.name);
|
|
97
|
-
console.log(" Ticker: ", announcement.symbol);
|
|
98
|
-
console.log(" Decimals: ", announcement.decimal);
|
|
99
|
-
console.log(
|
|
100
|
-
" MaxSupply: ",
|
|
101
|
-
announcement.maxSupply == 0
|
|
102
|
-
? "unlimited"
|
|
103
|
-
: announcement.maxSupply,
|
|
104
|
-
);
|
|
105
|
-
console.log(" TotalSupply:", tokenPublicKeyInfo.totalSupply);
|
|
106
|
-
console.log(" Freezable: ", announcement.isFreezable);
|
|
107
|
-
} else {
|
|
108
|
-
console.log(
|
|
109
|
-
"No TokenInfo found. You should announce the token on L1",
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
break;
|
|
114
|
-
case "mint":
|
|
115
|
-
if (!wallet.isSparkInitialized()) {
|
|
116
|
-
console.log("No wallet initialized");
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const amountToMint = BigInt(parseInt(args[0]));
|
|
121
|
-
await wallet.mintTokens(amountToMint);
|
|
122
|
-
console.log(`Minted ${amountToMint} tokens`);
|
|
123
|
-
break;
|
|
124
|
-
case "transfer":
|
|
125
|
-
if (!wallet.isSparkInitialized()) {
|
|
126
|
-
console.log("No wallet initialized");
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const transferAmount = BigInt(parseInt(args[0]));
|
|
131
|
-
const receiverPubKey = args[1];
|
|
132
|
-
await wallet.transferTokens(transferAmount, receiverPubKey);
|
|
133
|
-
console.log(
|
|
134
|
-
`Transferred ${transferAmount} tokens to ${receiverPubKey}`,
|
|
135
|
-
);
|
|
136
|
-
break;
|
|
137
|
-
case "burn":
|
|
138
|
-
if (!wallet.isSparkInitialized()) {
|
|
139
|
-
console.log("No wallet initialized");
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const amountToBurn = BigInt(parseInt(args[0]));
|
|
144
|
-
await wallet.burnTokens(amountToBurn);
|
|
145
|
-
console.log(`Burned ${amountToBurn} tokens`);
|
|
146
|
-
break;
|
|
147
|
-
case "freeze":
|
|
148
|
-
if (!wallet.isSparkInitialized()) {
|
|
149
|
-
console.log("No wallet initialized");
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const freezePublicKey = args[0];
|
|
154
|
-
const freezeResult = await wallet.freezeTokens(freezePublicKey);
|
|
155
|
-
console.log("Freeze result:", freezeResult);
|
|
156
|
-
break;
|
|
157
|
-
case "unfreeze":
|
|
158
|
-
if (!wallet.isSparkInitialized()) {
|
|
159
|
-
console.log("No wallet initialized");
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const unfreezePublicKey = args[0];
|
|
164
|
-
const unfreezeResult = await wallet.unfreezeTokens(unfreezePublicKey);
|
|
165
|
-
console.log("Unfreeze result:", unfreezeResult);
|
|
166
|
-
break;
|
|
167
|
-
case "getbalance":
|
|
168
|
-
if (!wallet.isSparkInitialized()) {
|
|
169
|
-
console.log("No wallet initialized");
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
const balanceInfo = await wallet.getBalance(true);
|
|
173
|
-
// Display token balances if available
|
|
174
|
-
console.log(`Token Balance: ${balanceInfo.balance}`);
|
|
175
|
-
break;
|
|
176
|
-
case "announce": {
|
|
177
|
-
if (!wallet.isL1Initialized()) {
|
|
178
|
-
console.log("No L1 wallet initialized");
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const tokenName = args[0];
|
|
183
|
-
const tokenTicker = args[1];
|
|
184
|
-
const decimals = parseInt(args[2]);
|
|
185
|
-
const maxSupply = BigInt(parseInt(args[3]));
|
|
186
|
-
const isFreezable = args[4] === "true";
|
|
187
|
-
|
|
188
|
-
if (tokenName.length < 3 || tokenName.length > 20) {
|
|
189
|
-
console.log("Invalid tokenName length");
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (tokenTicker.length < 3 || tokenTicker.length > 6) {
|
|
194
|
-
console.log("Invalid tokenTicker length");
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (decimals < 0) {
|
|
199
|
-
console.log("Invalid decimals. Should be >= 0");
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (maxSupply < 0) {
|
|
204
|
-
console.log("Invalid maxSupply. Should be >= 0");
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
let announcementResult = await wallet.announceTokenL1(
|
|
209
|
-
tokenName,
|
|
210
|
-
tokenTicker,
|
|
211
|
-
decimals,
|
|
212
|
-
maxSupply,
|
|
213
|
-
isFreezable,
|
|
214
|
-
);
|
|
215
|
-
if (announcementResult) {
|
|
216
|
-
console.log(
|
|
217
|
-
"Token Announcement L1 Transaction ID:",
|
|
218
|
-
announcementResult.txid,
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
case "withdraw": {
|
|
224
|
-
if (!wallet.isL1Initialized()) {
|
|
225
|
-
console.log("No L1 wallet initialized");
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const receiverPublicKey = args[0];
|
|
230
|
-
|
|
231
|
-
let withdrawResult = await wallet.withdrawTokens(receiverPublicKey);
|
|
232
|
-
if (withdrawResult) {
|
|
233
|
-
console.log("Withdrawal L1 Transaction ID:", withdrawResult.txid);
|
|
234
|
-
}
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
default:
|
|
238
|
-
console.log(`Unknown command: ${lowerCommand}`);
|
|
239
|
-
console.log(helpMessage);
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
} catch (error) {
|
|
243
|
-
console.error("Error executing command:", error.message);
|
|
244
|
-
console.log("Please try again or type 'help' for available commands");
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
runCLI();
|