payid 0.5.9 → 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/chunk-AUW7WDAB.js +198 -0
- package/dist/{chunk-SSO66YQI.js → chunk-E6VQETBC.js} +13 -0
- package/dist/{chunk-AYJYFAXJ.js → chunk-ESTGPUEQ.js} +24 -21
- package/dist/{chunk-ROBSNIIZ.js → chunk-EZ3BGZ7G.js} +25 -16
- package/dist/chunk-FZNMDGVK.js +24 -0
- package/dist/chunk-HKHRYRD6.js +752 -0
- package/dist/chunk-X7NYQ47Y.js +27 -0
- package/dist/chunk-XMUHMJRD.js +30 -0
- package/dist/context/index.d.ts +3 -2
- package/dist/context.v1-C1m-tz0o.d.ts +39 -0
- package/dist/context.v2-DIzPotmW.d.ts +37 -0
- package/dist/core/client/index.d.ts +5 -4
- package/dist/core/client/index.js +9 -5
- package/dist/core/server/index.d.ts +4 -3
- package/dist/core/server/index.js +7 -4
- package/dist/{index-2JCvey4-.d.ts → index-CDnE3SGM.d.ts} +18 -3
- package/dist/index-CsynGAGv.d.ts +53 -0
- package/dist/{index-Dj9IEios.d.ts → index-CubM9whW.d.ts} +4 -17
- package/dist/{index-C1DHMQA0.d.ts → index-DSxDlF9J.d.ts} +45 -68
- package/dist/{index-BEvnPzzt.d.ts → index-Dm2VdDEB.d.ts} +2 -1
- package/dist/index-G_1SiZJo.d.ts +104 -0
- package/dist/index.d.ts +407 -72
- package/dist/index.js +582 -77
- package/dist/issuer/index.d.ts +3 -2
- package/dist/issuer/index.js +4 -1
- package/dist/rule/index.d.ts +2 -2
- package/dist/rule/index.js +4 -3
- package/dist/rule-a_5ed-93.d.ts +39 -0
- package/dist/sessionPolicy/index.d.ts +3 -3
- package/dist/sessionPolicy/index.js +17 -6
- package/dist/types-D2o6XS7a.d.ts +66 -0
- package/dist/types-i4eTkhWa.d.ts +50 -0
- package/package.json +22 -9
- package/src/rule/engine/rule_engine.wasm +0 -0
- package/dist/chunk-IQNCMOIE.js +0 -47
- package/dist/chunk-MXKZJKXE.js +0 -33
- package/dist/chunk-PAJYP7JI.js +0 -308
- package/dist/chunk-QC24X74O.js +0 -41
- package/dist/index-BPJ_oOfy.d.ts +0 -81
- package/dist/index-BQQnMG2H.d.ts +0 -114
- package/dist/types-B8pJQdMQ.d.ts +0 -26
- package/dist/types-BmMf7udp.d.ts +0 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,46 +1,122 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { U as UserOperation } from './index-
|
|
4
|
-
export { i as server } from './index-
|
|
1
|
+
import { P as PayIDClient$1 } from './index-CsynGAGv.js';
|
|
2
|
+
export { i as client } from './index-CsynGAGv.js';
|
|
3
|
+
import { Z as ZGStorage, P as PayIDServer$1, U as UserOperation } from './index-DSxDlF9J.js';
|
|
4
|
+
export { i as server, z as storage } from './index-DSxDlF9J.js';
|
|
5
5
|
import { ethers } from 'ethers';
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
|
|
9
|
-
export { i as
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
import { R as ResolverOptions, e as RuleSource, c as RuleResult, a as DecisionProof } from './types-i4eTkhWa.js';
|
|
7
|
+
export { D as DecisionPayload, b as RuleDecisionDebug, d as RuleResultDebug, f as RuleTraceEntry } from './types-i4eTkhWa.js';
|
|
8
|
+
import { b as RuleConfig } from './rule-a_5ed-93.js';
|
|
9
|
+
export { A as AnyRule, M as MultiConditionRule, N as NestedRule, R as Rule, a as RuleCondition, S as SimpleRule, i as isMultiConditionRule, c as isNestedRule, d as isSimpleRule } from './rule-a_5ed-93.js';
|
|
10
|
+
import { R as RuleContext } from './context.v1-C1m-tz0o.js';
|
|
11
|
+
export { C as ContextV1, P as PayIdContext, T as TxContext } from './context.v1-C1m-tz0o.js';
|
|
12
|
+
import { S as SessionPolicyV2 } from './types-D2o6XS7a.js';
|
|
13
|
+
import { A as Attestation } from './context.v2-DIzPotmW.js';
|
|
14
|
+
export { C as ContextV2, E as EnvContext, O as OracleContext, R as RiskContext, S as StateContext } from './context.v2-DIzPotmW.js';
|
|
15
|
+
export { i as sessionPolicy } from './index-G_1SiZJo.js';
|
|
16
|
+
export { i as rule } from './index-CubM9whW.js';
|
|
17
|
+
export { i as issuer } from './index-CDnE3SGM.js';
|
|
18
|
+
export { i as context } from './index-Dm2VdDEB.js';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Create a client-safe PayID instance.
|
|
22
|
+
*
|
|
23
|
+
* - Safe for browser, mobile, and edge runtimes.
|
|
24
|
+
* - Signer is injected per-call in `evaluateAndProve`.
|
|
25
|
+
* - WASM rule engine with automatic TS fallback.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // Browser / React
|
|
30
|
+
* const client = createPayIDClient({ debugTrace: true });
|
|
31
|
+
* const { result, proof } = await client.evaluateAndProve({
|
|
32
|
+
* ..., signer: walletSigner
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function createPayIDClient(params?: {
|
|
37
|
+
wasm?: Uint8Array;
|
|
38
|
+
debugTrace?: boolean;
|
|
39
|
+
resolverOptions?: ResolverOptions;
|
|
40
|
+
}): PayIDClient$1;
|
|
41
|
+
/**
|
|
42
|
+
* Create a server-side PayID instance.
|
|
43
|
+
*
|
|
44
|
+
* - For backends, bundlers, and relayers only — never ship to browser.
|
|
45
|
+
* - Signer is bound at construction time (server wallet).
|
|
46
|
+
* - Supports Context V2 with `trustedIssuers` enforcement.
|
|
47
|
+
* - Can build ERC-4337 UserOperations.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* // Backend / bundler
|
|
52
|
+
* const server = createPayIDServer({
|
|
53
|
+
* signer: serverWallet,
|
|
54
|
+
* trustedIssuers: new Set([TIME_ISSUER, RISK_ISSUER]),
|
|
55
|
+
* });
|
|
56
|
+
* const { result, proof } = await server.evaluateAndProve({ ... });
|
|
57
|
+
* const userOp = server.buildUserOperation({ proof, paymentType: "erc20", ... });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare function createPayIDServer(params: {
|
|
61
|
+
signer: ethers.Signer;
|
|
62
|
+
wasm?: Uint8Array;
|
|
63
|
+
debugTrace?: boolean;
|
|
64
|
+
trustedIssuers?: Set<string>;
|
|
65
|
+
storage?: ZGStorage;
|
|
66
|
+
resolverOptions?: ResolverOptions;
|
|
67
|
+
}): PayIDServer$1;
|
|
68
|
+
/**
|
|
69
|
+
* Alias for `createPayIDClient` — backwards-compatible entry point.
|
|
70
|
+
* Prefer `createPayIDClient` or `createPayIDServer` for clarity.
|
|
71
|
+
*/
|
|
72
|
+
declare function createPayID(params?: {
|
|
73
|
+
wasm?: Uint8Array;
|
|
74
|
+
debugTrace?: boolean;
|
|
75
|
+
resolverOptions?: ResolverOptions;
|
|
76
|
+
}): PayIDClient$1;
|
|
12
77
|
|
|
13
78
|
interface PayIDClient {
|
|
14
79
|
/**
|
|
15
|
-
* Pure rule evaluation — client-safe
|
|
80
|
+
* Pure rule evaluation — no signing, client-safe.
|
|
16
81
|
*/
|
|
17
82
|
evaluate(context: RuleContext, rule: RuleConfig | RuleSource): Promise<RuleResult>;
|
|
18
83
|
/**
|
|
19
|
-
* Evaluate + generate EIP-712 Decision Proof
|
|
20
|
-
*
|
|
84
|
+
* Evaluate rule + generate EIP-712 Decision Proof.
|
|
85
|
+
* Signer (wallet) diinjeksikan per-call — cocok untuk browser.
|
|
21
86
|
*/
|
|
22
87
|
evaluateAndProve(params: {
|
|
23
88
|
context: RuleContext;
|
|
89
|
+
/** Rule yang diambil dari chain (authority rule). */
|
|
24
90
|
authorityRule: RuleConfig | RuleSource;
|
|
91
|
+
/** Override rule yang dipakai untuk evaluasi (opsional). */
|
|
25
92
|
evaluationRule?: RuleConfig;
|
|
93
|
+
/** Session policy V2 (Channel A — receiver sign constraints). */
|
|
94
|
+
sessionPolicyV2?: SessionPolicyV2;
|
|
26
95
|
payId: string;
|
|
27
96
|
payer: string;
|
|
28
97
|
receiver: string;
|
|
29
98
|
asset: string;
|
|
30
99
|
amount: bigint;
|
|
100
|
+
/** Wallet yang menandatangani proof. */
|
|
31
101
|
signer: ethers.Signer;
|
|
32
102
|
verifyingContract: string;
|
|
33
103
|
ruleAuthority: string;
|
|
104
|
+
/** Override ruleSetHash di proof (untuk combined rules). */
|
|
105
|
+
ruleSetHashOverride?: string;
|
|
34
106
|
ttlSeconds?: number;
|
|
107
|
+
chainId: number;
|
|
108
|
+
blockTimestamp: number;
|
|
109
|
+
/** EAS attestation UIDs untuk attestation-gated payments. */
|
|
110
|
+
attestationUIDs?: string[];
|
|
35
111
|
}): Promise<{
|
|
36
112
|
result: RuleResult;
|
|
37
|
-
proof:
|
|
113
|
+
proof: DecisionProof | null;
|
|
38
114
|
}>;
|
|
39
115
|
}
|
|
40
116
|
interface PayIDServer {
|
|
41
117
|
/**
|
|
42
|
-
* Evaluate + generate proof
|
|
43
|
-
* Signer sudah di-inject
|
|
118
|
+
* Evaluate rule + generate proof.
|
|
119
|
+
* Signer sudah di-inject di constructor — tidak ada signer per-call.
|
|
44
120
|
*/
|
|
45
121
|
evaluateAndProve(params: {
|
|
46
122
|
context: RuleContext;
|
|
@@ -56,87 +132,346 @@ interface PayIDServer {
|
|
|
56
132
|
ttlSeconds?: number;
|
|
57
133
|
chainId: number;
|
|
58
134
|
blockTimestamp: number;
|
|
135
|
+
attestationUIDs?: string[];
|
|
59
136
|
}): Promise<{
|
|
60
137
|
result: RuleResult;
|
|
61
|
-
proof:
|
|
138
|
+
proof: DecisionProof | null;
|
|
62
139
|
}>;
|
|
63
140
|
/**
|
|
64
|
-
* Build ERC-4337 UserOperation dari Decision Proof
|
|
65
|
-
*
|
|
141
|
+
* Build ERC-4337 UserOperation dari Decision Proof.
|
|
142
|
+
* Dipakai oleh bundler/relayer untuk kirim transaksi.
|
|
66
143
|
*/
|
|
67
144
|
buildUserOperation(params: {
|
|
68
|
-
proof:
|
|
145
|
+
proof: DecisionProof;
|
|
69
146
|
smartAccount: string;
|
|
70
147
|
nonce: string;
|
|
71
|
-
gas:
|
|
148
|
+
gas: {
|
|
149
|
+
callGasLimit: string;
|
|
150
|
+
verificationGasLimit: string;
|
|
151
|
+
preVerificationGas: string;
|
|
152
|
+
maxFeePerGas: string;
|
|
153
|
+
maxPriorityFeePerGas: string;
|
|
154
|
+
};
|
|
72
155
|
targetContract: string;
|
|
73
156
|
paymasterAndData?: string;
|
|
74
157
|
attestationUIDs?: string[];
|
|
158
|
+
paymentType?: "eth" | "erc20";
|
|
75
159
|
}): UserOperation;
|
|
76
160
|
}
|
|
77
161
|
|
|
162
|
+
interface ReverseResolutionResult {
|
|
163
|
+
payId: string;
|
|
164
|
+
owner: string;
|
|
165
|
+
activeRuleHash?: string;
|
|
166
|
+
metadata?: Record<string, unknown>;
|
|
167
|
+
}
|
|
168
|
+
interface ReverseResolutionOptions extends ResolverOptions {
|
|
169
|
+
registryUrl?: string;
|
|
170
|
+
timeoutMs?: number;
|
|
171
|
+
}
|
|
78
172
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* ## Responsibility
|
|
82
|
-
*
|
|
83
|
-
* - Holds the WASM binary used for rule execution
|
|
84
|
-
* - Defines the trust boundary for context attestation verification
|
|
85
|
-
* - Acts as the primary entry point for PayID rule evaluation
|
|
173
|
+
* Reverse resolve a wallet address to its registered PayID.
|
|
86
174
|
*
|
|
87
|
-
*
|
|
175
|
+
* Queries the 0G Storage reverse index or a fallback registry HTTP endpoint.
|
|
88
176
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* const { payId } = await reverseResolvePayID(
|
|
180
|
+
* "0x1234...",
|
|
181
|
+
* { registryUrl: "https://registry.pay.id/v1" }
|
|
182
|
+
* );
|
|
183
|
+
* console.log(payId); // "alice.pay.id"
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare function reverseResolvePayID(address: string, options?: ReverseResolutionOptions): Promise<ReverseResolutionResult | null>;
|
|
187
|
+
/**
|
|
188
|
+
* Batch reverse resolve multiple addresses at once.
|
|
189
|
+
* Useful for enriching contact lists or transaction history.
|
|
190
|
+
*/
|
|
191
|
+
declare function batchReverseResolve(addresses: string[], options?: ReverseResolutionOptions): Promise<Map<string, ReverseResolutionResult | null>>;
|
|
192
|
+
|
|
193
|
+
interface CachedRule {
|
|
194
|
+
key: string;
|
|
195
|
+
config: Record<string, unknown>;
|
|
196
|
+
timestamp: number;
|
|
197
|
+
sourceUri: string;
|
|
198
|
+
sizeBytes: number;
|
|
199
|
+
}
|
|
200
|
+
declare const ruleCache: {
|
|
201
|
+
get: (key: string) => Promise<CachedRule | null>;
|
|
202
|
+
set: (value: CachedRule) => Promise<void>;
|
|
203
|
+
delete: (key: string) => Promise<void>;
|
|
204
|
+
getAll: () => Promise<CachedRule[]>;
|
|
205
|
+
clear: () => Promise<void>;
|
|
206
|
+
};
|
|
207
|
+
interface CachedContact {
|
|
208
|
+
payId: string;
|
|
209
|
+
address: string;
|
|
210
|
+
name: string;
|
|
211
|
+
avatar?: string;
|
|
212
|
+
addedAt: number;
|
|
213
|
+
note?: string;
|
|
214
|
+
reputation?: number;
|
|
215
|
+
isBlacklisted?: boolean;
|
|
216
|
+
}
|
|
217
|
+
declare const contactCache: {
|
|
218
|
+
get: (payId: string) => Promise<CachedContact | null>;
|
|
219
|
+
set: (value: CachedContact) => Promise<void>;
|
|
220
|
+
delete: (payId: string) => Promise<void>;
|
|
221
|
+
getAll: () => Promise<CachedContact[]>;
|
|
222
|
+
findByAddress: (address: string) => Promise<CachedContact[]>;
|
|
223
|
+
findByName: (name: string) => Promise<CachedContact[]>;
|
|
224
|
+
};
|
|
225
|
+
type DraftStatus = "draft" | "queued" | "syncing" | "sent" | "failed";
|
|
226
|
+
interface DraftPayment {
|
|
227
|
+
id?: number;
|
|
228
|
+
toPayId: string;
|
|
229
|
+
toAddress?: string;
|
|
230
|
+
amount: string;
|
|
231
|
+
asset: string;
|
|
232
|
+
note?: string;
|
|
233
|
+
status: DraftStatus;
|
|
234
|
+
createdAt: number;
|
|
235
|
+
updatedAt: number;
|
|
236
|
+
proofHash?: string;
|
|
237
|
+
txHash?: string;
|
|
238
|
+
error?: string;
|
|
239
|
+
}
|
|
240
|
+
declare const draftCache: {
|
|
241
|
+
get: (id: number) => Promise<DraftPayment | null>;
|
|
242
|
+
set: (value: DraftPayment) => Promise<void>;
|
|
243
|
+
delete: (id: number) => Promise<void>;
|
|
244
|
+
getAll: () => Promise<DraftPayment[]>;
|
|
245
|
+
getPending: () => Promise<DraftPayment[]>;
|
|
246
|
+
getFailed: () => Promise<DraftPayment[]>;
|
|
247
|
+
};
|
|
248
|
+
interface CachedTx {
|
|
249
|
+
txHash: string;
|
|
250
|
+
from: string;
|
|
251
|
+
to: string;
|
|
252
|
+
amount: string;
|
|
253
|
+
asset: string;
|
|
254
|
+
payId?: string;
|
|
255
|
+
timestamp: number;
|
|
256
|
+
status: "pending" | "confirmed" | "failed";
|
|
257
|
+
fee?: string;
|
|
258
|
+
blockNumber?: number;
|
|
259
|
+
}
|
|
260
|
+
declare const historyCache: {
|
|
261
|
+
get: (txHash: string) => Promise<CachedTx | null>;
|
|
262
|
+
set: (value: CachedTx) => Promise<void>;
|
|
263
|
+
delete: (txHash: string) => Promise<void>;
|
|
264
|
+
getAll: () => Promise<CachedTx[]>;
|
|
265
|
+
};
|
|
266
|
+
interface CacheStats {
|
|
267
|
+
rules: number;
|
|
268
|
+
contacts: number;
|
|
269
|
+
drafts: number;
|
|
270
|
+
history: number;
|
|
271
|
+
totalSizeEstimate: number;
|
|
272
|
+
}
|
|
273
|
+
declare function getCacheStats(): Promise<CacheStats>;
|
|
274
|
+
declare function clearAllCache(): Promise<void>;
|
|
275
|
+
|
|
276
|
+
interface DeployRuleOptions {
|
|
277
|
+
ruleFile: string;
|
|
278
|
+
ipfsGateway?: string;
|
|
279
|
+
ruleAuthorityAddress: string;
|
|
280
|
+
chainId: number;
|
|
281
|
+
privateKey: string;
|
|
282
|
+
rpcUrl: string;
|
|
283
|
+
outputJson?: string;
|
|
284
|
+
}
|
|
285
|
+
interface DeployRuleResult {
|
|
286
|
+
ruleHash: string;
|
|
287
|
+
ipfsCid?: string;
|
|
288
|
+
ruleId?: string;
|
|
289
|
+
txHash: string;
|
|
290
|
+
status: "success" | "error";
|
|
291
|
+
error?: string;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Deploy a rule JSON file to IPFS and register it with RuleAuthority.
|
|
101
295
|
*
|
|
102
|
-
* @
|
|
103
|
-
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```bash
|
|
298
|
+
* npx payid deploy-rule ./my-rule.json \
|
|
299
|
+
* --authority 0x1234... \
|
|
300
|
+
* --chain 31337 \
|
|
301
|
+
* --key $PRIVATE_KEY \
|
|
302
|
+
* --rpc http://127.0.0.1:8545
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
declare function deployRule(options: DeployRuleOptions): Promise<DeployRuleResult>;
|
|
306
|
+
|
|
307
|
+
interface VerifyProofOptions {
|
|
308
|
+
txHash: string;
|
|
309
|
+
rpcUrl: string;
|
|
310
|
+
payIDVerifierAddress: string;
|
|
311
|
+
expectedSigner?: string;
|
|
312
|
+
}
|
|
313
|
+
interface VerifyProofResult {
|
|
314
|
+
valid: boolean;
|
|
315
|
+
status: "verified" | "invalid" | "not_found" | "error";
|
|
316
|
+
details?: {
|
|
317
|
+
payId: string;
|
|
318
|
+
payer: string;
|
|
319
|
+
receiver: string;
|
|
320
|
+
amount: string;
|
|
321
|
+
asset: string;
|
|
322
|
+
decision: "ALLOW" | "REJECT";
|
|
323
|
+
timestamp: number;
|
|
324
|
+
nonce: string;
|
|
325
|
+
ruleAuthority: string;
|
|
326
|
+
};
|
|
327
|
+
error?: string;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Verify a Decision Proof on-chain by txHash.
|
|
104
331
|
*
|
|
105
|
-
* @
|
|
106
|
-
*
|
|
332
|
+
* @example
|
|
333
|
+
* ```bash
|
|
334
|
+
* npx payid verify-proof 0xabc123... \
|
|
335
|
+
* --verifier 0x5678... \
|
|
336
|
+
* --rpc http://127.0.0.1:8545
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
declare function verifyProof(options: VerifyProofOptions): Promise<VerifyProofResult>;
|
|
340
|
+
|
|
341
|
+
declare function verifyAttestation(payload: object, proof: Attestation, trustedIssuers: Set<string>): void;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Extended context for fiat payment rails.
|
|
345
|
+
* The WASM engine evaluates JSON loosely, so we use Record<string,any>
|
|
346
|
+
* for tx fields beyond the standard RuleContext shape.
|
|
347
|
+
*/
|
|
348
|
+
type FiatRuleContext = Omit<RuleContext, "tx" | "env"> & {
|
|
349
|
+
tx: Record<string, any>;
|
|
350
|
+
env: {
|
|
351
|
+
timestamp: number;
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* QRIS / fiat payment payload from a bank app or PSP.
|
|
356
|
+
*/
|
|
357
|
+
interface QRISPayload {
|
|
358
|
+
/** Transaction amount in smallest unit (e.g. IDR satang) */
|
|
359
|
+
amount: string;
|
|
360
|
+
/** ISO-4217 currency code, e.g. "IDR", "USD" */
|
|
361
|
+
currency: string;
|
|
362
|
+
/** Merchant ID or identifier */
|
|
363
|
+
merchantId: string;
|
|
364
|
+
/** Payment Service Provider code, e.g. "BANK_ABC" */
|
|
365
|
+
pspCode: string;
|
|
366
|
+
/** Optional POS terminal ID */
|
|
367
|
+
terminalId?: string;
|
|
368
|
+
/** Optional Merchant Category Code (ISO 18245) */
|
|
369
|
+
mcc?: string;
|
|
370
|
+
/** Optional linked wallet address */
|
|
371
|
+
userWallet?: string;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Result of evaluating a fiat payment against merchant rules.
|
|
375
|
+
*/
|
|
376
|
+
interface FiatEvaluationResult {
|
|
377
|
+
/** Whether the payment is allowed */
|
|
378
|
+
allowed: boolean;
|
|
379
|
+
/** EIP-712 Decision Proof (present when allowed) */
|
|
380
|
+
proof?: DecisionProof;
|
|
381
|
+
/** Rejection reason (present when not allowed) */
|
|
382
|
+
reason?: string;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* FiatAdapter — bridge between traditional payment rails (QRIS, SWIFT, etc.)
|
|
386
|
+
* and the PAY.ID policy engine.
|
|
107
387
|
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
388
|
+
* The adapter normalizes bank/PSP payloads into PAY.ID RuleContext,
|
|
389
|
+
* evaluates merchant rules, and returns a DecisionProof for bank verification.
|
|
110
390
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```ts
|
|
393
|
+
* const adapter = new FiatAdapter();
|
|
114
394
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
395
|
+
* const { allowed, proof, reason } = await adapter.evaluatePayment(
|
|
396
|
+
* {
|
|
397
|
+
* amount: '150000',
|
|
398
|
+
* currency: 'IDR',
|
|
399
|
+
* merchantId: 'MID123',
|
|
400
|
+
* pspCode: 'BANK_ABC',
|
|
401
|
+
* },
|
|
402
|
+
* 'https://rules.example.com/merchant-rules.json',
|
|
403
|
+
* walletSigner,
|
|
404
|
+
* {
|
|
405
|
+
* verifyingContract: '0x...',
|
|
406
|
+
* ruleAuthority: '0x...',
|
|
407
|
+
* chainId: 31337,
|
|
408
|
+
* }
|
|
409
|
+
* );
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
declare class FiatAdapter {
|
|
413
|
+
private readonly client;
|
|
414
|
+
constructor(debugTrace?: boolean, wasm?: Uint8Array);
|
|
415
|
+
/**
|
|
416
|
+
* Evaluate a fiat payment payload against merchant rules.
|
|
417
|
+
*/
|
|
418
|
+
evaluatePayment(payload: QRISPayload, merchantRuleURI: string | RuleSource, signer: ethers.Signer, contractConfig: {
|
|
419
|
+
verifyingContract: string;
|
|
420
|
+
ruleAuthority: string;
|
|
421
|
+
chainId: number;
|
|
422
|
+
}): Promise<FiatEvaluationResult>;
|
|
423
|
+
/**
|
|
424
|
+
* Build a PAY.ID RuleContext from a fiat payload without evaluating.
|
|
425
|
+
* Useful for previewing or debugging rule logic.
|
|
426
|
+
*/
|
|
427
|
+
buildContext(payload: QRISPayload): FiatRuleContext;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Compute USD equivalent of a token amount from a Chainlink-style price feed.
|
|
117
432
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
433
|
+
* @param amount Raw token amount (in token's smallest unit, e.g. wei for ETH, micro-USDC)
|
|
434
|
+
* @param decimals Token decimals (e.g. 18 for ETH, 6 for USDC)
|
|
435
|
+
* @param priceInUsd Price from oracle in USD with 8 decimals (e.g. 350000000000 = $3500.00)
|
|
436
|
+
* @returns USD value with 8 decimals
|
|
122
437
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*
|
|
130
|
-
* ]);
|
|
438
|
+
* @example
|
|
439
|
+
* computeTxValueUsd(1_000_000n, 6, 100000000n) // 1 USDC @ $1.00 → 100000000n ($1.00)
|
|
440
|
+
* computeTxValueUsd(1000000000000000000n, 18, 350000000000n) // 1 ETH @ $3500 → 35000000000000000000n ($3500.00)
|
|
441
|
+
*/
|
|
442
|
+
declare function computeTxValueUsd(amount: bigint, decimals: number, priceInUsd: bigint): bigint;
|
|
443
|
+
/**
|
|
444
|
+
* Format a USD value (8 decimals) to human-readable string.
|
|
131
445
|
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
446
|
+
* @param usdValue USD amount with 8 decimals
|
|
447
|
+
* @returns Formatted string like "$45.00"
|
|
134
448
|
*/
|
|
135
|
-
declare function
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
449
|
+
declare function formatUsdValue(usdValue: bigint): string;
|
|
450
|
+
/**
|
|
451
|
+
* Minimal Chainlink AggregatorV3 ABI for fetching price off-chain.
|
|
452
|
+
*/
|
|
453
|
+
declare const CHAINLINK_AGGREGATOR_ABI: readonly [{
|
|
454
|
+
readonly name: "latestRoundData";
|
|
455
|
+
readonly type: "function";
|
|
456
|
+
readonly stateMutability: "view";
|
|
457
|
+
readonly inputs: readonly [];
|
|
458
|
+
readonly outputs: readonly [{
|
|
459
|
+
readonly name: "roundId";
|
|
460
|
+
readonly type: "uint80";
|
|
461
|
+
}, {
|
|
462
|
+
readonly name: "answer";
|
|
463
|
+
readonly type: "int256";
|
|
464
|
+
}, {
|
|
465
|
+
readonly name: "startedAt";
|
|
466
|
+
readonly type: "uint256";
|
|
467
|
+
}, {
|
|
468
|
+
readonly name: "updatedAt";
|
|
469
|
+
readonly type: "uint256";
|
|
470
|
+
}, {
|
|
471
|
+
readonly name: "answeredInRound";
|
|
472
|
+
readonly type: "uint80";
|
|
473
|
+
}];
|
|
474
|
+
}];
|
|
140
475
|
|
|
141
476
|
/**
|
|
142
477
|
* @module eas
|
|
@@ -203,4 +538,4 @@ declare namespace eas {
|
|
|
203
538
|
export { type eas_EASAttestation as EASAttestation, eas_EASClient as EASClient, type eas_EASClientOptions as EASClientOptions, eas_EAS_ADDRESSES as EAS_ADDRESSES };
|
|
204
539
|
}
|
|
205
540
|
|
|
206
|
-
export { type PayIDClient, type PayIDServer, createPayID, eas };
|
|
541
|
+
export { Attestation, CHAINLINK_AGGREGATOR_ABI, type CacheStats, type CachedContact, type CachedRule, type CachedTx, DecisionProof, type DeployRuleOptions, type DeployRuleResult, type DraftPayment, type DraftStatus, FiatAdapter, type FiatEvaluationResult, type PayIDClient, type PayIDServer, type QRISPayload, ResolverOptions, type ReverseResolutionOptions, type ReverseResolutionResult, RuleConfig, RuleContext, RuleResult, type VerifyProofOptions, type VerifyProofResult, batchReverseResolve, clearAllCache, computeTxValueUsd, contactCache, createPayID, createPayIDClient, createPayIDServer, deployRule, draftCache, eas, formatUsdValue, getCacheStats, historyCache, reverseResolvePayID, ruleCache, verifyAttestation, verifyProof };
|