@4mica/sdk 1.2.17 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -25
- package/dist/index.cjs +5513 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2730 -0
- package/dist/{src/abi/core4mica.d.ts → index.d.ts} +1032 -1
- package/dist/index.js +5439 -0
- package/dist/index.js.map +1 -0
- package/dist/models-B15ouNYG.d.cts +386 -0
- package/dist/models-B15ouNYG.d.ts +386 -0
- package/dist/server.cjs +172 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +119 -0
- package/dist/server.d.ts +119 -0
- package/dist/server.js +165 -0
- package/dist/server.js.map +1 -0
- package/package.json +52 -43
- package/dist/package.json +0 -80
- package/dist/src/abi/core4mica.js +0 -2200
- package/dist/src/abi/erc20.d.ts +0 -151
- package/dist/src/abi/erc20.js +0 -201
- package/dist/src/auth.d.ts +0 -62
- package/dist/src/auth.js +0 -218
- package/dist/src/bls.d.ts +0 -6
- package/dist/src/bls.js +0 -247
- package/dist/src/chain.d.ts +0 -2
- package/dist/src/chain.js +0 -26
- package/dist/src/client/index.d.ts +0 -71
- package/dist/src/client/index.js +0 -120
- package/dist/src/client/recipient.d.ts +0 -129
- package/dist/src/client/recipient.js +0 -257
- package/dist/src/client/shared.d.ts +0 -11
- package/dist/src/client/shared.js +0 -17
- package/dist/src/client/user.d.ts +0 -109
- package/dist/src/client/user.js +0 -151
- package/dist/src/config.d.ts +0 -103
- package/dist/src/config.js +0 -197
- package/dist/src/constants.d.ts +0 -4
- package/dist/src/constants.js +0 -7
- package/dist/src/contract.d.ts +0 -55
- package/dist/src/contract.js +0 -312
- package/dist/src/debug.d.ts +0 -2
- package/dist/src/debug.js +0 -5
- package/dist/src/errors.d.ts +0 -58
- package/dist/src/errors.js +0 -81
- package/dist/src/guarantee.d.ts +0 -25
- package/dist/src/guarantee.js +0 -272
- package/dist/src/http.d.ts +0 -11
- package/dist/src/http.js +0 -57
- package/dist/src/index.d.ts +0 -17
- package/dist/src/index.js +0 -33
- package/dist/src/models.d.ts +0 -261
- package/dist/src/models.js +0 -360
- package/dist/src/networks.d.ts +0 -40
- package/dist/src/networks.js +0 -57
- package/dist/src/payment.d.ts +0 -82
- package/dist/src/payment.js +0 -67
- package/dist/src/rpc.d.ts +0 -38
- package/dist/src/rpc.js +0 -161
- package/dist/src/serde.d.ts +0 -5
- package/dist/src/serde.js +0 -33
- package/dist/src/signing.d.ts +0 -170
- package/dist/src/signing.js +0 -311
- package/dist/src/utils.d.ts +0 -11
- package/dist/src/utils.js +0 -90
- package/dist/src/validation.d.ts +0 -32
- package/dist/src/validation.js +0 -84
- package/dist/src/wallet/cdp.d.ts +0 -13
- package/dist/src/wallet/cdp.js +0 -78
- package/dist/src/wallet/index.d.ts +0 -2
- package/dist/src/wallet/index.js +0 -5
- package/dist/src/x402/index.d.ts +0 -90
- package/dist/src/x402/index.js +0 -243
- package/dist/src/x402/models.d.ts +0 -75
- package/dist/src/x402/models.js +0 -2
package/dist/src/errors.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AuthMissingConfigError = exports.AuthConfigError = exports.AuthApiError = exports.AuthDecodeError = exports.AuthTransportError = exports.AuthUrlError = exports.AuthError = exports.X402Error = exports.VerificationError = exports.ContractError = exports.SigningError = exports.ClientInitializationError = exports.RpcError = exports.ConfigError = exports.FourMicaError = void 0;
|
|
4
|
-
/** Base class for all 4Mica SDK errors. Sets `error.name` to the subclass name. */
|
|
5
|
-
class FourMicaError extends Error {
|
|
6
|
-
constructor(message) {
|
|
7
|
-
super(message);
|
|
8
|
-
this.name = this.constructor.name;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.FourMicaError = FourMicaError;
|
|
12
|
-
/** Thrown when the SDK configuration is invalid (e.g. missing required fields or bad URL). */
|
|
13
|
-
class ConfigError extends FourMicaError {
|
|
14
|
-
}
|
|
15
|
-
exports.ConfigError = ConfigError;
|
|
16
|
-
/** Thrown when a 4Mica core RPC call fails. Includes the HTTP status and raw response body. */
|
|
17
|
-
class RpcError extends FourMicaError {
|
|
18
|
-
status;
|
|
19
|
-
body;
|
|
20
|
-
constructor(message, options) {
|
|
21
|
-
super(message);
|
|
22
|
-
this.status = options?.status;
|
|
23
|
-
this.body = options?.body;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.RpcError = RpcError;
|
|
27
|
-
/** Thrown when the SDK client fails to initialise (e.g. chain ID mismatch). */
|
|
28
|
-
class ClientInitializationError extends FourMicaError {
|
|
29
|
-
}
|
|
30
|
-
exports.ClientInitializationError = ClientInitializationError;
|
|
31
|
-
/** Thrown when signing a payment claim fails (e.g. unsupported scheme, address mismatch). */
|
|
32
|
-
class SigningError extends FourMicaError {
|
|
33
|
-
}
|
|
34
|
-
exports.SigningError = SigningError;
|
|
35
|
-
/** Thrown when an on-chain contract call fails or returns an unexpected result. */
|
|
36
|
-
class ContractError extends FourMicaError {
|
|
37
|
-
}
|
|
38
|
-
exports.ContractError = ContractError;
|
|
39
|
-
/** Thrown when BLS certificate verification fails (e.g. domain mismatch, invalid encoding). */
|
|
40
|
-
class VerificationError extends FourMicaError {
|
|
41
|
-
}
|
|
42
|
-
exports.VerificationError = VerificationError;
|
|
43
|
-
/** Thrown when an x402 HTTP payment flow encounters an error. */
|
|
44
|
-
class X402Error extends FourMicaError {
|
|
45
|
-
}
|
|
46
|
-
exports.X402Error = X402Error;
|
|
47
|
-
/** Base class for authentication-related errors. */
|
|
48
|
-
class AuthError extends FourMicaError {
|
|
49
|
-
}
|
|
50
|
-
exports.AuthError = AuthError;
|
|
51
|
-
/** Thrown when the auth URL is invalid or unreachable. */
|
|
52
|
-
class AuthUrlError extends AuthError {
|
|
53
|
-
}
|
|
54
|
-
exports.AuthUrlError = AuthUrlError;
|
|
55
|
-
/** Thrown when a network-level error occurs during authentication. */
|
|
56
|
-
class AuthTransportError extends AuthError {
|
|
57
|
-
}
|
|
58
|
-
exports.AuthTransportError = AuthTransportError;
|
|
59
|
-
/** Thrown when the auth server response cannot be decoded. */
|
|
60
|
-
class AuthDecodeError extends AuthError {
|
|
61
|
-
}
|
|
62
|
-
exports.AuthDecodeError = AuthDecodeError;
|
|
63
|
-
/** Thrown when the auth server returns an error response. Includes HTTP status and body. */
|
|
64
|
-
class AuthApiError extends AuthError {
|
|
65
|
-
status;
|
|
66
|
-
body;
|
|
67
|
-
constructor(message, options) {
|
|
68
|
-
super(message);
|
|
69
|
-
this.status = options?.status;
|
|
70
|
-
this.body = options?.body;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.AuthApiError = AuthApiError;
|
|
74
|
-
/** Thrown when auth configuration is invalid. */
|
|
75
|
-
class AuthConfigError extends AuthError {
|
|
76
|
-
}
|
|
77
|
-
exports.AuthConfigError = AuthConfigError;
|
|
78
|
-
/** Thrown when an authenticated operation is attempted without auth being configured. */
|
|
79
|
-
class AuthMissingConfigError extends AuthConfigError {
|
|
80
|
-
}
|
|
81
|
-
exports.AuthMissingConfigError = AuthMissingConfigError;
|
package/dist/src/guarantee.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { PaymentGuaranteeClaims } from './models';
|
|
2
|
-
/**
|
|
3
|
-
* ABI-encode a {@link PaymentGuaranteeClaims} object into a hex string.
|
|
4
|
-
*
|
|
5
|
-
* Produces the outer `(uint64 version, bytes innerClaims)` envelope format expected
|
|
6
|
-
* by the Core4Mica contract. Supports V1 (10 fields) and V2 (19 fields with validation policy).
|
|
7
|
-
*
|
|
8
|
-
* @param claims - Decoded claims to encode. Must have `version` set to `1` or `2`.
|
|
9
|
-
* @returns `0x`-prefixed hex string of the ABI-encoded envelope.
|
|
10
|
-
* @throws {@link VerificationError} if `version` is not `1` or `2`, the domain is not 32 bytes,
|
|
11
|
-
* or V2 claims are missing `validationPolicy`.
|
|
12
|
-
*/
|
|
13
|
-
export declare function encodeGuaranteeClaims(claims: PaymentGuaranteeClaims): string;
|
|
14
|
-
/**
|
|
15
|
-
* Decode ABI-encoded guarantee claims into a {@link PaymentGuaranteeClaims} object.
|
|
16
|
-
*
|
|
17
|
-
* Accepts either the modern `(uint64 version, bytes innerClaims)` envelope or the legacy
|
|
18
|
-
* unwrapped V1 format (raw 320-byte ABI encoding without an outer envelope).
|
|
19
|
-
*
|
|
20
|
-
* @param data - Hex string or raw bytes of the ABI-encoded claims.
|
|
21
|
-
* @returns Decoded {@link PaymentGuaranteeClaims} with `version` set to `1` or `2`.
|
|
22
|
-
* @throws {@link VerificationError} if the data is too short, the inner length is wrong,
|
|
23
|
-
* or the encoded version number is unsupported.
|
|
24
|
-
*/
|
|
25
|
-
export declare function decodeGuaranteeClaims(data: string | Uint8Array): PaymentGuaranteeClaims;
|
package/dist/src/guarantee.js
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeGuaranteeClaims = encodeGuaranteeClaims;
|
|
4
|
-
exports.decodeGuaranteeClaims = decodeGuaranteeClaims;
|
|
5
|
-
const viem_1 = require("viem");
|
|
6
|
-
const errors_1 = require("./errors");
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
|
-
const CLAIMS_ENCODED_BYTES = 32 * 10;
|
|
9
|
-
// Minimum bytes for a valid outer envelope: uint64 + bytes offset + bytes length
|
|
10
|
-
const MIN_ENVELOPE_BYTES = 32 * 2 + 32;
|
|
11
|
-
const CLAIM_TYPES = [
|
|
12
|
-
{ type: 'bytes32' },
|
|
13
|
-
{ type: 'uint256' },
|
|
14
|
-
{ type: 'uint256' },
|
|
15
|
-
{ type: 'address' },
|
|
16
|
-
{ type: 'address' },
|
|
17
|
-
{ type: 'uint256' },
|
|
18
|
-
{ type: 'uint256' },
|
|
19
|
-
{ type: 'address' },
|
|
20
|
-
{ type: 'uint64' },
|
|
21
|
-
{ type: 'uint64' },
|
|
22
|
-
];
|
|
23
|
-
// V2 adds: validation_registry_address, validation_request_hash, validation_chain_id,
|
|
24
|
-
// validator_address, validator_agent_id, min_validation_score,
|
|
25
|
-
// validation_subject_hash, job_hash, required_validation_tag (dynamic string)
|
|
26
|
-
const CLAIM_TYPES_V2 = [
|
|
27
|
-
{ type: 'bytes32' }, // domain
|
|
28
|
-
{ type: 'uint256' }, // tab_id
|
|
29
|
-
{ type: 'uint256' }, // req_id
|
|
30
|
-
{ type: 'address' }, // client (user)
|
|
31
|
-
{ type: 'address' }, // recipient
|
|
32
|
-
{ type: 'uint256' }, // amount
|
|
33
|
-
{ type: 'uint256' }, // total_amount
|
|
34
|
-
{ type: 'address' }, // asset
|
|
35
|
-
{ type: 'uint64' }, // timestamp
|
|
36
|
-
{ type: 'uint64' }, // version
|
|
37
|
-
{ type: 'address' }, // validation_registry_address
|
|
38
|
-
{ type: 'bytes32' }, // validation_request_hash
|
|
39
|
-
{ type: 'uint64' }, // validation_chain_id
|
|
40
|
-
{ type: 'address' }, // validator_address
|
|
41
|
-
{ type: 'uint256' }, // validator_agent_id
|
|
42
|
-
{ type: 'uint8' }, // min_validation_score
|
|
43
|
-
{ type: 'bytes32' }, // validation_subject_hash
|
|
44
|
-
{ type: 'bytes32' }, // job_hash
|
|
45
|
-
{ type: 'string' }, // required_validation_tag (dynamic)
|
|
46
|
-
];
|
|
47
|
-
const CLAIM_TYPES_V2_TUPLE = [
|
|
48
|
-
{
|
|
49
|
-
type: 'tuple',
|
|
50
|
-
components: [
|
|
51
|
-
{ name: 'domain', type: 'bytes32' },
|
|
52
|
-
{ name: 'tabId', type: 'uint256' },
|
|
53
|
-
{ name: 'reqId', type: 'uint256' },
|
|
54
|
-
{ name: 'user', type: 'address' },
|
|
55
|
-
{ name: 'recipient', type: 'address' },
|
|
56
|
-
{ name: 'amount', type: 'uint256' },
|
|
57
|
-
{ name: 'totalAmount', type: 'uint256' },
|
|
58
|
-
{ name: 'asset', type: 'address' },
|
|
59
|
-
{ name: 'timestamp', type: 'uint64' },
|
|
60
|
-
{ name: 'claimsVersion', type: 'uint64' },
|
|
61
|
-
{ name: 'validationRegistryAddress', type: 'address' },
|
|
62
|
-
{ name: 'validationRequestHash', type: 'bytes32' },
|
|
63
|
-
{ name: 'validationChainId', type: 'uint64' },
|
|
64
|
-
{ name: 'validatorAddress', type: 'address' },
|
|
65
|
-
{ name: 'validatorAgentId', type: 'uint256' },
|
|
66
|
-
{ name: 'minValidationScore', type: 'uint8' },
|
|
67
|
-
{ name: 'validationSubjectHash', type: 'bytes32' },
|
|
68
|
-
{ name: 'jobHash', type: 'bytes32' },
|
|
69
|
-
{ name: 'requiredValidationTag', type: 'string' },
|
|
70
|
-
],
|
|
71
|
-
},
|
|
72
|
-
];
|
|
73
|
-
function ensureDomainBytes(domain) {
|
|
74
|
-
const bytes = typeof domain === 'string' ? (0, viem_1.toBytes)(domain) : domain;
|
|
75
|
-
if (bytes.length !== 32) {
|
|
76
|
-
throw new errors_1.VerificationError('domain separator must be 32 bytes');
|
|
77
|
-
}
|
|
78
|
-
return bytes;
|
|
79
|
-
}
|
|
80
|
-
function normalizeHexBytes(data) {
|
|
81
|
-
if (typeof data === 'string') {
|
|
82
|
-
return (0, utils_1.ensureHexPrefix)(data);
|
|
83
|
-
}
|
|
84
|
-
return (0, utils_1.hexFromBytes)(data);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* ABI-encode a {@link PaymentGuaranteeClaims} object into a hex string.
|
|
88
|
-
*
|
|
89
|
-
* Produces the outer `(uint64 version, bytes innerClaims)` envelope format expected
|
|
90
|
-
* by the Core4Mica contract. Supports V1 (10 fields) and V2 (19 fields with validation policy).
|
|
91
|
-
*
|
|
92
|
-
* @param claims - Decoded claims to encode. Must have `version` set to `1` or `2`.
|
|
93
|
-
* @returns `0x`-prefixed hex string of the ABI-encoded envelope.
|
|
94
|
-
* @throws {@link VerificationError} if `version` is not `1` or `2`, the domain is not 32 bytes,
|
|
95
|
-
* or V2 claims are missing `validationPolicy`.
|
|
96
|
-
*/
|
|
97
|
-
function encodeGuaranteeClaims(claims) {
|
|
98
|
-
if (claims.version === 1) {
|
|
99
|
-
const domain = ensureDomainBytes(claims.domain);
|
|
100
|
-
const encoded = (0, viem_1.encodeAbiParameters)(CLAIM_TYPES, [
|
|
101
|
-
(0, utils_1.hexFromBytes)(domain),
|
|
102
|
-
(0, utils_1.parseU256)(claims.tabId),
|
|
103
|
-
(0, utils_1.parseU256)(claims.reqId),
|
|
104
|
-
claims.userAddress,
|
|
105
|
-
claims.recipientAddress,
|
|
106
|
-
(0, utils_1.parseU256)(claims.amount),
|
|
107
|
-
(0, utils_1.parseU256)(claims.totalAmount),
|
|
108
|
-
claims.assetAddress,
|
|
109
|
-
BigInt(claims.timestamp),
|
|
110
|
-
BigInt(claims.version),
|
|
111
|
-
]);
|
|
112
|
-
return (0, viem_1.encodeAbiParameters)([{ type: 'uint64' }, { type: 'bytes' }], [BigInt(claims.version), encoded]);
|
|
113
|
-
}
|
|
114
|
-
if (claims.version === 2) {
|
|
115
|
-
if (!claims.validationPolicy) {
|
|
116
|
-
throw new errors_1.VerificationError('V2 guarantee claims missing validationPolicy');
|
|
117
|
-
}
|
|
118
|
-
const p = claims.validationPolicy;
|
|
119
|
-
const domain = ensureDomainBytes(claims.domain);
|
|
120
|
-
const encoded = (0, viem_1.encodeAbiParameters)(CLAIM_TYPES_V2_TUPLE, [
|
|
121
|
-
{
|
|
122
|
-
domain: (0, utils_1.hexFromBytes)(domain),
|
|
123
|
-
tabId: (0, utils_1.parseU256)(claims.tabId),
|
|
124
|
-
reqId: (0, utils_1.parseU256)(claims.reqId),
|
|
125
|
-
user: claims.userAddress,
|
|
126
|
-
recipient: claims.recipientAddress,
|
|
127
|
-
amount: (0, utils_1.parseU256)(claims.amount),
|
|
128
|
-
totalAmount: (0, utils_1.parseU256)(claims.totalAmount),
|
|
129
|
-
asset: claims.assetAddress,
|
|
130
|
-
timestamp: BigInt(claims.timestamp),
|
|
131
|
-
claimsVersion: BigInt(claims.version),
|
|
132
|
-
validationRegistryAddress: p.validationRegistryAddress,
|
|
133
|
-
validationRequestHash: (0, utils_1.ensureHexPrefix)(p.validationRequestHash),
|
|
134
|
-
validationChainId: BigInt(p.validationChainId),
|
|
135
|
-
validatorAddress: p.validatorAddress,
|
|
136
|
-
validatorAgentId: p.validatorAgentId,
|
|
137
|
-
minValidationScore: p.minValidationScore,
|
|
138
|
-
validationSubjectHash: (0, utils_1.ensureHexPrefix)(p.validationSubjectHash),
|
|
139
|
-
jobHash: (0, utils_1.ensureHexPrefix)(p.jobHash),
|
|
140
|
-
requiredValidationTag: p.requiredValidationTag,
|
|
141
|
-
},
|
|
142
|
-
]);
|
|
143
|
-
return (0, viem_1.encodeAbiParameters)([{ type: 'uint64' }, { type: 'bytes' }], [BigInt(claims.version), encoded]);
|
|
144
|
-
}
|
|
145
|
-
throw new errors_1.VerificationError(`unsupported guarantee claims version: ${claims.version}`);
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Decode ABI-encoded guarantee claims into a {@link PaymentGuaranteeClaims} object.
|
|
149
|
-
*
|
|
150
|
-
* Accepts either the modern `(uint64 version, bytes innerClaims)` envelope or the legacy
|
|
151
|
-
* unwrapped V1 format (raw 320-byte ABI encoding without an outer envelope).
|
|
152
|
-
*
|
|
153
|
-
* @param data - Hex string or raw bytes of the ABI-encoded claims.
|
|
154
|
-
* @returns Decoded {@link PaymentGuaranteeClaims} with `version` set to `1` or `2`.
|
|
155
|
-
* @throws {@link VerificationError} if the data is too short, the inner length is wrong,
|
|
156
|
-
* or the encoded version number is unsupported.
|
|
157
|
-
*/
|
|
158
|
-
function decodeGuaranteeClaims(data) {
|
|
159
|
-
const hex = normalizeHexBytes(data);
|
|
160
|
-
const byteLen = (hex.length - 2) / 2;
|
|
161
|
-
// Try to decode as unwrapped V1 (legacy)
|
|
162
|
-
if (byteLen === CLAIMS_ENCODED_BYTES) {
|
|
163
|
-
return decodeV1Claims(hex);
|
|
164
|
-
}
|
|
165
|
-
// Decode outer envelope to get version
|
|
166
|
-
if (byteLen < MIN_ENVELOPE_BYTES) {
|
|
167
|
-
throw new errors_1.VerificationError(`unexpected guarantee claims length: ${byteLen} bytes`);
|
|
168
|
-
}
|
|
169
|
-
const [version, wrapped] = (0, viem_1.decodeAbiParameters)([{ type: 'uint64' }, { type: 'bytes' }], hex);
|
|
170
|
-
if (version === 1n) {
|
|
171
|
-
const innerHex = wrapped;
|
|
172
|
-
const innerByteLen = (innerHex.length - 2) / 2;
|
|
173
|
-
if (innerByteLen !== CLAIMS_ENCODED_BYTES) {
|
|
174
|
-
throw new errors_1.VerificationError(`unexpected V1 claims inner length: ${innerByteLen} bytes`);
|
|
175
|
-
}
|
|
176
|
-
return decodeV1Claims(innerHex);
|
|
177
|
-
}
|
|
178
|
-
if (version === 2n) {
|
|
179
|
-
return decodeV2Claims(wrapped);
|
|
180
|
-
}
|
|
181
|
-
throw new errors_1.VerificationError(`unsupported guarantee claims version: ${version}`);
|
|
182
|
-
}
|
|
183
|
-
function decodeV1Claims(encoded) {
|
|
184
|
-
let decoded;
|
|
185
|
-
try {
|
|
186
|
-
decoded = (0, viem_1.decodeAbiParameters)(CLAIM_TYPES, encoded);
|
|
187
|
-
}
|
|
188
|
-
catch (err) {
|
|
189
|
-
throw new errors_1.VerificationError(`failed to decode V1 guarantee claims: ${String(err)}`);
|
|
190
|
-
}
|
|
191
|
-
const [domain, tabId, reqId, user, recipient, amount, totalAmount, asset, timestamp, claimsVersion,] = decoded;
|
|
192
|
-
if (claimsVersion !== 1n) {
|
|
193
|
-
throw new errors_1.VerificationError(`unsupported guarantee claims version: ${claimsVersion}`);
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
domain: (0, viem_1.toBytes)(domain),
|
|
197
|
-
userAddress: user,
|
|
198
|
-
recipientAddress: recipient,
|
|
199
|
-
tabId: (0, utils_1.parseU256)(tabId),
|
|
200
|
-
reqId: (0, utils_1.parseU256)(reqId),
|
|
201
|
-
amount: (0, utils_1.parseU256)(amount),
|
|
202
|
-
totalAmount: (0, utils_1.parseU256)(totalAmount),
|
|
203
|
-
assetAddress: asset,
|
|
204
|
-
timestamp: Number(timestamp),
|
|
205
|
-
version: Number(claimsVersion),
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
function decodeV2Claims(encoded) {
|
|
209
|
-
try {
|
|
210
|
-
const [decoded] = (0, viem_1.decodeAbiParameters)(CLAIM_TYPES_V2_TUPLE, encoded);
|
|
211
|
-
return buildDecodedV2Claims(decoded);
|
|
212
|
-
}
|
|
213
|
-
catch (tupleErr) {
|
|
214
|
-
try {
|
|
215
|
-
const decoded = (0, viem_1.decodeAbiParameters)(CLAIM_TYPES_V2, encoded);
|
|
216
|
-
return buildDecodedV2Claims({
|
|
217
|
-
domain: decoded[0],
|
|
218
|
-
tabId: decoded[1],
|
|
219
|
-
reqId: decoded[2],
|
|
220
|
-
user: decoded[3],
|
|
221
|
-
recipient: decoded[4],
|
|
222
|
-
amount: decoded[5],
|
|
223
|
-
totalAmount: decoded[6],
|
|
224
|
-
asset: decoded[7],
|
|
225
|
-
timestamp: decoded[8],
|
|
226
|
-
claimsVersion: decoded[9],
|
|
227
|
-
validationRegistryAddress: decoded[10],
|
|
228
|
-
validationRequestHash: decoded[11],
|
|
229
|
-
validationChainId: decoded[12],
|
|
230
|
-
validatorAddress: decoded[13],
|
|
231
|
-
validatorAgentId: decoded[14],
|
|
232
|
-
minValidationScore: decoded[15],
|
|
233
|
-
validationSubjectHash: decoded[16],
|
|
234
|
-
jobHash: decoded[17],
|
|
235
|
-
requiredValidationTag: decoded[18],
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
catch (flatErr) {
|
|
239
|
-
throw new errors_1.VerificationError(`failed to decode V2 guarantee claims: ${String(tupleErr)}; fallback decode failed: ${String(flatErr)}`);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
function buildDecodedV2Claims(decoded) {
|
|
244
|
-
const { domain, tabId, reqId, user, recipient, amount, totalAmount, asset, timestamp, claimsVersion, validationRegistryAddress, validationRequestHash, validationChainId, validatorAddress, validatorAgentId, minValidationScore, validationSubjectHash, jobHash, requiredValidationTag, } = decoded;
|
|
245
|
-
if (claimsVersion !== 2n) {
|
|
246
|
-
throw new errors_1.VerificationError(`expected V2 claims version, got: ${claimsVersion}`);
|
|
247
|
-
}
|
|
248
|
-
const validationPolicy = {
|
|
249
|
-
validationRegistryAddress: validationRegistryAddress,
|
|
250
|
-
validationRequestHash: validationRequestHash,
|
|
251
|
-
validationChainId: Number(validationChainId),
|
|
252
|
-
validatorAddress: validatorAddress,
|
|
253
|
-
validatorAgentId: (0, utils_1.parseU256)(validatorAgentId),
|
|
254
|
-
minValidationScore: Number(minValidationScore),
|
|
255
|
-
validationSubjectHash: validationSubjectHash,
|
|
256
|
-
jobHash: jobHash,
|
|
257
|
-
requiredValidationTag: requiredValidationTag,
|
|
258
|
-
};
|
|
259
|
-
return {
|
|
260
|
-
domain: (0, viem_1.toBytes)(domain),
|
|
261
|
-
userAddress: user,
|
|
262
|
-
recipientAddress: recipient,
|
|
263
|
-
tabId: (0, utils_1.parseU256)(tabId),
|
|
264
|
-
reqId: (0, utils_1.parseU256)(reqId),
|
|
265
|
-
amount: (0, utils_1.parseU256)(amount),
|
|
266
|
-
totalAmount: (0, utils_1.parseU256)(totalAmount),
|
|
267
|
-
assetAddress: asset,
|
|
268
|
-
timestamp: Number(timestamp),
|
|
269
|
-
version: Number(claimsVersion),
|
|
270
|
-
validationPolicy,
|
|
271
|
-
};
|
|
272
|
-
}
|
package/dist/src/http.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type FetchFn = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
2
|
-
type DecodeErrorFactory = (message: string, response: Response) => Error;
|
|
3
|
-
type HttpErrorFactory = (message: string, response: Response, body: unknown) => Error;
|
|
4
|
-
export declare function normalizeBaseUrl(endpoint: string): string;
|
|
5
|
-
export declare function extractErrorMessage(payload: unknown): string;
|
|
6
|
-
export declare function requestJson<T>(fetchFn: FetchFn, url: string, init: RequestInit, options: {
|
|
7
|
-
decodeError: DecodeErrorFactory;
|
|
8
|
-
httpError: HttpErrorFactory;
|
|
9
|
-
allowEmptyOk?: boolean;
|
|
10
|
-
}): Promise<T>;
|
|
11
|
-
export {};
|
package/dist/src/http.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeBaseUrl = normalizeBaseUrl;
|
|
4
|
-
exports.extractErrorMessage = extractErrorMessage;
|
|
5
|
-
exports.requestJson = requestJson;
|
|
6
|
-
function normalizeBaseUrl(endpoint) {
|
|
7
|
-
return endpoint.endsWith('/') ? endpoint.slice(0, -1) : endpoint;
|
|
8
|
-
}
|
|
9
|
-
function extractErrorMessage(payload) {
|
|
10
|
-
if (payload && typeof payload === 'object') {
|
|
11
|
-
const record = payload;
|
|
12
|
-
const error = record.error;
|
|
13
|
-
const msg = record.message;
|
|
14
|
-
return ((typeof error === 'string' && error) ||
|
|
15
|
-
(typeof msg === 'string' && msg) ||
|
|
16
|
-
JSON.stringify(record, (_k, v) => v));
|
|
17
|
-
}
|
|
18
|
-
if (typeof payload === 'string' && payload.trim()) {
|
|
19
|
-
return payload.trim();
|
|
20
|
-
}
|
|
21
|
-
return 'unknown error';
|
|
22
|
-
}
|
|
23
|
-
async function requestJson(fetchFn, url, init, options) {
|
|
24
|
-
const response = await fetchFn(url, init);
|
|
25
|
-
let text = '';
|
|
26
|
-
try {
|
|
27
|
-
text = await response.text();
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
throw options.decodeError(`invalid response from ${response.url}: ${String(err)}`, response);
|
|
31
|
-
}
|
|
32
|
-
let payload = null;
|
|
33
|
-
let parsed = false;
|
|
34
|
-
let parseError;
|
|
35
|
-
if (text) {
|
|
36
|
-
try {
|
|
37
|
-
payload = JSON.parse(text);
|
|
38
|
-
parsed = true;
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
payload = text;
|
|
42
|
-
parseError = err;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!response.ok) {
|
|
46
|
-
const message = `${response.status}: ${extractErrorMessage(payload)}`;
|
|
47
|
-
throw options.httpError(message, response, payload);
|
|
48
|
-
}
|
|
49
|
-
if (!text && !options.allowEmptyOk) {
|
|
50
|
-
throw options.decodeError(`invalid JSON response from ${response.url}: empty response body`, response);
|
|
51
|
-
}
|
|
52
|
-
if (text && !parsed) {
|
|
53
|
-
const detail = parseError instanceof Error ? parseError.message : String(parseError);
|
|
54
|
-
throw options.decodeError(`invalid JSON response from ${response.url}: ${detail}`, response);
|
|
55
|
-
}
|
|
56
|
-
return payload;
|
|
57
|
-
}
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export * from './errors';
|
|
2
|
-
export * from './constants';
|
|
3
|
-
export * from './networks';
|
|
4
|
-
export * from './config';
|
|
5
|
-
export * from './utils';
|
|
6
|
-
export * from './models';
|
|
7
|
-
export * from './payment';
|
|
8
|
-
export * from './validation';
|
|
9
|
-
export * from './signing';
|
|
10
|
-
export * from './rpc';
|
|
11
|
-
export * from './auth';
|
|
12
|
-
export * from './contract';
|
|
13
|
-
export * from './guarantee';
|
|
14
|
-
export * from './bls';
|
|
15
|
-
export * from './x402/index';
|
|
16
|
-
export * from './client';
|
|
17
|
-
export * from './wallet';
|
package/dist/src/index.js
DELETED
|
@@ -1,33 +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("./constants"), exports);
|
|
19
|
-
__exportStar(require("./networks"), exports);
|
|
20
|
-
__exportStar(require("./config"), exports);
|
|
21
|
-
__exportStar(require("./utils"), exports);
|
|
22
|
-
__exportStar(require("./models"), exports);
|
|
23
|
-
__exportStar(require("./payment"), exports);
|
|
24
|
-
__exportStar(require("./validation"), exports);
|
|
25
|
-
__exportStar(require("./signing"), exports);
|
|
26
|
-
__exportStar(require("./rpc"), exports);
|
|
27
|
-
__exportStar(require("./auth"), exports);
|
|
28
|
-
__exportStar(require("./contract"), exports);
|
|
29
|
-
__exportStar(require("./guarantee"), exports);
|
|
30
|
-
__exportStar(require("./bls"), exports);
|
|
31
|
-
__exportStar(require("./x402/index"), exports);
|
|
32
|
-
__exportStar(require("./client"), exports);
|
|
33
|
-
__exportStar(require("./wallet"), exports);
|