@buildonspark/issuer-sdk 0.1.0 → 0.1.2

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 CHANGED
@@ -1,5 +1,28 @@
1
1
  # @buildonspark/issuer-sdk
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - **getIssuerTokenMetadata()**
8
+ - Convert extraMetadata from Buffer to Uint8Array for better cross-platform compatibility. Returns undefined when no metadata is present instead of an empty buffer on getIssuerTokenMetadata()
9
+
10
+ - Updated dependencies
11
+ - @buildonspark/spark-sdk@0.5.2
12
+
13
+ ## 0.1.1
14
+
15
+ ### Patch Changes
16
+
17
+ - **Token transaction v3**
18
+ - Updated test configs and expanded test coverage to include both v2 and v3 token transactions
19
+
20
+ **Extra metadata field available when creating new tokens**
21
+ - Added a field to accept additional bytes data to attach to token creates
22
+
23
+ - Updated dependencies
24
+ - @buildonspark/spark-sdk@0.5.1
25
+
3
26
  ## 0.1.0
4
27
 
5
28
  ### Minor Changes
@@ -38,6 +38,8 @@ type IssuerTokenMetadata = {
38
38
  maxSupply: bigint;
39
39
  /** Whether the token is freezable */
40
40
  isFreezable: boolean;
41
+ /** Extra metadata of the token */
42
+ extraMetadata?: Uint8Array;
41
43
  };
