@neuraiproject/neurai-assets 1.1.0 → 1.2.0

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.
Files changed (70) hide show
  1. package/README.md +138 -12
  2. package/dist/NeuraiAssets.global.js +7470 -0
  3. package/dist/NeuraiAssets.global.js.map +1 -0
  4. package/dist/browser.js +7445 -0
  5. package/dist/browser.js.map +1 -0
  6. package/dist/index.cjs +7456 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.js +7445 -0
  9. package/dist/index.js.map +1 -0
  10. package/index.d.ts +116 -0
  11. package/package.json +30 -4
  12. package/examples/01-create-root-asset.js +0 -71
  13. package/examples/02-create-sub-asset.js +0 -79
  14. package/examples/03-create-nfts.js +0 -140
  15. package/examples/04-reissue-asset.js +0 -164
  16. package/examples/05-create-qualifier-and-tag.js +0 -209
  17. package/examples/06-create-restricted-asset.js +0 -223
  18. package/examples/07-freeze-and-unfreeze.js +0 -292
  19. package/examples/08-query-assets.js +0 -332
  20. package/examples/09-wallet-integration.js +0 -320
  21. package/examples/10-depin-post-quantum.js +0 -83
  22. package/examples/README.md +0 -337
  23. package/src/NeuraiAssets.js +0 -504
  24. package/src/builders/BaseAssetTransactionBuilder.js +0 -324
  25. package/src/builders/FreezeAddressBuilder.js +0 -254
  26. package/src/builders/IssueDepinBuilder.js +0 -144
  27. package/src/builders/IssueQualifierBuilder.js +0 -236
  28. package/src/builders/IssueRestrictedBuilder.js +0 -221
  29. package/src/builders/IssueRootBuilder.js +0 -173
  30. package/src/builders/IssueSubBuilder.js +0 -237
  31. package/src/builders/IssueUniqueBuilder.js +0 -248
  32. package/src/builders/ReissueBuilder.js +0 -239
  33. package/src/builders/ReissueRestrictedBuilder.js +0 -254
  34. package/src/builders/TagAddressBuilder.js +0 -230
  35. package/src/builders/index.js +0 -40
  36. package/src/constants/assetTypes.js +0 -23
  37. package/src/constants/burnAddresses.js +0 -83
  38. package/src/constants/fees.js +0 -61
  39. package/src/constants/index.js +0 -46
  40. package/src/constants/networks.js +0 -151
  41. package/src/errors/AssetErrors.js +0 -135
  42. package/src/errors/ValidationErrors.js +0 -87
  43. package/src/errors/index.js +0 -56
  44. package/src/index.js +0 -69
  45. package/src/managers/BurnManager.js +0 -231
  46. package/src/managers/OutputOrderer.js +0 -281
  47. package/src/managers/OwnerTokenManager.js +0 -270
  48. package/src/managers/UTXOSelector.js +0 -307
  49. package/src/managers/index.js +0 -16
  50. package/src/queries/AssetQueries.js +0 -496
  51. package/src/queries/index.js +0 -10
  52. package/src/utils/amountConverter.js +0 -115
  53. package/src/utils/assetNameParser.js +0 -227
  54. package/src/utils/index.js +0 -16
  55. package/src/utils/networkDetector.js +0 -160
  56. package/src/utils/outputFormatter.js +0 -338
  57. package/src/validators/amountValidator.js +0 -149
  58. package/src/validators/assetNameValidator.js +0 -372
  59. package/src/validators/index.js +0 -16
  60. package/src/validators/ipfsValidator.js +0 -101
  61. package/src/validators/verifierValidator.js +0 -146
  62. package/tests/README.md +0 -126
  63. package/tests/integration/assetLifecycle.test.js +0 -271
  64. package/tests/mocks/rpcMock.js +0 -158
  65. package/tests/unit/NeuraiAssets.test.js +0 -243
  66. package/tests/unit/utils/amountConverter.test.js +0 -171
  67. package/tests/unit/utils/assetNameParser.test.js +0 -240
  68. package/tests/unit/utils/networkDetector.test.js +0 -89
  69. package/tests/unit/validators/amountValidator.test.js +0 -143
  70. package/tests/unit/validators/assetNameValidator.test.js +0 -257
