@b3dotfun/sdk 0.0.69 → 0.0.70-alpha.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/cjs/anyspend/index.d.ts +1 -0
- package/dist/cjs/anyspend/index.js +1 -0
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +6 -0
- package/dist/cjs/anyspend/react/components/AnySpend.js +13 -1
- package/dist/cjs/anyspend/react/components/AnySpendBondKit.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/AnySpendBondKit.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendBuySpin.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendBuySpin.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +6 -2
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -0
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +3 -1
- package/dist/cjs/anyspend/react/components/AnySpendDepositUpside.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendDepositUpside.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendNFT.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendStakeB3ExactIn.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendStakeUpside.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendStakeUpside.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnySpendStakeUpsideExactIn.js +2 -2
- package/dist/cjs/anyspend/react/components/AnySpendTournament.d.ts +2 -0
- package/dist/cjs/anyspend/react/components/AnySpendTournament.js +1 -1
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +2 -2
- package/dist/cjs/anyspend/react/components/AnyspendSignatureMint.d.ts +2 -1
- package/dist/cjs/anyspend/react/components/AnyspendSignatureMint.js +2 -2
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +2 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOrder.js +2 -1
- package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +16 -0
- package/dist/cjs/anyspend/services/anyspend.d.ts +2 -1
- package/dist/cjs/anyspend/services/anyspend.js +2 -1
- package/dist/cjs/anyspend/types/api.d.ts +295 -0
- package/dist/cjs/anyspend/utils/validation.d.ts +67 -0
- package/dist/cjs/anyspend/utils/validation.js +157 -0
- package/dist/cjs/global-account/react/components/ProfileEditor/ProfileEditor.js +14 -4
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/esm/anyspend/index.d.ts +1 -0
- package/dist/esm/anyspend/index.js +1 -0
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +6 -0
- package/dist/esm/anyspend/react/components/AnySpend.js +13 -1
- package/dist/esm/anyspend/react/components/AnySpendBondKit.d.ts +3 -1
- package/dist/esm/anyspend/react/components/AnySpendBondKit.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendBuySpin.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendBuySpin.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +6 -2
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -0
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +3 -1
- package/dist/esm/anyspend/react/components/AnySpendDepositUpside.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendDepositUpside.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendNFT.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendStakeB3.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendStakeB3.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendStakeB3ExactIn.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendStakeUpside.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendStakeUpside.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnySpendStakeUpsideExactIn.js +2 -2
- package/dist/esm/anyspend/react/components/AnySpendTournament.d.ts +2 -0
- package/dist/esm/anyspend/react/components/AnySpendTournament.js +1 -1
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +2 -2
- package/dist/esm/anyspend/react/components/AnyspendSignatureMint.d.ts +2 -1
- package/dist/esm/anyspend/react/components/AnyspendSignatureMint.js +2 -2
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +2 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOrder.js +2 -1
- package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +16 -0
- package/dist/esm/anyspend/services/anyspend.d.ts +2 -1
- package/dist/esm/anyspend/services/anyspend.js +2 -1
- package/dist/esm/anyspend/types/api.d.ts +295 -0
- package/dist/esm/anyspend/utils/validation.d.ts +67 -0
- package/dist/esm/anyspend/utils/validation.js +153 -0
- package/dist/esm/global-account/react/components/ProfileEditor/ProfileEditor.js +14 -4
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/types/anyspend/index.d.ts +1 -0
- package/dist/types/anyspend/react/components/AnySpend.d.ts +6 -0
- package/dist/types/anyspend/react/components/AnySpendBondKit.d.ts +3 -1
- package/dist/types/anyspend/react/components/AnySpendBuySpin.d.ts +2 -1
- package/dist/types/anyspend/react/components/AnySpendCustom.d.ts +1 -0
- package/dist/types/anyspend/react/components/AnySpendCustomExactIn.d.ts +1 -0
- package/dist/types/anyspend/react/components/AnySpendDepositUpside.d.ts +2 -1
- package/dist/types/anyspend/react/components/AnySpendNFT.d.ts +2 -1
- package/dist/types/anyspend/react/components/AnySpendStakeB3.d.ts +2 -1
- package/dist/types/anyspend/react/components/AnySpendStakeB3ExactIn.d.ts +2 -1
- package/dist/types/anyspend/react/components/AnySpendStakeUpside.d.ts +2 -1
- package/dist/types/anyspend/react/components/AnySpendStakeUpsideExactIn.d.ts +2 -1
- package/dist/types/anyspend/react/components/AnySpendTournament.d.ts +2 -0
- package/dist/types/anyspend/react/components/AnyspendDepositHype.d.ts +2 -1
- package/dist/types/anyspend/react/components/AnyspendSignatureMint.d.ts +2 -1
- package/dist/types/anyspend/react/hooks/useAnyspendCreateOrder.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +16 -0
- package/dist/types/anyspend/services/anyspend.d.ts +2 -1
- package/dist/types/anyspend/types/api.d.ts +295 -0
- package/dist/types/anyspend/utils/validation.d.ts +67 -0
- package/dist/types/global-account/react/stores/useModalStore.d.ts +4 -0
- package/package.json +3 -2
- package/src/anyspend/index.ts +1 -0
- package/src/anyspend/react/components/AnySpend.tsx +23 -0
- package/src/anyspend/react/components/AnySpendBondKit.tsx +3 -1
- package/src/anyspend/react/components/AnySpendBuySpin.tsx +3 -0
- package/src/anyspend/react/components/AnySpendCustom.tsx +8 -1
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +4 -0
- package/src/anyspend/react/components/AnySpendDepositUpside.tsx +3 -0
- package/src/anyspend/react/components/AnySpendNFT.tsx +3 -0
- package/src/anyspend/react/components/AnySpendStakeB3.tsx +3 -0
- package/src/anyspend/react/components/AnySpendStakeB3ExactIn.tsx +3 -0
- package/src/anyspend/react/components/AnySpendStakeUpside.tsx +3 -0
- package/src/anyspend/react/components/AnySpendStakeUpsideExactIn.tsx +3 -0
- package/src/anyspend/react/components/AnySpendTournament.tsx +3 -0
- package/src/anyspend/react/components/AnyspendDepositHype.tsx +3 -0
- package/src/anyspend/react/components/AnyspendSignatureMint.tsx +3 -0
- package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +2 -0
- package/src/anyspend/react/hooks/useAnyspendCreateOrder.ts +13 -1
- package/src/anyspend/services/anyspend.ts +3 -0
- package/src/anyspend/types/api.ts +295 -0
- package/src/anyspend/utils/validation.ts +209 -0
- package/src/global-account/react/components/ProfileEditor/ProfileEditor.tsx +20 -6
- package/src/global-account/react/stores/useModalStore.ts +4 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
export interface ValidationResult {
|
|
2
|
+
isValid: boolean;
|
|
3
|
+
error?: string;
|
|
4
|
+
cleaned?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface StringValidationOptions {
|
|
8
|
+
// Required/Optional
|
|
9
|
+
required?: boolean;
|
|
10
|
+
defaultValue?: () => string; // Generator for default (e.g., UUID)
|
|
11
|
+
|
|
12
|
+
// Length constraints
|
|
13
|
+
minLength?: number;
|
|
14
|
+
maxLength?: number;
|
|
15
|
+
|
|
16
|
+
// Character constraints
|
|
17
|
+
pattern?: RegExp;
|
|
18
|
+
patternErrorMessage?: string;
|
|
19
|
+
|
|
20
|
+
// Pre-processing
|
|
21
|
+
trim?: boolean; // Default: true
|
|
22
|
+
toLowerCase?: boolean;
|
|
23
|
+
toUpperCase?: boolean;
|
|
24
|
+
|
|
25
|
+
// Custom validation
|
|
26
|
+
customValidator?: (value: string) => { valid: boolean; error?: string };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Generic string validator with configurable rules
|
|
31
|
+
*/
|
|
32
|
+
export function validateString(value: string | undefined, options: StringValidationOptions): ValidationResult {
|
|
33
|
+
const {
|
|
34
|
+
required = false,
|
|
35
|
+
defaultValue,
|
|
36
|
+
minLength,
|
|
37
|
+
maxLength,
|
|
38
|
+
pattern,
|
|
39
|
+
patternErrorMessage,
|
|
40
|
+
trim = true,
|
|
41
|
+
toLowerCase = false,
|
|
42
|
+
toUpperCase = false,
|
|
43
|
+
customValidator,
|
|
44
|
+
} = options;
|
|
45
|
+
|
|
46
|
+
// Handle empty/undefined
|
|
47
|
+
if (!value || (trim && value.trim() === "")) {
|
|
48
|
+
if (required && !defaultValue) {
|
|
49
|
+
return { isValid: false, error: "This field is required" };
|
|
50
|
+
}
|
|
51
|
+
if (defaultValue) {
|
|
52
|
+
return { isValid: true, cleaned: defaultValue() };
|
|
53
|
+
}
|
|
54
|
+
return { isValid: true, cleaned: undefined };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Pre-processing
|
|
58
|
+
let cleaned = value;
|
|
59
|
+
if (trim) cleaned = cleaned.trim();
|
|
60
|
+
if (toLowerCase) cleaned = cleaned.toLowerCase();
|
|
61
|
+
if (toUpperCase) cleaned = cleaned.toUpperCase();
|
|
62
|
+
|
|
63
|
+
// Length validation
|
|
64
|
+
if (minLength !== undefined && cleaned.length < minLength) {
|
|
65
|
+
return {
|
|
66
|
+
isValid: false,
|
|
67
|
+
error: `Minimum length is ${minLength} characters`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (maxLength !== undefined && cleaned.length > maxLength) {
|
|
72
|
+
return {
|
|
73
|
+
isValid: false,
|
|
74
|
+
error: `Maximum length is ${maxLength} characters`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Pattern validation
|
|
79
|
+
if (pattern && !pattern.test(cleaned)) {
|
|
80
|
+
return {
|
|
81
|
+
isValid: false,
|
|
82
|
+
error: patternErrorMessage || "Invalid format",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Custom validation
|
|
87
|
+
if (customValidator) {
|
|
88
|
+
const customResult = customValidator(cleaned);
|
|
89
|
+
if (!customResult.valid) {
|
|
90
|
+
return { isValid: false, error: customResult.error };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return { isValid: true, cleaned };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Common validation patterns
|
|
99
|
+
*/
|
|
100
|
+
export const ValidationPatterns = {
|
|
101
|
+
ALPHANUMERIC: /^[a-zA-Z0-9]+$/,
|
|
102
|
+
ALPHANUMERIC_WITH_DASH_UNDERSCORE: /^[a-zA-Z0-9_-]+$/,
|
|
103
|
+
ALPHANUMERIC_WITH_SAFE_CHARS: /^[a-zA-Z0-9_.\-]+$/,
|
|
104
|
+
SAFE_IDENTIFIER: /^[a-zA-Z0-9_.\-]+$/, // For IDs, references
|
|
105
|
+
NO_CONTROL_CHARS: /^[^\x00-\x1F\x7F]+$/,
|
|
106
|
+
URL_SAFE: /^[a-zA-Z0-9_.\-~]+$/,
|
|
107
|
+
NUMERIC: /^\d+$/,
|
|
108
|
+
HEX: /^[0-9a-fA-F]+$/,
|
|
109
|
+
} as const;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Pre-configured validators for common use cases
|
|
113
|
+
*/
|
|
114
|
+
export const Validators = {
|
|
115
|
+
/**
|
|
116
|
+
* Validates client reference IDs (alphanumeric + safe chars)
|
|
117
|
+
* Returns undefined if not provided
|
|
118
|
+
*/
|
|
119
|
+
clientReferenceId: (value?: string) =>
|
|
120
|
+
validateString(value, {
|
|
121
|
+
required: false,
|
|
122
|
+
maxLength: 255,
|
|
123
|
+
pattern: ValidationPatterns.SAFE_IDENTIFIER,
|
|
124
|
+
patternErrorMessage: "Only letters, numbers, hyphens, underscores, and dots allowed",
|
|
125
|
+
trim: true,
|
|
126
|
+
customValidator: val => {
|
|
127
|
+
// Additional security checks
|
|
128
|
+
const dangerous = /('|"|;|--|\/\*|\*\/|<|>|script)/i;
|
|
129
|
+
if (dangerous.test(val)) {
|
|
130
|
+
return {
|
|
131
|
+
valid: false,
|
|
132
|
+
error: "Contains potentially dangerous characters",
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return { valid: true };
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Validates alphanumeric strings (letters and numbers only)
|
|
141
|
+
*/
|
|
142
|
+
alphanumeric: (value?: string, required = false) =>
|
|
143
|
+
validateString(value, {
|
|
144
|
+
required,
|
|
145
|
+
pattern: ValidationPatterns.ALPHANUMERIC,
|
|
146
|
+
patternErrorMessage: "Only letters and numbers allowed",
|
|
147
|
+
trim: true,
|
|
148
|
+
}),
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Validates wallet addresses (hex format)
|
|
152
|
+
*/
|
|
153
|
+
walletAddress: (value?: string, required = true) =>
|
|
154
|
+
validateString(value, {
|
|
155
|
+
required,
|
|
156
|
+
minLength: 42,
|
|
157
|
+
maxLength: 42,
|
|
158
|
+
pattern: /^0x[a-fA-F0-9]{40}$/,
|
|
159
|
+
patternErrorMessage: "Invalid wallet address format",
|
|
160
|
+
trim: true,
|
|
161
|
+
toLowerCase: true,
|
|
162
|
+
}),
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Validates order IDs (UUID format)
|
|
166
|
+
*/
|
|
167
|
+
orderId: (value?: string) =>
|
|
168
|
+
validateString(value, {
|
|
169
|
+
required: false,
|
|
170
|
+
pattern: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
|
|
171
|
+
patternErrorMessage: "Invalid order ID format",
|
|
172
|
+
trim: true,
|
|
173
|
+
toLowerCase: true,
|
|
174
|
+
}),
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Validates URL-safe strings
|
|
178
|
+
*/
|
|
179
|
+
urlSafe: (value?: string, maxLength = 255) =>
|
|
180
|
+
validateString(value, {
|
|
181
|
+
maxLength,
|
|
182
|
+
pattern: ValidationPatterns.URL_SAFE,
|
|
183
|
+
patternErrorMessage: "Contains invalid URL characters",
|
|
184
|
+
trim: true,
|
|
185
|
+
}),
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Validates safe identifiers (no injection risks)
|
|
189
|
+
*/
|
|
190
|
+
safeIdentifier: (value?: string, required = false) =>
|
|
191
|
+
validateString(value, {
|
|
192
|
+
required,
|
|
193
|
+
maxLength: 255,
|
|
194
|
+
pattern: ValidationPatterns.SAFE_IDENTIFIER,
|
|
195
|
+
patternErrorMessage: "Invalid identifier format",
|
|
196
|
+
customValidator: val => {
|
|
197
|
+
// Additional security checks
|
|
198
|
+
const dangerous = /('|"|;|--|\/\*|\*\/|<|>|script)/i;
|
|
199
|
+
if (dangerous.test(val)) {
|
|
200
|
+
return {
|
|
201
|
+
valid: false,
|
|
202
|
+
error: "Contains potentially dangerous characters",
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return { valid: true };
|
|
206
|
+
},
|
|
207
|
+
trim: true,
|
|
208
|
+
}),
|
|
209
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import { ens_normalize } from "@adraffy/ens-normalize";
|
|
3
4
|
import { Users } from "@b3dotfun/b3-api";
|
|
4
5
|
import app from "@b3dotfun/sdk/global-account/app";
|
|
5
6
|
import { Button, useB3, useProfile } from "@b3dotfun/sdk/global-account/react";
|
|
@@ -122,12 +123,25 @@ export function ProfileEditor({ onSuccess, className }: ProfileEditorProps) {
|
|
|
122
123
|
|
|
123
124
|
// Update username if changed (this will use the updated user from avatar change if both were updated)
|
|
124
125
|
if (hasUsernameChange && user?._id) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
)
|
|
126
|
+
const sanitizedUsername = ens_normalize(username);
|
|
127
|
+
const b3Username = `${sanitizedUsername}.b3.fun`;
|
|
128
|
+
const usernameSignMessage = `Register "${b3Username}"`;
|
|
129
|
+
const usernameSignature = await account?.signMessage({ message: usernameSignMessage });
|
|
130
|
+
|
|
131
|
+
if (!usernameSignature) {
|
|
132
|
+
throw new Error("Failed to sign username registration message");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
console.log("@@usernameSignature", usernameSignature);
|
|
136
|
+
|
|
137
|
+
// Register username with ENS
|
|
138
|
+
// Note: Type assertion needed until @b3dotfun/b3-api package is updated with RegisterUsername type
|
|
139
|
+
updatedUser = (await app
|
|
140
|
+
.service("users")
|
|
141
|
+
.registerUsername(
|
|
142
|
+
{ username, message: usernameSignMessage, hash: usernameSignature },
|
|
143
|
+
{} as any,
|
|
144
|
+
)) as unknown as Users;
|
|
131
145
|
}
|
|
132
146
|
|
|
133
147
|
// Update user state
|
|
@@ -128,6 +128,8 @@ export interface AnySpendModalProps extends BaseModalProps {
|
|
|
128
128
|
destinationTokenChainId?: number;
|
|
129
129
|
/** Custom USD input values for quick amount buttons in fiat onramp */
|
|
130
130
|
customUsdInputValues?: string[];
|
|
131
|
+
/** Client-provided reference ID for tracking orders */
|
|
132
|
+
clientReferenceId?: string;
|
|
131
133
|
}
|
|
132
134
|
|
|
133
135
|
/**
|
|
@@ -143,6 +145,8 @@ export interface AnySpendNftProps extends BaseModalProps {
|
|
|
143
145
|
recipientAddress?: string;
|
|
144
146
|
/** Callback function called when the NFT is successfully transferred */
|
|
145
147
|
onSuccess?: (txHash?: string) => void;
|
|
148
|
+
/** Client-provided reference ID for tracking orders */
|
|
149
|
+
clientReferenceId?: string;
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
/**
|