@amadeus-protocol/sdk 1.0.8 → 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 (200) hide show
  1. package/README.md +215 -30
  2. package/dist/api/chain.d.ts +144 -117
  3. package/dist/api/chain.d.ts.map +1 -1
  4. package/dist/api/chain.js +175 -146
  5. package/dist/api/chain.js.map +1 -1
  6. package/dist/api/contract.d.ts +78 -60
  7. package/dist/api/contract.d.ts.map +1 -1
  8. package/dist/api/contract.js +102 -75
  9. package/dist/api/contract.js.map +1 -1
  10. package/dist/api/epoch.d.ts +65 -66
  11. package/dist/api/epoch.d.ts.map +1 -1
  12. package/dist/api/epoch.js +90 -98
  13. package/dist/api/epoch.js.map +1 -1
  14. package/dist/api/peer.d.ts +77 -78
  15. package/dist/api/peer.d.ts.map +1 -1
  16. package/dist/api/peer.js +93 -94
  17. package/dist/api/peer.js.map +1 -1
  18. package/dist/api/proof.d.ts +44 -23
  19. package/dist/api/proof.d.ts.map +1 -1
  20. package/dist/api/proof.js +56 -29
  21. package/dist/api/proof.js.map +1 -1
  22. package/dist/api/transaction.d.ts +68 -69
  23. package/dist/api/transaction.d.ts.map +1 -1
  24. package/dist/api/transaction.js +84 -84
  25. package/dist/api/transaction.js.map +1 -1
  26. package/dist/api/wallet.d.ts +36 -37
  27. package/dist/api/wallet.d.ts.map +1 -1
  28. package/dist/api/wallet.js +47 -50
  29. package/dist/api/wallet.js.map +1 -1
  30. package/dist/client.d.ts +66 -68
  31. package/dist/client.d.ts.map +1 -1
  32. package/dist/client.js +231 -276
  33. package/dist/client.js.map +1 -1
  34. package/dist/constants.d.ts +13 -10
  35. package/dist/constants.d.ts.map +1 -1
  36. package/dist/constants.js +49 -45
  37. package/dist/constants.js.map +1 -1
  38. package/dist/contract-state.d.ts +6 -3
  39. package/dist/contract-state.d.ts.map +1 -1
  40. package/dist/contract-state.js +88 -106
  41. package/dist/contract-state.js.map +1 -1
  42. package/dist/contracts/abi-types.d.ts +32 -32
  43. package/dist/contracts/abi-types.d.ts.map +1 -1
  44. package/dist/contracts/coin.d.ts +13 -20
  45. package/dist/contracts/coin.d.ts.map +1 -1
  46. package/dist/contracts/coin.js +42 -38
  47. package/dist/contracts/coin.js.map +1 -1
  48. package/dist/contracts/contract-call.d.ts +14 -16
  49. package/dist/contracts/contract-call.d.ts.map +1 -1
  50. package/dist/contracts/contract-call.js +45 -54
  51. package/dist/contracts/contract-call.js.map +1 -1
  52. package/dist/contracts/contract.d.ts +24 -55
  53. package/dist/contracts/contract.d.ts.map +1 -1
  54. package/dist/contracts/contract.js +63 -101
  55. package/dist/contracts/contract.js.map +1 -1
  56. package/dist/contracts/lockup/abi.d.ts +54 -51
  57. package/dist/contracts/lockup/abi.d.ts.map +1 -1
  58. package/dist/contracts/lockup/abi.js +65 -74
  59. package/dist/contracts/lockup/abi.js.map +1 -1
  60. package/dist/contracts/lockup/helpers.d.ts +22 -18
  61. package/dist/contracts/lockup/helpers.d.ts.map +1 -1
  62. package/dist/contracts/lockup/helpers.js +44 -47
  63. package/dist/contracts/lockup/helpers.js.map +1 -1
  64. package/dist/contracts/lockup/parsers.d.ts +7 -3
  65. package/dist/contracts/lockup/parsers.d.ts.map +1 -1
  66. package/dist/contracts/lockup/parsers.js +51 -55
  67. package/dist/contracts/lockup/parsers.js.map +1 -1
  68. package/dist/contracts/lockup/storage-keys.d.ts +5 -2
  69. package/dist/contracts/lockup/storage-keys.d.ts.map +1 -1
  70. package/dist/contracts/lockup/storage-keys.js +54 -70
  71. package/dist/contracts/lockup/storage-keys.js.map +1 -1
  72. package/dist/contracts/lockup/types.d.ts +73 -70
  73. package/dist/contracts/lockup/types.d.ts.map +1 -1
  74. package/dist/contracts/lockup-prime/abi.d.ts +328 -325
  75. package/dist/contracts/lockup-prime/abi.d.ts.map +1 -1
  76. package/dist/contracts/lockup-prime/abi.js +397 -417
  77. package/dist/contracts/lockup-prime/abi.js.map +1 -1
  78. package/dist/contracts/lockup-prime/helpers.d.ts +35 -31
  79. package/dist/contracts/lockup-prime/helpers.d.ts.map +1 -1
  80. package/dist/contracts/lockup-prime/helpers.js +131 -137
  81. package/dist/contracts/lockup-prime/helpers.js.map +1 -1
  82. package/dist/contracts/lockup-prime/parsers.d.ts +9 -5
  83. package/dist/contracts/lockup-prime/parsers.d.ts.map +1 -1
  84. package/dist/contracts/lockup-prime/parsers.js +61 -61
  85. package/dist/contracts/lockup-prime/parsers.js.map +1 -1
  86. package/dist/contracts/lockup-prime/storage-keys.d.ts +7 -4
  87. package/dist/contracts/lockup-prime/storage-keys.d.ts.map +1 -1
  88. package/dist/contracts/lockup-prime/storage-keys.js +64 -80
  89. package/dist/contracts/lockup-prime/storage-keys.js.map +1 -1
  90. package/dist/contracts/lockup-prime/types.d.ts +92 -89
  91. package/dist/contracts/lockup-prime/types.d.ts.map +1 -1
  92. package/dist/contracts/lockup-prime/types.js +12 -13
  93. package/dist/contracts/lockup-prime/types.js.map +1 -1
  94. package/dist/contracts/nft/abi.d.ts +104 -0
  95. package/dist/contracts/nft/abi.d.ts.map +1 -0
  96. package/dist/contracts/nft/abi.js +135 -0
  97. package/dist/contracts/nft/abi.js.map +1 -0
  98. package/dist/contracts/nft/helpers.d.ts +21 -0
  99. package/dist/contracts/nft/helpers.d.ts.map +1 -0
  100. package/dist/contracts/nft/helpers.js +61 -0
  101. package/dist/contracts/nft/helpers.js.map +1 -0
  102. package/dist/contracts/nft/types.d.ts +47 -0
  103. package/dist/contracts/nft/types.d.ts.map +1 -0
  104. package/dist/conversion.d.ts +5 -2
  105. package/dist/conversion.d.ts.map +1 -1
  106. package/dist/conversion.js +45 -50
  107. package/dist/conversion.js.map +1 -1
  108. package/dist/crypto.d.ts +14 -16
  109. package/dist/crypto.d.ts.map +1 -1
  110. package/dist/crypto.js +121 -140
  111. package/dist/crypto.js.map +1 -1
  112. package/dist/encoding.d.ts +11 -8
  113. package/dist/encoding.d.ts.map +1 -1
  114. package/dist/encoding.js +123 -144
  115. package/dist/encoding.js.map +1 -1
  116. package/dist/encryption.d.ts +15 -12
  117. package/dist/encryption.d.ts.map +1 -1
  118. package/dist/encryption.js +119 -117
  119. package/dist/encryption.js.map +1 -1
  120. package/dist/explorer.d.ts +10 -7
  121. package/dist/explorer.d.ts.map +1 -1
  122. package/dist/explorer.js +51 -48
  123. package/dist/explorer.js.map +1 -1
  124. package/dist/formatters.d.ts +8 -5
  125. package/dist/formatters.d.ts.map +1 -1
  126. package/dist/formatters.js +67 -68
  127. package/dist/formatters.js.map +1 -1
  128. package/dist/index.d.ts +42 -55
  129. package/dist/index.js +39 -55
  130. package/dist/mnemonic.d.ts +12 -9
  131. package/dist/mnemonic.d.ts.map +1 -1
  132. package/dist/mnemonic.js +105 -114
  133. package/dist/mnemonic.js.map +1 -1
  134. package/dist/networks.d.ts +14 -17
  135. package/dist/networks.d.ts.map +1 -1
  136. package/dist/networks.js +40 -36
  137. package/dist/networks.js.map +1 -1
  138. package/dist/schemas.js +75 -79
  139. package/dist/schemas.js.map +1 -1
  140. package/dist/sdk.d.ts +69 -65
  141. package/dist/sdk.d.ts.map +1 -1
  142. package/dist/sdk.js +126 -117
  143. package/dist/sdk.js.map +1 -1
  144. package/dist/serialization.d.ts +8 -18
  145. package/dist/serialization.d.ts.map +1 -1
  146. package/dist/serialization.js +207 -260
  147. package/dist/serialization.js.map +1 -1
  148. package/dist/signing.js +67 -67
  149. package/dist/signing.js.map +1 -1
  150. package/dist/transaction-builder.d.ts +175 -184
  151. package/dist/transaction-builder.d.ts.map +1 -1
  152. package/dist/transaction-builder.js +295 -344
  153. package/dist/transaction-builder.js.map +1 -1
  154. package/dist/transaction-errors.d.ts +10 -12
  155. package/dist/transaction-errors.d.ts.map +1 -1
  156. package/dist/transaction-errors.js +145 -166
  157. package/dist/transaction-errors.js.map +1 -1
  158. package/dist/types.d.ts +530 -450
  159. package/dist/types.d.ts.map +1 -1
  160. package/dist/types.js +169 -183
  161. package/dist/types.js.map +1 -1
  162. package/dist/validation.d.ts +24 -26
  163. package/dist/validation.d.ts.map +1 -1
  164. package/dist/validation.js +194 -192
  165. package/dist/validation.js.map +1 -1
  166. package/package.json +4 -3
  167. package/dist/api/index.d.ts +0 -8
  168. package/dist/api/index.d.ts.map +0 -1
  169. package/dist/api/index.js +0 -8
  170. package/dist/api/index.js.map +0 -1
  171. package/dist/contracts/abi-types.js +0 -8
  172. package/dist/contracts/abi-types.js.map +0 -1
  173. package/dist/contracts/index.d.ts +0 -7
  174. package/dist/contracts/index.d.ts.map +0 -1
  175. package/dist/contracts/index.js +0 -7
  176. package/dist/contracts/index.js.map +0 -1
  177. package/dist/contracts/lockup/calls.d.ts +0 -23
  178. package/dist/contracts/lockup/calls.d.ts.map +0 -1
  179. package/dist/contracts/lockup/calls.js +0 -25
  180. package/dist/contracts/lockup/calls.js.map +0 -1
  181. package/dist/contracts/lockup/index.d.ts +0 -6
  182. package/dist/contracts/lockup/index.d.ts.map +0 -1
  183. package/dist/contracts/lockup/index.js +0 -6
  184. package/dist/contracts/lockup/index.js.map +0 -1
  185. package/dist/contracts/lockup/types.js +0 -7
  186. package/dist/contracts/lockup/types.js.map +0 -1
  187. package/dist/contracts/lockup-prime/calls.d.ts +0 -53
  188. package/dist/contracts/lockup-prime/calls.d.ts.map +0 -1
  189. package/dist/contracts/lockup-prime/calls.js +0 -60
  190. package/dist/contracts/lockup-prime/calls.js.map +0 -1
  191. package/dist/contracts/lockup-prime/index.d.ts +0 -6
  192. package/dist/contracts/lockup-prime/index.d.ts.map +0 -1
  193. package/dist/contracts/lockup-prime/index.js +0 -6
  194. package/dist/contracts/lockup-prime/index.js.map +0 -1
  195. package/dist/index.d.ts.map +0 -1
  196. package/dist/index.js.map +0 -1
  197. package/dist/schemas.d.ts +0 -67
  198. package/dist/schemas.d.ts.map +0 -1
  199. package/dist/signing.d.ts +0 -39
  200. package/dist/signing.d.ts.map +0 -1
