@alephium/web3 1.7.4 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +68 -9
- package/dist/src/api/api-alephium.js +33 -2
- package/dist/src/signer/signer.d.ts +5 -2
- package/dist/src/signer/signer.js +14 -4
- package/dist/src/signer/tx-builder.d.ts +8 -1
- package/dist/src/signer/tx-builder.js +107 -23
- package/dist/src/signer/types.d.ts +20 -0
- package/package.json +2 -2
- package/src/api/api-alephium.ts +104 -10
- package/src/signer/signer.ts +24 -10
- package/src/signer/tx-builder.ts +141 -28
- package/src/signer/types.ts +22 -2
package/src/api/api-alephium.ts
CHANGED
|
@@ -189,6 +189,51 @@ export interface BrokerInfo {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
/** BuildChainedDeployContractTx */
|
|
193
|
+
export interface BuildChainedDeployContractTx {
|
|
194
|
+
value: BuildDeployContractTx
|
|
195
|
+
type: string
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** BuildChainedDeployContractTxResult */
|
|
199
|
+
export interface BuildChainedDeployContractTxResult {
|
|
200
|
+
value: BuildDeployContractTxResult
|
|
201
|
+
type: string
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** BuildChainedExecuteScriptTx */
|
|
205
|
+
export interface BuildChainedExecuteScriptTx {
|
|
206
|
+
value: BuildExecuteScriptTx
|
|
207
|
+
type: string
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** BuildChainedExecuteScriptTxResult */
|
|
211
|
+
export interface BuildChainedExecuteScriptTxResult {
|
|
212
|
+
value: BuildExecuteScriptTxResult
|
|
213
|
+
type: string
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** BuildChainedTransferTx */
|
|
217
|
+
export interface BuildChainedTransferTx {
|
|
218
|
+
value: BuildTransferTx
|
|
219
|
+
type: string
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** BuildChainedTransferTxResult */
|
|
223
|
+
export interface BuildChainedTransferTxResult {
|
|
224
|
+
value: BuildTransferTxResult
|
|
225
|
+
type: string
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** BuildChainedTx */
|
|
229
|
+
export type BuildChainedTx = BuildChainedDeployContractTx | BuildChainedExecuteScriptTx | BuildChainedTransferTx
|
|
230
|
+
|
|
231
|
+
/** BuildChainedTxResult */
|
|
232
|
+
export type BuildChainedTxResult =
|
|
233
|
+
| BuildChainedDeployContractTxResult
|
|
234
|
+
| BuildChainedExecuteScriptTxResult
|
|
235
|
+
| BuildChainedTransferTxResult
|
|
236
|
+
|
|
192
237
|
/** BuildDeployContractTx */
|
|
193
238
|
export interface BuildDeployContractTx {
|
|
194
239
|
/** @format hex-string */
|
|
@@ -353,8 +398,8 @@ export interface BuildSweepMultisig {
|
|
|
353
398
|
targetBlockHash?: string
|
|
354
399
|
}
|
|
355
400
|
|
|
356
|
-
/**
|
|
357
|
-
export interface
|
|
401
|
+
/** BuildTransferTx */
|
|
402
|
+
export interface BuildTransferTx {
|
|
358
403
|
/** @format hex-string */
|
|
359
404
|
fromPublicKey: string
|
|
360
405
|
/** @format hex-string */
|
|
@@ -369,8 +414,8 @@ export interface BuildTransaction {
|
|
|
369
414
|
targetBlockHash?: string
|
|
370
415
|
}
|
|
371
416
|
|
|
372
|
-
/**
|
|
373
|
-
export interface
|
|
417
|
+
/** BuildTransferTxResult */
|
|
418
|
+
export interface BuildTransferTxResult {
|
|
374
419
|
unsignedTx: string
|
|
375
420
|
/** @format gas */
|
|
376
421
|
gasAmount: number
|
|
@@ -1204,6 +1249,8 @@ export interface TransactionTemplate {
|
|
|
1204
1249
|
unsigned: UnsignedTx
|
|
1205
1250
|
inputSignatures: string[]
|
|
1206
1251
|
scriptSignatures: string[]
|
|
1252
|
+
/** @format int64 */
|
|
1253
|
+
seenAt: number
|
|
1207
1254
|
}
|
|
1208
1255
|
|
|
1209
1256
|
/** Transfer */
|
|
@@ -1603,7 +1650,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1603
1650
|
|
|
1604
1651
|
/**
|
|
1605
1652
|
* @title Alephium API
|
|
1606
|
-
* @version 3.
|
|
1653
|
+
* @version 3.8.1
|
|
1607
1654
|
* @baseUrl ../
|
|
1608
1655
|
*/
|
|
1609
1656
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -2529,12 +2576,12 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2529
2576
|
*
|
|
2530
2577
|
* @tags Transactions
|
|
2531
2578
|
* @name PostTransactionsBuild
|
|
2532
|
-
* @summary Build an unsigned transaction to a number of recipients
|
|
2579
|
+
* @summary Build an unsigned transfer transaction to a number of recipients
|
|
2533
2580
|
* @request POST:/transactions/build
|
|
2534
2581
|
*/
|
|
2535
|
-
postTransactionsBuild: (data:
|
|
2582
|
+
postTransactionsBuild: (data: BuildTransferTx, params: RequestParams = {}) =>
|
|
2536
2583
|
this.request<
|
|
2537
|
-
|
|
2584
|
+
BuildTransferTxResult,
|
|
2538
2585
|
BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
|
|
2539
2586
|
>({
|
|
2540
2587
|
path: `/transactions/build`,
|
|
@@ -2555,7 +2602,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2555
2602
|
*/
|
|
2556
2603
|
postTransactionsBuildMultiAddresses: (data: BuildMultiAddressesTransaction, params: RequestParams = {}) =>
|
|
2557
2604
|
this.request<
|
|
2558
|
-
|
|
2605
|
+
BuildTransferTxResult,
|
|
2559
2606
|
BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
|
|
2560
2607
|
>({
|
|
2561
2608
|
path: `/transactions/build-multi-addresses`,
|
|
@@ -2652,6 +2699,32 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2652
2699
|
...params
|
|
2653
2700
|
}).then(convertHttpResponse),
|
|
2654
2701
|
|
|
2702
|
+
/**
|
|
2703
|
+
* No description
|
|
2704
|
+
*
|
|
2705
|
+
* @tags Transactions
|
|
2706
|
+
* @name GetTransactionsRichDetailsTxid
|
|
2707
|
+
* @summary Get transaction with enriched input information when node indexes are enabled.
|
|
2708
|
+
* @request GET:/transactions/rich-details/{txId}
|
|
2709
|
+
*/
|
|
2710
|
+
getTransactionsRichDetailsTxid: (
|
|
2711
|
+
txId: string,
|
|
2712
|
+
query?: {
|
|
2713
|
+
/** @format int32 */
|
|
2714
|
+
fromGroup?: number
|
|
2715
|
+
/** @format int32 */
|
|
2716
|
+
toGroup?: number
|
|
2717
|
+
},
|
|
2718
|
+
params: RequestParams = {}
|
|
2719
|
+
) =>
|
|
2720
|
+
this.request<RichTransaction, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
2721
|
+
path: `/transactions/rich-details/${txId}`,
|
|
2722
|
+
method: 'GET',
|
|
2723
|
+
query: query,
|
|
2724
|
+
format: 'json',
|
|
2725
|
+
...params
|
|
2726
|
+
}).then(convertHttpResponse),
|
|
2727
|
+
|
|
2655
2728
|
/**
|
|
2656
2729
|
* No description
|
|
2657
2730
|
*
|
|
@@ -2728,6 +2801,27 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2728
2801
|
query: query,
|
|
2729
2802
|
format: 'json',
|
|
2730
2803
|
...params
|
|
2804
|
+
}).then(convertHttpResponse),
|
|
2805
|
+
|
|
2806
|
+
/**
|
|
2807
|
+
* No description
|
|
2808
|
+
*
|
|
2809
|
+
* @tags Transactions
|
|
2810
|
+
* @name PostTransactionsBuildChained
|
|
2811
|
+
* @summary Build a chain of transactions
|
|
2812
|
+
* @request POST:/transactions/build-chained
|
|
2813
|
+
*/
|
|
2814
|
+
postTransactionsBuildChained: (data: BuildChainedTx[], params: RequestParams = {}) =>
|
|
2815
|
+
this.request<
|
|
2816
|
+
BuildChainedTxResult[],
|
|
2817
|
+
BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
|
|
2818
|
+
>({
|
|
2819
|
+
path: `/transactions/build-chained`,
|
|
2820
|
+
method: 'POST',
|
|
2821
|
+
body: data,
|
|
2822
|
+
type: ContentType.Json,
|
|
2823
|
+
format: 'json',
|
|
2824
|
+
...params
|
|
2731
2825
|
}).then(convertHttpResponse)
|
|
2732
2826
|
}
|
|
2733
2827
|
mempool = {
|
|
@@ -3095,7 +3189,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
3095
3189
|
*/
|
|
3096
3190
|
postMultisigBuild: (data: BuildMultisig, params: RequestParams = {}) =>
|
|
3097
3191
|
this.request<
|
|
3098
|
-
|
|
3192
|
+
BuildTransferTxResult,
|
|
3099
3193
|
BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable
|
|
3100
3194
|
>({
|
|
3101
3195
|
path: `/multisig/build`,
|
package/src/signer/signer.ts
CHANGED
|
@@ -28,7 +28,6 @@ import {
|
|
|
28
28
|
Destination,
|
|
29
29
|
SignDeployContractTxParams,
|
|
30
30
|
SignDeployContractTxResult,
|
|
31
|
-
SignerAddress,
|
|
32
31
|
SignExecuteScriptTxParams,
|
|
33
32
|
SignExecuteScriptTxResult,
|
|
34
33
|
SignMessageParams,
|
|
@@ -40,7 +39,9 @@ import {
|
|
|
40
39
|
SubmissionResult,
|
|
41
40
|
SubmitTransactionParams,
|
|
42
41
|
KeyType,
|
|
43
|
-
MessageHasher
|
|
42
|
+
MessageHasher,
|
|
43
|
+
SignChainedTxParams,
|
|
44
|
+
SignChainedTxResult
|
|
44
45
|
} from './types'
|
|
45
46
|
import { TransactionBuilder } from './tx-builder'
|
|
46
47
|
import { addressFromPublicKey, groupOfAddress } from '../address'
|
|
@@ -68,6 +69,7 @@ export abstract class SignerProvider {
|
|
|
68
69
|
abstract signAndSubmitDeployContractTx(params: SignDeployContractTxParams): Promise<SignDeployContractTxResult>
|
|
69
70
|
abstract signAndSubmitExecuteScriptTx(params: SignExecuteScriptTxParams): Promise<SignExecuteScriptTxResult>
|
|
70
71
|
abstract signAndSubmitUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>
|
|
72
|
+
abstract signAndSubmitChainedTx(params: SignChainedTxParams[]): Promise<SignChainedTxResult[]>
|
|
71
73
|
|
|
72
74
|
abstract signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult>
|
|
73
75
|
// The message will be prefixed with 'Alephium Signed Message: ' before signing
|
|
@@ -117,17 +119,16 @@ export abstract class SignerProviderSimple extends SignerProvider {
|
|
|
117
119
|
await this.submitTransaction(signResult)
|
|
118
120
|
return signResult
|
|
119
121
|
}
|
|
122
|
+
override async signAndSubmitChainedTx(params: SignChainedTxParams[]): Promise<SignChainedTxResult[]> {
|
|
123
|
+
const signResults = await this.signChainedTx(params)
|
|
124
|
+
for (const r of signResults) {
|
|
125
|
+
await this.submitTransaction(r)
|
|
126
|
+
}
|
|
127
|
+
return signResults
|
|
128
|
+
}
|
|
120
129
|
|
|
121
130
|
protected abstract getPublicKey(address: string): Promise<string>
|
|
122
131
|
|
|
123
|
-
private async usePublicKey<T extends SignerAddress>(
|
|
124
|
-
params: T
|
|
125
|
-
): Promise<Omit<T, 'signerAddress'> & { fromPublicKey: string }> {
|
|
126
|
-
const { signerAddress, ...restParams } = params
|
|
127
|
-
const publicKey = await this.getPublicKey(signerAddress)
|
|
128
|
-
return { fromPublicKey: publicKey, ...restParams }
|
|
129
|
-
}
|
|
130
|
-
|
|
131
132
|
async signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult> {
|
|
132
133
|
const response = await this.buildTransferTx(params)
|
|
133
134
|
const signature = await this.signRaw(params.signerAddress, response.txId)
|
|
@@ -169,6 +170,19 @@ export abstract class SignerProviderSimple extends SignerProvider {
|
|
|
169
170
|
)
|
|
170
171
|
}
|
|
171
172
|
|
|
173
|
+
async signChainedTx(params: SignChainedTxParams[]): Promise<SignChainedTxResult[]> {
|
|
174
|
+
const response = await this.buildChainedTx(params)
|
|
175
|
+
const signatures = await Promise.all(response.map((r, i) => this.signRaw(params[`${i}`].signerAddress, r.txId)))
|
|
176
|
+
return response.map((r, i) => ({ ...r, signature: signatures[`${i}`] } as SignChainedTxResult))
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async buildChainedTx(params: SignChainedTxParams[]): Promise<Omit<SignChainedTxResult, 'signature'>[]> {
|
|
180
|
+
return TransactionBuilder.from(this.nodeProvider).buildChainedTx(
|
|
181
|
+
params,
|
|
182
|
+
await Promise.all(params.map((p) => this.getPublicKey(p.signerAddress)))
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
172
186
|
// in general, wallet should show the decoded information to user for confirmation
|
|
173
187
|
// please overwrite this function for real wallet
|
|
174
188
|
async signUnsignedTx(params: SignUnsignedTxParams): Promise<SignUnsignedTxResult> {
|
package/src/signer/tx-builder.ts
CHANGED
|
@@ -21,20 +21,26 @@ import { fromApiNumber256, node, NodeProvider, toApiNumber256Optional, toApiToke
|
|
|
21
21
|
import { addressFromPublicKey, contractIdFromAddress } from '../address'
|
|
22
22
|
import { toApiDestinations } from './signer'
|
|
23
23
|
import {
|
|
24
|
+
SignChainedTxParams,
|
|
25
|
+
SignChainedTxResult,
|
|
24
26
|
KeyType,
|
|
27
|
+
SignDeployContractChainedTxResult,
|
|
25
28
|
SignDeployContractTxParams,
|
|
26
29
|
SignDeployContractTxResult,
|
|
27
30
|
SignerAddress,
|
|
31
|
+
SignExecuteScriptChainedTxResult,
|
|
28
32
|
SignExecuteScriptTxParams,
|
|
29
33
|
SignExecuteScriptTxResult,
|
|
34
|
+
SignTransferChainedTxResult,
|
|
30
35
|
SignTransferTxParams,
|
|
31
36
|
SignTransferTxResult,
|
|
32
37
|
SignUnsignedTxParams,
|
|
33
38
|
SignUnsignedTxResult
|
|
34
39
|
} from './types'
|
|
35
|
-
import { unsignedTxCodec
|
|
40
|
+
import { unsignedTxCodec } from '../codec'
|
|
36
41
|
import { groupIndexOfTransaction } from '../transaction'
|
|
37
42
|
import { blakeHash } from '../codec/hash'
|
|
43
|
+
import { BuildDeployContractTxResult, BuildChainedTx, BuildChainedTxResult } from '../api/api-alephium'
|
|
38
44
|
|
|
39
45
|
export abstract class TransactionBuilder {
|
|
40
46
|
abstract get nodeProvider(): NodeProvider
|
|
@@ -62,28 +68,129 @@ export abstract class TransactionBuilder {
|
|
|
62
68
|
params: SignTransferTxParams,
|
|
63
69
|
publicKey: string
|
|
64
70
|
): Promise<Omit<SignTransferTxResult, 'signature'>> {
|
|
71
|
+
const data = this.buildTransferTxParams(params, publicKey)
|
|
72
|
+
const response = await this.nodeProvider.transactions.postTransactionsBuild(data)
|
|
73
|
+
return this.convertTransferTxResult(response)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async buildDeployContractTx(
|
|
77
|
+
params: SignDeployContractTxParams,
|
|
78
|
+
publicKey: string
|
|
79
|
+
): Promise<Omit<SignDeployContractTxResult, 'signature'>> {
|
|
80
|
+
const data = this.buildDeployContractTxParams(params, publicKey)
|
|
81
|
+
const response = await this.nodeProvider.contracts.postContractsUnsignedTxDeployContract(data)
|
|
82
|
+
return this.convertDeployContractTxResult(response)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async buildExecuteScriptTx(
|
|
86
|
+
params: SignExecuteScriptTxParams,
|
|
87
|
+
publicKey: string
|
|
88
|
+
): Promise<Omit<SignExecuteScriptTxResult, 'signature'>> {
|
|
89
|
+
const data = this.buildExecuteScriptTxParams(params, publicKey)
|
|
90
|
+
const response = await this.nodeProvider.contracts.postContractsUnsignedTxExecuteScript(data)
|
|
91
|
+
return this.convertExecuteScriptTxResult(response)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async buildChainedTx(
|
|
95
|
+
params: SignChainedTxParams[],
|
|
96
|
+
publicKeys: string[]
|
|
97
|
+
): Promise<Omit<SignChainedTxResult, 'signature'>[]> {
|
|
98
|
+
if (params.length !== publicKeys.length) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
'The number of build chained transaction parameters must match the number of public keys provided'
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const data: BuildChainedTx[] = params.map((param, index) => {
|
|
105
|
+
const paramType = param.type
|
|
106
|
+
switch (paramType) {
|
|
107
|
+
case 'Transfer': {
|
|
108
|
+
const value = this.buildTransferTxParams(param, publicKeys[index])
|
|
109
|
+
return { type: paramType, value }
|
|
110
|
+
}
|
|
111
|
+
case 'DeployContract': {
|
|
112
|
+
const value = this.buildDeployContractTxParams(param, publicKeys[index])
|
|
113
|
+
return { type: paramType, value }
|
|
114
|
+
}
|
|
115
|
+
case 'ExecuteScript': {
|
|
116
|
+
const value = this.buildExecuteScriptTxParams(param, publicKeys[index])
|
|
117
|
+
return { type: paramType, value }
|
|
118
|
+
}
|
|
119
|
+
default:
|
|
120
|
+
throw new Error(`Unsupported transaction type: ${paramType}`)
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
const buildChainedTxsResponse = await this.nodeProvider.transactions.postTransactionsBuildChained(data)
|
|
125
|
+
|
|
126
|
+
const results = buildChainedTxsResponse.map((buildResult) => {
|
|
127
|
+
const buildResultType = buildResult.type
|
|
128
|
+
switch (buildResultType) {
|
|
129
|
+
case 'Transfer': {
|
|
130
|
+
const buildTransferTxResult = buildResult.value
|
|
131
|
+
return {
|
|
132
|
+
...this.convertTransferTxResult(buildTransferTxResult),
|
|
133
|
+
type: buildResultType
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
case 'DeployContract': {
|
|
137
|
+
const buildDeployContractTxResult = buildResult.value as BuildDeployContractTxResult
|
|
138
|
+
return {
|
|
139
|
+
...this.convertDeployContractTxResult(buildDeployContractTxResult),
|
|
140
|
+
type: buildResultType
|
|
141
|
+
} as SignDeployContractChainedTxResult
|
|
142
|
+
}
|
|
143
|
+
case 'ExecuteScript': {
|
|
144
|
+
const buildExecuteScriptTxResult = buildResult.value
|
|
145
|
+
return {
|
|
146
|
+
...this.convertExecuteScriptTxResult(buildExecuteScriptTxResult),
|
|
147
|
+
type: buildResultType
|
|
148
|
+
} as SignExecuteScriptChainedTxResult
|
|
149
|
+
}
|
|
150
|
+
default:
|
|
151
|
+
throw new Error(`Unexpected transaction type: ${buildResultType} for ${buildResult.value.txId}`)
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
return results
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
buildUnsignedTx(params: SignUnsignedTxParams): Omit<SignUnsignedTxResult, 'signature'> {
|
|
159
|
+
const unsignedTxBin = hexToBinUnsafe(params.unsignedTx)
|
|
160
|
+
const decoded = unsignedTxCodec.decode(unsignedTxBin)
|
|
161
|
+
const txId = binToHex(blakeHash(unsignedTxBin))
|
|
162
|
+
const [fromGroup, toGroup] = groupIndexOfTransaction(decoded)
|
|
163
|
+
return {
|
|
164
|
+
fromGroup: fromGroup,
|
|
165
|
+
toGroup: toGroup,
|
|
166
|
+
unsignedTx: params.unsignedTx,
|
|
167
|
+
txId: txId,
|
|
168
|
+
gasAmount: decoded.gasAmount,
|
|
169
|
+
gasPrice: decoded.gasPrice
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private buildTransferTxParams(params: SignTransferTxParams, publicKey: string): node.BuildTransferTx {
|
|
65
174
|
TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType)
|
|
66
175
|
|
|
67
176
|
const { destinations, gasPrice, ...rest } = params
|
|
68
|
-
|
|
177
|
+
return {
|
|
69
178
|
fromPublicKey: publicKey,
|
|
70
179
|
fromPublicKeyType: params.signerKeyType,
|
|
71
180
|
destinations: toApiDestinations(destinations),
|
|
72
181
|
gasPrice: toApiNumber256Optional(gasPrice),
|
|
73
182
|
...rest
|
|
74
183
|
}
|
|
75
|
-
const response = await this.nodeProvider.transactions.postTransactionsBuild(data)
|
|
76
|
-
return { ...response, gasPrice: fromApiNumber256(response.gasPrice) }
|
|
77
184
|
}
|
|
78
185
|
|
|
79
|
-
|
|
186
|
+
private buildDeployContractTxParams(
|
|
80
187
|
params: SignDeployContractTxParams,
|
|
81
188
|
publicKey: string
|
|
82
|
-
):
|
|
189
|
+
): node.BuildDeployContractTx {
|
|
83
190
|
TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType)
|
|
84
191
|
|
|
85
192
|
const { initialAttoAlphAmount, initialTokenAmounts, issueTokenAmount, gasPrice, ...rest } = params
|
|
86
|
-
|
|
193
|
+
return {
|
|
87
194
|
fromPublicKey: publicKey,
|
|
88
195
|
fromPublicKeyType: params.signerKeyType,
|
|
89
196
|
initialAttoAlphAmount: toApiNumber256Optional(initialAttoAlphAmount),
|
|
@@ -92,19 +199,13 @@ export abstract class TransactionBuilder {
|
|
|
92
199
|
gasPrice: toApiNumber256Optional(gasPrice),
|
|
93
200
|
...rest
|
|
94
201
|
}
|
|
95
|
-
const response = await this.nodeProvider.contracts.postContractsUnsignedTxDeployContract(data)
|
|
96
|
-
const contractId = binToHex(contractIdFromAddress(response.contractAddress))
|
|
97
|
-
return { ...response, groupIndex: response.fromGroup, contractId, gasPrice: fromApiNumber256(response.gasPrice) }
|
|
98
202
|
}
|
|
99
203
|
|
|
100
|
-
|
|
101
|
-
params: SignExecuteScriptTxParams,
|
|
102
|
-
publicKey: string
|
|
103
|
-
): Promise<Omit<SignExecuteScriptTxResult, 'signature'>> {
|
|
204
|
+
private buildExecuteScriptTxParams(params: SignExecuteScriptTxParams, publicKey: string): node.BuildExecuteScriptTx {
|
|
104
205
|
TransactionBuilder.validatePublicKey(params, publicKey, params.signerKeyType)
|
|
105
206
|
|
|
106
207
|
const { attoAlphAmount, tokens, gasPrice, ...rest } = params
|
|
107
|
-
|
|
208
|
+
return {
|
|
108
209
|
fromPublicKey: publicKey,
|
|
109
210
|
fromPublicKeyType: params.signerKeyType,
|
|
110
211
|
attoAlphAmount: toApiNumber256Optional(attoAlphAmount),
|
|
@@ -112,22 +213,34 @@ export abstract class TransactionBuilder {
|
|
|
112
213
|
gasPrice: toApiNumber256Optional(gasPrice),
|
|
113
214
|
...rest
|
|
114
215
|
}
|
|
115
|
-
const response = await this.nodeProvider.contracts.postContractsUnsignedTxExecuteScript(data)
|
|
116
|
-
return { ...response, groupIndex: response.fromGroup, gasPrice: fromApiNumber256(response.gasPrice) }
|
|
117
216
|
}
|
|
118
217
|
|
|
119
|
-
|
|
120
|
-
const unsignedTxBin = hexToBinUnsafe(params.unsignedTx)
|
|
121
|
-
const decoded = unsignedTxCodec.decode(unsignedTxBin)
|
|
122
|
-
const txId = binToHex(blakeHash(unsignedTxBin))
|
|
123
|
-
const [fromGroup, toGroup] = groupIndexOfTransaction(decoded)
|
|
218
|
+
private convertTransferTxResult(result: node.BuildTransferTxResult): Omit<SignTransferTxResult, 'signature'> {
|
|
124
219
|
return {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
220
|
+
...result,
|
|
221
|
+
gasPrice: fromApiNumber256(result.gasPrice)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private convertDeployContractTxResult(
|
|
226
|
+
result: node.BuildDeployContractTxResult
|
|
227
|
+
): Omit<SignDeployContractTxResult, 'signature'> {
|
|
228
|
+
const contractId = binToHex(contractIdFromAddress(result.contractAddress))
|
|
229
|
+
return {
|
|
230
|
+
...result,
|
|
231
|
+
groupIndex: result.fromGroup,
|
|
232
|
+
contractId,
|
|
233
|
+
gasPrice: fromApiNumber256(result.gasPrice)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private convertExecuteScriptTxResult(
|
|
238
|
+
result: node.BuildExecuteScriptTxResult
|
|
239
|
+
): Omit<SignExecuteScriptTxResult, 'signature'> {
|
|
240
|
+
return {
|
|
241
|
+
...result,
|
|
242
|
+
groupIndex: result.fromGroup,
|
|
243
|
+
gasPrice: fromApiNumber256(result.gasPrice)
|
|
131
244
|
}
|
|
132
245
|
}
|
|
133
246
|
}
|
package/src/signer/types.ts
CHANGED
|
@@ -54,7 +54,7 @@ export interface SignTransferTxParams {
|
|
|
54
54
|
gasAmount?: number
|
|
55
55
|
gasPrice?: Number256
|
|
56
56
|
}
|
|
57
|
-
assertType<Eq<keyof SignTransferTxParams, keyof TxBuildParams<node.
|
|
57
|
+
assertType<Eq<keyof SignTransferTxParams, keyof TxBuildParams<node.BuildTransferTx>>>()
|
|
58
58
|
export interface SignTransferTxResult {
|
|
59
59
|
fromGroup: number
|
|
60
60
|
toGroup: number
|
|
@@ -64,7 +64,7 @@ export interface SignTransferTxResult {
|
|
|
64
64
|
gasAmount: number
|
|
65
65
|
gasPrice: Number256
|
|
66
66
|
}
|
|
67
|
-
assertType<Eq<SignTransferTxResult, SignResult<node.
|
|
67
|
+
assertType<Eq<SignTransferTxResult, SignResult<node.BuildTransferTxResult>>>()
|
|
68
68
|
|
|
69
69
|
export interface SignDeployContractTxParams {
|
|
70
70
|
signerAddress: string
|
|
@@ -138,6 +138,26 @@ export interface SignUnsignedTxResult {
|
|
|
138
138
|
}
|
|
139
139
|
assertType<Eq<SignUnsignedTxResult, SignTransferTxResult>>
|
|
140
140
|
|
|
141
|
+
export type SignTransferChainedTxParams = SignTransferTxParams & { type: 'Transfer' }
|
|
142
|
+
export type SignDeployContractChainedTxParams = SignDeployContractTxParams & {
|
|
143
|
+
type: 'DeployContract'
|
|
144
|
+
}
|
|
145
|
+
export type SignExecuteScriptChainedTxParams = SignExecuteScriptTxParams & { type: 'ExecuteScript' }
|
|
146
|
+
export type SignChainedTxParams =
|
|
147
|
+
| SignTransferChainedTxParams
|
|
148
|
+
| SignDeployContractChainedTxParams
|
|
149
|
+
| SignExecuteScriptChainedTxParams
|
|
150
|
+
|
|
151
|
+
export type SignTransferChainedTxResult = SignTransferTxResult & { type: 'Transfer' }
|
|
152
|
+
export type SignDeployContractChainedTxResult = SignDeployContractTxResult & {
|
|
153
|
+
type: 'DeployContract'
|
|
154
|
+
}
|
|
155
|
+
export type SignExecuteScriptChainedTxResult = SignExecuteScriptTxResult & { type: 'ExecuteScript' }
|
|
156
|
+
export type SignChainedTxResult =
|
|
157
|
+
| SignTransferChainedTxResult
|
|
158
|
+
| SignDeployContractChainedTxResult
|
|
159
|
+
| SignExecuteScriptChainedTxResult
|
|
160
|
+
|
|
141
161
|
export type MessageHasher =
|
|
142
162
|
| 'alephium' // Message is prefixed with 'Alephium signed message: ' before hashed with blake2b
|
|
143
163
|
| 'sha256'
|