package/README.md CHANGED
@@ -5,11 +5,12 @@ Complete asset management library for Neurai blockchain. Supports creation, reis
5
5
  ## Features
6
6
 
7
7
  - ✅ **Non-custodial**: Library builds unsigned transactions, your wallet signs them
8
- - ✅ **All asset types**: ROOT, SUB, UNIQUE (NFTs), QUALIFIER, RESTRICTED
8
+ - ✅ **All asset types**: ROOT, SUB, UNIQUE (NFTs), QUALIFIER, RESTRICTED, DEPIN
9
9
  - ✅ **Complete operations**: Creation, reissuance, tagging, freezing
10
10
  - ✅ **RPC queries**: Complete wrapper for all asset query methods
11
11
  - ✅ **Client-side validation**: Prevents errors before creating transactions
12
12
  - ✅ **Owner token protection**: Validation to prevent permanent loss
13
+ - ✅ **PQ-ready networks**: Supports `xna-pq` and `xna-pq-test` with `nq1...` / `tnq1...` addresses
13
14
 
14
15
  ## Supported Asset Types
15
16
 
@@ -21,6 +22,7 @@ Complete asset management library for Neurai blockchain. Supports creation, reis
21
22
  | **QUALIFIER** | `#KYC` | 2000 XNA | Compliance tag |
22
23
  | **SUB_QUALIFIER** | `#PARENT/#SUB` | 200 XNA | Sub-qualifier |
23
24
  | **RESTRICTED** | `$SECURITY` | 3000 XNA | Security token with compliance |
25
+ | **DEPIN** | `&DEVICE` or `&DEVICE/ROUTER001` | 10 XNA | Soulbound asset with holder validity controls |
24
26
 
25
27
  ## Installation
26
28
 
@@ -28,6 +30,37 @@ Complete asset management library for Neurai blockchain. Supports creation, reis
28
30
  npm install @neuraiproject/neurai-assets
29
31
  ```
30
32
 
33
+ ## Package Outputs
34
+
35
+ The package now publishes explicit entry points for each runtime:
36
+
37
+ - `@neuraiproject/neurai-assets`: main ESM/CJS library entry
38
+ - `@neuraiproject/neurai-assets/browser`: browser-focused ESM entry
39
+ - `@neuraiproject/neurai-assets/global`: IIFE bundle for `<script src>`
40
+
41
+ ### ESM
42
+
43
+ ```javascript
44
+ import NeuraiAssets from '@neuraiproject/neurai-assets';
45
+ ```
46
+
47
+ ### Browser ESM
48
+
49
+ ```javascript
50
+ import NeuraiAssets from '@neuraiproject/neurai-assets/browser';
51
+ ```
52
+
53
+ ### Classic HTML
54
+
55
+ ```html
56
+ <script src="./node_modules/@neuraiproject/neurai-assets/dist/NeuraiAssets.global.js"></script>
57
+ <script>
58
+ const assets = new globalThis.NeuraiAssets(rpc, {
59
+ network: 'xna'
60
+ });
61
+ </script>
62
+ ```
63
+
31
64
  ## Basic Usage
32
65
 
33
66
  ```javascript
@@ -54,6 +87,17 @@ const signedTx = await wallet.signTransaction(result.rawTx);
54
87
  const txid = await wallet.broadcastTransaction(signedTx);
