@bleepay/core 0.0.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.
@@ -0,0 +1,349 @@
1
+ type SignInInput = {
2
+ type: 'resource';
3
+ data: SignInWithResourceInput;
4
+ };
5
+ type SignInResponse = {
6
+ authorization: {
7
+ token: string;
8
+ expiresIn: string;
9
+ };
10
+ };
11
+ type SignInWithResourceInput = {
12
+ resource: string;
13
+ };
14
+ declare const authApi: {
15
+ signIn(signInInput: SignInInput): Promise<SignInResponse>;
16
+ };
17
+
18
+ type ApiResponse<T> = {
19
+ data: T;
20
+ status: number;
21
+ };
22
+ type ApiError = {
23
+ code: string;
24
+ message: string;
25
+ status: number;
26
+ };
27
+ declare const apiClient: {
28
+ baseUrl: string;
29
+ timeout: number;
30
+ sessionToken: string | null;
31
+ request<T>(method: string, path: string, body?: unknown): Promise<ApiResponse<T>>;
32
+ setSessionToken(token: string): void;
33
+ get<T>(path: string): Promise<ApiResponse<T>>;
34
+ post<T>(path: string, body: unknown): Promise<ApiResponse<T>>;
35
+ put<T>(path: string, body: unknown): Promise<ApiResponse<T>>;
36
+ delete<T>(path: string): Promise<ApiResponse<T>>;
37
+ };
38
+
39
+ declare enum SessionType {
40
+ Default = "SESSION_DEFAULT"
41
+ }
42
+ declare enum SessionFormat {
43
+ Numeric = "numeric",
44
+ Alphanum = "alphanum"
45
+ }
46
+ declare enum SessionStatus {
47
+ Open = "OPEN",
48
+ Negotiating = "NEGOTIATING",
49
+ Established = "ESTABLISHED",
50
+ Closed = "CLOSED",
51
+ Expired = "EXPIRED",
52
+ TimedOut = "TIMED_OUT"
53
+ }
54
+ type SessionPayer = {
55
+ address: string;
56
+ };
57
+ type Session = {
58
+ id: string;
59
+ contextId: string | null;
60
+ payerId: string | null;
61
+ payeeId: string | null;
62
+ type: SessionType;
63
+ format: SessionFormat;
64
+ code: string;
65
+ payers: SessionPayer[];
66
+ status: SessionStatus;
67
+ expiresAt: string;
68
+ timeoutAt: string;
69
+ };
70
+
71
+ type SolanaPayerInstructionKey = {
72
+ pubkey: string;
73
+ isSigner?: boolean;
74
+ isWritable?: boolean;
75
+ };
76
+ type SolanaPayerInstruction = {
77
+ programId: string;
78
+ keys: SolanaPayerInstructionKey[];
79
+ data?: string;
80
+ };
81
+ type SolanaPayeeInstructionKey = {
82
+ pubkey: string;
83
+ isWritable?: boolean;
84
+ };
85
+ type SolanaPayeeInstruction = {
86
+ programId: string;
87
+ accounts: SolanaPayeeInstructionKey[];
88
+ data?: string;
89
+ };
90
+ type SolanaInstruction = SolanaPayerInstruction & SolanaPayeeInstruction;
91
+ type EthereumNativeMethod = {
92
+ method: string;
93
+ params: object;
94
+ };
95
+ type NativeMethod = EthereumNativeMethod;
96
+ type EthereumNativeSendTransaction = {
97
+ from: string;
98
+ to: string;
99
+ value: string;
100
+ data: string;
101
+ };
102
+ type SolanaNativeSendTransaction = {
103
+ feePayer: string;
104
+ recentBlockhash?: string;
105
+ instructions: SolanaInstruction[];
106
+ };
107
+ type NativeSendTransaction = EthereumNativeSendTransaction | SolanaNativeSendTransaction;
108
+ type EthereumNativeCallTransaction = {
109
+ from: string;
110
+ to: string;
111
+ value: string;
112
+ data: string;
113
+ };
114
+ type SolanaNativeCallTransaction = {
115
+ feePayer: string;
116
+ recentBlockhash?: string;
117
+ instructions: SolanaInstruction[];
118
+ };
119
+ type NativeCallTransaction = EthereumNativeCallTransaction | SolanaNativeCallTransaction;
120
+ type PaymentRequestWallet = {
121
+ address: string;
122
+ };
123
+ type PaymentRequest$1 = {
124
+ network: string;
125
+ currency: string;
126
+ currencyAddress: string;
127
+ amount: string;
128
+ wallet: PaymentRequestWallet;
129
+ };
130
+ type EthereumPlatformData = {
131
+ network: string;
132
+ chainId: string;
133
+ };
134
+ type SolanaPlatformData = {
135
+ network: string;
136
+ };
137
+ type PlatformData = EthereumPlatformData | SolanaPlatformData;
138
+ type VoucherNetwork = {
139
+ network: string;
140
+ type: 'evm' | 'solana';
141
+ chainId?: string;
142
+ };
143
+ declare enum VoucherFormat {
144
+ Numeric = "numeric",
145
+ Alphanum = "alphanum"
146
+ }
147
+ declare enum VoucherType {
148
+ Custom = "VOUCHER_CUSTOM",
149
+ Simple = "VOUCHER_SIMPLE"
150
+ }
151
+ declare enum VoucherStatus {
152
+ Reserved = "RESERVED",
153
+ Redeemed = "REDEEMED",
154
+ Discarded = "DISCARDED",
155
+ Resolved = "RESOLVED",
156
+ Expired = "EXPIRED"
157
+ }
158
+ type VoucherPayer = {
159
+ address: string;
160
+ };
161
+ declare enum VoucherInstructionType {
162
+ NativeRpcMethod = "rpc_method",
163
+ NativeCallTransaction = "call_transaction",
164
+ NativeSendTransaction = "send_transaction"
165
+ }
166
+ type VoucherInstructionRpcMethod = NativeMethod;
167
+ type VoucherInstructionSendTransaction = {
168
+ method: string;
169
+ params: NativeSendTransaction;
170
+ };
171
+ type VoucherInstructionCallTransaction = {
172
+ method: string;
173
+ params: NativeCallTransaction;
174
+ };
175
+ type VoucherInstructionData = VoucherInstructionRpcMethod | VoucherInstructionSendTransaction | VoucherInstructionCallTransaction;
176
+ type VoucherInstruction = {
177
+ type: VoucherInstructionType;
178
+ input: VoucherInstructionData;
179
+ networkIndex?: number;
180
+ };
181
+ declare enum VoucherPaymentType {
182
+ SystemRpcMethod = "system_rpc_method",
183
+ SystemApiMethod = "system_api_method",
184
+ NativeSendTransaction = "send_transaction"
185
+ }
186
+ type VoucherPaymentRpcMethod = NativeMethod;
187
+ type VoucherPaymentSystemApiMethod = {
188
+ submitHook: string;
189
+ statusHook: string;
190
+ };
191
+ type VoucherPaymentSystemRpcMethod = NativeMethod & VoucherPaymentSystemApiMethod;
192
+ type VoucherPaymentSendTransaction = {
193
+ method: string;
194
+ params: NativeSendTransaction;
195
+ };
196
+ type VoucherPaymentData = VoucherPaymentSystemRpcMethod | VoucherPaymentSystemApiMethod | VoucherPaymentSendTransaction;
197
+ type VoucherPayment = {
198
+ type: VoucherPaymentType;
199
+ input: VoucherPaymentData;
200
+ networkIndex?: number;
201
+ };
202
+ type VoucherReceipt = {
203
+ paymentId: string;
204
+ };
205
+ declare enum VoucherInteropStatus {
206
+ Pending = "PENDING",
207
+ Succeeded = "SUCCEEDED",
208
+ Failed = "FAILED",
209
+ Unknown = "UNKNOWN"
210
+ }
211
+ type Voucher = {
212
+ id: string;
213
+ contextId: string | null;
214
+ sessionId: string | null;
215
+ payerId: string | null;
216
+ payeeId: string | null;
217
+ type: VoucherType;
218
+ format: VoucherFormat;
219
+ code: string;
220
+ networks: VoucherNetwork[];
221
+ payers: VoucherPayer[];
222
+ extras: VoucherInstruction[];
223
+ payments: VoucherPayment[];
224
+ receipts: VoucherReceipt[];
225
+ suppliedPayment: PaymentRequest$1 | null;
226
+ expectedPayment: PaymentRequest$1 | null;
227
+ status: VoucherStatus;
228
+ expiresAt: string;
229
+ timeoutAt: string;
230
+ };
231
+
232
+ declare enum ContextType {
233
+ Default = "CONTEXT_DEFAULT"
234
+ }
235
+ declare enum ContextFormat {
236
+ Numeric = "numeric",
237
+ Alphanum = "alphanum"
238
+ }
239
+ declare enum ContextStatus {
240
+ Open = "OPEN",
241
+ Closed = "CLOSED",
242
+ Expired = "EXPIRED"
243
+ }
244
+ type ContextPayer = {
245
+ address: string;
246
+ };
247
+ type ContextResource = Voucher | Session;
248
+ type Context = {
249
+ id: string;
250
+ payerId: string | null;
251
+ payeeId: string | null;
252
+ type: ContextType;
253
+ format: ContextFormat;
254
+ code: string;
255
+ payers: ContextPayer[];
256
+ resources: ContextResource[];
257
+ status: ContextStatus;
258
+ expiresAt: string;
259
+ };
260
+
261
+ declare const contextApi: {
262
+ openContext: (format?: ContextFormat, payers?: ContextPayer[]) => Promise<Context>;
263
+ getContextById: (contextId: string) => Promise<Context>;
264
+ closeContext: (contextId: string, payeeId?: string | null) => Promise<Context>;
265
+ };
266
+
267
+ declare const sessionApi: {
268
+ getSessionById: (sessionId: string) => Promise<Session>;
269
+ openSession: (code: string, type?: SessionType) => Promise<Session>;
270
+ joinSession: (sessionId: string) => Promise<Session>;
271
+ closeSession: (sessionId: string) => Promise<Session>;
272
+ reserveVoucherInSession: (sessionId: string) => Promise<Voucher>;
273
+ };
274
+
275
+ type VoucherInteropStatusResponse = {
276
+ status: VoucherInteropStatus;
277
+ };
278
+ declare const vouchersApi: {
279
+ reserveVoucher: (code: string) => Promise<Voucher>;
280
+ getVoucherById: (voucherId: string) => Promise<Voucher>;
281
+ redeemVoucherById: (voucherId: string, networks?: VoucherNetwork[], payments?: VoucherPayment[], extras?: VoucherInstruction[], expectedPayment?: PaymentRequest | null) => Promise<Voucher>;
282
+ resolveVoucher: (voucherId: string, receipts: VoucherReceipt[]) => Promise<Voucher>;
283
+ discardVoucher: (voucherId: string) => Promise<void>;
284
+ initVoucherInterop: (voucherId: string, submitHook: string, signature: string) => Promise<{
285
+ id: string;
286
+ }>;
287
+ getVoucherInteropStatus: (voucherId: string, statusHook: string) => Promise<VoucherInteropStatusResponse>;
288
+ };
289
+
290
+ declare const API_BASE_URL = "https://payments-sandbox.bleepay.com/api/v1";
291
+ declare const VOUCHER_CODE_LENGTH = 6;
292
+ declare const VOUCHER_CODE_PATTERN: RegExp;
293
+ declare const DEFAULT_TIMEOUT_MS = 30000;
294
+
295
+ declare const storage: {
296
+ get<T>(key: string): T | null;
297
+ set<T>(key: string, value: T): void;
298
+ remove(key: string): void;
299
+ clear(): void;
300
+ };
301
+
302
+ declare const isValidVoucherCode: (code: string) => boolean;
303
+ declare const normalizeVoucherCode: (code: string) => string;
304
+ declare const isValidAddress: (address: string) => boolean;
305
+ declare const isValidChainId: (chainId: unknown) => chainId is number;
306
+ declare const formatAddress: (address: string, prefixLength?: number, suffixLength?: number) => string;
307
+ declare const formatAmount: (amount: string | number, decimals?: number) => string;
308
+
309
+ declare const createVoucherPayer: (address: string) => VoucherPayer;
310
+ declare const createVoucherReceipt: (paymentId: string) => VoucherReceipt;
311
+
312
+ declare const createEvmNetwork: (params: {
313
+ network: string;
314
+ chainId: string | number;
315
+ }) => VoucherNetwork;
316
+ declare const createEvmRpcMethodInstruction: (params: {
317
+ method: string;
318
+ params: object;
319
+ networkIndex?: number;
320
+ }) => VoucherInstruction;
321
+ declare const createEvmCallTransactionInstruction: (params: {
322
+ from: string;
323
+ to: string;
324
+ value: string;
325
+ data: string;
326
+ networkIndex?: number;
327
+ }) => VoucherInstruction;
328
+ declare const createEvmSendTransactionInstruction: (params: {
329
+ from: string;
330
+ to: string;
331
+ value: string;
332
+ data: string;
333
+ networkIndex?: number;
334
+ }) => VoucherInstruction;
335
+ declare const createEvmSystemRpcMethodPayment: (params: {
336
+ method: string;
337
+ params: object;
338
+ networkIndex?: number;
339
+ }) => VoucherPayment;
340
+ declare const createEvmPayment: (params: {
341
+ from: string;
342
+ to: string;
343
+ value: string;
344
+ data?: string;
345
+ networkIndex?: number;
346
+ }) => VoucherPayment;
347
+ declare const isEvmNetwork: (network: VoucherNetwork) => boolean;
348
+
349
+ export { API_BASE_URL, type ApiError, type ApiResponse, type Context, ContextFormat, type ContextPayer, type ContextResource, ContextStatus, ContextType, DEFAULT_TIMEOUT_MS, type EthereumNativeCallTransaction, type EthereumNativeMethod, type EthereumNativeSendTransaction, type EthereumPlatformData, type NativeCallTransaction, type NativeMethod, type NativeSendTransaction, type PaymentRequest$1 as PaymentRequest, type PaymentRequestWallet, type PlatformData, type Session, SessionFormat, type SessionPayer, SessionStatus, SessionType, type SignInInput, type SignInResponse, type SignInWithResourceInput, type SolanaInstruction, type SolanaNativeCallTransaction, type SolanaNativeSendTransaction, type SolanaPayeeInstruction, type SolanaPayeeInstructionKey, type SolanaPayerInstruction, type SolanaPayerInstructionKey, type SolanaPlatformData, VOUCHER_CODE_LENGTH, VOUCHER_CODE_PATTERN, type Voucher, VoucherFormat, type VoucherInstruction, type VoucherInstructionCallTransaction, type VoucherInstructionData, type VoucherInstructionRpcMethod, type VoucherInstructionSendTransaction, VoucherInstructionType, VoucherInteropStatus, type VoucherNetwork, type VoucherPayer, type VoucherPayment, type VoucherPaymentData, type VoucherPaymentRpcMethod, type VoucherPaymentSendTransaction, type VoucherPaymentSystemApiMethod, type VoucherPaymentSystemRpcMethod, VoucherPaymentType, type VoucherReceipt, VoucherStatus, VoucherType, apiClient, authApi, contextApi, createEvmCallTransactionInstruction, createEvmNetwork, createEvmPayment, createEvmRpcMethodInstruction, createEvmSendTransactionInstruction, createEvmSystemRpcMethodPayment, createVoucherPayer, createVoucherReceipt, formatAddress, formatAmount, isEvmNetwork, isValidAddress, isValidChainId, isValidVoucherCode, normalizeVoucherCode, sessionApi, storage, vouchersApi };
package/dist/index.js ADDED
@@ -0,0 +1,445 @@
1
+ // src/constants/index.ts
2
+ var API_BASE_URL = "https://payments-sandbox.bleepay.com/api/v1";
3
+ var VOUCHER_CODE_LENGTH = 6;
4
+ var VOUCHER_CODE_PATTERN = /^\d{6}$/;
5
+ var DEFAULT_TIMEOUT_MS = 3e4;
6
+
7
+ // src/api/client.ts
8
+ var apiClient = {
9
+ baseUrl: API_BASE_URL,
10
+ timeout: DEFAULT_TIMEOUT_MS,
11
+ sessionToken: null,
12
+ async request(method, path, body) {
13
+ const controller = new AbortController();
14
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
15
+ try {
16
+ const headers = {
17
+ "Content-Type": "application/json"
18
+ };
19
+ if (this.sessionToken) {
20
+ headers.Authorization = `Bearer ${this.sessionToken}`;
21
+ }
22
+ const response = await fetch(`${this.baseUrl}${path}`, {
23
+ method,
24
+ headers,
25
+ body: body ? JSON.stringify(body) : void 0,
26
+ signal: controller.signal
27
+ });
28
+ clearTimeout(timeoutId);
29
+ if (!response.ok) {
30
+ console.log("API error response:", response);
31
+ const error = await response.json();
32
+ throw new Error(error.message || `API error: ${response.status}`);
33
+ }
34
+ const data = await response.json();
35
+ return { data, status: response.status };
36
+ } catch (error) {
37
+ console.error("API request error:", error);
38
+ clearTimeout(timeoutId);
39
+ if (error instanceof Error && error.name === "AbortError") {
40
+ throw new Error("Request timeout");
41
+ }
42
+ throw error;
43
+ }
44
+ },
45
+ setSessionToken(token) {
46
+ this.sessionToken = token;
47
+ },
48
+ async get(path) {
49
+ return this.request("GET", path);
50
+ },
51
+ async post(path, body) {
52
+ return this.request("POST", path, body);
53
+ },
54
+ async put(path, body) {
55
+ return this.request("PUT", path, body);
56
+ },
57
+ async delete(path) {
58
+ return this.request("DELETE", path);
59
+ }
60
+ };
61
+
62
+ // src/api/auth.ts
63
+ var authApi = {
64
+ async signIn(signInInput) {
65
+ const response = await apiClient.post("/auth/sign-in", signInInput);
66
+ return response.data;
67
+ }
68
+ };
69
+
70
+ // src/types/context.ts
71
+ var ContextType = /* @__PURE__ */ ((ContextType2) => {
72
+ ContextType2["Default"] = "CONTEXT_DEFAULT";
73
+ return ContextType2;
74
+ })(ContextType || {});
75
+ var ContextFormat = /* @__PURE__ */ ((ContextFormat2) => {
76
+ ContextFormat2["Numeric"] = "numeric";
77
+ ContextFormat2["Alphanum"] = "alphanum";
78
+ return ContextFormat2;
79
+ })(ContextFormat || {});
80
+ var ContextStatus = /* @__PURE__ */ ((ContextStatus2) => {
81
+ ContextStatus2["Open"] = "OPEN";
82
+ ContextStatus2["Closed"] = "CLOSED";
83
+ ContextStatus2["Expired"] = "EXPIRED";
84
+ return ContextStatus2;
85
+ })(ContextStatus || {});
86
+
87
+ // src/api/context.ts
88
+ var contextApi = {
89
+ openContext: async (format = "numeric" /* Numeric */, payers = []) => {
90
+ const response = await apiClient.post("/vouchers/contexts/context-open", {
91
+ format,
92
+ payers
93
+ });
94
+ return response.data;
95
+ },
96
+ getContextById: async (contextId) => {
97
+ const response = await apiClient.get(`/vouchers/contexts/${contextId}`);
98
+ return response.data;
99
+ },
100
+ closeContext: async (contextId, payeeId = null) => {
101
+ const response = await apiClient.post(
102
+ `/vouchers/contexts/${contextId}/context-close`,
103
+ {
104
+ payeeId
105
+ }
106
+ );
107
+ return response.data;
108
+ }
109
+ };
110
+
111
+ // src/types/session.ts
112
+ var SessionType = /* @__PURE__ */ ((SessionType2) => {
113
+ SessionType2["Default"] = "SESSION_DEFAULT";
114
+ return SessionType2;
115
+ })(SessionType || {});
116
+ var SessionFormat = /* @__PURE__ */ ((SessionFormat2) => {
117
+ SessionFormat2["Numeric"] = "numeric";
118
+ SessionFormat2["Alphanum"] = "alphanum";
119
+ return SessionFormat2;
120
+ })(SessionFormat || {});
121
+ var SessionStatus = /* @__PURE__ */ ((SessionStatus2) => {
122
+ SessionStatus2["Open"] = "OPEN";
123
+ SessionStatus2["Negotiating"] = "NEGOTIATING";
124
+ SessionStatus2["Established"] = "ESTABLISHED";
125
+ SessionStatus2["Closed"] = "CLOSED";
126
+ SessionStatus2["Expired"] = "EXPIRED";
127
+ SessionStatus2["TimedOut"] = "TIMED_OUT";
128
+ return SessionStatus2;
129
+ })(SessionStatus || {});
130
+
131
+ // src/types/voucher.ts
132
+ var VoucherFormat = /* @__PURE__ */ ((VoucherFormat2) => {
133
+ VoucherFormat2["Numeric"] = "numeric";
134
+ VoucherFormat2["Alphanum"] = "alphanum";
135
+ return VoucherFormat2;
136
+ })(VoucherFormat || {});
137
+ var VoucherType = /* @__PURE__ */ ((VoucherType2) => {
138
+ VoucherType2["Custom"] = "VOUCHER_CUSTOM";
139
+ VoucherType2["Simple"] = "VOUCHER_SIMPLE";
140
+ return VoucherType2;
141
+ })(VoucherType || {});
142
+ var VoucherStatus = /* @__PURE__ */ ((VoucherStatus2) => {
143
+ VoucherStatus2["Reserved"] = "RESERVED";
144
+ VoucherStatus2["Redeemed"] = "REDEEMED";
145
+ VoucherStatus2["Discarded"] = "DISCARDED";
146
+ VoucherStatus2["Resolved"] = "RESOLVED";
147
+ VoucherStatus2["Expired"] = "EXPIRED";
148
+ return VoucherStatus2;
149
+ })(VoucherStatus || {});
150
+ var VoucherInstructionType = /* @__PURE__ */ ((VoucherInstructionType2) => {
151
+ VoucherInstructionType2["NativeRpcMethod"] = "rpc_method";
152
+ VoucherInstructionType2["NativeCallTransaction"] = "call_transaction";
153
+ VoucherInstructionType2["NativeSendTransaction"] = "send_transaction";
154
+ return VoucherInstructionType2;
155
+ })(VoucherInstructionType || {});
156
+ var VoucherPaymentType = /* @__PURE__ */ ((VoucherPaymentType2) => {
157
+ VoucherPaymentType2["SystemRpcMethod"] = "system_rpc_method";
158
+ VoucherPaymentType2["SystemApiMethod"] = "system_api_method";
159
+ VoucherPaymentType2["NativeSendTransaction"] = "send_transaction";
160
+ return VoucherPaymentType2;
161
+ })(VoucherPaymentType || {});
162
+ var VoucherInteropStatus = /* @__PURE__ */ ((VoucherInteropStatus2) => {
163
+ VoucherInteropStatus2["Pending"] = "PENDING";
164
+ VoucherInteropStatus2["Succeeded"] = "SUCCEEDED";
165
+ VoucherInteropStatus2["Failed"] = "FAILED";
166
+ VoucherInteropStatus2["Unknown"] = "UNKNOWN";
167
+ return VoucherInteropStatus2;
168
+ })(VoucherInteropStatus || {});
169
+
170
+ // src/api/session.ts
171
+ var sessionApi = {
172
+ getSessionById: async (sessionId) => {
173
+ const response = await apiClient.get(`/vouchers/sessions/${sessionId}`);
174
+ return response.data;
175
+ },
176
+ openSession: async (code, type = "SESSION_DEFAULT" /* Default */) => {
177
+ const response = await apiClient.post("/vouchers/sessions/session-open", {
178
+ code,
179
+ type
180
+ });
181
+ return response.data;
182
+ },
183
+ joinSession: async (sessionId) => {
184
+ const response = await apiClient.post(
185
+ `/vouchers/sessions/${sessionId}/session-join`,
186
+ {}
187
+ );
188
+ return response.data;
189
+ },
190
+ closeSession: async (sessionId) => {
191
+ const response = await apiClient.post(
192
+ `/vouchers/sessions/${sessionId}/session-close`,
193
+ {}
194
+ );
195
+ return response.data;
196
+ },
197
+ reserveVoucherInSession: async (sessionId) => {
198
+ const response = await apiClient.post(
199
+ `/vouchers/sessions/${sessionId}/reserve-voucher`,
200
+ {}
201
+ );
202
+ return response.data;
203
+ }
204
+ };
205
+
206
+ // src/api/vouchers.ts
207
+ var vouchersApi = {
208
+ reserveVoucher: async (code) => {
209
+ const response = await apiClient.post("/vouchers/reserve-voucher", {
210
+ code
211
+ });
212
+ return response.data;
213
+ },
214
+ getVoucherById: async (voucherId) => {
215
+ const response = await apiClient.get(`/vouchers/${voucherId}`);
216
+ return response.data;
217
+ },
218
+ redeemVoucherById: async (voucherId, networks = [], payments = [], extras = [], expectedPayment = null) => {
219
+ const response = await apiClient.post(`/vouchers/${voucherId}/redeem-voucher`, {
220
+ networks,
221
+ extras,
222
+ payments,
223
+ expectedPayment
224
+ });
225
+ return response.data;
226
+ },
227
+ resolveVoucher: async (voucherId, receipts) => {
228
+ const response = await apiClient.post(`/vouchers/${voucherId}/resolve-voucher`, {
229
+ receipts
230
+ });
231
+ return response.data;
232
+ },
233
+ discardVoucher: async (voucherId) => {
234
+ await apiClient.post(`/vouchers/${voucherId}/discard-voucher`, {});
235
+ },
236
+ initVoucherInterop: async (voucherId, submitHook, signature) => {
237
+ const response = await apiClient.post(
238
+ `/vouchers/${voucherId}/submit/${submitHook}`,
239
+ {
240
+ signature
241
+ }
242
+ );
243
+ return response.data;
244
+ },
245
+ getVoucherInteropStatus: async (voucherId, statusHook) => {
246
+ const response = await apiClient.get(
247
+ `/vouchers/${voucherId}/status/${statusHook}`
248
+ );
249
+ return response.data;
250
+ }
251
+ };
252
+
253
+ // src/utils/storage.ts
254
+ var STORAGE_PREFIX = "bleepay_";
255
+ var storage = {
256
+ get(key) {
257
+ if (typeof window === "undefined") return null;
258
+ try {
259
+ const item = window.localStorage.getItem(`${STORAGE_PREFIX}${key}`);
260
+ return item ? JSON.parse(item) : null;
261
+ } catch {
262
+ return null;
263
+ }
264
+ },
265
+ set(key, value) {
266
+ if (typeof window === "undefined") return;
267
+ try {
268
+ window.localStorage.setItem(`${STORAGE_PREFIX}${key}`, JSON.stringify(value));
269
+ } catch {
270
+ }
271
+ },
272
+ remove(key) {
273
+ if (typeof window === "undefined") return;
274
+ try {
275
+ window.localStorage.removeItem(`${STORAGE_PREFIX}${key}`);
276
+ } catch {
277
+ }
278
+ },
279
+ clear() {
280
+ if (typeof window === "undefined") return;
281
+ try {
282
+ const keys = Object.keys(window.localStorage);
283
+ for (const key of keys) {
284
+ if (key.startsWith(STORAGE_PREFIX)) {
285
+ window.localStorage.removeItem(key);
286
+ }
287
+ }
288
+ } catch {
289
+ }
290
+ }
291
+ };
292
+
293
+ // src/utils/validation.ts
294
+ var isValidVoucherCode = (code) => {
295
+ return VOUCHER_CODE_PATTERN.test(code);
296
+ };
297
+ var normalizeVoucherCode = (code) => {
298
+ return code.replace(/\D/g, "").slice(0, VOUCHER_CODE_LENGTH);
299
+ };
300
+ var isValidAddress = (address) => {
301
+ return /^0x[a-fA-F0-9]{40}$/.test(address);
302
+ };
303
+ var isValidChainId = (chainId) => {
304
+ return typeof chainId === "number" && Number.isInteger(chainId) && chainId > 0;
305
+ };
306
+ var formatAddress = (address, prefixLength = 6, suffixLength = 4) => {
307
+ if (!isValidAddress(address)) return address;
308
+ return `${address.slice(0, prefixLength)}...${address.slice(-suffixLength)}`;
309
+ };
310
+ var formatAmount = (amount, decimals = 2) => {
311
+ const num = typeof amount === "string" ? Number.parseFloat(amount) : amount;
312
+ return num.toLocaleString("en-US", {
313
+ minimumFractionDigits: decimals,
314
+ maximumFractionDigits: decimals
315
+ });
316
+ };
317
+
318
+ // src/utils/voucher-common.ts
319
+ var createVoucherPayer = (address) => {
320
+ return {
321
+ address
322
+ };
323
+ };
324
+ var createVoucherReceipt = (paymentId) => {
325
+ return {
326
+ paymentId
327
+ };
328
+ };
329
+
330
+ // src/utils/voucher-evm.ts
331
+ var createEvmNetwork = (params) => {
332
+ return {
333
+ network: params.network,
334
+ type: "evm",
335
+ chainId: String(params.chainId)
336
+ };
337
+ };
338
+ var createEvmRpcMethodInstruction = (params) => {
339
+ return {
340
+ type: "rpc_method" /* NativeRpcMethod */,
341
+ input: {
342
+ method: params.method,
343
+ params: params.params
344
+ },
345
+ networkIndex: params.networkIndex
346
+ };
347
+ };
348
+ var createEvmCallTransactionInstruction = (params) => {
349
+ return {
350
+ type: "call_transaction" /* NativeCallTransaction */,
351
+ input: {
352
+ method: "eth_call",
353
+ params: {
354
+ from: params.from,
355
+ to: params.to,
356
+ value: params.value,
357
+ data: params.data
358
+ }
359
+ },
360
+ networkIndex: params.networkIndex
361
+ };
362
+ };
363
+ var createEvmSendTransactionInstruction = (params) => {
364
+ return {
365
+ type: "send_transaction" /* NativeSendTransaction */,
366
+ input: {
367
+ method: "eth_sendTransaction",
368
+ params: {
369
+ from: params.from,
370
+ to: params.to,
371
+ value: params.value,
372
+ data: params.data
373
+ }
374
+ },
375
+ networkIndex: params.networkIndex
376
+ };
377
+ };
378
+ var createEvmSystemRpcMethodPayment = (params) => {
379
+ return {
380
+ type: "system_rpc_method" /* SystemRpcMethod */,
381
+ input: {
382
+ method: params.method,
383
+ params: params.params
384
+ },
385
+ networkIndex: params.networkIndex
386
+ };
387
+ };
388
+ var createEvmPayment = (params) => {
389
+ return {
390
+ type: "send_transaction" /* NativeSendTransaction */,
391
+ input: {
392
+ method: "eth_sendTransaction",
393
+ params: {
394
+ from: params.from,
395
+ to: params.to,
396
+ value: params.value,
397
+ data: params.data || "0x"
398
+ }
399
+ },
400
+ networkIndex: params.networkIndex
401
+ };
402
+ };
403
+ var isEvmNetwork = (network) => {
404
+ return network.type === "evm";
405
+ };
406
+ export {
407
+ API_BASE_URL,
408
+ ContextFormat,
409
+ ContextStatus,
410
+ ContextType,
411
+ DEFAULT_TIMEOUT_MS,
412
+ SessionFormat,
413
+ SessionStatus,
414
+ SessionType,
415
+ VOUCHER_CODE_LENGTH,
416
+ VOUCHER_CODE_PATTERN,
417
+ VoucherFormat,
418
+ VoucherInstructionType,
419
+ VoucherInteropStatus,
420
+ VoucherPaymentType,
421
+ VoucherStatus,
422
+ VoucherType,
423
+ apiClient,
424
+ authApi,
425
+ contextApi,
426
+ createEvmCallTransactionInstruction,
427
+ createEvmNetwork,
428
+ createEvmPayment,
429
+ createEvmRpcMethodInstruction,
430
+ createEvmSendTransactionInstruction,
431
+ createEvmSystemRpcMethodPayment,
432
+ createVoucherPayer,
433
+ createVoucherReceipt,
434
+ formatAddress,
435
+ formatAmount,
436
+ isEvmNetwork,
437
+ isValidAddress,
438
+ isValidChainId,
439
+ isValidVoucherCode,
440
+ normalizeVoucherCode,
441
+ sessionApi,
442
+ storage,
443
+ vouchersApi
444
+ };
445
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants/index.ts","../src/api/client.ts","../src/api/auth.ts","../src/types/context.ts","../src/api/context.ts","../src/types/session.ts","../src/types/voucher.ts","../src/api/session.ts","../src/api/vouchers.ts","../src/utils/storage.ts","../src/utils/validation.ts","../src/utils/voucher-common.ts","../src/utils/voucher-evm.ts"],"sourcesContent":["export const API_BASE_URL = 'https://payments-sandbox.bleepay.com/api/v1';\n\nexport const VOUCHER_CODE_LENGTH = 6;\nexport const VOUCHER_CODE_PATTERN = /^\\d{6}$/;\n\nexport const DEFAULT_TIMEOUT_MS = 30000;\n","import {API_BASE_URL, DEFAULT_TIMEOUT_MS} from '../constants';\n\nexport type ApiResponse<T> = {\n data: T;\n status: number;\n};\n\nexport type ApiError = {\n code: string;\n message: string;\n status: number;\n};\n\nexport const apiClient = {\n baseUrl: API_BASE_URL,\n timeout: DEFAULT_TIMEOUT_MS,\n sessionToken: null as string | null,\n\n async request<T>(method: string, path: string, body?: unknown): Promise<ApiResponse<T>> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n try {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n if (this.sessionToken) {\n headers.Authorization = `Bearer ${this.sessionToken}`;\n }\n\n const response = await fetch(`${this.baseUrl}${path}`, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n console.log('API error response:', response);\n const error = (await response.json()) as ApiError;\n throw new Error(error.message || `API error: ${response.status}`);\n }\n\n const data = (await response.json()) as T;\n return {data, status: response.status};\n } catch (error) {\n console.error('API request error:', error);\n clearTimeout(timeoutId);\n if (error instanceof Error && error.name === 'AbortError') {\n throw new Error('Request timeout');\n }\n throw error;\n }\n },\n\n setSessionToken(token: string): void {\n this.sessionToken = token;\n },\n\n async get<T>(path: string): Promise<ApiResponse<T>> {\n return this.request<T>('GET', path);\n },\n\n async post<T>(path: string, body: unknown): Promise<ApiResponse<T>> {\n return this.request<T>('POST', path, body);\n },\n\n async put<T>(path: string, body: unknown): Promise<ApiResponse<T>> {\n return this.request<T>('PUT', path, body);\n },\n\n async delete<T>(path: string): Promise<ApiResponse<T>> {\n return this.request<T>('DELETE', path);\n },\n};\n","import {apiClient} from './client';\n\nexport type SignInInput = {\n type: 'resource';\n data: SignInWithResourceInput;\n};\n\nexport type SignInResponse = {\n authorization: {\n token: string;\n expiresIn: string;\n };\n};\n\nexport type SignInWithResourceInput = {\n resource: string;\n};\n\nexport const authApi = {\n async signIn(signInInput: SignInInput): Promise<SignInResponse> {\n const response = await apiClient.post<SignInResponse>('/auth/sign-in', signInInput);\n return response.data;\n },\n};\n","import type {Session} from './session';\nimport type {Voucher} from './voucher';\n\nexport enum ContextType {\n Default = 'CONTEXT_DEFAULT',\n}\n\nexport enum ContextFormat {\n Numeric = 'numeric',\n Alphanum = 'alphanum',\n}\n\nexport enum ContextStatus {\n Open = 'OPEN',\n Closed = 'CLOSED',\n Expired = 'EXPIRED',\n}\n\nexport type ContextPayer = {\n address: string;\n};\n\nexport type ContextResource = Voucher | Session;\n\nexport type Context = {\n id: string;\n payerId: string | null;\n payeeId: string | null;\n type: ContextType;\n format: ContextFormat;\n code: string;\n payers: ContextPayer[];\n resources: ContextResource[];\n status: ContextStatus;\n expiresAt: string;\n};\n","import {Context, ContextFormat, ContextPayer} from '../types/context';\nimport {apiClient} from './client';\n\ntype OpenVoucherContextRequest = {\n format: ContextFormat;\n payers?: ContextPayer[];\n};\n\ntype CloseVoucherContextRequest = {\n payeeId: string | null;\n};\n\nexport const contextApi = {\n openContext: async (\n format: ContextFormat = ContextFormat.Numeric,\n payers: ContextPayer[] = [],\n ): Promise<Context> => {\n const response = await apiClient.post<Context>('/vouchers/contexts/context-open', {\n format,\n payers,\n } as OpenVoucherContextRequest);\n return response.data;\n },\n\n getContextById: async (contextId: string): Promise<Context> => {\n const response = await apiClient.get<Context>(`/vouchers/contexts/${contextId}`);\n return response.data;\n },\n\n closeContext: async (contextId: string, payeeId: string | null = null): Promise<Context> => {\n const response = await apiClient.post<Context>(\n `/vouchers/contexts/${contextId}/context-close`,\n {\n payeeId,\n } as CloseVoucherContextRequest,\n );\n return response.data;\n },\n};\n","export enum SessionType {\n Default = 'SESSION_DEFAULT',\n}\n\nexport enum SessionFormat {\n Numeric = 'numeric',\n Alphanum = 'alphanum',\n}\n\nexport enum SessionStatus {\n Open = 'OPEN',\n Negotiating = 'NEGOTIATING',\n Established = 'ESTABLISHED',\n Closed = 'CLOSED',\n Expired = 'EXPIRED',\n TimedOut = 'TIMED_OUT',\n}\n\nexport type SessionPayer = {\n address: string;\n};\n\nexport type Session = {\n id: string;\n contextId: string | null;\n payerId: string | null;\n payeeId: string | null;\n type: SessionType;\n format: SessionFormat;\n code: string;\n payers: SessionPayer[];\n status: SessionStatus;\n expiresAt: string;\n timeoutAt: string;\n};\n","export type SolanaPayerInstructionKey = {\n pubkey: string;\n isSigner?: boolean;\n isWritable?: boolean;\n};\n\nexport type SolanaPayerInstruction = {\n programId: string;\n keys: SolanaPayerInstructionKey[];\n data?: string;\n};\n\nexport type SolanaPayeeInstructionKey = {\n pubkey: string;\n isWritable?: boolean;\n};\n\nexport type SolanaPayeeInstruction = {\n programId: string;\n accounts: SolanaPayeeInstructionKey[];\n data?: string;\n};\n\nexport type SolanaInstruction = SolanaPayerInstruction & SolanaPayeeInstruction;\n\nexport type EthereumNativeMethod = {\n method: string;\n params: object;\n};\n\nexport type NativeMethod = EthereumNativeMethod;\n\nexport type EthereumNativeSendTransaction = {\n from: string;\n to: string;\n value: string;\n data: string;\n};\n\nexport type SolanaNativeSendTransaction = {\n feePayer: string;\n recentBlockhash?: string;\n instructions: SolanaInstruction[];\n};\n\nexport type NativeSendTransaction = EthereumNativeSendTransaction | SolanaNativeSendTransaction;\n\nexport type EthereumNativeCallTransaction = {\n from: string;\n to: string;\n value: string;\n data: string;\n};\n\nexport type SolanaNativeCallTransaction = {\n feePayer: string;\n recentBlockhash?: string;\n instructions: SolanaInstruction[];\n};\n\nexport type NativeCallTransaction = EthereumNativeCallTransaction | SolanaNativeCallTransaction;\n\nexport type PaymentRequestWallet = {\n address: string;\n};\n\nexport type PaymentRequest = {\n network: string;\n currency: string;\n currencyAddress: string;\n amount: string;\n wallet: PaymentRequestWallet;\n};\n\nexport type EthereumPlatformData = {\n network: string;\n chainId: string;\n};\n\nexport type SolanaPlatformData = {\n network: string;\n};\n\nexport type PlatformData = EthereumPlatformData | SolanaPlatformData;\n\nexport type VoucherNetwork = {\n network: string;\n type: 'evm' | 'solana';\n chainId?: string;\n};\n\nexport enum VoucherFormat {\n Numeric = 'numeric',\n Alphanum = 'alphanum',\n}\n\nexport enum VoucherType {\n Custom = 'VOUCHER_CUSTOM',\n Simple = 'VOUCHER_SIMPLE',\n}\n\nexport enum VoucherStatus {\n Reserved = 'RESERVED',\n Redeemed = 'REDEEMED',\n Discarded = 'DISCARDED',\n Resolved = 'RESOLVED',\n Expired = 'EXPIRED',\n}\n\nexport type VoucherPayer = {\n address: string;\n};\n\nexport enum VoucherInstructionType {\n NativeRpcMethod = 'rpc_method',\n NativeCallTransaction = 'call_transaction',\n NativeSendTransaction = 'send_transaction',\n}\n\nexport type VoucherInstructionRpcMethod = NativeMethod;\n\nexport type VoucherInstructionSendTransaction = {\n method: string;\n params: NativeSendTransaction;\n};\n\nexport type VoucherInstructionCallTransaction = {\n method: string;\n params: NativeCallTransaction;\n};\n\nexport type VoucherInstructionData =\n | VoucherInstructionRpcMethod\n | VoucherInstructionSendTransaction\n | VoucherInstructionCallTransaction;\n\nexport type VoucherInstruction = {\n type: VoucherInstructionType;\n input: VoucherInstructionData;\n networkIndex?: number;\n};\n\nexport enum VoucherPaymentType {\n SystemRpcMethod = 'system_rpc_method',\n SystemApiMethod = 'system_api_method',\n NativeSendTransaction = 'send_transaction',\n}\n\nexport type VoucherPaymentRpcMethod = NativeMethod;\n\nexport type VoucherPaymentSystemApiMethod = {\n submitHook: string;\n statusHook: string;\n};\n\nexport type VoucherPaymentSystemRpcMethod = NativeMethod & VoucherPaymentSystemApiMethod;\n\nexport type VoucherPaymentSendTransaction = {\n method: string;\n params: NativeSendTransaction;\n};\n\nexport type VoucherPaymentData =\n | VoucherPaymentSystemRpcMethod\n | VoucherPaymentSystemApiMethod\n | VoucherPaymentSendTransaction;\n\nexport type VoucherPayment = {\n type: VoucherPaymentType;\n input: VoucherPaymentData;\n networkIndex?: number;\n};\n\nexport type VoucherReceipt = {\n paymentId: string;\n};\n\nexport enum VoucherInteropStatus {\n Pending = 'PENDING',\n Succeeded = 'SUCCEEDED',\n Failed = 'FAILED',\n Unknown = 'UNKNOWN',\n}\n\nexport type Voucher = {\n id: string;\n contextId: string | null;\n sessionId: string | null;\n payerId: string | null;\n payeeId: string | null;\n type: VoucherType;\n format: VoucherFormat;\n code: string;\n networks: VoucherNetwork[];\n payers: VoucherPayer[];\n extras: VoucherInstruction[];\n payments: VoucherPayment[];\n receipts: VoucherReceipt[];\n suppliedPayment: PaymentRequest | null;\n expectedPayment: PaymentRequest | null;\n status: VoucherStatus;\n expiresAt: string;\n timeoutAt: string;\n};\n","import {Session, SessionType, Voucher} from '../types';\nimport {apiClient} from './client';\n\ntype OpenVoucherSessionRequest = {\n code: string;\n type: SessionType;\n};\n\ntype JoinVoucherSessionRequest = Record<string, never>;\n\ntype CloseVoucherSessionRequest = Record<string, never>;\n\ntype ReserveVoucherInSessionRequest = Record<string, never>;\n\nexport const sessionApi = {\n getSessionById: async (sessionId: string): Promise<Session> => {\n const response = await apiClient.get<Session>(`/vouchers/sessions/${sessionId}`);\n return response.data;\n },\n\n openSession: async (code: string, type: SessionType = SessionType.Default): Promise<Session> => {\n const response = await apiClient.post<Session>('/vouchers/sessions/session-open', {\n code,\n type,\n } as OpenVoucherSessionRequest);\n return response.data;\n },\n\n joinSession: async (sessionId: string): Promise<Session> => {\n const response = await apiClient.post<Session>(\n `/vouchers/sessions/${sessionId}/session-join`,\n {} as JoinVoucherSessionRequest,\n );\n return response.data;\n },\n\n closeSession: async (sessionId: string): Promise<Session> => {\n const response = await apiClient.post<Session>(\n `/vouchers/sessions/${sessionId}/session-close`,\n {} as CloseVoucherSessionRequest,\n );\n return response.data;\n },\n\n reserveVoucherInSession: async (sessionId: string): Promise<Voucher> => {\n const response = await apiClient.post<Voucher>(\n `/vouchers/sessions/${sessionId}/reserve-voucher`,\n {} as ReserveVoucherInSessionRequest,\n );\n return response.data;\n },\n};\n","import {\n Voucher,\n VoucherInstruction,\n VoucherInteropStatus,\n VoucherNetwork,\n VoucherPayment,\n VoucherReceipt,\n} from '../types';\nimport {apiClient} from './client';\n\ntype ReserveVoucherRequest = {\n code: string;\n};\n\ntype RedeemVoucherRequest = {\n networks?: VoucherNetwork[];\n extras?: VoucherInstruction[];\n payments?: VoucherPayment[];\n expectedPayment?: PaymentRequest | null;\n};\n\ntype ResolveVoucherRequest = {\n receipts: VoucherReceipt[];\n};\n\ntype VoucherInteropStatusResponse = {\n status: VoucherInteropStatus;\n};\n\nexport const vouchersApi = {\n reserveVoucher: async (code: string): Promise<Voucher> => {\n const response = await apiClient.post<Voucher>('/vouchers/reserve-voucher', {\n code,\n } as ReserveVoucherRequest);\n return response.data;\n },\n\n getVoucherById: async (voucherId: string): Promise<Voucher> => {\n const response = await apiClient.get<Voucher>(`/vouchers/${voucherId}`);\n return response.data;\n },\n\n redeemVoucherById: async (\n voucherId: string,\n networks: VoucherNetwork[] = [],\n payments: VoucherPayment[] = [],\n extras: VoucherInstruction[] = [],\n expectedPayment: PaymentRequest | null = null,\n ): Promise<Voucher> => {\n const response = await apiClient.post<Voucher>(`/vouchers/${voucherId}/redeem-voucher`, {\n networks,\n extras,\n payments,\n expectedPayment,\n } as RedeemVoucherRequest);\n return response.data;\n },\n\n resolveVoucher: async (voucherId: string, receipts: VoucherReceipt[]): Promise<Voucher> => {\n const response = await apiClient.post<Voucher>(`/vouchers/${voucherId}/resolve-voucher`, {\n receipts,\n } as ResolveVoucherRequest);\n return response.data;\n },\n\n discardVoucher: async (voucherId: string): Promise<void> => {\n await apiClient.post<void>(`/vouchers/${voucherId}/discard-voucher`, {});\n },\n\n initVoucherInterop: async (\n voucherId: string,\n submitHook: string,\n signature: string,\n ): Promise<{id: string}> => {\n const response = await apiClient.post<{id: string}>(\n `/vouchers/${voucherId}/submit/${submitHook}`,\n {\n signature,\n },\n );\n return response.data;\n },\n\n getVoucherInteropStatus: async (\n voucherId: string,\n statusHook: string,\n ): Promise<VoucherInteropStatusResponse> => {\n const response = await apiClient.get<VoucherInteropStatusResponse>(\n `/vouchers/${voucherId}/status/${statusHook}`,\n );\n return response.data;\n },\n};\n","const STORAGE_PREFIX = 'bleepay_';\n\nexport const storage = {\n get<T>(key: string): T | null {\n if (typeof window === 'undefined') return null;\n try {\n const item = window.localStorage.getItem(`${STORAGE_PREFIX}${key}`);\n return item ? (JSON.parse(item) as T) : null;\n } catch {\n return null;\n }\n },\n\n set<T>(key: string, value: T): void {\n if (typeof window === 'undefined') return;\n try {\n window.localStorage.setItem(`${STORAGE_PREFIX}${key}`, JSON.stringify(value));\n } catch {\n // Storage full or disabled\n }\n },\n\n remove(key: string): void {\n if (typeof window === 'undefined') return;\n try {\n window.localStorage.removeItem(`${STORAGE_PREFIX}${key}`);\n } catch {\n // Storage disabled\n }\n },\n\n clear(): void {\n if (typeof window === 'undefined') return;\n try {\n const keys = Object.keys(window.localStorage);\n for (const key of keys) {\n if (key.startsWith(STORAGE_PREFIX)) {\n window.localStorage.removeItem(key);\n }\n }\n } catch {\n // Storage disabled\n }\n },\n};\n","import {VOUCHER_CODE_LENGTH, VOUCHER_CODE_PATTERN} from '../constants';\n\nexport const isValidVoucherCode = (code: string): boolean => {\n return VOUCHER_CODE_PATTERN.test(code);\n};\n\nexport const normalizeVoucherCode = (code: string): string => {\n return code.replace(/\\D/g, '').slice(0, VOUCHER_CODE_LENGTH);\n};\n\nexport const isValidAddress = (address: string): boolean => {\n return /^0x[a-fA-F0-9]{40}$/.test(address);\n};\n\nexport const isValidChainId = (chainId: unknown): chainId is number => {\n return typeof chainId === 'number' && Number.isInteger(chainId) && chainId > 0;\n};\n\nexport const formatAddress = (address: string, prefixLength = 6, suffixLength = 4): string => {\n if (!isValidAddress(address)) return address;\n return `${address.slice(0, prefixLength)}...${address.slice(-suffixLength)}`;\n};\n\nexport const formatAmount = (amount: string | number, decimals = 2): string => {\n const num = typeof amount === 'string' ? Number.parseFloat(amount) : amount;\n return num.toLocaleString('en-US', {\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n });\n};\n","import {type VoucherPayer, type VoucherReceipt} from '../types';\n\nexport const createVoucherPayer = (address: string): VoucherPayer => {\n return {\n address,\n };\n};\n\nexport const createVoucherReceipt = (paymentId: string): VoucherReceipt => {\n return {\n paymentId,\n };\n};\n","import {\n type EthereumNativeCallTransaction,\n type EthereumNativeMethod,\n type EthereumNativeSendTransaction,\n type VoucherInstruction,\n VoucherInstructionType,\n type VoucherNetwork,\n type VoucherPayment,\n VoucherPaymentSystemRpcMethod,\n VoucherPaymentType,\n} from '../types';\n\nexport const createEvmNetwork = (params: {\n network: string;\n chainId: string | number;\n}): VoucherNetwork => {\n return {\n network: params.network,\n type: 'evm',\n chainId: String(params.chainId),\n };\n};\n\nexport const createEvmRpcMethodInstruction = (params: {\n method: string;\n params: object;\n networkIndex?: number;\n}): VoucherInstruction => {\n return {\n type: VoucherInstructionType.NativeRpcMethod,\n input: {\n method: params.method,\n params: params.params,\n } as EthereumNativeMethod,\n networkIndex: params.networkIndex,\n };\n};\n\nexport const createEvmCallTransactionInstruction = (params: {\n from: string;\n to: string;\n value: string;\n data: string;\n networkIndex?: number;\n}): VoucherInstruction => {\n return {\n type: VoucherInstructionType.NativeCallTransaction,\n input: {\n method: 'eth_call',\n params: {\n from: params.from,\n to: params.to,\n value: params.value,\n data: params.data,\n } as EthereumNativeCallTransaction,\n },\n networkIndex: params.networkIndex,\n };\n};\n\nexport const createEvmSendTransactionInstruction = (params: {\n from: string;\n to: string;\n value: string;\n data: string;\n networkIndex?: number;\n}): VoucherInstruction => {\n return {\n type: VoucherInstructionType.NativeSendTransaction,\n input: {\n method: 'eth_sendTransaction',\n params: {\n from: params.from,\n to: params.to,\n value: params.value,\n data: params.data,\n } as EthereumNativeSendTransaction,\n },\n networkIndex: params.networkIndex,\n };\n};\n\nexport const createEvmSystemRpcMethodPayment = (params: {\n method: string;\n params: object;\n networkIndex?: number;\n}): VoucherPayment => {\n return {\n type: VoucherPaymentType.SystemRpcMethod,\n input: {\n method: params.method,\n params: params.params,\n } as VoucherPaymentSystemRpcMethod,\n networkIndex: params.networkIndex,\n };\n};\n\nexport const createEvmPayment = (params: {\n from: string;\n to: string;\n value: string;\n data?: string;\n networkIndex?: number;\n}): VoucherPayment => {\n return {\n type: VoucherPaymentType.NativeSendTransaction,\n input: {\n method: 'eth_sendTransaction',\n params: {\n from: params.from,\n to: params.to,\n value: params.value,\n data: params.data || '0x',\n } as EthereumNativeSendTransaction,\n },\n networkIndex: params.networkIndex,\n };\n};\n\nexport const isEvmNetwork = (network: VoucherNetwork): boolean => {\n return network.type === 'evm';\n};\n"],"mappings":";AAAO,IAAM,eAAe;AAErB,IAAM,sBAAsB;AAC5B,IAAM,uBAAuB;AAE7B,IAAM,qBAAqB;;;ACQ3B,IAAM,YAAY;AAAA,EACvB,SAAS;AAAA,EACT,SAAS;AAAA,EACT,cAAc;AAAA,EAEd,MAAM,QAAW,QAAgB,MAAc,MAAyC;AACtF,UAAM,aAAa,IAAI,gBAAgB;AACvC,UAAM,YAAY,WAAW,MAAM,WAAW,MAAM,GAAG,KAAK,OAAO;AAEn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,OAAO;AAAA,EACvB;AACF;AAEO,IAAM,sCAAsC,CAAC,WAM1B;AACxB,SAAO;AAAA,IACL;AAAA,IACA,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,QAAQ;AAAA,QACN,MAAM,OAAO;AAAA,QACb,IAAI,OAAO;AAAA,QACX,OAAO,OAAO;AAAA,QACd,MAAM,OAAO;AAAA,MACf;AAAA,IACF;AAAA,IACA,cAAc,OAAO;AAAA,EACvB;AACF;AAEO,IAAM,sCAAsC,CAAC,WAM1B;AACxB,SAAO;AAAA,IACL;AAAA,IACA,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,QAAQ;AAAA,QACN,MAAM,OAAO;AAAA,QACb,IAAI,OAAO;AAAA,QACX,OAAO,OAAO;AAAA,QACd,MAAM,OAAO;AAAA,MACf;AAAA,IACF;AAAA,IACA,cAAc,OAAO;AAAA,EACvB;AACF;AAEO,IAAM,kCAAkC,CAAC,WAI1B;AACpB,SAAO;AAAA,IACL;AAAA,IACA,OAAO;AAAA,MACL,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO;AAAA,IACjB;AAAA,IACA,cAAc,OAAO;AAAA,EACvB;AACF;AAEO,IAAM,mBAAmB,CAAC,WAMX;AACpB,SAAO;AAAA,IACL;AAAA,IACA,OAAO;AAAA,MACL,QAAQ;AAAA,MACR,QAAQ;AAAA,QACN,MAAM,OAAO;AAAA,QACb,IAAI,OAAO;AAAA,QACX,OAAO,OAAO;AAAA,QACd,MAAM,OAAO,QAAQ;AAAA,MACvB;AAAA,IACF;AAAA,IACA,cAAc,OAAO;AAAA,EACvB;AACF;AAEO,IAAM,eAAe,CAAC,YAAqC;AAChE,SAAO,QAAQ,SAAS;AAC1B;","names":["ContextType","ContextFormat","ContextStatus","SessionType","SessionFormat","SessionStatus","VoucherFormat","VoucherType","VoucherStatus","VoucherInstructionType","VoucherPaymentType","VoucherInteropStatus"]}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@bleepay/core",
3
+ "version": "0.0.1",
4
+ "description": "Bleepay SDK – core logic, API client and session management",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "devDependencies": {
22
+ "tsup": "^8.5.0",
23
+ "typescript": "~5.8.3"
24
+ },
25
+ "sideEffects": false,
26
+ "scripts": {
27
+ "build": "tsup",
28
+ "dev": "tsup --watch",
29
+ "ts:check": "tsc --noEmit",
30
+ "clean": "rm -rf dist"
31
+ }
32
+ }