@reclaimprotocol/attestor-core 3.0.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 (204) hide show
  1. package/README.md +39 -0
  2. package/lib/avs/abis/avsDirectoryABI.d.ts +60 -0
  3. package/lib/avs/abis/avsDirectoryABI.js +344 -0
  4. package/lib/avs/abis/delegationABI.d.ts +126 -0
  5. package/lib/avs/abis/delegationABI.js +5 -0
  6. package/lib/avs/abis/registryABI.d.ts +136 -0
  7. package/lib/avs/abis/registryABI.js +729 -0
  8. package/lib/avs/client/create-claim-on-avs.d.ts +10 -0
  9. package/lib/avs/client/create-claim-on-avs.js +147 -0
  10. package/lib/avs/config.d.ts +7 -0
  11. package/lib/avs/config.js +24 -0
  12. package/lib/avs/contracts/ReclaimServiceManager.d.ts +697 -0
  13. package/lib/avs/contracts/ReclaimServiceManager.js +3 -0
  14. package/lib/avs/contracts/common.d.ts +21 -0
  15. package/lib/avs/contracts/common.js +3 -0
  16. package/lib/avs/contracts/factories/ReclaimServiceManager__factory.d.ts +888 -0
  17. package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +1174 -0
  18. package/lib/avs/contracts/factories/index.d.ts +1 -0
  19. package/lib/avs/contracts/factories/index.js +9 -0
  20. package/lib/avs/contracts/index.d.ts +3 -0
  21. package/lib/avs/contracts/index.js +30 -0
  22. package/lib/avs/tests/test.operator.d.ts +11 -0
  23. package/lib/avs/tests/test.operator.js +313 -0
  24. package/lib/avs/tests/utils.d.ts +2 -0
  25. package/lib/avs/tests/utils.js +50 -0
  26. package/lib/avs/types/index.d.ts +55 -0
  27. package/lib/avs/types/index.js +3 -0
  28. package/lib/avs/utils/contracts.d.ts +21 -0
  29. package/lib/avs/utils/contracts.js +38 -0
  30. package/lib/avs/utils/register.d.ts +27 -0
  31. package/lib/avs/utils/register.js +76 -0
  32. package/lib/avs/utils/tasks.d.ts +22 -0
  33. package/lib/avs/utils/tasks.js +45 -0
  34. package/lib/client/create-claim.d.ts +5 -0
  35. package/lib/client/create-claim.js +357 -0
  36. package/lib/client/index.d.ts +3 -0
  37. package/lib/client/index.js +20 -0
  38. package/lib/client/tunnels/make-rpc-tcp-tunnel.d.ts +16 -0
  39. package/lib/client/tunnels/make-rpc-tcp-tunnel.js +60 -0
  40. package/lib/client/tunnels/make-rpc-tls-tunnel.d.ts +25 -0
  41. package/lib/client/tunnels/make-rpc-tls-tunnel.js +135 -0
  42. package/lib/client/utils/attestor-pool.d.ts +6 -0
  43. package/lib/client/utils/attestor-pool.js +28 -0
  44. package/lib/client/utils/client-socket.d.ts +9 -0
  45. package/lib/client/utils/client-socket.js +77 -0
  46. package/lib/client/utils/message-handler.d.ts +4 -0
  47. package/lib/client/utils/message-handler.js +93 -0
  48. package/lib/config/index.d.ts +23 -0
  49. package/lib/config/index.js +35 -0
  50. package/lib/index.d.ts +9 -0
  51. package/lib/index.js +39 -0
  52. package/lib/proto/api.d.ts +414 -0
  53. package/lib/proto/api.js +2756 -0
  54. package/lib/providers/http/index.d.ts +3 -0
  55. package/lib/providers/http/index.js +472 -0
  56. package/lib/providers/http/utils.d.ts +44 -0
  57. package/lib/providers/http/utils.js +302 -0
  58. package/lib/providers/index.d.ts +4 -0
  59. package/lib/providers/index.js +11 -0
  60. package/lib/scripts/check-avs-registration.d.ts +1 -0
  61. package/lib/scripts/check-avs-registration.js +28 -0
  62. package/lib/scripts/generate-provider-types.d.ts +5 -0
  63. package/lib/scripts/generate-provider-types.js +82 -0
  64. package/lib/scripts/generate-receipt.d.ts +9 -0
  65. package/lib/scripts/generate-receipt.js +93 -0
  66. package/lib/scripts/register-avs-operator.d.ts +1 -0
  67. package/lib/scripts/register-avs-operator.js +6 -0
  68. package/lib/scripts/start-server.d.ts +1 -0
  69. package/lib/scripts/start-server.js +6 -0
  70. package/lib/scripts/verify-root-ca.d.ts +1 -0
  71. package/lib/scripts/verify-root-ca.js +51 -0
  72. package/lib/server/create-server.d.ts +7 -0
  73. package/lib/server/create-server.js +85 -0
  74. package/lib/server/handlers/claimTunnel.d.ts +2 -0
  75. package/lib/server/handlers/claimTunnel.js +55 -0
  76. package/lib/server/handlers/completeClaimOnChain.d.ts +2 -0
  77. package/lib/server/handlers/completeClaimOnChain.js +28 -0
  78. package/lib/server/handlers/createClaimOnChain.d.ts +2 -0
  79. package/lib/server/handlers/createClaimOnChain.js +31 -0
  80. package/lib/server/handlers/createTunnel.d.ts +2 -0
  81. package/lib/server/handlers/createTunnel.js +65 -0
  82. package/lib/server/handlers/disconnectTunnel.d.ts +2 -0
  83. package/lib/server/handlers/disconnectTunnel.js +10 -0
  84. package/lib/server/handlers/index.d.ts +4 -0
  85. package/lib/server/handlers/index.js +18 -0
  86. package/lib/server/handlers/init.d.ts +2 -0
  87. package/lib/server/handlers/init.js +21 -0
  88. package/lib/server/index.d.ts +4 -0
  89. package/lib/server/index.js +21 -0
  90. package/lib/server/socket.d.ts +11 -0
  91. package/lib/server/socket.js +95 -0
  92. package/lib/server/tunnels/make-tcp-tunnel.d.ts +20 -0
  93. package/lib/server/tunnels/make-tcp-tunnel.js +182 -0
  94. package/lib/server/utils/apm.d.ts +11 -0
  95. package/lib/server/utils/apm.js +39 -0
  96. package/lib/server/utils/assert-valid-claim-request.d.ts +29 -0
  97. package/lib/server/utils/assert-valid-claim-request.js +189 -0
  98. package/lib/server/utils/config-env.d.ts +1 -0
  99. package/lib/server/utils/config-env.js +7 -0
  100. package/lib/server/utils/generics.d.ts +22 -0
  101. package/lib/server/utils/generics.js +59 -0
  102. package/lib/server/utils/iso.d.ts +1 -0
  103. package/lib/server/utils/iso.js +260 -0
  104. package/lib/server/utils/keep-alive.d.ts +7 -0
  105. package/lib/server/utils/keep-alive.js +42 -0
  106. package/lib/server/utils/process-handshake.d.ts +13 -0
  107. package/lib/server/utils/process-handshake.js +179 -0
  108. package/lib/server/utils/verify-server-certificates.d.ts +7 -0
  109. package/lib/server/utils/verify-server-certificates.js +102 -0
  110. package/lib/tests/describe-with-server.d.ts +21 -0
  111. package/lib/tests/describe-with-server.js +67 -0
  112. package/lib/tests/mock-provider-server.d.ts +13 -0
  113. package/lib/tests/mock-provider-server.js +65 -0
  114. package/lib/tests/mocks.d.ts +4 -0
  115. package/lib/tests/mocks.js +23 -0
  116. package/lib/tests/test.claim-creation.d.ts +1 -0
  117. package/lib/tests/test.claim-creation.js +187 -0
  118. package/lib/tests/test.http-parser.d.ts +1 -0
  119. package/lib/tests/test.http-parser.js +118 -0
  120. package/lib/tests/test.http-provider-utils.d.ts +1 -0
  121. package/lib/tests/test.http-provider-utils.js +1932 -0
  122. package/lib/tests/test.http-provider.d.ts +1 -0
  123. package/lib/tests/test.http-provider.js +43 -0
  124. package/lib/tests/test.rpc-communication.d.ts +1 -0
  125. package/lib/tests/test.rpc-communication.js +64 -0
  126. package/lib/tests/test.rpc-tunnel.d.ts +1 -0
  127. package/lib/tests/test.rpc-tunnel.js +168 -0
  128. package/lib/tests/test.signatures.d.ts +1 -0
  129. package/lib/tests/test.signatures.js +24 -0
  130. package/lib/tests/test.tcp-tunnel.d.ts +1 -0
  131. package/lib/tests/test.tcp-tunnel.js +64 -0
  132. package/lib/tests/test.zk.d.ts +1 -0
  133. package/lib/tests/test.zk.js +169 -0
  134. package/lib/tests/utils.d.ts +12 -0
  135. package/lib/tests/utils.js +49 -0
  136. package/lib/types/claims.d.ts +64 -0
  137. package/lib/types/claims.js +3 -0
  138. package/lib/types/client.d.ts +136 -0
  139. package/lib/types/client.js +3 -0
  140. package/lib/types/general.d.ts +39 -0
  141. package/lib/types/general.js +3 -0
  142. package/lib/types/handlers.d.ts +10 -0
  143. package/lib/types/handlers.js +3 -0
  144. package/lib/types/index.d.ts +9 -0
  145. package/lib/types/index.js +26 -0
  146. package/lib/types/providers.d.ts +135 -0
  147. package/lib/types/providers.gen.d.ts +414 -0
  148. package/lib/types/providers.gen.js +14 -0
  149. package/lib/types/providers.js +3 -0
  150. package/lib/types/rpc.d.ts +35 -0
  151. package/lib/types/rpc.js +3 -0
  152. package/lib/types/signatures.d.ts +28 -0
  153. package/lib/types/signatures.js +3 -0
  154. package/lib/types/tunnel.d.ts +18 -0
  155. package/lib/types/tunnel.js +3 -0
  156. package/lib/types/zk.d.ts +16 -0
  157. package/lib/types/zk.js +3 -0
  158. package/lib/utils/benchmark.d.ts +1 -0
  159. package/lib/utils/benchmark.js +70 -0
  160. package/lib/utils/claims.d.ts +33 -0
  161. package/lib/utils/claims.js +112 -0
  162. package/lib/utils/env.d.ts +3 -0
  163. package/lib/utils/env.js +20 -0
  164. package/lib/utils/error.d.ts +27 -0
  165. package/lib/utils/error.js +43 -0
  166. package/lib/utils/generics.d.ts +112 -0
  167. package/lib/utils/generics.js +348 -0
  168. package/lib/utils/http-parser.d.ts +55 -0
  169. package/lib/utils/http-parser.js +249 -0
  170. package/lib/utils/index.d.ts +10 -0
  171. package/lib/utils/index.js +27 -0
  172. package/lib/utils/logger.d.ts +13 -0
  173. package/lib/utils/logger.js +100 -0
  174. package/lib/utils/prepare-packets.d.ts +16 -0
  175. package/lib/utils/prepare-packets.js +61 -0
  176. package/lib/utils/redactions.d.ts +41 -0
  177. package/lib/utils/redactions.js +111 -0
  178. package/lib/utils/retries.d.ts +12 -0
  179. package/lib/utils/retries.js +28 -0
  180. package/lib/utils/signatures/eth.d.ts +2 -0
  181. package/lib/utils/signatures/eth.js +33 -0
  182. package/lib/utils/signatures/index.d.ts +5 -0
  183. package/lib/utils/signatures/index.js +11 -0
  184. package/lib/utils/socket-base.d.ts +21 -0
  185. package/lib/utils/socket-base.js +89 -0
  186. package/lib/utils/tls.d.ts +2 -0
  187. package/lib/utils/tls.js +32 -0
  188. package/lib/utils/validation.d.ts +2 -0
  189. package/lib/utils/validation.js +46 -0
  190. package/lib/utils/ws.d.ts +12 -0
  191. package/lib/utils/ws.js +21 -0
  192. package/lib/utils/zk.d.ts +50 -0
  193. package/lib/utils/zk.js +282 -0
  194. package/lib/window-rpc/index.d.ts +3 -0
  195. package/lib/window-rpc/index.js +20 -0
  196. package/lib/window-rpc/setup-window-rpc.d.ts +5 -0
  197. package/lib/window-rpc/setup-window-rpc.js +239 -0
  198. package/lib/window-rpc/types.d.ts +184 -0
  199. package/lib/window-rpc/types.js +3 -0
  200. package/lib/window-rpc/utils.d.ts +13 -0
  201. package/lib/window-rpc/utils.js +76 -0
  202. package/lib/window-rpc/window-rpc-zk.d.ts +11 -0
  203. package/lib/window-rpc/window-rpc-zk.js +72 -0
  204. package/package.json +117 -0
