@neuraiproject/neurai-assets 1.2.0 → 1.2.1

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.
@@ -4172,7 +4172,7 @@ var NeuraiAssetsBundle = (function (exports) {
4172
4172
  addresses === undefined
4173
4173
  ) {
4174
4174
  network = networkOrParams.network;
4175
- actualAddresses = networkOrParams.addresses;
4175
+ actualAddresses = networkOrParams.walletAddresses || networkOrParams.addresses;
4176
4176
  actualParams = networkOrParams;
4177
4177
  } else {
4178
4178
  network = networkOrParams;
@@ -4395,6 +4395,142 @@ var NeuraiAssetsBundle = (function (exports) {
4395
4395
  return satoshis / Math.pow(10, units);
4396
4396
  }
4397
4397
 
4398
+ /**
4399
+ * Normalize builder inputs to raw transaction inputs
4400
+ * @param {Array} inputs - Builder inputs
4401
+ * @returns {Array<{txid: string, vout: number}>} Raw transaction inputs
4402
+ */
4403
+ toRawTxInputs(inputs) {
4404
+ return (inputs || []).map(input => ({
4405
+ txid: input.txid,
4406
+ vout: input.vout !== undefined ? input.vout : input.outputIndex
4407
+ }));
4408
+ }
4409
+
4410
+ /**
4411
+ * Convert XNA amount to satoshis
4412
+ * @param {number|null|undefined} amount - Amount in XNA
4413
+ * @returns {number|undefined} Amount in satoshis
4414
+ */
4415
+ xnaToSatoshis(amount) {
4416
+ if (amount === undefined || amount === null) {
4417
+ return undefined;
4418
+ }
4419
+
4420
+ return Math.round(amount * 100000000);
4421
+ }
4422
+
4423
+ /**
4424
+ * Build a typed local raw build payload compatible with
4425
+ * @neuraiproject/neurai-create-transaction createFromOperation(...)
4426
+ *
4427
+ * @param {string} operationType - Operation type
4428
+ * @param {Array} inputs - Builder inputs
4429
+ * @param {object|null} burnInfo - Burn metadata
4430
+ * @param {string|null} changeAddress - XNA change address
4431
+ * @param {number|null} changeAmount - XNA change amount in XNA
4432
+ * @param {object} operationParams - Operation-specific params
4433
+ * @returns {{ operationType: string, params: object }} Local raw build
4434
+ */
4435
+ buildLocalRawBuild(
4436
+ operationType,
4437
+ inputs,
4438
+ burnInfo = null,
4439
+ changeAddress = null,
4440
+ changeAmount = null,
4441
+ operationParams = {}
4442
+ ) {
4443
+ const params = {
4444
+ inputs: this.toRawTxInputs(inputs),
4445
+ ...operationParams
4446
+ };
4447
+
4448
+ if (burnInfo && burnInfo.address && burnInfo.amount !== undefined && burnInfo.amount !== null) {
4449
+ params.burnAddress = burnInfo.address;
4450
+ params.burnAmountSats = this.xnaToSatoshis(burnInfo.amount);
4451
+ }
4452
+
4453
+ if (changeAddress && changeAmount !== undefined && changeAmount !== null) {
4454
+ params.xnaChangeAddress = changeAddress;
4455
+ params.xnaChangeSats = this.xnaToSatoshis(changeAmount);
4456
+ }
4457
+
4458
+ return {
4459
+ operationType,
4460
+ params
4461
+ };
4462
+ }
4463
+
4464
+ /**
4465
+ * Normalize ordered outputs into flat entries
4466
+ * @param {Array|object} outputs - Transaction outputs
4467
+ * @returns {Array<{address: string, value: unknown}>} Output entries
4468
+ */
4469
+ getOutputEntries(outputs) {
4470
+ if (Array.isArray(outputs)) {
4471
+ return outputs.map(output => {
4472
+ const [address, value] = Object.entries(output)[0];
4473
+ return { address, value };
4474
+ });
4475
+ }
4476
+
4477
+ if (outputs && typeof outputs === 'object') {
4478
+ return Object.entries(outputs).map(([address, value]) => ({ address, value }));
4479
+ }
4480
+
4481
+ return [];
4482
+ }
4483
+
4484
+ /**
4485
+ * Extract burn metadata from outputs
4486
+ * @param {Array<{address: string, value: unknown}>} entries - Output entries
4487
+ * @param {number} burnAmount - Burn amount in XNA
4488
+ * @returns {{ burnAddress: string|null, burnAmount: number }}
4489
+ */
4490
+ extractBurnMetadata(entries, burnAmount) {
4491
+ if (!burnAmount || burnAmount <= 0) {
4492
+ return {
4493
+ burnAddress: null,
4494
+ burnAmount: 0
4495
+ };
4496
+ }
4497
+
4498
+ const burnEntry = entries.find(({ address, value }) => {
4499
+ return typeof value === 'number' &&
4500
+ value === burnAmount &&
4501
+ this.burnManager.isBurnAddress(address);
4502
+ });
4503
+
4504
+ return {
4505
+ burnAddress: burnEntry ? burnEntry.address : null,
4506
+ burnAmount
4507
+ };
4508
+ }
4509
+
4510
+ /**
4511
+ * Extract XNA change metadata from outputs
4512
+ * @param {Array<{address: string, value: unknown}>} entries - Output entries
4513
+ * @param {string|null} burnAddress - Burn address if present
4514
+ * @returns {{ changeAddress: string|null, changeAmount: number|null }}
4515
+ */
4516
+ extractChangeMetadata(entries, burnAddress = null) {
4517
+ const xnaOutputs = entries.filter(({ address, value }) => {
4518
+ return typeof value === 'number' && address !== burnAddress;
4519
+ });
4520
+
4521
+ if (xnaOutputs.length !== 1) {
4522
+ return {
4523
+ changeAddress: null,
4524
+ changeAmount: null
4525
+ };
4526
+ }
4527
+
4528
+ return {
4529
+ changeAddress: xnaOutputs[0].address,
4530
+ changeAmount: xnaOutputs[0].value
4531
+ };
4532
+ }
4533
+
4398
4534
  /**
4399
4535
  * Format transaction result
4400
4536
  * @param {string} rawTx - Raw transaction hex
@@ -4407,13 +4543,26 @@ var NeuraiAssetsBundle = (function (exports) {
4407
4543
  * @returns {object} Formatted result
4408
4544
  */
4409
4545
  formatResult(rawTx, utxos, inputs, outputs, fee, burnAmount, extra = {}) {
4546
+ const outputEntries = this.getOutputEntries(outputs);
4547
+ const burnMetadata = this.extractBurnMetadata(outputEntries, burnAmount);
4548
+ const changeMetadata = this.extractChangeMetadata(outputEntries, burnMetadata.burnAddress);
4549
+
4410
4550
  return {
4411
4551
  rawTx,
4412
4552
  utxos,
4413
4553
  inputs,
4414
4554
  outputs,
4415
4555
  fee,
4416
- burnAmount,
4556
+ burnAmount: burnMetadata.burnAmount,
4557
+ network: this.network,
4558
+ buildStrategy: 'rpc-node',
4559
+ burnAddress: burnMetadata.burnAddress,
4560
+ changeAddress: extra.changeAddress !== undefined
4561
+ ? extra.changeAddress
4562
+ : changeMetadata.changeAddress,
4563
+ changeAmount: extra.changeAmount !== undefined
4564
+ ? extra.changeAmount
4565
+ : changeMetadata.changeAmount,
4417
4566
  ...extra
4418
4567
  };
4419
4568
  }
@@ -4630,7 +4779,23 @@ var NeuraiAssetsBundle = (function (exports) {
4630
4779
  {
4631
4780
  assetName,
4632
4781
  ownerTokenName: assetName + '!',
4633
- operationType: 'ISSUE_ROOT'
4782
+ operationType: 'ISSUE_ROOT',
4783
+ localRawBuild: this.buildLocalRawBuild(
4784
+ 'ISSUE_ROOT',
4785
+ inputs,
4786
+ burnInfo,
4787
+ changeAddress,
4788
+ xnaChange > 0.00000001 ? parseFloat(xnaChange.toFixed(8)) : null,
4789
+ {
4790
+ toAddress,
4791
+ assetName,
4792
+ quantityRaw: this.toSatoshis(quantity, units),
4793
+ units,
4794
+ reissuable,
4795
+ ipfsHash: hasIpfs ? ipfsHash : undefined,
4796
+ ownerTokenAddress: changeAddress
4797
+ }
4798
+ )
4634
4799
  }
4635
4800
  );
4636
4801
  }
@@ -4876,7 +5041,23 @@ var NeuraiAssetsBundle = (function (exports) {
4876
5041
  parentAssetName,
4877
5042
  ownerTokenName: assetName + '!',
4878
5043
  parentOwnerTokenUsed: ownerTokenName,
4879
- operationType: 'ISSUE_SUB'
5044
+ operationType: 'ISSUE_SUB',
5045
+ localRawBuild: this.buildLocalRawBuild(
5046
+ 'ISSUE_SUB',
5047
+ inputs,
5048
+ burnInfo,
5049
+ changeAddress,
5050
+ xnaChange > 0.00000001 ? parseFloat(xnaChange.toFixed(8)) : null,
5051
+ {
5052
+ toAddress,
5053
+ assetName,
5054
+ quantityRaw: this.toSatoshis(quantity, units),
5055
+ units,
5056
+ reissuable,
5057
+ ipfsHash: hasIpfs ? ipfsHash : undefined,
5058
+ parentOwnerAddress: changeAddress
5059
+ }
5060
+ )
4880
5061
  }
4881
5062
  );
4882
5063
  }
@@ -5029,7 +5210,22 @@ var NeuraiAssetsBundle = (function (exports) {
5029
5210
  {
5030
5211
  assetName,
5031
5212
  ownerTokenName: `${assetName}!`,
5032
- operationType: 'ISSUE_DEPIN'
5213
+ operationType: 'ISSUE_DEPIN',
5214
+ localRawBuild: this.buildLocalRawBuild(
5215
+ 'ISSUE_DEPIN',
5216
+ inputs,
5217
+ burnInfo,
5218
+ changeAddress,
5219
+ xnaChange > 0.00000001 ? parseFloat(xnaChange.toFixed(8)) : null,
5220
+ {
5221
+ toAddress,
5222
+ assetName,
5223
+ quantityRaw: this.toSatoshis(quantity, 0),
5224
+ ipfsHash: hasIpfs ? ipfsHash : undefined,
5225
+ ownerTokenAddress: changeAddress,
5226
+ reissuable
5227
+ }
5228
+ )
5033
5229
  }
5034
5230
  );
5035
5231
  }
@@ -5277,7 +5473,23 @@ var NeuraiAssetsBundle = (function (exports) {
5277
5473
  newTotalSupply,
5278
5474
  previousSupply: currentSupply,
5279
5475
  reissuableLocked: reissuable === false,
5280
- operationType: 'REISSUE'
5476
+ operationType: 'REISSUE',
5477
+ localRawBuild: this.buildLocalRawBuild(
5478
+ 'REISSUE',
5479
+ inputs,
5480
+ burnInfo,
5481
+ changeAddress,
5482
+ xnaChange > 0.00000001 ? parseFloat(xnaChange.toFixed(8)) : null,
5483
+ {
5484
+ toAddress,
5485
+ assetName,
5486
+ quantityRaw: this.toSatoshis(quantity, units),
5487
+ units,
5488
+ reissuable: reissuable !== undefined ? reissuable : undefined,
5489
+ ipfsHash: newIpfs || undefined,
5490
+ ownerChangeAddress: isDepinAsset ? toAddress : changeAddress
5491
+ }
5492
+ )
5281
5493
  }
5282
5494
  );
5283
5495
  }
@@ -5534,7 +5746,21 @@ var NeuraiAssetsBundle = (function (exports) {
5534
5746
  createdNFTs,
5535
5747
  nftCount,
5536
5748
  ownerTokenUsed: ownerTokenName,
5537
- operationType: 'ISSUE_UNIQUE'
5749
+ operationType: 'ISSUE_UNIQUE',
5750
+ localRawBuild: this.buildLocalRawBuild(
5751
+ 'ISSUE_UNIQUE',
5752
+ inputs,
5753
+ burnInfo,
5754
+ changeAddress,
5755
+ xnaChange > 0.00000001 ? parseFloat(xnaChange.toFixed(8)) : null,
5756
+ {
5757
+ toAddress,
5758
+ rootName,
5759
+ assetTags,
5760
+ ipfsHashes: ipfsHashes.length > 0 ? ipfsHashes : undefined,
5761
+ ownerTokenAddress: changeAddress
5762
+ }
5763
+ )
5538
5764
  }
5539
5765
  );
5540
5766
  }
