@n1xyz/nord-ts 0.0.15 → 0.0.17

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 (195) hide show
  1. package/dist/bridge/client.js +45 -6
  2. package/dist/gen/common.js +1 -1
  3. package/dist/gen/nord.d.ts +61 -29
  4. package/dist/gen/nord.js +723 -130
  5. package/dist/idl/bridge.d.ts +569 -2
  6. package/dist/idl/bridge.js +5 -927
  7. package/dist/idl/bridge.json +75 -62
  8. package/dist/idl/index.d.ts +71 -49
  9. package/dist/index.d.ts +1 -3
  10. package/dist/index.js +6 -13
  11. package/dist/nord/api/actions.d.ts +7 -2
  12. package/dist/nord/api/actions.js +7 -1
  13. package/dist/nord/api/core.d.ts +1 -1
  14. package/dist/nord/api/core.js +3 -3
  15. package/dist/nord/api/market.js +1 -3
  16. package/dist/nord/api/queries.js +2 -2
  17. package/dist/nord/client/Nord.d.ts +9 -14
  18. package/dist/nord/client/Nord.js +27 -38
  19. package/dist/nord/client/NordUser.d.ts +7 -23
  20. package/dist/nord/client/NordUser.js +79 -151
  21. package/dist/nord/utils/NordError.js +5 -2
  22. package/dist/types.d.ts +34 -50
  23. package/dist/utils.d.ts +2 -0
  24. package/dist/utils.js +14 -0
  25. package/dist/websocket/NordWebSocketClient.js +0 -2
  26. package/package.json +20 -18
  27. package/protoc-generate.sh +0 -0
  28. package/src/idl/bridge.json +75 -62
  29. package/src/index.ts +9 -12
  30. package/src/nord/api/actions.ts +14 -3
  31. package/src/nord/api/core.ts +4 -2
  32. package/src/nord/api/market.ts +1 -4
  33. package/src/nord/api/queries.ts +2 -2
  34. package/src/nord/client/Nord.ts +45 -50
  35. package/src/nord/client/NordUser.ts +107 -178
  36. package/src/nord/utils/NordError.ts +6 -2
  37. package/src/types.ts +34 -49
  38. package/src/utils.ts +18 -0
  39. package/src/websocket/NordWebSocketClient.ts +0 -2
  40. package/tsconfig.json +1 -1
  41. package/docs/.nojekyll +0 -1
  42. package/docs/assets/hierarchy.js +0 -1
  43. package/docs/assets/highlight.css +0 -92
  44. package/docs/assets/icons.js +0 -18
  45. package/docs/assets/icons.svg +0 -1
  46. package/docs/assets/main.js +0 -60
  47. package/docs/assets/navigation.js +0 -1
  48. package/docs/assets/search.js +0 -1
  49. package/docs/assets/style.css +0 -1611
  50. package/docs/classes/Nord.html +0 -189
  51. package/docs/classes/NordError.html +0 -24
  52. package/docs/classes/NordUser.html +0 -115
  53. package/docs/classes/NordWebSocketClient.html +0 -330
  54. package/docs/classes/SolanaBridgeClient.html +0 -86
  55. package/docs/classes/Subscriber.html +0 -10
  56. package/docs/enums/FillMode.html +0 -5
  57. package/docs/enums/KeyType.html +0 -4
  58. package/docs/enums/MetricPeriod.html +0 -9
  59. package/docs/enums/PdaSeedType.html +0 -9
  60. package/docs/enums/PeakTpsPeriodUnit.html +0 -15
  61. package/docs/enums/Side.html +0 -3
  62. package/docs/enums/WebSocketMessageType.html +0 -7
  63. package/docs/functions/actionQueryRollman.html +0 -6
  64. package/docs/functions/actionsQueryRollman.html +0 -6
  65. package/docs/functions/aggregateMetrics-1.html +0 -7
  66. package/docs/functions/assert.html +0 -1
  67. package/docs/functions/bigIntToProtoU128.html +0 -4
  68. package/docs/functions/bridgeToBN.html +0 -5
  69. package/docs/functions/bufferToHex.html +0 -4
  70. package/docs/functions/cancelOrder.html +0 -1
  71. package/docs/functions/checkPubKeyLength.html +0 -1
  72. package/docs/functions/checkedFetch.html +0 -6
  73. package/docs/functions/createSession.html +0 -1
  74. package/docs/functions/decodeLengthDelimited.html +0 -11
  75. package/docs/functions/encodeLengthDelimited.html +0 -6
  76. package/docs/functions/fillModeToProtoFillMode.html +0 -5
  77. package/docs/functions/findMarket.html +0 -1
  78. package/docs/functions/findPda.html +0 -6
  79. package/docs/functions/findToken.html +0 -1
  80. package/docs/functions/fromBN.html +0 -5
  81. package/docs/functions/getAccount.html +0 -6
  82. package/docs/functions/getActionNonce.html +0 -5
  83. package/docs/functions/getCurrentTps.html +0 -6
  84. package/docs/functions/getInfo.html +0 -5
  85. package/docs/functions/getLastActionId.html +0 -5
  86. package/docs/functions/getMedianLatency.html +0 -6
  87. package/docs/functions/getOrderbook.html +0 -6
  88. package/docs/functions/getPeakTps.html +0 -6
  89. package/docs/functions/getTimestamp.html +0 -5
  90. package/docs/functions/getTotalTransactions.html +0 -5
  91. package/docs/functions/getTrades.html +0 -6
  92. package/docs/functions/getUserAccountIds.html +0 -6
  93. package/docs/functions/hexToBuffer.html +0 -4
  94. package/docs/functions/initWebSocketClient.html +0 -12
  95. package/docs/functions/keypairFromPrivateKey.html +0 -4
  96. package/docs/functions/makeSigningFunction.html +0 -4
  97. package/docs/functions/makeWalletSignFn.html +0 -6
  98. package/docs/functions/marketsStats.html +0 -5
  99. package/docs/functions/optExpect.html +0 -5
  100. package/docs/functions/optMap.html +0 -5
  101. package/docs/functions/optUnwrap.html +0 -2
  102. package/docs/functions/panic.html +0 -1
  103. package/docs/functions/placeOrder.html +0 -1
  104. package/docs/functions/queryAction.html +0 -6
  105. package/docs/functions/queryPrometheus.html +0 -6
  106. package/docs/functions/queryRecentActions.html +0 -7
  107. package/docs/functions/revokeSession.html +0 -1
  108. package/docs/functions/shortenPublicKey.html +0 -5
  109. package/docs/functions/signAction.html +0 -6
  110. package/docs/functions/toBN.html +0 -5
  111. package/docs/functions/toScaledU128.html +0 -8
  112. package/docs/functions/toScaledU64.html +0 -8
  113. package/docs/functions/transfer.html +0 -1
  114. package/docs/functions/withdraw.html +0 -1
  115. package/docs/hierarchy.html +0 -1
  116. package/docs/index.html +0 -40
  117. package/docs/interfaces/Account.html +0 -8
  118. package/docs/interfaces/ActionInfo.html +0 -8
  119. package/docs/interfaces/ActionNonceResponse.html +0 -3
  120. package/docs/interfaces/ActionQuery.html +0 -4
  121. package/docs/interfaces/ActionResponse.html +0 -8
  122. package/docs/interfaces/ActionsExtendedInfo.html +0 -10
  123. package/docs/interfaces/ActionsQuery.html +0 -5
  124. package/docs/interfaces/ActionsResponse.html +0 -6
  125. package/docs/interfaces/AggregateMetrics.html +0 -12
  126. package/docs/interfaces/BlockFacts.html +0 -10
  127. package/docs/interfaces/BlockQuery.html +0 -6
  128. package/docs/interfaces/BlockResponse.html +0 -6
  129. package/docs/interfaces/BlockSummary.html +0 -8
  130. package/docs/interfaces/BlockSummaryResponse.html +0 -6
  131. package/docs/interfaces/DeltaEvent.html +0 -6
  132. package/docs/interfaces/DepositSplParams.html +0 -10
  133. package/docs/interfaces/Info.html +0 -3
  134. package/docs/interfaces/Market.html +0 -8
  135. package/docs/interfaces/MarketStats.html +0 -7
  136. package/docs/interfaces/MarketsStatsResponse.html +0 -2
  137. package/docs/interfaces/NordConfig.html +0 -24
  138. package/docs/interfaces/NordWebSocketClientEvents.html +0 -4
  139. package/docs/interfaces/NordWebSocketEvents.html +0 -8
  140. package/docs/interfaces/Order.html +0 -6
  141. package/docs/interfaces/OrderInfo.html +0 -6
  142. package/docs/interfaces/OrderbookEntry.html +0 -4
  143. package/docs/interfaces/OrderbookQuery.html +0 -6
  144. package/docs/interfaces/OrderbookResponse.html +0 -6
  145. package/docs/interfaces/OrderbookSubscription.html +0 -159
  146. package/docs/interfaces/PerpMarketStats.html +0 -5
  147. package/docs/interfaces/RollmanActionExtendedInfo.html +0 -4
  148. package/docs/interfaces/RollmanActionInfo.html +0 -4
  149. package/docs/interfaces/RollmanActionResponse.html +0 -4
  150. package/docs/interfaces/RollmanActionsResponse.html +0 -2
  151. package/docs/interfaces/RollmanBlockResponse.html +0 -3
  152. package/docs/interfaces/SPLTokenInfo.html +0 -10
  153. package/docs/interfaces/SolanaBridgeConfig.html +0 -10
  154. package/docs/interfaces/StateFacts.html +0 -10
  155. package/docs/interfaces/SubscriberConfig.html +0 -3
  156. package/docs/interfaces/TimestampResponse.html +0 -3
  157. package/docs/interfaces/Token.html +0 -5
  158. package/docs/interfaces/TokenInfo.html +0 -6
  159. package/docs/interfaces/Trade.html +0 -5
  160. package/docs/interfaces/TradeSubscription.html +0 -159
  161. package/docs/interfaces/Trades.html +0 -5
  162. package/docs/interfaces/TradesQuery.html +0 -6
  163. package/docs/interfaces/TradesResponse.html +0 -7
  164. package/docs/interfaces/TransferParams.html +0 -8
  165. package/docs/interfaces/UserAccountIdsQuery.html +0 -3
  166. package/docs/interfaces/UserAccountIdsResponse.html +0 -3
  167. package/docs/interfaces/WebSocketAccountUpdate.html +0 -6
  168. package/docs/interfaces/WebSocketDeltaUpdate.html +0 -9
  169. package/docs/interfaces/WebSocketSubscription.html +0 -4
  170. package/docs/interfaces/WebSocketTradeUpdate.html +0 -6
  171. package/docs/interfaces/WithdrawalClaim.html +0 -14
  172. package/docs/interfaces/WithdrawalParams.html +0 -8
  173. package/docs/modules.html +0 -1
  174. package/docs/types/BigIntValue.html +0 -2
  175. package/docs/types/SubscriptionPattern.html +0 -4
  176. package/docs/types/SubscriptionType.html +0 -2
  177. package/docs/types/WebSocketMessage.html +0 -1
  178. package/docs/variables/DEBUG_KEYS.html +0 -1
  179. package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +0 -1
  180. package/docs/variables/DEV_TOKEN_INFOS.html +0 -1
  181. package/docs/variables/DEV_URL.html +0 -1
  182. package/docs/variables/MAX_BUFFER_LEN.html +0 -1
  183. package/docs/variables/SESSION_TTL.html +0 -1
  184. package/docs/variables/WEBSERVER_DEV_URL.html +0 -1
  185. package/docs/variables/ZERO_DECIMAL.html +0 -1
  186. package/docs/variables/_private.html +0 -2
  187. package/idl-generate.sh +0 -4
  188. package/src/bridge/client.ts +0 -498
  189. package/src/bridge/const.ts +0 -53
  190. package/src/bridge/index.ts +0 -6
  191. package/src/bridge/types.ts +0 -129
  192. package/src/bridge/utils.ts +0 -140
  193. package/src/gen/common.ts +0 -297
  194. package/src/gen/nord.ts +0 -6723
  195. package/src/idl/index.ts +0 -2
