@4mica/sdk 1.0.0 → 1.0.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.
Files changed (48) hide show
  1. package/README.md +17 -0
  2. package/dist/contract.d.ts +1 -0
  3. package/dist/contract.js +44 -18
  4. package/package.json +7 -2
  5. package/dist/abi/core4mica.json +0 -1605
  6. package/dist/abi/erc20.json +0 -187
  7. package/dist/client.d.ts +0 -56
  8. package/dist/client.js +0 -258
  9. package/dist/src/abi/core4mica.json +0 -1605
  10. package/dist/src/abi/erc20.json +0 -187
  11. package/dist/src/bls.d.ts +0 -5
  12. package/dist/src/bls.js +0 -45
  13. package/dist/src/client.d.ts +0 -55
  14. package/dist/src/client.js +0 -214
  15. package/dist/src/config.d.ts +0 -21
  16. package/dist/src/config.js +0 -76
  17. package/dist/src/contract.d.ts +0 -33
  18. package/dist/src/contract.js +0 -121
  19. package/dist/src/errors.d.ts +0 -17
  20. package/dist/src/errors.js +0 -31
  21. package/dist/src/guarantee.d.ts +0 -3
  22. package/dist/src/guarantee.js +0 -66
  23. package/dist/src/index.d.ts +0 -11
  24. package/dist/src/index.js +0 -27
  25. package/dist/src/models.d.ts +0 -119
  26. package/dist/src/models.js +0 -132
  27. package/dist/src/rpc.d.ts +0 -30
  28. package/dist/src/rpc.js +0 -122
  29. package/dist/src/signing.d.ts +0 -16
  30. package/dist/src/signing.js +0 -102
  31. package/dist/src/utils.d.ts +0 -8
  32. package/dist/src/utils.js +0 -78
  33. package/dist/src/x402.d.ts +0 -77
  34. package/dist/src/x402.js +0 -214
  35. package/dist/tests/config.test.d.ts +0 -1
  36. package/dist/tests/config.test.js +0 -26
  37. package/dist/tests/guarantee.test.d.ts +0 -1
  38. package/dist/tests/guarantee.test.js +0 -26
  39. package/dist/tests/rpc.test.d.ts +0 -1
  40. package/dist/tests/rpc.test.js +0 -44
  41. package/dist/tests/signing.test.d.ts +0 -1
  42. package/dist/tests/signing.test.js +0 -25
  43. package/dist/tests/utils.test.d.ts +0 -1
  44. package/dist/tests/utils.test.js +0 -25
  45. package/dist/tests/x402.test.d.ts +0 -1
  46. package/dist/tests/x402.test.js +0 -65
  47. package/dist/x402.d.ts +0 -78
  48. package/dist/x402.js +0 -231
