@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
@@ -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
  }
@@ -41,11 +41,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
41
41
  };
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
43
  exports.getTokenIdFromUnsignedTx = exports.getContractIdFromUnsignedTx = exports.getContractEventsCurrentCount = exports.multicallMethods = exports.callMethod = exports.subscribeContractEvents = exports.subscribeContractEvent = exports.decodeEvent = exports.subscribeContractDestroyedEvent = exports.subscribeContractCreatedEvent = exports.fetchContractState = exports.ContractInstance = exports.getMapItem = exports.RalphMap = exports.testMethod = exports.addStdIdToFields = exports.subscribeEventsFromContract = exports.decodeContractDestroyedEvent = exports.decodeContractCreatedEvent = exports.DestroyContractEventAddresses = exports.CreateContractEventAddresses = exports.ExecutableScript = exports.ContractFactory = exports.randomTxId = exports.fromApiEventFields = exports.fromApiArray = exports.getDefaultValue = exports.fromApiFields = exports.Script = exports.Contract = exports.Artifact = exports.Struct = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = exports.StdIdFieldName = void 0;
44
- const buffer_1 = require("buffer/");
45
44
  const fs_1 = require("fs");
46
45
  const api_1 = require("../api");
47
46
  const ralph = __importStar(require("./ralph"));
48
47
  const utils_1 = require("../utils");
48
+ const address_1 = require("../address");
49
49
  const global_1 = require("../global");
50
50
  const events_1 = require("./events");
51
51
  const constants_1 = require("../constants");
@@ -128,7 +128,7 @@ class Contract extends Artifact {
128
128
  this.stdInterfaceId = stdInterfaceId;
129
129
  this.bytecodeDebug = ralph.buildDebugBytecode(this.bytecode, this.bytecodeDebugPatch);
130
130
  this.codeHashDebug = codeHashDebug;
131
- this.decodedMethods = codec_1.contract.contractCodec.decodeContract(buffer_1.Buffer.from(bytecode, 'hex')).methods;
131
+ this.decodedMethods = codec_1.contract.contractCodec.decodeContract((0, utils_1.hexToBinUnsafe)(bytecode)).methods;
132
132
  }
