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.
@@ -1,158 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import { RuleContext, RuleConfig, RuleResult } from 'payid-types';
3
- import { R as RuleSource, D as DecisionProof } from './types-B8pJQdMQ.js';
4
-
5
- interface UserOperation {
6
- sender: string;
7
- nonce: string;
8
- initCode: string;
9
- callData: string;
10
- callGasLimit: string;
11
- verificationGasLimit: string;
12
- preVerificationGas: string;
13
- maxFeePerGas: string;
14
- maxPriorityFeePerGas: string;
15
- paymasterAndData: string;
16
- signature: string;
17
- }
18
-
19
- /**
20
- * @class PayIDServer
21
- * @description Server-side PayID engine.
22
- *
23
- * Digunakan ketika butuh:
24
- * - Context V2 (env, state, oracle, risk) dengan trusted issuers
25
- * - Build ERC-4337 UserOperation untuk bundler
26
- *
27
- * Signer di-inject saat construct — jangan pakai ini di browser.
28
- *
29
- * @example
30
- * ```ts
31
- * // Server/bundler side
32
- * const server = new PayIDServer(wasmBinary, serverSigner, trustedIssuers)
33
- *
34
- * const { result, proof } = await server.evaluateAndProve({
35
- * context: contextV2, // ← Context V2 dengan attestations
36
- * authorityRule,
37
- * payId: "pay.id/merchant",
38
- * payer: "0xPAYER",
39
- * receiver: "0xRECEIVER",
40
- * asset: USDT_ADDRESS,
41
- * amount: parseUnits("100", 6),
42
- * verifyingContract: PAYID_VERIFIER_ADDRESS,
43
- * ruleAuthority: RULE_AUTHORITY_ADDRESS,
44
- * })
45
- * ```
46
- */
47
- declare class PayIDServer {
48
- private readonly wasm;
49
- private readonly signer;
50
- private readonly trustedIssuers?;
51
- private readonly debugTrace?;
52
- constructor(wasm: Uint8Array, signer: ethers.Signer, trustedIssuers?: Set<string> | undefined, debugTrace?: boolean | undefined);
53
- /**
54
- * Evaluate + generate proof dengan signer dari constructor
55
- */
56
- evaluateAndProve(params: {
57
- context: RuleContext;
58
- authorityRule: RuleConfig | RuleSource;
59
- evaluationRule?: RuleConfig;
60
- payId: string;
61
- payer: string;
62
- receiver: string;
63
- asset: string;
64
- amount: bigint;
65
- verifyingContract: string;
66
- ruleAuthority: string;
67
- ttlSeconds?: number;
68
- }): Promise<{
69
- result: RuleResult;
70
- proof: DecisionProof | null;
71
- }>;
72
- /**
73
- * Build ERC-4337 UserOperation dari Decision Proof
74
- * Untuk bundler/relayer — server only
75
- */
76
- buildUserOperation(params: {
77
- proof: DecisionProof;
78
- smartAccount: string;
79
- nonce: string;
80
- gas: any;
81
- targetContract: string;
82
- paymasterAndData?: string;
83
- }): UserOperation;
84
- }
85
-
86
- /**
87
- * Create a PayID policy engine instance backed by a WASM rule evaluator.
88
- *
89
- * ## Responsibility
90
- *
91
- * - Holds the WASM binary used for rule execution
92
- * - Defines the trust boundary for context attestation verification
93
- * - Acts as the primary entry point for PayID rule evaluation
94
- *
95
- * ## Trust model
96
- *
97
- * - If `trustedIssuers` is provided, Context V2 attestation
98
- * verification is ENFORCED.
99
- * - If `trustedIssuers` is omitted, the engine runs in
100
- * legacy (Context V1) mode without cryptographic verification.
101
- *
102
- * ## Environment
103
- *
104
- * This class is safe to instantiate in:
105
- * - Browsers
106
- * - Mobile apps
107
- * - Edge runtimes
108
- * - Backend services
109
- *
110
- * @param wasm
111
- * Compiled PayID WASM rule engine binary.
112
- *
113
- * @param signer
114
- * Signer account
115
- *
116
- * @param debugTrace
117
- * Optional flag to enable decision trace generation for debugging.
118
- *
119
- * @param trustedIssuers
120
- * Optional set of trusted attestation issuer addresses.
121
- *
122
- * When provided, Context V2 attestation verification is ENFORCED:
123
- * - Only attestations issued by addresses in this set are accepted.
124
- * - Missing, expired, or invalid attestations cause evaluation to fail.
125
- *
126
- * When omitted, the engine runs in legacy (Context V1) mode
127
- * without cryptographic verification.
128
- *
129
- * ⚠️ Important:
130
- * - Do NOT pass an empty Set.
131
- * An empty set means "no issuer is trusted" and will
132
- * cause all attestations to be rejected.
133
- *
134
- * @example
135
- * ```ts
136
- * const trustedIssuers = new Set([
137
- * TIME_ISSUER,
138
- * STATE_ISSUER,
139
- * ORACLE_ISSUER,
140
- * RISK_ISSUER
141
- * ]);
142
- *
143
- * const payid = new PayID(wasmBinary, ethers.Signer, debugTrace, trustedIssuers);
144
- * ```
145
- */
146
- declare function createPayID(params: {
147
- wasm: Uint8Array;
148
- signer: ethers.Signer;
149
- debugTrace?: boolean;
150
- trustedIssuers?: Set<string>;
151
- }): PayIDServer;
152
-
153
- declare const index_createPayID: typeof createPayID;
154
- declare namespace index {
155
- export { index_createPayID as createPayID };
156
- }
157
-
158
- export { type UserOperation as U, createPayID as c, index as i };
@@ -1,118 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import { P as PayIDSessionPolicyPayloadV1 } from './types-DKt-zH0P.js';
3
- import { RuleConfig } from 'payid-types';
4
-
5
- /**
6
- * Create and sign an ephemeral PayID session policy payload.
7
- *
8
- * A session policy represents a **temporary, off-chain consent**
9
- * granted by the receiver to apply additional rule constraints
10
- * during rule evaluation (e.g. session limits, QR payments,
11
- * intent-scoped conditions).
12
- *
13
- * ## Security model
14
- *
15
- * - The session policy is signed by the receiver.
16
- * - The signature proves **explicit consent** for the included rule.
17
- * - This policy does NOT establish on-chain authority and MUST NOT
18
- * be registered or referenced in any on-chain rule registry.
19
- *
20
- * ## Canonicalization
21
- *
22
- * - The rule set is canonicalized BEFORE signing to ensure
23
- * deterministic hashing and signature verification.
24
- * - The exact payload signed here MUST be used verbatim during
25
- * policy verification.
26
- *
27
- * ## Lifecycle
28
- *
29
- * - Session policies are valid only until `expiresAt`.
30
- * - Expired policies MUST be rejected by the verifier.
31
- *
32
- * @param params
33
- * @param params.receiver
34
- * Address of the receiver granting the session policy.
35
- *
36
- * @param params.rule
37
- * Rule configuration to be applied as an **off-chain evaluation
38
- * override** during the session.
39
- *
40
- * @param params.expiresAt
41
- * UNIX timestamp (seconds) indicating when the session policy
42
- * becomes invalid.
43
- *
44
- * @param params.signer
45
- * Signer controlling the receiver address, used to sign the
46
- * session policy payload.
47
- *
48
- * @returns
49
- * A signed `PayIDSessionPolicyPayloadV1` that may be transmitted
50
- * to clients and verified using `decodeSessionPolicy`.
51
- *
52
- * @throws
53
- * May throw if signing fails or the signer is misconfigured.
54
- */
55
- declare function createSessionPolicyPayload(params: {
56
- receiver: string;
57
- rule: {
58
- version: string;
59
- logic: "AND";
60
- rules: any[];
61
- };
62
- expiresAt: number;
63
- signer: ethers.Signer;
64
- }): Promise<PayIDSessionPolicyPayloadV1>;
65
-
66
- /**
67
- * Decode and verify an ephemeral PayID session policy.
68
- *
69
- * This function validates that a session policy:
70
- * - Uses a supported policy version
71
- * - Has not expired
72
- * - Was cryptographically signed by the declared receiver
73
- *
74
- * If all checks pass, the embedded rule configuration is returned
75
- * and may be used as an **off-chain evaluation override**
76
- * (e.g. combined with an authoritative on-chain rule).
77
- *
78
- * ## Security model
79
- *
80
- * - The session policy signature represents **explicit consent**
81
- * from the receiver for temporary rule constraints.
82
- * - This policy does NOT establish on-chain authority and MUST NOT
83
- * be used to derive `ruleSetHash` or interact with rule registries.
84
- *
85
- * ## Invariants
86
- *
87
- * - The payload verified here MUST match exactly the payload that was signed.
88
- * - No canonicalization or mutation is performed during verification.
89
- * - Expired or invalidly signed policies are rejected immediately.
90
- *
91
- * @export
92
- *
93
- * @param sessionPolicy
94
- * A signed session policy payload created by
95
- * `createSessionPolicyPayload`.
96
- *
97
- * @param now
98
- * Current UNIX timestamp (seconds) used to validate policy expiry.
99
- *
100
- * @returns
101
- * A `RuleConfig` representing the session's evaluation rule.
102
- *
103
- * @throws
104
- * Throws if:
105
- * - The policy version is unsupported
106
- * - The policy has expired
107
- * - The signature does not match the receiver
108
- */
109
- declare function decodeSessionPolicy(sessionPolicy: PayIDSessionPolicyPayloadV1, now: number): RuleConfig;
110
-
111
- declare const index_PayIDSessionPolicyPayloadV1: typeof PayIDSessionPolicyPayloadV1;
112
- declare const index_createSessionPolicyPayload: typeof createSessionPolicyPayload;
113
- declare const index_decodeSessionPolicy: typeof decodeSessionPolicy;
114
- declare namespace index {
115
- export { index_PayIDSessionPolicyPayloadV1 as PayIDSessionPolicyPayloadV1, index_createSessionPolicyPayload as createSessionPolicyPayload, index_decodeSessionPolicy as decodeSessionPolicy };
116
- }
117
-
118
- export { createSessionPolicyPayload as c, decodeSessionPolicy as d, index as i };
@@ -1,114 +0,0 @@
1
- import { RuleContext, RuleConfig, RuleResult } from 'payid-types';
2
- import { ethers } from 'ethers';
3
- import { R as RuleSource, D as DecisionProof } from './types-B8pJQdMQ.js';
4
- import { P as PayIDSessionPolicyPayloadV1 } from './types-DKt-zH0P.js';
5
-
6
- /**
7
- * @class PayIDClient
8
- * @description Client-side PayID engine.
9
- *
10
- * Fully serverless — aman dipakai di browser, mobile, edge.
11
- * Tidak butuh issuer wallet, tidak butuh server.
12
- *
13
- * Untuk attestation, gunakan EAS UIDs yang di-fetch via `eas.EASClient`.
14
- *
15
- * @example
16
- * ```ts
17
- * const client = new PayIDClient(wasmBinary)
18
- *
19
- * // 1. Evaluate rule
20
- * const result = await client.evaluate(context, ruleConfig)
21
- *
22
- * // 2. Evaluate + generate proof (payer sign sendiri)
23
- * const { result, proof } = await client.evaluateAndProve({
24
- * context,
25
- * authorityRule: ruleConfig,
26
- * payId: "pay.id/merchant",
27
- * payer: await signer.getAddress(),
28
- * receiver: "0xRECEIVER",
29
- * asset: USDT_ADDRESS,
30
- * amount: parseUnits("100", 6),
31
- * signer,
32
- * verifyingContract: PAYID_VERIFIER_ADDRESS,
33
- * ruleAuthority: RULE_AUTHORITY_ADDRESS,
34
- * })
35
- * ```
36
- */
37
- declare class PayIDClient {
38
- private readonly wasm;
39
- private readonly debugTrace?;
40
- constructor(wasm: Uint8Array, debugTrace?: boolean | undefined);
41
- /**
42
- * Pure rule evaluation — client-safe, no signing, no server
43
- */
44
- evaluate(context: RuleContext, rule: RuleConfig | RuleSource): Promise<RuleResult>;
45
- /**
46
- * Evaluate + generate EIP-712 Decision Proof.
47
- * Payer sign sendiri menggunakan wallet mereka — tidak butuh server.
48
- */
49
- evaluateAndProve(params: {
50
- context: RuleContext;
51
- authorityRule: RuleConfig | RuleSource;
52
- evaluationRule?: RuleConfig;
53
- sessionPolicy?: PayIDSessionPolicyPayloadV1;
54
- payId: string;
55
- payer: string;
56
- receiver: string;
57
- asset: string;
58
- amount: bigint;
59
- signer: ethers.Signer;
60
- verifyingContract: string;
61
- ruleAuthority: string;
62
- ttlSeconds?: number;
63
- }): Promise<{
64
- result: RuleResult;
65
- proof: DecisionProof | null;
66
- }>;
67
- }
68
-
69
- /**
70
- * Create a PayID policy engine instance backed by a WASM rule evaluator.
71
- *
72
- * ## Responsibility
73
- *
74
- * - Holds the WASM binary used for rule execution
75
- * - Defines the trust boundary for context attestation verification
76
- * - Acts as the primary entry point for PayID rule evaluation
77
- *
78
- * ## Trust model
79
- *
80
- * - If `trustedIssuers` is provided, Context V2 attestation
81
- * verification is ENFORCED.
82
- * - If `trustedIssuers` is omitted, the engine runs in
83
- * legacy (Context V1) mode without cryptographic verification.
84
- *
85
- * ## Environment
86
- *
87
- * This class is safe to instantiate in:
88
- * - Browsers
89
- * - Mobile apps
90
- * - Edge runtimes
91
- * - Backend services
92
- *
93
- * @param wasm
94
- * Compiled PayID WASM rule engine binary.
95
- *
96
- * @param debugTrace
97
- * Optional flag to enable decision trace generation for debugging.
98
- * @example
99
- * ```ts
100
- *
101
- * const payid = new PayID(wasmBinary, debugTrace);
102
- * ```
103
- */
104
- declare function createPayID(params: {
105
- wasm: Uint8Array;
106
- debugTrace?: boolean;
107
- }): PayIDClient;
108
-
109
- declare const index_createPayID: typeof createPayID;
110
- declare namespace index {
111
- export { index_createPayID as createPayID };
112
- }
113
-
114
- export { createPayID as c, index as i };
@@ -1,3 +0,0 @@
1
- export { a as issueEnvContext, b as issueOracleContext, c as issueRiskContext, d as issueStateContext, s as signAttestation } from '../index-2JCvey4-.js';
2
- import 'payid-types';
3
- import 'ethers';
@@ -1,16 +0,0 @@
1
- import "../chunk-AOKLY2QN.js";
2
- import {
3
- issueEnvContext,
4
- issueOracleContext,
5
- issueRiskContext,
6
- issueStateContext,
7
- signAttestation
8
- } from "../chunk-7U3P7XJE.js";
9
- import "../chunk-R5U7XKVJ.js";
10
- export {
11
- issueEnvContext,
12
- issueOracleContext,
13
- issueRiskContext,
14
- issueStateContext,
15
- signAttestation
16
- };
@@ -1,2 +0,0 @@
1
- export { a as canonicalizeRuleSet, c as combineRules, h as hashRuleSet } from '../index-C7vziL_Z.js';
2
- import 'payid-types';
@@ -1,15 +0,0 @@
1
- import {
2
- hashRuleSet
3
- } from "../chunk-JRVCGSKK.js";
4
- import {
5
- combineRules
6
- } from "../chunk-QYH3FNQ4.js";
7
- import {
8
- canonicalizeRuleSet
9
- } from "../chunk-JJEWYFOV.js";
10
- import "../chunk-R5U7XKVJ.js";
11
- export {
12
- canonicalizeRuleSet,
13
- combineRules,
14
- hashRuleSet
15
- };
@@ -1,4 +0,0 @@
1
- export { c as createSessionPolicyPayload, d as decodeSessionPolicy } from '../index-DuOeYzN2.js';
2
- export { P as PayIDSessionPolicyPayloadV1 } from '../types-DKt-zH0P.js';
3
- import 'ethers';
4
- import 'payid-types';
@@ -1,13 +0,0 @@
1
- import {
2
- createSessionPolicyPayload
3
- } from "../chunk-ATWJEWZH.js";
4
- import {
5
- decodeSessionPolicy
6
- } from "../chunk-MXKZJKXE.js";
7
- import "../chunk-JJEWYFOV.js";
8
- import "../chunk-5ZEKI5Y2.js";
9
- import "../chunk-R5U7XKVJ.js";
10
- export {
11
- createSessionPolicyPayload,
12
- decodeSessionPolicy
13
- };
@@ -1,26 +0,0 @@
1
- interface RuleSource {
2
- uri: string;
3
- hash?: string;
4
- }
5
-
6
- interface DecisionPayload {
7
- version: string;
8
- payId: string;
9
- payer: string;
10
- receiver: string;
11
- asset: string;
12
- amount: bigint;
13
- contextHash: string;
14
- ruleSetHash: string;
15
- ruleAuthority: string;
16
- issuedAt: bigint;
17
- expiresAt: bigint;
18
- nonce: string;
19
- requiresAttestation: boolean;
20
- }
21
- interface DecisionProof {
22
- payload: DecisionPayload;
23
- signature: string;
24
- }
25
-
26
- export type { DecisionProof as D, RuleSource as R };
@@ -1,15 +0,0 @@
1
- interface PayIDSessionPolicyPayloadV1 {
2
- version: "payid.session.policy.v1" | string;
3
- receiver: string;
4
- rule: {
5
- version: string;
6
- logic: "AND" | "OR";
7
- rules: any[];
8
- };
9
- expiresAt: number;
10
- nonce: string;
11
- issuedAt: number;
12
- signature: string;
13
- }
14
-
15
- export type { PayIDSessionPolicyPayloadV1 as P };