@unicitylabs/uniclaw 0.1.5 → 0.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unicitylabs/uniclaw",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Unicity wallet identity and encrypted DMs for OpenClaw agents — powered by Sphere SDK",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/assets.ts CHANGED
@@ -18,13 +18,15 @@ interface AssetEntry {
18
18
  }
19
19
 
20
20
  interface AssetRegistry {
21
- /** Map from lowercase name or symbol to faucet coin name */
21
+ /** Map from lowercase name, symbol, or coin id to coin name */
22
22
  aliases: Map<string, string>;
23
- /** Map from faucet coin name to display symbol */
23
+ /** Map from coin name to symbol */
24
24
  symbols: Map<string, string>;
25
- /** Map from faucet coin name to decimals */
25
+ /** Map from coin name to decimals */
26
26
  decimals: Map<string, number>;
27
- /** List of all available symbols for display */
27
+ /** Map from coin name to coin id */
28
+ coinIds: Map<string, string>;
29
+ /** List of all available symbols */
28
30
  availableSymbols: string[];
29
31
  }
30
32
 
@@ -40,6 +42,7 @@ function loadRegistry(): AssetRegistry {
40
42
  const aliases = new Map<string, string>();
41
43
  const symbols = new Map<string, string>();
42
44
  const decimals = new Map<string, number>();
45
+ const coinIds = new Map<string, string>();
43
46
  const availableSymbols: string[] = [];
44
47
 
45
48
  for (const entry of entries) {
@@ -50,13 +53,14 @@ function loadRegistry(): AssetRegistry {
50
53
  const name = entry.name;
51
54
  const symbol = entry.symbol;
52
55
 
53
- // Map name, symbol (lowercase), and coin id to the faucet coin name
56
+ // Map name, symbol (lowercase), and coin id to the coin name
54
57
  aliases.set(name.toLowerCase(), name);
55
58
  aliases.set(symbol.toLowerCase(), name);
56
59
  aliases.set(entry.id, name);
57
60
 
58
- // Store display symbol and decimals
61
+ // Store symbol, decimals, and coin id
59
62
  symbols.set(name, symbol);
63
+ coinIds.set(name, entry.id);
60
64
  if (entry.decimals !== undefined) {
61
65
  decimals.set(name, entry.decimals);
62
66
  }
@@ -64,17 +68,17 @@ function loadRegistry(): AssetRegistry {
64
68
  availableSymbols.push(symbol);
65
69
  }
66
70
 
67
- cachedRegistry = { aliases, symbols, decimals, availableSymbols };
71
+ cachedRegistry = { aliases, symbols, decimals, coinIds, availableSymbols };
68
72
  return cachedRegistry;
69
73
  }
70
74
 
71
- /** Resolve user input (name or symbol) to faucet coin name, or null if not found */
75
+ /** Resolve user input (name or symbol) to coin name, or null if not found */
72
76
  export function resolveCoinId(input: string): string | null {
73
77
  const registry = loadRegistry();
74
78
  return registry.aliases.get(input.toLowerCase().trim()) ?? null;
75
79
  }
76
80
 
77
- /** Get display symbol for a coin (accepts name, symbol, or coin id) */
81
+ /** Get symbol for a coin (accepts name, symbol, or coin id) */
78
82
  export function getCoinSymbol(coin: string): string {
79
83
  const registry = loadRegistry();
80
84
  const name = registry.aliases.get(coin) ?? registry.aliases.get(coin.toLowerCase()) ?? coin;
@@ -88,6 +92,13 @@ export function getCoinDecimals(coin: string): number | undefined {
88
92
  return name ? registry.decimals.get(name) : registry.decimals.get(coin);
89
93
  }
90
94
 
95
+ /** Get coin id for a coin (accepts name, symbol, or coin id) */
96
+ export function getCoinId(coin: string): string | undefined {
97
+ const registry = loadRegistry();
98
+ const name = registry.aliases.get(coin) ?? registry.aliases.get(coin.toLowerCase());
99
+ return name ? registry.coinIds.get(name) : registry.coinIds.get(coin);
100
+ }
101
+
91
102
  /** Get list of all available symbols for display */
92
103
  export function getAvailableSymbols(): string[] {
93
104
  const registry = loadRegistry();
@@ -133,7 +144,7 @@ export function toHumanReadable(amount: string, decimals: number): string {
133
144
  /**
134
145
  * Format amount for display with symbol
135
146
  * @param amount Amount in smallest units
136
- * @param coinName Faucet coin name (e.g., "unicity")
147
+ * @param coinName Coin name (e.g., "unicity")
137
148
  */
138
149
  export function formatAmount(amount: string, coinName: string): string {
139
150
  const decimals = getCoinDecimals(coinName) ?? 0;
@@ -145,7 +156,7 @@ export function formatAmount(amount: string, coinName: string): string {
145
156
  /**
146
157
  * Parse user input amount to smallest units for a given coin
147
158
  * @param amount Human-readable amount (e.g., "100" or "1.5")
148
- * @param coinName Faucet coin name (e.g., "unicity")
159
+ * @param coinName Coin name (e.g., "unicity")
149
160
  */
150
161
  export function parseAmount(amount: number | string, coinName: string): string {
151
162
  const decimals = getCoinDecimals(coinName) ?? 0;
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { Type } from "@sinclair/typebox";
4
4
  import { getSphere } from "../sphere.js";
5
- import { resolveCoinId, getCoinSymbol, getCoinDecimals, toSmallestUnit } from "../assets.js";
5
+ import { resolveCoinId, getCoinSymbol, getCoinDecimals, getCoinId, toSmallestUnit } from "../assets.js";
6
6
  import { validateRecipient } from "../validation.js";
7
7
 
8
8
  export const requestPaymentTool = {
@@ -31,6 +31,11 @@ export const requestPaymentTool = {
31
31
  throw new Error(`Unknown coin "${params.coin}".`);
32
32
  }
33
33
 
34
+ const sdkCoinId = getCoinId(coinId);
35
+ if (!sdkCoinId) {
36
+ throw new Error(`No coin ID found for "${params.coin}".`);
37
+ }
38
+
34
39
  const decimals = getCoinDecimals(coinId) ?? 0;
35
40
  const amountSmallest = toSmallestUnit(params.amount, decimals);
36
41
  const symbol = getCoinSymbol(coinId);
@@ -39,7 +44,7 @@ export const requestPaymentTool = {
39
44
 
40
45
  const result = await sphere.payments.sendPaymentRequest(recipient, {
41
46
  amount: amountSmallest,
42
- coinId,
47
+ coinId: sdkCoinId,
43
48
  message: params.message,
44
49
  });
45
50
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { Type } from "@sinclair/typebox";
4
4
  import { getSphere } from "../sphere.js";
5
- import { resolveCoinId, getCoinSymbol, getCoinDecimals, toSmallestUnit } from "../assets.js";
5
+ import { resolveCoinId, getCoinSymbol, getCoinDecimals, getCoinId, toSmallestUnit } from "../assets.js";
6
6
  import { validateRecipient } from "../validation.js";
7
7
 
8
8
  export const sendTokensTool = {
@@ -31,6 +31,11 @@ export const sendTokensTool = {
31
31
  throw new Error(`Unknown coin "${params.coin}".`);
32
32
  }
33
33
 
34
+ const sdkCoinId = getCoinId(coinId);
35
+ if (!sdkCoinId) {
36
+ throw new Error(`No coin ID found for "${params.coin}".`);
37
+ }
38
+
34
39
  const decimals = getCoinDecimals(coinId) ?? 0;
35
40
  const amountSmallest = toSmallestUnit(params.amount, decimals);
36
41
  const symbol = getCoinSymbol(coinId);
@@ -40,7 +45,7 @@ export const sendTokensTool = {
40
45
  const result = await sphere.payments.send({
41
46
  recipient,
42
47
  amount: amountSmallest,
43
- coinId,
48
+ coinId: sdkCoinId,
44
49
  memo: params.memo,
45
50
  });
46
51