@stacknet/keyutils 0.3.1 → 0.4.1
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/components/index.cjs +2 -0
- package/dist/components/index.d.cts +141 -0
- package/dist/components/index.d.ts +141 -0
- package/dist/components/index.js +2 -0
- package/dist/core/index.cjs +1 -0
- package/dist/core/index.d.cts +53 -0
- package/dist/core/index.d.ts +53 -0
- package/dist/core/index.js +1 -0
- package/dist/hooks/index.cjs +2 -0
- package/dist/hooks/index.d.cts +107 -0
- package/dist/hooks/index.d.ts +107 -0
- package/dist/hooks/index.js +2 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +2 -0
- package/dist/types/index.cjs +1 -0
- package/dist/types/index.d.cts +128 -0
- package/dist/types/index.d.ts +128 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/index.cjs +1 -0
- package/dist/utils/index.d.cts +40 -0
- package/dist/utils/index.d.ts +40 -0
- package/dist/utils/index.js +1 -0
- package/package.json +6 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
interface NodeKeyInfo {
|
|
2
|
+
id: string;
|
|
3
|
+
keyIndex?: number | null;
|
|
4
|
+
key: string;
|
|
5
|
+
userId: string;
|
|
6
|
+
status: 'active' | 'inactive' | 'expired' | 'closed' | 'listed';
|
|
7
|
+
tokenBalance: number;
|
|
8
|
+
maxTokens: number;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
expiresAt?: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
paperWork?: string;
|
|
13
|
+
stackId?: string;
|
|
14
|
+
stackName?: string;
|
|
15
|
+
}
|
|
16
|
+
interface LedgerEntry {
|
|
17
|
+
id: string;
|
|
18
|
+
keyId: string;
|
|
19
|
+
type: 'credit' | 'debit' | 'mint' | 'reward';
|
|
20
|
+
amount: number;
|
|
21
|
+
description: string;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
metadata?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
interface PricingInfo {
|
|
26
|
+
priceUsd: number;
|
|
27
|
+
priceCents: number;
|
|
28
|
+
priceSol?: number;
|
|
29
|
+
tokenAllocation: number;
|
|
30
|
+
tokenAllocationFormatted: string;
|
|
31
|
+
currentDay: number;
|
|
32
|
+
currentEpoch: number;
|
|
33
|
+
nextHalvingDate: number;
|
|
34
|
+
daysUntilHalving: number;
|
|
35
|
+
keysSold: number;
|
|
36
|
+
saleActive: boolean;
|
|
37
|
+
saleStartDate: number;
|
|
38
|
+
}
|
|
39
|
+
interface MintResult {
|
|
40
|
+
success: boolean;
|
|
41
|
+
key?: NodeKeyInfo;
|
|
42
|
+
transactionId?: string;
|
|
43
|
+
error?: string;
|
|
44
|
+
}
|
|
45
|
+
type PaymentMethod = 'solana' | 'stripe';
|
|
46
|
+
interface KeyListing {
|
|
47
|
+
id: string;
|
|
48
|
+
keyId: string;
|
|
49
|
+
keyIndex?: number | null;
|
|
50
|
+
sellerId: string;
|
|
51
|
+
askPriceCents: number;
|
|
52
|
+
currency: string;
|
|
53
|
+
tokenBalance: number;
|
|
54
|
+
maxTokens: number;
|
|
55
|
+
paperWork?: string;
|
|
56
|
+
stackId?: string;
|
|
57
|
+
stackName?: string;
|
|
58
|
+
status: 'active' | 'sold' | 'cancelled';
|
|
59
|
+
createdAt: number;
|
|
60
|
+
}
|
|
61
|
+
interface ListingResult {
|
|
62
|
+
listingId: string;
|
|
63
|
+
keyId: string;
|
|
64
|
+
askPriceCents: number;
|
|
65
|
+
currency: string;
|
|
66
|
+
status: string;
|
|
67
|
+
}
|
|
68
|
+
interface DirectTransferResult {
|
|
69
|
+
keyId: string;
|
|
70
|
+
fromUserId: string;
|
|
71
|
+
toUserId: string;
|
|
72
|
+
transferredAt: number;
|
|
73
|
+
}
|
|
74
|
+
type FilingStatus = 'submitted' | 'validated' | 'paid' | 'failed';
|
|
75
|
+
interface FilingResult {
|
|
76
|
+
keyId: string;
|
|
77
|
+
fileHash: string;
|
|
78
|
+
txSignature?: string;
|
|
79
|
+
paperAmount: number;
|
|
80
|
+
status: FilingStatus;
|
|
81
|
+
beneficiary: string;
|
|
82
|
+
filedAt: string;
|
|
83
|
+
}
|
|
84
|
+
interface FilingHistoryEntry extends FilingResult {
|
|
85
|
+
proofPda?: string;
|
|
86
|
+
memo?: string;
|
|
87
|
+
}
|
|
88
|
+
/** A NodeKeyInfo that has a non-empty paperWork payload ready to file. */
|
|
89
|
+
type EligibleKey = NodeKeyInfo & {
|
|
90
|
+
paperWork: string;
|
|
91
|
+
};
|
|
92
|
+
type Platform = 'ios' | 'android' | 'windows' | 'mac' | 'linux';
|
|
93
|
+
interface PlatformDownload {
|
|
94
|
+
platform: Platform;
|
|
95
|
+
label: string;
|
|
96
|
+
url: string;
|
|
97
|
+
compatible: boolean;
|
|
98
|
+
}
|
|
99
|
+
type KeyWidgetTab = 'buy' | 'use' | 'keys';
|
|
100
|
+
interface KeyUtilsConfig {
|
|
101
|
+
apiBaseUrl: string;
|
|
102
|
+
stackId?: string;
|
|
103
|
+
stackName?: string;
|
|
104
|
+
paymentMethods?: PaymentMethod[];
|
|
105
|
+
merchantWallet?: string;
|
|
106
|
+
protocolTreasuryWallet?: string;
|
|
107
|
+
protocolFeeBps?: number;
|
|
108
|
+
stripePublicKey?: string;
|
|
109
|
+
theme?: 'light' | 'dark' | 'system';
|
|
110
|
+
maxQuantity?: number;
|
|
111
|
+
keyImage?: string;
|
|
112
|
+
keyImageClass?: string;
|
|
113
|
+
aispImage?: string;
|
|
114
|
+
termsUrl?: string;
|
|
115
|
+
solanaRpcUrl?: string;
|
|
116
|
+
}
|
|
117
|
+
interface KeyUtilsCallbacks {
|
|
118
|
+
onMintSuccess?: (result: MintResult) => void;
|
|
119
|
+
onMintError?: (error: Error) => void;
|
|
120
|
+
onPaymentStart?: (method: PaymentMethod) => void;
|
|
121
|
+
onPaymentComplete?: (method: PaymentMethod, transactionId: string) => void;
|
|
122
|
+
onListingCreated?: (listing: ListingResult) => void;
|
|
123
|
+
onTransferComplete?: (result: DirectTransferResult) => void;
|
|
124
|
+
onFilingComplete?: (result: FilingResult) => void;
|
|
125
|
+
onFilingError?: (error: Error) => void;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type { DirectTransferResult, EligibleKey, FilingHistoryEntry, FilingResult, FilingStatus, KeyListing, KeyUtilsCallbacks, KeyUtilsConfig, KeyWidgetTab, LedgerEntry, ListingResult, MintResult, NodeKeyInfo, PaymentMethod, Platform, PlatformDownload, PricingInfo };
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge');function i(){if(typeof document>"u")return {};let r=document.cookie.match(/(?:^|;\s*)__csrf=([^;]*)/);return r?{"x-csrf-token":r[1]}:{}}var s=500;function o(r,e){if(typeof r!="string"||r.length===0)return e;let t=r.replace(/[\u0000-\u001F\u007F]/g," ");return t.length>500?t.slice(0,500)+"\u2026":t}async function u(r,e){try{let t=await r.json();if(t&&typeof t=="object"&&"error"in t)return o(t.error,e)}catch{}return e}function f(r,e="#"){if(!r||typeof r!="string")return e;let t=r.trim();if(t===""||t==="#")return e;if(t.startsWith("/")||t.startsWith("./")||t.startsWith("../"))return t;try{let n=new URL(t);if(n.protocol==="http:"||n.protocol==="https:")return n.toString()}catch{}return e}function _(...r){return tailwindMerge.twMerge(clsx.clsx(r))}function x(r){return r==null?"0":r>=1e9?`${(r/1e9).toFixed(1)}B`:r>=1e6?`${(r/1e6).toFixed(1)}M`:r>=1e3?`${(r/1e3).toFixed(1)}K`:r.toLocaleString()}function h(r,e){return e<=0?0:Math.min(100,Math.round(r/e*100))}function y(r){return r>=70?"bg-green-500":r>=30?"bg-yellow-500":"bg-red-500"}function R(r){let e=typeof r=="string"&&/^\d+$/.test(r)?Number(r):r,t=new Date(e);return isNaN(t.getTime())?String(r):t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function E(){if(typeof navigator>"u")return "mac";let r=navigator.userAgent.toLowerCase();return /iphone|ipad|ipod/.test(r)?"ios":/android/.test(r)?"android":/win/.test(r)?"windows":/linux/.test(r)?"linux":"mac"}exports.MAX_ERROR_LEN=s;exports.calculateBalancePercentage=h;exports.clampErrorMessage=o;exports.cn=_;exports.csrfHeaders=i;exports.detectPlatform=E;exports.formatDate=R;exports.formatTokens=x;exports.getBalanceColor=y;exports.readErrorMessage=u;exports.safeUrl=f;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ClassValue } from 'clsx';
|
|
2
|
+
import { Platform } from '../types/index.cjs';
|
|
3
|
+
|
|
4
|
+
/** Read __csrf cookie and return as x-csrf-token header for mutations */
|
|
5
|
+
declare function csrfHeaders(): Record<string, string>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Safely extract a bounded error message from a fetch Response body.
|
|
9
|
+
*
|
|
10
|
+
* Caps the message at MAX_ERROR_LEN to prevent a malicious or misbehaving
|
|
11
|
+
* backend from injecting an arbitrarily large string into the UI. The
|
|
12
|
+
* fallback message is used if the body is not JSON or has no `error` field.
|
|
13
|
+
*/
|
|
14
|
+
declare const MAX_ERROR_LEN = 500;
|
|
15
|
+
declare function clampErrorMessage(msg: unknown, fallback: string): string;
|
|
16
|
+
declare function readErrorMessage(res: Response, fallback: string): Promise<string>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns a safe href value for an anchor or image source.
|
|
20
|
+
*
|
|
21
|
+
* Allows: relative paths (starting with /, ./, ../), and absolute http(s) URLs.
|
|
22
|
+
* Blocks: javascript:, data:, file:, vbscript:, mailto:, etc.
|
|
23
|
+
*
|
|
24
|
+
* React only sanitizes `javascript:` in href attributes by default; this
|
|
25
|
+
* helper closes the gap for `data:` (which can carry HTML/JS) and any other
|
|
26
|
+
* non-network protocol that a misconfigured or malicious config could supply.
|
|
27
|
+
*
|
|
28
|
+
* Returns the supplied `fallback` (default '#') for any input that fails
|
|
29
|
+
* validation, so the markup never renders an unsafe URL.
|
|
30
|
+
*/
|
|
31
|
+
declare function safeUrl(url: string | undefined | null, fallback?: string): string;
|
|
32
|
+
|
|
33
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
34
|
+
declare function formatTokens(amount: number | undefined | null): string;
|
|
35
|
+
declare function calculateBalancePercentage(current: number, max: number): number;
|
|
36
|
+
declare function getBalanceColor(percentage: number): string;
|
|
37
|
+
declare function formatDate(dateString: string | number): string;
|
|
38
|
+
declare function detectPlatform(): Platform;
|
|
39
|
+
|
|
40
|
+
export { MAX_ERROR_LEN, calculateBalancePercentage, clampErrorMessage, cn, csrfHeaders, detectPlatform, formatDate, formatTokens, getBalanceColor, readErrorMessage, safeUrl };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ClassValue } from 'clsx';
|
|
2
|
+
import { Platform } from '../types/index.js';
|
|
3
|
+
|
|
4
|
+
/** Read __csrf cookie and return as x-csrf-token header for mutations */
|
|
5
|
+
declare function csrfHeaders(): Record<string, string>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Safely extract a bounded error message from a fetch Response body.
|
|
9
|
+
*
|
|
10
|
+
* Caps the message at MAX_ERROR_LEN to prevent a malicious or misbehaving
|
|
11
|
+
* backend from injecting an arbitrarily large string into the UI. The
|
|
12
|
+
* fallback message is used if the body is not JSON or has no `error` field.
|
|
13
|
+
*/
|
|
14
|
+
declare const MAX_ERROR_LEN = 500;
|
|
15
|
+
declare function clampErrorMessage(msg: unknown, fallback: string): string;
|
|
16
|
+
declare function readErrorMessage(res: Response, fallback: string): Promise<string>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns a safe href value for an anchor or image source.
|
|
20
|
+
*
|
|
21
|
+
* Allows: relative paths (starting with /, ./, ../), and absolute http(s) URLs.
|
|
22
|
+
* Blocks: javascript:, data:, file:, vbscript:, mailto:, etc.
|
|
23
|
+
*
|
|
24
|
+
* React only sanitizes `javascript:` in href attributes by default; this
|
|
25
|
+
* helper closes the gap for `data:` (which can carry HTML/JS) and any other
|
|
26
|
+
* non-network protocol that a misconfigured or malicious config could supply.
|
|
27
|
+
*
|
|
28
|
+
* Returns the supplied `fallback` (default '#') for any input that fails
|
|
29
|
+
* validation, so the markup never renders an unsafe URL.
|
|
30
|
+
*/
|
|
31
|
+
declare function safeUrl(url: string | undefined | null, fallback?: string): string;
|
|
32
|
+
|
|
33
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
34
|
+
declare function formatTokens(amount: number | undefined | null): string;
|
|
35
|
+
declare function calculateBalancePercentage(current: number, max: number): number;
|
|
36
|
+
declare function getBalanceColor(percentage: number): string;
|
|
37
|
+
declare function formatDate(dateString: string | number): string;
|
|
38
|
+
declare function detectPlatform(): Platform;
|
|
39
|
+
|
|
40
|
+
export { MAX_ERROR_LEN, calculateBalancePercentage, clampErrorMessage, cn, csrfHeaders, detectPlatform, formatDate, formatTokens, getBalanceColor, readErrorMessage, safeUrl };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {clsx}from'clsx';import {twMerge}from'tailwind-merge';function i(){if(typeof document>"u")return {};let r=document.cookie.match(/(?:^|;\s*)__csrf=([^;]*)/);return r?{"x-csrf-token":r[1]}:{}}var s=500;function o(r,e){if(typeof r!="string"||r.length===0)return e;let t=r.replace(/[\u0000-\u001F\u007F]/g," ");return t.length>500?t.slice(0,500)+"\u2026":t}async function u(r,e){try{let t=await r.json();if(t&&typeof t=="object"&&"error"in t)return o(t.error,e)}catch{}return e}function f(r,e="#"){if(!r||typeof r!="string")return e;let t=r.trim();if(t===""||t==="#")return e;if(t.startsWith("/")||t.startsWith("./")||t.startsWith("../"))return t;try{let n=new URL(t);if(n.protocol==="http:"||n.protocol==="https:")return n.toString()}catch{}return e}function _(...r){return twMerge(clsx(r))}function x(r){return r==null?"0":r>=1e9?`${(r/1e9).toFixed(1)}B`:r>=1e6?`${(r/1e6).toFixed(1)}M`:r>=1e3?`${(r/1e3).toFixed(1)}K`:r.toLocaleString()}function h(r,e){return e<=0?0:Math.min(100,Math.round(r/e*100))}function y(r){return r>=70?"bg-green-500":r>=30?"bg-yellow-500":"bg-red-500"}function R(r){let e=typeof r=="string"&&/^\d+$/.test(r)?Number(r):r,t=new Date(e);return isNaN(t.getTime())?String(r):t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function E(){if(typeof navigator>"u")return "mac";let r=navigator.userAgent.toLowerCase();return /iphone|ipad|ipod/.test(r)?"ios":/android/.test(r)?"android":/win/.test(r)?"windows":/linux/.test(r)?"linux":"mac"}export{s as MAX_ERROR_LEN,h as calculateBalancePercentage,o as clampErrorMessage,_ as cn,i as csrfHeaders,E as detectPlatform,R as formatDate,x as formatTokens,y as getBalanceColor,u as readErrorMessage,f as safeUrl};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacknet/keyutils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Reusable components for buying and managing StackNet node keys",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -31,6 +31,11 @@
|
|
|
31
31
|
"types": "./dist/utils/index.d.ts",
|
|
32
32
|
"import": "./dist/utils/index.js",
|
|
33
33
|
"require": "./dist/utils/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./core": {
|
|
36
|
+
"types": "./dist/core/index.d.ts",
|
|
37
|
+
"import": "./dist/core/index.js",
|
|
38
|
+
"require": "./dist/core/index.cjs"
|
|
34
39
|
}
|
|
35
40
|
},
|
|
36
41
|
"files": [
|