@1money/protocol-ts-sdk 1.0.16 → 1.1.1
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/.claude/settings.local.json +14 -2
- package/.env.integration.example +19 -0
- package/AGENTS.md +28 -0
- package/LICENSE +21 -0
- package/README.md +21 -55
- package/es/__integration__/config.d.ts +24 -0
- package/es/__integration__/helpers.d.ts +75 -0
- package/es/__integration__/setup.d.ts +26 -0
- package/es/api/accounts/index.d.ts +7 -1
- package/es/api/accounts/types.d.ts +4 -2
- package/es/api/checkpoints/index.d.ts +7 -1
- package/es/api/checkpoints/types.d.ts +4 -16
- package/es/api/index.js +50 -5
- package/es/api/tokens/index.d.ts +13 -1
- package/es/api/tokens/types.d.ts +27 -9
- package/es/api/transactions/index.d.ts +7 -2
- package/es/api/transactions/types.d.ts +149 -2
- package/es/client/core.d.ts +1 -1
- package/es/client/index.js +8 -4
- package/es/index.js +63 -9
- package/es/utils/index.js +13 -4
- package/lib/__integration__/config.d.ts +24 -0
- package/lib/__integration__/helpers.d.ts +75 -0
- package/lib/__integration__/setup.d.ts +26 -0
- package/lib/api/accounts/index.d.ts +7 -1
- package/lib/api/accounts/types.d.ts +4 -2
- package/lib/api/checkpoints/index.d.ts +7 -1
- package/lib/api/checkpoints/types.d.ts +4 -16
- package/lib/api/index.js +48 -7
- package/lib/api/tokens/index.d.ts +13 -1
- package/lib/api/tokens/types.d.ts +27 -9
- package/lib/api/transactions/index.d.ts +7 -2
- package/lib/api/transactions/types.d.ts +149 -2
- package/lib/client/core.d.ts +1 -1
- package/lib/client/index.js +6 -6
- package/lib/index.js +61 -11
- package/lib/utils/index.js +13 -4
- package/package.json +10 -1
- package/umd/1money-protocol-ts-sdk.min.js +2 -2
|
@@ -7,8 +7,20 @@
|
|
|
7
7
|
"Bash(grep:*)",
|
|
8
8
|
"Bash(sed:*)",
|
|
9
9
|
"Bash(npm test)",
|
|
10
|
-
"Bash(npx tsc:*)"
|
|
10
|
+
"Bash(npx tsc:*)",
|
|
11
|
+
"Bash(./node_modules/.bin/tsc:*)",
|
|
12
|
+
"Bash(npm install:*)",
|
|
13
|
+
"Bash(npm run lint)",
|
|
14
|
+
"Bash(npm run test:integration:*)",
|
|
15
|
+
"Bash(node -e:*)",
|
|
16
|
+
"Bash(npm run test:integration:testnet:*)",
|
|
17
|
+
"Bash(node test-sig.mjs:*)",
|
|
18
|
+
"Bash(xargs grep -l recent_epoch|recent_checkpoint|recentEpoch|recentCheckpoint)",
|
|
19
|
+
"Bash(cat:*)",
|
|
20
|
+
"Bash(xargs grep:*)",
|
|
21
|
+
"Bash(npm run lint:es_fix:*)",
|
|
22
|
+
"Bash(node test-encoding.mjs:*)"
|
|
11
23
|
],
|
|
12
24
|
"deny": []
|
|
13
25
|
}
|
|
14
|
-
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Integration Test Environment Variables
|
|
2
|
+
# Copy this file to .env.integration and update with your values
|
|
3
|
+
|
|
4
|
+
# Enable integration tests
|
|
5
|
+
RUN_INTEGRATION_TESTS=true
|
|
6
|
+
|
|
7
|
+
# Network configuration (local, testnet, mainnet)
|
|
8
|
+
INTEGRATION_TEST_NETWORK=local
|
|
9
|
+
|
|
10
|
+
# Operator private key (for transaction signing)
|
|
11
|
+
# Default: Local test key
|
|
12
|
+
INTEGRATION_TEST_OPERATOR_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
|
|
13
|
+
|
|
14
|
+
# Master account private key (for token management)
|
|
15
|
+
# Default: Local test key
|
|
16
|
+
INTEGRATION_TEST_MASTER_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
|
|
17
|
+
|
|
18
|
+
# Test timeout in milliseconds
|
|
19
|
+
INTEGRATION_TEST_TIMEOUT=120000
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Repository Guidelines
|
|
2
|
+
|
|
3
|
+
## Project Structure & Module Organization
|
|
4
|
+
Core TypeScript sources live in `src/`, with domain folders for `api/`, `client/`, and shared `utils/`. Entry points such as `src/index.ts` stitch those modules together, while accompanying specs sit in sibling `__test__` directories (`src/api/tokens/__test__/index.test.ts`, etc.). Compiled artifacts are emitted to `es/` (ESM), `lib/` (CJS), and `umd/` for CDN usage, so never edit those outputs directly. Reference assets reside in `public/`, examples in `examples/`, and longer-form docs in `docs/`. Build behavior is centralized in `omni.config.js`, bundling tweaks in `rollup.config.js`, and TypeScript settings in `tsconfig.json`.
|
|
5
|
+
|
|
6
|
+
## Build, Test & Development Commands
|
|
7
|
+
Use your preferred package manager, but stay consistent per branch.
|
|
8
|
+
```bash
|
|
9
|
+
pnpm install # or npm install – install dev + peer tooling
|
|
10
|
+
npm run build # omni build -> emits es/lib/umd bundles
|
|
11
|
+
npm run build:remote # same build with RUN_ENV=remote for hosted targets
|
|
12
|
+
npm test # nyc + mocha using .mocharc.js
|
|
13
|
+
npm run lint # prettier check + eslint (ts/tsx)
|
|
14
|
+
npm run lint:fix # applies prettier/eslint autofixes
|
|
15
|
+
```
|
|
16
|
+
Run linting before opening a PR; CI expects clean output directories.
|
|
17
|
+
|
|
18
|
+
## Coding Style & Naming Conventions
|
|
19
|
+
The repo enforces `.editorconfig` (LF, UTF-8, two-space indents) and `prettier.config.js` (tabWidth 2, printWidth 50, single quotes, arrowParens `avoid`, trailing commas `none`). ESLint runs with `@typescript-eslint` rules over `src/**`. Prefer descriptive module exports (`api/checkpoints`, `client/rpc`) and keep test files named `*.test.ts`. Public APIs should expose camelCase functions, PascalCase classes, and never leak internal helper names.
|
|
20
|
+
|
|
21
|
+
## Testing Guidelines
|
|
22
|
+
All specs use Mocha + Chai and live beside their subjects (`__test__/`). Structure tests as `describe('<module>')` blocks with explicit success/error cases that mirror the SDK’s `.success/.timeout/.error` flow. Execute `npm test` locally; NYC writes reports to `.nyc_output/` and enforces the existing coverage baselines, so add scenarios rather than loosening thresholds. When adding a module, stub network calls and favor deterministic fixtures.
|
|
23
|
+
|
|
24
|
+
## Commit & Pull Request Guidelines
|
|
25
|
+
Commitlint extends the conventional config with allowed types such as `feat`, `fix`, `docs`, `refactor`, `test`, `chore`, plus the project tag `[1MONEY-PROTOCOL-TS-SDK]`. Format messages as `type(scope): summary`, e.g., `feat(api): add token metadata endpoint`. Before pushing, run `npm run lint && npm test` and ensure generated bundles are excluded from diffs. PRs should describe the change, list validation commands, link related issues, and include API or screenshot evidence when touching user-facing behavior.
|
|
26
|
+
|
|
27
|
+
## Security & Configuration Tips
|
|
28
|
+
Never commit `.env` values; tests should rely on mocked data or public endpoints. When debugging against live protocol nodes, set `RUN_ENV=remote` only in your shell and prefer the `testnet` client configuration shown in `README.md`. Audit dependencies before enabling new wallets or transports, and keep peer versions (`axios`, `viem`, `@ethereumjs/rlp`) aligned with the ranges declared in `package.json`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 1Money Co.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
The TS-SDK for 1Money Network Protocol
|
|
5
5
|
|
|
6
6
|
[](https://github.com/1Money-Co/1money-protocol-ts-sdk/actions/workflows/cicd-npm.yml)
|
|
7
|
-
[](https://www.npmjs.com/package/@1money/protocol-ts-sdk)
|
|
8
|
+
[](https://badge.fury.io/js/%401money%2Fprotocol-ts-sdk)
|
|
9
|
+
[](https://packagephobia.now.sh/result?p=%401money%2Fprotocol-ts-sdk)
|
|
10
|
+
[](https://github.com/1Money-Co/1money-protocol-ts-sdk/blob/main/LICENSE)
|
|
11
11
|
|
|
12
12
|
## Quick start
|
|
13
13
|
### Install
|
|
@@ -151,24 +151,6 @@ apiClient.someMethod()
|
|
|
151
151
|
|
|
152
152
|
## API Methods
|
|
153
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
154
|
### Chain API
|
|
173
155
|
|
|
174
156
|
#### Get Chain ID
|
|
@@ -236,8 +218,6 @@ const epochData = await apiClient.state.getLatestEpochCheckpoint()
|
|
|
236
218
|
|
|
237
219
|
// Create the payload array for signing
|
|
238
220
|
const payload = [
|
|
239
|
-
epochData.epoch, // recent_epoch
|
|
240
|
-
epochData.checkpoint, // recent_checkpoint
|
|
241
221
|
1, // chain_id
|
|
242
222
|
1, // nonce
|
|
243
223
|
'MTK', // symbol
|
|
@@ -253,10 +233,8 @@ if (!signature) {
|
|
|
253
233
|
throw new Error('Failed to generate signature');
|
|
254
234
|
}
|
|
255
235
|
|
|
256
|
-
// Create the issue payload
|
|
236
|
+
// Create the issue payload
|
|
257
237
|
const issuePayload = {
|
|
258
|
-
recent_epoch: epochData.epoch,
|
|
259
|
-
recent_checkpoint: epochData.checkpoint,
|
|
260
238
|
chain_id: 1,
|
|
261
239
|
nonce: 1,
|
|
262
240
|
name: 'My Token',
|
|
@@ -290,8 +268,6 @@ const epochData = await apiClient.state.getLatestEpochCheckpoint()
|
|
|
290
268
|
|
|
291
269
|
// Create the payload array for signing
|
|
292
270
|
const payload = [
|
|
293
|
-
epochData.epoch, // recent_epoch
|
|
294
|
-
epochData.checkpoint, // recent_checkpoint
|
|
295
271
|
1, // chain_id
|
|
296
272
|
1, // nonce
|
|
297
273
|
ManageListAction.Add, // action
|
|
@@ -305,10 +281,8 @@ if (!signature) {
|
|
|
305
281
|
throw new Error('Failed to generate signature');
|
|
306
282
|
}
|
|
307
283
|
|
|
308
|
-
// Create the manage list payload
|
|
284
|
+
// Create the manage list payload
|
|
309
285
|
const manageListPayload = {
|
|
310
|
-
recent_epoch: epochData.epoch,
|
|
311
|
-
recent_checkpoint: epochData.checkpoint,
|
|
312
286
|
chain_id: 1,
|
|
313
287
|
nonce: 1,
|
|
314
288
|
action: ManageListAction.Add,
|
|
@@ -349,12 +323,11 @@ const epochData = await apiClient.state.getLatestEpochCheckpoint()
|
|
|
349
323
|
|
|
350
324
|
// Create the payload array for signing
|
|
351
325
|
const payload = [
|
|
352
|
-
epochData.epoch, // recent_epoch
|
|
353
|
-
epochData.checkpoint, // recent_checkpoint
|
|
354
326
|
1, // chain_id
|
|
355
327
|
1, // nonce
|
|
356
|
-
'0x2cd8999Be299373D7881f4aDD11510030ad1412F', //
|
|
328
|
+
'0x2cd8999Be299373D7881f4aDD11510030ad1412F', // recipient (for burn, same as sender)
|
|
357
329
|
'1000000000000000000', // amount
|
|
330
|
+
'0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
|
|
358
331
|
];
|
|
359
332
|
|
|
360
333
|
// Generate signature
|
|
@@ -363,14 +336,13 @@ if (!signature) {
|
|
|
363
336
|
throw new Error('Failed to generate signature');
|
|
364
337
|
}
|
|
365
338
|
|
|
366
|
-
// Create the burn payload
|
|
339
|
+
// Create the burn payload
|
|
367
340
|
const burnPayload = {
|
|
368
|
-
recent_epoch: epochData.epoch,
|
|
369
|
-
recent_checkpoint: epochData.checkpoint,
|
|
370
341
|
chain_id: 1,
|
|
371
342
|
nonce: 1,
|
|
372
|
-
|
|
343
|
+
recipient: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
373
344
|
value: '1000000000000000000',
|
|
345
|
+
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
374
346
|
signature
|
|
375
347
|
};
|
|
376
348
|
|
|
@@ -397,14 +369,13 @@ const epochData = await apiClient.state.getLatestEpochCheckpoint()
|
|
|
397
369
|
|
|
398
370
|
// Create the payload array for signing
|
|
399
371
|
const payload = [
|
|
400
|
-
epochData.epoch, // recent_epoch
|
|
401
|
-
epochData.checkpoint, // recent_checkpoint
|
|
402
372
|
1, // chain_id
|
|
403
373
|
1, // nonce
|
|
404
|
-
'0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
|
|
405
|
-
'0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3', // authority_address
|
|
406
374
|
AuthorityAction.Grant, // action
|
|
407
|
-
AuthorityType.MasterMint, // authority_type
|
|
375
|
+
AuthorityType.MasterMint, // authority_type (sends 'MasterMintBurn')
|
|
376
|
+
'0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3', // authority_address
|
|
377
|
+
'0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
|
|
378
|
+
'1000000000000000000000', // value (optional, for MintBurnTokens type)
|
|
408
379
|
];
|
|
409
380
|
|
|
410
381
|
// Generate signature
|
|
@@ -413,16 +384,15 @@ if (!signature) {
|
|
|
413
384
|
throw new Error('Failed to generate signature');
|
|
414
385
|
}
|
|
415
386
|
|
|
416
|
-
// Create the authority payload
|
|
387
|
+
// Create the authority payload
|
|
417
388
|
const authorityPayload = {
|
|
418
|
-
recent_epoch: epochData.epoch,
|
|
419
|
-
recent_checkpoint: epochData.checkpoint,
|
|
420
389
|
chain_id: 1,
|
|
421
390
|
nonce: 1,
|
|
422
|
-
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
423
|
-
authority_address: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
|
|
424
391
|
action: AuthorityAction.Grant,
|
|
425
|
-
authority_type: AuthorityType.MasterMint,
|
|
392
|
+
authority_type: AuthorityType.MasterMint, // value is 'MasterMintBurn'
|
|
393
|
+
authority_address: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
|
|
394
|
+
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
395
|
+
value: '1000000000000000000000',
|
|
426
396
|
signature
|
|
427
397
|
};
|
|
428
398
|
|
|
@@ -489,8 +459,6 @@ const epochData = await apiClient.state.getLatestEpochCheckpoint()
|
|
|
489
459
|
|
|
490
460
|
// Create the payload array for signing
|
|
491
461
|
const payload = [
|
|
492
|
-
epochData.epoch, // recent_epoch
|
|
493
|
-
epochData.checkpoint, // recent_checkpoint
|
|
494
462
|
1, // chain_id
|
|
495
463
|
1, // nonce
|
|
496
464
|
'0x2cd8999Be299373D7881f4aDD11510030ad1412F', // recipient
|
|
@@ -504,10 +472,8 @@ if (!signature) {
|
|
|
504
472
|
throw new Error('Failed to generate signature');
|
|
505
473
|
}
|
|
506
474
|
|
|
507
|
-
// Create the payment payload
|
|
475
|
+
// Create the payment payload
|
|
508
476
|
const paymentPayload = {
|
|
509
|
-
recent_epoch: epochData.epoch,
|
|
510
|
-
recent_checkpoint: epochData.checkpoint,
|
|
511
477
|
chain_id: 1,
|
|
512
478
|
nonce: 1,
|
|
513
479
|
recipient: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test configuration
|
|
3
|
+
*
|
|
4
|
+
* Environment variables:
|
|
5
|
+
* - INTEGRATION_TEST_NETWORK: Network to use (local, testnet, mainnet)
|
|
6
|
+
* - INTEGRATION_TEST_OPERATOR_KEY: Operator private key
|
|
7
|
+
* - INTEGRATION_TEST_MASTER_KEY: Master account private key
|
|
8
|
+
* - RUN_INTEGRATION_TESTS: Set to 'true' to run integration tests
|
|
9
|
+
*/
|
|
10
|
+
export interface IntegrationTestConfig {
|
|
11
|
+
network: 'local' | 'testnet' | 'mainnet';
|
|
12
|
+
operatorKey: string;
|
|
13
|
+
masterKey: string;
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
timeout: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get integration test configuration from environment variables
|
|
19
|
+
*/
|
|
20
|
+
export declare function getConfig(): IntegrationTestConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Check if integration tests should run
|
|
23
|
+
*/
|
|
24
|
+
export declare function shouldRunIntegrationTests(): boolean;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test helper utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { RestSignature } from '../api/tokens/types';
|
|
5
|
+
import type { TestAccount } from './setup';
|
|
6
|
+
import type { Payload } from '../utils/interface';
|
|
7
|
+
/**
|
|
8
|
+
* Create API client for integration tests
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTestClient(): {
|
|
11
|
+
accounts: typeof import("../api/accounts").accountsApi;
|
|
12
|
+
checkpoints: typeof import("../api/checkpoints").checkpointsApi;
|
|
13
|
+
tokens: typeof import("../api/tokens").tokensApi;
|
|
14
|
+
transactions: typeof import("../api/transactions").transactionsApi;
|
|
15
|
+
chain: typeof import("../api/chain").chainApi;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Sign a payload with an account and return RestSignature format
|
|
19
|
+
*/
|
|
20
|
+
export declare function signPayload(payload: Payload, account: TestAccount): Promise<RestSignature>;
|
|
21
|
+
/**
|
|
22
|
+
* Wait for a transaction to be finalized
|
|
23
|
+
* @param txHash Transaction hash
|
|
24
|
+
* @param maxRetries Maximum number of retries
|
|
25
|
+
* @param retryDelay Delay between retries in milliseconds
|
|
26
|
+
*/
|
|
27
|
+
export declare function waitForFinalization(txHash: string, maxRetries?: number, retryDelay?: number): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Wait for a specific amount of time
|
|
30
|
+
*/
|
|
31
|
+
export declare function wait(ms: number): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Get current checkpoint number
|
|
34
|
+
*/
|
|
35
|
+
export declare function getCurrentCheckpoint(): Promise<number>;
|
|
36
|
+
/**
|
|
37
|
+
* Get account nonce
|
|
38
|
+
*/
|
|
39
|
+
export declare function getAccountNonce(address: string): Promise<number>;
|
|
40
|
+
/**
|
|
41
|
+
* Get chain ID
|
|
42
|
+
*/
|
|
43
|
+
export declare function getChainId(): Promise<number>;
|
|
44
|
+
/**
|
|
45
|
+
* Derive token address from owner and nonce
|
|
46
|
+
*/
|
|
47
|
+
export declare function deriveTokenAddress(owner: string, nonce: number): string;
|
|
48
|
+
/**
|
|
49
|
+
* Assert that a value is defined (throws if undefined/null)
|
|
50
|
+
*/
|
|
51
|
+
export declare function assertDefined<T>(value: T | undefined | null, message?: string): asserts value is T;
|
|
52
|
+
/**
|
|
53
|
+
* Format test section header
|
|
54
|
+
*/
|
|
55
|
+
export declare function logSection(title: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Format test step log
|
|
58
|
+
*/
|
|
59
|
+
export declare function logStep(step: string, detail?: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Generate a random token symbol for testing
|
|
62
|
+
*/
|
|
63
|
+
export declare function generateRandomSymbol(prefix?: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Normalize an address to checksum format for comparison
|
|
66
|
+
*/
|
|
67
|
+
export declare function normalizeAddress(address: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Check if two addresses are equal (case-insensitive)
|
|
70
|
+
*/
|
|
71
|
+
export declare function addressEquals(addr1: string, addr2: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Check if an array of addresses includes a specific address (case-insensitive)
|
|
74
|
+
*/
|
|
75
|
+
export declare function addressArrayIncludes(addresses: string[], targetAddress: string): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test setup and account generation
|
|
3
|
+
*/
|
|
4
|
+
import type { PrivateKeyAccount } from 'viem/accounts';
|
|
5
|
+
export interface TestAccount extends PrivateKeyAccount {
|
|
6
|
+
privateKey: `0x${string}`;
|
|
7
|
+
}
|
|
8
|
+
export interface TestAccounts {
|
|
9
|
+
operator: TestAccount;
|
|
10
|
+
master: TestAccount;
|
|
11
|
+
user1: TestAccount;
|
|
12
|
+
user2: TestAccount;
|
|
13
|
+
user3: TestAccount;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generate and cache test accounts
|
|
17
|
+
*/
|
|
18
|
+
export declare function getTestAccounts(): TestAccounts;
|
|
19
|
+
/**
|
|
20
|
+
* Log test account information
|
|
21
|
+
*/
|
|
22
|
+
export declare function logTestAccounts(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Reset test accounts (for cleanup)
|
|
25
|
+
*/
|
|
26
|
+
export declare function resetTestAccounts(): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AccountInfo, AssociatedTokenAccount } from './types';
|
|
1
|
+
import type { AccountInfo, AssociatedTokenAccount, BbNonceInfo } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Accounts API methods
|
|
4
4
|
*/
|
|
@@ -9,6 +9,12 @@ export declare const accountsApi: {
|
|
|
9
9
|
* @returns Promise with account info response
|
|
10
10
|
*/
|
|
11
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 account bbnonce
|
|
14
|
+
* @param address Address of the account to lookup nonce for
|
|
15
|
+
* @returns Promise with bbnonce info response
|
|
16
|
+
*/
|
|
17
|
+
getBbNonce: (address: string) => import("../../client/index.js").PromiseWrapper<"custom", BbNonceInfo, BbNonceInfo, BbNonceInfo, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | BbNonceInfo, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<BbNonceInfo>;
|
|
12
18
|
/**
|
|
13
19
|
* Get associated token account
|
|
14
20
|
* @param address Address of the account to lookup associated token account for
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { U256Schema } from '../types';
|
|
2
2
|
export interface AccountInfo {
|
|
3
3
|
nonce: number;
|
|
4
4
|
}
|
|
5
|
+
export interface BbNonceInfo {
|
|
6
|
+
bbnonce: number;
|
|
7
|
+
}
|
|
5
8
|
export interface AssociatedTokenAccount {
|
|
6
|
-
token_account_address: AddressSchema;
|
|
7
9
|
balance: U256Schema;
|
|
8
10
|
nonce: number;
|
|
9
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CheckpointNumberResponse,
|
|
1
|
+
import type { Checkpoint, CheckpointNumberResponse, CheckpointReceipts } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Checkpoint API methods
|
|
4
4
|
*/
|
|
@@ -22,5 +22,11 @@ export declare const checkpointsApi: {
|
|
|
22
22
|
* @returns Promise with checkpoint response
|
|
23
23
|
*/
|
|
24
24
|
getByNumber: (number: number | string, full?: boolean) => import("../../client/index.js").PromiseWrapper<"custom", Checkpoint, Checkpoint, Checkpoint, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Checkpoint, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Checkpoint>;
|
|
25
|
+
/**
|
|
26
|
+
* Get checkpoint receipts by number
|
|
27
|
+
* @param number Number of the checkpoint to lookup
|
|
28
|
+
* @returns Promise with checkpoint receipts response
|
|
29
|
+
*/
|
|
30
|
+
getReceiptsByNumber: (number: number | string) => import("../../client/index.js").PromiseWrapper<"custom", CheckpointReceipts, CheckpointReceipts, CheckpointReceipts, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | CheckpointReceipts, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<CheckpointReceipts>;
|
|
25
31
|
};
|
|
26
32
|
export default checkpointsApi;
|
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
import { B256Schema
|
|
1
|
+
import { B256Schema } from '../types';
|
|
2
|
+
import type { Transaction, TransactionReceipt } from '../transactions/types';
|
|
2
3
|
export interface CheckpointNumberResponse {
|
|
3
4
|
number: number;
|
|
4
5
|
}
|
|
5
|
-
export
|
|
6
|
-
hash: B256Schema;
|
|
7
|
-
chain_id: number;
|
|
8
|
-
from: AddressSchema;
|
|
9
|
-
nonce: number;
|
|
10
|
-
fee: number;
|
|
11
|
-
signature: {
|
|
12
|
-
r: string;
|
|
13
|
-
s: string;
|
|
14
|
-
v: number;
|
|
15
|
-
};
|
|
16
|
-
checkpoint_hash?: B256Schema;
|
|
17
|
-
checkpoint_number?: number;
|
|
18
|
-
transaction_index?: number;
|
|
19
|
-
}
|
|
6
|
+
export type { Transaction };
|
|
20
7
|
export interface Header {
|
|
21
8
|
hash: B256Schema;
|
|
22
9
|
parent_hash: B256Schema;
|
|
@@ -31,3 +18,4 @@ export interface Checkpoint extends Header {
|
|
|
31
18
|
size?: number;
|
|
32
19
|
transactions: Transaction[] | B256Schema[];
|
|
33
20
|
}
|
|
21
|
+
export type CheckpointReceipts = TransactionReceipt[];
|
package/es/api/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import'viem';import'@ethereumjs/rlp';import axios$1 from'axios';function _typeof(ele) {
|
|
2
2
|
if (typeof ele !== 'object')
|
|
3
3
|
return (typeof ele).toLowerCase();
|
|
4
4
|
const typeStr = Object.prototype.toString.call(ele);
|
|
@@ -116,7 +116,11 @@ class Request {
|
|
|
116
116
|
request(options) {
|
|
117
117
|
// Set default security headers
|
|
118
118
|
options.withCredentials = typeof options.withCredentials === 'boolean' ? options.withCredentials : true;
|
|
119
|
-
options.headers =
|
|
119
|
+
options.headers = {
|
|
120
|
+
...axios$1.defaults.headers.common,
|
|
121
|
+
...(options.method ? axios$1.defaults.headers[options.method] : {}),
|
|
122
|
+
...options.headers,
|
|
123
|
+
};
|
|
120
124
|
options.headers['Accept'] = options.headers['Accept'] || '*/*';
|
|
121
125
|
options.headers['X-Requested-With'] = options.headers['X-Requested-With'] || 'XMLHttpRequest';
|
|
122
126
|
options.headers['X-Content-Type-Options'] = options.headers['X-Content-Type-Options'] || 'nosniff';
|
|
@@ -261,9 +265,9 @@ class Request {
|
|
|
261
265
|
if (isTimeout)
|
|
262
266
|
return;
|
|
263
267
|
cleanup();
|
|
264
|
-
console.error(`[1Money client]: Error(${err.status ?? 500}, ${err.code ?? 'UNKNOWN'}), Message: ${err.message}, Config: ${err.config?.method}, ${err.config?.baseURL ?? ''}${err.config?.url ?? ''}, ${JSON.stringify(err.config?.headers ?? {})}, Request: ${JSON.stringify(err.config?.data ?? {})};`);
|
|
265
|
-
const status = err.response?.status ?? 500;
|
|
266
268
|
const data = err.response?.data ?? {};
|
|
269
|
+
console.error(`[1Money client]: Error(${err.status ?? 500}, ${err.code ?? 'UNKNOWN'}), Message: ${err.message}, Config: ${err.config?.method}, ${err.config?.baseURL ?? ''}, ${err.config?.url ?? ''}, ${JSON.stringify(err.config?.headers ?? {})}, Request: ${JSON.stringify(err.config?.data ?? {})}, Response: ${JSON.stringify(data)};`);
|
|
270
|
+
const status = err.response?.status ?? 500;
|
|
267
271
|
const headers = err.response?.headers ?? {};
|
|
268
272
|
try {
|
|
269
273
|
let res = data;
|
|
@@ -329,6 +333,14 @@ const accountsApi = {
|
|
|
329
333
|
getNonce: (address) => {
|
|
330
334
|
return get(`${API_PREFIX$4}/nonce?address=${address}`, { withCredentials: false });
|
|
331
335
|
},
|
|
336
|
+
/**
|
|
337
|
+
* Get account bbnonce
|
|
338
|
+
* @param address Address of the account to lookup nonce for
|
|
339
|
+
* @returns Promise with bbnonce info response
|
|
340
|
+
*/
|
|
341
|
+
getBbNonce: (address) => {
|
|
342
|
+
return get(`${API_PREFIX$4}/bbnonce?address=${address}`, { withCredentials: false });
|
|
343
|
+
},
|
|
332
344
|
/**
|
|
333
345
|
* Get associated token account
|
|
334
346
|
* @param address Address of the account to lookup associated token account for
|
|
@@ -367,6 +379,14 @@ const checkpointsApi = {
|
|
|
367
379
|
*/
|
|
368
380
|
getByNumber: (number, full = false) => {
|
|
369
381
|
return get(`${API_PREFIX$3}/by_number?number=${number}&full=${full}`, { withCredentials: false });
|
|
382
|
+
},
|
|
383
|
+
/**
|
|
384
|
+
* Get checkpoint receipts by number
|
|
385
|
+
* @param number Number of the checkpoint to lookup
|
|
386
|
+
* @returns Promise with checkpoint receipts response
|
|
387
|
+
*/
|
|
388
|
+
getReceiptsByNumber: (number) => {
|
|
389
|
+
return get(`${API_PREFIX$3}/receipts/by_number?number=${number}`, { withCredentials: false });
|
|
370
390
|
}
|
|
371
391
|
};const API_PREFIX$2 = `/${API_VERSION}/tokens`;
|
|
372
392
|
/**
|
|
@@ -444,6 +464,22 @@ const tokensApi = {
|
|
|
444
464
|
*/
|
|
445
465
|
updateMetadata: (payload) => {
|
|
446
466
|
return post(`${API_PREFIX$2}/update_metadata`, payload, { withCredentials: false });
|
|
467
|
+
},
|
|
468
|
+
/**
|
|
469
|
+
* Bridge and mint tokens
|
|
470
|
+
* @param payload Token bridge and mint request payload
|
|
471
|
+
* @returns Promise with transaction hash response
|
|
472
|
+
*/
|
|
473
|
+
bridgeAndMint: (payload) => {
|
|
474
|
+
return post(`${API_PREFIX$2}/bridge_and_mint`, payload, { withCredentials: false });
|
|
475
|
+
},
|
|
476
|
+
/**
|
|
477
|
+
* Burn and bridge tokens
|
|
478
|
+
* @param payload Token burn and bridge request payload
|
|
479
|
+
* @returns Promise with transaction hash response
|
|
480
|
+
*/
|
|
481
|
+
burnAndBridge: (payload) => {
|
|
482
|
+
return post(`${API_PREFIX$2}/burn_and_bridge`, payload, { withCredentials: false });
|
|
447
483
|
}
|
|
448
484
|
};const API_PREFIX$1 = `/${API_VERSION}/transactions`;
|
|
449
485
|
/**
|
|
@@ -466,6 +502,14 @@ const transactionsApi = {
|
|
|
466
502
|
getReceiptByHash: (hash) => {
|
|
467
503
|
return get(`${API_PREFIX$1}/receipt/by_hash?hash=${hash}`, { withCredentials: false });
|
|
468
504
|
},
|
|
505
|
+
/**
|
|
506
|
+
* Get finalized transaction by hash
|
|
507
|
+
* @param hash Hash of the transaction to lookup
|
|
508
|
+
* @returns Promise with finalized transaction receipt response
|
|
509
|
+
*/
|
|
510
|
+
getFinalizedByHash: (hash) => {
|
|
511
|
+
return get(`${API_PREFIX$1}/finalized/by_hash?hash=${hash}`, { withCredentials: false });
|
|
512
|
+
},
|
|
469
513
|
/**
|
|
470
514
|
* Estimate transaction fee
|
|
471
515
|
* @param from Address of the transaction author
|
|
@@ -503,11 +547,12 @@ const chainApi = {
|
|
|
503
547
|
};// Authority types
|
|
504
548
|
var AuthorityType;
|
|
505
549
|
(function (AuthorityType) {
|
|
506
|
-
AuthorityType["MasterMint"] = "
|
|
550
|
+
AuthorityType["MasterMint"] = "MasterMintBurn";
|
|
507
551
|
AuthorityType["MintBurnTokens"] = "MintBurnTokens";
|
|
508
552
|
AuthorityType["Pause"] = "Pause";
|
|
509
553
|
AuthorityType["ManageList"] = "ManageList";
|
|
510
554
|
AuthorityType["UpdateMetadata"] = "UpdateMetadata";
|
|
555
|
+
AuthorityType["Bridge"] = "Bridge";
|
|
511
556
|
})(AuthorityType || (AuthorityType = {}));
|
|
512
557
|
var AuthorityAction;
|
|
513
558
|
(function (AuthorityAction) {
|
package/es/api/tokens/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Hash, HashWithToken } from '../../api/types';
|
|
2
|
-
import type { MintInfo, TokenManageListPayload, TokenBurnPayload, TokenAuthorityPayload, TokenIssuePayload, TokenMintPayload, TokenPausePayload, TokenMetadataPayload } from './types';
|
|
2
|
+
import type { MintInfo, TokenManageListPayload, TokenBurnPayload, TokenAuthorityPayload, TokenIssuePayload, TokenMintPayload, TokenPausePayload, TokenMetadataPayload, TokenBridgeAndMintPayload, TokenBurnAndBridgePayload } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Tokens API methods
|
|
5
5
|
*/
|
|
@@ -58,5 +58,17 @@ export declare const tokensApi: {
|
|
|
58
58
|
* @returns Promise with transaction hash response
|
|
59
59
|
*/
|
|
60
60
|
updateMetadata: (payload: TokenMetadataPayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
61
|
+
/**
|
|
62
|
+
* Bridge and mint tokens
|
|
63
|
+
* @param payload Token bridge and mint request payload
|
|
64
|
+
* @returns Promise with transaction hash response
|
|
65
|
+
*/
|
|
66
|
+
bridgeAndMint: (payload: TokenBridgeAndMintPayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
67
|
+
/**
|
|
68
|
+
* Burn and bridge tokens
|
|
69
|
+
* @param payload Token burn and bridge request payload
|
|
70
|
+
* @returns Promise with transaction hash response
|
|
71
|
+
*/
|
|
72
|
+
burnAndBridge: (payload: TokenBurnAndBridgePayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
61
73
|
};
|
|
62
74
|
export default tokensApi;
|