@reclaimprotocol/attestor-core 5.0.1-beta.1 → 5.0.1-beta.2

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 (261) hide show
  1. package/lib/avs/abis/avsDirectoryABI.d.ts +60 -0
  2. package/lib/avs/abis/avsDirectoryABI.js +343 -0
  3. package/lib/avs/abis/delegationABI.d.ts +126 -0
  4. package/lib/avs/abis/delegationABI.js +4 -0
  5. package/lib/avs/abis/registryABI.d.ts +136 -0
  6. package/lib/avs/abis/registryABI.js +728 -0
  7. package/lib/avs/client/create-claim-on-avs.d.ts +12 -0
  8. package/lib/avs/client/create-claim-on-avs.js +168 -0
  9. package/lib/avs/config.d.ts +7 -0
  10. package/lib/avs/config.js +26 -0
  11. package/lib/avs/contracts/ReclaimServiceManager.d.ts +601 -0
  12. package/lib/avs/contracts/ReclaimServiceManager.js +0 -0
  13. package/lib/avs/contracts/common.d.ts +50 -0
  14. package/lib/avs/contracts/common.js +0 -0
  15. package/lib/avs/contracts/factories/ReclaimServiceManager__factory.d.ts +890 -0
  16. package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +1183 -0
  17. package/lib/avs/contracts/factories/index.d.ts +1 -0
  18. package/lib/avs/contracts/factories/index.js +4 -0
  19. package/lib/avs/contracts/index.d.ts +3 -0
  20. package/lib/avs/contracts/index.js +6 -0
  21. package/lib/avs/types/index.d.ts +55 -0
  22. package/lib/avs/types/index.js +0 -0
  23. package/lib/avs/utils/contracts.d.ts +21 -0
  24. package/lib/avs/utils/contracts.js +53 -0
  25. package/lib/avs/utils/register.d.ts +27 -0
  26. package/lib/avs/utils/register.js +74 -0
  27. package/lib/avs/utils/tasks.d.ts +22 -0
  28. package/lib/avs/utils/tasks.js +48 -0
  29. package/lib/client/create-claim.d.ts +5 -0
  30. package/lib/client/create-claim.js +461 -0
  31. package/lib/client/index.d.ts +3 -0
  32. package/lib/client/index.js +3 -0
  33. package/lib/client/tunnels/make-rpc-tcp-tunnel.d.ts +16 -0
  34. package/lib/client/tunnels/make-rpc-tcp-tunnel.js +53 -0
  35. package/lib/client/tunnels/make-rpc-tls-tunnel.d.ts +26 -0
  36. package/lib/client/tunnels/make-rpc-tls-tunnel.js +127 -0
  37. package/lib/client/utils/attestor-pool.d.ts +8 -0
  38. package/lib/client/utils/attestor-pool.js +24 -0
  39. package/lib/client/utils/client-socket.d.ts +11 -0
  40. package/lib/client/utils/client-socket.js +120 -0
  41. package/lib/client/utils/message-handler.d.ts +4 -0
  42. package/lib/client/utils/message-handler.js +97 -0
  43. package/lib/config/index.d.ts +31 -0
  44. package/lib/config/index.js +62 -0
  45. package/lib/external-rpc/benchmark.d.ts +1 -0
  46. package/lib/external-rpc/benchmark.js +82 -0
  47. package/lib/external-rpc/event-bus.d.ts +7 -0
  48. package/lib/external-rpc/event-bus.js +17 -0
  49. package/lib/external-rpc/global.d.js +0 -0
  50. package/lib/external-rpc/handle-incoming-msg.d.ts +2 -0
  51. package/lib/external-rpc/handle-incoming-msg.js +241 -0
  52. package/lib/external-rpc/index.d.ts +3 -0
  53. package/lib/external-rpc/index.js +3 -0
  54. package/lib/external-rpc/jsc-polyfills/1.d.ts +14 -0
  55. package/lib/external-rpc/jsc-polyfills/1.js +80 -0
  56. package/lib/external-rpc/jsc-polyfills/2.d.ts +1 -0
  57. package/lib/external-rpc/jsc-polyfills/2.js +15 -0
  58. package/lib/external-rpc/jsc-polyfills/event.d.ts +10 -0
  59. package/lib/external-rpc/jsc-polyfills/event.js +19 -0
  60. package/lib/external-rpc/jsc-polyfills/index.d.ts +2 -0
  61. package/lib/external-rpc/jsc-polyfills/index.js +2 -0
  62. package/lib/external-rpc/jsc-polyfills/ws.d.ts +21 -0
  63. package/lib/external-rpc/jsc-polyfills/ws.js +83 -0
  64. package/lib/external-rpc/setup-browser.d.ts +6 -0
  65. package/lib/external-rpc/setup-browser.js +33 -0
  66. package/lib/external-rpc/setup-jsc.d.ts +24 -0
  67. package/lib/external-rpc/setup-jsc.js +22 -0
  68. package/lib/external-rpc/types.d.ts +213 -0
  69. package/lib/external-rpc/types.js +0 -0
  70. package/lib/external-rpc/utils.d.ts +20 -0
  71. package/lib/external-rpc/utils.js +100 -0
  72. package/lib/external-rpc/zk.d.ts +14 -0
  73. package/lib/external-rpc/zk.js +58 -0
  74. package/lib/index.d.ts +9 -0
  75. package/lib/index.js +13 -0
  76. package/lib/mechain/abis/governanceABI.d.ts +50 -0
  77. package/lib/mechain/abis/governanceABI.js +461 -0
  78. package/lib/mechain/abis/taskABI.d.ts +157 -0
  79. package/lib/mechain/abis/taskABI.js +512 -0
  80. package/lib/mechain/client/create-claim-on-mechain.d.ts +10 -0
  81. package/lib/mechain/client/create-claim-on-mechain.js +33 -0
  82. package/lib/mechain/client/index.d.ts +1 -0
  83. package/lib/mechain/client/index.js +1 -0
  84. package/lib/mechain/constants/index.d.ts +3 -0
  85. package/lib/mechain/constants/index.js +8 -0
  86. package/lib/mechain/index.d.ts +2 -0
  87. package/lib/mechain/index.js +2 -0
  88. package/lib/mechain/types/index.d.ts +23 -0
  89. package/lib/mechain/types/index.js +0 -0
  90. package/lib/proto/api.d.ts +651 -0
  91. package/lib/proto/api.js +4250 -0
  92. package/lib/proto/tee-bundle.d.ts +156 -0
  93. package/lib/proto/tee-bundle.js +1296 -0
  94. package/lib/providers/http/index.d.ts +18 -0
  95. package/lib/providers/http/index.js +640 -0
  96. package/lib/providers/http/patch-parse5-tree.d.ts +6 -0
  97. package/lib/providers/http/patch-parse5-tree.js +34 -0
  98. package/lib/providers/http/utils.d.ts +77 -0
  99. package/lib/providers/http/utils.js +283 -0
  100. package/lib/providers/index.d.ts +4 -0
  101. package/lib/providers/index.js +7 -0
  102. package/lib/scripts/build-browser.d.ts +1 -0
  103. package/lib/scripts/build-jsc.d.ts +1 -0
  104. package/lib/scripts/build-lib.d.ts +1 -0
  105. package/lib/scripts/check-avs-registration.d.ts +1 -0
  106. package/lib/scripts/check-avs-registration.js +28 -0
  107. package/lib/scripts/fallbacks/crypto.d.ts +1 -0
  108. package/lib/scripts/fallbacks/crypto.js +4 -0
  109. package/lib/scripts/fallbacks/empty.d.ts +3 -0
  110. package/lib/scripts/fallbacks/empty.js +4 -0
  111. package/lib/scripts/fallbacks/re2.d.ts +1 -0
  112. package/lib/scripts/fallbacks/re2.js +7 -0
  113. package/lib/scripts/fallbacks/snarkjs.d.ts +1 -0
  114. package/lib/scripts/fallbacks/snarkjs.js +10 -0
  115. package/lib/scripts/fallbacks/stwo.d.ts +6 -0
  116. package/lib/scripts/fallbacks/stwo.js +159 -0
  117. package/lib/scripts/generate-provider-types.d.ts +5 -0
  118. package/lib/scripts/generate-provider-types.js +101 -0
  119. package/lib/scripts/generate-receipt.d.ts +9 -0
  120. package/lib/scripts/generate-receipt.js +101 -0
  121. package/lib/scripts/generate-toprf-keys.d.ts +1 -0
  122. package/lib/scripts/generate-toprf-keys.js +24 -0
  123. package/lib/scripts/jsc-cli-rpc.d.ts +1 -0
  124. package/lib/scripts/jsc-cli-rpc.js +35 -0
  125. package/lib/scripts/register-avs-operator.d.ts +1 -0
  126. package/lib/scripts/register-avs-operator.js +3 -0
  127. package/lib/scripts/start-server.d.ts +1 -0
  128. package/lib/scripts/start-server.js +11 -0
  129. package/lib/scripts/update-avs-metadata.d.ts +1 -0
  130. package/lib/scripts/update-avs-metadata.js +20 -0
  131. package/lib/scripts/utils.d.ts +1 -0
  132. package/lib/scripts/utils.js +10 -0
  133. package/lib/scripts/whitelist-operator.d.ts +1 -0
  134. package/lib/scripts/whitelist-operator.js +16 -0
  135. package/lib/server/create-server.d.ts +8 -0
  136. package/lib/server/create-server.js +105 -0
  137. package/lib/server/handlers/claimTeeBundle.d.ts +6 -0
  138. package/lib/server/handlers/claimTeeBundle.js +232 -0
  139. package/lib/server/handlers/claimTunnel.d.ts +2 -0
  140. package/lib/server/handlers/claimTunnel.js +80 -0
  141. package/lib/server/handlers/completeClaimOnChain.d.ts +2 -0
  142. package/lib/server/handlers/completeClaimOnChain.js +29 -0
  143. package/lib/server/handlers/createClaimOnChain.d.ts +2 -0
  144. package/lib/server/handlers/createClaimOnChain.js +32 -0
  145. package/lib/server/handlers/createTaskOnMechain.d.ts +2 -0
  146. package/lib/server/handlers/createTaskOnMechain.js +57 -0
  147. package/lib/server/handlers/createTunnel.d.ts +2 -0
  148. package/lib/server/handlers/createTunnel.js +98 -0
  149. package/lib/server/handlers/disconnectTunnel.d.ts +2 -0
  150. package/lib/server/handlers/disconnectTunnel.js +8 -0
  151. package/lib/server/handlers/fetchCertificateBytes.d.ts +2 -0
  152. package/lib/server/handlers/fetchCertificateBytes.js +57 -0
  153. package/lib/server/handlers/index.d.ts +4 -0
  154. package/lib/server/handlers/index.js +25 -0
  155. package/lib/server/handlers/init.d.ts +2 -0
  156. package/lib/server/handlers/init.js +33 -0
  157. package/lib/server/handlers/toprf.d.ts +2 -0
  158. package/lib/server/handlers/toprf.js +19 -0
  159. package/lib/server/index.d.ts +4 -0
  160. package/lib/server/index.js +4 -0
  161. package/lib/server/socket.d.ts +13 -0
  162. package/lib/server/socket.js +112 -0
  163. package/lib/server/tunnels/make-tcp-tunnel.d.ts +22 -0
  164. package/lib/server/tunnels/make-tcp-tunnel.js +202 -0
  165. package/lib/server/utils/apm.d.ts +11 -0
  166. package/lib/server/utils/apm.js +29 -0
  167. package/lib/server/utils/assert-valid-claim-request.d.ts +31 -0
  168. package/lib/server/utils/assert-valid-claim-request.js +354 -0
  169. package/lib/server/utils/config-env.d.ts +1 -0
  170. package/lib/server/utils/config-env.js +4 -0
  171. package/lib/server/utils/dns.d.ts +1 -0
  172. package/lib/server/utils/dns.js +24 -0
  173. package/lib/server/utils/gcp-attestation.d.ts +17 -0
  174. package/lib/server/utils/gcp-attestation.js +237 -0
  175. package/lib/server/utils/generics.d.ts +22 -0
  176. package/lib/server/utils/generics.js +45 -0
  177. package/lib/server/utils/iso.d.ts +1 -0
  178. package/lib/server/utils/iso.js +259 -0
  179. package/lib/server/utils/keep-alive.d.ts +7 -0
  180. package/lib/server/utils/keep-alive.js +38 -0
  181. package/lib/server/utils/nitro-attestation.d.ts +33 -0
  182. package/lib/server/utils/nitro-attestation.js +249 -0
  183. package/lib/server/utils/oprf-raw.d.ts +21 -0
  184. package/lib/server/utils/oprf-raw.js +61 -0
  185. package/lib/server/utils/process-handshake.d.ts +13 -0
  186. package/lib/server/utils/process-handshake.js +233 -0
  187. package/lib/server/utils/proxy-session.d.ts +1 -0
  188. package/lib/server/utils/proxy-session.js +6 -0
  189. package/lib/server/utils/tee-oprf-mpc-verification.d.ts +16 -0
  190. package/lib/server/utils/tee-oprf-mpc-verification.js +86 -0
  191. package/lib/server/utils/tee-oprf-verification.d.ts +24 -0
  192. package/lib/server/utils/tee-oprf-verification.js +151 -0
  193. package/lib/server/utils/tee-transcript-reconstruction.d.ts +24 -0
  194. package/lib/server/utils/tee-transcript-reconstruction.js +140 -0
  195. package/lib/server/utils/tee-verification.d.ts +28 -0
  196. package/lib/server/utils/tee-verification.js +358 -0
  197. package/lib/server/utils/validation.d.ts +2 -0
  198. package/lib/server/utils/validation.js +45 -0
  199. package/lib/types/bgp.d.ts +11 -0
  200. package/lib/types/bgp.js +0 -0
  201. package/lib/types/claims.d.ts +70 -0
  202. package/lib/types/claims.js +0 -0
  203. package/lib/types/client.d.ts +163 -0
  204. package/lib/types/client.js +0 -0
  205. package/lib/types/general.d.ts +76 -0
  206. package/lib/types/general.js +0 -0
  207. package/lib/types/handlers.d.ts +10 -0
  208. package/lib/types/handlers.js +0 -0
  209. package/lib/types/index.d.ts +10 -0
  210. package/lib/types/index.js +10 -0
  211. package/lib/types/providers.d.ts +161 -0
  212. package/lib/types/providers.gen.d.ts +443 -0
  213. package/lib/types/providers.gen.js +16 -0
  214. package/lib/types/providers.js +0 -0
  215. package/lib/types/rpc.d.ts +35 -0
  216. package/lib/types/rpc.js +0 -0
  217. package/lib/types/signatures.d.ts +28 -0
  218. package/lib/types/signatures.js +0 -0
  219. package/lib/types/tunnel.d.ts +18 -0
  220. package/lib/types/tunnel.js +0 -0
  221. package/lib/types/zk.d.ts +38 -0
  222. package/lib/types/zk.js +0 -0
  223. package/lib/utils/auth.d.ts +8 -0
  224. package/lib/utils/auth.js +71 -0
  225. package/lib/utils/b64-json.d.ts +2 -0
  226. package/lib/utils/b64-json.js +17 -0
  227. package/lib/utils/bgp-listener.d.ts +7 -0
  228. package/lib/utils/bgp-listener.js +123 -0
  229. package/lib/utils/claims.d.ts +33 -0
  230. package/lib/utils/claims.js +89 -0
  231. package/lib/utils/env.d.ts +3 -0
  232. package/lib/utils/env.js +19 -0
  233. package/lib/utils/error.d.ts +26 -0
  234. package/lib/utils/error.js +54 -0
  235. package/lib/utils/generics.d.ts +114 -0
  236. package/lib/utils/generics.js +268 -0
  237. package/lib/utils/http-parser.d.ts +59 -0
  238. package/lib/utils/http-parser.js +201 -0
  239. package/lib/utils/index.d.ts +13 -0
  240. package/lib/utils/index.js +13 -0
  241. package/lib/utils/logger.d.ts +13 -0
  242. package/lib/utils/logger.js +82 -0
  243. package/lib/utils/prepare-packets.d.ts +16 -0
  244. package/lib/utils/prepare-packets.js +69 -0
  245. package/lib/utils/redactions.d.ts +73 -0
  246. package/lib/utils/redactions.js +135 -0
  247. package/lib/utils/retries.d.ts +12 -0
  248. package/lib/utils/retries.js +26 -0
  249. package/lib/utils/signatures/eth.d.ts +2 -0
  250. package/lib/utils/signatures/eth.js +31 -0
  251. package/lib/utils/signatures/index.d.ts +5 -0
  252. package/lib/utils/signatures/index.js +12 -0
  253. package/lib/utils/socket-base.d.ts +23 -0
  254. package/lib/utils/socket-base.js +96 -0
  255. package/lib/utils/tls.d.ts +2 -0
  256. package/lib/utils/tls.js +58 -0
  257. package/lib/utils/ws.d.ts +7 -0
  258. package/lib/utils/ws.js +22 -0
  259. package/lib/utils/zk.d.ts +71 -0
  260. package/lib/utils/zk.js +625 -0
  261. package/package.json +2 -2
