@neuraiproject/neurai-assets 1.0.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 (58) hide show
  1. package/README.md +522 -0
  2. package/examples/01-create-root-asset.js +71 -0
  3. package/examples/02-create-sub-asset.js +79 -0
  4. package/examples/03-create-nfts.js +140 -0
  5. package/examples/04-reissue-asset.js +164 -0
  6. package/examples/05-create-qualifier-and-tag.js +209 -0
  7. package/examples/06-create-restricted-asset.js +223 -0
  8. package/examples/07-freeze-and-unfreeze.js +292 -0
  9. package/examples/08-query-assets.js +332 -0
  10. package/examples/09-wallet-integration.js +320 -0
  11. package/examples/README.md +319 -0
  12. package/package.json +43 -0
  13. package/src/NeuraiAssets.js +468 -0
  14. package/src/builders/BaseAssetTransactionBuilder.js +303 -0
  15. package/src/builders/FreezeAddressBuilder.js +271 -0
  16. package/src/builders/IssueQualifierBuilder.js +251 -0
  17. package/src/builders/IssueRestrictedBuilder.js +187 -0
  18. package/src/builders/IssueRootBuilder.js +173 -0
  19. package/src/builders/IssueSubBuilder.js +237 -0
  20. package/src/builders/IssueUniqueBuilder.js +255 -0
  21. package/src/builders/ReissueBuilder.js +246 -0
  22. package/src/builders/ReissueRestrictedBuilder.js +264 -0
  23. package/src/builders/TagAddressBuilder.js +243 -0
  24. package/src/builders/index.js +38 -0
  25. package/src/constants/assetTypes.js +23 -0
  26. package/src/constants/burnAddresses.js +65 -0
  27. package/src/constants/fees.js +61 -0
  28. package/src/constants/index.js +44 -0
  29. package/src/constants/networks.js +112 -0
  30. package/src/errors/AssetErrors.js +135 -0
  31. package/src/errors/ValidationErrors.js +87 -0
  32. package/src/errors/index.js +56 -0
  33. package/src/index.js +68 -0
  34. package/src/managers/BurnManager.js +222 -0
  35. package/src/managers/OutputOrderer.js +289 -0
  36. package/src/managers/OwnerTokenManager.js +265 -0
  37. package/src/managers/UTXOSelector.js +309 -0
  38. package/src/managers/index.js +16 -0
  39. package/src/queries/AssetQueries.js +447 -0
  40. package/src/queries/index.js +10 -0
  41. package/src/utils/amountConverter.js +115 -0
  42. package/src/utils/assetNameParser.js +203 -0
  43. package/src/utils/index.js +16 -0
  44. package/src/utils/networkDetector.js +144 -0
  45. package/src/utils/outputFormatter.js +292 -0
  46. package/src/validators/amountValidator.js +149 -0
  47. package/src/validators/assetNameValidator.js +296 -0
  48. package/src/validators/index.js +16 -0
  49. package/src/validators/ipfsValidator.js +101 -0
  50. package/src/validators/verifierValidator.js +146 -0
  51. package/tests/README.md +126 -0
  52. package/tests/integration/assetLifecycle.test.js +244 -0
  53. package/tests/mocks/rpcMock.js +156 -0
  54. package/tests/unit/NeuraiAssets.test.js +217 -0
  55. package/tests/unit/utils/amountConverter.test.js +171 -0
  56. package/tests/unit/utils/assetNameParser.test.js +203 -0
  57. package/tests/unit/validators/amountValidator.test.js +143 -0
  58. package/tests/unit/validators/assetNameValidator.test.js +228 -0
