@crediolabs/policy-synth 0.3.0 → 0.3.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 (102) hide show
  1. package/dist/record/freshness.d.ts +17 -11
  2. package/dist/record/freshness.js +28 -18
  3. package/dist-cjs/record/freshness.d.ts +17 -11
  4. package/dist-cjs/record/freshness.js +28 -18
  5. package/package.json +2 -2
  6. package/src/record/freshness.ts +29 -18
  7. package/dist/adapters/interpreter/index.d.ts +0 -1
  8. package/dist/adapters/interpreter/index.js +0 -2
  9. package/dist/adapters/oz/adapter.d.ts +0 -20
  10. package/dist/adapters/oz/adapter.js +0 -281
  11. package/dist/adapters/oz/index.d.ts +0 -1
  12. package/dist/adapters/oz/index.js +0 -2
  13. package/dist/codegen/compile-gate.d.ts +0 -33
  14. package/dist/codegen/compile-gate.js +0 -124
  15. package/dist/codegen/index.d.ts +0 -2
  16. package/dist/codegen/index.js +0 -8
  17. package/dist/codegen/template.d.ts +0 -18
  18. package/dist/codegen/template.js +0 -148
  19. package/dist/ir/index.d.ts +0 -1
  20. package/dist/ir/index.js +0 -2
  21. package/dist/ir/types.d.ts +0 -71
  22. package/dist/ir/types.js +0 -9
  23. package/dist/mandate/index.d.ts +0 -2
  24. package/dist/mandate/index.js +0 -2
  25. package/dist/mandate/to-ir.d.ts +0 -3
  26. package/dist/mandate/to-ir.js +0 -60
  27. package/dist/mandate/types.d.ts +0 -20
  28. package/dist/mandate/types.js +0 -8
  29. package/dist/seams/index.d.ts +0 -1
  30. package/dist/seams/index.js +0 -2
  31. package/dist/seams/types.d.ts +0 -64
  32. package/dist/seams/types.js +0 -11
  33. package/dist/synth/deny-cases.d.ts +0 -28
  34. package/dist/synth/deny-cases.js +0 -212
  35. package/dist/synth/evaluate.d.ts +0 -18
  36. package/dist/synth/evaluate.js +0 -271
  37. package/dist/synth/harness.d.ts +0 -28
  38. package/dist/synth/harness.js +0 -47
  39. package/dist/synth/minimize.d.ts +0 -4
  40. package/dist/synth/minimize.js +0 -38
  41. package/dist/synth/permit-context.d.ts +0 -8
  42. package/dist/synth/permit-context.js +0 -35
  43. package/dist/synth/predicate-literals.d.ts +0 -5
  44. package/dist/synth/predicate-literals.js +0 -25
  45. package/dist/synth/synthesize-from-mandate.d.ts +0 -20
  46. package/dist/synth/synthesize-from-mandate.js +0 -59
  47. package/dist/verify/envelope.d.ts +0 -15
  48. package/dist/verify/envelope.js +0 -22
  49. package/dist/verify/index.d.ts +0 -3
  50. package/dist/verify/index.js +0 -3
  51. package/dist/verify/simulate.d.ts +0 -18
  52. package/dist/verify/simulate.js +0 -172
  53. package/dist/verify/verify.d.ts +0 -15
  54. package/dist/verify/verify.js +0 -181
  55. package/dist-cjs/adapters/interpreter/index.d.ts +0 -1
  56. package/dist-cjs/adapters/interpreter/index.js +0 -7
  57. package/dist-cjs/adapters/oz/adapter.d.ts +0 -20
  58. package/dist-cjs/adapters/oz/adapter.js +0 -286
  59. package/dist-cjs/adapters/oz/index.d.ts +0 -1
  60. package/dist-cjs/adapters/oz/index.js +0 -8
  61. package/dist-cjs/codegen/compile-gate.d.ts +0 -33
  62. package/dist-cjs/codegen/compile-gate.js +0 -128
  63. package/dist-cjs/codegen/index.d.ts +0 -2
  64. package/dist-cjs/codegen/index.js +0 -14
  65. package/dist-cjs/codegen/template.d.ts +0 -18
  66. package/dist-cjs/codegen/template.js +0 -151
  67. package/dist-cjs/ir/index.d.ts +0 -1
  68. package/dist-cjs/ir/index.js +0 -3
  69. package/dist-cjs/ir/types.d.ts +0 -71
  70. package/dist-cjs/ir/types.js +0 -10
  71. package/dist-cjs/mandate/index.d.ts +0 -2
  72. package/dist-cjs/mandate/index.js +0 -6
  73. package/dist-cjs/mandate/to-ir.d.ts +0 -3
  74. package/dist-cjs/mandate/to-ir.js +0 -63
  75. package/dist-cjs/mandate/types.d.ts +0 -20
  76. package/dist-cjs/mandate/types.js +0 -9
  77. package/dist-cjs/seams/index.d.ts +0 -1
  78. package/dist-cjs/seams/index.js +0 -3
  79. package/dist-cjs/seams/types.d.ts +0 -64
  80. package/dist-cjs/seams/types.js +0 -12
  81. package/dist-cjs/synth/deny-cases.d.ts +0 -28
  82. package/dist-cjs/synth/deny-cases.js +0 -217
  83. package/dist-cjs/synth/evaluate.d.ts +0 -18
  84. package/dist-cjs/synth/evaluate.js +0 -274
  85. package/dist-cjs/synth/harness.d.ts +0 -28
  86. package/dist-cjs/synth/harness.js +0 -50
  87. package/dist-cjs/synth/minimize.d.ts +0 -4
  88. package/dist-cjs/synth/minimize.js +0 -41
  89. package/dist-cjs/synth/permit-context.d.ts +0 -8
  90. package/dist-cjs/synth/permit-context.js +0 -38
  91. package/dist-cjs/synth/predicate-literals.d.ts +0 -5
  92. package/dist-cjs/synth/predicate-literals.js +0 -28
  93. package/dist-cjs/synth/synthesize-from-mandate.d.ts +0 -20
  94. package/dist-cjs/synth/synthesize-from-mandate.js +0 -62
  95. package/dist-cjs/verify/envelope.d.ts +0 -15
  96. package/dist-cjs/verify/envelope.js +0 -23
  97. package/dist-cjs/verify/index.d.ts +0 -3
  98. package/dist-cjs/verify/index.js +0 -8
  99. package/dist-cjs/verify/simulate.d.ts +0 -18
  100. package/dist-cjs/verify/simulate.js +0 -175
  101. package/dist-cjs/verify/verify.d.ts +0 -15
  102. package/dist-cjs/verify/verify.js +0 -184