@@ -5779,7 +6005,24 @@ var NeuraiAssetsBundle = (function (exports) {
5779
6005
  qualifierType: isSub ? 'SUB_QUALIFIER' : 'QUALIFIER',
5780
6006
  parentQualifier: isSub ? parsed.parent : null,
5781
6007
  parentQualifierUsed: parentQualifierName,
5782
- operationType: isSub ? 'ISSUE_SUB_QUALIFIER' : 'ISSUE_QUALIFIER'
6008
+ operationType: isSub ? 'ISSUE_SUB_QUALIFIER' : 'ISSUE_QUALIFIER',
6009
+ localRawBuild: this.buildLocalRawBuild(
6010
+ isSub ? 'ISSUE_SUB_QUALIFIER' : 'ISSUE_QUALIFIER',
6011
+ inputs,
6012
+ burnInfo,
6013
+ changeAddress,
6014
+ xnaChange > 0.00000001 ? parseFloat(xnaChange.toFixed(8)) : null,
6015
+ {
6016
+ toAddress,
6017
+ assetName,
6018
+ quantityRaw: this.toSatoshis(quantity, 0),
6019
+ ipfsHash: hasIpfs ? ipfsHash : undefined,
6020
+ rootChangeAddress: isSub ? changeAddress : undefined,
6021
+ changeQuantityRaw: isSub && parentQualifierQuantity !== null
6022
+ ? this.toSatoshis(parentQualifierQuantity, 0)
6023
+ : undefined
6024
+ }
6025
+ )
5783
6026
  }
5784
6027
  );
