@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.
Files changed (106) hide show
  1. package/dist/alephium-web3.min.js +1 -1
  2. package/dist/alephium-web3.min.js.map +1 -1
  3. package/dist/src/address/address.js +5 -5
  4. package/dist/src/api/api-alephium.d.ts +1 -1
  5. package/dist/src/api/api-alephium.js +1 -1
  6. package/dist/src/codec/array-codec.d.ts +4 -12
  7. package/dist/src/codec/array-codec.js +15 -28
  8. package/dist/src/codec/asset-output-codec.d.ts +6 -11
  9. package/dist/src/codec/asset-output-codec.js +32 -71
  10. package/dist/src/codec/bigint-codec.d.ts +2 -1
  11. package/dist/src/codec/bigint-codec.js +14 -2
  12. package/dist/src/codec/bytestring-codec.d.ts +6 -11
  13. package/dist/src/codec/bytestring-codec.js +9 -23
  14. package/dist/src/codec/codec.d.ts +54 -5
  15. package/dist/src/codec/codec.js +112 -14
  16. package/dist/src/codec/compact-int-codec.d.ts +65 -44
  17. package/dist/src/codec/compact-int-codec.js +222 -204
  18. package/dist/src/codec/contract-codec.d.ts +5 -8
  19. package/dist/src/codec/contract-codec.js +15 -29
  20. package/dist/src/codec/contract-output-codec.d.ts +4 -10
  21. package/dist/src/codec/contract-output-codec.js +20 -40
  22. package/dist/src/codec/contract-output-ref-codec.d.ts +2 -8
  23. package/dist/src/codec/contract-output-ref-codec.js +7 -17
  24. package/dist/src/codec/either-codec.d.ts +8 -15
  25. package/dist/src/codec/either-codec.js +5 -46
  26. package/dist/src/codec/index.d.ts +4 -3
  27. package/dist/src/codec/index.js +7 -4
  28. package/dist/src/codec/input-codec.d.ts +4 -10
  29. package/dist/src/codec/input-codec.js +11 -46
  30. package/dist/src/codec/instr-codec.d.ts +633 -40
  31. package/dist/src/codec/instr-codec.js +1040 -434
  32. package/dist/src/codec/int-as-4bytes-codec.d.ts +7 -0
  33. package/dist/src/codec/{signed-int-codec.js → int-as-4bytes-codec.js} +6 -12
  34. package/dist/src/codec/lockup-script-codec.d.ts +23 -26
  35. package/dist/src/codec/lockup-script-codec.js +12 -58
  36. package/dist/src/codec/method-codec.d.ts +6 -18
  37. package/dist/src/codec/method-codec.js +20 -48
  38. package/dist/src/codec/option-codec.d.ts +8 -13
  39. package/dist/src/codec/option-codec.js +14 -32
  40. package/dist/src/codec/output-codec.d.ts +2 -2
  41. package/dist/src/codec/output-codec.js +1 -1
  42. package/dist/src/codec/reader.d.ts +8 -0
  43. package/dist/src/codec/reader.js +48 -0
  44. package/dist/src/codec/script-codec.d.ts +6 -14
  45. package/dist/src/codec/script-codec.js +6 -22
  46. package/dist/src/codec/signature-codec.d.ts +4 -12
  47. package/dist/src/codec/signature-codec.js +3 -15
  48. package/dist/src/codec/timestamp-codec.d.ts +8 -0
  49. package/dist/src/codec/timestamp-codec.js +39 -0
  50. package/dist/src/codec/token-codec.d.ts +3 -10
  51. package/dist/src/codec/token-codec.js +6 -24
  52. package/dist/src/codec/transaction-codec.d.ts +6 -11
  53. package/dist/src/codec/transaction-codec.js +24 -49
  54. package/dist/src/codec/unlock-script-codec.d.ts +25 -36
  55. package/dist/src/codec/unlock-script-codec.js +26 -147
  56. package/dist/src/codec/unsigned-tx-codec.d.ts +8 -14
  57. package/dist/src/codec/unsigned-tx-codec.js +24 -66
  58. package/dist/src/codec/val.d.ts +27 -0
  59. package/dist/src/codec/val.js +33 -0
  60. package/dist/src/contract/contract.js +6 -6
  61. package/dist/src/contract/index.d.ts +1 -0
  62. package/dist/src/contract/index.js +1 -0
  63. package/dist/src/contract/ralph.d.ts +0 -4
  64. package/dist/src/contract/ralph.js +50 -179
  65. package/dist/src/contract/script-simulator.d.ts +27 -0
  66. package/dist/src/contract/script-simulator.js +757 -0
  67. package/dist/src/exchange/exchange.js +1 -1
  68. package/package.json +3 -4
  69. package/src/address/address.ts +8 -8
  70. package/src/api/api-alephium.ts +1 -1
  71. package/src/codec/array-codec.ts +16 -34
  72. package/src/codec/asset-output-codec.ts +38 -83
  73. package/src/codec/bigint-codec.ts +16 -2
  74. package/src/codec/bytestring-codec.ts +10 -28
  75. package/src/codec/codec.ts +121 -15
  76. package/src/codec/compact-int-codec.ts +230 -207
  77. package/src/codec/contract-codec.ts +20 -33
  78. package/src/codec/contract-output-codec.ts +22 -48
  79. package/src/codec/contract-output-ref-codec.ts +6 -17
  80. package/src/codec/either-codec.ts +4 -53
  81. package/src/codec/index.ts +4 -3
  82. package/src/codec/input-codec.ts +14 -36
  83. package/src/codec/instr-codec.ts +1229 -455
  84. package/src/codec/{signed-int-codec.ts → int-as-4bytes-codec.ts} +6 -10
  85. package/src/codec/lockup-script-codec.ts +28 -76
  86. package/src/codec/method-codec.ts +23 -61
  87. package/src/codec/option-codec.ts +13 -36
  88. package/src/codec/output-codec.ts +2 -2
  89. package/src/codec/reader.ts +56 -0
  90. package/src/codec/script-codec.ts +9 -31
  91. package/src/codec/signature-codec.ts +3 -18
  92. package/src/codec/timestamp-codec.ts +42 -0
  93. package/src/codec/token-codec.ts +7 -26
  94. package/src/codec/transaction-codec.ts +29 -58
  95. package/src/codec/unlock-script-codec.ts +44 -171
  96. package/src/codec/unsigned-tx-codec.ts +34 -63
  97. package/src/codec/val.ts +40 -0
  98. package/src/contract/contract.ts +9 -13
  99. package/src/contract/index.ts +1 -0
  100. package/src/contract/ralph.ts +76 -172
  101. package/src/contract/script-simulator.ts +838 -0
  102. package/src/exchange/exchange.ts +1 -1
  103. package/dist/src/codec/long-codec.d.ts +0 -8
  104. package/dist/src/codec/long-codec.js +0 -55
  105. package/dist/src/codec/signed-int-codec.d.ts +0 -8
  106. package/src/codec/long-codec.ts +0 -58