@@ -1,121 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ContractGateway = void 0;
7
- const ethers_1 = require("ethers");
8
- const core4mica_json_1 = __importDefault(require("./abi/core4mica.json"));
9
- const erc20_json_1 = __importDefault(require("./abi/erc20.json"));
10
- const errors_1 = require("./errors");
11
- const utils_1 = require("./utils");
12
- class ContractGateway {
13
- constructor(ethRpcUrl, privateKey, contractAddress, chainId, provider, contractFactory) {
14
- this.erc20Cache = new Map();
15
- this.provider = provider ?? new ethers_1.JsonRpcProvider(ethRpcUrl, { chainId: Number(chainId) });
16
- this.wallet = new ethers_1.Wallet(privateKey, this.provider);
17
- const factory = contractFactory ?? ((addr, abi, signer) => new ethers_1.Contract(addr, abi.abi ?? abi, signer));
18
- this.contract = factory(contractAddress, core4mica_json_1.default, this.wallet);
19
- }
20
- async getChainId() {
21
- const network = await this.provider.getNetwork();
22
- return Number(network.chainId);
23
- }
24
- erc20(address) {
25
- const checksum = address;
26
- if (!this.erc20Cache.has(checksum)) {
27
- this.erc20Cache.set(checksum, new ethers_1.Contract(checksum, erc20_json_1.default.abi ?? erc20_json_1.default, this.wallet));
28
- }
29
- return this.erc20Cache.get(checksum);
30
- }
31
- async send(promise) {
32
- try {
33
- const tx = await promise;
34
- if (tx.wait) {
35
- return (await tx.wait());
36
- }
37
- return tx;
38
- }
39
- catch (err) {
40
- throw new errors_1.ContractError(err?.message ?? String(err));
41
- }
42
- }
43
- async getGuaranteeDomain() {
44
- return this.send(this.contract.guaranteeDomainSeparator());
45
- }
46
- async approveErc20(token, amount) {
47
- const erc20 = this.erc20(token);
48
- const target = this.contract.target ?? this.contract.address;
49
- return this.send(erc20.approve(target, (0, utils_1.parseU256)(amount)));
50
- }
51
- async deposit(amount, erc20Token) {
52
- if (erc20Token) {
53
- return this.send(this.contract.depositStablecoin(erc20Token, (0, utils_1.parseU256)(amount)));
54
- }
55
- return this.send(this.contract.deposit({
56
- value: (0, utils_1.parseU256)(amount),
57
- }));
58
- }
59
- async getUserAssets() {
60
- try {
61
- const result = await this.contract.getUserAllAssets(this.wallet.address);
62
- return result.map((asset) => ({
63
- asset: asset[0],
64
- collateral: (0, utils_1.parseU256)(asset[1]),
65
- withdrawal_request_timestamp: (0, utils_1.parseU256)(asset[2]),
66
- withdrawal_request_amount: (0, utils_1.parseU256)(asset[3]),
67
- }));
68
- }
69
- catch (err) {
70
- throw new errors_1.ContractError(err?.message ?? String(err));
71
- }
72
- }
73
- async getPaymentStatus(tabId) {
74
- try {
75
- const [paid, remunerated, asset] = await this.contract.getPaymentStatus((0, utils_1.parseU256)(tabId));
76
- return {
77
- paid: (0, utils_1.parseU256)(paid),
78
- remunerated: Boolean(remunerated),
79
- asset,
80
- };
81
- }
82
- catch (err) {
83
- throw new errors_1.ContractError(err?.message ?? String(err));
84
- }
85
- }
86
- async payTabEth(tabId, reqId, amount, recipient) {
87
- const data = Buffer.from(`tab_id:${(0, ethers_1.toBeHex)((0, utils_1.parseU256)(tabId))};req_id:${(0, ethers_1.toBeHex)((0, utils_1.parseU256)(reqId))}`);
88
- const tx = {
89
- to: recipient,
90
- value: (0, utils_1.parseU256)(amount),
91
- data: (0, ethers_1.hexlify)(data),
92
- };
93
- return this.send(this.wallet.sendTransaction(tx));
94
- }
95
- async payTabErc20(tabId, amount, erc20Token, recipient) {
96
- return this.send(this.contract.payTabInERC20Token((0, utils_1.parseU256)(tabId), erc20Token, (0, utils_1.parseU256)(amount), recipient));
97
- }
98
- async requestWithdrawal(amount, erc20Token) {
99
- if (erc20Token) {
100
- return this.send(this.contract.requestWithdrawal(erc20Token, (0, utils_1.parseU256)(amount)));
101
- }
102
- return this.send(this.contract.requestWithdrawal((0, utils_1.parseU256)(amount)));
103
- }
104
- async cancelWithdrawal(erc20Token) {
105
- if (erc20Token) {
106
- return this.send(this.contract.cancelWithdrawal(erc20Token));
107
- }
108
- return this.send(this.contract.cancelWithdrawal());
109
- }
110
- async finalizeWithdrawal(erc20Token) {
111
- if (erc20Token) {
112
- return this.send(this.contract.finalizeWithdrawal(erc20Token));
113
- }
114
- return this.send(this.contract.finalizeWithdrawal());
115
- }
116
- async remunerate(claimsBlob, signatureWords) {
117
- const sigStruct = signatureWords.map((word) => (0, ethers_1.hexlify)((0, ethers_1.getBytes)(word)));
118
- return this.send(this.contract.remunerate((0, ethers_1.hexlify)(claimsBlob), sigStruct));
119
- }
120
- }
121
- exports.ContractGateway = ContractGateway;
@@ -1,17 +0,0 @@
1
- export declare class FourMicaError extends Error {
2
- constructor(message: string);
3
- }
4
- export declare class ConfigError extends FourMicaError {
5
- }
6
- export declare class RpcError extends FourMicaError {
7
- }
8
- export declare class ClientInitializationError extends FourMicaError {
9
- }
10
- export declare class SigningError extends FourMicaError {
11
- }
12
- export declare class ContractError extends FourMicaError {
13
- }
14
- export declare class VerificationError extends FourMicaError {
15
- }
16
- export declare class X402Error extends FourMicaError {
17
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.X402Error = exports.VerificationError = exports.ContractError = exports.SigningError = exports.ClientInitializationError = exports.RpcError = exports.ConfigError = exports.FourMicaError = void 0;
4
- class FourMicaError extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = this.constructor.name;
8
- }
9
- }
10
- exports.FourMicaError = FourMicaError;
11
- class ConfigError extends FourMicaError {
12
- }
13
- exports.ConfigError = ConfigError;
14
- class RpcError extends FourMicaError {
15
- }
16
- exports.RpcError = RpcError;
17
- class ClientInitializationError extends FourMicaError {
18
- }
19
- exports.ClientInitializationError = ClientInitializationError;
20
- class SigningError extends FourMicaError {
21
- }
22
- exports.SigningError = SigningError;
23
- class ContractError extends FourMicaError {
24
- }
25
- exports.ContractError = ContractError;
26
- class VerificationError extends FourMicaError {
27
- }
28
- exports.VerificationError = VerificationError;
29
- class X402Error extends FourMicaError {
30
- }
31
- exports.X402Error = X402Error;
@@ -1,3 +0,0 @@
1
- import { PaymentGuaranteeClaims } from './models';
2
- export declare function encodeGuaranteeClaims(claims: PaymentGuaranteeClaims): string;
3
- export declare function decodeGuaranteeClaims(data: string | Uint8Array): PaymentGuaranteeClaims;
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeGuaranteeClaims = encodeGuaranteeClaims;
4
- exports.decodeGuaranteeClaims = decodeGuaranteeClaims;
5
- const ethers_1 = require("ethers");
6
- const errors_1 = require("./errors");
7
- const utils_1 = require("./utils");
8
- const CLAIM_TYPES = [
9
- 'bytes32',
10
- 'uint256',
11
- 'uint256',
12
- 'address',
13
- 'address',
14
- 'uint256',
15
- 'uint256',
16
- 'address',
17
- 'uint64',
18
- 'uint64',
19
- ];
20
- const coder = ethers_1.AbiCoder.defaultAbiCoder();
21
- function ensureDomainBytes(domain) {
22
- const bytes = typeof domain === 'string' ? (0, ethers_1.getBytes)(domain) : domain;
23
- if (bytes.length !== 32) {
24
- throw new errors_1.VerificationError('domain separator must be 32 bytes');
25
- }
26
- return bytes;
27
- }
28
- function encodeGuaranteeClaims(claims) {
29
- if (claims.version !== 1) {
30
- throw new errors_1.VerificationError(`unsupported guarantee claims version: ${claims.version}`);
31
- }
32
- const domain = ensureDomainBytes(claims.domain);
33
- const encoded = coder.encode(CLAIM_TYPES, [
34
- domain,
35
- (0, utils_1.parseU256)(claims.tabId),
36
- (0, utils_1.parseU256)(claims.reqId),
37
- claims.userAddress,
38
- claims.recipientAddress,
39
- (0, utils_1.parseU256)(claims.amount),
40
- (0, utils_1.parseU256)(claims.totalAmount),
41
- claims.assetAddress,
42
- BigInt(claims.timestamp),
43
- BigInt(claims.version),
44
- ]);
45
- return coder.encode(['uint64', 'bytes'], [BigInt(claims.version), encoded]);
46
- }
47
- function decodeGuaranteeClaims(data) {
48
- const rawBytes = typeof data === 'string' ? (0, ethers_1.getBytes)(data) : data;
49
- const [version, encoded] = coder.decode(['uint64', 'bytes'], rawBytes);
50
- if (version !== 1n) {
51
- throw new errors_1.VerificationError(`unsupported guarantee claims version: ${version}`);
52
- }
53
- const [domain, tabId, reqId, user, recipient, amount, totalAmount, asset, timestamp, claimsVersion,] = coder.decode(CLAIM_TYPES, encoded);
54
- return {
55
- domain: (0, ethers_1.getBytes)(domain),
56
- userAddress: user,
57
- recipientAddress: recipient,
58
- tabId: (0, utils_1.parseU256)(tabId),
59
- reqId: (0, utils_1.parseU256)(reqId),
60
- amount: (0, utils_1.parseU256)(amount),
61
- totalAmount: (0, utils_1.parseU256)(totalAmount),
62
- assetAddress: asset,
63
- timestamp: Number(timestamp),
64
- version: Number(claimsVersion),
65
- };
66
- }
@@ -1,11 +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 './contract';
8
- export * from './guarantee';
9
- export * from './bls';
10
- export * from './x402';
11
- export * from './client';
package/dist/src/index.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./errors"), exports);
18
- __exportStar(require("./config"), exports);
19
- __exportStar(require("./utils"), exports);
20
- __exportStar(require("./models"), exports);
21
- __exportStar(require("./signing"), exports);
22
- __exportStar(require("./rpc"), exports);
23
- __exportStar(require("./contract"), exports);
24
- __exportStar(require("./guarantee"), exports);
25
- __exportStar(require("./bls"), exports);
26
- __exportStar(require("./x402"), exports);
27
- __exportStar(require("./client"), exports);
@@ -1,119 +0,0 @@
1
- export declare enum SigningScheme {
2
- EIP712 = "eip712",
3
- EIP191 = "eip191"
4
- }
5
- export interface PaymentSignature {
6
- signature: string;
7
- scheme: SigningScheme;
8
- }
9
- export declare class PaymentGuaranteeRequestClaims {
10
- userAddress: string;
11
- recipientAddress: string;
12
- tabId: bigint;
13
- amount: bigint;
14
- timestamp: number;
15
- assetAddress: string;
16
- constructor(init: {
17
- userAddress: string;
18
- recipientAddress: string;
19
- tabId: bigint;
20
- amount: bigint;
21
- timestamp: number;
22
- assetAddress: string;
23
- });
24
- static new(userAddress: string, recipientAddress: string, tabId: number | bigint | string, amount: number | bigint | string, timestamp: number, erc20Token?: string | null): PaymentGuaranteeRequestClaims;
25
- }
26
- export interface PaymentGuaranteeClaims {
27
- domain: Uint8Array;
28
- userAddress: string;
29
- recipientAddress: string;
30
- tabId: bigint;
31
- reqId: bigint;
32
- amount: bigint;
33
- totalAmount: bigint;
34
- assetAddress: string;
35
- timestamp: number;
36
- version: number;
37
- }
38
- export interface BLSCert {
39
- claims: string;
40
- signature: string;
41
- }
42
- export interface TabPaymentStatus {
43
- paid: bigint;
44
- remunerated: boolean;
45
- asset: string;
46
- }
47
- export interface UserInfo {
48
- asset: string;
49
- collateral: bigint;
50
- withdrawalRequestAmount: bigint;
51
- withdrawalRequestTimestamp: number;
52
- }
53
- export declare class TabInfo {
54
- tabId: bigint;
55
- userAddress: string;
56
- recipientAddress: string;
57
- assetAddress: string;
58
- startTimestamp: number;
59
- ttlSeconds: number;
60
- status: string;
61
- settlementStatus: string;
62
- createdAt: number;
63
- updatedAt: number;
64
- constructor(tabId: bigint, userAddress: string, recipientAddress: string, assetAddress: string, startTimestamp: number, ttlSeconds: number, status: string, settlementStatus: string, createdAt: number, updatedAt: number);
65
- static fromRpc(raw: Record<string, any>): TabInfo;
66
- }
67
- export declare class GuaranteeInfo {
68
- tabId: bigint;
69
- reqId: bigint;
70
- fromAddress: string;
71
- toAddress: string;
72
- assetAddress: string;
73
- amount: bigint;
74
- timestamp: number;
75
- certificate?: string | null | undefined;
76
- constructor(tabId: bigint, reqId: bigint, fromAddress: string, toAddress: string, assetAddress: string, amount: bigint, timestamp: number, certificate?: string | null | undefined);
77
- static fromRpc(raw: Record<string, any>): GuaranteeInfo;
78
- }
79
- export declare class PendingRemunerationInfo {
80
- tab: TabInfo;
81
- latestGuarantee?: (GuaranteeInfo | null) | undefined;
82
- constructor(tab: TabInfo, latestGuarantee?: (GuaranteeInfo | null) | undefined);
83
- static fromRpc(raw: Record<string, any>): PendingRemunerationInfo;
84
- }
85
- export declare class CollateralEventInfo {
86
- id: string;
87
- userAddress: string;
88
- assetAddress: string;
89
- amount: bigint;
90
- eventType: string;
91
- tabId?: bigint | null | undefined;
92
- reqId?: bigint | null | undefined;
93
- txId?: string | null | undefined;
94
- createdAt: number;
95
- constructor(id: string, userAddress: string, assetAddress: string, amount: bigint, eventType: string, tabId?: bigint | null | undefined, reqId?: bigint | null | undefined, txId?: string | null | undefined, createdAt?: number);
96
- static fromRpc(raw: Record<string, any>): CollateralEventInfo;
97
- }
98
- export declare class AssetBalanceInfo {
99
- userAddress: string;
100
- assetAddress: string;
101
- total: bigint;
102
- locked: bigint;
103
- version: number;
104
- updatedAt: number;
105
- constructor(userAddress: string, assetAddress: string, total: bigint, locked: bigint, version: number, updatedAt: number);
106
- static fromRpc(raw: Record<string, any>): AssetBalanceInfo;
107
- }
108
- export declare class RecipientPaymentInfo {
109
- userAddress: string;
110
- recipientAddress: string;
111
- txHash: string;
112
- amount: bigint;
113
- verified: boolean;
114
- finalized: boolean;
115
- failed: boolean;
116
- createdAt: number;
117
- constructor(userAddress: string, recipientAddress: string, txHash: string, amount: bigint, verified: boolean, finalized: boolean, failed: boolean, createdAt: number);
118
- static fromRpc(raw: Record<string, any>): RecipientPaymentInfo;
119
- }
@@ -1,132 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RecipientPaymentInfo = exports.AssetBalanceInfo = exports.CollateralEventInfo = exports.PendingRemunerationInfo = exports.GuaranteeInfo = exports.TabInfo = exports.PaymentGuaranteeRequestClaims = exports.SigningScheme = void 0;
4
- const utils_1 = require("./utils");
5
- var SigningScheme;
6
- (function (SigningScheme) {
7
- SigningScheme["EIP712"] = "eip712";
8
- SigningScheme["EIP191"] = "eip191";
9
- })(SigningScheme || (exports.SigningScheme = SigningScheme = {}));
10
- class PaymentGuaranteeRequestClaims {
11
- constructor(init) {
12
- this.userAddress = init.userAddress;
13
- this.recipientAddress = init.recipientAddress;
14
- this.tabId = init.tabId;
15
- this.amount = init.amount;
16
- this.timestamp = init.timestamp;
17
- this.assetAddress = init.assetAddress;
18
- }
19
- static new(userAddress, recipientAddress, tabId, amount, timestamp, erc20Token) {
20
- const asset = erc20Token ?? '0x0000000000000000000000000000000000000000';
21
- return new PaymentGuaranteeRequestClaims({
22
- userAddress: (0, utils_1.normalizeAddress)(userAddress),
23
- recipientAddress: (0, utils_1.normalizeAddress)(recipientAddress),
24
- tabId: (0, utils_1.parseU256)(tabId),
25
- amount: (0, utils_1.parseU256)(amount),
26
- timestamp: Number(timestamp),
27
- assetAddress: (0, utils_1.normalizeAddress)(asset),
28
- });
29
- }
30
- }
31
- exports.PaymentGuaranteeRequestClaims = PaymentGuaranteeRequestClaims;
32
- function getAny(raw, ...keys) {
33
- for (const key of keys) {
34
- if (key in raw)
35
- return raw[key];
36
- }
37
- return undefined;
38
- }
39
- class TabInfo {
40
- constructor(tabId, userAddress, recipientAddress, assetAddress, startTimestamp, ttlSeconds, status, settlementStatus, createdAt, updatedAt) {
41
- this.tabId = tabId;
42
- this.userAddress = userAddress;
43
- this.recipientAddress = recipientAddress;
44
- this.assetAddress = assetAddress;
45
- this.startTimestamp = startTimestamp;
46
- this.ttlSeconds = ttlSeconds;
47
- this.status = status;
48
- this.settlementStatus = settlementStatus;
49
- this.createdAt = createdAt;
50
- this.updatedAt = updatedAt;
51
- }
52
- static fromRpc(raw) {
53
- return new TabInfo((0, utils_1.parseU256)(getAny(raw, 'tab_id', 'tabId') ?? 0), getAny(raw, 'user_address', 'userAddress') ?? '', getAny(raw, 'recipient_address', 'recipientAddress') ?? '', getAny(raw, 'asset_address', 'assetAddress') ?? '', Number(getAny(raw, 'start_timestamp', 'startTimestamp')), Number(getAny(raw, 'ttl_seconds', 'ttlSeconds')), getAny(raw, 'status') ?? '', getAny(raw, 'settlement_status', 'settlementStatus') ?? '', Number(getAny(raw, 'created_at', 'createdAt')), Number(getAny(raw, 'updated_at', 'updatedAt')));
54
- }
55
- }
56
- exports.TabInfo = TabInfo;
57
- class GuaranteeInfo {
58
- constructor(tabId, reqId, fromAddress, toAddress, assetAddress, amount, timestamp, certificate) {
59
- this.tabId = tabId;
60
- this.reqId = reqId;
61
- this.fromAddress = fromAddress;
62
- this.toAddress = toAddress;
63
- this.assetAddress = assetAddress;
64
- this.amount = amount;
65
- this.timestamp = timestamp;
66
- this.certificate = certificate;
67
- }
68
- static fromRpc(raw) {
69
- return new GuaranteeInfo((0, utils_1.parseU256)(getAny(raw, 'tab_id', 'tabId') ?? 0), (0, utils_1.parseU256)(getAny(raw, 'req_id', 'reqId') ?? 0), getAny(raw, 'from_address', 'fromAddress') ?? '', getAny(raw, 'to_address', 'toAddress') ?? '', getAny(raw, 'asset_address', 'assetAddress') ?? '', (0, utils_1.parseU256)(getAny(raw, 'amount') ?? 0), Number(getAny(raw, 'start_timestamp', 'startTimestamp', 'timestamp') ?? 0), getAny(raw, 'certificate'));
70
- }
71
- }
72
- exports.GuaranteeInfo = GuaranteeInfo;
73
- class PendingRemunerationInfo {
74
- constructor(tab, latestGuarantee) {
75
- this.tab = tab;
76
- this.latestGuarantee = latestGuarantee;
77
- }
78
- static fromRpc(raw) {
79
- const latest = getAny(raw, 'latest_guarantee', 'latestGuarantee');
80
- return new PendingRemunerationInfo(TabInfo.fromRpc(getAny(raw, 'tab') ?? {}), latest ? GuaranteeInfo.fromRpc(latest) : null);
81
- }
82
- }
83
- exports.PendingRemunerationInfo = PendingRemunerationInfo;
84
- class CollateralEventInfo {
85
- constructor(id, userAddress, assetAddress, amount, eventType, tabId, reqId, txId, createdAt = 0) {
86
- this.id = id;
87
- this.userAddress = userAddress;
88
- this.assetAddress = assetAddress;
89
- this.amount = amount;
90
- this.eventType = eventType;
91
- this.tabId = tabId;
92
- this.reqId = reqId;
93
- this.txId = txId;
94
- this.createdAt = createdAt;
95
- }
96
- static fromRpc(raw) {
97
- const tabId = getAny(raw, 'tab_id', 'tabId');
98
- const reqId = getAny(raw, 'req_id', 'reqId');
99
- return new CollateralEventInfo(getAny(raw, 'id') ?? '', getAny(raw, 'user_address', 'userAddress') ?? '', getAny(raw, 'asset_address', 'assetAddress') ?? '', (0, utils_1.parseU256)(getAny(raw, 'amount') ?? 0), getAny(raw, 'event_type', 'eventType') ?? '', tabId !== undefined && tabId !== null ? (0, utils_1.parseU256)(tabId) : null, reqId !== undefined && reqId !== null ? (0, utils_1.parseU256)(reqId) : null, getAny(raw, 'tx_id', 'txId'), Number(getAny(raw, 'created_at', 'createdAt') ?? 0));
100
- }
101
- }
102
- exports.CollateralEventInfo = CollateralEventInfo;
103
- class AssetBalanceInfo {
104
- constructor(userAddress, assetAddress, total, locked, version, updatedAt) {
105
- this.userAddress = userAddress;
106
- this.assetAddress = assetAddress;
107
- this.total = total;
108
- this.locked = locked;
109
- this.version = version;
110
- this.updatedAt = updatedAt;
111
- }
112
- static fromRpc(raw) {
113
- return new AssetBalanceInfo(getAny(raw, 'user_address', 'userAddress') ?? '', getAny(raw, 'asset_address', 'assetAddress') ?? '', (0, utils_1.parseU256)(getAny(raw, 'total') ?? 0), (0, utils_1.parseU256)(getAny(raw, 'locked') ?? 0), Number(getAny(raw, 'version') ?? 0), Number(getAny(raw, 'updated_at', 'updatedAt') ?? 0));
114
- }
115
- }
116
- exports.AssetBalanceInfo = AssetBalanceInfo;
117
- class RecipientPaymentInfo {
118
- constructor(userAddress, recipientAddress, txHash, amount, verified, finalized, failed, createdAt) {
119
- this.userAddress = userAddress;
120
- this.recipientAddress = recipientAddress;
121
- this.txHash = txHash;
122
- this.amount = amount;
123
- this.verified = verified;
124
- this.finalized = finalized;
125
- this.failed = failed;
126
- this.createdAt = createdAt;
127
- }
128
- static fromRpc(raw) {
129
- return new RecipientPaymentInfo(getAny(raw, 'user_address', 'userAddress') ?? '', getAny(raw, 'recipient_address', 'recipientAddress') ?? '', getAny(raw, 'tx_hash', 'txHash') ?? '', (0, utils_1.parseU256)(getAny(raw, 'amount') ?? 0), Boolean(getAny(raw, 'verified')), Boolean(getAny(raw, 'finalized')), Boolean(getAny(raw, 'failed')), Number(getAny(raw, 'created_at', 'createdAt') ?? 0));
130
- }
131
- }
132
- exports.RecipientPaymentInfo = RecipientPaymentInfo;
package/dist/src/rpc.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import { CorePublicParameters } from './signing';
2
- export type FetchFn = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
3
- export declare class RpcProxy {
4
- private baseUrl;
5
- private adminApiKey?;
6
- private fetchFn;
7
- constructor(endpoint: string, adminApiKey?: string, fetchFn?: FetchFn);
8
- aclose(): Promise<void>;
9
- private headers;
10
- private decode;
11
- private get;
12
- private post;
13
- getPublicParams(): Promise<CorePublicParameters>;
14
- issueGuarantee(body: Record<string, any>): Promise<any>;
15
- createPaymentTab(body: Record<string, any>): Promise<any>;
16
- listSettledTabs(recipientAddress: string): Promise<any[]>;
17
- listPendingRemunerations(recipientAddress: string): Promise<any[]>;
18
- getTab(tabId: number | bigint): Promise<any>;
19
- listRecipientTabs(recipientAddress: string, settlementStatuses?: string[]): Promise<any[]>;
20
- getTabGuarantees(tabId: number | bigint): Promise<any[]>;
21
- getLatestGuarantee(tabId: number | bigint): Promise<any>;
22
- getGuarantee(tabId: number | bigint, reqId: number | bigint): Promise<any>;
23
- listRecipientPayments(recipientAddress: string): Promise<any[]>;
24
- getCollateralEventsForTab(tabId: number | bigint): Promise<any[]>;
25
- getUserAssetBalance(userAddress: string, assetAddress: string): Promise<any>;
26
- updateUserSuspension(userAddress: string, suspended: boolean): Promise<any>;
27
- createAdminApiKey(body: Record<string, any>): Promise<any>;
28
- listAdminApiKeys(): Promise<any[]>;
29
- revokeAdminApiKey(keyId: string): Promise<any>;
30
- }