@polymarket/clob-client 5.0.0 → 5.1.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 (52) hide show
  1. package/package.json +2 -2
  2. package/dist/client.d.ts +0 -118
  3. package/dist/client.js +0 -776
  4. package/dist/client.js.map +0 -1
  5. package/dist/config.d.ts +0 -12
  6. package/dist/config.js +0 -28
  7. package/dist/config.js.map +0 -1
  8. package/dist/constants.d.ts +0 -3
  9. package/dist/constants.js +0 -7
  10. package/dist/constants.js.map +0 -1
  11. package/dist/endpoints.d.ts +0 -51
  12. package/dist/endpoints.js +0 -63
  13. package/dist/endpoints.js.map +0 -1
  14. package/dist/errors.d.ts +0 -4
  15. package/dist/errors.js +0 -5
  16. package/dist/errors.js.map +0 -1
  17. package/dist/headers/index.d.ts +0 -7
  18. package/dist/headers/index.js +0 -41
  19. package/dist/headers/index.js.map +0 -1
  20. package/dist/http-helpers/index.d.ts +0 -18
  21. package/dist/http-helpers/index.js +0 -105
  22. package/dist/http-helpers/index.js.map +0 -1
  23. package/dist/index.d.ts +0 -5
  24. package/dist/index.js +0 -6
  25. package/dist/index.js.map +0 -1
  26. package/dist/order-builder/builder.d.ts +0 -30
  27. package/dist/order-builder/builder.js +0 -52
  28. package/dist/order-builder/builder.js.map +0 -1
  29. package/dist/order-builder/helpers.d.ts +0 -51
  30. package/dist/order-builder/helpers.js +0 -279
  31. package/dist/order-builder/helpers.js.map +0 -1
  32. package/dist/order-builder/index.d.ts +0 -1
  33. package/dist/order-builder/index.js +0 -2
  34. package/dist/order-builder/index.js.map +0 -1
  35. package/dist/signing/constants.d.ts +0 -14
  36. package/dist/signing/constants.js +0 -16
  37. package/dist/signing/constants.js.map +0 -1
  38. package/dist/signing/eip712.d.ts +0 -10
  39. package/dist/signing/eip712.js +0 -34
  40. package/dist/signing/eip712.js.map +0 -1
  41. package/dist/signing/hmac.d.ts +0 -9
  42. package/dist/signing/hmac.js +0 -52
  43. package/dist/signing/hmac.js.map +0 -1
  44. package/dist/signing/index.d.ts +0 -2
  45. package/dist/signing/index.js +0 -3
  46. package/dist/signing/index.js.map +0 -1
  47. package/dist/types.d.ts +0 -445
  48. package/dist/types.js +0 -31
  49. package/dist/types.js.map +0 -1
  50. package/dist/utilities.d.ts +0 -16
  51. package/dist/utilities.js +0 -89
  52. package/dist/utilities.js.map +0 -1
