@alephium/web3 1.12.0-beta.0 → 1.12.0-danube.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/address/address.d.ts +1 -0
- package/dist/src/address/address.js +45 -22
- package/dist/src/api/api-alephium.d.ts +78 -124
- package/dist/src/api/api-alephium.js +0 -50
- package/dist/src/api/node-provider.d.ts +0 -2
- package/dist/src/api/node-provider.js +0 -1
- package/dist/src/codec/instr-codec.d.ts +26 -10
- package/dist/src/codec/instr-codec.js +38 -18
- package/dist/src/contract/contract.d.ts +11 -6
- package/dist/src/contract/contract.js +35 -21
- package/dist/src/contract/deployment.d.ts +2 -0
- package/dist/src/signer/signer.d.ts +13 -13
- package/dist/src/signer/signer.js +84 -9
- package/dist/src/signer/tx-builder.d.ts +4 -10
- package/dist/src/signer/tx-builder.js +41 -67
- package/dist/src/signer/types.d.ts +14 -27
- package/dist/src/signer/types.js +0 -3
- package/dist/src/utils/sign.js +2 -2
- package/package.json +1 -1
- package/src/address/address.ts +50 -19
- package/src/api/api-alephium.ts +92 -172
- package/src/api/node-provider.ts +0 -3
- package/src/codec/instr-codec.ts +45 -21
- package/src/contract/contract.ts +45 -29
- package/src/contract/deployment.ts +2 -0
- package/src/signer/signer.ts +118 -24
- package/src/signer/tx-builder.ts +60 -99
- package/src/signer/types.ts +31 -39
- package/src/utils/sign.ts +2 -2
package/src/signer/types.ts
CHANGED
|
@@ -34,18 +34,18 @@ export interface Destination {
|
|
|
34
34
|
}
|
|
35
35
|
assertType<Eq<keyof Destination, keyof node.Destination>>
|
|
36
36
|
|
|
37
|
-
export type KeyType = 'default' | 'bip340-schnorr' | '
|
|
37
|
+
export type KeyType = 'default' | 'bip340-schnorr' | 'gl-secp256k1' | 'gl-secp256r1' | 'gl-ed25519' | 'gl-webauthn'
|
|
38
38
|
|
|
39
39
|
export interface Account {
|
|
40
40
|
keyType: KeyType
|
|
41
41
|
address: string
|
|
42
|
-
group: number
|
|
42
|
+
group: number // TODO: optional for groupless address
|
|
43
43
|
publicKey: string
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export type SignerAddress = { signerAddress: string; signerKeyType?: KeyType }
|
|
47
47
|
type TxBuildParams<T> = Omit<T, 'fromPublicKey' | 'fromPublicKeyType' | 'targetBlockHash'> & SignerAddress
|
|
48
|
-
type SignResult<T> = Omit<T, 'gasPrice'> & { signature: string; gasPrice: Number256 }
|
|
48
|
+
type SignResult<T> = Omit<T, 'gasPrice' | 'type'> & { signature: string; gasPrice: Number256 }
|
|
49
49
|
|
|
50
50
|
export interface SignTransferTxParams {
|
|
51
51
|
signerAddress: string
|
|
@@ -54,6 +54,7 @@ export interface SignTransferTxParams {
|
|
|
54
54
|
utxos?: OutputRef[]
|
|
55
55
|
gasAmount?: number
|
|
56
56
|
gasPrice?: Number256
|
|
57
|
+
group?: number
|
|
57
58
|
}
|
|
58
59
|
assertType<Eq<keyof SignTransferTxParams, keyof TxBuildParams<node.BuildTransferTx>>>()
|
|
59
60
|
export interface SignTransferTxResult {
|
|
@@ -65,7 +66,7 @@ export interface SignTransferTxResult {
|
|
|
65
66
|
gasAmount: number
|
|
66
67
|
gasPrice: Number256
|
|
67
68
|
}
|
|
68
|
-
assertType<Eq<SignTransferTxResult, SignResult<node.
|
|
69
|
+
assertType<Eq<SignTransferTxResult, SignResult<node.BuildSimpleTransferTxResult>>>()
|
|
69
70
|
|
|
70
71
|
export interface SignDeployContractTxParams {
|
|
71
72
|
signerAddress: string
|
|
@@ -77,6 +78,7 @@ export interface SignDeployContractTxParams {
|
|
|
77
78
|
issueTokenTo?: string
|
|
78
79
|
gasAmount?: number
|
|
79
80
|
gasPrice?: Number256
|
|
81
|
+
group?: number
|
|
80
82
|
}
|
|
81
83
|
assertType<Eq<keyof SignDeployContractTxParams, keyof TxBuildParams<node.BuildDeployContractTx>>>()
|
|
82
84
|
export interface SignDeployContractTxResult {
|
|
@@ -92,7 +94,7 @@ export interface SignDeployContractTxResult {
|
|
|
92
94
|
assertType<
|
|
93
95
|
Eq<
|
|
94
96
|
Omit<SignDeployContractTxResult, 'groupIndex'>,
|
|
95
|
-
Omit<SignResult<node.
|
|
97
|
+
Omit<SignResult<node.BuildSimpleDeployContractTxResult> & { contractId: string }, 'fromGroup' | 'toGroup'>
|
|
96
98
|
>
|
|
97
99
|
>()
|
|
98
100
|
|
|
@@ -105,6 +107,7 @@ export interface SignExecuteScriptTxParams {
|
|
|
105
107
|
gasAmount?: number
|
|
106
108
|
gasPrice?: Number256
|
|
107
109
|
gasEstimationMultiplier?: number
|
|
110
|
+
group?: number
|
|
108
111
|
}
|
|
109
112
|
assertType<Eq<keyof SignExecuteScriptTxParams, keyof TxBuildParams<node.BuildExecuteScriptTx>>>()
|
|
110
113
|
export interface SignExecuteScriptTxResult {
|
|
@@ -119,10 +122,32 @@ export interface SignExecuteScriptTxResult {
|
|
|
119
122
|
assertType<
|
|
120
123
|
Eq<
|
|
121
124
|
Omit<SignExecuteScriptTxResult, 'groupIndex'>,
|
|
122
|
-
Omit<SignResult<node.
|
|
125
|
+
Omit<SignResult<node.BuildSimpleExecuteScriptTxResult>, 'fromGroup' | 'toGroup'>
|
|
123
126
|
>
|
|
124
127
|
>()
|
|
125
128
|
|
|
129
|
+
export interface GrouplessBuildTxResult<
|
|
130
|
+
T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult
|
|
131
|
+
> {
|
|
132
|
+
transferTxs: Omit<SignTransferTxResult, 'signature'>[]
|
|
133
|
+
tx: Omit<T, 'signature'>
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export type BuildTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> =
|
|
137
|
+
| GrouplessBuildTxResult<T>
|
|
138
|
+
| Omit<T, 'signature'>
|
|
139
|
+
|
|
140
|
+
export interface GrouplessSignTxResult<
|
|
141
|
+
T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult
|
|
142
|
+
> {
|
|
143
|
+
transferTxs: SignTransferTxResult[]
|
|
144
|
+
tx: T
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export type SignTxResult<T extends SignExecuteScriptTxResult | SignDeployContractTxResult | SignTransferTxResult> =
|
|
148
|
+
| GrouplessSignTxResult<T>
|
|
149
|
+
| T
|
|
150
|
+
|
|
126
151
|
export interface SignUnsignedTxParams {
|
|
127
152
|
signerAddress: string
|
|
128
153
|
signerKeyType?: KeyType
|
|
@@ -160,39 +185,6 @@ export type SignChainedTxResult =
|
|
|
160
185
|
| SignDeployContractChainedTxResult
|
|
161
186
|
| SignExecuteScriptChainedTxResult
|
|
162
187
|
|
|
163
|
-
export interface SignGrouplessTransferTxParams {
|
|
164
|
-
fromAddress: string
|
|
165
|
-
destinations: Destination[]
|
|
166
|
-
gasPrice?: Number256
|
|
167
|
-
targetBlockHash?: string
|
|
168
|
-
}
|
|
169
|
-
assertType<Eq<keyof SignGrouplessTransferTxParams, keyof node.BuildGrouplessTransferTx>>()
|
|
170
|
-
export interface SignGrouplessDeployContractTxParams {
|
|
171
|
-
fromAddress: string
|
|
172
|
-
bytecode: string
|
|
173
|
-
initialAttoAlphAmount?: Number256
|
|
174
|
-
initialTokenAmounts?: Token[]
|
|
175
|
-
issueTokenAmount?: Number256
|
|
176
|
-
issueTokenTo?: string
|
|
177
|
-
gasPrice?: Number256
|
|
178
|
-
targetBlockHash?: string
|
|
179
|
-
}
|
|
180
|
-
assertType<Eq<keyof SignGrouplessDeployContractTxParams, keyof node.BuildGrouplessDeployContractTx>>()
|
|
181
|
-
export interface SignGrouplessExecuteScriptTxParams {
|
|
182
|
-
fromAddress: string
|
|
183
|
-
bytecode: string
|
|
184
|
-
attoAlphAmount?: Number256
|
|
185
|
-
tokens?: Token[]
|
|
186
|
-
gasPrice?: Number256
|
|
187
|
-
targetBlockHash?: string
|
|
188
|
-
gasEstimationMultiplier?: number
|
|
189
|
-
}
|
|
190
|
-
assertType<Eq<keyof SignGrouplessExecuteScriptTxParams, keyof node.BuildGrouplessExecuteScriptTx>>()
|
|
191
|
-
export type SignGrouplessTxParams =
|
|
192
|
-
| SignGrouplessTransferTxParams
|
|
193
|
-
| SignGrouplessDeployContractTxParams
|
|
194
|
-
| SignGrouplessExecuteScriptTxParams
|
|
195
|
-
|
|
196
188
|
export type MessageHasher =
|
|
197
189
|
| 'alephium' // Message is prefixed with 'Alephium signed message: ' before hashed with blake2b
|
|
198
190
|
| 'sha256'
|
package/src/utils/sign.ts
CHANGED
|
@@ -40,7 +40,7 @@ necc.utils.hmacSha256Sync = (key: Uint8Array, ...messages: Uint8Array[]): Uint8A
|
|
|
40
40
|
export function sign(hash: string, privateKey: string, _keyType?: KeyType): string {
|
|
41
41
|
const keyType = _keyType ?? 'default'
|
|
42
42
|
|
|
43
|
-
if (keyType === 'default' || keyType === '
|
|
43
|
+
if (keyType === 'default' || keyType === 'gl-secp256k1') {
|
|
44
44
|
const key = ec.keyFromPrivate(privateKey)
|
|
45
45
|
const signature = key.sign(hash)
|
|
46
46
|
return encodeSignature(signature)
|
|
@@ -54,7 +54,7 @@ export function verifySignature(hash: string, publicKey: string, signature: stri
|
|
|
54
54
|
const keyType = _keyType ?? 'default'
|
|
55
55
|
|
|
56
56
|
try {
|
|
57
|
-
if (keyType === 'default' || keyType === '
|
|
57
|
+
if (keyType === 'default' || keyType === 'gl-secp256k1') {
|
|
58
58
|
const key = ec.keyFromPublic(publicKey, 'hex')
|
|
59
59
|
return key.verify(hash, signatureDecode(ec, signature))
|
|
60
60
|
} else {
|