@alephium/web3 0.42.0 → 0.44.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 (114) 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 +2 -3
  10. package/dist/src/codec/asset-output-codec.d.ts +3 -4
  11. package/dist/src/codec/asset-output-codec.js +13 -15
  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 +7 -7
  16. package/dist/src/codec/codec.d.ts +2 -3
  17. package/dist/src/codec/compact-int-codec.d.ts +11 -15
  18. package/dist/src/codec/compact-int-codec.js +23 -33
  19. package/dist/src/codec/contract-codec.d.ts +5 -6
  20. package/dist/src/codec/contract-codec.js +26 -26
  21. package/dist/src/codec/contract-output-codec.d.ts +2 -3
  22. package/dist/src/codec/contract-output-codec.js +9 -11
  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 +13 -14
  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 +2 -4
  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.d.ts +10 -1
  56. package/dist/src/contract/contract.js +197 -21
  57. package/dist/src/contract/ralph.d.ts +2 -1
  58. package/dist/src/contract/ralph.js +25 -11
  59. package/dist/src/{utils → exchange}/exchange.js +5 -5
  60. package/dist/src/exchange/index.d.ts +1 -0
  61. package/dist/src/exchange/index.js +25 -0
  62. package/dist/src/index.d.ts +2 -0
  63. package/dist/src/index.js +2 -0
  64. package/dist/src/signer/signer.js +4 -5
  65. package/dist/src/signer/tx-builder.js +3 -3
  66. package/dist/src/utils/index.d.ts +0 -2
  67. package/dist/src/utils/index.js +0 -7
  68. package/dist/src/utils/sign.js +1 -1
  69. package/dist/src/utils/utils.d.ts +1 -0
  70. package/dist/src/utils/utils.js +30 -11
  71. package/dist/src/utils/webcrypto.js +3 -4
  72. package/package.json +1 -2
  73. package/src/{utils → address}/address.ts +15 -19
  74. package/src/address/index.ts +19 -0
  75. package/src/api/node-provider.ts +2 -9
  76. package/src/api/types.ts +2 -2
  77. package/src/codec/array-codec.ts +5 -6
  78. package/src/codec/asset-output-codec.ts +20 -22
  79. package/src/codec/bigint-codec.ts +4 -5
  80. package/src/codec/bytestring-codec.ts +11 -11
  81. package/src/codec/codec.ts +2 -3
  82. package/src/codec/compact-int-codec.ts +36 -50
  83. package/src/codec/contract-codec.ts +30 -29
  84. package/src/codec/contract-output-codec.ts +13 -15
  85. package/src/codec/contract-output-ref-codec.ts +5 -5
  86. package/src/codec/either-codec.ts +3 -4
  87. package/src/codec/hash.ts +2 -3
  88. package/src/codec/input-codec.ts +10 -10
  89. package/src/codec/instr-codec.ts +3 -4
  90. package/src/codec/lockup-script-codec.ts +8 -9
  91. package/src/codec/long-codec.ts +3 -4
  92. package/src/codec/method-codec.ts +16 -17
  93. package/src/codec/option-codec.ts +4 -5
  94. package/src/codec/script-codec.ts +7 -9
  95. package/src/codec/signature-codec.ts +3 -4
  96. package/src/codec/signed-int-codec.ts +3 -4
  97. package/src/codec/token-codec.ts +6 -6
  98. package/src/codec/transaction-codec.ts +17 -18
  99. package/src/codec/unlock-script-codec.ts +26 -27
  100. package/src/codec/unsigned-tx-codec.ts +10 -11
  101. package/src/contract/contract.ts +274 -9
  102. package/src/contract/ralph.ts +29 -12
  103. package/src/{utils → exchange}/exchange.ts +3 -11
  104. package/src/exchange/index.ts +19 -0
  105. package/src/index.ts +2 -0
  106. package/src/signer/signer.ts +2 -3
  107. package/src/signer/tx-builder.ts +2 -2
  108. package/src/utils/index.ts +0 -2
  109. package/src/utils/sign.ts +1 -1
  110. package/src/utils/utils.ts +29 -10
  111. package/src/utils/webcrypto.ts +3 -4
  112. package/webpack.config.js +1 -5
  113. /package/dist/src/{utils → address}/address.d.ts +0 -0
  114. /package/dist/src/{utils → exchange}/exchange.d.ts +0 -0