55
88
  ```
56
89
 
90
+ You can also initialize the library with PQ networks and addresses:
91
+
92
+ ```javascript
93
+ const assetsPQ = new NeuraiAssets(rpc, {
94
+ network: 'xna-pq', // or 'xna-pq-test'
95
+ addresses: ['nq1yourpqaddress...'],
96
+ changeAddress: 'nq1yourpqchange...',
97
+ toAddress: 'nq1recipientpqaddress...'
98
+ });
99
+ ```
100
+
57
101
  ## Operation Examples
58
102
 
59
103
  ### Create ROOT Asset
@@ -93,6 +137,20 @@ const result = await assets.reissueAsset({
93
137
  });
94
138
  ```
95
139
 
140
+ ### Create DEPIN Asset
141
+
142
+ ```javascript
143
+ const result = await assets.createDepinAsset({
144
+ assetName: '&DEVICE/ROUTER001',
145
+ quantity: 1,
146
+ reissuable: false,
147
+ hasIpfs: false
148
+ });
149
+ ```
150
+
151
+ > **Note**: DEPIN assets always use `units = 0`. The library accepts both legacy
152
+ > and PQ addresses as recipients depending on the configured network.
153
+
96
154
  ### Create UNIQUE Assets (NFTs)
97
155
 
98
156
  ```javascript
@@ -319,6 +377,30 @@ const exists = await assets.assetExists('MYTOKEN');
319
377
  console.log(exists); // true/false
320
378
  ```
321
379
 
380
+ ### View DEPIN Holders
381
+
382
+ ```javascript
383
+ const holders = await assets.listDepinHolders('&DEVICE/ROUTER001');
384
+ console.log(holders);
385
+ // [
386
+ // { address: 'nq1holder...', amount: 1, valid: 1 },
387
+ // { address: 'nq1holder2...', amount: 1, valid: 0 }
388
+ // ]
389
+ ```
390
+
391
+ ### Check DEPIN Validity for an Address
392
+
393
+ ```javascript
394
+ const validity = await assets.checkDepinValidity('&DEVICE/ROUTER001', 'nq1holder...');
395
+ console.log(validity);
396
+ // {
397
+ // has_asset: true,
398
+ // amount: 1,
399
+ // valid: 1,
400
+ // blocked: false
401
+ // }
402
+ ```
403
+
322
404
  ### Detect Asset Type
323
405
 
324
406
  ```javascript
@@ -327,7 +409,8 @@ const type2 = assets.getAssetType('PARENT/SUB'); // 'SUB'
327
409
  const type3 = assets.getAssetType('TOKEN#NFT'); // 'UNIQUE'
328
410
  const type4 = assets.getAssetType('#KYC'); // 'QUALIFIER'
329
411
  const type5 = assets.getAssetType('$SECURITY'); // 'RESTRICTED'
330
- const type6 = assets.getAssetType('MYTOKEN!'); // 'OWNER'
412
+ const type6 = assets.getAssetType('&DEVICE/ONE'); // 'DEPIN'
413
+ const type7 = assets.getAssetType('MYTOKEN!'); // 'OWNER'
331
414
  ```
332
415
 
333
416
  ## Transaction Result Structure
@@ -337,15 +420,14 @@ All creation/reissuance operations return an object with this structure:
337
420
  ```javascript
338
421
  {
339
422
  rawTx: 'hex string', // Unsigned transaction (to sign with wallet)
423
+ utxos: [...], // UTXOs selected for the operation
340
424
  inputs: [...], // Transaction inputs
341
- outputs: {...}, // Ordered outputs
425
+ outputs: [...], // Ordered outputs
342
426
  fee: 0.001, // Fee in XNA
343
- burn: 1000, // Burned amount in XNA
344
- metadata: { // Operation-specific metadata
345
- assetName: 'MYTOKEN',
346
- ownerTokenName: 'MYTOKEN!',
347
- operationType: 'ISSUE_ROOT'
348
- }
427
+ burnAmount: 1000, // Burned amount in XNA
428
+ assetName: 'MYTOKEN', // Operation-specific fields vary by builder
429
+ ownerTokenName: 'MYTOKEN!',
430
+ operationType: 'ISSUE_ROOT'
349
431
  }
350
432
  ```
