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,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
combineRules
|
|
3
|
+
} from "./chunk-QYH3FNQ4.js";
|
|
4
|
+
import {
|
|
5
|
+
decodeSessionPolicy
|
|
6
|
+
} from "./chunk-MXKZJKXE.js";
|
|
7
|
+
import {
|
|
8
|
+
evaluate,
|
|
9
|
+
generateDecisionProof,
|
|
10
|
+
resolveRule
|
|
11
|
+
} from "./chunk-4MPVXPLM.js";
|
|
12
|
+
import {
|
|
13
|
+
__export
|
|
14
|
+
} from "./chunk-R5U7XKVJ.js";
|
|
15
|
+
|
|
16
|
+
// src/core/client/index.ts
|
|
17
|
+
var client_exports = {};
|
|
18
|
+
__export(client_exports, {
|
|
19
|
+
createPayID: () => createPayID
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// src/core/client/client.ts
|
|
23
|
+
import "ethers";
|
|
24
|
+
function isRuleSource(rule) {
|
|
25
|
+
return typeof rule === "object" && rule !== null && "uri" in rule;
|
|
26
|
+
}
|
|
27
|
+
var PayIDClient = class {
|
|
28
|
+
constructor(wasm, debugTrace) {
|
|
29
|
+
this.wasm = wasm;
|
|
30
|
+
this.debugTrace = debugTrace;
|
|
31
|
+
}
|
|
32
|
+
async evaluateAndProve(params) {
|
|
33
|
+
const authorityConfig = isRuleSource(params.authorityRule) ? (await resolveRule(params.authorityRule)).config : params.authorityRule;
|
|
34
|
+
const evalConfig = params.evaluationRule ?? (params.sessionPolicy ? combineRules(
|
|
35
|
+
params.authorityRule,
|
|
36
|
+
decodeSessionPolicy(
|
|
37
|
+
params.sessionPolicy,
|
|
38
|
+
Math.floor(Date.now() / 1e3)
|
|
39
|
+
).rules
|
|
40
|
+
) : params.authorityRule);
|
|
41
|
+
const result = await evaluate(
|
|
42
|
+
this.wasm,
|
|
43
|
+
params.context,
|
|
44
|
+
evalConfig,
|
|
45
|
+
{ debug: this.debugTrace }
|
|
46
|
+
);
|
|
47
|
+
if (result.decision !== "ALLOW") {
|
|
48
|
+
return { result, proof: null };
|
|
49
|
+
}
|
|
50
|
+
const proof = await generateDecisionProof({
|
|
51
|
+
payId: params.payId,
|
|
52
|
+
payer: params.payer,
|
|
53
|
+
receiver: params.receiver,
|
|
54
|
+
asset: params.asset,
|
|
55
|
+
amount: params.amount,
|
|
56
|
+
context: params.context,
|
|
57
|
+
ruleConfig: authorityConfig,
|
|
58
|
+
signer: params.signer,
|
|
59
|
+
verifyingContract: params.verifyingContract,
|
|
60
|
+
ruleRegistryContract: params.ruleRegistryContract,
|
|
61
|
+
ttlSeconds: params.ttlSeconds
|
|
62
|
+
});
|
|
63
|
+
return { result, proof };
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/core/client/index.ts
|
|
68
|
+
function createPayID(params) {
|
|
69
|
+
return new PayIDClient(
|
|
70
|
+
params.wasm,
|
|
71
|
+
params.debugTrace ?? false
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
createPayID,
|
|
77
|
+
client_exports
|
|
78
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPayID
|
|
3
|
+
} from "../../chunk-XWOB3JVE.js";
|
|
4
|
+
import "../../chunk-QYH3FNQ4.js";
|
|
5
|
+
import "../../chunk-MXKZJKXE.js";
|
|
6
|
+
import "../../chunk-JJEWYFOV.js";
|
|
7
|
+
import "../../chunk-4MPVXPLM.js";
|
|
8
|
+
import "../../chunk-5ZEKI5Y2.js";
|
|
9
|
+
import "../../chunk-R5U7XKVJ.js";
|
|
10
|
+
export {
|
|
11
|
+
createPayID
|
|
12
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EnvContext, OracleContext, RiskContext, StateContext, Attestation } from 'payid-types';
|
|
2
|
+
import { Wallet } from 'ethers';
|
|
3
|
+
|
|
4
|
+
declare function issueEnvContext(wallet: Wallet): Promise<EnvContext>;
|
|
5
|
+
|
|
6
|
+
declare function issueOracleContext(wallet: Wallet, data: Record<string, string | number>): Promise<OracleContext>;
|
|
7
|
+
|
|
8
|
+
declare function issueRiskContext(wallet: Wallet, score: number, category: string, modelHash: string): Promise<RiskContext>;
|
|
9
|
+
|
|
10
|
+
declare function issueStateContext(wallet: Wallet, spentToday: string, period: string): Promise<StateContext>;
|
|
11
|
+
|
|
12
|
+
declare function signAttestation(issuerWallet: Wallet, payload: object, ttlSeconds?: number): Promise<Attestation>;
|
|
13
|
+
|
|
14
|
+
declare const index_issueEnvContext: typeof issueEnvContext;
|
|
15
|
+
declare const index_issueOracleContext: typeof issueOracleContext;
|
|
16
|
+
declare const index_issueRiskContext: typeof issueRiskContext;
|
|
17
|
+
declare const index_issueStateContext: typeof issueStateContext;
|
|
18
|
+
declare const index_signAttestation: typeof signAttestation;
|
|
19
|
+
declare namespace index {
|
|
20
|
+
export { index_issueEnvContext as issueEnvContext, index_issueOracleContext as issueOracleContext, index_issueRiskContext as issueRiskContext, index_issueStateContext as issueStateContext, index_signAttestation as signAttestation };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { issueEnvContext as a, issueOracleContext as b, issueRiskContext as c, issueStateContext as d, index as i, signAttestation as s };
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Wallet } from 'ethers';
|
|
2
|
+
import { ContextV1, ContextV2 } from 'payid-types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Build an attested Context V2 object from a base execution context
|
|
6
|
+
* and a set of optional attestation issuers.
|
|
7
|
+
*
|
|
8
|
+
* ## Purpose
|
|
9
|
+
*
|
|
10
|
+
* This function assembles **Context V2**, which extends a raw
|
|
11
|
+
* execution context (Context V1) with **cryptographically attested
|
|
12
|
+
* facts** such as:
|
|
13
|
+
* - Environment data (time, runtime conditions)
|
|
14
|
+
* - Stateful data (daily spend, quotas)
|
|
15
|
+
* - Oracle data (country, FX rate, KYC attributes)
|
|
16
|
+
* - Risk signals (ML score, risk category)
|
|
17
|
+
*
|
|
18
|
+
* The resulting context is suitable for:
|
|
19
|
+
* - Deterministic rule evaluation
|
|
20
|
+
* - Context V2 verification via `preprocessContextV2`
|
|
21
|
+
* - Off-chain decision proof generation
|
|
22
|
+
* - On-chain attestation verification
|
|
23
|
+
*
|
|
24
|
+
* ## Trust model
|
|
25
|
+
*
|
|
26
|
+
* - Each context domain (`env`, `state`, `oracle`, `risk`) MUST be
|
|
27
|
+
* issued and signed by a trusted issuer.
|
|
28
|
+
* - The rule engine does NOT trust raw values; it only trusts
|
|
29
|
+
* verified attestations.
|
|
30
|
+
* - Which domains are required is determined by `ruleConfig.requires`.
|
|
31
|
+
*
|
|
32
|
+
* ## Responsibility
|
|
33
|
+
*
|
|
34
|
+
* This function:
|
|
35
|
+
* - Calls the appropriate issuer functions to generate attestations
|
|
36
|
+
* - Aggregates all issued contexts into a single Context V2 object
|
|
37
|
+
* - Does NOT evaluate rules
|
|
38
|
+
* - Does NOT perform attestation verification
|
|
39
|
+
*
|
|
40
|
+
* ## Environment
|
|
41
|
+
*
|
|
42
|
+
* This function may be called from:
|
|
43
|
+
* - Backend services
|
|
44
|
+
* - Relayers / bundlers
|
|
45
|
+
* - Edge runtimes
|
|
46
|
+
*
|
|
47
|
+
* It SHOULD NOT be called directly from untrusted clients unless
|
|
48
|
+
* issuer keys are properly secured.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ### Minimal Context V2 (env + state only)
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* const contextV2 = await buildContextV2({
|
|
55
|
+
* baseContext: {
|
|
56
|
+
* tx,
|
|
57
|
+
* payId
|
|
58
|
+
* },
|
|
59
|
+
* env: {
|
|
60
|
+
* issuer: envIssuer
|
|
61
|
+
* },
|
|
62
|
+
* state: {
|
|
63
|
+
* issuer: stateIssuer,
|
|
64
|
+
* spentToday: "2500000",
|
|
65
|
+
* period: "DAY"
|
|
66
|
+
* }
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ### Full Context V2 (env + state + oracle + risk)
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* const contextV2 = await buildContextV2({
|
|
75
|
+
* baseContext: {
|
|
76
|
+
* tx,
|
|
77
|
+
* payId
|
|
78
|
+
* },
|
|
79
|
+
* env: {
|
|
80
|
+
* issuer: envIssuer
|
|
81
|
+
* },
|
|
82
|
+
* state: {
|
|
83
|
+
* issuer: stateIssuer,
|
|
84
|
+
* spentToday: "2500000",
|
|
85
|
+
* period: "DAY"
|
|
86
|
+
* },
|
|
87
|
+
* oracle: {
|
|
88
|
+
* issuer: oracleIssuer,
|
|
89
|
+
* data: {
|
|
90
|
+
* country: "ID",
|
|
91
|
+
* fxRate: 15600
|
|
92
|
+
* }
|
|
93
|
+
* },
|
|
94
|
+
* risk: {
|
|
95
|
+
* issuer: riskIssuer,
|
|
96
|
+
* score: 72,
|
|
97
|
+
* category: "MEDIUM",
|
|
98
|
+
* modelHash: "0xmodelhash123"
|
|
99
|
+
* }
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @param params
|
|
104
|
+
* Context assembly parameters.
|
|
105
|
+
*
|
|
106
|
+
* @param params.baseContext
|
|
107
|
+
* Base execution context (Context V1), containing transaction
|
|
108
|
+
* and PayID-related fields.
|
|
109
|
+
*
|
|
110
|
+
* @param params.env
|
|
111
|
+
* Optional environment attestation.
|
|
112
|
+
* Typically used for time-based or runtime constraints.
|
|
113
|
+
*
|
|
114
|
+
* @param params.state
|
|
115
|
+
* Optional state attestation.
|
|
116
|
+
* Used for cumulative values such as daily spend or quota tracking.
|
|
117
|
+
*
|
|
118
|
+
* @param params.oracle
|
|
119
|
+
* Optional oracle attestation.
|
|
120
|
+
* Used for external facts such as country, FX rate, or KYC signals.
|
|
121
|
+
*
|
|
122
|
+
* @param params.risk
|
|
123
|
+
* Optional risk attestation.
|
|
124
|
+
* Used for ML-based risk scoring and categorization.
|
|
125
|
+
*
|
|
126
|
+
* @returns
|
|
127
|
+
* A fully assembled Context V2 object containing the base context
|
|
128
|
+
* and all requested attested sub-contexts.
|
|
129
|
+
*
|
|
130
|
+
* @throws
|
|
131
|
+
* May throw if attestation issuance fails for any domain.
|
|
132
|
+
*/
|
|
133
|
+
declare function buildContextV2(params: {
|
|
134
|
+
baseContext: ContextV1;
|
|
135
|
+
env?: {
|
|
136
|
+
issuer: Wallet;
|
|
137
|
+
};
|
|
138
|
+
state?: {
|
|
139
|
+
issuer: Wallet;
|
|
140
|
+
spentToday: string;
|
|
141
|
+
period: string;
|
|
142
|
+
};
|
|
143
|
+
oracle?: {
|
|
144
|
+
issuer: Wallet;
|
|
145
|
+
data: Record<string, string | number>;
|
|
146
|
+
};
|
|
147
|
+
risk?: {
|
|
148
|
+
issuer: Wallet;
|
|
149
|
+
score: number;
|
|
150
|
+
category: string;
|
|
151
|
+
modelHash: string;
|
|
152
|
+
};
|
|
153
|
+
}): Promise<ContextV2>;
|
|
154
|
+
|
|
155
|
+
declare const index_buildContextV2: typeof buildContextV2;
|
|
156
|
+
declare namespace index {
|
|
157
|
+
export { index_buildContextV2 as buildContextV2 };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export { buildContextV2 as b, index as i };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { RuleContext, RuleConfig, RuleResult } from 'payid-types';
|
|
2
|
+
import { ethers } from 'ethers';
|
|
3
|
+
import { D as DecisionProof } from './types-B5dv7L-8.js';
|
|
4
|
+
import { P as PayIDSessionPolicyPayloadV1 } from './types-DKt-zH0P.js';
|
|
5
|
+
|
|
6
|
+
declare class PayIDClient {
|
|
7
|
+
private readonly wasm;
|
|
8
|
+
private readonly debugTrace?;
|
|
9
|
+
constructor(wasm: Uint8Array, debugTrace?: boolean | undefined);
|
|
10
|
+
evaluateAndProve(params: {
|
|
11
|
+
context: RuleContext;
|
|
12
|
+
authorityRule: RuleConfig;
|
|
13
|
+
evaluationRule?: RuleConfig;
|
|
14
|
+
sessionPolicy?: PayIDSessionPolicyPayloadV1;
|
|
15
|
+
payId: string;
|
|
16
|
+
payer: string;
|
|
17
|
+
receiver: string;
|
|
18
|
+
asset: string;
|
|
19
|
+
amount: bigint;
|
|
20
|
+
signer: ethers.Signer;
|
|
21
|
+
ruleRegistryContract: string;
|
|
22
|
+
verifyingContract: string;
|
|
23
|
+
ttlSeconds?: number;
|
|
24
|
+
}): Promise<{
|
|
25
|
+
result: RuleResult;
|
|
26
|
+
proof: DecisionProof | null;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create a PayID policy engine instance backed by a WASM rule evaluator.
|
|
32
|
+
*
|
|
33
|
+
* ## Responsibility
|
|
34
|
+
*
|
|
35
|
+
* - Holds the WASM binary used for rule execution
|
|
36
|
+
* - Defines the trust boundary for context attestation verification
|
|
37
|
+
* - Acts as the primary entry point for PayID rule evaluation
|
|
38
|
+
*
|
|
39
|
+
* ## Trust model
|
|
40
|
+
*
|
|
41
|
+
* - If `trustedIssuers` is provided, Context V2 attestation
|
|
42
|
+
* verification is ENFORCED.
|
|
43
|
+
* - If `trustedIssuers` is omitted, the engine runs in
|
|
44
|
+
* legacy (Context V1) mode without cryptographic verification.
|
|
45
|
+
*
|
|
46
|
+
* ## Environment
|
|
47
|
+
*
|
|
48
|
+
* This class is safe to instantiate in:
|
|
49
|
+
* - Browsers
|
|
50
|
+
* - Mobile apps
|
|
51
|
+
* - Edge runtimes
|
|
52
|
+
* - Backend services
|
|
53
|
+
*
|
|
54
|
+
* @param wasm
|
|
55
|
+
* Compiled PayID WASM rule engine binary.
|
|
56
|
+
*
|
|
57
|
+
* @param debugTrace
|
|
58
|
+
* Optional flag to enable decision trace generation for debugging.
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
*
|
|
62
|
+
* const payid = new PayID(wasmBinary, debugTrace);
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function createPayID(params: {
|
|
66
|
+
wasm: Uint8Array;
|
|
67
|
+
debugTrace?: boolean;
|
|
68
|
+
}): PayIDClient;
|
|
69
|
+
|
|
70
|
+
declare const index_createPayID: typeof createPayID;
|
|
71
|
+
declare namespace index {
|
|
72
|
+
export { index_createPayID as createPayID };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { createPayID as c, index as i };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { RuleConfig } from 'payid-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Combine an authoritative rule set with additional ephemeral rules
|
|
5
|
+
* for off-chain evaluation.
|
|
6
|
+
*
|
|
7
|
+
* This helper merges:
|
|
8
|
+
* - A **default (authoritative) rule set** owned by the receiver
|
|
9
|
+
* - One or more **ephemeral rule constraints** (e.g. session / QR rules)
|
|
10
|
+
*
|
|
11
|
+
* The resulting rule set is intended **ONLY for off-chain evaluation**
|
|
12
|
+
* and MUST NOT be used as an authoritative rule on-chain.
|
|
13
|
+
*
|
|
14
|
+
* ## Security model
|
|
15
|
+
*
|
|
16
|
+
* - The default rule set defines sovereignty and ownership.
|
|
17
|
+
* - Ephemeral rules can only further restrict behavior
|
|
18
|
+
* (logical AND composition).
|
|
19
|
+
* - Ephemeral rules MUST NOT bypass or weaken default rules.
|
|
20
|
+
*
|
|
21
|
+
* ## Canonicalization
|
|
22
|
+
*
|
|
23
|
+
* - The combined rule set is canonicalized to ensure deterministic
|
|
24
|
+
* hashing and evaluation behavior.
|
|
25
|
+
*
|
|
26
|
+
* ## Invariants
|
|
27
|
+
*
|
|
28
|
+
* - The resulting rule set always uses logical AND semantics.
|
|
29
|
+
* - Rule order is normalized via canonicalization.
|
|
30
|
+
*
|
|
31
|
+
* @param defaultRuleSet
|
|
32
|
+
* The authoritative rule configuration (on-chain registered).
|
|
33
|
+
*
|
|
34
|
+
* @param sessionRule
|
|
35
|
+
* A list of additional rule conditions derived from an ephemeral
|
|
36
|
+
* policy (session, QR, intent, etc.).
|
|
37
|
+
*
|
|
38
|
+
* @returns
|
|
39
|
+
* A canonicalized rule configuration suitable for off-chain
|
|
40
|
+
* evaluation.
|
|
41
|
+
*/
|
|
42
|
+
declare function combineRules(defaultRuleSet: RuleConfig, sessionRule: any[]): {
|
|
43
|
+
version: string;
|
|
44
|
+
logic: "AND" | "OR";
|
|
45
|
+
rules: {
|
|
46
|
+
id: any;
|
|
47
|
+
if: any;
|
|
48
|
+
}[];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Canonicalize a rule set into a deterministic, order-independent form.
|
|
53
|
+
*
|
|
54
|
+
* Canonicalization ensures that semantically identical rule sets
|
|
55
|
+
* always produce the same structural representation, regardless of:
|
|
56
|
+
* - Rule insertion order
|
|
57
|
+
* - Object key order
|
|
58
|
+
* - Nested object layout
|
|
59
|
+
*
|
|
60
|
+
* This function is CRITICAL for:
|
|
61
|
+
* - Rule hashing (`ruleSetHash`)
|
|
62
|
+
* - Policy signing (QR / session / intent)
|
|
63
|
+
* - Consistent off-chain evaluation
|
|
64
|
+
*
|
|
65
|
+
* ## Canonicalization rules
|
|
66
|
+
*
|
|
67
|
+
* - Rules are normalized individually.
|
|
68
|
+
* - Rule entries are sorted lexicographically by `id`.
|
|
69
|
+
* - All nested objects are recursively sorted by key.
|
|
70
|
+
* - Arrays preserve their original order unless explicitly sorted.
|
|
71
|
+
*
|
|
72
|
+
* ## Security model
|
|
73
|
+
*
|
|
74
|
+
* - Canonicalization MUST be applied BEFORE hashing or signing.
|
|
75
|
+
* - Canonicalization MUST NOT be applied during verification
|
|
76
|
+
* (the verified payload must match exactly what was signed).
|
|
77
|
+
*
|
|
78
|
+
* ## Invariants
|
|
79
|
+
*
|
|
80
|
+
* - Canonicalization does NOT change rule semantics.
|
|
81
|
+
* - Canonicalization does NOT weaken rule constraints.
|
|
82
|
+
* - Canonicalization is a pure, deterministic operation.
|
|
83
|
+
*
|
|
84
|
+
* @param ruleSet
|
|
85
|
+
* A rule configuration object containing:
|
|
86
|
+
* - `version`: rule schema version
|
|
87
|
+
* - `logic`: logical operator ("AND" | "OR")
|
|
88
|
+
* - `rules`: list of rule definitions
|
|
89
|
+
*
|
|
90
|
+
* @returns
|
|
91
|
+
* A canonicalized rule configuration suitable for hashing,
|
|
92
|
+
* signing, and deterministic evaluation.
|
|
93
|
+
*/
|
|
94
|
+
declare function canonicalizeRuleSet(ruleSet: {
|
|
95
|
+
version: string;
|
|
96
|
+
logic: "AND" | "OR";
|
|
97
|
+
rules: any[];
|
|
98
|
+
}): {
|
|
99
|
+
version: string;
|
|
100
|
+
logic: "AND" | "OR";
|
|
101
|
+
rules: {
|
|
102
|
+
id: any;
|
|
103
|
+
if: any;
|
|
104
|
+
}[];
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Compute a deterministic hash of a canonicalized rule set.
|
|
109
|
+
*
|
|
110
|
+
* This function produces the `ruleSetHash` used to:
|
|
111
|
+
* - Reference authoritative rules in on-chain registries
|
|
112
|
+
* - Bind decision proofs to a specific rule configuration
|
|
113
|
+
* - Ensure integrity between off-chain evaluation and on-chain verification
|
|
114
|
+
*
|
|
115
|
+
* ## Canonicalization requirement
|
|
116
|
+
*
|
|
117
|
+
* - The input rule set MUST already be canonicalized using
|
|
118
|
+
* `canonicalizeRuleSet`.
|
|
119
|
+
* - Hashing a non-canonical rule set may result in inconsistent
|
|
120
|
+
* hashes for semantically identical rules.
|
|
121
|
+
*
|
|
122
|
+
* ## Security model
|
|
123
|
+
*
|
|
124
|
+
* - The hash represents the exact structure of the rule set at the
|
|
125
|
+
* time of hashing.
|
|
126
|
+
* - Any mutation (key order, rule order, value change) will produce
|
|
127
|
+
* a different hash.
|
|
128
|
+
*
|
|
129
|
+
* ## Invariants
|
|
130
|
+
*
|
|
131
|
+
* - This function does NOT perform canonicalization.
|
|
132
|
+
* - This function is pure and deterministic.
|
|
133
|
+
* - The same canonical rule set will always yield the same hash.
|
|
134
|
+
*
|
|
135
|
+
* @param ruleSet
|
|
136
|
+
* A canonicalized rule configuration object.
|
|
137
|
+
*
|
|
138
|
+
* @returns
|
|
139
|
+
* A `bytes32` hex string (keccak256) uniquely identifying the rule set.
|
|
140
|
+
*/
|
|
141
|
+
declare function hashRuleSet(ruleSet: any): string;
|
|
142
|
+
|
|
143
|
+
declare const index_canonicalizeRuleSet: typeof canonicalizeRuleSet;
|
|
144
|
+
declare const index_combineRules: typeof combineRules;
|
|
145
|
+
declare const index_hashRuleSet: typeof hashRuleSet;
|
|
146
|
+
declare namespace index {
|
|
147
|
+
export { index_canonicalizeRuleSet as canonicalizeRuleSet, index_combineRules as combineRules, index_hashRuleSet as hashRuleSet };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { canonicalizeRuleSet as a, combineRules as c, hashRuleSet as h, index as i };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { RuleContext, RuleConfig, RuleResult } from 'payid-types';
|
|
3
|
+
import { D as DecisionProof } from './types-B5dv7L-8.js';
|
|
4
|
+
|
|
5
|
+
declare class PayIDServer {
|
|
6
|
+
private readonly wasm;
|
|
7
|
+
private readonly signer;
|
|
8
|
+
private readonly trustedIssuers?;
|
|
9
|
+
private readonly debugTrace?;
|
|
10
|
+
constructor(wasm: Uint8Array, signer: ethers.Signer, trustedIssuers?: Set<string> | undefined, debugTrace?: boolean | undefined);
|
|
11
|
+
evaluateAndProve(params: {
|
|
12
|
+
context: RuleContext;
|
|
13
|
+
authorityRule: RuleConfig;
|
|
14
|
+
evaluationRule?: RuleConfig;
|
|
15
|
+
payId: string;
|
|
16
|
+
payer: string;
|
|
17
|
+
receiver: string;
|
|
18
|
+
asset: string;
|
|
19
|
+
amount: bigint;
|
|
20
|
+
ruleRegistryContract: string;
|
|
21
|
+
verifyingContract: string;
|
|
22
|
+
ttlSeconds?: number;
|
|
23
|
+
}): Promise<{
|
|
24
|
+
result: RuleResult;
|
|
25
|
+
proof: DecisionProof | null;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Create a PayID policy engine instance backed by a WASM rule evaluator.
|
|
31
|
+
*
|
|
32
|
+
* ## Responsibility
|
|
33
|
+
*
|
|
34
|
+
* - Holds the WASM binary used for rule execution
|
|
35
|
+
* - Defines the trust boundary for context attestation verification
|
|
36
|
+
* - Acts as the primary entry point for PayID rule evaluation
|
|
37
|
+
*
|
|
38
|
+
* ## Trust model
|
|
39
|
+
*
|
|
40
|
+
* - If `trustedIssuers` is provided, Context V2 attestation
|
|
41
|
+
* verification is ENFORCED.
|
|
42
|
+
* - If `trustedIssuers` is omitted, the engine runs in
|
|
43
|
+
* legacy (Context V1) mode without cryptographic verification.
|
|
44
|
+
*
|
|
45
|
+
* ## Environment
|
|
46
|
+
*
|
|
47
|
+
* This class is safe to instantiate in:
|
|
48
|
+
* - Browsers
|
|
49
|
+
* - Mobile apps
|
|
50
|
+
* - Edge runtimes
|
|
51
|
+
* - Backend services
|
|
52
|
+
*
|
|
53
|
+
* @param wasm
|
|
54
|
+
* Compiled PayID WASM rule engine binary.
|
|
55
|
+
*
|
|
56
|
+
* @param signer
|
|
57
|
+
* Signer account
|
|
58
|
+
*
|
|
59
|
+
* @param debugTrace
|
|
60
|
+
* Optional flag to enable decision trace generation for debugging.
|
|
61
|
+
*
|
|
62
|
+
* @param trustedIssuers
|
|
63
|
+
* Optional set of trusted attestation issuer addresses.
|
|
64
|
+
*
|
|
65
|
+
* When provided, Context V2 attestation verification is ENFORCED:
|
|
66
|
+
* - Only attestations issued by addresses in this set are accepted.
|
|
67
|
+
* - Missing, expired, or invalid attestations cause evaluation to fail.
|
|
68
|
+
*
|
|
69
|
+
* When omitted, the engine runs in legacy (Context V1) mode
|
|
70
|
+
* without cryptographic verification.
|
|
71
|
+
*
|
|
72
|
+
* ⚠️ Important:
|
|
73
|
+
* - Do NOT pass an empty Set.
|
|
74
|
+
* An empty set means "no issuer is trusted" and will
|
|
75
|
+
* cause all attestations to be rejected.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const trustedIssuers = new Set([
|
|
80
|
+
* TIME_ISSUER,
|
|
81
|
+
* STATE_ISSUER,
|
|
82
|
+
* ORACLE_ISSUER,
|
|
83
|
+
* RISK_ISSUER
|
|
84
|
+
* ]);
|
|
85
|
+
*
|
|
86
|
+
* const payid = new PayID(wasmBinary, ethers.Signer, debugTrace, trustedIssuers);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare function createPayID(params: {
|
|
90
|
+
wasm: Uint8Array;
|
|
91
|
+
signer: ethers.Signer;
|
|
92
|
+
debugTrace?: boolean;
|
|
93
|
+
trustedIssuers?: Set<string>;
|
|
94
|
+
}): PayIDServer;
|
|
95
|
+
|
|
96
|
+
declare const index_createPayID: typeof createPayID;
|
|
97
|
+
declare namespace index {
|
|
98
|
+
export { index_createPayID as createPayID };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { createPayID as c, index as i };
|