payid 0.5.0 → 0.5.2

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.
@@ -2,7 +2,7 @@ import {
2
2
  evaluate,
3
3
  generateDecisionProof,
4
4
  resolveRule
5
- } from "./chunk-UBYKCXWR.js";
5
+ } from "./chunk-LHLJP2TB.js";
6
6
  import {
7
7
  __export
8
8
  } from "./chunk-R5U7XKVJ.js";
@@ -8,7 +8,7 @@ import {
8
8
  evaluate,
9
9
  generateDecisionProof,
10
10
  resolveRule
11
- } from "./chunk-UBYKCXWR.js";
11
+ } from "./chunk-LHLJP2TB.js";
12
12
  import {
13
13
  __export
14
14
  } from "./chunk-R5U7XKVJ.js";
@@ -33,16 +33,7 @@ var PayIDClient = class {
33
33
  }).catch(() => {
34
34
  });
35
35
  }
36
- // Preload promise — WASM mulai di-fetch saat createPayID() dipanggil,
37
- // bukan saat evaluate() pertama. Hasilnya di-cache di wasm.ts.
38
36
  _ready;
39
- /**
40
- * Tunggu sampai WASM siap. Opsional — evaluate() akan menunggu sendiri,
41
- * tapi bisa di-await eksplisit untuk warmup:
42
- *
43
- * const client = createPayID();
44
- * await client.ready(); // WASM pasti sudah loaded setelah ini
45
- */
46
37
  async ready() {
47
38
  return this._ready;
48
39
  }