@@ -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");
@@ -54,13 +53,13 @@ class MethodCodec {
54
53
  .uint8('isPublic')
55
54
  .uint8('assetModifier')
56
55
  .nest('argsLength', {
57
- type: compact_int_codec_1.compactUnsignedIntCodec.parser
56
+ type: compact_int_codec_1.compactSignedIntCodec.parser
58
57
  })
59
58
  .nest('localsLength', {
60
- type: compact_int_codec_1.compactUnsignedIntCodec.parser
59
+ type: compact_int_codec_1.compactSignedIntCodec.parser
61
60
  })
62
61
  .nest('returnLength', {
63
- type: compact_int_codec_1.compactUnsignedIntCodec.parser
62
+ type: compact_int_codec_1.compactSignedIntCodec.parser
64
63
  })
65
64
  .nest('instrs', {
66
65
  type: instr_codec_1.instrsCodec.parser
@@ -68,11 +67,11 @@ class MethodCodec {
68
67
  }
69
68
  encode(input) {
70
69
  const result = [input.isPublic, input.assetModifier];
71
- result.push(...compact_int_codec_1.compactUnsignedIntCodec.encode(input.argsLength));
72
- result.push(...compact_int_codec_1.compactUnsignedIntCodec.encode(input.localsLength));
73
- result.push(...compact_int_codec_1.compactUnsignedIntCodec.encode(input.returnLength));
70
+ result.push(...compact_int_codec_1.compactSignedIntCodec.encode(input.argsLength));
71
+ result.push(...compact_int_codec_1.compactSignedIntCodec.encode(input.localsLength));
72
+ result.push(...compact_int_codec_1.compactSignedIntCodec.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);
@@ -81,9 +80,9 @@ class MethodCodec {
81
80
  return {
82
81
  isPublic: decodedMethod.isPublic === 1,
83
82
  ...decodeAssetModifier(decodedMethod.assetModifier),
84
- argsLength: compact_int_codec_1.compactUnsignedIntCodec.toU32(decodedMethod.argsLength),
85
- localsLength: compact_int_codec_1.compactUnsignedIntCodec.toU32(decodedMethod.localsLength),
86
- returnLength: compact_int_codec_1.compactUnsignedIntCodec.toU32(decodedMethod.returnLength),
83
+ argsLength: compact_int_codec_1.compactSignedIntCodec.toI32(decodedMethod.argsLength),
84
+ localsLength: compact_int_codec_1.compactSignedIntCodec.toI32(decodedMethod.localsLength),
85
+ returnLength: compact_int_codec_1.compactSignedIntCodec.toI32(decodedMethod.returnLength),
87
86
  instrs: decodedMethod.instrs.value
88
87
  };
89
88
  }
@@ -91,9 +90,9 @@ class MethodCodec {
91
90
  return {
92
91
  isPublic: method.isPublic ? 1 : 0,
93
92
  assetModifier: encodeAssetModifier(method),
94
- argsLength: compact_int_codec_1.compactUnsignedIntCodec.fromU32(method.argsLength),
95
- localsLength: compact_int_codec_1.compactUnsignedIntCodec.fromU32(method.localsLength),
96
- returnLength: compact_int_codec_1.compactUnsignedIntCodec.fromU32(method.returnLength),
93
+ argsLength: compact_int_codec_1.compactSignedIntCodec.fromI32(method.argsLength),
94
+ localsLength: compact_int_codec_1.compactSignedIntCodec.fromI32(method.localsLength),
95
+ returnLength: compact_int_codec_1.compactSignedIntCodec.fromI32(method.returnLength),
97
96
  instrs: instr_codec_1.instrsCodec.fromArray(method.instrs)
98
97
  };
99
98
  }
@@ -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);
@@ -42,7 +40,7 @@ class ScriptCodec {
42
40
  return { methods };
43
41
  }
44
42
  encodeScript(inputTxScript) {
45
- const methodLength = compact_int_codec_1.compactUnsignedIntCodec.fromU32(inputTxScript.methods.length);
43
+ const methodLength = compact_int_codec_1.compactSignedIntCodec.fromI32(inputTxScript.methods.length);
46
44
  const decodedMethods = inputTxScript.methods.map((method) => method_codec_1.MethodCodec.fromMethod(method));
47
45
  return this.encode({ methods: { value: decodedMethods, length: methodLength } });
48
46
  }
@@ -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>;
@@ -18,10 +18,10 @@ 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.tokensCodec = exports.tokenCodec = exports.TokenCodec = void 0;
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");
24
+ const utils_1 = require("../utils");
25
25
  class TokenCodec {
26
26
  constructor() {
27
27
  this.parser = binary_parser_1.Parser.start()
@@ -34,8 +34,8 @@ class TokenCodec {
34
34
  }
35
35
  encode(input) {
36
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]);
37
+ const amount = compact_int_codec_1.compactUnsignedIntCodec.encode(input.amount);
38
+ return (0, utils_1.concatBytes)([tokenId, amount]);
39
39
  }
40
40
  decode(input) {
41
41
  return this.parser.parse(input);
@@ -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 { UnsignedTx } from './unsigned-tx-codec';
@@ -17,10 +16,10 @@ export interface Transaction {
17
16
  }
18
17
  export declare class TransactionCodec implements Codec<Transaction> {
19
18
  parser: Parser;
20
- encode(decodedTx: Transaction): Buffer;
21
- decode(input: Buffer): Transaction;
22
- encodeApiTransaction(input: ApiTransaction): Buffer;
23
- decodeApiTransaction(input: Buffer): ApiTransaction;
19
+ encode(decodedTx: Transaction): Uint8Array;
20
+ decode(input: Uint8Array): Transaction;
21
+ encodeApiTransaction(input: ApiTransaction): Uint8Array;
22
+ decodeApiTransaction(input: Uint8Array): ApiTransaction;
24
23
  static toApiTransaction(transaction: Transaction): ApiTransaction;
25
24
  static fromApiTransaction(tx: ApiTransaction): Transaction;
26
25
  }
@@ -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.transactionCodec = exports.TransactionCodec = void 0;
21
- const buffer_1 = require("buffer/");
22
21
  const binary_parser_1 = require("binary-parser");
23
22
  const unsigned_tx_codec_1 = require("./unsigned-tx-codec");
24
23
  const signature_codec_1 = require("./signature-codec");
@@ -48,13 +47,13 @@ class TransactionCodec {
48
47
  });
49
48
  }
50
49
  encode(decodedTx) {
51
- return buffer_1.Buffer.concat([
50
+ return (0, utils_1.concatBytes)([
52
51
  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)])
52
+ new Uint8Array([decodedTx.scriptExecutionOk]),
53
+ contract_output_ref_codec_1.contractOutputRefsCodec.encode(decodedTx.contractInputs.value),
54
+ output_codec_1.outputsCodec.encode(decodedTx.generatedOutputs.value),
55
+ signature_codec_1.signaturesCodec.encode(decodedTx.inputSignatures.value),
56
+ signature_codec_1.signaturesCodec.encode(decodedTx.scriptSignatures.value)
58
57
  ]);
59
58
  }
60
59
  decode(input) {
@@ -74,7 +73,7 @@ class TransactionCodec {
74
73
  const scriptExecutionOk = !!transaction.scriptExecutionOk;
75
74
  const contractInputs = transaction.contractInputs.value.map((contractInput) => {
76
75
  const hint = contractInput.hint;
77
- const key = contractInput.key.toString('hex');
76
+ const key = (0, utils_1.binToHex)(contractInput.key);
78
77
  return { hint, key };
79
78
  });
80
79
  const txIdBytes = (0, utils_1.hexToBinUnsafe)(txId);
@@ -87,15 +86,15 @@ class TransactionCodec {
87
86
  return contract_output_codec_1.ContractOutputCodec.convertToApiContractOutput(txIdBytes, output.value, index);
88
87
  }
89
88
  });
90
- const inputSignatures = transaction.inputSignatures.value.map((signature) => signature.value.toString('hex'));
91
- const scriptSignatures = transaction.scriptSignatures.value.map((signature) => signature.value.toString('hex'));
89
+ const inputSignatures = transaction.inputSignatures.value.map((signature) => (0, utils_1.binToHex)(signature.value));
90
+ const scriptSignatures = transaction.scriptSignatures.value.map((signature) => (0, utils_1.binToHex)(signature.value));
92
91
  return { unsigned, scriptExecutionOk, contractInputs, generatedOutputs, inputSignatures, scriptSignatures };
93
92
  }
