@alephium/web3 0.42.0 → 0.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) 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/{utils → address}/address.js +15 -19
  4. package/dist/src/address/index.d.ts +1 -0
  5. package/dist/src/address/index.js +34 -0
  6. package/dist/src/api/node-provider.js +10 -9
  7. package/dist/src/api/types.js +1 -1
  8. package/dist/src/codec/array-codec.d.ts +2 -3
  9. package/dist/src/codec/array-codec.js +1 -2
  10. package/dist/src/codec/asset-output-codec.d.ts +3 -4
  11. package/dist/src/codec/asset-output-codec.js +10 -12
  12. package/dist/src/codec/bigint-codec.d.ts +2 -3
  13. package/dist/src/codec/bigint-codec.js +2 -3
  14. package/dist/src/codec/bytestring-codec.d.ts +5 -6
  15. package/dist/src/codec/bytestring-codec.js +5 -5
  16. package/dist/src/codec/codec.d.ts +2 -3
  17. package/dist/src/codec/compact-int-codec.d.ts +12 -13
  18. package/dist/src/codec/compact-int-codec.js +22 -22
  19. package/dist/src/codec/contract-codec.d.ts +5 -6
  20. package/dist/src/codec/contract-codec.js +24 -24
  21. package/dist/src/codec/contract-output-codec.d.ts +2 -3
  22. package/dist/src/codec/contract-output-codec.js +8 -10
  23. package/dist/src/codec/contract-output-ref-codec.d.ts +3 -4
  24. package/dist/src/codec/contract-output-ref-codec.js +2 -2
  25. package/dist/src/codec/either-codec.d.ts +2 -3
  26. package/dist/src/codec/either-codec.js +1 -2
  27. package/dist/src/codec/hash.d.ts +2 -3
  28. package/dist/src/codec/hash.js +17 -0
  29. package/dist/src/codec/input-codec.d.ts +3 -4
  30. package/dist/src/codec/input-codec.js +6 -6
  31. package/dist/src/codec/instr-codec.d.ts +2 -3
  32. package/dist/src/codec/instr-codec.js +1 -2
  33. package/dist/src/codec/lockup-script-codec.d.ts +5 -6
  34. package/dist/src/codec/lockup-script-codec.js +1 -2
  35. package/dist/src/codec/long-codec.d.ts +2 -3
  36. package/dist/src/codec/long-codec.js +1 -2
  37. package/dist/src/codec/method-codec.d.ts +2 -3
  38. package/dist/src/codec/method-codec.js +1 -2
  39. package/dist/src/codec/option-codec.d.ts +3 -4
  40. package/dist/src/codec/option-codec.js +2 -3
  41. package/dist/src/codec/script-codec.d.ts +4 -5
  42. package/dist/src/codec/script-codec.js +1 -3
  43. package/dist/src/codec/signature-codec.d.ts +3 -4
  44. package/dist/src/codec/signature-codec.js +17 -0
  45. package/dist/src/codec/signed-int-codec.d.ts +2 -3
  46. package/dist/src/codec/signed-int-codec.js +1 -2
  47. package/dist/src/codec/token-codec.d.ts +3 -4
  48. package/dist/src/codec/token-codec.js +3 -3
  49. package/dist/src/codec/transaction-codec.d.ts +4 -5
  50. package/dist/src/codec/transaction-codec.js +12 -13
  51. package/dist/src/codec/unlock-script-codec.d.ts +5 -6
  52. package/dist/src/codec/unlock-script-codec.js +14 -15
  53. package/dist/src/codec/unsigned-tx-codec.d.ts +4 -5
  54. package/dist/src/codec/unsigned-tx-codec.js +4 -5
  55. package/dist/src/contract/contract.js +20 -20
  56. package/dist/src/contract/ralph.d.ts +1 -1
  57. package/dist/src/contract/ralph.js +9 -10
  58. package/dist/src/{utils → exchange}/exchange.js +5 -5
  59. package/dist/src/exchange/index.d.ts +1 -0
  60. package/dist/src/exchange/index.js +25 -0
  61. package/dist/src/index.d.ts +2 -0
  62. package/dist/src/index.js +2 -0
  63. package/dist/src/signer/signer.js +4 -5
  64. package/dist/src/signer/tx-builder.js +3 -3
  65. package/dist/src/utils/index.d.ts +0 -2
  66. package/dist/src/utils/index.js +0 -7
  67. package/dist/src/utils/sign.js +1 -1
  68. package/dist/src/utils/utils.d.ts +1 -0
  69. package/dist/src/utils/utils.js +30 -11
  70. package/dist/src/utils/webcrypto.js +3 -4
  71. package/package.json +1 -2
  72. package/src/{utils → address}/address.ts +15 -19
  73. package/src/address/index.ts +19 -0
  74. package/src/api/node-provider.ts +2 -9
  75. package/src/api/types.ts +2 -2
  76. package/src/codec/array-codec.ts +3 -4
  77. package/src/codec/asset-output-codec.ts +16 -18
  78. package/src/codec/bigint-codec.ts +4 -5
  79. package/src/codec/bytestring-codec.ts +8 -8
  80. package/src/codec/codec.ts +2 -3
  81. package/src/codec/compact-int-codec.ts +36 -37
  82. package/src/codec/contract-codec.ts +28 -27
  83. package/src/codec/contract-output-codec.ts +11 -13
  84. package/src/codec/contract-output-ref-codec.ts +5 -5
  85. package/src/codec/either-codec.ts +3 -4
  86. package/src/codec/hash.ts +2 -3
  87. package/src/codec/input-codec.ts +10 -10
  88. package/src/codec/instr-codec.ts +3 -4
  89. package/src/codec/lockup-script-codec.ts +8 -9
  90. package/src/codec/long-codec.ts +3 -4
  91. package/src/codec/method-codec.ts +3 -4
  92. package/src/codec/option-codec.ts +4 -5
  93. package/src/codec/script-codec.ts +5 -7
  94. package/src/codec/signature-codec.ts +3 -4
  95. package/src/codec/signed-int-codec.ts +3 -4
  96. package/src/codec/token-codec.ts +6 -6
  97. package/src/codec/transaction-codec.ts +17 -18
  98. package/src/codec/unlock-script-codec.ts +26 -27
  99. package/src/codec/unsigned-tx-codec.ts +10 -11
  100. package/src/contract/contract.ts +3 -7
  101. package/src/contract/ralph.ts +10 -11
  102. package/src/{utils → exchange}/exchange.ts +3 -11
  103. package/src/exchange/index.ts +19 -0
  104. package/src/index.ts +2 -0
  105. package/src/signer/signer.ts +2 -3
  106. package/src/signer/tx-builder.ts +2 -2
  107. package/src/utils/index.ts +0 -2
  108. package/src/utils/sign.ts +1 -1
  109. package/src/utils/utils.ts +29 -10
  110. package/src/utils/webcrypto.ts +3 -4
  111. package/webpack.config.js +1 -5
  112. /package/dist/src/{utils → address}/address.d.ts +0 -0
  113. /package/dist/src/{utils → exchange}/exchange.d.ts +0 -0
