@taquito/sapling 22.0.0-beta.0 → 23.0.0-RC.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.
- package/dist/lib/sapling-keys/helpers.js +21 -6
- package/dist/lib/sapling-keys/in-memory-spending-key.js +1 -1
- package/dist/lib/sapling-keys/in-memory-viewing-key.js +1 -1
- package/dist/lib/sapling-tx-builder/sapling-transactions-builder.js +10 -3
- package/dist/lib/sapling-tx-viewer/helpers.js +1 -1
- package/dist/lib/taquito-sapling.js +8 -26
- package/dist/lib/version.js +2 -2
- package/dist/taquito-sapling.es6.js +42 -39
- package/dist/taquito-sapling.es6.js.map +1 -1
- package/dist/taquito-sapling.umd.js +41 -38
- package/dist/taquito-sapling.umd.js.map +1 -1
- package/package.json +6 -6
|
@@ -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 = (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
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,
|
|
231
|
+
throw new core_1.InvalidKeyHashError(to, toValidation);
|
|
253
232
|
}
|
|
254
233
|
}
|
|
255
234
|
validateDestinationSaplingAddress(to) {
|
|
256
|
-
|
|
257
|
-
|
|
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() {
|
package/dist/lib/version.js
CHANGED
|
@@ -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": "
|
|
7
|
-
"version": "
|
|
6
|
+
"commitHash": "13639ef56845fbb7e93bcbd37d3f6d0457b0872b",
|
|
7
|
+
"version": "23.0.0-RC.0"
|
|
8
8
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { MichelCodecPacker } from '@taquito/taquito';
|
|
3
|
-
import {
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
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 =
|
|
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:
|
|
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
|
|
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
|
|
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,
|
|
1433
|
+
throw new InvalidKeyHashError(to, toValidation);
|
|
1434
1434
|
}
|
|
1435
1435
|
}
|
|
1436
1436
|
validateDestinationSaplingAddress(to) {
|
|
1437
|
-
|
|
1438
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"taquito-sapling.es6.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -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.
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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,
|
|
1446
|
+
throw new core.InvalidKeyHashError(to, toValidation);
|
|
1447
1447
|
}
|
|
1448
1448
|
}
|
|
1449
1449
|
validateDestinationSaplingAddress(to) {
|
|
1450
|
-
|
|
1451
|
-
|
|
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":"
|
|
1
|
+
{"version":3,"file":"taquito-sapling.umd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taquito/sapling",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "23.0.0-RC.0",
|
|
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": "^
|
|
72
|
-
"@taquito/rpc": "^
|
|
73
|
-
"@taquito/taquito": "^
|
|
74
|
-
"@taquito/utils": "^
|
|
71
|
+
"@taquito/core": "^23.0.0-RC.0",
|
|
72
|
+
"@taquito/rpc": "^23.0.0-RC.0",
|
|
73
|
+
"@taquito/taquito": "^23.0.0-RC.0",
|
|
74
|
+
"@taquito/utils": "^23.0.0-RC.0",
|
|
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": "
|
|
109
|
+
"gitHead": "3bdb33e97e705d1c7090dd83e1b243e6e2a4d768"
|
|
110
110
|
}
|