@fora-protocol/sdk 1.0.3

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 (115) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +37 -0
  3. package/gen/ts/vocab/functiontokens.js +78 -0
  4. package/gen/ts/vocab/functiontokens.ts +84 -0
  5. package/gen/ts/vocab/geographytokens.js +30 -0
  6. package/gen/ts/vocab/geographytokens.ts +37 -0
  7. package/gen/ts/vocab/pricingunits.js +56 -0
  8. package/gen/ts/vocab/pricingunits.ts +63 -0
  9. package/gen/ts/vocab/quotametrics.js +40 -0
  10. package/gen/ts/vocab/quotametrics.ts +47 -0
  11. package/gen/ts/vocab/usertypes.js +40 -0
  12. package/gen/ts/vocab/usertypes.ts +46 -0
  13. package/gen/ts/wire/base.js +245 -0
  14. package/gen/ts/wire/base.ts +255 -0
  15. package/gen/ts/wire/names.js +41 -0
  16. package/gen/ts/wire/names.ts +42 -0
  17. package/gen/ts/wire/schemas.js +111 -0
  18. package/gen/ts/wire/schemas.ts +216 -0
  19. package/package.json +164 -0
  20. package/sdk/ts/client/content.d.ts +74 -0
  21. package/sdk/ts/client/content.js +466 -0
  22. package/sdk/ts/client/errors.d.ts +79 -0
  23. package/sdk/ts/client/errors.js +148 -0
  24. package/sdk/ts/client/index.d.ts +241 -0
  25. package/sdk/ts/client/index.js +740 -0
  26. package/sdk/ts/client/route.d.ts +41 -0
  27. package/sdk/ts/client/route.js +107 -0
  28. package/sdk/ts/client/send.d.ts +64 -0
  29. package/sdk/ts/client/send.js +142 -0
  30. package/sdk/ts/client/transport.d.ts +187 -0
  31. package/sdk/ts/client/transport.js +381 -0
  32. package/sdk/ts/core/multisig-parse.d.ts +47 -0
  33. package/sdk/ts/core/multisig-parse.js +234 -0
  34. package/sdk/ts/core/sign-request.d.ts +83 -0
  35. package/sdk/ts/core/sign-request.js +146 -0
  36. package/sdk/ts/core/sign.d.ts +31 -0
  37. package/sdk/ts/core/sign.js +82 -0
  38. package/sdk/ts/core/signing-transport.d.ts +75 -0
  39. package/sdk/ts/core/signing-transport.js +172 -0
  40. package/sdk/ts/core/verifier.d.ts +177 -0
  41. package/sdk/ts/core/verifier.js +269 -0
  42. package/sdk/ts/core/verify-multisig-request.d.ts +72 -0
  43. package/sdk/ts/core/verify-multisig-request.js +112 -0
  44. package/sdk/ts/core/verify-request.d.ts +181 -0
  45. package/sdk/ts/core/verify-request.js +284 -0
  46. package/sdk/ts/core/window.d.ts +22 -0
  47. package/sdk/ts/core/window.js +43 -0
  48. package/sdk/ts/core/wire-canon.d.ts +20 -0
  49. package/sdk/ts/core/wire-canon.js +174 -0
  50. package/sdk/ts/hono/middleware.d.ts +38 -0
  51. package/sdk/ts/hono/middleware.js +64 -0
  52. package/sdk/ts/resolvers/errors.d.ts +130 -0
  53. package/sdk/ts/resolvers/errors.js +150 -0
  54. package/sdk/ts/resolvers/http.d.ts +98 -0
  55. package/sdk/ts/resolvers/http.js +274 -0
  56. package/sdk/ts/resolvers/index.d.ts +9 -0
  57. package/sdk/ts/resolvers/index.js +15 -0
  58. package/sdk/ts/resolvers/jwks.d.ts +2 -0
  59. package/sdk/ts/resolvers/jwks.js +43 -0
  60. package/sdk/ts/resolvers/offer-key-cache.d.ts +68 -0
  61. package/sdk/ts/resolvers/offer-key-cache.js +152 -0
  62. package/sdk/ts/resolvers/registration-requirements.d.ts +47 -0
  63. package/sdk/ts/resolvers/registration-requirements.js +220 -0
  64. package/sdk/ts/resolvers/ssrf.d.ts +28 -0
  65. package/sdk/ts/resolvers/ssrf.js +235 -0
  66. package/sdk/ts/resolvers/static.d.ts +7 -0
  67. package/sdk/ts/resolvers/static.js +16 -0
  68. package/sdk/ts/resolvers/wba.d.ts +134 -0
  69. package/sdk/ts/resolvers/wba.js +506 -0
  70. package/sdk/ts/resolvers/wellknown.d.ts +28 -0
  71. package/sdk/ts/resolvers/wellknown.js +169 -0
  72. package/sdk/ts/src/acceptance.d.ts +46 -0
  73. package/sdk/ts/src/acceptance.js +162 -0
  74. package/sdk/ts/src/base64url.d.ts +19 -0
  75. package/sdk/ts/src/base64url.js +55 -0
  76. package/sdk/ts/src/crossfield.d.ts +28 -0
  77. package/sdk/ts/src/crossfield.js +215 -0
  78. package/sdk/ts/src/endpoint-rule.d.ts +30 -0
  79. package/sdk/ts/src/endpoint-rule.js +63 -0
  80. package/sdk/ts/src/errordetail.d.ts +115 -0
  81. package/sdk/ts/src/errordetail.js +256 -0
  82. package/sdk/ts/src/hashurl.d.ts +5 -0
  83. package/sdk/ts/src/hashurl.js +15 -0
  84. package/sdk/ts/src/host-ref.d.ts +70 -0
  85. package/sdk/ts/src/host-ref.js +320 -0
  86. package/sdk/ts/src/hosts.d.ts +138 -0
  87. package/sdk/ts/src/hosts.js +214 -0
  88. package/sdk/ts/src/idempotency.d.ts +11 -0
  89. package/sdk/ts/src/idempotency.js +27 -0
  90. package/sdk/ts/src/jsondepth.d.ts +27 -0
  91. package/sdk/ts/src/jsondepth.js +77 -0
  92. package/sdk/ts/src/licenseterm.d.ts +113 -0
  93. package/sdk/ts/src/licenseterm.js +433 -0
  94. package/sdk/ts/src/money.d.ts +21 -0
  95. package/sdk/ts/src/money.js +60 -0
  96. package/sdk/ts/src/offer-sign.d.ts +11 -0
  97. package/sdk/ts/src/offer-sign.js +31 -0
  98. package/sdk/ts/src/opaque-url.d.ts +3 -0
  99. package/sdk/ts/src/opaque-url.js +20 -0
  100. package/sdk/ts/src/pop.d.ts +51 -0
  101. package/sdk/ts/src/pop.js +166 -0
  102. package/sdk/ts/src/regschema.d.ts +229 -0
  103. package/sdk/ts/src/regschema.js +1315 -0
  104. package/sdk/ts/src/scopes.d.ts +20 -0
  105. package/sdk/ts/src/scopes.js +45 -0
  106. package/sdk/ts/src/signurl.d.ts +23 -0
  107. package/sdk/ts/src/signurl.js +107 -0
  108. package/sdk/ts/src/thumbprint.d.ts +14 -0
  109. package/sdk/ts/src/thumbprint.js +24 -0
  110. package/sdk/ts/src/verify.d.ts +49 -0
  111. package/sdk/ts/src/verify.js +109 -0
  112. package/sdk/ts/src/wire-names.d.ts +1 -0
  113. package/sdk/ts/src/wire-names.js +16 -0
  114. package/sdk/ts/src/wire.d.ts +68 -0
  115. package/sdk/ts/src/wire.js +114 -0