@@ -1,346 +1,297 @@
1
+ import { deriveSkAndSeed64FromBase58Seed, getPublicKey } from "./crypto.js";
2
+ import { toAtomicAma } from "./conversion.js";
3
+ import { buildAndSignRaw, buildUnsigned, buildUnsignedFromCall, normalizeSignerSk, signContractCall, signUnsigned } from "./signing.js";
4
+ import { createContract } from "./contracts/contract.js";
5
+ import { buildCoinTransfer } from "./contracts/coin.js";
6
+ import { LOCKUP_PRIME_ABI } from "./contracts/lockup-prime/abi.js";
7
+ import { LOCKUP_ABI } from "./contracts/lockup/abi.js";
8
+ import { buildNftCreateCollection, buildNftMint, buildNftTransfer } from "./contracts/nft/helpers.js";
9
+ //#region src/transaction-builder.ts
1
10
  /**
2
- * Transaction Builder
3
- *
4
- * Class-based API for building and signing Amadeus protocol transactions.
5
- * Delegates to the signing primitives in `signing.ts` and the ABI-driven
6
- * contract factory in `contracts/contract.ts`.
7
- *
8
- * ## Recommended: ABI-driven API
9
- *
10
- * ```ts
11
- * import { TransactionBuilder, LOCKUP_PRIME_ABI, toAtomicAma } from '@amadeus-protocol/sdk'
12
- *
13
- * // Via builder.contract(abi) — typed methods, auto-signed:
14
- * const builder = new TransactionBuilder('5Kd3N...')
15
- * const result = builder.contract(LOCKUP_PRIME_ABI).lock({
16
- * amount: toAtomicAma(100).toString(),
17
- * tier: '30d'
18
- * })
19
- *
20
- * // Or standalone:
21
- * import { createContract } from '@amadeus-protocol/sdk'
22
- * const lockupPrime = createContract(LOCKUP_PRIME_ABI)
23
- * const call = lockupPrime.lock({ amount: toAtomicAma(100).toString(), tier: '30d' })
24
- * const result = TransactionBuilder.signCall('5Kd3N...', call)
25
- * ```
26
- */
27
- import { deriveSkAndSeed64FromBase58Seed, getPublicKey } from './crypto';
28
- import { toAtomicAma } from './conversion';
29
- import { buildUnsigned, buildUnsignedFromCall, buildAndSignRaw, signUnsigned, signContractCall, normalizeSignerSk } from './signing';
30
- import { createContract } from './contracts/contract';
31
- import { buildCoinTransfer } from './contracts/coin';
32
- import { LOCKUP_PRIME_ABI } from './contracts/lockup-prime/abi';
33
- import { LOCKUP_ABI } from './contracts/lockup/abi';
34
- /**
35
- * Transaction Builder for Amadeus Protocol
36
- *
37
- * Provides methods for building and signing transactions. Can be instantiated
38
- * with a private key for convenience, or used statically.
39
- *
40
- * @example
41
- * ```ts
42
- * // ABI-driven (recommended)
43
- * const builder = new TransactionBuilder('5Kd3N...')
44
- * const result = builder.contract(LOCKUP_PRIME_ABI).lock({
45
- * amount: toAtomicAma(100).toString(),
46
- * tier: '30d'
47
- * })
48
- *
49
- * // Generic build/sign
50
- * const builder = new TransactionBuilder('5Kd3N...')
51
- * const { txHash, txPacked } = builder.buildAndSign('Coin', 'transfer', [
52
- * recipientBytes, '1000000000', 'AMA'
53
- * ])
54
- * ```
55
- */
56
- export class TransactionBuilder {
57
- privateKey;
58
- signerPk = null;
59
- signerSk = null;
60
- /**
61
- * Create a new TransactionBuilder instance
62
- *
63
- * @param privateKey - Optional Base58 encoded private key (seed). If provided,
64
- * the builder will use this key for all transactions.
65
- */
66
- constructor(privateKey) {
67
- this.privateKey = privateKey || null;
68
- if (this.privateKey) {
69
- this.initializeKeys();
70
- }
71
- }
72
- /**
73
- * Initialize signer keys from the private key
74
- */
75
- initializeKeys() {
76
- if (!this.privateKey) {
77
- throw new Error('Private key not set');
78
- }
79
- const { seed64, sk } = deriveSkAndSeed64FromBase58Seed(this.privateKey);
80
- this.signerPk = getPublicKey(seed64);
81
- this.signerSk = sk;
82
- }
83
- /**
84
- * Get the signer's secret key (normalizes to PrivKey format)
85
- */
86
- getSignerSk(signerSk) {
87
- if (signerSk) {
88
- return normalizeSignerSk(signerSk);
89
- }
90
- if (this.signerSk) {
91
- return this.signerSk;
92
- }
93
- if (this.privateKey) {
94
- return normalizeSignerSk(this.privateKey);
95
- }
96
- throw new Error('Secret key required for signing');
97
- }
98
- requirePk(signerPk) {
99
- const pk = signerPk || this.signerPk;
100
- if (!pk) {
101
- throw new Error('Signer public key required. Provide key or initialize builder with private key.');
102
- }
103
- return pk;
104
- }
105
- // ========================================================================
106
- // ABI-driven contract API
107
- // ========================================================================
108
- /**
109
- * Get a typed, signer-bound contract interface from an ABI definition.
110
- *
111
- * Each ABI function becomes a method that builds and signs in one step,
112
- * returning `BuildTransactionResult` directly.
113
- *
114
- * @param abi - An ABI definition object (declared `as const`)
115
- * @returns A `SignedContract<TAbi>` with typed methods for each ABI function
116
- *
117
- * @example
118
- * ```ts
119
- * const builder = new TransactionBuilder('5Kd3N...')
120
- *
121
- * // LockupPrime — all methods auto-detected from ABI:
122
- * const result = builder.contract(LOCKUP_PRIME_ABI).lock({
123
- * amount: toAtomicAma(100).toString(),
124
- * tier: '30d'
125
- * })
126
- *
127
- * builder.contract(LOCKUP_PRIME_ABI).unlock({ vaultIndex: '3' })
128
- * builder.contract(LOCKUP_PRIME_ABI).daily_checkin({ vaultIndex: '7' })
129
- *
130
- * // Lockup:
131
- * builder.contract(LOCKUP_ABI).unlock({ vaultIndex: '5' })
132
- *
133
- * // Any future contract — just pass its ABI:
134
- * builder.contract(SOME_NEW_ABI).someFunction({ param: 'value' })
135
- * ```
136
- */
137
- contract(abi) {
138
- if (!this.privateKey) {
139
- throw new Error('Private key required. Initialize builder with private key.');
140
- }
141
- return createContract(abi).connect(this.privateKey);
142
- }
143
- // ========================================================================
144
- // ContractCall-based API
145
- // ========================================================================
146
- /**
147
- * Derive keys from a Base58 private key and sign a ContractCall.
148
- *
149
- * @param senderPrivkey - Base58 encoded private key (seed)
150
- * @param call - A ContractCall from createContract(), buildContractCall(), or buildCoinTransfer()
151
- * @returns Transaction hash and packed transaction
152
- *
153
- * @example
154
- * ```ts
155
- * const lockupPrime = createContract(LOCKUP_PRIME_ABI)
156
- * const call = lockupPrime.lock({ amount: '100000000000', tier: '30d' })
157
- * const { txHash, txPacked } = TransactionBuilder.signCall('5Kd3N...', call)
158
- * ```
159
- */
160
- static signCall(senderPrivkey, call) {
161
- return signContractCall(senderPrivkey, call);
162
- }
163
- /**
164
- * Build an unsigned transaction from a ContractCall (static)
165
- */
166
- static buildFromCall(call, signerPk) {
167
- return buildUnsignedFromCall(signerPk, call);
168
- }
169
- /**
170
- * Build and sign a transaction from a ContractCall (static)
171
- */
172
- static buildAndSignCall(signerPk, signerSk, call) {
173
- return buildAndSignRaw(signerPk, signerSk, call.contract, call.method, call.args);
174
- }
175
- /**
176
- * Build an unsigned transaction from a ContractCall (instance)
177
- */
178
- buildFromCall(call) {
179
- return buildUnsignedFromCall(this.requirePk(), call);
180
- }
181
- /**
182
- * Build and sign a transaction from a ContractCall (instance)
183
- */
184
- buildAndSignCall(call) {
185
- const pk = this.requirePk();
186
- const sk = this.getSignerSk();
187
- return buildAndSignRaw(pk, sk, call.contract, call.method, call.args);
188
- }
189
- // ========================================================================
190
- // Generic build/sign methods
191
- // ========================================================================
192
- /**
193
- * Build an unsigned transaction (instance)
194
- */
195
- build(contract, method, args, signerPk) {
196
- return buildUnsigned(this.requirePk(signerPk), contract, method, args);
197
- }
198
- /**
199
- * Sign an unsigned transaction (instance)
200
- */
201
- sign(unsignedTx, signerSk) {
202
- return signUnsigned(unsignedTx, this.getSignerSk(signerSk));
203
- }
204
- /**
205
- * Build and sign a generic transaction (instance)
206
- */
207
- buildAndSign(contract, method, args, signerPk, signerSk) {
208
- const pk = this.requirePk(signerPk);
209
- const sk = this.getSignerSk(signerSk);
210
- return buildAndSignRaw(pk, sk, contract, method, args);
211
- }
212
- /**
213
- * Build an unsigned transaction (static)
214
- */
215
- static build(signerPk, contract, method, args) {
216
- return buildUnsigned(signerPk, contract, method, args);
217
- }
218
- /**
219
- * Sign an unsigned transaction (static)
220
- */
221
- static sign(unsignedTx, signerSk) {
222
- return signUnsigned(unsignedTx, signerSk);
223
- }
224
- /**
225
- * Build and sign a generic transaction (static)
226
- */
227
- static buildAndSign(signerPk, signerSk, contract, method, args) {
228
- return buildAndSignRaw(signerPk, signerSk, contract, method, args);
229
- }
230
- // ========================================================================
231
- // Coin transfer (instance)
232
- // ========================================================================
233
- /**
234
- * Build an unsigned Coin transfer transaction
235
- */
236
- buildTransfer(input) {
237
- return this.buildFromCall(buildCoinTransfer(input));
238
- }
239
- /**
240
- * Build and sign a Coin transfer transaction
241
- */
242
- transfer(input) {
243
- if (!this.privateKey) {
244
- throw new Error('Private key required. Initialize builder with private key or use static method.');
245
- }
246
- return this.buildAndSignCall(buildCoinTransfer(input));
247
- }
248
- // ========================================================================
249
- // Coin transfer (static)
250
- // ========================================================================
251
- /**
252
- * Build an unsigned Coin transfer transaction (static)
253
- */
254
- static buildTransfer(input, signerPk) {
255
- return TransactionBuilder.buildFromCall(buildCoinTransfer(input), signerPk);
256
- }
257
- /**
258
- * Build and sign a Coin transfer transaction (static)
259
- */
260
- static buildSignedTransfer(input) {
261
- return TransactionBuilder.signCall(input.senderPrivkey, buildCoinTransfer({ recipient: input.recipient, amount: input.amount, symbol: input.symbol }));
262
- }
263
- // ========================================================================
264
- // LockupPrime (instance)
265
- // ========================================================================
266
- /**
267
- * Build and sign a LockupPrime lock transaction
268
- */
269
- lockupPrimeLock(input) {
270
- return this.contract(LOCKUP_PRIME_ABI).lock({
271
- amount: toAtomicAma(input.amount).toString(),
272
- tier: input.tier
273
- });
274
- }
275
- /**
276
- * Build and sign a LockupPrime unlock transaction
277
- */
278
- lockupPrimeUnlock(input) {
279
- return this.contract(LOCKUP_PRIME_ABI).unlock({
280
- vaultIndex: input.vaultIndex.toString()
281
- });
282
- }
283
- /**
284
- * Build and sign a LockupPrime daily check-in transaction
285
- */
286
- lockupPrimeDailyCheckin(input) {
287
- return this.contract(LOCKUP_PRIME_ABI).daily_checkin({
288
- vaultIndex: input.vaultIndex.toString()
289
- });
290
- }
291
- // ========================================================================
292
- // Lockup (instance)
293
- // ========================================================================
294
- /**
295
- * Build and sign a Lockup unlock transaction
296
- */
297
- lockupUnlock(input) {
298
- return this.contract(LOCKUP_ABI).unlock({
299
- vaultIndex: input.vaultIndex.toString()
300
- });
301
- }
302
- // ========================================================================
303
- // LockupPrime (static)
304
- // ========================================================================
305
- /**
306
- * Build and sign a LockupPrime lock transaction (static)
307
- */
308
- static buildSignedLockupPrimeLock(input) {
309
- const call = createContract(LOCKUP_PRIME_ABI).lock({
310
- amount: toAtomicAma(input.amount).toString(),
311
- tier: input.tier
312
- });
313
- return TransactionBuilder.signCall(input.senderPrivkey, call);
314
- }
315
- /**
316
- * Build and sign a LockupPrime unlock transaction (static)
317
- */
318
- static buildSignedLockupPrimeUnlock(input) {
319
- const call = createContract(LOCKUP_PRIME_ABI).unlock({
320
- vaultIndex: input.vaultIndex.toString()
321
- });
322
- return TransactionBuilder.signCall(input.senderPrivkey, call);
323
- }
324
- /**
325
- * Build and sign a LockupPrime daily check-in transaction (static)
326
- */
327
- static buildSignedLockupPrimeDailyCheckin(input) {
328
- const call = createContract(LOCKUP_PRIME_ABI).daily_checkin({
329
- vaultIndex: input.vaultIndex.toString()
330
- });
331
- return TransactionBuilder.signCall(input.senderPrivkey, call);
332
- }
333
- // ========================================================================
334
- // Lockup (static)
335
- // ========================================================================
336
- /**
337
- * Build and sign a Lockup unlock transaction (static)
338
- */
339
- static buildSignedLockupUnlock(input) {
340
- const call = createContract(LOCKUP_ABI).unlock({
341
- vaultIndex: input.vaultIndex.toString()
342
- });
343
- return TransactionBuilder.signCall(input.senderPrivkey, call);
344
- }
345
- }
11
+ * Transaction Builder for Amadeus Protocol
12
+ *
13
+ * Provides methods for building and signing transactions. Can be instantiated
14
+ * with a private key for convenience, or used statically.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * // ABI-driven (recommended)
19
+ * const builder = new TransactionBuilder('5Kd3N...')
20
+ * const result = builder.contract(LOCKUP_PRIME_ABI).lock({
21
+ * amount: toAtomicAma(100).toString(),
22
+ * tier: '30d'
23
+ * })
24
+ *
25
+ * // Generic build/sign
26
+ * const builder = new TransactionBuilder('5Kd3N...')
27
+ * const { txHash, txPacked } = builder.buildAndSign('Coin', 'transfer', [
28
+ * recipientBytes, '1000000000', 'AMA'
29
+ * ])
30
+ * ```
31
+ */
32
+ var TransactionBuilder = class TransactionBuilder {
33
+ privateKey;
34
+ signerPk = null;
35
+ signerSk = null;
36
+ /**
37
+ * Create a new TransactionBuilder instance
38
+ *
39
+ * @param privateKey - Optional Base58 encoded private key (seed). If provided,
40
+ * the builder will use this key for all transactions.
41
+ */
42
+ constructor(privateKey) {
43
+ this.privateKey = privateKey || null;
44
+ if (this.privateKey) this.initializeKeys();
45
+ }
46
+ /**
47
+ * Initialize signer keys from the private key
48
+ */
49
+ initializeKeys() {
50
+ if (!this.privateKey) throw new Error("Private key not set");
51
+ const { seed64, sk } = deriveSkAndSeed64FromBase58Seed(this.privateKey);
52
+ this.signerPk = getPublicKey(seed64);
53
+ this.signerSk = sk;
54
+ }
55
+ /**
56
+ * Get the signer's secret key (normalizes to PrivKey format)
57
+ */
58
+ getSignerSk(signerSk) {
59
+ if (signerSk) return normalizeSignerSk(signerSk);
60
+ if (this.signerSk) return this.signerSk;
61
+ if (this.privateKey) return normalizeSignerSk(this.privateKey);
62
+ throw new Error("Secret key required for signing");
63
+ }
64
+ requirePk(signerPk) {
65
+ const pk = signerPk || this.signerPk;
66
+ if (!pk) throw new Error("Signer public key required. Provide key or initialize builder with private key.");
67
+ return pk;
68
+ }
69
+ /**
70
+ * Get a typed, signer-bound contract interface from an ABI definition.
71
+ *
72
+ * Each ABI function becomes a method that builds and signs in one step,
73
+ * returning `BuildTransactionResult` directly.
74
+ *
75
+ * @param abi - An ABI definition object (declared `as const`)
76
+ * @returns A `SignedContract<TAbi>` with typed methods for each ABI function
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const builder = new TransactionBuilder('5Kd3N...')
81
+ *
82
+ * // LockupPrime all methods auto-detected from ABI:
83
+ * const result = builder.contract(LOCKUP_PRIME_ABI).lock({
84
+ * amount: toAtomicAma(100).toString(),
85
+ * tier: '30d'
86
+ * })
87
+ *
88
+ * builder.contract(LOCKUP_PRIME_ABI).unlock({ vaultIndex: '3' })
89
+ * builder.contract(LOCKUP_PRIME_ABI).daily_checkin({ vaultIndex: '7' })
90
+ *
91
+ * // Lockup:
92
+ * builder.contract(LOCKUP_ABI).unlock({ vaultIndex: '5' })
93
+ *
94
+ * // Any future contract — just pass its ABI:
95
+ * builder.contract(SOME_NEW_ABI).someFunction({ param: 'value' })
96
+ * ```
97
+ */
98
+ contract(abi) {
99
+ if (!this.privateKey) throw new Error("Private key required. Initialize builder with private key.");
100
+ return createContract(abi).connect(this.privateKey);
101
+ }
102
+ /**
103
+ * Derive keys from a Base58 private key and sign a ContractCall.
104
+ *
105
+ * @param senderPrivkey - Base58 encoded private key (seed)
106
+ * @param call - A ContractCall from createContract(), buildContractCall(), or buildCoinTransfer()
107
+ * @returns Transaction hash and packed transaction
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const lockupPrime = createContract(LOCKUP_PRIME_ABI)
112
+ * const call = lockupPrime.lock({ amount: '100000000000', tier: '30d' })
113
+ * const { txHash, txPacked } = TransactionBuilder.signCall('5Kd3N...', call)
114
+ * ```
115
+ */
116
+ static signCall(senderPrivkey, call) {
117
+ return signContractCall(senderPrivkey, call);
118
+ }
119
+ /**
120
+ * Build an unsigned transaction from a ContractCall (static)
121
+ */
122
+ static buildFromCall(call, signerPk) {
123
+ return buildUnsignedFromCall(signerPk, call);
124
+ }
125
+ /**
126
+ * Build and sign a transaction from a ContractCall (static)
127
+ */
128
+ static buildAndSignCall(signerPk, signerSk, call) {
129
+ return buildAndSignRaw(signerPk, signerSk, call.contract, call.method, call.args);
130
+ }
131
+ /**
132
+ * Build an unsigned transaction from a ContractCall (instance)
133
+ */
134
+ buildFromCall(call) {
135
+ return buildUnsignedFromCall(this.requirePk(), call);
136
+ }
137
+ /**
138
+ * Build and sign a transaction from a ContractCall (instance)
139
+ */
140
+ buildAndSignCall(call) {
141
+ return buildAndSignRaw(this.requirePk(), this.getSignerSk(), call.contract, call.method, call.args);
142
+ }
143
+ /**
144
+ * Build an unsigned transaction (instance)
145
+ */
146
+ build(contract, method, args, signerPk) {
147
+ return buildUnsigned(this.requirePk(signerPk), contract, method, args);
148
+ }
149
+ /**
150
+ * Sign an unsigned transaction (instance)
151
+ */
152
+ sign(unsignedTx, signerSk) {
153
+ return signUnsigned(unsignedTx, this.getSignerSk(signerSk));
154
+ }
155
+ /**
156
+ * Build and sign a generic transaction (instance)
157
+ */
158
+ buildAndSign(contract, method, args, signerPk, signerSk) {
159
+ return buildAndSignRaw(this.requirePk(signerPk), this.getSignerSk(signerSk), contract, method, args);
160
+ }
161
+ /**
162
+ * Build an unsigned transaction (static)
163
+ */
164
+ static build(signerPk, contract, method, args) {
165
+ return buildUnsigned(signerPk, contract, method, args);
166
+ }
167
+ /**
168
+ * Sign an unsigned transaction (static)
169
+ */
170
+ static sign(unsignedTx, signerSk) {
171
+ return signUnsigned(unsignedTx, signerSk);
172
+ }
173
+ /**
174
+ * Build and sign a generic transaction (static)
175
+ */
176
+ static buildAndSign(signerPk, signerSk, contract, method, args) {
177
+ return buildAndSignRaw(signerPk, signerSk, contract, method, args);
178
+ }
179
+ /**
180
+ * Build an unsigned Coin transfer transaction
181
+ */
182
+ buildTransfer(input) {
183
+ return this.buildFromCall(buildCoinTransfer(input));
184
+ }
185
+ /**
186
+ * Build and sign a Coin transfer transaction
187
+ */
188
+ transfer(input) {
189
+ if (!this.privateKey) throw new Error("Private key required. Initialize builder with private key or use static method.");
190
+ return this.buildAndSignCall(buildCoinTransfer(input));
191
+ }
192
+ /**
193
+ * Build an unsigned Coin transfer transaction (static)
194
+ */
195
+ static buildTransfer(input, signerPk) {
196
+ return TransactionBuilder.buildFromCall(buildCoinTransfer(input), signerPk);
197
+ }
198
+ /**
199
+ * Build and sign a Coin transfer transaction (static)
200
+ */
201
+ static buildSignedTransfer(input) {
202
+ return TransactionBuilder.signCall(input.senderPrivkey, buildCoinTransfer({
203
+ recipient: input.recipient,
204
+ amount: input.amount,
205
+ symbol: input.symbol
206
+ }));
207
+ }
208
+ /**
209
+ * Build and sign a LockupPrime lock transaction
210
+ */
211
+ lockupPrimeLock(input) {
212
+ return this.contract(LOCKUP_PRIME_ABI).lock({
213
+ amount: toAtomicAma(input.amount).toString(),
214
+ tier: input.tier
215
+ });
216
+ }
217
+ /**
218
+ * Build and sign a LockupPrime unlock transaction
219
+ */
220
+ lockupPrimeUnlock(input) {
221
+ return this.contract(LOCKUP_PRIME_ABI).unlock({ vaultIndex: input.vaultIndex.toString() });
222
+ }
223
+ /**
224
+ * Build and sign a LockupPrime daily check-in transaction
225
+ */
226
+ lockupPrimeDailyCheckin(input) {
227
+ return this.contract(LOCKUP_PRIME_ABI).daily_checkin({ vaultIndex: input.vaultIndex.toString() });
228
+ }
229
+ /**
230
+ * Build and sign a Lockup unlock transaction
231
+ */
232
+ lockupUnlock(input) {
233
+ return this.contract(LOCKUP_ABI).unlock({ vaultIndex: input.vaultIndex.toString() });
234
+ }
235
+ /**
236
+ * Build and sign a LockupPrime lock transaction (static)
237
+ */
238
+ static buildSignedLockupPrimeLock(input) {
239
+ const call = createContract(LOCKUP_PRIME_ABI).lock({
240
+ amount: toAtomicAma(input.amount).toString(),
241
+ tier: input.tier
242
+ });
243
+ return TransactionBuilder.signCall(input.senderPrivkey, call);
244
+ }
245
+ /**
246
+ * Build and sign a LockupPrime unlock transaction (static)
247
+ */
248
+ static buildSignedLockupPrimeUnlock(input) {
249
+ const call = createContract(LOCKUP_PRIME_ABI).unlock({ vaultIndex: input.vaultIndex.toString() });
250
+ return TransactionBuilder.signCall(input.senderPrivkey, call);
251
+ }
252
+ /**
253
+ * Build and sign a LockupPrime daily check-in transaction (static)
254
+ */
255
+ static buildSignedLockupPrimeDailyCheckin(input) {
256
+ const call = createContract(LOCKUP_PRIME_ABI).daily_checkin({ vaultIndex: input.vaultIndex.toString() });
257
+ return TransactionBuilder.signCall(input.senderPrivkey, call);
258
+ }
259
+ /**
260
+ * Build and sign a Lockup unlock transaction (static)
261
+ */
262
+ static buildSignedLockupUnlock(input) {
263
+ const call = createContract(LOCKUP_ABI).unlock({ vaultIndex: input.vaultIndex.toString() });
264
+ return TransactionBuilder.signCall(input.senderPrivkey, call);
265
+ }
266
+ /** Build and sign an `Nft.transfer` transaction */
267
+ nftTransfer(input) {
268
+ if (!this.privateKey) throw new Error("Private key required. Initialize builder with private key or use static method.");
269
+ return this.buildAndSignCall(buildNftTransfer(input));
270
+ }
271
+ /** Build and sign an `Nft.mint` transaction (collection owner only) */
272
+ nftMint(input) {
273
+ if (!this.privateKey) throw new Error("Private key required. Initialize builder with private key or use static method.");
274
+ return this.buildAndSignCall(buildNftMint(input));
275
+ }
276
+ /** Build and sign an `Nft.create_collection` transaction */
277
+ nftCreateCollection(input) {
278
+ if (!this.privateKey) throw new Error("Private key required. Initialize builder with private key or use static method.");
279
+ return this.buildAndSignCall(buildNftCreateCollection(input));
280
+ }
281
+ /** Build and sign an `Nft.transfer` transaction (static) */
282
+ static buildSignedNftTransfer(input) {
283
+ return TransactionBuilder.signCall(input.senderPrivkey, buildNftTransfer(input));
284
+ }
285
+ /** Build and sign an `Nft.mint` transaction (static) */
286
+ static buildSignedNftMint(input) {
287
+ return TransactionBuilder.signCall(input.senderPrivkey, buildNftMint(input));
288
+ }
289
+ /** Build and sign an `Nft.create_collection` transaction (static) */
290
+ static buildSignedNftCreateCollection(input) {
291
+ return TransactionBuilder.signCall(input.senderPrivkey, buildNftCreateCollection(input));
292
+ }
293
+ };
294
+ //#endregion
295
+ export { TransactionBuilder };
296
+
346
297
  //# sourceMappingURL=transaction-builder.js.map