351
433
 
@@ -358,6 +440,7 @@ When you create an asset, an **owner token** is automatically generated (e.g., `
358
440
  - Create SUB assets
359
441
  - Manage tags (if qualifier)
360
442
  - Freeze/unfreeze (if restricted)
443
+ - Manage DEPIN reissuance and controls (if depin)
361
444
 
362
445
  ⚠️ **If you lose the owner token, you lose these capabilities PERMANENTLY**
363
446
 
@@ -378,7 +461,9 @@ The library automatically validates that the owner token is returned in each ope
378
461
  | Create QUALIFIER (root) | 2000 |
379
462
  | Create QUALIFIER (sub) | 200 |
380
463
  | Create RESTRICTED asset | 3000 |
464
+ | Create DEPIN asset | 10 |
381
465
  | Reissue ROOT/SUB | 200 |
466
+ | Reissue DEPIN | 200 |
382
467
  | Reissue RESTRICTED | 200 |
383
468
  | Tag/Untag address | 0.1 (per address) |
384
469
  | Freeze/Unfreeze address | 0 (network fee only) |
@@ -415,11 +500,37 @@ const assets = new NeuraiAssets(rpc, {
415
500
  const assets = new NeuraiAssets(rpc, {
416
501
  network: 'xna-test',
417
502
  addresses: [...],
418
- changeAddress: 'm...' // or 'n...'
419
- toAddress: 'm...'
503
+ changeAddress: 't...',
504
+ toAddress: 't...'
505
+ });
506
+
507
+ // PQ Mainnet
508
+ const assetsPQ = new NeuraiAssets(rpc, {
509
+ network: 'xna-pq',
510
+ addresses: ['nq1...'],
511
+ changeAddress: 'nq1...',
512
+ toAddress: 'nq1...'
513
+ });
514
+
515
+ // PQ Testnet
516
+ const assetsPQTest = new NeuraiAssets(rpc, {
517
+ network: 'xna-pq-test',
518
+ addresses: ['tnq1...'],
519
+ changeAddress: 'tnq1...',
520
+ toAddress: 'tnq1...'
420
521
  });
421
522
  ```
422
523
 
524
+ The library accepts these network names:
525
+
526
+ - `xna`: legacy/mainnet address flow (`N...`)
527
+ - `xna-test`: legacy/testnet address flow (`t...`)
528
+ - `xna-pq`: PQ mainnet address flow (`nq1...`)
529
+ - `xna-pq-test`: PQ testnet address flow (`tnq1...`)
530
+
531
+ If you need to derive PQ addresses, use `neurai-key` and pass the resulting `nq1...`
532
+ or `tnq1...` addresses into this library.
533
+
423
534
  ## Update Configuration
424
535
 
425
536
  ```javascript
@@ -449,6 +560,17 @@ const builder = new builders.IssueRootBuilder(rpc, {
449
560
  const result = await builder.build();
450
561
  ```
451
562
 
563
+ The builders module also includes:
564
+
565
+ - `IssueDepinBuilder`
566
+ - `IssueRootBuilder`
567
+ - `IssueSubBuilder`
568
+ - `IssueUniqueBuilder`
569
+ - `IssueQualifierBuilder`
570
+ - `IssueRestrictedBuilder`
571
+ - `ReissueBuilder`
572
+ - `ReissueRestrictedBuilder`
573
+
452
574
  ## Error Handling
453
575
 
454
576
  The library throws specific errors:
@@ -524,4 +646,8 @@ const signedTx = await wallet.signTransaction(result.rawTx);
524
646
  // Broadcast
525
647
  const txid = await wallet.broadcastTransaction(signedTx);
526
648
  console.log('Transaction ID:', txid);
527
- ```
649
+ ```
650
+
651
+ For PQ wallets, derive addresses externally with `neurai-key` using `xna-pq` or
652
+ `xna-pq-test`, then initialize `NeuraiAssets` with those addresses and the matching
653
+ network name.