@@ -1,279 +0,0 @@
1
- import { parseUnits } from "@ethersproject/units";
2
- import { ExchangeOrderBuilder, SignatureType, Side as UtilsSide, } from "@polymarket/order-utils";
3
- import { Side, OrderType } from "../types.js";
4
- import { decimalPlaces, roundDown, roundNormal, roundUp } from "../utilities.js";
5
- import { COLLATERAL_TOKEN_DECIMALS, getContractConfig } from "../config.js";
6
- export const ROUNDING_CONFIG = {
7
- "0.1": {
8
- price: 1,
9
- size: 2,
10
- amount: 3,
11
- },
12
- "0.01": {
13
- price: 2,
14
- size: 2,
15
- amount: 4,
16
- },
17
- "0.001": {
18
- price: 3,
19
- size: 2,
20
- amount: 5,
21
- },
22
- "0.0001": {
23
- price: 4,
24
- size: 2,
25
- amount: 6,
26
- },
27
- };
28
- /**
29
- * Generate and sign a order
30
- *
31
- * @param signer
32
- * @param exchangeAddress ctf exchange contract address
33
- * @param chainId
34
- * @param OrderData
35
- * @returns SignedOrder
36
- */
37
- export const buildOrder = async (signer, exchangeAddress, chainId, orderData) => {
38
- const cTFExchangeOrderBuilder = new ExchangeOrderBuilder(exchangeAddress, chainId, signer);
39
- return cTFExchangeOrderBuilder.buildSignedOrder(orderData);
40
- };
41
- export const getOrderRawAmounts = (side, size, price, roundConfig) => {
42
- const rawPrice = roundNormal(price, roundConfig.price);
43
- if (side === Side.BUY) {
44
- // force 2 decimals places
45
- const rawTakerAmt = roundDown(size, roundConfig.size);
46
- let rawMakerAmt = rawTakerAmt * rawPrice;
47
- if (decimalPlaces(rawMakerAmt) > roundConfig.amount) {
48
- rawMakerAmt = roundUp(rawMakerAmt, roundConfig.amount + 4);
49
- if (decimalPlaces(rawMakerAmt) > roundConfig.amount) {
50
- rawMakerAmt = roundDown(rawMakerAmt, roundConfig.amount);
51
- }
52
- }
53
- return {
54
- side: UtilsSide.BUY,
55
- rawMakerAmt,
56
- rawTakerAmt,
57
- };
58
- }
59
- else {
60
- const rawMakerAmt = roundDown(size, roundConfig.size);
61
- let rawTakerAmt = rawMakerAmt * rawPrice;
62
- if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
63
- rawTakerAmt = roundUp(rawTakerAmt, roundConfig.amount + 4);
64
- if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
65
- rawTakerAmt = roundDown(rawTakerAmt, roundConfig.amount);
66
- }
67
- }
68
- return {
69
- side: UtilsSide.SELL,
70
- rawMakerAmt,
71
- rawTakerAmt,
72
- };
73
- }
74
- };
75
- /**
76
- * Translate simple user order to args used to generate Orders
77
- */
78
- export const buildOrderCreationArgs = async (signer, maker, signatureType, userOrder, roundConfig) => {
79
- const { side, rawMakerAmt, rawTakerAmt } = getOrderRawAmounts(userOrder.side, userOrder.size, userOrder.price, roundConfig);
80
- const makerAmount = parseUnits(rawMakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();
81
- const takerAmount = parseUnits(rawTakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();
82
- let taker;
83
- if (typeof userOrder.taker !== "undefined" && userOrder.taker) {
84
- taker = userOrder.taker;
85
- }
86
- else {
87
- taker = "0x0000000000000000000000000000000000000000";
88
- }
89
- let feeRateBps;
90
- if (typeof userOrder.feeRateBps !== "undefined" && userOrder.feeRateBps) {
91
- feeRateBps = userOrder.feeRateBps.toString();
92
- }
93
- else {
94
- feeRateBps = "0";
95
- }
96
- let nonce;
97
- if (typeof userOrder.nonce !== "undefined" && userOrder.nonce) {
98
- nonce = userOrder.nonce.toString();
99
- }
100
- else {
101
- nonce = "0";
102
- }
103
- return {
104
- maker,
105
- taker,
106
- tokenId: userOrder.tokenID,
107
- makerAmount,
108
- takerAmount,
109
- side,
110
- feeRateBps,
111
- nonce,
112
- signer,
113
- expiration: (userOrder.expiration || 0).toString(),
114
- signatureType,
115
- };
116
- };
117
- export const createOrder = async (eoaSigner, chainId, signatureType, funderAddress, userOrder, options) => {
118
- const eoaSignerAddress = await eoaSigner.getAddress();
119
- // If funder address is not given, use the signer address
120
- const maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;
121
- const contractConfig = getContractConfig(chainId);
122
- const orderData = await buildOrderCreationArgs(eoaSignerAddress, maker, signatureType, userOrder, ROUNDING_CONFIG[options.tickSize]);
123
- const exchangeContract = options.negRisk
124
- ? contractConfig.negRiskExchange
125
- : contractConfig.exchange;
126
- return buildOrder(eoaSigner, exchangeContract, chainId, orderData);
127
- };
128
- export const getMarketOrderRawAmounts = (side, amount, price, roundConfig) => {
129
- // force 2 decimals places
130
- const rawPrice = roundDown(price, roundConfig.price);
131
- if (side === Side.BUY) {
132
- const rawMakerAmt = roundDown(amount, roundConfig.size);
133
- let rawTakerAmt = rawMakerAmt / rawPrice;
134
- if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
135
- rawTakerAmt = roundUp(rawTakerAmt, roundConfig.amount + 4);
136
- if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
137
- rawTakerAmt = roundDown(rawTakerAmt, roundConfig.amount);
138
- }
139
- }
140
- return {
141
- side: UtilsSide.BUY,
142
- rawMakerAmt,
143
- rawTakerAmt,
144
- };
145
- }
146
- else {
147
- const rawMakerAmt = roundDown(amount, roundConfig.size);
148
- let rawTakerAmt = rawMakerAmt * rawPrice;
149
- if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
150
- rawTakerAmt = roundUp(rawTakerAmt, roundConfig.amount + 4);
151
- if (decimalPlaces(rawTakerAmt) > roundConfig.amount) {
152
- rawTakerAmt = roundDown(rawTakerAmt, roundConfig.amount);
153
- }
154
- }
155
- return {
156
- side: UtilsSide.SELL,
157
- rawMakerAmt,
158
- rawTakerAmt,
159
- };
160
- }
161
- };
162
- /**
163
- * Translate simple user market order to args used to generate Orders
164
- */
165
- export const buildMarketOrderCreationArgs = async (signer, maker, signatureType, userMarketOrder, roundConfig) => {
166
- const { side, rawMakerAmt, rawTakerAmt } = getMarketOrderRawAmounts(userMarketOrder.side, userMarketOrder.amount, userMarketOrder.price || 1, roundConfig);
167
- const makerAmount = parseUnits(rawMakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();
168
- const takerAmount = parseUnits(rawTakerAmt.toString(), COLLATERAL_TOKEN_DECIMALS).toString();
169
- let taker;
170
- if (typeof userMarketOrder.taker !== "undefined" && userMarketOrder.taker) {
171
- taker = userMarketOrder.taker;
172
- }
173
- else {
174
- taker = "0x0000000000000000000000000000000000000000";
175
- }
176
- let feeRateBps;
177
- if (typeof userMarketOrder.feeRateBps !== "undefined" && userMarketOrder.feeRateBps) {
178
- feeRateBps = userMarketOrder.feeRateBps.toString();
179
- }
180
- else {
181
- feeRateBps = "0";
182
- }
183
- let nonce;
184
- if (typeof userMarketOrder.nonce !== "undefined" && userMarketOrder.nonce) {
185
- nonce = userMarketOrder.nonce.toString();
186
- }
187
- else {
188
- nonce = "0";
189
- }
190
- return {
191
- maker,
192
- taker,
193
- tokenId: userMarketOrder.tokenID,
194
- makerAmount,
195
- takerAmount,
196
- side,
197
- feeRateBps,
198
- nonce,
199
- signer,
200
- expiration: "0",
201
- signatureType,
202
- };
203
- };
204
- export const createMarketOrder = async (eoaSigner, chainId, signatureType, funderAddress, userMarketOrder, options) => {
205
- const eoaSignerAddress = await eoaSigner.getAddress();
206
- // If funder address is not given, use the signer address
207
- const maker = funderAddress === undefined ? eoaSignerAddress : funderAddress;
208
- const contractConfig = getContractConfig(chainId);
209
- const orderData = await buildMarketOrderCreationArgs(eoaSignerAddress, maker, signatureType, userMarketOrder, ROUNDING_CONFIG[options.tickSize]);
210
- const exchangeContract = options.negRisk
211
- ? contractConfig.negRiskExchange
212
- : contractConfig.exchange;
213
- return buildOrder(eoaSigner, exchangeContract, chainId, orderData);
214
- };
215
- /**
216
- * calculateBuyMarketPrice calculates the market price to buy a $$ amount
217
- * @param positions
218
- * @param amountToMatch worth to buy
219
- * @returns
220
- */
221
- export const calculateBuyMarketPrice = (positions, amountToMatch, orderType) => {
222
- if (!positions.length) {
223
- throw new Error("no match");
224
- }
225
- let sum = 0;
226
- /*
227
- Asks:
228
- [
229
- { price: '0.6', size: '100' },
230
- { price: '0.55', size: '100' },
231
- { price: '0.5', size: '100' }
232
- ]
233
- So, if the amount to match is $150 that will be reached at first position so price will be 0.6
234
- */
235
- for (let i = positions.length - 1; i >= 0; i--) {
236
- const p = positions[i];
237
- sum += parseFloat(p.size) * parseFloat(p.price);
238
- if (sum >= amountToMatch) {
239
- return parseFloat(p.price);
240
- }
241
- }
242
- if (orderType === OrderType.FOK) {
243
- throw new Error("no match");
244
- }
245
- return parseFloat(positions[0].price);
246
- };
247
- /**
248
- * calculateSellMarketPrice calculates the market price to sell a shares
249
- * @param positions
250
- * @param amountToMatch sells to share
251
- * @returns
252
- */
253
- export const calculateSellMarketPrice = (positions, amountToMatch, orderType) => {
254
- if (!positions.length) {
255
- throw new Error("no match");
256
- }
257
- let sum = 0;
258
- /*
259
- Bids:
260
- [
261
- { price: '0.4', size: '100' },
262
- { price: '0.45', size: '100' },
263
- { price: '0.5', size: '100' }
264
- ]
265
- So, if the amount to match is 300 that will be reached at the first position so price will be 0.4
266
- */
267
- for (let i = positions.length - 1; i >= 0; i--) {
268
- const p = positions[i];
269
- sum += parseFloat(p.size);
270
- if (sum >= amountToMatch) {
271
- return parseFloat(p.price);
272
- }
273
- }
274
- if (orderType === OrderType.FOK) {
275
- throw new Error("no match");
276
- }
277
- return parseFloat(positions[0].price);
278
- };
279
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/order-builder/helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,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@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/order-builder/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -1,14 +0,0 @@
1
- export declare const CLOB_DOMAIN_NAME = "ClobAuthDomain";
2
- export declare const CLOB_VERSION = "1";
3
- export declare const MSG_TO_SIGN = "This message attests that I control the given wallet";
4
- export declare const CLOB_DOMAIN: {
5
- name: string;
6
- version: string;
7
- chainId: number;
8
- };
9
- export declare const CLOB_TYPES: {
10
- ClobAuth: {
11
- name: string;
12
- type: string;
13
- }[];
14
- };
@@ -1,16 +0,0 @@
1
- export const CLOB_DOMAIN_NAME = "ClobAuthDomain";
2
- export const CLOB_VERSION = "1";
3
- export const MSG_TO_SIGN = "This message attests that I control the given wallet";
4
- export const CLOB_DOMAIN = {
5
- name: CLOB_DOMAIN_NAME,
6
- version: CLOB_VERSION,
7
- chainId: 1,
8
- };
9
- export const CLOB_TYPES = {
10
- ClobAuth: [
11
- { name: "address", type: "address" },
12
- { name: "timestamp", type: "string" },
13
- { name: "message", type: "string" },
14
- ],
15
- };
16
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/signing/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AACjD,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC;AAChC,MAAM,CAAC,MAAM,WAAW,GAAG,sDAAsD,CAAC;AAElF,MAAM,CAAC,MAAM,WAAW,GAAG;IACvB,IAAI,EAAE,gBAAgB;IACtB,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,CAAC;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG;IACtB,QAAQ,EAAE;QACN,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;QACpC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;QACrC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;KACtC;CACJ,CAAC"}
@@ -1,10 +0,0 @@
1
- import type { Wallet } from "@ethersproject/wallet";
2
- import type { JsonRpcSigner } from "@ethersproject/providers";
3
- import type { Chain } from "../types.ts";
4
- /**
5
- * Builds the canonical Polymarket CLOB EIP712 signature
6
- * @param signer
7
- * @param ts
8
- * @returns string
9
- */
10
- export declare const buildClobEip712Signature: (signer: Wallet | JsonRpcSigner, chainId: Chain, timestamp: number, nonce: number) => Promise<string>;
@@ -1,34 +0,0 @@
1
- import { MSG_TO_SIGN } from "./constants.js";
2
- /**
3
- * Builds the canonical Polymarket CLOB EIP712 signature
4
- * @param signer
5
- * @param ts
6
- * @returns string
7
- */
8
- export const buildClobEip712Signature = async (signer, chainId, timestamp, nonce) => {
9
- const address = await signer.getAddress();
10
- const ts = `${timestamp}`;
11
- const domain = {
12
- name: "ClobAuthDomain",
13
- version: "1",
14
- chainId: chainId,
15
- };
16
- const types = {
17
- ClobAuth: [
18
- { name: "address", type: "address" },
19
- { name: "timestamp", type: "string" },
20
- { name: "nonce", type: "uint256" },
21
- { name: "message", type: "string" },
22
- ],
23
- };
24
- const value = {
25
- address,
26
- timestamp: ts,
27
- nonce,
28
- message: MSG_TO_SIGN,
29
- };
30
- // eslint-disable-next-line no-underscore-dangle
31
- const sig = await signer._signTypedData(domain, types, value);
32
- return sig;
33
- };
34
- //# sourceMappingURL=eip712.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eip712.js","sourceRoot":"","sources":["../../src/signing/eip712.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EACzC,MAA8B,EAC9B,OAAc,EACd,SAAiB,EACjB,KAAa,EACE,EAAE;IACjB,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;IAC1C,MAAM,EAAE,GAAG,GAAG,SAAS,EAAE,CAAC;IAE1B,MAAM,MAAM,GAAG;QACX,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,OAAO;KACnB,CAAC;IAEF,MAAM,KAAK,GAAG;QACV,QAAQ,EAAE;YACN,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;YACpC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;YACrC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;YAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;SACtC;KACJ,CAAC;IACF,MAAM,KAAK,GAAG;QACV,OAAO;QACP,SAAS,EAAE,EAAE;QACb,KAAK;QACL,OAAO,EAAE,WAAW;KACvB,CAAC;IACF,gDAAgD;IAChD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAC9D,OAAO,GAAG,CAAC;AACf,CAAC,CAAC"}
@@ -1,9 +0,0 @@
1
- /**
2
- * Builds the canonical Polymarket CLOB HMAC signature
3
- * @param signer
4
- * @param key
5
- * @param secret
6
- * @param passphrase
7
- * @returns string
8
- */
9
- export declare const buildPolyHmacSignature: (secret: string, timestamp: number, method: string, requestPath: string, body?: string) => Promise<string>;
@@ -1,52 +0,0 @@
1
- function replaceAll(s, search, replace) {
2
- return s.split(search).join(replace);
3
- }
4
- /**
5
- * Converts base64 string to ArrayBuffer
6
- */
7
- function base64ToArrayBuffer(base64) {
8
- const binaryString = atob(base64);
9
- const bytes = new Uint8Array(binaryString.length);
10
- for (let i = 0; i < binaryString.length; i++) {
11
- bytes[i] = binaryString.charCodeAt(i);
12
- }
13
- return bytes.buffer;
14
- }
15
- /**
16
- * Converts ArrayBuffer to base64 string
17
- */
18
- function arrayBufferToBase64(buffer) {
19
- const bytes = new Uint8Array(buffer);
20
- let binary = "";
21
- for (let i = 0; i < bytes.byteLength; i++) {
22
- binary += String.fromCharCode(bytes[i]);
23
- }
24
- return btoa(binary);
25
- }
26
- /**
27
- * Builds the canonical Polymarket CLOB HMAC signature
28
- * @param signer
29
- * @param key
30
- * @param secret
31
- * @param passphrase
32
- * @returns string
33
- */
34
- export const buildPolyHmacSignature = async (secret, timestamp, method, requestPath, body) => {
35
- let message = timestamp + method + requestPath;
36
- if (body !== undefined) {
37
- message += body;
38
- }
39
- // Import the secret key from base64
40
- const keyData = base64ToArrayBuffer(secret);
41
- const cryptoKey = await crypto.subtle.importKey("raw", keyData, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
42
- // Sign the message
43
- const messageBuffer = new TextEncoder().encode(message);
44
- const signatureBuffer = await crypto.subtle.sign("HMAC", cryptoKey, messageBuffer);
45
- const sig = arrayBufferToBase64(signatureBuffer);
46
- // NOTE: Must be url safe base64 encoding, but keep base64 "=" suffix
47
- // Convert '+' to '-'
48
- // Convert '/' to '_'
49
- const sigUrlSafe = replaceAll(replaceAll(sig, "+", "-"), "/", "_");
50
- return sigUrlSafe;
51
- };
52
- //# sourceMappingURL=hmac.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hmac.js","sourceRoot":"","sources":["../../src/signing/hmac.ts"],"names":[],"mappings":"AAAA,SAAS,UAAU,CAAC,CAAS,EAAE,MAAc,EAAE,OAAe;IAC1D,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAAC,MAAc;IACvC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CA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e,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;IACnF,MAAM,GAAG,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAC;IAEjD,qEAAqE;IACrE,qBAAqB;IACrB,qBAAqB;IACrB,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IACnE,OAAO,UAAU,CAAC;AACtB,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from "./eip712.ts";
2
- export * from "./hmac.ts";
@@ -1,3 +0,0 @@
1
- export * from "./eip712.js";
2
- export * from "./hmac.js";
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/signing/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}