payid 0.6.0 → 1.0.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.
Files changed (38) hide show
  1. package/dist/{chunk-2VO4XLTT.js → chunk-7YVJJEON.js} +22 -17
  2. package/dist/{chunk-BLIRABV7.js → chunk-AUW7WDAB.js} +11 -20
  3. package/dist/{chunk-SSO66YQI.js → chunk-E6VQETBC.js} +13 -0
  4. package/dist/chunk-FZNMDGVK.js +24 -0
  5. package/dist/chunk-MSQM7KDN.js +752 -0
  6. package/dist/chunk-X7NYQ47Y.js +27 -0
  7. package/dist/{chunk-Q4UZCGU4.js → chunk-XMUHMJRD.js} +1 -1
  8. package/dist/{chunk-TQJUKEFO.js → chunk-YWH7WOMP.js} +24 -21
  9. package/dist/context/index.d.ts +3 -2
  10. package/dist/context.v1-C1m-tz0o.d.ts +39 -0
  11. package/dist/context.v2-DIzPotmW.d.ts +37 -0
  12. package/dist/core/client/index.d.ts +5 -4
  13. package/dist/core/client/index.js +9 -5
  14. package/dist/core/server/index.d.ts +4 -3
  15. package/dist/core/server/index.js +7 -4
  16. package/dist/{index-2JCvey4-.d.ts → index-CDnE3SGM.d.ts} +18 -3
  17. package/dist/index-CsynGAGv.d.ts +53 -0
  18. package/dist/{index-Dj9IEios.d.ts → index-CubM9whW.d.ts} +4 -17
  19. package/dist/{index-C1DHMQA0.d.ts → index-DSxDlF9J.d.ts} +45 -68
  20. package/dist/{index-BEvnPzzt.d.ts → index-Dm2VdDEB.d.ts} +2 -1
  21. package/dist/{index-DSHZvYii.d.ts → index-G_1SiZJo.d.ts} +8 -7
  22. package/dist/index.d.ts +407 -72
  23. package/dist/index.js +586 -81
  24. package/dist/issuer/index.d.ts +3 -2
  25. package/dist/issuer/index.js +4 -1
  26. package/dist/rule/index.d.ts +2 -2
  27. package/dist/rule/index.js +4 -3
  28. package/dist/rule-a_5ed-93.d.ts +39 -0
  29. package/dist/sessionPolicy/index.d.ts +3 -3
  30. package/dist/sessionPolicy/index.js +2 -2
  31. package/dist/{types-CpXiPRYs.d.ts → types-D2o6XS7a.d.ts} +1 -1
  32. package/dist/types-i4eTkhWa.d.ts +50 -0
  33. package/package.json +22 -9
  34. package/src/rule/engine/rule_engine.wasm +0 -0
  35. package/dist/chunk-DZ6GVRER.js +0 -309
  36. package/dist/chunk-QC24X74O.js +0 -41
  37. package/dist/index-CtdogR8X.d.ts +0 -82
  38. package/dist/types-B8pJQdMQ.d.ts +0 -26
@@ -1,15 +1,16 @@
1
- import {
2
- combineRules
3
- } from "./chunk-GG34PNTF.js";
4
1
  import {
5
2
  decodeSessionPolicy,
6
3
  decodeSessionPolicyV2
7
- } from "./chunk-BLIRABV7.js";
4
+ } from "./chunk-AUW7WDAB.js";
5
+ import {
6
+ combineRules
7
+ } from "./chunk-GG34PNTF.js";
8
8
  import {
9
9
  evaluate,
10
10
  generateDecisionProof,
11
+ loadWasm,
11
12
  resolveRule
12
- } from "./chunk-DZ6GVRER.js";
13
+ } from "./chunk-MSQM7KDN.js";
13
14
  import {
14
15
  __export
15
16
  } from "./chunk-MLKGABMK.js";
