@4mica/sdk 0.5.5 → 1.0.0

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/dist/models.d.ts CHANGED
@@ -1,12 +1,24 @@
1
1
  export { ADMIN_API_KEY_HEADER, ADMIN_API_KEY_PREFIX, ADMIN_SCOPE_MANAGE_KEYS, ADMIN_SCOPE_SUSPEND_USERS, } from './constants';
2
+ /** Signing scheme used when producing a payment guarantee signature. */
2
3
  export declare enum SigningScheme {
4
+ /** EIP-712 typed-data signing (default, preferred). */
3
5
  EIP712 = "eip712",
6
+ /** EIP-191 personal_sign (for wallets that do not support typed data). */
4
7
  EIP191 = "eip191"
5
8
  }
9
+ /** ECDSA signature and the scheme used to produce it. */
6
10
  export interface PaymentSignature {
11
+ /** 65-byte ECDSA signature as a `0x`-prefixed hex string. */
7
12
  signature: string;
8
13
  scheme: SigningScheme;
9
14
  }
15
+ /**
16
+ * V1 payment guarantee request claims. Signed by the payer and submitted to the
17
+ * core RPC to obtain a BLS guarantee certificate.
18
+ *
19
+ * Build with the static {@link PaymentGuaranteeRequestClaims.new} factory which
20
+ * normalises addresses and parses `uint256` values.
21
+ */
10
22
  export declare class PaymentGuaranteeRequestClaims {
11
23
  userAddress: string;
12
24
  recipientAddress: string;
@@ -26,6 +38,57 @@ export declare class PaymentGuaranteeRequestClaims {
26
38
  });
27
39
  static new(userAddress: string, recipientAddress: string, tabId: number | bigint | string, amount: number | bigint | string, timestamp: number, erc20Token?: string | null, reqId?: number | bigint | string): PaymentGuaranteeRequestClaims;
28
40
  }
