@4mica/sdk 1.2.16 → 1.3.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.
Files changed (74) hide show
  1. package/README.md +59 -25
  2. package/dist/index.cjs +5513 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +2730 -0
  5. package/dist/{src/abi/core4mica.d.ts → index.d.ts} +1032 -1
  6. package/dist/index.js +5439 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/models-B15ouNYG.d.cts +386 -0
  9. package/dist/models-B15ouNYG.d.ts +386 -0
  10. package/dist/server.cjs +172 -0
  11. package/dist/server.cjs.map +1 -0
  12. package/dist/server.d.cts +119 -0
  13. package/dist/server.d.ts +119 -0
  14. package/dist/server.js +165 -0
  15. package/dist/server.js.map +1 -0
  16. package/package.json +52 -43
  17. package/dist/package.json +0 -80
  18. package/dist/src/abi/core4mica.js +0 -2200
  19. package/dist/src/abi/erc20.d.ts +0 -151
  20. package/dist/src/abi/erc20.js +0 -201
  21. package/dist/src/auth.d.ts +0 -62
  22. package/dist/src/auth.js +0 -218
  23. package/dist/src/bls.d.ts +0 -6
  24. package/dist/src/bls.js +0 -247
  25. package/dist/src/chain.d.ts +0 -2
  26. package/dist/src/chain.js +0 -26
  27. package/dist/src/client/index.d.ts +0 -71
  28. package/dist/src/client/index.js +0 -120
  29. package/dist/src/client/recipient.d.ts +0 -129
  30. package/dist/src/client/recipient.js +0 -257
  31. package/dist/src/client/shared.d.ts +0 -11
  32. package/dist/src/client/shared.js +0 -17
  33. package/dist/src/client/user.d.ts +0 -109
  34. package/dist/src/client/user.js +0 -147
  35. package/dist/src/config.d.ts +0 -103
  36. package/dist/src/config.js +0 -197
  37. package/dist/src/constants.d.ts +0 -4
  38. package/dist/src/constants.js +0 -7
  39. package/dist/src/contract.d.ts +0 -55
  40. package/dist/src/contract.js +0 -312
  41. package/dist/src/debug.d.ts +0 -2
  42. package/dist/src/debug.js +0 -5
  43. package/dist/src/errors.d.ts +0 -58
  44. package/dist/src/errors.js +0 -81
  45. package/dist/src/guarantee.d.ts +0 -25
  46. package/dist/src/guarantee.js +0 -272
  47. package/dist/src/http.d.ts +0 -11
  48. package/dist/src/http.js +0 -57
  49. package/dist/src/index.d.ts +0 -17
  50. package/dist/src/index.js +0 -33
  51. package/dist/src/models.d.ts +0 -259
  52. package/dist/src/models.js +0 -356
  53. package/dist/src/networks.d.ts +0 -40
  54. package/dist/src/networks.js +0 -57
  55. package/dist/src/payment.d.ts +0 -82
  56. package/dist/src/payment.js +0 -67
  57. package/dist/src/rpc.d.ts +0 -38
  58. package/dist/src/rpc.js +0 -161
  59. package/dist/src/serde.d.ts +0 -5
  60. package/dist/src/serde.js +0 -33
  61. package/dist/src/signing.d.ts +0 -170
  62. package/dist/src/signing.js +0 -311
  63. package/dist/src/utils.d.ts +0 -11
  64. package/dist/src/utils.js +0 -90
  65. package/dist/src/validation.d.ts +0 -32
  66. package/dist/src/validation.js +0 -84
  67. package/dist/src/wallet/cdp.d.ts +0 -13
  68. package/dist/src/wallet/cdp.js +0 -78
  69. package/dist/src/wallet/index.d.ts +0 -2
  70. package/dist/src/wallet/index.js +0 -5
  71. package/dist/src/x402/index.d.ts +0 -90
  72. package/dist/src/x402/index.js +0 -243
  73. package/dist/src/x402/models.d.ts +0 -75
  74. package/dist/src/x402/models.js +0 -2