@@ -17,31 +17,13 @@ You should have received a copy of the GNU Lesser General Public License
17
17
  along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.contractCodec = exports.ContractCodec = exports.toHalfDecoded = void 0;
21
- const buffer_1 = require("buffer/");
20
+ exports.contractCodec = exports.ContractCodec = void 0;
22
21
  const binary_parser_1 = require("binary-parser");
23
22
  const array_codec_1 = require("./array-codec");
24
23
  const compact_int_codec_1 = require("./compact-int-codec");
25
24
  const method_codec_1 = require("./method-codec");
25
+ const utils_1 = require("../utils");
26
26
  const compactSignedIntsCodec = new array_codec_1.ArrayCodec(compact_int_codec_1.compactSignedIntCodec);
27
- function toHalfDecoded(contract) {
28
- const fieldLength = compact_int_codec_1.compactSignedIntCodec.fromI32(contract.fieldLength);
29
- const methods = contract.methods.map((m) => method_codec_1.methodCodec.encode(method_codec_1.MethodCodec.fromMethod(m)));
30
- let count = 0;
31
- const methodIndexes = Array.from(Array(methods.length).keys()).map((index) => {
32
- count += methods[`${index}`].length;
33
- return count;
34
- });
35
- return {
36
- fieldLength,
37
- methodIndexes: {
38
- length: compact_int_codec_1.compactSignedIntCodec.fromI32(methodIndexes.length),
39
- value: methodIndexes.map((value) => compact_int_codec_1.compactSignedIntCodec.fromI32(value))
40
- },
41
- methods: methods.reduce((acc, buffer) => buffer_1.Buffer.concat([acc, buffer]))
42
- };
43
- }
44
- exports.toHalfDecoded = toHalfDecoded;
45
27
  class ContractCodec {
46
28
  constructor() {
47
29
  this.parser = binary_parser_1.Parser.start()
@@ -54,10 +36,10 @@ class ContractCodec {
54
36
  .buffer('methods', { readUntil: 'eof' });
55
37
  }
56
38
  encode(input) {
57
- return buffer_1.Buffer.from([
58
- ...compact_int_codec_1.compactSignedIntCodec.encode(input.fieldLength),
59
- ...compactSignedIntsCodec.encode(input.methodIndexes.value),
60
- ...input.methods
39
+ return (0, utils_1.concatBytes)([
40
+ compact_int_codec_1.compactSignedIntCodec.encode(input.fieldLength),
41
+ compactSignedIntsCodec.encode(input.methodIndexes.value),
42
+ input.methods
61
43
  ]);
62
44
  }
63
45
  decode(input) {
@@ -76,6 +58,24 @@ class ContractCodec {
76
58
  }
77
59
  return { fieldLength, methods };
78
60
  }
61
+ 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)));
64
+ let count = 0;
65
+ const methodIndexes = Array.from(Array(methods.length).keys()).map((index) => {
66
+ count += methods[`${index}`].length;
67
+ return count;
68
+ });
69
+ const halfDecoded = {
70
+ 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
+ },
75
+ methods: (0, utils_1.concatBytes)(methods)
76
+ };
77
+ return this.encode(halfDecoded);
78
+ }
79
79
  }