@@ -16,15 +16,21 @@ export declare function isBelowThreshold(c: ParseConfidence): boolean;
16
16
  * under-confidence recording.
17
17
  *
18
18
  * The remediation text branches on which diagnostic bucket is non-empty:
19
- * - unknownContracts only -> user MUST supply an ABI (or re-capture
20
- * against a known protocol version). The contract is real, the
21
- * recorder just cannot decode it.
22
- * - opaqueScVals only -> the recorder encountered a value shape it
23
- * should support but did not decode. The user cannot supply an ABI
24
- * to fix a decoder bug; the guidance explicitly says so and points at
25
- * re-running after a tool upgrade / reporting the path.
26
- * - both -> list both diagnostics AND chain the right remediation for
27
- * each (the user supplies an ABI AND reports the decoder gap).
28
- * - neither (the "denom === 0" path) -> unchanged from the pre-fix
29
- * text; the user did not actually hit a code-level barrier. */
19
+ * - unknownContracts only -> the contract is not in the compiled-in
20
+ * registry. NOT "the contract has no interface": most Soroban
21
+ * contracts publish a typed spec on chain, this package just never
22
+ * reads one. The reason code stays `no-abi` because it is a published
23
+ * enum value, so the TEXT has to carry the correction.
24
+ * - opaqueScVals only -> the recorder met a value shape it should
25
+ * support but did not decode. That is a decoder bug, and the guidance
26
+ * says so rather than implying the caller can fix it.
27
+ * - both -> list both diagnostics and chain the right remediation.
28
+ * - neither (the "denom === 0" path) -> the caller did not actually hit
29
+ * a code-level barrier.
30
+ *
31
+ * Do NOT tell the caller to supply an ABI. There is no input for one:
32
+ * recognition runs off the compiled-in registry plus a known-contract set
33
+ * that no public tool boundary exposes. The old text named an action
34
+ * nobody could take and sent users looking for a file they do not have and
35
+ * would not need. */
30
36
  export declare function buildLowConfidenceQuestion(c: ParseConfidence): string;