@@ -0,0 +1,319 @@
1
+ # NeuraiAssets Examples
2
+
3
+ This directory contains comprehensive examples demonstrating all features of the `@neuraiproject/neurai-assets` library.
4
+
5
+ ## Overview
6
+
7
+ Each example is a standalone JavaScript file that demonstrates specific functionality. All examples include detailed comments explaining the code and the operations being performed.
8
+
9
+ ## Examples List
10
+
11
+ ### 1. Create ROOT Asset
12
+ **File:** [01-create-root-asset.js](01-create-root-asset.js)
13
+
14
+ Learn how to create a standard ROOT asset (token). This is the base asset type in Neurai.
15
+
16
+ - Cost: 1000 XNA
17
+ - Creates: `MYTOKEN` + `MYTOKEN!` (owner token)
18
+ - Features: Supply, decimals, reissuability, IPFS metadata
19
+
20
+ **Topics covered:**
21
+ - Initializing NeuraiAssets
22
+ - Creating a ROOT asset
23
+ - Understanding owner tokens
24
+ - Error handling
25
+
26
+ ---
27
+
28
+ ### 2. Create SUB Asset
29
+ **File:** [02-create-sub-asset.js](02-create-sub-asset.js)
30
+
31
+ Learn how to create SUB assets (child tokens of a ROOT asset).
32
+
33
+ - Format: `PARENT/SUB`
34
+ - Cost: 200 XNA
35
+ - Requires: Parent's owner token (`PARENT!`)
36
+
37
+ **Topics covered:**
38
+ - Creating SUB assets
39
+ - Verifying owner token ownership
40
+ - Returning owner tokens safely
41
+
42
+ ---
43
+
44
+ ### 3. Create UNIQUE Assets (NFTs)
45
+ **File:** [03-create-nfts.js](03-create-nfts.js)
46
+
47
+ Learn how to create UNIQUE assets (NFTs) on Neurai blockchain.
48
+
49
+ - Format: `ROOT#TAG`
50
+ - Cost: 10 XNA per NFT
51
+ - Features: Batch creation, individual IPFS metadata
52
+
53
+ **Topics covered:**
54
+ - Creating NFT collections
55
+ - Single NFT creation
56
+ - IPFS metadata for each NFT
57
+ - NFT properties (non-divisible, fixed quantity of 1)
58
+
59
+ ---
60
+
61
+ ### 4. Reissue Assets
62
+ **File:** [04-reissue-asset.js](04-reissue-asset.js)
63
+
64
+ Learn how to reissue (mint more supply) of existing assets.
65
+
66
+ - Cost: 200 XNA
67
+ - Requires: Asset's owner token
68
+ - Features: Mint more, lock supply, update metadata
69
+
70
+ **Topics covered:**
71
+ - Minting additional supply
72
+ - Locking supply permanently
73
+ - Updating IPFS metadata
74
+ - Checking reissuability status
75
+
76
+ ---
77
+
78
+ ### 5. Create QUALIFIERs and Tag Addresses
79
+ **File:** [05-create-qualifier-and-tag.js](05-create-qualifier-and-tag.js)
80
+
81
+ Learn how to create QUALIFIER assets (KYC/compliance tags) and assign them to addresses.
82
+
83
+ - Format: `#NAME`
84
+ - Create cost: 2000 XNA (root), 200 XNA (sub)
85
+ - Tag cost: 0.1 XNA per address
86
+
87
+ **Topics covered:**
88
+ - Creating QUALIFIER assets
89
+ - Tagging addresses with qualifiers
90
+ - Untagging addresses
91
+ - Creating compliance systems
92
+ - SUB_QUALIFIERs
93
+
94
+ ---
95
+
96
+ ### 6. Create RESTRICTED Assets
97
+ **File:** [06-create-restricted-asset.js](06-create-restricted-asset.js)
98
+
99
+ Learn how to create RESTRICTED assets (security tokens with compliance).
100
+
101
+ - Format: `$NAME`
102
+ - Cost: 3000 XNA
103
+ - Features: Verifier strings, compliance rules
104
+
105
+ **Topics covered:**
106
+ - Creating RESTRICTED assets
107
+ - Verifier string syntax (boolean logic)
108
+ - Complex verifier logic (AND, OR, parentheses)
109
+ - Validating verifier strings
110
+ - Checking address compliance
111
+
112
+ ---
113
+
114
+ ### 7. Freeze and Unfreeze Operations
115
+ **File:** [07-freeze-and-unfreeze.js](07-freeze-and-unfreeze.js)
116
+
117
+ Learn how to freeze/unfreeze addresses and assets (RESTRICTED assets only).
118
+
119
+ - Cost: 0 XNA (only network fee)
120
+ - Requires: Restricted asset's owner token
121
+
122
+ **Topics covered:**
123
+ - Freezing specific addresses
124
+ - Unfreezing addresses
125
+ - Global asset freeze
126
+ - Global asset unfreeze
127
+ - Complete freeze workflow
128
+
129
+ ---
130
+
131
+ ### 8. Query Asset Information
132
+ **File:** [08-query-assets.js](08-query-assets.js)
133
+
134
+ Learn how to query asset information from the blockchain.
135
+
136
+ - All queries are read-only (no transactions)
137
+ - No costs involved
138
+
139
+ **Topics covered:**
140
+ - Querying asset metadata
141
+ - Listing all assets
142
+ - Listing wallet assets
143
+ - Querying asset holders
144
+ - Querying address balances
145
+ - Checking asset existence
146
+ - Detecting asset types
147
+ - Pagination
148
+
149
+ ---
150
+
151
+ ### 9. Complete Wallet Integration
152
+ **File:** [09-wallet-integration.js](09-wallet-integration.js)
153
+
154
+ Learn complete integration with `@neuraiproject/neurai-jswallet`.
155
+
156
+ **Topics covered:**
157
+ - Initializing wallet and assets together
158
+ - Complete transaction workflow
159
+ - Signing and broadcasting
160
+ - Creating multiple assets in sequence
161
+ - Error handling strategies
162
+ - Dynamic configuration updates
163
+
164
+ ---
165
+
166
+ ## Running the Examples
167
+
168
+ ### Prerequisites
169
+
170
+ ```bash
171
+ npm install @neuraiproject/neurai-assets
172
+ # npm install @neuraiproject/neurai-jswallet # For wallet integration
173
+ ```
174
+
175
+ ### Running an Example
176
+
177
+ Each example is self-contained and can be run directly:
178
+
179
+ ```bash
180
+ node 01-create-root-asset.js
181
+ ```
182
+
183
+ ### Important Notes
184
+
185
+ 1. **Mock RPC**: All examples use mock RPC functions. Replace with your actual RPC client in production.
186
+
187
+ 2. **Network**: Examples use mainnet (`'xna'`). Change to `'xna-test'` for testnet.
188
+
189
+ 3. **Addresses**: Replace placeholder addresses with your actual wallet addresses.
190
+
191
+ 4. **Testing**: Test on testnet first before using mainnet.
192
+
193
+ ## Production Integration
194
+
195
+ For production use, integrate with `neurai-jswallet`:
196
+
197
+ ```javascript
198
+ const NeuraiWallet = require('@neuraiproject/neurai-jswallet');
199
+ const NeuraiAssets = require('@neuraiproject/neurai-assets');
200
+
201
+ // Initialize wallet
202
+ const wallet = new NeuraiWallet(mnemonic, {
203
+ network: 'xna',
204
+ rpcUrl: 'http://localhost:9766',
205
+ rpcUser: 'user',
206
+ rpcPassword: 'pass'
207
+ });
208
+
209
+ // Initialize assets
210
+ const assets = new NeuraiAssets(wallet.rpc.bind(wallet), {
211
+ network: 'xna',
212
+ addresses: wallet.getAllAddresses(),
213
+ changeAddress: wallet.getChangeAddress(),
214
+ toAddress: wallet.getReceivingAddress()
215
+ });
216
+
217
+ // Create asset
218
+ const result = await assets.createRootAsset({...});
219
+
220
+ // Sign and broadcast
221
+ const signedTx = await wallet.signTransaction(result.rawTx);
222
+ const txid = await wallet.broadcastTransaction(signedTx);
223
+ ```
224
+
225
+ ## Asset Type Reference
226
+
227
+ | Type | Format | Cost | Example |
228
+ |------|--------|------|---------|
229
+ | ROOT | `NAME` | 1000 XNA | `MYTOKEN` |
230
+ | SUB | `ROOT/SUB` | 200 XNA | `MYTOKEN/PREMIUM` |
231
+ | UNIQUE | `ROOT#TAG` | 10 XNA | `MYTOKEN#001` |
232
+ | QUALIFIER | `#NAME` | 2000 XNA | `#KYC_VERIFIED` |
233
+ | SUB_QUALIFIER | `#ROOT/#SUB` | 200 XNA | `#KYC/#LEVEL2` |
234
+ | RESTRICTED | `$NAME` | 3000 XNA | `$SECURITY` |
235
+ | OWNER | `NAME!` | N/A | `MYTOKEN!` |
236
+
237
+ ## Common Patterns
238
+
239
+ ### Pattern 1: Create Asset Ecosystem
240
+
241
+ ```javascript
242
+ // 1. Create ROOT asset
243
+ const root = await assets.createRootAsset({...});
244
+
245
+ // 2. Create SUB assets
246
+ const sub = await assets.createSubAsset({...});
247
+
248
+ // 3. Create NFT collection
249
+ const nfts = await assets.createUniqueAssets({...});
250
+ ```
251
+
252
+ ### Pattern 2: Security Token Workflow
253
+
254
+ ```javascript
255
+ // 1. Create qualifiers
256
+ const kyc = await assets.createQualifier({ qualifierName: '#KYC' });
257
+ const accredited = await assets.createQualifier({ qualifierName: '#ACCREDITED' });
258
+
259
+ // 2. Create restricted asset
260
+ const security = await assets.createRestrictedAsset({
261
+ assetName: '$SECURITY',
262
+ verifierString: '#KYC & #ACCREDITED'
263
+ });
264
+
265
+ // 3. Tag compliant addresses
266
+ await assets.tagAddresses({
267
+ qualifierName: '#KYC',
268
+ addresses: [...]
269
+ });
270
+
271
+ // 4. Freeze non-compliant addresses if needed
272
+ await assets.freezeAddresses({
273
+ assetName: '$SECURITY',
274
+ addresses: [...]
275
+ });
276
+ ```
277
+
278
+ ### Pattern 3: Query Before Action
279
+
280
+ ```javascript
281
+ // Always check before creating
282
+ const exists = await assets.assetExists('MYTOKEN');
283
+ if (exists) {
284
+ console.log('Asset already exists!');
285
+ return;
286
+ }
287
+
288
+ // Check owner token before reissuing
289
+ const myAssets = await assets.listMyAssets('MYTOKEN!');
290
+ if (!myAssets['MYTOKEN!']) {
291
+ console.log('You need the owner token!');
292
+ return;
293
+ }
294
+
295
+ // Proceed with operation
296
+ const result = await assets.createRootAsset({...});
297
+ ```
298
+
299
+ ## Error Handling
300
+
301
+ All examples include error handling. Common errors:
302
+
303
+ - `AssetExistsError` - Asset name already taken
304
+ - `AssetNotFoundError` - Asset doesn't exist
305
+ - `InsufficientFundsError` - Not enough XNA
306
+ - `OwnerTokenNotFoundError` - Missing required owner token
307
+ - `OwnerTokenNotReturnedError` - CRITICAL: Owner token lost
308
+ - `InvalidAssetNameError` - Invalid name format
309
+ - `MaxSupplyExceededError` - Exceeds 21 billion limit
310
+
311
+ ## Support
312
+
313
+ For questions or issues:
314
+ - Documentation: [README.md](../README.md)
315
+ - Issues: https://github.com/neuraiproject/neurai-jswallet/issues
316
+
317
+ ## License
318
+
319
+ MIT
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@neuraiproject/neurai-assets",
3
+ "version": "1.0.0",
4
+ "description": "Non-custodial Neurai asset management library for JavaScript",
5
+ "main": "./src/index.js",
6
+ "scripts": {
7
+ "test": "mocha ./tests/unit/**/*.test.js ./tests/integration/**/*.test.js",
8
+ "test:unit": "mocha ./tests/unit/**/*.test.js",
9
+ "test:integration": "mocha ./tests/integration/**/*.test.js",
10
+ "test:watch": "mocha --watch ./tests/**/*.test.js"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/neuraiproject/neurai-assets.git"
15
+ },
16
+ "keywords": [
17
+ "neurai",
18
+ "assets",
19
+ "tokens",
20
+ "nft",
21
+ "blockchain",
22
+ "cryptocurrency",
23
+ "non-custodial",
24
+ "xna"
25
+ ],
26
+ "author": "Neurai Project",
27
+ "license": "MIT",
28
+ "private": false,
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "dependencies": {},
33
+ "devDependencies": {
34
+ "chai": "^4.3.10",
35
+ "mocha": "^10.2.0"
36
+ },
37
+ "peerDependencies": {
38
+ "@neuraiproject/neurai-rpc": "^0.4.6"
39
+ },
40
+ "engines": {
41
+ "node": ">=14.0.0"
42
+ }
43
+ }