5785
6028
  }
@@ -6009,7 +6252,24 @@ var NeuraiAssetsBundle = (function (exports) {
6009
6252
  ownerTokenName,
6010
6253
  verifierString,
6011
6254
  requiredQualifiers,
6012
- operationType: 'ISSUE_RESTRICTED'
6255
+ operationType: 'ISSUE_RESTRICTED',
6256
+ localRawBuild: this.buildLocalRawBuild(
6257
+ 'ISSUE_RESTRICTED',
6258
+ inputs,
6259
+ burnInfo,
6260
+ changeAddress,
6261
+ xnaChange > 0.00000001 ? parseFloat(xnaChange.toFixed(8)) : null,
6262
+ {
6263
+ toAddress,
6264
+ assetName,
6265
+ quantityRaw: this.toSatoshis(quantity, units),
6266
+ verifierString,
6267
+ units,
6268
+ reissuable,
6269
+ ipfsHash: hasIpfs ? ipfsHash : undefined,
6270
+ ownerChangeAddress: changeAddress
6271
+ }
6272
+ )
6013
6273
  }
6014
6274
  );
6015
6275
  }
@@ -6272,7 +6532,24 @@ var NeuraiAssetsBundle = (function (exports) {
6272
6532
  newVerifier: changeVerifier ? newVerifier : undefined,
6273
6533
  requiredQualifiers,
6274
6534
  reissuableLocked: reissuable === false,
6275
- operationType: 'REISSUE_RESTRICTED'
6535
+ operationType: 'REISSUE_RESTRICTED',
6536
+ localRawBuild: this.buildLocalRawBuild(
6537
+ 'REISSUE_RESTRICTED',
6538
+ inputs,
6539
+ burnInfo,
6540
+ changeAddress,
6541
+ xnaChange > 0.00000001 ? parseFloat(xnaChange.toFixed(8)) : null,
6542
+ {
6543
+ toAddress,
6544
+ assetName,
6545
+ quantityRaw: this.toSatoshis(quantity, assetData.units || 0),
6546
+ units: assetData.units || 0,
6547
+ reissuable: reissuable !== undefined ? reissuable : undefined,
6548
+ ipfsHash: newIpfs || undefined,
6549
+ ownerChangeAddress: this.params.ownerChangeAddress || changeAddress,
6550
+ verifierString: changeVerifier ? newVerifier : undefined
6551
+ }
6552
+ )
6276
6553
  }
6277
6554
  );
