uvd-x402-sdk 2.111.0 → 2.112.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uvd-x402-sdk",
3
- "version": "2.111.0",
3
+ "version": "2.112.0",
4
4
  "description": "x402 Payment SDK - Gasless crypto payments across 31 networks via Ultravioleta facilitator. Supports EVM (including HashKey Chain, Scroll, SKALE Base, Robinhood Chain, Arc mainnet + testnet), Solana, Fogo, Stellar, NEAR, Algorand, Sui, XRP Ledger, and native Hedera mainnet + testnet. Features: ERC-8004 Trustless Agents, Escrow/Refunds, multi-stablecoin (USDC, EURC, AUSD, PYUSD, USDT, USDG).",
5
5
  "author": "Ultravioleta DAO <ultravioletadao@gmail.com>",
6
6
  "license": "MIT",
@@ -0,0 +1,81 @@
1
+ /** Internal runtime schemas for the deployed NEAR ERC-8004 interface. */
2
+ import { account, fullMatch, uint } from './encoding';
3
+ export type Check = (value: unknown) => boolean;
4
+ export const object = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);
5
+ export const text: Check = v => typeof v === 'string' && !/[\ud800-\udfff]/u.test(v);
6
+ export const bool: Check = v => typeof v === 'boolean';
7
+ export const nullable = (check: Check): Check => v => v === null || check(v);
8
+ export const list = (check: Check, max = 100): Check => v => Array.isArray(v) && v.length <= max && v.every(check);
9
+ export const num = (max: number): Check => v => typeof v === 'number' && Number.isSafeInteger(v) && v >= 0 && v <= max;
10
+ export const exact = (expected: unknown): Check => v => v === expected;
11
+ export function shape(required: Record<string, Check>, optional: Record<string, Check> = {}): Check {
12
+ return v => object(v) && Object.keys(v).every(k => Object.hasOwn(required, k) || Object.hasOwn(optional, k)) &&
13
+ Object.entries(required).every(([k, check]) => Object.hasOwn(v, k) && check(v[k])) &&
14
+ Object.entries(optional).every(([k, check]) => !Object.hasOwn(v, k) || check(v[k]));
15
+ }
16
+ export const unsigned = (bits: number): Check => v => {
17
+ if (typeof v !== 'string' || v.length > 78) return false;
18
+ try { uint(v, bits, 'integer'); return true; } catch { return false; }
19
+ };
20
+ export const u64 = unsigned(64), u128 = unsigned(128), u256 = unsigned(256);
21
+ export const positiveIndex: Check = v => u64(v) && v !== '0';
22
+ export const signed = (digits: number): Check => v => typeof v === 'string' && v.length <= digits + 1 &&
23
+ fullMatch(/^(0|-?[1-9][0-9]*)$/, v) && v.replace('-', '').length <= digits;
24
+ export const valueCheck: Check = v => signed(39)(v) && BigInt(v as string) >= -(10n ** 38n) && BigInt(v as string) <= 10n ** 38n;
25
+ export const decimals = num(18);
26
+ export const accountCheck: Check = v => { try { account(v as string, 'account'); return true; } catch { return false; } };
27
+ export const byteLength = (v: string): number => new TextEncoder().encode(v).length;
28
+ export const boundedText = (max: number): Check => v => text(v) && byteLength(v as string) <= max;
29
+ export const tag: Check = v => boundedText(64)(v) && !/\p{Cc}/u.test(v as string);
30
+ export const label: Check = v => typeof v === 'string' && fullMatch(/^[a-z0-9_-]{0,32}$/, v);
31
+ export const proof: Check = v => typeof v === 'string' && fullMatch(/^[\x21-\x7e]{1,128}$/, v);
32
+ export const hash: Check = v => typeof v === 'string' && fullMatch(/^[0-9a-f]{64}$/, v);
33
+ export const key: Check = v => typeof v === 'string' && fullMatch(/^[A-Za-z0-9._:/-]{1,64}$/, v);
34
+ export const uri = (max: number, empty = false): Check => v => typeof v === 'string' &&
35
+ ((empty && v === '') || (v.length <= max && fullMatch(/^[A-Za-z][A-Za-z0-9+.-]*:[A-Za-z0-9\-._~:/?#\[\]@!$&'()*+,;=%]+$/, v)));
36
+ export function base64(bytes: Uint8Array): string { return btoa(Array.from(bytes, b => String.fromCharCode(b)).join('')); }
37
+ export function unbase64(value: string): Uint8Array {
38
+ if (typeof value !== 'string' || !fullMatch(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/, value)) throw new Error('Invalid base64');
39
+ const bytes = Uint8Array.from(atob(value), c => c.charCodeAt(0));
40
+ if (base64(bytes) !== value) throw new Error('Noncanonical base64');
41
+ return bytes;
42
+ }
43
+ export const base64Check = (max: number): Check => v => {
44
+ if (typeof v !== 'string' || v.length > Math.ceil(max / 3) * 4) return false;
45
+ try { return unbase64(v).length <= max; } catch { return false; }
46
+ };
47
+ export function check(v: unknown, valid: Check, name: string): void { if (!valid(v)) throw new Error(`Invalid ${name}`); }
48
+ export const metadataEntry = shape({ metadata_key: v => key(v) && v !== 'agentWallet', metadata_value: base64Check(1024) });
49
+ const version = { erc8004_version: exact('2.0.0'), events_standard: exact('erc8004'), events_version: exact('1.0.0') };
50
+ export const identityConfigCheck = shape({ contract: exact('erc8004-identity'), ...version, total_agents: u64,
51
+ register_deposit: u128, token_reserve_bytes: exact(77), storage_byte_cost: u128, min_gas_nft_transfer_call: u64,
52
+ limits: shape({ max_agent_uri_len: exact(8192), max_metadata_key_len: exact(64), max_metadata_value_len: exact(1024),
53
+ max_register_metadata: exact(4), max_approvals: exact(8), max_memo_len: exact(256), max_deadline_delay_ns: exact('300000000000'), max_list_limit: exact(100) }) });
54
+ export const reputationConfigCheck = shape({ contract: exact('erc8004-reputation'), ...version, identity_registry: accountCheck,
55
+ feedback_deposit: u128, min_gas_give_feedback: u64, feedback_proof_deposit: u128, min_gas_give_feedback_with_proof: u64,
56
+ max_endpoint_len: exact(1024), max_feedback_uri_len: exact(4096), max_response_uri_len: exact(4096), max_tag_len: exact(64), max_list_limit: exact(100) });
57
+ export const verifierConfigCheck = shape({ contract: exact('erc8004-arras-verifier'), escrow: accountCheck,
58
+ min_gas_verify: u64, gas_get_payment: u64, gas_on_payment: u64 });
59
+ export const feedbackFields = { value: valueCheck, value_decimals: decimals, tag1: tag, tag2: tag };
60
+ export const feedbackCheck = shape({ ...feedbackFields, is_revoked: bool });
61
+ export const proofFields = { verifier: accountCheck, proof, counterparty: accountCheck, role: label, context: label, weight: u128 };
62
+ export const proofCheck = shape(proofFields);
63
+ export const refFields = { agent_id: u64, client_address: accountCheck, feedback_index: positiveIndex };
64
+ export const refCheck = shape(refFields);
65
+ export const summaryFields = { count: u64, summary_value: signed(56), summary_value_decimals: decimals };
66
+ export const summaryCheck = shape(summaryFields);
67
+ export const verifiedSummaryCheck = shape({ ...summaryFields, weight_sum: u256 });
68
+ export const tokenMetadataCheck = shape({ title: nullable(text), description: nullable(text), media: nullable(uri(8192)),
69
+ media_hash: nullable(base64Check(32)), copies: nullable(num(Number.MAX_SAFE_INTEGER)), issued_at: nullable(text),
70
+ expires_at: nullable(text), starts_at: nullable(text), updated_at: nullable(text), extra: nullable(text),
71
+ reference: nullable(uri(8192)), reference_hash: nullable(base64Check(32)) });
72
+ export const tokenCheck = shape({ token_id: u64, owner_id: accountCheck, metadata: tokenMetadataCheck,
73
+ approved_account_ids: v => object(v) && Object.keys(v).length <= 8 && Object.entries(v).every(([k,v]) => accountCheck(k) && num(Number.MAX_SAFE_INTEGER)(v)) });
74
+ export const nftMetadataCheck = shape({ spec: exact('nft-1.0.0'), name: text, symbol: text, icon: nullable(uri(8192)),
75
+ base_uri: nullable(uri(8192)), reference: nullable(uri(8192)), reference_hash: nullable(base64Check(32)) });
76
+ export const pendingWalletCheck = shape({ wallet: accountCheck, deadline: u64 });
77
+ export const agentCheck = shape({ owner_id: accountCheck, agent_wallet: nullable(accountCheck), authorized: bool });
78
+ const allFields = { clients: list(accountCheck), feedback_indexes: list(positiveIndex), values: list(valueCheck),
79
+ value_decimals: list(decimals), tag1s: list(tag), tag2s: list(tag), revoked_statuses: list(bool) };
80
+ export const allFeedbackCheck: Check = v => shape(allFields)(v) && object(v) &&
81
+ Object.values(v).every(a => (a as unknown[]).length === (v.clients as unknown[]).length);