@awarizon/core 2.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.
package/dist/index.js ADDED
@@ -0,0 +1,816 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AwarizonCore: () => AwarizonCore,
24
+ AwarizonKeyring: () => AwarizonKeyring,
25
+ DEFAULT_ENDPOINT: () => import_sdk14.DEFAULT_ENDPOINT,
26
+ MAX_CAMPAIGN_DURATION_DAYS: () => import_sdk14.MAX_CAMPAIGN_DURATION_DAYS,
27
+ MICRO_RIZ: () => import_sdk14.MICRO_RIZ,
28
+ MIN_CAMPAIGN_DURATION_DAYS: () => import_sdk14.MIN_CAMPAIGN_DURATION_DAYS,
29
+ MIN_INTERACTIONS: () => import_sdk14.MIN_INTERACTIONS,
30
+ MIN_SESSION_SECONDS: () => import_sdk14.MIN_SESSION_SECONDS,
31
+ PLANCK: () => import_sdk14.PLANCK,
32
+ RIZ: () => import_sdk14.RIZ,
33
+ createCore: () => createCore,
34
+ formatAmount: () => formatAmount,
35
+ isValidAmount: () => isValidAmount,
36
+ parseAmount: () => parseAmount
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
39
+
40
+ // src/AwarizonCore.ts
41
+ var import_sdk13 = require("@awarizon/sdk");
42
+
43
+ // src/keyring/index.ts
44
+ var import_util_crypto = require("@polkadot/util-crypto");
45
+ var import_keyring = require("@polkadot/keyring");
46
+ var import_util = require("@polkadot/util");
47
+ var AwarizonKeyring = class {
48
+ constructor() {
49
+ this.keyring = new import_keyring.Keyring({ type: "sr25519", ss58Format: 42 });
50
+ }
51
+ async initialize() {
52
+ await (0, import_util_crypto.cryptoWaitReady)();
53
+ }
54
+ generate(wordCount = 12) {
55
+ const mnemonic = (0, import_util_crypto.mnemonicGenerate)(wordCount);
56
+ const pair = this.keyring.addFromMnemonic(mnemonic);
57
+ return {
58
+ mnemonic,
59
+ address: pair.address,
60
+ publicKey: (0, import_util.u8aToHex)(pair.publicKey)
61
+ };
62
+ }
63
+ validate(mnemonic) {
64
+ return (0, import_util_crypto.mnemonicValidate)(mnemonic);
65
+ }
66
+ fromMnemonic(mnemonic) {
67
+ if (!this.validate(mnemonic)) {
68
+ throw new Error("Invalid mnemonic phrase");
69
+ }
70
+ return this.keyring.addFromMnemonic(mnemonic);
71
+ }
72
+ // Derive a child account. path examples: "//0", "//1", "//accountName"
73
+ derive(mnemonic, path) {
74
+ if (!this.validate(mnemonic)) {
75
+ throw new Error("Invalid mnemonic phrase");
76
+ }
77
+ return this.keyring.addFromMnemonic(`${mnemonic}${path}`);
78
+ }
79
+ // Encrypt keypair to JSON string safe for storage
80
+ encrypt(pair, password) {
81
+ const json = pair.toJson(password);
82
+ return JSON.stringify(json);
83
+ }
84
+ // Decrypt keypair from stored JSON string
85
+ decrypt(encrypted, password) {
86
+ try {
87
+ const json = JSON.parse(encrypted);
88
+ const pair = this.keyring.addFromJson(json);
89
+ pair.decodePkcs8(password);
90
+ return pair;
91
+ } catch {
92
+ throw new Error(
93
+ "Failed to decrypt wallet. Check your password and try again."
94
+ );
95
+ }
96
+ }
97
+ getAccount(pair) {
98
+ return {
99
+ address: pair.address,
100
+ publicKey: (0, import_util.u8aToHex)(pair.publicKey)
101
+ };
102
+ }
103
+ exportJson(pair, password) {
104
+ return JSON.stringify(pair.toJson(password));
105
+ }
106
+ importJson(json, password) {
107
+ try {
108
+ const parsed = JSON.parse(json);
109
+ const pair = this.keyring.addFromJson(parsed);
110
+ pair.decodePkcs8(password);
111
+ return pair;
112
+ } catch {
113
+ throw new Error(
114
+ "Failed to import wallet. Invalid backup file or wrong password."
115
+ );
116
+ }
117
+ }
118
+ toAddress(publicKey) {
119
+ return this.keyring.encodeAddress(publicKey, 42);
120
+ }
121
+ };
122
+
123
+ // src/modules/network.ts
124
+ var import_sdk2 = require("@awarizon/sdk");
125
+
126
+ // src/utils/amounts.ts
127
+ var import_sdk = require("@awarizon/sdk");
128
+ function parseAmount(input) {
129
+ const clean = input.replace(/\s*RIZ\s*/gi, "").trim();
130
+ if (!clean || isNaN(Number(clean))) {
131
+ throw new Error(
132
+ `Invalid amount: "${input}". Use format "10 RIZ" or "10"`
133
+ );
134
+ }
135
+ const [whole, decimal = ""] = clean.split(".");
136
+ const paddedDecimal = decimal.padEnd(12, "0").slice(0, 12);
137
+ return BigInt(whole || "0") * import_sdk.RIZ + BigInt(paddedDecimal);
138
+ }
139
+ function formatAmount(planck, decimals = 4) {
140
+ const whole = planck / import_sdk.RIZ;
141
+ const remainder = planck % import_sdk.RIZ;
142
+ const decStr = remainder.toString().padStart(12, "0").slice(0, decimals);
143
+ return `${whole.toLocaleString()}.${decStr} RIZ`;
144
+ }
145
+ function isValidAmount(input) {
146
+ try {
147
+ parseAmount(input);
148
+ return true;
149
+ } catch {
150
+ return false;
151
+ }
152
+ }
153
+
154
+ // src/modules/network.ts
155
+ var NetworkModule = class {
156
+ constructor(api) {
157
+ this.api = api;
158
+ }
159
+ async stats() {
160
+ const raw = await (0, import_sdk2.getNetworkStats)(this.api);
161
+ return {
162
+ totalWallets: Number(raw.total_wallets),
163
+ totalDeliveries: Number(raw.total_deliveries),
164
+ activeCampaigns: Number(raw.active_campaigns),
165
+ totalStaked: formatAmount(BigInt(raw.total_staked)),
166
+ currentEpoch: Number(raw.current_epoch),
167
+ inboxReserve: formatAmount(BigInt(raw.inbox_reserve_balance)),
168
+ totalExtrinsics: Number(raw.total_extrinsics),
169
+ circulatingSupply: formatAmount(BigInt(raw.circulating_supply)),
170
+ nonCirculatingSupply: formatAmount(BigInt(raw.non_circulating_supply))
171
+ };
172
+ }
173
+ async tokenStats() {
174
+ const raw = await (0, import_sdk2.getTokenStats)(this.api);
175
+ return {
176
+ totalIssuance: formatAmount(BigInt(raw.total_issuance)),
177
+ engagementPool: formatAmount(BigInt(raw.engagement_pool_balance))
178
+ };
179
+ }
180
+ async validatorCount() {
181
+ const count = await (0, import_sdk2.getValidatorCount)(this.api);
182
+ return Number(count);
183
+ }
184
+ async activeValidators() {
185
+ return (0, import_sdk2.getActiveValidators)(this.api);
186
+ }
187
+ subscribeBlocks(callback) {
188
+ return new Promise((resolve, reject) => {
189
+ this.api.rpc.chain.subscribeNewHeads((header) => {
190
+ callback(header.number.toNumber(), header.hash.toHex());
191
+ }).then((unsub) => resolve(unsub)).catch(reject);
192
+ });
193
+ }
194
+ };
195
+
196
+ // src/modules/wallet.ts
197
+ var import_sdk3 = require("@awarizon/sdk");
198
+ var WalletModule = class {
199
+ constructor(api) {
200
+ this.api = api;
201
+ }
202
+ async balance(address) {
203
+ const account = await this.api.query.system.account(address);
204
+ const data = account.data;
205
+ const free = BigInt(data.free.toString());
206
+ const reserved = BigInt(data.reserved.toString());
207
+ const total = free + reserved;
208
+ return {
209
+ free: formatAmount(free),
210
+ staked: formatAmount(reserved),
211
+ reserved: formatAmount(reserved),
212
+ total: formatAmount(total),
213
+ freePlanck: free
214
+ };
215
+ }
216
+ async send(params) {
217
+ const planck = parseAmount(params.amount);
218
+ const ext = this.api.tx.balances.transferKeepAlive(params.to, planck);
219
+ const result = await (0, import_sdk3.signAndSend)(this.api, ext, params.signer);
220
+ return {
221
+ hash: result.blockHash,
222
+ blockNumber: 0,
223
+ success: true
224
+ };
225
+ }
226
+ async totalIssuance() {
227
+ const issuance = await this.api.query.balances.totalIssuance();
228
+ return formatAmount(BigInt(issuance.toString()));
229
+ }
230
+ };
231
+
232
+ // src/modules/inbox.ts
233
+ var import_sdk4 = require("@awarizon/sdk");
234
+ var InboxModule = class {
235
+ constructor(api) {
236
+ this.api = api;
237
+ }
238
+ // Enumerate all InboxRecords for address via StorageDoubleMap prefix iteration
239
+ async list(address) {
240
+ const entries = await this.api.query.awarizonState.inboxRecords.entries(address);
241
+ return entries.map(([, value]) => {
242
+ const raw = value.toJSON();
243
+ return {
244
+ recordId: raw.record_id,
245
+ campaignId: raw.campaign_id,
246
+ developer: raw.developer,
247
+ manifestHash: raw.manifest_hash,
248
+ category: raw.category,
249
+ status: raw.status,
250
+ deliveredAt: raw.delivered_at,
251
+ engagedAt: raw.engaged_at ?? null,
252
+ rewardClaimed: raw.reward_claimed,
253
+ rewardEligible: raw.status === "Engaged" && !raw.reward_claimed
254
+ };
255
+ });
256
+ }
257
+ async get(address, recordId) {
258
+ const raw = await (0, import_sdk4.getInboxRecord)(this.api, address, recordId);
259
+ if (!raw) return null;
260
+ return {
261
+ recordId: raw.record_id,
262
+ campaignId: raw.campaign_id,
263
+ developer: raw.developer,
264
+ manifestHash: raw.manifest_hash,
265
+ category: raw.category,
266
+ status: raw.status,
267
+ deliveredAt: raw.delivered_at,
268
+ engagedAt: raw.engaged_at ?? null,
269
+ rewardClaimed: raw.reward_claimed,
270
+ rewardEligible: raw.status === "Engaged" && !raw.reward_claimed
271
+ };
272
+ }
273
+ async count(address) {
274
+ return (0, import_sdk4.getInboxCount)(this.api, address);
275
+ }
276
+ async engage(params) {
277
+ const sessionSeconds = params.sessionSeconds ?? import_sdk4.MIN_SESSION_SECONDS;
278
+ const interactions = params.interactions ?? import_sdk4.MIN_INTERACTIONS;
279
+ const ext = (0, import_sdk4.buildSubmitEngagement)(
280
+ this.api,
281
+ params.recordId,
282
+ sessionSeconds,
283
+ interactions
284
+ );
285
+ const result = await (0, import_sdk4.signAndSend)(this.api, ext, params.signer);
286
+ return { hash: result.blockHash, blockNumber: 0, success: true };
287
+ }
288
+ async claim(params) {
289
+ const ext = (0, import_sdk4.buildClaimReward)(this.api, params.recordId);
290
+ const result = await (0, import_sdk4.signAndSend)(this.api, ext, params.signer);
291
+ return { hash: result.blockHash, blockNumber: 0, success: true, reward: "1.0000 RIZ" };
292
+ }
293
+ async dismiss(params) {
294
+ const ext = (0, import_sdk4.buildDismissInboxRecord)(this.api, params.recordId);
295
+ const result = await (0, import_sdk4.signAndSend)(this.api, ext, params.signer);
296
+ return { hash: result.blockHash, blockNumber: 0, success: true };
297
+ }
298
+ };
299
+
300
+ // src/modules/developer.ts
301
+ var import_sdk5 = require("@awarizon/sdk");
302
+ var DeveloperModule = class {
303
+ constructor(api) {
304
+ this.api = api;
305
+ }
306
+ async register(params) {
307
+ const ext = (0, import_sdk5.buildRegisterDeveloper)(this.api);
308
+ const result = await (0, import_sdk5.signAndSend)(this.api, ext, params.signer);
309
+ return { hash: result.blockHash, blockNumber: 0, success: true };
310
+ }
311
+ async stake(params) {
312
+ const planck = parseAmount(params.amount);
313
+ const ext = (0, import_sdk5.buildStakeRiz)(this.api, planck);
314
+ const result = await (0, import_sdk5.signAndSend)(this.api, ext, params.signer);
315
+ return { hash: result.blockHash, blockNumber: 0, success: true };
316
+ }
317
+ async status(address) {
318
+ const profile = await (0, import_sdk5.getDeveloperProfile)(this.api, address);
319
+ if (!profile) return null;
320
+ return {
321
+ registered: true,
322
+ verified: profile.status === "Verified",
323
+ stake: formatAmount(profile.staked_riz),
324
+ totalCampaigns: profile.total_campaigns ?? 0,
325
+ totalDeliveries: Number(profile.total_deliveries),
326
+ violationCount: profile.violation_count ?? 0
327
+ };
328
+ }
329
+ };
330
+
331
+ // src/modules/apps.ts
332
+ var import_sdk6 = require("@awarizon/sdk");
333
+ var AppsModule = class {
334
+ constructor(api) {
335
+ this.api = api;
336
+ }
337
+ async register(params) {
338
+ const ext = (0, import_sdk6.buildRegisterManifest)(
339
+ this.api,
340
+ params.manifestHash,
341
+ params.category,
342
+ params.metadataUri
343
+ );
344
+ const result = await (0, import_sdk6.signAndSend)(this.api, ext, params.signer);
345
+ return {
346
+ hash: result.blockHash,
347
+ blockNumber: 0,
348
+ success: true,
349
+ manifestHash: params.manifestHash
350
+ };
351
+ }
352
+ async list(developerAddress) {
353
+ const hashes = await (0, import_sdk6.getDeveloperManifests)(this.api, developerAddress);
354
+ const manifests = [];
355
+ for (const hash of hashes) {
356
+ const raw = await this.api.query.awarizonState.manifests(hash);
357
+ const json = raw.toJSON();
358
+ if (!json) continue;
359
+ manifests.push({
360
+ manifestHash: json.manifest_hash,
361
+ developer: json.developer,
362
+ category: json.category,
363
+ registeredAt: json.registered_at,
364
+ metadataUri: typeof json.metadata_uri === "string" ? json.metadata_uri : Buffer.from(json.metadata_uri).toString("utf8")
365
+ });
366
+ }
367
+ return manifests;
368
+ }
369
+ };
370
+
371
+ // src/modules/campaigns.ts
372
+ var import_sdk7 = require("@awarizon/sdk");
373
+ var CATEGORY_MAP = {
374
+ DeFi: "DeFi",
375
+ Gaming: "Gaming",
376
+ Social: "Social",
377
+ Productivity: "Productivity",
378
+ Infrastructure: "Infrastructure",
379
+ DigitalAssets: "DigitalAssets",
380
+ DeveloperTools: "DeveloperTools",
381
+ Education: "Education"
382
+ };
383
+ function buildTargetingCriteria(opts) {
384
+ return {
385
+ wallet_age_min: opts.minWalletAge ?? null,
386
+ wallet_age_max: opts.maxWalletAge ?? null,
387
+ riz_balance_min: opts.minBalance ? parseAmount(opts.minBalance) : null,
388
+ riz_balance_max: opts.maxBalance ? parseAmount(opts.maxBalance) : null,
389
+ activity_min: opts.minActivity ?? null,
390
+ activity_max: opts.maxActivity ?? null,
391
+ region_codes: opts.regions ?? [],
392
+ category_history: (opts.categories ?? []).map((c) => CATEGORY_MAP[c]).filter((c) => c !== void 0),
393
+ custom_logic_hash: null
394
+ };
395
+ }
396
+ function targetingDescription(opts) {
397
+ const parts = [];
398
+ if (opts.categories?.length) parts.push(`categories: ${opts.categories.join(", ")}`);
399
+ if (opts.minBalance || opts.maxBalance)
400
+ parts.push(`balance: ${opts.minBalance ?? "0"} \u2013 ${opts.maxBalance ?? "\u221E"}`);
401
+ if (opts.minWalletAge || opts.maxWalletAge)
402
+ parts.push(`wallet age: ${opts.minWalletAge ?? 0} \u2013 ${opts.maxWalletAge ?? "\u221E"} days`);
403
+ if (opts.regions?.length) parts.push(`regions: ${opts.regions.join(", ")}`);
404
+ return parts.length ? parts.join("; ") : "no targeting filters";
405
+ }
406
+ function rawToCampaign(raw) {
407
+ return {
408
+ campaignId: raw.campaign_id,
409
+ developer: raw.developer,
410
+ manifestHash: raw.manifest_hash,
411
+ status: raw.status,
412
+ createdAt: raw.created_at,
413
+ expiresAt: raw.expires_at,
414
+ maxDeliveries: Number(raw.max_deliveries),
415
+ currentDeliveries: Number(raw.current_deliveries),
416
+ targetingDescription: "see on-chain targeting criteria"
417
+ };
418
+ }
419
+ var CampaignsModule = class {
420
+ constructor(api) {
421
+ this.api = api;
422
+ }
423
+ async create(params) {
424
+ const campaignId = (0, import_sdk7.generateCampaignId)(params.manifestHash);
425
+ const criteria = buildTargetingCriteria(params.targeting);
426
+ const ext = (0, import_sdk7.buildCreateCampaign)(
427
+ this.api,
428
+ campaignId,
429
+ params.manifestHash,
430
+ criteria,
431
+ params.durationDays,
432
+ params.maxDeliveries
433
+ );
434
+ const result = await (0, import_sdk7.signAndSend)(this.api, ext, params.signer);
435
+ return { hash: result.blockHash, blockNumber: 0, success: true, campaignId };
436
+ }
437
+ async get(campaignId) {
438
+ const raw = await (0, import_sdk7.getCampaign)(this.api, campaignId);
439
+ if (!raw) return null;
440
+ return rawToCampaign(raw);
441
+ }
442
+ async terminate(params) {
443
+ const ext = (0, import_sdk7.buildTerminateCampaign)(this.api, params.campaignId);
444
+ const result = await (0, import_sdk7.signAndSend)(this.api, ext, params.signer);
445
+ return { hash: result.blockHash, blockNumber: 0, success: true };
446
+ }
447
+ async deliver(params) {
448
+ const ext = (0, import_sdk7.buildDeliverToInbox)(
449
+ this.api,
450
+ params.wallet,
451
+ params.campaignId,
452
+ params.recordId
453
+ );
454
+ const result = await (0, import_sdk7.signAndSend)(this.api, ext, params.signer);
455
+ return { hash: result.blockHash, blockNumber: 0, success: true };
456
+ }
457
+ async deliveryStatus(campaignId) {
458
+ const raw = await (0, import_sdk7.getCampaignDeliveryStatus)(this.api, campaignId);
459
+ if (!raw) return null;
460
+ return {
461
+ current: Number(raw.current_deliveries),
462
+ max: Number(raw.max_deliveries),
463
+ remaining: Number(raw.remaining),
464
+ percentage: raw.percentage_used
465
+ };
466
+ }
467
+ // Convenience: build targeting criteria description without creating a campaign
468
+ describeTargeting(opts) {
469
+ return targetingDescription(opts);
470
+ }
471
+ };
472
+
473
+ // src/modules/assets.ts
474
+ var import_sdk8 = require("@awarizon/sdk");
475
+ var AssetsModule = class {
476
+ constructor(api) {
477
+ this.api = api;
478
+ }
479
+ async create(params) {
480
+ const ext = (0, import_sdk8.buildCreateAsset)(this.api, params.id, params.admin, params.minBalance);
481
+ const result = await (0, import_sdk8.signAndSend)(this.api, ext, params.signer);
482
+ return { hash: result.blockHash, blockNumber: 0, success: true, assetId: params.id };
483
+ }
484
+ async mint(params) {
485
+ const ext = (0, import_sdk8.buildMintAsset)(this.api, params.assetId, params.to, params.amount);
486
+ const result = await (0, import_sdk8.signAndSend)(this.api, ext, params.signer);
487
+ return { hash: result.blockHash, blockNumber: 0, success: true };
488
+ }
489
+ async transfer(params) {
490
+ const ext = (0, import_sdk8.buildTransferAsset)(this.api, params.assetId, params.to, params.amount);
491
+ const result = await (0, import_sdk8.signAndSend)(this.api, ext, params.signer);
492
+ return { hash: result.blockHash, blockNumber: 0, success: true };
493
+ }
494
+ async burn(params) {
495
+ const ext = this.api.tx.assets.burn(params.assetId, params.who, params.amount);
496
+ const result = await (0, import_sdk8.signAndSend)(this.api, ext, params.signer);
497
+ return { hash: result.blockHash, blockNumber: 0, success: true };
498
+ }
499
+ async balance(params) {
500
+ const raw = await this.api.query.assets.account(params.assetId, params.address);
501
+ const json = raw.toJSON();
502
+ const balRaw = BigInt(json?.balance?.toString() ?? "0");
503
+ return {
504
+ assetId: params.assetId,
505
+ symbol: String(params.assetId),
506
+ balance: balRaw.toString(),
507
+ balanceRaw: balRaw
508
+ };
509
+ }
510
+ async metadata(assetId) {
511
+ const raw = await this.api.query.assets.metadata(assetId);
512
+ const json = raw.toJSON();
513
+ return {
514
+ name: String(json.name ?? ""),
515
+ symbol: String(json.symbol ?? ""),
516
+ decimals: Number(json.decimals ?? 0)
517
+ };
518
+ }
519
+ async info(assetId) {
520
+ const raw = await this.api.query.assets.asset(assetId);
521
+ const json = raw.toJSON();
522
+ if (!json) return null;
523
+ const meta = await this.metadata(assetId);
524
+ return {
525
+ id: assetId,
526
+ name: meta.name,
527
+ symbol: meta.symbol,
528
+ decimals: meta.decimals,
529
+ supply: String(json.supply ?? "0"),
530
+ owner: String(json.owner ?? "")
531
+ };
532
+ }
533
+ };
534
+
535
+ // src/modules/nfts.ts
536
+ var import_sdk9 = require("@awarizon/sdk");
537
+ var NFTsModule = class {
538
+ constructor(api) {
539
+ this.api = api;
540
+ }
541
+ async createCollection(params) {
542
+ const ext = this.api.tx.nfts.create(
543
+ params.collectionId,
544
+ params.admin,
545
+ {}
546
+ // CollectionConfig — defaults suffice for basic usage
547
+ );
548
+ const result = await (0, import_sdk9.signAndSend)(this.api, ext, params.signer);
549
+ return { hash: result.blockHash, blockNumber: 0, success: true, collectionId: params.collectionId };
550
+ }
551
+ async mint(params) {
552
+ const ext = this.api.tx.nfts.mint(
553
+ params.collection,
554
+ params.itemId,
555
+ params.owner,
556
+ null
557
+ // witness_data (None)
558
+ );
559
+ const result = await (0, import_sdk9.signAndSend)(this.api, ext, params.signer);
560
+ return { hash: result.blockHash, blockNumber: 0, success: true };
561
+ }
562
+ async transfer(params) {
563
+ const ext = this.api.tx.nfts.transfer(params.collection, params.item, params.to);
564
+ const result = await (0, import_sdk9.signAndSend)(this.api, ext, params.signer);
565
+ return { hash: result.blockHash, blockNumber: 0, success: true };
566
+ }
567
+ async burn(params) {
568
+ const ext = this.api.tx.nfts.burn(params.collection, params.item);
569
+ const result = await (0, import_sdk9.signAndSend)(this.api, ext, params.signer);
570
+ return { hash: result.blockHash, blockNumber: 0, success: true };
571
+ }
572
+ async ownerOf(params) {
573
+ const raw = await this.api.query.nfts.item(params.collection, params.item);
574
+ const json = raw.toJSON();
575
+ if (!json) return null;
576
+ return String(json.owner ?? "");
577
+ }
578
+ async list(address) {
579
+ const entries = await this.api.query.nfts.account.entries(address);
580
+ const items = [];
581
+ for (const [key] of entries) {
582
+ const [, collection, item] = key.args;
583
+ items.push({
584
+ collection: Number(collection),
585
+ item: Number(item),
586
+ owner: address,
587
+ metadata: {}
588
+ });
589
+ }
590
+ return items;
591
+ }
592
+ };
593
+
594
+ // src/modules/validators.ts
595
+ var import_sdk10 = require("@awarizon/sdk");
596
+ function bpsToPercent(bps) {
597
+ return Math.round(bps / 100);
598
+ }
599
+ var ValidatorsModule = class {
600
+ constructor(api) {
601
+ this.api = api;
602
+ }
603
+ async register(params) {
604
+ const planck = parseAmount(params.stake);
605
+ const ext = (0, import_sdk10.buildRegisterValidator)(this.api, planck, params.regionCode, params.countryCode);
606
+ const result = await (0, import_sdk10.signAndSend)(this.api, ext, params.signer);
607
+ return { hash: result.blockHash, blockNumber: 0, success: true };
608
+ }
609
+ async delegate(params) {
610
+ const planck = parseAmount(params.amount);
611
+ const ext = (0, import_sdk10.buildDelegateStake)(this.api, params.to, planck);
612
+ const result = await (0, import_sdk10.signAndSend)(this.api, ext, params.signer);
613
+ return { hash: result.blockHash, blockNumber: 0, success: true };
614
+ }
615
+ async undelegate(params) {
616
+ const ext = (0, import_sdk10.buildUndelegateStake)(this.api, params.from);
617
+ const result = await (0, import_sdk10.signAndSend)(this.api, ext, params.signer);
618
+ return { hash: result.blockHash, blockNumber: 0, success: true };
619
+ }
620
+ async performance(address) {
621
+ const [validatorRaw, perfRaw] = await Promise.all([
622
+ this.api.query.awarizonConsensus.validators(address),
623
+ (0, import_sdk10.getValidatorPerformance)(this.api, address)
624
+ ]);
625
+ const validator = validatorRaw.toJSON();
626
+ if (!validator) return null;
627
+ const selfStake = BigInt(String(validator.self_stake ?? "0"));
628
+ const delegatedStake = BigInt(String(validator.delegated_stake ?? "0"));
629
+ return {
630
+ address,
631
+ selfStake: formatAmount(selfStake),
632
+ delegatedStake: formatAmount(delegatedStake),
633
+ totalStake: formatAmount(selfStake + delegatedStake),
634
+ performanceScore: perfRaw ? perfRaw.performance_score : 0,
635
+ uptime: perfRaw ? bpsToPercent(perfRaw.uptime_bps) : bpsToPercent(validator.uptime_bps ?? 0),
636
+ slashCount: perfRaw ? perfRaw.slash_count : validator.slash_count ?? 0,
637
+ isActive: Boolean(validator.is_active)
638
+ };
639
+ }
640
+ async list() {
641
+ const addresses = await (0, import_sdk10.getActiveValidators)(this.api);
642
+ const results = await Promise.all(addresses.map((addr) => this.performance(addr)));
643
+ return results.filter((v) => v !== null);
644
+ }
645
+ };
646
+
647
+ // src/modules/identity.ts
648
+ var import_sdk11 = require("@awarizon/sdk");
649
+ var IdentityModule = class {
650
+ constructor(api) {
651
+ this.api = api;
652
+ }
653
+ async get(address) {
654
+ return (0, import_sdk11.getIdentity)(this.api, address);
655
+ }
656
+ async lookup(name) {
657
+ return (0, import_sdk11.lookupName)(this.api, name);
658
+ }
659
+ async isAvailable(name) {
660
+ return (0, import_sdk11.isNameAvailable)(this.api, name);
661
+ }
662
+ async register(params) {
663
+ const ext = this.api.tx.awarizonIdentity.registerIdentity(
664
+ params.rizName ?? null,
665
+ params.displayName ?? null,
666
+ params.bio ?? null,
667
+ params.avatarUri ?? null,
668
+ params.website ?? null
669
+ );
670
+ const result = await (0, import_sdk11.signAndSend)(this.api, ext, params.signer);
671
+ return { hash: result.blockHash, blockNumber: 0, success: true };
672
+ }
673
+ async update(params) {
674
+ const ext = this.api.tx.awarizonIdentity.updateIdentity(
675
+ params.displayName ?? null,
676
+ params.bio ?? null,
677
+ params.avatarUri ?? null,
678
+ params.website ?? null
679
+ );
680
+ const result = await (0, import_sdk11.signAndSend)(this.api, ext, params.signer);
681
+ return { hash: result.blockHash, blockNumber: 0, success: true };
682
+ }
683
+ async recalculateReputation(params) {
684
+ const ext = this.api.tx.awarizonIdentity.recalculateReputation(params.account);
685
+ const result = await (0, import_sdk11.signAndSend)(this.api, ext, params.signer);
686
+ return { hash: result.blockHash, blockNumber: 0, success: true };
687
+ }
688
+ };
689
+
690
+ // src/modules/links.ts
691
+ var import_sdk12 = require("@awarizon/sdk");
692
+ var LinksModule = class {
693
+ constructor(api) {
694
+ this.api = api;
695
+ }
696
+ buildEvmLinkMessage(awarizonAddress) {
697
+ return `Link to Awarizon: ${awarizonAddress}`;
698
+ }
699
+ buildSolanaLinkMessage(awarizonAddress) {
700
+ return `Link to Awarizon: ${awarizonAddress}`;
701
+ }
702
+ async linkEvm(params) {
703
+ const addrBytes = hexToBytes20(params.evmAddress);
704
+ const sigBytes = hexToBytes65(params.signature);
705
+ const ext = this.api.tx.awarizonLinks.linkEvmAddress(addrBytes, sigBytes);
706
+ const result = await (0, import_sdk12.signAndSend)(this.api, ext, params.signer);
707
+ return { hash: result.blockHash, blockNumber: 0, success: true };
708
+ }
709
+ async linkSolana(params) {
710
+ const pubkeyBytes = base58ToBytes32(params.solanaPubkey);
711
+ const sigBytes = base64ToBytes64(params.signature);
712
+ const ext = this.api.tx.awarizonLinks.linkSolanaAddress(pubkeyBytes, sigBytes);
713
+ const result = await (0, import_sdk12.signAndSend)(this.api, ext, params.signer);
714
+ return { hash: result.blockHash, blockNumber: 0, success: true };
715
+ }
716
+ async unlink(params) {
717
+ const ext = this.api.tx.awarizonLinks.unlinkAddress(params.chain);
718
+ const result = await (0, import_sdk12.signAndSend)(this.api, ext, params.signer);
719
+ return { hash: result.blockHash, blockNumber: 0, success: true };
720
+ }
721
+ async list(address) {
722
+ return (0, import_sdk12.getLinkedAddresses)(this.api, address);
723
+ }
724
+ };
725
+ function hexToBytes20(hex) {
726
+ const clean = hex.replace(/^0x/i, "");
727
+ if (clean.length !== 40) throw new Error("EVM address must be 20 bytes (40 hex chars)");
728
+ return Uint8Array.from(Buffer.from(clean, "hex"));
729
+ }
730
+ function hexToBytes65(hex) {
731
+ const clean = hex.replace(/^0x/i, "");
732
+ if (clean.length !== 130) throw new Error("Signature must be 65 bytes (130 hex chars)");
733
+ return Uint8Array.from(Buffer.from(clean, "hex"));
734
+ }
735
+ function base58ToBytes32(b58) {
736
+ if (b58.startsWith("0x") || b58.startsWith("0X")) {
737
+ const clean = b58.slice(2);
738
+ return Uint8Array.from(Buffer.from(clean.padStart(64, "0"), "hex"));
739
+ }
740
+ throw new Error("Solana pubkey must be provided as 0x-prefixed hex (32 bytes)");
741
+ }
742
+ function base64ToBytes64(b64) {
743
+ const buf = Buffer.from(b64, "base64");
744
+ if (buf.length !== 64) throw new Error("Ed25519 signature must be 64 bytes");
745
+ return Uint8Array.from(buf);
746
+ }
747
+
748
+ // src/AwarizonCore.ts
749
+ var AwarizonCore = class {
750
+ constructor(config) {
751
+ this.config = config;
752
+ this.client = null;
753
+ this.api = null;
754
+ this.keyring = new AwarizonKeyring();
755
+ }
756
+ async connect() {
757
+ await this.keyring.initialize();
758
+ this.client = new import_sdk13.AwarizonClient(this.config.endpoint);
759
+ await this.client.connect();
760
+ this.api = this.client.getApi();
761
+ this.network = new NetworkModule(this.api);
762
+ this.wallet = new WalletModule(this.api);
763
+ this.inbox = new InboxModule(this.api);
764
+ this.developer = new DeveloperModule(this.api);
765
+ this.apps = new AppsModule(this.api);
766
+ this.campaigns = new CampaignsModule(this.api);
767
+ this.assets = new AssetsModule(this.api);
768
+ this.nfts = new NFTsModule(this.api);
769
+ this.validators = new ValidatorsModule(this.api);
770
+ this.identity = new IdentityModule(this.api);
771
+ this.links = new LinksModule(this.api);
772
+ return this;
773
+ }
774
+ async disconnect() {
775
+ if (this.client) {
776
+ await this.client.disconnect();
777
+ this.client = null;
778
+ this.api = null;
779
+ }
780
+ }
781
+ isConnected() {
782
+ return this.client !== null;
783
+ }
784
+ getApi() {
785
+ if (!this.api) {
786
+ throw new Error("Not connected. Call connect() first.");
787
+ }
788
+ return this.api;
789
+ }
790
+ };
791
+ async function createCore(config) {
792
+ const core = new AwarizonCore(config);
793
+ await core.connect();
794
+ return core;
795
+ }
796
+
797
+ // src/index.ts
798
+ var import_sdk14 = require("@awarizon/sdk");
799
+ // Annotate the CommonJS export names for ESM import in node:
800
+ 0 && (module.exports = {
801
+ AwarizonCore,
802
+ AwarizonKeyring,
803
+ DEFAULT_ENDPOINT,
804
+ MAX_CAMPAIGN_DURATION_DAYS,
805
+ MICRO_RIZ,
806
+ MIN_CAMPAIGN_DURATION_DAYS,
807
+ MIN_INTERACTIONS,
808
+ MIN_SESSION_SECONDS,
809
+ PLANCK,
810
+ RIZ,
811
+ createCore,
812
+ formatAmount,
813
+ isValidAmount,
814
+ parseAmount
815
+ });
816
+ //# sourceMappingURL=index.js.map