@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.
- package/README.md +17 -0
- package/dist/contract.d.ts +1 -0
- package/dist/contract.js +44 -18
- package/package.json +7 -2
- package/dist/abi/core4mica.json +0 -1605
- package/dist/abi/erc20.json +0 -187
- package/dist/client.d.ts +0 -56
- package/dist/client.js +0 -258
- package/dist/src/abi/core4mica.json +0 -1605
- package/dist/src/abi/erc20.json +0 -187
- package/dist/src/bls.d.ts +0 -5
- package/dist/src/bls.js +0 -45
- package/dist/src/client.d.ts +0 -55
- package/dist/src/client.js +0 -214
- package/dist/src/config.d.ts +0 -21
- package/dist/src/config.js +0 -76
- package/dist/src/contract.d.ts +0 -33
- package/dist/src/contract.js +0 -121
- package/dist/src/errors.d.ts +0 -17
- package/dist/src/errors.js +0 -31
- package/dist/src/guarantee.d.ts +0 -3
- package/dist/src/guarantee.js +0 -66
- package/dist/src/index.d.ts +0 -11
- package/dist/src/index.js +0 -27
- package/dist/src/models.d.ts +0 -119
- package/dist/src/models.js +0 -132
- package/dist/src/rpc.d.ts +0 -30
- package/dist/src/rpc.js +0 -122
- package/dist/src/signing.d.ts +0 -16
- package/dist/src/signing.js +0 -102
- package/dist/src/utils.d.ts +0 -8
- package/dist/src/utils.js +0 -78
- package/dist/src/x402.d.ts +0 -77
- package/dist/src/x402.js +0 -214
- package/dist/tests/config.test.d.ts +0 -1
- package/dist/tests/config.test.js +0 -26
- package/dist/tests/guarantee.test.d.ts +0 -1
- package/dist/tests/guarantee.test.js +0 -26
- package/dist/tests/rpc.test.d.ts +0 -1
- package/dist/tests/rpc.test.js +0 -44
- package/dist/tests/signing.test.d.ts +0 -1
- package/dist/tests/signing.test.js +0 -25
- package/dist/tests/utils.test.d.ts +0 -1
- package/dist/tests/utils.test.js +0 -25
- package/dist/tests/x402.test.d.ts +0 -1
- package/dist/tests/x402.test.js +0 -65
- package/dist/x402.d.ts +0 -78
- package/dist/x402.js +0 -231
package/dist/abi/erc20.json
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"abi": [
|
|
3
|
-
{
|
|
4
|
-
"type": "function",
|
|
5
|
-
"name": "allowance",
|
|
6
|
-
"inputs": [
|
|
7
|
-
{
|
|
8
|
-
"name": "owner",
|
|
9
|
-
"type": "address",
|
|
10
|
-
"internalType": "address"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"name": "spender",
|
|
14
|
-
"type": "address",
|
|
15
|
-
"internalType": "address"
|
|
16
|
-
}
|
|
17
|
-
],
|
|
18
|
-
"outputs": [
|
|
19
|
-
{
|
|
20
|
-
"name": "",
|
|
21
|
-
"type": "uint256",
|
|
22
|
-
"internalType": "uint256"
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
"stateMutability": "view"
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"type": "function",
|
|
29
|
-
"name": "approve",
|
|
30
|
-
"inputs": [
|
|
31
|
-
{
|
|
32
|
-
"name": "spender",
|
|
33
|
-
"type": "address",
|
|
34
|
-
"internalType": "address"
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"name": "value",
|
|
38
|
-
"type": "uint256",
|
|
39
|
-
"internalType": "uint256"
|
|
40
|
-
}
|
|
41
|
-
],
|
|
42
|
-
"outputs": [
|
|
43
|
-
{
|
|
44
|
-
"name": "",
|
|
45
|
-
"type": "bool",
|
|
46
|
-
"internalType": "bool"
|
|
47
|
-
}
|
|
48
|
-
],
|
|
49
|
-
"stateMutability": "nonpayable"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
"type": "function",
|
|
53
|
-
"name": "balanceOf",
|
|
54
|
-
"inputs": [
|
|
55
|
-
{
|
|
56
|
-
"name": "account",
|
|
57
|
-
"type": "address",
|
|
58
|
-
"internalType": "address"
|
|
59
|
-
}
|
|
60
|
-
],
|
|
61
|
-
"outputs": [
|
|
62
|
-
{
|
|
63
|
-
"name": "",
|
|
64
|
-
"type": "uint256",
|
|
65
|
-
"internalType": "uint256"
|
|
66
|
-
}
|
|
67
|
-
],
|
|
68
|
-
"stateMutability": "view"
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
"type": "function",
|
|
72
|
-
"name": "totalSupply",
|
|
73
|
-
"inputs": [],
|
|
74
|
-
"outputs": [
|
|
75
|
-
{
|
|
76
|
-
"name": "",
|
|
77
|
-
"type": "uint256",
|
|
78
|
-
"internalType": "uint256"
|
|
79
|
-
}
|
|
80
|
-
],
|
|
81
|
-
"stateMutability": "view"
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
"type": "function",
|
|
85
|
-
"name": "transfer",
|
|
86
|
-
"inputs": [
|
|
87
|
-
{
|
|
88
|
-
"name": "to",
|
|
89
|
-
"type": "address",
|
|
90
|
-
"internalType": "address"
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
"name": "value",
|
|
94
|
-
"type": "uint256",
|
|
95
|
-
"internalType": "uint256"
|
|
96
|
-
}
|
|
97
|
-
],
|
|
98
|
-
"outputs": [
|
|
99
|
-
{
|
|
100
|
-
"name": "",
|
|
101
|
-
"type": "bool",
|
|
102
|
-
"internalType": "bool"
|
|
103
|
-
}
|
|
104
|
-
],
|
|
105
|
-
"stateMutability": "nonpayable"
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
"type": "function",
|
|
109
|
-
"name": "transferFrom",
|
|
110
|
-
"inputs": [
|
|
111
|
-
{
|
|
112
|
-
"name": "from",
|
|
113
|
-
"type": "address",
|
|
114
|
-
"internalType": "address"
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
"name": "to",
|
|
118
|
-
"type": "address",
|
|
119
|
-
"internalType": "address"
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
"name": "value",
|
|
123
|
-
"type": "uint256",
|
|
124
|
-
"internalType": "uint256"
|
|
125
|
-
}
|
|
126
|
-
],
|
|
127
|
-
"outputs": [
|
|
128
|
-
{
|
|
129
|
-
"name": "",
|
|
130
|
-
"type": "bool",
|
|
131
|
-
"internalType": "bool"
|
|
132
|
-
}
|
|
133
|
-
],
|
|
134
|
-
"stateMutability": "nonpayable"
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
"type": "event",
|
|
138
|
-
"name": "Approval",
|
|
139
|
-
"inputs": [
|
|
140
|
-
{
|
|
141
|
-
"name": "owner",
|
|
142
|
-
"type": "address",
|
|
143
|
-
"indexed": true,
|
|
144
|
-
"internalType": "address"
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
"name": "spender",
|
|
148
|
-
"type": "address",
|
|
149
|
-
"indexed": true,
|
|
150
|
-
"internalType": "address"
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
"name": "value",
|
|
154
|
-
"type": "uint256",
|
|
155
|
-
"indexed": false,
|
|
156
|
-
"internalType": "uint256"
|
|
157
|
-
}
|
|
158
|
-
],
|
|
159
|
-
"anonymous": false
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
"type": "event",
|
|
163
|
-
"name": "Transfer",
|
|
164
|
-
"inputs": [
|
|
165
|
-
{
|
|
166
|
-
"name": "from",
|
|
167
|
-
"type": "address",
|
|
168
|
-
"indexed": true,
|
|
169
|
-
"internalType": "address"
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
"name": "to",
|
|
173
|
-
"type": "address",
|
|
174
|
-
"indexed": true,
|
|
175
|
-
"internalType": "address"
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
"name": "value",
|
|
179
|
-
"type": "uint256",
|
|
180
|
-
"indexed": false,
|
|
181
|
-
"internalType": "uint256"
|
|
182
|
-
}
|
|
183
|
-
],
|
|
184
|
-
"anonymous": false
|
|
185
|
-
}
|
|
186
|
-
]
|
|
187
|
-
}
|
package/dist/client.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { AuthTokens } from './auth';
|
|
2
|
-
import { Config } from './config';
|
|
3
|
-
import { ContractGateway } from './contract';
|
|
4
|
-
import { AssetBalanceInfo, BLSCert, CollateralEventInfo, GuaranteeInfo, PaymentGuaranteeClaims, PaymentGuaranteeRequestClaims, PaymentSignature, PendingRemunerationInfo, RecipientPaymentInfo, SigningScheme, TabInfo, TabPaymentStatus, UserInfo } from './models';
|
|
5
|
-
import { RpcProxy } from './rpc';
|
|
6
|
-
import { CorePublicParameters, PaymentSigner } from './signing';
|
|
7
|
-
export declare class Client {
|
|
8
|
-
readonly rpc: RpcProxy;
|
|
9
|
-
readonly params: CorePublicParameters;
|
|
10
|
-
readonly gateway: ContractGateway;
|
|
11
|
-
readonly guaranteeDomain: string;
|
|
12
|
-
readonly user: UserClient;
|
|
13
|
-
readonly recipient: RecipientClient;
|
|
14
|
-
readonly signer: PaymentSigner;
|
|
15
|
-
private authSession?;
|
|
16
|
-
private constructor();
|
|
17
|
-
static new(cfg: Config): Promise<Client>;
|
|
18
|
-
private static buildGateway;
|
|
19
|
-
aclose(): Promise<void>;
|
|
20
|
-
login(): Promise<AuthTokens>;
|
|
21
|
-
}
|
|
22
|
-
export declare class UserClient {
|
|
23
|
-
private client;
|
|
24
|
-
constructor(client: Client);
|
|
25
|
-
get guaranteeDomain(): string;
|
|
26
|
-
approveErc20(token: string, amount: number | bigint | string): Promise<import("viem").TransactionReceipt>;
|
|
27
|
-
deposit(amount: number | bigint | string, erc20Token?: string): Promise<import("viem").TransactionReceipt>;
|
|
28
|
-
getUser(): Promise<UserInfo[]>;
|
|
29
|
-
getTabPaymentStatus(tabId: number | bigint): Promise<TabPaymentStatus>;
|
|
30
|
-
signPayment(claims: PaymentGuaranteeRequestClaims, scheme?: SigningScheme): Promise<PaymentSignature>;
|
|
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>;
|
|
35
|
-
}
|
|
36
|
-
export declare class RecipientClient {
|
|
37
|
-
private client;
|
|
38
|
-
constructor(client: Client);
|
|
39
|
-
private get recipientAddress();
|
|
40
|
-
get guaranteeDomain(): string;
|
|
41
|
-
createTab(userAddress: string, recipientAddress: string, erc20Token: string | undefined | null, ttl?: number | null): Promise<bigint>;
|
|
42
|
-
getTabPaymentStatus(tabId: number | bigint): Promise<TabPaymentStatus>;
|
|
43
|
-
issuePaymentGuarantee(claims: PaymentGuaranteeRequestClaims, signature: string, scheme: SigningScheme): Promise<BLSCert>;
|
|
44
|
-
verifyPaymentGuarantee(cert: BLSCert): PaymentGuaranteeClaims;
|
|
45
|
-
remunerate(cert: BLSCert): Promise<import("viem").TransactionReceipt>;
|
|
46
|
-
listSettledTabs(): Promise<TabInfo[]>;
|
|
47
|
-
listPendingRemunerations(): Promise<PendingRemunerationInfo[]>;
|
|
48
|
-
getTab(tabId: number | bigint): Promise<TabInfo | null>;
|
|
49
|
-
listRecipientTabs(settlementStatuses?: string[]): Promise<TabInfo[]>;
|
|
50
|
-
getTabGuarantees(tabId: number | bigint): Promise<GuaranteeInfo[]>;
|
|
51
|
-
getLatestGuarantee(tabId: number | bigint): Promise<GuaranteeInfo | null>;
|
|
52
|
-
getGuarantee(tabId: number | bigint, reqId: number | bigint): Promise<GuaranteeInfo | null>;
|
|
53
|
-
listRecipientPayments(): Promise<RecipientPaymentInfo[]>;
|
|
54
|
-
getCollateralEventsForTab(tabId: number | bigint): Promise<CollateralEventInfo[]>;
|
|
55
|
-
getUserAssetBalance(userAddress: string, assetAddress: string): Promise<AssetBalanceInfo | null>;
|
|
56
|
-
}
|
package/dist/client.js
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RecipientClient = exports.UserClient = exports.Client = void 0;
|
|
4
|
-
const bls_1 = require("./bls");
|
|
5
|
-
const auth_1 = require("./auth");
|
|
6
|
-
const contract_1 = require("./contract");
|
|
7
|
-
const errors_1 = require("./errors");
|
|
8
|
-
const guarantee_1 = require("./guarantee");
|
|
9
|
-
const models_1 = require("./models");
|
|
10
|
-
const rpc_1 = require("./rpc");
|
|
11
|
-
const signing_1 = require("./signing");
|
|
12
|
-
const utils_1 = require("./utils");
|
|
13
|
-
const isNumericLike = (value) => typeof value === 'number' || typeof value === 'bigint' || typeof value === 'string';
|
|
14
|
-
function tabStatusFromRpc(status) {
|
|
15
|
-
const paid = status.paid !== undefined ? status.paid : (status.paidAmount ?? 0);
|
|
16
|
-
const remunerated = status.remunerated ?? status.paidOut ?? false;
|
|
17
|
-
const asset = status.asset ?? status.assetAddress ?? '';
|
|
18
|
-
return {
|
|
19
|
-
paid: (0, utils_1.parseU256)(paid),
|
|
20
|
-
remunerated: Boolean(remunerated),
|
|
21
|
-
asset,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
class Client {
|
|
25
|
-
rpc;
|
|
26
|
-
params;
|
|
27
|
-
gateway;
|
|
28
|
-
guaranteeDomain;
|
|
29
|
-
user;
|
|
30
|
-
recipient;
|
|
31
|
-
signer;
|
|
32
|
-
authSession;
|
|
33
|
-
constructor(rpc, params, gateway, guaranteeDomain, signer, authSession) {
|
|
34
|
-
this.rpc = rpc;
|
|
35
|
-
this.params = params;
|
|
36
|
-
this.gateway = gateway;
|
|
37
|
-
this.guaranteeDomain = guaranteeDomain;
|
|
38
|
-
this.signer = signer;
|
|
39
|
-
this.authSession = authSession;
|
|
40
|
-
this.user = new UserClient(this);
|
|
41
|
-
this.recipient = new RecipientClient(this);
|
|
42
|
-
}
|
|
43
|
-
static async new(cfg) {
|
|
44
|
-
const rpc = new rpc_1.RpcProxy(cfg.rpcUrl, cfg.adminApiKey);
|
|
45
|
-
const params = await rpc.getPublicParams();
|
|
46
|
-
const gateway = await Client.buildGateway(cfg, params);
|
|
47
|
-
const guaranteeDomain = await gateway.getGuaranteeDomain();
|
|
48
|
-
const signer = new signing_1.PaymentSigner(cfg.signer);
|
|
49
|
-
const authEnabled = cfg.authUrl !== undefined || cfg.authRefreshMarginSecs !== undefined;
|
|
50
|
-
const authSession = cfg.bearerToken || !authEnabled
|
|
51
|
-
? undefined
|
|
52
|
-
: new auth_1.AuthSession({
|
|
53
|
-
authUrl: cfg.authUrl ?? cfg.rpcUrl,
|
|
54
|
-
signer: cfg.signer,
|
|
55
|
-
refreshMarginSecs: cfg.authRefreshMarginSecs ?? 60,
|
|
56
|
-
});
|
|
57
|
-
if (cfg.bearerToken) {
|
|
58
|
-
rpc.withBearerToken(cfg.bearerToken);
|
|
59
|
-
}
|
|
60
|
-
else if (authSession) {
|
|
61
|
-
rpc.withTokenProvider(() => authSession.accessToken());
|
|
62
|
-
}
|
|
63
|
-
return new Client(rpc, params, gateway, guaranteeDomain, signer, authSession);
|
|
64
|
-
}
|
|
65
|
-
static async buildGateway(cfg, params) {
|
|
66
|
-
const ethRpcUrl = cfg.ethereumHttpRpcUrl ?? params.ethereumHttpRpcUrl;
|
|
67
|
-
const contractAddress = cfg.contractAddress ?? params.contractAddress;
|
|
68
|
-
return contract_1.ContractGateway.create(ethRpcUrl, cfg.signer, contractAddress, params.chainId);
|
|
69
|
-
}
|
|
70
|
-
async aclose() {
|
|
71
|
-
await this.rpc.aclose();
|
|
72
|
-
}
|
|
73
|
-
async login() {
|
|
74
|
-
if (!this.authSession) {
|
|
75
|
-
throw new errors_1.AuthMissingConfigError('auth is not enabled');
|
|
76
|
-
}
|
|
77
|
-
return this.authSession.login();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
exports.Client = Client;
|
|
81
|
-
class UserClient {
|
|
82
|
-
client;
|
|
83
|
-
constructor(client) {
|
|
84
|
-
this.client = client;
|
|
85
|
-
}
|
|
86
|
-
get guaranteeDomain() {
|
|
87
|
-
return this.client.guaranteeDomain;
|
|
88
|
-
}
|
|
89
|
-
async approveErc20(token, amount) {
|
|
90
|
-
return this.client.gateway.approveErc20(token, amount);
|
|
91
|
-
}
|
|
92
|
-
async deposit(amount, erc20Token) {
|
|
93
|
-
return this.client.gateway.deposit(amount, erc20Token);
|
|
94
|
-
}
|
|
95
|
-
async getUser() {
|
|
96
|
-
const assets = await this.client.gateway.getUserAssets();
|
|
97
|
-
return assets.map((a) => ({
|
|
98
|
-
asset: a.asset,
|
|
99
|
-
collateral: (0, utils_1.parseU256)(a.collateral),
|
|
100
|
-
withdrawalRequestAmount: (0, utils_1.parseU256)(a.withdrawalRequestAmount),
|
|
101
|
-
withdrawalRequestTimestamp: Number(a.withdrawalRequestTimestamp),
|
|
102
|
-
}));
|
|
103
|
-
}
|
|
104
|
-
async getTabPaymentStatus(tabId) {
|
|
105
|
-
const status = await this.client.gateway.getPaymentStatus(tabId);
|
|
106
|
-
return tabStatusFromRpc(status);
|
|
107
|
-
}
|
|
108
|
-
async signPayment(claims, scheme = models_1.SigningScheme.EIP712) {
|
|
109
|
-
return this.client.signer.signRequest(this.client.params, claims, scheme);
|
|
110
|
-
}
|
|
111
|
-
async payTab(tabId, reqId, amount, recipientAddress, erc20Token) {
|
|
112
|
-
if (erc20Token) {
|
|
113
|
-
return this.client.gateway.payTabErc20(tabId, amount, erc20Token, recipientAddress);
|
|
114
|
-
}
|
|
115
|
-
return this.client.gateway.payTabEth(tabId, reqId, amount, recipientAddress);
|
|
116
|
-
}
|
|
117
|
-
async requestWithdrawal(amount, erc20Token) {
|
|
118
|
-
return this.client.gateway.requestWithdrawal(amount, erc20Token);
|
|
119
|
-
}
|
|
120
|
-
async cancelWithdrawal(erc20Token) {
|
|
121
|
-
return this.client.gateway.cancelWithdrawal(erc20Token);
|
|
122
|
-
}
|
|
123
|
-
async finalizeWithdrawal(erc20Token) {
|
|
124
|
-
return this.client.gateway.finalizeWithdrawal(erc20Token);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.UserClient = UserClient;
|
|
128
|
-
class RecipientClient {
|
|
129
|
-
client;
|
|
130
|
-
constructor(client) {
|
|
131
|
-
this.client = client;
|
|
132
|
-
}
|
|
133
|
-
get recipientAddress() {
|
|
134
|
-
return (0, utils_1.normalizeAddress)(this.client.signer.signer.address);
|
|
135
|
-
}
|
|
136
|
-
get guaranteeDomain() {
|
|
137
|
-
return this.client.guaranteeDomain;
|
|
138
|
-
}
|
|
139
|
-
async createTab(userAddress, recipientAddress, erc20Token, ttl) {
|
|
140
|
-
const body = {
|
|
141
|
-
user_address: (0, utils_1.normalizeAddress)(userAddress),
|
|
142
|
-
recipient_address: (0, utils_1.normalizeAddress)(recipientAddress),
|
|
143
|
-
erc20_token: erc20Token ? (0, utils_1.normalizeAddress)(erc20Token) : null,
|
|
144
|
-
ttl: ttl ?? null,
|
|
145
|
-
};
|
|
146
|
-
const result = await this.client.rpc.createPaymentTab(body);
|
|
147
|
-
const record = result;
|
|
148
|
-
const tabIdRaw = record.id ?? record.tabId ?? record.tab_id;
|
|
149
|
-
const tabId = isNumericLike(tabIdRaw) ? tabIdRaw : 0;
|
|
150
|
-
return (0, utils_1.parseU256)(tabId);
|
|
151
|
-
}
|
|
152
|
-
async getTabPaymentStatus(tabId) {
|
|
153
|
-
const status = await this.client.gateway.getPaymentStatus(tabId);
|
|
154
|
-
return tabStatusFromRpc(status);
|
|
155
|
-
}
|
|
156
|
-
async issuePaymentGuarantee(claims, signature, scheme) {
|
|
157
|
-
const payload = {
|
|
158
|
-
claims: {
|
|
159
|
-
version: 'v1',
|
|
160
|
-
user_address: claims.userAddress,
|
|
161
|
-
recipient_address: claims.recipientAddress,
|
|
162
|
-
tab_id: (0, utils_1.serializeU256)(claims.tabId),
|
|
163
|
-
req_id: (0, utils_1.serializeU256)(claims.reqId),
|
|
164
|
-
amount: (0, utils_1.serializeU256)(claims.amount),
|
|
165
|
-
asset_address: claims.assetAddress,
|
|
166
|
-
timestamp: Number(claims.timestamp),
|
|
167
|
-
},
|
|
168
|
-
signature,
|
|
169
|
-
scheme,
|
|
170
|
-
};
|
|
171
|
-
const cert = await this.client.rpc.issueGuarantee(payload);
|
|
172
|
-
const record = cert;
|
|
173
|
-
const certClaims = typeof record.claims === 'string' ? record.claims : '';
|
|
174
|
-
const signatureOut = typeof record.signature === 'string' ? record.signature : '';
|
|
175
|
-
return { claims: certClaims, signature: signatureOut };
|
|
176
|
-
}
|
|
177
|
-
verifyPaymentGuarantee(cert) {
|
|
178
|
-
const claims = (0, guarantee_1.decodeGuaranteeClaims)(cert.claims);
|
|
179
|
-
const domainHex = this.guaranteeDomain.startsWith('0x')
|
|
180
|
-
? this.guaranteeDomain.slice(2)
|
|
181
|
-
: Buffer.from(this.guaranteeDomain).toString('hex');
|
|
182
|
-
const claimsHex = Buffer.from(claims.domain).toString('hex');
|
|
183
|
-
if (claimsHex !== domainHex) {
|
|
184
|
-
throw new errors_1.VerificationError('guarantee domain mismatch');
|
|
185
|
-
}
|
|
186
|
-
return claims;
|
|
187
|
-
}
|
|
188
|
-
async remunerate(cert) {
|
|
189
|
-
this.verifyPaymentGuarantee(cert);
|
|
190
|
-
const describeValue = (value) => {
|
|
191
|
-
if (value === null)
|
|
192
|
-
return 'null';
|
|
193
|
-
if (value === undefined)
|
|
194
|
-
return 'undefined';
|
|
195
|
-
if (Array.isArray(value))
|
|
196
|
-
return `array(len=${value.length})`;
|
|
197
|
-
if (typeof value === 'object') {
|
|
198
|
-
const keys = Object.keys(value);
|
|
199
|
-
return `object(keys=${keys.slice(0, 6).join(',')}${keys.length > 6 ? ',...' : ''})`;
|
|
200
|
-
}
|
|
201
|
-
return typeof value;
|
|
202
|
-
};
|
|
203
|
-
if (process.env.DEBUG_CERTS === '1') {
|
|
204
|
-
const preview = typeof cert.signature === 'string' ? cert.signature.slice(0, 12) : '';
|
|
205
|
-
console.log(` debug remunerate: signature=${describeValue(cert.signature)} ${preview}`);
|
|
206
|
-
}
|
|
207
|
-
if (typeof cert.claims !== 'string') {
|
|
208
|
-
throw new errors_1.VerificationError(`certificate.claims must be a hex string, got ${describeValue(cert.claims)}`);
|
|
209
|
-
}
|
|
210
|
-
if (typeof cert.signature !== 'string') {
|
|
211
|
-
throw new errors_1.VerificationError(`certificate.signature must be a hex string, got ${describeValue(cert.signature)}`);
|
|
212
|
-
}
|
|
213
|
-
const sigWords = await (0, bls_1.signatureToWordsAsync)(cert.signature);
|
|
214
|
-
const claimsBytes = Buffer.from(cert.claims.replace(/^0x/, ''), 'hex');
|
|
215
|
-
return this.client.gateway.remunerate(claimsBytes, sigWords);
|
|
216
|
-
}
|
|
217
|
-
async listSettledTabs() {
|
|
218
|
-
const tabs = await this.client.rpc.listSettledTabs(this.recipientAddress);
|
|
219
|
-
return tabs.map((t) => models_1.TabInfo.fromRpc(t));
|
|
220
|
-
}
|
|
221
|
-
async listPendingRemunerations() {
|
|
222
|
-
const items = await this.client.rpc.listPendingRemunerations(this.recipientAddress);
|
|
223
|
-
return items.map((item) => models_1.PendingRemunerationInfo.fromRpc(item));
|
|
224
|
-
}
|
|
225
|
-
async getTab(tabId) {
|
|
226
|
-
const result = await this.client.rpc.getTab(tabId);
|
|
227
|
-
return result ? models_1.TabInfo.fromRpc(result) : null;
|
|
228
|
-
}
|
|
229
|
-
async listRecipientTabs(settlementStatuses) {
|
|
230
|
-
const tabs = await this.client.rpc.listRecipientTabs(this.recipientAddress, settlementStatuses);
|
|
231
|
-
return tabs.map((t) => models_1.TabInfo.fromRpc(t));
|
|
232
|
-
}
|
|
233
|
-
async getTabGuarantees(tabId) {
|
|
234
|
-
const guarantees = await this.client.rpc.getTabGuarantees(tabId);
|
|
235
|
-
return guarantees.map((g) => models_1.GuaranteeInfo.fromRpc(g));
|
|
236
|
-
}
|
|
237
|
-
async getLatestGuarantee(tabId) {
|
|
238
|
-
const result = await this.client.rpc.getLatestGuarantee(tabId);
|
|
239
|
-
return result ? models_1.GuaranteeInfo.fromRpc(result) : null;
|
|
240
|
-
}
|
|
241
|
-
async getGuarantee(tabId, reqId) {
|
|
242
|
-
const result = await this.client.rpc.getGuarantee(tabId, reqId);
|
|
243
|
-
return result ? models_1.GuaranteeInfo.fromRpc(result) : null;
|
|
244
|
-
}
|
|
245
|
-
async listRecipientPayments() {
|
|
246
|
-
const payments = await this.client.rpc.listRecipientPayments(this.recipientAddress);
|
|
247
|
-
return payments.map((p) => models_1.RecipientPaymentInfo.fromRpc(p));
|
|
248
|
-
}
|
|
249
|
-
async getCollateralEventsForTab(tabId) {
|
|
250
|
-
const events = await this.client.rpc.getCollateralEventsForTab(tabId);
|
|
251
|
-
return events.map((ev) => models_1.CollateralEventInfo.fromRpc(ev));
|
|
252
|
-
}
|
|
253
|
-
async getUserAssetBalance(userAddress, assetAddress) {
|
|
254
|
-
const balance = await this.client.rpc.getUserAssetBalance(userAddress, assetAddress);
|
|
255
|
-
return balance ? models_1.AssetBalanceInfo.fromRpc(balance) : null;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
exports.RecipientClient = RecipientClient;
|