@buildonspark/issuer-sdk 0.0.95 → 0.0.97
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 +14 -0
- package/dist/{chunk-HQI3Y4QH.js → chunk-GKBNEYTU.js} +5 -33
- package/dist/index.cjs +5 -33
- package/dist/index.js +1 -1
- package/dist/index.node.cjs +5 -33
- package/dist/index.node.js +1 -1
- package/package.json +2 -2
- package/src/issuer-wallet/issuer-spark-wallet.ts +7 -20
- package/src/services/token-transactions.ts +0 -26
- package/src/tests/integration/spark.test.ts +208 -185
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @buildonspark/issuer-sdk
|
|
2
2
|
|
|
3
|
+
## 0.0.97
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @buildonspark/spark-sdk@0.3.4
|
|
9
|
+
|
|
10
|
+
## 0.0.96
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @buildonspark/spark-sdk@0.3.3
|
|
16
|
+
|
|
3
17
|
## 0.0.95
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -153,26 +153,6 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
|
|
|
153
153
|
constructor(config, connectionManager) {
|
|
154
154
|
super(config, connectionManager);
|
|
155
155
|
}
|
|
156
|
-
async constructMintTokenTransactionV0(tokenPublicKey, tokenAmount) {
|
|
157
|
-
return {
|
|
158
|
-
network: this.config.getNetworkProto(),
|
|
159
|
-
tokenInputs: {
|
|
160
|
-
$case: "mintInput",
|
|
161
|
-
mintInput: {
|
|
162
|
-
issuerPublicKey: tokenPublicKey,
|
|
163
|
-
issuerProvidedTimestamp: Date.now()
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
tokenOutputs: [
|
|
167
|
-
{
|
|
168
|
-
ownerPublicKey: tokenPublicKey,
|
|
169
|
-
tokenPublicKey,
|
|
170
|
-
tokenAmount: numberToBytesBE(tokenAmount, 16)
|
|
171
|
-
}
|
|
172
|
-
],
|
|
173
|
-
sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys()
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
156
|
async constructMintTokenTransaction(rawTokenIdentifierBytes, issuerTokenPublicKey, tokenAmount) {
|
|
177
157
|
return {
|
|
178
158
|
version: 2,
|
|
@@ -472,23 +452,15 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends SparkWallet {
|
|
|
472
452
|
* @returns The transaction ID of the mint operation
|
|
473
453
|
*/
|
|
474
454
|
async mintTokens(tokenAmount) {
|
|
475
|
-
let tokenTransaction;
|
|
476
455
|
const issuerTokenPublicKey = await super.getIdentityPublicKey();
|
|
477
456
|
const issuerTokenPublicKeyBytes = hexToBytes2(issuerTokenPublicKey);
|
|
478
457
|
const tokenMetadata = await this.getIssuerTokenMetadata();
|
|
479
458
|
const rawTokenIdentifier = tokenMetadata.rawTokenIdentifier;
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
} else {
|
|
486
|
-
tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
|
|
487
|
-
rawTokenIdentifier,
|
|
488
|
-
issuerTokenPublicKeyBytes,
|
|
489
|
-
tokenAmount
|
|
490
|
-
);
|
|
491
|
-
}
|
|
459
|
+
const tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
|
|
460
|
+
rawTokenIdentifier,
|
|
461
|
+
issuerTokenPublicKeyBytes,
|
|
462
|
+
tokenAmount
|
|
463
|
+
);
|
|
492
464
|
return await this.issuerTokenTransactionService.broadcastTokenTransaction(
|
|
493
465
|
tokenTransaction
|
|
494
466
|
);
|
package/dist/index.cjs
CHANGED
|
@@ -175,26 +175,6 @@ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransac
|
|
|
175
175
|
constructor(config, connectionManager) {
|
|
176
176
|
super(config, connectionManager);
|
|
177
177
|
}
|
|
178
|
-
async constructMintTokenTransactionV0(tokenPublicKey, tokenAmount) {
|
|
179
|
-
return {
|
|
180
|
-
network: this.config.getNetworkProto(),
|
|
181
|
-
tokenInputs: {
|
|
182
|
-
$case: "mintInput",
|
|
183
|
-
mintInput: {
|
|
184
|
-
issuerPublicKey: tokenPublicKey,
|
|
185
|
-
issuerProvidedTimestamp: Date.now()
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
tokenOutputs: [
|
|
189
|
-
{
|
|
190
|
-
ownerPublicKey: tokenPublicKey,
|
|
191
|
-
tokenPublicKey,
|
|
192
|
-
tokenAmount: (0, import_utils3.numberToBytesBE)(tokenAmount, 16)
|
|
193
|
-
}
|
|
194
|
-
],
|
|
195
|
-
sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys()
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
178
|
async constructMintTokenTransaction(rawTokenIdentifierBytes, issuerTokenPublicKey, tokenAmount) {
|
|
199
179
|
return {
|
|
200
180
|
version: 2,
|
|
@@ -494,23 +474,15 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk5.Spark
|
|
|
494
474
|
* @returns The transaction ID of the mint operation
|
|
495
475
|
*/
|
|
496
476
|
async mintTokens(tokenAmount) {
|
|
497
|
-
let tokenTransaction;
|
|
498
477
|
const issuerTokenPublicKey = await super.getIdentityPublicKey();
|
|
499
478
|
const issuerTokenPublicKeyBytes = (0, import_utils4.hexToBytes)(issuerTokenPublicKey);
|
|
500
479
|
const tokenMetadata = await this.getIssuerTokenMetadata();
|
|
501
480
|
const rawTokenIdentifier = tokenMetadata.rawTokenIdentifier;
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
} else {
|
|
508
|
-
tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
|
|
509
|
-
rawTokenIdentifier,
|
|
510
|
-
issuerTokenPublicKeyBytes,
|
|
511
|
-
tokenAmount
|
|
512
|
-
);
|
|
513
|
-
}
|
|
481
|
+
const tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
|
|
482
|
+
rawTokenIdentifier,
|
|
483
|
+
issuerTokenPublicKeyBytes,
|
|
484
|
+
tokenAmount
|
|
485
|
+
);
|
|
514
486
|
return await this.issuerTokenTransactionService.broadcastTokenTransaction(
|
|
515
487
|
tokenTransaction
|
|
516
488
|
);
|
package/dist/index.js
CHANGED
package/dist/index.node.cjs
CHANGED
|
@@ -175,26 +175,6 @@ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransac
|
|
|
175
175
|
constructor(config, connectionManager) {
|
|
176
176
|
super(config, connectionManager);
|
|
177
177
|
}
|
|
178
|
-
async constructMintTokenTransactionV0(tokenPublicKey, tokenAmount) {
|
|
179
|
-
return {
|
|
180
|
-
network: this.config.getNetworkProto(),
|
|
181
|
-
tokenInputs: {
|
|
182
|
-
$case: "mintInput",
|
|
183
|
-
mintInput: {
|
|
184
|
-
issuerPublicKey: tokenPublicKey,
|
|
185
|
-
issuerProvidedTimestamp: Date.now()
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
tokenOutputs: [
|
|
189
|
-
{
|
|
190
|
-
ownerPublicKey: tokenPublicKey,
|
|
191
|
-
tokenPublicKey,
|
|
192
|
-
tokenAmount: (0, import_utils3.numberToBytesBE)(tokenAmount, 16)
|
|
193
|
-
}
|
|
194
|
-
],
|
|
195
|
-
sparkOperatorIdentityPublicKeys: super.collectOperatorIdentityPublicKeys()
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
178
|
async constructMintTokenTransaction(rawTokenIdentifierBytes, issuerTokenPublicKey, tokenAmount) {
|
|
199
179
|
return {
|
|
200
180
|
version: 2,
|
|
@@ -494,23 +474,15 @@ var IssuerSparkWallet = class _IssuerSparkWallet extends import_spark_sdk5.Spark
|
|
|
494
474
|
* @returns The transaction ID of the mint operation
|
|
495
475
|
*/
|
|
496
476
|
async mintTokens(tokenAmount) {
|
|
497
|
-
let tokenTransaction;
|
|
498
477
|
const issuerTokenPublicKey = await super.getIdentityPublicKey();
|
|
499
478
|
const issuerTokenPublicKeyBytes = (0, import_utils4.hexToBytes)(issuerTokenPublicKey);
|
|
500
479
|
const tokenMetadata = await this.getIssuerTokenMetadata();
|
|
501
480
|
const rawTokenIdentifier = tokenMetadata.rawTokenIdentifier;
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
} else {
|
|
508
|
-
tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
|
|
509
|
-
rawTokenIdentifier,
|
|
510
|
-
issuerTokenPublicKeyBytes,
|
|
511
|
-
tokenAmount
|
|
512
|
-
);
|
|
513
|
-
}
|
|
481
|
+
const tokenTransaction = await this.issuerTokenTransactionService.constructMintTokenTransaction(
|
|
482
|
+
rawTokenIdentifier,
|
|
483
|
+
issuerTokenPublicKeyBytes,
|
|
484
|
+
tokenAmount
|
|
485
|
+
);
|
|
514
486
|
return await this.issuerTokenTransactionService.broadcastTokenTransaction(
|
|
515
487
|
tokenTransaction
|
|
516
488
|
);
|
package/dist/index.node.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buildonspark/issuer-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.97",
|
|
4
4
|
"description": "Spark Issuer SDK for token issuance",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"types": "tsc"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@buildonspark/spark-sdk": "0.3.
|
|
75
|
+
"@buildonspark/spark-sdk": "0.3.4",
|
|
76
76
|
"@noble/curves": "^1.8.0",
|
|
77
77
|
"@scure/btc-signer": "^1.5.0",
|
|
78
78
|
"buffer": "^6.0.3"
|
|
@@ -12,11 +12,7 @@ import {
|
|
|
12
12
|
ValidationError,
|
|
13
13
|
type ConfigOptions,
|
|
14
14
|
} from "@buildonspark/spark-sdk";
|
|
15
|
-
import {
|
|
16
|
-
OutputWithPreviousTransactionData,
|
|
17
|
-
TokenTransaction as TokenTransactionV0,
|
|
18
|
-
} from "@buildonspark/spark-sdk/proto/spark";
|
|
19
|
-
import { TokenTransaction } from "@buildonspark/spark-sdk/proto/spark_token";
|
|
15
|
+
import { OutputWithPreviousTransactionData } from "@buildonspark/spark-sdk/proto/spark";
|
|
20
16
|
import { bytesToHex, bytesToNumberBE, hexToBytes } from "@noble/curves/utils";
|
|
21
17
|
import { TokenFreezeService } from "../services/freeze.js";
|
|
22
18
|
import { IssuerTokenTransactionService } from "../services/token-transactions.js";
|
|
@@ -241,27 +237,18 @@ export class IssuerSparkWallet extends SparkWallet {
|
|
|
241
237
|
* @returns The transaction ID of the mint operation
|
|
242
238
|
*/
|
|
243
239
|
public async mintTokens(tokenAmount: bigint): Promise<string> {
|
|
244
|
-
let tokenTransaction: TokenTransactionV0 | TokenTransaction;
|
|
245
240
|
const issuerTokenPublicKey = await super.getIdentityPublicKey();
|
|
246
241
|
const issuerTokenPublicKeyBytes = hexToBytes(issuerTokenPublicKey);
|
|
247
242
|
|
|
248
243
|
const tokenMetadata = await this.getIssuerTokenMetadata();
|
|
249
244
|
const rawTokenIdentifier: Uint8Array = tokenMetadata.rawTokenIdentifier;
|
|
250
245
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
} else {
|
|
258
|
-
tokenTransaction =
|
|
259
|
-
await this.issuerTokenTransactionService.constructMintTokenTransaction(
|
|
260
|
-
rawTokenIdentifier,
|
|
261
|
-
issuerTokenPublicKeyBytes,
|
|
262
|
-
tokenAmount,
|
|
263
|
-
);
|
|
264
|
-
}
|
|
246
|
+
const tokenTransaction =
|
|
247
|
+
await this.issuerTokenTransactionService.constructMintTokenTransaction(
|
|
248
|
+
rawTokenIdentifier,
|
|
249
|
+
issuerTokenPublicKeyBytes,
|
|
250
|
+
tokenAmount,
|
|
251
|
+
);
|
|
265
252
|
|
|
266
253
|
return await this.issuerTokenTransactionService.broadcastTokenTransaction(
|
|
267
254
|
tokenTransaction,
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
WalletConfigService,
|
|
4
4
|
type ConnectionManager,
|
|
5
5
|
} from "@buildonspark/spark-sdk";
|
|
6
|
-
import { TokenTransaction as TokenTransactionV0 } from "@buildonspark/spark-sdk/proto/spark";
|
|
7
6
|
import { TokenTransaction } from "@buildonspark/spark-sdk/proto/spark_token";
|
|
8
7
|
import { numberToBytesBE } from "@noble/curves/utils";
|
|
9
8
|
|
|
@@ -15,31 +14,6 @@ export class IssuerTokenTransactionService extends TokenTransactionService {
|
|
|
15
14
|
super(config, connectionManager);
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
async constructMintTokenTransactionV0(
|
|
19
|
-
tokenPublicKey: Uint8Array,
|
|
20
|
-
tokenAmount: bigint,
|
|
21
|
-
): Promise<TokenTransactionV0> {
|
|
22
|
-
return {
|
|
23
|
-
network: this.config.getNetworkProto(),
|
|
24
|
-
tokenInputs: {
|
|
25
|
-
$case: "mintInput",
|
|
26
|
-
mintInput: {
|
|
27
|
-
issuerPublicKey: tokenPublicKey,
|
|
28
|
-
issuerProvidedTimestamp: Date.now(),
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
tokenOutputs: [
|
|
32
|
-
{
|
|
33
|
-
ownerPublicKey: tokenPublicKey,
|
|
34
|
-
tokenPublicKey: tokenPublicKey,
|
|
35
|
-
tokenAmount: numberToBytesBE(tokenAmount, 16),
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
sparkOperatorIdentityPublicKeys:
|
|
39
|
-
super.collectOperatorIdentityPublicKeys(),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
17
|
async constructMintTokenTransaction(
|
|
44
18
|
rawTokenIdentifierBytes: Uint8Array,
|
|
45
19
|
issuerTokenPublicKey: Uint8Array,
|
|
@@ -5,40 +5,25 @@ import {
|
|
|
5
5
|
WalletConfig,
|
|
6
6
|
} from "@buildonspark/spark-sdk";
|
|
7
7
|
import { jest } from "@jest/globals";
|
|
8
|
-
import {
|
|
8
|
+
import { bytesToHex } from "@noble/curves/utils";
|
|
9
9
|
import { IssuerSparkWalletTesting } from "../utils/issuer-test-wallet.js";
|
|
10
10
|
import { SparkWalletTesting } from "../utils/spark-testing-wallet.js";
|
|
11
11
|
import { BitcoinFaucet } from "@buildonspark/spark-sdk/test-utils";
|
|
12
|
+
import { InvoiceStatus } from "@buildonspark/spark-sdk/proto/spark";
|
|
12
13
|
|
|
13
|
-
export const
|
|
14
|
+
export const TOKENS_SCHNORR_CONFIG: Required<ConfigOptions> = {
|
|
14
15
|
...WalletConfig.LOCAL,
|
|
15
|
-
tokenTransactionVersion: "V0",
|
|
16
16
|
tokenSignatures: "SCHNORR",
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const
|
|
20
|
-
...WalletConfig.LOCAL,
|
|
21
|
-
tokenTransactionVersion: "V1",
|
|
22
|
-
tokenSignatures: "SCHNORR",
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const TOKENS_V0_ECDSA_CONFIG: Required<ConfigOptions> = {
|
|
26
|
-
...WalletConfig.LOCAL,
|
|
27
|
-
tokenSignatures: "ECDSA",
|
|
28
|
-
tokenTransactionVersion: "V0",
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const TOKENS_V1_ECDSA_CONFIG: Required<ConfigOptions> = {
|
|
19
|
+
export const TOKENS_ECDSA_CONFIG: Required<ConfigOptions> = {
|
|
32
20
|
...WalletConfig.LOCAL,
|
|
33
21
|
tokenSignatures: "ECDSA",
|
|
34
|
-
tokenTransactionVersion: "V1",
|
|
35
22
|
};
|
|
36
23
|
|
|
37
24
|
const TEST_CONFIGS = [
|
|
38
|
-
{ name: "
|
|
39
|
-
{ name: "
|
|
40
|
-
{ name: "TV1E", config: TOKENS_V1_ECDSA_CONFIG },
|
|
41
|
-
{ name: "TV1S", config: TOKENS_V1_SCHNORR_CONFIG },
|
|
25
|
+
{ name: "TE", config: TOKENS_ECDSA_CONFIG },
|
|
26
|
+
{ name: "TS", config: TOKENS_SCHNORR_CONFIG },
|
|
42
27
|
];
|
|
43
28
|
|
|
44
29
|
const brokenTestFn = process.env.GITHUB_ACTIONS ? it.skip : it;
|
|
@@ -198,8 +183,10 @@ describe.each(TEST_CONFIGS)(
|
|
|
198
183
|
expect(userBalance.balance).toBeGreaterThanOrEqual(tokenAmount);
|
|
199
184
|
});
|
|
200
185
|
|
|
201
|
-
const tv1It = name.startsWith("TV1") ? it.skip : it.skip;
|
|
202
|
-
|
|
186
|
+
// const tv1It = name.startsWith("TV1") ? it.skip : it.skip;
|
|
187
|
+
// TODO: (CNT-493) Re-enable invoice functionality once spark address migration is complete
|
|
188
|
+
const skipInvoiceTest = it.skip;
|
|
189
|
+
skipInvoiceTest("should transfer tokens using spark invoices", async () => {
|
|
203
190
|
const tokenAmount: bigint = 777n;
|
|
204
191
|
const initialIssuerBalance = 100000n;
|
|
205
192
|
|
|
@@ -254,201 +241,217 @@ describe.each(TEST_CONFIGS)(
|
|
|
254
241
|
expect(receiverBalance.balance).toEqual(tokenAmount);
|
|
255
242
|
});
|
|
256
243
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
244
|
+
skipInvoiceTest(
|
|
245
|
+
"should transfer tokens using multiple spark invoices",
|
|
246
|
+
async () => {
|
|
247
|
+
const amount1: bigint = 111n;
|
|
248
|
+
const amount2: bigint = 222n;
|
|
249
|
+
const amount3: bigint = 333n;
|
|
250
|
+
const totalAmount: bigint = amount1 + amount2 + amount3;
|
|
251
|
+
const initialIssuerBalance = 100000n;
|
|
263
252
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
253
|
+
const { wallet: issuerWallet } =
|
|
254
|
+
await IssuerSparkWalletTesting.initialize({
|
|
255
|
+
options: config,
|
|
256
|
+
});
|
|
257
|
+
const { wallet: receiverWallet1 } = await SparkWalletTesting.initialize(
|
|
258
|
+
{
|
|
259
|
+
options: config,
|
|
260
|
+
},
|
|
261
|
+
);
|
|
262
|
+
const { wallet: receiverWallet2 } = await SparkWalletTesting.initialize(
|
|
263
|
+
{
|
|
264
|
+
options: config,
|
|
265
|
+
},
|
|
266
|
+
);
|
|
274
267
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
268
|
+
await issuerWallet.createToken({
|
|
269
|
+
tokenName: `${name}INVM`,
|
|
270
|
+
tokenTicker: "INM",
|
|
271
|
+
decimals: 0,
|
|
272
|
+
isFreezable: false,
|
|
273
|
+
maxSupply: 1_000_000n,
|
|
274
|
+
});
|
|
282
275
|
|
|
283
|
-
|
|
276
|
+
await issuerWallet.mintTokens(initialIssuerBalance);
|
|
284
277
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
278
|
+
const issuerBalanceAfterMint =
|
|
279
|
+
await issuerWallet.getIssuerTokenBalance();
|
|
280
|
+
expect(issuerBalanceAfterMint).toBeDefined();
|
|
281
|
+
expect(issuerBalanceAfterMint.balance).toBe(initialIssuerBalance);
|
|
282
|
+
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier!;
|
|
283
|
+
const issuerBalanceBeforeTransfer = issuerBalanceAfterMint.balance;
|
|
290
284
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
285
|
+
const invoice1 = await receiverWallet1.createTokensInvoice({
|
|
286
|
+
amount: amount1,
|
|
287
|
+
tokenIdentifier,
|
|
288
|
+
memo: "Invoice #1",
|
|
289
|
+
expiryTime: new Date(Date.now() + 1000 * 60 * 60 * 24),
|
|
290
|
+
});
|
|
297
291
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
292
|
+
const invoice2 = await receiverWallet1.createTokensInvoice({
|
|
293
|
+
amount: amount2,
|
|
294
|
+
tokenIdentifier,
|
|
295
|
+
memo: "Invoice #2",
|
|
296
|
+
expiryTime: new Date(Date.now() + 1000 * 60 * 60 * 24),
|
|
297
|
+
});
|
|
304
298
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
299
|
+
const invoice3 = await receiverWallet2.createTokensInvoice({
|
|
300
|
+
amount: amount3,
|
|
301
|
+
tokenIdentifier,
|
|
302
|
+
memo: "Invoice #3",
|
|
303
|
+
expiryTime: new Date(Date.now() + 1000 * 60 * 60 * 24),
|
|
304
|
+
});
|
|
311
305
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
306
|
+
const { tokenTransactionSuccess } =
|
|
307
|
+
await issuerWallet.fulfillSparkInvoice([
|
|
308
|
+
{ invoice: invoice1 },
|
|
309
|
+
{ invoice: invoice2 },
|
|
310
|
+
{ invoice: invoice3 },
|
|
311
|
+
]);
|
|
312
|
+
expect(tokenTransactionSuccess.length).toBe(1);
|
|
313
|
+
expect(tokenTransactionSuccess[0].txid).toBeDefined();
|
|
314
|
+
expect(tokenTransactionSuccess[0].txid.length).toBeGreaterThan(0);
|
|
321
315
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
316
|
+
const issuerBalanceAfter = (await issuerWallet.getIssuerTokenBalance())
|
|
317
|
+
.balance;
|
|
318
|
+
expect(issuerBalanceAfter).toEqual(
|
|
319
|
+
issuerBalanceBeforeTransfer - totalAmount,
|
|
320
|
+
);
|
|
327
321
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
322
|
+
const receiver1BalanceObj = await receiverWallet1.getBalance();
|
|
323
|
+
const receiver1Balance = filterTokenBalanceForTokenIdentifier(
|
|
324
|
+
receiver1BalanceObj?.tokenBalances,
|
|
325
|
+
tokenIdentifier!,
|
|
326
|
+
);
|
|
327
|
+
expect(receiver1Balance.balance).toEqual(amount1 + amount2);
|
|
334
328
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
329
|
+
const receiver2BalanceObj = await receiverWallet2.getBalance();
|
|
330
|
+
const receiver2Balance = filterTokenBalanceForTokenIdentifier(
|
|
331
|
+
receiver2BalanceObj?.tokenBalances,
|
|
332
|
+
tokenIdentifier!,
|
|
333
|
+
);
|
|
334
|
+
expect(receiver2Balance.balance).toEqual(amount3);
|
|
335
|
+
},
|
|
336
|
+
);
|
|
342
337
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
338
|
+
skipInvoiceTest(
|
|
339
|
+
"should fail to fulfill an expired spark invoice",
|
|
340
|
+
async () => {
|
|
341
|
+
const tokenAmount: bigint = 123n;
|
|
342
|
+
const initialIssuerBalance = 100000n;
|
|
346
343
|
|
|
347
|
-
|
|
348
|
-
|
|
344
|
+
const { wallet: issuerWallet } =
|
|
345
|
+
await IssuerSparkWalletTesting.initialize({
|
|
346
|
+
options: config,
|
|
347
|
+
});
|
|
348
|
+
const { wallet: receiverWallet } = await SparkWalletTesting.initialize({
|
|
349
349
|
options: config,
|
|
350
350
|
});
|
|
351
|
-
const { wallet: receiverWallet } = await SparkWalletTesting.initialize({
|
|
352
|
-
options: config,
|
|
353
|
-
});
|
|
354
351
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
352
|
+
await issuerWallet.createToken({
|
|
353
|
+
tokenName: `${name}INVEXP`,
|
|
354
|
+
tokenTicker: "INVX",
|
|
355
|
+
decimals: 0,
|
|
356
|
+
isFreezable: false,
|
|
357
|
+
maxSupply: 1_000_000n,
|
|
358
|
+
});
|
|
362
359
|
|
|
363
|
-
|
|
360
|
+
await issuerWallet.mintTokens(initialIssuerBalance);
|
|
364
361
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
362
|
+
const issuerBalanceAfterMint =
|
|
363
|
+
await issuerWallet.getIssuerTokenBalance();
|
|
364
|
+
expect(issuerBalanceAfterMint).toBeDefined();
|
|
365
|
+
expect(issuerBalanceAfterMint.balance).toBe(initialIssuerBalance);
|
|
366
|
+
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier!;
|
|
367
|
+
const issuerBalanceBefore = issuerBalanceAfterMint.balance;
|
|
370
368
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
369
|
+
const expiredInvoice = await receiverWallet.createTokensInvoice({
|
|
370
|
+
amount: tokenAmount,
|
|
371
|
+
tokenIdentifier,
|
|
372
|
+
memo: "Expired invoice",
|
|
373
|
+
expiryTime: new Date(Date.now() - 60_000),
|
|
374
|
+
});
|
|
377
375
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
376
|
+
const { invalidInvoices } = await issuerWallet.fulfillSparkInvoice([
|
|
377
|
+
{ invoice: expiredInvoice },
|
|
378
|
+
]);
|
|
379
|
+
expect(invalidInvoices.length).toBe(1);
|
|
380
|
+
expect(invalidInvoices[0].invoice).toBe(expiredInvoice);
|
|
383
381
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
382
|
+
const issuerBalanceAfter = (await issuerWallet.getIssuerTokenBalance())
|
|
383
|
+
.balance;
|
|
384
|
+
expect(issuerBalanceAfter).toEqual(issuerBalanceBefore);
|
|
387
385
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
386
|
+
const receiverBalanceObj = await receiverWallet.getBalance();
|
|
387
|
+
const receiverBalance = filterTokenBalanceForTokenIdentifier(
|
|
388
|
+
receiverBalanceObj?.tokenBalances,
|
|
389
|
+
tokenIdentifier!,
|
|
390
|
+
);
|
|
391
|
+
expect(receiverBalance.balance).toEqual(0n);
|
|
392
|
+
},
|
|
393
|
+
);
|
|
395
394
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
395
|
+
skipInvoiceTest(
|
|
396
|
+
"should fulfill a spark invoice with null expiry",
|
|
397
|
+
async () => {
|
|
398
|
+
const tokenAmount: bigint = 321n;
|
|
399
|
+
const initialIssuerBalance = 100000n;
|
|
399
400
|
|
|
400
|
-
|
|
401
|
-
|
|
401
|
+
const { wallet: issuerWallet } =
|
|
402
|
+
await IssuerSparkWalletTesting.initialize({
|
|
403
|
+
options: config,
|
|
404
|
+
});
|
|
405
|
+
const { wallet: receiverWallet } = await SparkWalletTesting.initialize({
|
|
402
406
|
options: config,
|
|
403
407
|
});
|
|
404
|
-
const { wallet: receiverWallet } = await SparkWalletTesting.initialize({
|
|
405
|
-
options: config,
|
|
406
|
-
});
|
|
407
408
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
409
|
+
await issuerWallet.createToken({
|
|
410
|
+
tokenName: `${name}INVNULL`,
|
|
411
|
+
tokenTicker: "INVN",
|
|
412
|
+
decimals: 0,
|
|
413
|
+
isFreezable: false,
|
|
414
|
+
maxSupply: 1_000_000n,
|
|
415
|
+
});
|
|
415
416
|
|
|
416
|
-
|
|
417
|
+
await issuerWallet.mintTokens(initialIssuerBalance);
|
|
417
418
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
419
|
+
const issuerBalanceAfterMint =
|
|
420
|
+
await issuerWallet.getIssuerTokenBalance();
|
|
421
|
+
expect(issuerBalanceAfterMint).toBeDefined();
|
|
422
|
+
expect(issuerBalanceAfterMint.balance).toBe(initialIssuerBalance);
|
|
423
|
+
const tokenIdentifier = issuerBalanceAfterMint.tokenIdentifier!;
|
|
424
|
+
const issuerBalanceBefore = issuerBalanceAfterMint.balance;
|
|
423
425
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
426
|
+
const nullExpiryInvoice = await receiverWallet.createTokensInvoice({
|
|
427
|
+
amount: tokenAmount,
|
|
428
|
+
tokenIdentifier,
|
|
429
|
+
memo: "Null expiry invoice",
|
|
430
|
+
expiryTime: null as unknown as Date,
|
|
431
|
+
});
|
|
430
432
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
433
|
+
const { tokenTransactionSuccess } =
|
|
434
|
+
await issuerWallet.fulfillSparkInvoice([
|
|
435
|
+
{ invoice: nullExpiryInvoice },
|
|
436
|
+
]);
|
|
437
|
+
expect(tokenTransactionSuccess.length).toBe(1);
|
|
438
|
+
expect(tokenTransactionSuccess[0].txid).toBeDefined();
|
|
439
|
+
expect(tokenTransactionSuccess[0].txid.length).toBeGreaterThan(0);
|
|
438
440
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
441
|
+
const issuerBalanceAfter = (await issuerWallet.getIssuerTokenBalance())
|
|
442
|
+
.balance;
|
|
443
|
+
expect(issuerBalanceAfter).toEqual(issuerBalanceBefore - tokenAmount);
|
|
442
444
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
445
|
+
const receiverBalanceObj = await receiverWallet.getBalance();
|
|
446
|
+
const receiverBalance = filterTokenBalanceForTokenIdentifier(
|
|
447
|
+
receiverBalanceObj?.tokenBalances,
|
|
448
|
+
tokenIdentifier!,
|
|
449
|
+
);
|
|
450
|
+
expect(receiverBalance.balance).toEqual(tokenAmount);
|
|
451
|
+
},
|
|
452
|
+
);
|
|
450
453
|
|
|
451
|
-
|
|
454
|
+
skipInvoiceTest(
|
|
452
455
|
"should fulfill a tokens invoice without amount by passing amount parameter",
|
|
453
456
|
async () => {
|
|
454
457
|
const tokenAmount: bigint = 555n;
|
|
@@ -508,7 +511,7 @@ describe.each(TEST_CONFIGS)(
|
|
|
508
511
|
},
|
|
509
512
|
);
|
|
510
513
|
|
|
511
|
-
|
|
514
|
+
skipInvoiceTest(
|
|
512
515
|
`fulfillSparkInvoice successfully handles multiple mixed tokens and sats invoices`,
|
|
513
516
|
async () => {
|
|
514
517
|
const faucet = BitcoinFaucet.getInstance();
|
|
@@ -639,6 +642,26 @@ describe.each(TEST_CONFIGS)(
|
|
|
639
642
|
expect(tokenTransactionSuccess.length).toBe(2); // two token assets - divided into two token transactions
|
|
640
643
|
expect(tokenTransactionErrors.length).toBe(0);
|
|
641
644
|
expect(invalidInvoices.length).toBe(0);
|
|
645
|
+
const invoicesToQuery = [
|
|
646
|
+
invoice1000,
|
|
647
|
+
invoice2000,
|
|
648
|
+
invoiceNilAmount,
|
|
649
|
+
sdkOneTokenInvoiceA,
|
|
650
|
+
sdkOneTokenInvoiceB,
|
|
651
|
+
sdkTwoTokenInvoiceA,
|
|
652
|
+
sdkTwoTokenNilAmountInvoiceB,
|
|
653
|
+
];
|
|
654
|
+
const queryInvoiceResponse = await (sdk as any).querySparkInvoices(
|
|
655
|
+
invoicesToQuery,
|
|
656
|
+
);
|
|
657
|
+
expect(queryInvoiceResponse.invoiceStatuses.length).toBe(7);
|
|
658
|
+
for (let i = 0; i < queryInvoiceResponse.invoiceStatuses.length; i++) {
|
|
659
|
+
const response = queryInvoiceResponse.invoiceStatuses[i];
|
|
660
|
+
const invoiceStatus = response.status;
|
|
661
|
+
expect(invoiceStatus).toBeDefined();
|
|
662
|
+
expect(invoiceStatus).toBe(InvoiceStatus.FINALIZED);
|
|
663
|
+
expect(response.invoice).toBe(invoicesToQuery[i]);
|
|
664
|
+
}
|
|
642
665
|
},
|
|
643
666
|
);
|
|
644
667
|
|