@@ -76,6 +67,7 @@ var PayIDClient = class {
76
67
  amount: params.amount,
77
68
  context: params.context,
78
69
  ruleConfig: authorityConfig,
70
+ ruleSetHashOverride: params.ruleSetHashOverride,
79
71
  signer: params.signer,
80
72
  verifyingContract: params.verifyingContract,
81
73
  ruleAuthority: params.ruleAuthority,
@@ -266,7 +266,7 @@ async function generateDecisionProof(params) {
266
266
  asset: params.asset,
267
267
  amount: params.amount,
268
268
  contextHash: hashContext(params.context),
269
- ruleSetHash: hashRuleSet(params.ruleConfig),
269
+ ruleSetHash: params.ruleSetHashOverride ?? hashRuleSet(params.ruleConfig),
270
270
  ruleAuthority: params.ruleAuthority ?? ZeroAddress,
271
271
  issuedAt: BigInt(issuedAt),
272
272
  expiresAt: BigInt(expiresAt),
@@ -18,9 +18,20 @@ __export(rule_exports, {
18
18
 
19
19
  // src/rule/hash.ts
20
20
  import { keccak256, toUtf8Bytes } from "ethers";
21
+ function stableStringify(obj) {
22
+ if (Array.isArray(obj)) {
23
+ return `[${obj.map(stableStringify).join(",")}]`;
24
+ }
25
+ if (obj && typeof obj === "object") {
26
+ return `{${Object.keys(obj).sort().map(
27
+ (k) => `"${k}":${stableStringify(obj[k])}`
28
+ ).join(",")}}`;
29
+ }
30
+ return JSON.stringify(obj);
31
+ }
21
32
  function hashRuleSet(ruleSet) {
22
33
  return keccak256(
23
- toUtf8Bytes(JSON.stringify(ruleSet))
34
+ toUtf8Bytes(stableStringify(ruleSet))
24
35
  );
25
36
  }
26
37
 
@@ -1,4 +1,4 @@
1
- export { c as createPayID } from '../../index-BUTI_SDh.js';
1
+ export { c as createPayID } from '../../index-BzE_au5k.js';
2
2
  import 'payid-types';
3
3
  import 'ethers';
4
4
  import '../../types-B8pJQdMQ.js';
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createPayID
3
- } from "../../chunk-YGCGT2JP.js";
3
+ } from "../../chunk-KUWSOJU7.js";
4
4
  import "../../chunk-GG34PNTF.js";
5
5
  import "../../chunk-MXKZJKXE.js";
6
6
  import "../../chunk-6VPSJFO4.js";
7
- import "../../chunk-UBYKCXWR.js";
7
+ import "../../chunk-LHLJP2TB.js";
8
8
  import "../../chunk-5ZEKI5Y2.js";
9
9
  import "../../chunk-R5U7XKVJ.js";
10
10
  export {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createPayID
3
- } from "../../chunk-4RDYA3QD.js";
4
- import "../../chunk-UBYKCXWR.js";
3
+ } from "../../chunk-5WO2F5HT.js";
4
+ import "../../chunk-LHLJP2TB.js";
5
5
  import "../../chunk-5ZEKI5Y2.js";
6
6
  import "../../chunk-R5U7XKVJ.js";
7
7
  export {
@@ -8,13 +8,6 @@ declare class PayIDClient {
8
8
  private readonly wasm?;
9
9
  private readonly _ready;
10
10
  constructor(debugTrace?: boolean | undefined, wasm?: Uint8Array | undefined);
11
- /**
12
- * Tunggu sampai WASM siap. Opsional — evaluate() akan menunggu sendiri,
13
- * tapi bisa di-await eksplisit untuk warmup:
14
- *
15
- * const client = createPayID();
16
- * await client.ready(); // WASM pasti sudah loaded setelah ini
17
- */
18
11
  ready(): Promise<void>;
19
12
  evaluate(context: RuleContext, rule: RuleConfig | RuleSource): Promise<RuleResult>;
20
13
  evaluateAndProve(params: {
@@ -30,6 +23,17 @@ declare class PayIDClient {
30
23
  signer: ethers.Signer;
31
24
  verifyingContract: string;
32
25
  ruleAuthority: string;
26
+ /**
27
+ * Override ruleSetHash yang dipakai di proof payload.
28
+ *
29
+ * WAJIB diisi kalau on-chain hash di-register dengan format berbeda
30
+ * dari hashRuleSet(authorityRule) — misalnya dari test page CombineTab
31
+ * yang pakai format keccak256("tokenId:ruleHash").
32
+ *
33
+ * Nilai ini harus sama persis dengan activeHash dari
34
+ * CombinedRuleStorage.getActiveRuleOf(receiver).
35
+ */
36
+ ruleSetHashOverride?: string;
33
37
  ttlSeconds?: number;
34
38
  chainId: number;
35
39
  blockTimestamp: number;
@@ -67,36 +67,14 @@ declare function canonicalizeRuleSet(ruleSet: {
67
67
  /**
68
68
  * Compute a deterministic hash of a canonicalized rule set.
69
69
  *
70
- * This function produces the `ruleSetHash` used to:
71
- * - Reference authoritative rules in on-chain registries
72
- * - Bind decision proofs to a specific rule configuration
73
- * - Ensure integrity between off-chain evaluation and on-chain verification
74
- *
75
- * ## Canonicalization requirement
76
- *
77
- * - The input rule set MUST already be canonicalized using
78
- * `canonicalizeRuleSet`.
79
- * - Hashing a non-canonical rule set may result in inconsistent
80
- * hashes for semantically identical rules.
81
- *
82
- * ## Security model
83
- *
84
- * - The hash represents the exact structure of the rule set at the
85
- * time of hashing.
86
- * - Any mutation (key order, rule order, value change) will produce
87
- * a different hash.
88
- *
89
- * ## Invariants
90
- *
91
- * - This function does NOT perform canonicalization.
92
- * - This function is pure and deterministic.
93
- * - The same canonical rule set will always yield the same hash.
94
- *
95
- * @param ruleSet
96
- * A canonicalized rule configuration object.
97
- *
98
- * @returns
99
- * A `bytes32` hex string (keccak256) uniquely identifying the rule set.
70
+ * PENTING: Fungsi ini HARUS menggunakan stableStringify (bukan JSON.stringify)
71
+ * agar menghasilkan hash yang sama dengan:
72
+ * - register-combined-rule.ts (canonicalize + keccak256)
73
+ * - decision-proof/hash.ts (hashRuleSet)
74
+ * - CombinedRuleStorage.sol (ruleSetHash tersimpan on-chain)
75
+ *
76
+ * Menggunakan JSON.stringify biasa akan menghasilkan key order berbeda
77
+ * hash berbeda getRuleByHash revert dengan RULE_NOT_ACTIVE.
100
78
  */
101
79
  declare function hashRuleSet(ruleSet: any): string;
102
80
 
package/dist/index.d.ts CHANGED
@@ -4,10 +4,10 @@ import { U as UserOperation } from './index-C1DHMQA0.js';
4
4
  export { i as server } from './index-C1DHMQA0.js';
5
5
  import { ethers } from 'ethers';
6
6
  export { i as sessionPolicy } from './index-BQQnMG2H.js';
7
- export { i as rule } from './index-DerQdZmf.js';
7
+ export { i as rule } from './index-Dj9IEios.js';
8
8
  export { i as issuer } from './index-2JCvey4-.js';
9
9
  export { i as context } from './index-BEvnPzzt.js';
10
- export { i as client } from './index-BUTI_SDh.js';
10
+ export { i as client } from './index-BzE_au5k.js';
11
11
  import './types-BmMf7udp.js';
12
12
 
13
13
  interface PayIDClient {
package/dist/index.js CHANGED
@@ -7,13 +7,13 @@ import {
7
7
  import "./chunk-YKCMGGYB.js";
8
8
  import {
9
9
  rule_exports
10
- } from "./chunk-ILV7Z3IN.js";
10
+ } from "./chunk-U7PPUJJH.js";
11
11
  import {
12
12
  sessionPolicy_exports
13
13
  } from "./chunk-Y75PSD7U.js";
14
14
  import {
15
15
  client_exports
16
- } from "./chunk-YGCGT2JP.js";
16
+ } from "./chunk-KUWSOJU7.js";
17
17
  import "./chunk-GG34PNTF.js";
18
18
  import "./chunk-MXKZJKXE.js";
19
19
  import "./chunk-6VPSJFO4.js";
@@ -22,12 +22,12 @@ import {
22
22
  buildPayETHCallData,
23
23
  buildUserOperation,
24
24
  server_exports
25
- } from "./chunk-4RDYA3QD.js";
25
+ } from "./chunk-5WO2F5HT.js";
26
26
  import {
27
27
  evaluate,
28
28
  generateDecisionProof,
29
29
  resolveRule
30
- } from "./chunk-UBYKCXWR.js";
30
+ } from "./chunk-LHLJP2TB.js";
31
31
  import "./chunk-5ZEKI5Y2.js";
32
32
  import {
33
33
  __export
@@ -1,2 +1,2 @@
1
- export { a as canonicalizeRuleSet, c as combineRules, h as hashRuleSet } from '../index-DerQdZmf.js';
1
+ export { a as canonicalizeRuleSet, c as combineRules, h as hashRuleSet } from '../index-Dj9IEios.js';
2
2
  import 'payid-types';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  hashRuleSet
3
- } from "../chunk-ILV7Z3IN.js";
3
+ } from "../chunk-U7PPUJJH.js";
4
4
  import {
5
5
  combineRules
6
6
  } from "../chunk-GG34PNTF.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payid",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",