@amadeus-protocol/sdk 1.1.0 → 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.
Files changed (2) hide show
  1. package/README.md +215 -30
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -20,6 +20,19 @@ pnpm add @amadeus-protocol/sdk
20
20
  bun add @amadeus-protocol/sdk
21
21
  ```
22
22
 
23
+ > **ESM-only**: this package is published as pure ESM (`"type": "module"`). Use Node.js 20+ with `"type": "module"` in your `package.json`, or any modern bundler (Vite, webpack, esbuild, Metro). For CommonJS consumers, run via [`tsx`](https://github.com/privatenumber/tsx). See [Troubleshooting](https://docs.ama.one/sdk/9.-troubleshooting.md) for the `1.0.x` `ERR_MODULE_NOT_FOUND` issue and upgrade path.
24
+
25
+ ## What's New in 1.1.0
26
+
27
+ - **`contract.view()`** — read-only contract execution
28
+ - **`chain.getByFilter()`** / **`chain.getKpi()`** — filtered tx queries + protocol KPIs
29
+ - **`proof.getContractStateProof()`** — merkle proofs for contract state
30
+ - **`submitAndWait(txPacked, { finalized: true })`** — wait for finality instead of confirmation
31
+ - **NFT contract** — `NFT_ABI`, `buildNftTransfer/Mint/CreateCollection`, `TransactionBuilder.nftTransfer/nftMint/nftCreateCollection`
32
+ - **ESM fix** — published `dist/*.js` now resolves correctly under raw `node` (the `1.0.x` `ERR_MODULE_NOT_FOUND` bug)
33
+
34
+ See the [CHANGELOG](./CHANGELOG.md) for full release history.
35
+
23
36
  ## Features
24
37
 
25
38
  - **Canonical Serialization (VecPack)**: Deterministic encoding/decoding for cryptographic operations
@@ -72,6 +85,8 @@ const sdk = new AmadeusSDK({
72
85
  const stats = await sdk.chain.getStats()
73
86
  const tip = await sdk.chain.getTip()
74
87
  const entry = await sdk.chain.getByHash('5Kd3N...')
88
+ const { txs, cursor } = await sdk.chain.getByFilter({ contract: 'Coin', function: 'transfer' })
89
+ const { kpi } = await sdk.chain.getKpi()
75
90
 
76
91
  // Wallet API
77
92
  const balance = await sdk.wallet.getBalance('5Kd3N...', 'AMA')
@@ -79,12 +94,18 @@ const allBalances = await sdk.wallet.getAllBalances('5Kd3N...')
79
94
 
80
95
  // Transaction API
81
96
  const result = await sdk.transaction.submit(txPacked)
82
- const resultWithWait = await sdk.transaction.submitAndWait(txPacked)
97
+ const confirmed = await sdk.transaction.submitAndWait(txPacked)
98
+ const finalized = await sdk.transaction.submitAndWait(txPacked, { finalized: true })
83
99
  const tx = await sdk.transaction.get('5Kd3N...')
84
100
 
85
101
  // Contract API
86
102
  const contractData = await sdk.contract.get(key)
87
103
  const richlist = await sdk.contract.getRichlist()
104
+ const { success, result } = await sdk.contract.view({
105
+ contract: 'LockupPrime',
106
+ function: 'view_balance',
107
+ args: ['my_vault']
108
+ })
88
109
 
89
110
  // Epoch API
90
111
  const scores = await sdk.epoch.getScore()
@@ -93,6 +114,10 @@ const emission = await sdk.epoch.getEmissionAddress('5Kd3N...')
93
114
  // Peer API
94
115
  const nodes = await sdk.peer.getNodes()
95
116
  const trainers = await sdk.peer.getTrainers()
117
+
118
+ // Proof API
119
+ const validatorProof = await sdk.proof.getValidators(entryHash)
120
+ const stateProof = await sdk.proof.getContractStateProof(stateKey)
96
121
  ```
97
122
 
98
123
  ### Key Generation
@@ -151,6 +176,137 @@ const { txHash, txPacked } = builder.buildAndSign('Coin', 'transfer', [
151
176
  ])
152
177
  ```
153
178
 
179
+ #### ABI-Driven (Lockup, LockupPrime, etc.)
180
+
181
+ The recommended pattern for built-in contracts. Pass any ABI to `builder.contract(abi)` and get fully-typed function calls:
182
+
183
+ ```typescript
184
+ import {
185
+ TransactionBuilder,
186
+ LOCKUP_PRIME_ABI,
187
+ LOCKUP_ABI,
188
+ toAtomicAma
189
+ } from '@amadeus-protocol/sdk'
190
+
191
+ const builder = new TransactionBuilder('5Kd3N...')
192
+
193
+ // LockupPrime — auto-typed methods derived from the ABI
194
+ builder.contract(LOCKUP_PRIME_ABI).lock({ amount: toAtomicAma(100).toString(), tier: '30d' })
195
+ builder.contract(LOCKUP_PRIME_ABI).unlock({ vaultIndex: '3' })
196
+ builder.contract(LOCKUP_PRIME_ABI).daily_checkin({ vaultIndex: '7' })
197
+
198
+ // Lockup
199
+ builder.contract(LOCKUP_ABI).unlock({ vaultIndex: '5' })
200
+ ```
201
+
202
+ #### NFT (transfer, mint, create_collection)
203
+
204
+ The `Nft` built-in contract has dedicated builder methods. NFT amounts are integer counts, **not** AMA atomic units.
205
+
206
+ ```typescript
207
+ const builder = new TransactionBuilder(privateKey)
208
+
209
+ // Create a collection (caller becomes owner)
210
+ builder.nftCreateCollection({ collection: 'AGENTIC', soulbound: false })
211
+
212
+ // Mint tokens (collection owner only)
213
+ builder.nftMint({ recipient: '5Kd3N...', amount: 10, collection: 'AGENTIC', token: '1' })
214
+
215
+ // Transfer
216
+ builder.nftTransfer({ recipient: '5Kd3N...', amount: 1, collection: 'AGENTIC', token: '1' })
217
+ ```
218
+
219
+ Static variants: `TransactionBuilder.buildSignedNftTransfer/Mint/CreateCollection(input)` — each takes the same params plus `senderPrivkey`.
220
+
221
+ ### Signing Transactions
222
+
223
+ The SDK supports two patterns. Pick whichever fits your workflow.
224
+
225
+ #### Pattern 1 — Auto-signed (high-level, recommended)
226
+
227
+ The `TransactionBuilder` instance methods build **and** sign in one call. Best for app code where you have the private key in hand.
228
+
229
+ ```typescript
230
+ import { TransactionBuilder, LOCKUP_PRIME_ABI, toAtomicAma } from '@amadeus-protocol/sdk'
231
+
232
+ const builder = new TransactionBuilder('5Kd3N...') // Base58 seed
233
+
234
+ // Coin transfer
235
+ const a = builder.transfer({ recipient: '5Kd3N...', amount: 10.5, symbol: 'AMA' })
236
+
237
+ // ABI-driven (any contract)
238
+ const b = builder.contract(LOCKUP_PRIME_ABI).lock({
239
+ amount: toAtomicAma(100).toString(),
240
+ tier: '30d'
241
+ })
242
+
243
+ // NFT
244
+ const c = builder.nftTransfer({
245
+ recipient: '5Kd3N...',
246
+ amount: 1,
247
+ collection: 'AGENTIC',
248
+ token: '1'
249
+ })
250
+
251
+ // All return { txHash, txPacked } ready for sdk.transaction.submit(txPacked)
252
+ ```
253
+
254
+ #### Pattern 2 — Manual: build a `ContractCall`, sign separately
255
+
256
+ Build a `ContractCall` with a standalone helper or `createContract(ABI)`, then sign it independently with `TransactionBuilder.signCall(privkey, call)`. Useful when:
257
+
258
+ - You want to inspect or log the call before signing
259
+ - The signing key lives somewhere else (HSM, separate process, separate machine)
260
+ - You want to batch-build and sign at the end
261
+
262
+ ```typescript
263
+ import {
264
+ TransactionBuilder,
265
+ createContract,
266
+ LOCKUP_PRIME_ABI,
267
+ buildCoinTransfer,
268
+ buildNftTransfer,
269
+ toAtomicAma
270
+ } from '@amadeus-protocol/sdk'
271
+
272
+ // Build a ContractCall — three ways:
273
+
274
+ // A. Standalone helper (Coin)
275
+ const callA = buildCoinTransfer({ recipient: '5Kd3N...', amount: 10.5, symbol: 'AMA' })
276
+
277
+ // B. Standalone helper (NFT)
278
+ const callB = buildNftTransfer({
279
+ recipient: '5Kd3N...',
280
+ amount: 1,
281
+ collection: 'AGENTIC',
282
+ token: '1'
283
+ })
284
+
285
+ // C. ABI-driven, any contract
286
+ const lockupPrime = createContract(LOCKUP_PRIME_ABI)
287
+ const callC = lockupPrime.lock({ amount: toAtomicAma(100).toString(), tier: '30d' })
288
+
289
+ // Inspect if you want
290
+ console.log('Will call:', callC.contract, callC.method, callC.args)
291
+
292
+ // Sign with any private key (no builder instance needed)
293
+ const { txHash, txPacked } = TransactionBuilder.signCall('5Kd3N...', callC)
294
+ ```
295
+
296
+ #### Build-unsigned-then-sign (debugging)
297
+
298
+ If you need to inspect the full unsigned transaction (nonce, signer, action) before signing:
299
+
300
+ ```typescript
301
+ const builder = new TransactionBuilder('5Kd3N...')
302
+
303
+ const unsigned = builder.buildTransfer({ recipient: '5Kd3N...', amount: 10.5, symbol: 'AMA' })
304
+ console.log('Nonce:', unsigned.tx.nonce)
305
+ console.log('Action:', unsigned.tx.action)
306
+
307
+ const { txHash, txPacked } = builder.sign(unsigned)
308
+ ```
309
+
154
310
  #### Using Static Methods
155
311
 
156
312
  ```typescript
@@ -229,22 +385,19 @@ const atomic = toAtomicAma(1.5) // Returns 1500000000
229
385
  const ama = fromAtomicAma(1500000000) // Returns 1.5
230
386
  ```
231
387
 
232
- ### Signing Transactions
388
+ ### Mnemonics (BIP39)
233
389
 
234
390
  ```typescript
235
- import { TransactionBuilder } from '@amadeus-protocol/sdk'
391
+ import { generateMnemonic, validateMnemonic, mnemonicToSeedBase58 } from '@amadeus-protocol/sdk'
236
392
 
237
- // Using TransactionBuilder instance
238
- const builder = new TransactionBuilder('5Kd3N...')
239
-
240
- // Build unsigned transaction
241
- const unsignedTx = builder.build('Coin', 'transfer', args)
393
+ // Generate a 12-word mnemonic
394
+ const mnemonic = generateMnemonic()
242
395
 
243
- // Sign the transaction
244
- const { txHash, txPacked } = builder.sign(unsignedTx)
245
-
246
- // Or build and sign in one step
247
- const { txHash, txPacked } = builder.buildAndSign('Coin', 'transfer', args)
396
+ // Validate a mnemonic
397
+ if (validateMnemonic(mnemonic)) {
398
+ // Derive a Base58 seed (compatible with TransactionBuilder)
399
+ const seedBase58 = mnemonicToSeedBase58(mnemonic)
400
+ }
248
401
  ```
249
402
 
250
403
  ### Encoding Utilities
@@ -300,6 +453,13 @@ const decrypted = await decryptWithPassword(encrypted, 'my-password')
300
453
  - `derivePublicKeyFromSeedBase58(base58Seed: string): string` - Derive public key from Base58 seed
301
454
  - `deriveSkAndSeed64FromBase58Seed(base58Seed64: string)` - Derive secret key and seed
302
455
 
456
+ ### Mnemonics (BIP39)
457
+
458
+ - `generateMnemonic(): string` - Generate a 12-word BIP39 mnemonic
459
+ - `validateMnemonic(mnemonic: string): boolean` - Validate a BIP39 mnemonic
460
+ - `mnemonicToSeedBase58(mnemonic: string): string` - Derive a Base58 seed from a mnemonic
461
+ - `encodeVaultSecret`, `decodeVaultSecret`, `detectInputType` - Vault helpers
462
+
303
463
  ### Encoding
304
464
 
305
465
  - `toBase58(buf: Uint8Array): string` - Encode bytes to Base58
@@ -311,11 +471,6 @@ const decrypted = await decryptWithPassword(encrypted, 'my-password')
311
471
  - `uint8ArrayToArrayBuffer(bytes: Uint8Array): ArrayBuffer` - Convert Uint8Array to ArrayBuffer
312
472
  - `arrayBufferToUint8Array(buffer: ArrayBuffer): Uint8Array` - Convert ArrayBuffer to Uint8Array
313
473
 
314
- ### Signing
315
-
316
- - `signTx(hash: Uint8Array, sk: PrivKey): Uint8Array` - Sign a transaction hash
317
- - `signOOB(sk: string, msg: Uint8Array): Uint8Array` - Sign an out-of-band message
318
-
319
474
  ### Conversion
320
475
 
321
476
  - `toAtomicAma(ama: number): number` - Convert AMA to atomic units
@@ -333,18 +488,48 @@ const decrypted = await decryptWithPassword(encrypted, 'my-password')
333
488
 
334
489
  - `TransactionBuilder` - Class for building and signing transactions
335
490
  - **Constructor:** `new TransactionBuilder(privateKey?: string)` - Create a new builder instance
336
- - **Instance Methods:**
337
- - `build(contract, method, args, signerPk?): UnsignedTransactionWithHash` - Build an unsigned transaction
338
- - `sign(unsignedTx, signerSk?): BuildTxResult` - Sign an unsigned transaction
339
- - `buildAndSign(contract, method, args, signerPk?, signerSk?): BuildTxResult` - Build and sign in one step
340
- - `buildTransfer(input, signerPk?): UnsignedTransactionWithHash` - Build an unsigned transfer
341
- - `transfer(input): BuildTxResult` - Build and sign a transfer (convenience)
342
- - **Static Methods:**
343
- - `build(signerPk, contract, method, args): UnsignedTransactionWithHash` - Build unsigned transaction
344
- - `sign(unsignedTx, signerSk): BuildTxResult` - Sign an unsigned transaction
345
- - `buildAndSign(signerPk, signerSk, contract, method, args): BuildTxResult` - Build and sign in one step
346
- - `buildTransfer(input, signerPk): UnsignedTransactionWithHash` - Build unsigned transfer
347
- - `buildSignedTransfer(input): BuildTxResult` - Build and sign transfer (convenience)
491
+ - **ABI-driven (recommended):**
492
+ - `contract(abi)` - Returns a typed, signer-bound contract interface; each ABI function becomes a method that builds and signs in one step
493
+ - **Generic instance methods:**
494
+ - `build(contract, method, args, signerPk?): UnsignedTransactionWithHash`
495
+ - `sign(unsignedTx, signerSk?): BuildTransactionResult`
496
+ - `buildAndSign(contract, method, args, signerPk?, signerSk?): BuildTransactionResult`
497
+ - `buildFromCall(call): UnsignedTransactionWithHash`
498
+ - `buildAndSignCall(call): BuildTransactionResult`
499
+ - **Coin transfer:**
500
+ - `buildTransfer(input, signerPk?): UnsignedTransactionWithHash`
501
+ - `transfer(input): BuildTransactionResult`
502
+ - **NFT (Nft contract):**
503
+ - `nftTransfer({ recipient, amount, collection, token }): BuildTransactionResult`
504
+ - `nftMint({ recipient, amount, collection, token }): BuildTransactionResult`
505
+ - `nftCreateCollection({ collection, soulbound? }): BuildTransactionResult`
506
+ - **Lockup / LockupPrime convenience methods:**
507
+ - `lockupUnlock({ vaultIndex }): BuildTransactionResult`
508
+ - `lockupPrimeLock({ amount, tier }): BuildTransactionResult`
509
+ - `lockupPrimeUnlock({ vaultIndex }): BuildTransactionResult`
510
+ - `lockupPrimeDailyCheckin({ vaultIndex }): BuildTransactionResult`
511
+ - **Static methods:** `signCall`, `buildFromCall`, `buildAndSignCall`, `buildSignedTransfer`, `buildSignedNft{Transfer,Mint,CreateCollection}`, `buildSignedLockup{Unlock}`, `buildSignedLockupPrime{Lock,Unlock,DailyCheckin}`
512
+
513
+ ### Contract ABIs
514
+
515
+ `as const` ABI definitions for built-in contracts. Pass any ABI to `createContract(abi)` or `builder.contract(abi)` for fully-typed function calls.
516
+
517
+ - `LOCKUP_ABI` - `Lockup` (vesting) — `unlock(vaultIndex)`
518
+ - `LOCKUP_PRIME_ABI` - `LockupPrime` — `lock(amount, tier)`, `unlock(vaultIndex)`, `daily_checkin(vaultIndex)`
519
+ - `NFT_ABI` - `Nft` — `transfer`, `mint`, `create_collection`
520
+
521
+ Standalone builders that return a `ContractCall`:
522
+
523
+ - `buildCoinTransfer({ recipient, amount, symbol })`
524
+ - `buildNftTransfer({ recipient, amount, collection, token })`
525
+ - `buildNftMint({ recipient, amount, collection, token })`
526
+ - `buildNftCreateCollection({ collection, soulbound? })`
527
+ - `createContract(abi).fn(params)` - generic ABI-driven builder
528
+ - `buildContractCall(abi, fn, params)` - lower-level ABI-driven builder
529
+
530
+ ### Full API Reference
531
+
532
+ For complete documentation including request/response types, error handling, and end-to-end examples, see [docs.ama.one/sdk](https://docs.ama.one/sdk/1.-introduction.md).
348
533
 
349
534
  ## Examples
350
535
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amadeus-protocol/sdk",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Official TypeScript/JavaScript SDK for Amadeus Protocol - Core utilities for serialization, cryptography, transaction building, and API client",
5
5
  "repository": {
6
6
  "type": "git",