@@ -17,33 +18,38 @@ import {
17
18
  // src/core/client/index.ts
18
19
  var client_exports = {};
19
20
  __export(client_exports, {
20
- createPayID: () => createPayID
21
+ PayIDClient: () => PayIDClient,
22
+ createPayID: () => createPayIDClient,
23
+ createPayIDClient: () => createPayIDClient
21
24
  });
22
25
 
23
26
  // src/core/client/client.ts
24
- import { loadWasm } from "payid-rule-engine";
25
27
  import "ethers";
26
28
  function isRuleSource(rule) {
27
29
  return typeof rule === "object" && rule !== null && "uri" in rule;
28
30
  }
29
31
  var PayIDClient = class {
30
- constructor(debugTrace, wasm) {
32
+ constructor(debugTrace, wasm, resolverOptions) {
31
33
  this.debugTrace = debugTrace;
32
34
  this.wasm = wasm;
35
+ this.resolverOptions = resolverOptions;
33
36
  this._ready = loadWasm(this.wasm).then(() => {
34
37
  }).catch(() => {
35
38
  });
36
39
  }
40
+ debugTrace;
41
+ wasm;
42
+ resolverOptions;
37
43
  _ready;
38
44
  async ready() {
39
45
  return this._ready;
40
46
  }
41
47
  async evaluate(context, rule) {
42
- const config = isRuleSource(rule) ? (await resolveRule(rule)).config : rule;
48
+ const config = isRuleSource(rule) ? (await resolveRule(rule, this.resolverOptions)).config : rule;
43
49
  return evaluate(context, config, { debug: this.debugTrace }, this.wasm);
44
50
  }
45
51
  async evaluateAndProve(params) {
46
- const authorityConfig = isRuleSource(params.authorityRule) ? (await resolveRule(params.authorityRule)).config : params.authorityRule;
52
+ const authorityConfig = isRuleSource(params.authorityRule) ? (await resolveRule(params.authorityRule, this.resolverOptions)).config : params.authorityRule;
47
53
  const evalConfig = params.evaluationRule ?? (params.sessionPolicyV2 ? (() => {
48
54
  decodeSessionPolicyV2(params.sessionPolicyV2, params.blockTimestamp);
49
55
  return authorityConfig;
@@ -77,21 +83,20 @@ var PayIDClient = class {
77
83
  ruleAuthority: params.ruleAuthority,
78
84
  chainId: params.chainId ?? params.context?.tx?.chainId,
79
85
  ttlSeconds: params.ttlSeconds,
80
- blockTimestamp: params.blockTimestamp
86
+ blockTimestamp: params.blockTimestamp,
87
+ attestationUIDs: params.attestationUIDs
81
88
  });
82
89
  return { result, proof };
83
90
  }
84
91
  };
85
92
 
86
93
  // src/core/client/index.ts
87
- function createPayID(params) {
88
- return new PayIDClient(
89
- params.debugTrace ?? false,
90
- params.wasm
91
- );
94
+ function createPayIDClient(params) {
95
+ return new PayIDClient(params?.debugTrace, params?.wasm);
92
96
  }
93
97
 
94
98
  export {
95
- createPayID,
99
+ PayIDClient,
100
+ createPayIDClient,
96
101
  client_exports
97
102
  };
@@ -1,28 +1,13 @@
1
- import {
2
- canonicalizeRuleSet
3
- } from "./chunk-6VPSJFO4.js";
4
1
  import {
5
2
  randomHex
6
3
  } from "./chunk-KDC67LIN.js";
7
4
 
8
5
  // src/sessionPolicy/create.ts
9
6
  import { ethers } from "ethers";
10
- async function createSessionPolicyPayload(params) {
11
- const issuedAt = Math.floor(Date.now() / 1e3);
12
- const nonce = randomHex(16);
13
- const payload = {
14
- version: "payid.session.policy.v1",
15
- receiver: params.receiver,
16
- rule: canonicalizeRuleSet(params.rule),
17
- issuedAt,
18
- expiresAt: params.expiresAt,
19
- nonce
20
- };
21
- const message = ethers.keccak256(
22
- ethers.toUtf8Bytes(JSON.stringify(payload))
7
+ async function createSessionPolicyPayload(_params) {
8
+ throw new Error(
9
+ "SESSION_POLICY_V1_DISABLED: V1 policies have no chainId binding and are vulnerable to cross-chain replay. Use createSessionPolicyV2() instead."
23
10
  );
24
- const signature = await params.signer.signMessage(message);
25
- return { ...payload, signature };
26
11
  }
27
12
  var SESSION_POLICY_V2_DOMAIN_NAME = "PAY.ID SessionPolicy";
28
13
  var SESSION_POLICY_V2_DOMAIN_VERSION = "1";
@@ -59,14 +44,20 @@ async function createSessionPolicyV2(params) {
59
44
  verifyingContract,
60
45
  signer
61
46
  } = params;
47
+ const MIN_TTL_SECONDS = 60;
48
+ const MAX_TTL_SECONDS = 30 * 24 * 3600;
62
49
  if (!ethers.isAddress(receiver)) {
63
50
  throw new Error(`SESSION_POLICY_V2: receiver address tidak valid: ${receiver}`);
64
51
  }
65
52
  if (maxAmount <= 0n) {
66
53
  throw new Error("SESSION_POLICY_V2: maxAmount harus > 0");
67
54
  }
68
- if (expiresAt <= Math.floor(Date.now() / 1e3)) {
69
- throw new Error("SESSION_POLICY_V2: expiresAt sudah lewat");
55
+ const now = Math.floor(Date.now() / 1e3);
56
+ if (expiresAt <= now + MIN_TTL_SECONDS) {
57
+ throw new Error(`SESSION_POLICY_V2: expiresAt terlalu dekat \u2014 minimum ${MIN_TTL_SECONDS}s dari sekarang`);
58
+ }
59
+ if (expiresAt > now + MAX_TTL_SECONDS) {
60
+ throw new Error(`SESSION_POLICY_V2: expiresAt terlalu jauh \u2014 maksimum ${MAX_TTL_SECONDS / 86400} hari`);
70
61
  }
71
62
  const policyNonce = randomHex(32);
72
63
  const payIdBytes32 = ethers.keccak256(ethers.toUtf8Bytes(payId));
@@ -16,9 +16,22 @@ __export(issuer_exports, {
16
16
  issueOracleContext: () => issueOracleContext,
17
17
  issueRiskContext: () => issueRiskContext,
18
18
  issueStateContext: () => issueStateContext,
19
+ issueTokenPriceContext: () => issueTokenPriceContext,
19
20
  signAttestation: () => signAttestation
20
21
  });
21
22
 
23
+ // src/issuer/issueTokenPriceContext.ts
24
+ async function issueTokenPriceContext(wallet, tokenPrice, tokenAmount, tokenDecimals) {
25
+ const amountUsd = tokenAmount * tokenPrice / 10n ** BigInt(tokenDecimals + 8);
26
+ const proof = await signAttestation(
27
+ wallet,
28
+ { amountUsd: amountUsd.toString() },
29
+ 120
30
+ );
31
+ return { amountUsd: amountUsd.toString(), proof };
32
+ }
33
+
22
34
  export {
35
+ issueTokenPriceContext,
23
36
  issuer_exports
24
37
  };
@@ -0,0 +1,24 @@
1
+ import {
2
+ combineRules
3
+ } from "./chunk-GG34PNTF.js";
4
+ import {
5
+ canonicalizeRuleSet
6
+ } from "./chunk-6VPSJFO4.js";
7
+ import {
8
+ hashRuleSet
9
+ } from "./chunk-X7NYQ47Y.js";
10
+ import {
11
+ __export
12
+ } from "./chunk-MLKGABMK.js";
13
+
14
+ // src/rule/index.ts
15
+ var rule_exports = {};
16
+ __export(rule_exports, {
17
+ canonicalizeRuleSet: () => canonicalizeRuleSet,
18
+ combineRules: () => combineRules,
19
+ hashRuleSet: () => hashRuleSet
20
+ });
21
+
22
+ export {
23
+ rule_exports
24
+ };