@1money/protocol-ts-sdk 1.0.14

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 (65) hide show
  1. package/.claude/settings.local.json +14 -0
  2. package/CLAUDE.md +77 -0
  3. package/README.md +600 -0
  4. package/es/api/accounts/index.d.ts +20 -0
  5. package/es/api/accounts/types.d.ts +9 -0
  6. package/es/api/chain/index.d.ts +12 -0
  7. package/es/api/chain/types.d.ts +3 -0
  8. package/es/api/checkpoints/index.d.ts +26 -0
  9. package/es/api/checkpoints/types.d.ts +33 -0
  10. package/es/api/constants.d.ts +9 -0
  11. package/es/api/index.d.ts +31 -0
  12. package/es/api/index.js +593 -0
  13. package/es/api/state/index.d.ts +12 -0
  14. package/es/api/state/types.d.ts +7 -0
  15. package/es/api/tokens/index.d.ts +62 -0
  16. package/es/api/tokens/types.d.ts +130 -0
  17. package/es/api/transactions/index.d.ts +35 -0
  18. package/es/api/transactions/types.d.ts +25 -0
  19. package/es/api/types.d.ts +18 -0
  20. package/es/client/core.d.ts +109 -0
  21. package/es/client/index.d.ts +21 -0
  22. package/es/client/index.js +373 -0
  23. package/es/index.d.ts +20 -0
  24. package/es/index.js +1490 -0
  25. package/es/utils/address.d.ts +15 -0
  26. package/es/utils/index.d.ts +6 -0
  27. package/es/utils/index.js +841 -0
  28. package/es/utils/interface.d.ts +7 -0
  29. package/es/utils/safePromise.d.ts +4 -0
  30. package/es/utils/sign.d.ts +15 -0
  31. package/es/utils/txHash.d.ts +2 -0
  32. package/es/utils/typeof.d.ts +2 -0
  33. package/lib/api/accounts/index.d.ts +20 -0
  34. package/lib/api/accounts/types.d.ts +9 -0
  35. package/lib/api/chain/index.d.ts +12 -0
  36. package/lib/api/chain/types.d.ts +3 -0
  37. package/lib/api/checkpoints/index.d.ts +26 -0
  38. package/lib/api/checkpoints/types.d.ts +33 -0
  39. package/lib/api/constants.d.ts +9 -0
  40. package/lib/api/index.d.ts +31 -0
  41. package/lib/api/index.js +692 -0
  42. package/lib/api/state/index.d.ts +12 -0
  43. package/lib/api/state/types.d.ts +7 -0
  44. package/lib/api/tokens/index.d.ts +62 -0
  45. package/lib/api/tokens/types.d.ts +130 -0
  46. package/lib/api/transactions/index.d.ts +35 -0
  47. package/lib/api/transactions/types.d.ts +25 -0
  48. package/lib/api/types.d.ts +18 -0
  49. package/lib/client/core.d.ts +109 -0
  50. package/lib/client/index.d.ts +21 -0
  51. package/lib/client/index.js +434 -0
  52. package/lib/index.d.ts +20 -0
  53. package/lib/index.js +1591 -0
  54. package/lib/utils/address.d.ts +15 -0
  55. package/lib/utils/index.d.ts +6 -0
  56. package/lib/utils/index.js +937 -0
  57. package/lib/utils/interface.d.ts +7 -0
  58. package/lib/utils/safePromise.d.ts +4 -0
  59. package/lib/utils/sign.d.ts +15 -0
  60. package/lib/utils/txHash.d.ts +2 -0
  61. package/lib/utils/typeof.d.ts +2 -0
  62. package/package.json +111 -0
  63. package/public/favicon.ico +0 -0
  64. package/public/logo.png +0 -0
  65. package/umd/1money-protocol-ts-sdk.min.js +2 -0
