@amadeus-protocol/sdk 1.0.6 → 1.0.7
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/README.md +2 -2
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/contract-state.d.ts +59 -0
- package/dist/contract-state.d.ts.map +1 -0
- package/dist/contract-state.js +117 -0
- package/dist/contract-state.js.map +1 -0
- package/dist/contracts/abi-types.d.ts +87 -0
- package/dist/contracts/abi-types.d.ts.map +1 -0
- package/dist/contracts/abi-types.js +8 -0
- package/dist/contracts/abi-types.js.map +1 -0
- package/dist/contracts/coin.d.ts +42 -0
- package/dist/contracts/coin.d.ts.map +1 -0
- package/dist/contracts/coin.js +42 -0
- package/dist/contracts/coin.js.map +1 -0
- package/dist/contracts/contract-call.d.ts +49 -0
- package/dist/contracts/contract-call.d.ts.map +1 -0
- package/dist/contracts/contract-call.js +57 -0
- package/dist/contracts/contract-call.js.map +1 -0
- package/dist/contracts/contract.d.ts +113 -0
- package/dist/contracts/contract.d.ts.map +1 -0
- package/dist/contracts/contract.js +107 -0
- package/dist/contracts/contract.js.map +1 -0
- package/dist/contracts/index.d.ts +7 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +7 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/contracts/lockup/abi.d.ts +62 -0
- package/dist/contracts/lockup/abi.d.ts.map +1 -0
- package/dist/contracts/lockup/abi.js +77 -0
- package/dist/contracts/lockup/abi.js.map +1 -0
- package/dist/contracts/lockup/calls.d.ts +23 -0
- package/dist/contracts/lockup/calls.d.ts.map +1 -0
- package/dist/contracts/lockup/calls.js +25 -0
- package/dist/contracts/lockup/calls.js.map +1 -0
- package/dist/contracts/lockup/helpers.d.ts +24 -0
- package/dist/contracts/lockup/helpers.d.ts.map +1 -0
- package/dist/contracts/lockup/helpers.js +49 -0
- package/dist/contracts/lockup/helpers.js.map +1 -0
- package/dist/contracts/lockup/index.d.ts +6 -0
- package/dist/contracts/lockup/index.d.ts.map +1 -0
- package/dist/contracts/lockup/index.js +6 -0
- package/dist/contracts/lockup/index.js.map +1 -0
- package/dist/contracts/lockup/parsers.d.ts +20 -0
- package/dist/contracts/lockup/parsers.d.ts.map +1 -0
- package/dist/contracts/lockup/parsers.js +60 -0
- package/dist/contracts/lockup/parsers.js.map +1 -0
- package/dist/contracts/lockup/storage-keys.d.ts +15 -0
- package/dist/contracts/lockup/storage-keys.d.ts.map +1 -0
- package/dist/contracts/lockup/storage-keys.js +78 -0
- package/dist/contracts/lockup/storage-keys.js.map +1 -0
- package/dist/contracts/lockup/types.d.ts +90 -0
- package/dist/contracts/lockup/types.d.ts.map +1 -0
- package/dist/contracts/lockup/types.js +7 -0
- package/dist/contracts/lockup/types.js.map +1 -0
- package/dist/contracts/lockup-prime/abi.d.ts +348 -0
- package/dist/contracts/lockup-prime/abi.d.ts.map +1 -0
- package/dist/contracts/lockup-prime/abi.js +420 -0
- package/dist/contracts/lockup-prime/abi.js.map +1 -0
- package/dist/contracts/lockup-prime/calls.d.ts +53 -0
- package/dist/contracts/lockup-prime/calls.d.ts.map +1 -0
- package/dist/contracts/lockup-prime/calls.js +60 -0
- package/dist/contracts/lockup-prime/calls.js.map +1 -0
- package/dist/contracts/lockup-prime/helpers.d.ts +38 -0
- package/dist/contracts/lockup-prime/helpers.d.ts.map +1 -0
- package/dist/contracts/lockup-prime/helpers.js +147 -0
- package/dist/contracts/lockup-prime/helpers.js.map +1 -0
- package/dist/contracts/lockup-prime/index.d.ts +6 -0
- package/dist/contracts/lockup-prime/index.d.ts.map +1 -0
- package/dist/contracts/lockup-prime/index.js +6 -0
- package/dist/contracts/lockup-prime/index.js.map +1 -0
- package/dist/contracts/lockup-prime/parsers.d.ts +25 -0
- package/dist/contracts/lockup-prime/parsers.d.ts.map +1 -0
- package/dist/contracts/lockup-prime/parsers.js +68 -0
- package/dist/contracts/lockup-prime/parsers.js.map +1 -0
- package/dist/contracts/lockup-prime/storage-keys.d.ts +25 -0
- package/dist/contracts/lockup-prime/storage-keys.d.ts.map +1 -0
- package/dist/contracts/lockup-prime/storage-keys.js +92 -0
- package/dist/contracts/lockup-prime/storage-keys.js.map +1 -0
- package/dist/contracts/lockup-prime/types.d.ts +116 -0
- package/dist/contracts/lockup-prime/types.d.ts.map +1 -0
- package/dist/contracts/lockup-prime/types.js +18 -0
- package/dist/contracts/lockup-prime/types.js.map +1 -0
- package/dist/crypto.js +1 -1
- package/dist/crypto.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/serialization.d.ts +22 -0
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +39 -2
- package/dist/serialization.js.map +1 -1
- package/dist/signing.d.ts +39 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +84 -0
- package/dist/signing.js.map +1 -0
- package/dist/transaction-builder.d.ts +135 -194
- package/dist/transaction-builder.d.ts.map +1 -1
- package/dist/transaction-builder.js +237 -288
- package/dist/transaction-builder.js.map +1 -1
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Transaction Builder
|
|
3
3
|
*
|
|
4
|
-
*
|
|
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
|
+
* ```
|
|
5
26
|
*/
|
|
6
|
-
import { bls12_381 as bls } from '@noble/curves/bls12-381';
|
|
7
|
-
import { sha256 } from '@noble/hashes/sha2';
|
|
8
27
|
import { deriveSkAndSeed64FromBase58Seed, getPublicKey } from './crypto';
|
|
9
|
-
import { fromBase58, toBase58 } from './encoding';
|
|
10
28
|
import { toAtomicAma } from './conversion';
|
|
11
|
-
import {
|
|
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';
|
|
12
34
|
/**
|
|
13
35
|
* Transaction Builder for Amadeus Protocol
|
|
14
36
|
*
|
|
@@ -17,31 +39,24 @@ import { encode } from './serialization';
|
|
|
17
39
|
*
|
|
18
40
|
* @example
|
|
19
41
|
* ```ts
|
|
20
|
-
* //
|
|
42
|
+
* // ABI-driven (recommended)
|
|
21
43
|
* const builder = new TransactionBuilder('5Kd3N...')
|
|
22
|
-
* const
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* symbol: 'AMA'
|
|
44
|
+
* const result = builder.contract(LOCKUP_PRIME_ABI).lock({
|
|
45
|
+
* amount: toAtomicAma(100).toString(),
|
|
46
|
+
* tier: '30d'
|
|
26
47
|
* })
|
|
27
48
|
*
|
|
28
|
-
* //
|
|
29
|
-
* const
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* symbol: 'AMA'
|
|
34
|
-
* })
|
|
49
|
+
* // Generic build/sign
|
|
50
|
+
* const builder = new TransactionBuilder('5Kd3N...')
|
|
51
|
+
* const { txHash, txPacked } = builder.buildAndSign('Coin', 'transfer', [
|
|
52
|
+
* recipientBytes, '1000000000', 'AMA'
|
|
53
|
+
* ])
|
|
35
54
|
* ```
|
|
36
55
|
*/
|
|
37
56
|
export class TransactionBuilder {
|
|
38
57
|
privateKey;
|
|
39
58
|
signerPk = null;
|
|
40
59
|
signerSk = null;
|
|
41
|
-
/**
|
|
42
|
-
* Domain Separation Tag for transaction signatures
|
|
43
|
-
*/
|
|
44
|
-
static TX_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_TX_';
|
|
45
60
|
/**
|
|
46
61
|
* Create a new TransactionBuilder instance
|
|
47
62
|
*
|
|
@@ -54,73 +69,6 @@ export class TransactionBuilder {
|
|
|
54
69
|
this.initializeKeys();
|
|
55
70
|
}
|
|
56
71
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Generate a transaction nonce based on current timestamp
|
|
59
|
-
*/
|
|
60
|
-
static generateNonce() {
|
|
61
|
-
return BigInt(Date.now()) * 1000000n;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Create transaction structure
|
|
65
|
-
*/
|
|
66
|
-
static createTransaction(signer, contract, method, args) {
|
|
67
|
-
const action = {
|
|
68
|
-
op: 'call',
|
|
69
|
-
contract,
|
|
70
|
-
function: method,
|
|
71
|
-
args
|
|
72
|
-
};
|
|
73
|
-
return {
|
|
74
|
-
signer,
|
|
75
|
-
nonce: TransactionBuilder.generateNonce(),
|
|
76
|
-
action
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Build an unsigned transaction (returns transaction structure and hash)
|
|
81
|
-
*/
|
|
82
|
-
static buildUnsignedTransaction(signerPk, contract, method, args) {
|
|
83
|
-
const tx = TransactionBuilder.createTransaction(signerPk, contract, method, args);
|
|
84
|
-
const txEncoded = encode(tx);
|
|
85
|
-
const hash = sha256(txEncoded);
|
|
86
|
-
return { tx, hash };
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Normalize signer secret key to PrivKey format (handles Base58 strings)
|
|
90
|
-
*/
|
|
91
|
-
static normalizeSignerSk(signerSk) {
|
|
92
|
-
if (typeof signerSk === 'string') {
|
|
93
|
-
// Base58 string - derive PrivKey from it
|
|
94
|
-
const { sk } = deriveSkAndSeed64FromBase58Seed(signerSk);
|
|
95
|
-
return sk;
|
|
96
|
-
}
|
|
97
|
-
// Already PrivKey (Uint8Array)
|
|
98
|
-
return signerSk;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Sign a transaction hash using BLS12-381 with transaction DST
|
|
102
|
-
*/
|
|
103
|
-
static signHash(hash, signerSk) {
|
|
104
|
-
const normalizedSk = TransactionBuilder.normalizeSignerSk(signerSk);
|
|
105
|
-
return bls.sign(hash, normalizedSk, { DST: TransactionBuilder.TX_DST });
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Sign an unsigned transaction
|
|
109
|
-
*/
|
|
110
|
-
static signTransaction(unsignedTx, signerSk) {
|
|
111
|
-
const signature = TransactionBuilder.signHash(unsignedTx.hash, signerSk);
|
|
112
|
-
return {
|
|
113
|
-
txHash: toBase58(unsignedTx.hash),
|
|
114
|
-
txPacked: encode({ tx: unsignedTx.tx, hash: unsignedTx.hash, signature })
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Build and sign a transaction (convenience method)
|
|
119
|
-
*/
|
|
120
|
-
static buildAndSignTransaction(signerPk, signerSk, contract, method, args) {
|
|
121
|
-
const unsignedTx = TransactionBuilder.buildUnsignedTransaction(signerPk, contract, method, args);
|
|
122
|
-
return TransactionBuilder.signTransaction(unsignedTx, signerSk);
|
|
123
|
-
}
|
|
124
72
|
/**
|
|
125
73
|
* Initialize signer keys from the private key
|
|
126
74
|
*/
|
|
@@ -132,266 +80,267 @@ export class TransactionBuilder {
|
|
|
132
80
|
this.signerPk = getPublicKey(seed64);
|
|
133
81
|
this.signerSk = sk;
|
|
134
82
|
}
|
|
135
|
-
/**
|
|
136
|
-
* Build an unsigned transaction
|
|
137
|
-
*
|
|
138
|
-
* @param contract - Contract name
|
|
139
|
-
* @param method - Method name
|
|
140
|
-
* @param args - Method arguments
|
|
141
|
-
* @param signerPk - Optional signer's public key (required if instance has no private key)
|
|
142
|
-
* @returns Unsigned transaction with hash
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```ts
|
|
146
|
-
* const builder = new TransactionBuilder('5Kd3N...')
|
|
147
|
-
* const unsignedTx = builder.build('Coin', 'transfer', [
|
|
148
|
-
* recipientBytes,
|
|
149
|
-
* '1000000000',
|
|
150
|
-
* 'AMA'
|
|
151
|
-
* ])
|
|
152
|
-
* // Can inspect or modify before signing
|
|
153
|
-
* const { txHash, txPacked } = builder.sign(unsignedTx)
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
|
-
build(contract, method, args, signerPk) {
|
|
157
|
-
const pk = signerPk || this.signerPk;
|
|
158
|
-
if (!pk) {
|
|
159
|
-
throw new Error('Signer public key required. Provide key or initialize builder with private key.');
|
|
160
|
-
}
|
|
161
|
-
return TransactionBuilder.buildUnsignedTransaction(pk, contract, method, args);
|
|
162
|
-
}
|
|
163
83
|
/**
|
|
164
84
|
* Get the signer's secret key (normalizes to PrivKey format)
|
|
165
|
-
* Handles Base58 strings, PrivKey (Uint8Array), or uses cached/derived key
|
|
166
85
|
*/
|
|
167
86
|
getSignerSk(signerSk) {
|
|
168
|
-
// If provided, normalize it (convert Base58 string to PrivKey if needed)
|
|
169
87
|
if (signerSk) {
|
|
170
|
-
|
|
171
|
-
// Base58 string - derive PrivKey from it
|
|
172
|
-
const { sk } = deriveSkAndSeed64FromBase58Seed(signerSk);
|
|
173
|
-
return sk;
|
|
174
|
-
}
|
|
175
|
-
// Already PrivKey (Uint8Array)
|
|
176
|
-
return signerSk;
|
|
88
|
+
return normalizeSignerSk(signerSk);
|
|
177
89
|
}
|
|
178
|
-
// Use cached signerSk if available
|
|
179
90
|
if (this.signerSk) {
|
|
180
91
|
return this.signerSk;
|
|
181
92
|
}
|
|
182
|
-
// Derive from privateKey
|
|
183
93
|
if (this.privateKey) {
|
|
184
|
-
|
|
185
|
-
return sk;
|
|
94
|
+
return normalizeSignerSk(this.privateKey);
|
|
186
95
|
}
|
|
187
96
|
throw new Error('Secret key required for signing');
|
|
188
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
|
+
// ========================================================================
|
|
189
108
|
/**
|
|
190
|
-
*
|
|
109
|
+
* Get a typed, signer-bound contract interface from an ABI definition.
|
|
191
110
|
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
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
|
|
195
116
|
*
|
|
196
117
|
* @example
|
|
197
118
|
* ```ts
|
|
198
119
|
* const builder = new TransactionBuilder('5Kd3N...')
|
|
199
|
-
*
|
|
200
|
-
*
|
|
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' })
|
|
201
135
|
* ```
|
|
202
136
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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);
|
|
206
142
|
}
|
|
143
|
+
// ========================================================================
|
|
144
|
+
// ContractCall-based API
|
|
145
|
+
// ========================================================================
|
|
207
146
|
/**
|
|
208
|
-
*
|
|
147
|
+
* Derive keys from a Base58 private key and sign a ContractCall.
|
|
209
148
|
*
|
|
210
|
-
* @param
|
|
211
|
-
* @param
|
|
212
|
-
* @param args - Method arguments
|
|
213
|
-
* @param signerPk - Optional signer's public key (required if instance has no private key)
|
|
214
|
-
* @param signerSk - Optional signer's secret key (required if instance has no private key)
|
|
149
|
+
* @param senderPrivkey - Base58 encoded private key (seed)
|
|
150
|
+
* @param call - A ContractCall from createContract(), buildContractCall(), or buildCoinTransfer()
|
|
215
151
|
* @returns Transaction hash and packed transaction
|
|
216
152
|
*
|
|
217
153
|
* @example
|
|
218
154
|
* ```ts
|
|
219
|
-
* const
|
|
220
|
-
* const
|
|
221
|
-
*
|
|
222
|
-
* '1000000000',
|
|
223
|
-
* 'AMA'
|
|
224
|
-
* ])
|
|
155
|
+
* const lockupPrime = createContract(LOCKUP_PRIME_ABI)
|
|
156
|
+
* const call = lockupPrime.lock({ amount: '100000000000', tier: '30d' })
|
|
157
|
+
* const { txHash, txPacked } = TransactionBuilder.signCall('5Kd3N...', call)
|
|
225
158
|
* ```
|
|
226
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
|
+
*/
|
|
227
207
|
buildAndSign(contract, method, args, signerPk, signerSk) {
|
|
228
|
-
const pk =
|
|
229
|
-
if (!pk) {
|
|
230
|
-
throw new Error('Signer public key required. Provide key or initialize builder with private key.');
|
|
231
|
-
}
|
|
208
|
+
const pk = this.requirePk(signerPk);
|
|
232
209
|
const sk = this.getSignerSk(signerSk);
|
|
233
|
-
return
|
|
210
|
+
return buildAndSignRaw(pk, sk, contract, method, args);
|
|
234
211
|
}
|
|
235
212
|
/**
|
|
236
|
-
* Build an unsigned
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
*
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
*
|
|
249
|
-
|
|
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
|
|
250
235
|
*/
|
|
251
236
|
buildTransfer(input) {
|
|
252
|
-
|
|
253
|
-
throw new Error('Public key required. Initialize builder with private key or provide signerPk.');
|
|
254
|
-
}
|
|
255
|
-
return this.build('Coin', 'transfer', [
|
|
256
|
-
fromBase58(input.recipient),
|
|
257
|
-
toAtomicAma(input.amount).toString(),
|
|
258
|
-
input.symbol
|
|
259
|
-
]);
|
|
237
|
+
return this.buildFromCall(buildCoinTransfer(input));
|
|
260
238
|
}
|
|
261
239
|
/**
|
|
262
|
-
* Build and sign a transfer transaction
|
|
263
|
-
*
|
|
264
|
-
* @param input - Transfer transaction parameters
|
|
265
|
-
* @returns Transaction hash and packed transaction
|
|
266
|
-
*
|
|
267
|
-
* @example
|
|
268
|
-
* ```ts
|
|
269
|
-
* const builder = new TransactionBuilder('5Kd3N...')
|
|
270
|
-
* const { txHash, txPacked } = builder.transfer({
|
|
271
|
-
* recipient: '5Kd3N...',
|
|
272
|
-
* amount: 10.5,
|
|
273
|
-
* symbol: 'AMA'
|
|
274
|
-
* })
|
|
275
|
-
* ```
|
|
240
|
+
* Build and sign a Coin transfer transaction
|
|
276
241
|
*/
|
|
277
242
|
transfer(input) {
|
|
278
243
|
if (!this.privateKey) {
|
|
279
244
|
throw new Error('Private key required. Initialize builder with private key or use static method.');
|
|
280
245
|
}
|
|
281
|
-
return this.
|
|
282
|
-
fromBase58(input.recipient),
|
|
283
|
-
toAtomicAma(input.amount).toString(),
|
|
284
|
-
input.symbol
|
|
285
|
-
]);
|
|
246
|
+
return this.buildAndSignCall(buildCoinTransfer(input));
|
|
286
247
|
}
|
|
248
|
+
// ========================================================================
|
|
249
|
+
// Coin transfer (static)
|
|
250
|
+
// ========================================================================
|
|
287
251
|
/**
|
|
288
|
-
* Build an unsigned transfer transaction (static
|
|
289
|
-
*
|
|
290
|
-
* @param input - Transfer transaction parameters (without senderPrivkey)
|
|
291
|
-
* @param signerPk - Signer's public key
|
|
292
|
-
* @returns Unsigned transaction with hash
|
|
293
|
-
*
|
|
294
|
-
* @example
|
|
295
|
-
* ```ts
|
|
296
|
-
* const unsignedTx = TransactionBuilder.buildTransfer(
|
|
297
|
-
* { recipient: '5Kd3N...', amount: 10.5, symbol: 'AMA' },
|
|
298
|
-
* publicKey
|
|
299
|
-
* )
|
|
300
|
-
* ```
|
|
252
|
+
* Build an unsigned Coin transfer transaction (static)
|
|
301
253
|
*/
|
|
302
254
|
static buildTransfer(input, signerPk) {
|
|
303
|
-
return TransactionBuilder.
|
|
304
|
-
fromBase58(input.recipient),
|
|
305
|
-
toAtomicAma(input.amount).toString(),
|
|
306
|
-
input.symbol
|
|
307
|
-
]);
|
|
255
|
+
return TransactionBuilder.buildFromCall(buildCoinTransfer(input), signerPk);
|
|
308
256
|
}
|
|
309
257
|
/**
|
|
310
|
-
* Build and sign a transfer transaction (static
|
|
311
|
-
*
|
|
312
|
-
* @param input - Transfer transaction parameters
|
|
313
|
-
* @returns Transaction hash and packed transaction
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* ```ts
|
|
317
|
-
* const { txHash, txPacked } = TransactionBuilder.buildSignedTransfer({
|
|
318
|
-
* senderPrivkey: '5Kd3N...',
|
|
319
|
-
* recipient: '5Kd3N...',
|
|
320
|
-
* amount: 10.5,
|
|
321
|
-
* symbol: 'AMA'
|
|
322
|
-
* })
|
|
323
|
-
* ```
|
|
258
|
+
* Build and sign a Coin transfer transaction (static)
|
|
324
259
|
*/
|
|
325
260
|
static buildSignedTransfer(input) {
|
|
326
|
-
|
|
327
|
-
const signerPubKey = getPublicKey(seed64);
|
|
328
|
-
return TransactionBuilder.buildAndSignTransaction(signerPubKey, sk, 'Coin', 'transfer', [
|
|
329
|
-
fromBase58(input.recipient),
|
|
330
|
-
toAtomicAma(input.amount).toString(),
|
|
331
|
-
input.symbol
|
|
332
|
-
]);
|
|
261
|
+
return TransactionBuilder.signCall(input.senderPrivkey, buildCoinTransfer({ recipient: input.recipient, amount: input.amount, symbol: input.symbol }));
|
|
333
262
|
}
|
|
263
|
+
// ========================================================================
|
|
264
|
+
// LockupPrime (instance)
|
|
265
|
+
// ========================================================================
|
|
334
266
|
/**
|
|
335
|
-
* Build
|
|
336
|
-
*
|
|
337
|
-
* @param signerPk - Signer's public key
|
|
338
|
-
* @param contract - Contract name
|
|
339
|
-
* @param method - Method name
|
|
340
|
-
* @param args - Method arguments
|
|
341
|
-
* @returns Unsigned transaction with hash
|
|
342
|
-
*
|
|
343
|
-
* @example
|
|
344
|
-
* ```ts
|
|
345
|
-
* const unsignedTx = TransactionBuilder.build(
|
|
346
|
-
* publicKey,
|
|
347
|
-
* 'Coin',
|
|
348
|
-
* 'transfer',
|
|
349
|
-
* [recipientBytes, amount, 'AMA']
|
|
350
|
-
* )
|
|
351
|
-
* ```
|
|
267
|
+
* Build and sign a LockupPrime lock transaction
|
|
352
268
|
*/
|
|
353
|
-
|
|
354
|
-
return
|
|
269
|
+
lockupPrimeLock(input) {
|
|
270
|
+
return this.contract(LOCKUP_PRIME_ABI).lock({
|
|
271
|
+
amount: toAtomicAma(input.amount).toString(),
|
|
272
|
+
tier: input.tier
|
|
273
|
+
});
|
|
355
274
|
}
|
|
356
275
|
/**
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
* @param unsignedTx - Unsigned transaction with hash
|
|
360
|
-
* @param signerSk - Signer's secret key
|
|
361
|
-
* @returns Transaction hash and packed transaction
|
|
362
|
-
*
|
|
363
|
-
* @example
|
|
364
|
-
* ```ts
|
|
365
|
-
* const unsignedTx = TransactionBuilder.build(publicKey, 'Coin', 'transfer', args)
|
|
366
|
-
* const { txHash, txPacked } = TransactionBuilder.sign(unsignedTx, secretKey)
|
|
367
|
-
* ```
|
|
276
|
+
* Build and sign a LockupPrime unlock transaction
|
|
368
277
|
*/
|
|
369
|
-
|
|
370
|
-
return
|
|
278
|
+
lockupPrimeUnlock(input) {
|
|
279
|
+
return this.contract(LOCKUP_PRIME_ABI).unlock({
|
|
280
|
+
vaultIndex: input.vaultIndex.toString()
|
|
281
|
+
});
|
|
371
282
|
}
|
|
372
283
|
/**
|
|
373
|
-
* Build and sign a
|
|
374
|
-
*
|
|
375
|
-
* @param signerPk - Signer's public key
|
|
376
|
-
* @param signerSk - Signer's secret key
|
|
377
|
-
* @param contract - Contract name
|
|
378
|
-
* @param method - Method name
|
|
379
|
-
* @param args - Method arguments
|
|
380
|
-
* @returns Transaction hash and packed transaction
|
|
381
|
-
*
|
|
382
|
-
* @example
|
|
383
|
-
* ```ts
|
|
384
|
-
* const { txHash, txPacked } = TransactionBuilder.buildAndSign(
|
|
385
|
-
* publicKey,
|
|
386
|
-
* secretKey,
|
|
387
|
-
* 'Coin',
|
|
388
|
-
* 'transfer',
|
|
389
|
-
* [recipientBytes, amount, 'AMA']
|
|
390
|
-
* )
|
|
391
|
-
* ```
|
|
284
|
+
* Build and sign a LockupPrime daily check-in transaction
|
|
392
285
|
*/
|
|
393
|
-
|
|
394
|
-
return
|
|
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);
|
|
395
344
|
}
|
|
396
345
|
}
|
|
397
346
|
//# sourceMappingURL=transaction-builder.js.map
|