@alephium/web3 1.3.0 → 1.5.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/address/address.js +11 -5
- package/dist/src/api/api-alephium.d.ts +2 -4
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/codec/array-codec.d.ts +4 -12
- package/dist/src/codec/array-codec.js +15 -28
- package/dist/src/codec/asset-output-codec.d.ts +6 -11
- package/dist/src/codec/asset-output-codec.js +32 -71
- package/dist/src/codec/bigint-codec.d.ts +2 -1
- package/dist/src/codec/bigint-codec.js +14 -2
- package/dist/src/codec/bytestring-codec.d.ts +6 -11
- package/dist/src/codec/bytestring-codec.js +9 -23
- package/dist/src/codec/codec.d.ts +54 -5
- package/dist/src/codec/codec.js +112 -14
- package/dist/src/codec/compact-int-codec.d.ts +65 -44
- package/dist/src/codec/compact-int-codec.js +222 -204
- package/dist/src/codec/contract-codec.d.ts +5 -8
- package/dist/src/codec/contract-codec.js +15 -29
- package/dist/src/codec/contract-output-codec.d.ts +4 -10
- package/dist/src/codec/contract-output-codec.js +20 -40
- package/dist/src/codec/contract-output-ref-codec.d.ts +2 -8
- package/dist/src/codec/contract-output-ref-codec.js +7 -17
- package/dist/src/codec/either-codec.d.ts +8 -15
- package/dist/src/codec/either-codec.js +5 -46
- package/dist/src/codec/index.d.ts +4 -3
- package/dist/src/codec/index.js +7 -4
- package/dist/src/codec/input-codec.d.ts +4 -10
- package/dist/src/codec/input-codec.js +11 -46
- package/dist/src/codec/instr-codec.d.ts +633 -40
- package/dist/src/codec/instr-codec.js +1040 -434
- package/dist/src/codec/int-as-4bytes-codec.d.ts +7 -0
- package/dist/src/codec/{signed-int-codec.js → int-as-4bytes-codec.js} +6 -12
- package/dist/src/codec/lockup-script-codec.d.ts +23 -26
- package/dist/src/codec/lockup-script-codec.js +12 -58
- package/dist/src/codec/method-codec.d.ts +6 -18
- package/dist/src/codec/method-codec.js +20 -48
- package/dist/src/codec/option-codec.d.ts +8 -13
- package/dist/src/codec/option-codec.js +14 -32
- package/dist/src/codec/output-codec.d.ts +2 -2
- package/dist/src/codec/output-codec.js +1 -1
- package/dist/src/codec/reader.d.ts +8 -0
- package/dist/src/codec/reader.js +48 -0
- package/dist/src/codec/script-codec.d.ts +6 -14
- package/dist/src/codec/script-codec.js +6 -22
- package/dist/src/codec/signature-codec.d.ts +4 -12
- package/dist/src/codec/signature-codec.js +3 -15
- package/dist/src/codec/timestamp-codec.d.ts +8 -0
- package/dist/src/codec/timestamp-codec.js +39 -0
- package/dist/src/codec/token-codec.d.ts +3 -10
- package/dist/src/codec/token-codec.js +6 -24
- package/dist/src/codec/transaction-codec.d.ts +6 -11
- package/dist/src/codec/transaction-codec.js +24 -49
- package/dist/src/codec/unlock-script-codec.d.ts +25 -36
- package/dist/src/codec/unlock-script-codec.js +26 -147
- package/dist/src/codec/unsigned-tx-codec.d.ts +8 -14
- package/dist/src/codec/unsigned-tx-codec.js +24 -66
- package/dist/src/codec/val.d.ts +27 -0
- package/dist/src/codec/val.js +33 -0
- package/dist/src/contract/contract.d.ts +1 -0
- package/dist/src/contract/contract.js +20 -13
- package/dist/src/contract/index.d.ts +1 -0
- package/dist/src/contract/index.js +1 -0
- package/dist/src/contract/ralph.d.ts +0 -4
- package/dist/src/contract/ralph.js +50 -179
- package/dist/src/contract/script-simulator.d.ts +27 -0
- package/dist/src/contract/script-simulator.js +757 -0
- package/dist/src/exchange/exchange.js +1 -1
- package/package.json +3 -4
- package/src/address/address.ts +15 -9
- package/src/api/api-alephium.ts +2 -4
- package/src/codec/array-codec.ts +16 -34
- package/src/codec/asset-output-codec.ts +38 -83
- package/src/codec/bigint-codec.ts +16 -2
- package/src/codec/bytestring-codec.ts +10 -28
- package/src/codec/codec.ts +121 -15
- package/src/codec/compact-int-codec.ts +230 -207
- package/src/codec/contract-codec.ts +20 -33
- package/src/codec/contract-output-codec.ts +22 -48
- package/src/codec/contract-output-ref-codec.ts +6 -17
- package/src/codec/either-codec.ts +4 -53
- package/src/codec/index.ts +4 -3
- package/src/codec/input-codec.ts +14 -36
- package/src/codec/instr-codec.ts +1229 -455
- package/src/codec/{signed-int-codec.ts → int-as-4bytes-codec.ts} +6 -10
- package/src/codec/lockup-script-codec.ts +28 -76
- package/src/codec/method-codec.ts +23 -61
- package/src/codec/option-codec.ts +13 -36
- package/src/codec/output-codec.ts +2 -2
- package/src/codec/reader.ts +56 -0
- package/src/codec/script-codec.ts +9 -31
- package/src/codec/signature-codec.ts +3 -18
- package/src/codec/timestamp-codec.ts +42 -0
- package/src/codec/token-codec.ts +7 -26
- package/src/codec/transaction-codec.ts +29 -58
- package/src/codec/unlock-script-codec.ts +44 -171
- package/src/codec/unsigned-tx-codec.ts +34 -63
- package/src/codec/val.ts +40 -0
- package/src/contract/contract.ts +24 -20
- package/src/contract/index.ts +1 -0
- package/src/contract/ralph.ts +76 -172
- package/src/contract/script-simulator.ts +838 -0
- package/src/exchange/exchange.ts +1 -1
- package/dist/src/codec/long-codec.d.ts +0 -8
- package/dist/src/codec/long-codec.js +0 -55
- package/dist/src/codec/signed-int-codec.d.ts +0 -8
- package/src/codec/long-codec.ts +0 -58
package/src/exchange/exchange.ts
CHANGED
|
@@ -105,7 +105,7 @@ export function getAddressFromUnlockScript(unlockScript: string): Address {
|
|
|
105
105
|
if (unlockScriptType === UnlockScriptType.P2SH) {
|
|
106
106
|
let p2sh: P2SH
|
|
107
107
|
try {
|
|
108
|
-
p2sh = unlockScriptCodec.decode(decoded).
|
|
108
|
+
p2sh = unlockScriptCodec.decode(decoded).value as P2SH
|
|
109
109
|
} catch (_) {
|
|
110
110
|
throw new Error(`Invalid p2sh unlock script: ${unlockScript}`)
|
|
111
111
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Parser } from 'binary-parser';
|
|
2
|
-
import { Codec } from './codec';
|
|
3
|
-
export declare class LongCodec implements Codec<bigint> {
|
|
4
|
-
parser: Parser;
|
|
5
|
-
encode(input: bigint): Uint8Array;
|
|
6
|
-
decode(bytes: Uint8Array): bigint;
|
|
7
|
-
}
|
|
8
|
-
export declare const longCodec: LongCodec;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.longCodec = exports.LongCodec = void 0;
|
|
4
|
-
/*
|
|
5
|
-
Copyright 2018 - 2022 The Alephium Authors
|
|
6
|
-
This file is part of the alephium project.
|
|
7
|
-
|
|
8
|
-
The library is free software: you can redistribute it and/or modify
|
|
9
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
10
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
11
|
-
(at your option) any later version.
|
|
12
|
-
|
|
13
|
-
The library is distributed in the hope that it will be useful,
|
|
14
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
-
GNU Lesser General Public License for more details.
|
|
17
|
-
|
|
18
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
19
|
-
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
-
*/
|
|
21
|
-
const binary_parser_1 = require("binary-parser");
|
|
22
|
-
const codec_1 = require("./codec");
|
|
23
|
-
class LongCodec {
|
|
24
|
-
constructor() {
|
|
25
|
-
this.parser = binary_parser_1.Parser.start().buffer('value', {
|
|
26
|
-
length: 8
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
encode(input) {
|
|
30
|
-
const byteArray = new Uint8Array(8);
|
|
31
|
-
(0, codec_1.assert)(byteArray.length <= 8, 'Length should be less than or equal to 8');
|
|
32
|
-
for (let index = 0; index < byteArray.length; index++) {
|
|
33
|
-
const byte = input & BigInt(0xff);
|
|
34
|
-
byteArray[byteArray.length - index - 1] = Number(byte);
|
|
35
|
-
input >>= BigInt(8);
|
|
36
|
-
}
|
|
37
|
-
return byteArray;
|
|
38
|
-
}
|
|
39
|
-
decode(bytes) {
|
|
40
|
-
(0, codec_1.assert)(bytes.length == 8, 'Length should be 8');
|
|
41
|
-
let int64 = BigInt(0);
|
|
42
|
-
let pow = BigInt(1);
|
|
43
|
-
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
44
|
-
int64 += BigInt(bytes[i]) * pow;
|
|
45
|
-
pow *= BigInt(256);
|
|
46
|
-
}
|
|
47
|
-
// Determine if the number is negative (check the sign bit of the first byte)
|
|
48
|
-
if (bytes[0] & 0x80) {
|
|
49
|
-
int64 -= BigInt(1) << BigInt(64);
|
|
50
|
-
}
|
|
51
|
-
return int64;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.LongCodec = LongCodec;
|
|
55
|
-
exports.longCodec = new LongCodec();
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Parser } from 'binary-parser';
|
|
2
|
-
import { Codec } from './codec';
|
|
3
|
-
export declare class SignedIntCodec implements Codec<number> {
|
|
4
|
-
parser: Parser;
|
|
5
|
-
encode(value: number): Uint8Array;
|
|
6
|
-
decode(bytes: Uint8Array): number;
|
|
7
|
-
}
|
|
8
|
-
export declare const signedIntCodec: SignedIntCodec;
|
package/src/codec/long-codec.ts
DELETED
|
@@ -1,58 +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
|
-
import { Parser } from 'binary-parser'
|
|
19
|
-
import { Codec, assert } from './codec'
|
|
20
|
-
|
|
21
|
-
export class LongCodec implements Codec<bigint> {
|
|
22
|
-
parser = Parser.start().buffer('value', {
|
|
23
|
-
length: 8
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
encode(input: bigint): Uint8Array {
|
|
27
|
-
const byteArray = new Uint8Array(8)
|
|
28
|
-
|
|
29
|
-
assert(byteArray.length <= 8, 'Length should be less than or equal to 8')
|
|
30
|
-
for (let index = 0; index < byteArray.length; index++) {
|
|
31
|
-
const byte = input & BigInt(0xff)
|
|
32
|
-
byteArray[byteArray.length - index - 1] = Number(byte)
|
|
33
|
-
input >>= BigInt(8)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return byteArray
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
decode(bytes: Uint8Array): bigint {
|
|
40
|
-
assert(bytes.length == 8, 'Length should be 8')
|
|
41
|
-
let int64 = BigInt(0)
|
|
42
|
-
let pow = BigInt(1)
|
|
43
|
-
|
|
44
|
-
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
45
|
-
int64 += BigInt(bytes[i]) * pow
|
|
46
|
-
pow *= BigInt(256)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Determine if the number is negative (check the sign bit of the first byte)
|
|
50
|
-
if (bytes[0] & 0x80) {
|
|
51
|
-
int64 -= BigInt(1) << BigInt(64)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return int64
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const longCodec = new LongCodec()
|