@alephium/web3 0.39.3 → 0.41.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/api/api-alephium.d.ts +1 -1
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/api/node-provider.d.ts +2 -0
- package/dist/src/api/node-provider.js +12 -6
- package/dist/src/api/utils.d.ts +1 -1
- package/dist/src/block/block.d.ts +28 -0
- package/dist/src/block/block.js +131 -0
- package/dist/src/block/index.d.ts +1 -0
- package/dist/src/block/index.js +22 -0
- package/dist/src/codec/contract-output-codec.js +4 -4
- package/dist/src/codec/instr-codec.d.ts +3 -0
- package/dist/src/codec/instr-codec.js +19 -3
- package/dist/src/codec/lockup-script-codec.js +2 -2
- package/dist/src/codec/method-codec.d.ts +3 -1
- package/dist/src/codec/method-codec.js +27 -2
- package/dist/src/codec/script-codec.d.ts +11 -6
- package/dist/src/codec/script-codec.js +13 -2
- package/dist/src/codec/transaction-codec.js +2 -2
- package/dist/src/codec/unlock-script-codec.d.ts +2 -2
- package/dist/src/codec/unsigned-tx-codec.d.ts +2 -2
- package/dist/src/contract/contract.d.ts +25 -7
- package/dist/src/contract/contract.js +136 -51
- package/dist/src/contract/events.d.ts +1 -2
- package/dist/src/contract/events.js +28 -14
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/signer/tx-builder.js +4 -4
- package/dist/src/transaction/status.js +28 -4
- package/dist/src/utils/address.js +29 -16
- package/dist/src/utils/exchange.js +25 -15
- package/dist/src/utils/number.d.ts +1 -1
- package/dist/src/utils/sign.js +6 -6
- package/dist/src/utils/subscription.d.ts +4 -4
- package/dist/src/utils/subscription.js +1 -1
- package/package.json +5 -5
- package/src/api/api-alephium.ts +1 -1
- package/src/api/node-provider.ts +8 -1
- package/src/api/utils.ts +1 -1
- package/src/block/block.ts +139 -0
- package/src/block/index.ts +19 -0
- package/src/codec/contract-output-codec.ts +1 -1
- package/src/codec/instr-codec.ts +14 -1
- package/src/codec/lockup-script-codec.ts +3 -3
- package/src/codec/method-codec.ts +41 -3
- package/src/codec/script-codec.ts +23 -5
- package/src/codec/transaction-codec.ts +1 -1
- package/src/codec/unlock-script-codec.ts +2 -2
- package/src/codec/unsigned-tx-codec.ts +2 -2
- package/src/contract/contract.ts +178 -67
- package/src/contract/events.ts +6 -18
- package/src/index.ts +1 -0
- package/src/signer/tx-builder.ts +2 -2
- package/src/transaction/status.ts +4 -4
- package/src/utils/address.ts +15 -2
- package/src/utils/exchange.ts +32 -10
- package/src/utils/number.ts +1 -1
- package/src/utils/sign.ts +1 -1
- package/src/utils/subscription.ts +4 -4
- package/std/fungible_token_interface.ral +1 -0
- package/std/nft_collection_interface.ral +1 -0
- package/std/nft_collection_with_royalty_interface.ral +1 -0
- package/std/nft_interface.ral +1 -0
package/src/utils/exchange.ts
CHANGED
|
@@ -16,9 +16,20 @@ 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 {
|
|
19
|
+
import {
|
|
20
|
+
AddressType,
|
|
21
|
+
addressFromPublicKey,
|
|
22
|
+
addressFromScript,
|
|
23
|
+
binToHex,
|
|
24
|
+
bs58,
|
|
25
|
+
hexToBinUnsafe,
|
|
26
|
+
isHexString
|
|
27
|
+
} from '../utils'
|
|
20
28
|
import { Transaction } from '../api/api-alephium'
|
|
21
29
|
import { Address } from '../signer'
|
|
30
|
+
import { P2SH, unlockScriptCodec } from '../codec/unlock-script-codec'
|
|
31
|
+
import { Buffer } from 'buffer/'
|
|
32
|
+
import { scriptCodec } from '../codec/script-codec'
|
|
22
33
|
|
|
23
34
|
export function validateExchangeAddress(address: string) {
|
|
24
35
|
let decoded: Uint8Array
|
|
@@ -80,24 +91,35 @@ enum UnlockScriptType {
|
|
|
80
91
|
}
|
|
81
92
|
|
|
82
93
|
export function getAddressFromUnlockScript(unlockScript: string): Address {
|
|
94
|
+
if (!isHexString(unlockScript)) {
|
|
95
|
+
throw new Error(`Invalid unlock script ${unlockScript}, expected a hex string`)
|
|
96
|
+
}
|
|
83
97
|
const decoded = hexToBinUnsafe(unlockScript)
|
|
84
98
|
if (decoded.length === 0) throw new Error('UnlockScript is empty')
|
|
85
99
|
const unlockScriptType = decoded[0]
|
|
86
100
|
const unlockScriptBody = decoded.slice(1)
|
|
87
101
|
|
|
88
102
|
if (unlockScriptType === UnlockScriptType.P2PKH) {
|
|
103
|
+
if (unlockScriptBody.length !== 33) {
|
|
104
|
+
throw new Error(`Invalid p2pkh unlock script: ${unlockScript}`)
|
|
105
|
+
}
|
|
89
106
|
return addressFromPublicKey(binToHex(unlockScriptBody))
|
|
90
|
-
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (unlockScriptType === UnlockScriptType.P2MPKH) {
|
|
91
110
|
throw new Error('Naive multi-sig address is not supported for exchanges as it will be replaced by P2SH')
|
|
92
|
-
} else if (unlockScriptType === UnlockScriptType.P2SH) {
|
|
93
|
-
// FIXEME: for now we assume that the params is empty, so we need to
|
|
94
|
-
// remove the last byte from the `unlockScriptBody`, we can decode
|
|
95
|
-
// the unlock script once the codec PR is merged
|
|
96
|
-
const script = unlockScriptBody.slice(0, -1)
|
|
97
|
-
return addressFromScript(script)
|
|
98
|
-
} else {
|
|
99
|
-
throw new Error('Invalid unlock script type')
|
|
100
111
|
}
|
|
112
|
+
|
|
113
|
+
if (unlockScriptType === UnlockScriptType.P2SH) {
|
|
114
|
+
let p2sh: P2SH
|
|
115
|
+
try {
|
|
116
|
+
p2sh = unlockScriptCodec.decode(Buffer.from(decoded)).script as P2SH
|
|
117
|
+
} catch (_) {
|
|
118
|
+
throw new Error(`Invalid p2sh unlock script: ${unlockScript}`)
|
|
119
|
+
}
|
|
120
|
+
return addressFromScript(scriptCodec.encode(p2sh.script))
|
|
121
|
+
}
|
|
122
|
+
throw new Error('Invalid unlock script type')
|
|
101
123
|
}
|
|
102
124
|
|
|
103
125
|
function checkALPHOutput(tx: Transaction): boolean {
|
package/src/utils/number.ts
CHANGED
|
@@ -21,7 +21,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
21
21
|
// 2. https://github.com/ethers-io/ethers.js/blob/724881f34d428406488a1c9f9dbebe54b6edecda/src.ts/utils/fixednumber.ts
|
|
22
22
|
|
|
23
23
|
import BigNumber from 'bignumber.js'
|
|
24
|
-
import { Number256 } from '
|
|
24
|
+
import { Number256 } from '../api/types'
|
|
25
25
|
|
|
26
26
|
export const isNumeric = (numToCheck: any): boolean => !isNaN(parseFloat(numToCheck)) && isFinite(numToCheck)
|
|
27
27
|
|
package/src/utils/sign.ts
CHANGED
|
@@ -17,7 +17,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { ec as EC } from 'elliptic'
|
|
20
|
-
import { binToHex, encodeSignature, hexToBinUnsafe, signatureDecode } from '
|
|
20
|
+
import { binToHex, encodeSignature, hexToBinUnsafe, signatureDecode } from '../utils'
|
|
21
21
|
import { KeyType } from '../signer'
|
|
22
22
|
import * as necc from '@noble/secp256k1'
|
|
23
23
|
import { createHash, createHmac } from 'crypto'
|
|
@@ -18,8 +18,8 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
|
|
19
19
|
import EventEmitter from 'eventemitter3'
|
|
20
20
|
|
|
21
|
-
type MessageCallback<Message> = (message: Message) => Promise<void>
|
|
22
|
-
type ErrorCallback<Message> = (error: any, subscription: Subscription<Message>) => Promise<void>
|
|
21
|
+
type MessageCallback<Message> = (message: Message) => Promise<void> | void
|
|
22
|
+
type ErrorCallback<Message> = (error: any, subscription: Subscription<Message>) => Promise<void> | void
|
|
23
23
|
|
|
24
24
|
export interface SubscribeOptions<Message> {
|
|
25
25
|
pollingInterval: number
|
|
@@ -45,7 +45,7 @@ export abstract class Subscription<Message> {
|
|
|
45
45
|
this.eventEmitter = new EventEmitter()
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
subscribe(): void {
|
|
49
49
|
this.eventEmitter.on('tick', async () => {
|
|
50
50
|
await this.polling()
|
|
51
51
|
|
|
@@ -68,5 +68,5 @@ export abstract class Subscription<Message> {
|
|
|
68
68
|
return this.cancelled
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
abstract polling(): Promise<void>
|
|
71
|
+
protected abstract polling(): Promise<void>
|
|
72
72
|
}
|