@4mica/sdk 0.5.1 → 0.5.3
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/README.md +261 -394
- package/dist/abi/core4mica.d.ts +1244 -0
- package/dist/abi/core4mica.js +1606 -0
- package/dist/abi/erc20.d.ts +141 -0
- package/dist/abi/erc20.js +188 -0
- package/dist/auth.d.ts +2 -2
- package/dist/auth.js +11 -0
- package/dist/bls.js +3 -3
- package/dist/client.d.ts +7 -9
- package/dist/client.js +16 -26
- package/dist/config.d.ts +3 -4
- package/dist/config.js +12 -7
- package/dist/contract.d.ts +25 -20
- package/dist/contract.js +133 -89
- package/dist/errors.js +4 -0
- package/dist/guarantee.js +19 -20
- package/dist/models.js +63 -0
- package/dist/rpc.js +5 -0
- package/dist/signing.d.ts +6 -23
- package/dist/signing.js +25 -20
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +9 -5
- package/dist/x402/index.js +2 -0
- package/package.json +14 -14
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export declare const erc20Abi: readonly [{
|
|
2
|
+
readonly type: "function";
|
|
3
|
+
readonly name: "allowance";
|
|
4
|
+
readonly inputs: readonly [{
|
|
5
|
+
readonly name: "owner";
|
|
6
|
+
readonly type: "address";
|
|
7
|
+
readonly internalType: "address";
|
|
8
|
+
}, {
|
|
9
|
+
readonly name: "spender";
|
|
10
|
+
readonly type: "address";
|
|
11
|
+
readonly internalType: "address";
|
|
12
|
+
}];
|
|
13
|
+
readonly outputs: readonly [{
|
|
14
|
+
readonly name: "";
|
|
15
|
+
readonly type: "uint256";
|
|
16
|
+
readonly internalType: "uint256";
|
|
17
|
+
}];
|
|
18
|
+
readonly stateMutability: "view";
|
|
19
|
+
}, {
|
|
20
|
+
readonly type: "function";
|
|
21
|
+
readonly name: "approve";
|
|
22
|
+
readonly inputs: readonly [{
|
|
23
|
+
readonly name: "spender";
|
|
24
|
+
readonly type: "address";
|
|
25
|
+
readonly internalType: "address";
|
|
26
|
+
}, {
|
|
27
|
+
readonly name: "value";
|
|
28
|
+
readonly type: "uint256";
|
|
29
|
+
readonly internalType: "uint256";
|
|
30
|
+
}];
|
|
31
|
+
readonly outputs: readonly [{
|
|
32
|
+
readonly name: "";
|
|
33
|
+
readonly type: "bool";
|
|
34
|
+
readonly internalType: "bool";
|
|
35
|
+
}];
|
|
36
|
+
readonly stateMutability: "nonpayable";
|
|
37
|
+
}, {
|
|
38
|
+
readonly type: "function";
|
|
39
|
+
readonly name: "balanceOf";
|
|
40
|
+
readonly inputs: readonly [{
|
|
41
|
+
readonly name: "account";
|
|
42
|
+
readonly type: "address";
|
|
43
|
+
readonly internalType: "address";
|
|
44
|
+
}];
|
|
45
|
+
readonly outputs: readonly [{
|
|
46
|
+
readonly name: "";
|
|
47
|
+
readonly type: "uint256";
|
|
48
|
+
readonly internalType: "uint256";
|
|
49
|
+
}];
|
|
50
|
+
readonly stateMutability: "view";
|
|
51
|
+
}, {
|
|
52
|
+
readonly type: "function";
|
|
53
|
+
readonly name: "totalSupply";
|
|
54
|
+
readonly inputs: readonly [];
|
|
55
|
+
readonly outputs: readonly [{
|
|
56
|
+
readonly name: "";
|
|
57
|
+
readonly type: "uint256";
|
|
58
|
+
readonly internalType: "uint256";
|
|
59
|
+
}];
|
|
60
|
+
readonly stateMutability: "view";
|
|
61
|
+
}, {
|
|
62
|
+
readonly type: "function";
|
|
63
|
+
readonly name: "transfer";
|
|
64
|
+
readonly inputs: readonly [{
|
|
65
|
+
readonly name: "to";
|
|
66
|
+
readonly type: "address";
|
|
67
|
+
readonly internalType: "address";
|
|
68
|
+
}, {
|
|
69
|
+
readonly name: "value";
|
|
70
|
+
readonly type: "uint256";
|
|
71
|
+
readonly internalType: "uint256";
|
|
72
|
+
}];
|
|
73
|
+
readonly outputs: readonly [{
|
|
74
|
+
readonly name: "";
|
|
75
|
+
readonly type: "bool";
|
|
76
|
+
readonly internalType: "bool";
|
|
77
|
+
}];
|
|
78
|
+
readonly stateMutability: "nonpayable";
|
|
79
|
+
}, {
|
|
80
|
+
readonly type: "function";
|
|
81
|
+
readonly name: "transferFrom";
|
|
82
|
+
readonly inputs: readonly [{
|
|
83
|
+
readonly name: "from";
|
|
84
|
+
readonly type: "address";
|
|
85
|
+
readonly internalType: "address";
|
|
86
|
+
}, {
|
|
87
|
+
readonly name: "to";
|
|
88
|
+
readonly type: "address";
|
|
89
|
+
readonly internalType: "address";
|
|
90
|
+
}, {
|
|
91
|
+
readonly name: "value";
|
|
92
|
+
readonly type: "uint256";
|
|
93
|
+
readonly internalType: "uint256";
|
|
94
|
+
}];
|
|
95
|
+
readonly outputs: readonly [{
|
|
96
|
+
readonly name: "";
|
|
97
|
+
readonly type: "bool";
|
|
98
|
+
readonly internalType: "bool";
|
|
99
|
+
}];
|
|
100
|
+
readonly stateMutability: "nonpayable";
|
|
101
|
+
}, {
|
|
102
|
+
readonly type: "event";
|
|
103
|
+
readonly name: "Approval";
|
|
104
|
+
readonly inputs: readonly [{
|
|
105
|
+
readonly name: "owner";
|
|
106
|
+
readonly type: "address";
|
|
107
|
+
readonly indexed: true;
|
|
108
|
+
readonly internalType: "address";
|
|
109
|
+
}, {
|
|
110
|
+
readonly name: "spender";
|
|
111
|
+
readonly type: "address";
|
|
112
|
+
readonly indexed: true;
|
|
113
|
+
readonly internalType: "address";
|
|
114
|
+
}, {
|
|
115
|
+
readonly name: "value";
|
|
116
|
+
readonly type: "uint256";
|
|
117
|
+
readonly indexed: false;
|
|
118
|
+
readonly internalType: "uint256";
|
|
119
|
+
}];
|
|
120
|
+
readonly anonymous: false;
|
|
121
|
+
}, {
|
|
122
|
+
readonly type: "event";
|
|
123
|
+
readonly name: "Transfer";
|
|
124
|
+
readonly inputs: readonly [{
|
|
125
|
+
readonly name: "from";
|
|
126
|
+
readonly type: "address";
|
|
127
|
+
readonly indexed: true;
|
|
128
|
+
readonly internalType: "address";
|
|
129
|
+
}, {
|
|
130
|
+
readonly name: "to";
|
|
131
|
+
readonly type: "address";
|
|
132
|
+
readonly indexed: true;
|
|
133
|
+
readonly internalType: "address";
|
|
134
|
+
}, {
|
|
135
|
+
readonly name: "value";
|
|
136
|
+
readonly type: "uint256";
|
|
137
|
+
readonly indexed: false;
|
|
138
|
+
readonly internalType: "uint256";
|
|
139
|
+
}];
|
|
140
|
+
readonly anonymous: false;
|
|
141
|
+
}];
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.erc20Abi = void 0;
|
|
4
|
+
exports.erc20Abi = [
|
|
5
|
+
{
|
|
6
|
+
type: 'function',
|
|
7
|
+
name: 'allowance',
|
|
8
|
+
inputs: [
|
|
9
|
+
{
|
|
10
|
+
name: 'owner',
|
|
11
|
+
type: 'address',
|
|
12
|
+
internalType: 'address',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'spender',
|
|
16
|
+
type: 'address',
|
|
17
|
+
internalType: 'address',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
outputs: [
|
|
21
|
+
{
|
|
22
|
+
name: '',
|
|
23
|
+
type: 'uint256',
|
|
24
|
+
internalType: 'uint256',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
stateMutability: 'view',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: 'function',
|
|
31
|
+
name: 'approve',
|
|
32
|
+
inputs: [
|
|
33
|
+
{
|
|
34
|
+
name: 'spender',
|
|
35
|
+
type: 'address',
|
|
36
|
+
internalType: 'address',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'value',
|
|
40
|
+
type: 'uint256',
|
|
41
|
+
internalType: 'uint256',
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
outputs: [
|
|
45
|
+
{
|
|
46
|
+
name: '',
|
|
47
|
+
type: 'bool',
|
|
48
|
+
internalType: 'bool',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
stateMutability: 'nonpayable',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: 'function',
|
|
55
|
+
name: 'balanceOf',
|
|
56
|
+
inputs: [
|
|
57
|
+
{
|
|
58
|
+
name: 'account',
|
|
59
|
+
type: 'address',
|
|
60
|
+
internalType: 'address',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
outputs: [
|
|
64
|
+
{
|
|
65
|
+
name: '',
|
|
66
|
+
type: 'uint256',
|
|
67
|
+
internalType: 'uint256',
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
stateMutability: 'view',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: 'function',
|
|
74
|
+
name: 'totalSupply',
|
|
75
|
+
inputs: [],
|
|
76
|
+
outputs: [
|
|
77
|
+
{
|
|
78
|
+
name: '',
|
|
79
|
+
type: 'uint256',
|
|
80
|
+
internalType: 'uint256',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
stateMutability: 'view',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: 'function',
|
|
87
|
+
name: 'transfer',
|
|
88
|
+
inputs: [
|
|
89
|
+
{
|
|
90
|
+
name: 'to',
|
|
91
|
+
type: 'address',
|
|
92
|
+
internalType: 'address',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'value',
|
|
96
|
+
type: 'uint256',
|
|
97
|
+
internalType: 'uint256',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
outputs: [
|
|
101
|
+
{
|
|
102
|
+
name: '',
|
|
103
|
+
type: 'bool',
|
|
104
|
+
internalType: 'bool',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
stateMutability: 'nonpayable',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
type: 'function',
|
|
111
|
+
name: 'transferFrom',
|
|
112
|
+
inputs: [
|
|
113
|
+
{
|
|
114
|
+
name: 'from',
|
|
115
|
+
type: 'address',
|
|
116
|
+
internalType: 'address',
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: 'to',
|
|
120
|
+
type: 'address',
|
|
121
|
+
internalType: 'address',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'value',
|
|
125
|
+
type: 'uint256',
|
|
126
|
+
internalType: 'uint256',
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
outputs: [
|
|
130
|
+
{
|
|
131
|
+
name: '',
|
|
132
|
+
type: 'bool',
|
|
133
|
+
internalType: 'bool',
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
stateMutability: 'nonpayable',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
type: 'event',
|
|
140
|
+
name: 'Approval',
|
|
141
|
+
inputs: [
|
|
142
|
+
{
|
|
143
|
+
name: 'owner',
|
|
144
|
+
type: 'address',
|
|
145
|
+
indexed: true,
|
|
146
|
+
internalType: 'address',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: 'spender',
|
|
150
|
+
type: 'address',
|
|
151
|
+
indexed: true,
|
|
152
|
+
internalType: 'address',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: 'value',
|
|
156
|
+
type: 'uint256',
|
|
157
|
+
indexed: false,
|
|
158
|
+
internalType: 'uint256',
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
anonymous: false,
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
type: 'event',
|
|
165
|
+
name: 'Transfer',
|
|
166
|
+
inputs: [
|
|
167
|
+
{
|
|
168
|
+
name: 'from',
|
|
169
|
+
type: 'address',
|
|
170
|
+
indexed: true,
|
|
171
|
+
internalType: 'address',
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: 'to',
|
|
175
|
+
type: 'address',
|
|
176
|
+
indexed: true,
|
|
177
|
+
internalType: 'address',
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: 'value',
|
|
181
|
+
type: 'uint256',
|
|
182
|
+
indexed: false,
|
|
183
|
+
internalType: 'uint256',
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
anonymous: false,
|
|
187
|
+
},
|
|
188
|
+
];
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Account } from 'viem';
|
|
1
2
|
import type { FetchFn } from './rpc';
|
|
2
|
-
import { EvmSigner } from './signing';
|
|
3
3
|
export type AuthTokens = {
|
|
4
4
|
accessToken: string;
|
|
5
5
|
refreshToken: string;
|
|
@@ -47,7 +47,7 @@ export declare class AuthSession {
|
|
|
47
47
|
private loginPromise?;
|
|
48
48
|
constructor(options: {
|
|
49
49
|
authUrl: string;
|
|
50
|
-
signer:
|
|
50
|
+
signer: Account;
|
|
51
51
|
refreshMarginSecs?: number;
|
|
52
52
|
fetchFn?: FetchFn;
|
|
53
53
|
});
|
package/dist/auth.js
CHANGED
|
@@ -53,6 +53,8 @@ function buildSiweMessage(input) {
|
|
|
53
53
|
return `${input.domain} wants you to sign in with your Ethereum account:\n${input.address}\n\n${input.statement}\n\nURI: ${input.uri}\nVersion: 1\nChain ID: ${chainId}\nNonce: ${input.nonce}\nIssued At: ${input.issuedAt}\nExpiration Time: ${input.expiration}`;
|
|
54
54
|
}
|
|
55
55
|
class AuthClient {
|
|
56
|
+
baseUrl;
|
|
57
|
+
fetchFn;
|
|
56
58
|
constructor(endpoint, fetchFn = fetch) {
|
|
57
59
|
try {
|
|
58
60
|
const validated = (0, utils_1.validateUrl)(endpoint);
|
|
@@ -147,6 +149,12 @@ class AuthClient {
|
|
|
147
149
|
}
|
|
148
150
|
exports.AuthClient = AuthClient;
|
|
149
151
|
class AuthSession {
|
|
152
|
+
authClient;
|
|
153
|
+
signer;
|
|
154
|
+
refreshMarginSecs;
|
|
155
|
+
tokens;
|
|
156
|
+
inFlight;
|
|
157
|
+
loginPromise;
|
|
150
158
|
constructor(options) {
|
|
151
159
|
if (!options.authUrl) {
|
|
152
160
|
throw new errors_1.AuthMissingConfigError('missing auth_url');
|
|
@@ -223,6 +231,9 @@ class AuthSession {
|
|
|
223
231
|
issuedAt: nonce.siwe.issuedAt,
|
|
224
232
|
expiration: nonce.siwe.expiration,
|
|
225
233
|
});
|
|
234
|
+
if (!this.signer.signMessage) {
|
|
235
|
+
throw new errors_1.SigningError('signMessage is not supported for this account');
|
|
236
|
+
}
|
|
226
237
|
const signature = await this.signer.signMessage({ message });
|
|
227
238
|
const tokens = await this.authClient.verify(address, message, signature);
|
|
228
239
|
this.cacheTokens(tokens);
|
package/dist/bls.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.signatureToWords = signatureToWords;
|
|
4
|
-
const
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
5
|
const errors_1 = require("./errors");
|
|
6
6
|
function splitFp(value) {
|
|
7
7
|
const be48 = value.toString(16).padStart(96, '0');
|
|
8
|
-
const bytes = (0,
|
|
8
|
+
const bytes = (0, viem_1.toBytes)(`0x${be48}`);
|
|
9
9
|
const hi = new Uint8Array(32);
|
|
10
10
|
hi.set(bytes.slice(0, 16), 16);
|
|
11
11
|
const lo = bytes.slice(16);
|
|
@@ -38,7 +38,7 @@ function signatureToWords(signatureHex) {
|
|
|
38
38
|
throw new errors_1.VerificationError('invalid BLS field element');
|
|
39
39
|
};
|
|
40
40
|
try {
|
|
41
|
-
const sigBytes = (0,
|
|
41
|
+
const sigBytes = (0, viem_1.toBytes)(signatureHex);
|
|
42
42
|
const point = curves.bls12_381.G2.ProjectivePoint.fromHex(sigBytes);
|
|
43
43
|
const affine = point.toAffine();
|
|
44
44
|
const [x0, x1] = affine.x.c;
|
package/dist/client.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export declare class Client {
|
|
|
16
16
|
private constructor();
|
|
17
17
|
static new(cfg: Config): Promise<Client>;
|
|
18
18
|
private static buildGateway;
|
|
19
|
-
private static validateChainId;
|
|
20
19
|
aclose(): Promise<void>;
|
|
21
20
|
login(): Promise<AuthTokens>;
|
|
22
21
|
}
|
|
@@ -24,27 +23,26 @@ export declare class UserClient {
|
|
|
24
23
|
private client;
|
|
25
24
|
constructor(client: Client);
|
|
26
25
|
get guaranteeDomain(): string;
|
|
27
|
-
approveErc20(token: string, amount: number | bigint | string): Promise<
|
|
28
|
-
deposit(amount: number | bigint | string, erc20Token?: string): Promise<
|
|
26
|
+
approveErc20(token: string, amount: number | bigint | string): Promise<import("viem").TransactionReceipt>;
|
|
27
|
+
deposit(amount: number | bigint | string, erc20Token?: string): Promise<import("viem").TransactionReceipt>;
|
|
29
28
|
getUser(): Promise<UserInfo[]>;
|
|
30
29
|
getTabPaymentStatus(tabId: number | bigint): Promise<TabPaymentStatus>;
|
|
31
30
|
signPayment(claims: PaymentGuaranteeRequestClaims, scheme?: SigningScheme): Promise<PaymentSignature>;
|
|
32
|
-
payTab(tabId: number | bigint, reqId: number | bigint, amount: number | bigint | string, recipientAddress: string, erc20Token?: string): Promise<
|
|
33
|
-
requestWithdrawal(amount: number | bigint | string, erc20Token?: string): Promise<
|
|
34
|
-
cancelWithdrawal(erc20Token?: string): Promise<
|
|
35
|
-
finalizeWithdrawal(erc20Token?: string): Promise<
|
|
31
|
+
payTab(tabId: number | bigint, reqId: number | bigint, amount: number | bigint | string, recipientAddress: string, erc20Token?: string): Promise<import("viem").TransactionReceipt>;
|
|
32
|
+
requestWithdrawal(amount: number | bigint | string, erc20Token?: string): Promise<import("viem").TransactionReceipt>;
|
|
33
|
+
cancelWithdrawal(erc20Token?: string): Promise<import("viem").TransactionReceipt>;
|
|
34
|
+
finalizeWithdrawal(erc20Token?: string): Promise<import("viem").TransactionReceipt>;
|
|
36
35
|
}
|
|
37
36
|
export declare class RecipientClient {
|
|
38
37
|
private client;
|
|
39
38
|
constructor(client: Client);
|
|
40
39
|
private get recipientAddress();
|
|
41
40
|
get guaranteeDomain(): string;
|
|
42
|
-
private checkSigner;
|
|
43
41
|
createTab(userAddress: string, recipientAddress: string, erc20Token: string | undefined | null, ttl?: number | null): Promise<bigint>;
|
|
44
42
|
getTabPaymentStatus(tabId: number | bigint): Promise<TabPaymentStatus>;
|
|
45
43
|
issuePaymentGuarantee(claims: PaymentGuaranteeRequestClaims, signature: string, scheme: SigningScheme): Promise<BLSCert>;
|
|
46
44
|
verifyPaymentGuarantee(cert: BLSCert): PaymentGuaranteeClaims;
|
|
47
|
-
remunerate(cert: BLSCert): Promise<
|
|
45
|
+
remunerate(cert: BLSCert): Promise<import("viem").TransactionReceipt>;
|
|
48
46
|
listSettledTabs(): Promise<TabInfo[]>;
|
|
49
47
|
listPendingRemunerations(): Promise<PendingRemunerationInfo[]>;
|
|
50
48
|
getTab(tabId: number | bigint): Promise<TabInfo | null>;
|
package/dist/client.js
CHANGED
|
@@ -22,6 +22,14 @@ function tabStatusFromRpc(status) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
class Client {
|
|
25
|
+
rpc;
|
|
26
|
+
params;
|
|
27
|
+
gateway;
|
|
28
|
+
guaranteeDomain;
|
|
29
|
+
user;
|
|
30
|
+
recipient;
|
|
31
|
+
signer;
|
|
32
|
+
authSession;
|
|
25
33
|
constructor(rpc, params, gateway, guaranteeDomain, signer, authSession) {
|
|
26
34
|
this.rpc = rpc;
|
|
27
35
|
this.params = params;
|
|
@@ -35,8 +43,7 @@ class Client {
|
|
|
35
43
|
static async new(cfg) {
|
|
36
44
|
const rpc = new rpc_1.RpcProxy(cfg.rpcUrl, cfg.adminApiKey);
|
|
37
45
|
const params = await rpc.getPublicParams();
|
|
38
|
-
const gateway = Client.buildGateway(cfg, params);
|
|
39
|
-
await Client.validateChainId(gateway, params.chainId);
|
|
46
|
+
const gateway = await Client.buildGateway(cfg, params);
|
|
40
47
|
const guaranteeDomain = await gateway.getGuaranteeDomain();
|
|
41
48
|
const signer = new signing_1.PaymentSigner(cfg.signer);
|
|
42
49
|
const authEnabled = cfg.authUrl !== undefined || cfg.authRefreshMarginSecs !== undefined;
|
|
@@ -55,22 +62,10 @@ class Client {
|
|
|
55
62
|
}
|
|
56
63
|
return new Client(rpc, params, gateway, guaranteeDomain, signer, authSession);
|
|
57
64
|
}
|
|
58
|
-
static buildGateway(cfg, params) {
|
|
65
|
+
static async buildGateway(cfg, params) {
|
|
59
66
|
const ethRpcUrl = cfg.ethereumHttpRpcUrl ?? params.ethereumHttpRpcUrl;
|
|
60
67
|
const contractAddress = cfg.contractAddress ?? params.contractAddress;
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
static async validateChainId(gateway, expectedChainId) {
|
|
64
|
-
try {
|
|
65
|
-
const chainId = await gateway.getChainId();
|
|
66
|
-
if (Number(chainId) !== Number(expectedChainId)) {
|
|
67
|
-
throw new errors_1.ClientInitializationError(`chain id mismatch between core (${expectedChainId}) and provider (${chainId})`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
72
|
-
throw new errors_1.ClientInitializationError(message);
|
|
73
|
-
}
|
|
68
|
+
return contract_1.ContractGateway.create(ethRpcUrl, cfg.signer, contractAddress, params.chainId);
|
|
74
69
|
}
|
|
75
70
|
async aclose() {
|
|
76
71
|
await this.rpc.aclose();
|
|
@@ -84,6 +79,7 @@ class Client {
|
|
|
84
79
|
}
|
|
85
80
|
exports.Client = Client;
|
|
86
81
|
class UserClient {
|
|
82
|
+
client;
|
|
87
83
|
constructor(client) {
|
|
88
84
|
this.client = client;
|
|
89
85
|
}
|
|
@@ -101,8 +97,8 @@ class UserClient {
|
|
|
101
97
|
return assets.map((a) => ({
|
|
102
98
|
asset: a.asset,
|
|
103
99
|
collateral: (0, utils_1.parseU256)(a.collateral),
|
|
104
|
-
withdrawalRequestAmount: (0, utils_1.parseU256)(a.
|
|
105
|
-
withdrawalRequestTimestamp: Number(a.
|
|
100
|
+
withdrawalRequestAmount: (0, utils_1.parseU256)(a.withdrawalRequestAmount),
|
|
101
|
+
withdrawalRequestTimestamp: Number(a.withdrawalRequestTimestamp),
|
|
106
102
|
}));
|
|
107
103
|
}
|
|
108
104
|
async getTabPaymentStatus(tabId) {
|
|
@@ -130,22 +126,17 @@ class UserClient {
|
|
|
130
126
|
}
|
|
131
127
|
exports.UserClient = UserClient;
|
|
132
128
|
class RecipientClient {
|
|
129
|
+
client;
|
|
133
130
|
constructor(client) {
|
|
134
131
|
this.client = client;
|
|
135
132
|
}
|
|
136
133
|
get recipientAddress() {
|
|
137
|
-
return (0, utils_1.normalizeAddress)(this.client.
|
|
134
|
+
return (0, utils_1.normalizeAddress)(this.client.signer.signer.address);
|
|
138
135
|
}
|
|
139
136
|
get guaranteeDomain() {
|
|
140
137
|
return this.client.guaranteeDomain;
|
|
141
138
|
}
|
|
142
|
-
checkSigner(expected) {
|
|
143
|
-
if ((0, utils_1.normalizeAddress)(expected) !== this.recipientAddress) {
|
|
144
|
-
throw new errors_1.VerificationError('signer address does not match recipient address');
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
139
|
async createTab(userAddress, recipientAddress, erc20Token, ttl) {
|
|
148
|
-
this.checkSigner(recipientAddress);
|
|
149
140
|
const body = {
|
|
150
141
|
user_address: (0, utils_1.normalizeAddress)(userAddress),
|
|
151
142
|
recipient_address: (0, utils_1.normalizeAddress)(recipientAddress),
|
|
@@ -163,7 +154,6 @@ class RecipientClient {
|
|
|
163
154
|
return tabStatusFromRpc(status);
|
|
164
155
|
}
|
|
165
156
|
async issuePaymentGuarantee(claims, signature, scheme) {
|
|
166
|
-
this.checkSigner(claims.recipientAddress);
|
|
167
157
|
const payload = {
|
|
168
158
|
claims: {
|
|
169
159
|
version: 'v1',
|
package/dist/config.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Account } from 'viem/accounts';
|
|
2
2
|
export interface Config {
|
|
3
3
|
rpcUrl: string;
|
|
4
|
-
|
|
5
|
-
signer: EvmSigner;
|
|
4
|
+
signer: Account;
|
|
6
5
|
ethereumHttpRpcUrl?: string;
|
|
7
6
|
contractAddress?: string;
|
|
8
7
|
adminApiKey?: string;
|
|
@@ -23,7 +22,7 @@ export declare class ConfigBuilder {
|
|
|
23
22
|
private _authRefreshMarginSecs?;
|
|
24
23
|
rpcUrl(value: string): ConfigBuilder;
|
|
25
24
|
walletPrivateKey(value: string): ConfigBuilder;
|
|
26
|
-
signer(value:
|
|
25
|
+
signer(value: Account): ConfigBuilder;
|
|
27
26
|
ethereumHttpRpcUrl(value: string): ConfigBuilder;
|
|
28
27
|
contractAddress(value: string): ConfigBuilder;
|
|
29
28
|
adminApiKey(value: string): ConfigBuilder;
|
package/dist/config.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConfigBuilder = void 0;
|
|
4
|
+
const accounts_1 = require("viem/accounts");
|
|
4
5
|
const errors_1 = require("./errors");
|
|
5
|
-
const signing_1 = require("./signing");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
7
|
class ConfigBuilder {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
_rpcUrl = 'https://api.4mica.xyz/';
|
|
9
|
+
_walletPrivateKey;
|
|
10
|
+
_signer;
|
|
11
|
+
_ethereumHttpRpcUrl;
|
|
12
|
+
_contractAddress;
|
|
13
|
+
_adminApiKey;
|
|
14
|
+
_bearerToken;
|
|
15
|
+
_authEnabled = false;
|
|
16
|
+
_authUrl;
|
|
17
|
+
_authRefreshMarginSecs;
|
|
12
18
|
rpcUrl(value) {
|
|
13
19
|
this._rpcUrl = value;
|
|
14
20
|
return this;
|
|
@@ -87,7 +93,7 @@ class ConfigBuilder {
|
|
|
87
93
|
const walletPrivateKey = this._walletPrivateKey
|
|
88
94
|
? (0, utils_1.normalizePrivateKey)(this._walletPrivateKey)
|
|
89
95
|
: undefined;
|
|
90
|
-
const signer = this._signer ?? (0,
|
|
96
|
+
const signer = this._signer ?? (0, accounts_1.privateKeyToAccount)(walletPrivateKey);
|
|
91
97
|
const ethereumHttpRpcUrl = this._ethereumHttpRpcUrl
|
|
92
98
|
? (0, utils_1.validateUrl)(this._ethereumHttpRpcUrl)
|
|
93
99
|
: undefined;
|
|
@@ -102,7 +108,6 @@ class ConfigBuilder {
|
|
|
102
108
|
const authEnabled = this._authEnabled;
|
|
103
109
|
return {
|
|
104
110
|
rpcUrl,
|
|
105
|
-
walletPrivateKey: walletPrivateKey ?? signer.address,
|
|
106
111
|
signer,
|
|
107
112
|
ethereumHttpRpcUrl,
|
|
108
113
|
contractAddress,
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { createPublicClient, createWalletClient, type Hex, type Chain, Account, GetContractReturnType, HttpTransport } from 'viem';
|
|
2
|
+
import { core4micaAbi } from './abi/core4mica';
|
|
3
|
+
type TPublicClient = ReturnType<typeof createPublicClient>;
|
|
4
|
+
type TWalletClient = ReturnType<typeof createWalletClient<HttpTransport, Chain, Account>>;
|
|
5
|
+
type CoreContract = GetContractReturnType<typeof core4micaAbi, {
|
|
6
|
+
public: ReturnType<typeof createPublicClient>;
|
|
7
|
+
wallet: TWalletClient;
|
|
8
|
+
}>;
|
|
3
9
|
export declare class ContractGateway {
|
|
4
|
-
readonly
|
|
5
|
-
readonly
|
|
6
|
-
readonly contract:
|
|
10
|
+
readonly publicClient: TPublicClient;
|
|
11
|
+
readonly walletClient: TWalletClient;
|
|
12
|
+
readonly contract: CoreContract;
|
|
7
13
|
private erc20Cache;
|
|
8
|
-
constructor(
|
|
9
|
-
|
|
14
|
+
private constructor();
|
|
15
|
+
static create(rpcUrl: string, signer: Account, contractAddress: Hex, chainId: number): Promise<ContractGateway>;
|
|
10
16
|
private erc20;
|
|
11
|
-
private send;
|
|
12
17
|
getGuaranteeDomain(): Promise<string>;
|
|
13
|
-
approveErc20(token: string, amount: number | bigint | string): Promise<
|
|
14
|
-
deposit(amount: number | bigint | string, erc20Token?: string): Promise<
|
|
18
|
+
approveErc20(token: string, amount: number | bigint | string): Promise<import("viem").TransactionReceipt>;
|
|
19
|
+
deposit(amount: number | bigint | string, erc20Token?: string): Promise<import("viem").TransactionReceipt>;
|
|
15
20
|
getUserAssets(): Promise<{
|
|
16
|
-
asset: string
|
|
21
|
+
asset: `0x${string}`;
|
|
17
22
|
collateral: bigint;
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
withdrawalRequestTimestamp: bigint;
|
|
24
|
+
withdrawalRequestAmount: bigint;
|
|
20
25
|
}[]>;
|
|
21
26
|
getPaymentStatus(tabId: number | bigint): Promise<{
|
|
22
27
|
paid: bigint;
|
|
23
28
|
remunerated: boolean;
|
|
24
|
-
asset:
|
|
29
|
+
asset: Hex;
|
|
25
30
|
}>;
|
|
26
|
-
payTabEth(tabId: number | bigint, reqId: number | bigint, amount: number | bigint | string, recipient: string): Promise<
|
|
27
|
-
payTabErc20(tabId: number | bigint, amount: number | bigint | string, erc20Token: string, recipient: string): Promise<
|
|
28
|
-
requestWithdrawal(amount: number | bigint | string, erc20Token?: string): Promise<
|
|
29
|
-
cancelWithdrawal(erc20Token?: string): Promise<
|
|
30
|
-
finalizeWithdrawal(erc20Token?: string): Promise<
|
|
31
|
-
remunerate(claimsBlob: Uint8Array, signatureWords: Uint8Array[]): Promise<
|
|
31
|
+
payTabEth(tabId: number | bigint, reqId: number | bigint, amount: number | bigint | string, recipient: string): Promise<import("viem").TransactionReceipt>;
|
|
32
|
+
payTabErc20(tabId: number | bigint, amount: number | bigint | string, erc20Token: string, recipient: string): Promise<import("viem").TransactionReceipt>;
|
|
33
|
+
requestWithdrawal(amount: number | bigint | string, erc20Token?: string): Promise<import("viem").TransactionReceipt>;
|
|
34
|
+
cancelWithdrawal(erc20Token?: string): Promise<import("viem").TransactionReceipt>;
|
|
35
|
+
finalizeWithdrawal(erc20Token?: string): Promise<import("viem").TransactionReceipt>;
|
|
36
|
+
remunerate(claimsBlob: Uint8Array, signatureWords: Uint8Array[]): Promise<import("viem").TransactionReceipt>;
|
|
32
37
|
}
|
|
33
38
|
export {};
|