133
133
  publicFunctions() {
134
134
  return this.functions.filter((_, index) => this.decodedMethods[`${index}`].isPublic);
@@ -198,7 +198,7 @@ class Contract extends Artifact {
198
198
  const addressDef = typeof address !== 'undefined' ? address : Contract.randomAddress();
199
199
  return {
200
200
  address: addressDef,
201
- contractId: (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(addressDef)),
201
+ contractId: (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(addressDef)),
202
202
  bytecode: this.bytecode,
203
203
  codeHash: this.codeHash,
204
204
  fields: fields,
@@ -271,7 +271,7 @@ class Contract extends Artifact {
271
271
  fromApiContractState(state) {
272
272
  return {
273
273
  address: state.address,
274
- contractId: (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(state.address)),
274
+ contractId: (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(state.address)),
275
275
  bytecode: state.bytecode,
276
276
  initialStateHash: state.initialStateHash,
277
277
  codeHash: state.codeHash,
@@ -319,7 +319,7 @@ class Contract extends Artifact {
319
319
  addressToCodeHash.set(result.address, result.codeHash);
320
320
  result.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash));
321
321
  return {
322
- contractId: (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(result.address)),
322
+ contractId: (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(result.address)),
323
323
  contractAddress: result.address,
324
324
  returns: returns,
325
325
  gasUsed: result.gasUsed,
@@ -647,7 +647,7 @@ function specialContractAddress(eventIndex, groupIndex) {
647
647
  const bytes = new Uint8Array(32).fill(0);
648
648
  bytes[30] = eventIndex;
649
649
  bytes[31] = groupIndex;
650
- return (0, utils_1.addressFromContractId)((0, utils_1.binToHex)(bytes));
650
+ return (0, address_1.addressFromContractId)((0, utils_1.binToHex)(bytes));
651
651
  }
652
652
  exports.CreateContractEventAddresses = Array.from(Array(constants_1.TOTAL_NUMBER_OF_GROUPS).keys()).map((groupIndex) => specialContractAddress(Contract.ContractCreatedEventIndex, groupIndex));
653
653
  exports.DestroyContractEventAddresses = Array.from(Array(constants_1.TOTAL_NUMBER_OF_GROUPS).keys()).map((groupIndex) => specialContractAddress(Contract.ContractDestroyedEventIndex, groupIndex));
@@ -718,7 +718,7 @@ function calcWrapperContractId(parentContractId, mapIndex, key, keyType, group)
718
718
  const prefix = ralph.encodeMapPrefix(mapIndex);
719
719
  const encodedKey = ralph.primitiveToByteVec(key, keyType);
720
720
  const path = (0, utils_1.binToHex)(prefix) + (0, utils_1.binToHex)(encodedKey);
721
- return (0, utils_1.subContractId)(parentContractId, path, group);
721
+ return (0, address_1.subContractId)(parentContractId, path, group);
722
722
  }
723
723
  function genCodeForType(type, structs) {
724
724
  const { immFields, mutFields } = ralph.calcFieldSize(type, true, structs);
@@ -766,7 +766,7 @@ function genCodeForType(type, structs) {
766
766
  fieldLength: immFields + mutFields + 1,
767
767
  methods: [loadImmFieldByIndex, loadMutFieldByIndex, storeMutFieldByIndex, destroy]
768
768
  };
769
- const bytecode = codec_1.contract.contractCodec.encode(codec_1.contract.toHalfDecoded(c));
769
+ const bytecode = codec_1.contract.contractCodec.encodeContract(c);
770
770
  const codeHash = blake.blake2b(bytecode, undefined, 32);
771
771
  return { bytecode: (0, utils_1.binToHex)(bytecode), codeHash: (0, utils_1.binToHex)(codeHash) };
772
772
  }
@@ -785,7 +785,7 @@ function mapToExistingContracts(contract, parentContractId, group, map, mapIndex
785
785
  const contractId = calcWrapperContractId(parentContractId, mapIndex, key, keyType, group);
786
786
  return {
787
787
  ...generatedContract,
788
- address: (0, utils_1.addressFromContractId)(contractId),
788
+ address: (0, address_1.addressFromContractId)(contractId),
789
789
  contractId: contractId,
790
790
  fieldsSig: getContractFieldsSig(valueType),
791
791
  fields,
@@ -811,8 +811,8 @@ function mapsToExistingContracts(contract, parentContractId, group, initialMaps)
811
811
  async function testMethod(factory, methodName, params, getContractByCodeHash) {
812
812
  const txId = params?.txId ?? randomTxId();
813
813
  const contract = factory.contract;
814
- const address = params.address ?? (0, utils_1.addressFromContractId)((0, utils_1.binToHex)(crypto.getRandomValues(new Uint8Array(32))));
815
- const contractId = (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(address));
814
+ const address = params.address ?? (0, address_1.addressFromContractId)((0, utils_1.binToHex)(crypto.getRandomValues(new Uint8Array(32))));
815
+ const contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
816
816
  const group = params.group ?? 0;
817
817
  const initialMaps = params.initialMaps ?? {};
818
818
  const contractStates = mapsToExistingContracts(contract, contractId, group, initialMaps);
@@ -839,7 +839,7 @@ class RalphMap {
839
839
  this.parentContract = parentContract;
840
840
  this.parentContractId = parentContractId;
841
841
  this.mapName = mapName;
842
- this.groupIndex = (0, utils_1.groupOfAddress)((0, utils_1.addressFromContractId)(parentContractId));
842
+ this.groupIndex = (0, address_1.groupOfAddress)((0, address_1.addressFromContractId)(parentContractId));
843
843
  }
844
844
  async get(key) {
845
845
  return getMapItem(this.parentContract, this.parentContractId, this.groupIndex, this.mapName, key);
@@ -864,7 +864,7 @@ async function getMapItem(parentContract, parentContractId, groupIndex, mapName,
864
864
  }
865
865
  const [keyType, valueType] = ralph.parseMapType(mapType);
866
866
  const mapItemContractId = calcWrapperContractId(parentContractId, index, key, keyType, groupIndex);
867
- const mapItemAddress = (0, utils_1.addressFromContractId)(mapItemContractId);
867
+ const mapItemAddress = (0, address_1.addressFromContractId)(mapItemContractId);
868
868
  try {
869
869
  const state = await (0, global_1.getCurrentNodeProvider)().contracts.getContractsAddressState(mapItemAddress);
870
870
  const fieldsSig = getContractFieldsSig(valueType);
@@ -892,7 +892,7 @@ function buildMapInfo(contract, fields) {
892
892
  });
893
893
  }
894
894
  function extractFromEventLog(contract, result, allMaps, address, group) {
895
- const parentContractId = (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(address));
895
+ const parentContractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
896
896
  const newInserted = [];
897
897
  result.debugMessages.forEach((message) => {
898
898
  if (message.contractAddress !== address)
@@ -902,12 +902,12 @@ function extractFromEventLog(contract, result, allMaps, address, group) {
902
902
  return;
903
903
  const map = allMaps[`${decoded.mapIndex}`];
904
904
  const decodedKey = ralph.decodePrimitive(decoded.encodedKey, map.keyType);
905
- const contractId = (0, utils_1.subContractId)(parentContractId, decoded.path, group);
905
+ const contractId = (0, address_1.subContractId)(parentContractId, decoded.path, group);
906
906
  if (!decoded.isInsert) {
907
907
  map.value.delete(decodedKey);
908
908
  return;
909
909
  }
910
- const state = result.contracts.find((s) => s.address === (0, utils_1.addressFromContractId)(contractId));
910
+ const state = result.contracts.find((s) => s.address === (0, address_1.addressFromContractId)(contractId));
911
911
  if (state === undefined) {
912
912
  throw new Error(`Cannot find contract state for map value, map field: ${map.name}, value type: ${map.valueType}`);
913
913
  }
@@ -919,12 +919,12 @@ function extractFromEventLog(contract, result, allMaps, address, group) {
919
919
  return newInserted;
920
920
  }
921
921
  function updateMaps(contract, result, allMaps, address, group) {
922
- const parentContractId = (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(address));
922
+ const parentContractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
923
923
  const updated = [];
924
924
  allMaps.forEach((map) => {
925
925
  Array.from(map.value.keys()).forEach((key) => {
926
926
  const contractId = calcWrapperContractId(parentContractId, map.index, key, map.keyType, group);
927
- const updatedState = result.contracts.find((s) => s.address === (0, utils_1.addressFromContractId)(contractId));
927
+ const updatedState = result.contracts.find((s) => s.address === (0, address_1.addressFromContractId)(contractId));
928
928
  if (updatedState === undefined)
929
929
  return;
930
930
  updated.push(updatedState.address);
@@ -950,8 +950,8 @@ function existingContractsToMaps(contract, address, group, result, maps) {
950
950
  class ContractInstance {
951
951
  constructor(address) {
952
952
  this.address = address;
953
- this.contractId = (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(address));
954
- this.groupIndex = (0, utils_1.groupOfAddress)(address);
953
+ this.contractId = (0, utils_1.binToHex)((0, address_1.contractIdFromAddress)(address));
954
+ this.groupIndex = (0, address_1.groupOfAddress)(address);
955
955
  }
956
956
  }
957
957
  exports.ContractInstance = ContractInstance;
@@ -5,7 +5,7 @@ export declare function encodeBool(bool: boolean): Uint8Array;
5
5
  export declare function decodeBool(bytes: Uint8Array): boolean;
6
6
  export declare function encodeI256(i256: bigint): Uint8Array;
7
7
  export declare function encodeU256(u256: bigint): Uint8Array;
8
- export declare function encodeByteVec(bytes: string): Uint8Array;
8
+ export declare function encodeByteVec(hex: string): Uint8Array;
9
9
  export declare function encodeAddress(address: string): Uint8Array;
10
10
  export declare enum VmValType {
11
11
  Bool = 0,
@@ -19,7 +19,6 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
19
19
  var _a;
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.buildDebugBytecode = exports.encodeContractField = exports.buildContractByteCode = exports.encodeContractFields = exports.buildScriptByteCode = exports.flattenFields = exports.primitiveToByteVec = exports.decodePrimitive = exports.tryDecodeMapDebugLog = exports.calcFieldSize = exports.encodeMapPrefix = exports.parseMapType = exports.splitFields = exports.encodeScriptField = exports.encodeScriptFieldAsString = exports.encodePrimitiveValues = exports.addressVal = exports.byteVecVal = exports.u256Val = exports.i256Val = exports.boolVal = exports.encodeVmAddress = exports.encodeVmByteVec = exports.encodeVmU256 = exports.encodeVmI256 = exports.encodeVmBool = exports.VmValType = exports.encodeAddress = exports.encodeByteVec = exports.encodeU256 = exports.encodeI256 = exports.decodeBool = exports.encodeBool = void 0;
22
- const buffer_1 = require("buffer/");
23
22
  const api_1 = require("../api");
24
23
  const utils_1 = require("../utils");
25
24
  const codec_1 = require("../codec");
@@ -159,13 +158,13 @@ function encodeU256(u256) {
159
158
  }
160
159
  }
161
160
  exports.encodeU256 = encodeU256;
162
- function encodeByteVec(bytes) {
163
- if (!(0, utils_1.isHexString)(bytes)) {
164
- throw Error(`Given value ${bytes} is not a valid hex string`);
161
+ function encodeByteVec(hex) {
162
+ if (!(0, utils_1.isHexString)(hex)) {
163
+ throw Error(`Given value ${hex} is not a valid hex string`);
165
164
  }
166
- const buffer0 = buffer_1.Buffer.from(bytes, 'hex');
167
- const buffer1 = buffer_1.Buffer.from(encodeI256(BigInt(buffer0.length)));
168
- return buffer_1.Buffer.concat([buffer1, buffer0]);
165
+ const bytes0 = (0, utils_1.hexToBinUnsafe)(hex);
166
+ const bytes1 = encodeI256(BigInt(bytes0.length));
167
+ return (0, utils_1.concatBytes)([bytes1, bytes0]);
169
168
  }
170
169
  exports.encodeByteVec = encodeByteVec;
171
170
  function encodeAddress(address) {
@@ -258,7 +257,7 @@ function encodeScriptFieldU256(value) {
258
257
  return new Uint8Array([Instruction.u256Const, ...encodeU256(value)]);
259
258
  }
260
259
  function encodeScriptFieldAsString(tpe, value) {
261
- return buffer_1.Buffer.from(encodeScriptField(tpe, value)).toString('hex');
260
+ return (0, utils_1.binToHex)(encodeScriptField(tpe, value));
262
261
  }
263
262
  exports.encodeScriptFieldAsString = encodeScriptFieldAsString;
264
263
  function encodeScriptField(tpe, value) {
@@ -369,9 +368,9 @@ function decodePrimitive(value, type) {
369
368
  case 'Bool':
370
369
  return decodeBool(value);
371
370
  case 'I256':
372
- return codec_1.compactSignedIntCodec.decodeI256(buffer_1.Buffer.from(value));
371
+ return codec_1.compactSignedIntCodec.decodeI256(value);
373
372
  case 'U256':
374
- return codec_1.compactUnsignedIntCodec.decodeU256(buffer_1.Buffer.from(value));
373
+ return codec_1.compactUnsignedIntCodec.decodeU256(value);
375
374
  case 'ByteVec':
376
375
  return (0, utils_1.binToHex)(value);
377
376
  case 'Address':
@@ -18,9 +18,9 @@ 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.getAddressFromUnlockScript = exports.getSenderAddress = exports.getALPHDepositInfo = exports.isALPHTransferTx = exports.validateExchangeAddress = void 0;
21
+ const address_1 = require("../address");
21
22
  const utils_1 = require("../utils");
22
23
  const unlock_script_codec_1 = require("../codec/unlock-script-codec");
23
- const buffer_1 = require("buffer/");
24
24
  const script_codec_1 = require("../codec/script-codec");
25
25
  function validateExchangeAddress(address) {
26
26
  let decoded;
@@ -33,7 +33,7 @@ function validateExchangeAddress(address) {
33
33
  if (decoded.length === 0)
34
34
  throw new Error('Address is empty');
35
35
  const addressType = decoded[0];
36
- if (addressType !== utils_1.AddressType.P2PKH && addressType !== utils_1.AddressType.P2SH) {
36
+ if (addressType !== address_1.AddressType.P2PKH && addressType !== address_1.AddressType.P2SH) {
37
37
  throw new Error('Invalid address type');
38
38
  }
39
39
  if (decoded.length !== 33) {
@@ -98,7 +98,7 @@ function getAddressFromUnlockScript(unlockScript) {
98
98
  if (unlockScriptBody.length !== 33) {
99
99
  throw new Error(`Invalid p2pkh unlock script: ${unlockScript}`);
100
100
  }
101
- return (0, utils_1.addressFromPublicKey)((0, utils_1.binToHex)(unlockScriptBody));
101
+ return (0, address_1.addressFromPublicKey)((0, utils_1.binToHex)(unlockScriptBody));
102
102
  }
103
103
  if (unlockScriptType === UnlockScriptType.P2MPKH) {
104
104
  throw new Error('Naive multi-sig address is not supported for exchanges as it will be replaced by P2SH');
@@ -106,12 +106,12 @@ function getAddressFromUnlockScript(unlockScript) {
106
106
  if (unlockScriptType === UnlockScriptType.P2SH) {
107
107
  let p2sh;
108
108
  try {
109
- p2sh = unlock_script_codec_1.unlockScriptCodec.decode(buffer_1.Buffer.from(decoded)).script;
109
+ p2sh = unlock_script_codec_1.unlockScriptCodec.decode(decoded).script;
110
110
  }
111
111
  catch (_) {
112
112
  throw new Error(`Invalid p2sh unlock script: ${unlockScript}`);
113
113
  }
114
- return (0, utils_1.addressFromScript)(script_codec_1.scriptCodec.encode(p2sh.script));
114
+ return (0, address_1.addressFromScript)(script_codec_1.scriptCodec.encode(p2sh.script));
115
115
  }
116
116
  throw new Error('Invalid unlock script type');
117
117
  }
@@ -0,0 +1 @@
1
+ export { validateExchangeAddress, isALPHTransferTx, getSenderAddress, getALPHDepositInfo } from './exchange';
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /*
3
+ Copyright 2018 - 2022 The Alephium Authors
4
+ This file is part of the alephium project.
5
+
6
+ The library is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU Lesser General Public License as published by
8
+ the Free Software Foundation, either version 3 of the License, or
9
+ (at your option) any later version.
10
+
11
+ The library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public License
17
+ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.getALPHDepositInfo = exports.getSenderAddress = exports.isALPHTransferTx = exports.validateExchangeAddress = void 0;
21
+ var exchange_1 = require("./exchange");
22
+ Object.defineProperty(exports, "validateExchangeAddress", { enumerable: true, get: function () { return exchange_1.validateExchangeAddress; } });
23
+ Object.defineProperty(exports, "isALPHTransferTx", { enumerable: true, get: function () { return exchange_1.isALPHTransferTx; } });
24
+ Object.defineProperty(exports, "getSenderAddress", { enumerable: true, get: function () { return exchange_1.getSenderAddress; } });
25
+ Object.defineProperty(exports, "getALPHDepositInfo", { enumerable: true, get: function () { return exchange_1.getALPHDepositInfo; } });
@@ -10,3 +10,5 @@ export * as codec from './codec';
10
10
  export * as utils from './utils';
11
11
  export * from './debug';
12
12
  export * from './block';
13
+ export * from './address';
14
+ export * from './exchange';
package/dist/src/index.js CHANGED
@@ -59,3 +59,5 @@ exports.codec = __importStar(require("./codec"));
59
59
  exports.utils = __importStar(require("./utils"));
60
60
  __exportStar(require("./debug"), exports);
61
61
  __exportStar(require("./block"), exports);
62
+ __exportStar(require("./address"), exports);
63
+ __exportStar(require("./exchange"), exports);
@@ -44,13 +44,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
44
44
  };
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
46
  exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.hashMessage = exports.extendMessage = exports.SignerProviderWithCachedAccounts = exports.SignerProviderWithMultipleAccounts = exports.SignerProviderSimple = exports.InteractiveSignerProvider = exports.SignerProvider = void 0;
47
- const buffer_1 = require("buffer/");
48
47
  const crypto_1 = require("crypto");
49
48
  const api_1 = require("../api");
50
49
  const utils = __importStar(require("../utils"));
51
50
  const blakejs_1 = __importDefault(require("blakejs"));
52
51
  const tx_builder_1 = require("./tx-builder");
53
- const utils_1 = require("../utils");
52
+ const address_1 = require("../address");
54
53
  class SignerProvider {
55
54
  async getSelectedAccount() {
56
55
  const account = await this.unsafeGetSelectedAccount();
@@ -58,8 +57,8 @@ class SignerProvider {
58
57
  return account;
59
58
  }
60
59
  static validateAccount(account) {
61
- const derivedAddress = (0, utils_1.addressFromPublicKey)(account.publicKey, account.keyType);
62
- const derivedGroup = (0, utils_1.groupOfAddress)(derivedAddress);
60
+ const derivedAddress = (0, address_1.addressFromPublicKey)(account.publicKey, account.keyType);
61
+ const derivedGroup = (0, address_1.groupOfAddress)(derivedAddress);
63
62
  if (derivedAddress !== account.address || derivedGroup !== account.group) {
64
63
  throw Error(`Invalid accounot data: ${JSON.stringify(account)}`);
65
64
  }
@@ -206,7 +205,7 @@ function hashMessage(message, hasher) {
206
205
  return utils.binToHex(blakejs_1.default.blake2b(extendMessage(message), undefined, 32));
207
206
  case 'sha256':
208
207
  const sha256 = (0, crypto_1.createHash)('sha256');
209
- sha256.update(buffer_1.Buffer.from(message));
208
+ sha256.update(new TextEncoder().encode(message));
210
209
  return utils.binToHex(sha256.digest());
211
210
  case 'blake2b':
212
211
  return utils.binToHex(blakejs_1.default.blake2b(message, undefined, 32));