@alephium/web3 0.42.0 → 0.43.0
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/{utils → address}/address.js +15 -19
- package/dist/src/address/index.d.ts +1 -0
- package/dist/src/address/index.js +34 -0
- package/dist/src/api/node-provider.js +10 -9
- package/dist/src/api/types.js +1 -1
- package/dist/src/codec/array-codec.d.ts +2 -3
- package/dist/src/codec/array-codec.js +1 -2
- package/dist/src/codec/asset-output-codec.d.ts +3 -4
- package/dist/src/codec/asset-output-codec.js +10 -12
- package/dist/src/codec/bigint-codec.d.ts +2 -3
- package/dist/src/codec/bigint-codec.js +2 -3
- package/dist/src/codec/bytestring-codec.d.ts +5 -6
- package/dist/src/codec/bytestring-codec.js +5 -5
- package/dist/src/codec/codec.d.ts +2 -3
- package/dist/src/codec/compact-int-codec.d.ts +12 -13
- package/dist/src/codec/compact-int-codec.js +22 -22
- package/dist/src/codec/contract-codec.d.ts +5 -6
- package/dist/src/codec/contract-codec.js +24 -24
- package/dist/src/codec/contract-output-codec.d.ts +2 -3
- package/dist/src/codec/contract-output-codec.js +8 -10
- package/dist/src/codec/contract-output-ref-codec.d.ts +3 -4
- package/dist/src/codec/contract-output-ref-codec.js +2 -2
- package/dist/src/codec/either-codec.d.ts +2 -3
- package/dist/src/codec/either-codec.js +1 -2
- package/dist/src/codec/hash.d.ts +2 -3
- package/dist/src/codec/hash.js +17 -0
- package/dist/src/codec/input-codec.d.ts +3 -4
- package/dist/src/codec/input-codec.js +6 -6
- package/dist/src/codec/instr-codec.d.ts +2 -3
- package/dist/src/codec/instr-codec.js +1 -2
- package/dist/src/codec/lockup-script-codec.d.ts +5 -6
- package/dist/src/codec/lockup-script-codec.js +1 -2
- package/dist/src/codec/long-codec.d.ts +2 -3
- package/dist/src/codec/long-codec.js +1 -2
- package/dist/src/codec/method-codec.d.ts +2 -3
- package/dist/src/codec/method-codec.js +1 -2
- package/dist/src/codec/option-codec.d.ts +3 -4
- package/dist/src/codec/option-codec.js +2 -3
- package/dist/src/codec/script-codec.d.ts +4 -5
- package/dist/src/codec/script-codec.js +1 -3
- package/dist/src/codec/signature-codec.d.ts +3 -4
- package/dist/src/codec/signature-codec.js +17 -0
- package/dist/src/codec/signed-int-codec.d.ts +2 -3
- package/dist/src/codec/signed-int-codec.js +1 -2
- package/dist/src/codec/token-codec.d.ts +3 -4
- package/dist/src/codec/token-codec.js +3 -3
- package/dist/src/codec/transaction-codec.d.ts +4 -5
- package/dist/src/codec/transaction-codec.js +12 -13
- package/dist/src/codec/unlock-script-codec.d.ts +5 -6
- package/dist/src/codec/unlock-script-codec.js +14 -15
- package/dist/src/codec/unsigned-tx-codec.d.ts +4 -5
- package/dist/src/codec/unsigned-tx-codec.js +4 -5
- package/dist/src/contract/contract.js +20 -20
- package/dist/src/contract/ralph.d.ts +1 -1
- package/dist/src/contract/ralph.js +9 -10
- package/dist/src/{utils → exchange}/exchange.js +5 -5
- package/dist/src/exchange/index.d.ts +1 -0
- package/dist/src/exchange/index.js +25 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/signer/signer.js +4 -5
- package/dist/src/signer/tx-builder.js +3 -3
- package/dist/src/utils/index.d.ts +0 -2
- package/dist/src/utils/index.js +0 -7
- package/dist/src/utils/sign.js +1 -1
- package/dist/src/utils/utils.d.ts +1 -0
- package/dist/src/utils/utils.js +30 -11
- package/dist/src/utils/webcrypto.js +3 -4
- package/package.json +1 -2
- package/src/{utils → address}/address.ts +15 -19
- package/src/address/index.ts +19 -0
- package/src/api/node-provider.ts +2 -9
- package/src/api/types.ts +2 -2
- package/src/codec/array-codec.ts +3 -4
- package/src/codec/asset-output-codec.ts +16 -18
- package/src/codec/bigint-codec.ts +4 -5
- package/src/codec/bytestring-codec.ts +8 -8
- package/src/codec/codec.ts +2 -3
- package/src/codec/compact-int-codec.ts +36 -37
- package/src/codec/contract-codec.ts +28 -27
- package/src/codec/contract-output-codec.ts +11 -13
- package/src/codec/contract-output-ref-codec.ts +5 -5
- package/src/codec/either-codec.ts +3 -4
- package/src/codec/hash.ts +2 -3
- package/src/codec/input-codec.ts +10 -10
- package/src/codec/instr-codec.ts +3 -4
- package/src/codec/lockup-script-codec.ts +8 -9
- package/src/codec/long-codec.ts +3 -4
- package/src/codec/method-codec.ts +3 -4
- package/src/codec/option-codec.ts +4 -5
- package/src/codec/script-codec.ts +5 -7
- package/src/codec/signature-codec.ts +3 -4
- package/src/codec/signed-int-codec.ts +3 -4
- package/src/codec/token-codec.ts +6 -6
- package/src/codec/transaction-codec.ts +17 -18
- package/src/codec/unlock-script-codec.ts +26 -27
- package/src/codec/unsigned-tx-codec.ts +10 -11
- package/src/contract/contract.ts +3 -7
- package/src/contract/ralph.ts +10 -11
- package/src/{utils → exchange}/exchange.ts +3 -11
- package/src/exchange/index.ts +19 -0
- package/src/index.ts +2 -0
- package/src/signer/signer.ts +2 -3
- package/src/signer/tx-builder.ts +2 -2
- package/src/utils/index.ts +0 -2
- package/src/utils/sign.ts +1 -1
- package/src/utils/utils.ts +29 -10
- package/src/utils/webcrypto.ts +3 -4
- package/webpack.config.js +1 -5
- /package/dist/src/{utils → address}/address.d.ts +0 -0
- /package/dist/src/{utils → exchange}/exchange.d.ts +0 -0
package/src/signer/signer.ts
CHANGED
|
@@ -16,7 +16,6 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
16
16
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { Buffer } from 'buffer/'
|
|
20
19
|
import { createHash } from 'crypto'
|
|
21
20
|
import { ExplorerProvider, fromApiNumber256, fromApiTokens, NodeProvider, toApiNumber256, toApiTokens } from '../api'
|
|
22
21
|
import { node } from '../api'
|
|
@@ -44,7 +43,7 @@ import {
|
|
|
44
43
|
MessageHasher
|
|
45
44
|
} from './types'
|
|
46
45
|
import { TransactionBuilder } from './tx-builder'
|
|
47
|
-
import { addressFromPublicKey, groupOfAddress } from '../
|
|
46
|
+
import { addressFromPublicKey, groupOfAddress } from '../address'
|
|
48
47
|
|
|
49
48
|
export abstract class SignerProvider {
|
|
50
49
|
abstract get nodeProvider(): NodeProvider | undefined
|
|
@@ -254,7 +253,7 @@ export function hashMessage(message: string, hasher: MessageHasher): string {
|
|
|
254
253
|
return utils.binToHex(blake.blake2b(extendMessage(message), undefined, 32))
|
|
255
254
|
case 'sha256':
|
|
256
255
|
const sha256 = createHash('sha256')
|
|
257
|
-
sha256.update(
|
|
256
|
+
sha256.update(new TextEncoder().encode(message))
|
|
258
257
|
return utils.binToHex(sha256.digest())
|
|
259
258
|
case 'blake2b':
|
|
260
259
|
return utils.binToHex(blake.blake2b(message, undefined, 32))
|
package/src/signer/tx-builder.ts
CHANGED
|
@@ -16,9 +16,9 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
16
16
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { binToHex
|
|
19
|
+
import { binToHex } from '../utils'
|
|
20
20
|
import { fromApiNumber256, node, NodeProvider, toApiNumber256Optional, toApiTokens } from '../api'
|
|
21
|
-
import { addressFromPublicKey } from '../
|
|
21
|
+
import { addressFromPublicKey, contractIdFromAddress } from '../address'
|
|
22
22
|
import { toApiDestinations } from './signer'
|
|
23
23
|
import {
|
|
24
24
|
KeyType,
|
package/src/utils/index.ts
CHANGED
|
@@ -17,11 +17,9 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
export * from './webcrypto'
|
|
20
|
-
export * from './address'
|
|
21
20
|
export * from './bs58'
|
|
22
21
|
export * from './djb2'
|
|
23
22
|
export * from './utils'
|
|
24
23
|
export * from './subscription'
|
|
25
24
|
export * from './sign'
|
|
26
25
|
export * from './number'
|
|
27
|
-
export { validateExchangeAddress, isALPHTransferTx, getSenderAddress, getALPHDepositInfo } from './exchange'
|
package/src/utils/sign.ts
CHANGED
|
@@ -31,7 +31,7 @@ necc.utils.sha256Sync = (...messages: Uint8Array[]): Uint8Array => {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
necc.utils.hmacSha256Sync = (key: Uint8Array, ...messages: Uint8Array[]): Uint8Array => {
|
|
34
|
-
const hash = createHmac('sha256',
|
|
34
|
+
const hash = createHmac('sha256', key)
|
|
35
35
|
messages.forEach((m) => hash.update(m))
|
|
36
36
|
return Uint8Array.from(hash.digest())
|
|
37
37
|
}
|
package/src/utils/utils.ts
CHANGED
|
@@ -18,8 +18,6 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
|
|
19
19
|
import { ec as EC, SignatureInput } from 'elliptic'
|
|
20
20
|
import BN from 'bn.js'
|
|
21
|
-
import { Buffer } from 'buffer/'
|
|
22
|
-
|
|
23
21
|
import { TOTAL_NUMBER_OF_GROUPS, TOTAL_NUMBER_OF_CHAINS } from '../constants'
|
|
24
22
|
|
|
25
23
|
export const networkIds = ['mainnet', 'testnet', 'devnet'] as const
|
|
@@ -73,11 +71,17 @@ export function toNonNegativeBigInt(input: string): bigint | undefined {
|
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
export function hexToBinUnsafe(hex: string): Uint8Array {
|
|
76
|
-
|
|
74
|
+
const bytes: number[] = []
|
|
75
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
76
|
+
bytes.push(parseInt(hex.slice(i, i + 2), 16))
|
|
77
|
+
}
|
|
78
|
+
return new Uint8Array(bytes)
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
export function binToHex(bin: Uint8Array): string {
|
|
80
|
-
return
|
|
82
|
+
return Array.from(bin)
|
|
83
|
+
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
84
|
+
.join('')
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
export function blockChainIndex(blockHash: HexString): { fromGroup: number; toGroup: number } {
|
|
@@ -101,7 +105,8 @@ export function hexToString(str: string): string {
|
|
|
101
105
|
if (!isHexString(str)) {
|
|
102
106
|
throw new Error(`Invalid hex string: ${str}`)
|
|
103
107
|
}
|
|
104
|
-
|
|
108
|
+
const bytes = hexToBinUnsafe(str)
|
|
109
|
+
return new TextDecoder().decode(bytes)
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
export function sleep(ms: number): Promise<void> {
|
|
@@ -127,14 +132,28 @@ export function difficultyToTarget(diff: bigint): HexString {
|
|
|
127
132
|
const maxBigInt = 1n << 256n
|
|
128
133
|
const target = diff === 1n ? maxBigInt - 1n : maxBigInt / diff
|
|
129
134
|
const size = Math.floor((target.toString(2).length + 7) / 8)
|
|
130
|
-
const mantissa =
|
|
135
|
+
const mantissa = Number(
|
|
131
136
|
size <= 3
|
|
132
137
|
? BigInt.asIntN(32, target) << BigInt(8 * (3 - size))
|
|
133
138
|
: BigInt.asIntN(32, target >> BigInt(8 * (size - 3)))
|
|
134
|
-
|
|
135
|
-
mantissaBytes
|
|
136
|
-
|
|
137
|
-
|
|
139
|
+
)
|
|
140
|
+
const mantissaBytes = new Uint8Array(4)
|
|
141
|
+
mantissaBytes[0] = size
|
|
142
|
+
mantissaBytes[1] = (mantissa >> 16) & 0xff
|
|
143
|
+
mantissaBytes[2] = (mantissa >> 8) & 0xff
|
|
144
|
+
mantissaBytes[3] = mantissa & 0xff
|
|
145
|
+
return binToHex(mantissaBytes)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function concatBytes(arrays: Uint8Array[]): Uint8Array {
|
|
149
|
+
const totalLength = arrays.reduce((acc, arr) => acc + arr.length, 0)
|
|
150
|
+
const result = new Uint8Array(totalLength)
|
|
151
|
+
let offset = 0
|
|
152
|
+
for (const array of arrays) {
|
|
153
|
+
result.set(array, offset)
|
|
154
|
+
offset += array.length
|
|
155
|
+
}
|
|
156
|
+
return result
|
|
138
157
|
}
|
|
139
158
|
|
|
140
159
|
type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false
|
package/src/utils/webcrypto.ts
CHANGED
|
@@ -16,7 +16,6 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
16
16
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { Buffer } from 'buffer/'
|
|
20
19
|
import { webcrypto, randomFillSync } from 'crypto'
|
|
21
20
|
|
|
22
21
|
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'
|
|
@@ -30,12 +29,12 @@ export class WebCrypto {
|
|
|
30
29
|
"Failed to execute 'getRandomValues' on 'Crypto': parameter 1 is not of type 'ArrayBufferView'"
|
|
31
30
|
)
|
|
32
31
|
}
|
|
33
|
-
const
|
|
32
|
+
const bytes = new Uint8Array(array.buffer, array.byteOffset, array.byteLength)
|
|
34
33
|
|
|
35
34
|
if (isBrowser) {
|
|
36
|
-
globalThis.crypto.getRandomValues(
|
|
35
|
+
globalThis.crypto.getRandomValues(bytes)
|
|
37
36
|
} else {
|
|
38
|
-
randomFillSync(
|
|
37
|
+
randomFillSync(bytes)
|
|
39
38
|
}
|
|
40
39
|
return array
|
|
41
40
|
}
|
package/webpack.config.js
CHANGED
|
@@ -25,9 +25,6 @@ module.exports = {
|
|
|
25
25
|
},
|
|
26
26
|
plugins: [
|
|
27
27
|
new webpack.SourceMapDevToolPlugin({ filename: '[file].map' }),
|
|
28
|
-
new webpack.ProvidePlugin({
|
|
29
|
-
Buffer: ['buffer', 'Buffer']
|
|
30
|
-
}),
|
|
31
28
|
new webpack.IgnorePlugin({
|
|
32
29
|
checkResource(resource) {
|
|
33
30
|
// The "bip39/src/wordlists" node module consists of json files for multiple languages. We only need English.
|
|
@@ -40,8 +37,7 @@ module.exports = {
|
|
|
40
37
|
fallback: {
|
|
41
38
|
fs: false,
|
|
42
39
|
stream: require.resolve('stream-browserify'),
|
|
43
|
-
crypto: require.resolve('crypto-browserify')
|
|
44
|
-
buffer: require.resolve('buffer/')
|
|
40
|
+
crypto: require.resolve('crypto-browserify')
|
|
45
41
|
}
|
|
46
42
|
},
|
|
47
43
|
output: {
|
|
File without changes
|
|
File without changes
|