payid 0.3.1 → 0.3.3
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-4MPVXPLM.js +272 -0
- package/dist/chunk-5ZEKI5Y2.js +18 -0
- package/dist/chunk-7U3P7XJE.js +67 -0
- package/dist/chunk-AOKLY2QN.js +24 -0
- package/dist/chunk-ATWJEWZH.js +47 -0
- package/dist/chunk-FIMJNWJ3.js +72 -0
- package/dist/chunk-JJEWYFOV.js +42 -0
- package/dist/chunk-JRVCGSKK.js +30 -0
- package/dist/chunk-MXKZJKXE.js +33 -0
- package/dist/chunk-QYH3FNQ4.js +19 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-RCXMRX4F.js +54 -0
- package/dist/chunk-XWOB3JVE.js +78 -0
- package/dist/context/index.d.ts +3 -0
- package/dist/context/index.js +8 -0
- package/dist/core/client/index.d.ts +5 -0
- package/dist/core/client/index.js +12 -0
- package/dist/core/server/index.d.ts +4 -0
- package/dist/core/server/index.js +9 -0
- package/dist/index-2JCvey4-.d.ts +23 -0
- package/dist/index-BEvnPzzt.d.ts +160 -0
- package/dist/index-BrD4MTYK.d.ts +75 -0
- package/dist/index-C7vziL_Z.d.ts +150 -0
- package/dist/index-DY-T49uU.d.ts +101 -0
- package/dist/index-DuOeYzN2.d.ts +118 -0
- package/dist/index.d.ts +125 -1
- package/dist/index.js +303 -1
- package/dist/issuer/index.d.ts +3 -0
- package/dist/issuer/index.js +16 -0
- package/dist/rule/index.d.ts +2 -0
- package/dist/rule/index.js +15 -0
- package/dist/sessionPolicy/index.d.ts +4 -0
- package/dist/sessionPolicy/index.js +13 -0
- package/dist/types-B5dv7L-8.d.ts +21 -0
- package/dist/types-DKt-zH0P.d.ts +15 -0
- package/package.json +37 -7
- package/dist/decision-proof/generate.d.ts +0 -13
- package/dist/decision-proof/generate.js +0 -20
- package/dist/decision-proof/hash.d.ts +0 -2
- package/dist/decision-proof/hash.js +0 -21
- package/dist/decision-proof/sign.d.ts +0 -3
- package/dist/decision-proof/sign.js +0 -28
- package/dist/decision-proof/types.d.ts +0 -16
- package/dist/decision-proof/types.js +0 -1
- package/dist/erc4337/build.d.ts +0 -2
- package/dist/erc4337/build.js +0 -10
- package/dist/erc4337/types.d.ts +0 -13
- package/dist/erc4337/types.js +0 -1
- package/dist/erc4337/userop.d.ts +0 -15
- package/dist/erc4337/userop.js +0 -15
- package/dist/evaluate.d.ts +0 -4
- package/dist/evaluate.js +0 -46
- package/dist/normalize.d.ts +0 -2
- package/dist/normalize.js +0 -11
- package/dist/payid.d.ts +0 -70
- package/dist/payid.js +0 -93
- package/dist/resolver/http.d.ts +0 -1
- package/dist/resolver/http.js +0 -10
- package/dist/resolver/ipfs.d.ts +0 -1
- package/dist/resolver/ipfs.js +0 -13
- package/dist/resolver/resolver.d.ts +0 -2
- package/dist/resolver/resolver.js +0 -19
- package/dist/resolver/types.d.ts +0 -8
- package/dist/resolver/types.js +0 -1
- package/dist/resolver/utils.d.ts +0 -1
- package/dist/resolver/utils.js +0 -9
|
@@ -0,0 +1,118 @@
|
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,125 @@
|
|
|
1
|
-
|
|
1
|
+
import { RuleContext, RuleConfig, RuleResult } from 'payid-types';
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
export { i as sessionPolicy } from './index-DuOeYzN2.js';
|
|
4
|
+
export { i as rule } from './index-C7vziL_Z.js';
|
|
5
|
+
export { i as issuer } from './index-2JCvey4-.js';
|
|
6
|
+
export { i as context } from './index-BEvnPzzt.js';
|
|
7
|
+
export { i as server } from './index-BrD4MTYK.js';
|
|
8
|
+
export { i as client } from './index-DY-T49uU.js';
|
|
9
|
+
import './types-DKt-zH0P.js';
|
|
10
|
+
import './types-B5dv7L-8.js';
|
|
11
|
+
|
|
12
|
+
interface RuleSource {
|
|
13
|
+
uri: string;
|
|
14
|
+
hash?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface UserOperation {
|
|
18
|
+
sender: string;
|
|
19
|
+
nonce: string;
|
|
20
|
+
initCode: string;
|
|
21
|
+
callData: string;
|
|
22
|
+
callGasLimit: string;
|
|
23
|
+
verificationGasLimit: string;
|
|
24
|
+
preVerificationGas: string;
|
|
25
|
+
maxFeePerGas: string;
|
|
26
|
+
maxPriorityFeePerGas: string;
|
|
27
|
+
paymasterAndData: string;
|
|
28
|
+
signature: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface PayIDClient {
|
|
32
|
+
evaluate(context: RuleContext, rule: RuleConfig | RuleSource): Promise<RuleResult>;
|
|
33
|
+
}
|
|
34
|
+
interface PayIDServer {
|
|
35
|
+
evaluateAndProve(params: {
|
|
36
|
+
context: RuleContext;
|
|
37
|
+
authorityRule: RuleConfig;
|
|
38
|
+
evaluationRule?: RuleConfig;
|
|
39
|
+
payId: string;
|
|
40
|
+
payer: string;
|
|
41
|
+
receiver: string;
|
|
42
|
+
asset: string;
|
|
43
|
+
amount: bigint;
|
|
44
|
+
signer: ethers.Signer;
|
|
45
|
+
verifyingContract: string;
|
|
46
|
+
ruleRegistryContract: string;
|
|
47
|
+
ttlSeconds?: number;
|
|
48
|
+
}): Promise<{
|
|
49
|
+
result: RuleResult;
|
|
50
|
+
proof: any | null;
|
|
51
|
+
}>;
|
|
52
|
+
buildUserOperation(params: {
|
|
53
|
+
proof: any;
|
|
54
|
+
smartAccount: string;
|
|
55
|
+
nonce: string;
|
|
56
|
+
gas: any;
|
|
57
|
+
targetContract: string;
|
|
58
|
+
paymasterAndData?: string;
|
|
59
|
+
}): UserOperation;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Create a PayID policy engine instance backed by a WASM rule evaluator.
|
|
64
|
+
*
|
|
65
|
+
* ## Responsibility
|
|
66
|
+
*
|
|
67
|
+
* - Holds the WASM binary used for rule execution
|
|
68
|
+
* - Defines the trust boundary for context attestation verification
|
|
69
|
+
* - Acts as the primary entry point for PayID rule evaluation
|
|
70
|
+
*
|
|
71
|
+
* ## Trust model
|
|
72
|
+
*
|
|
73
|
+
* - If `trustedIssuers` is provided, Context V2 attestation
|
|
74
|
+
* verification is ENFORCED.
|
|
75
|
+
* - If `trustedIssuers` is omitted, the engine runs in
|
|
76
|
+
* legacy (Context V1) mode without cryptographic verification.
|
|
77
|
+
*
|
|
78
|
+
* ## Environment
|
|
79
|
+
*
|
|
80
|
+
* This class is safe to instantiate in:
|
|
81
|
+
* - Browsers
|
|
82
|
+
* - Mobile apps
|
|
83
|
+
* - Edge runtimes
|
|
84
|
+
* - Backend services
|
|
85
|
+
*
|
|
86
|
+
* @param wasm
|
|
87
|
+
* Compiled PayID WASM rule engine binary.
|
|
88
|
+
*
|
|
89
|
+
* @param debugTrace
|
|
90
|
+
* Optional flag to enable decision trace generation for debugging.
|
|
91
|
+
*
|
|
92
|
+
* @param trustedIssuers
|
|
93
|
+
* Optional set of trusted attestation issuer addresses.
|
|
94
|
+
*
|
|
95
|
+
* When provided, Context V2 attestation verification is ENFORCED:
|
|
96
|
+
* - Only attestations issued by addresses in this set are accepted.
|
|
97
|
+
* - Missing, expired, or invalid attestations cause evaluation to fail.
|
|
98
|
+
*
|
|
99
|
+
* When omitted, the engine runs in legacy (Context V1) mode
|
|
100
|
+
* without cryptographic verification.
|
|
101
|
+
*
|
|
102
|
+
* ⚠️ Important:
|
|
103
|
+
* - Do NOT pass an empty Set.
|
|
104
|
+
* An empty set means "no issuer is trusted" and will
|
|
105
|
+
* cause all attestations to be rejected.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* const trustedIssuers = new Set([
|
|
110
|
+
* TIME_ISSUER,
|
|
111
|
+
* STATE_ISSUER,
|
|
112
|
+
* ORACLE_ISSUER,
|
|
113
|
+
* RISK_ISSUER
|
|
114
|
+
* ]);
|
|
115
|
+
*
|
|
116
|
+
* const payid = new PayID(wasmBinary, debugTrace, trustedIssuers);
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function createPayID(params: {
|
|
120
|
+
wasm: Uint8Array;
|
|
121
|
+
debugTrace?: boolean;
|
|
122
|
+
trustedIssuers?: Set<string>;
|
|
123
|
+
}): PayIDClient & PayIDServer;
|
|
124
|
+
|
|
125
|
+
export { type PayIDClient, type PayIDServer, createPayID };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,303 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
context_exports
|
|
3
|
+
} from "./chunk-RCXMRX4F.js";
|
|
4
|
+
import {
|
|
5
|
+
issuer_exports
|
|
6
|
+
} from "./chunk-AOKLY2QN.js";
|
|
7
|
+
import "./chunk-7U3P7XJE.js";
|
|
8
|
+
import {
|
|
9
|
+
rule_exports
|
|
10
|
+
} from "./chunk-JRVCGSKK.js";
|
|
11
|
+
import {
|
|
12
|
+
sessionPolicy_exports
|
|
13
|
+
} from "./chunk-ATWJEWZH.js";
|
|
14
|
+
import {
|
|
15
|
+
client_exports
|
|
16
|
+
} from "./chunk-XWOB3JVE.js";
|
|
17
|
+
import "./chunk-QYH3FNQ4.js";
|
|
18
|
+
import "./chunk-MXKZJKXE.js";
|
|
19
|
+
import "./chunk-JJEWYFOV.js";
|
|
20
|
+
import {
|
|
21
|
+
server_exports
|
|
22
|
+
} from "./chunk-FIMJNWJ3.js";
|
|
23
|
+
import {
|
|
24
|
+
evaluate,
|
|
25
|
+
generateDecisionProof,
|
|
26
|
+
resolveRule
|
|
27
|
+
} from "./chunk-4MPVXPLM.js";
|
|
28
|
+
import "./chunk-5ZEKI5Y2.js";
|
|
29
|
+
import "./chunk-R5U7XKVJ.js";
|
|
30
|
+
|
|
31
|
+
// src/erc4337/build.ts
|
|
32
|
+
import { ethers } from "ethers";
|
|
33
|
+
function buildPayCallData(contractAddress, proof) {
|
|
34
|
+
const iface = new ethers.Interface([
|
|
35
|
+
"function pay(bytes payload, bytes signature)"
|
|
36
|
+
]);
|
|
37
|
+
return iface.encodeFunctionData("pay", [
|
|
38
|
+
ethers.toUtf8Bytes(JSON.stringify(proof.payload)),
|
|
39
|
+
proof.signature
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/erc4337/userop.ts
|
|
44
|
+
function buildUserOperation(params) {
|
|
45
|
+
return {
|
|
46
|
+
sender: params.sender,
|
|
47
|
+
nonce: params.nonce,
|
|
48
|
+
initCode: params.initCode ?? "0x",
|
|
49
|
+
callData: params.callData,
|
|
50
|
+
callGasLimit: params.gas.callGasLimit,
|
|
51
|
+
verificationGasLimit: params.gas.verificationGasLimit,
|
|
52
|
+
preVerificationGas: params.gas.preVerificationGas,
|
|
53
|
+
maxFeePerGas: params.gas.maxFeePerGas,
|
|
54
|
+
maxPriorityFeePerGas: params.gas.maxPriorityFeePerGas,
|
|
55
|
+
paymasterAndData: params.paymasterAndData ?? "0x",
|
|
56
|
+
signature: "0x"
|
|
57
|
+
// signed later by smart account
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/core/payid.ts
|
|
62
|
+
function isRuleSource(rule) {
|
|
63
|
+
return typeof rule === "object" && rule !== null && "uri" in rule;
|
|
64
|
+
}
|
|
65
|
+
var PayID = class {
|
|
66
|
+
constructor(wasm, debugTrace, trustedIssuers) {
|
|
67
|
+
this.wasm = wasm;
|
|
68
|
+
this.debugTrace = debugTrace;
|
|
69
|
+
this.trustedIssuers = trustedIssuers;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Evaluate a rule set against a given context using the PayID WASM engine.
|
|
73
|
+
*
|
|
74
|
+
* ## Responsibility
|
|
75
|
+
*
|
|
76
|
+
* This method performs **pure rule evaluation only**:
|
|
77
|
+
* - Resolves the rule configuration (inline or via RuleSource)
|
|
78
|
+
* - Executes the rule engine
|
|
79
|
+
* - Returns an ALLOW / REJECT decision
|
|
80
|
+
*
|
|
81
|
+
* This method does NOT:
|
|
82
|
+
* - Generate decision proofs
|
|
83
|
+
* - Interact with on-chain rule registries
|
|
84
|
+
* - Enforce rule ownership or authority
|
|
85
|
+
* - Perform any signing
|
|
86
|
+
*
|
|
87
|
+
* ## Environment
|
|
88
|
+
*
|
|
89
|
+
* This method is **client-safe** and may be called from:
|
|
90
|
+
* - Browsers
|
|
91
|
+
* - Mobile apps
|
|
92
|
+
* - Edge runtimes
|
|
93
|
+
* - Backend services
|
|
94
|
+
*
|
|
95
|
+
* ## Rule source behavior
|
|
96
|
+
*
|
|
97
|
+
* - If `rule` is a `RuleConfig`, it is evaluated directly.
|
|
98
|
+
* - If `rule` is a `RuleSource`, it is resolved off-chain
|
|
99
|
+
* before evaluation.
|
|
100
|
+
*
|
|
101
|
+
* @param context
|
|
102
|
+
* Rule execution context (transaction data, payId, etc.).
|
|
103
|
+
*
|
|
104
|
+
* @param rule
|
|
105
|
+
* Rule configuration to evaluate, either:
|
|
106
|
+
* - An inline `RuleConfig`, or
|
|
107
|
+
* - A `RuleSource` that resolves to a `RuleConfig`.
|
|
108
|
+
*
|
|
109
|
+
* @returns
|
|
110
|
+
* A `RuleResult` indicating whether the rule allows or
|
|
111
|
+
* rejects the given context.
|
|
112
|
+
*
|
|
113
|
+
* @throws
|
|
114
|
+
* May throw if rule resolution or evaluation fails.
|
|
115
|
+
*/
|
|
116
|
+
async evaluate(context, rule) {
|
|
117
|
+
const config = isRuleSource(rule) ? (await resolveRule(rule)).config : rule;
|
|
118
|
+
return evaluate(this.wasm, context, config, { debug: this.debugTrace, trustedIssuers: this.trustedIssuers });
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Evaluate a payment intent against PayID rules and (if allowed)
|
|
122
|
+
* generate an off-chain Decision Proof for on-chain verification.
|
|
123
|
+
*
|
|
124
|
+
* ## Conceptual model
|
|
125
|
+
*
|
|
126
|
+
* - `authorityRule` defines the **authoritative rule set**
|
|
127
|
+
* registered on-chain (NFT / combined rule).
|
|
128
|
+
* - `evaluationRule` (optional) is an **off-chain override**
|
|
129
|
+
* used only for evaluation (e.g. QR / session / intent rule).
|
|
130
|
+
* - On-chain verification ALWAYS references `authorityRule`.
|
|
131
|
+
*
|
|
132
|
+
* Invariant:
|
|
133
|
+
* - Evaluation may use `authorityRule ∧ evaluationRule`
|
|
134
|
+
* - Proof MUST reference `authorityRule` only
|
|
135
|
+
*
|
|
136
|
+
* @param params
|
|
137
|
+
* @param params.context
|
|
138
|
+
* Normalized rule execution context (tx, payId, etc.)
|
|
139
|
+
*
|
|
140
|
+
* @param params.authorityRule
|
|
141
|
+
* The authoritative rule set owned by the receiver and
|
|
142
|
+
* registered in the on-chain rule registry.
|
|
143
|
+
* This rule defines on-chain sovereignty.
|
|
144
|
+
*
|
|
145
|
+
* @param params.evaluationRule
|
|
146
|
+
* Optional evaluation override applied off-chain only
|
|
147
|
+
* (e.g. QR rule, ephemeral constraint).
|
|
148
|
+
* If omitted, `authorityRule` is used for evaluation.
|
|
149
|
+
*
|
|
150
|
+
* @param params.payId
|
|
151
|
+
* PayID identifier associated with the receiver.
|
|
152
|
+
*
|
|
153
|
+
* @param params.payer
|
|
154
|
+
* Address initiating the payment and signing the decision proof.
|
|
155
|
+
*
|
|
156
|
+
* @param params.receiver
|
|
157
|
+
* Address receiving the payment and owning the authoritative rule.
|
|
158
|
+
*
|
|
159
|
+
* @param params.asset
|
|
160
|
+
* Asset address to be transferred (address(0) for native ETH).
|
|
161
|
+
*
|
|
162
|
+
* @param params.amount
|
|
163
|
+
* Amount to be transferred (uint256 semantics).
|
|
164
|
+
*
|
|
165
|
+
* @param params.signer
|
|
166
|
+
* Signer corresponding to `payer`, used to sign the EIP-712
|
|
167
|
+
* decision proof payload.
|
|
168
|
+
*
|
|
169
|
+
* @param params.ruleRegistryContract
|
|
170
|
+
* Address of the on-chain rule registry / storage contract
|
|
171
|
+
* used by the verifier to resolve `ruleSetHash`.
|
|
172
|
+
*
|
|
173
|
+
* @param params.ttlSeconds
|
|
174
|
+
* Optional proof validity duration (seconds).
|
|
175
|
+
* Defaults to implementation-defined TTL.
|
|
176
|
+
*
|
|
177
|
+
* @returns
|
|
178
|
+
* An object containing:
|
|
179
|
+
* - `result`: rule evaluation result (ALLOW / REJECT)
|
|
180
|
+
* - `proof`: signed decision proof if allowed, otherwise `null`
|
|
181
|
+
*
|
|
182
|
+
* @throws
|
|
183
|
+
* May throw if rule resolution, evaluation, or signing fails.
|
|
184
|
+
*/
|
|
185
|
+
async evaluateAndProve(params) {
|
|
186
|
+
const authorityConfig = isRuleSource(params.authorityRule) ? (await resolveRule(params.authorityRule)).config : params.authorityRule;
|
|
187
|
+
const evalConfig = params.evaluationRule ?? authorityConfig;
|
|
188
|
+
const result = await evaluate(
|
|
189
|
+
this.wasm,
|
|
190
|
+
params.context,
|
|
191
|
+
evalConfig,
|
|
192
|
+
{
|
|
193
|
+
debug: this.debugTrace,
|
|
194
|
+
trustedIssuers: this.trustedIssuers
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
if (result.decision !== "ALLOW") {
|
|
198
|
+
return { result, proof: null };
|
|
199
|
+
}
|
|
200
|
+
const proof = await generateDecisionProof({
|
|
201
|
+
payId: params.payId,
|
|
202
|
+
payer: params.payer,
|
|
203
|
+
receiver: params.receiver,
|
|
204
|
+
asset: params.asset,
|
|
205
|
+
amount: params.amount,
|
|
206
|
+
context: params.context,
|
|
207
|
+
ruleConfig: authorityConfig,
|
|
208
|
+
signer: params.signer,
|
|
209
|
+
verifyingContract: params.verifyingContract,
|
|
210
|
+
ruleRegistryContract: params.ruleRegistryContract,
|
|
211
|
+
ttlSeconds: params.ttlSeconds
|
|
212
|
+
});
|
|
213
|
+
return { result, proof };
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Build an ERC-4337 UserOperation that executes a PayID payment
|
|
217
|
+
* using a previously generated Decision Proof.
|
|
218
|
+
*
|
|
219
|
+
* ## Responsibility
|
|
220
|
+
*
|
|
221
|
+
* This function:
|
|
222
|
+
* - Encodes the PayID `pay(...)` calldata using the provided proof
|
|
223
|
+
* - Wraps it into an ERC-4337 UserOperation
|
|
224
|
+
*
|
|
225
|
+
* This function does NOT:
|
|
226
|
+
* - Evaluate rules
|
|
227
|
+
* - Generate decision proofs
|
|
228
|
+
* - Perform any signature validation
|
|
229
|
+
*
|
|
230
|
+
* ## Environment constraint
|
|
231
|
+
*
|
|
232
|
+
* This function is **server-only** and MUST NOT be called in a browser:
|
|
233
|
+
* - It is intended for bundlers, relayers, or backend services
|
|
234
|
+
* - Client-side apps should only generate the proof
|
|
235
|
+
*
|
|
236
|
+
* A runtime guard is enforced to prevent accidental browser usage.
|
|
237
|
+
*
|
|
238
|
+
* @param params
|
|
239
|
+
* @param params.proof
|
|
240
|
+
* A valid Decision Proof generated by `evaluateAndProve`.
|
|
241
|
+
*
|
|
242
|
+
* @param params.smartAccount
|
|
243
|
+
* The ERC-4337 smart account address that will submit the UserOperation.
|
|
244
|
+
*
|
|
245
|
+
* @param params.nonce
|
|
246
|
+
* Current nonce of the smart account.
|
|
247
|
+
*
|
|
248
|
+
* @param params.gas
|
|
249
|
+
* Gas parameters for the UserOperation
|
|
250
|
+
* (callGasLimit, verificationGasLimit, preVerificationGas,
|
|
251
|
+
* maxFeePerGas, maxPriorityFeePerGas).
|
|
252
|
+
*
|
|
253
|
+
* @param params.targetContract
|
|
254
|
+
* Address of the PayID-compatible payment contract
|
|
255
|
+
* (e.g. PayWithPayID).
|
|
256
|
+
*
|
|
257
|
+
* @param params.paymasterAndData
|
|
258
|
+
* Optional paymaster data for sponsored transactions.
|
|
259
|
+
*
|
|
260
|
+
* @returns
|
|
261
|
+
* A fully constructed ERC-4337 UserOperation ready to be
|
|
262
|
+
* submitted to a bundler.
|
|
263
|
+
*
|
|
264
|
+
* @throws
|
|
265
|
+
* Throws if called in a browser environment.
|
|
266
|
+
*/
|
|
267
|
+
buildUserOperation(params) {
|
|
268
|
+
if (typeof globalThis !== "undefined" && "document" in globalThis) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
"buildUserOperation must not be called in browser"
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
const callData = buildPayCallData(
|
|
274
|
+
params.targetContract,
|
|
275
|
+
params.proof
|
|
276
|
+
);
|
|
277
|
+
return buildUserOperation({
|
|
278
|
+
sender: params.smartAccount,
|
|
279
|
+
nonce: params.nonce,
|
|
280
|
+
callData,
|
|
281
|
+
gas: params.gas,
|
|
282
|
+
paymasterAndData: params.paymasterAndData
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// src/factory.ts
|
|
288
|
+
function createPayID(params) {
|
|
289
|
+
return new PayID(
|
|
290
|
+
params.wasm,
|
|
291
|
+
params.debugTrace ?? false,
|
|
292
|
+
params.trustedIssuers
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
export {
|
|
296
|
+
server_exports as client,
|
|
297
|
+
context_exports as context,
|
|
298
|
+
createPayID,
|
|
299
|
+
issuer_exports as issuer,
|
|
300
|
+
rule_exports as rule,
|
|
301
|
+
client_exports as server,
|
|
302
|
+
sessionPolicy_exports as sessionPolicy
|
|
303
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface DecisionPayload {
|
|
2
|
+
version: string;
|
|
3
|
+
payId: string;
|
|
4
|
+
payer: string;
|
|
5
|
+
receiver: string;
|
|
6
|
+
asset: string;
|
|
7
|
+
amount: bigint;
|
|
8
|
+
contextHash: string;
|
|
9
|
+
ruleSetHash: string;
|
|
10
|
+
ruleAuthority: string;
|
|
11
|
+
issuedAt: bigint;
|
|
12
|
+
expiresAt: bigint;
|
|
13
|
+
nonce: string;
|
|
14
|
+
requiresAttestation: boolean;
|
|
15
|
+
}
|
|
16
|
+
interface DecisionProof {
|
|
17
|
+
payload: DecisionPayload;
|
|
18
|
+
signature: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type { DecisionProof as D };
|
|
@@ -0,0 +1,15 @@
|
|
|
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 };
|