@@ -0,0 +1,33 @@
1
+ import { ClaimTunnelResponse } from 'src/proto/api';
2
+ import { ClaimID, ClaimInfo, CompleteClaimData, ProviderParams } from 'src/types';
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").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,112 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createSignDataForClaim = createSignDataForClaim;
7
+ exports.assertValidClaimSignatures = assertValidClaimSignatures;
8
+ exports.getIdentifierFromClaimInfo = getIdentifierFromClaimInfo;
9
+ exports.canonicalStringify = canonicalStringify;
10
+ exports.hashProviderParams = hashProviderParams;
11
+ const tls_1 = require("@reclaimprotocol/tls");
12
+ const canonicalize_1 = __importDefault(require("canonicalize"));
13
+ const ethers_1 = require("ethers");
14
+ const config_1 = require("src/config");
15
+ const api_1 = require("src/proto/api");
16
+ const signatures_1 = require("src/utils/signatures");
17
+ /**
18
+ * Creates the standard string to sign for a claim.
19
+ * This data is what the attestor will sign when it successfully
20
+ * verifies a claim.
21
+ */
22
+ function createSignDataForClaim(data) {
23
+ const identifier = 'identifier' in data
24
+ ? data.identifier
25
+ : getIdentifierFromClaimInfo(data);
26
+ const lines = [
27
+ identifier,
28
+ // we lowercase the owner to ensure that the
29
+ // ETH addresses always serialize the same way
30
+ data.owner.toLowerCase(),
31
+ data.timestampS.toString(),
32
+ data.epoch.toString(),
33
+ ];
34
+ return lines.join('\n');
35
+ }
36
+ /**
37
+ * Verify the claim tunnel response from a attestor.
38
+ *
39
+ * If you'd only like to verify the claim signature, you can
40
+ * optionally only pass "claim" & "signatures.claimSignature"
41
+ * to this function.
42
+ *
43
+ * The successful run of this function means that the claim
44
+ * is valid, and the attestor that signed the claim is valid.
45
+ */
46
+ async function assertValidClaimSignatures({ signatures, ...res }, metadata = config_1.DEFAULT_METADATA) {
47
+ if (!signatures) {
48
+ throw new Error('No signatures provided');
49
+ }
50
+ const { resultSignature, claimSignature, attestorAddress } = signatures;
51
+ const { verify } = signatures_1.SIGNATURES[metadata.signatureType];
52
+ if (signatures === null || signatures === void 0 ? void 0 : signatures.resultSignature) {
53
+ const resBytes = api_1.ClaimTunnelResponse.encode(api_1.ClaimTunnelResponse.create(res)).finish();
54
+ const verified = await verify(resBytes, resultSignature, attestorAddress);
55
+ if (!verified) {
56
+ throw new Error('Invalid result signature');
57
+ }
58
+ }
59
+ // claim wasn't generated -- i.e. the transcript
60
+ // did not contain the necessary data
61
+ if (!res.claim) {
62
+ return;
63
+ }
64
+ const signData = createSignDataForClaim(res.claim);
65
+ const verifiedClaim = await verify((0, tls_1.strToUint8Array)(signData), claimSignature, attestorAddress);
66
+ if (!verifiedClaim) {
67
+ throw new Error('Invalid claim signature');
68
+ }
69
+ }
70
+ /**
71
+ * Generates a unique identifier for given claim info
72
+ * @param info
73
+ * @returns
74
+ */
75
+ function getIdentifierFromClaimInfo(info) {
76
+ var _a;
77
+ //re-canonicalize context if it's not empty
78
+ if (((_a = info.context) === null || _a === void 0 ? void 0 : _a.length) > 0) {
79
+ try {
80
+ const ctx = JSON.parse(info.context);
81
+ info.context = canonicalStringify(ctx);
82
+ }
83
+ catch (e) {
84
+ throw new Error('unable to parse non-empty context. Must be JSON');
85
+ }
86
+ }
87
+ const str = `${info.provider}\n${info.parameters}\n${info.context || ''}`;
88
+ //console.log('Identifier: ' + btoa(str))
89
+ return ethers_1.utils.keccak256((0, tls_1.strToUint8Array)(str)).toLowerCase();
90
+ }
91
+ /**
92
+ * Canonically stringifies an object, so that the same object will always
93
+ * produce the same string despite the order of keys
94
+ */
95
+ function canonicalStringify(params) {
96
+ if (!params) {
97
+ return '';
98
+ }
99
+ return (0, canonicalize_1.default)(params) || '';
100
+ }
101
+ function hashProviderParams(params) {
102
+ const filteredParams = {
103
+ url: params.url,
104
+ method: params.method,
105
+ responseMatches: params.responseMatches,
106
+ responseRedactions: params.responseRedactions,
107
+ geoLocation: params.geoLocation
108
+ };
109
+ const serializedParams = canonicalStringify(filteredParams);
110
+ return ethers_1.utils.keccak256((0, tls_1.strToUint8Array)(serializedParams)).toLowerCase();
111
+ }
112
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhaW1zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL2NsYWltcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpb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lQUFlLEVBQUUsTUFBTSxDQUFDLGVBQWU7UUFDdkMsa0JBQWtCLEVBQUUsTUFBTSxDQUFDLGtCQUFrQjtRQUM3QyxXQUFXLEVBQUMsTUFBTSxDQUFDLFdBQVc7S0FDOUIsQ0FBQTtJQUVELE1BQU0sZ0JBQWdCLEdBQUcsa0JBQWtCLENBQUMsY0FBYyxDQUFDLENBQUE7SUFDM0QsT0FBTyxjQUFLLENBQUMsU0FBUyxDQUNyQixJQUFBLHFCQUFlLEVBQUMsZ0JBQWdCLENBQUMsQ0FDakMsQ0FBQyxXQUFXLEVBQUUsQ0FBQTtBQUNoQixDQUFDIn0=
@@ -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,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectEnvironment = detectEnvironment;
4
+ exports.getEnvVariable = getEnvVariable;
5
+ function detectEnvironment() {
6
+ if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
7
+ return 'react-native';
8
+ }
9
+ if (typeof window !== 'undefined') {
10
+ return 'browser';
11
+ }
12
+ return 'node';
13
+ }
14
+ function getEnvVariable(name) {
15
+ if (typeof process === 'undefined') {
16
+ return undefined;
17
+ }
18
+ return process === null || process === void 0 ? void 0 : process.env[name];
19
+ }
20
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW52LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL2Vudi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUVBLDhDQVVDO0FBRUQsd0NBTUM7QUFsQkQsU0FBZ0IsaUJBQWlCO0lBQ2hDLElBQUcsT0FBTyxTQUFTLEtBQUssV0FBVyxJQUFJLFNBQVMsQ0FBQyxPQUFPLEtBQUssYUFBYSxFQUFFLENBQUM7UUFDNUUsT0FBTyxjQUFjLENBQUE7SUFDdEIsQ0FBQztJQUVELElBQUcsT0FBTyxNQUFNLEtBQUssV0FBVyxFQUFFLENBQUM7UUFDbEMsT0FBTyxTQUFTLENBQUE7SUFDakIsQ0FBQztJQUVELE9BQU8sTUFBTSxDQUFBO0FBQ2QsQ0FBQztBQUVELFNBQWdCLGNBQWMsQ0FBQyxJQUFZO0lBQzFDLElBQUcsT0FBTyxPQUFPLEtBQUssV0FBVyxFQUFFLENBQUM7UUFDbkMsT0FBTyxTQUFTLENBQUE7SUFDakIsQ0FBQztJQUVELE9BQU8sT0FBTyxhQUFQLE9BQU8sdUJBQVAsT0FBTyxDQUFFLEdBQUcsQ0FBQyxJQUFJLENBQUMsQ0FBQTtBQUMxQixDQUFDIn0=
@@ -0,0 +1,27 @@
1
+ import { ErrorCode, ErrorData } from 'src/proto/api';
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
+ code: keyof typeof ErrorCode;
9
+ message: string;
10
+ data?: {
11
+ [_: string]: any;
12
+ } | undefined;
13
+ readonly name = "AttestorError";
14
+ constructor(code: keyof typeof ErrorCode, message: string, data?: {
15
+ [_: string]: any;
16
+ } | undefined);
17
+ /**
18
+ * Encodes the error as a ErrorData
19
+ * protobuf message
20
+ */
21
+ toProto(): ErrorData;
22
+ static fromProto(data?: ErrorData): AttestorError;
23
+ static fromError(err: Error): AttestorError;
24
+ static badRequest(message: string, data?: {
25
+ [_: string]: any;
26
+ }): AttestorError;
27
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttestorError = void 0;
4
+ const api_1 = require("src/proto/api");
5
+ /**
6
+ * Represents an error that can be thrown by the Attestor Core
7
+ * or server. Provides a code, and optional data
8
+ * to pass along with the error.
9
+ */
10
+ class AttestorError extends Error {
11
+ constructor(code, message, data) {
12
+ super(message);
13
+ this.code = code;
14
+ this.message = message;
15
+ this.data = data;
16
+ this.name = 'AttestorError';
17
+ }
18
+ /**
19
+ * Encodes the error as a ErrorData
20
+ * protobuf message
21
+ */
22
+ toProto() {
23
+ return api_1.ErrorData.create({
24
+ code: api_1.ErrorCode[this.code],
25
+ message: this.message,
26
+ data: JSON.stringify(this.data)
27
+ });
28
+ }
29
+ static fromProto(data = api_1.ErrorData.fromJSON({})) {
30
+ return new AttestorError(api_1.ErrorCode[data.code], data.message, data.data ? JSON.parse(data.data) : undefined);
31
+ }
32
+ static fromError(err) {
33
+ if (err instanceof AttestorError) {
34
+ return err;
35
+ }
36
+ return new AttestorError('ERROR_INTERNAL', err.message);
37
+ }
38
+ static badRequest(message, data) {
39
+ return new AttestorError('ERROR_BAD_REQUEST', message, data);
40
+ }
41
+ }
42
+ exports.AttestorError = AttestorError;
43
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvZXJyb3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsdUNBQW9EO0FBRXBEOzs7O0dBSUc7QUFDSCxNQUFhLGFBQWMsU0FBUSxLQUFLO0lBSXZDLFlBQ1EsSUFBNEIsRUFDNUIsT0FBZSxFQUNmLElBQTJCO1FBRWxDLEtBQUssQ0FBQyxPQUFPLENBQUMsQ0FBQTtRQUpQLFNBQUksR0FBSixJQUFJLENBQXdCO1FBQzVCLFlBQU8sR0FBUCxPQUFPLENBQVE7UUFDZixTQUFJLEdBQUosSUFBSSxDQUF1QjtRQUwxQixTQUFJLEdBQUcsZUFBZSxDQUFBO0lBUS9CLENBQUM7SUFFRDs7O09BR0c7SUFDSCxPQUFPO1FBQ04sT0FBTyxlQUFTLENBQUMsTUFBTSxDQUFDO1lBQ3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api';
3
+ import { CompleteTLSPacket, IDecryptedTranscript, IDecryptedTranscriptMessage, ProviderField, RPCEvent, RPCEventMap, RPCEventType, RPCType, Transcript } from 'src/types';
4
+ export declare function uint8ArrayToStr(arr: Uint8Array): string;
5
+ export declare function getTranscriptString(receipt: IDecryptedTranscript): string;
6
+ export declare const unixTimestampSeconds: () => number;
7
+ /**
8
+ * Find index of needle in haystack
9
+ */
10
+ export declare function findIndexInUint8Array(haystack: Uint8Array, needle: Uint8Array): number;
11
+ /**
12
+ * convert a Uint8Array to a binary encoded str
13
+ * from: https://github.com/feross/buffer/blob/795bbb5bda1b39f1370ebd784bea6107b087e3a7/index.js#L1063
14
+ * @param buf
15
+ * @returns
16
+ */
17
+ export declare function uint8ArrayToBinaryStr(buf: Uint8Array): string;
18
+ export declare function gunzipSync(buf: Uint8Array): Uint8Array;
19
+ /**
20
+ * Fetch the ZK algorithm for the specified cipher suite
21
+ */
22
+ export declare function getZkAlgorithmForCipherSuite(cipherSuite: CipherSuite): "aes-256-ctr" | "aes-128-ctr" | "chacha20";
23
+ /**
24
+ * Get the pure ciphertext without any MAC,
25
+ * or authentication tag,
26
+ * @param content content w/o header
27
+ * @param cipherSuite
28
+ */
29
+ export declare function getPureCiphertext(content: Uint8Array, cipherSuite: CipherSuite): Uint8Array;
30
+ /**
31
+ * Get the 8 byte IV part that's stored in the record for some cipher suites
32
+ * @param content content w/o header
33
+ * @param cipherSuite
34
+ */
35
+ export declare function getRecordIV(content: Uint8Array, cipherSuite: CipherSuite): Uint8Array;
36
+ export declare function getProviderValue<P, T>(params: P, fn: ProviderField<P, T>): T;
37
+ export declare function generateRpcMessageId(): number;
38
+ /**
39
+ * Random session ID for a WebSocket client.
40
+ */
41
+ export declare function generateSessionId(): number;
42
+ /**
43
+ * Random ID for a tunnel.
44
+ */
45
+ export declare function generateTunnelId(): number;
46
+ export declare function makeRpcEvent<T extends RPCEventType>(type: T, data: RPCEventMap[T]): RPCEvent<T>;
47
+ /**
48
+ * Get the RPC type from the key.
49
+ * For eg. "claimTunnelRequest" ->
50
+ * { type: 'claimTunnel', direction: 'request' }
51
+ */
52
+ export declare function getRpcTypeFromKey(key: string): {
53
+ type: RPCType;
54
+ direction: "request";
55
+ } | {
56
+ type: RPCType;
57
+ direction: "response";
58
+ } | undefined;
59
+ /**
60
+ * Get the RPC response type from the RPC type.
61
+ * For eg. "claimTunnel" -> "claimTunnelResponse"
62
+ */
63
+ export declare function getRpcResponseType<T extends RPCType>(type: T): `${T}Response`;
64
+ /**
65
+ * Get the RPC request type from the RPC type.
66
+ * For eg. "claimTunnel" -> "claimTunnelRequest"
67
+ */
68
+ export declare function getRpcRequestType<T extends RPCType>(type: T): `${T}Request`;
69
+ export declare function isApplicationData(packet: CompleteTLSPacket, tlsVersion: string | undefined): boolean;
70
+ /**
71
+ * Convert the received data from a WS to a Uint8Array
72
+ */
73
+ export declare function extractArrayBufferFromWsData(data: unknown): Promise<Uint8Array>;
74
+ /**
75
+ * Check if the RPC message is a request or a response.
76
+ */
77
+ export declare function getRpcRequest(msg: RPCMessage): {
78
+ type: RPCType;
79
+ direction: "request";
80
+ } | {
81
+ type: RPCType;
82
+ direction: "response";
83
+ } | {
84
+ direction: "response";
85
+ type: "error";
86
+ } | undefined;
87
+ /**
88
+ * Finds all application data messages in a transcript
89
+ * and returns them. Removes the "contentType" suffix from the message.
90
+ * in TLS 1.3
91
+ */
92
+ export declare function extractApplicationDataFromTranscript({ transcript, tlsVersion }: IDecryptedTranscript): Transcript<Uint8Array>;
93
+ export type HandshakeTranscript<T> = {
94
+ sender: 'client' | 'server';
95
+ index: number;
96
+ message: T;
97
+ }[];
98
+ export declare function extractHandshakeFromTranscript({ transcript, tlsVersion }: {
99
+ transcript: IDecryptedTranscriptMessage[];
100
+ tlsVersion: TLSProtocolVersion;
101
+ }): HandshakeTranscript<Uint8Array>;
102
+ export declare function decryptDirect(directReveal: any, cipherSuite: CipherSuite, recordHeader: Uint8Array, serverTlsVersion: TLSProtocolVersion, content: Uint8Array): Promise<{
103
+ plaintext: Uint8Array;
104
+ iv: Uint8Array;
105
+ }>;
106
+ export declare function packRpcMessages(...msgs: Partial<RPCMessage>[]): RPCMessages;
107
+ /**
108
+ * Converts an Ethers struct (an array w named keys) to
109
+ * a plain object. Recursively converts all structs inside.
110
+ * Required to correctly JSON.stringify the struct.
111
+ */
112
+ export declare function ethersStructToPlainObject<T>(struct: T): T;