6278
6555
  }
@@ -6495,7 +6772,20 @@ var NeuraiAssetsBundle = (function (exports) {
6495
6772
  qualifierAssetUsed: qualifierName,
6496
6773
  targetAddresses,
6497
6774
  addressCount,
6498
- operationType: isUntag ? 'UNTAG_ADDRESSES' : 'TAG_ADDRESSES'
6775
+ operationType: isUntag ? 'UNTAG_ADDRESSES' : 'TAG_ADDRESSES',
6776
+ localRawBuild: this.buildLocalRawBuild(
6777
+ isUntag ? 'UNTAG_ADDRESSES' : 'TAG_ADDRESSES',
6778
+ inputs,
6779
+ burnInfo,
6780
+ changeAddress,
6781
+ xnaChange > 0.00000001 ? parseFloat(xnaChange.toFixed(8)) : null,
6782
+ {
6783
+ qualifierName,
6784
+ targetAddresses,
6785
+ qualifierChangeAddress: changeAddress,
6786
+ qualifierChangeAmountRaw: this.toSatoshis(qualifierQuantity, 0)
6787
+ }
6788
+ )
6499
6789
  }
6500
6790
  );
6501
6791
  }
@@ -6742,7 +7032,24 @@ var NeuraiAssetsBundle = (function (exports) {
6742
7032
  ownerTokenUsed: ownerTokenName,
6743
7033
  targetAddresses: targetAddresses.length > 0 ? targetAddresses : null,
6744
7034
  addressCount: targetAddresses.length,
6745
- operationType
7035
+ operationType,
7036
+ localRawBuild: this.buildLocalRawBuild(
7037
+ operationType,
7038
+ inputs,
7039
+ null,
7040
+ xnaChange > 0.00000001 ? changeAddress : null,
7041
+ xnaChange > 0.00000001 ? parseFloat(xnaChange.toFixed(8)) : null,
7042
+ operationType === 'FREEZE_ADDRESSES' || operationType === 'UNFREEZE_ADDRESSES'
7043
+ ? {
7044
+ assetName,
7045
+ targetAddresses,
7046
+ ownerChangeAddress: changeAddress
7047
+ }
7048
+ : {
7049
+ assetName,
7050
+ ownerChangeAddress: changeAddress
7051
+ }
7052
+ )
6746
7053
  }
6747
7054
  );
6748
7055
  }
@@ -6919,7 +7226,7 @@ var NeuraiAssetsBundle = (function (exports) {
6919
7226
  return {
6920
7227
  ...params,
6921
7228
  network: this.config.network,
6922
- addresses: this.config.addresses,
7229
+ walletAddresses: this.config.addresses,
6923
7230
  changeAddress: params.changeAddress || this.config.changeAddress,
6924
7231
  toAddress: params.toAddress || this.config.toAddress
6925
7232
  };