payid 0.5.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-AUW7WDAB.js +198 -0
- package/dist/{chunk-SSO66YQI.js → chunk-E6VQETBC.js} +13 -0
- package/dist/{chunk-AYJYFAXJ.js → chunk-ESTGPUEQ.js} +24 -21
- package/dist/{chunk-ROBSNIIZ.js → chunk-EZ3BGZ7G.js} +25 -16
- package/dist/chunk-FZNMDGVK.js +24 -0
- package/dist/chunk-HKHRYRD6.js +752 -0
- package/dist/chunk-X7NYQ47Y.js +27 -0
- package/dist/chunk-XMUHMJRD.js +30 -0
- package/dist/context/index.d.ts +3 -2
- package/dist/context.v1-C1m-tz0o.d.ts +39 -0
- package/dist/context.v2-DIzPotmW.d.ts +37 -0
- package/dist/core/client/index.d.ts +5 -4
- package/dist/core/client/index.js +9 -5
- package/dist/core/server/index.d.ts +4 -3
- package/dist/core/server/index.js +7 -4
- package/dist/{index-2JCvey4-.d.ts → index-CDnE3SGM.d.ts} +18 -3
- package/dist/index-CsynGAGv.d.ts +53 -0
- package/dist/{index-Dj9IEios.d.ts → index-CubM9whW.d.ts} +4 -17
- package/dist/{index-C1DHMQA0.d.ts → index-DSxDlF9J.d.ts} +45 -68
- package/dist/{index-BEvnPzzt.d.ts → index-Dm2VdDEB.d.ts} +2 -1
- package/dist/index-G_1SiZJo.d.ts +104 -0
- package/dist/index.d.ts +407 -72
- package/dist/index.js +582 -77
- package/dist/issuer/index.d.ts +3 -2
- package/dist/issuer/index.js +4 -1
- package/dist/rule/index.d.ts +2 -2
- package/dist/rule/index.js +4 -3
- package/dist/rule-a_5ed-93.d.ts +39 -0
- package/dist/sessionPolicy/index.d.ts +3 -3
- package/dist/sessionPolicy/index.js +17 -6
- package/dist/types-D2o6XS7a.d.ts +66 -0
- package/dist/types-i4eTkhWa.d.ts +50 -0
- package/package.json +22 -9
- package/src/rule/engine/rule_engine.wasm +0 -0
- package/dist/chunk-IQNCMOIE.js +0 -47
- package/dist/chunk-MXKZJKXE.js +0 -33
- package/dist/chunk-PAJYP7JI.js +0 -308
- package/dist/chunk-QC24X74O.js +0 -41
- package/dist/index-BPJ_oOfy.d.ts +0 -81
- package/dist/index-BQQnMG2H.d.ts +0 -114
- package/dist/types-B8pJQdMQ.d.ts +0 -26
- package/dist/types-BmMf7udp.d.ts +0 -13
package/dist/issuer/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { a as issueEnvContext, b as issueOracleContext, c as issueRiskContext, d as issueStateContext, s as signAttestation } from '../index-
|
|
2
|
-
import '
|
|
1
|
+
export { a as issueEnvContext, b as issueOracleContext, c as issueRiskContext, d as issueStateContext, e as issueTokenPriceContext, s as signAttestation } from '../index-CDnE3SGM.js';
|
|
2
|
+
import '../context.v2-DIzPotmW.js';
|
|
3
|
+
import '../context.v1-C1m-tz0o.js';
|
|
3
4
|
import 'ethers';
|
package/dist/issuer/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
issueTokenPriceContext
|
|
3
|
+
} from "../chunk-E6VQETBC.js";
|
|
2
4
|
import {
|
|
3
5
|
issueEnvContext,
|
|
4
6
|
issueOracleContext,
|
|
@@ -12,5 +14,6 @@ export {
|
|
|
12
14
|
issueOracleContext,
|
|
13
15
|
issueRiskContext,
|
|
14
16
|
issueStateContext,
|
|
17
|
+
issueTokenPriceContext,
|
|
15
18
|
signAttestation
|
|
16
19
|
};
|
package/dist/rule/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import '
|
|
1
|
+
export { c as canonicalizeRuleSet, a as combineRules, h as hashRuleSet } from '../index-CubM9whW.js';
|
|
2
|
+
import '../rule-a_5ed-93.js';
|
package/dist/rule/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
hashRuleSet
|
|
3
|
-
} from "../chunk-QC24X74O.js";
|
|
1
|
+
import "../chunk-FZNMDGVK.js";
|
|
4
2
|
import {
|
|
5
3
|
combineRules
|
|
6
4
|
} from "../chunk-GG34PNTF.js";
|
|
7
5
|
import {
|
|
8
6
|
canonicalizeRuleSet
|
|
9
7
|
} from "../chunk-6VPSJFO4.js";
|
|
8
|
+
import {
|
|
9
|
+
hashRuleSet
|
|
10
|
+
} from "../chunk-X7NYQ47Y.js";
|
|
10
11
|
import "../chunk-MLKGABMK.js";
|
|
11
12
|
export {
|
|
12
13
|
canonicalizeRuleSet,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
interface RuleCondition {
|
|
2
|
+
field: string;
|
|
3
|
+
op: string;
|
|
4
|
+
/** Literal value OR cross-field reference prefixed with "$" (e.g. "$state.dailyLimit") */
|
|
5
|
+
value: any;
|
|
6
|
+
}
|
|
7
|
+
interface SimpleRule {
|
|
8
|
+
id: string;
|
|
9
|
+
if: RuleCondition;
|
|
10
|
+
message?: string;
|
|
11
|
+
}
|
|
12
|
+
interface MultiConditionRule {
|
|
13
|
+
id: string;
|
|
14
|
+
logic: "AND" | "OR";
|
|
15
|
+
conditions: RuleCondition[];
|
|
16
|
+
message?: string;
|
|
17
|
+
}
|
|
18
|
+
interface NestedRule {
|
|
19
|
+
id: string;
|
|
20
|
+
logic: "AND" | "OR";
|
|
21
|
+
rules: AnyRule[];
|
|
22
|
+
message?: string;
|
|
23
|
+
}
|
|
24
|
+
type AnyRule = SimpleRule | MultiConditionRule | NestedRule;
|
|
25
|
+
declare function isSimpleRule(rule: AnyRule): rule is SimpleRule;
|
|
26
|
+
declare function isMultiConditionRule(rule: AnyRule): rule is MultiConditionRule;
|
|
27
|
+
declare function isNestedRule(rule: AnyRule): rule is NestedRule;
|
|
28
|
+
interface RuleConfig {
|
|
29
|
+
version?: string;
|
|
30
|
+
logic: "AND" | "OR";
|
|
31
|
+
rules: AnyRule[];
|
|
32
|
+
/** Optional list of required context namespaces (e.g. ["oracle", "risk"]) */
|
|
33
|
+
requires?: string[];
|
|
34
|
+
message?: string;
|
|
35
|
+
}
|
|
36
|
+
/** @deprecated Use AnyRule instead */
|
|
37
|
+
type Rule = AnyRule;
|
|
38
|
+
|
|
39
|
+
export { type AnyRule as A, type MultiConditionRule as M, type NestedRule as N, type Rule as R, type SimpleRule as S, type RuleCondition as a, type RuleConfig as b, isNestedRule as c, isSimpleRule as d, isMultiConditionRule as i };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { c as createSessionPolicyPayload, d as decodeSessionPolicy } from '../index-
|
|
2
|
-
export { P as PayIDSessionPolicyPayloadV1 } from '../types-
|
|
1
|
+
export { S as SESSION_POLICY_V2_TYPES, b as buildSessionPolicyV2Domain, c as createSessionPolicyPayload, a as createSessionPolicyV2, d as decodeSessionPolicy, e as decodeSessionPolicyV2, f as decodeSessionPolicyV2QR, g as encodeSessionPolicyV2QR } from '../index-G_1SiZJo.js';
|
|
2
|
+
export { P as PayIDSessionPolicyPayloadV1, S as SessionPolicyV2 } from '../types-D2o6XS7a.js';
|
|
3
3
|
import 'ethers';
|
|
4
|
-
import '
|
|
4
|
+
import '../rule-a_5ed-93.js';
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
+
import "../chunk-XMUHMJRD.js";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
SESSION_POLICY_V2_TYPES,
|
|
4
|
+
buildSessionPolicyV2Domain,
|
|
5
|
+
createSessionPolicyPayload,
|
|
6
|
+
createSessionPolicyV2,
|
|
7
|
+
decodeSessionPolicy,
|
|
8
|
+
decodeSessionPolicyV2,
|
|
9
|
+
decodeSessionPolicyV2QR,
|
|
10
|
+
encodeSessionPolicyV2QR
|
|
11
|
+
} from "../chunk-AUW7WDAB.js";
|
|
7
12
|
import "../chunk-6VPSJFO4.js";
|
|
8
13
|
import "../chunk-KDC67LIN.js";
|
|
9
14
|
import "../chunk-MLKGABMK.js";
|
|
10
15
|
export {
|
|
16
|
+
SESSION_POLICY_V2_TYPES,
|
|
17
|
+
buildSessionPolicyV2Domain,
|
|
11
18
|
createSessionPolicyPayload,
|
|
12
|
-
|
|
19
|
+
createSessionPolicyV2,
|
|
20
|
+
decodeSessionPolicy,
|
|
21
|
+
decodeSessionPolicyV2,
|
|
22
|
+
decodeSessionPolicyV2QR,
|
|
23
|
+
encodeSessionPolicyV2QR
|
|
13
24
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { b as RuleConfig } from './rule-a_5ed-93.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SessionPolicy V1 — off-chain only, rule injected inline.
|
|
5
|
+
*
|
|
6
|
+
* @deprecated Use SessionPolicyV2 for new implementations.
|
|
7
|
+
* V1 tidak ada chain binding (chainId, verifyingContract) sehingga
|
|
8
|
+
* policy bisa di-replay di chain lain, dan tidak ada constraint
|
|
9
|
+
* ruleSetHash / maxAmount.
|
|
10
|
+
*/
|
|
11
|
+
interface PayIDSessionPolicyPayloadV1 {
|
|
12
|
+
version: "payid.session.policy.v1" | string;
|
|
13
|
+
receiver: string;
|
|
14
|
+
rule: RuleConfig;
|
|
15
|
+
expiresAt: number;
|
|
16
|
+
nonce: string;
|
|
17
|
+
issuedAt: number;
|
|
18
|
+
signature: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* SessionPolicyV2 — Channel A, on-chain rule binding.
|
|
22
|
+
*
|
|
23
|
+
* Perbedaan dari V1:
|
|
24
|
+
*
|
|
25
|
+
* 1. ruleSetHash + ruleAuthority
|
|
26
|
+
* Receiver commit ke rule set yang terdaftar on-chain.
|
|
27
|
+
* Payer tidak bisa swap rule dengan yang lebih longgar.
|
|
28
|
+
*
|
|
29
|
+
* 2. allowedAsset + maxAmount
|
|
30
|
+
* Receiver set constraint token dan batas amount.
|
|
31
|
+
* Payer tidak bisa melebihi maxAmount atau pakai token lain.
|
|
32
|
+
*
|
|
33
|
+
* 3. chainId + verifyingContract (EIP-712 domain)
|
|
34
|
+
* Policy di-bind ke chain dan contract tertentu.
|
|
35
|
+
* Policy tidak bisa di-replay di chain lain.
|
|
36
|
+
*
|
|
37
|
+
* 4. Signed via EIP-712 (bukan raw keccak256)
|
|
38
|
+
* Type-safe, human-readable di wallet UI, standard.
|
|
39
|
+
*/
|
|
40
|
+
interface SessionPolicyV2 {
|
|
41
|
+
version: "payid.session.policy.v2";
|
|
42
|
+
/** Receiver address — pemilik policy */
|
|
43
|
+
receiver: string;
|
|
44
|
+
/** ruleSetHash dari CombinedRuleStorage — binding ke rule on-chain */
|
|
45
|
+
ruleSetHash: string;
|
|
46
|
+
/** CombinedRuleStorage address — authority rule */
|
|
47
|
+
ruleAuthority: string;
|
|
48
|
+
/** Token address yang diizinkan. ZeroAddress = ETH. */
|
|
49
|
+
allowedAsset: string;
|
|
50
|
+
/** Max amount per transaksi (string karena bigint tidak JSON-safe) */
|
|
51
|
+
maxAmount: string;
|
|
52
|
+
/** Unix timestamp expiry */
|
|
53
|
+
expiresAt: number;
|
|
54
|
+
/** Nonce unik per policy — anti-replay */
|
|
55
|
+
policyNonce: string;
|
|
56
|
+
/** PAY.ID identifier string (e.g. "pay.id/toko-budi") */
|
|
57
|
+
payId: string;
|
|
58
|
+
/** Chain ID — bagian dari EIP-712 domain */
|
|
59
|
+
chainId: number;
|
|
60
|
+
/** PayIDVerifier contract address — bagian dari EIP-712 domain */
|
|
61
|
+
verifyingContract: string;
|
|
62
|
+
/** EIP-712 signature dari receiver */
|
|
63
|
+
signature: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type { PayIDSessionPolicyPayloadV1 as P, SessionPolicyV2 as S };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
interface RuleResult {
|
|
2
|
+
decision: "ALLOW" | "REJECT";
|
|
3
|
+
code: string;
|
|
4
|
+
reason?: string;
|
|
5
|
+
}
|
|
6
|
+
interface RuleTraceEntry {
|
|
7
|
+
ruleId: string;
|
|
8
|
+
field: string;
|
|
9
|
+
op: string;
|
|
10
|
+
expected: any;
|
|
11
|
+
actual: any;
|
|
12
|
+
result: "PASS" | "FAIL";
|
|
13
|
+
}
|
|
14
|
+
interface RuleDecisionDebug {
|
|
15
|
+
trace: RuleTraceEntry[];
|
|
16
|
+
}
|
|
17
|
+
interface RuleResultDebug extends RuleResult {
|
|
18
|
+
debug?: RuleDecisionDebug;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface DecisionPayload {
|
|
22
|
+
version: string;
|
|
23
|
+
payId: string;
|
|
24
|
+
payer: string;
|
|
25
|
+
receiver: string;
|
|
26
|
+
asset: string;
|
|
27
|
+
amount: bigint;
|
|
28
|
+
contextHash: string;
|
|
29
|
+
ruleSetHash: string;
|
|
30
|
+
ruleAuthority: string;
|
|
31
|
+
issuedAt: bigint;
|
|
32
|
+
expiresAt: bigint;
|
|
33
|
+
nonce: string;
|
|
34
|
+
requiresAttestation: boolean;
|
|
35
|
+
attestationUIDsHash: string;
|
|
36
|
+
}
|
|
37
|
+
interface DecisionProof {
|
|
38
|
+
payload: DecisionPayload;
|
|
39
|
+
signature: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface RuleSource {
|
|
43
|
+
uri: string;
|
|
44
|
+
hash?: string;
|
|
45
|
+
}
|
|
46
|
+
interface ResolverOptions {
|
|
47
|
+
zgIndexerUrl?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type { DecisionPayload as D, ResolverOptions as R, DecisionProof as a, RuleDecisionDebug as b, RuleResult as c, RuleResultDebug as d, RuleSource as e, RuleTraceEntry as f };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -36,31 +36,44 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
|
-
"dist"
|
|
39
|
+
"dist",
|
|
40
|
+
"src/rule/engine/rule_engine.wasm"
|
|
40
41
|
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"type-check": "tsc --noEmit",
|
|
45
|
+
"test": "echo 'No unit tests — add test files to run with bun test'",
|
|
46
|
+
"prepublishOnly": "bun run type-check && bun run test && bun run build",
|
|
47
|
+
"release": "release-it",
|
|
48
|
+
"release:dry": "release-it --dry-run",
|
|
49
|
+
"release:patch": "release-it patch --no-git.requireCleanWorkingDir",
|
|
50
|
+
"release:minor": "release-it minor --no-git.requireCleanWorkingDir",
|
|
51
|
+
"release:major": "release-it major --no-git.requireCleanWorkingDir"
|
|
52
|
+
},
|
|
41
53
|
"dependencies": {
|
|
54
|
+
"@0gfoundation/0g-storage-ts-sdk": "^1.2.9",
|
|
42
55
|
"ethers": "^6.16.0",
|
|
43
|
-
"
|
|
44
|
-
"payid-types": "^0.2.2"
|
|
56
|
+
"wasi": "^0.0.6"
|
|
45
57
|
},
|
|
46
58
|
"peerDependencies": {
|
|
47
59
|
"typescript": "^5.9.3"
|
|
48
60
|
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"build": "tsup"
|
|
51
|
-
},
|
|
52
61
|
"devDependencies": {
|
|
53
62
|
"@types/bun": "latest",
|
|
63
|
+
"release-it": "^20.0.1",
|
|
54
64
|
"tsup": "^8.5.1"
|
|
55
65
|
},
|
|
56
|
-
"description": "
|
|
66
|
+
"description": "PAY.ID policy engine — evaluate payment rules and generate EIP-712 Decision Proofs",
|
|
57
67
|
"repository": {
|
|
58
68
|
"type": "git",
|
|
59
69
|
"url": "git+https://github.com/Mad1Duck/payid.git"
|
|
60
70
|
},
|
|
61
71
|
"keywords": [
|
|
62
72
|
"payment",
|
|
63
|
-
"policy"
|
|
73
|
+
"policy",
|
|
74
|
+
"eip-712",
|
|
75
|
+
"web3",
|
|
76
|
+
"evm"
|
|
64
77
|
],
|
|
65
78
|
"author": "rahvanna",
|
|
66
79
|
"license": "ISC",
|
|
Binary file
|
package/dist/chunk-IQNCMOIE.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
decodeSessionPolicy
|
|
3
|
-
} from "./chunk-MXKZJKXE.js";
|
|
4
|
-
import {
|
|
5
|
-
canonicalizeRuleSet
|
|
6
|
-
} from "./chunk-6VPSJFO4.js";
|
|
7
|
-
import {
|
|
8
|
-
randomHex
|
|
9
|
-
} from "./chunk-KDC67LIN.js";
|
|
10
|
-
import {
|
|
11
|
-
__export
|
|
12
|
-
} from "./chunk-MLKGABMK.js";
|
|
13
|
-
|
|
14
|
-
// src/sessionPolicy/index.ts
|
|
15
|
-
var sessionPolicy_exports = {};
|
|
16
|
-
__export(sessionPolicy_exports, {
|
|
17
|
-
createSessionPolicyPayload: () => createSessionPolicyPayload,
|
|
18
|
-
decodeSessionPolicy: () => decodeSessionPolicy
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// src/sessionPolicy/create.ts
|
|
22
|
-
import { ethers } from "ethers";
|
|
23
|
-
async function createSessionPolicyPayload(params) {
|
|
24
|
-
const issuedAt = Math.floor(Date.now() / 1e3);
|
|
25
|
-
const nonce = randomHex(16);
|
|
26
|
-
const payload = {
|
|
27
|
-
version: "payid.session.policy.v1",
|
|
28
|
-
receiver: params.receiver,
|
|
29
|
-
rule: canonicalizeRuleSet(params.rule),
|
|
30
|
-
issuedAt,
|
|
31
|
-
expiresAt: params.expiresAt,
|
|
32
|
-
nonce
|
|
33
|
-
};
|
|
34
|
-
const message = ethers.keccak256(
|
|
35
|
-
ethers.toUtf8Bytes(JSON.stringify(payload))
|
|
36
|
-
);
|
|
37
|
-
const signature = await params.signer.signMessage(message);
|
|
38
|
-
return {
|
|
39
|
-
...payload,
|
|
40
|
-
signature
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export {
|
|
45
|
-
createSessionPolicyPayload,
|
|
46
|
-
sessionPolicy_exports
|
|
47
|
-
};
|
package/dist/chunk-MXKZJKXE.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// src/sessionPolicy/decode.ts
|
|
2
|
-
import { ethers } from "ethers";
|
|
3
|
-
function decodeSessionPolicy(sessionPolicy, now) {
|
|
4
|
-
if (sessionPolicy.version !== "payid.session.policy.v1") {
|
|
5
|
-
throw new Error("INVALID_SESSION_POLICY_VERSION");
|
|
6
|
-
}
|
|
7
|
-
if (now > sessionPolicy.expiresAt) {
|
|
8
|
-
throw new Error("SESSION_POLICY_EXPIRED");
|
|
9
|
-
}
|
|
10
|
-
const payload = {
|
|
11
|
-
version: sessionPolicy.version,
|
|
12
|
-
receiver: sessionPolicy.receiver,
|
|
13
|
-
rule: sessionPolicy.rule,
|
|
14
|
-
issuedAt: sessionPolicy.issuedAt,
|
|
15
|
-
expiresAt: sessionPolicy.expiresAt,
|
|
16
|
-
nonce: sessionPolicy.nonce
|
|
17
|
-
};
|
|
18
|
-
const message = ethers.keccak256(
|
|
19
|
-
ethers.toUtf8Bytes(JSON.stringify(payload))
|
|
20
|
-
);
|
|
21
|
-
const recovered = ethers.verifyMessage(
|
|
22
|
-
message,
|
|
23
|
-
sessionPolicy.signature
|
|
24
|
-
);
|
|
25
|
-
if (recovered.toLowerCase() !== sessionPolicy.receiver.toLowerCase()) {
|
|
26
|
-
throw new Error("INVALID_SESSION_POLICY_SIGNATURE");
|
|
27
|
-
}
|
|
28
|
-
return sessionPolicy.rule;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
decodeSessionPolicy
|
|
33
|
-
};
|