@alephium/web3 0.37.0 → 0.38.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/api/api-alephium.d.ts +5 -0
- package/dist/src/api/types.d.ts +1 -1
- package/dist/src/codec/array-codec.d.ts +17 -0
- package/dist/src/codec/array-codec.js +59 -0
- package/dist/src/codec/asset-output-codec.d.ts +27 -0
- package/dist/src/codec/asset-output-codec.js +135 -0
- package/dist/src/codec/bigint-codec.d.ts +5 -0
- package/dist/src/codec/bigint-codec.js +86 -0
- package/dist/src/codec/bytestring-codec.d.ts +16 -0
- package/dist/src/codec/bytestring-codec.js +50 -0
- package/dist/src/codec/codec.d.ts +8 -0
- package/dist/src/codec/codec.js +9 -0
- package/dist/src/codec/compact-int-codec.d.ts +51 -0
- package/dist/src/codec/compact-int-codec.js +300 -0
- package/dist/src/codec/contract-codec.d.ts +23 -0
- package/dist/src/codec/contract-codec.js +81 -0
- package/dist/src/codec/contract-output-codec.d.ts +21 -0
- package/dist/src/codec/contract-output-codec.js +82 -0
- package/dist/src/codec/contract-output-ref-codec.d.ts +15 -0
- package/dist/src/codec/contract-output-ref-codec.js +38 -0
- package/dist/src/codec/either-codec.d.ts +17 -0
- package/dist/src/codec/either-codec.js +67 -0
- package/dist/src/codec/hash.d.ts +4 -0
- package/dist/src/codec/hash.js +23 -0
- package/dist/src/codec/index.d.ts +23 -0
- package/dist/src/codec/index.js +69 -0
- package/dist/src/codec/input-codec.d.ts +22 -0
- package/dist/src/codec/input-codec.js +71 -0
- package/dist/src/codec/instr-codec.d.ts +230 -0
- package/dist/src/codec/instr-codec.js +471 -0
- package/dist/src/codec/lockup-script-codec.d.ts +28 -0
- package/dist/src/codec/lockup-script-codec.js +80 -0
- package/dist/src/codec/long-codec.d.ts +9 -0
- package/dist/src/codec/long-codec.js +56 -0
- package/dist/src/codec/method-codec.d.ts +31 -0
- package/dist/src/codec/method-codec.js +78 -0
- package/dist/src/codec/option-codec.d.ts +15 -0
- package/dist/src/codec/option-codec.js +55 -0
- package/dist/src/codec/output-codec.d.ts +7 -0
- package/dist/src/codec/output-codec.js +26 -0
- package/dist/src/codec/script-codec.d.ts +16 -0
- package/dist/src/codec/script-codec.js +41 -0
- package/dist/src/codec/signature-codec.d.ts +14 -0
- package/dist/src/codec/signature-codec.js +19 -0
- package/dist/src/codec/signed-int-codec.d.ts +9 -0
- package/dist/src/codec/signed-int-codec.js +39 -0
- package/dist/src/codec/token-codec.d.ts +16 -0
- package/dist/src/codec/token-codec.js +46 -0
- package/dist/src/codec/transaction-codec.d.ts +27 -0
- package/dist/src/codec/transaction-codec.js +128 -0
- package/dist/src/codec/unlock-script-codec.d.ts +40 -0
- package/dist/src/codec/unlock-script-codec.js +170 -0
- package/dist/src/codec/unsigned-tx-codec.d.ts +30 -0
- package/dist/src/codec/unsigned-tx-codec.js +103 -0
- package/dist/src/contract/contract.d.ts +10 -4
- package/dist/src/contract/contract.js +184 -11
- package/dist/src/contract/ralph.d.ts +16 -0
- package/dist/src/contract/ralph.js +127 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +2 -1
- package/dist/src/utils/address.d.ts +2 -0
- package/dist/src/utils/address.js +18 -6
- package/package.json +4 -3
- package/src/api/api-alephium.ts +6 -0
- package/src/api/types.ts +1 -1
- package/src/codec/array-codec.ts +63 -0
- package/src/codec/asset-output-codec.ts +149 -0
- package/src/codec/bigint-codec.ts +92 -0
- package/src/codec/bytestring-codec.ts +56 -0
- package/src/codec/codec.ts +31 -0
- package/src/codec/compact-int-codec.ts +316 -0
- package/src/codec/contract-codec.ts +95 -0
- package/src/codec/contract-output-codec.ts +95 -0
- package/src/codec/contract-output-ref-codec.ts +42 -0
- package/src/codec/either-codec.ts +74 -0
- package/src/codec/hash.ts +35 -0
- package/src/codec/index.ts +41 -0
- package/src/codec/input-codec.ts +81 -0
- package/src/codec/instr-codec.ts +479 -0
- package/src/codec/lockup-script-codec.ts +99 -0
- package/src/codec/long-codec.ts +59 -0
- package/src/codec/method-codec.ts +97 -0
- package/src/codec/option-codec.ts +60 -0
- package/src/codec/output-codec.ts +26 -0
- package/src/codec/script-codec.ts +45 -0
- package/src/codec/signature-codec.ts +40 -0
- package/src/codec/signed-int-codec.ts +37 -0
- package/src/codec/token-codec.ts +51 -0
- package/src/codec/transaction-codec.ts +147 -0
- package/src/codec/unlock-script-codec.ts +194 -0
- package/src/codec/unsigned-tx-codec.ts +124 -0
- package/src/contract/contract.ts +271 -14
- package/src/contract/ralph.ts +140 -2
- package/src/index.ts +1 -1
- package/src/utils/address.ts +17 -5
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
|
+
import { Parser } from 'binary-parser';
|
|
3
|
+
import { ArrayCodec, DecodedArray } from './array-codec';
|
|
4
|
+
import { DecodedCompactInt } from './compact-int-codec';
|
|
5
|
+
import { Codec } from './codec';
|
|
6
|
+
import { Instr } from './instr-codec';
|
|
7
|
+
export interface DecodedMethod {
|
|
8
|
+
isPublic: number;
|
|
9
|
+
assetModifier: number;
|
|
10
|
+
argsLength: DecodedCompactInt;
|
|
11
|
+
localsLength: DecodedCompactInt;
|
|
12
|
+
returnLength: DecodedCompactInt;
|
|
13
|
+
instrs: DecodedArray<Instr>;
|
|
14
|
+
}
|
|
15
|
+
export interface Method {
|
|
16
|
+
isPublic: boolean;
|
|
17
|
+
assetModifier: number;
|
|
18
|
+
argsLength: number;
|
|
19
|
+
localsLength: number;
|
|
20
|
+
returnLength: number;
|
|
21
|
+
instrs: Instr[];
|
|
22
|
+
}
|
|
23
|
+
export declare class MethodCodec implements Codec<DecodedMethod> {
|
|
24
|
+
parser: Parser;
|
|
25
|
+
encode(input: DecodedMethod): Buffer;
|
|
26
|
+
decode(input: Buffer): DecodedMethod;
|
|
27
|
+
static toMethod(decodedMethod: DecodedMethod): Method;
|
|
28
|
+
static fromMethod(method: Method): DecodedMethod;
|
|
29
|
+
}
|
|
30
|
+
export declare const methodCodec: MethodCodec;
|
|
31
|
+
export declare const methodsCodec: ArrayCodec<DecodedMethod>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.methodsCodec = exports.methodCodec = exports.MethodCodec = 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 buffer_1 = require("buffer/");
|
|
22
|
+
const binary_parser_1 = require("binary-parser");
|
|
23
|
+
const array_codec_1 = require("./array-codec");
|
|
24
|
+
const compact_int_codec_1 = require("./compact-int-codec");
|
|
25
|
+
const instr_codec_1 = require("./instr-codec");
|
|
26
|
+
class MethodCodec {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.parser = binary_parser_1.Parser.start()
|
|
29
|
+
.uint8('isPublic')
|
|
30
|
+
.uint8('assetModifier')
|
|
31
|
+
.nest('argsLength', {
|
|
32
|
+
type: compact_int_codec_1.compactUnsignedIntCodec.parser
|
|
33
|
+
})
|
|
34
|
+
.nest('localsLength', {
|
|
35
|
+
type: compact_int_codec_1.compactUnsignedIntCodec.parser
|
|
36
|
+
})
|
|
37
|
+
.nest('returnLength', {
|
|
38
|
+
type: compact_int_codec_1.compactUnsignedIntCodec.parser
|
|
39
|
+
})
|
|
40
|
+
.nest('instrs', {
|
|
41
|
+
type: instr_codec_1.instrsCodec.parser
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
encode(input) {
|
|
45
|
+
const result = [input.isPublic, input.assetModifier];
|
|
46
|
+
result.push(...compact_int_codec_1.compactUnsignedIntCodec.encode(input.argsLength));
|
|
47
|
+
result.push(...compact_int_codec_1.compactUnsignedIntCodec.encode(input.localsLength));
|
|
48
|
+
result.push(...compact_int_codec_1.compactUnsignedIntCodec.encode(input.returnLength));
|
|
49
|
+
result.push(...instr_codec_1.instrsCodec.encode(input.instrs.value));
|
|
50
|
+
return buffer_1.Buffer.from(result);
|
|
51
|
+
}
|
|
52
|
+
decode(input) {
|
|
53
|
+
return this.parser.parse(input);
|
|
54
|
+
}
|
|
55
|
+
static toMethod(decodedMethod) {
|
|
56
|
+
return {
|
|
57
|
+
isPublic: decodedMethod.isPublic === 1,
|
|
58
|
+
assetModifier: decodedMethod.assetModifier,
|
|
59
|
+
argsLength: compact_int_codec_1.compactUnsignedIntCodec.toU32(decodedMethod.argsLength),
|
|
60
|
+
localsLength: compact_int_codec_1.compactUnsignedIntCodec.toU32(decodedMethod.localsLength),
|
|
61
|
+
returnLength: compact_int_codec_1.compactUnsignedIntCodec.toU32(decodedMethod.returnLength),
|
|
62
|
+
instrs: decodedMethod.instrs.value
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
static fromMethod(method) {
|
|
66
|
+
return {
|
|
67
|
+
isPublic: method.isPublic ? 1 : 0,
|
|
68
|
+
assetModifier: method.assetModifier,
|
|
69
|
+
argsLength: compact_int_codec_1.compactUnsignedIntCodec.fromU32(method.argsLength),
|
|
70
|
+
localsLength: compact_int_codec_1.compactUnsignedIntCodec.fromU32(method.localsLength),
|
|
71
|
+
returnLength: compact_int_codec_1.compactUnsignedIntCodec.fromU32(method.returnLength),
|
|
72
|
+
instrs: instr_codec_1.instrsCodec.fromArray(method.instrs)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.MethodCodec = MethodCodec;
|
|
77
|
+
exports.methodCodec = new MethodCodec();
|
|
78
|
+
exports.methodsCodec = new array_codec_1.ArrayCodec(exports.methodCodec);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
|
+
import { Parser } from 'binary-parser';
|
|
3
|
+
import { Codec } from './codec';
|
|
4
|
+
export interface Option<T> {
|
|
5
|
+
option: number;
|
|
6
|
+
value?: T;
|
|
7
|
+
}
|
|
8
|
+
export declare class OptionCodec<T> implements Codec<Option<T>> {
|
|
9
|
+
private childCodec;
|
|
10
|
+
parser: Parser;
|
|
11
|
+
constructor(childCodec: Codec<T>, parser?: Parser);
|
|
12
|
+
encode(input: Option<T>): Buffer;
|
|
13
|
+
decode(input: Buffer): Option<T>;
|
|
14
|
+
fromBuffer(input?: Buffer): Option<T>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OptionCodec = 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 buffer_1 = require("buffer/");
|
|
22
|
+
const binary_parser_1 = require("binary-parser");
|
|
23
|
+
class OptionCodec {
|
|
24
|
+
constructor(childCodec, parser = new binary_parser_1.Parser().uint8('option').choice('value', {
|
|
25
|
+
tag: 'option',
|
|
26
|
+
choices: {
|
|
27
|
+
0: new binary_parser_1.Parser(),
|
|
28
|
+
1: childCodec.parser
|
|
29
|
+
}
|
|
30
|
+
})) {
|
|
31
|
+
this.childCodec = childCodec;
|
|
32
|
+
this.parser = parser;
|
|
33
|
+
}
|
|
34
|
+
encode(input) {
|
|
35
|
+
const result = [input.option];
|
|
36
|
+
if (input.option === 1) {
|
|
37
|
+
result.push(...this.childCodec.encode(input.value));
|
|
38
|
+
}
|
|
39
|
+
return buffer_1.Buffer.from(result);
|
|
40
|
+
}
|
|
41
|
+
decode(input) {
|
|
42
|
+
const result = this.parser.parse(input);
|
|
43
|
+
return {
|
|
44
|
+
...result,
|
|
45
|
+
value: result.option ? this.childCodec.decode(result.value.value) : undefined
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
fromBuffer(input) {
|
|
49
|
+
return {
|
|
50
|
+
option: input ? 1 : 0,
|
|
51
|
+
value: input ? this.childCodec.decode(input) : undefined
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.OptionCodec = OptionCodec;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ArrayCodec } from './array-codec';
|
|
2
|
+
import { Either, EitherCodec } from './either-codec';
|
|
3
|
+
import { AssetOutput } from './asset-output-codec';
|
|
4
|
+
import { ContractOutput } from './contract-output-codec';
|
|
5
|
+
export type Output = Either<AssetOutput, ContractOutput>;
|
|
6
|
+
export declare const outputCodec: EitherCodec<AssetOutput, ContractOutput>;
|
|
7
|
+
export declare const outputsCodec: ArrayCodec<Either<AssetOutput, ContractOutput>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
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.outputsCodec = exports.outputCodec = void 0;
|
|
21
|
+
const array_codec_1 = require("./array-codec");
|
|
22
|
+
const either_codec_1 = require("./either-codec");
|
|
23
|
+
const asset_output_codec_1 = require("./asset-output-codec");
|
|
24
|
+
const contract_output_codec_1 = require("./contract-output-codec");
|
|
25
|
+
exports.outputCodec = new either_codec_1.EitherCodec(asset_output_codec_1.assetOutputCodec, contract_output_codec_1.contractOutputCodec);
|
|
26
|
+
exports.outputsCodec = new array_codec_1.ArrayCodec(exports.outputCodec);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
|
+
import { Parser } from 'binary-parser';
|
|
3
|
+
import { DecodedArray } from './array-codec';
|
|
4
|
+
import { Codec } from './codec';
|
|
5
|
+
import { DecodedMethod } from './method-codec';
|
|
6
|
+
import { OptionCodec } from './option-codec';
|
|
7
|
+
export interface Script {
|
|
8
|
+
methods: DecodedArray<DecodedMethod>;
|
|
9
|
+
}
|
|
10
|
+
export declare class ScriptCodec implements Codec<Script> {
|
|
11
|
+
parser: Parser;
|
|
12
|
+
encode(input: Script): Buffer;
|
|
13
|
+
decode(input: Buffer): Script;
|
|
14
|
+
}
|
|
15
|
+
export declare const scriptCodec: ScriptCodec;
|
|
16
|
+
export declare const statefulScriptCodecOpt: OptionCodec<Script>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.statefulScriptCodecOpt = exports.scriptCodec = exports.ScriptCodec = 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 buffer_1 = require("buffer/");
|
|
22
|
+
const binary_parser_1 = require("binary-parser");
|
|
23
|
+
const method_codec_1 = require("./method-codec");
|
|
24
|
+
const option_codec_1 = require("./option-codec");
|
|
25
|
+
class ScriptCodec {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.parser = binary_parser_1.Parser.start().nest('methods', {
|
|
28
|
+
type: method_codec_1.methodsCodec.parser
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
encode(input) {
|
|
32
|
+
const script = method_codec_1.methodsCodec.encode(input.methods.value);
|
|
33
|
+
return buffer_1.Buffer.from(script);
|
|
34
|
+
}
|
|
35
|
+
decode(input) {
|
|
36
|
+
return this.parser.parse(input);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.ScriptCodec = ScriptCodec;
|
|
40
|
+
exports.scriptCodec = new ScriptCodec();
|
|
41
|
+
exports.statefulScriptCodecOpt = new option_codec_1.OptionCodec(exports.scriptCodec);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
|
+
import { Parser } from 'binary-parser';
|
|
3
|
+
import { ArrayCodec } from './array-codec';
|
|
4
|
+
import { Codec } from './codec';
|
|
5
|
+
export interface Signature {
|
|
6
|
+
value: Buffer;
|
|
7
|
+
}
|
|
8
|
+
export declare class SignatureCodec implements Codec<Signature> {
|
|
9
|
+
parser: Parser;
|
|
10
|
+
encode(input: Signature): Buffer;
|
|
11
|
+
decode(input: Buffer): Signature;
|
|
12
|
+
}
|
|
13
|
+
export declare const signatureCodec: SignatureCodec;
|
|
14
|
+
export declare const signaturesCodec: ArrayCodec<Signature>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signaturesCodec = exports.signatureCodec = exports.SignatureCodec = void 0;
|
|
4
|
+
const binary_parser_1 = require("binary-parser");
|
|
5
|
+
const array_codec_1 = require("./array-codec");
|
|
6
|
+
class SignatureCodec {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.parser = binary_parser_1.Parser.start().buffer('value', { length: 64 });
|
|
9
|
+
}
|
|
10
|
+
encode(input) {
|
|
11
|
+
return input.value;
|
|
12
|
+
}
|
|
13
|
+
decode(input) {
|
|
14
|
+
return this.parser.parse(input);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.SignatureCodec = SignatureCodec;
|
|
18
|
+
exports.signatureCodec = new SignatureCodec();
|
|
19
|
+
exports.signaturesCodec = new array_codec_1.ArrayCodec(exports.signatureCodec);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Parser } from 'binary-parser';
|
|
2
|
+
import { Codec } from './codec';
|
|
3
|
+
import { Buffer } from 'buffer/';
|
|
4
|
+
export declare class SignedIntCodec implements Codec<number> {
|
|
5
|
+
parser: Parser;
|
|
6
|
+
encode(value: number): Buffer;
|
|
7
|
+
decode(bytes: Buffer): number;
|
|
8
|
+
}
|
|
9
|
+
export declare const signedIntCodec: SignedIntCodec;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signedIntCodec = exports.SignedIntCodec = 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
|
+
const buffer_1 = require("buffer/");
|
|
24
|
+
class SignedIntCodec {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.parser = binary_parser_1.Parser.start().buffer('value', {
|
|
27
|
+
length: 4
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
encode(value) {
|
|
31
|
+
return buffer_1.Buffer.from([(value >> 24) & 0xff, (value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff]);
|
|
32
|
+
}
|
|
33
|
+
decode(bytes) {
|
|
34
|
+
(0, codec_1.assert)(bytes.length === 4, 'Length should be 4');
|
|
35
|
+
return ((bytes[0] & 0xff) << 24) | ((bytes[1] & 0xff) << 16) | ((bytes[2] & 0xff) << 8) | (bytes[3] & 0xff);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.SignedIntCodec = SignedIntCodec;
|
|
39
|
+
exports.signedIntCodec = new SignedIntCodec();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
|
+
import { Parser } from 'binary-parser';
|
|
3
|
+
import { DecodedCompactInt } from './compact-int-codec';
|
|
4
|
+
import { Codec } from './codec';
|
|
5
|
+
import { ArrayCodec } from './array-codec';
|
|
6
|
+
export interface Token {
|
|
7
|
+
tokenId: Buffer;
|
|
8
|
+
amount: DecodedCompactInt;
|
|
9
|
+
}
|
|
10
|
+
export declare class TokenCodec implements Codec<Token> {
|
|
11
|
+
parser: Parser;
|
|
12
|
+
encode(input: Token): Buffer;
|
|
13
|
+
decode(input: Buffer): Token;
|
|
14
|
+
}
|
|
15
|
+
export declare const tokenCodec: TokenCodec;
|
|
16
|
+
export declare const tokensCodec: ArrayCodec<Token>;
|
|
@@ -0,0 +1,46 @@
|
|
|
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.tokensCodec = exports.tokenCodec = exports.TokenCodec = void 0;
|
|
21
|
+
const buffer_1 = require("buffer/");
|
|
22
|
+
const binary_parser_1 = require("binary-parser");
|
|
23
|
+
const compact_int_codec_1 = require("./compact-int-codec");
|
|
24
|
+
const array_codec_1 = require("./array-codec");
|
|
25
|
+
class TokenCodec {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.parser = binary_parser_1.Parser.start()
|
|
28
|
+
.buffer('tokenId', {
|
|
29
|
+
length: 32
|
|
30
|
+
})
|
|
31
|
+
.nest('amount', {
|
|
32
|
+
type: compact_int_codec_1.compactUnsignedIntCodec.parser
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
encode(input) {
|
|
36
|
+
const tokenId = input.tokenId;
|
|
37
|
+
const amount = buffer_1.Buffer.from(compact_int_codec_1.compactUnsignedIntCodec.encode(input.amount));
|
|
38
|
+
return buffer_1.Buffer.concat([tokenId, amount]);
|
|
39
|
+
}
|
|
40
|
+
decode(input) {
|
|
41
|
+
return this.parser.parse(input);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.TokenCodec = TokenCodec;
|
|
45
|
+
exports.tokenCodec = new TokenCodec();
|
|
46
|
+
exports.tokensCodec = new array_codec_1.ArrayCodec(exports.tokenCodec);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
|
+
import { Parser } from 'binary-parser';
|
|
3
|
+
import { DecodedArray } from './array-codec';
|
|
4
|
+
import { UnsignedTx } from './unsigned-tx-codec';
|
|
5
|
+
import { Signature } from './signature-codec';
|
|
6
|
+
import { ContractOutputRef } from './contract-output-ref-codec';
|
|
7
|
+
import { Transaction as ApiTransaction } from '../api/api-alephium';
|
|
8
|
+
import { Codec } from './codec';
|
|
9
|
+
import { Output } from './output-codec';
|
|
10
|
+
export interface Transaction {
|
|
11
|
+
unsigned: UnsignedTx;
|
|
12
|
+
scriptExecutionOk: number;
|
|
13
|
+
contractInputs: DecodedArray<ContractOutputRef>;
|
|
14
|
+
generatedOutputs: DecodedArray<Output>;
|
|
15
|
+
inputSignatures: DecodedArray<Signature>;
|
|
16
|
+
scriptSignatures: DecodedArray<Signature>;
|
|
17
|
+
}
|
|
18
|
+
export declare class TransactionCodec implements Codec<Transaction> {
|
|
19
|
+
parser: Parser;
|
|
20
|
+
encode(decodedTx: Transaction): Buffer;
|
|
21
|
+
decode(input: Buffer): Transaction;
|
|
22
|
+
encodeApiTransaction(input: ApiTransaction): Buffer;
|
|
23
|
+
decodeApiTransaction(input: Buffer): ApiTransaction;
|
|
24
|
+
static toApiTransaction(transaction: Transaction): ApiTransaction;
|
|
25
|
+
static fromApiTransaction(tx: ApiTransaction): Transaction;
|
|
26
|
+
}
|
|
27
|
+
export declare const transactionCodec: TransactionCodec;
|
|
@@ -0,0 +1,128 @@
|
|
|
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.transactionCodec = exports.TransactionCodec = void 0;
|
|
21
|
+
const buffer_1 = require("buffer/");
|
|
22
|
+
const binary_parser_1 = require("binary-parser");
|
|
23
|
+
const unsigned_tx_codec_1 = require("./unsigned-tx-codec");
|
|
24
|
+
const signature_codec_1 = require("./signature-codec");
|
|
25
|
+
const contract_output_ref_codec_1 = require("./contract-output-ref-codec");
|
|
26
|
+
const asset_output_codec_1 = require("./asset-output-codec");
|
|
27
|
+
const contract_output_codec_1 = require("./contract-output-codec");
|
|
28
|
+
const __1 = require("..");
|
|
29
|
+
const output_codec_1 = require("./output-codec");
|
|
30
|
+
class TransactionCodec {
|
|
31
|
+
constructor() {
|
|
32
|
+
this.parser = new binary_parser_1.Parser()
|
|
33
|
+
.nest('unsigned', {
|
|
34
|
+
type: unsigned_tx_codec_1.unsignedTxCodec.parser
|
|
35
|
+
})
|
|
36
|
+
.uint8('scriptExecutionOk')
|
|
37
|
+
.nest('contractInputs', {
|
|
38
|
+
type: contract_output_ref_codec_1.contractOutputRefsCodec.parser
|
|
39
|
+
})
|
|
40
|
+
.nest('generatedOutputs', {
|
|
41
|
+
type: output_codec_1.outputsCodec.parser
|
|
42
|
+
})
|
|
43
|
+
.nest('inputSignatures', {
|
|
44
|
+
type: signature_codec_1.signaturesCodec.parser
|
|
45
|
+
})
|
|
46
|
+
.nest('scriptSignatures', {
|
|
47
|
+
type: signature_codec_1.signaturesCodec.parser
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
encode(decodedTx) {
|
|
51
|
+
return buffer_1.Buffer.concat([
|
|
52
|
+
unsigned_tx_codec_1.unsignedTxCodec.encode(decodedTx.unsigned),
|
|
53
|
+
buffer_1.Buffer.from([decodedTx.scriptExecutionOk]),
|
|
54
|
+
buffer_1.Buffer.from([...contract_output_ref_codec_1.contractOutputRefsCodec.encode(decodedTx.contractInputs.value)]),
|
|
55
|
+
buffer_1.Buffer.from([...output_codec_1.outputsCodec.encode(decodedTx.generatedOutputs.value)]),
|
|
56
|
+
buffer_1.Buffer.from([...signature_codec_1.signaturesCodec.encode(decodedTx.inputSignatures.value)]),
|
|
57
|
+
buffer_1.Buffer.from([...signature_codec_1.signaturesCodec.encode(decodedTx.scriptSignatures.value)])
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
decode(input) {
|
|
61
|
+
return this.parser.parse(input);
|
|
62
|
+
}
|
|
63
|
+
encodeApiTransaction(input) {
|
|
64
|
+
const decodedTx = TransactionCodec.fromApiTransaction(input);
|
|
65
|
+
return this.encode(decodedTx);
|
|
66
|
+
}
|
|
67
|
+
decodeApiTransaction(input) {
|
|
68
|
+
const decodedTx = this.parser.parse(input);
|
|
69
|
+
return TransactionCodec.toApiTransaction(decodedTx);
|
|
70
|
+
}
|
|
71
|
+
static toApiTransaction(transaction) {
|
|
72
|
+
const txId = unsigned_tx_codec_1.UnsignedTxCodec.txId(transaction.unsigned);
|
|
73
|
+
const unsigned = unsigned_tx_codec_1.UnsignedTxCodec.toApiUnsignedTx(transaction.unsigned);
|
|
74
|
+
const scriptExecutionOk = !!transaction.scriptExecutionOk;
|
|
75
|
+
const contractInputs = transaction.contractInputs.value.map((contractInput) => {
|
|
76
|
+
const hint = contractInput.hint;
|
|
77
|
+
const key = contractInput.key.toString('hex');
|
|
78
|
+
return { hint, key };
|
|
79
|
+
});
|
|
80
|
+
const txIdBytes = (0, __1.hexToBinUnsafe)(txId);
|
|
81
|
+
const generatedOutputs = transaction.generatedOutputs.value.map((output, index) => {
|
|
82
|
+
if (output.either === 0) {
|
|
83
|
+
const fixedAssetOutput = asset_output_codec_1.AssetOutputCodec.toFixedAssetOutput(txIdBytes, output.value, index);
|
|
84
|
+
return { ...fixedAssetOutput, type: 'AssetOutput' };
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return contract_output_codec_1.ContractOutputCodec.convertToApiContractOutput(txIdBytes, output.value, index);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const inputSignatures = transaction.inputSignatures.value.map((signature) => signature.value.toString('hex'));
|
|
91
|
+
const scriptSignatures = transaction.scriptSignatures.value.map((signature) => signature.value.toString('hex'));
|
|
92
|
+
return { unsigned, scriptExecutionOk, contractInputs, generatedOutputs, inputSignatures, scriptSignatures };
|
|
93
|
+
}
|
|
94
|
+
static fromApiTransaction(tx) {
|
|
95
|
+
const unsigned = unsigned_tx_codec_1.UnsignedTxCodec.fromApiUnsignedTx(tx.unsigned);
|
|
96
|
+
const scriptExecutionOk = tx.scriptExecutionOk ? 1 : 0;
|
|
97
|
+
const contractInputs = tx.contractInputs.map((contractInput) => {
|
|
98
|
+
return { hint: contractInput.hint, key: buffer_1.Buffer.from(contractInput.key, 'hex') };
|
|
99
|
+
});
|
|
100
|
+
const generatedOutputs = tx.generatedOutputs.map((output) => {
|
|
101
|
+
if (output.type === 'AssetOutput') {
|
|
102
|
+
return output_codec_1.outputCodec.fromLeft(asset_output_codec_1.AssetOutputCodec.fromFixedAssetOutput(output));
|
|
103
|
+
}
|
|
104
|
+
else if (output.type === 'ContractOutput') {
|
|
105
|
+
return output_codec_1.outputCodec.fromRight(contract_output_codec_1.ContractOutputCodec.convertToOutput(output));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw new Error('Invalid output type');
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const inputSignatures = tx.inputSignatures.map((signature) => {
|
|
112
|
+
return { value: buffer_1.Buffer.from(signature, 'hex') };
|
|
113
|
+
});
|
|
114
|
+
const scriptSignatures = tx.scriptSignatures.map((signature) => {
|
|
115
|
+
return { value: buffer_1.Buffer.from(signature, 'hex') };
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
unsigned,
|
|
119
|
+
scriptExecutionOk,
|
|
120
|
+
contractInputs: contract_output_ref_codec_1.contractOutputRefsCodec.fromArray(contractInputs),
|
|
121
|
+
generatedOutputs: output_codec_1.outputsCodec.fromArray(generatedOutputs),
|
|
122
|
+
inputSignatures: signature_codec_1.signaturesCodec.fromArray(inputSignatures),
|
|
123
|
+
scriptSignatures: signature_codec_1.signaturesCodec.fromArray(scriptSignatures)
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.TransactionCodec = TransactionCodec;
|
|
128
|
+
exports.transactionCodec = new TransactionCodec();
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
|
+
import { Parser } from 'binary-parser';
|
|
3
|
+
import { DecodedArray } from './array-codec';
|
|
4
|
+
import { DecodedCompactInt } from './compact-int-codec';
|
|
5
|
+
import { Codec } from './codec';
|
|
6
|
+
import { Script } from './script-codec';
|
|
7
|
+
import { ByteString } from './bytestring-codec';
|
|
8
|
+
import { LockupScript } from './lockup-script-codec';
|
|
9
|
+
export interface P2PKH {
|
|
10
|
+
publicKey: Buffer;
|
|
11
|
+
}
|
|
12
|
+
export interface P2MPKH {
|
|
13
|
+
publicKeys: DecodedArray<{
|
|
14
|
+
publicKey: P2PKH;
|
|
15
|
+
index: DecodedCompactInt;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
export interface Val {
|
|
19
|
+
type: number;
|
|
20
|
+
val: number | DecodedCompactInt | ByteString | LockupScript;
|
|
21
|
+
}
|
|
22
|
+
export interface P2SH {
|
|
23
|
+
script: Script;
|
|
24
|
+
params: DecodedArray<Val>;
|
|
25
|
+
}
|
|
26
|
+
export declare class P2SHCodec implements Codec<P2SH> {
|
|
27
|
+
parser: Parser;
|
|
28
|
+
encode(input: P2SH): Buffer;
|
|
29
|
+
decode(input: Buffer): P2SH;
|
|
30
|
+
}
|
|
31
|
+
export interface UnlockScript {
|
|
32
|
+
scriptType: number;
|
|
33
|
+
script: P2PKH | P2MPKH | P2SH;
|
|
34
|
+
}
|
|
35
|
+
export declare class UnlockScriptCodec implements Codec<UnlockScript> {
|
|
36
|
+
parser: Parser;
|
|
37
|
+
encode(input: UnlockScript): Buffer;
|
|
38
|
+
decode(input: Buffer): UnlockScript;
|
|
39
|
+
}
|
|
40
|
+
export declare const unlockScriptCodec: UnlockScriptCodec;
|