@@ -39,17 +39,23 @@ export function isBelowThreshold(c) {
39
39
  * under-confidence recording.
40
40
  *
41
41
  * The remediation text branches on which diagnostic bucket is non-empty:
42
- * - unknownContracts only -> user MUST supply an ABI (or re-capture
43
- * against a known protocol version). The contract is real, the
44
- * recorder just cannot decode it.
45
- * - opaqueScVals only -> the recorder encountered a value shape it
46
- * should support but did not decode. The user cannot supply an ABI
47
- * to fix a decoder bug; the guidance explicitly says so and points at
48
- * re-running after a tool upgrade / reporting the path.
49
- * - both -> list both diagnostics AND chain the right remediation for
50
- * each (the user supplies an ABI AND reports the decoder gap).
51
- * - neither (the "denom === 0" path) -> unchanged from the pre-fix
52
- * text; the user did not actually hit a code-level barrier. */
42
+ * - unknownContracts only -> the contract is not in the compiled-in
43
+ * registry. NOT "the contract has no interface": most Soroban
44
+ * contracts publish a typed spec on chain, this package just never
45
+ * reads one. The reason code stays `no-abi` because it is a published
46
+ * enum value, so the TEXT has to carry the correction.
47
+ * - opaqueScVals only -> the recorder met a value shape it should
48
+ * support but did not decode. That is a decoder bug, and the guidance
49
+ * says so rather than implying the caller can fix it.
50
+ * - both -> list both diagnostics and chain the right remediation.
51
+ * - neither (the "denom === 0" path) -> the caller did not actually hit
52
+ * a code-level barrier.
53
+ *
54
+ * Do NOT tell the caller to supply an ABI. There is no input for one:
55
+ * recognition runs off the compiled-in registry plus a known-contract set
56
+ * that no public tool boundary exposes. The old text named an action
57
+ * nobody could take and sent users looking for a file they do not have and
58
+ * would not need. */
53
59
  export function buildLowConfidenceQuestion(c) {
54
60
  const hasUnknown = c.unknownContracts.length > 0;
55
61
  const hasOpaque = c.opaqueScVals.length > 0;
@@ -62,16 +68,20 @@ export function buildLowConfidenceQuestion(c) {
62
68
  }
63
69
  const why = reasons.length === 0 ? 'no diagnostic reason available' : reasons.join('; ');
64
70
  const header = `Recording refused: parseConfidence ${c.overall.toFixed(3)} is below the threshold ${c.thresholdUsed.toFixed(3)}. Diagnostic: ${why}.`;
65
- // The two remediation branches are explicit so the user (or the agent)
66
- // can dispatch on the verb. The "unknown contract" branch is the only
67
- // one that asks for an ABI; the "opaque ScVal" branch asks the user to
68
- // report the path and re-run after a tool upgrade.
71
+ // The remediation branches are explicit so the user (or the agent) can
72
+ // dispatch on the verb. Neither branch asks for an ABI: there is no input
73
+ // that accepts one, and for the unknown-contract branch the contract's
74
+ // own spec is usually on chain already - it is this package that does not
75
+ // read it.
76
+ const unknownAdvice = `The contract is not in this package's built-in registry - "no-abi" means unrecognised here, not that the contract lacks an interface. ` +
77
+ `You cannot supply one: the registry is compiled in. Either build the policy without deriving it from this transaction, or re-capture against a protocol the registry covers. ` +
78
+ `Passing confidenceOverride accepts the recording as it stands, including the arguments this tool could not attribute - do that only if you have checked them yourself.`;
69
79
  if (hasUnknown && hasOpaque) {
70
- return (`${header} Supply an ABI for the unknown contract(s) or re-capture the transaction against a known protocol version; ` +
71
- `also file the opaque ScVal path against the recorder (decoder limitation) and re-run record_transaction after a tool upgrade.`);
80
+ return (`${header} ${unknownAdvice} Separately, file the opaque ScVal path against the recorder (a decoder limitation) ` +
81
+ `and re-run record_transaction after a tool upgrade.`);
72
82
  }
73
83
  if (hasUnknown) {
74
- return `${header} Supply an ABI for the unknown contract(s) or re-capture the transaction against a known protocol version, then re-run record_transaction.`;
84
+ return `${header} ${unknownAdvice}`;
75
85
  }
76
86
  if (hasOpaque) {
77
87
  return `${header} This is a recorder decoder limitation (the value shape is supported in principle but not yet decoded) - the agent cannot fix it by supplying an ABI. Report the opaque ScVal path above against the recorder and re-run record_transaction after a tool upgrade.`;
@@ -16,15 +16,21 @@ export declare function isBelowThreshold(c: ParseConfidence): boolean;
16
16
  * under-confidence recording.
17
17
  *
18
18
  * The remediation text branches on which diagnostic bucket is non-empty:
19
- * - unknownContracts only -> user MUST supply an ABI (or re-capture
20
- * against a known protocol version). The contract is real, the
21
- * recorder just cannot decode it.
22
- * - opaqueScVals only -> the recorder encountered a value shape it
23
- * should support but did not decode. The user cannot supply an ABI
24
- * to fix a decoder bug; the guidance explicitly says so and points at
25
- * re-running after a tool upgrade / reporting the path.
26
- * - both -> list both diagnostics AND chain the right remediation for
27
- * each (the user supplies an ABI AND reports the decoder gap).
28
- * - neither (the "denom === 0" path) -> unchanged from the pre-fix
29
- * text; the user did not actually hit a code-level barrier. */
19
+ * - unknownContracts only -> the contract is not in the compiled-in
20
+ * registry. NOT "the contract has no interface": most Soroban
21
+ * contracts publish a typed spec on chain, this package just never
22
+ * reads one. The reason code stays `no-abi` because it is a published
23
+ * enum value, so the TEXT has to carry the correction.
24
+ * - opaqueScVals only -> the recorder met a value shape it should
25
+ * support but did not decode. That is a decoder bug, and the guidance
26
+ * says so rather than implying the caller can fix it.
27
+ * - both -> list both diagnostics and chain the right remediation.
28
+ * - neither (the "denom === 0" path) -> the caller did not actually hit
29
+ * a code-level barrier.
30
+ *
31
+ * Do NOT tell the caller to supply an ABI. There is no input for one:
32
+ * recognition runs off the compiled-in registry plus a known-contract set
33
+ * that no public tool boundary exposes. The old text named an action
34
+ * nobody could take and sent users looking for a file they do not have and
35
+ * would not need. */
30
36
  export declare function buildLowConfidenceQuestion(c: ParseConfidence): string;
@@ -44,17 +44,23 @@ function isBelowThreshold(c) {
44
44
  * under-confidence recording.
45
45
  *
46
46
  * The remediation text branches on which diagnostic bucket is non-empty:
47
- * - unknownContracts only -> user MUST supply an ABI (or re-capture
48
- * against a known protocol version). The contract is real, the
49
- * recorder just cannot decode it.
50
- * - opaqueScVals only -> the recorder encountered a value shape it
51
- * should support but did not decode. The user cannot supply an ABI
52
- * to fix a decoder bug; the guidance explicitly says so and points at
53
- * re-running after a tool upgrade / reporting the path.
54
- * - both -> list both diagnostics AND chain the right remediation for
55
- * each (the user supplies an ABI AND reports the decoder gap).
56
- * - neither (the "denom === 0" path) -> unchanged from the pre-fix
57
- * text; the user did not actually hit a code-level barrier. */
47
+ * - unknownContracts only -> the contract is not in the compiled-in
48
+ * registry. NOT "the contract has no interface": most Soroban
49
+ * contracts publish a typed spec on chain, this package just never
50
+ * reads one. The reason code stays `no-abi` because it is a published
51
+ * enum value, so the TEXT has to carry the correction.
52
+ * - opaqueScVals only -> the recorder met a value shape it should
53
+ * support but did not decode. That is a decoder bug, and the guidance
54
+ * says so rather than implying the caller can fix it.
55
+ * - both -> list both diagnostics and chain the right remediation.
56
+ * - neither (the "denom === 0" path) -> the caller did not actually hit
57
+ * a code-level barrier.
58
+ *
59
+ * Do NOT tell the caller to supply an ABI. There is no input for one:
60
+ * recognition runs off the compiled-in registry plus a known-contract set
61
+ * that no public tool boundary exposes. The old text named an action
62
+ * nobody could take and sent users looking for a file they do not have and
63
+ * would not need. */
58
64
  function buildLowConfidenceQuestion(c) {
59
65
  const hasUnknown = c.unknownContracts.length > 0;
60
66
  const hasOpaque = c.opaqueScVals.length > 0;
@@ -67,16 +73,20 @@ function buildLowConfidenceQuestion(c) {
67
73
  }
68
74
  const why = reasons.length === 0 ? 'no diagnostic reason available' : reasons.join('; ');
69
75
  const header = `Recording refused: parseConfidence ${c.overall.toFixed(3)} is below the threshold ${c.thresholdUsed.toFixed(3)}. Diagnostic: ${why}.`;
70
- // The two remediation branches are explicit so the user (or the agent)
71
- // can dispatch on the verb. The "unknown contract" branch is the only
72
- // one that asks for an ABI; the "opaque ScVal" branch asks the user to
73
- // report the path and re-run after a tool upgrade.
76
+ // The remediation branches are explicit so the user (or the agent) can
77
+ // dispatch on the verb. Neither branch asks for an ABI: there is no input
78
+ // that accepts one, and for the unknown-contract branch the contract's
79
+ // own spec is usually on chain already - it is this package that does not
80
+ // read it.
81
+ const unknownAdvice = `The contract is not in this package's built-in registry - "no-abi" means unrecognised here, not that the contract lacks an interface. ` +
82
+ `You cannot supply one: the registry is compiled in. Either build the policy without deriving it from this transaction, or re-capture against a protocol the registry covers. ` +
83
+ `Passing confidenceOverride accepts the recording as it stands, including the arguments this tool could not attribute - do that only if you have checked them yourself.`;
74
84
  if (hasUnknown && hasOpaque) {
75
- return (`${header} Supply an ABI for the unknown contract(s) or re-capture the transaction against a known protocol version; ` +
76
- `also file the opaque ScVal path against the recorder (decoder limitation) and re-run record_transaction after a tool upgrade.`);
85
+ return (`${header} ${unknownAdvice} Separately, file the opaque ScVal path against the recorder (a decoder limitation) ` +
86
+ `and re-run record_transaction after a tool upgrade.`);
77
87
  }
78
88
  if (hasUnknown) {
79
- return `${header} Supply an ABI for the unknown contract(s) or re-capture the transaction against a known protocol version, then re-run record_transaction.`;
89
+ return `${header} ${unknownAdvice}`;
80
90
  }
81
91
  if (hasOpaque) {
82
92
  return `${header} This is a recorder decoder limitation (the value shape is supported in principle but not yet decoded) - the agent cannot fix it by supplying an ABI. Report the opaque ScVal path above against the recorder and re-run record_transaction after a tool upgrade.`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crediolabs/policy-synth",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "license": "MIT",
5
5
  "description": "Off-chain TypeScript synthesis core for the OZ Accounts Policy Builder. Records Soroban transactions, synthesises the minimal policy that permits exactly that flow, verifies it, and returns an unsigned install transaction.",
6
6
  "type": "module",
@@ -67,7 +67,7 @@
67
67
  },
68
68
  "scripts": {
69
69
  "test": "bun test",
70
- "build": "tsc -p tsconfig.build.json && tsc -p tsconfig.build.cjs.json && node scripts/write-cjs-package-json.cjs",
70
+ "build": "rm -rf dist dist-cjs && tsc -p tsconfig.build.json && tsc -p tsconfig.build.cjs.json && node scripts/write-cjs-package-json.cjs",
71
71
  "build:esm": "tsc -p tsconfig.build.json",
72
72
  "build:cjs": "tsc -p tsconfig.build.cjs.json && node scripts/write-cjs-package-json.cjs",
73
73
  "prepublishOnly": "bun run build && bun test",
@@ -52,17 +52,23 @@ export function isBelowThreshold(c: ParseConfidence): boolean {
52
52
  * under-confidence recording.
53
53
  *
54
54
  * The remediation text branches on which diagnostic bucket is non-empty:
55
- * - unknownContracts only -> user MUST supply an ABI (or re-capture
56
- * against a known protocol version). The contract is real, the
57
- * recorder just cannot decode it.
58
- * - opaqueScVals only -> the recorder encountered a value shape it
59
- * should support but did not decode. The user cannot supply an ABI
60
- * to fix a decoder bug; the guidance explicitly says so and points at
61
- * re-running after a tool upgrade / reporting the path.
62
- * - both -> list both diagnostics AND chain the right remediation for
63
- * each (the user supplies an ABI AND reports the decoder gap).
64
- * - neither (the "denom === 0" path) -> unchanged from the pre-fix
65
- * text; the user did not actually hit a code-level barrier. */
55
+ * - unknownContracts only -> the contract is not in the compiled-in
56
+ * registry. NOT "the contract has no interface": most Soroban
57
+ * contracts publish a typed spec on chain, this package just never
58
+ * reads one. The reason code stays `no-abi` because it is a published
59
+ * enum value, so the TEXT has to carry the correction.
60
+ * - opaqueScVals only -> the recorder met a value shape it should
61
+ * support but did not decode. That is a decoder bug, and the guidance
62
+ * says so rather than implying the caller can fix it.
63
+ * - both -> list both diagnostics and chain the right remediation.
64
+ * - neither (the "denom === 0" path) -> the caller did not actually hit
65
+ * a code-level barrier.
66
+ *
67
+ * Do NOT tell the caller to supply an ABI. There is no input for one:
68
+ * recognition runs off the compiled-in registry plus a known-contract set
69
+ * that no public tool boundary exposes. The old text named an action
70
+ * nobody could take and sent users looking for a file they do not have and
71
+ * would not need. */
66
72
  export function buildLowConfidenceQuestion(c: ParseConfidence): string {
67
73
  const hasUnknown = c.unknownContracts.length > 0
68
74
  const hasOpaque = c.opaqueScVals.length > 0
@@ -75,18 +81,23 @@ export function buildLowConfidenceQuestion(c: ParseConfidence): string {
75
81
  }
76
82
  const why = reasons.length === 0 ? 'no diagnostic reason available' : reasons.join('; ')
77
83
  const header = `Recording refused: parseConfidence ${c.overall.toFixed(3)} is below the threshold ${c.thresholdUsed.toFixed(3)}. Diagnostic: ${why}.`
78
- // The two remediation branches are explicit so the user (or the agent)
79
- // can dispatch on the verb. The "unknown contract" branch is the only
80
- // one that asks for an ABI; the "opaque ScVal" branch asks the user to
81
- // report the path and re-run after a tool upgrade.
84
+ // The remediation branches are explicit so the user (or the agent) can
85
+ // dispatch on the verb. Neither branch asks for an ABI: there is no input
86
+ // that accepts one, and for the unknown-contract branch the contract's
87
+ // own spec is usually on chain already - it is this package that does not
88
+ // read it.
89
+ const unknownAdvice =
90
+ `The contract is not in this package's built-in registry - "no-abi" means unrecognised here, not that the contract lacks an interface. ` +
91
+ `You cannot supply one: the registry is compiled in. Either build the policy without deriving it from this transaction, or re-capture against a protocol the registry covers. ` +
92
+ `Passing confidenceOverride accepts the recording as it stands, including the arguments this tool could not attribute - do that only if you have checked them yourself.`
82
93
  if (hasUnknown && hasOpaque) {
83
94
  return (
84
- `${header} Supply an ABI for the unknown contract(s) or re-capture the transaction against a known protocol version; ` +
85
- `also file the opaque ScVal path against the recorder (decoder limitation) and re-run record_transaction after a tool upgrade.`
95
+ `${header} ${unknownAdvice} Separately, file the opaque ScVal path against the recorder (a decoder limitation) ` +
96
+ `and re-run record_transaction after a tool upgrade.`
86
97
  )
87
98
  }
88
99
  if (hasUnknown) {
89
- return `${header} Supply an ABI for the unknown contract(s) or re-capture the transaction against a known protocol version, then re-run record_transaction.`
100
+ return `${header} ${unknownAdvice}`
90
101
  }
91
102
  if (hasOpaque) {
92
103
  return `${header} This is a recorder decoder limitation (the value shape is supported in principle but not yet decoded) - the agent cannot fix it by supplying an ABI. Report the opaque ScVal path above against the recorder and re-run record_transaction after a tool upgrade.`
@@ -1 +0,0 @@
1
- export { createInterpreterAdapter, type InterpreterAdapterConfig, PLACEHOLDER_INTERPRETER_ADDRESS, } from './adapter.ts';
@@ -1,2 +0,0 @@
1
- // src/adapters/interpreter/index.ts - re-export the interpreter-policy CustodyAdapter.
2
- export { createInterpreterAdapter, PLACEHOLDER_INTERPRETER_ADDRESS, } from "./adapter.js";
@@ -1,20 +0,0 @@
1
- import type { CustodyAdapter } from '../../seams/types.ts';
2
- import type { Network } from '../../types.ts';
3
- /** OZ built-in policy contract instance addresses, per primitive. */
4
- export interface OzPrimitiveInstances {
5
- spending_limit: string;
6
- simple_threshold: string;
7
- weighted_threshold: string;
8
- }
9
- /** Per-network config for the OZ adapter. */
10
- export interface OzAdapterConfig {
11
- network: Network;
12
- instances: OzPrimitiveInstances;
13
- }
14
- /** [VERIFY] NOT real deployed addresses. The OZ built-in policy instances are
15
- * per-network deploy artifacts we do not have yet; install is a later phase.
16
- * Injected so the adapter never invents a Stellar contract address. */
17
- export declare const PLACEHOLDER_OZ_INSTANCES: OzPrimitiveInstances;
18
- /** Week-1 OZ adapter config with placeholder instance addresses. */
19
- export declare function placeholderOzConfig(network: Network): OzAdapterConfig;
20
- export declare function createOzAdapter(config: OzAdapterConfig): CustodyAdapter;
@@ -1,281 +0,0 @@
1
- // src/adapters/oz/adapter.ts - the OZ Accounts CustodyAdapter.
2
- //
3
- // Compiles a PolicyIR to an OZ `ProposedPolicy` using OZ built-in policy
4
- // primitives. Only the constructs OZ can express natively are lowered:
5
- // scope.contract -> ContextRuleType.call_contract (else default)
6
- // expiry.validUntilLedger -> ContextRuleDraft.validUntilLedger
7
- // window_spent(t,w) <= L -> `spending_limit` primitive
8
- // approval.threshold -> `simple_threshold` / `weighted_threshold`
9
- // Anything needing a capability this backend lacks (invocation
10
- // count, per-arg comparison/allowlist, guard, nested boolean predicate) is NOT
11
- // emitted: it is named in `uncovered` and `covered` is set false. Nothing is
12
- // silently dropped.
13
- //
14
- // OZ built-in policy instance addresses are per-network deploy artifacts we do
15
- // not have yet (install is a later phase). They are injected via config; week-1
16
- // ships a clearly-labelled [VERIFY] placeholder so nothing invents an address.
17
- import { OZ_LIMITS, SOROBAN_LIMITS } from "../../types.js";
18
- /** [VERIFY] NOT real deployed addresses. The OZ built-in policy instances are
19
- * per-network deploy artifacts we do not have yet; install is a later phase.
20
- * Injected so the adapter never invents a Stellar contract address. */
21
- export const PLACEHOLDER_OZ_INSTANCES = {
22
- spending_limit: 'VERIFY-oz-spending-limit-instance-address',
23
- simple_threshold: 'VERIFY-oz-simple-threshold-instance-address',
24
- weighted_threshold: 'VERIFY-oz-weighted-threshold-instance-address',
25
- };
26
- /** Week-1 OZ adapter config with placeholder instance addresses. */
27
- export function placeholderOzConfig(network) {
28
- return { network, instances: PLACEHOLDER_OZ_INSTANCES };
29
- }
30
- /** Parse confidence for a deterministic (non-decoded) input: full (1.0). A
31
- * mandate needs no decoding, so the gate is not applicable. */
32
- const FULL_PARSE_CONFIDENCE = {
33
- overall: 1,
34
- knownContracts: [],
35
- unknownContracts: [],
36
- opaqueScVals: [],
37
- thresholdUsed: 1,
38
- };
39
- const CAPABILITIES = {
40
- supportsSpendWindow: true,
41
- supportsThreshold: true,
42
- supportsTimeExpiry: true,
43
- supportsGeneralPredicate: false,
44
- };
45
- export function createOzAdapter(config) {
46
- return {
47
- name: 'oz-accounts',
48
- mode: 'enforce',
49
- capabilities: () => ({ ...CAPABILITIES }),
50
- compile: (ir) => compile(ir, config),
51
- simulate: () => simulateStub(),
52
- export: (ir) => canonicalStringify(ir),
53
- };
54
- }
55
- function compile(ir, config) {
56
- const uncovered = [];
57
- const firstRule = ir.rules[0];
58
- if (!firstRule) {
59
- return { covered: false, uncovered: ['empty PolicyIR (no rules to compile)'] };
60
- }
61
- if (ir.rules.length > 1) {
62
- uncovered.push(`multi-rule PolicyIR: ${ir.rules.length - 1} rule(s) beyond the first are not compiled (a ProposedPolicy carries a single context rule in this slice)`);
63
- }
64
- const lowered = lowerRule(firstRule, config);
65
- uncovered.push(...lowered.uncovered);
66
- const result = { covered: uncovered.length === 0, uncovered };
67
- if (!lowered.capExceeded) {
68
- const proposed = {
69
- contextRule: lowered.contextRule,
70
- policyDocuments: [],
71
- policyRefs: lowered.policyRefs,
72
- parseConfidence: { ...FULL_PARSE_CONFIDENCE },
73
- warnings: [],
74
- ambiguities: [],
75
- };
76
- result.proposed = proposed;
77
- }
78
- return result;
79
- }
80
- function lowerRule(rule, config) {
81
- const uncovered = [];
82
- const policyRefs = [];
83
- // scope -> context rule type. OZ scopes by contract (CallContract); a
84
- // method-level restriction is flagged as not covered because CallContract
85
- // alone permits other methods on the same contract (e.g. an unbounded approve
86
- // alongside a capped transfer).
87
- const contextRuleType = rule.scope.contract !== undefined
88
- ? { kind: 'call_contract', contract: rule.scope.contract }
89
- : { kind: 'default' };
90
- if (rule.scope.method !== undefined && rule.scope.contract !== undefined) {
91
- uncovered.push(`per-method scoping to \`${rule.scope.method}\` (OZ CallContract scopes by contract only; requires the interpreter predicate)`);
92
- }
93
- if (rule.scope.chainId !== undefined) {
94
- uncovered.push(`chainId \`${rule.scope.chainId}\` not bindable by the Stellar OZ adapter (network is per-context, not per-rule)`);
95
- }
96
- if (rule.roles.length > 0) {
97
- uncovered.push(`roles [${rule.roles.join(', ')}] dropped (role-to-signer mapping is a later phase; OZ signers carry addresses, not role names)`);
98
- }
99
- // expiry -> validUntilLedger. Unix-timestamp expiry cannot be expressed by an
100
- // OZ context rule (it expires by ledger sequence), so flag it.
101
- let validUntilLedger = null;
102
- if (rule.expiry) {
103
- if (rule.expiry.validUntilLedger !== undefined) {
104
- validUntilLedger = rule.expiry.validUntilLedger;
105
- }
106
- else if (rule.expiry.validUntilUnixSeconds !== undefined) {
107
- uncovered.push('time expiry given as a unix timestamp (OZ context rules expire by ledger sequence; supply expiry.validUntilLedger)');
108
- }
109
- }
110
- // guard -> not covered (applicability predicates are not an OZ built-in).
111
- if (rule.guard) {
112
- uncovered.push(`guard: ${describeCondition(rule.guard)}`);
113
- }
114
- // constraints -> spending_limit where they match; else not covered. The OZ
115
- // spending_limit takes `{ spending_limit: i128, period_ledgers: u32 }` and
116
- // has NO token param: it only accepts a CallContract context rule
117
- // (OnlyCallContractAllowed) and limits transfers of that context's contract,
118
- // so the spent token must equal the scope contract, and the window is a
119
- // ledger count (~5s/ledger), not seconds.
120
- for (const c of rule.constraints) {
121
- const spend = matchSpendingLimit(c);
122
- if (!spend) {
123
- uncovered.push(describeCondition(c));
124
- continue;
125
- }
126
- if (contextRuleType.kind !== 'call_contract' || spend.token !== contextRuleType.contract) {
127
- uncovered.push(`spending_limit on token ${spend.token} needs a CallContract context scoped to that token (OZ pins the limit to the context contract, not a token param)`);
128
- continue;
129
- }
130
- policyRefs.push({
131
- kind: 'oz_builtin',
132
- primitive: {
133
- primitive: 'spending_limit',
134
- params: {
135
- spending_limit: spend.limit,
136
- period_ledgers: secondsToLedgers(spend.windowSeconds),
137
- },
138
- },
139
- instanceAddress: config.instances.spending_limit,
140
- });
141
- }
142
- // approval.threshold -> simple/weighted threshold primitive. A threshold < 1
143
- // is not a real M-of-N gate (0 approvals authorises everything), so refuse to
144
- // emit a no-op primitive and flag it as not covered.
145
- if (rule.approval) {
146
- if (!Number.isInteger(rule.approval.threshold) || rule.approval.threshold < 1) {
147
- uncovered.push(`approval threshold ${rule.approval.threshold} is not a positive integer (a 0 or negative threshold is not an M-of-N gate)`);
148
- }
149
- else {
150
- const weights = rule.approval.weights;
151
- if (weights && Object.keys(weights).length > 0) {
152
- policyRefs.push({
153
- kind: 'oz_builtin',
154
- primitive: {
155
- primitive: 'weighted_threshold',
156
- params: { threshold: rule.approval.threshold, weights },
157
- },
158
- instanceAddress: config.instances.weighted_threshold,
159
- });
160
- }
161
- else {
162
- policyRefs.push({
163
- kind: 'oz_builtin',
164
- primitive: {
165
- primitive: 'simple_threshold',
166
- params: { threshold: rule.approval.threshold },
167
- },
168
- instanceAddress: config.instances.simple_threshold,
169
- });
170
- }
171
- }
172
- }
173
- const capExceeded = policyRefs.length > OZ_LIMITS.maxPoliciesPerRule;
174
- if (capExceeded) {
175
- uncovered.push(`policy count ${policyRefs.length} exceeds OZ maxPoliciesPerRule (${OZ_LIMITS.maxPoliciesPerRule})`);
176
- }
177
- const contextRule = {
178
- contextRuleType,
179
- name: contextRuleType.kind === 'call_contract'
180
- ? `call_contract:${contextRuleType.contract}`
181
- : 'default',
182
- validUntilLedger,
183
- signers: [],
184
- policies: policyRefs,
185
- };
186
- return { contextRule, policyRefs, uncovered, capExceeded };
187
- }
188
- /** Convert a spend window in seconds to OZ `period_ledgers` (u32, >= 1).
189
- * Stellar targets a ~5s ledger close time. */
190
- function secondsToLedgers(windowSeconds) {
191
- return Math.max(1, Math.round(windowSeconds / SOROBAN_LIMITS.secondsPerLedger));
192
- }
193
- /** Match the `window_spent(token, window) <= limit` compare that lowers to the
194
- * OZ `spending_limit` primitive. Only `lte` matches (the spend-cap semantic). */
195
- function matchSpendingLimit(c) {
196
- if (c.op !== 'compare')
197
- return null;
198
- const { selector, operator, value } = c.compare;
199
- if (selector.kind !== 'window_spent' || operator !== 'lte')
200
- return null;
201
- return { token: selector.token, limit: value, windowSeconds: selector.windowSeconds };
202
- }
203
- /** Human-readable descriptor for a construct the OZ built-in-primitive backend
204
- * cannot express, used to populate `uncovered`. */
205
- function describeCondition(cond) {
206
- switch (cond.op) {
207
- case 'in':
208
- return `value allowlist on ${describeSelector(cond.selector)} (arg allowlist)`;
209
- case 'eq_seq':
210
- return `exact ordered sequence on ${describeSelector(cond.selector)} (OZ built-ins cannot express an exact vector)`;
211
- case 'not':
212
- return 'negated condition (predicate DSL)';
213
- case 'and':
214
- case 'or':
215
- return `nested ${cond.op} condition (predicate DSL)`;
216
- case 'compare': {
217
- const s = cond.compare.selector;
218
- switch (s.kind) {
219
- case 'window_spent':
220
- return `spend-window comparison with operator '${cond.compare.operator}' (only 'lte' lowers to spending_limit)`;
221
- case 'amount':
222
- return `per-call amount comparison on ${s.token} (predicate DSL)`;
223
- case 'arg':
224
- return `argument comparison on arg ${s.argIndex} (predicate DSL)`;
225
- case 'arg_len':
226
- return `vec length comparison on arg ${s.argIndex} (predicate DSL)`;
227
- case 'arg_field':
228
- return `map field comparison on arg ${s.argIndex}.${s.field} (predicate DSL)`;
229
- case 'calldata':
230
- return 'EVM calldata comparison (predicate DSL)';
231
- case 'value':
232
- return 'tx.value comparison (predicate DSL)';
233
- case 'now':
234
- case 'valid_until':
235
- return 'time comparison (predicate DSL)';
236
- }
237
- }
238
- }
239
- }
240
- function describeSelector(s) {
241
- switch (s.kind) {
242
- case 'arg':
243
- return `arg ${s.argIndex}`;
244
- case 'arg_len':
245
- return `arg_len(${s.argIndex})`;
246
- case 'arg_field':
247
- return `arg_field(${s.argIndex}, ${s.element}, ${s.field})`;
248
- case 'amount':
249
- return `amount(${s.token})`;
250
- case 'window_spent':
251
- return `window_spent(${s.token})`;
252
- case 'calldata':
253
- return `calldata[${s.offset}:${s.offset + s.length}]`;
254
- default:
255
- return s.kind;
256
- }
257
- }
258
- function simulateStub() {
259
- return {
260
- backend: 'ts-model',
261
- permitted: null,
262
- evaluations: [],
263
- notes: ['stub: real permit/deny semantics wiring is a later phase'],
264
- };
265
- }
266
- /** Canonical JSON with recursively sorted object keys (stable across runs). */
267
- function canonicalStringify(value) {
268
- return JSON.stringify(sortKeys(value));
269
- }
270
- function sortKeys(value) {
271
- if (Array.isArray(value))
272
- return value.map(sortKeys);
273
- if (value && typeof value === 'object') {
274
- const out = {};
275
- for (const key of Object.keys(value).sort()) {
276
- out[key] = sortKeys(value[key]);
277
- }
278
- return out;
279
- }
280
- return value;
281
- }
@@ -1 +0,0 @@
1
- export { createOzAdapter, type OzAdapterConfig, type OzPrimitiveInstances, PLACEHOLDER_OZ_INSTANCES, placeholderOzConfig, } from './adapter.ts';
@@ -1,2 +0,0 @@
1
- // src/adapters/oz/index.ts - re-export the OZ Accounts CustodyAdapter.
2
- export { createOzAdapter, PLACEHOLDER_OZ_INSTANCES, placeholderOzConfig, } from "./adapter.js";