@@ -0,0 +1,14 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(npm run build:*)",
5
+ "Bash(rm:*)",
6
+ "Bash(mkdir:*)",
7
+ "Bash(grep:*)",
8
+ "Bash(sed:*)",
9
+ "Bash(npm test)",
10
+ "Bash(npx tsc:*)"
11
+ ],
12
+ "deny": []
13
+ }
14
+ }
package/CLAUDE.md ADDED
@@ -0,0 +1,77 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Development Commands
6
+
7
+ ### Building
8
+ - `npm run build` - Build the project using omni build tool (generates lib/, es/, and umd/ directories)
9
+ - `npm run build:remote` - Build for remote deployment with RUN_ENV=remote
10
+
11
+ ### Testing
12
+ - `npm test` - Run all tests using Mocha with nyc coverage
13
+ - Tests are located in `src/**/__test__/*.ts` files
14
+ - Uses Mocha with TypeScript support via tsx loader
15
+
16
+ ### Linting & Code Quality
17
+ - `npm run lint` - Run both Prettier and ESLint checks
18
+ - `npm run lint:fix` - Auto-fix Prettier and ESLint issues
19
+ - `npm run lint:es` - ESLint TypeScript files in src/
20
+ - `npm run lint:prettier` - Check Prettier formatting
21
+ - Individual fix commands: `lint:es_fix`, `lint:prettier_fix`
22
+
23
+ ### Development Workflow
24
+ - `npm run new` - Generate new components using omni CLI
25
+ - `npm run release` - Release package using omni tool
26
+
27
+ ## Project Architecture
28
+
29
+ This is a TypeScript SDK for the 1Money Network Protocol with a modular architecture:
30
+
31
+ ### Core Structure
32
+ - **src/index.ts** - Main entry point, exports api client and utilities
33
+ - **src/api/** - API client modules for different endpoints (accounts, tokens, transactions, checkpoints, chain)
34
+ - **src/client/** - Core HTTP client with promise wrapper system
35
+ - **src/utils/** - Utility functions for signing, address derivation, transaction hashing
36
+
37
+ ### Key Architecture Patterns
38
+
39
+ #### API Client Pattern
40
+ The main `api()` function creates a configured client that returns typed API modules. It supports:
41
+ - Network selection (mainnet/testnet/local) with automatic base URL switching
42
+ - Configurable timeouts
43
+ - Modular API endpoints (accounts, tokens, transactions, checkpoints, chain)
44
+
45
+ #### Promise Wrapper System
46
+ Uses a custom promise wrapper in `src/client/core.ts` that provides:
47
+ - `.success()`, `.error()`, `.timeout()`, `.rest()` handlers
48
+ - Support for both traditional promise chains and async/await
49
+ - Structured error handling with typed responses
50
+
51
+ #### Module Organization
52
+ Each API module (accounts, tokens, etc.) has:
53
+ - `index.ts` - API methods
54
+ - `types.ts` - TypeScript interfaces
55
+ - `__test__/index.test.ts` - Unit tests
56
+ - `README.md` - Module documentation
57
+
58
+ ### Build System
59
+ - Uses **omni-door CLI** for build orchestration
60
+ - **Rollup** for bundling with multiple output formats:
61
+ - CommonJS (`lib/`)
62
+ - ES Modules (`es/`)
63
+ - UMD bundle (`umd/1money-protocol-ts-sdk.min.js`)
64
+ - **tsc-alias** for path alias resolution
65
+ - External dependencies: axios, viem, @ethereumjs/rlp (peer dependencies)
66
+
67
+ ### TypeScript Configuration
68
+ - Target: ESNext with strict mode enabled
69
+ - Path aliases: `@/*` maps to `src/*`
70
+ - Generates declaration files (.d.ts)
71
+ - Excludes test files from compilation
72
+
73
+ ### Testing Strategy
74
+ - Uses Mocha with nyc for coverage
75
+ - Tests located alongside source files in `__test__/` directories
76
+ - Supports both TypeScript and JavaScript test files
77
+ - 60-second timeout for async operations
package/README.md ADDED
@@ -0,0 +1,600 @@
1
+ # @1money/protocol-ts-sdk
2
+ <img src="./public/logo.png" alt="1Money Logo" width="200"/>
3
+
4
+ The TS-SDK for 1Money Network Protocol
5
+
6
+ [![Build Status](https://github.com/1Money-Co/1money-protocol-ts-sdk/actions/workflows/cicd-npm.yml/badge.svg)](https://github.com/1Money-Co/1money-protocol-ts-sdk/actions/workflows/cicd-npm.yml)
7
+ [![NPM downloads](http://img.shields.io/npm/dm/%401money%2Fts-sdk.svg?style=flat-square)](https://www.npmjs.com/package/@1money/protocol-ts-sdk)
8
+ [![npm version](https://badge.fury.io/js/%401money%2Fts-sdk.svg)](https://badge.fury.io/js/%401money%2Fts-sdk)
9
+ [![install size](https://packagephobia.now.sh/badge?p=%401money%2Fts-sdk)](https://packagephobia.now.sh/result?p=%401money%2Fts-sdk)
10
+ [![license](http://img.shields.io/npm/l/%401money%2Fts-sdk.svg)](https://github.com/1money/tpls/blob/master/packages/ts-sdk/LICENSE)
11
+
12
+ ## Quick start
13
+ ### Install
14
+ ```shell
15
+ npm i -S @1money/protocol-ts-sdk axios viem @ethereumjs/rlp
16
+ # or
17
+ yarn add @1money/protocol-ts-sdk axios viem @ethereumjs/rlp
18
+ # or
19
+ pnpm i @1money/protocol-ts-sdk axios viem @ethereumjs/rlp
20
+ ```
21
+
22
+ ### Initialize the API Client
23
+
24
+ ```typescript
25
+ import { api } from '@1money/protocol-ts-sdk';
26
+
27
+ // Initialize with default settings (mainnet)
28
+ const apiClient = api();
29
+
30
+ // Or specify testnet network
31
+ const testnetClient = api({ network: 'testnet' });
32
+
33
+ // You can also set a custom timeout (in milliseconds)
34
+ const apiClient = api({
35
+ network: 'testnet',
36
+ timeout: 5000 // 5 seconds
37
+ });
38
+ ```
39
+
40
+ ### Fetch the current checkpoint number
41
+
42
+ ```typescript
43
+ const number = await apiClient.checkpoints.getNumber()
44
+ .success(response => {
45
+ console.log('number', response.number);
46
+ return response.number;
47
+ })
48
+ .error(err => {
49
+ console.error('Error:', err);
50
+ // return a default value
51
+ return 0;
52
+ });
53
+
54
+ // do something with the number
55
+ // ...
56
+ ```
57
+
58
+ ### Get checkpoint by number
59
+ ```typescript
60
+ const checkpoint = await apiClient.checkpoints.getByNumber(1)
61
+ .success(response => {
62
+ console.log('checkpoint', response);
63
+ });
64
+ ```
65
+
66
+ ## CDN
67
+ ```html
68
+ <script src="https://unpkg.com/@1money/protocol-ts-sdk@latest/umd/1money-protocol-ts-sdk.min.js"></script>
69
+
70
+ <script>
71
+ const apiClient = window.$1money.api({
72
+ network: 'testnet'
73
+ });
74
+
75
+ async function getNumber () {
76
+ const res = await apiClient.checkpoints.getNumber();
77
+ console.log('res: ', res);
78
+ }
79
+
80
+ getNumber();
81
+ </script>
82
+ ```
83
+
84
+ ## Error Handling
85
+
86
+ All API methods return a promise-like object with `.success()`, `.timeout()`, `.error()` and `.rest()` handlers. Always implement both handlers for proper error management:
87
+
88
+ 1. `.success()`: Handles successful API responses
89
+ 2. `.timeout()`: Specifically handles timeout errors
90
+ 3. `.error()`: Handles all other types of errors
91
+ 4. `.rest()`: A final handler that runs after any of the above handlers complete
92
+
93
+ ```typescript
94
+ import { api } from '@1money/protocol-ts-sdk';
95
+
96
+ const apiClient = api();
97
+
98
+ apiClient.someMethod()
99
+ .success(response => {
100
+ // Handle successful response
101
+ })
102
+ .timeout(err => {
103
+ // Handle timeout case
104
+ })
105
+ .error(err => {
106
+ // Handle other errors
107
+ });
108
+ ```
109
+
110
+ You can use `rest` to handle all other errors:
111
+ ```typescript
112
+ apiClient.someMethod()
113
+ .success(response => {
114
+ // Handle successful response
115
+ })
116
+ .rest(err => {
117
+ // Handle other cases
118
+ });
119
+ ```
120
+
121
+ #### Async/Await
122
+ You also can use async/await to handle the response:
123
+ ```typescript
124
+ import { api } from '@1money/protocol-ts-sdk';
125
+
126
+ const apiClient = api();
127
+
128
+ try {
129
+ const response = await apiClient.someMethod();
130
+ console.log('Response:', response);
131
+ } catch (err) {
132
+ console.error('Error:', err);
133
+ }
134
+ ```
135
+
136
+ #### Promise
137
+ You also can use standard `promise` to handle the response:
138
+ ```typescript
139
+ import { api } from '@1money/protocol-ts-sdk';
140
+
141
+ const apiClient = api();
142
+
143
+ apiClient.someMethod()
144
+ .then(response => {
145
+ console.log('Response:', response);
146
+ })
147
+ .catch(err => {
148
+ console.error('Error:', err);
149
+ });
150
+ ```
151
+
152
+ ## API Methods
153
+
154
+ ### State API
155
+
156
+ #### Get Latest Epoch Checkpoint
157
+ The state API provides access to the latest epoch and checkpoint values that are required for all POST operations. The response includes both the epoch/checkpoint numbers and their cryptographic hashes.
158
+
159
+ ```typescript
160
+ apiClient.state.getLatestEpochCheckpoint()
161
+ .success(response => {
162
+ console.log('Latest epoch:', response.epoch);
163
+ console.log('Latest checkpoint:', response.checkpoint);
164
+ console.log('Checkpoint hash:', response.checkpoint_hash);
165
+ console.log('Parent checkpoint hash:', response.checkpoint_parent_hash);
166
+ })
167
+ .error(err => {
168
+ console.error('Error:', err);
169
+ });
170
+ ```
171
+
172
+ ### Chain API
173
+
174
+ #### Get Chain ID
175
+ ```typescript
176
+ apiClient.chain.getChainId()
177
+ .success(response => {
178
+ console.log('Current chain id:', response.chain_id);
179
+ })
180
+ .error(err => {
181
+ console.error('Error:', err);
182
+ });
183
+ ```
184
+
185
+ ### Accounts API
186
+
187
+ #### Get Account Nonce
188
+ ```typescript
189
+ const address = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
190
+ apiClient.accounts.getNonce(address)
191
+ .success(response => {
192
+ console.log('Account nonce:', response);
193
+ })
194
+ .error(err => {
195
+ console.error('Error:', err);
196
+ });
197
+ ```
198
+
199
+ #### Get Associated Token Account
200
+ ```typescript
201
+ const address = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
202
+ const token = '0x2cd8999Be299373D7881f4aDD11510030ad1412F';
203
+ apiClient.accounts.getTokenAccount(address, token)
204
+ .success(response => {
205
+ console.log('Associated token account:', response);
206
+ })
207
+ .error(err => {
208
+ console.error('Error:', err);
209
+ });
210
+ ```
211
+
212
+ ### Tokens API
213
+
214
+ #### Get Token Metadata
215
+ ```typescript
216
+ const tokenAddress = '0x2cd8999Be299373D7881f4aDD11510030ad1412F';
217
+ apiClient.tokens.getTokenMetadata(tokenAddress)
218
+ .success(response => {
219
+ console.log('Token metadata:', response);
220
+ })
221
+ .error(err => {
222
+ console.error('Error:', err);
223
+ });
224
+ ```
225
+
226
+ #### Issue New Token
227
+ ```typescript
228
+ import { signMessage, toHex } from '@1money/protocol-ts-sdk';
229
+
230
+ // Your private key (DO NOT share or commit your private key)
231
+ const privateKey = 'YOUR_PRIVATE_KEY';
232
+
233
+ // First, get the latest epoch checkpoint
234
+ const epochData = await apiClient.state.getLatestEpochCheckpoint()
235
+ .success(response => response);
236
+
237
+ // Create the payload array for signing
238
+ const payload = [
239
+ epochData.epoch, // recent_epoch
240
+ epochData.checkpoint, // recent_checkpoint
241
+ 1, // chain_id
242
+ 1, // nonce
243
+ 'MTK', // symbol
244
+ 'My Token', // name
245
+ 18, // decimals
246
+ '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3', // master_authority
247
+ true, // is_private
248
+ ];
249
+
250
+ // Generate signature
251
+ const signature = await signMessage(payload, privateKey);
252
+ if (!signature) {
253
+ throw new Error('Failed to generate signature');
254
+ }
255
+
256
+ // Create the issue payload with epoch checkpoint data
257
+ const issuePayload = {
258
+ recent_epoch: epochData.epoch,
259
+ recent_checkpoint: epochData.checkpoint,
260
+ chain_id: 1,
261
+ nonce: 1,
262
+ name: 'My Token',
263
+ symbol: 'MTK',
264
+ decimals: 18,
265
+ master_authority: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
266
+ is_private: true,
267
+ signature
268
+ };
269
+
270
+ apiClient.tokens.issueToken(issuePayload)
271
+ .success(response => {
272
+ console.log('Token issued:', response);
273
+ })
274
+ .error(err => {
275
+ console.error('Error:', err);
276
+ });
277
+ ```
278
+
279
+ #### Manage Token Blacklist/Whitelist
280
+ ```typescript
281
+ import { signMessage, toHex } from '@1money/protocol-ts-sdk';
282
+ import type { ManageListAction } from '@1money/protocol-ts-sdk/api';
283
+
284
+ // Your private key (DO NOT share or commit your private key)
285
+ const privateKey = 'YOUR_PRIVATE_KEY';
286
+
287
+ // First, get the latest epoch checkpoint
288
+ const epochData = await apiClient.state.getLatestEpochCheckpoint()
289
+ .success(response => response);
290
+
291
+ // Create the payload array for signing
292
+ const payload = [
293
+ epochData.epoch, // recent_epoch
294
+ epochData.checkpoint, // recent_checkpoint
295
+ 1, // chain_id
296
+ 1, // nonce
297
+ ManageListAction.Add, // action
298
+ '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3', // address
299
+ '0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
300
+ ];
301
+
302
+ // Generate signature
303
+ const signature = await signMessage(payload, privateKey);
304
+ if (!signature) {
305
+ throw new Error('Failed to generate signature');
306
+ }
307
+
308
+ // Create the manage list payload with epoch checkpoint data
309
+ const manageListPayload = {
310
+ recent_epoch: epochData.epoch,
311
+ recent_checkpoint: epochData.checkpoint,
312
+ chain_id: 1,
313
+ nonce: 1,
314
+ action: ManageListAction.Add,
315
+ address: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
316
+ token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
317
+ signature
318
+ };
319
+
320
+ // Use manageBlacklist for blacklist operations
321
+ apiClient.tokens.manageBlacklist(manageListPayload)
322
+ .success(response => {
323
+ console.log('Blacklist update transaction hash:', response.hash);
324
+ })
325
+ .error(err => {
326
+ console.error('Error:', err);
327
+ });
328
+
329
+ // Or use manageWhitelist for whitelist operations
330
+ apiClient.tokens.manageWhitelist(manageListPayload)
331
+ .success(response => {
332
+ console.log('Whitelist update transaction hash:', response.hash);
333
+ })
334
+ .error(err => {
335
+ console.error('Error:', err);
336
+ });
337
+ ```
338
+
339
+ #### Burn Tokens
340
+ ```typescript
341
+ import { signMessage, toHex } from '@1money/protocol-ts-sdk';
342
+
343
+ // Your private key (DO NOT share or commit your private key)
344
+ const privateKey = 'YOUR_PRIVATE_KEY';
345
+
346
+ // First, get the latest epoch checkpoint
347
+ const epochData = await apiClient.state.getLatestEpochCheckpoint()
348
+ .success(response => response);
349
+
350
+ // Create the payload array for signing
351
+ const payload = [
352
+ epochData.epoch, // recent_epoch
353
+ epochData.checkpoint, // recent_checkpoint
354
+ 1, // chain_id
355
+ 1, // nonce
356
+ '0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
357
+ '1000000000000000000', // amount
358
+ ];
359
+
360
+ // Generate signature
361
+ const signature = await signMessage(payload, privateKey);
362
+ if (!signature) {
363
+ throw new Error('Failed to generate signature');
364
+ }
365
+
366
+ // Create the burn payload with epoch checkpoint data
367
+ const burnPayload = {
368
+ recent_epoch: epochData.epoch,
369
+ recent_checkpoint: epochData.checkpoint,
370
+ chain_id: 1,
371
+ nonce: 1,
372
+ token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
373
+ value: '1000000000000000000',
374
+ signature
375
+ };
376
+
377
+ apiClient.tokens.burnToken(burnPayload)
378
+ .success(response => {
379
+ console.log('Burn transaction hash:', response.hash);
380
+ })
381
+ .error(err => {
382
+ console.error('Error:', err);
383
+ });
384
+ ```
385
+
386
+ #### Grant Token Authority
387
+ ```typescript
388
+ import { signMessage, toHex } from '@1money/protocol-ts-sdk';
389
+ import type { AuthorityType, AuthorityAction } from '@1money/protocol-ts-sdk/api';
390
+
391
+ // Your private key (DO NOT share or commit your private key)
392
+ const privateKey = 'YOUR_PRIVATE_KEY';
393
+
394
+ // First, get the latest epoch checkpoint
395
+ const epochData = await apiClient.state.getLatestEpochCheckpoint()
396
+ .success(response => response);
397
+
398
+ // Create the payload array for signing
399
+ const payload = [
400
+ epochData.epoch, // recent_epoch
401
+ epochData.checkpoint, // recent_checkpoint
402
+ 1, // chain_id
403
+ 1, // nonce
404
+ '0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
405
+ '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3', // authority_address
406
+ AuthorityAction.Grant, // action
407
+ AuthorityType.MasterMint, // authority_type
408
+ ];
409
+
410
+ // Generate signature
411
+ const signature = await signMessage(payload, privateKey);
412
+ if (!signature) {
413
+ throw new Error('Failed to generate signature');
414
+ }
415
+
416
+ // Create the authority payload with epoch checkpoint data
417
+ const authorityPayload = {
418
+ recent_epoch: epochData.epoch,
419
+ recent_checkpoint: epochData.checkpoint,
420
+ chain_id: 1,
421
+ nonce: 1,
422
+ token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
423
+ authority_address: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
424
+ action: AuthorityAction.Grant,
425
+ authority_type: AuthorityType.MasterMint,
426
+ signature
427
+ };
428
+
429
+ apiClient.tokens.grantAuthority(authorityPayload)
430
+ .success(response => {
431
+ console.log('Authority update transaction hash:', response.hash);
432
+ })
433
+ .error(err => {
434
+ console.error('Error:', err);
435
+ });
436
+ ```
437
+
438
+ ### Transactions API
439
+
440
+ #### Get Transaction Details
441
+ ```typescript
442
+ const txHash = '0xf55f9525be94633b56f954d3252d52b8ef42f5fd5f9491b243708471c15cc40c';
443
+ apiClient.transactions.getByHash(txHash)
444
+ .success(response => {
445
+ console.log('Transaction details:', response);
446
+ })
447
+ .error(err => {
448
+ console.error('Error:', err);
449
+ });
450
+ ```
451
+
452
+ #### Get Transaction Receipt
453
+ ```typescript
454
+ const txHash = '0xf55f9525be94633b56f954d3252d52b8ef42f5fd5f9491b243708471c15cc40c';
455
+ apiClient.transactions.getReceiptByHash(txHash)
456
+ .success(response => {
457
+ console.log('Transaction receipt:', response);
458
+ })
459
+ .error(err => {
460
+ console.error('Error:', err);
461
+ });
462
+ ```
463
+
464
+ #### Estimate Transaction Fee
465
+ ```typescript
466
+ const fromAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
467
+ const value = '1000000000';
468
+ const tokenAddress = '0x2cd8999Be299373D7881f4aDD11510030ad1412F';
469
+
470
+ apiClient.transactions.estimateFee(fromAddress, value, tokenAddress)
471
+ .success(response => {
472
+ console.log('Estimated fee:', response);
473
+ })
474
+ .error(err => {
475
+ console.error('Error:', err);
476
+ });
477
+ ```
478
+
479
+ #### Submit Payment Transaction
480
+ ```typescript
481
+ import { signMessage, toHex } from '@1money/protocol-ts-sdk';
482
+
483
+ // Your private key (DO NOT share or commit your private key)
484
+ const privateKey = 'YOUR_PRIVATE_KEY';
485
+
486
+ // First, get the latest epoch checkpoint
487
+ const epochData = await apiClient.state.getLatestEpochCheckpoint()
488
+ .success(response => response);
489
+
490
+ // Create the payload array for signing
491
+ const payload = [
492
+ epochData.epoch, // recent_epoch
493
+ epochData.checkpoint, // recent_checkpoint
494
+ 1, // chain_id
495
+ 1, // nonce
496
+ '0x2cd8999Be299373D7881f4aDD11510030ad1412F', // recipient
497
+ '1000000000', // value
498
+ '0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
499
+ ];
500
+
501
+ // Generate signature
502
+ const signature = await signMessage(payload, privateKey);
503
+ if (!signature) {
504
+ throw new Error('Failed to generate signature');
505
+ }
506
+
507
+ // Create the payment payload with epoch checkpoint data
508
+ const paymentPayload = {
509
+ recent_epoch: epochData.epoch,
510
+ recent_checkpoint: epochData.checkpoint,
511
+ chain_id: 1,
512
+ nonce: 1,
513
+ recipient: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
514
+ value: '1000000000',
515
+ token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
516
+ signature
517
+ };
518
+
519
+ apiClient.transactions.payment(paymentPayload)
520
+ .success(response => {
521
+ console.log('Payment transaction hash:', response.hash);
522
+ })
523
+ .error(err => {
524
+ console.error('Error:', err);
525
+ });
526
+ ```
527
+
528
+
529
+ ## Utility Functions
530
+
531
+ ### Calculate Transaction Hash
532
+ ```typescript
533
+ import { calcTxHash } from '@1money/protocol-ts-sdk';
534
+
535
+ // Create the payload array
536
+ const payload = [
537
+ 1212101, // chain_id
538
+ 2, // nonce
539
+ '0x0000000000000000000000000000000000000000', // recipient
540
+ 1024, // value
541
+ '0x0000000000000000000000000000000000000000', // token
542
+ ];
543
+
544
+ // Create the signature object
545
+ const signature = {
546
+ r: '0xe9ef6ce7aaeb4656f197b63a96c932ab5e0fd2df0913f6af1c8e7b1879e5ed0a',
547
+ s: '0x68a9cbaa35af5e3d896a2841d19a42dba729380a1c91864403de872578f6f6c3',
548
+ v: 0,
549
+ };
550
+
551
+ // Calculate the transaction hash
552
+ const hash = calcTxHash(payload, signature);
553
+ console.log('Transaction hash:', hash);
554
+ ```
555
+
556
+ ### Derive Token Address
557
+ ```typescript
558
+ import { deriveTokenAddress } from '@1money/protocol-ts-sdk';
559
+
560
+ const walletAddress = '0xA634dfba8c7550550817898bC4820cD10888Aac5';
561
+ const mintAddress = '0x8E9d1b45293e30EF38564582979195DD16A16E13';
562
+
563
+ // Derive the token account address
564
+ const tokenAddress = deriveTokenAddress(walletAddress, mintAddress);
565
+ console.log('Token account address:', tokenAddress);
566
+ ```
567
+
568
+ ### Convert to Hex
569
+ ```typescript
570
+ import { toHex } from '@1money/protocol-ts-sdk';
571
+
572
+ // Convert different types to hex
573
+ const boolHex = toHex(true); // '0x01'
574
+ const numHex = toHex(123); // '0x7b'
575
+ const strHex = toHex('hello'); // '0x68656c6c6f'
576
+ const arrHex = toHex([1, 2, 3]); // '0x010203'
577
+ ```
578
+
579
+ ### Sign Message
580
+ ```typescript
581
+ import { signMessage } from '@1money/protocol-ts-sdk';
582
+
583
+ // Your private key (DO NOT share or commit your private key)
584
+ const privateKey = 'YOUR_PRIVATE_KEY';
585
+
586
+ // Create the payload array for signing
587
+ const payload = [
588
+ 1212101, // chain_id
589
+ 2, // nonce
590
+ '0x0000000000000000000000000000000000000000', // recipient
591
+ '1000000000000000000', // value (in wei)
592
+ '0x0000000000000000000000000000000000000000', // token
593
+ ];
594
+
595
+ // Sign the message
596
+ const signature = await signMessage(payload, privateKey);
597
+ ```
598
+
599
+ ## License
600
+ MIT
@@ -0,0 +1,20 @@
1
+ import type { AccountInfo, AssociatedTokenAccount } from './types';
2
+ /**
3
+ * Accounts API methods
4
+ */
5
+ export declare const accountsApi: {
6
+ /**
7
+ * Get account nonce
8
+ * @param address Address of the account to lookup nonce for
9
+ * @returns Promise with account info response
10
+ */
11
+ getNonce: (address: string) => import("../../client/index.js").PromiseWrapper<"custom", AccountInfo, AccountInfo, AccountInfo, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | AccountInfo, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<AccountInfo>;
12
+ /**
13
+ * Get associated token account
14
+ * @param address Address of the account to lookup associated token account for
15
+ * @param token Token address to lookup associated token account for
16
+ * @returns Promise with associated token account response
17
+ */
18
+ getTokenAccount: (address: string, token: string) => import("../../client/index.js").PromiseWrapper<"custom", AssociatedTokenAccount, AssociatedTokenAccount, AssociatedTokenAccount, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | AssociatedTokenAccount, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<AssociatedTokenAccount>;
19
+ };
20
+ export default accountsApi;