payid 0.3.9 → 0.4.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/dist/index.d.ts +689 -18
- package/dist/index.js +780 -52
- package/package.json +3 -3
- package/dist/chunk-5ZEKI5Y2.js +0 -18
- package/dist/chunk-7U3P7XJE.js +0 -67
- package/dist/chunk-AOKLY2QN.js +0 -24
- package/dist/chunk-ATWJEWZH.js +0 -47
- package/dist/chunk-JJEWYFOV.js +0 -42
- package/dist/chunk-JRVCGSKK.js +0 -30
- package/dist/chunk-METOE7DV.js +0 -264
- package/dist/chunk-MXKZJKXE.js +0 -33
- package/dist/chunk-QYH3FNQ4.js +0 -19
- package/dist/chunk-R5U7XKVJ.js +0 -16
- package/dist/chunk-RCXMRX4F.js +0 -54
- package/dist/chunk-SIHQPH55.js +0 -139
- package/dist/chunk-UBGZH6HB.js +0 -90
- package/dist/context/index.d.ts +0 -3
- package/dist/context/index.js +0 -8
- package/dist/core/client/index.d.ts +0 -5
- package/dist/core/client/index.js +0 -12
- package/dist/core/server/index.d.ts +0 -4
- package/dist/core/server/index.js +0 -9
- package/dist/index-2JCvey4-.d.ts +0 -23
- package/dist/index-BEvnPzzt.d.ts +0 -160
- package/dist/index-C7vziL_Z.d.ts +0 -150
- package/dist/index-CiTDNVSZ.d.ts +0 -158
- package/dist/index-DuOeYzN2.d.ts +0 -118
- package/dist/index-on2SYkvq.d.ts +0 -114
- package/dist/issuer/index.d.ts +0 -3
- package/dist/issuer/index.js +0 -16
- package/dist/rule/index.d.ts +0 -2
- package/dist/rule/index.js +0 -15
- package/dist/sessionPolicy/index.d.ts +0 -4
- package/dist/sessionPolicy/index.js +0 -13
- package/dist/types-B8pJQdMQ.d.ts +0 -26
- package/dist/types-DKt-zH0P.d.ts +0 -15
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import * as payid_types from 'payid-types';
|
|
2
|
+
import { RuleContext, RuleConfig, RuleResult, AnyRule, EnvContext, OracleContext, RiskContext, StateContext, Attestation, ContextV1, ContextV2 } from 'payid-types';
|
|
3
|
+
import { ethers, Wallet } from 'ethers';
|
|
4
|
+
|
|
5
|
+
interface RuleSource {
|
|
6
|
+
uri: string;
|
|
7
|
+
hash?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface UserOperation {
|
|
11
|
+
sender: string;
|
|
12
|
+
nonce: string;
|
|
13
|
+
initCode: string;
|
|
14
|
+
callData: string;
|
|
15
|
+
callGasLimit: string;
|
|
16
|
+
verificationGasLimit: string;
|
|
17
|
+
preVerificationGas: string;
|
|
18
|
+
maxFeePerGas: string;
|
|
19
|
+
maxPriorityFeePerGas: string;
|
|
20
|
+
paymasterAndData: string;
|
|
21
|
+
signature: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface PayIDClient$1 {
|
|
14
25
|
/**
|
|
15
26
|
* Pure rule evaluation — client-safe, no signing
|
|
16
27
|
*/
|
|
@@ -37,7 +48,7 @@ interface PayIDClient {
|
|
|
37
48
|
proof: any | null;
|
|
38
49
|
}>;
|
|
39
50
|
}
|
|
40
|
-
interface PayIDServer {
|
|
51
|
+
interface PayIDServer$1 {
|
|
41
52
|
/**
|
|
42
53
|
* Evaluate + generate proof dengan trusted issuers
|
|
43
54
|
* Signer sudah di-inject saat construct PayIDServer
|
|
@@ -54,6 +65,8 @@ interface PayIDServer {
|
|
|
54
65
|
verifyingContract: string;
|
|
55
66
|
ruleAuthority: string;
|
|
56
67
|
ttlSeconds?: number;
|
|
68
|
+
chainId: number;
|
|
69
|
+
blockTimestamp: number;
|
|
57
70
|
}): Promise<{
|
|
58
71
|
result: RuleResult;
|
|
59
72
|
proof: any | null;
|
|
@@ -69,6 +82,7 @@ interface PayIDServer {
|
|
|
69
82
|
gas: any;
|
|
70
83
|
targetContract: string;
|
|
71
84
|
paymasterAndData?: string;
|
|
85
|
+
attestationUIDs?: string[];
|
|
72
86
|
}): UserOperation;
|
|
73
87
|
}
|
|
74
88
|
|
|
@@ -129,11 +143,411 @@ interface PayIDServer {
|
|
|
129
143
|
* const payid = new PayID(wasmBinary, debugTrace, trustedIssuers);
|
|
130
144
|
* ```
|
|
131
145
|
*/
|
|
132
|
-
declare function createPayID(params: {
|
|
133
|
-
wasm
|
|
146
|
+
declare function createPayID$2(params: {
|
|
147
|
+
wasm?: Uint8Array;
|
|
134
148
|
debugTrace?: boolean;
|
|
135
149
|
trustedIssuers?: Set<string>;
|
|
136
|
-
}): PayIDClient & PayIDServer;
|
|
150
|
+
}): PayIDClient$1 & PayIDServer$1;
|
|
151
|
+
|
|
152
|
+
interface PayIDSessionPolicyPayloadV1 {
|
|
153
|
+
version: "payid.session.policy.v1" | string;
|
|
154
|
+
receiver: string;
|
|
155
|
+
rule: RuleConfig;
|
|
156
|
+
expiresAt: number;
|
|
157
|
+
nonce: string;
|
|
158
|
+
issuedAt: number;
|
|
159
|
+
signature: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Create and sign an ephemeral PayID session policy payload.
|
|
164
|
+
*
|
|
165
|
+
* A session policy represents a **temporary, off-chain consent**
|
|
166
|
+
* granted by the receiver to apply additional rule constraints
|
|
167
|
+
* during rule evaluation (e.g. session limits, QR payments,
|
|
168
|
+
* intent-scoped conditions).
|
|
169
|
+
*
|
|
170
|
+
* ## Security model
|
|
171
|
+
*
|
|
172
|
+
* - The session policy is signed by the receiver.
|
|
173
|
+
* - The signature proves **explicit consent** for the included rule.
|
|
174
|
+
* - This policy does NOT establish on-chain authority and MUST NOT
|
|
175
|
+
* be registered or referenced in any on-chain rule registry.
|
|
176
|
+
*
|
|
177
|
+
* ## Canonicalization
|
|
178
|
+
*
|
|
179
|
+
* - The rule set is canonicalized BEFORE signing to ensure
|
|
180
|
+
* deterministic hashing and signature verification.
|
|
181
|
+
* - The exact payload signed here MUST be used verbatim during
|
|
182
|
+
* policy verification.
|
|
183
|
+
*
|
|
184
|
+
* ## Lifecycle
|
|
185
|
+
*
|
|
186
|
+
* - Session policies are valid only until `expiresAt`.
|
|
187
|
+
* - Expired policies MUST be rejected by the verifier.
|
|
188
|
+
*
|
|
189
|
+
* @param params
|
|
190
|
+
* @param params.receiver
|
|
191
|
+
* Address of the receiver granting the session policy.
|
|
192
|
+
*
|
|
193
|
+
* @param params.rule
|
|
194
|
+
* Rule configuration to be applied as an **off-chain evaluation
|
|
195
|
+
* override** during the session.
|
|
196
|
+
*
|
|
197
|
+
* @param params.expiresAt
|
|
198
|
+
* UNIX timestamp (seconds) indicating when the session policy
|
|
199
|
+
* becomes invalid.
|
|
200
|
+
*
|
|
201
|
+
* @param params.signer
|
|
202
|
+
* Signer controlling the receiver address, used to sign the
|
|
203
|
+
* session policy payload.
|
|
204
|
+
*
|
|
205
|
+
* @returns
|
|
206
|
+
* A signed `PayIDSessionPolicyPayloadV1` that may be transmitted
|
|
207
|
+
* to clients and verified using `decodeSessionPolicy`.
|
|
208
|
+
*
|
|
209
|
+
* @throws
|
|
210
|
+
* May throw if signing fails or the signer is misconfigured.
|
|
211
|
+
*/
|
|
212
|
+
declare function createSessionPolicyPayload(params: {
|
|
213
|
+
receiver: string;
|
|
214
|
+
rule: RuleConfig;
|
|
215
|
+
expiresAt: number;
|
|
216
|
+
signer: ethers.Signer;
|
|
217
|
+
}): Promise<PayIDSessionPolicyPayloadV1>;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Decode and verify an ephemeral PayID session policy.
|
|
221
|
+
*
|
|
222
|
+
* This function validates that a session policy:
|
|
223
|
+
* - Uses a supported policy version
|
|
224
|
+
* - Has not expired
|
|
225
|
+
* - Was cryptographically signed by the declared receiver
|
|
226
|
+
*
|
|
227
|
+
* If all checks pass, the embedded rule configuration is returned
|
|
228
|
+
* and may be used as an **off-chain evaluation override**
|
|
229
|
+
* (e.g. combined with an authoritative on-chain rule).
|
|
230
|
+
*
|
|
231
|
+
* ## Security model
|
|
232
|
+
*
|
|
233
|
+
* - The session policy signature represents **explicit consent**
|
|
234
|
+
* from the receiver for temporary rule constraints.
|
|
235
|
+
* - This policy does NOT establish on-chain authority and MUST NOT
|
|
236
|
+
* be used to derive `ruleSetHash` or interact with rule registries.
|
|
237
|
+
*
|
|
238
|
+
* ## Invariants
|
|
239
|
+
*
|
|
240
|
+
* - The payload verified here MUST match exactly the payload that was signed.
|
|
241
|
+
* - No canonicalization or mutation is performed during verification.
|
|
242
|
+
* - Expired or invalidly signed policies are rejected immediately.
|
|
243
|
+
*
|
|
244
|
+
* @export
|
|
245
|
+
*
|
|
246
|
+
* @param sessionPolicy
|
|
247
|
+
* A signed session policy payload created by
|
|
248
|
+
* `createSessionPolicyPayload`.
|
|
249
|
+
*
|
|
250
|
+
* @param now
|
|
251
|
+
* Current UNIX timestamp (seconds) used to validate policy expiry.
|
|
252
|
+
*
|
|
253
|
+
* @returns
|
|
254
|
+
* A `RuleConfig` representing the session's evaluation rule.
|
|
255
|
+
*
|
|
256
|
+
* @throws
|
|
257
|
+
* Throws if:
|
|
258
|
+
* - The policy version is unsupported
|
|
259
|
+
* - The policy has expired
|
|
260
|
+
* - The signature does not match the receiver
|
|
261
|
+
*/
|
|
262
|
+
declare function decodeSessionPolicy(sessionPolicy: PayIDSessionPolicyPayloadV1, now: number): RuleConfig;
|
|
263
|
+
|
|
264
|
+
type index$5_PayIDSessionPolicyPayloadV1 = PayIDSessionPolicyPayloadV1;
|
|
265
|
+
declare const index$5_createSessionPolicyPayload: typeof createSessionPolicyPayload;
|
|
266
|
+
declare const index$5_decodeSessionPolicy: typeof decodeSessionPolicy;
|
|
267
|
+
declare namespace index$5 {
|
|
268
|
+
export { type index$5_PayIDSessionPolicyPayloadV1 as PayIDSessionPolicyPayloadV1, index$5_createSessionPolicyPayload as createSessionPolicyPayload, index$5_decodeSessionPolicy as decodeSessionPolicy };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Combine an authoritative rule set with additional ephemeral rules
|
|
273
|
+
* for off-chain evaluation.
|
|
274
|
+
*
|
|
275
|
+
* This helper merges:
|
|
276
|
+
* - A **default (authoritative) rule set** owned by the receiver
|
|
277
|
+
* - One or more **ephemeral rule constraints** (e.g. session / QR rules)
|
|
278
|
+
*
|
|
279
|
+
* The resulting rule set is intended **ONLY for off-chain evaluation**
|
|
280
|
+
* and MUST NOT be used as an authoritative rule on-chain.
|
|
281
|
+
*
|
|
282
|
+
* ## Security model
|
|
283
|
+
*
|
|
284
|
+
* - The default rule set defines sovereignty and ownership.
|
|
285
|
+
* - Ephemeral rules can only further restrict behavior
|
|
286
|
+
* (logical AND composition).
|
|
287
|
+
* - Ephemeral rules MUST NOT bypass or weaken default rules.
|
|
288
|
+
*
|
|
289
|
+
* ## Canonicalization
|
|
290
|
+
*
|
|
291
|
+
* - The combined rule set is canonicalized to ensure deterministic
|
|
292
|
+
* hashing and evaluation behavior.
|
|
293
|
+
*
|
|
294
|
+
* ## Invariants
|
|
295
|
+
*
|
|
296
|
+
* - The resulting rule set always uses logical AND semantics.
|
|
297
|
+
* - Rule order is normalized via canonicalization.
|
|
298
|
+
*
|
|
299
|
+
* @param defaultRuleSet
|
|
300
|
+
* The authoritative rule configuration (on-chain registered).
|
|
301
|
+
*
|
|
302
|
+
* @param sessionRule
|
|
303
|
+
* A list of additional rule conditions derived from an ephemeral
|
|
304
|
+
* policy (session, QR, intent, etc.).
|
|
305
|
+
*
|
|
306
|
+
* @returns
|
|
307
|
+
* A canonicalized rule configuration suitable for off-chain
|
|
308
|
+
* evaluation.
|
|
309
|
+
*/
|
|
310
|
+
declare function combineRules(defaultRuleSet: RuleConfig, sessionRule: any[]): {
|
|
311
|
+
version: string;
|
|
312
|
+
logic: "AND" | "OR";
|
|
313
|
+
rules: payid_types.AnyRule[];
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Canonicalize a rule set into a deterministic, order-independent form.
|
|
318
|
+
*
|
|
319
|
+
* Supports all three v4 rule formats:
|
|
320
|
+
* - Format A: { id, if, message? }
|
|
321
|
+
* - Format B: { id, logic, conditions[], message? }
|
|
322
|
+
* - Format C: { id, logic, rules[], message? }
|
|
323
|
+
*/
|
|
324
|
+
declare function canonicalizeRuleSet(ruleSet: {
|
|
325
|
+
version?: string;
|
|
326
|
+
logic: "AND" | "OR";
|
|
327
|
+
rules: any[];
|
|
328
|
+
}): {
|
|
329
|
+
version: string;
|
|
330
|
+
logic: "AND" | "OR";
|
|
331
|
+
rules: AnyRule[];
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Compute a deterministic hash of a canonicalized rule set.
|
|
336
|
+
*
|
|
337
|
+
* This function produces the `ruleSetHash` used to:
|
|
338
|
+
* - Reference authoritative rules in on-chain registries
|
|
339
|
+
* - Bind decision proofs to a specific rule configuration
|
|
340
|
+
* - Ensure integrity between off-chain evaluation and on-chain verification
|
|
341
|
+
*
|
|
342
|
+
* ## Canonicalization requirement
|
|
343
|
+
*
|
|
344
|
+
* - The input rule set MUST already be canonicalized using
|
|
345
|
+
* `canonicalizeRuleSet`.
|
|
346
|
+
* - Hashing a non-canonical rule set may result in inconsistent
|
|
347
|
+
* hashes for semantically identical rules.
|
|
348
|
+
*
|
|
349
|
+
* ## Security model
|
|
350
|
+
*
|
|
351
|
+
* - The hash represents the exact structure of the rule set at the
|
|
352
|
+
* time of hashing.
|
|
353
|
+
* - Any mutation (key order, rule order, value change) will produce
|
|
354
|
+
* a different hash.
|
|
355
|
+
*
|
|
356
|
+
* ## Invariants
|
|
357
|
+
*
|
|
358
|
+
* - This function does NOT perform canonicalization.
|
|
359
|
+
* - This function is pure and deterministic.
|
|
360
|
+
* - The same canonical rule set will always yield the same hash.
|
|
361
|
+
*
|
|
362
|
+
* @param ruleSet
|
|
363
|
+
* A canonicalized rule configuration object.
|
|
364
|
+
*
|
|
365
|
+
* @returns
|
|
366
|
+
* A `bytes32` hex string (keccak256) uniquely identifying the rule set.
|
|
367
|
+
*/
|
|
368
|
+
declare function hashRuleSet(ruleSet: any): string;
|
|
369
|
+
|
|
370
|
+
declare const index$4_canonicalizeRuleSet: typeof canonicalizeRuleSet;
|
|
371
|
+
declare const index$4_combineRules: typeof combineRules;
|
|
372
|
+
declare const index$4_hashRuleSet: typeof hashRuleSet;
|
|
373
|
+
declare namespace index$4 {
|
|
374
|
+
export { index$4_canonicalizeRuleSet as canonicalizeRuleSet, index$4_combineRules as combineRules, index$4_hashRuleSet as hashRuleSet };
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
declare function issueEnvContext(wallet: Wallet): Promise<EnvContext>;
|
|
378
|
+
|
|
379
|
+
declare function issueOracleContext(wallet: Wallet, data: Record<string, string | number>): Promise<OracleContext>;
|
|
380
|
+
|
|
381
|
+
declare function issueRiskContext(wallet: Wallet, score: number, category: string, modelHash: string): Promise<RiskContext>;
|
|
382
|
+
|
|
383
|
+
declare function issueStateContext(wallet: Wallet, spentToday: string, period: string): Promise<StateContext>;
|
|
384
|
+
|
|
385
|
+
declare function signAttestation(issuerWallet: Wallet, payload: object, ttlSeconds?: number): Promise<Attestation>;
|
|
386
|
+
|
|
387
|
+
declare const index$3_issueEnvContext: typeof issueEnvContext;
|
|
388
|
+
declare const index$3_issueOracleContext: typeof issueOracleContext;
|
|
389
|
+
declare const index$3_issueRiskContext: typeof issueRiskContext;
|
|
390
|
+
declare const index$3_issueStateContext: typeof issueStateContext;
|
|
391
|
+
declare const index$3_signAttestation: typeof signAttestation;
|
|
392
|
+
declare namespace index$3 {
|
|
393
|
+
export { index$3_issueEnvContext as issueEnvContext, index$3_issueOracleContext as issueOracleContext, index$3_issueRiskContext as issueRiskContext, index$3_issueStateContext as issueStateContext, index$3_signAttestation as signAttestation };
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Build an attested Context V2 object from a base execution context
|
|
398
|
+
* and a set of optional attestation issuers.
|
|
399
|
+
*
|
|
400
|
+
* ## Purpose
|
|
401
|
+
*
|
|
402
|
+
* This function assembles **Context V2**, which extends a raw
|
|
403
|
+
* execution context (Context V1) with **cryptographically attested
|
|
404
|
+
* facts** such as:
|
|
405
|
+
* - Environment data (time, runtime conditions)
|
|
406
|
+
* - Stateful data (daily spend, quotas)
|
|
407
|
+
* - Oracle data (country, FX rate, KYC attributes)
|
|
408
|
+
* - Risk signals (ML score, risk category)
|
|
409
|
+
*
|
|
410
|
+
* The resulting context is suitable for:
|
|
411
|
+
* - Deterministic rule evaluation
|
|
412
|
+
* - Context V2 verification via `preprocessContextV2`
|
|
413
|
+
* - Off-chain decision proof generation
|
|
414
|
+
* - On-chain attestation verification
|
|
415
|
+
*
|
|
416
|
+
* ## Trust model
|
|
417
|
+
*
|
|
418
|
+
* - Each context domain (`env`, `state`, `oracle`, `risk`) MUST be
|
|
419
|
+
* issued and signed by a trusted issuer.
|
|
420
|
+
* - The rule engine does NOT trust raw values; it only trusts
|
|
421
|
+
* verified attestations.
|
|
422
|
+
* - Which domains are required is determined by `ruleConfig.requires`.
|
|
423
|
+
*
|
|
424
|
+
* ## Responsibility
|
|
425
|
+
*
|
|
426
|
+
* This function:
|
|
427
|
+
* - Calls the appropriate issuer functions to generate attestations
|
|
428
|
+
* - Aggregates all issued contexts into a single Context V2 object
|
|
429
|
+
* - Does NOT evaluate rules
|
|
430
|
+
* - Does NOT perform attestation verification
|
|
431
|
+
*
|
|
432
|
+
* ## Environment
|
|
433
|
+
*
|
|
434
|
+
* This function may be called from:
|
|
435
|
+
* - Backend services
|
|
436
|
+
* - Relayers / bundlers
|
|
437
|
+
* - Edge runtimes
|
|
438
|
+
*
|
|
439
|
+
* It SHOULD NOT be called directly from untrusted clients unless
|
|
440
|
+
* issuer keys are properly secured.
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ### Minimal Context V2 (env + state only)
|
|
444
|
+
*
|
|
445
|
+
* ```ts
|
|
446
|
+
* const contextV2 = await buildContextV2({
|
|
447
|
+
* baseContext: {
|
|
448
|
+
* tx,
|
|
449
|
+
* payId
|
|
450
|
+
* },
|
|
451
|
+
* env: {
|
|
452
|
+
* issuer: envIssuer
|
|
453
|
+
* },
|
|
454
|
+
* state: {
|
|
455
|
+
* issuer: stateIssuer,
|
|
456
|
+
* spentToday: "2500000",
|
|
457
|
+
* period: "DAY"
|
|
458
|
+
* }
|
|
459
|
+
* });
|
|
460
|
+
* ```
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ### Full Context V2 (env + state + oracle + risk)
|
|
464
|
+
*
|
|
465
|
+
* ```ts
|
|
466
|
+
* const contextV2 = await buildContextV2({
|
|
467
|
+
* baseContext: {
|
|
468
|
+
* tx,
|
|
469
|
+
* payId
|
|
470
|
+
* },
|
|
471
|
+
* env: {
|
|
472
|
+
* issuer: envIssuer
|
|
473
|
+
* },
|
|
474
|
+
* state: {
|
|
475
|
+
* issuer: stateIssuer,
|
|
476
|
+
* spentToday: "2500000",
|
|
477
|
+
* period: "DAY"
|
|
478
|
+
* },
|
|
479
|
+
* oracle: {
|
|
480
|
+
* issuer: oracleIssuer,
|
|
481
|
+
* data: {
|
|
482
|
+
* country: "ID",
|
|
483
|
+
* fxRate: 15600
|
|
484
|
+
* }
|
|
485
|
+
* },
|
|
486
|
+
* risk: {
|
|
487
|
+
* issuer: riskIssuer,
|
|
488
|
+
* score: 72,
|
|
489
|
+
* category: "MEDIUM",
|
|
490
|
+
* modelHash: "0xmodelhash123"
|
|
491
|
+
* }
|
|
492
|
+
* });
|
|
493
|
+
* ```
|
|
494
|
+
*
|
|
495
|
+
* @param params
|
|
496
|
+
* Context assembly parameters.
|
|
497
|
+
*
|
|
498
|
+
* @param params.baseContext
|
|
499
|
+
* Base execution context (Context V1), containing transaction
|
|
500
|
+
* and PayID-related fields.
|
|
501
|
+
*
|
|
502
|
+
* @param params.env
|
|
503
|
+
* Optional environment attestation.
|
|
504
|
+
* Typically used for time-based or runtime constraints.
|
|
505
|
+
*
|
|
506
|
+
* @param params.state
|
|
507
|
+
* Optional state attestation.
|
|
508
|
+
* Used for cumulative values such as daily spend or quota tracking.
|
|
509
|
+
*
|
|
510
|
+
* @param params.oracle
|
|
511
|
+
* Optional oracle attestation.
|
|
512
|
+
* Used for external facts such as country, FX rate, or KYC signals.
|
|
513
|
+
*
|
|
514
|
+
* @param params.risk
|
|
515
|
+
* Optional risk attestation.
|
|
516
|
+
* Used for ML-based risk scoring and categorization.
|
|
517
|
+
*
|
|
518
|
+
* @returns
|
|
519
|
+
* A fully assembled Context V2 object containing the base context
|
|
520
|
+
* and all requested attested sub-contexts.
|
|
521
|
+
*
|
|
522
|
+
* @throws
|
|
523
|
+
* May throw if attestation issuance fails for any domain.
|
|
524
|
+
*/
|
|
525
|
+
declare function buildContextV2(params: {
|
|
526
|
+
baseContext: ContextV1;
|
|
527
|
+
env?: {
|
|
528
|
+
issuer: Wallet;
|
|
529
|
+
};
|
|
530
|
+
state?: {
|
|
531
|
+
issuer: Wallet;
|
|
532
|
+
spentToday: string;
|
|
533
|
+
period: string;
|
|
534
|
+
};
|
|
535
|
+
oracle?: {
|
|
536
|
+
issuer: Wallet;
|
|
537
|
+
data: Record<string, string | number>;
|
|
538
|
+
};
|
|
539
|
+
risk?: {
|
|
540
|
+
issuer: Wallet;
|
|
541
|
+
score: number;
|
|
542
|
+
category: string;
|
|
543
|
+
modelHash: string;
|
|
544
|
+
};
|
|
545
|
+
}): Promise<ContextV2>;
|
|
546
|
+
|
|
547
|
+
declare const index$2_buildContextV2: typeof buildContextV2;
|
|
548
|
+
declare namespace index$2 {
|
|
549
|
+
export { index$2_buildContextV2 as buildContextV2 };
|
|
550
|
+
}
|
|
137
551
|
|
|
138
552
|
/**
|
|
139
553
|
* @module eas
|
|
@@ -200,4 +614,261 @@ declare namespace eas {
|
|
|
200
614
|
export { type eas_EASAttestation as EASAttestation, eas_EASClient as EASClient, type eas_EASClientOptions as EASClientOptions, eas_EAS_ADDRESSES as EAS_ADDRESSES };
|
|
201
615
|
}
|
|
202
616
|
|
|
203
|
-
|
|
617
|
+
interface DecisionPayload {
|
|
618
|
+
version: string;
|
|
619
|
+
payId: string;
|
|
620
|
+
payer: string;
|
|
621
|
+
receiver: string;
|
|
622
|
+
asset: string;
|
|
623
|
+
amount: bigint;
|
|
624
|
+
contextHash: string;
|
|
625
|
+
ruleSetHash: string;
|
|
626
|
+
ruleAuthority: string;
|
|
627
|
+
issuedAt: bigint;
|
|
628
|
+
expiresAt: bigint;
|
|
629
|
+
nonce: string;
|
|
630
|
+
requiresAttestation: boolean;
|
|
631
|
+
}
|
|
632
|
+
interface DecisionProof {
|
|
633
|
+
payload: DecisionPayload;
|
|
634
|
+
signature: string;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* @class PayIDClient
|
|
639
|
+
* @description Client-side PayID engine.
|
|
640
|
+
*
|
|
641
|
+
* Fully serverless — aman dipakai di browser, mobile, edge.
|
|
642
|
+
* Tidak butuh issuer wallet, tidak butuh server.
|
|
643
|
+
*
|
|
644
|
+
* Untuk attestation, gunakan EAS UIDs yang di-fetch via `eas.EASClient`.
|
|
645
|
+
*
|
|
646
|
+
* @example
|
|
647
|
+
* ```ts
|
|
648
|
+
* const client = new PayIDClient(wasmBinary)
|
|
649
|
+
*
|
|
650
|
+
* // 1. Evaluate rule
|
|
651
|
+
* const result = await client.evaluate(context, ruleConfig)
|
|
652
|
+
*
|
|
653
|
+
* // 2. Evaluate + generate proof (payer sign sendiri)
|
|
654
|
+
* const { result, proof } = await client.evaluateAndProve({
|
|
655
|
+
* context,
|
|
656
|
+
* authorityRule: ruleConfig,
|
|
657
|
+
* payId: "pay.id/merchant",
|
|
658
|
+
* payer: await signer.getAddress(),
|
|
659
|
+
* receiver: "0xRECEIVER",
|
|
660
|
+
* asset: USDT_ADDRESS,
|
|
661
|
+
* amount: parseUnits("100", 6),
|
|
662
|
+
* signer,
|
|
663
|
+
* verifyingContract: PAYID_VERIFIER_ADDRESS,
|
|
664
|
+
* ruleAuthority: RULE_AUTHORITY_ADDRESS,
|
|
665
|
+
* })
|
|
666
|
+
* ```
|
|
667
|
+
*/
|
|
668
|
+
declare class PayIDClient {
|
|
669
|
+
private readonly debugTrace?;
|
|
670
|
+
private readonly wasm?;
|
|
671
|
+
constructor(debugTrace?: boolean | undefined, wasm?: Uint8Array | undefined);
|
|
672
|
+
evaluate(context: RuleContext, rule: RuleConfig | RuleSource): Promise<RuleResult>;
|
|
673
|
+
evaluateAndProve(params: {
|
|
674
|
+
context: RuleContext;
|
|
675
|
+
authorityRule: RuleConfig | RuleSource;
|
|
676
|
+
evaluationRule?: RuleConfig;
|
|
677
|
+
sessionPolicy?: PayIDSessionPolicyPayloadV1;
|
|
678
|
+
payId: string;
|
|
679
|
+
payer: string;
|
|
680
|
+
receiver: string;
|
|
681
|
+
asset: string;
|
|
682
|
+
amount: bigint;
|
|
683
|
+
signer: ethers.Signer;
|
|
684
|
+
verifyingContract: string;
|
|
685
|
+
ruleAuthority: string;
|
|
686
|
+
ttlSeconds?: number;
|
|
687
|
+
chainId: number;
|
|
688
|
+
blockTimestamp: number;
|
|
689
|
+
}): Promise<{
|
|
690
|
+
result: RuleResult;
|
|
691
|
+
proof: DecisionProof | null;
|
|
692
|
+
}>;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Create a PayID policy engine instance backed by a WASM rule evaluator.
|
|
697
|
+
*
|
|
698
|
+
* ## Responsibility
|
|
699
|
+
*
|
|
700
|
+
* - Holds the WASM binary used for rule execution
|
|
701
|
+
* - Defines the trust boundary for context attestation verification
|
|
702
|
+
* - Acts as the primary entry point for PayID rule evaluation
|
|
703
|
+
*
|
|
704
|
+
* ## Trust model
|
|
705
|
+
*
|
|
706
|
+
* - If `trustedIssuers` is provided, Context V2 attestation
|
|
707
|
+
* verification is ENFORCED.
|
|
708
|
+
* - If `trustedIssuers` is omitted, the engine runs in
|
|
709
|
+
* legacy (Context V1) mode without cryptographic verification.
|
|
710
|
+
*
|
|
711
|
+
* ## Environment
|
|
712
|
+
*
|
|
713
|
+
* This class is safe to instantiate in:
|
|
714
|
+
* - Browsers
|
|
715
|
+
* - Mobile apps
|
|
716
|
+
* - Edge runtimes
|
|
717
|
+
* - Backend services
|
|
718
|
+
*
|
|
719
|
+
* @param wasm
|
|
720
|
+
* Compiled PayID WASM rule engine binary.
|
|
721
|
+
*
|
|
722
|
+
* @param debugTrace
|
|
723
|
+
* Optional flag to enable decision trace generation for debugging.
|
|
724
|
+
* @example
|
|
725
|
+
* ```ts
|
|
726
|
+
*
|
|
727
|
+
* const payid = new PayID(wasmBinary, debugTrace);
|
|
728
|
+
* ```
|
|
729
|
+
*/
|
|
730
|
+
declare function createPayID$1(params: {
|
|
731
|
+
wasm?: Uint8Array;
|
|
732
|
+
debugTrace?: boolean;
|
|
733
|
+
}): PayIDClient;
|
|
734
|
+
|
|
735
|
+
declare namespace index$1 {
|
|
736
|
+
export { createPayID$1 as createPayID };
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* @class PayIDServer
|
|
741
|
+
* @description Server-side PayID engine.
|
|
742
|
+
*
|
|
743
|
+
* Digunakan ketika butuh:
|
|
744
|
+
* - Context V2 (env, state, oracle, risk) dengan trusted issuers
|
|
745
|
+
* - Build ERC-4337 UserOperation untuk bundler
|
|
746
|
+
*
|
|
747
|
+
* Signer di-inject saat construct — jangan pakai ini di browser.
|
|
748
|
+
*
|
|
749
|
+
* @example
|
|
750
|
+
* ```ts
|
|
751
|
+
* // Server/bundler side
|
|
752
|
+
* const server = new PayIDServer(wasmBinary, serverSigner, trustedIssuers)
|
|
753
|
+
*
|
|
754
|
+
* const { result, proof } = await server.evaluateAndProve({
|
|
755
|
+
* context: contextV2, // ← Context V2 dengan attestations
|
|
756
|
+
* authorityRule,
|
|
757
|
+
* payId: "pay.id/merchant",
|
|
758
|
+
* payer: "0xPAYER",
|
|
759
|
+
* receiver: "0xRECEIVER",
|
|
760
|
+
* asset: USDT_ADDRESS,
|
|
761
|
+
* amount: parseUnits("100", 6),
|
|
762
|
+
* verifyingContract: PAYID_VERIFIER_ADDRESS,
|
|
763
|
+
* ruleAuthority: RULE_AUTHORITY_ADDRESS,
|
|
764
|
+
* })
|
|
765
|
+
* ```
|
|
766
|
+
*/
|
|
767
|
+
declare class PayIDServer {
|
|
768
|
+
private readonly signer;
|
|
769
|
+
private readonly trustedIssuers?;
|
|
770
|
+
private readonly debugTrace?;
|
|
771
|
+
private readonly wasm?;
|
|
772
|
+
constructor(signer: ethers.Signer, trustedIssuers?: Set<string> | undefined, debugTrace?: boolean | undefined, wasm?: Uint8Array | undefined);
|
|
773
|
+
evaluateAndProve(params: {
|
|
774
|
+
context: RuleContext;
|
|
775
|
+
authorityRule: RuleConfig | RuleSource;
|
|
776
|
+
evaluationRule?: RuleConfig;
|
|
777
|
+
payId: string;
|
|
778
|
+
payer: string;
|
|
779
|
+
receiver: string;
|
|
780
|
+
asset: string;
|
|
781
|
+
amount: bigint;
|
|
782
|
+
verifyingContract: string;
|
|
783
|
+
ruleAuthority: string;
|
|
784
|
+
ttlSeconds?: number;
|
|
785
|
+
chainId: number;
|
|
786
|
+
blockTimestamp: number;
|
|
787
|
+
}): Promise<{
|
|
788
|
+
result: RuleResult;
|
|
789
|
+
proof: DecisionProof | null;
|
|
790
|
+
}>;
|
|
791
|
+
buildUserOperation(params: {
|
|
792
|
+
proof: DecisionProof;
|
|
793
|
+
smartAccount: string;
|
|
794
|
+
nonce: string;
|
|
795
|
+
gas: any;
|
|
796
|
+
targetContract: string;
|
|
797
|
+
paymasterAndData?: string;
|
|
798
|
+
attestationUIDs?: string[];
|
|
799
|
+
}): UserOperation;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Create a PayID policy engine instance backed by a WASM rule evaluator.
|
|
804
|
+
*
|
|
805
|
+
* ## Responsibility
|
|
806
|
+
*
|
|
807
|
+
* - Holds the WASM binary used for rule execution
|
|
808
|
+
* - Defines the trust boundary for context attestation verification
|
|
809
|
+
* - Acts as the primary entry point for PayID rule evaluation
|
|
810
|
+
*
|
|
811
|
+
* ## Trust model
|
|
812
|
+
*
|
|
813
|
+
* - If `trustedIssuers` is provided, Context V2 attestation
|
|
814
|
+
* verification is ENFORCED.
|
|
815
|
+
* - If `trustedIssuers` is omitted, the engine runs in
|
|
816
|
+
* legacy (Context V1) mode without cryptographic verification.
|
|
817
|
+
*
|
|
818
|
+
* ## Environment
|
|
819
|
+
*
|
|
820
|
+
* This class is safe to instantiate in:
|
|
821
|
+
* - Browsers
|
|
822
|
+
* - Mobile apps
|
|
823
|
+
* - Edge runtimes
|
|
824
|
+
* - Backend services
|
|
825
|
+
*
|
|
826
|
+
* @param wasm
|
|
827
|
+
* Compiled PayID WASM rule engine binary.
|
|
828
|
+
*
|
|
829
|
+
* @param signer
|
|
830
|
+
* Signer account
|
|
831
|
+
*
|
|
832
|
+
* @param debugTrace
|
|
833
|
+
* Optional flag to enable decision trace generation for debugging.
|
|
834
|
+
*
|
|
835
|
+
* @param trustedIssuers
|
|
836
|
+
* Optional set of trusted attestation issuer addresses.
|
|
837
|
+
*
|
|
838
|
+
* When provided, Context V2 attestation verification is ENFORCED:
|
|
839
|
+
* - Only attestations issued by addresses in this set are accepted.
|
|
840
|
+
* - Missing, expired, or invalid attestations cause evaluation to fail.
|
|
841
|
+
*
|
|
842
|
+
* When omitted, the engine runs in legacy (Context V1) mode
|
|
843
|
+
* without cryptographic verification.
|
|
844
|
+
*
|
|
845
|
+
* ⚠️ Important:
|
|
846
|
+
* - Do NOT pass an empty Set.
|
|
847
|
+
* An empty set means "no issuer is trusted" and will
|
|
848
|
+
* cause all attestations to be rejected.
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
* ```ts
|
|
852
|
+
* const trustedIssuers = new Set([
|
|
853
|
+
* TIME_ISSUER,
|
|
854
|
+
* STATE_ISSUER,
|
|
855
|
+
* ORACLE_ISSUER,
|
|
856
|
+
* RISK_ISSUER
|
|
857
|
+
* ]);
|
|
858
|
+
*
|
|
859
|
+
* const payid = new PayID(wasmBinary, ethers.Signer, debugTrace, trustedIssuers);
|
|
860
|
+
* ```
|
|
861
|
+
*/
|
|
862
|
+
declare function createPayID(params: {
|
|
863
|
+
wasm?: Uint8Array;
|
|
864
|
+
signer: ethers.Signer;
|
|
865
|
+
debugTrace?: boolean;
|
|
866
|
+
trustedIssuers?: Set<string>;
|
|
867
|
+
}): PayIDServer;
|
|
868
|
+
|
|
869
|
+
declare const index_createPayID: typeof createPayID;
|
|
870
|
+
declare namespace index {
|
|
871
|
+
export { index_createPayID as createPayID };
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
export { type PayIDClient$1 as PayIDClient, type PayIDServer$1 as PayIDServer, index$1 as client, index$2 as context, createPayID$2 as createPayID, eas, index$3 as issuer, index$4 as rule, index as server, index$5 as sessionPolicy };
|