80
80
  exports.ContractCodec = ContractCodec;
81
81
  exports.contractCodec = new ContractCodec();
@@ -1,4 +1,3 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { DecodedArray } from './array-codec';
4
3
  import { DecodedCompactInt } from './compact-int-codec';
@@ -13,8 +12,8 @@ export interface ContractOutput {
13
12
  }
14
13
  export declare class ContractOutputCodec implements Codec<ContractOutput> {
15
14
  parser: Parser;
16
- encode(input: ContractOutput): Buffer;
17
- decode(input: Buffer): ContractOutput;
15
+ encode(input: ContractOutput): Uint8Array;
16
+ decode(input: Uint8Array): ContractOutput;
18
17
  static convertToApiContractOutput(txIdBytes: Uint8Array, output: ContractOutput, index: number): ApiContractOutput;
19
18
  static convertToOutput(apiContractOutput: ApiContractOutput): ContractOutput;
20
19
  }
@@ -18,7 +18,6 @@ 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 buffer_1 = require("buffer/");
22
21
  const binary_parser_1 = require("binary-parser");
23
22
  const compact_int_codec_1 = require("./compact-int-codec");
24
23
  const token_codec_1 = require("./token-codec");
@@ -40,22 +39,22 @@ class ContractOutputCodec {
40
39
  });
41
40
  }
42
41
  encode(input) {
43
- const amount = buffer_1.Buffer.from(compact_int_codec_1.compactUnsignedIntCodec.encode(input.amount));
42
+ const amount = compact_int_codec_1.compactUnsignedIntCodec.encode(input.amount);
44
43
  const lockupScript = input.lockupScript.contractId;
45
- const tokens = buffer_1.Buffer.from(token_codec_1.tokensCodec.encode(input.tokens.value));
46
- return buffer_1.Buffer.concat([amount, lockupScript, tokens]);
44
+ const tokens = token_codec_1.tokensCodec.encode(input.tokens.value);
45
+ return (0, utils_1.concatBytes)([amount, lockupScript, tokens]);
47
46
  }
48
47
  decode(input) {
49
48
  return this.parser.parse(input);
50
49
  }
