@taquito/sapling 24.3.0-beta.2 → 24.3.0-beta.3
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/SAPLING_PARAMS_PROVENANCE.md +24 -0
- package/dist/lib/sapling-keys/in-memory-proving-key.js +1 -1
- 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-module-wrapper.js +12 -4
- package/dist/lib/sapling-state/sapling-state.js +3 -2
- package/dist/lib/sapling-tx-builder/sapling-transactions-builder.js +6 -5
- package/dist/lib/sapling-tx-viewer/sapling-transaction-viewer.js +3 -2
- package/dist/lib/taquito-sapling.js +6 -5
- package/dist/lib/types.js +2 -0
- package/dist/lib/version.js +2 -2
- package/dist/taquito-sapling.es6.js +27 -15
- package/dist/taquito-sapling.es6.js.map +1 -1
- package/dist/taquito-sapling.umd.js +28 -15
- package/dist/taquito-sapling.umd.js.map +1 -1
- package/dist/types/sapling-module-wrapper.d.ts +1 -1
- package/dist/types/sapling-state/sapling-state.d.ts +4 -1
- package/dist/types/sapling-tx-builder/sapling-transactions-builder.d.ts +6 -3
- package/dist/types/sapling-tx-viewer/sapling-transaction-viewer.d.ts +4 -1
- package/dist/types/types.d.ts +4 -1
- package/package.json +14 -16
- package/saplingOutputParams.js +13 -0
- package/fetch-sapling-params.js +0 -39
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
## Sapling Parameter Provenance
|
|
2
|
+
|
|
3
|
+
The `saplingOutputParams.js` file in this package and the `saplingSpendParams.js` file in the sibling `@taquito/sapling-spend-params` package are vendored copies of the Sapling proving parameters distributed by the Zcash project.
|
|
4
|
+
|
|
5
|
+
Source:
|
|
6
|
+
- `https://download.z.cash/downloads/sapling-spend.params`
|
|
7
|
+
- `https://download.z.cash/downloads/sapling-output.params`
|
|
8
|
+
|
|
9
|
+
Verification data:
|
|
10
|
+
- `sapling-spend.params`
|
|
11
|
+
- Size: `47,958,396` bytes
|
|
12
|
+
- SHA-256: `8e48ffd23abb3a5fd9c5589204f32d9c31285a04b78096ba40a79b75677efc13`
|
|
13
|
+
- `sapling-output.params`
|
|
14
|
+
- Size: `3,592,860` bytes
|
|
15
|
+
- SHA-256: `2f0ebbcbb9bb0bcffe95a397e7eba89c29eb4dde6191c339db88570e3f3fb0e4`
|
|
16
|
+
|
|
17
|
+
Why these files are vendored:
|
|
18
|
+
- `@taquito/sapling` previously fetched them during `postinstall`, which made installs network-dependent.
|
|
19
|
+
- Vendoring keeps published packages self-contained and makes builds reproducible.
|
|
20
|
+
- These parameters are treated as fixed trusted setup artifacts, not routine updatable assets.
|
|
21
|
+
|
|
22
|
+
Maintainer note:
|
|
23
|
+
- `fetch-sapling-params.js` is retained only as a repo-maintenance helper to regenerate the vendored wrapper files from the exact raw parameter files above.
|
|
24
|
+
- Any regeneration should be exceptional, manually reviewed, and accompanied by explicit provenance updates in this file.
|
|
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var _InMemoryProvingKey_provingKey;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.InMemoryProvingKey = void 0;
|
|
16
|
-
const sapling = require("@
|
|
16
|
+
const sapling = require("@taquito/sapling-wasm");
|
|
17
17
|
const helpers_1 = require("./helpers");
|
|
18
18
|
/**
|
|
19
19
|
* holds the proving key, create proof for spend descriptions
|
|
@@ -14,7 +14,7 @@ var _InMemorySpendingKey_spendingKeyBuf, _InMemorySpendingKey_saplingViewingKey;
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.InMemorySpendingKey = void 0;
|
|
16
16
|
const in_memory_viewing_key_1 = require("./in-memory-viewing-key");
|
|
17
|
-
const sapling = require("@
|
|
17
|
+
const sapling = require("@taquito/sapling-wasm");
|
|
18
18
|
const utils_1 = require("@taquito/utils");
|
|
19
19
|
const bip39 = require("@scure/bip39");
|
|
20
20
|
const helpers_1 = require("./helpers");
|
|
@@ -14,7 +14,7 @@ var _InMemoryViewingKey_fullViewingKey;
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.InMemoryViewingKey = void 0;
|
|
16
16
|
const utils_1 = require("@taquito/utils");
|
|
17
|
-
const sapling = require("@
|
|
17
|
+
const sapling = require("@taquito/sapling-wasm");
|
|
18
18
|
const helpers_1 = require("./helpers");
|
|
19
19
|
/**
|
|
20
20
|
* Holds the viewing key
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SaplingWrapper = void 0;
|
|
4
|
-
const sapling = require("@
|
|
5
|
-
const random_1 = require("@stablelib/random");
|
|
4
|
+
const sapling = require("@taquito/sapling-wasm");
|
|
6
5
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
7
6
|
const saplingOutputParams = require('../saplingOutputParams');
|
|
8
7
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
9
|
-
const saplingSpendParams = require('
|
|
8
|
+
const saplingSpendParams = require('@taquito/sapling-spend-params');
|
|
10
9
|
let cachedParams;
|
|
10
|
+
const getRandomValueSource = () => {
|
|
11
|
+
const crypto = globalThis.crypto;
|
|
12
|
+
if (!crypto?.getRandomValues) {
|
|
13
|
+
throw new Error('Sapling randomness requires globalThis.crypto.getRandomValues');
|
|
14
|
+
}
|
|
15
|
+
return crypto;
|
|
16
|
+
};
|
|
11
17
|
class SaplingWrapper {
|
|
12
18
|
async withProvingContext(action) {
|
|
13
19
|
await this.initSaplingParameters();
|
|
14
20
|
return sapling.withProvingContext(action);
|
|
15
21
|
}
|
|
16
22
|
getRandomBytes(length) {
|
|
17
|
-
|
|
23
|
+
const bytes = new Uint8Array(length);
|
|
24
|
+
getRandomValueSource().getRandomValues(bytes);
|
|
25
|
+
return bytes;
|
|
18
26
|
}
|
|
19
27
|
async randR() {
|
|
20
28
|
return sapling.randR();
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.SaplingState = void 0;
|
|
9
9
|
const errors_1 = require("../errors");
|
|
10
|
-
const sapling_wasm_1 = require("@
|
|
10
|
+
const sapling_wasm_1 = require("@taquito/sapling-wasm");
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
12
|
const utils_2 = require("@taquito/utils");
|
|
13
13
|
const bignumber_js_1 = require("bignumber.js");
|
|
14
|
+
const BigNumber = bignumber_js_1.default;
|
|
14
15
|
/**
|
|
15
16
|
* The SaplingState class's main purpose is to provide a Merkle path for the forger and the transaction builder, so that it may verify that the Sapling transaction is valid
|
|
16
17
|
*
|
|
@@ -130,7 +131,7 @@ class SaplingState {
|
|
|
130
131
|
}
|
|
131
132
|
else {
|
|
132
133
|
let nextPos, nextTree, otherTree;
|
|
133
|
-
const fullTree = new
|
|
134
|
+
const fullTree = new BigNumber(2).pow(height - 1);
|
|
134
135
|
if (position.lt(fullTree)) {
|
|
135
136
|
nextPos = position;
|
|
136
137
|
nextTree = tree[1];
|
|
@@ -17,6 +17,7 @@ const blakejs_1 = require("blakejs");
|
|
|
17
17
|
const nacl_1 = require("@stablelib/nacl");
|
|
18
18
|
const constants_1 = require("../constants");
|
|
19
19
|
const bignumber_js_1 = require("bignumber.js");
|
|
20
|
+
const BigNumber = bignumber_js_1.default;
|
|
20
21
|
const utils_1 = require("@taquito/utils");
|
|
21
22
|
const helpers_1 = require("../sapling-tx-viewer/helpers");
|
|
22
23
|
const sapling_state_1 = require("../sapling-state/sapling-state");
|
|
@@ -85,9 +86,9 @@ class SaplingTransactionBuilder {
|
|
|
85
86
|
const outputs = [];
|
|
86
87
|
const inputs = [];
|
|
87
88
|
inputs.push(...(await this.prepareSaplingSpendDescription(saplingContext, chosenInputs.inputsToSpend)));
|
|
88
|
-
let sumAmountOutput = new
|
|
89
|
+
let sumAmountOutput = new BigNumber(0);
|
|
89
90
|
for (const i in saplingTransactionParams) {
|
|
90
|
-
sumAmountOutput = sumAmountOutput.plus(new
|
|
91
|
+
sumAmountOutput = sumAmountOutput.plus(new BigNumber(saplingTransactionParams[i].amount));
|
|
91
92
|
const [address] = (0, utils_1.b58DecodeAndCheckPrefix)(saplingTransactionParams[i].to, [
|
|
92
93
|
utils_1.PrefixV2.SaplingAddress,
|
|
93
94
|
]);
|
|
@@ -111,7 +112,7 @@ class SaplingTransactionBuilder {
|
|
|
111
112
|
randomCommitmentTrapdoor: randomCommitmentTrapdoor,
|
|
112
113
|
outgoingViewingKey: outgoingViewingKey,
|
|
113
114
|
}, chosenInputs.sumSelectedInputs);
|
|
114
|
-
sumAmountOutput = sumAmountOutput.plus(new
|
|
115
|
+
sumAmountOutput = sumAmountOutput.plus(new BigNumber(payBackAmount));
|
|
115
116
|
outputs.push(payBackOutput);
|
|
116
117
|
}
|
|
117
118
|
const balance = this.calculateTransactionBalance(chosenInputs.sumSelectedInputs.toString(), sumAmountOutput.toString());
|
|
@@ -133,7 +134,7 @@ class SaplingTransactionBuilder {
|
|
|
133
134
|
}
|
|
134
135
|
// sum of values of inputs minus sums of values of output equals balance
|
|
135
136
|
calculateTransactionBalance(inputTotal, outputTotal) {
|
|
136
|
-
return new
|
|
137
|
+
return new BigNumber(inputTotal).minus(new BigNumber(outputTotal));
|
|
137
138
|
}
|
|
138
139
|
async prepareSaplingOutputDescription(parametersOutputDescription) {
|
|
139
140
|
const ephemeralPrivateKey = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").randR();
|
|
@@ -186,7 +187,7 @@ class SaplingTransactionBuilder {
|
|
|
186
187
|
const saplingSpendDescriptions = [];
|
|
187
188
|
for (let i = 0; i < inputsToSpend.length; i++) {
|
|
188
189
|
const amount = (0, helpers_1.convertValueToBigNumber)(inputsToSpend[i].value).toString();
|
|
189
|
-
const witness = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingState, "f").getWitness(stateTree, new
|
|
190
|
+
const witness = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingState, "f").getWitness(stateTree, new BigNumber(inputsToSpend[i].position));
|
|
190
191
|
const unsignedSpendDescription = __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemoryProvingKey, "f")
|
|
191
192
|
? await __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemoryProvingKey, "f").prepareSpendDescription({
|
|
192
193
|
saplingContext,
|
|
@@ -13,8 +13,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var _SaplingTransactionViewer_viewingKeyProvider, _SaplingTransactionViewer_readProvider, _SaplingTransactionViewer_saplingContractId;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.SaplingTransactionViewer = void 0;
|
|
16
|
-
const sapling = require("@
|
|
16
|
+
const sapling = require("@taquito/sapling-wasm");
|
|
17
17
|
const bignumber_js_1 = require("bignumber.js");
|
|
18
|
+
const BigNumber = bignumber_js_1.default;
|
|
18
19
|
const utils_1 = require("@taquito/utils");
|
|
19
20
|
const blakejs_1 = require("blakejs");
|
|
20
21
|
const nacl_1 = require("@stablelib/nacl");
|
|
@@ -44,7 +45,7 @@ class SaplingTransactionViewer {
|
|
|
44
45
|
*
|
|
45
46
|
*/
|
|
46
47
|
async getBalance() {
|
|
47
|
-
let balance = new
|
|
48
|
+
let balance = new BigNumber(0);
|
|
48
49
|
const { commitments_and_ciphertexts, nullifiers } = await this.getSaplingDiff();
|
|
49
50
|
for (let i = 0; i < commitments_and_ciphertexts.length; i++) {
|
|
50
51
|
const decrypted = await this.decryptCiphertextAsReceiver(commitments_and_ciphertexts[i]);
|
|
@@ -18,6 +18,7 @@ var _SaplingToolkit_inMemorySpendingKey, _SaplingToolkit_saplingId, _SaplingTool
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.SaplingToolkit = exports.InMemoryProvingKey = exports.InMemorySpendingKey = exports.InMemoryViewingKey = exports.SaplingTransactionViewer = void 0;
|
|
20
20
|
const bignumber_js_1 = require("bignumber.js");
|
|
21
|
+
const BigNumber = bignumber_js_1.default;
|
|
21
22
|
const taquito_1 = require("@taquito/taquito");
|
|
22
23
|
const utils_1 = require("@taquito/utils");
|
|
23
24
|
const errors_1 = require("./errors");
|
|
@@ -122,7 +123,7 @@ class SaplingToolkit {
|
|
|
122
123
|
const { formatedParams, totalAmount } = this.formatTransactionParams([unshieldedTxParams], this.validateDestinationImplicitAddress);
|
|
123
124
|
const boundData = await this.createBoundData(formatedParams[0].to);
|
|
124
125
|
const root = await this.getRoot();
|
|
125
|
-
const chosenInputs = await this.selectInputsToSpend(new
|
|
126
|
+
const chosenInputs = await this.selectInputsToSpend(new BigNumber(formatedParams[0].amount));
|
|
126
127
|
const { inputs, outputs, signature, balance } = await __classPrivateFieldGet(this, _SaplingToolkit_saplingTxBuilder, "f").createSaplingTx([], totalAmount, boundData, chosenInputs);
|
|
127
128
|
const forgedSaplingTx = __classPrivateFieldGet(this, _SaplingToolkit_saplingForger, "f").forgeSaplingTransaction({
|
|
128
129
|
inputs,
|
|
@@ -159,13 +160,13 @@ class SaplingToolkit {
|
|
|
159
160
|
}
|
|
160
161
|
formatTransactionParams(txParams, validateDestination) {
|
|
161
162
|
const formatedParams = [];
|
|
162
|
-
let totalAmount = new
|
|
163
|
+
let totalAmount = new BigNumber(0);
|
|
163
164
|
txParams.forEach((param) => {
|
|
164
165
|
validateDestination(param.to);
|
|
165
166
|
const amountMutez = param.mutez
|
|
166
167
|
? param.amount.toString()
|
|
167
168
|
: (0, utils_1.format)('tz', 'mutez', param.amount).toString();
|
|
168
|
-
totalAmount = totalAmount.plus(new
|
|
169
|
+
totalAmount = totalAmount.plus(new BigNumber(amountMutez));
|
|
169
170
|
const memo = param.memo ?? constants_1.DEFAULT_MEMO;
|
|
170
171
|
if (memo.length > __classPrivateFieldGet(this, _SaplingToolkit_memoSize, "f")) {
|
|
171
172
|
throw new errors_1.InvalidMemo(memo, `expecting length to be less than ${__classPrivateFieldGet(this, _SaplingToolkit_memoSize, "f")}`);
|
|
@@ -220,7 +221,7 @@ class SaplingToolkit {
|
|
|
220
221
|
const saplingTxViewer = await this.getSaplingTransactionViewer();
|
|
221
222
|
const { incoming } = await saplingTxViewer.getIncomingAndOutgoingTransactionsRaw();
|
|
222
223
|
const inputsToSpend = [];
|
|
223
|
-
let sumSelectedInputs = new
|
|
224
|
+
let sumSelectedInputs = new BigNumber(0);
|
|
224
225
|
incoming.forEach((input) => {
|
|
225
226
|
if (!input.isSpent && sumSelectedInputs.isLessThan(amountMutez)) {
|
|
226
227
|
const txAmount = (0, helpers_1.convertValueToBigNumber)(input.value);
|
|
@@ -229,7 +230,7 @@ class SaplingToolkit {
|
|
|
229
230
|
inputsToSpend.push(rest);
|
|
230
231
|
}
|
|
231
232
|
});
|
|
232
|
-
if (sumSelectedInputs.isLessThan(new
|
|
233
|
+
if (sumSelectedInputs.isLessThan(new BigNumber(amountMutez))) {
|
|
233
234
|
throw new errors_1.InsufficientBalance(sumSelectedInputs.toString(), amountMutez.toString());
|
|
234
235
|
}
|
|
235
236
|
return { inputsToSpend, sumSelectedInputs };
|
package/dist/lib/types.js
CHANGED
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!
|
|
5
5
|
exports.VERSION = {
|
|
6
|
-
"commitHash": "
|
|
7
|
-
"version": "24.3.0-beta.
|
|
6
|
+
"commitHash": "a312cd3f4fc0ab0fb3351bfffe6ad855772cb077",
|
|
7
|
+
"version": "24.3.0-beta.3"
|
|
8
8
|
};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumberJs from 'bignumber.js';
|
|
2
2
|
import { MichelCodecPacker } from '@taquito/taquito';
|
|
3
3
|
import { b58Encode, PrefixV2, bytesToString, toHexBuf, stringToBytes, hex2buf, mergebuf, hex2Bytes, num2PaddedHex, b58DecodeAndCheckPrefix, format, b58DecodePublicKeyHash, validateKeyHash, ValidationResult } from '@taquito/utils';
|
|
4
4
|
import { ParameterValidationError, TaquitoError, InvalidKeyHashError, InvalidAddressError } from '@taquito/core';
|
|
5
|
-
import * as sapling from '@
|
|
6
|
-
import { merkleHash } from '@
|
|
5
|
+
import * as sapling from '@taquito/sapling-wasm';
|
|
6
|
+
import { merkleHash } from '@taquito/sapling-wasm';
|
|
7
7
|
import blake from 'blakejs';
|
|
8
8
|
import { openSecretBox, secretBox } from '@stablelib/nacl';
|
|
9
|
-
import { randomBytes } from '@stablelib/random';
|
|
10
9
|
import toBuffer from 'typedarray-to-buffer';
|
|
11
10
|
|
|
12
11
|
/******************************************************************************
|
|
@@ -134,7 +133,7 @@ function readableFormat(saplingTransactionProperties) {
|
|
|
134
133
|
};
|
|
135
134
|
}
|
|
136
135
|
function convertValueToBigNumber(value) {
|
|
137
|
-
return new
|
|
136
|
+
return new BigNumberJs(Buffer.from(value).toString('hex'), 16);
|
|
138
137
|
}
|
|
139
138
|
function bufToUint8Array(buffer) {
|
|
140
139
|
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / Uint8Array.BYTES_PER_ELEMENT);
|
|
@@ -227,7 +226,7 @@ class SaplingForger {
|
|
|
227
226
|
const encodedMemo = Buffer.from(stringToBytes(txPlainText.memo).padEnd(txPlainText.memoSize, '0'), 'hex');
|
|
228
227
|
return Buffer.concat([
|
|
229
228
|
txPlainText.diversifier,
|
|
230
|
-
toHexBuf(new
|
|
229
|
+
toHexBuf(new BigNumberJs(txPlainText.amount), 64),
|
|
231
230
|
txPlainText.randomCommitmentTrapdoor,
|
|
232
231
|
toHexBuf(txPlainText.memoSize, 32),
|
|
233
232
|
encodedMemo,
|
|
@@ -241,6 +240,7 @@ const DEFAULT_MEMO = '';
|
|
|
241
240
|
const DEFAULT_BOUND_DATA = Buffer.from('', 'hex');
|
|
242
241
|
|
|
243
242
|
var _SaplingTransactionViewer_viewingKeyProvider, _SaplingTransactionViewer_readProvider, _SaplingTransactionViewer_saplingContractId;
|
|
243
|
+
const BigNumber$3 = BigNumberJs;
|
|
244
244
|
/**
|
|
245
245
|
* Allows to retrieve and decrypt sapling transactions using on a viewing key
|
|
246
246
|
*
|
|
@@ -264,7 +264,7 @@ class SaplingTransactionViewer {
|
|
|
264
264
|
*
|
|
265
265
|
*/
|
|
266
266
|
async getBalance() {
|
|
267
|
-
let balance = new BigNumber(0);
|
|
267
|
+
let balance = new BigNumber$3(0);
|
|
268
268
|
const { commitments_and_ciphertexts, nullifiers } = await this.getSaplingDiff();
|
|
269
269
|
for (let i = 0; i < commitments_and_ciphertexts.length; i++) {
|
|
270
270
|
const decrypted = await this.decryptCiphertextAsReceiver(commitments_and_ciphertexts[i]);
|
|
@@ -456,6 +456,7 @@ const changeEndianness = (hex) => {
|
|
|
456
456
|
* https://github.com/airgap-it/airgap-coin-lib/blob/master/LICENSE.md
|
|
457
457
|
*
|
|
458
458
|
*/
|
|
459
|
+
const BigNumber$2 = BigNumberJs;
|
|
459
460
|
/**
|
|
460
461
|
* The SaplingState class's main purpose is to provide a Merkle path for the forger and the transaction builder, so that it may verify that the Sapling transaction is valid
|
|
461
462
|
*
|
|
@@ -575,7 +576,7 @@ class SaplingState {
|
|
|
575
576
|
}
|
|
576
577
|
else {
|
|
577
578
|
let nextPos, nextTree, otherTree;
|
|
578
|
-
const fullTree = new BigNumber(2).pow(height - 1);
|
|
579
|
+
const fullTree = new BigNumber$2(2).pow(height - 1);
|
|
579
580
|
if (position.lt(fullTree)) {
|
|
580
581
|
nextPos = position;
|
|
581
582
|
nextTree = tree[1];
|
|
@@ -594,15 +595,24 @@ class SaplingState {
|
|
|
594
595
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
595
596
|
const saplingOutputParams = require('../saplingOutputParams');
|
|
596
597
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
597
|
-
const saplingSpendParams = require('
|
|
598
|
+
const saplingSpendParams = require('@taquito/sapling-spend-params');
|
|
598
599
|
let cachedParams;
|
|
600
|
+
const getRandomValueSource = () => {
|
|
601
|
+
const crypto = globalThis.crypto;
|
|
602
|
+
if (!crypto?.getRandomValues) {
|
|
603
|
+
throw new Error('Sapling randomness requires globalThis.crypto.getRandomValues');
|
|
604
|
+
}
|
|
605
|
+
return crypto;
|
|
606
|
+
};
|
|
599
607
|
class SaplingWrapper {
|
|
600
608
|
async withProvingContext(action) {
|
|
601
609
|
await this.initSaplingParameters();
|
|
602
610
|
return sapling.withProvingContext(action);
|
|
603
611
|
}
|
|
604
612
|
getRandomBytes(length) {
|
|
605
|
-
|
|
613
|
+
const bytes = new Uint8Array(length);
|
|
614
|
+
getRandomValueSource().getRandomValues(bytes);
|
|
615
|
+
return bytes;
|
|
606
616
|
}
|
|
607
617
|
async randR() {
|
|
608
618
|
return sapling.randR();
|
|
@@ -645,6 +655,7 @@ class SaplingWrapper {
|
|
|
645
655
|
}
|
|
646
656
|
|
|
647
657
|
var _SaplingTransactionBuilder_inMemorySpendingKey, _SaplingTransactionBuilder_inMemoryProvingKey, _SaplingTransactionBuilder_saplingForger, _SaplingTransactionBuilder_contractAddress, _SaplingTransactionBuilder_saplingId, _SaplingTransactionBuilder_memoSize, _SaplingTransactionBuilder_readProvider, _SaplingTransactionBuilder_saplingWrapper, _SaplingTransactionBuilder_chainId, _SaplingTransactionBuilder_saplingState;
|
|
658
|
+
const BigNumber$1 = BigNumberJs;
|
|
648
659
|
class SaplingTransactionBuilder {
|
|
649
660
|
constructor(keys, saplingForger, saplingContractDetails, readProvider, saplingWrapper = new SaplingWrapper()) {
|
|
650
661
|
_SaplingTransactionBuilder_inMemorySpendingKey.set(this, void 0);
|
|
@@ -709,9 +720,9 @@ class SaplingTransactionBuilder {
|
|
|
709
720
|
const outputs = [];
|
|
710
721
|
const inputs = [];
|
|
711
722
|
inputs.push(...(await this.prepareSaplingSpendDescription(saplingContext, chosenInputs.inputsToSpend)));
|
|
712
|
-
let sumAmountOutput = new BigNumber(0);
|
|
723
|
+
let sumAmountOutput = new BigNumber$1(0);
|
|
713
724
|
for (const i in saplingTransactionParams) {
|
|
714
|
-
sumAmountOutput = sumAmountOutput.plus(new BigNumber(saplingTransactionParams[i].amount));
|
|
725
|
+
sumAmountOutput = sumAmountOutput.plus(new BigNumber$1(saplingTransactionParams[i].amount));
|
|
715
726
|
const [address] = b58DecodeAndCheckPrefix(saplingTransactionParams[i].to, [
|
|
716
727
|
PrefixV2.SaplingAddress,
|
|
717
728
|
]);
|
|
@@ -735,7 +746,7 @@ class SaplingTransactionBuilder {
|
|
|
735
746
|
randomCommitmentTrapdoor: randomCommitmentTrapdoor,
|
|
736
747
|
outgoingViewingKey: outgoingViewingKey,
|
|
737
748
|
}, chosenInputs.sumSelectedInputs);
|
|
738
|
-
sumAmountOutput = sumAmountOutput.plus(new BigNumber(payBackAmount));
|
|
749
|
+
sumAmountOutput = sumAmountOutput.plus(new BigNumber$1(payBackAmount));
|
|
739
750
|
outputs.push(payBackOutput);
|
|
740
751
|
}
|
|
741
752
|
const balance = this.calculateTransactionBalance(chosenInputs.sumSelectedInputs.toString(), sumAmountOutput.toString());
|
|
@@ -757,7 +768,7 @@ class SaplingTransactionBuilder {
|
|
|
757
768
|
}
|
|
758
769
|
// sum of values of inputs minus sums of values of output equals balance
|
|
759
770
|
calculateTransactionBalance(inputTotal, outputTotal) {
|
|
760
|
-
return new BigNumber(inputTotal).minus(new BigNumber(outputTotal));
|
|
771
|
+
return new BigNumber$1(inputTotal).minus(new BigNumber$1(outputTotal));
|
|
761
772
|
}
|
|
762
773
|
async prepareSaplingOutputDescription(parametersOutputDescription) {
|
|
763
774
|
const ephemeralPrivateKey = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").randR();
|
|
@@ -810,7 +821,7 @@ class SaplingTransactionBuilder {
|
|
|
810
821
|
const saplingSpendDescriptions = [];
|
|
811
822
|
for (let i = 0; i < inputsToSpend.length; i++) {
|
|
812
823
|
const amount = convertValueToBigNumber(inputsToSpend[i].value).toString();
|
|
813
|
-
const witness = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingState, "f").getWitness(stateTree, new BigNumber(inputsToSpend[i].position));
|
|
824
|
+
const witness = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingState, "f").getWitness(stateTree, new BigNumber$1(inputsToSpend[i].position));
|
|
814
825
|
const unsignedSpendDescription = __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemoryProvingKey, "f")
|
|
815
826
|
? await __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemoryProvingKey, "f").prepareSpendDescription({
|
|
816
827
|
saplingContext,
|
|
@@ -1825,6 +1836,7 @@ _InMemoryProvingKey_provingKey = new WeakMap();
|
|
|
1825
1836
|
* @module @taquito/sapling
|
|
1826
1837
|
*/
|
|
1827
1838
|
var _SaplingToolkit_inMemorySpendingKey, _SaplingToolkit_saplingId, _SaplingToolkit_contractAddress, _SaplingToolkit_memoSize, _SaplingToolkit_readProvider, _SaplingToolkit_packer, _SaplingToolkit_saplingForger, _SaplingToolkit_saplingTxBuilder, _SaplingToolkit_saplingTransactionViewer;
|
|
1839
|
+
const BigNumber = BigNumberJs;
|
|
1828
1840
|
/**
|
|
1829
1841
|
* Class that surfaces all of the sapling capability allowing to read from a sapling state and prepare transactions
|
|
1830
1842
|
*
|