@oobe-protocol-labs/synapse-sap-sdk 0.9.3 → 0.10.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 (72) hide show
  1. package/dist/cjs/constants/index.js +9 -1
  2. package/dist/cjs/constants/index.js.map +1 -1
  3. package/dist/cjs/constants/payments.js +87 -0
  4. package/dist/cjs/constants/payments.js.map +1 -0
  5. package/dist/cjs/constants/seeds.js +9 -1
  6. package/dist/cjs/constants/seeds.js.map +1 -1
  7. package/dist/cjs/idl/synapse_agent_sap.json +270 -2
  8. package/dist/cjs/index.js +13 -2
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/modules/escrow-v2.js +10 -0
  11. package/dist/cjs/modules/escrow-v2.js.map +1 -1
  12. package/dist/cjs/modules/escrow.js +29 -4
  13. package/dist/cjs/modules/escrow.js.map +1 -1
  14. package/dist/cjs/pda/index.js +31 -1
  15. package/dist/cjs/pda/index.js.map +1 -1
  16. package/dist/cjs/plugin/index.js +3 -1
  17. package/dist/cjs/plugin/index.js.map +1 -1
  18. package/dist/cjs/utils/hash.js +52 -1
  19. package/dist/cjs/utils/hash.js.map +1 -1
  20. package/dist/cjs/utils/index.js +2 -1
  21. package/dist/cjs/utils/index.js.map +1 -1
  22. package/dist/esm/constants/index.js +2 -0
  23. package/dist/esm/constants/index.js.map +1 -1
  24. package/dist/esm/constants/payments.js +82 -0
  25. package/dist/esm/constants/payments.js.map +1 -0
  26. package/dist/esm/constants/seeds.js +9 -1
  27. package/dist/esm/constants/seeds.js.map +1 -1
  28. package/dist/esm/idl/synapse_agent_sap.json +270 -2
  29. package/dist/esm/index.js +4 -2
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/modules/escrow-v2.js +11 -1
  32. package/dist/esm/modules/escrow-v2.js.map +1 -1
  33. package/dist/esm/modules/escrow.js +30 -5
  34. package/dist/esm/modules/escrow.js.map +1 -1
  35. package/dist/esm/pda/index.js +29 -0
  36. package/dist/esm/pda/index.js.map +1 -1
  37. package/dist/esm/plugin/index.js +3 -1
  38. package/dist/esm/plugin/index.js.map +1 -1
  39. package/dist/esm/utils/hash.js +50 -0
  40. package/dist/esm/utils/hash.js.map +1 -1
  41. package/dist/esm/utils/index.js +1 -1
  42. package/dist/esm/utils/index.js.map +1 -1
  43. package/dist/types/constants/index.d.ts +1 -0
  44. package/dist/types/constants/index.d.ts.map +1 -1
  45. package/dist/types/constants/payments.d.ts +78 -0
  46. package/dist/types/constants/payments.d.ts.map +1 -0
  47. package/dist/types/constants/seeds.d.ts +9 -1
  48. package/dist/types/constants/seeds.d.ts.map +1 -1
  49. package/dist/types/index.d.ts +3 -2
  50. package/dist/types/index.d.ts.map +1 -1
  51. package/dist/types/modules/escrow-v2.d.ts.map +1 -1
  52. package/dist/types/modules/escrow.d.ts +9 -1
  53. package/dist/types/modules/escrow.d.ts.map +1 -1
  54. package/dist/types/pda/index.d.ts +21 -0
  55. package/dist/types/pda/index.d.ts.map +1 -1
  56. package/dist/types/plugin/index.d.ts.map +1 -1
  57. package/dist/types/utils/hash.d.ts +27 -0
  58. package/dist/types/utils/hash.d.ts.map +1 -1
  59. package/dist/types/utils/index.d.ts +1 -1
  60. package/dist/types/utils/index.d.ts.map +1 -1
  61. package/package.json +1 -1
  62. package/src/constants/index.ts +11 -1
  63. package/src/constants/payments.ts +92 -0
  64. package/src/constants/seeds.ts +9 -1
  65. package/src/idl/synapse_agent_sap.json +270 -2
  66. package/src/index.ts +12 -1
  67. package/src/modules/escrow-v2.ts +15 -0
  68. package/src/modules/escrow.ts +36 -3
  69. package/src/pda/index.ts +39 -0
  70. package/src/plugin/index.ts +2 -0
  71. package/src/utils/hash.ts +56 -0
  72. package/src/utils/index.ts +1 -1
package/src/utils/hash.ts CHANGED
@@ -55,3 +55,59 @@ export const sha256 = (input: string | Buffer | Uint8Array): Uint8Array => {
55
55
  * ```
56
56
  */
57
57
  export const hashToArray = (hash: Uint8Array): number[] => Array.from(hash);
58
+
59
+ /**
60
+ * Compute the deterministic batch root used by `settle_batch` (v0.10.0).
61
+ *
62
+ * The on-chain program enforces:
63
+ * `batch_root == sha256(s_0 || s_1 || ... || s_{N-1})`
64
+ * where each `s_i` is a 32-byte service hash, in the same order as the
65
+ * `settlements: Settlement[]` array passed to the instruction.
66
+ *
67
+ * Use this helper to derive the seed for the {@link deriveSettlementReceipt}
68
+ * PDA when batching settlements.
69
+ *
70
+ * @name computeBatchRoot
71
+ * @param serviceHashes - Array of 32-byte service hashes (Buffer/Uint8Array/number[]).
72
+ * @returns {Uint8Array} 32-byte batch root.
73
+ * @throws If any `serviceHashes[i]` is not exactly 32 bytes long.
74
+ * @category Utils
75
+ * @since v0.10.0
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import { computeBatchRoot, hashToArray } from "@synapse-sap/sdk/utils";
80
+ *
81
+ * const root = computeBatchRoot([h1, h2, h3]);
82
+ * await client.escrow.settleBatch(depositor, settlements, root);
83
+ * ```
84
+ */
85
+ export const computeBatchRoot = (
86
+ serviceHashes: ReadonlyArray<Uint8Array | Buffer | number[]>,
87
+ ): Uint8Array => {
88
+ if (serviceHashes.length === 0) {
89
+ throw new Error("computeBatchRoot: serviceHashes must not be empty");
90
+ }
91
+ const hash = createHash("sha256");
92
+ for (let i = 0; i < serviceHashes.length; i++) {
93
+ const h = serviceHashes[i];
94
+ let buf: Buffer;
95
+ if (h instanceof Uint8Array) {
96
+ buf = Buffer.from(h);
97
+ } else if (Array.isArray(h)) {
98
+ buf = Buffer.from(h);
99
+ } else {
100
+ throw new Error(
101
+ `computeBatchRoot: serviceHashes[${i}] is undefined or unsupported type`,
102
+ );
103
+ }
104
+ if (buf.length !== 32) {
105
+ throw new Error(
106
+ `computeBatchRoot: serviceHashes[${i}] must be 32 bytes, got ${buf.length}`,
107
+ );
108
+ }
109
+ hash.update(buf);
110
+ }
111
+ return new Uint8Array(hash.digest());
112
+ };
113
+
@@ -14,7 +14,7 @@
14
14
  * ```
15
15
  */
16
16
 
17
- export { sha256, hashToArray } from "./hash";
17
+ export { sha256, hashToArray, computeBatchRoot } from "./hash";
18
18
  export { assert } from "./validation";
19
19
  export { serializeAccount, serializeValue } from "./serialization";
20
20