@taquito/sapling 23.0.0-beta.0 → 23.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,13 +6,28 @@ const typedarray_to_buffer_1 = require("typedarray-to-buffer");
6
6
  const nacl_1 = require("@stablelib/nacl");
7
7
  const pbkdf2_1 = require("pbkdf2");
8
8
  const utils_1 = require("@taquito/utils");
9
+ const core_1 = require("@taquito/core");
9
10
  function decryptKey(spendingKey, password) {
10
- const keyArr = (0, utils_1.b58cdecode)(spendingKey, utils_1.prefix[utils_1.Prefix.SASK]);
11
- // exit first if no password and key is encrypted
12
- if (!password && spendingKey.slice(0, 4) !== 'sask') {
13
- throw new errors_1.InvalidSpendingKey(spendingKey, 'no password provided to decrypt');
14
- }
15
- if (password && spendingKey.slice(0, 4) !== 'sask') {
11
+ const [keyArr, pre] = (() => {
12
+ try {
13
+ return (0, utils_1.b58DecodeAndCheckPrefix)(spendingKey, [
14
+ utils_1.PrefixV2.SaplingSpendingKey,
15
+ utils_1.PrefixV2.EncryptedSaplingSpendingKey,
16
+ ]);
17
+ }
18
+ catch (err) {
19
+ if (err instanceof core_1.ParameterValidationError) {
20
+ throw new errors_1.InvalidSpendingKey(spendingKey, 'invalid spending key');
21
+ }
22
+ else {
23
+ throw err;
24
+ }
25
+ }
26
+ })();
27
+ if (pre === utils_1.PrefixV2.EncryptedSaplingSpendingKey) {
28
+ if (!password) {
29
+ throw new errors_1.InvalidSpendingKey(spendingKey, 'no password provided to decrypt');
30
+ }
16
31
  const salt = (0, typedarray_to_buffer_1.default)(keyArr.slice(0, 8));
17
32
  const encryptedSk = (0, typedarray_to_buffer_1.default)(keyArr.slice(8));
18
33
  const encryptionKey = pbkdf2_1.default.pbkdf2Sync(password, salt, 32768, 32, 'sha512');
@@ -58,7 +58,7 @@ class InMemorySpendingKey {
58
58
  // reduce seed bytes must be 32 bytes reflecting both halves
59
59
  const seed = Buffer.from(first32.map((byte, index) => byte ^ second32[index]));
60
60
  const spendingKeyArr = new Uint8Array(yield sapling.getExtendedSpendingKey(seed, derivationPath));
61
- const spendingKey = (0, utils_1.b58cencode)(spendingKeyArr, utils_1.prefix[utils_1.Prefix.SASK]);
61
+ const spendingKey = (0, utils_1.b58Encode)(spendingKeyArr, utils_1.PrefixV2.SaplingSpendingKey);
62
62
  return new InMemorySpendingKey(spendingKey);
63
63
  });
64
64
  }
@@ -88,7 +88,7 @@ class InMemoryViewingKey {
88
88
  return __awaiter(this, void 0, void 0, function* () {
89
89
  const { index, raw } = yield sapling.getPaymentAddressFromViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"), addressIndex);
90
90
  return {
91
- address: (0, utils_1.b58cencode)(raw, utils_1.prefix[utils_1.Prefix.ZET1]),
91
+ address: (0, utils_1.b58Encode)(raw, utils_1.PrefixV2.SaplingAddress),
92
92
  addressIndex: index.readInt32LE(),
93
93
  };
94
94
  });
@@ -60,9 +60,12 @@ class SaplingTransactionBuilder {
60
60
  const outputs = [];
61
61
  const inputs = [];
62
62
  for (const i in saplingTransactionParams) {
63
+ const [address] = (0, utils_1.b58DecodeAndCheckPrefix)(saplingTransactionParams[i].to, [
64
+ utils_1.PrefixV2.SaplingAddress,
65
+ ]);
63
66
  outputs.push(yield this.prepareSaplingOutputDescription({
64
67
  saplingContext,
65
- address: (0, utils_1.b58cdecode)(saplingTransactionParams[i].to, utils_1.prefix[utils_1.Prefix.ZET1]),
68
+ address,
66
69
  amount: saplingTransactionParams[i].amount,
67
70
  memo: saplingTransactionParams[i].memo,
68
71
  randomCommitmentTrapdoor: rcm,
@@ -97,9 +100,12 @@ class SaplingTransactionBuilder {
97
100
  let sumAmountOutput = new bignumber_js_1.default(0);
98
101
  for (const i in saplingTransactionParams) {
99
102
  sumAmountOutput = sumAmountOutput.plus(new bignumber_js_1.default(saplingTransactionParams[i].amount));
103
+ const [address] = (0, utils_1.b58DecodeAndCheckPrefix)(saplingTransactionParams[i].to, [
104
+ utils_1.PrefixV2.SaplingAddress,
105
+ ]);
100
106
  outputs.push(yield this.prepareSaplingOutputDescription({
101
107
  saplingContext,
102
- address: (0, utils_1.b58cdecode)(saplingTransactionParams[i].to, utils_1.prefix[utils_1.Prefix.ZET1]),
108
+ address,
103
109
  amount: saplingTransactionParams[i].amount,
104
110
  memo: saplingTransactionParams[i].memo,
105
111
  randomCommitmentTrapdoor,
@@ -108,9 +114,10 @@ class SaplingTransactionBuilder {
108
114
  }
109
115
  if (chosenInputs.sumSelectedInputs.isGreaterThan(sumAmountOutput)) {
110
116
  const payBackAddress = (yield saplingViewer.getAddress()).address;
117
+ const [address] = (0, utils_1.b58DecodeAndCheckPrefix)(payBackAddress, [utils_1.PrefixV2.SaplingAddress]);
111
118
  const { payBackOutput, payBackAmount } = yield this.createPaybackOutput({
112
119
  saplingContext,
113
- address: (0, utils_1.b58cdecode)(payBackAddress, utils_1.prefix[utils_1.Prefix.ZET1]),
120
+ address,
114
121
  amount: txTotalAmount.toString(),
115
122
  memo: constants_1.DEFAULT_MEMO,
116
123
  randomCommitmentTrapdoor: randomCommitmentTrapdoor,
@@ -18,7 +18,7 @@ function readableFormat(saplingTransactionProperties) {
18
18
  return {
19
19
  value: convertValueToBigNumber(saplingTransactionProperties.value),
20
20
  memo: memoHexToUtf8(Buffer.from(saplingTransactionProperties.memo).toString('hex')),
21
- paymentAddress: (0, utils_1.b58cencode)(saplingTransactionProperties.paymentAddress, utils_1.prefix[utils_1.Prefix.ZET1]),
21
+ paymentAddress: (0, utils_1.b58Encode)(saplingTransactionProperties.paymentAddress, utils_1.PrefixV2.SaplingAddress),
22
22
  };
23
23
  }
24
24
  function convertValueToBigNumber(value) {
@@ -217,30 +217,9 @@ class SaplingToolkit {
217
217
  }
218
218
  createBoundData(destination) {
219
219
  return __awaiter(this, void 0, void 0, function* () {
220
- const pref = destination.substring(0, 3);
221
- let pad;
222
- switch (pref) {
223
- case 'tz1': {
224
- pad = Buffer.from('00', 'hex');
225
- break;
226
- }
227
- case 'tz2': {
228
- pad = Buffer.from('01', 'hex');
229
- break;
230
- }
231
- case 'tz3': {
232
- pad = Buffer.from('02', 'hex');
233
- break;
234
- }
235
- default: {
236
- throw new core_1.InvalidAddressError(destination, (0, utils_1.invalidDetail)(utils_1.ValidationResult.NO_PREFIX_MATCHED) +
237
- ` expecting one of the following prefix '${utils_1.Prefix.TZ1}', '${utils_1.Prefix.TZ2}' or '${utils_1.Prefix.TZ3}'.`);
238
- }
239
- }
240
- const decodedDestination = (0, utils_1.b58cdecode)(destination, utils_1.prefix[pref]);
241
- const padDestination = Buffer.concat([pad, Buffer.from(decodedDestination)]);
220
+ const bytes = (0, utils_1.b58DecodePublicKeyHash)(destination, 'hex');
242
221
  const packedDestination = yield __classPrivateFieldGet(this, _SaplingToolkit_packer, "f").packData({
243
- data: { bytes: padDestination.toString('hex') },
222
+ data: { bytes },
244
223
  type: { prim: 'bytes' },
245
224
  });
246
225
  return Buffer.from(packedDestination.packed, 'hex');
@@ -249,12 +228,15 @@ class SaplingToolkit {
249
228
  validateDestinationImplicitAddress(to) {
250
229
  const toValidation = (0, utils_1.validateKeyHash)(to);
251
230
  if (toValidation !== utils_1.ValidationResult.VALID) {
252
- throw new core_1.InvalidKeyHashError(to, (0, utils_1.invalidDetail)(toValidation));
231
+ throw new core_1.InvalidKeyHashError(to, toValidation);
253
232
  }
254
233
  }
255
234
  validateDestinationSaplingAddress(to) {
256
- if (!to.startsWith(utils_1.Prefix.ZET1)) {
257
- throw new core_1.InvalidAddressError(to, (0, utils_1.invalidDetail)(utils_1.ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix ${utils_1.Prefix.ZET1}.`);
235
+ try {
236
+ (0, utils_1.b58DecodeAndCheckPrefix)(to, [utils_1.PrefixV2.SaplingAddress]);
237
+ }
238
+ catch (_a) {
239
+ throw new core_1.InvalidAddressError(to, `expecting prefix ${utils_1.PrefixV2.SaplingAddress}.`);
258
240
  }
259
241
  }
260
242
  getSaplingContractId() {
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // IMPORTANT: THIS FILE IS AUTO GENERATED! DO NOT MANUALLY EDIT OR CHECKIN!
5
5
  exports.VERSION = {
6
- "commitHash": "7af2138a9e5c5b230c4b4c726f35c2f2e67b721c",
7
- "version": "23.0.0-beta.0"
6
+ "commitHash": "10b3de10de15ae68d47b1fca922d3129d2f79641",
7
+ "version": "23.0.0-beta.1"
8
8
  };
@@ -1,6 +1,6 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  import { MichelCodecPacker } from '@taquito/taquito';
3
- import { b58cencode, prefix, Prefix, bytesToString, toHexBuf, stringToBytes, hex2buf, mergebuf, hex2Bytes, num2PaddedHex, b58cdecode, format, validateKeyHash, ValidationResult, invalidDetail } from '@taquito/utils';
3
+ import { b58Encode, PrefixV2, bytesToString, toHexBuf, stringToBytes, hex2buf, mergebuf, hex2Bytes, num2PaddedHex, b58DecodeAndCheckPrefix, format, validateKeyHash, ValidationResult, b58DecodePublicKeyHash } from '@taquito/utils';
4
4
  import { ParameterValidationError, TaquitoError, InvalidKeyHashError, InvalidAddressError } from '@taquito/core';
5
5
  import * as sapling from '@airgap/sapling-wasm';
6
6
  import { merkleHash } from '@airgap/sapling-wasm';
@@ -154,7 +154,7 @@ function readableFormat(saplingTransactionProperties) {
154
154
  return {
155
155
  value: convertValueToBigNumber(saplingTransactionProperties.value),
156
156
  memo: memoHexToUtf8(Buffer.from(saplingTransactionProperties.memo).toString('hex')),
157
- paymentAddress: b58cencode(saplingTransactionProperties.paymentAddress, prefix[Prefix.ZET1]),
157
+ paymentAddress: b58Encode(saplingTransactionProperties.paymentAddress, PrefixV2.SaplingAddress),
158
158
  };
159
159
  }
160
160
  function convertValueToBigNumber(value) {
@@ -747,9 +747,12 @@ class SaplingTransactionBuilder {
747
747
  const outputs = [];
748
748
  const inputs = [];
749
749
  for (const i in saplingTransactionParams) {
750
+ const [address] = b58DecodeAndCheckPrefix(saplingTransactionParams[i].to, [
751
+ PrefixV2.SaplingAddress,
752
+ ]);
750
753
  outputs.push(yield this.prepareSaplingOutputDescription({
751
754
  saplingContext,
752
- address: b58cdecode(saplingTransactionParams[i].to, prefix[Prefix.ZET1]),
755
+ address,
753
756
  amount: saplingTransactionParams[i].amount,
754
757
  memo: saplingTransactionParams[i].memo,
755
758
  randomCommitmentTrapdoor: rcm,
@@ -784,9 +787,12 @@ class SaplingTransactionBuilder {
784
787
  let sumAmountOutput = new BigNumber(0);
785
788
  for (const i in saplingTransactionParams) {
786
789
  sumAmountOutput = sumAmountOutput.plus(new BigNumber(saplingTransactionParams[i].amount));
790
+ const [address] = b58DecodeAndCheckPrefix(saplingTransactionParams[i].to, [
791
+ PrefixV2.SaplingAddress,
792
+ ]);
787
793
  outputs.push(yield this.prepareSaplingOutputDescription({
788
794
  saplingContext,
789
- address: b58cdecode(saplingTransactionParams[i].to, prefix[Prefix.ZET1]),
795
+ address,
790
796
  amount: saplingTransactionParams[i].amount,
791
797
  memo: saplingTransactionParams[i].memo,
792
798
  randomCommitmentTrapdoor,
@@ -795,9 +801,10 @@ class SaplingTransactionBuilder {
795
801
  }
796
802
  if (chosenInputs.sumSelectedInputs.isGreaterThan(sumAmountOutput)) {
797
803
  const payBackAddress = (yield saplingViewer.getAddress()).address;
804
+ const [address] = b58DecodeAndCheckPrefix(payBackAddress, [PrefixV2.SaplingAddress]);
798
805
  const { payBackOutput, payBackAmount } = yield this.createPaybackOutput({
799
806
  saplingContext,
800
- address: b58cdecode(payBackAddress, prefix[Prefix.ZET1]),
807
+ address,
801
808
  amount: txTotalAmount.toString(),
802
809
  memo: DEFAULT_MEMO,
803
810
  randomCommitmentTrapdoor: randomCommitmentTrapdoor,
@@ -972,12 +979,26 @@ class SaplingTransactionBuilder {
972
979
  _SaplingTransactionBuilder_inMemorySpendingKey = new WeakMap(), _SaplingTransactionBuilder_inMemoryProvingKey = new WeakMap(), _SaplingTransactionBuilder_saplingForger = new WeakMap(), _SaplingTransactionBuilder_contractAddress = new WeakMap(), _SaplingTransactionBuilder_saplingId = new WeakMap(), _SaplingTransactionBuilder_memoSize = new WeakMap(), _SaplingTransactionBuilder_readProvider = new WeakMap(), _SaplingTransactionBuilder_saplingWrapper = new WeakMap(), _SaplingTransactionBuilder_chainId = new WeakMap(), _SaplingTransactionBuilder_saplingState = new WeakMap();
973
980
 
974
981
  function decryptKey(spendingKey, password) {
975
- const keyArr = b58cdecode(spendingKey, prefix[Prefix.SASK]);
976
- // exit first if no password and key is encrypted
977
- if (!password && spendingKey.slice(0, 4) !== 'sask') {
978
- throw new InvalidSpendingKey(spendingKey, 'no password provided to decrypt');
979
- }
980
- if (password && spendingKey.slice(0, 4) !== 'sask') {
982
+ const [keyArr, pre] = (() => {
983
+ try {
984
+ return b58DecodeAndCheckPrefix(spendingKey, [
985
+ PrefixV2.SaplingSpendingKey,
986
+ PrefixV2.EncryptedSaplingSpendingKey,
987
+ ]);
988
+ }
989
+ catch (err) {
990
+ if (err instanceof ParameterValidationError) {
991
+ throw new InvalidSpendingKey(spendingKey, 'invalid spending key');
992
+ }
993
+ else {
994
+ throw err;
995
+ }
996
+ }
997
+ })();
998
+ if (pre === PrefixV2.EncryptedSaplingSpendingKey) {
999
+ if (!password) {
1000
+ throw new InvalidSpendingKey(spendingKey, 'no password provided to decrypt');
1001
+ }
981
1002
  const salt = toBuffer(keyArr.slice(0, 8));
982
1003
  const encryptedSk = toBuffer(keyArr.slice(8));
983
1004
  const encryptionKey = pbkdf2.pbkdf2Sync(password, salt, 32768, 32, 'sha512');
@@ -1024,7 +1045,7 @@ class InMemorySpendingKey {
1024
1045
  // reduce seed bytes must be 32 bytes reflecting both halves
1025
1046
  const seed = Buffer.from(first32.map((byte, index) => byte ^ second32[index]));
1026
1047
  const spendingKeyArr = new Uint8Array(yield sapling.getExtendedSpendingKey(seed, derivationPath));
1027
- const spendingKey = b58cencode(spendingKeyArr, prefix[Prefix.SASK]);
1048
+ const spendingKey = b58Encode(spendingKeyArr, PrefixV2.SaplingSpendingKey);
1028
1049
  return new InMemorySpendingKey(spendingKey);
1029
1050
  });
1030
1051
  }
@@ -1167,7 +1188,7 @@ class InMemoryViewingKey {
1167
1188
  return __awaiter(this, void 0, void 0, function* () {
1168
1189
  const { index, raw } = yield sapling.getPaymentAddressFromViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"), addressIndex);
1169
1190
  return {
1170
- address: b58cencode(raw, prefix[Prefix.ZET1]),
1191
+ address: b58Encode(raw, PrefixV2.SaplingAddress),
1171
1192
  addressIndex: index.readInt32LE(),
1172
1193
  };
1173
1194
  });
@@ -1398,30 +1419,9 @@ class SaplingToolkit {
1398
1419
  }
1399
1420
  createBoundData(destination) {
1400
1421
  return __awaiter(this, void 0, void 0, function* () {
1401
- const pref = destination.substring(0, 3);
1402
- let pad;
1403
- switch (pref) {
1404
- case 'tz1': {
1405
- pad = Buffer.from('00', 'hex');
1406
- break;
1407
- }
1408
- case 'tz2': {
1409
- pad = Buffer.from('01', 'hex');
1410
- break;
1411
- }
1412
- case 'tz3': {
1413
- pad = Buffer.from('02', 'hex');
1414
- break;
1415
- }
1416
- default: {
1417
- throw new InvalidAddressError(destination, invalidDetail(ValidationResult.NO_PREFIX_MATCHED) +
1418
- ` expecting one of the following prefix '${Prefix.TZ1}', '${Prefix.TZ2}' or '${Prefix.TZ3}'.`);
1419
- }
1420
- }
1421
- const decodedDestination = b58cdecode(destination, prefix[pref]);
1422
- const padDestination = Buffer.concat([pad, Buffer.from(decodedDestination)]);
1422
+ const bytes = b58DecodePublicKeyHash(destination, 'hex');
1423
1423
  const packedDestination = yield __classPrivateFieldGet(this, _SaplingToolkit_packer, "f").packData({
1424
- data: { bytes: padDestination.toString('hex') },
1424
+ data: { bytes },
1425
1425
  type: { prim: 'bytes' },
1426
1426
  });
1427
1427
  return Buffer.from(packedDestination.packed, 'hex');
@@ -1430,12 +1430,15 @@ class SaplingToolkit {
1430
1430
  validateDestinationImplicitAddress(to) {
1431
1431
  const toValidation = validateKeyHash(to);
1432
1432
  if (toValidation !== ValidationResult.VALID) {
1433
- throw new InvalidKeyHashError(to, invalidDetail(toValidation));
1433
+ throw new InvalidKeyHashError(to, toValidation);
1434
1434
  }
1435
1435
  }
1436
1436
  validateDestinationSaplingAddress(to) {
1437
- if (!to.startsWith(Prefix.ZET1)) {
1438
- throw new InvalidAddressError(to, invalidDetail(ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix ${Prefix.ZET1}.`);
1437
+ try {
1438
+ b58DecodeAndCheckPrefix(to, [PrefixV2.SaplingAddress]);
1439
+ }
1440
+ catch (_a) {
1441
+ throw new InvalidAddressError(to, `expecting prefix ${PrefixV2.SaplingAddress}.`);
1439
1442
  }
1440
1443
  }
1441
1444
  getSaplingContractId() {
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-sapling.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -167,7 +167,7 @@
167
167
  return {
168
168
  value: convertValueToBigNumber(saplingTransactionProperties.value),
169
169
  memo: memoHexToUtf8(Buffer.from(saplingTransactionProperties.memo).toString('hex')),
170
- paymentAddress: utils.b58cencode(saplingTransactionProperties.paymentAddress, utils.prefix[utils.Prefix.ZET1]),
170
+ paymentAddress: utils.b58Encode(saplingTransactionProperties.paymentAddress, utils.PrefixV2.SaplingAddress),
171
171
  };
172
172
  }
173
173
  function convertValueToBigNumber(value) {
@@ -760,9 +760,12 @@
760
760
  const outputs = [];
761
761
  const inputs = [];
762
762
  for (const i in saplingTransactionParams) {
763
+ const [address] = utils.b58DecodeAndCheckPrefix(saplingTransactionParams[i].to, [
764
+ utils.PrefixV2.SaplingAddress,
765
+ ]);
763
766
  outputs.push(yield this.prepareSaplingOutputDescription({
764
767
  saplingContext,
765
- address: utils.b58cdecode(saplingTransactionParams[i].to, utils.prefix[utils.Prefix.ZET1]),
768
+ address,
766
769
  amount: saplingTransactionParams[i].amount,
767
770
  memo: saplingTransactionParams[i].memo,
768
771
  randomCommitmentTrapdoor: rcm,
@@ -797,9 +800,12 @@
797
800
  let sumAmountOutput = new BigNumber(0);
798
801
  for (const i in saplingTransactionParams) {
799
802
  sumAmountOutput = sumAmountOutput.plus(new BigNumber(saplingTransactionParams[i].amount));
803
+ const [address] = utils.b58DecodeAndCheckPrefix(saplingTransactionParams[i].to, [
804
+ utils.PrefixV2.SaplingAddress,
805
+ ]);
800
806
  outputs.push(yield this.prepareSaplingOutputDescription({
801
807
  saplingContext,
802
- address: utils.b58cdecode(saplingTransactionParams[i].to, utils.prefix[utils.Prefix.ZET1]),
808
+ address,
803
809
  amount: saplingTransactionParams[i].amount,
804
810
  memo: saplingTransactionParams[i].memo,
805
811
  randomCommitmentTrapdoor,
@@ -808,9 +814,10 @@
808
814
  }
809
815
  if (chosenInputs.sumSelectedInputs.isGreaterThan(sumAmountOutput)) {
810
816
  const payBackAddress = (yield saplingViewer.getAddress()).address;
817
+ const [address] = utils.b58DecodeAndCheckPrefix(payBackAddress, [utils.PrefixV2.SaplingAddress]);
811
818
  const { payBackOutput, payBackAmount } = yield this.createPaybackOutput({
812
819
  saplingContext,
813
- address: utils.b58cdecode(payBackAddress, utils.prefix[utils.Prefix.ZET1]),
820
+ address,
814
821
  amount: txTotalAmount.toString(),
815
822
  memo: DEFAULT_MEMO,
816
823
  randomCommitmentTrapdoor: randomCommitmentTrapdoor,
@@ -985,12 +992,26 @@
985
992
  _SaplingTransactionBuilder_inMemorySpendingKey = new WeakMap(), _SaplingTransactionBuilder_inMemoryProvingKey = new WeakMap(), _SaplingTransactionBuilder_saplingForger = new WeakMap(), _SaplingTransactionBuilder_contractAddress = new WeakMap(), _SaplingTransactionBuilder_saplingId = new WeakMap(), _SaplingTransactionBuilder_memoSize = new WeakMap(), _SaplingTransactionBuilder_readProvider = new WeakMap(), _SaplingTransactionBuilder_saplingWrapper = new WeakMap(), _SaplingTransactionBuilder_chainId = new WeakMap(), _SaplingTransactionBuilder_saplingState = new WeakMap();
986
993
 
987
994
  function decryptKey(spendingKey, password) {
988
- const keyArr = utils.b58cdecode(spendingKey, utils.prefix[utils.Prefix.SASK]);
989
- // exit first if no password and key is encrypted
990
- if (!password && spendingKey.slice(0, 4) !== 'sask') {
991
- throw new InvalidSpendingKey(spendingKey, 'no password provided to decrypt');
992
- }
993
- if (password && spendingKey.slice(0, 4) !== 'sask') {
995
+ const [keyArr, pre] = (() => {
996
+ try {
997
+ return utils.b58DecodeAndCheckPrefix(spendingKey, [
998
+ utils.PrefixV2.SaplingSpendingKey,
999
+ utils.PrefixV2.EncryptedSaplingSpendingKey,
1000
+ ]);
1001
+ }
1002
+ catch (err) {
1003
+ if (err instanceof core.ParameterValidationError) {
1004
+ throw new InvalidSpendingKey(spendingKey, 'invalid spending key');
1005
+ }
1006
+ else {
1007
+ throw err;
1008
+ }
1009
+ }
1010
+ })();
1011
+ if (pre === utils.PrefixV2.EncryptedSaplingSpendingKey) {
1012
+ if (!password) {
1013
+ throw new InvalidSpendingKey(spendingKey, 'no password provided to decrypt');
1014
+ }
994
1015
  const salt = toBuffer(keyArr.slice(0, 8));
995
1016
  const encryptedSk = toBuffer(keyArr.slice(8));
996
1017
  const encryptionKey = pbkdf2.pbkdf2Sync(password, salt, 32768, 32, 'sha512');
@@ -1037,7 +1058,7 @@
1037
1058
  // reduce seed bytes must be 32 bytes reflecting both halves
1038
1059
  const seed = Buffer.from(first32.map((byte, index) => byte ^ second32[index]));
1039
1060
  const spendingKeyArr = new Uint8Array(yield sapling__namespace.getExtendedSpendingKey(seed, derivationPath));
1040
- const spendingKey = utils.b58cencode(spendingKeyArr, utils.prefix[utils.Prefix.SASK]);
1061
+ const spendingKey = utils.b58Encode(spendingKeyArr, utils.PrefixV2.SaplingSpendingKey);
1041
1062
  return new InMemorySpendingKey(spendingKey);
1042
1063
  });
1043
1064
  }
@@ -1180,7 +1201,7 @@
1180
1201
  return __awaiter(this, void 0, void 0, function* () {
1181
1202
  const { index, raw } = yield sapling__namespace.getPaymentAddressFromViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"), addressIndex);
1182
1203
  return {
1183
- address: utils.b58cencode(raw, utils.prefix[utils.Prefix.ZET1]),
1204
+ address: utils.b58Encode(raw, utils.PrefixV2.SaplingAddress),
1184
1205
  addressIndex: index.readInt32LE(),
1185
1206
  };
1186
1207
  });
@@ -1411,30 +1432,9 @@
1411
1432
  }
1412
1433
  createBoundData(destination) {
1413
1434
  return __awaiter(this, void 0, void 0, function* () {
1414
- const pref = destination.substring(0, 3);
1415
- let pad;
1416
- switch (pref) {
1417
- case 'tz1': {
1418
- pad = Buffer.from('00', 'hex');
1419
- break;
1420
- }
1421
- case 'tz2': {
1422
- pad = Buffer.from('01', 'hex');
1423
- break;
1424
- }
1425
- case 'tz3': {
1426
- pad = Buffer.from('02', 'hex');
1427
- break;
1428
- }
1429
- default: {
1430
- throw new core.InvalidAddressError(destination, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) +
1431
- ` expecting one of the following prefix '${utils.Prefix.TZ1}', '${utils.Prefix.TZ2}' or '${utils.Prefix.TZ3}'.`);
1432
- }
1433
- }
1434
- const decodedDestination = utils.b58cdecode(destination, utils.prefix[pref]);
1435
- const padDestination = Buffer.concat([pad, Buffer.from(decodedDestination)]);
1435
+ const bytes = utils.b58DecodePublicKeyHash(destination, 'hex');
1436
1436
  const packedDestination = yield __classPrivateFieldGet(this, _SaplingToolkit_packer, "f").packData({
1437
- data: { bytes: padDestination.toString('hex') },
1437
+ data: { bytes },
1438
1438
  type: { prim: 'bytes' },
1439
1439
  });
1440
1440
  return Buffer.from(packedDestination.packed, 'hex');
@@ -1443,12 +1443,15 @@
1443
1443
  validateDestinationImplicitAddress(to) {
1444
1444
  const toValidation = utils.validateKeyHash(to);
1445
1445
  if (toValidation !== utils.ValidationResult.VALID) {
1446
- throw new core.InvalidKeyHashError(to, utils.invalidDetail(toValidation));
1446
+ throw new core.InvalidKeyHashError(to, toValidation);
1447
1447
  }
1448
1448
  }
1449
1449
  validateDestinationSaplingAddress(to) {
1450
- if (!to.startsWith(utils.Prefix.ZET1)) {
1451
- throw new core.InvalidAddressError(to, utils.invalidDetail(utils.ValidationResult.NO_PREFIX_MATCHED) + ` expecting prefix ${utils.Prefix.ZET1}.`);
1450
+ try {
1451
+ utils.b58DecodeAndCheckPrefix(to, [utils.PrefixV2.SaplingAddress]);
1452
+ }
1453
+ catch (_a) {
1454
+ throw new core.InvalidAddressError(to, `expecting prefix ${utils.PrefixV2.SaplingAddress}.`);
1452
1455
  }
1453
1456
  }
1454
1457
  getSaplingContractId() {
@@ -1 +1 @@
1
- {"version":3,"file":"taquito-sapling.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taquito/sapling",
3
- "version": "23.0.0-beta.0",
3
+ "version": "23.0.0-beta.1",
4
4
  "description": "Allows reading and preparing sapling transactions",
5
5
  "keywords": [
6
6
  "tezos",
@@ -68,10 +68,10 @@
68
68
  "@airgap/sapling-wasm": "0.0.9",
69
69
  "@stablelib/nacl": "^1.0.4",
70
70
  "@stablelib/random": "^1.0.2",
71
- "@taquito/core": "^23.0.0-beta.0",
72
- "@taquito/rpc": "^23.0.0-beta.0",
73
- "@taquito/taquito": "^23.0.0-beta.0",
74
- "@taquito/utils": "^23.0.0-beta.0",
71
+ "@taquito/core": "^23.0.0-beta.1",
72
+ "@taquito/rpc": "^23.0.0-beta.1",
73
+ "@taquito/taquito": "^23.0.0-beta.1",
74
+ "@taquito/utils": "^23.0.0-beta.1",
75
75
  "bignumber.js": "^9.1.2",
76
76
  "bip39": "3.1.0",
77
77
  "blakejs": "^1.2.1",
@@ -106,5 +106,5 @@
106
106
  "ts-node": "^10.9.2",
107
107
  "typescript": "~5.5.4"
108
108
  },
109
- "gitHead": "37cc766d60407d7909fbd2d841d9dd946243d04a"
109
+ "gitHead": "1469d6f0d55134a4b853598a2eec48e6f71b3da3"
110
110
  }