94
93
  static fromApiTransaction(tx) {
95
94
  const unsigned = unsigned_tx_codec_1.UnsignedTxCodec.fromApiUnsignedTx(tx.unsigned);
96
95
  const scriptExecutionOk = tx.scriptExecutionOk ? 1 : 0;
97
96
  const contractInputs = tx.contractInputs.map((contractInput) => {
98
- return { hint: contractInput.hint, key: buffer_1.Buffer.from(contractInput.key, 'hex') };
97
+ return { hint: contractInput.hint, key: (0, utils_1.hexToBinUnsafe)(contractInput.key) };
99
98
  });
100
99
  const generatedOutputs = tx.generatedOutputs.map((output) => {
101
100
  if (output.type === 'AssetOutput') {
@@ -109,10 +108,10 @@ class TransactionCodec {
109
108
  }
110
109
  });
111
110
  const inputSignatures = tx.inputSignatures.map((signature) => {
112
- return { value: buffer_1.Buffer.from(signature, 'hex') };
111
+ return { value: (0, utils_1.hexToBinUnsafe)(signature) };
113
112
  });
114
113
  const scriptSignatures = tx.scriptSignatures.map((signature) => {
115
- return { value: buffer_1.Buffer.from(signature, 'hex') };
114
+ return { value: (0, utils_1.hexToBinUnsafe)(signature) };
116
115
  });
117
116
  return {
118
117
  unsigned,
@@ -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';
@@ -7,7 +6,7 @@ import { DecodedScript } from './script-codec';
7
6
  import { ByteString } from './bytestring-codec';
8
7
  import { LockupScript } from './lockup-script-codec';
9
8
  export interface P2PKH {
10
- publicKey: Buffer;
9
+ publicKey: Uint8Array;
11
10
  }
12
11
  export interface P2MPKH {
13
12
  publicKeys: DecodedArray<{
@@ -25,8 +24,8 @@ export interface P2SH {
25
24
  }
26
25
  export declare class P2SHCodec implements Codec<P2SH> {
27
26
  parser: Parser;
28
- encode(input: P2SH): Buffer;
29
- decode(input: Buffer): P2SH;
27
+ encode(input: P2SH): Uint8Array;
28
+ decode(input: Uint8Array): P2SH;
30
29
  }
31
30
  export interface UnlockScript {
32
31
  scriptType: number;
@@ -34,7 +33,7 @@ export interface UnlockScript {
34
33
  }
35
34
  export declare class UnlockScriptCodec implements Codec<UnlockScript> {
36
35
  parser: Parser;
37
- encode(input: UnlockScript): Buffer;
38
- decode(input: Buffer): UnlockScript;
36
+ encode(input: UnlockScript): Uint8Array;
37
+ decode(input: Uint8Array): UnlockScript;
39
38
  }
40
39
  export declare const unlockScriptCodec: UnlockScriptCodec;
@@ -18,13 +18,13 @@ 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");
25
24
  const script_codec_1 = require("./script-codec");
26
25
  const bytestring_codec_1 = require("./bytestring-codec");
27
26
  const lockup_script_codec_1 = require("./lockup-script-codec");
27
+ const utils_1 = require("../utils");
28
28
  class P2PKHCodec {
29
29
  constructor() {
30
30
  this.parser = binary_parser_1.Parser.start().buffer('publicKey', { length: 33 });
@@ -46,10 +46,10 @@ class P2MPKHCodec {
46
46
  });
47
47
  }
48
48
  encode(input) {
49
- return buffer_1.Buffer.concat([
50
- buffer_1.Buffer.from(compact_int_codec_1.compactUnsignedIntCodec.encode(input.publicKeys.length)),
49
+ return (0, utils_1.concatBytes)([
50
+ compact_int_codec_1.compactUnsignedIntCodec.encode(input.publicKeys.length),
51
51
  ...input.publicKeys.value.map((v) => {
52
- return buffer_1.Buffer.concat([v.publicKey.publicKey, buffer_1.Buffer.from(compact_int_codec_1.compactUnsignedIntCodec.encode(v.index))]);
52
+ return (0, utils_1.concatBytes)([v.publicKey.publicKey, compact_int_codec_1.compactUnsignedIntCodec.encode(v.index)]);
53
53
  })
54
54
  ]);
55
55
  }
@@ -77,23 +77,23 @@ class ValCodec {
77
77
  const valType = input.type;
78
78
  if (valType === 0x00) {
79
79
  // Boolean
80
- return buffer_1.Buffer.from([valType, input.val]);
80
+ return new Uint8Array([valType, input.val]);
81
81
  }
82
82
  else if (valType === 0x01) {
83
83
  // I256
84
- return buffer_1.Buffer.from([valType, ...compact_int_codec_1.compactUnsignedIntCodec.encode(input.val)]);
84
+ return new Uint8Array([valType, ...compact_int_codec_1.compactUnsignedIntCodec.encode(input.val)]);
85
85
  }
86
86
  else if (valType === 0x02) {
87
87
  // U256
88
- return buffer_1.Buffer.from([valType, ...compact_int_codec_1.compactUnsignedIntCodec.encode(input.val)]);
88
+ return new Uint8Array([valType, ...compact_int_codec_1.compactUnsignedIntCodec.encode(input.val)]);
89
89
  }
90
90
  else if (valType === 0x03) {
91
91
  // ByteVec
92
- return buffer_1.Buffer.from([valType, ...bytestring_codec_1.byteStringCodec.encode(input.val)]);
92
+ return new Uint8Array([valType, ...bytestring_codec_1.byteStringCodec.encode(input.val)]);
93
93
  }
94
94
  else if (valType === 0x04) {
95
95
  // Address
96
- return buffer_1.Buffer.from([valType, ...lockup_script_codec_1.lockupScriptCodec.encode(input.val)]);
96
+ return new Uint8Array([valType, ...lockup_script_codec_1.lockupScriptCodec.encode(input.val)]);
97
97
  }
98
98
  else {
99
99
  throw new Error(`ValCodec: unsupported val type: ${valType}`);
@@ -116,7 +116,7 @@ class P2SHCodec {
116
116
  });
117
117
  }
118
118
  encode(input) {
119
- return buffer_1.Buffer.concat([script_codec_1.scriptCodec.encode(input.script), valsCodec.encode(input.params.value)]);
119
+ return (0, utils_1.concatBytes)([script_codec_1.scriptCodec.encode(input.script), valsCodec.encode(input.params.value)]);
120
120
  }
121
121
  decode(input) {
122
122
  return this.parser.parse(input);
@@ -141,22 +141,21 @@ class UnlockScriptCodec {
141
141
  encode(input) {
142
142
  const scriptType = input.scriptType;
143
143
  const inputUnLockScript = input.script;
144
- const inputUnLockScriptType = buffer_1.Buffer.from([scriptType]);
145
144
  if (scriptType === 0) {
146
145
  // P2PKH
147
- return buffer_1.Buffer.concat([inputUnLockScriptType, p2pkhCodec.encode(inputUnLockScript)]);
146
+ return new Uint8Array([scriptType, ...p2pkhCodec.encode(inputUnLockScript)]);
148
147
  }
149
148
  else if (scriptType === 1) {
150
149
  // P2MPKH
151
- return buffer_1.Buffer.concat([inputUnLockScriptType, p2mpkhCodec.encode(inputUnLockScript)]);
150
+ return new Uint8Array([scriptType, ...p2mpkhCodec.encode(inputUnLockScript)]);
152
151
  }
153
152
  else if (scriptType === 2) {
154
153
  // P2SH
155
- return buffer_1.Buffer.concat([inputUnLockScriptType, p2shCodec.encode(input.script)]);
154
+ return new Uint8Array([scriptType, ...p2shCodec.encode(inputUnLockScript)]);
156
155
  }
157
156
  else if (scriptType === 3) {
158
157
  // SameAsPrevious
159
- return inputUnLockScriptType;
158
+ return new Uint8Array([scriptType]);
160
159
  }
161
160
  else {
162
161
  throw new Error(`TODO: encode unlock script: ${scriptType}`);
@@ -1,4 +1,3 @@
1
- import { Buffer } from 'buffer/';
2
1
  import { Parser } from 'binary-parser';
3
2
  import { UnsignedTx as ApiUnsignedTx } from '../api/api-alephium';
4
3
  import { DecodedScript } from './script-codec';
@@ -19,10 +18,10 @@ export interface UnsignedTx {
19
18
  }
20
19
  export declare class UnsignedTxCodec implements Codec<UnsignedTx> {
21
20
  parser: Parser;
22
- encode(decodedUnsignedTx: UnsignedTx): Buffer;
23
- decode(input: Buffer): UnsignedTx;
24
- encodeApiUnsignedTx(input: ApiUnsignedTx): Buffer;
25
- decodeApiUnsignedTx(input: Buffer): ApiUnsignedTx;
21
+ encode(decodedUnsignedTx: UnsignedTx): Uint8Array;
22
+ decode(input: Uint8Array): UnsignedTx;
23
+ encodeApiUnsignedTx(input: ApiUnsignedTx): Uint8Array;
24
+ decodeApiUnsignedTx(input: Uint8Array): ApiUnsignedTx;
26
25
  static txId(unsignedTx: UnsignedTx): string;
27
26
  static toApiUnsignedTx(unsigned: UnsignedTx): ApiUnsignedTx;
28
27
  static fromApiUnsignedTx(unsignedTx: ApiUnsignedTx): UnsignedTx;
@@ -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 script_codec_1 = require("./script-codec");
@@ -48,8 +47,8 @@ class UnsignedTxCodec {
48
47
  });
49
48
  }
50
49
  encode(decodedUnsignedTx) {
51
- return buffer_1.Buffer.concat([
52
- buffer_1.Buffer.from([decodedUnsignedTx.version, decodedUnsignedTx.networkId]),
50
+ return (0, utils_1.concatBytes)([
51
+ new Uint8Array([decodedUnsignedTx.version, decodedUnsignedTx.networkId]),
53
52
  script_codec_1.statefulScriptCodecOpt.encode(decodedUnsignedTx.statefulScript),
54
53
  compact_int_codec_1.compactSignedIntCodec.encode(decodedUnsignedTx.gasAmount),
55
54
  compact_int_codec_1.compactUnsignedIntCodec.encode(decodedUnsignedTx.gasPrice),
@@ -82,7 +81,7 @@ class UnsignedTxCodec {
82
81
  const fixedOutputs = asset_output_codec_1.AssetOutputCodec.toFixedAssetOutputs(txIdBytes, unsigned.fixedOutputs.value);
83
82
  let scriptOpt = undefined;
84
83
  if (unsigned.statefulScript.option === 1) {
85
- scriptOpt = script_codec_1.scriptCodec.encode(unsigned.statefulScript.value).toString('hex');
84
+ scriptOpt = (0, utils_1.binToHex)(script_codec_1.scriptCodec.encode(unsigned.statefulScript.value));
86
85
  }
87
86
  return { txId, version, networkId, gasAmount, scriptOpt, gasPrice, inputs, fixedOutputs };
88
87
  }
@@ -95,7 +94,7 @@ class UnsignedTxCodec {
95
94
  const inputs = input_codec_1.inputsCodec.fromArray(inputsValue);
96
95
  const fixedOutputsValue = asset_output_codec_1.AssetOutputCodec.fromFixedAssetOutputs(unsignedTx.fixedOutputs);
97
96
  const fixedOutputs = asset_output_codec_1.assetOutputsCodec.fromArray(fixedOutputsValue);
98
- const statefulScript = script_codec_1.statefulScriptCodecOpt.fromBuffer(unsignedTx.scriptOpt ? buffer_1.Buffer.from(unsignedTx.scriptOpt, 'hex') : undefined);
97
+ const statefulScript = script_codec_1.statefulScriptCodecOpt.fromBytes(unsignedTx.scriptOpt ? (0, utils_1.hexToBinUnsafe)(unsignedTx.scriptOpt) : undefined);
99
98
  return { version, networkId, gasAmount, gasPrice, inputs, fixedOutputs, statefulScript };
100
99
  }
101
100
  }
@@ -1,5 +1,5 @@
1
1
  import { NamedVals, node, NodeProvider, Number256, Token, Val } from '../api';
2
- import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignerProvider, Address } from '../signer';
2
+ import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScriptTxParams, SignerProvider, Address, SignExecuteScriptTxResult } from '../signer';
3
3
  import { Optional, HexString } from '../utils';
4
4
  import { EventSubscribeOptions, EventSubscription } from './events';
5
5
  import { Method } from '../codec';
@@ -220,6 +220,14 @@ export interface CallContractResult<R> {
220
220
  events: ContractEvent[];
221
221
  debugMessages: DebugMessage[];
222
222
  }
223
+ export interface SignExecuteContractMethodParams<T extends Arguments = Arguments> {
224
+ args: T;
225
+ signer: SignerProvider;
226
+ attoAlphAmount?: Number256;
227
+ tokens?: Token[];
228
+ gasAmount?: number;
229
+ gasPrice?: Number256;
230
+ }
223
231
  export declare const CreateContractEventAddresses: string[];
224
232
  export declare const DestroyContractEventAddresses: string[];
225
233
  export type ContractCreatedEventFields = {
@@ -267,6 +275,7 @@ export declare function decodeEvent<F extends Fields, M extends ContractEvent<F>
267
275
  export declare function subscribeContractEvent<F extends Fields, M extends ContractEvent<F>>(contract: Contract, instance: ContractInstance, options: EventSubscribeOptions<M>, eventName: string, fromCount?: number): EventSubscription;
268
276
  export declare function subscribeContractEvents(contract: Contract, instance: ContractInstance, options: EventSubscribeOptions<ContractEvent<any>>, fromCount?: number): EventSubscription;
269
277
  export declare function callMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, instance: ContractInstance, methodName: string, params: Optional<CallContractParams<A>, 'args'>, getContractByCodeHash: (codeHash: string) => Contract): Promise<CallContractResult<R>>;
278
+ export declare function signExecuteMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, instance: ContractInstance, methodName: string, params: Optional<SignExecuteContractMethodParams<A>, 'args'>): Promise<SignExecuteScriptTxResult>;
270
279
  export declare function multicallMethods<I extends ContractInstance, F extends Fields>(contract: ContractFactory<I, F>, instance: ContractInstance, calls: Record<string, Optional<CallContractParams<any>, 'args'>>, getContractByCodeHash: (codeHash: string) => Contract): Promise<Record<string, CallContractResult<any>>>;
271
280
  export declare function getContractEventsCurrentCount(contractAddress: Address): Promise<number>;
272
281
  export declare const getContractIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;