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