@alephium/web3 1.4.0 → 1.5.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.js +5 -5
- package/dist/src/api/api-alephium.d.ts +1 -1
- 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.js +6 -6
- 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 +8 -8
- package/src/api/api-alephium.ts +1 -1
- 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 +9 -13
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.intAs4BytesCodec = exports.IntAs4BytesCodec = void 0;
|
|
4
4
|
/*
|
|
5
5
|
Copyright 2018 - 2022 The Alephium Authors
|
|
6
6
|
This file is part of the alephium project.
|
|
@@ -18,21 +18,15 @@ GNU Lesser General Public License for more details.
|
|
|
18
18
|
You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
const binary_parser_1 = require("binary-parser");
|
|
22
21
|
const codec_1 = require("./codec");
|
|
23
|
-
class
|
|
24
|
-
constructor() {
|
|
25
|
-
this.parser = binary_parser_1.Parser.start().buffer('value', {
|
|
26
|
-
length: 4
|
|
27
|
-
});
|
|
28
|
-
}
|
|
22
|
+
class IntAs4BytesCodec extends codec_1.Codec {
|
|
29
23
|
encode(value) {
|
|
30
24
|
return new Uint8Array([(value >> 24) & 0xff, (value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff]);
|
|
31
25
|
}
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
_decode(input) {
|
|
27
|
+
const bytes = input.consumeBytes(4);
|
|
34
28
|
return ((bytes[0] & 0xff) << 24) | ((bytes[1] & 0xff) << 16) | ((bytes[2] & 0xff) << 8) | (bytes[3] & 0xff);
|
|
35
29
|
}
|
|
36
30
|
}
|
|
37
|
-
exports.
|
|
38
|
-
exports.
|
|
31
|
+
exports.IntAs4BytesCodec = IntAs4BytesCodec;
|
|
32
|
+
exports.intAs4BytesCodec = new IntAs4BytesCodec();
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
1
|
+
import { EnumCodec } from './codec';
|
|
2
|
+
export type PublicKeyHash = Uint8Array;
|
|
3
|
+
export type P2PKH = Uint8Array;
|
|
4
|
+
export type P2SH = Uint8Array;
|
|
5
|
+
export type P2C = Uint8Array;
|
|
6
|
+
export declare const p2cCodec: import("./codec").FixedSizeCodec;
|
|
7
|
+
export interface P2MPKH {
|
|
8
|
+
publicKeyHashes: PublicKeyHash[];
|
|
9
|
+
m: number;
|
|
7
10
|
}
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export declare class LockupScriptCodec implements Codec<LockupScript> {
|
|
23
|
-
parser: Parser;
|
|
24
|
-
encode(input: LockupScript): Uint8Array;
|
|
25
|
-
decode(input: Uint8Array): LockupScript;
|
|
26
|
-
}
|
|
27
|
-
export declare const lockupScriptCodec: LockupScriptCodec;
|
|
11
|
+
export type LockupScript = {
|
|
12
|
+
kind: 'P2PKH';
|
|
13
|
+
value: P2PKH;
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'P2MPKH';
|
|
16
|
+
value: P2MPKH;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'P2SH';
|
|
19
|
+
value: P2SH;
|
|
20
|
+
} | {
|
|
21
|
+
kind: 'P2C';
|
|
22
|
+
value: P2C;
|
|
23
|
+
};
|
|
24
|
+
export declare const lockupScriptCodec: EnumCodec<LockupScript>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lockupScriptCodec = exports.
|
|
3
|
+
exports.lockupScriptCodec = exports.p2cCodec = void 0;
|
|
4
4
|
/*
|
|
5
5
|
Copyright 2018 - 2022 The Alephium Authors
|
|
6
6
|
This file is part of the alephium project.
|
|
@@ -18,63 +18,17 @@ GNU Lesser General Public License for more details.
|
|
|
18
18
|
You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
const binary_parser_1 = require("binary-parser");
|
|
22
21
|
const compact_int_codec_1 = require("./compact-int-codec");
|
|
23
22
|
const codec_1 = require("./codec");
|
|
24
23
|
const array_codec_1 = require("./array-codec");
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
const publicKeyHashCodec = new PublicKeyHashCodec();
|
|
37
|
-
const publicKeyHashesCodec = new array_codec_1.ArrayCodec(publicKeyHashCodec);
|
|
38
|
-
const multiSigParser = binary_parser_1.Parser.start()
|
|
39
|
-
.nest('publicKeyHashes', { type: publicKeyHashesCodec.parser })
|
|
40
|
-
.nest('m', { type: compact_int_codec_1.compactSignedIntCodec.parser });
|
|
41
|
-
class LockupScriptCodec {
|
|
42
|
-
constructor() {
|
|
43
|
-
this.parser = binary_parser_1.Parser.start()
|
|
44
|
-
.uint8('scriptType')
|
|
45
|
-
.choice('script', {
|
|
46
|
-
tag: 'scriptType',
|
|
47
|
-
choices: {
|
|
48
|
-
0: publicKeyHashCodec.parser,
|
|
49
|
-
1: multiSigParser,
|
|
50
|
-
2: binary_parser_1.Parser.start().buffer('scriptHash', { length: 32 }),
|
|
51
|
-
3: binary_parser_1.Parser.start().buffer('contractId', { length: 32 })
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
encode(input) {
|
|
56
|
-
const result = [input.scriptType];
|
|
57
|
-
if (input.scriptType === 0) {
|
|
58
|
-
result.push(...input.script.publicKeyHash);
|
|
59
|
-
}
|
|
60
|
-
else if (input.scriptType === 1) {
|
|
61
|
-
result.push(...publicKeyHashesCodec.encode(input.script.publicKeyHashes.value));
|
|
62
|
-
result.push(...compact_int_codec_1.compactSignedIntCodec.encode(input.script.m));
|
|
63
|
-
}
|
|
64
|
-
else if (input.scriptType === 2) {
|
|
65
|
-
result.push(...input.script.scriptHash);
|
|
66
|
-
}
|
|
67
|
-
else if (input.scriptType === 3) {
|
|
68
|
-
result.push(...input.script.contractId);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
throw new Error(`Unsupported script type: ${input.scriptType}`);
|
|
72
|
-
}
|
|
73
|
-
return new Uint8Array(result);
|
|
74
|
-
}
|
|
75
|
-
decode(input) {
|
|
76
|
-
return this.parser.parse(input);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.LockupScriptCodec = LockupScriptCodec;
|
|
80
|
-
exports.lockupScriptCodec = new LockupScriptCodec();
|
|
24
|
+
exports.p2cCodec = codec_1.byte32Codec;
|
|
25
|
+
const p2mpkhCodec = new codec_1.ObjectCodec({
|
|
26
|
+
publicKeyHashes: new array_codec_1.ArrayCodec(codec_1.byte32Codec),
|
|
27
|
+
m: compact_int_codec_1.i32Codec
|
|
28
|
+
});
|
|
29
|
+
exports.lockupScriptCodec = new codec_1.EnumCodec('lockup script', {
|
|
30
|
+
P2PKH: codec_1.byte32Codec,
|
|
31
|
+
P2MPKH: p2mpkhCodec,
|
|
32
|
+
P2SH: codec_1.byte32Codec,
|
|
33
|
+
P2C: codec_1.byte32Codec
|
|
34
|
+
});
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ArrayCodec, DecodedArray } from './array-codec';
|
|
3
|
-
import { DecodedCompactInt } from './compact-int-codec';
|
|
1
|
+
import { ArrayCodec } from './array-codec';
|
|
4
2
|
import { Codec } from './codec';
|
|
5
3
|
import { Instr } from './instr-codec';
|
|
6
|
-
|
|
7
|
-
isPublic: number;
|
|
8
|
-
assetModifier: number;
|
|
9
|
-
argsLength: DecodedCompactInt;
|
|
10
|
-
localsLength: DecodedCompactInt;
|
|
11
|
-
returnLength: DecodedCompactInt;
|
|
12
|
-
instrs: DecodedArray<Instr>;
|
|
13
|
-
}
|
|
4
|
+
import { Reader } from './reader';
|
|
14
5
|
export interface Method {
|
|
15
6
|
isPublic: boolean;
|
|
16
7
|
usePreapprovedAssets: boolean;
|
|
@@ -21,12 +12,9 @@ export interface Method {
|
|
|
21
12
|
returnLength: number;
|
|
22
13
|
instrs: Instr[];
|
|
23
14
|
}
|
|
24
|
-
export declare class MethodCodec
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
decode(input: Uint8Array): DecodedMethod;
|
|
28
|
-
static toMethod(decodedMethod: DecodedMethod): Method;
|
|
29
|
-
static fromMethod(method: Method): DecodedMethod;
|
|
15
|
+
export declare class MethodCodec extends Codec<Method> {
|
|
16
|
+
encode(method: Method): Uint8Array;
|
|
17
|
+
_decode(input: Reader): Method;
|
|
30
18
|
}
|
|
31
19
|
export declare const methodCodec: MethodCodec;
|
|
32
|
-
export declare const methodsCodec: ArrayCodec<
|
|
20
|
+
export declare const methodsCodec: ArrayCodec<Method>;
|
|
@@ -18,10 +18,11 @@ GNU Lesser General Public License for more details.
|
|
|
18
18
|
You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
const binary_parser_1 = require("binary-parser");
|
|
22
21
|
const array_codec_1 = require("./array-codec");
|
|
23
22
|
const compact_int_codec_1 = require("./compact-int-codec");
|
|
23
|
+
const codec_1 = require("./codec");
|
|
24
24
|
const instr_codec_1 = require("./instr-codec");
|
|
25
|
+
const utils_1 = require("../utils");
|
|
25
26
|
function decodeAssetModifier(encoded) {
|
|
26
27
|
const usePayToContractOnly = (encoded & 4) !== 0;
|
|
27
28
|
switch (encoded & 3) {
|
|
@@ -47,54 +48,25 @@ function encodeAssetModifier(arg) {
|
|
|
47
48
|
: 3;
|
|
48
49
|
return encoded | (arg.usePayToContractOnly ? 4 : 0);
|
|
49
50
|
}
|
|
50
|
-
class MethodCodec {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
})
|
|
61
|
-
.nest('returnLength', {
|
|
62
|
-
type: compact_int_codec_1.compactSignedIntCodec.parser
|
|
63
|
-
})
|
|
64
|
-
.nest('instrs', {
|
|
65
|
-
type: instr_codec_1.instrsCodec.parser
|
|
66
|
-
});
|
|
51
|
+
class MethodCodec extends codec_1.Codec {
|
|
52
|
+
encode(method) {
|
|
53
|
+
const bytes = [];
|
|
54
|
+
bytes.push(codec_1.boolCodec.encode(method.isPublic));
|
|
55
|
+
bytes.push(new Uint8Array([encodeAssetModifier(method)]));
|
|
56
|
+
bytes.push(compact_int_codec_1.i32Codec.encode(method.argsLength));
|
|
57
|
+
bytes.push(compact_int_codec_1.i32Codec.encode(method.localsLength));
|
|
58
|
+
bytes.push(compact_int_codec_1.i32Codec.encode(method.returnLength));
|
|
59
|
+
bytes.push(instr_codec_1.instrsCodec.encode(method.instrs));
|
|
60
|
+
return (0, utils_1.concatBytes)(bytes);
|
|
67
61
|
}
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
decode(input) {
|
|
77
|
-
return this.parser.parse(input);
|
|
78
|
-
}
|
|
79
|
-
static toMethod(decodedMethod) {
|
|
80
|
-
return {
|
|
81
|
-
isPublic: decodedMethod.isPublic === 1,
|
|
82
|
-
...decodeAssetModifier(decodedMethod.assetModifier),
|
|
83
|
-
argsLength: compact_int_codec_1.compactSignedIntCodec.toI32(decodedMethod.argsLength),
|
|
84
|
-
localsLength: compact_int_codec_1.compactSignedIntCodec.toI32(decodedMethod.localsLength),
|
|
85
|
-
returnLength: compact_int_codec_1.compactSignedIntCodec.toI32(decodedMethod.returnLength),
|
|
86
|
-
instrs: decodedMethod.instrs.value
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
static fromMethod(method) {
|
|
90
|
-
return {
|
|
91
|
-
isPublic: method.isPublic ? 1 : 0,
|
|
92
|
-
assetModifier: encodeAssetModifier(method),
|
|
93
|
-
argsLength: compact_int_codec_1.compactSignedIntCodec.fromI32(method.argsLength),
|
|
94
|
-
localsLength: compact_int_codec_1.compactSignedIntCodec.fromI32(method.localsLength),
|
|
95
|
-
returnLength: compact_int_codec_1.compactSignedIntCodec.fromI32(method.returnLength),
|
|
96
|
-
instrs: instr_codec_1.instrsCodec.fromArray(method.instrs)
|
|
97
|
-
};
|
|
62
|
+
_decode(input) {
|
|
63
|
+
const isPublic = codec_1.boolCodec._decode(input);
|
|
64
|
+
const assetModifier = decodeAssetModifier(codec_1.byteCodec._decode(input));
|
|
65
|
+
const argsLength = compact_int_codec_1.i32Codec._decode(input);
|
|
66
|
+
const localsLength = compact_int_codec_1.i32Codec._decode(input);
|
|
67
|
+
const returnLength = compact_int_codec_1.i32Codec._decode(input);
|
|
68
|
+
const instrs = instr_codec_1.instrsCodec._decode(input);
|
|
69
|
+
return { ...assetModifier, isPublic, argsLength, localsLength, returnLength, instrs };
|
|
98
70
|
}
|
|
99
71
|
}
|
|
100
72
|
exports.MethodCodec = MethodCodec;
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { Parser } from 'binary-parser';
|
|
2
1
|
import { Codec } from './codec';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
value
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
encode(input: Option<T>): Uint8Array;
|
|
12
|
-
decode(input: Uint8Array): Option<T>;
|
|
13
|
-
fromBytes(input?: Uint8Array): Option<T>;
|
|
14
|
-
}
|
|
2
|
+
export type Option<T> = {
|
|
3
|
+
kind: 'None';
|
|
4
|
+
value: undefined;
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'Some';
|
|
7
|
+
value: T;
|
|
8
|
+
};
|
|
9
|
+
export declare function option<T>(codec: Codec<T>): Codec<Option<T>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.option = void 0;
|
|
4
4
|
/*
|
|
5
5
|
Copyright 2018 - 2022 The Alephium Authors
|
|
6
6
|
This file is part of the alephium project.
|
|
@@ -18,37 +18,19 @@ GNU Lesser General Public License for more details.
|
|
|
18
18
|
You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
const
|
|
22
|
-
class
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
choices: {
|
|
26
|
-
0: new binary_parser_1.Parser(),
|
|
27
|
-
1: childCodec.parser
|
|
28
|
-
}
|
|
29
|
-
})) {
|
|
30
|
-
this.childCodec = childCodec;
|
|
31
|
-
this.parser = parser;
|
|
21
|
+
const codec_1 = require("./codec");
|
|
22
|
+
const undefinedCodec = new (class extends codec_1.Codec {
|
|
23
|
+
encode() {
|
|
24
|
+
return new Uint8Array([]);
|
|
32
25
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (input.option === 1) {
|
|
36
|
-
result.push(...this.childCodec.encode(input.value));
|
|
37
|
-
}
|
|
38
|
-
return new Uint8Array(result);
|
|
39
|
-
}
|
|
40
|
-
decode(input) {
|
|
41
|
-
const result = this.parser.parse(input);
|
|
42
|
-
return {
|
|
43
|
-
...result,
|
|
44
|
-
value: result.option ? this.childCodec.decode(result.value.value) : undefined
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
fromBytes(input) {
|
|
48
|
-
return {
|
|
49
|
-
option: input ? 1 : 0,
|
|
50
|
-
value: input ? this.childCodec.decode(input) : undefined
|
|
51
|
-
};
|
|
26
|
+
_decode() {
|
|
27
|
+
return undefined;
|
|
52
28
|
}
|
|
29
|
+
})();
|
|
30
|
+
function option(codec) {
|
|
31
|
+
return new codec_1.EnumCodec('option', {
|
|
32
|
+
None: undefinedCodec,
|
|
33
|
+
Some: codec
|
|
34
|
+
});
|
|
53
35
|
}
|
|
54
|
-
exports.
|
|
36
|
+
exports.option = option;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ArrayCodec } from './array-codec';
|
|
2
|
-
import { Either
|
|
2
|
+
import { Either } from './either-codec';
|
|
3
3
|
import { AssetOutput } from './asset-output-codec';
|
|
4
4
|
import { ContractOutput } from './contract-output-codec';
|
|
5
5
|
export type Output = Either<AssetOutput, ContractOutput>;
|
|
6
|
-
export declare const outputCodec:
|
|
6
|
+
export declare const outputCodec: import("./codec").Codec<Either<AssetOutput, ContractOutput>>;
|
|
7
7
|
export declare const outputsCodec: ArrayCodec<Either<AssetOutput, ContractOutput>>;
|
|
@@ -22,5 +22,5 @@ const array_codec_1 = require("./array-codec");
|
|
|
22
22
|
const either_codec_1 = require("./either-codec");
|
|
23
23
|
const asset_output_codec_1 = require("./asset-output-codec");
|
|
24
24
|
const contract_output_codec_1 = require("./contract-output-codec");
|
|
25
|
-
exports.outputCodec =
|
|
25
|
+
exports.outputCodec = (0, either_codec_1.either)('output', asset_output_codec_1.assetOutputCodec, contract_output_codec_1.contractOutputCodec);
|
|
26
26
|
exports.outputsCodec = new array_codec_1.ArrayCodec(exports.outputCodec);
|
|
@@ -0,0 +1,48 @@
|
|
|
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.Reader = void 0;
|
|
21
|
+
class Reader {
|
|
22
|
+
constructor(bytes) {
|
|
23
|
+
this.index = 0;
|
|
24
|
+
this.bytes = bytes;
|
|
25
|
+
}
|
|
26
|
+
consumeByte() {
|
|
27
|
+
if (this.index >= this.bytes.length) {
|
|
28
|
+
throw new Error(`Index out of range: unable to consume byte at index ${this.index}, data length: ${this.bytes.length}`);
|
|
29
|
+
}
|
|
30
|
+
const byte = this.bytes[`${this.index}`];
|
|
31
|
+
this.index += 1;
|
|
32
|
+
return byte;
|
|
33
|
+
}
|
|
34
|
+
consumeBytes(num) {
|
|
35
|
+
const from = this.index;
|
|
36
|
+
const to = this.index + num;
|
|
37
|
+
if (from > to || to > this.bytes.length) {
|
|
38
|
+
throw new Error(`Index out of range: unable to consume bytes from index ${from} to ${to}, data length: ${this.bytes.length}`);
|
|
39
|
+
}
|
|
40
|
+
const bytes = this.bytes.slice(from, to);
|
|
41
|
+
this.index = to;
|
|
42
|
+
return bytes;
|
|
43
|
+
}
|
|
44
|
+
consumeAll() {
|
|
45
|
+
return this.consumeBytes(this.bytes.length - this.index);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.Reader = Reader;
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import { Parser } from 'binary-parser';
|
|
2
|
-
import { DecodedArray } from './array-codec';
|
|
3
1
|
import { Codec } from './codec';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
export interface DecodedScript {
|
|
7
|
-
methods: DecodedArray<DecodedMethod>;
|
|
8
|
-
}
|
|
2
|
+
import { Method } from './method-codec';
|
|
3
|
+
import { Reader } from './reader';
|
|
9
4
|
export interface Script {
|
|
10
5
|
methods: Method[];
|
|
11
6
|
}
|
|
12
|
-
export declare class ScriptCodec
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
decode(input: Uint8Array): DecodedScript;
|
|
16
|
-
decodeScript(input: Uint8Array): Script;
|
|
17
|
-
encodeScript(inputTxScript: Script): Uint8Array;
|
|
7
|
+
export declare class ScriptCodec extends Codec<Script> {
|
|
8
|
+
encode(input: Script): Uint8Array;
|
|
9
|
+
_decode(input: Reader): Script;
|
|
18
10
|
}
|
|
19
11
|
export declare const scriptCodec: ScriptCodec;
|
|
20
|
-
export declare const statefulScriptCodecOpt:
|
|
12
|
+
export declare const statefulScriptCodecOpt: Codec<import("./option-codec").Option<Script>>;
|
|
@@ -18,33 +18,17 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.statefulScriptCodecOpt = exports.scriptCodec = exports.ScriptCodec = void 0;
|
|
21
|
-
const
|
|
21
|
+
const codec_1 = require("./codec");
|
|
22
22
|
const method_codec_1 = require("./method-codec");
|
|
23
23
|
const option_codec_1 = require("./option-codec");
|
|
24
|
-
|
|
25
|
-
class ScriptCodec {
|
|
26
|
-
constructor() {
|
|
27
|
-
this.parser = binary_parser_1.Parser.start().nest('methods', {
|
|
28
|
-
type: method_codec_1.methodsCodec.parser
|
|
29
|
-
});
|
|
30
|
-
}
|
|
24
|
+
class ScriptCodec extends codec_1.Codec {
|
|
31
25
|
encode(input) {
|
|
32
|
-
return method_codec_1.methodsCodec.encode(input.methods
|
|
33
|
-
}
|
|
34
|
-
decode(input) {
|
|
35
|
-
return this.parser.parse(input);
|
|
36
|
-
}
|
|
37
|
-
decodeScript(input) {
|
|
38
|
-
const decodedTxScript = this.decode(input);
|
|
39
|
-
const methods = decodedTxScript.methods.value.map((decodedMethod) => method_codec_1.MethodCodec.toMethod(decodedMethod));
|
|
40
|
-
return { methods };
|
|
26
|
+
return method_codec_1.methodsCodec.encode(input.methods);
|
|
41
27
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const decodedMethods = inputTxScript.methods.map((method) => method_codec_1.MethodCodec.fromMethod(method));
|
|
45
|
-
return this.encode({ methods: { value: decodedMethods, length: methodLength } });
|
|
28
|
+
_decode(input) {
|
|
29
|
+
return { methods: method_codec_1.methodsCodec._decode(input) };
|
|
46
30
|
}
|
|
47
31
|
}
|
|
48
32
|
exports.ScriptCodec = ScriptCodec;
|
|
49
33
|
exports.scriptCodec = new ScriptCodec();
|
|
50
|
-
exports.statefulScriptCodecOpt =
|
|
34
|
+
exports.statefulScriptCodecOpt = (0, option_codec_1.option)(exports.scriptCodec);
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import { Parser } from 'binary-parser';
|
|
2
1
|
import { ArrayCodec } from './array-codec';
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare class SignatureCodec implements Codec<Signature> {
|
|
8
|
-
parser: Parser;
|
|
9
|
-
encode(input: Signature): Uint8Array;
|
|
10
|
-
decode(input: Uint8Array): Signature;
|
|
11
|
-
}
|
|
12
|
-
export declare const signatureCodec: SignatureCodec;
|
|
13
|
-
export declare const signaturesCodec: ArrayCodec<Signature>;
|
|
2
|
+
import { FixedSizeCodec } from './codec';
|
|
3
|
+
export type Signature = Uint8Array;
|
|
4
|
+
export declare const signatureCodec: FixedSizeCodec;
|
|
5
|
+
export declare const signaturesCodec: ArrayCodec<Uint8Array>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.signaturesCodec = exports.signatureCodec =
|
|
3
|
+
exports.signaturesCodec = exports.signatureCodec = void 0;
|
|
4
4
|
/*
|
|
5
5
|
Copyright 2018 - 2022 The Alephium Authors
|
|
6
6
|
This file is part of the alephium project.
|
|
@@ -18,19 +18,7 @@ GNU Lesser General Public License for more details.
|
|
|
18
18
|
You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
const binary_parser_1 = require("binary-parser");
|
|
22
21
|
const array_codec_1 = require("./array-codec");
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.parser = binary_parser_1.Parser.start().buffer('value', { length: 64 });
|
|
26
|
-
}
|
|
27
|
-
encode(input) {
|
|
28
|
-
return input.value;
|
|
29
|
-
}
|
|
30
|
-
decode(input) {
|
|
31
|
-
return this.parser.parse(input);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.SignatureCodec = SignatureCodec;
|
|
35
|
-
exports.signatureCodec = new SignatureCodec();
|
|
22
|
+
const codec_1 = require("./codec");
|
|
23
|
+
exports.signatureCodec = new codec_1.FixedSizeCodec(64);
|
|
36
24
|
exports.signaturesCodec = new array_codec_1.ArrayCodec(exports.signatureCodec);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Codec } from './codec';
|
|
2
|
+
import { Reader } from './reader';
|
|
3
|
+
export declare class TimestampCodec extends Codec<bigint> {
|
|
4
|
+
static max: bigint;
|
|
5
|
+
encode(input: bigint): Uint8Array;
|
|
6
|
+
_decode(input: Reader): bigint;
|
|
7
|
+
}
|
|
8
|
+
export declare const timestampCodec: TimestampCodec;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.timestampCodec = exports.TimestampCodec = 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 utils_1 = require("../utils");
|
|
22
|
+
const codec_1 = require("./codec");
|
|
23
|
+
class TimestampCodec extends codec_1.Codec {
|
|
24
|
+
encode(input) {
|
|
25
|
+
(0, codec_1.assert)(input >= 0n && input < TimestampCodec.max, `Invalid timestamp: ${input}`);
|
|
26
|
+
const byteArray = new Uint8Array(8);
|
|
27
|
+
for (let index = 0; index < 8; index += 1) {
|
|
28
|
+
byteArray[`${index}`] = Number((input >> BigInt((7 - index) * 8)) & BigInt(0xff));
|
|
29
|
+
}
|
|
30
|
+
return byteArray;
|
|
31
|
+
}
|
|
32
|
+
_decode(input) {
|
|
33
|
+
const bytes = input.consumeBytes(8);
|
|
34
|
+
return BigInt(`0x${(0, utils_1.binToHex)(bytes)}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.TimestampCodec = TimestampCodec;
|
|
38
|
+
TimestampCodec.max = 1n << 64n;
|
|
39
|
+
exports.timestampCodec = new TimestampCodec();
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DecodedCompactInt } from './compact-int-codec';
|
|
3
|
-
import { Codec } from './codec';
|
|
1
|
+
import { ObjectCodec } from './codec';
|
|
4
2
|
import { ArrayCodec } from './array-codec';
|
|
5
3
|
export interface Token {
|
|
6
4
|
tokenId: Uint8Array;
|
|
7
|
-
amount:
|
|
5
|
+
amount: bigint;
|
|
8
6
|
}
|
|
9
|
-
export declare
|
|
10
|
-
parser: Parser;
|
|
11
|
-
encode(input: Token): Uint8Array;
|
|
12
|
-
decode(input: Uint8Array): Token;
|
|
13
|
-
}
|
|
14
|
-
export declare const tokenCodec: TokenCodec;
|
|
7
|
+
export declare const tokenCodec: ObjectCodec<Token>;
|
|
15
8
|
export declare const tokensCodec: ArrayCodec<Token>;
|