@alephium/web3 0.41.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.d.ts +8 -95
- package/dist/src/contract/contract.js +31 -564
- 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/transaction/index.d.ts +1 -0
- package/dist/src/transaction/index.js +1 -0
- package/dist/src/transaction/utils.d.ts +2 -0
- package/dist/src/transaction/utils.js +34 -0
- 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 +18 -790
- 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/transaction/index.ts +1 -0
- package/src/transaction/utils.ts +38 -0
- 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 -6
- package/dist/src/utils/error.d.ts +0 -15
- package/dist/src/utils/error.js +0 -66
- package/src/utils/error.ts +0 -77
- /package/dist/src/{utils → address}/address.d.ts +0 -0
- /package/dist/src/{utils → exchange}/exchange.d.ts +0 -0
package/src/contract/ralph.ts
CHANGED
|
@@ -16,9 +16,8 @@ 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 { Val, decodeArrayType, toApiAddress, toApiBoolean, toApiByteVec, toApiNumber256 } from '../api'
|
|
21
|
-
import { HexString, binToHex, bs58, hexToBinUnsafe, isHexString } from '../utils'
|
|
20
|
+
import { HexString, binToHex, bs58, concatBytes, hexToBinUnsafe, isHexString } from '../utils'
|
|
22
21
|
import { Fields, FieldsSig, Struct } from './contract'
|
|
23
22
|
import { compactSignedIntCodec, compactUnsignedIntCodec } from '../codec'
|
|
24
23
|
|
|
@@ -151,14 +150,14 @@ export function encodeU256(u256: bigint): Uint8Array {
|
|
|
151
150
|
}
|
|
152
151
|
}
|
|
153
152
|
|
|
154
|
-
export function encodeByteVec(
|
|
155
|
-
if (!isHexString(
|
|
156
|
-
throw Error(`Given value ${
|
|
153
|
+
export function encodeByteVec(hex: string): Uint8Array {
|
|
154
|
+
if (!isHexString(hex)) {
|
|
155
|
+
throw Error(`Given value ${hex} is not a valid hex string`)
|
|
157
156
|
}
|
|
158
157
|
|
|
159
|
-
const
|
|
160
|
-
const
|
|
161
|
-
return
|
|
158
|
+
const bytes0 = hexToBinUnsafe(hex)
|
|
159
|
+
const bytes1 = encodeI256(BigInt(bytes0.length))
|
|
160
|
+
return concatBytes([bytes1, bytes0])
|
|
162
161
|
}
|
|
163
162
|
|
|
164
163
|
export function encodeAddress(address: string): Uint8Array {
|
|
@@ -254,7 +253,7 @@ function encodeScriptFieldU256(value: bigint): Uint8Array {
|
|
|
254
253
|
}
|
|
255
254
|
|
|
256
255
|
export function encodeScriptFieldAsString(tpe: string, value: Val): string {
|
|
257
|
-
return
|
|
256
|
+
return binToHex(encodeScriptField(tpe, value))
|
|
258
257
|
}
|
|
259
258
|
|
|
260
259
|
export function encodeScriptField(tpe: string, value: Val): Uint8Array {
|
|
@@ -378,9 +377,9 @@ export function decodePrimitive(value: Uint8Array, type: string): Val {
|
|
|
378
377
|
case 'Bool':
|
|
379
378
|
return decodeBool(value)
|
|
380
379
|
case 'I256':
|
|
381
|
-
return compactSignedIntCodec.decodeI256(
|
|
380
|
+
return compactSignedIntCodec.decodeI256(value)
|
|
382
381
|
case 'U256':
|
|
383
|
-
return compactUnsignedIntCodec.decodeU256(
|
|
382
|
+
return compactUnsignedIntCodec.decodeU256(value)
|
|
384
383
|
case 'ByteVec':
|
|
385
384
|
return binToHex(value)
|
|
386
385
|
case 'Address':
|
|
@@ -16,19 +16,11 @@ 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 {
|
|
20
|
-
|
|
21
|
-
addressFromPublicKey,
|
|
22
|
-
addressFromScript,
|
|
23
|
-
binToHex,
|
|
24
|
-
bs58,
|
|
25
|
-
hexToBinUnsafe,
|
|
26
|
-
isHexString
|
|
27
|
-
} from '../utils'
|
|
19
|
+
import { AddressType, addressFromPublicKey, addressFromScript } from '../address'
|
|
20
|
+
import { binToHex, bs58, hexToBinUnsafe, isHexString } from '../utils'
|
|
28
21
|
import { Transaction } from '../api/api-alephium'
|
|
29
22
|
import { Address } from '../signer'
|
|
30
23
|
import { P2SH, unlockScriptCodec } from '../codec/unlock-script-codec'
|
|
31
|
-
import { Buffer } from 'buffer/'
|
|
32
24
|
import { scriptCodec } from '../codec/script-codec'
|
|
33
25
|
|
|
34
26
|
export function validateExchangeAddress(address: string) {
|
|
@@ -113,7 +105,7 @@ export function getAddressFromUnlockScript(unlockScript: string): Address {
|
|
|
113
105
|
if (unlockScriptType === UnlockScriptType.P2SH) {
|
|
114
106
|
let p2sh: P2SH
|
|
115
107
|
try {
|
|
116
|
-
p2sh = unlockScriptCodec.decode(
|
|
108
|
+
p2sh = unlockScriptCodec.decode(decoded).script as P2SH
|
|
117
109
|
} catch (_) {
|
|
118
110
|
throw new Error(`Invalid p2sh unlock script: ${unlockScript}`)
|
|
119
111
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
+
This file is part of the alephium project.
|
|
4
|
+
|
|
5
|
+
The library is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
The library is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Lesser General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export { validateExchangeAddress, isALPHTransferTx, getSenderAddress, getALPHDepositInfo } from './exchange'
|
package/src/index.ts
CHANGED
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/transaction/index.ts
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
+
This file is part of the alephium project.
|
|
4
|
+
|
|
5
|
+
The library is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
The library is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Lesser General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { node } from '../api'
|
|
20
|
+
import { getCurrentNodeProvider } from '../global'
|
|
21
|
+
|
|
22
|
+
function isConfirmed(txStatus: node.TxStatus): txStatus is node.Confirmed {
|
|
23
|
+
return txStatus.type === 'Confirmed'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function waitForTxConfirmation(
|
|
27
|
+
txId: string,
|
|
28
|
+
confirmations: number,
|
|
29
|
+
requestInterval: number
|
|
30
|
+
): Promise<node.Confirmed> {
|
|
31
|
+
const provider = getCurrentNodeProvider()
|
|
32
|
+
const status = await provider.transactions.getTransactionsStatus({ txId: txId })
|
|
33
|
+
if (isConfirmed(status) && status.chainConfirmations >= confirmations) {
|
|
34
|
+
return status
|
|
35
|
+
}
|
|
36
|
+
await new Promise((r) => setTimeout(r, requestInterval))
|
|
37
|
+
return waitForTxConfirmation(txId, confirmations, requestInterval)
|
|
38
|
+
}
|
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,9 +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
|
-
path: require.resolve('path-browserify'),
|
|
45
|
-
buffer: require.resolve('buffer/')
|
|
40
|
+
crypto: require.resolve('crypto-browserify')
|
|
46
41
|
}
|
|
47
42
|
},
|
|
48
43
|
output: {
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare class CompilationError {
|
|
2
|
-
lineStart: number;
|
|
3
|
-
column: number;
|
|
4
|
-
errorType: string;
|
|
5
|
-
line: number;
|
|
6
|
-
codeLine: string;
|
|
7
|
-
errorIndicator: string;
|
|
8
|
-
message: string;
|
|
9
|
-
additionalLine1?: string | undefined;
|
|
10
|
-
additionalLine2?: string | undefined;
|
|
11
|
-
constructor(lineStart: number, column: number, errorType: string, line: number, codeLine: string, errorIndicator: string, message: string, additionalLine1?: string | undefined, additionalLine2?: string | undefined);
|
|
12
|
-
reformat(line: number, file: string): string;
|
|
13
|
-
}
|
|
14
|
-
export declare function parseError(error: string): CompilationError | undefined;
|
|
15
|
-
export {};
|
package/dist/src/utils/error.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
4
|
-
This file is part of the alephium project.
|
|
5
|
-
|
|
6
|
-
The library is free software: you can redistribute it and/or modify
|
|
7
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
8
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
(at your option) any later version.
|
|
10
|
-
|
|
11
|
-
The library is distributed in the hope that it will be useful,
|
|
12
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
GNU Lesser General Public License for more details.
|
|
15
|
-
|
|
16
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
17
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*/
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.parseError = void 0;
|
|
21
|
-
class CompilationError {
|
|
22
|
-
constructor(lineStart, column, errorType, line, codeLine, errorIndicator, message, additionalLine1, additionalLine2) {
|
|
23
|
-
this.lineStart = lineStart;
|
|
24
|
-
this.column = column;
|
|
25
|
-
this.errorType = errorType;
|
|
26
|
-
this.line = line;
|
|
27
|
-
this.codeLine = codeLine;
|
|
28
|
-
this.errorIndicator = errorIndicator;
|
|
29
|
-
this.message = message;
|
|
30
|
-
this.additionalLine1 = additionalLine1;
|
|
31
|
-
this.additionalLine2 = additionalLine2;
|
|
32
|
-
}
|
|
33
|
-
reformat(line, file) {
|
|
34
|
-
const spaces = `${line}`.replace(/\d/g, ' ');
|
|
35
|
-
const newError = `${file} (${line}:${this.column}): ${this.errorType}
|
|
36
|
-
${line} |${this.codeLine}
|
|
37
|
-
${spaces} |${this.errorIndicator}
|
|
38
|
-
${spaces} |${this.message}`;
|
|
39
|
-
if (this.additionalLine1 && this.additionalLine2) {
|
|
40
|
-
return `${newError}\n${spaces} |${this.additionalLine1}\n${spaces} |${this.additionalLine2}`;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
return newError;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const errorRegex = /error \((\d+):(\d+)\):\s*(.*)\n\s*(\d+)\s*\|(.*)\n.*\|(.*)\n\s*\|(.*)(?:\n\s*\|(.*)\n\s*\|(.*))?/;
|
|
48
|
-
function parseError(error) {
|
|
49
|
-
const match = error.match(errorRegex);
|
|
50
|
-
if (match) {
|
|
51
|
-
const lineStart = parseInt(match[1]);
|
|
52
|
-
const column = parseInt(match[2]);
|
|
53
|
-
const errorType = match[3];
|
|
54
|
-
const line = parseInt(match[4]);
|
|
55
|
-
const codeLine = match[5];
|
|
56
|
-
const errorIndicator = match[6];
|
|
57
|
-
const message = match[7];
|
|
58
|
-
const additionalLine1 = match[8];
|
|
59
|
-
const additionalLine2 = match[9];
|
|
60
|
-
return new CompilationError(lineStart, column, errorType, line, codeLine, errorIndicator, message, additionalLine1, additionalLine2);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
undefined;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.parseError = parseError;
|
package/src/utils/error.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
3
|
-
This file is part of the alephium project.
|
|
4
|
-
|
|
5
|
-
The library is free software: you can redistribute it and/or modify
|
|
6
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
7
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
(at your option) any later version.
|
|
9
|
-
|
|
10
|
-
The library is distributed in the hope that it will be useful,
|
|
11
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
GNU Lesser General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
16
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
class CompilationError {
|
|
20
|
-
constructor(
|
|
21
|
-
public lineStart: number,
|
|
22
|
-
public column: number,
|
|
23
|
-
public errorType: string,
|
|
24
|
-
public line: number,
|
|
25
|
-
public codeLine: string,
|
|
26
|
-
public errorIndicator: string,
|
|
27
|
-
public message: string,
|
|
28
|
-
public additionalLine1?: string,
|
|
29
|
-
public additionalLine2?: string
|
|
30
|
-
) {}
|
|
31
|
-
|
|
32
|
-
reformat(line: number, file: string): string {
|
|
33
|
-
const spaces = `${line}`.replace(/\d/g, ' ')
|
|
34
|
-
const newError = `${file} (${line}:${this.column}): ${this.errorType}
|
|
35
|
-
${line} |${this.codeLine}
|
|
36
|
-
${spaces} |${this.errorIndicator}
|
|
37
|
-
${spaces} |${this.message}`
|
|
38
|
-
|
|
39
|
-
if (this.additionalLine1 && this.additionalLine2) {
|
|
40
|
-
return `${newError}\n${spaces} |${this.additionalLine1}\n${spaces} |${this.additionalLine2}`
|
|
41
|
-
} else {
|
|
42
|
-
return newError
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const errorRegex = /error \((\d+):(\d+)\):\s*(.*)\n\s*(\d+)\s*\|(.*)\n.*\|(.*)\n\s*\|(.*)(?:\n\s*\|(.*)\n\s*\|(.*))?/
|
|
48
|
-
|
|
49
|
-
export function parseError(error: string): CompilationError | undefined {
|
|
50
|
-
const match = error.match(errorRegex)
|
|
51
|
-
|
|
52
|
-
if (match) {
|
|
53
|
-
const lineStart = parseInt(match[1])
|
|
54
|
-
const column = parseInt(match[2])
|
|
55
|
-
const errorType = match[3]
|
|
56
|
-
const line = parseInt(match[4])
|
|
57
|
-
const codeLine = match[5]
|
|
58
|
-
const errorIndicator = match[6]
|
|
59
|
-
const message = match[7]
|
|
60
|
-
const additionalLine1 = match[8]
|
|
61
|
-
const additionalLine2 = match[9]
|
|
62
|
-
|
|
63
|
-
return new CompilationError(
|
|
64
|
-
lineStart,
|
|
65
|
-
column,
|
|
66
|
-
errorType,
|
|
67
|
-
line,
|
|
68
|
-
codeLine,
|
|
69
|
-
errorIndicator,
|
|
70
|
-
message,
|
|
71
|
-
additionalLine1,
|
|
72
|
-
additionalLine2
|
|
73
|
-
)
|
|
74
|
-
} else {
|
|
75
|
-
undefined
|
|
76
|
-
}
|
|
77
|
-
}
|
|
File without changes
|
|
File without changes
|