hive-stream 3.0.0 → 3.0.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 (107) hide show
  1. package/AGENTS.md +35 -0
  2. package/DOCUMENTATION.md +396 -0
  3. package/README.md +160 -39
  4. package/dist/actions.d.ts +3 -3
  5. package/dist/actions.js +7 -7
  6. package/dist/actions.js.map +1 -1
  7. package/dist/adapters/base.adapter.d.ts +19 -1
  8. package/dist/adapters/base.adapter.js +16 -0
  9. package/dist/adapters/base.adapter.js.map +1 -1
  10. package/dist/adapters/mongodb.adapter.d.ts +5 -11
  11. package/dist/adapters/mongodb.adapter.js +10 -10
  12. package/dist/adapters/mongodb.adapter.js.map +1 -1
  13. package/dist/adapters/postgresql.adapter.d.ts +17 -0
  14. package/dist/adapters/postgresql.adapter.js +99 -8
  15. package/dist/adapters/postgresql.adapter.js.map +1 -1
  16. package/dist/adapters/sqlite.adapter.d.ts +17 -0
  17. package/dist/adapters/sqlite.adapter.js +99 -8
  18. package/dist/adapters/sqlite.adapter.js.map +1 -1
  19. package/dist/api.js +86 -0
  20. package/dist/api.js.map +1 -1
  21. package/dist/config.d.ts +26 -0
  22. package/dist/config.js +76 -4
  23. package/dist/config.js.map +1 -1
  24. package/dist/contracts/coinflip.contract.d.ts +8 -26
  25. package/dist/contracts/coinflip.contract.js +123 -144
  26. package/dist/contracts/coinflip.contract.js.map +1 -1
  27. package/dist/contracts/contract.d.ts +3 -0
  28. package/dist/contracts/contract.js +26 -0
  29. package/dist/contracts/contract.js.map +1 -0
  30. package/dist/contracts/dice.contract.d.ts +9 -36
  31. package/dist/contracts/dice.contract.js +135 -200
  32. package/dist/contracts/dice.contract.js.map +1 -1
  33. package/dist/contracts/exchange.contract.d.ts +11 -0
  34. package/dist/contracts/exchange.contract.js +492 -0
  35. package/dist/contracts/exchange.contract.js.map +1 -0
  36. package/dist/contracts/lotto.contract.d.ts +15 -19
  37. package/dist/contracts/lotto.contract.js +154 -162
  38. package/dist/contracts/lotto.contract.js.map +1 -1
  39. package/dist/contracts/nft.contract.d.ts +4 -0
  40. package/dist/contracts/nft.contract.js +65 -0
  41. package/dist/contracts/nft.contract.js.map +1 -1
  42. package/dist/contracts/poll.contract.d.ts +4 -0
  43. package/dist/contracts/poll.contract.js +105 -0
  44. package/dist/contracts/poll.contract.js.map +1 -0
  45. package/dist/contracts/rps.contract.d.ts +9 -0
  46. package/dist/contracts/rps.contract.js +217 -0
  47. package/dist/contracts/rps.contract.js.map +1 -0
  48. package/dist/contracts/tipjar.contract.d.ts +4 -0
  49. package/dist/contracts/tipjar.contract.js +60 -0
  50. package/dist/contracts/tipjar.contract.js.map +1 -0
  51. package/dist/contracts/token.contract.d.ts +3 -17
  52. package/dist/contracts/token.contract.js +128 -80
  53. package/dist/contracts/token.contract.js.map +1 -1
  54. package/dist/exchanges/coingecko.d.ts +7 -1
  55. package/dist/exchanges/coingecko.js +38 -21
  56. package/dist/exchanges/coingecko.js.map +1 -1
  57. package/dist/exchanges/exchange.d.ts +15 -8
  58. package/dist/exchanges/exchange.js +65 -11
  59. package/dist/exchanges/exchange.js.map +1 -1
  60. package/dist/hive-rates.d.ts +29 -4
  61. package/dist/hive-rates.js +179 -92
  62. package/dist/hive-rates.js.map +1 -1
  63. package/dist/index.d.ts +11 -3
  64. package/dist/index.js +19 -4
  65. package/dist/index.js.map +1 -1
  66. package/dist/metadata.d.ts +63 -0
  67. package/dist/metadata.js +407 -0
  68. package/dist/metadata.js.map +1 -0
  69. package/dist/streamer.d.ts +104 -11
  70. package/dist/streamer.js +415 -143
  71. package/dist/streamer.js.map +1 -1
  72. package/dist/test.js +11 -12
  73. package/dist/test.js.map +1 -1
  74. package/dist/types/hive-stream.d.ts +85 -14
  75. package/dist/types/rates.d.ts +47 -0
  76. package/dist/types/rates.js +29 -0
  77. package/dist/types/rates.js.map +1 -0
  78. package/dist/utils.d.ts +318 -11
  79. package/dist/utils.js +804 -115
  80. package/dist/utils.js.map +1 -1
  81. package/examples/contracts/README.md +8 -0
  82. package/examples/contracts/exchange.ts +38 -0
  83. package/examples/contracts/poll.ts +21 -0
  84. package/examples/contracts/rps.ts +19 -0
  85. package/examples/contracts/tipjar.ts +19 -0
  86. package/package.json +20 -19
  87. package/test-contract-block.md +3 -3
  88. package/tests/actions.spec.ts +7 -7
  89. package/tests/adapters/actions-persistence.spec.ts +4 -4
  90. package/tests/adapters/sqlite.adapter.spec.ts +2 -2
  91. package/tests/config-input.spec.ts +90 -0
  92. package/tests/contracts/coinflip.contract.spec.ts +26 -154
  93. package/tests/contracts/dice.contract.spec.ts +24 -140
  94. package/tests/contracts/exchange.contract.spec.ts +84 -0
  95. package/tests/contracts/lotto.contract.spec.ts +30 -295
  96. package/tests/contracts/token.contract.spec.ts +72 -316
  97. package/tests/exchanges/coingecko.exchange.spec.ts +169 -0
  98. package/tests/exchanges/exchange.base.spec.ts +246 -0
  99. package/tests/helpers/mock-fetch.ts +165 -0
  100. package/tests/hive-chain-features.spec.ts +319 -0
  101. package/tests/hive-rates.spec.ts +443 -0
  102. package/tests/integration/hive-rates.integration.spec.ts +35 -0
  103. package/tests/metadata.spec.ts +63 -0
  104. package/tests/streamer-actions.spec.ts +29 -18
  105. package/tests/streamer.spec.ts +142 -49
  106. package/tests/types/rates.spec.ts +216 -0
  107. package/tests/utils.spec.ts +27 -6
