@wiimdy/openfunderse-sdk 0.1.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 (62) hide show
  1. package/README.md +43 -0
  2. package/dist/attestation-verifier.d.ts +11 -0
  3. package/dist/attestation-verifier.js +60 -0
  4. package/dist/attestation.d.ts +4 -0
  5. package/dist/attestation.js +16 -0
  6. package/dist/canonical.d.ts +3 -0
  7. package/dist/canonical.js +37 -0
  8. package/dist/dist_bak_vercel_repro/attestation-verifier.d.ts +11 -0
  9. package/dist/dist_bak_vercel_repro/attestation-verifier.js +60 -0
  10. package/dist/dist_bak_vercel_repro/attestation.d.ts +4 -0
  11. package/dist/dist_bak_vercel_repro/attestation.js +16 -0
  12. package/dist/dist_bak_vercel_repro/canonical.d.ts +3 -0
  13. package/dist/dist_bak_vercel_repro/canonical.js +37 -0
  14. package/dist/dist_bak_vercel_repro/eip712.d.ts +112 -0
  15. package/dist/dist_bak_vercel_repro/eip712.js +74 -0
  16. package/dist/dist_bak_vercel_repro/erc1271.d.ts +4 -0
  17. package/dist/dist_bak_vercel_repro/erc1271.js +24 -0
  18. package/dist/dist_bak_vercel_repro/execution-data.d.ts +3 -0
  19. package/dist/dist_bak_vercel_repro/execution-data.js +66 -0
  20. package/dist/dist_bak_vercel_repro/hash.d.ts +16 -0
  21. package/dist/dist_bak_vercel_repro/hash.js +67 -0
  22. package/dist/dist_bak_vercel_repro/index.d.ts +14 -0
  23. package/dist/dist_bak_vercel_repro/index.js +14 -0
  24. package/dist/dist_bak_vercel_repro/nadfun-types.d.ts +29 -0
  25. package/dist/dist_bak_vercel_repro/nadfun-types.js +1 -0
  26. package/dist/dist_bak_vercel_repro/ordering.d.ts +5 -0
  27. package/dist/dist_bak_vercel_repro/ordering.js +22 -0
  28. package/dist/dist_bak_vercel_repro/relayer-utils.d.ts +29 -0
  29. package/dist/dist_bak_vercel_repro/relayer-utils.js +108 -0
  30. package/dist/dist_bak_vercel_repro/scope.d.ts +5 -0
  31. package/dist/dist_bak_vercel_repro/scope.js +26 -0
  32. package/dist/dist_bak_vercel_repro/types.d.ts +106 -0
  33. package/dist/dist_bak_vercel_repro/types.js +1 -0
  34. package/dist/dist_bak_vercel_repro/validate.d.ts +2 -0
  35. package/dist/dist_bak_vercel_repro/validate.js +12 -0
  36. package/dist/dist_bak_vercel_repro/weighted-attestation.d.ts +19 -0
  37. package/dist/dist_bak_vercel_repro/weighted-attestation.js +62 -0
  38. package/dist/eip712.d.ts +112 -0
  39. package/dist/eip712.js +74 -0
  40. package/dist/erc1271.d.ts +4 -0
  41. package/dist/erc1271.js +24 -0
  42. package/dist/execution-data.d.ts +3 -0
  43. package/dist/execution-data.js +66 -0
  44. package/dist/hash.d.ts +16 -0
  45. package/dist/hash.js +67 -0
  46. package/dist/index.d.ts +14 -0
  47. package/dist/index.js +14 -0
  48. package/dist/nadfun-types.d.ts +29 -0
  49. package/dist/nadfun-types.js +1 -0
  50. package/dist/ordering.d.ts +5 -0
  51. package/dist/ordering.js +22 -0
  52. package/dist/relayer-utils.d.ts +29 -0
  53. package/dist/relayer-utils.js +108 -0
  54. package/dist/scope.d.ts +5 -0
  55. package/dist/scope.js +26 -0
  56. package/dist/types.d.ts +106 -0
  57. package/dist/types.js +1 -0
  58. package/dist/validate.d.ts +2 -0
  59. package/dist/validate.js +12 -0
  60. package/dist/weighted-attestation.d.ts +19 -0
  61. package/dist/weighted-attestation.js +62 -0
  62. package/package.json +32 -0
@@ -0,0 +1,62 @@
1
+ function toKey(address) {
2
+ return address.toLowerCase();
3
+ }
4
+ export function buildValidatorWeightMap(entries, options = {}) {
5
+ const allowZeroWeight = options.allowZeroWeight ?? false;
6
+ const map = new Map();
7
+ for (const entry of entries) {
8
+ if (entry.weight < 0n) {
9
+ throw new Error("weight must be non-negative");
10
+ }
11
+ if (!allowZeroWeight && entry.weight === 0n) {
12
+ throw new Error("weight must be positive");
13
+ }
14
+ const key = toKey(entry.validator);
15
+ if (map.has(key)) {
16
+ throw new Error(`duplicate validator weight entry: ${entry.validator}`);
17
+ }
18
+ map.set(key, entry.weight);
19
+ }
20
+ return map;
21
+ }
22
+ export function totalValidatorWeight(weightMap) {
23
+ let total = 0n;
24
+ for (const weight of weightMap.values()) {
25
+ total += weight;
26
+ }
27
+ return total;
28
+ }
29
+ export function attestedWeight(attesters, weightMap) {
30
+ let total = 0n;
31
+ const seen = new Set();
32
+ for (const attester of attesters) {
33
+ const key = toKey(attester);
34
+ if (seen.has(key))
35
+ continue;
36
+ seen.add(key);
37
+ const weight = weightMap.get(key);
38
+ if (weight !== undefined) {
39
+ total += weight;
40
+ }
41
+ }
42
+ return total;
43
+ }
44
+ export function reachedWeightedThreshold(attesters, weightMap, thresholdWeight) {
45
+ if (thresholdWeight <= 0n) {
46
+ throw new Error("thresholdWeight must be positive");
47
+ }
48
+ return attestedWeight(attesters, weightMap) >= thresholdWeight;
49
+ }
50
+ export function weightedThresholdState(attesters, weightMap, thresholdWeight) {
51
+ if (thresholdWeight <= 0n) {
52
+ throw new Error("thresholdWeight must be positive");
53
+ }
54
+ const totalWeight = totalValidatorWeight(weightMap);
55
+ const reachedWeight = attestedWeight(attesters, weightMap);
56
+ return {
57
+ totalWeight,
58
+ attestedWeight: reachedWeight,
59
+ thresholdWeight,
60
+ met: reachedWeight >= thresholdWeight
61
+ };
62
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@wiimdy/openfunderse-sdk",
3
+ "version": "0.1.1",
4
+ "description": "Canonical hashing and EIP-712 helpers for Claw protocol components.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "clean": "rm -rf dist",
22
+ "typecheck": "tsc -p tsconfig.json --noEmit",
23
+ "test": "npm run build && node --test test/**/*.test.mjs",
24
+ "intent:compute:nadfun": "npm run build && node scripts/compute-nadfun-intent.mjs"
25
+ },
26
+ "dependencies": {
27
+ "viem": "^2.38.2"
28
+ },
29
+ "devDependencies": {
30
+ "typescript": "^5.9.2"
31
+ }
32
+ }