@gatewayfm/ups-sdk 0.1.13 → 0.1.15
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/account/index.d.mts +1 -1
- package/dist/account/index.d.ts +1 -1
- package/dist/account/index.js +2 -2
- package/dist/account/index.mjs +1 -1
- package/dist/{chunk-2S2KS5ZI.js → chunk-6S7HWY3Z.js} +17 -11
- package/dist/chunk-6S7HWY3Z.js.map +1 -0
- package/dist/{chunk-BUSFZFJS.mjs → chunk-EONLKSST.mjs} +11 -10
- package/dist/chunk-EONLKSST.mjs.map +1 -0
- package/dist/{chunk-VORGSH76.mjs → chunk-OPWSYY5P.mjs} +40 -3
- package/dist/chunk-OPWSYY5P.mjs.map +1 -0
- package/dist/{chunk-XKQI2VMJ.js → chunk-XFJ6SPQN.js} +11 -10
- package/dist/chunk-XFJ6SPQN.js.map +1 -0
- package/dist/{chunk-PMX24TXY.js → chunk-XPW56652.js} +40 -2
- package/dist/chunk-XPW56652.js.map +1 -0
- package/dist/{chunk-S65V52WZ.mjs → chunk-ZVB256ZP.mjs} +17 -11
- package/dist/chunk-ZVB256ZP.mjs.map +1 -0
- package/dist/{index-D_ytPgEV.d.ts → index-0emNrQ4Y.d.ts} +1 -1
- package/dist/{index-Csrh5-dl.d.mts → index-BEjQJc66.d.mts} +35 -4
- package/dist/{index-Csrh5-dl.d.ts → index-BEjQJc66.d.ts} +35 -4
- package/dist/{index-1p5DSytk.d.mts → index-bErQcXnC.d.mts} +1 -1
- package/dist/index.d.mts +35 -4
- package/dist/index.d.ts +35 -4
- package/dist/index.js +77 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -30
- package/dist/index.mjs.map +1 -1
- package/dist/payment/index.d.mts +14 -2
- package/dist/payment/index.d.ts +14 -2
- package/dist/payment/index.js +2 -2
- package/dist/payment/index.mjs +1 -1
- package/dist/wallet/index.d.mts +2 -2
- package/dist/wallet/index.d.ts +2 -2
- package/dist/wallet/index.js +2 -2
- package/dist/wallet/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-2S2KS5ZI.js.map +0 -1
- package/dist/chunk-BUSFZFJS.mjs.map +0 -1
- package/dist/chunk-PMX24TXY.js.map +0 -1
- package/dist/chunk-S65V52WZ.mjs.map +0 -1
- package/dist/chunk-VORGSH76.mjs.map +0 -1
- package/dist/chunk-XKQI2VMJ.js.map +0 -1
package/dist/account/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { H as HttpClient } from '../http-client-D9JtkvUx.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { h as Account, j as CreateAccountParams, k as CreateAccountResponse } from '../index-BEjQJc66.mjs';
|
|
3
3
|
|
|
4
4
|
declare class AccountModule {
|
|
5
5
|
private http;
|
package/dist/account/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { H as HttpClient } from '../http-client-D9JtkvUx.js';
|
|
2
|
-
import {
|
|
2
|
+
import { h as Account, j as CreateAccountParams, k as CreateAccountResponse } from '../index-BEjQJc66.js';
|
|
3
3
|
|
|
4
4
|
declare class AccountModule {
|
|
5
5
|
private http;
|
package/dist/account/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkXFJ6SPQN_js = require('../chunk-XFJ6SPQN.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "AccountModule", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkXFJ6SPQN_js.AccountModule; }
|
|
10
10
|
});
|
|
11
11
|
//# sourceMappingURL=index.js.map
|
|
12
12
|
//# sourceMappingURL=index.js.map
|
package/dist/account/index.mjs
CHANGED
|
@@ -46,10 +46,11 @@ var WalletModule = class {
|
|
|
46
46
|
provider
|
|
47
47
|
};
|
|
48
48
|
} catch (error) {
|
|
49
|
-
|
|
49
|
+
const e = error;
|
|
50
|
+
if (e.code === 4001) {
|
|
50
51
|
throw new chunkG525R6AV_js.WalletError("User rejected connection");
|
|
51
52
|
}
|
|
52
|
-
throw new chunkG525R6AV_js.WalletError(`Connection failed: ${
|
|
53
|
+
throw new chunkG525R6AV_js.WalletError(`Connection failed: ${e.message || "Unknown error"}`, error);
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
async disconnect() {
|
|
@@ -82,8 +83,9 @@ var WalletModule = class {
|
|
|
82
83
|
message
|
|
83
84
|
});
|
|
84
85
|
} catch (error) {
|
|
85
|
-
|
|
86
|
-
throw new chunkG525R6AV_js.WalletError(
|
|
86
|
+
const e = error;
|
|
87
|
+
if (e.code === 4001) throw new chunkG525R6AV_js.WalletError("User rejected signing");
|
|
88
|
+
throw new chunkG525R6AV_js.WalletError(`Sign message failed: ${e.message || "Unknown error"}`, error);
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
async signTypedData(typedData) {
|
|
@@ -99,8 +101,9 @@ var WalletModule = class {
|
|
|
99
101
|
message: typedData.message
|
|
100
102
|
});
|
|
101
103
|
} catch (error) {
|
|
102
|
-
|
|
103
|
-
throw new chunkG525R6AV_js.WalletError(
|
|
104
|
+
const e = error;
|
|
105
|
+
if (e.code === 4001) throw new chunkG525R6AV_js.WalletError("User rejected signing");
|
|
106
|
+
throw new chunkG525R6AV_js.WalletError(`Sign typed data failed: ${e.message || "Unknown error"}`, error);
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
109
|
async switchChain(chainId) {
|
|
@@ -115,15 +118,17 @@ var WalletModule = class {
|
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
120
|
onStateChange(callback) {
|
|
118
|
-
const unsub1 = this.eventBus.on("wallet:
|
|
121
|
+
const unsub1 = this.eventBus.on("wallet:stateChanged", () => callback(this._state));
|
|
119
122
|
return unsub1;
|
|
120
123
|
}
|
|
121
124
|
updateState(newState) {
|
|
122
125
|
this._state = newState;
|
|
126
|
+
this.eventBus.emit("wallet:stateChanged", this._state);
|
|
123
127
|
}
|
|
124
128
|
setupListeners(provider) {
|
|
125
129
|
if (!provider.on) return;
|
|
126
|
-
provider.on("accountsChanged", (
|
|
130
|
+
provider.on("accountsChanged", (...args) => {
|
|
131
|
+
const accounts = args[0];
|
|
127
132
|
if (accounts.length === 0) {
|
|
128
133
|
this.disconnect();
|
|
129
134
|
} else {
|
|
@@ -131,7 +136,8 @@ var WalletModule = class {
|
|
|
131
136
|
this.eventBus.emit("wallet:accountsChanged", accounts);
|
|
132
137
|
}
|
|
133
138
|
});
|
|
134
|
-
provider.on("chainChanged", (
|
|
139
|
+
provider.on("chainChanged", (...args) => {
|
|
140
|
+
const chainId = args[0];
|
|
135
141
|
const id = parseInt(chainId, 16);
|
|
136
142
|
this.updateState({ ...this._state, chainId: id });
|
|
137
143
|
this.eventBus.emit("wallet:chainChanged", id);
|
|
@@ -146,5 +152,5 @@ var WalletModule = class {
|
|
|
146
152
|
};
|
|
147
153
|
|
|
148
154
|
exports.WalletModule = WalletModule;
|
|
149
|
-
//# sourceMappingURL=chunk-
|
|
150
|
-
//# sourceMappingURL=chunk-
|
|
155
|
+
//# sourceMappingURL=chunk-6S7HWY3Z.js.map
|
|
156
|
+
//# sourceMappingURL=chunk-6S7HWY3Z.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/wallet/index.ts"],"names":["mainnet","base","baseSepolia","WalletError","createWalletClient","custom"],"mappings":";;;;;;AAMO,IAAM,eAAN,MAAmB;AAAA,EAUtB,YAAoB,QAAA,EAAoB;AAApB,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAAA,EAAsB;AAAA,EATlC,MAAA,GAAsB;AAAA,IAC1B,WAAA,EAAa,KAAA;AAAA,IACb,OAAA,EAAS,IAAA;AAAA,IACT,OAAA,EAAS,IAAA;AAAA,IACT,QAAA,EAAU;AAAA,GACd;AAAA,EACQ,MAAA,GAA8B,IAA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ChD,MAAA,MAAM,OAAA,GAAU,KAAK,CAAC,CAAA;AACtB,MAAA,MAAM,EAAA,GAAK,QAAA,CAAS,OAAA,EAAS,EAAE,CAAA;AAC/B,MAAA,IAAA,CAAK,YAAY,EAAE,GAAG,KAAK,MAAA,EAAQ,OAAA,EAAS,IAAI,CAAA;AAGhD,MAAA,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,qBAAA,EAAuB,EAAE,CAAA;AAAA,IAChD,CAAC,CAAA;AAED,IAAA,QAAA,CAAS,EAAA,CAAG,cAAc,MAAM;AAC5B,MAAA,IAAA,CAAK,UAAA,EAAW;AAAA,IACpB,CAAC,CAAA;AAAA,EACL;AAAA,EAEQ,SAAS,OAAA,EAAiB;AAC9B,IAAA,OAAO,KAAK,MAAA,CAAO,IAAA,CAAK,CAAA,CAAA,KAAK,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,EACjD;AACJ","file":"chunk-6S7HWY3Z.js","sourcesContent":["import { createWalletClient, custom, WalletClient } from 'viem';\nimport { mainnet, base, baseSepolia } from 'viem/chains';\nimport { WalletState, ConnectedWallet, EIP1193Provider, EIP712TypedData } from '../types';\nimport { EventBus } from '../core/event-bus';\nimport { WalletError } from '../core/errors';\n\nexport class WalletModule {\n private _state: WalletState = {\n isConnected: false,\n address: null,\n chainId: null,\n provider: null,\n };\n private client: WalletClient | null = null;\n private chains = [mainnet, base, baseSepolia];\n\n constructor(private eventBus: EventBus) { }\n\n get state(): WalletState {\n return { ...this._state };\n }\n\n async connect(provider: EIP1193Provider): Promise<ConnectedWallet> {\n try {\n this.setupListeners(provider);\n\n const addresses = (await provider.request({ method: 'eth_requestAccounts' })) as string[];\n if (!addresses || addresses.length === 0) {\n throw new WalletError('No accounts found');\n }\n\n const chainIdHex = (await provider.request({ method: 'eth_chainId' })) as string;\n const chainId = parseInt(chainIdHex, 16);\n\n this.client = createWalletClient({\n chain: this.getChain(chainId),\n transport: custom(provider),\n });\n\n const address = addresses[0];\n\n this.updateState({\n isConnected: true,\n address,\n chainId,\n provider,\n });\n\n this.eventBus.emit('wallet:connected', this._state);\n\n return {\n address,\n chainId,\n provider,\n };\n } catch (error: unknown) {\n const e = error as { code?: number; message?: string };\n if (e.code === 4001) {\n throw new WalletError('User rejected connection');\n }\n throw new WalletError(`Connection failed: ${e.message || 'Unknown error'}`, error as Error);\n }\n }\n\n async disconnect(): Promise<void> {\n // Remove listeners if needed (not easily possible with just EIP1193Provider standard without storing internal listener refs, but we can clear state)\n // Actually standard providers like Metamask don't really 'disconnect' via API, but we act as if we did.\n if (this._state.provider && this._state.provider.removeListener) {\n // We should ideally remove listeners we added.\n // For simplicity in this scope, we just resetting state.\n }\n\n this.updateState({\n isConnected: false,\n address: null,\n chainId: null,\n provider: null\n });\n this.client = null;\n this.eventBus.emit('wallet:disconnected', undefined);\n }\n\n getAddress(): string | null {\n return this._state.address;\n }\n\n getChainId(): number | null {\n return this._state.chainId;\n }\n\n isConnected(): boolean {\n return this._state.isConnected;\n }\n\n async signMessage(message: string): Promise<string> {\n if (!this.client || !this._state.address) {\n throw new WalletError('Wallet not connected');\n }\n try {\n return await this.client.signMessage({\n account: this._state.address as `0x${string}`,\n message,\n });\n } catch (error: unknown) {\n const e = error as { code?: number; message?: string };\n if (e.code === 4001) throw new WalletError('User rejected signing');\n throw new WalletError(`Sign message failed: ${e.message || 'Unknown error'}`, error as Error);\n }\n }\n\n async signTypedData(typedData: EIP712TypedData): Promise<string> {\n if (!this.client || !this._state.address) {\n throw new WalletError('Wallet not connected');\n }\n try {\n // viem expects exact structure\n return await this.client.signTypedData({\n account: this._state.address as `0x${string}`,\n domain: typedData.domain as any,\n types: typedData.types as any,\n primaryType: typedData.primaryType,\n message: typedData.message,\n });\n } catch (error: unknown) {\n const e = error as { code?: number; message?: string };\n if (e.code === 4001) throw new WalletError('User rejected signing');\n throw new WalletError(`Sign typed data failed: ${e.message || 'Unknown error'}`, error as Error);\n }\n }\n\n async switchChain(chainId: number): Promise<void> {\n if (!this._state.provider) throw new WalletError('Provider not available');\n try {\n await this._state.provider.request({\n method: 'wallet_switchEthereumChain',\n params: [{ chainId: `0x${chainId.toString(16)}` }],\n });\n } catch (error: unknown) {\n throw new WalletError(`Switch chain failed: ${(error as Error).message}`, error as Error);\n }\n }\n\n onStateChange(callback: (state: WalletState) => void): () => void {\n const unsub1 = this.eventBus.on('wallet:stateChanged', () => callback(this._state));\n return unsub1;\n }\n\n private updateState(newState: WalletState) {\n this._state = newState;\n this.eventBus.emit('wallet:stateChanged', this._state);\n }\n\n private setupListeners(provider: EIP1193Provider) {\n if (!provider.on) return;\n\n provider.on('accountsChanged', (...args: unknown[]) => {\n const accounts = args[0] as string[];\n if (accounts.length === 0) {\n this.disconnect();\n } else {\n this.updateState({ ...this._state, address: accounts[0] });\n this.eventBus.emit('wallet:accountsChanged', accounts);\n }\n });\n\n provider.on('chainChanged', (...args: unknown[]) => {\n const chainId = args[0] as string;\n const id = parseInt(chainId, 16);\n this.updateState({ ...this._state, chainId: id });\n // Update client chain if possible or recreate?\n // For now just update state\n this.eventBus.emit('wallet:chainChanged', id);\n });\n\n provider.on('disconnect', () => {\n this.disconnect();\n });\n }\n\n private getChain(chainId: number) {\n return this.chains.find(c => c.id === chainId);\n }\n}\n"]}
|
|
@@ -37,19 +37,20 @@ var AccountModule = class {
|
|
|
37
37
|
return response.wallet_address;
|
|
38
38
|
}
|
|
39
39
|
mapAccount(data) {
|
|
40
|
+
const d = data;
|
|
40
41
|
return {
|
|
41
|
-
id:
|
|
42
|
-
ownerAddress:
|
|
43
|
-
walletAddress:
|
|
44
|
-
status:
|
|
45
|
-
kycLevel:
|
|
46
|
-
userId:
|
|
47
|
-
createdAt:
|
|
48
|
-
updatedAt:
|
|
42
|
+
id: d.id,
|
|
43
|
+
ownerAddress: d.owner_address,
|
|
44
|
+
walletAddress: d.wallet_address,
|
|
45
|
+
status: d.status,
|
|
46
|
+
kycLevel: d.kyc_level ?? 0,
|
|
47
|
+
userId: d.user_id,
|
|
48
|
+
createdAt: d.created_at,
|
|
49
|
+
updatedAt: d.updated_at
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
53
|
|
|
53
54
|
export { AccountModule };
|
|
54
|
-
//# sourceMappingURL=chunk-
|
|
55
|
-
//# sourceMappingURL=chunk-
|
|
55
|
+
//# sourceMappingURL=chunk-EONLKSST.mjs.map
|
|
56
|
+
//# sourceMappingURL=chunk-EONLKSST.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/account/index.ts"],"names":[],"mappings":";AAGO,IAAM,gBAAN,MAAoB;AAAA,EACvB,YAAoB,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAoB;AAAA,EAExC,MAAM,IAAI,EAAA,EAA8B;AACpC,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,KAAK,GAAA,CAA0B,CAAA,UAAA,EAAa,EAAE,CAAA,CAAE,CAAA;AAC5E,IAAA,OAAO,IAAA,CAAK,UAAA,CAAW,QAAA,CAAS,OAAO,CAAA;AAAA,EAC3C;AAAA,EAEA,MAAM,YAAY,OAAA,EAAmC;AAMjD,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,EAAK;AACjC,IAAA,MAAM,OAAA,GAAU,QAAA,CAAS,IAAA,CAAK,CAAA,CAAA,KAAK,CAAA,CAAE,cAAc,WAAA,EAAY,KAAM,OAAA,CAAQ,WAAA,EAAa,CAAA;AAC1F,IAAA,IAAI,CAAC,OAAA,EAAS;AACV,MAAA,MAAM,IAAI,MAAM,8BAA8B,CAAA;AAAA,IAClD;AACA,IAAA,OAAO,OAAA;AAAA,EACX;AAAA,EAEA,MAAM,IAAA,GAA2B;AAC7B,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,IAA6B,WAAW,CAAA;AACzE,IAAA,OAAO,QAAA,CAAS,QAAA,CAAS,GAAA,CAAI,IAAA,CAAK,UAAU,CAAA;AAAA,EAChD;AAAA,EAEA,MAAM,OAAO,MAAA,EAA6D;AACtE,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,KAAU,WAAA,EAAa;AAAA,MACpD,eAAe,MAAA,CAAO,YAAA;AAAA,MACtB,MAAM,MAAA,CAAO;AAAA,KAChB,CAAA;AAED,IAAA,OAAO;AAAA,MACH,OAAA,EAAS,IAAA,CAAK,UAAA,CAAW,QAAA,CAAS,OAAO,CAAA;AAAA,MACzC,QAAQ,QAAA,CAAS;AAAA,KACrB;AAAA,EACJ;AAAA,EAEA,MAAM,eAAe,MAAA,EAAiE;AAClF,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,CAAK,KAAiC,mBAAA,EAAqB;AAAA,MACnF,eAAe,MAAA,CAAO,YAAA;AAAA,MACtB,MAAM,MAAA,CAAO;AAAA,KAChB,CAAA;AACD,IAAA,OAAO,QAAA,CAAS,cAAA;AAAA,EACpB;AAAA,EAEQ,WAAW,IAAA,EAAoB;AAEnC,IAAA,MAAM,CAAA,GAAI,IAAA;AACV,IAAA,OAAO;AAAA,MACH,IAAI,CAAA,CAAE,EAAA;AAAA,MACN,cAAc,CAAA,CAAE,aAAA;AAAA,MAChB,eAAe,CAAA,CAAE,cAAA;AAAA,MACjB,QAAQ,CAAA,CAAE,MAAA;AAAA,MACV,QAAA,EAAU,EAAE,SAAA,IAAa,CAAA;AAAA,MACzB,QAAQ,CAAA,CAAE,OAAA;AAAA,MACV,WAAW,CAAA,CAAE,UAAA;AAAA,MACb,WAAW,CAAA,CAAE;AAAA,KACjB;AAAA,EACJ;AACJ","file":"chunk-EONLKSST.mjs","sourcesContent":["import { HttpClient } from '../core/http-client';\nimport { Account, CreateAccountParams, CreateAccountResponse } from '../types';\n\nexport class AccountModule {\n constructor(private http: HttpClient) { }\n\n async get(id: string): Promise<Account> {\n const response = await this.http.get<{ account: unknown }>(`/accounts/${id}`);\n return this.mapAccount(response.account);\n }\n\n async getByWallet(address: string): Promise<Account> {\n // Assuming API supports query param or specific endpoint. \n // The task list says \"GET /accounts -> { accounts: [...] }\". \n // It doesn't explicitly have a \"get by wallet\" endpoint, but usually list filters.\n // Or maybe we filter the list.\n // \"GET /accounts\" implies listing current user's accounts usually?\n const response = await this.list();\n const account = response.find(a => a.walletAddress.toLowerCase() === address.toLowerCase());\n if (!account) {\n throw new Error('Account not found for wallet');\n }\n return account;\n }\n\n async list(): Promise<Account[]> {\n const response = await this.http.get<{ accounts: unknown[] }>('/accounts');\n return response.accounts.map(this.mapAccount);\n }\n\n async create(params: CreateAccountParams): Promise<CreateAccountResponse> {\n const response = await this.http.post<any>('/accounts', {\n owner_address: params.ownerAddress,\n salt: params.salt,\n });\n\n return {\n account: this.mapAccount(response.account),\n txHash: response.tx_hash,\n };\n }\n\n async predictAddress(params: { ownerAddress: string; salt: string }): Promise<string> {\n const response = await this.http.post<{ wallet_address: string }>('/accounts/predict', {\n owner_address: params.ownerAddress,\n salt: params.salt,\n });\n return response.wallet_address;\n }\n\n private mapAccount(data: any): Account {\n // Map snake_case to camelCase\n const d = data as any;\n return {\n id: d.id,\n ownerAddress: d.owner_address,\n walletAddress: d.wallet_address,\n status: d.status,\n kycLevel: d.kyc_level ?? 0,\n userId: d.user_id,\n createdAt: d.created_at,\n updatedAt: d.updated_at,\n };\n }\n}\n"]}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { PaymentError } from './chunk-BH5YEAE6.mjs';
|
|
2
2
|
|
|
3
|
+
// src/types/index.ts
|
|
4
|
+
var PaymentType = /* @__PURE__ */ ((PaymentType2) => {
|
|
5
|
+
PaymentType2["UNSPECIFIED"] = "UNSPECIFIED";
|
|
6
|
+
PaymentType2["DIRECT"] = "DIRECT";
|
|
7
|
+
PaymentType2["ESCROW"] = "ESCROW";
|
|
8
|
+
PaymentType2["INVOICE"] = "INVOICE";
|
|
9
|
+
return PaymentType2;
|
|
10
|
+
})(PaymentType || {});
|
|
11
|
+
|
|
3
12
|
// src/payment/index.ts
|
|
4
13
|
var PaymentModule = class {
|
|
5
14
|
constructor(http, wallet) {
|
|
@@ -22,6 +31,34 @@ var PaymentModule = class {
|
|
|
22
31
|
}
|
|
23
32
|
return this.settle(signed, requirementsWithFrom);
|
|
24
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Pay an invoice
|
|
36
|
+
* @param invoice The invoice to pay
|
|
37
|
+
* @param params Payment parameters (amount, asset, network)
|
|
38
|
+
*/
|
|
39
|
+
async payInvoice(invoice, params) {
|
|
40
|
+
const payTo = params.payTo || invoice.merchant;
|
|
41
|
+
if (!payTo) throw new PaymentError("No payee address (merchant) available for invoice");
|
|
42
|
+
const requirements = {
|
|
43
|
+
scheme: "exact",
|
|
44
|
+
network: params.network,
|
|
45
|
+
maxAmountRequired: params.amount,
|
|
46
|
+
asset: params.asset,
|
|
47
|
+
payTo,
|
|
48
|
+
maxTimeoutSeconds: 3600,
|
|
49
|
+
extra: {
|
|
50
|
+
name: "x402 Payment Token",
|
|
51
|
+
version: "1",
|
|
52
|
+
payment_type: "INVOICE" /* INVOICE */,
|
|
53
|
+
invoice_id: invoice.invoice_id,
|
|
54
|
+
invoice_payment_type: invoice.payment_type
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return this.pay({
|
|
58
|
+
requirements,
|
|
59
|
+
from: params.from
|
|
60
|
+
});
|
|
61
|
+
}
|
|
25
62
|
buildAuthorization(requirements, from) {
|
|
26
63
|
const array = new Uint8Array(32);
|
|
27
64
|
crypto.getRandomValues(array);
|
|
@@ -131,6 +168,6 @@ var PaymentModule = class {
|
|
|
131
168
|
}
|
|
132
169
|
};
|
|
133
170
|
|
|
134
|
-
export { PaymentModule };
|
|
135
|
-
//# sourceMappingURL=chunk-
|
|
136
|
-
//# sourceMappingURL=chunk-
|
|
171
|
+
export { PaymentModule, PaymentType };
|
|
172
|
+
//# sourceMappingURL=chunk-OPWSYY5P.mjs.map
|
|
173
|
+
//# sourceMappingURL=ch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AM,mBAAA,GAAyD;AAC3D,IAAA,OAAO,KAAK,IAAA,CAAK,GAAA,CAA8B,mBAAmB,EAAE,QAAA,EAAU,MAAM,CAAA;AAAA,EACxF;AACJ","file":"chunk-OPWSYY5P.mjs","sourcesContent":["export interface UPSConfig {\n baseUrl: string; // API base URL\n network: string; // CAIP-2 format: \"eip155:737998412\"\n chainId?: number; // Optional, parsed from network if not provided\n timeout?: number; // Request timeout (default: 30000)\n retryAttempts?: number; // Retry count (default: 3)\n refreshInterval?: number; // Token refresh interval in ms (default: 60000 = 1 min)\n}\n\n// Authentication\nexport interface AuthState {\n isAuthenticated: boolean;\n token: string | null;\n expiresAt: Date | null;\n address: string | null;\n}\n\nexport interface AuthResult {\n token: string;\n expiresAt: string;\n}\n\n// User (from /auth/connect and /users/me)\nexport interface User {\n id: string;\n walletAddress: string;\n status: string;\n createdAt: string;\n}\n\n// Connect auth result (unified auth flow)\nexport interface ConnectResult {\n user: User;\n token: string;\n expiresAt: string;\n isNewUser: boolean;\n}\n\n// Wallet\nexport type EIP1193Provider = {\n request: (args: { method: string; params?: unknown[] }) => Promise<unknown>;\n on?: (event: string, handler: (...args: unknown[]) => void) => void;\n removeListener?: (event: string, handler: (...args: unknown[]) => void) => void;\n};\n\nexport interface WalletState {\n isConnected: boolean;\n address: string | null;\n chainId: number | null;\n provider: EIP1193Provider | null;\n}\n\nexport interface ConnectedWallet {\n address: string;\n chainId: number;\n provider: EIP1193Provider;\n}\n\n// Account\nexport type AccountStatus = 'pending' | 'kyc_in_progress' | 'active' | 'frozen' | 'closed';\n\nexport interface Account {\n id: string;\n ownerAddress: string;\n walletAddress: string;\n status: AccountStatus;\n kycLevel: number;\n userId?: string;\n createdAt: string;\n updatedAt?: string;\n}\n\nexport interface CreateAccountParams {\n ownerAddress: string;\n salt: string; // 0x-prefixed 32-byte hex\n}\n\nexport interface CreateAccountResponse {\n account: Account;\n txHash: string;\n}\n\n// Payment (x402)\nexport interface PaymentRequirements {\n scheme: string;\n network: string;\n maxAmountRequired: string;\n asset: string;\n payTo: string;\n maxTimeoutSeconds: number;\n resource?: string;\n description?: string;\n\n extra?: PaymentExtra;\n from?: string;\n}\n\nexport enum PaymentType {\n UNSPECIFIED = 'UNSPECIFIED',\n DIRECT = 'DIRECT',\n ESCROW = 'ESCROW',\n INVOICE = 'INVOICE'\n}\n\nexport interface PaymentExtra {\n name?: string;\n version?: string;\n payment_type?: PaymentType; // snake_case from API\n arbiter?: string;\n release_time?: number; // snake_case from API\n payee?: string; // intended recipient for escrow\n invoice_id?: string;\n invoice_payment_type?: 'DIRECT' | 'ESCROW';\n}\n\nexport interface PaymentAuthorization {\n from: string;\n to: string;\n value: string;\n validAfter: number;\n validBefore: number;\n nonce: string; // bytes32 hex\n}\n\nexport interface SignedAuthorization extends PaymentAuthorization {\n signature: string;\n}\n\nexport interface VerifyResponse {\n isValid: boolean;\n invalidReason?: string;\n payer?: string;\n}\n\nexport interface SettleResponse {\n success: boolean;\n errorReason?: string;\n transaction?: string;\n network?: string;\n payer?: string;\n}\n\n// x402 Supported Schemes\nexport interface SupportedScheme {\n x402Version: number;\n scheme: string;\n network: string;\n}\n\nexport interface SupportedSchemesResponse {\n kinds: SupportedScheme[];\n extensions?: string[];\n signers?: Record<string, string[]>;\n}\n\n// EIP-712 Typed Data\nexport interface EIP712Domain {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: string;\n}\n\nexport interface EIP712Type {\n name: string;\n type: string;\n}\n\nexport interface EIP712TypedData {\n domain: EIP712Domain;\n types: Record<string, EIP712Type[]>;\n primaryType: string;\n message: Record<string, unknown>;\n}\n\n// Escrow\nexport interface Escrow {\n escrowId: string;\n payer: string;\n payee: string;\n amount: string;\n arbiter: string;\n releaseTime: number;\n status: EscrowStatus;\n}\n\nexport type EscrowStatus = 'ACTIVE' | 'RELEASED' | 'REFUNDED';\n\nexport interface EscrowActionResponse {\n success: boolean;\n errorReason?: string;\n transaction?: string;\n network?: string;\n}\n\n// Invoices\nexport type InvoiceStatus = 'UNSPECIFIED' | 'PENDING' | 'PARTIALLY_PAID' | 'PAID' | 'CANCELLED' | 'EXPIRED';\n\nexport interface Invoice {\n invoice_id: string;\n merchant: string;\n payer: string;\n amount: string;\n paid_amount: string;\n due_date: number;\n created_at: number;\n payment_type: 'DIRECT' | 'ESCROW';\n status: InvoiceStatus;\n metadata_uri: string;\n}\n\nexport interface CreateInvoiceRequest {\n merchant?: string;\n amount: string;\n payer?: string;\n due_date: number;\n payment_type: 'DIRECT' | 'ESCROW';\n metadata_uri: string;\n}\n\nexport interface InvoiceResponse {\n invoice: Invoice;\n}\n\nexport interface InvoiceListResponse {\n invoices: Invoice[];\n next_page_token: string;\n}\n","import { HttpClient } from '../core/http-client';\nimport { WalletModule } from '../wallet';\nimport {\n PaymentRequirements,\n PaymentAuthorization,\n SignedAuthorization,\n VerifyResponse,\n SettleResponse,\n SupportedSchemesResponse,\n EIP712TypedData,\n Invoice,\n PaymentType\n} from '../types';\nimport { PaymentError } from '../core/errors';\n\nexport class PaymentModule {\n constructor(\n private http: HttpClient,\n private wallet: WalletModule\n ) { }\n\n async pay(request: { requirements: PaymentRequirements; from?: string }): Promise<SettleResponse> {\n const from = request.from || request.requirements.from || this.wallet.getAddress();\n if (!from) throw new PaymentError('No sender address provided');\n\n // Create requirements with `from` set for EIP-1271 Smart Account signature verification\n const requirementsWithFrom: PaymentRequirements = {\n ...request.requirements,\n from, // Critical: backend needs to know which Smart Account is the payer\n };\n\n const auth = this.buildAuthorization(requirementsWithFrom, from);\n const signed = await this.signAuthorization(auth, requirementsWithFrom);\n\n const verification = await this.verify(signed, requirementsWithFrom);\n if (!verification.isValid) {\n throw new PaymentError(`Payment verification failed: ${verification.invalidReason}`);\n }\n\n return this.settle(signed, requirementsWithFrom);\n }\n\n /**\n * Pay an invoice\n * @param invoice The invoice to pay\n * @param params Payment parameters (amount, asset, network)\n */\n async payInvoice(invoice: Invoice, params: {\n amount: string; // Atomic units\n asset: string;\n network: string;\n payTo?: string; // Defaults to invoice.merchant\n from?: string; // Payer Smart Account address\n }): Promise<SettleResponse> {\n const payTo = params.payTo || invoice.merchant;\n if (!payTo) throw new PaymentError('No payee address (merchant) available for invoice');\n\n const requirements: PaymentRequirements = {\n scheme: 'exact',\n network: params.network,\n maxAmountRequired: params.amount,\n asset: params.asset,\n payTo,\n maxTimeoutSeconds: 3600,\n extra: {\n name: 'x402 Payment Token',\n version: '1',\n payment_type: PaymentType.INVOICE,\n invoice_id: invoice.invoice_id,\n invoice_payment_type: invoice.payment_type\n }\n };\n\n return this.pay({\n requirements,\n from: params.from\n });\n }\n\n buildAuthorization(requirements: PaymentRequirements, from: string): PaymentAuthorization {\n const array = new Uint8Array(32);\n crypto.getRandomValues(array);\n const nonce = '0x' + Array.from(array).map(b => b.toString(16).padStart(2, '0')).join('');\n\n const now = Math.floor(Date.now() / 1000);\n\n return {\n from,\n to: requirements.payTo,\n value: requirements.maxAmountRequired,\n validAfter: now - 60, // 60s buffer\n validBefore: now + requirements.maxTimeoutSeconds,\n nonce\n };\n }\n\n async signAuthorization(authorization: PaymentAuthorization, requirements: PaymentRequirements): Promise<SignedAuthorization> {\n let chainId: number;\n const network = requirements.network;\n if (network.startsWith('eip155:')) {\n chainId = parseInt(network.split(':')[1], 10);\n } else {\n chainId = parseInt(network, 10);\n }\n\n if (isNaN(chainId)) throw new PaymentError('Invalid chain ID');\n\n // EIP-712 requires uint256 values as BigInt for proper encoding\n const typedData: EIP712TypedData = {\n domain: {\n name: requirements.extra?.name || \"x402 Payment Token\",\n version: requirements.extra?.version || \"1\",\n chainId,\n verifyingContract: requirements.asset\n },\n types: {\n TransferWithAuthorization: [\n { name: \"from\", type: \"address\" },\n { name: \"to\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"validAfter\", type: \"uint256\" },\n { name: \"validBefore\", type: \"uint256\" },\n { name: \"nonce\", type: \"bytes32\" }\n ]\n },\n primaryType: \"TransferWithAuthorization\",\n message: {\n from: authorization.from,\n to: authorization.to,\n // CRITICAL: viem requires BigInt for uint256 types\n value: BigInt(authorization.value),\n validAfter: BigInt(authorization.validAfter),\n validBefore: BigInt(authorization.validBefore),\n nonce: authorization.nonce\n }\n };\n\n const signature = await this.wallet.signTypedData(typedData);\n return { ...authorization, signature };\n }\n\n encodePaymentHeader(signed: SignedAuthorization, requirements: PaymentRequirements): string {\n const authorization = {\n from: signed.from,\n to: signed.to,\n value: signed.value,\n nonce: signed.nonce,\n validAfter: signed.validAfter.toString(),\n validBefore: signed.validBefore.toString(),\n };\n\n const accepted = {\n scheme: requirements.scheme,\n network: requirements.network,\n amount: requirements.maxAmountRequired,\n asset: requirements.asset,\n payTo: requirements.payTo,\n maxTimeoutSeconds: requirements.maxTimeoutSeconds,\n };\n\n const paymentPayload = {\n x402Version: 1,\n accepted,\n payload: {\n authorization,\n signature: signed.signature,\n },\n };\n\n const jsonStr = JSON.stringify(paymentPayload);\n const b64Str = btoa(jsonStr);\n return `x402 ${b64Str}`;\n }\n\n async verify(signed: SignedAuthorization, requirements: PaymentRequirements): Promise<VerifyResponse> {\n const header = this.encodePaymentHeader(signed, requirements);\n return this.http.post<VerifyResponse>('/x402/verify', {\n x402Version: 1,\n paymentHeader: header,\n paymentRequirements: requirements\n }, { skipAuth: true });\n }\n\n async settle(signed: SignedAuthorization, requirements: PaymentRequirements): Promise<SettleResponse> {\n const header = this.encodePaymentHeader(signed, requirements);\n return this.http.post<SettleResponse>('/x402/settle', {\n x402Version: 1,\n paymentHeader: header,\n paymentRequirements: requirements\n }, { skipAuth: true });\n }\n\n /**\n * Get supported payment schemes from the facilitator.\n * This endpoint does not require authentication.\n */\n async getSupportedSchemes(): Promise<SupportedSchemesResponse> {\n return this.http.get<SupportedSchemesResponse>('/x402/supported', { skipAuth: true });\n }\n}\n"]}
|
|
@@ -39,19 +39,20 @@ var AccountModule = class {
|
|
|
39
39
|
return response.wallet_address;
|
|
40
40
|
}
|
|
41
41
|
mapAccount(data) {
|
|
42
|
+
const d = data;
|
|
42
43
|
return {
|
|
43
|
-
id:
|
|
44
|
-
ownerAddress:
|
|
45
|
-
walletAddress:
|
|
46
|
-
status:
|
|
47
|
-
kycLevel:
|
|
48
|
-
userId:
|
|
49
|
-
createdAt:
|
|
50
|
-
updatedAt:
|
|
44
|
+
id: d.id,
|
|
45
|
+
ownerAddress: d.owner_address,
|
|
46
|
+
walletAddress: d.wallet_address,
|
|
47
|
+
status: d.status,
|
|
48
|
+
kycLevel: d.kyc_level ?? 0,
|
|
49
|
+
userId: d.user_id,
|
|
50
|
+
createdAt: d.created_at,
|
|
51
|
+
updatedAt: d.updated_at
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
exports.AccountModule = AccountModule;
|
|
56
|
-
//# sourceMappingURL=chunk-
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
57
|
+
//# sourceMappingURL=chunk-XFJ6SPQN.js.map
|
|
58
|
+
//# sourceMappingURL=chunk-XFJ6SPQN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/account/index.ts"],"names":[],"mappings":";;;AAGO,IAAM,gBAAN,MAAoB;AAAA,EACvB,YAAoB,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAoB;AAAA,EAExC,MAAM,IAAI,EAAA,EAA8B;AACpC,IAAA,MAAM,WAAW,MAAM,IAAA,CAAK,KAAK,GAAA,CAA0B,CAAA,UAAA,EAAa,EAAE,CAAA,CAAE,CAAA;AAC5E,IAAA,OAAO,IAAA,CAAK,UAAA,CAAW,QAAA,CAAS,OAAO,CAAA;AAAA,EAC3C;AAAA,EAEA,MAAM,YAAY,OAAA,EAAmC;AAMjD,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,IAAA,EAAK;AACjC,IAAA,MAAM,OAAA,GAAU,QAAA,CAAS,IAAA,CAAK,CAAA,CAAA,KAAK,CAAA,CAAE,cAAc,WAAA,EAAY,KAAM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AAA,MACzB,QAAQ,CAAA,CAAE,OAAA;AAAA,MACV,WAAW,CAAA,CAAE,UAAA;AAAA,MACb,WAAW,CAAA,CAAE;AAAA,KACjB;AAAA,EACJ;AACJ","file":"chunk-XFJ6SPQN.js","sourcesContent":["import { HttpClient } from '../core/http-client';\nimport { Account, CreateAccountParams, CreateAccountResponse } from '../types';\n\nexport class AccountModule {\n constructor(private http: HttpClient) { }\n\n async get(id: string): Promise<Account> {\n const response = await this.http.get<{ account: unknown }>(`/accounts/${id}`);\n return this.mapAccount(response.account);\n }\n\n async getByWallet(address: string): Promise<Account> {\n // Assuming API supports query param or specific endpoint. \n // The task list says \"GET /accounts -> { accounts: [...] }\". \n // It doesn't explicitly have a \"get by wallet\" endpoint, but usually list filters.\n // Or maybe we filter the list.\n // \"GET /accounts\" implies listing current user's accounts usually?\n const response = await this.list();\n const account = response.find(a => a.walletAddress.toLowerCase() === address.toLowerCase());\n if (!account) {\n throw new Error('Account not found for wallet');\n }\n return account;\n }\n\n async list(): Promise<Account[]> {\n const response = await this.http.get<{ accounts: unknown[] }>('/accounts');\n return response.accounts.map(this.mapAccount);\n }\n\n async create(params: CreateAccountParams): Promise<CreateAccountResponse> {\n const response = await this.http.post<any>('/accounts', {\n owner_address: params.ownerAddress,\n salt: params.salt,\n });\n\n return {\n account: this.mapAccount(response.account),\n txHash: response.tx_hash,\n };\n }\n\n async predictAddress(params: { ownerAddress: string; salt: string }): Promise<string> {\n const response = await this.http.post<{ wallet_address: string }>('/accounts/predict', {\n owner_address: params.ownerAddress,\n salt: params.salt,\n });\n return response.wallet_address;\n }\n\n private mapAccount(data: any): Account {\n // Map snake_case to camelCase\n const d = data as any;\n return {\n id: d.id,\n ownerAddress: d.owner_address,\n walletAddress: d.wallet_address,\n status: d.status,\n kycLevel: d.kyc_level ?? 0,\n userId: d.user_id,\n createdAt: d.created_at,\n updatedAt: d.updated_at,\n };\n }\n}\n"]}
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkG525R6AV_js = require('./chunk-G525R6AV.js');
|
|
4
4
|
|
|
5
|
+
// src/types/index.ts
|
|
6
|
+
var PaymentType = /* @__PURE__ */ ((PaymentType2) => {
|
|
7
|
+
PaymentType2["UNSPECIFIED"] = "UNSPECIFIED";
|
|
8
|
+
PaymentType2["DIRECT"] = "DIRECT";
|
|
9
|
+
PaymentType2["ESCROW"] = "ESCROW";
|
|
10
|
+
PaymentType2["INVOICE"] = "INVOICE";
|
|
11
|
+
return PaymentType2;
|
|
12
|
+
})(PaymentType || {});
|
|
13
|
+
|
|
5
14
|
// src/payment/index.ts
|
|
6
15
|
var PaymentModule = class {
|
|
7
16
|
constructor(http, wallet) {
|
|
@@ -24,6 +33,34 @@ var PaymentModule = class {
|
|
|
24
33
|
}
|
|
25
34
|
return this.settle(signed, requirementsWithFrom);
|
|
26
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Pay an invoice
|
|
38
|
+
* @param invoice The invoice to pay
|
|
39
|
+
* @param params Payment parameters (amount, asset, network)
|
|
40
|
+
*/
|
|
41
|
+
async payInvoice(invoice, params) {
|
|
42
|
+
const payTo = params.payTo || invoice.merchant;
|
|
43
|
+
if (!payTo) throw new chunkG525R6AV_js.PaymentError("No payee address (merchant) available for invoice");
|
|
44
|
+
const requirements = {
|
|
45
|
+
scheme: "exact",
|
|
46
|
+
network: params.network,
|
|
47
|
+
maxAmountRequired: params.amount,
|
|
48
|
+
asset: params.asset,
|
|
49
|
+
payTo,
|
|
50
|
+
maxTimeoutSeconds: 3600,
|
|
51
|
+
extra: {
|
|
52
|
+
name: "x402 Payment Token",
|
|
53
|
+
version: "1",
|
|
54
|
+
payment_type: "INVOICE" /* INVOICE */,
|
|
55
|
+
invoice_id: invoice.invoice_id,
|
|
56
|
+
invoice_payment_type: invoice.payment_type
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return this.pay({
|
|
60
|
+
requirements,
|
|
61
|
+
from: params.from
|
|
62
|
+
});
|
|
63
|
+
}
|
|
27
64
|
buildAuthorization(requirements, from) {
|
|
28
65
|
const array = new Uint8Array(32);
|
|
29
66
|
crypto.getRandomValues(array);
|
|
@@ -134,5 +171,6 @@ var PaymentModule = class {
|
|
|
134
171
|
};
|
|
135
172
|
|
|
136
173
|
exports.PaymentModule = PaymentModule;
|
|
137
|
-
|
|
138
|
-
//# sourceMappingURL=chunk-
|
|
174
|
+
exports.PaymentType = PaymentType;
|
|
175
|
+
//# sourceMappingURL=chunk-XPW56652.js.map
|
|
176
|
+
//# sourceMappingURL=chunk-XPW56652.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/index.ts","../src/payment/index.ts"],"names":["PaymentType","PaymentError"],"mappings":";;;;;AAiGO,IAAK,WAAA,qBAAAA,YAAAA,KAAL;AACH,EAAAA,aAAA,aAAA,CAAA,GAAc,aAAA;AACd,EAAAA,aAAA,QAAA,CAAA,GAAS,QAAA;AACT,EAAAA,aAAA,QAAA,CAAA,GAAS,QAAA;AACT,EAAAA,aAAA,SAAA,CAAA,GAAU,SAAA;AAJF,EAAA,OAAAA,YAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;;;AClFL,IAAM,gBAAN,MAAoB;AAAA,EACvB,WAAA,CACY,MACA,MAAA,EACV;AAFU,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EACR;AAAA,EAEJ,MAAM,IAAI,OAAA,EAAwF;AAC9F,IAAA,MAAM,IAAA,GAAO,QAAQ,IAAA,IAAQ,OAAA,CAAQ,aAAa,IAAA,IAAQ,IAAA,CAAK,OAAO,UAAA,EAAW;AACjF,IAAA,IAAI,CAAC,IAAA,EAAM,MAAM,IAAIC,8BAAa,4BAA4B,CAAA;AAG9D,IAAA,MAAM,oBAAA,GAA4C;AAAA,MAC9C,GAAG,OAAA,CAAQ,YAAA;AAAA,MACX;AAAA;AAAA,KACJ;AAEA,IAA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YAAA,EAA4D;AAClG,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,mBAAA,CAAoB,MAAA,EAAQ,YAAY,CAAA;AAC5D,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAqB,cAAA,EAAgB;AAAA,MAClD,WAAA,EAAa,CAAA;AAAA,MACb,aAAA,EAAe,MAAA;AAAA,MACf,mBAAA,EAAqB;AAAA,KACzB,EAAG,EAAE,QAAA,EAAU,IAAA,EAAM,CAAA;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,mBAAA,GAAyD;AAC3D,IAAA,OAAO,KAAK,IAAA,CAAK,GAAA,CAA8B,mBAAmB,EAAE,QAAA,EAAU,MAAM,CAAA;AAAA,EACxF;AACJ","file":"chunk-XPW56652.js","sourcesContent":["export interface UPSConfig {\n baseUrl: string; // API base URL\n network: string; // CAIP-2 format: \"eip155:737998412\"\n chainId?: number; // Optional, parsed from network if not provided\n timeout?: number; // Request timeout (default: 30000)\n retryAttempts?: number; // Retry count (default: 3)\n refreshInterval?: number; // Token refresh interval in ms (default: 60000 = 1 min)\n}\n\n// Authentication\nexport interface AuthState {\n isAuthenticated: boolean;\n token: string | null;\n expiresAt: Date | null;\n address: string | null;\n}\n\nexport interface AuthResult {\n token: string;\n expiresAt: string;\n}\n\n// User (from /auth/connect and /users/me)\nexport interface User {\n id: string;\n walletAddress: string;\n status: string;\n createdAt: string;\n}\n\n// Connect auth result (unified auth flow)\nexport interface ConnectResult {\n user: User;\n token: string;\n expiresAt: string;\n isNewUser: boolean;\n}\n\n// Wallet\nexport type EIP1193Provider = {\n request: (args: { method: string; params?: unknown[] }) => Promise<unknown>;\n on?: (event: string, handler: (...args: unknown[]) => void) => void;\n removeListener?: (event: string, handler: (...args: unknown[]) => void) => void;\n};\n\nexport interface WalletState {\n isConnected: boolean;\n address: string | null;\n chainId: number | null;\n provider: EIP1193Provider | null;\n}\n\nexport interface ConnectedWallet {\n address: string;\n chainId: number;\n provider: EIP1193Provider;\n}\n\n// Account\nexport type AccountStatus = 'pending' | 'kyc_in_progress' | 'active' | 'frozen' | 'closed';\n\nexport interface Account {\n id: string;\n ownerAddress: string;\n walletAddress: string;\n status: AccountStatus;\n kycLevel: number;\n userId?: string;\n createdAt: string;\n updatedAt?: string;\n}\n\nexport interface CreateAccountParams {\n ownerAddress: string;\n salt: string; // 0x-prefixed 32-byte hex\n}\n\nexport interface CreateAccountResponse {\n account: Account;\n txHash: string;\n}\n\n// Payment (x402)\nexport interface PaymentRequirements {\n scheme: string;\n network: string;\n maxAmountRequired: string;\n asset: string;\n payTo: string;\n maxTimeoutSeconds: number;\n resource?: string;\n description?: string;\n\n extra?: PaymentExtra;\n from?: string;\n}\n\nexport enum PaymentType {\n UNSPECIFIED = 'UNSPECIFIED',\n DIRECT = 'DIRECT',\n ESCROW = 'ESCROW',\n INVOICE = 'INVOICE'\n}\n\nexport interface PaymentExtra {\n name?: string;\n version?: string;\n payment_type?: PaymentType; // snake_case from API\n arbiter?: string;\n release_time?: number; // snake_case from API\n payee?: string; // intended recipient for escrow\n invoice_id?: string;\n invoice_payment_type?: 'DIRECT' | 'ESCROW';\n}\n\nexport interface PaymentAuthorization {\n from: string;\n to: string;\n value: string;\n validAfter: number;\n validBefore: number;\n nonce: string; // bytes32 hex\n}\n\nexport interface SignedAuthorization extends PaymentAuthorization {\n signature: string;\n}\n\nexport interface VerifyResponse {\n isValid: boolean;\n invalidReason?: string;\n payer?: string;\n}\n\nexport interface SettleResponse {\n success: boolean;\n errorReason?: string;\n transaction?: string;\n network?: string;\n payer?: string;\n}\n\n// x402 Supported Schemes\nexport interface SupportedScheme {\n x402Version: number;\n scheme: string;\n network: string;\n}\n\nexport interface SupportedSchemesResponse {\n kinds: SupportedScheme[];\n extensions?: string[];\n signers?: Record<string, string[]>;\n}\n\n// EIP-712 Typed Data\nexport interface EIP712Domain {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: string;\n}\n\nexport interface EIP712Type {\n name: string;\n type: string;\n}\n\nexport interface EIP712TypedData {\n domain: EIP712Domain;\n types: Record<string, EIP712Type[]>;\n primaryType: string;\n message: Record<string, unknown>;\n}\n\n// Escrow\nexport interface Escrow {\n escrowId: string;\n payer: string;\n payee: string;\n amount: string;\n arbiter: string;\n releaseTime: number;\n status: EscrowStatus;\n}\n\nexport type EscrowStatus = 'ACTIVE' | 'RELEASED' | 'REFUNDED';\n\nexport interface EscrowActionResponse {\n success: boolean;\n errorReason?: string;\n transaction?: string;\n network?: string;\n}\n\n// Invoices\nexport type InvoiceStatus = 'UNSPECIFIED' | 'PENDING' | 'PARTIALLY_PAID' | 'PAID' | 'CANCELLED' | 'EXPIRED';\n\nexport interface Invoice {\n invoice_id: string;\n merchant: string;\n payer: string;\n amount: string;\n paid_amount: string;\n due_date: number;\n created_at: number;\n payment_type: 'DIRECT' | 'ESCROW';\n status: InvoiceStatus;\n metadata_uri: string;\n}\n\nexport interface CreateInvoiceRequest {\n merchant?: string;\n amount: string;\n payer?: string;\n due_date: number;\n payment_type: 'DIRECT' | 'ESCROW';\n metadata_uri: string;\n}\n\nexport interface InvoiceResponse {\n invoice: Invoice;\n}\n\nexport interface InvoiceListResponse {\n invoices: Invoice[];\n next_page_token: string;\n}\n","import { HttpClient } from '../core/http-client';\nimport { WalletModule } from '../wallet';\nimport {\n PaymentRequirements,\n PaymentAuthorization,\n SignedAuthorization,\n VerifyResponse,\n SettleResponse,\n SupportedSchemesResponse,\n EIP712TypedData,\n Invoice,\n PaymentType\n} from '../types';\nimport { PaymentError } from '../core/errors';\n\nexport class PaymentModule {\n constructor(\n private http: HttpClient,\n private wallet: WalletModule\n ) { }\n\n async pay(request: { requirements: PaymentRequirements; from?: string }): Promise<SettleResponse> {\n const from = request.from || request.requirements.from || this.wallet.getAddress();\n if (!from) throw new PaymentError('No sender address provided');\n\n // Create requirements with `from` set for EIP-1271 Smart Account signature verification\n const requirementsWithFrom: PaymentRequirements = {\n ...request.requirements,\n from, // Critical: backend needs to know which Smart Account is the payer\n };\n\n const auth = this.buildAuthorization(requirementsWithFrom, from);\n const signed = await this.signAuthorization(auth, requirementsWithFrom);\n\n const verification = await this.verify(signed, requirementsWithFrom);\n if (!verification.isValid) {\n throw new PaymentError(`Payment verification failed: ${verification.invalidReason}`);\n }\n\n return this.settle(signed, requirementsWithFrom);\n }\n\n /**\n * Pay an invoice\n * @param invoice The invoice to pay\n * @param params Payment parameters (amount, asset, network)\n */\n async payInvoice(invoice: Invoice, params: {\n amount: string; // Atomic units\n asset: string;\n network: string;\n payTo?: string; // Defaults to invoice.merchant\n from?: string; // Payer Smart Account address\n }): Promise<SettleResponse> {\n const payTo = params.payTo || invoice.merchant;\n if (!payTo) throw new PaymentError('No payee address (merchant) available for invoice');\n\n const requirements: PaymentRequirements = {\n scheme: 'exact',\n network: params.network,\n maxAmountRequired: params.amount,\n asset: params.asset,\n payTo,\n maxTimeoutSeconds: 3600,\n extra: {\n name: 'x402 Payment Token',\n version: '1',\n payment_type: PaymentType.INVOICE,\n invoice_id: invoice.invoice_id,\n invoice_payment_type: invoice.payment_type\n }\n };\n\n return this.pay({\n requirements,\n from: params.from\n });\n }\n\n buildAuthorization(requirements: PaymentRequirements, from: string): PaymentAuthorization {\n const array = new Uint8Array(32);\n crypto.getRandomValues(array);\n const nonce = '0x' + Array.from(array).map(b => b.toString(16).padStart(2, '0')).join('');\n\n const now = Math.floor(Date.now() / 1000);\n\n return {\n from,\n to: requirements.payTo,\n value: requirements.maxAmountRequired,\n validAfter: now - 60, // 60s buffer\n validBefore: now + requirements.maxTimeoutSeconds,\n nonce\n };\n }\n\n async signAuthorization(authorization: PaymentAuthorization, requirements: PaymentRequirements): Promise<SignedAuthorization> {\n let chainId: number;\n const network = requirements.network;\n if (network.startsWith('eip155:')) {\n chainId = parseInt(network.split(':')[1], 10);\n } else {\n chainId = parseInt(network, 10);\n }\n\n if (isNaN(chainId)) throw new PaymentError('Invalid chain ID');\n\n // EIP-712 requires uint256 values as BigInt for proper encoding\n const typedData: EIP712TypedData = {\n domain: {\n name: requirements.extra?.name || \"x402 Payment Token\",\n version: requirements.extra?.version || \"1\",\n chainId,\n verifyingContract: requirements.asset\n },\n types: {\n TransferWithAuthorization: [\n { name: \"from\", type: \"address\" },\n { name: \"to\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"validAfter\", type: \"uint256\" },\n { name: \"validBefore\", type: \"uint256\" },\n { name: \"nonce\", type: \"bytes32\" }\n ]\n },\n primaryType: \"TransferWithAuthorization\",\n message: {\n from: authorization.from,\n to: authorization.to,\n // CRITICAL: viem requires BigInt for uint256 types\n value: BigInt(authorization.value),\n validAfter: BigInt(authorization.validAfter),\n validBefore: BigInt(authorization.validBefore),\n nonce: authorization.nonce\n }\n };\n\n const signature = await this.wallet.signTypedData(typedData);\n return { ...authorization, signature };\n }\n\n encodePaymentHeader(signed: SignedAuthorization, requirements: PaymentRequirements): string {\n const authorization = {\n from: signed.from,\n to: signed.to,\n value: signed.value,\n nonce: signed.nonce,\n validAfter: signed.validAfter.toString(),\n validBefore: signed.validBefore.toString(),\n };\n\n const accepted = {\n scheme: requirements.scheme,\n network: requirements.network,\n amount: requirements.maxAmountRequired,\n asset: requirements.asset,\n payTo: requirements.payTo,\n maxTimeoutSeconds: requirements.maxTimeoutSeconds,\n };\n\n const paymentPayload = {\n x402Version: 1,\n accepted,\n payload: {\n authorization,\n signature: signed.signature,\n },\n };\n\n const jsonStr = JSON.stringify(paymentPayload);\n const b64Str = btoa(jsonStr);\n return `x402 ${b64Str}`;\n }\n\n async verify(signed: SignedAuthorization, requirements: PaymentRequirements): Promise<VerifyResponse> {\n const header = this.encodePaymentHeader(signed, requirements);\n return this.http.post<VerifyResponse>('/x402/verify', {\n x402Version: 1,\n paymentHeader: header,\n paymentRequirements: requirements\n }, { skipAuth: true });\n }\n\n async settle(signed: SignedAuthorization, requirements: PaymentRequirements): Promise<SettleResponse> {\n const header = this.encodePaymentHeader(signed, requirements);\n return this.http.post<SettleResponse>('/x402/settle', {\n x402Version: 1,\n paymentHeader: header,\n paymentRequirements: requirements\n }, { skipAuth: true });\n }\n\n /**\n * Get supported payment schemes from the facilitator.\n * This endpoint does not require authentication.\n */\n async getSupportedSchemes(): Promise<SupportedSchemesResponse> {\n return this.http.get<SupportedSchemesResponse>('/x402/supported', { skipAuth: true });\n }\n}\n"]}
|
|
@@ -44,10 +44,11 @@ var WalletModule = class {
|
|
|
44
44
|
provider
|
|
45
45
|
};
|
|
46
46
|
} catch (error) {
|
|
47
|
-
|
|
47
|
+
const e = error;
|
|
48
|
+
if (e.code === 4001) {
|
|
48
49
|
throw new WalletError("User rejected connection");
|
|
49
50
|
}
|
|
50
|
-
throw new WalletError(`Connection failed: ${
|
|
51
|
+
throw new WalletError(`Connection failed: ${e.message || "Unknown error"}`, error);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
54
|
async disconnect() {
|
|
@@ -80,8 +81,9 @@ var WalletModule = class {
|
|
|
80
81
|
message
|
|
81
82
|
});
|
|
82
83
|
} catch (error) {
|
|
83
|
-
|
|
84
|
-
throw new WalletError(
|
|
84
|
+
const e = error;
|
|
85
|
+
if (e.code === 4001) throw new WalletError("User rejected signing");
|
|
86
|
+
throw new WalletError(`Sign message failed: ${e.message || "Unknown error"}`, error);
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
async signTypedData(typedData) {
|
|
@@ -97,8 +99,9 @@ var WalletModule = class {
|
|
|
97
99
|
message: typedData.message
|
|
98
100
|
});
|
|
99
101
|
} catch (error) {
|
|
100
|
-
|
|
101
|
-
throw new WalletError(
|
|
102
|
+
const e = error;
|
|
103
|
+
if (e.code === 4001) throw new WalletError("User rejected signing");
|
|
104
|
+
throw new WalletError(`Sign typed data failed: ${e.message || "Unknown error"}`, error);
|
|
102
105
|
}
|
|
103
106
|
}
|
|
104
107
|
async switchChain(chainId) {
|
|
@@ -113,15 +116,17 @@ var WalletModule = class {
|
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
118
|
onStateChange(callback) {
|
|
116
|
-
const unsub1 = this.eventBus.on("wallet:
|
|
119
|
+
const unsub1 = this.eventBus.on("wallet:stateChanged", () => callback(this._state));
|
|
117
120
|
return unsub1;
|
|
118
121
|
}
|
|
119
122
|
updateState(newState) {
|
|
120
123
|
this._state = newState;
|
|
124
|
+
this.eventBus.emit("wallet:stateChanged", this._state);
|
|
121
125
|
}
|
|
122
126
|
setupListeners(provider) {
|
|
123
127
|
if (!provider.on) return;
|
|
124
|
-
provider.on("accountsChanged", (
|
|
128
|
+
provider.on("accountsChanged", (...args) => {
|
|
129
|
+
const accounts = args[0];
|
|
125
130
|
if (accounts.length === 0) {
|
|
126
131
|
this.disconnect();
|
|
127
132
|
} else {
|
|
@@ -129,7 +134,8 @@ var WalletModule = class {
|
|
|
129
134
|
this.eventBus.emit("wallet:accountsChanged", accounts);
|
|
130
135
|
}
|
|
131
136
|
});
|
|
132
|
-
provider.on("chainChanged", (
|
|
137
|
+
provider.on("chainChanged", (...args) => {
|
|
138
|
+
const chainId = args[0];
|
|
133
139
|
const id = parseInt(chainId, 16);
|
|
134
140
|
this.updateState({ ...this._state, chainId: id });
|
|
135
141
|
this.eventBus.emit("wallet:chainChanged", id);
|
|
@@ -144,5 +150,5 @@ var WalletModule = class {
|
|
|
144
150
|
};
|
|
145
151
|
|
|
146
152
|
export { WalletModule };
|
|
147
|
-
//# sourceMappingURL=chunk-
|
|
148
|
-
//# sourceMappingURL=chunk-
|
|
153
|
+
//# sourceMappingURL=chunk-ZVB256ZP.mjs.map
|
|
154
|
+
//# sourceMappingURL=chunk-ZVB256ZP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/wallet/index.ts"],"names":[],"mappings":";;;;AAMO,IAAM,eAAN,MAAmB;AAAA,EAUtB,YAAoB,QAAA,EAAoB;AAApB,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAAA,EAAsB;AAAA,EATlC,MAAA,GAAsB;AAAA,IAC1B,WAAA,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D;AAAA,IACJ,CAAC,CAAA;AAED,IAAA,QAAA,CAAS,EAAA,CAAG,cAAA,EAAgB,CAAA,GAAI,IAAA,KAAoB;AAChD,MAAA,MAAM,OAAA,GAAU,KAAK,CAAC,CAAA;AACtB,MAAA,MAAM,EAAA,GAAK,QAAA,CAAS,OAAA,EAAS,EAAE,CAAA;AAC/B,MAAA,IAAA,CAAK,YAAY,EAAE,GAAG,KAAK,MAAA,EAAQ,OAAA,EAAS,IAAI,CAAA;AAGhD,MAAA,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,qBAAA,EAAuB,EAAE,CAAA;AAAA,IAChD,CAAC,CAAA;AAED,IAAA,QAAA,CAAS,EAAA,CAAG,cAAc,MAAM;AAC5B,MAAA,IAAA,CAAK,UAAA,EAAW;AAAA,IACpB,CAAC,CAAA;AAAA,EACL;AAAA,EAEQ,SAAS,OAAA,EAAiB;AAC9B,IAAA,OAAO,KAAK,MAAA,CAAO,IAAA,CAAK,CAAA,CAAA,KAAK,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,EACjD;AACJ","file":"chunk-ZVB256ZP.mjs","sourcesContent":["import { createWalletClient, custom, WalletClient } from 'viem';\nimport { mainnet, base, baseSepolia } from 'viem/chains';\nimport { WalletState, ConnectedWallet, EIP1193Provider, EIP712TypedData } from '../types';\nimport { EventBus } from '../core/event-bus';\nimport { WalletError } from '../core/errors';\n\nexport class WalletModule {\n private _state: WalletState = {\n isConnected: false,\n address: null,\n chainId: null,\n provider: null,\n };\n private client: WalletClient | null = null;\n private chains = [mainnet, base, baseSepolia];\n\n constructor(private eventBus: EventBus) { }\n\n get state(): WalletState {\n return { ...this._state };\n }\n\n async connect(provider: EIP1193Provider): Promise<ConnectedWallet> {\n try {\n this.setupListeners(provider);\n\n const addresses = (await provider.request({ method: 'eth_requestAccounts' })) as string[];\n if (!addresses || addresses.length === 0) {\n throw new WalletError('No accounts found');\n }\n\n const chainIdHex = (await provider.request({ method: 'eth_chainId' })) as string;\n const chainId = parseInt(chainIdHex, 16);\n\n this.client = createWalletClient({\n chain: this.getChain(chainId),\n transport: custom(provider),\n });\n\n const address = addresses[0];\n\n this.updateState({\n isConnected: true,\n address,\n chainId,\n provider,\n });\n\n this.eventBus.emit('wallet:connected', this._state);\n\n return {\n address,\n chainId,\n provider,\n };\n } catch (error: unknown) {\n const e = error as { code?: number; message?: string };\n if (e.code === 4001) {\n throw new WalletError('User rejected connection');\n }\n throw new WalletError(`Connection failed: ${e.message || 'Unknown error'}`, error as Error);\n }\n }\n\n async disconnect(): Promise<void> {\n // Remove listeners if needed (not easily possible with just EIP1193Provider standard without storing internal listener refs, but we can clear state)\n // Actually standard providers like Metamask don't really 'disconnect' via API, but we act as if we did.\n if (this._state.provider && this._state.provider.removeListener) {\n // We should ideally remove listeners we added.\n // For simplicity in this scope, we just resetting state.\n }\n\n this.updateState({\n isConnected: false,\n address: null,\n chainId: null,\n provider: null\n });\n this.client = null;\n this.eventBus.emit('wallet:disconnected', undefined);\n }\n\n getAddress(): string | null {\n return this._state.address;\n }\n\n getChainId(): number | null {\n return this._state.chainId;\n }\n\n isConnected(): boolean {\n return this._state.isConnected;\n }\n\n async signMessage(message: string): Promise<string> {\n if (!this.client || !this._state.address) {\n throw new WalletError('Wallet not connected');\n }\n try {\n return await this.client.signMessage({\n account: this._state.address as `0x${string}`,\n message,\n });\n } catch (error: unknown) {\n const e = error as { code?: number; message?: string };\n if (e.code === 4001) throw new WalletError('User rejected signing');\n throw new WalletError(`Sign message failed: ${e.message || 'Unknown error'}`, error as Error);\n }\n }\n\n async signTypedData(typedData: EIP712TypedData): Promise<string> {\n if (!this.client || !this._state.address) {\n throw new WalletError('Wallet not connected');\n }\n try {\n // viem expects exact structure\n return await this.client.signTypedData({\n account: this._state.address as `0x${string}`,\n domain: typedData.domain as any,\n types: typedData.types as any,\n primaryType: typedData.primaryType,\n message: typedData.message,\n });\n } catch (error: unknown) {\n const e = error as { code?: number; message?: string };\n if (e.code === 4001) throw new WalletError('User rejected signing');\n throw new WalletError(`Sign typed data failed: ${e.message || 'Unknown error'}`, error as Error);\n }\n }\n\n async switchChain(chainId: number): Promise<void> {\n if (!this._state.provider) throw new WalletError('Provider not available');\n try {\n await this._state.provider.request({\n method: 'wallet_switchEthereumChain',\n params: [{ chainId: `0x${chainId.toString(16)}` }],\n });\n } catch (error: unknown) {\n throw new WalletError(`Switch chain failed: ${(error as Error).message}`, error as Error);\n }\n }\n\n onStateChange(callback: (state: WalletState) => void): () => void {\n const unsub1 = this.eventBus.on('wallet:stateChanged', () => callback(this._state));\n return unsub1;\n }\n\n private updateState(newState: WalletState) {\n this._state = newState;\n this.eventBus.emit('wallet:stateChanged', this._state);\n }\n\n private setupListeners(provider: EIP1193Provider) {\n if (!provider.on) return;\n\n provider.on('accountsChanged', (...args: unknown[]) => {\n const accounts = args[0] as string[];\n if (accounts.length === 0) {\n this.disconnect();\n } else {\n this.updateState({ ...this._state, address: accounts[0] });\n this.eventBus.emit('wallet:accountsChanged', accounts);\n }\n });\n\n provider.on('chainChanged', (...args: unknown[]) => {\n const chainId = args[0] as string;\n const id = parseInt(chainId, 16);\n this.updateState({ ...this._state, chainId: id });\n // Update client chain if possible or recreate?\n // For now just update state\n this.eventBus.emit('wallet:chainChanged', id);\n });\n\n provider.on('disconnect', () => {\n this.disconnect();\n });\n }\n\n private getChain(chainId: number) {\n return this.chains.find(c => c.id === chainId);\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { W as WalletState,
|
|
1
|
+
import { W as WalletState, f as EIP1193Provider, g as ConnectedWallet, n as EIP712TypedData } from './index-BEjQJc66.js';
|
|
2
2
|
|
|
3
3
|
type Callback<T = any> = (payload: T) => void;
|
|
4
4
|
type Unsubscribe = () => void;
|
|
@@ -33,8 +33,8 @@ type EIP1193Provider = {
|
|
|
33
33
|
method: string;
|
|
34
34
|
params?: unknown[];
|
|
35
35
|
}) => Promise<unknown>;
|
|
36
|
-
on?: (event: string, handler: (...args:
|
|
37
|
-
removeListener?: (event: string, handler: (...args:
|
|
36
|
+
on?: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
37
|
+
removeListener?: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
38
38
|
};
|
|
39
39
|
interface WalletState {
|
|
40
40
|
isConnected: boolean;
|
|
@@ -81,7 +81,8 @@ interface PaymentRequirements {
|
|
|
81
81
|
declare enum PaymentType {
|
|
82
82
|
UNSPECIFIED = "UNSPECIFIED",
|
|
83
83
|
DIRECT = "DIRECT",
|
|
84
|
-
ESCROW = "ESCROW"
|
|
84
|
+
ESCROW = "ESCROW",
|
|
85
|
+
INVOICE = "INVOICE"
|
|
85
86
|
}
|
|
86
87
|
interface PaymentExtra {
|
|
87
88
|
name?: string;
|
|
@@ -90,6 +91,8 @@ interface PaymentExtra {
|
|
|
90
91
|
arbiter?: string;
|
|
91
92
|
release_time?: number;
|
|
92
93
|
payee?: string;
|
|
94
|
+
invoice_id?: string;
|
|
95
|
+
invoice_payment_type?: 'DIRECT' | 'ESCROW';
|
|
93
96
|
}
|
|
94
97
|
interface PaymentAuthorization {
|
|
95
98
|
from: string;
|
|
@@ -156,5 +159,33 @@ interface EscrowActionResponse {
|
|
|
156
159
|
transaction?: string;
|
|
157
160
|
network?: string;
|
|
158
161
|
}
|
|
162
|
+
type InvoiceStatus = 'UNSPECIFIED' | 'PENDING' | 'PARTIALLY_PAID' | 'PAID' | 'CANCELLED' | 'EXPIRED';
|
|
163
|
+
interface Invoice {
|
|
164
|
+
invoice_id: string;
|
|
165
|
+
merchant: string;
|
|
166
|
+
payer: string;
|
|
167
|
+
amount: string;
|
|
168
|
+
paid_amount: string;
|
|
169
|
+
due_date: number;
|
|
170
|
+
created_at: number;
|
|
171
|
+
payment_type: 'DIRECT' | 'ESCROW';
|
|
172
|
+
status: InvoiceStatus;
|
|
173
|
+
metadata_uri: string;
|
|
174
|
+
}
|
|
175
|
+
interface CreateInvoiceRequest {
|
|
176
|
+
merchant?: string;
|
|
177
|
+
amount: string;
|
|
178
|
+
payer?: string;
|
|
179
|
+
due_date: number;
|
|
180
|
+
payment_type: 'DIRECT' | 'ESCROW';
|
|
181
|
+
metadata_uri: string;
|
|
182
|
+
}
|
|
183
|
+
interface InvoiceResponse {
|
|
184
|
+
invoice: Invoice;
|
|
185
|
+
}
|
|
186
|
+
interface InvoiceListResponse {
|
|
187
|
+
invoices: Invoice[];
|
|
188
|
+
next_page_token: string;
|
|
189
|
+
}
|
|
159
190
|
|
|
160
|
-
export { type AuthState as A, type ConnectResult as C, type Escrow as E, type PaymentAuthorization as P, type SettleResponse as S, type User as U, type VerifyResponse as V, type WalletState as W, type AuthResult as a, type EscrowActionResponse as b, type
|
|
191
|
+
export { type AuthState as A, type ConnectResult as C, type Escrow as E, type InvoiceResponse as I, type PaymentAuthorization as P, type SettleResponse as S, type User as U, type VerifyResponse as V, type WalletState as W, type AuthResult as a, type EscrowActionResponse as b, type CreateInvoiceRequest as c, type InvoiceListResponse as d, type UPSConfig as e, type EIP1193Provider as f, type ConnectedWallet as g, type Account as h, type AccountStatus as i, type CreateAccountParams as j, type CreateAccountResponse as k, type EIP712Domain as l, type EIP712Type as m, type EIP712TypedData as n, type EscrowStatus as o, type Invoice as p, type InvoiceStatus as q, type PaymentExtra as r, type PaymentRequirements as s, PaymentType as t, type SignedAuthorization as u, type SupportedScheme as v, type SupportedSchemesResponse as w };
|