@@ -1,151 +0,0 @@
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: "decimals";
54
- readonly inputs: readonly [];
55
- readonly outputs: readonly [{
56
- readonly name: "";
57
- readonly type: "uint8";
58
- readonly internalType: "uint8";
59
- }];
60
- readonly stateMutability: "view";
61
- }, {
62
- readonly type: "function";
63
- readonly name: "totalSupply";
64
- readonly inputs: readonly [];
65
- readonly outputs: readonly [{
66
- readonly name: "";
67
- readonly type: "uint256";
68
- readonly internalType: "uint256";
69
- }];
70
- readonly stateMutability: "view";
71
- }, {
72
- readonly type: "function";
73
- readonly name: "transfer";
74
- readonly inputs: readonly [{
75
- readonly name: "to";
76
- readonly type: "address";
77
- readonly internalType: "address";
78
- }, {
79
- readonly name: "value";
80
- readonly type: "uint256";
81
- readonly internalType: "uint256";
82
- }];
83
- readonly outputs: readonly [{
84
- readonly name: "";
85
- readonly type: "bool";
86
- readonly internalType: "bool";
87
- }];
88
- readonly stateMutability: "nonpayable";
89
- }, {
90
- readonly type: "function";
91
- readonly name: "transferFrom";
92
- readonly inputs: readonly [{
93
- readonly name: "from";
94
- readonly type: "address";
95
- readonly internalType: "address";
96
- }, {
97
- readonly name: "to";
98
- readonly type: "address";
99
- readonly internalType: "address";
100
- }, {
101
- readonly name: "value";
102
- readonly type: "uint256";
103
- readonly internalType: "uint256";
104
- }];
105
- readonly outputs: readonly [{
106
- readonly name: "";
107
- readonly type: "bool";
108
- readonly internalType: "bool";
109
- }];
110
- readonly stateMutability: "nonpayable";
111
- }, {
112
- readonly type: "event";
113
- readonly name: "Approval";
114
- readonly inputs: readonly [{
115
- readonly name: "owner";
116
- readonly type: "address";
117
- readonly indexed: true;
118
- readonly internalType: "address";
119
- }, {
120
- readonly name: "spender";
121
- readonly type: "address";
122
- readonly indexed: true;
123
- readonly internalType: "address";
124
- }, {
125
- readonly name: "value";
126
- readonly type: "uint256";
127
- readonly indexed: false;
128
- readonly internalType: "uint256";
129
- }];
130
- readonly anonymous: false;
131
- }, {
132
- readonly type: "event";
133
- readonly name: "Transfer";
134
- readonly inputs: readonly [{
135
- readonly name: "from";
136
- readonly type: "address";
137
- readonly indexed: true;
138
- readonly internalType: "address";
139
- }, {
140
- readonly name: "to";
141
- readonly type: "address";
142
- readonly indexed: true;
143
- readonly internalType: "address";
144
- }, {
145
- readonly name: "value";
146
- readonly type: "uint256";
147
- readonly indexed: false;
148
- readonly internalType: "uint256";
149
- }];
150
- readonly anonymous: false;
151
- }];
@@ -1,201 +0,0 @@
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: 'decimals',
75
- inputs: [],
76
- outputs: [
77
- {
78
- name: '',
79
- type: 'uint8',
80
- internalType: 'uint8',
81
- },
82
- ],
83
- stateMutability: 'view',
84
- },
85
- {
86
- type: 'function',
87
- name: 'totalSupply',
88
- inputs: [],
89
- outputs: [
90
- {
91
- name: '',
92
- type: 'uint256',
93
- internalType: 'uint256',
94
- },
95
- ],
96
- stateMutability: 'view',
97
- },
98
- {
99
- type: 'function',
100
- name: 'transfer',
101
- inputs: [
102
- {
103
- name: 'to',
104
- type: 'address',
105
- internalType: 'address',
106
- },
107
- {
108
- name: 'value',
109
- type: 'uint256',
110
- internalType: 'uint256',
111
- },
112
- ],
113
- outputs: [
114
- {
115
- name: '',
116
- type: 'bool',
117
- internalType: 'bool',
118
- },
119
- ],
120
- stateMutability: 'nonpayable',
121
- },
122
- {
123
- type: 'function',
124
- name: 'transferFrom',
125
- inputs: [
126
- {
127
- name: 'from',
128
- type: 'address',
129
- internalType: 'address',
130
- },
131
- {
132
- name: 'to',
133
- type: 'address',
134
- internalType: 'address',
135
- },
136
- {
137
- name: 'value',
138
- type: 'uint256',
139
- internalType: 'uint256',
140
- },
141
- ],
142
- outputs: [
143
- {
144
- name: '',
145
- type: 'bool',
146
- internalType: 'bool',
147
- },
148
- ],
149
- stateMutability: 'nonpayable',
150
- },
151
- {
152
- type: 'event',
153
- name: 'Approval',
154
- inputs: [
155
- {
156
- name: 'owner',
157
- type: 'address',
158
- indexed: true,
159
- internalType: 'address',
160
- },
161
- {
162
- name: 'spender',
163
- type: 'address',
164
- indexed: true,
165
- internalType: 'address',
166
- },
167
- {
168
- name: 'value',
169
- type: 'uint256',
170
- indexed: false,
171
- internalType: 'uint256',
172
- },
173
- ],
174
- anonymous: false,
175
- },
176
- {
177
- type: 'event',
178
- name: 'Transfer',
179
- inputs: [
180
- {
181
- name: 'from',
182
- type: 'address',
183
- indexed: true,
184
- internalType: 'address',
185
- },
186
- {
187
- name: 'to',
188
- type: 'address',
189
- indexed: true,
190
- internalType: 'address',
191
- },
192
- {
193
- name: 'value',
194
- type: 'uint256',
195
- indexed: false,
196
- internalType: 'uint256',
197
- },
198
- ],
199
- anonymous: false,
200
- },
201
- ];
@@ -1,62 +0,0 @@
1
- import { Account } from 'viem';
2
- import type { FetchFn } from './rpc';
3
- export type AuthTokens = {
4
- accessToken: string;
5
- refreshToken: string;
6
- expiresIn: number;
7
- };
8
- export type SiweTemplate = {
9
- domain: string;
10
- uri: string;
11
- chainId: number;
12
- statement: string;
13
- expiration: string;
14
- issuedAt: string;
15
- };
16
- export type AuthNonceResponse = {
17
- nonce: string;
18
- siwe: SiweTemplate;
19
- };
20
- export declare function buildSiweMessage(input: {
21
- domain: string;
22
- address: string;
23
- statement: string;
24
- uri: string;
25
- chainId: number | string;
26
- nonce: string;
27
- issuedAt: string;
28
- expiration: string;
29
- }): string;
30
- export declare class AuthClient {
31
- private baseUrl;
32
- private fetchFn;
33
- constructor(endpoint: string, fetchFn?: FetchFn);
34
- getNonce(address: string): Promise<AuthNonceResponse>;
35
- verify(address: string, message: string, signature: string): Promise<AuthTokens>;
36
- refresh(refreshToken: string): Promise<AuthTokens>;
37
- logout(refreshToken: string): Promise<void>;
38
- private post;
39
- private request;
40
- }
41
- export declare class AuthSession {
42
- private authClient;
43
- private signer;
44
- private refreshMarginSecs;
45
- private tokens?;
46
- private inFlight?;
47
- private loginPromise?;
48
- constructor(options: {
49
- authUrl: string;
50
- signer: Account;
51
- refreshMarginSecs?: number;
52
- fetchFn?: FetchFn;
53
- });
54
- accessToken(): Promise<string>;
55
- login(): Promise<AuthTokens>;
56
- logout(): Promise<void>;
57
- private refreshOrLogin;
58
- private performLogin;
59
- private refreshTokens;
60
- private cacheTokens;
61
- private isExpiringSoon;
62
- }
package/dist/src/auth.js DELETED
@@ -1,218 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthSession = exports.AuthClient = void 0;
4
- exports.buildSiweMessage = buildSiweMessage;
5
- const http_1 = require("./http");
6
- const errors_1 = require("./errors");
7
- const utils_1 = require("./utils");
8
- const serde_1 = require("./serde");
9
- const missingField = (label) => new errors_1.AuthDecodeError(`invalid auth response: missing ${label}`);
10
- const parseTokens = (payload) => {
11
- const accessToken = (0, serde_1.readString)(payload.access_token ?? payload.accessToken, 'access_token', missingField);
12
- const refreshToken = (0, serde_1.readString)(payload.refresh_token ?? payload.refreshToken, 'refresh_token', missingField);
13
- const expiresIn = (0, serde_1.readNumber)(payload.expires_in ?? payload.expiresIn, 'expires_in', missingField);
14
- return { accessToken, refreshToken, expiresIn };
15
- };
16
- const parseSiweTemplate = (payload) => {
17
- const domain = (0, serde_1.readString)(payload.domain, 'siwe.domain', missingField);
18
- const uri = (0, serde_1.readString)(payload.uri, 'siwe.uri', missingField);
19
- const chainId = (0, serde_1.readNumber)(payload.chain_id ?? payload.chainId, 'siwe.chain_id', missingField);
20
- const statement = (0, serde_1.readString)(payload.statement, 'siwe.statement', missingField);
21
- const expiration = (0, serde_1.readString)(payload.expiration, 'siwe.expiration', missingField);
22
- const issuedAt = (0, serde_1.readString)(payload.issued_at ?? payload.issuedAt, 'siwe.issued_at', missingField);
23
- return { domain, uri, chainId, statement, expiration, issuedAt };
24
- };
25
- const parseNonceResponse = (payload) => {
26
- if (!(0, serde_1.isRecord)(payload)) {
27
- throw new errors_1.AuthDecodeError('invalid auth response: nonce payload');
28
- }
29
- const nonce = (0, serde_1.readString)(payload.nonce, 'nonce', missingField);
30
- if (!(0, serde_1.isRecord)(payload.siwe)) {
31
- throw new errors_1.AuthDecodeError('invalid auth response: missing siwe template');
32
- }
33
- return { nonce, siwe: parseSiweTemplate(payload.siwe) };
34
- };
35
- function buildSiweMessage(input) {
36
- const chainId = String(input.chainId);
37
- 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}`;
38
- }
39
- class AuthClient {
40
- baseUrl;
41
- fetchFn;
42
- constructor(endpoint, fetchFn = fetch) {
43
- try {
44
- const validated = (0, utils_1.validateUrl)(endpoint);
45
- this.baseUrl = (0, http_1.normalizeBaseUrl)(validated);
46
- }
47
- catch (err) {
48
- if (err instanceof utils_1.ValidationError) {
49
- throw new errors_1.AuthUrlError(err.message);
50
- }
51
- throw err;
52
- }
53
- this.fetchFn = fetchFn;
54
- }
55
- async getNonce(address) {
56
- const payload = await this.post('/auth/nonce', { address });
57
- return parseNonceResponse(payload);
58
- }
59
- async verify(address, message, signature) {
60
- const payload = await this.post('/auth/verify', { address, message, signature });
61
- if (!(0, serde_1.isRecord)(payload)) {
62
- throw new errors_1.AuthDecodeError('invalid auth response: verify payload');
63
- }
64
- return parseTokens(payload);
65
- }
66
- async refresh(refreshToken) {
67
- const payload = await this.post('/auth/refresh', { refresh_token: refreshToken });
68
- if (!(0, serde_1.isRecord)(payload)) {
69
- throw new errors_1.AuthDecodeError('invalid auth response: refresh payload');
70
- }
71
- return parseTokens(payload);
72
- }
73
- async logout(refreshToken) {
74
- await this.post('/auth/logout', { refresh_token: refreshToken });
75
- }
76
- async post(path, body) {
77
- return this.request(path, {
78
- method: 'POST',
79
- headers: { 'content-type': 'application/json' },
80
- body: JSON.stringify(body),
81
- });
82
- }
83
- async request(path, init) {
84
- try {
85
- return await (0, http_1.requestJson)(this.fetchFn, `${this.baseUrl}${path}`, init, {
86
- decodeError: (message) => new errors_1.AuthDecodeError(message),
87
- httpError: (message, response, body) => new errors_1.AuthApiError(message, {
88
- status: response.status,
89
- body,
90
- }),
91
- allowEmptyOk: true,
92
- });
93
- }
94
- catch (err) {
95
- if (err instanceof errors_1.AuthError) {
96
- throw err;
97
- }
98
- throw new errors_1.AuthTransportError(`auth request failed: ${String(err)}`);
99
- }
100
- }
101
- }
102
- exports.AuthClient = AuthClient;
103
- class AuthSession {
104
- authClient;
105
- signer;
106
- refreshMarginSecs;
107
- tokens;
108
- inFlight;
109
- loginPromise;
110
- constructor(options) {
111
- if (!options.authUrl) {
112
- throw new errors_1.AuthMissingConfigError('missing auth_url');
113
- }
114
- this.authClient = new AuthClient(options.authUrl, options.fetchFn);
115
- this.signer = options.signer;
116
- const margin = options.refreshMarginSecs ?? 60;
117
- if (!Number.isFinite(margin) || margin < 0) {
118
- throw new errors_1.AuthConfigError('refresh margin must be non-negative');
119
- }
120
- this.refreshMarginSecs = margin;
121
- }
122
- async accessToken() {
123
- if (this.tokens && !this.isExpiringSoon()) {
124
- return this.tokens.accessToken;
125
- }
126
- if (this.inFlight) {
127
- return this.inFlight;
128
- }
129
- this.inFlight = this.refreshOrLogin();
130
- try {
131
- return await this.inFlight;
132
- }
133
- finally {
134
- this.inFlight = undefined;
135
- }
136
- }
137
- async login() {
138
- if (this.loginPromise) {
139
- return this.loginPromise;
140
- }
141
- this.loginPromise = this.performLogin();
142
- try {
143
- return await this.loginPromise;
144
- }
145
- finally {
146
- this.loginPromise = undefined;
147
- }
148
- }
149
- async logout() {
150
- if (!this.tokens?.refreshToken) {
151
- return;
152
- }
153
- await this.authClient.logout(this.tokens.refreshToken);
154
- this.tokens = undefined;
155
- }
156
- async refreshOrLogin() {
157
- if (this.tokens?.refreshToken) {
158
- try {
159
- const tokens = await this.refreshTokens();
160
- return tokens.accessToken;
161
- }
162
- catch (err) {
163
- if (err instanceof errors_1.AuthApiError && err.status === 401) {
164
- const tokens = await this.login();
165
- return tokens.accessToken;
166
- }
167
- throw err;
168
- }
169
- }
170
- const tokens = await this.login();
171
- return tokens.accessToken;
172
- }
173
- async performLogin() {
174
- const address = this.signer.address;
175
- const nonce = await this.authClient.getNonce(address);
176
- const message = buildSiweMessage({
177
- domain: nonce.siwe.domain,
178
- address,
179
- statement: nonce.siwe.statement,
180
- uri: nonce.siwe.uri,
181
- chainId: nonce.siwe.chainId,
182
- nonce: nonce.nonce,
183
- issuedAt: nonce.siwe.issuedAt,
184
- expiration: nonce.siwe.expiration,
185
- });
186
- if (!this.signer.signMessage) {
187
- throw new errors_1.SigningError('signMessage is not supported for this account');
188
- }
189
- const signature = await this.signer.signMessage({ message });
190
- const tokens = await this.authClient.verify(address, message, signature);
191
- this.cacheTokens(tokens);
192
- return tokens;
193
- }
194
- async refreshTokens() {
195
- if (!this.tokens?.refreshToken) {
196
- throw new errors_1.AuthMissingConfigError('missing refresh token');
197
- }
198
- const tokens = await this.authClient.refresh(this.tokens.refreshToken);
199
- this.cacheTokens(tokens);
200
- return tokens;
201
- }
202
- cacheTokens(tokens) {
203
- const now = Date.now() / 1000;
204
- this.tokens = {
205
- accessToken: tokens.accessToken,
206
- refreshToken: tokens.refreshToken,
207
- expiresAt: now + tokens.expiresIn,
208
- };
209
- }
210
- isExpiringSoon() {
211
- if (!this.tokens) {
212
- return true;
213
- }
214
- const now = Date.now() / 1000;
215
- return now + this.refreshMarginSecs >= this.tokens.expiresAt;
216
- }
217
- }
218
- exports.AuthSession = AuthSession;
package/dist/src/bls.d.ts DELETED
@@ -1,6 +0,0 @@
1
- /**
2
- * Expand a compressed G2 signature into the tuple expected by the contract.
3
- * This mirrors the Python helper and requires the optional `@noble/curves` dependency.
4
- */
5
- export declare function signatureToWords(signatureHex: string): Uint8Array[];
6
- export declare function signatureToWordsAsync(signatureHex: string): Promise<Uint8Array[]>;