@@ -18,49 +18,38 @@ 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.contractCodec = exports.ContractCodec = void 0;
21
- const binary_parser_1 = require("binary-parser");
22
21
  const array_codec_1 = require("./array-codec");
22
+ const codec_1 = require("./codec");
23
23
  const compact_int_codec_1 = require("./compact-int-codec");
24
24
  const method_codec_1 = require("./method-codec");
25
25
  const utils_1 = require("../utils");
26
- const compactSignedIntsCodec = new array_codec_1.ArrayCodec(compact_int_codec_1.compactSignedIntCodec);
27
- class ContractCodec {
28
- constructor() {
29
- this.parser = binary_parser_1.Parser.start()
30
- .nest('fieldLength', {
31
- type: compact_int_codec_1.compactSignedIntCodec.parser
32
- })
33
- .nest('methodIndexes', {
34
- type: compactSignedIntsCodec.parser
35
- })
36
- .buffer('methods', { readUntil: 'eof' });
37
- }
26
+ const i32sCodec = new array_codec_1.ArrayCodec(compact_int_codec_1.i32Codec);
27
+ class ContractCodec extends codec_1.Codec {
38
28
  encode(input) {
39
- return (0, utils_1.concatBytes)([
40
- compact_int_codec_1.compactSignedIntCodec.encode(input.fieldLength),
41
- compactSignedIntsCodec.encode(input.methodIndexes.value),
42
- input.methods
43
- ]);
29
+ return (0, utils_1.concatBytes)([compact_int_codec_1.i32Codec.encode(input.fieldLength), i32sCodec.encode(input.methodIndexes), input.methods]);
44
30
  }
45
- decode(input) {
46
- return this.parser.parse(input);
31
+ _decode(input) {
32
+ const fieldLength = compact_int_codec_1.i32Codec._decode(input);
33
+ const methodIndexes = i32sCodec._decode(input);
34
+ const methods = input.consumeAll();
35
+ return { fieldLength, methodIndexes, methods };
47
36
  }
48
37
  decodeContract(input) {
49
38
  const halfDecoded = this.decode(input);
50
- const fieldLength = compact_int_codec_1.compactSignedIntCodec.toI32(halfDecoded.fieldLength);
51
- const methodIndexes = halfDecoded.methodIndexes.value.map((v) => compact_int_codec_1.compactSignedIntCodec.toI32(v));
39
+ const fieldLength = halfDecoded.fieldLength;
40
+ const methodIndexes = halfDecoded.methodIndexes;
52
41
  const methods = [];
53
42
  for (let i = 0, start = 0; i < methodIndexes.length; i++) {
54
43
  const end = methodIndexes[i];
55
- const method = method_codec_1.MethodCodec.toMethod(method_codec_1.methodCodec.decode(halfDecoded.methods.slice(start, end)));
44
+ const method = method_codec_1.methodCodec.decode(halfDecoded.methods.slice(start, end));
56
45
  methods.push(method);
57
46
  start = end;
58
47
  }
59
48
  return { fieldLength, methods };
60
49
  }
61
50
  encodeContract(contract) {
62
- const fieldLength = compact_int_codec_1.compactSignedIntCodec.fromI32(contract.fieldLength);
63
- const methods = contract.methods.map((m) => method_codec_1.methodCodec.encode(method_codec_1.MethodCodec.fromMethod(m)));
51
+ const fieldLength = contract.fieldLength;
52
+ const methods = contract.methods.map((m) => method_codec_1.methodCodec.encode(m));
64
53
  let count = 0;
65
54
  const methodIndexes = Array.from(Array(methods.length).keys()).map((index) => {
66
55
  count += methods[`${index}`].length;
@@ -68,10 +57,7 @@ class ContractCodec {
68
57
  });
69
58
  const halfDecoded = {
70
59
  fieldLength,
71
- methodIndexes: {
72
- length: compact_int_codec_1.compactSignedIntCodec.fromI32(methodIndexes.length),
73
- value: methodIndexes.map((value) => compact_int_codec_1.compactSignedIntCodec.fromI32(value))
74
- },
60
+ methodIndexes: methodIndexes,
75
61
  methods: (0, utils_1.concatBytes)(methods)
76
62
  };
77
63
  return this.encode(halfDecoded);
@@ -1,19 +1,13 @@
1
- import { Parser } from 'binary-parser';
2
- import { DecodedArray } from './array-codec';
3
- import { DecodedCompactInt } from './compact-int-codec';
4
1
  import { P2C } from './lockup-script-codec';
5
- import { Codec } from './codec';
2
+ import { ObjectCodec } from './codec';
6
3
  import { Token } from './token-codec';
7
4
  import { ContractOutput as ApiContractOutput } from '../api/api-alephium';
8
5
  export interface ContractOutput {
9
- amount: DecodedCompactInt;
6
+ amount: bigint;
10
7
  lockupScript: P2C;
11
- tokens: DecodedArray<Token>;
8
+ tokens: Token[];
12
9
  }
13
- export declare class ContractOutputCodec implements Codec<ContractOutput> {
14
- parser: Parser;
15
- encode(input: ContractOutput): Uint8Array;
16
- decode(input: Uint8Array): ContractOutput;
10
+ export declare class ContractOutputCodec extends ObjectCodec<ContractOutput> {
17
11
  static convertToApiContractOutput(txIdBytes: Uint8Array, output: ContractOutput, index: number): ApiContractOutput;
18
12
  static convertToOutput(apiContractOutput: ApiContractOutput): ContractOutput;
19
13
  }
@@ -18,63 +18,43 @@ 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");
22
+ const lockup_script_codec_1 = require("./lockup-script-codec");
23
+ const codec_1 = require("./codec");
23
24
  const token_codec_1 = require("./token-codec");
24
25
  const hash_1 = require("./hash");
25
26
  const utils_1 = require("../utils");
26
- const signed_int_codec_1 = require("./signed-int-codec");
27
- const lockup_script_codec_1 = require("./lockup-script-codec");
28
- class ContractOutputCodec {
29
- constructor() {
30
- this.parser = binary_parser_1.Parser.start()
31
- .nest('amount', {
32
- type: compact_int_codec_1.compactUnsignedIntCodec.parser
33
- })
34
- .nest('lockupScript', {
35
- type: binary_parser_1.Parser.start().buffer('contractId', { length: 32 })
36
- })
37
- .nest('tokens', {
38
- type: token_codec_1.tokensCodec.parser
39
- });
40
- }
41
- encode(input) {
42
- const amount = compact_int_codec_1.compactUnsignedIntCodec.encode(input.amount);
43
- const lockupScript = input.lockupScript.contractId;
44
- const tokens = token_codec_1.tokensCodec.encode(input.tokens.value);
45
- return (0, utils_1.concatBytes)([amount, lockupScript, tokens]);
46
- }
47
- decode(input) {
48
- return this.parser.parse(input);
49
- }
27
+ const int_as_4bytes_codec_1 = require("./int-as-4bytes-codec");
28
+ const lockup_script_codec_2 = require("./lockup-script-codec");
29
+ class ContractOutputCodec extends codec_1.ObjectCodec {
50
30
  static convertToApiContractOutput(txIdBytes, output, index) {
51
- const hint = (0, hash_1.createHint)(output.lockupScript.contractId);
52
- const key = (0, utils_1.binToHex)((0, hash_1.blakeHash)((0, utils_1.concatBytes)([txIdBytes, signed_int_codec_1.signedIntCodec.encode(index)])));
53
- const attoAlphAmount = compact_int_codec_1.compactUnsignedIntCodec.toU256(output.amount).toString();
54
- const address = utils_1.bs58.encode(new Uint8Array([0x03, ...output.lockupScript.contractId]));
55
- const tokens = output.tokens.value.map((token) => {
31
+ const hint = (0, hash_1.createHint)(output.lockupScript);
32
+ const key = (0, utils_1.binToHex)((0, hash_1.blakeHash)((0, utils_1.concatBytes)([txIdBytes, int_as_4bytes_codec_1.intAs4BytesCodec.encode(index)])));
33
+ const attoAlphAmount = output.amount.toString();
34
+ const address = utils_1.bs58.encode(new Uint8Array([0x03, ...output.lockupScript]));
35
+ const tokens = output.tokens.map((token) => {
56
36
  return {
57
37
  id: (0, utils_1.binToHex)(token.tokenId),
58
- amount: compact_int_codec_1.compactUnsignedIntCodec.toU256(token.amount).toString()
38
+ amount: token.amount.toString()
59
39
  };
60
40
  });
61
41
  return { hint, key, attoAlphAmount, address, tokens, type: 'ContractOutput' };
62
42
  }
63
43
  static convertToOutput(apiContractOutput) {
64
- const amount = compact_int_codec_1.compactUnsignedIntCodec.fromU256(BigInt(apiContractOutput.attoAlphAmount));
65
- const lockupScript = lockup_script_codec_1.lockupScriptCodec.decode(utils_1.bs58.decode(apiContractOutput.address)).script;
66
- const tokensValue = apiContractOutput.tokens.map((token) => {
44
+ const amount = BigInt(apiContractOutput.attoAlphAmount);
45
+ const lockupScript = lockup_script_codec_2.lockupScriptCodec.decode(utils_1.bs58.decode(apiContractOutput.address)).value;
46
+ const tokens = apiContractOutput.tokens.map((token) => {
67
47
  return {
68
48
  tokenId: (0, utils_1.hexToBinUnsafe)(token.id),
69
- amount: compact_int_codec_1.compactUnsignedIntCodec.fromU256(BigInt(token.amount))
49
+ amount: BigInt(token.amount)
70
50
  };
71
51
  });
72
- const tokens = {
73
- length: compact_int_codec_1.compactSignedIntCodec.fromI32(tokensValue.length),
74
- value: tokensValue
75
- };
76
52
  return { amount, lockupScript, tokens };
77
53
  }
78
54
  }
79
55
  exports.ContractOutputCodec = ContractOutputCodec;
80
- exports.contractOutputCodec = new ContractOutputCodec();
56
+ exports.contractOutputCodec = new ContractOutputCodec({
57
+ amount: compact_int_codec_1.u256Codec,
58
+ lockupScript: lockup_script_codec_1.p2cCodec,
59
+ tokens: token_codec_1.tokensCodec
60
+ });
@@ -1,14 +1,8 @@
1
- import { Parser } from 'binary-parser';
2
1
  import { ArrayCodec } from './array-codec';
3
- import { Codec } from './codec';
2
+ import { ObjectCodec } from './codec';
4
3
  export interface ContractOutputRef {
5
4
  hint: number;
6
5
  key: Uint8Array;
7
6
  }
8
- export declare class ContractOutputRefCodec implements Codec<ContractOutputRef> {
9
- parser: Parser;
10
- encode(input: ContractOutputRef): Uint8Array;
11
- decode(input: Uint8Array): ContractOutputRef;
12
- }
13
- export declare const contractOutputRefCodec: ContractOutputRefCodec;
7
+ export declare const contractOutputRefCodec: ObjectCodec<ContractOutputRef>;
14
8
  export declare const contractOutputRefsCodec: ArrayCodec<ContractOutputRef>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.contractOutputRefsCodec = exports.contractOutputRefCodec = exports.ContractOutputRefCodec = void 0;
3
+ exports.contractOutputRefsCodec = exports.contractOutputRefCodec = 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,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
- const signed_int_codec_1 = require("./signed-int-codec");
24
- const utils_1 = require("../utils");
25
- class ContractOutputRefCodec {
26
- constructor() {
27
- this.parser = binary_parser_1.Parser.start().int32('hint').buffer('key', { length: 32 });
28
- }
29
- encode(input) {
30
- return (0, utils_1.concatBytes)([signed_int_codec_1.signedIntCodec.encode(input.hint), input.key]);
31
- }
32
- decode(input) {
33
- return this.parser.parse(input);
34
- }
35
- }
36
- exports.ContractOutputRefCodec = ContractOutputRefCodec;
37
- exports.contractOutputRefCodec = new ContractOutputRefCodec();
22
+ const codec_1 = require("./codec");
23
+ const int_as_4bytes_codec_1 = require("./int-as-4bytes-codec");
24
+ exports.contractOutputRefCodec = new codec_1.ObjectCodec({
25
+ hint: int_as_4bytes_codec_1.intAs4BytesCodec,
26
+ key: codec_1.byte32Codec
27
+ });
38
28
  exports.contractOutputRefsCodec = new array_codec_1.ArrayCodec(exports.contractOutputRefCodec);
@@ -1,16 +1,9 @@
1
- import { Parser } from 'binary-parser';
2
1
  import { Codec } from './codec';
3
- export interface Either<L, R> {
4
- either: number;
5
- value: L | R;
6
- }
7
- export declare class EitherCodec<L, R> implements Codec<Either<L, R>> {
8
- private leftCodec;
9
- private rightCodec;
10
- parser: Parser;
11
- constructor(leftCodec: Codec<L>, rightCodec: Codec<R>, parser?: Parser);
12
- encode(input: Either<L, R>): Uint8Array;
13
- decode(input: Uint8Array): Either<L, R>;
14
- fromLeft(left: L): Either<L, R>;
15
- fromRight(right: R): Either<L, R>;
16
- }
2
+ export type Either<L, R> = {
3
+ kind: 'Left';
4
+ value: L;
5
+ } | {
6
+ kind: 'Right';
7
+ value: R;
8
+ };
9
+ export declare function either<L, R>(name: string, l: Codec<L>, r: Codec<R>): Codec<Either<L, R>>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EitherCodec = void 0;
3
+ exports.either = void 0;
4
4
  /*
5
5
  Copyright 2018 - 2022 The Alephium Authors
6
6
  This file is part of the alephium project.
@@ -18,49 +18,8 @@ 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
- class EitherCodec {
23
- constructor(leftCodec, rightCodec, parser = binary_parser_1.Parser.start()
24
- .uint8('either')
25
- .choice('value', {
26
- tag: 'either',
27
- choices: {
28
- 0: leftCodec.parser,
29
- 1: rightCodec.parser
30
- }
31
- })) {
32
- this.leftCodec = leftCodec;
33
- this.rightCodec = rightCodec;
34
- this.parser = parser;
35
- }
36
- encode(input) {
37
- const result = [input.either];
38
- if (input.either === 0) {
39
- result.push(...this.leftCodec.encode(input.value));
40
- }
41
- else {
42
- result.push(...this.rightCodec.encode(input.value));
43
- }
44
- return new Uint8Array(result);
45
- }
46
- decode(input) {
47
- const result = this.parser.parse(input);
48
- return {
49
- ...result,
50
- value: result.either === 0 ? this.leftCodec.decode(result.value.value) : this.rightCodec.decode(result.value.value)
51
- };
52
- }
53
- fromLeft(left) {
54
- return {
55
- either: 0,
56
- value: left
57
- };
58
- }
59
- fromRight(right) {
60
- return {
61
- either: 1,
62
- value: right
63
- };
64
- }
21
+ const codec_1 = require("./codec");
22
+ function either(name, l, r) {
23
+ return new codec_1.EnumCodec(name, { Left: l, Right: r });
65
24
  }
66
- exports.EitherCodec = EitherCodec;
25
+ exports.either = either;
@@ -2,7 +2,7 @@ export * from './array-codec';
2
2
  export * as assetOutput from './asset-output-codec';
3
3
  export * from './bigint-codec';
4
4
  export * from './bytestring-codec';
5
- export * from './codec';
5
+ export { Codec, boolCodec } from './codec';
6
6
  export * from './compact-int-codec';
7
7
  export * as contractOutput from './contract-output-codec';
8
8
  export * from './contract-output-ref-codec';
@@ -11,12 +11,13 @@ export * from './input-codec';
11
11
  export * from './instr-codec';
12
12
  export * as lockupScript from './lockup-script-codec';
13
13
  export * as unlockScript from './unlock-script-codec';
14
- export * from './long-codec';
14
+ export * as val from './val';
15
+ export * from './timestamp-codec';
15
16
  export * from './method-codec';
16
17
  export * from './option-codec';
17
18
  export * as script from './script-codec';
18
19
  export * from './signature-codec';
19
- export * from './signed-int-codec';
20
+ export * from './int-as-4bytes-codec';
20
21
  export * as token from './token-codec';
21
22
  export * from './transaction-codec';
22
23
  export * from './unsigned-tx-codec';
@@ -43,12 +43,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
43
43
  return result;
44
44
  };
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.contract = exports.token = exports.script = exports.unlockScript = exports.lockupScript = exports.contractOutput = exports.assetOutput = void 0;
46
+ exports.contract = exports.token = exports.script = exports.val = exports.unlockScript = exports.lockupScript = exports.contractOutput = exports.boolCodec = exports.Codec = exports.assetOutput = void 0;
47
47
  __exportStar(require("./array-codec"), exports);
48
48
  exports.assetOutput = __importStar(require("./asset-output-codec"));
49
49
  __exportStar(require("./bigint-codec"), exports);
50
50
  __exportStar(require("./bytestring-codec"), exports);
51
- __exportStar(require("./codec"), exports);
51
+ var codec_1 = require("./codec");
52
+ Object.defineProperty(exports, "Codec", { enumerable: true, get: function () { return codec_1.Codec; } });
53
+ Object.defineProperty(exports, "boolCodec", { enumerable: true, get: function () { return codec_1.boolCodec; } });
52
54
  __exportStar(require("./compact-int-codec"), exports);
53
55
  exports.contractOutput = __importStar(require("./contract-output-codec"));
54
56
  __exportStar(require("./contract-output-ref-codec"), exports);
@@ -57,12 +59,13 @@ __exportStar(require("./input-codec"), exports);
57
59
  __exportStar(require("./instr-codec"), exports);
58
60
  exports.lockupScript = __importStar(require("./lockup-script-codec"));
59
61
  exports.unlockScript = __importStar(require("./unlock-script-codec"));
60
- __exportStar(require("./long-codec"), exports);
62
+ exports.val = __importStar(require("./val"));
63
+ __exportStar(require("./timestamp-codec"), exports);
61
64
  __exportStar(require("./method-codec"), exports);
62
65
  __exportStar(require("./option-codec"), exports);
63
66
  exports.script = __importStar(require("./script-codec"));
64
67
  __exportStar(require("./signature-codec"), exports);
65
- __exportStar(require("./signed-int-codec"), exports);
68
+ __exportStar(require("./int-as-4bytes-codec"), exports);
66
69
  exports.token = __importStar(require("./token-codec"));
67
70
  __exportStar(require("./transaction-codec"), exports);
68
71
  __exportStar(require("./unsigned-tx-codec"), exports);
@@ -1,19 +1,13 @@
1
- import { Parser } from 'binary-parser';
2
1
  import { AssetInput } from '../api/api-alephium';
3
2
  import { UnlockScript } from './unlock-script-codec';
4
- import { Codec } from './codec';
3
+ import { ObjectCodec } from './codec';
5
4
  import { ArrayCodec } from './array-codec';
6
5
  export interface Input {
7
- outputRef: {
8
- hint: number;
9
- key: Uint8Array;
10
- };
6
+ hint: number;
7
+ key: Uint8Array;
11
8
  unlockScript: UnlockScript;
12
9
  }
13
- export declare class InputCodec implements Codec<Input> {
14
- parser: Parser;
15
- encode(input: Input): Uint8Array;
16
- decode(input: Uint8Array): Input;
10
+ export declare class InputCodec extends ObjectCodec<Input> {
17
11
  static toAssetInputs(inputs: Input[]): AssetInput[];
18
12
  static fromAssetInputs(inputs: AssetInput[]): Input[];
19
13
  }
@@ -1,52 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.inputsCodec = exports.inputCodec = exports.InputCodec = 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
4
  const utils_1 = require("../utils");
23
5
  const unlock_script_codec_1 = require("./unlock-script-codec");
24
- const signed_int_codec_1 = require("./signed-int-codec");
6
+ const codec_1 = require("./codec");
25
7
  const array_codec_1 = require("./array-codec");
26
- class InputCodec {
27
- constructor() {
28
- this.parser = binary_parser_1.Parser.start()
29
- .nest('outputRef', {
30
- type: binary_parser_1.Parser.start().int32('hint').buffer('key', { length: 32 })
31
- })
32
- .nest('unlockScript', {
33
- type: unlock_script_codec_1.unlockScriptCodec.parser
34
- });
35
- }
36
- encode(input) {
37
- return (0, utils_1.concatBytes)([
38
- signed_int_codec_1.signedIntCodec.encode(input.outputRef.hint),
39
- input.outputRef.key,
40
- unlock_script_codec_1.unlockScriptCodec.encode(input.unlockScript)
41
- ]);
42
- }
43
- decode(input) {
44
- return this.parser.parse(input);
45
- }
8
+ const int_as_4bytes_codec_1 = require("./int-as-4bytes-codec");
9
+ class InputCodec extends codec_1.ObjectCodec {
46
10
  static toAssetInputs(inputs) {
47
11
  return inputs.map((input) => {
48
- const hint = input.outputRef.hint;
49
- const key = (0, utils_1.binToHex)(input.outputRef.key);
12
+ const hint = input.hint;
13
+ const key = (0, utils_1.binToHex)(input.key);
50
14
  const unlockScript = unlock_script_codec_1.unlockScriptCodec.encode(input.unlockScript);
51
15
  return {
52
16
  outputRef: { hint, key },
@@ -59,13 +23,14 @@ class InputCodec {
59
23
  const hint = input.outputRef.hint;
60
24
  const key = (0, utils_1.hexToBinUnsafe)(input.outputRef.key);
61
25
  const unlockScript = unlock_script_codec_1.unlockScriptCodec.decode((0, utils_1.hexToBinUnsafe)(input.unlockScript));
62
- return {
63
- outputRef: { hint, key },
64
- unlockScript
65
- };
26
+ return { hint, key, unlockScript };
66
27
  });
67
28
  }
68
29
  }
69
30
  exports.InputCodec = InputCodec;
70
- exports.inputCodec = new InputCodec();
31
+ exports.inputCodec = new InputCodec({
32
+ hint: int_as_4bytes_codec_1.intAs4BytesCodec,
33
+ key: codec_1.byte32Codec,
34
+ unlockScript: unlock_script_codec_1.unlockScriptCodec
35
+ });
71
36
  exports.inputsCodec = new array_codec_1.ArrayCodec(exports.inputCodec);