@andy-liquid-labs/lighter-ts-sdk 1.0.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.
- package/README.md +381 -0
- package/dist/index.d.mts +3686 -0
- package/dist/index.d.ts +3686 -0
- package/dist/index.js +6168 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5939 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -0
- package/src/api/exchange/change-account-tier.ts +38 -0
- package/src/api/exchange/fastwithdraw.ts +38 -0
- package/src/api/exchange/index.ts +7 -0
- package/src/api/exchange/notification-ack.ts +36 -0
- package/src/api/exchange/send-tx-batch.ts +53 -0
- package/src/api/exchange/send-tx.ts +105 -0
- package/src/api/exchange/tokens-create.ts +50 -0
- package/src/api/exchange/tokens-revoke.ts +38 -0
- package/src/api/index.ts +3 -0
- package/src/api/info/account-by-l1-address.ts +23 -0
- package/src/api/info/account.ts +80 -0
- package/src/api/info/announcement.ts +24 -0
- package/src/api/info/api-keys.ts +32 -0
- package/src/api/info/asset-details.ts +42 -0
- package/src/api/info/candles.ts +31 -0
- package/src/api/info/exchange-stats.ts +16 -0
- package/src/api/info/fastbridge-info.ts +15 -0
- package/src/api/info/funding-rates.ts +22 -0
- package/src/api/info/fundings.ts +29 -0
- package/src/api/info/index.ts +20 -0
- package/src/api/info/next-nonce.ts +26 -0
- package/src/api/info/order-book-details.ts +125 -0
- package/src/api/info/order-books.ts +23 -0
- package/src/api/info/recent-trades.ts +24 -0
- package/src/api/info/root-info.ts +13 -0
- package/src/api/info/root-status.ts +13 -0
- package/src/api/info/tx-from-l1-hash.ts +20 -0
- package/src/api/info/tx.ts +45 -0
- package/src/api/info/txs.ts +19 -0
- package/src/api/info/withdrawal-delay.ts +13 -0
- package/src/api/info-private/account-active-orders.ts +31 -0
- package/src/api/info-private/account-inactive-orders.ts +83 -0
- package/src/api/info-private/account-limits.ts +35 -0
- package/src/api/info-private/account-metadata.ts +43 -0
- package/src/api/info-private/deposit-history.ts +49 -0
- package/src/api/info-private/export.ts +41 -0
- package/src/api/info-private/fastwithdraw-info.ts +35 -0
- package/src/api/info-private/index.ts +18 -0
- package/src/api/info-private/l1-metadata.ts +35 -0
- package/src/api/info-private/liquidations.ts +96 -0
- package/src/api/info-private/pnl.ts +52 -0
- package/src/api/info-private/position-funding.ts +54 -0
- package/src/api/info-private/public-pools-metadata.ts +46 -0
- package/src/api/info-private/referral-points.ts +43 -0
- package/src/api/info-private/tokens.ts +44 -0
- package/src/api/info-private/trades.ts +66 -0
- package/src/api/info-private/transfer-fee-info.ts +37 -0
- package/src/api/info-private/transfer-history.ts +54 -0
- package/src/api/info-private/withdraw-history.ts +49 -0
- package/src/client/clientManager.ts +121 -0
- package/src/client/exchange-client.ts +637 -0
- package/src/client/http/client.ts +137 -0
- package/src/client/http/index.ts +6 -0
- package/src/client/http/interface.ts +89 -0
- package/src/client/index.ts +11 -0
- package/src/client/info-client.ts +383 -0
- package/src/client/info-private-client.ts +444 -0
- package/src/client/txClient.ts +597 -0
- package/src/client/ws-client.ts +457 -0
- package/src/crypto/ecgfp5.ts +722 -0
- package/src/crypto/goldilocks.ts +136 -0
- package/src/crypto/gorand.ts +777 -0
- package/src/crypto/index.ts +6 -0
- package/src/crypto/poseidon2.ts +365 -0
- package/src/crypto/scalar.ts +375 -0
- package/src/index.ts +112 -0
- package/src/signer/index.ts +5 -0
- package/src/signer/keyManager.ts +132 -0
- package/src/types/bridge.ts +24 -0
- package/src/types/constants.ts +252 -0
- package/src/types/errors.ts +168 -0
- package/src/types/index.ts +12 -0
- package/src/types/requests.ts +197 -0
- package/src/types/txInfo.ts +1277 -0
- package/src/types/txInfoPools.ts +502 -0
- package/src/types/txInfoSerializer.ts +348 -0
- package/src/types/ws.ts +407 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goldilocks Prime Field implementation
|
|
3
|
+
* Field modulus: p = 2^64 - 2^32 + 1
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const GOLDILOCKS_MODULUS = 0xffffffff00000001n;
|
|
7
|
+
|
|
8
|
+
export function toCanonicalUint64(x: bigint): bigint {
|
|
9
|
+
return x >= GOLDILOCKS_MODULUS ? x - GOLDILOCKS_MODULUS : x;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Goldilocks field element
|
|
14
|
+
*/
|
|
15
|
+
export class GoldilocksElement {
|
|
16
|
+
readonly value: bigint;
|
|
17
|
+
|
|
18
|
+
constructor(value: bigint) {
|
|
19
|
+
this.value = mod(value, GOLDILOCKS_MODULUS);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
add(other: GoldilocksElement): GoldilocksElement {
|
|
23
|
+
return new GoldilocksElement(this.value + other.value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
sub(other: GoldilocksElement): GoldilocksElement {
|
|
27
|
+
return new GoldilocksElement(this.value - other.value + GOLDILOCKS_MODULUS);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
mul(other: GoldilocksElement): GoldilocksElement {
|
|
31
|
+
return new GoldilocksElement(this.value * other.value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
square(): GoldilocksElement {
|
|
35
|
+
return this.mul(this);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static fromUint32(value: number): GoldilocksElement {
|
|
39
|
+
return new GoldilocksElement(BigInt(value >>> 0));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static fromInt64(value: bigint): GoldilocksElement {
|
|
43
|
+
// Handle signed values
|
|
44
|
+
if (value < 0n) {
|
|
45
|
+
return new GoldilocksElement(value + GOLDILOCKS_MODULUS);
|
|
46
|
+
}
|
|
47
|
+
return new GoldilocksElement(value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static fromUint64(value: bigint): GoldilocksElement {
|
|
51
|
+
return new GoldilocksElement(value & 0xffffffffffffffffn);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static zero(): GoldilocksElement {
|
|
55
|
+
return new GoldilocksElement(0n);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static one(): GoldilocksElement {
|
|
59
|
+
return new GoldilocksElement(1n);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
toLittleEndianBytes(): Uint8Array {
|
|
63
|
+
const bytes = new Uint8Array(8);
|
|
64
|
+
let val = this.value;
|
|
65
|
+
for (let i = 0; i < 8; i++) {
|
|
66
|
+
bytes[i] = Number(val & 0xffn);
|
|
67
|
+
val >>= 8n;
|
|
68
|
+
}
|
|
69
|
+
return bytes;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static fromLittleEndianBytes(bytes: Uint8Array): GoldilocksElement {
|
|
73
|
+
let value = 0n;
|
|
74
|
+
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
75
|
+
value = (value << 8n) | BigInt(bytes[i]);
|
|
76
|
+
}
|
|
77
|
+
return new GoldilocksElement(value);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Modular reduction
|
|
83
|
+
*/
|
|
84
|
+
function mod(a: bigint, m: bigint): bigint {
|
|
85
|
+
const result = a % m;
|
|
86
|
+
return result >= 0n ? result : result + m;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Convert bytes to Goldilocks field elements
|
|
91
|
+
* Each element holds up to 7 bytes of data
|
|
92
|
+
*/
|
|
93
|
+
export function bytesToFieldElements(bytes: Uint8Array): GoldilocksElement[] {
|
|
94
|
+
const elements: GoldilocksElement[] = [];
|
|
95
|
+
const bytesPerElement = 7;
|
|
96
|
+
|
|
97
|
+
for (let i = 0; i < bytes.length; i += bytesPerElement) {
|
|
98
|
+
const chunk = bytes.slice(i, Math.min(i + bytesPerElement, bytes.length));
|
|
99
|
+
let value = 0n;
|
|
100
|
+
for (let j = chunk.length - 1; j >= 0; j--) {
|
|
101
|
+
value = (value << 8n) | BigInt(chunk[j]);
|
|
102
|
+
}
|
|
103
|
+
elements.push(new GoldilocksElement(value));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return elements;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Convert bytes to Goldilocks field elements using canonical little-endian
|
|
111
|
+
* 8-byte chunks, matching ArrayFromCanonicalLittleEndianBytes in Go.
|
|
112
|
+
*/
|
|
113
|
+
export function bytesToFieldElementsCanonicalLE(
|
|
114
|
+
bytes: Uint8Array,
|
|
115
|
+
): GoldilocksElement[] {
|
|
116
|
+
const elements: GoldilocksElement[] = [];
|
|
117
|
+
const bytesPerElement = 8;
|
|
118
|
+
|
|
119
|
+
for (let i = 0; i < bytes.length; i += bytesPerElement) {
|
|
120
|
+
const chunk = bytes.slice(i, Math.min(i + bytesPerElement, bytes.length));
|
|
121
|
+
let value = 0n;
|
|
122
|
+
for (let j = chunk.length - 1; j >= 0; j--) {
|
|
123
|
+
value = (value << 8n) | BigInt(chunk[j]);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (value >= GOLDILOCKS_MODULUS) {
|
|
127
|
+
throw new Error(
|
|
128
|
+
`Non-canonical Goldilocks element from bytes: ${value.toString(16)}`,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
elements.push(new GoldilocksElement(value));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return elements;
|
|
136
|
+
}
|