41
+ /** On-chain validation policy fields carried in a V2 payment guarantee certificate. */
42
+ export interface PaymentGuaranteeValidationPolicyV2 {
43
+ validationRegistryAddress: string;
44
+ validationRequestHash: string;
45
+ validationChainId: number;
46
+ validatorAddress: string;
47
+ validatorAgentId: bigint;
48
+ minValidationScore: number;
49
+ validationSubjectHash: string;
50
+ requiredValidationTag: string;
51
+ }
52
+ /**
53
+ * V2 payment guarantee request claims — extends V1 with a full on-chain validation policy.
54
+ *
55
+ * Compute `validationSubjectHash` via `computeValidationSubjectHash(baseClaims)` and
56
+ * `validationRequestHash` via `computeValidationRequestHash(partialV2)` before constructing.
57
+ *
58
+ * @throws {@link ValidationError} if `minValidationScore` is outside [1, 100].
59
+ */
60
+ export declare class PaymentGuaranteeRequestClaimsV2 extends PaymentGuaranteeRequestClaims {
61
+ validationRegistryAddress: string;
62
+ validationRequestHash: string;
63
+ validationChainId: number;
64
+ validatorAddress: string;
65
+ validatorAgentId: bigint;
66
+ minValidationScore: number;
67
+ validationSubjectHash: string;
68
+ requiredValidationTag: string;
69
+ constructor(init: {
70
+ userAddress: string;
71
+ recipientAddress: string;
72
+ tabId: bigint;
73
+ reqId?: bigint;
74
+ amount: bigint;
75
+ timestamp: number;
76
+ assetAddress: string;
77
+ validationRegistryAddress: string;
78
+ validationRequestHash: string;
79
+ validationChainId: number;
80
+ validatorAddress: string;
81
+ validatorAgentId: bigint;
82
+ minValidationScore: number;
83
+ validationSubjectHash: string;
84
+ requiredValidationTag: string;
85
+ });
86
+ }
87
+ /**
88
+ * Decoded payment guarantee claims, as returned by `decodeGuaranteeClaims`.
89
+ * `version` is `1` for V1 certificates and `2` for V2 certificates.
90
+ * V2 certificates additionally carry a `validationPolicy`.
91
+ */
29
92
  export interface PaymentGuaranteeClaims {
30
93
  domain: Uint8Array;
31
94
  userAddress: string;
@@ -37,20 +100,36 @@ export interface PaymentGuaranteeClaims {
37
100
  assetAddress: string;
38
101
  timestamp: number;
39
102
  version: number;
103
+ validationPolicy?: PaymentGuaranteeValidationPolicyV2;
40
104
  }
105
+ /**
106
+ * BLS guarantee certificate returned by `issuePaymentGuarantee`.
107
+ * Both fields are `0x`-prefixed hex strings.
108
+ */
41
109
  export interface BLSCert {
110
+ /** ABI-encoded `(uint64 version, bytes innerClaims)` envelope as a hex string. */
42
111
  claims: string;
112
+ /** BLS12-381 G2 signature as a hex string. */
43
113
  signature: string;
44
114
  }
115
+ /** On-chain payment status of a tab, returned by `getTabPaymentStatus`. */
45
116
  export interface TabPaymentStatus {
117
+ /** Cumulative amount paid so far (in token base units). */
46
118
  paid: bigint;
119
+ /** Whether the recipient has already called `remunerate` on-chain. */
47
120
  remunerated: boolean;
121
+ /** Asset address (`0x000...` for ETH). */
48
122
  asset: string;
49
123
  }
124
+ /** On-chain collateral position for a single asset, returned by `getUser`. */
50
125
  export interface UserInfo {
126
+ /** Asset address (`0x000...` for ETH). */
51
127
  asset: string;
128
+ /** Total deposited collateral available for payments (in token base units). */
52
129
  collateral: bigint;
130
+ /** Amount of a pending withdrawal request (0 if none). */
53
131
  withdrawalRequestAmount: bigint;
132
+ /** Unix timestamp when the withdrawal request was made (0 if none). */
54
133
  withdrawalRequestTimestamp: number;
55
134
  }
56
135
  export declare class UserSuspensionStatus {
@@ -145,3 +224,32 @@ export declare class RecipientPaymentInfo {
145
224
  constructor(userAddress: string, recipientAddress: string, txHash: string, amount: bigint, verified: boolean, finalized: boolean, failed: boolean, createdAt: number);
146
225
  static fromRpc(raw: Record<string, unknown>): RecipientPaymentInfo;
147
226
  }
227
+ export interface SupportedTokenInfo {
228
+ symbol: string;
229
+ address: string;
230
+ decimals?: number;
231
+ }
232
+ export declare class SupportedTokensResponse {
233
+ chainId: number;
234
+ tokens: SupportedTokenInfo[];
235
+ constructor(chainId: number, tokens: SupportedTokenInfo[]);
236
+ static fromRpc(raw: Record<string, unknown>): SupportedTokensResponse;
237
+ }
238
+ export declare class CorePublicParameters {
239
+ publicKey: Uint8Array;
240
+ contractAddress: string;
241
+ ethereumHttpRpcUrl: string;
242
+ eip712Name: string;
243
+ eip712Version: string;
244
+ chainId: number;
245
+ maxAcceptedGuaranteeVersion: number;
246
+ acceptedGuaranteeVersions: number[];
247
+ activeGuaranteeDomainSeparator: string;
248
+ /** Allowlist of trusted validation registry addresses configured in core (may be empty). */
249
+ trustedValidationRegistries: string[];
250
+ validationHashCanonicalizationVersion: string;
251
+ constructor(publicKey: Uint8Array, contractAddress: string, ethereumHttpRpcUrl: string, eip712Name: string, eip712Version: string, chainId: number, maxAcceptedGuaranteeVersion?: number, acceptedGuaranteeVersions?: number[], activeGuaranteeDomainSeparator?: string,
252
+ /** Allowlist of trusted validation registry addresses configured in core (may be empty). */
253
+ trustedValidationRegistries?: string[], validationHashCanonicalizationVersion?: string);
254
+ static fromRpc(payload: Record<string, unknown>): CorePublicParameters;
255
+ }
package/dist/models.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RecipientPaymentInfo = exports.AssetBalanceInfo = exports.CollateralEventInfo = exports.PendingRemunerationInfo = exports.GuaranteeInfo = exports.TabInfo = exports.AdminApiKeySecret = exports.AdminApiKeyInfo = exports.UserSuspensionStatus = exports.PaymentGuaranteeRequestClaims = exports.SigningScheme = exports.ADMIN_SCOPE_SUSPEND_USERS = exports.ADMIN_SCOPE_MANAGE_KEYS = exports.ADMIN_API_KEY_PREFIX = exports.ADMIN_API_KEY_HEADER = void 0;
3
+ exports.CorePublicParameters = exports.SupportedTokensResponse = exports.RecipientPaymentInfo = exports.AssetBalanceInfo = exports.CollateralEventInfo = exports.PendingRemunerationInfo = exports.GuaranteeInfo = exports.TabInfo = exports.AdminApiKeySecret = exports.AdminApiKeyInfo = exports.UserSuspensionStatus = exports.PaymentGuaranteeRequestClaimsV2 = exports.PaymentGuaranteeRequestClaims = exports.SigningScheme = exports.ADMIN_SCOPE_SUSPEND_USERS = exports.ADMIN_SCOPE_MANAGE_KEYS = exports.ADMIN_API_KEY_PREFIX = exports.ADMIN_API_KEY_HEADER = void 0;
4
+ const viem_1 = require("viem");
4
5
  const serde_1 = require("./serde");
5
6
  const utils_1 = require("./utils");
6
7
  var constants_1 = require("./constants");
@@ -8,11 +9,21 @@ Object.defineProperty(exports, "ADMIN_API_KEY_HEADER", { enumerable: true, get:
8
9
  Object.defineProperty(exports, "ADMIN_API_KEY_PREFIX", { enumerable: true, get: function () { return constants_1.ADMIN_API_KEY_PREFIX; } });
9
10
  Object.defineProperty(exports, "ADMIN_SCOPE_MANAGE_KEYS", { enumerable: true, get: function () { return constants_1.ADMIN_SCOPE_MANAGE_KEYS; } });
10
11
  Object.defineProperty(exports, "ADMIN_SCOPE_SUSPEND_USERS", { enumerable: true, get: function () { return constants_1.ADMIN_SCOPE_SUSPEND_USERS; } });
12
+ /** Signing scheme used when producing a payment guarantee signature. */
11
13
  var SigningScheme;
12
14
  (function (SigningScheme) {
15
+ /** EIP-712 typed-data signing (default, preferred). */
13
16
  SigningScheme["EIP712"] = "eip712";
17
+ /** EIP-191 personal_sign (for wallets that do not support typed data). */
14
18
  SigningScheme["EIP191"] = "eip191";
15
19
  })(SigningScheme || (exports.SigningScheme = SigningScheme = {}));
20
+ /**
21
+ * V1 payment guarantee request claims. Signed by the payer and submitted to the
22
+ * core RPC to obtain a BLS guarantee certificate.
23
+ *
24
+ * Build with the static {@link PaymentGuaranteeRequestClaims.new} factory which
25
+ * normalises addresses and parses `uint256` values.
26
+ */
16
27
  class PaymentGuaranteeRequestClaims {
17
28
  userAddress;
18
29
  recipientAddress;
@@ -44,6 +55,39 @@ class PaymentGuaranteeRequestClaims {
44
55
  }
45
56
  }
46
57
  exports.PaymentGuaranteeRequestClaims = PaymentGuaranteeRequestClaims;
58
+ /**
59
+ * V2 payment guarantee request claims — extends V1 with a full on-chain validation policy.
60
+ *
61
+ * Compute `validationSubjectHash` via `computeValidationSubjectHash(baseClaims)` and
62
+ * `validationRequestHash` via `computeValidationRequestHash(partialV2)` before constructing.
63
+ *
64
+ * @throws {@link ValidationError} if `minValidationScore` is outside [1, 100].
65
+ */
66
+ class PaymentGuaranteeRequestClaimsV2 extends PaymentGuaranteeRequestClaims {
67
+ validationRegistryAddress;
68
+ validationRequestHash;
69
+ validationChainId;
70
+ validatorAddress;
71
+ validatorAgentId;
72
+ minValidationScore;
73
+ validationSubjectHash;
74
+ requiredValidationTag;
75
+ constructor(init) {
76
+ super(init);
77
+ if (init.minValidationScore < 1 || init.minValidationScore > 100) {
78
+ throw new utils_1.ValidationError(`minValidationScore must be in [1, 100], got ${init.minValidationScore}`);
79
+ }
80
+ this.validationRegistryAddress = (0, utils_1.normalizeAddress)(init.validationRegistryAddress);
81
+ this.validationRequestHash = (0, utils_1.ensureHexPrefix)(init.validationRequestHash).toLowerCase();
82
+ this.validationChainId = init.validationChainId;
83
+ this.validatorAddress = (0, utils_1.normalizeAddress)(init.validatorAddress);
84
+ this.validatorAgentId = init.validatorAgentId;
85
+ this.minValidationScore = init.minValidationScore;
86
+ this.validationSubjectHash = (0, utils_1.ensureHexPrefix)(init.validationSubjectHash).toLowerCase();
87
+ this.requiredValidationTag = init.requiredValidationTag;
88
+ }
89
+ }
90
+ exports.PaymentGuaranteeRequestClaimsV2 = PaymentGuaranteeRequestClaimsV2;
47
91
  class UserSuspensionStatus {
48
92
  userAddress;
49
93
  suspended;
@@ -232,3 +276,78 @@ class RecipientPaymentInfo {
232
276
  }
233
277
  }
234
278
  exports.RecipientPaymentInfo = RecipientPaymentInfo;
279
+ class SupportedTokensResponse {
280
+ chainId;
281
+ tokens;
282
+ constructor(chainId, tokens) {
283
+ this.chainId = chainId;
284
+ this.tokens = tokens;
285
+ }
286
+ static fromRpc(raw) {
287
+ const tokensRaw = (0, serde_1.getAny)(raw, 'tokens');
288
+ const tokens = [];
289
+ if (Array.isArray(tokensRaw)) {
290
+ for (const token of tokensRaw) {
291
+ const address = (0, serde_1.getAny)(token, 'address');
292
+ if (typeof address !== 'string' || address.length === 0)
293
+ continue;
294
+ const decimals = (0, serde_1.getAny)(token, 'decimals');
295
+ tokens.push({
296
+ symbol: String((0, serde_1.getAny)(token, 'symbol') ?? ''),
297
+ address,
298
+ decimals: decimals === undefined || decimals === null ? undefined : Number(decimals),
299
+ });
300
+ }
301
+ }
302
+ return new SupportedTokensResponse(Number((0, serde_1.getAny)(raw, 'chain_id', 'chainId') ?? 0), tokens);
303
+ }
304
+ }
305
+ exports.SupportedTokensResponse = SupportedTokensResponse;
306
+ class CorePublicParameters {
307
+ publicKey;
308
+ contractAddress;
309
+ ethereumHttpRpcUrl;
310
+ eip712Name;
311
+ eip712Version;
312
+ chainId;
313
+ maxAcceptedGuaranteeVersion;
314
+ acceptedGuaranteeVersions;
315
+ activeGuaranteeDomainSeparator;
316
+ trustedValidationRegistries;
317
+ validationHashCanonicalizationVersion;
318
+ constructor(publicKey, contractAddress, ethereumHttpRpcUrl, eip712Name, eip712Version, chainId, maxAcceptedGuaranteeVersion = 1, acceptedGuaranteeVersions = [], activeGuaranteeDomainSeparator = '',
319
+ /** Allowlist of trusted validation registry addresses configured in core (may be empty). */
320
+ trustedValidationRegistries = [], validationHashCanonicalizationVersion = '4MICA_VALIDATION_REQUEST_V1') {
321
+ this.publicKey = publicKey;
322
+ this.contractAddress = contractAddress;
323
+ this.ethereumHttpRpcUrl = ethereumHttpRpcUrl;
324
+ this.eip712Name = eip712Name;
325
+ this.eip712Version = eip712Version;
326
+ this.chainId = chainId;
327
+ this.maxAcceptedGuaranteeVersion = maxAcceptedGuaranteeVersion;
328
+ this.acceptedGuaranteeVersions = acceptedGuaranteeVersions;
329
+ this.activeGuaranteeDomainSeparator = activeGuaranteeDomainSeparator;
330
+ this.trustedValidationRegistries = trustedValidationRegistries;
331
+ this.validationHashCanonicalizationVersion = validationHashCanonicalizationVersion;
332
+ }
333
+ static fromRpc(payload) {
334
+ const pkRaw = payload.public_key ?? payload.publicKey;
335
+ const pk = typeof pkRaw === 'string'
336
+ ? (0, viem_1.toBytes)(pkRaw)
337
+ : pkRaw instanceof Uint8Array
338
+ ? pkRaw
339
+ : Array.isArray(pkRaw)
340
+ ? Uint8Array.from(pkRaw)
341
+ : new Uint8Array();
342
+ const registriesRaw = payload.trusted_validation_registries ?? payload.trustedValidationRegistries;
343
+ const trustedValidationRegistries = Array.isArray(registriesRaw)
344
+ ? registriesRaw.map(String)
345
+ : [];
346
+ return new CorePublicParameters(pk, String(payload.contract_address ?? payload.contractAddress ?? ''), String(payload.ethereum_http_rpc_url ?? payload.ethereumHttpRpcUrl ?? ''), (payload.eip712_name ?? payload.eip712Name ?? '4Mica'), (payload.eip712_version ?? payload.eip712Version ?? '1'), Number(payload.chain_id ?? payload.chainId), Number(payload.max_accepted_guarantee_version ?? payload.maxAcceptedGuaranteeVersion ?? 1), Array.isArray(payload.accepted_guarantee_versions ?? payload.acceptedGuaranteeVersions)
347
+ ? (payload.accepted_guarantee_versions ?? payload.acceptedGuaranteeVersions).map((version) => Number(version))
348
+ : [], String(payload.active_guarantee_domain_separator ?? payload.activeGuaranteeDomainSeparator ?? ''), trustedValidationRegistries, String(payload.validation_hash_canonicalization_version ??
349
+ payload.validationHashCanonicalizationVersion ??
350
+ '4MICA_VALIDATION_REQUEST_V1'));
351
+ }
352
+ }
353
+ exports.CorePublicParameters = CorePublicParameters;
package/dist/payment.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { PaymentGuaranteeRequestClaims, PaymentSignature, SigningScheme } from './models';
2
- export interface PaymentPayloadClaims {
3
- version: string;
1
+ import { PaymentGuaranteeRequestClaims, PaymentGuaranteeRequestClaimsV2, PaymentSignature, SigningScheme } from './models';
2
+ interface PaymentPayloadClaimsBase {
4
3
  user_address: string;
5
4
  recipient_address: string;
6
5
  tab_id: string;
@@ -9,11 +8,74 @@ export interface PaymentPayloadClaims {
9
8
  timestamp: number;
10
9
  asset_address: string;
11
10
  }
11
+ /** Wire-format representation of V1 payment guarantee claims sent to the core RPC. */
12
+ export interface PaymentPayloadClaims extends PaymentPayloadClaimsBase {
13
+ version: 'v1';
14
+ }
15
+ /** Wire-format representation of V2 payment guarantee claims sent to the core RPC. */
16
+ export interface PaymentPayloadClaimsV2 extends PaymentPayloadClaimsBase {
17
+ version: 'v2';
18
+ validation_registry_address: string;
19
+ validation_request_hash: string;
20
+ validation_chain_id: number;
21
+ validator_address: string;
22
+ validator_agent_id: string;
23
+ min_validation_score: number;
24
+ validation_subject_hash: string;
25
+ required_validation_tag: string;
26
+ }
27
+ /** Assembled payment payload ready to be submitted to the core RPC `issueGuarantee` endpoint. */
12
28
  export interface PaymentPayload {
13
- claims: PaymentPayloadClaims;
29
+ claims: PaymentPayloadClaims | PaymentPayloadClaimsV2;
30
+ /** 65-byte ECDSA signature as a `0x`-prefixed hex string. */
14
31
  signature: string;
15
32
  scheme: SigningScheme;
16
33
  }
34
+ /**
35
+ * Serialize V1 payment claims to the wire format expected by the core RPC.
36
+ *
37
+ * @param claims - V1 payment guarantee request claims.
38
+ * @returns JSON-serialisable object with snake_case keys and hex-encoded `uint256` fields.
39
+ */
17
40
  export declare function serializePaymentClaims(claims: PaymentGuaranteeRequestClaims): PaymentPayloadClaims;
41
+ /**
42
+ * Serialize V2 payment claims to the wire format expected by the core RPC.
43
+ *
44
+ * Extends the V1 serialisation with the eight additional validation policy fields.
45
+ *
46
+ * @param claims - V2 payment guarantee request claims with validation policy.
47
+ * @returns JSON-serialisable object with snake_case keys and hex-encoded `uint256` fields.
48
+ */
49
+ export declare function serializePaymentClaimsV2(claims: PaymentGuaranteeRequestClaimsV2): PaymentPayloadClaimsV2;
50
+ /**
51
+ * Build a {@link PaymentPayload} from V2 claims and a {@link PaymentSignature}.
52
+ *
53
+ * @param claims - V2 payment guarantee request claims.
54
+ * @param signature - Pre-built signature object (includes the scheme).
55
+ */
56
+ export declare function buildPaymentPayload(claims: PaymentGuaranteeRequestClaimsV2, signature: PaymentSignature): PaymentPayload;
57
+ /**
58
+ * Build a {@link PaymentPayload} from V2 claims, a raw signature hex string, and a scheme.
59
+ *
60
+ * @param claims - V2 payment guarantee request claims.
61
+ * @param signature - 65-byte ECDSA signature as a `0x`-prefixed hex string.
62
+ * @param scheme - Signing scheme used to produce the signature.
63
+ */
64
+ export declare function buildPaymentPayload(claims: PaymentGuaranteeRequestClaimsV2, signature: string, scheme: SigningScheme): PaymentPayload;
65
+ /**
66
+ * Build a {@link PaymentPayload} from V1 claims and a {@link PaymentSignature}.
67
+ *
68
+ * @param claims - V1 payment guarantee request claims.
69
+ * @param signature - Pre-built signature object (includes the scheme).
70
+ */
18
71
  export declare function buildPaymentPayload(claims: PaymentGuaranteeRequestClaims, signature: PaymentSignature): PaymentPayload;
72
+ /**
73
+ * Build a {@link PaymentPayload} from V1 claims, a raw signature hex string, and a scheme.
74
+ *
75
+ * @param claims - V1 payment guarantee request claims.
76
+ * @param signature - 65-byte ECDSA signature as a `0x`-prefixed hex string.
77
+ * @param scheme - Signing scheme used to produce the signature.
78
+ * @throws {@link SigningError} if `signature` is a string but no `scheme` is provided.
79
+ */
19
80
  export declare function buildPaymentPayload(claims: PaymentGuaranteeRequestClaims, signature: string, scheme: SigningScheme): PaymentPayload;
81
+ export {};
package/dist/payment.js CHANGED
@@ -1,31 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.serializePaymentClaims = serializePaymentClaims;
4
+ exports.serializePaymentClaimsV2 = serializePaymentClaimsV2;
4
5
  exports.buildPaymentPayload = buildPaymentPayload;
6
+ const models_1 = require("./models");
5
7
  const utils_1 = require("./utils");
8
+ const errors_1 = require("./errors");
9
+ /**
10
+ * Serialize V1 payment claims to the wire format expected by the core RPC.
11
+ *
12
+ * @param claims - V1 payment guarantee request claims.
13
+ * @returns JSON-serialisable object with snake_case keys and hex-encoded `uint256` fields.
14
+ */
6
15
  function serializePaymentClaims(claims) {
7
16
  return {
8
17
  version: 'v1',
9
- user_address: claims.userAddress,
10
- recipient_address: claims.recipientAddress,
18
+ user_address: claims.userAddress.toLowerCase(),
19
+ recipient_address: claims.recipientAddress.toLowerCase(),
11
20
  tab_id: (0, utils_1.serializeU256)(claims.tabId),
12
21
  req_id: (0, utils_1.serializeU256)(claims.reqId),
13
22
  amount: (0, utils_1.serializeU256)(claims.amount),
14
- asset_address: claims.assetAddress,
23
+ asset_address: claims.assetAddress.toLowerCase(),
15
24
  timestamp: claims.timestamp,
16
25
  };
17
26
  }
27
+ /**
28
+ * Serialize V2 payment claims to the wire format expected by the core RPC.
29
+ *
30
+ * Extends the V1 serialisation with the eight additional validation policy fields.
31
+ *
32
+ * @param claims - V2 payment guarantee request claims with validation policy.
33
+ * @returns JSON-serialisable object with snake_case keys and hex-encoded `uint256` fields.
34
+ */
35
+ function serializePaymentClaimsV2(claims) {
36
+ return {
37
+ ...serializePaymentClaims(claims),
38
+ version: 'v2',
39
+ validation_registry_address: claims.validationRegistryAddress.toLowerCase(),
40
+ validation_request_hash: claims.validationRequestHash.toLowerCase(),
41
+ validation_chain_id: claims.validationChainId,
42
+ validator_address: claims.validatorAddress.toLowerCase(),
43
+ validator_agent_id: (0, utils_1.serializeU256)(claims.validatorAgentId),
44
+ min_validation_score: claims.minValidationScore,
45
+ validation_subject_hash: claims.validationSubjectHash.toLowerCase(),
46
+ required_validation_tag: claims.requiredValidationTag,
47
+ };
48
+ }
18
49
  function buildPaymentPayload(claims, signature, scheme) {
19
50
  const signed = typeof signature === 'string'
20
51
  ? (() => {
21
52
  if (!scheme) {
22
- throw new Error('scheme is required when providing a signature string');
53
+ throw new errors_1.SigningError('scheme is required when providing a signature string');
23
54
  }
24
55
  return { signature, scheme };
25
56
  })()
26
57
  : signature;
58
+ const serialized = claims instanceof models_1.PaymentGuaranteeRequestClaimsV2
59
+ ? serializePaymentClaimsV2(claims)
60
+ : serializePaymentClaims(claims);
27
61
  return {
28
- claims: serializePaymentClaims(claims),
62
+ claims: serialized,
29
63
  signature: signed.signature,
30
64
  scheme: signed.scheme,
31
65
  };
package/dist/rpc.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { AdminApiKeyInfo, AdminApiKeySecret, UserSuspensionStatus } from './models';
2
- import { CorePublicParameters } from './signing';
1
+ import { AdminApiKeyInfo, AdminApiKeySecret, CorePublicParameters, SupportedTokensResponse, UserSuspensionStatus } from './models';
3
2
  import { type FetchFn as HttpFetchFn } from './http';
4
3
  export type FetchFn = HttpFetchFn;
5
4
  export type BearerTokenProvider = () => string | Promise<string>;
@@ -18,6 +17,7 @@ export declare class RpcProxy {
18
17
  private get;
19
18
  private post;
20
19
  getPublicParams(): Promise<CorePublicParameters>;
20
+ getSupportedTokens(): Promise<SupportedTokensResponse>;
21
21
  issueGuarantee(body: unknown): Promise<Record<string, unknown>>;
22
22
  createPaymentTab(body: unknown): Promise<Record<string, unknown>>;
23
23
  listSettledTabs(recipientAddress: string): Promise<Record<string, unknown>[]>;
package/dist/rpc.js CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RpcProxy = void 0;
4
4
  const constants_1 = require("./constants");
5
5
  const models_1 = require("./models");
6
- const signing_1 = require("./signing");
7
6
  const errors_1 = require("./errors");
8
7
  const http_1 = require("./http");
9
8
  function serializeTabId(tabId) {
@@ -83,7 +82,11 @@ class RpcProxy {
83
82
  }
84
83
  async getPublicParams() {
85
84
  const data = await this.get('/core/public-params');
86
- return signing_1.CorePublicParameters.fromRpc(data);
85
+ return models_1.CorePublicParameters.fromRpc(data);
86
+ }
87
+ async getSupportedTokens() {
88
+ const data = await this.get('/core/tokens');
89
+ return models_1.SupportedTokensResponse.fromRpc(data);
87
90
  }
88
91
  async issueGuarantee(body) {
89
92
  return this.post('/core/guarantees', body);
package/dist/signing.d.ts CHANGED
@@ -1,15 +1,6 @@
1
1
  import { Account, type Hex } from 'viem';
2
- import { PaymentGuaranteeRequestClaims, PaymentSignature, SigningScheme } from './models';
3
- export declare class CorePublicParameters {
4
- publicKey: Uint8Array;
5
- contractAddress: string;
6
- ethereumHttpRpcUrl: string;
7
- eip712Name: string;
8
- eip712Version: string;
9
- chainId: number;
10
- constructor(publicKey: Uint8Array, contractAddress: string, ethereumHttpRpcUrl: string, eip712Name: string, eip712Version: string, chainId: number);
11
- static fromRpc(payload: Record<string, unknown>): CorePublicParameters;
12
- }
2
+ export { computeValidationSubjectHash, computeValidationRequestHash } from './validation';
3
+ import { CorePublicParameters, PaymentGuaranteeRequestClaims, PaymentGuaranteeRequestClaimsV2, PaymentSignature, SigningScheme } from './models';
13
4
  export declare const GUARANTEE_EIP712_TYPES: {
14
5
  readonly EIP712Domain: readonly [{
15
6
  readonly name: "name";
@@ -44,6 +35,64 @@ export declare const GUARANTEE_EIP712_TYPES: {
44
35
  readonly type: "uint64";
45
36
  }];
46
37
  };
38
+ export declare const GUARANTEE_EIP712_TYPES_V2: {
39
+ readonly EIP712Domain: readonly [{
40
+ readonly name: "name";
41
+ readonly type: "string";
42
+ }, {
43
+ readonly name: "version";
44
+ readonly type: "string";
45
+ }, {
46
+ readonly name: "chainId";
47
+ readonly type: "uint256";
48
+ }];
49
+ readonly SolGuaranteeRequestClaimsV2: readonly [{
50
+ readonly name: "user";
51
+ readonly type: "address";
52
+ }, {
53
+ readonly name: "recipient";
54
+ readonly type: "address";
55
+ }, {
56
+ readonly name: "tabId";
57
+ readonly type: "uint256";
58
+ }, {
59
+ readonly name: "reqId";
60
+ readonly type: "uint256";
61
+ }, {
62
+ readonly name: "amount";
63
+ readonly type: "uint256";
64
+ }, {
65
+ readonly name: "asset";
66
+ readonly type: "address";
67
+ }, {
68
+ readonly name: "timestamp";
69
+ readonly type: "uint64";
70
+ }, {
71
+ readonly name: "validationRegistryAddress";
72
+ readonly type: "address";
73
+ }, {
74
+ readonly name: "validationRequestHash";
75
+ readonly type: "bytes32";
76
+ }, {
77
+ readonly name: "validationChainId";
78
+ readonly type: "uint256";
79
+ }, {
80
+ readonly name: "validatorAddress";
81
+ readonly type: "address";
82
+ }, {
83
+ readonly name: "validatorAgentId";
84
+ readonly type: "uint256";
85
+ }, {
86
+ readonly name: "minValidationScore";
87
+ readonly type: "uint8";
88
+ }, {
89
+ readonly name: "validationSubjectHash";
90
+ readonly type: "bytes32";
91
+ }, {
92
+ readonly name: "requiredValidationTag";
93
+ readonly type: "string";
94
+ }];
95
+ };
47
96
  export type GuaranteeTypedData = {
48
97
  types: typeof GUARANTEE_EIP712_TYPES;
49
98
  primaryType: 'SolGuaranteeRequestClaimsV1';
@@ -62,6 +111,32 @@ export type GuaranteeTypedData = {
62
111
  timestamp: bigint;
63
112
  };
64
113
  };
114
+ export type GuaranteeTypedDataV2 = {
115
+ types: typeof GUARANTEE_EIP712_TYPES_V2;
116
+ primaryType: 'SolGuaranteeRequestClaimsV2';
117
+ domain: {
118
+ name: string;
119
+ version: string;
120
+ chainId: number;
121
+ };
122
+ message: {
123
+ user: Hex;
124
+ recipient: Hex;
125
+ tabId: bigint;
126
+ reqId: bigint;
127
+ amount: bigint;
128
+ asset: Hex;
129
+ timestamp: bigint;
130
+ validationRegistryAddress: Hex;
131
+ validationRequestHash: Hex;
132
+ validationChainId: bigint;
133
+ validatorAddress: Hex;
134
+ validatorAgentId: bigint;
135
+ minValidationScore: number;
136
+ validationSubjectHash: Hex;
137
+ requiredValidationTag: string;
138
+ };
139
+ };
65
140
  export type GuaranteeTypedDataValidationOptions = {
66
141
  expectedChainId?: number;
67
142
  expectedSigner?: string;
@@ -81,9 +156,11 @@ export declare function validateGuaranteeTypedData(payload: {
81
156
  }, options?: GuaranteeTypedDataValidationOptions): void;
82
157
  export declare function validateGuaranteeSigningContext(params: CorePublicParameters, claims: PaymentGuaranteeRequestClaims, options?: GuaranteeSigningContextOptions): void;
83
158
  export declare function buildGuaranteeTypedData(params: CorePublicParameters, claims: PaymentGuaranteeRequestClaims): GuaranteeTypedData;
159
+ export declare function buildGuaranteeTypedDataV2(params: CorePublicParameters, claims: PaymentGuaranteeRequestClaimsV2): GuaranteeTypedDataV2;
160
+ export declare function encodeGuaranteeEip191V2(claims: PaymentGuaranteeRequestClaimsV2): string;
84
161
  export declare function encodeGuaranteeEip191(claims: PaymentGuaranteeRequestClaims): string;
85
162
  export declare class PaymentSigner {
86
163
  readonly signer: Account;
87
164
  constructor(signer: Account);
88
- signRequest(params: CorePublicParameters, claims: PaymentGuaranteeRequestClaims, scheme?: SigningScheme): Promise<PaymentSignature>;
165
+ signRequest(params: CorePublicParameters, claims: PaymentGuaranteeRequestClaims | PaymentGuaranteeRequestClaimsV2, scheme?: SigningScheme): Promise<PaymentSignature>;
89
166
  }