51
50
  static convertToApiContractOutput(txIdBytes, output, index) {
52
51
  const hint = (0, hash_1.createHint)(output.lockupScript.contractId);
53
- const key = (0, utils_1.binToHex)((0, hash_1.blakeHash)(buffer_1.Buffer.concat([txIdBytes, signed_int_codec_1.signedIntCodec.encode(index)])));
52
+ const key = (0, utils_1.binToHex)((0, hash_1.blakeHash)((0, utils_1.concatBytes)([txIdBytes, signed_int_codec_1.signedIntCodec.encode(index)])));
54
53
  const attoAlphAmount = compact_int_codec_1.compactUnsignedIntCodec.toU256(output.amount).toString();
55
- const address = utils_1.bs58.encode(buffer_1.Buffer.concat([buffer_1.Buffer.from([0x03]), output.lockupScript.contractId]));
54
+ const address = utils_1.bs58.encode(new Uint8Array([0x03, ...output.lockupScript.contractId]));
56
55
  const tokens = output.tokens.value.map((token) => {
57
56
  return {
58
- id: token.tokenId.toString('hex'),
57
+ id: (0, utils_1.binToHex)(token.tokenId),
59
58
  amount: compact_int_codec_1.compactUnsignedIntCodec.toU256(token.amount).toString()
60
59
  };
61
60
  });
@@ -63,11 +62,10 @@ class ContractOutputCodec {
63
62
  }
64
63
  static convertToOutput(apiContractOutput) {
65
64
  const amount = compact_int_codec_1.compactUnsignedIntCodec.fromU256(BigInt(apiContractOutput.attoAlphAmount));
66
- const lockupScript = lockup_script_codec_1.lockupScriptCodec.decode(buffer_1.Buffer.from(utils_1.bs58.decode(apiContractOutput.address)))
67
- .script;
65
+ const lockupScript = lockup_script_codec_1.lockupScriptCodec.decode(utils_1.bs58.decode(apiContractOutput.address)).script;
68
66
  const tokensValue = apiContractOutput.tokens.map((token) => {
69
67
  return {
70
- tokenId: buffer_1.Buffer.from(token.id, 'hex'),
68
+ tokenId: (0, utils_1.hexToBinUnsafe)(token.id),
71
69
  amount: compact_int_codec_1.compactUnsignedIntCodec.fromU256(BigInt(token.amount))
72
70
  };
73
71
  });
@@ -1,15 +1,14 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { ArrayCodec } from './array-codec';
4
3
  import { Codec } from './codec';
5
4
  export interface ContractOutputRef {
6
5
  hint: number;
7
- key: Buffer;
6
+ key: Uint8Array;
8
7
  }
9
8
  export declare class ContractOutputRefCodec implements Codec<ContractOutputRef> {
10
9
  parser: Parser;
11
- encode(input: ContractOutputRef): Buffer;
12
- decode(input: Buffer): ContractOutputRef;
10
+ encode(input: ContractOutputRef): Uint8Array;
11
+ decode(input: Uint8Array): ContractOutputRef;
13
12
  }
14
13
  export declare const contractOutputRefCodec: ContractOutputRefCodec;
15
14
  export declare const contractOutputRefsCodec: ArrayCodec<ContractOutputRef>;
@@ -18,16 +18,16 @@ 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 buffer_1 = require("buffer/");
22
21
  const binary_parser_1 = require("binary-parser");
23
22
  const array_codec_1 = require("./array-codec");
24
23
  const signed_int_codec_1 = require("./signed-int-codec");
24
+ const utils_1 = require("../utils");
25
25
  class ContractOutputRefCodec {
26
26
  constructor() {
27
27
  this.parser = binary_parser_1.Parser.start().int32('hint').buffer('key', { length: 32 });
28
28
  }
29
29
  encode(input) {
30
- return buffer_1.Buffer.concat([buffer_1.Buffer.from([...signed_int_codec_1.signedIntCodec.encode(input.hint), ...input.key])]);
30
+ return (0, utils_1.concatBytes)([signed_int_codec_1.signedIntCodec.encode(input.hint), input.key]);
31
31
  }
32
32
  decode(input) {
33
33
  return this.parser.parse(input);
@@ -1,4 +1,3 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { Codec } from './codec';
4
3
  export interface Either<L, R> {
@@ -10,8 +9,8 @@ export declare class EitherCodec<L, R> implements Codec<Either<L, R>> {
10
9
  private rightCodec;
11
10
  parser: Parser;
12
11
  constructor(leftCodec: Codec<L>, rightCodec: Codec<R>, parser?: Parser);
13
- encode(input: Either<L, R>): Buffer;
14
- decode(input: Buffer): Either<L, R>;
12
+ encode(input: Either<L, R>): Uint8Array;
13
+ decode(input: Uint8Array): Either<L, R>;
15
14
  fromLeft(left: L): Either<L, R>;
16
15
  fromRight(right: R): Either<L, R>;
17
16
  }
@@ -18,7 +18,6 @@ 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 buffer_1 = require("buffer/");
22
21
  const binary_parser_1 = require("binary-parser");
23
22
  class EitherCodec {
24
23
  constructor(leftCodec, rightCodec, parser = binary_parser_1.Parser.start()
@@ -42,7 +41,7 @@ class EitherCodec {
42
41
  else {
43
42
  result.push(...this.rightCodec.encode(input.value));
44
43
  }
45
- return buffer_1.Buffer.from(result);
44
+ return new Uint8Array(result);
46
45
  }
47
46
  decode(input) {
48
47
  const result = this.parser.parse(input);
@@ -1,4 +1,3 @@
1
- import { Buffer } from 'buffer/';
2
1
  export declare function blakeHash(raw: Uint8Array): Uint8Array;
3
- export declare function djbIntHash(bytes: Buffer): number;
4
- export declare function createHint(input: Buffer): number;
2
+ export declare function djbIntHash(bytes: Uint8Array): number;
3
+ export declare function createHint(input: Uint8Array): number;
@@ -4,6 +4,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createHint = exports.djbIntHash = exports.blakeHash = void 0;
7
+ /*
8
+ Copyright 2018 - 2022 The Alephium Authors
9
+ This file is part of the alephium project.
10
+
11
+ The library is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU Lesser General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ (at your option) any later version.
15
+
16
+ The library is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU Lesser General Public License for more details.
20
+
21
+ You should have received a copy of the GNU Lesser General Public License
22
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
23
+ */
7
24
  const blakejs_1 = __importDefault(require("blakejs"));
8
25
  function blakeHash(raw) {
9
26
  return blakejs_1.default.blake2b(raw, undefined, 32);
@@ -1,4 +1,3 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { AssetInput } from '../api/api-alephium';
4
3
  import { UnlockScript } from './unlock-script-codec';
@@ -7,14 +6,14 @@ import { ArrayCodec } from './array-codec';
7
6
  export interface Input {
8
7
  outputRef: {
9
8
  hint: number;
10
- key: Buffer;
9
+ key: Uint8Array;
11
10
  };
12
11
  unlockScript: UnlockScript;
13
12
  }
14
13
  export declare class InputCodec implements Codec<Input> {
15
14
  parser: Parser;
16
- encode(input: Input): Buffer;
17
- decode(input: Buffer): Input;
15
+ encode(input: Input): Uint8Array;
16
+ decode(input: Uint8Array): Input;
18
17
  static toAssetInputs(inputs: Input[]): AssetInput[];
19
18
  static fromAssetInputs(inputs: AssetInput[]): Input[];
20
19
  }
@@ -18,7 +18,6 @@ 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 buffer_1 = require("buffer/");
22
21
  const binary_parser_1 = require("binary-parser");
23
22
  const utils_1 = require("../utils");
24
23
  const unlock_script_codec_1 = require("./unlock-script-codec");
@@ -35,8 +34,9 @@ class InputCodec {
35
34
  });
36
35
  }
37
36
  encode(input) {
38
- return buffer_1.Buffer.concat([
39
- buffer_1.Buffer.from([...signed_int_codec_1.signedIntCodec.encode(input.outputRef.hint), ...input.outputRef.key]),
37
+ return (0, utils_1.concatBytes)([
38
+ signed_int_codec_1.signedIntCodec.encode(input.outputRef.hint),
39
+ input.outputRef.key,
40
40
  unlock_script_codec_1.unlockScriptCodec.encode(input.unlockScript)
41
41
  ]);
42
42
  }
@@ -50,15 +50,15 @@ class InputCodec {
50
50
  const unlockScript = unlock_script_codec_1.unlockScriptCodec.encode(input.unlockScript);
51
51
  return {
52
52
  outputRef: { hint, key },
53
- unlockScript: unlockScript.toString('hex')
53
+ unlockScript: (0, utils_1.binToHex)(unlockScript)
54
54
  };
55
55
  });
56
56
  }
57
57
  static fromAssetInputs(inputs) {
58
58
  return inputs.map((input) => {
59
59
  const hint = input.outputRef.hint;
60
- const key = buffer_1.Buffer.from(input.outputRef.key, 'hex');
61
- const unlockScript = unlock_script_codec_1.unlockScriptCodec.decode(buffer_1.Buffer.from(input.unlockScript, 'hex'));
60
+ const key = (0, utils_1.hexToBinUnsafe)(input.outputRef.key);
61
+ const unlockScript = unlock_script_codec_1.unlockScriptCodec.decode((0, utils_1.hexToBinUnsafe)(input.unlockScript));
62
62
  return {
63
63
  outputRef: { hint, key },
64
64
  unlockScript
@@ -1,4 +1,3 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { ArrayCodec, DecodedArray } from './array-codec';
4
3
  import { DecodedCompactInt } from './compact-int-codec';
@@ -226,8 +225,8 @@ export declare const MethodSelector: (selector: number) => Instr;
226
225
  export declare const CallExternalBySelector: (selector: number) => Instr;
227
226
  export declare class InstrCodec implements Codec<Instr> {
228
227
  parser: Parser;
229
- encode(instr: Instr): Buffer;
230
- decode(input: Buffer): Instr;
228
+ encode(instr: Instr): Uint8Array;
229
+ decode(input: Uint8Array): Instr;
231
230
  }
232
231
  export declare const instrCodec: InstrCodec;
233
232
  export declare const instrsCodec: ArrayCodec<Instr>;
@@ -21,7 +21,6 @@ GNU Lesser General Public License for more details.
21
21
  You should have received a copy of the GNU Lesser General Public License
22
22
  along with the library. If not, see <http://www.gnu.org/licenses/>.
23
23
  */
24
- const buffer_1 = require("buffer/");
25
24
  const binary_parser_1 = require("binary-parser");
26
25
  const array_codec_1 = require("./array-codec");
27
26
  const compact_int_codec_1 = require("./compact-int-codec");
@@ -476,7 +475,7 @@ class InstrCodec {
476
475
  else if (instr.code === 0xd3 || instr.code === 0xd4) {
477
476
  result.push(...signed_int_codec_1.signedIntCodec.encode(instrValue.index));
478
477
  }
479
- return buffer_1.Buffer.from(result);
478
+ return new Uint8Array(result);
480
479
  }
481
480
  decode(input) {
482
481
  return this.parser.parse(input);
@@ -1,20 +1,19 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { DecodedCompactInt } from './compact-int-codec';
4
3
  import { Codec } from './codec';
5
4
  import { DecodedArray } from './array-codec';
6
5
  export interface PublicKeyHash {
7
- publicKeyHash: Buffer;
6
+ publicKeyHash: Uint8Array;
8
7
  }
9
8
  export interface MultiSig {
10
9
  publicKeyHashes: DecodedArray<PublicKeyHash>;
11
10
  m: DecodedCompactInt;
12
11
  }
13
12
  export interface P2SH {
14
- scriptHash: Buffer;
13
+ scriptHash: Uint8Array;
15
14
  }
16
15
  export interface P2C {
17
- contractId: Buffer;
16
+ contractId: Uint8Array;
18
17
  }
19
18
  export interface LockupScript {
20
19
  scriptType: number;
@@ -22,7 +21,7 @@ export interface LockupScript {
22
21
  }
23
22
  export declare class LockupScriptCodec implements Codec<LockupScript> {
24
23
  parser: Parser;
25
- encode(input: LockupScript): Buffer;
26
- decode(input: Buffer): LockupScript;
24
+ encode(input: LockupScript): Uint8Array;
25
+ decode(input: Uint8Array): LockupScript;
27
26
  }
28
27
  export declare const lockupScriptCodec: LockupScriptCodec;
@@ -18,7 +18,6 @@ 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 buffer_1 = require("buffer/");
22
21
  const binary_parser_1 = require("binary-parser");
23
22
  const compact_int_codec_1 = require("./compact-int-codec");
24
23
  const array_codec_1 = require("./array-codec");
@@ -70,7 +69,7 @@ class LockupScriptCodec {
70
69
  else {
71
70
  throw new Error(`Unsupported script type: ${input.scriptType}`);
72
71
  }
73
- return buffer_1.Buffer.from(result);
72
+ return new Uint8Array(result);
74
73
  }
75
74
  decode(input) {
76
75
  return this.parser.parse(input);
@@ -1,9 +1,8 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { Codec } from './codec';
4
3
  export declare class LongCodec implements Codec<bigint> {
5
4
  parser: Parser;
6
- encode(input: bigint): Buffer;
7
- decode(bytes: Buffer): bigint;
5
+ encode(input: bigint): Uint8Array;
6
+ decode(bytes: Uint8Array): bigint;
8
7
  }
9
8
  export declare const longCodec: LongCodec;
@@ -18,7 +18,6 @@ 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 buffer_1 = require("buffer/");
22
21
  const binary_parser_1 = require("binary-parser");
23
22
  const codec_1 = require("./codec");
24
23
  class LongCodec {
@@ -35,7 +34,7 @@ class LongCodec {
35
34
  byteArray[byteArray.length - index - 1] = Number(byte);
36
35
  input >>= BigInt(8);
37
36
  }
38
- return buffer_1.Buffer.from(byteArray);
37
+ return byteArray;
39
38
  }
40
39
  decode(bytes) {
41
40
  (0, codec_1.assert)(bytes.length == 8, 'Length should be 8');
@@ -1,4 +1,3 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { ArrayCodec, DecodedArray } from './array-codec';
4
3
  import { DecodedCompactInt } from './compact-int-codec';
@@ -24,8 +23,8 @@ export interface Method {
24
23
  }
25
24
  export declare class MethodCodec implements Codec<DecodedMethod> {
26
25
  parser: Parser;
27
- encode(input: DecodedMethod): Buffer;
28
- decode(input: Buffer): DecodedMethod;
26
+ encode(input: DecodedMethod): Uint8Array;
27
+ decode(input: Uint8Array): DecodedMethod;
29
28
  static toMethod(decodedMethod: DecodedMethod): Method;
30
29
  static fromMethod(method: Method): DecodedMethod;
31
30
  }
@@ -18,7 +18,6 @@ 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 buffer_1 = require("buffer/");
22
21
  const binary_parser_1 = require("binary-parser");
23
22
  const array_codec_1 = require("./array-codec");
24
23
  const compact_int_codec_1 = require("./compact-int-codec");
@@ -72,7 +71,7 @@ class MethodCodec {
72
71
  result.push(...compact_int_codec_1.compactUnsignedIntCodec.encode(input.localsLength));
73
72
  result.push(...compact_int_codec_1.compactUnsignedIntCodec.encode(input.returnLength));
74
73
  result.push(...instr_codec_1.instrsCodec.encode(input.instrs.value));
75
- return buffer_1.Buffer.from(result);
74
+ return new Uint8Array(result);
76
75
  }
77
76
  decode(input) {
78
77
  return this.parser.parse(input);
@@ -1,4 +1,3 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { Codec } from './codec';
4
3
  export interface Option<T> {
@@ -9,7 +8,7 @@ export declare class OptionCodec<T> implements Codec<Option<T>> {
9
8
  private childCodec;
10
9
  parser: Parser;
11
10
  constructor(childCodec: Codec<T>, parser?: Parser);
12
- encode(input: Option<T>): Buffer;
13
- decode(input: Buffer): Option<T>;
14
- fromBuffer(input?: Buffer): Option<T>;
11
+ encode(input: Option<T>): Uint8Array;
12
+ decode(input: Uint8Array): Option<T>;
13
+ fromBytes(input?: Uint8Array): Option<T>;
15
14
  }
@@ -18,7 +18,6 @@ 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 buffer_1 = require("buffer/");
22
21
  const binary_parser_1 = require("binary-parser");
23
22
  class OptionCodec {
24
23
  constructor(childCodec, parser = new binary_parser_1.Parser().uint8('option').choice('value', {
@@ -36,7 +35,7 @@ class OptionCodec {
36
35
  if (input.option === 1) {
37
36
  result.push(...this.childCodec.encode(input.value));
38
37
  }
39
- return buffer_1.Buffer.from(result);
38
+ return new Uint8Array(result);
40
39
  }
41
40
  decode(input) {
42
41
  const result = this.parser.parse(input);
@@ -45,7 +44,7 @@ class OptionCodec {
45
44
  value: result.option ? this.childCodec.decode(result.value.value) : undefined
46
45
  };
47
46
  }
48
- fromBuffer(input) {
47
+ fromBytes(input) {
49
48
  return {
50
49
  option: input ? 1 : 0,
51
50
  value: input ? this.childCodec.decode(input) : undefined
@@ -1,4 +1,3 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { DecodedArray } from './array-codec';
4
3
  import { Codec } from './codec';
@@ -12,10 +11,10 @@ export interface Script {
12
11
  }
13
12
  export declare class ScriptCodec implements Codec<DecodedScript> {
14
13
  parser: Parser;
15
- encode(input: DecodedScript): Buffer;
16
- decode(input: Buffer): DecodedScript;
17
- decodeScript(input: Buffer): Script;
18
- encodeScript(inputTxScript: Script): Buffer;
14
+ encode(input: DecodedScript): Uint8Array;
15
+ decode(input: Uint8Array): DecodedScript;
16
+ decodeScript(input: Uint8Array): Script;
17
+ encodeScript(inputTxScript: Script): Uint8Array;
19
18
  }
20
19
  export declare const scriptCodec: ScriptCodec;
21
20
  export declare const statefulScriptCodecOpt: OptionCodec<DecodedScript>;
@@ -18,7 +18,6 @@ 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 buffer_1 = require("buffer/");
22
21
  const binary_parser_1 = require("binary-parser");
23
22
  const method_codec_1 = require("./method-codec");
24
23
  const option_codec_1 = require("./option-codec");
@@ -30,8 +29,7 @@ class ScriptCodec {
30
29
  });
31
30
  }
32
31
  encode(input) {
33
- const script = method_codec_1.methodsCodec.encode(input.methods.value);
34
- return buffer_1.Buffer.from(script);
32
+ return method_codec_1.methodsCodec.encode(input.methods.value);
35
33
  }
36
34
  decode(input) {
37
35
  return this.parser.parse(input);
@@ -1,14 +1,13 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { ArrayCodec } from './array-codec';
4
3
  import { Codec } from './codec';
5
4
  export interface Signature {
6
- value: Buffer;
5
+ value: Uint8Array;
7
6
  }
8
7
  export declare class SignatureCodec implements Codec<Signature> {
9
8
  parser: Parser;
10
- encode(input: Signature): Buffer;
11
- decode(input: Buffer): Signature;
9
+ encode(input: Signature): Uint8Array;
10
+ decode(input: Uint8Array): Signature;
12
11
  }
13
12
  export declare const signatureCodec: SignatureCodec;
14
13
  export declare const signaturesCodec: ArrayCodec<Signature>;
@@ -1,6 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.signaturesCodec = exports.signatureCodec = exports.SignatureCodec = 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
+ */
4
21
  const binary_parser_1 = require("binary-parser");
5
22
  const array_codec_1 = require("./array-codec");
6
23
  class SignatureCodec {
@@ -1,9 +1,8 @@
1
1
  import { Parser } from 'binary-parser';
2
2
  import { Codec } from './codec';
3
- import { Buffer } from 'buffer/';
4
3
  export declare class SignedIntCodec implements Codec<number> {
5
4
  parser: Parser;
6
- encode(value: number): Buffer;
7
- decode(bytes: Buffer): number;
5
+ encode(value: number): Uint8Array;
6
+ decode(bytes: Uint8Array): number;
8
7
  }
9
8
  export declare const signedIntCodec: SignedIntCodec;
@@ -20,7 +20,6 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
20
20
  */
21
21
  const binary_parser_1 = require("binary-parser");
22
22
  const codec_1 = require("./codec");
23
- const buffer_1 = require("buffer/");
24
23
  class SignedIntCodec {
25
24
  constructor() {
26
25
  this.parser = binary_parser_1.Parser.start().buffer('value', {
@@ -28,7 +27,7 @@ class SignedIntCodec {
28
27
  });
29
28
  }
30
29
  encode(value) {
31
- return buffer_1.Buffer.from([(value >> 24) & 0xff, (value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff]);
30
+ return new Uint8Array([(value >> 24) & 0xff, (value >> 16) & 0xff, (value >> 8) & 0xff, value & 0xff]);
32
31
  }
33
32
  decode(bytes) {
34
33
  (0, codec_1.assert)(bytes.length === 4, 'Length should be 4');
@@ -1,16 +1,15 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { DecodedCompactInt } from './compact-int-codec';
4
3
  import { Codec } from './codec';
5
4
  import { ArrayCodec } from './array-codec';
6
5
  export interface Token {
7
- tokenId: Buffer;
6
+ tokenId: Uint8Array;
8
7
  amount: DecodedCompactInt;
9
8
  }
10
9
  export declare class TokenCodec implements Codec<Token> {
11
10
  parser: Parser;
12
- encode(input: Token): Buffer;
13
- decode(input: Buffer): Token;
11
+ encode(input: Token): Uint8Array;
12
+ decode(input: Uint8Array): Token;
14
13
  }
15
14
  export declare const tokenCodec: TokenCodec;
16
15
  export declare const tokensCodec: ArrayCodec<Token>;