package/package.json ADDED
@@ -0,0 +1,164 @@
1
+ {
2
+ "name": "@fora-protocol/sdk",
3
+ "version": "1.0.3",
4
+ "description": "FORA protocol SDK for TypeScript: the generated wire schemas (Zod) and vocabulary, the IO-free protocol mechanics (signing, verification, canonicalization), the key/endpoint resolvers and the Connect-unary JSON client.",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/FORA-Protocol/protocol.git",
9
+ "directory": "sdk/ts"
10
+ },
11
+ "homepage": "https://fora-protocol.org",
12
+ "type": "module",
13
+ "files": [
14
+ "gen",
15
+ "sdk"
16
+ ],
17
+ "exports": {
18
+ "./base64url": {
19
+ "types": "./sdk/ts/src/base64url.d.ts",
20
+ "default": "./sdk/ts/src/base64url.js"
21
+ },
22
+ "./thumbprint": {
23
+ "types": "./sdk/ts/src/thumbprint.d.ts",
24
+ "default": "./sdk/ts/src/thumbprint.js"
25
+ },
26
+ "./verify": {
27
+ "types": "./sdk/ts/src/verify.d.ts",
28
+ "default": "./sdk/ts/src/verify.js"
29
+ },
30
+ "./signurl": {
31
+ "types": "./sdk/ts/src/signurl.d.ts",
32
+ "default": "./sdk/ts/src/signurl.js"
33
+ },
34
+ "./offer-sign": {
35
+ "types": "./sdk/ts/src/offer-sign.d.ts",
36
+ "default": "./sdk/ts/src/offer-sign.js"
37
+ },
38
+ "./pop": {
39
+ "types": "./sdk/ts/src/pop.d.ts",
40
+ "default": "./sdk/ts/src/pop.js"
41
+ },
42
+ "./crossfield": {
43
+ "types": "./sdk/ts/src/crossfield.d.ts",
44
+ "default": "./sdk/ts/src/crossfield.js"
45
+ },
46
+ "./errordetail": {
47
+ "types": "./sdk/ts/src/errordetail.d.ts",
48
+ "default": "./sdk/ts/src/errordetail.js"
49
+ },
50
+ "./money": {
51
+ "types": "./sdk/ts/src/money.d.ts",
52
+ "default": "./sdk/ts/src/money.js"
53
+ },
54
+ "./idempotency": {
55
+ "types": "./sdk/ts/src/idempotency.d.ts",
56
+ "default": "./sdk/ts/src/idempotency.js"
57
+ },
58
+ "./scopes": {
59
+ "types": "./sdk/ts/src/scopes.d.ts",
60
+ "default": "./sdk/ts/src/scopes.js"
61
+ },
62
+ "./hashurl": {
63
+ "types": "./sdk/ts/src/hashurl.d.ts",
64
+ "default": "./sdk/ts/src/hashurl.js"
65
+ },
66
+ "./hosts": {
67
+ "types": "./sdk/ts/src/hosts.d.ts",
68
+ "default": "./sdk/ts/src/hosts.js"
69
+ },
70
+ "./regschema": {
71
+ "types": "./sdk/ts/src/regschema.d.ts",
72
+ "default": "./sdk/ts/src/regschema.js"
73
+ },
74
+ "./licenseterm": {
75
+ "types": "./sdk/ts/src/licenseterm.d.ts",
76
+ "default": "./sdk/ts/src/licenseterm.js"
77
+ },
78
+ "./wire": {
79
+ "types": "./sdk/ts/src/wire.d.ts",
80
+ "default": "./sdk/ts/src/wire.js"
81
+ },
82
+ "./core": {
83
+ "types": "./sdk/ts/core/verifier.d.ts",
84
+ "default": "./sdk/ts/core/verifier.js"
85
+ },
86
+ "./core/wire-canon": {
87
+ "types": "./sdk/ts/core/wire-canon.d.ts",
88
+ "default": "./sdk/ts/core/wire-canon.js"
89
+ },
90
+ "./core/sign": {
91
+ "types": "./sdk/ts/core/sign.d.ts",
92
+ "default": "./sdk/ts/core/sign.js"
93
+ },
94
+ "./core/sign-request": {
95
+ "types": "./sdk/ts/core/sign-request.d.ts",
96
+ "default": "./sdk/ts/core/sign-request.js"
97
+ },
98
+ "./core/signing-transport": {
99
+ "types": "./sdk/ts/core/signing-transport.d.ts",
100
+ "default": "./sdk/ts/core/signing-transport.js"
101
+ },
102
+ "./core/verify-request": {
103
+ "types": "./sdk/ts/core/verify-request.d.ts",
104
+ "default": "./sdk/ts/core/verify-request.js"
105
+ },
106
+ "./core/verify-multisig-request": {
107
+ "types": "./sdk/ts/core/verify-multisig-request.d.ts",
108
+ "default": "./sdk/ts/core/verify-multisig-request.js"
109
+ },
110
+ "./core/window": {
111
+ "types": "./sdk/ts/core/window.d.ts",
112
+ "default": "./sdk/ts/core/window.js"
113
+ },
114
+ "./hono": {
115
+ "types": "./sdk/ts/hono/middleware.d.ts",
116
+ "default": "./sdk/ts/hono/middleware.js"
117
+ },
118
+ "./acceptance": {
119
+ "types": "./sdk/ts/src/acceptance.d.ts",
120
+ "default": "./sdk/ts/src/acceptance.js"
121
+ },
122
+ "./resolvers": {
123
+ "types": "./sdk/ts/resolvers/index.d.ts",
124
+ "default": "./sdk/ts/resolvers/index.js"
125
+ },
126
+ "./client": {
127
+ "types": "./sdk/ts/client/index.d.ts",
128
+ "default": "./sdk/ts/client/index.js"
129
+ },
130
+ "./wire/schemas": {
131
+ "types": "./gen/ts/wire/schemas.ts",
132
+ "default": "./gen/ts/wire/schemas.js"
133
+ },
134
+ "./wire/base": {
135
+ "types": "./gen/ts/wire/base.ts",
136
+ "default": "./gen/ts/wire/base.js"
137
+ },
138
+ "./wire/names": {
139
+ "types": "./gen/ts/wire/names.ts",
140
+ "default": "./gen/ts/wire/names.js"
141
+ },
142
+ "./vocab/*": {
143
+ "types": "./gen/ts/vocab/*.ts",
144
+ "default": "./gen/ts/vocab/*.js"
145
+ }
146
+ },
147
+ "dependencies": {
148
+ "ajv": "^8.20.0",
149
+ "canonicalize": "^3.0.0",
150
+ "undici": "^6.27.0"
151
+ },
152
+ "peerDependencies": {
153
+ "hono": "^4.7.0",
154
+ "zod": "^3.23.0 || ^4.0.0"
155
+ },
156
+ "peerDependenciesMeta": {
157
+ "hono": {
158
+ "optional": true
159
+ }
160
+ },
161
+ "publishConfig": {
162
+ "access": "public"
163
+ }
164
+ }
@@ -0,0 +1,74 @@
1
+ import { type Dispatcher } from "undici";
2
+ import type { Window } from "../core/window.ts";
3
+ /**
4
+ * DEFAULT_CONTENT_TIMEOUT_MS bounds one content fetch. An agent is blocked on the call
5
+ * that triggered it, so a fetch that has not answered by now is more useful as a reported
6
+ * failure than as a hang.
7
+ */
8
+ export declare const DEFAULT_CONTENT_TIMEOUT_MS = 30000;
9
+ /**
10
+ * DEFAULT_MAX_CONTENT_BYTES caps one fetched body at 8 MiB. A memory bound on the
11
+ * fetching process, not a judgement about how large licensed content may be: the body is
12
+ * buffered whole and held for the life of the call, and a batch fetches one per item.
13
+ */
14
+ export declare const DEFAULT_MAX_CONTENT_BYTES: number;
15
+ /** One fetched resource. */
16
+ export interface Content {
17
+ /** The signed delivery URL that was fetched, echoed back so a caller correlating a
18
+ * batch does not have to keep its own map. */
19
+ url: string;
20
+ /** The media type the edge served, parameters stripped. */
21
+ mimeType: string;
22
+ /** The fetched bytes. */
23
+ body: Uint8Array;
24
+ }
25
+ /** What the content leg needs to mint one proof and dial once. */
26
+ export interface ContentFetchOptions {
27
+ /** The agent keypair the delivery URL is bound to. Both halves are required and
28
+ * neither can be derived from the other: the private half signs, the public half is
29
+ * presented alongside. */
30
+ keyPair: CryptoKeyPair;
31
+ /** The freshness window stamped on the proof. Short on purpose, and deliberately NOT
32
+ * the signed URL's own expiry, which can be hours: the proof covers only the method
33
+ * and the URL, so for as long as the window is open anyone who observes the request
34
+ * can repeat it. */
35
+ window?: Window;
36
+ timeoutMs?: number;
37
+ maxBytes?: number;
38
+ requestId?: () => string;
39
+ /** The dialing seam, guarded by default. An edge runtime with no undici injects its
40
+ * own; the same obligations come with it — no redirects, the address pin, and a body
41
+ * whose socket is released even when this leg refuses without reading it. */
42
+ dispatcher?: Dispatcher;
43
+ }
44
+ /**
45
+ * fetchContent retrieves the content at signedURL, presenting the proof of possession
46
+ * minted for it.
47
+ *
48
+ * Redirects are REFUSED. Following one would either replay a proof bound to the old URL,
49
+ * which the edge's own check rejects, or hand a fresh proof of possession of the agent's
50
+ * key to whatever host the first hop named.
51
+ *
52
+ * The URL is taken as given. Whether it is one this agent bought, and whether its
53
+ * agent_id matches this agent's key, are the CALLER's checks to make — the SDK exports
54
+ * verifyEd25519SignedUrl and the proof-of-possession verifier for exactly that, and
55
+ * running them first turns an edge 403 into a local answer. Worth doing when the URL
56
+ * reached the caller from anywhere but its own execute response: a proof is minted for
57
+ * whatever URL is passed in.
58
+ */
59
+ export declare function fetchContent(signedURL: string, opts: ContentFetchOptions): Promise<Content>;
60
+ /**
61
+ * mimeTypeOf reduces a Content-Type to its media type, dropping parameters such as
62
+ * charset. The charset belongs to whoever decodes the bytes; the content carries the
63
+ * media type alone.
64
+ *
65
+ * The parameters are DISCARDED WITHOUT BEING PARSED, and the media type's shape is checked
66
+ * rather than delegated to a parser, because the three SDKs must answer one thing for one
67
+ * header. Go's stdlib parser reports a malformed PARAMETER as an error beside a perfectly
68
+ * good media type — honouring that answers "unknown" for `text/plain; ;`, discarding the one
69
+ * thing the field carries because of the part this is defined to ignore — and it accepts a
70
+ * bare token with no slash, which is not a media type at all. The rule is stated instead:
71
+ * the text before the first `;`, trimmed and lowercased, must be token "/" token over RFC
72
+ * 9110's token characters.
73
+ */
74
+ export declare function mimeTypeOf(header: string | undefined): string;