package/dist/utils.d.ts CHANGED
@@ -1,27 +1,334 @@
1
- import { Client, SignedTransaction } from '@hiveio/dhive';
1
+ import { Client, SignedTransaction, PrivateKey } from '@hiveio/dhive';
2
2
  import { ConfigInterface } from './config';
3
+ type HiveKeyInput = string | PrivateKey;
4
+ interface AuthorityInput {
5
+ weight_threshold: number;
6
+ account_auths: [string, number][];
7
+ key_auths: [string, number][];
8
+ }
9
+ /**
10
+ * Utility functions for Hive blockchain operations and general helpers
11
+ */
3
12
  export declare const Utils: {
4
- sleep(milliseconds: number): Promise<unknown>;
5
- shuffle(array: any): any;
6
- roundPrecision(value: any, precision: any): number;
13
+ /**
14
+ * Pauses execution for the specified number of milliseconds
15
+ * @param milliseconds - The number of milliseconds to sleep
16
+ * @returns Promise that resolves after the specified time
17
+ */
18
+ sleep(milliseconds: number): Promise<void>;
19
+ normalizePrivateKeys(keys: HiveKeyInput | HiveKeyInput[]): PrivateKey[];
20
+ toHiveTimestamp(value: string | Date): string;
21
+ normalizeJsonMeta(meta?: string | Record<string, any>): string;
22
+ /**
23
+ * Shuffles an array in place using the Fisher-Yates algorithm
24
+ * @param array - The array to shuffle (modified in place)
25
+ * @returns The shuffled array
26
+ */
27
+ shuffle<T>(array: T[]): T[];
28
+ /**
29
+ * Rounds a number to the specified precision
30
+ * @param value - The number to round
31
+ * @param precision - The number of decimal places
32
+ * @returns The rounded number
33
+ */
34
+ roundPrecision(value: number, precision: number): number;
35
+ /**
36
+ * Generates a random number within the specified range (inclusive)
37
+ * @param min - The minimum value (default: 0)
38
+ * @param max - The maximum value (default: 2000)
39
+ * @returns A random number between min and max, or NaN if inputs are invalid
40
+ */
7
41
  randomRange(min?: number, max?: number): number;
42
+ /**
43
+ * Generates a random alphanumeric string of the specified length
44
+ * @param length - The desired length of the string (default: 12)
45
+ * @returns A random string containing numbers and letters
46
+ */
8
47
  randomString(length?: number): string;
9
- convertHiveAmount(amount: any, fiatSymbol: any, hiveSymbol: any): Promise<any>;
10
- jsonParse(str: string): any;
11
- getTransaction(client: Client, blockNumber: number, transactionId: any): Promise<SignedTransaction>;
48
+ /**
49
+ * Converts a Hive amount from one currency to another using current exchange rates
50
+ * @param amount - The amount to convert
51
+ * @param fiatSymbol - The source currency symbol
52
+ * @param hiveSymbol - The target Hive currency symbol
53
+ * @returns The converted amount rounded to 3 decimal places
54
+ */
55
+ convertHiveAmount(amount: number, fiatSymbol: string, hiveSymbol: string): Promise<number>;
56
+ /**
57
+ * Safely parses a JSON string
58
+ * @param str - The string to parse
59
+ * @returns The parsed object or null if parsing fails
60
+ */
61
+ jsonParse(str: string): any | null;
62
+ /**
63
+ * Retrieves a transaction from a specific block
64
+ * @param client - The Hive client instance
65
+ * @param blockNumber - The block number containing the transaction
66
+ * @param transactionId - The transaction ID to retrieve
67
+ * @returns The signed transaction
68
+ * @throws Error if transaction is not found in the block
69
+ */
70
+ getTransaction(client: Client, blockNumber: number, transactionId: string): Promise<SignedTransaction>;
71
+ /**
72
+ * Verifies that a transfer transaction matches the expected parameters
73
+ * @param transaction - The signed transaction to verify
74
+ * @param from - Expected sender account
75
+ * @param to - Expected recipient account
76
+ * @param amount - Expected transfer amount
77
+ * @returns True if the transfer matches all parameters
78
+ */
12
79
  verifyTransfer(transaction: SignedTransaction, from: string, to: string, amount: string): Promise<boolean>;
80
+ /**
81
+ * Transfers Hive tokens between accounts
82
+ * @param client - The Hive client instance
83
+ * @param config - Configuration containing the active key
84
+ * @param from - Sender account name
85
+ * @param to - Recipient account name
86
+ * @param amount - Amount to transfer (will be formatted to 3 decimal places)
87
+ * @param symbol - Token symbol (e.g., 'HIVE', 'HBD')
88
+ * @param memo - Optional memo for the transfer
89
+ * @returns Promise resolving to the broadcast result
90
+ */
13
91
  transferHiveTokens(client: Client, config: Partial<ConfigInterface>, from: string, to: string, amount: string, symbol: string, memo?: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
92
+ /**
93
+ * Broadcasts one or more Hive operations signed by one or multiple private keys.
94
+ */
95
+ broadcastOperations(client: Client, operations: Array<[string, any]>, signingKeys: HiveKeyInput | HiveKeyInput[]): Promise<import("@hiveio/dhive").TransactionConfirmation>;
96
+ /**
97
+ * Alias for explicitly broadcasting with multiple signatures.
98
+ */
99
+ broadcastMultiSigOperations(client: Client, operations: Array<[string, any]>, signingKeys: HiveKeyInput[]): any;
100
+ /**
101
+ * Builds a Hive authority object for account_update/account_update2 operations.
102
+ */
103
+ createAuthority(keyAuths?: Array<[string, number]>, accountAuths?: Array<[string, number]>, weightThreshold?: number): AuthorityInput;
104
+ /**
105
+ * Updates account authorities, enabling native Hive multisig thresholds.
106
+ */
107
+ updateAccountAuthorities(client: Client, config: Partial<ConfigInterface>, account: string, authorityUpdate: {
108
+ owner?: AuthorityInput;
109
+ active?: AuthorityInput;
110
+ posting?: AuthorityInput;
111
+ memo_key?: string;
112
+ json_metadata?: string;
113
+ posting_json_metadata?: string;
114
+ useAccountUpdate2?: boolean;
115
+ }, signingKeys?: HiveKeyInput | HiveKeyInput[]): Promise<any>;
116
+ /**
117
+ * Creates an escrow transfer on Hive.
118
+ */
119
+ escrowTransfer(client: Client, config: Partial<ConfigInterface>, options: {
120
+ from: string;
121
+ to: string;
122
+ agent: string;
123
+ escrow_id: number;
124
+ hive_amount?: string;
125
+ hbd_amount?: string;
126
+ fee: string;
127
+ ratification_deadline: string | Date;
128
+ escrow_expiration: string | Date;
129
+ json_meta?: string | Record<string, any>;
130
+ }, signingKeys?: HiveKeyInput | HiveKeyInput[]): any;
131
+ /**
132
+ * Approves or rejects an escrow transfer.
133
+ */
134
+ escrowApprove(client: Client, config: Partial<ConfigInterface>, options: {
135
+ from: string;
136
+ to: string;
137
+ agent: string;
138
+ who: string;
139
+ escrow_id: number;
140
+ approve: boolean;
141
+ }, signingKeys?: HiveKeyInput | HiveKeyInput[]): any;
142
+ /**
143
+ * Opens an escrow dispute.
144
+ */
145
+ escrowDispute(client: Client, config: Partial<ConfigInterface>, options: {
146
+ from: string;
147
+ to: string;
148
+ agent: string;
149
+ who: string;
150
+ escrow_id: number;
151
+ }, signingKeys?: HiveKeyInput | HiveKeyInput[]): any;
152
+ /**
153
+ * Releases escrow funds.
154
+ */
155
+ escrowRelease(client: Client, config: Partial<ConfigInterface>, options: {
156
+ from: string;
157
+ to: string;
158
+ agent: string;
159
+ who: string;
160
+ receiver: string;
161
+ escrow_id: number;
162
+ hive_amount?: string;
163
+ hbd_amount?: string;
164
+ }, signingKeys?: HiveKeyInput | HiveKeyInput[]): any;
165
+ /**
166
+ * Transfers Hive tokens to multiple accounts with a delay between transfers
167
+ * @param client - The Hive client instance
168
+ * @param config - Configuration containing the active key
169
+ * @param from - Sender account name
170
+ * @param accounts - Array of recipient account names
171
+ * @param amount - Amount to transfer to each account
172
+ * @param symbol - Token symbol
173
+ * @param memo - Memo for all transfers
174
+ * @returns True if all transfers completed successfully
175
+ */
14
176
  transferHiveTokensMultiple(client: Client, config: ConfigInterface, from: string, accounts: string[], amount: string, symbol: string, memo: string): Promise<boolean>;
15
- getAccountTransfers(client: Client, account: string, from?: number, max?: number): Promise<any>;
16
- getApiJson(client: Client, from?: number, limit?: number): Promise<any>;
177
+ /**
178
+ * Retrieves account transfer history
179
+ * @param client - The Hive client instance
180
+ * @param account - Account name to get transfers for
181
+ * @param from - Starting index (default: -1 for most recent)
182
+ * @param max - Maximum number of transfers to retrieve
183
+ * @returns Array of transfer operations with date information
184
+ */
185
+ getAccountTransfers(client: Client, account: string, from?: number, max?: number): Promise<any[]>;
186
+ /**
187
+ * Retrieves custom JSON operations from the hiveapi account
188
+ * @param client - The Hive client instance
189
+ * @param from - Starting index (default: -1)
190
+ * @param limit - Maximum number of operations to retrieve
191
+ * @returns Array of custom JSON operations with date information
192
+ */
193
+ getApiJson(client: Client, from?: number, limit?: number): Promise<any[]>;
194
+ /**
195
+ * Transfers Hive Engine tokens between accounts
196
+ * @param client - The Hive client instance
197
+ * @param config - Configuration containing the active key and Hive Engine ID
198
+ * @param from - Sender account name
199
+ * @param to - Recipient account name
200
+ * @param quantity - Token quantity to transfer
201
+ * @param symbol - Token symbol (will be converted to uppercase)
202
+ * @param memo - Optional memo for the transfer
203
+ * @returns Promise resolving to the broadcast result
204
+ */
17
205
  transferHiveEngineTokens(client: Client, config: ConfigInterface, from: string, to: string, quantity: string, symbol: string, memo?: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
206
+ /**
207
+ * Transfers Hive Engine tokens to multiple accounts in batches
208
+ * @param client - The Hive client instance
209
+ * @param config - Configuration containing the active key and Hive Engine ID
210
+ * @param from - Sender account name
211
+ * @param accounts - Array of account objects with 'account' and optional 'amount' properties
212
+ * @param symbol - Token symbol
213
+ * @param memo - Memo for all transfers
214
+ * @param amount - Default amount if not specified per account
215
+ * @returns Promise that resolves when all batches are completed
216
+ */
18
217
  transferHiveEngineTokensMultiple(client: Client, config: ConfigInterface, from: string, accounts: any[], symbol: string, memo: string, amount?: string): Promise<void>;
218
+ /**
219
+ * Issues new Hive Engine tokens to an account
220
+ * @param client - The Hive client instance
221
+ * @param config - Configuration containing the active key and Hive Engine ID
222
+ * @param from - Issuer account name
223
+ * @param to - Recipient account name
224
+ * @param symbol - Token symbol
225
+ * @param quantity - Quantity of tokens to issue
226
+ * @param memo - Optional memo for the issuance
227
+ * @returns Promise resolving to the broadcast result
228
+ */
19
229
  issueHiveEngineTokens(client: Client, config: ConfigInterface, from: string, to: string, symbol: string, quantity: string, memo?: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
230
+ /**
231
+ * Issues Hive Engine tokens to multiple accounts in batches
232
+ * @param client - The Hive client instance
233
+ * @param config - Configuration containing the active key and Hive Engine ID
234
+ * @param from - Issuer account name
235
+ * @param accounts - Array of account objects with 'account' and optional 'amount' properties
236
+ * @param symbol - Token symbol
237
+ * @param memo - Memo for all issuances
238
+ * @param amount - Default amount if not specified per account
239
+ * @returns Promise that resolves when all batches are completed
240
+ */
20
241
  issueHiveEngineTokensMultiple(client: Client, config: ConfigInterface, from: string, accounts: any[], symbol: string, memo: string, amount?: string): Promise<void>;
21
- randomNumber(previousBlockId: any, blockId: any, transactionId: any): number;
242
+ /**
243
+ * Schedules a recurrent transfer on Hive.
244
+ */
245
+ recurrentTransfer(client: Client, config: Partial<ConfigInterface>, options: {
246
+ from: string;
247
+ to: string;
248
+ amount: string;
249
+ memo?: string;
250
+ recurrence: number;
251
+ executions: number;
252
+ }, signingKeys?: HiveKeyInput | HiveKeyInput[]): any;
253
+ /**
254
+ * Creates a DHF proposal.
255
+ */
256
+ createProposal(client: Client, config: Partial<ConfigInterface>, options: {
257
+ creator: string;
258
+ receiver: string;
259
+ start_date: string | Date;
260
+ end_date: string | Date;
261
+ daily_pay: string;
262
+ subject: string;
263
+ permlink: string;
264
+ }, signingKeys?: HiveKeyInput | HiveKeyInput[]): any;
265
+ /**
266
+ * Votes for/against one or more DHF proposals.
267
+ */
268
+ updateProposalVotes(client: Client, config: Partial<ConfigInterface>, options: {
269
+ voter: string;
270
+ proposal_ids: number[];
271
+ approve: boolean;
272
+ }, signingKeys?: HiveKeyInput | HiveKeyInput[]): any;
273
+ /**
274
+ * Removes one or more DHF proposals.
275
+ */
276
+ removeProposals(client: Client, config: Partial<ConfigInterface>, options: {
277
+ proposal_owner: string;
278
+ proposal_ids: number[];
279
+ }, signingKeys?: HiveKeyInput | HiveKeyInput[]): any;
280
+ /**
281
+ * Generates a deterministic random number based on blockchain data
282
+ * @param previousBlockId - The previous block ID
283
+ * @param blockId - The current block ID
284
+ * @param transactionId - The transaction ID
285
+ * @returns A deterministic random number between 1 and 100
286
+ */
287
+ randomNumber(previousBlockId: string, blockId: string, transactionId: string): number;
288
+ /**
289
+ * Upvotes a post or comment
290
+ * @param client - The Hive client instance
291
+ * @param config - Configuration containing the posting key
292
+ * @param voter - The account name doing the voting
293
+ * @param votePercentage - Vote percentage as a string (default: '100.0')
294
+ * @param author - The author of the post/comment
295
+ * @param permlink - The permlink of the post/comment
296
+ * @returns Promise resolving to the broadcast result
297
+ * @throws Error if negative voting values are provided
298
+ */
22
299
  upvote(client: Client, config: Partial<ConfigInterface>, voter: string, votePercentage: string, author: string, permlink: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
300
+ /**
301
+ * Downvotes a post or comment
302
+ * @param client - The Hive client instance
303
+ * @param config - Configuration containing the posting key
304
+ * @param voter - The account name doing the voting
305
+ * @param votePercentage - Vote percentage as a string (default: '100.0')
306
+ * @param author - The author of the post/comment
307
+ * @param permlink - The permlink of the post/comment
308
+ * @returns Promise resolving to the broadcast result
309
+ */
23
310
  downvote(client: Client, config: Partial<ConfigInterface>, voter: string, votePercentage: string, author: string, permlink: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
311
+ /**
312
+ * Converts vote percentage to voting weight for Hive blockchain
313
+ * @param votePercentage - Vote percentage (0-100)
314
+ * @returns Voting weight (0-10000)
315
+ */
24
316
  votingWeight(votePercentage: number): number;
25
- asyncForEach(array: any[], callback: any): Promise<void>;
317
+ /**
318
+ * Executes an async function for each element in an array sequentially
319
+ * @param array - The array to iterate over
320
+ * @param callback - The async callback function to execute for each element
321
+ * @returns Promise that resolves when all iterations are complete
322
+ */
323
+ asyncForEach<T>(array: T[], callback: (value: T, index: number, array: T[]) => Promise<void>): Promise<void>;
324
+ /**
325
+ * Generates a Hivesigner transfer URL
326
+ * @param to - Recipient account name
327
+ * @param memo - Transfer memo
328
+ * @param amount - Transfer amount with currency symbol
329
+ * @param redirectUri - URI to redirect to after signing
330
+ * @returns The complete Hivesigner transfer URL
331
+ */
26
332
  getTransferUrl(to: string, memo: string, amount: string, redirectUri: string): string;
27
333
  };
334
+ export {};