@1money/protocol-ts-sdk 1.1.2-alpha.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +2 -1
- package/README.md +244 -134
- package/es/__integration__/helpers.d.ts +0 -7
- package/es/api/checkpoints/types.d.ts +0 -1
- package/es/api/index.js +17 -10
- package/es/api/tokens/index.d.ts +7 -1
- package/es/api/tokens/types.d.ts +21 -6
- package/es/api/transactions/index.d.ts +4 -3
- package/es/api/transactions/types.d.ts +14 -5
- package/es/client/index.js +4 -4
- package/es/index.d.ts +1 -0
- package/es/index.js +481 -22
- package/es/signing/builders/index.d.ts +11 -0
- package/es/signing/builders/payment.d.ts +3 -0
- package/es/signing/builders/tokenAuthority.d.ts +3 -0
- package/es/signing/builders/tokenBridgeAndMint.d.ts +3 -0
- package/es/signing/builders/tokenBurn.d.ts +3 -0
- package/es/signing/builders/tokenBurnAndBridge.d.ts +3 -0
- package/es/signing/builders/tokenClawback.d.ts +3 -0
- package/es/signing/builders/tokenIssue.d.ts +3 -0
- package/es/signing/builders/tokenManageList.d.ts +3 -0
- package/es/signing/builders/tokenMetadata.d.ts +3 -0
- package/es/signing/builders/tokenMint.d.ts +3 -0
- package/es/signing/builders/tokenPause.d.ts +3 -0
- package/es/signing/builders/validate.d.ts +18 -0
- package/es/signing/core.d.ts +27 -0
- package/es/signing/index.d.ts +18 -0
- package/es/signing/signer.d.ts +3 -0
- package/es/utils/encode.d.ts +11 -0
- package/es/utils/index.d.ts +2 -1
- package/es/utils/index.js +90 -10
- package/es/utils/interface.d.ts +27 -0
- package/es/utils/sign.d.ts +6 -1
- package/lib/__integration__/helpers.d.ts +0 -7
- package/lib/api/checkpoints/types.d.ts +0 -1
- package/lib/api/index.js +17 -10
- package/lib/api/tokens/index.d.ts +7 -1
- package/lib/api/tokens/types.d.ts +21 -6
- package/lib/api/transactions/index.d.ts +4 -3
- package/lib/api/transactions/types.d.ts +14 -5
- package/lib/client/index.js +4 -4
- package/lib/index.d.ts +1 -0
- package/lib/index.js +469 -21
- package/lib/signing/builders/index.d.ts +11 -0
- package/lib/signing/builders/payment.d.ts +3 -0
- package/lib/signing/builders/tokenAuthority.d.ts +3 -0
- package/lib/signing/builders/tokenBridgeAndMint.d.ts +3 -0
- package/lib/signing/builders/tokenBurn.d.ts +3 -0
- package/lib/signing/builders/tokenBurnAndBridge.d.ts +3 -0
- package/lib/signing/builders/tokenClawback.d.ts +3 -0
- package/lib/signing/builders/tokenIssue.d.ts +3 -0
- package/lib/signing/builders/tokenManageList.d.ts +3 -0
- package/lib/signing/builders/tokenMetadata.d.ts +3 -0
- package/lib/signing/builders/tokenMint.d.ts +3 -0
- package/lib/signing/builders/tokenPause.d.ts +3 -0
- package/lib/signing/builders/validate.d.ts +18 -0
- package/lib/signing/core.d.ts +27 -0
- package/lib/signing/index.d.ts +18 -0
- package/lib/signing/signer.d.ts +3 -0
- package/lib/utils/encode.d.ts +11 -0
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +90 -10
- package/lib/utils/interface.d.ts +27 -0
- package/lib/utils/sign.d.ts +6 -1
- package/package.json +2 -2
- package/umd/1money-protocol-ts-sdk.min.js +3 -2
- package/.env.integration +0 -16
- package/umd/1money-ts-sdk.min.js +0 -2
package/README.md
CHANGED
|
@@ -37,6 +37,34 @@ const apiClient = api({
|
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
### Configure Custom HTTP Headers
|
|
41
|
+
|
|
42
|
+
You can set custom HTTP headers that will be included in all API requests:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { setInitConfig } from '@1money/protocol-ts-sdk';
|
|
46
|
+
|
|
47
|
+
// Set custom headers for all requests
|
|
48
|
+
setInitConfig({
|
|
49
|
+
headers: {
|
|
50
|
+
'Authorization': 'Bearer your-token',
|
|
51
|
+
'X-Custom-Header': 'custom-value'
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// You can also combine with other configuration options
|
|
56
|
+
setInitConfig({
|
|
57
|
+
baseURL: 'https://api.custom-domain.com',
|
|
58
|
+
timeout: 10000,
|
|
59
|
+
headers: {
|
|
60
|
+
'Authorization': 'Bearer your-token',
|
|
61
|
+
'X-API-Key': 'your-api-key'
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Note**: Custom headers are automatically merged with axios default headers, ensuring both your custom headers and the library's default security headers are included in all requests.
|
|
67
|
+
|
|
40
68
|
### Fetch the current checkpoint number
|
|
41
69
|
|
|
42
70
|
```typescript
|
|
@@ -207,43 +235,40 @@ apiClient.tokens.getTokenMetadata(tokenAddress)
|
|
|
207
235
|
|
|
208
236
|
#### Issue New Token
|
|
209
237
|
```typescript
|
|
210
|
-
import {
|
|
238
|
+
import {
|
|
239
|
+
TransactionBuilder,
|
|
240
|
+
createPrivateKeySigner
|
|
241
|
+
} from '@1money/protocol-ts-sdk';
|
|
211
242
|
|
|
212
243
|
// Your private key (DO NOT share or commit your private key)
|
|
213
244
|
const privateKey = 'YOUR_PRIVATE_KEY';
|
|
245
|
+
const masterAuthority = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
|
|
214
246
|
|
|
215
|
-
//
|
|
216
|
-
const
|
|
247
|
+
// Get chain id and current nonce
|
|
248
|
+
const { chain_id } = await apiClient.chain.getChainId()
|
|
249
|
+
.success(response => response);
|
|
250
|
+
const { nonce } = await apiClient.accounts.getNonce(masterAuthority)
|
|
217
251
|
.success(response => response);
|
|
218
252
|
|
|
219
|
-
//
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
'MTK', // symbol
|
|
224
|
-
'My Token', // name
|
|
225
|
-
18, // decimals
|
|
226
|
-
'0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3', // master_authority
|
|
227
|
-
true, // is_private
|
|
228
|
-
];
|
|
229
|
-
|
|
230
|
-
// Generate signature
|
|
231
|
-
const signature = await signMessage(payload, privateKey);
|
|
232
|
-
if (!signature) {
|
|
233
|
-
throw new Error('Failed to generate signature');
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Create the issue payload
|
|
237
|
-
const issuePayload = {
|
|
238
|
-
chain_id: 1,
|
|
239
|
-
nonce: 1,
|
|
240
|
-
name: 'My Token',
|
|
253
|
+
// Build transaction and prepare signature hash internally
|
|
254
|
+
const prepared = TransactionBuilder.tokenIssue({
|
|
255
|
+
chain_id,
|
|
256
|
+
nonce,
|
|
241
257
|
symbol: 'MTK',
|
|
258
|
+
name: 'My Token',
|
|
242
259
|
decimals: 18,
|
|
243
|
-
master_authority:
|
|
260
|
+
master_authority: masterAuthority,
|
|
244
261
|
is_private: true,
|
|
245
|
-
|
|
246
|
-
};
|
|
262
|
+
clawback_enabled: true
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// Sign with private key
|
|
266
|
+
const signed = await prepared.sign(
|
|
267
|
+
createPrivateKeySigner(privateKey as `0x${string}`)
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
// Build request body with signature
|
|
271
|
+
const issuePayload = signed.toRequest();
|
|
247
272
|
|
|
248
273
|
apiClient.tokens.issueToken(issuePayload)
|
|
249
274
|
.success(response => {
|
|
@@ -256,40 +281,38 @@ apiClient.tokens.issueToken(issuePayload)
|
|
|
256
281
|
|
|
257
282
|
#### Manage Token Blacklist/Whitelist
|
|
258
283
|
```typescript
|
|
259
|
-
import {
|
|
260
|
-
|
|
284
|
+
import {
|
|
285
|
+
ManageListAction,
|
|
286
|
+
TransactionBuilder,
|
|
287
|
+
createPrivateKeySigner
|
|
288
|
+
} from '@1money/protocol-ts-sdk';
|
|
261
289
|
|
|
262
290
|
// Your private key (DO NOT share or commit your private key)
|
|
263
291
|
const privateKey = 'YOUR_PRIVATE_KEY';
|
|
292
|
+
const operatorAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
|
|
264
293
|
|
|
265
|
-
//
|
|
266
|
-
const
|
|
294
|
+
// Get chain id and current nonce
|
|
295
|
+
const { chain_id } = await apiClient.chain.getChainId()
|
|
296
|
+
.success(response => response);
|
|
297
|
+
const { nonce } = await apiClient.accounts.getNonce(operatorAddress)
|
|
267
298
|
.success(response => response);
|
|
268
299
|
|
|
269
|
-
//
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
ManageListAction.Add,
|
|
274
|
-
|
|
275
|
-
'0x2cd8999Be299373D7881f4aDD11510030ad1412F'
|
|
276
|
-
|
|
300
|
+
// Build transaction and prepare signature hash internally
|
|
301
|
+
const prepared = TransactionBuilder.tokenManageList({
|
|
302
|
+
chain_id,
|
|
303
|
+
nonce,
|
|
304
|
+
action: ManageListAction.Add,
|
|
305
|
+
address: operatorAddress,
|
|
306
|
+
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F'
|
|
307
|
+
});
|
|
277
308
|
|
|
278
|
-
//
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
309
|
+
// Sign with private key
|
|
310
|
+
const signed = await prepared.sign(
|
|
311
|
+
createPrivateKeySigner(privateKey as `0x${string}`)
|
|
312
|
+
);
|
|
283
313
|
|
|
284
|
-
//
|
|
285
|
-
const manageListPayload =
|
|
286
|
-
chain_id: 1,
|
|
287
|
-
nonce: 1,
|
|
288
|
-
action: ManageListAction.Add,
|
|
289
|
-
address: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
|
|
290
|
-
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
291
|
-
signature
|
|
292
|
-
};
|
|
314
|
+
// Build request body with signature
|
|
315
|
+
const manageListPayload = signed.toRequest();
|
|
293
316
|
|
|
294
317
|
// Use manageBlacklist for blacklist operations
|
|
295
318
|
apiClient.tokens.manageBlacklist(manageListPayload)
|
|
@@ -312,39 +335,36 @@ apiClient.tokens.manageWhitelist(manageListPayload)
|
|
|
312
335
|
|
|
313
336
|
#### Burn Tokens
|
|
314
337
|
```typescript
|
|
315
|
-
import {
|
|
338
|
+
import {
|
|
339
|
+
TransactionBuilder,
|
|
340
|
+
createPrivateKeySigner
|
|
341
|
+
} from '@1money/protocol-ts-sdk';
|
|
316
342
|
|
|
317
343
|
// Your private key (DO NOT share or commit your private key)
|
|
318
344
|
const privateKey = 'YOUR_PRIVATE_KEY';
|
|
345
|
+
const ownerAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
|
|
319
346
|
|
|
320
|
-
//
|
|
321
|
-
const
|
|
347
|
+
// Get chain id and current nonce
|
|
348
|
+
const { chain_id } = await apiClient.chain.getChainId()
|
|
349
|
+
.success(response => response);
|
|
350
|
+
const { nonce } = await apiClient.accounts.getNonce(ownerAddress)
|
|
322
351
|
.success(response => response);
|
|
323
352
|
|
|
324
|
-
//
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
'
|
|
329
|
-
'
|
|
330
|
-
|
|
331
|
-
];
|
|
353
|
+
// Build transaction and prepare signature hash internally
|
|
354
|
+
const prepared = TransactionBuilder.tokenBurn({
|
|
355
|
+
chain_id,
|
|
356
|
+
nonce,
|
|
357
|
+
value: '1000000000000000000',
|
|
358
|
+
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F'
|
|
359
|
+
});
|
|
332
360
|
|
|
333
|
-
//
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
361
|
+
// Sign with private key
|
|
362
|
+
const signed = await prepared.sign(
|
|
363
|
+
createPrivateKeySigner(privateKey as `0x${string}`)
|
|
364
|
+
);
|
|
338
365
|
|
|
339
|
-
//
|
|
340
|
-
const burnPayload =
|
|
341
|
-
chain_id: 1,
|
|
342
|
-
nonce: 1,
|
|
343
|
-
recipient: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
344
|
-
value: '1000000000000000000',
|
|
345
|
-
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
346
|
-
signature
|
|
347
|
-
};
|
|
366
|
+
// Build request body with signature
|
|
367
|
+
const burnPayload = signed.toRequest();
|
|
348
368
|
|
|
349
369
|
apiClient.tokens.burnToken(burnPayload)
|
|
350
370
|
.success(response => {
|
|
@@ -357,44 +377,41 @@ apiClient.tokens.burnToken(burnPayload)
|
|
|
357
377
|
|
|
358
378
|
#### Grant Token Authority
|
|
359
379
|
```typescript
|
|
360
|
-
import {
|
|
361
|
-
|
|
380
|
+
import {
|
|
381
|
+
AuthorityAction,
|
|
382
|
+
AuthorityType,
|
|
383
|
+
TransactionBuilder,
|
|
384
|
+
createPrivateKeySigner
|
|
385
|
+
} from '@1money/protocol-ts-sdk';
|
|
362
386
|
|
|
363
387
|
// Your private key (DO NOT share or commit your private key)
|
|
364
388
|
const privateKey = 'YOUR_PRIVATE_KEY';
|
|
389
|
+
const masterAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
|
|
365
390
|
|
|
366
|
-
//
|
|
367
|
-
const
|
|
391
|
+
// Get chain id and current nonce
|
|
392
|
+
const { chain_id } = await apiClient.chain.getChainId()
|
|
393
|
+
.success(response => response);
|
|
394
|
+
const { nonce } = await apiClient.accounts.getNonce(masterAddress)
|
|
368
395
|
.success(response => response);
|
|
369
396
|
|
|
370
|
-
//
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
AuthorityAction.Grant, // action
|
|
375
|
-
AuthorityType.MasterMint, // authority_type (sends 'MasterMintBurn')
|
|
376
|
-
'0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3', // authority_address
|
|
377
|
-
'0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
|
|
378
|
-
'1000000000000000000000', // value (optional, for MintBurnTokens type)
|
|
379
|
-
];
|
|
380
|
-
|
|
381
|
-
// Generate signature
|
|
382
|
-
const signature = await signMessage(payload, privateKey);
|
|
383
|
-
if (!signature) {
|
|
384
|
-
throw new Error('Failed to generate signature');
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// Create the authority payload
|
|
388
|
-
const authorityPayload = {
|
|
389
|
-
chain_id: 1,
|
|
390
|
-
nonce: 1,
|
|
397
|
+
// Build transaction and prepare signature hash internally
|
|
398
|
+
const prepared = TransactionBuilder.tokenAuthority({
|
|
399
|
+
chain_id,
|
|
400
|
+
nonce,
|
|
391
401
|
action: AuthorityAction.Grant,
|
|
392
|
-
authority_type: AuthorityType.MasterMint,
|
|
402
|
+
authority_type: AuthorityType.MasterMint,
|
|
393
403
|
authority_address: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
|
|
394
404
|
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
395
|
-
value: '1000000000000000000000'
|
|
396
|
-
|
|
397
|
-
|
|
405
|
+
value: '1000000000000000000000'
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
// Sign with private key
|
|
409
|
+
const signed = await prepared.sign(
|
|
410
|
+
createPrivateKeySigner(privateKey as `0x${string}`)
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
// Build request body with signature
|
|
414
|
+
const authorityPayload = signed.toRequest();
|
|
398
415
|
|
|
399
416
|
apiClient.tokens.grantAuthority(authorityPayload)
|
|
400
417
|
.success(response => {
|
|
@@ -405,6 +422,100 @@ apiClient.tokens.grantAuthority(authorityPayload)
|
|
|
405
422
|
});
|
|
406
423
|
```
|
|
407
424
|
|
|
425
|
+
#### Bridge and Mint
|
|
426
|
+
```typescript
|
|
427
|
+
import {
|
|
428
|
+
TransactionBuilder,
|
|
429
|
+
createPrivateKeySigner
|
|
430
|
+
} from '@1money/protocol-ts-sdk';
|
|
431
|
+
|
|
432
|
+
// Your private key (DO NOT share or commit your private key)
|
|
433
|
+
const privateKey = 'YOUR_PRIVATE_KEY';
|
|
434
|
+
const bridgeOperatorAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
|
|
435
|
+
|
|
436
|
+
// Get chain id and current nonce
|
|
437
|
+
const { chain_id } = await apiClient.chain.getChainId()
|
|
438
|
+
.success(response => response);
|
|
439
|
+
const { nonce } = await apiClient.accounts.getNonce(bridgeOperatorAddress)
|
|
440
|
+
.success(response => response);
|
|
441
|
+
|
|
442
|
+
// Build transaction and prepare signature hash internally
|
|
443
|
+
const prepared = TransactionBuilder.tokenBridgeAndMint({
|
|
444
|
+
chain_id,
|
|
445
|
+
nonce,
|
|
446
|
+
recipient: '0x6324dAc598f9B637824978eD6b268C896E0c40E0',
|
|
447
|
+
value: '25000000000000000000',
|
|
448
|
+
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
449
|
+
source_chain_id: 1,
|
|
450
|
+
source_tx_hash: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
451
|
+
bridge_metadata: 'bridge_from_chain_1'
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// Sign with private key
|
|
455
|
+
const signed = await prepared.sign(
|
|
456
|
+
createPrivateKeySigner(privateKey as `0x${string}`)
|
|
457
|
+
);
|
|
458
|
+
|
|
459
|
+
// Build request body with signature
|
|
460
|
+
const bridgeAndMintPayload = signed.toRequest();
|
|
461
|
+
|
|
462
|
+
apiClient.tokens.bridgeAndMint(bridgeAndMintPayload)
|
|
463
|
+
.success(response => {
|
|
464
|
+
console.log('Bridge and mint transaction hash:', response.hash);
|
|
465
|
+
})
|
|
466
|
+
.error(err => {
|
|
467
|
+
console.error('Error:', err);
|
|
468
|
+
});
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
#### Burn and Bridge
|
|
472
|
+
```typescript
|
|
473
|
+
import {
|
|
474
|
+
TransactionBuilder,
|
|
475
|
+
createPrivateKeySigner
|
|
476
|
+
} from '@1money/protocol-ts-sdk';
|
|
477
|
+
|
|
478
|
+
// Your private key (DO NOT share or commit your private key)
|
|
479
|
+
const privateKey = 'YOUR_PRIVATE_KEY';
|
|
480
|
+
const senderAddress = '0x6324dAc598f9B637824978eD6b268C896E0c40E0';
|
|
481
|
+
|
|
482
|
+
// Get chain id and current nonce
|
|
483
|
+
const { chain_id } = await apiClient.chain.getChainId()
|
|
484
|
+
.success(response => response);
|
|
485
|
+
const { nonce } = await apiClient.accounts.getNonce(senderAddress)
|
|
486
|
+
.success(response => response);
|
|
487
|
+
|
|
488
|
+
// Build transaction and prepare signature hash internally
|
|
489
|
+
const prepared = TransactionBuilder.tokenBurnAndBridge({
|
|
490
|
+
chain_id,
|
|
491
|
+
nonce,
|
|
492
|
+
sender: senderAddress,
|
|
493
|
+
value: '20000000000000000000',
|
|
494
|
+
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
495
|
+
destination_chain_id: 1,
|
|
496
|
+
destination_address: '0x1234567890abcdef1234567890abcdef12345678',
|
|
497
|
+
escrow_fee: '1000000000000000000',
|
|
498
|
+
bridge_metadata: 'bridge_to_chain_1',
|
|
499
|
+
bridge_param: '0x'
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
// Sign with private key
|
|
503
|
+
const signed = await prepared.sign(
|
|
504
|
+
createPrivateKeySigner(privateKey as `0x${string}`)
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
// Build request body with signature
|
|
508
|
+
const burnAndBridgePayload = signed.toRequest();
|
|
509
|
+
|
|
510
|
+
apiClient.tokens.burnAndBridge(burnAndBridgePayload)
|
|
511
|
+
.success(response => {
|
|
512
|
+
console.log('Burn and bridge transaction hash:', response.hash);
|
|
513
|
+
})
|
|
514
|
+
.error(err => {
|
|
515
|
+
console.error('Error:', err);
|
|
516
|
+
});
|
|
517
|
+
```
|
|
518
|
+
|
|
408
519
|
### Transactions API
|
|
409
520
|
|
|
410
521
|
#### Get Transaction Details
|
|
@@ -434,10 +545,11 @@ apiClient.transactions.getReceiptByHash(txHash)
|
|
|
434
545
|
#### Estimate Transaction Fee
|
|
435
546
|
```typescript
|
|
436
547
|
const fromAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
|
|
548
|
+
const toAddress = '0x6324dAc598f9B637824978eD6b268C896E0c40E0';
|
|
437
549
|
const value = '1000000000';
|
|
438
550
|
const tokenAddress = '0x2cd8999Be299373D7881f4aDD11510030ad1412F';
|
|
439
551
|
|
|
440
|
-
apiClient.transactions.estimateFee(fromAddress, value, tokenAddress)
|
|
552
|
+
apiClient.transactions.estimateFee(fromAddress, toAddress, value, tokenAddress)
|
|
441
553
|
.success(response => {
|
|
442
554
|
console.log('Estimated fee:', response);
|
|
443
555
|
})
|
|
@@ -448,39 +560,37 @@ apiClient.transactions.estimateFee(fromAddress, value, tokenAddress)
|
|
|
448
560
|
|
|
449
561
|
#### Submit Payment Transaction
|
|
450
562
|
```typescript
|
|
451
|
-
import {
|
|
563
|
+
import {
|
|
564
|
+
TransactionBuilder,
|
|
565
|
+
createPrivateKeySigner
|
|
566
|
+
} from '@1money/protocol-ts-sdk';
|
|
452
567
|
|
|
453
568
|
// Your private key (DO NOT share or commit your private key)
|
|
454
569
|
const privateKey = 'YOUR_PRIVATE_KEY';
|
|
570
|
+
const senderAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
|
|
455
571
|
|
|
456
|
-
//
|
|
457
|
-
const
|
|
572
|
+
// Get chain id and current nonce
|
|
573
|
+
const { chain_id } = await apiClient.chain.getChainId()
|
|
574
|
+
.success(response => response);
|
|
575
|
+
const { nonce } = await apiClient.accounts.getNonce(senderAddress)
|
|
458
576
|
.success(response => response);
|
|
459
577
|
|
|
460
|
-
//
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
'
|
|
465
|
-
'1000000000',
|
|
466
|
-
'0x2cd8999Be299373D7881f4aDD11510030ad1412F'
|
|
467
|
-
|
|
578
|
+
// Build transaction and prepare signature hash internally
|
|
579
|
+
const prepared = TransactionBuilder.payment({
|
|
580
|
+
chain_id,
|
|
581
|
+
nonce,
|
|
582
|
+
recipient: '0xa128999Be299373D7881f4aDD11510030ad13512',
|
|
583
|
+
value: '1000000000',
|
|
584
|
+
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F'
|
|
585
|
+
});
|
|
468
586
|
|
|
469
|
-
//
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
587
|
+
// Sign with private key
|
|
588
|
+
const signed = await prepared.sign(
|
|
589
|
+
createPrivateKeySigner(privateKey as `0x${string}`)
|
|
590
|
+
);
|
|
474
591
|
|
|
475
|
-
//
|
|
476
|
-
const paymentPayload =
|
|
477
|
-
chain_id: 1,
|
|
478
|
-
nonce: 1,
|
|
479
|
-
recipient: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
480
|
-
value: '1000000000',
|
|
481
|
-
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
|
|
482
|
-
signature
|
|
483
|
-
};
|
|
592
|
+
// Build request body with signature
|
|
593
|
+
const paymentPayload = signed.toRequest();
|
|
484
594
|
|
|
485
595
|
apiClient.transactions.payment(paymentPayload)
|
|
486
596
|
.success(response => {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Integration test helper utilities
|
|
3
3
|
*/
|
|
4
|
-
import type { RestSignature } from '../api/tokens/types';
|
|
5
|
-
import type { TestAccount } from './setup';
|
|
6
|
-
import type { Payload } from '../utils/interface';
|
|
7
4
|
/**
|
|
8
5
|
* Create API client for integration tests
|
|
9
6
|
*/
|
|
@@ -14,10 +11,6 @@ export declare function createTestClient(): {
|
|
|
14
11
|
transactions: typeof import("../api/transactions").transactionsApi;
|
|
15
12
|
chain: typeof import("../api/chain").chainApi;
|
|
16
13
|
};
|
|
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
14
|
/**
|
|
22
15
|
* Wait for a transaction to be finalized
|
|
23
16
|
* @param txHash Transaction hash
|
package/es/api/index.js
CHANGED
|
@@ -46,7 +46,7 @@ import'viem';import'@ethereumjs/rlp';import axios from'axios';function _typeof(e
|
|
|
46
46
|
this._restScope = scope || this._restScope;
|
|
47
47
|
// @ts-ignore
|
|
48
48
|
if (this._restScope.length === 0) {
|
|
49
|
-
console.warn('[1Money
|
|
49
|
+
console.warn('[1Money SDK]: The ".rest(cb, scope)" scope is empty and will never be triggered!');
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
52
52
|
let deletedCounter = 0;
|
|
@@ -61,7 +61,7 @@ import'viem';import'@ethereumjs/rlp';import axios from'axios';function _typeof(e
|
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
if (deletedCounter === this._restScope.length) {
|
|
64
|
-
console.warn(`[1Money
|
|
64
|
+
console.warn(`[1Money SDK]: The "${this._restScope.join(', ')}" had been called and the "rest" will never be triggered!`);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
return wrapper;
|
|
@@ -110,7 +110,7 @@ class Request {
|
|
|
110
110
|
}
|
|
111
111
|
setting(config) {
|
|
112
112
|
if (!config)
|
|
113
|
-
return console.warn('[1Money
|
|
113
|
+
return console.warn('[1Money SDK]: setting method required correct parameters!');
|
|
114
114
|
this._config = { ...this._config, ...config };
|
|
115
115
|
}
|
|
116
116
|
request(options) {
|
|
@@ -266,7 +266,7 @@ class Request {
|
|
|
266
266
|
return;
|
|
267
267
|
cleanup();
|
|
268
268
|
const data = err.response?.data ?? {};
|
|
269
|
-
console.error(`[1Money
|
|
269
|
+
console.error(`[1Money SDK]: 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
270
|
const status = err.response?.status ?? 500;
|
|
271
271
|
const headers = err.response?.headers ?? {};
|
|
272
272
|
try {
|
|
@@ -487,6 +487,14 @@ const tokensApi = {
|
|
|
487
487
|
*/
|
|
488
488
|
burnAndBridge: (payload) => {
|
|
489
489
|
return post(`${API_PREFIX$2}/burn_and_bridge`, payload, { withCredentials: false });
|
|
490
|
+
},
|
|
491
|
+
/**
|
|
492
|
+
* Claw back tokens from a wallet
|
|
493
|
+
* @param payload Token clawback request payload
|
|
494
|
+
* @returns Promise with transaction hash response
|
|
495
|
+
*/
|
|
496
|
+
clawbackToken: (payload) => {
|
|
497
|
+
return post(`${API_PREFIX$2}/clawback`, payload, { withCredentials: false });
|
|
490
498
|
}
|
|
491
499
|
};const API_PREFIX$1 = `/${API_VERSION}/transactions`;
|
|
492
500
|
/**
|
|
@@ -520,15 +528,13 @@ const transactionsApi = {
|
|
|
520
528
|
/**
|
|
521
529
|
* Estimate transaction fee
|
|
522
530
|
* @param from Address of the transaction author
|
|
531
|
+
* @param to Address of the transaction recipient
|
|
523
532
|
* @param value Value of the transaction
|
|
524
|
-
* @param token
|
|
533
|
+
* @param token Token address
|
|
525
534
|
* @returns Promise with fee estimate response
|
|
526
535
|
*/
|
|
527
|
-
estimateFee: (from, value, token) => {
|
|
528
|
-
|
|
529
|
-
if (token) {
|
|
530
|
-
url += `&token=${token}`;
|
|
531
|
-
}
|
|
536
|
+
estimateFee: (from, to, value, token) => {
|
|
537
|
+
const url = `${API_PREFIX$1}/estimate_fee?from=${from}&value=${value}&to=${to}&token=${token}`;
|
|
532
538
|
return get(url, { withCredentials: false });
|
|
533
539
|
},
|
|
534
540
|
/**
|
|
@@ -560,6 +566,7 @@ var AuthorityType;
|
|
|
560
566
|
AuthorityType["ManageList"] = "ManageList";
|
|
561
567
|
AuthorityType["UpdateMetadata"] = "UpdateMetadata";
|
|
562
568
|
AuthorityType["Bridge"] = "Bridge";
|
|
569
|
+
AuthorityType["Clawback"] = "Clawback";
|
|
563
570
|
})(AuthorityType || (AuthorityType = {}));
|
|
564
571
|
var AuthorityAction;
|
|
565
572
|
(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, TokenBridgeAndMintPayload, TokenBurnAndBridgePayload } from './types';
|
|
2
|
+
import type { MintInfo, TokenManageListPayload, TokenBurnPayload, TokenAuthorityPayload, TokenIssuePayload, TokenMintPayload, TokenPausePayload, TokenMetadataPayload, TokenBridgeAndMintPayload, TokenBurnAndBridgePayload, TokenClawbackPayload } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Tokens API methods
|
|
5
5
|
*/
|
|
@@ -70,5 +70,11 @@ export declare const tokensApi: {
|
|
|
70
70
|
* @returns Promise with transaction hash response
|
|
71
71
|
*/
|
|
72
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>;
|
|
73
|
+
/**
|
|
74
|
+
* Claw back tokens from a wallet
|
|
75
|
+
* @param payload Token clawback request payload
|
|
76
|
+
* @returns Promise with transaction hash response
|
|
77
|
+
*/
|
|
78
|
+
clawbackToken: (payload: TokenClawbackPayload) => 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>;
|
|
73
79
|
};
|
|
74
80
|
export default tokensApi;
|