@4mica/sdk 0.5.0 → 0.5.2

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/src/errors.ts DELETED
@@ -1,40 +0,0 @@
1
- export class FourMicaError extends Error {
2
- constructor(message: string) {
3
- super(message);
4
- this.name = this.constructor.name;
5
- }
6
- }
7
-
8
- export class ConfigError extends FourMicaError {}
9
- export class RpcError extends FourMicaError {
10
- readonly status?: number;
11
- readonly body?: unknown;
12
-
13
- constructor(message: string, options?: { status?: number; body?: unknown }) {
14
- super(message);
15
- this.status = options?.status;
16
- this.body = options?.body;
17
- }
18
- }
19
- export class ClientInitializationError extends FourMicaError {}
20
- export class SigningError extends FourMicaError {}
21
- export class ContractError extends FourMicaError {}
22
- export class VerificationError extends FourMicaError {}
23
- export class X402Error extends FourMicaError {}
24
-
25
- export class AuthError extends FourMicaError {}
26
- export class AuthUrlError extends AuthError {}
27
- export class AuthTransportError extends AuthError {}
28
- export class AuthDecodeError extends AuthError {}
29
- export class AuthApiError extends AuthError {
30
- readonly status?: number;
31
- readonly body?: unknown;
32
-
33
- constructor(message: string, options?: { status?: number; body?: unknown }) {
34
- super(message);
35
- this.status = options?.status;
36
- this.body = options?.body;
37
- }
38
- }
39
- export class AuthConfigError extends AuthError {}
40
- export class AuthMissingConfigError extends AuthConfigError {}
package/src/guarantee.ts DELETED
@@ -1,96 +0,0 @@
1
- import { AbiCoder, getBytes } from 'ethers';
2
- import { VerificationError } from './errors';
3
- import { PaymentGuaranteeClaims } from './models';
4
- import { parseU256 } from './utils';
5
-
6
- const CLAIM_TYPES = [
7
- 'bytes32',
8
- 'uint256',
9
- 'uint256',
10
- 'address',
11
- 'address',
12
- 'uint256',
13
- 'uint256',
14
- 'address',
15
- 'uint64',
16
- 'uint64',
17
- ];
18
-
19
- const coder = AbiCoder.defaultAbiCoder();
20
-
21
- function ensureDomainBytes(domain: string | Uint8Array): Uint8Array {
22
- const bytes = typeof domain === 'string' ? getBytes(domain) : domain;
23
- if (bytes.length !== 32) {
24
- throw new VerificationError('domain separator must be 32 bytes');
25
- }
26
- return bytes;
27
- }
28
-
29
- export function encodeGuaranteeClaims(claims: PaymentGuaranteeClaims): string {
30
- if (claims.version !== 1) {
31
- throw new VerificationError(`unsupported guarantee claims version: ${claims.version}`);
32
- }
33
-
34
- const domain = ensureDomainBytes(claims.domain);
35
- const encoded = coder.encode(CLAIM_TYPES, [
36
- domain,
37
- parseU256(claims.tabId),
38
- parseU256(claims.reqId),
39
- claims.userAddress,
40
- claims.recipientAddress,
41
- parseU256(claims.amount),
42
- parseU256(claims.totalAmount),
43
- claims.assetAddress,
44
- BigInt(claims.timestamp),
45
- BigInt(claims.version),
46
- ]);
47
- return coder.encode(['uint64', 'bytes'], [BigInt(claims.version), encoded]);
48
- }
49
-
50
- export function decodeGuaranteeClaims(data: string | Uint8Array): PaymentGuaranteeClaims {
51
- const rawBytes = typeof data === 'string' ? getBytes(data) : data;
52
- const [version, encoded] = coder.decode(['uint64', 'bytes'], rawBytes) as unknown as [
53
- bigint,
54
- string,
55
- ];
56
- if (version !== 1n) {
57
- throw new VerificationError(`unsupported guarantee claims version: ${version}`);
58
- }
59
-
60
- const [
61
- domain,
62
- tabId,
63
- reqId,
64
- user,
65
- recipient,
66
- amount,
67
- totalAmount,
68
- asset,
69
- timestamp,
70
- claimsVersion,
71
- ] = coder.decode(CLAIM_TYPES, encoded) as unknown as [
72
- string,
73
- bigint,
74
- bigint,
75
- string,
76
- string,
77
- bigint,
78
- bigint,
79
- string,
80
- bigint,
81
- bigint,
82
- ];
83
-
84
- return {
85
- domain: getBytes(domain),
86
- userAddress: user,
87
- recipientAddress: recipient,
88
- tabId: parseU256(tabId),
89
- reqId: parseU256(reqId),
90
- amount: parseU256(amount),
91
- totalAmount: parseU256(totalAmount),
92
- assetAddress: asset,
93
- timestamp: Number(timestamp),
94
- version: Number(claimsVersion),
95
- };
96
- }
package/src/index.ts DELETED
@@ -1,12 +0,0 @@
1
- export * from './errors';
2
- export * from './config';
3
- export * from './utils';
4
- export * from './models';
5
- export * from './signing';
6
- export * from './rpc';
7
- export * from './auth';
8
- export * from './contract';
9
- export * from './guarantee';
10
- export * from './bls';
11
- export * from './x402/index';
12
- export * from './client';
package/src/models.ts DELETED
@@ -1,309 +0,0 @@
1
- import { normalizeAddress, parseU256 } from './utils';
2
-
3
- export enum SigningScheme {
4
- EIP712 = 'eip712',
5
- EIP191 = 'eip191',
6
- }
7
-
8
- export const ADMIN_API_KEY_HEADER = 'x-api-key';
9
- export const ADMIN_API_KEY_PREFIX = 'ak_';
10
- export const ADMIN_SCOPE_SUSPEND_USERS = 'user_suspension:write';
11
- export const ADMIN_SCOPE_MANAGE_KEYS = 'admin_api_keys:manage';
12
-
13
- export interface PaymentSignature {
14
- signature: string;
15
- scheme: SigningScheme;
16
- }
17
-
18
- export class PaymentGuaranteeRequestClaims {
19
- userAddress: string;
20
- recipientAddress: string;
21
- tabId: bigint;
22
- reqId: bigint;
23
- amount: bigint;
24
- timestamp: number;
25
- assetAddress: string;
26
-
27
- constructor(init: {
28
- userAddress: string;
29
- recipientAddress: string;
30
- tabId: bigint;
31
- reqId?: bigint;
32
- amount: bigint;
33
- timestamp: number;
34
- assetAddress: string;
35
- }) {
36
- this.userAddress = init.userAddress;
37
- this.recipientAddress = init.recipientAddress;
38
- this.tabId = init.tabId;
39
- this.reqId = init.reqId ?? 0n;
40
- this.amount = init.amount;
41
- this.timestamp = init.timestamp;
42
- this.assetAddress = init.assetAddress;
43
- }
44
-
45
- static new(
46
- userAddress: string,
47
- recipientAddress: string,
48
- tabId: number | bigint | string,
49
- amount: number | bigint | string,
50
- timestamp: number,
51
- erc20Token?: string | null,
52
- reqId?: number | bigint | string
53
- ): PaymentGuaranteeRequestClaims {
54
- const asset = erc20Token ?? '0x0000000000000000000000000000000000000000';
55
- return new PaymentGuaranteeRequestClaims({
56
- userAddress: normalizeAddress(userAddress),
57
- recipientAddress: normalizeAddress(recipientAddress),
58
- tabId: parseU256(tabId),
59
- reqId: reqId !== undefined ? parseU256(reqId) : 0n,
60
- amount: parseU256(amount),
61
- timestamp: Number(timestamp),
62
- assetAddress: normalizeAddress(asset),
63
- });
64
- }
65
- }
66
-
67
- export interface PaymentGuaranteeClaims {
68
- domain: Uint8Array;
69
- userAddress: string;
70
- recipientAddress: string;
71
- tabId: bigint;
72
- reqId: bigint;
73
- amount: bigint;
74
- totalAmount: bigint;
75
- assetAddress: string;
76
- timestamp: number;
77
- version: number;
78
- }
79
-
80
- export interface BLSCert {
81
- claims: string;
82
- signature: string;
83
- }
84
-
85
- export interface TabPaymentStatus {
86
- paid: bigint;
87
- remunerated: boolean;
88
- asset: string;
89
- }
90
-
91
- export interface UserInfo {
92
- asset: string;
93
- collateral: bigint;
94
- withdrawalRequestAmount: bigint;
95
- withdrawalRequestTimestamp: number;
96
- }
97
-
98
- export class UserSuspensionStatus {
99
- constructor(
100
- public userAddress: string,
101
- public suspended: boolean,
102
- public updatedAt: number
103
- ) {}
104
-
105
- static fromRpc(raw: Record<string, unknown>): UserSuspensionStatus {
106
- return new UserSuspensionStatus(
107
- (getAny(raw, 'user_address', 'userAddress') ?? '') as string,
108
- Boolean(getAny(raw, 'suspended')),
109
- Number(getAny(raw, 'updated_at', 'updatedAt') ?? 0)
110
- );
111
- }
112
- }
113
-
114
- export class AdminApiKeyInfo {
115
- constructor(
116
- public id: string,
117
- public name: string,
118
- public scopes: string[],
119
- public createdAt: number,
120
- public revokedAt?: number | null
121
- ) {}
122
-
123
- static fromRpc(raw: Record<string, unknown>): AdminApiKeyInfo {
124
- const revoked = getAny(raw, 'revoked_at', 'revokedAt');
125
- return new AdminApiKeyInfo(
126
- (getAny(raw, 'id') ?? '') as string,
127
- (getAny(raw, 'name') ?? '') as string,
128
- ((getAny(raw, 'scopes') ?? []) as string[]).map(String),
129
- Number(getAny(raw, 'created_at', 'createdAt') ?? 0),
130
- revoked === undefined || revoked === null ? null : Number(revoked)
131
- );
132
- }
133
- }
134
-
135
- export class AdminApiKeySecret {
136
- constructor(
137
- public id: string,
138
- public name: string,
139
- public scopes: string[],
140
- public createdAt: number,
141
- public apiKey: string
142
- ) {}
143
-
144
- static fromRpc(raw: Record<string, unknown>): AdminApiKeySecret {
145
- return new AdminApiKeySecret(
146
- (getAny(raw, 'id') ?? '') as string,
147
- (getAny(raw, 'name') ?? '') as string,
148
- ((getAny(raw, 'scopes') ?? []) as string[]).map(String),
149
- Number(getAny(raw, 'created_at', 'createdAt') ?? 0),
150
- (getAny(raw, 'api_key', 'apiKey') ?? '') as string
151
- );
152
- }
153
- }
154
-
155
- function getAny<T>(raw: Record<string, unknown>, ...keys: string[]): T | undefined {
156
- for (const key of keys) {
157
- if (key in raw) return raw[key] as T;
158
- }
159
- return undefined;
160
- }
161
-
162
- export class TabInfo {
163
- constructor(
164
- public tabId: bigint,
165
- public userAddress: string,
166
- public recipientAddress: string,
167
- public assetAddress: string,
168
- public startTimestamp: number,
169
- public ttlSeconds: number,
170
- public status: string,
171
- public settlementStatus: string,
172
- public createdAt: number,
173
- public updatedAt: number
174
- ) {}
175
-
176
- static fromRpc(raw: Record<string, unknown>): TabInfo {
177
- return new TabInfo(
178
- parseU256((getAny(raw, 'tab_id', 'tabId') ?? 0) as number | bigint | string),
179
- (getAny(raw, 'user_address', 'userAddress') ?? '') as string,
180
- (getAny(raw, 'recipient_address', 'recipientAddress') ?? '') as string,
181
- (getAny(raw, 'asset_address', 'assetAddress') ?? '') as string,
182
- Number(getAny(raw, 'start_timestamp', 'startTimestamp')),
183
- Number(getAny(raw, 'ttl_seconds', 'ttlSeconds')),
184
- (getAny(raw, 'status') ?? '') as string,
185
- (getAny(raw, 'settlement_status', 'settlementStatus') ?? '') as string,
186
- Number(getAny(raw, 'created_at', 'createdAt')),
187
- Number(getAny(raw, 'updated_at', 'updatedAt'))
188
- );
189
- }
190
- }
191
-
192
- export class GuaranteeInfo {
193
- constructor(
194
- public tabId: bigint,
195
- public reqId: bigint,
196
- public fromAddress: string,
197
- public toAddress: string,
198
- public assetAddress: string,
199
- public amount: bigint,
200
- public timestamp: number,
201
- public certificate?: string | null
202
- ) {}
203
-
204
- static fromRpc(raw: Record<string, unknown>): GuaranteeInfo {
205
- return new GuaranteeInfo(
206
- parseU256((getAny(raw, 'tab_id', 'tabId') ?? 0) as number | bigint | string),
207
- parseU256((getAny(raw, 'req_id', 'reqId') ?? 0) as number | bigint | string),
208
- (getAny(raw, 'from_address', 'fromAddress') ?? '') as string,
209
- (getAny(raw, 'to_address', 'toAddress') ?? '') as string,
210
- (getAny(raw, 'asset_address', 'assetAddress') ?? '') as string,
211
- parseU256((getAny(raw, 'amount') ?? 0) as number | bigint | string),
212
- Number(getAny(raw, 'start_timestamp', 'startTimestamp', 'timestamp') ?? 0),
213
- getAny(raw, 'certificate')
214
- );
215
- }
216
- }
217
-
218
- export class PendingRemunerationInfo {
219
- constructor(
220
- public tab: TabInfo,
221
- public latestGuarantee?: GuaranteeInfo | null
222
- ) {}
223
-
224
- static fromRpc(raw: Record<string, unknown>): PendingRemunerationInfo {
225
- const latest = getAny<Record<string, unknown>>(raw, 'latest_guarantee', 'latestGuarantee');
226
- return new PendingRemunerationInfo(
227
- TabInfo.fromRpc(getAny(raw, 'tab') ?? {}),
228
- latest ? GuaranteeInfo.fromRpc(latest) : null
229
- );
230
- }
231
- }
232
-
233
- export class CollateralEventInfo {
234
- constructor(
235
- public id: string,
236
- public userAddress: string,
237
- public assetAddress: string,
238
- public amount: bigint,
239
- public eventType: string,
240
- public tabId?: bigint | null,
241
- public reqId?: bigint | null,
242
- public txId?: string | null,
243
- public createdAt: number = 0
244
- ) {}
245
-
246
- static fromRpc(raw: Record<string, unknown>): CollateralEventInfo {
247
- const tabId = getAny(raw, 'tab_id', 'tabId');
248
- const reqId = getAny(raw, 'req_id', 'reqId');
249
- return new CollateralEventInfo(
250
- (getAny(raw, 'id') ?? '') as string,
251
- (getAny(raw, 'user_address', 'userAddress') ?? '') as string,
252
- (getAny(raw, 'asset_address', 'assetAddress') ?? '') as string,
253
- parseU256((getAny(raw, 'amount') ?? 0) as number | bigint | string),
254
- (getAny(raw, 'event_type', 'eventType') ?? '') as string,
255
- tabId !== undefined && tabId !== null ? parseU256(tabId as number | bigint | string) : null,
256
- reqId !== undefined && reqId !== null ? parseU256(reqId as number | bigint | string) : null,
257
- getAny(raw, 'tx_id', 'txId'),
258
- Number(getAny(raw, 'created_at', 'createdAt') ?? 0)
259
- );
260
- }
261
- }
262
-
263
- export class AssetBalanceInfo {
264
- constructor(
265
- public userAddress: string,
266
- public assetAddress: string,
267
- public total: bigint,
268
- public locked: bigint,
269
- public version: number,
270
- public updatedAt: number
271
- ) {}
272
-
273
- static fromRpc(raw: Record<string, unknown>): AssetBalanceInfo {
274
- return new AssetBalanceInfo(
275
- (getAny(raw, 'user_address', 'userAddress') ?? '') as string,
276
- (getAny(raw, 'asset_address', 'assetAddress') ?? '') as string,
277
- parseU256((getAny(raw, 'total') ?? 0) as number | bigint | string),
278
- parseU256((getAny(raw, 'locked') ?? 0) as number | bigint | string),
279
- Number(getAny(raw, 'version') ?? 0),
280
- Number(getAny(raw, 'updated_at', 'updatedAt') ?? 0)
281
- );
282
- }
283
- }
284
-
285
- export class RecipientPaymentInfo {
286
- constructor(
287
- public userAddress: string,
288
- public recipientAddress: string,
289
- public txHash: string,
290
- public amount: bigint,
291
- public verified: boolean,
292
- public finalized: boolean,
293
- public failed: boolean,
294
- public createdAt: number
295
- ) {}
296
-
297
- static fromRpc(raw: Record<string, unknown>): RecipientPaymentInfo {
298
- return new RecipientPaymentInfo(
299
- (getAny(raw, 'user_address', 'userAddress') ?? '') as string,
300
- (getAny(raw, 'recipient_address', 'recipientAddress') ?? '') as string,
301
- (getAny(raw, 'tx_hash', 'txHash') ?? '') as string,
302
- parseU256((getAny(raw, 'amount') ?? 0) as number | bigint | string),
303
- Boolean(getAny(raw, 'verified')),
304
- Boolean(getAny(raw, 'finalized')),
305
- Boolean(getAny(raw, 'failed')),
306
- Number(getAny(raw, 'created_at', 'createdAt') ?? 0)
307
- );
308
- }
309
- }
package/src/rpc.ts DELETED
@@ -1,225 +0,0 @@
1
- import {
2
- ADMIN_API_KEY_HEADER,
3
- AdminApiKeyInfo,
4
- AdminApiKeySecret,
5
- UserSuspensionStatus,
6
- } from './models';
7
- import { CorePublicParameters } from './signing';
8
- import { RpcError } from './errors';
9
-
10
- export type FetchFn = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
11
- export type BearerTokenProvider = () => string | Promise<string>;
12
-
13
- function serializeTabId(tabId: number | bigint): string {
14
- return `0x${BigInt(tabId).toString(16)}`;
15
- }
16
-
17
- export class RpcProxy {
18
- private baseUrl: string;
19
- private adminApiKey?: string;
20
- private bearerToken?: string;
21
- private bearerTokenProvider?: BearerTokenProvider;
22
- private fetchFn: FetchFn;
23
-
24
- constructor(endpoint: string, adminApiKey?: string, fetchFn: FetchFn = fetch) {
25
- this.baseUrl = endpoint.endsWith('/') ? endpoint.slice(0, -1) : endpoint;
26
- this.adminApiKey = adminApiKey;
27
- this.fetchFn = fetchFn;
28
- }
29
-
30
- async aclose(): Promise<void> {
31
- // no-op for symmetry with Python SDK
32
- }
33
-
34
- withBearerToken(token: string): RpcProxy {
35
- this.bearerToken = token;
36
- return this;
37
- }
38
-
39
- withTokenProvider(provider: BearerTokenProvider): RpcProxy {
40
- this.bearerTokenProvider = provider;
41
- return this;
42
- }
43
-
44
- private async headers(): Promise<Record<string, string>> {
45
- const headers: Record<string, string> = {};
46
- if (this.adminApiKey) {
47
- headers[ADMIN_API_KEY_HEADER] = this.adminApiKey;
48
- }
49
- const token = await this.resolveBearerToken();
50
- if (token) {
51
- headers['Authorization'] = token;
52
- }
53
- return headers;
54
- }
55
-
56
- private async resolveBearerToken(): Promise<string | undefined> {
57
- let token = this.bearerToken;
58
- if (!token && this.bearerTokenProvider) {
59
- token = await this.bearerTokenProvider();
60
- }
61
- if (!token) {
62
- return undefined;
63
- }
64
- const trimmed = token.trim();
65
- if (/^bearer\s+/i.test(trimmed)) {
66
- return trimmed;
67
- }
68
- return `Bearer ${trimmed}`;
69
- }
70
-
71
- private async decode<T>(response: Response): Promise<T> {
72
- let payload: unknown;
73
- try {
74
- payload = await response.json();
75
- } catch (err) {
76
- if (response.ok) {
77
- throw new RpcError(`invalid JSON response from ${response.url}: ${String(err)}`);
78
- }
79
- payload = await response.text();
80
- }
81
-
82
- if (response.ok) {
83
- return payload as T;
84
- }
85
-
86
- let message = 'unknown error';
87
- if (payload && typeof payload === 'object') {
88
- const record = payload as Record<string, unknown>;
89
- const error = record.error;
90
- const msg = record.message;
91
- message =
92
- (typeof error === 'string' && error) ||
93
- (typeof msg === 'string' && msg) ||
94
- JSON.stringify(record, (_k, v) => v);
95
- } else if (typeof payload === 'string' && payload.trim()) {
96
- message = payload.trim();
97
- }
98
- throw new RpcError(`${response.status}: ${message}`, {
99
- status: response.status,
100
- body: payload,
101
- });
102
- }
103
-
104
- private async get<T>(path: string): Promise<T> {
105
- const resp = await this.fetchFn(`${this.baseUrl}${path}`, {
106
- headers: await this.headers(),
107
- method: 'GET',
108
- });
109
- return this.decode<T>(resp);
110
- }
111
-
112
- private async post<T>(path: string, body: Record<string, unknown>): Promise<T> {
113
- const resp = await this.fetchFn(`${this.baseUrl}${path}`, {
114
- headers: { 'content-type': 'application/json', ...(await this.headers()) },
115
- method: 'POST',
116
- body: JSON.stringify(body),
117
- });
118
- return this.decode<T>(resp);
119
- }
120
-
121
- async getPublicParams(): Promise<CorePublicParameters> {
122
- const data = await this.get<Record<string, unknown>>('/core/public-params');
123
- return CorePublicParameters.fromRpc(data);
124
- }
125
-
126
- async issueGuarantee(body: Record<string, unknown>): Promise<Record<string, unknown>> {
127
- return this.post<Record<string, unknown>>('/core/guarantees', body);
128
- }
129
-
130
- async createPaymentTab(body: Record<string, unknown>): Promise<Record<string, unknown>> {
131
- return this.post<Record<string, unknown>>('/core/payment-tabs', body);
132
- }
133
-
134
- async listSettledTabs(recipientAddress: string): Promise<Record<string, unknown>[]> {
135
- return this.get<Record<string, unknown>[]>(`/core/recipients/${recipientAddress}/settled-tabs`);
136
- }
137
-
138
- async listPendingRemunerations(recipientAddress: string): Promise<Record<string, unknown>[]> {
139
- return this.get<Record<string, unknown>[]>(
140
- `/core/recipients/${recipientAddress}/pending-remunerations`
141
- );
142
- }
143
-
144
- async getTab(tabId: number | bigint): Promise<Record<string, unknown> | null> {
145
- return this.get<Record<string, unknown> | null>(`/core/tabs/${serializeTabId(tabId)}`);
146
- }
147
-
148
- async listRecipientTabs(
149
- recipientAddress: string,
150
- settlementStatuses?: string[]
151
- ): Promise<Record<string, unknown>[]> {
152
- let query = '';
153
- if (settlementStatuses?.length) {
154
- query =
155
- '?' + settlementStatuses.map((s) => `settlement_status=${encodeURIComponent(s)}`).join('&');
156
- }
157
- return this.get<Record<string, unknown>[]>(`/core/recipients/${recipientAddress}/tabs${query}`);
158
- }
159
-
160
- async getTabGuarantees(tabId: number | bigint): Promise<Record<string, unknown>[]> {
161
- return this.get<Record<string, unknown>[]>(`/core/tabs/${serializeTabId(tabId)}/guarantees`);
162
- }
163
-
164
- async getLatestGuarantee(tabId: number | bigint): Promise<Record<string, unknown> | null> {
165
- return this.get<Record<string, unknown> | null>(
166
- `/core/tabs/${serializeTabId(tabId)}/guarantees/latest`
167
- );
168
- }
169
-
170
- async getGuarantee(
171
- tabId: number | bigint,
172
- reqId: number | bigint
173
- ): Promise<Record<string, unknown> | null> {
174
- return this.get<Record<string, unknown> | null>(
175
- `/core/tabs/${serializeTabId(tabId)}/guarantees/${reqId}`
176
- );
177
- }
178
-
179
- async listRecipientPayments(recipientAddress: string): Promise<Record<string, unknown>[]> {
180
- return this.get<Record<string, unknown>[]>(`/core/recipients/${recipientAddress}/payments`);
181
- }
182
-
183
- async getCollateralEventsForTab(tabId: number | bigint): Promise<Record<string, unknown>[]> {
184
- return this.get<Record<string, unknown>[]>(
185
- `/core/tabs/${serializeTabId(tabId)}/collateral-events`
186
- );
187
- }
188
-
189
- async getUserAssetBalance(
190
- userAddress: string,
191
- assetAddress: string
192
- ): Promise<Record<string, unknown> | null> {
193
- return this.get<Record<string, unknown> | null>(
194
- `/core/users/${userAddress}/assets/${assetAddress}`
195
- );
196
- }
197
-
198
- async updateUserSuspension(
199
- userAddress: string,
200
- suspended: boolean
201
- ): Promise<UserSuspensionStatus> {
202
- const data = await this.post<Record<string, unknown>>(`/core/users/${userAddress}/suspension`, {
203
- suspended,
204
- });
205
- return UserSuspensionStatus.fromRpc(data);
206
- }
207
-
208
- async createAdminApiKey(body: Record<string, unknown>): Promise<AdminApiKeySecret> {
209
- const data = await this.post<Record<string, unknown>>('/core/admin/api-keys', body);
210
- return AdminApiKeySecret.fromRpc(data);
211
- }
212
-
213
- async listAdminApiKeys(): Promise<AdminApiKeyInfo[]> {
214
- const data = await this.get<Record<string, unknown>[]>('/core/admin/api-keys');
215
- return data.map((entry) => AdminApiKeyInfo.fromRpc(entry));
216
- }
217
-
218
- async revokeAdminApiKey(keyId: string): Promise<AdminApiKeyInfo> {
219
- const data = await this.post<Record<string, unknown>>(
220
- `/core/admin/api-keys/${keyId}/revoke`,
221
- {}
222
- );
223
- return AdminApiKeyInfo.fromRpc(data);
224
- }
225
- }