@@ -0,0 +1,17 @@
1
+ import { decodeBase64, encodeBase64 } from "ethers";
2
+ const B64_JSON_REPLACER = (key, value) => {
3
+ if (value instanceof Uint8Array || typeof value === "object" && value && "buffer" in value && value.buffer instanceof ArrayBuffer) {
4
+ return { type: "uint8array", value: encodeBase64(value) };
5
+ }
6
+ return value;
7
+ };
8
+ const B64_JSON_REVIVER = (key, value) => {
9
+ if (value?.type === "uint8array") {
10
+ return decodeBase64(value.value);
11
+ }
12
+ return value;
13
+ };
14
+ export {
15
+ B64_JSON_REPLACER,
16
+ B64_JSON_REVIVER
17
+ };
@@ -0,0 +1,7 @@
1
+ import type { Logger } from 'pino';
2
+ import type { BGPListener } from '#src/types/index.ts';
3
+ /**
4
+ * Listens for BGP announcements and emits events whenever
5
+ * an announcement overlaps with a target IP.
6
+ */
7
+ export declare function createBgpListener(logger: Logger): BGPListener;
@@ -0,0 +1,123 @@
1
+ import CIDR from "ip-cidr";
2
+ import { BGP_WS_URL } from "../config/index.js";
3
+ import { makeWebSocket } from "../utils/ws.js";
4
+ const ANNOUNCEMENT_OVERLAP = "announcement-overlap";
5
+ class BGPAnnouncementOverlapEvent extends Event {
6
+ data;
7
+ constructor(data) {
8
+ super(ANNOUNCEMENT_OVERLAP);
9
+ this.data = data;
10
+ }
11
+ }
12
+ function createBgpListener(logger) {
13
+ let ws;
14
+ let closed = false;
15
+ const targetIps = /* @__PURE__ */ new Set();
16
+ const eventTarget = new EventTarget();
17
+ openWs();
18
+ return {
19
+ onOverlap(ips, callback) {
20
+ for (const ip of ips) {
21
+ targetIps.add(ip);
22
+ }
23
+ eventTarget.addEventListener(
24
+ ANNOUNCEMENT_OVERLAP,
25
+ _callback
26
+ );
27
+ return () => {
28
+ for (const ip of ips) {
29
+ targetIps.delete(ip);
30
+ }
31
+ eventTarget.removeEventListener(
32
+ ANNOUNCEMENT_OVERLAP,
33
+ _callback
34
+ );
35
+ };
36
+ function _callback(event) {
37
+ callback(event.data);
38
+ }
39
+ },
40
+ close() {
41
+ ws.onclose = null;
42
+ ws.onerror = null;
43
+ ws.close();
44
+ closed = true;
45
+ }
46
+ };
47
+ function openWs() {
48
+ logger.debug("connecting to BGP websocket");
49
+ ws = makeWebSocket(BGP_WS_URL);
50
+ ws.onopen = onOpen;
51
+ ws.onerror = (ev) => onClose(ev);
52
+ ws.onclose = () => onClose(new Error("Unexpected close"));
53
+ ws.onmessage = ({ data }) => {
54
+ const str = typeof data === "string" ? data : data.toString();
55
+ try {
56
+ onMessage(str);
57
+ } catch (err) {
58
+ logger.error({ data, err }, "error processing BGP message");
59
+ }
60
+ };
61
+ }
62
+ function onOpen() {
63
+ const subscriptionMessage = {
64
+ type: "ris_subscribe",
65
+ data: {
66
+ type: "UPDATE"
67
+ }
68
+ };
69
+ ws.send(JSON.stringify(subscriptionMessage));
70
+ logger.info("connected to BGP websocket");
71
+ }
72
+ function onClose(err) {
73
+ if (closed) {
74
+ return;
75
+ }
76
+ logger.info({ err }, "BGP websocket closed");
77
+ if (!err) {
78
+ return;
79
+ }
80
+ logger.info("reconnecting to BGP websocket");
81
+ openWs();
82
+ }
83
+ function onMessage(message) {
84
+ const data = JSON.parse(message);
85
+ const announcements = data?.data?.announcements;
86
+ logger.trace({ data }, "got BGP update");
87
+ if (!Array.isArray(announcements)) {
88
+ return;
89
+ }
90
+ const asPath = data?.data?.path;
91
+ for (const announcement of announcements) {
92
+ const prefixes = announcement?.prefixes;
93
+ const nextHop = announcement?.["next_hop"];
94
+ const hasPrefixes = prefixes?.length && (nextHop || asPath);
95
+ if (!hasPrefixes) {
96
+ return;
97
+ }
98
+ for (const prefix of prefixes) {
99
+ if (!overlapsTargetIps(prefix)) {
100
+ continue;
101
+ }
102
+ eventTarget.dispatchEvent(
103
+ new BGPAnnouncementOverlapEvent({ prefix })
104
+ );
105
+ }
106
+ }
107
+ }
108
+ function overlapsTargetIps(prefix) {
109
+ if (prefix.endsWith("/0")) {
110
+ return false;
111
+ }
112
+ const cidr = new CIDR(prefix);
113
+ for (const ip of targetIps) {
114
+ if (cidr.contains(ip)) {
115
+ return true;
116
+ }
117
+ }
118
+ return false;
119
+ }
120
+ }
121
+ export {
122
+ createBgpListener
123
+ };
@@ -0,0 +1,33 @@
1
+ import { ClaimTunnelResponse } from '#src/proto/api.ts';
2
+ import type { ClaimID, ClaimInfo, CompleteClaimData, ProviderParams } from '#src/types/index.ts';
3
+ /**
4
+ * Creates the standard string to sign for a claim.
5
+ * This data is what the attestor will sign when it successfully
6
+ * verifies a claim.
7
+ */
8
+ export declare function createSignDataForClaim(data: CompleteClaimData): string;
9
+ /**
10
+ * Verify the claim tunnel response from a attestor.
11
+ *
12
+ * If you'd only like to verify the claim signature, you can
13
+ * optionally only pass "claim" & "signatures.claimSignature"
14
+ * to this function.
15
+ *
16
+ * The successful run of this function means that the claim
17
+ * is valid, and the attestor that signed the claim is valid.
18
+ */
19
+ export declare function assertValidClaimSignatures({ signatures, ...res }: Partial<ClaimTunnelResponse>, metadata?: import("#src/proto/api.ts").InitRequest): Promise<void>;
20
+ /**
21
+ * Generates a unique identifier for given claim info
22
+ * @param info
23
+ * @returns
24
+ */
25
+ export declare function getIdentifierFromClaimInfo(info: ClaimInfo): ClaimID;
26
+ /**
27
+ * Canonically stringifies an object, so that the same object will always
28
+ * produce the same string despite the order of keys
29
+ */
30
+ export declare function canonicalStringify(params: {
31
+ [key: string]: any;
32
+ } | undefined): string;
33
+ export declare function hashProviderParams(params: ProviderParams<'http'>): string;
@@ -0,0 +1,89 @@
1
+ import canonicalize from "canonicalize";
2
+ import { keccak256 } from "ethers";
3
+ import { DEFAULT_METADATA } from "../config/index.js";
4
+ import { ClaimTunnelResponse } from "../proto/api.js";
5
+ import { SIGNATURES, strToUint8Array } from "../utils/index.js";
6
+ function createSignDataForClaim(data) {
7
+ const lines = [
8
+ getIdentifierFromClaimInfo(data),
9
+ // we lowercase the owner to ensure that the
10
+ // ETH addresses always serialize the same way
11
+ data.owner.toLowerCase(),
12
+ data.timestampS.toString(),
13
+ data.epoch.toString()
14
+ ];
15
+ return lines.join("\n");
16
+ }
17
+ async function assertValidClaimSignatures({
18
+ signatures,
19
+ ...res
20
+ }, metadata = DEFAULT_METADATA) {
21
+ if (!signatures) {
22
+ throw new Error("No signatures provided");
23
+ }
24
+ const {
25
+ resultSignature,
26
+ claimSignature,
27
+ attestorAddress
28
+ } = signatures;
29
+ const { verify } = SIGNATURES[metadata.signatureType];
30
+ if (signatures?.resultSignature) {
31
+ const resBytes = ClaimTunnelResponse.encode(ClaimTunnelResponse.create(res)).finish();
32
+ const verified = await verify(resBytes, resultSignature, attestorAddress);
33
+ if (!verified) {
34
+ throw new Error("Invalid result signature");
35
+ }
36
+ }
37
+ if (!res.claim) {
38
+ return;
39
+ }
40
+ const signData = createSignDataForClaim(res.claim);
41
+ const verifiedClaim = await verify(
42
+ strToUint8Array(signData),
43
+ claimSignature,
44
+ attestorAddress
45
+ );
46
+ if (!verifiedClaim) {
47
+ throw new Error("Invalid claim signature");
48
+ }
49
+ }
50
+ function getIdentifierFromClaimInfo(info) {
51
+ if (info.context?.length > 0) {
52
+ try {
53
+ const ctx = JSON.parse(info.context);
54
+ info.context = canonicalStringify(ctx);
55
+ } catch {
56
+ throw new Error("unable to parse non-empty context. Must be JSON");
57
+ }
58
+ }
59
+ const str = `${info.provider}
60
+ ${info.parameters}
61
+ ${info.context || ""}`;
62
+ return keccak256(strToUint8Array(str)).toLowerCase();
63
+ }
64
+ function canonicalStringify(params) {
65
+ if (!params) {
66
+ return "";
67
+ }
68
+ return canonicalize(params) || "";
69
+ }
70
+ function hashProviderParams(params) {
71
+ const filteredParams = {
72
+ url: params.url,
73
+ method: params.method,
74
+ body: params.body,
75
+ responseMatches: params.responseMatches,
76
+ responseRedactions: params.responseRedactions
77
+ };
78
+ const serializedParams = canonicalStringify(filteredParams);
79
+ return keccak256(
80
+ strToUint8Array(serializedParams)
81
+ ).toLowerCase();
82
+ }
83
+ export {
84
+ assertValidClaimSignatures,
85
+ canonicalStringify,
86
+ createSignDataForClaim,
87
+ getIdentifierFromClaimInfo,
88
+ hashProviderParams
89
+ };
@@ -0,0 +1,3 @@
1
+ export type TransportType = 'node' | 'react-native' | 'browser';
2
+ export declare function detectEnvironment(): TransportType;
3
+ export declare function getEnvVariable(name: string): string | undefined;
@@ -0,0 +1,19 @@
1
+ function detectEnvironment() {
2
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
3
+ return "react-native";
4
+ }
5
+ if (typeof window !== "undefined") {
6
+ return "browser";
7
+ }
8
+ return "node";
9
+ }
10
+ function getEnvVariable(name) {
11
+ if (typeof process === "undefined") {
12
+ return void 0;
13
+ }
14
+ return process?.env[name];
15
+ }
16
+ export {
17
+ detectEnvironment,
18
+ getEnvVariable
19
+ };
@@ -0,0 +1,26 @@
1
+ import { ErrorCode, ErrorData } from '#src/proto/api.ts';
2
+ /**
3
+ * Represents an error that can be thrown by the Attestor Core
4
+ * or server. Provides a code, and optional data
5
+ * to pass along with the error.
6
+ */
7
+ export declare class AttestorError extends Error {
8
+ readonly name = "AttestorError";
9
+ readonly code: keyof typeof ErrorCode;
10
+ readonly data: {
11
+ [_: string]: any;
12
+ } | undefined;
13
+ constructor(code: keyof typeof ErrorCode, message: string, data?: {
14
+ [_: string]: any;
15
+ });
16
+ /**
17
+ * Encodes the error as a ErrorData
18
+ * protobuf message
19
+ */
20
+ toProto(): ErrorData;
21
+ static fromProto(data?: ErrorData): AttestorError;
22
+ static fromError(err: Error, code?: keyof typeof ErrorCode): AttestorError;
23
+ static badRequest(message: string, data?: {
24
+ [_: string]: any;
25
+ }): AttestorError;
26
+ }
@@ -0,0 +1,54 @@
1
+ import { ErrorCode, ErrorData } from "../proto/api.js";
2
+ const PROTO_ERROR = ErrorData.fromJSON({});
3
+ class AttestorError extends Error {
4
+ name = "AttestorError";
5
+ code;
6
+ data;
7
+ constructor(code, message, data) {
8
+ super(message);
9
+ this.code = code;
10
+ this.data = data;
11
+ }
12
+ /**
13
+ * Encodes the error as a ErrorData
14
+ * protobuf message
15
+ */
16
+ toProto() {
17
+ return ErrorData.create({
18
+ code: ErrorCode[this.code],
19
+ message: this.message,
20
+ data: JSON.stringify(this.data)
21
+ });
22
+ }
23
+ static fromProto(data = PROTO_ERROR) {
24
+ return new AttestorError(
25
+ typeof data.code === "number" ? getKeyForValue(ErrorCode, data.code) || "UNRECOGNIZED" : data.code,
26
+ data.message,
27
+ data.data ? JSON.parse(data.data) : void 0
28
+ );
29
+ }
30
+ static fromError(err, code = "ERROR_INTERNAL") {
31
+ if (err instanceof AttestorError) {
32
+ return err;
33
+ }
34
+ return new AttestorError(code, err.message);
35
+ }
36
+ static badRequest(message, data) {
37
+ return new AttestorError(
38
+ "ERROR_BAD_REQUEST",
39
+ message,
40
+ data
41
+ );
42
+ }
43
+ }
44
+ function getKeyForValue(obj, value) {
45
+ for (const key in obj) {
46
+ if (obj[key] === value) {
47
+ return key;
48
+ }
49
+ }
50
+ return void 0;
51
+ }
52
+ export {
53
+ AttestorError
54
+ };
@@ -0,0 +1,114 @@
1
+ import type { CipherSuite, TLSProtocolVersion } from '@reclaimprotocol/tls';
2
+ import { uint8ArrayToBinaryStr } from '@reclaimprotocol/tls';
3
+ import { RPCMessage, RPCMessages } from '#src/proto/api.ts';
4
+ import type { CompleteTLSPacket, IDecryptedTranscript, IDecryptedTranscriptMessage, ProviderField, RPCEvent, RPCEventMap, RPCEventType, RPCType, Transcript } from '#src/types/index.ts';
5
+ export { uint8ArrayToBinaryStr };
6
+ /**
7
+ * Decodes a Uint8Array to a UTF-8 string.
8
+ */
9
+ export declare function uint8ArrayToStr(arr: Uint8Array): string;
10
+ /**
11
+ * Encodes a UTF-8 string to a Uint8Array.
12
+ */
13
+ export declare function strToUint8Array(str: string): Uint8Array;
14
+ export declare function getTranscriptString(receipt: IDecryptedTranscript): string;
15
+ export declare const unixTimestampSeconds: () => number;
16
+ /**
17
+ * Find index of needle in haystack
18
+ */
19
+ export declare function findIndexInUint8Array(haystack: Uint8Array, needle: Uint8Array): number;
20
+ /**
21
+ * Fetch the ZK algorithm for the specified cipher suite
22
+ */
23
+ export declare function getZkAlgorithmForCipherSuite(cipherSuite: CipherSuite): "aes-256-ctr" | "aes-128-ctr" | "chacha20";
24
+ /**
25
+ * Get the pure ciphertext without any MAC,
26
+ * or authentication tag,
27
+ * @param content content w/o header
28
+ * @param cipherSuite
29
+ */
30
+ export declare function getPureCiphertext(content: Uint8Array, cipherSuite: CipherSuite): Uint8Array<ArrayBufferLike>;
31
+ /**
32
+ * Get the 8 byte IV part that's stored in the record for some cipher suites
33
+ * @param content content w/o header
34
+ * @param cipherSuite
35
+ */
36
+ export declare function getRecordIV(content: Uint8Array, cipherSuite: CipherSuite): Uint8Array<ArrayBuffer>;
37
+ export declare function getProviderValue<P, S, T>(params: P, fn: ProviderField<P, S, T>, secretParams?: S): T;
38
+ export declare function generateRpcMessageId(): number;
39
+ /**
40
+ * Random session ID for a WebSocket client.
41
+ */
42
+ export declare function generateSessionId(): number;
43
+ /**
44
+ * Random ID for a tunnel.
45
+ */
46
+ export declare function generateTunnelId(): number;
47
+ export declare function makeRpcEvent<T extends RPCEventType>(type: T, data: RPCEventMap[T]): RPCEvent<T>;
48
+ /**
49
+ * Get the RPC type from the key.
50
+ * For eg. "claimTunnelRequest" ->
51
+ * { type: 'claimTunnel', direction: 'request' }
52
+ */
53
+ export declare function getRpcTypeFromKey(key: string): {
54
+ type: RPCType;
55
+ direction: "request";
56
+ } | {
57
+ type: RPCType;
58
+ direction: "response";
59
+ } | undefined;
60
+ /**
61
+ * Get the RPC response type from the RPC type.
62
+ * For eg. "claimTunnel" -> "claimTunnelResponse"
63
+ */
64
+ export declare function getRpcResponseType<T extends RPCType>(type: T): `${T}Response`;
65
+ /**
66
+ * Get the RPC request type from the RPC type.
67
+ * For eg. "claimTunnel" -> "claimTunnelRequest"
68
+ */
69
+ export declare function getRpcRequestType<T extends RPCType>(type: T): `${T}Request`;
70
+ export declare function isApplicationData(packet: CompleteTLSPacket, tlsVersion: string | undefined): boolean;
71
+ /**
72
+ * Convert the received data from a WS to a Uint8Array
73
+ */
74
+ export declare function extractArrayBufferFromWsData(data: unknown): Promise<Uint8Array>;
75
+ /**
76
+ * Check if the RPC message is a request or a response.
77
+ */
78
+ export declare function getRpcRequest(msg: RPCMessage): {
79
+ type: RPCType;
80
+ direction: "request";
81
+ } | {
82
+ type: RPCType;
83
+ direction: "response";
84
+ } | {
85
+ direction: "response";
86
+ type: "error";
87
+ } | undefined;
88
+ /**
89
+ * Finds all application data messages in a transcript
90
+ * and returns them. Removes the "contentType" suffix from the message.
91
+ * in TLS 1.3
92
+ */
93
+ export declare function extractApplicationDataFromTranscript({ transcript, tlsVersion }: IDecryptedTranscript): Transcript<Uint8Array<ArrayBufferLike>>;
94
+ export type HandshakeTranscript<T> = {
95
+ sender: 'client' | 'server';
96
+ index: number;
97
+ message: T;
98
+ }[];
99
+ export declare function extractHandshakeFromTranscript({ transcript, tlsVersion }: {
100
+ transcript: IDecryptedTranscriptMessage[];
101
+ tlsVersion: TLSProtocolVersion;
102
+ }): HandshakeTranscript<Uint8Array<ArrayBufferLike>>;
103
+ export declare function decryptDirect(directReveal: any, cipherSuite: CipherSuite, recordHeader: Uint8Array, serverTlsVersion: TLSProtocolVersion, content: Uint8Array): Promise<{
104
+ plaintext: Uint8Array<ArrayBufferLike>;
105
+ iv: Uint8Array<ArrayBufferLike>;
106
+ }>;
107
+ export declare function packRpcMessages(...msgs: Partial<RPCMessage>[]): RPCMessages;
108
+ /**
109
+ * Converts an Ethers struct (an array w named keys) to
110
+ * a plain object. Recursively converts all structs inside.
111
+ * Required to correctly JSON.stringify the struct.
112
+ */
113
+ export declare function ethersStructToPlainObject<T>(struct: T): T;
114
+ export declare function isTls13Suite(suite: CipherSuite): suite is "TLS_CHACHA20_POLY1305_SHA256" | "TLS_AES_256_GCM_SHA384" | "TLS_AES_128_GCM_SHA256";