@@ -1,140 +0,0 @@
1
- import { Keypair, PublicKey } from "@solana/web3.js";
2
- import { BN } from "@coral-xyz/anchor";
3
- import bs58 from "bs58";
4
- import { PdaSeedType } from "./types";
5
-
6
- /**
7
- * Convert a private key string to a Solana Keypair
8
- *
9
- * @param privateKey Private key as base58 string, hex string, or Uint8Array
10
- * @returns Solana Keypair
11
- */
12
- export function keypairFromPrivateKey(
13
- privateKey: string | Uint8Array,
14
- ): Keypair {
15
- if (typeof privateKey === "string") {
16
- // Check if it's a base58 encoded string
17
- if (!privateKey.startsWith("0x")) {
18
- return Keypair.fromSecretKey(bs58.decode(privateKey));
19
- }
20
-
21
- // It's a hex string
22
- const hex = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
23
- const bytes = new Uint8Array(
24
- hex.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16)),
25
- );
26
- return Keypair.fromSecretKey(bytes);
27
- }
28
-
29
- // It's already a Uint8Array
30
- return Keypair.fromSecretKey(privateKey);
31
- }
32
-
33
- /**
34
- * Create a signing function for Solana transactions
35
- *
36
- * @param keypair Solana keypair
37
- * @returns Signing function
38
- */
39
- export function makeSigningFunction(keypair: Keypair) {
40
- return async (_message: Uint8Array): Promise<Uint8Array> => {
41
- // Use the correct API for signing with a Keypair
42
- const signature = keypair.secretKey.slice(0, 32);
43
- const publicKey = keypair.publicKey.toBytes();
44
-
45
- // This is a simplified version - in a real implementation, you would use proper signing
46
- // For now, we're just returning a placeholder signature
47
- return new Uint8Array([...signature, ...publicKey].slice(0, 64));
48
- };
49
- }
50
-
51
- /**
52
- * Convert a number to a BN with the specified number of decimals
53
- *
54
- * @param amount Amount as a number
55
- * @param decimals Number of decimals
56
- * @returns BN representation of the amount
57
- */
58
- export function bridgeToBN(amount: number, decimals: number): BN {
59
- const factor = Math.pow(10, decimals);
60
- const amountBN = new BN(Math.floor(amount * factor));
61
- return amountBN;
62
- }
63
-
64
- /**
65
- * Format a BN as a human-readable number with the specified number of decimals
66
- *
67
- * @param amount Amount as a BN
68
- * @param decimals Number of decimals
69
- * @returns Formatted number
70
- */
71
- export function fromBN(amount: BN, decimals: number): number {
72
- const factor = Math.pow(10, decimals);
73
- return amount.toNumber() / factor;
74
- }
75
-
76
- /**
77
- * Derive a PDA (Program Derived Address) for the given seeds
78
- *
79
- * @param programId Program ID
80
- * @param type PDA seed type
81
- * @param seeds Additional seeds
82
- * @returns [PDA, bump]
83
- */
84
- export function findPda(
85
- programId: PublicKey,
86
- type: PdaSeedType,
87
- ...seeds: (Buffer | PublicKey | string | number)[]
88
- ): [PublicKey, number] {
89
- const seedBuffers = [
90
- Buffer.from(type),
91
- ...seeds.map((seed) => {
92
- if (seed instanceof PublicKey) {
93
- return seed.toBuffer();
94
- } else if (typeof seed === "string") {
95
- return Buffer.from(seed);
96
- } else if (typeof seed === "number") {
97
- return Buffer.from([seed]);
98
- }
99
- return seed;
100
- }),
101
- ];
102
-
103
- return PublicKey.findProgramAddressSync(seedBuffers, programId);
104
- }
105
-
106
- /**
107
- * Convert a buffer to a hex string
108
- *
109
- * @param buffer Buffer to convert
110
- * @returns Hex string
111
- */
112
- export function bufferToHex(buffer: Buffer | Uint8Array): string {
113
- return "0x" + Buffer.from(buffer).toString("hex");
114
- }
115
-
116
- /**
117
- * Convert a hex string to a buffer
118
- *
119
- * @param hex Hex string
120
- * @returns Buffer
121
- */
122
- export function hexToBuffer(hex: string): Buffer {
123
- const hexString = hex.startsWith("0x") ? hex.slice(2) : hex;
124
- return Buffer.from(hexString, "hex");
125
- }
126
-
127
- /**
128
- * Shorten a public key for display
129
- *
130
- * @param publicKey Public key to shorten
131
- * @param chars Number of characters to show at the beginning and end
132
- * @returns Shortened public key
133
- */
134
- export function shortenPublicKey(
135
- publicKey: PublicKey | string,
136
- chars = 4,
137
- ): string {
138
- const key = typeof publicKey === "string" ? publicKey : publicKey.toBase58();
139
- return `${key.slice(0, chars)}...${key.slice(-chars)}`;
140
- }
package/src/gen/common.ts DELETED
@@ -1,297 +0,0 @@
1
- // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
2
- // versions:
3
- // protoc-gen-ts_proto v2.7.0
4
- // protoc v3.21.12
5
- // source: common.proto
6
-
7
- /* eslint-disable */
8
- import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
9
-
10
- export const protobufPackage = "common";
11
-
12
- export interface Message {
13
- kind?:
14
- | //
15
- /**
16
- * there are many things to come here, that why enum,
17
- * from list abi calls, nfts, multi asset transfer
18
- */
19
- { $case: "transfer"; value: Message_Transfer }
20
- | undefined;
21
- }
22
-
23
- /**
24
- * Message sent by user to app to move funds out of app, `withdraw`.
25
- * Receiver side considers it `route` or `deposit`.
26
- */
27
- export interface Message_Transfer {
28
- /** Token id as registered on L1 chain settlement */
29
- tokenId: number;
30
- /**
31
- * User public key from L1 which he used for deposits
32
- * This address will be used to deposit onto L1 or L2 target,
33
- * Target is "here", as soon as ther are no `channel_id`s remaining.
34
- */
35
- userPubkey: Uint8Array;
36
- amount: bigint;
37
- /**
38
- * Numeric identifiers of channels to traverse.
39
- *
40
- * Message removed first channel_id in list,
41
- * and sent remaining message to "removed" channel.
42
- *
43
- * If received by app via channel and no channels defined,
44
- * deposit target this app ("here").
45
- *
46
- * If it is direct user input and no channels defined, default route is used: q
47
- * to Gate on Nord, to L1 on Gate, and to Gate on L1.
48
- */
49
- channelId: number[];
50
- }
51
-
52
- function createBaseMessage(): Message {
53
- return { kind: undefined };
54
- }
55
-
56
- export const Message: MessageFns<Message> = {
57
- encode(message: Message, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
58
- switch (message.kind?.$case) {
59
- case "transfer":
60
- Message_Transfer.encode(message.kind.value, writer.uint32(10).fork()).join();
61
- break;
62
- }
63
- return writer;
64
- },
65
-
66
- decode(input: BinaryReader | Uint8Array, length?: number): Message {
67
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
68
- let end = length === undefined ? reader.len : reader.pos + length;
69
- const message = createBaseMessage();
70
- while (reader.pos < end) {
71
- const tag = reader.uint32();
72
- switch (tag >>> 3) {
73
- case 1: {
74
- if (tag !== 10) {
75
- break;
76
- }
77
-
78
- message.kind = { $case: "transfer", value: Message_Transfer.decode(reader, reader.uint32()) };
79
- continue;
80
- }
81
- }
82
- if ((tag & 7) === 4 || tag === 0) {
83
- break;
84
- }
85
- reader.skip(tag & 7);
86
- }
87
- return message;
88
- },
89
-
90
- fromJSON(object: any): Message {
91
- return {
92
- kind: isSet(object.transfer)
93
- ? { $case: "transfer", value: Message_Transfer.fromJSON(object.transfer) }
94
- : undefined,
95
- };
96
- },
97
-
98
- toJSON(message: Message): unknown {
99
- const obj: any = {};
100
- if (message.kind?.$case === "transfer") {
101
- obj.transfer = Message_Transfer.toJSON(message.kind.value);
102
- }
103
- return obj;
104
- },
105
-
106
- create<I extends Exact<DeepPartial<Message>, I>>(base?: I): Message {
107
- return Message.fromPartial(base ?? ({} as any));
108
- },
109
- fromPartial<I extends Exact<DeepPartial<Message>, I>>(object: I): Message {
110
- const message = createBaseMessage();
111
- switch (object.kind?.$case) {
112
- case "transfer": {
113
- if (object.kind?.value !== undefined && object.kind?.value !== null) {
114
- message.kind = { $case: "transfer", value: Message_Transfer.fromPartial(object.kind.value) };
115
- }
116
- break;
117
- }
118
- }
119
- return message;
120
- },
121
- };
122
-
123
- function createBaseMessage_Transfer(): Message_Transfer {
124
- return { tokenId: 0, userPubkey: new Uint8Array(0), amount: 0n, channelId: [] };
125
- }
126
-
127
- export const Message_Transfer: MessageFns<Message_Transfer> = {
128
- encode(message: Message_Transfer, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
129
- if (message.tokenId !== 0) {
130
- writer.uint32(8).uint32(message.tokenId);
131
- }
132
- if (message.userPubkey.length !== 0) {
133
- writer.uint32(18).bytes(message.userPubkey);
134
- }
135
- if (message.amount !== 0n) {
136
- if (BigInt.asUintN(64, message.amount) !== message.amount) {
137
- throw new globalThis.Error("value provided for field message.amount of type uint64 too large");
138
- }
139
- writer.uint32(24).uint64(message.amount);
140
- }
141
- writer.uint32(58).fork();
142
- for (const v of message.channelId) {
143
- writer.uint32(v);
144
- }
145
- writer.join();
146
- return writer;
147
- },
148
-
149
- decode(input: BinaryReader | Uint8Array, length?: number): Message_Transfer {
150
- const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
151
- let end = length === undefined ? reader.len : reader.pos + length;
152
- const message = createBaseMessage_Transfer();
153
- while (reader.pos < end) {
154
- const tag = reader.uint32();
155
- switch (tag >>> 3) {
156
- case 1: {
157
- if (tag !== 8) {
158
- break;
159
- }
160
-
161
- message.tokenId = reader.uint32();
162
- continue;
163
- }
164
- case 2: {
165
- if (tag !== 18) {
166
- break;
167
- }
168
-
169
- message.userPubkey = reader.bytes();
170
- continue;
171
- }
172
- case 3: {
173
- if (tag !== 24) {
174
- break;
175
- }
176
-
177
- message.amount = reader.uint64() as bigint;
178
- continue;
179
- }
180
- case 7: {
181
- if (tag === 56) {
182
- message.channelId.push(reader.uint32());
183
-
184
- continue;
185
- }
186
-
187
- if (tag === 58) {
188
- const end2 = reader.uint32() + reader.pos;
189
- while (reader.pos < end2) {
190
- message.channelId.push(reader.uint32());
191
- }
192
-
193
- continue;
194
- }
195
-
196
- break;
197
- }
198
- }
199
- if ((tag & 7) === 4 || tag === 0) {
200
- break;
201
- }
202
- reader.skip(tag & 7);
203
- }
204
- return message;
205
- },
206
-
207
- fromJSON(object: any): Message_Transfer {
208
- return {
209
- tokenId: isSet(object.tokenId) ? globalThis.Number(object.tokenId) : 0,
210
- userPubkey: isSet(object.userPubkey) ? bytesFromBase64(object.userPubkey) : new Uint8Array(0),
211
- amount: isSet(object.amount) ? BigInt(object.amount) : 0n,
212
- channelId: globalThis.Array.isArray(object?.channelId)
213
- ? object.channelId.map((e: any) => globalThis.Number(e))
214
- : [],
215
- };
216
- },
217
-
218
- toJSON(message: Message_Transfer): unknown {
219
- const obj: any = {};
220
- if (message.tokenId !== 0) {
221
- obj.tokenId = Math.round(message.tokenId);
222
- }
223
- if (message.userPubkey.length !== 0) {
224
- obj.userPubkey = base64FromBytes(message.userPubkey);
225
- }
226
- if (message.amount !== 0n) {
227
- obj.amount = message.amount.toString();
228
- }
229
- if (message.channelId?.length) {
230
- obj.channelId = message.channelId.map((e) => Math.round(e));
231
- }
232
- return obj;
233
- },
234
-
235
- create<I extends Exact<DeepPartial<Message_Transfer>, I>>(base?: I): Message_Transfer {
236
- return Message_Transfer.fromPartial(base ?? ({} as any));
237
- },
238
- fromPartial<I extends Exact<DeepPartial<Message_Transfer>, I>>(object: I): Message_Transfer {
239
- const message = createBaseMessage_Transfer();
240
- message.tokenId = object.tokenId ?? 0;
241
- message.userPubkey = object.userPubkey ?? new Uint8Array(0);
242
- message.amount = object.amount ?? 0n;
243
- message.channelId = object.channelId?.map((e) => e) || [];
244
- return message;
245
- },
246
- };
247
-
248
- function bytesFromBase64(b64: string): Uint8Array {
249
- if ((globalThis as any).Buffer) {
250
- return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
251
- } else {
252
- const bin = globalThis.atob(b64);
253
- const arr = new Uint8Array(bin.length);
254
- for (let i = 0; i < bin.length; ++i) {
255
- arr[i] = bin.charCodeAt(i);
256
- }
257
- return arr;
258
- }
259
- }
260
-
261
- function base64FromBytes(arr: Uint8Array): string {
262
- if ((globalThis as any).Buffer) {
263
- return globalThis.Buffer.from(arr).toString("base64");
264
- } else {
265
- const bin: string[] = [];
266
- arr.forEach((byte) => {
267
- bin.push(globalThis.String.fromCharCode(byte));
268
- });
269
- return globalThis.btoa(bin.join(""));
270
- }
271
- }
272
-
273
- type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
274
-
275
- export type DeepPartial<T> = T extends Builtin ? T
276
- : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
277
- : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
278
- : T extends { $case: string; value: unknown } ? { $case: T["$case"]; value?: DeepPartial<T["value"]> }
279
- : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
280
- : Partial<T>;
281
-
282
- type KeysOfUnion<T> = T extends T ? keyof T : never;
283
- export type Exact<P, I extends P> = P extends Builtin ? P
284
- : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
285
-
286
- function isSet(value: any): boolean {
287
- return value !== null && value !== undefined;
288
- }
289
-
290
- export interface MessageFns<T> {
291
- encode(message: T, writer?: BinaryWriter): BinaryWriter;
292
- decode(input: BinaryReader | Uint8Array, length?: number): T;
293
- fromJSON(object: any): T;
294
- toJSON(message: T): unknown;
295
- create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
296
- fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
297
- }