42
44
  interface TokenDistribution {
43
45
  totalCirculatingSupply: bigint;
@@ -90,18 +92,20 @@ declare abstract class IssuerSparkWallet extends SparkWallet {
90
92
  * @param params.decimals - The number of decimal places for the token.
91
93
  * @param params.isFreezable - Whether the token can be frozen.
92
94
  * @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
95
+ * @param params.extraMetadata - (Optional) This can be used to store additional bytes data to be associated with a token, like image data.
93
96
  *
94
97
  * @returns The transaction ID of the announcement.
95
98
  *
96
99
  * @throws {SparkValidationError} If `decimals` is not a safe integer or other validation fails.
97
100
  * @throws {SparkRequestError} If the announcement transaction cannot be broadcast.
98
101
  */
99
- createToken({ tokenName, tokenTicker, decimals, isFreezable, maxSupply, }: {
102
+ createToken({ tokenName, tokenTicker, decimals, isFreezable, maxSupply, extraMetadata, }: {
100
103
  tokenName: string;
101
104
  tokenTicker: string;
102
105
  decimals: number;
103
106
  isFreezable: boolean;
104
107
  maxSupply?: bigint;
108
+ extraMetadata?: Uint8Array;
105
109
  }): Promise<string>;
106
110
  /**
107
111
  * Mints new tokens
@@ -210,7 +210,7 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
210
210
  ]
211
211
  };
212
212
  }
213
- async constructCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable) {
213
+ async constructCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable, extraMetadata) {
214
214
  return {
215
215
  version: 2,
216
216
  network: this.config.getNetworkProto(),
@@ -222,7 +222,8 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
222
222
  tokenTicker,
223
223
  decimals,
224
224
  maxSupply: numberToBytesBE(maxSupply, 16),
225
- isFreezable
225
+ isFreezable,
226
+ extraMetadata
226
227
  }
227
228
  },
228
229
  tokenOutputs: [],
@@ -232,7 +233,7 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
232
233
  invoiceAttachments: []
233
234
  };
234
235
  }
235
- async constructPartialCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable) {
236
+ async constructPartialCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable, extraMetadata) {
236
237
  return {
237
238
  version: 3,
238
239
  tokenTransactionMetadata: {
@@ -250,7 +251,8 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
250
251
  tokenTicker,
251
252
  decimals,
252
253
  maxSupply: numberToBytesBE(maxSupply, 16),
253
- isFreezable
254
+ isFreezable,
255
+ extraMetadata
254
256
  }
255
257
  },
256
258
  partialTokenOutputs: []
@@ -269,7 +271,8 @@ var MIN_SYMBOL_SIZE = 3;
269
271
  var MAX_SYMBOL_SIZE = 6;
270
272
  var MAX_DECIMALS = 255;
271
273
  var MAXIMUM_MAX_SUPPLY = (1n << 128n) - 1n;
272
- function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply) {
274
+ var MAX_TOKEN_CONTENT_SIZE = 1024;
275
+ function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply, extraMetadata) {
273
276
  if (!isNfcNormalized(tokenName)) {
274
277
  throw new SparkValidationError2("Token name must be NFC-normalised UTF-8", {
275
278
  field: "tokenName",
@@ -328,6 +331,16 @@ function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply) {
328
331
  expected: `>=0 and <=${MAXIMUM_MAX_SUPPLY.toString()}`
329
332
  });
330
333
  }
334
+ if (extraMetadata && extraMetadata.length > MAX_TOKEN_CONTENT_SIZE) {
335
+ throw new SparkValidationError2(
336
+ `Extra metadata must be less than ${MAX_TOKEN_CONTENT_SIZE} bytes`,
337
+ {
338
+ field: "extraMetadata",
339
+ value: extraMetadata.length,
340
+ expected: `<${MAX_TOKEN_CONTENT_SIZE}`
341
+ }
342
+ );
343
+ }
331
344
  }
332
345
 
333
346
  // src/issuer-wallet/issuer-spark-wallet.ts
@@ -393,7 +406,8 @@ var IssuerSparkWallet = class extends SparkWallet {
393
406
  tokenTicker: metadata.tokenTicker,
394
407
  decimals: metadata.decimals,
395
408
  maxSupply: bytesToNumberBE(metadata.maxSupply),
396
- isFreezable: metadata.isFreezable
409
+ isFreezable: metadata.isFreezable,
410
+ extraMetadata: metadata.extraMetadata ? new Uint8Array(metadata.extraMetadata) : void 0
397
411
  };
398
412
  }
399
413
  const sparkTokenClient = await this.connectionManager.createSparkTokenClient(
@@ -428,7 +442,8 @@ var IssuerSparkWallet = class extends SparkWallet {
428
442
  tokenTicker: metadata.tokenTicker,
429
443
  decimals: metadata.decimals,
430
444
  maxSupply: bytesToNumberBE(metadata.maxSupply),
431
- isFreezable: metadata.isFreezable
445
+ isFreezable: metadata.isFreezable,
446
+ extraMetadata: metadata.extraMetadata
432
447
  };
433
448
  } catch (error) {
434
449
  throw new SparkRequestError2("Failed to fetch token metadata", { error });
@@ -455,6 +470,7 @@ var IssuerSparkWallet = class extends SparkWallet {
455
470
  * @param params.decimals - The number of decimal places for the token.
456
471
  * @param params.isFreezable - Whether the token can be frozen.
457
472
  * @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
473
+ * @param params.extraMetadata - (Optional) This can be used to store additional bytes data to be associated with a token, like image data.
458
474
  *
459
475
  * @returns The transaction ID of the announcement.
460
476
  *
@@ -466,9 +482,16 @@ var IssuerSparkWallet = class extends SparkWallet {
466
482
  tokenTicker,
467
483
  decimals,
468
484
  isFreezable,
469
- maxSupply = 0n
485
+ maxSupply = 0n,
486
+ extraMetadata
470
487
  }) {
471
- validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply);
488
+ validateTokenParameters(
489
+ tokenName,
490
+ tokenTicker,
491
+ decimals,
492
+ maxSupply,
493
+ extraMetadata
494
+ );
472
495
  const issuerPublicKey = await super.getIdentityPublicKey();
473
496
  if (this.config.getTokenTransactionVersion() === "V2") {
474
497
  const tokenTransaction = await this.issuerTokenTransactionService.constructCreateTokenTransaction(
@@ -477,7 +500,8 @@ var IssuerSparkWallet = class extends SparkWallet {
477
500
  tokenTicker,
478
501
  decimals,
479
502
  maxSupply,
480
- isFreezable
503
+ isFreezable,
504
+ extraMetadata
481
505
  );
482
506
  return await this.issuerTokenTransactionService.broadcastTokenTransaction(
483
507
  tokenTransaction
@@ -489,7 +513,8 @@ var IssuerSparkWallet = class extends SparkWallet {
489
513
  tokenTicker,
490
514
  decimals,
491
515
  maxSupply,
492
- isFreezable
516
+ isFreezable,
517
+ extraMetadata
493
518
  );
494
519
  return await this.issuerTokenTransactionService.broadcastTokenTransactionV3(
495
520
  partialTokenTransaction
@@ -225,7 +225,7 @@ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransac
225
225
  ]
226
226
  };
227
227
  }
228
- async constructCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable) {
228
+ async constructCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable, extraMetadata) {
229
229
  return {
230
230
  version: 2,
231
231
  network: this.config.getNetworkProto(),
@@ -237,7 +237,8 @@ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransac
237
237
  tokenTicker,
238
238
  decimals,
239
239
  maxSupply: (0, import_utils3.numberToBytesBE)(maxSupply, 16),
240
- isFreezable
240
+ isFreezable,
241
+ extraMetadata
241
242
  }
242
243
  },
243
244
  tokenOutputs: [],
@@ -247,7 +248,7 @@ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransac
247
248
  invoiceAttachments: []
248
249
  };
249
250
  }
250
- async constructPartialCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable) {
251
+ async constructPartialCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable, extraMetadata) {
251
252
  return {
252
253
  version: 3,
253
254
  tokenTransactionMetadata: {
@@ -265,7 +266,8 @@ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransac
265
266
  tokenTicker,
266
267
  decimals,
267
268
  maxSupply: (0, import_utils3.numberToBytesBE)(maxSupply, 16),
268
- isFreezable
269
+ isFreezable,
270
+ extraMetadata
269
271
  }
270
272
  },
271
273
  partialTokenOutputs: []
@@ -284,7 +286,8 @@ var MIN_SYMBOL_SIZE = 3;
284
286
  var MAX_SYMBOL_SIZE = 6;
285
287
  var MAX_DECIMALS = 255;
286
288
  var MAXIMUM_MAX_SUPPLY = (1n << 128n) - 1n;
287
- function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply) {
289
+ var MAX_TOKEN_CONTENT_SIZE = 1024;
290
+ function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply, extraMetadata) {
288
291
  if (!isNfcNormalized(tokenName)) {
289
292
  throw new import_spark_sdk4.SparkValidationError("Token name must be NFC-normalised UTF-8", {
290
293
  field: "tokenName",
@@ -343,6 +346,16 @@ function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply) {
343
346
  expected: `>=0 and <=${MAXIMUM_MAX_SUPPLY.toString()}`
344
347
  });
345
348
  }
349
+ if (extraMetadata && extraMetadata.length > MAX_TOKEN_CONTENT_SIZE) {
350
+ throw new import_spark_sdk4.SparkValidationError(
351
+ `Extra metadata must be less than ${MAX_TOKEN_CONTENT_SIZE} bytes`,
352
+ {
353
+ field: "extraMetadata",
354
+ value: extraMetadata.length,
355
+ expected: `<${MAX_TOKEN_CONTENT_SIZE}`
356
+ }
357
+ );
358
+ }
346
359
  }
347
360
 
348
361
  // src/issuer-wallet/issuer-spark-wallet.ts
@@ -408,7 +421,8 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
408
421
  tokenTicker: metadata.tokenTicker,
409
422
  decimals: metadata.decimals,
410
423
  maxSupply: (0, import_utils4.bytesToNumberBE)(metadata.maxSupply),
411
- isFreezable: metadata.isFreezable
424
+ isFreezable: metadata.isFreezable,
425
+ extraMetadata: metadata.extraMetadata ? new Uint8Array(metadata.extraMetadata) : void 0
412
426
  };
413
427
  }
414
428
  const sparkTokenClient = await this.connectionManager.createSparkTokenClient(
@@ -443,7 +457,8 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
443
457
  tokenTicker: metadata.tokenTicker,
444
458
  decimals: metadata.decimals,
445
459
  maxSupply: (0, import_utils4.bytesToNumberBE)(metadata.maxSupply),
446
- isFreezable: metadata.isFreezable
460
+ isFreezable: metadata.isFreezable,
461
+ extraMetadata: metadata.extraMetadata
447
462
  };
448
463
  } catch (error) {
449
464
  throw new import_spark_sdk5.SparkRequestError("Failed to fetch token metadata", { error });
@@ -470,6 +485,7 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
470
485
  * @param params.decimals - The number of decimal places for the token.
471
486
  * @param params.isFreezable - Whether the token can be frozen.
472
487
  * @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
488
+ * @param params.extraMetadata - (Optional) This can be used to store additional bytes data to be associated with a token, like image data.
473
489
  *
474
490
  * @returns The transaction ID of the announcement.
475
491
  *
@@ -481,9 +497,16 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
481
497
  tokenTicker,
482
498
  decimals,
483
499
  isFreezable,
484
- maxSupply = 0n
500
+ maxSupply = 0n,
501
+ extraMetadata
485
502
  }) {
486
- validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply);
503
+ validateTokenParameters(
504
+ tokenName,
505
+ tokenTicker,
506
+ decimals,
507
+ maxSupply,
508
+ extraMetadata
509
+ );
487
510
  const issuerPublicKey = await super.getIdentityPublicKey();
488
511
  if (this.config.getTokenTransactionVersion() === "V2") {
489
512
  const tokenTransaction = await this.issuerTokenTransactionService.constructCreateTokenTransaction(
@@ -492,7 +515,8 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
492
515
  tokenTicker,
493
516
  decimals,
494
517
  maxSupply,
495
- isFreezable
518
+ isFreezable,
519
+ extraMetadata
496
520
  );
497
521
  return await this.issuerTokenTransactionService.broadcastTokenTransaction(
498
522
  tokenTransaction
@@ -504,7 +528,8 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
504
528
  tokenTicker,
505
529
  decimals,
506
530
  maxSupply,
507
- isFreezable
531
+ isFreezable,
532
+ extraMetadata
508
533
  );
509
534
  return await this.issuerTokenTransactionService.broadcastTokenTransactionV3(
510
535
  partialTokenTransaction
@@ -38,6 +38,8 @@ type IssuerTokenMetadata = {
38
38
  maxSupply: bigint;
39
39
  /** Whether the token is freezable */
40
40
  isFreezable: boolean;
41
+ /** Extra metadata of the token */
42
+ extraMetadata?: Uint8Array;
41
43
  };
42
44
  interface TokenDistribution {
43
45
  totalCirculatingSupply: bigint;
@@ -90,18 +92,20 @@ declare abstract class IssuerSparkWallet extends SparkWallet {
90
92
  * @param params.decimals - The number of decimal places for the token.
91
93
  * @param params.isFreezable - Whether the token can be frozen.
92
94
  * @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
95
+ * @param params.extraMetadata - (Optional) This can be used to store additional bytes data to be associated with a token, like image data.
93
96
  *
94
97
  * @returns The transaction ID of the announcement.
95
98
  *
96
99
  * @throws {SparkValidationError} If `decimals` is not a safe integer or other validation fails.
97
100
  * @throws {SparkRequestError} If the announcement transaction cannot be broadcast.
98
101
  */
99
- createToken({ tokenName, tokenTicker, decimals, isFreezable, maxSupply, }: {
102
+ createToken({ tokenName, tokenTicker, decimals, isFreezable, maxSupply, extraMetadata, }: {
100
103
  tokenName: string;
101
104
  tokenTicker: string;
102
105
  decimals: number;
103
106
  isFreezable: boolean;
104
107
  maxSupply?: bigint;
108
+ extraMetadata?: Uint8Array;
105
109
  }): Promise<string>;
106
110
  /**
107
111
  * Mints new tokens
@@ -38,6 +38,8 @@ type IssuerTokenMetadata = {
38
38
  maxSupply: bigint;
39
39
  /** Whether the token is freezable */
40
40
  isFreezable: boolean;
41
+ /** Extra metadata of the token */
42
+ extraMetadata?: Uint8Array;
41
43
  };
42
44
  interface TokenDistribution {
43
45
  totalCirculatingSupply: bigint;
@@ -90,18 +92,20 @@ declare abstract class IssuerSparkWallet extends SparkWallet {
90
92
  * @param params.decimals - The number of decimal places for the token.
91
93
  * @param params.isFreezable - Whether the token can be frozen.
92
94
  * @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
95
+ * @param params.extraMetadata - (Optional) This can be used to store additional bytes data to be associated with a token, like image data.
93
96
  *
94
97
  * @returns The transaction ID of the announcement.
95
98
  *
96
99
  * @throws {SparkValidationError} If `decimals` is not a safe integer or other validation fails.
97
100
  * @throws {SparkRequestError} If the announcement transaction cannot be broadcast.
98
101
  */
99
- createToken({ tokenName, tokenTicker, decimals, isFreezable, maxSupply, }: {
102
+ createToken({ tokenName, tokenTicker, decimals, isFreezable, maxSupply, extraMetadata, }: {
100
103
  tokenName: string;
101
104
  tokenTicker: string;
102
105
  decimals: number;
103
106
  isFreezable: boolean;
104
107
  maxSupply?: bigint;
108
+ extraMetadata?: Uint8Array;
105
109
  }): Promise<string>;
106
110
  /**
107
111
  * Mints new tokens
@@ -200,7 +200,7 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
200
200
  ]
201
201
  };
202
202
  }
203
- async constructCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable) {
203
+ async constructCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable, extraMetadata) {
204
204
  return {
205
205
  version: 2,
206
206
  network: this.config.getNetworkProto(),
@@ -212,7 +212,8 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
212
212
  tokenTicker,
213
213
  decimals,
214
214
  maxSupply: numberToBytesBE(maxSupply, 16),
215
- isFreezable
215
+ isFreezable,
216
+ extraMetadata
216
217
  }
217
218
  },
218
219
  tokenOutputs: [],
@@ -222,7 +223,7 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
222
223
  invoiceAttachments: []
223
224
  };
224
225
  }
225
- async constructPartialCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable) {
226
+ async constructPartialCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable, extraMetadata) {
226
227
  return {
227
228
  version: 3,
228
229
  tokenTransactionMetadata: {
@@ -240,7 +241,8 @@ var IssuerTokenTransactionService = class extends TokenTransactionService {
240
241
  tokenTicker,
241
242
  decimals,
242
243
  maxSupply: numberToBytesBE(maxSupply, 16),
243
- isFreezable
244
+ isFreezable,
245
+ extraMetadata
244
246
  }
245
247
  },
246
248
  partialTokenOutputs: []
@@ -259,7 +261,8 @@ var MIN_SYMBOL_SIZE = 3;
259
261
  var MAX_SYMBOL_SIZE = 6;
260
262
  var MAX_DECIMALS = 255;
261
263
  var MAXIMUM_MAX_SUPPLY = (1n << 128n) - 1n;
262
- function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply) {
264
+ var MAX_TOKEN_CONTENT_SIZE = 1024;
265
+ function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply, extraMetadata) {
263
266
  if (!isNfcNormalized(tokenName)) {
264
267
  throw new SparkValidationError2("Token name must be NFC-normalised UTF-8", {
265
268
  field: "tokenName",
@@ -318,6 +321,16 @@ function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply) {
318
321
  expected: `>=0 and <=${MAXIMUM_MAX_SUPPLY.toString()}`
319
322
  });
320
323
  }
324
+ if (extraMetadata && extraMetadata.length > MAX_TOKEN_CONTENT_SIZE) {
325
+ throw new SparkValidationError2(
326
+ `Extra metadata must be less than ${MAX_TOKEN_CONTENT_SIZE} bytes`,
327
+ {
328
+ field: "extraMetadata",
329
+ value: extraMetadata.length,
330
+ expected: `<${MAX_TOKEN_CONTENT_SIZE}`
331
+ }
332
+ );
333
+ }
321
334
  }
322
335
 
323
336
  // src/issuer-wallet/issuer-spark-wallet.ts
@@ -383,7 +396,8 @@ var IssuerSparkWallet = class extends SparkWallet {
383
396
  tokenTicker: metadata.tokenTicker,
384
397
  decimals: metadata.decimals,
385
398
  maxSupply: bytesToNumberBE(metadata.maxSupply),
386
- isFreezable: metadata.isFreezable
399
+ isFreezable: metadata.isFreezable,
400
+ extraMetadata: metadata.extraMetadata ? new Uint8Array(metadata.extraMetadata) : void 0
387
401
  };
388
402
  }
389
403
  const sparkTokenClient = await this.connectionManager.createSparkTokenClient(
@@ -418,7 +432,8 @@ var IssuerSparkWallet = class extends SparkWallet {
418
432
  tokenTicker: metadata.tokenTicker,
419
433
  decimals: metadata.decimals,
420
434
  maxSupply: bytesToNumberBE(metadata.maxSupply),
421
- isFreezable: metadata.isFreezable
435
+ isFreezable: metadata.isFreezable,
436
+ extraMetadata: metadata.extraMetadata
422
437
  };
423
438
  } catch (error) {
424
439
  throw new SparkRequestError2("Failed to fetch token metadata", { error });
@@ -445,6 +460,7 @@ var IssuerSparkWallet = class extends SparkWallet {
445
460
  * @param params.decimals - The number of decimal places for the token.
446
461
  * @param params.isFreezable - Whether the token can be frozen.
447
462
  * @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
463
+ * @param params.extraMetadata - (Optional) This can be used to store additional bytes data to be associated with a token, like image data.
448
464
  *
449
465
  * @returns The transaction ID of the announcement.
450
466
  *
@@ -456,9 +472,16 @@ var IssuerSparkWallet = class extends SparkWallet {
456
472
  tokenTicker,
457
473
  decimals,
458
474
  isFreezable,
459
- maxSupply = 0n
475
+ maxSupply = 0n,
476
+ extraMetadata
460
477
  }) {
461
- validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply);
478
+ validateTokenParameters(
479
+ tokenName,
480
+ tokenTicker,
481
+ decimals,
482
+ maxSupply,
483
+ extraMetadata
484
+ );
462
485
  const issuerPublicKey = await super.getIdentityPublicKey();
463
486
  if (this.config.getTokenTransactionVersion() === "V2") {
464
487
  const tokenTransaction = await this.issuerTokenTransactionService.constructCreateTokenTransaction(
@@ -467,7 +490,8 @@ var IssuerSparkWallet = class extends SparkWallet {
467
490
  tokenTicker,
468
491
  decimals,
469
492
  maxSupply,
470
- isFreezable
493
+ isFreezable,
494
+ extraMetadata
471
495
  );
472
496
  return await this.issuerTokenTransactionService.broadcastTokenTransaction(
473
497
  tokenTransaction
@@ -479,7 +503,8 @@ var IssuerSparkWallet = class extends SparkWallet {
479
503
  tokenTicker,
480
504
  decimals,
481
505
  maxSupply,
482
- isFreezable
506
+ isFreezable,
507
+ extraMetadata
483
508
  );
484
509
  return await this.issuerTokenTransactionService.broadcastTokenTransactionV3(
485
510
  partialTokenTransaction
@@ -228,7 +228,7 @@ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransac
228
228
  ]
229
229
  };
230
230
  }
231
- async constructCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable) {
231
+ async constructCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable, extraMetadata) {
232
232
  return {
233
233
  version: 2,
234
234
  network: this.config.getNetworkProto(),
@@ -240,7 +240,8 @@ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransac
240
240
  tokenTicker,
241
241
  decimals,
242
242
  maxSupply: (0, import_utils3.numberToBytesBE)(maxSupply, 16),
243
- isFreezable
243
+ isFreezable,
244
+ extraMetadata
244
245
  }
245
246
  },
246
247
  tokenOutputs: [],
@@ -250,7 +251,7 @@ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransac
250
251
  invoiceAttachments: []
251
252
  };
252
253
  }
253
- async constructPartialCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable) {
254
+ async constructPartialCreateTokenTransaction(tokenPublicKey, tokenName, tokenTicker, decimals, maxSupply, isFreezable, extraMetadata) {
254
255
  return {
255
256
  version: 3,
256
257
  tokenTransactionMetadata: {
@@ -268,7 +269,8 @@ var IssuerTokenTransactionService = class extends import_spark_sdk3.TokenTransac
268
269
  tokenTicker,
269
270
  decimals,
270
271
  maxSupply: (0, import_utils3.numberToBytesBE)(maxSupply, 16),
271
- isFreezable
272
+ isFreezable,
273
+ extraMetadata
272
274
  }
273
275
  },
274
276
  partialTokenOutputs: []
@@ -287,7 +289,8 @@ var MIN_SYMBOL_SIZE = 3;
287
289
  var MAX_SYMBOL_SIZE = 6;
288
290
  var MAX_DECIMALS = 255;
289
291
  var MAXIMUM_MAX_SUPPLY = (1n << 128n) - 1n;
290
- function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply) {
292
+ var MAX_TOKEN_CONTENT_SIZE = 1024;
293
+ function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply, extraMetadata) {
291
294
  if (!isNfcNormalized(tokenName)) {
292
295
  throw new import_spark_sdk4.SparkValidationError("Token name must be NFC-normalised UTF-8", {
293
296
  field: "tokenName",
@@ -346,6 +349,16 @@ function validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply) {
346
349
  expected: `>=0 and <=${MAXIMUM_MAX_SUPPLY.toString()}`
347
350
  });
348
351
  }
352
+ if (extraMetadata && extraMetadata.length > MAX_TOKEN_CONTENT_SIZE) {
353
+ throw new import_spark_sdk4.SparkValidationError(
354
+ `Extra metadata must be less than ${MAX_TOKEN_CONTENT_SIZE} bytes`,
355
+ {
356
+ field: "extraMetadata",
357
+ value: extraMetadata.length,
358
+ expected: `<${MAX_TOKEN_CONTENT_SIZE}`
359
+ }
360
+ );
361
+ }
349
362
  }
350
363
 
351
364
  // src/issuer-wallet/issuer-spark-wallet.ts
@@ -411,7 +424,8 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
411
424
  tokenTicker: metadata.tokenTicker,
412
425
  decimals: metadata.decimals,
413
426
  maxSupply: (0, import_utils4.bytesToNumberBE)(metadata.maxSupply),
414
- isFreezable: metadata.isFreezable
427
+ isFreezable: metadata.isFreezable,
428
+ extraMetadata: metadata.extraMetadata ? new Uint8Array(metadata.extraMetadata) : void 0
415
429
  };
416
430
  }
417
431
  const sparkTokenClient = await this.connectionManager.createSparkTokenClient(
@@ -446,7 +460,8 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
446
460
  tokenTicker: metadata.tokenTicker,
447
461
  decimals: metadata.decimals,
448
462
  maxSupply: (0, import_utils4.bytesToNumberBE)(metadata.maxSupply),
449
- isFreezable: metadata.isFreezable
463
+ isFreezable: metadata.isFreezable,
464
+ extraMetadata: metadata.extraMetadata
450
465
  };
451
466
  } catch (error) {
452
467
  throw new import_spark_sdk5.SparkRequestError("Failed to fetch token metadata", { error });
@@ -473,6 +488,7 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
473
488
  * @param params.decimals - The number of decimal places for the token.
474
489
  * @param params.isFreezable - Whether the token can be frozen.
475
490
  * @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
491
+ * @param params.extraMetadata - (Optional) This can be used to store additional bytes data to be associated with a token, like image data.
476
492
  *
477
493
  * @returns The transaction ID of the announcement.
478
494
  *
@@ -484,9 +500,16 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
484
500
  tokenTicker,
485
501
  decimals,
486
502
  isFreezable,
487
- maxSupply = 0n
503
+ maxSupply = 0n,
504
+ extraMetadata
488
505
  }) {
489
- validateTokenParameters(tokenName, tokenTicker, decimals, maxSupply);
506
+ validateTokenParameters(
507
+ tokenName,
508
+ tokenTicker,
509
+ decimals,
510
+ maxSupply,
511
+ extraMetadata
512
+ );
490
513
  const issuerPublicKey = await super.getIdentityPublicKey();
491
514
  if (this.config.getTokenTransactionVersion() === "V2") {
492
515
  const tokenTransaction = await this.issuerTokenTransactionService.constructCreateTokenTransaction(
@@ -495,7 +518,8 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
495
518
  tokenTicker,
496
519
  decimals,
497
520
  maxSupply,
498
- isFreezable
521
+ isFreezable,
522
+ extraMetadata
499
523
  );
500
524
  return await this.issuerTokenTransactionService.broadcastTokenTransaction(
501
525
  tokenTransaction
@@ -507,7 +531,8 @@ var IssuerSparkWallet = class extends import_spark_sdk5.SparkWallet {
507
531
  tokenTicker,
508
532
  decimals,
509
533
  maxSupply,
510
- isFreezable
534
+ isFreezable,
535
+ extraMetadata
511
536
  );
512
537
  return await this.issuerTokenTransactionService.broadcastTokenTransactionV3(
513
538
  partialTokenTransaction
@@ -38,6 +38,8 @@ type IssuerTokenMetadata = {
38
38
  maxSupply: bigint;
39
39
  /** Whether the token is freezable */
40
40
  isFreezable: boolean;
41
+ /** Extra metadata of the token */
42
+ extraMetadata?: Uint8Array;
41
43
  };
42
44
  interface TokenDistribution {
43
45
  totalCirculatingSupply: bigint;
@@ -90,18 +92,20 @@ declare abstract class IssuerSparkWallet extends SparkWallet {
90
92
  * @param params.decimals - The number of decimal places for the token.
91
93
  * @param params.isFreezable - Whether the token can be frozen.
92
94
  * @param [params.maxSupply=0n] - (Optional) The maximum supply of the token. Defaults to <code>0n</code>.
95
+ * @param params.extraMetadata - (Optional) This can be used to store additional bytes data to be associated with a token, like image data.
93
96
  *
94
97
  * @returns The transaction ID of the announcement.
95
98
  *
96
99
  * @throws {SparkValidationError} If `decimals` is not a safe integer or other validation fails.
97
100
  * @throws {SparkRequestError} If the announcement transaction cannot be broadcast.
98
101
  */
99
- createToken({ tokenName, tokenTicker, decimals, isFreezable, maxSupply, }: {
102
+ createToken({ tokenName, tokenTicker, decimals, isFreezable, maxSupply, extraMetadata, }: {
100
103
  tokenName: string;
101
104
  tokenTicker: string;
102
105
  decimals: number;
103
106
  isFreezable: boolean;
104
107
  maxSupply?: bigint;
108
+ extraMetadata?: Uint8Array;
105
109
  }): Promise<string>;
106
110
  /**
107
111
  * Mints new tokens