@juspay/neurolink 11.29.2 → 11.30.0

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 (50) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/dist/auth/anthropicOAuth.d.ts +50 -0
  3. package/dist/auth/anthropicOAuth.js +78 -0
  4. package/dist/browser/neurolink.min.js +393 -393
  5. package/dist/cli/commands/proxy.d.ts +2 -0
  6. package/dist/cli/commands/proxy.js +284 -4
  7. package/dist/cli/commands/proxyExpose.d.ts +35 -0
  8. package/dist/cli/commands/proxyExpose.js +252 -0
  9. package/dist/cli/commands/proxyPeer.d.ts +29 -0
  10. package/dist/cli/commands/proxyPeer.js +738 -0
  11. package/dist/cli/commands/proxyShare.d.ts +37 -0
  12. package/dist/cli/commands/proxyShare.js +1080 -0
  13. package/dist/cli/parser.js +7 -1
  14. package/dist/proxy/peerStore.d.ts +52 -0
  15. package/dist/proxy/peerStore.js +324 -0
  16. package/dist/proxy/peerTransport.d.ts +38 -0
  17. package/dist/proxy/peerTransport.js +242 -0
  18. package/dist/proxy/proxyPaths.d.ts +8 -0
  19. package/dist/proxy/proxyPaths.js +55 -17
  20. package/dist/proxy/requestLogger.js +8 -0
  21. package/dist/proxy/residentGrants.d.ts +57 -0
  22. package/dist/proxy/residentGrants.js +393 -0
  23. package/dist/proxy/shareAudit.d.ts +81 -0
  24. package/dist/proxy/shareAudit.js +280 -0
  25. package/dist/proxy/shareContext.d.ts +38 -0
  26. package/dist/proxy/shareContext.js +92 -0
  27. package/dist/proxy/shareGate.d.ts +64 -0
  28. package/dist/proxy/shareGate.js +216 -0
  29. package/dist/proxy/shareGrants.d.ts +115 -0
  30. package/dist/proxy/shareGrants.js +590 -0
  31. package/dist/proxy/shareLease.d.ts +101 -0
  32. package/dist/proxy/shareLease.js +192 -0
  33. package/dist/proxy/shareLedger.d.ts +105 -0
  34. package/dist/proxy/shareLedger.js +406 -0
  35. package/dist/proxy/shareListener.d.ts +60 -0
  36. package/dist/proxy/shareListener.js +143 -0
  37. package/dist/proxy/shareNotes.d.ts +97 -0
  38. package/dist/proxy/shareNotes.js +234 -0
  39. package/dist/proxy/sharePolicy.d.ts +110 -0
  40. package/dist/proxy/sharePolicy.js +366 -0
  41. package/dist/proxy/shareProvisioning.d.ts +110 -0
  42. package/dist/proxy/shareProvisioning.js +237 -0
  43. package/dist/proxy/shareReceipts.d.ts +99 -0
  44. package/dist/proxy/shareReceipts.js +303 -0
  45. package/dist/proxy/shareSigning.d.ts +40 -0
  46. package/dist/proxy/shareSigning.js +78 -0
  47. package/dist/server/routes/claudeProxyRoutes.js +1066 -3
  48. package/dist/types/cli.d.ts +61 -0
  49. package/dist/types/proxy.d.ts +781 -0
  50. package/package.json +2 -1
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The one HMAC used across peer sharing.
3
+ *
4
+ * Leases, receipts and coin notes all need the same thing: a statement one node
5
+ * makes that another can check without being able to forge. They had grown
6
+ * separate copies of the same twenty lines, which is how two of them end up with
7
+ * different canonicalisation and a signature that verifies on one path and not
8
+ * the other.
9
+ *
10
+ * **Why HMAC and not a signature scheme.** The key-distribution problem that
11
+ * asymmetric keys solve does not exist here: every one of these statements
12
+ * passes between exactly two nodes that already share a secret. The package's
13
+ * browser bundle also stubs `node:crypto` down to a subset with no Ed25519 in
14
+ * it, and these modules are reachable from that build.
15
+ *
16
+ * **What that costs.** A MAC proves authorship only to someone holding the key,
17
+ * so a receipt is evidence between the two parties to it and not to a third.
18
+ * Coin notes are built around that limit rather than against it — see
19
+ * `shareNotes.ts`.
20
+ *
21
+ * @module proxy/shareSigning
22
+ */
23
+ import { createHmac, randomBytes } from "node:crypto";
24
+ /** A secret suitable for keying any of the statements in this subsystem. */
25
+ export function generateShareSecret() {
26
+ return randomBytes(32).toString("base64url");
27
+ }
28
+ /**
29
+ * Canonicalise and sign.
30
+ *
31
+ * The payload is serialized with its keys sorted, so two nodes that built the
32
+ * same object in a different order still agree on the bytes being signed.
33
+ */
34
+ export function signSharePayload(payload, secret) {
35
+ return createHmac("sha256", secret)
36
+ .update(canonicalize(payload))
37
+ .digest("base64url");
38
+ }
39
+ /** Does `signature` match what this secret would produce for this payload? */
40
+ export function verifySharePayload(payload, signature, secret) {
41
+ return secretsMatch(signSharePayload(payload, secret), signature);
42
+ }
43
+ /**
44
+ * Compare two strings without leaking where they diverge.
45
+ *
46
+ * Hand-rolled rather than `crypto.timingSafeEqual` because that is one of the
47
+ * things the browser bundle's `node:crypto` stub does not carry.
48
+ */
49
+ export function secretsMatch(expected, presented) {
50
+ if (expected.length !== presented.length || expected.length === 0) {
51
+ return false;
52
+ }
53
+ let difference = 0;
54
+ for (let index = 0; index < expected.length; index += 1) {
55
+ difference |= expected.charCodeAt(index) ^ presented.charCodeAt(index);
56
+ }
57
+ return difference === 0;
58
+ }
59
+ /**
60
+ * Deterministic JSON: object keys sorted at every depth, `undefined` dropped.
61
+ *
62
+ * Array order is meaningful and is left alone.
63
+ */
64
+ function canonicalize(value) {
65
+ return JSON.stringify(sortDeep(value));
66
+ }
67
+ function sortDeep(value) {
68
+ if (Array.isArray(value)) {
69
+ return value.map(sortDeep);
70
+ }
71
+ if (value === null || typeof value !== "object") {
72
+ return value;
73
+ }
74
+ const entries = Object.entries(value)
75
+ .filter(([, entry]) => entry !== undefined)
76
+ .sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0));
77
+ return Object.fromEntries(entries.map(([key, entry]) => [key, sortDeep(entry)]));
78
+ }