@buildonspark/issuer-sdk 0.0.26 → 0.0.27
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/dist/index.cjs +11 -2
- package/dist/index.js +11 -2
- package/package.json +3 -3
- package/src/issuer-spark-wallet.ts +19 -10
- package/src/tests/integration/spark.test.ts +4 -14
package/dist/index.cjs
CHANGED
|
@@ -335,6 +335,7 @@ function convertTokenActivityToHexEncoded(rawTransactions) {
|
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
// src/issuer-spark-wallet.ts
|
|
338
|
+
var import_address2 = require("@buildonspark/spark-sdk/address");
|
|
338
339
|
var BURN_ADDRESS = "02".repeat(33);
|
|
339
340
|
var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk.SparkWallet {
|
|
340
341
|
issuerTokenTransactionService;
|
|
@@ -438,8 +439,12 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk.SparkW
|
|
|
438
439
|
async freezeTokens(ownerPublicKey) {
|
|
439
440
|
await this.syncTokenLeaves();
|
|
440
441
|
const tokenPublicKey = await super.getIdentityPublicKey();
|
|
442
|
+
const decodedOwnerPubkey = (0, import_address2.decodeSparkAddress)(
|
|
443
|
+
ownerPublicKey,
|
|
444
|
+
this.config.getNetworkType()
|
|
445
|
+
);
|
|
441
446
|
const response = await this.tokenFreezeService.freezeTokens(
|
|
442
|
-
(0, import_utils6.hexToBytes)(
|
|
447
|
+
(0, import_utils6.hexToBytes)(decodedOwnerPubkey),
|
|
443
448
|
(0, import_utils6.hexToBytes)(tokenPublicKey)
|
|
444
449
|
);
|
|
445
450
|
const tokenAmount = (0, import_utils6.bytesToNumberBE)(response.impactedTokenAmount);
|
|
@@ -451,8 +456,12 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk.SparkW
|
|
|
451
456
|
async unfreezeTokens(ownerPublicKey) {
|
|
452
457
|
await this.syncTokenLeaves();
|
|
453
458
|
const tokenPublicKey = await super.getIdentityPublicKey();
|
|
459
|
+
const decodedOwnerPubkey = (0, import_address2.decodeSparkAddress)(
|
|
460
|
+
ownerPublicKey,
|
|
461
|
+
this.config.getNetworkType()
|
|
462
|
+
);
|
|
454
463
|
const response = await this.tokenFreezeService.unfreezeTokens(
|
|
455
|
-
(0, import_utils6.hexToBytes)(
|
|
464
|
+
(0, import_utils6.hexToBytes)(decodedOwnerPubkey),
|
|
456
465
|
(0, import_utils6.hexToBytes)(tokenPublicKey)
|
|
457
466
|
);
|
|
458
467
|
const tokenAmount = (0, import_utils6.bytesToNumberBE)(response.impactedTokenAmount);
|
package/dist/index.js
CHANGED
|
@@ -315,6 +315,7 @@ function convertTokenActivityToHexEncoded(rawTransactions) {
|
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
// src/issuer-spark-wallet.ts
|
|
318
|
+
import { decodeSparkAddress } from "@buildonspark/spark-sdk/address";
|
|
318
319
|
var BURN_ADDRESS = "02".repeat(33);
|
|
319
320
|
var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
|
|
320
321
|
issuerTokenTransactionService;
|
|
@@ -418,8 +419,12 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
|
|
|
418
419
|
async freezeTokens(ownerPublicKey) {
|
|
419
420
|
await this.syncTokenLeaves();
|
|
420
421
|
const tokenPublicKey = await super.getIdentityPublicKey();
|
|
422
|
+
const decodedOwnerPubkey = decodeSparkAddress(
|
|
423
|
+
ownerPublicKey,
|
|
424
|
+
this.config.getNetworkType()
|
|
425
|
+
);
|
|
421
426
|
const response = await this.tokenFreezeService.freezeTokens(
|
|
422
|
-
hexToBytes(
|
|
427
|
+
hexToBytes(decodedOwnerPubkey),
|
|
423
428
|
hexToBytes(tokenPublicKey)
|
|
424
429
|
);
|
|
425
430
|
const tokenAmount = bytesToNumberBE2(response.impactedTokenAmount);
|
|
@@ -431,8 +436,12 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
|
|
|
431
436
|
async unfreezeTokens(ownerPublicKey) {
|
|
432
437
|
await this.syncTokenLeaves();
|
|
433
438
|
const tokenPublicKey = await super.getIdentityPublicKey();
|
|
439
|
+
const decodedOwnerPubkey = decodeSparkAddress(
|
|
440
|
+
ownerPublicKey,
|
|
441
|
+
this.config.getNetworkType()
|
|
442
|
+
);
|
|
434
443
|
const response = await this.tokenFreezeService.unfreezeTokens(
|
|
435
|
-
hexToBytes(
|
|
444
|
+
hexToBytes(decodedOwnerPubkey),
|
|
436
445
|
hexToBytes(tokenPublicKey)
|
|
437
446
|
);
|
|
438
447
|
const tokenAmount = bytesToNumberBE2(response.impactedTokenAmount);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildonspark/issuer-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
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.0.
|
|
57
|
+
"@buildonspark/lrc20-sdk": "0.0.25",
|
|
58
|
+
"@buildonspark/spark-sdk": "0.0.27",
|
|
59
59
|
"@noble/curves": "^1.8.0",
|
|
60
60
|
"@scure/bip39": "^1.5.4",
|
|
61
61
|
"@scure/btc-signer": "^1.5.0",
|
|
@@ -2,9 +2,12 @@ import {
|
|
|
2
2
|
LRCWallet,
|
|
3
3
|
TokenPubkey,
|
|
4
4
|
TokenPubkeyAnnouncement,
|
|
5
|
-
TokenPubkeyInfo
|
|
5
|
+
TokenPubkeyInfo,
|
|
6
6
|
} from "@buildonspark/lrc20-sdk";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ListAllTokenTransactionsCursor,
|
|
9
|
+
OperationType,
|
|
10
|
+
} from "@buildonspark/lrc20-sdk/proto/rpc/v1/types";
|
|
8
11
|
import { SparkWallet, SparkWalletProps } from "@buildonspark/spark-sdk";
|
|
9
12
|
import { encodeSparkAddress } from "@buildonspark/spark-sdk/address";
|
|
10
13
|
import { LeafWithPreviousTransactionData } from "@buildonspark/spark-sdk/proto/spark";
|
|
@@ -30,12 +33,14 @@ import {
|
|
|
30
33
|
convertTokenActivityToHexEncoded,
|
|
31
34
|
convertToTokenPubKeyInfoResponse,
|
|
32
35
|
} from "./utils/type-mappers.js";
|
|
36
|
+
import { decodeSparkAddress } from "@buildonspark/spark-sdk/address";
|
|
33
37
|
|
|
34
38
|
const BURN_ADDRESS = "02".repeat(33);
|
|
35
39
|
|
|
36
40
|
export class IssuerSparkWallet
|
|
37
41
|
extends SparkWallet
|
|
38
|
-
implements IssuerWalletInterface
|
|
42
|
+
implements IssuerWalletInterface
|
|
43
|
+
{
|
|
39
44
|
private issuerTokenTransactionService: IssuerTokenTransactionService;
|
|
40
45
|
private tokenFreezeService: TokenFreezeService;
|
|
41
46
|
private tokenPublicKeyInfo?: TokenPubkeyInfo;
|
|
@@ -88,7 +93,7 @@ export class IssuerSparkWallet
|
|
|
88
93
|
bytesToHex(identityKey.privateKey!),
|
|
89
94
|
LRC_WALLET_NETWORK[network],
|
|
90
95
|
LRC_WALLET_NETWORK_TYPE[network],
|
|
91
|
-
this.config.lrc20ApiConfig
|
|
96
|
+
this.config.lrc20ApiConfig,
|
|
92
97
|
);
|
|
93
98
|
}
|
|
94
99
|
|
|
@@ -115,11 +120,9 @@ export class IssuerSparkWallet
|
|
|
115
120
|
if (this.tokenPublicKeyInfo) {
|
|
116
121
|
return convertToTokenPubKeyInfoResponse(this.tokenPublicKeyInfo);
|
|
117
122
|
}
|
|
118
|
-
|
|
119
123
|
const tokenPublicKey = bytesToHex(this.lrc20Wallet!.pubkey);
|
|
120
124
|
const rawTokenPubkeyInfo =
|
|
121
125
|
await this.lrc20Wallet!.getTokenPubkeyInfo(tokenPublicKey);
|
|
122
|
-
|
|
123
126
|
this.tokenPublicKeyInfo = rawTokenPubkeyInfo;
|
|
124
127
|
if (!rawTokenPubkeyInfo) {
|
|
125
128
|
return null;
|
|
@@ -166,9 +169,12 @@ export class IssuerSparkWallet
|
|
|
166
169
|
): Promise<{ impactedLeafIds: string[]; impactedTokenAmount: bigint }> {
|
|
167
170
|
await this.syncTokenLeaves();
|
|
168
171
|
const tokenPublicKey = await super.getIdentityPublicKey();
|
|
169
|
-
|
|
172
|
+
const decodedOwnerPubkey = decodeSparkAddress(
|
|
173
|
+
ownerPublicKey,
|
|
174
|
+
this.config.getNetworkType(),
|
|
175
|
+
);
|
|
170
176
|
const response = await this.tokenFreezeService!.freezeTokens(
|
|
171
|
-
hexToBytes(
|
|
177
|
+
hexToBytes(decodedOwnerPubkey),
|
|
172
178
|
hexToBytes(tokenPublicKey),
|
|
173
179
|
);
|
|
174
180
|
|
|
@@ -186,9 +192,12 @@ export class IssuerSparkWallet
|
|
|
186
192
|
): Promise<{ impactedLeafIds: string[]; impactedTokenAmount: bigint }> {
|
|
187
193
|
await this.syncTokenLeaves();
|
|
188
194
|
const tokenPublicKey = await super.getIdentityPublicKey();
|
|
189
|
-
|
|
195
|
+
const decodedOwnerPubkey = decodeSparkAddress(
|
|
196
|
+
ownerPublicKey,
|
|
197
|
+
this.config.getNetworkType(),
|
|
198
|
+
);
|
|
190
199
|
const response = await this.tokenFreezeService!.unfreezeTokens(
|
|
191
|
-
hexToBytes(
|
|
200
|
+
hexToBytes(decodedOwnerPubkey),
|
|
192
201
|
hexToBytes(tokenPublicKey),
|
|
193
202
|
);
|
|
194
203
|
const tokenAmount = bytesToNumberBE(response.impactedTokenAmount);
|
|
@@ -9,11 +9,7 @@ import { BitcoinFaucet } from "../../../../spark-sdk/src/tests/utils/test-faucet
|
|
|
9
9
|
import { IssuerSparkWallet } from "../../issuer-spark-wallet.js";
|
|
10
10
|
|
|
11
11
|
describe("token integration test", () => {
|
|
12
|
-
|
|
13
|
-
process.env.GITHUB_ACTIONS ? it.skip : it;
|
|
14
|
-
|
|
15
|
-
// Increase timeout for all tests in this suite
|
|
16
|
-
jest.setTimeout(60000);
|
|
12
|
+
jest.setTimeout(80000);
|
|
17
13
|
|
|
18
14
|
it("should issue a single token with ECDSA", async () => {
|
|
19
15
|
const tokenAmount: bigint = 1000n;
|
|
@@ -284,7 +280,6 @@ describe("token integration test", () => {
|
|
|
284
280
|
tokenPublicKey: await issuerWallet.getIdentityPublicKey(),
|
|
285
281
|
receiverSparkAddress: userWalletPublicKey,
|
|
286
282
|
});
|
|
287
|
-
|
|
288
283
|
const issuerBalanceAfterTransfer =
|
|
289
284
|
await issuerWallet.getIssuerTokenBalance();
|
|
290
285
|
expect(issuerBalanceAfterTransfer.balance).toEqual(0n);
|
|
@@ -295,7 +290,6 @@ describe("token integration test", () => {
|
|
|
295
290
|
tokenPublicKey,
|
|
296
291
|
);
|
|
297
292
|
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
298
|
-
|
|
299
293
|
// Freeze tokens
|
|
300
294
|
const freezeResponse = await issuerWallet.freezeTokens(userWalletPublicKey);
|
|
301
295
|
expect(freezeResponse.impactedLeafIds.length).toBeGreaterThan(0);
|
|
@@ -413,7 +407,6 @@ describe("token integration test", () => {
|
|
|
413
407
|
const issuerBalanceAfterTransfer =
|
|
414
408
|
await issuerWallet.getIssuerTokenBalance();
|
|
415
409
|
expect(issuerBalanceAfterTransfer.balance).toEqual(0n);
|
|
416
|
-
|
|
417
410
|
const tokenPublicKeyHex = await issuerWallet.getIdentityPublicKey();
|
|
418
411
|
const userWalletPublicKeyHex = await userWallet.getSparkAddress();
|
|
419
412
|
const userBalanceAfterTransfer = await getSparkWalletTokenBalanceOrZero(
|
|
@@ -421,24 +414,22 @@ describe("token integration test", () => {
|
|
|
421
414
|
tokenPublicKeyHex,
|
|
422
415
|
);
|
|
423
416
|
expect(userBalanceAfterTransfer.balance).toEqual(tokenAmount);
|
|
424
|
-
|
|
425
417
|
await userWallet.transferTokens({
|
|
426
418
|
tokenPublicKey: tokenPublicKeyHex,
|
|
427
419
|
tokenAmount,
|
|
428
|
-
receiverSparkAddress:
|
|
420
|
+
receiverSparkAddress: await issuerWallet.getSparkAddress(),
|
|
429
421
|
});
|
|
430
422
|
|
|
431
423
|
const userBalanceAfterTransferBack = await getSparkWalletTokenBalanceOrZero(
|
|
432
424
|
userWallet,
|
|
433
425
|
tokenPublicKeyHex,
|
|
434
426
|
);
|
|
427
|
+
|
|
435
428
|
expect(userBalanceAfterTransferBack.balance).toEqual(0n);
|
|
436
429
|
|
|
437
430
|
const issuerTokenBalance = await issuerWallet.getIssuerTokenBalance();
|
|
438
431
|
expect(issuerTokenBalance.balance).toEqual(tokenAmount);
|
|
439
|
-
|
|
440
432
|
await issuerWallet.burnTokens(tokenAmount);
|
|
441
|
-
|
|
442
433
|
const issuerTokenBalanceAfterBurn =
|
|
443
434
|
await issuerWallet.getIssuerTokenBalance();
|
|
444
435
|
expect(issuerTokenBalanceAfterBurn.balance).toEqual(0n);
|
|
@@ -474,7 +465,6 @@ describe("token integration test", () => {
|
|
|
474
465
|
expect(issuerBalanceAfterTransfer.balance).toEqual(0n);
|
|
475
466
|
|
|
476
467
|
const tokenPublicKeyHex = await issuerWallet.getIdentityPublicKey();
|
|
477
|
-
const userWalletPublicKeyHex = await userWallet.getSparkAddress();
|
|
478
468
|
const userBalanceAfterTransfer = await getSparkWalletTokenBalanceOrZero(
|
|
479
469
|
userWallet,
|
|
480
470
|
tokenPublicKeyHex,
|
|
@@ -484,7 +474,7 @@ describe("token integration test", () => {
|
|
|
484
474
|
await userWallet.transferTokens({
|
|
485
475
|
tokenPublicKey: tokenPublicKeyHex,
|
|
486
476
|
tokenAmount,
|
|
487
|
-
receiverSparkAddress:
|
|
477
|
+
receiverSparkAddress: await issuerWallet.getSparkAddress(),
|
|
488
478
|
});
|
|
489
479
|
|
|
490
480
|
const userBalanceAfterTransferBack = await getSparkWalletTokenBalanceOrZero(
|